123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749 |
- (function webpackUniversalModuleDefinition(root, factory) {
- if(typeof exports === 'object' && typeof module === 'object')
- module.exports = factory();
- else if(typeof define === 'function' && define.amd)
- define([], factory);
- else if(typeof exports === 'object')
- exports["Parchment"] = factory();
- else
- root["Parchment"] = factory();
- })(typeof self !== 'undefined' ? self : this, function() {
- return /******/ (function(modules) { // webpackBootstrap
- /******/ // The module cache
- /******/ var installedModules = {};
- /******/
- /******/ // The require function
- /******/ function __webpack_require__(moduleId) {
- /******/
- /******/ // Check if module is in cache
- /******/ if(installedModules[moduleId]) {
- /******/ return installedModules[moduleId].exports;
- /******/ }
- /******/ // Create a new module (and put it into the cache)
- /******/ var module = installedModules[moduleId] = {
- /******/ i: moduleId,
- /******/ l: false,
- /******/ exports: {}
- /******/ };
- /******/
- /******/ // Execute the module function
- /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
- /******/
- /******/ // Flag the module as loaded
- /******/ module.l = true;
- /******/
- /******/ // Return the exports of the module
- /******/ return module.exports;
- /******/ }
- /******/
- /******/
- /******/ // expose the modules object (__webpack_modules__)
- /******/ __webpack_require__.m = modules;
- /******/
- /******/ // expose the module cache
- /******/ __webpack_require__.c = installedModules;
- /******/
- /******/ // define getter function for harmony exports
- /******/ __webpack_require__.d = function(exports, name, getter) {
- /******/ if(!__webpack_require__.o(exports, name)) {
- /******/ Object.defineProperty(exports, name, {
- /******/ configurable: false,
- /******/ enumerable: true,
- /******/ get: getter
- /******/ });
- /******/ }
- /******/ };
- /******/
- /******/ // getDefaultExport function for compatibility with non-harmony modules
- /******/ __webpack_require__.n = function(module) {
- /******/ var getter = module && module.__esModule ?
- /******/ function getDefault() { return module['default']; } :
- /******/ function getModuleExports() { return module; };
- /******/ __webpack_require__.d(getter, 'a', getter);
- /******/ return getter;
- /******/ };
- /******/
- /******/ // Object.prototype.hasOwnProperty.call
- /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
- /******/
- /******/ // __webpack_public_path__
- /******/ __webpack_require__.p = "";
- /******/
- /******/ // Load entry module and return exports
- /******/ return __webpack_require__(__webpack_require__.s = 9);
- /******/ })
- /************************************************************************/
- /******/ ([
- /* 0 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var ParchmentError = /** @class */ (function (_super) {
- __extends(ParchmentError, _super);
- function ParchmentError(message) {
- var _this = this;
- message = '[Parchment] ' + message;
- _this = _super.call(this, message) || this;
- _this.message = message;
- _this.name = _this.constructor.name;
- return _this;
- }
- return ParchmentError;
- }(Error));
- exports.ParchmentError = ParchmentError;
- var attributes = {};
- var classes = {};
- var tags = {};
- var types = {};
- exports.DATA_KEY = '__blot';
- var Scope;
- (function (Scope) {
- Scope[Scope["TYPE"] = 3] = "TYPE";
- Scope[Scope["LEVEL"] = 12] = "LEVEL";
- Scope[Scope["ATTRIBUTE"] = 13] = "ATTRIBUTE";
- Scope[Scope["BLOT"] = 14] = "BLOT";
- Scope[Scope["INLINE"] = 7] = "INLINE";
- Scope[Scope["BLOCK"] = 11] = "BLOCK";
- Scope[Scope["BLOCK_BLOT"] = 10] = "BLOCK_BLOT";
- Scope[Scope["INLINE_BLOT"] = 6] = "INLINE_BLOT";
- Scope[Scope["BLOCK_ATTRIBUTE"] = 9] = "BLOCK_ATTRIBUTE";
- Scope[Scope["INLINE_ATTRIBUTE"] = 5] = "INLINE_ATTRIBUTE";
- Scope[Scope["ANY"] = 15] = "ANY";
- })(Scope = exports.Scope || (exports.Scope = {}));
- function create(input, value) {
- var match = query(input);
- if (match == null) {
- throw new ParchmentError("Unable to create " + input + " blot");
- }
- var BlotClass = match;
- var node =
- // @ts-ignore
- input instanceof Node || input['nodeType'] === Node.TEXT_NODE ? input : BlotClass.create(value);
- return new BlotClass(node, value);
- }
- exports.create = create;
- function find(node, bubble) {
- if (bubble === void 0) { bubble = false; }
- if (node == null)
- return null;
- // @ts-ignore
- if (node[exports.DATA_KEY] != null)
- return node[exports.DATA_KEY].blot;
- if (bubble)
- return find(node.parentNode, bubble);
- return null;
- }
- exports.find = find;
- function query(query, scope) {
- if (scope === void 0) { scope = Scope.ANY; }
- var match;
- if (typeof query === 'string') {
- match = types[query] || attributes[query];
- // @ts-ignore
- }
- else if (query instanceof Text || query['nodeType'] === Node.TEXT_NODE) {
- match = types['text'];
- }
- else if (typeof query === 'number') {
- if (query & Scope.LEVEL & Scope.BLOCK) {
- match = types['block'];
- }
- else if (query & Scope.LEVEL & Scope.INLINE) {
- match = types['inline'];
- }
- }
- else if (query instanceof HTMLElement) {
- var names = (query.getAttribute('class') || '').split(/\s+/);
- for (var i in names) {
- match = classes[names[i]];
- if (match)
- break;
- }
- match = match || tags[query.tagName];
- }
- if (match == null)
- return null;
- // @ts-ignore
- if (scope & Scope.LEVEL & match.scope && scope & Scope.TYPE & match.scope)
- return match;
- return null;
- }
- exports.query = query;
- function register() {
- var Definitions = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- Definitions[_i] = arguments[_i];
- }
- if (Definitions.length > 1) {
- return Definitions.map(function (d) {
- return register(d);
- });
- }
- var Definition = Definitions[0];
- if (typeof Definition.blotName !== 'string' && typeof Definition.attrName !== 'string') {
- throw new ParchmentError('Invalid definition');
- }
- else if (Definition.blotName === 'abstract') {
- throw new ParchmentError('Cannot register abstract class');
- }
- types[Definition.blotName || Definition.attrName] = Definition;
- if (typeof Definition.keyName === 'string') {
- attributes[Definition.keyName] = Definition;
- }
- else {
- if (Definition.className != null) {
- classes[Definition.className] = Definition;
- }
- if (Definition.tagName != null) {
- if (Array.isArray(Definition.tagName)) {
- Definition.tagName = Definition.tagName.map(function (tagName) {
- return tagName.toUpperCase();
- });
- }
- else {
- Definition.tagName = Definition.tagName.toUpperCase();
- }
- var tagNames = Array.isArray(Definition.tagName) ? Definition.tagName : [Definition.tagName];
- tagNames.forEach(function (tag) {
- if (tags[tag] == null || Definition.className == null) {
- tags[tag] = Definition;
- }
- });
- }
- }
- return Definition;
- }
- exports.register = register;
- /***/ }),
- /* 1 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var Registry = __webpack_require__(0);
- var Attributor = /** @class */ (function () {
- function Attributor(attrName, keyName, options) {
- if (options === void 0) { options = {}; }
- this.attrName = attrName;
- this.keyName = keyName;
- var attributeBit = Registry.Scope.TYPE & Registry.Scope.ATTRIBUTE;
- if (options.scope != null) {
- // Ignore type bits, force attribute bit
- this.scope = (options.scope & Registry.Scope.LEVEL) | attributeBit;
- }
- else {
- this.scope = Registry.Scope.ATTRIBUTE;
- }
- if (options.whitelist != null)
- this.whitelist = options.whitelist;
- }
- Attributor.keys = function (node) {
- return [].map.call(node.attributes, function (item) {
- return item.name;
- });
- };
- Attributor.prototype.add = function (node, value) {
- if (!this.canAdd(node, value))
- return false;
- node.setAttribute(this.keyName, value);
- return true;
- };
- Attributor.prototype.canAdd = function (node, value) {
- var match = Registry.query(node, Registry.Scope.BLOT & (this.scope | Registry.Scope.TYPE));
- if (match == null)
- return false;
- if (this.whitelist == null)
- return true;
- if (typeof value === 'string') {
- return this.whitelist.indexOf(value.replace(/["']/g, '')) > -1;
- }
- else {
- return this.whitelist.indexOf(value) > -1;
- }
- };
- Attributor.prototype.remove = function (node) {
- node.removeAttribute(this.keyName);
- };
- Attributor.prototype.value = function (node) {
- var value = node.getAttribute(this.keyName);
- if (this.canAdd(node, value) && value) {
- return value;
- }
- return '';
- };
- return Attributor;
- }());
- exports.default = Attributor;
- /***/ }),
- /* 2 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var linked_list_1 = __webpack_require__(11);
- var shadow_1 = __webpack_require__(5);
- var Registry = __webpack_require__(0);
- var ContainerBlot = /** @class */ (function (_super) {
- __extends(ContainerBlot, _super);
- function ContainerBlot(domNode) {
- var _this = _super.call(this, domNode) || this;
- _this.build();
- return _this;
- }
- ContainerBlot.prototype.appendChild = function (other) {
- this.insertBefore(other);
- };
- ContainerBlot.prototype.attach = function () {
- _super.prototype.attach.call(this);
- this.children.forEach(function (child) {
- child.attach();
- });
- };
- ContainerBlot.prototype.build = function () {
- var _this = this;
- this.children = new linked_list_1.default();
- // Need to be reversed for if DOM nodes already in order
- [].slice
- .call(this.domNode.childNodes)
- .reverse()
- .forEach(function (node) {
- try {
- var child = makeBlot(node);
- _this.insertBefore(child, _this.children.head || undefined);
- }
- catch (err) {
- if (err instanceof Registry.ParchmentError)
- return;
- else
- throw err;
- }
- });
- };
- ContainerBlot.prototype.deleteAt = function (index, length) {
- if (index === 0 && length === this.length()) {
- return this.remove();
- }
- this.children.forEachAt(index, length, function (child, offset, length) {
- child.deleteAt(offset, length);
- });
- };
- ContainerBlot.prototype.descendant = function (criteria, index) {
- var _a = this.children.find(index), child = _a[0], offset = _a[1];
- if ((criteria.blotName == null && criteria(child)) ||
- (criteria.blotName != null && child instanceof criteria)) {
- return [child, offset];
- }
- else if (child instanceof ContainerBlot) {
- return child.descendant(criteria, offset);
- }
- else {
- return [null, -1];
- }
- };
- ContainerBlot.prototype.descendants = function (criteria, index, length) {
- if (index === void 0) { index = 0; }
- if (length === void 0) { length = Number.MAX_VALUE; }
- var descendants = [];
- var lengthLeft = length;
- this.children.forEachAt(index, length, function (child, index, length) {
- if ((criteria.blotName == null && criteria(child)) ||
- (criteria.blotName != null && child instanceof criteria)) {
- descendants.push(child);
- }
- if (child instanceof ContainerBlot) {
- descendants = descendants.concat(child.descendants(criteria, index, lengthLeft));
- }
- lengthLeft -= length;
- });
- return descendants;
- };
- ContainerBlot.prototype.detach = function () {
- this.children.forEach(function (child) {
- child.detach();
- });
- _super.prototype.detach.call(this);
- };
- ContainerBlot.prototype.formatAt = function (index, length, name, value) {
- this.children.forEachAt(index, length, function (child, offset, length) {
- child.formatAt(offset, length, name, value);
- });
- };
- ContainerBlot.prototype.insertAt = function (index, value, def) {
- var _a = this.children.find(index), child = _a[0], offset = _a[1];
- if (child) {
- child.insertAt(offset, value, def);
- }
- else {
- var blot = def == null ? Registry.create('text', value) : Registry.create(value, def);
- this.appendChild(blot);
- }
- };
- ContainerBlot.prototype.insertBefore = function (childBlot, refBlot) {
- if (this.statics.allowedChildren != null &&
- !this.statics.allowedChildren.some(function (child) {
- return childBlot instanceof child;
- })) {
- throw new Registry.ParchmentError("Cannot insert " + childBlot.statics.blotName + " into " + this.statics.blotName);
- }
- childBlot.insertInto(this, refBlot);
- };
- ContainerBlot.prototype.length = function () {
- return this.children.reduce(function (memo, child) {
- return memo + child.length();
- }, 0);
- };
- ContainerBlot.prototype.moveChildren = function (targetParent, refNode) {
- this.children.forEach(function (child) {
- targetParent.insertBefore(child, refNode);
- });
- };
- ContainerBlot.prototype.optimize = function (context) {
- _super.prototype.optimize.call(this, context);
- if (this.children.length === 0) {
- if (this.statics.defaultChild != null) {
- var child = Registry.create(this.statics.defaultChild);
- this.appendChild(child);
- child.optimize(context);
- }
- else {
- this.remove();
- }
- }
- };
- ContainerBlot.prototype.path = function (index, inclusive) {
- if (inclusive === void 0) { inclusive = false; }
- var _a = this.children.find(index, inclusive), child = _a[0], offset = _a[1];
- var position = [[this, index]];
- if (child instanceof ContainerBlot) {
- return position.concat(child.path(offset, inclusive));
- }
- else if (child != null) {
- position.push([child, offset]);
- }
- return position;
- };
- ContainerBlot.prototype.removeChild = function (child) {
- this.children.remove(child);
- };
- ContainerBlot.prototype.replace = function (target) {
- if (target instanceof ContainerBlot) {
- target.moveChildren(this);
- }
- _super.prototype.replace.call(this, target);
- };
- ContainerBlot.prototype.split = function (index, force) {
- if (force === void 0) { force = false; }
- if (!force) {
- if (index === 0)
- return this;
- if (index === this.length())
- return this.next;
- }
- var after = this.clone();
- this.parent.insertBefore(after, this.next);
- this.children.forEachAt(index, this.length(), function (child, offset, length) {
- child = child.split(offset, force);
- after.appendChild(child);
- });
- return after;
- };
- ContainerBlot.prototype.unwrap = function () {
- this.moveChildren(this.parent, this.next);
- this.remove();
- };
- ContainerBlot.prototype.update = function (mutations, context) {
- var _this = this;
- var addedNodes = [];
- var removedNodes = [];
- mutations.forEach(function (mutation) {
- if (mutation.target === _this.domNode && mutation.type === 'childList') {
- addedNodes.push.apply(addedNodes, mutation.addedNodes);
- removedNodes.push.apply(removedNodes, mutation.removedNodes);
- }
- });
- removedNodes.forEach(function (node) {
- // Check node has actually been removed
- // One exception is Chrome does not immediately remove IFRAMEs
- // from DOM but MutationRecord is correct in its reported removal
- if (node.parentNode != null &&
- // @ts-ignore
- node.tagName !== 'IFRAME' &&
- document.body.compareDocumentPosition(node) & Node.DOCUMENT_POSITION_CONTAINED_BY) {
- return;
- }
- var blot = Registry.find(node);
- if (blot == null)
- return;
- if (blot.domNode.parentNode == null || blot.domNode.parentNode === _this.domNode) {
- blot.detach();
- }
- });
- addedNodes
- .filter(function (node) {
- return node.parentNode == _this.domNode;
- })
- .sort(function (a, b) {
- if (a === b)
- return 0;
- if (a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING) {
- return 1;
- }
- return -1;
- })
- .forEach(function (node) {
- var refBlot = null;
- if (node.nextSibling != null) {
- refBlot = Registry.find(node.nextSibling);
- }
- var blot = makeBlot(node);
- if (blot.next != refBlot || blot.next == null) {
- if (blot.parent != null) {
- blot.parent.removeChild(_this);
- }
- _this.insertBefore(blot, refBlot || undefined);
- }
- });
- };
- return ContainerBlot;
- }(shadow_1.default));
- function makeBlot(node) {
- var blot = Registry.find(node);
- if (blot == null) {
- try {
- blot = Registry.create(node);
- }
- catch (e) {
- blot = Registry.create(Registry.Scope.INLINE);
- [].slice.call(node.childNodes).forEach(function (child) {
- // @ts-ignore
- blot.domNode.appendChild(child);
- });
- if (node.parentNode) {
- node.parentNode.replaceChild(blot.domNode, node);
- }
- blot.attach();
- }
- }
- return blot;
- }
- exports.default = ContainerBlot;
- /***/ }),
- /* 3 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var attributor_1 = __webpack_require__(1);
- var store_1 = __webpack_require__(6);
- var container_1 = __webpack_require__(2);
- var Registry = __webpack_require__(0);
- var FormatBlot = /** @class */ (function (_super) {
- __extends(FormatBlot, _super);
- function FormatBlot(domNode) {
- var _this = _super.call(this, domNode) || this;
- _this.attributes = new store_1.default(_this.domNode);
- return _this;
- }
- FormatBlot.formats = function (domNode) {
- if (typeof this.tagName === 'string') {
- return true;
- }
- else if (Array.isArray(this.tagName)) {
- return domNode.tagName.toLowerCase();
- }
- return undefined;
- };
- FormatBlot.prototype.format = function (name, value) {
- var format = Registry.query(name);
- if (format instanceof attributor_1.default) {
- this.attributes.attribute(format, value);
- }
- else if (value) {
- if (format != null && (name !== this.statics.blotName || this.formats()[name] !== value)) {
- this.replaceWith(name, value);
- }
- }
- };
- FormatBlot.prototype.formats = function () {
- var formats = this.attributes.values();
- var format = this.statics.formats(this.domNode);
- if (format != null) {
- formats[this.statics.blotName] = format;
- }
- return formats;
- };
- FormatBlot.prototype.replaceWith = function (name, value) {
- var replacement = _super.prototype.replaceWith.call(this, name, value);
- this.attributes.copy(replacement);
- return replacement;
- };
- FormatBlot.prototype.update = function (mutations, context) {
- var _this = this;
- _super.prototype.update.call(this, mutations, context);
- if (mutations.some(function (mutation) {
- return mutation.target === _this.domNode && mutation.type === 'attributes';
- })) {
- this.attributes.build();
- }
- };
- FormatBlot.prototype.wrap = function (name, value) {
- var wrapper = _super.prototype.wrap.call(this, name, value);
- if (wrapper instanceof FormatBlot && wrapper.statics.scope === this.statics.scope) {
- this.attributes.move(wrapper);
- }
- return wrapper;
- };
- return FormatBlot;
- }(container_1.default));
- exports.default = FormatBlot;
- /***/ }),
- /* 4 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var shadow_1 = __webpack_require__(5);
- var Registry = __webpack_require__(0);
- var LeafBlot = /** @class */ (function (_super) {
- __extends(LeafBlot, _super);
- function LeafBlot() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- LeafBlot.value = function (domNode) {
- return true;
- };
- LeafBlot.prototype.index = function (node, offset) {
- if (this.domNode === node ||
- this.domNode.compareDocumentPosition(node) & Node.DOCUMENT_POSITION_CONTAINED_BY) {
- return Math.min(offset, 1);
- }
- return -1;
- };
- LeafBlot.prototype.position = function (index, inclusive) {
- var offset = [].indexOf.call(this.parent.domNode.childNodes, this.domNode);
- if (index > 0)
- offset += 1;
- return [this.parent.domNode, offset];
- };
- LeafBlot.prototype.value = function () {
- return _a = {}, _a[this.statics.blotName] = this.statics.value(this.domNode) || true, _a;
- var _a;
- };
- LeafBlot.scope = Registry.Scope.INLINE_BLOT;
- return LeafBlot;
- }(shadow_1.default));
- exports.default = LeafBlot;
- /***/ }),
- /* 5 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var Registry = __webpack_require__(0);
- var ShadowBlot = /** @class */ (function () {
- function ShadowBlot(domNode) {
- this.domNode = domNode;
- // @ts-ignore
- this.domNode[Registry.DATA_KEY] = { blot: this };
- }
- Object.defineProperty(ShadowBlot.prototype, "statics", {
- // Hack for accessing inherited static methods
- get: function () {
- return this.constructor;
- },
- enumerable: true,
- configurable: true
- });
- ShadowBlot.create = function (value) {
- if (this.tagName == null) {
- throw new Registry.ParchmentError('Blot definition missing tagName');
- }
- var node;
- if (Array.isArray(this.tagName)) {
- if (typeof value === 'string') {
- value = value.toUpperCase();
- if (parseInt(value).toString() === value) {
- value = parseInt(value);
- }
- }
- if (typeof value === 'number') {
- node = document.createElement(this.tagName[value - 1]);
- }
- else if (this.tagName.indexOf(value) > -1) {
- node = document.createElement(value);
- }
- else {
- node = document.createElement(this.tagName[0]);
- }
- }
- else {
- node = document.createElement(this.tagName);
- }
- if (this.className) {
- node.classList.add(this.className);
- }
- return node;
- };
- ShadowBlot.prototype.attach = function () {
- if (this.parent != null) {
- this.scroll = this.parent.scroll;
- }
- };
- ShadowBlot.prototype.clone = function () {
- var domNode = this.domNode.cloneNode(false);
- return Registry.create(domNode);
- };
- ShadowBlot.prototype.detach = function () {
- if (this.parent != null)
- this.parent.removeChild(this);
- // @ts-ignore
- delete this.domNode[Registry.DATA_KEY];
- };
- ShadowBlot.prototype.deleteAt = function (index, length) {
- var blot = this.isolate(index, length);
- blot.remove();
- };
- ShadowBlot.prototype.formatAt = function (index, length, name, value) {
- var blot = this.isolate(index, length);
- if (Registry.query(name, Registry.Scope.BLOT) != null && value) {
- blot.wrap(name, value);
- }
- else if (Registry.query(name, Registry.Scope.ATTRIBUTE) != null) {
- var parent_1 = Registry.create(this.statics.scope);
- blot.wrap(parent_1);
- parent_1.format(name, value);
- }
- };
- ShadowBlot.prototype.insertAt = function (index, value, def) {
- var blot = def == null ? Registry.create('text', value) : Registry.create(value, def);
- var ref = this.split(index);
- this.parent.insertBefore(blot, ref);
- };
- ShadowBlot.prototype.insertInto = function (parentBlot, refBlot) {
- if (refBlot === void 0) { refBlot = null; }
- if (this.parent != null) {
- this.parent.children.remove(this);
- }
- var refDomNode = null;
- parentBlot.children.insertBefore(this, refBlot);
- if (refBlot != null) {
- refDomNode = refBlot.domNode;
- }
- if (this.domNode.parentNode != parentBlot.domNode ||
- this.domNode.nextSibling != refDomNode) {
- parentBlot.domNode.insertBefore(this.domNode, refDomNode);
- }
- this.parent = parentBlot;
- this.attach();
- };
- ShadowBlot.prototype.isolate = function (index, length) {
- var target = this.split(index);
- target.split(length);
- return target;
- };
- ShadowBlot.prototype.length = function () {
- return 1;
- };
- ShadowBlot.prototype.offset = function (root) {
- if (root === void 0) { root = this.parent; }
- if (this.parent == null || this == root)
- return 0;
- return this.parent.children.offset(this) + this.parent.offset(root);
- };
- ShadowBlot.prototype.optimize = function (context) {
- // TODO clean up once we use WeakMap
- // @ts-ignore
- if (this.domNode[Registry.DATA_KEY] != null) {
- // @ts-ignore
- delete this.domNode[Registry.DATA_KEY].mutations;
- }
- };
- ShadowBlot.prototype.remove = function () {
- if (this.domNode.parentNode != null) {
- this.domNode.parentNode.removeChild(this.domNode);
- }
- this.detach();
- };
- ShadowBlot.prototype.replace = function (target) {
- if (target.parent == null)
- return;
- target.parent.insertBefore(this, target.next);
- target.remove();
- };
- ShadowBlot.prototype.replaceWith = function (name, value) {
- var replacement = typeof name === 'string' ? Registry.create(name, value) : name;
- replacement.replace(this);
- return replacement;
- };
- ShadowBlot.prototype.split = function (index, force) {
- return index === 0 ? this : this.next;
- };
- ShadowBlot.prototype.update = function (mutations, context) {
- // Nothing to do by default
- };
- ShadowBlot.prototype.wrap = function (name, value) {
- var wrapper = typeof name === 'string' ? Registry.create(name, value) : name;
- if (this.parent != null) {
- this.parent.insertBefore(wrapper, this.next);
- }
- wrapper.appendChild(this);
- return wrapper;
- };
- ShadowBlot.blotName = 'abstract';
- return ShadowBlot;
- }());
- exports.default = ShadowBlot;
- /***/ }),
- /* 6 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var attributor_1 = __webpack_require__(1);
- var class_1 = __webpack_require__(7);
- var style_1 = __webpack_require__(8);
- var Registry = __webpack_require__(0);
- var AttributorStore = /** @class */ (function () {
- function AttributorStore(domNode) {
- this.attributes = {};
- this.domNode = domNode;
- this.build();
- }
- AttributorStore.prototype.attribute = function (attribute, value) {
- // verb
- if (value) {
- if (attribute.add(this.domNode, value)) {
- if (attribute.value(this.domNode) != null) {
- this.attributes[attribute.attrName] = attribute;
- }
- else {
- delete this.attributes[attribute.attrName];
- }
- }
- }
- else {
- attribute.remove(this.domNode);
- delete this.attributes[attribute.attrName];
- }
- };
- AttributorStore.prototype.build = function () {
- var _this = this;
- this.attributes = {};
- var attributes = attributor_1.default.keys(this.domNode);
- var classes = class_1.default.keys(this.domNode);
- var styles = style_1.default.keys(this.domNode);
- attributes
- .concat(classes)
- .concat(styles)
- .forEach(function (name) {
- var attr = Registry.query(name, Registry.Scope.ATTRIBUTE);
- if (attr instanceof attributor_1.default) {
- _this.attributes[attr.attrName] = attr;
- }
- });
- };
- AttributorStore.prototype.copy = function (target) {
- var _this = this;
- Object.keys(this.attributes).forEach(function (key) {
- var value = _this.attributes[key].value(_this.domNode);
- target.format(key, value);
- });
- };
- AttributorStore.prototype.move = function (target) {
- var _this = this;
- this.copy(target);
- Object.keys(this.attributes).forEach(function (key) {
- _this.attributes[key].remove(_this.domNode);
- });
- this.attributes = {};
- };
- AttributorStore.prototype.values = function () {
- var _this = this;
- return Object.keys(this.attributes).reduce(function (attributes, name) {
- attributes[name] = _this.attributes[name].value(_this.domNode);
- return attributes;
- }, {});
- };
- return AttributorStore;
- }());
- exports.default = AttributorStore;
- /***/ }),
- /* 7 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var attributor_1 = __webpack_require__(1);
- function match(node, prefix) {
- var className = node.getAttribute('class') || '';
- return className.split(/\s+/).filter(function (name) {
- return name.indexOf(prefix + "-") === 0;
- });
- }
- var ClassAttributor = /** @class */ (function (_super) {
- __extends(ClassAttributor, _super);
- function ClassAttributor() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- ClassAttributor.keys = function (node) {
- return (node.getAttribute('class') || '').split(/\s+/).map(function (name) {
- return name
- .split('-')
- .slice(0, -1)
- .join('-');
- });
- };
- ClassAttributor.prototype.add = function (node, value) {
- if (!this.canAdd(node, value))
- return false;
- this.remove(node);
- node.classList.add(this.keyName + "-" + value);
- return true;
- };
- ClassAttributor.prototype.remove = function (node) {
- var matches = match(node, this.keyName);
- matches.forEach(function (name) {
- node.classList.remove(name);
- });
- if (node.classList.length === 0) {
- node.removeAttribute('class');
- }
- };
- ClassAttributor.prototype.value = function (node) {
- var result = match(node, this.keyName)[0] || '';
- var value = result.slice(this.keyName.length + 1); // +1 for hyphen
- return this.canAdd(node, value) ? value : '';
- };
- return ClassAttributor;
- }(attributor_1.default));
- exports.default = ClassAttributor;
- /***/ }),
- /* 8 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var attributor_1 = __webpack_require__(1);
- function camelize(name) {
- var parts = name.split('-');
- var rest = parts
- .slice(1)
- .map(function (part) {
- return part[0].toUpperCase() + part.slice(1);
- })
- .join('');
- return parts[0] + rest;
- }
- var StyleAttributor = /** @class */ (function (_super) {
- __extends(StyleAttributor, _super);
- function StyleAttributor() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- StyleAttributor.keys = function (node) {
- return (node.getAttribute('style') || '').split(';').map(function (value) {
- var arr = value.split(':');
- return arr[0].trim();
- });
- };
- StyleAttributor.prototype.add = function (node, value) {
- if (!this.canAdd(node, value))
- return false;
- // @ts-ignore
- node.style[camelize(this.keyName)] = value;
- return true;
- };
- StyleAttributor.prototype.remove = function (node) {
- // @ts-ignore
- node.style[camelize(this.keyName)] = '';
- if (!node.getAttribute('style')) {
- node.removeAttribute('style');
- }
- };
- StyleAttributor.prototype.value = function (node) {
- // @ts-ignore
- var value = node.style[camelize(this.keyName)];
- return this.canAdd(node, value) ? value : '';
- };
- return StyleAttributor;
- }(attributor_1.default));
- exports.default = StyleAttributor;
- /***/ }),
- /* 9 */
- /***/ (function(module, exports, __webpack_require__) {
- module.exports = __webpack_require__(10);
- /***/ }),
- /* 10 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var container_1 = __webpack_require__(2);
- var format_1 = __webpack_require__(3);
- var leaf_1 = __webpack_require__(4);
- var scroll_1 = __webpack_require__(12);
- var inline_1 = __webpack_require__(13);
- var block_1 = __webpack_require__(14);
- var embed_1 = __webpack_require__(15);
- var text_1 = __webpack_require__(16);
- var attributor_1 = __webpack_require__(1);
- var class_1 = __webpack_require__(7);
- var style_1 = __webpack_require__(8);
- var store_1 = __webpack_require__(6);
- var Registry = __webpack_require__(0);
- var Parchment = {
- Scope: Registry.Scope,
- create: Registry.create,
- find: Registry.find,
- query: Registry.query,
- register: Registry.register,
- Container: container_1.default,
- Format: format_1.default,
- Leaf: leaf_1.default,
- Embed: embed_1.default,
- Scroll: scroll_1.default,
- Block: block_1.default,
- Inline: inline_1.default,
- Text: text_1.default,
- Attributor: {
- Attribute: attributor_1.default,
- Class: class_1.default,
- Style: style_1.default,
- Store: store_1.default,
- },
- };
- exports.default = Parchment;
- /***/ }),
- /* 11 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var LinkedList = /** @class */ (function () {
- function LinkedList() {
- this.head = this.tail = null;
- this.length = 0;
- }
- LinkedList.prototype.append = function () {
- var nodes = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- nodes[_i] = arguments[_i];
- }
- this.insertBefore(nodes[0], null);
- if (nodes.length > 1) {
- this.append.apply(this, nodes.slice(1));
- }
- };
- LinkedList.prototype.contains = function (node) {
- var cur, next = this.iterator();
- while ((cur = next())) {
- if (cur === node)
- return true;
- }
- return false;
- };
- LinkedList.prototype.insertBefore = function (node, refNode) {
- if (!node)
- return;
- node.next = refNode;
- if (refNode != null) {
- node.prev = refNode.prev;
- if (refNode.prev != null) {
- refNode.prev.next = node;
- }
- refNode.prev = node;
- if (refNode === this.head) {
- this.head = node;
- }
- }
- else if (this.tail != null) {
- this.tail.next = node;
- node.prev = this.tail;
- this.tail = node;
- }
- else {
- node.prev = null;
- this.head = this.tail = node;
- }
- this.length += 1;
- };
- LinkedList.prototype.offset = function (target) {
- var index = 0, cur = this.head;
- while (cur != null) {
- if (cur === target)
- return index;
- index += cur.length();
- cur = cur.next;
- }
- return -1;
- };
- LinkedList.prototype.remove = function (node) {
- if (!this.contains(node))
- return;
- if (node.prev != null)
- node.prev.next = node.next;
- if (node.next != null)
- node.next.prev = node.prev;
- if (node === this.head)
- this.head = node.next;
- if (node === this.tail)
- this.tail = node.prev;
- this.length -= 1;
- };
- LinkedList.prototype.iterator = function (curNode) {
- if (curNode === void 0) { curNode = this.head; }
- // TODO use yield when we can
- return function () {
- var ret = curNode;
- if (curNode != null)
- curNode = curNode.next;
- return ret;
- };
- };
- LinkedList.prototype.find = function (index, inclusive) {
- if (inclusive === void 0) { inclusive = false; }
- var cur, next = this.iterator();
- while ((cur = next())) {
- var length_1 = cur.length();
- if (index < length_1 ||
- (inclusive && index === length_1 && (cur.next == null || cur.next.length() !== 0))) {
- return [cur, index];
- }
- index -= length_1;
- }
- return [null, 0];
- };
- LinkedList.prototype.forEach = function (callback) {
- var cur, next = this.iterator();
- while ((cur = next())) {
- callback(cur);
- }
- };
- LinkedList.prototype.forEachAt = function (index, length, callback) {
- if (length <= 0)
- return;
- var _a = this.find(index), startNode = _a[0], offset = _a[1];
- var cur, curIndex = index - offset, next = this.iterator(startNode);
- while ((cur = next()) && curIndex < index + length) {
- var curLength = cur.length();
- if (index > curIndex) {
- callback(cur, index - curIndex, Math.min(length, curIndex + curLength - index));
- }
- else {
- callback(cur, 0, Math.min(curLength, index + length - curIndex));
- }
- curIndex += curLength;
- }
- };
- LinkedList.prototype.map = function (callback) {
- return this.reduce(function (memo, cur) {
- memo.push(callback(cur));
- return memo;
- }, []);
- };
- LinkedList.prototype.reduce = function (callback, memo) {
- var cur, next = this.iterator();
- while ((cur = next())) {
- memo = callback(memo, cur);
- }
- return memo;
- };
- return LinkedList;
- }());
- exports.default = LinkedList;
- /***/ }),
- /* 12 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var container_1 = __webpack_require__(2);
- var Registry = __webpack_require__(0);
- var OBSERVER_CONFIG = {
- attributes: true,
- characterData: true,
- characterDataOldValue: true,
- childList: true,
- subtree: true,
- };
- var MAX_OPTIMIZE_ITERATIONS = 100;
- var ScrollBlot = /** @class */ (function (_super) {
- __extends(ScrollBlot, _super);
- function ScrollBlot(node) {
- var _this = _super.call(this, node) || this;
- _this.scroll = _this;
- _this.observer = new MutationObserver(function (mutations) {
- _this.update(mutations);
- });
- _this.observer.observe(_this.domNode, OBSERVER_CONFIG);
- _this.attach();
- return _this;
- }
- ScrollBlot.prototype.detach = function () {
- _super.prototype.detach.call(this);
- this.observer.disconnect();
- };
- ScrollBlot.prototype.deleteAt = function (index, length) {
- this.update();
- if (index === 0 && length === this.length()) {
- this.children.forEach(function (child) {
- child.remove();
- });
- }
- else {
- _super.prototype.deleteAt.call(this, index, length);
- }
- };
- ScrollBlot.prototype.formatAt = function (index, length, name, value) {
- this.update();
- _super.prototype.formatAt.call(this, index, length, name, value);
- };
- ScrollBlot.prototype.insertAt = function (index, value, def) {
- this.update();
- _super.prototype.insertAt.call(this, index, value, def);
- };
- ScrollBlot.prototype.optimize = function (mutations, context) {
- var _this = this;
- if (mutations === void 0) { mutations = []; }
- if (context === void 0) { context = {}; }
- _super.prototype.optimize.call(this, context);
- // We must modify mutations directly, cannot make copy and then modify
- var records = [].slice.call(this.observer.takeRecords());
- // Array.push currently seems to be implemented by a non-tail recursive function
- // so we cannot just mutations.push.apply(mutations, this.observer.takeRecords());
- while (records.length > 0)
- mutations.push(records.pop());
- // TODO use WeakMap
- var mark = function (blot, markParent) {
- if (markParent === void 0) { markParent = true; }
- if (blot == null || blot === _this)
- return;
- if (blot.domNode.parentNode == null)
- return;
- // @ts-ignore
- if (blot.domNode[Registry.DATA_KEY].mutations == null) {
- // @ts-ignore
- blot.domNode[Registry.DATA_KEY].mutations = [];
- }
- if (markParent)
- mark(blot.parent);
- };
- var optimize = function (blot) {
- // Post-order traversal
- if (
- // @ts-ignore
- blot.domNode[Registry.DATA_KEY] == null ||
- // @ts-ignore
- blot.domNode[Registry.DATA_KEY].mutations == null) {
- return;
- }
- if (blot instanceof container_1.default) {
- blot.children.forEach(optimize);
- }
- blot.optimize(context);
- };
- var remaining = mutations;
- for (var i = 0; remaining.length > 0; i += 1) {
- if (i >= MAX_OPTIMIZE_ITERATIONS) {
- throw new Error('[Parchment] Maximum optimize iterations reached');
- }
- remaining.forEach(function (mutation) {
- var blot = Registry.find(mutation.target, true);
- if (blot == null)
- return;
- if (blot.domNode === mutation.target) {
- if (mutation.type === 'childList') {
- mark(Registry.find(mutation.previousSibling, false));
- [].forEach.call(mutation.addedNodes, function (node) {
- var child = Registry.find(node, false);
- mark(child, false);
- if (child instanceof container_1.default) {
- child.children.forEach(function (grandChild) {
- mark(grandChild, false);
- });
- }
- });
- }
- else if (mutation.type === 'attributes') {
- mark(blot.prev);
- }
- }
- mark(blot);
- });
- this.children.forEach(optimize);
- remaining = [].slice.call(this.observer.takeRecords());
- records = remaining.slice();
- while (records.length > 0)
- mutations.push(records.pop());
- }
- };
- ScrollBlot.prototype.update = function (mutations, context) {
- var _this = this;
- if (context === void 0) { context = {}; }
- mutations = mutations || this.observer.takeRecords();
- // TODO use WeakMap
- mutations
- .map(function (mutation) {
- var blot = Registry.find(mutation.target, true);
- if (blot == null)
- return null;
- // @ts-ignore
- if (blot.domNode[Registry.DATA_KEY].mutations == null) {
- // @ts-ignore
- blot.domNode[Registry.DATA_KEY].mutations = [mutation];
- return blot;
- }
- else {
- // @ts-ignore
- blot.domNode[Registry.DATA_KEY].mutations.push(mutation);
- return null;
- }
- })
- .forEach(function (blot) {
- if (blot == null ||
- blot === _this ||
- //@ts-ignore
- blot.domNode[Registry.DATA_KEY] == null)
- return;
- // @ts-ignore
- blot.update(blot.domNode[Registry.DATA_KEY].mutations || [], context);
- });
- // @ts-ignore
- if (this.domNode[Registry.DATA_KEY].mutations != null) {
- // @ts-ignore
- _super.prototype.update.call(this, this.domNode[Registry.DATA_KEY].mutations, context);
- }
- this.optimize(mutations, context);
- };
- ScrollBlot.blotName = 'scroll';
- ScrollBlot.defaultChild = 'block';
- ScrollBlot.scope = Registry.Scope.BLOCK_BLOT;
- ScrollBlot.tagName = 'DIV';
- return ScrollBlot;
- }(container_1.default));
- exports.default = ScrollBlot;
- /***/ }),
- /* 13 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var format_1 = __webpack_require__(3);
- var Registry = __webpack_require__(0);
- // Shallow object comparison
- function isEqual(obj1, obj2) {
- if (Object.keys(obj1).length !== Object.keys(obj2).length)
- return false;
- // @ts-ignore
- for (var prop in obj1) {
- // @ts-ignore
- if (obj1[prop] !== obj2[prop])
- return false;
- }
- return true;
- }
- var InlineBlot = /** @class */ (function (_super) {
- __extends(InlineBlot, _super);
- function InlineBlot() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- InlineBlot.formats = function (domNode) {
- if (domNode.tagName === InlineBlot.tagName)
- return undefined;
- return _super.formats.call(this, domNode);
- };
- InlineBlot.prototype.format = function (name, value) {
- var _this = this;
- if (name === this.statics.blotName && !value) {
- this.children.forEach(function (child) {
- if (!(child instanceof format_1.default)) {
- child = child.wrap(InlineBlot.blotName, true);
- }
- _this.attributes.copy(child);
- });
- this.unwrap();
- }
- else {
- _super.prototype.format.call(this, name, value);
- }
- };
- InlineBlot.prototype.formatAt = function (index, length, name, value) {
- if (this.formats()[name] != null || Registry.query(name, Registry.Scope.ATTRIBUTE)) {
- var blot = this.isolate(index, length);
- blot.format(name, value);
- }
- else {
- _super.prototype.formatAt.call(this, index, length, name, value);
- }
- };
- InlineBlot.prototype.optimize = function (context) {
- _super.prototype.optimize.call(this, context);
- var formats = this.formats();
- if (Object.keys(formats).length === 0) {
- return this.unwrap(); // unformatted span
- }
- var next = this.next;
- if (next instanceof InlineBlot && next.prev === this && isEqual(formats, next.formats())) {
- next.moveChildren(this);
- next.remove();
- }
- };
- InlineBlot.blotName = 'inline';
- InlineBlot.scope = Registry.Scope.INLINE_BLOT;
- InlineBlot.tagName = 'SPAN';
- return InlineBlot;
- }(format_1.default));
- exports.default = InlineBlot;
- /***/ }),
- /* 14 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var format_1 = __webpack_require__(3);
- var Registry = __webpack_require__(0);
- var BlockBlot = /** @class */ (function (_super) {
- __extends(BlockBlot, _super);
- function BlockBlot() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- BlockBlot.formats = function (domNode) {
- var tagName = Registry.query(BlockBlot.blotName).tagName;
- if (domNode.tagName === tagName)
- return undefined;
- return _super.formats.call(this, domNode);
- };
- BlockBlot.prototype.format = function (name, value) {
- if (Registry.query(name, Registry.Scope.BLOCK) == null) {
- return;
- }
- else if (name === this.statics.blotName && !value) {
- this.replaceWith(BlockBlot.blotName);
- }
- else {
- _super.prototype.format.call(this, name, value);
- }
- };
- BlockBlot.prototype.formatAt = function (index, length, name, value) {
- if (Registry.query(name, Registry.Scope.BLOCK) != null) {
- this.format(name, value);
- }
- else {
- _super.prototype.formatAt.call(this, index, length, name, value);
- }
- };
- BlockBlot.prototype.insertAt = function (index, value, def) {
- if (def == null || Registry.query(value, Registry.Scope.INLINE) != null) {
- // Insert text or inline
- _super.prototype.insertAt.call(this, index, value, def);
- }
- else {
- var after = this.split(index);
- var blot = Registry.create(value, def);
- after.parent.insertBefore(blot, after);
- }
- };
- BlockBlot.prototype.update = function (mutations, context) {
- if (navigator.userAgent.match(/Trident/)) {
- this.build();
- }
- else {
- _super.prototype.update.call(this, mutations, context);
- }
- };
- BlockBlot.blotName = 'block';
- BlockBlot.scope = Registry.Scope.BLOCK_BLOT;
- BlockBlot.tagName = 'P';
- return BlockBlot;
- }(format_1.default));
- exports.default = BlockBlot;
- /***/ }),
- /* 15 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var leaf_1 = __webpack_require__(4);
- var EmbedBlot = /** @class */ (function (_super) {
- __extends(EmbedBlot, _super);
- function EmbedBlot() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- EmbedBlot.formats = function (domNode) {
- return undefined;
- };
- EmbedBlot.prototype.format = function (name, value) {
- // super.formatAt wraps, which is what we want in general,
- // but this allows subclasses to overwrite for formats
- // that just apply to particular embeds
- _super.prototype.formatAt.call(this, 0, this.length(), name, value);
- };
- EmbedBlot.prototype.formatAt = function (index, length, name, value) {
- if (index === 0 && length === this.length()) {
- this.format(name, value);
- }
- else {
- _super.prototype.formatAt.call(this, index, length, name, value);
- }
- };
- EmbedBlot.prototype.formats = function () {
- return this.statics.formats(this.domNode);
- };
- return EmbedBlot;
- }(leaf_1.default));
- exports.default = EmbedBlot;
- /***/ }),
- /* 16 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- var leaf_1 = __webpack_require__(4);
- var Registry = __webpack_require__(0);
- var TextBlot = /** @class */ (function (_super) {
- __extends(TextBlot, _super);
- function TextBlot(node) {
- var _this = _super.call(this, node) || this;
- _this.text = _this.statics.value(_this.domNode);
- return _this;
- }
- TextBlot.create = function (value) {
- return document.createTextNode(value);
- };
- TextBlot.value = function (domNode) {
- var text = domNode.data;
- // @ts-ignore
- if (text['normalize'])
- text = text['normalize']();
- return text;
- };
- TextBlot.prototype.deleteAt = function (index, length) {
- this.domNode.data = this.text = this.text.slice(0, index) + this.text.slice(index + length);
- };
- TextBlot.prototype.index = function (node, offset) {
- if (this.domNode === node) {
- return offset;
- }
- return -1;
- };
- TextBlot.prototype.insertAt = function (index, value, def) {
- if (def == null) {
- this.text = this.text.slice(0, index) + value + this.text.slice(index);
- this.domNode.data = this.text;
- }
- else {
- _super.prototype.insertAt.call(this, index, value, def);
- }
- };
- TextBlot.prototype.length = function () {
- return this.text.length;
- };
- TextBlot.prototype.optimize = function (context) {
- _super.prototype.optimize.call(this, context);
- this.text = this.statics.value(this.domNode);
- if (this.text.length === 0) {
- this.remove();
- }
- else if (this.next instanceof TextBlot && this.next.prev === this) {
- this.insertAt(this.length(), this.next.value());
- this.next.remove();
- }
- };
- TextBlot.prototype.position = function (index, inclusive) {
- if (inclusive === void 0) { inclusive = false; }
- return [this.domNode, index];
- };
- TextBlot.prototype.split = function (index, force) {
- if (force === void 0) { force = false; }
- if (!force) {
- if (index === 0)
- return this;
- if (index === this.length())
- return this.next;
- }
- var after = Registry.create(this.domNode.splitText(index));
- this.parent.insertBefore(after, this.next);
- this.text = this.statics.value(this.domNode);
- return after;
- };
- TextBlot.prototype.update = function (mutations, context) {
- var _this = this;
- if (mutations.some(function (mutation) {
- return mutation.type === 'characterData' && mutation.target === _this.domNode;
- })) {
- this.text = this.statics.value(this.domNode);
- }
- };
- TextBlot.prototype.value = function () {
- return this.text;
- };
- TextBlot.blotName = 'text';
- TextBlot.scope = Registry.Scope.INLINE_BLOT;
- return TextBlot;
- }(leaf_1.default));
- exports.default = TextBlot;
- /***/ })
- /******/ ]);
- });
- //# sourceMappingURL=parchment.js.map
|