Skip to content

Commit

Permalink
Revert list-view changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ajlende committed Apr 9, 2024
1 parent 5d0a81a commit 9e5640a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 44 deletions.
5 changes: 1 addition & 4 deletions packages/block-editor/src/components/list-view/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ function ListViewBlock( {
isExpanded,
selectedClientIds,
isSyncedBranch,
hideInnerBlocks,
} ) {
const cellRef = useRef( null );
const rowRef = useRef( null );
Expand Down Expand Up @@ -317,9 +316,7 @@ function ListViewBlock( {
path={ path }
id={ `list-view-${ listViewInstanceId }-block-${ clientId }` }
data-block={ clientId }
data-expanded={
canEdit && ! hideInnerBlocks ? isExpanded : undefined
}
data-expanded={ canEdit ? isExpanded : undefined }
ref={ rowRef }
>
<TreeGridCell
Expand Down
58 changes: 21 additions & 37 deletions packages/block-editor/src/components/list-view/branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function ListViewBranch( props ) {
fixedListWindow,
isExpanded,
parentId,
shouldShowInnerBlocks = true,
isSyncedBranch = false,
showAppender: showAppenderProp = true,
} = props;
Expand All @@ -113,17 +114,6 @@ function ListViewBranch( props ) {
[ parentId ]
);

const { getHasOverlay, isZoomOutMode } = useSelect( ( select ) => {
return {
getHasOverlay:
select( blockEditorStore )
.__unstableHasActiveBlockOverlayActive,
isZoomOutMode:
select( blockEditorStore ).__unstableGetEditorMode() ===
'zoom-out',
};
}, [] );

const {
blockDropPosition,
blockDropTargetIndex,
Expand Down Expand Up @@ -184,9 +174,10 @@ function ListViewBranch( props ) {
: `${ position }`;
const hasNestedBlocks = !! innerBlocks?.length;

const shouldExpand = hasNestedBlocks
? expandedState[ clientId ] ?? isExpanded
: undefined;
const shouldExpand =
hasNestedBlocks && shouldShowInnerBlocks
? expandedState[ clientId ] ?? isExpanded
: undefined;

// Make updates to the selected or dragged blocks synchronous,
// but asynchronous for any other block.
Expand All @@ -197,9 +188,6 @@ function ListViewBranch( props ) {
const isSelectedBranch =
isBranchSelected || ( isSelected && hasNestedBlocks );

const hideInnerBlocks =
isZoomOutMode && getHasOverlay( clientId );

// To avoid performance issues, we only render blocks that are in view,
// or blocks that are selected or dragged. If a block is selected,
// it is only counted if it is the first of the block selection.
Expand Down Expand Up @@ -232,33 +220,29 @@ function ListViewBranch( props ) {
displacement={ displacement }
isAfterDraggedBlocks={ isAfterDraggedBlocks }
isNesting={ isNesting }
hideInnerBlocks={ hideInnerBlocks }
/>
) }
{ ! showBlock && (
<tr>
<td className="block-editor-list-view-placeholder" />
</tr>
) }
{ hasNestedBlocks &&
shouldExpand &&
! hideInnerBlocks &&
! isDragged && (
<ListViewBranch
parentId={ clientId }
blocks={ innerBlocks }
selectBlock={ selectBlock }
showBlockMovers={ showBlockMovers }
level={ level + 1 }
path={ updatedPath }
listPosition={ nextPosition + 1 }
fixedListWindow={ fixedListWindow }
isBranchSelected={ isSelectedBranch }
selectedClientIds={ selectedClientIds }
isExpanded={ isExpanded }
isSyncedBranch={ syncedBranch }
/>
) }
{ hasNestedBlocks && shouldExpand && ! isDragged && (
<ListViewBranch
parentId={ clientId }
blocks={ innerBlocks }
selectBlock={ selectBlock }
showBlockMovers={ showBlockMovers }
level={ level + 1 }
path={ updatedPath }
listPosition={ nextPosition + 1 }
fixedListWindow={ fixedListWindow }
isBranchSelected={ isSelectedBranch }
selectedClientIds={ selectedClientIds }
isExpanded={ isExpanded }
isSyncedBranch={ syncedBranch }
/>
) }
</AsyncModeProvider>
);
} ) }
Expand Down
11 changes: 8 additions & 3 deletions packages/block-editor/src/components/list-view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,20 @@ function ListViewComponent(
const blockIndexes = useListViewBlockIndexes( clientIdsTree );

const { getBlock } = useSelect( blockEditorStore );
const { visibleBlockCount } = useSelect(
const { visibleBlockCount, shouldShowInnerBlocks } = useSelect(
( select ) => {
const { getGlobalBlockCount, getClientIdsOfDescendants } =
select( blockEditorStore );
const {
getGlobalBlockCount,
getClientIdsOfDescendants,
__unstableGetEditorMode,
} = select( blockEditorStore );
const draggedBlockCount =
draggedClientIds?.length > 0
? getClientIdsOfDescendants( draggedClientIds ).length + 1
: 0;
return {
visibleBlockCount: getGlobalBlockCount() - draggedBlockCount,
shouldShowInnerBlocks: __unstableGetEditorMode() !== 'zoom-out',
};
},
[ draggedClientIds ]
Expand Down Expand Up @@ -393,6 +397,7 @@ function ListViewComponent(
fixedListWindow={ fixedListWindow }
selectedClientIds={ selectedClientIds }
isExpanded={ isExpanded }
shouldShowInnerBlocks={ shouldShowInnerBlocks }
showAppender={ showAppender }
/>
</ListViewContext.Provider>
Expand Down

0 comments on commit 9e5640a

Please sign in to comment.