Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
dom.getRectangleFromRange(range);
// $ExpectType Element | undefined
dom.getScrollContainer(element);
// $ExpectType void
dom.insertAfter(node, node);
// $ExpectType boolean
dom.isEntirelySelected(element);
// $ExpectType boolean
dom.isHorizontalEdge(element, true);
// $ExpectType boolean
dom.isTextField(element);
// $ExpectType boolean
dom.isVerticalEdge(element, false);
// $ExpectType void
dom.placeCaretAtHorizontalEdge(element, true);
// $ExpectType void
dom.placeCaretAtHorizontalEdge(undefined, false);
// $ExpectType void
dom.placeCaretAtVerticalEdge(element, true);
// $ExpectType void
dom.placeCaretAtVerticalEdge(undefined, false);
function isTabCandidate( node, i, array ) {
// Not a candidate if the node is not tabbable.
if ( ! focus.tabbable.isTabbableIndex( node ) ) {
return false;
}
// Prefer text fields...
if ( isTextField( node ) ) {
return true;
}
// ...but settle for block focus stop.
if ( ! isBlockFocusStop( node ) ) {
return false;
}
// If element contains inner blocks, stop immediately at its focus
// wrapper.
if ( hasInnerBlocksContext( node ) ) {
return true;
}
// If navigating out of a block (in reverse), don't consider its
// block focus stop.
startTypingInTextField( event ) {
const { isTyping, onStartTyping } = this.props;
const { type, target } = event;
// Abort early if already typing, or key press is incurred outside a
// text field (e.g. arrow-ing through toolbar buttons).
// Ignore typing in a block toolbar
if ( isTyping || ! isTextField( target ) || target.closest( '.block-editor-block-toolbar' ) ) {
return;
}
// Special-case keydown because certain keys do not emit a keypress
// event. Conversely avoid keydown as the canonical event since there
// are many keydown which are explicitly not targeted for typing.
if ( type === 'keydown' && ! isKeyDownEligibleForStartTyping( event ) ) {
return;
}
onStartTyping();
}
startTypingInTextField( event ) {
const { isTyping, onStartTyping } = this.props;
const { type, target } = event;
// Abort early if already typing, or key press is incurred outside a
// text field (e.g. arrow-ing through toolbar buttons).
// Ignore typing in a block toolbar
if ( isTyping || ! isTextField( target ) || target.closest( '.editor-block-toolbar' ) ) {
return;
}
// Special-case keydown because certain keys do not emit a keypress
// event. Conversely avoid keydown as the canonical event since there
// are many keydown which are explicitly not targeted for typing.
if ( type === 'keydown' && ! isKeyDownEligibleForStartTyping( event ) ) {
return;
}
onStartTyping();
}
const handleKeyDown = ( event ) => {
if ( ! selectedCell ) {
return;
}
const { keyCode, target } = event;
//
if ( ! isTextField( target ) ) {
return;
}
const isUp = keyCode === UP;
const isDown = keyCode === DOWN;
const isLeft = keyCode === LEFT;
const isRight = keyCode === RIGHT;
const isHome = keyCode === HOME;
const isEnd = keyCode === END;
const isHorizontal = isLeft || isRight || isHome || isEnd;
const isVertical = isUp || isDown;
const isNav = isHorizontal || isVertical;
// The user hasn't pressed a navigation key, abort early.
if ( ! isNav ) {
return;
this.props.setTimeout( () => {
const { isTyping, onStopTyping } = this.props;
const { target } = event;
if ( isTyping && ! isTextField( target ) ) {
onStopTyping();
}
} );
}
this.props.setTimeout( () => {
const { isTyping, onStopTyping } = this.props;
const { target } = event;
if ( isTyping && ! isTextField( target ) ) {
onStopTyping();
}
} );
}