2018-12-13 23:41:57 -05:00
this [ "wp" ] = this [ "wp" ] || { } ; this [ "wp" ] [ "dom" ] =
/******/ ( function ( modules ) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = { } ;
/******/
/******/ // The require function
/******/ function _ _webpack _require _ _ ( moduleId ) {
/******/
/******/ // Check if module is in cache
/******/ if ( installedModules [ moduleId ] ) {
/******/ return installedModules [ moduleId ] . exports ;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules [ moduleId ] = {
/******/ i : moduleId ,
/******/ l : false ,
/******/ exports : { }
/******/ } ;
/******/
/******/ // Execute the module function
/******/ modules [ moduleId ] . call ( module . exports , module , module . exports , _ _webpack _require _ _ ) ;
/******/
/******/ // Flag the module as loaded
/******/ module . l = true ;
/******/
/******/ // Return the exports of the module
/******/ return module . exports ;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ _ _webpack _require _ _ . m = modules ;
/******/
/******/ // expose the module cache
/******/ _ _webpack _require _ _ . c = installedModules ;
/******/
/******/ // define getter function for harmony exports
/******/ _ _webpack _require _ _ . d = function ( exports , name , getter ) {
/******/ if ( ! _ _webpack _require _ _ . o ( exports , name ) ) {
/******/ Object . defineProperty ( exports , name , { enumerable : true , get : getter } ) ;
/******/ }
/******/ } ;
/******/
/******/ // define __esModule on exports
/******/ _ _webpack _require _ _ . r = function ( exports ) {
/******/ if ( typeof Symbol !== 'undefined' && Symbol . toStringTag ) {
/******/ Object . defineProperty ( exports , Symbol . toStringTag , { value : 'Module' } ) ;
/******/ }
/******/ Object . defineProperty ( exports , '__esModule' , { value : true } ) ;
/******/ } ;
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ _ _webpack _require _ _ . t = function ( value , mode ) {
/******/ if ( mode & 1 ) value = _ _webpack _require _ _ ( value ) ;
/******/ if ( mode & 8 ) return value ;
/******/ if ( ( mode & 4 ) && typeof value === 'object' && value && value . _ _esModule ) return value ;
/******/ var ns = Object . create ( null ) ;
/******/ _ _webpack _require _ _ . r ( ns ) ;
/******/ Object . defineProperty ( ns , 'default' , { enumerable : true , value : value } ) ;
/******/ if ( mode & 2 && typeof value != 'string' ) for ( var key in value ) _ _webpack _require _ _ . d ( ns , key , function ( key ) { return value [ key ] ; } . bind ( null , key ) ) ;
/******/ return ns ;
/******/ } ;
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ _ _webpack _require _ _ . n = function ( module ) {
/******/ var getter = module && module . _ _esModule ?
/******/ function getDefault ( ) { return module [ 'default' ] ; } :
/******/ function getModuleExports ( ) { return module ; } ;
/******/ _ _webpack _require _ _ . d ( getter , 'a' , getter ) ;
/******/ return getter ;
/******/ } ;
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ _ _webpack _require _ _ . o = function ( object , property ) { return Object . prototype . hasOwnProperty . call ( object , property ) ; } ;
/******/
/******/ // __webpack_public_path__
/******/ _ _webpack _require _ _ . p = "" ;
/******/
/******/
/******/ // Load entry module and return exports
2021-02-24 10:57:54 -05:00
/******/ return _ _webpack _require _ _ ( _ _webpack _require _ _ . s = 460 ) ;
2018-12-13 23:41:57 -05:00
/******/ } )
/************************************************************************/
/******/ ( {
2021-01-27 21:04:13 -05:00
/***/ 15 :
/***/ ( function ( module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) {
"use strict" ;
// EXPORTS
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "a" , function ( ) { return /* binding */ _toConsumableArray ; } ) ;
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.js
var arrayLikeToArray = _ _webpack _require _ _ ( 24 ) ;
// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js
function _arrayWithoutHoles ( arr ) {
if ( Array . isArray ( arr ) ) return Object ( arrayLikeToArray [ "a" /* default */ ] ) ( arr ) ;
}
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/iterableToArray.js
var iterableToArray = _ _webpack _require _ _ ( 37 ) ;
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js
2021-02-02 00:17:13 -05:00
var unsupportedIterableToArray = _ _webpack _require _ _ ( 31 ) ;
2021-01-27 21:04:13 -05:00
// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/nonIterableSpread.js
function _nonIterableSpread ( ) {
throw new TypeError ( "Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method." ) ;
}
// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js
function _toConsumableArray ( arr ) {
return _arrayWithoutHoles ( arr ) || Object ( iterableToArray [ "a" /* default */ ] ) ( arr ) || Object ( unsupportedIterableToArray [ "a" /* default */ ] ) ( arr ) || _nonIterableSpread ( ) ;
}
/***/ } ) ,
2018-12-17 22:14:52 -05:00
/***/ 2 :
/***/ ( function ( module , exports ) {
2021-01-27 21:04:13 -05:00
( function ( ) { module . exports = window [ "lodash" ] ; } ( ) ) ;
/***/ } ) ,
/***/ 24 :
/***/ ( function ( module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) {
"use strict" ;
/* harmony export (binding) */ _ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "a" , function ( ) { return _arrayLikeToArray ; } ) ;
function _arrayLikeToArray ( arr , len ) {
if ( len == null || len > arr . length ) len = arr . length ;
for ( var i = 0 , arr2 = new Array ( len ) ; i < len ; i ++ ) {
arr2 [ i ] = arr [ i ] ;
}
return arr2 ;
}
/***/ } ) ,
2021-02-02 00:17:13 -05:00
/***/ 31 :
2021-01-27 21:04:13 -05:00
/***/ ( function ( module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) {
"use strict" ;
/* harmony export (binding) */ _ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "a" , function ( ) { return _unsupportedIterableToArray ; } ) ;
/* harmony import */ var _babel _runtime _helpers _esm _arrayLikeToArray _ _WEBPACK _IMPORTED _MODULE _0 _ _ = _ _webpack _require _ _ ( 24 ) ;
function _unsupportedIterableToArray ( o , minLen ) {
if ( ! o ) return ;
if ( typeof o === "string" ) return Object ( _babel _runtime _helpers _esm _arrayLikeToArray _ _WEBPACK _IMPORTED _MODULE _0 _ _ [ /* default */ "a" ] ) ( o , minLen ) ;
var n = Object . prototype . toString . call ( o ) . slice ( 8 , - 1 ) ;
if ( n === "Object" && o . constructor ) n = o . constructor . name ;
if ( n === "Map" || n === "Set" ) return Array . from ( o ) ;
if ( n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/ . test ( n ) ) return Object ( _babel _runtime _helpers _esm _arrayLikeToArray _ _WEBPACK _IMPORTED _MODULE _0 _ _ [ /* default */ "a" ] ) ( o , minLen ) ;
}
/***/ } ) ,
/***/ 37 :
/***/ ( function ( module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) {
"use strict" ;
/* harmony export (binding) */ _ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "a" , function ( ) { return _iterableToArray ; } ) ;
function _iterableToArray ( iter ) {
if ( typeof Symbol !== "undefined" && Symbol . iterator in Object ( iter ) ) return Array . from ( iter ) ;
}
2018-12-13 23:41:57 -05:00
/***/ } ) ,
2021-02-24 10:57:54 -05:00
/***/ 460 :
2018-12-13 23:41:57 -05:00
/***/ ( function ( module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) {
"use strict" ;
2020-06-29 07:50:29 -04:00
// ESM COMPAT FLAG
2018-12-13 23:41:57 -05:00
_ _webpack _require _ _ . r ( _ _webpack _exports _ _ ) ;
2020-06-29 07:50:29 -04:00
// EXPORTS
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "focus" , function ( ) { return /* binding */ build _module _focus ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "isHorizontalEdge" , function ( ) { return /* reexport */ isHorizontalEdge ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "isVerticalEdge" , function ( ) { return /* reexport */ isVerticalEdge ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "getRectangleFromRange" , function ( ) { return /* reexport */ getRectangleFromRange ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "computeCaretRect" , function ( ) { return /* reexport */ computeCaretRect ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "placeCaretAtHorizontalEdge" , function ( ) { return /* reexport */ placeCaretAtHorizontalEdge ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "placeCaretAtVerticalEdge" , function ( ) { return /* reexport */ placeCaretAtVerticalEdge ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "isTextField" , function ( ) { return /* reexport */ isTextField ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "isNumberInput" , function ( ) { return /* reexport */ isNumberInput ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "documentHasTextSelection" , function ( ) { return /* reexport */ documentHasTextSelection ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "documentHasUncollapsedSelection" , function ( ) { return /* reexport */ documentHasUncollapsedSelection ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "documentHasSelection" , function ( ) { return /* reexport */ documentHasSelection ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "isEntirelySelected" , function ( ) { return /* reexport */ isEntirelySelected ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "getScrollContainer" , function ( ) { return /* reexport */ getScrollContainer ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "getOffsetParent" , function ( ) { return /* reexport */ getOffsetParent ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "replace" , function ( ) { return /* reexport */ replace ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "remove" , function ( ) { return /* reexport */ remove ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "insertAfter" , function ( ) { return /* reexport */ insertAfter ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "unwrap" , function ( ) { return /* reexport */ unwrap ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "replaceTag" , function ( ) { return /* reexport */ replaceTag ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "wrap" , function ( ) { return /* reexport */ wrap ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "__unstableStripHTML" , function ( ) { return /* reexport */ _ _unstableStripHTML ; } ) ;
2020-10-13 09:10:30 -04:00
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "isEmpty" , function ( ) { return /* reexport */ isEmpty ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "removeInvalidHTML" , function ( ) { return /* reexport */ removeInvalidHTML ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "getPhrasingContentSchema" , function ( ) { return /* reexport */ getPhrasingContentSchema ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "isPhrasingContent" , function ( ) { return /* reexport */ isPhrasingContent ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "isTextContent" , function ( ) { return /* reexport */ isTextContent ; } ) ;
2021-01-27 21:04:13 -05:00
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "getFilesFromDataTransfer" , function ( ) { return /* reexport */ getFilesFromDataTransfer ; } ) ;
2020-06-29 07:50:29 -04:00
// NAMESPACE OBJECT: ./node_modules/@wordpress/dom/build-module/focusable.js
2018-12-17 22:14:52 -05:00
var focusable _namespaceObject = { } ;
_ _webpack _require _ _ . r ( focusable _namespaceObject ) ;
_ _webpack _require _ _ . d ( focusable _namespaceObject , "find" , function ( ) { return find ; } ) ;
2020-06-29 07:50:29 -04:00
// NAMESPACE OBJECT: ./node_modules/@wordpress/dom/build-module/tabbable.js
2018-12-17 22:14:52 -05:00
var tabbable _namespaceObject = { } ;
_ _webpack _require _ _ . r ( tabbable _namespaceObject ) ;
_ _webpack _require _ _ . d ( tabbable _namespaceObject , "isTabbableIndex" , function ( ) { return isTabbableIndex ; } ) ;
_ _webpack _require _ _ . d ( tabbable _namespaceObject , "find" , function ( ) { return tabbable _find ; } ) ;
2020-01-22 17:06:21 -05:00
_ _webpack _require _ _ . d ( tabbable _namespaceObject , "findPrevious" , function ( ) { return findPrevious ; } ) ;
_ _webpack _require _ _ . d ( tabbable _namespaceObject , "findNext" , function ( ) { return findNext ; } ) ;
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/focusable.js
/ * *
* References :
*
* Focusable :
* - https : //www.w3.org/TR/html5/editing.html#focus-management
*
* Sequential focus navigation :
* - https : //www.w3.org/TR/html5/editing.html#sequential-focus-navigation-and-the-tabindex-attribute
*
* Disabled elements :
* - https : //www.w3.org/TR/html5/disabled-elements.html#disabled-elements
*
* getClientRects algorithm ( requiring layout box ) :
* - https : //www.w3.org/TR/cssom-view-1/#extension-to-the-element-interface
*
* AREA elements associated with an IMG :
* - https : //w3c.github.io/html/editing.html#data-model
* /
var SELECTOR = [ '[tabindex]' , 'a[href]' , 'button:not([disabled])' , 'input:not([type="hidden"]):not([disabled])' , 'select:not([disabled])' , 'textarea:not([disabled])' , 'iframe' , 'object' , 'embed' , 'area[href]' , '[contenteditable]:not([contenteditable=false])' ] . join ( ',' ) ;
/ * *
* Returns true if the specified element is visible ( i . e . neither display : none
* nor visibility : hidden ) .
*
* @ param { Element } element DOM element to test .
*
* @ return { boolean } Whether element is visible .
* /
function isVisible ( element ) {
return element . offsetWidth > 0 || element . offsetHeight > 0 || element . getClientRects ( ) . length > 0 ;
2018-12-13 23:41:57 -05:00
}
2020-07-07 10:43:35 -04:00
/ * *
* Returns true if the specified element should be skipped from focusable elements .
* For now it rather specific for ` iframes ` and if tabindex attribute is set to - 1.
*
* @ param { Element } element DOM element to test .
*
* @ return { boolean } Whether element should be skipped from focusable elements .
* /
function skipFocus ( element ) {
return element . nodeName . toLowerCase ( ) === 'iframe' && element . getAttribute ( 'tabindex' ) === '-1' ;
}
2018-12-17 22:14:52 -05:00
/ * *
* Returns true if the specified area element is a valid focusable element , or
* false otherwise . Area is only focusable if within a map where a named map
* referenced by an image somewhere in the document .
*
* @ param { Element } element DOM area element to test .
*
* @ return { boolean } Whether area element is valid for focus .
* /
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
function isValidFocusableArea ( element ) {
var map = element . closest ( 'map[name]' ) ;
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
if ( ! map ) {
return false ;
}
2020-10-13 09:10:30 -04:00
var img = element . ownerDocument . querySelector ( 'img[usemap="#' + map . name + '"]' ) ;
2018-12-17 22:14:52 -05:00
return ! ! img && isVisible ( img ) ;
}
/ * *
* Returns all focusable elements within a given context .
*
* @ param { Element } context Element in which to search .
*
* @ return { Element [ ] } Focusable elements .
* /
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
function find ( context ) {
var elements = context . querySelectorAll ( SELECTOR ) ;
2020-01-08 06:57:23 -05:00
return Array . from ( elements ) . filter ( function ( element ) {
2020-07-07 10:43:35 -04:00
if ( ! isVisible ( element ) || skipFocus ( element ) ) {
2018-12-17 22:14:52 -05:00
return false ;
}
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
var nodeName = element . nodeName ;
if ( 'AREA' === nodeName ) {
return isValidFocusableArea ( element ) ;
}
return true ;
} ) ;
2018-12-13 23:41:57 -05:00
}
2021-01-27 21:04:13 -05:00
// EXTERNAL MODULE: external "lodash"
var external _lodash _ = _ _webpack _require _ _ ( 2 ) ;
2019-03-21 08:48:00 -04:00
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/tabbable.js
2019-03-21 08:48:00 -04:00
/ * *
* External dependencies
* /
2018-12-17 22:14:52 -05:00
/ * *
* Internal dependencies
* /
2018-12-13 23:41:57 -05:00
2019-03-21 08:48:00 -04:00
2018-12-17 22:14:52 -05:00
/ * *
* Returns the tab index of the given element . In contrast with the tabIndex
* property , this normalizes the default ( 0 ) to avoid browser inconsistencies ,
* operating under the assumption that this function is only ever called with a
* focusable node .
*
* @ see https : //bugzilla.mozilla.org/show_bug.cgi?id=1190261
*
* @ param { Element } element Element from which to retrieve .
*
* @ return { ? number } Tab index of element ( default 0 ) .
* /
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
function getTabIndex ( element ) {
var tabIndex = element . getAttribute ( 'tabindex' ) ;
return tabIndex === null ? 0 : parseInt ( tabIndex , 10 ) ;
}
/ * *
* Returns true if the specified element is tabbable , or false otherwise .
*
* @ param { Element } element Element to test .
*
* @ return { boolean } Whether element is tabbable .
* /
function isTabbableIndex ( element ) {
return getTabIndex ( element ) !== - 1 ;
}
2019-03-21 08:48:00 -04:00
/ * *
* Returns a stateful reducer function which constructs a filtered array of
* tabbable elements , where at most one radio input is selected for a given
* name , giving priority to checked input , falling back to the first
* encountered .
*
* @ return { Function } Radio group collapse reducer .
* /
function createStatefulCollapseRadioGroup ( ) {
var CHOSEN _RADIO _BY _NAME = { } ;
return function collapseRadioGroup ( result , element ) {
var nodeName = element . nodeName ,
type = element . type ,
checked = element . checked ,
name = element . name ; // For all non-radio tabbables, construct to array by concatenating.
if ( nodeName !== 'INPUT' || type !== 'radio' || ! name ) {
return result . concat ( element ) ;
}
var hasChosen = CHOSEN _RADIO _BY _NAME . hasOwnProperty ( name ) ; // Omit by skipping concatenation if the radio element is not chosen.
var isChosen = checked || ! hasChosen ;
if ( ! isChosen ) {
return result ;
} // At this point, if there had been a chosen element, the current
// element is checked and should take priority. Retroactively remove
// the element which had previously been considered the chosen one.
if ( hasChosen ) {
var hadChosenElement = CHOSEN _RADIO _BY _NAME [ name ] ;
2021-01-27 21:04:13 -05:00
result = Object ( external _lodash _ [ "without" ] ) ( result , hadChosenElement ) ;
2019-03-21 08:48:00 -04:00
}
CHOSEN _RADIO _BY _NAME [ name ] = element ;
return result . concat ( element ) ;
} ;
}
2018-12-17 22:14:52 -05:00
/ * *
* An array map callback , returning an object with the element value and its
* array index location as properties . This is used to emulate a proper stable
* sort where equal tabIndex should be left in order of their occurrence in the
* document .
*
* @ param { Element } element Element .
* @ param { number } index Array index of element .
*
* @ return { Object } Mapped object with element , index .
* /
2019-03-21 08:48:00 -04:00
2018-12-17 22:14:52 -05:00
function mapElementToObjectTabbable ( element , index ) {
return {
element : element ,
index : index
} ;
}
/ * *
* An array map callback , returning an element of the given mapped object ' s
* element value .
*
* @ param { Object } object Mapped object with index .
*
* @ return { Element } Mapped object element .
* /
function mapObjectTabbableToElement ( object ) {
return object . element ;
}
/ * *
* A sort comparator function used in comparing two objects of mapped elements .
*
* @ see mapElementToObjectTabbable
*
* @ param { Object } a First object to compare .
* @ param { Object } b Second object to compare .
*
* @ return { number } Comparator result .
* /
function compareObjectTabbables ( a , b ) {
var aTabIndex = getTabIndex ( a . element ) ;
var bTabIndex = getTabIndex ( b . element ) ;
if ( aTabIndex === bTabIndex ) {
return a . index - b . index ;
}
return aTabIndex - bTabIndex ;
}
2020-01-22 17:06:21 -05:00
/ * *
* Givin focusable elements , filters out tabbable element .
*
* @ param { Array } focusables Focusable elements to filter .
*
* @ return { Array } Tabbable elements .
* /
function filterTabbable ( focusables ) {
return focusables . filter ( isTabbableIndex ) . map ( mapElementToObjectTabbable ) . sort ( compareObjectTabbables ) . map ( mapObjectTabbableToElement ) . reduce ( createStatefulCollapseRadioGroup ( ) , [ ] ) ;
}
2018-12-17 22:14:52 -05:00
function tabbable _find ( context ) {
2020-01-22 17:06:21 -05:00
return filterTabbable ( find ( context ) ) ;
}
/ * *
* Given a focusable element , find the preceding tabbable element .
*
* @ param { Element } element The focusable element before which to look . Defaults
* to the active element .
* /
2020-10-13 09:10:30 -04:00
function findPrevious ( element ) {
var focusables = find ( element . ownerDocument . body ) ;
2020-01-22 17:06:21 -05:00
var index = focusables . indexOf ( element ) ; // Remove all focusables after and including `element`.
focusables . length = index ;
2021-01-27 21:04:13 -05:00
return Object ( external _lodash _ [ "last" ] ) ( filterTabbable ( focusables ) ) ;
2020-01-22 17:06:21 -05:00
}
/ * *
* Given a focusable element , find the next tabbable element .
*
* @ param { Element } element The focusable element after which to look . Defaults
* to the active element .
* /
2020-10-13 09:10:30 -04:00
function findNext ( element ) {
var focusables = find ( element . ownerDocument . body ) ;
2020-01-22 17:06:21 -05:00
var index = focusables . indexOf ( element ) ; // Remove all focusables before and inside `element`.
var remaining = focusables . slice ( index + 1 ) . filter ( function ( node ) {
return ! element . contains ( node ) ;
} ) ;
2021-01-27 21:04:13 -05:00
return Object ( external _lodash _ [ "first" ] ) ( filterTabbable ( remaining ) ) ;
2018-12-17 22:14:52 -05:00
}
2021-01-27 21:04:13 -05:00
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js + 2 modules
var toConsumableArray = _ _webpack _require _ _ ( 15 ) ;
2020-10-13 09:10:30 -04:00
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/defineProperty.js
var defineProperty = _ _webpack _require _ _ ( 5 ) ;
// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/phrasing-content.js
function ownKeys ( object , enumerableOnly ) { var keys = Object . keys ( object ) ; if ( Object . getOwnPropertySymbols ) { var symbols = Object . getOwnPropertySymbols ( object ) ; if ( enumerableOnly ) symbols = symbols . filter ( function ( sym ) { return Object . getOwnPropertyDescriptor ( object , sym ) . enumerable ; } ) ; keys . push . apply ( keys , symbols ) ; } return keys ; }
function _objectSpread ( target ) { for ( var i = 1 ; i < arguments . length ; i ++ ) { var source = arguments [ i ] != null ? arguments [ i ] : { } ; if ( i % 2 ) { ownKeys ( Object ( source ) , true ) . forEach ( function ( key ) { Object ( defineProperty [ "a" /* default */ ] ) ( target , key , source [ key ] ) ; } ) ; } else if ( Object . getOwnPropertyDescriptors ) { Object . defineProperties ( target , Object . getOwnPropertyDescriptors ( source ) ) ; } else { ownKeys ( Object ( source ) ) . forEach ( function ( key ) { Object . defineProperty ( target , key , Object . getOwnPropertyDescriptor ( source , key ) ) ; } ) ; } } return target ; }
/ * *
* External dependencies
* /
/ * *
* All phrasing content elements .
*
* @ see https : //www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0
* /
/ * *
* All text - level semantic elements .
*
* @ see https : //html.spec.whatwg.org/multipage/text-level-semantics.html
* /
var textContentSchema = {
strong : { } ,
em : { } ,
s : { } ,
del : { } ,
ins : { } ,
a : {
attributes : [ 'href' , 'target' , 'rel' ]
} ,
code : { } ,
abbr : {
attributes : [ 'title' ]
} ,
sub : { } ,
sup : { } ,
br : { } ,
small : { } ,
// To do: fix blockquote.
// cite: {},
q : {
attributes : [ 'cite' ]
} ,
dfn : {
attributes : [ 'title' ]
} ,
data : {
attributes : [ 'value' ]
} ,
time : {
attributes : [ 'datetime' ]
} ,
var : { } ,
samp : { } ,
kbd : { } ,
i : { } ,
b : { } ,
u : { } ,
mark : { } ,
ruby : { } ,
rt : { } ,
rp : { } ,
bdi : {
attributes : [ 'dir' ]
} ,
bdo : {
attributes : [ 'dir' ]
} ,
wbr : { } ,
'#text' : { }
} ; // Recursion is needed.
// Possible: strong > em > strong.
// Impossible: strong > strong.
2021-01-27 21:04:13 -05:00
Object ( external _lodash _ [ "without" ] ) ( Object . keys ( textContentSchema ) , '#text' , 'br' ) . forEach ( function ( tag ) {
textContentSchema [ tag ] . children = Object ( external _lodash _ [ "omit" ] ) ( textContentSchema , tag ) ;
2020-10-13 09:10:30 -04:00
} ) ;
/ * *
* Embedded content elements .
*
* @ see https : //www.w3.org/TR/2011/WD-html5-20110525/content-models.html#embedded-content-0
* /
var embeddedContentSchema = {
audio : {
attributes : [ 'src' , 'preload' , 'autoplay' , 'mediagroup' , 'loop' , 'muted' ]
} ,
canvas : {
attributes : [ 'width' , 'height' ]
} ,
embed : {
attributes : [ 'src' , 'type' , 'width' , 'height' ]
} ,
img : {
attributes : [ 'alt' , 'src' , 'srcset' , 'usemap' , 'ismap' , 'width' , 'height' ]
} ,
object : {
attributes : [ 'data' , 'type' , 'name' , 'usemap' , 'form' , 'width' , 'height' ]
} ,
video : {
attributes : [ 'src' , 'poster' , 'preload' , 'autoplay' , 'mediagroup' , 'loop' , 'muted' , 'controls' , 'width' , 'height' ]
}
} ;
/ * *
* Phrasing content elements .
*
* @ see https : //www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0
* /
var phrasingContentSchema = _objectSpread ( _objectSpread ( { } , textContentSchema ) , embeddedContentSchema ) ;
/ * *
* Get schema of possible paths for phrasing content .
*
* @ see https : //developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content
*
* @ param { string } context Set to "paste" to exclude invisible elements and
* sensitive data .
*
* @ return { Object } Schema .
* /
function getPhrasingContentSchema ( context ) {
if ( context !== 'paste' ) {
return phrasingContentSchema ;
}
2021-01-27 21:04:13 -05:00
return Object ( external _lodash _ [ "omit" ] ) ( _objectSpread ( _objectSpread ( { } , phrasingContentSchema ) , { } , {
2020-10-13 09:10:30 -04:00
// We shouldn't paste potentially sensitive information which is not
// visible to the user when pasted, so strip the attributes.
ins : {
children : phrasingContentSchema . ins . children
} ,
del : {
children : phrasingContentSchema . del . children
}
} ) , [ 'u' , // Used to mark misspelling. Shouldn't be pasted.
'abbr' , // Invisible.
'data' , // Invisible.
'time' , // Invisible.
'wbr' , // Invisible.
'bdi' , // Invisible.
'bdo' // Invisible.
] ) ;
}
/ * *
* Find out whether or not the given node is phrasing content .
*
* @ see https : //developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content
*
* @ param { Element } node The node to test .
*
* @ return { boolean } True if phrasing content , false if not .
* /
function isPhrasingContent ( node ) {
var tag = node . nodeName . toLowerCase ( ) ;
return getPhrasingContentSchema ( ) . hasOwnProperty ( tag ) || tag === 'span' ;
}
function isTextContent ( node ) {
var tag = node . nodeName . toLowerCase ( ) ;
return textContentSchema . hasOwnProperty ( tag ) || tag === 'span' ;
}
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom.js
2021-01-27 21:04:13 -05:00
2018-12-13 23:41:57 -05:00
/ * *
* External dependencies
* /
/ * *
2020-10-13 09:10:30 -04:00
* Internal dependencies
2018-12-13 23:41:57 -05:00
* /
2020-10-13 09:10:30 -04:00
function getComputedStyle ( node ) {
return node . ownerDocument . defaultView . getComputedStyle ( node ) ;
}
2021-01-27 21:04:13 -05:00
/ * *
* Gets the height of the range without ignoring zero width rectangles , which
* some browsers ignore when creating a union .
*
* @ param { Range } range The range to check .
* /
function getRangeHeight ( range ) {
var rects = Array . from ( range . getClientRects ( ) ) ;
if ( ! rects . length ) {
return ;
}
var highestTop = Math . min . apply ( Math , Object ( toConsumableArray [ "a" /* default */ ] ) ( rects . map ( function ( _ref ) {
var top = _ref . top ;
return top ;
} ) ) ) ;
var lowestBottom = Math . max . apply ( Math , Object ( toConsumableArray [ "a" /* default */ ] ) ( rects . map ( function ( _ref2 ) {
var bottom = _ref2 . bottom ;
return bottom ;
} ) ) ) ;
return lowestBottom - highestTop ;
}
2018-12-13 23:41:57 -05:00
/ * *
* Returns true if the given selection object is in the forward direction , or
* false otherwise .
*
* @ see https : //developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition
*
* @ param { Selection } selection Selection object to check .
*
* @ return { boolean } Whether the selection is forward .
* /
2020-10-13 09:10:30 -04:00
2018-12-13 23:41:57 -05:00
function isSelectionForward ( selection ) {
var anchorNode = selection . anchorNode ,
focusNode = selection . focusNode ,
anchorOffset = selection . anchorOffset ,
focusOffset = selection . focusOffset ;
var position = anchorNode . compareDocumentPosition ( focusNode ) ; // Disable reason: `Node#compareDocumentPosition` returns a bitmask value,
// so bitwise operators are intended.
/* eslint-disable no-bitwise */
// Compare whether anchor node precedes focus node. If focus node (where
// end of selection occurs) is after the anchor node, it is forward.
2020-10-13 09:10:30 -04:00
if ( position & anchorNode . DOCUMENT _POSITION _PRECEDING ) {
2018-12-13 23:41:57 -05:00
return false ;
}
2020-10-13 09:10:30 -04:00
if ( position & anchorNode . DOCUMENT _POSITION _FOLLOWING ) {
2018-12-13 23:41:57 -05:00
return true ;
}
/* eslint-enable no-bitwise */
// `compareDocumentPosition` returns 0 when passed the same node, in which
// case compare offsets.
if ( position === 0 ) {
return anchorOffset <= focusOffset ;
} // This should never be reached, but return true as default case.
return true ;
}
/ * *
Block Editor: Update packages to bring a selection of bugfixes in.
Props iseulde, kjellr, aduth, 0mirka00, mcsf, nosolosw, gziolo, jasmussen, talldanwp, notnownikki, swissspidy, jorgefilipecosta, noisysocks.
See https://github.com/WordPress/gutenberg/pull/14796.
Fixes #46801.
Built from https://develop.svn.wordpress.org/trunk@45138
git-svn-id: http://core.svn.wordpress.org/trunk@44947 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-04-08 02:37:57 -04:00
* Check whether the selection is at the edge of the container . Checks for
* horizontal position by default . Set ` onlyVertical ` to true to check only
* vertically .
2018-12-13 23:41:57 -05:00
*
Block Editor: Update packages to bring a selection of bugfixes in.
Props iseulde, kjellr, aduth, 0mirka00, mcsf, nosolosw, gziolo, jasmussen, talldanwp, notnownikki, swissspidy, jorgefilipecosta, noisysocks.
See https://github.com/WordPress/gutenberg/pull/14796.
Fixes #46801.
Built from https://develop.svn.wordpress.org/trunk@45138
git-svn-id: http://core.svn.wordpress.org/trunk@44947 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-04-08 02:37:57 -04:00
* @ param { Element } container Focusable element .
* @ param { boolean } isReverse Set to true to check left , false to check right .
* @ param { boolean } onlyVertical Set to true to check only vertical position .
2018-12-13 23:41:57 -05:00
*
Block Editor: Update packages to bring a selection of bugfixes in.
Props iseulde, kjellr, aduth, 0mirka00, mcsf, nosolosw, gziolo, jasmussen, talldanwp, notnownikki, swissspidy, jorgefilipecosta, noisysocks.
See https://github.com/WordPress/gutenberg/pull/14796.
Fixes #46801.
Built from https://develop.svn.wordpress.org/trunk@45138
git-svn-id: http://core.svn.wordpress.org/trunk@44947 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-04-08 02:37:57 -04:00
* @ return { boolean } True if at the edge , false if not .
2018-12-13 23:41:57 -05:00
* /
Block Editor: Update packages to bring a selection of bugfixes in.
Props iseulde, kjellr, aduth, 0mirka00, mcsf, nosolosw, gziolo, jasmussen, talldanwp, notnownikki, swissspidy, jorgefilipecosta, noisysocks.
See https://github.com/WordPress/gutenberg/pull/14796.
Fixes #46801.
Built from https://develop.svn.wordpress.org/trunk@45138
git-svn-id: http://core.svn.wordpress.org/trunk@44947 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-04-08 02:37:57 -04:00
function isEdge ( container , isReverse , onlyVertical ) {
2021-01-27 21:04:13 -05:00
if ( Object ( external _lodash _ [ "includes" ] ) ( [ 'INPUT' , 'TEXTAREA' ] , container . tagName ) ) {
2018-12-13 23:41:57 -05:00
if ( container . selectionStart !== container . selectionEnd ) {
return false ;
}
if ( isReverse ) {
return container . selectionStart === 0 ;
}
return container . value . length === container . selectionStart ;
}
if ( ! container . isContentEditable ) {
return true ;
}
2020-10-13 09:10:30 -04:00
var ownerDocument = container . ownerDocument ;
var defaultView = ownerDocument . defaultView ;
var selection = defaultView . getSelection ( ) ;
Block Editor: Update packages to bring a selection of bugfixes in.
Props iseulde, kjellr, aduth, 0mirka00, mcsf, nosolosw, gziolo, jasmussen, talldanwp, notnownikki, swissspidy, jorgefilipecosta, noisysocks.
See https://github.com/WordPress/gutenberg/pull/14796.
Fixes #46801.
Built from https://develop.svn.wordpress.org/trunk@45138
git-svn-id: http://core.svn.wordpress.org/trunk@44947 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-04-08 02:37:57 -04:00
if ( ! selection . rangeCount ) {
return false ;
}
2018-12-13 23:41:57 -05:00
2021-01-27 21:04:13 -05:00
var range = selection . getRangeAt ( 0 ) ;
var collapsedRange = range . cloneRange ( ) ;
2019-04-22 08:40:04 -04:00
var isForward = isSelectionForward ( selection ) ;
var isCollapsed = selection . isCollapsed ; // Collapse in direction of selection.
if ( ! isCollapsed ) {
2021-01-27 21:04:13 -05:00
collapsedRange . collapse ( ! isForward ) ;
2019-04-22 08:40:04 -04:00
}
2021-01-27 21:04:13 -05:00
var collapsedRangeRect = getRectangleFromRange ( collapsedRange ) ;
2019-04-22 08:40:04 -04:00
var rangeRect = getRectangleFromRange ( range ) ;
2018-12-13 23:41:57 -05:00
2021-01-27 21:04:13 -05:00
if ( ! collapsedRangeRect || ! rangeRect ) {
Block Editor: Update packages to bring a selection of bugfixes in.
Props iseulde, kjellr, aduth, 0mirka00, mcsf, nosolosw, gziolo, jasmussen, talldanwp, notnownikki, swissspidy, jorgefilipecosta, noisysocks.
See https://github.com/WordPress/gutenberg/pull/14796.
Fixes #46801.
Built from https://develop.svn.wordpress.org/trunk@45138
git-svn-id: http://core.svn.wordpress.org/trunk@44947 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-04-08 02:37:57 -04:00
return false ;
2021-01-27 21:04:13 -05:00
} // Only consider the multiline selection at the edge if the direction is
// towards the edge. The selection is multiline if it is taller than the
// collapsed selection.
2018-12-13 23:41:57 -05:00
Block Editor: Update packages to bring a selection of bugfixes in.
Props iseulde, kjellr, aduth, 0mirka00, mcsf, nosolosw, gziolo, jasmussen, talldanwp, notnownikki, swissspidy, jorgefilipecosta, noisysocks.
See https://github.com/WordPress/gutenberg/pull/14796.
Fixes #46801.
Built from https://develop.svn.wordpress.org/trunk@45138
git-svn-id: http://core.svn.wordpress.org/trunk@44947 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-04-08 02:37:57 -04:00
2021-01-27 21:04:13 -05:00
if ( ! isCollapsed && getRangeHeight ( range ) > collapsedRangeRect . height && isForward === isReverse ) {
2018-12-13 23:41:57 -05:00
return false ;
2019-05-16 14:08:00 -04:00
} // In the case of RTL scripts, the horizontal edge is at the opposite side.
2021-01-27 21:04:13 -05:00
var _getComputedStyle = getComputedStyle ( container ) ,
direction = _getComputedStyle . direction ;
var isReverseDir = direction === 'rtl' ? ! isReverse : isReverse ;
var containerRect = container . getBoundingClientRect ( ) ; // To check if a selection is at the edge, we insert a test selection at the
// edge of the container and check if the selections have the same vertical
// or horizontal position. If they do, the selection is at the edge.
// This method proves to be better than a DOM-based calculation for the
// horizontal edge, since it ignores empty textnodes and a trailing line
// break element. In other words, we need to check visual positioning, not
// DOM positioning.
// It also proves better than using the computed style for the vertical
// edge, because we cannot know the padding and line height reliably in
// pixels. `getComputedStyle` may return a value with different units.
2019-03-07 04:09:59 -05:00
2019-05-16 14:08:00 -04:00
var x = isReverseDir ? containerRect . left + 1 : containerRect . right - 1 ;
2021-01-27 21:04:13 -05:00
var y = isReverse ? containerRect . top + 1 : containerRect . bottom - 1 ;
2020-10-13 09:10:30 -04:00
var testRange = hiddenCaretRangeFromPoint ( ownerDocument , x , y , container ) ;
2018-12-13 23:41:57 -05:00
Block Editor: Update packages to bring a selection of bugfixes in.
Props iseulde, kjellr, aduth, 0mirka00, mcsf, nosolosw, gziolo, jasmussen, talldanwp, notnownikki, swissspidy, jorgefilipecosta, noisysocks.
See https://github.com/WordPress/gutenberg/pull/14796.
Fixes #46801.
Built from https://develop.svn.wordpress.org/trunk@45138
git-svn-id: http://core.svn.wordpress.org/trunk@44947 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-04-08 02:37:57 -04:00
if ( ! testRange ) {
return false ;
}
2018-12-13 23:41:57 -05:00
2021-01-27 21:04:13 -05:00
var testRect = getRectangleFromRange ( testRange ) ;
2019-09-19 11:19:18 -04:00
2021-01-27 21:04:13 -05:00
if ( ! testRect ) {
return false ;
}
var verticalSide = isReverse ? 'top' : 'bottom' ;
var horizontalSide = isReverseDir ? 'left' : 'right' ;
var verticalDiff = testRect [ verticalSide ] - rangeRect [ verticalSide ] ;
var horizontalDiff = testRect [ horizontalSide ] - collapsedRangeRect [ horizontalSide ] ; // Allow the position to be 1px off.
var hasVerticalDiff = Math . abs ( verticalDiff ) <= 1 ;
var hasHorizontalDiff = Math . abs ( horizontalDiff ) <= 1 ;
return onlyVertical ? hasVerticalDiff : hasVerticalDiff && hasHorizontalDiff ;
Block Editor: Update packages to bring a selection of bugfixes in.
Props iseulde, kjellr, aduth, 0mirka00, mcsf, nosolosw, gziolo, jasmussen, talldanwp, notnownikki, swissspidy, jorgefilipecosta, noisysocks.
See https://github.com/WordPress/gutenberg/pull/14796.
Fixes #46801.
Built from https://develop.svn.wordpress.org/trunk@45138
git-svn-id: http://core.svn.wordpress.org/trunk@44947 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-04-08 02:37:57 -04:00
}
/ * *
* Check whether the selection is horizontally at the edge of the container .
*
* @ param { Element } container Focusable element .
* @ param { boolean } isReverse Set to true to check left , false for right .
*
* @ return { boolean } True if at the horizontal edge , false if not .
* /
function isHorizontalEdge ( container , isReverse ) {
return isEdge ( container , isReverse ) ;
2018-12-13 23:41:57 -05:00
}
/ * *
* Check whether the selection is vertically at the edge of the container .
*
* @ param { Element } container Focusable element .
* @ param { boolean } isReverse Set to true to check top , false for bottom .
*
Block Editor: Update packages to bring a selection of bugfixes in.
Props iseulde, kjellr, aduth, 0mirka00, mcsf, nosolosw, gziolo, jasmussen, talldanwp, notnownikki, swissspidy, jorgefilipecosta, noisysocks.
See https://github.com/WordPress/gutenberg/pull/14796.
Fixes #46801.
Built from https://develop.svn.wordpress.org/trunk@45138
git-svn-id: http://core.svn.wordpress.org/trunk@44947 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-04-08 02:37:57 -04:00
* @ return { boolean } True if at the vertical edge , false if not .
2018-12-13 23:41:57 -05:00
* /
function isVerticalEdge ( container , isReverse ) {
Block Editor: Update packages to bring a selection of bugfixes in.
Props iseulde, kjellr, aduth, 0mirka00, mcsf, nosolosw, gziolo, jasmussen, talldanwp, notnownikki, swissspidy, jorgefilipecosta, noisysocks.
See https://github.com/WordPress/gutenberg/pull/14796.
Fixes #46801.
Built from https://develop.svn.wordpress.org/trunk@45138
git-svn-id: http://core.svn.wordpress.org/trunk@44947 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-04-08 02:37:57 -04:00
return isEdge ( container , isReverse , true ) ;
2018-12-13 23:41:57 -05:00
}
/ * *
* Get the rectangle of a given Range .
*
* @ param { Range } range The range .
*
* @ return { DOMRect } The rectangle .
* /
function getRectangleFromRange ( range ) {
// For uncollapsed ranges, get the rectangle that bounds the contents of the
// range; this a rectangle enclosing the union of the bounding rectangles
// for all the elements in the range.
if ( ! range . collapsed ) {
return range . getBoundingClientRect ( ) ;
}
Block Editor: Update packages to bring a selection of bugfixes in.
Props iseulde, kjellr, aduth, 0mirka00, mcsf, nosolosw, gziolo, jasmussen, talldanwp, notnownikki, swissspidy, jorgefilipecosta, noisysocks.
See https://github.com/WordPress/gutenberg/pull/14796.
Fixes #46801.
Built from https://develop.svn.wordpress.org/trunk@45138
git-svn-id: http://core.svn.wordpress.org/trunk@44947 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-04-08 02:37:57 -04:00
var _range = range ,
2020-10-13 09:10:30 -04:00
startContainer = _range . startContainer ;
var ownerDocument = startContainer . ownerDocument ; // Correct invalid "BR" ranges. The cannot contain any children.
Block Editor: Update packages to bring a selection of bugfixes in.
Props iseulde, kjellr, aduth, 0mirka00, mcsf, nosolosw, gziolo, jasmussen, talldanwp, notnownikki, swissspidy, jorgefilipecosta, noisysocks.
See https://github.com/WordPress/gutenberg/pull/14796.
Fixes #46801.
Built from https://develop.svn.wordpress.org/trunk@45138
git-svn-id: http://core.svn.wordpress.org/trunk@44947 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-04-08 02:37:57 -04:00
if ( startContainer . nodeName === 'BR' ) {
var parentNode = startContainer . parentNode ;
var index = Array . from ( parentNode . childNodes ) . indexOf ( startContainer ) ;
2020-10-13 09:10:30 -04:00
range = ownerDocument . createRange ( ) ;
Block Editor: Update packages to bring a selection of bugfixes in.
Props iseulde, kjellr, aduth, 0mirka00, mcsf, nosolosw, gziolo, jasmussen, talldanwp, notnownikki, swissspidy, jorgefilipecosta, noisysocks.
See https://github.com/WordPress/gutenberg/pull/14796.
Fixes #46801.
Built from https://develop.svn.wordpress.org/trunk@45138
git-svn-id: http://core.svn.wordpress.org/trunk@44947 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-04-08 02:37:57 -04:00
range . setStart ( parentNode , index ) ;
range . setEnd ( parentNode , index ) ;
}
2018-12-13 23:41:57 -05:00
var rect = range . getClientRects ( ) [ 0 ] ; // If the collapsed range starts (and therefore ends) at an element node,
// `getClientRects` can be empty in some browsers. This can be resolved
// by adding a temporary text node with zero-width space to the range.
//
// See: https://stackoverflow.com/a/6847328/995445
if ( ! rect ) {
2020-10-13 09:10:30 -04:00
var padNode = ownerDocument . createTextNode ( "\u200B" ) ; // Do not modify the live range.
2019-04-22 08:40:04 -04:00
range = range . cloneRange ( ) ;
2018-12-13 23:41:57 -05:00
range . insertNode ( padNode ) ;
rect = range . getClientRects ( ) [ 0 ] ;
padNode . parentNode . removeChild ( padNode ) ;
}
return rect ;
}
/ * *
* Get the rectangle for the selection in a container .
*
2020-10-13 09:10:30 -04:00
* @ param { Window } win The window of the selection .
*
2018-12-13 23:41:57 -05:00
* @ return { ? DOMRect } The rectangle .
* /
2020-10-13 09:10:30 -04:00
function computeCaretRect ( win ) {
var selection = win . getSelection ( ) ;
2018-12-13 23:41:57 -05:00
var range = selection . rangeCount ? selection . getRangeAt ( 0 ) : null ;
if ( ! range ) {
return ;
}
return getRectangleFromRange ( range ) ;
}
/ * *
* Places the caret at start or end of a given element .
*
* @ param { Element } container Focusable element .
* @ param { boolean } isReverse True for end , false for start .
* /
function placeCaretAtHorizontalEdge ( container , isReverse ) {
if ( ! container ) {
return ;
}
2021-01-27 21:04:13 -05:00
if ( Object ( external _lodash _ [ "includes" ] ) ( [ 'INPUT' , 'TEXTAREA' ] , container . tagName ) ) {
2018-12-13 23:41:57 -05:00
container . focus ( ) ;
if ( isReverse ) {
container . selectionStart = container . value . length ;
container . selectionEnd = container . value . length ;
} else {
container . selectionStart = 0 ;
container . selectionEnd = 0 ;
}
return ;
}
container . focus ( ) ;
if ( ! container . isContentEditable ) {
return ;
} // Select on extent child of the container, not the container itself. This
// avoids the selection always being `endOffset` of 1 when placed at end,
// where `startContainer`, `endContainer` would always be container itself.
var rangeTarget = container [ isReverse ? 'lastChild' : 'firstChild' ] ; // If no range target, it implies that the container is empty. Focusing is
// sufficient for caret to be placed correctly.
if ( ! rangeTarget ) {
return ;
}
2020-10-13 09:10:30 -04:00
var ownerDocument = container . ownerDocument ;
var defaultView = ownerDocument . defaultView ;
var selection = defaultView . getSelection ( ) ;
var range = ownerDocument . createRange ( ) ;
2018-12-13 23:41:57 -05:00
range . selectNodeContents ( rangeTarget ) ;
range . collapse ( ! isReverse ) ;
selection . removeAllRanges ( ) ;
selection . addRange ( range ) ;
}
/ * *
* Polyfill .
* Get a collapsed range for a given point .
*
* @ see https : //developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint
*
2020-10-13 09:10:30 -04:00
* @ param { Document } doc The document of the range .
* @ param { number } x Horizontal position within the current viewport .
* @ param { number } y Vertical position within the current viewport .
2018-12-13 23:41:57 -05:00
*
* @ return { ? Range } The best range for the given point .
* /
function caretRangeFromPoint ( doc , x , y ) {
if ( doc . caretRangeFromPoint ) {
return doc . caretRangeFromPoint ( x , y ) ;
}
if ( ! doc . caretPositionFromPoint ) {
return null ;
}
var point = doc . caretPositionFromPoint ( x , y ) ; // If x or y are negative, outside viewport, or there is no text entry node.
// https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint
if ( ! point ) {
return null ;
}
var range = doc . createRange ( ) ;
range . setStart ( point . offsetNode , point . offset ) ;
range . collapse ( true ) ;
return range ;
}
/ * *
* Get a collapsed range for a given point .
* Gives the container a temporary high z - index ( above any UI ) .
* This is preferred over getting the UI nodes and set styles there .
*
* @ param { Document } doc The document of the range .
* @ param { number } x Horizontal position within the current viewport .
* @ param { number } y Vertical position within the current viewport .
* @ param { Element } container Container in which the range is expected to be found .
*
* @ return { ? Range } The best range for the given point .
* /
function hiddenCaretRangeFromPoint ( doc , x , y , container ) {
2019-09-19 11:19:18 -04:00
var originalZIndex = container . style . zIndex ;
var originalPosition = container . style . position ; // A z-index only works if the element position is not static.
2018-12-13 23:41:57 -05:00
container . style . zIndex = '10000' ;
2019-09-19 11:19:18 -04:00
container . style . position = 'relative' ;
2018-12-13 23:41:57 -05:00
var range = caretRangeFromPoint ( doc , x , y ) ;
2019-09-19 11:19:18 -04:00
container . style . zIndex = originalZIndex ;
container . style . position = originalPosition ;
2018-12-13 23:41:57 -05:00
return range ;
}
/ * *
* Places the caret at the top or bottom of a given element .
*
* @ param { Element } container Focusable element .
* @ param { boolean } isReverse True for bottom , false for top .
* @ param { DOMRect } [ rect ] The rectangle to position the caret with .
* @ param { boolean } [ mayUseScroll = true ] True to allow scrolling , false to disallow .
* /
function placeCaretAtVerticalEdge ( container , isReverse , rect ) {
var mayUseScroll = arguments . length > 3 && arguments [ 3 ] !== undefined ? arguments [ 3 ] : true ;
if ( ! container ) {
return ;
}
if ( ! rect || ! container . isContentEditable ) {
placeCaretAtHorizontalEdge ( container , isReverse ) ;
return ;
} // Offset by a buffer half the height of the caret rect. This is needed
// because caretRangeFromPoint may default to the end of the selection if
// offset is too close to the edge. It's unclear how to precisely calculate
// this threshold; it may be the padded area of some combination of line
// height, caret height, and font size. The buffer offset is effectively
// equivalent to a point at half the height of a line of text.
var buffer = rect . height / 2 ;
var editableRect = container . getBoundingClientRect ( ) ;
var x = rect . left ;
var y = isReverse ? editableRect . bottom - buffer : editableRect . top + buffer ;
2020-10-13 09:10:30 -04:00
var ownerDocument = container . ownerDocument ;
var defaultView = ownerDocument . defaultView ;
var range = hiddenCaretRangeFromPoint ( ownerDocument , x , y , container ) ;
2018-12-13 23:41:57 -05:00
if ( ! range || ! container . contains ( range . startContainer ) ) {
if ( mayUseScroll && ( ! range || ! range . startContainer || ! range . startContainer . contains ( container ) ) ) {
// Might be out of view.
// Easier than attempting to calculate manually.
container . scrollIntoView ( isReverse ) ;
placeCaretAtVerticalEdge ( container , isReverse , rect , false ) ;
return ;
}
placeCaretAtHorizontalEdge ( container , isReverse ) ;
return ;
}
2020-10-13 09:10:30 -04:00
var selection = defaultView . getSelection ( ) ;
2018-12-13 23:41:57 -05:00
selection . removeAllRanges ( ) ;
selection . addRange ( range ) ;
container . focus ( ) ; // Editable was already focussed, it goes back to old range...
// This fixes it.
selection . removeAllRanges ( ) ;
selection . addRange ( range ) ;
}
/ * *
* Check whether the given element is a text field , where text field is defined
* by the ability to select within the input , or that it is contenteditable .
*
* See : https : //html.spec.whatwg.org/#textFieldSelection
*
* @ param { HTMLElement } element The HTML element .
*
* @ return { boolean } True if the element is an text field , false if not .
* /
function isTextField ( element ) {
2020-07-14 07:39:09 -04:00
var nodeName = element . nodeName ,
contentEditable = element . contentEditable ;
var nonTextInputs = [ 'button' , 'checkbox' , 'hidden' , 'file' , 'radio' , 'image' , 'range' , 'reset' , 'submit' , 'number' ] ;
return nodeName === 'INPUT' && ! nonTextInputs . includes ( element . type ) || nodeName === 'TEXTAREA' || contentEditable === 'true' ;
2018-12-13 23:41:57 -05:00
}
/ * *
2020-06-26 09:33:47 -04:00
* Check whether the given element is an input field of type number
* and has a valueAsNumber
2018-12-13 23:41:57 -05:00
*
2020-06-26 09:33:47 -04:00
* @ param { HTMLElement } element The HTML element .
*
* @ return { boolean } True if the element is input and holds a number .
2018-12-13 23:41:57 -05:00
* /
2020-06-26 09:33:47 -04:00
function isNumberInput ( element ) {
var nodeName = element . nodeName ,
type = element . type ,
valueAsNumber = element . valueAsNumber ;
return nodeName === 'INPUT' && type === 'number' && ! ! valueAsNumber ;
}
/ * *
* Check whether the current document has selected text . This applies to ranges
* of text in the document , and not selection inside < input > and < textarea >
* elements .
*
* See : https : //developer.mozilla.org/en-US/docs/Web/API/Window/getSelection#Related_objects.
*
2020-10-13 09:10:30 -04:00
* @ param { Document } doc The document to check .
*
2020-06-26 09:33:47 -04:00
* @ return { boolean } True if there is selection , false if not .
* /
2018-12-13 23:41:57 -05:00
2020-10-13 09:10:30 -04:00
function documentHasTextSelection ( doc ) {
var selection = doc . defaultView . getSelection ( ) ;
2018-12-13 23:41:57 -05:00
var range = selection . rangeCount ? selection . getRangeAt ( 0 ) : null ;
return range && ! range . collapsed ;
}
2020-06-26 09:33:47 -04:00
/ * *
* Check whether the given element , assumed an input field or textarea ,
* contains a ( uncollapsed ) selection of text .
*
* Note : this is perhaps an abuse of the term "selection" , since these elements
* manage selection differently and aren ' t covered by Selection # collapsed .
*
* See : https : //developer.mozilla.org/en-US/docs/Web/API/Window/getSelection#Related_objects.
*
* @ param { HTMLElement } element The HTML element .
*
* @ return { boolean } Whether the input / textareaa element has some "selection" .
* /
function inputFieldHasUncollapsedSelection ( element ) {
if ( ! isTextField ( element ) && ! isNumberInput ( element ) ) {
return false ;
}
try {
var selectionStart = element . selectionStart ,
selectionEnd = element . selectionEnd ;
return selectionStart !== null && selectionStart !== selectionEnd ;
} catch ( error ) {
// Safari throws an exception when trying to get `selectionStart`
// on non-text <input> elements (which, understandably, don't
// have the text selection API). We catch this via a try/catch
// block, as opposed to a more explicit check of the element's
// input types, because of Safari's non-standard behavior. This
// also means we don't have to worry about the list of input
// types that support `selectionStart` changing as the HTML spec
// evolves over time.
return false ;
}
}
/ * *
* Check whether the current document has any sort of selection . This includes
* ranges of text across elements and any selection inside < input > and
* < textarea > elements .
*
2020-10-13 09:10:30 -04:00
* @ param { Document } doc The document to check .
*
2020-06-26 09:33:47 -04:00
* @ return { boolean } Whether there is any sort of "selection" in the document .
* /
2020-10-13 09:10:30 -04:00
function documentHasUncollapsedSelection ( doc ) {
return documentHasTextSelection ( doc ) || inputFieldHasUncollapsedSelection ( doc . activeElement ) ;
2020-06-26 09:33:47 -04:00
}
/ * *
* Check whether the current document has a selection . This checks for both
* focus in an input field and general text selection .
*
2020-10-13 09:10:30 -04:00
* @ param { Document } doc The document to check .
*
2020-06-26 09:33:47 -04:00
* @ return { boolean } True if there is selection , false if not .
* /
2020-10-13 09:10:30 -04:00
function documentHasSelection ( doc ) {
return isTextField ( doc . activeElement ) || isNumberInput ( doc . activeElement ) || documentHasTextSelection ( doc ) ;
2020-06-26 09:33:47 -04:00
}
2018-12-13 23:41:57 -05:00
/ * *
* Check whether the contents of the element have been entirely selected .
* Returns true if there is no possibility of selection .
*
* @ param { Element } element The element to check .
*
* @ return { boolean } True if entirely selected , false if not .
* /
function isEntirelySelected ( element ) {
2021-01-27 21:04:13 -05:00
if ( Object ( external _lodash _ [ "includes" ] ) ( [ 'INPUT' , 'TEXTAREA' ] , element . nodeName ) ) {
2018-12-13 23:41:57 -05:00
return element . selectionStart === 0 && element . value . length === element . selectionEnd ;
}
if ( ! element . isContentEditable ) {
return true ;
}
2020-10-13 09:10:30 -04:00
var ownerDocument = element . ownerDocument ;
var defaultView = ownerDocument . defaultView ;
var selection = defaultView . getSelection ( ) ;
2018-12-13 23:41:57 -05:00
var range = selection . rangeCount ? selection . getRangeAt ( 0 ) : null ;
if ( ! range ) {
return true ;
}
var startContainer = range . startContainer ,
endContainer = range . endContainer ,
startOffset = range . startOffset ,
endOffset = range . endOffset ;
Block Editor: Update `@wordpress` dependencies to match Gutenberg 4.5.1.
- Update the annotations, api-fetch, block-library, blocks, components, compose, core-data, data, date, dom, edit-post, editor, element, format-library, html-entities, i18n, jest-console, jest-preset-default, keycodes, list-reusable-blocks, notices, nux, plugins, rich-text, scripts, token-lists, url, viewport packages.
- Upgrades React from 16.5.2 to 16.6.3.
- Adds a missing `wp-date` dependency to the editor script.
- Updates changed dependencies in `script-loader.php`.
- Fixes undefined notices in some blocks.
- Removes incorrect `gutenberg` textdomain.
Merges [43891], [43903], and [43919] to trunk.
Props atimmer, aduth, youknowriad, danielbachhuber.
See #45145.
Built from https://develop.svn.wordpress.org/trunk@44262
git-svn-id: http://core.svn.wordpress.org/trunk@44092 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-12-17 10:37:00 -05:00
if ( startContainer === element && endContainer === element && startOffset === 0 && endOffset === element . childNodes . length ) {
return true ;
}
var lastChild = element . lastChild ;
2020-10-13 09:10:30 -04:00
var lastChildContentLength = lastChild . nodeType === lastChild . TEXT _NODE ? lastChild . data . length : lastChild . childNodes . length ;
Block Editor: Update `@wordpress` dependencies to match Gutenberg 4.5.1.
- Update the annotations, api-fetch, block-library, blocks, components, compose, core-data, data, date, dom, edit-post, editor, element, format-library, html-entities, i18n, jest-console, jest-preset-default, keycodes, list-reusable-blocks, notices, nux, plugins, rich-text, scripts, token-lists, url, viewport packages.
- Upgrades React from 16.5.2 to 16.6.3.
- Adds a missing `wp-date` dependency to the editor script.
- Updates changed dependencies in `script-loader.php`.
- Fixes undefined notices in some blocks.
- Removes incorrect `gutenberg` textdomain.
Merges [43891], [43903], and [43919] to trunk.
Props atimmer, aduth, youknowriad, danielbachhuber.
See #45145.
Built from https://develop.svn.wordpress.org/trunk@44262
git-svn-id: http://core.svn.wordpress.org/trunk@44092 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-12-17 10:37:00 -05:00
return startContainer === element . firstChild && endContainer === element . lastChild && startOffset === 0 && endOffset === lastChildContentLength ;
2018-12-13 23:41:57 -05:00
}
/ * *
* Given a DOM node , finds the closest scrollable container node .
*
* @ param { Element } node Node from which to start .
*
* @ return { ? Element } Scrollable container node , if found .
* /
function getScrollContainer ( node ) {
if ( ! node ) {
return ;
} // Scrollable if scrollable height exceeds displayed...
if ( node . scrollHeight > node . clientHeight ) {
// ...except when overflow is defined to be hidden or visible
2021-01-27 21:04:13 -05:00
var _getComputedStyle2 = getComputedStyle ( node ) ,
overflowY = _getComputedStyle2 . overflowY ;
2018-12-13 23:41:57 -05:00
if ( /(auto|scroll)/ . test ( overflowY ) ) {
return node ;
}
} // Continue traversing
return getScrollContainer ( node . parentNode ) ;
}
/ * *
* Returns the closest positioned element , or null under any of the conditions
* of the offsetParent specification . Unlike offsetParent , this function is not
* limited to HTMLElement and accepts any Node ( e . g . Node . TEXT _NODE ) .
*
* @ see https : //drafts.csswg.org/cssom-view/#dom-htmlelement-offsetparent
*
* @ param { Node } node Node from which to find offset parent .
*
* @ return { ? Node } Offset parent .
* /
function getOffsetParent ( node ) {
// Cannot retrieve computed style or offset parent only anything other than
// an element node, so find the closest element node.
var closestElement ;
while ( closestElement = node . parentNode ) {
2020-10-13 09:10:30 -04:00
if ( closestElement . nodeType === closestElement . ELEMENT _NODE ) {
2018-12-13 23:41:57 -05:00
break ;
}
}
if ( ! closestElement ) {
return null ;
} // If the closest element is already positioned, return it, as offsetParent
// does not otherwise consider the node itself.
if ( getComputedStyle ( closestElement ) . position !== 'static' ) {
return closestElement ;
}
return closestElement . offsetParent ;
}
/ * *
* Given two DOM nodes , replaces the former with the latter in the DOM .
*
* @ param { Element } processedNode Node to be removed .
* @ param { Element } newNode Node to be inserted in its place .
* @ return { void }
* /
function replace ( processedNode , newNode ) {
insertAfter ( newNode , processedNode . parentNode ) ;
remove ( processedNode ) ;
}
/ * *
* Given a DOM node , removes it from the DOM .
*
* @ param { Element } node Node to be removed .
* @ return { void }
* /
function remove ( node ) {
node . parentNode . removeChild ( node ) ;
}
/ * *
* Given two DOM nodes , inserts the former in the DOM as the next sibling of
* the latter .
*
* @ param { Element } newNode Node to be inserted .
* @ param { Element } referenceNode Node after which to perform the insertion .
* @ return { void }
* /
function insertAfter ( newNode , referenceNode ) {
referenceNode . parentNode . insertBefore ( newNode , referenceNode . nextSibling ) ;
}
/ * *
* Unwrap the given node . This means any child nodes are moved to the parent .
*
* @ param { Node } node The node to unwrap .
*
* @ return { void }
* /
function unwrap ( node ) {
var parent = node . parentNode ;
while ( node . firstChild ) {
parent . insertBefore ( node . firstChild , node ) ;
}
parent . removeChild ( node ) ;
}
/ * *
* Replaces the given node with a new node with the given tag name .
*
* @ param { Element } node The node to replace
* @ param { string } tagName The new tag name .
*
* @ return { Element } The new node .
* /
2018-12-16 23:52:00 -05:00
function replaceTag ( node , tagName ) {
var newNode = node . ownerDocument . createElement ( tagName ) ;
2018-12-13 23:41:57 -05:00
while ( node . firstChild ) {
newNode . appendChild ( node . firstChild ) ;
}
node . parentNode . replaceChild ( newNode , node ) ;
return newNode ;
}
2018-12-16 23:52:00 -05:00
/ * *
* Wraps the given node with a new node with the given tag name .
*
* @ param { Element } newNode The node to insert .
* @ param { Element } referenceNode The node to wrap .
* /
function wrap ( newNode , referenceNode ) {
referenceNode . parentNode . insertBefore ( newNode , referenceNode ) ;
newNode . appendChild ( referenceNode ) ;
}
2020-02-06 16:03:31 -05:00
/ * *
* 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 ) {
2020-10-13 09:10:30 -04:00
var document = new window . DOMParser ( ) . parseFromString ( html , 'text/html' ) ;
2020-02-06 16:03:31 -05:00
return document . body . textContent || '' ;
}
2020-10-13 09:10:30 -04:00
/ * *
* Given a schema , unwraps or removes nodes , attributes and classes on a node
* list .
*
* @ param { NodeList } nodeList The nodeList to filter .
* @ param { Document } doc The document of the nodeList .
* @ param { Object } schema An array of functions that can mutate with the provided node .
* @ param { Object } inline Whether to clean for inline mode .
* /
function cleanNodeList ( nodeList , doc , schema , inline ) {
Array . from ( nodeList ) . forEach ( function ( node ) {
var tag = node . nodeName . toLowerCase ( ) ; // It's a valid child, if the tag exists in the schema without an isMatch
// function, or with an isMatch function that matches the node.
if ( schema . hasOwnProperty ( tag ) && ( ! schema [ tag ] . isMatch || schema [ tag ] . isMatch ( node ) ) ) {
if ( node . nodeType === node . ELEMENT _NODE ) {
var _schema$tag = schema [ tag ] ,
_schema$tag$attribute = _schema$tag . attributes ,
attributes = _schema$tag$attribute === void 0 ? [ ] : _schema$tag$attribute ,
_schema$tag$classes = _schema$tag . classes ,
classes = _schema$tag$classes === void 0 ? [ ] : _schema$tag$classes ,
children = _schema$tag . children ,
_schema$tag$require = _schema$tag . require ,
require = _schema$tag$require === void 0 ? [ ] : _schema$tag$require ,
allowEmpty = _schema$tag . allowEmpty ; // If the node is empty and it's supposed to have children,
// remove the node.
if ( children && ! allowEmpty && isEmpty ( node ) ) {
remove ( node ) ;
return ;
}
if ( node . hasAttributes ( ) ) {
// Strip invalid attributes.
2021-01-27 21:04:13 -05:00
Array . from ( node . attributes ) . forEach ( function ( _ref3 ) {
var name = _ref3 . name ;
2020-10-13 09:10:30 -04:00
2021-01-27 21:04:13 -05:00
if ( name !== 'class' && ! Object ( external _lodash _ [ "includes" ] ) ( attributes , name ) ) {
2020-10-13 09:10:30 -04:00
node . removeAttribute ( name ) ;
}
} ) ; // Strip invalid classes.
// In jsdom-jscore, 'node.classList' can be undefined.
// TODO: Explore patching this in jsdom-jscore.
if ( node . classList && node . classList . length ) {
var mattchers = classes . map ( function ( item ) {
if ( typeof item === 'string' ) {
return function ( className ) {
return className === item ;
} ;
} else if ( item instanceof RegExp ) {
return function ( className ) {
return item . test ( className ) ;
} ;
}
2021-01-27 21:04:13 -05:00
return external _lodash _ [ "noop" ] ;
2020-10-13 09:10:30 -04:00
} ) ;
Array . from ( node . classList ) . forEach ( function ( name ) {
if ( ! mattchers . some ( function ( isMatch ) {
return isMatch ( name ) ;
} ) ) {
node . classList . remove ( name ) ;
}
} ) ;
if ( ! node . classList . length ) {
node . removeAttribute ( 'class' ) ;
}
}
}
if ( node . hasChildNodes ( ) ) {
// Do not filter any content.
if ( children === '*' ) {
return ;
} // Continue if the node is supposed to have children.
if ( children ) {
// If a parent requires certain children, but it does
// not have them, drop the parent and continue.
if ( require . length && ! node . querySelector ( require . join ( ',' ) ) ) {
cleanNodeList ( node . childNodes , doc , schema , inline ) ;
unwrap ( node ) ; // If the node is at the top, phrasing content, and
// contains children that are block content, unwrap
// the node because it is invalid.
} else if ( node . parentNode . nodeName === 'BODY' && isPhrasingContent ( node ) ) {
cleanNodeList ( node . childNodes , doc , schema , inline ) ;
if ( Array . from ( node . childNodes ) . some ( function ( child ) {
return ! isPhrasingContent ( child ) ;
} ) ) {
unwrap ( node ) ;
}
} else {
cleanNodeList ( node . childNodes , doc , children , inline ) ;
} // Remove children if the node is not supposed to have any.
} else {
while ( node . firstChild ) {
remove ( node . firstChild ) ;
}
}
}
} // Invalid child. Continue with schema at the same place and unwrap.
} else {
cleanNodeList ( node . childNodes , doc , schema , inline ) ; // For inline mode, insert a line break when unwrapping nodes that
// are not phrasing content.
if ( inline && ! isPhrasingContent ( node ) && node . nextElementSibling ) {
insertAfter ( doc . createElement ( 'br' ) , node ) ;
}
unwrap ( node ) ;
}
} ) ;
}
/ * *
* Recursively checks if an element is empty . An element is not empty if it
* contains text or contains elements with attributes such as images .
*
* @ param { Element } element The element to check .
*
2021-01-27 21:04:13 -05:00
* @ return { boolean } Whether or not the element is empty .
2020-10-13 09:10:30 -04:00
* /
function isEmpty ( element ) {
if ( ! element . hasChildNodes ( ) ) {
return true ;
}
return Array . from ( element . childNodes ) . every ( function ( node ) {
if ( node . nodeType === node . TEXT _NODE ) {
return ! node . nodeValue . trim ( ) ;
}
if ( node . nodeType === node . ELEMENT _NODE ) {
if ( node . nodeName === 'BR' ) {
return true ;
} else if ( node . hasAttributes ( ) ) {
return false ;
}
return isEmpty ( node ) ;
}
return true ;
} ) ;
}
/ * *
* Given a schema , unwraps or removes nodes , attributes and classes on HTML .
*
* @ param { string } HTML The HTML to clean up .
* @ param { Object } schema Schema for the HTML .
* @ param { Object } inline Whether to clean for inline mode .
*
* @ return { string } The cleaned up HTML .
* /
function removeInvalidHTML ( HTML , schema , inline ) {
var doc = document . implementation . createHTMLDocument ( '' ) ;
doc . body . innerHTML = HTML ;
cleanNodeList ( doc . body . childNodes , doc , schema , inline ) ;
return doc . body . innerHTML ;
}
2018-12-13 23:41:57 -05:00
2021-01-27 21:04:13 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/data-transfer.js
/ * *
* Gets all files from a DataTransfer object .
*
* @ param { DataTransfer } dataTransfer DataTransfer object to inspect .
*
* @ return { Object [ ] } An array containing all files .
* /
function getFilesFromDataTransfer ( dataTransfer ) {
var files = Object ( toConsumableArray [ "a" /* default */ ] ) ( dataTransfer . files ) ;
Array . from ( dataTransfer . items ) . forEach ( function ( item ) {
var file = item . getAsFile ( ) ;
if ( file && ! files . find ( function ( _ref ) {
var name = _ref . name ,
type = _ref . type ,
size = _ref . size ;
return name === file . name && type === file . type && size === file . size ;
} ) ) {
files . push ( file ) ;
}
} ) ;
return files ;
}
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/index.js
2018-12-13 23:41:57 -05:00
/ * *
* Internal dependencies
* /
2019-03-21 08:48:00 -04:00
/ * *
* Object grouping ` focusable ` and ` tabbable ` utils
* under the keys with the same name .
* /
2018-12-17 22:14:52 -05:00
var build _module _focus = {
focusable : focusable _namespaceObject ,
tabbable : tabbable _namespaceObject
2018-12-13 23:41:57 -05:00
} ;
2020-10-13 09:10:30 -04:00
2021-01-27 21:04:13 -05:00
2020-10-13 09:10:30 -04:00
/***/ } ) ,
/***/ 5 :
/***/ ( function ( module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) {
"use strict" ;
/* harmony export (binding) */ _ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "a" , function ( ) { return _defineProperty ; } ) ;
function _defineProperty ( obj , key , value ) {
if ( key in obj ) {
Object . defineProperty ( obj , key , {
value : value ,
enumerable : true ,
configurable : true ,
writable : true
} ) ;
} else {
obj [ key ] = value ;
}
return obj ;
}
2018-12-13 23:41:57 -05:00
/***/ } )
2018-12-17 22:14:52 -05:00
/******/ } ) ;