2018-12-13 23:41:57 -05:00
this [ "wp" ] = this [ "wp" ] || { } ; this [ "wp" ] [ "richText" ] =
/******/ ( 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-05-20 08:20:04 -04:00
/******/ return _ _webpack _require _ _ ( _ _webpack _require _ _ . s = "yyEc" ) ;
2018-12-13 23:41:57 -05:00
/******/ } )
/************************************************************************/
/******/ ( {
2021-05-20 08:20:04 -04:00
/***/ "1ZqX" :
/***/ ( function ( module , exports ) {
( function ( ) { module . exports = window [ "wp" ] [ "data" ] ; } ( ) ) ;
/***/ } ) ,
/***/ "GRId" :
2018-12-17 22:14:52 -05:00
/***/ ( function ( module , exports ) {
2018-12-13 23:41:57 -05:00
2021-01-27 21:04:13 -05:00
( function ( ) { module . exports = window [ "wp" ] [ "element" ] ; } ( ) ) ;
2018-12-13 23:41:57 -05:00
/***/ } ) ,
2021-05-20 08:20:04 -04:00
/***/ "K9lf" :
2021-04-15 11:19:43 -04:00
/***/ ( function ( module , exports ) {
( function ( ) { module . exports = window [ "wp" ] [ "compose" ] ; } ( ) ) ;
/***/ } ) ,
2021-05-20 08:20:04 -04:00
/***/ "RxS6" :
2018-12-17 22:14:52 -05:00
/***/ ( function ( module , exports ) {
2018-12-13 23:41:57 -05:00
2021-01-27 21:04:13 -05:00
( function ( ) { module . exports = window [ "wp" ] [ "keycodes" ] ; } ( ) ) ;
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
/***/ } ) ,
2018-12-13 23:41:57 -05:00
2021-05-20 08:20:04 -04:00
/***/ "Vx3V" :
2021-01-27 21:04:13 -05:00
/***/ ( function ( module , exports ) {
2021-05-20 08:20:04 -04:00
( function ( ) { module . exports = window [ "wp" ] [ "escapeHtml" ] ; } ( ) ) ;
2021-01-27 21:04:13 -05:00
/***/ } ) ,
2021-05-20 08:20:04 -04:00
/***/ "YLtl" :
2020-03-23 19:40:19 -04:00
/***/ ( function ( module , exports ) {
2021-05-19 11:09:27 -04:00
( function ( ) { module . exports = window [ "lodash" ] ; } ( ) ) ;
2020-06-26 09:33:47 -04:00
/***/ } ) ,
2021-11-08 09:29:21 -05:00
/***/ "gdqT" :
/***/ ( function ( module , exports ) {
( function ( ) { module . exports = window [ "wp" ] [ "a11y" ] ; } ( ) ) ;
/***/ } ) ,
/***/ "l3Sj" :
/***/ ( function ( module , exports ) {
( function ( ) { module . exports = window [ "wp" ] [ "i18n" ] ; } ( ) ) ;
/***/ } ) ,
2021-05-20 08:20:04 -04:00
/***/ "pPDe" :
2020-06-26 09:33:47 -04:00
/***/ ( function ( module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) {
2019-03-07 04:09:59 -05:00
"use strict" ;
2020-01-22 17:06:21 -05:00
var LEAF _KEY , hasWeakMap ;
2019-03-07 04:09:59 -05:00
/ * *
2020-01-22 17:06:21 -05:00
* Arbitrary value used as key for referencing cache object in WeakMap tree .
*
* @ type { Object }
2019-03-07 04:09:59 -05:00
* /
2020-01-22 17:06:21 -05:00
LEAF _KEY = { } ;
2019-03-07 04:09:59 -05:00
/ * *
2020-01-22 17:06:21 -05:00
* Whether environment supports WeakMap .
*
* @ type { boolean }
2019-03-07 04:09:59 -05:00
* /
2020-01-22 17:06:21 -05:00
hasWeakMap = typeof WeakMap !== 'undefined' ;
2019-03-07 04:09:59 -05:00
/ * *
2020-01-22 17:06:21 -05:00
* Returns the first argument as the sole entry in an array .
2019-03-07 04:09:59 -05:00
*
2020-01-22 17:06:21 -05:00
* @ param { * } value Value to return .
2019-03-07 04:09:59 -05:00
*
2020-01-22 17:06:21 -05:00
* @ return { Array } Value returned as entry in array .
2019-03-07 04:09:59 -05:00
* /
2020-01-22 17:06:21 -05:00
function arrayOf ( value ) {
return [ value ] ;
2019-03-07 04:09:59 -05:00
}
/ * *
2020-01-22 17:06:21 -05:00
* Returns true if the value passed is object - like , or false otherwise . A value
* is object - like if it can support property assignment , e . g . object or array .
2019-03-07 04:09:59 -05:00
*
2020-01-22 17:06:21 -05:00
* @ param { * } value Value to test .
2019-03-07 04:09:59 -05:00
*
2020-01-22 17:06:21 -05:00
* @ return { boolean } Whether value is object - like .
2019-03-07 04:09:59 -05:00
* /
2020-01-22 17:06:21 -05:00
function isObjectLike ( value ) {
return ! ! value && 'object' === typeof value ;
}
2019-03-07 04:09:59 -05:00
/ * *
2020-01-22 17:06:21 -05:00
* Creates and returns a new cache object .
2019-03-07 04:09:59 -05:00
*
2020-01-22 17:06:21 -05:00
* @ return { Object } Cache object .
2019-03-07 04:09:59 -05:00
* /
2020-01-22 17:06:21 -05:00
function createCache ( ) {
var cache = {
clear : function ( ) {
cache . head = null ;
} ,
} ;
2019-03-07 04:09:59 -05:00
2020-01-22 17:06:21 -05:00
return cache ;
2019-03-07 04:09:59 -05:00
}
/ * *
2020-01-22 17:06:21 -05:00
* Returns true if entries within the two arrays are strictly equal by
* reference from a starting index .
2019-03-07 04:09:59 -05:00
*
2020-01-22 17:06:21 -05:00
* @ param { Array } a First array .
* @ param { Array } b Second array .
* @ param { number } fromIndex Index from which to start comparison .
*
* @ return { boolean } Whether arrays are shallowly equal .
2019-03-07 04:09:59 -05:00
* /
2020-01-22 17:06:21 -05:00
function isShallowEqual ( a , b , fromIndex ) {
var i ;
2019-03-07 04:09:59 -05:00
2020-01-22 17:06:21 -05:00
if ( a . length !== b . length ) {
return false ;
}
2019-03-07 04:09:59 -05:00
2020-01-22 17:06:21 -05:00
for ( i = fromIndex ; i < a . length ; i ++ ) {
if ( a [ i ] !== b [ i ] ) {
return false ;
}
}
2019-03-07 04:09:59 -05:00
2020-01-22 17:06:21 -05:00
return true ;
2019-03-07 04:09:59 -05:00
}
/ * *
2020-01-22 17:06:21 -05:00
* Returns a memoized selector function . The getDependants function argument is
* called before the memoized selector and is expected to return an immutable
* reference or array of references on which the selector depends for computing
* its own return value . The memoize cache is preserved only as long as those
* dependant references remain the same . If getDependants returns a different
* reference ( s ) , the cache is cleared and the selector value regenerated .
2019-03-07 04:09:59 -05:00
*
2020-01-22 17:06:21 -05:00
* @ param { Function } selector Selector function .
* @ param { Function } getDependants Dependant getter returning an immutable
* reference or array of reference used in
* cache bust consideration .
2019-03-07 04:09:59 -05:00
*
2020-01-22 17:06:21 -05:00
* @ return { Function } Memoized selector .
2019-03-07 04:09:59 -05:00
* /
2020-01-22 17:06:21 -05:00
/* harmony default export */ _ _webpack _exports _ _ [ "a" ] = ( function ( selector , getDependants ) {
var rootCache , getCache ;
2019-03-07 04:09:59 -05:00
2020-01-22 17:06:21 -05:00
// Use object source as dependant if getter not provided
if ( ! getDependants ) {
getDependants = arrayOf ;
}
/ * *
* Returns the root cache . If WeakMap is supported , this is assigned to the
* root WeakMap cache set , otherwise it is a shared instance of the default
* cache object .
*
* @ return { ( WeakMap | Object ) } Root cache object .
* /
function getRootCache ( ) {
return rootCache ;
}
/ * *
* Returns the cache for a given dependants array . When possible , a WeakMap
* will be used to create a unique cache for each set of dependants . This
* is feasible due to the nature of WeakMap in allowing garbage collection
* to occur on entries where the key object is no longer referenced . Since
* WeakMap requires the key to be an object , this is only possible when the
* dependant is object - like . The root cache is created as a hierarchy where
* each top - level key is the first entry in a dependants set , the value a
* WeakMap where each key is the next dependant , and so on . This continues
* so long as the dependants are object - like . If no dependants are object -
* like , then the cache is shared across all invocations .
*
* @ see isObjectLike
*
* @ param { Array } dependants Selector dependants .
*
* @ return { Object } Cache object .
* /
function getWeakMapCache ( dependants ) {
var caches = rootCache ,
isUniqueByDependants = true ,
i , dependant , map , cache ;
for ( i = 0 ; i < dependants . length ; i ++ ) {
dependant = dependants [ i ] ;
// Can only compose WeakMap from object-like key.
if ( ! isObjectLike ( dependant ) ) {
isUniqueByDependants = false ;
break ;
}
// Does current segment of cache already have a WeakMap?
if ( caches . has ( dependant ) ) {
// Traverse into nested WeakMap.
caches = caches . get ( dependant ) ;
} else {
// Create, set, and traverse into a new one.
map = new WeakMap ( ) ;
caches . set ( dependant , map ) ;
caches = map ;
}
}
// We use an arbitrary (but consistent) object as key for the last item
// in the WeakMap to serve as our running cache.
if ( ! caches . has ( LEAF _KEY ) ) {
cache = createCache ( ) ;
cache . isUniqueByDependants = isUniqueByDependants ;
caches . set ( LEAF _KEY , cache ) ;
}
return caches . get ( LEAF _KEY ) ;
}
// Assign cache handler by availability of WeakMap
getCache = hasWeakMap ? getWeakMapCache : getRootCache ;
/ * *
* Resets root memoization cache .
* /
function clear ( ) {
rootCache = hasWeakMap ? new WeakMap ( ) : createCache ( ) ;
}
// eslint-disable-next-line jsdoc/check-param-names
/ * *
* The augmented selector call , considering first whether dependants have
* changed before passing it to underlying memoize function .
*
* @ param { Object } source Source object for derivation .
* @ param { ... * } extraArgs Additional arguments to pass to selector .
*
* @ return { * } Selector result .
* /
function callSelector ( /* source, ...extraArgs */ ) {
var len = arguments . length ,
cache , node , i , args , dependants ;
// Create copy of arguments (avoid leaking deoptimization).
args = new Array ( len ) ;
for ( i = 0 ; i < len ; i ++ ) {
args [ i ] = arguments [ i ] ;
}
dependants = getDependants . apply ( null , args ) ;
cache = getCache ( dependants ) ;
// If not guaranteed uniqueness by dependants (primitive type or lack
// of WeakMap support), shallow compare against last dependants and, if
// references have changed, destroy cache to recalculate result.
if ( ! cache . isUniqueByDependants ) {
if ( cache . lastDependants && ! isShallowEqual ( dependants , cache . lastDependants , 0 ) ) {
cache . clear ( ) ;
}
cache . lastDependants = dependants ;
}
node = cache . head ;
while ( node ) {
// Check whether node arguments match arguments
if ( ! isShallowEqual ( node . args , args , 1 ) ) {
node = node . next ;
continue ;
}
// At this point we can assume we've found a match
// Surface matched node to head if not already
if ( node !== cache . head ) {
// Adjust siblings to point to each other.
node . prev . next = node . next ;
if ( node . next ) {
node . next . prev = node . prev ;
}
node . next = cache . head ;
node . prev = null ;
cache . head . prev = node ;
cache . head = node ;
}
// Return immediately
return node . val ;
}
// No cached value found. Continue to insertion phase:
node = {
// Generate the result from original function
val : selector . apply ( null , args ) ,
} ;
// Avoid including the source object in the cache.
args [ 0 ] = null ;
node . args = args ;
// Don't need to check whether node is already head, since it would
// have been returned above already if it was
// Shift existing head down list
if ( cache . head ) {
cache . head . prev = node ;
node . next = cache . head ;
}
cache . head = node ;
return node . val ;
}
callSelector . getDependants = getDependants ;
callSelector . clear = clear ;
clear ( ) ;
return callSelector ;
} ) ;
/***/ } ) ,
2021-05-20 08:20:04 -04:00
/***/ "yyEc" :
2020-01-22 17:06:21 -05:00
/***/ ( function ( module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) {
"use strict" ;
2020-06-29 07:50:29 -04:00
// ESM COMPAT FLAG
2020-01-22 17:06:21 -05:00
_ _webpack _require _ _ . r ( _ _webpack _exports _ _ ) ;
2020-06-29 07:50:29 -04:00
// EXPORTS
2021-01-27 21:04:13 -05:00
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "store" , function ( ) { return /* reexport */ store ; } ) ;
2020-06-29 07:50:29 -04:00
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "applyFormat" , function ( ) { return /* reexport */ applyFormat ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "concat" , function ( ) { return /* reexport */ concat ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "create" , function ( ) { return /* reexport */ create ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "getActiveFormat" , function ( ) { return /* reexport */ getActiveFormat ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "getActiveObject" , function ( ) { return /* reexport */ getActiveObject ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "getTextContent" , function ( ) { return /* reexport */ getTextContent ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "__unstableIsListRootSelected" , function ( ) { return /* reexport */ isListRootSelected ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "__unstableIsActiveListType" , function ( ) { return /* reexport */ isActiveListType ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "isCollapsed" , function ( ) { return /* reexport */ isCollapsed ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "isEmpty" , function ( ) { return /* reexport */ isEmpty ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "__unstableIsEmptyLine" , function ( ) { return /* reexport */ isEmptyLine ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "join" , function ( ) { return /* reexport */ join ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "registerFormatType" , function ( ) { return /* reexport */ registerFormatType ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "removeFormat" , function ( ) { return /* reexport */ removeFormat ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "remove" , function ( ) { return /* reexport */ remove _remove ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "replace" , function ( ) { return /* reexport */ replace _replace ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "insert" , function ( ) { return /* reexport */ insert ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "__unstableInsertLineSeparator" , function ( ) { return /* reexport */ insertLineSeparator ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "__unstableRemoveLineSeparator" , function ( ) { return /* reexport */ removeLineSeparator ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "insertObject" , function ( ) { return /* reexport */ insertObject ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "slice" , function ( ) { return /* reexport */ slice ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "split" , function ( ) { return /* reexport */ split ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "__unstableToDom" , function ( ) { return /* reexport */ toDom ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "toHTMLString" , function ( ) { return /* reexport */ toHTMLString ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "toggleFormat" , function ( ) { return /* reexport */ toggleFormat ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "__UNSTABLE_LINE_SEPARATOR" , function ( ) { return /* reexport */ LINE _SEPARATOR ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "unregisterFormatType" , function ( ) { return /* reexport */ unregisterFormatType ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "__unstableCanIndentListItems" , function ( ) { return /* reexport */ canIndentListItems ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "__unstableCanOutdentListItems" , function ( ) { return /* reexport */ canOutdentListItems ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "__unstableIndentListItems" , function ( ) { return /* reexport */ indentListItems ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "__unstableOutdentListItems" , function ( ) { return /* reexport */ outdentListItems ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "__unstableChangeListType" , function ( ) { return /* reexport */ changeListType ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "__unstableCreateElement" , function ( ) { return /* reexport */ createElement ; } ) ;
2021-01-27 21:04:13 -05:00
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "useAnchorRef" , function ( ) { return /* reexport */ useAnchorRef ; } ) ;
2021-05-21 06:14:23 -04:00
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "__experimentalRichText" , function ( ) { return /* reexport */ _ _experimentalRichText ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "__unstableUseRichText" , function ( ) { return /* reexport */ useRichText ; } ) ;
2020-06-29 07:50:29 -04:00
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "__unstableFormatEdit" , function ( ) { return /* reexport */ FormatEdit ; } ) ;
// NAMESPACE OBJECT: ./node_modules/@wordpress/rich-text/build-module/store/selectors.js
2020-01-22 17:06:21 -05:00
var selectors _namespaceObject = { } ;
_ _webpack _require _ _ . r ( selectors _namespaceObject ) ;
_ _webpack _require _ _ . d ( selectors _namespaceObject , "getFormatTypes" , function ( ) { return getFormatTypes ; } ) ;
_ _webpack _require _ _ . d ( selectors _namespaceObject , "getFormatType" , function ( ) { return getFormatType ; } ) ;
_ _webpack _require _ _ . d ( selectors _namespaceObject , "getFormatTypeForBareElement" , function ( ) { return getFormatTypeForBareElement ; } ) ;
_ _webpack _require _ _ . d ( selectors _namespaceObject , "getFormatTypeForClassName" , function ( ) { return getFormatTypeForClassName ; } ) ;
2020-06-29 07:50:29 -04:00
// NAMESPACE OBJECT: ./node_modules/@wordpress/rich-text/build-module/store/actions.js
2020-01-22 17:06:21 -05:00
var actions _namespaceObject = { } ;
_ _webpack _require _ _ . r ( actions _namespaceObject ) ;
_ _webpack _require _ _ . d ( actions _namespaceObject , "addFormatTypes" , function ( ) { return addFormatTypes ; } ) ;
_ _webpack _require _ _ . d ( actions _namespaceObject , "removeFormatTypes" , function ( ) { return removeFormatTypes ; } ) ;
2021-01-27 21:04:13 -05:00
// EXTERNAL MODULE: external ["wp","data"]
2021-05-20 08:20:04 -04:00
var external _wp _data _ = _ _webpack _require _ _ ( "1ZqX" ) ;
2020-01-22 17:06:21 -05:00
2021-01-27 21:04:13 -05:00
// EXTERNAL MODULE: external "lodash"
2021-05-20 08:20:04 -04:00
var external _lodash _ = _ _webpack _require _ _ ( "YLtl" ) ;
2020-01-22 17:06:21 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/store/reducer.js
/ * *
* External dependencies
* /
/ * *
* WordPress dependencies
* /
/ * *
* Reducer managing the format types
*
* @ param { Object } state Current state .
* @ param { Object } action Dispatched action .
*
* @ return { Object } Updated state .
* /
2021-11-15 07:50:17 -05:00
function reducer _formatTypes ( ) {
let state = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : { } ;
let action = arguments . length > 1 ? arguments [ 1 ] : undefined ;
2020-01-22 17:06:21 -05:00
switch ( action . type ) {
case 'ADD_FORMAT_TYPES' :
2021-05-19 11:09:27 -04:00
return { ... state ,
... Object ( external _lodash _ [ "keyBy" ] ) ( action . formatTypes , 'name' )
} ;
2020-01-22 17:06:21 -05:00
case 'REMOVE_FORMAT_TYPES' :
2021-01-27 21:04:13 -05:00
return Object ( external _lodash _ [ "omit" ] ) ( state , action . names ) ;
2020-01-22 17:06:21 -05:00
}
return state ;
}
2021-01-27 21:04:13 -05:00
/* harmony default export */ var reducer = ( Object ( external _wp _data _ [ "combineReducers" ] ) ( {
2020-01-22 17:06:21 -05:00
formatTypes : reducer _formatTypes
} ) ) ;
// EXTERNAL MODULE: ./node_modules/rememo/es/rememo.js
2021-05-20 08:20:04 -04:00
var rememo = _ _webpack _require _ _ ( "pPDe" ) ;
2020-01-22 17:06:21 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/store/selectors.js
/ * *
* External dependencies
* /
/ * *
* Returns all the available format types .
*
* @ param { Object } state Data state .
*
* @ return { Array } Format types .
* /
2021-05-19 11:09:27 -04:00
const getFormatTypes = Object ( rememo [ "a" /* default */ ] ) ( state => Object . values ( state . formatTypes ) , state => [ state . formatTypes ] ) ;
2020-01-22 17:06:21 -05:00
/ * *
* Returns a format type by name .
*
* @ param { Object } state Data state .
2021-11-08 09:29:21 -05:00
* @ param { string } name Format type name .
2020-01-22 17:06:21 -05:00
*
* @ return { Object ? } Format type .
* /
function getFormatType ( state , name ) {
return state . formatTypes [ name ] ;
}
/ * *
* Gets the format type , if any , that can handle a bare element ( without a
* data - format - type attribute ) , given the tag name of this element .
*
* @ param { Object } state Data state .
* @ param { string } bareElementTagName The tag name of the element to find a
* format type for .
* @ return { ? Object } Format type .
* /
function getFormatTypeForBareElement ( state , bareElementTagName ) {
2021-11-15 07:50:17 -05:00
return Object ( external _lodash _ [ "find" ] ) ( getFormatTypes ( state ) , _ref => {
let {
className ,
tagName
} = _ref ;
2020-01-22 17:06:21 -05:00
return className === null && bareElementTagName === tagName ;
} ) ;
}
/ * *
* Gets the format type , if any , that can handle an element , given its classes .
*
* @ param { Object } state Data state .
* @ param { string } elementClassName The classes of the element to find a format
* type for .
* @ return { ? Object } Format type .
* /
function getFormatTypeForClassName ( state , elementClassName ) {
2021-11-15 07:50:17 -05:00
return Object ( external _lodash _ [ "find" ] ) ( getFormatTypes ( state ) , _ref2 => {
let {
className
} = _ref2 ;
2020-01-22 17:06:21 -05:00
if ( className === null ) {
return false ;
}
2021-05-19 11:09:27 -04:00
return ` ${ elementClassName } ` . indexOf ( ` ${ className } ` ) >= 0 ;
2020-01-22 17:06:21 -05:00
} ) ;
}
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/store/actions.js
/ * *
* External dependencies
* /
/ * *
* Returns an action object used in signalling that format types have been
* added .
*
* @ param { Array | Object } formatTypes Format types received .
*
* @ return { Object } Action object .
* /
function addFormatTypes ( formatTypes ) {
return {
type : 'ADD_FORMAT_TYPES' ,
2021-01-27 21:04:13 -05:00
formatTypes : Object ( external _lodash _ [ "castArray" ] ) ( formatTypes )
2020-01-22 17:06:21 -05:00
} ;
}
/ * *
* Returns an action object used to remove a registered format type .
*
* @ param { string | Array } names Format name .
*
* @ return { Object } Action object .
* /
2019-03-07 04:09:59 -05:00
function removeFormatTypes ( names ) {
2018-12-17 22:14:52 -05:00
return {
type : 'REMOVE_FORMAT_TYPES' ,
2021-01-27 21:04:13 -05:00
names : Object ( external _lodash _ [ "castArray" ] ) ( names )
2018-12-17 22:14:52 -05:00
} ;
}
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/store/index.js
2018-12-14 06:02:53 -05:00
/ * *
2018-12-16 23:52:00 -05:00
* WordPress dependencies
2018-12-14 06:02:53 -05:00
* /
2018-12-13 23:41:57 -05:00
/ * *
* Internal dependencies
* /
2018-12-14 06:02:53 -05:00
2021-05-19 11:09:27 -04:00
const STORE _NAME = 'core/rich-text' ;
2021-01-27 21:04:13 -05:00
/ * *
* Store definition for the rich - text namespace .
*
2021-02-02 00:17:13 -05:00
* @ see https : //github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
2021-01-27 21:04:13 -05:00
*
* @ type { Object }
* /
2021-05-19 11:09:27 -04:00
const store = Object ( external _wp _data _ [ "createReduxStore" ] ) ( STORE _NAME , {
2018-12-17 22:14:52 -05:00
reducer : reducer ,
selectors : selectors _namespaceObject ,
actions : actions _namespaceObject
} ) ;
2021-01-27 21:04:13 -05:00
Object ( external _wp _data _ [ "register" ] ) ( store ) ;
2018-12-14 06:02:53 -05:00
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/is-format-equal.js
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextFormat} RichTextFormat */
2018-12-13 23:41:57 -05:00
/ * *
2018-12-17 22:14:52 -05:00
* Optimised equality check for format objects .
*
2020-10-13 09:10:30 -04:00
* @ param { ? RichTextFormat } format1 Format to compare .
* @ param { ? RichTextFormat } format2 Format to compare .
2018-12-17 22:14:52 -05:00
*
* @ return { boolean } True if formats are equal , false if not .
2018-12-13 23:41:57 -05:00
* /
2018-12-17 22:14:52 -05:00
function isFormatEqual ( format1 , format2 ) {
// Both not defined.
if ( format1 === format2 ) {
return true ;
} // Either not defined.
2018-12-13 23:41:57 -05:00
2018-12-14 06:02:53 -05:00
2018-12-17 22:14:52 -05:00
if ( ! format1 || ! format2 ) {
return false ;
2018-12-14 06:02:53 -05:00
}
2018-12-17 22:14:52 -05:00
if ( format1 . type !== format2 . type ) {
return false ;
}
2018-12-16 23:52:00 -05:00
2021-05-19 11:09:27 -04:00
const attributes1 = format1 . attributes ;
const attributes2 = format2 . attributes ; // Both not defined.
2018-12-16 23:52:00 -05:00
2018-12-17 22:14:52 -05:00
if ( attributes1 === attributes2 ) {
return true ;
} // Either not defined.
2018-12-16 23:52:00 -05:00
2018-12-17 22:14:52 -05:00
if ( ! attributes1 || ! attributes2 ) {
return false ;
2018-12-16 23:52:00 -05:00
}
2018-12-14 06:02:53 -05:00
2021-05-19 11:09:27 -04:00
const keys1 = Object . keys ( attributes1 ) ;
const keys2 = Object . keys ( attributes2 ) ;
2018-12-14 06:02:53 -05:00
2018-12-17 22:14:52 -05:00
if ( keys1 . length !== keys2 . length ) {
return false ;
2018-12-14 06:02:53 -05:00
}
2021-05-19 11:09:27 -04:00
const length = keys1 . length ; // Optimise for speed.
2018-12-14 06:02:53 -05:00
2021-05-19 11:09:27 -04:00
for ( let i = 0 ; i < length ; i ++ ) {
const name = keys1 [ i ] ;
2018-12-14 06:02:53 -05:00
2018-12-17 22:14:52 -05:00
if ( attributes1 [ name ] !== attributes2 [ name ] ) {
return false ;
2018-12-14 06:02:53 -05:00
}
}
2018-12-17 22:14:52 -05:00
return true ;
2018-12-14 06:02:53 -05:00
}
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/normalise-formats.js
2018-12-13 23:41:57 -05:00
/ * *
2018-12-17 22:14:52 -05:00
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
2018-12-17 22:14:52 -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
* Normalises formats : ensures subsequent adjacent equal formats have the same
* reference .
2018-12-13 23:41:57 -05:00
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value Value to normalise formats of .
2018-12-13 23:41:57 -05:00
*
2020-10-13 09:10:30 -04:00
* @ return { RichTextValue } New value with normalised formats .
2018-12-13 23:41:57 -05:00
* /
2019-03-21 08:48:00 -04:00
function normaliseFormats ( value ) {
2021-05-19 11:09:27 -04:00
const newFormats = value . formats . slice ( ) ;
newFormats . forEach ( ( formatsAtIndex , index ) => {
const formatsAtPreviousIndex = newFormats [ index - 1 ] ;
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 ( formatsAtPreviousIndex ) {
2021-05-19 11:09:27 -04:00
const newFormatsAtIndex = formatsAtIndex . slice ( ) ;
newFormatsAtIndex . forEach ( ( format , formatIndex ) => {
const previousFormat = formatsAtPreviousIndex [ formatIndex ] ;
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 ( isFormatEqual ( format , previousFormat ) ) {
newFormatsAtIndex [ formatIndex ] = previousFormat ;
}
} ) ;
newFormats [ index ] = newFormatsAtIndex ;
}
2018-12-17 22:14:52 -05:00
} ) ;
2021-05-19 11:09:27 -04:00
return { ... value ,
2019-03-21 08:48:00 -04:00
formats : newFormats
2021-05-19 11:09:27 -04:00
} ;
2018-12-17 22:14:52 -05:00
}
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/apply-format.js
/ * *
* External dependencies
* /
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
/ * *
* Internal dependencies
* /
2018-12-13 23:41:57 -05:00
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
/** @typedef {import('./create').RichTextFormat} RichTextFormat */
2019-09-19 11:19:18 -04:00
function replace ( array , index , value ) {
array = array . slice ( ) ;
array [ index ] = value ;
return array ;
}
2018-12-13 23:41:57 -05:00
/ * *
2018-12-17 22:14:52 -05:00
* Apply a format object to a Rich Text value from the given ` startIndex ` to the
* given ` endIndex ` . Indices are retrieved from the selection if none are
* provided .
2018-12-13 23:41:57 -05:00
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value Value to modify .
* @ param { RichTextFormat } format Format to apply .
* @ param { number } [ startIndex ] Start index .
* @ param { number } [ endIndex ] End index .
2018-12-17 22:14:52 -05:00
*
2020-10-13 09:10:30 -04:00
* @ return { RichTextValue } A new value with the format applied .
2018-12-13 23:41:57 -05:00
* /
2019-09-19 11:19:18 -04:00
2021-11-15 07:50:17 -05:00
function applyFormat ( value , format ) {
let startIndex = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : value . start ;
let endIndex = arguments . length > 3 && arguments [ 3 ] !== undefined ? arguments [ 3 ] : value . end ;
2021-05-19 11:09:27 -04:00
const {
formats ,
activeFormats
} = value ;
const newFormats = formats . slice ( ) ; // The selection is collapsed.
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
if ( startIndex === endIndex ) {
2021-05-19 11:09:27 -04:00
const startFormat = Object ( external _lodash _ [ "find" ] ) ( newFormats [ startIndex ] , {
2018-12-17 22:14:52 -05:00
type : format . type
} ) ; // If the caret is at a format of the same type, expand start and end to
// the edges of the format. This is useful to apply new attributes.
2018-12-14 06:02:53 -05:00
2018-12-17 22:14:52 -05:00
if ( startFormat ) {
2021-05-19 11:09:27 -04:00
const index = newFormats [ startIndex ] . indexOf ( startFormat ) ;
2019-09-19 11:19:18 -04:00
while ( newFormats [ startIndex ] && newFormats [ startIndex ] [ index ] === startFormat ) {
newFormats [ startIndex ] = replace ( newFormats [ startIndex ] , index , format ) ;
2018-12-17 22:14:52 -05:00
startIndex -- ;
2018-12-13 23:41:57 -05:00
}
2018-12-17 22:14:52 -05:00
endIndex ++ ;
2018-12-13 23:41:57 -05:00
2019-09-19 11:19:18 -04:00
while ( newFormats [ endIndex ] && newFormats [ endIndex ] [ index ] === startFormat ) {
newFormats [ endIndex ] = replace ( newFormats [ endIndex ] , index , format ) ;
2018-12-17 22:14:52 -05:00
endIndex ++ ;
2019-05-16 14:08:00 -04:00
}
2018-12-17 22:14:52 -05:00
}
} else {
2019-09-19 11:19:18 -04:00
// Determine the highest position the new format can be inserted at.
2021-05-19 11:09:27 -04:00
let position = + Infinity ;
2019-09-19 11:19:18 -04:00
2021-05-19 11:09:27 -04:00
for ( let index = startIndex ; index < endIndex ; index ++ ) {
if ( newFormats [ index ] ) {
2021-11-15 07:50:17 -05:00
newFormats [ index ] = newFormats [ index ] . filter ( _ref => {
let {
type
} = _ref ;
return type !== format . type ;
} ) ;
2021-05-19 11:09:27 -04:00
const length = newFormats [ index ] . length ;
2019-09-19 11:19:18 -04:00
if ( length < position ) {
position = length ;
}
} else {
2021-05-19 11:09:27 -04:00
newFormats [ index ] = [ ] ;
2019-09-19 11:19:18 -04:00
position = 0 ;
}
}
2021-05-19 11:09:27 -04:00
for ( let index = startIndex ; index < endIndex ; index ++ ) {
newFormats [ index ] . splice ( position , 0 , format ) ;
2018-12-13 23:41:57 -05:00
}
}
2021-05-19 11:09:27 -04:00
return normaliseFormats ( { ... value ,
2019-05-16 14:08:00 -04:00
formats : newFormats ,
// Always revise active formats. This serves as a placeholder for new
// inputs with the format so new input appears with the format applied,
// and ensures a format of the same type uses the latest values.
2021-05-19 11:09:27 -04:00
activeFormats : [ ... Object ( external _lodash _ [ "reject" ] ) ( activeFormats , {
2019-05-16 14:08:00 -04:00
type : format . type
2021-05-19 11:09:27 -04:00
} ) , format ]
} ) ;
2018-12-13 23:41:57 -05:00
}
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/create-element.js
2018-12-15 06:00:40 -05:00
/ * *
2018-12-17 22:14:52 -05:00
* Parse the given HTML into a body element .
2018-12-15 06:00:40 -05:00
*
2018-12-18 22:16:48 -05:00
* Note : The current implementation will return a shared reference , reset on
* each call to ` createElement ` . Therefore , you should not hold a reference to
* the value to operate upon asynchronously , as it may have unexpected results .
*
2018-12-17 22:14:52 -05:00
* @ param { HTMLDocument } document The HTML document to use to parse .
* @ param { string } html The HTML to parse .
2018-12-15 06:00:40 -05:00
*
2018-12-17 22:14:52 -05:00
* @ return { HTMLBodyElement } Body element with parsed HTML .
2018-12-15 06:00:40 -05:00
* /
2021-11-15 07:50:17 -05:00
function createElement ( _ref , html ) {
let {
implementation
} = _ref ;
2018-12-18 22:16:48 -05:00
// Because `createHTMLDocument` is an expensive operation, and with this
// function being internal to `rich-text` (full control in avoiding a risk
// of asynchronous operations on the shared reference), a single document
// is reused and reset for each call to the function.
if ( ! createElement . body ) {
createElement . body = implementation . createHTMLDocument ( '' ) . body ;
}
2018-12-17 22:14:52 -05:00
2018-12-18 22:16:48 -05:00
createElement . body . innerHTML = html ;
return createElement . body ;
2018-12-15 06:00:40 -05:00
}
2019-03-21 08:48:00 -04:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/special-characters.js
/ * *
2019-09-19 11:19:18 -04:00
* Line separator character , used for multiline text .
2019-03-21 08:48:00 -04:00
* /
2021-05-19 11:09:27 -04:00
const LINE _SEPARATOR = '\u2028' ;
2019-09-19 11:19:18 -04:00
/ * *
* Object replacement character , used as a placeholder for objects .
* /
2021-05-19 11:09:27 -04:00
const OBJECT _REPLACEMENT _CHARACTER = '\ufffc' ;
2019-09-19 11:19:18 -04:00
/ * *
* Zero width non - breaking space , used as padding in the editable DOM tree when
* it is empty otherwise .
* /
2021-05-19 11:09:27 -04:00
const ZWNBSP = '\ufeff' ;
2019-03-21 08:48:00 -04:00
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/create.js
2018-12-15 06:00:40 -05:00
/ * *
2018-12-17 22:14:52 -05:00
* WordPress dependencies
2018-12-15 06:00:40 -05:00
* /
2018-12-13 23:41:57 -05:00
/ * *
2018-12-17 22:14:52 -05:00
* Internal dependencies
2018-12-13 23:41:57 -05:00
* /
2018-12-14 06:02:53 -05:00
2020-10-13 09:10:30 -04:00
/ * *
* @ typedef { Object } RichTextFormat
*
* @ property { string } type Format type .
* /
/ * *
* @ typedef { Array < RichTextFormat > } RichTextFormatList
* /
/ * *
* @ typedef { Object } RichTextValue
*
* @ property { string } text Text .
* @ property { Array < RichTextFormatList > } formats Formats .
* @ property { Array < RichTextFormat > } replacements Replacements .
* @ property { number | undefined } start Selection start .
* @ property { number | undefined } end Selection end .
* /
2018-12-14 06:02:53 -05:00
2018-12-17 22:14:52 -05:00
function createEmptyValue ( ) {
return {
formats : [ ] ,
2019-03-21 08:48:00 -04:00
replacements : [ ] ,
2018-12-17 22:14:52 -05:00
text : ''
} ;
}
2018-12-14 06:02:53 -05:00
2021-11-15 07:50:17 -05:00
function toFormat ( _ref ) {
let {
type ,
attributes
} = _ref ;
2021-05-19 11:09:27 -04:00
let formatType ;
2018-12-15 06:00:40 -05:00
2018-12-17 22:14:52 -05:00
if ( attributes && attributes . class ) {
2021-11-08 09:29:21 -05:00
formatType = Object ( external _wp _data _ [ "select" ] ) ( store ) . getFormatTypeForClassName ( attributes . class ) ;
2018-12-15 06:00:40 -05:00
2018-12-17 22:14:52 -05:00
if ( formatType ) {
// Preserve any additional classes.
2021-05-19 11:09:27 -04:00
attributes . class = ` ${ attributes . class } ` . replace ( ` ${ formatType . className } ` , ' ' ) . trim ( ) ;
2018-12-15 06:00:40 -05:00
2018-12-17 22:14:52 -05:00
if ( ! attributes . class ) {
delete attributes . class ;
}
}
}
2018-12-15 06:00:40 -05:00
2018-12-17 22:14:52 -05:00
if ( ! formatType ) {
2021-11-08 09:29:21 -05:00
formatType = Object ( external _wp _data _ [ "select" ] ) ( store ) . getFormatTypeForBareElement ( type ) ;
2018-12-17 22:14:52 -05:00
}
2018-12-15 06:00:40 -05:00
2018-12-17 22:14:52 -05:00
if ( ! formatType ) {
return attributes ? {
2021-05-19 11:09:27 -04:00
type ,
attributes
2018-12-17 22:14:52 -05:00
} : {
2021-05-19 11:09:27 -04:00
type
2018-12-17 22:14:52 -05:00
} ;
}
2018-12-15 06:00:40 -05:00
2019-03-21 08:48:00 -04:00
if ( formatType . _ _experimentalCreatePrepareEditableTree && ! formatType . _ _experimentalCreateOnChangeEditableValue ) {
return null ;
}
2018-12-17 22:14:52 -05:00
if ( ! attributes ) {
return {
type : formatType . name
} ;
}
2018-12-15 06:00:40 -05:00
2021-05-19 11:09:27 -04:00
const registeredAttributes = { } ;
const unregisteredAttributes = { } ;
2021-11-08 09:29:21 -05:00
const _attributes = { ... attributes
} ;
2018-12-15 06:00:40 -05:00
2021-11-08 09:29:21 -05:00
for ( const key in formatType . attributes ) {
const name = formatType . attributes [ key ] ;
registeredAttributes [ key ] = _attributes [ name ] ;
2018-12-13 23:41:57 -05:00
2021-11-08 09:29:21 -05:00
if ( formatType . _ _unstableFilterAttributeValue ) {
registeredAttributes [ key ] = formatType . _ _unstableFilterAttributeValue ( key , registeredAttributes [ key ] ) ;
} // delete the attribute and what's left is considered
// to be unregistered.
delete _attributes [ name ] ;
if ( typeof registeredAttributes [ key ] === 'undefined' ) {
delete registeredAttributes [ key ] ;
2018-12-17 22:14:52 -05:00
}
}
2018-12-13 23:41:57 -05:00
2021-11-08 09:29:21 -05:00
for ( const name in _attributes ) {
unregisteredAttributes [ name ] = attributes [ name ] ;
}
2018-12-17 22:14:52 -05:00
return {
type : formatType . name ,
attributes : registeredAttributes ,
2021-05-19 11:09:27 -04:00
unregisteredAttributes
2018-12-17 22:14:52 -05:00
} ;
}
/ * *
* Create a RichText value from an ` Element ` tree ( DOM ) , an HTML string or a
* plain text string , with optionally a ` Range ` object to set the selection . If
* called without any input , an empty value will be created . If
* ` multilineTag ` is provided , any content of direct children whose type matches
* ` multilineTag ` will be separated by two newlines . The optional functions can
* be used to filter out content .
*
2019-03-21 08:48:00 -04:00
* A value will have the following shape , which you are strongly encouraged not
* to modify without the use of helper functions :
*
* ` ` ` js
* {
* text : string ,
* formats : Array ,
* replacements : Array ,
* ? start : number ,
* ? end : number ,
* }
* ` ` `
*
* As you can see , text and formatting are separated . ` text ` holds the text ,
* including any replacement characters for objects and lines . ` formats ` ,
* ` objects ` and ` lines ` are all sparse arrays of the same length as ` text ` . It
* holds information about the formatting at the relevant text indices . Finally
* ` start ` and ` end ` state which text indices are selected . They are only
* provided if a ` Range ` was given .
*
2021-11-08 09:29:21 -05:00
* @ param { Object } [ $1 ] Optional named arguments .
* @ param { Element } [ $1 . element ] Element to create value from .
* @ param { string } [ $1 . text ] Text to create value from .
* @ param { string } [ $1 . html ] HTML to create value from .
* @ param { Range } [ $1 . range ] Range to create value from .
* @ param { string } [ $1 . multilineTag ] Multiline tag if the structure is
* multiline .
* @ param { Array } [ $1 . multilineWrapperTags ] Tags where lines can be found if
* nesting is possible .
* @ param { boolean } [ $1 . preserveWhiteSpace ] Whether or not to collapse white
* space characters .
2020-10-13 09:10:30 -04:00
* @ param { boolean } [ $1 . _ _unstableIsEditableTree ]
2018-12-17 22:14:52 -05:00
*
2020-10-13 09:10:30 -04:00
* @ return { RichTextValue } A rich text value .
2018-12-17 22:14:52 -05:00
* /
2018-12-13 23:41:57 -05:00
2021-11-15 07:50:17 -05:00
function create ( ) {
let {
element ,
text ,
html ,
range ,
multilineTag ,
multilineWrapperTags ,
_ _unstableIsEditableTree : isEditableTree ,
preserveWhiteSpace
} = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : { } ;
2018-12-17 22:14:52 -05:00
if ( typeof text === 'string' && text . length > 0 ) {
return {
formats : Array ( text . length ) ,
2019-03-21 08:48:00 -04:00
replacements : Array ( text . length ) ,
2021-05-19 11:09:27 -04:00
text
2018-12-17 22:14:52 -05:00
} ;
}
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
if ( typeof html === 'string' && html . length > 0 ) {
2020-06-26 09:33:47 -04:00
// It does not matter which document this is, we're just using it to
// parse.
2018-12-17 22:14:52 -05:00
element = createElement ( document , html ) ;
}
2018-12-13 23:41:57 -05:00
2021-05-19 11:09:27 -04:00
if ( typeof element !== 'object' ) {
2018-12-17 22:14:52 -05:00
return createEmptyValue ( ) ;
}
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
if ( ! multilineTag ) {
return createFromElement ( {
2021-05-19 11:09:27 -04:00
element ,
range ,
isEditableTree ,
preserveWhiteSpace
2018-12-17 22:14:52 -05:00
} ) ;
}
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
return createFromMultilineElement ( {
2021-05-19 11:09:27 -04:00
element ,
range ,
multilineTag ,
multilineWrapperTags ,
isEditableTree ,
preserveWhiteSpace
2018-12-17 22:14:52 -05:00
} ) ;
}
/ * *
* Helper to accumulate the value ' s selection start and end from the current
* node and range .
*
* @ param { Object } accumulator Object to accumulate into .
* @ param { Node } node Node to create value with .
* @ param { Range } range Range to create value with .
* @ param { Object } value Value that is being accumulated .
* /
2018-12-14 06:02:53 -05:00
2018-12-17 22:14:52 -05:00
function accumulateSelection ( accumulator , node , range , value ) {
if ( ! range ) {
return ;
}
2018-12-14 06:02:53 -05:00
2021-05-19 11:09:27 -04:00
const {
parentNode
} = node ;
const {
startContainer ,
startOffset ,
endContainer ,
endOffset
} = range ;
const currentLength = accumulator . text . length ; // Selection can be extracted from value.
2018-12-14 06:02:53 -05:00
2018-12-17 22:14:52 -05:00
if ( value . start !== undefined ) {
accumulator . start = currentLength + value . start ; // Range indicates that the current node has selection.
2020-06-26 09:33:47 -04:00
} else if ( node === startContainer && node . nodeType === node . TEXT _NODE ) {
2018-12-17 22:14:52 -05:00
accumulator . start = currentLength + startOffset ; // Range indicates that the current node is selected.
} else if ( parentNode === startContainer && node === startContainer . childNodes [ startOffset ] ) {
accumulator . start = currentLength ; // Range indicates that the selection is after the current node.
} else if ( parentNode === startContainer && node === startContainer . childNodes [ startOffset - 1 ] ) {
accumulator . start = currentLength + value . text . length ; // Fallback if no child inside handled the selection.
} else if ( node === startContainer ) {
accumulator . start = currentLength ;
} // Selection can be extracted from value.
2018-12-14 06:02:53 -05:00
2018-12-17 22:14:52 -05:00
if ( value . end !== undefined ) {
accumulator . end = currentLength + value . end ; // Range indicates that the current node has selection.
2020-06-26 09:33:47 -04:00
} else if ( node === endContainer && node . nodeType === node . TEXT _NODE ) {
2018-12-17 22:14:52 -05:00
accumulator . end = currentLength + endOffset ; // Range indicates that the current node is selected.
} else if ( parentNode === endContainer && node === endContainer . childNodes [ endOffset - 1 ] ) {
accumulator . end = currentLength + value . text . length ; // Range indicates that the selection is before the current node.
} else if ( parentNode === endContainer && node === endContainer . childNodes [ endOffset ] ) {
accumulator . end = currentLength ; // Fallback if no child inside handled the selection.
} else if ( node === endContainer ) {
accumulator . end = currentLength + endOffset ;
}
}
/ * *
* Adjusts the start and end offsets from a range based on a text filter .
*
* @ param { Node } node Node of which the text should be filtered .
* @ param { Range } range The range to filter .
* @ param { Function } filter Function to use to filter the text .
*
2020-10-13 09:10:30 -04:00
* @ return { Object | void } Object containing range properties .
2018-12-17 22:14:52 -05:00
* /
2018-12-14 06:02:53 -05:00
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
function filterRange ( node , range , filter ) {
if ( ! range ) {
return ;
}
2018-12-13 23:41:57 -05:00
2021-05-19 11:09:27 -04:00
const {
startContainer ,
endContainer
} = range ;
let {
startOffset ,
endOffset
} = range ;
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
if ( node === startContainer ) {
startOffset = filter ( node . nodeValue . slice ( 0 , startOffset ) ) . length ;
}
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
if ( node === endContainer ) {
endOffset = filter ( node . nodeValue . slice ( 0 , endOffset ) ) . length ;
}
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
return {
2021-05-19 11:09:27 -04:00
startContainer ,
startOffset ,
endContainer ,
endOffset
2018-12-17 22:14:52 -05:00
} ;
}
2020-01-08 06:57:23 -05:00
/ * *
* Collapse any whitespace used for HTML formatting to one space character ,
* because it will also be displayed as such by the browser .
*
* @ param { string } string
* /
function collapseWhiteSpace ( string ) {
return string . replace ( /[\n\r\t]+/g , ' ' ) ;
}
/ * *
2021-11-08 09:29:21 -05:00
* Removes reserved characters used by rich - text ( zero width non breaking spaces added by ` toTree ` and object replacement characters ) .
2020-01-08 06:57:23 -05:00
*
* @ param { string } string
* /
2019-09-19 11:19:18 -04:00
2021-11-08 09:29:21 -05:00
function removeReservedCharacters ( string ) {
//with the global flag, note that we should create a new regex each time OR reset lastIndex state.
return string . replace ( new RegExp ( ` [ ${ ZWNBSP } ${ OBJECT _REPLACEMENT _CHARACTER } ] ` , 'gu' ) , '' ) ;
2019-03-07 04:09:59 -05:00
}
2018-12-17 22:14:52 -05:00
/ * *
* Creates a Rich Text value from a DOM element and range .
*
2020-10-13 09:10:30 -04:00
* @ param { Object } $1 Named argements .
* @ param { Element } [ $1 . element ] Element to create value from .
* @ param { Range } [ $1 . range ] Range to create value from .
* @ param { string } [ $1 . multilineTag ] Multiline tag if the structure is
2018-12-17 22:14:52 -05:00
* multiline .
2020-10-13 09:10:30 -04:00
* @ param { Array } [ $1 . multilineWrapperTags ] Tags where lines can be found if
2018-12-17 22:14:52 -05:00
* nesting is possible .
2020-10-13 09:10:30 -04:00
* @ param { boolean } [ $1 . preserveWhiteSpace ] Whether or not to collapse white
2020-01-08 06:57:23 -05:00
* space characters .
2020-10-13 09:10:30 -04:00
* @ param { Array } [ $1 . currentWrapperTags ]
* @ param { boolean } [ $1 . isEditableTree ]
2018-12-17 22:14:52 -05:00
*
2020-10-13 09:10:30 -04:00
* @ return { RichTextValue } A rich text value .
2018-12-17 22:14:52 -05:00
* /
2018-12-13 23:41:57 -05:00
2021-11-15 07:50:17 -05:00
function createFromElement ( _ref2 ) {
let {
element ,
range ,
multilineTag ,
multilineWrapperTags ,
currentWrapperTags = [ ] ,
isEditableTree ,
preserveWhiteSpace
} = _ref2 ;
2021-05-19 11:09:27 -04:00
const accumulator = createEmptyValue ( ) ;
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
if ( ! element ) {
return accumulator ;
}
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
if ( ! element . hasChildNodes ( ) ) {
accumulateSelection ( accumulator , element , range , createEmptyValue ( ) ) ;
return accumulator ;
}
2018-12-13 23:41:57 -05:00
2021-05-19 11:09:27 -04:00
const length = element . childNodes . length ; // Optimise for speed.
2018-12-13 23:41:57 -05:00
2021-05-19 11:09:27 -04:00
for ( let index = 0 ; index < length ; index ++ ) {
const node = element . childNodes [ index ] ;
const type = node . nodeName . toLowerCase ( ) ;
2018-12-13 23:41:57 -05:00
2020-06-26 09:33:47 -04:00
if ( node . nodeType === node . TEXT _NODE ) {
2021-11-08 09:29:21 -05:00
let filter = removeReservedCharacters ;
2020-01-08 06:57:23 -05:00
if ( ! preserveWhiteSpace ) {
2021-11-08 09:29:21 -05:00
filter = string => removeReservedCharacters ( collapseWhiteSpace ( string ) ) ;
2020-01-08 06:57:23 -05:00
}
2021-05-19 11:09:27 -04:00
const text = filter ( node . nodeValue ) ;
2020-01-08 06:57:23 -05:00
range = filterRange ( node , range , filter ) ;
2018-12-17 22:14:52 -05:00
accumulateSelection ( accumulator , node , range , {
2021-05-19 11:09:27 -04:00
text
2019-03-21 08:48:00 -04:00
} ) ; // Create a sparse array of the same length as `text`, in which
2018-12-17 22:14:52 -05:00
// formats can be added.
2018-12-13 23:41:57 -05:00
2019-03-21 08:48:00 -04:00
accumulator . formats . length += text . length ;
accumulator . replacements . length += text . length ;
accumulator . text += text ;
2021-05-19 11:09:27 -04:00
continue ;
2018-12-17 22:14:52 -05:00
}
2018-12-13 23:41:57 -05:00
2020-06-26 09:33:47 -04:00
if ( node . nodeType !== node . ELEMENT _NODE ) {
2021-05-19 11:09:27 -04:00
continue ;
2018-12-17 22:14:52 -05:00
}
2018-12-13 23:41:57 -05:00
2019-09-19 11:19:18 -04:00
if ( isEditableTree && ( // Ignore any placeholders.
node . getAttribute ( 'data-rich-text-placeholder' ) || // Ignore any line breaks that are not inserted by us.
type === 'br' && ! node . getAttribute ( 'data-rich-text-line-break' ) ) ) {
2018-12-17 22:14:52 -05:00
accumulateSelection ( accumulator , node , range , createEmptyValue ( ) ) ;
2021-05-19 11:09:27 -04:00
continue ;
2018-12-17 22:14:52 -05:00
}
2018-12-13 23:41:57 -05:00
2021-07-13 19:58:30 -04:00
if ( type === 'script' ) {
const value = {
formats : [ , ] ,
replacements : [ {
type ,
attributes : {
'data-rich-text-script' : node . getAttribute ( 'data-rich-text-script' ) || encodeURIComponent ( node . innerHTML )
}
} ] ,
text : OBJECT _REPLACEMENT _CHARACTER
} ;
accumulateSelection ( accumulator , node , range , value ) ;
mergePair ( accumulator , value ) ;
continue ;
}
2018-12-17 22:14:52 -05:00
if ( type === 'br' ) {
accumulateSelection ( accumulator , node , range , createEmptyValue ( ) ) ;
2019-03-21 08:48:00 -04:00
mergePair ( accumulator , create ( {
text : '\n'
} ) ) ;
2021-05-19 11:09:27 -04:00
continue ;
2018-12-17 22:14:52 -05:00
}
2018-12-13 23:41:57 -05:00
2021-11-08 09:29:21 -05:00
const format = toFormat ( {
2021-05-19 11:09:27 -04:00
type ,
2019-03-07 04:09:59 -05:00
attributes : getAttributes ( {
element : node
} )
} ) ;
2018-12-17 22:14:52 -05:00
if ( multilineWrapperTags && multilineWrapperTags . indexOf ( type ) !== - 1 ) {
2021-05-19 11:09:27 -04:00
const value = createFromMultilineElement ( {
2018-12-17 22:14:52 -05:00
element : node ,
2021-05-19 11:09:27 -04:00
range ,
multilineTag ,
multilineWrapperTags ,
currentWrapperTags : [ ... currentWrapperTags , format ] ,
isEditableTree ,
preserveWhiteSpace
2018-12-17 22:14:52 -05:00
} ) ;
2021-05-19 11:09:27 -04:00
accumulateSelection ( accumulator , node , range , value ) ;
mergePair ( accumulator , value ) ;
continue ;
2018-12-17 22:14:52 -05:00
}
2018-12-15 06:00:40 -05:00
2021-05-19 11:09:27 -04:00
const value = createFromElement ( {
2019-03-21 08:48:00 -04:00
element : node ,
2021-05-19 11:09:27 -04:00
range ,
multilineTag ,
multilineWrapperTags ,
isEditableTree ,
preserveWhiteSpace
2019-03-21 08:48:00 -04:00
} ) ;
accumulateSelection ( accumulator , node , range , value ) ;
2018-12-15 06:00:40 -05:00
2019-03-21 08:48:00 -04:00
if ( ! format ) {
mergePair ( accumulator , value ) ;
} else if ( value . text . length === 0 ) {
if ( format . attributes ) {
mergePair ( accumulator , {
formats : [ , ] ,
replacements : [ format ] ,
text : OBJECT _REPLACEMENT _CHARACTER
} ) ;
2018-12-17 22:14:52 -05:00
}
} else {
2020-01-22 17:06:21 -05:00
// Indices should share a reference to the same formats array.
// Only create a new reference if `formats` changes.
2020-02-06 16:03:31 -05:00
function mergeFormats ( formats ) {
2020-01-22 17:06:21 -05:00
if ( mergeFormats . formats === formats ) {
return mergeFormats . newFormats ;
}
2021-05-19 11:09:27 -04:00
const newFormats = formats ? [ format , ... formats ] : [ format ] ;
2020-01-22 17:06:21 -05:00
mergeFormats . formats = formats ;
mergeFormats . newFormats = newFormats ;
return newFormats ;
2020-02-06 16:03:31 -05:00
} // Since the formats parameter can be `undefined`, preset
2020-01-22 17:06:21 -05:00
// `mergeFormats` with a new reference.
mergeFormats . newFormats = [ format ] ;
2021-05-19 11:09:27 -04:00
mergePair ( accumulator , { ... value ,
2020-01-22 17:06:21 -05:00
formats : Array . from ( value . formats , mergeFormats )
2021-05-19 11:09:27 -04:00
} ) ;
2019-03-21 08:48:00 -04:00
}
2018-12-15 06:00:40 -05:00
}
2018-12-17 22:14:52 -05:00
return accumulator ;
2018-12-15 06:00:40 -05:00
}
2018-12-14 06:02:53 -05:00
/ * *
2018-12-17 22:14:52 -05:00
* Creates a rich text value from a DOM element and range that should be
* multiline .
2018-12-14 06:02:53 -05:00
*
2020-10-13 09:10:30 -04:00
* @ param { Object } $1 Named argements .
* @ param { Element } [ $1 . element ] Element to create value from .
* @ param { Range } [ $1 . range ] Range to create value from .
* @ param { string } [ $1 . multilineTag ] Multiline tag if the structure is
* multiline .
* @ param { Array } [ $1 . multilineWrapperTags ] Tags where lines can be found if
* nesting is possible .
2021-11-08 09:29:21 -05:00
* @ param { Array } [ $1 . currentWrapperTags ] Whether to prepend a line
2020-10-13 09:10:30 -04:00
* separator .
* @ param { boolean } [ $1 . preserveWhiteSpace ] Whether or not to collapse white
* space characters .
* @ param { boolean } [ $1 . isEditableTree ]
2018-12-14 06:02:53 -05:00
*
2020-10-13 09:10:30 -04:00
* @ return { RichTextValue } A rich text value .
2018-12-14 06:02:53 -05:00
* /
2018-12-13 23:41:57 -05:00
2021-11-15 07:50:17 -05:00
function createFromMultilineElement ( _ref3 ) {
let {
element ,
range ,
multilineTag ,
multilineWrapperTags ,
currentWrapperTags = [ ] ,
isEditableTree ,
preserveWhiteSpace
} = _ref3 ;
2021-05-19 11:09:27 -04:00
const accumulator = createEmptyValue ( ) ;
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
if ( ! element || ! element . hasChildNodes ( ) ) {
return accumulator ;
}
2018-12-13 23:41:57 -05:00
2021-05-19 11:09:27 -04:00
const length = element . children . length ; // Optimise for speed.
2018-12-13 23:41:57 -05:00
2021-05-19 11:09:27 -04:00
for ( let index = 0 ; index < length ; index ++ ) {
const node = element . children [ index ] ;
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
if ( node . nodeName . toLowerCase ( ) !== multilineTag ) {
continue ;
}
2018-12-13 23:41:57 -05:00
2021-05-19 11:09:27 -04:00
const value = createFromElement ( {
2018-12-17 22:14:52 -05:00
element : node ,
2021-05-19 11:09:27 -04:00
range ,
multilineTag ,
multilineWrapperTags ,
currentWrapperTags ,
isEditableTree ,
preserveWhiteSpace
2019-03-21 08:48:00 -04:00
} ) ; // Multiline value text should be separated by a line separator.
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
if ( index !== 0 || currentWrapperTags . length > 0 ) {
2019-03-21 08:48:00 -04:00
mergePair ( accumulator , {
formats : [ , ] ,
replacements : currentWrapperTags . length > 0 ? [ currentWrapperTags ] : [ , ] ,
text : LINE _SEPARATOR
} ) ;
2018-12-17 22:14:52 -05:00
}
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
accumulateSelection ( accumulator , node , range , value ) ;
2019-03-21 08:48:00 -04:00
mergePair ( accumulator , value ) ;
2018-12-17 22:14:52 -05:00
}
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
return accumulator ;
}
2018-12-13 23:41:57 -05:00
/ * *
2018-12-17 22:14:52 -05:00
* Gets the attributes of an element in object shape .
2018-12-13 23:41:57 -05:00
*
2020-10-13 09:10:30 -04:00
* @ param { Object } $1 Named argements .
* @ param { Element } $1 . element Element to get attributes from .
2018-12-13 23:41:57 -05:00
*
2020-10-13 09:10:30 -04:00
* @ return { Object | void } Attribute object or ` undefined ` if the element has no
* attributes .
2018-12-13 23:41:57 -05:00
* /
2018-12-17 22:14:52 -05:00
2021-11-15 07:50:17 -05:00
function getAttributes ( _ref4 ) {
let {
element
} = _ref4 ;
2018-12-17 22:14:52 -05:00
if ( ! element . hasAttributes ( ) ) {
2018-12-13 23:41:57 -05:00
return ;
}
2021-05-19 11:09:27 -04:00
const length = element . attributes . length ;
let accumulator ; // Optimise for speed.
2018-12-13 23:41:57 -05:00
2021-05-19 11:09:27 -04:00
for ( let i = 0 ; i < length ; i ++ ) {
const {
name ,
value
} = element . attributes [ i ] ;
2018-12-13 23:41:57 -05:00
2019-03-21 08:48:00 -04:00
if ( name . indexOf ( 'data-rich-text-' ) === 0 ) {
2018-12-17 22:14:52 -05:00
continue ;
}
2018-12-13 23:41:57 -05:00
2021-07-13 19:58:30 -04:00
const safeName = /^on/i . test ( name ) ? 'data-disable-rich-text-' + name : name ;
2018-12-17 22:14:52 -05:00
accumulator = accumulator || { } ;
2021-07-13 19:58:30 -04:00
accumulator [ safeName ] = value ;
2018-12-17 22:14:52 -05:00
}
2018-12-13 23:41:57 -05:00
2019-03-07 04:09:59 -05:00
return accumulator ;
}
2019-03-21 08:48:00 -04:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/concat.js
/ * *
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
2019-03-21 08:48:00 -04:00
/ * *
* Concats a pair of rich text values . Not that this mutates ` a ` and does NOT
* normalise formats !
*
2020-10-13 09:10:30 -04:00
* @ param { Object } a Value to mutate .
* @ param { Object } b Value to add read from .
2019-03-21 08:48:00 -04:00
*
* @ return { Object } ` a ` , mutated .
* /
function mergePair ( a , b ) {
a . formats = a . formats . concat ( b . formats ) ;
a . replacements = a . replacements . concat ( b . replacements ) ;
a . text += b . text ;
return a ;
}
/ * *
* Combine all Rich Text values into one . This is similar to
* ` String.prototype.concat ` .
*
2020-10-13 09:10:30 -04:00
* @ param { ... RichTextValue } values Objects to combine .
2019-03-21 08:48:00 -04:00
*
2020-10-13 09:10:30 -04:00
* @ return { RichTextValue } A new value combining all given records .
2019-03-21 08:48:00 -04:00
* /
2021-11-15 07:50:17 -05:00
function concat ( ) {
for ( var _len = arguments . length , values = new Array ( _len ) , _key = 0 ; _key < _len ; _key ++ ) {
values [ _key ] = arguments [ _key ] ;
}
2019-03-21 08:48:00 -04:00
return normaliseFormats ( values . reduce ( mergePair , create ( ) ) ) ;
}
2019-03-07 04:09:59 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-active-formats.js
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
/** @typedef {import('./create').RichTextFormatList} RichTextFormatList */
2019-03-07 04:09:59 -05:00
/ * *
* Gets the all format objects at the start of the selection .
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value Value to inspect .
* @ param { Array } EMPTY _ACTIVE _FORMATS Array to return if there are no
* active formats .
2019-03-07 04:09:59 -05:00
*
2020-10-13 09:10:30 -04:00
* @ return { RichTextFormatList } Active format objects .
2019-03-07 04:09:59 -05:00
* /
2021-11-15 07:50:17 -05:00
function getActiveFormats ( _ref ) {
let {
formats ,
start ,
end ,
activeFormats
} = _ref ;
let EMPTY _ACTIVE _FORMATS = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : [ ] ;
2019-03-07 04:09:59 -05:00
if ( start === undefined ) {
2020-01-22 17:06:21 -05:00
return EMPTY _ACTIVE _FORMATS ;
2019-03-07 04:09:59 -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 ( start === end ) {
// For a collapsed caret, it is possible to override the active formats.
if ( activeFormats ) {
return activeFormats ;
}
2021-05-19 11:09:27 -04:00
const formatsBefore = formats [ start - 1 ] || EMPTY _ACTIVE _FORMATS ;
const formatsAfter = formats [ start ] || EMPTY _ACTIVE _FORMATS ; // By default, select the lowest amount of formats possible (which means
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
// the caret is positioned outside the format boundary). The user can
// then use arrow keys to define `activeFormats`.
if ( formatsBefore . length < formatsAfter . length ) {
return formatsBefore ;
}
2019-03-07 04:09:59 -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 formatsAfter ;
2019-03-07 04:09:59 -05:00
}
2020-01-22 17:06:21 -05:00
return formats [ start ] || EMPTY _ACTIVE _FORMATS ;
2018-12-17 22:14:52 -05:00
}
2018-12-15 06:00:40 -05:00
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-active-format.js
2018-12-13 23:41:57 -05:00
/ * *
2018-12-17 22:14:52 -05:00
* External dependencies
2018-12-13 23:41:57 -05:00
* /
2018-12-15 06:00:40 -05:00
2019-03-07 04:09:59 -05:00
/ * *
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
/** @typedef {import('./create').RichTextFormat} RichTextFormat */
2018-12-13 23:41:57 -05:00
/ * *
2018-12-17 22:14:52 -05:00
* Gets the format object by type at the start of the selection . This can be
* used to get e . g . the URL of a link format at the current selection , but also
* to check if a format is active at the selection . Returns undefined if there
* is no format at the selection .
2018-12-13 23:41:57 -05:00
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value Value to inspect .
* @ param { string } formatType Format type to look for .
2018-12-13 23:41:57 -05:00
*
2020-10-13 09:10:30 -04:00
* @ return { RichTextFormat | undefined } Active format object of the specified
* type , or undefined .
2018-12-13 23:41:57 -05:00
* /
2019-03-07 04:09:59 -05:00
function getActiveFormat ( value , formatType ) {
2021-01-27 21:04:13 -05:00
return Object ( external _lodash _ [ "find" ] ) ( getActiveFormats ( value ) , {
2018-12-17 22:14:52 -05:00
type : formatType
} ) ;
2018-12-13 23:41:57 -05:00
}
2019-03-21 08:48:00 -04:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-active-object.js
/ * *
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
/** @typedef {import('./create').RichTextFormat} RichTextFormat */
2019-03-21 08:48:00 -04:00
/ * *
* Gets the active object , if there is any .
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value Value to inspect .
2019-03-21 08:48:00 -04:00
*
2020-10-13 09:10:30 -04:00
* @ return { RichTextFormat | void } Active object , or undefined .
2019-03-21 08:48:00 -04:00
* /
2021-11-15 07:50:17 -05:00
function getActiveObject ( _ref ) {
let {
start ,
end ,
replacements ,
text
} = _ref ;
2019-03-21 08:48:00 -04:00
if ( start + 1 !== end || text [ start ] !== OBJECT _REPLACEMENT _CHARACTER ) {
return ;
}
return replacements [ start ] ;
}
2019-09-19 11:19:18 -04:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-text-content.js
2021-04-15 11:19:43 -04:00
/ * *
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
2019-09-19 11:19:18 -04:00
/ * *
* Get the textual content of a Rich Text value . This is similar to
* ` Element.textContent ` .
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value Value to use .
2019-09-19 11:19:18 -04:00
*
* @ return { string } The text content .
* /
2021-04-15 11:19:43 -04:00
2021-11-15 07:50:17 -05:00
function getTextContent ( _ref ) {
let {
text
} = _ref ;
2021-04-15 11:19:43 -04:00
return text . replace ( new RegExp ( OBJECT _REPLACEMENT _CHARACTER , 'g' ) , '' ) . replace ( new RegExp ( LINE _SEPARATOR , 'g' ) , '\n' ) ;
2019-09-19 11:19:18 -04:00
}
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-line-index.js
/ * *
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
2018-12-13 23:41:57 -05:00
/ * *
2019-09-19 11:19:18 -04:00
* Gets the currently selected line index , or the first line index if the
* selection spans over multiple items .
2018-12-13 23:41:57 -05:00
*
2021-11-08 09:29:21 -05:00
* @ param { RichTextValue } value Value to get the line index from .
* @ param { boolean } startIndex Optional index that should be contained by
* the line . Defaults to the selection start
* of the value .
2018-12-13 23:41:57 -05:00
*
2020-10-13 09:10:30 -04:00
* @ return { number | void } The line index . Undefined if not found .
2018-12-13 23:41:57 -05:00
* /
2019-09-19 11:19:18 -04:00
2021-11-15 07:50:17 -05:00
function getLineIndex ( _ref ) {
let {
start ,
text
} = _ref ;
let startIndex = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : start ;
2021-05-19 11:09:27 -04:00
let index = startIndex ;
2019-09-19 11:19:18 -04:00
while ( index -- ) {
if ( text [ index ] === LINE _SEPARATOR ) {
return index ;
}
}
2018-12-17 22:14:52 -05:00
}
2018-12-13 23:41:57 -05:00
2019-09-19 11:19:18 -04:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/is-list-root-selected.js
/ * *
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
2018-12-17 22:14:52 -05:00
/ * *
2019-09-19 11:19:18 -04:00
* Whether or not the root list is selected .
2018-12-17 22:14:52 -05:00
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value The value to check .
2018-12-17 22:14:52 -05:00
*
2019-09-19 11:19:18 -04:00
* @ return { boolean } True if the root list or nothing is selected , false if an
* inner list is selected .
2018-12-17 22:14:52 -05:00
* /
2019-09-19 11:19:18 -04:00
function isListRootSelected ( value ) {
2021-05-19 11:09:27 -04:00
const {
replacements ,
start
} = value ;
const lineIndex = getLineIndex ( value , start ) ;
const replacement = replacements [ lineIndex ] ;
2019-09-19 11:19:18 -04:00
return ! replacement || replacement . length < 1 ;
2018-12-17 22:14:52 -05:00
}
2018-12-13 23:41:57 -05:00
2019-09-19 11:19:18 -04:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/is-active-list-type.js
2018-12-17 22:14:52 -05:00
/ * *
2019-09-19 11:19:18 -04:00
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
2019-09-19 11:19:18 -04:00
/ * *
2021-01-27 21:04:13 -05:00
* Whether or not the selected list has the given tag name .
2018-12-17 22:14:52 -05:00
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value The value to check .
* @ param { string } type The tag name the list should have .
* @ param { string } rootType The current root tag name , to compare with in
* case nothing is selected .
2018-12-17 22:14:52 -05:00
*
2019-09-19 11:19:18 -04:00
* @ return { boolean } True if the current list type matches ` type ` , false if not .
2018-12-17 22:14:52 -05:00
* /
2019-09-19 11:19:18 -04:00
function isActiveListType ( value , type , rootType ) {
2021-05-19 11:09:27 -04:00
const {
replacements ,
start
} = value ;
const lineIndex = getLineIndex ( value , start ) ;
const replacement = replacements [ lineIndex ] ;
2019-09-19 11:19:18 -04:00
if ( ! replacement || replacement . length === 0 ) {
return type === rootType ;
}
2021-05-19 11:09:27 -04:00
const lastFormat = replacement [ replacement . length - 1 ] ;
2019-09-19 11:19:18 -04:00
return lastFormat . type === type ;
2018-12-17 22:14:52 -05:00
}
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/is-collapsed.js
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
2018-12-17 22:14:52 -05:00
/ * *
* Check if the selection of a Rich Text value is collapsed or not . Collapsed
* means that no characters are selected , but there is a caret present . If there
* is no selection , ` undefined ` will be returned . This is similar to
* ` window.getSelection().isCollapsed() ` .
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value The rich text value to check .
2018-12-17 22:14:52 -05:00
*
2019-03-21 08:48:00 -04:00
* @ return { boolean | undefined } True if the selection is collapsed , false if not ,
* undefined if there is no selection .
2018-12-17 22:14:52 -05:00
* /
2021-11-15 07:50:17 -05:00
function isCollapsed ( _ref ) {
let {
start ,
end
} = _ref ;
2018-12-17 22:14:52 -05:00
if ( start === undefined || end === undefined ) {
return ;
2018-12-13 23:41:57 -05:00
}
2018-12-17 22:14:52 -05:00
return start === end ;
2018-12-13 23:41:57 -05:00
}
2019-03-21 08:48:00 -04:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/is-empty.js
/ * *
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
2019-03-21 08:48:00 -04:00
/ * *
* Check if a Rich Text value is Empty , meaning it contains no text or any
* objects ( such as images ) .
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value Value to use .
2019-03-21 08:48:00 -04:00
*
* @ return { boolean } True if the value is empty , false if not .
* /
2021-11-15 07:50:17 -05:00
function isEmpty ( _ref ) {
let {
text
} = _ref ;
2019-03-21 08:48:00 -04:00
return text . length === 0 ;
}
/ * *
* Check if the current collapsed selection is on an empty line in case of a
* multiline value .
*
2021-11-08 09:29:21 -05:00
* @ param { RichTextValue } value Value te check .
2019-03-21 08:48:00 -04:00
*
* @ return { boolean } True if the line is empty , false if not .
* /
2021-11-15 07:50:17 -05:00
function isEmptyLine ( _ref2 ) {
let {
text ,
start ,
end
} = _ref2 ;
2019-03-21 08:48:00 -04:00
if ( start !== end ) {
return false ;
}
if ( text . length === 0 ) {
return true ;
}
if ( start === 0 && text . slice ( 0 , 1 ) === LINE _SEPARATOR ) {
return true ;
}
if ( start === text . length && text . slice ( - 1 ) === LINE _SEPARATOR ) {
return true ;
}
2021-05-19 11:09:27 -04:00
return text . slice ( start - 1 , end + 1 ) === ` ${ LINE _SEPARATOR } ${ LINE _SEPARATOR } ` ;
2019-03-21 08:48:00 -04:00
}
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/join.js
2018-12-13 23:41:57 -05:00
/ * *
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
2018-12-13 23:41:57 -05:00
/ * *
* Combine an array of Rich Text values into one , optionally separated by
* ` separator ` , which can be a Rich Text value , HTML string , or plain text
* string . This is similar to ` Array.prototype.join ` .
*
2020-10-13 09:10:30 -04:00
* @ param { Array < RichTextValue > } values An array of values to join .
* @ param { string | RichTextValue } [ separator ] Separator string or value .
2018-12-13 23:41:57 -05:00
*
2020-10-13 09:10:30 -04:00
* @ return { RichTextValue } A new combined value .
2018-12-13 23:41:57 -05:00
* /
2021-11-15 07:50:17 -05:00
function join ( values ) {
let separator = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : '' ;
2018-12-13 23:41:57 -05:00
if ( typeof separator === 'string' ) {
2018-12-17 22:14:52 -05:00
separator = create ( {
2018-12-13 23:41:57 -05:00
text : separator
} ) ;
}
2021-11-15 07:50:17 -05:00
return normaliseFormats ( values . reduce ( ( accumlator , _ref ) => {
let {
formats ,
replacements ,
text
} = _ref ;
return {
formats : accumlator . formats . concat ( separator . formats , formats ) ,
replacements : accumlator . replacements . concat ( separator . replacements , replacements ) ,
text : accumlator . text + separator . text + text
} ;
} ) ) ;
2018-12-13 23:41:57 -05:00
}
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/register-format-type.js
2018-12-14 06:02:53 -05:00
/ * *
* WordPress dependencies
* /
2021-01-27 21:04:13 -05:00
/ * *
* Internal dependencies
* /
2020-01-08 06:57:23 -05:00
/ * *
* @ typedef { Object } WPFormat
*
* @ property { string } name A string identifying the format . Must be
* unique across all registered formats .
* @ property { string } tagName The HTML tag this format will wrap the
* selection with .
* @ property { string } [ className ] A class to match the format .
* @ property { string } title Name of the format .
* @ property { Function } edit Should return a component for the user to
* interact with the new registered format .
* /
2018-12-14 06:02:53 -05:00
/ * *
* Registers a new format provided a unique name and an object defining its
* behavior .
*
2021-11-08 09:29:21 -05:00
* @ param { string } name Format name .
* @ param { WPFormat } settings Format settings .
2018-12-14 06:02:53 -05:00
*
2020-10-13 09:10:30 -04:00
* @ return { WPFormat | undefined } The format , if it has been successfully
* registered ; otherwise ` undefined ` .
2018-12-14 06:02:53 -05:00
* /
function registerFormatType ( name , settings ) {
2021-05-19 11:09:27 -04:00
settings = {
name ,
... settings
} ;
2018-12-14 06:02:53 -05:00
if ( typeof settings . name !== 'string' ) {
window . console . error ( 'Format names must be strings.' ) ;
return ;
}
if ( ! /^[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*$/ . test ( settings . name ) ) {
window . console . error ( 'Format names must contain a namespace prefix, include only lowercase alphanumeric characters or dashes, and start with a letter. Example: my-plugin/my-custom-format' ) ;
return ;
}
2021-01-27 21:04:13 -05:00
if ( Object ( external _wp _data _ [ "select" ] ) ( store ) . getFormatType ( settings . name ) ) {
2018-12-14 06:02:53 -05:00
window . console . error ( 'Format "' + settings . name + '" is already registered.' ) ;
return ;
}
2018-12-16 23:52:00 -05:00
if ( typeof settings . tagName !== 'string' || settings . tagName === '' ) {
window . console . error ( 'Format tag names must be a string.' ) ;
return ;
}
if ( ( typeof settings . className !== 'string' || settings . className === '' ) && settings . className !== null ) {
window . console . error ( 'Format class names must be a string, or null to handle bare elements.' ) ;
return ;
}
if ( ! /^[_a-zA-Z]+[a-zA-Z0-9-]*$/ . test ( settings . className ) ) {
window . console . error ( 'A class name must begin with a letter, followed by any number of hyphens, letters, or numbers.' ) ;
2018-12-14 06:02:53 -05:00
return ;
}
2018-12-16 23:52:00 -05:00
if ( settings . className === null ) {
2021-05-19 11:09:27 -04:00
const formatTypeForBareElement = Object ( external _wp _data _ [ "select" ] ) ( store ) . getFormatTypeForBareElement ( settings . tagName ) ;
2018-12-16 23:52:00 -05:00
if ( formatTypeForBareElement ) {
2021-05-19 11:09:27 -04:00
window . console . error ( ` Format " ${ formatTypeForBareElement . name } " is already registered to handle bare tag name " ${ settings . tagName } ". ` ) ;
2018-12-16 23:52:00 -05:00
return ;
}
} else {
2021-05-19 11:09:27 -04:00
const formatTypeForClassName = Object ( external _wp _data _ [ "select" ] ) ( store ) . getFormatTypeForClassName ( settings . className ) ;
2018-12-16 23:52:00 -05:00
if ( formatTypeForClassName ) {
2021-05-19 11:09:27 -04:00
window . console . error ( ` Format " ${ formatTypeForClassName . name } " is already registered to handle class name " ${ settings . className } ". ` ) ;
2018-12-16 23:52:00 -05:00
return ;
}
}
2018-12-14 06:02:53 -05:00
if ( ! ( 'title' in settings ) || settings . title === '' ) {
window . console . error ( 'The format "' + settings . name + '" must have a title.' ) ;
return ;
}
if ( 'keywords' in settings && settings . keywords . length > 3 ) {
window . console . error ( 'The format "' + settings . name + '" can have a maximum of 3 keywords.' ) ;
2020-01-22 17:06:21 -05:00
return ;
}
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
2020-01-22 17:06:21 -05:00
if ( typeof settings . title !== 'string' ) {
window . console . error ( 'Format titles must be strings.' ) ;
return ;
2018-12-16 23:52:00 -05:00
}
2021-01-27 21:04:13 -05:00
Object ( external _wp _data _ [ "dispatch" ] ) ( store ) . addFormatTypes ( settings ) ;
2018-12-14 06:02:53 -05:00
return settings ;
}
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/remove-format.js
2018-12-13 23:41:57 -05:00
/ * *
* External dependencies
* /
/ * *
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
2018-12-13 23:41:57 -05:00
/ * *
* Remove any format object from a Rich Text value by type from the given
* ` startIndex ` to the given ` endIndex ` . Indices are retrieved from the
* selection if none are provided .
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value Value to modify .
* @ param { string } formatType Format type to remove .
* @ param { number } [ startIndex ] Start index .
* @ param { number } [ endIndex ] End index .
2018-12-13 23:41:57 -05:00
*
2020-10-13 09:10:30 -04:00
* @ return { RichTextValue } A new value with the format applied .
2018-12-13 23:41:57 -05:00
* /
2021-11-15 07:50:17 -05:00
function removeFormat ( value , formatType ) {
let startIndex = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : value . start ;
let endIndex = arguments . length > 3 && arguments [ 3 ] !== undefined ? arguments [ 3 ] : value . end ;
2021-05-19 11:09:27 -04:00
const {
formats ,
activeFormats
} = value ;
const newFormats = formats . slice ( ) ; // If the selection is collapsed, expand start and end to the edges of the
2018-12-13 23:41:57 -05:00
// format.
if ( startIndex === endIndex ) {
2021-05-19 11:09:27 -04:00
const format = Object ( external _lodash _ [ "find" ] ) ( newFormats [ startIndex ] , {
2018-12-13 23:41:57 -05:00
type : formatType
} ) ;
2019-03-21 08:48:00 -04:00
if ( format ) {
2021-01-27 21:04:13 -05:00
while ( Object ( external _lodash _ [ "find" ] ) ( newFormats [ startIndex ] , format ) ) {
2019-03-21 08:48:00 -04:00
filterFormats ( newFormats , startIndex , formatType ) ;
startIndex -- ;
}
2018-12-13 23:41:57 -05:00
endIndex ++ ;
2019-03-21 08:48:00 -04:00
2021-01-27 21:04:13 -05:00
while ( Object ( external _lodash _ [ "find" ] ) ( newFormats [ endIndex ] , format ) ) {
2019-03-21 08:48:00 -04:00
filterFormats ( newFormats , endIndex , formatType ) ;
endIndex ++ ;
}
2018-12-13 23:41:57 -05:00
}
} else {
2021-05-19 11:09:27 -04:00
for ( let i = startIndex ; i < endIndex ; i ++ ) {
2018-12-13 23:41:57 -05:00
if ( newFormats [ i ] ) {
filterFormats ( newFormats , i , formatType ) ;
}
}
}
2021-05-19 11:09:27 -04:00
return normaliseFormats ( { ... value ,
2019-05-16 14:08:00 -04:00
formats : newFormats ,
2021-01-27 21:04:13 -05:00
activeFormats : Object ( external _lodash _ [ "reject" ] ) ( activeFormats , {
2019-05-16 14:08:00 -04:00
type : formatType
} )
2021-05-19 11:09:27 -04:00
} ) ;
2018-12-13 23:41:57 -05:00
}
function filterFormats ( formats , index , formatType ) {
2021-11-15 07:50:17 -05:00
const newFormats = formats [ index ] . filter ( _ref => {
let {
type
} = _ref ;
return type !== formatType ;
} ) ;
2018-12-13 23:41:57 -05:00
if ( newFormats . length ) {
formats [ index ] = newFormats ;
} else {
delete formats [ index ] ;
}
}
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/insert.js
/ * *
* Internal dependencies
* /
2018-12-13 23:41:57 -05:00
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
2018-12-17 22:14:52 -05:00
/ * *
* Insert a Rich Text value , an HTML string , or a plain text string , into a
* Rich Text value at the given ` startIndex ` . Any content between ` startIndex `
* and ` endIndex ` will be removed . Indices are retrieved from the selection if
* none are provided .
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value Value to modify .
* @ param { RichTextValue | string } valueToInsert Value to insert .
* @ param { number } [ startIndex ] Start index .
* @ param { number } [ endIndex ] End index .
2018-12-17 22:14:52 -05:00
*
2020-10-13 09:10:30 -04:00
* @ return { RichTextValue } A new value with the value inserted .
2018-12-17 22:14:52 -05:00
* /
2018-12-13 23:41:57 -05:00
2021-11-15 07:50:17 -05:00
function insert ( value , valueToInsert ) {
let startIndex = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : value . start ;
let endIndex = arguments . length > 3 && arguments [ 3 ] !== undefined ? arguments [ 3 ] : value . end ;
2021-05-19 11:09:27 -04:00
const {
formats ,
replacements ,
text
} = value ;
2018-12-17 22:14:52 -05:00
if ( typeof valueToInsert === 'string' ) {
valueToInsert = create ( {
text : valueToInsert
} ) ;
}
2021-05-19 11:09:27 -04:00
const index = startIndex + valueToInsert . text . length ;
2018-12-17 22:14:52 -05:00
return normaliseFormats ( {
formats : formats . slice ( 0 , startIndex ) . concat ( valueToInsert . formats , formats . slice ( endIndex ) ) ,
2019-03-21 08:48:00 -04:00
replacements : replacements . slice ( 0 , startIndex ) . concat ( valueToInsert . replacements , replacements . slice ( endIndex ) ) ,
2018-12-17 22:14:52 -05:00
text : text . slice ( 0 , startIndex ) + valueToInsert . text + text . slice ( endIndex ) ,
start : index ,
end : index
} ) ;
}
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/remove.js
2018-12-13 23:41:57 -05:00
/ * *
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
2018-12-13 23:41:57 -05:00
/ * *
* Remove content from a Rich Text value between the given ` startIndex ` and
* ` endIndex ` . Indices are retrieved from the selection if none are provided .
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value Value to modify .
* @ param { number } [ startIndex ] Start index .
* @ param { number } [ endIndex ] End index .
2018-12-13 23:41:57 -05:00
*
2020-10-13 09:10:30 -04:00
* @ return { RichTextValue } A new value with the content removed .
2018-12-13 23:41:57 -05:00
* /
2018-12-17 22:14:52 -05:00
function remove _remove ( value , startIndex , endIndex ) {
return insert ( value , create ( ) , startIndex , endIndex ) ;
2018-12-13 23:41:57 -05:00
}
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/replace.js
2018-12-13 23:41:57 -05:00
/ * *
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
2018-12-13 23:41:57 -05:00
/ * *
* Search a Rich Text value and replace the match ( es ) with ` replacement ` . This
* is similar to ` String.prototype.replace ` .
*
2021-11-08 09:29:21 -05:00
* @ param { RichTextValue } value The value to modify .
* @ param { RegExp | string } pattern A RegExp object or literal . Can also be
2018-12-13 23:41:57 -05:00
* a string . It is treated as a verbatim
* string and is not interpreted as a
* regular expression . Only the first
* occurrence will be replaced .
* @ param { Function | string } replacement The match or matches are replaced with
* the specified or the value returned by
* the specified function .
*
2020-10-13 09:10:30 -04:00
* @ return { RichTextValue } A new value with replacements applied .
2018-12-13 23:41:57 -05:00
* /
2021-11-15 07:50:17 -05:00
function replace _replace ( _ref , pattern , replacement ) {
let {
formats ,
replacements ,
text ,
start ,
end
} = _ref ;
text = text . replace ( pattern , function ( match ) {
for ( var _len = arguments . length , rest = new Array ( _len > 1 ? _len - 1 : 0 ) , _key = 1 ; _key < _len ; _key ++ ) {
rest [ _key - 1 ] = arguments [ _key ] ;
}
2021-05-19 11:09:27 -04:00
const offset = rest [ rest . length - 2 ] ;
let newText = replacement ;
let newFormats ;
let newReplacements ;
2018-12-13 23:41:57 -05:00
if ( typeof newText === 'function' ) {
2021-05-19 11:09:27 -04:00
newText = replacement ( match , ... rest ) ;
2018-12-13 23:41:57 -05:00
}
2021-05-19 11:09:27 -04:00
if ( typeof newText === 'object' ) {
2018-12-13 23:41:57 -05:00
newFormats = newText . formats ;
2019-03-21 08:48:00 -04:00
newReplacements = newText . replacements ;
2018-12-13 23:41:57 -05:00
newText = newText . text ;
} else {
newFormats = Array ( newText . length ) ;
2019-03-21 08:48:00 -04:00
newReplacements = Array ( newText . length ) ;
2018-12-13 23:41:57 -05:00
if ( formats [ offset ] ) {
newFormats = newFormats . fill ( formats [ offset ] ) ;
}
}
formats = formats . slice ( 0 , offset ) . concat ( newFormats , formats . slice ( offset + match . length ) ) ;
2019-03-21 08:48:00 -04:00
replacements = replacements . slice ( 0 , offset ) . concat ( newReplacements , replacements . slice ( offset + match . length ) ) ;
2018-12-13 23:41:57 -05:00
if ( start ) {
start = end = offset + newText . length ;
}
return newText ;
} ) ;
2018-12-17 22:14:52 -05:00
return normaliseFormats ( {
2021-05-19 11:09:27 -04:00
formats ,
replacements ,
text ,
start ,
end
2018-12-13 23:41:57 -05:00
} ) ;
}
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/insert-line-separator.js
/ * *
* Internal dependencies
* /
2018-12-13 23:41:57 -05:00
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
2018-12-17 22:14:52 -05:00
/ * *
* Insert a line break character into a Rich Text value at the given
* ` startIndex ` . Any content between ` startIndex ` and ` endIndex ` will be
* removed . Indices are retrieved from the selection if none are provided .
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value Value to modify .
* @ param { number } [ startIndex ] Start index .
* @ param { number } [ endIndex ] End index .
2018-12-17 22:14:52 -05:00
*
2020-10-13 09:10:30 -04:00
* @ return { RichTextValue } A new value with the value inserted .
2018-12-17 22:14:52 -05:00
* /
2021-11-15 07:50:17 -05:00
function insertLineSeparator ( value ) {
let startIndex = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : value . start ;
let endIndex = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : value . end ;
2021-05-19 11:09:27 -04:00
const beforeText = value . text . slice ( 0 , startIndex ) ;
const previousLineSeparatorIndex = beforeText . lastIndexOf ( LINE _SEPARATOR ) ;
const previousLineSeparatorFormats = value . replacements [ previousLineSeparatorIndex ] ;
let replacements = [ , ] ;
2018-12-17 22:14:52 -05:00
if ( previousLineSeparatorFormats ) {
2019-03-21 08:48:00 -04:00
replacements = [ previousLineSeparatorFormats ] ;
2018-12-17 22:14:52 -05:00
}
2021-05-19 11:09:27 -04:00
const valueToInsert = {
2019-03-21 08:48:00 -04:00
formats : [ , ] ,
2021-05-19 11:09:27 -04:00
replacements ,
2018-12-17 22:14:52 -05:00
text : LINE _SEPARATOR
} ;
return insert ( value , valueToInsert , startIndex , endIndex ) ;
}
2019-09-19 11:19:18 -04:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/remove-line-separator.js
/ * *
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
2019-09-19 11:19:18 -04:00
/ * *
2020-10-13 09:10:30 -04:00
* Removes a line separator character , if existing , from a Rich Text value at
* the current indices . If no line separator exists on the indices it will
* return undefined .
2019-09-19 11:19:18 -04:00
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value Value to modify .
* @ param { boolean } backward Indicates if are removing from the start
* index or the end index .
2019-09-19 11:19:18 -04:00
*
2020-10-13 09:10:30 -04:00
* @ return { RichTextValue | undefined } A new value with the line separator
* removed . Or undefined if no line separator
* is found on the position .
2019-09-19 11:19:18 -04:00
* /
2021-11-15 07:50:17 -05:00
function removeLineSeparator ( value ) {
let backward = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : true ;
2021-05-19 11:09:27 -04:00
const {
replacements ,
text ,
start ,
end
} = value ;
const collapsed = isCollapsed ( value ) ;
let index = start - 1 ;
let removeStart = collapsed ? start - 1 : start ;
let removeEnd = end ;
2019-09-19 11:19:18 -04:00
if ( ! backward ) {
index = end ;
removeStart = start ;
removeEnd = collapsed ? end + 1 : end ;
}
if ( text [ index ] !== LINE _SEPARATOR ) {
return ;
}
2021-05-19 11:09:27 -04:00
let newValue ; // If the line separator that is about te be removed
2019-09-19 11:19:18 -04:00
// contains wrappers, remove the wrappers first.
if ( collapsed && replacements [ index ] && replacements [ index ] . length ) {
2021-05-19 11:09:27 -04:00
const newReplacements = replacements . slice ( ) ;
2019-09-19 11:19:18 -04:00
newReplacements [ index ] = replacements [ index ] . slice ( 0 , - 1 ) ;
2021-05-19 11:09:27 -04:00
newValue = { ... value ,
2019-09-19 11:19:18 -04:00
replacements : newReplacements
2021-05-19 11:09:27 -04:00
} ;
2019-09-19 11:19:18 -04:00
} else {
newValue = remove _remove ( value , removeStart , removeEnd ) ;
}
return newValue ;
}
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/insert-object.js
/ * *
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
/** @typedef {import('./create').RichTextFormat} RichTextFormat */
2018-12-17 22:14:52 -05:00
/ * *
* Insert a format as an object into a Rich Text value at the given
* ` startIndex ` . Any content between ` startIndex ` and ` endIndex ` will be
* removed . Indices are retrieved from the selection if none are provided .
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value Value to modify .
* @ param { RichTextFormat } formatToInsert Format to insert as object .
* @ param { number } [ startIndex ] Start index .
* @ param { number } [ endIndex ] End index .
2018-12-17 22:14:52 -05:00
*
2020-10-13 09:10:30 -04:00
* @ return { RichTextValue } A new value with the object inserted .
2018-12-17 22:14:52 -05:00
* /
function insertObject ( value , formatToInsert , startIndex , endIndex ) {
2021-05-19 11:09:27 -04:00
const valueToInsert = {
2019-03-21 08:48:00 -04:00
formats : [ , ] ,
replacements : [ formatToInsert ] ,
2020-10-13 09:10:30 -04:00
text : OBJECT _REPLACEMENT _CHARACTER
2018-12-17 22:14:52 -05:00
} ;
return insert ( value , valueToInsert , startIndex , endIndex ) ;
}
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/slice.js
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
2018-12-13 23:41:57 -05:00
/ * *
* Slice a Rich Text value from ` startIndex ` to ` endIndex ` . Indices are
* retrieved from the selection if none are provided . This is similar to
* ` String.prototype.slice ` .
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value Value to modify .
* @ param { number } [ startIndex ] Start index .
* @ param { number } [ endIndex ] End index .
2018-12-13 23:41:57 -05:00
*
2020-10-13 09:10:30 -04:00
* @ return { RichTextValue } A new extracted value .
2018-12-13 23:41:57 -05:00
* /
2021-11-15 07:50:17 -05:00
function slice ( value ) {
let startIndex = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : value . start ;
let endIndex = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : value . end ;
2021-05-19 11:09:27 -04:00
const {
formats ,
replacements ,
text
} = value ;
2018-12-13 23:41:57 -05:00
if ( startIndex === undefined || endIndex === undefined ) {
2021-05-19 11:09:27 -04:00
return { ... value
} ;
2018-12-13 23:41:57 -05:00
}
return {
formats : formats . slice ( startIndex , endIndex ) ,
2019-03-21 08:48:00 -04:00
replacements : replacements . slice ( startIndex , endIndex ) ,
2018-12-13 23:41:57 -05:00
text : text . slice ( startIndex , endIndex )
} ;
}
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/split.js
2018-12-13 23:41:57 -05:00
/ * *
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
2018-12-13 23:41:57 -05:00
/ * *
* Split a Rich Text value in two at the given ` startIndex ` and ` endIndex ` , or
* split at the given separator . This is similar to ` String.prototype.split ` .
* Indices are retrieved from the selection if none are provided .
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value
2019-03-21 08:48:00 -04:00
* @ param { number | string } [ string ] Start index , or string at which to split .
2018-12-13 23:41:57 -05:00
*
2021-05-21 06:14:23 -04:00
* @ return { Array < RichTextValue > | undefined } An array of new values .
2018-12-13 23:41:57 -05:00
* /
2021-11-15 07:50:17 -05:00
function split ( _ref , string ) {
let {
formats ,
replacements ,
text ,
start ,
end
} = _ref ;
2018-12-13 23:41:57 -05:00
if ( typeof string !== 'string' ) {
2021-05-19 11:09:27 -04:00
return splitAtSelection ( ... arguments ) ;
2018-12-13 23:41:57 -05:00
}
2021-05-19 11:09:27 -04:00
let nextStart = 0 ;
return text . split ( string ) . map ( substring => {
const startIndex = nextStart ;
const value = {
2018-12-13 23:41:57 -05:00
formats : formats . slice ( startIndex , startIndex + substring . length ) ,
2019-03-21 08:48:00 -04:00
replacements : replacements . slice ( startIndex , startIndex + substring . length ) ,
2018-12-13 23:41:57 -05:00
text : substring
} ;
nextStart += string . length + substring . length ;
if ( start !== undefined && end !== undefined ) {
if ( start >= startIndex && start < nextStart ) {
value . start = start - startIndex ;
} else if ( start < startIndex && end > startIndex ) {
value . start = 0 ;
}
if ( end >= startIndex && end < nextStart ) {
value . end = end - startIndex ;
} else if ( start < nextStart && end > nextStart ) {
value . end = substring . length ;
}
}
return value ;
} ) ;
}
2021-11-15 07:50:17 -05:00
function splitAtSelection ( _ref2 ) {
let {
formats ,
replacements ,
text ,
start ,
end
} = _ref2 ;
let startIndex = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : start ;
let endIndex = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : end ;
2021-05-21 06:14:23 -04:00
if ( start === undefined || end === undefined ) {
return ;
}
2021-05-19 11:09:27 -04:00
const before = {
2018-12-13 23:41:57 -05:00
formats : formats . slice ( 0 , startIndex ) ,
2019-03-21 08:48:00 -04:00
replacements : replacements . slice ( 0 , startIndex ) ,
2018-12-13 23:41:57 -05:00
text : text . slice ( 0 , startIndex )
} ;
2021-05-19 11:09:27 -04:00
const after = {
2018-12-13 23:41:57 -05:00
formats : formats . slice ( endIndex ) ,
2019-03-21 08:48:00 -04:00
replacements : replacements . slice ( endIndex ) ,
2018-12-13 23:41:57 -05:00
text : text . slice ( endIndex ) ,
start : 0 ,
end : 0
} ;
return [ // Ensure newlines are trimmed.
2019-09-19 11:19:18 -04:00
replace _replace ( before , /\u2028+$/ , '' ) , replace _replace ( after , /^\u2028+/ , '' ) ] ;
2018-12-13 23:41:57 -05:00
}
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-format-type.js
2018-12-14 06:02:53 -05:00
/ * *
2018-12-17 22:14:52 -05:00
* WordPress dependencies
2018-12-14 06:02:53 -05:00
* /
2021-01-27 21:04:13 -05:00
/ * *
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
/** @typedef {import('./register-format-type').RichTextFormatType} RichTextFormatType */
2018-12-14 06:02:53 -05:00
/ * *
2018-12-17 22:14:52 -05:00
* Returns a registered format type .
2018-12-14 06:02:53 -05:00
*
2018-12-17 22:14:52 -05:00
* @ param { string } name Format name .
2018-12-14 06:02:53 -05:00
*
2020-10-13 09:10:30 -04:00
* @ return { RichTextFormatType | undefined } Format type .
2018-12-14 06:02:53 -05:00
* /
2018-12-17 22:14:52 -05:00
function get _format _type _getFormatType ( name ) {
2021-01-27 21:04:13 -05:00
return Object ( external _wp _data _ [ "select" ] ) ( store ) . getFormatType ( name ) ;
2018-12-14 06:02:53 -05:00
}
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/to-tree.js
2018-12-14 06:02:53 -05:00
/ * *
* Internal dependencies
* /
2021-07-13 19:58:30 -04:00
function restoreOnAttributes ( attributes , isEditableTree ) {
if ( isEditableTree ) {
return attributes ;
}
const newAttributes = { } ;
for ( const key in attributes ) {
let newKey = key ;
if ( key . startsWith ( 'data-disable-rich-text-' ) ) {
newKey = key . slice ( 'data-disable-rich-text-' . length ) ;
}
newAttributes [ newKey ] = attributes [ key ] ;
}
return newAttributes ;
}
2019-03-07 04:09:59 -05:00
/ * *
* Converts a format object to information that can be used to create an element
* from ( type , attributes and object ) .
*
2021-11-08 09:29:21 -05:00
* @ param { Object } $1 Named parameters .
* @ param { string } $1 . type The format type .
* @ param { Object } $1 . attributes The format attributes .
* @ param { Object } $1 . unregisteredAttributes The unregistered format
* attributes .
* @ param { boolean } $1 . object Whether or not it is an object
* format .
* @ param { boolean } $1 . boundaryClass Whether or not to apply a boundary
* class .
* @ param { boolean } $1 . isEditableTree
2021-07-13 19:58:30 -04:00
*
2021-11-08 09:29:21 -05:00
* @ return { Object } Information to be used for element creation .
2019-03-07 04:09:59 -05:00
* /
2021-07-13 19:58:30 -04:00
2021-11-15 07:50:17 -05:00
function fromFormat ( _ref ) {
let {
type ,
attributes ,
unregisteredAttributes ,
object ,
boundaryClass ,
isEditableTree
} = _ref ;
2021-05-19 11:09:27 -04:00
const formatType = get _format _type _getFormatType ( type ) ;
let elementAttributes = { } ;
2019-03-07 04:09:59 -05:00
if ( boundaryClass ) {
elementAttributes [ 'data-rich-text-format-boundary' ] = 'true' ;
}
2018-12-14 06:02:53 -05:00
2018-12-17 22:14:52 -05:00
if ( ! formatType ) {
2019-03-07 04:09:59 -05:00
if ( attributes ) {
2021-05-19 11:09:27 -04:00
elementAttributes = { ... attributes ,
... elementAttributes
} ;
2019-03-07 04:09:59 -05:00
}
2018-12-17 22:14:52 -05:00
return {
2021-05-19 11:09:27 -04:00
type ,
2021-07-13 19:58:30 -04:00
attributes : restoreOnAttributes ( elementAttributes , isEditableTree ) ,
2021-05-19 11:09:27 -04:00
object
2018-12-17 22:14:52 -05:00
} ;
}
2018-12-14 06:02:53 -05:00
2021-05-19 11:09:27 -04:00
elementAttributes = { ... unregisteredAttributes ,
... elementAttributes
} ;
2018-12-14 06:02:53 -05:00
2021-05-19 11:09:27 -04:00
for ( const name in attributes ) {
const key = formatType . attributes ? formatType . attributes [ name ] : false ;
2018-12-14 06:02:53 -05:00
2018-12-17 22:14:52 -05:00
if ( key ) {
elementAttributes [ key ] = attributes [ name ] ;
} else {
elementAttributes [ name ] = attributes [ name ] ;
}
}
2018-12-14 06:02:53 -05:00
2018-12-17 22:14:52 -05:00
if ( formatType . className ) {
if ( elementAttributes . class ) {
2021-05-19 11:09:27 -04:00
elementAttributes . class = ` ${ formatType . className } ${ elementAttributes . class } ` ;
2018-12-17 22:14:52 -05:00
} else {
elementAttributes . class = formatType . className ;
}
}
2018-12-14 06:02:53 -05:00
2018-12-17 22:14:52 -05:00
return {
type : formatType . tagName ,
object : formatType . object ,
2021-07-13 19:58:30 -04:00
attributes : restoreOnAttributes ( elementAttributes , isEditableTree )
2018-12-17 22:14:52 -05:00
} ;
}
2020-01-22 17:06:21 -05:00
/ * *
* Checks if both arrays of formats up until a certain index are equal .
*
* @ param { Array } a Array of formats to compare .
* @ param { Array } b Array of formats to compare .
* @ param { number } index Index to check until .
* /
function isEqualUntil ( a , b , index ) {
do {
if ( a [ index ] !== b [ index ] ) {
return false ;
}
} while ( index -- ) ;
return true ;
}
2018-12-14 06:02:53 -05:00
2021-11-15 07:50:17 -05:00
function toTree ( _ref2 ) {
let {
value ,
multilineTag ,
preserveWhiteSpace ,
createEmpty ,
append ,
getLastChild ,
getParent ,
isText ,
getText ,
remove ,
appendText ,
onStartIndex ,
onEndIndex ,
isEditableTree ,
placeholder
} = _ref2 ;
2021-05-19 11:09:27 -04:00
const {
formats ,
replacements ,
text ,
start ,
end
} = value ;
const formatsLength = formats . length + 1 ;
const tree = createEmpty ( ) ;
const multilineFormat = {
2018-12-17 22:14:52 -05:00
type : multilineTag
} ;
2021-05-19 11:09:27 -04:00
const activeFormats = getActiveFormats ( value ) ;
const deepestActiveFormat = activeFormats [ activeFormats . length - 1 ] ;
let lastSeparatorFormats ;
let lastCharacterFormats ;
let lastCharacter ; // If we're building a multiline tree, start off with a multiline element.
2018-12-14 06:02:53 -05:00
2018-12-17 22:14:52 -05:00
if ( multilineTag ) {
append ( append ( tree , {
type : multilineTag
} ) , '' ) ;
lastCharacterFormats = lastSeparatorFormats = [ multilineFormat ] ;
} else {
append ( tree , '' ) ;
}
2018-12-14 06:02:53 -05:00
2021-05-19 11:09:27 -04:00
for ( let i = 0 ; i < formatsLength ; i ++ ) {
const character = text . charAt ( i ) ;
const shouldInsertPadding = isEditableTree && ( // Pad the line if the line is empty.
2019-03-21 08:48:00 -04:00
! lastCharacter || lastCharacter === LINE _SEPARATOR || // Pad the line if the previous character is a line break, otherwise
// the line break won't be visible.
lastCharacter === '\n' ) ;
2021-05-19 11:09:27 -04:00
let characterFormats = formats [ i ] ; // Set multiline tags in queue for building the tree.
2018-12-14 06:02:53 -05:00
2018-12-17 22:14:52 -05:00
if ( multilineTag ) {
if ( character === LINE _SEPARATOR ) {
2021-05-19 11:09:27 -04:00
characterFormats = lastSeparatorFormats = ( replacements [ i ] || [ ] ) . reduce ( ( accumulator , format ) => {
2019-03-21 08:48:00 -04:00
accumulator . push ( format , multilineFormat ) ;
2018-12-17 22:14:52 -05:00
return accumulator ;
} , [ multilineFormat ] ) ;
} else {
2021-05-19 11:09:27 -04:00
characterFormats = [ ... lastSeparatorFormats , ... ( characterFormats || [ ] ) ] ;
2018-12-17 22:14:52 -05:00
}
}
2018-12-14 06:02:53 -05:00
2021-05-19 11:09:27 -04:00
let pointer = getLastChild ( tree ) ;
2018-12-14 06:02:53 -05:00
2019-03-21 08:48:00 -04:00
if ( shouldInsertPadding && character === LINE _SEPARATOR ) {
2021-05-19 11:09:27 -04:00
let node = pointer ;
2018-12-14 06:02:53 -05:00
2018-12-17 22:14:52 -05:00
while ( ! isText ( node ) ) {
node = getLastChild ( node ) ;
}
2018-12-16 23:52:00 -05:00
2019-09-19 11:19:18 -04:00
append ( getParent ( node ) , ZWNBSP ) ;
2019-03-21 08:48:00 -04:00
} // Set selection for the start of line.
if ( lastCharacter === LINE _SEPARATOR ) {
2021-05-19 11:09:27 -04:00
let node = pointer ;
2019-03-21 08:48:00 -04:00
2021-05-19 11:09:27 -04:00
while ( ! isText ( node ) ) {
node = getLastChild ( node ) ;
2019-03-21 08:48:00 -04:00
}
2018-12-17 22:14:52 -05:00
if ( onStartIndex && start === i ) {
2021-05-19 11:09:27 -04:00
onStartIndex ( tree , node ) ;
2018-12-17 22:14:52 -05:00
}
2018-12-14 06:02:53 -05:00
2018-12-17 22:14:52 -05:00
if ( onEndIndex && end === i ) {
2021-05-19 11:09:27 -04:00
onEndIndex ( tree , node ) ;
2018-12-17 22:14:52 -05:00
}
}
2018-12-14 06:02:53 -05:00
2018-12-17 22:14:52 -05:00
if ( characterFormats ) {
2021-05-19 11:09:27 -04:00
characterFormats . forEach ( ( format , formatIndex ) => {
2020-01-22 17:06:21 -05:00
if ( pointer && lastCharacterFormats && // Reuse the last element if all formats remain the same.
isEqualUntil ( characterFormats , lastCharacterFormats , formatIndex ) && ( // Do not reuse the last element if the character is a
2018-12-17 22:14:52 -05:00
// line separator.
character !== LINE _SEPARATOR || characterFormats . length - 1 !== formatIndex ) ) {
pointer = getLastChild ( pointer ) ;
return ;
}
2018-12-16 23:52:00 -05:00
2021-05-19 11:09:27 -04:00
const {
type ,
attributes ,
unregisteredAttributes
} = format ;
const boundaryClass = isEditableTree && character !== LINE _SEPARATOR && format === deepestActiveFormat ;
const parent = getParent ( pointer ) ;
const newNode = append ( parent , fromFormat ( {
type ,
attributes ,
unregisteredAttributes ,
2021-07-13 19:58:30 -04:00
boundaryClass ,
isEditableTree
2019-03-07 04:09:59 -05:00
} ) ) ;
2018-12-16 23:52:00 -05:00
2018-12-17 22:14:52 -05:00
if ( isText ( pointer ) && getText ( pointer ) . length === 0 ) {
remove ( pointer ) ;
}
2019-03-21 08:48:00 -04:00
pointer = append ( newNode , '' ) ;
2018-12-17 22:14:52 -05:00
} ) ;
} // No need for further processing if the character is a line separator.
if ( character === LINE _SEPARATOR ) {
lastCharacterFormats = characterFormats ;
lastCharacter = character ;
2021-05-19 11:09:27 -04:00
continue ;
2019-03-07 04:09:59 -05:00
} // If there is selection at 0, handle it before characters are inserted.
2018-12-17 22:14:52 -05:00
if ( i === 0 ) {
if ( onStartIndex && start === 0 ) {
onStartIndex ( tree , pointer ) ;
}
if ( onEndIndex && end === 0 ) {
onEndIndex ( tree , pointer ) ;
}
}
2019-03-21 08:48:00 -04:00
if ( character === OBJECT _REPLACEMENT _CHARACTER ) {
2021-11-08 09:29:21 -05:00
var _replacements$i ;
if ( ! isEditableTree && ( ( _replacements$i = replacements [ i ] ) === null || _replacements$i === void 0 ? void 0 : _replacements$i . type ) === 'script' ) {
2021-07-13 19:58:30 -04:00
pointer = append ( getParent ( pointer ) , fromFormat ( {
type : 'script' ,
isEditableTree
} ) ) ;
append ( pointer , {
html : decodeURIComponent ( replacements [ i ] . attributes [ 'data-rich-text-script' ] )
} ) ;
} else {
pointer = append ( getParent ( pointer ) , fromFormat ( { ... replacements [ i ] ,
object : true ,
isEditableTree
} ) ) ;
} // Ensure pointer is text node.
2019-03-21 08:48:00 -04:00
pointer = append ( getParent ( pointer ) , '' ) ;
2020-01-08 06:57:23 -05:00
} else if ( ! preserveWhiteSpace && character === '\n' ) {
2019-03-21 08:48:00 -04:00
pointer = append ( getParent ( pointer ) , {
type : 'br' ,
attributes : isEditableTree ? {
'data-rich-text-line-break' : 'true'
} : undefined ,
object : true
} ) ; // Ensure pointer is text node.
pointer = append ( getParent ( pointer ) , '' ) ;
} else if ( ! isText ( pointer ) ) {
pointer = append ( getParent ( pointer ) , character ) ;
} else {
appendText ( pointer , character ) ;
2018-12-17 22:14:52 -05:00
}
if ( onStartIndex && start === i + 1 ) {
onStartIndex ( tree , pointer ) ;
}
2018-12-16 23:52:00 -05:00
2018-12-17 22:14:52 -05:00
if ( onEndIndex && end === i + 1 ) {
onEndIndex ( tree , pointer ) ;
2018-12-16 23:52:00 -05:00
}
2019-03-21 08:48:00 -04:00
if ( shouldInsertPadding && i === text . length ) {
2019-09-19 11:19:18 -04:00
append ( getParent ( pointer ) , ZWNBSP ) ;
if ( placeholder && text . length === 0 ) {
append ( getParent ( pointer ) , {
type : 'span' ,
attributes : {
'data-rich-text-placeholder' : placeholder ,
// Necessary to prevent the placeholder from catching
// selection. The placeholder is also not editable after
// all.
2021-04-15 11:19:43 -04:00
contenteditable : 'false' ,
style : 'pointer-events:none;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;'
2019-09-19 11:19:18 -04:00
}
} ) ;
}
2019-03-21 08:48:00 -04:00
}
2018-12-17 22:14:52 -05:00
lastCharacterFormats = characterFormats ;
lastCharacter = character ;
}
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
return tree ;
}
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/to-dom.js
2018-12-13 23:41:57 -05:00
/ * *
* Internal dependencies
* /
2018-12-18 22:16:48 -05:00
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
2018-12-13 23:41:57 -05:00
/ * *
* Creates a path as an array of indices from the given root node to the given
* node .
*
* @ param { Node } node Node to find the path of .
* @ param { HTMLElement } rootNode Root node to find the path from .
* @ param { Array } path Initial path to build on .
*
* @ return { Array } The path from the root node to the node .
* /
function createPathToNode ( node , rootNode , path ) {
2021-05-19 11:09:27 -04:00
const parentNode = node . parentNode ;
let i = 0 ;
2018-12-13 23:41:57 -05:00
while ( node = node . previousSibling ) {
i ++ ;
}
2021-05-19 11:09:27 -04:00
path = [ i , ... path ] ;
2018-12-13 23:41:57 -05:00
if ( parentNode !== rootNode ) {
path = createPathToNode ( parentNode , rootNode , path ) ;
}
return path ;
}
/ * *
* Gets a node given a path ( array of indices ) from the given node .
*
* @ param { HTMLElement } node Root node to find the wanted node in .
* @ param { Array } path Path ( indices ) to the wanted node .
*
* @ return { Object } Object with the found node and the remaining offset ( if any ) .
* /
function getNodeByPath ( node , path ) {
2021-05-19 11:09:27 -04:00
path = [ ... path ] ;
2018-12-13 23:41:57 -05:00
while ( node && path . length > 1 ) {
node = node . childNodes [ path . shift ( ) ] ;
}
return {
2021-05-19 11:09:27 -04:00
node ,
2018-12-13 23:41:57 -05:00
offset : path [ 0 ]
} ;
}
2018-12-17 22:14:52 -05:00
function to _dom _append ( element , child ) {
2018-12-13 23:41:57 -05:00
if ( typeof child === 'string' ) {
child = element . ownerDocument . createTextNode ( child ) ;
}
2021-05-19 11:09:27 -04:00
const {
type ,
attributes
} = child ;
2018-12-13 23:41:57 -05:00
if ( type ) {
child = element . ownerDocument . createElement ( type ) ;
2021-05-19 11:09:27 -04:00
for ( const key in attributes ) {
2018-12-13 23:41:57 -05:00
child . setAttribute ( key , attributes [ key ] ) ;
}
}
return element . appendChild ( child ) ;
}
2018-12-17 22:14:52 -05:00
function to _dom _appendText ( node , text ) {
2018-12-13 23:41:57 -05:00
node . appendData ( text ) ;
}
2021-11-15 07:50:17 -05:00
function to _dom _getLastChild ( _ref ) {
let {
lastChild
} = _ref ;
2018-12-13 23:41:57 -05:00
return lastChild ;
}
2021-11-15 07:50:17 -05:00
function to _dom _getParent ( _ref2 ) {
let {
parentNode
} = _ref2 ;
2018-12-13 23:41:57 -05:00
return parentNode ;
}
2020-06-26 09:33:47 -04:00
function to _dom _isText ( node ) {
return node . nodeType === node . TEXT _NODE ;
2018-12-13 23:41:57 -05:00
}
2021-11-15 07:50:17 -05:00
function to _dom _getText ( _ref3 ) {
let {
nodeValue
} = _ref3 ;
2018-12-13 23:41:57 -05:00
return nodeValue ;
}
2018-12-17 22:14:52 -05:00
function to _dom _remove ( node ) {
2018-12-13 23:41:57 -05:00
return node . parentNode . removeChild ( node ) ;
}
2021-11-15 07:50:17 -05:00
function toDom ( _ref4 ) {
let {
value ,
multilineTag ,
prepareEditableTree ,
isEditableTree = true ,
placeholder ,
doc = document
} = _ref4 ;
2021-05-19 11:09:27 -04:00
let startPath = [ ] ;
let endPath = [ ] ;
2019-09-19 11:19:18 -04:00
if ( prepareEditableTree ) {
2021-05-19 11:09:27 -04:00
value = { ... value ,
2019-09-19 11:19:18 -04:00
formats : prepareEditableTree ( value )
2021-05-19 11:09:27 -04:00
} ;
2019-09-19 11:19:18 -04:00
}
2020-06-26 09:33:47 -04:00
/ * *
* Returns a new instance of a DOM tree upon which RichText operations can be
* applied .
*
* Note : The current implementation will return a shared reference , reset on
* each call to ` createEmpty ` . Therefore , you should not hold a reference to
* the value to operate upon asynchronously , as it may have unexpected results .
*
* @ return { Object } RichText tree .
* /
2021-05-19 11:09:27 -04:00
const createEmpty = ( ) => createElement ( doc , '' ) ;
2019-09-19 11:19:18 -04:00
2021-05-19 11:09:27 -04:00
const tree = toTree ( {
value ,
multilineTag ,
createEmpty ,
2018-12-17 22:14:52 -05:00
append : to _dom _append ,
getLastChild : to _dom _getLastChild ,
getParent : to _dom _getParent ,
isText : to _dom _isText ,
getText : to _dom _getText ,
remove : to _dom _remove ,
appendText : to _dom _appendText ,
2021-05-19 11:09:27 -04:00
onStartIndex ( body , pointer ) {
2018-12-13 23:41:57 -05:00
startPath = createPathToNode ( pointer , body , [ pointer . nodeValue . length ] ) ;
} ,
2021-05-19 11:09:27 -04:00
onEndIndex ( body , pointer ) {
2018-12-13 23:41:57 -05:00
endPath = createPathToNode ( pointer , body , [ pointer . nodeValue . length ] ) ;
} ,
2021-05-19 11:09:27 -04:00
isEditableTree ,
placeholder
2018-12-13 23:41:57 -05:00
} ) ;
return {
body : tree ,
selection : {
2021-05-19 11:09:27 -04:00
startPath ,
endPath
2018-12-13 23:41:57 -05:00
}
} ;
}
/ * *
* Create an ` Element ` tree from a Rich Text value and applies the difference to
* the ` Element ` tree contained by ` current ` . If a ` multilineTag ` is provided ,
* text separated by two new lines will be wrapped in an ` Element ` of that type .
*
2020-10-13 09:10:30 -04:00
* @ param { Object } $1 Named arguments .
* @ param { RichTextValue } $1 . value Value to apply .
* @ param { HTMLElement } $1 . current The live root node to apply the element tree to .
* @ param { string } [ $1 . multilineTag ] Multiline tag .
* @ param { Function } [ $1 . prepareEditableTree ] Function to filter editorable formats .
* @ param { boolean } [ $1 . _ _unstableDomOnly ] Only apply elements , no selection .
* @ param { string } [ $1 . placeholder ] Placeholder text .
2018-12-13 23:41:57 -05:00
* /
2021-11-15 07:50:17 -05:00
function apply ( _ref5 ) {
let {
value ,
current ,
multilineTag ,
prepareEditableTree ,
_ _unstableDomOnly ,
placeholder
} = _ref5 ;
2018-12-13 23:41:57 -05:00
// Construct a new element tree in memory.
2021-05-19 11:09:27 -04:00
const {
body ,
selection
} = toDom ( {
value ,
multilineTag ,
prepareEditableTree ,
placeholder ,
2020-06-26 09:33:47 -04:00
doc : current . ownerDocument
2021-05-19 11:09:27 -04:00
} ) ;
2018-12-13 23:41:57 -05:00
applyValue ( body , current ) ;
2019-03-07 04:09:59 -05:00
if ( value . start !== undefined && ! _ _unstableDomOnly ) {
2018-12-13 23:41:57 -05:00
applySelection ( selection , current ) ;
}
}
function applyValue ( future , current ) {
2021-05-19 11:09:27 -04:00
let i = 0 ;
let futureChild ;
2018-12-13 23:41:57 -05:00
2018-12-18 22:16:48 -05:00
while ( futureChild = future . firstChild ) {
2021-05-19 11:09:27 -04:00
const currentChild = current . childNodes [ i ] ;
2018-12-13 23:41:57 -05:00
if ( ! currentChild ) {
2018-12-18 22:16:48 -05:00
current . appendChild ( futureChild ) ;
} else if ( ! currentChild . isEqualNode ( futureChild ) ) {
2020-06-26 09:33:47 -04:00
if ( currentChild . nodeName !== futureChild . nodeName || currentChild . nodeType === currentChild . TEXT _NODE && currentChild . data !== futureChild . data ) {
2019-03-07 04:09:59 -05:00
current . replaceChild ( futureChild , currentChild ) ;
} else {
2021-05-19 11:09:27 -04:00
const currentAttributes = currentChild . attributes ;
const futureAttributes = futureChild . attributes ;
2019-03-07 04:09:59 -05:00
if ( currentAttributes ) {
2021-05-19 11:09:27 -04:00
let ii = currentAttributes . length ; // Reverse loop because `removeAttribute` on `currentChild`
2019-09-19 11:19:18 -04:00
// changes `currentAttributes`.
while ( ii -- ) {
2021-05-19 11:09:27 -04:00
const {
name
} = currentAttributes [ ii ] ;
2019-03-07 04:09:59 -05:00
if ( ! futureChild . getAttribute ( name ) ) {
currentChild . removeAttribute ( name ) ;
}
}
}
if ( futureAttributes ) {
2021-05-19 11:09:27 -04:00
for ( let ii = 0 ; ii < futureAttributes . length ; ii ++ ) {
const {
name ,
value
} = futureAttributes [ ii ] ;
if ( currentChild . getAttribute ( name ) !== value ) {
currentChild . setAttribute ( name , value ) ;
2019-03-07 04:09:59 -05:00
}
}
}
applyValue ( futureChild , currentChild ) ;
future . removeChild ( futureChild ) ;
}
2018-12-13 23:41:57 -05:00
} else {
2018-12-18 22:16:48 -05:00
future . removeChild ( futureChild ) ;
2018-12-13 23:41:57 -05:00
}
i ++ ;
}
while ( current . childNodes [ i ] ) {
current . removeChild ( current . childNodes [ i ] ) ;
}
}
2018-12-18 22:16:48 -05:00
/ * *
* Returns true if two ranges are equal , or false otherwise . Ranges are
* considered equal if their start and end occur in the same container and
* offset .
*
* @ param { Range } a First range object to test .
* @ param { Range } b First range object to test .
*
* @ return { boolean } Whether the two ranges are equal .
* /
function isRangeEqual ( a , b ) {
return a . startContainer === b . startContainer && a . startOffset === b . startOffset && a . endContainer === b . endContainer && a . endOffset === b . endOffset ;
}
2021-11-15 07:50:17 -05:00
function applySelection ( _ref6 , current ) {
let {
startPath ,
endPath
} = _ref6 ;
2021-05-19 11:09:27 -04:00
const {
node : startContainer ,
offset : startOffset
} = getNodeByPath ( current , startPath ) ;
const {
node : endContainer ,
offset : endOffset
} = getNodeByPath ( current , endPath ) ;
const {
ownerDocument
} = current ;
const {
defaultView
} = ownerDocument ;
const selection = defaultView . getSelection ( ) ;
const range = ownerDocument . createRange ( ) ;
2019-03-07 04:09:59 -05:00
range . setStart ( startContainer , startOffset ) ;
2020-02-06 16:03:31 -05:00
range . setEnd ( endContainer , endOffset ) ;
2021-05-19 11:09:27 -04:00
const {
activeElement
} = ownerDocument ;
2018-12-13 23:41:57 -05:00
2019-03-07 04:09:59 -05:00
if ( selection . rangeCount > 0 ) {
2018-12-18 22:16:48 -05:00
// If the to be added range and the live range are the same, there's no
// need to remove the live range and add the equivalent range.
2019-03-07 04:09:59 -05:00
if ( isRangeEqual ( range , selection . getRangeAt ( 0 ) ) ) {
2018-12-18 22:16:48 -05:00
return ;
}
2019-03-07 04:09:59 -05:00
selection . removeAllRanges ( ) ;
2018-12-18 22:16:48 -05:00
}
2020-03-02 18:21:15 -05:00
selection . addRange ( range ) ; // This function is not intended to cause a shift in focus. Since the above
// selection manipulations may shift focus, ensure that focus is restored to
2020-03-23 19:40:19 -04:00
// its previous state.
2020-03-02 18:21:15 -05:00
2020-06-26 09:33:47 -04:00
if ( activeElement !== ownerDocument . activeElement ) {
2020-03-02 18:21:15 -05:00
// The `instanceof` checks protect against edge cases where the focused
// element is not of the interface HTMLElement (does not have a `focus`
// or `blur` property).
//
// See: https://github.com/Microsoft/TypeScript/issues/5901#issuecomment-431649653
2020-06-26 09:33:47 -04:00
if ( activeElement instanceof defaultView . HTMLElement ) {
2020-03-23 19:40:19 -04:00
activeElement . focus ( ) ;
2020-03-02 18:21:15 -05:00
}
}
2018-12-13 23:41:57 -05:00
}
2021-01-27 21:04:13 -05:00
// EXTERNAL MODULE: external ["wp","escapeHtml"]
2021-05-20 08:20:04 -04:00
var external _wp _escapeHtml _ = _ _webpack _require _ _ ( "Vx3V" ) ;
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/to-html-string.js
2018-12-13 23:41:57 -05:00
/ * *
2019-03-07 04:09:59 -05:00
* WordPress dependencies
2018-12-13 23:41:57 -05:00
* /
/ * *
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
2018-12-13 23:41:57 -05:00
/ * *
* Create an HTML string from a Rich Text value . If a ` multilineTag ` is
2018-12-15 06:00:40 -05:00
* provided , text separated by a line separator will be wrapped in it .
2018-12-13 23:41:57 -05:00
*
2020-10-13 09:10:30 -04:00
* @ param { Object } $1 Named argements .
* @ param { RichTextValue } $1 . value Rich text value .
* @ param { string } [ $1 . multilineTag ] Multiline tag .
* @ param { boolean } [ $1 . preserveWhiteSpace ] Whether or not to use newline
* characters for line breaks .
2018-12-13 23:41:57 -05:00
*
* @ return { string } HTML string .
* /
2021-11-15 07:50:17 -05:00
function toHTMLString ( _ref ) {
let {
value ,
multilineTag ,
preserveWhiteSpace
} = _ref ;
2021-05-19 11:09:27 -04:00
const tree = toTree ( {
value ,
multilineTag ,
preserveWhiteSpace ,
2018-12-17 22:14:52 -05:00
createEmpty : to _html _string _createEmpty ,
append : to _html _string _append ,
getLastChild : to _html _string _getLastChild ,
getParent : to _html _string _getParent ,
isText : to _html _string _isText ,
getText : to _html _string _getText ,
remove : to _html _string _remove ,
appendText : to _html _string _appendText
2018-12-13 23:41:57 -05:00
} ) ;
return createChildrenHTML ( tree . children ) ;
}
2018-12-17 22:14:52 -05:00
function to _html _string _createEmpty ( ) {
2018-12-15 06:00:40 -05:00
return { } ;
2018-12-13 23:41:57 -05:00
}
2021-11-15 07:50:17 -05:00
function to _html _string _getLastChild ( _ref2 ) {
let {
children
} = _ref2 ;
2018-12-13 23:41:57 -05:00
return children && children [ children . length - 1 ] ;
}
2018-12-17 22:14:52 -05:00
function to _html _string _append ( parent , object ) {
2018-12-13 23:41:57 -05:00
if ( typeof object === 'string' ) {
object = {
text : object
} ;
}
object . parent = parent ;
parent . children = parent . children || [ ] ;
parent . children . push ( object ) ;
return object ;
}
2018-12-17 22:14:52 -05:00
function to _html _string _appendText ( object , text ) {
2018-12-13 23:41:57 -05:00
object . text += text ;
}
2021-11-15 07:50:17 -05:00
function to _html _string _getParent ( _ref3 ) {
let {
parent
} = _ref3 ;
2018-12-13 23:41:57 -05:00
return parent ;
}
2021-11-15 07:50:17 -05:00
function to _html _string _isText ( _ref4 ) {
let {
text
} = _ref4 ;
2018-12-13 23:41:57 -05:00
return typeof text === 'string' ;
}
2021-11-15 07:50:17 -05:00
function to _html _string _getText ( _ref5 ) {
let {
text
} = _ref5 ;
2018-12-13 23:41:57 -05:00
return text ;
}
2018-12-17 22:14:52 -05:00
function to _html _string _remove ( object ) {
2021-05-19 11:09:27 -04:00
const index = object . parent . children . indexOf ( object ) ;
2018-12-13 23:41:57 -05:00
if ( index !== - 1 ) {
object . parent . children . splice ( index , 1 ) ;
}
return object ;
}
2021-11-15 07:50:17 -05:00
function createElementHTML ( _ref6 ) {
let {
type ,
attributes ,
object ,
children
} = _ref6 ;
2021-05-19 11:09:27 -04:00
let attributeString = '' ;
2018-12-13 23:41:57 -05:00
2021-05-19 11:09:27 -04:00
for ( const key in attributes ) {
2021-01-27 21:04:13 -05:00
if ( ! Object ( external _wp _escapeHtml _ [ "isValidAttributeName" ] ) ( key ) ) {
2018-12-13 23:53:54 -05:00
continue ;
}
2021-05-19 11:09:27 -04:00
attributeString += ` ${ key } =" ${ Object ( external _wp _escapeHtml _ [ "escapeAttribute" ] ) ( attributes [ key ] ) } " ` ;
2018-12-13 23:41:57 -05:00
}
if ( object ) {
2021-05-19 11:09:27 -04:00
return ` < ${ type } ${ attributeString } > ` ;
2018-12-13 23:41:57 -05:00
}
2021-05-19 11:09:27 -04:00
return ` < ${ type } ${ attributeString } > ${ createChildrenHTML ( children ) } </ ${ type } > ` ;
2018-12-13 23:41:57 -05:00
}
2021-11-15 07:50:17 -05:00
function createChildrenHTML ( ) {
let children = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : [ ] ;
2021-05-19 11:09:27 -04:00
return children . map ( child => {
2021-07-13 19:58:30 -04:00
if ( child . html !== undefined ) {
return child . html ;
}
2021-01-27 21:04:13 -05:00
return child . text === undefined ? createElementHTML ( child ) : Object ( external _wp _escapeHtml _ [ "escapeEditableHTML" ] ) ( child . text ) ;
2018-12-17 22:14:52 -05:00
} ) . join ( '' ) ;
}
2018-12-14 06:02:53 -05:00
2021-11-08 09:29:21 -05:00
// EXTERNAL MODULE: external ["wp","a11y"]
var external _wp _a11y _ = _ _webpack _require _ _ ( "gdqT" ) ;
// EXTERNAL MODULE: external ["wp","i18n"]
var external _wp _i18n _ = _ _webpack _require _ _ ( "l3Sj" ) ;
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/toggle-format.js
2021-11-08 09:29:21 -05:00
/ * *
* WordPress dependencies
* /
2018-12-14 06:02:53 -05:00
/ * *
* Internal dependencies
* /
2021-11-08 09:29:21 -05:00
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
/** @typedef {import('./create').RichTextFormat} RichTextFormat */
2018-12-14 06:02:53 -05:00
/ * *
* Toggles a format object to a Rich Text value at the current selection .
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value Value to modify .
* @ param { RichTextFormat } format Format to apply or remove .
2018-12-14 06:02:53 -05:00
*
2020-10-13 09:10:30 -04:00
* @ return { RichTextValue } A new value with the format applied or removed .
2018-12-14 06:02:53 -05:00
* /
function toggleFormat ( value , format ) {
2018-12-17 22:14:52 -05:00
if ( getActiveFormat ( value , format . type ) ) {
2021-11-08 09:29:21 -05:00
// For screen readers, will announce if formatting control is disabled.
if ( format . title ) {
// translators: %s: title of the formatting control
Object ( external _wp _a11y _ [ "speak" ] ) ( Object ( external _wp _i18n _ [ "sprintf" ] ) ( Object ( external _wp _i18n _ [ "__" ] ) ( '%s removed.' ) , format . title ) , 'assertive' ) ;
}
2018-12-17 22:14:52 -05:00
return removeFormat ( value , format . type ) ;
2021-11-08 09:29:21 -05:00
} // For screen readers, will announce if formatting control is enabled.
if ( format . title ) {
// translators: %s: title of the formatting control
Object ( external _wp _a11y _ [ "speak" ] ) ( Object ( external _wp _i18n _ [ "sprintf" ] ) ( Object ( external _wp _i18n _ [ "__" ] ) ( '%s applied.' ) , format . title ) , 'assertive' ) ;
2018-12-14 06:02:53 -05:00
}
2020-01-08 06:57:23 -05:00
return applyFormat ( value , format ) ;
}
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/unregister-format-type.js
/ * *
* WordPress dependencies
* /
2021-01-27 21:04:13 -05:00
/ * *
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
/** @typedef {import('./register-format-type').RichTextFormatType} RichTextFormatType */
2020-01-08 06:57:23 -05:00
/ * *
* Unregisters a format .
*
* @ param { string } name Format name .
*
2020-10-13 09:10:30 -04:00
* @ return { RichTextFormatType | undefined } The previous format value , if it has
* been successfully unregistered ;
* otherwise ` undefined ` .
2020-01-08 06:57:23 -05:00
* /
function unregisterFormatType ( name ) {
2021-05-19 11:09:27 -04:00
const oldFormat = Object ( external _wp _data _ [ "select" ] ) ( store ) . getFormatType ( name ) ;
2020-01-08 06:57:23 -05:00
if ( ! oldFormat ) {
2021-05-19 11:09:27 -04:00
window . console . error ( ` Format ${ name } is not registered. ` ) ;
2020-01-08 06:57:23 -05:00
return ;
}
2021-01-27 21:04:13 -05:00
Object ( external _wp _data _ [ "dispatch" ] ) ( store ) . removeFormatTypes ( name ) ;
2020-01-08 06:57:23 -05:00
return oldFormat ;
}
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/can-indent-list-items.js
/ * *
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
2020-01-08 06:57:23 -05:00
/ * *
* Checks if the selected list item can be indented .
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value Value to check .
2020-01-08 06:57:23 -05:00
*
* @ return { boolean } Whether or not the selected list item can be indented .
* /
function canIndentListItems ( value ) {
2021-05-19 11:09:27 -04:00
const lineIndex = getLineIndex ( value ) ; // There is only one line, so the line cannot be indented.
2020-01-08 06:57:23 -05:00
if ( lineIndex === undefined ) {
return false ;
}
2021-05-19 11:09:27 -04:00
const {
replacements
} = value ;
const previousLineIndex = getLineIndex ( value , lineIndex ) ;
const formatsAtLineIndex = replacements [ lineIndex ] || [ ] ;
const formatsAtPreviousLineIndex = replacements [ previousLineIndex ] || [ ] ; // If the indentation of the current line is greater than previous line,
2020-01-08 06:57:23 -05:00
// then the line cannot be furter indented.
return formatsAtLineIndex . length <= formatsAtPreviousLineIndex . length ;
2018-12-14 06:02:53 -05:00
}
2020-01-08 06:57:23 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/can-outdent-list-items.js
2018-12-14 06:02:53 -05:00
/ * *
2020-01-08 06:57:23 -05:00
* Internal dependencies
2018-12-14 06:02:53 -05:00
* /
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
2018-12-14 06:02:53 -05:00
/ * *
2020-01-08 06:57:23 -05:00
* Checks if the selected list item can be outdented .
2018-12-14 06:02:53 -05:00
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value Value to check .
2018-12-14 06:02:53 -05:00
*
2020-01-08 06:57:23 -05:00
* @ return { boolean } Whether or not the selected list item can be outdented .
2018-12-14 06:02:53 -05:00
* /
2020-01-08 06:57:23 -05:00
function canOutdentListItems ( value ) {
2021-05-19 11:09:27 -04:00
const {
replacements ,
start
} = value ;
const startingLineIndex = getLineIndex ( value , start ) ;
2020-01-08 06:57:23 -05:00
return replacements [ startingLineIndex ] !== undefined ;
2018-12-14 06:02:53 -05:00
}
2019-01-29 13:23:55 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/indent-list-items.js
/ * *
* Internal dependencies
* /
2020-01-08 06:57:23 -05:00
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
/** @typedef {import('./create').RichTextFormat} RichTextFormat */
2019-01-29 13:23:55 -05:00
/ * *
* Gets the line index of the first previous list item with higher indentation .
*
2021-11-08 09:29:21 -05:00
* @ param { RichTextValue } value Value to search .
* @ param { number } lineIndex Line index of the list item to compare
* with .
2019-01-29 13:23:55 -05:00
*
2020-10-13 09:10:30 -04:00
* @ return { number | void } The line index .
2019-01-29 13:23:55 -05:00
* /
2021-11-15 07:50:17 -05:00
function getTargetLevelLineIndex ( _ref , lineIndex ) {
let {
text ,
replacements
} = _ref ;
2021-05-19 11:09:27 -04:00
const startFormats = replacements [ lineIndex ] || [ ] ;
let index = lineIndex ;
2019-01-29 13:23:55 -05:00
while ( index -- >= 0 ) {
if ( text [ index ] !== LINE _SEPARATOR ) {
continue ;
}
2021-05-19 11:09:27 -04:00
const formatsAtIndex = replacements [ index ] || [ ] ; // Return the first line index that is one level higher. If the level is
2019-01-29 13:23:55 -05:00
// lower or equal, there is no result.
if ( formatsAtIndex . length === startFormats . length + 1 ) {
return index ;
} else if ( formatsAtIndex . length <= startFormats . length ) {
return ;
}
}
}
/ * *
* Indents any selected list items if possible .
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value Value to change .
* @ param { RichTextFormat } rootFormat Root format .
2019-01-29 13:23:55 -05:00
*
2020-10-13 09:10:30 -04:00
* @ return { RichTextValue } The changed value .
2019-01-29 13:23:55 -05:00
* /
function indentListItems ( value , rootFormat ) {
2020-01-08 06:57:23 -05:00
if ( ! canIndentListItems ( value ) ) {
2019-01-29 13:23:55 -05:00
return value ;
}
2021-05-19 11:09:27 -04:00
const lineIndex = getLineIndex ( value ) ;
const previousLineIndex = getLineIndex ( value , lineIndex ) ;
const {
text ,
replacements ,
end
} = value ;
const newFormats = replacements . slice ( ) ;
const targetLevelLineIndex = getTargetLevelLineIndex ( value , lineIndex ) ;
for ( let index = lineIndex ; index < end ; index ++ ) {
2019-01-29 13:23:55 -05:00
if ( text [ index ] !== LINE _SEPARATOR ) {
continue ;
} // Get the previous list, and if there's a child list, take over the
// formats. If not, duplicate the last level and create a new level.
if ( targetLevelLineIndex ) {
2021-05-19 11:09:27 -04:00
const targetFormats = replacements [ targetLevelLineIndex ] || [ ] ;
2019-01-29 13:23:55 -05:00
newFormats [ index ] = targetFormats . concat ( ( newFormats [ index ] || [ ] ) . slice ( targetFormats . length - 1 ) ) ;
} else {
2021-05-19 11:09:27 -04:00
const targetFormats = replacements [ previousLineIndex ] || [ ] ;
const lastformat = targetFormats [ targetFormats . length - 1 ] || rootFormat ;
newFormats [ index ] = targetFormats . concat ( [ lastformat ] , ( newFormats [ index ] || [ ] ) . slice ( targetFormats . length ) ) ;
2019-01-29 13:23:55 -05:00
}
}
2021-05-19 11:09:27 -04:00
return { ... value ,
2019-03-21 08:48:00 -04:00
replacements : newFormats
2021-05-19 11:09:27 -04:00
} ;
2019-01-29 13:23:55 -05:00
}
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-parent-line-index.js
/ * *
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
2019-01-29 13:23:55 -05:00
/ * *
* Gets the index of the first parent list . To get the parent list formats , we
* go through every list item until we find one with exactly one format type
* less .
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value Value to search .
* @ param { number } lineIndex Line index of a child list item .
2019-01-29 13:23:55 -05:00
*
2020-10-13 09:10:30 -04:00
* @ return { number | void } The parent list line index .
2019-01-29 13:23:55 -05:00
* /
2021-11-15 07:50:17 -05:00
function getParentLineIndex ( _ref , lineIndex ) {
let {
text ,
replacements
} = _ref ;
2021-05-19 11:09:27 -04:00
const startFormats = replacements [ lineIndex ] || [ ] ;
let index = lineIndex ;
2019-01-29 13:23:55 -05:00
while ( index -- >= 0 ) {
if ( text [ index ] !== LINE _SEPARATOR ) {
continue ;
}
2021-05-19 11:09:27 -04:00
const formatsAtIndex = replacements [ index ] || [ ] ;
2019-01-29 13:23:55 -05:00
if ( formatsAtIndex . length === startFormats . length - 1 ) {
return index ;
}
}
}
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-last-child-index.js
/ * *
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
2019-01-29 13:23:55 -05:00
/ * *
* Gets the line index of the last child in the list .
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value Value to search .
* @ param { number } lineIndex Line index of a list item in the list .
2019-01-29 13:23:55 -05:00
*
2020-10-13 09:10:30 -04:00
* @ return { number } The index of the last child .
2019-01-29 13:23:55 -05:00
* /
2021-11-15 07:50:17 -05:00
function getLastChildIndex ( _ref , lineIndex ) {
let {
text ,
replacements
} = _ref ;
2021-05-19 11:09:27 -04:00
const lineFormats = replacements [ lineIndex ] || [ ] ; // Use the given line index in case there are no next children.
2019-01-29 13:23:55 -05:00
2021-05-19 11:09:27 -04:00
let childIndex = lineIndex ; // `lineIndex` could be `undefined` if it's the first line.
2019-01-29 13:23:55 -05:00
2021-05-19 11:09:27 -04:00
for ( let index = lineIndex || 0 ; index < text . length ; index ++ ) {
2019-01-29 13:23:55 -05:00
// We're only interested in line indices.
if ( text [ index ] !== LINE _SEPARATOR ) {
continue ;
}
2021-05-19 11:09:27 -04:00
const formatsAtIndex = replacements [ index ] || [ ] ; // If the amout of formats is equal or more, store it, then return the
2019-01-29 13:23:55 -05:00
// last one if the amount of formats is less.
if ( formatsAtIndex . length >= lineFormats . length ) {
childIndex = index ;
} else {
return childIndex ;
}
} // If the end of the text is reached, return the last child index.
return childIndex ;
}
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/outdent-list-items.js
/ * *
* Internal dependencies
* /
2020-01-08 06:57:23 -05:00
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
2019-01-29 13:23:55 -05:00
/ * *
* Outdents any selected list items if possible .
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value Value to change .
2019-01-29 13:23:55 -05:00
*
2020-10-13 09:10:30 -04:00
* @ return { RichTextValue } The changed value .
2019-01-29 13:23:55 -05:00
* /
function outdentListItems ( value ) {
2020-01-08 06:57:23 -05:00
if ( ! canOutdentListItems ( value ) ) {
return value ;
}
2021-05-19 11:09:27 -04:00
const {
text ,
replacements ,
start ,
end
} = value ;
const startingLineIndex = getLineIndex ( value , start ) ;
const newFormats = replacements . slice ( 0 ) ;
const parentFormats = replacements [ getParentLineIndex ( value , startingLineIndex ) ] || [ ] ;
const endingLineIndex = getLineIndex ( value , end ) ;
const lastChildIndex = getLastChildIndex ( value , endingLineIndex ) ; // Outdent all list items from the starting line index until the last child
2019-01-29 13:23:55 -05:00
// index of the ending list. All children of the ending list need to be
// outdented, otherwise they'll be orphaned.
2021-05-19 11:09:27 -04:00
for ( let index = startingLineIndex ; index <= lastChildIndex ; index ++ ) {
2019-01-29 13:23:55 -05:00
// Skip indices that are not line separators.
if ( text [ index ] !== LINE _SEPARATOR ) {
continue ;
} // In the case of level 0, the formats at the index are undefined.
2021-05-19 11:09:27 -04:00
const currentFormats = newFormats [ index ] || [ ] ; // Omit the indentation level where the selection starts.
2019-01-29 13:23:55 -05:00
newFormats [ index ] = parentFormats . concat ( currentFormats . slice ( parentFormats . length + 1 ) ) ;
if ( newFormats [ index ] . length === 0 ) {
delete newFormats [ index ] ;
}
}
2021-05-19 11:09:27 -04:00
return { ... value ,
2019-03-21 08:48:00 -04:00
replacements : newFormats
2021-05-19 11:09:27 -04:00
} ;
2019-01-29 13:23:55 -05:00
}
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/change-list-type.js
/ * *
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
/** @typedef {import('./create').RichTextFormat} RichTextFormat */
2019-01-29 13:23:55 -05:00
/ * *
* Changes the list type of the selected indented list , if any . Looks at the
* currently selected list item and takes the parent list , then changes the list
2019-03-07 04:09:59 -05:00
* type of this list . When multiple lines are selected , the parent lists are
* takes and changed .
2018-12-14 06:02:53 -05:00
*
2020-10-13 09:10:30 -04:00
* @ param { RichTextValue } value Value to change .
* @ param { RichTextFormat } newFormat The new list format object . Choose between
* ` { type: 'ol' } ` and ` { type: 'ul' } ` .
2018-12-14 06:02:53 -05:00
*
2020-10-13 09:10:30 -04:00
* @ return { RichTextValue } The changed value .
2018-12-14 06:02:53 -05:00
* /
2019-03-07 04:09:59 -05:00
function changeListType ( value , newFormat ) {
2021-05-19 11:09:27 -04:00
const {
text ,
replacements ,
start ,
end
} = value ;
const startingLineIndex = getLineIndex ( value , start ) ;
const startLineFormats = replacements [ startingLineIndex ] || [ ] ;
const endLineFormats = replacements [ getLineIndex ( value , end ) ] || [ ] ;
const startIndex = getParentLineIndex ( value , startingLineIndex ) ;
const newReplacements = replacements . slice ( ) ;
const startCount = startLineFormats . length - 1 ;
const endCount = endLineFormats . length - 1 ;
let changed ;
for ( let index = startIndex + 1 || 0 ; index < text . length ; index ++ ) {
2019-03-07 04:09:59 -05:00
if ( text [ index ] !== LINE _SEPARATOR ) {
continue ;
}
2018-12-14 06:02:53 -05:00
2019-03-21 08:48:00 -04:00
if ( ( newReplacements [ index ] || [ ] ) . length <= startCount ) {
2019-03-07 04:09:59 -05:00
break ;
}
2019-03-21 08:48:00 -04:00
if ( ! newReplacements [ index ] ) {
2019-03-07 04:09:59 -05:00
continue ;
}
changed = true ;
2021-05-19 11:09:27 -04:00
newReplacements [ index ] = newReplacements [ index ] . map ( ( format , i ) => {
2019-03-07 04:09:59 -05:00
return i < startCount || i > endCount ? format : newFormat ;
} ) ;
}
if ( ! changed ) {
return value ;
}
2021-05-19 11:09:27 -04:00
return { ... value ,
2019-03-21 08:48:00 -04:00
replacements : newReplacements
2021-05-19 11:09:27 -04:00
} ;
2018-12-14 06:02:53 -05:00
}
2021-01-27 21:04:13 -05:00
// EXTERNAL MODULE: external ["wp","element"]
2021-05-20 08:20:04 -04:00
var external _wp _element _ = _ _webpack _require _ _ ( "GRId" ) ;
2021-01-27 21:04:13 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-anchor-ref.js
/ * *
* WordPress dependencies
* /
2019-09-19 11:19:18 -04:00
2021-01-27 21:04:13 -05:00
/ * *
* Internal dependencies
* /
2020-01-22 17:06:21 -05:00
2019-09-19 11:19:18 -04:00
2021-01-27 21:04:13 -05:00
/** @typedef {import('@wordpress/element').RefObject} RefObject */
2019-09-19 11:19:18 -04:00
2021-01-27 21:04:13 -05:00
/** @typedef {import('../register-format-type').RichTextFormatType} RichTextFormatType */
2019-09-19 11:19:18 -04:00
2021-01-27 21:04:13 -05:00
/** @typedef {import('../create').RichTextValue} RichTextValue */
2019-09-19 11:19:18 -04:00
/ * *
2021-01-27 21:04:13 -05:00
* This hook , to be used in a format type ' s Edit component , returns the active
* element that is formatted , or the selection range if no format is active .
* The returned value is meant to be used for positioning UI , e . g . by passing it
* to the ` Popover ` component .
*
* @ param { Object } $1 Named parameters .
* @ param { RefObject < HTMLElement > } $1 . ref React ref of the element
* containing the editable content .
* @ param { RichTextValue } $1 . value Value to check for selection .
* @ param { RichTextFormatType } $1 . settings The format type ' s settings .
*
* @ return { Element | Range } The active element or selection range .
2019-09-19 11:19:18 -04:00
* /
2021-11-15 07:50:17 -05:00
function useAnchorRef ( _ref ) {
let {
ref ,
value ,
settings = { }
} = _ref ;
2021-05-19 11:09:27 -04:00
const {
tagName ,
className ,
name
} = settings ;
const activeFormat = name ? getActiveFormat ( value , name ) : undefined ;
return Object ( external _wp _element _ [ "useMemo" ] ) ( ( ) => {
2021-01-27 21:04:13 -05:00
if ( ! ref . current ) return ;
2021-05-19 11:09:27 -04:00
const {
ownerDocument : {
defaultView
}
} = ref . current ;
const selection = defaultView . getSelection ( ) ;
2021-01-27 21:04:13 -05:00
if ( ! selection . rangeCount ) {
return ;
}
2021-05-19 11:09:27 -04:00
const range = selection . getRangeAt ( 0 ) ;
2021-01-27 21:04:13 -05:00
if ( ! activeFormat ) {
return range ;
}
2021-05-19 11:09:27 -04:00
let element = range . startContainer ; // If the caret is right before the element, select the next element.
2021-01-27 21:04:13 -05:00
element = element . nextElementSibling || element ;
while ( element . nodeType !== element . ELEMENT _NODE ) {
element = element . parentNode ;
}
return element . closest ( tagName + ( className ? '.' + className : '' ) ) ;
} , [ activeFormat , value . start , value . end , tagName , className ] ) ;
}
2021-04-15 11:19:43 -04:00
// EXTERNAL MODULE: external ["wp","compose"]
2021-05-20 08:20:04 -04:00
var external _wp _compose _ = _ _webpack _require _ _ ( "K9lf" ) ;
2021-04-15 11:19:43 -04:00
2021-05-21 06:14:23 -04:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-default-style.js
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-05-21 06:14:23 -04:00
* WordPress dependencies
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-05-21 06:14:23 -04:00
* In HTML , leading and trailing spaces are not visible , and multiple spaces
* elsewhere are visually reduced to one space . This rule prevents spaces from
* collapsing so all space is visible in the editor and can be removed . It also
* prevents some browsers from inserting non - breaking spaces at the end of a
* line to prevent the space from visually disappearing . Sometimes these non
* breaking spaces can linger in the editor causing unwanted non breaking spaces
* in between words . If also prevent Firefox from inserting a trailing ` br ` node
* to visualise any trailing space , causing the element to be saved .
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-05-21 06:14:23 -04:00
* > Authors are encouraged to set the 'white-space' property on editing hosts
* > and on markup that was originally created through these editing mechanisms
* > to the value 'pre-wrap' . Default HTML whitespace handling is not well
* > suited to WYSIWYG editing , and line wrapping will not work correctly in
* > some corner cases if 'white-space' is left at its default value .
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-05-21 06:14:23 -04:00
* https : //html.spec.whatwg.org/multipage/interaction.html#best-practices-for-in-page-editors
2021-01-27 21:04:13 -05:00
*
2021-05-21 06:14:23 -04:00
* @ type { string }
2021-01-27 21:04:13 -05:00
* /
2021-05-21 06:14:23 -04:00
const whiteSpace = 'pre-wrap' ;
2020-01-22 17:06:21 -05:00
/ * *
2021-05-21 06:14:23 -04:00
* A minimum width of 1 px will prevent the rich text container from collapsing
* to 0 width and hiding the caret . This is useful for inline containers .
2020-01-22 17:06:21 -05:00
* /
2021-05-21 06:14:23 -04:00
const minWidth = '1px' ;
function useDefaultStyle ( ) {
return Object ( external _wp _element _ [ "useCallback" ] ) ( element => {
if ( ! element ) return ;
element . style . whiteSpace = whiteSpace ;
element . style . minWidth = minWidth ;
} , [ ] ) ;
2020-01-22 17:06:21 -05:00
}
2020-06-26 09:33:47 -04:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-boundary-style.js
2020-01-22 17:06:21 -05:00
/ * *
* WordPress dependencies
* /
2020-10-13 09:10:30 -04:00
/ *
2020-01-22 17:06:21 -05:00
* Calculates and renders the format boundary style when the active formats
* change .
* /
2021-11-15 07:50:17 -05:00
function useBoundaryStyle ( _ref ) {
let {
record
} = _ref ;
2021-05-21 06:14:23 -04:00
const ref = Object ( external _wp _element _ [ "useRef" ] ) ( ) ;
const {
activeFormats = [ ]
} = record . current ;
2021-05-19 11:09:27 -04:00
Object ( external _wp _element _ [ "useEffect" ] ) ( ( ) => {
2020-01-22 17:06:21 -05:00
// There's no need to recalculate the boundary styles if no formats are
// active, because no boundary styles will be visible.
if ( ! activeFormats || ! activeFormats . length ) {
return ;
}
2021-05-19 11:09:27 -04:00
const boundarySelector = '*[data-rich-text-format-boundary]' ;
const element = ref . current . querySelector ( boundarySelector ) ;
2020-01-22 17:06:21 -05:00
if ( ! element ) {
return ;
}
2021-05-19 11:09:27 -04:00
const {
ownerDocument
} = element ;
const {
defaultView
} = ownerDocument ;
const computedStyle = defaultView . getComputedStyle ( element ) ;
const newColor = computedStyle . color . replace ( ')' , ', 0.2)' ) . replace ( 'rgb' , 'rgba' ) ;
const selector = ` .rich-text:focus ${ boundarySelector } ` ;
const rule = ` background-color: ${ newColor } ` ;
const style = ` ${ selector } { ${ rule } } ` ;
const globalStyleId = 'rich-text-boundary-style' ;
let globalStyle = ownerDocument . getElementById ( globalStyleId ) ;
2020-06-26 09:33:47 -04:00
if ( ! globalStyle ) {
globalStyle = ownerDocument . createElement ( 'style' ) ;
globalStyle . id = globalStyleId ;
ownerDocument . head . appendChild ( globalStyle ) ;
}
2020-01-22 17:06:21 -05:00
if ( globalStyle . innerHTML !== style ) {
globalStyle . innerHTML = style ;
}
} , [ activeFormats ] ) ;
2021-05-21 06:14:23 -04:00
return ref ;
2020-01-22 17:06:21 -05:00
}
2021-04-15 11:19:43 -04:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-copy-handler.js
/ * *
* WordPress dependencies
* /
2021-05-19 11:09:27 -04:00
2021-04-15 11:19:43 -04:00
/ * *
* Internal dependencies
* /
2021-05-19 11:09:27 -04:00
function useCopyHandler ( props ) {
const propsRef = Object ( external _wp _element _ [ "useRef" ] ) ( props ) ;
propsRef . current = props ;
return Object ( external _wp _compose _ [ "useRefEffect" ] ) ( element => {
2021-04-15 11:19:43 -04:00
function onCopy ( event ) {
2021-05-19 11:09:27 -04:00
const {
record ,
multilineTag ,
preserveWhiteSpace
} = propsRef . current ;
2021-04-15 11:19:43 -04:00
if ( isCollapsed ( record . current ) || ! element . contains ( element . ownerDocument . activeElement ) ) {
return ;
}
2021-05-19 11:09:27 -04:00
const selectedRecord = slice ( record . current ) ;
const plainText = getTextContent ( selectedRecord ) ;
const html = toHTMLString ( {
2021-04-15 11:19:43 -04:00
value : selectedRecord ,
2021-05-19 11:09:27 -04:00
multilineTag ,
preserveWhiteSpace
2021-04-15 11:19:43 -04:00
} ) ;
event . clipboardData . setData ( 'text/plain' , plainText ) ;
event . clipboardData . setData ( 'text/html' , html ) ;
event . clipboardData . setData ( 'rich-text' , 'true' ) ;
2021-11-08 09:29:21 -05:00
event . clipboardData . setData ( 'rich-text-multi-line-tag' , multilineTag || '' ) ;
2021-04-15 11:19:43 -04:00
event . preventDefault ( ) ;
}
element . addEventListener ( 'copy' , onCopy ) ;
2021-05-19 11:09:27 -04:00
return ( ) => {
2021-04-15 11:19:43 -04:00
element . removeEventListener ( 'copy' , onCopy ) ;
} ;
2021-05-19 11:09:27 -04:00
} , [ ] ) ;
2021-04-15 11:19:43 -04:00
}
2021-05-21 06:14:23 -04:00
// EXTERNAL MODULE: external ["wp","keycodes"]
var external _wp _keycodes _ = _ _webpack _require _ _ ( "RxS6" ) ;
2021-05-19 11:09:27 -04:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-format-boundaries.js
/ * *
* WordPress dependencies
* /
/ * *
* Internal dependencies
* /
const EMPTY _ACTIVE _FORMATS = [ ] ;
function useFormatBoundaries ( props ) {
2021-05-21 06:14:23 -04:00
const [ , forceRender ] = Object ( external _wp _element _ [ "useReducer" ] ) ( ( ) => ( { } ) ) ;
2021-05-19 11:09:27 -04:00
const propsRef = Object ( external _wp _element _ [ "useRef" ] ) ( props ) ;
propsRef . current = props ;
return Object ( external _wp _compose _ [ "useRefEffect" ] ) ( element => {
function onKeyDown ( event ) {
const {
keyCode ,
shiftKey ,
altKey ,
metaKey ,
ctrlKey
} = event ;
if ( // Only override left and right keys without modifiers pressed.
shiftKey || altKey || metaKey || ctrlKey || keyCode !== external _wp _keycodes _ [ "LEFT" ] && keyCode !== external _wp _keycodes _ [ "RIGHT" ] ) {
return ;
}
const {
record ,
2021-05-21 06:14:23 -04:00
applyRecord
2021-05-19 11:09:27 -04:00
} = propsRef . current ;
const {
text ,
formats ,
start ,
end ,
activeFormats : currentActiveFormats = [ ]
} = record . current ;
const collapsed = isCollapsed ( record . current ) ;
const {
ownerDocument
} = element ;
const {
defaultView
} = ownerDocument ; // To do: ideally, we should look at visual position instead.
const {
direction
} = defaultView . getComputedStyle ( element ) ;
const reverseKey = direction === 'rtl' ? external _wp _keycodes _ [ "RIGHT" ] : external _wp _keycodes _ [ "LEFT" ] ;
const isReverse = event . keyCode === reverseKey ; // If the selection is collapsed and at the very start, do nothing if
// navigating backward.
// If the selection is collapsed and at the very end, do nothing if
// navigating forward.
if ( collapsed && currentActiveFormats . length === 0 ) {
if ( start === 0 && isReverse ) {
return ;
}
2018-12-14 06:02:53 -05:00
2021-05-19 11:09:27 -04:00
if ( end === text . length && ! isReverse ) {
return ;
}
} // If the selection is not collapsed, let the browser handle collapsing
// the selection for now. Later we could expand this logic to set
// boundary positions if needed.
2018-12-14 06:02:53 -05:00
2021-05-19 11:09:27 -04:00
if ( ! collapsed ) {
return ;
}
2018-12-14 06:02:53 -05:00
2021-05-19 11:09:27 -04:00
const formatsBefore = formats [ start - 1 ] || EMPTY _ACTIVE _FORMATS ;
const formatsAfter = formats [ start ] || EMPTY _ACTIVE _FORMATS ;
2021-11-08 09:29:21 -05:00
const destination = isReverse ? formatsBefore : formatsAfter ;
const isIncreasing = currentActiveFormats . every ( ( format , index ) => format === destination [ index ] ) ;
2021-05-19 11:09:27 -04:00
let newActiveFormatsLength = currentActiveFormats . length ;
2021-01-27 21:04:13 -05:00
2021-11-08 09:29:21 -05:00
if ( ! isIncreasing ) {
newActiveFormatsLength -- ;
} else if ( newActiveFormatsLength < destination . length ) {
newActiveFormatsLength ++ ;
2021-05-19 11:09:27 -04:00
}
if ( newActiveFormatsLength === currentActiveFormats . length ) {
2021-11-08 09:29:21 -05:00
record . current . _newActiveFormats = destination ;
2021-05-19 11:09:27 -04:00
return ;
}
event . preventDefault ( ) ;
2021-11-08 09:29:21 -05:00
const origin = isReverse ? formatsAfter : formatsBefore ;
const source = isIncreasing ? destination : origin ;
2021-05-19 11:09:27 -04:00
const newActiveFormats = source . slice ( 0 , newActiveFormatsLength ) ;
const newValue = { ... record . current ,
activeFormats : newActiveFormats
} ;
record . current = newValue ;
applyRecord ( newValue ) ;
2021-05-21 06:14:23 -04:00
forceRender ( ) ;
2021-05-19 11:09:27 -04:00
}
element . addEventListener ( 'keydown' , onKeyDown ) ;
return ( ) => {
element . removeEventListener ( 'keydown' , onKeyDown ) ;
} ;
} , [ ] ) ;
}
2021-05-21 06:14:23 -04:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-select-object.js
2021-05-19 11:09:27 -04:00
/ * *
* WordPress dependencies
* /
2021-05-21 06:14:23 -04:00
function useSelectObject ( ) {
2021-05-19 11:09:27 -04:00
return Object ( external _wp _compose _ [ "useRefEffect" ] ) ( element => {
2021-05-21 06:14:23 -04:00
function onClick ( event ) {
2021-05-19 11:09:27 -04:00
const {
2021-05-21 06:14:23 -04:00
target
} = event ; // If the child element has no text content, it must be an object.
2021-05-19 11:09:27 -04:00
2021-05-21 06:14:23 -04:00
if ( target === element || target . textContent ) {
2021-05-19 11:09:27 -04:00
return ;
}
2021-05-21 06:14:23 -04:00
const {
ownerDocument
} = target ;
const {
defaultView
} = ownerDocument ;
const range = ownerDocument . createRange ( ) ;
const selection = defaultView . getSelection ( ) ;
range . selectNode ( target ) ;
selection . removeAllRanges ( ) ;
selection . addRange ( range ) ;
2021-05-19 11:09:27 -04:00
}
2021-05-21 06:14:23 -04:00
element . addEventListener ( 'click' , onClick ) ;
2021-05-19 11:09:27 -04:00
return ( ) => {
2021-05-21 06:14:23 -04:00
element . removeEventListener ( 'click' , onClick ) ;
2021-05-19 11:09:27 -04:00
} ;
} , [ ] ) ;
}
2021-05-21 06:14:23 -04:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-indent-list-item-on-space.js
2019-09-19 11:19:18 -04:00
/ * *
* WordPress dependencies
* /
2018-12-14 06:02:53 -05:00
2019-09-19 11:19:18 -04:00
/ * *
* Internal dependencies
* /
2018-12-14 06:02:53 -05:00
2021-05-21 06:14:23 -04:00
function useIndentListItemOnSpace ( props ) {
const propsRef = Object ( external _wp _element _ [ "useRef" ] ) ( props ) ;
propsRef . current = props ;
return Object ( external _wp _compose _ [ "useRefEffect" ] ) ( element => {
function onKeyDown ( event ) {
const {
keyCode ,
shiftKey ,
altKey ,
metaKey ,
ctrlKey
} = event ;
const {
multilineTag ,
createRecord ,
handleChange
} = propsRef . current ;
2018-12-14 06:02:53 -05:00
2021-05-21 06:14:23 -04:00
if ( // Only override when no modifiers are pressed.
shiftKey || altKey || metaKey || ctrlKey || keyCode !== external _wp _keycodes _ [ "SPACE" ] || multilineTag !== 'li' ) {
return ;
}
2018-12-14 06:02:53 -05:00
2021-05-21 06:14:23 -04:00
const currentValue = createRecord ( ) ;
2018-12-14 06:02:53 -05:00
2021-05-21 06:14:23 -04:00
if ( ! isCollapsed ( currentValue ) ) {
return ;
}
2018-12-14 06:02:53 -05:00
2021-05-21 06:14:23 -04:00
const {
text ,
start
} = currentValue ;
const characterBefore = text [ start - 1 ] ; // The caret must be at the start of a line.
2019-03-07 04:09:59 -05:00
2021-05-21 06:14:23 -04:00
if ( characterBefore && characterBefore !== LINE _SEPARATOR ) {
return ;
}
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-05-21 06:14:23 -04:00
handleChange ( indentListItems ( currentValue , {
type : element . tagName . toLowerCase ( )
} ) ) ;
event . preventDefault ( ) ;
}
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-05-21 06:14:23 -04:00
element . addEventListener ( 'keydown' , onKeyDown ) ;
return ( ) => {
element . removeEventListener ( 'keydown' , onKeyDown ) ;
} ;
} , [ ] ) ;
}
2018-12-14 06:02:53 -05:00
2021-05-21 06:14:23 -04:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/update-formats.js
/ * *
* Internal dependencies
* /
2018-12-14 06:02:53 -05:00
2021-05-21 06:14:23 -04:00
/** @typedef {import('./create').RichTextValue} RichTextValue */
2020-01-08 06:57:23 -05:00
2019-09-19 11:19:18 -04:00
/ * *
2021-05-21 06:14:23 -04:00
* Efficiently updates all the formats from ` start ` ( including ) until ` end `
* ( excluding ) with the active formats . Mutates ` value ` .
2019-09-19 11:19:18 -04:00
*
2021-11-08 09:29:21 -05:00
* @ param { Object } $1 Named paramentes .
* @ param { RichTextValue } $1 . value Value te update .
* @ param { number } $1 . start Index to update from .
* @ param { number } $1 . end Index to update until .
* @ param { Array } $1 . formats Replacement formats .
2019-09-19 11:19:18 -04:00
*
2021-05-21 06:14:23 -04:00
* @ return { RichTextValue } Mutated value .
2019-09-19 11:19:18 -04:00
* /
2018-12-17 22:14:52 -05:00
2021-11-15 07:50:17 -05:00
function updateFormats ( _ref ) {
let {
value ,
start ,
end ,
formats
} = _ref ;
2021-11-08 09:29:21 -05:00
// Start and end may be switched in case of delete.
const min = Math . min ( start , end ) ;
const max = Math . max ( start , end ) ;
const formatsBefore = value . formats [ min - 1 ] || [ ] ;
const formatsAfter = value . formats [ max ] || [ ] ; // First, fix the references. If any format right before or after are
2021-05-21 06:14:23 -04:00
// equal, the replacement format should use the same reference.
value . activeFormats = formats . map ( ( format , index ) => {
if ( formatsBefore [ index ] ) {
if ( isFormatEqual ( format , formatsBefore [ index ] ) ) {
return formatsBefore [ index ] ;
}
} else if ( formatsAfter [ index ] ) {
if ( isFormatEqual ( format , formatsAfter [ index ] ) ) {
return formatsAfter [ index ] ;
}
}
return format ;
} ) ;
while ( -- end >= start ) {
if ( value . activeFormats . length > 0 ) {
value . formats [ end ] = value . activeFormats ;
} else {
delete value . formats [ end ] ;
}
}
return value ;
}
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-input-and-selection.js
2020-01-08 06:57:23 -05:00
/ * *
2021-05-21 06:14:23 -04:00
* WordPress dependencies
2020-01-08 06:57:23 -05:00
* /
2021-05-21 06:14:23 -04:00
2021-04-15 11:19:43 -04:00
/ * *
2021-05-21 06:14:23 -04:00
* Internal dependencies
2021-04-15 11:19:43 -04:00
* /
2021-05-21 06:14:23 -04:00
2020-01-08 06:57:23 -05:00
/ * *
2021-05-21 06:14:23 -04:00
* All inserting input types that would insert HTML into the DOM .
*
* @ see https : //www.w3.org/TR/input-events-2/#interface-InputEvent-Attributes
2020-01-08 06:57:23 -05:00
*
2021-05-21 06:14:23 -04:00
* @ type { Set }
2020-01-08 06:57:23 -05:00
* /
2021-05-21 06:14:23 -04:00
const INSERTION _INPUT _TYPES _TO _IGNORE = new Set ( [ 'insertParagraph' , 'insertOrderedList' , 'insertUnorderedList' , 'insertHorizontalRule' , 'insertLink' ] ) ;
const use _input _and _selection _EMPTY _ACTIVE _FORMATS = [ ] ;
2019-10-15 12:17:12 -04:00
/ * *
* If the selection is set on the placeholder element , collapse the selection to
* the start ( before the placeholder ) .
2020-06-26 09:33:47 -04:00
*
* @ param { Window } defaultView
2019-10-15 12:17:12 -04:00
* /
2020-06-26 09:33:47 -04:00
function fixPlaceholderSelection ( defaultView ) {
2021-05-19 11:09:27 -04:00
const selection = defaultView . getSelection ( ) ;
const {
anchorNode ,
anchorOffset
} = selection ;
2019-10-15 12:17:12 -04:00
if ( anchorNode . nodeType !== anchorNode . ELEMENT _NODE ) {
return ;
}
2021-05-19 11:09:27 -04:00
const targetNode = anchorNode . childNodes [ anchorOffset ] ;
2019-10-15 12:17:12 -04:00
if ( ! targetNode || targetNode . nodeType !== targetNode . ELEMENT _NODE || ! targetNode . getAttribute ( 'data-rich-text-placeholder' ) ) {
return ;
}
selection . collapseToStart ( ) ;
}
Block Editor: Update WordPress packages to include the latest bug fixes.
Updated packages:
@wordpress/annotations@1.7.1
@wordpress/api-fetch@3.6.1
@wordpress/babel-plugin-makepot@3.2.1
@wordpress/babel-preset-default@4.6.1
@wordpress/block-directory@1.0.1
@wordpress/block-editor@3.2.1
@wordpress/block-library@2.9.1
@wordpress/blocks@6.7.1
@wordpress/components@8.3.1
@wordpress/compose@3.7.1
@wordpress/core-data@2.7.1
@wordpress/data-controls@1.3.1
@wordpress/data@4.9.1
@wordpress/docgen@1.4.1
@wordpress/dom@2.5.1
@wordpress/e2e-test-utils@2.4.1
@wordpress/e2e-tests@1.7.1
@wordpress/edit-post@3.8.1
@wordpress/editor@9.7.1
@wordpress/element@2.8.1
@wordpress/format-library@1.9.1
@wordpress/i18n@3.6.1
@wordpress/jest-console@3.3.1
@wordpress/jest-preset-default@5.1.1
@wordpress/keycodes@2.6.1
@wordpress/library-export-default-webpack-plugin@1.4.1
@wordpress/list-reusable-blocks@1.8.1
@wordpress/media-utils@1.2.1
@wordpress/notices@1.8.1
@wordpress/nux@3.7.1
@wordpress/plugins@2.7.1
@wordpress/redux-routine@3.6.1
@wordpress/rich-text@3.7.1
@wordpress/scripts@5.0.1
@wordpress/server-side-render@1.3.1
@wordpress/shortcode@2.4.1
@wordpress/token-list@1.6.1
@wordpress/viewport@2.8.1
@wordpress/wordcount@2.6.1
Props epiqueras, youknowriad, donmhico, jorgefilipecosta, soean, mcsf, noisysocks, andraganescu, gziolo, talldanwp, iseulde, nrqsnchz, mapk, karmatosed, joen, afercia, kjellr, desrosj.
Fixes #48186.
Built from https://develop.svn.wordpress.org/trunk@46364
git-svn-id: http://core.svn.wordpress.org/trunk@46163 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-30 16:07:06 -04:00
2021-05-21 06:14:23 -04:00
function useInputAndSelection ( props ) {
const propsRef = Object ( external _wp _element _ [ "useRef" ] ) ( props ) ;
propsRef . current = props ;
return Object ( external _wp _compose _ [ "useRefEffect" ] ) ( element => {
const {
ownerDocument
} = element ;
const {
defaultView
} = ownerDocument ;
let isComposing = false ;
let rafId ;
function onInput ( event ) {
// Do not trigger a change if characters are being composed.
// Browsers will usually emit a final `input` event when the
// characters are composed.
// As of December 2019, Safari doesn't support
// nativeEvent.isComposing.
if ( isComposing ) {
return ;
}
2020-06-26 09:33:47 -04:00
2021-05-21 06:14:23 -04:00
let inputType ;
2020-06-26 09:33:47 -04:00
2021-05-21 06:14:23 -04:00
if ( event ) {
inputType = event . inputType ;
2020-06-26 09:33:47 -04:00
}
2021-05-21 06:14:23 -04:00
const {
record ,
applyRecord ,
createRecord ,
handleChange
} = propsRef . current ; // The browser formatted something or tried to insert HTML.
// Overwrite it. It will be handled later by the format library if
// needed.
if ( inputType && ( inputType . indexOf ( 'format' ) === 0 || INSERTION _INPUT _TYPES _TO _IGNORE . has ( inputType ) ) ) {
applyRecord ( record . current ) ;
return ;
}
2020-06-26 09:33:47 -04:00
2021-05-21 06:14:23 -04:00
const currentValue = createRecord ( ) ;
const {
start ,
activeFormats : oldActiveFormats = [ ]
} = record . current ; // Update the formats between the last and new caret position.
2020-06-26 09:33:47 -04:00
2021-05-21 06:14:23 -04:00
const change = updateFormats ( {
value : currentValue ,
start ,
end : currentValue . start ,
formats : oldActiveFormats
} ) ;
handleChange ( change ) ;
2019-09-19 11:19:18 -04:00
}
2021-05-21 06:14:23 -04:00
/ * *
* Syncs the selection to local state . A callback for the ` selectionchange `
* native events , ` keyup ` , ` mouseup ` and ` touchend ` synthetic events , and
* animation frames after the ` focus ` event .
*
* @ param { Event | DOMHighResTimeStamp } event
* /
2020-06-26 09:33:47 -04:00
2019-09-19 11:19:18 -04:00
2021-05-21 06:14:23 -04:00
function handleSelectionChange ( event ) {
if ( ownerDocument . activeElement !== element ) {
return ;
}
2019-09-19 11:19:18 -04:00
2021-05-21 06:14:23 -04:00
const {
record ,
applyRecord ,
createRecord ,
isSelected ,
onSelectionChange
} = propsRef . current ;
2018-12-17 22:14:52 -05:00
2021-05-21 06:14:23 -04:00
if ( event . type !== 'selectionchange' && ! isSelected ) {
return ;
} // Check if the implementor disabled editing. `contentEditable`
// does disable input, but not text selection, so we must ignore
// selection changes.
2018-12-17 22:14:52 -05:00
2021-05-21 06:14:23 -04:00
if ( element . contentEditable !== 'true' ) {
return ;
} // In case of a keyboard event, ignore selection changes during
// composition.
2018-12-17 22:14:52 -05:00
2020-06-26 09:33:47 -04:00
2021-05-21 06:14:23 -04:00
if ( isComposing ) {
2019-09-19 11:19:18 -04:00
return ;
}
2018-12-17 22:14:52 -05:00
2021-05-21 06:14:23 -04:00
const {
start ,
end ,
text
} = createRecord ( ) ;
const oldRecord = record . current ; // Fallback mechanism for IE11, which doesn't support the input event.
// Any input results in a selection change.
2020-01-08 06:57:23 -05:00
2021-05-21 06:14:23 -04:00
if ( text !== oldRecord . text ) {
onInput ( ) ;
return ;
}
2020-01-08 06:57:23 -05:00
2021-05-21 06:14:23 -04:00
if ( start === oldRecord . start && end === oldRecord . end ) {
// Sometimes the browser may set the selection on the placeholder
// element, in which case the caret is not visible. We need to set
// the caret before the placeholder if that's the case.
if ( oldRecord . text . length === 0 && start === 0 ) {
fixPlaceholderSelection ( defaultView ) ;
}
2020-01-08 06:57:23 -05:00
2021-05-21 06:14:23 -04:00
return ;
2019-09-19 11:19:18 -04:00
}
2020-06-26 09:33:47 -04:00
2021-05-21 06:14:23 -04:00
const newValue = { ... oldRecord ,
start ,
end ,
// _newActiveFormats may be set on arrow key navigation to control
// the right boundary position. If undefined, getActiveFormats will
// give the active formats according to the browser.
activeFormats : oldRecord . _newActiveFormats ,
_newActiveFormats : undefined
} ;
const newActiveFormats = getActiveFormats ( newValue , use _input _and _selection _EMPTY _ACTIVE _FORMATS ) ; // Update the value with the new active formats.
2020-06-26 09:33:47 -04:00
2021-05-21 06:14:23 -04:00
newValue . activeFormats = newActiveFormats ; // It is important that the internal value is updated first,
// otherwise the value will be wrong on render!
2020-01-22 17:06:21 -05:00
2021-05-21 06:14:23 -04:00
record . current = newValue ;
applyRecord ( newValue , {
domOnly : true
2020-06-26 09:33:47 -04:00
} ) ;
2021-05-21 06:14:23 -04:00
onSelectionChange ( start , end ) ;
2019-09-19 11:19:18 -04:00
}
2020-06-26 09:33:47 -04:00
2021-05-21 06:14:23 -04:00
function onCompositionStart ( ) {
isComposing = true ; // Do not update the selection when characters are being composed as
// this rerenders the component and might distroy internal browser
// editing state.
2020-06-26 09:33:47 -04:00
2021-05-21 06:14:23 -04:00
ownerDocument . removeEventListener ( 'selectionchange' , handleSelectionChange ) ;
2020-06-26 09:33:47 -04:00
}
2018-12-17 22:14:52 -05:00
2021-05-21 06:14:23 -04:00
function onCompositionEnd ( ) {
isComposing = false ; // Ensure the value is up-to-date for browsers that don't emit a final
// input event after composition.
Block Editor: Update WordPress packages to include the latest bug fixes.
Updated packages:
@wordpress/annotations@1.7.1
@wordpress/api-fetch@3.6.1
@wordpress/babel-plugin-makepot@3.2.1
@wordpress/babel-preset-default@4.6.1
@wordpress/block-directory@1.0.1
@wordpress/block-editor@3.2.1
@wordpress/block-library@2.9.1
@wordpress/blocks@6.7.1
@wordpress/components@8.3.1
@wordpress/compose@3.7.1
@wordpress/core-data@2.7.1
@wordpress/data-controls@1.3.1
@wordpress/data@4.9.1
@wordpress/docgen@1.4.1
@wordpress/dom@2.5.1
@wordpress/e2e-test-utils@2.4.1
@wordpress/e2e-tests@1.7.1
@wordpress/edit-post@3.8.1
@wordpress/editor@9.7.1
@wordpress/element@2.8.1
@wordpress/format-library@1.9.1
@wordpress/i18n@3.6.1
@wordpress/jest-console@3.3.1
@wordpress/jest-preset-default@5.1.1
@wordpress/keycodes@2.6.1
@wordpress/library-export-default-webpack-plugin@1.4.1
@wordpress/list-reusable-blocks@1.8.1
@wordpress/media-utils@1.2.1
@wordpress/notices@1.8.1
@wordpress/nux@3.7.1
@wordpress/plugins@2.7.1
@wordpress/redux-routine@3.6.1
@wordpress/rich-text@3.7.1
@wordpress/scripts@5.0.1
@wordpress/server-side-render@1.3.1
@wordpress/shortcode@2.4.1
@wordpress/token-list@1.6.1
@wordpress/viewport@2.8.1
@wordpress/wordcount@2.6.1
Props epiqueras, youknowriad, donmhico, jorgefilipecosta, soean, mcsf, noisysocks, andraganescu, gziolo, talldanwp, iseulde, nrqsnchz, mapk, karmatosed, joen, afercia, kjellr, desrosj.
Fixes #48186.
Built from https://develop.svn.wordpress.org/trunk@46364
git-svn-id: http://core.svn.wordpress.org/trunk@46163 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-30 16:07:06 -04:00
2021-05-21 06:14:23 -04:00
onInput ( {
inputType : 'insertText'
} ) ; // Tracking selection changes can be resumed.
2019-09-19 11:19:18 -04:00
2021-05-21 06:14:23 -04:00
ownerDocument . addEventListener ( 'selectionchange' , handleSelectionChange ) ;
2020-06-26 09:33:47 -04:00
}
2019-09-19 11:19:18 -04:00
2021-05-21 06:14:23 -04:00
function onFocus ( ) {
const {
record ,
isSelected ,
2021-11-08 09:29:21 -05:00
onSelectionChange ,
applyRecord
2021-05-21 06:14:23 -04:00
} = propsRef . current ;
2020-06-26 09:33:47 -04:00
2021-05-21 06:14:23 -04:00
if ( ! isSelected ) {
// We know for certain that on focus, the old selection is invalid.
// It will be recalculated on the next mouseup, keyup, or touchend
// event.
const index = undefined ;
record . current = { ... record . current ,
start : index ,
end : index ,
activeFormats : use _input _and _selection _EMPTY _ACTIVE _FORMATS
} ;
onSelectionChange ( index , index ) ;
2020-06-26 09:33:47 -04:00
} else {
2021-11-08 09:29:21 -05:00
applyRecord ( record . current ) ;
2021-05-21 06:14:23 -04:00
onSelectionChange ( record . current . start , record . current . end ) ;
} // Update selection as soon as possible, which is at the next animation
// frame. The event listener for selection changes may be added too late
// at this point, but this focus event is still too early to calculate
// the selection.
2019-09-19 11:19:18 -04:00
2018-12-17 22:14:52 -05:00
2021-05-21 06:14:23 -04:00
rafId = defaultView . requestAnimationFrame ( handleSelectionChange ) ;
ownerDocument . addEventListener ( 'selectionchange' , handleSelectionChange ) ;
}
2019-09-19 11:19:18 -04:00
2021-05-21 06:14:23 -04:00
function onBlur ( ) {
ownerDocument . removeEventListener ( 'selectionchange' , handleSelectionChange ) ;
2020-06-26 09:33:47 -04:00
}
2019-09-19 11:19:18 -04:00
2021-05-21 06:14:23 -04:00
element . addEventListener ( 'input' , onInput ) ;
element . addEventListener ( 'compositionstart' , onCompositionStart ) ;
element . addEventListener ( 'compositionend' , onCompositionEnd ) ;
element . addEventListener ( 'focus' , onFocus ) ;
element . addEventListener ( 'blur' , onBlur ) ; // Selection updates must be done at these events as they
// happen before the `selectionchange` event. In some cases,
// the `selectionchange` event may not even fire, for
// example when the window receives focus again on click.
2019-09-19 11:19:18 -04:00
2021-05-21 06:14:23 -04:00
element . addEventListener ( 'keyup' , handleSelectionChange ) ;
element . addEventListener ( 'mouseup' , handleSelectionChange ) ;
element . addEventListener ( 'touchend' , handleSelectionChange ) ;
return ( ) => {
element . removeEventListener ( 'input' , onInput ) ;
element . removeEventListener ( 'compositionstart' , onCompositionStart ) ;
element . removeEventListener ( 'compositionend' , onCompositionEnd ) ;
element . removeEventListener ( 'focus' , onFocus ) ;
element . removeEventListener ( 'blur' , onBlur ) ;
element . removeEventListener ( 'keyup' , handleSelectionChange ) ;
element . removeEventListener ( 'mouseup' , handleSelectionChange ) ;
element . removeEventListener ( 'touchend' , handleSelectionChange ) ;
ownerDocument . removeEventListener ( 'selectionchange' , handleSelectionChange ) ;
defaultView . cancelAnimationFrame ( rafId ) ;
} ;
} , [ ] ) ;
}
2019-09-19 11:19:18 -04:00
2021-05-21 06:14:23 -04:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-delete.js
/ * *
* WordPress dependencies
* /
2020-01-22 17:06:21 -05:00
2019-09-19 11:19:18 -04:00
2020-01-08 06:57:23 -05:00
2021-05-21 06:14:23 -04:00
/ * *
* Internal dependencies
* /
2020-06-26 09:33:47 -04:00
2019-09-19 11:19:18 -04:00
2021-05-21 06:14:23 -04:00
function useDelete ( props ) {
const propsRef = Object ( external _wp _element _ [ "useRef" ] ) ( props ) ;
propsRef . current = props ;
return Object ( external _wp _compose _ [ "useRefEffect" ] ) ( element => {
function onKeyDown ( event ) {
const {
keyCode
} = event ;
const {
createRecord ,
handleChange ,
multilineTag
} = propsRef . current ;
2019-09-19 11:19:18 -04:00
2021-05-21 06:14:23 -04:00
if ( event . defaultPrevented ) {
return ;
}
2019-09-19 11:19:18 -04:00
2021-05-21 06:14:23 -04:00
if ( keyCode !== external _wp _keycodes _ [ "DELETE" ] && keyCode !== external _wp _keycodes _ [ "BACKSPACE" ] ) {
return ;
}
2019-09-19 11:19:18 -04:00
2021-05-21 06:14:23 -04:00
const currentValue = createRecord ( ) ;
const {
start ,
end ,
text
} = currentValue ;
const isReverse = keyCode === external _wp _keycodes _ [ "BACKSPACE" ] ; // Always handle full content deletion ourselves.
2020-01-08 06:57:23 -05:00
2021-05-21 06:14:23 -04:00
if ( start === 0 && end !== 0 && end === text . length ) {
handleChange ( remove _remove ( currentValue ) ) ;
event . preventDefault ( ) ;
return ;
}
2019-09-19 11:19:18 -04:00
2021-05-21 06:14:23 -04:00
if ( multilineTag ) {
let newValue ; // Check to see if we should remove the first item if empty.
2019-09-19 11:19:18 -04:00
2021-05-21 06:14:23 -04:00
if ( isReverse && currentValue . start === 0 && currentValue . end === 0 && isEmptyLine ( currentValue ) ) {
newValue = removeLineSeparator ( currentValue , ! isReverse ) ;
} else {
newValue = removeLineSeparator ( currentValue , isReverse ) ;
}
2020-06-26 09:33:47 -04:00
2021-05-21 06:14:23 -04:00
if ( newValue ) {
handleChange ( newValue ) ;
event . preventDefault ( ) ;
}
}
2020-06-26 09:33:47 -04:00
}
2019-09-19 11:19:18 -04:00
2021-05-21 06:14:23 -04:00
element . addEventListener ( 'keydown' , onKeyDown ) ;
return ( ) => {
element . removeEventListener ( 'keydown' , onKeyDown ) ;
} ;
} , [ ] ) ;
}
2019-09-19 11:19:18 -04:00
2021-11-08 09:29:21 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-space.js
/ * *
* WordPress dependencies
* /
/ * *
* For some elements like BUTTON and SUMMARY , the space key doesn ' t insert a
* space character in some browsers even though the element is editable . We have
* to manually insert a space and prevent default behaviour .
*
* DO NOT limit this behaviour to specific tag names ! It would mean that this
* behaviour is not widely tested . If there ' s ever any problems , we should find
* a different solution entirely or remove it entirely .
* /
function useSpace ( ) {
return Object ( external _wp _compose _ [ "useRefEffect" ] ) ( element => {
function onKeyDown ( event ) {
// Don't insert a space if default behaviour is prevented.
if ( event . defaultPrevented ) {
return ;
}
const {
keyCode ,
altKey ,
metaKey ,
ctrlKey
} = event ; // Only consider the space key without modifiers pressed.
if ( keyCode !== external _wp _keycodes _ [ "SPACE" ] || altKey || metaKey || ctrlKey ) {
return ;
}
event . target . ownerDocument . execCommand ( 'insertText' , false , ' ' ) ;
event . preventDefault ( ) ;
}
element . addEventListener ( 'keydown' , onKeyDown ) ;
return ( ) => {
element . removeEventListener ( 'keydown' , onKeyDown ) ;
} ;
} , [ ] ) ;
}
2021-05-21 06:14:23 -04:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/index.js
/ * *
* WordPress dependencies
* /
2019-09-19 11:19:18 -04:00
2021-11-08 09:29:21 -05:00
2021-05-21 06:14:23 -04:00
/ * *
* Internal dependencies
* /
2019-09-19 11:19:18 -04:00
2020-06-26 09:33:47 -04:00
2019-09-19 11:19:18 -04:00
2020-06-26 09:33:47 -04:00
2019-09-19 11:19:18 -04:00
2020-06-26 09:33:47 -04:00
2019-09-19 11:19:18 -04:00
2021-11-15 07:50:17 -05:00
function useRichText ( _ref ) {
let {
value = '' ,
selectionStart ,
selectionEnd ,
placeholder ,
preserveWhiteSpace ,
onSelectionChange ,
onChange ,
_ _unstableMultilineTag : multilineTag ,
_ _unstableDisableFormats : disableFormats ,
_ _unstableIsSelected : isSelected ,
_ _unstableDependencies = [ ] ,
_ _unstableAfterParse ,
_ _unstableBeforeSerialize ,
_ _unstableAddInvisibleFormats
} = _ref ;
2021-11-08 09:29:21 -05:00
const registry = Object ( external _wp _data _ [ "useRegistry" ] ) ( ) ;
2021-05-21 06:14:23 -04:00
const [ , forceRender ] = Object ( external _wp _element _ [ "useReducer" ] ) ( ( ) => ( { } ) ) ;
const ref = Object ( external _wp _element _ [ "useRef" ] ) ( ) ;
2019-09-19 11:19:18 -04:00
2021-05-21 06:14:23 -04:00
function createRecord ( ) {
const {
ownerDocument : {
defaultView
}
} = ref . current ;
const selection = defaultView . getSelection ( ) ;
const range = selection . rangeCount > 0 ? selection . getRangeAt ( 0 ) : null ;
return create ( {
element : ref . current ,
range ,
multilineTag ,
multilineWrapperTags : multilineTag === 'li' ? [ 'ul' , 'ol' ] : undefined ,
_ _unstableIsEditableTree : true ,
preserveWhiteSpace
} ) ;
2020-06-26 09:33:47 -04:00
}
2019-09-19 11:19:18 -04:00
2021-11-15 07:50:17 -05:00
function applyRecord ( newRecord ) {
let {
domOnly
} = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : { } ;
2021-05-21 06:14:23 -04:00
apply ( {
value : newRecord ,
current : ref . current ,
multilineTag ,
multilineWrapperTags : multilineTag === 'li' ? [ 'ul' , 'ol' ] : undefined ,
prepareEditableTree : _ _unstableAddInvisibleFormats ,
_ _unstableDomOnly : domOnly ,
placeholder
} ) ;
} // Internal values are updated synchronously, unlike props and state.
2019-09-19 11:19:18 -04:00
2021-05-21 06:14:23 -04:00
const _value = Object ( external _wp _element _ [ "useRef" ] ) ( value ) ;
2019-09-19 11:19:18 -04:00
2021-05-21 06:14:23 -04:00
const record = Object ( external _wp _element _ [ "useRef" ] ) ( ) ;
2019-09-19 11:19:18 -04:00
2021-05-21 06:14:23 -04:00
function setRecordFromProps ( ) {
_value . current = value ;
record . current = create ( {
html : value ,
multilineTag ,
multilineWrapperTags : multilineTag === 'li' ? [ 'ul' , 'ol' ] : undefined ,
preserveWhiteSpace
} ) ;
2019-09-19 11:19:18 -04:00
2021-05-21 06:14:23 -04:00
if ( disableFormats ) {
record . current . formats = Array ( value . length ) ;
record . current . replacements = Array ( value . length ) ;
2020-06-26 09:33:47 -04:00
}
2021-11-08 09:29:21 -05:00
if ( _ _unstableAfterParse ) {
record . current . formats = _ _unstableAfterParse ( record . current ) ;
}
2021-05-21 06:14:23 -04:00
record . current . start = selectionStart ;
record . current . end = selectionEnd ;
}
2019-09-19 11:19:18 -04:00
2021-05-21 06:14:23 -04:00
const hadSelectionUpdate = Object ( external _wp _element _ [ "useRef" ] ) ( false ) ;
2020-06-26 09:33:47 -04:00
2021-05-21 06:14:23 -04:00
if ( ! record . current ) {
2021-11-08 09:29:21 -05:00
var _record$current , _record$current$forma , _record$current$forma2 ;
setRecordFromProps ( ) ; // Sometimes formats are added programmatically and we need to make
// sure it's persisted to the block store / markup. If these formats
// are not applied, they could cause inconsistencies between the data
// in the visual editor and the frontend. Right now, it's only relevant
// to the `core/text-color` format, which is applied at runtime in
// certain circunstances. See the `__unstableFilterAttributeValue`
// function in `packages/format-library/src/text-color/index.js`.
// @todo find a less-hacky way of solving this.
const hasRelevantInitFormat = ( ( _record$current = record . current ) === null || _record$current === void 0 ? void 0 : ( _record$current$forma = _record$current . formats [ 0 ] ) === null || _record$current$forma === void 0 ? void 0 : ( _record$current$forma2 = _record$current$forma [ 0 ] ) === null || _record$current$forma2 === void 0 ? void 0 : _record$current$forma2 . type ) === 'core/text-color' ;
if ( hasRelevantInitFormat ) {
handleChangesUponInit ( record . current ) ;
}
2021-05-21 06:14:23 -04:00
} else if ( selectionStart !== record . current . start || selectionEnd !== record . current . end ) {
hadSelectionUpdate . current = isSelected ;
record . current = { ... record . current ,
start : selectionStart ,
end : selectionEnd
2021-05-19 11:09:27 -04:00
} ;
2020-06-26 09:33:47 -04:00
}
/ * *
* Sync the value to global state . The node tree and selection will also be
* updated if differences are found .
*
2021-05-21 06:14:23 -04:00
* @ param { Object } newRecord The record to sync and apply .
2020-06-26 09:33:47 -04:00
* /
2021-05-21 06:14:23 -04:00
function handleChange ( newRecord ) {
2021-11-08 09:29:21 -05:00
record . current = newRecord ;
2021-05-21 06:14:23 -04:00
applyRecord ( newRecord ) ;
2020-06-26 09:33:47 -04:00
if ( disableFormats ) {
2021-05-21 06:14:23 -04:00
_value . current = newRecord . text ;
} else {
_value . current = toHTMLString ( {
2021-11-08 09:29:21 -05:00
value : _ _unstableBeforeSerialize ? { ... newRecord ,
2021-05-21 06:14:23 -04:00
formats : _ _unstableBeforeSerialize ( newRecord )
2021-11-08 09:29:21 -05:00
} : newRecord ,
2021-05-21 06:14:23 -04:00
multilineTag ,
preserveWhiteSpace
} ) ;
2019-09-19 11:19:18 -04:00
}
2021-05-19 11:09:27 -04:00
const {
start ,
end ,
2021-05-21 06:14:23 -04:00
formats ,
text
} = newRecord ; // Selection must be updated first, so it is recorded in history when
2020-06-26 09:33:47 -04:00
// the content change happens.
2021-11-08 09:29:21 -05:00
// We batch both calls to only attempt to rerender once.
registry . batch ( ( ) => {
onSelectionChange ( start , end ) ;
onChange ( _value . current , {
_ _unstableFormats : formats ,
_ _unstableText : text
} ) ;
} ) ;
forceRender ( ) ;
}
2020-06-26 09:33:47 -04:00
2021-11-08 09:29:21 -05:00
function handleChangesUponInit ( newRecord ) {
record . current = newRecord ;
_value . current = toHTMLString ( {
value : _ _unstableBeforeSerialize ? { ... newRecord ,
formats : _ _unstableBeforeSerialize ( newRecord )
} : newRecord ,
multilineTag ,
preserveWhiteSpace
} ) ;
const {
formats ,
text
} = newRecord ;
registry . batch ( ( ) => {
onChange ( _value . current , {
_ _unstableFormats : formats ,
_ _unstableText : text
} ) ;
2021-05-21 06:14:23 -04:00
} ) ;
forceRender ( ) ;
2020-06-26 09:33:47 -04:00
}
function applyFromProps ( ) {
2021-05-21 06:14:23 -04:00
setRecordFromProps ( ) ;
2020-06-26 09:33:47 -04:00
applyRecord ( record . current ) ;
}
2021-05-21 06:14:23 -04:00
const didMount = Object ( external _wp _element _ [ "useRef" ] ) ( false ) ; // Value updates must happen synchonously to avoid overwriting newer values.
Object ( external _wp _element _ [ "useLayoutEffect" ] ) ( ( ) => {
2020-06-26 09:33:47 -04:00
if ( didMount . current && value !== _value . current ) {
applyFromProps ( ) ;
2019-09-19 11:19:18 -04:00
}
2021-05-21 06:14:23 -04:00
} , [ value ] ) ; // Value updates must happen synchonously to avoid overwriting newer values.
Object ( external _wp _element _ [ "useLayoutEffect" ] ) ( ( ) => {
if ( ! hadSelectionUpdate . current ) {
2020-06-26 09:33:47 -04:00
return ;
}
2021-05-21 06:14:23 -04:00
applyFromProps ( ) ;
hadSelectionUpdate . current = false ;
} , [ hadSelectionUpdate . current ] ) ;
const mergedRefs = Object ( external _wp _compose _ [ "useMergeRefs" ] ) ( [ ref , useDefaultStyle ( ) , useBoundaryStyle ( {
record
2021-11-08 09:29:21 -05:00
} ) , useCopyHandler ( {
2021-05-21 06:14:23 -04:00
record ,
multilineTag ,
preserveWhiteSpace
} ) , useSelectObject ( ) , useFormatBoundaries ( {
record ,
applyRecord
} ) , useDelete ( {
createRecord ,
handleChange ,
multilineTag
} ) , useIndentListItemOnSpace ( {
multilineTag ,
createRecord ,
handleChange
} ) , useInputAndSelection ( {
record ,
applyRecord ,
createRecord ,
handleChange ,
2021-05-19 11:09:27 -04:00
isSelected ,
2021-05-21 06:14:23 -04:00
onSelectionChange
2021-11-08 09:29:21 -05:00
} ) , useSpace ( ) , Object ( external _wp _compose _ [ "useRefEffect" ] ) ( ( ) => {
2021-05-21 06:14:23 -04:00
applyFromProps ( ) ;
didMount . current = true ;
} , [ placeholder , ... _ _unstableDependencies ] ) ] ) ;
return {
2020-06-26 09:33:47 -04:00
value : record . current ,
onChange : handleChange ,
2021-05-21 06:14:23 -04:00
ref : mergedRefs
} ;
2020-06-26 09:33:47 -04:00
}
2021-05-21 06:14:23 -04:00
function _ _experimentalRichText ( ) { }
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/format-edit.js
2019-10-15 11:37:08 -04:00
/ * *
2021-05-21 06:14:23 -04:00
* Internal dependencies
2019-10-15 11:37:08 -04:00
* /
2020-10-13 09:10:30 -04:00
2021-11-15 07:50:17 -05:00
function FormatEdit ( _ref ) {
let {
formatTypes ,
onChange ,
onFocus ,
value ,
forwardedRef
} = _ref ;
2021-05-21 06:14:23 -04:00
return formatTypes . map ( settings => {
const {
name ,
edit : Edit
} = settings ;
if ( ! Edit ) {
return null ;
}
const activeFormat = getActiveFormat ( value , name ) ;
const isActive = activeFormat !== undefined ;
const activeObject = getActiveObject ( value ) ;
const isObjectActive = activeObject !== undefined && activeObject . type === name ;
return Object ( external _wp _element _ [ "createElement" ] ) ( Edit , {
key : name ,
isActive : isActive ,
activeAttributes : isActive ? activeFormat . attributes || { } : { } ,
isObjectActive : isObjectActive ,
activeObjectAttributes : isObjectActive ? activeObject . attributes || { } : { } ,
value : value ,
onChange : onChange ,
onFocus : onFocus ,
contentRef : forwardedRef
} ) ;
} ) ;
}
2019-10-15 11:37:08 -04:00
// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/index.js
2021-01-27 21:04:13 -05:00
2019-10-15 11:37:08 -04:00
2019-09-19 11:19:18 -04:00
2019-10-15 11:37:08 -04:00
2019-09-19 11:19:18 -04:00
2021-04-15 11:19:43 -04:00
2018-12-13 23:41:57 -05:00
/***/ } )
2018-12-17 22:14:52 -05:00
/******/ } ) ;