Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Switch to a more generic 'isBlockInterfaceHidden' approach
  • Loading branch information
glendaviesnz committed Oct 30, 2022
commit 422e17f5fe81bad7f508773b600ec22d8ee142d2
32 changes: 16 additions & 16 deletions docs/reference-guides/data/data-core-block-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,18 @@ _Returns_

- `?boolean`: Whether the insertion point is visible or not.

### isBlockInterfaceHidden

Returns true if the the block interface should be hidden, or false otherwise.

_Parameters_

- _state_ `Object`: Global application state.

_Returns_

- `boolean`: Whether the block toolbar is hidden.

### isBlockMultiSelected

Returns true if the client ID occurs within the block multi-selection, or
Expand Down Expand Up @@ -963,18 +975,6 @@ _Returns_

- `boolean`: Whether block is selected and multi-selection exists.

### isBlockToolbarHidden

Returns true if the the block toolbar should be hidden, or false otherwise.

_Parameters_

- _state_ `Object`: Global application state.

_Returns_

- `boolean`: Whether the block toolbar is hidden.

### isBlockValid

Returns whether a block is valid or not.
Expand Down Expand Up @@ -1199,9 +1199,9 @@ _Parameters_

- _clientId_ `string`: Target block client ID.

### hideBlockToolbar
### hideBlockInterface

Returns an action object used in signalling that the user has begun to show spacing visualizer.
Returns an action object used in signalling that the block interface, eg. toolbar, outline, etc. should be hidden.

_Returns_

Expand Down Expand Up @@ -1522,9 +1522,9 @@ _Returns_

- `Object`: Action object.

### showBlockToolbar
### showBlockInterface

Returns an action object used in signalling that the user has stopped showing spacing visualizer.
Returns an action object used in signalling that the block interface, eg. toolbar, outline, etc. should be shown.

_Returns_

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function selector( select ) {
isMultiSelecting,
hasMultiSelection,
isTyping,
isBlockToolbarHidden,
isBlockInterfaceHidden,
getSettings,
getLastMultiSelectedBlockClientId,
} = select( blockEditorStore );
Expand All @@ -37,7 +37,7 @@ function selector( select ) {
editorMode: __unstableGetEditorMode(),
isMultiSelecting: isMultiSelecting(),
isTyping: isTyping(),
isBlockToolbarHidden: isBlockToolbarHidden(),
isBlockInterfaceHidden: isBlockInterfaceHidden(),
hasFixedToolbar: getSettings().hasFixedToolbar,
isDistractionFree: getSettings().isDistractionFree,
lastClientId: hasMultiSelection()
Expand All @@ -59,7 +59,7 @@ function SelectedBlockPopover( {
editorMode,
isMultiSelecting,
isTyping,
isBlockToolbarHidden,
isBlockInterfaceHidden,
hasFixedToolbar,
isDistractionFree,
lastClientId,
Expand Down Expand Up @@ -97,7 +97,7 @@ function SelectedBlockPopover( {
! isMultiSelecting &&
! showEmptyBlockSideInserter &&
! isTyping &&
! isBlockToolbarHidden;
! isBlockInterfaceHidden;
const canFocusHiddenToolbar =
editorMode === 'edit' &&
! shouldShowContextualToolbar &&
Expand Down
6 changes: 3 additions & 3 deletions packages/block-editor/src/hooks/dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ export const AXIAL_SIDES = [ 'vertical', 'horizontal' ];

function useVisualizerMouseOver() {
const [ isMouseOver, setIsMouseOver ] = useState( false );
const { hideBlockToolbar, showBlockToolbar } =
const { hideBlockInterface, showBlockInterface } =
useDispatch( blockEditorStore );
const onMouseOver = () => {
hideBlockToolbar();
hideBlockInterface();
setIsMouseOver( true );
};
const onMouseOut = () => {
showBlockToolbar();
showBlockInterface();
setIsMouseOver( false );
};
return { isMouseOver, onMouseOver, onMouseOut };
Expand Down
12 changes: 6 additions & 6 deletions packages/block-editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1264,24 +1264,24 @@ export function toggleBlockMode( clientId ) {
}

/**
* Returns an action object used in signalling that the user has begun to show spacing visualizer.
* Returns an action object used in signalling that the block interface, eg. toolbar, outline, etc. should be hidden.
*
* @return {Object} Action object.
*/
export function hideBlockToolbar() {
export function hideBlockInterface() {
return {
type: 'HIDE_BLOCK_TOOLBAR',
type: 'HIDE_BLOCK_INTERFACE',
};
}

/**
* Returns an action object used in signalling that the user has stopped showing spacing visualizer.
* Returns an action object used in signalling that the block interface, eg. toolbar, outline, etc. should be shown.
*
* @return {Object} Action object.
*/
export function showBlockToolbar() {
export function showBlockInterface() {
return {
type: 'SHOW_BLOCK_TOOLBAR',
type: 'SHOW_BLOCK_INTERFACE',
};
}

Expand Down
10 changes: 5 additions & 5 deletions packages/block-editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1161,19 +1161,19 @@ export const blocks = pipe(
} );

/**
* Reducer returning visibility status of block toolbar.
* Reducer returning visibility status of block interface.
*
* @param {boolean} state Current state.
* @param {Object} action Dispatched action.
*
* @return {boolean} Updated state.
*/
export function isBlockToolbarHidden( state = false, action ) {
export function isBlockInterfaceHidden( state = false, action ) {
switch ( action.type ) {
case 'HIDE_BLOCK_TOOLBAR':
case 'HIDE_BLOCK_INTERFACE':
return true;

case 'SHOW_BLOCK_TOOLBAR':
case 'SHOW_BLOCK_INTERFACE':
return false;
}

Expand Down Expand Up @@ -1829,7 +1829,7 @@ export function temporarilyEditingAsBlocks( state = '', action ) {
export default combineReducers( {
blocks,
isTyping,
isBlockToolbarHidden,
isBlockInterfaceHidden,
draggedBlocks,
selection,
isMultiSelecting,
Expand Down
6 changes: 3 additions & 3 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1277,14 +1277,14 @@ export function isTyping( state ) {
}

/**
* Returns true if the the block toolbar should be hidden, or false otherwise.
* Returns true if the the block interface should be hidden, or false otherwise.
*
* @param {Object} state Global application state.
*
* @return {boolean} Whether the block toolbar is hidden.
*/
export function isBlockToolbarHidden( state ) {
return state.isBlockToolbarHidden;
export function isBlockInterfaceHidden( state ) {
return state.isBlockInterfaceHidden;
}

/**
Expand Down
20 changes: 10 additions & 10 deletions packages/block-editor/src/store/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const noop = () => {};

const {
clearSelectedBlock,
hideBlockToolbar,
hideBlockInterface,
insertBlock,
insertBlocks,
mergeBlocks,
Expand All @@ -40,7 +40,7 @@ const {
replaceInnerBlocks,
resetBlocks,
selectBlock,
showBlockToolbar,
showBlockInterface,
showInsertionPoint,
startMultiSelect,
startTyping,
Expand Down Expand Up @@ -777,18 +777,18 @@ describe( 'actions', () => {
} );
} );

describe( 'hideBlockToolbar', () => {
it( 'should return the HIDE_BLOCK_TOOLBAR action', () => {
expect( hideBlockToolbar() ).toEqual( {
type: 'HIDE_BLOCK_TOOLBAR',
describe( 'hideBlockInterface', () => {
it( 'should return the HIDE_BLOCK_INTERFACE action', () => {
expect( hideBlockInterface() ).toEqual( {
type: 'HIDE_BLOCK_INTERFACE',
} );
} );
} );

describe( 'showBlockToolbar', () => {
it( 'should return the SHOW_BLOCK_TOOLBAR action', () => {
expect( showBlockToolbar() ).toEqual( {
type: 'SHOW_BLOCK_TOOLBAR',
describe( 'showBlockInterface', () => {
it( 'should return the SHOW_BLOCK_INTERFACE action', () => {
expect( showBlockInterface() ).toEqual( {
type: 'SHOW_BLOCK_INTERFACE',
} );
} );
} );
Expand Down
16 changes: 8 additions & 8 deletions packages/block-editor/src/store/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
hasSameKeys,
isUpdatingSameBlockAttribute,
blocks,
isBlockToolbarHidden,
isBlockInterfaceHidden,
isTyping,
draggedBlocks,
selection,
Expand Down Expand Up @@ -2254,18 +2254,18 @@ describe( 'state', () => {
} );
} );

describe( 'isBlockToolbarHidden()', () => {
it( 'should set the hide block toolbar flag to true', () => {
const state = isBlockToolbarHidden( false, {
type: 'HIDE_BLOCK_TOOLBAR',
describe( 'isBlockInterfaceHidden()', () => {
it( 'should set the hide block interface flag to true', () => {
const state = isBlockInterfaceHidden( false, {
type: 'HIDE_BLOCK_INTERFACE',
} );

expect( state ).toBe( true );
} );

it( 'should set the hide block toolbar flag to false', () => {
const state = isBlockToolbarHidden( false, {
type: 'SHOW_BLOCK_TOOLBAR',
it( 'should set the hide block interface flag to false', () => {
const state = isBlockInterfaceHidden( false, {
type: 'SHOW_BLOCK_INTERFACE',
} );

expect( state ).toBe( false );
Expand Down
16 changes: 8 additions & 8 deletions packages/block-editor/src/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const {
isBlockMultiSelected,
isFirstMultiSelectedBlock,
getBlockMode,
isBlockToolbarHidden,
isBlockInterfaceHidden,
isTyping,
isDraggingBlocks,
getDraggedBlockClientIds,
Expand Down Expand Up @@ -1941,21 +1941,21 @@ describe( 'selectors', () => {
} );
} );

describe( 'isBlockToolbarHidden', () => {
it( 'should return the true if toggled try in state', () => {
describe( 'isBlockInterfaceHidden', () => {
it( 'should return the true if toggled true in state', () => {
const state = {
isBlockToolbarHidden: true,
isBlockInterfaceHidden: true,
};

expect( isBlockToolbarHidden( state ) ).toBe( true );
expect( isBlockInterfaceHidden( state ) ).toBe( true );
} );

it( 'should return false if toggle false in state', () => {
it( 'should return false if toggled false in state', () => {
const state = {
isBlockToolbarHidden: false,
isBlockInterfaceHidden: false,
};

expect( isBlockToolbarHidden( state ) ).toBe( false );
expect( isBlockInterfaceHidden( state ) ).toBe( false );
} );
} );

Expand Down