-
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.
Rich text core: remove dependency on block client ID and other block …
…specific behaviour (#31752)
- Loading branch information
Showing
8 changed files
with
615 additions
and
416 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
packages/block-editor/src/components/rich-text/format-edit.js
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,44 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { getActiveFormat, getActiveObject } from '@wordpress/rich-text'; | ||
|
||
export default function FormatEdit( { | ||
formatTypes, | ||
onChange, | ||
onFocus, | ||
value, | ||
forwardedRef, | ||
} ) { | ||
return formatTypes.map( ( settings ) => { | ||
const { name, edit: Edit } = settings; | ||
|
||
if ( ! Edit ) { | ||
return null; | ||
} | ||
|
||
const activeFormat = getActiveFormat( value, name ); | ||
const isActive = activeFormat !== undefined; | ||
const activeObject = getActiveObject( value ); | ||
const isObjectActive = | ||
activeObject !== undefined && activeObject.type === name; | ||
|
||
return ( | ||
<Edit | ||
key={ name } | ||
isActive={ isActive } | ||
activeAttributes={ | ||
isActive ? activeFormat.attributes || {} : {} | ||
} | ||
isObjectActive={ isObjectActive } | ||
activeObjectAttributes={ | ||
isObjectActive ? activeObject.attributes || {} : {} | ||
} | ||
value={ value } | ||
onChange={ onChange } | ||
onFocus={ onFocus } | ||
contentRef={ forwardedRef } | ||
/> | ||
); | ||
} ); | ||
} |
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.