[ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 this["wp"] = this["wp"] || {}; this["wp"]["richText"] = 2 /******/ (function(modules) { // webpackBootstrap 3 /******/ // The module cache 4 /******/ var installedModules = {}; 5 /******/ 6 /******/ // The require function 7 /******/ function __webpack_require__(moduleId) { 8 /******/ 9 /******/ // Check if module is in cache 10 /******/ if(installedModules[moduleId]) { 11 /******/ return installedModules[moduleId].exports; 12 /******/ } 13 /******/ // Create a new module (and put it into the cache) 14 /******/ var module = installedModules[moduleId] = { 15 /******/ i: moduleId, 16 /******/ l: false, 17 /******/ exports: {} 18 /******/ }; 19 /******/ 20 /******/ // Execute the module function 21 /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 22 /******/ 23 /******/ // Flag the module as loaded 24 /******/ module.l = true; 25 /******/ 26 /******/ // Return the exports of the module 27 /******/ return module.exports; 28 /******/ } 29 /******/ 30 /******/ 31 /******/ // expose the modules object (__webpack_modules__) 32 /******/ __webpack_require__.m = modules; 33 /******/ 34 /******/ // expose the module cache 35 /******/ __webpack_require__.c = installedModules; 36 /******/ 37 /******/ // define getter function for harmony exports 38 /******/ __webpack_require__.d = function(exports, name, getter) { 39 /******/ if(!__webpack_require__.o(exports, name)) { 40 /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); 41 /******/ } 42 /******/ }; 43 /******/ 44 /******/ // define __esModule on exports 45 /******/ __webpack_require__.r = function(exports) { 46 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 47 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 48 /******/ } 49 /******/ Object.defineProperty(exports, '__esModule', { value: true }); 50 /******/ }; 51 /******/ 52 /******/ // create a fake namespace object 53 /******/ // mode & 1: value is a module id, require it 54 /******/ // mode & 2: merge all properties of value into the ns 55 /******/ // mode & 4: return value when already ns object 56 /******/ // mode & 8|1: behave like require 57 /******/ __webpack_require__.t = function(value, mode) { 58 /******/ if(mode & 1) value = __webpack_require__(value); 59 /******/ if(mode & 8) return value; 60 /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; 61 /******/ var ns = Object.create(null); 62 /******/ __webpack_require__.r(ns); 63 /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); 64 /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); 65 /******/ return ns; 66 /******/ }; 67 /******/ 68 /******/ // getDefaultExport function for compatibility with non-harmony modules 69 /******/ __webpack_require__.n = function(module) { 70 /******/ var getter = module && module.__esModule ? 71 /******/ function getDefault() { return module['default']; } : 72 /******/ function getModuleExports() { return module; }; 73 /******/ __webpack_require__.d(getter, 'a', getter); 74 /******/ return getter; 75 /******/ }; 76 /******/ 77 /******/ // Object.prototype.hasOwnProperty.call 78 /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; 79 /******/ 80 /******/ // __webpack_public_path__ 81 /******/ __webpack_require__.p = ""; 82 /******/ 83 /******/ 84 /******/ // Load entry module and return exports 85 /******/ return __webpack_require__(__webpack_require__.s = "./node_modules/@wordpress/rich-text/build-module/index.js"); 86 /******/ }) 87 /************************************************************************/ 88 /******/ ({ 89 90 /***/ "./node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js": 91 /*!**********************************************************************!*\ 92 !*** ./node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js ***! 93 \**********************************************************************/ 94 /*! exports provided: default */ 95 /***/ (function(module, __webpack_exports__, __webpack_require__) { 96 97 "use strict"; 98 __webpack_require__.r(__webpack_exports__); 99 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _arrayWithoutHoles; }); 100 function _arrayWithoutHoles(arr) { 101 if (Array.isArray(arr)) { 102 for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { 103 arr2[i] = arr[i]; 104 } 105 106 return arr2; 107 } 108 } 109 110 /***/ }), 111 112 /***/ "./node_modules/@babel/runtime/helpers/esm/defineProperty.js": 113 /*!*******************************************************************!*\ 114 !*** ./node_modules/@babel/runtime/helpers/esm/defineProperty.js ***! 115 \*******************************************************************/ 116 /*! exports provided: default */ 117 /***/ (function(module, __webpack_exports__, __webpack_require__) { 118 119 "use strict"; 120 __webpack_require__.r(__webpack_exports__); 121 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _defineProperty; }); 122 function _defineProperty(obj, key, value) { 123 if (key in obj) { 124 Object.defineProperty(obj, key, { 125 value: value, 126 enumerable: true, 127 configurable: true, 128 writable: true 129 }); 130 } else { 131 obj[key] = value; 132 } 133 134 return obj; 135 } 136 137 /***/ }), 138 139 /***/ "./node_modules/@babel/runtime/helpers/esm/iterableToArray.js": 140 /*!********************************************************************!*\ 141 !*** ./node_modules/@babel/runtime/helpers/esm/iterableToArray.js ***! 142 \********************************************************************/ 143 /*! exports provided: default */ 144 /***/ (function(module, __webpack_exports__, __webpack_require__) { 145 146 "use strict"; 147 __webpack_require__.r(__webpack_exports__); 148 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _iterableToArray; }); 149 function _iterableToArray(iter) { 150 if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); 151 } 152 153 /***/ }), 154 155 /***/ "./node_modules/@babel/runtime/helpers/esm/nonIterableSpread.js": 156 /*!**********************************************************************!*\ 157 !*** ./node_modules/@babel/runtime/helpers/esm/nonIterableSpread.js ***! 158 \**********************************************************************/ 159 /*! exports provided: default */ 160 /***/ (function(module, __webpack_exports__, __webpack_require__) { 161 162 "use strict"; 163 __webpack_require__.r(__webpack_exports__); 164 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _nonIterableSpread; }); 165 function _nonIterableSpread() { 166 throw new TypeError("Invalid attempt to spread non-iterable instance"); 167 } 168 169 /***/ }), 170 171 /***/ "./node_modules/@babel/runtime/helpers/esm/objectSpread.js": 172 /*!*****************************************************************!*\ 173 !*** ./node_modules/@babel/runtime/helpers/esm/objectSpread.js ***! 174 \*****************************************************************/ 175 /*! exports provided: default */ 176 /***/ (function(module, __webpack_exports__, __webpack_require__) { 177 178 "use strict"; 179 __webpack_require__.r(__webpack_exports__); 180 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _objectSpread; }); 181 /* harmony import */ var _defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./defineProperty */ "./node_modules/@babel/runtime/helpers/esm/defineProperty.js"); 182 183 function _objectSpread(target) { 184 for (var i = 1; i < arguments.length; i++) { 185 var source = arguments[i] != null ? arguments[i] : {}; 186 var ownKeys = Object.keys(source); 187 188 if (typeof Object.getOwnPropertySymbols === 'function') { 189 ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { 190 return Object.getOwnPropertyDescriptor(source, sym).enumerable; 191 })); 192 } 193 194 ownKeys.forEach(function (key) { 195 Object(_defineProperty__WEBPACK_IMPORTED_MODULE_0__["default"])(target, key, source[key]); 196 }); 197 } 198 199 return target; 200 } 201 202 /***/ }), 203 204 /***/ "./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js": 205 /*!**********************************************************************!*\ 206 !*** ./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js ***! 207 \**********************************************************************/ 208 /*! exports provided: default */ 209 /***/ (function(module, __webpack_exports__, __webpack_require__) { 210 211 "use strict"; 212 __webpack_require__.r(__webpack_exports__); 213 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _toConsumableArray; }); 214 /* harmony import */ var _arrayWithoutHoles__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./arrayWithoutHoles */ "./node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js"); 215 /* harmony import */ var _iterableToArray__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./iterableToArray */ "./node_modules/@babel/runtime/helpers/esm/iterableToArray.js"); 216 /* harmony import */ var _nonIterableSpread__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./nonIterableSpread */ "./node_modules/@babel/runtime/helpers/esm/nonIterableSpread.js"); 217 218 219 220 function _toConsumableArray(arr) { 221 return Object(_arrayWithoutHoles__WEBPACK_IMPORTED_MODULE_0__["default"])(arr) || Object(_iterableToArray__WEBPACK_IMPORTED_MODULE_1__["default"])(arr) || Object(_nonIterableSpread__WEBPACK_IMPORTED_MODULE_2__["default"])(); 222 } 223 224 /***/ }), 225 226 /***/ "./node_modules/@babel/runtime/helpers/esm/typeof.js": 227 /*!***********************************************************!*\ 228 !*** ./node_modules/@babel/runtime/helpers/esm/typeof.js ***! 229 \***********************************************************/ 230 /*! exports provided: default */ 231 /***/ (function(module, __webpack_exports__, __webpack_require__) { 232 233 "use strict"; 234 __webpack_require__.r(__webpack_exports__); 235 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _typeof; }); 236 function _typeof2(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof2 = function _typeof2(obj) { return typeof obj; }; } else { _typeof2 = function _typeof2(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof2(obj); } 237 238 function _typeof(obj) { 239 if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") { 240 _typeof = function _typeof(obj) { 241 return _typeof2(obj); 242 }; 243 } else { 244 _typeof = function _typeof(obj) { 245 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj); 246 }; 247 } 248 249 return _typeof(obj); 250 } 251 252 /***/ }), 253 254 /***/ "./node_modules/@wordpress/rich-text/build-module/apply-format.js": 255 /*!************************************************************************!*\ 256 !*** ./node_modules/@wordpress/rich-text/build-module/apply-format.js ***! 257 \************************************************************************/ 258 /*! exports provided: applyFormat */ 259 /***/ (function(module, __webpack_exports__, __webpack_require__) { 260 261 "use strict"; 262 __webpack_require__.r(__webpack_exports__); 263 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "applyFormat", function() { return applyFormat; }); 264 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lodash */ "lodash"); 265 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_0__); 266 /* harmony import */ var _normalise_formats__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./normalise-formats */ "./node_modules/@wordpress/rich-text/build-module/normalise-formats.js"); 267 /** 268 * External dependencies 269 */ 270 271 /** 272 * Internal dependencies 273 */ 274 275 276 /** 277 * Apply a format object to a Rich Text value from the given `startIndex` to the 278 * given `endIndex`. Indices are retrieved from the selection if none are 279 * provided. 280 * 281 * @param {Object} value Value to modify. 282 * @param {Object} format Format to apply. 283 * @param {number} startIndex Start index. 284 * @param {number} endIndex End index. 285 * 286 * @return {Object} A new value with the format applied. 287 */ 288 289 function applyFormat(_ref, format) { 290 var formats = _ref.formats, 291 text = _ref.text, 292 start = _ref.start, 293 end = _ref.end; 294 var startIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : start; 295 var endIndex = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : end; 296 var newFormats = formats.slice(0); // If the selection is collapsed, expand start and end to the edges of the 297 // format. 298 299 if (startIndex === endIndex) { 300 var startFormat = Object(lodash__WEBPACK_IMPORTED_MODULE_0__["find"])(newFormats[startIndex], { 301 type: format.type 302 }); 303 304 while (Object(lodash__WEBPACK_IMPORTED_MODULE_0__["find"])(newFormats[startIndex], startFormat)) { 305 applyFormats(newFormats, startIndex, format); 306 startIndex--; 307 } 308 309 endIndex++; 310 311 while (Object(lodash__WEBPACK_IMPORTED_MODULE_0__["find"])(newFormats[endIndex], startFormat)) { 312 applyFormats(newFormats, endIndex, format); 313 endIndex++; 314 } 315 } else { 316 for (var index = startIndex; index < endIndex; index++) { 317 applyFormats(newFormats, index, format); 318 } 319 } 320 321 return Object(_normalise_formats__WEBPACK_IMPORTED_MODULE_1__["normaliseFormats"])({ 322 formats: newFormats, 323 text: text, 324 start: start, 325 end: end 326 }); 327 } 328 329 function applyFormats(formats, index, format) { 330 if (formats[index]) { 331 var newFormatsAtIndex = formats[index].filter(function (_ref2) { 332 var type = _ref2.type; 333 return type !== format.type; 334 }); 335 newFormatsAtIndex.push(format); 336 formats[index] = newFormatsAtIndex; 337 } else { 338 formats[index] = [format]; 339 } 340 } 341 342 343 /***/ }), 344 345 /***/ "./node_modules/@wordpress/rich-text/build-module/concat.js": 346 /*!******************************************************************!*\ 347 !*** ./node_modules/@wordpress/rich-text/build-module/concat.js ***! 348 \******************************************************************/ 349 /*! exports provided: concat */ 350 /***/ (function(module, __webpack_exports__, __webpack_require__) { 351 352 "use strict"; 353 __webpack_require__.r(__webpack_exports__); 354 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "concat", function() { return concat; }); 355 /* harmony import */ var _normalise_formats__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./normalise-formats */ "./node_modules/@wordpress/rich-text/build-module/normalise-formats.js"); 356 /** 357 * Internal dependencies 358 */ 359 360 /** 361 * Combine all Rich Text values into one. This is similar to 362 * `String.prototype.concat`. 363 * 364 * @param {...[object]} values An array of all values to combine. 365 * 366 * @return {Object} A new value combining all given records. 367 */ 368 369 function concat() { 370 for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) { 371 values[_key] = arguments[_key]; 372 } 373 374 return Object(_normalise_formats__WEBPACK_IMPORTED_MODULE_0__["normaliseFormats"])(values.reduce(function (accumlator, _ref) { 375 var formats = _ref.formats, 376 text = _ref.text; 377 return { 378 text: accumlator.text + text, 379 formats: accumlator.formats.concat(formats) 380 }; 381 })); 382 } 383 384 385 /***/ }), 386 387 /***/ "./node_modules/@wordpress/rich-text/build-module/create-element.js": 388 /*!**************************************************************************!*\ 389 !*** ./node_modules/@wordpress/rich-text/build-module/create-element.js ***! 390 \**************************************************************************/ 391 /*! exports provided: createElement */ 392 /***/ (function(module, __webpack_exports__, __webpack_require__) { 393 394 "use strict"; 395 __webpack_require__.r(__webpack_exports__); 396 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "createElement", function() { return createElement; }); 397 /** 398 * Parse the given HTML into a body element. 399 * 400 * @param {HTMLDocument} document The HTML document to use to parse. 401 * @param {string} html The HTML to parse. 402 * 403 * @return {HTMLBodyElement} Body element with parsed HTML. 404 */ 405 function createElement(_ref, html) { 406 var implementation = _ref.implementation; 407 408 var _implementation$creat = implementation.createHTMLDocument(''), 409 body = _implementation$creat.body; 410 411 body.innerHTML = html; 412 return body; 413 } 414 415 416 /***/ }), 417 418 /***/ "./node_modules/@wordpress/rich-text/build-module/create.js": 419 /*!******************************************************************!*\ 420 !*** ./node_modules/@wordpress/rich-text/build-module/create.js ***! 421 \******************************************************************/ 422 /*! exports provided: create */ 423 /***/ (function(module, __webpack_exports__, __webpack_require__) { 424 425 "use strict"; 426 __webpack_require__.r(__webpack_exports__); 427 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "create", function() { return create; }); 428 /* harmony import */ var _babel_runtime_helpers_esm_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/esm/toConsumableArray */ "./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js"); 429 /* harmony import */ var _babel_runtime_helpers_esm_typeof__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/esm/typeof */ "./node_modules/@babel/runtime/helpers/esm/typeof.js"); 430 /* harmony import */ var _is_empty__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./is-empty */ "./node_modules/@wordpress/rich-text/build-module/is-empty.js"); 431 /* harmony import */ var _is_format_equal__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./is-format-equal */ "./node_modules/@wordpress/rich-text/build-module/is-format-equal.js"); 432 /* harmony import */ var _create_element__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./create-element */ "./node_modules/@wordpress/rich-text/build-module/create-element.js"); 433 434 435 436 /** 437 * Internal dependencies 438 */ 439 440 441 442 /** 443 * Browser dependencies 444 */ 445 446 var _window$Node = window.Node, 447 TEXT_NODE = _window$Node.TEXT_NODE, 448 ELEMENT_NODE = _window$Node.ELEMENT_NODE; 449 450 function createEmptyValue() { 451 return { 452 formats: [], 453 text: '' 454 }; 455 } 456 /** 457 * Create a RichText value from an `Element` tree (DOM), an HTML string or a 458 * plain text string, with optionally a `Range` object to set the selection. If 459 * called without any input, an empty value will be created. If 460 * `multilineTag` is provided, any content of direct children whose type matches 461 * `multilineTag` will be separated by two newlines. The optional functions can 462 * be used to filter out content. 463 * 464 * @param {?Object} $1 Optional named argements. 465 * @param {?Element} $1.element Element to create value from. 466 * @param {?string} $1.text Text to create value from. 467 * @param {?string} $1.html HTML to create value from. 468 * @param {?Range} $1.range Range to create value from. 469 * @param {?string} $1.multilineTag Multiline tag if the structure is 470 * multiline. 471 * @param {?Function} $1.removeNode Function to declare whether the given 472 * node should be removed. 473 * @param {?Function} $1.unwrapNode Function to declare whether the given 474 * node should be unwrapped. 475 * @param {?Function} $1.filterString Function to filter the given string. 476 * @param {?Function} $1.removeAttribute Wether to remove an attribute based on 477 * the name. 478 * 479 * @return {Object} A rich text value. 480 */ 481 482 483 function create() { 484 var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, 485 element = _ref.element, 486 text = _ref.text, 487 html = _ref.html, 488 range = _ref.range, 489 multilineTag = _ref.multilineTag, 490 removeNode = _ref.removeNode, 491 unwrapNode = _ref.unwrapNode, 492 filterString = _ref.filterString, 493 removeAttribute = _ref.removeAttribute; 494 495 if (typeof text === 'string' && text.length > 0) { 496 return { 497 formats: Array(text.length), 498 text: text 499 }; 500 } 501 502 if (typeof html === 'string' && html.length > 0) { 503 element = Object(_create_element__WEBPACK_IMPORTED_MODULE_4__["createElement"])(document, html); 504 } 505 506 if (Object(_babel_runtime_helpers_esm_typeof__WEBPACK_IMPORTED_MODULE_1__["default"])(element) !== 'object') { 507 return createEmptyValue(); 508 } 509 510 if (!multilineTag) { 511 return createFromElement({ 512 element: element, 513 range: range, 514 removeNode: removeNode, 515 unwrapNode: unwrapNode, 516 filterString: filterString, 517 removeAttribute: removeAttribute 518 }); 519 } 520 521 return createFromMultilineElement({ 522 element: element, 523 range: range, 524 multilineTag: multilineTag, 525 removeNode: removeNode, 526 unwrapNode: unwrapNode, 527 filterString: filterString, 528 removeAttribute: removeAttribute 529 }); 530 } 531 /** 532 * Helper to accumulate the value's selection start and end from the current 533 * node and range. 534 * 535 * @param {Object} accumulator Object to accumulate into. 536 * @param {Node} node Node to create value with. 537 * @param {Range} range Range to create value with. 538 * @param {Object} value Value that is being accumulated. 539 */ 540 541 function accumulateSelection(accumulator, node, range, value) { 542 if (!range) { 543 return; 544 } 545 546 var parentNode = node.parentNode; 547 var startContainer = range.startContainer, 548 startOffset = range.startOffset, 549 endContainer = range.endContainer, 550 endOffset = range.endOffset; 551 var currentLength = accumulator.text.length; // Selection can be extracted from value. 552 553 if (value.start !== undefined) { 554 accumulator.start = currentLength + value.start; // Range indicates that the current node has selection. 555 } else if (node === startContainer) { 556 accumulator.start = currentLength + startOffset; // Range indicates that the current node is selected. 557 } else if (parentNode === startContainer && node === startContainer.childNodes[startOffset]) { 558 accumulator.start = currentLength; 559 } // Selection can be extracted from value. 560 561 562 if (value.end !== undefined) { 563 accumulator.end = currentLength + value.end; // Range indicates that the current node has selection. 564 } else if (node === endContainer) { 565 accumulator.end = currentLength + endOffset; // Range indicates that the current node is selected. 566 } else if (parentNode === endContainer && node === endContainer.childNodes[endOffset - 1]) { 567 accumulator.end = currentLength + value.text.length; // Range indicates that the selection is before the current node. 568 } else if (parentNode === endContainer && node === endContainer.childNodes[endOffset]) { 569 accumulator.end = currentLength; 570 } 571 } 572 /** 573 * Adjusts the start and end offsets from a range based on a text filter. 574 * 575 * @param {Node} node Node of which the text should be filtered. 576 * @param {Range} range The range to filter. 577 * @param {Function} filter Function to use to filter the text. 578 * 579 * @return {?Object} Object containing range properties. 580 */ 581 582 583 function filterRange(node, range, filter) { 584 if (!range) { 585 return; 586 } 587 588 var startContainer = range.startContainer, 589 endContainer = range.endContainer; 590 var startOffset = range.startOffset, 591 endOffset = range.endOffset; 592 593 if (node === startContainer) { 594 startOffset = filter(node.nodeValue.slice(0, startOffset)).length; 595 } 596 597 if (node === endContainer) { 598 endOffset = filter(node.nodeValue.slice(0, endOffset)).length; 599 } 600 601 return { 602 startContainer: startContainer, 603 startOffset: startOffset, 604 endContainer: endContainer, 605 endOffset: endOffset 606 }; 607 } 608 /** 609 * Creates a Rich Text value from a DOM element and range. 610 * 611 * @param {Object} $1 Named argements. 612 * @param {?Element} $1.element Element to create value from. 613 * @param {?Range} $1.range Range to create value from. 614 * @param {?Function} $1.removeNode Function to declare whether the given 615 * node should be removed. 616 * @param {?Function} $1.unwrapNode Function to declare whether the given 617 * node should be unwrapped. 618 * @param {?Function} $1.filterString Function to filter the given string. 619 * @param {?Function} $1.removeAttribute Wether to remove an attribute based on 620 * the name. 621 * 622 * @return {Object} A rich text value. 623 */ 624 625 626 function createFromElement(_ref2) { 627 var element = _ref2.element, 628 range = _ref2.range, 629 removeNode = _ref2.removeNode, 630 unwrapNode = _ref2.unwrapNode, 631 filterString = _ref2.filterString, 632 removeAttribute = _ref2.removeAttribute; 633 var accumulator = createEmptyValue(); 634 635 if (!element) { 636 return accumulator; 637 } 638 639 if (!element.hasChildNodes()) { 640 accumulateSelection(accumulator, element, range, createEmptyValue()); 641 return accumulator; 642 } 643 644 var length = element.childNodes.length; // Remove any line breaks in text nodes. They are not content, but used to 645 // format the HTML. Line breaks in HTML are stored as BR elements. 646 // See https://www.w3.org/TR/html5/syntax.html#newlines. 647 648 var filterStringComplete = function filterStringComplete(string) { 649 string = string.replace(/[\r\n]/g, ''); 650 651 if (filterString) { 652 string = filterString(string); 653 } 654 655 return string; 656 }; // Optimise for speed. 657 658 659 for (var index = 0; index < length; index++) { 660 var node = element.childNodes[index]; 661 662 if (node.nodeType === TEXT_NODE) { 663 var _text = filterStringComplete(node.nodeValue); 664 665 range = filterRange(node, range, filterStringComplete); 666 accumulateSelection(accumulator, node, range, { 667 text: _text 668 }); 669 accumulator.text += _text; // Create a sparse array of the same length as `text`, in which 670 // formats can be added. 671 672 accumulator.formats.length += _text.length; 673 continue; 674 } 675 676 if (node.nodeType !== ELEMENT_NODE) { 677 continue; 678 } 679 680 if (removeNode && removeNode(node) || unwrapNode && unwrapNode(node) && !node.hasChildNodes()) { 681 accumulateSelection(accumulator, node, range, createEmptyValue()); 682 continue; 683 } 684 685 if (node.nodeName === 'BR') { 686 accumulateSelection(accumulator, node, range, createEmptyValue()); 687 accumulator.text += '\n'; 688 accumulator.formats.length += 1; 689 continue; 690 } 691 692 var lastFormats = accumulator.formats[accumulator.formats.length - 1]; 693 var lastFormat = lastFormats && lastFormats[lastFormats.length - 1]; 694 var format = void 0; 695 696 if (!unwrapNode || !unwrapNode(node)) { 697 var type = node.nodeName.toLowerCase(); 698 var attributes = getAttributes({ 699 element: node, 700 removeAttribute: removeAttribute 701 }); 702 var newFormat = attributes ? { 703 type: type, 704 attributes: attributes 705 } : { 706 type: type 707 }; // Reuse the last format if it's equal. 708 709 if (Object(_is_format_equal__WEBPACK_IMPORTED_MODULE_3__["isFormatEqual"])(newFormat, lastFormat)) { 710 format = lastFormat; 711 } else { 712 format = newFormat; 713 } 714 } 715 716 var value = createFromElement({ 717 element: node, 718 range: range, 719 removeNode: removeNode, 720 unwrapNode: unwrapNode, 721 filterString: filterString, 722 removeAttribute: removeAttribute 723 }); 724 var text = value.text; 725 var start = accumulator.text.length; 726 accumulateSelection(accumulator, node, range, value); // Don't apply the element as formatting if it has no content. 727 728 if (Object(_is_empty__WEBPACK_IMPORTED_MODULE_2__["isEmpty"])(value) && format && !format.attributes) { 729 continue; 730 } 731 732 var formats = accumulator.formats; 733 734 if (format && format.attributes && text.length === 0) { 735 format.object = true; // Object replacement character. 736 737 accumulator.text += "\uFFFC"; 738 739 if (formats[start]) { 740 formats[start].unshift(format); 741 } else { 742 formats[start] = [format]; 743 } 744 } else { 745 accumulator.text += text; 746 var i = value.formats.length; // Optimise for speed. 747 748 while (i--) { 749 var formatIndex = start + i; 750 751 if (format) { 752 if (formats[formatIndex]) { 753 formats[formatIndex].push(format); 754 } else { 755 formats[formatIndex] = [format]; 756 } 757 } 758 759 if (value.formats[i]) { 760 if (formats[formatIndex]) { 761 var _formats$formatIndex; 762 763 (_formats$formatIndex = formats[formatIndex]).push.apply(_formats$formatIndex, Object(_babel_runtime_helpers_esm_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__["default"])(value.formats[i])); 764 } else { 765 formats[formatIndex] = value.formats[i]; 766 } 767 } 768 } 769 } 770 } 771 772 return accumulator; 773 } 774 /** 775 * Creates a rich text value from a DOM element and range that should be 776 * multiline. 777 * 778 * @param {Object} $1 Named argements. 779 * @param {?Element} $1.element Element to create value from. 780 * @param {?Range} $1.range Range to create value from. 781 * @param {?string} $1.multilineTag Multiline tag if the structure is 782 * multiline. 783 * @param {?Function} $1.removeNode Function to declare whether the given 784 * node should be removed. 785 * @param {?Function} $1.unwrapNode Function to declare whether the given 786 * node should be unwrapped. 787 * @param {?Function} $1.filterString Function to filter the given string. 788 * @param {?Function} $1.removeAttribute Wether to remove an attribute based on 789 * the name. 790 * 791 * @return {Object} A rich text value. 792 */ 793 794 795 function createFromMultilineElement(_ref3) { 796 var element = _ref3.element, 797 range = _ref3.range, 798 multilineTag = _ref3.multilineTag, 799 removeNode = _ref3.removeNode, 800 unwrapNode = _ref3.unwrapNode, 801 filterString = _ref3.filterString, 802 removeAttribute = _ref3.removeAttribute; 803 var accumulator = createEmptyValue(); 804 805 if (!element || !element.hasChildNodes()) { 806 return accumulator; 807 } 808 809 var length = element.children.length; // Optimise for speed. 810 811 for (var index = 0; index < length; index++) { 812 var node = element.children[index]; 813 814 if (node.nodeName.toLowerCase() !== multilineTag) { 815 continue; 816 } 817 818 var value = createFromElement({ 819 element: node, 820 range: range, 821 multilineTag: multilineTag, 822 removeNode: removeNode, 823 unwrapNode: unwrapNode, 824 filterString: filterString, 825 removeAttribute: removeAttribute 826 }); // Multiline value text should be separated by a double line break. 827 828 if (index !== 0) { 829 accumulator.formats = accumulator.formats.concat([,]); 830 accumulator.text += "\u2028"; 831 } 832 833 accumulateSelection(accumulator, node, range, value); 834 accumulator.formats = accumulator.formats.concat(value.formats); 835 accumulator.text += value.text; 836 } 837 838 return accumulator; 839 } 840 /** 841 * Gets the attributes of an element in object shape. 842 * 843 * @param {Object} $1 Named argements. 844 * @param {Element} $1.element Element to get attributes from. 845 * @param {?Function} $1.removeAttribute Wether to remove an attribute based on 846 * the name. 847 * 848 * @return {?Object} Attribute object or `undefined` if the element has no 849 * attributes. 850 */ 851 852 853 function getAttributes(_ref4) { 854 var element = _ref4.element, 855 removeAttribute = _ref4.removeAttribute; 856 857 if (!element.hasAttributes()) { 858 return; 859 } 860 861 var length = element.attributes.length; 862 var accumulator; // Optimise for speed. 863 864 for (var i = 0; i < length; i++) { 865 var _element$attributes$i = element.attributes[i], 866 name = _element$attributes$i.name, 867 value = _element$attributes$i.value; 868 869 if (removeAttribute && removeAttribute(name)) { 870 continue; 871 } 872 873 accumulator = accumulator || {}; 874 accumulator[name] = value; 875 } 876 877 return accumulator; 878 } 879 880 881 /***/ }), 882 883 /***/ "./node_modules/@wordpress/rich-text/build-module/get-active-format.js": 884 /*!*****************************************************************************!*\ 885 !*** ./node_modules/@wordpress/rich-text/build-module/get-active-format.js ***! 886 \*****************************************************************************/ 887 /*! exports provided: getActiveFormat */ 888 /***/ (function(module, __webpack_exports__, __webpack_require__) { 889 890 "use strict"; 891 __webpack_require__.r(__webpack_exports__); 892 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getActiveFormat", function() { return getActiveFormat; }); 893 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lodash */ "lodash"); 894 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_0__); 895 /** 896 * External dependencies 897 */ 898 899 /** 900 * Gets the format object by type at the start of the selection. This can be 901 * used to get e.g. the URL of a link format at the current selection, but also 902 * to check if a format is active at the selection. Returns undefined if there 903 * is no format at the selection. 904 * 905 * @param {Object} value Value to inspect. 906 * @param {string} formatType Format type to look for. 907 * 908 * @return {?Object} Active format object of the specified type, or undefined. 909 */ 910 911 function getActiveFormat(_ref, formatType) { 912 var formats = _ref.formats, 913 start = _ref.start; 914 915 if (start === undefined) { 916 return; 917 } 918 919 return Object(lodash__WEBPACK_IMPORTED_MODULE_0__["find"])(formats[start], { 920 type: formatType 921 }); 922 } 923 924 925 /***/ }), 926 927 /***/ "./node_modules/@wordpress/rich-text/build-module/get-text-content.js": 928 /*!****************************************************************************!*\ 929 !*** ./node_modules/@wordpress/rich-text/build-module/get-text-content.js ***! 930 \****************************************************************************/ 931 /*! exports provided: getTextContent */ 932 /***/ (function(module, __webpack_exports__, __webpack_require__) { 933 934 "use strict"; 935 __webpack_require__.r(__webpack_exports__); 936 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getTextContent", function() { return getTextContent; }); 937 /** 938 * Get the textual content of a Rich Text value. This is similar to 939 * `Element.textContent`. 940 * 941 * @param {Object} value Value to use. 942 * 943 * @return {string} The text content. 944 */ 945 function getTextContent(_ref) { 946 var text = _ref.text; 947 return text; 948 } 949 950 951 /***/ }), 952 953 /***/ "./node_modules/@wordpress/rich-text/build-module/index.js": 954 /*!*****************************************************************!*\ 955 !*** ./node_modules/@wordpress/rich-text/build-module/index.js ***! 956 \*****************************************************************/ 957 /*! exports provided: applyFormat, concat, create, getActiveFormat, getTextContent, isCollapsed, isEmpty, isEmptyLine, join, removeFormat, remove, replace, insert, slice, split, apply, unstableToDom, toHTMLString */ 958 /***/ (function(module, __webpack_exports__, __webpack_require__) { 959 960 "use strict"; 961 __webpack_require__.r(__webpack_exports__); 962 /* harmony import */ var _apply_format__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./apply-format */ "./node_modules/@wordpress/rich-text/build-module/apply-format.js"); 963 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "applyFormat", function() { return _apply_format__WEBPACK_IMPORTED_MODULE_0__["applyFormat"]; }); 964 965 /* harmony import */ var _concat__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./concat */ "./node_modules/@wordpress/rich-text/build-module/concat.js"); 966 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "concat", function() { return _concat__WEBPACK_IMPORTED_MODULE_1__["concat"]; }); 967 968 /* harmony import */ var _create__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./create */ "./node_modules/@wordpress/rich-text/build-module/create.js"); 969 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "create", function() { return _create__WEBPACK_IMPORTED_MODULE_2__["create"]; }); 970 971 /* harmony import */ var _get_active_format__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./get-active-format */ "./node_modules/@wordpress/rich-text/build-module/get-active-format.js"); 972 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getActiveFormat", function() { return _get_active_format__WEBPACK_IMPORTED_MODULE_3__["getActiveFormat"]; }); 973 974 /* harmony import */ var _get_text_content__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./get-text-content */ "./node_modules/@wordpress/rich-text/build-module/get-text-content.js"); 975 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getTextContent", function() { return _get_text_content__WEBPACK_IMPORTED_MODULE_4__["getTextContent"]; }); 976 977 /* harmony import */ var _is_collapsed__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./is-collapsed */ "./node_modules/@wordpress/rich-text/build-module/is-collapsed.js"); 978 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "isCollapsed", function() { return _is_collapsed__WEBPACK_IMPORTED_MODULE_5__["isCollapsed"]; }); 979 980 /* harmony import */ var _is_empty__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./is-empty */ "./node_modules/@wordpress/rich-text/build-module/is-empty.js"); 981 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "isEmpty", function() { return _is_empty__WEBPACK_IMPORTED_MODULE_6__["isEmpty"]; }); 982 983 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "isEmptyLine", function() { return _is_empty__WEBPACK_IMPORTED_MODULE_6__["isEmptyLine"]; }); 984 985 /* harmony import */ var _join__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./join */ "./node_modules/@wordpress/rich-text/build-module/join.js"); 986 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "join", function() { return _join__WEBPACK_IMPORTED_MODULE_7__["join"]; }); 987 988 /* harmony import */ var _remove_format__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./remove-format */ "./node_modules/@wordpress/rich-text/build-module/remove-format.js"); 989 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "removeFormat", function() { return _remove_format__WEBPACK_IMPORTED_MODULE_8__["removeFormat"]; }); 990 991 /* harmony import */ var _remove__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./remove */ "./node_modules/@wordpress/rich-text/build-module/remove.js"); 992 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "remove", function() { return _remove__WEBPACK_IMPORTED_MODULE_9__["remove"]; }); 993 994 /* harmony import */ var _replace__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./replace */ "./node_modules/@wordpress/rich-text/build-module/replace.js"); 995 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "replace", function() { return _replace__WEBPACK_IMPORTED_MODULE_10__["replace"]; }); 996 997 /* harmony import */ var _insert__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./insert */ "./node_modules/@wordpress/rich-text/build-module/insert.js"); 998 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "insert", function() { return _insert__WEBPACK_IMPORTED_MODULE_11__["insert"]; }); 999 1000 /* harmony import */ var _slice__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./slice */ "./node_modules/@wordpress/rich-text/build-module/slice.js"); 1001 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "slice", function() { return _slice__WEBPACK_IMPORTED_MODULE_12__["slice"]; }); 1002 1003 /* harmony import */ var _split__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./split */ "./node_modules/@wordpress/rich-text/build-module/split.js"); 1004 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "split", function() { return _split__WEBPACK_IMPORTED_MODULE_13__["split"]; }); 1005 1006 /* harmony import */ var _to_dom__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./to-dom */ "./node_modules/@wordpress/rich-text/build-module/to-dom.js"); 1007 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "apply", function() { return _to_dom__WEBPACK_IMPORTED_MODULE_14__["apply"]; }); 1008 1009 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "unstableToDom", function() { return _to_dom__WEBPACK_IMPORTED_MODULE_14__["toDom"]; }); 1010 1011 /* harmony import */ var _to_html_string__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./to-html-string */ "./node_modules/@wordpress/rich-text/build-module/to-html-string.js"); 1012 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "toHTMLString", function() { return _to_html_string__WEBPACK_IMPORTED_MODULE_15__["toHTMLString"]; }); 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 /***/ }), 1033 1034 /***/ "./node_modules/@wordpress/rich-text/build-module/insert.js": 1035 /*!******************************************************************!*\ 1036 !*** ./node_modules/@wordpress/rich-text/build-module/insert.js ***! 1037 \******************************************************************/ 1038 /*! exports provided: insert */ 1039 /***/ (function(module, __webpack_exports__, __webpack_require__) { 1040 1041 "use strict"; 1042 __webpack_require__.r(__webpack_exports__); 1043 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "insert", function() { return insert; }); 1044 /* harmony import */ var _create__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./create */ "./node_modules/@wordpress/rich-text/build-module/create.js"); 1045 /* harmony import */ var _normalise_formats__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./normalise-formats */ "./node_modules/@wordpress/rich-text/build-module/normalise-formats.js"); 1046 /** 1047 * Internal dependencies 1048 */ 1049 1050 1051 /** 1052 * Insert a Rich Text value, an HTML string, or a plain text string, into a 1053 * Rich Text value at the given `startIndex`. Any content between `startIndex` 1054 * and `endIndex` will be removed. Indices are retrieved from the selection if 1055 * none are provided. 1056 * 1057 * @param {Object} value Value to modify. 1058 * @param {string} valueToInsert Value to insert. 1059 * @param {number} startIndex Start index. 1060 * @param {number} endIndex End index. 1061 * 1062 * @return {Object} A new value with the value inserted. 1063 */ 1064 1065 function insert(_ref, valueToInsert) { 1066 var formats = _ref.formats, 1067 text = _ref.text, 1068 start = _ref.start, 1069 end = _ref.end; 1070 var startIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : start; 1071 var endIndex = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : end; 1072 1073 if (typeof valueToInsert === 'string') { 1074 valueToInsert = Object(_create__WEBPACK_IMPORTED_MODULE_0__["create"])({ 1075 text: valueToInsert 1076 }); 1077 } 1078 1079 var index = startIndex + valueToInsert.text.length; 1080 return Object(_normalise_formats__WEBPACK_IMPORTED_MODULE_1__["normaliseFormats"])({ 1081 formats: formats.slice(0, startIndex).concat(valueToInsert.formats, formats.slice(endIndex)), 1082 text: text.slice(0, startIndex) + valueToInsert.text + text.slice(endIndex), 1083 start: index, 1084 end: index 1085 }); 1086 } 1087 1088 1089 /***/ }), 1090 1091 /***/ "./node_modules/@wordpress/rich-text/build-module/is-collapsed.js": 1092 /*!************************************************************************!*\ 1093 !*** ./node_modules/@wordpress/rich-text/build-module/is-collapsed.js ***! 1094 \************************************************************************/ 1095 /*! exports provided: isCollapsed */ 1096 /***/ (function(module, __webpack_exports__, __webpack_require__) { 1097 1098 "use strict"; 1099 __webpack_require__.r(__webpack_exports__); 1100 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isCollapsed", function() { return isCollapsed; }); 1101 /** 1102 * Check if the selection of a Rich Text value is collapsed or not. Collapsed 1103 * means that no characters are selected, but there is a caret present. If there 1104 * is no selection, `undefined` will be returned. This is similar to 1105 * `window.getSelection().isCollapsed()`. 1106 * 1107 * @param {Object} value The rich text value to check. 1108 * 1109 * @return {?boolean} True if the selection is collapsed, false if not, 1110 * undefined if there is no selection. 1111 */ 1112 function isCollapsed(_ref) { 1113 var start = _ref.start, 1114 end = _ref.end; 1115 1116 if (start === undefined || end === undefined) { 1117 return; 1118 } 1119 1120 return start === end; 1121 } 1122 1123 1124 /***/ }), 1125 1126 /***/ "./node_modules/@wordpress/rich-text/build-module/is-empty.js": 1127 /*!********************************************************************!*\ 1128 !*** ./node_modules/@wordpress/rich-text/build-module/is-empty.js ***! 1129 \********************************************************************/ 1130 /*! exports provided: isEmpty, isEmptyLine */ 1131 /***/ (function(module, __webpack_exports__, __webpack_require__) { 1132 1133 "use strict"; 1134 __webpack_require__.r(__webpack_exports__); 1135 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isEmpty", function() { return isEmpty; }); 1136 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isEmptyLine", function() { return isEmptyLine; }); 1137 /** 1138 * Check if a Rich Text value is Empty, meaning it contains no text or any 1139 * objects (such as images). 1140 * 1141 * @param {Object} value Value to use. 1142 * 1143 * @return {boolean} True if the value is empty, false if not. 1144 */ 1145 function isEmpty(_ref) { 1146 var text = _ref.text; 1147 return text.length === 0; 1148 } 1149 /** 1150 * Check if the current collapsed selection is on an empty line in case of a 1151 * multiline value. 1152 * 1153 * @param {Object} value Value te check. 1154 * 1155 * @return {boolean} True if the line is empty, false if not. 1156 */ 1157 1158 function isEmptyLine(_ref2) { 1159 var text = _ref2.text, 1160 start = _ref2.start, 1161 end = _ref2.end; 1162 1163 if (start !== end) { 1164 return false; 1165 } 1166 1167 if (text.length === 0) { 1168 return true; 1169 } 1170 1171 if (start === 0 && text.slice(0, 1) === "\u2028") { 1172 return true; 1173 } 1174 1175 if (start === text.length && text.slice(-1) === "\u2028") { 1176 return true; 1177 } 1178 1179 return text.slice(start - 1, end + 1) === "\u2028\u2028"; 1180 } 1181 1182 1183 /***/ }), 1184 1185 /***/ "./node_modules/@wordpress/rich-text/build-module/is-format-equal.js": 1186 /*!***************************************************************************!*\ 1187 !*** ./node_modules/@wordpress/rich-text/build-module/is-format-equal.js ***! 1188 \***************************************************************************/ 1189 /*! exports provided: isFormatEqual */ 1190 /***/ (function(module, __webpack_exports__, __webpack_require__) { 1191 1192 "use strict"; 1193 __webpack_require__.r(__webpack_exports__); 1194 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isFormatEqual", function() { return isFormatEqual; }); 1195 /** 1196 * Optimised equality check for format objects. 1197 * 1198 * @param {?Object} format1 Format to compare. 1199 * @param {?Object} format2 Format to compare. 1200 * 1201 * @return {boolean} True if formats are equal, false if not. 1202 */ 1203 function isFormatEqual(format1, format2) { 1204 // Both not defined. 1205 if (format1 === format2) { 1206 return true; 1207 } // Either not defined. 1208 1209 1210 if (!format1 || !format2) { 1211 return false; 1212 } 1213 1214 if (format1.type !== format2.type) { 1215 return false; 1216 } 1217 1218 var attributes1 = format1.attributes; 1219 var attributes2 = format2.attributes; // Both not defined. 1220 1221 if (attributes1 === attributes2) { 1222 return true; 1223 } // Either not defined. 1224 1225 1226 if (!attributes1 || !attributes2) { 1227 return false; 1228 } 1229 1230 var keys1 = Object.keys(attributes1); 1231 var keys2 = Object.keys(attributes2); 1232 1233 if (keys1.length !== keys2.length) { 1234 return false; 1235 } 1236 1237 var length = keys1.length; // Optimise for speed. 1238 1239 for (var i = 0; i < length; i++) { 1240 var name = keys1[i]; 1241 1242 if (attributes1[name] !== attributes2[name]) { 1243 return false; 1244 } 1245 } 1246 1247 return true; 1248 } 1249 1250 1251 /***/ }), 1252 1253 /***/ "./node_modules/@wordpress/rich-text/build-module/join.js": 1254 /*!****************************************************************!*\ 1255 !*** ./node_modules/@wordpress/rich-text/build-module/join.js ***! 1256 \****************************************************************/ 1257 /*! exports provided: join */ 1258 /***/ (function(module, __webpack_exports__, __webpack_require__) { 1259 1260 "use strict"; 1261 __webpack_require__.r(__webpack_exports__); 1262 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "join", function() { return join; }); 1263 /* harmony import */ var _create__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./create */ "./node_modules/@wordpress/rich-text/build-module/create.js"); 1264 /* harmony import */ var _normalise_formats__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./normalise-formats */ "./node_modules/@wordpress/rich-text/build-module/normalise-formats.js"); 1265 /** 1266 * Internal dependencies 1267 */ 1268 1269 1270 /** 1271 * Combine an array of Rich Text values into one, optionally separated by 1272 * `separator`, which can be a Rich Text value, HTML string, or plain text 1273 * string. This is similar to `Array.prototype.join`. 1274 * 1275 * @param {Array} values An array of values to join. 1276 * @param {string|Object} separator Separator string or value. 1277 * 1278 * @return {Object} A new combined value. 1279 */ 1280 1281 function join(values) { 1282 var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; 1283 1284 if (typeof separator === 'string') { 1285 separator = Object(_create__WEBPACK_IMPORTED_MODULE_0__["create"])({ 1286 text: separator 1287 }); 1288 } 1289 1290 return Object(_normalise_formats__WEBPACK_IMPORTED_MODULE_1__["normaliseFormats"])(values.reduce(function (accumlator, _ref) { 1291 var formats = _ref.formats, 1292 text = _ref.text; 1293 return { 1294 text: accumlator.text + separator.text + text, 1295 formats: accumlator.formats.concat(separator.formats, formats) 1296 }; 1297 })); 1298 } 1299 1300 1301 /***/ }), 1302 1303 /***/ "./node_modules/@wordpress/rich-text/build-module/normalise-formats.js": 1304 /*!*****************************************************************************!*\ 1305 !*** ./node_modules/@wordpress/rich-text/build-module/normalise-formats.js ***! 1306 \*****************************************************************************/ 1307 /*! exports provided: normaliseFormats */ 1308 /***/ (function(module, __webpack_exports__, __webpack_require__) { 1309 1310 "use strict"; 1311 __webpack_require__.r(__webpack_exports__); 1312 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "normaliseFormats", function() { return normaliseFormats; }); 1313 /* harmony import */ var _is_format_equal__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./is-format-equal */ "./node_modules/@wordpress/rich-text/build-module/is-format-equal.js"); 1314 /** 1315 * Internal dependencies 1316 */ 1317 1318 /** 1319 * Normalises formats: ensures subsequent equal formats have the same reference. 1320 * 1321 * @param {Object} value Value to normalise formats of. 1322 * 1323 * @return {Object} New value with normalised formats. 1324 */ 1325 1326 function normaliseFormats(_ref) { 1327 var formats = _ref.formats, 1328 text = _ref.text, 1329 start = _ref.start, 1330 end = _ref.end; 1331 var newFormats = formats.slice(0); 1332 newFormats.forEach(function (formatsAtIndex, index) { 1333 var lastFormatsAtIndex = newFormats[index - 1]; 1334 1335 if (lastFormatsAtIndex) { 1336 var newFormatsAtIndex = formatsAtIndex.slice(0); 1337 newFormatsAtIndex.forEach(function (format, formatIndex) { 1338 var lastFormat = lastFormatsAtIndex[formatIndex]; 1339 1340 if (Object(_is_format_equal__WEBPACK_IMPORTED_MODULE_0__["isFormatEqual"])(format, lastFormat)) { 1341 newFormatsAtIndex[formatIndex] = lastFormat; 1342 } 1343 }); 1344 newFormats[index] = newFormatsAtIndex; 1345 } 1346 }); 1347 return { 1348 formats: newFormats, 1349 text: text, 1350 start: start, 1351 end: end 1352 }; 1353 } 1354 1355 1356 /***/ }), 1357 1358 /***/ "./node_modules/@wordpress/rich-text/build-module/remove-format.js": 1359 /*!*************************************************************************!*\ 1360 !*** ./node_modules/@wordpress/rich-text/build-module/remove-format.js ***! 1361 \*************************************************************************/ 1362 /*! exports provided: removeFormat */ 1363 /***/ (function(module, __webpack_exports__, __webpack_require__) { 1364 1365 "use strict"; 1366 __webpack_require__.r(__webpack_exports__); 1367 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "removeFormat", function() { return removeFormat; }); 1368 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lodash */ "lodash"); 1369 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_0__); 1370 /* harmony import */ var _normalise_formats__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./normalise-formats */ "./node_modules/@wordpress/rich-text/build-module/normalise-formats.js"); 1371 /** 1372 * External dependencies 1373 */ 1374 1375 /** 1376 * Internal dependencies 1377 */ 1378 1379 1380 /** 1381 * Remove any format object from a Rich Text value by type from the given 1382 * `startIndex` to the given `endIndex`. Indices are retrieved from the 1383 * selection if none are provided. 1384 * 1385 * @param {Object} value Value to modify. 1386 * @param {string} formatType Format type to remove. 1387 * @param {number} startIndex Start index. 1388 * @param {number} endIndex End index. 1389 * 1390 * @return {Object} A new value with the format applied. 1391 */ 1392 1393 function removeFormat(_ref, formatType) { 1394 var formats = _ref.formats, 1395 text = _ref.text, 1396 start = _ref.start, 1397 end = _ref.end; 1398 var startIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : start; 1399 var endIndex = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : end; 1400 var newFormats = formats.slice(0); // If the selection is collapsed, expand start and end to the edges of the 1401 // format. 1402 1403 if (startIndex === endIndex) { 1404 var format = Object(lodash__WEBPACK_IMPORTED_MODULE_0__["find"])(newFormats[startIndex], { 1405 type: formatType 1406 }); 1407 1408 while (Object(lodash__WEBPACK_IMPORTED_MODULE_0__["find"])(newFormats[startIndex], format)) { 1409 filterFormats(newFormats, startIndex, formatType); 1410 startIndex--; 1411 } 1412 1413 endIndex++; 1414 1415 while (Object(lodash__WEBPACK_IMPORTED_MODULE_0__["find"])(newFormats[endIndex], format)) { 1416 filterFormats(newFormats, endIndex, formatType); 1417 endIndex++; 1418 } 1419 } else { 1420 for (var i = startIndex; i < endIndex; i++) { 1421 if (newFormats[i]) { 1422 filterFormats(newFormats, i, formatType); 1423 } 1424 } 1425 } 1426 1427 return Object(_normalise_formats__WEBPACK_IMPORTED_MODULE_1__["normaliseFormats"])({ 1428 formats: newFormats, 1429 text: text, 1430 start: start, 1431 end: end 1432 }); 1433 } 1434 1435 function filterFormats(formats, index, formatType) { 1436 var newFormats = formats[index].filter(function (_ref2) { 1437 var type = _ref2.type; 1438 return type !== formatType; 1439 }); 1440 1441 if (newFormats.length) { 1442 formats[index] = newFormats; 1443 } else { 1444 delete formats[index]; 1445 } 1446 } 1447 1448 1449 /***/ }), 1450 1451 /***/ "./node_modules/@wordpress/rich-text/build-module/remove.js": 1452 /*!******************************************************************!*\ 1453 !*** ./node_modules/@wordpress/rich-text/build-module/remove.js ***! 1454 \******************************************************************/ 1455 /*! exports provided: remove */ 1456 /***/ (function(module, __webpack_exports__, __webpack_require__) { 1457 1458 "use strict"; 1459 __webpack_require__.r(__webpack_exports__); 1460 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "remove", function() { return remove; }); 1461 /* harmony import */ var _insert__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./insert */ "./node_modules/@wordpress/rich-text/build-module/insert.js"); 1462 /* harmony import */ var _create__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./create */ "./node_modules/@wordpress/rich-text/build-module/create.js"); 1463 /** 1464 * Internal dependencies 1465 */ 1466 1467 1468 /** 1469 * Remove content from a Rich Text value between the given `startIndex` and 1470 * `endIndex`. Indices are retrieved from the selection if none are provided. 1471 * 1472 * @param {Object} value Value to modify. 1473 * @param {number} startIndex Start index. 1474 * @param {number} endIndex End index. 1475 * 1476 * @return {Object} A new value with the content removed. 1477 */ 1478 1479 function remove(value, startIndex, endIndex) { 1480 return Object(_insert__WEBPACK_IMPORTED_MODULE_0__["insert"])(value, Object(_create__WEBPACK_IMPORTED_MODULE_1__["create"])(), startIndex, endIndex); 1481 } 1482 1483 1484 /***/ }), 1485 1486 /***/ "./node_modules/@wordpress/rich-text/build-module/replace.js": 1487 /*!*******************************************************************!*\ 1488 !*** ./node_modules/@wordpress/rich-text/build-module/replace.js ***! 1489 \*******************************************************************/ 1490 /*! exports provided: replace */ 1491 /***/ (function(module, __webpack_exports__, __webpack_require__) { 1492 1493 "use strict"; 1494 __webpack_require__.r(__webpack_exports__); 1495 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "replace", function() { return replace; }); 1496 /* harmony import */ var _babel_runtime_helpers_esm_typeof__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/esm/typeof */ "./node_modules/@babel/runtime/helpers/esm/typeof.js"); 1497 /* harmony import */ var _normalise_formats__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./normalise-formats */ "./node_modules/@wordpress/rich-text/build-module/normalise-formats.js"); 1498 1499 1500 /** 1501 * Internal dependencies 1502 */ 1503 1504 /** 1505 * Search a Rich Text value and replace the match(es) with `replacement`. This 1506 * is similar to `String.prototype.replace`. 1507 * 1508 * @param {Object} value The value to modify. 1509 * @param {RegExp|string} pattern A RegExp object or literal. Can also be 1510 * a string. It is treated as a verbatim 1511 * string and is not interpreted as a 1512 * regular expression. Only the first 1513 * occurrence will be replaced. 1514 * @param {Function|string} replacement The match or matches are replaced with 1515 * the specified or the value returned by 1516 * the specified function. 1517 * 1518 * @return {Object} A new value with replacements applied. 1519 */ 1520 1521 function replace(_ref, pattern, replacement) { 1522 var formats = _ref.formats, 1523 text = _ref.text, 1524 start = _ref.start, 1525 end = _ref.end; 1526 text = text.replace(pattern, function (match) { 1527 for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { 1528 rest[_key - 1] = arguments[_key]; 1529 } 1530 1531 var offset = rest[rest.length - 2]; 1532 var newText = replacement; 1533 var newFormats; 1534 1535 if (typeof newText === 'function') { 1536 newText = replacement.apply(void 0, [match].concat(rest)); 1537 } 1538 1539 if (Object(_babel_runtime_helpers_esm_typeof__WEBPACK_IMPORTED_MODULE_0__["default"])(newText) === 'object') { 1540 newFormats = newText.formats; 1541 newText = newText.text; 1542 } else { 1543 newFormats = Array(newText.length); 1544 1545 if (formats[offset]) { 1546 newFormats = newFormats.fill(formats[offset]); 1547 } 1548 } 1549 1550 formats = formats.slice(0, offset).concat(newFormats, formats.slice(offset + match.length)); 1551 1552 if (start) { 1553 start = end = offset + newText.length; 1554 } 1555 1556 return newText; 1557 }); 1558 return Object(_normalise_formats__WEBPACK_IMPORTED_MODULE_1__["normaliseFormats"])({ 1559 formats: formats, 1560 text: text, 1561 start: start, 1562 end: end 1563 }); 1564 } 1565 1566 1567 /***/ }), 1568 1569 /***/ "./node_modules/@wordpress/rich-text/build-module/slice.js": 1570 /*!*****************************************************************!*\ 1571 !*** ./node_modules/@wordpress/rich-text/build-module/slice.js ***! 1572 \*****************************************************************/ 1573 /*! exports provided: slice */ 1574 /***/ (function(module, __webpack_exports__, __webpack_require__) { 1575 1576 "use strict"; 1577 __webpack_require__.r(__webpack_exports__); 1578 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "slice", function() { return slice; }); 1579 /** 1580 * Slice a Rich Text value from `startIndex` to `endIndex`. Indices are 1581 * retrieved from the selection if none are provided. This is similar to 1582 * `String.prototype.slice`. 1583 * 1584 * @param {Object} value Value to modify. 1585 * @param {number} startIndex Start index. 1586 * @param {number} endIndex End index. 1587 * 1588 * @return {Object} A new extracted value. 1589 */ 1590 function slice(_ref) { 1591 var formats = _ref.formats, 1592 text = _ref.text, 1593 start = _ref.start, 1594 end = _ref.end; 1595 var startIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : start; 1596 var endIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : end; 1597 1598 if (startIndex === undefined || endIndex === undefined) { 1599 return { 1600 formats: formats, 1601 text: text 1602 }; 1603 } 1604 1605 return { 1606 formats: formats.slice(startIndex, endIndex), 1607 text: text.slice(startIndex, endIndex) 1608 }; 1609 } 1610 1611 1612 /***/ }), 1613 1614 /***/ "./node_modules/@wordpress/rich-text/build-module/split.js": 1615 /*!*****************************************************************!*\ 1616 !*** ./node_modules/@wordpress/rich-text/build-module/split.js ***! 1617 \*****************************************************************/ 1618 /*! exports provided: split */ 1619 /***/ (function(module, __webpack_exports__, __webpack_require__) { 1620 1621 "use strict"; 1622 __webpack_require__.r(__webpack_exports__); 1623 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "split", function() { return split; }); 1624 /* harmony import */ var _replace__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./replace */ "./node_modules/@wordpress/rich-text/build-module/replace.js"); 1625 /** 1626 * Internal dependencies 1627 */ 1628 1629 /** 1630 * Split a Rich Text value in two at the given `startIndex` and `endIndex`, or 1631 * split at the given separator. This is similar to `String.prototype.split`. 1632 * Indices are retrieved from the selection if none are provided. 1633 * 1634 * @param {Object} value Value to modify. 1635 * @param {number|string} string Start index, or string at which to split. 1636 * @param {number} end End index. 1637 * 1638 * @return {Array} An array of new values. 1639 */ 1640 1641 function split(_ref, string) { 1642 var formats = _ref.formats, 1643 text = _ref.text, 1644 start = _ref.start, 1645 end = _ref.end; 1646 1647 if (typeof string !== 'string') { 1648 return splitAtSelection.apply(void 0, arguments); 1649 } 1650 1651 var nextStart = 0; 1652 return text.split(string).map(function (substring) { 1653 var startIndex = nextStart; 1654 var value = { 1655 formats: formats.slice(startIndex, startIndex + substring.length), 1656 text: substring 1657 }; 1658 nextStart += string.length + substring.length; 1659 1660 if (start !== undefined && end !== undefined) { 1661 if (start >= startIndex && start < nextStart) { 1662 value.start = start - startIndex; 1663 } else if (start < startIndex && end > startIndex) { 1664 value.start = 0; 1665 } 1666 1667 if (end >= startIndex && end < nextStart) { 1668 value.end = end - startIndex; 1669 } else if (start < nextStart && end > nextStart) { 1670 value.end = substring.length; 1671 } 1672 } 1673 1674 return value; 1675 }); 1676 } 1677 1678 function splitAtSelection(_ref2) { 1679 var formats = _ref2.formats, 1680 text = _ref2.text, 1681 start = _ref2.start, 1682 end = _ref2.end; 1683 var startIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : start; 1684 var endIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : end; 1685 var before = { 1686 formats: formats.slice(0, startIndex), 1687 text: text.slice(0, startIndex) 1688 }; 1689 var after = { 1690 formats: formats.slice(endIndex), 1691 text: text.slice(endIndex), 1692 start: 0, 1693 end: 0 1694 }; 1695 return [// Ensure newlines are trimmed. 1696 Object(_replace__WEBPACK_IMPORTED_MODULE_0__["replace"])(before, /\u2028+$/, ''), Object(_replace__WEBPACK_IMPORTED_MODULE_0__["replace"])(after, /^\u2028+/, '')]; 1697 } 1698 1699 1700 /***/ }), 1701 1702 /***/ "./node_modules/@wordpress/rich-text/build-module/to-dom.js": 1703 /*!******************************************************************!*\ 1704 !*** ./node_modules/@wordpress/rich-text/build-module/to-dom.js ***! 1705 \******************************************************************/ 1706 /*! exports provided: toDom, apply, applyValue, applySelection */ 1707 /***/ (function(module, __webpack_exports__, __webpack_require__) { 1708 1709 "use strict"; 1710 __webpack_require__.r(__webpack_exports__); 1711 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "toDom", function() { return toDom; }); 1712 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "apply", function() { return apply; }); 1713 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "applyValue", function() { return applyValue; }); 1714 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "applySelection", function() { return applySelection; }); 1715 /* harmony import */ var _babel_runtime_helpers_esm_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/esm/toConsumableArray */ "./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js"); 1716 /* harmony import */ var _to_tree__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./to-tree */ "./node_modules/@wordpress/rich-text/build-module/to-tree.js"); 1717 1718 1719 /** 1720 * Internal dependencies 1721 */ 1722 1723 /** 1724 * Browser dependencies 1725 */ 1726 1727 var _window$Node = window.Node, 1728 TEXT_NODE = _window$Node.TEXT_NODE, 1729 ELEMENT_NODE = _window$Node.ELEMENT_NODE; 1730 /** 1731 * Creates a path as an array of indices from the given root node to the given 1732 * node. 1733 * 1734 * @param {Node} node Node to find the path of. 1735 * @param {HTMLElement} rootNode Root node to find the path from. 1736 * @param {Array} path Initial path to build on. 1737 * 1738 * @return {Array} The path from the root node to the node. 1739 */ 1740 1741 function createPathToNode(node, rootNode, path) { 1742 var parentNode = node.parentNode; 1743 var i = 0; 1744 1745 while (node = node.previousSibling) { 1746 i++; 1747 } 1748 1749 path = [i].concat(Object(_babel_runtime_helpers_esm_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__["default"])(path)); 1750 1751 if (parentNode !== rootNode) { 1752 path = createPathToNode(parentNode, rootNode, path); 1753 } 1754 1755 return path; 1756 } 1757 /** 1758 * Gets a node given a path (array of indices) from the given node. 1759 * 1760 * @param {HTMLElement} node Root node to find the wanted node in. 1761 * @param {Array} path Path (indices) to the wanted node. 1762 * 1763 * @return {Object} Object with the found node and the remaining offset (if any). 1764 */ 1765 1766 1767 function getNodeByPath(node, path) { 1768 path = Object(_babel_runtime_helpers_esm_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__["default"])(path); 1769 1770 while (node && path.length > 1) { 1771 node = node.childNodes[path.shift()]; 1772 } 1773 1774 return { 1775 node: node, 1776 offset: path[0] 1777 }; 1778 } 1779 1780 function createEmpty(type) { 1781 var _document$implementat = document.implementation.createHTMLDocument(''), 1782 body = _document$implementat.body; 1783 1784 if (type) { 1785 return body.appendChild(body.ownerDocument.createElement(type)); 1786 } 1787 1788 return body; 1789 } 1790 1791 function append(element, child) { 1792 if (typeof child === 'string') { 1793 child = element.ownerDocument.createTextNode(child); 1794 } 1795 1796 var _child = child, 1797 type = _child.type, 1798 attributes = _child.attributes; 1799 1800 if (type) { 1801 child = element.ownerDocument.createElement(type); 1802 1803 for (var key in attributes) { 1804 child.setAttribute(key, attributes[key]); 1805 } 1806 } 1807 1808 return element.appendChild(child); 1809 } 1810 1811 function appendText(node, text) { 1812 node.appendData(text); 1813 } 1814 1815 function getLastChild(_ref) { 1816 var lastChild = _ref.lastChild; 1817 return lastChild; 1818 } 1819 1820 function getParent(_ref2) { 1821 var parentNode = _ref2.parentNode; 1822 return parentNode; 1823 } 1824 1825 function isText(_ref3) { 1826 var nodeType = _ref3.nodeType; 1827 return nodeType === TEXT_NODE; 1828 } 1829 1830 function getText(_ref4) { 1831 var nodeValue = _ref4.nodeValue; 1832 return nodeValue; 1833 } 1834 1835 function remove(node) { 1836 return node.parentNode.removeChild(node); 1837 } 1838 1839 function toDom(value, multilineTag) { 1840 var startPath = []; 1841 var endPath = []; 1842 var tree = Object(_to_tree__WEBPACK_IMPORTED_MODULE_1__["toTree"])(value, multilineTag, { 1843 createEmpty: createEmpty, 1844 append: append, 1845 getLastChild: getLastChild, 1846 getParent: getParent, 1847 isText: isText, 1848 getText: getText, 1849 remove: remove, 1850 appendText: appendText, 1851 onStartIndex: function onStartIndex(body, pointer, multilineIndex) { 1852 startPath = createPathToNode(pointer, body, [pointer.nodeValue.length]); 1853 1854 if (multilineIndex !== undefined) { 1855 startPath = [multilineIndex].concat(Object(_babel_runtime_helpers_esm_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__["default"])(startPath)); 1856 } 1857 }, 1858 onEndIndex: function onEndIndex(body, pointer, multilineIndex) { 1859 endPath = createPathToNode(pointer, body, [pointer.nodeValue.length]); 1860 1861 if (multilineIndex !== undefined) { 1862 endPath = [multilineIndex].concat(Object(_babel_runtime_helpers_esm_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__["default"])(endPath)); 1863 } 1864 }, 1865 onEmpty: function onEmpty(body) { 1866 var br = body.ownerDocument.createElement('br'); 1867 br.setAttribute('data-mce-bogus', '1'); 1868 body.appendChild(br); 1869 } 1870 }); 1871 return { 1872 body: tree, 1873 selection: { 1874 startPath: startPath, 1875 endPath: endPath 1876 } 1877 }; 1878 } 1879 /** 1880 * Create an `Element` tree from a Rich Text value and applies the difference to 1881 * the `Element` tree contained by `current`. If a `multilineTag` is provided, 1882 * text separated by two new lines will be wrapped in an `Element` of that type. 1883 * 1884 * @param {Object} value Value to apply. 1885 * @param {HTMLElement} current The live root node to apply the element 1886 * tree to. 1887 * @param {string} multilineTag Multiline tag. 1888 */ 1889 1890 function apply(value, current, multilineTag) { 1891 // Construct a new element tree in memory. 1892 var _toDom = toDom(value, multilineTag), 1893 body = _toDom.body, 1894 selection = _toDom.selection; 1895 1896 applyValue(body, current); 1897 1898 if (value.start !== undefined) { 1899 applySelection(selection, current); 1900 } 1901 } 1902 function applyValue(future, current) { 1903 var i = 0; 1904 1905 while (future.firstChild) { 1906 var currentChild = current.childNodes[i]; 1907 var futureNodeType = future.firstChild.nodeType; 1908 1909 if (!currentChild) { 1910 current.appendChild(future.firstChild); 1911 } else if (futureNodeType !== currentChild.nodeType || futureNodeType !== TEXT_NODE || future.firstChild.nodeValue !== currentChild.nodeValue) { 1912 current.replaceChild(future.firstChild, currentChild); 1913 } else { 1914 future.removeChild(future.firstChild); 1915 } 1916 1917 i++; 1918 } 1919 1920 while (current.childNodes[i]) { 1921 current.removeChild(current.childNodes[i]); 1922 } 1923 } 1924 function applySelection(selection, current) { 1925 var _getNodeByPath = getNodeByPath(current, selection.startPath), 1926 startContainer = _getNodeByPath.node, 1927 startOffset = _getNodeByPath.offset; 1928 1929 var _getNodeByPath2 = getNodeByPath(current, selection.endPath), 1930 endContainer = _getNodeByPath2.node, 1931 endOffset = _getNodeByPath2.offset; 1932 1933 var windowSelection = window.getSelection(); 1934 var range = current.ownerDocument.createRange(); 1935 var collapsed = startContainer === endContainer && startOffset === endOffset; 1936 1937 if (collapsed && startOffset === 0 && startContainer.previousSibling && startContainer.previousSibling.nodeType === ELEMENT_NODE && startContainer.previousSibling.nodeName !== 'BR') { 1938 startContainer.insertData(0, "\uFEFF"); 1939 range.setStart(startContainer, 1); 1940 range.setEnd(endContainer, 1); 1941 } else if (collapsed && startOffset === 0 && startContainer === TEXT_NODE && startContainer.nodeValue.length === 0) { 1942 startContainer.insertData(0, "\uFEFF"); 1943 range.setStart(startContainer, 1); 1944 range.setEnd(endContainer, 1); 1945 } else { 1946 range.setStart(startContainer, startOffset); 1947 range.setEnd(endContainer, endOffset); 1948 } 1949 1950 windowSelection.removeAllRanges(); 1951 windowSelection.addRange(range); 1952 } 1953 1954 1955 /***/ }), 1956 1957 /***/ "./node_modules/@wordpress/rich-text/build-module/to-html-string.js": 1958 /*!**************************************************************************!*\ 1959 !*** ./node_modules/@wordpress/rich-text/build-module/to-html-string.js ***! 1960 \**************************************************************************/ 1961 /*! exports provided: toHTMLString */ 1962 /***/ (function(module, __webpack_exports__, __webpack_require__) { 1963 1964 "use strict"; 1965 __webpack_require__.r(__webpack_exports__); 1966 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "toHTMLString", function() { return toHTMLString; }); 1967 /* harmony import */ var _wordpress_escape_html__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/escape-html */ "@wordpress/escape-html"); 1968 /* harmony import */ var _wordpress_escape_html__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_escape_html__WEBPACK_IMPORTED_MODULE_0__); 1969 /* harmony import */ var _to_tree__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./to-tree */ "./node_modules/@wordpress/rich-text/build-module/to-tree.js"); 1970 /** 1971 * Internal dependencies 1972 */ 1973 1974 /** 1975 * Internal dependencies 1976 */ 1977 1978 1979 /** 1980 * Create an HTML string from a Rich Text value. If a `multilineTag` is 1981 * provided, text separated by two new lines will be wrapped in it. 1982 * 1983 * @param {Object} value Rich text value. 1984 * @param {string} multilineTag Multiline tag. 1985 * 1986 * @return {string} HTML string. 1987 */ 1988 1989 function toHTMLString(value, multilineTag) { 1990 var tree = Object(_to_tree__WEBPACK_IMPORTED_MODULE_1__["toTree"])(value, multilineTag, { 1991 createEmpty: createEmpty, 1992 append: append, 1993 getLastChild: getLastChild, 1994 getParent: getParent, 1995 isText: isText, 1996 getText: getText, 1997 remove: remove, 1998 appendText: appendText 1999 }); 2000 return createChildrenHTML(tree.children); 2001 } 2002 2003 function createEmpty(type) { 2004 return { 2005 type: type 2006 }; 2007 } 2008 2009 function getLastChild(_ref) { 2010 var children = _ref.children; 2011 return children && children[children.length - 1]; 2012 } 2013 2014 function append(parent, object) { 2015 if (typeof object === 'string') { 2016 object = { 2017 text: object 2018 }; 2019 } 2020 2021 object.parent = parent; 2022 parent.children = parent.children || []; 2023 parent.children.push(object); 2024 return object; 2025 } 2026 2027 function appendText(object, text) { 2028 object.text += text; 2029 } 2030 2031 function getParent(_ref2) { 2032 var parent = _ref2.parent; 2033 return parent; 2034 } 2035 2036 function isText(_ref3) { 2037 var text = _ref3.text; 2038 return typeof text === 'string'; 2039 } 2040 2041 function getText(_ref4) { 2042 var text = _ref4.text; 2043 return text; 2044 } 2045 2046 function remove(object) { 2047 var index = object.parent.children.indexOf(object); 2048 2049 if (index !== -1) { 2050 object.parent.children.splice(index, 1); 2051 } 2052 2053 return object; 2054 } 2055 2056 function createElementHTML(_ref5) { 2057 var type = _ref5.type, 2058 attributes = _ref5.attributes, 2059 object = _ref5.object, 2060 children = _ref5.children; 2061 var attributeString = ''; 2062 2063 for (var key in attributes) { 2064 attributeString += " ".concat(key, "=\"").concat(Object(_wordpress_escape_html__WEBPACK_IMPORTED_MODULE_0__["escapeAttribute"])(attributes[key]), "\""); 2065 } 2066 2067 if (object) { 2068 return "<".concat(type).concat(attributeString, ">"); 2069 } 2070 2071 return "<".concat(type).concat(attributeString, ">").concat(createChildrenHTML(children), "</").concat(type, ">"); 2072 } 2073 2074 function createChildrenHTML() { 2075 var children = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; 2076 return children.map(function (child) { 2077 return child.text === undefined ? createElementHTML(child) : Object(_wordpress_escape_html__WEBPACK_IMPORTED_MODULE_0__["escapeHTML"])(child.text); 2078 }).join(''); 2079 } 2080 2081 2082 /***/ }), 2083 2084 /***/ "./node_modules/@wordpress/rich-text/build-module/to-tree.js": 2085 /*!*******************************************************************!*\ 2086 !*** ./node_modules/@wordpress/rich-text/build-module/to-tree.js ***! 2087 \*******************************************************************/ 2088 /*! exports provided: toTree */ 2089 /***/ (function(module, __webpack_exports__, __webpack_require__) { 2090 2091 "use strict"; 2092 __webpack_require__.r(__webpack_exports__); 2093 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "toTree", function() { return toTree; }); 2094 /* harmony import */ var _babel_runtime_helpers_esm_objectSpread__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/esm/objectSpread */ "./node_modules/@babel/runtime/helpers/esm/objectSpread.js"); 2095 /* harmony import */ var _split__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./split */ "./node_modules/@wordpress/rich-text/build-module/split.js"); 2096 2097 2098 /** 2099 * Internal dependencies 2100 */ 2101 2102 function toTree(value, multilineTag, settings) { 2103 if (multilineTag) { 2104 var _createEmpty = settings.createEmpty, 2105 _append = settings.append; 2106 2107 var _tree = _createEmpty(); 2108 2109 Object(_split__WEBPACK_IMPORTED_MODULE_1__["split"])(value, "\u2028").forEach(function (piece, index) { 2110 _append(_tree, toTree(piece, null, Object(_babel_runtime_helpers_esm_objectSpread__WEBPACK_IMPORTED_MODULE_0__["default"])({}, settings, { 2111 tag: multilineTag, 2112 multilineIndex: index 2113 }))); 2114 }); 2115 return _tree; 2116 } 2117 2118 var tag = settings.tag, 2119 multilineIndex = settings.multilineIndex, 2120 createEmpty = settings.createEmpty, 2121 append = settings.append, 2122 getLastChild = settings.getLastChild, 2123 getParent = settings.getParent, 2124 isText = settings.isText, 2125 getText = settings.getText, 2126 remove = settings.remove, 2127 appendText = settings.appendText, 2128 onStartIndex = settings.onStartIndex, 2129 onEndIndex = settings.onEndIndex, 2130 onEmpty = settings.onEmpty; 2131 var formats = value.formats, 2132 text = value.text, 2133 start = value.start, 2134 end = value.end; 2135 var formatsLength = formats.length + 1; 2136 var tree = createEmpty(tag); 2137 append(tree, ''); 2138 2139 var _loop = function _loop(i) { 2140 var character = text.charAt(i); 2141 var characterFormats = formats[i]; 2142 var lastCharacterFormats = formats[i - 1]; 2143 var pointer = getLastChild(tree); 2144 2145 if (characterFormats) { 2146 characterFormats.forEach(function (format, formatIndex) { 2147 if (pointer && lastCharacterFormats && format === lastCharacterFormats[formatIndex]) { 2148 pointer = getLastChild(pointer); 2149 return; 2150 } 2151 2152 var type = format.type, 2153 attributes = format.attributes, 2154 object = format.object; 2155 var parent = getParent(pointer); 2156 var newNode = append(parent, { 2157 type: type, 2158 attributes: attributes, 2159 object: object 2160 }); 2161 2162 if (isText(pointer) && getText(pointer).length === 0) { 2163 remove(pointer); 2164 } 2165 2166 pointer = append(object ? parent : newNode, ''); 2167 }); 2168 } // If there is selection at 0, handle it before characters are inserted. 2169 2170 2171 if (onStartIndex && start === 0 && i === 0) { 2172 onStartIndex(tree, pointer, multilineIndex); 2173 } 2174 2175 if (onEndIndex && end === 0 && i === 0) { 2176 onEndIndex(tree, pointer, multilineIndex); 2177 } 2178 2179 if (character !== "\uFFFC") { 2180 if (character === '\n') { 2181 pointer = append(getParent(pointer), { 2182 type: 'br', 2183 object: true 2184 }); // Ensure pointer is text node. 2185 2186 pointer = append(getParent(pointer), ''); 2187 } else if (!isText(pointer)) { 2188 pointer = append(getParent(pointer), character); 2189 } else { 2190 appendText(pointer, character); 2191 } 2192 } 2193 2194 if (onStartIndex && start === i + 1) { 2195 onStartIndex(tree, pointer, multilineIndex); 2196 } 2197 2198 if (onEndIndex && end === i + 1) { 2199 onEndIndex(tree, pointer, multilineIndex); 2200 } 2201 }; 2202 2203 for (var i = 0; i < formatsLength; i++) { 2204 _loop(i); 2205 } 2206 2207 if (onEmpty && text.length === 0) { 2208 onEmpty(tree); 2209 } 2210 2211 return tree; 2212 } 2213 2214 2215 /***/ }), 2216 2217 /***/ "@wordpress/escape-html": 2218 /*!*********************************************!*\ 2219 !*** external {"this":["wp","escapeHtml"]} ***! 2220 \*********************************************/ 2221 /*! no static exports found */ 2222 /***/ (function(module, exports) { 2223 2224 (function() { module.exports = this["wp"]["escapeHtml"]; }()); 2225 2226 /***/ }), 2227 2228 /***/ "lodash": 2229 /*!*************************!*\ 2230 !*** external "lodash" ***! 2231 \*************************/ 2232 /*! no static exports found */ 2233 /***/ (function(module, exports) { 2234 2235 (function() { module.exports = this["lodash"]; }()); 2236 2237 /***/ }) 2238 2239 /******/ }); 2240 //# sourceMappingURL=rich-text.js.map
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Jan 7 01:00:05 2019 | Cross-referenced by PHPXref 0.7.1 |