vendor: 6,592 bytes, lines 1-220
1/* 2Trix 2.1.1 3Copyright © 2024 37signals, LLC 4 */ 5(function (global, factory) { 6 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : 7 typeof define === 'function' && define.amd ? define(factory) : 8 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Trix = factory()); 9})(this, (function () { 'use strict'; 10 11 var name = "trix"; 12 var version = "2.1.1"; 13 var description = "A rich text editor for everyday writing"; 14 var main = "dist/trix.umd.min.js"; 15 var module = "dist/trix.esm.min.js"; 16 var style = "dist/trix.css"; 17 var files = [ 18 "dist/*.css", 19 "dist/*.js", 20 "dist/*.map", 21 "src/{inspector,trix}/*.js" 22 ]; 23 var repository = { 24 type: "git", 25 url: "git+https://github.com/basecamp/trix.git" 26 }; 27 var keywords = [ 28 "rich text", 29 "wysiwyg", 30 "editor" 31 ]; 32 var author = "37signals, LLC"; 33 var license = "MIT"; 34 var bugs = { 35 url: "https://github.com/basecamp/trix/issues" 36 }; 37 var homepage = "https://trix-editor.org/"; 38 var devDependencies = { 39 "@babel/core": "^7.16.0", 40 "@babel/preset-env": "^7.16.4", 41 "@rollup/plugin-babel": "^5.3.0", 42 "@rollup/plugin-commonjs": "^22.0.2", 43 "@rollup/plugin-json": "^4.1.0", 44 "@rollup/plugin-node-resolve": "^13.3.0", 45 "@web/dev-server": "^0.1.34", 46 "babel-eslint": "^10.1.0", 47 concurrently: "^7.4.0", 48 eslint: "^7.32.0", 49 esm: "^3.2.25", 50 karma: "6.4.1", 51 "karma-chrome-launcher": "3.2.0", 52 "karma-qunit": "^4.1.2", 53 "karma-sauce-launcher": "^4.3.6", 54 "node-sass": "^7.0.1", 55 qunit: "2.19.1", 56 rangy: "^1.3.0", 57 rollup: "^2.56.3", 58 "rollup-plugin-includepaths": "^0.2.4", 59 "rollup-plugin-terser": "^7.0.2", 60 svgo: "^2.8.0", 61 webdriverio: "^7.19.5" 62 }; 63 var resolutions = { 64 webdriverio: "^7.19.5" 65 }; 66 var scripts = { 67 "build-css": "node-sass --functions=./assets/trix/stylesheets/functions assets/trix.scss dist/trix.css", 68 "build-js": "rollup -c", 69 "build-assets": "cp -f assets/*.html dist/", 70 build: "yarn run build-js && yarn run build-css && yarn run build-assets", 71 watch: "rollup -c -w", 72 lint: "eslint .", 73 pretest: "yarn run lint && yarn run build", 74 test: "karma start", 75 prerelease: "yarn version && yarn test", 76 release: "npm adduser && npm publish", 77 postrelease: "git push && git push --tags", 78 dev: "web-dev-server --app-index index.html --root-dir dist --node-resolve --open", 79 start: "yarn build-assets && concurrently --kill-others --names js,css,dev-server 'yarn watch' 'yarn build-css --watch' 'yarn dev'" 80 }; 81 var _package = { 82 name: name, 83 version: version, 84 description: description, 85 main: main, 86 module: module, 87 style: style, 88 files: files, 89 repository: repository, 90 keywords: keywords, 91 author: author, 92 license: license, 93 bugs: bugs, 94 homepage: homepage, 95 devDependencies: devDependencies, 96 resolutions: resolutions, 97 scripts: scripts 98 }; 99 100 const attachmentSelector = "[data-trix-attachment]"; 101 const attachments = { 102 preview: { 103 presentation: "gallery", 104 caption: { 105 name: true, 106 size: true 107 } 108 }, 109 file: { 110 caption: { 111 size: true 112 } 113 } 114 }; 115 116 const attributes = { 117 default: { 118 tagName: "div", 119 parse: false 120 }, 121 quote: { 122 tagName: "blockquote", 123 nestable: true 124 }, 125 heading1: { 126 tagName: "h1", 127 terminal: true, 128 breakOnReturn: true, 129 group: false 130 }, 131 code: { 132 tagName: "pre", 133 terminal: true, 134 htmlAttributes: ["language"], 135 text: { 136 plaintext: true 137 } 138 }, 139 bulletList: { 140 tagName: "ul", 141 parse: false 142 }, 143 bullet: { 144 tagName: "li", 145 listAttribute: "bulletList", 146 group: false, 147 nestable: true, 148 test(element) { 149 return tagName$1(element.parentNode) === attributes[this.listAttribute].tagName; 150 } 151 }, 152 numberList: { 153 tagName: "ol", 154 parse: false 155 }, 156 number: { 157 tagName: "li", 158 listAttribute: "numberList", 159 group: false, 160 nestable: true, 161 test(element) { 162 return tagName$1(element.parentNode) === attributes[this.listAttribute].tagName; 163 } 164 }, 165 attachmentGallery: { 166 tagName: "div", 167 exclusive: true, 168 terminal: true, 169 parse: false, 170 group: false 171 } 172 }; 173 const tagName$1 = element => { 174 var _element$tagName; 175 return element === null || element === void 0 || (_element$tagName = element.tagName) === null || _element$tagName === void 0 ? void 0 : _element$tagName.toLowerCase(); 176 }; 177 178 const androidVersionMatch = navigator.userAgent.match(/android\s([0-9]+.*Chrome)/i); 179 const androidVersion = androidVersionMatch && parseInt(androidVersionMatch[1]); 180 var browser$1 = { 181 // Android emits composition events when moving the cursor through existing text 182 // Introduced in Chrome 65: https://bugs.chromium.org/p/chromium/issues/detail?id=764439#c9 183 composesExistingText: /Android.*Chrome/.test(navigator.userAgent), 184 // Android 13, especially on Samsung keyboards, emits extra compositionend and beforeinput events 185 // that can make the input handler lose the current selection or enter an infinite input -> render -> input 186 // loop. 187 recentAndroid: androidVersion && androidVersion > 12, 188 samsungAndroid: androidVersion && navigator.userAgent.match(/Android.*SM-/), 189 // IE 11 activates resizing handles on editable elements that have "layout" 190 forcesObjectResizing: /Trident.*rv:11/.test(navigator.userAgent), 191 // https://www.w3.org/TR/input-events-1/ + https://www.w3.org/TR/input-events-2/ 192 supportsInputEvents: typeof InputEvent !== "undefined" && ["data", "getTargetRanges", "inputType"].every(prop => prop in InputEvent.prototype) 193 }; 194 195 var css$3 = { 196 attachment: "attachment", 197 attachmentCaption: "attachment__caption", 198 attachmentCaptionEditor: "attachment__caption-editor", 199 attachmentMetadata: "attachment__metadata", 200 attachmentMetadataContainer: "attachment__metadata-container", 201 attachmentName: "attachment__name", 202 attachmentProgress: "attachment__progress", 203 attachmentSize: "attachment__size", 204 attachmentToolbar: "attachment__toolbar", 205 attachmentGallery: "attachment-gallery" 206 }; 207 208 var lang$1 = { 209 attachFiles: "Attach Files", 210 bold: "Bold", 211 bullets: "Bullets", 212 byte: "Byte", 213 bytes: "Bytes", 214 captionPlaceholder: "Add a captionâ¦", 215 code: "Code", 216 heading1: "Heading", 217 indent: "Increase Level", 218 italic: "Italic", 219 link: "Link", 220 numbers: "Numbers",
vendor: 3,312 bytes, lines 221-329
221 outdent: "Decrease Level", 222 quote: "Quote", 223 redo: "Redo", 224 remove: "Remove", 225 strike: "Strikethrough", 226 undo: "Undo", 227 unlink: "Unlink", 228 url: "URL", 229 urlPlaceholder: "Enter a URLâ¦", 230 GB: "GB", 231 KB: "KB", 232 MB: "MB", 233 PB: "PB", 234 TB: "TB" 235 }; 236 237 /* eslint-disable 238 no-case-declarations, 239 */ 240 const sizes = [lang$1.bytes, lang$1.KB, lang$1.MB, lang$1.GB, lang$1.TB, lang$1.PB]; 241 var file_size_formatting = { 242 prefix: "IEC", 243 precision: 2, 244 formatter(number) { 245 switch (number) { 246 case 0: 247 return "0 ".concat(lang$1.bytes); 248 case 1: 249 return "1 ".concat(lang$1.byte); 250 default: 251 let base; 252 if (this.prefix === "SI") { 253 base = 1000; 254 } else if (this.prefix === "IEC") { 255 base = 1024; 256 } 257 const exp = Math.floor(Math.log(number) / Math.log(base)); 258 const humanSize = number / Math.pow(base, exp); 259 const string = humanSize.toFixed(this.precision); 260 const withoutInsignificantZeros = string.replace(/0*$/, "").replace(/\.$/, ""); 261 return "".concat(withoutInsignificantZeros, " ").concat(sizes[exp]); 262 } 263 } 264 }; 265 266 const ZERO_WIDTH_SPACE = "\uFEFF"; 267 const NON_BREAKING_SPACE = "\u00A0"; 268 const OBJECT_REPLACEMENT_CHARACTER = "\uFFFC"; 269 270 const extend = function (properties) { 271 for (const key in properties) { 272 const value = properties[key]; 273 this[key] = value; 274 } 275 return this; 276 }; 277 278 const html = document.documentElement; 279 const match = html.matches; 280 const handleEvent = function (eventName) { 281 let { 282 onElement, 283 matchingSelector, 284 withCallback, 285 inPhase, 286 preventDefault, 287 times 288 } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 289 const element = onElement ? onElement : html; 290 const selector = matchingSelector; 291 const useCapture = inPhase === "capturing"; 292 const handler = function (event) { 293 if (times != null && --times === 0) { 294 handler.destroy(); 295 } 296 const target = findClosestElementFromNode(event.target, { 297 matchingSelector: selector 298 }); 299 if (target != null) { 300 withCallback === null || withCallback === void 0 || withCallback.call(target, event, target); 301 if (preventDefault) { 302 event.preventDefault(); 303 } 304 } 305 }; 306 handler.destroy = () => element.removeEventListener(eventName, handler, useCapture); 307 element.addEventListener(eventName, handler, useCapture); 308 return handler; 309 }; 310 const handleEventOnce = function (eventName) { 311 let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 312 options.times = 1; 313 return handleEvent(eventName, options); 314 }; 315 const triggerEvent = function (eventName) { 316 let { 317 onElement, 318 bubbles, 319 cancelable, 320 attributes 321 } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 322 const element = onElement != null ? onElement : html; 323 bubbles = bubbles !== false; 324 cancelable = cancelable !== false; 325 const event = document.createEvent("Events"); 326 event.initEvent(eventName, bubbles, cancelable); 327 if (attributes != null) { 328 extend.call(event, attributes); 329 }
vendor: 13,206 bytes, lines 329-630
329 330 return element.dispatchEvent(event); 331 }; 332 const elementMatchesSelector = function (element, selector) { 333 if ((element === null || element === void 0 ? void 0 : element.nodeType) === 1) { 334 return match.call(element, selector); 335 } 336 }; 337 const findClosestElementFromNode = function (node) { 338 let { 339 matchingSelector, 340 untilNode 341 } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 342 while (node && node.nodeType !== Node.ELEMENT_NODE) { 343 node = node.parentNode; 344 } 345 if (node == null) { 346 return; 347 } 348 if (matchingSelector != null) { 349 if (node.closest && untilNode == null) { 350 return node.closest(matchingSelector); 351 } else { 352 while (node && node !== untilNode) { 353 if (elementMatchesSelector(node, matchingSelector)) { 354 return node; 355 } 356 node = node.parentNode; 357 } 358 } 359 } else { 360 return node; 361 } 362 }; 363 const findInnerElement = function (element) { 364 while ((_element = element) !== null && _element !== void 0 && _element.firstElementChild) { 365 var _element; 366 element = element.firstElementChild; 367 } 368 return element; 369 }; 370 const innerElementIsActive = element => document.activeElement !== element && elementContainsNode(element, document.activeElement); 371 const elementContainsNode = function (element, node) { 372 if (!element || !node) { 373 return; 374 } 375 while (node) { 376 if (node === element) { 377 return true; 378 } 379 node = node.parentNode; 380 } 381 }; 382 const findNodeFromContainerAndOffset = function (container, offset) { 383 if (!container) { 384 return; 385 } 386 if (container.nodeType === Node.TEXT_NODE) { 387 return container; 388 } else if (offset === 0) { 389 return container.firstChild != null ? container.firstChild : container; 390 } else { 391 return container.childNodes.item(offset - 1); 392 } 393 }; 394 const findElementFromContainerAndOffset = function (container, offset) { 395 const node = findNodeFromContainerAndOffset(container, offset); 396 return findClosestElementFromNode(node); 397 }; 398 const findChildIndexOfNode = function (node) { 399 var _node; 400 if (!((_node = node) !== null && _node !== void 0 && _node.parentNode)) { 401 return; 402 } 403 let childIndex = 0; 404 node = node.previousSibling; 405 while (node) { 406 childIndex++; 407 node = node.previousSibling; 408 } 409 return childIndex; 410 }; 411 const removeNode = node => { 412 var _node$parentNode; 413 return node === null || node === void 0 || (_node$parentNode = node.parentNode) === null || _node$parentNode === void 0 ? void 0 : _node$parentNode.removeChild(node); 414 }; 415 const walkTree = function (tree) { 416 let { 417 onlyNodesOfType, 418 usingFilter, 419 expandEntityReferences 420 } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 421 const whatToShow = (() => { 422 switch (onlyNodesOfType) { 423 case "element": 424 return NodeFilter.SHOW_ELEMENT; 425 case "text": 426 return NodeFilter.SHOW_TEXT; 427 case "comment": 428 return NodeFilter.SHOW_COMMENT; 429 default: 430 return NodeFilter.SHOW_ALL; 431 } 432 })(); 433 return document.createTreeWalker(tree, whatToShow, usingFilter != null ? usingFilter : null, expandEntityReferences === true); 434 }; 435 const tagName = element => { 436 var _element$tagName; 437 return element === null || element === void 0 || (_element$tagName = element.tagName) === null || _element$tagName === void 0 ? void 0 : _element$tagName.toLowerCase(); 438 }; 439 const makeElement = function (tag) { 440 let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 441 let key, value; 442 if (typeof tag === "object") { 443 options = tag; 444 tag = options.tagName; 445 } else { 446 options = { 447 attributes: options 448 }; 449 } 450 const element = document.createElement(tag); 451 if (options.editable != null) { 452 if (options.attributes == null) { 453 options.attributes = {}; 454 } 455 options.attributes.contenteditable = options.editable; 456 } 457 if (options.attributes) { 458 for (key in options.attributes) { 459 value = options.attributes[key]; 460 element.setAttribute(key, value); 461 } 462 } 463 if (options.style) { 464 for (key in options.style) { 465 value = options.style[key]; 466 element.style[key] = value; 467 } 468 } 469 if (options.data) { 470 for (key in options.data) { 471 value = options.data[key]; 472 element.dataset[key] = value; 473 } 474 } 475 if (options.className) { 476 options.className.split(" ").forEach(className => { 477 element.classList.add(className); 478 }); 479 } 480 if (options.textContent) { 481 element.textContent = options.textContent; 482 } 483 if (options.childNodes) { 484 [].concat(options.childNodes).forEach(childNode => { 485 element.appendChild(childNode); 486 }); 487 } 488 return element; 489 }; 490 let blockTagNames = undefined; 491 const getBlockTagNames = function () { 492 if (blockTagNames != null) { 493 return blockTagNames; 494 } 495 blockTagNames = []; 496 for (const key in attributes) { 497 const attributes$1 = attributes[key]; 498 if (attributes$1.tagName) { 499 blockTagNames.push(attributes$1.tagName); 500 } 501 } 502 return blockTagNames; 503 }; 504 const nodeIsBlockContainer = node => nodeIsBlockStartComment(node === null || node === void 0 ? void 0 : node.firstChild); 505 const nodeProbablyIsBlockContainer = function (node) { 506 return getBlockTagNames().includes(tagName(node)) && !getBlockTagNames().includes(tagName(node.firstChild)); 507 }; 508 const nodeIsBlockStart = function (node) { 509 let { 510 strict 511 } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { 512 strict: true 513 }; 514 if (strict) { 515 return nodeIsBlockStartComment(node); 516 } else { 517 return nodeIsBlockStartComment(node) || !nodeIsBlockStartComment(node.firstChild) && nodeProbablyIsBlockContainer(node); 518 } 519 }; 520 const nodeIsBlockStartComment = node => nodeIsCommentNode(node) && (node === null || node === void 0 ? void 0 : node.data) === "block"; 521 const nodeIsCommentNode = node => (node === null || node === void 0 ? void 0 : node.nodeType) === Node.COMMENT_NODE; 522 const nodeIsCursorTarget = function (node) { 523 let { 524 name 525 } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 526 if (!node) { 527 return; 528 } 529 if (nodeIsTextNode(node)) { 530 if (node.data === ZERO_WIDTH_SPACE) { 531 if (name) { 532 return node.parentNode.dataset.trixCursorTarget === name; 533 } else { 534 return true; 535 } 536 } 537 } else { 538 return nodeIsCursorTarget(node.firstChild); 539 } 540 }; 541 const nodeIsAttachmentElement = node => elementMatchesSelector(node, attachmentSelector); 542 const nodeIsEmptyTextNode = node => nodeIsTextNode(node) && (node === null || node === void 0 ? void 0 : node.data) === ""; 543 const nodeIsTextNode = node => (node === null || node === void 0 ? void 0 : node.nodeType) === Node.TEXT_NODE; 544 545 const input = { 546 level2Enabled: true, 547 getLevel() { 548 if (this.level2Enabled && browser$1.supportsInputEvents) { 549 return 2; 550 } else { 551 return 0; 552 } 553 }, 554 pickFiles(callback) { 555 const input = makeElement("input", { 556 type: "file", 557 multiple: true, 558 hidden: true, 559 id: this.fileInputId 560 }); 561 input.addEventListener("change", () => { 562 callback(input.files); 563 removeNode(input); 564 }); 565 removeNode(document.getElementById(this.fileInputId)); 566 document.body.appendChild(input); 567 input.click(); 568 } 569 }; 570 571 var key_names = { 572 8: "backspace", 573 9: "tab", 574 13: "return", 575 27: "escape", 576 37: "left", 577 39: "right", 578 46: "delete", 579 68: "d", 580 72: "h", 581 79: "o" 582 }; 583 584 var parser = { 585 removeBlankTableCells: false, 586 tableCellSeparator: " | ", 587 tableRowSeparator: "\n" 588 }; 589 590 var text_attributes = { 591 bold: { 592 tagName: "strong", 593 inheritable: true, 594 parser(element) { 595 const style = window.getComputedStyle(element); 596 return style.fontWeight === "bold" || style.fontWeight >= 600; 597 } 598 }, 599 italic: { 600 tagName: "em", 601 inheritable: true, 602 parser(element) { 603 const style = window.getComputedStyle(element); 604 return style.fontStyle === "italic"; 605 } 606 }, 607 href: { 608 groupTagName: "a", 609 parser(element) { 610 const matchingSelector = "a:not(".concat(attachmentSelector, ")"); 611 const link = element.closest(matchingSelector); 612 if (link) { 613 return link.getAttribute("href"); 614 } 615 } 616 }, 617 strike: { 618 tagName: "del", 619 inheritable: true 620 }, 621 frozen: { 622 style: { 623 backgroundColor: "highlight" 624 } 625 } 626 }; 627 628 var toolbar = { 629 getDefaultHTML() { 630 return "<div class=\"trix-button-row\">\n <span class=\"trix-button-group trix-button-group--text-tools\" data-trix-button-group=\"text-tools\">\n <button type=\"button\" class=\"trix-button trix-button--icon trix-button--icon-bold\" data-trix-attribute=\"bold\" data-trix-key=\"b\" title=\"".concat(lang$1.bold, "\" tabindex=\"-1\">").concat(lang$1.bold, "</button>\n <button type=\"button\" class=\"trix-button trix-button--icon trix-button--icon-italic\" data-trix-attribute=\"italic\" data-trix-key=\"i\" title=\"").concat(lang$1.italic, "\" tabindex=\"-1\">").concat(lang$1.italic, "</button>\n <button type=\"button\" class=\"trix-button trix-button--icon trix-button--icon-strike\" data-trix-attribute=\"strike\" title=\"").concat(lang$1.strike, "\" tabindex=\"-1\">").concat(lang$1.strike, "</button>\n <button type=\"button\" class=\"trix-button trix-button--icon trix-button--icon-link\" data-trix-attribute=\"href\" data-trix-action=\"link\" data-trix-key=\"k\" title=\"").concat(lang$1.link, "\" tabindex=\"-1\">").concat(lang$1.link, "</button>\n </span>\n\n <span class=\"trix-button-group trix-button-group--block-tools\" data-trix-button-group=\"block-tools\">\n <button type=\"button\" class=\"trix-button trix-button--icon trix-button--icon-heading-1\" data-trix-attribute=\"heading1\" title=\"").concat(lang$1.heading1, "\" tabindex=\"-1\">").concat(lang$1.heading1, "</button>\n <button type=\"button\" class=\"trix-button trix-button--icon trix-button--icon-quote\" data-trix-attribute=\"quote\" title=\"").concat(lang$1.quote, "\" tabindex=\"-1\">").concat(lang$1.quote, "</button>\n <button type=\"button\" class=\"trix-button trix-button--icon trix-button--icon-code\" data-trix-attribute=\"code\" title=\"").concat(lang$1.code, "\" tabindex=\"-1\">").concat(lang$1.code, "</button>\n <button type=\"button\" class=\"trix-button trix-button--icon trix-button--icon-bullet-list\" data-trix-attribute=\"bullet\" title=\"").concat(lang$1.bullets, "\" tabindex=\"-1\">").concat(lang$1.bullets, "</button>\n <button type=\"button\" class=\"trix-button trix-button--icon trix-button--icon-number-list\" data-trix-attribute=\"number\" title=\"").concat(lang$1.numbers, "\" tabindex=\"-1\">").concat(lang$1.numbers, "</button>\n <button type=\"button\" class=\"trix-button trix-button--icon trix-button--icon-decrease-nesting-level\" data-trix-action=\"decreaseNestingLevel\" title=\"").concat(lang$1.outdent, "\" tabindex=\"-1\">").concat(lang$1.outdent, "</button>\n <button type=\"button\" class=\"trix-button trix-button--icon trix-button--icon-increase-nesting-level\" data-trix-action=\"increaseNestingLevel\" title=\"").concat(lang$1.indent, "\" tabindex=\"-1\">").concat(lang$1.indent, "</button>\n </span>\n\n <span class=\"trix-button-group trix-button-group--file-tools\" data-trix-button-group=\"file-tools\">\n <button type=\"button\" class=\"trix-button trix-button--icon trix-button--icon-attach\" data-trix-action=\"attachFiles\" title=\"").concat(lang$1.attachFiles, "\" tabindex=\"-1\">").concat(lang$1.attachFiles, "</button>\n </span>\n\n <span class=\"trix-button-group-spacer\"></span>\n\n <span class=\"trix-button-group trix-button-group--history-tools\" data-trix-button-group=\"history-tools\">\n <button type=\"button\" class=\"trix-button trix-button--icon trix-button--icon-undo\" data-trix-action=\"undo\" data-trix-key=\"z\" title=\"").concat(lang$1.undo, "\" tabindex=\"-1\">").concat(lang$1.undo, "</button>\n <button type=\"button\" class=\"trix-button trix-button--icon trix-button--icon-redo\" data-trix-action=\"redo\" data-trix-key=\"shift+z\" title=\"").concat(lang$1.redo, "\" tabindex=\"-1\">").concat(lang$1.redo, "</button>\n </span>\n </div>\n\n <div class=\"trix-dialogs\" data-trix-dialogs>\n <div class=\"trix-dialog trix-dialog--link\" data-trix-dialog=\"href\" data-trix-dialog-attribute=\"href\">\n <div class=\"trix-dialog__link-fields\">\n <input type=\"url\" name=\"href\" class=\"trix-input trix-input--dialog\" placeholder=\"").concat(lang$1.urlPlaceholder, "\" aria-label=\"").concat(lang$1.url, "\"
630required data-trix-input>\n <div class=\"trix-button-group\">\n <input type=\"button\" class=\"trix-button trix-button--dialog\" value=\"").concat(lang$1.link, "\" data-trix-method=\"setAttribute\">\n <input type=\"button\" class=\"trix-button trix-button--dialog\" value=\"").concat(lang$1.unlink, "\" data-trix-method=\"removeAttribute\">\n </div>\n </div>\n </div>\n </div>"); 631 } 632 }; 633 634 const undo = { 635 interval: 5000 636 }; 637 638 var config = /*#__PURE__*/Object.freeze({ 639 __proto__: null, 640 attachments: attachments, 641 blockAttributes: attributes, 642 browser: browser$1, 643 css: css$3, 644 fileSize: file_size_formatting, 645 input: input,
vendor: 1,656 bytes, lines 646-707
646 keyNames: key_names, 647 lang: lang$1, 648 parser: parser, 649 textAttributes: text_attributes, 650 toolbar: toolbar, 651 undo: undo 652 }); 653 654 class BasicObject { 655 static proxyMethod(expression) { 656 const { 657 name, 658 toMethod, 659 toProperty, 660 optional 661 } = parseProxyMethodExpression(expression); 662 this.prototype[name] = function () { 663 let subject; 664 let object; 665 if (toMethod) { 666 if (optional) { 667 var _this$toMethod; 668 object = (_this$toMethod = this[toMethod]) === null || _this$toMethod === void 0 ? void 0 : _this$toMethod.call(this); 669 } else { 670 object = this[toMethod](); 671 } 672 } else if (toProperty) { 673 object = this[toProperty]; 674 } 675 if (optional) { 676 var _object; 677 subject = (_object = object) === null || _object === void 0 ? void 0 : _object[name]; 678 if (subject) { 679 return apply.call(subject, object, arguments); 680 } 681 } else { 682 subject = object[name]; 683 return apply.call(subject, object, arguments); 684 } 685 }; 686 } 687 } 688 const parseProxyMethodExpression = function (expression) { 689 const match = expression.match(proxyMethodExpressionPattern); 690 if (!match) { 691 throw new Error("can't parse @proxyMethod expression: ".concat(expression)); 692 } 693 const args = { 694 name: match[4] 695 }; 696 if (match[2] != null) { 697 args.toMethod = match[1]; 698 } else { 699 args.toProperty = match[1]; 700 } 701 if (match[3] != null) { 702 args.optional = true; 703 } 704 return args; 705 }; 706 const { 707 apply
vendor: 10,866 bytes, lines 707-1040
707 708 } = Function.prototype; 709 const proxyMethodExpressionPattern = new RegExp("\ 710^\ 711(.+?)\ 712(\\(\\))?\ 713(\\?)?\ 714\\.\ 715(.+?)\ 716$\ 717"); 718 719 var _Array$from, _$codePointAt$1, _$1, _String$fromCodePoint; 720 class UTF16String extends BasicObject { 721 static box() { 722 let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ""; 723 if (value instanceof this) { 724 return value; 725 } else { 726 return this.fromUCS2String(value === null || value === void 0 ? void 0 : value.toString()); 727 } 728 } 729 static fromUCS2String(ucs2String) { 730 return new this(ucs2String, ucs2decode(ucs2String)); 731 } 732 static fromCodepoints(codepoints) { 733 return new this(ucs2encode(codepoints), codepoints); 734 } 735 constructor(ucs2String, codepoints) { 736 super(...arguments); 737 this.ucs2String = ucs2String; 738 this.codepoints = codepoints; 739 this.length = this.codepoints.length; 740 this.ucs2Length = this.ucs2String.length; 741 } 742 offsetToUCS2Offset(offset) { 743 return ucs2encode(this.codepoints.slice(0, Math.max(0, offset))).length; 744 } 745 offsetFromUCS2Offset(ucs2Offset) { 746 return ucs2decode(this.ucs2String.slice(0, Math.max(0, ucs2Offset))).length; 747 } 748 slice() { 749 return this.constructor.fromCodepoints(this.codepoints.slice(...arguments)); 750 } 751 charAt(offset) { 752 return this.slice(offset, offset + 1); 753 } 754 isEqualTo(value) { 755 return this.constructor.box(value).ucs2String === this.ucs2String; 756 } 757 toJSON() { 758 return this.ucs2String; 759 } 760 getCacheKey() { 761 return this.ucs2String; 762 } 763 toString() { 764 return this.ucs2String; 765 } 766 } 767 const hasArrayFrom = ((_Array$from = Array.from) === null || _Array$from === void 0 ? void 0 : _Array$from.call(Array, "\ud83d\udc7c").length) === 1; 768 const hasStringCodePointAt$1 = ((_$codePointAt$1 = (_$1 = " ").codePointAt) === null || _$codePointAt$1 === void 0 ? void 0 : _$codePointAt$1.call(_$1, 0)) != null; 769 const hasStringFromCodePoint = ((_String$fromCodePoint = String.fromCodePoint) === null || _String$fromCodePoint === void 0 ? void 0 : _String$fromCodePoint.call(String, 32, 128124)) === " \ud83d\udc7c"; 770 771 // UCS-2 conversion helpers ported from Mathias Bynens' Punycode.js: 772 // https://github.com/bestiejs/punycode.js#punycodeucs2 773 774 let ucs2decode, ucs2encode; 775 776 // Creates an array containing the numeric code points of each Unicode 777 // character in the string. While JavaScript uses UCS-2 internally, 778 // this function will convert a pair of surrogate halves (each of which 779 // UCS-2 exposes as separate characters) into a single code point, 780 // matching UTF-16. 781 if (hasArrayFrom && hasStringCodePointAt$1) { 782 ucs2decode = string => Array.from(string).map(char => char.codePointAt(0)); 783 } else { 784 ucs2decode = function (string) { 785 const output = []; 786 let counter = 0; 787 const { 788 length 789 } = string; 790 while (counter < length) { 791 let value = string.charCodeAt(counter++); 792 if (0xd800 <= value && value <= 0xdbff && counter < length) { 793 // high surrogate, and there is a next character 794 const extra = string.charCodeAt(counter++); 795 if ((extra & 0xfc00) === 0xdc00) { 796 // low surrogate 797 value = ((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000; 798 } else { 799 // unmatched surrogate; only append this code unit, in case the 800 // next code unit is the high surrogate of a surrogate pair 801 counter--; 802 } 803 } 804 output.push(value); 805 } 806 return output; 807 }; 808 } 809 810 // Creates a string based on an array of numeric code points. 811 if (hasStringFromCodePoint) { 812 ucs2encode = array => String.fromCodePoint(...Array.from(array || [])); 813 } else { 814 ucs2encode = function (array) { 815 const characters = (() => { 816 const result = []; 817 Array.from(array).forEach(value => { 818 let output = ""; 819 if (value > 0xffff) { 820 value -= 0x10000; 821 output += String.fromCharCode(value >>> 10 & 0x3ff | 0xd800); 822 value = 0xdc00 | value & 0x3ff; 823 } 824 result.push(output + String.fromCharCode(value)); 825 }); 826 return result; 827 })(); 828 return characters.join(""); 829 }; 830 } 831 832 let id$2 = 0; 833 class TrixObject extends BasicObject { 834 static fromJSONString(jsonString) { 835 return this.fromJSON(JSON.parse(jsonString)); 836 } 837 constructor() { 838 super(...arguments); 839 this.id = ++id$2; 840 } 841 hasSameConstructorAs(object) { 842 return this.constructor === (object === null || object === void 0 ? void 0 : object.constructor); 843 } 844 isEqualTo(object) { 845 return this === object; 846 } 847 inspect() { 848 const parts = []; 849 const contents = this.contentsForInspection() || {}; 850 for (const key in contents) { 851 const value = contents[key]; 852 parts.push("".concat(key, "=").concat(value)); 853 } 854 return "#<".concat(this.constructor.name, ":").concat(this.id).concat(parts.length ? " ".concat(parts.join(", ")) : "", ">"); 855 } 856 contentsForInspection() {} 857 toJSONString() { 858 return JSON.stringify(this); 859 } 860 toUTF16String() { 861 return UTF16String.box(this); 862 } 863 getCacheKey() { 864 return this.id.toString(); 865 } 866 } 867 868 /* eslint-disable 869 id-length, 870 */ 871 const arraysAreEqual = function () { 872 let a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; 873 let b = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; 874 if (a.length !== b.length) { 875 return false; 876 } 877 for (let index = 0; index < a.length; index++) { 878 const value = a[index]; 879 if (value !== b[index]) { 880 return false; 881 } 882 } 883 return true; 884 }; 885 const arrayStartsWith = function () { 886 let a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; 887 let b = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; 888 return arraysAreEqual(a.slice(0, b.length), b); 889 }; 890 const spliceArray = function (array) { 891 const result = array.slice(0); 892 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { 893 args[_key - 1] = arguments[_key]; 894 } 895 result.splice(...args); 896 return result; 897 }; 898 const summarizeArrayChange = function () { 899 let oldArray = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; 900 let newArray = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; 901 const added = []; 902 const removed = []; 903 const existingValues = new Set(); 904 oldArray.forEach(value => { 905 existingValues.add(value); 906 }); 907 const currentValues = new Set(); 908 newArray.forEach(value => { 909 currentValues.add(value); 910 if (!existingValues.has(value)) { 911 added.push(value); 912 } 913 }); 914 oldArray.forEach(value => { 915 if (!currentValues.has(value)) { 916 removed.push(value); 917 } 918 }); 919 return { 920 added, 921 removed 922 }; 923 }; 924 925 // https://github.com/mathiasbynens/unicode-2.1.8/blob/master/Bidi_Class/Right_To_Left/regex.js 926 const RTL_PATTERN = /[\u05BE\u05C0\u05C3\u05D0-\u05EA\u05F0-\u05F4\u061B\u061F\u0621-\u063A\u0640-\u064A\u066D\u0671-\u06B7\u06BA-\u06BE\u06C0-\u06CE\u06D0-\u06D5\u06E5\u06E6\u200F\u202B\u202E\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE72\uFE74\uFE76-\uFEFC]/; 927 const getDirection = function () { 928 const input = makeElement("input", { 929 dir: "auto", 930 name: "x", 931 dirName: "x.dir" 932 }); 933 const textArea = makeElement("textarea", { 934 dir: "auto", 935 name: "y", 936 dirName: "y.dir" 937 }); 938 const form = makeElement("form"); 939 form.appendChild(input); 940 form.appendChild(textArea); 941 const supportsDirName = function () { 942 try { 943 return new FormData(form).has(textArea.dirName); 944 } catch (error) { 945 return false; 946 } 947 }(); 948 const supportsDirSelector = function () { 949 try { 950 return input.matches(":dir(ltr),:dir(rtl)"); 951 } catch (error) { 952 return false; 953 } 954 }(); 955 if (supportsDirName) { 956 return function (string) { 957 textArea.value = string; 958 return new FormData(form).get(textArea.dirName); 959 }; 960 } else if (supportsDirSelector) { 961 return function (string) { 962 input.value = string; 963 if (input.matches(":dir(rtl)")) { 964 return "rtl"; 965 } else { 966 return "ltr"; 967 } 968 }; 969 } else { 970 return function (string) { 971 const char = string.trim().charAt(0); 972 if (RTL_PATTERN.test(char)) { 973 return "rtl"; 974 } else { 975 return "ltr"; 976 } 977 }; 978 } 979 }(); 980 981 let allAttributeNames = null; 982 let blockAttributeNames = null; 983 let textAttributeNames = null; 984 let listAttributeNames = null; 985 const getAllAttributeNames = () => { 986 if (!allAttributeNames) { 987 allAttributeNames = getTextAttributeNames().concat(getBlockAttributeNames()); 988 } 989 return allAttributeNames; 990 }; 991 const getBlockConfig = attributeName => attributes[attributeName]; 992 const getBlockAttributeNames = () => { 993 if (!blockAttributeNames) { 994 blockAttributeNames = Object.keys(attributes); 995 } 996 return blockAttributeNames; 997 }; 998 const getTextConfig = attributeName => text_attributes[attributeName]; 999 const getTextAttributeNames = () => { 1000 if (!textAttributeNames) { 1001 textAttributeNames = Object.keys(text_attributes); 1002 } 1003 return textAttributeNames; 1004 }; 1005 const getListAttributeNames = () => { 1006 if (!listAttributeNames) { 1007 listAttributeNames = []; 1008 for (const key in attributes) { 1009 const { 1010 listAttribute 1011 } = attributes[key]; 1012 if (listAttribute != null) { 1013 listAttributeNames.push(listAttribute); 1014 } 1015 } 1016 } 1017 return listAttributeNames; 1018 }; 1019 1020 /* eslint-disable 1021 */ 1022 const installDefaultCSSForTagName = function (tagName, defaultCSS) { 1023 const styleElement = insertStyleElementForTagName(tagName); 1024 styleElement.textContent = defaultCSS.replace(/%t/g, tagName); 1025 }; 1026 const insertStyleElementForTagName = function (tagName) { 1027 const element = document.createElement("style"); 1028 element.setAttribute("type", "text/css"); 1029 element.setAttribute("data-tag-name", tagName.toLowerCase()); 1030 const nonce = getCSPNonce(); 1031 if (nonce) { 1032 element.setAttribute("nonce", nonce); 1033 } 1034 document.head.insertBefore(element, document.head.firstChild); 1035 return element; 1036 }; 1037 const getCSPNonce = function () { 1038 const element = getMetaElement("trix-csp-nonce") || getMetaElement("csp-nonce"); 1039 if (element) { 1040
vendor: 1,329 bytes, lines 1040-1081
1040return element.getAttribute("content"); 1041 } 1042 }; 1043 const getMetaElement = name => document.head.querySelector("meta[name=".concat(name, "]")); 1044 1045 const testTransferData = { 1046 "application/x-trix-feature-detection": "test" 1047 }; 1048 const dataTransferIsPlainText = function (dataTransfer) { 1049 const text = dataTransfer.getData("text/plain"); 1050 const html = dataTransfer.getData("text/html"); 1051 if (text && html) { 1052 const { 1053 body 1054 } = new DOMParser().parseFromString(html, "text/html"); 1055 if (body.textContent === text) { 1056 return !body.querySelector("*"); 1057 } 1058 } else { 1059 return text === null || text === void 0 ? void 0 : text.length; 1060 } 1061 }; 1062 const dataTransferIsWritable = function (dataTransfer) { 1063 if (!(dataTransfer !== null && dataTransfer !== void 0 && dataTransfer.setData)) return false; 1064 for (const key in testTransferData) { 1065 const value = testTransferData[key]; 1066 try { 1067 dataTransfer.setData(key, value); 1068 if (!dataTransfer.getData(key) === value) return false; 1069 } catch (error) { 1070 return false; 1071 } 1072 } 1073 return true; 1074 }; 1075 const keyEventIsKeyboardCommand = function () { 1076 if (/Mac|^iP/.test(navigator.platform)) { 1077 return event => event.metaKey; 1078 } else { 1079 return event => event.ctrlKey; 1080 } 1081 }();
vendor: 19,008 bytes, lines 1081-1710
1081 1082 1083 const defer = fn => setTimeout(fn, 1); 1084 1085 /* eslint-disable 1086 id-length, 1087 */ 1088 const copyObject = function () { 1089 let object = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; 1090 const result = {}; 1091 for (const key in object) { 1092 const value = object[key]; 1093 result[key] = value; 1094 } 1095 return result; 1096 }; 1097 const objectsAreEqual = function () { 1098 let a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; 1099 let b = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 1100 if (Object.keys(a).length !== Object.keys(b).length) { 1101 return false; 1102 } 1103 for (const key in a) { 1104 const value = a[key]; 1105 if (value !== b[key]) { 1106 return false; 1107 } 1108 } 1109 return true; 1110 }; 1111 1112 const normalizeRange = function (range) { 1113 if (range == null) return; 1114 if (!Array.isArray(range)) { 1115 range = [range, range]; 1116 } 1117 return [copyValue(range[0]), copyValue(range[1] != null ? range[1] : range[0])]; 1118 }; 1119 const rangeIsCollapsed = function (range) { 1120 if (range == null) return; 1121 const [start, end] = normalizeRange(range); 1122 return rangeValuesAreEqual(start, end); 1123 }; 1124 const rangesAreEqual = function (leftRange, rightRange) { 1125 if (leftRange == null || rightRange == null) return; 1126 const [leftStart, leftEnd] = normalizeRange(leftRange); 1127 const [rightStart, rightEnd] = normalizeRange(rightRange); 1128 return rangeValuesAreEqual(leftStart, rightStart) && rangeValuesAreEqual(leftEnd, rightEnd); 1129 }; 1130 const copyValue = function (value) { 1131 if (typeof value === "number") { 1132 return value; 1133 } else { 1134 return copyObject(value); 1135 } 1136 }; 1137 const rangeValuesAreEqual = function (left, right) { 1138 if (typeof left === "number") { 1139 return left === right; 1140 } else { 1141 return objectsAreEqual(left, right); 1142 } 1143 }; 1144 1145 class SelectionChangeObserver extends BasicObject { 1146 constructor() { 1147 super(...arguments); 1148 this.update = this.update.bind(this); 1149 this.selectionManagers = []; 1150 } 1151 start() { 1152 if (!this.started) { 1153 this.started = true; 1154 document.addEventListener("selectionchange", this.update, true); 1155 } 1156 } 1157 stop() { 1158 if (this.started) { 1159 this.started = false; 1160 return document.removeEventListener("selectionchange", this.update, true); 1161 } 1162 } 1163 registerSelectionManager(selectionManager) { 1164 if (!this.selectionManagers.includes(selectionManager)) { 1165 this.selectionManagers.push(selectionManager); 1166 return this.start(); 1167 } 1168 } 1169 unregisterSelectionManager(selectionManager) { 1170 this.selectionManagers = this.selectionManagers.filter(sm => sm !== selectionManager); 1171 if (this.selectionManagers.length === 0) { 1172 return this.stop(); 1173 } 1174 } 1175 notifySelectionManagersOfSelectionChange() { 1176 return this.selectionManagers.map(selectionManager => selectionManager.selectionDidChange()); 1177 } 1178 update() { 1179 this.notifySelectionManagersOfSelectionChange(); 1180 } 1181 reset() { 1182 this.update(); 1183 } 1184 } 1185 const selectionChangeObserver = new SelectionChangeObserver(); 1186 const getDOMSelection = function () { 1187 const selection = window.getSelection(); 1188 if (selection.rangeCount > 0) { 1189 return selection; 1190 } 1191 }; 1192 const getDOMRange = function () { 1193 var _getDOMSelection; 1194 const domRange = (_getDOMSelection = getDOMSelection()) === null || _getDOMSelection === void 0 ? void 0 : _getDOMSelection.getRangeAt(0); 1195 if (domRange) { 1196 if (!domRangeIsPrivate(domRange)) { 1197 return domRange; 1198 } 1199 } 1200 }; 1201 const setDOMRange = function (domRange) { 1202 const selection = window.getSelection(); 1203 selection.removeAllRanges(); 1204 selection.addRange(domRange); 1205 return selectionChangeObserver.update(); 1206 }; 1207 1208 // In Firefox, clicking certain <input> elements changes the selection to a 1209 // private element used to draw its UI. Attempting to access properties of those 1210 // elements throws an error. 1211 // https://bugzilla.mozilla.org/show_bug.cgi?id=208427 1212 const domRangeIsPrivate = domRange => nodeIsPrivate(domRange.startContainer) || nodeIsPrivate(domRange.endContainer); 1213 const nodeIsPrivate = node => !Object.getPrototypeOf(node); 1214 1215 /* eslint-disable 1216 id-length, 1217 no-useless-escape, 1218 */ 1219 const normalizeSpaces = string => string.replace(new RegExp("".concat(ZERO_WIDTH_SPACE), "g"), "").replace(new RegExp("".concat(NON_BREAKING_SPACE), "g"), " "); 1220 const normalizeNewlines = string => string.replace(/\r\n?/g, "\n"); 1221 const breakableWhitespacePattern = new RegExp("[^\\S".concat(NON_BREAKING_SPACE, "]")); 1222 const squishBreakableWhitespace = string => string 1223 // Replace all breakable whitespace characters with a space 1224 .replace(new RegExp("".concat(breakableWhitespacePattern.source), "g"), " ") 1225 // Replace two or more spaces with a single space 1226 .replace(/\ {2,}/g, " "); 1227 const summarizeStringChange = function (oldString, newString) { 1228 let added, removed; 1229 oldString = UTF16String.box(oldString); 1230 newString = UTF16String.box(newString); 1231 if (newString.length < oldString.length) { 1232 [removed, added] = utf16StringDifferences(oldString, newString); 1233 } else { 1234 [added, removed] = utf16StringDifferences(newString, oldString); 1235 } 1236 return { 1237 added, 1238 removed 1239 }; 1240 }; 1241 const utf16StringDifferences = function (a, b) { 1242 if (a.isEqualTo(b)) { 1243 return ["", ""]; 1244 } 1245 const diffA = utf16StringDifference(a, b); 1246 const { 1247 length 1248 } = diffA.utf16String; 1249 let diffB; 1250 if (length) { 1251 const { 1252 offset 1253 } = diffA; 1254 const codepoints = a.codepoints.slice(0, offset).concat(a.codepoints.slice(offset + length)); 1255 diffB = utf16StringDifference(b, UTF16String.fromCodepoints(codepoints)); 1256 } else { 1257 diffB = utf16StringDifference(b, a); 1258 } 1259 return [diffA.utf16String.toString(), diffB.utf16String.toString()]; 1260 }; 1261 const utf16StringDifference = function (a, b) { 1262 let leftIndex = 0; 1263 let rightIndexA = a.length; 1264 let rightIndexB = b.length; 1265 while (leftIndex < rightIndexA && a.charAt(leftIndex).isEqualTo(b.charAt(leftIndex))) { 1266 leftIndex++; 1267 } 1268 while (rightIndexA > leftIndex + 1 && a.charAt(rightIndexA - 1).isEqualTo(b.charAt(rightIndexB - 1))) { 1269 rightIndexA--; 1270 rightIndexB--; 1271 } 1272 return { 1273 utf16String: a.slice(leftIndex, rightIndexA), 1274 offset: leftIndex 1275 }; 1276 }; 1277 1278 class Hash extends TrixObject { 1279 static fromCommonAttributesOfObjects() { 1280 let objects = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; 1281 if (!objects.length) { 1282 return new this(); 1283 } 1284 let hash = box(objects[0]); 1285 let keys = hash.getKeys(); 1286 objects.slice(1).forEach(object => { 1287 keys = hash.getKeysCommonToHash(box(object)); 1288 hash = hash.slice(keys); 1289 }); 1290 return hash; 1291 } 1292 static box(values) { 1293 return box(values); 1294 } 1295 constructor() { 1296 let values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; 1297 super(...arguments); 1298 this.values = copy(values); 1299 } 1300 add(key, value) { 1301 return this.merge(object(key, value)); 1302 } 1303 remove(key) { 1304 return new Hash(copy(this.values, key)); 1305 } 1306 get(key) { 1307 return this.values[key]; 1308 } 1309 has(key) { 1310 return key in this.values; 1311 } 1312 merge(values) { 1313 return new Hash(merge(this.values, unbox(values))); 1314 } 1315 slice(keys) { 1316 const values = {}; 1317 Array.from(keys).forEach(key => { 1318 if (this.has(key)) { 1319 values[key] = this.values[key]; 1320 } 1321 }); 1322 return new Hash(values); 1323 } 1324 getKeys() { 1325 return Object.keys(this.values); 1326 } 1327 getKeysCommonToHash(hash) { 1328 hash = box(hash); 1329 return this.getKeys().filter(key => this.values[key] === hash.values[key]); 1330 } 1331 isEqualTo(values) { 1332 return arraysAreEqual(this.toArray(), box(values).toArray()); 1333 } 1334 isEmpty() { 1335 return this.getKeys().length === 0; 1336 } 1337 toArray() { 1338 if (!this.array) { 1339 const result = []; 1340 for (const key in this.values) { 1341 const value = this.values[key]; 1342 result.push(result.push(key, value)); 1343 } 1344 this.array = result.slice(0); 1345 } 1346 return this.array; 1347 } 1348 toObject() { 1349 return copy(this.values); 1350 } 1351 toJSON() { 1352 return this.toObject(); 1353 } 1354 contentsForInspection() { 1355 return { 1356 values: JSON.stringify(this.values) 1357 }; 1358 } 1359 } 1360 const object = function (key, value) { 1361 const result = {}; 1362 result[key] = value; 1363 return result; 1364 }; 1365 const merge = function (object, values) { 1366 const result = copy(object); 1367 for (const key in values) { 1368 const value = values[key]; 1369 result[key] = value; 1370 } 1371 return result; 1372 }; 1373 const copy = function (object, keyToRemove) { 1374 const result = {}; 1375 const sortedKeys = Object.keys(object).sort(); 1376 sortedKeys.forEach(key => { 1377 if (key !== keyToRemove) { 1378 result[key] = object[key]; 1379 } 1380 }); 1381 return result; 1382 }; 1383 const box = function (object) { 1384 if (object instanceof Hash) { 1385 return object; 1386 } else { 1387 return new Hash(object); 1388 } 1389 }; 1390 const unbox = function (object) { 1391 if (object instanceof Hash) { 1392 return object.values; 1393 } else { 1394 return object; 1395 } 1396 }; 1397 1398 class ObjectGroup { 1399 static groupObjects() { 1400 let ungroupedObjects = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; 1401 let { 1402 depth, 1403 asTree 1404 } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 1405 let group; 1406 if (asTree) { 1407 if (depth == null) { 1408 depth = 0; 1409 } 1410 } 1411 const objects = []; 1412 Array.from(ungroupedObjects).forEach(object => { 1413 var _object$canBeGrouped2; 1414 if (group) { 1415 var _object$canBeGrouped, _group$canBeGroupedWi, _group; 1416 if ((_object$canBeGrouped = object.canBeGrouped) !== null && _object$canBeGrouped !== void 0 && _object$canBeGrouped.call(object, depth) && (_group$canBeGroupedWi = (_group = group[group.length - 1]).canBeGroupedWith) !== null && _group$canBeGroupedWi !== void 0 && _group$canBeGroupedWi.call(_group, object, depth)) { 1417 group.push(object); 1418 return; 1419 } else { 1420 objects.push(new this(group, { 1421 depth, 1422 asTree 1423 })); 1424 group = null; 1425 } 1426 } 1427 if ((_object$canBeGrouped2 = object.canBeGrouped) !== null && _object$canBeGrouped2 !== void 0 && _object$canBeGrouped2.call(object, depth)) { 1428 group = [object]; 1429 } else { 1430 objects.push(object); 1431 } 1432 }); 1433 if (group) { 1434 objects.push(new this(group, { 1435 depth, 1436 asTree 1437 })); 1438 } 1439 return objects; 1440 } 1441 constructor() { 1442 let objects = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; 1443 let { 1444 depth, 1445 asTree 1446 } = arguments.length > 1 ? arguments[1] : undefined; 1447 this.objects = objects; 1448 if (asTree) { 1449 this.depth = depth; 1450 this.objects = this.constructor.groupObjects(this.objects, { 1451 asTree, 1452 depth: this.depth + 1 1453 }); 1454 } 1455 } 1456 getObjects() { 1457 return this.objects; 1458 } 1459 getDepth() { 1460 return this.depth; 1461 } 1462 getCacheKey() { 1463 const keys = ["objectGroup"]; 1464 Array.from(this.getObjects()).forEach(object => { 1465 keys.push(object.getCacheKey()); 1466 }); 1467 return keys.join("/"); 1468 } 1469 } 1470 1471 class ObjectMap extends BasicObject { 1472 constructor() { 1473 let objects = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; 1474 super(...arguments); 1475 this.objects = {}; 1476 Array.from(objects).forEach(object => { 1477 const hash = JSON.stringify(object); 1478 if (this.objects[hash] == null) { 1479 this.objects[hash] = object; 1480 } 1481 }); 1482 } 1483 find(object) { 1484 const hash = JSON.stringify(object); 1485 return this.objects[hash]; 1486 } 1487 } 1488 1489 class ElementStore { 1490 constructor(elements) { 1491 this.reset(elements); 1492 } 1493 add(element) { 1494 const key = getKey(element); 1495 this.elements[key] = element; 1496 } 1497 remove(element) { 1498 const key = getKey(element); 1499 const value = this.elements[key]; 1500 if (value) { 1501 delete this.elements[key]; 1502 return value; 1503 } 1504 } 1505 reset() { 1506 let elements = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; 1507 this.elements = {}; 1508 Array.from(elements).forEach(element => { 1509 this.add(element); 1510 }); 1511 return elements; 1512 } 1513 } 1514 const getKey = element => element.dataset.trixStoreKey; 1515 1516 class Operation extends BasicObject { 1517 isPerforming() { 1518 return this.performing === true; 1519 } 1520 hasPerformed() { 1521 return this.performed === true; 1522 } 1523 hasSucceeded() { 1524 return this.performed && this.succeeded; 1525 } 1526 hasFailed() { 1527 return this.performed && !this.succeeded; 1528 } 1529 getPromise() { 1530 if (!this.promise) { 1531 this.promise = new Promise((resolve, reject) => { 1532 this.performing = true; 1533 return this.perform((succeeded, result) => { 1534 this.succeeded = succeeded; 1535 this.performing = false; 1536 this.performed = true; 1537 if (this.succeeded) { 1538 resolve(result); 1539 } else { 1540 reject(result); 1541 } 1542 }); 1543 }); 1544 } 1545 return this.promise; 1546 } 1547 perform(callback) { 1548 return callback(false); 1549 } 1550 release() { 1551 var _this$promise, _this$promise$cancel; 1552 (_this$promise = this.promise) === null || _this$promise === void 0 || (_this$promise$cancel = _this$promise.cancel) === null || _this$promise$cancel === void 0 || _this$promise$cancel.call(_this$promise); 1553 this.promise = null; 1554 this.performing = null; 1555 this.performed = null; 1556 this.succeeded = null; 1557 } 1558 } 1559 Operation.proxyMethod("getPromise().then"); 1560 Operation.proxyMethod("getPromise().catch"); 1561 1562 class ObjectView extends BasicObject { 1563 constructor(object) { 1564 let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 1565 super(...arguments); 1566 this.object = object; 1567 this.options = options; 1568 this.childViews = []; 1569 this.rootView = this; 1570 } 1571 getNodes() { 1572 if (!this.nodes) { 1573 this.nodes = this.createNodes(); 1574 } 1575 return this.nodes.map(node => node.cloneNode(true)); 1576 } 1577 invalidate() { 1578 var _this$parentView; 1579 this.nodes = null; 1580 this.childViews = []; 1581 return (_this$parentView = this.parentView) === null || _this$parentView === void 0 ? void 0 : _this$parentView.invalidate(); 1582 } 1583 invalidateViewForObject(object) { 1584 var _this$findViewForObje; 1585 return (_this$findViewForObje = this.findViewForObject(object)) === null || _this$findViewForObje === void 0 ? void 0 : _this$findViewForObje.invalidate(); 1586 } 1587 findOrCreateCachedChildView(viewClass, object, options) { 1588 let view = this.getCachedViewForObject(object); 1589 if (view) { 1590 this.recordChildView(view); 1591 } else { 1592 view = this.createChildView(...arguments); 1593 this.cacheViewForObject(view, object); 1594 } 1595 return view; 1596 } 1597 createChildView(viewClass, object) { 1598 let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; 1599 if (object instanceof ObjectGroup) { 1600 options.viewClass = viewClass; 1601 viewClass = ObjectGroupView; 1602 } 1603 const view = new viewClass(object, options); 1604 return this.recordChildView(view); 1605 } 1606 recordChildView(view) { 1607 view.parentView = this; 1608 view.rootView = this.rootView; 1609 this.childViews.push(view); 1610 return view; 1611 } 1612 getAllChildViews() { 1613 let views = []; 1614 this.childViews.forEach(childView => { 1615 views.push(childView); 1616 views = views.concat(childView.getAllChildViews()); 1617 }); 1618 return views; 1619 } 1620 findElement() { 1621 return this.findElementForObject(this.object); 1622 } 1623 findElementForObject(object) { 1624 const id = object === null || object === void 0 ? void 0 : object.id; 1625 if (id) { 1626 return this.rootView.element.querySelector("[data-trix-id='".concat(id, "']")); 1627 } 1628 } 1629 findViewForObject(object) { 1630 for (const view of this.getAllChildViews()) { 1631 if (view.object === object) { 1632 return view; 1633 } 1634 } 1635 } 1636 getViewCache() { 1637 if (this.rootView === this) { 1638 if (this.isViewCachingEnabled()) { 1639 if (!this.viewCache) { 1640 this.viewCache = {}; 1641 } 1642 return this.viewCache; 1643 } 1644 } else { 1645 return this.rootView.getViewCache(); 1646 } 1647 } 1648 isViewCachingEnabled() { 1649 return this.shouldCacheViews !== false; 1650 } 1651 enableViewCaching() { 1652 this.shouldCacheViews = true; 1653 } 1654 disableViewCaching() { 1655 this.shouldCacheViews = false; 1656 } 1657 getCachedViewForObject(object) { 1658 var _this$getViewCache; 1659 return (_this$getViewCache = this.getViewCache()) === null || _this$getViewCache === void 0 ? void 0 : _this$getViewCache[object.getCacheKey()]; 1660 } 1661 cacheViewForObject(view, object) { 1662 const cache = this.getViewCache(); 1663 if (cache) { 1664 cache[object.getCacheKey()] = view; 1665 } 1666 } 1667 garbageCollectCachedViews() { 1668 const cache = this.getViewCache(); 1669 if (cache) { 1670 const views = this.getAllChildViews().concat(this); 1671 const objectKeys = views.map(view => view.object.getCacheKey()); 1672 for (const key in cache) { 1673 if (!objectKeys.includes(key)) { 1674 delete cache[key]; 1675 } 1676 } 1677 } 1678 } 1679 } 1680 class ObjectGroupView extends ObjectView { 1681 constructor() { 1682 super(...arguments); 1683 this.objectGroup = this.object; 1684 this.viewClass = this.options.viewClass; 1685 delete this.options.viewClass; 1686 } 1687 getChildViews() { 1688 if (!this.childViews.length) { 1689 Array.from(this.objectGroup.getObjects()).forEach(object => { 1690 this.findOrCreateCachedChildView(this.viewClass, object, this.options); 1691 }); 1692 } 1693 return this.childViews; 1694 } 1695 createNodes() { 1696 const element = this.createContainerElement(); 1697 this.getChildViews().forEach(view => { 1698 Array.from(view.getNodes()).forEach(node => { 1699 element.appendChild(node); 1700 }); 1701 }); 1702 return [element]; 1703 } 1704 createContainerElement() { 1705 let depth = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.objectGroup.getDepth(); 1706 return this.getChildViews()[0].createContainerElement(depth); 1707 } 1708 } 1709 1710
vendor: 6,797 bytes, lines 1710-1928
1710const { 1711 css: css$2 1712 } = config; 1713 class AttachmentView extends ObjectView { 1714 constructor() { 1715 super(...arguments); 1716 this.attachment = this.object; 1717 this.attachment.uploadProgressDelegate = this; 1718 this.attachmentPiece = this.options.piece; 1719 } 1720 createContentNodes() { 1721 return []; 1722 } 1723 createNodes() { 1724 let innerElement; 1725 const figure = innerElement = makeElement({ 1726 tagName: "figure", 1727 className: this.getClassName(), 1728 data: this.getData(), 1729 editable: false 1730 }); 1731 const href = this.getHref(); 1732 if (href) { 1733 innerElement = makeElement({ 1734 tagName: "a", 1735 editable: false, 1736 attributes: { 1737 href, 1738 tabindex: -1 1739 } 1740 }); 1741 figure.appendChild(innerElement); 1742 } 1743 if (this.attachment.hasContent()) { 1744 innerElement.innerHTML = this.attachment.getContent(); 1745 } else { 1746 this.createContentNodes().forEach(node => { 1747 innerElement.appendChild(node); 1748 }); 1749 } 1750 innerElement.appendChild(this.createCaptionElement()); 1751 if (this.attachment.isPending()) { 1752 this.progressElement = makeElement({ 1753 tagName: "progress", 1754 attributes: { 1755 class: css$2.attachmentProgress, 1756 value: this.attachment.getUploadProgress(), 1757 max: 100 1758 }, 1759 data: { 1760 trixMutable: true, 1761 trixStoreKey: ["progressElement", this.attachment.id].join("/") 1762 } 1763 }); 1764 figure.appendChild(this.progressElement); 1765 } 1766 return [createCursorTarget("left"), figure, createCursorTarget("right")]; 1767 } 1768 createCaptionElement() { 1769 const figcaption = makeElement({ 1770 tagName: "figcaption", 1771 className: css$2.attachmentCaption 1772 }); 1773 const caption = this.attachmentPiece.getCaption(); 1774 if (caption) { 1775 figcaption.classList.add("".concat(css$2.attachmentCaption, "--edited")); 1776 figcaption.textContent = caption; 1777 } else { 1778 let name, size; 1779 const captionConfig = this.getCaptionConfig(); 1780 if (captionConfig.name) { 1781 name = this.attachment.getFilename(); 1782 } 1783 if (captionConfig.size) { 1784 size = this.attachment.getFormattedFilesize(); 1785 } 1786 if (name) { 1787 const nameElement = makeElement({ 1788 tagName: "span", 1789 className: css$2.attachmentName, 1790 textContent: name 1791 }); 1792 figcaption.appendChild(nameElement); 1793 } 1794 if (size) { 1795 if (name) { 1796 figcaption.appendChild(document.createTextNode(" ")); 1797 } 1798 const sizeElement = makeElement({ 1799 tagName: "span", 1800 className: css$2.attachmentSize, 1801 textContent: size 1802 }); 1803 figcaption.appendChild(sizeElement); 1804 } 1805 } 1806 return figcaption; 1807 } 1808 getClassName() { 1809 const names = [css$2.attachment, "".concat(css$2.attachment, "--").concat(this.attachment.getType())]; 1810 const extension = this.attachment.getExtension(); 1811 if (extension) { 1812 names.push("".concat(css$2.attachment, "--").concat(extension)); 1813 } 1814 return names.join(" "); 1815 } 1816 getData() { 1817 const data = { 1818 trixAttachment: JSON.stringify(this.attachment), 1819 trixContentType: this.attachment.getContentType(), 1820 trixId: this.attachment.id 1821 }; 1822 const { 1823 attributes 1824 } = this.attachmentPiece; 1825 if (!attributes.isEmpty()) { 1826 data.trixAttributes = JSON.stringify(attributes); 1827 } 1828 if (this.attachment.isPending()) { 1829 data.trixSerialize = false; 1830 } 1831 return data; 1832 } 1833 getHref() { 1834 if (!htmlContainsTagName(this.attachment.getContent(), "a")) { 1835 return this.attachment.getHref(); 1836 } 1837 } 1838 getCaptionConfig() { 1839 var _config$attachments$t; 1840 const type = this.attachment.getType(); 1841 const captionConfig = copyObject((_config$attachments$t = attachments[type]) === null || _config$attachments$t === void 0 ? void 0 : _config$attachments$t.caption); 1842 if (type === "file") { 1843 captionConfig.name = true; 1844 } 1845 return captionConfig; 1846 } 1847 findProgressElement() { 1848 var _this$findElement; 1849 return (_this$findElement = this.findElement()) === null || _this$findElement === void 0 ? void 0 : _this$findElement.querySelector("progress"); 1850 } 1851 1852 // Attachment delegate 1853 1854 attachmentDidChangeUploadProgress() { 1855 const value = this.attachment.getUploadProgress(); 1856 const progressElement = this.findProgressElement(); 1857 if (progressElement) { 1858 progressElement.value = value; 1859 } 1860 } 1861 } 1862 const createCursorTarget = name => makeElement({ 1863 tagName: "span", 1864 textContent: ZERO_WIDTH_SPACE, 1865 data: { 1866 trixCursorTarget: name, 1867 trixSerialize: false 1868 } 1869 }); 1870 const htmlContainsTagName = function (html, tagName) { 1871 const div = makeElement("div"); 1872 div.innerHTML = html || ""; 1873 return div.querySelector(tagName); 1874 }; 1875 1876 class PreviewableAttachmentView extends AttachmentView { 1877 constructor() { 1878 super(...arguments); 1879 this.attachment.previewDelegate = this; 1880 } 1881 createContentNodes() { 1882 this.image = makeElement({ 1883 tagName: "img", 1884 attributes: { 1885 src: "" 1886 }, 1887 data: { 1888 trixMutable: true 1889 } 1890 }); 1891 this.refresh(this.image); 1892 return [this.image]; 1893 } 1894 createCaptionElement() { 1895 const figcaption = super.createCaptionElement(...arguments); 1896 if (!figcaption.textContent) { 1897 figcaption.setAttribute("data-trix-placeholder", lang$1.captionPlaceholder); 1898 } 1899 return figcaption; 1900 } 1901 refresh(image) { 1902 if (!image) { 1903 var _this$findElement; 1904 image = (_this$findElement = this.findElement()) === null || _this$findElement === void 0 ? void 0 : _this$findElement.querySelector("img"); 1905 } 1906 if (image) { 1907 return this.updateAttributesForImage(image); 1908 } 1909 } 1910 updateAttributesForImage(image) { 1911 const url = this.attachment.getURL(); 1912 const previewURL = this.attachment.getPreviewURL(); 1913 image.src = previewURL || url; 1914 if (previewURL === url) { 1915 image.removeAttribute("data-trix-serialized-attributes"); 1916 } else { 1917 const serializedAttributes = JSON.stringify({ 1918 src: url 1919 }); 1920 image.setAttribute("data-trix-serialized-attributes", serializedAttributes); 1921 } 1922 const width = this.attachment.getWidth(); 1923 const height = this.attachment.getHeight(); 1924 if (width != null) { 1925 image.width = width; 1926 } 1927 if (height != null) { 1928 image.height = heigh
vendor: 9,116 bytes, lines 1928-2223
1928t; 1929 } 1930 const storeKey = ["imageElement", this.attachment.id, image.src, image.width, image.height].join("/"); 1931 image.dataset.trixStoreKey = storeKey; 1932 } 1933 1934 // Attachment delegate 1935 1936 attachmentDidChangeAttributes() { 1937 this.refresh(this.image); 1938 return this.refresh(); 1939 } 1940 } 1941 1942 /* eslint-disable 1943 no-useless-escape, 1944 no-var, 1945 */ 1946 class PieceView extends ObjectView { 1947 constructor() { 1948 super(...arguments); 1949 this.piece = this.object; 1950 this.attributes = this.piece.getAttributes(); 1951 this.textConfig = this.options.textConfig; 1952 this.context = this.options.context; 1953 if (this.piece.attachment) { 1954 this.attachment = this.piece.attachment; 1955 } else { 1956 this.string = this.piece.toString(); 1957 } 1958 } 1959 createNodes() { 1960 let nodes = this.attachment ? this.createAttachmentNodes() : this.createStringNodes(); 1961 const element = this.createElement(); 1962 if (element) { 1963 const innerElement = findInnerElement(element); 1964 Array.from(nodes).forEach(node => { 1965 innerElement.appendChild(node); 1966 }); 1967 nodes = [element]; 1968 } 1969 return nodes; 1970 } 1971 createAttachmentNodes() { 1972 const constructor = this.attachment.isPreviewable() ? PreviewableAttachmentView : AttachmentView; 1973 const view = this.createChildView(constructor, this.piece.attachment, { 1974 piece: this.piece 1975 }); 1976 return view.getNodes(); 1977 } 1978 createStringNodes() { 1979 var _this$textConfig; 1980 if ((_this$textConfig = this.textConfig) !== null && _this$textConfig !== void 0 && _this$textConfig.plaintext) { 1981 return [document.createTextNode(this.string)]; 1982 } else { 1983 const nodes = []; 1984 const iterable = this.string.split("\n"); 1985 for (let index = 0; index < iterable.length; index++) { 1986 const substring = iterable[index]; 1987 if (index > 0) { 1988 const element = makeElement("br"); 1989 nodes.push(element); 1990 } 1991 if (substring.length) { 1992 const node = document.createTextNode(this.preserveSpaces(substring)); 1993 nodes.push(node); 1994 } 1995 } 1996 return nodes; 1997 } 1998 } 1999 createElement() { 2000 let element, key, value; 2001 const styles = {}; 2002 for (key in this.attributes) { 2003 value = this.attributes[key]; 2004 const config = getTextConfig(key); 2005 if (config) { 2006 if (config.tagName) { 2007 var innerElement; 2008 const pendingElement = makeElement(config.tagName); 2009 if (innerElement) { 2010 innerElement.appendChild(pendingElement); 2011 innerElement = pendingElement; 2012 } else { 2013 element = innerElement = pendingElement; 2014 } 2015 } 2016 if (config.styleProperty) { 2017 styles[config.styleProperty] = value; 2018 } 2019 if (config.style) { 2020 for (key in config.style) { 2021 value = config.style[key]; 2022 styles[key] = value; 2023 } 2024 } 2025 } 2026 } 2027 if (Object.keys(styles).length) { 2028 if (!element) { 2029 element = makeElement("span"); 2030 } 2031 for (key in styles) { 2032 value = styles[key]; 2033 element.style[key] = value; 2034 } 2035 } 2036 return element; 2037 } 2038 createContainerElement() { 2039 for (const key in this.attributes) { 2040 const value = this.attributes[key]; 2041 const config = getTextConfig(key); 2042 if (config) { 2043 if (config.groupTagName) { 2044 const attributes = {}; 2045 attributes[key] = value; 2046 return makeElement(config.groupTagName, attributes); 2047 } 2048 } 2049 } 2050 } 2051 preserveSpaces(string) { 2052 if (this.context.isLast) { 2053 string = string.replace(/\ $/, NON_BREAKING_SPACE); 2054 } 2055 string = string.replace(/(\S)\ {3}(\S)/g, "$1 ".concat(NON_BREAKING_SPACE, " $2")).replace(/\ {2}/g, "".concat(NON_BREAKING_SPACE, " ")).replace(/\ {2}/g, " ".concat(NON_BREAKING_SPACE)); 2056 if (this.context.isFirst || this.context.followsWhitespace) { 2057 string = string.replace(/^\ /, NON_BREAKING_SPACE); 2058 } 2059 return string; 2060 } 2061 } 2062 2063 /* eslint-disable 2064 no-var, 2065 */ 2066 class TextView extends ObjectView { 2067 constructor() { 2068 super(...arguments); 2069 this.text = this.object; 2070 this.textConfig = this.options.textConfig; 2071 } 2072 createNodes() { 2073 const nodes = []; 2074 const pieces = ObjectGroup.groupObjects(this.getPieces()); 2075 const lastIndex = pieces.length - 1; 2076 for (let index = 0; index < pieces.length; index++) { 2077 const piece = pieces[index]; 2078 const context = {}; 2079 if (index === 0) { 2080 context.isFirst = true; 2081 } 2082 if (index === lastIndex) { 2083 context.isLast = true; 2084 } 2085 if (endsWithWhitespace(previousPiece)) { 2086 context.followsWhitespace = true; 2087 } 2088 const view = this.findOrCreateCachedChildView(PieceView, piece, { 2089 textConfig: this.textConfig, 2090 context 2091 }); 2092 nodes.push(...Array.from(view.getNodes() || [])); 2093 var previousPiece = piece; 2094 } 2095 return nodes; 2096 } 2097 getPieces() { 2098 return Array.from(this.text.getPieces()).filter(piece => !piece.hasAttribute("blockBreak")); 2099 } 2100 } 2101 const endsWithWhitespace = piece => /\s$/.test(piece === null || piece === void 0 ? void 0 : piece.toString()); 2102 2103 const { 2104 css: css$1 2105 } = config; 2106 class BlockView extends ObjectView { 2107 constructor() { 2108 super(...arguments); 2109 this.block = this.object; 2110 this.attributes = this.block.getAttributes(); 2111 } 2112 createNodes() { 2113 const comment = document.createComment("block"); 2114 const nodes = [comment]; 2115 if (this.block.isEmpty()) { 2116 nodes.push(makeElement("br")); 2117 } else { 2118 var _getBlockConfig; 2119 const textConfig = (_getBlockConfig = getBlockConfig(this.block.getLastAttribute())) === null || _getBlockConfig === void 0 ? void 0 : _getBlockConfig.text; 2120 const textView = this.findOrCreateCachedChildView(TextView, this.block.text, { 2121 textConfig 2122 }); 2123 nodes.push(...Array.from(textView.getNodes() || [])); 2124 if (this.shouldAddExtraNewlineElement()) { 2125 nodes.push(makeElement("br")); 2126 } 2127 } 2128 if (this.attributes.length) { 2129 return nodes; 2130 } else { 2131 let attributes$1; 2132 const { 2133 tagName 2134 } = attributes.default; 2135 if (this.block.isRTL()) { 2136 attributes$1 = { 2137 dir: "rtl" 2138 }; 2139 } 2140 const element = makeElement({ 2141 tagName, 2142 attributes: attributes$1 2143 }); 2144 nodes.forEach(node => element.appendChild(node)); 2145 return [element]; 2146 } 2147 } 2148 createContainerElement(depth) { 2149 const attributes = {}; 2150 let className; 2151 const attributeName = this.attributes[depth]; 2152 const { 2153 tagName, 2154 htmlAttributes = [] 2155 } = getBlockConfig(attributeName); 2156 if (depth === 0 && this.block.isRTL()) { 2157 Object.assign(attributes, { 2158 dir: "rtl" 2159 }); 2160 } 2161 if (attributeName === "attachmentGallery") { 2162 const size = this.block.getBlockBreakPosition(); 2163 className = "".concat(css$1.attachmentGallery, " ").concat(css$1.attachmentGallery, "--").concat(size); 2164 } 2165 Object.entries(this.block.htmlAttributes).forEach(_ref => { 2166 let [name, value] = _ref; 2167 if (htmlAttributes.includes(name)) { 2168 attributes[name] = value; 2169 } 2170 }); 2171 return makeElement({ 2172 tagName, 2173 className, 2174 attributes 2175 }); 2176 } 2177 2178 // A single <br> at the end of a block element has no visual representation 2179 // so add an extra one. 2180 shouldAddExtraNewlineElement() { 2181 return /\n\n$/.test(this.block.toString()); 2182 } 2183 } 2184 2185 class DocumentView extends ObjectView { 2186 static render(document) { 2187 const element = makeElement("div"); 2188 const view = new this(document, { 2189 element 2190 }); 2191 view.render(); 2192 view.sync(); 2193 return element; 2194 } 2195 constructor() { 2196 super(...arguments); 2197 this.element = this.options.element; 2198 this.elementStore = new ElementStore(); 2199 this.setDocument(this.object); 2200 } 2201 setDocument(document) { 2202 if (!document.isEqualTo(this.document)) { 2203 this.document = this.object = document; 2204 } 2205 } 2206 render() { 2207 this.childViews = []; 2208 this.shadowElement = makeElement("div"); 2209 if (!this.document.isEmpty()) { 2210 const objects = ObjectGroup.groupObjects(this.document.getBlocks(), { 2211 asTree: true 2212 }); 2213 Array.from(objects).forEach(object => { 2214 const view = this.findOrCreateCachedChildView(BlockView, object); 2215 Array.from(view.getNodes()).map(node => this.shadowElement.appendChild(node)); 2216 }); 2217 } 2218 } 2219 isSynced() { 2220 return elementsHaveEqualHTML(this.shadowElement, this.element); 2221 } 2222 sync() { 2223 const
2223fragment = this.createDocumentFragmentForSync(); 2224 while (this.element.lastChild) { 2225 this.element.removeChild(this.element.lastChild); 2226 } 2227 this.element.appendChild(fragment); 2228 return this.didSync(); 2229 } 2230 2231 // Private 2232 2233 didSync() { 2234 this.elementStore.reset(findStoredElements(this.element)); 2235 return defer(() => this.garbageCollectCachedViews()); 2236 } 2237 createDocumentFragmentForSync() { 2238 const fragment = document.createDocumentFragment();
vendor: 7,482 bytes, lines 2239-2462
2239 Array.from(this.shadowElement.childNodes).forEach(node => { 2240 fragment.appendChild(node.cloneNode(true)); 2241 }); 2242 Array.from(findStoredElements(fragment)).forEach(element => { 2243 const storedElement = this.elementStore.remove(element); 2244 if (storedElement) { 2245 element.parentNode.replaceChild(storedElement, element); 2246 } 2247 }); 2248 return fragment; 2249 } 2250 } 2251 const findStoredElements = element => element.querySelectorAll("[data-trix-store-key]"); 2252 const elementsHaveEqualHTML = (element, otherElement) => ignoreSpaces(element.innerHTML) === ignoreSpaces(otherElement.innerHTML); 2253 const ignoreSpaces = html => html.replace(/ /g, " "); 2254 2255 function _AsyncGenerator(e) { 2256 var r, t; 2257 function resume(r, t) { 2258 try { 2259 var n = e[r](t), 2260 o = n.value, 2261 u = o instanceof _OverloadYield; 2262 Promise.resolve(u ? o.v : o).then(function (t) { 2263 if (u) { 2264 var i = "return" === r ? "return" : "next"; 2265 if (!o.k || t.done) return resume(i, t); 2266 t = e[i](t).value; 2267 } 2268 settle(n.done ? "return" : "normal", t); 2269 }, function (e) { 2270 resume("throw", e); 2271 }); 2272 } catch (e) { 2273 settle("throw", e); 2274 } 2275 } 2276 function settle(e, n) { 2277 switch (e) { 2278 case "return": 2279 r.resolve({ 2280 value: n, 2281 done: !0 2282 }); 2283 break; 2284 case "throw": 2285 r.reject(n); 2286 break; 2287 default: 2288 r.resolve({ 2289 value: n, 2290 done: !1 2291 }); 2292 } 2293 (r = r.next) ? resume(r.key, r.arg) : t = null; 2294 } 2295 this._invoke = function (e, n) { 2296 return new Promise(function (o, u) { 2297 var i = { 2298 key: e, 2299 arg: n, 2300 resolve: o, 2301 reject: u, 2302 next: null 2303 }; 2304 t ? t = t.next = i : (r = t = i, resume(e, n)); 2305 }); 2306 }, "function" != typeof e.return && (this.return = void 0); 2307 } 2308 _AsyncGenerator.prototype["function" == typeof Symbol && Symbol.asyncIterator || "@@asyncIterator"] = function () { 2309 return this; 2310 }, _AsyncGenerator.prototype.next = function (e) { 2311 return this._invoke("next", e); 2312 }, _AsyncGenerator.prototype.throw = function (e) { 2313 return this._invoke("throw", e); 2314 }, _AsyncGenerator.prototype.return = function (e) { 2315 return this._invoke("return", e); 2316 }; 2317 function _OverloadYield(t, e) { 2318 this.v = t, this.k = e; 2319 } 2320 function old_createMetadataMethodsForProperty(e, t, a, r) { 2321 return { 2322 getMetadata: function (o) { 2323 old_assertNotFinished(r, "getMetadata"), old_assertMetadataKey(o); 2324 var i = e[o]; 2325 if (void 0 !== i) if (1 === t) { 2326 var n = i.public; 2327 if (void 0 !== n) return n[a]; 2328 } else if (2 === t) { 2329 var l = i.private; 2330 if (void 0 !== l) return l.get(a); 2331 } else if (Object.hasOwnProperty.call(i, "constructor")) return i.constructor; 2332 }, 2333 setMetadata: function (o, i) { 2334 old_assertNotFinished(r, "setMetadata"), old_assertMetadataKey(o); 2335 var n = e[o]; 2336 if (void 0 === n && (n = e[o] = {}), 1 === t) { 2337 var l = n.public; 2338 void 0 === l && (l = n.public = {}), l[a] = i; 2339 } else if (2 === t) { 2340 var s = n.priv; 2341 void 0 === s && (s = n.private = new Map()), s.set(a, i); 2342 } else n.constructor = i; 2343 } 2344 }; 2345 } 2346 function old_convertMetadataMapToFinal(e, t) { 2347 var a = e[Symbol.metadata || Symbol.for("Symbol.metadata")], 2348 r = Object.getOwnPropertySymbols(t); 2349 if (0 !== r.length) { 2350 for (var o = 0; o < r.length; o++) { 2351 var i = r[o], 2352 n = t[i], 2353 l = a ? a[i] : null, 2354 s = n.public, 2355 c = l ? l.public : null; 2356 s && c && Object.setPrototypeOf(s, c); 2357 var d = n.private; 2358 if (d) { 2359 var u = Array.from(d.values()), 2360 f = l ? l.private : null; 2361 f && (u = u.concat(f)), n.private = u; 2362 } 2363 l && Object.setPrototypeOf(n, l); 2364 } 2365 a && Object.setPrototypeOf(t, a), e[Symbol.metadata || Symbol.for("Symbol.metadata")] = t; 2366 } 2367 } 2368 function old_createAddInitializerMethod(e, t) { 2369 return function (a) { 2370 old_assertNotFinished(t, "addInitializer"), old_assertCallable(a, "An initializer"), e.push(a); 2371 }; 2372 } 2373 function old_memberDec(e, t, a, r, o, i, n, l, s) { 2374 var c; 2375 switch (i) { 2376 case 1: 2377 c = "accessor"; 2378 break; 2379 case 2: 2380 c = "method"; 2381 break; 2382 case 3: 2383 c = "getter"; 2384 break; 2385 case 4: 2386 c = "setter"; 2387 break; 2388 default: 2389 c = "field"; 2390 } 2391 var d, 2392 u, 2393 f = { 2394 kind: c, 2395 name: l ? "#" + t : t, 2396 isStatic: n, 2397 isPrivate: l 2398 }, 2399 p = { 2400 v: !1 2401 }; 2402 if (0 !== i && (f.addInitializer = old_createAddInitializerMethod(o, p)), l) { 2403 d = 2, u = Symbol(t); 2404 var v = {}; 2405 0 === i ? (v.get = a.get, v.set = a.set) : 2 === i ? v.get = function () { 2406 return a.value; 2407 } : (1 !== i && 3 !== i || (v.get = function () { 2408 return a.get.call(this); 2409 }), 1 !== i && 4 !== i || (v.set = function (e) { 2410 a.set.call(this, e); 2411 })), f.access = v; 2412 } else d = 1, u = t; 2413 try { 2414 return e(s, Object.assign(f, old_createMetadataMethodsForProperty(r, d, u, p))); 2415 } finally { 2416 p.v = !0; 2417 } 2418 } 2419 function old_assertNotFinished(e, t) { 2420 if (e.v) throw new Error("attempted to call " + t + " after decoration was finished"); 2421 } 2422 function old_assertMetadataKey(e) { 2423 if ("symbol" != typeof e) throw new TypeError("Metadata keys must be symbols, received: " + e); 2424 } 2425 function old_assertCallable(e, t) { 2426 if ("function" != typeof e) throw new TypeError(t + " must be a function"); 2427 } 2428 function old_assertValidReturnValue(e, t) { 2429 var a = typeof t; 2430 if (1 === e) { 2431 if ("object" !== a || null === t) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0"); 2432 void 0 !== t.get && old_assertCallable(t.get, "accessor.get"), void 0 !== t.set && old_assertCallable(t.set, "accessor.set"), void 0 !== t.init && old_assertCallable(t.init, "accessor.init"), void 0 !== t.initializer && old_assertCallable(t.initializer, "accessor.initializer"); 2433 } else if ("function" !== a) { 2434 var r; 2435 throw r = 0 === e ? "field" : 10 === e ? "class" : "method", new TypeError(r + " decorators must return a function or void 0"); 2436 } 2437 } 2438 function old_getInit(e) { 2439 var t; 2440 return null == (t = e.init) && (t = e.initializer) && "undefined" != typeof console && console.warn(".initializer has been renamed to .init as of March 2022"), t; 2441 } 2442 function old_applyMemberDec(e, t, a, r, o, i, n, l, s) { 2443 var c, 2444 d, 2445 u, 2446 f, 2447 p, 2448 v, 2449 h = a[0]; 2450 if (n ? c = 0 === o || 1 === o ? { 2451 get: a[3], 2452 set: a[4] 2453 } : 3 === o ? { 2454 get: a[3] 2455 } : 4 === o ? { 2456 set: a[3] 2457 } : { 2458 value: a[3] 2459 } : 0 !== o && (c = Object.getOwnPropertyDescriptor(t, r)), 1 === o ? u = { 2460 get: c.get, 2461 set: c.set 2462 } : 2 === o ? u = c.value : 3 === o ? u = c.get : 4 === o && (u = c.set), "function" == typeof h) void 0 !== (f = old_memberDec(h, r, c, l, s, o, i, n, u)) && (old_assertValidReturnValue(o, f), 0 === o ? d = f : 1 === o ? (d = old_getInit(f), p
vendor: 22,399 bytes, lines 2462-3105
2462= f.get || u.get, v = f.set || u.set, u = { 2463 get: p, 2464 set: v 2465 }) : u = f);else for (var y = h.length - 1; y >= 0; y--) { 2466 var b; 2467 if (void 0 !== (f = old_memberDec(h[y], r, c, l, s, o, i, n, u))) old_assertValidReturnValue(o, f), 0 === o ? b = f : 1 === o ? (b = old_getInit(f), p = f.get || u.get, v = f.set || u.set, u = { 2468 get: p, 2469 set: v 2470 }) : u = f, void 0 !== b && (void 0 === d ? d = b : "function" == typeof d ? d = [d, b] : d.push(b)); 2471 } 2472 if (0 === o || 1 === o) { 2473 if (void 0 === d) d = function (e, t) { 2474 return t; 2475 };else if ("function" != typeof d) { 2476 var g = d; 2477 d = function (e, t) { 2478 for (var a = t, r = 0; r < g.length; r++) a = g[r].call(e, a); 2479 return a; 2480 }; 2481 } else { 2482 var m = d; 2483 d = function (e, t) { 2484 return m.call(e, t); 2485 }; 2486 } 2487 e.push(d); 2488 } 2489 0 !== o && (1 === o ? (c.get = u.get, c.set = u.set) : 2 === o ? c.value = u : 3 === o ? c.get = u : 4 === o && (c.set = u), n ? 1 === o ? (e.push(function (e, t) { 2490 return u.get.call(e, t); 2491 }), e.push(function (e, t) { 2492 return u.set.call(e, t); 2493 })) : 2 === o ? e.push(u) : e.push(function (e, t) { 2494 return u.call(e, t); 2495 }) : Object.defineProperty(t, r, c)); 2496 } 2497 function old_applyMemberDecs(e, t, a, r, o) { 2498 for (var i, n, l = new Map(), s = new Map(), c = 0; c < o.length; c++) { 2499 var d = o[c]; 2500 if (Array.isArray(d)) { 2501 var u, 2502 f, 2503 p, 2504 v = d[1], 2505 h = d[2], 2506 y = d.length > 3, 2507 b = v >= 5; 2508 if (b ? (u = t, f = r, 0 !== (v -= 5) && (p = n = n || [])) : (u = t.prototype, f = a, 0 !== v && (p = i = i || [])), 0 !== v && !y) { 2509 var g = b ? s : l, 2510 m = g.get(h) || 0; 2511 if (!0 === m || 3 === m && 4 !== v || 4 === m && 3 !== v) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + h); 2512 !m && v > 2 ? g.set(h, v) : g.set(h, !0); 2513 } 2514 old_applyMemberDec(e, u, d, h, v, b, y, f, p); 2515 } 2516 } 2517 old_pushInitializers(e, i), old_pushInitializers(e, n); 2518 } 2519 function old_pushInitializers(e, t) { 2520 t && e.push(function (e) { 2521 for (var a = 0; a < t.length; a++) t[a].call(e); 2522 return e; 2523 }); 2524 } 2525 function old_applyClassDecs(e, t, a, r) { 2526 if (r.length > 0) { 2527 for (var o = [], i = t, n = t.name, l = r.length - 1; l >= 0; l--) { 2528 var s = { 2529 v: !1 2530 }; 2531 try { 2532 var c = Object.assign({ 2533 kind: "class", 2534 name: n, 2535 addInitializer: old_createAddInitializerMethod(o, s) 2536 }, old_createMetadataMethodsForProperty(a, 0, n, s)), 2537 d = r[l](i, c); 2538 } finally { 2539 s.v = !0; 2540 } 2541 void 0 !== d && (old_assertValidReturnValue(10, d), i = d); 2542 } 2543 e.push(i, function () { 2544 for (var e = 0; e < o.length; e++) o[e].call(i); 2545 }); 2546 } 2547 } 2548 function _applyDecs(e, t, a) { 2549 var r = [], 2550 o = {}, 2551 i = {}; 2552 return old_applyMemberDecs(r, e, i, o, t), old_convertMetadataMapToFinal(e.prototype, i), old_applyClassDecs(r, e, o, a), old_convertMetadataMapToFinal(e, o), r; 2553 } 2554 function applyDecs2203Factory() { 2555 function createAddInitializerMethod(e, t) { 2556 return function (r) { 2557 !function (e, t) { 2558 if (e.v) throw new Error("attempted to call " + t + " after decoration was finished"); 2559 }(t, "addInitializer"), assertCallable(r, "An initializer"), e.push(r); 2560 }; 2561 } 2562 function memberDec(e, t, r, a, n, i, s, o) { 2563 var c; 2564 switch (n) { 2565 case 1: 2566 c = "accessor"; 2567 break; 2568 case 2: 2569 c = "method"; 2570 break; 2571 case 3: 2572 c = "getter"; 2573 break; 2574 case 4: 2575 c = "setter"; 2576 break; 2577 default: 2578 c = "field"; 2579 } 2580 var l, 2581 u, 2582 f = { 2583 kind: c, 2584 name: s ? "#" + t : t, 2585 static: i, 2586 private: s 2587 }, 2588 p = { 2589 v: !1 2590 }; 2591 0 !== n && (f.addInitializer = createAddInitializerMethod(a, p)), 0 === n ? s ? (l = r.get, u = r.set) : (l = function () { 2592 return this[t]; 2593 }, u = function (e) { 2594 this[t] = e; 2595 }) : 2 === n ? l = function () { 2596 return r.value; 2597 } : (1 !== n && 3 !== n || (l = function () { 2598 return r.get.call(this); 2599 }), 1 !== n && 4 !== n || (u = function (e) { 2600 r.set.call(this, e); 2601 })), f.access = l && u ? { 2602 get: l, 2603 set: u 2604 } : l ? { 2605 get: l 2606 } : { 2607 set: u 2608 }; 2609 try { 2610 return e(o, f); 2611 } finally { 2612 p.v = !0; 2613 } 2614 } 2615 function assertCallable(e, t) { 2616 if ("function" != typeof e) throw new TypeError(t + " must be a function"); 2617 } 2618 function assertValidReturnValue(e, t) { 2619 var r = typeof t; 2620 if (1 === e) { 2621 if ("object" !== r || null === t) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0"); 2622 void 0 !== t.get && assertCallable(t.get, "accessor.get"), void 0 !== t.set && assertCallable(t.set, "accessor.set"), void 0 !== t.init && assertCallable(t.init, "accessor.init"); 2623 } else if ("function" !== r) { 2624 var a; 2625 throw a = 0 === e ? "field" : 10 === e ? "class" : "method", new TypeError(a + " decorators must return a function or void 0"); 2626 } 2627 } 2628 function applyMemberDec(e, t, r, a, n, i, s, o) { 2629 var c, 2630 l, 2631 u, 2632 f, 2633 p, 2634 d, 2635 h = r[0]; 2636 if (s ? c = 0 === n || 1 === n ? { 2637 get: r[3], 2638 set: r[4] 2639 } : 3 === n ? { 2640 get: r[3] 2641 } : 4 === n ? { 2642 set: r[3] 2643 } : { 2644 value: r[3] 2645 } : 0 !== n && (c = Object.getOwnPropertyDescriptor(t, a)), 1 === n ? u = { 2646 get: c.get, 2647 set: c.set 2648 } : 2 === n ? u = c.value : 3 === n ? u = c.get : 4 === n && (u = c.set), "function" == typeof h) void 0 !== (f = memberDec(h, a, c, o, n, i, s, u)) && (assertValidReturnValue(n, f), 0 === n ? l = f : 1 === n ? (l = f.init, p = f.get || u.get, d = f.set || u.set, u = { 2649 get: p, 2650 set: d 2651 }) : u = f);else for (var v = h.length - 1; v >= 0; v--) { 2652 var g; 2653 if (void 0 !== (f = memberDec(h[v], a, c, o, n, i, s, u))) assertValidReturnValue(n, f), 0 === n ? g = f : 1 === n ? (g = f.init, p = f.get || u.get, d = f.set || u.set, u = { 2654 get: p, 2655 set: d 2656 }) : u = f, void 0 !== g && (void 0 === l ? l = g : "function" == typeof l ? l = [l, g] : l.push(g)); 2657 } 2658 if (0 === n || 1 === n) { 2659 if (void 0 === l) l = function (e, t) { 2660 return t; 2661 };else if ("function" != typeof l) { 2662 var y = l; 2663 l = function (e, t) { 2664 for (var r = t, a = 0; a < y.length; a++) r = y[a].call(e, r); 2665 return r; 2666 }; 2667 } else { 2668 var m = l; 2669 l = function (e, t) { 2670 return m.call(e, t); 2671 }; 2672 } 2673 e.push(l); 2674 } 2675 0 !== n && (1 === n ? (c.get = u.get, c.set = u.set) : 2 === n ? c.value = u : 3 === n ? c.get = u : 4 === n && (c.set = u), s ? 1 === n ? (e.push(function (e, t) { 2676 return u.get.call(e, t); 2677 }), e.push(function (e, t) { 2678 return u.set.call(e, t); 2679 })) : 2 === n ? e.push(u) : e.push(function (e, t) { 2680 return u.call(e, t); 2681 }) : Object.defineProperty(t, a, c)); 2682 } 2683 function pushInitializers(e, t) { 2684 t && e.push(function (e) { 2685 for (var r = 0; r < t.length; r++) t[r].call(e); 2686 return e; 2687 }); 2688 } 2689 return function (e, t, r) { 2690 var a = []; 2691 return function (e, t, r) { 2692 for (var a, n, i = new Map(), s = new Map(), o = 0; o < r.length; o++) { 2693 var c = r[o]; 2694 if (Array.isArray(c)) { 2695 var l, 2696 u, 2697 f = c[1], 2698 p = c[2], 2699 d = c.length > 3, 2700 h = f >= 5; 2701 if (h ? (l = t, 0 != (f -= 5) && (u = n = n || [])) : (l = t.prototype, 0 !== f && (u = a = a || [])), 0 !== f && !d) { 2702 var v = h ? s : i, 2703 g = v.get(p) || 0; 2704 if (!0 === g || 3 === g && 4 !== f || 4 === g && 3 !== f) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + p); 2705 !g && f > 2 ? v.set(p, f) : v.set(p, !0); 2706 } 2707 applyMemberDec(e, l, c, p, f, h, d, u); 2708 } 2709 } 2710 pushInitializers(e, a), pushInitializers(e, n); 2711 }(a, e, t), function (e, t, r) { 2712 if (r.length > 0) { 2713 for (var a = [], n = t, i = t.name, s = r.length - 1; s >= 0; s--) { 2714 var o = { 2715 v: !1 2716 }; 2717 try { 2718 var c = r[s](n, { 2719 kind: "class", 2720 name: i, 2721 addInitializer: createAddInitializerMethod(a, o) 2722 }); 2723 } finally { 2724 o.v = !0; 2725 } 2726 void 0 !== c && (assertValidReturnValue(10, c), n = c); 2727 } 2728 e.push(n, function () { 2729 for (var e = 0; e < a.length; e++) a[e].call(n); 2730 }); 2731 } 2732 }(a, e, r), a; 2733 }; 2734 } 2735 var applyDecs2203Impl; 2736 function _applyDecs2203(e, t, r) { 2737 return (applyDecs2203Impl = applyDecs2203Impl || applyDecs2203Factory())(e, t, r); 2738 } 2739 function applyDecs2203RFactory() { 2740 function createAddInitializerMethod(e, t) { 2741 return function (r) { 2742 !function (e, t) { 2743 if (e.v) throw new Error("attempted to call " + t + " after decoration was finished"); 2744 }(t, "addInitializer"), assertCallable(r, "An initializer"), e.push(r); 2745 }; 2746 } 2747 function memberDec(e, t, r, n, a, i, s, o) { 2748 var c; 2749 switch (a) { 2750 case 1: 2751 c = "accessor"; 2752 break; 2753 case 2: 2754 c = "method"; 2755 break; 2756 case 3: 2757 c = "getter"; 2758 break; 2759 case 4: 2760 c = "setter"; 2761 break; 2762 default: 2763 c = "field"; 2764 } 2765 var l, 2766 u, 2767 f = { 2768 kind: c, 2769 name: s ? "#" + t : t, 2770 static: i, 2771 private: s 2772 }, 2773 p = { 2774 v: !1 2775 }; 2776 0 !== a && (f.addInitializer = createAddInitializerMethod(n, p)), 0 === a ? s ? (l = r.get, u = r.set) : (l = function () { 2777 return this[t]; 2778 }, u = function (e) { 2779 this[t] = e; 2780 }) : 2 === a ? l = function () { 2781 return r.value; 2782 } : (1 !== a && 3 !== a || (l = function () { 2783 return r.get.call(this); 2784 }), 1 !== a && 4 !== a || (u = function (e) { 2785 r.set.call(this, e); 2786 })), f.access = l && u ? { 2787 get: l, 2788 set: u 2789 } : l ? { 2790 get: l 2791 } : { 2792 set: u 2793 }; 2794 try { 2795 return e(o, f); 2796 } finally { 2797 p.v = !0; 2798 } 2799 } 2800 function assertCallable(e, t) { 2801 if ("function" != typeof e) throw new TypeError(t + " must be a function"); 2802 } 2803 function assertValidReturnValue(e, t) { 2804 var r = typeof t; 2805 if (1 === e) { 2806 if ("object" !== r || null === t) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0"); 2807 void 0 !== t.get && assertCallable(t.get, "accessor.get"), void 0 !== t.set && assertCallable(t.set, "accessor.set"), void 0 !== t.init && assertCallable(t.init, "accessor.init"); 2808 } else if ("function" !== r) { 2809 var n; 2810 throw n = 0 === e ? "field" : 10 === e ? "class" : "method", new TypeError(n + " decorators must return a function or void 0"); 2811 } 2812 } 2813 function applyMemberDec(e, t, r, n, a, i, s, o) { 2814 var c, 2815 l, 2816 u, 2817 f, 2818 p, 2819 d, 2820 h = r[0]; 2821 if (s ? c = 0 === a || 1 === a ? { 2822 get: r[3], 2823 set: r[4] 2824 } : 3 === a ? { 2825 get: r[3] 2826 } : 4 === a ? { 2827 set: r[3] 2828 } : { 2829 value: r[3] 2830 } : 0 !== a && (c = Object.getOwnPropertyDescriptor(t, n)), 1 === a ? u = { 2831 get: c.get, 2832 set: c.set 2833 } : 2 === a ? u = c.value : 3 === a ? u = c.get : 4 === a && (u = c.set), "function" == typeof h) void 0 !== (f = memberDec(h, n, c, o, a, i, s, u)) && (assertValidReturnValue(a, f), 0 === a ? l = f : 1 === a ? (l = f.init, p = f.get || u.get, d = f.set || u.set, u = { 2834 get: p, 2835 set: d 2836 }) : u = f);else for (var v = h.length - 1; v >= 0; v--) { 2837 var g; 2838 if (void 0 !== (f = memberDec(h[v], n, c, o, a, i, s, u))) assertValidReturnValue(a, f), 0 === a ? g = f : 1 === a ? (g = f.init, p = f.get || u.get, d = f.set || u.set, u = { 2839 get: p, 2840 set: d 2841 }) : u = f, void 0 !== g && (void 0 === l ? l = g : "function" == typeof l ? l = [l, g] : l.push(g)); 2842 } 2843 if (0 === a || 1 === a) { 2844 if (void 0 === l) l = function (e, t) { 2845 return t; 2846 };else if ("function" != typeof l) { 2847 var y = l; 2848 l = function (e, t) { 2849 for (var r = t, n = 0; n < y.length; n++) r = y[n].call(e, r); 2850 return r; 2851 }; 2852 } else { 2853 var m = l; 2854 l = function (e, t) { 2855 return m.call(e, t); 2856 }; 2857 } 2858 e.push(l); 2859 } 2860 0 !== a && (1 === a ? (c.get = u.get, c.set = u.set) : 2 === a ? c.value = u : 3 === a ? c.get = u : 4 === a && (c.set = u), s ? 1 === a ? (e.push(function (e, t) { 2861 return u.get.call(e, t); 2862 }), e.push(function (e, t) { 2863 return u.set.call(e, t); 2864 })) : 2 === a ? e.push(u) : e.push(function (e, t) { 2865 return u.call(e, t); 2866 }) : Object.defineProperty(t, n, c)); 2867 } 2868 function applyMemberDecs(e, t) { 2869 for (var r, n, a = [], i = new Map(), s = new Map(), o = 0; o < t.length; o++) { 2870 var c = t[o]; 2871 if (Array.isArray(c)) { 2872 var l, 2873 u, 2874 f = c[1], 2875 p = c[2], 2876 d = c.length > 3, 2877 h = f >= 5; 2878 if (h ? (l = e, 0 !== (f -= 5) && (u = n = n || [])) : (l = e.prototype, 0 !== f && (u = r = r || [])), 0 !== f && !d) { 2879 var v = h ? s : i, 2880 g = v.get(p) || 0; 2881 if (!0 === g || 3 === g && 4 !== f || 4 === g && 3 !== f) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + p); 2882 !g && f > 2 ? v.set(p, f) : v.set(p, !0); 2883 } 2884 applyMemberDec(a, l, c, p, f, h, d, u); 2885 } 2886 } 2887 return pushInitializers(a, r), pushInitializers(a, n), a; 2888 } 2889 function pushInitializers(e, t) { 2890 t && e.push(function (e) { 2891 for (var r = 0; r < t.length; r++) t[r].call(e); 2892 return e; 2893 }); 2894 } 2895 return function (e, t, r) { 2896 return { 2897 e: applyMemberDecs(e, t), 2898 get c() { 2899 return function (e, t) { 2900 if (t.length > 0) { 2901 for (var r = [], n = e, a = e.name, i = t.length - 1; i >= 0; i--) { 2902 var s = { 2903 v: !1 2904 }; 2905 try { 2906 var o = t[i](n, { 2907 kind: "class", 2908 name: a, 2909 addInitializer: createAddInitializerMethod(r, s) 2910 }); 2911 } finally { 2912 s.v = !0; 2913 } 2914 void 0 !== o && (assertValidReturnValue(10, o), n = o); 2915 } 2916 return [n, function () { 2917 for (var e = 0; e < r.length; e++) r[e].call(n); 2918 }]; 2919 } 2920 }(e, r); 2921 } 2922 }; 2923 }; 2924 } 2925 function _applyDecs2203R(e, t, r) { 2926 return (_applyDecs2203R = applyDecs2203RFactory())(e, t, r); 2927 } 2928 function applyDecs2301Factory() { 2929 function createAddInitializerMethod(e, t) { 2930 return function (r) { 2931 !function (e, t) { 2932 if (e.v) throw new Error("attempted to call " + t + " after decoration was finished"); 2933 }(t, "addInitializer"), assertCallable(r, "An initializer"), e.push(r); 2934 }; 2935 } 2936 function assertInstanceIfPrivate(e, t) { 2937 if (!e(t)) throw new TypeError("Attempted to access private element on non-instance"); 2938 } 2939 function memberDec(e, t, r, n, a, i, s, o, c) { 2940 var u; 2941 switch (a) { 2942 case 1: 2943 u = "accessor"; 2944 break; 2945 case 2: 2946 u = "method"; 2947 break; 2948 case 3: 2949 u = "getter"; 2950 break; 2951 case 4: 2952 u = "setter"; 2953 break; 2954 default: 2955 u = "field"; 2956 } 2957 var l, 2958 f, 2959 p = { 2960 kind: u, 2961 name: s ? "#" + t : t, 2962 static: i, 2963 private: s 2964 }, 2965 d = { 2966 v: !1 2967 }; 2968 if (0 !== a && (p.addInitializer = createAddInitializerMethod(n, d)), s || 0 !== a && 2 !== a) { 2969 if (2 === a) l = function (e) { 2970 return assertInstanceIfPrivate(c, e), r.value; 2971 };else { 2972 var h = 0 === a || 1 === a; 2973 (h || 3 === a) && (l = s ? function (e) { 2974 return assertInstanceIfPrivate(c, e), r.get.call(e); 2975 } : function (e) { 2976 return r.get.call(e); 2977 }), (h || 4 === a) && (f = s ? function (e, t) { 2978 assertInstanceIfPrivate(c, e), r.set.call(e, t); 2979 } : function (e, t) { 2980 r.set.call(e, t); 2981 }); 2982 } 2983 } else l = function (e) { 2984 return e[t]; 2985 }, 0 === a && (f = function (e, r) { 2986 e[t] = r; 2987 }); 2988 var v = s ? c.bind() : function (e) { 2989 return t in e; 2990 }; 2991 p.access = l && f ? { 2992 get: l, 2993 set: f, 2994 has: v 2995 } : l ? { 2996 get: l, 2997 has: v 2998 } : { 2999 set: f, 3000 has: v 3001 }; 3002 try { 3003 return e(o, p); 3004 } finally { 3005 d.v = !0; 3006 } 3007 } 3008 function assertCallable(e, t) { 3009 if ("function" != typeof e) throw new TypeError(t + " must be a function"); 3010 } 3011 function assertValidReturnValue(e, t) { 3012 var r = typeof t; 3013 if (1 === e) { 3014 if ("object" !== r || null === t) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0"); 3015 void 0 !== t.get && assertCallable(t.get, "accessor.get"), void 0 !== t.set && assertCallable(t.set, "accessor.set"), void 0 !== t.init && assertCallable(t.init, "accessor.init"); 3016 } else if ("function" !== r) { 3017 var n; 3018 throw n = 0 === e ? "field" : 10 === e ? "class" : "method", new TypeError(n + " decorators must return a function or void 0"); 3019 } 3020 } 3021 function curryThis2(e) { 3022 return function (t) { 3023 e(this, t); 3024 }; 3025 } 3026 function applyMemberDec(e, t, r, n, a, i, s, o, c) { 3027 var u, 3028 l, 3029 f, 3030 p, 3031 d, 3032 h, 3033 v, 3034 g = r[0]; 3035 if (s ? u = 0 === a || 1 === a ? { 3036 get: (p = r[3], function () { 3037 return p(this); 3038 }), 3039 set: curryThis2(r[4]) 3040 } : 3 === a ? { 3041 get: r[3] 3042 } : 4 === a ? { 3043 set: r[3] 3044 } : { 3045 value: r[3] 3046 } : 0 !== a && (u = Object.getOwnPropertyDescriptor(t, n)), 1 === a ? f = { 3047 get: u.get, 3048 set: u.set 3049 } : 2 === a ? f = u.value : 3 === a ? f = u.get : 4 === a && (f = u.set), "function" == typeof g) void 0 !== (d = memberDec(g, n, u, o, a, i, s, f, c)) && (assertValidReturnValue(a, d), 0 === a ? l = d : 1 === a ? (l = d.init, h = d.get || f.get, v = d.set || f.set, f = { 3050 get: h, 3051 set: v 3052 }) : f = d);else for (var y = g.length - 1; y >= 0; y--) { 3053 var m; 3054 if (void 0 !== (d = memberDec(g[y], n, u, o, a, i, s, f, c))) assertValidReturnValue(a, d), 0 === a ? m = d : 1 === a ? (m = d.init, h = d.get || f.get, v = d.set || f.set, f = { 3055 get: h, 3056 set: v 3057 }) : f = d, void 0 !== m && (void 0 === l ? l = m : "function" == typeof l ? l = [l, m] : l.push(m)); 3058 } 3059 if (0 === a || 1 === a) { 3060 if (void 0 === l) l = function (e, t) { 3061 return t; 3062 };else if ("function" != typeof l) { 3063 var b = l; 3064 l = function (e, t) { 3065 for (var r = t, n = 0; n < b.length; n++) r = b[n].call(e, r); 3066 return r; 3067 }; 3068 } else { 3069 var I = l; 3070 l = function (e, t) { 3071 return I.call(e, t); 3072 }; 3073 } 3074 e.push(l); 3075 } 3076 0 !== a && (1 === a ? (u.get = f.get, u.set = f.set) : 2 === a ? u.value = f : 3 === a ? u.get = f : 4 === a && (u.set = f), s ? 1 === a ? (e.push(function (e, t) { 3077 return f.get.call(e, t); 3078 }), e.push(function (e, t) { 3079 return f.set.call(e, t); 3080 })) : 2 === a ? e.push(f) : e.push(function (e, t) { 3081 return f.call(e, t); 3082 }) : Object.defineProperty(t, n, u)); 3083 } 3084 function applyMemberDecs(e, t, r) { 3085 for (var n, a, i, s = [], o = new Map(), c = new Map(), u = 0; u < t.length; u++) { 3086 var l = t[u]; 3087 if (Array.isArray(l)) { 3088 var f, 3089 p, 3090 d = l[1], 3091 h = l[2], 3092 v = l.length > 3, 3093 g = d >= 5, 3094 y = r; 3095 if (g ? (f = e, 0 !== (d -= 5) && (p = a = a || []), v && !i && (i = function (t) { 3096 return _checkInRHS(t) === e; 3097 }), y = i) : (f = e.prototype, 0 !== d && (p = n = n || [])), 0 !== d && !v) { 3098 var m = g ? c : o, 3099 b = m.get(h) || 0; 3100 if (!0 === b || 3 === b && 4 !== d || 4 === b && 3 !== d) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + h); 3101 !b && d > 2 ? m.set(h, d) : m.set(h, !0); 3102 } 3103 applyMemberDec(s, f, l, h, d, g, v, p, y); 3104 } 3105 }
vendor: 6,955 bytes, lines 3106-3326
3106 return pushInitializers(s, n), pushInitializers(s, a), s; 3107 } 3108 function pushInitializers(e, t) { 3109 t && e.push(function (e) { 3110 for (var r = 0; r < t.length; r++) t[r].call(e); 3111 return e; 3112 }); 3113 } 3114 return function (e, t, r, n) { 3115 return { 3116 e: applyMemberDecs(e, t, n), 3117 get c() { 3118 return function (e, t) { 3119 if (t.length > 0) { 3120 for (var r = [], n = e, a = e.name, i = t.length - 1; i >= 0; i--) { 3121 var s = { 3122 v: !1 3123 }; 3124 try { 3125 var o = t[i](n, { 3126 kind: "class", 3127 name: a, 3128 addInitializer: createAddInitializerMethod(r, s) 3129 }); 3130 } finally { 3131 s.v = !0; 3132 } 3133 void 0 !== o && (assertValidReturnValue(10, o), n = o); 3134 } 3135 return [n, function () { 3136 for (var e = 0; e < r.length; e++) r[e].call(n); 3137 }]; 3138 } 3139 }(e, r); 3140 } 3141 }; 3142 }; 3143 } 3144 function _applyDecs2301(e, t, r, n) { 3145 return (_applyDecs2301 = applyDecs2301Factory())(e, t, r, n); 3146 } 3147 function createAddInitializerMethod(e, t) { 3148 return function (r) { 3149 assertNotFinished(t, "addInitializer"), assertCallable(r, "An initializer"), e.push(r); 3150 }; 3151 } 3152 function assertInstanceIfPrivate(e, t) { 3153 if (!e(t)) throw new TypeError("Attempted to access private element on non-instance"); 3154 } 3155 function memberDec(e, t, r, a, n, i, s, o, c, l, u) { 3156 var f; 3157 switch (i) { 3158 case 1: 3159 f = "accessor"; 3160 break; 3161 case 2: 3162 f = "method"; 3163 break; 3164 case 3: 3165 f = "getter"; 3166 break; 3167 case 4: 3168 f = "setter"; 3169 break; 3170 default: 3171 f = "field"; 3172 } 3173 var d, 3174 p, 3175 h = { 3176 kind: f, 3177 name: o ? "#" + r : r, 3178 static: s, 3179 private: o, 3180 metadata: u 3181 }, 3182 v = { 3183 v: !1 3184 }; 3185 if (0 !== i && (h.addInitializer = createAddInitializerMethod(n, v)), o || 0 !== i && 2 !== i) { 3186 if (2 === i) d = function (e) { 3187 return assertInstanceIfPrivate(l, e), a.value; 3188 };else { 3189 var y = 0 === i || 1 === i; 3190 (y || 3 === i) && (d = o ? function (e) { 3191 return assertInstanceIfPrivate(l, e), a.get.call(e); 3192 } : function (e) { 3193 return a.get.call(e); 3194 }), (y || 4 === i) && (p = o ? function (e, t) { 3195 assertInstanceIfPrivate(l, e), a.set.call(e, t); 3196 } : function (e, t) { 3197 a.set.call(e, t); 3198 }); 3199 } 3200 } else d = function (e) { 3201 return e[r]; 3202 }, 0 === i && (p = function (e, t) { 3203 e[r] = t; 3204 }); 3205 var m = o ? l.bind() : function (e) { 3206 return r in e; 3207 }; 3208 h.access = d && p ? { 3209 get: d, 3210 set: p, 3211 has: m 3212 } : d ? { 3213 get: d, 3214 has: m 3215 } : { 3216 set: p, 3217 has: m 3218 }; 3219 try { 3220 return e.call(t, c, h); 3221 } finally { 3222 v.v = !0; 3223 } 3224 } 3225 function assertNotFinished(e, t) { 3226 if (e.v) throw new Error("attempted to call " + t + " after decoration was finished"); 3227 } 3228 function assertCallable(e, t) { 3229 if ("function" != typeof e) throw new TypeError(t + " must be a function"); 3230 } 3231 function assertValidReturnValue(e, t) { 3232 var r = typeof t; 3233 if (1 === e) { 3234 if ("object" !== r || null === t) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0"); 3235 void 0 !== t.get && assertCallable(t.get, "accessor.get"), void 0 !== t.set && assertCallable(t.set, "accessor.set"), void 0 !== t.init && assertCallable(t.init, "accessor.init"); 3236 } else if ("function" !== r) { 3237 var a; 3238 throw a = 0 === e ? "field" : 5 === e ? "class" : "method", new TypeError(a + " decorators must return a function or void 0"); 3239 } 3240 } 3241 function curryThis1(e) { 3242 return function () { 3243 return e(this); 3244 }; 3245 } 3246 function curryThis2(e) { 3247 return function (t) { 3248 e(this, t); 3249 }; 3250 } 3251 function applyMemberDec(e, t, r, a, n, i, s, o, c, l, u) { 3252 var f, 3253 d, 3254 p, 3255 h, 3256 v, 3257 y, 3258 m = r[0]; 3259 a || Array.isArray(m) || (m = [m]), o ? f = 0 === i || 1 === i ? { 3260 get: curryThis1(r[3]), 3261 set: curryThis2(r[4]) 3262 } : 3 === i ? { 3263 get: r[3] 3264 } : 4 === i ? { 3265 set: r[3] 3266 } : { 3267 value: r[3] 3268 } : 0 !== i && (f = Object.getOwnPropertyDescriptor(t, n)), 1 === i ? p = { 3269 get: f.get, 3270 set: f.set 3271 } : 2 === i ? p = f.value : 3 === i ? p = f.get : 4 === i && (p = f.set); 3272 for (var g = a ? 2 : 1, b = m.length - 1; b >= 0; b -= g) { 3273 var I; 3274 if (void 0 !== (h = memberDec(m[b], a ? m[b - 1] : void 0, n, f, c, i, s, o, p, l, u))) assertValidReturnValue(i, h), 0 === i ? I = h : 1 === i ? (I = h.init, v = h.get || p.get, y = h.set || p.set, p = { 3275 get: v, 3276 set: y 3277 }) : p = h, void 0 !== I && (void 0 === d ? d = I : "function" == typeof d ? d = [d, I] : d.push(I)); 3278 } 3279 if (0 === i || 1 === i) { 3280 if (void 0 === d) d = function (e, t) { 3281 return t; 3282 };else if ("function" != typeof d) { 3283 var w = d; 3284 d = function (e, t) { 3285 for (var r = t, a = w.length - 1; a >= 0; a--) r = w[a].call(e, r); 3286 return r; 3287 }; 3288 } else { 3289 var M = d; 3290 d = function (e, t) { 3291 return M.call(e, t); 3292 }; 3293 } 3294 e.push(d); 3295 } 3296 0 !== i && (1 === i ? (f.get = p.get, f.set = p.set) : 2 === i ? f.value = p : 3 === i ? f.get = p : 4 === i && (f.set = p), o ? 1 === i ? (e.push(function (e, t) { 3297 return p.get.call(e, t); 3298 }), e.push(function (e, t) { 3299 return p.set.call(e, t); 3300 })) : 2 === i ? e.push(p) : e.push(function (e, t) { 3301 return p.call(e, t); 3302 }) : Object.defineProperty(t, n, f)); 3303 } 3304 function applyMemberDecs(e, t, r, a) { 3305 for (var n, i, s, o = [], c = new Map(), l = new Map(), u = 0; u < t.length; u++) { 3306 var f = t[u]; 3307 if (Array.isArray(f)) { 3308 var d, 3309 p, 3310 h = f[1], 3311 v = f[2], 3312 y = f.length > 3, 3313 m = 16 & h, 3314 g = !!(8 & h), 3315 b = r; 3316 if (h &= 7, g ? (d = e, 0 !== h && (p = i = i || []), y && !s && (s = function (t) { 3317 return _checkInRHS(t) === e; 3318 }), b = s) : (d = e.prototype, 0 !== h && (p = n = n || [])), 0 !== h && !y) { 3319 var I = g ? l : c, 3320 w = I.get(v) || 0; 3321 if (!0 === w || 3 === w && 4 !== h || 4 === w && 3 !== h) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + v); 3322 I.set(v, !(!w && h > 2) || h); 3323 } 3324 applyMemberDec(o, d, f, m, v, h, g, y, p, b, a); 3325 } 3326 }
vendor: 23,828 bytes, lines 3327-4010
3327 return pushInitializers(o, n), pushInitializers(o, i), o; 3328 } 3329 function pushInitializers(e, t) { 3330 t && e.push(function (e) { 3331 for (var r = 0; r < t.length; r++) t[r].call(e); 3332 return e; 3333 }); 3334 } 3335 function applyClassDecs(e, t, r, a) { 3336 if (t.length) { 3337 for (var n = [], i = e, s = e.name, o = r ? 2 : 1, c = t.length - 1; c >= 0; c -= o) { 3338 var l = { 3339 v: !1 3340 }; 3341 try { 3342 var u = t[c].call(r ? t[c - 1] : void 0, i, { 3343 kind: "class", 3344 name: s, 3345 addInitializer: createAddInitializerMethod(n, l), 3346 metadata: a 3347 }); 3348 } finally { 3349 l.v = !0; 3350 } 3351 void 0 !== u && (assertValidReturnValue(5, u), i = u); 3352 } 3353 return [defineMetadata(i, a), function () { 3354 for (var e = 0; e < n.length; e++) n[e].call(i); 3355 }]; 3356 } 3357 } 3358 function defineMetadata(e, t) { 3359 return Object.defineProperty(e, Symbol.metadata || Symbol.for("Symbol.metadata"), { 3360 configurable: !0, 3361 enumerable: !0, 3362 value: t 3363 }); 3364 } 3365 function _applyDecs2305(e, t, r, a, n, i) { 3366 if (arguments.length >= 6) var s = i[Symbol.metadata || Symbol.for("Symbol.metadata")]; 3367 var o = Object.create(void 0 === s ? null : s), 3368 c = applyMemberDecs(e, t, n, o); 3369 return r.length || defineMetadata(e, o), { 3370 e: c, 3371 get c() { 3372 return applyClassDecs(e, r, a, o); 3373 } 3374 }; 3375 } 3376 function _asyncGeneratorDelegate(t) { 3377 var e = {}, 3378 n = !1; 3379 function pump(e, r) { 3380 return n = !0, r = new Promise(function (n) { 3381 n(t[e](r)); 3382 }), { 3383 done: !1, 3384 value: new _OverloadYield(r, 1) 3385 }; 3386 } 3387 return e["undefined" != typeof Symbol && Symbol.iterator || "@@iterator"] = function () { 3388 return this; 3389 }, e.next = function (t) { 3390 return n ? (n = !1, t) : pump("next", t); 3391 }, "function" == typeof t.throw && (e.throw = function (t) { 3392 if (n) throw n = !1, t; 3393 return pump("throw", t); 3394 }), "function" == typeof t.return && (e.return = function (t) { 3395 return n ? (n = !1, t) : pump("return", t); 3396 }), e; 3397 } 3398 function _asyncIterator(r) { 3399 var n, 3400 t, 3401 o, 3402 e = 2; 3403 for ("undefined" != typeof Symbol && (t = Symbol.asyncIterator, o = Symbol.iterator); e--;) { 3404 if (t && null != (n = r[t])) return n.call(r); 3405 if (o && null != (n = r[o])) return new AsyncFromSyncIterator(n.call(r)); 3406 t = "@@asyncIterator", o = "@@iterator"; 3407 } 3408 throw new TypeError("Object is not async iterable"); 3409 } 3410 function AsyncFromSyncIterator(r) { 3411 function AsyncFromSyncIteratorContinuation(r) { 3412 if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object.")); 3413 var n = r.done; 3414 return Promise.resolve(r.value).then(function (r) { 3415 return { 3416 value: r, 3417 done: n 3418 }; 3419 }); 3420 } 3421 return AsyncFromSyncIterator = function (r) { 3422 this.s = r, this.n = r.next; 3423 }, AsyncFromSyncIterator.prototype = { 3424 s: null, 3425 n: null, 3426 next: function () { 3427 return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments)); 3428 }, 3429 return: function (r) { 3430 var n = this.s.return; 3431 return void 0 === n ? Promise.resolve({ 3432 value: r, 3433 done: !0 3434 }) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments)); 3435 }, 3436 throw: function (r) { 3437 var n = this.s.return; 3438 return void 0 === n ? Promise.reject(r) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments)); 3439 } 3440 }, new AsyncFromSyncIterator(r); 3441 } 3442 function _awaitAsyncGenerator(e) { 3443 return new _OverloadYield(e, 0); 3444 } 3445 function _checkInRHS(e) { 3446 if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? typeof e : "null")); 3447 return e; 3448 } 3449 function _defineAccessor(e, r, n, t) { 3450 var c = { 3451 configurable: !0, 3452 enumerable: !0 3453 }; 3454 return c[e] = t, Object.defineProperty(r, n, c); 3455 } 3456 function dispose_SuppressedError(r, e) { 3457 return "undefined" != typeof SuppressedError ? dispose_SuppressedError = SuppressedError : (dispose_SuppressedError = function (r, e) { 3458 this.suppressed = r, this.error = e, this.stack = new Error().stack; 3459 }, dispose_SuppressedError.prototype = Object.create(Error.prototype, { 3460 constructor: { 3461 value: dispose_SuppressedError, 3462 writable: !0, 3463 configurable: !0 3464 } 3465 })), new dispose_SuppressedError(r, e); 3466 } 3467 function _dispose(r, e, s) { 3468 function next() { 3469 for (; r.length > 0;) try { 3470 var o = r.pop(), 3471 p = o.d.call(o.v); 3472 if (o.a) return Promise.resolve(p).then(next, err); 3473 } catch (r) { 3474 return err(r); 3475 } 3476 if (s) throw e; 3477 } 3478 function err(r) { 3479 return e = s ? new dispose_SuppressedError(r, e) : r, s = !0, next(); 3480 } 3481 return next(); 3482 } 3483 function _importDeferProxy(e) { 3484 var t = null, 3485 constValue = function (e) { 3486 return function () { 3487 return e; 3488 }; 3489 }, 3490 proxy = function (r) { 3491 return function (n, o, f) { 3492 return null === t && (t = e()), r(t, o, f); 3493 }; 3494 }; 3495 return new Proxy({}, { 3496 defineProperty: constValue(!1), 3497 deleteProperty: constValue(!1), 3498 get: proxy(Reflect.get), 3499 getOwnPropertyDescriptor: proxy(Reflect.getOwnPropertyDescriptor), 3500 getPrototypeOf: constValue(null), 3501 isExtensible: constValue(!1), 3502 has: proxy(Reflect.has), 3503 ownKeys: proxy(Reflect.ownKeys), 3504 preventExtensions: constValue(!0), 3505 set: constValue(!1), 3506 setPrototypeOf: constValue(!1) 3507 }); 3508 } 3509 function _iterableToArrayLimit(r, l) { 3510 var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; 3511 if (null != t) { 3512 var e, 3513 n, 3514 i, 3515 u, 3516 a = [], 3517 f = !0, 3518 o = !1; 3519 try { 3520 if (i = (t = t.call(r)).next, 0 === l) { 3521 if (Object(t) !== t) return; 3522 f = !1; 3523 } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); 3524 } catch (r) { 3525 o = !0, n = r; 3526 } finally { 3527 try { 3528 if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; 3529 } finally { 3530 if (o) throw n; 3531 } 3532 } 3533 return a; 3534 } 3535 } 3536 function _iterableToArrayLimitLoose(e, r) { 3537 var t = e && ("undefined" != typeof Symbol && e[Symbol.iterator] || e["@@iterator"]); 3538 if (null != t) { 3539 var o, 3540 l = []; 3541 for (t = t.call(e); e.length < r && !(o = t.next()).done;) l.push(o.value); 3542 return l; 3543 } 3544 } 3545 var REACT_ELEMENT_TYPE; 3546 function _jsx(e, r, E, l) { 3547 REACT_ELEMENT_TYPE || (REACT_ELEMENT_TYPE = "function" == typeof Symbol && Symbol.for && Symbol.for("react.element") || 60103); 3548 var o = e && e.defaultProps, 3549 n = arguments.length - 3; 3550 if (r || 0 === n || (r = { 3551 children: void 0 3552 }), 1 === n) r.children = l;else if (n > 1) { 3553 for (var t = new Array(n), f = 0; f < n; f++) t[f] = arguments[f + 3]; 3554 r.children = t; 3555 } 3556 if (r && o) for (var i in o) void 0 === r[i] && (r[i] = o[i]);else r || (r = o || {}); 3557 return { 3558 $$typeof: REACT_ELEMENT_TYPE, 3559 type: e, 3560 key: void 0 === E ? null : "" + E, 3561 ref: null, 3562 props: r, 3563 _owner: null 3564 }; 3565 } 3566 function ownKeys(e, r) { 3567 var t = Object.keys(e); 3568 if (Object.getOwnPropertySymbols) { 3569 var o = Object.getOwnPropertySymbols(e); 3570 r && (o = o.filter(function (r) { 3571 return Object.getOwnPropertyDescriptor(e, r).enumerable; 3572 })), t.push.apply(t, o); 3573 } 3574 return t; 3575 } 3576 function _objectSpread2(e) { 3577 for (var r = 1; r < arguments.length; r++) { 3578 var t = null != arguments[r] ? arguments[r] : {}; 3579 r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { 3580 _defineProperty(e, r, t[r]); 3581 }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { 3582 Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); 3583 }); 3584 } 3585 return e; 3586 } 3587 function _regeneratorRuntime() { 3588 "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ 3589 _regeneratorRuntime = function () { 3590 return e; 3591 }; 3592 var t, 3593 e = {}, 3594 r = Object.prototype, 3595 n = r.hasOwnProperty, 3596 o = Object.defineProperty || function (t, e, r) { 3597 t[e] = r.value; 3598 }, 3599 i = "function" == typeof Symbol ? Symbol : {}, 3600 a = i.iterator || "@@iterator", 3601 c = i.asyncIterator || "@@asyncIterator", 3602 u = i.toStringTag || "@@toStringTag"; 3603 function define(t, e, r) { 3604 return Object.defineProperty(t, e, { 3605 value: r, 3606 enumerable: !0, 3607 configurable: !0, 3608 writable: !0 3609 }), t[e]; 3610 } 3611 try { 3612 define({}, ""); 3613 } catch (t) { 3614 define = function (t, e, r) { 3615 return t[e] = r; 3616 }; 3617 } 3618 function wrap(t, e, r, n) { 3619 var i = e && e.prototype instanceof Generator ? e : Generator, 3620 a = Object.create(i.prototype), 3621 c = new Context(n || []); 3622 return o(a, "_invoke", { 3623 value: makeInvokeMethod(t, r, c) 3624 }), a; 3625 } 3626 function tryCatch(t, e, r) { 3627 try { 3628 return { 3629 type: "normal", 3630 arg: t.call(e, r) 3631 }; 3632 } catch (t) { 3633 return { 3634 type: "throw", 3635 arg: t 3636 }; 3637 } 3638 } 3639 e.wrap = wrap; 3640 var h = "suspendedStart", 3641 l = "suspendedYield", 3642 f = "executing", 3643 s = "completed", 3644 y = {}; 3645 function Generator() {} 3646 function GeneratorFunction() {} 3647 function GeneratorFunctionPrototype() {} 3648 var p = {}; 3649 define(p, a, function () { 3650 return this; 3651 }); 3652 var d = Object.getPrototypeOf, 3653 v = d && d(d(values([]))); 3654 v && v !== r && n.call(v, a) && (p = v); 3655 var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); 3656 function defineIteratorMethods(t) { 3657 ["next", "throw", "return"].forEach(function (e) { 3658 define(t, e, function (t) { 3659 return this._invoke(e, t); 3660 }); 3661 }); 3662 } 3663 function AsyncIterator(t, e) { 3664 function invoke(r, o, i, a) { 3665 var c = tryCatch(t[r], t, o); 3666 if ("throw" !== c.type) { 3667 var u = c.arg, 3668 h = u.value; 3669 return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { 3670 invoke("next", t, i, a); 3671 }, function (t) { 3672 invoke("throw", t, i, a); 3673 }) : e.resolve(h).then(function (t) { 3674 u.value = t, i(u); 3675 }, function (t) { 3676 return invoke("throw", t, i, a); 3677 }); 3678 } 3679 a(c.arg); 3680 } 3681 var r; 3682 o(this, "_invoke", { 3683 value: function (t, n) { 3684 function callInvokeWithMethodAndArg() { 3685 return new e(function (e, r) { 3686 invoke(t, n, e, r); 3687 }); 3688 } 3689 return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); 3690 } 3691 }); 3692 } 3693 function makeInvokeMethod(e, r, n) { 3694 var o = h; 3695 return function (i, a) { 3696 if (o === f) throw new Error("Generator is already running"); 3697 if (o === s) { 3698 if ("throw" === i) throw a; 3699 return { 3700 value: t, 3701 done: !0 3702 }; 3703 } 3704 for (n.method = i, n.arg = a;;) { 3705 var c = n.delegate; 3706 if (c) { 3707 var u = maybeInvokeDelegate(c, n); 3708 if (u) { 3709 if (u === y) continue; 3710 return u; 3711 } 3712 } 3713 if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { 3714 if (o === h) throw o = s, n.arg; 3715 n.dispatchException(n.arg); 3716 } else "return" === n.method && n.abrupt("return", n.arg); 3717 o = f; 3718 var p = tryCatch(e, r, n); 3719 if ("normal" === p.type) { 3720 if (o = n.done ? s : l, p.arg === y) continue; 3721 return { 3722 value: p.arg, 3723 done: n.done 3724 }; 3725 } 3726 "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); 3727 } 3728 }; 3729 } 3730 function maybeInvokeDelegate(e, r) { 3731 var n = r.method, 3732 o = e.iterator[n]; 3733 if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; 3734 var i = tryCatch(o, e.iterator, r.arg); 3735 if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; 3736 var a = i.arg; 3737 return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); 3738 } 3739 function pushTryEntry(t) { 3740 var e = { 3741 tryLoc: t[0] 3742 }; 3743 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); 3744 } 3745 function resetTryEntry(t) { 3746 var e = t.completion || {}; 3747 e.type = "normal", delete e.arg, t.completion = e; 3748 } 3749 function Context(t) { 3750 this.tryEntries = [{ 3751 tryLoc: "root" 3752 }], t.forEach(pushTryEntry, this), this.reset(!0); 3753 } 3754 function values(e) { 3755 if (e || "" === e) { 3756 var r = e[a]; 3757 if (r) return r.call(e); 3758 if ("function" == typeof e.next) return e; 3759 if (!isNaN(e.length)) { 3760 var o = -1, 3761 i = function next() { 3762 for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; 3763 return next.value = t, next.done = !0, next; 3764 }; 3765 return i.next = i; 3766 } 3767 } 3768 throw new TypeError(typeof e + " is not iterable"); 3769 } 3770 return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { 3771 value: GeneratorFunctionPrototype, 3772 configurable: !0 3773 }), o(GeneratorFunctionPrototype, "constructor", { 3774 value: GeneratorFunction, 3775 configurable: !0 3776 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { 3777 var e = "function" == typeof t && t.constructor; 3778 return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); 3779 }, e.mark = function (t) { 3780 return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; 3781 }, e.awrap = function (t) { 3782 return { 3783 __await: t 3784 }; 3785 }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { 3786 return this; 3787 }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { 3788 void 0 === i && (i = Promise); 3789 var a = new AsyncIterator(wrap(t, r, n, o), i); 3790 return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { 3791 return t.done ? t.value : a.next(); 3792 }); 3793 }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { 3794 return this; 3795 }), define(g, "toString", function () { 3796 return "[object Generator]"; 3797 }), e.keys = function (t) { 3798 var e = Object(t), 3799 r = []; 3800 for (var n in e) r.push(n); 3801 return r.reverse(), function next() { 3802 for (; r.length;) { 3803 var t = r.pop(); 3804 if (t in e) return next.value = t, next.done = !1, next; 3805 } 3806 return next.done = !0, next; 3807 }; 3808 }, e.values = values, Context.prototype = { 3809 constructor: Context, 3810 reset: function (e) { 3811 if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); 3812 }, 3813 stop: function () { 3814 this.done = !0; 3815 var t = this.tryEntries[0].completion; 3816 if ("throw" === t.type) throw t.arg; 3817 return this.rval; 3818 }, 3819 dispatchException: function (e) { 3820 if (this.done) throw e; 3821 var r = this; 3822 function handle(n, o) { 3823 return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; 3824 } 3825 for (var o = this.tryEntries.length - 1; o >= 0; --o) { 3826 var i = this.tryEntries[o], 3827 a = i.completion; 3828 if ("root" === i.tryLoc) return handle("end"); 3829 if (i.tryLoc <= this.prev) { 3830 var c = n.call(i, "catchLoc"), 3831 u = n.call(i, "finallyLoc"); 3832 if (c && u) { 3833 if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); 3834 if (this.prev < i.finallyLoc) return handle(i.finallyLoc); 3835 } else if (c) { 3836 if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); 3837 } else { 3838 if (!u) throw new Error("try statement without catch or finally"); 3839 if (this.prev < i.finallyLoc) return handle(i.finallyLoc); 3840 } 3841 } 3842 } 3843 }, 3844 abrupt: function (t, e) { 3845 for (var r = this.tryEntries.length - 1; r >= 0; --r) { 3846 var o = this.tryEntries[r]; 3847 if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { 3848 var i = o; 3849 break; 3850 } 3851 } 3852 i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); 3853 var a = i ? i.completion : {}; 3854 return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); 3855 }, 3856 complete: function (t, e) { 3857 if ("throw" === t.type) throw t.arg; 3858 return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; 3859 }, 3860 finish: function (t) { 3861 for (var e = this.tryEntries.length - 1; e >= 0; --e) { 3862 var r = this.tryEntries[e]; 3863 if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; 3864 } 3865 }, 3866 catch: function (t) { 3867 for (var e = this.tryEntries.length - 1; e >= 0; --e) { 3868 var r = this.tryEntries[e]; 3869 if (r.tryLoc === t) { 3870 var n = r.completion; 3871 if ("throw" === n.type) { 3872 var o = n.arg; 3873 resetTryEntry(r); 3874 } 3875 return o; 3876 } 3877 } 3878 throw new Error("illegal catch attempt"); 3879 }, 3880 delegateYield: function (e, r, n) { 3881 return this.delegate = { 3882 iterator: values(e), 3883 resultName: r, 3884 nextLoc: n 3885 }, "next" === this.method && (this.arg = t), y; 3886 } 3887 }, e; 3888 } 3889 function _typeof(o) { 3890 "@babel/helpers - typeof"; 3891 3892 return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { 3893 return typeof o; 3894 } : function (o) { 3895 return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; 3896 }, _typeof(o); 3897 } 3898 function _using(o, e, n) { 3899 if (null == e) return e; 3900 if ("object" != typeof e) throw new TypeError("using declarations can only be used with objects, null, or undefined."); 3901 if (n) var r = e[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")]; 3902 if (null == r && (r = e[Symbol.dispose || Symbol.for("Symbol.dispose")]), "function" != typeof r) throw new TypeError("Property [Symbol.dispose] is not a function."); 3903 return o.push({ 3904 v: e, 3905 d: r, 3906 a: n 3907 }), e; 3908 } 3909 function _wrapRegExp() { 3910 _wrapRegExp = function (e, r) { 3911 return new BabelRegExp(e, void 0, r); 3912 }; 3913 var e = RegExp.prototype, 3914 r = new WeakMap(); 3915 function BabelRegExp(e, t, p) { 3916 var o = new RegExp(e, t); 3917 return r.set(o, p || r.get(e)), _setPrototypeOf(o, BabelRegExp.prototype); 3918 } 3919 function buildGroups(e, t) { 3920 var p = r.get(t); 3921 return Object.keys(p).reduce(function (r, t) { 3922 var o = p[t]; 3923 if ("number" == typeof o) r[t] = e[o];else { 3924 for (var i = 0; void 0 === e[o[i]] && i + 1 < o.length;) i++; 3925 r[t] = e[o[i]]; 3926 } 3927 return r; 3928 }, Object.create(null)); 3929 } 3930 return _inherits(BabelRegExp, RegExp), BabelRegExp.prototype.exec = function (r) { 3931 var t = e.exec.call(this, r); 3932 if (t) { 3933 t.groups = buildGroups(t, this); 3934 var p = t.indices; 3935 p && (p.groups = buildGroups(p, this)); 3936 } 3937 return t; 3938 }, BabelRegExp.prototype[Symbol.replace] = function (t, p) { 3939 if ("string" == typeof p) { 3940 var o = r.get(this); 3941 return e[Symbol.replace].call(this, t, p.replace(/\$<([^>]+)>/g, function (e, r) { 3942 var t = o[r]; 3943 return "$" + (Array.isArray(t) ? t.join("$") : t); 3944 })); 3945 } 3946 if ("function" == typeof p) { 3947 var i = this; 3948 return e[Symbol.replace].call(this, t, function () { 3949 var e = arguments; 3950 return "object" != typeof e[e.length - 1] && (e = [].slice.call(e)).push(buildGroups(e, i)), p.apply(this, e); 3951 }); 3952 } 3953 return e[Symbol.replace].call(this, t, p); 3954 }, _wrapRegExp.apply(this, arguments); 3955 } 3956 function _AwaitValue(value) { 3957 this.wrapped = value; 3958 } 3959 function _wrapAsyncGenerator(fn) { 3960 return function () { 3961 return new _AsyncGenerator(fn.apply(this, arguments)); 3962 }; 3963 } 3964 function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { 3965 try { 3966 var info = gen[key](arg); 3967 var value = info.value; 3968 } catch (error) { 3969 reject(error); 3970 return; 3971 } 3972 if (info.done) { 3973 resolve(value); 3974 } else { 3975 Promise.resolve(value).then(_next, _throw); 3976 } 3977 } 3978 function _asyncToGenerator(fn) { 3979 return function () { 3980 var self = this, 3981 args = arguments; 3982 return new Promise(function (resolve, reject) { 3983 var gen = fn.apply(self, args); 3984 function _next(value) { 3985 asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); 3986 } 3987 function _throw(err) { 3988 asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); 3989 } 3990 _next(undefined); 3991 }); 3992 }; 3993 } 3994 function _classCallCheck(instance, Constructor) { 3995 if (!(instance instanceof Constructor)) { 3996 throw new TypeError("Cannot call a class as a function"); 3997 } 3998 } 3999 function _defineProperties(target, props) { 4000 for (var i = 0; i < props.length; i++) { 4001 var descriptor = props[i]; 4002 descriptor.enumerable = descriptor.enumerable || false; 4003 descriptor.configurable = true; 4004 if ("value" in descriptor) descriptor.writable = true; 4005 Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); 4006 } 4007 } 4008 function _createClass(Constructor, protoProps, staticProps) { 4009 if (protoProps) _defineProperties(Constructor.prototype, protoProps); 4010 if (staticProps) _defineProperties(Constructor, staticProps);
vendor: 5,042 bytes, lines 4011-4158
4011 Object.defineProperty(Constructor, "prototype", { 4012 writable: false 4013 }); 4014 return Constructor; 4015 } 4016 function _defineEnumerableProperties(obj, descs) { 4017 for (var key in descs) { 4018 var desc = descs[key]; 4019 desc.configurable = desc.enumerable = true; 4020 if ("value" in desc) desc.writable = true; 4021 Object.defineProperty(obj, key, desc); 4022 } 4023 if (Object.getOwnPropertySymbols) { 4024 var objectSymbols = Object.getOwnPropertySymbols(descs); 4025 for (var i = 0; i < objectSymbols.length; i++) { 4026 var sym = objectSymbols[i]; 4027 var desc = descs[sym]; 4028 desc.configurable = desc.enumerable = true; 4029 if ("value" in desc) desc.writable = true; 4030 Object.defineProperty(obj, sym, desc); 4031 } 4032 } 4033 return obj; 4034 } 4035 function _defaults(obj, defaults) { 4036 var keys = Object.getOwnPropertyNames(defaults); 4037 for (var i = 0; i < keys.length; i++) { 4038 var key = keys[i]; 4039 var value = Object.getOwnPropertyDescriptor(defaults, key); 4040 if (value && value.configurable && obj[key] === undefined) { 4041 Object.defineProperty(obj, key, value); 4042 } 4043 } 4044 return obj; 4045 } 4046 function _defineProperty(obj, key, value) { 4047 key = _toPropertyKey(key); 4048 if (key in obj) { 4049 Object.defineProperty(obj, key, { 4050 value: value, 4051 enumerable: true, 4052 configurable: true, 4053 writable: true 4054 }); 4055 } else { 4056 obj[key] = value; 4057 } 4058 return obj; 4059 } 4060 function _extends() { 4061 _extends = Object.assign ? Object.assign.bind() : function (target) { 4062 for (var i = 1; i < arguments.length; i++) { 4063 var source = arguments[i]; 4064 for (var key in source) { 4065 if (Object.prototype.hasOwnProperty.call(source, key)) { 4066 target[key] = source[key]; 4067 } 4068 } 4069 } 4070 return target; 4071 }; 4072 return _extends.apply(this, arguments); 4073 } 4074 function _objectSpread(target) { 4075 for (var i = 1; i < arguments.length; i++) { 4076 var source = arguments[i] != null ? Object(arguments[i]) : {}; 4077 var ownKeys = Object.keys(source); 4078 if (typeof Object.getOwnPropertySymbols === 'function') { 4079 ownKeys.push.apply(ownKeys, Object.getOwnPropertySymbols(source).filter(function (sym) { 4080 return Object.getOwnPropertyDescriptor(source, sym).enumerable; 4081 })); 4082 } 4083 ownKeys.forEach(function (key) { 4084 _defineProperty(target, key, source[key]); 4085 }); 4086 } 4087 return target; 4088 } 4089 function _inherits(subClass, superClass) { 4090 if (typeof superClass !== "function" && superClass !== null) { 4091 throw new TypeError("Super expression must either be null or a function"); 4092 } 4093 subClass.prototype = Object.create(superClass && superClass.prototype, { 4094 constructor: { 4095 value: subClass, 4096 writable: true, 4097 configurable: true 4098 } 4099 }); 4100 Object.defineProperty(subClass, "prototype", { 4101 writable: false 4102 }); 4103 if (superClass) _setPrototypeOf(subClass, superClass); 4104 } 4105 function _inheritsLoose(subClass, superClass) { 4106 subClass.prototype = Object.create(superClass.prototype); 4107 subClass.prototype.constructor = subClass; 4108 _setPrototypeOf(subClass, superClass); 4109 } 4110 function _getPrototypeOf(o) { 4111 _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { 4112 return o.__proto__ || Object.getPrototypeOf(o); 4113 }; 4114 return _getPrototypeOf(o); 4115 } 4116 function _setPrototypeOf(o, p) { 4117 _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { 4118 o.__proto__ = p; 4119 return o; 4120 }; 4121 return _setPrototypeOf(o, p); 4122 } 4123 function _isNativeReflectConstruct() { 4124 if (typeof Reflect === "undefined" || !Reflect.construct) return false; 4125 if (Reflect.construct.sham) return false; 4126 if (typeof Proxy === "function") return true; 4127 try { 4128 Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); 4129 return true; 4130 } catch (e) { 4131 return false; 4132 } 4133 } 4134 function _construct(Parent, args, Class) { 4135 if (_isNativeReflectConstruct()) { 4136 _construct = Reflect.construct.bind(); 4137 } else { 4138 _construct = function _construct(Parent, args, Class) { 4139 var a = [null]; 4140 a.push.apply(a, args); 4141 var Constructor = Function.bind.apply(Parent, a); 4142 var instance = new Constructor(); 4143 if (Class) _setPrototypeOf(instance, Class.prototype); 4144 return instance; 4145 }; 4146 } 4147 return _construct.apply(null, arguments); 4148 } 4149 function _isNativeFunction(fn) { 4150 return Function.toString.call(fn).indexOf("[native code]") !== -1; 4151 } 4152 function _wrapNativeSuper(Class) { 4153 var _cache = typeof Map === "function" ? new Map() : undefined; 4154 _wrapNativeSuper = function _wrapNativeSuper(Class) { 4155 if (Class === null || !_isNativeFunction(Class)) return Class; 4156 if (typeof Class !== "function") { 4157 throw new TypeError("Super expression must either be null or a function"); 4158 }
4159 if (typeof _cache !== "undefined") { 4160 if (_cache.has(Class)) return _cache.get(Class); 4161 _cache.set(Class, Wrapper); 4162 } 4163 function Wrapper() { 4164 return _construct(Class, arguments, _getPrototypeOf(this).constructor); 4165 } 4166 Wrapper.prototype = Object.create(Class.prototype, { 4167 constructor: { 4168 value: Wrapper, 4169 enumerable: false, 4170 writable: true, 4171 configurable: true 4172 } 4173 }); 4174 return _setPrototypeOf(Wrapper, Class); 4175 }; 4176 return _wrapNativeSuper(Class); 4177 } 4178 function _instanceof(left, right) { 4179 if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { 4180 return !!right[Symbol.hasInstance](left); 4181 } else { 4182 return left instanceof right; 4183 } 4184 } 4185 function _interopRequireDefault(obj) { 4186 return obj && obj.__esModule ? obj : { 4187 default: obj 4188 }; 4189 } 4190 function _getRequireWildcardCache(nodeInterop) { 4191 if (typeof WeakMap !== "function") return null; 4192 var cacheBabelInterop = new WeakMap(); 4193 var cacheNodeInterop = new WeakMap(); 4194 return (_getRequireWildcardCache = function (nodeInterop) { 4195 return nodeInterop ? cacheNodeInterop : cacheBabelInterop; 4196 })(nodeInterop); 4197 } 4198 function _interopRequireWildcard(obj, nodeInterop) { 4199 if (!nodeInterop && obj && obj.__esModule) { 4200 return obj; 4201 } 4202 if (obj === null || typeof obj !== "object" && typeof obj !== "function") { 4203 return { 4204 default: obj 4205 }; 4206 } 4207 var cache = _getRequireWildcardCache(nodeInterop); 4208 if (cache && cache.has(obj)) { 4209 return cache.get(obj); 4210 } 4211 var newObj = {}; 4212 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; 4213 for (var key in obj) { 4214 if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { 4215 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; 4216 if (desc && (desc.get || desc.set)) { 4217 Object.defineProperty(newObj, key, desc); 4218 } else { 4219 newObj[key] = obj[key]; 4220 } 4221 } 4222 } 4223 newObj.default = obj; 4224 if (cache) { 4225 cache.set(obj, newObj); 4226 } 4227 return newObj; 4228 } 4229 function _newArrowCheck(innerThis, boundThis) { 4230 if (innerThis !== boundThis) { 4231 throw new TypeError("Cannot instantiate an arrow function"); 4232 } 4233 } 4234 function _objectDestructuringEmpty(obj) { 4235 if (obj == null) throw new TypeError("Cannot destructure " + obj); 4236 } 4237 function _objectWithoutPropertiesLoose(source, excluded) { 4238 if (source == null) return {}; 4239 var target = {}; 4240 var sourceKeys = Object.keys(source); 4241 var key, i; 4242 for (i = 0; i < sourceKeys.length; i++) { 4243 key = sourceKeys[i]; 4244 if (excluded.indexOf(key) >= 0) continue; 4245 target[key] = source[key]; 4246 } 4247 return target; 4248 } 4249 function _objectWithoutProperties(source, excluded) { 4250 if (source == null) return {}; 4251 var target = _objectWithoutPropertiesLoose(source, excluded); 4252 var key, i; 4253 if (Object.getOwnPropertySymbols) { 4254 var sourceSymbolKeys = Object.getOwnPropertySymbols(source); 4255 for (i = 0; i < sourceSymbolKeys.length; i++) { 4256 key = sourceSymbolKeys[i]; 4257 if (excluded.indexOf(key) >= 0) continue; 4258 if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; 4259 target[key] = source[key]; 4260 } 4261 } 4262 return target; 4263 } 4264 function _assertThisInitialized(self) { 4265 if (self === void 0) { 4266 throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); 4267 } 4268 return self; 4269 } 4270 function _possibleConstructorReturn(self, call) { 4271 if (call && (typeof call === "object" || typeof call === "function")) { 4272 return call; 4273 } else if (call !== void 0) { 4274 throw new TypeError("Derived constructors may only return object or undefined"); 4275 } 4276 return _assertThisInitialized(self); 4277 } 4278 function _createSuper(Derived) { 4279 var hasNativeReflectConstruct = _isNativeReflectConstruct(); 4280 return function _createSuperInternal() { 4281 var Super = _getPrototypeOf(Derived), 4282 result; 4283 if (hasNativeReflectConstruct) { 4284 var NewTarget = _getPrototypeOf(this).constructor; 4285 result = Reflect.construct(Super, arguments, NewTarget); 4286 } else { 4287 result = Super.apply(this, arguments); 4288 } 4289 return _possibleConstructorReturn(this, result); 4290 }; 4291 } 4292 function _superPropBase(object, property) { 4293 while (!Object.prototype.hasOwnProperty.call(object, property)) { 4294 object = _getPrototypeOf(object); 4295 if (object === null) break; 4296 } 4297 return object; 4298 } 4299 function _get() { 4300 if (typeof Reflect !== "undefined" && Reflect.get) { 4301 _get = Reflect.get.bind(); 4302 } else { 4303 _get = function _get(target, property, receiver) { 4304 var base = _superPropBase(target, property); 4305 if (!base) return; 4306 var desc = Object.getOwnPropertyDescriptor(base, property); 4307 if (desc.get) { 4308 return desc.get.call(arguments.length < 3 ? target : receiver); 4309 } 4310 return desc.value; 4311 }; 4312 } 4313 return _get.apply(this, arguments); 4314 } 4315 function set(target, property, value, receiver) { 4316 if (typeof Reflect !== "undefined" && Reflect.set) { 4317 set = Reflect.set; 4318 } else { 4319 set = function set(target, property, value, receiver) { 4320 var base = _superPropBase(target, property); 4321 var desc; 4322 if (base) { 4323 desc = Object.getOwnPropertyDescriptor(base, property); 4324 if (desc.set) { 4325 desc.set.call(receiver, value); 4326 return true; 4327 } else if (!desc.writable) { 4328 return false;
vendor: 6,730 bytes, lines 4329-4521
4329 } 4330 } 4331 desc = Object.getOwnPropertyDescriptor(receiver, property); 4332 if (desc) { 4333 if (!desc.writable) { 4334 return false; 4335 } 4336 desc.value = value; 4337 Object.defineProperty(receiver, property, desc); 4338 } else { 4339 _defineProperty(receiver, property, value); 4340 } 4341 return true; 4342 }; 4343 } 4344 return set(target, property, value, receiver); 4345 } 4346 function _set(target, property, value, receiver, isStrict) { 4347 var s = set(target, property, value, receiver || target); 4348 if (!s && isStrict) { 4349 throw new TypeError('failed to set property'); 4350 } 4351 return value; 4352 } 4353 function _taggedTemplateLiteral(strings, raw) { 4354 if (!raw) { 4355 raw = strings.slice(0); 4356 } 4357 return Object.freeze(Object.defineProperties(strings, { 4358 raw: { 4359 value: Object.freeze(raw) 4360 } 4361 })); 4362 } 4363 function _taggedTemplateLiteralLoose(strings, raw) { 4364 if (!raw) { 4365 raw = strings.slice(0); 4366 } 4367 strings.raw = raw; 4368 return strings; 4369 } 4370 function _readOnlyError(name) { 4371 throw new TypeError("\"" + name + "\" is read-only"); 4372 } 4373 function _writeOnlyError(name) { 4374 throw new TypeError("\"" + name + "\" is write-only"); 4375 } 4376 function _classNameTDZError(name) { 4377 throw new ReferenceError("Class \"" + name + "\" cannot be referenced in computed property keys."); 4378 } 4379 function _temporalUndefined() {} 4380 function _tdz(name) { 4381 throw new ReferenceError(name + " is not defined - temporal dead zone"); 4382 } 4383 function _temporalRef(val, name) { 4384 return val === _temporalUndefined ? _tdz(name) : val; 4385 } 4386 function _slicedToArray(arr, i) { 4387 return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); 4388 } 4389 function _slicedToArrayLoose(arr, i) { 4390 return _arrayWithHoles(arr) || _iterableToArrayLimitLoose(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); 4391 } 4392 function _toArray(arr) { 4393 return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); 4394 } 4395 function _toConsumableArray(arr) { 4396 return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); 4397 } 4398 function _arrayWithoutHoles(arr) { 4399 if (Array.isArray(arr)) return _arrayLikeToArray(arr); 4400 } 4401 function _arrayWithHoles(arr) { 4402 if (Array.isArray(arr)) return arr; 4403 } 4404 function _maybeArrayLike(next, arr, i) { 4405 if (arr && !Array.isArray(arr) && typeof arr.length === "number") { 4406 var len = arr.length; 4407 return _arrayLikeToArray(arr, i !== void 0 && i < len ? i : len); 4408 } 4409 return next(arr, i); 4410 } 4411 function _iterableToArray(iter) { 4412 if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); 4413 } 4414 function _unsupportedIterableToArray(o, minLen) { 4415 if (!o) return; 4416 if (typeof o === "string") return _arrayLikeToArray(o, minLen); 4417 var n = Object.prototype.toString.call(o).slice(8, -1); 4418 if (n === "Object" && o.constructor) n = o.constructor.name; 4419 if (n === "Map" || n === "Set") return Array.from(o); 4420 if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); 4421 } 4422 function _arrayLikeToArray(arr, len) { 4423 if (len == null || len > arr.length) len = arr.length; 4424 for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; 4425 return arr2; 4426 } 4427 function _nonIterableSpread() { 4428 throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); 4429 } 4430 function _nonIterableRest() { 4431 throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); 4432 } 4433 function _createForOfIteratorHelper(o, allowArrayLike) { 4434 var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; 4435 if (!it) { 4436 if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { 4437 if (it) o = it; 4438 var i = 0; 4439 var F = function () {}; 4440 return { 4441 s: F, 4442 n: function () { 4443 if (i >= o.length) return { 4444 done: true 4445 }; 4446 return { 4447 done: false, 4448 value: o[i++] 4449 }; 4450 }, 4451 e: function (e) { 4452 throw e; 4453 }, 4454 f: F 4455 }; 4456 } 4457 throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); 4458 } 4459 var normalCompletion = true, 4460 didErr = false, 4461 err; 4462 return { 4463 s: function () { 4464 it = it.call(o); 4465 }, 4466 n: function () { 4467 var step = it.next(); 4468 normalCompletion = step.done; 4469 return step; 4470 }, 4471 e: function (e) { 4472 didErr = true; 4473 err = e; 4474 }, 4475 f: function () { 4476 try { 4477 if (!normalCompletion && it.return != null) it.return(); 4478 } finally { 4479 if (didErr) throw err; 4480 } 4481 } 4482 }; 4483 } 4484 function _createForOfIteratorHelperLoose(o, allowArrayLike) { 4485 var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; 4486 if (it) return (it = it.call(o)).next.bind(it); 4487 if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { 4488 if (it) o = it; 4489 var i = 0; 4490 return function () { 4491 if (i >= o.length) return { 4492 done: true 4493 }; 4494 return { 4495 done: false, 4496 value: o[i++] 4497 }; 4498 }; 4499 } 4500 throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); 4501 } 4502 function _skipFirstGeneratorNext(fn) { 4503 return function () { 4504 var it = fn.apply(this, arguments); 4505 it.next(); 4506 return it; 4507 }; 4508 } 4509 function _toPrimitive(input, hint) { 4510 if (typeof input !== "object" || input === null) return input; 4511 var prim = input[Symbol.toPrimitive]; 4512 if (prim !== undefined) { 4513 var res = prim.call(input, hint || "default"); 4514 if (typeof res !== "object") return res; 4515 throw new TypeError("@@toPrimitive must return a primitive value."); 4516 } 4517 return (hint === "string" ? String : Number)(input); 4518 } 4519 function _toPropertyKey(arg) { 4520 var key = _toPrimitive(arg, "string"); 4521 return typeof key === "symbol" ? key : String(key)
vendor: 23,419 bytes, lines 4521-5154
4521; 4522 } 4523 function _initializerWarningHelper(descriptor, context) { 4524 throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); 4525 } 4526 function _initializerDefineProperty(target, property, descriptor, context) { 4527 if (!descriptor) return; 4528 Object.defineProperty(target, property, { 4529 enumerable: descriptor.enumerable, 4530 configurable: descriptor.configurable, 4531 writable: descriptor.writable, 4532 value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 4533 }); 4534 } 4535 function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { 4536 var desc = {}; 4537 Object.keys(descriptor).forEach(function (key) { 4538 desc[key] = descriptor[key]; 4539 }); 4540 desc.enumerable = !!desc.enumerable; 4541 desc.configurable = !!desc.configurable; 4542 if ('value' in desc || desc.initializer) { 4543 desc.writable = true; 4544 } 4545 desc = decorators.slice().reverse().reduce(function (desc, decorator) { 4546 return decorator(target, property, desc) || desc; 4547 }, desc); 4548 if (context && desc.initializer !== void 0) { 4549 desc.value = desc.initializer ? desc.initializer.call(context) : void 0; 4550 desc.initializer = undefined; 4551 } 4552 if (desc.initializer === void 0) { 4553 Object.defineProperty(target, property, desc); 4554 desc = null; 4555 } 4556 return desc; 4557 } 4558 var id$1 = 0; 4559 function _classPrivateFieldLooseKey(name) { 4560 return "__private_" + id$1++ + "_" + name; 4561 } 4562 function _classPrivateFieldLooseBase(receiver, privateKey) { 4563 if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { 4564 throw new TypeError("attempted to use private field on non-instance"); 4565 } 4566 return receiver; 4567 } 4568 function _classPrivateFieldGet(receiver, privateMap) { 4569 var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); 4570 return _classApplyDescriptorGet(receiver, descriptor); 4571 } 4572 function _classPrivateFieldSet(receiver, privateMap, value) { 4573 var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); 4574 _classApplyDescriptorSet(receiver, descriptor, value); 4575 return value; 4576 } 4577 function _classPrivateFieldDestructureSet(receiver, privateMap) { 4578 var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); 4579 return _classApplyDescriptorDestructureSet(receiver, descriptor); 4580 } 4581 function _classExtractFieldDescriptor(receiver, privateMap, action) { 4582 if (!privateMap.has(receiver)) { 4583 throw new TypeError("attempted to " + action + " private field on non-instance"); 4584 } 4585 return privateMap.get(receiver); 4586 } 4587 function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { 4588 _classCheckPrivateStaticAccess(receiver, classConstructor); 4589 _classCheckPrivateStaticFieldDescriptor(descriptor, "get"); 4590 return _classApplyDescriptorGet(receiver, descriptor); 4591 } 4592 function _classStaticPrivateFieldSpecSet(receiver, classConstructor, descriptor, value) { 4593 _classCheckPrivateStaticAccess(receiver, classConstructor); 4594 _classCheckPrivateStaticFieldDescriptor(descriptor, "set"); 4595 _classApplyDescriptorSet(receiver, descriptor, value); 4596 return value; 4597 } 4598 function _classStaticPrivateMethodGet(receiver, classConstructor, method) { 4599 _classCheckPrivateStaticAccess(receiver, classConstructor); 4600 return method; 4601 } 4602 function _classStaticPrivateMethodSet() { 4603 throw new TypeError("attempted to set read only static private field"); 4604 } 4605 function _classApplyDescriptorGet(receiver, descriptor) { 4606 if (descriptor.get) { 4607 return descriptor.get.call(receiver); 4608 } 4609 return descriptor.value; 4610 } 4611 function _classApplyDescriptorSet(receiver, descriptor, value) { 4612 if (descriptor.set) { 4613 descriptor.set.call(receiver, value); 4614 } else { 4615 if (!descriptor.writable) { 4616 throw new TypeError("attempted to set read only private field"); 4617 } 4618 descriptor.value = value; 4619 } 4620 } 4621 function _classApplyDescriptorDestructureSet(receiver, descriptor) { 4622 if (descriptor.set) { 4623 if (!("__destrObj" in descriptor)) { 4624 descriptor.__destrObj = { 4625 set value(v) { 4626 descriptor.set.call(receiver, v); 4627 } 4628 }; 4629 } 4630 return descriptor.__destrObj; 4631 } else { 4632 if (!descriptor.writable) { 4633 throw new TypeError("attempted to set read only private field"); 4634 } 4635 return descriptor; 4636 } 4637 } 4638 function _classStaticPrivateFieldDestructureSet(receiver, classConstructor, descriptor) { 4639 _classCheckPrivateStaticAccess(receiver, classConstructor); 4640 _classCheckPrivateStaticFieldDescriptor(descriptor, "set"); 4641 return _classApplyDescriptorDestructureSet(receiver, descriptor); 4642 } 4643 function _classCheckPrivateStaticAccess(receiver, classConstructor) { 4644 if (receiver !== classConstructor) { 4645 throw new TypeError("Private static access of wrong provenance"); 4646 } 4647 } 4648 function _classCheckPrivateStaticFieldDescriptor(descriptor, action) { 4649 if (descriptor === undefined) { 4650 throw new TypeError("attempted to " + action + " private static field before its declaration"); 4651 } 4652 } 4653 function _decorate(decorators, factory, superClass, mixins) { 4654 var api = _getDecoratorsApi(); 4655 if (mixins) { 4656 for (var i = 0; i < mixins.length; i++) { 4657 api = mixins[i](api); 4658 } 4659 } 4660 var r = factory(function initialize(O) { 4661 api.initializeInstanceElements(O, decorated.elements); 4662 }, superClass); 4663 var decorated = api.decorateClass(_coalesceClassElements(r.d.map(_createElementDescriptor)), decorators); 4664 api.initializeClassElements(r.F, decorated.elements); 4665 return api.runClassFinishers(r.F, decorated.finishers); 4666 } 4667 function _getDecoratorsApi() { 4668 _getDecoratorsApi = function () { 4669 return api; 4670 }; 4671 var api = { 4672 elementsDefinitionOrder: [["method"], ["field"]], 4673 initializeInstanceElements: function (O, elements) { 4674 ["method", "field"].forEach(function (kind) { 4675 elements.forEach(function (element) { 4676 if (element.kind === kind && element.placement === "own") { 4677 this.defineClassElement(O, element); 4678 } 4679 }, this); 4680 }, this); 4681 }, 4682 initializeClassElements: function (F, elements) { 4683 var proto = F.prototype; 4684 ["method", "field"].forEach(function (kind) { 4685 elements.forEach(function (element) { 4686 var placement = element.placement; 4687 if (element.kind === kind && (placement === "static" || placement === "prototype")) { 4688 var receiver = placement === "static" ? F : proto; 4689 this.defineClassElement(receiver, element); 4690 } 4691 }, this); 4692 }, this); 4693 }, 4694 defineClassElement: function (receiver, element) { 4695 var descriptor = element.descriptor; 4696 if (element.kind === "field") { 4697 var initializer = element.initializer; 4698 descriptor = { 4699 enumerable: descriptor.enumerable, 4700 writable: descriptor.writable, 4701 configurable: descriptor.configurable, 4702 value: initializer === void 0 ? void 0 : initializer.call(receiver) 4703 }; 4704 } 4705 Object.defineProperty(receiver, element.key, descriptor); 4706 }, 4707 decorateClass: function (elements, decorators) { 4708 var newElements = []; 4709 var finishers = []; 4710 var placements = { 4711 static: [], 4712 prototype: [], 4713 own: [] 4714 }; 4715 elements.forEach(function (element) { 4716 this.addElementPlacement(element, placements); 4717 }, this); 4718 elements.forEach(function (element) { 4719 if (!_hasDecorators(element)) return newElements.push(element); 4720 var elementFinishersExtras = this.decorateElement(element, placements); 4721 newElements.push(elementFinishersExtras.element); 4722 newElements.push.apply(newElements, elementFinishersExtras.extras); 4723 finishers.push.apply(finishers, elementFinishersExtras.finishers); 4724 }, this); 4725 if (!decorators) { 4726 return { 4727 elements: newElements, 4728 finishers: finishers 4729 }; 4730 } 4731 var result = this.decorateConstructor(newElements, decorators); 4732 finishers.push.apply(finishers, result.finishers); 4733 result.finishers = finishers; 4734 return result; 4735 }, 4736 addElementPlacement: function (element, placements, silent) { 4737 var keys = placements[element.placement]; 4738 if (!silent && keys.indexOf(element.key) !== -1) { 4739 throw new TypeError("Duplicated element (" + element.key + ")"); 4740 } 4741 keys.push(element.key); 4742 }, 4743 decorateElement: function (element, placements) { 4744 var extras = []; 4745 var finishers = []; 4746 for (var decorators = element.decorators, i = decorators.length - 1; i >= 0; i--) { 4747 var keys = placements[element.placement]; 4748 keys.splice(keys.indexOf(element.key), 1); 4749 var elementObject = this.fromElementDescriptor(element); 4750 var elementFinisherExtras = this.toElementFinisherExtras((0, decorators[i])(elementObject) || elementObject); 4751 element = elementFinisherExtras.element; 4752 this.addElementPlacement(element, placements); 4753 if (elementFinisherExtras.finisher) { 4754 finishers.push(elementFinisherExtras.finisher); 4755 } 4756 var newExtras = elementFinisherExtras.extras; 4757 if (newExtras) { 4758 for (var j = 0; j < newExtras.length; j++) { 4759 this.addElementPlacement(newExtras[j], placements); 4760 } 4761 extras.push.apply(extras, newExtras); 4762 } 4763 } 4764 return { 4765 element: element, 4766 finishers: finishers, 4767 extras: extras 4768 }; 4769 }, 4770 decorateConstructor: function (elements, decorators) { 4771 var finishers = []; 4772 for (var i = decorators.length - 1; i >= 0; i--) { 4773 var obj = this.fromClassDescriptor(elements); 4774 var elementsAndFinisher = this.toClassDescriptor((0, decorators[i])(obj) || obj); 4775 if (elementsAndFinisher.finisher !== undefined) { 4776 finishers.push(elementsAndFinisher.finisher); 4777 } 4778 if (elementsAndFinisher.elements !== undefined) { 4779 elements = elementsAndFinisher.elements; 4780 for (var j = 0; j < elements.length - 1; j++) { 4781 for (var k = j + 1; k < elements.length; k++) { 4782 if (elements[j].key === elements[k].key && elements[j].placement === elements[k].placement) { 4783 throw new TypeError("Duplicated element (" + elements[j].key + ")"); 4784 } 4785 } 4786 } 4787 } 4788 } 4789 return { 4790 elements: elements, 4791 finishers: finishers 4792 }; 4793 }, 4794 fromElementDescriptor: function (element) { 4795 var obj = { 4796 kind: element.kind, 4797 key: element.key, 4798 placement: element.placement, 4799 descriptor: element.descriptor 4800 }; 4801 var desc = { 4802 value: "Descriptor", 4803 configurable: true 4804 }; 4805 Object.defineProperty(obj, Symbol.toStringTag, desc); 4806 if (element.kind === "field") obj.initializer = element.initializer; 4807 return obj; 4808 }, 4809 toElementDescriptors: function (elementObjects) { 4810 if (elementObjects === undefined) return; 4811 return _toArray(elementObjects).map(function (elementObject) { 4812 var element = this.toElementDescriptor(elementObject); 4813 this.disallowProperty(elementObject, "finisher", "An element descriptor"); 4814 this.disallowProperty(elementObject, "extras", "An element descriptor"); 4815 return element; 4816 }, this); 4817 }, 4818 toElementDescriptor: function (elementObject) { 4819 var kind = String(elementObject.kind); 4820 if (kind !== "method" && kind !== "field") { 4821 throw new TypeError('An element descriptor\'s .kind property must be either "method" or' + ' "field", but a decorator created an element descriptor with' + ' .kind "' + kind + '"'); 4822 } 4823 var key = _toPropertyKey(elementObject.key); 4824 var placement = String(elementObject.placement); 4825 if (placement !== "static" && placement !== "prototype" && placement !== "own") { 4826 throw new TypeError('An element descriptor\'s .placement property must be one of "static",' + ' "prototype" or "own", but a decorator created an element descriptor' + ' with .placement "' + placement + '"'); 4827 } 4828 var descriptor = elementObject.descriptor; 4829 this.disallowProperty(elementObject, "elements", "An element descriptor"); 4830 var element = { 4831 kind: kind, 4832 key: key, 4833 placement: placement, 4834 descriptor: Object.assign({}, descriptor) 4835 }; 4836 if (kind !== "field") { 4837 this.disallowProperty(elementObject, "initializer", "A method descriptor"); 4838 } else { 4839 this.disallowProperty(descriptor, "get", "The property descriptor of a field descriptor"); 4840 this.disallowProperty(descriptor, "set", "The property descriptor of a field descriptor"); 4841 this.disallowProperty(descriptor, "value", "The property descriptor of a field descriptor"); 4842 element.initializer = elementObject.initializer; 4843 } 4844 return element; 4845 }, 4846 toElementFinisherExtras: function (elementObject) { 4847 var element = this.toElementDescriptor(elementObject); 4848 var finisher = _optionalCallableProperty(elementObject, "finisher"); 4849 var extras = this.toElementDescriptors(elementObject.extras); 4850 return { 4851 element: element, 4852 finisher: finisher, 4853 extras: extras 4854 }; 4855 }, 4856 fromClassDescriptor: function (elements) { 4857 var obj = { 4858 kind: "class", 4859 elements: elements.map(this.fromElementDescriptor, this) 4860 }; 4861 var desc = { 4862 value: "Descriptor", 4863 configurable: true 4864 }; 4865 Object.defineProperty(obj, Symbol.toStringTag, desc); 4866 return obj; 4867 }, 4868 toClassDescriptor: function (obj) { 4869 var kind = String(obj.kind); 4870 if (kind !== "class") { 4871 throw new TypeError('A class descriptor\'s .kind property must be "class", but a decorator' + ' created a class descriptor with .kind "' + kind + '"'); 4872 } 4873 this.disallowProperty(obj, "key", "A class descriptor"); 4874 this.disallowProperty(obj, "placement", "A class descriptor"); 4875 this.disallowProperty(obj, "descriptor", "A class descriptor"); 4876 this.disallowProperty(obj, "initializer", "A class descriptor"); 4877 this.disallowProperty(obj, "extras", "A class descriptor"); 4878 var finisher = _optionalCallableProperty(obj, "finisher"); 4879 var elements = this.toElementDescriptors(obj.elements); 4880 return { 4881 elements: elements, 4882 finisher: finisher 4883 }; 4884 }, 4885 runClassFinishers: function (constructor, finishers) { 4886 for (var i = 0; i < finishers.length; i++) { 4887 var newConstructor = (0, finishers[i])(constructor); 4888 if (newConstructor !== undefined) { 4889 if (typeof newConstructor !== "function") { 4890 throw new TypeError("Finishers must return a constructor."); 4891 } 4892 constructor = newConstructor; 4893 } 4894 } 4895 return constructor; 4896 }, 4897 disallowProperty: function (obj, name, objectType) { 4898 if (obj[name] !== undefined) { 4899 throw new TypeError(objectType + " can't have a ." + name + " property."); 4900 } 4901 } 4902 }; 4903 return api; 4904 } 4905 function _createElementDescriptor(def) { 4906 var key = _toPropertyKey(def.key); 4907 var descriptor; 4908 if (def.kind === "method") { 4909 descriptor = { 4910 value: def.value, 4911 writable: true, 4912 configurable: true, 4913 enumerable: false 4914 }; 4915 } else if (def.kind === "get") { 4916 descriptor = { 4917 get: def.value, 4918 configurable: true, 4919 enumerable: false 4920 }; 4921 } else if (def.kind === "set") { 4922 descriptor = { 4923 set: def.value, 4924 configurable: true, 4925 enumerable: false 4926 }; 4927 } else if (def.kind === "field") { 4928 descriptor = { 4929 configurable: true, 4930 writable: true, 4931 enumerable: true 4932 }; 4933 } 4934 var element = { 4935 kind: def.kind === "field" ? "field" : "method", 4936 key: key, 4937 placement: def.static ? "static" : def.kind === "field" ? "own" : "prototype", 4938 descriptor: descriptor 4939 }; 4940 if (def.decorators) element.decorators = def.decorators; 4941 if (def.kind === "field") element.initializer = def.value; 4942 return element; 4943 } 4944 function _coalesceGetterSetter(element, other) { 4945 if (element.descriptor.get !== undefined) { 4946 other.descriptor.get = element.descriptor.get; 4947 } else { 4948 other.descriptor.set = element.descriptor.set; 4949 } 4950 } 4951 function _coalesceClassElements(elements) { 4952 var newElements = []; 4953 var isSameElement = function (other) { 4954 return other.kind === "method" && other.key === element.key && other.placement === element.placement; 4955 }; 4956 for (var i = 0; i < elements.length; i++) { 4957 var element = elements[i]; 4958 var other; 4959 if (element.kind === "method" && (other = newElements.find(isSameElement))) { 4960 if (_isDataDescriptor(element.descriptor) || _isDataDescriptor(other.descriptor)) { 4961 if (_hasDecorators(element) || _hasDecorators(other)) { 4962 throw new ReferenceError("Duplicated methods (" + element.key + ") can't be decorated."); 4963 } 4964 other.descriptor = element.descriptor; 4965 } else { 4966 if (_hasDecorators(element)) { 4967 if (_hasDecorators(other)) { 4968 throw new ReferenceError("Decorators can't be placed on different accessors with for " + "the same property (" + element.key + ")."); 4969 } 4970 other.decorators = element.decorators; 4971 } 4972 _coalesceGetterSetter(element, other); 4973 } 4974 } else { 4975 newElements.push(element); 4976 } 4977 } 4978 return newElements; 4979 } 4980 function _hasDecorators(element) { 4981 return element.decorators && element.decorators.length; 4982 } 4983 function _isDataDescriptor(desc) { 4984 return desc !== undefined && !(desc.value === undefined && desc.writable === undefined); 4985 } 4986 function _optionalCallableProperty(obj, name) { 4987 var value = obj[name]; 4988 if (value !== undefined && typeof value !== "function") { 4989 throw new TypeError("Expected '" + name + "' to be a function"); 4990 } 4991 return value; 4992 } 4993 function _classPrivateMethodGet(receiver, privateSet, fn) { 4994 if (!privateSet.has(receiver)) { 4995 throw new TypeError("attempted to get private field on non-instance"); 4996 } 4997 return fn; 4998 } 4999 function _checkPrivateRedeclaration(obj, privateCollection) { 5000 if (privateCollection.has(obj)) { 5001 throw new TypeError("Cannot initialize the same private elements twice on an object"); 5002 } 5003 } 5004 function _classPrivateFieldInitSpec(obj, privateMap, value) { 5005 _checkPrivateRedeclaration(obj, privateMap); 5006 privateMap.set(obj, value); 5007 } 5008 function _classPrivateMethodInitSpec(obj, privateSet) { 5009 _checkPrivateRedeclaration(obj, privateSet); 5010 privateSet.add(obj); 5011 } 5012 function _classPrivateMethodSet() { 5013 throw new TypeError("attempted to reassign private method"); 5014 } 5015 function _identity(x) { 5016 return x; 5017 } 5018 function _nullishReceiverError(r) { 5019 throw new TypeError("Cannot set property of null or undefined."); 5020 } 5021 5022 class Piece extends TrixObject { 5023 static registerType(type, constructor) { 5024 constructor.type = type; 5025 this.types[type] = constructor; 5026 } 5027 static fromJSON(pieceJSON) { 5028 const constructor = this.types[pieceJSON.type]; 5029 if (constructor) { 5030 return constructor.fromJSON(pieceJSON); 5031 } 5032 } 5033 constructor(value) { 5034 let attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 5035 super(...arguments); 5036 this.attributes = Hash.box(attributes); 5037 } 5038 copyWithAttributes(attributes) { 5039 return new this.constructor(this.getValue(), attributes); 5040 } 5041 copyWithAdditionalAttributes(attributes) { 5042 return this.copyWithAttributes(this.attributes.merge(attributes)); 5043 } 5044 copyWithoutAttribute(attribute) { 5045 return this.copyWithAttributes(this.attributes.remove(attribute)); 5046 } 5047 copy() { 5048 return this.copyWithAttributes(this.attributes); 5049 } 5050 getAttribute(attribute) { 5051 return this.attributes.get(attribute); 5052 } 5053 getAttributesHash() { 5054 return this.attributes; 5055 } 5056 getAttributes() { 5057 return this.attributes.toObject(); 5058 } 5059 hasAttribute(attribute) { 5060 return this.attributes.has(attribute); 5061 } 5062 hasSameStringValueAsPiece(piece) { 5063 return piece && this.toString() === piece.toString(); 5064 } 5065 hasSameAttributesAsPiece(piece) { 5066 return piece && (this.attributes === piece.attributes || this.attributes.isEqualTo(piece.attributes)); 5067 } 5068 isBlockBreak() { 5069 return false; 5070 } 5071 isEqualTo(piece) { 5072 return super.isEqualTo(...arguments) || this.hasSameConstructorAs(piece) && this.hasSameStringValueAsPiece(piece) && this.hasSameAttributesAsPiece(piece); 5073 } 5074 isEmpty() { 5075 return this.length === 0; 5076 } 5077 isSerializable() { 5078 return true; 5079 } 5080 toJSON() { 5081 return { 5082 type: this.constructor.type, 5083 attributes: this.getAttributes() 5084 }; 5085 } 5086 contentsForInspection() { 5087 return { 5088 type: this.constructor.type, 5089 attributes: this.attributes.inspect() 5090 }; 5091 } 5092 5093 // Grouping 5094 5095 canBeGrouped() { 5096 return this.hasAttribute("href"); 5097 } 5098 canBeGroupedWith(piece) { 5099 return this.getAttribute("href") === piece.getAttribute("href"); 5100 } 5101 5102 // Splittable 5103 5104 getLength() { 5105 return this.length; 5106 } 5107 canBeConsolidatedWith(piece) { 5108 return false; 5109 } 5110 } 5111 _defineProperty(Piece, "types", {}); 5112 5113 class ImagePreloadOperation extends Operation { 5114 constructor(url) { 5115 super(...arguments); 5116 this.url = url; 5117 } 5118 perform(callback) { 5119 const image = new Image(); 5120 image.onload = () => { 5121 image.width = this.width = image.naturalWidth; 5122 image.height = this.height = image.naturalHeight; 5123 return callback(true, image); 5124 }; 5125 image.onerror = () => callback(false); 5126 image.src = this.url; 5127 } 5128 } 5129 5130 class Attachment extends TrixObject { 5131 static attachmentForFile(file) { 5132 const attributes = this.attributesForFile(file); 5133 const attachment = new this(attributes); 5134 attachment.setFile(file); 5135 return attachment; 5136 } 5137 static attributesForFile(file) { 5138 return new Hash({ 5139 filename: file.name, 5140 filesize: file.size, 5141 contentType: file.type 5142 }); 5143 } 5144 static fromJSON(attachmentJSON) { 5145 return new this(attachmentJSON); 5146 } 5147 constructor() { 5148 let attributes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; 5149 super(attributes); 5150 this.releaseFile = this.releaseFile.bind(this); 5151 this.attributes = Hash.box(attributes); 5152 this.didChangeAttributes(); 5153 } 5154
vendor: 8,215 bytes, lines 5154-5382
5154getAttribute(attribute) { 5155 return this.attributes.get(attribute); 5156 } 5157 hasAttribute(attribute) { 5158 return this.attributes.has(attribute); 5159 } 5160 getAttributes() { 5161 return this.attributes.toObject(); 5162 } 5163 setAttributes() { 5164 let attributes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; 5165 const newAttributes = this.attributes.merge(attributes); 5166 if (!this.attributes.isEqualTo(newAttributes)) { 5167 var _this$previewDelegate, _this$previewDelegate2, _this$delegate, _this$delegate$attach; 5168 this.attributes = newAttributes; 5169 this.didChangeAttributes(); 5170 (_this$previewDelegate = this.previewDelegate) === null || _this$previewDelegate === void 0 || (_this$previewDelegate2 = _this$previewDelegate.attachmentDidChangeAttributes) === null || _this$previewDelegate2 === void 0 || _this$previewDelegate2.call(_this$previewDelegate, this); 5171 return (_this$delegate = this.delegate) === null || _this$delegate === void 0 || (_this$delegate$attach = _this$delegate.attachmentDidChangeAttributes) === null || _this$delegate$attach === void 0 ? void 0 : _this$delegate$attach.call(_this$delegate, this); 5172 } 5173 } 5174 didChangeAttributes() { 5175 if (this.isPreviewable()) { 5176 return this.preloadURL(); 5177 } 5178 } 5179 isPending() { 5180 return this.file != null && !(this.getURL() || this.getHref()); 5181 } 5182 isPreviewable() { 5183 if (this.attributes.has("previewable")) { 5184 return this.attributes.get("previewable"); 5185 } else { 5186 return Attachment.previewablePattern.test(this.getContentType()); 5187 } 5188 } 5189 getType() { 5190 if (this.hasContent()) { 5191 return "content"; 5192 } else if (this.isPreviewable()) { 5193 return "preview"; 5194 } else { 5195 return "file"; 5196 } 5197 } 5198 getURL() { 5199 return this.attributes.get("url"); 5200 } 5201 getHref() { 5202 return this.attributes.get("href"); 5203 } 5204 getFilename() { 5205 return this.attributes.get("filename") || ""; 5206 } 5207 getFilesize() { 5208 return this.attributes.get("filesize"); 5209 } 5210 getFormattedFilesize() { 5211 const filesize = this.attributes.get("filesize"); 5212 if (typeof filesize === "number") { 5213 return file_size_formatting.formatter(filesize); 5214 } else { 5215 return ""; 5216 } 5217 } 5218 getExtension() { 5219 var _this$getFilename$mat; 5220 return (_this$getFilename$mat = this.getFilename().match(/\.(\w+)$/)) === null || _this$getFilename$mat === void 0 ? void 0 : _this$getFilename$mat[1].toLowerCase(); 5221 } 5222 getContentType() { 5223 return this.attributes.get("contentType"); 5224 } 5225 hasContent() { 5226 return this.attributes.has("content"); 5227 } 5228 getContent() { 5229 return this.attributes.get("content"); 5230 } 5231 getWidth() { 5232 return this.attributes.get("width"); 5233 } 5234 getHeight() { 5235 return this.attributes.get("height"); 5236 } 5237 getFile() { 5238 return this.file; 5239 } 5240 setFile(file) { 5241 this.file = file; 5242 if (this.isPreviewable()) { 5243 return this.preloadFile(); 5244 } 5245 } 5246 releaseFile() { 5247 this.releasePreloadedFile(); 5248 this.file = null; 5249 } 5250 getUploadProgress() { 5251 return this.uploadProgress != null ? this.uploadProgress : 0; 5252 } 5253 setUploadProgress(value) { 5254 if (this.uploadProgress !== value) { 5255 var _this$uploadProgressD, _this$uploadProgressD2; 5256 this.uploadProgress = value; 5257 return (_this$uploadProgressD = this.uploadProgressDelegate) === null || _this$uploadProgressD === void 0 || (_this$uploadProgressD2 = _this$uploadProgressD.attachmentDidChangeUploadProgress) === null || _this$uploadProgressD2 === void 0 ? void 0 : _this$uploadProgressD2.call(_this$uploadProgressD, this); 5258 } 5259 } 5260 toJSON() { 5261 return this.getAttributes(); 5262 } 5263 getCacheKey() { 5264 return [super.getCacheKey(...arguments), this.attributes.getCacheKey(), this.getPreviewURL()].join("/"); 5265 } 5266 5267 // Previewable 5268 5269 getPreviewURL() { 5270 return this.previewURL || this.preloadingURL; 5271 } 5272 setPreviewURL(url) { 5273 if (url !== this.getPreviewURL()) { 5274 var _this$previewDelegate3, _this$previewDelegate4, _this$delegate2, _this$delegate2$attac; 5275 this.previewURL = url; 5276 (_this$previewDelegate3 = this.previewDelegate) === null || _this$previewDelegate3 === void 0 || (_this$previewDelegate4 = _this$previewDelegate3.attachmentDidChangeAttributes) === null || _this$previewDelegate4 === void 0 || _this$previewDelegate4.call(_this$previewDelegate3, this); 5277 return (_this$delegate2 = this.delegate) === null || _this$delegate2 === void 0 || (_this$delegate2$attac = _this$delegate2.attachmentDidChangePreviewURL) === null || _this$delegate2$attac === void 0 ? void 0 : _this$delegate2$attac.call(_this$delegate2, this); 5278 } 5279 } 5280 preloadURL() { 5281 return this.preload(this.getURL(), this.releaseFile); 5282 } 5283 preloadFile() { 5284 if (this.file) { 5285 this.fileObjectURL = URL.createObjectURL(this.file); 5286 return this.preload(this.fileObjectURL); 5287 } 5288 } 5289 releasePreloadedFile() { 5290 if (this.fileObjectURL) { 5291 URL.revokeObjectURL(this.fileObjectURL); 5292 this.fileObjectURL = null; 5293 } 5294 } 5295 preload(url, callback) { 5296 if (url && url !== this.getPreviewURL()) { 5297 this.preloadingURL = url; 5298 const operation = new ImagePreloadOperation(url); 5299 return operation.then(_ref => { 5300 let { 5301 width, 5302 height 5303 } = _ref; 5304 if (!this.getWidth() || !this.getHeight()) { 5305 this.setAttributes({ 5306 width, 5307 height 5308 }); 5309 } 5310 this.preloadingURL = null; 5311 this.setPreviewURL(url); 5312 return callback === null || callback === void 0 ? void 0 : callback(); 5313 }).catch(() => { 5314 this.preloadingURL = null; 5315 return callback === null || callback === void 0 ? void 0 : callback(); 5316 }); 5317 } 5318 } 5319 } 5320 _defineProperty(Attachment, "previewablePattern", /^image(\/(gif|png|webp|jpe?g)|$)/); 5321 5322 class AttachmentPiece extends Piece { 5323 static fromJSON(pieceJSON) { 5324 return new this(Attachment.fromJSON(pieceJSON.attachment), pieceJSON.attributes); 5325 } 5326 constructor(attachment) { 5327 super(...arguments); 5328 this.attachment = attachment; 5329 this.length = 1; 5330 this.ensureAttachmentExclusivelyHasAttribute("href"); 5331 if (!this.attachment.hasContent()) { 5332 this.removeProhibitedAttributes(); 5333 } 5334 } 5335 ensureAttachmentExclusivelyHasAttribute(attribute) { 5336 if (this.hasAttribute(attribute)) { 5337 if (!this.attachment.hasAttribute(attribute)) { 5338 this.attachment.setAttributes(this.attributes.slice([attribute])); 5339 } 5340 this.attributes = this.attributes.remove(attribute); 5341 } 5342 } 5343 removeProhibitedAttributes() { 5344 const attributes = this.attributes.slice(AttachmentPiece.permittedAttributes); 5345 if (!attributes.isEqualTo(this.attributes)) { 5346 this.attributes = attributes; 5347 } 5348 } 5349 getValue() { 5350 return this.attachment; 5351 } 5352 isSerializable() { 5353 return !this.attachment.isPending(); 5354 } 5355 getCaption() { 5356 return this.attributes.get("caption") || ""; 5357 } 5358 isEqualTo(piece) { 5359 var _piece$attachment; 5360 return super.isEqualTo(piece) && this.attachment.id === (piece === null || piece === void 0 || (_piece$attachment = piece.attachment) === null || _piece$attachment === void 0 ? void 0 : _piece$attachment.id); 5361 } 5362 toString() { 5363 return OBJECT_REPLACEMENT_CHARACTER; 5364 } 5365 toJSON() { 5366 const json = super.toJSON(...arguments); 5367 json.attachment = this.attachment; 5368 return json; 5369 } 5370 getCacheKey() { 5371 return [super.getCacheKey(...arguments), this.attachment.getCacheKey()].join("/"); 5372 } 5373 toConsole() { 5374 return JSON.stringify(this.toString()); 5375 } 5376 } 5377 _defineProperty(AttachmentPiece, "permittedAttributes", ["caption", "presentation"]); 5378 Piece.registerType("attachment", AttachmentPiece); 5379 5380 class StringPiece extends Piece { 5381 static fromJSON(pieceJSON) { 5382 return new this(pieceJSON.string, pieceJSON.
vendor: 51,682 bytes, lines 5382-6819
5382attributes); 5383 } 5384 constructor(string) { 5385 super(...arguments); 5386 this.string = normalizeNewlines(string); 5387 this.length = this.string.length; 5388 } 5389 getValue() { 5390 return this.string; 5391 } 5392 toString() { 5393 return this.string.toString(); 5394 } 5395 isBlockBreak() { 5396 return this.toString() === "\n" && this.getAttribute("blockBreak") === true; 5397 } 5398 toJSON() { 5399 const result = super.toJSON(...arguments); 5400 result.string = this.string; 5401 return result; 5402 } 5403 5404 // Splittable 5405 5406 canBeConsolidatedWith(piece) { 5407 return piece && this.hasSameConstructorAs(piece) && this.hasSameAttributesAsPiece(piece); 5408 } 5409 consolidateWith(piece) { 5410 return new this.constructor(this.toString() + piece.toString(), this.attributes); 5411 } 5412 splitAtOffset(offset) { 5413 let left, right; 5414 if (offset === 0) { 5415 left = null; 5416 right = this; 5417 } else if (offset === this.length) { 5418 left = this; 5419 right = null; 5420 } else { 5421 left = new this.constructor(this.string.slice(0, offset), this.attributes); 5422 right = new this.constructor(this.string.slice(offset), this.attributes); 5423 } 5424 return [left, right]; 5425 } 5426 toConsole() { 5427 let { 5428 string 5429 } = this; 5430 if (string.length > 15) { 5431 string = string.slice(0, 14) + "â¦"; 5432 } 5433 return JSON.stringify(string.toString()); 5434 } 5435 } 5436 Piece.registerType("string", StringPiece); 5437 5438 /* eslint-disable 5439 prefer-const, 5440 */ 5441 class SplittableList extends TrixObject { 5442 static box(objects) { 5443 if (objects instanceof this) { 5444 return objects; 5445 } else { 5446 return new this(objects); 5447 } 5448 } 5449 constructor() { 5450 let objects = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; 5451 super(...arguments); 5452 this.objects = objects.slice(0); 5453 this.length = this.objects.length; 5454 } 5455 indexOf(object) { 5456 return this.objects.indexOf(object); 5457 } 5458 splice() { 5459 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 5460 args[_key] = arguments[_key]; 5461 } 5462 return new this.constructor(spliceArray(this.objects, ...args)); 5463 } 5464 eachObject(callback) { 5465 return this.objects.map((object, index) => callback(object, index)); 5466 } 5467 insertObjectAtIndex(object, index) { 5468 return this.splice(index, 0, object); 5469 } 5470 insertSplittableListAtIndex(splittableList, index) { 5471 return this.splice(index, 0, ...splittableList.objects); 5472 } 5473 insertSplittableListAtPosition(splittableList, position) { 5474 const [objects, index] = this.splitObjectAtPosition(position); 5475 return new this.constructor(objects).insertSplittableListAtIndex(splittableList, index); 5476 } 5477 editObjectAtIndex(index, callback) { 5478 return this.replaceObjectAtIndex(callback(this.objects[index]), index); 5479 } 5480 replaceObjectAtIndex(object, index) { 5481 return this.splice(index, 1, object); 5482 } 5483 removeObjectAtIndex(index) { 5484 return this.splice(index, 1); 5485 } 5486 getObjectAtIndex(index) { 5487 return this.objects[index]; 5488 } 5489 getSplittableListInRange(range) { 5490 const [objects, leftIndex, rightIndex] = this.splitObjectsAtRange(range); 5491 return new this.constructor(objects.slice(leftIndex, rightIndex + 1)); 5492 } 5493 selectSplittableList(test) { 5494 const objects = this.objects.filter(object => test(object)); 5495 return new this.constructor(objects); 5496 } 5497 removeObjectsInRange(range) { 5498 const [objects, leftIndex, rightIndex] = this.splitObjectsAtRange(range); 5499 return new this.constructor(objects).splice(leftIndex, rightIndex - leftIndex + 1); 5500 } 5501 transformObjectsInRange(range, transform) { 5502 const [objects, leftIndex, rightIndex] = this.splitObjectsAtRange(range); 5503 const transformedObjects = objects.map((object, index) => leftIndex <= index && index <= rightIndex ? transform(object) : object); 5504 return new this.constructor(transformedObjects); 5505 } 5506 splitObjectsAtRange(range) { 5507 let rightOuterIndex; 5508 let [objects, leftInnerIndex, offset] = this.splitObjectAtPosition(startOfRange(range)); 5509 [objects, rightOuterIndex] = new this.constructor(objects).splitObjectAtPosition(endOfRange(range) + offset); 5510 return [objects, leftInnerIndex, rightOuterIndex - 1]; 5511 } 5512 getObjectAtPosition(position) { 5513 const { 5514 index 5515 } = this.findIndexAndOffsetAtPosition(position); 5516 return this.objects[index]; 5517 } 5518 splitObjectAtPosition(position) { 5519 let splitIndex, splitOffset; 5520 const { 5521 index, 5522 offset 5523 } = this.findIndexAndOffsetAtPosition(position); 5524 const objects = this.objects.slice(0); 5525 if (index != null) { 5526 if (offset === 0) { 5527 splitIndex = index; 5528 splitOffset = 0; 5529 } else { 5530 const object = this.getObjectAtIndex(index); 5531 const [leftObject, rightObject] = object.splitAtOffset(offset); 5532 objects.splice(index, 1, leftObject, rightObject); 5533 splitIndex = index + 1; 5534 splitOffset = leftObject.getLength() - offset; 5535 } 5536 } else { 5537 splitIndex = objects.length; 5538 splitOffset = 0; 5539 } 5540 return [objects, splitIndex, splitOffset]; 5541 } 5542 consolidate() { 5543 const objects = []; 5544 let pendingObject = this.objects[0]; 5545 this.objects.slice(1).forEach(object => { 5546 var _pendingObject$canBeC, _pendingObject; 5547 if ((_pendingObject$canBeC = (_pendingObject = pendingObject).canBeConsolidatedWith) !== null && _pendingObject$canBeC !== void 0 && _pendingObject$canBeC.call(_pendingObject, object)) { 5548 pendingObject = pendingObject.consolidateWith(object); 5549 } else { 5550 objects.push(pendingObject); 5551 pendingObject = object; 5552 } 5553 }); 5554 if (pendingObject) { 5555 objects.push(pendingObject); 5556 } 5557 return new this.constructor(objects); 5558 } 5559 consolidateFromIndexToIndex(startIndex, endIndex) { 5560 const objects = this.objects.slice(0); 5561 const objectsInRange = objects.slice(startIndex, endIndex + 1); 5562 const consolidatedInRange = new this.constructor(objectsInRange).consolidate().toArray(); 5563 return this.splice(startIndex, objectsInRange.length, ...consolidatedInRange); 5564 } 5565 findIndexAndOffsetAtPosition(position) { 5566 let index; 5567 let currentPosition = 0; 5568 for (index = 0; index < this.objects.length; index++) { 5569 const object = this.objects[index]; 5570 const nextPosition = currentPosition + object.getLength(); 5571 if (currentPosition <= position && position < nextPosition) { 5572 return { 5573 index, 5574 offset: position - currentPosition 5575 }; 5576 } 5577 currentPosition = nextPosition; 5578 } 5579 return { 5580 index: null, 5581 offset: null 5582 }; 5583 } 5584 findPositionAtIndexAndOffset(index, offset) { 5585 let position = 0; 5586 for (let currentIndex = 0; currentIndex < this.objects.length; currentIndex++) { 5587 const object = this.objects[currentIndex]; 5588 if (currentIndex < index) { 5589 position += object.getLength(); 5590 } else if (currentIndex === index) { 5591 position += offset; 5592 break; 5593 } 5594 } 5595 return position; 5596 } 5597 getEndPosition() { 5598 if (this.endPosition == null) { 5599 this.endPosition = 0; 5600 this.objects.forEach(object => this.endPosition += object.getLength()); 5601 } 5602 return this.endPosition; 5603 } 5604 toString() { 5605 return this.objects.join(""); 5606 } 5607 toArray() { 5608 return this.objects.slice(0); 5609 } 5610 toJSON() { 5611 return this.toArray(); 5612 } 5613 isEqualTo(splittableList) { 5614 return super.isEqualTo(...arguments) || objectArraysAreEqual(this.objects, splittableList === null || splittableList === void 0 ? void 0 : splittableList.objects); 5615 } 5616 contentsForInspection() { 5617 return { 5618 objects: "[".concat(this.objects.map(object => object.inspect()).join(", "), "]") 5619 }; 5620 } 5621 } 5622 const objectArraysAreEqual = function (left) { 5623 let right = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; 5624 if (left.length !== right.length) { 5625 return false; 5626 } 5627 let result = true; 5628 for (let index = 0; index < left.length; index++) { 5629 const object = left[index]; 5630 if (result && !object.isEqualTo(right[index])) { 5631 result = false; 5632 } 5633 } 5634 return result; 5635 }; 5636 const startOfRange = range => range[0]; 5637 const endOfRange = range => range[1]; 5638 5639 class Text extends TrixObject { 5640 static textForAttachmentWithAttributes(attachment, attributes) { 5641 const piece = new AttachmentPiece(attachment, attributes); 5642 return new this([piece]); 5643 } 5644 static textForStringWithAttributes(string, attributes) { 5645 const piece = new StringPiece(string, attributes); 5646 return new this([piece]); 5647 } 5648 static fromJSON(textJSON) { 5649 const pieces = Array.from(textJSON).map(pieceJSON => Piece.fromJSON(pieceJSON)); 5650 return new this(pieces); 5651 } 5652 constructor() { 5653 let pieces = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; 5654 super(...arguments); 5655 const notEmpty = pieces.filter(piece => !piece.isEmpty()); 5656 this.pieceList = new SplittableList(notEmpty); 5657 } 5658 copy() { 5659 return this.copyWithPieceList(this.pieceList); 5660 } 5661 copyWithPieceList(pieceList) { 5662 return new this.constructor(pieceList.consolidate().toArray()); 5663 } 5664 copyUsingObjectMap(objectMap) { 5665 const pieces = this.getPieces().map(piece => objectMap.find(piece) || piece); 5666 return new this.constructor(pieces); 5667 } 5668 appendText(text) { 5669 return this.insertTextAtPosition(text, this.getLength()); 5670 } 5671 insertTextAtPosition(text, position) { 5672 return this.copyWithPieceList(this.pieceList.insertSplittableListAtPosition(text.pieceList, position)); 5673 } 5674 removeTextAtRange(range) { 5675 return this.copyWithPieceList(this.pieceList.removeObjectsInRange(range)); 5676 } 5677 replaceTextAtRange(text, range) { 5678 return this.removeTextAtRange(range).insertTextAtPosition(text, range[0]); 5679 } 5680 moveTextFromRangeToPosition(range, position) { 5681 if (range[0] <= position && position <= range[1]) return; 5682 const text = this.getTextAtRange(range); 5683 const length = text.getLength(); 5684 if (range[0] < position) { 5685 position -= length; 5686 } 5687 return this.removeTextAtRange(range).insertTextAtPosition(text, position); 5688 } 5689 addAttributeAtRange(attribute, value, range) { 5690 const attributes = {}; 5691 attributes[attribute] = value; 5692 return this.addAttributesAtRange(attributes, range); 5693 } 5694 addAttributesAtRange(attributes, range) { 5695 return this.copyWithPieceList(this.pieceList.transformObjectsInRange(range, piece => piece.copyWithAdditionalAttributes(attributes))); 5696 } 5697 removeAttributeAtRange(attribute, range) { 5698 return this.copyWithPieceList(this.pieceList.transformObjectsInRange(range, piece => piece.copyWithoutAttribute(attribute))); 5699 } 5700 setAttributesAtRange(attributes, range) { 5701 return this.copyWithPieceList(this.pieceList.transformObjectsInRange(range, piece => piece.copyWithAttributes(attributes))); 5702 } 5703 getAttributesAtPosition(position) { 5704 var _this$pieceList$getOb; 5705 return ((_this$pieceList$getOb = this.pieceList.getObjectAtPosition(position)) === null || _this$pieceList$getOb === void 0 ? void 0 : _this$pieceList$getOb.getAttributes()) || {}; 5706 } 5707 getCommonAttributes() { 5708 const objects = Array.from(this.pieceList.toArray()).map(piece => piece.getAttributes()); 5709 return Hash.fromCommonAttributesOfObjects(objects).toObject(); 5710 } 5711 getCommonAttributesAtRange(range) { 5712 return this.getTextAtRange(range).getCommonAttributes() || {}; 5713 } 5714 getExpandedRangeForAttributeAtOffset(attributeName, offset) { 5715 let right; 5716 let left = right = offset; 5717 const length = this.getLength(); 5718 while (left > 0 && this.getCommonAttributesAtRange([left - 1, right])[attributeName]) { 5719 left--; 5720 } 5721 while (right < length && this.getCommonAttributesAtRange([offset, right + 1])[attributeName]) { 5722 right++; 5723 } 5724 return [left, right]; 5725 } 5726 getTextAtRange(range) { 5727 return this.copyWithPieceList(this.pieceList.getSplittableListInRange(range)); 5728 } 5729 getStringAtRange(range) { 5730 return this.pieceList.getSplittableListInRange(range).toString(); 5731 } 5732 getStringAtPosition(position) { 5733 return this.getStringAtRange([position, position + 1]); 5734 } 5735 startsWithString(string) { 5736 return this.getStringAtRange([0, string.length]) === string; 5737 } 5738 endsWithString(string) { 5739 const length = this.getLength(); 5740 return this.getStringAtRange([length - string.length, length]) === string; 5741 } 5742 getAttachmentPieces() { 5743 return this.pieceList.toArray().filter(piece => !!piece.attachment); 5744 } 5745 getAttachments() { 5746 return this.getAttachmentPieces().map(piece => piece.attachment); 5747 } 5748 getAttachmentAndPositionById(attachmentId) { 5749 let position = 0; 5750 for (const piece of this.pieceList.toArray()) { 5751 var _piece$attachment; 5752 if (((_piece$attachment = piece.attachment) === null || _piece$attachment === void 0 ? void 0 : _piece$attachment.id) === attachmentId) { 5753 return { 5754 attachment: piece.attachment, 5755 position 5756 }; 5757 } 5758 position += piece.length; 5759 } 5760 return { 5761 attachment: null, 5762 position: null 5763 }; 5764 } 5765 getAttachmentById(attachmentId) { 5766 const { 5767 attachment 5768 } = this.getAttachmentAndPositionById(attachmentId); 5769 return attachment; 5770 } 5771 getRangeOfAttachment(attachment) { 5772 const attachmentAndPosition = this.getAttachmentAndPositionById(attachment.id); 5773 const position = attachmentAndPosition.position; 5774 attachment = attachmentAndPosition.attachment; 5775 if (attachment) { 5776 return [position, position + 1]; 5777 } 5778 } 5779 updateAttributesForAttachment(attributes, attachment) { 5780 const range = this.getRangeOfAttachment(attachment); 5781 if (range) { 5782 return this.addAttributesAtRange(attributes, range); 5783 } else { 5784 return this; 5785 } 5786 } 5787 getLength() { 5788 return this.pieceList.getEndPosition(); 5789 } 5790 isEmpty() { 5791 return this.getLength() === 0; 5792 } 5793 isEqualTo(text) { 5794 var _text$pieceList; 5795 return super.isEqualTo(text) || (text === null || text === void 0 || (_text$pieceList = text.pieceList) === null || _text$pieceList === void 0 ? void 0 : _text$pieceList.isEqualTo(this.pieceList)); 5796 } 5797 isBlockBreak() { 5798 return this.getLength() === 1 && this.pieceList.getObjectAtIndex(0).isBlockBreak(); 5799 } 5800 eachPiece(callback) { 5801 return this.pieceList.eachObject(callback); 5802 } 5803 getPieces() { 5804 return this.pieceList.toArray(); 5805 } 5806 getPieceAtPosition(position) { 5807 return this.pieceList.getObjectAtPosition(position); 5808 } 5809 contentsForInspection() { 5810 return { 5811 pieceList: this.pieceList.inspect() 5812 }; 5813 } 5814 toSerializableText() { 5815 const pieceList = this.pieceList.selectSplittableList(piece => piece.isSerializable()); 5816 return this.copyWithPieceList(pieceList); 5817 } 5818 toString() { 5819 return this.pieceList.toString(); 5820 } 5821 toJSON() { 5822 return this.pieceList.toJSON(); 5823 } 5824 toConsole() { 5825 return JSON.stringify(this.pieceList.toArray().map(piece => JSON.parse(piece.toConsole()))); 5826 } 5827 5828 // BIDI 5829 5830 getDirection() { 5831 return getDirection(this.toString()); 5832 } 5833 isRTL() { 5834 return this.getDirection() === "rtl"; 5835 } 5836 } 5837 5838 class Block extends TrixObject { 5839 static fromJSON(blockJSON) { 5840 const text = Text.fromJSON(blockJSON.text); 5841 return new this(text, blockJSON.attributes, blockJSON.htmlAttributes); 5842 } 5843 constructor(text, attributes, htmlAttributes) { 5844 super(...arguments); 5845 this.text = applyBlockBreakToText(text || new Text()); 5846 this.attributes = attributes || []; 5847 this.htmlAttributes = htmlAttributes || {}; 5848 } 5849 isEmpty() { 5850 return this.text.isBlockBreak(); 5851 } 5852 isEqualTo(block) { 5853 if (super.isEqualTo(block)) return true; 5854 return this.text.isEqualTo(block === null || block === void 0 ? void 0 : block.text) && arraysAreEqual(this.attributes, block === null || block === void 0 ? void 0 : block.attributes) && objectsAreEqual(this.htmlAttributes, block === null || block === void 0 ? void 0 : block.htmlAttributes); 5855 } 5856 copyWithText(text) { 5857 return new Block(text, this.attributes, this.htmlAttributes); 5858 } 5859 copyWithoutText() { 5860 return this.copyWithText(null); 5861 } 5862 copyWithAttributes(attributes) { 5863 return new Block(this.text, attributes, this.htmlAttributes); 5864 } 5865 copyWithoutAttributes() { 5866 return this.copyWithAttributes(null); 5867 } 5868 copyUsingObjectMap(objectMap) { 5869 const mappedText = objectMap.find(this.text); 5870 if (mappedText) { 5871 return this.copyWithText(mappedText); 5872 } else { 5873 return this.copyWithText(this.text.copyUsingObjectMap(objectMap)); 5874 } 5875 } 5876 addAttribute(attribute) { 5877 const attributes = this.attributes.concat(expandAttribute(attribute)); 5878 return this.copyWithAttributes(attributes); 5879 } 5880 addHTMLAttribute(attribute, value) { 5881 const htmlAttributes = Object.assign({}, this.htmlAttributes, { 5882 [attribute]: value 5883 }); 5884 return new Block(this.text, this.attributes, htmlAttributes); 5885 } 5886 removeAttribute(attribute) { 5887 const { 5888 listAttribute 5889 } = getBlockConfig(attribute); 5890 const attributes = removeLastValue(removeLastValue(this.attributes, attribute), listAttribute); 5891 return this.copyWithAttributes(attributes); 5892 } 5893 removeLastAttribute() { 5894 return this.removeAttribute(this.getLastAttribute()); 5895 } 5896 getLastAttribute() { 5897 return getLastElement(this.attributes); 5898 } 5899 getAttributes() { 5900 return this.attributes.slice(0); 5901 } 5902 getAttributeLevel() { 5903 return this.attributes.length; 5904 } 5905 getAttributeAtLevel(level) { 5906 return this.attributes[level - 1]; 5907 } 5908 hasAttribute(attributeName) { 5909 return this.attributes.includes(attributeName); 5910 } 5911 hasAttributes() { 5912 return this.getAttributeLevel() > 0; 5913 } 5914 getLastNestableAttribute() { 5915 return getLastElement(this.getNestableAttributes()); 5916 } 5917 getNestableAttributes() { 5918 return this.attributes.filter(attribute => getBlockConfig(attribute).nestable); 5919 } 5920 getNestingLevel() { 5921 return this.getNestableAttributes().length; 5922 } 5923 decreaseNestingLevel() { 5924 const attribute = this.getLastNestableAttribute(); 5925 if (attribute) { 5926 return this.removeAttribute(attribute); 5927 } else { 5928 return this; 5929 } 5930 } 5931 increaseNestingLevel() { 5932 const attribute = this.getLastNestableAttribute(); 5933 if (attribute) { 5934 const index = this.attributes.lastIndexOf(attribute); 5935 const attributes = spliceArray(this.attributes, index + 1, 0, ...expandAttribute(attribute)); 5936 return this.copyWithAttributes(attributes); 5937 } else { 5938 return this; 5939 } 5940 } 5941 getListItemAttributes() { 5942 return this.attributes.filter(attribute => getBlockConfig(attribute).listAttribute); 5943 } 5944 isListItem() { 5945 var _getBlockConfig; 5946 return (_getBlockConfig = getBlockConfig(this.getLastAttribute())) === null || _getBlockConfig === void 0 ? void 0 : _getBlockConfig.listAttribute; 5947 } 5948 isTerminalBlock() { 5949 var _getBlockConfig2; 5950 return (_getBlockConfig2 = getBlockConfig(this.getLastAttribute())) === null || _getBlockConfig2 === void 0 ? void 0 : _getBlockConfig2.terminal; 5951 } 5952 breaksOnReturn() { 5953 var _getBlockConfig3; 5954 return (_getBlockConfig3 = getBlockConfig(this.getLastAttribute())) === null || _getBlockConfig3 === void 0 ? void 0 : _getBlockConfig3.breakOnReturn; 5955 } 5956 findLineBreakInDirectionFromPosition(direction, position) { 5957 const string = this.toString(); 5958 let result; 5959 switch (direction) { 5960 case "forward": 5961 result = string.indexOf("\n", position); 5962 break; 5963 case "backward": 5964 result = string.slice(0, position).lastIndexOf("\n"); 5965 } 5966 if (result !== -1) { 5967 return result; 5968 } 5969 } 5970 contentsForInspection() { 5971 return { 5972 text: this.text.inspect(), 5973 attributes: this.attributes 5974 }; 5975 } 5976 toString() { 5977 return this.text.toString(); 5978 } 5979 toJSON() { 5980 return { 5981 text: this.text, 5982 attributes: this.attributes, 5983 htmlAttributes: this.htmlAttributes 5984 }; 5985 } 5986 5987 // BIDI 5988 5989 getDirection() { 5990 return this.text.getDirection(); 5991 } 5992 isRTL() { 5993 return this.text.isRTL(); 5994 } 5995 5996 // Splittable 5997 5998 getLength() { 5999 return this.text.getLength(); 6000 } 6001 canBeConsolidatedWith(block) { 6002 return !this.hasAttributes() && !block.hasAttributes() && this.getDirection() === block.getDirection(); 6003 } 6004 consolidateWith(block) { 6005 const newlineText = Text.textForStringWithAttributes("\n"); 6006 const text = this.getTextWithoutBlockBreak().appendText(newlineText); 6007 return this.copyWithText(text.appendText(block.text)); 6008 } 6009 splitAtOffset(offset) { 6010 let left, right; 6011 if (offset === 0) { 6012 left = null; 6013 right = this; 6014 } else if (offset === this.getLength()) { 6015 left = this; 6016 right = null; 6017 } else { 6018 left = this.copyWithText(this.text.getTextAtRange([0, offset])); 6019 right = this.copyWithText(this.text.getTextAtRange([offset, this.getLength()])); 6020 } 6021 return [left, right]; 6022 } 6023 getBlockBreakPosition() { 6024 return this.text.getLength() - 1; 6025 } 6026 getTextWithoutBlockBreak() { 6027 if (textEndsInBlockBreak(this.text)) { 6028 return this.text.getTextAtRange([0, this.getBlockBreakPosition()]); 6029 } else { 6030 return this.text.copy(); 6031 } 6032 } 6033 6034 // Grouping 6035 6036 canBeGrouped(depth) { 6037 return this.attributes[depth]; 6038 } 6039 canBeGroupedWith(otherBlock, depth) { 6040 const otherAttributes = otherBlock.getAttributes(); 6041 const otherAttribute = otherAttributes[depth]; 6042 const attribute = this.attributes[depth]; 6043 return attribute === otherAttribute && !(getBlockConfig(attribute).group === false && !getListAttributeNames().includes(otherAttributes[depth + 1])) && (this.getDirection() === otherBlock.getDirection() || otherBlock.isEmpty()); 6044 } 6045 } 6046 6047 // Block breaks 6048 6049 const applyBlockBreakToText = function (text) { 6050 text = unmarkExistingInnerBlockBreaksInText(text); 6051 text = addBlockBreakToText(text); 6052 return text; 6053 }; 6054 const unmarkExistingInnerBlockBreaksInText = function (text) { 6055 let modified = false; 6056 const pieces = text.getPieces(); 6057 let innerPieces = pieces.slice(0, pieces.length - 1); 6058 const lastPiece = pieces[pieces.length - 1]; 6059 if (!lastPiece) return text; 6060 innerPieces = innerPieces.map(piece => { 6061 if (piece.isBlockBreak()) { 6062 modified = true; 6063 return unmarkBlockBreakPiece(piece); 6064 } else { 6065 return piece; 6066 } 6067 }); 6068 if (modified) { 6069 return new Text([...innerPieces, lastPiece]); 6070 } else { 6071 return text; 6072 } 6073 }; 6074 const blockBreakText = Text.textForStringWithAttributes("\n", { 6075 blockBreak: true 6076 }); 6077 const addBlockBreakToText = function (text) { 6078 if (textEndsInBlockBreak(text)) { 6079 return text; 6080 } else { 6081 return text.appendText(blockBreakText); 6082 } 6083 }; 6084 const textEndsInBlockBreak = function (text) { 6085 const length = text.getLength(); 6086 if (length === 0) { 6087 return false; 6088 } 6089 const endText = text.getTextAtRange([length - 1, length]); 6090 return endText.isBlockBreak(); 6091 }; 6092 const unmarkBlockBreakPiece = piece => piece.copyWithoutAttribute("blockBreak"); 6093 6094 // Attributes 6095 6096 const expandAttribute = function (attribute) { 6097 const { 6098 listAttribute 6099 } = getBlockConfig(attribute); 6100 if (listAttribute) { 6101 return [listAttribute, attribute]; 6102 } else { 6103 return [attribute]; 6104 } 6105 }; 6106 6107 // Array helpers 6108 6109 const getLastElement = array => array.slice(-1)[0]; 6110 const removeLastValue = function (array, value) { 6111 const index = array.lastIndexOf(value); 6112 if (index === -1) { 6113 return array; 6114 } else { 6115 return spliceArray(array, index, 1); 6116 } 6117 }; 6118 6119 class Document extends TrixObject { 6120 static fromJSON(documentJSON) { 6121 const blocks = Array.from(documentJSON).map(blockJSON => Block.fromJSON(blockJSON)); 6122 return new this(blocks); 6123 } 6124 static fromString(string, textAttributes) { 6125 const text = Text.textForStringWithAttributes(string, textAttributes); 6126 return new this([new Block(text)]); 6127 } 6128 constructor() { 6129 let blocks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; 6130 super(...arguments); 6131 if (blocks.length === 0) { 6132 blocks = [new Block()]; 6133 } 6134 this.blockList = SplittableList.box(blocks); 6135 } 6136 isEmpty() { 6137 const block = this.getBlockAtIndex(0); 6138 return this.blockList.length === 1 && block.isEmpty() && !block.hasAttributes(); 6139 } 6140 copy() { 6141 let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; 6142 const blocks = options.consolidateBlocks ? this.blockList.consolidate().toArray() : this.blockList.toArray(); 6143 return new this.constructor(blocks); 6144 } 6145 copyUsingObjectsFromDocument(sourceDocument) { 6146 const objectMap = new ObjectMap(sourceDocument.getObjects()); 6147 return this.copyUsingObjectMap(objectMap); 6148 } 6149 copyUsingObjectMap(objectMap) { 6150 const blocks = this.getBlocks().map(block => { 6151 const mappedBlock = objectMap.find(block); 6152 return mappedBlock || block.copyUsingObjectMap(objectMap); 6153 }); 6154 return new this.constructor(blocks); 6155 } 6156 copyWithBaseBlockAttributes() { 6157 let blockAttributes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; 6158 const blocks = this.getBlocks().map(block => { 6159 const attributes = blockAttributes.concat(block.getAttributes()); 6160 return block.copyWithAttributes(attributes); 6161 }); 6162 return new this.constructor(blocks); 6163 } 6164 replaceBlock(oldBlock, newBlock) { 6165 const index = this.blockList.indexOf(oldBlock); 6166 if (index === -1) { 6167 return this; 6168 } 6169 return new this.constructor(this.blockList.replaceObjectAtIndex(newBlock, index)); 6170 } 6171 insertDocumentAtRange(document, range) { 6172 const { 6173 blockList 6174 } = document; 6175 range = normalizeRange(range); 6176 let [position] = range; 6177 const { 6178 index, 6179 offset 6180 } = this.locationFromPosition(position); 6181 let result = this; 6182 const block = this.getBlockAtPosition(position); 6183 if (rangeIsCollapsed(range) && block.isEmpty() && !block.hasAttributes()) { 6184 result = new this.constructor(result.blockList.removeObjectAtIndex(index)); 6185 } else if (block.getBlockBreakPosition() === offset) { 6186 position++; 6187 } 6188 result = result.removeTextAtRange(range); 6189 return new this.constructor(result.blockList.insertSplittableListAtPosition(blockList, position)); 6190 } 6191 mergeDocumentAtRange(document, range) { 6192 let formattedDocument, result; 6193 range = normalizeRange(range); 6194 const [startPosition] = range; 6195 const startLocation = this.locationFromPosition(startPosition); 6196 const blockAttributes = this.getBlockAtIndex(startLocation.index).getAttributes(); 6197 const baseBlockAttributes = document.getBaseBlockAttributes(); 6198 const trailingBlockAttributes = blockAttributes.slice(-baseBlockAttributes.length); 6199 if (arraysAreEqual(baseBlockAttributes, trailingBlockAttributes)) { 6200 const leadingBlockAttributes = blockAttributes.slice(0, -baseBlockAttributes.length); 6201 formattedDocument = document.copyWithBaseBlockAttributes(leadingBlockAttributes); 6202 } else { 6203 formattedDocument = document.copy({ 6204 consolidateBlocks: true 6205 }).copyWithBaseBlockAttributes(blockAttributes); 6206 } 6207 const blockCount = formattedDocument.getBlockCount(); 6208 const firstBlock = formattedDocument.getBlockAtIndex(0); 6209 if (arraysAreEqual(blockAttributes, firstBlock.getAttributes())) { 6210 const firstText = firstBlock.getTextWithoutBlockBreak(); 6211 result = this.insertTextAtRange(firstText, range); 6212 if (blockCount > 1) { 6213 formattedDocument = new this.constructor(formattedDocument.getBlocks().slice(1)); 6214 const position = startPosition + firstText.getLength(); 6215 result = result.insertDocumentAtRange(formattedDocument, position); 6216 } 6217 } else { 6218 result = this.insertDocumentAtRange(formattedDocument, range); 6219 } 6220 return result; 6221 } 6222 insertTextAtRange(text, range) { 6223 range = normalizeRange(range); 6224 const [startPosition] = range; 6225 const { 6226 index, 6227 offset 6228 } = this.locationFromPosition(startPosition); 6229 const document = this.removeTextAtRange(range); 6230 return new this.constructor(document.blockList.editObjectAtIndex(index, block => block.copyWithText(block.text.insertTextAtPosition(text, offset)))); 6231 } 6232 removeTextAtRange(range) { 6233 let blocks; 6234 range = normalizeRange(range); 6235 const [leftPosition, rightPosition] = range; 6236 if (rangeIsCollapsed(range)) { 6237 return this; 6238 } 6239 const [leftLocation, rightLocation] = Array.from(this.locationRangeFromRange(range)); 6240 const leftIndex = leftLocation.index; 6241 const leftOffset = leftLocation.offset; 6242 const leftBlock = this.getBlockAtIndex(leftIndex); 6243 const rightIndex = rightLocation.index; 6244 const rightOffset = rightLocation.offset; 6245 const rightBlock = this.getBlockAtIndex(rightIndex); 6246 const removeRightNewline = rightPosition - leftPosition === 1 && leftBlock.getBlockBreakPosition() === leftOffset && rightBlock.getBlockBreakPosition() !== rightOffset && rightBlock.text.getStringAtPosition(rightOffset) === "\n"; 6247 if (removeRightNewline) { 6248 blocks = this.blockList.editObjectAtIndex(rightIndex, block => block.copyWithText(block.text.removeTextAtRange([rightOffset, rightOffset + 1]))); 6249 } else { 6250 let block; 6251 const leftText = leftBlock.text.getTextAtRange([0, leftOffset]); 6252 const rightText = rightBlock.text.getTextAtRange([rightOffset, rightBlock.getLength()]); 6253 const text = leftText.appendText(rightText); 6254 const removingLeftBlock = leftIndex !== rightIndex && leftOffset === 0; 6255 const useRightBlock = removingLeftBlock && leftBlock.getAttributeLevel() >= rightBlock.getAttributeLevel(); 6256 if (useRightBlock) { 6257 block = rightBlock.copyWithText(text); 6258 } else { 6259 block = leftBlock.copyWithText(text); 6260 } 6261 const affectedBlockCount = rightIndex + 1 - leftIndex; 6262 blocks = this.blockList.splice(leftIndex, affectedBlockCount, block); 6263 } 6264 return new this.constructor(blocks); 6265 } 6266 moveTextFromRangeToPosition(range, position) { 6267 let text; 6268 range = normalizeRange(range); 6269 const [startPosition, endPosition] = range; 6270 if (startPosition <= position && position <= endPosition) { 6271 return this; 6272 } 6273 let document = this.getDocumentAtRange(range); 6274 let result = this.removeTextAtRange(range); 6275 const movingRightward = startPosition < position; 6276 if (movingRightward) { 6277 position -= document.getLength(); 6278 } 6279 const [firstBlock, ...blocks] = document.getBlocks(); 6280 if (blocks.length === 0) { 6281 text = firstBlock.getTextWithoutBlockBreak(); 6282 if (movingRightward) { 6283 position += 1; 6284 } 6285 } else { 6286 text = firstBlock.text; 6287 } 6288 result = result.insertTextAtRange(text, position); 6289 if (blocks.length === 0) { 6290 return result; 6291 } 6292 document = new this.constructor(blocks); 6293 position += text.getLength(); 6294 return result.insertDocumentAtRange(document, position); 6295 } 6296 addAttributeAtRange(attribute, value, range) { 6297 let { 6298 blockList 6299 } = this; 6300 this.eachBlockAtRange(range, (block, textRange, index) => blockList = blockList.editObjectAtIndex(index, function () { 6301 if (getBlockConfig(attribute)) { 6302 return block.addAttribute(attribute, value); 6303 } else { 6304 if (textRange[0] === textRange[1]) { 6305 return block; 6306 } else { 6307 return block.copyWithText(block.text.addAttributeAtRange(attribute, value, textRange)); 6308 } 6309 } 6310 })); 6311 return new this.constructor(blockList); 6312 } 6313 addAttribute(attribute, value) { 6314 let { 6315 blockList 6316 } = this; 6317 this.eachBlock((block, index) => blockList = blockList.editObjectAtIndex(index, () => block.addAttribute(attribute, value))); 6318 return new this.constructor(blockList); 6319 } 6320 removeAttributeAtRange(attribute, range) { 6321 let { 6322 blockList 6323 } = this; 6324 this.eachBlockAtRange(range, function (block, textRange, index) { 6325 if (getBlockConfig(attribute)) { 6326 blockList = blockList.editObjectAtIndex(index, () => block.removeAttribute(attribute)); 6327 } else if (textRange[0] !== textRange[1]) { 6328 blockList = blockList.editObjectAtIndex(index, () => block.copyWithText(block.text.removeAttributeAtRange(attribute, textRange))); 6329 } 6330 }); 6331 return new this.constructor(blockList); 6332 } 6333 updateAttributesForAttachment(attributes, attachment) { 6334 const range = this.getRangeOfAttachment(attachment); 6335 const [startPosition] = Array.from(range); 6336 const { 6337 index 6338 } = this.locationFromPosition(startPosition); 6339 const text = this.getTextAtIndex(index); 6340 return new this.constructor(this.blockList.editObjectAtIndex(index, block => block.copyWithText(text.updateAttributesForAttachment(attributes, attachment)))); 6341 } 6342 removeAttributeForAttachment(attribute, attachment) { 6343 const range = this.getRangeOfAttachment(attachment); 6344 return this.removeAttributeAtRange(attribute, range); 6345 } 6346 setHTMLAttributeAtPosition(position, name, value) { 6347 const block = this.getBlockAtPosition(position); 6348 const updatedBlock = block.addHTMLAttribute(name, value); 6349 return this.replaceBlock(block, updatedBlock); 6350 } 6351 insertBlockBreakAtRange(range) { 6352 let blocks; 6353 range = normalizeRange(range); 6354 const [startPosition] = range; 6355 const { 6356 offset 6357 } = this.locationFromPosition(startPosition); 6358 const document = this.removeTextAtRange(range); 6359 if (offset === 0) { 6360 blocks = [new Block()]; 6361 } 6362 return new this.constructor(document.blockList.insertSplittableListAtPosition(new SplittableList(blocks), startPosition)); 6363 } 6364 applyBlockAttributeAtRange(attributeName, value, range) { 6365 const expanded = this.expandRangeToLineBreaksAndSplitBlocks(range); 6366 let document = expanded.document; 6367 range = expanded.range; 6368 const blockConfig = getBlockConfig(attributeName); 6369 if (blockConfig.listAttribute) { 6370 document = document.removeLastListAttributeAtRange(range, { 6371 exceptAttributeName: attributeName 6372 }); 6373 const converted = document.convertLineBreaksToBlockBreaksInRange(range); 6374 document = converted.document; 6375 range = converted.range; 6376 } else if (blockConfig.exclusive) { 6377 document = document.removeBlockAttributesAtRange(range); 6378 } else if (blockConfig.terminal) { 6379 document = document.removeLastTerminalAttributeAtRange(range); 6380 } else { 6381 document = document.consolidateBlocksAtRange(range); 6382 } 6383 return document.addAttributeAtRange(attributeName, value, range); 6384 } 6385 removeLastListAttributeAtRange(range) { 6386 let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 6387 let { 6388 blockList 6389 } = this; 6390 this.eachBlockAtRange(range, function (block, textRange, index) { 6391 const lastAttributeName = block.getLastAttribute(); 6392 if (!lastAttributeName) { 6393 return; 6394 } 6395 if (!getBlockConfig(lastAttributeName).listAttribute) { 6396 return; 6397 } 6398 if (lastAttributeName === options.exceptAttributeName) { 6399 return; 6400 } 6401 blockList = blockList.editObjectAtIndex(index, () => block.removeAttribute(lastAttributeName)); 6402 }); 6403 return new this.constructor(blockList); 6404 } 6405 removeLastTerminalAttributeAtRange(range) { 6406 let { 6407 blockList 6408 } = this; 6409 this.eachBlockAtRange(range, function (block, textRange, index) { 6410 const lastAttributeName = block.getLastAttribute(); 6411 if (!lastAttributeName) { 6412 return; 6413 } 6414 if (!getBlockConfig(lastAttributeName).terminal) { 6415 return; 6416 } 6417 blockList = blockList.editObjectAtIndex(index, () => block.removeAttribute(lastAttributeName)); 6418 }); 6419 return new this.constructor(blockList); 6420 } 6421 removeBlockAttributesAtRange(range) { 6422 let { 6423 blockList 6424 } = this; 6425 this.eachBlockAtRange(range, function (block, textRange, index) { 6426 if (block.hasAttributes()) { 6427 blockList = blockList.editObjectAtIndex(index, () => block.copyWithoutAttributes()); 6428 } 6429 }); 6430 return new this.constructor(blockList); 6431 } 6432 expandRangeToLineBreaksAndSplitBlocks(range) { 6433 let position; 6434 range = normalizeRange(range); 6435 let [startPosition, endPosition] = range; 6436 const startLocation = this.locationFromPosition(startPosition); 6437 const endLocation = this.locationFromPosition(endPosition); 6438 let document = this; 6439 const startBlock = document.getBlockAtIndex(startLocation.index); 6440 startLocation.offset = startBlock.findLineBreakInDirectionFromPosition("backward", startLocation.offset); 6441 if (startLocation.offset != null) { 6442 position = document.positionFromLocation(startLocation); 6443 document = document.insertBlockBreakAtRange([position, position + 1]); 6444 endLocation.index += 1; 6445 endLocation.offset -= document.getBlockAtIndex(startLocation.index).getLength(); 6446 startLocation.index += 1; 6447 } 6448 startLocation.offset = 0; 6449 if (endLocation.offset === 0 && endLocation.index > startLocation.index) { 6450 endLocation.index -= 1; 6451 endLocation.offset = document.getBlockAtIndex(endLocation.index).getBlockBreakPosition(); 6452 } else { 6453 const endBlock = document.getBlockAtIndex(endLocation.index); 6454 if (endBlock.text.getStringAtRange([endLocation.offset - 1, endLocation.offset]) === "\n") { 6455 endLocation.offset -= 1; 6456 } else { 6457 endLocation.offset = endBlock.findLineBreakInDirectionFromPosition("forward", endLocation.offset); 6458 } 6459 if (endLocation.offset !== endBlock.getBlockBreakPosition()) { 6460 position = document.positionFromLocation(endLocation); 6461 document = document.insertBlockBreakAtRange([position, position + 1]); 6462 } 6463 } 6464 startPosition = document.positionFromLocation(startLocation); 6465 endPosition = document.positionFromLocation(endLocation); 6466 range = normalizeRange([startPosition, endPosition]); 6467 return { 6468 document, 6469 range 6470 }; 6471 } 6472 convertLineBreaksToBlockBreaksInRange(range) { 6473 range = normalizeRange(range); 6474 let [position] = range; 6475 const string = this.getStringAtRange(range).slice(0, -1); 6476 let document = this; 6477 string.replace(/.*?\n/g, function (match) { 6478 position += match.length; 6479 document = document.insertBlockBreakAtRange([position - 1, position]); 6480 }); 6481 return { 6482 document, 6483 range 6484 }; 6485 } 6486 consolidateBlocksAtRange(range) { 6487 range = normalizeRange(range); 6488 const [startPosition, endPosition] = range; 6489 const startIndex = this.locationFromPosition(startPosition).index; 6490 const endIndex = this.locationFromPosition(endPosition).index; 6491 return new this.constructor(this.blockList.consolidateFromIndexToIndex(startIndex, endIndex)); 6492 } 6493 getDocumentAtRange(range) { 6494 range = normalizeRange(range); 6495 const blocks = this.blockList.getSplittableListInRange(range).toArray(); 6496 return new this.constructor(blocks); 6497 } 6498 getStringAtRange(range) { 6499 let endIndex; 6500 const array = range = normalizeRange(range), 6501 endPosition = array[array.length - 1]; 6502 if (endPosition !== this.getLength()) { 6503 endIndex = -1; 6504 } 6505 return this.getDocumentAtRange(range).toString().slice(0, endIndex); 6506 } 6507 getBlockAtIndex(index) { 6508 return this.blockList.getObjectAtIndex(index); 6509 } 6510 getBlockAtPosition(position) { 6511 const { 6512 index 6513 } = this.locationFromPosition(position); 6514 return this.getBlockAtIndex(index); 6515 } 6516 getTextAtIndex(index) { 6517 var _this$getBlockAtIndex; 6518 return (_this$getBlockAtIndex = this.getBlockAtIndex(index)) === null || _this$getBlockAtIndex === void 0 ? void 0 : _this$getBlockAtIndex.text; 6519 } 6520 getTextAtPosition(position) { 6521 const { 6522 index 6523 } = this.locationFromPosition(position); 6524 return this.getTextAtIndex(index); 6525 } 6526 getPieceAtPosition(position) { 6527 const { 6528 index, 6529 offset 6530 } = this.locationFromPosition(position); 6531 return this.getTextAtIndex(index).getPieceAtPosition(offset); 6532 } 6533 getCharacterAtPosition(position) { 6534 const { 6535 index, 6536 offset 6537 } = this.locationFromPosition(position); 6538 return this.getTextAtIndex(index).getStringAtRange([offset, offset + 1]); 6539 } 6540 getLength() { 6541 return this.blockList.getEndPosition(); 6542 } 6543 getBlocks() { 6544 return this.blockList.toArray(); 6545 } 6546 getBlockCount() { 6547 return this.blockList.length; 6548 } 6549 getEditCount() { 6550 return this.editCount; 6551 } 6552 eachBlock(callback) { 6553 return this.blockList.eachObject(callback); 6554 } 6555 eachBlockAtRange(range, callback) { 6556 let block, textRange; 6557 range = normalizeRange(range); 6558 const [startPosition, endPosition] = range; 6559 const startLocation = this.locationFromPosition(startPosition); 6560 const endLocation = this.locationFromPosition(endPosition); 6561 if (startLocation.index === endLocation.index) { 6562 block = this.getBlockAtIndex(startLocation.index); 6563 textRange = [startLocation.offset, endLocation.offset]; 6564 return callback(block, textRange, startLocation.index); 6565 } else { 6566 for (let index = startLocation.index; index <= endLocation.index; index++) { 6567 block = this.getBlockAtIndex(index); 6568 if (block) { 6569 switch (index) { 6570 case startLocation.index: 6571 textRange = [startLocation.offset, block.text.getLength()]; 6572 break; 6573 case endLocation.index: 6574 textRange = [0, endLocation.offset]; 6575 break; 6576 default: 6577 textRange = [0, block.text.getLength()]; 6578 } 6579 callback(block, textRange, index); 6580 } 6581 } 6582 } 6583 } 6584 getCommonAttributesAtRange(range) { 6585 range = normalizeRange(range); 6586 const [startPosition] = range; 6587 if (rangeIsCollapsed(range)) { 6588 return this.getCommonAttributesAtPosition(startPosition); 6589 } else { 6590 const textAttributes = []; 6591 const blockAttributes = []; 6592 this.eachBlockAtRange(range, function (block, textRange) { 6593 if (textRange[0] !== textRange[1]) { 6594 textAttributes.push(block.text.getCommonAttributesAtRange(textRange)); 6595 return blockAttributes.push(attributesForBlock(block)); 6596 } 6597 }); 6598 return Hash.fromCommonAttributesOfObjects(textAttributes).merge(Hash.fromCommonAttributesOfObjects(blockAttributes)).toObject(); 6599 } 6600 } 6601 getCommonAttributesAtPosition(position) { 6602 let key, value; 6603 const { 6604 index, 6605 offset 6606 } = this.locationFromPosition(position); 6607 const block = this.getBlockAtIndex(index); 6608 if (!block) { 6609 return {}; 6610 } 6611 const commonAttributes = attributesForBlock(block); 6612 const attributes = block.text.getAttributesAtPosition(offset); 6613 const attributesLeft = block.text.getAttributesAtPosition(offset - 1); 6614 const inheritableAttributes = Object.keys(text_attributes).filter(key => { 6615 return text_attributes[key].inheritable; 6616 }); 6617 for (key in attributesLeft) { 6618 value = attributesLeft[key]; 6619 if (value === attributes[key] || inheritableAttributes.includes(key)) { 6620 commonAttributes[key] = value; 6621 } 6622 } 6623 return commonAttributes; 6624 } 6625 getRangeOfCommonAttributeAtPosition(attributeName, position) { 6626 const { 6627 index, 6628 offset 6629 } = this.locationFromPosition(position); 6630 const text = this.getTextAtIndex(index); 6631 const [startOffset, endOffset] = Array.from(text.getExpandedRangeForAttributeAtOffset(attributeName, offset)); 6632 const start = this.positionFromLocation({ 6633 index, 6634 offset: startOffset 6635 }); 6636 const end = this.positionFromLocation({ 6637 index, 6638 offset: endOffset 6639 }); 6640 return normalizeRange([start, end]); 6641 } 6642 getBaseBlockAttributes() { 6643 let baseBlockAttributes = this.getBlockAtIndex(0).getAttributes(); 6644 for (let blockIndex = 1; blockIndex < this.getBlockCount(); blockIndex++) { 6645 const blockAttributes = this.getBlockAtIndex(blockIndex).getAttributes(); 6646 const lastAttributeIndex = Math.min(baseBlockAttributes.length, blockAttributes.length); 6647 baseBlockAttributes = (() => { 6648 const result = []; 6649 for (let index = 0; index < lastAttributeIndex; index++) { 6650 if (blockAttributes[index] !== baseBlockAttributes[index]) { 6651 break; 6652 } 6653 result.push(blockAttributes[index]); 6654 } 6655 return result; 6656 })(); 6657 } 6658 return baseBlockAttributes; 6659 } 6660 getAttachmentById(attachmentId) { 6661 for (const attachment of this.getAttachments()) { 6662 if (attachment.id === attachmentId) { 6663 return attachment; 6664 } 6665 } 6666 } 6667 getAttachmentPieces() { 6668 let attachmentPieces = []; 6669 this.blockList.eachObject(_ref => { 6670 let { 6671 text 6672 } = _ref; 6673 return attachmentPieces = attachmentPieces.concat(text.getAttachmentPieces()); 6674 }); 6675 return attachmentPieces; 6676 } 6677 getAttachments() { 6678 return this.getAttachmentPieces().map(piece => piece.attachment); 6679 } 6680 getRangeOfAttachment(attachment) { 6681 let position = 0; 6682 const iterable = this.blockList.toArray(); 6683 for (let index = 0; index < iterable.length; index++) { 6684 const { 6685 text 6686 } = iterable[index]; 6687 const textRange = text.getRangeOfAttachment(attachment); 6688 if (textRange) { 6689 return normalizeRange([position + textRange[0], position + textRange[1]]); 6690 } 6691 position += text.getLength(); 6692 } 6693 } 6694 getLocationRangeOfAttachment(attachment) { 6695 const range = this.getRangeOfAttachment(attachment); 6696 return this.locationRangeFromRange(range); 6697 } 6698 getAttachmentPieceForAttachment(attachment) { 6699 for (const piece of this.getAttachmentPieces()) { 6700 if (piece.attachment === attachment) { 6701 return piece; 6702 } 6703 } 6704 } 6705 findRangesForBlockAttribute(attributeName) { 6706 let position = 0; 6707 const ranges = []; 6708 this.getBlocks().forEach(block => { 6709 const length = block.getLength(); 6710 if (block.hasAttribute(attributeName)) { 6711 ranges.push([position, position + length]); 6712 } 6713 position += length; 6714 }); 6715 return ranges; 6716 } 6717 findRangesForTextAttribute(attributeName) { 6718 let { 6719 withValue 6720 } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 6721 let position = 0; 6722 let range = []; 6723 const ranges = []; 6724 const match = function (piece) { 6725 if (withValue) { 6726 return piece.getAttribute(attributeName) === withValue; 6727 } else { 6728 return piece.hasAttribute(attributeName); 6729 } 6730 }; 6731 this.getPieces().forEach(piece => { 6732 const length = piece.getLength(); 6733 if (match(piece)) { 6734 if (range[1] === position) { 6735 range[1] = position + length; 6736 } else { 6737 ranges.push(range = [position, position + length]); 6738 } 6739 } 6740 position += length; 6741 }); 6742 return ranges; 6743 } 6744 locationFromPosition(position) { 6745 const location = this.blockList.findIndexAndOffsetAtPosition(Math.max(0, position)); 6746 if (location.index != null) { 6747 return location; 6748 } else { 6749 const blocks = this.getBlocks(); 6750 return { 6751 index: blocks.length - 1, 6752 offset: blocks[blocks.length - 1].getLength() 6753 }; 6754 } 6755 } 6756 positionFromLocation(location) { 6757 return this.blockList.findPositionAtIndexAndOffset(location.index, location.offset); 6758 } 6759 locationRangeFromPosition(position) { 6760 return normalizeRange(this.locationFromPosition(position)); 6761 } 6762 locationRangeFromRange(range) { 6763 range = normalizeRange(range); 6764 if (!range) return; 6765 const [startPosition, endPosition] = Array.from(range); 6766 const startLocation = this.locationFromPosition(startPosition); 6767 const endLocation = this.locationFromPosition(endPosition); 6768 return normalizeRange([startLocation, endLocation]); 6769 } 6770 rangeFromLocationRange(locationRange) { 6771 let rightPosition; 6772 locationRange = normalizeRange(locationRange); 6773 const leftPosition = this.positionFromLocation(locationRange[0]); 6774 if (!rangeIsCollapsed(locationRange)) { 6775 rightPosition = this.positionFromLocation(locationRange[1]); 6776 } 6777 return normalizeRange([leftPosition, rightPosition]); 6778 } 6779 isEqualTo(document) { 6780 return this.blockList.isEqualTo(document === null || document === void 0 ? void 0 : document.blockList); 6781 } 6782 getTexts() { 6783 return this.getBlocks().map(block => block.text); 6784 } 6785 getPieces() { 6786 const pieces = []; 6787 Array.from(this.getTexts()).forEach(text => { 6788 pieces.push(...Array.from(text.getPieces() || [])); 6789 }); 6790 return pieces; 6791 } 6792 getObjects() { 6793 return this.getBlocks().concat(this.getTexts()).concat(this.getPieces()); 6794 } 6795 toSerializableDocument() { 6796 const blocks = []; 6797 this.blockList.eachObject(block => blocks.push(block.copyWithText(block.text.toSerializableText()))); 6798 return new this.constructor(blocks); 6799 } 6800 toString() { 6801 return this.blockList.toString(); 6802 } 6803 toJSON() { 6804 return this.blockList.toJSON(); 6805 } 6806 toConsole() { 6807 return JSON.stringify(this.blockList.toArray().map(block => JSON.parse(block.text.toConsole()))); 6808 } 6809 } 6810 const attributesForBlock = function (block) { 6811 const attributes = {}; 6812 const attributeName = block.getLastAttribute(); 6813 if (attributeName) { 6814 attributes[attributeName] = true; 6815 } 6816 return attributes; 6817 }; 6818 6819
vendor: 1,043 bytes, lines 6819-6842
6819const DEFAULT_ALLOWED_ATTRIBUTES = "style href src width height language class".split(" "); 6820 const DEFAULT_FORBIDDEN_PROTOCOLS = "javascript:".split(" "); 6821 const DEFAULT_FORBIDDEN_ELEMENTS = "script iframe form noscript".split(" "); 6822 class HTMLSanitizer extends BasicObject { 6823 static sanitize(html, options) { 6824 const sanitizer = new this(html, options); 6825 sanitizer.sanitize(); 6826 return sanitizer; 6827 } 6828 constructor(html) { 6829 let { 6830 allowedAttributes, 6831 forbiddenProtocols, 6832 forbiddenElements 6833 } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 6834 super(...arguments); 6835 this.allowedAttributes = allowedAttributes || DEFAULT_ALLOWED_ATTRIBUTES; 6836 this.forbiddenProtocols = forbiddenProtocols || DEFAULT_FORBIDDEN_PROTOCOLS; 6837 this.forbiddenElements = forbiddenElements || DEFAULT_FORBIDDEN_ELEMENTS; 6838 this.body = createBodyElementForHTML(html); 6839 } 6840 sanitize() { 6841 this.sanitizeElements(); 6842 return this.normalizeListElementNesting()
vendor: 2,592 bytes, lines 6842-6924
6842; 6843 } 6844 getHTML() { 6845 return this.body.innerHTML; 6846 } 6847 getBody() { 6848 return this.body; 6849 } 6850 6851 // Private 6852 6853 sanitizeElements() { 6854 const walker = walkTree(this.body); 6855 const nodesToRemove = []; 6856 while (walker.nextNode()) { 6857 const node = walker.currentNode; 6858 switch (node.nodeType) { 6859 case Node.ELEMENT_NODE: 6860 if (this.elementIsRemovable(node)) { 6861 nodesToRemove.push(node); 6862 } else { 6863 this.sanitizeElement(node); 6864 } 6865 break; 6866 case Node.COMMENT_NODE: 6867 nodesToRemove.push(node); 6868 break; 6869 } 6870 } 6871 nodesToRemove.forEach(node => removeNode(node)); 6872 return this.body; 6873 } 6874 sanitizeElement(element) { 6875 if (element.hasAttribute("href")) { 6876 if (this.forbiddenProtocols.includes(element.protocol)) { 6877 element.removeAttribute("href"); 6878 } 6879 } 6880 Array.from(element.attributes).forEach(_ref => { 6881 let { 6882 name 6883 } = _ref; 6884 if (!this.allowedAttributes.includes(name) && name.indexOf("data-trix") !== 0) { 6885 element.removeAttribute(name); 6886 } 6887 }); 6888 return element; 6889 } 6890 normalizeListElementNesting() { 6891 Array.from(this.body.querySelectorAll("ul,ol")).forEach(listElement => { 6892 const previousElement = listElement.previousElementSibling; 6893 if (previousElement) { 6894 if (tagName(previousElement) === "li") { 6895 previousElement.appendChild(listElement); 6896 } 6897 } 6898 }); 6899 return this.body; 6900 } 6901 elementIsRemovable(element) { 6902 if ((element === null || element === void 0 ? void 0 : element.nodeType) !== Node.ELEMENT_NODE) return; 6903 return this.elementIsForbidden(element) || this.elementIsntSerializable(element); 6904 } 6905 elementIsForbidden(element) { 6906 return this.forbiddenElements.includes(tagName(element)); 6907 } 6908 elementIsntSerializable(element) { 6909 return element.getAttribute("data-trix-serialize") === "false" && !nodeIsAttachmentElement(element); 6910 } 6911 } 6912 const createBodyElementForHTML = function () { 6913 let html = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ""; 6914 // Remove everything after </html> 6915 html = html.replace(/<\/html[^>]*>[^]*$/i, "</html>"); 6916 const doc = document.implementation.createHTMLDocument(""); 6917 doc.documentElement.innerHTML = html; 6918 Array.from(doc.head.querySelectorAll("style")).forEach(element => { 6919 doc.body.appendChild(element); 6920 }); 6921 return doc.body; 6922 }; 6923 6924
6924/* eslint-disable 6925 no-case-declarations, 6926 no-irregular-whitespace, 6927 */ 6928 const pieceForString = function (string) { 6929 let attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 6930 const type = "string"; 6931 string = normalizeSpaces(string); 6932 return { 6933 string, 6934 attributes, 6935 type 6936 }; 6937 }; 6938 const pieceForAttachment = function (attachment) { 6939 let attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 6940 const type = "attachment"; 6941 return { 6942 attachment, 6943 attributes, 6944 type 6945 }; 6946 }; 6947 const blockForAttributes = function () { 6948 let attributes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; 6949 let htmlAttributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 6950 const text = []; 6951 return { 6952 text, 6953 attributes, 6954 htmlAttributes 6955 }; 6956 }; 6957 const parseTrixDataAttribute = (element, name) => { 6958 try { 6959 const data = JSON.parse(element.getAttribute("data-trix-".concat(name))); 6960 if (data.contentType === "text/html" && data.content) { 6961 data.content = HTMLSanitizer.sanitize(data.content).getHTML(); 6962 } 6963 return data; 6964 } catch (error) { 6965 return {}; 6966 } 6967 }; 6968 const getImageDimensions = element => { 6969 const width = element.getAttribute("width"); 6970 const height = element.getAttribute("height"); 6971 const dimensions = {}; 6972 if (width) { 6973 dimensions.width = parseInt(width, 10); 6974 } 6975 if (height) { 6976 dimensions.height = parseInt(height, 10); 6977 } 6978 return dimensions; 6979 }; 6980 class HTMLParser extends BasicObject { 6981 static parse(html, options) { 6982 const parser = new this(html, options); 6983 parser.parse(); 6984 return parser; 6985 } 6986 constructor(html) { 6987 let { 6988 referenceElement 6989 } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 6990 super(...arguments); 6991 this.html = html; 6992 this.referenceElement = referenceElement; 6993 this.blocks = []; 6994 this.blockElements = []; 6995 this.processedElements = []; 6996 } 6997 getDocument() { 6998 return Document.fromJSON(this.blocks); 6999 } 7000 7001 // HTML parsing 7002 7003 parse() { 7004 try { 7005 this.createHiddenContainer(); 7006 const html = HTMLSanitizer.sanitize(this.html).getHTML(); 7007 this.containerElement.innerHTML = html
vendor: 138,486 bytes, lines 7007-10530
7007; 7008 const walker = walkTree(this.containerElement, { 7009 usingFilter: nodeFilter 7010 }); 7011 while (walker.nextNode()) { 7012 this.processNode(walker.currentNode); 7013 } 7014 return this.translateBlockElementMarginsToNewlines(); 7015 } finally { 7016 this.removeHiddenContainer(); 7017 } 7018 } 7019 createHiddenContainer() { 7020 if (this.referenceElement) { 7021 this.containerElement = this.referenceElement.cloneNode(false); 7022 this.containerElement.removeAttribute("id"); 7023 this.containerElement.setAttribute("data-trix-internal", ""); 7024 this.containerElement.style.display = "none"; 7025 return this.referenceElement.parentNode.insertBefore(this.containerElement, this.referenceElement.nextSibling); 7026 } else { 7027 this.containerElement = makeElement({ 7028 tagName: "div", 7029 style: { 7030 display: "none" 7031 } 7032 }); 7033 return document.body.appendChild(this.containerElement); 7034 } 7035 } 7036 removeHiddenContainer() { 7037 return removeNode(this.containerElement); 7038 } 7039 processNode(node) { 7040 switch (node.nodeType) { 7041 case Node.TEXT_NODE: 7042 if (!this.isInsignificantTextNode(node)) { 7043 this.appendBlockForTextNode(node); 7044 return this.processTextNode(node); 7045 } 7046 break; 7047 case Node.ELEMENT_NODE: 7048 this.appendBlockForElement(node); 7049 return this.processElement(node); 7050 } 7051 } 7052 appendBlockForTextNode(node) { 7053 const element = node.parentNode; 7054 if (element === this.currentBlockElement && this.isBlockElement(node.previousSibling)) { 7055 return this.appendStringWithAttributes("\n"); 7056 } else if (element === this.containerElement || this.isBlockElement(element)) { 7057 var _this$currentBlock; 7058 const attributes = this.getBlockAttributes(element); 7059 const htmlAttributes = this.getBlockHTMLAttributes(element); 7060 if (!arraysAreEqual(attributes, (_this$currentBlock = this.currentBlock) === null || _this$currentBlock === void 0 ? void 0 : _this$currentBlock.attributes)) { 7061 this.currentBlock = this.appendBlockForAttributesWithElement(attributes, element, htmlAttributes); 7062 this.currentBlockElement = element; 7063 } 7064 } 7065 } 7066 appendBlockForElement(element) { 7067 const elementIsBlockElement = this.isBlockElement(element); 7068 const currentBlockContainsElement = elementContainsNode(this.currentBlockElement, element); 7069 if (elementIsBlockElement && !this.isBlockElement(element.firstChild)) { 7070 if (!this.isInsignificantTextNode(element.firstChild) || !this.isBlockElement(element.firstElementChild)) { 7071 const attributes = this.getBlockAttributes(element); 7072 const htmlAttributes = this.getBlockHTMLAttributes(element); 7073 if (element.firstChild) { 7074 if (!(currentBlockContainsElement && arraysAreEqual(attributes, this.currentBlock.attributes))) { 7075 this.currentBlock = this.appendBlockForAttributesWithElement(attributes, element, htmlAttributes); 7076 this.currentBlockElement = element; 7077 } else { 7078 return this.appendStringWithAttributes("\n"); 7079 } 7080 } 7081 } 7082 } else if (this.currentBlockElement && !currentBlockContainsElement && !elementIsBlockElement) { 7083 const parentBlockElement = this.findParentBlockElement(element); 7084 if (parentBlockElement) { 7085 return this.appendBlockForElement(parentBlockElement); 7086 } else { 7087 this.currentBlock = this.appendEmptyBlock(); 7088 this.currentBlockElement = null; 7089 } 7090 } 7091 } 7092 findParentBlockElement(element) { 7093 let { 7094 parentElement 7095 } = element; 7096 while (parentElement && parentElement !== this.containerElement) { 7097 if (this.isBlockElement(parentElement) && this.blockElements.includes(parentElement)) { 7098 return parentElement; 7099 } else { 7100 parentElement = parentElement.parentElement; 7101 } 7102 } 7103 return null; 7104 } 7105 processTextNode(node) { 7106 let string = node.data; 7107 if (!elementCanDisplayPreformattedText(node.parentNode)) { 7108 var _node$previousSibling; 7109 string = squishBreakableWhitespace(string); 7110 if (stringEndsWithWhitespace((_node$previousSibling = node.previousSibling) === null || _node$previousSibling === void 0 ? void 0 : _node$previousSibling.textContent)) { 7111 string = leftTrimBreakableWhitespace(string); 7112 } 7113 } 7114 return this.appendStringWithAttributes(string, this.getTextAttributes(node.parentNode)); 7115 } 7116 processElement(element) { 7117 let attributes; 7118 if (nodeIsAttachmentElement(element)) { 7119 attributes = parseTrixDataAttribute(element, "attachment"); 7120 if (Object.keys(attributes).length) { 7121 const textAttributes = this.getTextAttributes(element); 7122 this.appendAttachmentWithAttributes(attributes, textAttributes); 7123 // We have everything we need so avoid processing inner nodes 7124 element.innerHTML = ""; 7125 } 7126 return this.processedElements.push(element); 7127 } else { 7128 switch (tagName(element)) { 7129 case "br": 7130 if (!this.isExtraBR(element) && !this.isBlockElement(element.nextSibling)) { 7131 this.appendStringWithAttributes("\n", this.getTextAttributes(element)); 7132 } 7133 return this.processedElements.push(element); 7134 case "img": 7135 attributes = { 7136 url: element.getAttribute("src"), 7137 contentType: "image" 7138 }; 7139 const object = getImageDimensions(element); 7140 for (const key in object) { 7141 const value = object[key]; 7142 attributes[key] = value; 7143 } 7144 this.appendAttachmentWithAttributes(attributes, this.getTextAttributes(element)); 7145 return this.processedElements.push(element); 7146 case "tr": 7147 if (this.needsTableSeparator(element)) { 7148 return this.appendStringWithAttributes(parser.tableRowSeparator); 7149 } 7150 break; 7151 case "td": 7152 if (this.needsTableSeparator(element)) { 7153 return this.appendStringWithAttributes(parser.tableCellSeparator); 7154 } 7155 break; 7156 } 7157 } 7158 } 7159 7160 // Document construction 7161 7162 appendBlockForAttributesWithElement(attributes, element) { 7163 let htmlAttributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; 7164 this.blockElements.push(element); 7165 const block = blockForAttributes(attributes, htmlAttributes); 7166 this.blocks.push(block); 7167 return block; 7168 } 7169 appendEmptyBlock() { 7170 return this.appendBlockForAttributesWithElement([], null); 7171 } 7172 appendStringWithAttributes(string, attributes) { 7173 return this.appendPiece(pieceForString(string, attributes)); 7174 } 7175 appendAttachmentWithAttributes(attachment, attributes) { 7176 return this.appendPiece(pieceForAttachment(attachment, attributes)); 7177 } 7178 appendPiece(piece) { 7179 if (this.blocks.length === 0) { 7180 this.appendEmptyBlock(); 7181 } 7182 return this.blocks[this.blocks.length - 1].text.push(piece); 7183 } 7184 appendStringToTextAtIndex(string, index) { 7185 const { 7186 text 7187 } = this.blocks[index]; 7188 const piece = text[text.length - 1]; 7189 if ((piece === null || piece === void 0 ? void 0 : piece.type) === "string") { 7190 piece.string += string; 7191 } else { 7192 return text.push(pieceForString(string)); 7193 } 7194 } 7195 prependStringToTextAtIndex(string, index) { 7196 const { 7197 text 7198 } = this.blocks[index]; 7199 const piece = text[0]; 7200 if ((piece === null || piece === void 0 ? void 0 : piece.type) === "string") { 7201 piece.string = string + piece.string; 7202 } else { 7203 return text.unshift(pieceForString(string)); 7204 } 7205 } 7206 7207 // Attribute parsing 7208 7209 getTextAttributes(element) { 7210 let value; 7211 const attributes = {}; 7212 for (const attribute in text_attributes) { 7213 const configAttr = text_attributes[attribute]; 7214 if (configAttr.tagName && findClosestElementFromNode(element, { 7215 matchingSelector: configAttr.tagName, 7216 untilNode: this.containerElement 7217 })) { 7218 attributes[attribute] = true; 7219 } else if (configAttr.parser) { 7220 value = configAttr.parser(element); 7221 if (value) { 7222 let attributeInheritedFromBlock = false; 7223 for (const blockElement of this.findBlockElementAncestors(element)) { 7224 if (configAttr.parser(blockElement) === value) { 7225 attributeInheritedFromBlock = true; 7226 break; 7227 } 7228 } 7229 if (!attributeInheritedFromBlock) { 7230 attributes[attribute] = value; 7231 } 7232 } 7233 } else if (configAttr.styleProperty) { 7234 value = element.style[configAttr.styleProperty]; 7235 if (value) { 7236 attributes[attribute] = value; 7237 } 7238 } 7239 } 7240 if (nodeIsAttachmentElement(element)) { 7241 const object = parseTrixDataAttribute(element, "attributes"); 7242 for (const key in object) { 7243 value = object[key]; 7244 attributes[key] = value; 7245 } 7246 } 7247 return attributes; 7248 } 7249 getBlockAttributes(element) { 7250 const attributes$1 = []; 7251 while (element && element !== this.containerElement) { 7252 for (const attribute in attributes) { 7253 const attrConfig = attributes[attribute]; 7254 if (attrConfig.parse !== false) { 7255 if (tagName(element) === attrConfig.tagName) { 7256 var _attrConfig$test; 7257 if ((_attrConfig$test = attrConfig.test) !== null && _attrConfig$test !== void 0 && _attrConfig$test.call(attrConfig, element) || !attrConfig.test) { 7258 attributes$1.push(attribute); 7259 if (attrConfig.listAttribute) { 7260 attributes$1.push(attrConfig.listAttribute); 7261 } 7262 } 7263 } 7264 } 7265 } 7266 element = element.parentNode; 7267 } 7268 return attributes$1.reverse(); 7269 } 7270 getBlockHTMLAttributes(element) { 7271 const attributes$1 = {}; 7272 const blockConfig = Object.values(attributes).find(settings => settings.tagName === tagName(element)); 7273 const allowedAttributes = (blockConfig === null || blockConfig === void 0 ? void 0 : blockConfig.htmlAttributes) || []; 7274 allowedAttributes.forEach(attribute => { 7275 if (element.hasAttribute(attribute)) { 7276 attributes$1[attribute] = element.getAttribute(attribute); 7277 } 7278 }); 7279 return attributes$1; 7280 } 7281 findBlockElementAncestors(element) { 7282 const ancestors = []; 7283 while (element && element !== this.containerElement) { 7284 const tag = tagName(element); 7285 if (getBlockTagNames().includes(tag)) { 7286 ancestors.push(element); 7287 } 7288 element = element.parentNode; 7289 } 7290 return ancestors; 7291 } 7292 7293 // Element inspection 7294 7295 isBlockElement(element) { 7296 if ((element === null || element === void 0 ? void 0 : element.nodeType) !== Node.ELEMENT_NODE) return; 7297 if (nodeIsAttachmentElement(element)) return; 7298 if (findClosestElementFromNode(element, { 7299 matchingSelector: "td", 7300 untilNode: this.containerElement 7301 })) return; 7302 return getBlockTagNames().includes(tagName(element)) || window.getComputedStyle(element).display === "block"; 7303 } 7304 isInsignificantTextNode(node) { 7305 if ((node === null || node === void 0 ? void 0 : node.nodeType) !== Node.TEXT_NODE) return; 7306 if (!stringIsAllBreakableWhitespace(node.data)) return; 7307 const { 7308 parentNode, 7309 previousSibling, 7310 nextSibling 7311 } = node; 7312 if (nodeEndsWithNonWhitespace(parentNode.previousSibling) && !this.isBlockElement(parentNode.previousSibling)) return; 7313 if (elementCanDisplayPreformattedText(parentNode)) return; 7314 return !previousSibling || this.isBlockElement(previousSibling) || !nextSibling || this.isBlockElement(nextSibling); 7315 } 7316 isExtraBR(element) { 7317 return tagName(element) === "br" && this.isBlockElement(element.parentNode) && element.parentNode.lastChild === element; 7318 } 7319 needsTableSeparator(element) { 7320 if (parser.removeBlankTableCells) { 7321 var _element$previousSibl; 7322 const content = (_element$previousSibl = element.previousSibling) === null || _element$previousSibl === void 0 ? void 0 : _element$previousSibl.textContent; 7323 return content && /\S/.test(content); 7324 } else { 7325 return element.previousSibling; 7326 } 7327 } 7328 7329 // Margin translation 7330 7331 translateBlockElementMarginsToNewlines() { 7332 const defaultMargin = this.getMarginOfDefaultBlockElement(); 7333 for (let index = 0; index < this.blocks.length; index++) { 7334 const margin = this.getMarginOfBlockElementAtIndex(index); 7335 if (margin) { 7336 if (margin.top > defaultMargin.top * 2) { 7337 this.prependStringToTextAtIndex("\n", index); 7338 } 7339 if (margin.bottom > defaultMargin.bottom * 2) { 7340 this.appendStringToTextAtIndex("\n", index); 7341 } 7342 } 7343 } 7344 } 7345 getMarginOfBlockElementAtIndex(index) { 7346 const element = this.blockElements[index]; 7347 if (element) { 7348 if (element.textContent) { 7349 if (!getBlockTagNames().includes(tagName(element)) && !this.processedElements.includes(element)) { 7350 return getBlockElementMargin(element); 7351 } 7352 } 7353 } 7354 } 7355 getMarginOfDefaultBlockElement() { 7356 const element = makeElement(attributes.default.tagName); 7357 this.containerElement.appendChild(element); 7358 return getBlockElementMargin(element); 7359 } 7360 } 7361 7362 //Â Helpers 7363 7364 const elementCanDisplayPreformattedText = function (element) { 7365 const { 7366 whiteSpace 7367 } = window.getComputedStyle(element); 7368 return ["pre", "pre-wrap", "pre-line"].includes(whiteSpace); 7369 }; 7370 const nodeEndsWithNonWhitespace = node => node && !stringEndsWithWhitespace(node.textContent); 7371 const getBlockElementMargin = function (element) { 7372 const style = window.getComputedStyle(element); 7373 if (style.display === "block") { 7374 return { 7375 top: parseInt(style.marginTop), 7376 bottom: parseInt(style.marginBottom) 7377 }; 7378 } 7379 }; 7380 const nodeFilter = function (node) { 7381 if (tagName(node) === "style") { 7382 return NodeFilter.FILTER_REJECT; 7383 } else { 7384 return NodeFilter.FILTER_ACCEPT; 7385 } 7386 }; 7387 7388 // Whitespace 7389 7390 const leftTrimBreakableWhitespace = string => string.replace(new RegExp("^".concat(breakableWhitespacePattern.source, "+")), ""); 7391 const stringIsAllBreakableWhitespace = string => new RegExp("^".concat(breakableWhitespacePattern.source, "*$")).test(string); 7392 const stringEndsWithWhitespace = string => /\s$/.test(string); 7393 7394 /* eslint-disable 7395 no-empty, 7396 */ 7397 const unserializableElementSelector = "[data-trix-serialize=false]"; 7398 const unserializableAttributeNames = ["contenteditable", "data-trix-id", "data-trix-store-key", "data-trix-mutable", "data-trix-placeholder", "tabindex"]; 7399 const serializedAttributesAttribute = "data-trix-serialized-attributes"; 7400 const serializedAttributesSelector = "[".concat(serializedAttributesAttribute, "]"); 7401 const blockCommentPattern = new RegExp("<!--block-->", "g"); 7402 const serializers = { 7403 "application/json": function (serializable) { 7404 let document; 7405 if (serializable instanceof Document) { 7406 document = serializable; 7407 } else if (serializable instanceof HTMLElement) { 7408 document = HTMLParser.parse(serializable.innerHTML).getDocument(); 7409 } else { 7410 throw new Error("unserializable object"); 7411 } 7412 return document.toSerializableDocument().toJSONString(); 7413 }, 7414 "text/html": function (serializable) { 7415 let element; 7416 if (serializable instanceof Document) { 7417 element = DocumentView.render(serializable); 7418 } else if (serializable instanceof HTMLElement) { 7419 element = serializable.cloneNode(true); 7420 } else { 7421 throw new Error("unserializable object"); 7422 } 7423 7424 // Remove unserializable elements 7425 Array.from(element.querySelectorAll(unserializableElementSelector)).forEach(el => { 7426 removeNode(el); 7427 }); 7428 7429 // Remove unserializable attributes 7430 unserializableAttributeNames.forEach(attribute => { 7431 Array.from(element.querySelectorAll("[".concat(attribute, "]"))).forEach(el => { 7432 el.removeAttribute(attribute); 7433 }); 7434 }); 7435 7436 // Rewrite elements with serialized attribute overrides 7437 Array.from(element.querySelectorAll(serializedAttributesSelector)).forEach(el => { 7438 try { 7439 const attributes = JSON.parse(el.getAttribute(serializedAttributesAttribute)); 7440 el.removeAttribute(serializedAttributesAttribute); 7441 for (const name in attributes) { 7442 const value = attributes[name]; 7443 el.setAttribute(name, value); 7444 } 7445 } catch (error) {} 7446 }); 7447 return element.innerHTML.replace(blockCommentPattern, ""); 7448 } 7449 }; 7450 const deserializers = { 7451 "application/json": function (string) { 7452 return Document.fromJSONString(string); 7453 }, 7454 "text/html": function (string) { 7455 return HTMLParser.parse(string).getDocument(); 7456 } 7457 }; 7458 const serializeToContentType = function (serializable, contentType) { 7459 const serializer = serializers[contentType]; 7460 if (serializer) { 7461 return serializer(serializable); 7462 } else { 7463 throw new Error("unknown content type: ".concat(contentType)); 7464 } 7465 }; 7466 const deserializeFromContentType = function (string, contentType) { 7467 const deserializer = deserializers[contentType]; 7468 if (deserializer) { 7469 return deserializer(string); 7470 } else { 7471 throw new Error("unknown content type: ".concat(contentType)); 7472 } 7473 }; 7474 7475 var core = /*#__PURE__*/Object.freeze({ 7476 __proto__: null 7477 }); 7478 7479 class ManagedAttachment extends BasicObject { 7480 constructor(attachmentManager, attachment) { 7481 super(...arguments); 7482 this.attachmentManager = attachmentManager; 7483 this.attachment = attachment; 7484 this.id = this.attachment.id; 7485 this.file = this.attachment.file; 7486 } 7487 remove() { 7488 return this.attachmentManager.requestRemovalOfAttachment(this.attachment); 7489 } 7490 } 7491 ManagedAttachment.proxyMethod("attachment.getAttribute"); 7492 ManagedAttachment.proxyMethod("attachment.hasAttribute"); 7493 ManagedAttachment.proxyMethod("attachment.setAttribute"); 7494 ManagedAttachment.proxyMethod("attachment.getAttributes"); 7495 ManagedAttachment.proxyMethod("attachment.setAttributes"); 7496 ManagedAttachment.proxyMethod("attachment.isPending"); 7497 ManagedAttachment.proxyMethod("attachment.isPreviewable"); 7498 ManagedAttachment.proxyMethod("attachment.getURL"); 7499 ManagedAttachment.proxyMethod("attachment.getHref"); 7500 ManagedAttachment.proxyMethod("attachment.getFilename"); 7501 ManagedAttachment.proxyMethod("attachment.getFilesize"); 7502 ManagedAttachment.proxyMethod("attachment.getFormattedFilesize"); 7503 ManagedAttachment.proxyMethod("attachment.getExtension"); 7504 ManagedAttachment.proxyMethod("attachment.getContentType"); 7505 ManagedAttachment.proxyMethod("attachment.getFile"); 7506 ManagedAttachment.proxyMethod("attachment.setFile"); 7507 ManagedAttachment.proxyMethod("attachment.releaseFile"); 7508 ManagedAttachment.proxyMethod("attachment.getUploadProgress"); 7509 ManagedAttachment.proxyMethod("attachment.setUploadProgress"); 7510 7511 class AttachmentManager extends BasicObject { 7512 constructor() { 7513 let attachments = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; 7514 super(...arguments); 7515 this.managedAttachments = {}; 7516 Array.from(attachments).forEach(attachment => { 7517 this.manageAttachment(attachment); 7518 }); 7519 } 7520 getAttachments() { 7521 const result = []; 7522 for (const id in this.managedAttachments) { 7523 const attachment = this.managedAttachments[id]; 7524 result.push(attachment); 7525 } 7526 return result; 7527 } 7528 manageAttachment(attachment) { 7529 if (!this.managedAttachments[attachment.id]) { 7530 this.managedAttachments[attachment.id] = new ManagedAttachment(this, attachment); 7531 } 7532 return this.managedAttachments[attachment.id]; 7533 } 7534 attachmentIsManaged(attachment) { 7535 return attachment.id in this.managedAttachments; 7536 } 7537 requestRemovalOfAttachment(attachment) { 7538 if (this.attachmentIsManaged(attachment)) { 7539 var _this$delegate, _this$delegate$attach; 7540 return (_this$delegate = this.delegate) === null || _this$delegate === void 0 || (_this$delegate$attach = _this$delegate.attachmentManagerDidRequestRemovalOfAttachment) === null || _this$delegate$attach === void 0 ? void 0 : _this$delegate$attach.call(_this$delegate, attachment); 7541 } 7542 } 7543 unmanageAttachment(attachment) { 7544 const managedAttachment = this.managedAttachments[attachment.id]; 7545 delete this.managedAttachments[attachment.id]; 7546 return managedAttachment; 7547 } 7548 } 7549 7550 class LineBreakInsertion { 7551 constructor(composition) { 7552 this.composition = composition; 7553 this.document = this.composition.document; 7554 const selectedRange = this.composition.getSelectedRange(); 7555 this.startPosition = selectedRange[0]; 7556 this.endPosition = selectedRange[1]; 7557 this.startLocation = this.document.locationFromPosition(this.startPosition); 7558 this.endLocation = this.document.locationFromPosition(this.endPosition); 7559 this.block = this.document.getBlockAtIndex(this.endLocation.index); 7560 this.breaksOnReturn = this.block.breaksOnReturn(); 7561 this.previousCharacter = this.block.text.getStringAtPosition(this.endLocation.offset - 1); 7562 this.nextCharacter = this.block.text.getStringAtPosition(this.endLocation.offset); 7563 } 7564 shouldInsertBlockBreak() { 7565 if (this.block.hasAttributes() && this.block.isListItem() && !this.block.isEmpty()) { 7566 return this.startLocation.offset !== 0; 7567 } else { 7568 return this.breaksOnReturn && this.nextCharacter !== "\n"; 7569 } 7570 } 7571 shouldBreakFormattedBlock() { 7572 return this.block.hasAttributes() && !this.block.isListItem() && (this.breaksOnReturn && this.nextCharacter === "\n" || this.previousCharacter === "\n"); 7573 } 7574 shouldDecreaseListLevel() { 7575 return this.block.hasAttributes() && this.block.isListItem() && this.block.isEmpty(); 7576 } 7577 shouldPrependListItem() { 7578 return this.block.isListItem() && this.startLocation.offset === 0 && !this.block.isEmpty(); 7579 } 7580 shouldRemoveLastBlockAttribute() { 7581 return this.block.hasAttributes() && !this.block.isListItem() && this.block.isEmpty(); 7582 } 7583 } 7584 7585 const PLACEHOLDER = " "; 7586 class Composition extends BasicObject { 7587 constructor() { 7588 super(...arguments); 7589 this.document = new Document(); 7590 this.attachments = []; 7591 this.currentAttributes = {}; 7592 this.revision = 0; 7593 } 7594 setDocument(document) { 7595 if (!document.isEqualTo(this.document)) { 7596 var _this$delegate, _this$delegate$compos; 7597 this.document = document; 7598 this.refreshAttachments(); 7599 this.revision++; 7600 return (_this$delegate = this.delegate) === null || _this$delegate === void 0 || (_this$delegate$compos = _this$delegate.compositionDidChangeDocument) === null || _this$delegate$compos === void 0 ? void 0 : _this$delegate$compos.call(_this$delegate, document); 7601 } 7602 } 7603 7604 // Snapshots 7605 7606 getSnapshot() { 7607 return { 7608 document: this.document, 7609 selectedRange: this.getSelectedRange() 7610 }; 7611 } 7612 loadSnapshot(_ref) { 7613 var _this$delegate2, _this$delegate2$compo, _this$delegate3, _this$delegate3$compo; 7614 let { 7615 document, 7616 selectedRange 7617 } = _ref; 7618 (_this$delegate2 = this.delegate) === null || _this$delegate2 === void 0 || (_this$delegate2$compo = _this$delegate2.compositionWillLoadSnapshot) === null || _this$delegate2$compo === void 0 || _this$delegate2$compo.call(_this$delegate2); 7619 this.setDocument(document != null ? document : new Document()); 7620 this.setSelection(selectedRange != null ? selectedRange : [0, 0]); 7621 return (_this$delegate3 = this.delegate) === null || _this$delegate3 === void 0 || (_this$delegate3$compo = _this$delegate3.compositionDidLoadSnapshot) === null || _this$delegate3$compo === void 0 ? void 0 : _this$delegate3$compo.call(_this$delegate3); 7622 } 7623 7624 // Responder protocol 7625 7626 insertText(text) { 7627 let { 7628 updatePosition 7629 } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { 7630 updatePosition: true 7631 }; 7632 const selectedRange = this.getSelectedRange(); 7633 this.setDocument(this.document.insertTextAtRange(text, selectedRange)); 7634 const startPosition = selectedRange[0]; 7635 const endPosition = startPosition + text.getLength(); 7636 if (updatePosition) { 7637 this.setSelection(endPosition); 7638 } 7639 return this.notifyDelegateOfInsertionAtRange([startPosition, endPosition]); 7640 } 7641 insertBlock() { 7642 let block = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Block(); 7643 const document = new Document([block]); 7644 return this.insertDocument(document); 7645 } 7646 insertDocument() { 7647 let document = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Document(); 7648 const selectedRange = this.getSelectedRange(); 7649 this.setDocument(this.document.insertDocumentAtRange(document, selectedRange)); 7650 const startPosition = selectedRange[0]; 7651 const endPosition = startPosition + document.getLength(); 7652 this.setSelection(endPosition); 7653 return this.notifyDelegateOfInsertionAtRange([startPosition, endPosition]); 7654 } 7655 insertString(string, options) { 7656 const attributes = this.getCurrentTextAttributes(); 7657 const text = Text.textForStringWithAttributes(string, attributes); 7658 return this.insertText(text, options); 7659 } 7660 insertBlockBreak() { 7661 const selectedRange = this.getSelectedRange(); 7662 this.setDocument(this.document.insertBlockBreakAtRange(selectedRange)); 7663 const startPosition = selectedRange[0]; 7664 const endPosition = startPosition + 1; 7665 this.setSelection(endPosition); 7666 return this.notifyDelegateOfInsertionAtRange([startPosition, endPosition]); 7667 } 7668 insertLineBreak() { 7669 const insertion = new LineBreakInsertion(this); 7670 if (insertion.shouldDecreaseListLevel()) { 7671 this.decreaseListLevel(); 7672 return this.setSelection(insertion.startPosition); 7673 } else if (insertion.shouldPrependListItem()) { 7674 const document = new Document([insertion.block.copyWithoutText()]); 7675 return this.insertDocument(document); 7676 } else if (insertion.shouldInsertBlockBreak()) { 7677 return this.insertBlockBreak(); 7678 } else if (insertion.shouldRemoveLastBlockAttribute()) { 7679 return this.removeLastBlockAttribute(); 7680 } else if (insertion.shouldBreakFormattedBlock()) { 7681 return this.breakFormattedBlock(insertion); 7682 } else { 7683 return this.insertString("\n"); 7684 } 7685 } 7686 insertHTML(html) { 7687 const document = HTMLParser.parse(html).getDocument(); 7688 const selectedRange = this.getSelectedRange(); 7689 this.setDocument(this.document.mergeDocumentAtRange(document, selectedRange)); 7690 const startPosition = selectedRange[0]; 7691 const endPosition = startPosition + document.getLength() - 1; 7692 this.setSelection(endPosition); 7693 return this.notifyDelegateOfInsertionAtRange([startPosition, endPosition]); 7694 } 7695 replaceHTML(html) { 7696 const document = HTMLParser.parse(html).getDocument().copyUsingObjectsFromDocument(this.document); 7697 const locationRange = this.getLocationRange({ 7698 strict: false 7699 }); 7700 const selectedRange = this.document.rangeFromLocationRange(locationRange); 7701 this.setDocument(document); 7702 return this.setSelection(selectedRange); 7703 } 7704 insertFile(file) { 7705 return this.insertFiles([file]); 7706 } 7707 insertFiles(files) { 7708 const attachments = []; 7709 Array.from(files).forEach(file => { 7710 var _this$delegate4; 7711 if ((_this$delegate4 = this.delegate) !== null && _this$delegate4 !== void 0 && _this$delegate4.compositionShouldAcceptFile(file)) { 7712 const attachment = Attachment.attachmentForFile(file); 7713 attachments.push(attachment); 7714 } 7715 }); 7716 return this.insertAttachments(attachments); 7717 } 7718 insertAttachment(attachment) { 7719 return this.insertAttachments([attachment]); 7720 } 7721 insertAttachments(attachments$1) { 7722 let text = new Text(); 7723 Array.from(attachments$1).forEach(attachment => { 7724 var _config$attachments$t; 7725 const type = attachment.getType(); 7726 const presentation = (_config$attachments$t = attachments[type]) === null || _config$attachments$t === void 0 ? void 0 : _config$attachments$t.presentation; 7727 const attributes = this.getCurrentTextAttributes(); 7728 if (presentation) { 7729 attributes.presentation = presentation; 7730 } 7731 const attachmentText = Text.textForAttachmentWithAttributes(attachment, attributes); 7732 text = text.appendText(attachmentText); 7733 }); 7734 return this.insertText(text); 7735 } 7736 shouldManageDeletingInDirection(direction) { 7737 const locationRange = this.getLocationRange(); 7738 if (rangeIsCollapsed(locationRange)) { 7739 if (direction === "backward" && locationRange[0].offset === 0) { 7740 return true; 7741 } 7742 if (this.shouldManageMovingCursorInDirection(direction)) { 7743 return true; 7744 } 7745 } else { 7746 if (locationRange[0].index !== locationRange[1].index) { 7747 return true; 7748 } 7749 } 7750 return false; 7751 } 7752 deleteInDirection(direction) { 7753 let { 7754 length 7755 } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 7756 let attachment, deletingIntoPreviousBlock, selectionSpansBlocks; 7757 const locationRange = this.getLocationRange(); 7758 let range = this.getSelectedRange(); 7759 const selectionIsCollapsed = rangeIsCollapsed(range); 7760 if (selectionIsCollapsed) { 7761 deletingIntoPreviousBlock = direction === "backward" && locationRange[0].offset === 0; 7762 } else { 7763 selectionSpansBlocks = locationRange[0].index !== locationRange[1].index; 7764 } 7765 if (deletingIntoPreviousBlock) { 7766 if (this.canDecreaseBlockAttributeLevel()) { 7767 const block = this.getBlock(); 7768 if (block.isListItem()) { 7769 this.decreaseListLevel(); 7770 } else { 7771 this.decreaseBlockAttributeLevel(); 7772 } 7773 this.setSelection(range[0]); 7774 if (block.isEmpty()) { 7775 return false; 7776 } 7777 } 7778 } 7779 if (selectionIsCollapsed) { 7780 range = this.getExpandedRangeInDirection(direction, { 7781 length 7782 }); 7783 if (direction === "backward") { 7784 attachment = this.getAttachmentAtRange(range); 7785 } 7786 } 7787 if (attachment) { 7788 this.editAttachment(attachment); 7789 return false; 7790 } else { 7791 this.setDocument(this.document.removeTextAtRange(range)); 7792 this.setSelection(range[0]); 7793 if (deletingIntoPreviousBlock || selectionSpansBlocks) { 7794 return false; 7795 } 7796 } 7797 } 7798 moveTextFromRange(range) { 7799 const [position] = Array.from(this.getSelectedRange()); 7800 this.setDocument(this.document.moveTextFromRangeToPosition(range, position)); 7801 return this.setSelection(position); 7802 } 7803 removeAttachment(attachment) { 7804 const range = this.document.getRangeOfAttachment(attachment); 7805 if (range) { 7806 this.stopEditingAttachment(); 7807 this.setDocument(this.document.removeTextAtRange(range)); 7808 return this.setSelection(range[0]); 7809 } 7810 } 7811 removeLastBlockAttribute() { 7812 const [startPosition, endPosition] = Array.from(this.getSelectedRange()); 7813 const block = this.document.getBlockAtPosition(endPosition); 7814 this.removeCurrentAttribute(block.getLastAttribute()); 7815 return this.setSelection(startPosition); 7816 } 7817 insertPlaceholder() { 7818 this.placeholderPosition = this.getPosition(); 7819 return this.insertString(PLACEHOLDER); 7820 } 7821 selectPlaceholder() { 7822 if (this.placeholderPosition != null) { 7823 this.setSelectedRange([this.placeholderPosition, this.placeholderPosition + PLACEHOLDER.length]); 7824 return this.getSelectedRange(); 7825 } 7826 } 7827 forgetPlaceholder() { 7828 this.placeholderPosition = null; 7829 } 7830 7831 // Current attributes 7832 7833 hasCurrentAttribute(attributeName) { 7834 const value = this.currentAttributes[attributeName]; 7835 return value != null && value !== false; 7836 } 7837 toggleCurrentAttribute(attributeName) { 7838 const value = !this.currentAttributes[attributeName]; 7839 if (value) { 7840 return this.setCurrentAttribute(attributeName, value); 7841 } else { 7842 return this.removeCurrentAttribute(attributeName); 7843 } 7844 } 7845 canSetCurrentAttribute(attributeName) { 7846 if (getBlockConfig(attributeName)) { 7847 return this.canSetCurrentBlockAttribute(attributeName); 7848 } else { 7849 return this.canSetCurrentTextAttribute(attributeName); 7850 } 7851 } 7852 canSetCurrentTextAttribute(attributeName) { 7853 const document = this.getSelectedDocument(); 7854 if (!document) return; 7855 for (const attachment of Array.from(document.getAttachments())) { 7856 if (!attachment.hasContent()) { 7857 return false; 7858 } 7859 } 7860 return true; 7861 } 7862 canSetCurrentBlockAttribute(attributeName) { 7863 const block = this.getBlock(); 7864 if (!block) return; 7865 return !block.isTerminalBlock(); 7866 } 7867 setCurrentAttribute(attributeName, value) { 7868 if (getBlockConfig(attributeName)) { 7869 return this.setBlockAttribute(attributeName, value); 7870 } else { 7871 this.setTextAttribute(attributeName, value); 7872 this.currentAttributes[attributeName] = value; 7873 return this.notifyDelegateOfCurrentAttributesChange(); 7874 } 7875 } 7876 setHTMLAtributeAtPosition(position, attributeName, value) { 7877 var _getBlockConfig; 7878 const block = this.document.getBlockAtPosition(position); 7879 const allowedHTMLAttributes = (_getBlockConfig = getBlockConfig(block.getLastAttribute())) === null || _getBlockConfig === void 0 ? void 0 : _getBlockConfig.htmlAttributes; 7880 if (block && allowedHTMLAttributes !== null && allowedHTMLAttributes !== void 0 && allowedHTMLAttributes.includes(attributeName)) { 7881 const newDocument = this.document.setHTMLAttributeAtPosition(position, attributeName, value); 7882 this.setDocument(newDocument); 7883 } 7884 } 7885 setTextAttribute(attributeName, value) { 7886 const selectedRange = this.getSelectedRange(); 7887 if (!selectedRange) return; 7888 const [startPosition, endPosition] = Array.from(selectedRange); 7889 if (startPosition === endPosition) { 7890 if (attributeName === "href") { 7891 const text = Text.textForStringWithAttributes(value, { 7892 href: value 7893 }); 7894 return this.insertText(text); 7895 } 7896 } else { 7897 return this.setDocument(this.document.addAttributeAtRange(attributeName, value, selectedRange)); 7898 } 7899 } 7900 setBlockAttribute(attributeName, value) { 7901 const selectedRange = this.getSelectedRange(); 7902 if (this.canSetCurrentAttribute(attributeName)) { 7903 this.setDocument(this.document.applyBlockAttributeAtRange(attributeName, value, selectedRange)); 7904 return this.setSelection(selectedRange); 7905 } 7906 } 7907 removeCurrentAttribute(attributeName) { 7908 if (getBlockConfig(attributeName)) { 7909 this.removeBlockAttribute(attributeName); 7910 return this.updateCurrentAttributes(); 7911 } else { 7912 this.removeTextAttribute(attributeName); 7913 delete this.currentAttributes[attributeName]; 7914 return this.notifyDelegateOfCurrentAttributesChange(); 7915 } 7916 } 7917 removeTextAttribute(attributeName) { 7918 const selectedRange = this.getSelectedRange(); 7919 if (!selectedRange) return; 7920 return this.setDocument(this.document.removeAttributeAtRange(attributeName, selectedRange)); 7921 } 7922 removeBlockAttribute(attributeName) { 7923 const selectedRange = this.getSelectedRange(); 7924 if (!selectedRange) return; 7925 return this.setDocument(this.document.removeAttributeAtRange(attributeName, selectedRange)); 7926 } 7927 canDecreaseNestingLevel() { 7928 var _this$getBlock; 7929 return ((_this$getBlock = this.getBlock()) === null || _this$getBlock === void 0 ? void 0 : _this$getBlock.getNestingLevel()) > 0; 7930 } 7931 canIncreaseNestingLevel() { 7932 var _getBlockConfig2; 7933 const block = this.getBlock(); 7934 if (!block) return; 7935 if ((_getBlockConfig2 = getBlockConfig(block.getLastNestableAttribute())) !== null && _getBlockConfig2 !== void 0 && _getBlockConfig2.listAttribute) { 7936 const previousBlock = this.getPreviousBlock(); 7937 if (previousBlock) { 7938 return arrayStartsWith(previousBlock.getListItemAttributes(), block.getListItemAttributes()); 7939 } 7940 } else { 7941 return block.getNestingLevel() > 0; 7942 } 7943 } 7944 decreaseNestingLevel() { 7945 const block = this.getBlock(); 7946 if (!block) return; 7947 return this.setDocument(this.document.replaceBlock(block, block.decreaseNestingLevel())); 7948 } 7949 increaseNestingLevel() { 7950 const block = this.getBlock(); 7951 if (!block) return; 7952 return this.setDocument(this.document.replaceBlock(block, block.increaseNestingLevel())); 7953 } 7954 canDecreaseBlockAttributeLevel() { 7955 var _this$getBlock2; 7956 return ((_this$getBlock2 = this.getBlock()) === null || _this$getBlock2 === void 0 ? void 0 : _this$getBlock2.getAttributeLevel()) > 0; 7957 } 7958 decreaseBlockAttributeLevel() { 7959 var _this$getBlock3; 7960 const attribute = (_this$getBlock3 = this.getBlock()) === null || _this$getBlock3 === void 0 ? void 0 : _this$getBlock3.getLastAttribute(); 7961 if (attribute) { 7962 return this.removeCurrentAttribute(attribute); 7963 } 7964 } 7965 decreaseListLevel() { 7966 let [startPosition] = Array.from(this.getSelectedRange()); 7967 const { 7968 index 7969 } = this.document.locationFromPosition(startPosition); 7970 let endIndex = index; 7971 const attributeLevel = this.getBlock().getAttributeLevel(); 7972 let block = this.document.getBlockAtIndex(endIndex + 1); 7973 while (block) { 7974 if (!block.isListItem() || block.getAttributeLevel() <= attributeLevel) { 7975 break; 7976 } 7977 endIndex++; 7978 block = this.document.getBlockAtIndex(endIndex + 1); 7979 } 7980 startPosition = this.document.positionFromLocation({ 7981 index, 7982 offset: 0 7983 }); 7984 const endPosition = this.document.positionFromLocation({ 7985 index: endIndex, 7986 offset: 0 7987 }); 7988 return this.setDocument(this.document.removeLastListAttributeAtRange([startPosition, endPosition])); 7989 } 7990 updateCurrentAttributes() { 7991 const selectedRange = this.getSelectedRange({ 7992 ignoreLock: true 7993 }); 7994 if (selectedRange) { 7995 const currentAttributes = this.document.getCommonAttributesAtRange(selectedRange); 7996 Array.from(getAllAttributeNames()).forEach(attributeName => { 7997 if (!currentAttributes[attributeName]) { 7998 if (!this.canSetCurrentAttribute(attributeName)) { 7999 currentAttributes[attributeName] = false; 8000 } 8001 } 8002 }); 8003 if (!objectsAreEqual(currentAttributes, this.currentAttributes)) { 8004 this.currentAttributes = currentAttributes; 8005 return this.notifyDelegateOfCurrentAttributesChange(); 8006 } 8007 } 8008 } 8009 getCurrentAttributes() { 8010 return extend.call({}, this.currentAttributes); 8011 } 8012 getCurrentTextAttributes() { 8013 const attributes = {}; 8014 for (const key in this.currentAttributes) { 8015 const value = this.currentAttributes[key]; 8016 if (value !== false) { 8017 if (getTextConfig(key)) { 8018 attributes[key] = value; 8019 } 8020 } 8021 } 8022 return attributes; 8023 } 8024 8025 // Selection freezing 8026 8027 freezeSelection() { 8028 return this.setCurrentAttribute("frozen", true); 8029 } 8030 thawSelection() { 8031 return this.removeCurrentAttribute("frozen"); 8032 } 8033 hasFrozenSelection() { 8034 return this.hasCurrentAttribute("frozen"); 8035 } 8036 setSelection(selectedRange) { 8037 var _this$delegate5; 8038 const locationRange = this.document.locationRangeFromRange(selectedRange); 8039 return (_this$delegate5 = this.delegate) === null || _this$delegate5 === void 0 ? void 0 : _this$delegate5.compositionDidRequestChangingSelectionToLocationRange(locationRange); 8040 } 8041 getSelectedRange() { 8042 const locationRange = this.getLocationRange(); 8043 if (locationRange) { 8044 return this.document.rangeFromLocationRange(locationRange); 8045 } 8046 } 8047 setSelectedRange(selectedRange) { 8048 const locationRange = this.document.locationRangeFromRange(selectedRange); 8049 return this.getSelectionManager().setLocationRange(locationRange); 8050 } 8051 getPosition() { 8052 const locationRange = this.getLocationRange(); 8053 if (locationRange) { 8054 return this.document.positionFromLocation(locationRange[0]); 8055 } 8056 } 8057 getLocationRange(options) { 8058 if (this.targetLocationRange) { 8059 return this.targetLocationRange; 8060 } else { 8061 return this.getSelectionManager().getLocationRange(options) || normalizeRange({ 8062 index: 0, 8063 offset: 0 8064 }); 8065 } 8066 } 8067 withTargetLocationRange(locationRange, fn) { 8068 let result; 8069 this.targetLocationRange = locationRange; 8070 try { 8071 result = fn(); 8072 } finally { 8073 this.targetLocationRange = null; 8074 } 8075 return result; 8076 } 8077 withTargetRange(range, fn) { 8078 const locationRange = this.document.locationRangeFromRange(range); 8079 return this.withTargetLocationRange(locationRange, fn); 8080 } 8081 withTargetDOMRange(domRange, fn) { 8082 const locationRange = this.createLocationRangeFromDOMRange(domRange, { 8083 strict: false 8084 }); 8085 return this.withTargetLocationRange(locationRange, fn); 8086 } 8087 getExpandedRangeInDirection(direction) { 8088 let { 8089 length 8090 } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 8091 let [startPosition, endPosition] = Array.from(this.getSelectedRange()); 8092 if (direction === "backward") { 8093 if (length) { 8094 startPosition -= length; 8095 } else { 8096 startPosition = this.translateUTF16PositionFromOffset(startPosition, -1); 8097 } 8098 } else { 8099 if (length) { 8100 endPosition += length; 8101 } else { 8102 endPosition = this.translateUTF16PositionFromOffset(endPosition, 1); 8103 } 8104 } 8105 return normalizeRange([startPosition, endPosition]); 8106 } 8107 shouldManageMovingCursorInDirection(direction) { 8108 if (this.editingAttachment) { 8109 return true; 8110 } 8111 const range = this.getExpandedRangeInDirection(direction); 8112 return this.getAttachmentAtRange(range) != null; 8113 } 8114 moveCursorInDirection(direction) { 8115 let canEditAttachment, range; 8116 if (this.editingAttachment) { 8117 range = this.document.getRangeOfAttachment(this.editingAttachment); 8118 } else { 8119 const selectedRange = this.getSelectedRange(); 8120 range = this.getExpandedRangeInDirection(direction); 8121 canEditAttachment = !rangesAreEqual(selectedRange, range); 8122 } 8123 if (direction === "backward") { 8124 this.setSelectedRange(range[0]); 8125 } else { 8126 this.setSelectedRange(range[1]); 8127 } 8128 if (canEditAttachment) { 8129 const attachment = this.getAttachmentAtRange(range); 8130 if (attachment) { 8131 return this.editAttachment(attachment); 8132 } 8133 } 8134 } 8135 expandSelectionInDirection(direction) { 8136 let { 8137 length 8138 } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 8139 const range = this.getExpandedRangeInDirection(direction, { 8140 length 8141 }); 8142 return this.setSelectedRange(range); 8143 } 8144 expandSelectionForEditing() { 8145 if (this.hasCurrentAttribute("href")) { 8146 return this.expandSelectionAroundCommonAttribute("href"); 8147 } 8148 } 8149 expandSelectionAroundCommonAttribute(attributeName) { 8150 const position = this.getPosition(); 8151 const range = this.document.getRangeOfCommonAttributeAtPosition(attributeName, position); 8152 return this.setSelectedRange(range); 8153 } 8154 selectionContainsAttachments() { 8155 var _this$getSelectedAtta; 8156 return ((_this$getSelectedAtta = this.getSelectedAttachments()) === null || _this$getSelectedAtta === void 0 ? void 0 : _this$getSelectedAtta.length) > 0; 8157 } 8158 selectionIsInCursorTarget() { 8159 return this.editingAttachment || this.positionIsCursorTarget(this.getPosition()); 8160 } 8161 positionIsCursorTarget(position) { 8162 const location = this.document.locationFromPosition(position); 8163 if (location) { 8164 return this.locationIsCursorTarget(location); 8165 } 8166 } 8167 positionIsBlockBreak(position) { 8168 var _this$document$getPie; 8169 return (_this$document$getPie = this.document.getPieceAtPosition(position)) === null || _this$document$getPie === void 0 ? void 0 : _this$document$getPie.isBlockBreak(); 8170 } 8171 getSelectedDocument() { 8172 const selectedRange = this.getSelectedRange(); 8173 if (selectedRange) { 8174 return this.document.getDocumentAtRange(selectedRange); 8175 } 8176 } 8177 getSelectedAttachments() { 8178 var _this$getSelectedDocu; 8179 return (_this$getSelectedDocu = this.getSelectedDocument()) === null || _this$getSelectedDocu === void 0 ? void 0 : _this$getSelectedDocu.getAttachments(); 8180 } 8181 8182 // Attachments 8183 8184 getAttachments() { 8185 return this.attachments.slice(0); 8186 } 8187 refreshAttachments() { 8188 const attachments = this.document.getAttachments(); 8189 const { 8190 added, 8191 removed 8192 } = summarizeArrayChange(this.attachments, attachments); 8193 this.attachments = attachments; 8194 Array.from(removed).forEach(attachment => { 8195 var _this$delegate6, _this$delegate6$compo; 8196 attachment.delegate = null; 8197 (_this$delegate6 = this.delegate) === null || _this$delegate6 === void 0 || (_this$delegate6$compo = _this$delegate6.compositionDidRemoveAttachment) === null || _this$delegate6$compo === void 0 || _this$delegate6$compo.call(_this$delegate6, attachment); 8198 }); 8199 return (() => { 8200 const result = []; 8201 Array.from(added).forEach(attachment => { 8202 var _this$delegate7, _this$delegate7$compo; 8203 attachment.delegate = this; 8204 result.push((_this$delegate7 = this.delegate) === null || _this$delegate7 === void 0 || (_this$delegate7$compo = _this$delegate7.compositionDidAddAttachment) === null || _this$delegate7$compo === void 0 ? void 0 : _this$delegate7$compo.call(_this$delegate7, attachment)); 8205 }); 8206 return result; 8207 })(); 8208 } 8209 8210 // Attachment delegate 8211 8212 attachmentDidChangeAttributes(attachment) { 8213 var _this$delegate8, _this$delegate8$compo; 8214 this.revision++; 8215 return (_this$delegate8 = this.delegate) === null || _this$delegate8 === void 0 || (_this$delegate8$compo = _this$delegate8.compositionDidEditAttachment) === null || _this$delegate8$compo === void 0 ? void 0 : _this$delegate8$compo.call(_this$delegate8, attachment); 8216 } 8217 attachmentDidChangePreviewURL(attachment) { 8218 var _this$delegate9, _this$delegate9$compo; 8219 this.revision++; 8220 return (_this$delegate9 = this.delegate) === null || _this$delegate9 === void 0 || (_this$delegate9$compo = _this$delegate9.compositionDidChangeAttachmentPreviewURL) === null || _this$delegate9$compo === void 0 ? void 0 : _this$delegate9$compo.call(_this$delegate9, attachment); 8221 } 8222 8223 // Attachment editing 8224 8225 editAttachment(attachment, options) { 8226 var _this$delegate10, _this$delegate10$comp; 8227 if (attachment === this.editingAttachment) return; 8228 this.stopEditingAttachment(); 8229 this.editingAttachment = attachment; 8230 return (_this$delegate10 = this.delegate) === null || _this$delegate10 === void 0 || (_this$delegate10$comp = _this$delegate10.compositionDidStartEditingAttachment) === null || _this$delegate10$comp === void 0 ? void 0 : _this$delegate10$comp.call(_this$delegate10, this.editingAttachment, options); 8231 } 8232 stopEditingAttachment() { 8233 var _this$delegate11, _this$delegate11$comp; 8234 if (!this.editingAttachment) return; 8235 (_this$delegate11 = this.delegate) === null || _this$delegate11 === void 0 || (_this$delegate11$comp = _this$delegate11.compositionDidStopEditingAttachment) === null || _this$delegate11$comp === void 0 || _this$delegate11$comp.call(_this$delegate11, this.editingAttachment); 8236 this.editingAttachment = null; 8237 } 8238 updateAttributesForAttachment(attributes, attachment) { 8239 return this.setDocument(this.document.updateAttributesForAttachment(attributes, attachment)); 8240 } 8241 removeAttributeForAttachment(attribute, attachment) { 8242 return this.setDocument(this.document.removeAttributeForAttachment(attribute, attachment)); 8243 } 8244 8245 // Private 8246 8247 breakFormattedBlock(insertion) { 8248 let { 8249 document 8250 } = insertion; 8251 const { 8252 block 8253 } = insertion; 8254 let position = insertion.startPosition; 8255 let range = [position - 1, position]; 8256 if (block.getBlockBreakPosition() === insertion.startLocation.offset) { 8257 if (block.breaksOnReturn() && insertion.nextCharacter === "\n") { 8258 position += 1; 8259 } else { 8260 document = document.removeTextAtRange(range); 8261 } 8262 range = [position, position]; 8263 } else if (insertion.nextCharacter === "\n") { 8264 if (insertion.previousCharacter === "\n") { 8265 range = [position - 1, position + 1]; 8266 } else { 8267 range = [position, position + 1]; 8268 position += 1; 8269 } 8270 } else if (insertion.startLocation.offset - 1 !== 0) { 8271 position += 1; 8272 } 8273 const newDocument = new Document([block.removeLastAttribute().copyWithoutText()]); 8274 this.setDocument(document.insertDocumentAtRange(newDocument, range)); 8275 return this.setSelection(position); 8276 } 8277 getPreviousBlock() { 8278 const locationRange = this.getLocationRange(); 8279 if (locationRange) { 8280 const { 8281 index 8282 } = locationRange[0]; 8283 if (index > 0) { 8284 return this.document.getBlockAtIndex(index - 1); 8285 } 8286 } 8287 } 8288 getBlock() { 8289 const locationRange = this.getLocationRange(); 8290 if (locationRange) { 8291 return this.document.getBlockAtIndex(locationRange[0].index); 8292 } 8293 } 8294 getAttachmentAtRange(range) { 8295 const document = this.document.getDocumentAtRange(range); 8296 if (document.toString() === "".concat(OBJECT_REPLACEMENT_CHARACTER, "\n")) { 8297 return document.getAttachments()[0]; 8298 } 8299 } 8300 notifyDelegateOfCurrentAttributesChange() { 8301 var _this$delegate12, _this$delegate12$comp; 8302 return (_this$delegate12 = this.delegate) === null || _this$delegate12 === void 0 || (_this$delegate12$comp = _this$delegate12.compositionDidChangeCurrentAttributes) === null || _this$delegate12$comp === void 0 ? void 0 : _this$delegate12$comp.call(_this$delegate12, this.currentAttributes); 8303 } 8304 notifyDelegateOfInsertionAtRange(range) { 8305 var _this$delegate13, _this$delegate13$comp; 8306 return (_this$delegate13 = this.delegate) === null || _this$delegate13 === void 0 || (_this$delegate13$comp = _this$delegate13.compositionDidPerformInsertionAtRange) === null || _this$delegate13$comp === void 0 ? void 0 : _this$delegate13$comp.call(_this$delegate13, range); 8307 } 8308 translateUTF16PositionFromOffset(position, offset) { 8309 const utf16string = this.document.toUTF16String(); 8310 const utf16position = utf16string.offsetFromUCS2Offset(position); 8311 return utf16string.offsetToUCS2Offset(utf16position + offset); 8312 } 8313 } 8314 Composition.proxyMethod("getSelectionManager().getPointRange"); 8315 Composition.proxyMethod("getSelectionManager().setLocationRangeFromPointRange"); 8316 Composition.proxyMethod("getSelectionManager().createLocationRangeFromDOMRange"); 8317 Composition.proxyMethod("getSelectionManager().locationIsCursorTarget"); 8318 Composition.proxyMethod("getSelectionManager().selectionIsExpanded"); 8319 Composition.proxyMethod("delegate?.getSelectionManager"); 8320 8321 class UndoManager extends BasicObject { 8322 constructor(composition) { 8323 super(...arguments); 8324 this.composition = composition; 8325 this.undoEntries = []; 8326 this.redoEntries = []; 8327 } 8328 recordUndoEntry(description) { 8329 let { 8330 context, 8331 consolidatable 8332 } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 8333 const previousEntry = this.undoEntries.slice(-1)[0]; 8334 if (!consolidatable || !entryHasDescriptionAndContext(previousEntry, description, context)) { 8335 const undoEntry = this.createEntry({ 8336 description, 8337 context 8338 }); 8339 this.undoEntries.push(undoEntry); 8340 this.redoEntries = []; 8341 } 8342 } 8343 undo() { 8344 const undoEntry = this.undoEntries.pop(); 8345 if (undoEntry) { 8346 const redoEntry = this.createEntry(undoEntry); 8347 this.redoEntries.push(redoEntry); 8348 return this.composition.loadSnapshot(undoEntry.snapshot); 8349 } 8350 } 8351 redo() { 8352 const redoEntry = this.redoEntries.pop(); 8353 if (redoEntry) { 8354 const undoEntry = this.createEntry(redoEntry); 8355 this.undoEntries.push(undoEntry); 8356 return this.composition.loadSnapshot(redoEntry.snapshot); 8357 } 8358 } 8359 canUndo() { 8360 return this.undoEntries.length > 0; 8361 } 8362 canRedo() { 8363 return this.redoEntries.length > 0; 8364 } 8365 8366 // Private 8367 8368 createEntry() { 8369 let { 8370 description, 8371 context 8372 } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; 8373 return { 8374 description: description === null || description === void 0 ? void 0 : description.toString(), 8375 context: JSON.stringify(context), 8376 snapshot: this.composition.getSnapshot() 8377 }; 8378 } 8379 } 8380 const entryHasDescriptionAndContext = (entry, description, context) => (entry === null || entry === void 0 ? void 0 : entry.description) === (description === null || description === void 0 ? void 0 : description.toString()) && (entry === null || entry === void 0 ? void 0 : entry.context) === JSON.stringify(context); 8381 8382 const BLOCK_ATTRIBUTE_NAME = "attachmentGallery"; 8383 const TEXT_ATTRIBUTE_NAME = "presentation"; 8384 const TEXT_ATTRIBUTE_VALUE = "gallery"; 8385 class Filter { 8386 constructor(snapshot) { 8387 this.document = snapshot.document; 8388 this.selectedRange = snapshot.selectedRange; 8389 } 8390 perform() { 8391 this.removeBlockAttribute(); 8392 return this.applyBlockAttribute(); 8393 } 8394 getSnapshot() { 8395 return { 8396 document: this.document, 8397 selectedRange: this.selectedRange 8398 }; 8399 } 8400 8401 // Private 8402 8403 removeBlockAttribute() { 8404 return this.findRangesOfBlocks().map(range => this.document = this.document.removeAttributeAtRange(BLOCK_ATTRIBUTE_NAME, range)); 8405 } 8406 applyBlockAttribute() { 8407 let offset = 0; 8408 this.findRangesOfPieces().forEach(range => { 8409 if (range[1] - range[0] > 1) { 8410 range[0] += offset; 8411 range[1] += offset; 8412 if (this.document.getCharacterAtPosition(range[1]) !== "\n") { 8413 this.document = this.document.insertBlockBreakAtRange(range[1]); 8414 if (range[1] < this.selectedRange[1]) { 8415 this.moveSelectedRangeForward(); 8416 } 8417 range[1]++; 8418 offset++; 8419 } 8420 if (range[0] !== 0) { 8421 if (this.document.getCharacterAtPosition(range[0] - 1) !== "\n") { 8422 this.document = this.document.insertBlockBreakAtRange(range[0]); 8423 if (range[0] < this.selectedRange[0]) { 8424 this.moveSelectedRangeForward(); 8425 } 8426 range[0]++; 8427 offset++; 8428 } 8429 } 8430 this.document = this.document.applyBlockAttributeAtRange(BLOCK_ATTRIBUTE_NAME, true, range); 8431 } 8432 }); 8433 } 8434 findRangesOfBlocks() { 8435 return this.document.findRangesForBlockAttribute(BLOCK_ATTRIBUTE_NAME); 8436 } 8437 findRangesOfPieces() { 8438 return this.document.findRangesForTextAttribute(TEXT_ATTRIBUTE_NAME, { 8439 withValue: TEXT_ATTRIBUTE_VALUE 8440 }); 8441 } 8442 moveSelectedRangeForward() { 8443 this.selectedRange[0] += 1; 8444 this.selectedRange[1] += 1; 8445 } 8446 } 8447 8448 const attachmentGalleryFilter = function (snapshot) { 8449 const filter = new Filter(snapshot); 8450 filter.perform(); 8451 return filter.getSnapshot(); 8452 }; 8453 8454 const DEFAULT_FILTERS = [attachmentGalleryFilter]; 8455 class Editor { 8456 constructor(composition, selectionManager, element) { 8457 this.insertFiles = this.insertFiles.bind(this); 8458 this.composition = composition; 8459 this.selectionManager = selectionManager; 8460 this.element = element; 8461 this.undoManager = new UndoManager(this.composition); 8462 this.filters = DEFAULT_FILTERS.slice(0); 8463 } 8464 loadDocument(document) { 8465 return this.loadSnapshot({ 8466 document, 8467 selectedRange: [0, 0] 8468 }); 8469 } 8470 loadHTML() { 8471 let html = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ""; 8472 const document = HTMLParser.parse(html, { 8473 referenceElement: this.element 8474 }).getDocument(); 8475 return this.loadDocument(document); 8476 } 8477 loadJSON(_ref) { 8478 let { 8479 document, 8480 selectedRange 8481 } = _ref; 8482 document = Document.fromJSON(document); 8483 return this.loadSnapshot({ 8484 document, 8485 selectedRange 8486 }); 8487 } 8488 loadSnapshot(snapshot) { 8489 this.undoManager = new UndoManager(this.composition); 8490 return this.composition.loadSnapshot(snapshot); 8491 } 8492 getDocument() { 8493 return this.composition.document; 8494 } 8495 getSelectedDocument() { 8496 return this.composition.getSelectedDocument(); 8497 } 8498 getSnapshot() { 8499 return this.composition.getSnapshot(); 8500 } 8501 toJSON() { 8502 return this.getSnapshot(); 8503 } 8504 8505 // Document manipulation 8506 8507 deleteInDirection(direction) { 8508 return this.composition.deleteInDirection(direction); 8509 } 8510 insertAttachment(attachment) { 8511 return this.composition.insertAttachment(attachment); 8512 } 8513 insertAttachments(attachments) { 8514 return this.composition.insertAttachments(attachments); 8515 } 8516 insertDocument(document) { 8517 return this.composition.insertDocument(document); 8518 } 8519 insertFile(file) { 8520 return this.composition.insertFile(file); 8521 } 8522 insertFiles(files) { 8523 return this.composition.insertFiles(files); 8524 } 8525 insertHTML(html) { 8526 return this.composition.insertHTML(html); 8527 } 8528 insertString(string) { 8529 return this.composition.insertString(string); 8530 } 8531 insertText(text) { 8532 return this.composition.insertText(text); 8533 } 8534 insertLineBreak() { 8535 return this.composition.insertLineBreak(); 8536 } 8537 8538 // Selection 8539 8540 getSelectedRange() { 8541 return this.composition.getSelectedRange(); 8542 } 8543 getPosition() { 8544 return this.composition.getPosition(); 8545 } 8546 getClientRectAtPosition(position) { 8547 const locationRange = this.getDocument().locationRangeFromRange([position, position + 1]); 8548 return this.selectionManager.getClientRectAtLocationRange(locationRange); 8549 } 8550 expandSelectionInDirection(direction) { 8551 return this.composition.expandSelectionInDirection(direction); 8552 } 8553 moveCursorInDirection(direction) { 8554 return this.composition.moveCursorInDirection(direction); 8555 } 8556 setSelectedRange(selectedRange) { 8557 return this.composition.setSelectedRange(selectedRange); 8558 } 8559 8560 // Attributes 8561 8562 activateAttribute(name) { 8563 let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; 8564 return this.composition.setCurrentAttribute(name, value); 8565 } 8566 attributeIsActive(name) { 8567 return this.composition.hasCurrentAttribute(name); 8568 } 8569 canActivateAttribute(name) { 8570 return this.composition.canSetCurrentAttribute(name); 8571 } 8572 deactivateAttribute(name) { 8573 return this.composition.removeCurrentAttribute(name); 8574 } 8575 8576 // HTML attributes 8577 setHTMLAtributeAtPosition(position, name, value) { 8578 this.composition.setHTMLAtributeAtPosition(position, name, value); 8579 } 8580 8581 // Nesting level 8582 8583 canDecreaseNestingLevel() { 8584 return this.composition.canDecreaseNestingLevel(); 8585 } 8586 canIncreaseNestingLevel() { 8587 return this.composition.canIncreaseNestingLevel(); 8588 } 8589 decreaseNestingLevel() { 8590 if (this.canDecreaseNestingLevel()) { 8591 return this.composition.decreaseNestingLevel(); 8592 } 8593 } 8594 increaseNestingLevel() { 8595 if (this.canIncreaseNestingLevel()) { 8596 return this.composition.increaseNestingLevel(); 8597 } 8598 } 8599 8600 // Undo/redo 8601 8602 canRedo() { 8603 return this.undoManager.canRedo(); 8604 } 8605 canUndo() { 8606 return this.undoManager.canUndo(); 8607 } 8608 recordUndoEntry(description) { 8609 let { 8610 context, 8611 consolidatable 8612 } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 8613 return this.undoManager.recordUndoEntry(description, { 8614 context, 8615 consolidatable 8616 }); 8617 } 8618 redo() { 8619 if (this.canRedo()) { 8620 return this.undoManager.redo(); 8621 } 8622 } 8623 undo() { 8624 if (this.canUndo()) { 8625 return this.undoManager.undo(); 8626 } 8627 } 8628 } 8629 8630 /* eslint-disable 8631 no-var, 8632 prefer-const, 8633 */ 8634 class LocationMapper { 8635 constructor(element) { 8636 this.element = element; 8637 } 8638 findLocationFromContainerAndOffset(container, offset) { 8639 let { 8640 strict 8641 } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : { 8642 strict: true 8643 }; 8644 let childIndex = 0; 8645 let foundBlock = false; 8646 const location = { 8647 index: 0, 8648 offset: 0 8649 }; 8650 const attachmentElement = this.findAttachmentElementParentForNode(container); 8651 if (attachmentElement) { 8652 container = attachmentElement.parentNode; 8653 offset = findChildIndexOfNode(attachmentElement); 8654 } 8655 const walker = walkTree(this.element, { 8656 usingFilter: rejectAttachmentContents 8657 }); 8658 while (walker.nextNode()) { 8659 const node = walker.currentNode; 8660 if (node === container && nodeIsTextNode(container)) { 8661 if (!nodeIsCursorTarget(node)) { 8662 location.offset += offset; 8663 } 8664 break; 8665 } else { 8666 if (node.parentNode === container) { 8667 if (childIndex++ === offset) { 8668 break; 8669 } 8670 } else if (!elementContainsNode(container, node)) { 8671 if (childIndex > 0) { 8672 break; 8673 } 8674 } 8675 if (nodeIsBlockStart(node, { 8676 strict 8677 })) { 8678 if (foundBlock) { 8679 location.index++; 8680 } 8681 location.offset = 0; 8682 foundBlock = true; 8683 } else { 8684 location.offset += nodeLength(node); 8685 } 8686 } 8687 } 8688 return location; 8689 } 8690 findContainerAndOffsetFromLocation(location) { 8691 let container, offset; 8692 if (location.index === 0 && location.offset === 0) { 8693 container = this.element; 8694 offset = 0; 8695 while (container.firstChild) { 8696 container = container.firstChild; 8697 if (nodeIsBlockContainer(container)) { 8698 offset = 1; 8699 break; 8700 } 8701 } 8702 return [container, offset]; 8703 } 8704 let [node, nodeOffset] = this.findNodeAndOffsetFromLocation(location); 8705 if (!node) return; 8706 if (nodeIsTextNode(node)) { 8707 if (nodeLength(node) === 0) { 8708 container = node.parentNode.parentNode; 8709 offset = findChildIndexOfNode(node.parentNode); 8710 if (nodeIsCursorTarget(node, { 8711 name: "right" 8712 })) { 8713 offset++; 8714 } 8715 } else { 8716 container = node; 8717 offset = location.offset - nodeOffset; 8718 } 8719 } else { 8720 container = node.parentNode; 8721 if (!nodeIsBlockStart(node.previousSibling)) { 8722 if (!nodeIsBlockContainer(container)) { 8723 while (node === container.lastChild) { 8724 node = container; 8725 container = container.parentNode; 8726 if (nodeIsBlockContainer(container)) { 8727 break; 8728 } 8729 } 8730 } 8731 } 8732 offset = findChildIndexOfNode(node); 8733 if (location.offset !== 0) { 8734 offset++; 8735 } 8736 } 8737 return [container, offset]; 8738 } 8739 findNodeAndOffsetFromLocation(location) { 8740 let node, nodeOffset; 8741 let offset = 0; 8742 for (const currentNode of this.getSignificantNodesForIndex(location.index)) { 8743 const length = nodeLength(currentNode); 8744 if (location.offset <= offset + length) { 8745 if (nodeIsTextNode(currentNode)) { 8746 node = currentNode; 8747 nodeOffset = offset; 8748 if (location.offset === nodeOffset && nodeIsCursorTarget(node)) { 8749 break; 8750 } 8751 } else if (!node) { 8752 node = currentNode; 8753 nodeOffset = offset; 8754 } 8755 } 8756 offset += length; 8757 if (offset > location.offset) { 8758 break; 8759 } 8760 } 8761 return [node, nodeOffset]; 8762 } 8763 8764 // Private 8765 8766 findAttachmentElementParentForNode(node) { 8767 while (node && node !== this.element) { 8768 if (nodeIsAttachmentElement(node)) { 8769 return node; 8770 } 8771 node = node.parentNode; 8772 } 8773 } 8774 getSignificantNodesForIndex(index) { 8775 const nodes = []; 8776 const walker = walkTree(this.element, { 8777 usingFilter: acceptSignificantNodes 8778 }); 8779 let recordingNodes = false; 8780 while (walker.nextNode()) { 8781 const node = walker.currentNode; 8782 if (nodeIsBlockStartComment(node)) { 8783 var blockIndex; 8784 if (blockIndex != null) { 8785 blockIndex++; 8786 } else { 8787 blockIndex = 0; 8788 } 8789 if (blockIndex === index) { 8790 recordingNodes = true; 8791 } else if (recordingNodes) { 8792 break; 8793 } 8794 } else if (recordingNodes) { 8795 nodes.push(node); 8796 } 8797 } 8798 return nodes; 8799 } 8800 } 8801 const nodeLength = function (node) { 8802 if (node.nodeType === Node.TEXT_NODE) { 8803 if (nodeIsCursorTarget(node)) { 8804 return 0; 8805 } else { 8806 const string = node.textContent; 8807 return string.length; 8808 } 8809 } else if (tagName(node) === "br" || nodeIsAttachmentElement(node)) { 8810 return 1; 8811 } else { 8812 return 0; 8813 } 8814 }; 8815 const acceptSignificantNodes = function (node) { 8816 if (rejectEmptyTextNodes(node) === NodeFilter.FILTER_ACCEPT) { 8817 return rejectAttachmentContents(node); 8818 } else { 8819 return NodeFilter.FILTER_REJECT; 8820 } 8821 }; 8822 const rejectEmptyTextNodes = function (node) { 8823 if (nodeIsEmptyTextNode(node)) { 8824 return NodeFilter.FILTER_REJECT; 8825 } else { 8826 return NodeFilter.FILTER_ACCEPT; 8827 } 8828 }; 8829 const rejectAttachmentContents = function (node) { 8830 if (nodeIsAttachmentElement(node.parentNode)) { 8831 return NodeFilter.FILTER_REJECT; 8832 } else { 8833 return NodeFilter.FILTER_ACCEPT; 8834 } 8835 }; 8836 8837 /* eslint-disable 8838 id-length, 8839 no-empty, 8840 */ 8841 class PointMapper { 8842 createDOMRangeFromPoint(_ref) { 8843 let { 8844 x, 8845 y 8846 } = _ref; 8847 let domRange; 8848 if (document.caretPositionFromPoint) { 8849 const { 8850 offsetNode, 8851 offset 8852 } = document.caretPositionFromPoint(x, y); 8853 domRange = document.createRange(); 8854 domRange.setStart(offsetNode, offset); 8855 return domRange; 8856 } else if (document.caretRangeFromPoint) { 8857 return document.caretRangeFromPoint(x, y); 8858 } else if (document.body.createTextRange) { 8859 const originalDOMRange = getDOMRange(); 8860 try { 8861 // IE 11 throws "Unspecified error" when using moveToPoint 8862 // during a drag-and-drop operation. 8863 const textRange = document.body.createTextRange(); 8864 textRange.moveToPoint(x, y); 8865 textRange.select(); 8866 } catch (error) {} 8867 domRange = getDOMRange(); 8868 setDOMRange(originalDOMRange); 8869 return domRange; 8870 } 8871 } 8872 getClientRectsForDOMRange(domRange) { 8873 const array = Array.from(domRange.getClientRects()); 8874 const start = array[0]; 8875 const end = array[array.length - 1]; 8876 return [start, end]; 8877 } 8878 } 8879 8880 /* eslint-disable 8881 */ 8882 class SelectionManager extends BasicObject { 8883 constructor(element) { 8884 super(...arguments); 8885 this.didMouseDown = this.didMouseDown.bind(this); 8886 this.selectionDidChange = this.selectionDidChange.bind(this); 8887 this.element = element; 8888 this.locationMapper = new LocationMapper(this.element); 8889 this.pointMapper = new PointMapper(); 8890 this.lockCount = 0; 8891 handleEvent("mousedown", { 8892 onElement: this.element, 8893 withCallback: this.didMouseDown 8894 }); 8895 } 8896 getLocationRange() { 8897 let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; 8898 if (options.strict === false) { 8899 return this.createLocationRangeFromDOMRange(getDOMRange()); 8900 } else if (options.ignoreLock) { 8901 return this.currentLocationRange; 8902 } else if (this.lockedLocationRange) { 8903 return this.lockedLocationRange; 8904 } else { 8905 return this.currentLocationRange; 8906 } 8907 } 8908 setLocationRange(locationRange) { 8909 if (this.lockedLocationRange) return; 8910 locationRange = normalizeRange(locationRange); 8911 const domRange = this.createDOMRangeFromLocationRange(locationRange); 8912 if (domRange) { 8913 setDOMRange(domRange); 8914 this.updateCurrentLocationRange(locationRange); 8915 } 8916 } 8917 setLocationRangeFromPointRange(pointRange) { 8918 pointRange = normalizeRange(pointRange); 8919 const startLocation = this.getLocationAtPoint(pointRange[0]); 8920 const endLocation = this.getLocationAtPoint(pointRange[1]); 8921 this.setLocationRange([startLocation, endLocation]); 8922 } 8923 getClientRectAtLocationRange(locationRange) { 8924 const domRange = this.createDOMRangeFromLocationRange(locationRange); 8925 if (domRange) { 8926 return this.getClientRectsForDOMRange(domRange)[1]; 8927 } 8928 } 8929 locationIsCursorTarget(location) { 8930 const node = Array.from(this.findNodeAndOffsetFromLocation(location))[0]; 8931 return nodeIsCursorTarget(node); 8932 } 8933 lock() { 8934 if (this.lockCount++ === 0) { 8935 this.updateCurrentLocationRange(); 8936 this.lockedLocationRange = this.getLocationRange(); 8937 } 8938 } 8939 unlock() { 8940 if (--this.lockCount === 0) { 8941 const { 8942 lockedLocationRange 8943 } = this; 8944 this.lockedLocationRange = null; 8945 if (lockedLocationRange != null) { 8946 return this.setLocationRange(lockedLocationRange); 8947 } 8948 } 8949 } 8950 clearSelection() { 8951 var _getDOMSelection; 8952 return (_getDOMSelection = getDOMSelection()) === null || _getDOMSelection === void 0 ? void 0 : _getDOMSelection.removeAllRanges(); 8953 } 8954 selectionIsCollapsed() { 8955 var _getDOMRange; 8956 return ((_getDOMRange = getDOMRange()) === null || _getDOMRange === void 0 ? void 0 : _getDOMRange.collapsed) === true; 8957 } 8958 selectionIsExpanded() { 8959 return !this.selectionIsCollapsed(); 8960 } 8961 createLocationRangeFromDOMRange(domRange, options) { 8962 if (domRange == null || !this.domRangeWithinElement(domRange)) return; 8963 const start = this.findLocationFromContainerAndOffset(domRange.startContainer, domRange.startOffset, options); 8964 if (!start) return; 8965 const end = domRange.collapsed ? undefined : this.findLocationFromContainerAndOffset(domRange.endContainer, domRange.endOffset, options); 8966 return normalizeRange([start, end]); 8967 } 8968 didMouseDown() { 8969 return this.pauseTemporarily(); 8970 } 8971 pauseTemporarily() { 8972 let resumeHandlers; 8973 this.paused = true; 8974 const resume = () => { 8975 this.paused = false; 8976 clearTimeout(resumeTimeout); 8977 Array.from(resumeHandlers).forEach(handler => { 8978 handler.destroy(); 8979 }); 8980 if (elementContainsNode(document, this.element)) { 8981 return this.selectionDidChange(); 8982 } 8983 }; 8984 const resumeTimeout = setTimeout(resume, 200); 8985 resumeHandlers = ["mousemove", "keydown"].map(eventName => handleEvent(eventName, { 8986 onElement: document, 8987 withCallback: resume 8988 })); 8989 } 8990 selectionDidChange() { 8991 if (!this.paused && !innerElementIsActive(this.element)) { 8992 return this.updateCurrentLocationRange(); 8993 } 8994 } 8995 updateCurrentLocationRange(locationRange) { 8996 if (locationRange != null ? locationRange : locationRange = this.createLocationRangeFromDOMRange(getDOMRange())) { 8997 if (!rangesAreEqual(locationRange, this.currentLocationRange)) { 8998 var _this$delegate, _this$delegate$locati; 8999 this.currentLocationRange = locationRange; 9000 return (_this$delegate = this.delegate) === null || _this$delegate === void 0 || (_this$delegate$locati = _this$delegate.locationRangeDidChange) === null || _this$delegate$locati === void 0 ? void 0 : _this$delegate$locati.call(_this$delegate, this.currentLocationRange.slice(0)); 9001 } 9002 } 9003 } 9004 createDOMRangeFromLocationRange(locationRange) { 9005 const rangeStart = this.findContainerAndOffsetFromLocation(locationRange[0]); 9006 const rangeEnd = rangeIsCollapsed(locationRange) ? rangeStart : this.findContainerAndOffsetFromLocation(locationRange[1]) || rangeStart; 9007 if (rangeStart != null && rangeEnd != null) { 9008 const domRange = document.createRange(); 9009 domRange.setStart(...Array.from(rangeStart || [])); 9010 domRange.setEnd(...Array.from(rangeEnd || [])); 9011 return domRange; 9012 } 9013 } 9014 getLocationAtPoint(point) { 9015 const domRange = this.createDOMRangeFromPoint(point); 9016 if (domRange) { 9017 var _this$createLocationR; 9018 return (_this$createLocationR = this.createLocationRangeFromDOMRange(domRange)) === null || _this$createLocationR === void 0 ? void 0 : _this$createLocationR[0]; 9019 } 9020 } 9021 domRangeWithinElement(domRange) { 9022 if (domRange.collapsed) { 9023 return elementContainsNode(this.element, domRange.startContainer); 9024 } else { 9025 return elementContainsNode(this.element, domRange.startContainer) && elementContainsNode(this.element, domRange.endContainer); 9026 } 9027 } 9028 } 9029 SelectionManager.proxyMethod("locationMapper.findLocationFromContainerAndOffset"); 9030 SelectionManager.proxyMethod("locationMapper.findContainerAndOffsetFromLocation"); 9031 SelectionManager.proxyMethod("locationMapper.findNodeAndOffsetFromLocation"); 9032 SelectionManager.proxyMethod("pointMapper.createDOMRangeFromPoint"); 9033 SelectionManager.proxyMethod("pointMapper.getClientRectsForDOMRange"); 9034 9035 var models = /*#__PURE__*/Object.freeze({ 9036 __proto__: null, 9037 Attachment: Attachment, 9038 AttachmentManager: AttachmentManager, 9039 AttachmentPiece: AttachmentPiece, 9040 Block: Block, 9041 Composition: Composition, 9042 Document: Document, 9043 Editor: Editor, 9044 HTMLParser: HTMLParser, 9045 HTMLSanitizer: HTMLSanitizer, 9046 LineBreakInsertion: LineBreakInsertion, 9047 LocationMapper: LocationMapper, 9048 ManagedAttachment: ManagedAttachment, 9049 Piece: Piece, 9050 PointMapper: PointMapper, 9051 SelectionManager: SelectionManager, 9052 SplittableList: SplittableList, 9053 StringPiece: StringPiece, 9054 Text: Text, 9055 UndoManager: UndoManager 9056 }); 9057 9058 var views = /*#__PURE__*/Object.freeze({ 9059 __proto__: null, 9060 ObjectView: ObjectView, 9061 AttachmentView: AttachmentView, 9062 BlockView: BlockView, 9063 DocumentView: DocumentView, 9064 PieceView: PieceView, 9065 PreviewableAttachmentView: PreviewableAttachmentView, 9066 TextView: TextView 9067 }); 9068 9069 const { 9070 lang, 9071 css, 9072 keyNames: keyNames$1 9073 } = config; 9074 const undoable = function (fn) { 9075 return function () { 9076 const commands = fn.apply(this, arguments); 9077 commands.do(); 9078 if (!this.undos) { 9079 this.undos = []; 9080 } 9081 this.undos.push(commands.undo); 9082 }; 9083 }; 9084 class AttachmentEditorController extends BasicObject { 9085 constructor(attachmentPiece, _element, container) { 9086 let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; 9087 super(...arguments); 9088 // Installing and uninstalling 9089 _defineProperty(this, "makeElementMutable", undoable(() => { 9090 return { 9091 do: () => { 9092 this.element.dataset.trixMutable = true; 9093 }, 9094 undo: () => delete this.element.dataset.trixMutable 9095 }; 9096 })); 9097 _defineProperty(this, "addToolbar", undoable(() => { 9098 // <div class="#{css.attachmentMetadataContainer}" data-trix-mutable="true"> 9099 // <div class="trix-button-row"> 9100 // <span class="trix-button-group trix-button-group--actions"> 9101 // <button type="button" class="trix-button trix-button--remove" title="#{lang.remove}" data-trix-action="remove">#{lang.remove}</button> 9102 // </span> 9103 // </div> 9104 // </div> 9105 const element = makeElement({ 9106 tagName: "div", 9107 className: css.attachmentToolbar, 9108 data: { 9109 trixMutable: true 9110 }, 9111 childNodes: makeElement({ 9112 tagName: "div", 9113 className: "trix-button-row", 9114 childNodes: makeElement({ 9115 tagName: "span", 9116 className: "trix-button-group trix-button-group--actions", 9117 childNodes: makeElement({ 9118 tagName: "button", 9119 className: "trix-button trix-button--remove", 9120 textContent: lang.remove, 9121 attributes: { 9122 title: lang.remove 9123 }, 9124 data: { 9125 trixAction: "remove" 9126 } 9127 }) 9128 }) 9129 }) 9130 }); 9131 if (this.attachment.isPreviewable()) { 9132 // <div class="#{css.attachmentMetadataContainer}"> 9133 // <span class="#{css.attachmentMetadata}"> 9134 // <span class="#{css.attachmentName}" title="#{name}">#{name}</span> 9135 // <span class="#{css.attachmentSize}">#{size}</span> 9136 // </span> 9137 // </div> 9138 element.appendChild(makeElement({ 9139 tagName: "div", 9140 className: css.attachmentMetadataContainer, 9141 childNodes: makeElement({ 9142 tagName: "span", 9143 className: css.attachmentMetadata, 9144 childNodes: [makeElement({ 9145 tagName: "span", 9146 className: css.attachmentName, 9147 textContent: this.attachment.getFilename(), 9148 attributes: { 9149 title: this.attachment.getFilename() 9150 } 9151 }), makeElement({ 9152 tagName: "span", 9153 className: css.attachmentSize, 9154 textContent: this.attachment.getFormattedFilesize() 9155 })] 9156 }) 9157 })); 9158 } 9159 handleEvent("click", { 9160 onElement: element, 9161 withCallback: this.didClickToolbar 9162 }); 9163 handleEvent("click", { 9164 onElement: element, 9165 matchingSelector: "[data-trix-action]", 9166 withCallback: this.didClickActionButton 9167 }); 9168 triggerEvent("trix-attachment-before-toolbar", { 9169 onElement: this.element, 9170 attributes: { 9171 toolbar: element, 9172 attachment: this.attachment 9173 } 9174 }); 9175 return { 9176 do: () => this.element.appendChild(element), 9177 undo: () => removeNode(element) 9178 }; 9179 })); 9180 _defineProperty(this, "installCaptionEditor", undoable(() => { 9181 const textarea = makeElement({ 9182 tagName: "textarea", 9183 className: css.attachmentCaptionEditor, 9184 attributes: { 9185 placeholder: lang.captionPlaceholder 9186 }, 9187 data: { 9188 trixMutable: true 9189 } 9190 }); 9191 textarea.value = this.attachmentPiece.getCaption(); 9192 const textareaClone = textarea.cloneNode(); 9193 textareaClone.classList.add("trix-autoresize-clone"); 9194 textareaClone.tabIndex = -1; 9195 const autoresize = function () { 9196 textareaClone.value = textarea.value; 9197 textarea.style.height = textareaClone.scrollHeight + "px"; 9198 }; 9199 handleEvent("input", { 9200 onElement: textarea, 9201 withCallback: autoresize 9202 }); 9203 handleEvent("input", { 9204 onElement: textarea, 9205 withCallback: this.didInputCaption 9206 }); 9207 handleEvent("keydown", { 9208 onElement: textarea, 9209 withCallback: this.didKeyDownCaption 9210 }); 9211 handleEvent("change", { 9212 onElement: textarea, 9213 withCallback: this.didChangeCaption 9214 }); 9215 handleEvent("blur", { 9216 onElement: textarea, 9217 withCallback: this.didBlurCaption 9218 }); 9219 const figcaption = this.element.querySelector("figcaption"); 9220 const editingFigcaption = figcaption.cloneNode(); 9221 return { 9222 do: () => { 9223 figcaption.style.display = "none"; 9224 editingFigcaption.appendChild(textarea); 9225 editingFigcaption.appendChild(textareaClone); 9226 editingFigcaption.classList.add("".concat(css.attachmentCaption, "--editing")); 9227 figcaption.parentElement.insertBefore(editingFigcaption, figcaption); 9228 autoresize(); 9229 if (this.options.editCaption) { 9230 return defer(() => textarea.focus()); 9231 } 9232 }, 9233 undo() { 9234 removeNode(editingFigcaption); 9235 figcaption.style.display = null; 9236 } 9237 }; 9238 })); 9239 this.didClickToolbar = this.didClickToolbar.bind(this); 9240 this.didClickActionButton = this.didClickActionButton.bind(this); 9241 this.didKeyDownCaption = this.didKeyDownCaption.bind(this); 9242 this.didInputCaption = this.didInputCaption.bind(this); 9243 this.didChangeCaption = this.didChangeCaption.bind(this); 9244 this.didBlurCaption = this.didBlurCaption.bind(this); 9245 this.attachmentPiece = attachmentPiece; 9246 this.element = _element; 9247 this.container = container; 9248 this.options = options; 9249 this.attachment = this.attachmentPiece.attachment; 9250 if (tagName(this.element) === "a") { 9251 this.element = this.element.firstChild; 9252 } 9253 this.install(); 9254 } 9255 install() { 9256 this.makeElementMutable(); 9257 this.addToolbar(); 9258 if (this.attachment.isPreviewable()) { 9259 this.installCaptionEditor(); 9260 } 9261 } 9262 uninstall() { 9263 var _this$delegate; 9264 let undo = this.undos.pop(); 9265 this.savePendingCaption(); 9266 while (undo) { 9267 undo(); 9268 undo = this.undos.pop(); 9269 } 9270 (_this$delegate = this.delegate) === null || _this$delegate === void 0 || _this$delegate.didUninstallAttachmentEditor(this); 9271 } 9272 9273 // Private 9274 9275 savePendingCaption() { 9276 if (this.pendingCaption != null) { 9277 const caption = this.pendingCaption; 9278 this.pendingCaption = null; 9279 if (caption) { 9280 var _this$delegate2, _this$delegate2$attac; 9281 (_this$delegate2 = this.delegate) === null || _this$delegate2 === void 0 || (_this$delegate2$attac = _this$delegate2.attachmentEditorDidRequestUpdatingAttributesForAttachment) === null || _this$delegate2$attac === void 0 || _this$delegate2$attac.call(_this$delegate2, { 9282 caption 9283 }, this.attachment); 9284 } else { 9285 var _this$delegate3, _this$delegate3$attac; 9286 (_this$delegate3 = this.delegate) === null || _this$delegate3 === void 0 || (_this$delegate3$attac = _this$delegate3.attachmentEditorDidRequestRemovingAttributeForAttachment) === null || _this$delegate3$attac === void 0 || _this$delegate3$attac.call(_this$delegate3, "caption", this.attachment); 9287 } 9288 } 9289 } 9290 // Event handlers 9291 9292 didClickToolbar(event) { 9293 event.preventDefault(); 9294 return event.stopPropagation(); 9295 } 9296 didClickActionButton(event) { 9297 var _this$delegate4; 9298 const action = event.target.getAttribute("data-trix-action"); 9299 switch (action) { 9300 case "remove": 9301 return (_this$delegate4 = this.delegate) === null || _this$delegate4 === void 0 ? void 0 : _this$delegate4.attachmentEditorDidRequestRemovalOfAttachment(this.attachment); 9302 } 9303 } 9304 didKeyDownCaption(event) { 9305 if (keyNames$1[event.keyCode] === "return") { 9306 var _this$delegate5, _this$delegate5$attac; 9307 event.preventDefault(); 9308 this.savePendingCaption(); 9309 return (_this$delegate5 = this.delegate) === null || _this$delegate5 === void 0 || (_this$delegate5$attac = _this$delegate5.attachmentEditorDidRequestDeselectingAttachment) === null || _this$delegate5$attac === void 0 ? void 0 : _this$delegate5$attac.call(_this$delegate5, this.attachment); 9310 } 9311 } 9312 didInputCaption(event) { 9313 this.pendingCaption = event.target.value.replace(/\s/g, " ").trim(); 9314 } 9315 didChangeCaption(event) { 9316 return this.savePendingCaption(); 9317 } 9318 didBlurCaption(event) { 9319 return this.savePendingCaption(); 9320 } 9321 } 9322 9323 class CompositionController extends BasicObject { 9324 constructor(element, composition) { 9325 super(...arguments); 9326 this.didFocus = this.didFocus.bind(this); 9327 this.didBlur = this.didBlur.bind(this); 9328 this.didClickAttachment = this.didClickAttachment.bind(this); 9329 this.element = element; 9330 this.composition = composition; 9331 this.documentView = new DocumentView(this.composition.document, { 9332 element: this.element 9333 }); 9334 handleEvent("focus", { 9335 onElement: this.element, 9336 withCallback: this.didFocus 9337 }); 9338 handleEvent("blur", { 9339 onElement: this.element, 9340 withCallback: this.didBlur 9341 }); 9342 handleEvent("click", { 9343 onElement: this.element, 9344 matchingSelector: "a[contenteditable=false]", 9345 preventDefault: true 9346 }); 9347 handleEvent("mousedown", { 9348 onElement: this.element, 9349 matchingSelector: attachmentSelector, 9350 withCallback: this.didClickAttachment 9351 }); 9352 handleEvent("click", { 9353 onElement: this.element, 9354 matchingSelector: "a".concat(attachmentSelector), 9355 preventDefault: true 9356 }); 9357 } 9358 didFocus(event) { 9359 var _this$blurPromise; 9360 const perform = () => { 9361 if (!this.focused) { 9362 var _this$delegate, _this$delegate$compos; 9363 this.focused = true; 9364 return (_this$delegate = this.delegate) === null || _this$delegate === void 0 || (_this$delegate$compos = _this$delegate.compositionControllerDidFocus) === null || _this$delegate$compos === void 0 ? void 0 : _this$delegate$compos.call(_this$delegate); 9365 } 9366 }; 9367 return ((_this$blurPromise = this.blurPromise) === null || _this$blurPromise === void 0 ? void 0 : _this$blurPromise.then(perform)) || perform(); 9368 } 9369 didBlur(event) { 9370 this.blurPromise = new Promise(resolve => { 9371 return defer(() => { 9372 if (!innerElementIsActive(this.element)) { 9373 var _this$delegate2, _this$delegate2$compo; 9374 this.focused = null; 9375 (_this$delegate2 = this.delegate) === null || _this$delegate2 === void 0 || (_this$delegate2$compo = _this$delegate2.compositionControllerDidBlur) === null || _this$delegate2$compo === void 0 || _this$delegate2$compo.call(_this$delegate2); 9376 } 9377 this.blurPromise = null; 9378 return resolve(); 9379 }); 9380 }); 9381 } 9382 didClickAttachment(event, target) { 9383 var _this$delegate3, _this$delegate3$compo; 9384 const attachment = this.findAttachmentForElement(target); 9385 const editCaption = !!findClosestElementFromNode(event.target, { 9386 matchingSelector: "figcaption" 9387 }); 9388 return (_this$delegate3 = this.delegate) === null || _this$delegate3 === void 0 || (_this$delegate3$compo = _this$delegate3.compositionControllerDidSelectAttachment) === null || _this$delegate3$compo === void 0 ? void 0 : _this$delegate3$compo.call(_this$delegate3, attachment, { 9389 editCaption 9390 }); 9391 } 9392 getSerializableElement() { 9393 if (this.isEditingAttachment()) { 9394 return this.documentView.shadowElement; 9395 } else { 9396 return this.element; 9397 } 9398 } 9399 render() { 9400 var _this$delegate6, _this$delegate6$compo; 9401 if (this.revision !== this.composition.revision) { 9402 this.documentView.setDocument(this.composition.document); 9403 this.documentView.render(); 9404 this.revision = this.composition.revision; 9405 } 9406 if (this.canSyncDocumentView() && !this.documentView.isSynced()) { 9407 var _this$delegate4, _this$delegate4$compo, _this$delegate5, _this$delegate5$compo; 9408 (_this$delegate4 = this.delegate) === null || _this$delegate4 === void 0 || (_this$delegate4$compo = _this$delegate4.compositionControllerWillSyncDocumentView) === null || _this$delegate4$compo === void 0 || _this$delegate4$compo.call(_this$delegate4); 9409 this.documentView.sync(); 9410 (_this$delegate5 = this.delegate) === null || _this$delegate5 === void 0 || (_this$delegate5$compo = _this$delegate5.compositionControllerDidSyncDocumentView) === null || _this$delegate5$compo === void 0 || _this$delegate5$compo.call(_this$delegate5); 9411 } 9412 return (_this$delegate6 = this.delegate) === null || _this$delegate6 === void 0 || (_this$delegate6$compo = _this$delegate6.compositionControllerDidRender) === null || _this$delegate6$compo === void 0 ? void 0 : _this$delegate6$compo.call(_this$delegate6); 9413 } 9414 rerenderViewForObject(object) { 9415 this.invalidateViewForObject(object); 9416 return this.render(); 9417 } 9418 invalidateViewForObject(object) { 9419 return this.documentView.invalidateViewForObject(object); 9420 } 9421 isViewCachingEnabled() { 9422 return this.documentView.isViewCachingEnabled(); 9423 } 9424 enableViewCaching() { 9425 return this.documentView.enableViewCaching(); 9426 } 9427 disableViewCaching() { 9428 return this.documentView.disableViewCaching(); 9429 } 9430 refreshViewCache() { 9431 return this.documentView.garbageCollectCachedViews(); 9432 } 9433 9434 // Attachment editor management 9435 9436 isEditingAttachment() { 9437 return !!this.attachmentEditor; 9438 } 9439 installAttachmentEditorForAttachment(attachment, options) { 9440 var _this$attachmentEdito; 9441 if (((_this$attachmentEdito = this.attachmentEditor) === null || _this$attachmentEdito === void 0 ? void 0 : _this$attachmentEdito.attachment) === attachment) return; 9442 const element = this.documentView.findElementForObject(attachment); 9443 if (!element) return; 9444 this.uninstallAttachmentEditor(); 9445 const attachmentPiece = this.composition.document.getAttachmentPieceForAttachment(attachment); 9446 this.attachmentEditor = new AttachmentEditorController(attachmentPiece, element, this.element, options); 9447 this.attachmentEditor.delegate = this; 9448 } 9449 uninstallAttachmentEditor() { 9450 var _this$attachmentEdito2; 9451 return (_this$attachmentEdito2 = this.attachmentEditor) === null || _this$attachmentEdito2 === void 0 ? void 0 : _this$attachmentEdito2.uninstall(); 9452 } 9453 9454 // Attachment controller delegate 9455 9456 didUninstallAttachmentEditor() { 9457 this.attachmentEditor = null; 9458 return this.render(); 9459 } 9460 attachmentEditorDidRequestUpdatingAttributesForAttachment(attributes, attachment) { 9461 var _this$delegate7, _this$delegate7$compo; 9462 (_this$delegate7 = this.delegate) === null || _this$delegate7 === void 0 || (_this$delegate7$compo = _this$delegate7.compositionControllerWillUpdateAttachment) === null || _this$delegate7$compo === void 0 || _this$delegate7$compo.call(_this$delegate7, attachment); 9463 return this.composition.updateAttributesForAttachment(attributes, attachment); 9464 } 9465 attachmentEditorDidRequestRemovingAttributeForAttachment(attribute, attachment) { 9466 var _this$delegate8, _this$delegate8$compo; 9467 (_this$delegate8 = this.delegate) === null || _this$delegate8 === void 0 || (_this$delegate8$compo = _this$delegate8.compositionControllerWillUpdateAttachment) === null || _this$delegate8$compo === void 0 || _this$delegate8$compo.call(_this$delegate8, attachment); 9468 return this.composition.removeAttributeForAttachment(attribute, attachment); 9469 } 9470 attachmentEditorDidRequestRemovalOfAttachment(attachment) { 9471 var _this$delegate9, _this$delegate9$compo; 9472 return (_this$delegate9 = this.delegate) === null || _this$delegate9 === void 0 || (_this$delegate9$compo = _this$delegate9.compositionControllerDidRequestRemovalOfAttachment) === null || _this$delegate9$compo === void 0 ? void 0 : _this$delegate9$compo.call(_this$delegate9, attachment); 9473 } 9474 attachmentEditorDidRequestDeselectingAttachment(attachment) { 9475 var _this$delegate10, _this$delegate10$comp; 9476 return (_this$delegate10 = this.delegate) === null || _this$delegate10 === void 0 || (_this$delegate10$comp = _this$delegate10.compositionControllerDidRequestDeselectingAttachment) === null || _this$delegate10$comp === void 0 ? void 0 : _this$delegate10$comp.call(_this$delegate10, attachment); 9477 } 9478 9479 // Private 9480 9481 canSyncDocumentView() { 9482 return !this.isEditingAttachment(); 9483 } 9484 findAttachmentForElement(element) { 9485 return this.composition.document.getAttachmentById(parseInt(element.dataset.trixId, 10)); 9486 } 9487 } 9488 9489 class Controller extends BasicObject {} 9490 9491 const mutableAttributeName = "data-trix-mutable"; 9492 const mutableSelector = "[".concat(mutableAttributeName, "]"); 9493 const options = { 9494 attributes: true, 9495 childList: true, 9496 characterData: true, 9497 characterDataOldValue: true, 9498 subtree: true 9499 }; 9500 class MutationObserver extends BasicObject { 9501 constructor(element) { 9502 super(element); 9503 this.didMutate = this.didMutate.bind(this); 9504 this.element = element; 9505 this.observer = new window.MutationObserver(this.didMutate); 9506 this.start(); 9507 } 9508 start() { 9509 this.reset(); 9510 return this.observer.observe(this.element, options); 9511 } 9512 stop() { 9513 return this.observer.disconnect(); 9514 } 9515 didMutate(mutations) { 9516 this.mutations.push(...Array.from(this.findSignificantMutations(mutations) || [])); 9517 if (this.mutations.length) { 9518 var _this$delegate, _this$delegate$elemen; 9519 (_this$delegate = this.delegate) === null || _this$delegate === void 0 || (_this$delegate$elemen = _this$delegate.elementDidMutate) === null || _this$delegate$elemen === void 0 || _this$delegate$elemen.call(_this$delegate, this.getMutationSummary()); 9520 return this.reset(); 9521 } 9522 } 9523 9524 // Private 9525 9526 reset() { 9527 this.mutations = []; 9528 } 9529 findSignificantMutations(mutations) { 9530 return mutations.filter(mutation => { 9531 return this.mutationIsSignificant(mutation); 9532 }); 9533 } 9534 mutationIsSignificant(mutation) { 9535 if (this.nodeIsMutable(mutation.target)) { 9536 return false; 9537 } 9538 for (const node of Array.from(this.nodesModifiedByMutation(mutation))) { 9539 if (this.nodeIsSignificant(node)) return true; 9540 } 9541 return false; 9542 } 9543 nodeIsSignificant(node) { 9544 return node !== this.element && !this.nodeIsMutable(node) && !nodeIsEmptyTextNode(node); 9545 } 9546 nodeIsMutable(node) { 9547 return findClosestElementFromNode(node, { 9548 matchingSelector: mutableSelector 9549 }); 9550 } 9551 nodesModifiedByMutation(mutation) { 9552 const nodes = []; 9553 switch (mutation.type) { 9554 case "attributes": 9555 if (mutation.attributeName !== mutableAttributeName) { 9556 nodes.push(mutation.target); 9557 } 9558 break; 9559 case "characterData": 9560 // Changes to text nodes should consider the parent element 9561 nodes.push(mutation.target.parentNode); 9562 nodes.push(mutation.target); 9563 break; 9564 case "childList": 9565 // Consider each added or removed node 9566 nodes.push(...Array.from(mutation.addedNodes || [])); 9567 nodes.push(...Array.from(mutation.removedNodes || [])); 9568 break; 9569 } 9570 return nodes; 9571 } 9572 getMutationSummary() { 9573 return this.getTextMutationSummary(); 9574 } 9575 getTextMutationSummary() { 9576 const { 9577 additions, 9578 deletions 9579 } = this.getTextChangesFromCharacterData(); 9580 const textChanges = this.getTextChangesFromChildList(); 9581 Array.from(textChanges.additions).forEach(addition => { 9582 if (!Array.from(additions).includes(addition)) { 9583 additions.push(addition); 9584 } 9585 }); 9586 deletions.push(...Array.from(textChanges.deletions || [])); 9587 const summary = {}; 9588 const added = additions.join(""); 9589 if (added) { 9590 summary.textAdded = added; 9591 } 9592 const deleted = deletions.join(""); 9593 if (deleted) { 9594 summary.textDeleted = deleted; 9595 } 9596 return summary; 9597 } 9598 getMutationsByType(type) { 9599 return Array.from(this.mutations).filter(mutation => mutation.type === type); 9600 } 9601 getTextChangesFromChildList() { 9602 let textAdded, textRemoved; 9603 const addedNodes = []; 9604 const removedNodes = []; 9605 Array.from(this.getMutationsByType("childList")).forEach(mutation => { 9606 addedNodes.push(...Array.from(mutation.addedNodes || [])); 9607 removedNodes.push(...Array.from(mutation.removedNodes || [])); 9608 }); 9609 const singleBlockCommentRemoved = addedNodes.length === 0 && removedNodes.length === 1 && nodeIsBlockStartComment(removedNodes[0]); 9610 if (singleBlockCommentRemoved) { 9611 textAdded = []; 9612 textRemoved = ["\n"]; 9613 } else { 9614 textAdded = getTextForNodes(addedNodes); 9615 textRemoved = getTextForNodes(removedNodes); 9616 } 9617 const additions = textAdded.filter((text, index) => text !== textRemoved[index]).map(normalizeSpaces); 9618 const deletions = textRemoved.filter((text, index) => text !== textAdded[index]).map(normalizeSpaces); 9619 return { 9620 additions, 9621 deletions 9622 }; 9623 } 9624 getTextChangesFromCharacterData() { 9625 let added, removed; 9626 const characterMutations = this.getMutationsByType("characterData"); 9627 if (characterMutations.length) { 9628 const startMutation = characterMutations[0], 9629 endMutation = characterMutations[characterMutations.length - 1]; 9630 const oldString = normalizeSpaces(startMutation.oldValue); 9631 const newString = normalizeSpaces(endMutation.target.data); 9632 const summarized = summarizeStringChange(oldString, newString); 9633 added = summarized.added; 9634 removed = summarized.removed; 9635 } 9636 return { 9637 additions: added ? [added] : [], 9638 deletions: removed ? [removed] : [] 9639 }; 9640 } 9641 } 9642 const getTextForNodes = function () { 9643 let nodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; 9644 const text = []; 9645 for (const node of Array.from(nodes)) { 9646 switch (node.nodeType) { 9647 case Node.TEXT_NODE: 9648 text.push(node.data); 9649 break; 9650 case Node.ELEMENT_NODE: 9651 if (tagName(node) === "br") { 9652 text.push("\n"); 9653 } else { 9654 text.push(...Array.from(getTextForNodes(node.childNodes) || [])); 9655 } 9656 break; 9657 } 9658 } 9659 return text; 9660 }; 9661 9662 /* eslint-disable 9663 no-empty, 9664 */ 9665 class FileVerificationOperation extends Operation { 9666 constructor(file) { 9667 super(...arguments); 9668 this.file = file; 9669 } 9670 perform(callback) { 9671 const reader = new FileReader(); 9672 reader.onerror = () => callback(false); 9673 reader.onload = () => { 9674 reader.onerror = null; 9675 try { 9676 reader.abort(); 9677 } catch (error) {} 9678 return callback(true, this.file); 9679 }; 9680 return reader.readAsArrayBuffer(this.file); 9681 } 9682 } 9683 9684 // Each software keyboard on Android emits its own set of events and some of them can be buggy. 9685 // This class detects when some buggy events are being emitted and lets know the input controller 9686 // that they should be ignored. 9687 class FlakyAndroidKeyboardDetector { 9688 constructor(element) { 9689 this.element = element; 9690 } 9691 shouldIgnore(event) { 9692 if (!browser$1.samsungAndroid) return false; 9693 this.previousEvent = this.event; 9694 this.event = event; 9695 this.checkSamsungKeyboardBuggyModeStart(); 9696 this.checkSamsungKeyboardBuggyModeEnd(); 9697 return this.buggyMode; 9698 } 9699 9700 // private 9701 9702 // The Samsung keyboard on Android can enter a buggy state in which it emits a flurry of confused events that, 9703 // if processed, corrupts the editor. The buggy mode always starts with an insertText event, right after a 9704 // keydown event with for an "Unidentified" key, with the same text as the editor element, except for a few 9705 // extra whitespace, or exotic utf8, characters. 9706 checkSamsungKeyboardBuggyModeStart() { 9707 if (this.insertingLongTextAfterUnidentifiedChar() && differsInWhitespace(this.element.innerText, this.event.data)) { 9708 this.buggyMode = true; 9709 this.event.preventDefault(); 9710 } 9711 } 9712 9713 // The flurry of buggy events are always insertText. If we see any other type, it means it's over. 9714 checkSamsungKeyboardBuggyModeEnd() { 9715 if (this.buggyMode && this.event.inputType !== "insertText") { 9716 this.buggyMode = false; 9717 } 9718 } 9719 insertingLongTextAfterUnidentifiedChar() { 9720 var _this$event$data; 9721 return this.isBeforeInputInsertText() && this.previousEventWasUnidentifiedKeydown() && ((_this$event$data = this.event.data) === null || _this$event$data === void 0 ? void 0 : _this$event$data.length) > 50; 9722 } 9723 isBeforeInputInsertText() { 9724 return this.event.type === "beforeinput" && this.event.inputType === "insertText"; 9725 } 9726 previousEventWasUnidentifiedKeydown() { 9727 var _this$previousEvent, _this$previousEvent2; 9728 return ((_this$previousEvent = this.previousEvent) === null || _this$previousEvent === void 0 ? void 0 : _this$previousEvent.type) === "keydown" && ((_this$previousEvent2 = this.previousEvent) === null || _this$previousEvent2 === void 0 ? void 0 : _this$previousEvent2.key) === "Unidentified"; 9729 } 9730 } 9731 const differsInWhitespace = (text1, text2) => { 9732 return normalize(text1) === normalize(text2); 9733 }; 9734 const whiteSpaceNormalizerRegexp = new RegExp("(".concat(OBJECT_REPLACEMENT_CHARACTER, "|").concat(ZERO_WIDTH_SPACE, "|").concat(NON_BREAKING_SPACE, "|\\s)+"), "g"); 9735 const normalize = text => text.replace(whiteSpaceNormalizerRegexp, " ").trim(); 9736 9737 class InputController extends BasicObject { 9738 constructor(element) { 9739 super(...arguments); 9740 this.element = element; 9741 this.mutationObserver = new MutationObserver(this.element); 9742 this.mutationObserver.delegate = this; 9743 this.flakyKeyboardDetector = new FlakyAndroidKeyboardDetector(this.element); 9744 for (const eventName in this.constructor.events) { 9745 handleEvent(eventName, { 9746 onElement: this.element, 9747 withCallback: this.handlerFor(eventName) 9748 }); 9749 } 9750 } 9751 elementDidMutate(mutationSummary) {} 9752 editorWillSyncDocumentView() { 9753 return this.mutationObserver.stop(); 9754 } 9755 editorDidSyncDocumentView() { 9756 return this.mutationObserver.start(); 9757 } 9758 requestRender() { 9759 var _this$delegate, _this$delegate$inputC; 9760 return (_this$delegate = this.delegate) === null || _this$delegate === void 0 || (_this$delegate$inputC = _this$delegate.inputControllerDidRequestRender) === null || _this$delegate$inputC === void 0 ? void 0 : _this$delegate$inputC.call(_this$delegate); 9761 } 9762 requestReparse() { 9763 var _this$delegate2, _this$delegate2$input; 9764 (_this$delegate2 = this.delegate) === null || _this$delegate2 === void 0 || (_this$delegate2$input = _this$delegate2.inputControllerDidRequestReparse) === null || _this$delegate2$input === void 0 || _this$delegate2$input.call(_this$delegate2); 9765 return this.requestRender(); 9766 } 9767 attachFiles(files) { 9768 const operations = Array.from(files).map(file => new FileVerificationOperation(file)); 9769 return Promise.all(operations).then(files => { 9770 this.handleInput(function () { 9771 var _this$delegate3, _this$responder; 9772 (_this$delegate3 = this.delegate) === null || _this$delegate3 === void 0 || _this$delegate3.inputControllerWillAttachFiles(); 9773 (_this$responder = this.responder) === null || _this$responder === void 0 || _this$responder.insertFiles(files); 9774 return this.requestRender(); 9775 }); 9776 }); 9777 } 9778 9779 // Private 9780 9781 handlerFor(eventName) { 9782 return event => { 9783 if (!event.defaultPrevented) { 9784 this.handleInput(() => { 9785 if (!innerElementIsActive(this.element)) { 9786 if (this.flakyKeyboardDetector.shouldIgnore(event)) return; 9787 this.eventName = eventName; 9788 this.constructor.events[eventName].call(this, event); 9789 } 9790 }); 9791 } 9792 }; 9793 } 9794 handleInput(callback) { 9795 try { 9796 var _this$delegate4; 9797 (_this$delegate4 = this.delegate) === null || _this$delegate4 === void 0 || _this$delegate4.inputControllerWillHandleInput(); 9798 callback.call(this); 9799 } finally { 9800 var _this$delegate5; 9801 (_this$delegate5 = this.delegate) === null || _this$delegate5 === void 0 || _this$delegate5.inputControllerDidHandleInput(); 9802 } 9803 } 9804 createLinkHTML(href, text) { 9805 const link = document.createElement("a"); 9806 link.href = href; 9807 link.textContent = text ? text : href; 9808 return link.outerHTML; 9809 } 9810 } 9811 _defineProperty(InputController, "events", {}); 9812 9813 var _$codePointAt, _; 9814 const { 9815 browser, 9816 keyNames 9817 } = config; 9818 let pastedFileCount = 0; 9819 class Level0InputController extends InputController { 9820 constructor() { 9821 super(...arguments); 9822 this.resetInputSummary(); 9823 } 9824 setInputSummary() { 9825 let summary = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; 9826 this.inputSummary.eventName = this.eventName; 9827 for (const key in summary) { 9828 const value = summary[key]; 9829 this.inputSummary[key] = value; 9830 } 9831 return this.inputSummary; 9832 } 9833 resetInputSummary() { 9834 this.inputSummary = {}; 9835 } 9836 reset() { 9837 this.resetInputSummary(); 9838 return selectionChangeObserver.reset(); 9839 } 9840 9841 // Mutation observer delegate 9842 9843 elementDidMutate(mutationSummary) { 9844 if (this.isComposing()) { 9845 var _this$delegate, _this$delegate$inputC; 9846 return (_this$delegate = this.delegate) === null || _this$delegate === void 0 || (_this$delegate$inputC = _this$delegate.inputControllerDidAllowUnhandledInput) === null || _this$delegate$inputC === void 0 ? void 0 : _this$delegate$inputC.call(_this$delegate); 9847 } else { 9848 return this.handleInput(function () { 9849 if (this.mutationIsSignificant(mutationSummary)) { 9850 if (this.mutationIsExpected(mutationSummary)) { 9851 this.requestRender(); 9852 } else { 9853 this.requestReparse(); 9854 } 9855 } 9856 return this.reset(); 9857 }); 9858 } 9859 } 9860 mutationIsExpected(_ref) { 9861 let { 9862 textAdded, 9863 textDeleted 9864 } = _ref; 9865 if (this.inputSummary.preferDocument) { 9866 return true; 9867 } 9868 const mutationAdditionMatchesSummary = textAdded != null ? textAdded === this.inputSummary.textAdded : !this.inputSummary.textAdded; 9869 const mutationDeletionMatchesSummary = textDeleted != null ? this.inputSummary.didDelete : !this.inputSummary.didDelete; 9870 const unexpectedNewlineAddition = ["\n", " \n"].includes(textAdded) && !mutationAdditionMatchesSummary; 9871 const unexpectedNewlineDeletion = textDeleted === "\n" && !mutationDeletionMatchesSummary; 9872 const singleUnexpectedNewline = unexpectedNewlineAddition && !unexpectedNewlineDeletion || unexpectedNewlineDeletion && !unexpectedNewlineAddition; 9873 if (singleUnexpectedNewline) { 9874 const range = this.getSelectedRange(); 9875 if (range) { 9876 var _this$responder; 9877 const offset = unexpectedNewlineAddition ? textAdded.replace(/\n$/, "").length || -1 : (textAdded === null || textAdded === void 0 ? void 0 : textAdded.length) || 1; 9878 if ((_this$responder = this.responder) !== null && _this$responder !== void 0 && _this$responder.positionIsBlockBreak(range[1] + offset)) { 9879 return true; 9880 } 9881 } 9882 } 9883 return mutationAdditionMatchesSummary && mutationDeletionMatchesSummary; 9884 } 9885 mutationIsSignificant(mutationSummary) { 9886 var _this$compositionInpu; 9887 const textChanged = Object.keys(mutationSummary).length > 0; 9888 const composedEmptyString = ((_this$compositionInpu = this.compositionInput) === null || _this$compositionInpu === void 0 ? void 0 : _this$compositionInpu.getEndData()) === ""; 9889 return textChanged || !composedEmptyString; 9890 } 9891 9892 // Private 9893 9894 getCompositionInput() { 9895 if (this.isComposing()) { 9896 return this.compositionInput; 9897 } else { 9898 this.compositionInput = new CompositionInput(this); 9899 } 9900 } 9901 isComposing() { 9902 return this.compositionInput && !this.compositionInput.isEnded(); 9903 } 9904 deleteInDirection(direction, event) { 9905 var _this$responder2; 9906 if (((_this$responder2 = this.responder) === null || _this$responder2 === void 0 ? void 0 : _this$responder2.deleteInDirection(direction)) === false) { 9907 if (event) { 9908 event.preventDefault(); 9909 return this.requestRender(); 9910 } 9911 } else { 9912 return this.setInputSummary({ 9913 didDelete: true 9914 }); 9915 } 9916 } 9917 serializeSelectionToDataTransfer(dataTransfer) { 9918 var _this$responder3; 9919 if (!dataTransferIsWritable(dataTransfer)) return; 9920 const document = (_this$responder3 = this.responder) === null || _this$responder3 === void 0 ? void 0 : _this$responder3.getSelectedDocument().toSerializableDocument(); 9921 dataTransfer.setData("application/x-trix-document", JSON.stringify(document)); 9922 dataTransfer.setData("text/html", DocumentView.render(document).innerHTML); 9923 dataTransfer.setData("text/plain", document.toString().replace(/\n$/, "")); 9924 return true; 9925 } 9926 canAcceptDataTransfer(dataTransfer) { 9927 const types = {}; 9928 Array.from((dataTransfer === null || dataTransfer === void 0 ? void 0 : dataTransfer.types) || []).forEach(type => { 9929 types[type] = true; 9930 }); 9931 return types.Files || types["application/x-trix-document"] || types["text/html"] || types["text/plain"]; 9932 } 9933 getPastedHTMLUsingHiddenElement(callback) { 9934 const selectedRange = this.getSelectedRange(); 9935 const style = { 9936 position: "absolute", 9937 left: "".concat(window.pageXOffset, "px"), 9938 top: "".concat(window.pageYOffset, "px"), 9939 opacity: 0 9940 }; 9941 const element = makeElement({ 9942 style, 9943 tagName: "div", 9944 editable: true 9945 }); 9946 document.body.appendChild(element); 9947 element.focus(); 9948 return requestAnimationFrame(() => { 9949 const html = element.innerHTML; 9950 removeNode(element); 9951 this.setSelectedRange(selectedRange); 9952 return callback(html); 9953 }); 9954 } 9955 } 9956 _defineProperty(Level0InputController, "events", { 9957 keydown(event) { 9958 if (!this.isComposing()) { 9959 this.resetInputSummary(); 9960 } 9961 this.inputSummary.didInput = true; 9962 const keyName = keyNames[event.keyCode]; 9963 if (keyName) { 9964 var _context2; 9965 let context = this.keys; 9966 ["ctrl", "alt", "shift", "meta"].forEach(modifier => { 9967 if (event["".concat(modifier, "Key")]) { 9968 var _context; 9969 if (modifier === "ctrl") { 9970 modifier = "control"; 9971 } 9972 context = (_context = context) === null || _context === void 0 ? void 0 : _context[modifier]; 9973 } 9974 }); 9975 if (((_context2 = context) === null || _context2 === void 0 ? void 0 : _context2[keyName]) != null) { 9976 this.setInputSummary({ 9977 keyName 9978 }); 9979 selectionChangeObserver.reset(); 9980 context[keyName].call(this, event); 9981 } 9982 } 9983 if (keyEventIsKeyboardCommand(event)) { 9984 const character = String.fromCharCode(event.keyCode).toLowerCase(); 9985 if (character) { 9986 var _this$delegate3; 9987 const keys = ["alt", "shift"].map(modifier => { 9988 if (event["".concat(modifier, "Key")]) { 9989 return modifier; 9990 } 9991 }).filter(key => key); 9992 keys.push(character); 9993 if ((_this$delegate3 = this.delegate) !== null && _this$delegate3 !== void 0 && _this$delegate3.inputControllerDidReceiveKeyboardCommand(keys)) { 9994 event.preventDefault(); 9995 } 9996 } 9997 } 9998 }, 9999 keypress(event) { 10000 if (this.inputSummary.eventName != null) return; 10001 if (event.metaKey) return; 10002 if (event.ctrlKey && !event.altKey) return; 10003 const string = stringFromKeyEvent(event); 10004 if (string) { 10005 var _this$delegate4, _this$responder9; 10006 (_this$delegate4 = this.delegate) === null || _this$delegate4 === void 0 || _this$delegate4.inputControllerWillPerformTyping(); 10007 (_this$responder9 = this.responder) === null || _this$responder9 === void 0 || _this$responder9.insertString(string); 10008 return this.setInputSummary({ 10009 textAdded: string, 10010 didDelete: this.selectionIsExpanded() 10011 }); 10012 } 10013 }, 10014 textInput(event) { 10015 // Handle autocapitalization 10016 const { 10017 data 10018 } = event; 10019 const { 10020 textAdded 10021 } = this.inputSummary; 10022 if (textAdded && textAdded !== data && textAdded.toUpperCase() === data) { 10023 var _this$responder10; 10024 const range = this.getSelectedRange(); 10025 this.setSelectedRange([range[0], range[1] + textAdded.length]); 10026 (_this$responder10 = this.responder) === null || _this$responder10 === void 0 || _this$responder10.insertString(data); 10027 this.setInputSummary({ 10028 textAdded: data 10029 }); 10030 return this.setSelectedRange(range); 10031 } 10032 }, 10033 dragenter(event) { 10034 event.preventDefault(); 10035 }, 10036 dragstart(event) { 10037 var _this$delegate5, _this$delegate5$input; 10038 this.serializeSelectionToDataTransfer(event.dataTransfer); 10039 this.draggedRange = this.getSelectedRange(); 10040 return (_this$delegate5 = this.delegate) === null || _this$delegate5 === void 0 || (_this$delegate5$input = _this$delegate5.inputControllerDidStartDrag) === null || _this$delegate5$input === void 0 ? void 0 : _this$delegate5$input.call(_this$delegate5); 10041 }, 10042 dragover(event) { 10043 if (this.draggedRange || this.canAcceptDataTransfer(event.dataTransfer)) { 10044 event.preventDefault(); 10045 const draggingPoint = { 10046 x: event.clientX, 10047 y: event.clientY 10048 }; 10049 if (!objectsAreEqual(draggingPoint, this.draggingPoint)) { 10050 var _this$delegate6, _this$delegate6$input; 10051 this.draggingPoint = draggingPoint; 10052 return (_this$delegate6 = this.delegate) === null || _this$delegate6 === void 0 || (_this$delegate6$input = _this$delegate6.inputControllerDidReceiveDragOverPoint) === null || _this$delegate6$input === void 0 ? void 0 : _this$delegate6$input.call(_this$delegate6, this.draggingPoint); 10053 } 10054 } 10055 }, 10056 dragend(event) { 10057 var _this$delegate7, _this$delegate7$input; 10058 (_this$delegate7 = this.delegate) === null || _this$delegate7 === void 0 || (_this$delegate7$input = _this$delegate7.inputControllerDidCancelDrag) === null || _this$delegate7$input === void 0 || _this$delegate7$input.call(_this$delegate7); 10059 this.draggedRange = null; 10060 this.draggingPoint = null; 10061 }, 10062 drop(event) { 10063 var _event$dataTransfer, _this$responder11; 10064 event.preventDefault(); 10065 const files = (_event$dataTransfer = event.dataTransfer) === null || _event$dataTransfer === void 0 ? void 0 : _event$dataTransfer.files; 10066 const documentJSON = event.dataTransfer.getData("application/x-trix-document"); 10067 const point = { 10068 x: event.clientX, 10069 y: event.clientY 10070 }; 10071 (_this$responder11 = this.responder) === null || _this$responder11 === void 0 || _this$responder11.setLocationRangeFromPointRange(point); 10072 if (files !== null && files !== void 0 && files.length) { 10073 this.attachFiles(files); 10074 } else if (this.draggedRange) { 10075 var _this$delegate8, _this$responder12; 10076 (_this$delegate8 = this.delegate) === null || _this$delegate8 === void 0 || _this$delegate8.inputControllerWillMoveText(); 10077 (_this$responder12 = this.responder) === null || _this$responder12 === void 0 || _this$responder12.moveTextFromRange(this.draggedRange); 10078 this.draggedRange = null; 10079 this.requestRender(); 10080 } else if (documentJSON) { 10081 var _this$responder13; 10082 const document = Document.fromJSONString(documentJSON); 10083 (_this$responder13 = this.responder) === null || _this$responder13 === void 0 || _this$responder13.insertDocument(document); 10084 this.requestRender(); 10085 } 10086 this.draggedRange = null; 10087 this.draggingPoint = null; 10088 }, 10089 cut(event) { 10090 var _this$responder14; 10091 if ((_this$responder14 = this.responder) !== null && _this$responder14 !== void 0 && _this$responder14.selectionIsExpanded()) { 10092 var _this$delegate9; 10093 if (this.serializeSelectionToDataTransfer(event.clipboardData)) { 10094 event.preventDefault(); 10095 } 10096 (_this$delegate9 = this.delegate) === null || _this$delegate9 === void 0 || _this$delegate9.inputControllerWillCutText(); 10097 this.deleteInDirection("backward"); 10098 if (event.defaultPrevented) { 10099 return this.requestRender(); 10100 } 10101 } 10102 }, 10103 copy(event) { 10104 var _this$responder15; 10105 if ((_this$responder15 = this.responder) !== null && _this$responder15 !== void 0 && _this$responder15.selectionIsExpanded()) { 10106 if (this.serializeSelectionToDataTransfer(event.clipboardData)) { 10107 event.preventDefault(); 10108 } 10109 } 10110 }, 10111 paste(event) { 10112 const clipboard = event.clipboardData || event.testClipboardData; 10113 const paste = { 10114 clipboard 10115 }; 10116 if (!clipboard || pasteEventIsCrippledSafariHTMLPaste(event)) { 10117 this.getPastedHTMLUsingHiddenElement(html => { 10118 var _this$delegate10, _this$responder16, _this$delegate11; 10119 paste.type = "text/html"; 10120 paste.html = html; 10121 (_this$delegate10 = this.delegate) === null || _this$delegate10 === void 0 || _this$delegate10.inputControllerWillPaste(paste); 10122 (_this$responder16 = this.responder) === null || _this$responder16 === void 0 || _this$responder16.insertHTML(paste.html); 10123 this.requestRender(); 10124 return (_this$delegate11 = this.delegate) === null || _this$delegate11 === void 0 ? void 0 : _this$delegate11.inputControllerDidPaste(paste); 10125 }); 10126 return; 10127 } 10128 const href = clipboard.getData("URL"); 10129 const html = clipboard.getData("text/html"); 10130 const name = clipboard.getData("public.url-name"); 10131 if (href) { 10132 var _this$delegate12, _this$responder17, _this$delegate13; 10133 let string; 10134 paste.type = "text/html"; 10135 if (name) { 10136 string = squishBreakableWhitespace(name).trim(); 10137 } else { 10138 string = href; 10139 } 10140 paste.html = this.createLinkHTML(href, string); 10141 (_this$delegate12 = this.delegate) === null || _this$delegate12 === void 0 || _this$delegate12.inputControllerWillPaste(paste); 10142 this.setInputSummary({ 10143 textAdded: string, 10144 didDelete: this.selectionIsExpanded() 10145 }); 10146 (_this$responder17 = this.responder) === null || _this$responder17 === void 0 || _this$responder17.insertHTML(paste.html); 10147 this.requestRender(); 10148 (_this$delegate13 = this.delegate) === null || _this$delegate13 === void 0 || _this$delegate13.inputControllerDidPaste(paste); 10149 } else if (dataTransferIsPlainText(clipboard)) { 10150 var _this$delegate14, _this$responder18, _this$delegate15; 10151 paste.type = "text/plain"; 10152 paste.string = clipboard.getData("text/plain"); 10153 (_this$delegate14 = this.delegate) === null || _this$delegate14 === void 0 || _this$delegate14.inputControllerWillPaste(paste); 10154 this.setInputSummary({ 10155 textAdded: paste.string, 10156 didDelete: this.selectionIsExpanded() 10157 }); 10158 (_this$responder18 = this.responder) === null || _this$responder18 === void 0 || _this$responder18.insertString(paste.string); 10159 this.requestRender(); 10160 (_this$delegate15 = this.delegate) === null || _this$delegate15 === void 0 || _this$delegate15.inputControllerDidPaste(paste); 10161 } else if (html) { 10162 var _this$delegate16, _this$responder19, _this$delegate17; 10163 paste.type = "text/html"; 10164 paste.html = html; 10165 (_this$delegate16 = this.delegate) === null || _this$delegate16 === void 0 || _this$delegate16.inputControllerWillPaste(paste); 10166 (_this$responder19 = this.responder) === null || _this$responder19 === void 0 || _this$responder19.insertHTML(paste.html); 10167 this.requestRender(); 10168 (_this$delegate17 = this.delegate) === null || _this$delegate17 === void 0 || _this$delegate17.inputControllerDidPaste(paste); 10169 } else if (Array.from(clipboard.types).includes("Files")) { 10170 var _clipboard$items, _clipboard$items$getA; 10171 const file = (_clipboard$items = clipboard.items) === null || _clipboard$items === void 0 || (_clipboard$items = _clipboard$items[0]) === null || _clipboard$items === void 0 || (_clipboard$items$getA = _clipboard$items.getAsFile) === null || _clipboard$items$getA === void 0 ? void 0 : _clipboard$items$getA.call(_clipboard$items); 10172 if (file) { 10173 var _this$delegate18, _this$responder20, _this$delegate19; 10174 const extension = extensionForFile(file); 10175 if (!file.name && extension) { 10176 file.name = "pasted-file-".concat(++pastedFileCount, ".").concat(extension); 10177 } 10178 paste.type = "File"; 10179 paste.file = file; 10180 (_this$delegate18 = this.delegate) === null || _this$delegate18 === void 0 || _this$delegate18.inputControllerWillAttachFiles(); 10181 (_this$responder20 = this.responder) === null || _this$responder20 === void 0 || _this$responder20.insertFile(paste.file); 10182 this.requestRender(); 10183 (_this$delegate19 = this.delegate) === null || _this$delegate19 === void 0 || _this$delegate19.inputControllerDidPaste(paste); 10184 } 10185 } 10186 event.preventDefault(); 10187 }, 10188 compositionstart(event) { 10189 return this.getCompositionInput().start(event.data); 10190 }, 10191 compositionupdate(event) { 10192 return this.getCompositionInput().update(event.data); 10193 }, 10194 compositionend(event) { 10195 return this.getCompositionInput().end(event.data); 10196 }, 10197 beforeinput(event) { 10198 this.inputSummary.didInput = true; 10199 }, 10200 input(event) { 10201 this.inputSummary.didInput = true; 10202 return event.stopPropagation(); 10203 } 10204 }); 10205 _defineProperty(Level0InputController, "keys", { 10206 backspace(event) { 10207 var _this$delegate20; 10208 (_this$delegate20 = this.delegate) === null || _this$delegate20 === void 0 || _this$delegate20.inputControllerWillPerformTyping(); 10209 return this.deleteInDirection("backward", event); 10210 }, 10211 delete(event) { 10212 var _this$delegate21; 10213 (_this$delegate21 = this.delegate) === null || _this$delegate21 === void 0 || _this$delegate21.inputControllerWillPerformTyping(); 10214 return this.deleteInDirection("forward", event); 10215 }, 10216 return(event) { 10217 var _this$delegate22, _this$responder21; 10218 this.setInputSummary({ 10219 preferDocument: true 10220 }); 10221 (_this$delegate22 = this.delegate) === null || _this$delegate22 === void 0 || _this$delegate22.inputControllerWillPerformTyping(); 10222 return (_this$responder21 = this.responder) === null || _this$responder21 === void 0 ? void 0 : _this$responder21.insertLineBreak(); 10223 }, 10224 tab(event) { 10225 var _this$responder22; 10226 if ((_this$responder22 = this.responder) !== null && _this$responder22 !== void 0 && _this$responder22.canIncreaseNestingLevel()) { 10227 var _this$responder23; 10228 (_this$responder23 = this.responder) === null || _this$responder23 === void 0 || _this$responder23.increaseNestingLevel(); 10229 this.requestRender(); 10230 event.preventDefault(); 10231 } 10232 }, 10233 left(event) { 10234 if (this.selectionIsInCursorTarget()) { 10235 var _this$responder24; 10236 event.preventDefault(); 10237 return (_this$responder24 = this.responder) === null || _this$responder24 === void 0 ? void 0 : _this$responder24.moveCursorInDirection("backward"); 10238 } 10239 }, 10240 right(event) { 10241 if (this.selectionIsInCursorTarget()) { 10242 var _this$responder25; 10243 event.preventDefault(); 10244 return (_this$responder25 = this.responder) === null || _this$responder25 === void 0 ? void 0 : _this$responder25.moveCursorInDirection("forward"); 10245 } 10246 }, 10247 control: { 10248 d(event) { 10249 var _this$delegate23; 10250 (_this$delegate23 = this.delegate) === null || _this$delegate23 === void 0 || _this$delegate23.inputControllerWillPerformTyping(); 10251 return this.deleteInDirection("forward", event); 10252 }, 10253 h(event) { 10254 var _this$delegate24; 10255 (_this$delegate24 = this.delegate) === null || _this$delegate24 === void 0 || _this$delegate24.inputControllerWillPerformTyping(); 10256 return this.deleteInDirection("backward", event); 10257 }, 10258 o(event) { 10259 var _this$delegate25, _this$responder26; 10260 event.preventDefault(); 10261 (_this$delegate25 = this.delegate) === null || _this$delegate25 === void 0 || _this$delegate25.inputControllerWillPerformTyping(); 10262 (_this$responder26 = this.responder) === null || _this$responder26 === void 0 || _this$responder26.insertString("\n", { 10263 updatePosition: false 10264 }); 10265 return this.requestRender(); 10266 } 10267 }, 10268 shift: { 10269 return(event) { 10270 var _this$delegate26, _this$responder27; 10271 (_this$delegate26 = this.delegate) === null || _this$delegate26 === void 0 || _this$delegate26.inputControllerWillPerformTyping(); 10272 (_this$responder27 = this.responder) === null || _this$responder27 === void 0 || _this$responder27.insertString("\n"); 10273 this.requestRender(); 10274 event.preventDefault(); 10275 }, 10276 tab(event) { 10277 var _this$responder28; 10278 if ((_this$responder28 = this.responder) !== null && _this$responder28 !== void 0 && _this$responder28.canDecreaseNestingLevel()) { 10279 var _this$responder29; 10280 (_this$responder29 = this.responder) === null || _this$responder29 === void 0 || _this$responder29.decreaseNestingLevel(); 10281 this.requestRender(); 10282 event.preventDefault(); 10283 } 10284 }, 10285 left(event) { 10286 if (this.selectionIsInCursorTarget()) { 10287 event.preventDefault(); 10288 return this.expandSelectionInDirection("backward"); 10289 } 10290 }, 10291 right(event) { 10292 if (this.selectionIsInCursorTarget()) { 10293 event.preventDefault(); 10294 return this.expandSelectionInDirection("forward"); 10295 } 10296 } 10297 }, 10298 alt: { 10299 backspace(event) { 10300 var _this$delegate27; 10301 this.setInputSummary({ 10302 preferDocument: false 10303 }); 10304 return (_this$delegate27 = this.delegate) === null || _this$delegate27 === void 0 ? void 0 : _this$delegate27.inputControllerWillPerformTyping(); 10305 } 10306 }, 10307 meta: { 10308 backspace(event) { 10309 var _this$delegate28; 10310 this.setInputSummary({ 10311 preferDocument: false 10312 }); 10313 return (_this$delegate28 = this.delegate) === null || _this$delegate28 === void 0 ? void 0 : _this$delegate28.inputControllerWillPerformTyping(); 10314 } 10315 } 10316 }); 10317 Level0InputController.proxyMethod("responder?.getSelectedRange"); 10318 Level0InputController.proxyMethod("responder?.setSelectedRange"); 10319 Level0InputController.proxyMethod("responder?.expandSelectionInDirection"); 10320 Level0InputController.proxyMethod("responder?.selectionIsInCursorTarget"); 10321 Level0InputController.proxyMethod("responder?.selectionIsExpanded"); 10322 const extensionForFile = file => { 10323 var _file$type; 10324 return (_file$type = file.type) === null || _file$type === void 0 || (_file$type = _file$type.match(/\/(\w+)$/)) === null || _file$type === void 0 ? void 0 : _file$type[1]; 10325 }; 10326 const hasStringCodePointAt = !!((_$codePointAt = (_ = " ").codePointAt) !== null && _$codePointAt !== void 0 && _$codePointAt.call(_, 0)); 10327 const stringFromKeyEvent = function (event) { 10328 if (event.key && hasStringCodePointAt && event.key.codePointAt(0) === event.keyCode) { 10329 return event.key; 10330 } else { 10331 let code; 10332 if (event.which === null) { 10333 code = event.keyCode; 10334 } else if (event.which !== 0 && event.charCode !== 0) { 10335 code = event.charCode; 10336 } 10337 if (code != null && keyNames[code] !== "escape") { 10338 return UTF16String.fromCodepoints([code]).toString(); 10339 } 10340 } 10341 }; 10342 const pasteEventIsCrippledSafariHTMLPaste = function (event) { 10343 const paste = event.clipboardData; 10344 if (paste) { 10345 if (paste.types.includes("text/html")) { 10346 // Answer is yes if there's any possibility of Paste and Match Style in Safari, 10347 // which is nearly impossible to detect confidently: https://bugs.webkit.org/show_bug.cgi?id=174165 10348 for (const type of paste.types) { 10349 const hasPasteboardFlavor = /^CorePasteboardFlavorType/.test(type); 10350 const hasReadableDynamicData = /^dyn\./.test(type) && paste.getData(type); 10351 const mightBePasteAndMatchStyle = hasPasteboardFlavor || hasReadableDynamicData; 10352 if (mightBePasteAndMatchStyle) { 10353 return true; 10354 } 10355 } 10356 return false; 10357 } else { 10358 const isExternalHTMLPaste = paste.types.includes("com.apple.webarchive"); 10359 const isExternalRichTextPaste = paste.types.includes("com.apple.flat-rtfd"); 10360 return isExternalHTMLPaste || isExternalRichTextPaste; 10361 } 10362 } 10363 }; 10364 class CompositionInput extends BasicObject { 10365 constructor(inputController) { 10366 super(...arguments); 10367 this.inputController = inputController; 10368 this.responder = this.inputController.responder; 10369 this.delegate = this.inputController.delegate; 10370 this.inputSummary = this.inputController.inputSummary; 10371 this.data = {}; 10372 } 10373 start(data) { 10374 this.data.start = data; 10375 if (this.isSignificant()) { 10376 var _this$responder5; 10377 if (this.inputSummary.eventName === "keypress" && this.inputSummary.textAdded) { 10378 var _this$responder4; 10379 (_this$responder4 = this.responder) === null || _this$responder4 === void 0 || _this$responder4.deleteInDirection("left"); 10380 } 10381 if (!this.selectionIsExpanded()) { 10382 this.insertPlaceholder(); 10383 this.requestRender(); 10384 } 10385 this.range = (_this$responder5 = this.responder) === null || _this$responder5 === void 0 ? void 0 : _this$responder5.getSelectedRange(); 10386 } 10387 } 10388 update(data) { 10389 this.data.update = data; 10390 if (this.isSignificant()) { 10391 const range = this.selectPlaceholder(); 10392 if (range) { 10393 this.forgetPlaceholder(); 10394 this.range = range; 10395 } 10396 } 10397 } 10398 end(data) { 10399 this.data.end = data; 10400 if (this.isSignificant()) { 10401 this.forgetPlaceholder(); 10402 if (this.canApplyToDocument()) { 10403 var _this$delegate2, _this$responder6, _this$responder7, _this$responder8; 10404 this.setInputSummary({ 10405 preferDocument: true, 10406 didInput: false 10407 }); 10408 (_this$delegate2 = this.delegate) === null || _this$delegate2 === void 0 || _this$delegate2.inputControllerWillPerformTyping(); 10409 (_this$responder6 = this.responder) === null || _this$responder6 === void 0 || _this$responder6.setSelectedRange(this.range); 10410 (_this$responder7 = this.responder) === null || _this$responder7 === void 0 || _this$responder7.insertString(this.data.end); 10411 return (_this$responder8 = this.responder) === null || _this$responder8 === void 0 ? void 0 : _this$responder8.setSelectedRange(this.range[0] + this.data.end.length); 10412 } else if (this.data.start != null || this.data.update != null) { 10413 this.requestReparse(); 10414 return this.inputController.reset(); 10415 } 10416 } else { 10417 return this.inputController.reset(); 10418 } 10419 } 10420 getEndData() { 10421 return this.data.end; 10422 } 10423 isEnded() { 10424 return this.getEndData() != null; 10425 } 10426 isSignificant() { 10427 if (browser.composesExistingText) { 10428 return this.inputSummary.didInput; 10429 } else { 10430 return true; 10431 } 10432 } 10433 10434 // Private 10435 10436 canApplyToDocument() { 10437 var _this$data$start, _this$data$end; 10438 return ((_this$data$start = this.data.start) === null || _this$data$start === void 0 ? void 0 : _this$data$start.length) === 0 && ((_this$data$end = this.data.end) === null || _this$data$end === void 0 ? void 0 : _this$data$end.length) > 0 && this.range; 10439 } 10440 } 10441 CompositionInput.proxyMethod("inputController.setInputSummary"); 10442 CompositionInput.proxyMethod("inputController.requestRender"); 10443 CompositionInput.proxyMethod("inputController.requestReparse"); 10444 CompositionInput.proxyMethod("responder?.selectionIsExpanded"); 10445 CompositionInput.proxyMethod("responder?.insertPlaceholder"); 10446 CompositionInput.proxyMethod("responder?.selectPlaceholder"); 10447 CompositionInput.proxyMethod("responder?.forgetPlaceholder"); 10448 10449 class Level2InputController extends InputController { 10450 constructor() { 10451 super(...arguments); 10452 this.render = this.render.bind(this); 10453 } 10454 elementDidMutate() { 10455 if (this.scheduledRender) { 10456 if (this.composing) { 10457 var _this$delegate, _this$delegate$inputC; 10458 return (_this$delegate = this.delegate) === null || _this$delegate === void 0 || (_this$delegate$inputC = _this$delegate.inputControllerDidAllowUnhandledInput) === null || _this$delegate$inputC === void 0 ? void 0 : _this$delegate$inputC.call(_this$delegate); 10459 } 10460 } else { 10461 return this.reparse(); 10462 } 10463 } 10464 scheduleRender() { 10465 return this.scheduledRender ? this.scheduledRender : this.scheduledRender = requestAnimationFrame(this.render); 10466 } 10467 render() { 10468 var _this$afterRender; 10469 cancelAnimationFrame(this.scheduledRender); 10470 this.scheduledRender = null; 10471 if (!this.composing) { 10472 var _this$delegate2; 10473 (_this$delegate2 = this.delegate) === null || _this$delegate2 === void 0 || _this$delegate2.render(); 10474 } 10475 (_this$afterRender = this.afterRender) === null || _this$afterRender === void 0 || _this$afterRender.call(this); 10476 this.afterRender = null; 10477 } 10478 reparse() { 10479 var _this$delegate3; 10480 return (_this$delegate3 = this.delegate) === null || _this$delegate3 === void 0 ? void 0 : _this$delegate3.reparse(); 10481 } 10482 10483 // Responder helpers 10484 10485 insertString() { 10486 var _this$delegate4; 10487 let string = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ""; 10488 let options = arguments.length > 1 ? arguments[1] : undefined; 10489 (_this$delegate4 = this.delegate) === null || _this$delegate4 === void 0 || _this$delegate4.inputControllerWillPerformTyping(); 10490 return this.withTargetDOMRange(function () { 10491 var _this$responder; 10492 return (_this$responder = this.responder) === null || _this$responder === void 0 ? void 0 : _this$responder.insertString(string, options); 10493 }); 10494 } 10495 toggleAttributeIfSupported(attributeName) { 10496 if (getAllAttributeNames().includes(attributeName)) { 10497 var _this$delegate5; 10498 (_this$delegate5 = this.delegate) === null || _this$delegate5 === void 0 || _this$delegate5.inputControllerWillPerformFormatting(attributeName); 10499 return this.withTargetDOMRange(function () { 10500 var _this$responder2; 10501 return (_this$responder2 = this.responder) === null || _this$responder2 === void 0 ? void 0 : _this$responder2.toggleCurrentAttribute(attributeName); 10502 }); 10503 } 10504 } 10505 activateAttributeIfSupported(attributeName, value) { 10506 if (getAllAttributeNames().includes(attributeName)) { 10507 var _this$delegate6; 10508 (_this$delegate6 = this.delegate) === null || _this$delegate6 === void 0 || _this$delegate6.inputControllerWillPerformFormatting(attributeName); 10509 return this.withTargetDOMRange(function () { 10510 var _this$responder3; 10511 return (_this$responder3 = this.responder) === null || _this$responder3 === void 0 ? void 0 : _this$responder3.setCurrentAttribute(attributeName, value); 10512 }); 10513 } 10514 } 10515 deleteInDirection(direction) { 10516 let { 10517 recordUndoEntry 10518 } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { 10519 recordUndoEntry: true 10520 }; 10521 if (recordUndoEntry) { 10522 var _this$delegate7; 10523 (_this$delegate7 = this.delegate) === null || _this$delegate7 === void 0 || _this$delegate7.inputControllerWillPerformTyping(); 10524 } 10525 const perform = () => { 10526 var _this$responder4; 10527 return (_this$responder4 = this.responder) === null || _this$responder4 === void 0 ? void 0 : _this$responder4.deleteInDirection(direction); 10528 }; 10529 const domRange = this.getTargetDOMRange({ 10530 minLength:
vendor: 4,504 bytes, lines 10530-10646
105302 10531 }); 10532 if (domRange) { 10533 return this.withTargetDOMRange(domRange, perform); 10534 } else { 10535 return perform(); 10536 } 10537 } 10538 10539 // Selection helpers 10540 10541 withTargetDOMRange(domRange, fn) { 10542 if (typeof domRange === "function") { 10543 fn = domRange; 10544 domRange = this.getTargetDOMRange(); 10545 } 10546 if (domRange) { 10547 var _this$responder5; 10548 return (_this$responder5 = this.responder) === null || _this$responder5 === void 0 ? void 0 : _this$responder5.withTargetDOMRange(domRange, fn.bind(this)); 10549 } else { 10550 selectionChangeObserver.reset(); 10551 return fn.call(this); 10552 } 10553 } 10554 getTargetDOMRange() { 10555 var _this$event$getTarget, _this$event; 10556 let { 10557 minLength 10558 } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { 10559 minLength: 0 10560 }; 10561 const targetRanges = (_this$event$getTarget = (_this$event = this.event).getTargetRanges) === null || _this$event$getTarget === void 0 ? void 0 : _this$event$getTarget.call(_this$event); 10562 if (targetRanges) { 10563 if (targetRanges.length) { 10564 const domRange = staticRangeToRange(targetRanges[0]); 10565 if (minLength === 0 || domRange.toString().length >= minLength) { 10566 return domRange; 10567 } 10568 } 10569 } 10570 } 10571 withEvent(event, fn) { 10572 let result; 10573 this.event = event; 10574 try { 10575 result = fn.call(this); 10576 } finally { 10577 this.event = null; 10578 } 10579 return result; 10580 } 10581 } 10582 _defineProperty(Level2InputController, "events", { 10583 keydown(event) { 10584 if (keyEventIsKeyboardCommand(event)) { 10585 var _this$delegate8; 10586 const command = keyboardCommandFromKeyEvent(event); 10587 if ((_this$delegate8 = this.delegate) !== null && _this$delegate8 !== void 0 && _this$delegate8.inputControllerDidReceiveKeyboardCommand(command)) { 10588 event.preventDefault(); 10589 } 10590 } else { 10591 let name = event.key; 10592 if (event.altKey) { 10593 name += "+Alt"; 10594 } 10595 if (event.shiftKey) { 10596 name += "+Shift"; 10597 } 10598 const handler = this.constructor.keys[name]; 10599 if (handler) { 10600 return this.withEvent(event, handler); 10601 } 10602 } 10603 }, 10604 // Handle paste event to work around beforeinput.insertFromPaste browser bugs. 10605 // Safe to remove each condition once fixed upstream. 10606 paste(event) { 10607 var _event$clipboardData; 10608 // https://bugs.webkit.org/show_bug.cgi?id=194921 10609 let paste; 10610 const href = (_event$clipboardData = event.clipboardData) === null || _event$clipboardData === void 0 ? void 0 : _event$clipboardData.getData("URL"); 10611 if (pasteEventHasFilesOnly(event)) { 10612 event.preventDefault(); 10613 return this.attachFiles(event.clipboardData.files); 10614 10615 // https://bugs.chromium.org/p/chromium/issues/detail?id=934448 10616 } else if (pasteEventHasPlainTextOnly(event)) { 10617 var _this$delegate9, _this$responder6, _this$delegate10; 10618 event.preventDefault(); 10619 paste = { 10620 type: "text/plain", 10621 string: event.clipboardData.getData("text/plain") 10622 }; 10623 (_this$delegate9 = this.delegate) === null || _this$delegate9 === void 0 || _this$delegate9.inputControllerWillPaste(paste); 10624 (_this$responder6 = this.responder) === null || _this$responder6 === void 0 || _this$responder6.insertString(paste.string); 10625 this.render(); 10626 return (_this$delegate10 = this.delegate) === null || _this$delegate10 === void 0 ? void 0 : _this$delegate10.inputControllerDidPaste(paste); 10627 10628 // https://bugs.webkit.org/show_bug.cgi?id=196702 10629 } else if (href) { 10630 var _this$delegate11, _this$responder7, _this$delegate12; 10631 event.preventDefault(); 10632 paste = { 10633 type: "text/html", 10634 html: this.createLinkHTML(href) 10635 }; 10636 (_this$delegate11 = this.delegate) === null || _this$delegate11 === void 0 || _this$delegate11.inputControllerWillPaste(paste); 10637 (_this$responder7 = this.responder) === null || _this$responder7 === void 0 || _this$responder7.insertHTML(paste.html); 10638 this.render(); 10639 return (_this$delegate12 = this.delegate) === null || _this$delegate12 === void 0 ? void 0 : _this$delegate12.inputControllerDidPaste(paste); 10640 } 10641 }, 10642 beforeinput(event) { 10643 const handler = this.constructor.inputTypes[event.inputType]; 10644 if (handler) { 10645 this.withEvent(event, handler); 10646 this.scheduleR
vendor: 10,527 bytes, lines 10646-10908
10646ender(); 10647 } 10648 }, 10649 input(event) { 10650 selectionChangeObserver.reset(); 10651 }, 10652 dragstart(event) { 10653 var _this$responder8; 10654 if ((_this$responder8 = this.responder) !== null && _this$responder8 !== void 0 && _this$responder8.selectionContainsAttachments()) { 10655 var _this$responder9; 10656 event.dataTransfer.setData("application/x-trix-dragging", true); 10657 this.dragging = { 10658 range: (_this$responder9 = this.responder) === null || _this$responder9 === void 0 ? void 0 : _this$responder9.getSelectedRange(), 10659 point: pointFromEvent(event) 10660 }; 10661 } 10662 }, 10663 dragenter(event) { 10664 if (dragEventHasFiles(event)) { 10665 event.preventDefault(); 10666 } 10667 }, 10668 dragover(event) { 10669 if (this.dragging) { 10670 event.preventDefault(); 10671 const point = pointFromEvent(event); 10672 if (!objectsAreEqual(point, this.dragging.point)) { 10673 var _this$responder10; 10674 this.dragging.point = point; 10675 return (_this$responder10 = this.responder) === null || _this$responder10 === void 0 ? void 0 : _this$responder10.setLocationRangeFromPointRange(point); 10676 } 10677 } else if (dragEventHasFiles(event)) { 10678 event.preventDefault(); 10679 } 10680 }, 10681 drop(event) { 10682 if (this.dragging) { 10683 var _this$delegate13, _this$responder11; 10684 event.preventDefault(); 10685 (_this$delegate13 = this.delegate) === null || _this$delegate13 === void 0 || _this$delegate13.inputControllerWillMoveText(); 10686 (_this$responder11 = this.responder) === null || _this$responder11 === void 0 || _this$responder11.moveTextFromRange(this.dragging.range); 10687 this.dragging = null; 10688 return this.scheduleRender(); 10689 } else if (dragEventHasFiles(event)) { 10690 var _this$responder12; 10691 event.preventDefault(); 10692 const point = pointFromEvent(event); 10693 (_this$responder12 = this.responder) === null || _this$responder12 === void 0 || _this$responder12.setLocationRangeFromPointRange(point); 10694 return this.attachFiles(event.dataTransfer.files); 10695 } 10696 }, 10697 dragend() { 10698 if (this.dragging) { 10699 var _this$responder13; 10700 (_this$responder13 = this.responder) === null || _this$responder13 === void 0 || _this$responder13.setSelectedRange(this.dragging.range); 10701 this.dragging = null; 10702 } 10703 }, 10704 compositionend(event) { 10705 if (this.composing) { 10706 this.composing = false; 10707 if (!browser$1.recentAndroid) this.scheduleRender(); 10708 } 10709 } 10710 }); 10711 _defineProperty(Level2InputController, "keys", { 10712 ArrowLeft() { 10713 var _this$responder14; 10714 if ((_this$responder14 = this.responder) !== null && _this$responder14 !== void 0 && _this$responder14.shouldManageMovingCursorInDirection("backward")) { 10715 var _this$responder15; 10716 this.event.preventDefault(); 10717 return (_this$responder15 = this.responder) === null || _this$responder15 === void 0 ? void 0 : _this$responder15.moveCursorInDirection("backward"); 10718 } 10719 }, 10720 ArrowRight() { 10721 var _this$responder16; 10722 if ((_this$responder16 = this.responder) !== null && _this$responder16 !== void 0 && _this$responder16.shouldManageMovingCursorInDirection("forward")) { 10723 var _this$responder17; 10724 this.event.preventDefault(); 10725 return (_this$responder17 = this.responder) === null || _this$responder17 === void 0 ? void 0 : _this$responder17.moveCursorInDirection("forward"); 10726 } 10727 }, 10728 Backspace() { 10729 var _this$responder18; 10730 if ((_this$responder18 = this.responder) !== null && _this$responder18 !== void 0 && _this$responder18.shouldManageDeletingInDirection("backward")) { 10731 var _this$delegate14, _this$responder19; 10732 this.event.preventDefault(); 10733 (_this$delegate14 = this.delegate) === null || _this$delegate14 === void 0 || _this$delegate14.inputControllerWillPerformTyping(); 10734 (_this$responder19 = this.responder) === null || _this$responder19 === void 0 || _this$responder19.deleteInDirection("backward"); 10735 return this.render(); 10736 } 10737 }, 10738 Tab() { 10739 var _this$responder20; 10740 if ((_this$responder20 = this.responder) !== null && _this$responder20 !== void 0 && _this$responder20.canIncreaseNestingLevel()) { 10741 var _this$responder21; 10742 this.event.preventDefault(); 10743 (_this$responder21 = this.responder) === null || _this$responder21 === void 0 || _this$responder21.increaseNestingLevel(); 10744 return this.render(); 10745 } 10746 }, 10747 "Tab+Shift"() { 10748 var _this$responder22; 10749 if ((_this$responder22 = this.responder) !== null && _this$responder22 !== void 0 && _this$responder22.canDecreaseNestingLevel()) { 10750 var _this$responder23; 10751 this.event.preventDefault(); 10752 (_this$responder23 = this.responder) === null || _this$responder23 === void 0 || _this$responder23.decreaseNestingLevel(); 10753 return this.render(); 10754 } 10755 } 10756 }); 10757 _defineProperty(Level2InputController, "inputTypes", { 10758 deleteByComposition() { 10759 return this.deleteInDirection("backward", { 10760 recordUndoEntry: false 10761 }); 10762 }, 10763 deleteByCut() { 10764 return this.deleteInDirection("backward"); 10765 }, 10766 deleteByDrag() { 10767 this.event.preventDefault(); 10768 return this.withTargetDOMRange(function () { 10769 var _this$responder24; 10770 this.deleteByDragRange = (_this$responder24 = this.responder) === null || _this$responder24 === void 0 ? void 0 : _this$responder24.getSelectedRange(); 10771 }); 10772 }, 10773 deleteCompositionText() { 10774 return this.deleteInDirection("backward", { 10775 recordUndoEntry: false 10776 }); 10777 }, 10778 deleteContent() { 10779 return this.deleteInDirection("backward"); 10780 }, 10781 deleteContentBackward() { 10782 return this.deleteInDirection("backward"); 10783 }, 10784 deleteContentForward() { 10785 return this.deleteInDirection("forward"); 10786 }, 10787 deleteEntireSoftLine() { 10788 return this.deleteInDirection("forward"); 10789 }, 10790 deleteHardLineBackward() { 10791 return this.deleteInDirection("backward"); 10792 }, 10793 deleteHardLineForward() { 10794 return this.deleteInDirection("forward"); 10795 }, 10796 deleteSoftLineBackward() { 10797 return this.deleteInDirection("backward"); 10798 }, 10799 deleteSoftLineForward() { 10800 return this.deleteInDirection("forward"); 10801 }, 10802 deleteWordBackward() { 10803 return this.deleteInDirection("backward"); 10804 }, 10805 deleteWordForward() { 10806 return this.deleteInDirection("forward"); 10807 }, 10808 formatBackColor() { 10809 return this.activateAttributeIfSupported("backgroundColor", this.event.data); 10810 }, 10811 formatBold() { 10812 return this.toggleAttributeIfSupported("bold"); 10813 }, 10814 formatFontColor() { 10815 return this.activateAttributeIfSupported("color", this.event.data); 10816 }, 10817 formatFontName() { 10818 return this.activateAttributeIfSupported("font", this.event.data); 10819 }, 10820 formatIndent() { 10821 var _this$responder25; 10822 if ((_this$responder25 = this.responder) !== null && _this$responder25 !== void 0 && _this$responder25.canIncreaseNestingLevel()) { 10823 return this.withTargetDOMRange(function () { 10824 var _this$responder26; 10825 return (_this$responder26 = this.responder) === null || _this$responder26 === void 0 ? void 0 : _this$responder26.increaseNestingLevel(); 10826 }); 10827 } 10828 }, 10829 formatItalic() { 10830 return this.toggleAttributeIfSupported("italic"); 10831 }, 10832 formatJustifyCenter() { 10833 return this.toggleAttributeIfSupported("justifyCenter"); 10834 }, 10835 formatJustifyFull() { 10836 return this.toggleAttributeIfSupported("justifyFull"); 10837 }, 10838 formatJustifyLeft() { 10839 return this.toggleAttributeIfSupported("justifyLeft"); 10840 }, 10841 formatJustifyRight() { 10842 return this.toggleAttributeIfSupported("justifyRight"); 10843 }, 10844 formatOutdent() { 10845 var _this$responder27; 10846 if ((_this$responder27 = this.responder) !== null && _this$responder27 !== void 0 && _this$responder27.canDecreaseNestingLevel()) { 10847 return this.withTargetDOMRange(function () { 10848 var _this$responder28; 10849 return (_this$responder28 = this.responder) === null || _this$responder28 === void 0 ? void 0 : _this$responder28.decreaseNestingLevel(); 10850 }); 10851 } 10852 }, 10853 formatRemove() { 10854 this.withTargetDOMRange(function () { 10855 for (const attributeName in (_this$responder29 = this.responder) === null || _this$responder29 === void 0 ? void 0 : _this$responder29.getCurrentAttributes()) { 10856 var _this$responder29, _this$responder30; 10857 (_this$responder30 = this.responder) === null || _this$responder30 === void 0 || _this$responder30.removeCurrentAttribute(attributeName); 10858 } 10859 }); 10860 }, 10861 formatSetBlockTextDirection() { 10862 return this.activateAttributeIfSupported("blockDir", this.event.data); 10863 }, 10864 formatSetInlineTextDirection() { 10865 return this.activateAttributeIfSupported("textDir", this.event.data); 10866 }, 10867 formatStrikeThrough() { 10868 return this.toggleAttributeIfSupported("strike"); 10869 }, 10870 formatSubscript() { 10871 return this.toggleAttributeIfSupported("sub"); 10872 }, 10873 formatSuperscript() { 10874 return this.toggleAttributeIfSupported("sup"); 10875 }, 10876 formatUnderline() { 10877 return this.toggleAttributeIfSupported("underline"); 10878 }, 10879 historyRedo() { 10880 var _this$delegate15; 10881 return (_this$delegate15 = this.delegate) === null || _this$delegate15 === void 0 ? void 0 : _this$delegate15.inputControllerWillPerformRedo(); 10882 }, 10883 historyUndo() { 10884 var _this$delegate16; 10885 return (_this$delegate16 = this.delegate) === null || _this$delegate16 === void 0 ? void 0 : _this$delegate16.inputControllerWillPerformUndo(); 10886 }, 10887 insertCompositionText() { 10888 this.composing = true; 10889 return this.insertString(this.event.data); 10890 }, 10891 insertFromComposition() { 10892 this.composing = false; 10893 return this.insertString(this.event.data); 10894 }, 10895 insertFromDrop() { 10896 const range = this.deleteByDragRange; 10897 if (range) { 10898 var _this$delegate17; 10899 this.deleteByDragRange = null; 10900 (_this$delegate17 = this.delegate) === null || _this$delegate17 === void 0 || _this$delegate17.inputControllerWillMoveText(); 10901 return this.withTargetDOMRange(function () { 10902 var _this$responder31; 10903 return (_this$responder31 = this.responder) === null || _this$responder31 === void 0 ? void 0 : _this$responder31.moveTextFromRange(range); 10904 }); 10905 } 10906 }, 10907 insertFromPaste() { 10908
vendor: 14,517 bytes, lines 10908-11262
10908var _dataTransfer$files; 10909 const { 10910 dataTransfer 10911 } = this.event; 10912 const paste = { 10913 dataTransfer 10914 }; 10915 const href = dataTransfer.getData("URL"); 10916 const html = dataTransfer.getData("text/html"); 10917 if (href) { 10918 var _this$delegate18; 10919 let string; 10920 this.event.preventDefault(); 10921 paste.type = "text/html"; 10922 const name = dataTransfer.getData("public.url-name"); 10923 if (name) { 10924 string = squishBreakableWhitespace(name).trim(); 10925 } else { 10926 string = href; 10927 } 10928 paste.html = this.createLinkHTML(href, string); 10929 (_this$delegate18 = this.delegate) === null || _this$delegate18 === void 0 || _this$delegate18.inputControllerWillPaste(paste); 10930 this.withTargetDOMRange(function () { 10931 var _this$responder32; 10932 return (_this$responder32 = this.responder) === null || _this$responder32 === void 0 ? void 0 : _this$responder32.insertHTML(paste.html); 10933 }); 10934 this.afterRender = () => { 10935 var _this$delegate19; 10936 return (_this$delegate19 = this.delegate) === null || _this$delegate19 === void 0 ? void 0 : _this$delegate19.inputControllerDidPaste(paste); 10937 }; 10938 } else if (dataTransferIsPlainText(dataTransfer)) { 10939 var _this$delegate20; 10940 paste.type = "text/plain"; 10941 paste.string = dataTransfer.getData("text/plain"); 10942 (_this$delegate20 = this.delegate) === null || _this$delegate20 === void 0 || _this$delegate20.inputControllerWillPaste(paste); 10943 this.withTargetDOMRange(function () { 10944 var _this$responder33; 10945 return (_this$responder33 = this.responder) === null || _this$responder33 === void 0 ? void 0 : _this$responder33.insertString(paste.string); 10946 }); 10947 this.afterRender = () => { 10948 var _this$delegate21; 10949 return (_this$delegate21 = this.delegate) === null || _this$delegate21 === void 0 ? void 0 : _this$delegate21.inputControllerDidPaste(paste); 10950 }; 10951 } else if (html) { 10952 var _this$delegate22; 10953 this.event.preventDefault(); 10954 paste.type = "text/html"; 10955 paste.html = html; 10956 (_this$delegate22 = this.delegate) === null || _this$delegate22 === void 0 || _this$delegate22.inputControllerWillPaste(paste); 10957 this.withTargetDOMRange(function () { 10958 var _this$responder34; 10959 return (_this$responder34 = this.responder) === null || _this$responder34 === void 0 ? void 0 : _this$responder34.insertHTML(paste.html); 10960 }); 10961 this.afterRender = () => { 10962 var _this$delegate23; 10963 return (_this$delegate23 = this.delegate) === null || _this$delegate23 === void 0 ? void 0 : _this$delegate23.inputControllerDidPaste(paste); 10964 }; 10965 } else if ((_dataTransfer$files = dataTransfer.files) !== null && _dataTransfer$files !== void 0 && _dataTransfer$files.length) { 10966 var _this$delegate24; 10967 paste.type = "File"; 10968 paste.file = dataTransfer.files[0]; 10969 (_this$delegate24 = this.delegate) === null || _this$delegate24 === void 0 || _this$delegate24.inputControllerWillPaste(paste); 10970 this.withTargetDOMRange(function () { 10971 var _this$responder35; 10972 return (_this$responder35 = this.responder) === null || _this$responder35 === void 0 ? void 0 : _this$responder35.insertFile(paste.file); 10973 }); 10974 this.afterRender = () => { 10975 var _this$delegate25; 10976 return (_this$delegate25 = this.delegate) === null || _this$delegate25 === void 0 ? void 0 : _this$delegate25.inputControllerDidPaste(paste); 10977 }; 10978 } 10979 }, 10980 insertFromYank() { 10981 return this.insertString(this.event.data); 10982 }, 10983 insertLineBreak() { 10984 return this.insertString("\n"); 10985 }, 10986 insertLink() { 10987 return this.activateAttributeIfSupported("href", this.event.data); 10988 }, 10989 insertOrderedList() { 10990 return this.toggleAttributeIfSupported("number"); 10991 }, 10992 insertParagraph() { 10993 var _this$delegate26; 10994 (_this$delegate26 = this.delegate) === null || _this$delegate26 === void 0 || _this$delegate26.inputControllerWillPerformTyping(); 10995 return this.withTargetDOMRange(function () { 10996 var _this$responder36; 10997 return (_this$responder36 = this.responder) === null || _this$responder36 === void 0 ? void 0 : _this$responder36.insertLineBreak(); 10998 }); 10999 }, 11000 insertReplacementText() { 11001 const replacement = this.event.dataTransfer.getData("text/plain"); 11002 const domRange = this.event.getTargetRanges()[0]; 11003 this.withTargetDOMRange(domRange, () => { 11004 this.insertString(replacement, { 11005 updatePosition: false 11006 }); 11007 }); 11008 }, 11009 insertText() { 11010 var _this$event$dataTrans; 11011 return this.insertString(this.event.data || ((_this$event$dataTrans = this.event.dataTransfer) === null || _this$event$dataTrans === void 0 ? void 0 : _this$event$dataTrans.getData("text/plain"))); 11012 }, 11013 insertTranspose() { 11014 return this.insertString(this.event.data); 11015 }, 11016 insertUnorderedList() { 11017 return this.toggleAttributeIfSupported("bullet"); 11018 } 11019 }); 11020 const staticRangeToRange = function (staticRange) { 11021 const range = document.createRange(); 11022 range.setStart(staticRange.startContainer, staticRange.startOffset); 11023 range.setEnd(staticRange.endContainer, staticRange.endOffset); 11024 return range; 11025 }; 11026 11027 // Event helpers 11028 11029 const dragEventHasFiles = event => { 11030 var _event$dataTransfer; 11031 return Array.from(((_event$dataTransfer = event.dataTransfer) === null || _event$dataTransfer === void 0 ? void 0 : _event$dataTransfer.types) || []).includes("Files"); 11032 }; 11033 const pasteEventHasFilesOnly = function (event) { 11034 const clipboard = event.clipboardData; 11035 if (clipboard) { 11036 return clipboard.types.includes("Files") && clipboard.types.length === 1 && clipboard.files.length >= 1; 11037 } 11038 }; 11039 const pasteEventHasPlainTextOnly = function (event) { 11040 const clipboard = event.clipboardData; 11041 if (clipboard) { 11042 return clipboard.types.includes("text/plain") && clipboard.types.length === 1; 11043 } 11044 }; 11045 const keyboardCommandFromKeyEvent = function (event) { 11046 const command = []; 11047 if (event.altKey) { 11048 command.push("alt"); 11049 } 11050 if (event.shiftKey) { 11051 command.push("shift"); 11052 } 11053 command.push(event.key); 11054 return command; 11055 }; 11056 const pointFromEvent = event => ({ 11057 x: event.clientX, 11058 y: event.clientY 11059 }); 11060 11061 const attributeButtonSelector = "[data-trix-attribute]"; 11062 const actionButtonSelector = "[data-trix-action]"; 11063 const toolbarButtonSelector = "".concat(attributeButtonSelector, ", ").concat(actionButtonSelector); 11064 const dialogSelector = "[data-trix-dialog]"; 11065 const activeDialogSelector = "".concat(dialogSelector, "[data-trix-active]"); 11066 const dialogButtonSelector = "".concat(dialogSelector, " [data-trix-method]"); 11067 const dialogInputSelector = "".concat(dialogSelector, " [data-trix-input]"); 11068 const getInputForDialog = (element, attributeName) => { 11069 if (!attributeName) { 11070 attributeName = getAttributeName(element); 11071 } 11072 return element.querySelector("[data-trix-input][name='".concat(attributeName, "']")); 11073 }; 11074 const getActionName = element => element.getAttribute("data-trix-action"); 11075 const getAttributeName = element => { 11076 return element.getAttribute("data-trix-attribute") || element.getAttribute("data-trix-dialog-attribute"); 11077 }; 11078 const getDialogName = element => element.getAttribute("data-trix-dialog"); 11079 class ToolbarController extends BasicObject { 11080 constructor(element) { 11081 super(element); 11082 this.didClickActionButton = this.didClickActionButton.bind(this); 11083 this.didClickAttributeButton = this.didClickAttributeButton.bind(this); 11084 this.didClickDialogButton = this.didClickDialogButton.bind(this); 11085 this.didKeyDownDialogInput = this.didKeyDownDialogInput.bind(this); 11086 this.element = element; 11087 this.attributes = {}; 11088 this.actions = {}; 11089 this.resetDialogInputs(); 11090 handleEvent("mousedown", { 11091 onElement: this.element, 11092 matchingSelector: actionButtonSelector, 11093 withCallback: this.didClickActionButton 11094 }); 11095 handleEvent("mousedown", { 11096 onElement: this.element, 11097 matchingSelector: attributeButtonSelector, 11098 withCallback: this.didClickAttributeButton 11099 }); 11100 handleEvent("click", { 11101 onElement: this.element, 11102 matchingSelector: toolbarButtonSelector, 11103 preventDefault: true 11104 }); 11105 handleEvent("click", { 11106 onElement: this.element, 11107 matchingSelector: dialogButtonSelector, 11108 withCallback: this.didClickDialogButton 11109 }); 11110 handleEvent("keydown", { 11111 onElement: this.element, 11112 matchingSelector: dialogInputSelector, 11113 withCallback: this.didKeyDownDialogInput 11114 }); 11115 } 11116 11117 // Event handlers 11118 11119 didClickActionButton(event, element) { 11120 var _this$delegate; 11121 (_this$delegate = this.delegate) === null || _this$delegate === void 0 || _this$delegate.toolbarDidClickButton(); 11122 event.preventDefault(); 11123 const actionName = getActionName(element); 11124 if (this.getDialog(actionName)) { 11125 return this.toggleDialog(actionName); 11126 } else { 11127 var _this$delegate2; 11128 return (_this$delegate2 = this.delegate) === null || _this$delegate2 === void 0 ? void 0 : _this$delegate2.toolbarDidInvokeAction(actionName, element); 11129 } 11130 } 11131 didClickAttributeButton(event, element) { 11132 var _this$delegate3; 11133 (_this$delegate3 = this.delegate) === null || _this$delegate3 === void 0 || _this$delegate3.toolbarDidClickButton(); 11134 event.preventDefault(); 11135 const attributeName = getAttributeName(element); 11136 if (this.getDialog(attributeName)) { 11137 this.toggleDialog(attributeName); 11138 } else { 11139 var _this$delegate4; 11140 (_this$delegate4 = this.delegate) === null || _this$delegate4 === void 0 || _this$delegate4.toolbarDidToggleAttribute(attributeName); 11141 } 11142 return this.refreshAttributeButtons(); 11143 } 11144 didClickDialogButton(event, element) { 11145 const dialogElement = findClosestElementFromNode(element, { 11146 matchingSelector: dialogSelector 11147 }); 11148 const method = element.getAttribute("data-trix-method"); 11149 return this[method].call(this, dialogElement); 11150 } 11151 didKeyDownDialogInput(event, element) { 11152 if (event.keyCode === 13) { 11153 // Enter key 11154 event.preventDefault(); 11155 const attribute = element.getAttribute("name"); 11156 const dialog = this.getDialog(attribute); 11157 this.setAttribute(dialog); 11158 } 11159 if (event.keyCode === 27) { 11160 // Escape key 11161 event.preventDefault(); 11162 return this.hideDialog(); 11163 } 11164 } 11165 11166 // Action buttons 11167 11168 updateActions(actions) { 11169 this.actions = actions; 11170 return this.refreshActionButtons(); 11171 } 11172 refreshActionButtons() { 11173 return this.eachActionButton((element, actionName) => { 11174 element.disabled = this.actions[actionName] === false; 11175 }); 11176 } 11177 eachActionButton(callback) { 11178 return Array.from(this.element.querySelectorAll(actionButtonSelector)).map(element => callback(element, getActionName(element))); 11179 } 11180 11181 // Attribute buttons 11182 11183 updateAttributes(attributes) { 11184 this.attributes = attributes; 11185 return this.refreshAttributeButtons(); 11186 } 11187 refreshAttributeButtons() { 11188 return this.eachAttributeButton((element, attributeName) => { 11189 element.disabled = this.attributes[attributeName] === false; 11190 if (this.attributes[attributeName] || this.dialogIsVisible(attributeName)) { 11191 element.setAttribute("data-trix-active", ""); 11192 return element.classList.add("trix-active"); 11193 } else { 11194 element.removeAttribute("data-trix-active"); 11195 return element.classList.remove("trix-active"); 11196 } 11197 }); 11198 } 11199 eachAttributeButton(callback) { 11200 return Array.from(this.element.querySelectorAll(attributeButtonSelector)).map(element => callback(element, getAttributeName(element))); 11201 } 11202 applyKeyboardCommand(keys) { 11203 const keyString = JSON.stringify(keys.sort()); 11204 for (const button of Array.from(this.element.querySelectorAll("[data-trix-key]"))) { 11205 const buttonKeys = button.getAttribute("data-trix-key").split("+"); 11206 const buttonKeyString = JSON.stringify(buttonKeys.sort()); 11207 if (buttonKeyString === keyString) { 11208 triggerEvent("mousedown", { 11209 onElement: button 11210 }); 11211 return true; 11212 } 11213 } 11214 return false; 11215 } 11216 11217 // Dialogs 11218 11219 dialogIsVisible(dialogName) { 11220 const element = this.getDialog(dialogName); 11221 if (element) { 11222 return element.hasAttribute("data-trix-active"); 11223 } 11224 } 11225 toggleDialog(dialogName) { 11226 if (this.dialogIsVisible(dialogName)) { 11227 return this.hideDialog(); 11228 } else { 11229 return this.showDialog(dialogName); 11230 } 11231 } 11232 showDialog(dialogName) { 11233 var _this$delegate5, _this$delegate6; 11234 this.hideDialog(); 11235 (_this$delegate5 = this.delegate) === null || _this$delegate5 === void 0 || _this$delegate5.toolbarWillShowDialog(); 11236 const element = this.getDialog(dialogName); 11237 element.setAttribute("data-trix-active", ""); 11238 element.classList.add("trix-active"); 11239 Array.from(element.querySelectorAll("input[disabled]")).forEach(disabledInput => { 11240 disabledInput.removeAttribute("disabled"); 11241 }); 11242 const attributeName = getAttributeName(element); 11243 if (attributeName) { 11244 const input = getInputForDialog(element, dialogName); 11245 if (input) { 11246 input.value = this.attributes[attributeName] || ""; 11247 input.select(); 11248 } 11249 } 11250 return (_this$delegate6 = this.delegate) === null || _this$delegate6 === void 0 ? void 0 : _this$delegate6.toolbarDidShowDialog(dialogName); 11251 } 11252 setAttribute(dialogElement) { 11253 const attributeName = getAttributeName(dialogElement); 11254 const input = getInputForDialog(dialogElement, attributeName); 11255 if (input.willValidate && !input.checkValidity()) { 11256 input.setAttribute("data-trix-validate", ""); 11257 input.classList.add("trix-validate"); 11258 return input.focus(); 11259 } else { 11260 var _this$delegate7; 11261 (_this$delegate7 = this.delegate) === null || _this$delegate7 === void 0 || _this$delegate7.toolbarDidUpdateAttribute(attributeName, input.value); 11262 return this.hideDialog()
vendor: 15,645 bytes, lines 11262-11702
11262; 11263 } 11264 } 11265 removeAttribute(dialogElement) { 11266 var _this$delegate8; 11267 const attributeName = getAttributeName(dialogElement); 11268 (_this$delegate8 = this.delegate) === null || _this$delegate8 === void 0 || _this$delegate8.toolbarDidRemoveAttribute(attributeName); 11269 return this.hideDialog(); 11270 } 11271 hideDialog() { 11272 const element = this.element.querySelector(activeDialogSelector); 11273 if (element) { 11274 var _this$delegate9; 11275 element.removeAttribute("data-trix-active"); 11276 element.classList.remove("trix-active"); 11277 this.resetDialogInputs(); 11278 return (_this$delegate9 = this.delegate) === null || _this$delegate9 === void 0 ? void 0 : _this$delegate9.toolbarDidHideDialog(getDialogName(element)); 11279 } 11280 } 11281 resetDialogInputs() { 11282 Array.from(this.element.querySelectorAll(dialogInputSelector)).forEach(input => { 11283 input.setAttribute("disabled", "disabled"); 11284 input.removeAttribute("data-trix-validate"); 11285 input.classList.remove("trix-validate"); 11286 }); 11287 } 11288 getDialog(dialogName) { 11289 return this.element.querySelector("[data-trix-dialog=".concat(dialogName, "]")); 11290 } 11291 } 11292 11293 const snapshotsAreEqual = (a, b) => rangesAreEqual(a.selectedRange, b.selectedRange) && a.document.isEqualTo(b.document); 11294 class EditorController extends Controller { 11295 constructor(_ref) { 11296 let { 11297 editorElement, 11298 document, 11299 html 11300 } = _ref; 11301 super(...arguments); 11302 this.editorElement = editorElement; 11303 this.selectionManager = new SelectionManager(this.editorElement); 11304 this.selectionManager.delegate = this; 11305 this.composition = new Composition(); 11306 this.composition.delegate = this; 11307 this.attachmentManager = new AttachmentManager(this.composition.getAttachments()); 11308 this.attachmentManager.delegate = this; 11309 this.inputController = input.getLevel() === 2 ? new Level2InputController(this.editorElement) : new Level0InputController(this.editorElement); 11310 this.inputController.delegate = this; 11311 this.inputController.responder = this.composition; 11312 this.compositionController = new CompositionController(this.editorElement, this.composition); 11313 this.compositionController.delegate = this; 11314 this.toolbarController = new ToolbarController(this.editorElement.toolbarElement); 11315 this.toolbarController.delegate = this; 11316 this.editor = new Editor(this.composition, this.selectionManager, this.editorElement); 11317 if (document) { 11318 this.editor.loadDocument(document); 11319 } else { 11320 this.editor.loadHTML(html); 11321 } 11322 } 11323 registerSelectionManager() { 11324 return selectionChangeObserver.registerSelectionManager(this.selectionManager); 11325 } 11326 unregisterSelectionManager() { 11327 return selectionChangeObserver.unregisterSelectionManager(this.selectionManager); 11328 } 11329 render() { 11330 return this.compositionController.render(); 11331 } 11332 reparse() { 11333 return this.composition.replaceHTML(this.editorElement.innerHTML); 11334 } 11335 11336 // Composition delegate 11337 11338 compositionDidChangeDocument(document) { 11339 this.notifyEditorElement("document-change"); 11340 if (!this.handlingInput) { 11341 return this.render(); 11342 } 11343 } 11344 compositionDidChangeCurrentAttributes(currentAttributes) { 11345 this.currentAttributes = currentAttributes; 11346 this.toolbarController.updateAttributes(this.currentAttributes); 11347 this.updateCurrentActions(); 11348 return this.notifyEditorElement("attributes-change", { 11349 attributes: this.currentAttributes 11350 }); 11351 } 11352 compositionDidPerformInsertionAtRange(range) { 11353 if (this.pasting) { 11354 this.pastedRange = range; 11355 } 11356 } 11357 compositionShouldAcceptFile(file) { 11358 return this.notifyEditorElement("file-accept", { 11359 file 11360 }); 11361 } 11362 compositionDidAddAttachment(attachment) { 11363 const managedAttachment = this.attachmentManager.manageAttachment(attachment); 11364 return this.notifyEditorElement("attachment-add", { 11365 attachment: managedAttachment 11366 }); 11367 } 11368 compositionDidEditAttachment(attachment) { 11369 this.compositionController.rerenderViewForObject(attachment); 11370 const managedAttachment = this.attachmentManager.manageAttachment(attachment); 11371 this.notifyEditorElement("attachment-edit", { 11372 attachment: managedAttachment 11373 }); 11374 return this.notifyEditorElement("change"); 11375 } 11376 compositionDidChangeAttachmentPreviewURL(attachment) { 11377 this.compositionController.invalidateViewForObject(attachment); 11378 return this.notifyEditorElement("change"); 11379 } 11380 compositionDidRemoveAttachment(attachment) { 11381 const managedAttachment = this.attachmentManager.unmanageAttachment(attachment); 11382 return this.notifyEditorElement("attachment-remove", { 11383 attachment: managedAttachment 11384 }); 11385 } 11386 compositionDidStartEditingAttachment(attachment, options) { 11387 this.attachmentLocationRange = this.composition.document.getLocationRangeOfAttachment(attachment); 11388 this.compositionController.installAttachmentEditorForAttachment(attachment, options); 11389 return this.selectionManager.setLocationRange(this.attachmentLocationRange); 11390 } 11391 compositionDidStopEditingAttachment(attachment) { 11392 this.compositionController.uninstallAttachmentEditor(); 11393 this.attachmentLocationRange = null; 11394 } 11395 compositionDidRequestChangingSelectionToLocationRange(locationRange) { 11396 if (this.loadingSnapshot && !this.isFocused()) return; 11397 this.requestedLocationRange = locationRange; 11398 this.compositionRevisionWhenLocationRangeRequested = this.composition.revision; 11399 if (!this.handlingInput) { 11400 return this.render(); 11401 } 11402 } 11403 compositionWillLoadSnapshot() { 11404 this.loadingSnapshot = true; 11405 } 11406 compositionDidLoadSnapshot() { 11407 this.compositionController.refreshViewCache(); 11408 this.render(); 11409 this.loadingSnapshot = false; 11410 } 11411 getSelectionManager() { 11412 return this.selectionManager; 11413 } 11414 11415 // Attachment manager delegate 11416 11417 attachmentManagerDidRequestRemovalOfAttachment(attachment) { 11418 return this.removeAttachment(attachment); 11419 } 11420 11421 // Document controller delegate 11422 11423 compositionControllerWillSyncDocumentView() { 11424 this.inputController.editorWillSyncDocumentView(); 11425 this.selectionManager.lock(); 11426 return this.selectionManager.clearSelection(); 11427 } 11428 compositionControllerDidSyncDocumentView() { 11429 this.inputController.editorDidSyncDocumentView(); 11430 this.selectionManager.unlock(); 11431 this.updateCurrentActions(); 11432 return this.notifyEditorElement("sync"); 11433 } 11434 compositionControllerDidRender() { 11435 if (this.requestedLocationRange) { 11436 if (this.compositionRevisionWhenLocationRangeRequested === this.composition.revision) { 11437 this.selectionManager.setLocationRange(this.requestedLocationRange); 11438 } 11439 this.requestedLocationRange = null; 11440 this.compositionRevisionWhenLocationRangeRequested = null; 11441 } 11442 if (this.renderedCompositionRevision !== this.composition.revision) { 11443 this.runEditorFilters(); 11444 this.composition.updateCurrentAttributes(); 11445 this.notifyEditorElement("render"); 11446 } 11447 this.renderedCompositionRevision = this.composition.revision; 11448 } 11449 compositionControllerDidFocus() { 11450 if (this.isFocusedInvisibly()) { 11451 this.setLocationRange({ 11452 index: 0, 11453 offset: 0 11454 }); 11455 } 11456 this.toolbarController.hideDialog(); 11457 return this.notifyEditorElement("focus"); 11458 } 11459 compositionControllerDidBlur() { 11460 return this.notifyEditorElement("blur"); 11461 } 11462 compositionControllerDidSelectAttachment(attachment, options) { 11463 this.toolbarController.hideDialog(); 11464 return this.composition.editAttachment(attachment, options); 11465 } 11466 compositionControllerDidRequestDeselectingAttachment(attachment) { 11467 const locationRange = this.attachmentLocationRange || this.composition.document.getLocationRangeOfAttachment(attachment); 11468 return this.selectionManager.setLocationRange(locationRange[1]); 11469 } 11470 compositionControllerWillUpdateAttachment(attachment) { 11471 return this.editor.recordUndoEntry("Edit Attachment", { 11472 context: attachment.id, 11473 consolidatable: true 11474 }); 11475 } 11476 compositionControllerDidRequestRemovalOfAttachment(attachment) { 11477 return this.removeAttachment(attachment); 11478 } 11479 11480 // Input controller delegate 11481 11482 inputControllerWillHandleInput() { 11483 this.handlingInput = true; 11484 this.requestedRender = false; 11485 } 11486 inputControllerDidRequestRender() { 11487 this.requestedRender = true; 11488 } 11489 inputControllerDidHandleInput() { 11490 this.handlingInput = false; 11491 if (this.requestedRender) { 11492 this.requestedRender = false; 11493 return this.render(); 11494 } 11495 } 11496 inputControllerDidAllowUnhandledInput() { 11497 return this.notifyEditorElement("change"); 11498 } 11499 inputControllerDidRequestReparse() { 11500 return this.reparse(); 11501 } 11502 inputControllerWillPerformTyping() { 11503 return this.recordTypingUndoEntry(); 11504 } 11505 inputControllerWillPerformFormatting(attributeName) { 11506 return this.recordFormattingUndoEntry(attributeName); 11507 } 11508 inputControllerWillCutText() { 11509 return this.editor.recordUndoEntry("Cut"); 11510 } 11511 inputControllerWillPaste(paste) { 11512 this.editor.recordUndoEntry("Paste"); 11513 this.pasting = true; 11514 return this.notifyEditorElement("before-paste", { 11515 paste 11516 }); 11517 } 11518 inputControllerDidPaste(paste) { 11519 paste.range = this.pastedRange; 11520 this.pastedRange = null; 11521 this.pasting = null; 11522 return this.notifyEditorElement("paste", { 11523 paste 11524 }); 11525 } 11526 inputControllerWillMoveText() { 11527 return this.editor.recordUndoEntry("Move"); 11528 } 11529 inputControllerWillAttachFiles() { 11530 return this.editor.recordUndoEntry("Drop Files"); 11531 } 11532 inputControllerWillPerformUndo() { 11533 return this.editor.undo(); 11534 } 11535 inputControllerWillPerformRedo() { 11536 return this.editor.redo(); 11537 } 11538 inputControllerDidReceiveKeyboardCommand(keys) { 11539 return this.toolbarController.applyKeyboardCommand(keys); 11540 } 11541 inputControllerDidStartDrag() { 11542 this.locationRangeBeforeDrag = this.selectionManager.getLocationRange(); 11543 } 11544 inputControllerDidReceiveDragOverPoint(point) { 11545 return this.selectionManager.setLocationRangeFromPointRange(point); 11546 } 11547 inputControllerDidCancelDrag() { 11548 this.selectionManager.setLocationRange(this.locationRangeBeforeDrag); 11549 this.locationRangeBeforeDrag = null; 11550 } 11551 11552 // Selection manager delegate 11553 11554 locationRangeDidChange(locationRange) { 11555 this.composition.updateCurrentAttributes(); 11556 this.updateCurrentActions(); 11557 if (this.attachmentLocationRange && !rangesAreEqual(this.attachmentLocationRange, locationRange)) { 11558 this.composition.stopEditingAttachment(); 11559 } 11560 return this.notifyEditorElement("selection-change"); 11561 } 11562 11563 // Toolbar controller delegate 11564 11565 toolbarDidClickButton() { 11566 if (!this.getLocationRange()) { 11567 return this.setLocationRange({ 11568 index: 0, 11569 offset: 0 11570 }); 11571 } 11572 } 11573 toolbarDidInvokeAction(actionName, invokingElement) { 11574 return this.invokeAction(actionName, invokingElement); 11575 } 11576 toolbarDidToggleAttribute(attributeName) { 11577 this.recordFormattingUndoEntry(attributeName); 11578 this.composition.toggleCurrentAttribute(attributeName); 11579 this.render(); 11580 if (!this.selectionFrozen) { 11581 return this.editorElement.focus(); 11582 } 11583 } 11584 toolbarDidUpdateAttribute(attributeName, value) { 11585 this.recordFormattingUndoEntry(attributeName); 11586 this.composition.setCurrentAttribute(attributeName, value); 11587 this.render(); 11588 if (!this.selectionFrozen) { 11589 return this.editorElement.focus(); 11590 } 11591 } 11592 toolbarDidRemoveAttribute(attributeName) { 11593 this.recordFormattingUndoEntry(attributeName); 11594 this.composition.removeCurrentAttribute(attributeName); 11595 this.render(); 11596 if (!this.selectionFrozen) { 11597 return this.editorElement.focus(); 11598 } 11599 } 11600 toolbarWillShowDialog(dialogElement) { 11601 this.composition.expandSelectionForEditing(); 11602 return this.freezeSelection(); 11603 } 11604 toolbarDidShowDialog(dialogName) { 11605 return this.notifyEditorElement("toolbar-dialog-show", { 11606 dialogName 11607 }); 11608 } 11609 toolbarDidHideDialog(dialogName) { 11610 this.thawSelection(); 11611 this.editorElement.focus(); 11612 return this.notifyEditorElement("toolbar-dialog-hide", { 11613 dialogName 11614 }); 11615 } 11616 11617 // Selection 11618 11619 freezeSelection() { 11620 if (!this.selectionFrozen) { 11621 this.selectionManager.lock(); 11622 this.composition.freezeSelection(); 11623 this.selectionFrozen = true; 11624 return this.render(); 11625 } 11626 } 11627 thawSelection() { 11628 if (this.selectionFrozen) { 11629 this.composition.thawSelection(); 11630 this.selectionManager.unlock(); 11631 this.selectionFrozen = false; 11632 return this.render(); 11633 } 11634 } 11635 canInvokeAction(actionName) { 11636 if (this.actionIsExternal(actionName)) { 11637 return true; 11638 } else { 11639 var _this$actions$actionN; 11640 return !!((_this$actions$actionN = this.actions[actionName]) !== null && _this$actions$actionN !== void 0 && (_this$actions$actionN = _this$actions$actionN.test) !== null && _this$actions$actionN !== void 0 && _this$actions$actionN.call(this)); 11641 } 11642 } 11643 invokeAction(actionName, invokingElement) { 11644 if (this.actionIsExternal(actionName)) { 11645 return this.notifyEditorElement("action-invoke", { 11646 actionName, 11647 invokingElement 11648 }); 11649 } else { 11650 var _this$actions$actionN2; 11651 return (_this$actions$actionN2 = this.actions[actionName]) === null || _this$actions$actionN2 === void 0 || (_this$actions$actionN2 = _this$actions$actionN2.perform) === null || _this$actions$actionN2 === void 0 ? void 0 : _this$actions$actionN2.call(this); 11652 } 11653 } 11654 actionIsExternal(actionName) { 11655 return /^x-./.test(actionName); 11656 } 11657 getCurrentActions() { 11658 const result = {}; 11659 for (const actionName in this.actions) { 11660 result[actionName] = this.canInvokeAction(actionName); 11661 } 11662 return result; 11663 } 11664 updateCurrentActions() { 11665 const currentActions = this.getCurrentActions(); 11666 if (!objectsAreEqual(currentActions, this.currentActions)) { 11667 this.currentActions = currentActions; 11668 this.toolbarController.updateActions(this.currentActions); 11669 return this.notifyEditorElement("actions-change", { 11670 actions: this.currentActions 11671 }); 11672 } 11673 } 11674 11675 // Editor filters 11676 11677 runEditorFilters() { 11678 let snapshot = this.composition.getSnapshot(); 11679 Array.from(this.editor.filters).forEach(filter => { 11680 const { 11681 document, 11682 selectedRange 11683 } = snapshot; 11684 snapshot = filter.call(this.editor, snapshot) || {}; 11685 if (!snapshot.document) { 11686 snapshot.document = document; 11687 } 11688 if (!snapshot.selectedRange) { 11689 snapshot.selectedRange = selectedRange; 11690 } 11691 }); 11692 if (!snapshotsAreEqual(snapshot, this.composition.getSnapshot())) { 11693 return this.composition.loadSnapshot(snapshot); 11694 } 11695 } 11696 11697 // Private 11698 11699 updateInputElement() { 11700 const element = this.compositionController.getSerializableElement(); 11701 const value = serializeToContentType(element, "text/html"); 11702 return this.editorElement.set
11702InputElementValue(value); 11703 } 11704 notifyEditorElement(message, data) { 11705 switch (message) { 11706 case "document-change": 11707 this.documentChangedSinceLastRender = true; 11708 break; 11709 case "render": 11710 if (this.documentChangedSinceLastRender) { 11711 this.documentChangedSinceLastRender = false;
vendor: 5,857 bytes, lines 11712-11895
11712 this.notifyEditorElement("change"); 11713 } 11714 break; 11715 case "change": 11716 case "attachment-add": 11717 case "attachment-edit": 11718 case "attachment-remove": 11719 this.updateInputElement(); 11720 break; 11721 } 11722 return this.editorElement.notify(message, data); 11723 } 11724 removeAttachment(attachment) { 11725 this.editor.recordUndoEntry("Delete Attachment"); 11726 this.composition.removeAttachment(attachment); 11727 return this.render(); 11728 } 11729 recordFormattingUndoEntry(attributeName) { 11730 const blockConfig = getBlockConfig(attributeName); 11731 const locationRange = this.selectionManager.getLocationRange(); 11732 if (blockConfig || !rangeIsCollapsed(locationRange)) { 11733 return this.editor.recordUndoEntry("Formatting", { 11734 context: this.getUndoContext(), 11735 consolidatable: true 11736 }); 11737 } 11738 } 11739 recordTypingUndoEntry() { 11740 return this.editor.recordUndoEntry("Typing", { 11741 context: this.getUndoContext(this.currentAttributes), 11742 consolidatable: true 11743 }); 11744 } 11745 getUndoContext() { 11746 for (var _len = arguments.length, context = new Array(_len), _key = 0; _key < _len; _key++) { 11747 context[_key] = arguments[_key]; 11748 } 11749 return [this.getLocationContext(), this.getTimeContext(), ...Array.from(context)]; 11750 } 11751 getLocationContext() { 11752 const locationRange = this.selectionManager.getLocationRange(); 11753 if (rangeIsCollapsed(locationRange)) { 11754 return locationRange[0].index; 11755 } else { 11756 return locationRange; 11757 } 11758 } 11759 getTimeContext() { 11760 if (undo.interval > 0) { 11761 return Math.floor(new Date().getTime() / undo.interval); 11762 } else { 11763 return 0; 11764 } 11765 } 11766 isFocused() { 11767 var _this$editorElement$o; 11768 return this.editorElement === ((_this$editorElement$o = this.editorElement.ownerDocument) === null || _this$editorElement$o === void 0 ? void 0 : _this$editorElement$o.activeElement); 11769 } 11770 11771 // Detect "Cursor disappears sporadically" Firefox bug. 11772 // - https://bugzilla.mozilla.org/show_bug.cgi?id=226301 11773 isFocusedInvisibly() { 11774 return this.isFocused() && !this.getLocationRange(); 11775 } 11776 get actions() { 11777 return this.constructor.actions; 11778 } 11779 } 11780 _defineProperty(EditorController, "actions", { 11781 undo: { 11782 test() { 11783 return this.editor.canUndo(); 11784 }, 11785 perform() { 11786 return this.editor.undo(); 11787 } 11788 }, 11789 redo: { 11790 test() { 11791 return this.editor.canRedo(); 11792 }, 11793 perform() { 11794 return this.editor.redo(); 11795 } 11796 }, 11797 link: { 11798 test() { 11799 return this.editor.canActivateAttribute("href"); 11800 } 11801 }, 11802 increaseNestingLevel: { 11803 test() { 11804 return this.editor.canIncreaseNestingLevel(); 11805 }, 11806 perform() { 11807 return this.editor.increaseNestingLevel() && this.render(); 11808 } 11809 }, 11810 decreaseNestingLevel: { 11811 test() { 11812 return this.editor.canDecreaseNestingLevel(); 11813 }, 11814 perform() { 11815 return this.editor.decreaseNestingLevel() && this.render(); 11816 } 11817 }, 11818 attachFiles: { 11819 test() { 11820 return true; 11821 }, 11822 perform() { 11823 return input.pickFiles(this.editor.insertFiles); 11824 } 11825 } 11826 }); 11827 EditorController.proxyMethod("getSelectionManager().setLocationRange"); 11828 EditorController.proxyMethod("getSelectionManager().getLocationRange"); 11829 11830 var controllers = /*#__PURE__*/Object.freeze({ 11831 __proto__: null, 11832 AttachmentEditorController: AttachmentEditorController, 11833 CompositionController: CompositionController, 11834 Controller: Controller, 11835 EditorController: EditorController, 11836 InputController: InputController, 11837 Level0InputController: Level0InputController, 11838 Level2InputController: Level2InputController, 11839 ToolbarController: ToolbarController 11840 }); 11841 11842 var observers = /*#__PURE__*/Object.freeze({ 11843 __proto__: null, 11844 MutationObserver: MutationObserver, 11845 SelectionChangeObserver: SelectionChangeObserver 11846 }); 11847 11848 var operations = /*#__PURE__*/Object.freeze({ 11849 __proto__: null, 11850 FileVerificationOperation: FileVerificationOperation, 11851 ImagePreloadOperation: ImagePreloadOperation 11852 }); 11853 11854 installDefaultCSSForTagName("trix-toolbar", "%t {\n display: block;\n}\n\n%t {\n white-space: nowrap;\n}\n\n%t [data-trix-dialog] {\n display: none;\n}\n\n%t [data-trix-dialog][data-trix-active] {\n display: block;\n}\n\n%t [data-trix-dialog] [data-trix-validate]:invalid {\n background-color: #ffdddd;\n}"); 11855 class TrixToolbarElement extends HTMLElement { 11856 // Element lifecycle 11857 11858 connectedCallback() { 11859 if (this.innerHTML === "") { 11860 this.innerHTML = toolbar.getDefaultHTML(); 11861 } 11862 } 11863 } 11864 11865 let id = 0; 11866 11867 // Contenteditable support helpers 11868 11869 const autofocus = function (element) { 11870 if (!document.querySelector(":focus")) { 11871 if (element.hasAttribute("autofocus") && document.querySelector("[autofocus]") === element) { 11872 return element.focus(); 11873 } 11874 } 11875 }; 11876 const makeEditable = function (element) { 11877 if (element.hasAttribute("contenteditable")) { 11878 return; 11879 } 11880 element.setAttribute("contenteditable", ""); 11881 return handleEventOnce("focus", { 11882 onElement: element, 11883 withCallback() { 11884 return configureContentEditable(element); 11885 } 11886 }); 11887 }; 11888 const configureContentEditable = function (element) { 11889 disableObjectResizing(element); 11890 return setDefaultParagraphSeparator(element); 11891 }; 11892 const disableObjectResizing = function (element) { 11893 var _document$queryComman, _document; 11894 if ((_document$queryComman = (_document = document).queryCommandSupported) !== null && _document$queryComman !== void 0 && _document$queryComman.call(_document, "enableObjectResizing")) { 11895 document.execCommand("enableObjectResizing", false, false);
11896 return handleEvent("mscontrolselect", { 11897 onElement: element, 11898 preventDefault: true 11899 }); 11900 } 11901 }; 11902 const setDefaultParagraphSeparator = function (element) { 11903 var _document$queryComman2, _document2; 11904 if ((_document$queryComman2 = (_document2 = document).queryCommandSupported) !== null && _document$queryComman2 !== void 0 && _document$queryComman2.call(_document2, "DefaultParagraphSeparator")) { 11905 const { 11906 tagName 11907 } = attributes.default; 11908 if (["div", "p"].includes(tagName)) { 11909 return document.execCommand("DefaultParagraphSeparator", false, tagName); 11910 } 11911 } 11912 }; 11913 11914 // Accessibility helpers 11915 11916 const addAccessibilityRole = function (element) { 11917 if (element.hasAttribute("role")) { 11918 return; 11919 } 11920 return element.setAttribute("role", "textbox"); 11921 }; 11922 const ensureAriaLabel = function (element) { 11923 if (element.hasAttribute("aria-label") || element.hasAttribute("aria-labelledby")) { 11924 return; 11925 } 11926 const update = function () { 11927 const texts = Array.from(element.labels).map(label => { 11928 if (!label.contains(element)) return label.textContent; 11929 }).filter(text => text); 11930 const text = texts.join(" "); 11931 if (text) { 11932 return element.setAttribute("aria-label", text); 11933 } else { 11934 return element.removeAttribute("aria-label"); 11935 } 11936 }; 11937 update(); 11938 return handleEvent("focus", { 11939 onElement: element, 11940 withCallback: update 11941 }); 11942 }; 11943 11944 // Style 11945 11946 const cursorTargetStyles = function () { 11947 if (browser$1.forcesObjectResizing) { 11948 return { 11949 display: "inline", 11950 width: "auto" 11951 }; 11952 } else { 11953 return { 11954 display: "inline-block", 11955 width: "1px" 11956 }; 11957 } 11958 }(); 11959 installDefaultCSSForTagName("trix-editor", "%t {\n display: block;\n}\n\n%t:empty:not(:focus)::before {\n content: attr(placeholder);\n color: graytext;\n cursor: text;\n pointer-events: none;\n white-space: pre-line;\n}\n\n%t a[contenteditable=false] {\n cursor: text;\n}\n\n%t img {\n max-width: 100%;\n height: auto;\n}\n\n%t ".concat(attachmentSelector, " figcaption textarea {\n resize: none;\n}\n\n%t ").concat(attachmentSelector, " figcaption textarea.trix-autoresize-clone {\n position: absolute;\n left: -9999px;\n max-height: 0px;\n}\n\n%t ").concat(attachmentSelector, " figcaption[data-trix-placeholder]:empty::before {\n content: attr(data-trix-placeholder);\n color: graytext;\n}\n\n%t [data-trix-cursor-target] {\n display: ").concat(cursorTargetStyles.display, " !important;\n width: ").concat(cursorTargetStyles.width, " !important;\n padding: 0 !important;\n margin: 0 !important;\n border: none !important;\n}\n\n%t [data-trix-cursor-target=left] {\n vertical-align: top !important;\n margin-left: -1px !important;\n}\n\n%t [data-trix-cursor-target=right] {\n vertical-align: bottom !important;\n margin-right: -1px !important;\n}")); 11960 class TrixEditorElement extends HTMLElement { 11961 // Properties 11962 11963 get trixId() { 11964 if (this.hasAttribute("trix-id")) { 11965 return this.getAttribute("trix-id"); 11966 } else { 11967 this.setAttribute("trix-id", ++id); 11968 return this.trixId; 11969 } 11970 } 11971 get labels() { 11972 const labels = []; 11973 if (this.id && this.ownerDocument) { 11974 labels.push(...Array.from(this.ownerDocument.querySelectorAll("label[for='".concat(this.id, "']")) || [])); 11975 } 11976 const label = findClosestElementFromNode(this, { 11977 matchingSelector: "label" 11978 }); 11979 if (label) { 11980 if ([this, null].includes(label.control)) { 11981 labels.push(label); 11982 } 11983 } 11984 return labels; 11985 } 11986 get toolbarElement() { 11987 if (this.hasAttribute("toolbar")) { 11988 var _this$ownerDocument; 11989 return (_this$ownerDocument = this.ownerDocument) === null || _this$ownerDocument === void 0 ? void 0 : _this$ownerDocument.getElementById(this.getAttribute("toolbar")); 11990 } else if (this.parentNode) { 11991 const toolbarId = "trix-toolbar-".concat(this.trixId); 11992 this.setAttribute("toolbar", toolbarId); 11993 const element = makeElement("trix-toolbar", { 11994 id: toolbarId 11995 }); 11996 this.parentNode.insertBefore(element, this); 11997 return element; 11998 } else { 11999 return undefined; 12000 } 12001 } 12002 get form() { 12003 var _this$inputElement; 12004 return (_this$inputElement = this.inputElement) === null || _this$inputElement === void 0 ? void 0 : _this$inputElement.form; 12005 } 12006 get inputElement() { 12007 if (this.hasAttribute("input")) { 12008 var _this$ownerDocument2; 12009 return (_this$ownerDocument2 = this.ownerDocument) === null || _this$ownerDocument2 === void 0 ? void 0 : _this$ownerDocument2.getElementById(this.getAttribute("input")); 12010 } else if (this.parentNode) { 12011 const inputId = "trix-input-".concat(this.trixId); 12012 this.setAttribute("input", inputId); 12013 const element = makeElement("input", { 12014 type: "hidden", 12015 id: inputId 12016 }); 12017 this.parentNode.insertBefore(element, this.nextElementSibling); 12018 return element; 12019 } else { 12020 return undefined; 12021 } 12022 } 12023 get editor() { 12024 var _this$editorControlle; 12025 return (_this$editorControlle = this.editorController) === null || _this$editorControlle === void 0 ? void 0 : _this$editorControlle.editor; 12026 } 12027 get name() { 12028 var _this$inputElement2; 12029 return (_this$inputElement2 = this.inputElement) === null || _this$inputElement2 === void 0 ? void 0 : _this$inputElement2.name; 12030 } 12031 get value() { 12032 var _this$inputElement3; 12033 return (_this$inputElement3 = this.inputElement) === null || _this$inputElement3 === void 0 ? void 0 : _this$inputElement3.value; 12034 } 12035 set value(defaultValue) { 12036 var _this$editor; 12037 this.defaultValue = defaultValue; 12038 (_this$editor = this.editor) === null || _this$editor === void 0 || _this$editor.loadHTML(this.defaultValue); 12039 } 12040 12041 // Controller delegate methods 12042 12043 notify(message, data) { 12044 if (this.editorController) { 12045 return triggerEvent("trix-".concat(message), { 12046 onElement: this, 12047 attributes: data 12048 }); 12049 } 12050 } 12051 setInputElementValue(value) { 12052 if (this.inputElement) { 12053 this.inputElement.value = value; 12054 } 12055 } 12056 12057 // Element lifecycle 12058 12059 connectedCallback() { 12060 if (!this.hasAttribute("data-trix-internal")) { 12061 makeEditable(this); 12062 addAccessibilityRole(this); 12063 ensureAriaLabel(this); 12064 if (!this.editorController) { 12065 triggerEvent("trix-before-initialize", { 12066 onElement: this 12067 }); 12068 this.editorController = new EditorController({ 12069 editorElement: this, 12070 html: this.defaultValue = this.value 12071 }); 12072 requestAnimationFrame(() => triggerEvent("trix-initialize", { 12073 onElement: this 12074 })); 12075 } 12076 this.editorController.registerSelectionManager(); 12077 this.registerResetListener(); 12078 this.registerClickListener(); 12079 autofocus(this); 12080 } 12081 } 12082 disconnectedCallback() { 12083 var _this$editorControlle2; 12084 (_this$editorControlle2 = this.editorController) === null || _this$editorControlle2 === void 0 || _this$editorControlle2.unregisterSelectionManager(); 12085 this.unregisterResetListener(); 12086 return this.unregisterClickListener(); 12087 } 12088 12089 // Form support 12090 12091 registerResetListener() { 12092 this.resetListener = this.resetBubbled.bind(this); 12093 return window.addEventListener("reset", this.resetListener, false); 12094 } 12095 unregisterResetListener() { 12096 return window.removeEventListener("reset", this.resetListener, false); 12097 } 12098 registerClickListener() { 12099 this.clickListener = this.clickBubbled.bind(this); 12100 return window.addEventListener("click", this.clickListener, false); 12101 } 12102 unregisterClickListener() { 12103 return window.removeEventListener("click", this.clickListener, false); 12104 } 12105 resetBubbled(event) { 12106 if (event.defaultPrevented) return; 12107 if (event.target !== this.form) return; 12108 return this.reset(); 12109 } 12110 clickBubbled(event) { 12111 if (event.defaultPrevented) return; 12112 if (this.contains(event.target)) return; 12113 const label = findClosestElementFromNode(event.target, { 12114 matchingSelector: "label" 12115 }); 12116 if (!label) return; 12117 if (!Array.from(this.labels).includes(label)) return; 12118 return this.focus(); 12119 } 12120 reset() { 12121 this.value = this.defaultValue; 12122 } 12123 } 12124 12125 var elements = /*#__PURE__*/Object.freeze({ 12126 __proto__: null, 12127 TrixEditorElement: TrixEditorElement, 12128 TrixToolbarElement: TrixToolbarElement 12129 }); 12130 12131 var filters = /*#__PURE__*/Object.freeze({ 12132 __proto__: null, 12133 Filter: Filter, 12134 attachmentGalleryFilter: attachmentGalleryFilter 12135 }); 12136 12137 const Trix = { 12138 VERSION: version, 12139 config, 12140 core, 12141 models, 12142 views, 12143 controllers, 12144 observers, 12145 operations, 12146 elements, 12147 filters 12148 }; 12149 12150 // Expose models under the Trix constant for compatibility with v1 12151 Object.assign(Trix, models); 12152 function start() { 12153 if (!customElements.get("trix-toolbar")) { 12154 customElements.define("trix-toolbar", TrixToolbarElement); 12155 } 12156 if (!customElements.get("trix-editor")) { 12157 customElements.define("trix-editor", TrixEditorElement); 12158 } 12159 } 12160 window.Trix = Trix; 12161 setTimeout(start, 0); 12162 12163 return Trix; 12164 12165}));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.