diff -r 34716fd837a4 -r be944660c56a wp/wp-includes/js/dist/rich-text.js --- a/wp/wp-includes/js/dist/rich-text.js Tue Dec 15 15:52:01 2020 +0100 +++ b/wp/wp-includes/js/dist/rich-text.js Wed Sep 21 18:19:35 2022 +0200 @@ -82,338 +82,54 @@ /******/ /******/ /******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 440); +/******/ return __webpack_require__(__webpack_require__.s = "yyEc"); /******/ }) /************************************************************************/ /******/ ({ -/***/ 0: +/***/ "1ZqX": /***/ (function(module, exports) { -(function() { module.exports = this["wp"]["element"]; }()); - -/***/ }), - -/***/ 11: -/***/ (function(module, exports, __webpack_require__) { - -var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*! - Copyright (c) 2017 Jed Watson. - Licensed under the MIT License (MIT), see - http://jedwatson.github.io/classnames -*/ -/* global define */ - -(function () { - 'use strict'; - - var hasOwn = {}.hasOwnProperty; - - function classNames () { - var classes = []; - - for (var i = 0; i < arguments.length; i++) { - var arg = arguments[i]; - if (!arg) continue; - - var argType = typeof arg; - - if (argType === 'string' || argType === 'number') { - classes.push(arg); - } else if (Array.isArray(arg) && arg.length) { - var inner = classNames.apply(null, arg); - if (inner) { - classes.push(inner); - } - } else if (argType === 'object') { - for (var key in arg) { - if (hasOwn.call(arg, key) && arg[key]) { - classes.push(key); - } - } - } - } - - return classes.join(' '); - } - - if ( true && module.exports) { - classNames.default = classNames; - module.exports = classNames; - } else if (true) { - // register as 'classnames', consistent with npm package name - !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = (function () { - return classNames; - }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), - __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); - } else {} -}()); - +(function() { module.exports = window["wp"]["data"]; }()); /***/ }), -/***/ 14: -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; - -// EXPORTS -__webpack_require__.d(__webpack_exports__, "a", function() { return /* binding */ _slicedToArray; }); - -// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/arrayWithHoles.js -var arrayWithHoles = __webpack_require__(38); - -// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/iterableToArrayLimit.js -function _iterableToArrayLimit(arr, i) { - if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; - var _arr = []; - var _n = true; - var _d = false; - var _e = undefined; - - try { - for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { - _arr.push(_s.value); - - if (i && _arr.length === i) break; - } - } catch (err) { - _d = true; - _e = err; - } finally { - try { - if (!_n && _i["return"] != null) _i["return"](); - } finally { - if (_d) throw _e; - } - } - - return _arr; -} -// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js -var unsupportedIterableToArray = __webpack_require__(29); - -// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/nonIterableRest.js -var nonIterableRest = __webpack_require__(39); - -// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/slicedToArray.js - - - - -function _slicedToArray(arr, i) { - return Object(arrayWithHoles["a" /* default */])(arr) || _iterableToArrayLimit(arr, i) || Object(unsupportedIterableToArray["a" /* default */])(arr, i) || Object(nonIterableRest["a" /* default */])(); -} +/***/ "GRId": +/***/ (function(module, exports) { + +(function() { module.exports = window["wp"]["element"]; }()); /***/ }), -/***/ 15: -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _objectWithoutProperties; }); -/* harmony import */ var _objectWithoutPropertiesLoose__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(41); - -function _objectWithoutProperties(source, excluded) { - if (source == null) return {}; - var target = Object(_objectWithoutPropertiesLoose__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(source, excluded); - var key, i; - - if (Object.getOwnPropertySymbols) { - var sourceSymbolKeys = Object.getOwnPropertySymbols(source); - - for (i = 0; i < sourceSymbolKeys.length; i++) { - key = sourceSymbolKeys[i]; - if (excluded.indexOf(key) >= 0) continue; - if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; - target[key] = source[key]; - } - } - - return target; -} +/***/ "K9lf": +/***/ (function(module, exports) { + +(function() { module.exports = window["wp"]["compose"]; }()); /***/ }), -/***/ 18: -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; - -// EXPORTS -__webpack_require__.d(__webpack_exports__, "a", function() { return /* binding */ _toConsumableArray; }); - -// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.js -var arrayLikeToArray = __webpack_require__(26); - -// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js - -function _arrayWithoutHoles(arr) { - if (Array.isArray(arr)) return Object(arrayLikeToArray["a" /* default */])(arr); -} -// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/iterableToArray.js -var iterableToArray = __webpack_require__(35); - -// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js -var unsupportedIterableToArray = __webpack_require__(29); - -// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/nonIterableSpread.js -function _nonIterableSpread() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -} -// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js - - - - -function _toConsumableArray(arr) { - return _arrayWithoutHoles(arr) || Object(iterableToArray["a" /* default */])(arr) || Object(unsupportedIterableToArray["a" /* default */])(arr) || _nonIterableSpread(); -} - -/***/ }), - -/***/ 2: +/***/ "RxS6": /***/ (function(module, exports) { -(function() { module.exports = this["lodash"]; }()); - -/***/ }), - -/***/ 21: -/***/ (function(module, exports) { - -(function() { module.exports = this["wp"]["keycodes"]; }()); - -/***/ }), - -/***/ 26: -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _arrayLikeToArray; }); -function _arrayLikeToArray(arr, len) { - if (len == null || len > arr.length) len = arr.length; - - for (var i = 0, arr2 = new Array(len); i < len; i++) { - arr2[i] = arr[i]; - } - - return arr2; -} - -/***/ }), - -/***/ 29: -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _unsupportedIterableToArray; }); -/* harmony import */ var _arrayLikeToArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(26); - -function _unsupportedIterableToArray(o, minLen) { - if (!o) return; - if (typeof o === "string") return Object(_arrayLikeToArray__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if (n === "Object" && o.constructor) n = o.constructor.name; - if (n === "Map" || n === "Set") return Array.from(o); - if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return Object(_arrayLikeToArray__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(o, minLen); -} +(function() { module.exports = window["wp"]["keycodes"]; }()); /***/ }), -/***/ 35: -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _iterableToArray; }); -function _iterableToArray(iter) { - if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); -} - -/***/ }), - -/***/ 37: +/***/ "Vx3V": /***/ (function(module, exports) { -(function() { module.exports = this["wp"]["deprecated"]; }()); - -/***/ }), - -/***/ 38: -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _arrayWithHoles; }); -function _arrayWithHoles(arr) { - if (Array.isArray(arr)) return arr; -} - -/***/ }), - -/***/ 39: -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _nonIterableRest; }); -function _nonIterableRest() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -} - -/***/ }), - -/***/ 4: -/***/ (function(module, exports) { - -(function() { module.exports = this["wp"]["data"]; }()); +(function() { module.exports = window["wp"]["escapeHtml"]; }()); /***/ }), -/***/ 40: -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _typeof; }); -function _typeof(obj) { - "@babel/helpers - typeof"; - - if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { - _typeof = function _typeof(obj) { - return typeof obj; - }; - } else { - _typeof = function _typeof(obj) { - return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; - }; - } - - return _typeof(obj); -} +/***/ "YLtl": +/***/ (function(module, exports) { + +(function() { module.exports = window["lodash"]; }()); /***/ }), -/***/ 41: -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _objectWithoutPropertiesLoose; }); -function _objectWithoutPropertiesLoose(source, excluded) { - if (source == null) return {}; - var target = {}; - var sourceKeys = Object.keys(source); - var key, i; - - for (i = 0; i < sourceKeys.length; i++) { - key = sourceKeys[i]; - if (excluded.indexOf(key) >= 0) continue; - target[key] = source[key]; - } - - return target; -} - -/***/ }), - -/***/ 42: +/***/ "pPDe": /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; @@ -695,7 +411,7 @@ /***/ }), -/***/ 440: +/***/ "yyEc": /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; @@ -703,6 +419,7 @@ __webpack_require__.r(__webpack_exports__); // EXPORTS +__webpack_require__.d(__webpack_exports__, "store", function() { return /* reexport */ store; }); __webpack_require__.d(__webpack_exports__, "applyFormat", function() { return /* reexport */ applyFormat; }); __webpack_require__.d(__webpack_exports__, "concat", function() { return /* reexport */ concat; }); __webpack_require__.d(__webpack_exports__, "create", function() { return /* reexport */ create; }); @@ -736,7 +453,9 @@ __webpack_require__.d(__webpack_exports__, "__unstableOutdentListItems", function() { return /* reexport */ outdentListItems; }); __webpack_require__.d(__webpack_exports__, "__unstableChangeListType", function() { return /* reexport */ changeListType; }); __webpack_require__.d(__webpack_exports__, "__unstableCreateElement", function() { return /* reexport */ createElement; }); -__webpack_require__.d(__webpack_exports__, "__experimentalRichText", function() { return /* reexport */ component; }); +__webpack_require__.d(__webpack_exports__, "useAnchorRef", function() { return /* reexport */ useAnchorRef; }); +__webpack_require__.d(__webpack_exports__, "__experimentalRichText", function() { return /* reexport */ __experimentalRichText; }); +__webpack_require__.d(__webpack_exports__, "__unstableUseRichText", function() { return /* reexport */ useRichText; }); __webpack_require__.d(__webpack_exports__, "__unstableFormatEdit", function() { return /* reexport */ FormatEdit; }); // NAMESPACE OBJECT: ./node_modules/@wordpress/rich-text/build-module/store/selectors.js @@ -753,22 +472,13 @@ __webpack_require__.d(actions_namespaceObject, "addFormatTypes", function() { return addFormatTypes; }); __webpack_require__.d(actions_namespaceObject, "removeFormatTypes", function() { return removeFormatTypes; }); -// EXTERNAL MODULE: external {"this":["wp","data"]} -var external_this_wp_data_ = __webpack_require__(4); - -// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/defineProperty.js -var defineProperty = __webpack_require__(5); - -// EXTERNAL MODULE: external {"this":"lodash"} -var external_this_lodash_ = __webpack_require__(2); +// EXTERNAL MODULE: external ["wp","data"] +var external_wp_data_ = __webpack_require__("1ZqX"); + +// EXTERNAL MODULE: external "lodash" +var external_lodash_ = __webpack_require__("YLtl"); // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/store/reducer.js - - -function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } - -function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } - /** * External dependencies */ @@ -787,26 +497,25 @@ * @return {Object} Updated state. */ -function reducer_formatTypes() { - var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - var action = arguments.length > 1 ? arguments[1] : undefined; - +function reducer_formatTypes(state = {}, action) { switch (action.type) { case 'ADD_FORMAT_TYPES': - return _objectSpread({}, state, {}, Object(external_this_lodash_["keyBy"])(action.formatTypes, 'name')); + return { ...state, + ...Object(external_lodash_["keyBy"])(action.formatTypes, 'name') + }; case 'REMOVE_FORMAT_TYPES': - return Object(external_this_lodash_["omit"])(state, action.names); + return Object(external_lodash_["omit"])(state, action.names); } return state; } -/* harmony default export */ var reducer = (Object(external_this_wp_data_["combineReducers"])({ +/* harmony default export */ var reducer = (Object(external_wp_data_["combineReducers"])({ formatTypes: reducer_formatTypes })); // EXTERNAL MODULE: ./node_modules/rememo/es/rememo.js -var rememo = __webpack_require__(42); +var rememo = __webpack_require__("pPDe"); // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/store/selectors.js /** @@ -822,11 +531,7 @@ * @return {Array} Format types. */ -var getFormatTypes = Object(rememo["a" /* default */])(function (state) { - return Object.values(state.formatTypes); -}, function (state) { - return [state.formatTypes]; -}); +const getFormatTypes = Object(rememo["a" /* default */])(state => Object.values(state.formatTypes), state => [state.formatTypes]); /** * Returns a format type by name. * @@ -850,9 +555,10 @@ */ function getFormatTypeForBareElement(state, bareElementTagName) { - return Object(external_this_lodash_["find"])(getFormatTypes(state), function (_ref) { - var className = _ref.className, - tagName = _ref.tagName; + return Object(external_lodash_["find"])(getFormatTypes(state), ({ + className, + tagName + }) => { return className === null && bareElementTagName === tagName; }); } @@ -866,14 +572,14 @@ */ function getFormatTypeForClassName(state, elementClassName) { - return Object(external_this_lodash_["find"])(getFormatTypes(state), function (_ref2) { - var className = _ref2.className; - + return Object(external_lodash_["find"])(getFormatTypes(state), ({ + className + }) => { if (className === null) { return false; } - return " ".concat(elementClassName, " ").indexOf(" ".concat(className, " ")) >= 0; + return ` ${elementClassName} `.indexOf(` ${className} `) >= 0; }); } @@ -894,7 +600,7 @@ function addFormatTypes(formatTypes) { return { type: 'ADD_FORMAT_TYPES', - formatTypes: Object(external_this_lodash_["castArray"])(formatTypes) + formatTypes: Object(external_lodash_["castArray"])(formatTypes) }; } /** @@ -908,7 +614,7 @@ function removeFormatTypes(names) { return { type: 'REMOVE_FORMAT_TYPES', - names: Object(external_this_lodash_["castArray"])(names) + names: Object(external_lodash_["castArray"])(names) }; } @@ -924,21 +630,30 @@ -Object(external_this_wp_data_["registerStore"])('core/rich-text', { +const STORE_NAME = 'core/rich-text'; +/** + * Store definition for the rich-text namespace. + * + * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore + * + * @type {Object} + */ + +const store = Object(external_wp_data_["createReduxStore"])(STORE_NAME, { reducer: reducer, selectors: selectors_namespaceObject, actions: actions_namespaceObject }); - -// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js + 2 modules -var toConsumableArray = __webpack_require__(18); +Object(external_wp_data_["register"])(store); // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/is-format-equal.js +/** @typedef {import('./create').RichTextFormat} RichTextFormat */ + /** * Optimised equality check for format objects. * - * @param {?Object} format1 Format to compare. - * @param {?Object} format2 Format to compare. + * @param {?RichTextFormat} format1 Format to compare. + * @param {?RichTextFormat} format2 Format to compare. * * @return {boolean} True if formats are equal, false if not. */ @@ -957,8 +672,8 @@ return false; } - var attributes1 = format1.attributes; - var attributes2 = format2.attributes; // Both not defined. + const attributes1 = format1.attributes; + const attributes2 = format2.attributes; // Both not defined. if (attributes1 === attributes2) { return true; @@ -969,17 +684,17 @@ return false; } - var keys1 = Object.keys(attributes1); - var keys2 = Object.keys(attributes2); + const keys1 = Object.keys(attributes1); + const keys2 = Object.keys(attributes2); if (keys1.length !== keys2.length) { return false; } - var length = keys1.length; // Optimise for speed. - - for (var i = 0; i < length; i++) { - var name = keys1[i]; + const length = keys1.length; // Optimise for speed. + + for (let i = 0; i < length; i++) { + const name = keys1[i]; if (attributes1[name] !== attributes2[name]) { return false; @@ -990,34 +705,30 @@ } // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/normalise-formats.js - - -function normalise_formats_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } - -function normalise_formats_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { normalise_formats_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { normalise_formats_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } - /** * Internal dependencies */ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + /** * Normalises formats: ensures subsequent adjacent equal formats have the same * reference. * - * @param {Object} value Value to normalise formats of. + * @param {RichTextValue} value Value to normalise formats of. * - * @return {Object} New value with normalised formats. + * @return {RichTextValue} New value with normalised formats. */ function normaliseFormats(value) { - var newFormats = value.formats.slice(); - newFormats.forEach(function (formatsAtIndex, index) { - var formatsAtPreviousIndex = newFormats[index - 1]; + const newFormats = value.formats.slice(); + newFormats.forEach((formatsAtIndex, index) => { + const formatsAtPreviousIndex = newFormats[index - 1]; if (formatsAtPreviousIndex) { - var newFormatsAtIndex = formatsAtIndex.slice(); - newFormatsAtIndex.forEach(function (format, formatIndex) { - var previousFormat = formatsAtPreviousIndex[formatIndex]; + const newFormatsAtIndex = formatsAtIndex.slice(); + newFormatsAtIndex.forEach((format, formatIndex) => { + const previousFormat = formatsAtPreviousIndex[formatIndex]; if (isFormatEqual(format, previousFormat)) { newFormatsAtIndex[formatIndex] = previousFormat; @@ -1026,19 +737,12 @@ newFormats[index] = newFormatsAtIndex; } }); - return normalise_formats_objectSpread({}, value, { + return { ...value, formats: newFormats - }); + }; } // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/apply-format.js - - - -function apply_format_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } - -function apply_format_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { apply_format_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { apply_format_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } - /** * External dependencies */ @@ -1048,6 +752,9 @@ */ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + +/** @typedef {import('./create').RichTextFormat} RichTextFormat */ function replace(array, index, value) { array = array.slice(); @@ -1059,30 +766,30 @@ * given `endIndex`. Indices are retrieved from the selection if none are * provided. * - * @param {Object} value Value to modify. - * @param {Object} format Format to apply. - * @param {number} [startIndex] Start index. - * @param {number} [endIndex] End index. + * @param {RichTextValue} value Value to modify. + * @param {RichTextFormat} format Format to apply. + * @param {number} [startIndex] Start index. + * @param {number} [endIndex] End index. * - * @return {Object} A new value with the format applied. + * @return {RichTextValue} A new value with the format applied. */ -function applyFormat(value, format) { - var startIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : value.start; - var endIndex = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : value.end; - var formats = value.formats, - activeFormats = value.activeFormats; - var newFormats = formats.slice(); // The selection is collapsed. +function applyFormat(value, format, startIndex = value.start, endIndex = value.end) { + const { + formats, + activeFormats + } = value; + const newFormats = formats.slice(); // The selection is collapsed. if (startIndex === endIndex) { - var startFormat = Object(external_this_lodash_["find"])(newFormats[startIndex], { + const startFormat = Object(external_lodash_["find"])(newFormats[startIndex], { type: format.type }); // If the caret is at a format of the same type, expand start and end to // the edges of the format. This is useful to apply new attributes. if (startFormat) { - var index = newFormats[startIndex].indexOf(startFormat); + const index = newFormats[startIndex].indexOf(startFormat); while (newFormats[startIndex] && newFormats[startIndex][index] === startFormat) { newFormats[startIndex] = replace(newFormats[startIndex], index, format); @@ -1098,44 +805,40 @@ } } else { // Determine the highest position the new format can be inserted at. - var position = +Infinity; - - for (var _index = startIndex; _index < endIndex; _index++) { - if (newFormats[_index]) { - newFormats[_index] = newFormats[_index].filter(function (_ref) { - var type = _ref.type; - return type !== format.type; - }); - var length = newFormats[_index].length; + let position = +Infinity; + + for (let index = startIndex; index < endIndex; index++) { + if (newFormats[index]) { + newFormats[index] = newFormats[index].filter(({ + type + }) => type !== format.type); + const length = newFormats[index].length; if (length < position) { position = length; } } else { - newFormats[_index] = []; + newFormats[index] = []; position = 0; } } - for (var _index2 = startIndex; _index2 < endIndex; _index2++) { - newFormats[_index2].splice(position, 0, format); + for (let index = startIndex; index < endIndex; index++) { + newFormats[index].splice(position, 0, format); } } - return normaliseFormats(apply_format_objectSpread({}, value, { + return normaliseFormats({ ...value, 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. - activeFormats: [].concat(Object(toConsumableArray["a" /* default */])(Object(external_this_lodash_["reject"])(activeFormats, { + activeFormats: [...Object(external_lodash_["reject"])(activeFormats, { type: format.type - })), [format]) - })); + }), format] + }); } -// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/typeof.js -var esm_typeof = __webpack_require__(40); - // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/create-element.js /** * Parse the given HTML into a body element. @@ -1149,9 +852,9 @@ * * @return {HTMLBodyElement} Body element with parsed HTML. */ -function createElement(_ref, html) { - var implementation = _ref.implementation; - +function createElement({ + implementation +}, html) { // 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 @@ -1168,28 +871,20 @@ /** * Line separator character, used for multiline text. */ -var LINE_SEPARATOR = "\u2028"; +const LINE_SEPARATOR = '\u2028'; /** * Object replacement character, used as a placeholder for objects. */ -var OBJECT_REPLACEMENT_CHARACTER = "\uFFFC"; +const OBJECT_REPLACEMENT_CHARACTER = '\ufffc'; /** * Zero width non-breaking space, used as padding in the editable DOM tree when * it is empty otherwise. */ -var ZWNBSP = "\uFEFF"; +const ZWNBSP = '\ufeff'; // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/create.js - - - - -function create_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } - -function create_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { create_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { create_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } - /** * WordPress dependencies */ @@ -1202,6 +897,25 @@ +/** + * @typedef {Object} RichTextFormat + * + * @property {string} type Format type. + */ + +/** + * @typedef {Array} RichTextFormatList + */ + +/** + * @typedef {Object} RichTextValue + * + * @property {string} text Text. + * @property {Array} formats Formats. + * @property {Array} replacements Replacements. + * @property {number|undefined} start Selection start. + * @property {number|undefined} end Selection end. + */ function createEmptyValue() { return { @@ -1212,24 +926,25 @@ } function simpleFindKey(object, value) { - for (var key in object) { + for (const key in object) { if (object[key] === value) { return key; } } } -function toFormat(_ref) { - var type = _ref.type, - attributes = _ref.attributes; - var formatType; +function toFormat({ + type, + attributes +}) { + let formatType; if (attributes && attributes.class) { - formatType = Object(external_this_wp_data_["select"])('core/rich-text').getFormatTypeForClassName(attributes.class); + formatType = Object(external_wp_data_["select"])('core/rich-text').getFormatTypeForClassName(attributes.class); if (formatType) { // Preserve any additional classes. - attributes.class = " ".concat(attributes.class, " ").replace(" ".concat(formatType.className, " "), ' ').trim(); + attributes.class = ` ${attributes.class} `.replace(` ${formatType.className} `, ' ').trim(); if (!attributes.class) { delete attributes.class; @@ -1238,15 +953,15 @@ } if (!formatType) { - formatType = Object(external_this_wp_data_["select"])('core/rich-text').getFormatTypeForBareElement(type); + formatType = Object(external_wp_data_["select"])('core/rich-text').getFormatTypeForBareElement(type); } if (!formatType) { return attributes ? { - type: type, - attributes: attributes + type, + attributes } : { - type: type + type }; } @@ -1260,11 +975,11 @@ }; } - var registeredAttributes = {}; - var unregisteredAttributes = {}; - - for (var name in attributes) { - var key = simpleFindKey(formatType.attributes, name); + const registeredAttributes = {}; + const unregisteredAttributes = {}; + + for (const name in attributes) { + const key = simpleFindKey(formatType.attributes, name); if (key) { registeredAttributes[key] = attributes[name]; @@ -1276,7 +991,7 @@ return { type: formatType.name, attributes: registeredAttributes, - unregisteredAttributes: unregisteredAttributes + unregisteredAttributes }; } /** @@ -1316,29 +1031,29 @@ * multiline. * @param {Array} [$1.multilineWrapperTags] Tags where lines can be found if * nesting is possible. - * @param {?boolean} [$1.preserveWhiteSpace] Whether or not to collapse white + * @param {boolean} [$1.preserveWhiteSpace] Whether or not to collapse white * space characters. + * @param {boolean} [$1.__unstableIsEditableTree] * - * @return {Object} A rich text value. + * @return {RichTextValue} A rich text value. */ -function create() { - var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, - element = _ref2.element, - text = _ref2.text, - html = _ref2.html, - range = _ref2.range, - multilineTag = _ref2.multilineTag, - multilineWrapperTags = _ref2.multilineWrapperTags, - isEditableTree = _ref2.__unstableIsEditableTree, - preserveWhiteSpace = _ref2.preserveWhiteSpace; - +function create({ + element, + text, + html, + range, + multilineTag, + multilineWrapperTags, + __unstableIsEditableTree: isEditableTree, + preserveWhiteSpace +} = {}) { if (typeof text === 'string' && text.length > 0) { return { formats: Array(text.length), replacements: Array(text.length), - text: text + text }; } @@ -1348,26 +1063,26 @@ element = createElement(document, html); } - if (Object(esm_typeof["a" /* default */])(element) !== 'object') { + if (typeof element !== 'object') { return createEmptyValue(); } if (!multilineTag) { return createFromElement({ - element: element, - range: range, - isEditableTree: isEditableTree, - preserveWhiteSpace: preserveWhiteSpace + element, + range, + isEditableTree, + preserveWhiteSpace }); } return createFromMultilineElement({ - element: element, - range: range, - multilineTag: multilineTag, - multilineWrapperTags: multilineWrapperTags, - isEditableTree: isEditableTree, - preserveWhiteSpace: preserveWhiteSpace + element, + range, + multilineTag, + multilineWrapperTags, + isEditableTree, + preserveWhiteSpace }); } /** @@ -1385,12 +1100,16 @@ return; } - var parentNode = node.parentNode; - var startContainer = range.startContainer, - startOffset = range.startOffset, - endContainer = range.endContainer, - endOffset = range.endOffset; - var currentLength = accumulator.text.length; // Selection can be extracted from value. + const { + parentNode + } = node; + const { + startContainer, + startOffset, + endContainer, + endOffset + } = range; + const currentLength = accumulator.text.length; // Selection can be extracted from value. if (value.start !== undefined) { accumulator.start = currentLength + value.start; // Range indicates that the current node has selection. @@ -1424,7 +1143,7 @@ * @param {Range} range The range to filter. * @param {Function} filter Function to use to filter the text. * - * @return {?Object} Object containing range properties. + * @return {Object|void} Object containing range properties. */ @@ -1433,10 +1152,14 @@ return; } - var startContainer = range.startContainer, - endContainer = range.endContainer; - var startOffset = range.startOffset, - endOffset = range.endOffset; + const { + startContainer, + endContainer + } = range; + let { + startOffset, + endOffset + } = range; if (node === startContainer) { startOffset = filter(node.nodeValue.slice(0, startOffset)).length; @@ -1447,10 +1170,10 @@ } return { - startContainer: startContainer, - startOffset: startOffset, - endContainer: endContainer, - endOffset: endOffset + startContainer, + startOffset, + endContainer, + endOffset }; } /** @@ -1465,7 +1188,7 @@ return string.replace(/[\n\r\t]+/g, ' '); } -var ZWNBSPRegExp = new RegExp(ZWNBSP, 'g'); +const ZWNBSPRegExp = new RegExp(ZWNBSP, 'g'); /** * Removes padding (zero width non breaking spaces) added by `toTree`. * @@ -1478,30 +1201,32 @@ /** * Creates a Rich Text value from a DOM element and range. * - * @param {Object} $1 Named argements. - * @param {?Element} $1.element Element to create value from. - * @param {?Range} $1.range Range to create value from. - * @param {?string} $1.multilineTag Multiline tag if the structure is + * @param {Object} $1 Named argements. + * @param {Element} [$1.element] Element to create value from. + * @param {Range} [$1.range] Range to create value from. + * @param {string} [$1.multilineTag] Multiline tag if the structure is * multiline. - * @param {?Array} $1.multilineWrapperTags Tags where lines can be found if + * @param {Array} [$1.multilineWrapperTags] Tags where lines can be found if * nesting is possible. - * @param {?boolean} $1.preserveWhiteSpace Whether or not to collapse white + * @param {boolean} [$1.preserveWhiteSpace] Whether or not to collapse white * space characters. + * @param {Array} [$1.currentWrapperTags] + * @param {boolean} [$1.isEditableTree] * - * @return {Object} A rich text value. + * @return {RichTextValue} A rich text value. */ -function createFromElement(_ref3) { - var element = _ref3.element, - range = _ref3.range, - multilineTag = _ref3.multilineTag, - multilineWrapperTags = _ref3.multilineWrapperTags, - _ref3$currentWrapperT = _ref3.currentWrapperTags, - currentWrapperTags = _ref3$currentWrapperT === void 0 ? [] : _ref3$currentWrapperT, - isEditableTree = _ref3.isEditableTree, - preserveWhiteSpace = _ref3.preserveWhiteSpace; - var accumulator = createEmptyValue(); +function createFromElement({ + element, + range, + multilineTag, + multilineWrapperTags, + currentWrapperTags = [], + isEditableTree, + preserveWhiteSpace +}) { + const accumulator = createEmptyValue(); if (!element) { return accumulator; @@ -1512,43 +1237,57 @@ return accumulator; } - var length = element.childNodes.length; // Optimise for speed. - - var _loop = function _loop(index) { - var node = element.childNodes[index]; - var type = node.nodeName.toLowerCase(); + const length = element.childNodes.length; // Optimise for speed. + + for (let index = 0; index < length; index++) { + const node = element.childNodes[index]; + const type = node.nodeName.toLowerCase(); if (node.nodeType === node.TEXT_NODE) { - var filter = removePadding; + let filter = removePadding; if (!preserveWhiteSpace) { - filter = function filter(string) { - return removePadding(collapseWhiteSpace(string)); - }; + filter = string => removePadding(collapseWhiteSpace(string)); } - var text = filter(node.nodeValue); + const text = filter(node.nodeValue); range = filterRange(node, range, filter); accumulateSelection(accumulator, node, range, { - text: text + text }); // Create a sparse array of the same length as `text`, in which // formats can be added. accumulator.formats.length += text.length; accumulator.replacements.length += text.length; accumulator.text += text; - return "continue"; + continue; } if (node.nodeType !== node.ELEMENT_NODE) { - return "continue"; + continue; } if (isEditableTree && ( // Ignore any placeholders. node.getAttribute('data-rich-text-placeholder') || // Ignore any line breaks that are not inserted by us. type === 'br' && !node.getAttribute('data-rich-text-line-break'))) { accumulateSelection(accumulator, node, range, createEmptyValue()); - return "continue"; + continue; + } + + if (type === 'script') { + const value = { + formats: [,], + replacements: [{ + type, + attributes: { + 'data-rich-text-script': node.getAttribute('data-rich-text-script') || encodeURIComponent(node.innerHTML) + } + }], + text: OBJECT_REPLACEMENT_CHARACTER + }; + accumulateSelection(accumulator, node, range, value); + mergePair(accumulator, value); + continue; } if (type === 'br') { @@ -1556,42 +1295,41 @@ mergePair(accumulator, create({ text: '\n' })); - return "continue"; + continue; } - var lastFormats = accumulator.formats[accumulator.formats.length - 1]; - var lastFormat = lastFormats && lastFormats[lastFormats.length - 1]; - var newFormat = toFormat({ - type: type, + const lastFormats = accumulator.formats[accumulator.formats.length - 1]; + const lastFormat = lastFormats && lastFormats[lastFormats.length - 1]; + const newFormat = toFormat({ + type, attributes: getAttributes({ element: node }) }); - var format = isFormatEqual(newFormat, lastFormat) ? lastFormat : newFormat; + const format = isFormatEqual(newFormat, lastFormat) ? lastFormat : newFormat; if (multilineWrapperTags && multilineWrapperTags.indexOf(type) !== -1) { - var _value = createFromMultilineElement({ + const value = createFromMultilineElement({ element: node, - range: range, - multilineTag: multilineTag, - multilineWrapperTags: multilineWrapperTags, - currentWrapperTags: [].concat(Object(toConsumableArray["a" /* default */])(currentWrapperTags), [format]), - isEditableTree: isEditableTree, - preserveWhiteSpace: preserveWhiteSpace + range, + multilineTag, + multilineWrapperTags, + currentWrapperTags: [...currentWrapperTags, format], + isEditableTree, + preserveWhiteSpace }); - - accumulateSelection(accumulator, node, range, _value); - mergePair(accumulator, _value); - return "continue"; + accumulateSelection(accumulator, node, range, value); + mergePair(accumulator, value); + continue; } - var value = createFromElement({ + const value = createFromElement({ element: node, - range: range, - multilineTag: multilineTag, - multilineWrapperTags: multilineWrapperTags, - isEditableTree: isEditableTree, - preserveWhiteSpace: preserveWhiteSpace + range, + multilineTag, + multilineWrapperTags, + isEditableTree, + preserveWhiteSpace }); accumulateSelection(accumulator, node, range, value); @@ -1613,7 +1351,7 @@ return mergeFormats.newFormats; } - var newFormats = formats ? [format].concat(Object(toConsumableArray["a" /* default */])(formats)) : [format]; + const newFormats = formats ? [format, ...formats] : [format]; mergeFormats.formats = formats; mergeFormats.newFormats = newFormats; return newFormats; @@ -1622,16 +1360,10 @@ mergeFormats.newFormats = [format]; - mergePair(accumulator, create_objectSpread({}, value, { + mergePair(accumulator, { ...value, formats: Array.from(value.formats, mergeFormats) - })); + }); } - }; - - for (var index = 0; index < length; index++) { - var _ret = _loop(index); - - if (_ret === "continue") continue; } return accumulator; @@ -1640,54 +1372,55 @@ * Creates a rich text value from a DOM element and range that should be * multiline. * - * @param {Object} $1 Named argements. - * @param {?Element} $1.element Element to create value from. - * @param {?Range} $1.range Range to create value from. - * @param {?string} $1.multilineTag Multiline tag if the structure is - * multiline. - * @param {?Array} $1.multilineWrapperTags Tags where lines can be found if - * nesting is possible. - * @param {boolean} $1.currentWrapperTags Whether to prepend a line - * separator. - * @param {?boolean} $1.preserveWhiteSpace Whether or not to collapse white - * space characters. + * @param {Object} $1 Named argements. + * @param {Element} [$1.element] Element to create value from. + * @param {Range} [$1.range] Range to create value from. + * @param {string} [$1.multilineTag] Multiline tag if the structure is + * multiline. + * @param {Array} [$1.multilineWrapperTags] Tags where lines can be found if + * nesting is possible. + * @param {boolean} [$1.currentWrapperTags] Whether to prepend a line + * separator. + * @param {boolean} [$1.preserveWhiteSpace] Whether or not to collapse white + * space characters. + * @param {boolean} [$1.isEditableTree] * - * @return {Object} A rich text value. + * @return {RichTextValue} A rich text value. */ -function createFromMultilineElement(_ref4) { - var element = _ref4.element, - range = _ref4.range, - multilineTag = _ref4.multilineTag, - multilineWrapperTags = _ref4.multilineWrapperTags, - _ref4$currentWrapperT = _ref4.currentWrapperTags, - currentWrapperTags = _ref4$currentWrapperT === void 0 ? [] : _ref4$currentWrapperT, - isEditableTree = _ref4.isEditableTree, - preserveWhiteSpace = _ref4.preserveWhiteSpace; - var accumulator = createEmptyValue(); +function createFromMultilineElement({ + element, + range, + multilineTag, + multilineWrapperTags, + currentWrapperTags = [], + isEditableTree, + preserveWhiteSpace +}) { + const accumulator = createEmptyValue(); if (!element || !element.hasChildNodes()) { return accumulator; } - var length = element.children.length; // Optimise for speed. - - for (var index = 0; index < length; index++) { - var node = element.children[index]; + const length = element.children.length; // Optimise for speed. + + for (let index = 0; index < length; index++) { + const node = element.children[index]; if (node.nodeName.toLowerCase() !== multilineTag) { continue; } - var value = createFromElement({ + const value = createFromElement({ element: node, - range: range, - multilineTag: multilineTag, - multilineWrapperTags: multilineWrapperTags, - currentWrapperTags: currentWrapperTags, - isEditableTree: isEditableTree, - preserveWhiteSpace: preserveWhiteSpace + range, + multilineTag, + multilineWrapperTags, + currentWrapperTags, + isEditableTree, + preserveWhiteSpace }); // Multiline value text should be separated by a line separator. if (index !== 0 || currentWrapperTags.length > 0) { @@ -1707,35 +1440,37 @@ /** * Gets the attributes of an element in object shape. * - * @param {Object} $1 Named argements. - * @param {Element} $1.element Element to get attributes from. + * @param {Object} $1 Named argements. + * @param {Element} $1.element Element to get attributes from. * - * @return {?Object} Attribute object or `undefined` if the element has no - * attributes. + * @return {Object|void} Attribute object or `undefined` if the element has no + * attributes. */ -function getAttributes(_ref5) { - var element = _ref5.element; - +function getAttributes({ + element +}) { if (!element.hasAttributes()) { return; } - var length = element.attributes.length; - var accumulator; // Optimise for speed. - - for (var i = 0; i < length; i++) { - var _element$attributes$i = element.attributes[i], - name = _element$attributes$i.name, - value = _element$attributes$i.value; + const length = element.attributes.length; + let accumulator; // Optimise for speed. + + for (let i = 0; i < length; i++) { + const { + name, + value + } = element.attributes[i]; if (name.indexOf('data-rich-text-') === 0) { continue; } + const safeName = /^on/i.test(name) ? 'data-disable-rich-text-' + name : name; accumulator = accumulator || {}; - accumulator[name] = value; + accumulator[safeName] = value; } return accumulator; @@ -1747,12 +1482,14 @@ */ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + /** * Concats a pair of rich text values. Not that this mutates `a` and does NOT * normalise formats! * - * @param {Object} a Value to mutate. - * @param {Object} b Value to add read from. + * @param {Object} a Value to mutate. + * @param {Object} b Value to add read from. * * @return {Object} `a`, mutated. */ @@ -1767,40 +1504,35 @@ * Combine all Rich Text values into one. This is similar to * `String.prototype.concat`. * - * @param {...Object} values Objects to combine. + * @param {...RichTextValue} values Objects to combine. * - * @return {Object} A new value combining all given records. + * @return {RichTextValue} A new value combining all given records. */ -function concat() { - for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) { - values[_key] = arguments[_key]; - } - +function concat(...values) { return normaliseFormats(values.reduce(mergePair, create())); } // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-active-formats.js +/** @typedef {import('./create').RichTextValue} RichTextValue */ + +/** @typedef {import('./create').RichTextFormatList} RichTextFormatList */ + /** * Gets the all format objects at the start of the selection. * - * @param {Object} value Value to inspect. - * @param {Array} value.formats Formats object data values. - * @param {number} value.start Index to start from. - * @param {number} value.end Index to end. - * @param {Array} value.activeFormats Array to return if there are active formats. - * @param {Array} EMPTY_ACTIVE_FORMATS Array to return if there are no active - * formats. + * @param {RichTextValue} value Value to inspect. + * @param {Array} EMPTY_ACTIVE_FORMATS Array to return if there are no + * active formats. * - * @return {?Object} Active format objects. + * @return {RichTextFormatList} Active format objects. */ -function getActiveFormats(_ref) { - var formats = _ref.formats, - start = _ref.start, - end = _ref.end, - activeFormats = _ref.activeFormats; - var EMPTY_ACTIVE_FORMATS = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; - +function getActiveFormats({ + formats, + start, + end, + activeFormats +}, EMPTY_ACTIVE_FORMATS = []) { if (start === undefined) { return EMPTY_ACTIVE_FORMATS; } @@ -1811,8 +1543,8 @@ return activeFormats; } - var formatsBefore = formats[start - 1] || EMPTY_ACTIVE_FORMATS; - var formatsAfter = formats[start] || EMPTY_ACTIVE_FORMATS; // By default, select the lowest amount of formats possible (which means + const formatsBefore = formats[start - 1] || EMPTY_ACTIVE_FORMATS; + const formatsAfter = formats[start] || EMPTY_ACTIVE_FORMATS; // By default, select the lowest amount of formats possible (which means // the caret is positioned outside the format boundary). The user can // then use arrow keys to define `activeFormats`. @@ -1836,20 +1568,25 @@ */ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + +/** @typedef {import('./create').RichTextFormat} RichTextFormat */ + /** * 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. * - * @param {Object} value Value to inspect. - * @param {string} formatType Format type to look for. + * @param {RichTextValue} value Value to inspect. + * @param {string} formatType Format type to look for. * - * @return {Object|undefined} Active format object of the specified type, or undefined. + * @return {RichTextFormat|undefined} Active format object of the specified + * type, or undefined. */ function getActiveFormat(value, formatType) { - return Object(external_this_lodash_["find"])(getActiveFormats(value), { + return Object(external_lodash_["find"])(getActiveFormats(value), { type: formatType }); } @@ -1859,20 +1596,24 @@ * Internal dependencies */ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + +/** @typedef {import('./create').RichTextFormat} RichTextFormat */ + /** * Gets the active object, if there is any. * - * @param {Object} value Value to inspect. + * @param {RichTextValue} value Value to inspect. * - * @return {?Object} Active object, or undefined. + * @return {RichTextFormat|void} Active object, or undefined. */ -function getActiveObject(_ref) { - var start = _ref.start, - end = _ref.end, - replacements = _ref.replacements, - text = _ref.text; - +function getActiveObject({ + start, + end, + replacements, + text +}) { if (start + 1 !== end || text[start] !== OBJECT_REPLACEMENT_CHARACTER) { return; } @@ -1882,16 +1623,24 @@ // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-text-content.js /** + * Internal dependencies + */ + +/** @typedef {import('./create').RichTextValue} RichTextValue */ + +/** * Get the textual content of a Rich Text value. This is similar to * `Element.textContent`. * - * @param {Object} value Value to use. + * @param {RichTextValue} value Value to use. * * @return {string} The text content. */ -function getTextContent(_ref) { - var text = _ref.text; - return text; + +function getTextContent({ + text +}) { + return text.replace(new RegExp(OBJECT_REPLACEMENT_CHARACTER, 'g'), '').replace(new RegExp(LINE_SEPARATOR, 'g'), '\n'); } // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-line-index.js @@ -1899,23 +1648,25 @@ * Internal dependencies */ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + /** * Gets the currently selected line index, or the first line index if the * selection spans over multiple items. * - * @param {Object} value Value to get the line index from. - * @param {boolean} startIndex Optional index that should be contained by the - * line. Defaults to the selection start of the - * value. + * @param {RichTextValue} value Value to get the line index from. + * @param {boolean} startIndex Optional index that should be contained by + * the line. Defaults to the selection start + * of the value. * - * @return {?boolean} The line index. Undefined if not found. + * @return {number|void} The line index. Undefined if not found. */ -function getLineIndex(_ref) { - var start = _ref.start, - text = _ref.text; - var startIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : start; - var index = startIndex; +function getLineIndex({ + start, + text +}, startIndex = start) { + let index = startIndex; while (index--) { if (text[index] === LINE_SEPARATOR) { @@ -1929,20 +1680,24 @@ * Internal dependencies */ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + /** * Whether or not the root list is selected. * - * @param {Object} value The value to check. + * @param {RichTextValue} value The value to check. * * @return {boolean} True if the root list or nothing is selected, false if an * inner list is selected. */ function isListRootSelected(value) { - var replacements = value.replacements, - start = value.start; - var lineIndex = getLineIndex(value, start); - var replacement = replacements[lineIndex]; + const { + replacements, + start + } = value; + const lineIndex = getLineIndex(value, start); + const replacement = replacements[lineIndex]; return !replacement || replacement.length < 1; } @@ -1951,47 +1706,53 @@ * Internal dependencies */ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + /** - * Wether or not the selected list has the given tag name. + * Whether or not the selected list has the given tag name. * - * @param {Object} value The value to check. - * @param {string} type The tag name the list should have. - * @param {string} rootType The current root tag name, to compare with in case - * nothing is selected. + * @param {RichTextValue} value The value to check. + * @param {string} type The tag name the list should have. + * @param {string} rootType The current root tag name, to compare with in + * case nothing is selected. * * @return {boolean} True if the current list type matches `type`, false if not. */ function isActiveListType(value, type, rootType) { - var replacements = value.replacements, - start = value.start; - var lineIndex = getLineIndex(value, start); - var replacement = replacements[lineIndex]; + const { + replacements, + start + } = value; + const lineIndex = getLineIndex(value, start); + const replacement = replacements[lineIndex]; if (!replacement || replacement.length === 0) { return type === rootType; } - var lastFormat = replacement[replacement.length - 1]; + const lastFormat = replacement[replacement.length - 1]; return lastFormat.type === type; } // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/is-collapsed.js +/** @typedef {import('./create').RichTextValue} RichTextValue */ + /** * 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()`. * - * @param {Object} value The rich text value to check. + * @param {RichTextValue} value The rich text value to check. * * @return {boolean|undefined} True if the selection is collapsed, false if not, * undefined if there is no selection. */ -function isCollapsed(_ref) { - var start = _ref.start, - end = _ref.end; - +function isCollapsed({ + start, + end +}) { if (start === undefined || end === undefined) { return; } @@ -2004,33 +1765,36 @@ * Internal dependencies */ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + /** * Check if a Rich Text value is Empty, meaning it contains no text or any * objects (such as images). * - * @param {Object} value Value to use. + * @param {RichTextValue} value Value to use. * * @return {boolean} True if the value is empty, false if not. */ -function isEmpty(_ref) { - var text = _ref.text; +function isEmpty({ + text +}) { return text.length === 0; } /** * Check if the current collapsed selection is on an empty line in case of a * multiline value. * - * @param {Object} value Value te check. + * @param {RichTextValue} value Value te check. * * @return {boolean} True if the line is empty, false if not. */ -function isEmptyLine(_ref2) { - var text = _ref2.text, - start = _ref2.start, - end = _ref2.end; - +function isEmptyLine({ + text, + start, + end +}) { if (start !== end) { return false; } @@ -2047,7 +1811,7 @@ return true; } - return text.slice(start - 1, end + 1) === "".concat(LINE_SEPARATOR).concat(LINE_SEPARATOR); + return text.slice(start - 1, end + 1) === `${LINE_SEPARATOR}${LINE_SEPARATOR}`; } // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/join.js @@ -2056,50 +1820,48 @@ */ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + /** * 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`. * - * @param {Array} values An array of values to join. - * @param {string|Object} [separator] Separator string or value. + * @param {Array} values An array of values to join. + * @param {string|RichTextValue} [separator] Separator string or value. * - * @return {Object} A new combined value. + * @return {RichTextValue} A new combined value. */ -function join(values) { - var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; - +function join(values, separator = '') { if (typeof separator === 'string') { separator = create({ text: separator }); } - return normaliseFormats(values.reduce(function (accumlator, _ref) { - var formats = _ref.formats, - replacements = _ref.replacements, - text = _ref.text; - return { - formats: accumlator.formats.concat(separator.formats, formats), - replacements: accumlator.replacements.concat(separator.replacements, replacements), - text: accumlator.text + separator.text + text - }; - })); + 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 + }))); } // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/register-format-type.js - - -function register_format_type_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } - -function register_format_type_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { register_format_type_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { register_format_type_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } - /** * WordPress dependencies */ /** + * Internal dependencies + */ + + +/** * @typedef {Object} WPFormat * * @property {string} name A string identifying the format. Must be @@ -2119,14 +1881,15 @@ * @param {string} name Format name. * @param {WPFormat} settings Format settings. * - * @return {WPFormat|undefined} The format, if it has been successfully registered; - * otherwise `undefined`. + * @return {WPFormat|undefined} The format, if it has been successfully + * registered; otherwise `undefined`. */ function registerFormatType(name, settings) { - settings = register_format_type_objectSpread({ - name: name - }, settings); + settings = { + name, + ...settings + }; if (typeof settings.name !== 'string') { window.console.error('Format names must be strings.'); @@ -2138,7 +1901,7 @@ return; } - if (Object(external_this_wp_data_["select"])('core/rich-text').getFormatType(settings.name)) { + if (Object(external_wp_data_["select"])(store).getFormatType(settings.name)) { window.console.error('Format "' + settings.name + '" is already registered.'); return; } @@ -2159,17 +1922,17 @@ } if (settings.className === null) { - var formatTypeForBareElement = Object(external_this_wp_data_["select"])('core/rich-text').getFormatTypeForBareElement(settings.tagName); + const formatTypeForBareElement = Object(external_wp_data_["select"])(store).getFormatTypeForBareElement(settings.tagName); if (formatTypeForBareElement) { - window.console.error("Format \"".concat(formatTypeForBareElement.name, "\" is already registered to handle bare tag name \"").concat(settings.tagName, "\".")); + window.console.error(`Format "${formatTypeForBareElement.name}" is already registered to handle bare tag name "${settings.tagName}".`); return; } } else { - var formatTypeForClassName = Object(external_this_wp_data_["select"])('core/rich-text').getFormatTypeForClassName(settings.className); + const formatTypeForClassName = Object(external_wp_data_["select"])(store).getFormatTypeForClassName(settings.className); if (formatTypeForClassName) { - window.console.error("Format \"".concat(formatTypeForClassName.name, "\" is already registered to handle class name \"").concat(settings.className, "\".")); + window.console.error(`Format "${formatTypeForClassName.name}" is already registered to handle class name "${settings.className}".`); return; } } @@ -2189,17 +1952,11 @@ return; } - Object(external_this_wp_data_["dispatch"])('core/rich-text').addFormatTypes(settings); + Object(external_wp_data_["dispatch"])(store).addFormatTypes(settings); return settings; } // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/remove-format.js - - -function remove_format_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } - -function remove_format_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { remove_format_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { remove_format_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } - /** * External dependencies */ @@ -2209,66 +1966,67 @@ */ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + /** * 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. * - * @param {Object} value Value to modify. - * @param {string} formatType Format type to remove. - * @param {number} [startIndex] Start index. - * @param {number} [endIndex] End index. + * @param {RichTextValue} value Value to modify. + * @param {string} formatType Format type to remove. + * @param {number} [startIndex] Start index. + * @param {number} [endIndex] End index. * - * @return {Object} A new value with the format applied. + * @return {RichTextValue} A new value with the format applied. */ -function removeFormat(value, formatType) { - var startIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : value.start; - var endIndex = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : value.end; - var formats = value.formats, - activeFormats = value.activeFormats; - var newFormats = formats.slice(); // If the selection is collapsed, expand start and end to the edges of the +function removeFormat(value, formatType, startIndex = value.start, endIndex = value.end) { + const { + formats, + activeFormats + } = value; + const newFormats = formats.slice(); // If the selection is collapsed, expand start and end to the edges of the // format. if (startIndex === endIndex) { - var format = Object(external_this_lodash_["find"])(newFormats[startIndex], { + const format = Object(external_lodash_["find"])(newFormats[startIndex], { type: formatType }); if (format) { - while (Object(external_this_lodash_["find"])(newFormats[startIndex], format)) { + while (Object(external_lodash_["find"])(newFormats[startIndex], format)) { filterFormats(newFormats, startIndex, formatType); startIndex--; } endIndex++; - while (Object(external_this_lodash_["find"])(newFormats[endIndex], format)) { + while (Object(external_lodash_["find"])(newFormats[endIndex], format)) { filterFormats(newFormats, endIndex, formatType); endIndex++; } } } else { - for (var i = startIndex; i < endIndex; i++) { + for (let i = startIndex; i < endIndex; i++) { if (newFormats[i]) { filterFormats(newFormats, i, formatType); } } } - return normaliseFormats(remove_format_objectSpread({}, value, { + return normaliseFormats({ ...value, formats: newFormats, - activeFormats: Object(external_this_lodash_["reject"])(activeFormats, { + activeFormats: Object(external_lodash_["reject"])(activeFormats, { type: formatType }) - })); + }); } function filterFormats(formats, index, formatType) { - var newFormats = formats[index].filter(function (_ref) { - var type = _ref.type; - return type !== formatType; - }); + const newFormats = formats[index].filter(({ + type + }) => type !== formatType); if (newFormats.length) { formats[index] = newFormats; @@ -2283,26 +2041,28 @@ */ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + /** * 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. * - * @param {Object} value Value to modify. - * @param {Object|string} valueToInsert Value to insert. - * @param {number} [startIndex] Start index. - * @param {number} [endIndex] End index. + * @param {RichTextValue} value Value to modify. + * @param {RichTextValue|string} valueToInsert Value to insert. + * @param {number} [startIndex] Start index. + * @param {number} [endIndex] End index. * - * @return {Object} A new value with the value inserted. + * @return {RichTextValue} A new value with the value inserted. */ -function insert(value, valueToInsert) { - var startIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : value.start; - var endIndex = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : value.end; - var formats = value.formats, - replacements = value.replacements, - text = value.text; +function insert(value, valueToInsert, startIndex = value.start, endIndex = value.end) { + const { + formats, + replacements, + text + } = value; if (typeof valueToInsert === 'string') { valueToInsert = create({ @@ -2310,7 +2070,7 @@ }); } - var index = startIndex + valueToInsert.text.length; + const index = startIndex + valueToInsert.text.length; return normaliseFormats({ formats: formats.slice(0, startIndex).concat(valueToInsert.formats, formats.slice(endIndex)), replacements: replacements.slice(0, startIndex).concat(valueToInsert.replacements, replacements.slice(endIndex)), @@ -2326,15 +2086,17 @@ */ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + /** * Remove content from a Rich Text value between the given `startIndex` and * `endIndex`. Indices are retrieved from the selection if none are provided. * - * @param {Object} value Value to modify. - * @param {number} [startIndex] Start index. - * @param {number} [endIndex] End index. + * @param {RichTextValue} value Value to modify. + * @param {number} [startIndex] Start index. + * @param {number} [endIndex] End index. * - * @return {Object} A new value with the content removed. + * @return {RichTextValue} A new value with the content removed. */ function remove_remove(value, startIndex, endIndex) { @@ -2342,17 +2104,17 @@ } // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/replace.js - - /** * Internal dependencies */ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + /** * Search a Rich Text value and replace the match(es) with `replacement`. This * is similar to `String.prototype.replace`. * - * @param {Object} value The value to modify. + * @param {RichTextValue} value The value to modify. * @param {RegExp|string} pattern A RegExp object or literal. Can also be * a string. It is treated as a verbatim * string and is not interpreted as a @@ -2362,30 +2124,27 @@ * the specified or the value returned by * the specified function. * - * @return {Object} A new value with replacements applied. + * @return {RichTextValue} A new value with replacements applied. */ -function replace_replace(_ref, pattern, replacement) { - var formats = _ref.formats, - replacements = _ref.replacements, - text = _ref.text, - start = _ref.start, - end = _ref.end; - text = text.replace(pattern, function (match) { - for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - rest[_key - 1] = arguments[_key]; - } - - var offset = rest[rest.length - 2]; - var newText = replacement; - var newFormats; - var newReplacements; +function replace_replace({ + formats, + replacements, + text, + start, + end +}, pattern, replacement) { + text = text.replace(pattern, (match, ...rest) => { + const offset = rest[rest.length - 2]; + let newText = replacement; + let newFormats; + let newReplacements; if (typeof newText === 'function') { - newText = replacement.apply(void 0, [match].concat(rest)); + newText = replacement(match, ...rest); } - if (Object(esm_typeof["a" /* default */])(newText) === 'object') { + if (typeof newText === 'object') { newFormats = newText.formats; newReplacements = newText.replacements; newText = newText.text; @@ -2408,11 +2167,11 @@ return newText; }); return normaliseFormats({ - formats: formats, - replacements: replacements, - text: text, - start: start, - end: end + formats, + replacements, + text, + start, + end }); } @@ -2422,72 +2181,72 @@ */ +/** @typedef {import('./create').RichTextValue} RichTextValue */ /** * Insert a line break character into a Rich Text value at the given * `startIndex`. Any content between `startIndex` and `endIndex` will be * removed. Indices are retrieved from the selection if none are provided. * - * @param {Object} value Value to modify. - * @param {number} [startIndex] Start index. - * @param {number} [endIndex] End index. + * @param {RichTextValue} value Value to modify. + * @param {number} [startIndex] Start index. + * @param {number} [endIndex] End index. * - * @return {Object} A new value with the value inserted. + * @return {RichTextValue} A new value with the value inserted. */ -function insertLineSeparator(value) { - var startIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : value.start; - var endIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : value.end; - var beforeText = getTextContent(value).slice(0, startIndex); - var previousLineSeparatorIndex = beforeText.lastIndexOf(LINE_SEPARATOR); - var previousLineSeparatorFormats = value.replacements[previousLineSeparatorIndex]; - var replacements = [,]; +function insertLineSeparator(value, startIndex = value.start, endIndex = value.end) { + const beforeText = value.text.slice(0, startIndex); + const previousLineSeparatorIndex = beforeText.lastIndexOf(LINE_SEPARATOR); + const previousLineSeparatorFormats = value.replacements[previousLineSeparatorIndex]; + let replacements = [,]; if (previousLineSeparatorFormats) { replacements = [previousLineSeparatorFormats]; } - var valueToInsert = { + const valueToInsert = { formats: [,], - replacements: replacements, + replacements, text: LINE_SEPARATOR }; return insert(value, valueToInsert, startIndex, endIndex); } // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/remove-line-separator.js - - -function remove_line_separator_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } - -function remove_line_separator_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { remove_line_separator_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { remove_line_separator_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } - /** * Internal dependencies */ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + /** - * Removes a line separator character, if existing, from a Rich Text value at the current - * indices. If no line separator exists on the indices it will return undefined. + * Removes a line separator character, if existing, from a Rich Text value at + * the current indices. If no line separator exists on the indices it will + * return undefined. * - * @param {Object} value Value to modify. - * @param {boolean} backward indicates if are removing from the start index or the end index. + * @param {RichTextValue} value Value to modify. + * @param {boolean} backward Indicates if are removing from the start + * index or the end index. * - * @return {Object|undefined} A new value with the line separator removed. Or undefined if no line separator is found on the position. + * @return {RichTextValue|undefined} A new value with the line separator + * removed. Or undefined if no line separator + * is found on the position. */ -function removeLineSeparator(value) { - var backward = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; - var replacements = value.replacements, - text = value.text, - start = value.start, - end = value.end; - var collapsed = isCollapsed(value); - var index = start - 1; - var removeStart = collapsed ? start - 1 : start; - var removeEnd = end; +function removeLineSeparator(value, backward = true) { + const { + replacements, + text, + start, + end + } = value; + const collapsed = isCollapsed(value); + let index = start - 1; + let removeStart = collapsed ? start - 1 : start; + let removeEnd = end; if (!backward) { index = end; @@ -2499,15 +2258,15 @@ return; } - var newValue; // If the line separator that is about te be removed + let newValue; // If the line separator that is about te be removed // contains wrappers, remove the wrappers first. if (collapsed && replacements[index] && replacements[index].length) { - var newReplacements = replacements.slice(); + const newReplacements = replacements.slice(); newReplacements[index] = replacements[index].slice(0, -1); - newValue = remove_line_separator_objectSpread({}, value, { + newValue = { ...value, replacements: newReplacements - }); + }; } else { newValue = remove_remove(value, removeStart, removeEnd); } @@ -2520,56 +2279,57 @@ * Internal dependencies */ -var insert_object_OBJECT_REPLACEMENT_CHARACTER = "\uFFFC"; + +/** @typedef {import('./create').RichTextValue} RichTextValue */ + +/** @typedef {import('./create').RichTextFormat} RichTextFormat */ + /** * 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. * - * @param {Object} value Value to modify. - * @param {Object} formatToInsert Format to insert as object. - * @param {number} [startIndex] Start index. - * @param {number} [endIndex] End index. + * @param {RichTextValue} value Value to modify. + * @param {RichTextFormat} formatToInsert Format to insert as object. + * @param {number} [startIndex] Start index. + * @param {number} [endIndex] End index. * - * @return {Object} A new value with the object inserted. + * @return {RichTextValue} A new value with the object inserted. */ function insertObject(value, formatToInsert, startIndex, endIndex) { - var valueToInsert = { + const valueToInsert = { formats: [,], replacements: [formatToInsert], - text: insert_object_OBJECT_REPLACEMENT_CHARACTER + text: OBJECT_REPLACEMENT_CHARACTER }; return insert(value, valueToInsert, startIndex, endIndex); } // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/slice.js - - -function slice_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } - -function slice_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { slice_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { slice_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } +/** @typedef {import('./create').RichTextValue} RichTextValue */ /** * 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`. * - * @param {Object} value Value to modify. - * @param {number} [startIndex] Start index. - * @param {number} [endIndex] End index. + * @param {RichTextValue} value Value to modify. + * @param {number} [startIndex] Start index. + * @param {number} [endIndex] End index. * - * @return {Object} A new extracted value. + * @return {RichTextValue} A new extracted value. */ -function slice(value) { - var startIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : value.start; - var endIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : value.end; - var formats = value.formats, - replacements = value.replacements, - text = value.text; +function slice(value, startIndex = value.start, endIndex = value.end) { + const { + formats, + replacements, + text + } = value; if (startIndex === undefined || endIndex === undefined) { - return slice_objectSpread({}, value); + return { ...value + }; } return { @@ -2584,37 +2344,34 @@ * Internal dependencies */ +/** @typedef {import('./create').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 {Object} value - * @param {Object[]} value.formats - * @param {Object[]} value.replacements - * @param {string} value.text - * @param {number} value.start - * @param {number} value.end + * @param {RichTextValue} value * @param {number|string} [string] Start index, or string at which to split. * - * @return {Array} An array of new values. + * @return {Array|undefined} An array of new values. */ -function split(_ref, string) { - var formats = _ref.formats, - replacements = _ref.replacements, - text = _ref.text, - start = _ref.start, - end = _ref.end; - +function split({ + formats, + replacements, + text, + start, + end +}, string) { if (typeof string !== 'string') { - return splitAtSelection.apply(void 0, arguments); + return splitAtSelection(...arguments); } - var nextStart = 0; - return text.split(string).map(function (substring) { - var startIndex = nextStart; - var value = { + 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 @@ -2639,20 +2396,23 @@ }); } -function splitAtSelection(_ref2) { - var formats = _ref2.formats, - replacements = _ref2.replacements, - text = _ref2.text, - start = _ref2.start, - end = _ref2.end; - var startIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : start; - var endIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : end; - var before = { +function splitAtSelection({ + formats, + replacements, + text, + start, + end +}, startIndex = start, endIndex = end) { + if (start === undefined || end === undefined) { + return; + } + + const before = { formats: formats.slice(0, startIndex), replacements: replacements.slice(0, startIndex), text: text.slice(0, startIndex) }; - var after = { + const after = { formats: formats.slice(endIndex), replacements: replacements.slice(endIndex), text: text.slice(endIndex), @@ -2669,31 +2429,51 @@ */ /** + * Internal dependencies + */ + + +/** @typedef {import('./register-format-type').RichTextFormatType} RichTextFormatType */ + +/** * Returns a registered format type. * * @param {string} name Format name. * - * @return {?Object} Format type. + * @return {RichTextFormatType|undefined} Format type. */ function get_format_type_getFormatType(name) { - return Object(external_this_wp_data_["select"])('core/rich-text').getFormatType(name); + return Object(external_wp_data_["select"])(store).getFormatType(name); } // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/to-tree.js - - - -function to_tree_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } - -function to_tree_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { to_tree_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { to_tree_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } - /** * Internal dependencies */ + +function restoreOnAttributes(attributes, isEditableTree) { + if (isEditableTree) { + return attributes; + } + + const newAttributes = {}; + + for (const key in attributes) { + let newKey = key; + + if (key.startsWith('data-disable-rich-text-')) { + newKey = key.slice('data-disable-rich-text-'.length); + } + + newAttributes[newKey] = attributes[key]; + } + + return newAttributes; +} /** * Converts a format object to information that can be used to create an element * from (type, attributes and object). @@ -2703,22 +2483,27 @@ * @param {Object} $1.attributes The format attributes. * @param {Object} $1.unregisteredAttributes The unregistered format * attributes. - * @param {boolean} $1.object Wether or not it is an object + * @param {boolean} $1.object Whether or not it is an object * format. - * @param {boolean} $1.boundaryClass Wether or not to apply a boundary + * @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(_ref) { - var type = _ref.type, - attributes = _ref.attributes, - unregisteredAttributes = _ref.unregisteredAttributes, - object = _ref.object, - boundaryClass = _ref.boundaryClass; - var formatType = get_format_type_getFormatType(type); - var elementAttributes = {}; + +function fromFormat({ + type, + attributes, + unregisteredAttributes, + object, + boundaryClass, + isEditableTree +}) { + const formatType = get_format_type_getFormatType(type); + let elementAttributes = {}; if (boundaryClass) { elementAttributes['data-rich-text-format-boundary'] = 'true'; @@ -2726,20 +2511,24 @@ if (!formatType) { if (attributes) { - elementAttributes = to_tree_objectSpread({}, attributes, {}, elementAttributes); + elementAttributes = { ...attributes, + ...elementAttributes + }; } return { - type: type, - attributes: elementAttributes, - object: object + type, + attributes: restoreOnAttributes(elementAttributes, isEditableTree), + object }; } - elementAttributes = to_tree_objectSpread({}, unregisteredAttributes, {}, elementAttributes); - - for (var name in attributes) { - var key = formatType.attributes ? formatType.attributes[name] : false; + elementAttributes = { ...unregisteredAttributes, + ...elementAttributes + }; + + for (const name in attributes) { + const key = formatType.attributes ? formatType.attributes[name] : false; if (key) { elementAttributes[key] = attributes[name]; @@ -2750,7 +2539,7 @@ if (formatType.className) { if (elementAttributes.class) { - elementAttributes.class = "".concat(formatType.className, " ").concat(elementAttributes.class); + elementAttributes.class = `${formatType.className} ${elementAttributes.class}`; } else { elementAttributes.class = formatType.className; } @@ -2759,7 +2548,7 @@ return { type: formatType.tagName, object: formatType.object, - attributes: elementAttributes + attributes: restoreOnAttributes(elementAttributes, isEditableTree) }; } /** @@ -2781,37 +2570,40 @@ return true; } -function toTree(_ref2) { - var value = _ref2.value, - multilineTag = _ref2.multilineTag, - preserveWhiteSpace = _ref2.preserveWhiteSpace, - createEmpty = _ref2.createEmpty, - append = _ref2.append, - getLastChild = _ref2.getLastChild, - getParent = _ref2.getParent, - isText = _ref2.isText, - getText = _ref2.getText, - remove = _ref2.remove, - appendText = _ref2.appendText, - onStartIndex = _ref2.onStartIndex, - onEndIndex = _ref2.onEndIndex, - isEditableTree = _ref2.isEditableTree, - placeholder = _ref2.placeholder; - var formats = value.formats, - replacements = value.replacements, - text = value.text, - start = value.start, - end = value.end; - var formatsLength = formats.length + 1; - var tree = createEmpty(); - var multilineFormat = { +function toTree({ + value, + multilineTag, + preserveWhiteSpace, + 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 multilineFormat = { type: multilineTag }; - var activeFormats = getActiveFormats(value); - var deepestActiveFormat = activeFormats[activeFormats.length - 1]; - var lastSeparatorFormats; - var lastCharacterFormats; - var lastCharacter; // If we're building a multiline tree, start off with a multiline element. + const activeFormats = getActiveFormats(value); + const deepestActiveFormat = activeFormats[activeFormats.length - 1]; + let lastSeparatorFormats; + let lastCharacterFormats; + let lastCharacter; // If we're building a multiline tree, start off with a multiline element. if (multilineTag) { append(append(tree, { @@ -2822,29 +2614,29 @@ append(tree, ''); } - var _loop = function _loop(i) { - var character = text.charAt(i); - var shouldInsertPadding = isEditableTree && ( // Pad the line if the line is empty. + for (let i = 0; i < formatsLength; i++) { + const character = text.charAt(i); + const shouldInsertPadding = isEditableTree && ( // Pad the line if the line is empty. !lastCharacter || lastCharacter === LINE_SEPARATOR || // Pad the line if the previous character is a line break, otherwise // the line break won't be visible. lastCharacter === '\n'); - var characterFormats = formats[i]; // Set multiline tags in queue for building the tree. + let characterFormats = formats[i]; // Set multiline tags in queue for building the tree. if (multilineTag) { if (character === LINE_SEPARATOR) { - characterFormats = lastSeparatorFormats = (replacements[i] || []).reduce(function (accumulator, format) { + characterFormats = lastSeparatorFormats = (replacements[i] || []).reduce((accumulator, format) => { accumulator.push(format, multilineFormat); return accumulator; }, [multilineFormat]); } else { - characterFormats = [].concat(Object(toConsumableArray["a" /* default */])(lastSeparatorFormats), Object(toConsumableArray["a" /* default */])(characterFormats || [])); + characterFormats = [...lastSeparatorFormats, ...(characterFormats || [])]; } } - var pointer = getLastChild(tree); + let pointer = getLastChild(tree); if (shouldInsertPadding && character === LINE_SEPARATOR) { - var node = pointer; + let node = pointer; while (!isText(node)) { node = getLastChild(node); @@ -2855,23 +2647,23 @@ if (lastCharacter === LINE_SEPARATOR) { - var _node = pointer; - - while (!isText(_node)) { - _node = getLastChild(_node); + let node = pointer; + + while (!isText(node)) { + node = getLastChild(node); } if (onStartIndex && start === i) { - onStartIndex(tree, _node); + onStartIndex(tree, node); } if (onEndIndex && end === i) { - onEndIndex(tree, _node); + onEndIndex(tree, node); } } if (characterFormats) { - characterFormats.forEach(function (format, formatIndex) { + characterFormats.forEach((format, formatIndex) => { if (pointer && lastCharacterFormats && // Reuse the last element if all formats remain the same. isEqualUntil(characterFormats, lastCharacterFormats, formatIndex) && ( // Do not reuse the last element if the character is a // line separator. @@ -2880,16 +2672,19 @@ return; } - var type = format.type, - attributes = format.attributes, - unregisteredAttributes = format.unregisteredAttributes; - var boundaryClass = isEditableTree && character !== LINE_SEPARATOR && format === deepestActiveFormat; - var parent = getParent(pointer); - var newNode = append(parent, fromFormat({ - type: type, - attributes: attributes, - unregisteredAttributes: unregisteredAttributes, - boundaryClass: boundaryClass + const { + type, + attributes, + unregisteredAttributes + } = format; + const boundaryClass = isEditableTree && character !== LINE_SEPARATOR && format === deepestActiveFormat; + const parent = getParent(pointer); + const newNode = append(parent, fromFormat({ + type, + attributes, + unregisteredAttributes, + boundaryClass, + isEditableTree })); if (isText(pointer) && getText(pointer).length === 0) { @@ -2904,7 +2699,7 @@ if (character === LINE_SEPARATOR) { lastCharacterFormats = characterFormats; lastCharacter = character; - return "continue"; + continue; } // If there is selection at 0, handle it before characters are inserted. @@ -2919,9 +2714,21 @@ } if (character === OBJECT_REPLACEMENT_CHARACTER) { - pointer = append(getParent(pointer), fromFormat(to_tree_objectSpread({}, replacements[i], { - object: true - }))); // Ensure pointer is text node. + if (!isEditableTree && replacements[i].type === 'script') { + pointer = append(getParent(pointer), fromFormat({ + type: 'script', + isEditableTree + })); + append(pointer, { + html: decodeURIComponent(replacements[i].attributes['data-rich-text-script']) + }); + } else { + pointer = append(getParent(pointer), fromFormat({ ...replacements[i], + object: true, + isEditableTree + })); + } // Ensure pointer is text node. + pointer = append(getParent(pointer), ''); } else if (!preserveWhiteSpace && character === '\n') { @@ -2959,7 +2766,8 @@ // Necessary to prevent the placeholder from catching // selection. The placeholder is also not editable after // all. - contenteditable: 'false' + contenteditable: 'false', + style: 'pointer-events:none;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;' } }); } @@ -2967,30 +2775,19 @@ lastCharacterFormats = characterFormats; lastCharacter = character; - }; - - for (var i = 0; i < formatsLength; i++) { - var _ret = _loop(i); - - if (_ret === "continue") continue; } return tree; } // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/to-dom.js - - - -function to_dom_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } - -function to_dom_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { to_dom_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { to_dom_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } - /** * Internal dependencies */ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + /** * Creates a path as an array of indices from the given root node to the given * node. @@ -3003,14 +2800,14 @@ */ function createPathToNode(node, rootNode, path) { - var parentNode = node.parentNode; - var i = 0; + const parentNode = node.parentNode; + let i = 0; while (node = node.previousSibling) { i++; } - path = [i].concat(Object(toConsumableArray["a" /* default */])(path)); + path = [i, ...path]; if (parentNode !== rootNode) { path = createPathToNode(parentNode, rootNode, path); @@ -3029,14 +2826,14 @@ function getNodeByPath(node, path) { - path = Object(toConsumableArray["a" /* default */])(path); + path = [...path]; while (node && path.length > 1) { node = node.childNodes[path.shift()]; } return { - node: node, + node, offset: path[0] }; } @@ -3046,14 +2843,15 @@ child = element.ownerDocument.createTextNode(child); } - var _child = child, - type = _child.type, - attributes = _child.attributes; + const { + type, + attributes + } = child; if (type) { child = element.ownerDocument.createElement(type); - for (var key in attributes) { + for (const key in attributes) { child.setAttribute(key, attributes[key]); } } @@ -3065,13 +2863,15 @@ node.appendData(text); } -function to_dom_getLastChild(_ref) { - var lastChild = _ref.lastChild; +function to_dom_getLastChild({ + lastChild +}) { return lastChild; } -function to_dom_getParent(_ref2) { - var parentNode = _ref2.parentNode; +function to_dom_getParent({ + parentNode +}) { return parentNode; } @@ -3079,8 +2879,9 @@ return node.nodeType === node.TEXT_NODE; } -function to_dom_getText(_ref3) { - var nodeValue = _ref3.nodeValue; +function to_dom_getText({ + nodeValue +}) { return nodeValue; } @@ -3088,22 +2889,21 @@ return node.parentNode.removeChild(node); } -function toDom(_ref4) { - var value = _ref4.value, - multilineTag = _ref4.multilineTag, - prepareEditableTree = _ref4.prepareEditableTree, - _ref4$isEditableTree = _ref4.isEditableTree, - isEditableTree = _ref4$isEditableTree === void 0 ? true : _ref4$isEditableTree, - placeholder = _ref4.placeholder, - _ref4$doc = _ref4.doc, - doc = _ref4$doc === void 0 ? document : _ref4$doc; - var startPath = []; - var endPath = []; +function toDom({ + value, + multilineTag, + prepareEditableTree, + isEditableTree = true, + placeholder, + doc = document +}) { + let startPath = []; + let endPath = []; if (prepareEditableTree) { - value = to_dom_objectSpread({}, value, { + value = { ...value, formats: prepareEditableTree(value) - }); + }; } /** * Returns a new instance of a DOM tree upon which RichText operations can be @@ -3117,14 +2917,12 @@ */ - var createEmpty = function createEmpty() { - return createElement(doc, ''); - }; - - var tree = toTree({ - value: value, - multilineTag: multilineTag, - createEmpty: createEmpty, + const createEmpty = () => createElement(doc, ''); + + const tree = toTree({ + value, + multilineTag, + createEmpty, append: to_dom_append, getLastChild: to_dom_getLastChild, getParent: to_dom_getParent, @@ -3132,20 +2930,23 @@ getText: to_dom_getText, remove: to_dom_remove, appendText: to_dom_appendText, - onStartIndex: function onStartIndex(body, pointer) { + + onStartIndex(body, pointer) { startPath = createPathToNode(pointer, body, [pointer.nodeValue.length]); }, - onEndIndex: function onEndIndex(body, pointer) { + + onEndIndex(body, pointer) { endPath = createPathToNode(pointer, body, [pointer.nodeValue.length]); }, - isEditableTree: isEditableTree, - placeholder: placeholder + + isEditableTree, + placeholder }); return { body: tree, selection: { - startPath: startPath, - endPath: endPath + startPath, + endPath } }; } @@ -3154,32 +2955,34 @@ * the `Element` tree contained by `current`. If a `multilineTag` is provided, * text separated by two new lines will be wrapped in an `Element` of that type. * - * @param {Object} $1 Named arguments. - * @param {Object} $1.value Value to apply. - * @param {HTMLElement} $1.current The live root node to apply the element tree to. - * @param {string} [$1.multilineTag] Multiline tag. - * @param {Array} [$1.multilineWrapperTags] Tags where lines can be found if nesting is possible. + * @param {Object} $1 Named arguments. + * @param {RichTextValue} $1.value Value to apply. + * @param {HTMLElement} $1.current The live root node to apply the element tree to. + * @param {string} [$1.multilineTag] Multiline tag. + * @param {Function} [$1.prepareEditableTree] Function to filter editorable formats. + * @param {boolean} [$1.__unstableDomOnly] Only apply elements, no selection. + * @param {string} [$1.placeholder] Placeholder text. */ -function apply(_ref5) { - var value = _ref5.value, - current = _ref5.current, - multilineTag = _ref5.multilineTag, - prepareEditableTree = _ref5.prepareEditableTree, - __unstableDomOnly = _ref5.__unstableDomOnly, - placeholder = _ref5.placeholder; - +function apply({ + value, + current, + multilineTag, + prepareEditableTree, + __unstableDomOnly, + placeholder +}) { // Construct a new element tree in memory. - var _toDom = toDom({ - value: value, - multilineTag: multilineTag, - prepareEditableTree: prepareEditableTree, - placeholder: placeholder, + const { + body, + selection + } = toDom({ + value, + multilineTag, + prepareEditableTree, + placeholder, doc: current.ownerDocument - }), - body = _toDom.body, - selection = _toDom.selection; - + }); applyValue(body, current); if (value.start !== undefined && !__unstableDomOnly) { @@ -3187,11 +2990,11 @@ } } function applyValue(future, current) { - var i = 0; - var futureChild; + let i = 0; + let futureChild; while (futureChild = future.firstChild) { - var currentChild = current.childNodes[i]; + const currentChild = current.childNodes[i]; if (!currentChild) { current.appendChild(futureChild); @@ -3199,15 +3002,17 @@ if (currentChild.nodeName !== futureChild.nodeName || currentChild.nodeType === currentChild.TEXT_NODE && currentChild.data !== futureChild.data) { current.replaceChild(futureChild, currentChild); } else { - var currentAttributes = currentChild.attributes; - var futureAttributes = futureChild.attributes; + const currentAttributes = currentChild.attributes; + const futureAttributes = futureChild.attributes; if (currentAttributes) { - var ii = currentAttributes.length; // Reverse loop because `removeAttribute` on `currentChild` + let ii = currentAttributes.length; // Reverse loop because `removeAttribute` on `currentChild` // changes `currentAttributes`. while (ii--) { - var name = currentAttributes[ii].name; + const { + name + } = currentAttributes[ii]; if (!futureChild.getAttribute(name)) { currentChild.removeAttribute(name); @@ -3216,13 +3021,14 @@ } if (futureAttributes) { - for (var _ii = 0; _ii < futureAttributes.length; _ii++) { - var _futureAttributes$_ii = futureAttributes[_ii], - _name = _futureAttributes$_ii.name, - value = _futureAttributes$_ii.value; - - if (currentChild.getAttribute(_name) !== value) { - currentChild.setAttribute(_name, value); + for (let ii = 0; ii < futureAttributes.length; ii++) { + const { + name, + value + } = futureAttributes[ii]; + + if (currentChild.getAttribute(name) !== value) { + currentChild.setAttribute(name, value); } } } @@ -3256,25 +3062,31 @@ return a.startContainer === b.startContainer && a.startOffset === b.startOffset && a.endContainer === b.endContainer && a.endOffset === b.endOffset; } -function applySelection(_ref6, current) { - var startPath = _ref6.startPath, - endPath = _ref6.endPath; - - var _getNodeByPath = getNodeByPath(current, startPath), - startContainer = _getNodeByPath.node, - startOffset = _getNodeByPath.offset; - - var _getNodeByPath2 = getNodeByPath(current, endPath), - endContainer = _getNodeByPath2.node, - endOffset = _getNodeByPath2.offset; - - var ownerDocument = current.ownerDocument; - var defaultView = ownerDocument.defaultView; - var selection = defaultView.getSelection(); - var range = ownerDocument.createRange(); +function applySelection({ + startPath, + endPath +}, current) { + 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(); range.setStart(startContainer, startOffset); range.setEnd(endContainer, endOffset); - var activeElement = ownerDocument.activeElement; + const { + activeElement + } = ownerDocument; if (selection.rangeCount > 0) { // If the to be added range and the live range are the same, there's no @@ -3302,8 +3114,8 @@ } } -// EXTERNAL MODULE: external {"this":["wp","escapeHtml"]} -var external_this_wp_escapeHtml_ = __webpack_require__(89); +// EXTERNAL MODULE: external ["wp","escapeHtml"] +var external_wp_escapeHtml_ = __webpack_require__("Vx3V"); // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/to-html-string.js /** @@ -3315,27 +3127,30 @@ */ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + /** * Create an HTML string from a Rich Text value. If a `multilineTag` is * provided, text separated by a line separator will be wrapped in it. * - * @param {Object} $1 Named argements. - * @param {Object} $1.value Rich text value. - * @param {string} [$1.multilineTag] Multiline tag. - * @param {?boolean} [$1.preserveWhiteSpace] Whether or not to use newline - * characters for line breaks. + * @param {Object} $1 Named argements. + * @param {RichTextValue} $1.value Rich text value. + * @param {string} [$1.multilineTag] Multiline tag. + * @param {boolean} [$1.preserveWhiteSpace] Whether or not to use newline + * characters for line breaks. * * @return {string} HTML string. */ -function toHTMLString(_ref) { - var value = _ref.value, - multilineTag = _ref.multilineTag, - preserveWhiteSpace = _ref.preserveWhiteSpace; - var tree = toTree({ - value: value, - multilineTag: multilineTag, - preserveWhiteSpace: preserveWhiteSpace, +function toHTMLString({ + value, + multilineTag, + preserveWhiteSpace +}) { + const tree = toTree({ + value, + multilineTag, + preserveWhiteSpace, createEmpty: to_html_string_createEmpty, append: to_html_string_append, getLastChild: to_html_string_getLastChild, @@ -3352,8 +3167,9 @@ return {}; } -function to_html_string_getLastChild(_ref2) { - var children = _ref2.children; +function to_html_string_getLastChild({ + children +}) { return children && children[children.length - 1]; } @@ -3374,23 +3190,26 @@ object.text += text; } -function to_html_string_getParent(_ref3) { - var parent = _ref3.parent; +function to_html_string_getParent({ + parent +}) { return parent; } -function to_html_string_isText(_ref4) { - var text = _ref4.text; +function to_html_string_isText({ + text +}) { return typeof text === 'string'; } -function to_html_string_getText(_ref5) { - var text = _ref5.text; +function to_html_string_getText({ + text +}) { return text; } function to_html_string_remove(object) { - var index = object.parent.children.indexOf(object); + const index = object.parent.children.indexOf(object); if (index !== -1) { object.parent.children.splice(index, 1); @@ -3399,32 +3218,36 @@ return object; } -function createElementHTML(_ref6) { - var type = _ref6.type, - attributes = _ref6.attributes, - object = _ref6.object, - children = _ref6.children; - var attributeString = ''; - - for (var key in attributes) { - if (!Object(external_this_wp_escapeHtml_["isValidAttributeName"])(key)) { +function createElementHTML({ + type, + attributes, + object, + children +}) { + let attributeString = ''; + + for (const key in attributes) { + if (!Object(external_wp_escapeHtml_["isValidAttributeName"])(key)) { continue; } - attributeString += " ".concat(key, "=\"").concat(Object(external_this_wp_escapeHtml_["escapeAttribute"])(attributes[key]), "\""); + attributeString += ` ${key}="${Object(external_wp_escapeHtml_["escapeAttribute"])(attributes[key])}"`; } if (object) { - return "<".concat(type).concat(attributeString, ">"); + return `<${type}${attributeString}>`; } - return "<".concat(type).concat(attributeString, ">").concat(createChildrenHTML(children), ""); + return `<${type}${attributeString}>${createChildrenHTML(children)}`; } -function createChildrenHTML() { - var children = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; - return children.map(function (child) { - return child.text === undefined ? createElementHTML(child) : Object(external_this_wp_escapeHtml_["escapeEditableHTML"])(child.text); +function createChildrenHTML(children = []) { + return children.map(child => { + if (child.html !== undefined) { + return child.html; + } + + return child.text === undefined ? createElementHTML(child) : Object(external_wp_escapeHtml_["escapeEditableHTML"])(child.text); }).join(''); } @@ -3435,13 +3258,17 @@ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + +/** @typedef {import('./create').RichTextFormat} RichTextFormat */ + /** * Toggles a format object to a Rich Text value at the current selection. * - * @param {Object} value Value to modify. - * @param {Object} format Format to apply or remove. + * @param {RichTextValue} value Value to modify. + * @param {RichTextFormat} format Format to apply or remove. * - * @return {Object} A new value with the format applied or removed. + * @return {RichTextValue} A new value with the format applied or removed. */ function toggleFormat(value, format) { @@ -3457,26 +3284,32 @@ * WordPress dependencies */ -/** @typedef {import('./register-format-type').WPFormat} WPFormat */ +/** + * Internal dependencies + */ + + +/** @typedef {import('./register-format-type').RichTextFormatType} RichTextFormatType */ /** * Unregisters a format. * * @param {string} name Format name. * - * @return {WPFormat|undefined} The previous format value, if it has been successfully - * unregistered; otherwise `undefined`. + * @return {RichTextFormatType|undefined} The previous format value, if it has + * been successfully unregistered; + * otherwise `undefined`. */ function unregisterFormatType(name) { - var oldFormat = Object(external_this_wp_data_["select"])('core/rich-text').getFormatType(name); + const oldFormat = Object(external_wp_data_["select"])(store).getFormatType(name); if (!oldFormat) { - window.console.error("Format ".concat(name, " is not registered.")); + window.console.error(`Format ${name} is not registered.`); return; } - Object(external_this_wp_data_["dispatch"])('core/rich-text').removeFormatTypes(name); + Object(external_wp_data_["dispatch"])(store).removeFormatTypes(name); return oldFormat; } @@ -3485,25 +3318,29 @@ * Internal dependencies */ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + /** * Checks if the selected list item can be indented. * - * @param {Object} value Value to check. + * @param {RichTextValue} value Value to check. * * @return {boolean} Whether or not the selected list item can be indented. */ function canIndentListItems(value) { - var lineIndex = getLineIndex(value); // There is only one line, so the line cannot be indented. + const lineIndex = getLineIndex(value); // There is only one line, so the line cannot be indented. if (lineIndex === undefined) { return false; } - var replacements = value.replacements; - var previousLineIndex = getLineIndex(value, lineIndex); - var formatsAtLineIndex = replacements[lineIndex] || []; - var formatsAtPreviousLineIndex = replacements[previousLineIndex] || []; // If the indentation of the current line is greater than previous line, + const { + replacements + } = value; + const previousLineIndex = getLineIndex(value, lineIndex); + const formatsAtLineIndex = replacements[lineIndex] || []; + const formatsAtPreviousLineIndex = replacements[previousLineIndex] || []; // If the indentation of the current line is greater than previous line, // then the line cannot be furter indented. return formatsAtLineIndex.length <= formatsAtPreviousLineIndex.length; @@ -3514,55 +3351,59 @@ * Internal dependencies */ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + /** * Checks if the selected list item can be outdented. * - * @param {Object} value Value to check. + * @param {RichTextValue} value Value to check. * * @return {boolean} Whether or not the selected list item can be outdented. */ function canOutdentListItems(value) { - var replacements = value.replacements, - start = value.start; - var startingLineIndex = getLineIndex(value, start); + const { + replacements, + start + } = value; + const startingLineIndex = getLineIndex(value, start); return replacements[startingLineIndex] !== undefined; } // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/indent-list-items.js - - -function indent_list_items_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } - -function indent_list_items_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { indent_list_items_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { indent_list_items_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } - /** * Internal dependencies */ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + +/** @typedef {import('./create').RichTextFormat} RichTextFormat */ + /** * Gets the line index of the first previous list item with higher indentation. * - * @param {Object} value Value to search. - * @param {number} lineIndex Line index of the list item to compare with. + * @param {RichTextValue} value Value to search. + * @param {number} lineIndex Line index of the list item to compare + * with. * - * @return {boolean} The line index. + * @return {number|void} The line index. */ -function getTargetLevelLineIndex(_ref, lineIndex) { - var text = _ref.text, - replacements = _ref.replacements; - var startFormats = replacements[lineIndex] || []; - var index = lineIndex; +function getTargetLevelLineIndex({ + text, + replacements +}, lineIndex) { + const startFormats = replacements[lineIndex] || []; + let index = lineIndex; while (index-- >= 0) { if (text[index] !== LINE_SEPARATOR) { continue; } - var formatsAtIndex = replacements[index] || []; // Return the first line index that is one level higher. If the level is + const formatsAtIndex = replacements[index] || []; // Return the first line index that is one level higher. If the level is // lower or equal, there is no result. if (formatsAtIndex.length === startFormats.length + 1) { @@ -3575,10 +3416,10 @@ /** * Indents any selected list items if possible. * - * @param {Object} value Value to change. - * @param {Object} rootFormat Root format. + * @param {RichTextValue} value Value to change. + * @param {RichTextFormat} rootFormat Root format. * - * @return {Object} The changed value. + * @return {RichTextValue} The changed value. */ @@ -3587,15 +3428,17 @@ return value; } - var lineIndex = getLineIndex(value); - var previousLineIndex = getLineIndex(value, lineIndex); - var text = value.text, - replacements = value.replacements, - end = value.end; - var newFormats = replacements.slice(); - var targetLevelLineIndex = getTargetLevelLineIndex(value, lineIndex); - - for (var index = lineIndex; index < end; index++) { + const lineIndex = getLineIndex(value); + const previousLineIndex = getLineIndex(value, lineIndex); + const { + text, + replacements, + end + } = value; + const newFormats = replacements.slice(); + const targetLevelLineIndex = getTargetLevelLineIndex(value, lineIndex); + + for (let index = lineIndex; index < end; index++) { if (text[index] !== LINE_SEPARATOR) { continue; } // Get the previous list, and if there's a child list, take over the @@ -3603,19 +3446,18 @@ if (targetLevelLineIndex) { - var targetFormats = replacements[targetLevelLineIndex] || []; + const targetFormats = replacements[targetLevelLineIndex] || []; newFormats[index] = targetFormats.concat((newFormats[index] || []).slice(targetFormats.length - 1)); } else { - var _targetFormats = replacements[previousLineIndex] || []; - - var lastformat = _targetFormats[_targetFormats.length - 1] || rootFormat; - newFormats[index] = _targetFormats.concat([lastformat], (newFormats[index] || []).slice(_targetFormats.length)); + const targetFormats = replacements[previousLineIndex] || []; + const lastformat = targetFormats[targetFormats.length - 1] || rootFormat; + newFormats[index] = targetFormats.concat([lastformat], (newFormats[index] || []).slice(targetFormats.length)); } } - return indent_list_items_objectSpread({}, value, { + return { ...value, replacements: newFormats - }); + }; } // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-parent-line-index.js @@ -3623,29 +3465,32 @@ * Internal dependencies */ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + /** * Gets the index of the first parent list. To get the parent list formats, we * go through every list item until we find one with exactly one format type * less. * - * @param {Object} value Value to search. - * @param {number} lineIndex Line index of a child list item. + * @param {RichTextValue} value Value to search. + * @param {number} lineIndex Line index of a child list item. * - * @return {Array} The parent list line index. + * @return {number|void} The parent list line index. */ -function getParentLineIndex(_ref, lineIndex) { - var text = _ref.text, - replacements = _ref.replacements; - var startFormats = replacements[lineIndex] || []; - var index = lineIndex; +function getParentLineIndex({ + text, + replacements +}, lineIndex) { + const startFormats = replacements[lineIndex] || []; + let index = lineIndex; while (index-- >= 0) { if (text[index] !== LINE_SEPARATOR) { continue; } - var formatsAtIndex = replacements[index] || []; + const formatsAtIndex = replacements[index] || []; if (formatsAtIndex.length === startFormats.length - 1) { return index; @@ -3658,29 +3503,32 @@ * Internal dependencies */ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + /** * Gets the line index of the last child in the list. * - * @param {Object} value Value to search. - * @param {number} lineIndex Line index of a list item in the list. + * @param {RichTextValue} value Value to search. + * @param {number} lineIndex Line index of a list item in the list. * - * @return {Array} The index of the last child. + * @return {number} The index of the last child. */ -function getLastChildIndex(_ref, lineIndex) { - var text = _ref.text, - replacements = _ref.replacements; - var lineFormats = replacements[lineIndex] || []; // Use the given line index in case there are no next children. - - var childIndex = lineIndex; // `lineIndex` could be `undefined` if it's the first line. - - for (var index = lineIndex || 0; index < text.length; index++) { +function getLastChildIndex({ + text, + replacements +}, lineIndex) { + const lineFormats = replacements[lineIndex] || []; // Use the given line index in case there are no next children. + + let childIndex = lineIndex; // `lineIndex` could be `undefined` if it's the first line. + + for (let index = lineIndex || 0; index < text.length; index++) { // We're only interested in line indices. if (text[index] !== LINE_SEPARATOR) { continue; } - var formatsAtIndex = replacements[index] || []; // If the amout of formats is equal or more, store it, then return the + const formatsAtIndex = replacements[index] || []; // If the amout of formats is equal or more, store it, then return the // last one if the amount of formats is less. if (formatsAtIndex.length >= lineFormats.length) { @@ -3695,12 +3543,6 @@ } // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/outdent-list-items.js - - -function outdent_list_items_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } - -function outdent_list_items_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { outdent_list_items_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { outdent_list_items_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } - /** * Internal dependencies */ @@ -3709,12 +3551,14 @@ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + /** * Outdents any selected list items if possible. * - * @param {Object} value Value to change. + * @param {RichTextValue} value Value to change. * - * @return {Object} The changed value. + * @return {RichTextValue} The changed value. */ function outdentListItems(value) { @@ -3722,26 +3566,28 @@ return value; } - var text = value.text, - replacements = value.replacements, - start = value.start, - end = value.end; - var startingLineIndex = getLineIndex(value, start); - var newFormats = replacements.slice(0); - var parentFormats = replacements[getParentLineIndex(value, startingLineIndex)] || []; - var endingLineIndex = getLineIndex(value, end); - var lastChildIndex = getLastChildIndex(value, endingLineIndex); // Outdent all list items from the starting line index until the last child + const { + text, + replacements, + start, + end + } = value; + const startingLineIndex = getLineIndex(value, start); + const newFormats = replacements.slice(0); + const parentFormats = replacements[getParentLineIndex(value, startingLineIndex)] || []; + const endingLineIndex = getLineIndex(value, end); + const lastChildIndex = getLastChildIndex(value, endingLineIndex); // Outdent all list items from the starting line index until the last child // index of the ending list. All children of the ending list need to be // outdented, otherwise they'll be orphaned. - for (var index = startingLineIndex; index <= lastChildIndex; index++) { + for (let index = startingLineIndex; index <= lastChildIndex; index++) { // Skip indices that are not line separators. if (text[index] !== LINE_SEPARATOR) { continue; } // In the case of level 0, the formats at the index are undefined. - var currentFormats = newFormats[index] || []; // Omit the indentation level where the selection starts. + const currentFormats = newFormats[index] || []; // Omit the indentation level where the selection starts. newFormats[index] = parentFormats.concat(currentFormats.slice(parentFormats.length + 1)); @@ -3750,52 +3596,52 @@ } } - return outdent_list_items_objectSpread({}, value, { + return { ...value, replacements: newFormats - }); + }; } // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/change-list-type.js - - -function change_list_type_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } - -function change_list_type_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { change_list_type_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { change_list_type_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } - /** * Internal dependencies */ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + +/** @typedef {import('./create').RichTextFormat} RichTextFormat */ + /** * Changes the list type of the selected indented list, if any. Looks at the * currently selected list item and takes the parent list, then changes the list * type of this list. When multiple lines are selected, the parent lists are * takes and changed. * - * @param {Object} value Value to change. - * @param {Object} newFormat The new list format object. Choose between - * `{ type: 'ol' }` and `{ type: 'ul' }`. + * @param {RichTextValue} value Value to change. + * @param {RichTextFormat} newFormat The new list format object. Choose between + * `{ type: 'ol' }` and `{ type: 'ul' }`. * - * @return {Object} The changed value. + * @return {RichTextValue} The changed value. */ function changeListType(value, newFormat) { - var text = value.text, - replacements = value.replacements, - start = value.start, - end = value.end; - var startingLineIndex = getLineIndex(value, start); - var startLineFormats = replacements[startingLineIndex] || []; - var endLineFormats = replacements[getLineIndex(value, end)] || []; - var startIndex = getParentLineIndex(value, startingLineIndex); - var newReplacements = replacements.slice(); - var startCount = startLineFormats.length - 1; - var endCount = endLineFormats.length - 1; - var changed; - - for (var index = startIndex + 1 || 0; index < text.length; index++) { + const { + text, + replacements, + start, + end + } = value; + const startingLineIndex = getLineIndex(value, start); + const startLineFormats = replacements[startingLineIndex] || []; + const endLineFormats = replacements[getLineIndex(value, end)] || []; + const startIndex = getParentLineIndex(value, startingLineIndex); + const newReplacements = replacements.slice(); + const startCount = startLineFormats.length - 1; + const endCount = endLineFormats.length - 1; + let changed; + + for (let index = startIndex + 1 || 0; index < text.length; index++) { if (text[index] !== LINE_SEPARATOR) { continue; } @@ -3809,7 +3655,7 @@ } changed = true; - newReplacements[index] = newReplacements[index].map(function (format, i) { + newReplacements[index] = newReplacements[index].map((format, i) => { return i < startCount || i > endCount ? format : newFormat; }); } @@ -3818,35 +3664,207 @@ return value; } - return change_list_type_objectSpread({}, value, { + return { ...value, replacements: newReplacements - }); + }; +} + +// EXTERNAL MODULE: external ["wp","element"] +var external_wp_element_ = __webpack_require__("GRId"); + +// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-anchor-ref.js +/** + * WordPress dependencies + */ + +/** + * Internal dependencies + */ + + +/** @typedef {import('@wordpress/element').RefObject} RefObject */ + +/** @typedef {import('../register-format-type').RichTextFormatType} RichTextFormatType */ + +/** @typedef {import('../create').RichTextValue} RichTextValue */ + +/** + * This hook, to be used in a format type's Edit component, returns the active + * element that is formatted, or the selection range if no format is active. + * The returned value is meant to be used for positioning UI, e.g. by passing it + * to the `Popover` component. + * + * @param {Object} $1 Named parameters. + * @param {RefObject} $1.ref React ref of the element + * containing the editable content. + * @param {RichTextValue} $1.value Value to check for selection. + * @param {RichTextFormatType} $1.settings The format type's settings. + * + * @return {Element|Range} The active element or selection range. + */ + +function useAnchorRef({ + ref, + value, + settings = {} +}) { + const { + tagName, + className, + name + } = settings; + const activeFormat = name ? getActiveFormat(value, name) : undefined; + return Object(external_wp_element_["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; + } + + let element = range.startContainer; // If the caret is right before the element, select the next element. + + 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]); } -// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/extends.js -var esm_extends = __webpack_require__(8); - -// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/slicedToArray.js + 1 modules -var slicedToArray = __webpack_require__(14); - -// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/objectWithoutProperties.js -var objectWithoutProperties = __webpack_require__(15); - -// EXTERNAL MODULE: external {"this":["wp","element"]} -var external_this_wp_element_ = __webpack_require__(0); - -// EXTERNAL MODULE: ./node_modules/classnames/index.js -var classnames = __webpack_require__(11); -var classnames_default = /*#__PURE__*/__webpack_require__.n(classnames); - -// EXTERNAL MODULE: external {"this":["wp","keycodes"]} -var external_this_wp_keycodes_ = __webpack_require__(21); - -// EXTERNAL MODULE: external {"this":["wp","deprecated"]} -var external_this_wp_deprecated_ = __webpack_require__(37); -var external_this_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_this_wp_deprecated_); - -// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/format-edit.js +// EXTERNAL MODULE: external ["wp","compose"] +var external_wp_compose_ = __webpack_require__("K9lf"); + +// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-default-style.js +/** + * WordPress dependencies + */ + +/** + * 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. + * + * > 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. + * + * https://html.spec.whatwg.org/multipage/interaction.html#best-practices-for-in-page-editors + * + * @type {string} + */ + +const whiteSpace = 'pre-wrap'; +/** + * A minimum width of 1px will prevent the rich text container from collapsing + * to 0 width and hiding the caret. This is useful for inline containers. + */ + +const minWidth = '1px'; +function useDefaultStyle() { + return Object(external_wp_element_["useCallback"])(element => { + if (!element) return; + element.style.whiteSpace = whiteSpace; + element.style.minWidth = minWidth; + }, []); +} + +// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-boundary-style.js +/** + * WordPress dependencies + */ + +/* + * Calculates and renders the format boundary style when the active formats + * change. + */ + +function useBoundaryStyle({ + record +}) { + const ref = Object(external_wp_element_["useRef"])(); + const { + activeFormats = [] + } = record.current; + Object(external_wp_element_["useEffect"])(() => { + // There's no need to recalculate the boundary styles if no formats are + // active, because no boundary styles will be visible. + if (!activeFormats || !activeFormats.length) { + return; + } + + const boundarySelector = '*[data-rich-text-format-boundary]'; + const element = ref.current.querySelector(boundarySelector); + + if (!element) { + return; + } + + 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); + + if (!globalStyle) { + globalStyle = ownerDocument.createElement('style'); + globalStyle.id = globalStyleId; + ownerDocument.head.appendChild(globalStyle); + } + + if (globalStyle.innerHTML !== style) { + globalStyle.innerHTML = style; + } + }, [activeFormats]); + return ref; +} + +// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-inline-warning.js +/** + * WordPress dependencies + */ + +const message = 'RichText cannot be used with an inline container. Please use a different display property.'; +function useInlineWarning() { + const ref = Object(external_wp_element_["useRef"])(); + Object(external_wp_element_["useEffect"])(() => { + if (false) {} + }, []); + return ref; +} + +// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-copy-handler.js +/** + * WordPress dependencies + */ /** @@ -3854,52 +3872,275 @@ */ -/** - * Set of all interactive content tags. - * - * @see https://html.spec.whatwg.org/multipage/dom.html#interactive-content - */ - -var interactiveContentTags = new Set(['a', 'audio', 'button', 'details', 'embed', 'iframe', 'input', 'label', 'select', 'textarea', 'video']); -function FormatEdit(_ref) { - var formatTypes = _ref.formatTypes, - onChange = _ref.onChange, - onFocus = _ref.onFocus, - value = _ref.value, - allowedFormats = _ref.allowedFormats, - withoutInteractiveFormatting = _ref.withoutInteractiveFormatting; - return formatTypes.map(function (_ref2) { - var name = _ref2.name, - Edit = _ref2.edit, - tagName = _ref2.tagName; - - if (!Edit) { - return null; + + + +function useCopyHandler(props) { + const propsRef = Object(external_wp_element_["useRef"])(props); + propsRef.current = props; + return Object(external_wp_compose_["useRefEffect"])(element => { + function onCopy(event) { + const { + record, + multilineTag, + preserveWhiteSpace + } = propsRef.current; + + if (isCollapsed(record.current) || !element.contains(element.ownerDocument.activeElement)) { + return; + } + + const selectedRecord = slice(record.current); + const plainText = getTextContent(selectedRecord); + const html = toHTMLString({ + value: selectedRecord, + multilineTag, + preserveWhiteSpace + }); + event.clipboardData.setData('text/plain', plainText); + event.clipboardData.setData('text/html', html); + event.clipboardData.setData('rich-text', 'true'); + event.preventDefault(); } - if (allowedFormats && allowedFormats.indexOf(name) === -1) { - return null; - } - - if (withoutInteractiveFormatting && interactiveContentTags.has(tagName)) { - return null; + element.addEventListener('copy', onCopy); + return () => { + element.removeEventListener('copy', onCopy); + }; + }, []); +} + +// EXTERNAL MODULE: external ["wp","keycodes"] +var external_wp_keycodes_ = __webpack_require__("RxS6"); + +// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-format-boundaries.js +/** + * WordPress dependencies + */ + + + +/** + * Internal dependencies + */ + + +const EMPTY_ACTIVE_FORMATS = []; +function useFormatBoundaries(props) { + const [, forceRender] = Object(external_wp_element_["useReducer"])(() => ({})); + const propsRef = Object(external_wp_element_["useRef"])(props); + propsRef.current = props; + return Object(external_wp_compose_["useRefEffect"])(element => { + function onKeyDown(event) { + const { + keyCode, + shiftKey, + altKey, + metaKey, + ctrlKey + } = event; + + if ( // Only override left and right keys without modifiers pressed. + shiftKey || altKey || metaKey || ctrlKey || keyCode !== external_wp_keycodes_["LEFT"] && keyCode !== external_wp_keycodes_["RIGHT"]) { + return; + } + + const { + record, + applyRecord + } = propsRef.current; + const { + text, + formats, + start, + end, + activeFormats: currentActiveFormats = [] + } = record.current; + const collapsed = isCollapsed(record.current); + const { + ownerDocument + } = element; + const { + defaultView + } = ownerDocument; // To do: ideally, we should look at visual position instead. + + const { + direction + } = defaultView.getComputedStyle(element); + const reverseKey = direction === 'rtl' ? external_wp_keycodes_["RIGHT"] : external_wp_keycodes_["LEFT"]; + const isReverse = event.keyCode === reverseKey; // If the selection is collapsed and at the very start, do nothing if + // navigating backward. + // If the selection is collapsed and at the very end, do nothing if + // navigating forward. + + if (collapsed && currentActiveFormats.length === 0) { + if (start === 0 && isReverse) { + return; + } + + if (end === text.length && !isReverse) { + return; + } + } // If the selection is not collapsed, let the browser handle collapsing + // the selection for now. Later we could expand this logic to set + // boundary positions if needed. + + + if (!collapsed) { + return; + } + + const formatsBefore = formats[start - 1] || EMPTY_ACTIVE_FORMATS; + const formatsAfter = formats[start] || EMPTY_ACTIVE_FORMATS; + let newActiveFormatsLength = currentActiveFormats.length; + let source = formatsAfter; + + if (formatsBefore.length > formatsAfter.length) { + source = formatsBefore; + } // If the amount of formats before the caret and after the caret is + // different, the caret is at a format boundary. + + + if (formatsBefore.length < formatsAfter.length) { + if (!isReverse && currentActiveFormats.length < formatsAfter.length) { + newActiveFormatsLength++; + } + + if (isReverse && currentActiveFormats.length > formatsBefore.length) { + newActiveFormatsLength--; + } + } else if (formatsBefore.length > formatsAfter.length) { + if (!isReverse && currentActiveFormats.length > formatsAfter.length) { + newActiveFormatsLength--; + } + + if (isReverse && currentActiveFormats.length < formatsBefore.length) { + newActiveFormatsLength++; + } + } + + if (newActiveFormatsLength === currentActiveFormats.length) { + record.current._newActiveFormats = isReverse ? formatsBefore : formatsAfter; + return; + } + + event.preventDefault(); + const newActiveFormats = source.slice(0, newActiveFormatsLength); + const newValue = { ...record.current, + activeFormats: newActiveFormats + }; + record.current = newValue; + applyRecord(newValue); + forceRender(); } - var activeFormat = getActiveFormat(value, name); - var isActive = activeFormat !== undefined; - var activeObject = getActiveObject(value); - var isObjectActive = activeObject !== undefined && activeObject.type === name; - return Object(external_this_wp_element_["createElement"])(Edit, { - key: name, - isActive: isActive, - activeAttributes: isActive ? activeFormat.attributes || {} : {}, - isObjectActive: isObjectActive, - activeObjectAttributes: isObjectActive ? activeObject.attributes || {} : {}, - value: value, - onChange: onChange, - onFocus: onFocus - }); - }); + element.addEventListener('keydown', onKeyDown); + return () => { + element.removeEventListener('keydown', onKeyDown); + }; + }, []); +} + +// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-select-object.js +/** + * WordPress dependencies + */ + +function useSelectObject() { + return Object(external_wp_compose_["useRefEffect"])(element => { + function onClick(event) { + const { + target + } = event; // If the child element has no text content, it must be an object. + + if (target === element || target.textContent) { + return; + } + + const { + ownerDocument + } = target; + const { + defaultView + } = ownerDocument; + const range = ownerDocument.createRange(); + const selection = defaultView.getSelection(); + range.selectNode(target); + selection.removeAllRanges(); + selection.addRange(range); + } + + element.addEventListener('click', onClick); + return () => { + element.removeEventListener('click', onClick); + }; + }, []); +} + +// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-indent-list-item-on-space.js +/** + * WordPress dependencies + */ + + + +/** + * Internal dependencies + */ + + + + +function useIndentListItemOnSpace(props) { + const propsRef = Object(external_wp_element_["useRef"])(props); + propsRef.current = props; + return Object(external_wp_compose_["useRefEffect"])(element => { + function onKeyDown(event) { + const { + keyCode, + shiftKey, + altKey, + metaKey, + ctrlKey + } = event; + const { + multilineTag, + createRecord, + handleChange + } = propsRef.current; + + if ( // Only override when no modifiers are pressed. + shiftKey || altKey || metaKey || ctrlKey || keyCode !== external_wp_keycodes_["SPACE"] || multilineTag !== 'li') { + return; + } + + const currentValue = createRecord(); + + if (!isCollapsed(currentValue)) { + return; + } + + const { + text, + start + } = currentValue; + const characterBefore = text[start - 1]; // The caret must be at the start of a line. + + if (characterBefore && characterBefore !== LINE_SEPARATOR) { + return; + } + + handleChange(indentListItems(currentValue, { + type: element.tagName.toLowerCase() + })); + event.preventDefault(); + } + + element.addEventListener('keydown', onKeyDown); + return () => { + element.removeEventListener('keydown', onKeyDown); + }; + }, []); } // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/update-formats.js @@ -3907,29 +4148,32 @@ * Internal dependencies */ +/** @typedef {import('./create').RichTextValue} RichTextValue */ + /** * Efficiently updates all the formats from `start` (including) until `end` * (excluding) with the active formats. Mutates `value`. * - * @param {Object} $1 Named paramentes. - * @param {Object} $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. + * @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. * - * @return {Object} Mutated value. + * @return {RichTextValue} Mutated value. */ -function updateFormats(_ref) { - var value = _ref.value, - start = _ref.start, - end = _ref.end, - formats = _ref.formats; - var formatsBefore = value.formats[start - 1] || []; - var formatsAfter = value.formats[end] || []; // First, fix the references. If any format right before or after are +function updateFormats({ + value, + start, + end, + formats +}) { + const formatsBefore = value.formats[start - 1] || []; + const formatsAfter = value.formats[end] || []; // First, fix the references. If any format right before or after are // equal, the replacement format should use the same reference. - value.activeFormats = formats.map(function (format, index) { + value.activeFormats = formats.map((format, index) => { if (formatsBefore[index]) { if (isFormatEqual(format, formatsBefore[index])) { return formatsBefore[index]; @@ -3954,226 +4198,18 @@ return value; } -// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/with-format-types.js - - - - -function with_format_types_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } - -function with_format_types_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { with_format_types_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { with_format_types_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } - -/** - * External dependencies - */ - +// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-input-and-selection.js /** * WordPress dependencies */ - - -function formatTypesSelector(select) { - return select('core/rich-text').getFormatTypes(); -} -/** - * This higher-order component provides RichText with the `formatTypes` prop - * and its derived props from experimental format type settings. - * - * @param {WPComponent} RichText The rich text component to add props for. - * - * @return {WPComponent} New enhanced component. - */ - - -function withFormatTypes(RichText) { - return function WithFormatTypes(props) { - var clientId = props.clientId, - identifier = props.identifier; - var formatTypes = Object(external_this_wp_data_["useSelect"])(formatTypesSelector, []); - var selectProps = Object(external_this_wp_data_["useSelect"])(function (select) { - return formatTypes.reduce(function (acc, settings) { - if (!settings.__experimentalGetPropsForEditableTreePreparation) { - return acc; - } - - var selectPrefix = "format_prepare_props_(".concat(settings.name, ")_"); - return with_format_types_objectSpread({}, acc, {}, Object(external_this_lodash_["mapKeys"])(settings.__experimentalGetPropsForEditableTreePreparation(select, { - richTextIdentifier: identifier, - blockClientId: clientId - }), function (value, key) { - return selectPrefix + key; - })); - }, {}); - }, [formatTypes, clientId, identifier]); - - var dispatchProps = Object(external_this_wp_data_["__unstableUseDispatchWithMap"])(function (dispatch) { - return formatTypes.reduce(function (acc, settings) { - if (!settings.__experimentalGetPropsForEditableTreeChangeHandler) { - return acc; - } - - var dispatchPrefix = "format_on_change_props_(".concat(settings.name, ")_"); - return with_format_types_objectSpread({}, acc, {}, Object(external_this_lodash_["mapKeys"])(settings.__experimentalGetPropsForEditableTreeChangeHandler(dispatch, { - richTextIdentifier: identifier, - blockClientId: clientId - }), function (value, key) { - return dispatchPrefix + key; - })); - }, {}); - }, [formatTypes, clientId, identifier]); - - var newProps = Object(external_this_wp_element_["useMemo"])(function () { - return formatTypes.reduce(function (acc, settings) { - if (!settings.__experimentalCreatePrepareEditableTree) { - return acc; - } - - var args = { - richTextIdentifier: identifier, - blockClientId: clientId - }; - - var combined = with_format_types_objectSpread({}, selectProps, {}, dispatchProps); - - var name = settings.name; - var selectPrefix = "format_prepare_props_(".concat(name, ")_"); - var dispatchPrefix = "format_on_change_props_(".concat(name, ")_"); - var propsByPrefix = Object.keys(combined).reduce(function (accumulator, key) { - if (key.startsWith(selectPrefix)) { - accumulator[key.slice(selectPrefix.length)] = combined[key]; - } - - if (key.startsWith(dispatchPrefix)) { - accumulator[key.slice(dispatchPrefix.length)] = combined[key]; - } - - return accumulator; - }, {}); - - if (settings.__experimentalCreateOnChangeEditableValue) { - var _objectSpread2; - - return with_format_types_objectSpread({}, acc, (_objectSpread2 = {}, Object(defineProperty["a" /* default */])(_objectSpread2, "format_value_functions_(".concat(name, ")"), settings.__experimentalCreatePrepareEditableTree(propsByPrefix, args)), Object(defineProperty["a" /* default */])(_objectSpread2, "format_on_change_functions_(".concat(name, ")"), settings.__experimentalCreateOnChangeEditableValue(propsByPrefix, args)), _objectSpread2)); - } - - return with_format_types_objectSpread({}, acc, Object(defineProperty["a" /* default */])({}, "format_prepare_functions_(".concat(name, ")"), settings.__experimentalCreatePrepareEditableTree(propsByPrefix, args))); - }, {}); - }, [formatTypes, clientId, identifier, selectProps, dispatchProps]); - return Object(external_this_wp_element_["createElement"])(RichText, Object(esm_extends["a" /* default */])({}, props, selectProps, newProps, { - formatTypes: formatTypes - })); - }; -} - -// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-boundary-style.js -/** - * WordPress dependencies - */ - -/** - * Calculates and renders the format boundary style when the active formats - * change. - */ - -function useBoundaryStyle(_ref) { - var activeFormats = _ref.activeFormats, - ref = _ref.ref; - Object(external_this_wp_element_["useEffect"])(function () { - // There's no need to recalculate the boundary styles if no formats are - // active, because no boundary styles will be visible. - if (!activeFormats || !activeFormats.length) { - return; - } - - var boundarySelector = '*[data-rich-text-format-boundary]'; - var element = ref.current.querySelector(boundarySelector); - - if (!element) { - return; - } - - var ownerDocument = element.ownerDocument; - var defaultView = ownerDocument.defaultView; - var computedStyle = defaultView.getComputedStyle(element); - var newColor = computedStyle.color.replace(')', ', 0.2)').replace('rgb', 'rgba'); - var selector = ".rich-text:focus ".concat(boundarySelector); - var rule = "background-color: ".concat(newColor); - var style = "".concat(selector, " {").concat(rule, "}"); - var globalStyleId = 'rich-text-boundary-style'; - var globalStyle = ownerDocument.getElementById(globalStyleId); - - if (!globalStyle) { - globalStyle = ownerDocument.createElement('style'); - globalStyle.id = globalStyleId; - ownerDocument.head.appendChild(globalStyle); - } - - if (globalStyle.innerHTML !== style) { - globalStyle.innerHTML = style; - } - }, [activeFormats]); -} - -// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-inline-warning.js -/** - * WordPress dependencies - */ - -function useInlineWarning(_ref) { - var ref = _ref.ref; - Object(external_this_wp_element_["useEffect"])(function () { - if (false) { var computedStyle, defaultView, target; } - }, []); -} - -// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/index.js - - - - - - -function component_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } - -function component_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { component_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { component_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } - -/** - * External dependencies - */ - - -/** - * WordPress dependencies - */ - - - - /** * Internal dependencies */ - - - - - - - - - - - - - - - -/** @typedef {import('@wordpress/element').WPSyntheticEvent} WPSyntheticEvent */ - /** * All inserting input types that would insert HTML into the DOM. * @@ -4182,54 +4218,8 @@ * @type {Set} */ -var INSERTION_INPUT_TYPES_TO_IGNORE = new Set(['insertParagraph', 'insertOrderedList', 'insertUnorderedList', 'insertHorizontalRule', 'insertLink']); -/** - * 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. - * - * > 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. - * - * https://html.spec.whatwg.org/multipage/interaction.html#best-practices-for-in-page-editors - * - * @type {string} - */ - -var whiteSpace = 'pre-wrap'; -/** - * Default style object for the editable element. - * - * @type {Object} - */ - -var defaultStyle = { - whiteSpace: whiteSpace -}; -var EMPTY_ACTIVE_FORMATS = []; - -function createPrepareEditableTree(props, prefix) { - var fns = Object.keys(props).reduce(function (accumulator, key) { - if (key.startsWith(prefix)) { - accumulator.push(props[key]); - } - - return accumulator; - }, []); - return function (value) { - return fns.reduce(function (accumulator, fn) { - return fn(accumulator, value.text); - }, value.formats); - }; -} +const INSERTION_INPUT_TYPES_TO_IGNORE = new Set(['insertParagraph', 'insertOrderedList', 'insertUnorderedList', 'insertHorizontalRule', 'insertLink']); +const use_input_and_selection_EMPTY_ACTIVE_FORMATS = []; /** * If the selection is set on the placeholder element, collapse the selection to * the start (before the placeholder). @@ -4237,17 +4227,18 @@ * @param {Window} defaultView */ - function fixPlaceholderSelection(defaultView) { - var selection = defaultView.getSelection(); - var anchorNode = selection.anchorNode, - anchorOffset = selection.anchorOffset; + const selection = defaultView.getSelection(); + const { + anchorNode, + anchorOffset + } = selection; if (anchorNode.nodeType !== anchorNode.ELEMENT_NODE) { return; } - var targetNode = anchorNode.childNodes[anchorOffset]; + const targetNode = anchorNode.childNodes[anchorOffset]; if (!targetNode || targetNode.nodeType !== targetNode.ELEMENT_NODE || !targetNode.getAttribute('data-rich-text-placeholder')) { return; @@ -4256,1094 +4247,593 @@ selection.collapseToStart(); } -function component_RichText(_ref) { - var _ref$tagName = _ref.tagName, - TagName = _ref$tagName === void 0 ? 'div' : _ref$tagName, - _ref$value = _ref.value, - value = _ref$value === void 0 ? '' : _ref$value, - selectionStart = _ref.selectionStart, - selectionEnd = _ref.selectionEnd, - children = _ref.children, - allowedFormats = _ref.allowedFormats, - withoutInteractiveFormatting = _ref.withoutInteractiveFormatting, - formatTypes = _ref.formatTypes, - style = _ref.style, - className = _ref.className, - placeholder = _ref.placeholder, - disabled = _ref.disabled, - preserveWhiteSpace = _ref.preserveWhiteSpace, - onPaste = _ref.onPaste, - _ref$format = _ref.format, - format = _ref$format === void 0 ? 'string' : _ref$format, - onDelete = _ref.onDelete, - onEnter = _ref.onEnter, - onSelectionChange = _ref.onSelectionChange, - onChange = _ref.onChange, - onFocus = _ref.unstableOnFocus, - setFocusedElement = _ref.setFocusedElement, - instanceId = _ref.instanceId, - multilineTag = _ref.__unstableMultilineTag, - multilineRootTag = _ref.__unstableMultilineRootTag, - disableFormats = _ref.__unstableDisableFormats, - didAutomaticChange = _ref.__unstableDidAutomaticChange, - inputRule = _ref.__unstableInputRule, - markAutomaticChange = _ref.__unstableMarkAutomaticChange, - allowPrefixTransformations = _ref.__unstableAllowPrefixTransformations, - undo = _ref.__unstableUndo, - isCaretWithinFormattedText = _ref.__unstableIsCaretWithinFormattedText, - onEnterFormattedText = _ref.__unstableOnEnterFormattedText, - onExitFormattedText = _ref.__unstableOnExitFormattedText, - onCreateUndoLevel = _ref.__unstableOnCreateUndoLevel, - isSelected = _ref.__unstableIsSelected, - ref = _ref.forwardedRef, - remainingProps = Object(objectWithoutProperties["a" /* default */])(_ref, ["tagName", "value", "selectionStart", "selectionEnd", "children", "allowedFormats", "withoutInteractiveFormatting", "formatTypes", "style", "className", "placeholder", "disabled", "preserveWhiteSpace", "onPaste", "format", "onDelete", "onEnter", "onSelectionChange", "onChange", "unstableOnFocus", "setFocusedElement", "instanceId", "__unstableMultilineTag", "__unstableMultilineRootTag", "__unstableDisableFormats", "__unstableDidAutomaticChange", "__unstableInputRule", "__unstableMarkAutomaticChange", "__unstableAllowPrefixTransformations", "__unstableUndo", "__unstableIsCaretWithinFormattedText", "__unstableOnEnterFormattedText", "__unstableOnExitFormattedText", "__unstableOnCreateUndoLevel", "__unstableIsSelected", "forwardedRef"]); - - var _useState = Object(external_this_wp_element_["useState"])(), - _useState2 = Object(slicedToArray["a" /* default */])(_useState, 2), - _useState2$ = _useState2[0], - activeFormats = _useState2$ === void 0 ? [] : _useState2$, - setActiveFormats = _useState2[1]; // For backward compatibility, fall back to tagName if it's a string. - // tagName can now be a component for light blocks. - - - if (!multilineRootTag && typeof TagName === 'string') { - multilineRootTag = TagName; - } - - function getDoc() { - return ref.current.ownerDocument; - } - - function getWin() { - return getDoc().defaultView; - } - /** - * Converts the outside data structure to our internal representation. - * - * @param {*} string The outside value, data type depends on props. - * - * @return {Object} An internal rich-text value. - */ - - - function formatToValue(string) { - if (disableFormats) { - return { - text: string, - formats: Array(string.length), - replacements: Array(string.length) - }; - } - - if (format !== 'string') { - return string; +function useInputAndSelection(props) { + const propsRef = Object(external_wp_element_["useRef"])(props); + propsRef.current = props; + return Object(external_wp_compose_["useRefEffect"])(element => { + const { + ownerDocument + } = element; + const { + defaultView + } = ownerDocument; + let isComposing = false; + let rafId; + + function onInput(event) { + // Do not trigger a change if characters are being composed. + // Browsers will usually emit a final `input` event when the + // characters are composed. + // As of December 2019, Safari doesn't support + // nativeEvent.isComposing. + if (isComposing) { + return; + } + + let inputType; + + if (event) { + inputType = event.inputType; + } + + const { + record, + applyRecord, + createRecord, + handleChange + } = propsRef.current; // The browser formatted something or tried to insert HTML. + // Overwrite it. It will be handled later by the format library if + // needed. + + if (inputType && (inputType.indexOf('format') === 0 || INSERTION_INPUT_TYPES_TO_IGNORE.has(inputType))) { + applyRecord(record.current); + return; + } + + const currentValue = createRecord(); + const { + start, + activeFormats: oldActiveFormats = [] + } = record.current; // Update the formats between the last and new caret position. + + const change = updateFormats({ + value: currentValue, + start, + end: currentValue.start, + formats: oldActiveFormats + }); + handleChange(change); } - - var prepare = createPrepareEditableTree(remainingProps, 'format_value_functions'); - var result = create({ - html: string, - multilineTag: multilineTag, - multilineWrapperTags: multilineTag === 'li' ? ['ul', 'ol'] : undefined, - preserveWhiteSpace: preserveWhiteSpace - }); - result.formats = prepare(result); - return result; - } - /** - * Removes editor only formats from the value. - * - * Editor only formats are applied using `prepareEditableTree`, so we need to - * remove them before converting the internal state - * - * @param {Object} val The internal rich-text value. - * - * @return {Object} A new rich-text value. - */ - - - function removeEditorOnlyFormats(val) { - formatTypes.forEach(function (formatType) { - // Remove formats created by prepareEditableTree, because they are editor only. - if (formatType.__experimentalCreatePrepareEditableTree) { - val = removeFormat(val, formatType.name, 0, val.text.length); + /** + * Syncs the selection to local state. A callback for the `selectionchange` + * native events, `keyup`, `mouseup` and `touchend` synthetic events, and + * animation frames after the `focus` event. + * + * @param {Event|DOMHighResTimeStamp} event + */ + + + function handleSelectionChange(event) { + if (ownerDocument.activeElement !== element) { + return; } - }); - return val; - } - /** - * Converts the internal value to the external data format. - * - * @param {Object} val The internal rich-text value. - * - * @return {*} The external data format, data type depends on props. - */ - - - function valueToFormat(val) { - if (disableFormats) { - return val.text; - } - - val = removeEditorOnlyFormats(val); - - if (format !== 'string') { - return; - } - - return toHTMLString({ - value: val, - multilineTag: multilineTag, - preserveWhiteSpace: preserveWhiteSpace - }); - } // Internal values are updated synchronously, unlike props and state. - - - var _value = Object(external_this_wp_element_["useRef"])(value); - - var record = Object(external_this_wp_element_["useRef"])(Object(external_this_wp_element_["useMemo"])(function () { - var initialRecord = formatToValue(value); - initialRecord.start = selectionStart; - initialRecord.end = selectionEnd; - return initialRecord; - }, [])); - - function createRecord() { - var selection = getWin().getSelection(); - var range = selection.rangeCount > 0 ? selection.getRangeAt(0) : null; - return create({ - element: ref.current, - range: range, - multilineTag: multilineTag, - multilineWrapperTags: multilineTag === 'li' ? ['ul', 'ol'] : undefined, - __unstableIsEditableTree: true, - preserveWhiteSpace: preserveWhiteSpace - }); - } - - function applyRecord(newRecord) { - var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - domOnly = _ref2.domOnly; - - apply({ - value: newRecord, - current: ref.current, - multilineTag: multilineTag, - multilineWrapperTags: multilineTag === 'li' ? ['ul', 'ol'] : undefined, - prepareEditableTree: createPrepareEditableTree(remainingProps, 'format_prepare_functions'), - __unstableDomOnly: domOnly, - placeholder: placeholder - }); - } - /** - * Handles a paste event. - * - * Saves the pasted data as plain text in `pastedPlainText`. - * - * @param {ClipboardEvent} event The paste event. - */ - - - function handlePaste(event) { - if (!isSelected) { - event.preventDefault(); - return; - } - - var clipboardData = event.clipboardData; - var items = clipboardData.items, - files = clipboardData.files; // In Edge these properties can be null instead of undefined, so a more - // rigorous test is required over using default values. - - items = Object(external_this_lodash_["isNil"])(items) ? [] : items; - files = Object(external_this_lodash_["isNil"])(files) ? [] : files; - var plainText = ''; - var html = ''; // IE11 only supports `Text` as an argument for `getData` and will - // otherwise throw an invalid argument error, so we try the standard - // arguments first, then fallback to `Text` if they fail. - - try { - plainText = clipboardData.getData('text/plain'); - html = clipboardData.getData('text/html'); - } catch (error1) { - try { - html = clipboardData.getData('Text'); - } catch (error2) { - // Some browsers like UC Browser paste plain text by default and - // don't support clipboardData at all, so allow default - // behaviour. + + const { + record, + applyRecord, + createRecord, + isSelected, + onSelectionChange + } = propsRef.current; + + if (event.type !== 'selectionchange' && !isSelected) { + return; + } // Check if the implementor disabled editing. `contentEditable` + // does disable input, but not text selection, so we must ignore + // selection changes. + + + if (element.contentEditable !== 'true') { + return; + } // In case of a keyboard event, ignore selection changes during + // composition. + + + if (isComposing) { + return; + } + + const { + start, + end, + text + } = createRecord(); + const oldRecord = record.current; // Fallback mechanism for IE11, which doesn't support the input event. + // Any input results in a selection change. + + 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; } - } - - event.preventDefault(); // Allows us to ask for this information when we get a report. - - window.console.log('Received HTML:\n\n', html); - window.console.log('Received plain text:\n\n', plainText); - - if (disableFormats) { - handleChange(insert(record.current, plainText)); - return; - } - - var transformed = formatTypes.reduce(function (accumlator, _ref3) { - var __unstablePasteRule = _ref3.__unstablePasteRule; - - // Only allow one transform. - if (__unstablePasteRule && accumlator === record.current) { - accumlator = __unstablePasteRule(record.current, { - html: html, - plainText: plainText - }); - } - - return accumlator; - }, record.current); - - if (transformed !== record.current) { - handleChange(transformed); - return; - } - - if (onPaste) { - files = Array.from(files); - Array.from(items).forEach(function (item) { - if (!item.getAsFile) { - return; - } - - var file = item.getAsFile(); - - if (!file) { - return; - } - - var name = file.name, - type = file.type, - size = file.size; - - if (!Object(external_this_lodash_["find"])(files, { - name: name, - type: type, - size: size - })) { - files.push(file); - } + + const newValue = { ...oldRecord, + start, + end, + // _newActiveFormats may be set on arrow key navigation to control + // the right boundary position. If undefined, getActiveFormats will + // give the active formats according to the browser. + activeFormats: oldRecord._newActiveFormats, + _newActiveFormats: undefined + }; + const newActiveFormats = getActiveFormats(newValue, use_input_and_selection_EMPTY_ACTIVE_FORMATS); // Update the value with the new active formats. + + newValue.activeFormats = newActiveFormats; // It is important that the internal value is updated first, + // otherwise the value will be wrong on render! + + record.current = newValue; + applyRecord(newValue, { + domOnly: true }); - onPaste({ - value: removeEditorOnlyFormats(record.current), - onChange: handleChange, - html: html, - plainText: plainText, - files: files, - activeFormats: activeFormats - }); + onSelectionChange(start, end); + } + + function onCompositionStart() { + isComposing = true; // Do not update the selection when characters are being composed as + // this rerenders the component and might distroy internal browser + // editing state. + + ownerDocument.removeEventListener('selectionchange', handleSelectionChange); + } + + function onCompositionEnd() { + isComposing = false; // Ensure the value is up-to-date for browsers that don't emit a final + // input event after composition. + + onInput({ + inputType: 'insertText' + }); // Tracking selection changes can be resumed. + + ownerDocument.addEventListener('selectionchange', handleSelectionChange); } - } - /** - * Handles delete on keydown: - * - outdent list items, - * - delete content if everything is selected, - * - trigger the onDelete prop when selection is uncollapsed and at an edge. - * - * @param {WPSyntheticEvent} event A synthetic keyboard event. - */ - - - function handleDelete(event) { - var keyCode = event.keyCode; - - if (keyCode !== external_this_wp_keycodes_["DELETE"] && keyCode !== external_this_wp_keycodes_["BACKSPACE"] && keyCode !== external_this_wp_keycodes_["ESCAPE"]) { - return; + + function onFocus() { + const { + record, + isSelected, + onSelectionChange + } = propsRef.current; + + if (!isSelected) { + // We know for certain that on focus, the old selection is invalid. + // It will be recalculated on the next mouseup, keyup, or touchend + // event. + const index = undefined; + record.current = { ...record.current, + start: index, + end: index, + activeFormats: use_input_and_selection_EMPTY_ACTIVE_FORMATS + }; + onSelectionChange(index, index); + } else { + onSelectionChange(record.current.start, record.current.end); + } // Update selection as soon as possible, which is at the next animation + // frame. The event listener for selection changes may be added too late + // at this point, but this focus event is still too early to calculate + // the selection. + + + rafId = defaultView.requestAnimationFrame(handleSelectionChange); + ownerDocument.addEventListener('selectionchange', handleSelectionChange); + } + + function onBlur() { + ownerDocument.removeEventListener('selectionchange', handleSelectionChange); } - if (didAutomaticChange) { - event.preventDefault(); - undo(); - return; - } - - if (keyCode === external_this_wp_keycodes_["ESCAPE"]) { - return; - } - - var currentValue = createRecord(); - var start = currentValue.start, - end = currentValue.end, - text = currentValue.text; - var isReverse = keyCode === external_this_wp_keycodes_["BACKSPACE"]; // Always handle full content deletion ourselves. - - if (start === 0 && end !== 0 && end === text.length) { - handleChange(remove_remove(currentValue)); - event.preventDefault(); - return; - } - - if (multilineTag) { - var newValue; // Check to see if we should remove the first item if empty. - - if (isReverse && currentValue.start === 0 && currentValue.end === 0 && isEmptyLine(currentValue)) { - newValue = removeLineSeparator(currentValue, !isReverse); - } else { - newValue = removeLineSeparator(currentValue, isReverse); + element.addEventListener('input', onInput); + element.addEventListener('compositionstart', onCompositionStart); + element.addEventListener('compositionend', onCompositionEnd); + element.addEventListener('focus', onFocus); + element.addEventListener('blur', onBlur); // Selection updates must be done at these events as they + // happen before the `selectionchange` event. In some cases, + // the `selectionchange` event may not even fire, for + // example when the window receives focus again on click. + + element.addEventListener('keyup', handleSelectionChange); + element.addEventListener('mouseup', handleSelectionChange); + element.addEventListener('touchend', handleSelectionChange); + return () => { + element.removeEventListener('input', onInput); + element.removeEventListener('compositionstart', onCompositionStart); + element.removeEventListener('compositionend', onCompositionEnd); + element.removeEventListener('focus', onFocus); + element.removeEventListener('blur', onBlur); + element.removeEventListener('keyup', handleSelectionChange); + element.removeEventListener('mouseup', handleSelectionChange); + element.removeEventListener('touchend', handleSelectionChange); + ownerDocument.removeEventListener('selectionchange', handleSelectionChange); + defaultView.cancelAnimationFrame(rafId); + }; + }, []); +} + +// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-delete.js +/** + * WordPress dependencies + */ + + + +/** + * Internal dependencies + */ + + + + +function useDelete(props) { + const propsRef = Object(external_wp_element_["useRef"])(props); + propsRef.current = props; + return Object(external_wp_compose_["useRefEffect"])(element => { + function onKeyDown(event) { + const { + keyCode + } = event; + const { + createRecord, + handleChange, + multilineTag + } = propsRef.current; + + if (event.defaultPrevented) { + return; } - if (newValue) { - handleChange(newValue); + if (keyCode !== external_wp_keycodes_["DELETE"] && keyCode !== external_wp_keycodes_["BACKSPACE"]) { + return; + } + + const currentValue = createRecord(); + const { + start, + end, + text + } = currentValue; + const isReverse = keyCode === external_wp_keycodes_["BACKSPACE"]; // Always handle full content deletion ourselves. + + if (start === 0 && end !== 0 && end === text.length) { + handleChange(remove_remove(currentValue)); event.preventDefault(); return; } - } // Only process delete if the key press occurs at an uncollapsed edge. - - - if (!onDelete || !isCollapsed(currentValue) || activeFormats.length || isReverse && start !== 0 || !isReverse && end !== text.length) { - return; - } - - onDelete({ - isReverse: isReverse, - value: currentValue - }); - event.preventDefault(); - } - /** - * Triggers the `onEnter` prop on keydown. - * - * @param {WPSyntheticEvent} event A synthetic keyboard event. - */ - - - function handleEnter(event) { - if (event.keyCode !== external_this_wp_keycodes_["ENTER"]) { - return; - } - - event.preventDefault(); - - if (!onEnter) { - return; - } - - onEnter({ - value: removeEditorOnlyFormats(createRecord()), - onChange: handleChange, - shiftKey: event.shiftKey - }); - } - /** - * Indents list items on space keydown. - * - * @param {WPSyntheticEvent} event A synthetic keyboard event. - */ - - - function handleSpace(event) { - var keyCode = event.keyCode, - shiftKey = event.shiftKey, - altKey = event.altKey, - metaKey = event.metaKey, - ctrlKey = event.ctrlKey; - - if ( // Only override when no modifiers are pressed. - shiftKey || altKey || metaKey || ctrlKey || keyCode !== external_this_wp_keycodes_["SPACE"] || multilineTag !== 'li') { - return; - } - - var currentValue = createRecord(); - - if (!isCollapsed(currentValue)) { - return; - } - - var text = currentValue.text, - start = currentValue.start; - var characterBefore = text[start - 1]; // The caret must be at the start of a line. - - if (characterBefore && characterBefore !== LINE_SEPARATOR) { - return; - } - - handleChange(indentListItems(currentValue, { - type: multilineRootTag - })); - event.preventDefault(); - } - /** - * Handles horizontal keyboard navigation when no modifiers are pressed. The - * navigation is handled separately to move correctly around format - * boundaries. - * - * @param {WPSyntheticEvent} event A synthetic keyboard event. - */ - - - function handleHorizontalNavigation(event) { - var keyCode = event.keyCode, - shiftKey = event.shiftKey, - altKey = event.altKey, - metaKey = event.metaKey, - ctrlKey = event.ctrlKey; - - if ( // Only override left and right keys without modifiers pressed. - shiftKey || altKey || metaKey || ctrlKey || keyCode !== external_this_wp_keycodes_["LEFT"] && keyCode !== external_this_wp_keycodes_["RIGHT"]) { - return; - } - - var _record$current = record.current, - text = _record$current.text, - formats = _record$current.formats, - start = _record$current.start, - end = _record$current.end, - _record$current$activ = _record$current.activeFormats, - currentActiveFormats = _record$current$activ === void 0 ? [] : _record$current$activ; - var collapsed = isCollapsed(record.current); // To do: ideally, we should look at visual position instead. - - var _getWin$getComputedSt = getWin().getComputedStyle(ref.current), - direction = _getWin$getComputedSt.direction; - - var reverseKey = direction === 'rtl' ? external_this_wp_keycodes_["RIGHT"] : external_this_wp_keycodes_["LEFT"]; - var isReverse = event.keyCode === reverseKey; // If the selection is collapsed and at the very start, do nothing if - // navigating backward. - // If the selection is collapsed and at the very end, do nothing if - // navigating forward. - - if (collapsed && currentActiveFormats.length === 0) { - if (start === 0 && isReverse) { - return; - } - - if (end === text.length && !isReverse) { - return; - } - } // If the selection is not collapsed, let the browser handle collapsing - // the selection for now. Later we could expand this logic to set - // boundary positions if needed. - - - if (!collapsed) { - return; - } // In all other cases, prevent default behaviour. - - - event.preventDefault(); - var formatsBefore = formats[start - 1] || EMPTY_ACTIVE_FORMATS; - var formatsAfter = formats[start] || EMPTY_ACTIVE_FORMATS; - var newActiveFormatsLength = currentActiveFormats.length; - var source = formatsAfter; - - if (formatsBefore.length > formatsAfter.length) { - source = formatsBefore; - } // If the amount of formats before the caret and after the caret is - // different, the caret is at a format boundary. - - - if (formatsBefore.length < formatsAfter.length) { - if (!isReverse && currentActiveFormats.length < formatsAfter.length) { - newActiveFormatsLength++; - } - - if (isReverse && currentActiveFormats.length > formatsBefore.length) { - newActiveFormatsLength--; - } - } else if (formatsBefore.length > formatsAfter.length) { - if (!isReverse && currentActiveFormats.length > formatsAfter.length) { - newActiveFormatsLength--; - } - - if (isReverse && currentActiveFormats.length < formatsBefore.length) { - newActiveFormatsLength++; + + if (multilineTag) { + let newValue; // Check to see if we should remove the first item if empty. + + if (isReverse && currentValue.start === 0 && currentValue.end === 0 && isEmptyLine(currentValue)) { + newValue = removeLineSeparator(currentValue, !isReverse); + } else { + newValue = removeLineSeparator(currentValue, isReverse); + } + + if (newValue) { + handleChange(newValue); + event.preventDefault(); + } } } - if (newActiveFormatsLength !== currentActiveFormats.length) { - var _newActiveFormats = source.slice(0, newActiveFormatsLength); - - var _newValue = component_objectSpread({}, record.current, { - activeFormats: _newActiveFormats - }); - - record.current = _newValue; - applyRecord(_newValue); - setActiveFormats(_newActiveFormats); - return; - } - - var newPos = start + (isReverse ? -1 : 1); - var newActiveFormats = isReverse ? formatsBefore : formatsAfter; - - var newValue = component_objectSpread({}, record.current, { - start: newPos, - end: newPos, - activeFormats: newActiveFormats + element.addEventListener('keydown', onKeyDown); + return () => { + element.removeEventListener('keydown', onKeyDown); + }; + }, []); +} + +// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/index.js +/** + * WordPress dependencies + */ + + +/** + * Internal dependencies + */ + + + + + + + + + + + + + +function useRichText({ + value = '', + selectionStart, + selectionEnd, + placeholder, + preserveWhiteSpace, + onSelectionChange, + onChange, + __unstableMultilineTag: multilineTag, + __unstableDisableFormats: disableFormats, + __unstableIsSelected: isSelected, + __unstableDependencies, + __unstableAfterParse, + __unstableBeforeSerialize, + __unstableAddInvisibleFormats +}) { + const [, forceRender] = Object(external_wp_element_["useReducer"])(() => ({})); + const ref = Object(external_wp_element_["useRef"])(); + + function createRecord() { + const { + ownerDocument: { + defaultView + } + } = ref.current; + const selection = defaultView.getSelection(); + const range = selection.rangeCount > 0 ? selection.getRangeAt(0) : null; + return create({ + element: ref.current, + range, + multilineTag, + multilineWrapperTags: multilineTag === 'li' ? ['ul', 'ol'] : undefined, + __unstableIsEditableTree: true, + preserveWhiteSpace }); - - record.current = newValue; - applyRecord(newValue); - onSelectionChange(newPos, newPos); - setActiveFormats(newActiveFormats); - } - - function handleKeyDown(event) { - if (event.defaultPrevented) { - return; - } - - handleDelete(event); - handleEnter(event); - handleSpace(event); - handleHorizontalNavigation(event); - } - - var lastHistoryValue = Object(external_this_wp_element_["useRef"])(value); - - function createUndoLevel() { - // If the content is the same, no level needs to be created. - if (lastHistoryValue.current === _value.current) { - return; - } - - onCreateUndoLevel(); - lastHistoryValue.current = _value.current; } - var isComposing = Object(external_this_wp_element_["useRef"])(false); - var timeout = Object(external_this_wp_element_["useRef"])(); - /** - * Handle input on the next selection change event. - * - * @param {WPSyntheticEvent} event Synthetic input event. - */ - - function handleInput(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.current) { - return; - } - - var inputType; - - if (event) { - inputType = event.inputType; - } - - if (!inputType && event && event.nativeEvent) { - inputType = event.nativeEvent.inputType; - } // The browser formatted something or tried to insert HTML. - // Overwrite it. It will be handled later by the format library if - // needed. - - - if (inputType && (inputType.indexOf('format') === 0 || INSERTION_INPUT_TYPES_TO_IGNORE.has(inputType))) { - applyRecord(record.current); - return; - } - - var currentValue = createRecord(); - var _record$current2 = record.current, - start = _record$current2.start, - _record$current2$acti = _record$current2.activeFormats, - oldActiveFormats = _record$current2$acti === void 0 ? [] : _record$current2$acti; // Update the formats between the last and new caret position. - - var change = updateFormats({ - value: currentValue, - start: start, - end: currentValue.start, - formats: oldActiveFormats + function applyRecord(newRecord, { + domOnly + } = {}) { + apply({ + value: newRecord, + current: ref.current, + multilineTag, + multilineWrapperTags: multilineTag === 'li' ? ['ul', 'ol'] : undefined, + prepareEditableTree: __unstableAddInvisibleFormats, + __unstableDomOnly: domOnly, + placeholder }); - handleChange(change, { - withoutHistory: true - }); // Create an undo level when input stops for over a second. - - getWin().clearTimeout(timeout.current); - timeout.current = getWin().setTimeout(createUndoLevel, 1000); // Only run input rules when inserting text. - - if (inputType !== 'insertText') { - return; - } - - if (allowPrefixTransformations && inputRule) { - inputRule(change, valueToFormat); + } // Internal values are updated synchronously, unlike props and state. + + + const _value = Object(external_wp_element_["useRef"])(value); + + const record = Object(external_wp_element_["useRef"])(); + + function setRecordFromProps() { + _value.current = value; + record.current = create({ + html: value, + multilineTag, + multilineWrapperTags: multilineTag === 'li' ? ['ul', 'ol'] : undefined, + preserveWhiteSpace + }); + + if (disableFormats) { + record.current.formats = Array(value.length); + record.current.replacements = Array(value.length); } - var transformed = formatTypes.reduce(function (accumlator, _ref4) { - var __unstableInputRule = _ref4.__unstableInputRule; - - if (__unstableInputRule) { - accumlator = __unstableInputRule(accumlator); - } - - return accumlator; - }, change); - - if (transformed !== change) { - createUndoLevel(); - handleChange(component_objectSpread({}, transformed, { - activeFormats: oldActiveFormats - })); - markAutomaticChange(); - } - } - - function handleCompositionStart() { - isComposing.current = true; // Do not update the selection when characters are being composed as - // this rerenders the component and might distroy internal browser - // editing state. - - getDoc().removeEventListener('selectionchange', handleSelectionChange); - } - - function handleCompositionEnd() { - isComposing.current = false; // Ensure the value is up-to-date for browsers that don't emit a final - // input event after composition. - - handleInput({ - inputType: 'insertText' - }); // Tracking selection changes can be resumed. - - getDoc().addEventListener('selectionchange', handleSelectionChange); + record.current.formats = __unstableAfterParse(record.current); + record.current.start = selectionStart; + record.current.end = selectionEnd; } - var didMount = Object(external_this_wp_element_["useRef"])(false); - /** - * Syncs the selection to local state. A callback for the `selectionchange` - * native events, `keyup`, `mouseup` and `touchend` synthetic events, and - * animation frames after the `focus` event. - * - * @param {Event|WPSyntheticEvent|DOMHighResTimeStamp} event - */ - - function handleSelectionChange(event) { - if (!ref.current) { - return; - } - - if (document.activeElement !== ref.current) { - return; - } - - if (event.type !== 'selectionchange' && !isSelected) { - return; - } - - if (disabled) { - return; - } // In case of a keyboard event, ignore selection changes during - // composition. - - - if (isComposing.current) { - return; - } - - var _createRecord = createRecord(), - start = _createRecord.start, - end = _createRecord.end, - text = _createRecord.text; - - var oldRecord = record.current; // Fallback mechanism for IE11, which doesn't support the input event. - // Any input results in a selection change. - - if (text !== oldRecord.text) { - handleInput(); - 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(getWin()); - } - - return; - } - - var newValue = component_objectSpread({}, oldRecord, { - start: start, - end: end, - // Allow `getActiveFormats` to get new `activeFormats`. - activeFormats: undefined - }); - - var newActiveFormats = getActiveFormats(newValue, EMPTY_ACTIVE_FORMATS); // Update the value with the new active formats. - - newValue.activeFormats = newActiveFormats; - - if (!isCaretWithinFormattedText && newActiveFormats.length) { - onEnterFormattedText(); - } else if (isCaretWithinFormattedText && !newActiveFormats.length) { - onExitFormattedText(); - } // It is important that the internal value is updated first, - // otherwise the value will be wrong on render! - - - record.current = newValue; - applyRecord(newValue, { - domOnly: true - }); - onSelectionChange(start, end); - setActiveFormats(newActiveFormats); + const hadSelectionUpdate = Object(external_wp_element_["useRef"])(false); + + if (!record.current) { + setRecordFromProps(); + } else if (selectionStart !== record.current.start || selectionEnd !== record.current.end) { + hadSelectionUpdate.current = isSelected; + record.current = { ...record.current, + start: selectionStart, + end: selectionEnd + }; } /** * Sync the value to global state. The node tree and selection will also be * updated if differences are found. * - * @param {Object} newRecord The record to sync and apply. - * @param {Object} $2 Named options. - * @param {boolean} $2.withoutHistory If true, no undo level will be - * created. + * @param {Object} newRecord The record to sync and apply. */ function handleChange(newRecord) { - var _ref5 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - withoutHistory = _ref5.withoutHistory; + applyRecord(newRecord); if (disableFormats) { - newRecord.formats = Array(newRecord.text.length); - newRecord.replacements = Array(newRecord.text.length); + _value.current = newRecord.text; + } else { + _value.current = toHTMLString({ + value: { ...newRecord, + formats: __unstableBeforeSerialize(newRecord) + }, + multilineTag, + preserveWhiteSpace + }); } - applyRecord(newRecord); - var start = newRecord.start, - end = newRecord.end, - _newRecord$activeForm = newRecord.activeFormats, - newActiveFormats = _newRecord$activeForm === void 0 ? [] : _newRecord$activeForm; - var changeHandlers = Object(external_this_lodash_["pickBy"])(remainingProps, function (v, key) { - return key.startsWith('format_on_change_functions_'); - }); - Object.values(changeHandlers).forEach(function (changeHandler) { - changeHandler(newRecord.formats, newRecord.text); - }); - _value.current = valueToFormat(newRecord); - record.current = newRecord; // Selection must be updated first, so it is recorded in history when + record.current = newRecord; + const { + start, + end, + formats, + text + } = newRecord; // Selection must be updated first, so it is recorded in history when // the content change happens. onSelectionChange(start, end); - onChange(_value.current); - setActiveFormats(newActiveFormats); - - if (!withoutHistory) { - createUndoLevel(); - } - } - /** - * Select object when they are clicked. The browser will not set any - * selection when clicking e.g. an image. - * - * @param {WPSyntheticEvent} event Synthetic mousedown or touchstart event. - */ - - - function handlePointerDown(event) { - var target = event.target; // If the child element has no text content, it must be an object. - - if (target === ref.current || target.textContent) { - return; - } - - var parentNode = target.parentNode; - var index = Array.from(parentNode.childNodes).indexOf(target); - var range = getDoc().createRange(); - var selection = getWin().getSelection(); - range.setStart(target.parentNode, index); - range.setEnd(target.parentNode, index + 1); - selection.removeAllRanges(); - selection.addRange(range); - } - - var rafId = Object(external_this_wp_element_["useRef"])(); - /** - * Handles a focus event on the contenteditable field, calling the - * `unstableOnFocus` prop callback if one is defined. The callback does not - * receive any arguments. - * - * This is marked as a private API and the `unstableOnFocus` prop is not - * documented, as the current requirements where it is used are subject to - * future refactoring following `isSelected` handling. - * - * In contrast with `setFocusedElement`, this is only triggered in response - * to focus within the contenteditable field, whereas `setFocusedElement` - * is triggered on focus within any `RichText` descendent element. - * - * @see setFocusedElement - * - * @private - */ - - function handleFocus() { - if (onFocus) { - onFocus(); - } - - 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. - var index = undefined; - record.current = component_objectSpread({}, record.current, { - start: index, - end: index, - activeFormats: EMPTY_ACTIVE_FORMATS - }); - onSelectionChange(index, index); - setActiveFormats(EMPTY_ACTIVE_FORMATS); - } else { - onSelectionChange(record.current.start, record.current.end); - setActiveFormats(getActiveFormats(component_objectSpread({}, record.current, { - activeFormats: undefined - }), EMPTY_ACTIVE_FORMATS)); - } // Update selection as soon as possible, which is at the next animation - // frame. The event listener for selection changes may be added too late - // at this point, but this focus event is still too early to calculate - // the selection. - - - rafId.current = getWin().requestAnimationFrame(handleSelectionChange); - getDoc().addEventListener('selectionchange', handleSelectionChange); - - if (setFocusedElement) { - external_this_wp_deprecated_default()('wp.blockEditor.RichText setFocusedElement prop', { - alternative: 'selection state from the block editor store.' - }); - setFocusedElement(instanceId); - } - } - - function handleBlur() { - getDoc().removeEventListener('selectionchange', handleSelectionChange); + onChange(_value.current, { + __unstableFormats: formats, + __unstableText: text + }); + forceRender(); } function applyFromProps() { - _value.current = value; - record.current = formatToValue(value); - record.current.start = selectionStart; - record.current.end = selectionEnd; + setRecordFromProps(); applyRecord(record.current); } - Object(external_this_wp_element_["useEffect"])(function () { - if (didMount.current) { - applyFromProps(); - } - }, [TagName, placeholder]); - Object(external_this_wp_element_["useEffect"])(function () { + const didMount = Object(external_wp_element_["useRef"])(false); // Value updates must happen synchonously to avoid overwriting newer values. + + Object(external_wp_element_["useLayoutEffect"])(() => { if (didMount.current && value !== _value.current) { applyFromProps(); } - }, [value]); - Object(external_this_wp_element_["useEffect"])(function () { - if (!didMount.current) { + }, [value]); // Value updates must happen synchonously to avoid overwriting newer values. + + Object(external_wp_element_["useLayoutEffect"])(() => { + if (!hadSelectionUpdate.current) { return; } - if (isSelected && (selectionStart !== record.current.start || selectionEnd !== record.current.end)) { - applyFromProps(); - } else { - record.current = component_objectSpread({}, record.current, { - start: selectionStart, - end: selectionEnd - }); - } - }, [selectionStart, selectionEnd, isSelected]); - var prefix = 'format_prepare_props_'; - - var predicate = function predicate(v, key) { - return key.startsWith(prefix); - }; - - var prepareProps = Object(external_this_lodash_["pickBy"])(remainingProps, predicate); - Object(external_this_wp_element_["useEffect"])(function () { - if (didMount.current) { - applyFromProps(); - } - }, Object.values(prepareProps)); - Object(external_this_wp_element_["useLayoutEffect"])(function () { - applyRecord(record.current, { - domOnly: true - }); - didMount.current = true; - return function () { - getDoc().removeEventListener('selectionchange', handleSelectionChange); - getWin().cancelAnimationFrame(rafId.current); - getWin().clearTimeout(timeout.current); - }; - }, []); + applyFromProps(); + hadSelectionUpdate.current = false; + }, [hadSelectionUpdate.current]); function focus() { ref.current.focus(); applyRecord(record.current); } - var ariaProps = Object(external_this_lodash_["pickBy"])(remainingProps, function (v, key) { - return Object(external_this_lodash_["startsWith"])(key, 'aria-'); - }); - - var editableProps = component_objectSpread({ - // Overridable props. - role: 'textbox', - 'aria-multiline': true, - 'aria-label': placeholder - }, ariaProps, { - ref: ref, - style: style ? component_objectSpread({}, style, { - whiteSpace: whiteSpace - }) : defaultStyle, - className: classnames_default()('rich-text', className), - onPaste: handlePaste, - onInput: handleInput, - onCompositionStart: handleCompositionStart, - onCompositionEnd: handleCompositionEnd, - onKeyDown: handleKeyDown, - onFocus: handleFocus, - onBlur: handleBlur, - onMouseDown: handlePointerDown, - onTouchStart: handlePointerDown, - // Selection updates must be done at these events as they - // happen before the `selectionchange` event. In some cases, - // the `selectionchange` event may not even fire, for - // example when the window receives focus again on click. - onKeyUp: handleSelectionChange, - onMouseUp: handleSelectionChange, - onTouchEnd: handleSelectionChange, - // Do not set the attribute if disabled. - contentEditable: disabled ? undefined : true, - suppressContentEditableWarning: !disabled - }); - - useBoundaryStyle({ - ref: ref, - activeFormats: activeFormats - }); - useInlineWarning({ - ref: ref - }); - return Object(external_this_wp_element_["createElement"])(external_this_wp_element_["Fragment"], null, isSelected && Object(external_this_wp_element_["createElement"])(FormatEdit, { - allowedFormats: allowedFormats, - withoutInteractiveFormatting: withoutInteractiveFormatting, + const mergedRefs = Object(external_wp_compose_["useMergeRefs"])([ref, useDefaultStyle(), useBoundaryStyle({ + record + }), useInlineWarning(), useCopyHandler({ + record, + multilineTag, + preserveWhiteSpace + }), useSelectObject(), useFormatBoundaries({ + record, + applyRecord + }), useDelete({ + createRecord, + handleChange, + multilineTag + }), useIndentListItemOnSpace({ + multilineTag, + createRecord, + handleChange + }), useInputAndSelection({ + record, + applyRecord, + createRecord, + handleChange, + isSelected, + onSelectionChange + }), Object(external_wp_compose_["useRefEffect"])(() => { + applyFromProps(); + didMount.current = true; + }, [placeholder, ...__unstableDependencies])]); + return { value: record.current, onChange: handleChange, onFocus: focus, - formatTypes: formatTypes - }), children && children({ - isSelected: isSelected, - value: record.current, - onChange: handleChange, - onFocus: focus, - editableProps: editableProps, - editableTagName: TagName - }), !children && Object(external_this_wp_element_["createElement"])(TagName, editableProps)); + ref: mergedRefs + }; } - -var RichTextWrapper = withFormatTypes(component_RichText); -/** - * Renders a rich content input, providing users with the option to format the - * content. - */ - -/* harmony default export */ var component = (Object(external_this_wp_element_["forwardRef"])(function (props, ref) { - return Object(external_this_wp_element_["createElement"])(RichTextWrapper, Object(esm_extends["a" /* default */])({}, props, { - forwardedRef: ref - })); -})); - -// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/index.js +function __experimentalRichText() {} + +// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/format-edit.js + + /** * Internal dependencies */ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -/***/ }), - -/***/ 5: -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _defineProperty; }); -function _defineProperty(obj, key, value) { - if (key in obj) { - Object.defineProperty(obj, key, { +function FormatEdit({ + formatTypes, + onChange, + onFocus, + value, + forwardedRef +}) { + return formatTypes.map(settings => { + const { + name, + edit: Edit + } = settings; + + if (!Edit) { + return null; + } + + const activeFormat = getActiveFormat(value, name); + const isActive = activeFormat !== undefined; + const activeObject = getActiveObject(value); + const isObjectActive = activeObject !== undefined && activeObject.type === name; + return Object(external_wp_element_["createElement"])(Edit, { + key: name, + isActive: isActive, + activeAttributes: isActive ? activeFormat.attributes || {} : {}, + isObjectActive: isObjectActive, + activeObjectAttributes: isObjectActive ? activeObject.attributes || {} : {}, value: value, - enumerable: true, - configurable: true, - writable: true + onChange: onChange, + onFocus: onFocus, + contentRef: forwardedRef }); - } else { - obj[key] = value; - } - - return obj; + }); } -/***/ }), - -/***/ 8: -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _extends; }); -function _extends() { - _extends = Object.assign || function (target) { - for (var i = 1; i < arguments.length; i++) { - var source = arguments[i]; - - for (var key in source) { - if (Object.prototype.hasOwnProperty.call(source, key)) { - target[key] = source[key]; - } - } - } - - return target; - }; - - return _extends.apply(this, arguments); -} - -/***/ }), - -/***/ 89: -/***/ (function(module, exports) { - -(function() { module.exports = this["wp"]["escapeHtml"]; }()); +// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/index.js + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /***/ })