-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from DLXPlugins/feature/mobile-selection-safari
Fix mobile rendering on Safari and Add WP Fonts to Block
- Loading branch information
Showing
10 changed files
with
178 additions
and
23 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 |
---|---|---|
@@ -1 +1 @@ | ||
<?php return array('dependencies' => array('react', 'wp-a11y', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '218cc8ffaf44f794c30a'); | ||
<?php return array('dependencies' => array('react', 'wp-a11y', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '3e1eb88b9d5efb8f9137'); |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
export function getOffsetScroll(_window) { | ||
const body = _window.document.body; | ||
const scrollReference = _window.getComputedStyle(body).position === "static" ? body.parentNode : body; | ||
return scrollReference.getBoundingClientRect(); | ||
} | ||
|
||
let matchFunc; | ||
export function matches(element, selector) { | ||
if (!matchFunc) matchFunc = getMatchFunctionName(element); | ||
return element[matchFunc](selector); | ||
} | ||
|
||
export function closest(element, selector) { | ||
let target = element; | ||
while (target && (target.nodeType !== 1 /* === Node.ELEMENT_NODE */ || !matches(target, selector))) { | ||
target = target.parentNode; | ||
} | ||
|
||
return target; | ||
} | ||
|
||
// `contains` in IE doesn't work with text nodes | ||
export function contains(ancestor, target) { | ||
const comparedPositions = ancestor.compareDocumentPosition(target); | ||
// eslint-disable-next-line no-bitwise | ||
return !comparedPositions || (comparedPositions & 16 /* === Node.DOCUMENT_POSITION_CONTAINED_BY */) > 0; | ||
} | ||
|
||
// eslint-disable-next-line consistent-return | ||
function getMatchFunctionName(element) { | ||
const suffix = "atchesSelector"; | ||
for (const name of [ "matches", `m${suffix}`, `webkitM${suffix}`, `mozM${suffix}`, `msM${suffix}`, `oM${suffix}` ]) { | ||
if (element[name]) return name; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { closest, contains } from './dom.js'; | ||
|
||
export function isSelectionForward( selection ) { | ||
if ( selection.isCollapsed ) { | ||
return true; | ||
} | ||
|
||
const comparedPositions = selection.anchorNode.compareDocumentPosition( selection.focusNode ); | ||
if ( ! comparedPositions ) { | ||
// It's the same node | ||
return selection.anchorOffset < selection.focusOffset; | ||
} | ||
|
||
// eslint-disable-next-line no-bitwise | ||
return ( comparedPositions & 4 /* === Node.DOCUMENT_POSITION_FOLLOWING */ ) > 0; | ||
} | ||
|
||
export function getEndLineRect( range, isForward ) { | ||
let endLineRects; | ||
const rangeRects = range.getClientRects(); | ||
const sliceRects = [].slice.bind( rangeRects ); | ||
|
||
if ( isForward ) { | ||
let lastLeft = Infinity; | ||
let i = rangeRects.length; | ||
while ( i-- ) { | ||
const rect = rangeRects[ i ]; | ||
if ( rect.left > lastLeft ) { | ||
break; | ||
} | ||
lastLeft = rect.left; | ||
} | ||
endLineRects = sliceRects( i + 1 ); | ||
} else { | ||
let lastRight = -Infinity; | ||
let i = 0; | ||
for ( ; i < rangeRects.length; i++ ) { | ||
const rect = rangeRects[ i ]; | ||
if ( rect.right < lastRight ) { | ||
break; | ||
} | ||
lastRight = rect.right; | ||
} | ||
endLineRects = sliceRects( 0, i ); | ||
} | ||
|
||
return { | ||
top: Math.min( ...endLineRects.map( ( rect ) => rect.top ) ), | ||
bottom: Math.max( ...endLineRects.map( ( rect ) => rect.bottom ) ), | ||
left: endLineRects[ 0 ].left, | ||
right: endLineRects[ endLineRects.length - 1 ].right, | ||
}; | ||
} | ||
|
||
export function constrainRange( range, selector ) { | ||
const constrainedRange = range.cloneRange(); | ||
if ( range.collapsed || ! selector ) { | ||
return constrainedRange; | ||
} | ||
|
||
let ancestor = closest( range.startContainer, selector ); | ||
if ( ancestor ) { | ||
if ( ! contains( ancestor, range.endContainer ) ) { | ||
constrainedRange.setEnd( ancestor, ancestor.childNodes.length ); | ||
} | ||
} else { | ||
ancestor = closest( range.endContainer, selector ); | ||
if ( ancestor ) { | ||
constrainedRange.setStart( ancestor, 0 ); | ||
} else { | ||
constrainedRange.collapse(); | ||
} | ||
} | ||
|
||
return constrainedRange; | ||
} |
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