@wordpress/dom
Advanced tools
Comparing version 2.7.0 to 2.8.0
@@ -10,2 +10,3 @@ /** | ||
var _window = window, | ||
DOMParser = _window.DOMParser, | ||
getComputedStyle = _window.getComputedStyle; | ||
@@ -95,3 +96,4 @@ var _window$Node = window.Node, | ||
var range = selection.getRangeAt(0).cloneRange(); | ||
var originalRange = selection.getRangeAt(0); | ||
var range = originalRange.cloneRange(); | ||
var isForward = isSelectionForward(selection); | ||
@@ -125,3 +127,4 @@ var isCollapsed = selection.isCollapsed; // Collapse in direction of selection. | ||
var containerRect = container.getBoundingClientRect(); | ||
var verticalEdge = isReverse ? containerRect.top + padding > rangeRect.top - buffer : containerRect.bottom - padding < rangeRect.bottom + buffer; | ||
var originalRangeRect = getRectangleFromRange(originalRange); | ||
var verticalEdge = isReverse ? containerRect.top + padding > originalRangeRect.top - buffer : containerRect.bottom - padding < originalRangeRect.bottom + buffer; | ||
@@ -632,2 +635,14 @@ if (!verticalEdge) { | ||
} | ||
/** | ||
* Removes any HTML tags from the provided string. | ||
* | ||
* @param {string} html The string containing html. | ||
* | ||
* @return {string} The text content with any html removed. | ||
*/ | ||
export function __unstableStripHTML(html) { | ||
var document = new DOMParser().parseFromString(html, 'text/html'); | ||
return document.body.textContent || ''; | ||
} | ||
//# sourceMappingURL=dom.js.map |
@@ -23,2 +23,3 @@ "use strict"; | ||
exports.wrap = wrap; | ||
exports.__unstableStripHTML = __unstableStripHTML; | ||
@@ -35,2 +36,3 @@ var _lodash = require("lodash"); | ||
var _window = window, | ||
DOMParser = _window.DOMParser, | ||
getComputedStyle = _window.getComputedStyle; | ||
@@ -120,3 +122,4 @@ var _window$Node = window.Node, | ||
var range = selection.getRangeAt(0).cloneRange(); | ||
var originalRange = selection.getRangeAt(0); | ||
var range = originalRange.cloneRange(); | ||
var isForward = isSelectionForward(selection); | ||
@@ -150,3 +153,4 @@ var isCollapsed = selection.isCollapsed; // Collapse in direction of selection. | ||
var containerRect = container.getBoundingClientRect(); | ||
var verticalEdge = isReverse ? containerRect.top + padding > rangeRect.top - buffer : containerRect.bottom - padding < rangeRect.bottom + buffer; | ||
var originalRangeRect = getRectangleFromRange(originalRange); | ||
var verticalEdge = isReverse ? containerRect.top + padding > originalRangeRect.top - buffer : containerRect.bottom - padding < originalRangeRect.bottom + buffer; | ||
@@ -673,2 +677,15 @@ if (!verticalEdge) { | ||
} | ||
/** | ||
* Removes any HTML tags from the provided string. | ||
* | ||
* @param {string} html The string containing html. | ||
* | ||
* @return {string} The text content with any html removed. | ||
*/ | ||
function __unstableStripHTML(html) { | ||
var document = new DOMParser().parseFromString(html, 'text/html'); | ||
return document.body.textContent || ''; | ||
} | ||
//# sourceMappingURL=dom.js.map |
{ | ||
"name": "@wordpress/dom", | ||
"version": "2.7.0", | ||
"version": "2.8.0", | ||
"description": "DOM utilities module for WordPress.", | ||
@@ -26,3 +26,3 @@ "author": "The WordPress Contributors", | ||
"dependencies": { | ||
"@babel/runtime": "^7.4.4", | ||
"@babel/runtime": "^7.8.3", | ||
"lodash": "^4.17.15" | ||
@@ -33,3 +33,3 @@ }, | ||
}, | ||
"gitHead": "3e867dd7c6560e4b2cb9a59cc02856e055be6142" | ||
"gitHead": "41fc84af285da696c65c235331ee245dfe23971d" | ||
} |
@@ -10,3 +10,3 @@ /** | ||
const { getComputedStyle } = window; | ||
const { DOMParser, getComputedStyle } = window; | ||
const { | ||
@@ -30,8 +30,3 @@ TEXT_NODE, | ||
function isSelectionForward( selection ) { | ||
const { | ||
anchorNode, | ||
focusNode, | ||
anchorOffset, | ||
focusOffset, | ||
} = selection; | ||
const { anchorNode, focusNode, anchorOffset, focusOffset } = selection; | ||
@@ -98,3 +93,4 @@ const position = anchorNode.compareDocumentPosition( focusNode ); | ||
const range = selection.getRangeAt( 0 ).cloneRange(); | ||
const originalRange = selection.getRangeAt( 0 ); | ||
const range = originalRange.cloneRange(); | ||
const isForward = isSelectionForward( selection ); | ||
@@ -127,5 +123,7 @@ const isCollapsed = selection.isCollapsed; | ||
const padding = parseInt( computedStyle[ | ||
`padding${ isReverse ? 'Top' : 'Bottom' }` | ||
], 10 ) || 0; | ||
const padding = | ||
parseInt( | ||
computedStyle[ `padding${ isReverse ? 'Top' : 'Bottom' }` ], | ||
10 | ||
) || 0; | ||
@@ -136,7 +134,8 @@ // Calculate a buffer that is half the line height. In some browsers, the | ||
// over its line boundary. | ||
const buffer = 3 * parseInt( lineHeight, 10 ) / 4; | ||
const buffer = ( 3 * parseInt( lineHeight, 10 ) ) / 4; | ||
const containerRect = container.getBoundingClientRect(); | ||
const verticalEdge = isReverse ? | ||
containerRect.top + padding > rangeRect.top - buffer : | ||
containerRect.bottom - padding < rangeRect.bottom + buffer; | ||
const originalRangeRect = getRectangleFromRange( originalRange ); | ||
const verticalEdge = isReverse | ||
? containerRect.top + padding > originalRangeRect.top - buffer | ||
: containerRect.bottom - padding < originalRangeRect.bottom + buffer; | ||
@@ -153,3 +152,3 @@ if ( ! verticalEdge ) { | ||
const { direction } = computedStyle; | ||
const isReverseDir = direction === 'rtl' ? ( ! isReverse ) : isReverse; | ||
const isReverseDir = direction === 'rtl' ? ! isReverse : isReverse; | ||
@@ -162,3 +161,5 @@ // To calculate the horizontal position, we insert a test range and see if | ||
const x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1; | ||
const y = isReverse ? containerRect.top + buffer : containerRect.bottom - buffer; | ||
const y = isReverse | ||
? containerRect.top + buffer | ||
: containerRect.bottom - buffer; | ||
const testRange = hiddenCaretRangeFromPoint( document, x, y, container ); | ||
@@ -221,3 +222,5 @@ | ||
const { parentNode } = startContainer; | ||
const index = Array.from( parentNode.childNodes ).indexOf( startContainer ); | ||
const index = Array.from( parentNode.childNodes ).indexOf( | ||
startContainer | ||
); | ||
@@ -387,3 +390,8 @@ range = document.createRange(); | ||
*/ | ||
export function placeCaretAtVerticalEdge( container, isReverse, rect, mayUseScroll = true ) { | ||
export function placeCaretAtVerticalEdge( | ||
container, | ||
isReverse, | ||
rect, | ||
mayUseScroll = true | ||
) { | ||
if ( ! container ) { | ||
@@ -407,3 +415,5 @@ return; | ||
const x = rect.left; | ||
const y = isReverse ? ( editableRect.bottom - buffer ) : ( editableRect.top + buffer ); | ||
const y = isReverse | ||
? editableRect.bottom - buffer | ||
: editableRect.top + buffer; | ||
@@ -413,5 +423,8 @@ const range = hiddenCaretRangeFromPoint( document, x, y, container ); | ||
if ( ! range || ! container.contains( range.startContainer ) ) { | ||
if ( mayUseScroll && ( | ||
( ! range || ! range.startContainer ) || | ||
! range.startContainer.contains( container ) ) ) { | ||
if ( | ||
mayUseScroll && | ||
( ! range || | ||
! range.startContainer || | ||
! range.startContainer.contains( container ) ) | ||
) { | ||
// Might be out of view. | ||
@@ -454,3 +467,3 @@ // Easier than attempting to calculate manually. | ||
( nodeName === 'INPUT' && selectionStart !== null ) || | ||
( nodeName === 'TEXTAREA' ) || | ||
nodeName === 'TEXTAREA' || | ||
contentEditable === 'true' | ||
@@ -498,3 +511,6 @@ ); | ||
if ( includes( [ 'INPUT', 'TEXTAREA' ], element.nodeName ) ) { | ||
return element.selectionStart === 0 && element.value.length === element.selectionEnd; | ||
return ( | ||
element.selectionStart === 0 && | ||
element.value.length === element.selectionEnd | ||
); | ||
} | ||
@@ -525,5 +541,6 @@ | ||
const lastChild = element.lastChild; | ||
const lastChildContentLength = lastChild.nodeType === TEXT_NODE ? | ||
lastChild.data.length : | ||
lastChild.childNodes.length; | ||
const lastChildContentLength = | ||
lastChild.nodeType === TEXT_NODE | ||
? lastChild.data.length | ||
: lastChild.childNodes.length; | ||
@@ -678,1 +695,13 @@ return ( | ||
} | ||
/** | ||
* Removes any HTML tags from the provided string. | ||
* | ||
* @param {string} html The string containing html. | ||
* | ||
* @return {string} The text content with any html removed. | ||
*/ | ||
export function __unstableStripHTML( html ) { | ||
const document = new DOMParser().parseFromString( html, 'text/html' ); | ||
return document.body.textContent || ''; | ||
} |
/** | ||
* Internal dependencies | ||
*/ | ||
import { isHorizontalEdge, placeCaretAtHorizontalEdge, isTextField } from '../dom'; | ||
import { | ||
isHorizontalEdge, | ||
placeCaretAtHorizontalEdge, | ||
isTextField, | ||
__unstableStripHTML as stripHTML, | ||
} from '../dom'; | ||
@@ -115,8 +120,3 @@ describe( 'DOM', () => { | ||
*/ | ||
const TEXT_INPUT_TYPES = [ | ||
'text', | ||
'password', | ||
'search', | ||
'url', | ||
]; | ||
const TEXT_INPUT_TYPES = [ 'text', 'password', 'search', 'url' ]; | ||
@@ -142,3 +142,5 @@ it( 'should return false for non-text input elements', () => { | ||
it( 'should return true for an textarea element', () => { | ||
expect( isTextField( document.createElement( 'textarea' ) ) ).toBe( true ); | ||
expect( isTextField( document.createElement( 'textarea' ) ) ).toBe( | ||
true | ||
); | ||
} ); | ||
@@ -155,5 +157,21 @@ | ||
it( 'should return true for a normal div element', () => { | ||
expect( isTextField( document.createElement( 'div' ) ) ).toBe( false ); | ||
expect( isTextField( document.createElement( 'div' ) ) ).toBe( | ||
false | ||
); | ||
} ); | ||
} ); | ||
describe( 'stripHTML', () => { | ||
it( 'removes any HTML from a text string', () => { | ||
expect( stripHTML( 'This is <em>emphasized</em>' ) ).toBe( | ||
'This is emphasized' | ||
); | ||
} ); | ||
it( 'removes script tags, but does not execute them', () => { | ||
const html = 'This will not <script>throw "Error"</script>'; | ||
expect( stripHTML( html ) ).toBe( 'This will not throw "Error"' ); | ||
expect( () => stripHTML( html ) ).not.toThrow(); | ||
} ); | ||
} ); | ||
} ); |
@@ -29,7 +29,3 @@ /** | ||
expect( tabbables ).toEqual( [ | ||
first, | ||
second, | ||
third, | ||
] ); | ||
expect( tabbables ).toEqual( [ first, second, third ] ); | ||
} ); | ||
@@ -71,7 +67,3 @@ | ||
expect( tabbables ).toEqual( [ | ||
firstRadio, | ||
text, | ||
fourthRadio, | ||
] ); | ||
expect( tabbables ).toEqual( [ firstRadio, text, fourthRadio ] ); | ||
} ); | ||
@@ -104,6 +96,3 @@ | ||
expect( tabbables ).toEqual( [ | ||
text, | ||
thirdRadio, | ||
] ); | ||
expect( tabbables ).toEqual( [ text, thirdRadio ] ); | ||
} ); | ||
@@ -128,9 +117,5 @@ | ||
expect( tabbables ).toEqual( [ | ||
firstRadio, | ||
text, | ||
secondRadio, | ||
] ); | ||
expect( tabbables ).toEqual( [ firstRadio, text, secondRadio ] ); | ||
} ); | ||
} ); | ||
} ); |
@@ -12,17 +12,21 @@ /** | ||
const ifNotHidden = ( value, elseValue ) => function() { | ||
let isHidden = false; | ||
let node = this; | ||
do { | ||
isHidden = ( | ||
node.style.display === 'none' || | ||
node.style.visibility === 'hidden' | ||
const ifNotHidden = ( value, elseValue ) => | ||
function() { | ||
let isHidden = false; | ||
let node = this; | ||
do { | ||
isHidden = | ||
node.style.display === 'none' || | ||
node.style.visibility === 'hidden'; | ||
node = node.parentNode; | ||
} while ( | ||
! isHidden && | ||
node && | ||
node.nodeType === window.Node.ELEMENT_NODE | ||
); | ||
node = node.parentNode; | ||
} while ( ! isHidden && node && node.nodeType === window.Node.ELEMENT_NODE ); | ||
return isHidden ? elseValue : value; | ||
}; | ||
return isHidden ? elseValue : value; | ||
}; | ||
Object.defineProperties( element, { | ||
@@ -37,12 +41,17 @@ offsetHeight: { | ||
element.getClientRects = ifNotHidden( [ { | ||
width: 10, | ||
height: 10, | ||
top: 0, | ||
right: 10, | ||
bottom: 10, | ||
left: 0, | ||
} ], [] ); | ||
element.getClientRects = ifNotHidden( | ||
[ | ||
{ | ||
width: 10, | ||
height: 10, | ||
top: 0, | ||
right: 10, | ||
bottom: 10, | ||
left: 0, | ||
}, | ||
], | ||
[] | ||
); | ||
return element; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
223907
2871
4
Updated@babel/runtime@^7.8.3