/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/format-library/src/unknown/index.js
45 строк
1008 B
Marco Ciampini
ESLint: Replace strict config with bulk suppressions (#81248)
07 авг 2026, 14:34
Не верифицирован
07 авг 2026, 14:34
7f43eaf
Код
Авторство
О чём код?
import { __ } from '@wordpress/i18n'; import { removeFormat, slice, isCollapsed } from '@wordpress/rich-text'; import { RichTextToolbarButton } from '@wordpress/block-editor'; import { help } from '@wordpress/icons'; const name = 'core/unknown'; const title = __( 'Clear Unknown Formatting' ); function selectionContainsUnknownFormats( value ) { if ( isCollapsed( value ) ) { return false; } const selectedValue = slice( value ); return selectedValue.formats.some( ( formats ) => { return formats.some( ( format ) => format.type === name ); } ); } export const unknown = { name, title, tagName: '*', className: null, edit( { isActive, value, onChange, onFocus } ) { if ( ! isActive && ! selectionContainsUnknownFormats( value ) ) { return null; } function onClick() { onChange( removeFormat( value, name ) ); onFocus(); } return ( <RichTextToolbarButton name="unknown" icon={ help } title={ title } onClick={ onClick } isActive /> ); }, };