Skip to content

Commit

Permalink
Site Editor: use EditorProvider instead of custom logic (#56000)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored Nov 16, 2023
1 parent c5b1249 commit f9b544d
Show file tree
Hide file tree
Showing 16 changed files with 444 additions and 635 deletions.
23 changes: 2 additions & 21 deletions packages/block-editor/src/components/provider/use-block-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,11 @@ export default function useBlockSync( {
resetBlocks,
resetSelection,
replaceInnerBlocks,
selectBlock,
setHasControlledInnerBlocks,
__unstableMarkNextChangeAsNotPersistent,
} = registry.dispatch( blockEditorStore );
const {
hasSelectedBlock,
getBlockName,
getBlocks,
getSelectionStart,
getSelectionEnd,
getBlock,
} = registry.select( blockEditorStore );
const { getBlockName, getBlocks, getSelectionStart, getSelectionEnd } =
registry.select( blockEditorStore );
const isControlled = useSelect(
( select ) => {
return (
Expand Down Expand Up @@ -180,9 +173,6 @@ export default function useBlockSync( {
// bound sync, unset the outbound value to avoid considering it in
// subsequent renders.
pendingChanges.current.outgoing = [];
const hadSelection = hasSelectedBlock();
const selectionAnchor = getSelectionStart();
const selectionFocus = getSelectionEnd();
setControlledBlocks();

if ( controlledSelection ) {
Expand All @@ -191,15 +181,6 @@ export default function useBlockSync( {
controlledSelection.selectionEnd,
controlledSelection.initialPosition
);
} else {
const selectionStillExists = getBlock(
selectionAnchor.clientId
);
if ( hadSelection && ! selectionStillExists ) {
selectBlock( clientId );
} else {
resetSelection( selectionAnchor, selectionFocus );
}
}
}
}, [ controlledBlocks, clientId ] );
Expand Down
9 changes: 8 additions & 1 deletion packages/core-data/src/entity-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ export function useEntityBlockEditor( kind, name, { id: _id } = {} ) {
const id = _id ?? providerId;
const { content, editedBlocks, meta } = useSelect(
( select ) => {
if ( ! id ) {
return {};
}
const { getEditedEntityRecord } = select( STORE_NAME );
const editedRecord = getEditedEntityRecord( kind, name, id );
return {
Expand All @@ -169,14 +172,18 @@ export function useEntityBlockEditor( kind, name, { id: _id } = {} ) {
useDispatch( STORE_NAME );

const blocks = useMemo( () => {
if ( ! id ) {
return undefined;
}

if ( editedBlocks ) {
return editedBlocks;
}

return content && typeof content !== 'function'
? parse( content )
: EMPTY_ARRAY;
}, [ editedBlocks, content ] );
}, [ id, editedBlocks, content ] );

const updateFootnotes = useCallback(
( _blocks ) => updateFootnotesFromMeta( _blocks, meta ),
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit f9b544d

Please sign in to comment.