2024-01-31 07:59:56 -05:00
/******/ ( ( ) => { // webpackBootstrap
2022-04-11 08:04:30 -04:00
/******/ "use strict" ;
/******/ // The require scope
/******/ var _ _webpack _require _ _ = { } ;
/******/
/************************************************************************/
2022-09-20 11:43:29 -04:00
/******/ /* webpack/runtime/compat get default export */
2024-01-31 07:59:56 -05:00
/******/ ( ( ) => {
2022-09-20 11:43:29 -04:00
/******/ // getDefaultExport function for compatibility with non-harmony modules
2024-01-31 07:59:56 -05:00
/******/ _ _webpack _require _ _ . n = ( module ) => {
2022-09-20 11:43:29 -04:00
/******/ var getter = module && module . _ _esModule ?
2024-01-31 07:59:56 -05:00
/******/ ( ) => ( module [ 'default' ] ) :
/******/ ( ) => ( module ) ;
2022-09-20 11:43:29 -04:00
/******/ _ _webpack _require _ _ . d ( getter , { a : getter } ) ;
/******/ return getter ;
/******/ } ;
2024-01-31 07:59:56 -05:00
/******/ } ) ( ) ;
2022-09-20 11:43:29 -04:00
/******/
2022-04-11 08:04:30 -04:00
/******/ /* webpack/runtime/define property getters */
2024-01-31 07:59:56 -05:00
/******/ ( ( ) => {
2022-04-11 08:04:30 -04:00
/******/ // define getter functions for harmony exports
2024-01-31 07:59:56 -05:00
/******/ _ _webpack _require _ _ . d = ( exports , definition ) => {
2022-04-11 08:04:30 -04:00
/******/ for ( var key in definition ) {
/******/ if ( _ _webpack _require _ _ . o ( definition , key ) && ! _ _webpack _require _ _ . o ( exports , key ) ) {
/******/ Object . defineProperty ( exports , key , { enumerable : true , get : definition [ key ] } ) ;
/******/ }
/******/ }
/******/ } ;
2024-01-31 07:59:56 -05:00
/******/ } ) ( ) ;
2022-04-11 08:04:30 -04:00
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
2024-01-31 07:59:56 -05:00
/******/ ( ( ) => {
/******/ _ _webpack _require _ _ . o = ( obj , prop ) => ( Object . prototype . hasOwnProperty . call ( obj , prop ) )
/******/ } ) ( ) ;
2022-04-11 08:04:30 -04:00
/******/
/******/ /* webpack/runtime/make namespace object */
2024-01-31 07:59:56 -05:00
/******/ ( ( ) => {
2022-04-11 08:04:30 -04:00
/******/ // define __esModule on exports
2024-01-31 07:59:56 -05:00
/******/ _ _webpack _require _ _ . r = ( exports ) => {
2022-04-11 08:04:30 -04:00
/******/ if ( typeof Symbol !== 'undefined' && Symbol . toStringTag ) {
/******/ Object . defineProperty ( exports , Symbol . toStringTag , { value : 'Module' } ) ;
/******/ }
/******/ Object . defineProperty ( exports , '__esModule' , { value : true } ) ;
2018-12-13 23:41:57 -05:00
/******/ } ;
2024-01-31 07:59:56 -05:00
/******/ } ) ( ) ;
2022-04-11 08:04:30 -04:00
/******/
2018-12-13 23:41:57 -05:00
/************************************************************************/
2022-04-11 08:04:30 -04:00
var _ _webpack _exports _ _ = { } ;
// ESM COMPAT FLAG
_ _webpack _require _ _ . r ( _ _webpack _exports _ _ ) ;
2021-01-27 21:04:13 -05:00
2022-04-11 08:04:30 -04:00
// EXPORTS
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , {
2024-01-31 07:59:56 -05:00
RichTextData : ( ) => ( /* reexport */ RichTextData ) ,
_ _experimentalRichText : ( ) => ( /* reexport */ _ _experimentalRichText ) ,
_ _unstableCreateElement : ( ) => ( /* reexport */ createElement ) ,
_ _unstableToDom : ( ) => ( /* reexport */ toDom ) ,
_ _unstableUseRichText : ( ) => ( /* reexport */ useRichText ) ,
applyFormat : ( ) => ( /* reexport */ applyFormat ) ,
concat : ( ) => ( /* reexport */ concat ) ,
create : ( ) => ( /* reexport */ create ) ,
getActiveFormat : ( ) => ( /* reexport */ getActiveFormat ) ,
getActiveFormats : ( ) => ( /* reexport */ getActiveFormats ) ,
getActiveObject : ( ) => ( /* reexport */ getActiveObject ) ,
getTextContent : ( ) => ( /* reexport */ getTextContent ) ,
insert : ( ) => ( /* reexport */ insert ) ,
insertObject : ( ) => ( /* reexport */ insertObject ) ,
isCollapsed : ( ) => ( /* reexport */ isCollapsed ) ,
isEmpty : ( ) => ( /* reexport */ isEmpty ) ,
join : ( ) => ( /* reexport */ join ) ,
registerFormatType : ( ) => ( /* reexport */ registerFormatType ) ,
remove : ( ) => ( /* reexport */ remove _remove ) ,
removeFormat : ( ) => ( /* reexport */ removeFormat ) ,
replace : ( ) => ( /* reexport */ replace _replace ) ,
slice : ( ) => ( /* reexport */ slice ) ,
split : ( ) => ( /* reexport */ split ) ,
store : ( ) => ( /* reexport */ store ) ,
toHTMLString : ( ) => ( /* reexport */ toHTMLString ) ,
toggleFormat : ( ) => ( /* reexport */ toggleFormat ) ,
unregisterFormatType : ( ) => ( /* reexport */ unregisterFormatType ) ,
useAnchor : ( ) => ( /* reexport */ useAnchor ) ,
useAnchorRef : ( ) => ( /* reexport */ useAnchorRef )
2022-04-11 08:04:30 -04:00
} ) ;
2021-01-27 21:04:13 -05:00
2022-04-11 08:04:30 -04:00
// NAMESPACE OBJECT: ./node_modules/@wordpress/rich-text/build-module/store/selectors.js
var selectors _namespaceObject = { } ;
_ _webpack _require _ _ . r ( selectors _namespaceObject ) ;
_ _webpack _require _ _ . d ( selectors _namespaceObject , {
2024-01-31 07:59:56 -05:00
getFormatType : ( ) => ( getFormatType ) ,
getFormatTypeForBareElement : ( ) => ( getFormatTypeForBareElement ) ,
getFormatTypeForClassName : ( ) => ( getFormatTypeForClassName ) ,
getFormatTypes : ( ) => ( getFormatTypes )
2022-04-11 08:04:30 -04:00
} ) ;
2020-03-23 19:40:19 -04:00
2022-04-11 08:04:30 -04:00
// NAMESPACE OBJECT: ./node_modules/@wordpress/rich-text/build-module/store/actions.js
var actions _namespaceObject = { } ;
_ _webpack _require _ _ . r ( actions _namespaceObject ) ;
_ _webpack _require _ _ . d ( actions _namespaceObject , {
2024-01-31 07:59:56 -05:00
addFormatTypes : ( ) => ( addFormatTypes ) ,
removeFormatTypes : ( ) => ( removeFormatTypes )
2022-04-11 08:04:30 -04:00
} ) ;
2020-06-26 09:33:47 -04:00
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: external ["wp","data"]
2024-01-31 07:59:56 -05:00
const external _wp _data _namespaceObject = window [ "wp" ] [ "data" ] ;
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/store/reducer.js
/ * *
* WordPress dependencies
* /
2021-11-08 09:29:21 -05:00
2023-09-26 10:23:26 -04:00
2022-04-11 08:04:30 -04:00
/ * *
* Reducer managing the format types
*
* @ param { Object } state Current state .
* @ param { Object } action Dispatched action .
*
* @ return { Object } Updated state .
* /
2023-06-27 10:24:19 -04:00
function formatTypes ( state = { } , action ) {
2022-04-11 08:04:30 -04:00
switch ( action . type ) {
case 'ADD_FORMAT_TYPES' :
2023-09-26 10:23:26 -04:00
return {
... state ,
2022-09-20 11:43:29 -04:00
// Key format types by their name.
2023-09-26 10:23:26 -04:00
... action . formatTypes . reduce ( ( newFormatTypes , type ) => ( {
... newFormatTypes ,
2022-09-20 11:43:29 -04:00
[ type . name ] : type
} ) , { } )
2022-04-11 08:04:30 -04:00
} ;
case 'REMOVE_FORMAT_TYPES' :
2023-06-27 10:24:19 -04:00
return Object . fromEntries ( Object . entries ( state ) . filter ( ( [ key ] ) => ! action . names . includes ( key ) ) ) ;
2022-04-11 08:04:30 -04:00
}
return state ;
}
2024-01-31 07:59:56 -05:00
/* harmony default export */ const reducer = ( ( 0 , external _wp _data _namespaceObject . combineReducers ) ( {
2022-04-11 08:04:30 -04:00
formatTypes
} ) ) ;
2020-06-26 09:33:47 -04:00
2022-09-20 11:43:29 -04:00
; // CONCATENATED MODULE: ./node_modules/rememo/rememo.js
2019-03-07 04:09:59 -05:00
2022-09-20 11:43:29 -04:00
/** @typedef {(...args: any[]) => *[]} GetDependants */
/** @typedef {() => void} Clear */
2019-03-07 04:09:59 -05:00
/ * *
2022-09-20 11:43:29 -04:00
* @ typedef { {
* getDependants : GetDependants ,
* clear : Clear
* } } EnhancedSelector
* /
/ * *
* Internal cache entry .
2020-01-22 17:06:21 -05:00
*
2022-09-20 11:43:29 -04:00
* @ typedef CacheNode
*
* @ property { ? CacheNode | undefined } [ prev ] Previous node .
* @ property { ? CacheNode | undefined } [ next ] Next node .
* @ property { * [ ] } args Function arguments for cache entry .
* @ property { * } val Function result .
* /
/ * *
* @ typedef Cache
*
* @ property { Clear } clear Function to clear cache .
* @ property { boolean } [ isUniqueByDependants ] Whether dependants are valid in
* considering cache uniqueness . A cache is unique if dependents are all arrays
* or objects .
* @ property { CacheNode ? } [ head ] Cache head .
* @ property { * [ ] } [ lastDependants ] Dependants from previous invocation .
2019-03-07 04:09:59 -05:00
* /
/ * *
2022-09-20 11:43:29 -04:00
* Arbitrary value used as key for referencing cache object in WeakMap tree .
2020-01-22 17:06:21 -05:00
*
2022-09-20 11:43:29 -04:00
* @ type { { } }
2019-03-07 04:09:59 -05:00
* /
2022-09-20 11:43:29 -04:00
var LEAF _KEY = { } ;
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
*
2022-09-20 11:43:29 -04:00
* @ template T
2019-03-07 04:09:59 -05:00
*
2022-09-20 11:43:29 -04:00
* @ param { T } value Value to return .
*
* @ return { [ T ] } Value returned as entry in array .
2019-03-07 04:09:59 -05:00
* /
2022-09-20 11:43:29 -04: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
* /
2022-09-20 11:43:29 -04:00
function isObjectLike ( value ) {
return ! ! value && 'object' === typeof value ;
2020-01-22 17:06:21 -05:00
}
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
*
2022-09-20 11:43:29 -04:00
* @ return { Cache } Cache object .
2019-03-07 04:09:59 -05:00
* /
2020-01-22 17:06:21 -05:00
function createCache ( ) {
2022-09-20 11:43:29 -04:00
/** @type {Cache} */
2020-01-22 17:06:21 -05:00
var cache = {
2022-09-20 11:43:29 -04:00
clear : function ( ) {
2020-01-22 17:06:21 -05:00
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
*
2022-09-20 11:43:29 -04:00
* @ param { * [ ] } a First array .
* @ param { * [ ] } b Second array .
2020-01-22 17:06:21 -05:00
* @ param { number } fromIndex Index from which to start comparison .
*
* @ return { boolean } Whether arrays are shallowly equal .
2019-03-07 04:09:59 -05:00
* /
2022-09-20 11:43:29 -04:00
function isShallowEqual ( a , b , fromIndex ) {
2020-01-22 17:06:21 -05:00
var i ;
2019-03-07 04:09:59 -05:00
2022-09-20 11:43:29 -04:00
if ( a . length !== b . length ) {
2020-01-22 17:06:21 -05:00
return false ;
}
2019-03-07 04:09:59 -05:00
2022-09-20 11:43:29 -04:00
for ( i = fromIndex ; i < a . length ; i ++ ) {
if ( a [ i ] !== b [ i ] ) {
2020-01-22 17:06:21 -05:00
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
*
2022-09-20 11:43:29 -04:00
* @ template { ( ... args : * [ ] ) => * } S
2019-03-07 04:09:59 -05:00
*
2022-09-20 11:43:29 -04:00
* @ param { S } selector Selector function .
* @ param { GetDependants = } getDependants Dependant getter returning an array of
* references used in cache bust consideration .
2019-03-07 04:09:59 -05:00
* /
2022-09-20 11:43:29 -04:00
/* harmony default export */ function rememo ( selector , getDependants ) {
/** @type {WeakMap<*,*>} */
var rootCache ;
2020-01-22 17:06:21 -05:00
2022-09-20 11:43:29 -04:00
/** @type {GetDependants} */
var normalizedGetDependants = getDependants ? getDependants : arrayOf ;
2020-01-22 17:06:21 -05:00
/ * *
* 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
*
2022-09-20 11:43:29 -04:00
* @ param { * [ ] } dependants Selector dependants .
2020-01-22 17:06:21 -05:00
*
2022-09-20 11:43:29 -04:00
* @ return { Cache } Cache object .
2020-01-22 17:06:21 -05:00
* /
2022-09-20 11:43:29 -04:00
function getCache ( dependants ) {
2020-01-22 17:06:21 -05:00
var caches = rootCache ,
isUniqueByDependants = true ,
2022-09-20 11:43:29 -04:00
i ,
dependant ,
map ,
cache ;
2020-01-22 17:06:21 -05:00
2022-09-20 11:43:29 -04:00
for ( i = 0 ; i < dependants . length ; i ++ ) {
dependant = dependants [ i ] ;
2020-01-22 17:06:21 -05:00
// Can only compose WeakMap from object-like key.
2022-09-20 11:43:29 -04:00
if ( ! isObjectLike ( dependant ) ) {
2020-01-22 17:06:21 -05:00
isUniqueByDependants = false ;
break ;
}
// Does current segment of cache already have a WeakMap?
2022-09-20 11:43:29 -04:00
if ( caches . has ( dependant ) ) {
2020-01-22 17:06:21 -05:00
// Traverse into nested WeakMap.
2022-09-20 11:43:29 -04:00
caches = caches . get ( dependant ) ;
2020-01-22 17:06:21 -05:00
} else {
// Create, set, and traverse into a new one.
map = new WeakMap ( ) ;
2022-09-20 11:43:29 -04:00
caches . set ( dependant , map ) ;
2020-01-22 17:06:21 -05:00
caches = map ;
}
}
// We use an arbitrary (but consistent) object as key for the last item
// in the WeakMap to serve as our running cache.
2022-09-20 11:43:29 -04:00
if ( ! caches . has ( LEAF _KEY ) ) {
2020-01-22 17:06:21 -05:00
cache = createCache ( ) ;
cache . isUniqueByDependants = isUniqueByDependants ;
2022-09-20 11:43:29 -04:00
caches . set ( LEAF _KEY , cache ) ;
2020-01-22 17:06:21 -05:00
}
2022-09-20 11:43:29 -04:00
return caches . get ( LEAF _KEY ) ;
2020-01-22 17:06:21 -05:00
}
/ * *
* Resets root memoization cache .
* /
function clear ( ) {
2022-09-20 11:43:29 -04:00
rootCache = new WeakMap ( ) ;
2020-01-22 17:06:21 -05:00
}
2022-09-20 11:43:29 -04:00
/* eslint-disable jsdoc/check-param-names */
2020-01-22 17:06:21 -05:00
/ * *
* The augmented selector call , considering first whether dependants have
* changed before passing it to underlying memoize function .
*
2022-09-20 11:43:29 -04:00
* @ param { * } source Source object for derivation .
* @ param { ... * } extraArgs Additional arguments to pass to selector .
2020-01-22 17:06:21 -05:00
*
* @ return { * } Selector result .
* /
2022-09-20 11:43:29 -04:00
/* eslint-enable jsdoc/check-param-names */
function callSelector ( /* source, ...extraArgs */ ) {
2020-01-22 17:06:21 -05:00
var len = arguments . length ,
2022-09-20 11:43:29 -04:00
cache ,
node ,
i ,
args ,
dependants ;
2020-01-22 17:06:21 -05:00
// Create copy of arguments (avoid leaking deoptimization).
2022-09-20 11:43:29 -04:00
args = new Array ( len ) ;
for ( i = 0 ; i < len ; i ++ ) {
args [ i ] = arguments [ i ] ;
2020-01-22 17:06:21 -05:00
}
2022-09-20 11:43:29 -04:00
dependants = normalizedGetDependants . apply ( null , args ) ;
cache = getCache ( dependants ) ;
// If not guaranteed uniqueness by dependants (primitive type), 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 )
) {
2020-01-22 17:06:21 -05:00
cache . clear ( ) ;
}
cache . lastDependants = dependants ;
}
node = cache . head ;
2022-09-20 11:43:29 -04:00
while ( node ) {
2020-01-22 17:06:21 -05:00
// Check whether node arguments match arguments
2022-09-20 11:43:29 -04:00
if ( ! isShallowEqual ( node . args , args , 1 ) ) {
2020-01-22 17:06:21 -05:00
node = node . next ;
continue ;
}
// At this point we can assume we've found a match
// Surface matched node to head if not already
2022-09-20 11:43:29 -04:00
if ( node !== cache . head ) {
2020-01-22 17:06:21 -05:00
// Adjust siblings to point to each other.
2022-09-20 11:43:29 -04:00
/** @type {CacheNode} */ ( node . prev ) . next = node . next ;
if ( node . next ) {
2020-01-22 17:06:21 -05:00
node . next . prev = node . prev ;
}
node . next = cache . head ;
node . prev = null ;
2022-09-20 11:43:29 -04:00
/** @type {CacheNode} */ ( cache . head ) . prev = node ;
2020-01-22 17:06:21 -05:00
cache . head = node ;
}
// Return immediately
return node . val ;
}
// No cached value found. Continue to insertion phase:
2022-09-20 11:43:29 -04:00
node = /** @type {CacheNode} */ ( {
2020-01-22 17:06:21 -05:00
// Generate the result from original function
2022-09-20 11:43:29 -04:00
val : selector . apply ( null , args ) ,
} ) ;
2020-01-22 17:06:21 -05:00
// Avoid including the source object in the cache.
2022-09-20 11:43:29 -04:00
args [ 0 ] = null ;
2020-01-22 17:06:21 -05:00
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
2022-09-20 11:43:29 -04:00
if ( cache . head ) {
2020-01-22 17:06:21 -05:00
cache . head . prev = node ;
node . next = cache . head ;
}
cache . head = node ;
return node . val ;
}
2022-09-20 11:43:29 -04:00
callSelector . getDependants = normalizedGetDependants ;
2020-01-22 17:06:21 -05:00
callSelector . clear = clear ;
clear ( ) ;
2022-09-20 11:43:29 -04:00
return /** @type {S & EnhancedSelector} */ ( callSelector ) ;
2020-01-22 17:06:21 -05:00
}
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/store/selectors.js
2020-01-22 17:06:21 -05:00
/ * *
* External dependencies
* /
2023-09-26 10:23:26 -04:00
2020-01-22 17:06:21 -05:00
/ * *
* Returns all the available format types .
*
* @ param { Object } state Data state .
*
2023-09-26 10:23:26 -04:00
* @ example
* ` ` ` js
* import { _ _ , sprintf } from '@wordpress/i18n' ;
* import { store as richTextStore } from '@wordpress/rich-text' ;
* import { useSelect } from '@wordpress/data' ;
*
* const ExampleComponent = ( ) => {
* const { getFormatTypes } = useSelect (
* ( select ) => select ( richTextStore ) ,
* [ ]
* ) ;
*
* const availableFormats = getFormatTypes ( ) ;
*
* return availableFormats ? (
* < ul >
* { availableFormats ? . map ( ( format ) => (
* < li > { format . name } < / l i >
* ) ) }
* < / u l >
* ) : (
* _ _ ( 'No Formats available' )
* ) ;
* } ;
* ` ` `
*
2020-01-22 17:06:21 -05:00
* @ return { Array } Format types .
* /
2022-04-11 08:04:30 -04:00
const getFormatTypes = rememo ( state => Object . values ( state . formatTypes ) , state => [ state . formatTypes ] ) ;
2023-09-26 10:23:26 -04:00
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
*
2023-09-26 10:23:26 -04:00
* @ example
* ` ` ` js
* import { _ _ , sprintf } from '@wordpress/i18n' ;
* import { store as richTextStore } from '@wordpress/rich-text' ;
* import { useSelect } from '@wordpress/data' ;
*
* const ExampleComponent = ( ) => {
* const { getFormatType } = useSelect (
* ( select ) => select ( richTextStore ) ,
* [ ]
* ) ;
*
* const boldFormat = getFormatType ( 'core/bold' ) ;
*
* return boldFormat ? (
* < ul >
* { Object . entries ( boldFormat ) ? . map ( ( [ key , value ] ) => (
* < li >
* { key } : { value }
* < / l i >
* ) ) }
* < / u l >
* ) : (
* _ _ ( 'Not Found' )
* ;
* } ;
* ` ` `
*
2020-01-22 17:06:21 -05:00
* @ return { Object ? } Format type .
* /
function getFormatType ( state , name ) {
return state . formatTypes [ name ] ;
}
2023-09-26 10:23:26 -04:00
2020-01-22 17:06:21 -05:00
/ * *
* 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 .
2023-09-26 10:23:26 -04:00
*
* @ example
* ` ` ` js
* import { _ _ , sprintf } from '@wordpress/i18n' ;
* import { store as richTextStore } from '@wordpress/rich-text' ;
* import { useSelect } from '@wordpress/data' ;
*
* const ExampleComponent = ( ) => {
* const { getFormatTypeForBareElement } = useSelect (
* ( select ) => select ( richTextStore ) ,
* [ ]
* ) ;
*
* const format = getFormatTypeForBareElement ( 'strong' ) ;
*
* return format && < p > { sprintf ( _ _ ( 'Format name: %s' ) , format . name ) } < / p > ;
* }
* ` ` `
*
2020-01-22 17:06:21 -05:00
* @ return { ? Object } Format type .
* /
function getFormatTypeForBareElement ( state , bareElementTagName ) {
2023-02-07 02:04:52 -05:00
const formatTypes = getFormatTypes ( state ) ;
2023-06-27 10:24:19 -04:00
return formatTypes . find ( ( {
className ,
tagName
} ) => {
2020-01-22 17:06:21 -05:00
return className === null && bareElementTagName === tagName ;
2023-06-27 10:24:19 -04:00
} ) || formatTypes . find ( ( {
className ,
tagName
} ) => {
2023-02-07 02:04:52 -05:00
return className === null && '*' === tagName ;
2020-01-22 17:06:21 -05:00
} ) ;
}
2023-09-26 10:23:26 -04:00
2020-01-22 17:06:21 -05:00
/ * *
* 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 .
2023-09-26 10:23:26 -04:00
*
* @ example
* ` ` ` js
* import { _ _ , sprintf } from '@wordpress/i18n' ;
* import { store as richTextStore } from '@wordpress/rich-text' ;
* import { useSelect } from '@wordpress/data' ;
*
* const ExampleComponent = ( ) => {
* const { getFormatTypeForClassName } = useSelect (
* ( select ) => select ( richTextStore ) ,
* [ ]
* ) ;
*
* const format = getFormatTypeForClassName ( 'has-inline-color' ) ;
*
* return format && < p > { sprintf ( _ _ ( 'Format name: %s' ) , format . name ) } < / p > ;
* } ;
* ` ` `
*
2020-01-22 17:06:21 -05:00
* @ return { ? Object } Format type .
* /
function getFormatTypeForClassName ( state , elementClassName ) {
2023-06-27 10:24:19 -04:00
return getFormatTypes ( state ) . find ( ( {
className
} ) => {
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
} ) ;
}
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/store/actions.js
2020-01-22 17:06:21 -05:00
/ * *
* Returns an action object used in signalling that format types have been
* added .
2023-09-26 10:23:26 -04:00
* Ignored from documentation as registerFormatType should be used instead from @ wordpress / rich - text
*
* @ ignore
2020-01-22 17:06:21 -05:00
*
* @ param { Array | Object } formatTypes Format types received .
*
* @ return { Object } Action object .
* /
function addFormatTypes ( formatTypes ) {
return {
type : 'ADD_FORMAT_TYPES' ,
2023-02-07 02:04:52 -05:00
formatTypes : Array . isArray ( formatTypes ) ? formatTypes : [ formatTypes ]
2020-01-22 17:06:21 -05:00
} ;
}
2023-09-26 10:23:26 -04:00
2020-01-22 17:06:21 -05:00
/ * *
* Returns an action object used to remove a registered format type .
*
2023-09-26 10:23:26 -04:00
* Ignored from documentation as unregisterFormatType should be used instead from @ wordpress / rich - text
*
* @ ignore
*
2020-01-22 17:06:21 -05:00
* @ 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' ,
2023-02-07 02:04:52 -05:00
names : Array . isArray ( names ) ? names : [ names ]
2018-12-17 22:14:52 -05:00
} ;
}
2018-12-13 23:41:57 -05:00
2022-04-11 08:04:30 -04: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
* /
2023-09-26 10:23:26 -04:00
2018-12-13 23:41:57 -05:00
/ * *
* Internal dependencies
* /
2021-05-19 11:09:27 -04:00
const STORE _NAME = 'core/rich-text' ;
2023-09-26 10:23:26 -04:00
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 }
* /
2022-04-11 08:04:30 -04:00
const store = ( 0 , external _wp _data _namespaceObject . createReduxStore ) ( STORE _NAME , {
2018-12-17 22:14:52 -05:00
reducer : reducer ,
selectors : selectors _namespaceObject ,
actions : actions _namespaceObject
} ) ;
2022-04-11 08:04:30 -04:00
( 0 , external _wp _data _namespaceObject . register ) ( store ) ;
2018-12-14 06:02:53 -05:00
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/is-format-equal.js
2023-06-27 10:24:19 -04:00
/** @typedef {import('./types').RichTextFormat} RichTextFormat */
2020-10-13 09:10:30 -04:00
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 ;
2023-09-26 10:23:26 -04:00
}
2018-12-14 06:02:53 -05:00
2023-09-26 10:23:26 -04:00
// Either not defined.
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 ;
}
2021-05-19 11:09:27 -04:00
const attributes1 = format1 . attributes ;
2023-09-26 10:23:26 -04:00
const attributes2 = format2 . attributes ;
2018-12-16 23:52:00 -05:00
2023-09-26 10:23:26 -04:00
// Both not defined.
2018-12-17 22:14:52 -05:00
if ( attributes1 === attributes2 ) {
return true ;
2023-09-26 10:23:26 -04:00
}
2018-12-16 23:52:00 -05:00
2023-09-26 10:23:26 -04:00
// Either not defined.
2018-12-17 22:14:52 -05:00
if ( ! attributes1 || ! attributes2 ) {
return false ;
2018-12-16 23:52:00 -05:00
}
2021-05-19 11:09:27 -04:00
const keys1 = Object . keys ( attributes1 ) ;
const keys2 = Object . keys ( attributes2 ) ;
2018-12-17 22:14:52 -05:00
if ( keys1 . length !== keys2 . length ) {
return false ;
2018-12-14 06:02:53 -05:00
}
2023-09-26 10:23:26 -04:00
const length = keys1 . length ;
2018-12-14 06:02:53 -05:00
2023-09-26 10:23:26 -04:00
// Optimise for speed.
2021-05-19 11:09:27 -04:00
for ( let i = 0 ; i < length ; i ++ ) {
const name = keys1 [ i ] ;
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
2022-04-11 08:04:30 -04: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
* /
2023-09-26 10:23:26 -04:00
2023-06-27 10:24:19 -04:00
/** @typedef {import('./types').RichTextValue} RichTextValue */
2020-10-13 09:10:30 -04:00
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 ] ;
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 ] ;
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
} ) ;
2023-09-26 10:23:26 -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
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/apply-format.js
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
2023-09-26 10:23:26 -04:00
/** @typedef {import('./types').RichTextValue} RichTextValue */
2023-06-27 10:24:19 -04:00
/** @typedef {import('./types').RichTextFormat} RichTextFormat */
2019-09-19 11:19:18 -04:00
function replace ( array , index , value ) {
array = array . slice ( ) ;
array [ index ] = value ;
return array ;
}
2023-09-26 10:23:26 -04:00
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
* /
2023-06-27 10:24:19 -04:00
function applyFormat ( value , format , startIndex = value . start , endIndex = value . end ) {
2021-05-19 11:09:27 -04:00
const {
formats ,
activeFormats
} = value ;
2023-09-26 10:23:26 -04:00
const newFormats = formats . slice ( ) ;
2018-12-13 23:41:57 -05:00
2023-09-26 10:23:26 -04:00
// The selection is collapsed.
2018-12-17 22:14:52 -05:00
if ( startIndex === endIndex ) {
2023-06-27 10:24:19 -04:00
const startFormat = newFormats [ startIndex ] ? . find ( ( {
type
2023-09-26 10:23:26 -04:00
} ) => type === format . type ) ;
2018-12-14 06:02:53 -05:00
2023-09-26 10:23:26 -04:00
// 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-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 ++ ;
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 ;
for ( let index = startIndex ; index < endIndex ; index ++ ) {
if ( newFormats [ index ] ) {
2023-06-27 10:24:19 -04:00
newFormats [ index ] = newFormats [ index ] . filter ( ( {
type
} ) => 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
}
}
2023-09-26 10:23:26 -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.
2023-06-27 10:24:19 -04:00
activeFormats : [ ... ( activeFormats ? . filter ( ( {
type
} ) => type !== format . type ) || [ ] ) , format ]
2021-05-19 11:09:27 -04:00
} ) ;
2018-12-13 23:41:57 -05:00
}
2022-04-11 08:04:30 -04: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
* /
2023-06-27 10:24:19 -04:00
function createElement ( {
implementation
} , html ) {
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 ;
}
createElement . body . innerHTML = html ;
return createElement . body ;
2018-12-15 06:00:40 -05:00
}
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/special-characters.js
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' ;
2023-09-26 10:23:26 -04:00
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
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
; // CONCATENATED MODULE: external ["wp","escapeHtml"]
2024-01-31 07:59:56 -05:00
const external _wp _escapeHtml _namespaceObject = window [ "wp" ] [ "escapeHtml" ] ;
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-active-formats.js
/** @typedef {import('./types').RichTextValue} RichTextValue */
/** @typedef {import('./types').RichTextFormatList} RichTextFormatList */
2018-12-15 06:00:40 -05:00
/ * *
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
* Internal dependencies
2018-12-15 06:00:40 -05:00
* /
2023-09-26 10:23:26 -04:00
2018-12-13 23:41:57 -05:00
/ * *
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
* Gets the all format objects at the start of the selection .
*
* @ param { RichTextValue } value Value to inspect .
* @ param { Array } EMPTY _ACTIVE _FORMATS Array to return if there are no
* active formats .
*
* @ return { RichTextFormatList } Active format objects .
2018-12-13 23:41:57 -05:00
* /
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
function getActiveFormats ( value , EMPTY _ACTIVE _FORMATS = [ ] ) {
const {
formats ,
start ,
end ,
activeFormats
} = value ;
if ( start === undefined ) {
return EMPTY _ACTIVE _FORMATS ;
}
if ( start === end ) {
// For a collapsed caret, it is possible to override the active formats.
if ( activeFormats ) {
return activeFormats ;
}
const formatsBefore = formats [ start - 1 ] || EMPTY _ACTIVE _FORMATS ;
const formatsAfter = formats [ start ] || EMPTY _ACTIVE _FORMATS ;
2018-12-13 23:41:57 -05:00
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
// By default, select the lowest amount of formats possible (which means
// 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 ;
}
return formatsAfter ;
}
2018-12-13 23:41:57 -05:00
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
// If there's no formats at the start index, there are not active formats.
if ( ! formats [ start ] ) {
return EMPTY _ACTIVE _FORMATS ;
}
const selectedFormats = formats . slice ( start , end ) ;
2018-12-13 23:41:57 -05:00
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
// Clone the formats so we're not mutating the live value.
const _activeFormats = [ ... selectedFormats [ 0 ] ] ;
let i = selectedFormats . length ;
2018-12-13 23:41:57 -05:00
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
// For performance reasons, start from the end where it's much quicker to
// realise that there are no active formats.
while ( i -- ) {
const formatsAtIndex = selectedFormats [ i ] ;
2018-12-14 06:02:53 -05:00
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
// If we run into any index without formats, we're sure that there's no
// active formats.
if ( ! formatsAtIndex ) {
return EMPTY _ACTIVE _FORMATS ;
}
let ii = _activeFormats . length ;
2018-12-14 06:02:53 -05:00
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
// Loop over the active formats and remove any that are not present at
// the current index.
while ( ii -- ) {
const format = _activeFormats [ ii ] ;
if ( ! formatsAtIndex . find ( _format => isFormatEqual ( format , _format ) ) ) {
_activeFormats . splice ( ii , 1 ) ;
2018-12-17 22:14:52 -05:00
}
}
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
// If there are no active formats, we can stop.
if ( _activeFormats . length === 0 ) {
return EMPTY _ACTIVE _FORMATS ;
}
2018-12-17 22:14:52 -05:00
}
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
return _activeFormats || EMPTY _ACTIVE _FORMATS ;
}
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-format-type.js
/ * *
* WordPress dependencies
* /
/ * *
* Internal dependencies
* /
/** @typedef {import('./register-format-type').RichTextFormatType} RichTextFormatType */
/ * *
* Returns a registered format type .
*
* @ param { string } name Format name .
*
* @ return { RichTextFormatType | undefined } Format type .
* /
function get _format _type _getFormatType ( name ) {
return ( 0 , external _wp _data _namespaceObject . select ) ( store ) . getFormatType ( name ) ;
}
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/to-tree.js
/ * *
* Internal dependencies
* /
function restoreOnAttributes ( attributes , isEditableTree ) {
if ( isEditableTree ) {
return attributes ;
2018-12-17 22:14:52 -05:00
}
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
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 ] ;
2018-12-17 22:14:52 -05:00
}
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
return newAttributes ;
}
/ * *
* Converts a format object to information that can be used to create an element
* from ( type , attributes and object ) .
*
* @ param { Object } $1 Named parameters .
* @ param { string } $1 . type The format type .
* @ param { string } $1 . tagName The tag name .
* @ 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
*
* @ return { Object } Information to be used for element creation .
* /
function fromFormat ( {
type ,
tagName ,
attributes ,
unregisteredAttributes ,
object ,
boundaryClass ,
isEditableTree
} ) {
const formatType = get _format _type _getFormatType ( type ) ;
let elementAttributes = { } ;
if ( boundaryClass && isEditableTree ) {
elementAttributes [ 'data-rich-text-format-boundary' ] = 'true' ;
2019-03-21 08:48:00 -04:00
}
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
if ( ! formatType ) {
if ( attributes ) {
elementAttributes = {
... attributes ,
... elementAttributes
} ;
}
2018-12-17 22:14:52 -05:00
return {
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
type ,
attributes : restoreOnAttributes ( elementAttributes , isEditableTree ) ,
object
2018-12-17 22:14:52 -05:00
} ;
}
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
elementAttributes = {
... unregisteredAttributes ,
... elementAttributes
2021-11-08 09:29:21 -05:00
} ;
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
for ( const name in attributes ) {
const key = formatType . attributes ? formatType . attributes [ name ] : false ;
if ( key ) {
elementAttributes [ key ] = attributes [ name ] ;
} else {
elementAttributes [ name ] = attributes [ name ] ;
2018-12-17 22:14:52 -05:00
}
}
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
if ( formatType . className ) {
if ( elementAttributes . class ) {
elementAttributes . class = ` ${ formatType . className } ${ elementAttributes . class } ` ;
} else {
elementAttributes . class = formatType . className ;
}
2021-11-08 09:29:21 -05:00
}
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
// When a format is declared as non editable, make it non editable in the
// editor.
if ( isEditableTree && formatType . contentEditable === false ) {
elementAttributes . contenteditable = 'false' ;
2023-06-27 10:24:19 -04:00
}
2018-12-17 22:14:52 -05:00
return {
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
type : tagName || formatType . tagName ,
object : formatType . object ,
attributes : restoreOnAttributes ( elementAttributes , isEditableTree )
2018-12-17 22:14:52 -05:00
} ;
}
2023-09-26 10:23:26 -04:00
2018-12-17 22:14:52 -05:00
/ * *
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
* Checks if both arrays of formats up until a certain index are equal .
2019-03-21 08:48:00 -04:00
*
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
* @ 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 ;
}
function toTree ( {
value ,
2024-03-12 10:30:24 -04:00
preserveWhiteSpace ,
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
createEmpty ,
append ,
getLastChild ,
getParent ,
isText ,
getText ,
remove ,
appendText ,
onStartIndex ,
onEndIndex ,
isEditableTree ,
placeholder
} ) {
const {
formats ,
replacements ,
text ,
start ,
end
} = value ;
const formatsLength = formats . length + 1 ;
const tree = createEmpty ( ) ;
const activeFormats = getActiveFormats ( value ) ;
const deepestActiveFormat = activeFormats [ activeFormats . length - 1 ] ;
let lastCharacterFormats ;
let lastCharacter ;
append ( tree , '' ) ;
for ( let i = 0 ; i < formatsLength ; i ++ ) {
const character = text . charAt ( i ) ;
const shouldInsertPadding = isEditableTree && (
// Pad the line if the line is empty.
! lastCharacter ||
// Pad the line if the previous character is a line break, otherwise
// the line break won't be visible.
lastCharacter === '\n' ) ;
const characterFormats = formats [ i ] ;
let pointer = getLastChild ( tree ) ;
if ( characterFormats ) {
characterFormats . forEach ( ( format , formatIndex ) => {
if ( pointer && lastCharacterFormats &&
// Reuse the last element if all formats remain the same.
isEqualUntil ( characterFormats , lastCharacterFormats , formatIndex ) ) {
pointer = getLastChild ( pointer ) ;
return ;
}
const {
type ,
tagName ,
attributes ,
unregisteredAttributes
} = format ;
const boundaryClass = isEditableTree && format === deepestActiveFormat ;
const parent = getParent ( pointer ) ;
const newNode = append ( parent , fromFormat ( {
type ,
tagName ,
attributes ,
unregisteredAttributes ,
boundaryClass ,
isEditableTree
} ) ) ;
if ( isText ( pointer ) && getText ( pointer ) . length === 0 ) {
remove ( pointer ) ;
}
pointer = append ( newNode , '' ) ;
} ) ;
}
// If there is selection at 0, handle it before characters are inserted.
if ( i === 0 ) {
if ( onStartIndex && start === 0 ) {
onStartIndex ( tree , pointer ) ;
}
if ( onEndIndex && end === 0 ) {
onEndIndex ( tree , pointer ) ;
}
}
if ( character === OBJECT _REPLACEMENT _CHARACTER ) {
const replacement = replacements [ i ] ;
if ( ! replacement ) continue ;
const {
type ,
attributes ,
innerHTML
} = replacement ;
const formatType = get _format _type _getFormatType ( type ) ;
if ( ! isEditableTree && type === 'script' ) {
pointer = append ( getParent ( pointer ) , fromFormat ( {
type : 'script' ,
isEditableTree
} ) ) ;
append ( pointer , {
html : decodeURIComponent ( attributes [ 'data-rich-text-script' ] )
} ) ;
} else if ( formatType ? . contentEditable === false ) {
// For non editable formats, render the stored inner HTML.
pointer = append ( getParent ( pointer ) , fromFormat ( {
... replacement ,
isEditableTree ,
boundaryClass : start === i && end === i + 1
} ) ) ;
if ( innerHTML ) {
append ( pointer , {
html : innerHTML
} ) ;
}
} else {
pointer = append ( getParent ( pointer ) , fromFormat ( {
... replacement ,
object : true ,
isEditableTree
} ) ) ;
}
// Ensure pointer is text node.
pointer = append ( getParent ( pointer ) , '' ) ;
2024-03-12 10:30:24 -04:00
} else if ( ! preserveWhiteSpace && character === '\n' ) {
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05: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 ) ;
}
if ( onStartIndex && start === i + 1 ) {
onStartIndex ( tree , pointer ) ;
}
if ( onEndIndex && end === i + 1 ) {
onEndIndex ( tree , pointer ) ;
}
if ( shouldInsertPadding && i === text . length ) {
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 and being editable.
style : 'pointer-events:none;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;'
}
} ) ;
}
}
lastCharacterFormats = characterFormats ;
lastCharacter = character ;
}
return tree ;
}
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/to-html-string.js
/ * *
* WordPress dependencies
* /
/ * *
* Internal dependencies
* /
/** @typedef {import('./types').RichTextValue} RichTextValue */
/ * *
* Create an HTML string from a Rich Text value .
*
2024-03-12 10:30:24 -04:00
* @ param { Object } $1 Named argements .
* @ param { RichTextValue } $1 . value Rich text value .
* @ param { boolean } [ $1 . preserveWhiteSpace ] Preserves newlines if true .
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
*
* @ return { string } HTML string .
* /
function toHTMLString ( {
2024-03-12 10:30:24 -04:00
value ,
preserveWhiteSpace
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
} ) {
const tree = toTree ( {
value ,
2024-03-12 10:30:24 -04:00
preserveWhiteSpace ,
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
createEmpty ,
append ,
getLastChild ,
getParent ,
isText ,
getText ,
remove ,
appendText
} ) ;
return createChildrenHTML ( tree . children ) ;
}
function createEmpty ( ) {
return { } ;
}
function getLastChild ( {
children
} ) {
return children && children [ children . length - 1 ] ;
}
function append ( parent , object ) {
if ( typeof object === 'string' ) {
object = {
text : object
} ;
}
object . parent = parent ;
parent . children = parent . children || [ ] ;
parent . children . push ( object ) ;
return object ;
}
function appendText ( object , text ) {
object . text += text ;
}
function getParent ( {
parent
} ) {
return parent ;
}
function isText ( {
text
} ) {
return typeof text === 'string' ;
}
function getText ( {
text
} ) {
return text ;
}
function remove ( object ) {
const index = object . parent . children . indexOf ( object ) ;
if ( index !== - 1 ) {
object . parent . children . splice ( index , 1 ) ;
}
return object ;
}
function createElementHTML ( {
type ,
attributes ,
object ,
children
} ) {
let attributeString = '' ;
for ( const key in attributes ) {
if ( ! ( 0 , external _wp _escapeHtml _namespaceObject . isValidAttributeName ) ( key ) ) {
continue ;
}
attributeString += ` ${ key } =" ${ ( 0 , external _wp _escapeHtml _namespaceObject . escapeAttribute ) ( attributes [ key ] ) } " ` ;
}
if ( object ) {
return ` < ${ type } ${ attributeString } > ` ;
}
return ` < ${ type } ${ attributeString } > ${ createChildrenHTML ( children ) } </ ${ type } > ` ;
}
function createChildrenHTML ( children = [ ] ) {
return children . map ( child => {
if ( child . html !== undefined ) {
return child . html ;
}
return child . text === undefined ? createElementHTML ( child ) : ( 0 , external _wp _escapeHtml _namespaceObject . escapeEditableHTML ) ( child . text ) ;
} ) . join ( '' ) ;
}
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-text-content.js
/ * *
* Internal dependencies
* /
/** @typedef {import('./types').RichTextValue} RichTextValue */
/ * *
* Get the textual content of a Rich Text value . This is similar to
* ` Element.textContent ` .
*
* @ param { RichTextValue } value Value to use .
*
* @ return { string } The text content .
* /
function getTextContent ( {
text
} ) {
return text . replace ( OBJECT _REPLACEMENT _CHARACTER , '' ) ;
}
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/create.js
/ * *
* WordPress dependencies
* /
/ * *
* Internal dependencies
* /
/** @typedef {import('./types').RichTextValue} RichTextValue */
function createEmptyValue ( ) {
return {
formats : [ ] ,
replacements : [ ] ,
text : ''
} ;
}
function toFormat ( {
tagName ,
attributes
} ) {
let formatType ;
if ( attributes && attributes . class ) {
formatType = ( 0 , external _wp _data _namespaceObject . select ) ( store ) . getFormatTypeForClassName ( attributes . class ) ;
if ( formatType ) {
// Preserve any additional classes.
attributes . class = ` ${ attributes . class } ` . replace ( ` ${ formatType . className } ` , ' ' ) . trim ( ) ;
if ( ! attributes . class ) {
delete attributes . class ;
}
}
}
if ( ! formatType ) {
formatType = ( 0 , external _wp _data _namespaceObject . select ) ( store ) . getFormatTypeForBareElement ( tagName ) ;
}
if ( ! formatType ) {
return attributes ? {
type : tagName ,
attributes
} : {
type : tagName
} ;
}
if ( formatType . _ _experimentalCreatePrepareEditableTree && ! formatType . _ _experimentalCreateOnChangeEditableValue ) {
return null ;
}
if ( ! attributes ) {
return {
formatType ,
type : formatType . name ,
tagName
} ;
}
const registeredAttributes = { } ;
const unregisteredAttributes = { } ;
const _attributes = {
... attributes
} ;
for ( const key in formatType . attributes ) {
const name = formatType . attributes [ key ] ;
registeredAttributes [ key ] = _attributes [ name ] ;
// delete the attribute and what's left is considered
// to be unregistered.
delete _attributes [ name ] ;
if ( typeof registeredAttributes [ key ] === 'undefined' ) {
delete registeredAttributes [ key ] ;
}
}
for ( const name in _attributes ) {
unregisteredAttributes [ name ] = attributes [ name ] ;
}
if ( formatType . contentEditable === false ) {
delete unregisteredAttributes . contenteditable ;
}
return {
formatType ,
type : formatType . name ,
tagName ,
attributes : registeredAttributes ,
unregisteredAttributes
} ;
}
/ * *
* The RichTextData class is used to instantiate a wrapper around rich text
* values , with methods that can be used to transform or manipulate the data .
*
2024-02-09 13:22:22 -05:00
* - Create an empty instance : ` new RichTextData() ` .
* - Create one from an HTML string : ` RichTextData.fromHTMLString(
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
* '<em>hello</em>' ) ` .
* - Create one from a wrapper HTMLElement : ` RichTextData.fromHTMLElement(
* document . querySelector ( 'p' ) ) ` .
* - Create one from plain text : ` RichTextData.fromPlainText( '1 \n 2' ) ` .
* - Create one from a rich text value : ` new RichTextData( { text: '...',
* formats : [ ... ] } ) ` .
*
* @ todo Add methods to manipulate the data , such as applyFormat , slice etc .
* /
class RichTextData {
2024-02-09 13:22:22 -05:00
# value ;
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
static empty ( ) {
return new RichTextData ( ) ;
}
static fromPlainText ( text ) {
return new RichTextData ( create ( {
text
} ) ) ;
}
static fromHTMLString ( html ) {
return new RichTextData ( create ( {
html
} ) ) ;
}
static fromHTMLElement ( htmlElement , options = { } ) {
const {
preserveWhiteSpace = false
} = options ;
const element = preserveWhiteSpace ? htmlElement : collapseWhiteSpace ( htmlElement ) ;
const richTextData = new RichTextData ( create ( {
element
} ) ) ;
Object . defineProperty ( richTextData , 'originalHTML' , {
value : htmlElement . innerHTML
} ) ;
return richTextData ;
}
constructor ( init = createEmptyValue ( ) ) {
2024-02-09 13:22:22 -05:00
this . # value = init ;
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
}
toPlainText ( ) {
2024-02-09 13:22:22 -05:00
return getTextContent ( this . # value ) ;
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
}
// We could expose `toHTMLElement` at some point as well, but we'd only use
// it internally.
2024-03-12 10:30:24 -04:00
toHTMLString ( {
preserveWhiteSpace
} = { } ) {
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
return this . originalHTML || toHTMLString ( {
2024-03-12 10:30:24 -04:00
value : this . # value ,
preserveWhiteSpace
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
} ) ;
}
valueOf ( ) {
return this . toHTMLString ( ) ;
}
toString ( ) {
return this . toHTMLString ( ) ;
}
toJSON ( ) {
return this . toHTMLString ( ) ;
}
get length ( ) {
return this . text . length ;
}
get formats ( ) {
2024-02-09 13:22:22 -05:00
return this . # value . formats ;
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
}
get replacements ( ) {
2024-02-09 13:22:22 -05:00
return this . # value . replacements ;
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
}
get text ( ) {
2024-02-09 13:22:22 -05:00
return this . # value . text ;
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
}
}
for ( const name of Object . getOwnPropertyNames ( String . prototype ) ) {
if ( RichTextData . prototype . hasOwnProperty ( name ) ) {
continue ;
}
Object . defineProperty ( RichTextData . prototype , name , {
value ( ... args ) {
// Should we convert back to RichTextData?
return this . toHTMLString ( ) [ name ] ( ... args ) ;
}
} ) ;
}
/ * *
* 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 . The optional
* functions can be used to filter out content .
*
* 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 ,
* }
2019-03-21 08:48:00 -04:00
* ` ` `
*
* 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 .
2020-10-13 09:10:30 -04:00
* @ param { boolean } [ $1 . _ _unstableIsEditableTree ]
* @ return { RichTextValue } A rich text value .
2018-12-17 22:14:52 -05:00
* /
2023-06-27 10:24:19 -04:00
function create ( {
element ,
text ,
html ,
range ,
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
_ _unstableIsEditableTree : isEditableTree
2023-06-27 10:24:19 -04:00
} = { } ) {
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
if ( html instanceof RichTextData ) {
return {
text : html . text ,
formats : html . formats ,
replacements : html . replacements
} ;
}
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
} ;
}
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 ) ;
}
2021-05-19 11:09:27 -04:00
if ( typeof element !== 'object' ) {
2018-12-17 22:14:52 -05:00
return createEmptyValue ( ) ;
}
2023-09-26 10:23:26 -04:00
return createFromElement ( {
2021-05-19 11:09:27 -04:00
element ,
range ,
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
isEditableTree
2018-12-17 22:14:52 -05:00
} ) ;
}
2023-09-26 10:23:26 -04:00
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 .
* /
function accumulateSelection ( accumulator , node , range , value ) {
if ( ! range ) {
return ;
}
2021-05-19 11:09:27 -04:00
const {
parentNode
} = node ;
const {
startContainer ,
startOffset ,
endContainer ,
endOffset
} = range ;
2023-09-26 10:23:26 -04:00
const currentLength = accumulator . text . length ;
2018-12-14 06:02:53 -05:00
2023-09-26 10:23:26 -04:00
// Selection can be extracted from value.
2018-12-17 22:14:52 -05:00
if ( value . start !== undefined ) {
2023-09-26 10:23:26 -04:00
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 ) {
2023-09-26 10:23:26 -04:00
accumulator . start = currentLength + startOffset ;
// Range indicates that the current node is selected.
2018-12-17 22:14:52 -05:00
} else if ( parentNode === startContainer && node === startContainer . childNodes [ startOffset ] ) {
2023-09-26 10:23:26 -04:00
accumulator . start = currentLength ;
// Range indicates that the selection is after the current node.
2018-12-17 22:14:52 -05:00
} else if ( parentNode === startContainer && node === startContainer . childNodes [ startOffset - 1 ] ) {
2023-09-26 10:23:26 -04:00
accumulator . start = currentLength + value . text . length ;
// Fallback if no child inside handled the selection.
2018-12-17 22:14:52 -05:00
} else if ( node === startContainer ) {
accumulator . start = currentLength ;
2023-09-26 10:23:26 -04:00
}
2018-12-14 06:02:53 -05:00
2023-09-26 10:23:26 -04:00
// Selection can be extracted from value.
2018-12-17 22:14:52 -05:00
if ( value . end !== undefined ) {
2023-09-26 10:23:26 -04:00
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 ) {
2023-09-26 10:23:26 -04:00
accumulator . end = currentLength + endOffset ;
// Range indicates that the current node is selected.
2018-12-17 22:14:52 -05:00
} else if ( parentNode === endContainer && node === endContainer . childNodes [ endOffset - 1 ] ) {
2023-09-26 10:23:26 -04:00
accumulator . end = currentLength + value . text . length ;
// Range indicates that the selection is before the current node.
2018-12-17 22:14:52 -05:00
} else if ( parentNode === endContainer && node === endContainer . childNodes [ endOffset ] ) {
2023-09-26 10:23:26 -04:00
accumulator . end = currentLength ;
// Fallback if no child inside handled the selection.
2018-12-17 22:14:52 -05:00
} else if ( node === endContainer ) {
accumulator . end = currentLength + endOffset ;
}
}
2023-09-26 10:23:26 -04:00
2018-12-17 22:14:52 -05:00
/ * *
* 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
* /
function filterRange ( node , range , filter ) {
if ( ! range ) {
return ;
}
2021-05-19 11:09:27 -04:00
const {
startContainer ,
endContainer
} = range ;
let {
startOffset ,
endOffset
} = range ;
2018-12-17 22:14:52 -05:00
if ( node === startContainer ) {
startOffset = filter ( node . nodeValue . slice ( 0 , startOffset ) ) . length ;
}
if ( node === endContainer ) {
endOffset = filter ( node . nodeValue . slice ( 0 , endOffset ) ) . length ;
}
return {
2021-05-19 11:09:27 -04:00
startContainer ,
startOffset ,
endContainer ,
endOffset
2018-12-17 22:14:52 -05:00
} ;
}
2023-09-26 10:23:26 -04: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 .
*
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
* We need to strip it from the content because we use white - space : pre - wrap for
* displaying editable rich text . Without using white - space : pre - wrap , the
* browser will litter the content with non breaking spaces , among other issues .
* See packages / rich - text / src / component / use - default - style . js .
*
* @ see
* https : //developer.mozilla.org/en-US/docs/Web/CSS/white-space-collapse#collapsing_of_white_space
*
* @ param { HTMLElement } element
* @ param { boolean } isRoot
*
* @ return { HTMLElement } New element with collapsed whitespace .
2020-01-08 06:57:23 -05:00
* /
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
function collapseWhiteSpace ( element , isRoot = true ) {
const clone = element . cloneNode ( true ) ;
clone . normalize ( ) ;
Array . from ( clone . childNodes ) . forEach ( ( node , i , nodes ) => {
if ( node . nodeType === node . TEXT _NODE ) {
let newNodeValue = node . nodeValue ;
if ( /[\n\t\r\f]/ . test ( newNodeValue ) ) {
newNodeValue = newNodeValue . replace ( /[\n\t\r\f]+/g , ' ' ) ;
}
if ( newNodeValue . indexOf ( ' ' ) !== - 1 ) {
newNodeValue = newNodeValue . replace ( / {2,}/g , ' ' ) ;
}
if ( i === 0 && newNodeValue . startsWith ( ' ' ) ) {
newNodeValue = newNodeValue . slice ( 1 ) ;
} else if ( isRoot && i === nodes . length - 1 && newNodeValue . endsWith ( ' ' ) ) {
newNodeValue = newNodeValue . slice ( 0 , - 1 ) ;
}
node . nodeValue = newNodeValue ;
} else if ( node . nodeType === node . ELEMENT _NODE ) {
collapseWhiteSpace ( node , false ) ;
}
} ) ;
return clone ;
2020-01-08 06:57:23 -05:00
}
2023-09-26 10:23:26 -04:00
2020-01-08 06:57:23 -05:00
/ * *
2024-02-09 13:22:22 -05:00
* We need to normalise line breaks to ` \n ` so they are consistent across
* platforms and serialised properly . Not removing \ r would cause it to
* linger and result in double line breaks when whitespace is preserved .
* /
const CARRIAGE _RETURN = '\r' ;
/ * *
* 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
* /
2021-11-08 09:29:21 -05:00
function removeReservedCharacters ( string ) {
2024-02-09 13:22:22 -05:00
// 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 } ${ CARRIAGE _RETURN } ] ` , 'gu' ) , '' ) ;
2019-03-07 04:09:59 -05:00
}
2023-09-26 10:23:26 -04:00
2018-12-17 22:14:52 -05:00
/ * *
* Creates a Rich Text value from a DOM element and range .
*
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
* @ param { Object } $1 Named argements .
* @ param { Element } [ $1 . element ] Element to create value from .
* @ param { Range } [ $1 . range ] Range to create value from .
2020-10-13 09:10:30 -04:00
* @ 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
* /
2023-06-27 10:24:19 -04:00
function createFromElement ( {
element ,
range ,
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
isEditableTree
2023-06-27 10:24:19 -04:00
} ) {
2021-05-19 11:09:27 -04:00
const accumulator = createEmptyValue ( ) ;
2018-12-17 22:14:52 -05:00
if ( ! element ) {
return accumulator ;
}
if ( ! element . hasChildNodes ( ) ) {
accumulateSelection ( accumulator , element , range , createEmptyValue ( ) ) ;
return accumulator ;
}
2023-09-26 10:23:26 -04:00
const length = element . childNodes . length ;
2018-12-13 23:41:57 -05:00
2023-09-26 10:23:26 -04:00
// Optimise for speed.
2021-05-19 11:09:27 -04:00
for ( let index = 0 ; index < length ; index ++ ) {
const node = element . childNodes [ index ] ;
2023-02-07 02:04:52 -05:00
const tagName = node . nodeName . toLowerCase ( ) ;
2020-06-26 09:33:47 -04:00
if ( node . nodeType === node . TEXT _NODE ) {
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
const text = removeReservedCharacters ( node . nodeValue ) ;
range = filterRange ( node , range , removeReservedCharacters ) ;
2018-12-17 22:14:52 -05:00
accumulateSelection ( accumulator , node , range , {
2021-05-19 11:09:27 -04:00
text
2023-09-26 10:23:26 -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.
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
}
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
}
2024-03-04 09:08:24 -05:00
if ( isEditableTree &&
2023-09-26 10:23:26 -04:00
// Ignore any line breaks that are not inserted by us.
2024-03-04 09:08:24 -05:00
tagName === '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
}
2023-02-07 02:04:52 -05:00
if ( tagName === 'script' ) {
2021-07-13 19:58:30 -04:00
const value = {
formats : [ , ] ,
replacements : [ {
2023-02-07 02:04:52 -05:00
type : tagName ,
2021-07-13 19:58:30 -04:00
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 ;
}
2023-02-07 02:04:52 -05:00
if ( tagName === 'br' ) {
2018-12-17 22:14:52 -05:00
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
}
2021-11-08 09:29:21 -05:00
const format = toFormat ( {
2023-02-07 02:04:52 -05:00
tagName ,
2019-03-07 04:09:59 -05:00
attributes : getAttributes ( {
element : node
} )
2023-09-26 10:23:26 -04:00
} ) ;
2023-06-27 10:24:19 -04:00
2023-09-26 10:23:26 -04:00
// When a format type is declared as not editable, replace it with an
// object replacement character and preserve the inner HTML.
2023-06-27 10:24:19 -04:00
if ( format ? . formatType ? . contentEditable === false ) {
delete format . formatType ;
accumulateSelection ( accumulator , node , range , createEmptyValue ( ) ) ;
mergePair ( accumulator , {
formats : [ , ] ,
2023-09-26 10:23:26 -04:00
replacements : [ {
... format ,
2023-06-27 10:24:19 -04:00
innerHTML : node . innerHTML
} ] ,
text : OBJECT _REPLACEMENT _CHARACTER
} ) ;
continue ;
}
if ( format ) delete format . formatType ;
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 ,
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
isEditableTree
2019-03-21 08:48:00 -04:00
} ) ;
accumulateSelection ( accumulator , node , range , value ) ;
2024-03-04 09:08:24 -05:00
// Ignore any placeholders, but keep their content since the browser
// might insert text inside them when the editable element is flex.
if ( ! format || node . getAttribute ( 'data-rich-text-placeholder' ) ) {
2019-03-21 08:48:00 -04:00
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 ;
2023-09-26 10:23:26 -04:00
}
2020-01-22 17:06:21 -05:00
2023-09-26 10:23:26 -04:00
// Since the formats parameter can be `undefined`, preset
// `mergeFormats` with a new reference.
2020-01-22 17:06:21 -05:00
mergeFormats . newFormats = [ format ] ;
2023-09-26 10:23:26 -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-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
* /
2023-06-27 10:24:19 -04:00
function getAttributes ( {
element
} ) {
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 ;
2023-09-26 10:23:26 -04:00
let accumulator ;
2018-12-13 23:41:57 -05:00
2023-09-26 10:23:26 -04:00
// Optimise for speed.
2021-05-19 11:09:27 -04:00
for ( let i = 0 ; i < length ; i ++ ) {
const {
name ,
value
} = element . attributes [ i ] ;
2019-03-21 08:48:00 -04:00
if ( name . indexOf ( 'data-rich-text-' ) === 0 ) {
2018-12-17 22:14:52 -05:00
continue ;
}
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
}
2019-03-07 04:09:59 -05:00
return accumulator ;
}
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/concat.js
2019-03-21 08:48:00 -04:00
/ * *
* Internal dependencies
* /
2023-09-26 10:23:26 -04:00
2023-06-27 10:24:19 -04:00
/** @typedef {import('./types').RichTextValue} RichTextValue */
2020-10-13 09:10:30 -04:00
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 ;
}
2023-09-26 10:23:26 -04:00
2019-03-21 08:48:00 -04:00
/ * *
* 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
* /
2023-06-27 10:24:19 -04:00
function concat ( ... values ) {
2019-03-21 08:48:00 -04:00
return normaliseFormats ( values . reduce ( mergePair , create ( ) ) ) ;
}
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-active-format.js
2019-03-07 04:09:59 -05:00
/ * *
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
2023-09-26 10:23:26 -04:00
/** @typedef {import('./types').RichTextValue} RichTextValue */
2023-06-27 10:24:19 -04:00
/** @typedef {import('./types').RichTextFormat} RichTextFormat */
2020-10-13 09:10:30 -04:00
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 ) {
2023-06-27 10:24:19 -04:00
return getActiveFormats ( value ) . find ( ( {
type
} ) => type === formatType ) ;
2018-12-13 23:41:57 -05:00
}
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-active-object.js
2019-03-21 08:48:00 -04:00
/ * *
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
2023-09-26 10:23:26 -04:00
/** @typedef {import('./types').RichTextValue} RichTextValue */
2023-06-27 10:24:19 -04:00
/** @typedef {import('./types').RichTextFormat} RichTextFormat */
2020-10-13 09:10:30 -04:00
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
* /
2023-06-27 10:24:19 -04:00
function getActiveObject ( {
start ,
end ,
replacements ,
text
} ) {
2019-03-21 08:48:00 -04:00
if ( start + 1 !== end || text [ start ] !== OBJECT _REPLACEMENT _CHARACTER ) {
return ;
}
return replacements [ start ] ;
}
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/is-collapsed.js
2023-06-27 10:24:19 -04:00
/ * *
* Internal dependencies
* /
2020-10-13 09:10:30 -04:00
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() ` .
*
2023-06-27 10:24:19 -04:00
* @ param props The rich text value to check .
* @ param props . start
* @ param props . end
* @ return True if the selection is collapsed , false if not , undefined if there is no selection .
* /
function isCollapsed ( {
start ,
end
} ) {
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
}
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/is-empty.js
2023-06-27 10:24:19 -04:00
/** @typedef {import('./types').RichTextValue} RichTextValue */
2020-10-13 09:10:30 -04:00
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 .
* /
2023-06-27 10:24:19 -04:00
function isEmpty ( {
text
} ) {
2019-03-21 08:48:00 -04:00
return text . length === 0 ;
}
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/join.js
2018-12-13 23:41:57 -05:00
/ * *
* Internal dependencies
* /
2023-09-26 10:23:26 -04:00
2023-06-27 10:24:19 -04:00
/** @typedef {import('./types').RichTextValue} RichTextValue */
2020-10-13 09:10:30 -04:00
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
* /
2023-06-27 10:24:19 -04:00
function join ( values , separator = '' ) {
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
} ) ;
}
2023-06-27 10:24:19 -04:00
return normaliseFormats ( values . reduce ( ( accumlator , {
formats ,
replacements ,
text
} ) => ( {
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
}
2022-04-11 08:04:30 -04: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
*
2023-09-26 10:23:26 -04:00
* @ 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 { boolean } interactive Whether format makes content interactive or not .
* @ property { string | null } [ 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 .
2020-01-08 06:57:23 -05:00
* /
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 ;
}
2022-04-11 08:04:30 -04:00
if ( ( 0 , external _wp _data _namespaceObject . 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 ;
}
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
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, underscores, letters, or numbers.' ) ;
2018-12-14 06:02:53 -05:00
return ;
}
2018-12-16 23:52:00 -05:00
if ( settings . className === null ) {
2022-04-11 08:04:30 -04:00
const formatTypeForBareElement = ( 0 , external _wp _data _namespaceObject . select ) ( store ) . getFormatTypeForBareElement ( settings . tagName ) ;
2023-02-07 02:04:52 -05:00
if ( formatTypeForBareElement && formatTypeForBareElement . name !== 'core/unknown' ) {
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 {
2022-04-11 08:04:30 -04:00
const formatTypeForClassName = ( 0 , external _wp _data _namespaceObject . 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 ;
}
if ( typeof settings . title !== 'string' ) {
window . console . error ( 'Format titles must be strings.' ) ;
return ;
2018-12-16 23:52:00 -05:00
}
2022-04-11 08:04:30 -04:00
( 0 , external _wp _data _namespaceObject . dispatch ) ( store ) . addFormatTypes ( settings ) ;
2018-12-14 06:02:53 -05:00
return settings ;
}
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/remove-format.js
2018-12-13 23:41:57 -05:00
/ * *
* Internal dependencies
* /
2023-09-26 10:23:26 -04:00
2023-06-27 10:24:19 -04:00
/** @typedef {import('./types').RichTextValue} RichTextValue */
2020-10-13 09:10:30 -04:00
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
* /
2023-06-27 10:24:19 -04:00
function removeFormat ( value , formatType , startIndex = value . start , endIndex = value . end ) {
2021-05-19 11:09:27 -04:00
const {
formats ,
activeFormats
} = value ;
2023-09-26 10:23:26 -04:00
const newFormats = formats . slice ( ) ;
2018-12-13 23:41:57 -05:00
2023-09-26 10:23:26 -04:00
// If the selection is collapsed, expand start and end to the edges of the
// format.
2018-12-13 23:41:57 -05:00
if ( startIndex === endIndex ) {
2023-06-27 10:24:19 -04:00
const format = newFormats [ startIndex ] ? . find ( ( {
type
} ) => type === formatType ) ;
2019-03-21 08:48:00 -04:00
if ( format ) {
2023-06-27 10:24:19 -04:00
while ( newFormats [ startIndex ] ? . find ( newFormat => newFormat === format ) ) {
2019-03-21 08:48:00 -04:00
filterFormats ( newFormats , startIndex , formatType ) ;
startIndex -- ;
}
2018-12-13 23:41:57 -05:00
endIndex ++ ;
2023-06-27 10:24:19 -04:00
while ( newFormats [ endIndex ] ? . find ( newFormat => newFormat === 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 ) ;
}
}
}
2023-09-26 10:23:26 -04:00
return normaliseFormats ( {
... value ,
2019-05-16 14:08:00 -04:00
formats : newFormats ,
2023-06-27 10:24:19 -04:00
activeFormats : activeFormats ? . filter ( ( {
type
} ) => type !== formatType ) || [ ]
2021-05-19 11:09:27 -04:00
} ) ;
2018-12-13 23:41:57 -05:00
}
function filterFormats ( formats , index , formatType ) {
2023-06-27 10:24:19 -04:00
const newFormats = formats [ index ] . filter ( ( {
type
} ) => type !== formatType ) ;
2018-12-13 23:41:57 -05:00
if ( newFormats . length ) {
formats [ index ] = newFormats ;
} else {
delete formats [ index ] ;
}
}
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/insert.js
2018-12-17 22:14:52 -05:00
/ * *
* Internal dependencies
* /
2018-12-13 23:41:57 -05:00
2023-09-26 10:23:26 -04:00
2023-06-27 10:24:19 -04:00
/** @typedef {import('./types').RichTextValue} RichTextValue */
2020-10-13 09:10:30 -04:00
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
* /
2023-06-27 10:24:19 -04:00
function insert ( value , valueToInsert , startIndex = value . start , endIndex = 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
} ) ;
}
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/remove.js
2018-12-13 23:41:57 -05:00
/ * *
* Internal dependencies
* /
2023-09-26 10:23:26 -04:00
2023-06-27 10:24:19 -04:00
/** @typedef {import('./types').RichTextValue} RichTextValue */
2020-10-13 09:10:30 -04:00
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
* /
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
function remove _remove ( value , startIndex , endIndex ) {
2018-12-17 22:14:52 -05:00
return insert ( value , create ( ) , startIndex , endIndex ) ;
2018-12-13 23:41:57 -05:00
}
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/replace.js
2018-12-13 23:41:57 -05:00
/ * *
* Internal dependencies
* /
2023-09-26 10:23:26 -04:00
2023-06-27 10:24:19 -04:00
/** @typedef {import('./types').RichTextValue} RichTextValue */
2020-10-13 09:10:30 -04:00
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
* /
2023-06-27 10:24:19 -04:00
function replace _replace ( {
formats ,
replacements ,
text ,
start ,
end
} , pattern , replacement ) {
text = text . replace ( pattern , ( match , ... rest ) => {
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
} ) ;
}
2023-09-26 10:23:26 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/insert-object.js
2018-12-17 22:14:52 -05:00
/ * *
* Internal dependencies
* /
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
2020-10-13 09:10:30 -04:00
2023-06-27 10:24:19 -04:00
/** @typedef {import('./types').RichTextValue} RichTextValue */
/** @typedef {import('./types').RichTextFormat} RichTextFormat */
2020-10-13 09:10:30 -04:00
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 .
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
* @ param { number } [ startIndex ] Start index .
* @ param { number } [ endIndex ] End index .
*
* @ return { RichTextValue } A new value with the object inserted .
2018-12-14 06:02:53 -05:00
* /
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
function insertObject ( value , formatToInsert , startIndex , endIndex ) {
const valueToInsert = {
formats : [ , ] ,
replacements : [ formatToInsert ] ,
text : OBJECT _REPLACEMENT _CHARACTER
} ;
return insert ( value , valueToInsert , startIndex , endIndex ) ;
2021-07-13 19:58:30 -04:00
}
2023-09-26 10:23:26 -04:00
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/slice.js
/** @typedef {import('./types').RichTextValue} RichTextValue */
2019-03-07 04:09:59 -05:00
/ * *
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -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 ` .
2019-03-07 04:09:59 -05:00
*
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
* @ param { RichTextValue } value Value to modify .
* @ param { number } [ startIndex ] Start index .
* @ param { number } [ endIndex ] End index .
2021-07-13 19:58:30 -04:00
*
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
* @ return { RichTextValue } A new extracted value .
2019-03-07 04:09:59 -05:00
* /
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
function slice ( value , startIndex = value . start , endIndex = value . end ) {
const {
formats ,
replacements ,
text
} = value ;
if ( startIndex === undefined || endIndex === undefined ) {
2018-12-17 22:14:52 -05:00
return {
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
... value
2018-12-17 22:14:52 -05:00
} ;
}
return {
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
formats : formats . slice ( startIndex , endIndex ) ,
replacements : replacements . slice ( startIndex , endIndex ) ,
text : text . slice ( startIndex , endIndex )
2018-12-17 22:14:52 -05:00
} ;
}
2023-09-26 10:23:26 -04:00
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/split.js
2020-01-22 17:06:21 -05:00
/ * *
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
* Internal dependencies
2020-01-22 17:06:21 -05:00
* /
2018-12-17 22:14:52 -05:00
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
/** @typedef {import('./types').RichTextValue} RichTextValue */
/ * *
* 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 .
*
* @ param { RichTextValue } value
* @ param { number | string } [ string ] Start index , or string at which to split .
*
* @ return { Array < RichTextValue > | undefined } An array of new values .
* /
function split ( {
formats ,
replacements ,
text ,
start ,
end
} , string ) {
if ( typeof string !== 'string' ) {
return splitAtSelection ( ... arguments ) ;
}
let nextStart = 0 ;
return text . split ( string ) . map ( substring => {
const startIndex = nextStart ;
const value = {
formats : formats . slice ( startIndex , startIndex + substring . length ) ,
replacements : replacements . slice ( startIndex , startIndex + substring . length ) ,
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 ;
2023-09-26 10:23:26 -04:00
}
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
if ( end >= startIndex && end < nextStart ) {
value . end = end - startIndex ;
} else if ( start < nextStart && end > nextStart ) {
value . end = substring . length ;
2019-09-19 11:19:18 -04:00
}
2019-03-21 08:48:00 -04:00
}
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
return value ;
} ) ;
}
function splitAtSelection ( {
formats ,
replacements ,
text ,
start ,
end
} , startIndex = start , endIndex = end ) {
if ( start === undefined || end === undefined ) {
return ;
2018-12-17 22:14:52 -05:00
}
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
const before = {
formats : formats . slice ( 0 , startIndex ) ,
replacements : replacements . slice ( 0 , startIndex ) ,
text : text . slice ( 0 , startIndex )
} ;
const after = {
formats : formats . slice ( endIndex ) ,
replacements : replacements . slice ( endIndex ) ,
text : text . slice ( endIndex ) ,
start : 0 ,
end : 0
} ;
return [ before , after ] ;
2018-12-17 22:14:52 -05:00
}
2018-12-13 23:41:57 -05:00
2023-06-27 10:24:19 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/is-range-equal.js
/ * *
* 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 | null } a First range object to test .
* @ param { Range | null } b First range object to test .
*
* @ return { boolean } Whether the two ranges are equal .
* /
function isRangeEqual ( a , b ) {
return a === b || a && b && a . startContainer === b . startContainer && a . startOffset === b . startOffset && a . endContainer === b . endContainer && a . endOffset === b . endOffset ;
}
2022-04-11 08:04:30 -04: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
2023-06-27 10:24:19 -04:00
2023-09-26 10:23:26 -04:00
2023-06-27 10:24:19 -04:00
/** @typedef {import('./types').RichTextValue} RichTextValue */
2020-10-13 09:10:30 -04:00
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 ;
}
2023-09-26 10:23:26 -04:00
2018-12-13 23:41:57 -05:00
/ * *
* 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 ]
} ;
}
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
function to _dom _append ( element , child ) {
2023-07-11 02:59:09 -04:00
if ( child . html !== undefined ) {
return element . innerHTML += child . html ;
}
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 ) ;
}
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
function to _dom _appendText ( node , text ) {
2018-12-13 23:41:57 -05:00
node . appendData ( text ) ;
}
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
function to _dom _getLastChild ( {
2023-06-27 10:24:19 -04:00
lastChild
} ) {
2018-12-13 23:41:57 -05:00
return lastChild ;
}
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
function to _dom _getParent ( {
2023-06-27 10:24:19 -04:00
parentNode
} ) {
2018-12-13 23:41:57 -05:00
return parentNode ;
}
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
function to _dom _isText ( node ) {
2020-06-26 09:33:47 -04:00
return node . nodeType === node . TEXT _NODE ;
2018-12-13 23:41:57 -05:00
}
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
function to _dom _getText ( {
2023-06-27 10:24:19 -04:00
nodeValue
} ) {
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 ) ;
}
2023-06-27 10:24:19 -04:00
function toDom ( {
value ,
prepareEditableTree ,
isEditableTree = true ,
placeholder ,
doc = document
} ) {
2021-05-19 11:09:27 -04:00
let startPath = [ ] ;
let endPath = [ ] ;
2019-09-19 11:19:18 -04:00
if ( prepareEditableTree ) {
2023-09-26 10:23:26 -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
}
2023-09-26 10:23:26 -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 , '' ) ;
const tree = toTree ( {
value ,
createEmpty ,
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
append : to _dom _append ,
getLastChild : to _dom _getLastChild ,
getParent : to _dom _getParent ,
isText : to _dom _isText ,
getText : to _dom _getText ,
2018-12-17 22:14:52 -05:00
remove : to _dom _remove ,
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
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
}
} ;
}
2023-09-26 10:23:26 -04:00
2018-12-13 23:41:57 -05:00
/ * *
* Create an ` Element ` tree from a Rich Text value and applies the difference to
2023-09-26 10:23:26 -04:00
* the ` Element ` tree contained by ` current ` .
2018-12-13 23:41:57 -05:00
*
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 { 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
* /
2023-06-27 10:24:19 -04:00
function apply ( {
value ,
current ,
prepareEditableTree ,
_ _unstableDomOnly ,
placeholder
} ) {
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 ,
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-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 ) {
2023-09-26 10:23:26 -04:00
let ii = currentAttributes . length ;
2019-09-19 11:19:18 -04:00
2023-09-26 10:23:26 -04:00
// Reverse loop because `removeAttribute` on `currentChild`
// changes `currentAttributes`.
2019-09-19 11:19:18 -04:00
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 ] ) ;
}
}
2023-06-27 10:24:19 -04:00
function applySelection ( {
startPath ,
endPath
} , current ) {
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 ;
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
}
2023-09-26 10:23:26 -04:00
selection . addRange ( range ) ;
2018-12-18 22:16:48 -05:00
2023-09-26 10:23:26 -04:00
// This function is not intended to cause a shift in focus. Since the above
2020-03-02 18:21:15 -05:00
// selection manipulations may shift focus, ensure that focus is restored to
2020-03-23 19:40:19 -04:00
// its previous state.
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
}
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: external ["wp","a11y"]
2024-01-31 07:59:56 -05:00
const external _wp _a11y _namespaceObject = window [ "wp" ] [ "a11y" ] ;
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: external ["wp","i18n"]
2024-01-31 07:59:56 -05:00
const external _wp _i18n _namespaceObject = window [ "wp" ] [ "i18n" ] ;
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/toggle-format.js
2021-11-08 09:29:21 -05:00
/ * *
* WordPress dependencies
* /
2023-09-26 10:23:26 -04:00
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
2023-09-26 10:23:26 -04:00
/** @typedef {import('./types').RichTextValue} RichTextValue */
2023-06-27 10:24:19 -04:00
/** @typedef {import('./types').RichTextFormat} RichTextFormat */
2020-10-13 09:10:30 -04:00
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
2022-04-11 08:04:30 -04:00
( 0 , external _wp _a11y _namespaceObject . speak ) ( ( 0 , external _wp _i18n _namespaceObject . sprintf ) ( ( 0 , external _wp _i18n _namespaceObject . _ _ ) ( '%s removed.' ) , format . title ) , 'assertive' ) ;
2021-11-08 09:29:21 -05:00
}
2018-12-17 22:14:52 -05:00
return removeFormat ( value , format . type ) ;
2023-09-26 10:23:26 -04:00
}
// For screen readers, will announce if formatting control is enabled.
2021-11-08 09:29:21 -05:00
if ( format . title ) {
// translators: %s: title of the formatting control
2022-04-11 08:04:30 -04:00
( 0 , external _wp _a11y _namespaceObject . speak ) ( ( 0 , external _wp _i18n _namespaceObject . sprintf ) ( ( 0 , external _wp _i18n _namespaceObject . _ _ ) ( '%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 ) ;
}
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/unregister-format-type.js
2020-01-08 06:57:23 -05:00
/ * *
* WordPress dependencies
* /
2023-09-26 10:23:26 -04:00
2021-01-27 21:04:13 -05:00
/ * *
* Internal dependencies
* /
2023-06-27 10:24:19 -04:00
/** @typedef {import('./register-format-type').WPFormat} WPFormat */
2020-01-08 06:57:23 -05:00
/ * *
* Unregisters a format .
*
* @ param { string } name Format name .
*
2023-06-27 10:24:19 -04:00
* @ return { WPFormat | undefined } The previous format value , if it has
2020-10-13 09:10:30 -04:00
* been successfully unregistered ;
* otherwise ` undefined ` .
2020-01-08 06:57:23 -05:00
* /
function unregisterFormatType ( name ) {
2022-04-11 08:04:30 -04:00
const oldFormat = ( 0 , external _wp _data _namespaceObject . 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 ;
}
2022-04-11 08:04:30 -04:00
( 0 , external _wp _data _namespaceObject . dispatch ) ( store ) . removeFormatTypes ( name ) ;
2020-01-08 06:57:23 -05:00
return oldFormat ;
}
2022-09-20 11:43:29 -04:00
; // CONCATENATED MODULE: external ["wp","element"]
2024-01-31 07:59:56 -05:00
const external _wp _element _namespaceObject = window [ "wp" ] [ "element" ] ;
2022-09-20 11:43:29 -04:00
; // CONCATENATED MODULE: external ["wp","deprecated"]
2024-01-31 07:59:56 -05:00
const external _wp _deprecated _namespaceObject = window [ "wp" ] [ "deprecated" ] ;
2022-09-20 11:43:29 -04:00
var external _wp _deprecated _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( external _wp _deprecated _namespaceObject ) ;
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-anchor-ref.js
2020-01-08 06:57:23 -05:00
/ * *
2022-09-20 11:43:29 -04:00
* WordPress dependencies
2020-01-08 06:57:23 -05:00
* /
2020-10-13 09:10:30 -04:00
2023-09-26 10:23:26 -04:00
2020-01-08 06:57:23 -05:00
/ * *
2022-09-20 11:43:29 -04:00
* Internal dependencies
2020-01-08 06:57:23 -05:00
* /
2023-06-27 10:24:19 -04:00
/ * *
* @ template T
* @ typedef { import ( '@wordpress/element' ) . RefObject < T > } RefObject < T >
* /
/** @typedef {import('../register-format-type').WPFormat} WPFormat */
/** @typedef {import('../types').RichTextValue} RichTextValue */
2020-10-13 09:10:30 -04:00
2018-12-14 06:02:53 -05:00
/ * *
2022-09-20 11:43:29 -04: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 .
2018-12-14 06:02:53 -05:00
*
2022-09-20 11:43:29 -04:00
* @ 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 .
2023-06-27 10:24:19 -04:00
* @ param { WPFormat } $1 . settings The format type ' s settings .
2018-12-14 06:02:53 -05:00
*
2022-09-20 11:43:29 -04:00
* @ return { Element | Range } The active element or selection range .
2018-12-14 06:02:53 -05:00
* /
2023-06-27 10:24:19 -04:00
function useAnchorRef ( {
ref ,
value ,
settings = { }
} ) {
2022-09-20 11:43:29 -04:00
external _wp _deprecated _default ( ) ( '`useAnchorRef` hook' , {
since : '6.1' ,
alternative : '`useAnchor` hook'
} ) ;
2021-05-19 11:09:27 -04:00
const {
2022-09-20 11:43:29 -04:00
tagName ,
className ,
name
} = settings ;
const activeFormat = name ? getActiveFormat ( value , name ) : undefined ;
return ( 0 , external _wp _element _namespaceObject . useMemo ) ( ( ) => {
if ( ! ref . current ) return ;
const {
ownerDocument : {
defaultView
}
} = ref . current ;
const selection = defaultView . getSelection ( ) ;
if ( ! selection . rangeCount ) {
return ;
}
const range = selection . getRangeAt ( 0 ) ;
if ( ! activeFormat ) {
return range ;
}
2023-09-26 10:23:26 -04:00
let element = range . startContainer ;
2022-09-20 11:43:29 -04:00
2023-09-26 10:23:26 -04:00
// If the caret is right before the element, select the next element.
2022-09-20 11:43:29 -04: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 ] ) ;
2018-12-14 06:02:53 -05:00
}
2024-02-13 08:12:17 -05:00
; // CONCATENATED MODULE: external ["wp","compose"]
const external _wp _compose _namespaceObject = window [ "wp" ] [ "compose" ] ;
2022-09-20 11:43:29 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-anchor.js
/ * *
* WordPress dependencies
* /
2023-06-27 10:24:19 -04:00
2024-02-13 08:12:17 -05:00
2023-09-26 10:23:26 -04:00
/** @typedef {import('../register-format-type').WPFormat} WPFormat */
2023-06-27 10:24:19 -04:00
/** @typedef {import('../types').RichTextValue} RichTextValue */
2019-01-29 13:23:55 -05:00
/ * *
2023-06-27 10:24:19 -04:00
* Given a range and a format tag name and class name , returns the closest
* format element .
*
* @ param { Range } range The Range to check .
* @ param { HTMLElement } editableContentElement The editable wrapper .
* @ param { string } tagName The tag name of the format element .
* @ param { string } className The class name of the format element .
*
* @ return { HTMLElement | undefined } The format element , if found .
2019-01-29 13:23:55 -05:00
* /
2023-06-27 10:24:19 -04:00
function getFormatElement ( range , editableContentElement , tagName , className ) {
2023-09-26 10:23:26 -04:00
let element = range . startContainer ;
// Even if the active format is defined, the actualy DOM range's start
// container may be outside of the format's DOM element:
// `a‸<strong>b</strong>` (DOM) while visually it's `a<strong>‸b</strong>`.
// So at a given selection index, start with the deepest format DOM element.
if ( element . nodeType === element . TEXT _NODE && range . startOffset === element . length && element . nextSibling ) {
element = element . nextSibling ;
while ( element . firstChild ) {
element = element . firstChild ;
}
}
2023-06-27 10:24:19 -04:00
if ( element . nodeType !== element . ELEMENT _NODE ) {
element = element . parentElement ;
}
if ( ! element ) return ;
if ( element === editableContentElement ) return ;
if ( ! editableContentElement . contains ( element ) ) return ;
2023-09-26 10:23:26 -04:00
const selector = tagName + ( className ? '.' + className : '' ) ;
// .closest( selector ), but with a boundary. Check if the element matches
2023-06-27 10:24:19 -04:00
// the selector. If it doesn't match, try the parent element if it's not the
// editable wrapper. We don't want to try to match ancestors of the editable
// wrapper, which is what .closest( selector ) would do. When the element is
// the editable wrapper (which is most likely the case because most text is
// unformatted), this never runs.
while ( element !== editableContentElement ) {
if ( element . matches ( selector ) ) {
return element ;
}
element = element . parentElement ;
}
}
2023-09-26 10:23:26 -04:00
2022-09-20 11:43:29 -04:00
/ * *
* @ typedef { Object } VirtualAnchorElement
2023-06-27 10:24:19 -04:00
* @ property { ( ) => DOMRect } getBoundingClientRect A function returning a DOMRect
2023-09-26 10:23:26 -04:00
* @ property { HTMLElement } contextElement The actual DOM element
2022-09-20 11:43:29 -04:00
* /
2020-10-13 09:10:30 -04:00
2023-06-27 10:24:19 -04:00
/ * *
* Creates a virtual anchor element for a range .
*
* @ param { Range } range The range to create a virtual anchor element for .
* @ param { HTMLElement } editableContentElement The editable wrapper .
*
* @ return { VirtualAnchorElement } The virtual anchor element .
* /
function createVirtualAnchorElement ( range , editableContentElement ) {
return {
2023-09-26 10:23:26 -04:00
contextElement : editableContentElement ,
2023-06-27 10:24:19 -04:00
getBoundingClientRect ( ) {
return editableContentElement . contains ( range . startContainer ) ? range . getBoundingClientRect ( ) : editableContentElement . getBoundingClientRect ( ) ;
}
} ;
}
2023-09-26 10:23:26 -04:00
2023-06-27 10:24:19 -04:00
/ * *
* Get the anchor : a format element if there is a matching one based on the
* tagName and className or a range otherwise .
*
* @ param { HTMLElement } editableContentElement The editable wrapper .
* @ param { string } tagName The tag name of the format
* element .
* @ param { string } className The class name of the format
* element .
*
* @ return { HTMLElement | VirtualAnchorElement | undefined } The anchor .
* /
function getAnchor ( editableContentElement , tagName , className ) {
if ( ! editableContentElement ) return ;
const {
ownerDocument
} = editableContentElement ;
const {
defaultView
} = ownerDocument ;
const selection = defaultView . getSelection ( ) ;
if ( ! selection ) return ;
if ( ! selection . rangeCount ) return ;
const range = selection . getRangeAt ( 0 ) ;
if ( ! range || ! range . startContainer ) return ;
const formatElement = getFormatElement ( range , editableContentElement , tagName , className ) ;
if ( formatElement ) return formatElement ;
return createVirtualAnchorElement ( range , editableContentElement ) ;
}
2023-09-26 10:23:26 -04:00
2019-01-29 13:23:55 -05:00
/ * *
2022-09-20 11:43:29 -04:00
* This hook , to be used in a format type ' s Edit component , returns the active
* element that is formatted , or a virtual element for 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 via the ` anchor ` prop .
2019-01-29 13:23:55 -05:00
*
2023-06-27 10:24:19 -04:00
* @ param { Object } $1 Named parameters .
* @ param { HTMLElement | null } $1 . editableContentElement The element containing
* the editable content .
* @ param { WPFormat = } $1 . settings The format type ' s settings .
2022-09-20 11:43:29 -04:00
* @ return { Element | VirtualAnchorElement | undefined | null } The active element or selection range .
2019-01-29 13:23:55 -05:00
* /
2023-06-27 10:24:19 -04:00
function useAnchor ( {
editableContentElement ,
settings = { }
} ) {
2021-05-19 11:09:27 -04:00
const {
tagName ,
2024-02-13 08:12:17 -05:00
className ,
isActive
2021-05-19 11:09:27 -04:00
} = settings ;
2023-06-27 10:24:19 -04:00
const [ anchor , setAnchor ] = ( 0 , external _wp _element _namespaceObject . useState ) ( ( ) => getAnchor ( editableContentElement , tagName , className ) ) ;
2024-02-13 08:12:17 -05:00
const wasActive = ( 0 , external _wp _compose _namespaceObject . usePrevious ) ( isActive ) ;
2023-06-27 10:24:19 -04:00
( 0 , external _wp _element _namespaceObject . useLayoutEffect ) ( ( ) => {
2022-09-20 11:43:29 -04:00
if ( ! editableContentElement ) return ;
2024-03-12 10:30:24 -04:00
function callback ( ) {
setAnchor ( getAnchor ( editableContentElement , tagName , className ) ) ;
}
function attach ( ) {
ownerDocument . addEventListener ( 'selectionchange' , callback ) ;
}
function detach ( ) {
ownerDocument . removeEventListener ( 'selectionchange' , callback ) ;
}
2021-05-19 11:09:27 -04:00
const {
2023-06-27 10:24:19 -04:00
ownerDocument
2022-09-20 11:43:29 -04:00
} = editableContentElement ;
2024-02-13 08:12:17 -05:00
if ( editableContentElement === ownerDocument . activeElement ||
// When a link is created, we need to attach the popover to the newly created anchor.
! wasActive && isActive ||
// Sometimes we're _removing_ an active anchor, such as the inline color popover.
// When we add the color, it switches from a virtual anchor to a `<mark>` element.
// When we _remove_ the color, it switches from a `<mark>` element to a virtual anchor.
wasActive && ! isActive ) {
2023-06-27 10:24:19 -04:00
setAnchor ( getAnchor ( editableContentElement , tagName , className ) ) ;
2024-03-12 10:30:24 -04:00
attach ( ) ;
2021-01-27 21:04:13 -05:00
}
2024-03-12 10:30:24 -04:00
editableContentElement . addEventListener ( 'focusin' , attach ) ;
editableContentElement . addEventListener ( 'focusout' , detach ) ;
return ( ) => {
detach ( ) ;
editableContentElement . removeEventListener ( 'focusin' , attach ) ;
editableContentElement . removeEventListener ( 'focusout' , detach ) ;
} ;
2024-02-13 08:12:17 -05:00
} , [ editableContentElement , tagName , className , isActive , wasActive ] ) ;
2023-06-27 10:24:19 -04:00
return anchor ;
2021-01-27 21:04:13 -05:00
}
2022-04-11 08:04:30 -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
* /
2023-09-26 10:23:26 -04:00
Block Editor: Update packages to bring a selection of bugfixes in.
Props iseulde, kjellr, aduth, 0mirka00, mcsf, nosolosw, gziolo, jasmussen, talldanwp, notnownikki, swissspidy, jorgefilipecosta, noisysocks.
See https://github.com/WordPress/gutenberg/pull/14796.
Fixes #46801.
Built from https://develop.svn.wordpress.org/trunk@45138
git-svn-id: http://core.svn.wordpress.org/trunk@44947 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-04-08 02:37:57 -04:00
/ * *
2021-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' ;
2023-09-26 10:23:26 -04:00
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 ( ) {
2022-04-11 08:04:30 -04:00
return ( 0 , external _wp _element _namespaceObject . useCallback ) ( element => {
2021-05-21 06:14:23 -04:00
if ( ! element ) return ;
element . style . whiteSpace = whiteSpace ;
element . style . minWidth = minWidth ;
} , [ ] ) ;
2020-01-22 17:06:21 -05:00
}
2022-04-11 08:04:30 -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
* /
2023-09-26 10:23:26 -04:00
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 .
* /
2023-06-27 10:24:19 -04:00
function useBoundaryStyle ( {
record
} ) {
2022-04-11 08:04:30 -04:00
const ref = ( 0 , external _wp _element _namespaceObject . useRef ) ( ) ;
2021-05-21 06:14:23 -04:00
const {
2023-06-27 10:24:19 -04:00
activeFormats = [ ] ,
replacements ,
start
2021-05-21 06:14:23 -04:00
} = record . current ;
2023-06-27 10:24:19 -04:00
const activeReplacement = replacements [ start ] ;
2022-04-11 08:04:30 -04:00
( 0 , external _wp _element _namespaceObject . 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.
2023-06-27 10:24:19 -04:00
if ( ( ! activeFormats || ! activeFormats . length ) && ! activeReplacement ) {
2020-01-22 17:06:21 -05:00
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 ;
}
2023-06-27 10:24:19 -04:00
} , [ activeFormats , activeReplacement ] ) ;
2021-05-21 06:14:23 -04:00
return ref ;
2020-01-22 17:06:21 -05:00
}
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-copy-handler.js
2021-04-15 11:19:43 -04:00
/ * *
* WordPress dependencies
* /
2021-05-19 11:09:27 -04:00
2023-09-26 10:23:26 -04:00
2021-04-15 11:19:43 -04:00
/ * *
* Internal dependencies
* /
2021-05-19 11:09:27 -04:00
function useCopyHandler ( props ) {
2022-04-11 08:04:30 -04:00
const propsRef = ( 0 , external _wp _element _namespaceObject . useRef ) ( props ) ;
2021-05-19 11:09:27 -04:00
propsRef . current = props ;
2022-04-11 08:04:30 -04:00
return ( 0 , external _wp _compose _namespaceObject . useRefEffect ) ( element => {
2021-04-15 11:19:43 -04:00
function onCopy ( event ) {
2021-05-19 11:09:27 -04:00
const {
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
record
2021-05-19 11:09:27 -04:00
} = propsRef . current ;
2023-06-27 10:24:19 -04:00
const {
ownerDocument
} = element ;
if ( isCollapsed ( record . current ) || ! element . contains ( ownerDocument . activeElement ) ) {
2021-04-15 11:19:43 -04:00
return ;
}
2021-05-19 11:09:27 -04:00
const selectedRecord = slice ( record . current ) ;
const plainText = getTextContent ( selectedRecord ) ;
const html = toHTMLString ( {
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
value : selectedRecord
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' ) ;
event . preventDefault ( ) ;
2023-06-27 10:24:19 -04:00
if ( event . type === 'cut' ) {
ownerDocument . execCommand ( 'delete' ) ;
}
2021-04-15 11:19:43 -04:00
}
element . addEventListener ( 'copy' , onCopy ) ;
2023-06-27 10:24:19 -04:00
element . addEventListener ( 'cut' , onCopy ) ;
2021-05-19 11:09:27 -04:00
return ( ) => {
2021-04-15 11:19:43 -04:00
element . removeEventListener ( 'copy' , onCopy ) ;
2023-06-27 10:24:19 -04:00
element . removeEventListener ( 'cut' , onCopy ) ;
2021-04-15 11:19:43 -04:00
} ;
2021-05-19 11:09:27 -04:00
} , [ ] ) ;
2021-04-15 11:19:43 -04:00
}
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: external ["wp","keycodes"]
2024-01-31 07:59:56 -05:00
const external _wp _keycodes _namespaceObject = window [ "wp" ] [ "keycodes" ] ;
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-format-boundaries.js
2021-05-19 11:09:27 -04:00
/ * *
* WordPress dependencies
* /
2023-09-26 10:23:26 -04:00
2021-05-19 11:09:27 -04:00
/ * *
* Internal dependencies
* /
const EMPTY _ACTIVE _FORMATS = [ ] ;
function useFormatBoundaries ( props ) {
2022-04-11 08:04:30 -04:00
const [ , forceRender ] = ( 0 , external _wp _element _namespaceObject . useReducer ) ( ( ) => ( { } ) ) ;
const propsRef = ( 0 , external _wp _element _namespaceObject . useRef ) ( props ) ;
2021-05-19 11:09:27 -04:00
propsRef . current = props ;
2022-04-11 08:04:30 -04:00
return ( 0 , external _wp _compose _namespaceObject . useRefEffect ) ( element => {
2021-05-19 11:09:27 -04:00
function onKeyDown ( event ) {
const {
keyCode ,
shiftKey ,
altKey ,
metaKey ,
ctrlKey
} = event ;
2023-09-26 10:23:26 -04:00
if (
// Only override left and right keys without modifiers pressed.
2022-04-11 08:04:30 -04:00
shiftKey || altKey || metaKey || ctrlKey || keyCode !== external _wp _keycodes _namespaceObject . LEFT && keyCode !== external _wp _keycodes _namespaceObject . RIGHT ) {
2021-05-19 11:09:27 -04:00
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
2023-09-26 10:23:26 -04:00
} = ownerDocument ;
// To do: ideally, we should look at visual position instead.
2021-05-19 11:09:27 -04:00
const {
direction
} = defaultView . getComputedStyle ( element ) ;
2022-04-11 08:04:30 -04:00
const reverseKey = direction === 'rtl' ? external _wp _keycodes _namespaceObject . RIGHT : external _wp _keycodes _namespaceObject . LEFT ;
2023-09-26 10:23:26 -04:00
const isReverse = event . keyCode === reverseKey ;
// If the selection is collapsed and at the very start, do nothing if
2021-05-19 11:09:27 -04:00
// 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 ;
}
if ( end === text . length && ! isReverse ) {
return ;
}
2023-09-26 10:23:26 -04:00
}
// If the selection is not collapsed, let the browser handle collapsing
2021-05-19 11:09:27 -04:00
// the selection for now. Later we could expand this logic to set
// boundary positions if needed.
if ( ! collapsed ) {
return ;
}
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-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 ) ;
2023-09-26 10:23:26 -04:00
const newValue = {
... record . current ,
2021-05-19 11:09:27 -04:00
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 ) ;
} ;
} , [ ] ) ;
}
2022-04-11 08:04:30 -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 ( ) {
2022-04-11 08:04:30 -04:00
return ( 0 , external _wp _compose _namespaceObject . 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
2023-09-26 10:23:26 -04:00
} = event ;
2021-05-19 11:09:27 -04:00
2023-09-26 10:23:26 -04:00
// If the child element has no text content, it must be an object.
2023-06-27 10:24:19 -04:00
if ( target === element || target . textContent && target . isContentEditable ) {
2021-05-19 11:09:27 -04:00
return ;
}
2021-05-21 06:14:23 -04:00
const {
ownerDocument
} = target ;
const {
defaultView
} = ownerDocument ;
2023-09-26 10:23:26 -04:00
const selection = defaultView . getSelection ( ) ;
2023-06-27 10:24:19 -04:00
2023-09-26 10:23:26 -04:00
// If it's already selected, do nothing and let default behavior
// happen. This means it's "click-through".
2023-06-27 10:24:19 -04:00
if ( selection . containsNode ( target ) ) return ;
2023-09-26 10:23:26 -04:00
const range = ownerDocument . createRange ( ) ;
// If the target is within a non editable element, select the non
2023-07-11 02:59:09 -04:00
// editable element.
const nodeToSelect = target . isContentEditable ? target : target . closest ( '[contenteditable]' ) ;
range . selectNode ( nodeToSelect ) ;
2021-05-21 06:14:23 -04:00
selection . removeAllRanges ( ) ;
selection . addRange ( range ) ;
2023-06-27 10:24:19 -04:00
event . preventDefault ( ) ;
}
function onFocusIn ( event ) {
// When there is incoming focus from a link, select the object.
if ( event . relatedTarget && ! element . contains ( event . relatedTarget ) && event . relatedTarget . tagName === 'A' ) {
onClick ( event ) ;
}
2021-05-19 11:09:27 -04:00
}
2021-05-21 06:14:23 -04:00
element . addEventListener ( 'click' , onClick ) ;
2023-06-27 10:24:19 -04:00
element . addEventListener ( 'focusin' , onFocusIn ) ;
2021-05-19 11:09:27 -04:00
return ( ) => {
2021-05-21 06:14:23 -04:00
element . removeEventListener ( 'click' , onClick ) ;
2023-06-27 10:24:19 -04:00
element . removeEventListener ( 'focusin' , onFocusIn ) ;
2021-05-19 11:09:27 -04:00
} ;
} , [ ] ) ;
}
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/update-formats.js
2021-05-21 06:14:23 -04:00
/ * *
* Internal dependencies
* /
2018-12-14 06:02:53 -05:00
2023-09-26 10:23:26 -04:00
2023-06-27 10:24:19 -04:00
/** @typedef {import('./types').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
* /
2023-06-27 10:24:19 -04:00
function updateFormats ( {
value ,
start ,
end ,
formats
} ) {
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 ] || [ ] ;
2023-09-26 10:23:26 -04:00
const formatsAfter = value . formats [ max ] || [ ] ;
2021-05-21 06:14:23 -04:00
2023-09-26 10:23:26 -04:00
// First, fix the references. If any format right before or after are
// equal, the replacement format should use the same reference.
2021-05-21 06:14:23 -04:00
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 ;
}
2022-04-11 08:04:30 -04:00
; // 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
2023-09-26 10:23:26 -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 = [ ] ;
2022-09-20 11:43:29 -04:00
const PLACEHOLDER _ATTR _NAME = 'data-rich-text-placeholder' ;
2023-09-26 10:23:26 -04:00
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 ] ;
2022-09-20 11:43:29 -04:00
if ( ! targetNode || targetNode . nodeType !== targetNode . ELEMENT _NODE || ! targetNode . hasAttribute ( PLACEHOLDER _ATTR _NAME ) ) {
2019-10-15 12:17:12 -04:00
return ;
}
selection . collapseToStart ( ) ;
}
2021-05-21 06:14:23 -04:00
function useInputAndSelection ( props ) {
2022-04-11 08:04:30 -04:00
const propsRef = ( 0 , external _wp _element _namespaceObject . useRef ) ( props ) ;
2021-05-21 06:14:23 -04:00
propsRef . current = props ;
2022-04-11 08:04:30 -04:00
return ( 0 , external _wp _compose _namespaceObject . useRefEffect ) ( element => {
2021-05-21 06:14:23 -04:00
const {
ownerDocument
} = element ;
const {
defaultView
} = ownerDocument ;
let isComposing = false ;
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 ;
}
let inputType ;
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
2023-09-26 10:23:26 -04:00
} = propsRef . current ;
// The browser formatted something or tried to insert HTML.
2021-05-21 06:14:23 -04:00
// 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 ;
}
const currentValue = createRecord ( ) ;
const {
start ,
activeFormats : oldActiveFormats = [ ]
2023-09-26 10:23:26 -04:00
} = record . current ;
2020-06-26 09:33:47 -04:00
2023-09-26 10:23:26 -04:00
// Update the formats between the last and new caret position.
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
}
2023-09-26 10:23:26 -04:00
2021-05-21 06:14:23 -04:00
/ * *
2023-06-27 10:24:19 -04:00
* Syncs the selection to local state . A callback for the
* ` selectionchange ` event .
2021-05-21 06:14:23 -04:00
* /
2023-06-27 10:24:19 -04:00
function handleSelectionChange ( ) {
2021-05-21 06:14:23 -04:00
const {
record ,
applyRecord ,
createRecord ,
onSelectionChange
2023-09-26 10:23:26 -04:00
} = propsRef . current ;
// Check if the implementor disabled editing. `contentEditable`
2022-05-02 06:39:04 -04:00
// does disable input, but not text selection, so we must ignore
// selection changes.
if ( element . contentEditable !== 'true' ) {
return ;
2023-09-26 10:23:26 -04:00
}
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
// Ensure the active element is the rich text element.
2022-04-12 11:12:47 -04:00
if ( ownerDocument . activeElement !== element ) {
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
// If it is not, we can stop listening for selection changes.
// We resume listening when the element is focused.
ownerDocument . removeEventListener ( 'selectionchange' , handleSelectionChange ) ;
2021-05-21 06:14:23 -04:00
return ;
2023-09-26 10:23:26 -04:00
}
2020-06-26 09:33:47 -04:00
2023-09-26 10:23:26 -04:00
// In case of a keyboard event, ignore selection changes during
// composition.
2021-05-21 06:14:23 -04:00
if ( isComposing ) {
2019-09-19 11:19:18 -04:00
return ;
}
2021-05-21 06:14:23 -04:00
const {
start ,
end ,
text
} = createRecord ( ) ;
2023-09-26 10:23:26 -04:00
const oldRecord = record . current ;
2020-01-08 06:57:23 -05:00
2023-09-26 10:23:26 -04:00
// Fallback mechanism for IE11, which doesn't support the input event.
// Any input results in a selection change.
2021-05-21 06:14:23 -04:00
if ( text !== oldRecord . text ) {
onInput ( ) ;
return ;
}
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 ) ;
}
return ;
2019-09-19 11:19:18 -04:00
}
2023-09-26 10:23:26 -04:00
const newValue = {
... oldRecord ,
2021-05-21 06:14:23 -04:00
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
} ;
2023-09-26 10:23:26 -04:00
const newActiveFormats = getActiveFormats ( newValue , use _input _and _selection _EMPTY _ACTIVE _FORMATS ) ;
2020-06-26 09:33:47 -04:00
2023-09-26 10:23:26 -04:00
// Update the value with the new active formats.
newValue . activeFormats = newActiveFormats ;
2020-01-22 17:06:21 -05:00
2023-09-26 10:23:26 -04:00
// It is important that the internal value is updated first,
// otherwise the value will be wrong on render!
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
}
2021-05-21 06:14:23 -04:00
function onCompositionStart ( ) {
2023-09-26 10:23:26 -04:00
isComposing = true ;
// Do not update the selection when characters are being composed as
2022-05-02 06:39:04 -04:00
// this rerenders the component and might destroy internal browser
2021-05-21 06:14:23 -04:00
// editing state.
2023-09-26 10:23:26 -04:00
ownerDocument . removeEventListener ( 'selectionchange' , handleSelectionChange ) ;
// Remove the placeholder. Since the rich text value doesn't update
2022-09-20 11:43:29 -04:00
// during composition, the placeholder doesn't get removed. There's
// no need to re-add it, when the value is updated on compositionend
// it will be re-added when the value is empty.
2023-06-27 10:24:19 -04:00
element . querySelector ( ` [ ${ PLACEHOLDER _ATTR _NAME } ] ` ) ? . remove ( ) ;
2020-06-26 09:33:47 -04:00
}
2021-05-21 06:14:23 -04:00
function onCompositionEnd ( ) {
2023-09-26 10:23:26 -04:00
isComposing = false ;
// Ensure the value is up-to-date for browsers that don't emit a final
2021-05-21 06:14:23 -04:00
// input event after composition.
onInput ( {
inputType : 'insertText'
2023-09-26 10:23:26 -04:00
} ) ;
// Tracking selection changes can be resumed.
2021-05-21 06:14:23 -04:00
ownerDocument . addEventListener ( 'selectionchange' , handleSelectionChange ) ;
2020-06-26 09:33:47 -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
2023-09-26 10:23:26 -04:00
} = propsRef . current ;
2022-04-12 11:12:47 -04:00
2023-09-26 10:23:26 -04:00
// When the whole editor is editable, let writing flow handle
// selection.
2022-04-12 11:12:47 -04:00
if ( element . parentElement . closest ( '[contenteditable="true"]' ) ) {
return ;
}
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 ;
2023-09-26 10:23:26 -04:00
record . current = {
... record . current ,
2021-05-21 06:14:23 -04:00
start : index ,
end : index ,
activeFormats : use _input _and _selection _EMPTY _ACTIVE _FORMATS
} ;
2020-06-26 09:33:47 -04:00
} else {
2024-02-09 13:22:22 -05:00
applyRecord ( record . current , {
domOnly : true
} ) ;
2023-06-27 10:24:19 -04:00
}
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
onSelectionChange ( record . current . start , record . current . end ) ;
ownerDocument . addEventListener ( 'selectionchange' , handleSelectionChange ) ;
2020-06-26 09:33:47 -04:00
}
2021-05-21 06:14:23 -04:00
element . addEventListener ( 'input' , onInput ) ;
element . addEventListener ( 'compositionstart' , onCompositionStart ) ;
element . addEventListener ( 'compositionend' , onCompositionEnd ) ;
2023-06-27 10:24:19 -04:00
element . addEventListener ( 'focus' , onFocus ) ;
2021-05-21 06:14:23 -04:00
return ( ) => {
element . removeEventListener ( 'input' , onInput ) ;
element . removeEventListener ( 'compositionstart' , onCompositionStart ) ;
element . removeEventListener ( 'compositionend' , onCompositionEnd ) ;
element . removeEventListener ( 'focus' , onFocus ) ;
2023-06-27 10:24:19 -04:00
} ;
} , [ ] ) ;
}
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-selection-change-compat.js
/ * *
* WordPress dependencies
* /
2023-09-26 10:23:26 -04:00
2023-06-27 10:24:19 -04:00
/ * *
* Internal dependencies
* /
/ * *
* Sometimes some browsers are not firing a ` selectionchange ` event when
* changing the selection by mouse or keyboard . This hook makes sure that , if we
* detect no ` selectionchange ` or ` input ` event between the up and down events ,
* we fire a ` selectionchange ` event .
*
* @ return { import ( '@wordpress/compose' ) . RefEffect } A ref effect attaching the
* listeners .
* /
function useSelectionChangeCompat ( ) {
return ( 0 , external _wp _compose _namespaceObject . useRefEffect ) ( element => {
const {
ownerDocument
} = element ;
const {
defaultView
} = ownerDocument ;
2023-07-28 03:40:16 -04:00
const selection = defaultView ? . getSelection ( ) ;
2023-06-27 10:24:19 -04:00
let range ;
function getRange ( ) {
return selection . rangeCount ? selection . getRangeAt ( 0 ) : null ;
}
function onDown ( event ) {
const type = event . type === 'keydown' ? 'keyup' : 'pointerup' ;
function onCancel ( ) {
ownerDocument . removeEventListener ( type , onUp ) ;
ownerDocument . removeEventListener ( 'selectionchange' , onCancel ) ;
ownerDocument . removeEventListener ( 'input' , onCancel ) ;
}
function onUp ( ) {
onCancel ( ) ;
if ( isRangeEqual ( range , getRange ( ) ) ) return ;
ownerDocument . dispatchEvent ( new Event ( 'selectionchange' ) ) ;
}
ownerDocument . addEventListener ( type , onUp ) ;
ownerDocument . addEventListener ( 'selectionchange' , onCancel ) ;
ownerDocument . addEventListener ( 'input' , onCancel ) ;
range = getRange ( ) ;
}
element . addEventListener ( 'pointerdown' , onDown ) ;
element . addEventListener ( 'keydown' , onDown ) ;
return ( ) => {
element . removeEventListener ( 'pointerdown' , onDown ) ;
element . removeEventListener ( 'keydown' , onDown ) ;
2021-05-21 06:14:23 -04:00
} ;
} , [ ] ) ;
}
2019-09-19 11:19:18 -04:00
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-delete.js
2021-05-21 06:14:23 -04:00
/ * *
* 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
2023-09-26 10:23:26 -04:00
2021-05-21 06:14:23 -04:00
/ * *
* Internal dependencies
* /
2020-06-26 09:33:47 -04:00
2021-05-21 06:14:23 -04:00
function useDelete ( props ) {
2022-04-11 08:04:30 -04:00
const propsRef = ( 0 , external _wp _element _namespaceObject . useRef ) ( props ) ;
2021-05-21 06:14:23 -04:00
propsRef . current = props ;
2022-04-11 08:04:30 -04:00
return ( 0 , external _wp _compose _namespaceObject . useRefEffect ) ( element => {
2021-05-21 06:14:23 -04:00
function onKeyDown ( event ) {
const {
keyCode
} = event ;
const {
createRecord ,
2023-09-26 10:23:26 -04:00
handleChange
2021-05-21 06:14:23 -04:00
} = propsRef . current ;
if ( event . defaultPrevented ) {
return ;
}
2022-04-11 08:04:30 -04:00
if ( keyCode !== external _wp _keycodes _namespaceObject . DELETE && keyCode !== external _wp _keycodes _namespaceObject . BACKSPACE ) {
2021-05-21 06:14:23 -04:00
return ;
}
const currentValue = createRecord ( ) ;
const {
start ,
end ,
text
} = currentValue ;
2020-01-08 06:57:23 -05:00
2023-09-26 10:23:26 -04:00
// Always handle full content deletion ourselves.
2021-05-21 06:14:23 -04:00
if ( start === 0 && end !== 0 && end === text . length ) {
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
handleChange ( remove _remove ( currentValue ) ) ;
2021-05-21 06:14:23 -04:00
event . preventDefault ( ) ;
}
2020-06-26 09:33:47 -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
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/index.js
2021-05-21 06:14:23 -04:00
/ * *
* WordPress dependencies
* /
2019-09-19 11:19:18 -04:00
2021-11-08 09:29:21 -05:00
2023-09-26 10:23:26 -04: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
2023-06-27 10:24:19 -04:00
function useRichText ( {
value = '' ,
selectionStart ,
selectionEnd ,
placeholder ,
onSelectionChange ,
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
preserveWhiteSpace ,
2023-06-27 10:24:19 -04:00
onChange ,
_ _unstableDisableFormats : disableFormats ,
_ _unstableIsSelected : isSelected ,
_ _unstableDependencies = [ ] ,
_ _unstableAfterParse ,
_ _unstableBeforeSerialize ,
_ _unstableAddInvisibleFormats
} ) {
2022-04-11 08:04:30 -04:00
const registry = ( 0 , external _wp _data _namespaceObject . useRegistry ) ( ) ;
const [ , forceRender ] = ( 0 , external _wp _element _namespaceObject . useReducer ) ( ( ) => ( { } ) ) ;
const ref = ( 0 , external _wp _element _namespaceObject . useRef ) ( ) ;
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 ,
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
_ _unstableIsEditableTree : true
2021-05-21 06:14:23 -04:00
} ) ;
2020-06-26 09:33:47 -04:00
}
2023-06-27 10:24:19 -04:00
function applyRecord ( newRecord , {
domOnly
} = { } ) {
2021-05-21 06:14:23 -04:00
apply ( {
value : newRecord ,
current : ref . current ,
prepareEditableTree : _ _unstableAddInvisibleFormats ,
_ _unstableDomOnly : domOnly ,
placeholder
} ) ;
2023-09-26 10:23:26 -04:00
}
2019-09-19 11:19:18 -04:00
2023-09-26 10:23:26 -04:00
// Internal values are updated synchronously, unlike props and state.
2022-04-11 08:04:30 -04:00
const _value = ( 0 , external _wp _element _namespaceObject . useRef ) ( value ) ;
const record = ( 0 , external _wp _element _namespaceObject . useRef ) ( ) ;
2021-05-21 06:14:23 -04:00
function setRecordFromProps ( ) {
_value . current = value ;
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
record . current = value ;
if ( ! ( value instanceof RichTextData ) ) {
record . current = value ? RichTextData . fromHTMLString ( value , {
preserveWhiteSpace
} ) : RichTextData . empty ( ) ;
}
// To do: make rich text internally work with RichTextData.
record . current = {
text : record . current . text ,
formats : record . current . formats ,
replacements : record . current . replacements
} ;
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 ;
}
2022-04-11 08:04:30 -04:00
const hadSelectionUpdate = ( 0 , external _wp _element _namespaceObject . useRef ) ( false ) ;
2021-05-21 06:14:23 -04:00
if ( ! record . current ) {
2023-06-27 10:24:19 -04:00
hadSelectionUpdate . current = isSelected ;
2023-09-26 10:23:26 -04:00
setRecordFromProps ( ) ;
2021-05-21 06:14:23 -04:00
} else if ( selectionStart !== record . current . start || selectionEnd !== record . current . end ) {
hadSelectionUpdate . current = isSelected ;
2023-09-26 10:23:26 -04:00
record . current = {
... record . current ,
2021-05-21 06:14:23 -04:00
start : selectionStart ,
2023-09-26 10:23:26 -04:00
end : selectionEnd ,
activeFormats : undefined
2021-05-19 11:09:27 -04:00
} ;
2020-06-26 09:33:47 -04:00
}
2023-09-26 10:23:26 -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 {
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
const newFormats = _ _unstableBeforeSerialize ? _ _unstableBeforeSerialize ( newRecord ) : newRecord . formats ;
newRecord = {
... newRecord ,
formats : newFormats
} ;
if ( typeof value === 'string' ) {
_value . current = toHTMLString ( {
2024-03-12 10:30:24 -04:00
value : newRecord ,
preserveWhiteSpace
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
} ) ;
} else {
_value . current = new RichTextData ( newRecord ) ;
}
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
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
} = record . current ;
2023-09-26 10:23:26 -04:00
// 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
function applyFromProps ( ) {
2021-05-21 06:14:23 -04:00
setRecordFromProps ( ) ;
2020-06-26 09:33:47 -04:00
applyRecord ( record . current ) ;
}
2023-09-26 10:23:26 -04:00
const didMount = ( 0 , external _wp _element _namespaceObject . useRef ) ( false ) ;
2020-06-26 09:33:47 -04:00
2023-09-26 10:23:26 -04:00
// Value updates must happen synchonously to avoid overwriting newer values.
2022-04-11 08:04:30 -04:00
( 0 , external _wp _element _namespaceObject . useLayoutEffect ) ( ( ) => {
2020-06-26 09:33:47 -04:00
if ( didMount . current && value !== _value . current ) {
applyFromProps ( ) ;
2022-04-12 11:12:47 -04:00
forceRender ( ) ;
2019-09-19 11:19:18 -04:00
}
2023-09-26 10:23:26 -04:00
} , [ value ] ) ;
2021-05-21 06:14:23 -04:00
2023-09-26 10:23:26 -04:00
// Value updates must happen synchonously to avoid overwriting newer values.
2022-04-11 08:04:30 -04:00
( 0 , external _wp _element _namespaceObject . useLayoutEffect ) ( ( ) => {
2021-05-21 06:14:23 -04:00
if ( ! hadSelectionUpdate . current ) {
2020-06-26 09:33:47 -04:00
return ;
}
2022-04-12 11:12:47 -04:00
if ( ref . current . ownerDocument . activeElement !== ref . current ) {
ref . current . focus ( ) ;
}
2023-09-26 10:23:26 -04:00
applyRecord ( record . current ) ;
2021-05-21 06:14:23 -04:00
hadSelectionUpdate . current = false ;
} , [ hadSelectionUpdate . current ] ) ;
2022-04-11 08:04:30 -04:00
const mergedRefs = ( 0 , external _wp _compose _namespaceObject . useMergeRefs ) ( [ ref , useDefaultStyle ( ) , useBoundaryStyle ( {
2021-05-21 06:14:23 -04:00
record
2021-11-08 09:29:21 -05:00
} ) , useCopyHandler ( {
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
record
2021-05-21 06:14:23 -04:00
} ) , useSelectObject ( ) , useFormatBoundaries ( {
record ,
applyRecord
} ) , useDelete ( {
createRecord ,
2023-09-26 10:23:26 -04:00
handleChange
2021-05-21 06:14:23 -04:00
} ) , useInputAndSelection ( {
record ,
applyRecord ,
createRecord ,
handleChange ,
2021-05-19 11:09:27 -04:00
isSelected ,
2021-05-21 06:14:23 -04:00
onSelectionChange
2023-06-27 10:24:19 -04:00
} ) , useSelectionChangeCompat ( ) , ( 0 , external _wp _compose _namespaceObject . 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 ,
Editor: Update block editor packages to the latest patch releases.
This updates the block editor related npm dependencies to their latest patch versions ahead of WordPress 6.2.1 RC1.
Updated packages:
- @wordpress/annotations@2.26.4
- @wordpress/block-directory@4.3.12
- @wordpress/block-editor@11.3.10
- @wordpress/block-library@8.3.12
- @wordpress/components@23.3.7
- @wordpress/customize-widgets@4.3.12
- @wordpress/edit-post@7.3.12
- @wordpress/edit-site@5.3.12
- @wordpress/edit-widgets@5.3.12
- @wordpress/editor@13.3.10
- @wordpress/format-library@4.3.10
- @wordpress/interface@5.3.8
- @wordpress/list-reusable-blocks@4.3.7
- @wordpress/preferences@3.3.7
- @wordpress/reusable-blocks@4.3.10
- @wordpress/rich-text@6.3.4
- @wordpress/server-side-render@4.3.7
- @wordpress/widgets@3.3.10
This changeset includes the following fixes:
- i18n: Add context to labels related to CSS position properties gutenberg#49135
- Comments: Fix 'sprintf requires more than 1 params' error gutenberg#49054
- Fix the site editor loading in multi-site installs gutenberg#49861
- Fix quick inserter going off-screen in some situations gutenberg#49881
- Site Editor: Decode the site title properly gutenberg#49685
- Firefox: fix input rules (React async state issue) gutenberg#48210
- Only show alignment info when parent layout is constrained. gutenberg#49703
- [Inserter]: Fix onHover error on patterns tab in mobile gutenberg#49450
- Fix site editor redirection after creating new template or template part gutenberg#49364
Props mamaduka, audrasjb, wildworks, ocean90, aristath, costdev, hellofromtonya, youknowriad, mdxfr, oandregal, mattwiebe, bph, ndiego, talldanwp, joen, ellatrix, kevin940726, isabel_brison, andrewserong, ntsekouras, welcher.
Fixes #58274.
Built from https://develop.svn.wordpress.org/trunk@55737
git-svn-id: http://core.svn.wordpress.org/trunk@55249 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-05-09 10:13:25 -04:00
// A function to get the most recent value so event handlers in
// useRichText implementations have access to it. For example when
// listening to input events, we internally update the state, but this
// state is not yet available to the input event handler because React
// may re-render asynchronously.
getValue : ( ) => record . current ,
2020-06-26 09:33:47 -04:00
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 ( ) { }
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/index.js
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
2023-06-27 10:24:19 -04:00
/ * *
* An object which represents a formatted string . See main ` @wordpress/rich-text `
* documentation for more information .
* /
2018-12-13 23:41:57 -05:00
2022-04-11 08:04:30 -04:00
( window . wp = window . wp || { } ) . richText = _ _webpack _exports _ _ ;
/******/ } ) ( )
;