-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Coediting: Display user id when block gets frozen
- Loading branch information
Showing
12 changed files
with
409 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* External dependency | ||
*/ | ||
import classnames from 'classnames'; | ||
import { connect } from 'react-redux'; | ||
|
||
/** | ||
* WordPress dependency | ||
*/ | ||
import { BlockEdit, getBlockDefaultClassname, getBlockType, hasBlockSupport } from '@wordpress/blocks'; | ||
import { addFilter } from '@wordpress/hooks'; | ||
import { getWrapperDisplayName } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependency | ||
*/ | ||
import './style.scss'; | ||
// TODO: Move selectors to the local folder | ||
import { | ||
getBlock, | ||
getFrozenBlockCollaboratorColor, | ||
getFrozenBlockCollaboratorName, | ||
isBlockFrozenByCollaborator, | ||
} from '../../editor/selectors'; | ||
|
||
const withFrozenMode = ( OriginalComponent, originalProps ) => { | ||
const Component = ( { isFrozenByCollaborator, ...props } ) => { | ||
if ( isFrozenByCollaborator ) { | ||
const { block, collaboratorColor, collaboratorName } = props; | ||
const { attributes, name, isValid, uid } = block; | ||
const blockType = getBlockType( name ); | ||
|
||
// Determine whether the block has props to apply to the wrapper. | ||
let wrapperProps; | ||
if ( blockType.getEditWrapperProps ) { | ||
wrapperProps = blockType.getEditWrapperProps( attributes ); | ||
} | ||
|
||
// Generate a class name for the block's editable form | ||
const generatedClassName = hasBlockSupport( blockType, 'className', true ) ? | ||
getBlockDefaultClassname( block.name ) : | ||
null; | ||
const className = classnames( generatedClassName, block.attributes.className ); | ||
|
||
return ( | ||
<div | ||
className={ `editor-block-list__block is-frozen-by-collaborator is-${ collaboratorColor }` } | ||
{ ...wrapperProps } | ||
> | ||
<legend className="coediting-legend">{ collaboratorName }</legend> | ||
<div className="editor-block-list__block-edit"> | ||
{ isValid && <BlockEdit | ||
attributes={ attributes } | ||
className={ className } | ||
id={ uid } | ||
name={ name } | ||
/> } | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
return <OriginalComponent { ...originalProps } />; | ||
}; | ||
Component.displayName = getWrapperDisplayName( OriginalComponent, 'frozen-mode' ); | ||
|
||
const mapStateToProps = ( state, { uid } ) => ( { | ||
block: getBlock( state, uid ), | ||
collaboratorColor: getFrozenBlockCollaboratorColor( state, uid ), | ||
collaboratorName: getFrozenBlockCollaboratorName( state, uid ), | ||
isFrozenByCollaborator: isBlockFrozenByCollaborator( state, uid ), | ||
} ); | ||
|
||
return connect( mapStateToProps )( Component ); | ||
}; | ||
|
||
addFilter( 'Editor.BlockItem', 'coediting/block-item/frozen-mode', withFrozenMode ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
$coediting-green: #46b450; | ||
$coediting-orange: #f56e28; | ||
$coediting-purple: #826eb4; | ||
$coediting-red: #dc3232; | ||
$coediting-yellow: #ffb900; | ||
|
||
.is-frozen-by-collaborator { | ||
&.editor-block-list__block { | ||
cursor: not-allowed; | ||
pointer-events: none; | ||
user-select: none; | ||
|
||
&:before { | ||
outline: 1px solid; | ||
} | ||
|
||
.coediting-legend { | ||
color: $white; | ||
font-size: $default-font-size; | ||
padding: 2px 5px; | ||
position: absolute; | ||
right: 0; | ||
top: 0; | ||
z-index: 50; | ||
|
||
@include break-small { | ||
right: $block-mover-padding-visible | ||
} | ||
} | ||
|
||
&.is-green { | ||
&:before { | ||
outline-color:$coediting-green; | ||
} | ||
.coediting-legend { | ||
background-color: $coediting-green; | ||
} | ||
} | ||
|
||
&.is-orange { | ||
&:before { | ||
outline-color:$coediting-orange; | ||
} | ||
.coediting-legend { | ||
background-color: $coediting-orange; | ||
} | ||
} | ||
|
||
&.is-purple { | ||
&:before { | ||
outline-color:$coediting-purple; | ||
} | ||
.coediting-legend { | ||
background-color: $coediting-purple; | ||
} | ||
} | ||
|
||
&.is-red { | ||
&:before { | ||
outline-color:$coediting-red; | ||
} | ||
.coediting-legend { | ||
background-color: $coediting-red; | ||
} | ||
} | ||
|
||
&.is-yellow { | ||
&:before { | ||
outline-color:$coediting-yellow; | ||
} | ||
.coediting-legend { | ||
background-color: $coediting-yellow; | ||
} | ||
} | ||
} | ||
|
||
.editor-block-list__block-edit { | ||
opacity: 0.8; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.