@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
package/build/reducer.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/reducer.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6/index.js';\n\n/**\n * WordPress dependencies\n */\nimport { compose } from '@wordpress/compose';\nimport { combineReducers } from '@wordpress/data';\nimport { createUndoManager } from '@wordpress/undo-manager';\n\n/**\n * Internal dependencies\n */\nimport { ifMatchingAction, replaceAction } from './utils';\nimport { reducer as queriedDataReducer } from './queried-data';\nimport { rootEntitiesConfig, DEFAULT_ENTITY_KEY } from './entities';\n\n/** @typedef {import('./types').AnyFunction} AnyFunction */\n\n/**\n * Reducer managing authors state. Keyed by id.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function users( state = { byId: {}, queries: {} }, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_USER_QUERY':\n\t\t\treturn {\n\t\t\t\tbyId: {\n\t\t\t\t\t...state.byId,\n\t\t\t\t\t// Key users by their ID.\n\t\t\t\t\t...action.users.reduce(\n\t\t\t\t\t\t( newUsers, user ) => ( {\n\t\t\t\t\t\t\t...newUsers,\n\t\t\t\t\t\t\t[ user.id ]: user,\n\t\t\t\t\t\t} ),\n\t\t\t\t\t\t{}\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t\tqueries: {\n\t\t\t\t\t...state.queries,\n\t\t\t\t\t[ action.queryID ]: action.users.map( ( user ) => user.id ),\n\t\t\t\t},\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing current user state.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function currentUser( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_CURRENT_USER':\n\t\t\treturn action.currentUser;\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing the current theme.\n *\n * @param {string|undefined} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {string|undefined} Updated state.\n */\nexport function currentTheme( state = undefined, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_CURRENT_THEME':\n\t\t\treturn action.currentTheme.stylesheet;\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing the current global styles id.\n *\n * @param {string|undefined} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {string|undefined} Updated state.\n */\nexport function currentGlobalStylesId( state = undefined, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_CURRENT_GLOBAL_STYLES_ID':\n\t\t\treturn action.id;\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing the theme base global styles.\n *\n * @param {Record<string, object>} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Record<string, object>} Updated state.\n */\nexport function themeBaseGlobalStyles( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_THEME_GLOBAL_STYLES':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.stylesheet ]: action.globalStyles,\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing the theme global styles variations.\n *\n * @param {Record<string, object>} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Record<string, object>} Updated state.\n */\nexport function themeGlobalStyleVariations( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_THEME_GLOBAL_STYLE_VARIATIONS':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.stylesheet ]: action.variations,\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\nconst withMultiEntityRecordEdits = ( reducer ) => ( state, action ) => {\n\tif ( action.type === 'UNDO' || action.type === 'REDO' ) {\n\t\tconst { record } = action;\n\n\t\tlet newState = state;\n\t\trecord.forEach( ( { id: { kind, name, recordId }, changes } ) => {\n\t\t\tnewState = reducer( newState, {\n\t\t\t\ttype: 'EDIT_ENTITY_RECORD',\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId,\n\t\t\t\tedits: Object.entries( changes ).reduce(\n\t\t\t\t\t( acc, [ key, value ] ) => {\n\t\t\t\t\t\tacc[ key ] =\n\t\t\t\t\t\t\taction.type === 'UNDO' ? value.from : value.to;\n\t\t\t\t\t\treturn acc;\n\t\t\t\t\t},\n\t\t\t\t\t{}\n\t\t\t\t),\n\t\t\t} );\n\t\t} );\n\t\treturn newState;\n\t}\n\n\treturn reducer( state, action );\n};\n\n/**\n * Higher Order Reducer for a given entity config. It supports:\n *\n * - Fetching\n * - Editing\n * - Saving\n *\n * @param {Object} entityConfig Entity config.\n *\n * @return {AnyFunction} Reducer.\n */\nfunction entity( entityConfig ) {\n\treturn compose( [\n\t\twithMultiEntityRecordEdits,\n\n\t\t// Limit to matching action type so we don't attempt to replace action on\n\t\t// an unhandled action.\n\t\tifMatchingAction(\n\t\t\t( action ) =>\n\t\t\t\taction.name &&\n\t\t\t\taction.kind &&\n\t\t\t\taction.name === entityConfig.name &&\n\t\t\t\taction.kind === entityConfig.kind\n\t\t),\n\n\t\t// Inject the entity config into the action.\n\t\treplaceAction( ( action ) => {\n\t\t\treturn {\n\t\t\t\tkey: entityConfig.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t...action,\n\t\t\t};\n\t\t} ),\n\t] )(\n\t\tcombineReducers( {\n\t\t\tqueriedData: queriedDataReducer,\n\t\t\tedits: ( state = {}, action ) => {\n\t\t\t\tswitch ( action.type ) {\n\t\t\t\t\tcase 'RECEIVE_ITEMS':\n\t\t\t\t\t\tconst context = action?.query?.context ?? 'default';\n\t\t\t\t\t\tif ( context !== 'default' ) {\n\t\t\t\t\t\t\treturn state;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst nextState = { ...state };\n\t\t\t\t\t\tconst itemsList = Array.isArray( action.items )\n\t\t\t\t\t\t\t? action.items\n\t\t\t\t\t\t\t: [ action.items ];\n\n\t\t\t\t\t\tfor ( const record of itemsList ) {\n\t\t\t\t\t\t\tconst recordId = record?.[ action.key ];\n\t\t\t\t\t\t\tconst edits = nextState[ recordId ];\n\t\t\t\t\t\t\tif ( ! edits ) {\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst nextEdits = Object.keys( edits ).reduce(\n\t\t\t\t\t\t\t\t( acc, key ) => {\n\t\t\t\t\t\t\t\t\t// If the edited value is still different to the persisted value,\n\t\t\t\t\t\t\t\t\t// keep the edited value in edits.\n\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t// Edits are the \"raw\" attribute values, but records may have\n\t\t\t\t\t\t\t\t\t\t// objects with more properties, so we use `get` here for the\n\t\t\t\t\t\t\t\t\t\t// comparison.\n\t\t\t\t\t\t\t\t\t\t! fastDeepEqual(\n\t\t\t\t\t\t\t\t\t\t\tedits[ key ],\n\t\t\t\t\t\t\t\t\t\t\trecord[ key ]?.raw ?? record[ key ]\n\t\t\t\t\t\t\t\t\t\t) &&\n\t\t\t\t\t\t\t\t\t\t// Sometimes the server alters the sent value which means\n\t\t\t\t\t\t\t\t\t\t// we need to also remove the edits before the api request.\n\t\t\t\t\t\t\t\t\t\t( ! action.persistedEdits ||\n\t\t\t\t\t\t\t\t\t\t\t! fastDeepEqual(\n\t\t\t\t\t\t\t\t\t\t\t\tedits[ key ],\n\t\t\t\t\t\t\t\t\t\t\t\taction.persistedEdits[ key ]\n\t\t\t\t\t\t\t\t\t\t\t) )\n\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\tacc[ key ] = edits[ key ];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn acc;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{}\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tif ( Object.keys( nextEdits ).length ) {\n\t\t\t\t\t\t\t\tnextState[ recordId ] = nextEdits;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tdelete nextState[ recordId ];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn nextState;\n\n\t\t\t\t\tcase 'EDIT_ENTITY_RECORD':\n\t\t\t\t\t\tconst nextEdits = {\n\t\t\t\t\t\t\t...state[ action.recordId ],\n\t\t\t\t\t\t\t...action.edits,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tObject.keys( nextEdits ).forEach( ( key ) => {\n\t\t\t\t\t\t\t// Delete cleared edits so that the properties\n\t\t\t\t\t\t\t// are not considered dirty.\n\t\t\t\t\t\t\tif ( nextEdits[ key ] === undefined ) {\n\t\t\t\t\t\t\t\tdelete nextEdits[ key ];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} );\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...state,\n\t\t\t\t\t\t\t[ action.recordId ]: nextEdits,\n\t\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn state;\n\t\t\t},\n\n\t\t\tsaving: ( state = {}, action ) => {\n\t\t\t\tswitch ( action.type ) {\n\t\t\t\t\tcase 'SAVE_ENTITY_RECORD_START':\n\t\t\t\t\tcase 'SAVE_ENTITY_RECORD_FINISH':\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...state,\n\t\t\t\t\t\t\t[ action.recordId ]: {\n\t\t\t\t\t\t\t\tpending:\n\t\t\t\t\t\t\t\t\taction.type === 'SAVE_ENTITY_RECORD_START',\n\t\t\t\t\t\t\t\terror: action.error,\n\t\t\t\t\t\t\t\tisAutosave: action.isAutosave,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn state;\n\t\t\t},\n\n\t\t\tdeleting: ( state = {}, action ) => {\n\t\t\t\tswitch ( action.type ) {\n\t\t\t\t\tcase 'DELETE_ENTITY_RECORD_START':\n\t\t\t\t\tcase 'DELETE_ENTITY_RECORD_FINISH':\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...state,\n\t\t\t\t\t\t\t[ action.recordId ]: {\n\t\t\t\t\t\t\t\tpending:\n\t\t\t\t\t\t\t\t\taction.type ===\n\t\t\t\t\t\t\t\t\t'DELETE_ENTITY_RECORD_START',\n\t\t\t\t\t\t\t\terror: action.error,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn state;\n\t\t\t},\n\n\t\t\trevisions: ( state = {}, action ) => {\n\t\t\t\t// Use the same queriedDataReducer shape for revisions.\n\t\t\t\tif ( action.type === 'RECEIVE_ITEM_REVISIONS' ) {\n\t\t\t\t\tconst recordKey = action.recordKey;\n\t\t\t\t\tdelete action.recordKey;\n\t\t\t\t\tconst newState = queriedDataReducer( state[ recordKey ], {\n\t\t\t\t\t\t...action,\n\t\t\t\t\t\ttype: 'RECEIVE_ITEMS',\n\t\t\t\t\t} );\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...state,\n\t\t\t\t\t\t[ recordKey ]: newState,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tif ( action.type === 'REMOVE_ITEMS' ) {\n\t\t\t\t\treturn Object.fromEntries(\n\t\t\t\t\t\tObject.entries( state ).filter(\n\t\t\t\t\t\t\t( [ id ] ) =>\n\t\t\t\t\t\t\t\t! action.itemIds.some( ( itemId ) => {\n\t\t\t\t\t\t\t\t\tif ( Number.isInteger( itemId ) ) {\n\t\t\t\t\t\t\t\t\t\treturn itemId === +id;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn itemId === id;\n\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn state;\n\t\t\t},\n\t\t} )\n\t);\n}\n\n/**\n * Reducer keeping track of the registered entities.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function entitiesConfig( state = rootEntitiesConfig, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'ADD_ENTITIES':\n\t\t\treturn [ ...state, ...action.entities ];\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer keeping track of the registered entities config and data.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport const entities = ( state = {}, action ) => {\n\tconst newConfig = entitiesConfig( state.config, action );\n\n\t// Generates a reducer for the entities nested by `kind` and `name`.\n\t// A config array with shape:\n\t// ```\n\t// [\n\t// { kind: 'taxonomy', name: 'category' },\n\t// { kind: 'taxonomy', name: 'post_tag' },\n\t// { kind: 'postType', name: 'post' },\n\t// { kind: 'postType', name: 'page' },\n\t// ]\n\t// ```\n\t// generates a reducer for state tree with shape:\n\t// ```\n\t// {\n\t// taxonomy: {\n\t// category,\n\t// post_tag,\n\t// },\n\t// postType: {\n\t// post,\n\t// page,\n\t// },\n\t// }\n\t// ```\n\tlet entitiesDataReducer = state.reducer;\n\tif ( ! entitiesDataReducer || newConfig !== state.config ) {\n\t\tconst entitiesByKind = newConfig.reduce( ( acc, record ) => {\n\t\t\tconst { kind } = record;\n\t\t\tif ( ! acc[ kind ] ) {\n\t\t\t\tacc[ kind ] = [];\n\t\t\t}\n\t\t\tacc[ kind ].push( record );\n\t\t\treturn acc;\n\t\t}, {} );\n\n\t\tentitiesDataReducer = combineReducers(\n\t\t\tObject.fromEntries(\n\t\t\t\tObject.entries( entitiesByKind ).map(\n\t\t\t\t\t( [ kind, subEntities ] ) => {\n\t\t\t\t\t\tconst kindReducer = combineReducers(\n\t\t\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\t\t\tsubEntities.map( ( entityConfig ) => [\n\t\t\t\t\t\t\t\t\tentityConfig.name,\n\t\t\t\t\t\t\t\t\tentity( entityConfig ),\n\t\t\t\t\t\t\t\t] )\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn [ kind, kindReducer ];\n\t\t\t\t\t}\n\t\t\t\t)\n\t\t\t)\n\t\t);\n\t}\n\n\tconst newData = entitiesDataReducer( state.records, action );\n\n\tif (\n\t\tnewData === state.records &&\n\t\tnewConfig === state.config &&\n\t\tentitiesDataReducer === state.reducer\n\t) {\n\t\treturn state;\n\t}\n\n\treturn {\n\t\treducer: entitiesDataReducer,\n\t\trecords: newData,\n\t\tconfig: newConfig,\n\t};\n};\n\n/**\n * @type {UndoManager}\n */\nexport function undoManager( state = createUndoManager() ) {\n\treturn state;\n}\n\nexport function editsReference( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'EDIT_ENTITY_RECORD':\n\t\tcase 'UNDO':\n\t\tcase 'REDO':\n\t\t\treturn {};\n\t}\n\treturn state;\n}\n\n/**\n * Reducer managing embed preview data.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function embedPreviews( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_EMBED_PREVIEW':\n\t\t\tconst { url, preview } = action;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ url ]: preview,\n\t\t\t};\n\t}\n\treturn state;\n}\n\n/**\n * State which tracks whether the user can perform an action on a REST\n * resource.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function userPermissions( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_USER_PERMISSION':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.key ]: action.isAllowed,\n\t\t\t};\n\t\tcase 'RECEIVE_USER_PERMISSIONS':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t...action.permissions,\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer returning autosaves keyed by their parent's post id.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function autosaves( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_AUTOSAVES':\n\t\t\tconst { postId, autosaves: autosavesData } = action;\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ postId ]: autosavesData,\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\nexport function blockPatterns( state = [], action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_BLOCK_PATTERNS':\n\t\t\treturn action.patterns;\n\t}\n\n\treturn state;\n}\n\nexport function blockPatternCategories( state = [], action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_BLOCK_PATTERN_CATEGORIES':\n\t\t\treturn action.categories;\n\t}\n\n\treturn state;\n}\n\nexport function userPatternCategories( state = [], action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_USER_PATTERN_CATEGORIES':\n\t\t\treturn action.patternCategories;\n\t}\n\treturn state;\n}\n\nexport function navigationFallbackId( state = null, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_NAVIGATION_FALLBACK_ID':\n\t\t\treturn action.fallbackId;\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing the theme global styles revisions.\n *\n * @param {Record<string, object>} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Record<string, object>} Updated state.\n */\nexport function themeGlobalStyleRevisions( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_THEME_GLOBAL_STYLE_REVISIONS':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.currentId ]: action.revisions,\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing the template lookup per query.\n *\n * @param {Record<string, string>} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Record<string, string>} Updated state.\n */\nexport function defaultTemplates( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_DEFAULT_TEMPLATE':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ JSON.stringify( action.query ) ]: action.templateId,\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer returning an object of registered post meta.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function registeredPostMeta( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_REGISTERED_POST_META':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.postType ]: action.registeredPostMeta,\n\t\t\t};\n\t}\n\treturn state;\n}\n\n/**\n * Reducer managing editor settings.\n *\n * @param {Object} state Current state.\n * @param {Object} action Action object.\n *\n * @return {Object} Updated state.\n */\nexport function editorSettings( state = null, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_EDITOR_SETTINGS':\n\t\t\treturn action.settings;\n\t}\n\treturn state;\n}\n\n/**\n * Reducer managing editor assets.\n *\n * @param {Object} state Current state.\n * @param {Object} action Action object.\n *\n * @return {Object} Updated state.\n */\nexport function editorAssets( state = null, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_EDITOR_ASSETS':\n\t\t\treturn action.assets;\n\t}\n\treturn state;\n}\n\n/**\n * Reducer managing sync connection states for entities.\n * Keyed by \"kind/name:id\" (e.g., \"postType/post:123\").\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function syncConnectionStatuses( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'SET_SYNC_CONNECTION_STATUS': {\n\t\t\tconst key = `${ action.kind }/${ action.name }:${ action.key }`;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ key ]: action.status,\n\t\t\t};\n\t\t}\n\t\tcase 'CLEAR_SYNC_CONNECTION_STATUS': {\n\t\t\tconst key = `${ action.kind }/${ action.name }:${ action.key }`;\n\t\t\tconst { [ key ]: _, ...rest } = state;\n\t\t\treturn rest;\n\t\t}\n\t}\n\treturn state;\n}\n\n/**\n * Reducer managing whether collaboration is supported.\n *\n * Default to true, as collaboration is supported by default\n * unless explicitly disabled due to unsupported conditions\n * such as metaboxes.\n *\n * @param {boolean} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {boolean} Updated state.\n */\nexport function collaborationSupported( state = true, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'SET_COLLABORATION_SUPPORTED':\n\t\t\treturn action.supported;\n\t}\n\treturn state;\n}\n\nexport default combineReducers( {\n\tusers,\n\tcurrentTheme,\n\tcurrentGlobalStylesId,\n\tcurrentUser,\n\tthemeGlobalStyleVariations,\n\tthemeBaseGlobalStyles,\n\tthemeGlobalStyleRevisions,\n\tentities,\n\teditsReference,\n\tundoManager,\n\tembedPreviews,\n\tuserPermissions,\n\tautosaves,\n\tblockPatterns,\n\tblockPatternCategories,\n\tuserPatternCategories,\n\tnavigationFallbackId,\n\tdefaultTemplates,\n\tregisteredPostMeta,\n\teditorSettings,\n\teditorAssets,\n\tsyncConnectionStatuses,\n\tcollaborationSupported,\n} );\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA0B;AAK1B,qBAAwB;AACxB,kBAAgC;AAChC,0BAAkC;AAKlC,mBAAgD;AAChD,0BAA8C;AAC9C,sBAAuD;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6/index.js';\n\n/**\n * WordPress dependencies\n */\nimport { compose } from '@wordpress/compose';\nimport { combineReducers } from '@wordpress/data';\nimport { createUndoManager } from '@wordpress/undo-manager';\n\n/**\n * Internal dependencies\n */\nimport { ifMatchingAction, replaceAction } from './utils';\nimport { reducer as queriedDataReducer } from './queried-data';\nimport { rootEntitiesConfig, DEFAULT_ENTITY_KEY } from './entities';\nimport { ConnectionErrorCode } from './sync';\n\n/** @typedef {import('./types').AnyFunction} AnyFunction */\n\n/**\n * Reducer managing authors state. Keyed by id.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function users( state = { byId: {}, queries: {} }, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_USER_QUERY':\n\t\t\treturn {\n\t\t\t\tbyId: {\n\t\t\t\t\t...state.byId,\n\t\t\t\t\t// Key users by their ID.\n\t\t\t\t\t...action.users.reduce(\n\t\t\t\t\t\t( newUsers, user ) => ( {\n\t\t\t\t\t\t\t...newUsers,\n\t\t\t\t\t\t\t[ user.id ]: user,\n\t\t\t\t\t\t} ),\n\t\t\t\t\t\t{}\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t\tqueries: {\n\t\t\t\t\t...state.queries,\n\t\t\t\t\t[ action.queryID ]: action.users.map( ( user ) => user.id ),\n\t\t\t\t},\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing current user state.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function currentUser( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_CURRENT_USER':\n\t\t\treturn action.currentUser;\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing the current theme.\n *\n * @param {string|undefined} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {string|undefined} Updated state.\n */\nexport function currentTheme( state = undefined, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_CURRENT_THEME':\n\t\t\treturn action.currentTheme.stylesheet;\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing the current global styles id.\n *\n * @param {string|undefined} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {string|undefined} Updated state.\n */\nexport function currentGlobalStylesId( state = undefined, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_CURRENT_GLOBAL_STYLES_ID':\n\t\t\treturn action.id;\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing the theme base global styles.\n *\n * @param {Record<string, object>} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Record<string, object>} Updated state.\n */\nexport function themeBaseGlobalStyles( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_THEME_GLOBAL_STYLES':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.stylesheet ]: action.globalStyles,\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing the theme global styles variations.\n *\n * @param {Record<string, object>} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Record<string, object>} Updated state.\n */\nexport function themeGlobalStyleVariations( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_THEME_GLOBAL_STYLE_VARIATIONS':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.stylesheet ]: action.variations,\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\nconst withMultiEntityRecordEdits = ( reducer ) => ( state, action ) => {\n\tif ( action.type === 'UNDO' || action.type === 'REDO' ) {\n\t\tconst { record } = action;\n\n\t\tlet newState = state;\n\t\trecord.forEach( ( { id: { kind, name, recordId }, changes } ) => {\n\t\t\tnewState = reducer( newState, {\n\t\t\t\ttype: 'EDIT_ENTITY_RECORD',\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId,\n\t\t\t\tedits: Object.entries( changes ).reduce(\n\t\t\t\t\t( acc, [ key, value ] ) => {\n\t\t\t\t\t\tacc[ key ] =\n\t\t\t\t\t\t\taction.type === 'UNDO' ? value.from : value.to;\n\t\t\t\t\t\treturn acc;\n\t\t\t\t\t},\n\t\t\t\t\t{}\n\t\t\t\t),\n\t\t\t} );\n\t\t} );\n\t\treturn newState;\n\t}\n\n\treturn reducer( state, action );\n};\n\n/**\n * Higher Order Reducer for a given entity config. It supports:\n *\n * - Fetching\n * - Editing\n * - Saving\n *\n * @param {Object} entityConfig Entity config.\n *\n * @return {AnyFunction} Reducer.\n */\nfunction entity( entityConfig ) {\n\treturn compose( [\n\t\twithMultiEntityRecordEdits,\n\n\t\t// Limit to matching action type so we don't attempt to replace action on\n\t\t// an unhandled action.\n\t\tifMatchingAction(\n\t\t\t( action ) =>\n\t\t\t\taction.name &&\n\t\t\t\taction.kind &&\n\t\t\t\taction.name === entityConfig.name &&\n\t\t\t\taction.kind === entityConfig.kind\n\t\t),\n\n\t\t// Inject the entity config into the action.\n\t\treplaceAction( ( action ) => {\n\t\t\treturn {\n\t\t\t\tkey: entityConfig.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t...action,\n\t\t\t};\n\t\t} ),\n\t] )(\n\t\tcombineReducers( {\n\t\t\tqueriedData: queriedDataReducer,\n\t\t\tedits: ( state = {}, action ) => {\n\t\t\t\tswitch ( action.type ) {\n\t\t\t\t\tcase 'RECEIVE_ITEMS':\n\t\t\t\t\t\tconst context = action?.query?.context ?? 'default';\n\t\t\t\t\t\tif ( context !== 'default' ) {\n\t\t\t\t\t\t\treturn state;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst nextState = { ...state };\n\t\t\t\t\t\tconst itemsList = Array.isArray( action.items )\n\t\t\t\t\t\t\t? action.items\n\t\t\t\t\t\t\t: [ action.items ];\n\n\t\t\t\t\t\tfor ( const record of itemsList ) {\n\t\t\t\t\t\t\tconst recordId = record?.[ action.key ];\n\t\t\t\t\t\t\tconst edits = nextState[ recordId ];\n\t\t\t\t\t\t\tif ( ! edits ) {\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst nextEdits = Object.keys( edits ).reduce(\n\t\t\t\t\t\t\t\t( acc, key ) => {\n\t\t\t\t\t\t\t\t\t// If the edited value is still different to the persisted value,\n\t\t\t\t\t\t\t\t\t// keep the edited value in edits.\n\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t// Edits are the \"raw\" attribute values, but records may have\n\t\t\t\t\t\t\t\t\t\t// objects with more properties, so we use `get` here for the\n\t\t\t\t\t\t\t\t\t\t// comparison.\n\t\t\t\t\t\t\t\t\t\t! fastDeepEqual(\n\t\t\t\t\t\t\t\t\t\t\tedits[ key ],\n\t\t\t\t\t\t\t\t\t\t\trecord[ key ]?.raw ?? record[ key ]\n\t\t\t\t\t\t\t\t\t\t) &&\n\t\t\t\t\t\t\t\t\t\t// Sometimes the server alters the sent value which means\n\t\t\t\t\t\t\t\t\t\t// we need to also remove the edits before the api request.\n\t\t\t\t\t\t\t\t\t\t( ! action.persistedEdits ||\n\t\t\t\t\t\t\t\t\t\t\t! fastDeepEqual(\n\t\t\t\t\t\t\t\t\t\t\t\tedits[ key ],\n\t\t\t\t\t\t\t\t\t\t\t\taction.persistedEdits[ key ]\n\t\t\t\t\t\t\t\t\t\t\t) )\n\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\tacc[ key ] = edits[ key ];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn acc;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{}\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tif ( Object.keys( nextEdits ).length ) {\n\t\t\t\t\t\t\t\tnextState[ recordId ] = nextEdits;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tdelete nextState[ recordId ];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn nextState;\n\n\t\t\t\t\tcase 'EDIT_ENTITY_RECORD':\n\t\t\t\t\t\tconst nextEdits = {\n\t\t\t\t\t\t\t...state[ action.recordId ],\n\t\t\t\t\t\t\t...action.edits,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tObject.keys( nextEdits ).forEach( ( key ) => {\n\t\t\t\t\t\t\t// Delete cleared edits so that the properties\n\t\t\t\t\t\t\t// are not considered dirty.\n\t\t\t\t\t\t\tif ( nextEdits[ key ] === undefined ) {\n\t\t\t\t\t\t\t\tdelete nextEdits[ key ];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} );\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...state,\n\t\t\t\t\t\t\t[ action.recordId ]: nextEdits,\n\t\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn state;\n\t\t\t},\n\n\t\t\tsaving: ( state = {}, action ) => {\n\t\t\t\tswitch ( action.type ) {\n\t\t\t\t\tcase 'SAVE_ENTITY_RECORD_START':\n\t\t\t\t\tcase 'SAVE_ENTITY_RECORD_FINISH':\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...state,\n\t\t\t\t\t\t\t[ action.recordId ]: {\n\t\t\t\t\t\t\t\tpending:\n\t\t\t\t\t\t\t\t\taction.type === 'SAVE_ENTITY_RECORD_START',\n\t\t\t\t\t\t\t\terror: action.error,\n\t\t\t\t\t\t\t\tisAutosave: action.isAutosave,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn state;\n\t\t\t},\n\n\t\t\tdeleting: ( state = {}, action ) => {\n\t\t\t\tswitch ( action.type ) {\n\t\t\t\t\tcase 'DELETE_ENTITY_RECORD_START':\n\t\t\t\t\tcase 'DELETE_ENTITY_RECORD_FINISH':\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...state,\n\t\t\t\t\t\t\t[ action.recordId ]: {\n\t\t\t\t\t\t\t\tpending:\n\t\t\t\t\t\t\t\t\taction.type ===\n\t\t\t\t\t\t\t\t\t'DELETE_ENTITY_RECORD_START',\n\t\t\t\t\t\t\t\terror: action.error,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn state;\n\t\t\t},\n\n\t\t\trevisions: ( state = {}, action ) => {\n\t\t\t\t// Use the same queriedDataReducer shape for revisions.\n\t\t\t\tif ( action.type === 'RECEIVE_ITEM_REVISIONS' ) {\n\t\t\t\t\tconst recordKey = action.recordKey;\n\t\t\t\t\tdelete action.recordKey;\n\t\t\t\t\tconst newState = queriedDataReducer( state[ recordKey ], {\n\t\t\t\t\t\t...action,\n\t\t\t\t\t\ttype: 'RECEIVE_ITEMS',\n\t\t\t\t\t} );\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...state,\n\t\t\t\t\t\t[ recordKey ]: newState,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tif ( action.type === 'REMOVE_ITEMS' ) {\n\t\t\t\t\treturn Object.fromEntries(\n\t\t\t\t\t\tObject.entries( state ).filter(\n\t\t\t\t\t\t\t( [ id ] ) =>\n\t\t\t\t\t\t\t\t! action.itemIds.some( ( itemId ) => {\n\t\t\t\t\t\t\t\t\tif ( Number.isInteger( itemId ) ) {\n\t\t\t\t\t\t\t\t\t\treturn itemId === +id;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn itemId === id;\n\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn state;\n\t\t\t},\n\t\t} )\n\t);\n}\n\n/**\n * Reducer keeping track of the registered entities.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function entitiesConfig( state = rootEntitiesConfig, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'ADD_ENTITIES':\n\t\t\treturn [ ...state, ...action.entities ];\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer keeping track of the registered entities config and data.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport const entities = ( state = {}, action ) => {\n\tconst newConfig = entitiesConfig( state.config, action );\n\n\t// Generates a reducer for the entities nested by `kind` and `name`.\n\t// A config array with shape:\n\t// ```\n\t// [\n\t// { kind: 'taxonomy', name: 'category' },\n\t// { kind: 'taxonomy', name: 'post_tag' },\n\t// { kind: 'postType', name: 'post' },\n\t// { kind: 'postType', name: 'page' },\n\t// ]\n\t// ```\n\t// generates a reducer for state tree with shape:\n\t// ```\n\t// {\n\t// taxonomy: {\n\t// category,\n\t// post_tag,\n\t// },\n\t// postType: {\n\t// post,\n\t// page,\n\t// },\n\t// }\n\t// ```\n\tlet entitiesDataReducer = state.reducer;\n\tif ( ! entitiesDataReducer || newConfig !== state.config ) {\n\t\tconst entitiesByKind = newConfig.reduce( ( acc, record ) => {\n\t\t\tconst { kind } = record;\n\t\t\tif ( ! acc[ kind ] ) {\n\t\t\t\tacc[ kind ] = [];\n\t\t\t}\n\t\t\tacc[ kind ].push( record );\n\t\t\treturn acc;\n\t\t}, {} );\n\n\t\tentitiesDataReducer = combineReducers(\n\t\t\tObject.fromEntries(\n\t\t\t\tObject.entries( entitiesByKind ).map(\n\t\t\t\t\t( [ kind, subEntities ] ) => {\n\t\t\t\t\t\tconst kindReducer = combineReducers(\n\t\t\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\t\t\tsubEntities.map( ( entityConfig ) => [\n\t\t\t\t\t\t\t\t\tentityConfig.name,\n\t\t\t\t\t\t\t\t\tentity( entityConfig ),\n\t\t\t\t\t\t\t\t] )\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn [ kind, kindReducer ];\n\t\t\t\t\t}\n\t\t\t\t)\n\t\t\t)\n\t\t);\n\t}\n\n\tconst newData = entitiesDataReducer( state.records, action );\n\n\tif (\n\t\tnewData === state.records &&\n\t\tnewConfig === state.config &&\n\t\tentitiesDataReducer === state.reducer\n\t) {\n\t\treturn state;\n\t}\n\n\treturn {\n\t\treducer: entitiesDataReducer,\n\t\trecords: newData,\n\t\tconfig: newConfig,\n\t};\n};\n\n/**\n * @type {UndoManager}\n */\nexport function undoManager( state = createUndoManager() ) {\n\treturn state;\n}\n\nexport function editsReference( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'EDIT_ENTITY_RECORD':\n\t\tcase 'UNDO':\n\t\tcase 'REDO':\n\t\t\treturn {};\n\t}\n\treturn state;\n}\n\n/**\n * Reducer managing embed preview data.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function embedPreviews( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_EMBED_PREVIEW':\n\t\t\tconst { url, preview } = action;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ url ]: preview,\n\t\t\t};\n\t}\n\treturn state;\n}\n\n/**\n * State which tracks whether the user can perform an action on a REST\n * resource.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function userPermissions( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_USER_PERMISSION':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.key ]: action.isAllowed,\n\t\t\t};\n\t\tcase 'RECEIVE_USER_PERMISSIONS':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t...action.permissions,\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer returning autosaves keyed by their parent's post id.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function autosaves( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_AUTOSAVES':\n\t\t\tconst { postId, autosaves: autosavesData } = action;\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ postId ]: autosavesData,\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\nexport function blockPatterns( state = [], action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_BLOCK_PATTERNS':\n\t\t\treturn action.patterns;\n\t}\n\n\treturn state;\n}\n\nexport function blockPatternCategories( state = [], action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_BLOCK_PATTERN_CATEGORIES':\n\t\t\treturn action.categories;\n\t}\n\n\treturn state;\n}\n\nexport function userPatternCategories( state = [], action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_USER_PATTERN_CATEGORIES':\n\t\t\treturn action.patternCategories;\n\t}\n\treturn state;\n}\n\nexport function navigationFallbackId( state = null, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_NAVIGATION_FALLBACK_ID':\n\t\t\treturn action.fallbackId;\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing the theme global styles revisions.\n *\n * @param {Record<string, object>} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Record<string, object>} Updated state.\n */\nexport function themeGlobalStyleRevisions( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_THEME_GLOBAL_STYLE_REVISIONS':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.currentId ]: action.revisions,\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing the template lookup per query.\n *\n * @param {Record<string, string>} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Record<string, string>} Updated state.\n */\nexport function defaultTemplates( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_DEFAULT_TEMPLATE':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ JSON.stringify( action.query ) ]: action.templateId,\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer returning an object of registered post meta.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function registeredPostMeta( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_REGISTERED_POST_META':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.postType ]: action.registeredPostMeta,\n\t\t\t};\n\t}\n\treturn state;\n}\n\n/**\n * Reducer managing editor settings.\n *\n * @param {Object} state Current state.\n * @param {Object} action Action object.\n *\n * @return {Object} Updated state.\n */\nexport function editorSettings( state = null, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_EDITOR_SETTINGS':\n\t\t\treturn action.settings;\n\t}\n\treturn state;\n}\n\n/**\n * Reducer managing editor assets.\n *\n * @param {Object} state Current state.\n * @param {Object} action Action object.\n *\n * @return {Object} Updated state.\n */\nexport function editorAssets( state = null, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_EDITOR_ASSETS':\n\t\t\treturn action.assets;\n\t}\n\treturn state;\n}\n\n/**\n * Reducer managing sync connection states for entities.\n * Keyed by \"kind/name:id\" (e.g., \"postType/post:123\").\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function syncConnectionStatuses( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'SET_SYNC_CONNECTION_STATUS': {\n\t\t\tconst key = `${ action.kind }/${ action.name }:${ action.key }`;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ key ]: action.status,\n\t\t\t};\n\t\t}\n\t\tcase 'CLEAR_SYNC_CONNECTION_STATUS': {\n\t\t\tconst key = `${ action.kind }/${ action.name }:${ action.key }`;\n\t\t\tconst { [ key ]: _, ...rest } = state;\n\t\t\treturn rest;\n\t\t}\n\t}\n\treturn state;\n}\n\n/**\n * Reducer managing whether collaboration is supported.\n *\n * Default to true, as collaboration is supported by default\n * unless explicitly disabled due to unsupported conditions\n * such as metaboxes.\n *\n * @param {boolean} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {boolean} Updated state.\n */\nexport function collaborationSupported( state = true, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'SET_COLLABORATION_SUPPORTED':\n\t\t\treturn action.supported;\n\n\t\tcase 'SET_SYNC_CONNECTION_STATUS':\n\t\t\tif (\n\t\t\t\tConnectionErrorCode.DOCUMENT_SIZE_LIMIT_EXCEEDED ===\n\t\t\t\taction.status?.error?.code\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn state;\n\t}\n\treturn state;\n}\n\nexport default combineReducers( {\n\tusers,\n\tcurrentTheme,\n\tcurrentGlobalStylesId,\n\tcurrentUser,\n\tthemeGlobalStyleVariations,\n\tthemeBaseGlobalStyles,\n\tthemeGlobalStyleRevisions,\n\tentities,\n\teditsReference,\n\tundoManager,\n\tembedPreviews,\n\tuserPermissions,\n\tautosaves,\n\tblockPatterns,\n\tblockPatternCategories,\n\tuserPatternCategories,\n\tnavigationFallbackId,\n\tdefaultTemplates,\n\tregisteredPostMeta,\n\teditorSettings,\n\teditorAssets,\n\tsyncConnectionStatuses,\n\tcollaborationSupported,\n} );\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA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,IACtB,KAAK;AACJ,aAAO,OAAO;AAAA,EAChB;AACA,SAAO;AACR;AAWO,SAAS,uBAAwB,QAAQ,CAAC,GAAG,QAAS;AAC5D,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK,8BAA8B;AAClC,YAAM,MAAM,GAAI,OAAO,IAAK,IAAK,OAAO,IAAK,IAAK,OAAO,GAAI;AAC7D,aAAO;AAAA,QACN,GAAG;AAAA,QACH,CAAE,GAAI,GAAG,OAAO;AAAA,MACjB;AAAA,IACD;AAAA,IACA,KAAK,gCAAgC;AACpC,YAAM,MAAM,GAAI,OAAO,IAAK,IAAK,OAAO,IAAK,IAAK,OAAO,GAAI;AAC7D,YAAM,EAAE,CAAE,GAAI,GAAG,GAAG,GAAG,KAAK,IAAI;AAChC,aAAO;AAAA,IACR;AAAA,EACD;AACA,SAAO;AACR;AAcO,SAAS,uBAAwB,QAAQ,MAAM,QAAS;AAC9D,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK;AACJ,aAAO,OAAO;AAAA,IAEf,KAAK;AACJ,UACC,gCAAoB,iCACpB,OAAO,QAAQ,OAAO,MACrB;AACD,eAAO;AAAA,MACR;AAEA,aAAO;AAAA,EACT;AACA,SAAO;AACR;AAEA,IAAO,sBAAQ,6BAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,CAAE;",
|
|
6
6
|
"names": ["queriedDataReducer", "nextEdits", "fastDeepEqual"]
|
|
7
7
|
}
|
package/build/sync.cjs
CHANGED
|
@@ -22,6 +22,7 @@ var sync_exports = {};
|
|
|
22
22
|
__export(sync_exports, {
|
|
23
23
|
CRDT_DOC_META_PERSISTENCE_KEY: () => CRDT_DOC_META_PERSISTENCE_KEY,
|
|
24
24
|
CRDT_RECORD_MAP_KEY: () => CRDT_RECORD_MAP_KEY,
|
|
25
|
+
ConnectionErrorCode: () => ConnectionErrorCode,
|
|
25
26
|
Delta: () => Delta,
|
|
26
27
|
LOCAL_EDITOR_ORIGIN: () => LOCAL_EDITOR_ORIGIN,
|
|
27
28
|
LOCAL_UNDO_IGNORED_ORIGIN: () => LOCAL_UNDO_IGNORED_ORIGIN,
|
|
@@ -32,6 +33,7 @@ module.exports = __toCommonJS(sync_exports);
|
|
|
32
33
|
var import_sync = require("@wordpress/sync");
|
|
33
34
|
var import_lock_unlock = require("./lock-unlock.cjs");
|
|
34
35
|
var {
|
|
36
|
+
ConnectionErrorCode,
|
|
35
37
|
createSyncManager,
|
|
36
38
|
Delta,
|
|
37
39
|
CRDT_DOC_META_PERSISTENCE_KEY,
|
|
@@ -52,6 +54,7 @@ function getSyncManager() {
|
|
|
52
54
|
0 && (module.exports = {
|
|
53
55
|
CRDT_DOC_META_PERSISTENCE_KEY,
|
|
54
56
|
CRDT_RECORD_MAP_KEY,
|
|
57
|
+
ConnectionErrorCode,
|
|
55
58
|
Delta,
|
|
56
59
|
LOCAL_EDITOR_ORIGIN,
|
|
57
60
|
LOCAL_UNDO_IGNORED_ORIGIN,
|
package/build/sync.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/sync.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tprivateApis as syncPrivateApis,\n\ttype SyncManager,\n} from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from './lock-unlock';\n\nconst {\n\tcreateSyncManager,\n\tDelta,\n\tCRDT_DOC_META_PERSISTENCE_KEY,\n\tCRDT_RECORD_MAP_KEY,\n\tLOCAL_EDITOR_ORIGIN,\n\tLOCAL_UNDO_IGNORED_ORIGIN,\n\tretrySyncConnection,\n} = unlock( syncPrivateApis );\n\nexport {\n\tDelta,\n\tCRDT_DOC_META_PERSISTENCE_KEY,\n\tCRDT_RECORD_MAP_KEY,\n\tLOCAL_EDITOR_ORIGIN,\n\tLOCAL_UNDO_IGNORED_ORIGIN,\n\tretrySyncConnection,\n};\n\nlet syncManager: SyncManager;\n\nexport function getSyncManager(): SyncManager | undefined {\n\tif ( syncManager ) {\n\t\treturn syncManager;\n\t}\n\n\tsyncManager = createSyncManager();\n\n\treturn syncManager;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAGO;AAKP,yBAAuB;AAEvB,IAAM;AAAA,EACL;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,QAAI,2BAAQ,YAAAA,WAAgB;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tprivateApis as syncPrivateApis,\n\ttype SyncManager,\n} from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from './lock-unlock';\n\nconst {\n\tConnectionErrorCode,\n\tcreateSyncManager,\n\tDelta,\n\tCRDT_DOC_META_PERSISTENCE_KEY,\n\tCRDT_RECORD_MAP_KEY,\n\tLOCAL_EDITOR_ORIGIN,\n\tLOCAL_UNDO_IGNORED_ORIGIN,\n\tretrySyncConnection,\n} = unlock( syncPrivateApis );\n\nexport {\n\tConnectionErrorCode,\n\tDelta,\n\tCRDT_DOC_META_PERSISTENCE_KEY,\n\tCRDT_RECORD_MAP_KEY,\n\tLOCAL_EDITOR_ORIGIN,\n\tLOCAL_UNDO_IGNORED_ORIGIN,\n\tretrySyncConnection,\n};\n\nlet syncManager: SyncManager;\n\nexport function getSyncManager(): SyncManager | undefined {\n\tif ( syncManager ) {\n\t\treturn syncManager;\n\t}\n\n\tsyncManager = createSyncManager();\n\n\treturn syncManager;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAGO;AAKP,yBAAuB;AAEvB,IAAM;AAAA,EACL;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,QAAI,2BAAQ,YAAAA,WAAgB;AAY5B,IAAI;AAEG,SAAS,iBAA0C;AACzD,MAAK,aAAc;AAClB,WAAO;AAAA,EACR;AAEA,gBAAc,kBAAkB;AAEhC,SAAO;AACR;",
|
|
6
6
|
"names": ["syncPrivateApis"]
|
|
7
7
|
}
|
package/build/types.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/types.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport type { Y } from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport type { SelectionType } from './utils/crdt-user-selections';\n\nexport interface AnyFunction {\n\t( ...args: any[] ): any;\n}\n\n/**\n * An index path from the root of the block tree to a specific block.\n *\n * For example, `[0, 1]` refers to `blocks[0].innerBlocks[1]`.\n *\n * These paths are \"absolute\" in that they start from the post content root\n * (not from the template root when \"Show Template\" mode is active).\n * Both the Yjs document and the block-editor store share the same tree\n * structure for post content blocks, so the same path can be used to\n * navigate either tree.\n */\nexport type AbsoluteBlockIndexPath = number[];\n\n/**\n * Avoid a circular dependency with @wordpress/editor\n *\n * Additionaly, this type marks `attributeKey` and `offset` as possibly\n * `undefined`, which can happen in two known scenarios:\n *\n * 1. If a user has an entire block highlighted (e.g., a `core/image` block).\n * 2. If there's an intermediate selection state while inserting a block, those\n * properties will be temporarily`undefined`.\n */\nexport interface WPBlockSelection {\n\tclientId: string;\n\tattributeKey?: string;\n\toffset?: number;\n}\n\nexport interface WPSelection {\n\tselectionEnd: WPBlockSelection;\n\tselectionStart: WPBlockSelection;\n\tinitialPosition?: number | null;\n}\n\n/**\n * The position of the cursor.\n */\nexport type CursorPosition = {\n\trelativePosition: Y.RelativePosition;\n\n\t// Also store the absolute offset index of the cursor from the perspective\n\t// of the user who is updating the selection.\n\t//\n\t// Do not use this value directly, instead use `createAbsolutePositionFromRelativePosition()`\n\t// on relativePosition for the most up-to-date positioning.\n\t//\n\t// This is used because local Y.Text changes (e.g. adding or deleting a character)\n\t// can result in the same relative position if it is pinned to an unchanged\n\t// character. With both of these values as editor state, a change in perceived\n\t// position will always result in a redraw.\n\tabsoluteOffset: number;\n};\n\n/**\n * The direction of a text selection, indicating where the caret sits.\n */\nexport enum SelectionDirection {\n\t/** The caret is at the end of the selection (default / left-to-right). */\n\tForward = 'f',\n\t/** The caret is at the start of the selection (right-to-left). */\n\tBackward = 'b',\n}\n\nexport type SelectionNone = {\n\t// The user has not made a selection.\n\ttype: SelectionType.None;\n};\n\nexport type SelectionCursor = {\n\t// The user has a cursor position in a block with no text highlighted.\n\t// The block is derived on the receiver side by navigating up from the\n\t// resolved cursorPosition via Y.AbstractType.parent.\n\ttype: SelectionType.Cursor;\n\tcursorPosition: CursorPosition;\n};\n\nexport type SelectionInOneBlock = {\n\t// The user has highlighted text in a single block.\n\t// The block is derived on the receiver side by navigating up from the\n\t// resolved cursorStartPosition via Y.AbstractType.parent.\n\ttype: SelectionType.SelectionInOneBlock;\n\tcursorStartPosition: CursorPosition;\n\tcursorEndPosition: CursorPosition;\n\t// The direction of the selection, indicating where the caret sits.\n\tselectionDirection?: SelectionDirection;\n};\n\nexport type SelectionInMultipleBlocks = {\n\t// The user has highlighted text over multiple blocks.\n\t// The blocks are derived on the receiver side by navigating up from the\n\t// resolved cursor positions via Y.AbstractType.parent.\n\ttype: SelectionType.SelectionInMultipleBlocks;\n\tcursorStartPosition: CursorPosition;\n\tcursorEndPosition: CursorPosition;\n\t// The direction of the selection, indicating where the caret sits.\n\tselectionDirection?: SelectionDirection;\n};\n\nexport type SelectionWholeBlock = {\n\t// The user has a non-text block selected, like an image block.\n\t// Uses a Y.RelativePosition pointing to the block in its parent Y.Array,\n\t// since there is no text cursor to navigate up from.\n\ttype: SelectionType.WholeBlock;\n\tblockPosition: Y.RelativePosition;\n};\n\nexport type SelectionState =\n\t| SelectionNone\n\t| SelectionCursor\n\t| SelectionInOneBlock\n\t| SelectionInMultipleBlocks\n\t| SelectionWholeBlock;\n\nexport interface ResolvedSelection {\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport type { ConnectionStatusDisconnected, Y } from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport type { SelectionType } from './utils/crdt-user-selections';\n\nexport type { ConnectionStatus } from '@wordpress/sync';\n\nexport type ConnectionError = NonNullable<\n\tConnectionStatusDisconnected[ 'error' ]\n>;\n\nexport interface AnyFunction {\n\t( ...args: any[] ): any;\n}\n\n/**\n * An index path from the root of the block tree to a specific block.\n *\n * For example, `[0, 1]` refers to `blocks[0].innerBlocks[1]`.\n *\n * These paths are \"absolute\" in that they start from the post content root\n * (not from the template root when \"Show Template\" mode is active).\n * Both the Yjs document and the block-editor store share the same tree\n * structure for post content blocks, so the same path can be used to\n * navigate either tree.\n */\nexport type AbsoluteBlockIndexPath = number[];\n\n/**\n * Avoid a circular dependency with @wordpress/editor\n *\n * Additionaly, this type marks `attributeKey` and `offset` as possibly\n * `undefined`, which can happen in two known scenarios:\n *\n * 1. If a user has an entire block highlighted (e.g., a `core/image` block).\n * 2. If there's an intermediate selection state while inserting a block, those\n * properties will be temporarily`undefined`.\n */\nexport interface WPBlockSelection {\n\tclientId: string;\n\tattributeKey?: string;\n\toffset?: number;\n}\n\nexport interface WPSelection {\n\tselectionEnd: WPBlockSelection;\n\tselectionStart: WPBlockSelection;\n\tinitialPosition?: number | null;\n}\n\n/**\n * The position of the cursor.\n */\nexport type CursorPosition = {\n\trelativePosition: Y.RelativePosition;\n\n\t// Also store the absolute offset index of the cursor from the perspective\n\t// of the user who is updating the selection.\n\t//\n\t// Do not use this value directly, instead use `createAbsolutePositionFromRelativePosition()`\n\t// on relativePosition for the most up-to-date positioning.\n\t//\n\t// This is used because local Y.Text changes (e.g. adding or deleting a character)\n\t// can result in the same relative position if it is pinned to an unchanged\n\t// character. With both of these values as editor state, a change in perceived\n\t// position will always result in a redraw.\n\tabsoluteOffset: number;\n};\n\n/**\n * The direction of a text selection, indicating where the caret sits.\n */\nexport enum SelectionDirection {\n\t/** The caret is at the end of the selection (default / left-to-right). */\n\tForward = 'f',\n\t/** The caret is at the start of the selection (right-to-left). */\n\tBackward = 'b',\n}\n\nexport type SelectionNone = {\n\t// The user has not made a selection.\n\ttype: SelectionType.None;\n};\n\nexport type SelectionCursor = {\n\t// The user has a cursor position in a block with no text highlighted.\n\t// The block is derived on the receiver side by navigating up from the\n\t// resolved cursorPosition via Y.AbstractType.parent.\n\ttype: SelectionType.Cursor;\n\tcursorPosition: CursorPosition;\n};\n\nexport type SelectionInOneBlock = {\n\t// The user has highlighted text in a single block.\n\t// The block is derived on the receiver side by navigating up from the\n\t// resolved cursorStartPosition via Y.AbstractType.parent.\n\ttype: SelectionType.SelectionInOneBlock;\n\tcursorStartPosition: CursorPosition;\n\tcursorEndPosition: CursorPosition;\n\t// The direction of the selection, indicating where the caret sits.\n\tselectionDirection?: SelectionDirection;\n};\n\nexport type SelectionInMultipleBlocks = {\n\t// The user has highlighted text over multiple blocks.\n\t// The blocks are derived on the receiver side by navigating up from the\n\t// resolved cursor positions via Y.AbstractType.parent.\n\ttype: SelectionType.SelectionInMultipleBlocks;\n\tcursorStartPosition: CursorPosition;\n\tcursorEndPosition: CursorPosition;\n\t// The direction of the selection, indicating where the caret sits.\n\tselectionDirection?: SelectionDirection;\n};\n\nexport type SelectionWholeBlock = {\n\t// The user has a non-text block selected, like an image block.\n\t// Uses a Y.RelativePosition pointing to the block in its parent Y.Array,\n\t// since there is no text cursor to navigate up from.\n\ttype: SelectionType.WholeBlock;\n\tblockPosition: Y.RelativePosition;\n};\n\nexport type SelectionState =\n\t| SelectionNone\n\t| SelectionCursor\n\t| SelectionInOneBlock\n\t| SelectionInMultipleBlocks\n\t| SelectionWholeBlock;\n\nexport interface ResolvedSelection {\n\trichTextOffset: number | null;\n\tlocalClientId: string | null;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA6EO,IAAK,qBAAL,kBAAKA,wBAAL;AAEN,EAAAA,oBAAA,aAAU;AAEV,EAAAA,oBAAA,cAAW;AAJA,SAAAA;AAAA,GAAA;",
|
|
6
6
|
"names": ["SelectionDirection"]
|
|
7
7
|
}
|
|
@@ -83,7 +83,7 @@ function convertWPBlockSelectionToSelection(selection, ydoc) {
|
|
|
83
83
|
const offset = selection.offset ?? 0;
|
|
84
84
|
const relativePosition = import_sync.Y.createRelativePositionFromTypeIndex(
|
|
85
85
|
changedYText,
|
|
86
|
-
offset
|
|
86
|
+
(0, import_crdt_utils.richTextOffsetToHtmlIndex)(changedYText.toString(), offset)
|
|
87
87
|
);
|
|
88
88
|
return {
|
|
89
89
|
type: "RelativeSelection" /* RelativeSelection */,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/block-selection-history.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\n/**\n * WordPress dependencies\n */\nimport { Y } from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,kBAAkB;AAKlB,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\n/**\n * WordPress dependencies\n */\nimport { Y } from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport {\n\tfindBlockByClientIdInDoc,\n\trichTextOffsetToHtmlIndex,\n} from './crdt-utils';\nimport type { WPBlockSelection, WPSelection } from '../types';\n\n// Default size for selection history (not including current selection)\nconst SELECTION_HISTORY_DEFAULT_SIZE = 5;\n\nexport enum YSelectionType {\n\tRelativeSelection = 'RelativeSelection',\n\tBlockSelection = 'BlockSelection',\n}\n\nexport interface YRelativeSelection {\n\ttype: YSelectionType.RelativeSelection;\n\tattributeKey: string;\n\trelativePosition: Y.RelativePosition;\n\tclientId: string;\n\toffset: number;\n}\n\nexport interface YBlockSelection {\n\ttype: YSelectionType.BlockSelection;\n\tclientId: string;\n}\n\nexport type YSelection = YRelativeSelection | YBlockSelection;\n\nexport type YFullSelection = {\n\tstart: YSelection;\n\tend: YSelection;\n};\n\nexport interface YSelectionHistory {\n\tselection: YFullSelection;\n\tbackupSelections?: YFullSelection[];\n}\n\nexport interface BlockSelectionHistory {\n\tgetSelectionHistory: () => YFullSelection[];\n\tupdateSelection: ( newSelection: WPSelection ) => void;\n}\n\n/**\n * This function is used to track recent block selections to help in restoring\n * a user's selection after an undo or redo operation.\n *\n * Maintains a history array for previous selections, which can be used for\n * backup restoration locations.\n * @param ydoc\n * @param historySize\n */\nexport function createBlockSelectionHistory(\n\tydoc: Y.Doc,\n\thistorySize: number = SELECTION_HISTORY_DEFAULT_SIZE\n): BlockSelectionHistory {\n\tlet history: YFullSelection[] = [];\n\n\t/**\n\t * Get the block history including current selection.\n\t */\n\tconst getSelectionHistory = (): YFullSelection[] => {\n\t\treturn history.slice( 0 );\n\t};\n\n\t/**\n\t * Update the selection history with a new selection.\n\t * @param newSelection\n\t */\n\tconst updateSelection = ( newSelection: WPSelection ): void => {\n\t\tif (\n\t\t\t! newSelection?.selectionStart?.clientId ||\n\t\t\t! newSelection?.selectionEnd?.clientId\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { selectionStart, selectionEnd } = newSelection;\n\t\tconst start = convertWPBlockSelectionToSelection(\n\t\t\tselectionStart,\n\t\t\tydoc\n\t\t);\n\t\tconst end = convertWPBlockSelectionToSelection( selectionEnd, ydoc );\n\n\t\taddToHistory( { start, end } );\n\t};\n\n\t/**\n\t * Add a selection to the history, maintaining only the last `historySize` unique selections.\n\t * New selections are added to the front.\n\t * Removes any existing entries with the same start and end block combination.\n\t * @param yFullSelection\n\t */\n\tconst addToHistory = ( yFullSelection: YFullSelection ): void => {\n\t\t// Remove any existing entries with the same start and end block combination\n\t\tconst startClientId = yFullSelection.start.clientId;\n\t\tconst endClientId = yFullSelection.end.clientId;\n\n\t\thistory = history.filter( ( entry ) => {\n\t\t\tconst isSameBlockCombination =\n\t\t\t\tentry.start.clientId === startClientId &&\n\t\t\t\tentry.end.clientId === endClientId;\n\n\t\t\treturn ! isSameBlockCombination;\n\t\t} );\n\n\t\t// Add the new selection to the front\n\t\thistory.unshift( yFullSelection );\n\n\t\t// Trim to max size (remove oldest entries from the back)\n\t\tif ( history.length > historySize + 1 ) {\n\t\t\thistory = history.slice( 0, historySize + 1 );\n\t\t}\n\t};\n\n\treturn {\n\t\tgetSelectionHistory,\n\t\tupdateSelection,\n\t};\n}\n\n/**\n * Convert a WPBlockSelection to a YSelection.\n * @param selection\n * @param ydoc\n * @return A YSelection object.\n */\nfunction convertWPBlockSelectionToSelection(\n\tselection: WPBlockSelection,\n\tydoc: Y.Doc\n): YSelection {\n\tconst clientId = selection.clientId;\n\tconst block = findBlockByClientIdInDoc( clientId, ydoc );\n\tconst attributes = block?.get( 'attributes' );\n\tconst attributeKey = selection.attributeKey;\n\n\tconst changedYText = attributeKey\n\t\t? attributes?.get( attributeKey )\n\t\t: undefined;\n\n\tconst isYText = changedYText instanceof Y.Text;\n\tconst isFullyDefinedSelection = attributeKey && clientId;\n\n\tif ( ! isYText || ! isFullyDefinedSelection ) {\n\t\t// We either don't have a valid YText (it's been deleted) or we've\n\t\t// been passed a selection that's just a block clientId.\n\t\t// Store as BlockSelection.\n\t\treturn {\n\t\t\ttype: YSelectionType.BlockSelection,\n\t\t\tclientId,\n\t\t};\n\t}\n\n\tconst offset = selection.offset ?? 0;\n\tconst relativePosition = Y.createRelativePositionFromTypeIndex(\n\t\tchangedYText,\n\t\trichTextOffsetToHtmlIndex( changedYText.toString(), offset )\n\t);\n\n\treturn {\n\t\ttype: YSelectionType.RelativeSelection,\n\t\tattributeKey,\n\t\trelativePosition,\n\t\tclientId,\n\t\toffset,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,kBAAkB;AAKlB,wBAGO;AAIP,IAAM,iCAAiC;AAEhC,IAAK,iBAAL,kBAAKA,oBAAL;AACN,EAAAA,gBAAA,uBAAoB;AACpB,EAAAA,gBAAA,oBAAiB;AAFN,SAAAA;AAAA,GAAA;AA4CL,SAAS,4BACf,MACA,cAAsB,gCACE;AACxB,MAAI,UAA4B,CAAC;AAKjC,QAAM,sBAAsB,MAAwB;AACnD,WAAO,QAAQ,MAAO,CAAE;AAAA,EACzB;AAMA,QAAM,kBAAkB,CAAE,iBAAqC;AAC9D,QACC,CAAE,cAAc,gBAAgB,YAChC,CAAE,cAAc,cAAc,UAC7B;AACD;AAAA,IACD;AAEA,UAAM,EAAE,gBAAgB,aAAa,IAAI;AACzC,UAAM,QAAQ;AAAA,MACb;AAAA,MACA;AAAA,IACD;AACA,UAAM,MAAM,mCAAoC,cAAc,IAAK;AAEnE,iBAAc,EAAE,OAAO,IAAI,CAAE;AAAA,EAC9B;AAQA,QAAM,eAAe,CAAE,mBAA0C;AAEhE,UAAM,gBAAgB,eAAe,MAAM;AAC3C,UAAM,cAAc,eAAe,IAAI;AAEvC,cAAU,QAAQ,OAAQ,CAAE,UAAW;AACtC,YAAM,yBACL,MAAM,MAAM,aAAa,iBACzB,MAAM,IAAI,aAAa;AAExB,aAAO,CAAE;AAAA,IACV,CAAE;AAGF,YAAQ,QAAS,cAAe;AAGhC,QAAK,QAAQ,SAAS,cAAc,GAAI;AACvC,gBAAU,QAAQ,MAAO,GAAG,cAAc,CAAE;AAAA,IAC7C;AAAA,EACD;AAEA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,EACD;AACD;AAQA,SAAS,mCACR,WACA,MACa;AACb,QAAM,WAAW,UAAU;AAC3B,QAAM,YAAQ,4CAA0B,UAAU,IAAK;AACvD,QAAM,aAAa,OAAO,IAAK,YAAa;AAC5C,QAAM,eAAe,UAAU;AAE/B,QAAM,eAAe,eAClB,YAAY,IAAK,YAAa,IAC9B;AAEH,QAAM,UAAU,wBAAwB,cAAE;AAC1C,QAAM,0BAA0B,gBAAgB;AAEhD,MAAK,CAAE,WAAW,CAAE,yBAA0B;AAI7C,WAAO;AAAA,MACN,MAAM;AAAA,MACN;AAAA,IACD;AAAA,EACD;AAEA,QAAM,SAAS,UAAU,UAAU;AACnC,QAAM,mBAAmB,cAAE;AAAA,IAC1B;AAAA,QACA,6CAA2B,aAAa,SAAS,GAAG,MAAO;AAAA,EAC5D;AAEA,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
6
|
"names": ["YSelectionType"]
|
|
7
7
|
}
|
|
@@ -42,6 +42,22 @@ var import_sync = require("@wordpress/sync");
|
|
|
42
42
|
var import_crdt_utils = require("./crdt-utils.cjs");
|
|
43
43
|
var import_sync2 = require("../sync.cjs");
|
|
44
44
|
var serializableBlocksCache = /* @__PURE__ */ new WeakMap();
|
|
45
|
+
function serializeAttributeValue(value) {
|
|
46
|
+
if (value instanceof import_rich_text.RichTextData) {
|
|
47
|
+
return value.valueOf();
|
|
48
|
+
}
|
|
49
|
+
if (Array.isArray(value)) {
|
|
50
|
+
return value.map(serializeAttributeValue);
|
|
51
|
+
}
|
|
52
|
+
if (value && typeof value === "object") {
|
|
53
|
+
const result = {};
|
|
54
|
+
for (const [k, v] of Object.entries(value)) {
|
|
55
|
+
result[k] = serializeAttributeValue(v);
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
45
61
|
function makeBlockAttributesSerializable(blockName, attributes) {
|
|
46
62
|
const newAttributes = { ...attributes };
|
|
47
63
|
for (const [key, value] of Object.entries(attributes)) {
|
|
@@ -49,9 +65,7 @@ function makeBlockAttributesSerializable(blockName, attributes) {
|
|
|
49
65
|
delete newAttributes[key];
|
|
50
66
|
continue;
|
|
51
67
|
}
|
|
52
|
-
|
|
53
|
-
newAttributes[key] = value.valueOf();
|
|
54
|
-
}
|
|
68
|
+
newAttributes[key] = serializeAttributeValue(value);
|
|
55
69
|
}
|
|
56
70
|
return newAttributes;
|
|
57
71
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/crdt-blocks.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport { v4 as uuidv4 } from 'uuid';\nimport fastDeepEqual from 'fast-deep-equal/es6/index.js';\n\n/**\n * WordPress dependencies\n */\n// @ts-expect-error No exported types.\nimport { getBlockTypes } from '@wordpress/blocks';\nimport { RichTextData } from '@wordpress/rich-text';\nimport { Y } from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport { createYMap, type YMapRecord, type YMapWrap } from './crdt-utils';\nimport { Delta } from '../sync';\n\ninterface BlockAttributes {\n\t[ key: string ]: unknown;\n}\n\ninterface BlockAttributeType {\n\trole?: string;\n\ttype?: string;\n}\n\ninterface BlockType {\n\tattributes?: Record< string, BlockAttributeType >;\n\tname: string;\n}\n\n// A block as represented in Gutenberg's data store.\nexport interface Block {\n\tattributes: BlockAttributes;\n\tclientId?: string;\n\tinnerBlocks: Block[];\n\tisValid?: boolean;\n\tname: string;\n\toriginalContent?: string;\n\tvalidationIssues?: string[]; // unserializable\n}\n\n// A block as represented in the CRDT document (Y.Map).\nexport interface YBlockRecord extends YMapRecord {\n\tattributes: YBlockAttributes;\n\tclientId: string;\n\tinnerBlocks: YBlocks;\n\tisValid?: boolean;\n\toriginalContent?: string;\n\tname: string;\n}\n\nexport type YBlock = YMapWrap< YBlockRecord >;\nexport type YBlocks = Y.Array< YBlock >;\n\n// Block attribute schema cannot be known at compile time, so we use Y.Map.\n// Attribute values will be typed as the union of `Y.Text` and `unknown`.\nexport type YBlockAttributes = Y.Map< Y.Text | unknown >;\n\nconst serializableBlocksCache = new WeakMap< WeakKey, Block[] >();\n\nfunction makeBlockAttributesSerializable(\n\tblockName: string,\n\tattributes: BlockAttributes\n): BlockAttributes {\n\tconst newAttributes = { ...attributes };\n\tfor ( const [ key, value ] of Object.entries( attributes ) ) {\n\t\tif ( isLocalAttribute( blockName, key ) ) {\n\t\t\tdelete newAttributes[ key ];\n\t\t\tcontinue;\n\t\t}\n\n\t\tif ( value instanceof RichTextData ) {\n\t\t\tnewAttributes[ key ] = value.valueOf();\n\t\t}\n\t}\n\treturn newAttributes;\n}\n\nfunction makeBlocksSerializable( blocks: Block[] ): Block[] {\n\treturn blocks.map( ( block: Block ) => {\n\t\tconst { name, innerBlocks, attributes, ...rest } = block;\n\t\tdelete rest.validationIssues;\n\t\treturn {\n\t\t\t...rest,\n\t\t\tname,\n\t\t\tattributes: makeBlockAttributesSerializable( name, attributes ),\n\t\t\tinnerBlocks: makeBlocksSerializable( innerBlocks ),\n\t\t};\n\t} );\n}\n\n/**\n * @param {any} gblock\n * @param {Y.Map} yblock\n */\nfunction areBlocksEqual( gblock: Block, yblock: YBlock ): boolean {\n\tconst yblockAsJson = yblock.toJSON();\n\n\t// we must not sync clientId, as this can't be generated consistently and\n\t// hence will lead to merge conflicts.\n\tconst overwrites = {\n\t\tinnerBlocks: null,\n\t\tclientId: null,\n\t};\n\tconst res = fastDeepEqual(\n\t\tObject.assign( {}, gblock, overwrites ),\n\t\tObject.assign( {}, yblockAsJson, overwrites )\n\t);\n\tconst inners = gblock.innerBlocks || [];\n\tconst yinners = yblock.get( 'innerBlocks' );\n\treturn (\n\t\tres &&\n\t\tinners.length === yinners?.length &&\n\t\tinners.every( ( block: Block, i: number ) =>\n\t\t\tareBlocksEqual( block, yinners.get( i ) )\n\t\t)\n\t);\n}\n\nfunction createNewYAttributeMap(\n\tblockName: string,\n\tattributes: BlockAttributes\n): YBlockAttributes {\n\treturn new Y.Map(\n\t\tObject.entries( attributes ).map(\n\t\t\t( [ attributeName, attributeValue ] ) => {\n\t\t\t\treturn [\n\t\t\t\t\tattributeName,\n\t\t\t\t\tcreateNewYAttributeValue(\n\t\t\t\t\t\tblockName,\n\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\tattributeValue\n\t\t\t\t\t),\n\t\t\t\t];\n\t\t\t}\n\t\t)\n\t);\n}\n\nfunction createNewYAttributeValue(\n\tblockName: string,\n\tattributeName: string,\n\tattributeValue: unknown\n): Y.Text | unknown {\n\tconst isRichText = isRichTextAttribute( blockName, attributeName );\n\n\tif ( isRichText ) {\n\t\treturn new Y.Text( attributeValue?.toString() ?? '' );\n\t}\n\n\treturn attributeValue;\n}\n\nfunction createNewYBlock( block: Block ): YBlock {\n\treturn createYMap< YBlockRecord >(\n\t\tObject.fromEntries(\n\t\t\tObject.entries( block ).map( ( [ key, value ] ) => {\n\t\t\t\tswitch ( key ) {\n\t\t\t\t\tcase 'attributes': {\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\tcreateNewYAttributeMap( block.name, value ),\n\t\t\t\t\t\t];\n\t\t\t\t\t}\n\n\t\t\t\t\tcase 'innerBlocks': {\n\t\t\t\t\t\tconst innerBlocks = new Y.Array();\n\n\t\t\t\t\t\t// If not an array, set to empty Y.Array.\n\t\t\t\t\t\tif ( ! Array.isArray( value ) ) {\n\t\t\t\t\t\t\treturn [ key, innerBlocks ];\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tinnerBlocks.insert(\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\tvalue.map( ( innerBlock: Block ) =>\n\t\t\t\t\t\t\t\tcreateNewYBlock( innerBlock )\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn [ key, innerBlocks ];\n\t\t\t\t\t}\n\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn [ key, value ];\n\t\t\t\t}\n\t\t\t} )\n\t\t)\n\t);\n}\n\n/**\n * Merge incoming block data into the local Y.Doc.\n * This function is called to sync local block changes to a shared Y.Doc.\n *\n * @param yblocks The blocks in the local Y.Doc.\n * @param incomingBlocks Gutenberg blocks being synced.\n * @param cursorPosition The position of the cursor after the change occurs.\n */\nexport function mergeCrdtBlocks(\n\tyblocks: YBlocks,\n\tincomingBlocks: Block[],\n\tcursorPosition: number | null\n): void {\n\t// Ensure we are working with serializable block data.\n\tif ( ! serializableBlocksCache.has( incomingBlocks ) ) {\n\t\tserializableBlocksCache.set(\n\t\t\tincomingBlocks,\n\t\t\tmakeBlocksSerializable( incomingBlocks )\n\t\t);\n\t}\n\tconst blocksToSync = serializableBlocksCache.get( incomingBlocks ) ?? [];\n\n\t// This is a rudimentary diff implementation similar to the y-prosemirror diffing\n\t// approach.\n\t// A better implementation would also diff the textual content and represent it\n\t// using a Y.Text type.\n\t// However, at this time it makes more sense to keep this algorithm generic to\n\t// support all kinds of block types.\n\t// Ideally, we ensure that block data structure have a consistent data format.\n\t// E.g.:\n\t// - textual content (using rich-text formatting?) may always be stored under `block.text`\n\t// - local information that shouldn't be shared (e.g. clientId or isDragging) is stored under `block.private`\n\t//\n\t// @credit Kevin Jahns (dmonad)\n\t// @link https://github.com/WordPress/gutenberg/pull/68483\n\tconst numOfCommonEntries = Math.min(\n\t\tblocksToSync.length ?? 0,\n\t\tyblocks.length\n\t);\n\n\tlet left = 0;\n\tlet right = 0;\n\n\t// skip equal blocks from left\n\tfor (\n\t\t;\n\t\tleft < numOfCommonEntries &&\n\t\tareBlocksEqual( blocksToSync[ left ], yblocks.get( left ) );\n\t\tleft++\n\t) {\n\t\t/* nop */\n\t}\n\n\t// skip equal blocks from right\n\tfor (\n\t\t;\n\t\tright < numOfCommonEntries - left &&\n\t\tareBlocksEqual(\n\t\t\tblocksToSync[ blocksToSync.length - right - 1 ],\n\t\t\tyblocks.get( yblocks.length - right - 1 )\n\t\t);\n\t\tright++\n\t) {\n\t\t/* nop */\n\t}\n\n\tconst numOfUpdatesNeeded = numOfCommonEntries - left - right;\n\tconst numOfInsertionsNeeded = Math.max(\n\t\t0,\n\t\tblocksToSync.length - yblocks.length\n\t);\n\tconst numOfDeletionsNeeded = Math.max(\n\t\t0,\n\t\tyblocks.length - blocksToSync.length\n\t);\n\n\t// updates\n\tfor ( let i = 0; i < numOfUpdatesNeeded; i++, left++ ) {\n\t\tconst block = blocksToSync[ left ];\n\t\tconst yblock = yblocks.get( left );\n\t\tObject.entries( block ).forEach( ( [ key, value ] ) => {\n\t\t\tswitch ( key ) {\n\t\t\t\tcase 'attributes': {\n\t\t\t\t\tconst currentAttributes = yblock.get( key );\n\n\t\t\t\t\t// If attributes are not set on the yblock, use the new values.\n\t\t\t\t\tif ( ! currentAttributes ) {\n\t\t\t\t\t\tyblock.set(\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\tcreateNewYAttributeMap( block.name, value )\n\t\t\t\t\t\t);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tObject.entries( value ).forEach(\n\t\t\t\t\t\t( [ attributeName, attributeValue ] ) => {\n\t\t\t\t\t\t\tconst currentAttribute =\n\t\t\t\t\t\t\t\tcurrentAttributes?.get( attributeName );\n\n\t\t\t\t\t\t\tconst isExpectedType = isExpectedAttributeType(\n\t\t\t\t\t\t\t\tblock.name,\n\t\t\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\t\t\tcurrentAttribute\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tconst isAttributeChanged =\n\t\t\t\t\t\t\t\t! isExpectedType ||\n\t\t\t\t\t\t\t\t! fastDeepEqual(\n\t\t\t\t\t\t\t\t\tcurrentAttribute,\n\t\t\t\t\t\t\t\t\tattributeValue\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tif ( isAttributeChanged ) {\n\t\t\t\t\t\t\t\tupdateYBlockAttribute(\n\t\t\t\t\t\t\t\t\tblock.name,\n\t\t\t\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\t\t\t\tattributeValue,\n\t\t\t\t\t\t\t\t\tcurrentAttributes,\n\t\t\t\t\t\t\t\t\tcursorPosition\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\n\t\t\t\t\t// Delete any attributes that are no longer present.\n\t\t\t\t\tcurrentAttributes.forEach(\n\t\t\t\t\t\t( _attrValue: unknown, attrName: string ) => {\n\t\t\t\t\t\t\tif ( ! value.hasOwnProperty( attrName ) ) {\n\t\t\t\t\t\t\t\tcurrentAttributes.delete( attrName );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase 'innerBlocks': {\n\t\t\t\t\t// Recursively merge innerBlocks\n\t\t\t\t\tlet yInnerBlocks = yblock.get( key );\n\n\t\t\t\t\tif ( ! ( yInnerBlocks instanceof Y.Array ) ) {\n\t\t\t\t\t\tyInnerBlocks = new Y.Array< YBlock >();\n\t\t\t\t\t\tyblock.set( key, yInnerBlocks );\n\t\t\t\t\t}\n\n\t\t\t\t\tmergeCrdtBlocks(\n\t\t\t\t\t\tyInnerBlocks,\n\t\t\t\t\t\tvalue ?? [],\n\t\t\t\t\t\tcursorPosition\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault:\n\t\t\t\t\tif ( ! fastDeepEqual( block[ key ], yblock.get( key ) ) ) {\n\t\t\t\t\t\tyblock.set( key, value );\n\t\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t\tyblock.forEach( ( _v, k ) => {\n\t\t\tif ( ! block.hasOwnProperty( k ) ) {\n\t\t\t\tyblock.delete( k );\n\t\t\t}\n\t\t} );\n\t}\n\n\t// deletes\n\tyblocks.delete( left, numOfDeletionsNeeded );\n\n\t// inserts\n\tfor ( let i = 0; i < numOfInsertionsNeeded; i++, left++ ) {\n\t\tconst newBlock = [ createNewYBlock( blocksToSync[ left ] ) ];\n\n\t\tyblocks.insert( left, newBlock );\n\t}\n\n\t// remove duplicate clientids\n\tconst knownClientIds = new Set< string >();\n\tfor ( let j = 0; j < yblocks.length; j++ ) {\n\t\tconst yblock: YBlock = yblocks.get( j );\n\n\t\tlet clientId = yblock.get( 'clientId' );\n\n\t\tif ( ! clientId ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif ( knownClientIds.has( clientId ) ) {\n\t\t\tclientId = uuidv4();\n\t\t\tyblock.set( 'clientId', clientId );\n\t\t}\n\t\tknownClientIds.add( clientId );\n\t}\n}\n\n/**\n * Update a single attribute on a Yjs block attributes map (currentAttributes).\n *\n * For rich-text attributes that already exist as Y.Text instances, the update\n * is applied as a delta merge so that concurrent edits are preserved. All\n * other attributes are replaced wholesale via `createNewYAttributeValue`.\n *\n * @param blockName The block type name, e.g. 'core/paragraph'.\n * @param attributeName The name of the attribute to update, e.g. 'content'.\n * @param attributeValue The new value for the attribute.\n * @param currentAttributes The Y.Map holding the block's current attributes.\n * @param cursorPosition The local cursor position, used when merging rich-text deltas.\n */\nfunction updateYBlockAttribute(\n\tblockName: string,\n\tattributeName: string,\n\tattributeValue: unknown,\n\tcurrentAttributes: YBlockAttributes,\n\tcursorPosition: number | null\n): void {\n\tconst isRichText = isRichTextAttribute( blockName, attributeName );\n\tconst currentAttribute = currentAttributes.get( attributeName );\n\n\tif (\n\t\tisRichText &&\n\t\t'string' === typeof attributeValue &&\n\t\tcurrentAttributes.has( attributeName ) &&\n\t\tcurrentAttribute instanceof Y.Text\n\t) {\n\t\t// Rich text values are stored as persistent Y.Text instances.\n\t\t// Update the value with a delta in place.\n\t\tmergeRichTextUpdate( currentAttribute, attributeValue, cursorPosition );\n\t} else {\n\t\tcurrentAttributes.set(\n\t\t\tattributeName,\n\t\t\tcreateNewYAttributeValue( blockName, attributeName, attributeValue )\n\t\t);\n\t}\n}\n\n// Cached block attribute types, populated once from getBlockTypes().\nlet cachedBlockAttributeTypes: Map< string, Map< string, BlockAttributeType > >;\n\n/**\n * Get the attribute type definition for a block attribute.\n *\n * @param blockName The name of the block, e.g. 'core/paragraph'.\n * @param attributeName The name of the attribute, e.g. 'content'.\n * @return The type definition of the attribute.\n */\nfunction getBlockAttributeType(\n\tblockName: string,\n\tattributeName: string\n): BlockAttributeType | undefined {\n\tif ( ! cachedBlockAttributeTypes ) {\n\t\t// Parse the attributes for all blocks once.\n\t\tcachedBlockAttributeTypes = new Map();\n\n\t\tfor ( const blockType of getBlockTypes() as BlockType[] ) {\n\t\t\tcachedBlockAttributeTypes.set(\n\t\t\t\tblockType.name,\n\t\t\t\tnew Map< string, BlockAttributeType >(\n\t\t\t\t\tObject.entries( blockType.attributes ?? {} ).map(\n\t\t\t\t\t\t( [ name, definition ] ) => {\n\t\t\t\t\t\t\tconst { role, type } = definition;\n\t\t\t\t\t\t\treturn [ name, { role, type } ];\n\t\t\t\t\t\t}\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}\n\n\treturn cachedBlockAttributeTypes.get( blockName )?.get( attributeName );\n}\n\n/**\n * Check if an attribute value is the expected type.\n *\n * @param blockName The name of the block, e.g. 'core/paragraph'.\n * @param attributeName The name of the attribute, e.g. 'content'.\n * @param attributeValue The current attribute value.\n * @return True if the attribute type is expected, false otherwise.\n */\nfunction isExpectedAttributeType(\n\tblockName: string,\n\tattributeName: string,\n\tattributeValue: unknown\n): boolean {\n\tconst expectedAttributeType = getBlockAttributeType(\n\t\tblockName,\n\t\tattributeName\n\t)?.type;\n\n\tif ( expectedAttributeType === 'rich-text' ) {\n\t\treturn attributeValue instanceof Y.Text;\n\t}\n\n\tif ( expectedAttributeType === 'string' ) {\n\t\treturn typeof attributeValue === 'string';\n\t}\n\n\t// No other types comparisons use special logic.\n\treturn true;\n}\n\n/**\n * Given a block name and attribute key, return true if the attribute is local\n * and should not be synced.\n *\n * @param blockName The name of the block, e.g. 'core/image'.\n * @param attributeName The name of the attribute to check, e.g. 'blob'.\n * @return True if the attribute is local, false otherwise.\n */\nfunction isLocalAttribute( blockName: string, attributeName: string ): boolean {\n\treturn 'local' === getBlockAttributeType( blockName, attributeName )?.role;\n}\n\n/**\n * Given a block name and attribute key, return true if the attribute is rich-text typed.\n *\n * @param blockName The name of the block, e.g. 'core/paragraph'.\n * @param attributeName The name of the attribute to check, e.g. 'content'.\n * @return True if the attribute is rich-text typed, false otherwise.\n */\nfunction isRichTextAttribute(\n\tblockName: string,\n\tattributeName: string\n): boolean {\n\treturn (\n\t\t'rich-text' === getBlockAttributeType( blockName, attributeName )?.type\n\t);\n}\n\nlet localDoc: Y.Doc;\n\n/**\n * Given a Y.Text object and an updated string value, diff the new value and\n * apply the delta to the Y.Text.\n *\n * @param blockYText The Y.Text to update.\n * @param updatedValue The updated value.\n * @param cursorPosition The position of the cursor after the change occurs.\n */\nexport function mergeRichTextUpdate(\n\tblockYText: Y.Text,\n\tupdatedValue: string,\n\tcursorPosition: number | null = null\n): void {\n\t// Gutenberg does not use Yjs shared types natively, so we can only subscribe\n\t// to changes from store and apply them to Yjs types that we create and\n\t// manage. Crucially, for rich-text attributes, we do not receive granular\n\t// string updates; we get the new full string value on each change, even when\n\t// only a single character changed.\n\t//\n\t// The code below allows us to compute a delta between the current and new\n\t// value, then apply it to the Y.Text.\n\n\tif ( ! localDoc ) {\n\t\t// Y.Text must be attached to a Y.Doc to be able to do operations on it.\n\t\t// Create a temporary Y.Text attached to a local Y.Doc for delta computation.\n\t\tlocalDoc = new Y.Doc();\n\t}\n\n\tconst localYText = localDoc.getText( 'temporary-text' );\n\tlocalYText.delete( 0, localYText.length );\n\tlocalYText.insert( 0, updatedValue );\n\n\tconst currentValueAsDelta = new Delta( blockYText.toDelta() );\n\tconst updatedValueAsDelta = new Delta( localYText.toDelta() );\n\tconst deltaDiff = currentValueAsDelta.diffWithCursor(\n\t\tupdatedValueAsDelta,\n\t\tcursorPosition\n\t);\n\n\tblockYText.applyDelta( deltaDiff.ops );\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA6B;AAC7B,iBAA0B;AAM1B,oBAA8B;AAC9B,uBAA6B;AAC7B,kBAAkB;AAKlB,wBAA2D;AAC3D,IAAAA,eAAsB;AA4CtB,IAAM,0BAA0B,oBAAI,QAA4B;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport { v4 as uuidv4 } from 'uuid';\nimport fastDeepEqual from 'fast-deep-equal/es6/index.js';\n\n/**\n * WordPress dependencies\n */\n// @ts-expect-error No exported types.\nimport { getBlockTypes } from '@wordpress/blocks';\nimport { RichTextData } from '@wordpress/rich-text';\nimport { Y } from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport { createYMap, type YMapRecord, type YMapWrap } from './crdt-utils';\nimport { Delta } from '../sync';\n\ninterface BlockAttributes {\n\t[ key: string ]: unknown;\n}\n\ninterface BlockAttributeType {\n\trole?: string;\n\ttype?: string;\n}\n\ninterface BlockType {\n\tattributes?: Record< string, BlockAttributeType >;\n\tname: string;\n}\n\n// A block as represented in Gutenberg's data store.\nexport interface Block {\n\tattributes: BlockAttributes;\n\tclientId?: string;\n\tinnerBlocks: Block[];\n\tisValid?: boolean;\n\tname: string;\n\toriginalContent?: string;\n\tvalidationIssues?: string[]; // unserializable\n}\n\n// A block as represented in the CRDT document (Y.Map).\nexport interface YBlockRecord extends YMapRecord {\n\tattributes: YBlockAttributes;\n\tclientId: string;\n\tinnerBlocks: YBlocks;\n\tisValid?: boolean;\n\toriginalContent?: string;\n\tname: string;\n}\n\nexport type YBlock = YMapWrap< YBlockRecord >;\nexport type YBlocks = Y.Array< YBlock >;\n\n// Block attribute schema cannot be known at compile time, so we use Y.Map.\n// Attribute values will be typed as the union of `Y.Text` and `unknown`.\nexport type YBlockAttributes = Y.Map< Y.Text | unknown >;\n\nconst serializableBlocksCache = new WeakMap< WeakKey, Block[] >();\n\n/**\n * Recursively walk an attribute value and convert any RichTextData instances\n * to their string (HTML) representation. This is necessary for array-type and\n * object-type attributes, which can contain nested RichTextData.\n *\n * @param value The attribute value to serialize.\n * @return The value with all RichTextData instances replaced by strings.\n */\nfunction serializeAttributeValue( value: unknown ): unknown {\n\tif ( value instanceof RichTextData ) {\n\t\treturn value.valueOf();\n\t}\n\n\t// e.g. core/table `body`: [ { cells: [ { content: RichTextData } ] } ]\n\tif ( Array.isArray( value ) ) {\n\t\treturn value.map( serializeAttributeValue );\n\t}\n\n\t// e.g. a single row inside core/table `body`: { cells: [ ... ] }\n\tif ( value && typeof value === 'object' ) {\n\t\tconst result: Record< string, unknown > = {};\n\n\t\tfor ( const [ k, v ] of Object.entries( value ) ) {\n\t\t\tresult[ k ] = serializeAttributeValue( v );\n\t\t}\n\t\treturn result;\n\t}\n\n\treturn value;\n}\n\nfunction makeBlockAttributesSerializable(\n\tblockName: string,\n\tattributes: BlockAttributes\n): BlockAttributes {\n\tconst newAttributes = { ...attributes };\n\tfor ( const [ key, value ] of Object.entries( attributes ) ) {\n\t\tif ( isLocalAttribute( blockName, key ) ) {\n\t\t\tdelete newAttributes[ key ];\n\t\t\tcontinue;\n\t\t}\n\n\t\tnewAttributes[ key ] = serializeAttributeValue( value );\n\t}\n\treturn newAttributes;\n}\n\nfunction makeBlocksSerializable( blocks: Block[] ): Block[] {\n\treturn blocks.map( ( block: Block ) => {\n\t\tconst { name, innerBlocks, attributes, ...rest } = block;\n\t\tdelete rest.validationIssues;\n\t\treturn {\n\t\t\t...rest,\n\t\t\tname,\n\t\t\tattributes: makeBlockAttributesSerializable( name, attributes ),\n\t\t\tinnerBlocks: makeBlocksSerializable( innerBlocks ),\n\t\t};\n\t} );\n}\n\n/**\n * @param {any} gblock\n * @param {Y.Map} yblock\n */\nfunction areBlocksEqual( gblock: Block, yblock: YBlock ): boolean {\n\tconst yblockAsJson = yblock.toJSON();\n\n\t// we must not sync clientId, as this can't be generated consistently and\n\t// hence will lead to merge conflicts.\n\tconst overwrites = {\n\t\tinnerBlocks: null,\n\t\tclientId: null,\n\t};\n\tconst res = fastDeepEqual(\n\t\tObject.assign( {}, gblock, overwrites ),\n\t\tObject.assign( {}, yblockAsJson, overwrites )\n\t);\n\tconst inners = gblock.innerBlocks || [];\n\tconst yinners = yblock.get( 'innerBlocks' );\n\treturn (\n\t\tres &&\n\t\tinners.length === yinners?.length &&\n\t\tinners.every( ( block: Block, i: number ) =>\n\t\t\tareBlocksEqual( block, yinners.get( i ) )\n\t\t)\n\t);\n}\n\nfunction createNewYAttributeMap(\n\tblockName: string,\n\tattributes: BlockAttributes\n): YBlockAttributes {\n\treturn new Y.Map(\n\t\tObject.entries( attributes ).map(\n\t\t\t( [ attributeName, attributeValue ] ) => {\n\t\t\t\treturn [\n\t\t\t\t\tattributeName,\n\t\t\t\t\tcreateNewYAttributeValue(\n\t\t\t\t\t\tblockName,\n\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\tattributeValue\n\t\t\t\t\t),\n\t\t\t\t];\n\t\t\t}\n\t\t)\n\t);\n}\n\nfunction createNewYAttributeValue(\n\tblockName: string,\n\tattributeName: string,\n\tattributeValue: unknown\n): Y.Text | unknown {\n\tconst isRichText = isRichTextAttribute( blockName, attributeName );\n\n\tif ( isRichText ) {\n\t\treturn new Y.Text( attributeValue?.toString() ?? '' );\n\t}\n\n\treturn attributeValue;\n}\n\nfunction createNewYBlock( block: Block ): YBlock {\n\treturn createYMap< YBlockRecord >(\n\t\tObject.fromEntries(\n\t\t\tObject.entries( block ).map( ( [ key, value ] ) => {\n\t\t\t\tswitch ( key ) {\n\t\t\t\t\tcase 'attributes': {\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\tcreateNewYAttributeMap( block.name, value ),\n\t\t\t\t\t\t];\n\t\t\t\t\t}\n\n\t\t\t\t\tcase 'innerBlocks': {\n\t\t\t\t\t\tconst innerBlocks = new Y.Array();\n\n\t\t\t\t\t\t// If not an array, set to empty Y.Array.\n\t\t\t\t\t\tif ( ! Array.isArray( value ) ) {\n\t\t\t\t\t\t\treturn [ key, innerBlocks ];\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tinnerBlocks.insert(\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\tvalue.map( ( innerBlock: Block ) =>\n\t\t\t\t\t\t\t\tcreateNewYBlock( innerBlock )\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn [ key, innerBlocks ];\n\t\t\t\t\t}\n\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn [ key, value ];\n\t\t\t\t}\n\t\t\t} )\n\t\t)\n\t);\n}\n\n/**\n * Merge incoming block data into the local Y.Doc.\n * This function is called to sync local block changes to a shared Y.Doc.\n *\n * @param yblocks The blocks in the local Y.Doc.\n * @param incomingBlocks Gutenberg blocks being synced.\n * @param cursorPosition The position of the cursor after the change occurs.\n */\nexport function mergeCrdtBlocks(\n\tyblocks: YBlocks,\n\tincomingBlocks: Block[],\n\tcursorPosition: number | null\n): void {\n\t// Ensure we are working with serializable block data.\n\tif ( ! serializableBlocksCache.has( incomingBlocks ) ) {\n\t\tserializableBlocksCache.set(\n\t\t\tincomingBlocks,\n\t\t\tmakeBlocksSerializable( incomingBlocks )\n\t\t);\n\t}\n\tconst blocksToSync = serializableBlocksCache.get( incomingBlocks ) ?? [];\n\n\t// This is a rudimentary diff implementation similar to the y-prosemirror diffing\n\t// approach.\n\t// A better implementation would also diff the textual content and represent it\n\t// using a Y.Text type.\n\t// However, at this time it makes more sense to keep this algorithm generic to\n\t// support all kinds of block types.\n\t// Ideally, we ensure that block data structure have a consistent data format.\n\t// E.g.:\n\t// - textual content (using rich-text formatting?) may always be stored under `block.text`\n\t// - local information that shouldn't be shared (e.g. clientId or isDragging) is stored under `block.private`\n\t//\n\t// @credit Kevin Jahns (dmonad)\n\t// @link https://github.com/WordPress/gutenberg/pull/68483\n\tconst numOfCommonEntries = Math.min(\n\t\tblocksToSync.length ?? 0,\n\t\tyblocks.length\n\t);\n\n\tlet left = 0;\n\tlet right = 0;\n\n\t// skip equal blocks from left\n\tfor (\n\t\t;\n\t\tleft < numOfCommonEntries &&\n\t\tareBlocksEqual( blocksToSync[ left ], yblocks.get( left ) );\n\t\tleft++\n\t) {\n\t\t/* nop */\n\t}\n\n\t// skip equal blocks from right\n\tfor (\n\t\t;\n\t\tright < numOfCommonEntries - left &&\n\t\tareBlocksEqual(\n\t\t\tblocksToSync[ blocksToSync.length - right - 1 ],\n\t\t\tyblocks.get( yblocks.length - right - 1 )\n\t\t);\n\t\tright++\n\t) {\n\t\t/* nop */\n\t}\n\n\tconst numOfUpdatesNeeded = numOfCommonEntries - left - right;\n\tconst numOfInsertionsNeeded = Math.max(\n\t\t0,\n\t\tblocksToSync.length - yblocks.length\n\t);\n\tconst numOfDeletionsNeeded = Math.max(\n\t\t0,\n\t\tyblocks.length - blocksToSync.length\n\t);\n\n\t// updates\n\tfor ( let i = 0; i < numOfUpdatesNeeded; i++, left++ ) {\n\t\tconst block = blocksToSync[ left ];\n\t\tconst yblock = yblocks.get( left );\n\t\tObject.entries( block ).forEach( ( [ key, value ] ) => {\n\t\t\tswitch ( key ) {\n\t\t\t\tcase 'attributes': {\n\t\t\t\t\tconst currentAttributes = yblock.get( key );\n\n\t\t\t\t\t// If attributes are not set on the yblock, use the new values.\n\t\t\t\t\tif ( ! currentAttributes ) {\n\t\t\t\t\t\tyblock.set(\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\tcreateNewYAttributeMap( block.name, value )\n\t\t\t\t\t\t);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tObject.entries( value ).forEach(\n\t\t\t\t\t\t( [ attributeName, attributeValue ] ) => {\n\t\t\t\t\t\t\tconst currentAttribute =\n\t\t\t\t\t\t\t\tcurrentAttributes?.get( attributeName );\n\n\t\t\t\t\t\t\tconst isExpectedType = isExpectedAttributeType(\n\t\t\t\t\t\t\t\tblock.name,\n\t\t\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\t\t\tcurrentAttribute\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tconst isAttributeChanged =\n\t\t\t\t\t\t\t\t! isExpectedType ||\n\t\t\t\t\t\t\t\t! fastDeepEqual(\n\t\t\t\t\t\t\t\t\tcurrentAttribute,\n\t\t\t\t\t\t\t\t\tattributeValue\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tif ( isAttributeChanged ) {\n\t\t\t\t\t\t\t\tupdateYBlockAttribute(\n\t\t\t\t\t\t\t\t\tblock.name,\n\t\t\t\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\t\t\t\tattributeValue,\n\t\t\t\t\t\t\t\t\tcurrentAttributes,\n\t\t\t\t\t\t\t\t\tcursorPosition\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\n\t\t\t\t\t// Delete any attributes that are no longer present.\n\t\t\t\t\tcurrentAttributes.forEach(\n\t\t\t\t\t\t( _attrValue: unknown, attrName: string ) => {\n\t\t\t\t\t\t\tif ( ! value.hasOwnProperty( attrName ) ) {\n\t\t\t\t\t\t\t\tcurrentAttributes.delete( attrName );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase 'innerBlocks': {\n\t\t\t\t\t// Recursively merge innerBlocks\n\t\t\t\t\tlet yInnerBlocks = yblock.get( key );\n\n\t\t\t\t\tif ( ! ( yInnerBlocks instanceof Y.Array ) ) {\n\t\t\t\t\t\tyInnerBlocks = new Y.Array< YBlock >();\n\t\t\t\t\t\tyblock.set( key, yInnerBlocks );\n\t\t\t\t\t}\n\n\t\t\t\t\tmergeCrdtBlocks(\n\t\t\t\t\t\tyInnerBlocks,\n\t\t\t\t\t\tvalue ?? [],\n\t\t\t\t\t\tcursorPosition\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault:\n\t\t\t\t\tif ( ! fastDeepEqual( block[ key ], yblock.get( key ) ) ) {\n\t\t\t\t\t\tyblock.set( key, value );\n\t\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t\tyblock.forEach( ( _v, k ) => {\n\t\t\tif ( ! block.hasOwnProperty( k ) ) {\n\t\t\t\tyblock.delete( k );\n\t\t\t}\n\t\t} );\n\t}\n\n\t// deletes\n\tyblocks.delete( left, numOfDeletionsNeeded );\n\n\t// inserts\n\tfor ( let i = 0; i < numOfInsertionsNeeded; i++, left++ ) {\n\t\tconst newBlock = [ createNewYBlock( blocksToSync[ left ] ) ];\n\n\t\tyblocks.insert( left, newBlock );\n\t}\n\n\t// remove duplicate clientids\n\tconst knownClientIds = new Set< string >();\n\tfor ( let j = 0; j < yblocks.length; j++ ) {\n\t\tconst yblock: YBlock = yblocks.get( j );\n\n\t\tlet clientId = yblock.get( 'clientId' );\n\n\t\tif ( ! clientId ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif ( knownClientIds.has( clientId ) ) {\n\t\t\tclientId = uuidv4();\n\t\t\tyblock.set( 'clientId', clientId );\n\t\t}\n\t\tknownClientIds.add( clientId );\n\t}\n}\n\n/**\n * Update a single attribute on a Yjs block attributes map (currentAttributes).\n *\n * For rich-text attributes that already exist as Y.Text instances, the update\n * is applied as a delta merge so that concurrent edits are preserved. All\n * other attributes are replaced wholesale via `createNewYAttributeValue`.\n *\n * @param blockName The block type name, e.g. 'core/paragraph'.\n * @param attributeName The name of the attribute to update, e.g. 'content'.\n * @param attributeValue The new value for the attribute.\n * @param currentAttributes The Y.Map holding the block's current attributes.\n * @param cursorPosition The local cursor position, used when merging rich-text deltas.\n */\nfunction updateYBlockAttribute(\n\tblockName: string,\n\tattributeName: string,\n\tattributeValue: unknown,\n\tcurrentAttributes: YBlockAttributes,\n\tcursorPosition: number | null\n): void {\n\tconst isRichText = isRichTextAttribute( blockName, attributeName );\n\tconst currentAttribute = currentAttributes.get( attributeName );\n\n\tif (\n\t\tisRichText &&\n\t\t'string' === typeof attributeValue &&\n\t\tcurrentAttributes.has( attributeName ) &&\n\t\tcurrentAttribute instanceof Y.Text\n\t) {\n\t\t// Rich text values are stored as persistent Y.Text instances.\n\t\t// Update the value with a delta in place.\n\t\tmergeRichTextUpdate( currentAttribute, attributeValue, cursorPosition );\n\t} else {\n\t\tcurrentAttributes.set(\n\t\t\tattributeName,\n\t\t\tcreateNewYAttributeValue( blockName, attributeName, attributeValue )\n\t\t);\n\t}\n}\n\n// Cached block attribute types, populated once from getBlockTypes().\nlet cachedBlockAttributeTypes: Map< string, Map< string, BlockAttributeType > >;\n\n/**\n * Get the attribute type definition for a block attribute.\n *\n * @param blockName The name of the block, e.g. 'core/paragraph'.\n * @param attributeName The name of the attribute, e.g. 'content'.\n * @return The type definition of the attribute.\n */\nfunction getBlockAttributeType(\n\tblockName: string,\n\tattributeName: string\n): BlockAttributeType | undefined {\n\tif ( ! cachedBlockAttributeTypes ) {\n\t\t// Parse the attributes for all blocks once.\n\t\tcachedBlockAttributeTypes = new Map();\n\n\t\tfor ( const blockType of getBlockTypes() as BlockType[] ) {\n\t\t\tcachedBlockAttributeTypes.set(\n\t\t\t\tblockType.name,\n\t\t\t\tnew Map< string, BlockAttributeType >(\n\t\t\t\t\tObject.entries( blockType.attributes ?? {} ).map(\n\t\t\t\t\t\t( [ name, definition ] ) => {\n\t\t\t\t\t\t\tconst { role, type } = definition;\n\t\t\t\t\t\t\treturn [ name, { role, type } ];\n\t\t\t\t\t\t}\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}\n\n\treturn cachedBlockAttributeTypes.get( blockName )?.get( attributeName );\n}\n\n/**\n * Check if an attribute value is the expected type.\n *\n * @param blockName The name of the block, e.g. 'core/paragraph'.\n * @param attributeName The name of the attribute, e.g. 'content'.\n * @param attributeValue The current attribute value.\n * @return True if the attribute type is expected, false otherwise.\n */\nfunction isExpectedAttributeType(\n\tblockName: string,\n\tattributeName: string,\n\tattributeValue: unknown\n): boolean {\n\tconst expectedAttributeType = getBlockAttributeType(\n\t\tblockName,\n\t\tattributeName\n\t)?.type;\n\n\tif ( expectedAttributeType === 'rich-text' ) {\n\t\treturn attributeValue instanceof Y.Text;\n\t}\n\n\tif ( expectedAttributeType === 'string' ) {\n\t\treturn typeof attributeValue === 'string';\n\t}\n\n\t// No other types comparisons use special logic.\n\treturn true;\n}\n\n/**\n * Given a block name and attribute key, return true if the attribute is local\n * and should not be synced.\n *\n * @param blockName The name of the block, e.g. 'core/image'.\n * @param attributeName The name of the attribute to check, e.g. 'blob'.\n * @return True if the attribute is local, false otherwise.\n */\nfunction isLocalAttribute( blockName: string, attributeName: string ): boolean {\n\treturn 'local' === getBlockAttributeType( blockName, attributeName )?.role;\n}\n\n/**\n * Given a block name and attribute key, return true if the attribute is rich-text typed.\n *\n * @param blockName The name of the block, e.g. 'core/paragraph'.\n * @param attributeName The name of the attribute to check, e.g. 'content'.\n * @return True if the attribute is rich-text typed, false otherwise.\n */\nfunction isRichTextAttribute(\n\tblockName: string,\n\tattributeName: string\n): boolean {\n\treturn (\n\t\t'rich-text' === getBlockAttributeType( blockName, attributeName )?.type\n\t);\n}\n\nlet localDoc: Y.Doc;\n\n/**\n * Given a Y.Text object and an updated string value, diff the new value and\n * apply the delta to the Y.Text.\n *\n * @param blockYText The Y.Text to update.\n * @param updatedValue The updated value.\n * @param cursorPosition The position of the cursor after the change occurs.\n */\nexport function mergeRichTextUpdate(\n\tblockYText: Y.Text,\n\tupdatedValue: string,\n\tcursorPosition: number | null = null\n): void {\n\t// Gutenberg does not use Yjs shared types natively, so we can only subscribe\n\t// to changes from store and apply them to Yjs types that we create and\n\t// manage. Crucially, for rich-text attributes, we do not receive granular\n\t// string updates; we get the new full string value on each change, even when\n\t// only a single character changed.\n\t//\n\t// The code below allows us to compute a delta between the current and new\n\t// value, then apply it to the Y.Text.\n\n\tif ( ! localDoc ) {\n\t\t// Y.Text must be attached to a Y.Doc to be able to do operations on it.\n\t\t// Create a temporary Y.Text attached to a local Y.Doc for delta computation.\n\t\tlocalDoc = new Y.Doc();\n\t}\n\n\tconst localYText = localDoc.getText( 'temporary-text' );\n\tlocalYText.delete( 0, localYText.length );\n\tlocalYText.insert( 0, updatedValue );\n\n\tconst currentValueAsDelta = new Delta( blockYText.toDelta() );\n\tconst updatedValueAsDelta = new Delta( localYText.toDelta() );\n\tconst deltaDiff = currentValueAsDelta.diffWithCursor(\n\t\tupdatedValueAsDelta,\n\t\tcursorPosition\n\t);\n\n\tblockYText.applyDelta( deltaDiff.ops );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA6B;AAC7B,iBAA0B;AAM1B,oBAA8B;AAC9B,uBAA6B;AAC7B,kBAAkB;AAKlB,wBAA2D;AAC3D,IAAAA,eAAsB;AA4CtB,IAAM,0BAA0B,oBAAI,QAA4B;AAUhE,SAAS,wBAAyB,OAA0B;AAC3D,MAAK,iBAAiB,+BAAe;AACpC,WAAO,MAAM,QAAQ;AAAA,EACtB;AAGA,MAAK,MAAM,QAAS,KAAM,GAAI;AAC7B,WAAO,MAAM,IAAK,uBAAwB;AAAA,EAC3C;AAGA,MAAK,SAAS,OAAO,UAAU,UAAW;AACzC,UAAM,SAAoC,CAAC;AAE3C,eAAY,CAAE,GAAG,CAAE,KAAK,OAAO,QAAS,KAAM,GAAI;AACjD,a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AiC;AAC9E,SAAO,YAAY,sBAAuB,WAAW,aAAc,GAAG;AACvE;AASA,SAAS,oBACR,WACA,eACU;AACV,SACC,gBAAgB,sBAAuB,WAAW,aAAc,GAAG;AAErE;AAEA,IAAI;AAUG,SAAS,oBACf,YACA,cACA,iBAAgC,MACzB;AAUP,MAAK,CAAE,UAAW;AAGjB,eAAW,IAAI,cAAE,IAAI;AAAA,EACtB;AAEA,QAAM,aAAa,SAAS,QAAS,gBAAiB;AACtD,aAAW,OAAQ,GAAG,WAAW,MAAO;AACxC,aAAW,OAAQ,GAAG,YAAa;AAEnC,QAAM,sBAAsB,IAAI,mBAAO,WAAW,QAAQ,CAAE;AAC5D,QAAM,sBAAsB,IAAI,mBAAO,WAAW,QAAQ,CAAE;AAC5D,QAAM,YAAY,oBAAoB;AAAA,IACrC;AAAA,IACA;AAAA,EACD;AAEA,aAAW,WAAY,UAAU,GAAI;AACtC;",
|
|
6
6
|
"names": ["import_sync", "fastDeepEqual", "uuidv4"]
|
|
7
7
|
}
|
|
@@ -58,7 +58,10 @@ function convertYSelectionToBlockSelection(ySelection, ydoc) {
|
|
|
58
58
|
return {
|
|
59
59
|
clientId,
|
|
60
60
|
attributeKey,
|
|
61
|
-
offset:
|
|
61
|
+
offset: (0, import_crdt_utils.htmlIndexToRichTextOffset)(
|
|
62
|
+
absolutePosition.type.toString(),
|
|
63
|
+
absolutePosition.index
|
|
64
|
+
)
|
|
62
65
|
};
|
|
63
66
|
}
|
|
64
67
|
} else if (ySelection.type === import_block_selection_history.YSelectionType.BlockSelection) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/crdt-selection.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { dispatch, select } from '@wordpress/data';\n// @ts-expect-error No exported types.\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n// @ts-expect-error No exported types.\nimport { isUnmodifiedBlock } from '@wordpress/blocks';\nimport { type CRDTDoc, Y } from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport {\n\tcreateBlockSelectionHistory,\n\tYSelectionType,\n\ttype BlockSelectionHistory,\n\ttype YFullSelection,\n\ttype YSelection,\n} from './block-selection-history';\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiC;AAEjC,0BAA0C;AAE1C,oBAAkC;AAClC,kBAAgC;AAKhC,qCAMO;AACP,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { dispatch, select } from '@wordpress/data';\n// @ts-expect-error No exported types.\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n// @ts-expect-error No exported types.\nimport { isUnmodifiedBlock } from '@wordpress/blocks';\nimport { type CRDTDoc, Y } from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport {\n\tcreateBlockSelectionHistory,\n\tYSelectionType,\n\ttype BlockSelectionHistory,\n\ttype YFullSelection,\n\ttype YSelection,\n} from './block-selection-history';\nimport {\n\tfindBlockByClientIdInDoc,\n\thtmlIndexToRichTextOffset,\n} from './crdt-utils';\nimport type { WPBlockSelection, WPSelection } from '../types';\n\n// WeakMap to store BlockSelectionHistory instances per Y.Doc\nconst selectionHistoryMap = new WeakMap< CRDTDoc, BlockSelectionHistory >();\n\n/**\n * Get or create a BlockSelectionHistory instance for a given Y.Doc.\n *\n * @param ydoc The Y.Doc to get the selection history for\n * @return The BlockSelectionHistory instance\n */\nfunction getBlockSelectionHistory( ydoc: CRDTDoc ): BlockSelectionHistory {\n\tlet history = selectionHistoryMap.get( ydoc );\n\n\tif ( ! history ) {\n\t\thistory = createBlockSelectionHistory( ydoc );\n\t\tselectionHistoryMap.set( ydoc, history );\n\t}\n\n\treturn history;\n}\n\nexport function getSelectionHistory( ydoc: CRDTDoc ): YFullSelection[] {\n\treturn getBlockSelectionHistory( ydoc ).getSelectionHistory();\n}\n\nexport function updateSelectionHistory(\n\tydoc: CRDTDoc,\n\twpSelection: WPSelection\n): void {\n\treturn getBlockSelectionHistory( ydoc ).updateSelection( wpSelection );\n}\n\n/**\n * Convert a YSelection to a WPBlockSelection.\n * @param ySelection The YSelection (relative) to convert\n * @param ydoc The Y.Doc to convert the selection to a block selection for\n * @return The converted WPBlockSelection, or null if the conversion fails\n */\nfunction convertYSelectionToBlockSelection(\n\tySelection: YSelection,\n\tydoc: Y.Doc\n): WPBlockSelection | null {\n\tif ( ySelection.type === YSelectionType.RelativeSelection ) {\n\t\tconst { relativePosition, attributeKey, clientId } = ySelection;\n\n\t\tconst absolutePosition = Y.createAbsolutePositionFromRelativePosition(\n\t\t\trelativePosition,\n\t\t\tydoc\n\t\t);\n\n\t\tif ( absolutePosition ) {\n\t\t\treturn {\n\t\t\t\tclientId,\n\t\t\t\tattributeKey,\n\t\t\t\toffset: htmlIndexToRichTextOffset(\n\t\t\t\t\tabsolutePosition.type.toString(),\n\t\t\t\t\tabsolutePosition.index\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\t} else if ( ySelection.type === YSelectionType.BlockSelection ) {\n\t\treturn {\n\t\t\tclientId: ySelection.clientId,\n\t\t\tattributeKey: undefined,\n\t\t\toffset: undefined,\n\t\t};\n\t}\n\n\treturn null;\n}\n\n/**\n * Convert a YFullSelection to a WPSelection by resolving relative positions\n * and verifying the blocks exist in the document.\n * @param yFullSelection The YFullSelection to convert\n * @param ydoc The Y.Doc to resolve positions against\n * @return The converted WPSelection, or null if the conversion fails\n */\nfunction convertYFullSelectionToWPSelection(\n\tyFullSelection: YFullSelection,\n\tydoc: Y.Doc\n): WPSelection | null {\n\tconst { start, end } = yFullSelection;\n\tconst startBlock = findBlockByClientIdInDoc( start.clientId, ydoc );\n\tconst endBlock = findBlockByClientIdInDoc( end.clientId, ydoc );\n\n\tif ( ! startBlock || ! endBlock ) {\n\t\treturn null;\n\t}\n\n\tconst startBlockSelection = convertYSelectionToBlockSelection(\n\t\tstart,\n\t\tydoc\n\t);\n\tconst endBlockSelection = convertYSelectionToBlockSelection( end, ydoc );\n\n\tif ( startBlockSelection === null || endBlockSelection === null ) {\n\t\treturn null;\n\t}\n\n\treturn {\n\t\tselectionStart: startBlockSelection,\n\t\tselectionEnd: endBlockSelection,\n\t};\n}\n\n/**\n * Given a Y.Doc and a selection history, find the most recent selection\n * that exists in the document. Skip any selections that are not in the document.\n * @param ydoc The Y.Doc to find the selection in\n * @param selectionHistory The selection history to check\n * @return The most recent selection that exists in the document, or null if no selection exists.\n */\nfunction findSelectionFromHistory(\n\tydoc: Y.Doc,\n\tselectionHistory: YFullSelection[]\n): WPSelection | null {\n\tfor ( const positionToTry of selectionHistory ) {\n\t\tconst result = convertYFullSelectionToWPSelection(\n\t\t\tpositionToTry,\n\t\t\tydoc\n\t\t);\n\t\tif ( result !== null ) {\n\t\t\treturn result;\n\t\t}\n\t}\n\n\treturn null;\n}\n\n/**\n * Restore the selection to the most recent selection in history that is\n * available in the document.\n * @param selectionHistory The selection history to restore\n * @param ydoc The Y.Doc where blocks are stored\n */\nexport function restoreSelection(\n\tselectionHistory: YFullSelection[],\n\tydoc: Y.Doc\n): void {\n\t// Find the most recent selection in history that is available in\n\t// the document.\n\tconst selectionToRestore = findSelectionFromHistory(\n\t\tydoc,\n\t\tselectionHistory\n\t);\n\n\tif ( selectionToRestore === null ) {\n\t\t// Case 1: No blocks in history are available for restoration.\n\t\t// Do nothing.\n\t\treturn;\n\t}\n\n\tconst { getBlock } = select( blockEditorStore );\n\tconst { resetSelection } = dispatch( blockEditorStore );\n\tconst { selectionStart, selectionEnd } = selectionToRestore;\n\tconst isSelectionInSameBlock =\n\t\tselectionStart.clientId === selectionEnd.clientId;\n\n\tif ( isSelectionInSameBlock ) {\n\t\t// Case 2: After content is restored, the selection is available\n\t\t// within the same block\n\n\t\tconst block = getBlock( selectionStart.clientId );\n\t\tconst isBlockEmpty = block && isUnmodifiedBlock( block );\n\t\tconst isBeginningOfEmptyBlock =\n\t\t\t0 === selectionStart.offset &&\n\t\t\t0 === selectionEnd.offset &&\n\t\t\tisBlockEmpty &&\n\t\t\t! selectionStart.attributeKey &&\n\t\t\t! selectionEnd.attributeKey;\n\n\t\tif ( isBeginningOfEmptyBlock ) {\n\t\t\t// Case 2a: When the content in a block has been removed after an\n\t\t\t// undo, WordPress will set the selection to the block's client ID\n\t\t\t// with an undefined startOffset and endOffset.\n\t\t\t//\n\t\t\t// To match the default behavior and tests, exclude the selection\n\t\t\t// offset when resetting to position 0.\n\t\t\tconst selectionStartWithoutOffset = {\n\t\t\t\tclientId: selectionStart.clientId,\n\t\t\t};\n\t\t\tconst selectionEndWithoutOffset = {\n\t\t\t\tclientId: selectionEnd.clientId,\n\t\t\t};\n\n\t\t\tresetSelection(\n\t\t\t\tselectionStartWithoutOffset,\n\t\t\t\tselectionEndWithoutOffset,\n\t\t\t\t0\n\t\t\t);\n\t\t} else {\n\t\t\t// Case 2b: Otherwise, reset including the saved selection offset.\n\t\t\tresetSelection( selectionStart, selectionEnd, 0 );\n\t\t}\n\t} else {\n\t\t// Case 3: A multi-block selection was made. resetSelection() can only\n\t\t// restore selections within the same block.\n\t\t// When a multi-block selection is made, selectionEnd represents\n\t\t// where the user's cursor ended.\n\t\tresetSelection( selectionEnd, selectionEnd, 0 );\n\t}\n}\n\n/**\n * If the latest selection has been shifted by remote edits, resolve and return\n * it as a WPSelection. Returns null when the history is empty or neither\n * endpoint has moved.\n *\n * @param ydoc The Y.Doc to resolve positions against\n * @param selectionHistory The selection history to check\n * @return The shifted WPSelection, or null if nothing moved.\n */\nexport function getShiftedSelection(\n\tydoc: Y.Doc,\n\tselectionHistory: YFullSelection[]\n): WPSelection | null {\n\tif ( selectionHistory.length === 0 ) {\n\t\treturn null;\n\t}\n\n\tconst { start, end } = selectionHistory[ 0 ];\n\n\t// Block-level selections have no offset that can shift.\n\tif (\n\t\tstart.type === YSelectionType.BlockSelection ||\n\t\tend.type === YSelectionType.BlockSelection\n\t) {\n\t\treturn null;\n\t}\n\n\tconst selectionStart = convertYSelectionToBlockSelection( start, ydoc );\n\tconst selectionEnd = convertYSelectionToBlockSelection( end, ydoc );\n\n\tif ( ! selectionStart || ! selectionEnd ) {\n\t\treturn null;\n\t}\n\n\t// Only dispatch if at least one endpoint actually moved.\n\tconst startShifted = selectionStart.offset !== start.offset;\n\tconst endShifted = selectionEnd.offset !== end.offset;\n\n\tif ( ! startShifted && ! endShifted ) {\n\t\treturn null;\n\t}\n\n\treturn { selectionStart, selectionEnd };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiC;AAEjC,0BAA0C;AAE1C,oBAAkC;AAClC,kBAAgC;AAKhC,qCAMO;AACP,wBAGO;AAIP,IAAM,sBAAsB,oBAAI,QAA0C;AAQ1E,SAAS,yBAA0B,MAAuC;AACzE,MAAI,UAAU,oBAAoB,IAAK,IAAK;AAE5C,MAAK,CAAE,SAAU;AAChB,kBAAU,4DAA6B,IAAK;AAC5C,wBAAoB,IAAK,MAAM,OAAQ;AAAA,EACxC;AAEA,SAAO;AACR;AAEO,SAAS,oBAAqB,MAAkC;AACtE,SAAO,yBAA0B,IAAK,EAAE,oBAAoB;AAC7D;AAEO,SAAS,uBACf,MACA,aACO;AACP,SAAO,yBAA0B,IAAK,EAAE,gBAAiB,WAAY;AACtE;AAQA,SAAS,kCACR,YACA,MAC0B;AAC1B,MAAK,WAAW,SAAS,8CAAe,mBAAoB;AAC3D,UAAM,EAAE,kBAAkB,cAAc,SAAS,IAAI;AAErD,UAAM,mBAAmB,cAAE;AAAA,MAC1B;AAAA,MACA;AAAA,IACD;AAEA,QAAK,kBAAmB;AACvB,aAAO;AAAA,QACN;AAAA,QACA;AAAA,QACA,YAAQ;AAAA,UACP,iBAAiB,KAAK,SAAS;AAAA,UAC/B,iBAAiB;AAAA,QAClB;AAAA,MACD;AAAA,I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AM,aAAa,UACnB,gBACA,CAAE,eAAe,gBACjB,CAAE,aAAa;AAEhB,QAAK,yBAA0B;AAO9B,YAAM,8BAA8B;AAAA,QACnC,UAAU,eAAe;AAAA,MAC1B;AACA,YAAM,4BAA4B;AAAA,QACjC,UAAU,aAAa;AAAA,MACxB;AAEA;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAAA,IACD,OAAO;AAEN,qBAAgB,gBAAgB,cAAc,CAAE;AAAA,IACjD;AAAA,EACD,OAAO;AAKN,mBAAgB,cAAc,cAAc,CAAE;AAAA,EAC/C;AACD;AAWO,SAAS,oBACf,MACA,kBACqB;AACrB,MAAK,iBAAiB,WAAW,GAAI;AACpC,WAAO;AAAA,EACR;AAEA,QAAM,EAAE,OAAO,IAAI,IAAI,iBAAkB,CAAE;AAG3C,MACC,MAAM,SAAS,8CAAe,kBAC9B,IAAI,SAAS,8CAAe,gBAC3B;AACD,WAAO;AAAA,EACR;AAEA,QAAM,iBAAiB,kCAAmC,OAAO,IAAK;AACtE,QAAM,eAAe,kCAAmC,KAAK,IAAK;AAElE,MAAK,CAAE,kBAAkB,CAAE,cAAe;AACzC,WAAO;AAAA,EACR;AAGA,QAAM,eAAe,eAAe,WAAW,MAAM;AACrD,QAAM,aAAa,aAAa,WAAW,IAAI;AAE/C,MAAK,CAAE,gBAAgB,CAAE,YAAa;AACrC,WAAO;AAAA,EACR;AAEA,SAAO,EAAE,gBAAgB,aAAa;AACvC;",
|
|
6
6
|
"names": ["blockEditorStore"]
|
|
7
7
|
}
|
|
@@ -113,7 +113,7 @@ function getCursorPosition(selection, blocks) {
|
|
|
113
113
|
}
|
|
114
114
|
const relativePosition = import_sync.Y.createRelativePositionFromTypeIndex(
|
|
115
115
|
currentYText,
|
|
116
|
-
selection.offset
|
|
116
|
+
(0, import_crdt_utils.richTextOffsetToHtmlIndex)(currentYText.toString(), selection.offset)
|
|
117
117
|
);
|
|
118
118
|
return {
|
|
119
119
|
relativePosition,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/crdt-user-selections.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { select } 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 { CRDT_RECORD_MAP_KEY } from '../sync';\nimport type { YPostRecord } from './crdt';\nimport type { YBlock, YBlocks } from './crdt-blocks';\nimport { getRootMap } from './crdt-utils';\nimport type { SelectionDirection } from '../types';\nimport {\n\ttype AbsoluteBlockIndexPath,\n\ttype WPBlockSelection,\n\ttype SelectionState,\n\ttype SelectionNone,\n\ttype SelectionCursor,\n\ttype SelectionInOneBlock,\n\ttype SelectionInMultipleBlocks,\n\ttype SelectionWholeBlock,\n\ttype CursorPosition,\n} from '../types';\n\n/**\n * The type of selection.\n */\nexport enum SelectionType {\n\tNone = 'none',\n\tCursor = 'cursor',\n\tSelectionInOneBlock = 'selection-in-one-block',\n\tSelectionInMultipleBlocks = 'selection-in-multiple-blocks',\n\tWholeBlock = 'whole-block',\n}\n\n/**\n * Converts WordPress block editor selection to a SelectionState.\n *\n * Uses getBlockPathForLocalClientId to locate blocks in the Yjs document by\n * their tree position (index path) rather than clientId, since clientIds may\n * differ between the block-editor store and the Yjs document (e.g. in \"Show\n * Template\" mode).\n *\n * @param selectionStart - The start position of the selection\n * @param selectionEnd - The end position of the selection\n * @param yDoc - The Yjs document\n * @param options - Optional parameters\n * @param options.selectionDirection - The direction of the selection (forward or backward)\n * @return The SelectionState\n */\nexport function getSelectionState(\n\tselectionStart: WPBlockSelection,\n\tselectionEnd: WPBlockSelection,\n\tyDoc: Y.Doc,\n\toptions?: { selectionDirection?: SelectionDirection }\n): SelectionState {\n\tconst { selectionDirection } = options ?? {};\n\tconst ymap = getRootMap< YPostRecord >( yDoc, CRDT_RECORD_MAP_KEY );\n\tconst yBlocks = ymap.get( 'blocks' );\n\n\tconst isSelectionEmpty = Object.keys( selectionStart ).length === 0;\n\tconst noSelection: SelectionNone = {\n\t\ttype: SelectionType.None,\n\t};\n\n\tif ( isSelectionEmpty || ! yBlocks ) {\n\t\t// Case 1: No selection, or no blocks in the document.\n\t\treturn noSelection;\n\t}\n\n\t// When the page initially loads, selectionStart can contain an empty object `{}`.\n\tconst isSelectionInOneBlock =\n\t\tselectionStart.clientId === selectionEnd.clientId;\n\tconst isCursorOnly =\n\t\tisSelectionInOneBlock && selectionStart.offset === selectionEnd.offset;\n\tconst isSelectionAWholeBlock =\n\t\tisSelectionInOneBlock &&\n\t\tselectionStart.offset === undefined &&\n\t\tselectionEnd.offset === undefined;\n\n\tif ( isSelectionAWholeBlock ) {\n\t\t// Case 2: A whole block is selected.\n\t\tconst path = getBlockPathForLocalClientId( selectionStart.clientId );\n\t\tconst blockPosition = path\n\t\t\t? createRelativePositionForBlockPath( path, yBlocks )\n\t\t\t: null;\n\n\t\tif ( ! blockPosition ) {\n\t\t\treturn noSelection;\n\t\t}\n\n\t\treturn {\n\t\t\ttype: SelectionType.WholeBlock,\n\t\t\tblockPosition,\n\t\t};\n\t} else if ( isCursorOnly ) {\n\t\t// Case 3: Cursor only, no text selected\n\t\tconst cursorPosition = getCursorPosition( selectionStart, yBlocks );\n\n\t\tif ( ! cursorPosition ) {\n\t\t\t// If we can't find the cursor position in block text, treat it as a non-selection.\n\t\t\treturn noSelection;\n\t\t}\n\n\t\treturn {\n\t\t\ttype: SelectionType.Cursor,\n\t\t\tcursorPosition,\n\t\t};\n\t} else if ( isSelectionInOneBlock ) {\n\t\t// Case 4: Selection in a single block\n\t\tconst cursorStartPosition = getCursorPosition(\n\t\t\tselectionStart,\n\t\t\tyBlocks\n\t\t);\n\t\tconst cursorEndPosition = getCursorPosition( selectionEnd, yBlocks );\n\n\t\tif ( ! cursorStartPosition || ! cursorEndPosition ) {\n\t\t\t// If we can't find the cursor positions in block text, treat it as a non-selection.\n\t\t\treturn noSelection;\n\t\t}\n\n\t\treturn {\n\t\t\ttype: SelectionType.SelectionInOneBlock,\n\t\t\tcursorStartPosition,\n\t\t\tcursorEndPosition,\n\t\t\tselectionDirection,\n\t\t};\n\t}\n\n\t// Case 5: Selection in multiple blocks\n\tconst cursorStartPosition = getCursorPosition( selectionStart, yBlocks );\n\tconst cursorEndPosition = getCursorPosition( selectionEnd, yBlocks );\n\tif ( ! cursorStartPosition || ! cursorEndPosition ) {\n\t\t// If we can't find the cursor positions in block text, treat it as a non-selection.\n\t\treturn noSelection;\n\t}\n\n\treturn {\n\t\ttype: SelectionType.SelectionInMultipleBlocks,\n\t\tcursorStartPosition,\n\t\tcursorEndPosition,\n\t\tselectionDirection,\n\t};\n}\n\n/**\n * Get the cursor position from a selection.\n *\n * @param selection - The selection.\n * @param blocks - The blocks to search through.\n * @return The cursor position, or null if not found.\n */\nfunction getCursorPosition(\n\tselection: WPBlockSelection,\n\tblocks: YBlocks\n): CursorPosition | null {\n\tconst path = getBlockPathForLocalClientId( selection.clientId );\n\tconst block = path ? findBlockByPath( path, blocks ) : null;\n\tif (\n\t\t! block ||\n\t\t! selection.attributeKey ||\n\t\tundefined === selection.offset\n\t) {\n\t\treturn null;\n\t}\n\n\tconst attributes = block.get( 'attributes' );\n\tconst currentYText = attributes?.get( selection.attributeKey );\n\n\t// If the attribute is not a Y.Text, return null.\n\tif ( ! ( currentYText instanceof Y.Text ) ) {\n\t\treturn null;\n\t}\n\n\tconst relativePosition = Y.createRelativePositionFromTypeIndex(\n\t\tcurrentYText,\n\t\tselection.offset\n\t);\n\n\treturn {\n\t\trelativePosition,\n\t\tabsoluteOffset: selection.offset,\n\t};\n}\n\n/**\n * Resolves a local block-editor clientId to its index path relative to the\n * post content blocks. This allows finding the corresponding block in the Yjs\n * document even when clientIds differ (e.g. in \"Show Template\" mode where\n * blocks are cloned).\n *\n * In template mode, the block tree includes template parts and wrapper blocks\n * around a core/post-content block. The Yjs document only contains the post\n * content blocks, so we stop the upward walk when the parent is\n * core/post-content (its inner blocks correspond to the Yjs root blocks).\n *\n * @param clientId - The local block-editor clientId to resolve.\n * @return The index path from root, or null if not resolvable.\n */\nexport function getBlockPathForLocalClientId(\n\tclientId: string\n): AbsoluteBlockIndexPath | null {\n\tconst { getBlockIndex, getBlockRootClientId, getBlockName } =\n\t\tselect( blockEditorStore );\n\n\tconst path: AbsoluteBlockIndexPath = [];\n\tlet current: string | null = clientId;\n\twhile ( current ) {\n\t\tconst index = getBlockIndex( current );\n\t\tif ( index === -1 ) {\n\t\t\treturn null;\n\t\t}\n\t\tpath.unshift( index );\n\t\tconst parent = getBlockRootClientId( current );\n\t\tif ( ! parent ) {\n\t\t\tbreak;\n\t\t}\n\t\t// If the parent is core/post-content, stop here \u2014 the Yjs doc\n\t\t// root blocks correspond to post-content's inner blocks.\n\t\tconst parentName = getBlockName( parent );\n\t\tif ( parentName === 'core/post-content' ) {\n\t\t\tbreak;\n\t\t}\n\t\tcurrent = parent;\n\t}\n\treturn path.length > 0 ? path : null;\n}\n\n/**\n * Find a block by navigating a tree index path in the Yjs block hierarchy.\n *\n * @param path - The index path, e.g. [0, 1] for blocks[0].innerBlocks[1].\n * @param blocks - The root-level Yjs blocks array.\n * @return The block Y.Map if found, null otherwise.\n */\nfunction findBlockByPath(\n\tpath: AbsoluteBlockIndexPath,\n\tblocks: YBlocks\n): YBlock | null {\n\tlet currentBlocks = blocks;\n\tfor ( let i = 0; i < path.length; i++ ) {\n\t\tif ( path[ i ] >= currentBlocks.length ) {\n\t\t\treturn null;\n\t\t}\n\t\tconst block = currentBlocks.get( path[ i ] );\n\t\tif ( ! block ) {\n\t\t\treturn null;\n\t\t}\n\t\tif ( i === path.length - 1 ) {\n\t\t\treturn block;\n\t\t}\n\t\tcurrentBlocks =\n\t\t\tblock.get( 'innerBlocks' ) ?? ( new Y.Array() as YBlocks );\n\t}\n\treturn null;\n}\n\n/**\n * Create a Y.RelativePosition for a block by navigating a tree index path.\n *\n * @param path - The index path, e.g. [0, 1] for blocks[0].innerBlocks[1].\n * @param blocks - The root-level Yjs blocks array.\n * @return A Y.RelativePosition for the block, or null if the path is invalid.\n */\nfunction createRelativePositionForBlockPath(\n\tpath: AbsoluteBlockIndexPath,\n\tblocks: YBlocks\n): Y.RelativePosition | null {\n\tlet currentBlocks = blocks;\n\tfor ( let i = 0; i < path.length; i++ ) {\n\t\tif ( path[ i ] >= currentBlocks.length ) {\n\t\t\treturn null;\n\t\t}\n\t\tif ( i === path.length - 1 ) {\n\t\t\treturn Y.createRelativePositionFromTypeIndex(\n\t\t\t\tcurrentBlocks,\n\t\t\t\tpath[ i ]\n\t\t\t);\n\t\t}\n\t\tconst block = currentBlocks.get( path[ i ] );\n\t\tcurrentBlocks =\n\t\t\tblock?.get( 'innerBlocks' ) ?? ( new Y.Array() as YBlocks );\n\t}\n\treturn null;\n}\n\n/**\n * Check if two selection states are equal.\n *\n * @param selection1 - The first selection state.\n * @param selection2 - The second selection state.\n * @return True if the selection states are equal, false otherwise.\n */\nexport function areSelectionsStatesEqual(\n\tselection1: SelectionState,\n\tselection2: SelectionState\n): boolean {\n\tif ( selection1.type !== selection2.type ) {\n\t\treturn false;\n\t}\n\n\tswitch ( selection1.type ) {\n\t\tcase SelectionType.None:\n\t\t\treturn true;\n\n\t\tcase SelectionType.Cursor:\n\t\t\treturn areCursorPositionsEqual(\n\t\t\t\tselection1.cursorPosition,\n\t\t\t\t( selection2 as SelectionCursor ).cursorPosition\n\t\t\t);\n\n\t\tcase SelectionType.SelectionInOneBlock:\n\t\t\treturn (\n\t\t\t\tareCursorPositionsEqual(\n\t\t\t\t\tselection1.cursorStartPosition,\n\t\t\t\t\t( selection2 as SelectionInOneBlock ).cursorStartPosition\n\t\t\t\t) &&\n\t\t\t\tareCursorPositionsEqual(\n\t\t\t\t\tselection1.cursorEndPosition,\n\t\t\t\t\t( selection2 as SelectionInOneBlock ).cursorEndPosition\n\t\t\t\t) &&\n\t\t\t\tselection1.selectionDirection ===\n\t\t\t\t\t( selection2 as SelectionInOneBlock ).selectionDirection\n\t\t\t);\n\n\t\tcase SelectionType.SelectionInMultipleBlocks:\n\t\t\treturn (\n\t\t\t\tareCursorPositionsEqual(\n\t\t\t\t\tselection1.cursorStartPosition,\n\t\t\t\t\t( selection2 as SelectionInMultipleBlocks )\n\t\t\t\t\t\t.cursorStartPosition\n\t\t\t\t) &&\n\t\t\t\tareCursorPositionsEqual(\n\t\t\t\t\tselection1.cursorEndPosition,\n\t\t\t\t\t( selection2 as SelectionInMultipleBlocks )\n\t\t\t\t\t\t.cursorEndPosition\n\t\t\t\t) &&\n\t\t\t\tselection1.selectionDirection ===\n\t\t\t\t\t( selection2 as SelectionInMultipleBlocks )\n\t\t\t\t\t\t.selectionDirection\n\t\t\t);\n\t\tcase SelectionType.WholeBlock:\n\t\t\treturn Y.compareRelativePositions(\n\t\t\t\tselection1.blockPosition,\n\t\t\t\t( selection2 as SelectionWholeBlock ).blockPosition\n\t\t\t);\n\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\n/**\n * Check if two cursor positions are equal.\n *\n * @param cursorPosition1 - The first cursor position.\n * @param cursorPosition2 - The second cursor position.\n * @return True if the cursor positions are equal, false otherwise.\n */\nfunction areCursorPositionsEqual(\n\tcursorPosition1: CursorPosition,\n\tcursorPosition2: CursorPosition\n): boolean {\n\tconst isRelativePositionEqual = Y.compareRelativePositions(\n\t\tcursorPosition1.relativePosition,\n\t\tcursorPosition2.relativePosition\n\t);\n\n\t// Ensure a change in calculated absolute offset results in a treating the cursor as modified.\n\t// This is necessary because Y.Text relative positions can remain the same after text changes.\n\tconst isAbsoluteOffsetEqual =\n\t\tcursorPosition1.absoluteOffset === cursorPosition2.absoluteOffset;\n\n\treturn isRelativePositionEqual && isAbsoluteOffsetEqual;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAuB;AACvB,kBAAkB;AAElB,0BAA0C;AAK1C,IAAAA,eAAoC;AAGpC,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { select } 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 { CRDT_RECORD_MAP_KEY } from '../sync';\nimport type { YPostRecord } from './crdt';\nimport type { YBlock, YBlocks } from './crdt-blocks';\nimport { getRootMap, richTextOffsetToHtmlIndex } from './crdt-utils';\nimport type {\n\tAbsoluteBlockIndexPath,\n\tWPBlockSelection,\n\tSelectionState,\n\tSelectionNone,\n\tSelectionCursor,\n\tSelectionInOneBlock,\n\tSelectionInMultipleBlocks,\n\tSelectionWholeBlock,\n\tSelectionDirection,\n\tCursorPosition,\n} from '../types';\n\n/**\n * The type of selection.\n */\nexport enum SelectionType {\n\tNone = 'none',\n\tCursor = 'cursor',\n\tSelectionInOneBlock = 'selection-in-one-block',\n\tSelectionInMultipleBlocks = 'selection-in-multiple-blocks',\n\tWholeBlock = 'whole-block',\n}\n\n/**\n * Converts WordPress block editor selection to a SelectionState.\n *\n * Uses getBlockPathForLocalClientId to locate blocks in the Yjs document by\n * their tree position (index path) rather than clientId, since clientIds may\n * differ between the block-editor store and the Yjs document (e.g. in \"Show\n * Template\" mode).\n *\n * @param selectionStart - The start position of the selection\n * @param selectionEnd - The end position of the selection\n * @param yDoc - The Yjs document\n * @param options - Optional parameters\n * @param options.selectionDirection - The direction of the selection (forward or backward)\n * @return The SelectionState\n */\nexport function getSelectionState(\n\tselectionStart: WPBlockSelection,\n\tselectionEnd: WPBlockSelection,\n\tyDoc: Y.Doc,\n\toptions?: { selectionDirection?: SelectionDirection }\n): SelectionState {\n\tconst { selectionDirection } = options ?? {};\n\tconst ymap = getRootMap< YPostRecord >( yDoc, CRDT_RECORD_MAP_KEY );\n\tconst yBlocks = ymap.get( 'blocks' );\n\n\tconst isSelectionEmpty = Object.keys( selectionStart ).length === 0;\n\tconst noSelection: SelectionNone = {\n\t\ttype: SelectionType.None,\n\t};\n\n\tif ( isSelectionEmpty || ! yBlocks ) {\n\t\t// Case 1: No selection, or no blocks in the document.\n\t\treturn noSelection;\n\t}\n\n\t// When the page initially loads, selectionStart can contain an empty object `{}`.\n\tconst isSelectionInOneBlock =\n\t\tselectionStart.clientId === selectionEnd.clientId;\n\tconst isCursorOnly =\n\t\tisSelectionInOneBlock && selectionStart.offset === selectionEnd.offset;\n\tconst isSelectionAWholeBlock =\n\t\tisSelectionInOneBlock &&\n\t\tselectionStart.offset === undefined &&\n\t\tselectionEnd.offset === undefined;\n\n\tif ( isSelectionAWholeBlock ) {\n\t\t// Case 2: A whole block is selected.\n\t\tconst path = getBlockPathForLocalClientId( selectionStart.clientId );\n\t\tconst blockPosition = path\n\t\t\t? createRelativePositionForBlockPath( path, yBlocks )\n\t\t\t: null;\n\n\t\tif ( ! blockPosition ) {\n\t\t\treturn noSelection;\n\t\t}\n\n\t\treturn {\n\t\t\ttype: SelectionType.WholeBlock,\n\t\t\tblockPosition,\n\t\t};\n\t} else if ( isCursorOnly ) {\n\t\t// Case 3: Cursor only, no text selected\n\t\tconst cursorPosition = getCursorPosition( selectionStart, yBlocks );\n\n\t\tif ( ! cursorPosition ) {\n\t\t\t// If we can't find the cursor position in block text, treat it as a non-selection.\n\t\t\treturn noSelection;\n\t\t}\n\n\t\treturn {\n\t\t\ttype: SelectionType.Cursor,\n\t\t\tcursorPosition,\n\t\t};\n\t} else if ( isSelectionInOneBlock ) {\n\t\t// Case 4: Selection in a single block\n\t\tconst cursorStartPosition = getCursorPosition(\n\t\t\tselectionStart,\n\t\t\tyBlocks\n\t\t);\n\t\tconst cursorEndPosition = getCursorPosition( selectionEnd, yBlocks );\n\n\t\tif ( ! cursorStartPosition || ! cursorEndPosition ) {\n\t\t\t// If we can't find the cursor positions in block text, treat it as a non-selection.\n\t\t\treturn noSelection;\n\t\t}\n\n\t\treturn {\n\t\t\ttype: SelectionType.SelectionInOneBlock,\n\t\t\tcursorStartPosition,\n\t\t\tcursorEndPosition,\n\t\t\tselectionDirection,\n\t\t};\n\t}\n\n\t// Case 5: Selection in multiple blocks\n\tconst cursorStartPosition = getCursorPosition( selectionStart, yBlocks );\n\tconst cursorEndPosition = getCursorPosition( selectionEnd, yBlocks );\n\tif ( ! cursorStartPosition || ! cursorEndPosition ) {\n\t\t// If we can't find the cursor positions in block text, treat it as a non-selection.\n\t\treturn noSelection;\n\t}\n\n\treturn {\n\t\ttype: SelectionType.SelectionInMultipleBlocks,\n\t\tcursorStartPosition,\n\t\tcursorEndPosition,\n\t\tselectionDirection,\n\t};\n}\n\n/**\n * Get the cursor position from a selection.\n *\n * @param selection - The selection.\n * @param blocks - The blocks to search through.\n * @return The cursor position, or null if not found.\n */\nfunction getCursorPosition(\n\tselection: WPBlockSelection,\n\tblocks: YBlocks\n): CursorPosition | null {\n\tconst path = getBlockPathForLocalClientId( selection.clientId );\n\tconst block = path ? findBlockByPath( path, blocks ) : null;\n\tif (\n\t\t! block ||\n\t\t! selection.attributeKey ||\n\t\tundefined === selection.offset\n\t) {\n\t\treturn null;\n\t}\n\n\tconst attributes = block.get( 'attributes' );\n\tconst currentYText = attributes?.get( selection.attributeKey );\n\n\t// If the attribute is not a Y.Text, return null.\n\tif ( ! ( currentYText instanceof Y.Text ) ) {\n\t\treturn null;\n\t}\n\n\tconst relativePosition = Y.createRelativePositionFromTypeIndex(\n\t\tcurrentYText,\n\t\trichTextOffsetToHtmlIndex( currentYText.toString(), selection.offset )\n\t);\n\n\treturn {\n\t\trelativePosition,\n\t\tabsoluteOffset: selection.offset,\n\t};\n}\n\n/**\n * Resolves a local block-editor clientId to its index path relative to the\n * post content blocks. This allows finding the corresponding block in the Yjs\n * document even when clientIds differ (e.g. in \"Show Template\" mode where\n * blocks are cloned).\n *\n * In template mode, the block tree includes template parts and wrapper blocks\n * around a core/post-content block. The Yjs document only contains the post\n * content blocks, so we stop the upward walk when the parent is\n * core/post-content (its inner blocks correspond to the Yjs root blocks).\n *\n * @param clientId - The local block-editor clientId to resolve.\n * @return The index path from root, or null if not resolvable.\n */\nexport function getBlockPathForLocalClientId(\n\tclientId: string\n): AbsoluteBlockIndexPath | null {\n\tconst { getBlockIndex, getBlockRootClientId, getBlockName } =\n\t\tselect( blockEditorStore );\n\n\tconst path: AbsoluteBlockIndexPath = [];\n\tlet current: string | null = clientId;\n\twhile ( current ) {\n\t\tconst index = getBlockIndex( current );\n\t\tif ( index === -1 ) {\n\t\t\treturn null;\n\t\t}\n\t\tpath.unshift( index );\n\t\tconst parent = getBlockRootClientId( current );\n\t\tif ( ! parent ) {\n\t\t\tbreak;\n\t\t}\n\t\t// If the parent is core/post-content, stop here \u2014 the Yjs doc\n\t\t// root blocks correspond to post-content's inner blocks.\n\t\tconst parentName = getBlockName( parent );\n\t\tif ( parentName === 'core/post-content' ) {\n\t\t\tbreak;\n\t\t}\n\t\tcurrent = parent;\n\t}\n\treturn path.length > 0 ? path : null;\n}\n\n/**\n * Find a block by navigating a tree index path in the Yjs block hierarchy.\n *\n * @param path - The index path, e.g. [0, 1] for blocks[0].innerBlocks[1].\n * @param blocks - The root-level Yjs blocks array.\n * @return The block Y.Map if found, null otherwise.\n */\nfunction findBlockByPath(\n\tpath: AbsoluteBlockIndexPath,\n\tblocks: YBlocks\n): YBlock | null {\n\tlet currentBlocks = blocks;\n\tfor ( let i = 0; i < path.length; i++ ) {\n\t\tif ( path[ i ] >= currentBlocks.length ) {\n\t\t\treturn null;\n\t\t}\n\t\tconst block = currentBlocks.get( path[ i ] );\n\t\tif ( ! block ) {\n\t\t\treturn null;\n\t\t}\n\t\tif ( i === path.length - 1 ) {\n\t\t\treturn block;\n\t\t}\n\t\tcurrentBlocks =\n\t\t\tblock.get( 'innerBlocks' ) ?? ( new Y.Array() as YBlocks );\n\t}\n\treturn null;\n}\n\n/**\n * Create a Y.RelativePosition for a block by navigating a tree index path.\n *\n * @param path - The index path, e.g. [0, 1] for blocks[0].innerBlocks[1].\n * @param blocks - The root-level Yjs blocks array.\n * @return A Y.RelativePosition for the block, or null if the path is invalid.\n */\nfunction createRelativePositionForBlockPath(\n\tpath: AbsoluteBlockIndexPath,\n\tblocks: YBlocks\n): Y.RelativePosition | null {\n\tlet currentBlocks = blocks;\n\tfor ( let i = 0; i < path.length; i++ ) {\n\t\tif ( path[ i ] >= currentBlocks.length ) {\n\t\t\treturn null;\n\t\t}\n\t\tif ( i === path.length - 1 ) {\n\t\t\treturn Y.createRelativePositionFromTypeIndex(\n\t\t\t\tcurrentBlocks,\n\t\t\t\tpath[ i ]\n\t\t\t);\n\t\t}\n\t\tconst block = currentBlocks.get( path[ i ] );\n\t\tcurrentBlocks =\n\t\t\tblock?.get( 'innerBlocks' ) ?? ( new Y.Array() as YBlocks );\n\t}\n\treturn null;\n}\n\n/**\n * Check if two selection states are equal.\n *\n * @param selection1 - The first selection state.\n * @param selection2 - The second selection state.\n * @return True if the selection states are equal, false otherwise.\n */\nexport function areSelectionsStatesEqual(\n\tselection1: SelectionState,\n\tselection2: SelectionState\n): boolean {\n\tif ( selection1.type !== selection2.type ) {\n\t\treturn false;\n\t}\n\n\tswitch ( selection1.type ) {\n\t\tcase SelectionType.None:\n\t\t\treturn true;\n\n\t\tcase SelectionType.Cursor:\n\t\t\treturn areCursorPositionsEqual(\n\t\t\t\tselection1.cursorPosition,\n\t\t\t\t( selection2 as SelectionCursor ).cursorPosition\n\t\t\t);\n\n\t\tcase SelectionType.SelectionInOneBlock:\n\t\t\treturn (\n\t\t\t\tareCursorPositionsEqual(\n\t\t\t\t\tselection1.cursorStartPosition,\n\t\t\t\t\t( selection2 as SelectionInOneBlock ).cursorStartPosition\n\t\t\t\t) &&\n\t\t\t\tareCursorPositionsEqual(\n\t\t\t\t\tselection1.cursorEndPosition,\n\t\t\t\t\t( selection2 as SelectionInOneBlock ).cursorEndPosition\n\t\t\t\t) &&\n\t\t\t\tselection1.selectionDirection ===\n\t\t\t\t\t( selection2 as SelectionInOneBlock ).selectionDirection\n\t\t\t);\n\n\t\tcase SelectionType.SelectionInMultipleBlocks:\n\t\t\treturn (\n\t\t\t\tareCursorPositionsEqual(\n\t\t\t\t\tselection1.cursorStartPosition,\n\t\t\t\t\t( selection2 as SelectionInMultipleBlocks )\n\t\t\t\t\t\t.cursorStartPosition\n\t\t\t\t) &&\n\t\t\t\tareCursorPositionsEqual(\n\t\t\t\t\tselection1.cursorEndPosition,\n\t\t\t\t\t( selection2 as SelectionInMultipleBlocks )\n\t\t\t\t\t\t.cursorEndPosition\n\t\t\t\t) &&\n\t\t\t\tselection1.selectionDirection ===\n\t\t\t\t\t( selection2 as SelectionInMultipleBlocks )\n\t\t\t\t\t\t.selectionDirection\n\t\t\t);\n\t\tcase SelectionType.WholeBlock:\n\t\t\treturn Y.compareRelativePositions(\n\t\t\t\tselection1.blockPosition,\n\t\t\t\t( selection2 as SelectionWholeBlock ).blockPosition\n\t\t\t);\n\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\n/**\n * Check if two cursor positions are equal.\n *\n * @param cursorPosition1 - The first cursor position.\n * @param cursorPosition2 - The second cursor position.\n * @return True if the cursor positions are equal, false otherwise.\n */\nfunction areCursorPositionsEqual(\n\tcursorPosition1: CursorPosition,\n\tcursorPosition2: CursorPosition\n): boolean {\n\tconst isRelativePositionEqual = Y.compareRelativePositions(\n\t\tcursorPosition1.relativePosition,\n\t\tcursorPosition2.relativePosition\n\t);\n\n\t// Ensure a change in calculated absolute offset results in a treating the cursor as modified.\n\t// This is necessary because Y.Text relative positions can remain the same after text changes.\n\tconst isAbsoluteOffsetEqual =\n\t\tcursorPosition1.absoluteOffset === cursorPosition2.absoluteOffset;\n\n\treturn isRelativePositionEqual && isAbsoluteOffsetEqual;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAuB;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C,KACA;AAAA,QACC,WAAW;AAAA,QACT,WAAoC;AAAA,MACvC,KACA,WAAW,uBACR,WAAoC;AAAA,IAGzC,KAAK;AACJ,aACC;AAAA,QACC,WAAW;AAAA,QACT,WACA;AAAA,MACH,KACA;AAAA,QACC,WAAW;AAAA,QACT,WACA;AAAA,MACH,KACA,WAAW,uBACR,WACA;AAAA,IAEL,KAAK;AACJ,aAAO,cAAE;AAAA,QACR,WAAW;AAAA,QACT,WAAoC;AAAA,MACvC;AAAA,IAED;AACC,aAAO;AAAA,EACT;AACD;AASA,SAAS,wBACR,iBACA,iBACU;AACV,QAAM,0BAA0B,cAAE;AAAA,IACjC,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,EACjB;AAIA,QAAM,wBACL,gBAAgB,mBAAmB,gBAAgB;AAEpD,SAAO,2BAA2B;AACnC;",
|
|
6
6
|
"names": ["import_sync", "SelectionType", "cursorStartPosition", "cursorEndPosition", "blockEditorStore"]
|
|
7
7
|
}
|