diff --git a/motorradig/.idea/workspace.xml b/motorradig/.idea/workspace.xml index c7f1313..633c0cb 100644 --- a/motorradig/.idea/workspace.xml +++ b/motorradig/.idea/workspace.xml @@ -2,8 +2,14 @@ + + + + + + + + + @@ -125,7 +138,7 @@ - + @@ -140,9 +153,9 @@ + - @@ -207,7 +220,7 @@ - + @@ -231,13 +244,17 @@ \ No newline at end of file diff --git a/motorradig/package-lock.json b/motorradig/package-lock.json index b0abe29..b7f5c12 100644 --- a/motorradig/package-lock.json +++ b/motorradig/package-lock.json @@ -3511,6 +3511,14 @@ "integrity": "sha512-483XLLxTVIwWK3QTrMGRqUfUpoOs/0hbQrl2oz4J0pAcm3A3bu84wxTFqGqkJzewCLdME38xJLJAxBABfQT8sQ==", "dev": true }, + "fault": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/fault/-/fault-1.0.3.tgz", + "integrity": "sha512-sfFuP4X0hzrbGKjAUNXYvNqsZ5F6ohx/dZ9I0KQud/aiZNwg263r5L9yGB0clvXHCkzXh5W3t7RSHchggYIFmA==", + "requires": { + "format": "^0.2.2" + } + }, "faye-websocket": { "version": "0.10.0", "resolved": "https://registry.npmjs.org/faye-websocket/-/faye-websocket-0.10.0.tgz", @@ -3667,6 +3675,11 @@ "integrity": "sha1-gQaNKVqBQuwKxybG4iAMMPttXoA=", "dev": true }, + "format": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/format/-/format-0.2.2.tgz", + "integrity": "sha1-1hcBB+nv3E7TDJ3DkBbflCtctYs=" + }, "forwarded": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", @@ -4578,6 +4591,11 @@ "integrity": "sha512-l9sfDFsuqtOqKDsQdqrMRk0U85RZc0RtOR9yPI7mRVOa4FsR/BVnZ0shmQRM96Ji99kYZP/7hn1cedc1+ApsTQ==", "dev": true }, + "highlight.js": { + "version": "9.16.2", + "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-9.16.2.tgz", + "integrity": "sha512-feMUrVLZvjy0oC7FVJQcSQRqbBq9kwqnYE4+Kj9ZjbHh3g+BisiPgF49NyQbVLNdrL/qqZr3Ca9yOKwgn2i/tw==" + }, "hmac-drbg": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", @@ -5566,6 +5584,15 @@ "integrity": "sha1-miyr0bno4K6ZOkv31YdcOcQujqw=", "dev": true }, + "lowlight": { + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/lowlight/-/lowlight-1.13.0.tgz", + "integrity": "sha512-bFXLa+UO1eM3zieFAcNqf6rTQ1D5ERFv64/euQbbH/LT3U9XXwH6tOrgUAGWDsQ1QgN3ZhgOcv8p3/S+qKGdTQ==", + "requires": { + "fault": "^1.0.2", + "highlight.js": "~9.16.0" + } + }, "lru-cache": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", @@ -6233,9 +6260,9 @@ } }, "orderedmap": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/orderedmap/-/orderedmap-1.1.0.tgz", - "integrity": "sha512-abUlPCcmyI/17BWWoUWeAbnniTFUZuczP6iowD9XMBcUoD9jRtUO6w+KXkw64TDk+iHdyDfTAjIH7mTRzhXcaw==" + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/orderedmap/-/orderedmap-1.1.1.tgz", + "integrity": "sha512-3Ux8um0zXbVacKUkcytc0u3HgC0b0bBLT+I60r2J/En72cI0nZffqrA7Xtf2Hqs27j1g82llR5Mhbd0Z1XW4AQ==" }, "original": { "version": "1.0.2", @@ -7247,6 +7274,14 @@ "integrity": "sha1-mEcocL8igTL8vdhoEputEsPAKeM=", "dev": true }, + "prosemirror-collab": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/prosemirror-collab/-/prosemirror-collab-1.2.2.tgz", + "integrity": "sha512-tBnHKMLgy5Qmx9MYVcLfs3pAyjtcqYYDd9kp3y+LSiQzkhMQDfZSV3NXWe4Gsly32adSef173BvObwfoSQL5MA==", + "requires": { + "prosemirror-state": "^1.0.0" + } + }, "prosemirror-commands": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/prosemirror-commands/-/prosemirror-commands-1.1.2.tgz", @@ -7278,6 +7313,16 @@ "prosemirror-view": "^1.0.0" } }, + "prosemirror-history": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/prosemirror-history/-/prosemirror-history-1.1.2.tgz", + "integrity": "sha512-erhxYS5gm/6MiXP8jUoJBgc8IbaqjHDVPl9KGg5JrMZOSSOwHv85+4Fb0Q7sYtv2fYwAjOSw/kSA9vkxJ6wOwA==", + "requires": { + "prosemirror-state": "^1.2.2", + "prosemirror-transform": "^1.0.0", + "rope-sequence": "^1.3.0" + } + }, "prosemirror-inputrules": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/prosemirror-inputrules/-/prosemirror-inputrules-1.1.2.tgz", @@ -7830,6 +7875,11 @@ "inherits": "^2.0.1" } }, + "rope-sequence": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/rope-sequence/-/rope-sequence-1.3.2.tgz", + "integrity": "sha512-ku6MFrwEVSVmXLvy3dYph3LAMNS0890K7fabn+0YIRQ2T96T9F4gkFf0vf0WW0JUraNWwGRtInEpH7yO4tbQZg==" + }, "run-queue": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/run-queue/-/run-queue-1.0.3.tgz", @@ -8859,6 +8909,34 @@ "tiptap-utils": "^1.8.3" } }, + "tiptap-extensions": { + "version": "1.28.6", + "resolved": "https://registry.npmjs.org/tiptap-extensions/-/tiptap-extensions-1.28.6.tgz", + "integrity": "sha512-hkYKJHxkqmeIRyuOaVvsrC/IcoXZmBw/Gx4JJHPiCAKvLQyjgYZpNjbVH9nIgdlxLvVjFDVBoPWGHy00qGp8qQ==", + "requires": { + "lowlight": "1.13.0", + "prosemirror-collab": "1.2.2", + "prosemirror-history": "1.1.2", + "prosemirror-model": "1.8.2", + "prosemirror-state": "1.3.2", + "prosemirror-tables": "1.0.0", + "prosemirror-transform": "1.2.2", + "prosemirror-utils": "0.9.6", + "prosemirror-view": "1.13.4", + "tiptap": "^1.26.6", + "tiptap-commands": "^1.12.5" + }, + "dependencies": { + "prosemirror-transform": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/prosemirror-transform/-/prosemirror-transform-1.2.2.tgz", + "integrity": "sha512-expO11jAsxaHk2RdZtzPsumc1bAAZi4UiXwTLQbftsdnIUWZE5Snyag595p1lx/B8QHUZ6tYWWOaOkzXKoJmYw==", + "requires": { + "prosemirror-model": "^1.0.0" + } + } + } + }, "tiptap-utils": { "version": "1.8.3", "resolved": "https://registry.npmjs.org/tiptap-utils/-/tiptap-utils-1.8.3.tgz", diff --git a/motorradig/package.json b/motorradig/package.json index 4d00b44..753e521 100644 --- a/motorradig/package.json +++ b/motorradig/package.json @@ -24,6 +24,7 @@ }, "dependencies": { "tiptap": "^1.26.6", + "tiptap-extensions": "^1.28.6", "vue-router": "^3.1.5", "vuex": "^3.1.2" } diff --git a/motorradig/public/js/Icon.js b/motorradig/public/js/Icon.js new file mode 100644 index 0000000..8557e02 --- /dev/null +++ b/motorradig/public/js/Icon.js @@ -0,0 +1,112 @@ +/******/ (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, { enumerable: true, get: getter }); +/******/ } +/******/ }; +/******/ +/******/ // define __esModule on exports +/******/ __webpack_require__.r = function(exports) { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ +/******/ // create a fake namespace object +/******/ // mode & 1: value is a module id, require it +/******/ // mode & 2: merge all properties of value into the ns +/******/ // mode & 4: return value when already ns object +/******/ // mode & 8|1: behave like require +/******/ __webpack_require__.t = function(value, mode) { +/******/ if(mode & 1) value = __webpack_require__(value); +/******/ if(mode & 8) return value; +/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; +/******/ var ns = Object.create(null); +/******/ __webpack_require__.r(ns); +/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); +/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); +/******/ return ns; +/******/ }; +/******/ +/******/ // 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 = 1); +/******/ }) +/************************************************************************/ +/******/ ({ + +/***/ "./resources/js/views/components/Icon.js": +/*!***********************************************!*\ + !*** ./resources/js/views/components/Icon.js ***! + \***********************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +throw new Error("Module build failed (from ./node_modules/babel-loader/lib/index.js):\nError: ENOENT: no such file or directory, open '/Users/tschneider/dev/repo/motorradig/motorradig/resources/js/views/components/Icon.js'"); + +/***/ }), + +/***/ 1: +/*!*****************************************************!*\ + !*** multi ./resources/js/views/components/Icon.js ***! + \*****************************************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +module.exports = __webpack_require__(/*! /Users/tschneider/dev/repo/motorradig/motorradig/resources/js/views/components/Icon.js */"./resources/js/views/components/Icon.js"); + + +/***/ }) + +/******/ }); \ No newline at end of file diff --git a/motorradig/public/js/app.js b/motorradig/public/js/app.js index cc1b671..5d1f655 100644 --- a/motorradig/public/js/app.js +++ b/motorradig/public/js/app.js @@ -1827,6 +1827,92 @@ module.exports = { }; +/***/ }), + +/***/ "./node_modules/babel-loader/lib/index.js?!./node_modules/vue-loader/lib/index.js?!./resources/js/views/EditPage.vue?vue&type=script&lang=js&": +/*!**************************************************************************************************************************************************************!*\ + !*** ./node_modules/babel-loader/lib??ref--4-0!./node_modules/vue-loader/lib??vue-loader-options!./resources/js/views/EditPage.vue?vue&type=script&lang=js& ***! + \**************************************************************************************************************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var tiptap__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tiptap */ "./node_modules/tiptap/dist/tiptap.esm.js"); +/* harmony import */ var tiptap_extensions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! tiptap-extensions */ "./node_modules/tiptap-extensions/dist/extensions.esm.js"); +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// + + +/* harmony default export */ __webpack_exports__["default"] = ({ + components: { + EditorContent: tiptap__WEBPACK_IMPORTED_MODULE_0__["EditorContent"], + EditorMenuBar: tiptap__WEBPACK_IMPORTED_MODULE_0__["EditorMenuBar"] + }, + data: function data() { + return { + editor: new tiptap__WEBPACK_IMPORTED_MODULE_0__["Editor"]({ + extensions: [new tiptap_extensions__WEBPACK_IMPORTED_MODULE_1__["Blockquote"](), new tiptap_extensions__WEBPACK_IMPORTED_MODULE_1__["BulletList"](), new tiptap_extensions__WEBPACK_IMPORTED_MODULE_1__["CodeBlock"](), new tiptap_extensions__WEBPACK_IMPORTED_MODULE_1__["HardBreak"](), new tiptap_extensions__WEBPACK_IMPORTED_MODULE_1__["Heading"]({ + levels: [1, 2, 3] + }), new tiptap_extensions__WEBPACK_IMPORTED_MODULE_1__["HorizontalRule"](), new tiptap_extensions__WEBPACK_IMPORTED_MODULE_1__["ListItem"](), new tiptap_extensions__WEBPACK_IMPORTED_MODULE_1__["OrderedList"](), new tiptap_extensions__WEBPACK_IMPORTED_MODULE_1__["TodoItem"](), new tiptap_extensions__WEBPACK_IMPORTED_MODULE_1__["TodoList"](), new tiptap_extensions__WEBPACK_IMPORTED_MODULE_1__["Link"](), new tiptap_extensions__WEBPACK_IMPORTED_MODULE_1__["Bold"](), new tiptap_extensions__WEBPACK_IMPORTED_MODULE_1__["Code"](), new tiptap_extensions__WEBPACK_IMPORTED_MODULE_1__["Italic"](), new tiptap_extensions__WEBPACK_IMPORTED_MODULE_1__["Strike"](), new tiptap_extensions__WEBPACK_IMPORTED_MODULE_1__["Underline"](), new tiptap_extensions__WEBPACK_IMPORTED_MODULE_1__["History"]()], + content: "\n

\n Hi there,\n

\n

\n this is a very basic example of tiptap.\n

\n
body { display: none; }
\n \n
\n It's amazing \uD83D\uDC4F\n
\n \u2013 mom\n
\n " + }) + }; + }, + beforeDestroy: function beforeDestroy() { + this.editor.destroy(); + } +}); + /***/ }), /***/ "./node_modules/babel-loader/lib/index.js?!./node_modules/vue-loader/lib/index.js?!./resources/js/views/Main.vue?vue&type=script&lang=js&": @@ -1896,6 +1982,14 @@ __webpack_require__.r(__webpack_exports__); // // // +// +// +// +// +// +// +// +// /* harmony default export */ __webpack_exports__["default"] = ({ data: function data() { return { @@ -1922,6 +2016,9 @@ __webpack_require__.r(__webpack_exports__); console.log("Logout unsuccessful."); console.log(error); }); + }, + editPage: function editPage() { + this.$router.push('/edit_page'); } }, created: function created() { @@ -2156,6 +2253,1227 @@ __webpack_require__.r(__webpack_exports__); } }); +/***/ }), + +/***/ "./node_modules/fault/index.js": +/*!*************************************!*\ + !*** ./node_modules/fault/index.js ***! + \*************************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +var formatter = __webpack_require__(/*! format */ "./node_modules/format/format.js") + +var fault = create(Error) + +module.exports = fault + +fault.eval = create(EvalError) +fault.range = create(RangeError) +fault.reference = create(ReferenceError) +fault.syntax = create(SyntaxError) +fault.type = create(TypeError) +fault.uri = create(URIError) + +fault.create = create + +// Create a new `EConstructor`, with the formatted `format` as a first argument. +function create(EConstructor) { + FormattedError.displayName = EConstructor.displayName || EConstructor.name + + return FormattedError + + function FormattedError(format) { + if (format) { + format = formatter.apply(null, arguments) + } + + return new EConstructor(format) + } +} + + +/***/ }), + +/***/ "./node_modules/format/format.js": +/*!***************************************!*\ + !*** ./node_modules/format/format.js ***! + \***************************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +// +// format - printf-like string formatting for JavaScript +// github.com/samsonjs/format +// @_sjs +// +// Copyright 2010 - 2013 Sami Samhuri +// +// MIT License +// http://sjs.mit-license.org +// + +;(function() { + + //// Export the API + var namespace; + + // CommonJS / Node module + if (true) { + namespace = module.exports = format; + } + + // Browsers and other environments + else {} + + namespace.format = format; + namespace.vsprintf = vsprintf; + + if (typeof console !== 'undefined' && typeof console.log === 'function') { + namespace.printf = printf; + } + + function printf(/* ... */) { + console.log(format.apply(null, arguments)); + } + + function vsprintf(fmt, replacements) { + return format.apply(null, [fmt].concat(replacements)); + } + + function format(fmt) { + var argIndex = 1 // skip initial format argument + , args = [].slice.call(arguments) + , i = 0 + , n = fmt.length + , result = '' + , c + , escaped = false + , arg + , tmp + , leadingZero = false + , precision + , nextArg = function() { return args[argIndex++]; } + , slurpNumber = function() { + var digits = ''; + while (/\d/.test(fmt[i])) { + digits += fmt[i++]; + c = fmt[i]; + } + return digits.length > 0 ? parseInt(digits) : null; + } + ; + for (; i < n; ++i) { + c = fmt[i]; + if (escaped) { + escaped = false; + if (c == '.') { + leadingZero = false; + c = fmt[++i]; + } + else if (c == '0' && fmt[i + 1] == '.') { + leadingZero = true; + i += 2; + c = fmt[i]; + } + else { + leadingZero = true; + } + precision = slurpNumber(); + switch (c) { + case 'b': // number in binary + result += parseInt(nextArg(), 10).toString(2); + break; + case 'c': // character + arg = nextArg(); + if (typeof arg === 'string' || arg instanceof String) + result += arg; + else + result += String.fromCharCode(parseInt(arg, 10)); + break; + case 'd': // number in decimal + result += parseInt(nextArg(), 10); + break; + case 'f': // floating point number + tmp = String(parseFloat(nextArg()).toFixed(precision || 6)); + result += leadingZero ? tmp : tmp.replace(/^0/, ''); + break; + case 'j': // JSON + result += JSON.stringify(nextArg()); + break; + case 'o': // number in octal + result += '0' + parseInt(nextArg(), 10).toString(8); + break; + case 's': // string + result += nextArg(); + break; + case 'x': // lowercase hexadecimal + result += '0x' + parseInt(nextArg(), 10).toString(16); + break; + case 'X': // uppercase hexadecimal + result += '0x' + parseInt(nextArg(), 10).toString(16).toUpperCase(); + break; + default: + result += c; + break; + } + } else if (c === '%') { + escaped = true; + } else { + result += c; + } + } + return result; + } + +}()); + + +/***/ }), + +/***/ "./node_modules/highlight.js/lib/highlight.js": +/*!****************************************************!*\ + !*** ./node_modules/highlight.js/lib/highlight.js ***! + \****************************************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/* +Syntax highlighting with language autodetection. +https://highlightjs.org/ +*/ + +(function(factory) { + + // Find the global object for export to both the browser and web workers. + var globalObject = typeof window === 'object' && window || + typeof self === 'object' && self; + + // Setup highlight.js for different environments. First is Node.js or + // CommonJS. + // `nodeType` is checked to ensure that `exports` is not a HTML element. + if( true && !exports.nodeType) { + factory(exports); + } else if(globalObject) { + // Export hljs globally even when using AMD for cases when this script + // is loaded with others that may still expect a global hljs. + globalObject.hljs = factory({}); + + // Finally register the global hljs with AMD. + if(true) { + !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = (function() { + return globalObject.hljs; + }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), + __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); + } + } + +}(function(hljs) { + // Convenience variables for build-in objects + var ArrayProto = [], + objectKeys = Object.keys; + + // Global internal variables used within the highlight.js library. + var languages = {}, + aliases = {}; + + // Regular expressions used throughout the highlight.js library. + var noHighlightRe = /^(no-?highlight|plain|text)$/i, + languagePrefixRe = /\blang(?:uage)?-([\w-]+)\b/i, + fixMarkupRe = /((^(<[^>]+>|\t|)+|(?:\n)))/gm; + + // The object will be assigned by the build tool. It used to synchronize API + // of external language files with minified version of the highlight.js library. + var API_REPLACES; + + var spanEndTag = ''; + + // Global options used when within external APIs. This is modified when + // calling the `hljs.configure` function. + var options = { + classPrefix: 'hljs-', + tabReplace: null, + useBR: false, + languages: undefined + }; + + // keywords that should have no default relevance value + var COMMON_KEYWORDS = 'of and for in not or if then'.split(' ') + + + /* Utility functions */ + + function escape(value) { + return value.replace(/&/g, '&').replace(//g, '>'); + } + + function tag(node) { + return node.nodeName.toLowerCase(); + } + + function testRe(re, lexeme) { + var match = re && re.exec(lexeme); + return match && match.index === 0; + } + + function isNotHighlighted(language) { + return noHighlightRe.test(language); + } + + function blockLanguage(block) { + var i, match, length, _class; + var classes = block.className + ' '; + + classes += block.parentNode ? block.parentNode.className : ''; + + // language-* takes precedence over non-prefixed class names. + match = languagePrefixRe.exec(classes); + if (match) { + return getLanguage(match[1]) ? match[1] : 'no-highlight'; + } + + classes = classes.split(/\s+/); + + for (i = 0, length = classes.length; i < length; i++) { + _class = classes[i]; + + if (isNotHighlighted(_class) || getLanguage(_class)) { + return _class; + } + } + } + + function inherit(parent) { // inherit(parent, override_obj, override_obj, ...) + var key; + var result = {}; + var objects = Array.prototype.slice.call(arguments, 1); + + for (key in parent) + result[key] = parent[key]; + objects.forEach(function(obj) { + for (key in obj) + result[key] = obj[key]; + }); + return result; + } + + /* Stream merging */ + + function nodeStream(node) { + var result = []; + (function _nodeStream(node, offset) { + for (var child = node.firstChild; child; child = child.nextSibling) { + if (child.nodeType === 3) + offset += child.nodeValue.length; + else if (child.nodeType === 1) { + result.push({ + event: 'start', + offset: offset, + node: child + }); + offset = _nodeStream(child, offset); + // Prevent void elements from having an end tag that would actually + // double them in the output. There are more void elements in HTML + // but we list only those realistically expected in code display. + if (!tag(child).match(/br|hr|img|input/)) { + result.push({ + event: 'stop', + offset: offset, + node: child + }); + } + } + } + return offset; + })(node, 0); + return result; + } + + function mergeStreams(original, highlighted, value) { + var processed = 0; + var result = ''; + var nodeStack = []; + + function selectStream() { + if (!original.length || !highlighted.length) { + return original.length ? original : highlighted; + } + if (original[0].offset !== highlighted[0].offset) { + return (original[0].offset < highlighted[0].offset) ? original : highlighted; + } + + /* + To avoid starting the stream just before it should stop the order is + ensured that original always starts first and closes last: + + if (event1 == 'start' && event2 == 'start') + return original; + if (event1 == 'start' && event2 == 'stop') + return highlighted; + if (event1 == 'stop' && event2 == 'start') + return original; + if (event1 == 'stop' && event2 == 'stop') + return highlighted; + + ... which is collapsed to: + */ + return highlighted[0].event === 'start' ? original : highlighted; + } + + function open(node) { + function attr_str(a) {return ' ' + a.nodeName + '="' + escape(a.value).replace('"', '"') + '"';} + result += '<' + tag(node) + ArrayProto.map.call(node.attributes, attr_str).join('') + '>'; + } + + function close(node) { + result += ''; + } + + function render(event) { + (event.event === 'start' ? open : close)(event.node); + } + + while (original.length || highlighted.length) { + var stream = selectStream(); + result += escape(value.substring(processed, stream[0].offset)); + processed = stream[0].offset; + if (stream === original) { + /* + On any opening or closing tag of the original markup we first close + the entire highlighted node stack, then render the original tag along + with all the following original tags at the same offset and then + reopen all the tags on the highlighted stack. + */ + nodeStack.reverse().forEach(close); + do { + render(stream.splice(0, 1)[0]); + stream = selectStream(); + } while (stream === original && stream.length && stream[0].offset === processed); + nodeStack.reverse().forEach(open); + } else { + if (stream[0].event === 'start') { + nodeStack.push(stream[0].node); + } else { + nodeStack.pop(); + } + render(stream.splice(0, 1)[0]); + } + } + return result + escape(value.substr(processed)); + } + + /* Initialization */ + + function dependencyOnParent(mode) { + if (!mode) return false; + + return mode.endsWithParent || dependencyOnParent(mode.starts) + } + + function expand_or_clone_mode(mode) { + if (mode.variants && !mode.cached_variants) { + mode.cached_variants = mode.variants.map(function(variant) { + return inherit(mode, {variants: null}, variant); + }); + } + + // EXPAND + // if we have variants then essentually "replace" the mode with the variants + // this happens in compileMode, where this function is called from + if (mode.cached_variants) + return mode.cached_variants; + + // CLONE + // if we have dependencies on parents then we need a unique + // instance of ourselves, so we can be reused with many + // different parents without issue + if (dependencyOnParent(mode)) + return [inherit(mode, { starts: mode.starts ? inherit(mode.starts) : null })] + + // no special dependency issues, just return ourselves + return [mode] + } + + function restoreLanguageApi(obj) { + if(API_REPLACES && !obj.langApiRestored) { + obj.langApiRestored = true; + for(var key in API_REPLACES) + obj[key] && (obj[API_REPLACES[key]] = obj[key]); + (obj.contains || []).concat(obj.variants || []).forEach(restoreLanguageApi); + } + } + + function compileKeywords(rawKeywords, case_insensitive) { + var compiled_keywords = {}; + + if (typeof rawKeywords === 'string') { // string + splitAndCompile('keyword', rawKeywords); + } else { + objectKeys(rawKeywords).forEach(function (className) { + splitAndCompile(className, rawKeywords[className]); + }); + } + return compiled_keywords; + + // --- + + function splitAndCompile(className, str) { + if (case_insensitive) { + str = str.toLowerCase(); + } + str.split(' ').forEach(function(keyword) { + var pair = keyword.split('|'); + compiled_keywords[pair[0]] = [className, scoreForKeyword(pair[0], pair[1])]; + }); + }; + } + + function scoreForKeyword(keyword, providedScore) { + // manual scores always win over common keywords + // so you can force a score of 1 if you really insist + if (providedScore) + return Number(providedScore) + + return commonKeyword(keyword) ? 0 : 1; + } + + function commonKeyword(word) { + return COMMON_KEYWORDS.indexOf(word.toLowerCase()) != -1 + } + + function compileLanguage(language) { + + function reStr(re) { + return (re && re.source) || re; + } + + function langRe(value, global) { + return new RegExp( + reStr(value), + 'm' + (language.case_insensitive ? 'i' : '') + (global ? 'g' : '') + ); + } + + function reCountMatchGroups(re) { + return (new RegExp(re.toString() + '|')).exec('').length - 1; + } + + // joinRe logically computes regexps.join(separator), but fixes the + // backreferences so they continue to match. + // it also places each individual regular expression into it's own + // match group, keeping track of the sequencing of those match groups + // is currently an exercise for the caller. :-) + function joinRe(regexps, separator) { + // backreferenceRe matches an open parenthesis or backreference. To avoid + // an incorrect parse, it additionally matches the following: + // - [...] elements, where the meaning of parentheses and escapes change + // - other escape sequences, so we do not misparse escape sequences as + // interesting elements + // - non-matching or lookahead parentheses, which do not capture. These + // follow the '(' with a '?'. + var backreferenceRe = /\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9][0-9]*)|\\./; + var numCaptures = 0; + var ret = ''; + for (var i = 0; i < regexps.length; i++) { + numCaptures += 1; + var offset = numCaptures; + var re = reStr(regexps[i]); + if (i > 0) { + ret += separator; + } + ret += "("; + while (re.length > 0) { + var match = backreferenceRe.exec(re); + if (match == null) { + ret += re; + break; + } + ret += re.substring(0, match.index); + re = re.substring(match.index + match[0].length); + if (match[0][0] == '\\' && match[1]) { + // Adjust the backreference. + ret += '\\' + String(Number(match[1]) + offset); + } else { + ret += match[0]; + if (match[0] == '(') { + numCaptures++; + } + } + } + ret += ")"; + } + return ret; + } + + function buildModeRegex(mode) { + + var matchIndexes = {}; + var matcherRe; + var regexes = []; + var matcher = {}; + var matchAt = 1; + + function addRule(rule, regex) { + matchIndexes[matchAt] = rule; + regexes.push([rule, regex]); + matchAt += reCountMatchGroups(regex) + 1; + } + + var term; + for (var i=0; i < mode.contains.length; i++) { + var re; + term = mode.contains[i]; + if (term.beginKeywords) { + re = '\\.?(?:' + term.begin + ')\\.?'; + } else { + re = term.begin; + } + addRule(term, re); + } + if (mode.terminator_end) + addRule("end", mode.terminator_end); + if (mode.illegal) + addRule("illegal", mode.illegal); + + var terminators = regexes.map(function(el) { return el[1] }); + matcherRe = langRe(joinRe(terminators, '|'), true); + + matcher.lastIndex = 0; + matcher.exec = function(s) { + var rule; + + if( regexes.length === 0) return null; + + matcherRe.lastIndex = matcher.lastIndex; + var match = matcherRe.exec(s); + if (!match) { return null; } + + for(var i = 0; i'; + + return openSpan + insideSpan + closeSpan; + } + + function processKeywords() { + var keyword_match, last_index, match, result; + + if (!top.keywords) + return escape(mode_buffer); + + result = ''; + last_index = 0; + top.lexemesRe.lastIndex = 0; + match = top.lexemesRe.exec(mode_buffer); + + while (match) { + result += escape(mode_buffer.substring(last_index, match.index)); + keyword_match = keywordMatch(top, match); + if (keyword_match) { + relevance += keyword_match[1]; + result += buildSpan(keyword_match[0], escape(match[0])); + } else { + result += escape(match[0]); + } + last_index = top.lexemesRe.lastIndex; + match = top.lexemesRe.exec(mode_buffer); + } + return result + escape(mode_buffer.substr(last_index)); + } + + function processSubLanguage() { + var explicit = typeof top.subLanguage === 'string'; + if (explicit && !languages[top.subLanguage]) { + return escape(mode_buffer); + } + + var result = explicit ? + highlight(top.subLanguage, mode_buffer, true, continuations[top.subLanguage]) : + highlightAuto(mode_buffer, top.subLanguage.length ? top.subLanguage : undefined); + + // Counting embedded language score towards the host language may be disabled + // with zeroing the containing mode relevance. Usecase in point is Markdown that + // allows XML everywhere and makes every XML snippet to have a much larger Markdown + // score. + if (top.relevance > 0) { + relevance += result.relevance; + } + if (explicit) { + continuations[top.subLanguage] = result.top; + } + return buildSpan(result.language, result.value, false, true); + } + + function processBuffer() { + result += (top.subLanguage != null ? processSubLanguage() : processKeywords()); + mode_buffer = ''; + } + + function startNewMode(mode) { + result += mode.className? buildSpan(mode.className, '', true): ''; + top = Object.create(mode, {parent: {value: top}}); + } + + + function doBeginMatch(match) { + var lexeme = match[0]; + var new_mode = match.rule; + + if (new_mode && new_mode.endSameAsBegin) { + new_mode.endRe = escapeRe( lexeme ); + } + + if (new_mode.skip) { + mode_buffer += lexeme; + } else { + if (new_mode.excludeBegin) { + mode_buffer += lexeme; + } + processBuffer(); + if (!new_mode.returnBegin && !new_mode.excludeBegin) { + mode_buffer = lexeme; + } + } + startNewMode(new_mode, lexeme); + return new_mode.returnBegin ? 0 : lexeme.length; + } + + function doEndMatch(match) { + var lexeme = match[0]; + var end_mode = endOfMode(top, lexeme); + if (!end_mode) { return; } + + var origin = top; + if (origin.skip) { + mode_buffer += lexeme; + } else { + if (!(origin.returnEnd || origin.excludeEnd)) { + mode_buffer += lexeme; + } + processBuffer(); + if (origin.excludeEnd) { + mode_buffer = lexeme; + } + } + do { + if (top.className) { + result += spanEndTag; + } + if (!top.skip && !top.subLanguage) { + relevance += top.relevance; + } + top = top.parent; + } while (top !== end_mode.parent); + if (end_mode.starts) { + if (end_mode.endSameAsBegin) { + end_mode.starts.endRe = end_mode.endRe; + } + startNewMode(end_mode.starts, ''); + } + return origin.returnEnd ? 0 : lexeme.length; + } + + var lastMatch = {}; + function processLexeme(text_before_match, match) { + + var lexeme = match && match[0]; + + // add non-matched text to the current mode buffer + mode_buffer += text_before_match; + + if (lexeme == null) { + processBuffer(); + return 0; + } + + // we've found a 0 width match and we're stuck, so we need to advance + // this happens when we have badly behaved rules that have optional matchers to the degree that + // sometimes they can end up matching nothing at all + // Ref: https://github.com/highlightjs/highlight.js/issues/2140 + if (lastMatch.type=="begin" && match.type=="end" && lastMatch.index == match.index && lexeme === "") { + // spit the "skipped" character that our regex choked on back into the output sequence + mode_buffer += value.slice(match.index, match.index + 1) + return 1; + } + lastMatch = match; + + if (match.type==="begin") { + return doBeginMatch(match); + } else if (match.type==="illegal" && !ignore_illegals) { + // illegal match, we do not continue processing + throw new Error('Illegal lexeme "' + lexeme + '" for mode "' + (top.className || '') + '"'); + } else if (match.type==="end") { + var processed = doEndMatch(match); + if (processed != undefined) + return processed; + } + + /* + Why might be find ourselves here? Only one occasion now. An end match that was + triggered but could not be completed. When might this happen? When an `endSameasBegin` + rule sets the end rule to a specific match. Since the overall mode termination rule that's + being used to scan the text isn't recompiled that means that any match that LOOKS like + the end (but is not, because it is not an exact match to the beginning) will + end up here. A definite end match, but when `doEndMatch` tries to "reapply" + the end rule and fails to match, we wind up here, and just silently ignore the end. + + This causes no real harm other than stopping a few times too many. + */ + + mode_buffer += lexeme; + return lexeme.length; + } + + var language = getLanguage(name); + if (!language) { + throw new Error('Unknown language: "' + name + '"'); + } + + compileLanguage(language); + var top = continuation || language; + var continuations = {}; // keep continuations for sub-languages + var result = '', current; + for(current = top; current !== language; current = current.parent) { + if (current.className) { + result = buildSpan(current.className, '', true) + result; + } + } + var mode_buffer = ''; + var relevance = 0; + try { + var match, count, index = 0; + while (true) { + top.terminators.lastIndex = index; + match = top.terminators.exec(value); + if (!match) + break; + count = processLexeme(value.substring(index, match.index), match); + index = match.index + count; + } + processLexeme(value.substr(index)); + for(current = top; current.parent; current = current.parent) { // close dangling modes + if (current.className) { + result += spanEndTag; + } + } + return { + relevance: relevance, + value: result, + illegal:false, + language: name, + top: top + }; + } catch (e) { + if (e.message && e.message.indexOf('Illegal') !== -1) { + return { + illegal: true, + relevance: 0, + value: escape(value) + }; + } else { + throw e; + } + } + } + + /* + Highlighting with language detection. Accepts a string with the code to + highlight. Returns an object with the following properties: + + - language (detected language) + - relevance (int) + - value (an HTML string with highlighting markup) + - second_best (object with the same structure for second-best heuristically + detected language, may be absent) + + */ + function highlightAuto(text, languageSubset) { + languageSubset = languageSubset || options.languages || objectKeys(languages); + var result = { + relevance: 0, + value: escape(text) + }; + var second_best = result; + languageSubset.filter(getLanguage).filter(autoDetection).forEach(function(name) { + var current = highlight(name, text, false); + current.language = name; + if (current.relevance > second_best.relevance) { + second_best = current; + } + if (current.relevance > result.relevance) { + second_best = result; + result = current; + } + }); + if (second_best.language) { + result.second_best = second_best; + } + return result; + } + + /* + Post-processing of the highlighted markup: + + - replace TABs with something more useful + - replace real line-breaks with '
' for non-pre containers + + */ + function fixMarkup(value) { + return !(options.tabReplace || options.useBR) + ? value + : value.replace(fixMarkupRe, function(match, p1) { + if (options.useBR && match === '\n') { + return '
'; + } else if (options.tabReplace) { + return p1.replace(/\t/g, options.tabReplace); + } + return ''; + }); + } + + function buildClassName(prevClassName, currentLang, resultLang) { + var language = currentLang ? aliases[currentLang] : resultLang, + result = [prevClassName.trim()]; + + if (!prevClassName.match(/\bhljs\b/)) { + result.push('hljs'); + } + + if (prevClassName.indexOf(language) === -1) { + result.push(language); + } + + return result.join(' ').trim(); + } + + /* + Applies highlighting to a DOM node containing code. Accepts a DOM node and + two optional parameters for fixMarkup. + */ + function highlightBlock(block) { + var node, originalStream, result, resultNode, text; + var language = blockLanguage(block); + + if (isNotHighlighted(language)) + return; + + if (options.useBR) { + node = document.createElementNS('http://www.w3.org/1999/xhtml', 'div'); + node.innerHTML = block.innerHTML.replace(/\n/g, '').replace(//g, '\n'); + } else { + node = block; + } + text = node.textContent; + result = language ? highlight(language, text, true) : highlightAuto(text); + + originalStream = nodeStream(node); + if (originalStream.length) { + resultNode = document.createElementNS('http://www.w3.org/1999/xhtml', 'div'); + resultNode.innerHTML = result.value; + result.value = mergeStreams(originalStream, nodeStream(resultNode), text); + } + result.value = fixMarkup(result.value); + + block.innerHTML = result.value; + block.className = buildClassName(block.className, language, result.language); + block.result = { + language: result.language, + re: result.relevance + }; + if (result.second_best) { + block.second_best = { + language: result.second_best.language, + re: result.second_best.relevance + }; + } + } + + /* + Updates highlight.js global options with values passed in the form of an object. + */ + function configure(user_options) { + options = inherit(options, user_options); + } + + /* + Applies highlighting to all
..
blocks on a page. + */ + function initHighlighting() { + if (initHighlighting.called) + return; + initHighlighting.called = true; + + var blocks = document.querySelectorAll('pre code'); + ArrayProto.forEach.call(blocks, highlightBlock); + } + + /* + Attaches highlighting to the page load event. + */ + function initHighlightingOnLoad() { + addEventListener('DOMContentLoaded', initHighlighting, false); + addEventListener('load', initHighlighting, false); + } + + function registerLanguage(name, language) { + var lang = languages[name] = language(hljs); + restoreLanguageApi(lang); + lang.rawDefinition = language.bind(null,hljs); + + if (lang.aliases) { + lang.aliases.forEach(function(alias) {aliases[alias] = name;}); + } + } + + function listLanguages() { + return objectKeys(languages); + } + + function getLanguage(name) { + name = (name || '').toLowerCase(); + return languages[name] || languages[aliases[name]]; + } + + function autoDetection(name) { + var lang = getLanguage(name); + return lang && !lang.disableAutodetect; + } + + /* Interface definition */ + + hljs.highlight = highlight; + hljs.highlightAuto = highlightAuto; + hljs.fixMarkup = fixMarkup; + hljs.highlightBlock = highlightBlock; + hljs.configure = configure; + hljs.initHighlighting = initHighlighting; + hljs.initHighlightingOnLoad = initHighlightingOnLoad; + hljs.registerLanguage = registerLanguage; + hljs.listLanguages = listLanguages; + hljs.getLanguage = getLanguage; + hljs.autoDetection = autoDetection; + hljs.inherit = inherit; + + // Common regexps + hljs.IDENT_RE = '[a-zA-Z]\\w*'; + hljs.UNDERSCORE_IDENT_RE = '[a-zA-Z_]\\w*'; + hljs.NUMBER_RE = '\\b\\d+(\\.\\d+)?'; + hljs.C_NUMBER_RE = '(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)'; // 0x..., 0..., decimal, float + hljs.BINARY_NUMBER_RE = '\\b(0b[01]+)'; // 0b... + hljs.RE_STARTERS_RE = '!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~'; + + // Common modes + hljs.BACKSLASH_ESCAPE = { + begin: '\\\\[\\s\\S]', relevance: 0 + }; + hljs.APOS_STRING_MODE = { + className: 'string', + begin: '\'', end: '\'', + illegal: '\\n', + contains: [hljs.BACKSLASH_ESCAPE] + }; + hljs.QUOTE_STRING_MODE = { + className: 'string', + begin: '"', end: '"', + illegal: '\\n', + contains: [hljs.BACKSLASH_ESCAPE] + }; + hljs.PHRASAL_WORDS_MODE = { + begin: /\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/ + }; + hljs.COMMENT = function (begin, end, inherits) { + var mode = hljs.inherit( + { + className: 'comment', + begin: begin, end: end, + contains: [] + }, + inherits || {} + ); + mode.contains.push(hljs.PHRASAL_WORDS_MODE); + mode.contains.push({ + className: 'doctag', + begin: '(?:TODO|FIXME|NOTE|BUG|XXX):', + relevance: 0 + }); + return mode; + }; + hljs.C_LINE_COMMENT_MODE = hljs.COMMENT('//', '$'); + hljs.C_BLOCK_COMMENT_MODE = hljs.COMMENT('/\\*', '\\*/'); + hljs.HASH_COMMENT_MODE = hljs.COMMENT('#', '$'); + hljs.NUMBER_MODE = { + className: 'number', + begin: hljs.NUMBER_RE, + relevance: 0 + }; + hljs.C_NUMBER_MODE = { + className: 'number', + begin: hljs.C_NUMBER_RE, + relevance: 0 + }; + hljs.BINARY_NUMBER_MODE = { + className: 'number', + begin: hljs.BINARY_NUMBER_RE, + relevance: 0 + }; + hljs.CSS_NUMBER_MODE = { + className: 'number', + begin: hljs.NUMBER_RE + '(' + + '%|em|ex|ch|rem' + + '|vw|vh|vmin|vmax' + + '|cm|mm|in|pt|pc|px' + + '|deg|grad|rad|turn' + + '|s|ms' + + '|Hz|kHz' + + '|dpi|dpcm|dppx' + + ')?', + relevance: 0 + }; + hljs.REGEXP_MODE = { + className: 'regexp', + begin: /\//, end: /\/[gimuy]*/, + illegal: /\n/, + contains: [ + hljs.BACKSLASH_ESCAPE, + { + begin: /\[/, end: /\]/, + relevance: 0, + contains: [hljs.BACKSLASH_ESCAPE] + } + ] + }; + hljs.TITLE_MODE = { + className: 'title', + begin: hljs.IDENT_RE, + relevance: 0 + }; + hljs.UNDERSCORE_TITLE_MODE = { + className: 'title', + begin: hljs.UNDERSCORE_IDENT_RE, + relevance: 0 + }; + hljs.METHOD_GUARD = { + // excludes method names from keyword processing + begin: '\\.\\s*' + hljs.UNDERSCORE_IDENT_RE, + relevance: 0 + }; + + return hljs; +})); + + /***/ }), /***/ "./node_modules/is-buffer/index.js": @@ -2178,6 +3496,1084 @@ module.exports = function isBuffer (obj) { } +/***/ }), + +/***/ "./node_modules/lowlight/lib/core.js": +/*!*******************************************!*\ + !*** ./node_modules/lowlight/lib/core.js ***! + \*******************************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +var high = __webpack_require__(/*! highlight.js/lib/highlight.js */ "./node_modules/highlight.js/lib/highlight.js") +var fault = __webpack_require__(/*! fault */ "./node_modules/fault/index.js") + +// The lowlight interface, which has to be compatible with highlight.js, as +// this object is passed to highlight.js syntaxes. + +function High() {} + +High.prototype = high + +// Expose. +var low = new High() // Ha! + +module.exports = low + +low.highlight = highlight +low.highlightAuto = autoHighlight +low.registerLanguage = registerLanguage +low.listLanguages = listLanguages +low.registerAlias = registerAlias +low.getLanguage = getLanguage + +var inherit = high.inherit +var own = {}.hasOwnProperty + +var defaultPrefix = 'hljs-' +var keyInsensitive = 'case_insensitive' +var keyCachedVariants = 'cached_variants' +var keyTerminatorEnd = 'terminator_end' +var space = ' ' +var verticalBar = '|' +var parenOpen = '(' +var parenClose = ')' +var backslash = '\\' +var commonKeywords = ['of', 'and', 'for', 'in', 'not', 'or', 'if', 'then'] + +// Maps of syntaxes. +var languageNames = [] +var languages = {} +var aliases = {} + +// Highlighting with language detection. +// Accepts a string with the code to highlight. +// Returns an object with the following properties: +// +// * `language` — Detected language +// * `relevance` — Integer +// * `value` — HAST tree with highlighting markup +// * `secondBest` — Object with the same structure for second-best +// heuristically detected language, may be absent. +function autoHighlight(value, options) { + var settings = options || {} + var subset = settings.subset || languageNames + var prefix = settings.prefix + var length = subset.length + var index = -1 + var result + var secondBest + var current + var name + + if (prefix === null || prefix === undefined) { + prefix = defaultPrefix + } + + if (typeof value !== 'string') { + throw fault('Expected `string` for value, got `%s`', value) + } + + secondBest = normalize({}) + result = normalize({}) + + while (++index < length) { + name = subset[index] + + if (!getLanguage(name)) { + continue + } + + current = normalize(coreHighlight(name, value, false, prefix)) + + current.language = name + + if (current.relevance > secondBest.relevance) { + secondBest = current + } + + if (current.relevance > result.relevance) { + secondBest = result + result = current + } + } + + if (secondBest.language) { + result.secondBest = secondBest + } + + return result +} + +// Highlighting `value` in the language `language`. +function highlight(language, value, options) { + var settings = options || {} + var prefix = settings.prefix + + if (prefix === null || prefix === undefined) { + prefix = defaultPrefix + } + + return normalize(coreHighlight(language, value, true, prefix)) +} + +// Register a language. +function registerLanguage(name, syntax) { + var lang = syntax(low) + + lang.rawDefinition = syntax.bind(null, low) + + languages[name] = lang + + languageNames.push(name) + + if (lang.aliases) { + registerAlias(name, lang.aliases) + } +} + +// Get a list of all registered languages. +function listLanguages() { + return languageNames.concat() +} + +// Register more aliases for an already registered language. +function registerAlias(name, alias) { + var map = name + var key + var list + var length + var index + + if (alias) { + map = {} + map[name] = alias + } + + for (key in map) { + list = map[key] + list = typeof list === 'string' ? [list] : list + length = list.length + index = -1 + + while (++index < length) { + aliases[list[index]] = key + } + } +} + +// Core highlighting function. +// Accepts a language name, or an alias, and a string with the code to +// highlight. +// eslint-disable-next-line max-params +function coreHighlight(name, value, ignore, prefix, continuation) { + var lastMatch = {} + var continuations = {} + var stack = [] + var modeBuffer = '' + var relevance = 0 + var language + var top + var current + var currentChildren + var offset + var count + var match + var children + + if (typeof name !== 'string') { + throw fault('Expected `string` for name, got `%s`', name) + } + + if (typeof value !== 'string') { + throw fault('Expected `string` for value, got `%s`', value) + } + + language = getLanguage(name) + top = continuation || language + children = [] + + current = top + currentChildren = children + + if (!language) { + throw fault('Unknown language: `%s` is not registered', name) + } + + compileLanguage(language) + + try { + top.terminators.lastIndex = 0 + offset = 0 + match = top.terminators.exec(value) + + while (match) { + count = processLexeme(value.slice(offset, match.index), match) + offset = match.index + count + top.terminators.lastIndex = offset + match = top.terminators.exec(value) + } + + processLexeme(value.slice(offset)) + current = top + + while (current.parent) { + if (current.className) { + pop() + } + + current = current.parent + } + + return { + relevance: relevance, + value: currentChildren, + illegal: false, + language: name, + top: top + } + } catch (error) { + /* istanbul ignore if - Catch-all */ + if (error.message.indexOf('Illegal') === -1) { + throw error + } + + return {relevance: 0, illegal: true, value: addText(value, [])} + } + + function escapeRe(value) { + return new RegExp(value.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'), 'm') + } + + function doBeginMatch(match) { + var lexeme = match[0] + var newMode = match.rule + + if (newMode && newMode.endSameAsBegin) { + newMode.endRe = escapeRe(lexeme) + } + + if (newMode.skip) { + modeBuffer += lexeme + } else { + if (newMode.excludeBegin) { + modeBuffer += lexeme + } + + addSiblings(processBuffer(), currentChildren) + + if (!newMode.returnBegin && !newMode.excludeBegin) { + modeBuffer = lexeme + } + } + + startNewMode(newMode) + + return newMode.returnBegin ? 0 : lexeme.length + } + + function doEndMatch(match) { + var lexeme = match[0] + var matchPlusRemainder = value.slice(match.index) + var endMode = endOfMode(top, matchPlusRemainder) + + if (!endMode) { + return + } + + var origin = top + + if (origin.skip) { + modeBuffer += lexeme + } else { + if (!(origin.returnEnd || origin.excludeEnd)) { + modeBuffer += lexeme + } + + addSiblings(processBuffer(), currentChildren) + + if (origin.excludeEnd) { + modeBuffer = lexeme + } + } + + do { + if (top.className) { + pop() + } + + if (!top.skip && !top.subLanguage) { + relevance += top.relevance + } + + top = top.parent + } while (top !== endMode.parent) + + if (endMode.starts) { + /* istanbul ignore if - hljs 9.16 added support for this but didn’t use it yet. */ + if (endMode.endSameAsBegin) { + endMode.starts.endRe = endMode.endRe + } + + startNewMode(endMode.starts) + } + + return origin.returnEnd ? 0 : lexeme.length + } + + function processLexeme(textBeforeMatch, match) { + var lexeme = match && match[0] + var processed + + // Add non-matched text to the current mode buffer + modeBuffer += textBeforeMatch + + if (lexeme === undefined) { + addSiblings(processBuffer(), currentChildren) + return 0 + } + + // We've found a 0 width match and we're stuck, so we need to advance + // this happens when we have badly behaved rules that have optional matchers to the degree that + // sometimes they can end up matching nothing at all + // Ref: https://github.com/highlightjs/highlight.js/issues/2140 + /* istanbul ignore if - Unknown what this fixes or which case fixes it */ + if ( + lastMatch.type === 'begin' && + match.type === 'end' && + lastMatch.index === match.index && + lexeme === '' + ) { + // Spit the “skipped” character that our regex choked on back into the output sequence + modeBuffer += value.slice(match.index, match.index + 1) + return 1 + } + + lastMatch = match + + if (match.type === 'begin') { + return doBeginMatch(match) + } + + if (match.type === 'end') { + processed = doEndMatch(match) + + if (processed !== undefined) { + return processed + } + } + + if (match.type === 'illegal' && !ignore) { + // Illegal match, we do not continue processing + throw fault( + 'Illegal lexeme "%s" for mode "%s"', + lexeme, + top.className || '' + ) + } + + // Why might be find ourselves here? + // Only one occasion now. + // An end match that was triggered but could not be completed. + // When might this happen? + // When an `endSameasBegin` rule sets the end rule to a specific match. + // Since the overall mode termination rule that’s being used to scan the + // text isn’t recompiled that means that any match that LOOKS like the end + // (but is not, because it is not an exact match to the beginning) will end + // up here. + // A definite end match, but when `doEndMatch` tries to “reapply” the end + // rule and fails to match, we wind up here, and just silently ignore the + // end. + // This causes no real harm other than stopping a few times too many. + modeBuffer += lexeme + + return lexeme.length + } + + // Start a new mode with a `lexeme` to process. + function startNewMode(mode) { + var node + + if (mode.className) { + node = build(mode.className, []) + } + + // Enter a new mode. + if (node) { + currentChildren.push(node) + stack.push(currentChildren) + currentChildren = node.children + } + + top = Object.create(mode, {parent: {value: top}}) + } + + // Process the buffer. + function processBuffer() { + var result = top.subLanguage ? processSubLanguage() : processKeywords() + modeBuffer = '' + return result + } + + // Process a sublanguage (returns a list of nodes). + function processSubLanguage() { + var explicit = typeof top.subLanguage === 'string' + var subvalue + + /* istanbul ignore if - support non-loaded sublanguages */ + if (explicit && !languages[top.subLanguage]) { + return addText(modeBuffer, []) + } + + if (explicit) { + subvalue = coreHighlight( + top.subLanguage, + modeBuffer, + true, + prefix, + continuations[top.subLanguage] + ) + } else { + subvalue = autoHighlight(modeBuffer, { + subset: top.subLanguage.length === 0 ? undefined : top.subLanguage, + prefix: prefix + }) + } + + // If we couldn’t highlight, for example because the requests subset isn’t + // loaded, return a text node. + if (!subvalue.language) { + return [buildText(modeBuffer)] + } + + // Counting embedded language score towards the host language may be + // disabled with zeroing the containing mode relevance. + // Usecase in point is Markdown that allows XML everywhere and makes every + // XML snippet to have a much larger Markdown score. + if (top.relevance > 0) { + relevance += subvalue.relevance + } + + if (explicit) { + continuations[top.subLanguage] = subvalue.top + } + + return [build(subvalue.language, subvalue.value, true)] + } + + // Process keywords. Returns nodes. + function processKeywords() { + var nodes = [] + var lastIndex + var keyword + var node + var submatch + + if (!top.keywords) { + return addText(modeBuffer, nodes) + } + + lastIndex = 0 + + top.lexemesRe.lastIndex = 0 + + keyword = top.lexemesRe.exec(modeBuffer) + + while (keyword) { + addText(modeBuffer.slice(lastIndex, keyword.index), nodes) + + submatch = keywordMatch(top, keyword) + + if (submatch) { + relevance += submatch[1] + + node = build(submatch[0], []) + + nodes.push(node) + + addText(keyword[0], node.children) + } else { + addText(keyword[0], nodes) + } + + lastIndex = top.lexemesRe.lastIndex + keyword = top.lexemesRe.exec(modeBuffer) + } + + addText(modeBuffer.slice(lastIndex), nodes) + + return nodes + } + + // Add siblings. + function addSiblings(siblings, nodes) { + var length = siblings.length + var index = -1 + var sibling + + while (++index < length) { + sibling = siblings[index] + + if (sibling.type === 'text') { + addText(sibling.value, nodes) + } else { + nodes.push(sibling) + } + } + } + + // Add a text. + function addText(value, nodes) { + var tail + + if (value) { + tail = nodes[nodes.length - 1] + + if (tail && tail.type === 'text') { + tail.value += value + } else { + nodes.push(buildText(value)) + } + } + + return nodes + } + + // Build a text. + function buildText(value) { + return {type: 'text', value: value} + } + + // Build a span. + function build(name, contents, noPrefix) { + return { + type: 'element', + tagName: 'span', + properties: { + className: [(noPrefix ? '' : prefix) + name] + }, + children: contents + } + } + + // Check if the first word in `keywords` is a keyword. + function keywordMatch(mode, keywords) { + var keyword = keywords[0] + + if (language[keyInsensitive]) { + keyword = keyword.toLowerCase() + } + + return own.call(mode.keywords, keyword) && mode.keywords[keyword] + } + + // Check if `lexeme` ends `mode`. + function endOfMode(mode, lexeme) { + if (test(mode.endRe, lexeme)) { + while (mode.endsParent && mode.parent) { + mode = mode.parent + } + + return mode + } + + if (mode.endsWithParent) { + return endOfMode(mode.parent, lexeme) + } + } + + // Exit the current context. + function pop() { + /* istanbul ignore next - removed in hljs 9.3 */ + currentChildren = stack.pop() || children + } +} + +// Compile a language. +function compileLanguage(language) { + compileMode(language) + + // Compile a language mode, optionally with a parent. + function compileMode(mode, parent) { + if (mode.compiled) { + return + } + + mode.compiled = true + + mode.keywords = mode.keywords || mode.beginKeywords + + if (mode.keywords) { + mode.keywords = compileKeywords(mode.keywords, language[keyInsensitive]) + } + + mode.lexemesRe = langRe(mode.lexemes || /\w+/, true) + + if (parent) { + if (mode.beginKeywords) { + mode.begin = + '\\b(' + mode.beginKeywords.split(space).join(verticalBar) + ')\\b' + } + + if (!mode.begin) { + mode.begin = /\B|\b/ + } + + mode.beginRe = langRe(mode.begin) + + if (mode.endSameAsBegin) { + mode.end = mode.begin + } + + if (!mode.end && !mode.endsWithParent) { + mode.end = /\B|\b/ + } + + if (mode.end) { + mode.endRe = langRe(mode.end) + } + + mode[keyTerminatorEnd] = source(mode.end) || '' + + if (mode.endsWithParent && parent[keyTerminatorEnd]) { + mode[keyTerminatorEnd] += + (mode.end ? verticalBar : '') + parent[keyTerminatorEnd] + } + } + + if (mode.illegal) { + mode.illegalRe = langRe(mode.illegal) + } + + if (mode.relevance === undefined) { + mode.relevance = 1 + } + + mode.contains = compileContains(mode.contains || [], mode) + + if (mode.starts) { + compileMode(mode.starts, parent) + } + + mode.terminators = buildModeRegex(mode) + } + + function compileContains(contains, mode) { + var result = [] + var length = contains.length + var index = -1 + var contained + + while (++index < length) { + contained = contains[index] + result = result.concat( + expandOrCloneMode(contained === 'self' ? mode : contained) + ) + } + + length = result.length + index = -1 + + while (++index < length) { + compileMode(result[index], mode) + } + + return result + } + + function buildModeRegex(mode) { + var indices = {} + var expression + var regexes = [] + var matcher = {} + var matchAt = 1 + var term + var values = mode.contains + var length = values.length + var index = -1 + var terminators = [] + + while (++index < length) { + term = values[index] + + addRule( + term, + term.beginKeywords ? '\\.?(?:' + term.begin + ')\\.?' : term.begin + ) + } + + if (mode[keyTerminatorEnd]) { + addRule('end', mode[keyTerminatorEnd]) + } + + if (mode.illegal) { + addRule('illegal', mode.illegal) + } + + length = regexes.length + index = -1 + + while (++index < length) { + terminators[index] = regexes[index][1] + } + + expression = langRe(joinRe(terminators, verticalBar), true) + + matcher = {lastIndex: 0, exec: exec} + + return matcher + + function exec(value) { + var length + var index + var rule + var match + var submatch + + if (regexes.length === 0) return null + + expression.lastIndex = matcher.lastIndex + match = expression.exec(value) + + if (!match) { + return null + } + + length = match.length + index = -1 + + while (++index < length) { + submatch = match[index] + + if (submatch !== undefined && indices[index] !== undefined) { + rule = indices[index] + break + } + } + + // Illegal or end match + if (typeof rule === 'string') { + match.type = rule + match.extra = [mode.illegal, mode.terminator_end] + } else { + match.type = 'begin' + match.rule = rule + } + + return match + } + + function addRule(rule, regex) { + indices[matchAt] = rule + regexes.push([rule, regex]) + matchAt += new RegExp(regex.toString() + verticalBar).exec('').length + } + } + + function joinRe(regexes, separator) { + var backreferenceRe = /\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9]\d*)|\\./ + var captures = 0 + var result = '' + var length = regexes.length + var index = -1 + var regex + var offset + var expression + var match + + while (++index < length) { + regex = regexes[index] + expression = source(regex) + captures += 1 + offset = captures + + if (index !== 0) { + result += separator + } + + result += parenOpen + + while (expression.length > 0) { + match = backreferenceRe.exec(expression) + + if (match === null) { + result += expression + break + } + + result += expression.slice(0, match.index) + expression = expression.slice(match.index + match[0].length) + + if (match[0][0] === backslash && match[1]) { + // Adjust the backreference. + result += backslash + String(Number(match[1]) + offset) + } else { + result += match[0] + + if (match[0] === parenOpen) { + captures++ + } + } + } + + result += parenClose + } + + return result + } + + // Create a regex for `value`. + function langRe(value, global) { + return new RegExp( + source(value), + 'm' + (language[keyInsensitive] ? 'i' : '') + (global ? 'g' : '') + ) + } + + // Get the source of an expression or string. + function source(re) { + return (re && re.source) || re + } +} + +function compileKeywords(values, caseInsensitive) { + var compiled = {} + var key + + if (typeof values === 'string') { + flatten('keyword', values) + } else { + for (key in values) { + flatten(key, values[key]) + } + } + + return compiled + + function flatten(key, value) { + var val = caseInsensitive ? value.toLowerCase() : value + all(key, val.split(space)) + } + + function all(key, values) { + var length = values.length + var index = -1 + var pair + + while (++index < length) { + pair = values[index].split(verticalBar) + compiled[pair[0]] = [key, Number(pair[1]) || common(pair[0]) ? 0 : 1] + } + } +} + +function common(value) { + return commonKeywords.indexOf(value.toLowerCase()) !== -1 +} + +function expandOrCloneMode(mode) { + var length + var index + var variants + var result + + if (mode.variants && !mode[keyCachedVariants]) { + variants = mode.variants + length = variants.length + index = -1 + result = [] + + while (++index < length) { + result[index] = inherit(mode, {variants: null}, variants[index]) + } + + mode[keyCachedVariants] = result + } + + // Expand. + if (mode.cached_variants) return mode.cached_variants + + // Clone. + if (dependencyOnParent(mode)) + return [inherit(mode, {starts: mode.starts ? inherit(mode.starts) : null})] + + return [mode] +} + +function dependencyOnParent(mode) { + return mode ? mode.endsWithParent || dependencyOnParent(mode.starts) : false +} + +// Normalize a syntax result. +function normalize(result) { + return { + relevance: result.relevance || 0, + language: result.language || null, + value: result.value || [] + } +} + +// Check if `expression` matches `lexeme`. +function test(expression, lexeme) { + var match = expression && expression.exec(lexeme) + return match && match.index === 0 +} + +// Get a language by `name`. +function getLanguage(name) { + name = name.toLowerCase() + + return languages[name] || languages[aliases[name]] +} + + +/***/ }), + +/***/ "./node_modules/orderedmap/index.es.js": +/*!*********************************************!*\ + !*** ./node_modules/orderedmap/index.es.js ***! + \*********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +// ::- Persistent data structure representing an ordered mapping from +// strings to values, with some convenient update methods. +function OrderedMap(content) { + this.content = content; +} + +OrderedMap.prototype = { + constructor: OrderedMap, + + find: function(key) { + for (var i = 0; i < this.content.length; i += 2) + if (this.content[i] === key) return i + return -1 + }, + + // :: (string) → ?any + // Retrieve the value stored under `key`, or return undefined when + // no such key exists. + get: function(key) { + var found = this.find(key); + return found == -1 ? undefined : this.content[found + 1] + }, + + // :: (string, any, ?string) → OrderedMap + // Create a new map by replacing the value of `key` with a new + // value, or adding a binding to the end of the map. If `newKey` is + // given, the key of the binding will be replaced with that key. + update: function(key, value, newKey) { + var self = newKey && newKey != key ? this.remove(newKey) : this; + var found = self.find(key), content = self.content.slice(); + if (found == -1) { + content.push(newKey || key, value); + } else { + content[found + 1] = value; + if (newKey) content[found] = newKey; + } + return new OrderedMap(content) + }, + + // :: (string) → OrderedMap + // Return a map with the given key removed, if it existed. + remove: function(key) { + var found = this.find(key); + if (found == -1) return this + var content = this.content.slice(); + content.splice(found, 2); + return new OrderedMap(content) + }, + + // :: (string, any) → OrderedMap + // Add a new key to the start of the map. + addToStart: function(key, value) { + return new OrderedMap([key, value].concat(this.remove(key).content)) + }, + + // :: (string, any) → OrderedMap + // Add a new key to the end of the map. + addToEnd: function(key, value) { + var content = this.remove(key).content.slice(); + content.push(key, value); + return new OrderedMap(content) + }, + + // :: (string, string, any) → OrderedMap + // Add a key after the given key. If `place` is not found, the new + // key is added to the end. + addBefore: function(place, key, value) { + var without = this.remove(key), content = without.content.slice(); + var found = without.find(place); + content.splice(found == -1 ? content.length : found, 0, key, value); + return new OrderedMap(content) + }, + + // :: ((key: string, value: any)) + // Call the given function for each key/value pair in the map, in + // order. + forEach: function(f) { + for (var i = 0; i < this.content.length; i += 2) + f(this.content[i], this.content[i + 1]); + }, + + // :: (union) → OrderedMap + // Create a new map by prepending the keys in this map that don't + // appear in `map` before the keys in `map`. + prepend: function(map) { + map = OrderedMap.from(map); + if (!map.size) return this + return new OrderedMap(map.content.concat(this.subtract(map).content)) + }, + + // :: (union) → OrderedMap + // Create a new map by appending the keys in this map that don't + // appear in `map` after the keys in `map`. + append: function(map) { + map = OrderedMap.from(map); + if (!map.size) return this + return new OrderedMap(this.subtract(map).content.concat(map.content)) + }, + + // :: (union) → OrderedMap + // Create a map containing all the keys in this map that don't + // appear in `map`. + subtract: function(map) { + var result = this; + map = OrderedMap.from(map); + for (var i = 0; i < map.content.length; i += 2) + result = result.remove(map.content[i]); + return result + }, + + // :: number + // The amount of keys in this map. + get size() { + return this.content.length >> 1 + } +}; + +// :: (?union) → OrderedMap +// Return a map with the given content. If null, create an empty +// map. If given an ordered map, return that map itself. If given an +// object, create a map from the object's properties. +OrderedMap.from = function(value) { + if (value instanceof OrderedMap) return value + var content = []; + if (value) for (var prop in value) content.push(prop, value[prop]); + return new OrderedMap(content) +}; + +var orderedmap = OrderedMap; + +/* harmony default export */ __webpack_exports__["default"] = (orderedmap); + + /***/ }), /***/ "./node_modules/process/browser.js": @@ -2373,6 +4769,18257 @@ process.chdir = function (dir) { process.umask = function() { return 0; }; +/***/ }), + +/***/ "./node_modules/prosemirror-collab/dist/index.es.js": +/*!**********************************************************!*\ + !*** ./node_modules/prosemirror-collab/dist/index.es.js ***! + \**********************************************************/ +/*! exports provided: collab, getVersion, rebaseSteps, receiveTransaction, sendableSteps */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "collab", function() { return collab; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getVersion", function() { return getVersion; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "rebaseSteps", function() { return rebaseSteps; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "receiveTransaction", function() { return receiveTransaction; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "sendableSteps", function() { return sendableSteps; }); +/* harmony import */ var prosemirror_state__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! prosemirror-state */ "./node_modules/prosemirror-state/dist/index.es.js"); + + +var Rebaseable = function Rebaseable(step, inverted, origin) { + this.step = step; + this.inverted = inverted; + this.origin = origin; +}; + +// : ([Rebaseable], [Step], Transform) → [Rebaseable] +// Undo a given set of steps, apply a set of other steps, and then +// redo them. +function rebaseSteps(steps, over, transform) { + for (var i = steps.length - 1; i >= 0; i--) { transform.step(steps[i].inverted); } + for (var i$1 = 0; i$1 < over.length; i$1++) { transform.step(over[i$1]); } + var result = []; + for (var i$2 = 0, mapFrom = steps.length; i$2 < steps.length; i$2++) { + var mapped = steps[i$2].step.map(transform.mapping.slice(mapFrom)); + mapFrom--; + if (mapped && !transform.maybeStep(mapped).failed) { + transform.mapping.setMirror(mapFrom, transform.steps.length - 1); + result.push(new Rebaseable(mapped, mapped.invert(transform.docs[transform.docs.length - 1]), steps[i$2].origin)); + } + } + return result +} + +// This state field accumulates changes that have to be sent to the +// central authority in the collaborating group and makes it possible +// to integrate changes made by peers into our local document. It is +// defined by the plugin, and will be available as the `collab` field +// in the resulting editor state. +var CollabState = function CollabState(version, unconfirmed) { + // : number + // The version number of the last update received from the central + // authority. Starts at 0 or the value of the `version` property + // in the option object, for the editor's value when the option + // was enabled. + this.version = version; + + // : [Rebaseable] + // The local steps that havent been successfully sent to the + // server yet. + this.unconfirmed = unconfirmed; +}; + +function unconfirmedFrom(transform) { + var result = []; + for (var i = 0; i < transform.steps.length; i++) + { result.push(new Rebaseable(transform.steps[i], + transform.steps[i].invert(transform.docs[i]), + transform)); } + return result +} + +var collabKey = new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["PluginKey"]("collab"); + +// :: (?Object) → Plugin +// +// Creates a plugin that enables the collaborative editing framework +// for the editor. +// +// config::- An optional set of options +// +// version:: ?number +// The starting version number of the collaborative editing. +// Defaults to 0. +// +// clientID:: ?union +// This client's ID, used to distinguish its changes from those of +// other clients. Defaults to a random 32-bit number. +function collab(config) { + if ( config === void 0 ) config = {}; + + config = {version: config.version || 0, + clientID: config.clientID == null ? Math.floor(Math.random() * 0xFFFFFFFF) : config.clientID}; + + return new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["Plugin"]({ + key: collabKey, + + state: { + init: function () { return new CollabState(config.version, []); }, + apply: function apply(tr, collab) { + var newState = tr.getMeta(collabKey); + if (newState) + { return newState } + if (tr.docChanged) + { return new CollabState(collab.version, collab.unconfirmed.concat(unconfirmedFrom(tr))) } + return collab + } + }, + + config: config, + // This is used to notify the history plugin to not merge steps, + // so that the history can be rebased. + historyPreserveItems: true + }) +} + +// :: (state: EditorState, steps: [Step], clientIDs: [union], options: ?Object) → Transaction +// Create a transaction that represents a set of new steps received from +// the authority. Applying this transaction moves the state forward to +// adjust to the authority's view of the document. +// +// options::- Additional options. +// +// mapSelectionBackward:: ?boolean +// When enabled (the default is `false`), if the current selection +// is a [text selection](#state.TextSelection), its sides are +// mapped with a negative bias for this transaction, so that +// content inserted at the cursor ends up after the cursor. Users +// usually prefer this, but it isn't done by default for reasons +// of backwards compatibility. +function receiveTransaction(state, steps, clientIDs, options) { + // Pushes a set of steps (received from the central authority) into + // the editor state (which should have the collab plugin enabled). + // Will recognize its own changes, and confirm unconfirmed steps as + // appropriate. Remaining unconfirmed steps will be rebased over + // remote steps. + var collabState = collabKey.getState(state); + var version = collabState.version + steps.length; + var ourID = collabKey.get(state).spec.config.clientID; + + // Find out which prefix of the steps originated with us + var ours = 0; + while (ours < clientIDs.length && clientIDs[ours] == ourID) { ++ours; } + var unconfirmed = collabState.unconfirmed.slice(ours); + steps = ours ? steps.slice(ours) : steps; + + // If all steps originated with us, we're done. + if (!steps.length) + { return state.tr.setMeta(collabKey, new CollabState(version, unconfirmed)) } + + var nUnconfirmed = unconfirmed.length; + var tr = state.tr; + if (nUnconfirmed) { + unconfirmed = rebaseSteps(unconfirmed, steps, tr); + } else { + for (var i = 0; i < steps.length; i++) { tr.step(steps[i]); } + unconfirmed = []; + } + + var newCollabState = new CollabState(version, unconfirmed); + if (options && options.mapSelectionBackward && state.selection instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"]) { + tr.setSelection(prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"].between(tr.doc.resolve(tr.mapping.map(state.selection.anchor, -1)), + tr.doc.resolve(tr.mapping.map(state.selection.head, -1)), -1)); + tr.updated &= ~1; + } + return tr.setMeta("rebased", nUnconfirmed).setMeta("addToHistory", false).setMeta(collabKey, newCollabState) +} + +// :: (state: EditorState) → ?{version: number, steps: [Step], clientID: union, origins: [Transaction]} +// Provides data describing the editor's unconfirmed steps, which need +// to be sent to the central authority. Returns null when there is +// nothing to send. +// +// `origins` holds the _original_ transactions that produced each +// steps. This can be useful for looking up time stamps and other +// metadata for the steps, but note that the steps may have been +// rebased, whereas the origin transactions are still the old, +// unchanged objects. +function sendableSteps(state) { + var collabState = collabKey.getState(state); + if (collabState.unconfirmed.length == 0) { return null } + return { + version: collabState.version, + steps: collabState.unconfirmed.map(function (s) { return s.step; }), + clientID: collabKey.get(state).spec.config.clientID, + get origins() { return this._origins || (this._origins = collabState.unconfirmed.map(function (s) { return s.origin; })) } + } +} + +// :: (EditorState) → number +// Get the version up to which the collab plugin has synced with the +// central authority. +function getVersion(state) { + return collabKey.getState(state).version +} + + +//# sourceMappingURL=index.es.js.map + + +/***/ }), + +/***/ "./node_modules/prosemirror-commands/dist/index.es.js": +/*!************************************************************!*\ + !*** ./node_modules/prosemirror-commands/dist/index.es.js ***! + \************************************************************/ +/*! exports provided: autoJoin, baseKeymap, chainCommands, createParagraphNear, deleteSelection, exitCode, joinBackward, joinDown, joinForward, joinUp, lift, liftEmptyBlock, macBaseKeymap, newlineInCode, pcBaseKeymap, selectAll, selectNodeBackward, selectNodeForward, selectParentNode, setBlockType, splitBlock, splitBlockKeepMarks, toggleMark, wrapIn */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "autoJoin", function() { return autoJoin; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "baseKeymap", function() { return baseKeymap; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "chainCommands", function() { return chainCommands; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "createParagraphNear", function() { return createParagraphNear; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "deleteSelection", function() { return deleteSelection; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "exitCode", function() { return exitCode; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "joinBackward", function() { return joinBackward; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "joinDown", function() { return joinDown; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "joinForward", function() { return joinForward; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "joinUp", function() { return joinUp; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "lift", function() { return lift; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "liftEmptyBlock", function() { return liftEmptyBlock; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "macBaseKeymap", function() { return macBaseKeymap; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "newlineInCode", function() { return newlineInCode; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pcBaseKeymap", function() { return pcBaseKeymap; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectAll", function() { return selectAll; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectNodeBackward", function() { return selectNodeBackward; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectNodeForward", function() { return selectNodeForward; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectParentNode", function() { return selectParentNode; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setBlockType", function() { return setBlockType; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "splitBlock", function() { return splitBlock; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "splitBlockKeepMarks", function() { return splitBlockKeepMarks; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "toggleMark", function() { return toggleMark; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "wrapIn", function() { return wrapIn; }); +/* harmony import */ var prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! prosemirror-transform */ "./node_modules/prosemirror-transform/dist/index.es.js"); +/* harmony import */ var prosemirror_model__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! prosemirror-model */ "./node_modules/prosemirror-model/dist/index.es.js"); +/* harmony import */ var prosemirror_state__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! prosemirror-state */ "./node_modules/prosemirror-state/dist/index.es.js"); + + + + +// :: (EditorState, ?(tr: Transaction)) → bool +// Delete the selection, if there is one. +function deleteSelection(state, dispatch) { + if (state.selection.empty) { return false } + if (dispatch) { dispatch(state.tr.deleteSelection().scrollIntoView()); } + return true +} + +// :: (EditorState, ?(tr: Transaction), ?EditorView) → bool +// If the selection is empty and at the start of a textblock, try to +// reduce the distance between that block and the one before it—if +// there's a block directly before it that can be joined, join them. +// If not, try to move the selected block closer to the next one in +// the document structure by lifting it out of its parent or moving it +// into a parent of the previous block. Will use the view for accurate +// (bidi-aware) start-of-textblock detection if given. +function joinBackward(state, dispatch, view) { + var ref = state.selection; + var $cursor = ref.$cursor; + if (!$cursor || (view ? !view.endOfTextblock("backward", state) + : $cursor.parentOffset > 0)) + { return false } + + var $cut = findCutBefore($cursor); + + // If there is no node before this, try to lift + if (!$cut) { + var range = $cursor.blockRange(), target = range && Object(prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__["liftTarget"])(range); + if (target == null) { return false } + if (dispatch) { dispatch(state.tr.lift(range, target).scrollIntoView()); } + return true + } + + var before = $cut.nodeBefore; + // Apply the joining algorithm + if (!before.type.spec.isolating && deleteBarrier(state, $cut, dispatch)) + { return true } + + // If the node below has no content and the node above is + // selectable, delete the node below and select the one above. + if ($cursor.parent.content.size == 0 && + (textblockAt(before, "end") || prosemirror_state__WEBPACK_IMPORTED_MODULE_2__["NodeSelection"].isSelectable(before))) { + if (dispatch) { + var tr = state.tr.deleteRange($cursor.before(), $cursor.after()); + tr.setSelection(textblockAt(before, "end") ? prosemirror_state__WEBPACK_IMPORTED_MODULE_2__["Selection"].findFrom(tr.doc.resolve(tr.mapping.map($cut.pos, -1)), -1) + : prosemirror_state__WEBPACK_IMPORTED_MODULE_2__["NodeSelection"].create(tr.doc, $cut.pos - before.nodeSize)); + dispatch(tr.scrollIntoView()); + } + return true + } + + // If the node before is an atom, delete it + if (before.isAtom && $cut.depth == $cursor.depth - 1) { + if (dispatch) { dispatch(state.tr.delete($cut.pos - before.nodeSize, $cut.pos).scrollIntoView()); } + return true + } + + return false +} + +function textblockAt(node, side) { + for (; node; node = (side == "start" ? node.firstChild : node.lastChild)) + { if (node.isTextblock) { return true } } + return false +} + +// :: (EditorState, ?(tr: Transaction), ?EditorView) → bool +// When the selection is empty and at the start of a textblock, select +// the node before that textblock, if possible. This is intended to be +// bound to keys like backspace, after +// [`joinBackward`](#commands.joinBackward) or other deleting +// commands, as a fall-back behavior when the schema doesn't allow +// deletion at the selected point. +function selectNodeBackward(state, dispatch, view) { + var ref = state.selection; + var $cursor = ref.$cursor; + if (!$cursor || (view ? !view.endOfTextblock("backward", state) + : $cursor.parentOffset > 0)) + { return false } + + var $cut = findCutBefore($cursor), node = $cut && $cut.nodeBefore; + if (!node || !prosemirror_state__WEBPACK_IMPORTED_MODULE_2__["NodeSelection"].isSelectable(node)) { return false } + if (dispatch) + { dispatch(state.tr.setSelection(prosemirror_state__WEBPACK_IMPORTED_MODULE_2__["NodeSelection"].create(state.doc, $cut.pos - node.nodeSize)).scrollIntoView()); } + return true +} + +function findCutBefore($pos) { + if (!$pos.parent.type.spec.isolating) { for (var i = $pos.depth - 1; i >= 0; i--) { + if ($pos.index(i) > 0) { return $pos.doc.resolve($pos.before(i + 1)) } + if ($pos.node(i).type.spec.isolating) { break } + } } + return null +} + +// :: (EditorState, ?(tr: Transaction), ?EditorView) → bool +// If the selection is empty and the cursor is at the end of a +// textblock, try to reduce or remove the boundary between that block +// and the one after it, either by joining them or by moving the other +// block closer to this one in the tree structure. Will use the view +// for accurate start-of-textblock detection if given. +function joinForward(state, dispatch, view) { + var ref = state.selection; + var $cursor = ref.$cursor; + if (!$cursor || (view ? !view.endOfTextblock("forward", state) + : $cursor.parentOffset < $cursor.parent.content.size)) + { return false } + + var $cut = findCutAfter($cursor); + + // If there is no node after this, there's nothing to do + if (!$cut) { return false } + + var after = $cut.nodeAfter; + // Try the joining algorithm + if (deleteBarrier(state, $cut, dispatch)) { return true } + + // If the node above has no content and the node below is + // selectable, delete the node above and select the one below. + if ($cursor.parent.content.size == 0 && + (textblockAt(after, "start") || prosemirror_state__WEBPACK_IMPORTED_MODULE_2__["NodeSelection"].isSelectable(after))) { + if (dispatch) { + var tr = state.tr.deleteRange($cursor.before(), $cursor.after()); + tr.setSelection(textblockAt(after, "start") ? prosemirror_state__WEBPACK_IMPORTED_MODULE_2__["Selection"].findFrom(tr.doc.resolve(tr.mapping.map($cut.pos)), 1) + : prosemirror_state__WEBPACK_IMPORTED_MODULE_2__["NodeSelection"].create(tr.doc, tr.mapping.map($cut.pos))); + dispatch(tr.scrollIntoView()); + } + return true + } + + // If the next node is an atom, delete it + if (after.isAtom && $cut.depth == $cursor.depth - 1) { + if (dispatch) { dispatch(state.tr.delete($cut.pos, $cut.pos + after.nodeSize).scrollIntoView()); } + return true + } + + return false +} + +// :: (EditorState, ?(tr: Transaction), ?EditorView) → bool +// When the selection is empty and at the end of a textblock, select +// the node coming after that textblock, if possible. This is intended +// to be bound to keys like delete, after +// [`joinForward`](#commands.joinForward) and similar deleting +// commands, to provide a fall-back behavior when the schema doesn't +// allow deletion at the selected point. +function selectNodeForward(state, dispatch, view) { + var ref = state.selection; + var $cursor = ref.$cursor; + if (!$cursor || (view ? !view.endOfTextblock("forward", state) + : $cursor.parentOffset < $cursor.parent.content.size)) + { return false } + + var $cut = findCutAfter($cursor), node = $cut && $cut.nodeAfter; + if (!node || !prosemirror_state__WEBPACK_IMPORTED_MODULE_2__["NodeSelection"].isSelectable(node)) { return false } + if (dispatch) + { dispatch(state.tr.setSelection(prosemirror_state__WEBPACK_IMPORTED_MODULE_2__["NodeSelection"].create(state.doc, $cut.pos)).scrollIntoView()); } + return true +} + +function findCutAfter($pos) { + if (!$pos.parent.type.spec.isolating) { for (var i = $pos.depth - 1; i >= 0; i--) { + var parent = $pos.node(i); + if ($pos.index(i) + 1 < parent.childCount) { return $pos.doc.resolve($pos.after(i + 1)) } + if (parent.type.spec.isolating) { break } + } } + return null +} + +// :: (EditorState, ?(tr: Transaction)) → bool +// Join the selected block or, if there is a text selection, the +// closest ancestor block of the selection that can be joined, with +// the sibling above it. +function joinUp(state, dispatch) { + var sel = state.selection, nodeSel = sel instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_2__["NodeSelection"], point; + if (nodeSel) { + if (sel.node.isTextblock || !Object(prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__["canJoin"])(state.doc, sel.from)) { return false } + point = sel.from; + } else { + point = Object(prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__["joinPoint"])(state.doc, sel.from, -1); + if (point == null) { return false } + } + if (dispatch) { + var tr = state.tr.join(point); + if (nodeSel) { tr.setSelection(prosemirror_state__WEBPACK_IMPORTED_MODULE_2__["NodeSelection"].create(tr.doc, point - state.doc.resolve(point).nodeBefore.nodeSize)); } + dispatch(tr.scrollIntoView()); + } + return true +} + +// :: (EditorState, ?(tr: Transaction)) → bool +// Join the selected block, or the closest ancestor of the selection +// that can be joined, with the sibling after it. +function joinDown(state, dispatch) { + var sel = state.selection, point; + if (sel instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_2__["NodeSelection"]) { + if (sel.node.isTextblock || !Object(prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__["canJoin"])(state.doc, sel.to)) { return false } + point = sel.to; + } else { + point = Object(prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__["joinPoint"])(state.doc, sel.to, 1); + if (point == null) { return false } + } + if (dispatch) + { dispatch(state.tr.join(point).scrollIntoView()); } + return true +} + +// :: (EditorState, ?(tr: Transaction)) → bool +// Lift the selected block, or the closest ancestor block of the +// selection that can be lifted, out of its parent node. +function lift(state, dispatch) { + var ref = state.selection; + var $from = ref.$from; + var $to = ref.$to; + var range = $from.blockRange($to), target = range && Object(prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__["liftTarget"])(range); + if (target == null) { return false } + if (dispatch) { dispatch(state.tr.lift(range, target).scrollIntoView()); } + return true +} + +// :: (EditorState, ?(tr: Transaction)) → bool +// If the selection is in a node whose type has a truthy +// [`code`](#model.NodeSpec.code) property in its spec, replace the +// selection with a newline character. +function newlineInCode(state, dispatch) { + var ref = state.selection; + var $head = ref.$head; + var $anchor = ref.$anchor; + if (!$head.parent.type.spec.code || !$head.sameParent($anchor)) { return false } + if (dispatch) { dispatch(state.tr.insertText("\n").scrollIntoView()); } + return true +} + +// :: (EditorState, ?(tr: Transaction)) → bool +// When the selection is in a node with a truthy +// [`code`](#model.NodeSpec.code) property in its spec, create a +// default block after the code block, and move the cursor there. +function exitCode(state, dispatch) { + var ref = state.selection; + var $head = ref.$head; + var $anchor = ref.$anchor; + if (!$head.parent.type.spec.code || !$head.sameParent($anchor)) { return false } + var above = $head.node(-1), after = $head.indexAfter(-1), type = above.contentMatchAt(after).defaultType; + if (!above.canReplaceWith(after, after, type)) { return false } + if (dispatch) { + var pos = $head.after(), tr = state.tr.replaceWith(pos, pos, type.createAndFill()); + tr.setSelection(prosemirror_state__WEBPACK_IMPORTED_MODULE_2__["Selection"].near(tr.doc.resolve(pos), 1)); + dispatch(tr.scrollIntoView()); + } + return true +} + +// :: (EditorState, ?(tr: Transaction)) → bool +// If a block node is selected, create an empty paragraph before (if +// it is its parent's first child) or after it. +function createParagraphNear(state, dispatch) { + var ref = state.selection; + var $from = ref.$from; + var $to = ref.$to; + if ($from.parent.inlineContent || $to.parent.inlineContent) { return false } + var type = $from.parent.contentMatchAt($to.indexAfter()).defaultType; + if (!type || !type.isTextblock) { return false } + if (dispatch) { + var side = (!$from.parentOffset && $to.index() < $to.parent.childCount ? $from : $to).pos; + var tr = state.tr.insert(side, type.createAndFill()); + tr.setSelection(prosemirror_state__WEBPACK_IMPORTED_MODULE_2__["TextSelection"].create(tr.doc, side + 1)); + dispatch(tr.scrollIntoView()); + } + return true +} + +// :: (EditorState, ?(tr: Transaction)) → bool +// If the cursor is in an empty textblock that can be lifted, lift the +// block. +function liftEmptyBlock(state, dispatch) { + var ref = state.selection; + var $cursor = ref.$cursor; + if (!$cursor || $cursor.parent.content.size) { return false } + if ($cursor.depth > 1 && $cursor.after() != $cursor.end(-1)) { + var before = $cursor.before(); + if (Object(prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__["canSplit"])(state.doc, before)) { + if (dispatch) { dispatch(state.tr.split(before).scrollIntoView()); } + return true + } + } + var range = $cursor.blockRange(), target = range && Object(prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__["liftTarget"])(range); + if (target == null) { return false } + if (dispatch) { dispatch(state.tr.lift(range, target).scrollIntoView()); } + return true +} + +// :: (EditorState, ?(tr: Transaction)) → bool +// Split the parent block of the selection. If the selection is a text +// selection, also delete its content. +function splitBlock(state, dispatch) { + var ref = state.selection; + var $from = ref.$from; + var $to = ref.$to; + if (state.selection instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_2__["NodeSelection"] && state.selection.node.isBlock) { + if (!$from.parentOffset || !Object(prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__["canSplit"])(state.doc, $from.pos)) { return false } + if (dispatch) { dispatch(state.tr.split($from.pos).scrollIntoView()); } + return true + } + + if (!$from.parent.isBlock) { return false } + + if (dispatch) { + var atEnd = $to.parentOffset == $to.parent.content.size; + var tr = state.tr; + if (state.selection instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_2__["TextSelection"]) { tr.deleteSelection(); } + var deflt = $from.depth == 0 ? null : $from.node(-1).contentMatchAt($from.indexAfter(-1)).defaultType; + var types = atEnd && deflt ? [{type: deflt}] : null; + var can = Object(prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__["canSplit"])(tr.doc, tr.mapping.map($from.pos), 1, types); + if (!types && !can && Object(prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__["canSplit"])(tr.doc, tr.mapping.map($from.pos), 1, deflt && [{type: deflt}])) { + types = [{type: deflt}]; + can = true; + } + if (can) { + tr.split(tr.mapping.map($from.pos), 1, types); + if (!atEnd && !$from.parentOffset && $from.parent.type != deflt && + $from.node(-1).canReplace($from.index(-1), $from.indexAfter(-1), prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(deflt.create(), $from.parent))) + { tr.setNodeMarkup(tr.mapping.map($from.before()), deflt); } + } + dispatch(tr.scrollIntoView()); + } + return true +} + +// :: (EditorState, ?(tr: Transaction)) → bool +// Acts like [`splitBlock`](#commands.splitBlock), but without +// resetting the set of active marks at the cursor. +function splitBlockKeepMarks(state, dispatch) { + return splitBlock(state, dispatch && (function (tr) { + var marks = state.storedMarks || (state.selection.$to.parentOffset && state.selection.$from.marks()); + if (marks) { tr.ensureMarks(marks); } + dispatch(tr); + })) +} + +// :: (EditorState, ?(tr: Transaction)) → bool +// Move the selection to the node wrapping the current selection, if +// any. (Will not select the document node.) +function selectParentNode(state, dispatch) { + var ref = state.selection; + var $from = ref.$from; + var to = ref.to; + var pos; + var same = $from.sharedDepth(to); + if (same == 0) { return false } + pos = $from.before(same); + if (dispatch) { dispatch(state.tr.setSelection(prosemirror_state__WEBPACK_IMPORTED_MODULE_2__["NodeSelection"].create(state.doc, pos))); } + return true +} + +// :: (EditorState, ?(tr: Transaction)) → bool +// Select the whole document. +function selectAll(state, dispatch) { + if (dispatch) { dispatch(state.tr.setSelection(new prosemirror_state__WEBPACK_IMPORTED_MODULE_2__["AllSelection"](state.doc))); } + return true +} + +function joinMaybeClear(state, $pos, dispatch) { + var before = $pos.nodeBefore, after = $pos.nodeAfter, index = $pos.index(); + if (!before || !after || !before.type.compatibleContent(after.type)) { return false } + if (!before.content.size && $pos.parent.canReplace(index - 1, index)) { + if (dispatch) { dispatch(state.tr.delete($pos.pos - before.nodeSize, $pos.pos).scrollIntoView()); } + return true + } + if (!$pos.parent.canReplace(index, index + 1) || !(after.isTextblock || Object(prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__["canJoin"])(state.doc, $pos.pos))) + { return false } + if (dispatch) + { dispatch(state.tr + .clearIncompatible($pos.pos, before.type, before.contentMatchAt(before.childCount)) + .join($pos.pos) + .scrollIntoView()); } + return true +} + +function deleteBarrier(state, $cut, dispatch) { + var before = $cut.nodeBefore, after = $cut.nodeAfter, conn, match; + if (before.type.spec.isolating || after.type.spec.isolating) { return false } + if (joinMaybeClear(state, $cut, dispatch)) { return true } + + if ($cut.parent.canReplace($cut.index(), $cut.index() + 1) && + (conn = (match = before.contentMatchAt(before.childCount)).findWrapping(after.type)) && + match.matchType(conn[0] || after.type).validEnd) { + if (dispatch) { + var end = $cut.pos + after.nodeSize, wrap = prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].empty; + for (var i = conn.length - 1; i >= 0; i--) + { wrap = prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(conn[i].create(null, wrap)); } + wrap = prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(before.copy(wrap)); + var tr = state.tr.step(new prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__["ReplaceAroundStep"]($cut.pos - 1, end, $cut.pos, end, new prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Slice"](wrap, 1, 0), conn.length, true)); + var joinAt = end + 2 * conn.length; + if (Object(prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__["canJoin"])(tr.doc, joinAt)) { tr.join(joinAt); } + dispatch(tr.scrollIntoView()); + } + return true + } + + var selAfter = prosemirror_state__WEBPACK_IMPORTED_MODULE_2__["Selection"].findFrom($cut, 1); + var range = selAfter && selAfter.$from.blockRange(selAfter.$to), target = range && Object(prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__["liftTarget"])(range); + if (target != null && target >= $cut.depth) { + if (dispatch) { dispatch(state.tr.lift(range, target).scrollIntoView()); } + return true + } + + return false +} + +// Parameterized commands + +// :: (NodeType, ?Object) → (state: EditorState, dispatch: ?(tr: Transaction)) → bool +// Wrap the selection in a node of the given type with the given +// attributes. +function wrapIn(nodeType, attrs) { + return function(state, dispatch) { + var ref = state.selection; + var $from = ref.$from; + var $to = ref.$to; + var range = $from.blockRange($to), wrapping = range && Object(prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__["findWrapping"])(range, nodeType, attrs); + if (!wrapping) { return false } + if (dispatch) { dispatch(state.tr.wrap(range, wrapping).scrollIntoView()); } + return true + } +} + +// :: (NodeType, ?Object) → (state: EditorState, dispatch: ?(tr: Transaction)) → bool +// Returns a command that tries to set the selected textblocks to the +// given node type with the given attributes. +function setBlockType(nodeType, attrs) { + return function(state, dispatch) { + var ref = state.selection; + var from = ref.from; + var to = ref.to; + var applicable = false; + state.doc.nodesBetween(from, to, function (node, pos) { + if (applicable) { return false } + if (!node.isTextblock || node.hasMarkup(nodeType, attrs)) { return } + if (node.type == nodeType) { + applicable = true; + } else { + var $pos = state.doc.resolve(pos), index = $pos.index(); + applicable = $pos.parent.canReplaceWith(index, index + 1, nodeType); + } + }); + if (!applicable) { return false } + if (dispatch) { dispatch(state.tr.setBlockType(from, to, nodeType, attrs).scrollIntoView()); } + return true + } +} + +function markApplies(doc, ranges, type) { + var loop = function ( i ) { + var ref = ranges[i]; + var $from = ref.$from; + var $to = ref.$to; + var can = $from.depth == 0 ? doc.type.allowsMarkType(type) : false; + doc.nodesBetween($from.pos, $to.pos, function (node) { + if (can) { return false } + can = node.inlineContent && node.type.allowsMarkType(type); + }); + if (can) { return { v: true } } + }; + + for (var i = 0; i < ranges.length; i++) { + var returned = loop( i ); + + if ( returned ) return returned.v; + } + return false +} + +// :: (MarkType, ?Object) → (state: EditorState, dispatch: ?(tr: Transaction)) → bool +// Create a command function that toggles the given mark with the +// given attributes. Will return `false` when the current selection +// doesn't support that mark. This will remove the mark if any marks +// of that type exist in the selection, or add it otherwise. If the +// selection is empty, this applies to the [stored +// marks](#state.EditorState.storedMarks) instead of a range of the +// document. +function toggleMark(markType, attrs) { + return function(state, dispatch) { + var ref = state.selection; + var empty = ref.empty; + var $cursor = ref.$cursor; + var ranges = ref.ranges; + if ((empty && !$cursor) || !markApplies(state.doc, ranges, markType)) { return false } + if (dispatch) { + if ($cursor) { + if (markType.isInSet(state.storedMarks || $cursor.marks())) + { dispatch(state.tr.removeStoredMark(markType)); } + else + { dispatch(state.tr.addStoredMark(markType.create(attrs))); } + } else { + var has = false, tr = state.tr; + for (var i = 0; !has && i < ranges.length; i++) { + var ref$1 = ranges[i]; + var $from = ref$1.$from; + var $to = ref$1.$to; + has = state.doc.rangeHasMark($from.pos, $to.pos, markType); + } + for (var i$1 = 0; i$1 < ranges.length; i$1++) { + var ref$2 = ranges[i$1]; + var $from$1 = ref$2.$from; + var $to$1 = ref$2.$to; + if (has) { tr.removeMark($from$1.pos, $to$1.pos, markType); } + else { tr.addMark($from$1.pos, $to$1.pos, markType.create(attrs)); } + } + dispatch(tr.scrollIntoView()); + } + } + return true + } +} + +function wrapDispatchForJoin(dispatch, isJoinable) { + return function (tr) { + if (!tr.isGeneric) { return dispatch(tr) } + + var ranges = []; + for (var i = 0; i < tr.mapping.maps.length; i++) { + var map = tr.mapping.maps[i]; + for (var j = 0; j < ranges.length; j++) + { ranges[j] = map.map(ranges[j]); } + map.forEach(function (_s, _e, from, to) { return ranges.push(from, to); }); + } + + // Figure out which joinable points exist inside those ranges, + // by checking all node boundaries in their parent nodes. + var joinable = []; + for (var i$1 = 0; i$1 < ranges.length; i$1 += 2) { + var from = ranges[i$1], to = ranges[i$1 + 1]; + var $from = tr.doc.resolve(from), depth = $from.sharedDepth(to), parent = $from.node(depth); + for (var index = $from.indexAfter(depth), pos = $from.after(depth + 1); pos <= to; ++index) { + var after = parent.maybeChild(index); + if (!after) { break } + if (index && joinable.indexOf(pos) == -1) { + var before = parent.child(index - 1); + if (before.type == after.type && isJoinable(before, after)) + { joinable.push(pos); } + } + pos += after.nodeSize; + } + } + // Join the joinable points + joinable.sort(function (a, b) { return a - b; }); + for (var i$2 = joinable.length - 1; i$2 >= 0; i$2--) { + if (Object(prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__["canJoin"])(tr.doc, joinable[i$2])) { tr.join(joinable[i$2]); } + } + dispatch(tr); + } +} + +// :: ((state: EditorState, ?(tr: Transaction)) → bool, union<(before: Node, after: Node) → bool, [string]>) → (state: EditorState, ?(tr: Transaction)) → bool +// Wrap a command so that, when it produces a transform that causes +// two joinable nodes to end up next to each other, those are joined. +// Nodes are considered joinable when they are of the same type and +// when the `isJoinable` predicate returns true for them or, if an +// array of strings was passed, if their node type name is in that +// array. +function autoJoin(command, isJoinable) { + if (Array.isArray(isJoinable)) { + var types = isJoinable; + isJoinable = function (node) { return types.indexOf(node.type.name) > -1; }; + } + return function (state, dispatch) { return command(state, dispatch && wrapDispatchForJoin(dispatch, isJoinable)); } +} + +// :: (...[(EditorState, ?(tr: Transaction), ?EditorView) → bool]) → (EditorState, ?(tr: Transaction), ?EditorView) → bool +// Combine a number of command functions into a single function (which +// calls them one by one until one returns true). +function chainCommands() { + var commands = [], len = arguments.length; + while ( len-- ) commands[ len ] = arguments[ len ]; + + return function(state, dispatch, view) { + for (var i = 0; i < commands.length; i++) + { if (commands[i](state, dispatch, view)) { return true } } + return false + } +} + +var backspace = chainCommands(deleteSelection, joinBackward, selectNodeBackward); +var del = chainCommands(deleteSelection, joinForward, selectNodeForward); + +// :: Object +// A basic keymap containing bindings not specific to any schema. +// Binds the following keys (when multiple commands are listed, they +// are chained with [`chainCommands`](#commands.chainCommands)): +// +// * **Enter** to `newlineInCode`, `createParagraphNear`, `liftEmptyBlock`, `splitBlock` +// * **Mod-Enter** to `exitCode` +// * **Backspace** and **Mod-Backspace** to `deleteSelection`, `joinBackward`, `selectNodeBackward` +// * **Delete** and **Mod-Delete** to `deleteSelection`, `joinForward`, `selectNodeForward` +// * **Mod-Delete** to `deleteSelection`, `joinForward`, `selectNodeForward` +// * **Mod-a** to `selectAll` +var pcBaseKeymap = { + "Enter": chainCommands(newlineInCode, createParagraphNear, liftEmptyBlock, splitBlock), + "Mod-Enter": exitCode, + "Backspace": backspace, + "Mod-Backspace": backspace, + "Delete": del, + "Mod-Delete": del, + "Mod-a": selectAll +}; + +// :: Object +// A copy of `pcBaseKeymap` that also binds **Ctrl-h** like Backspace, +// **Ctrl-d** like Delete, **Alt-Backspace** like Ctrl-Backspace, and +// **Ctrl-Alt-Backspace**, **Alt-Delete**, and **Alt-d** like +// Ctrl-Delete. +var macBaseKeymap = { + "Ctrl-h": pcBaseKeymap["Backspace"], + "Alt-Backspace": pcBaseKeymap["Mod-Backspace"], + "Ctrl-d": pcBaseKeymap["Delete"], + "Ctrl-Alt-Backspace": pcBaseKeymap["Mod-Delete"], + "Alt-Delete": pcBaseKeymap["Mod-Delete"], + "Alt-d": pcBaseKeymap["Mod-Delete"] +}; +for (var key in pcBaseKeymap) { macBaseKeymap[key] = pcBaseKeymap[key]; } + +// declare global: os, navigator +var mac = typeof navigator != "undefined" ? /Mac/.test(navigator.platform) + : typeof os != "undefined" ? os.platform() == "darwin" : false; + +// :: Object +// Depending on the detected platform, this will hold +// [`pcBasekeymap`](#commands.pcBaseKeymap) or +// [`macBaseKeymap`](#commands.macBaseKeymap). +var baseKeymap = mac ? macBaseKeymap : pcBaseKeymap; + + +//# sourceMappingURL=index.es.js.map + + +/***/ }), + +/***/ "./node_modules/prosemirror-dropcursor/dist/index.es.js": +/*!**************************************************************!*\ + !*** ./node_modules/prosemirror-dropcursor/dist/index.es.js ***! + \**************************************************************/ +/*! exports provided: dropCursor */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "dropCursor", function() { return dropCursor; }); +/* harmony import */ var prosemirror_state__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! prosemirror-state */ "./node_modules/prosemirror-state/dist/index.es.js"); +/* harmony import */ var prosemirror_transform__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! prosemirror-transform */ "./node_modules/prosemirror-transform/dist/index.es.js"); + + + +// :: (options: ?Object) → Plugin +// Create a plugin that, when added to a ProseMirror instance, +// causes a decoration to show up at the drop position when something +// is dragged over the editor. +// +// options::- These options are supported: +// +// color:: ?string +// The color of the cursor. Defaults to `black`. +// +// width:: ?number +// The precise width of the cursor in pixels. Defaults to 1. +// +// class:: ?string +// A CSS class name to add to the cursor element. +function dropCursor(options) { + if ( options === void 0 ) options = {}; + + return new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["Plugin"]({ + view: function view(editorView) { return new DropCursorView(editorView, options) } + }) +} + +var DropCursorView = function DropCursorView(editorView, options) { + var this$1 = this; + + this.editorView = editorView; + this.width = options.width || 1; + this.color = options.color || "black"; + this.class = options.class; + this.cursorPos = null; + this.element = null; + this.timeout = null; + + this.handlers = ["dragover", "dragend", "drop", "dragleave"].map(function (name) { + var handler = function (e) { return this$1[name](e); }; + editorView.dom.addEventListener(name, handler); + return {name: name, handler: handler} + }); +}; + +DropCursorView.prototype.destroy = function destroy () { + var this$1 = this; + + this.handlers.forEach(function (ref) { + var name = ref.name; + var handler = ref.handler; + + return this$1.editorView.dom.removeEventListener(name, handler); + }); +}; + +DropCursorView.prototype.update = function update (editorView, prevState) { + if (this.cursorPos != null && prevState.doc != editorView.state.doc) { this.updateOverlay(); } +}; + +DropCursorView.prototype.setCursor = function setCursor (pos) { + if (pos == this.cursorPos) { return } + this.cursorPos = pos; + if (pos == null) { + this.element.parentNode.removeChild(this.element); + this.element = null; + } else { + this.updateOverlay(); + } +}; + +DropCursorView.prototype.updateOverlay = function updateOverlay () { + var $pos = this.editorView.state.doc.resolve(this.cursorPos), rect; + if (!$pos.parent.inlineContent) { + var before = $pos.nodeBefore, after = $pos.nodeAfter; + if (before || after) { + var nodeRect = this.editorView.nodeDOM(this.cursorPos - (before ?before.nodeSize : 0)).getBoundingClientRect(); + var top = before ? nodeRect.bottom : nodeRect.top; + if (before && after) + { top = (top + this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top) / 2; } + rect = {left: nodeRect.left, right: nodeRect.right, top: top - this.width / 2, bottom: top + this.width / 2}; + } + } + if (!rect) { + var coords = this.editorView.coordsAtPos(this.cursorPos); + rect = {left: coords.left - this.width / 2, right: coords.left + this.width / 2, top: coords.top, bottom: coords.bottom}; + } + + var parent = this.editorView.dom.offsetParent; + if (!this.element) { + this.element = parent.appendChild(document.createElement("div")); + if (this.class) { this.element.className = this.class; } + this.element.style.cssText = "position: absolute; z-index: 50; pointer-events: none; background-color: " + this.color; + } + var parentRect = !parent || parent == document.body && getComputedStyle(parent).position == "static" + ? {left: -pageXOffset, top: -pageYOffset} : parent.getBoundingClientRect(); + this.element.style.left = (rect.left - parentRect.left) + "px"; + this.element.style.top = (rect.top - parentRect.top) + "px"; + this.element.style.width = (rect.right - rect.left) + "px"; + this.element.style.height = (rect.bottom - rect.top) + "px"; +}; + +DropCursorView.prototype.scheduleRemoval = function scheduleRemoval (timeout) { + var this$1 = this; + + clearTimeout(this.timeout); + this.timeout = setTimeout(function () { return this$1.setCursor(null); }, timeout); +}; + +DropCursorView.prototype.dragover = function dragover (event) { + if (!this.editorView.editable) { return } + var pos = this.editorView.posAtCoords({left: event.clientX, top: event.clientY}); + if (pos) { + var target = pos.pos; + if (this.editorView.dragging && this.editorView.dragging.slice) { + target = Object(prosemirror_transform__WEBPACK_IMPORTED_MODULE_1__["dropPoint"])(this.editorView.state.doc, target, this.editorView.dragging.slice); + if (target == null) { target = pos.pos; } + } + this.setCursor(target); + this.scheduleRemoval(5000); + } +}; + +DropCursorView.prototype.dragend = function dragend () { + this.scheduleRemoval(20); +}; + +DropCursorView.prototype.drop = function drop () { + this.scheduleRemoval(20); +}; + +DropCursorView.prototype.dragleave = function dragleave (event) { + if (event.target == this.editorView.dom || !this.editorView.dom.contains(event.relatedTarget)) + { this.setCursor(null); } +}; + + +//# sourceMappingURL=index.es.js.map + + +/***/ }), + +/***/ "./node_modules/prosemirror-gapcursor/dist/index.es.js": +/*!*************************************************************!*\ + !*** ./node_modules/prosemirror-gapcursor/dist/index.es.js ***! + \*************************************************************/ +/*! exports provided: GapCursor, gapCursor */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GapCursor", function() { return GapCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "gapCursor", function() { return gapCursor; }); +/* harmony import */ var prosemirror_keymap__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! prosemirror-keymap */ "./node_modules/prosemirror-keymap/dist/index.es.js"); +/* harmony import */ var prosemirror_state__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! prosemirror-state */ "./node_modules/prosemirror-state/dist/index.es.js"); +/* harmony import */ var prosemirror_view__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! prosemirror-view */ "./node_modules/prosemirror-view/dist/index.es.js"); +/* harmony import */ var prosemirror_model__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! prosemirror-model */ "./node_modules/prosemirror-model/dist/index.es.js"); + + + + + +// ::- Gap cursor selections are represented using this class. Its +// `$anchor` and `$head` properties both point at the cursor position. +var GapCursor = /*@__PURE__*/(function (Selection) { + function GapCursor($pos) { + Selection.call(this, $pos, $pos); + } + + if ( Selection ) GapCursor.__proto__ = Selection; + GapCursor.prototype = Object.create( Selection && Selection.prototype ); + GapCursor.prototype.constructor = GapCursor; + + GapCursor.prototype.map = function map (doc, mapping) { + var $pos = doc.resolve(mapping.map(this.head)); + return GapCursor.valid($pos) ? new GapCursor($pos) : Selection.near($pos) + }; + + GapCursor.prototype.content = function content () { return prosemirror_model__WEBPACK_IMPORTED_MODULE_3__["Slice"].empty }; + + GapCursor.prototype.eq = function eq (other) { + return other instanceof GapCursor && other.head == this.head + }; + + GapCursor.prototype.toJSON = function toJSON () { + return {type: "gapcursor", pos: this.head} + }; + + GapCursor.fromJSON = function fromJSON (doc, json) { + if (typeof json.pos != "number") { throw new RangeError("Invalid input for GapCursor.fromJSON") } + return new GapCursor(doc.resolve(json.pos)) + }; + + GapCursor.prototype.getBookmark = function getBookmark () { return new GapBookmark(this.anchor) }; + + GapCursor.valid = function valid ($pos) { + var parent = $pos.parent; + if (parent.isTextblock || !closedBefore($pos) || !closedAfter($pos)) { return false } + var override = parent.type.spec.allowGapCursor; + if (override != null) { return override } + var deflt = parent.contentMatchAt($pos.index()).defaultType; + return deflt && deflt.isTextblock + }; + + GapCursor.findFrom = function findFrom ($pos, dir, mustMove) { + if (!mustMove && GapCursor.valid($pos)) { return $pos } + + var pos = $pos.pos, next = null; + // Scan up from this position + for (var d = $pos.depth;; d--) { + var parent = $pos.node(d); + if (dir > 0 ? $pos.indexAfter(d) < parent.childCount : $pos.index(d) > 0) { + next = parent.maybeChild(dir > 0 ? $pos.indexAfter(d) : $pos.index(d) - 1); + break + } else if (d == 0) { + return null + } + pos += dir; + var $cur = $pos.doc.resolve(pos); + if (GapCursor.valid($cur)) { return $cur } + } + + // And then down into the next node + for (;;) { + next = dir > 0 ? next.firstChild : next.lastChild; + if (!next) { break } + pos += dir; + var $cur$1 = $pos.doc.resolve(pos); + if (GapCursor.valid($cur$1)) { return $cur$1 } + } + + return null + }; + + return GapCursor; +}(prosemirror_state__WEBPACK_IMPORTED_MODULE_1__["Selection"])); + +GapCursor.prototype.visible = false; + +prosemirror_state__WEBPACK_IMPORTED_MODULE_1__["Selection"].jsonID("gapcursor", GapCursor); + +var GapBookmark = function GapBookmark(pos) { + this.pos = pos; +}; +GapBookmark.prototype.map = function map (mapping) { + return new GapBookmark(mapping.map(this.pos)) +}; +GapBookmark.prototype.resolve = function resolve (doc) { + var $pos = doc.resolve(this.pos); + return GapCursor.valid($pos) ? new GapCursor($pos) : prosemirror_state__WEBPACK_IMPORTED_MODULE_1__["Selection"].near($pos) +}; + +function closedBefore($pos) { + for (var d = $pos.depth; d >= 0; d--) { + var index = $pos.index(d); + // At the start of this parent, look at next one + if (index == 0) { continue } + // See if the node before (or its first ancestor) is closed + for (var before = $pos.node(d).child(index - 1);; before = before.lastChild) { + if ((before.childCount == 0 && !before.inlineContent) || before.isAtom || before.type.spec.isolating) { return true } + if (before.inlineContent) { return false } + } + } + // Hit start of document + return true +} + +function closedAfter($pos) { + for (var d = $pos.depth; d >= 0; d--) { + var index = $pos.indexAfter(d), parent = $pos.node(d); + if (index == parent.childCount) { continue } + for (var after = parent.child(index);; after = after.firstChild) { + if ((after.childCount == 0 && !after.inlineContent) || after.isAtom || after.type.spec.isolating) { return true } + if (after.inlineContent) { return false } + } + } + return true +} + +// :: () → Plugin +// Create a gap cursor plugin. When enabled, this will capture clicks +// near and arrow-key-motion past places that don't have a normally +// selectable position nearby, and create a gap cursor selection for +// them. The cursor is drawn as an element with class +// `ProseMirror-gapcursor`. You can either include +// `style/gapcursor.css` from the package's directory or add your own +// styles to make it visible. +var gapCursor = function() { + return new prosemirror_state__WEBPACK_IMPORTED_MODULE_1__["Plugin"]({ + props: { + decorations: drawGapCursor, + + createSelectionBetween: function createSelectionBetween(_view, $anchor, $head) { + if ($anchor.pos == $head.pos && GapCursor.valid($head)) { return new GapCursor($head) } + }, + + handleClick: handleClick, + handleKeyDown: handleKeyDown + } + }) +}; + +var handleKeyDown = Object(prosemirror_keymap__WEBPACK_IMPORTED_MODULE_0__["keydownHandler"])({ + "ArrowLeft": arrow("horiz", -1), + "ArrowRight": arrow("horiz", 1), + "ArrowUp": arrow("vert", -1), + "ArrowDown": arrow("vert", 1) +}); + +function arrow(axis, dir) { + var dirStr = axis == "vert" ? (dir > 0 ? "down" : "up") : (dir > 0 ? "right" : "left"); + return function(state, dispatch, view) { + var sel = state.selection; + var $start = dir > 0 ? sel.$to : sel.$from, mustMove = sel.empty; + if (sel instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_1__["TextSelection"]) { + if (!view.endOfTextblock(dirStr)) { return false } + mustMove = false; + $start = state.doc.resolve(dir > 0 ? $start.after() : $start.before()); + } + var $found = GapCursor.findFrom($start, dir, mustMove); + if (!$found) { return false } + if (dispatch) { dispatch(state.tr.setSelection(new GapCursor($found))); } + return true + } +} + +function handleClick(view, pos, event) { + if (!view.editable) { return false } + var $pos = view.state.doc.resolve(pos); + if (!GapCursor.valid($pos)) { return false } + var ref = view.posAtCoords({left: event.clientX, top: event.clientY}); + var inside = ref.inside; + if (inside > -1 && prosemirror_state__WEBPACK_IMPORTED_MODULE_1__["NodeSelection"].isSelectable(view.state.doc.nodeAt(inside))) { return false } + view.dispatch(view.state.tr.setSelection(new GapCursor($pos))); + return true +} + +function drawGapCursor(state) { + if (!(state.selection instanceof GapCursor)) { return null } + var node = document.createElement("div"); + node.className = "ProseMirror-gapcursor"; + return prosemirror_view__WEBPACK_IMPORTED_MODULE_2__["DecorationSet"].create(state.doc, [prosemirror_view__WEBPACK_IMPORTED_MODULE_2__["Decoration"].widget(state.selection.head, node, {key: "gapcursor"})]) +} + + +//# sourceMappingURL=index.es.js.map + + +/***/ }), + +/***/ "./node_modules/prosemirror-history/dist/index.es.js": +/*!***********************************************************!*\ + !*** ./node_modules/prosemirror-history/dist/index.es.js ***! + \***********************************************************/ +/*! exports provided: HistoryState, closeHistory, history, redo, redoDepth, undo, undoDepth */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "HistoryState", function() { return HistoryState; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "closeHistory", function() { return closeHistory; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "history", function() { return history; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "redo", function() { return redo; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "redoDepth", function() { return redoDepth; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "undo", function() { return undo; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "undoDepth", function() { return undoDepth; }); +/* harmony import */ var rope_sequence__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! rope-sequence */ "./node_modules/rope-sequence/dist/index.es.js"); +/* harmony import */ var prosemirror_transform__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! prosemirror-transform */ "./node_modules/prosemirror-transform/dist/index.es.js"); +/* harmony import */ var prosemirror_state__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! prosemirror-state */ "./node_modules/prosemirror-state/dist/index.es.js"); + + + + +// ProseMirror's history isn't simply a way to roll back to a previous +// state, because ProseMirror supports applying changes without adding +// them to the history (for example during collaboration). +// +// To this end, each 'Branch' (one for the undo history and one for +// the redo history) keeps an array of 'Items', which can optionally +// hold a step (an actual undoable change), and always hold a position +// map (which is needed to move changes below them to apply to the +// current document). +// +// An item that has both a step and a selection bookmark is the start +// of an 'event' — a group of changes that will be undone or redone at +// once. (It stores only the bookmark, since that way we don't have to +// provide a document until the selection is actually applied, which +// is useful when compressing.) + +// Used to schedule history compression +var max_empty_items = 500; + +var Branch = function Branch(items, eventCount) { + this.items = items; + this.eventCount = eventCount; +}; + +// : (EditorState, bool) → ?{transform: Transform, selection: ?SelectionBookmark, remaining: Branch} +// Pop the latest event off the branch's history and apply it +// to a document transform. +Branch.prototype.popEvent = function popEvent (state, preserveItems) { + var this$1 = this; + + if (this.eventCount == 0) { return null } + + var end = this.items.length; + for (;; end--) { + var next = this.items.get(end - 1); + if (next.selection) { --end; break } + } + + var remap, mapFrom; + if (preserveItems) { + remap = this.remapping(end, this.items.length); + mapFrom = remap.maps.length; + } + var transform = state.tr; + var selection, remaining; + var addAfter = [], addBefore = []; + + this.items.forEach(function (item, i) { + if (!item.step) { + if (!remap) { + remap = this$1.remapping(end, i + 1); + mapFrom = remap.maps.length; + } + mapFrom--; + addBefore.push(item); + return + } + + if (remap) { + addBefore.push(new Item(item.map)); + var step = item.step.map(remap.slice(mapFrom)), map; + + if (step && transform.maybeStep(step).doc) { + map = transform.mapping.maps[transform.mapping.maps.length - 1]; + addAfter.push(new Item(map, null, null, addAfter.length + addBefore.length)); + } + mapFrom--; + if (map) { remap.appendMap(map, mapFrom); } + } else { + transform.maybeStep(item.step); + } + + if (item.selection) { + selection = remap ? item.selection.map(remap.slice(mapFrom)) : item.selection; + remaining = new Branch(this$1.items.slice(0, end).append(addBefore.reverse().concat(addAfter)), this$1.eventCount - 1); + return false + } + }, this.items.length, 0); + + return {remaining: remaining, transform: transform, selection: selection} +}; + +// : (Transform, ?SelectionBookmark, Object) → Branch +// Create a new branch with the given transform added. +Branch.prototype.addTransform = function addTransform (transform, selection, histOptions, preserveItems) { + var newItems = [], eventCount = this.eventCount; + var oldItems = this.items, lastItem = !preserveItems && oldItems.length ? oldItems.get(oldItems.length - 1) : null; + + for (var i = 0; i < transform.steps.length; i++) { + var step = transform.steps[i].invert(transform.docs[i]); + var item = new Item(transform.mapping.maps[i], step, selection), merged = (void 0); + if (merged = lastItem && lastItem.merge(item)) { + item = merged; + if (i) { newItems.pop(); } + else { oldItems = oldItems.slice(0, oldItems.length - 1); } + } + newItems.push(item); + if (selection) { + eventCount++; + selection = null; + } + if (!preserveItems) { lastItem = item; } + } + var overflow = eventCount - histOptions.depth; + if (overflow > DEPTH_OVERFLOW) { + oldItems = cutOffEvents(oldItems, overflow); + eventCount -= overflow; + } + return new Branch(oldItems.append(newItems), eventCount) +}; + +Branch.prototype.remapping = function remapping (from, to) { + var maps = new prosemirror_transform__WEBPACK_IMPORTED_MODULE_1__["Mapping"]; + this.items.forEach(function (item, i) { + var mirrorPos = item.mirrorOffset != null && i - item.mirrorOffset >= from + ? mirrorPos = maps.maps.length - item.mirrorOffset : null; + maps.appendMap(item.map, mirrorPos); + }, from, to); + return maps +}; + +Branch.prototype.addMaps = function addMaps (array) { + if (this.eventCount == 0) { return this } + return new Branch(this.items.append(array.map(function (map) { return new Item(map); })), this.eventCount) +}; + +// : (Transform, number) +// When the collab module receives remote changes, the history has +// to know about those, so that it can adjust the steps that were +// rebased on top of the remote changes, and include the position +// maps for the remote changes in its array of items. +Branch.prototype.rebased = function rebased (rebasedTransform, rebasedCount) { + if (!this.eventCount) { return this } + + var rebasedItems = [], start = Math.max(0, this.items.length - rebasedCount); + + var mapping = rebasedTransform.mapping; + var newUntil = rebasedTransform.steps.length; + var eventCount = this.eventCount; + this.items.forEach(function (item) { if (item.selection) { eventCount--; } }, start); + + var iRebased = rebasedCount; + this.items.forEach(function (item) { + var pos = mapping.getMirror(--iRebased); + if (pos == null) { return } + newUntil = Math.min(newUntil, pos); + var map = mapping.maps[pos]; + if (item.step) { + var step = rebasedTransform.steps[pos].invert(rebasedTransform.docs[pos]); + var selection = item.selection && item.selection.map(mapping.slice(iRebased + 1, pos)); + if (selection) { eventCount++; } + rebasedItems.push(new Item(map, step, selection)); + } else { + rebasedItems.push(new Item(map)); + } + }, start); + + var newMaps = []; + for (var i = rebasedCount; i < newUntil; i++) + { newMaps.push(new Item(mapping.maps[i])); } + var items = this.items.slice(0, start).append(newMaps).append(rebasedItems); + var branch = new Branch(items, eventCount); + + if (branch.emptyItemCount() > max_empty_items) + { branch = branch.compress(this.items.length - rebasedItems.length); } + return branch +}; + +Branch.prototype.emptyItemCount = function emptyItemCount () { + var count = 0; + this.items.forEach(function (item) { if (!item.step) { count++; } }); + return count +}; + +// Compressing a branch means rewriting it to push the air (map-only +// items) out. During collaboration, these naturally accumulate +// because each remote change adds one. The `upto` argument is used +// to ensure that only the items below a given level are compressed, +// because `rebased` relies on a clean, untouched set of items in +// order to associate old items with rebased steps. +Branch.prototype.compress = function compress (upto) { + if ( upto === void 0 ) upto = this.items.length; + + var remap = this.remapping(0, upto), mapFrom = remap.maps.length; + var items = [], events = 0; + this.items.forEach(function (item, i) { + if (i >= upto) { + items.push(item); + if (item.selection) { events++; } + } else if (item.step) { + var step = item.step.map(remap.slice(mapFrom)), map = step && step.getMap(); + mapFrom--; + if (map) { remap.appendMap(map, mapFrom); } + if (step) { + var selection = item.selection && item.selection.map(remap.slice(mapFrom)); + if (selection) { events++; } + var newItem = new Item(map.invert(), step, selection), merged, last = items.length - 1; + if (merged = items.length && items[last].merge(newItem)) + { items[last] = merged; } + else + { items.push(newItem); } + } + } else if (item.map) { + mapFrom--; + } + }, this.items.length, 0); + return new Branch(rope_sequence__WEBPACK_IMPORTED_MODULE_0__["default"].from(items.reverse()), events) +}; + +Branch.empty = new Branch(rope_sequence__WEBPACK_IMPORTED_MODULE_0__["default"].empty, 0); + +function cutOffEvents(items, n) { + var cutPoint; + items.forEach(function (item, i) { + if (item.selection && (n-- == 0)) { + cutPoint = i; + return false + } + }); + return items.slice(cutPoint) +} + +var Item = function Item(map, step, selection, mirrorOffset) { + // The (forward) step map for this item. + this.map = map; + // The inverted step + this.step = step; + // If this is non-null, this item is the start of a group, and + // this selection is the starting selection for the group (the one + // that was active before the first step was applied) + this.selection = selection; + // If this item is the inverse of a previous mapping on the stack, + // this points at the inverse's offset + this.mirrorOffset = mirrorOffset; +}; + +Item.prototype.merge = function merge (other) { + if (this.step && other.step && !other.selection) { + var step = other.step.merge(this.step); + if (step) { return new Item(step.getMap().invert(), step, this.selection) } + } +}; + +// The value of the state field that tracks undo/redo history for that +// state. Will be stored in the plugin state when the history plugin +// is active. +var HistoryState = function HistoryState(done, undone, prevRanges, prevTime) { + this.done = done; + this.undone = undone; + this.prevRanges = prevRanges; + this.prevTime = prevTime; +}; + +var DEPTH_OVERFLOW = 20; + +// : (HistoryState, EditorState, Transaction, Object) +// Record a transformation in undo history. +function applyTransaction(history, state, tr, options) { + var historyTr = tr.getMeta(historyKey), rebased; + if (historyTr) { return historyTr.historyState } + + if (tr.getMeta(closeHistoryKey)) { history = new HistoryState(history.done, history.undone, null, 0); } + + var appended = tr.getMeta("appendedTransaction"); + + if (tr.steps.length == 0) { + return history + } else if (appended && appended.getMeta(historyKey)) { + if (appended.getMeta(historyKey).redo) + { return new HistoryState(history.done.addTransform(tr, null, options, mustPreserveItems(state)), + history.undone, rangesFor(tr.mapping.maps[tr.steps.length - 1]), history.prevTime) } + else + { return new HistoryState(history.done, history.undone.addTransform(tr, null, options, mustPreserveItems(state)), + null, history.prevTime) } + } else if (tr.getMeta("addToHistory") !== false && !(appended && appended.getMeta("addToHistory") === false)) { + // Group transforms that occur in quick succession into one event. + var newGroup = !appended && (history.prevTime < (tr.time || 0) - options.newGroupDelay || + !isAdjacentTo(tr, history.prevRanges)); + var prevRanges = appended ? mapRanges(history.prevRanges, tr.mapping) : rangesFor(tr.mapping.maps[tr.steps.length - 1]); + return new HistoryState(history.done.addTransform(tr, newGroup ? state.selection.getBookmark() : null, + options, mustPreserveItems(state)), + Branch.empty, prevRanges, tr.time) + } else if (rebased = tr.getMeta("rebased")) { + // Used by the collab module to tell the history that some of its + // content has been rebased. + return new HistoryState(history.done.rebased(tr, rebased), + history.undone.rebased(tr, rebased), + mapRanges(history.prevRanges, tr.mapping), history.prevTime) + } else { + return new HistoryState(history.done.addMaps(tr.mapping.maps), + history.undone.addMaps(tr.mapping.maps), + mapRanges(history.prevRanges, tr.mapping), history.prevTime) + } +} + +function isAdjacentTo(transform, prevRanges) { + if (!prevRanges) { return false } + if (!transform.docChanged) { return true } + var adjacent = false; + transform.mapping.maps[0].forEach(function (start, end) { + for (var i = 0; i < prevRanges.length; i += 2) + { if (start <= prevRanges[i + 1] && end >= prevRanges[i]) + { adjacent = true; } } + }); + return adjacent +} + +function rangesFor(map) { + var result = []; + map.forEach(function (_from, _to, from, to) { return result.push(from, to); }); + return result +} + +function mapRanges(ranges, mapping) { + if (!ranges) { return null } + var result = []; + for (var i = 0; i < ranges.length; i += 2) { + var from = mapping.map(ranges[i], 1), to = mapping.map(ranges[i + 1], -1); + if (from <= to) { result.push(from, to); } + } + return result +} + +// : (HistoryState, EditorState, (tr: Transaction), bool) +// Apply the latest event from one branch to the document and shift the event +// onto the other branch. +function histTransaction(history, state, dispatch, redo) { + var preserveItems = mustPreserveItems(state), histOptions = historyKey.get(state).spec.config; + var pop = (redo ? history.undone : history.done).popEvent(state, preserveItems); + if (!pop) { return } + + var selection = pop.selection.resolve(pop.transform.doc); + var added = (redo ? history.done : history.undone).addTransform(pop.transform, state.selection.getBookmark(), + histOptions, preserveItems); + + var newHist = new HistoryState(redo ? added : pop.remaining, redo ? pop.remaining : added, null, 0); + dispatch(pop.transform.setSelection(selection).setMeta(historyKey, {redo: redo, historyState: newHist}).scrollIntoView()); +} + +var cachedPreserveItems = false, cachedPreserveItemsPlugins = null; +// Check whether any plugin in the given state has a +// `historyPreserveItems` property in its spec, in which case we must +// preserve steps exactly as they came in, so that they can be +// rebased. +function mustPreserveItems(state) { + var plugins = state.plugins; + if (cachedPreserveItemsPlugins != plugins) { + cachedPreserveItems = false; + cachedPreserveItemsPlugins = plugins; + for (var i = 0; i < plugins.length; i++) { if (plugins[i].spec.historyPreserveItems) { + cachedPreserveItems = true; + break + } } + } + return cachedPreserveItems +} + +// :: (Transaction) → Transaction +// Set a flag on the given transaction that will prevent further steps +// from being appended to an existing history event (so that they +// require a separate undo command to undo). +function closeHistory(tr) { + return tr.setMeta(closeHistoryKey, true) +} + +var historyKey = new prosemirror_state__WEBPACK_IMPORTED_MODULE_2__["PluginKey"]("history"); +var closeHistoryKey = new prosemirror_state__WEBPACK_IMPORTED_MODULE_2__["PluginKey"]("closeHistory"); + +// :: (?Object) → Plugin +// Returns a plugin that enables the undo history for an editor. The +// plugin will track undo and redo stacks, which can be used with the +// [`undo`](#history.undo) and [`redo`](#history.redo) commands. +// +// You can set an `"addToHistory"` [metadata +// property](#state.Transaction.setMeta) of `false` on a transaction +// to prevent it from being rolled back by undo. +// +// config::- +// Supports the following configuration options: +// +// depth:: ?number +// The amount of history events that are collected before the +// oldest events are discarded. Defaults to 100. +// +// newGroupDelay:: ?number +// The delay between changes after which a new group should be +// started. Defaults to 500 (milliseconds). Note that when changes +// aren't adjacent, a new group is always started. +function history(config) { + config = {depth: config && config.depth || 100, + newGroupDelay: config && config.newGroupDelay || 500}; + return new prosemirror_state__WEBPACK_IMPORTED_MODULE_2__["Plugin"]({ + key: historyKey, + + state: { + init: function init() { + return new HistoryState(Branch.empty, Branch.empty, null, 0) + }, + apply: function apply(tr, hist, state) { + return applyTransaction(hist, state, tr, config) + } + }, + + config: config + }) +} + +// :: (EditorState, ?(tr: Transaction)) → bool +// A command function that undoes the last change, if any. +function undo(state, dispatch) { + var hist = historyKey.getState(state); + if (!hist || hist.done.eventCount == 0) { return false } + if (dispatch) { histTransaction(hist, state, dispatch, false); } + return true +} + +// :: (EditorState, ?(tr: Transaction)) → bool +// A command function that redoes the last undone change, if any. +function redo(state, dispatch) { + var hist = historyKey.getState(state); + if (!hist || hist.undone.eventCount == 0) { return false } + if (dispatch) { histTransaction(hist, state, dispatch, true); } + return true +} + +// :: (EditorState) → number +// The amount of undoable events available in a given state. +function undoDepth(state) { + var hist = historyKey.getState(state); + return hist ? hist.done.eventCount : 0 +} + +// :: (EditorState) → number +// The amount of redoable events available in a given editor state. +function redoDepth(state) { + var hist = historyKey.getState(state); + return hist ? hist.undone.eventCount : 0 +} + + +//# sourceMappingURL=index.es.js.map + + +/***/ }), + +/***/ "./node_modules/prosemirror-inputrules/dist/index.es.js": +/*!**************************************************************!*\ + !*** ./node_modules/prosemirror-inputrules/dist/index.es.js ***! + \**************************************************************/ +/*! exports provided: InputRule, closeDoubleQuote, closeSingleQuote, ellipsis, emDash, inputRules, openDoubleQuote, openSingleQuote, smartQuotes, textblockTypeInputRule, undoInputRule, wrappingInputRule */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "InputRule", function() { return InputRule; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "closeDoubleQuote", function() { return closeDoubleQuote; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "closeSingleQuote", function() { return closeSingleQuote; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ellipsis", function() { return ellipsis; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "emDash", function() { return emDash; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "inputRules", function() { return inputRules; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "openDoubleQuote", function() { return openDoubleQuote; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "openSingleQuote", function() { return openSingleQuote; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "smartQuotes", function() { return smartQuotes; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "textblockTypeInputRule", function() { return textblockTypeInputRule; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "undoInputRule", function() { return undoInputRule; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "wrappingInputRule", function() { return wrappingInputRule; }); +/* harmony import */ var prosemirror_state__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! prosemirror-state */ "./node_modules/prosemirror-state/dist/index.es.js"); +/* harmony import */ var prosemirror_transform__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! prosemirror-transform */ "./node_modules/prosemirror-transform/dist/index.es.js"); + + + +// ::- Input rules are regular expressions describing a piece of text +// that, when typed, causes something to happen. This might be +// changing two dashes into an emdash, wrapping a paragraph starting +// with `"> "` into a blockquote, or something entirely different. +var InputRule = function InputRule(match, handler) { + this.match = match; + this.handler = typeof handler == "string" ? stringHandler(handler) : handler; +}; + +function stringHandler(string) { + return function(state, match, start, end) { + var insert = string; + if (match[1]) { + var offset = match[0].lastIndexOf(match[1]); + insert += match[0].slice(offset + match[1].length); + start += offset; + var cutOff = start - end; + if (cutOff > 0) { + insert = match[0].slice(offset - cutOff, offset) + insert; + start = end; + } + } + return state.tr.insertText(insert, start, end) + } +} + +var MAX_MATCH = 500; + +// :: (config: {rules: [InputRule]}) → Plugin +// Create an input rules plugin. When enabled, it will cause text +// input that matches any of the given rules to trigger the rule's +// action. +function inputRules(ref) { + var rules = ref.rules; + + var plugin = new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["Plugin"]({ + state: { + init: function init() { return null }, + apply: function apply(tr, prev) { + var stored = tr.getMeta(this); + if (stored) { return stored } + return tr.selectionSet || tr.docChanged ? null : prev + } + }, + + props: { + handleTextInput: function handleTextInput(view, from, to, text) { + return run(view, from, to, text, rules, plugin) + }, + handleDOMEvents: { + compositionend: function (view) { + setTimeout(function () { + var ref = view.state.selection; + var $cursor = ref.$cursor; + if ($cursor) { run(view, $cursor.pos, $cursor.pos, "", rules, plugin); } + }); + } + } + }, + + isInputRules: true + }); + return plugin +} + +function run(view, from, to, text, rules, plugin) { + if (view.composing) { return false } + var state = view.state, $from = state.doc.resolve(from); + if ($from.parent.type.spec.code) { return false } + var textBefore = $from.parent.textBetween(Math.max(0, $from.parentOffset - MAX_MATCH), $from.parentOffset, + null, "\ufffc") + text; + for (var i = 0; i < rules.length; i++) { + var match = rules[i].match.exec(textBefore); + var tr = match && rules[i].handler(state, match, from - (match[0].length - text.length), to); + if (!tr) { continue } + view.dispatch(tr.setMeta(plugin, {transform: tr, from: from, to: to, text: text})); + return true + } + return false +} + +// :: (EditorState, ?(Transaction)) → bool +// This is a command that will undo an input rule, if applying such a +// rule was the last thing that the user did. +function undoInputRule(state, dispatch) { + var plugins = state.plugins; + for (var i = 0; i < plugins.length; i++) { + var plugin = plugins[i], undoable = (void 0); + if (plugin.spec.isInputRules && (undoable = plugin.getState(state))) { + if (dispatch) { + var tr = state.tr, toUndo = undoable.transform; + for (var j = toUndo.steps.length - 1; j >= 0; j--) + { tr.step(toUndo.steps[j].invert(toUndo.docs[j])); } + var marks = tr.doc.resolve(undoable.from).marks(); + dispatch(tr.replaceWith(undoable.from, undoable.to, state.schema.text(undoable.text, marks))); + } + return true + } + } + return false +} + +// :: InputRule Converts double dashes to an emdash. +var emDash = new InputRule(/--$/, "—"); +// :: InputRule Converts three dots to an ellipsis character. +var ellipsis = new InputRule(/\.\.\.$/, "…"); +// :: InputRule “Smart” opening double quotes. +var openDoubleQuote = new InputRule(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/, "“"); +// :: InputRule “Smart” closing double quotes. +var closeDoubleQuote = new InputRule(/"$/, "”"); +// :: InputRule “Smart” opening single quotes. +var openSingleQuote = new InputRule(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/, "‘"); +// :: InputRule “Smart” closing single quotes. +var closeSingleQuote = new InputRule(/'$/, "’"); + +// :: [InputRule] Smart-quote related input rules. +var smartQuotes = [openDoubleQuote, closeDoubleQuote, openSingleQuote, closeSingleQuote]; + +// :: (RegExp, NodeType, ?union, ?([string], Node) → bool) → InputRule +// Build an input rule for automatically wrapping a textblock when a +// given string is typed. The `regexp` argument is +// directly passed through to the `InputRule` constructor. You'll +// probably want the regexp to start with `^`, so that the pattern can +// only occur at the start of a textblock. +// +// `nodeType` is the type of node to wrap in. If it needs attributes, +// you can either pass them directly, or pass a function that will +// compute them from the regular expression match. +// +// By default, if there's a node with the same type above the newly +// wrapped node, the rule will try to [join](#transform.Transform.join) those +// two nodes. You can pass a join predicate, which takes a regular +// expression match and the node before the wrapped node, and can +// return a boolean to indicate whether a join should happen. +function wrappingInputRule(regexp, nodeType, getAttrs, joinPredicate) { + return new InputRule(regexp, function (state, match, start, end) { + var attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; + var tr = state.tr.delete(start, end); + var $start = tr.doc.resolve(start), range = $start.blockRange(), wrapping = range && Object(prosemirror_transform__WEBPACK_IMPORTED_MODULE_1__["findWrapping"])(range, nodeType, attrs); + if (!wrapping) { return null } + tr.wrap(range, wrapping); + var before = tr.doc.resolve(start - 1).nodeBefore; + if (before && before.type == nodeType && Object(prosemirror_transform__WEBPACK_IMPORTED_MODULE_1__["canJoin"])(tr.doc, start - 1) && + (!joinPredicate || joinPredicate(match, before))) + { tr.join(start - 1); } + return tr + }) +} + +// :: (RegExp, NodeType, ?union) → InputRule +// Build an input rule that changes the type of a textblock when the +// matched text is typed into it. You'll usually want to start your +// regexp with `^` to that it is only matched at the start of a +// textblock. The optional `getAttrs` parameter can be used to compute +// the new node's attributes, and works the same as in the +// `wrappingInputRule` function. +function textblockTypeInputRule(regexp, nodeType, getAttrs) { + return new InputRule(regexp, function (state, match, start, end) { + var $start = state.doc.resolve(start); + var attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; + if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType)) { return null } + return state.tr + .delete(start, end) + .setBlockType(start, start, nodeType, attrs) + }) +} + + +//# sourceMappingURL=index.es.js.map + + +/***/ }), + +/***/ "./node_modules/prosemirror-keymap/dist/index.es.js": +/*!**********************************************************!*\ + !*** ./node_modules/prosemirror-keymap/dist/index.es.js ***! + \**********************************************************/ +/*! exports provided: keydownHandler, keymap */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "keydownHandler", function() { return keydownHandler; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "keymap", function() { return keymap; }); +/* harmony import */ var w3c_keyname__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! w3c-keyname */ "./node_modules/w3c-keyname/index.es.js"); +/* harmony import */ var prosemirror_state__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! prosemirror-state */ "./node_modules/prosemirror-state/dist/index.es.js"); + + + +// declare global: navigator + +var mac = typeof navigator != "undefined" ? /Mac/.test(navigator.platform) : false; + +function normalizeKeyName(name) { + var parts = name.split(/-(?!$)/), result = parts[parts.length - 1]; + if (result == "Space") { result = " "; } + var alt, ctrl, shift, meta; + for (var i = 0; i < parts.length - 1; i++) { + var mod = parts[i]; + if (/^(cmd|meta|m)$/i.test(mod)) { meta = true; } + else if (/^a(lt)?$/i.test(mod)) { alt = true; } + else if (/^(c|ctrl|control)$/i.test(mod)) { ctrl = true; } + else if (/^s(hift)?$/i.test(mod)) { shift = true; } + else if (/^mod$/i.test(mod)) { if (mac) { meta = true; } else { ctrl = true; } } + else { throw new Error("Unrecognized modifier name: " + mod) } + } + if (alt) { result = "Alt-" + result; } + if (ctrl) { result = "Ctrl-" + result; } + if (meta) { result = "Meta-" + result; } + if (shift) { result = "Shift-" + result; } + return result +} + +function normalize(map) { + var copy = Object.create(null); + for (var prop in map) { copy[normalizeKeyName(prop)] = map[prop]; } + return copy +} + +function modifiers(name, event, shift) { + if (event.altKey) { name = "Alt-" + name; } + if (event.ctrlKey) { name = "Ctrl-" + name; } + if (event.metaKey) { name = "Meta-" + name; } + if (shift !== false && event.shiftKey) { name = "Shift-" + name; } + return name +} + +// :: (Object) → Plugin +// Create a keymap plugin for the given set of bindings. +// +// Bindings should map key names to [command](#commands)-style +// functions, which will be called with `(EditorState, dispatch, +// EditorView)` arguments, and should return true when they've handled +// the key. Note that the view argument isn't part of the command +// protocol, but can be used as an escape hatch if a binding needs to +// directly interact with the UI. +// +// Key names may be strings like `"Shift-Ctrl-Enter"`—a key +// identifier prefixed with zero or more modifiers. Key identifiers +// are based on the strings that can appear in +// [`KeyEvent.key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key). +// Use lowercase letters to refer to letter keys (or uppercase letters +// if you want shift to be held). You may use `"Space"` as an alias +// for the `" "` name. +// +// Modifiers can be given in any order. `Shift-` (or `s-`), `Alt-` (or +// `a-`), `Ctrl-` (or `c-` or `Control-`) and `Cmd-` (or `m-` or +// `Meta-`) are recognized. For characters that are created by holding +// shift, the `Shift-` prefix is implied, and should not be added +// explicitly. +// +// You can use `Mod-` as a shorthand for `Cmd-` on Mac and `Ctrl-` on +// other platforms. +// +// You can add multiple keymap plugins to an editor. The order in +// which they appear determines their precedence (the ones early in +// the array get to dispatch first). +function keymap(bindings) { + return new prosemirror_state__WEBPACK_IMPORTED_MODULE_1__["Plugin"]({props: {handleKeyDown: keydownHandler(bindings)}}) +} + +// :: (Object) → (view: EditorView, event: dom.Event) → bool +// Given a set of bindings (using the same format as +// [`keymap`](#keymap.keymap), return a [keydown +// handler](#view.EditorProps.handleKeyDown) that handles them. +function keydownHandler(bindings) { + var map = normalize(bindings); + return function(view, event) { + var name = Object(w3c_keyname__WEBPACK_IMPORTED_MODULE_0__["keyName"])(event), isChar = name.length == 1 && name != " ", baseName; + var direct = map[modifiers(name, event, !isChar)]; + if (direct && direct(view.state, view.dispatch, view)) { return true } + if (isChar && (event.shiftKey || event.altKey || event.metaKey) && + (baseName = w3c_keyname__WEBPACK_IMPORTED_MODULE_0__["base"][event.keyCode]) && baseName != name) { + var fromCode = map[modifiers(baseName, event, true)]; + if (fromCode && fromCode(view.state, view.dispatch, view)) { return true } + } else if (isChar && event.shiftKey) { + var withShift = map[modifiers(name, event, true)]; + if (withShift && withShift(view.state, view.dispatch, view)) { return true } + } + return false + } +} + + +//# sourceMappingURL=index.es.js.map + + +/***/ }), + +/***/ "./node_modules/prosemirror-model/dist/index.es.js": +/*!*********************************************************!*\ + !*** ./node_modules/prosemirror-model/dist/index.es.js ***! + \*********************************************************/ +/*! exports provided: ContentMatch, DOMParser, DOMSerializer, Fragment, Mark, MarkType, Node, NodeRange, NodeType, ReplaceError, ResolvedPos, Schema, Slice */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ContentMatch", function() { return ContentMatch; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DOMParser", function() { return DOMParser; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DOMSerializer", function() { return DOMSerializer; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Fragment", function() { return Fragment; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Mark", function() { return Mark; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MarkType", function() { return MarkType; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Node", function() { return Node; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "NodeRange", function() { return NodeRange; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "NodeType", function() { return NodeType; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ReplaceError", function() { return ReplaceError; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ResolvedPos", function() { return ResolvedPos; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Schema", function() { return Schema; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Slice", function() { return Slice; }); +/* harmony import */ var orderedmap__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! orderedmap */ "./node_modules/orderedmap/index.es.js"); + + +function findDiffStart(a, b, pos) { + for (var i = 0;; i++) { + if (i == a.childCount || i == b.childCount) + { return a.childCount == b.childCount ? null : pos } + + var childA = a.child(i), childB = b.child(i); + if (childA == childB) { pos += childA.nodeSize; continue } + + if (!childA.sameMarkup(childB)) { return pos } + + if (childA.isText && childA.text != childB.text) { + for (var j = 0; childA.text[j] == childB.text[j]; j++) + { pos++; } + return pos + } + if (childA.content.size || childB.content.size) { + var inner = findDiffStart(childA.content, childB.content, pos + 1); + if (inner != null) { return inner } + } + pos += childA.nodeSize; + } +} + +function findDiffEnd(a, b, posA, posB) { + for (var iA = a.childCount, iB = b.childCount;;) { + if (iA == 0 || iB == 0) + { return iA == iB ? null : {a: posA, b: posB} } + + var childA = a.child(--iA), childB = b.child(--iB), size = childA.nodeSize; + if (childA == childB) { + posA -= size; posB -= size; + continue + } + + if (!childA.sameMarkup(childB)) { return {a: posA, b: posB} } + + if (childA.isText && childA.text != childB.text) { + var same = 0, minSize = Math.min(childA.text.length, childB.text.length); + while (same < minSize && childA.text[childA.text.length - same - 1] == childB.text[childB.text.length - same - 1]) { + same++; posA--; posB--; + } + return {a: posA, b: posB} + } + if (childA.content.size || childB.content.size) { + var inner = findDiffEnd(childA.content, childB.content, posA - 1, posB - 1); + if (inner) { return inner } + } + posA -= size; posB -= size; + } +} + +// ::- A fragment represents a node's collection of child nodes. +// +// Like nodes, fragments are persistent data structures, and you +// should not mutate them or their content. Rather, you create new +// instances whenever needed. The API tries to make this easy. +var Fragment = function Fragment(content, size) { + this.content = content; + // :: number + // The size of the fragment, which is the total of the size of its + // content nodes. + this.size = size || 0; + if (size == null) { for (var i = 0; i < content.length; i++) + { this.size += content[i].nodeSize; } } +}; + +var prototypeAccessors = { firstChild: { configurable: true },lastChild: { configurable: true },childCount: { configurable: true } }; + +// :: (number, number, (node: Node, start: number, parent: Node, index: number) → ?bool, ?number) +// Invoke a callback for all descendant nodes between the given two +// positions (relative to start of this fragment). Doesn't descend +// into a node when the callback returns `false`. +Fragment.prototype.nodesBetween = function nodesBetween (from, to, f, nodeStart, parent) { + if ( nodeStart === void 0 ) nodeStart = 0; + + for (var i = 0, pos = 0; pos < to; i++) { + var child = this.content[i], end = pos + child.nodeSize; + if (end > from && f(child, nodeStart + pos, parent, i) !== false && child.content.size) { + var start = pos + 1; + child.nodesBetween(Math.max(0, from - start), + Math.min(child.content.size, to - start), + f, nodeStart + start); + } + pos = end; + } +}; + +// :: ((node: Node, pos: number, parent: Node) → ?bool) +// Call the given callback for every descendant node. The callback +// may return `false` to prevent traversal of a given node's children. +Fragment.prototype.descendants = function descendants (f) { + this.nodesBetween(0, this.size, f); +}; + +// : (number, number, ?string, ?string) → string +Fragment.prototype.textBetween = function textBetween (from, to, blockSeparator, leafText) { + var text = "", separated = true; + this.nodesBetween(from, to, function (node, pos) { + if (node.isText) { + text += node.text.slice(Math.max(from, pos) - pos, to - pos); + separated = !blockSeparator; + } else if (node.isLeaf && leafText) { + text += leafText; + separated = !blockSeparator; + } else if (!separated && node.isBlock) { + text += blockSeparator; + separated = true; + } + }, 0); + return text +}; + +// :: (Fragment) → Fragment +// Create a new fragment containing the combined content of this +// fragment and the other. +Fragment.prototype.append = function append (other) { + if (!other.size) { return this } + if (!this.size) { return other } + var last = this.lastChild, first = other.firstChild, content = this.content.slice(), i = 0; + if (last.isText && last.sameMarkup(first)) { + content[content.length - 1] = last.withText(last.text + first.text); + i = 1; + } + for (; i < other.content.length; i++) { content.push(other.content[i]); } + return new Fragment(content, this.size + other.size) +}; + +// :: (number, ?number) → Fragment +// Cut out the sub-fragment between the two given positions. +Fragment.prototype.cut = function cut (from, to) { + if (to == null) { to = this.size; } + if (from == 0 && to == this.size) { return this } + var result = [], size = 0; + if (to > from) { for (var i = 0, pos = 0; pos < to; i++) { + var child = this.content[i], end = pos + child.nodeSize; + if (end > from) { + if (pos < from || end > to) { + if (child.isText) + { child = child.cut(Math.max(0, from - pos), Math.min(child.text.length, to - pos)); } + else + { child = child.cut(Math.max(0, from - pos - 1), Math.min(child.content.size, to - pos - 1)); } + } + result.push(child); + size += child.nodeSize; + } + pos = end; + } } + return new Fragment(result, size) +}; + +Fragment.prototype.cutByIndex = function cutByIndex (from, to) { + if (from == to) { return Fragment.empty } + if (from == 0 && to == this.content.length) { return this } + return new Fragment(this.content.slice(from, to)) +}; + +// :: (number, Node) → Fragment +// Create a new fragment in which the node at the given index is +// replaced by the given node. +Fragment.prototype.replaceChild = function replaceChild (index, node) { + var current = this.content[index]; + if (current == node) { return this } + var copy = this.content.slice(); + var size = this.size + node.nodeSize - current.nodeSize; + copy[index] = node; + return new Fragment(copy, size) +}; + +// : (Node) → Fragment +// Create a new fragment by prepending the given node to this +// fragment. +Fragment.prototype.addToStart = function addToStart (node) { + return new Fragment([node].concat(this.content), this.size + node.nodeSize) +}; + +// : (Node) → Fragment +// Create a new fragment by appending the given node to this +// fragment. +Fragment.prototype.addToEnd = function addToEnd (node) { + return new Fragment(this.content.concat(node), this.size + node.nodeSize) +}; + +// :: (Fragment) → bool +// Compare this fragment to another one. +Fragment.prototype.eq = function eq (other) { + if (this.content.length != other.content.length) { return false } + for (var i = 0; i < this.content.length; i++) + { if (!this.content[i].eq(other.content[i])) { return false } } + return true +}; + +// :: ?Node +// The first child of the fragment, or `null` if it is empty. +prototypeAccessors.firstChild.get = function () { return this.content.length ? this.content[0] : null }; + +// :: ?Node +// The last child of the fragment, or `null` if it is empty. +prototypeAccessors.lastChild.get = function () { return this.content.length ? this.content[this.content.length - 1] : null }; + +// :: number +// The number of child nodes in this fragment. +prototypeAccessors.childCount.get = function () { return this.content.length }; + +// :: (number) → Node +// Get the child node at the given index. Raise an error when the +// index is out of range. +Fragment.prototype.child = function child (index) { + var found = this.content[index]; + if (!found) { throw new RangeError("Index " + index + " out of range for " + this) } + return found +}; + +// :: (number) → ?Node +// Get the child node at the given index, if it exists. +Fragment.prototype.maybeChild = function maybeChild (index) { + return this.content[index] +}; + +// :: ((node: Node, offset: number, index: number)) +// Call `f` for every child node, passing the node, its offset +// into this parent node, and its index. +Fragment.prototype.forEach = function forEach (f) { + for (var i = 0, p = 0; i < this.content.length; i++) { + var child = this.content[i]; + f(child, p, i); + p += child.nodeSize; + } +}; + +// :: (Fragment) → ?number +// Find the first position at which this fragment and another +// fragment differ, or `null` if they are the same. +Fragment.prototype.findDiffStart = function findDiffStart$1 (other, pos) { + if ( pos === void 0 ) pos = 0; + + return findDiffStart(this, other, pos) +}; + +// :: (Fragment) → ?{a: number, b: number} +// Find the first position, searching from the end, at which this +// fragment and the given fragment differ, or `null` if they are the +// same. Since this position will not be the same in both nodes, an +// object with two separate positions is returned. +Fragment.prototype.findDiffEnd = function findDiffEnd$1 (other, pos, otherPos) { + if ( pos === void 0 ) pos = this.size; + if ( otherPos === void 0 ) otherPos = other.size; + + return findDiffEnd(this, other, pos, otherPos) +}; + +// : (number, ?number) → {index: number, offset: number} +// Find the index and inner offset corresponding to a given relative +// position in this fragment. The result object will be reused +// (overwritten) the next time the function is called. (Not public.) +Fragment.prototype.findIndex = function findIndex (pos, round) { + if ( round === void 0 ) round = -1; + + if (pos == 0) { return retIndex(0, pos) } + if (pos == this.size) { return retIndex(this.content.length, pos) } + if (pos > this.size || pos < 0) { throw new RangeError(("Position " + pos + " outside of fragment (" + (this) + ")")) } + for (var i = 0, curPos = 0;; i++) { + var cur = this.child(i), end = curPos + cur.nodeSize; + if (end >= pos) { + if (end == pos || round > 0) { return retIndex(i + 1, end) } + return retIndex(i, curPos) + } + curPos = end; + } +}; + +// :: () → string +// Return a debugging string that describes this fragment. +Fragment.prototype.toString = function toString () { return "<" + this.toStringInner() + ">" }; + +Fragment.prototype.toStringInner = function toStringInner () { return this.content.join(", ") }; + +// :: () → ?Object +// Create a JSON-serializeable representation of this fragment. +Fragment.prototype.toJSON = function toJSON () { + return this.content.length ? this.content.map(function (n) { return n.toJSON(); }) : null +}; + +// :: (Schema, ?Object) → Fragment +// Deserialize a fragment from its JSON representation. +Fragment.fromJSON = function fromJSON (schema, value) { + if (!value) { return Fragment.empty } + if (!Array.isArray(value)) { throw new RangeError("Invalid input for Fragment.fromJSON") } + return new Fragment(value.map(schema.nodeFromJSON)) +}; + +// :: ([Node]) → Fragment +// Build a fragment from an array of nodes. Ensures that adjacent +// text nodes with the same marks are joined together. +Fragment.fromArray = function fromArray (array) { + if (!array.length) { return Fragment.empty } + var joined, size = 0; + for (var i = 0; i < array.length; i++) { + var node = array[i]; + size += node.nodeSize; + if (i && node.isText && array[i - 1].sameMarkup(node)) { + if (!joined) { joined = array.slice(0, i); } + joined[joined.length - 1] = node.withText(joined[joined.length - 1].text + node.text); + } else if (joined) { + joined.push(node); + } + } + return new Fragment(joined || array, size) +}; + +// :: (?union) → Fragment +// Create a fragment from something that can be interpreted as a set +// of nodes. For `null`, it returns the empty fragment. For a +// fragment, the fragment itself. For a node or array of nodes, a +// fragment containing those nodes. +Fragment.from = function from (nodes) { + if (!nodes) { return Fragment.empty } + if (nodes instanceof Fragment) { return nodes } + if (Array.isArray(nodes)) { return this.fromArray(nodes) } + if (nodes.attrs) { return new Fragment([nodes], nodes.nodeSize) } + throw new RangeError("Can not convert " + nodes + " to a Fragment" + + (nodes.nodesBetween ? " (looks like multiple versions of prosemirror-model were loaded)" : "")) +}; + +Object.defineProperties( Fragment.prototype, prototypeAccessors ); + +var found = {index: 0, offset: 0}; +function retIndex(index, offset) { + found.index = index; + found.offset = offset; + return found +} + +// :: Fragment +// An empty fragment. Intended to be reused whenever a node doesn't +// contain anything (rather than allocating a new empty fragment for +// each leaf node). +Fragment.empty = new Fragment([], 0); + +function compareDeep(a, b) { + if (a === b) { return true } + if (!(a && typeof a == "object") || + !(b && typeof b == "object")) { return false } + var array = Array.isArray(a); + if (Array.isArray(b) != array) { return false } + if (array) { + if (a.length != b.length) { return false } + for (var i = 0; i < a.length; i++) { if (!compareDeep(a[i], b[i])) { return false } } + } else { + for (var p in a) { if (!(p in b) || !compareDeep(a[p], b[p])) { return false } } + for (var p$1 in b) { if (!(p$1 in a)) { return false } } + } + return true +} + +// ::- A mark is a piece of information that can be attached to a node, +// such as it being emphasized, in code font, or a link. It has a type +// and optionally a set of attributes that provide further information +// (such as the target of the link). Marks are created through a +// `Schema`, which controls which types exist and which +// attributes they have. +var Mark = function Mark(type, attrs) { + // :: MarkType + // The type of this mark. + this.type = type; + // :: Object + // The attributes associated with this mark. + this.attrs = attrs; +}; + +// :: ([Mark]) → [Mark] +// Given a set of marks, create a new set which contains this one as +// well, in the right position. If this mark is already in the set, +// the set itself is returned. If any marks that are set to be +// [exclusive](#model.MarkSpec.excludes) with this mark are present, +// those are replaced by this one. +Mark.prototype.addToSet = function addToSet (set) { + var copy, placed = false; + for (var i = 0; i < set.length; i++) { + var other = set[i]; + if (this.eq(other)) { return set } + if (this.type.excludes(other.type)) { + if (!copy) { copy = set.slice(0, i); } + } else if (other.type.excludes(this.type)) { + return set + } else { + if (!placed && other.type.rank > this.type.rank) { + if (!copy) { copy = set.slice(0, i); } + copy.push(this); + placed = true; + } + if (copy) { copy.push(other); } + } + } + if (!copy) { copy = set.slice(); } + if (!placed) { copy.push(this); } + return copy +}; + +// :: ([Mark]) → [Mark] +// Remove this mark from the given set, returning a new set. If this +// mark is not in the set, the set itself is returned. +Mark.prototype.removeFromSet = function removeFromSet (set) { + for (var i = 0; i < set.length; i++) + { if (this.eq(set[i])) + { return set.slice(0, i).concat(set.slice(i + 1)) } } + return set +}; + +// :: ([Mark]) → bool +// Test whether this mark is in the given set of marks. +Mark.prototype.isInSet = function isInSet (set) { + for (var i = 0; i < set.length; i++) + { if (this.eq(set[i])) { return true } } + return false +}; + +// :: (Mark) → bool +// Test whether this mark has the same type and attributes as +// another mark. +Mark.prototype.eq = function eq (other) { + return this == other || + (this.type == other.type && compareDeep(this.attrs, other.attrs)) +}; + +// :: () → Object +// Convert this mark to a JSON-serializeable representation. +Mark.prototype.toJSON = function toJSON () { + var obj = {type: this.type.name}; + for (var _ in this.attrs) { + obj.attrs = this.attrs; + break + } + return obj +}; + +// :: (Schema, Object) → Mark +Mark.fromJSON = function fromJSON (schema, json) { + if (!json) { throw new RangeError("Invalid input for Mark.fromJSON") } + var type = schema.marks[json.type]; + if (!type) { throw new RangeError(("There is no mark type " + (json.type) + " in this schema")) } + return type.create(json.attrs) +}; + +// :: ([Mark], [Mark]) → bool +// Test whether two sets of marks are identical. +Mark.sameSet = function sameSet (a, b) { + if (a == b) { return true } + if (a.length != b.length) { return false } + for (var i = 0; i < a.length; i++) + { if (!a[i].eq(b[i])) { return false } } + return true +}; + +// :: (?union) → [Mark] +// Create a properly sorted mark set from null, a single mark, or an +// unsorted array of marks. +Mark.setFrom = function setFrom (marks) { + if (!marks || marks.length == 0) { return Mark.none } + if (marks instanceof Mark) { return [marks] } + var copy = marks.slice(); + copy.sort(function (a, b) { return a.type.rank - b.type.rank; }); + return copy +}; + +// :: [Mark] The empty set of marks. +Mark.none = []; + +// ReplaceError:: class extends Error +// Error type raised by [`Node.replace`](#model.Node.replace) when +// given an invalid replacement. + +function ReplaceError(message) { + var err = Error.call(this, message); + err.__proto__ = ReplaceError.prototype; + return err +} + +ReplaceError.prototype = Object.create(Error.prototype); +ReplaceError.prototype.constructor = ReplaceError; +ReplaceError.prototype.name = "ReplaceError"; + +// ::- A slice represents a piece cut out of a larger document. It +// stores not only a fragment, but also the depth up to which nodes on +// both side are ‘open’ (cut through). +var Slice = function Slice(content, openStart, openEnd) { + // :: Fragment The slice's content. + this.content = content; + // :: number The open depth at the start. + this.openStart = openStart; + // :: number The open depth at the end. + this.openEnd = openEnd; +}; + +var prototypeAccessors$1 = { size: { configurable: true } }; + +// :: number +// The size this slice would add when inserted into a document. +prototypeAccessors$1.size.get = function () { + return this.content.size - this.openStart - this.openEnd +}; + +Slice.prototype.insertAt = function insertAt (pos, fragment) { + var content = insertInto(this.content, pos + this.openStart, fragment, null); + return content && new Slice(content, this.openStart, this.openEnd) +}; + +Slice.prototype.removeBetween = function removeBetween (from, to) { + return new Slice(removeRange(this.content, from + this.openStart, to + this.openStart), this.openStart, this.openEnd) +}; + +// :: (Slice) → bool +// Tests whether this slice is equal to another slice. +Slice.prototype.eq = function eq (other) { + return this.content.eq(other.content) && this.openStart == other.openStart && this.openEnd == other.openEnd +}; + +Slice.prototype.toString = function toString () { + return this.content + "(" + this.openStart + "," + this.openEnd + ")" +}; + +// :: () → ?Object +// Convert a slice to a JSON-serializable representation. +Slice.prototype.toJSON = function toJSON () { + if (!this.content.size) { return null } + var json = {content: this.content.toJSON()}; + if (this.openStart > 0) { json.openStart = this.openStart; } + if (this.openEnd > 0) { json.openEnd = this.openEnd; } + return json +}; + +// :: (Schema, ?Object) → Slice +// Deserialize a slice from its JSON representation. +Slice.fromJSON = function fromJSON (schema, json) { + if (!json) { return Slice.empty } + var openStart = json.openStart || 0, openEnd = json.openEnd || 0; + if (typeof openStart != "number" || typeof openEnd != "number") + { throw new RangeError("Invalid input for Slice.fromJSON") } + return new Slice(Fragment.fromJSON(schema, json.content), json.openStart || 0, json.openEnd || 0) +}; + +// :: (Fragment, ?bool) → Slice +// Create a slice from a fragment by taking the maximum possible +// open value on both side of the fragment. +Slice.maxOpen = function maxOpen (fragment, openIsolating) { + if ( openIsolating === void 0 ) openIsolating=true; + + var openStart = 0, openEnd = 0; + for (var n = fragment.firstChild; n && !n.isLeaf && (openIsolating || !n.type.spec.isolating); n = n.firstChild) { openStart++; } + for (var n$1 = fragment.lastChild; n$1 && !n$1.isLeaf && (openIsolating || !n$1.type.spec.isolating); n$1 = n$1.lastChild) { openEnd++; } + return new Slice(fragment, openStart, openEnd) +}; + +Object.defineProperties( Slice.prototype, prototypeAccessors$1 ); + +function removeRange(content, from, to) { + var ref = content.findIndex(from); + var index = ref.index; + var offset = ref.offset; + var child = content.maybeChild(index); + var ref$1 = content.findIndex(to); + var indexTo = ref$1.index; + var offsetTo = ref$1.offset; + if (offset == from || child.isText) { + if (offsetTo != to && !content.child(indexTo).isText) { throw new RangeError("Removing non-flat range") } + return content.cut(0, from).append(content.cut(to)) + } + if (index != indexTo) { throw new RangeError("Removing non-flat range") } + return content.replaceChild(index, child.copy(removeRange(child.content, from - offset - 1, to - offset - 1))) +} + +function insertInto(content, dist, insert, parent) { + var ref = content.findIndex(dist); + var index = ref.index; + var offset = ref.offset; + var child = content.maybeChild(index); + if (offset == dist || child.isText) { + if (parent && !parent.canReplace(index, index, insert)) { return null } + return content.cut(0, dist).append(insert).append(content.cut(dist)) + } + var inner = insertInto(child.content, dist - offset - 1, insert); + return inner && content.replaceChild(index, child.copy(inner)) +} + +// :: Slice +// The empty slice. +Slice.empty = new Slice(Fragment.empty, 0, 0); + +function replace($from, $to, slice) { + if (slice.openStart > $from.depth) + { throw new ReplaceError("Inserted content deeper than insertion position") } + if ($from.depth - slice.openStart != $to.depth - slice.openEnd) + { throw new ReplaceError("Inconsistent open depths") } + return replaceOuter($from, $to, slice, 0) +} + +function replaceOuter($from, $to, slice, depth) { + var index = $from.index(depth), node = $from.node(depth); + if (index == $to.index(depth) && depth < $from.depth - slice.openStart) { + var inner = replaceOuter($from, $to, slice, depth + 1); + return node.copy(node.content.replaceChild(index, inner)) + } else if (!slice.content.size) { + return close(node, replaceTwoWay($from, $to, depth)) + } else if (!slice.openStart && !slice.openEnd && $from.depth == depth && $to.depth == depth) { // Simple, flat case + var parent = $from.parent, content = parent.content; + return close(parent, content.cut(0, $from.parentOffset).append(slice.content).append(content.cut($to.parentOffset))) + } else { + var ref = prepareSliceForReplace(slice, $from); + var start = ref.start; + var end = ref.end; + return close(node, replaceThreeWay($from, start, end, $to, depth)) + } +} + +function checkJoin(main, sub) { + if (!sub.type.compatibleContent(main.type)) + { throw new ReplaceError("Cannot join " + sub.type.name + " onto " + main.type.name) } +} + +function joinable($before, $after, depth) { + var node = $before.node(depth); + checkJoin(node, $after.node(depth)); + return node +} + +function addNode(child, target) { + var last = target.length - 1; + if (last >= 0 && child.isText && child.sameMarkup(target[last])) + { target[last] = child.withText(target[last].text + child.text); } + else + { target.push(child); } +} + +function addRange($start, $end, depth, target) { + var node = ($end || $start).node(depth); + var startIndex = 0, endIndex = $end ? $end.index(depth) : node.childCount; + if ($start) { + startIndex = $start.index(depth); + if ($start.depth > depth) { + startIndex++; + } else if ($start.textOffset) { + addNode($start.nodeAfter, target); + startIndex++; + } + } + for (var i = startIndex; i < endIndex; i++) { addNode(node.child(i), target); } + if ($end && $end.depth == depth && $end.textOffset) + { addNode($end.nodeBefore, target); } +} + +function close(node, content) { + if (!node.type.validContent(content)) + { throw new ReplaceError("Invalid content for node " + node.type.name) } + return node.copy(content) +} + +function replaceThreeWay($from, $start, $end, $to, depth) { + var openStart = $from.depth > depth && joinable($from, $start, depth + 1); + var openEnd = $to.depth > depth && joinable($end, $to, depth + 1); + + var content = []; + addRange(null, $from, depth, content); + if (openStart && openEnd && $start.index(depth) == $end.index(depth)) { + checkJoin(openStart, openEnd); + addNode(close(openStart, replaceThreeWay($from, $start, $end, $to, depth + 1)), content); + } else { + if (openStart) + { addNode(close(openStart, replaceTwoWay($from, $start, depth + 1)), content); } + addRange($start, $end, depth, content); + if (openEnd) + { addNode(close(openEnd, replaceTwoWay($end, $to, depth + 1)), content); } + } + addRange($to, null, depth, content); + return new Fragment(content) +} + +function replaceTwoWay($from, $to, depth) { + var content = []; + addRange(null, $from, depth, content); + if ($from.depth > depth) { + var type = joinable($from, $to, depth + 1); + addNode(close(type, replaceTwoWay($from, $to, depth + 1)), content); + } + addRange($to, null, depth, content); + return new Fragment(content) +} + +function prepareSliceForReplace(slice, $along) { + var extra = $along.depth - slice.openStart, parent = $along.node(extra); + var node = parent.copy(slice.content); + for (var i = extra - 1; i >= 0; i--) + { node = $along.node(i).copy(Fragment.from(node)); } + return {start: node.resolveNoCache(slice.openStart + extra), + end: node.resolveNoCache(node.content.size - slice.openEnd - extra)} +} + +// ::- You can [_resolve_](#model.Node.resolve) a position to get more +// information about it. Objects of this class represent such a +// resolved position, providing various pieces of context information, +// and some helper methods. +// +// Throughout this interface, methods that take an optional `depth` +// parameter will interpret undefined as `this.depth` and negative +// numbers as `this.depth + value`. +var ResolvedPos = function ResolvedPos(pos, path, parentOffset) { + // :: number The position that was resolved. + this.pos = pos; + this.path = path; + // :: number + // The number of levels the parent node is from the root. If this + // position points directly into the root node, it is 0. If it + // points into a top-level paragraph, 1, and so on. + this.depth = path.length / 3 - 1; + // :: number The offset this position has into its parent node. + this.parentOffset = parentOffset; +}; + +var prototypeAccessors$2 = { parent: { configurable: true },doc: { configurable: true },textOffset: { configurable: true },nodeAfter: { configurable: true },nodeBefore: { configurable: true } }; + +ResolvedPos.prototype.resolveDepth = function resolveDepth (val) { + if (val == null) { return this.depth } + if (val < 0) { return this.depth + val } + return val +}; + +// :: Node +// The parent node that the position points into. Note that even if +// a position points into a text node, that node is not considered +// the parent—text nodes are ‘flat’ in this model, and have no content. +prototypeAccessors$2.parent.get = function () { return this.node(this.depth) }; + +// :: Node +// The root node in which the position was resolved. +prototypeAccessors$2.doc.get = function () { return this.node(0) }; + +// :: (?number) → Node +// The ancestor node at the given level. `p.node(p.depth)` is the +// same as `p.parent`. +ResolvedPos.prototype.node = function node (depth) { return this.path[this.resolveDepth(depth) * 3] }; + +// :: (?number) → number +// The index into the ancestor at the given level. If this points at +// the 3rd node in the 2nd paragraph on the top level, for example, +// `p.index(0)` is 1 and `p.index(1)` is 2. +ResolvedPos.prototype.index = function index (depth) { return this.path[this.resolveDepth(depth) * 3 + 1] }; + +// :: (?number) → number +// The index pointing after this position into the ancestor at the +// given level. +ResolvedPos.prototype.indexAfter = function indexAfter (depth) { + depth = this.resolveDepth(depth); + return this.index(depth) + (depth == this.depth && !this.textOffset ? 0 : 1) +}; + +// :: (?number) → number +// The (absolute) position at the start of the node at the given +// level. +ResolvedPos.prototype.start = function start (depth) { + depth = this.resolveDepth(depth); + return depth == 0 ? 0 : this.path[depth * 3 - 1] + 1 +}; + +// :: (?number) → number +// The (absolute) position at the end of the node at the given +// level. +ResolvedPos.prototype.end = function end (depth) { + depth = this.resolveDepth(depth); + return this.start(depth) + this.node(depth).content.size +}; + +// :: (?number) → number +// The (absolute) position directly before the wrapping node at the +// given level, or, when `depth` is `this.depth + 1`, the original +// position. +ResolvedPos.prototype.before = function before (depth) { + depth = this.resolveDepth(depth); + if (!depth) { throw new RangeError("There is no position before the top-level node") } + return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1] +}; + +// :: (?number) → number +// The (absolute) position directly after the wrapping node at the +// given level, or the original position when `depth` is `this.depth + 1`. +ResolvedPos.prototype.after = function after (depth) { + depth = this.resolveDepth(depth); + if (!depth) { throw new RangeError("There is no position after the top-level node") } + return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1] + this.path[depth * 3].nodeSize +}; + +// :: number +// When this position points into a text node, this returns the +// distance between the position and the start of the text node. +// Will be zero for positions that point between nodes. +prototypeAccessors$2.textOffset.get = function () { return this.pos - this.path[this.path.length - 1] }; + +// :: ?Node +// Get the node directly after the position, if any. If the position +// points into a text node, only the part of that node after the +// position is returned. +prototypeAccessors$2.nodeAfter.get = function () { + var parent = this.parent, index = this.index(this.depth); + if (index == parent.childCount) { return null } + var dOff = this.pos - this.path[this.path.length - 1], child = parent.child(index); + return dOff ? parent.child(index).cut(dOff) : child +}; + +// :: ?Node +// Get the node directly before the position, if any. If the +// position points into a text node, only the part of that node +// before the position is returned. +prototypeAccessors$2.nodeBefore.get = function () { + var index = this.index(this.depth); + var dOff = this.pos - this.path[this.path.length - 1]; + if (dOff) { return this.parent.child(index).cut(0, dOff) } + return index == 0 ? null : this.parent.child(index - 1) +}; + +// :: () → [Mark] +// Get the marks at this position, factoring in the surrounding +// marks' [`inclusive`](#model.MarkSpec.inclusive) property. If the +// position is at the start of a non-empty node, the marks of the +// node after it (if any) are returned. +ResolvedPos.prototype.marks = function marks () { + var parent = this.parent, index = this.index(); + + // In an empty parent, return the empty array + if (parent.content.size == 0) { return Mark.none } + + // When inside a text node, just return the text node's marks + if (this.textOffset) { return parent.child(index).marks } + + var main = parent.maybeChild(index - 1), other = parent.maybeChild(index); + // If the `after` flag is true of there is no node before, make + // the node after this position the main reference. + if (!main) { var tmp = main; main = other; other = tmp; } + + // Use all marks in the main node, except those that have + // `inclusive` set to false and are not present in the other node. + var marks = main.marks; + for (var i = 0; i < marks.length; i++) + { if (marks[i].type.spec.inclusive === false && (!other || !marks[i].isInSet(other.marks))) + { marks = marks[i--].removeFromSet(marks); } } + + return marks +}; + +// :: (ResolvedPos) → ?[Mark] +// Get the marks after the current position, if any, except those +// that are non-inclusive and not present at position `$end`. This +// is mostly useful for getting the set of marks to preserve after a +// deletion. Will return `null` if this position is at the end of +// its parent node or its parent node isn't a textblock (in which +// case no marks should be preserved). +ResolvedPos.prototype.marksAcross = function marksAcross ($end) { + var after = this.parent.maybeChild(this.index()); + if (!after || !after.isInline) { return null } + + var marks = after.marks, next = $end.parent.maybeChild($end.index()); + for (var i = 0; i < marks.length; i++) + { if (marks[i].type.spec.inclusive === false && (!next || !marks[i].isInSet(next.marks))) + { marks = marks[i--].removeFromSet(marks); } } + return marks +}; + +// :: (number) → number +// The depth up to which this position and the given (non-resolved) +// position share the same parent nodes. +ResolvedPos.prototype.sharedDepth = function sharedDepth (pos) { + for (var depth = this.depth; depth > 0; depth--) + { if (this.start(depth) <= pos && this.end(depth) >= pos) { return depth } } + return 0 +}; + +// :: (?ResolvedPos, ?(Node) → bool) → ?NodeRange +// Returns a range based on the place where this position and the +// given position diverge around block content. If both point into +// the same textblock, for example, a range around that textblock +// will be returned. If they point into different blocks, the range +// around those blocks in their shared ancestor is returned. You can +// pass in an optional predicate that will be called with a parent +// node to see if a range into that parent is acceptable. +ResolvedPos.prototype.blockRange = function blockRange (other, pred) { + if ( other === void 0 ) other = this; + + if (other.pos < this.pos) { return other.blockRange(this) } + for (var d = this.depth - (this.parent.inlineContent || this.pos == other.pos ? 1 : 0); d >= 0; d--) + { if (other.pos <= this.end(d) && (!pred || pred(this.node(d)))) + { return new NodeRange(this, other, d) } } +}; + +// :: (ResolvedPos) → bool +// Query whether the given position shares the same parent node. +ResolvedPos.prototype.sameParent = function sameParent (other) { + return this.pos - this.parentOffset == other.pos - other.parentOffset +}; + +// :: (ResolvedPos) → ResolvedPos +// Return the greater of this and the given position. +ResolvedPos.prototype.max = function max (other) { + return other.pos > this.pos ? other : this +}; + +// :: (ResolvedPos) → ResolvedPos +// Return the smaller of this and the given position. +ResolvedPos.prototype.min = function min (other) { + return other.pos < this.pos ? other : this +}; + +ResolvedPos.prototype.toString = function toString () { + var str = ""; + for (var i = 1; i <= this.depth; i++) + { str += (str ? "/" : "") + this.node(i).type.name + "_" + this.index(i - 1); } + return str + ":" + this.parentOffset +}; + +ResolvedPos.resolve = function resolve (doc, pos) { + if (!(pos >= 0 && pos <= doc.content.size)) { throw new RangeError("Position " + pos + " out of range") } + var path = []; + var start = 0, parentOffset = pos; + for (var node = doc;;) { + var ref = node.content.findIndex(parentOffset); + var index = ref.index; + var offset = ref.offset; + var rem = parentOffset - offset; + path.push(node, index, start + offset); + if (!rem) { break } + node = node.child(index); + if (node.isText) { break } + parentOffset = rem - 1; + start += offset + 1; + } + return new ResolvedPos(pos, path, parentOffset) +}; + +ResolvedPos.resolveCached = function resolveCached (doc, pos) { + for (var i = 0; i < resolveCache.length; i++) { + var cached = resolveCache[i]; + if (cached.pos == pos && cached.doc == doc) { return cached } + } + var result = resolveCache[resolveCachePos] = ResolvedPos.resolve(doc, pos); + resolveCachePos = (resolveCachePos + 1) % resolveCacheSize; + return result +}; + +Object.defineProperties( ResolvedPos.prototype, prototypeAccessors$2 ); + +var resolveCache = [], resolveCachePos = 0, resolveCacheSize = 12; + +// ::- Represents a flat range of content, i.e. one that starts and +// ends in the same node. +var NodeRange = function NodeRange($from, $to, depth) { + // :: ResolvedPos A resolved position along the start of the + // content. May have a `depth` greater than this object's `depth` + // property, since these are the positions that were used to + // compute the range, not re-resolved positions directly at its + // boundaries. + this.$from = $from; + // :: ResolvedPos A position along the end of the content. See + // caveat for [`$from`](#model.NodeRange.$from). + this.$to = $to; + // :: number The depth of the node that this range points into. + this.depth = depth; +}; + +var prototypeAccessors$1$1 = { start: { configurable: true },end: { configurable: true },parent: { configurable: true },startIndex: { configurable: true },endIndex: { configurable: true } }; + +// :: number The position at the start of the range. +prototypeAccessors$1$1.start.get = function () { return this.$from.before(this.depth + 1) }; +// :: number The position at the end of the range. +prototypeAccessors$1$1.end.get = function () { return this.$to.after(this.depth + 1) }; + +// :: Node The parent node that the range points into. +prototypeAccessors$1$1.parent.get = function () { return this.$from.node(this.depth) }; +// :: number The start index of the range in the parent node. +prototypeAccessors$1$1.startIndex.get = function () { return this.$from.index(this.depth) }; +// :: number The end index of the range in the parent node. +prototypeAccessors$1$1.endIndex.get = function () { return this.$to.indexAfter(this.depth) }; + +Object.defineProperties( NodeRange.prototype, prototypeAccessors$1$1 ); + +var emptyAttrs = Object.create(null); + +// ::- This class represents a node in the tree that makes up a +// ProseMirror document. So a document is an instance of `Node`, with +// children that are also instances of `Node`. +// +// Nodes are persistent data structures. Instead of changing them, you +// create new ones with the content you want. Old ones keep pointing +// at the old document shape. This is made cheaper by sharing +// structure between the old and new data as much as possible, which a +// tree shape like this (without back pointers) makes easy. +// +// **Do not** directly mutate the properties of a `Node` object. See +// [the guide](/docs/guide/#doc) for more information. +var Node = function Node(type, attrs, content, marks) { + // :: NodeType + // The type of node that this is. + this.type = type; + + // :: Object + // An object mapping attribute names to values. The kind of + // attributes allowed and required are + // [determined](#model.NodeSpec.attrs) by the node type. + this.attrs = attrs; + + // :: Fragment + // A container holding the node's children. + this.content = content || Fragment.empty; + + // :: [Mark] + // The marks (things like whether it is emphasized or part of a + // link) applied to this node. + this.marks = marks || Mark.none; +}; + +var prototypeAccessors$3 = { nodeSize: { configurable: true },childCount: { configurable: true },textContent: { configurable: true },firstChild: { configurable: true },lastChild: { configurable: true },isBlock: { configurable: true },isTextblock: { configurable: true },inlineContent: { configurable: true },isInline: { configurable: true },isText: { configurable: true },isLeaf: { configurable: true },isAtom: { configurable: true } }; + +// text:: ?string +// For text nodes, this contains the node's text content. + +// :: number +// The size of this node, as defined by the integer-based [indexing +// scheme](/docs/guide/#doc.indexing). For text nodes, this is the +// amount of characters. For other leaf nodes, it is one. For +// non-leaf nodes, it is the size of the content plus two (the start +// and end token). +prototypeAccessors$3.nodeSize.get = function () { return this.isLeaf ? 1 : 2 + this.content.size }; + +// :: number +// The number of children that the node has. +prototypeAccessors$3.childCount.get = function () { return this.content.childCount }; + +// :: (number) → Node +// Get the child node at the given index. Raises an error when the +// index is out of range. +Node.prototype.child = function child (index) { return this.content.child(index) }; + +// :: (number) → ?Node +// Get the child node at the given index, if it exists. +Node.prototype.maybeChild = function maybeChild (index) { return this.content.maybeChild(index) }; + +// :: ((node: Node, offset: number, index: number)) +// Call `f` for every child node, passing the node, its offset +// into this parent node, and its index. +Node.prototype.forEach = function forEach (f) { this.content.forEach(f); }; + +// :: (number, number, (node: Node, pos: number, parent: Node, index: number) → ?bool, ?number) +// Invoke a callback for all descendant nodes recursively between +// the given two positions that are relative to start of this node's +// content. The callback is invoked with the node, its +// parent-relative position, its parent node, and its child index. +// When the callback returns false for a given node, that node's +// children will not be recursed over. The last parameter can be +// used to specify a starting position to count from. +Node.prototype.nodesBetween = function nodesBetween (from, to, f, startPos) { + if ( startPos === void 0 ) startPos = 0; + + this.content.nodesBetween(from, to, f, startPos, this); +}; + +// :: ((node: Node, pos: number, parent: Node) → ?bool) +// Call the given callback for every descendant node. Doesn't +// descend into a node when the callback returns `false`. +Node.prototype.descendants = function descendants (f) { + this.nodesBetween(0, this.content.size, f); +}; + +// :: string +// Concatenates all the text nodes found in this fragment and its +// children. +prototypeAccessors$3.textContent.get = function () { return this.textBetween(0, this.content.size, "") }; + +// :: (number, number, ?string, ?string) → string +// Get all text between positions `from` and `to`. When +// `blockSeparator` is given, it will be inserted whenever a new +// block node is started. When `leafText` is given, it'll be +// inserted for every non-text leaf node encountered. +Node.prototype.textBetween = function textBetween (from, to, blockSeparator, leafText) { + return this.content.textBetween(from, to, blockSeparator, leafText) +}; + +// :: ?Node +// Returns this node's first child, or `null` if there are no +// children. +prototypeAccessors$3.firstChild.get = function () { return this.content.firstChild }; + +// :: ?Node +// Returns this node's last child, or `null` if there are no +// children. +prototypeAccessors$3.lastChild.get = function () { return this.content.lastChild }; + +// :: (Node) → bool +// Test whether two nodes represent the same piece of document. +Node.prototype.eq = function eq (other) { + return this == other || (this.sameMarkup(other) && this.content.eq(other.content)) +}; + +// :: (Node) → bool +// Compare the markup (type, attributes, and marks) of this node to +// those of another. Returns `true` if both have the same markup. +Node.prototype.sameMarkup = function sameMarkup (other) { + return this.hasMarkup(other.type, other.attrs, other.marks) +}; + +// :: (NodeType, ?Object, ?[Mark]) → bool +// Check whether this node's markup correspond to the given type, +// attributes, and marks. +Node.prototype.hasMarkup = function hasMarkup (type, attrs, marks) { + return this.type == type && + compareDeep(this.attrs, attrs || type.defaultAttrs || emptyAttrs) && + Mark.sameSet(this.marks, marks || Mark.none) +}; + +// :: (?Fragment) → Node +// Create a new node with the same markup as this node, containing +// the given content (or empty, if no content is given). +Node.prototype.copy = function copy (content) { + if ( content === void 0 ) content = null; + + if (content == this.content) { return this } + return new this.constructor(this.type, this.attrs, content, this.marks) +}; + +// :: ([Mark]) → Node +// Create a copy of this node, with the given set of marks instead +// of the node's own marks. +Node.prototype.mark = function mark (marks) { + return marks == this.marks ? this : new this.constructor(this.type, this.attrs, this.content, marks) +}; + +// :: (number, ?number) → Node +// Create a copy of this node with only the content between the +// given positions. If `to` is not given, it defaults to the end of +// the node. +Node.prototype.cut = function cut (from, to) { + if (from == 0 && to == this.content.size) { return this } + return this.copy(this.content.cut(from, to)) +}; + +// :: (number, ?number) → Slice +// Cut out the part of the document between the given positions, and +// return it as a `Slice` object. +Node.prototype.slice = function slice (from, to, includeParents) { + if ( to === void 0 ) to = this.content.size; + if ( includeParents === void 0 ) includeParents = false; + + if (from == to) { return Slice.empty } + + var $from = this.resolve(from), $to = this.resolve(to); + var depth = includeParents ? 0 : $from.sharedDepth(to); + var start = $from.start(depth), node = $from.node(depth); + var content = node.content.cut($from.pos - start, $to.pos - start); + return new Slice(content, $from.depth - depth, $to.depth - depth) +}; + +// :: (number, number, Slice) → Node +// Replace the part of the document between the given positions with +// the given slice. The slice must 'fit', meaning its open sides +// must be able to connect to the surrounding content, and its +// content nodes must be valid children for the node they are placed +// into. If any of this is violated, an error of type +// [`ReplaceError`](#model.ReplaceError) is thrown. +Node.prototype.replace = function replace$1 (from, to, slice) { + return replace(this.resolve(from), this.resolve(to), slice) +}; + +// :: (number) → ?Node +// Find the node directly after the given position. +Node.prototype.nodeAt = function nodeAt (pos) { + for (var node = this;;) { + var ref = node.content.findIndex(pos); + var index = ref.index; + var offset = ref.offset; + node = node.maybeChild(index); + if (!node) { return null } + if (offset == pos || node.isText) { return node } + pos -= offset + 1; + } +}; + +// :: (number) → {node: ?Node, index: number, offset: number} +// Find the (direct) child node after the given offset, if any, +// and return it along with its index and offset relative to this +// node. +Node.prototype.childAfter = function childAfter (pos) { + var ref = this.content.findIndex(pos); + var index = ref.index; + var offset = ref.offset; + return {node: this.content.maybeChild(index), index: index, offset: offset} +}; + +// :: (number) → {node: ?Node, index: number, offset: number} +// Find the (direct) child node before the given offset, if any, +// and return it along with its index and offset relative to this +// node. +Node.prototype.childBefore = function childBefore (pos) { + if (pos == 0) { return {node: null, index: 0, offset: 0} } + var ref = this.content.findIndex(pos); + var index = ref.index; + var offset = ref.offset; + if (offset < pos) { return {node: this.content.child(index), index: index, offset: offset} } + var node = this.content.child(index - 1); + return {node: node, index: index - 1, offset: offset - node.nodeSize} +}; + +// :: (number) → ResolvedPos +// Resolve the given position in the document, returning an +// [object](#model.ResolvedPos) with information about its context. +Node.prototype.resolve = function resolve (pos) { return ResolvedPos.resolveCached(this, pos) }; + +Node.prototype.resolveNoCache = function resolveNoCache (pos) { return ResolvedPos.resolve(this, pos) }; + +// :: (number, number, MarkType) → bool +// Test whether a mark of the given type occurs in this document +// between the two given positions. +Node.prototype.rangeHasMark = function rangeHasMark (from, to, type) { + var found = false; + if (to > from) { this.nodesBetween(from, to, function (node) { + if (type.isInSet(node.marks)) { found = true; } + return !found + }); } + return found +}; + +// :: bool +// True when this is a block (non-inline node) +prototypeAccessors$3.isBlock.get = function () { return this.type.isBlock }; + +// :: bool +// True when this is a textblock node, a block node with inline +// content. +prototypeAccessors$3.isTextblock.get = function () { return this.type.isTextblock }; + +// :: bool +// True when this node allows inline content. +prototypeAccessors$3.inlineContent.get = function () { return this.type.inlineContent }; + +// :: bool +// True when this is an inline node (a text node or a node that can +// appear among text). +prototypeAccessors$3.isInline.get = function () { return this.type.isInline }; + +// :: bool +// True when this is a text node. +prototypeAccessors$3.isText.get = function () { return this.type.isText }; + +// :: bool +// True when this is a leaf node. +prototypeAccessors$3.isLeaf.get = function () { return this.type.isLeaf }; + +// :: bool +// True when this is an atom, i.e. when it does not have directly +// editable content. This is usually the same as `isLeaf`, but can +// be configured with the [`atom` property](#model.NodeSpec.atom) on +// a node's spec (typically used when the node is displayed as an +// uneditable [node view](#view.NodeView)). +prototypeAccessors$3.isAtom.get = function () { return this.type.isAtom }; + +// :: () → string +// Return a string representation of this node for debugging +// purposes. +Node.prototype.toString = function toString () { + if (this.type.spec.toDebugString) { return this.type.spec.toDebugString(this) } + var name = this.type.name; + if (this.content.size) + { name += "(" + this.content.toStringInner() + ")"; } + return wrapMarks(this.marks, name) +}; + +// :: (number) → ContentMatch +// Get the content match in this node at the given index. +Node.prototype.contentMatchAt = function contentMatchAt (index) { + var match = this.type.contentMatch.matchFragment(this.content, 0, index); + if (!match) { throw new Error("Called contentMatchAt on a node with invalid content") } + return match +}; + +// :: (number, number, ?Fragment, ?number, ?number) → bool +// Test whether replacing the range between `from` and `to` (by +// child index) with the given replacement fragment (which defaults +// to the empty fragment) would leave the node's content valid. You +// can optionally pass `start` and `end` indices into the +// replacement fragment. +Node.prototype.canReplace = function canReplace (from, to, replacement, start, end) { + if ( replacement === void 0 ) replacement = Fragment.empty; + if ( start === void 0 ) start = 0; + if ( end === void 0 ) end = replacement.childCount; + + var one = this.contentMatchAt(from).matchFragment(replacement, start, end); + var two = one && one.matchFragment(this.content, to); + if (!two || !two.validEnd) { return false } + for (var i = start; i < end; i++) { if (!this.type.allowsMarks(replacement.child(i).marks)) { return false } } + return true +}; + +// :: (number, number, NodeType, ?[Mark]) → bool +// Test whether replacing the range `from` to `to` (by index) with a +// node of the given type would leave the node's content valid. +Node.prototype.canReplaceWith = function canReplaceWith (from, to, type, marks) { + if (marks && !this.type.allowsMarks(marks)) { return false } + var start = this.contentMatchAt(from).matchType(type); + var end = start && start.matchFragment(this.content, to); + return end ? end.validEnd : false +}; + +// :: (Node) → bool +// Test whether the given node's content could be appended to this +// node. If that node is empty, this will only return true if there +// is at least one node type that can appear in both nodes (to avoid +// merging completely incompatible nodes). +Node.prototype.canAppend = function canAppend (other) { + if (other.content.size) { return this.canReplace(this.childCount, this.childCount, other.content) } + else { return this.type.compatibleContent(other.type) } +}; + +// Unused. Left for backwards compatibility. +Node.prototype.defaultContentType = function defaultContentType (at) { + return this.contentMatchAt(at).defaultType +}; + +// :: () +// Check whether this node and its descendants conform to the +// schema, and raise error when they do not. +Node.prototype.check = function check () { + if (!this.type.validContent(this.content)) + { throw new RangeError(("Invalid content for node " + (this.type.name) + ": " + (this.content.toString().slice(0, 50)))) } + this.content.forEach(function (node) { return node.check(); }); +}; + +// :: () → Object +// Return a JSON-serializeable representation of this node. +Node.prototype.toJSON = function toJSON () { + var obj = {type: this.type.name}; + for (var _ in this.attrs) { + obj.attrs = this.attrs; + break + } + if (this.content.size) + { obj.content = this.content.toJSON(); } + if (this.marks.length) + { obj.marks = this.marks.map(function (n) { return n.toJSON(); }); } + return obj +}; + +// :: (Schema, Object) → Node +// Deserialize a node from its JSON representation. +Node.fromJSON = function fromJSON (schema, json) { + if (!json) { throw new RangeError("Invalid input for Node.fromJSON") } + var marks = null; + if (json.marks) { + if (!Array.isArray(json.marks)) { throw new RangeError("Invalid mark data for Node.fromJSON") } + marks = json.marks.map(schema.markFromJSON); + } + if (json.type == "text") { + if (typeof json.text != "string") { throw new RangeError("Invalid text node in JSON") } + return schema.text(json.text, marks) + } + var content = Fragment.fromJSON(schema, json.content); + return schema.nodeType(json.type).create(json.attrs, content, marks) +}; + +Object.defineProperties( Node.prototype, prototypeAccessors$3 ); + +var TextNode = /*@__PURE__*/(function (Node) { + function TextNode(type, attrs, content, marks) { + Node.call(this, type, attrs, null, marks); + + if (!content) { throw new RangeError("Empty text nodes are not allowed") } + + this.text = content; + } + + if ( Node ) TextNode.__proto__ = Node; + TextNode.prototype = Object.create( Node && Node.prototype ); + TextNode.prototype.constructor = TextNode; + + var prototypeAccessors$1 = { textContent: { configurable: true },nodeSize: { configurable: true } }; + + TextNode.prototype.toString = function toString () { + if (this.type.spec.toDebugString) { return this.type.spec.toDebugString(this) } + return wrapMarks(this.marks, JSON.stringify(this.text)) + }; + + prototypeAccessors$1.textContent.get = function () { return this.text }; + + TextNode.prototype.textBetween = function textBetween (from, to) { return this.text.slice(from, to) }; + + prototypeAccessors$1.nodeSize.get = function () { return this.text.length }; + + TextNode.prototype.mark = function mark (marks) { + return marks == this.marks ? this : new TextNode(this.type, this.attrs, this.text, marks) + }; + + TextNode.prototype.withText = function withText (text) { + if (text == this.text) { return this } + return new TextNode(this.type, this.attrs, text, this.marks) + }; + + TextNode.prototype.cut = function cut (from, to) { + if ( from === void 0 ) from = 0; + if ( to === void 0 ) to = this.text.length; + + if (from == 0 && to == this.text.length) { return this } + return this.withText(this.text.slice(from, to)) + }; + + TextNode.prototype.eq = function eq (other) { + return this.sameMarkup(other) && this.text == other.text + }; + + TextNode.prototype.toJSON = function toJSON () { + var base = Node.prototype.toJSON.call(this); + base.text = this.text; + return base + }; + + Object.defineProperties( TextNode.prototype, prototypeAccessors$1 ); + + return TextNode; +}(Node)); + +function wrapMarks(marks, str) { + for (var i = marks.length - 1; i >= 0; i--) + { str = marks[i].type.name + "(" + str + ")"; } + return str +} + +// ::- Instances of this class represent a match state of a node +// type's [content expression](#model.NodeSpec.content), and can be +// used to find out whether further content matches here, and whether +// a given position is a valid end of the node. +var ContentMatch = function ContentMatch(validEnd) { + // :: bool + // True when this match state represents a valid end of the node. + this.validEnd = validEnd; + this.next = []; + this.wrapCache = []; +}; + +var prototypeAccessors$4 = { inlineContent: { configurable: true },defaultType: { configurable: true },edgeCount: { configurable: true } }; + +ContentMatch.parse = function parse (string, nodeTypes) { + var stream = new TokenStream(string, nodeTypes); + if (stream.next == null) { return ContentMatch.empty } + var expr = parseExpr(stream); + if (stream.next) { stream.err("Unexpected trailing text"); } + var match = dfa(nfa(expr)); + checkForDeadEnds(match, stream); + return match +}; + +// :: (NodeType) → ?ContentMatch +// Match a node type, returning a match after that node if +// successful. +ContentMatch.prototype.matchType = function matchType (type) { + for (var i = 0; i < this.next.length; i += 2) + { if (this.next[i] == type) { return this.next[i + 1] } } + return null +}; + +// :: (Fragment, ?number, ?number) → ?ContentMatch +// Try to match a fragment. Returns the resulting match when +// successful. +ContentMatch.prototype.matchFragment = function matchFragment (frag, start, end) { + if ( start === void 0 ) start = 0; + if ( end === void 0 ) end = frag.childCount; + + var cur = this; + for (var i = start; cur && i < end; i++) + { cur = cur.matchType(frag.child(i).type); } + return cur +}; + +prototypeAccessors$4.inlineContent.get = function () { + var first = this.next[0]; + return first ? first.isInline : false +}; + +// :: ?NodeType +// Get the first matching node type at this match position that can +// be generated. +prototypeAccessors$4.defaultType.get = function () { + for (var i = 0; i < this.next.length; i += 2) { + var type = this.next[i]; + if (!(type.isText || type.hasRequiredAttrs())) { return type } + } +}; + +ContentMatch.prototype.compatible = function compatible (other) { + for (var i = 0; i < this.next.length; i += 2) + { for (var j = 0; j < other.next.length; j += 2) + { if (this.next[i] == other.next[j]) { return true } } } + return false +}; + +// :: (Fragment, bool, ?number) → ?Fragment +// Try to match the given fragment, and if that fails, see if it can +// be made to match by inserting nodes in front of it. When +// successful, return a fragment of inserted nodes (which may be +// empty if nothing had to be inserted). When `toEnd` is true, only +// return a fragment if the resulting match goes to the end of the +// content expression. +ContentMatch.prototype.fillBefore = function fillBefore (after, toEnd, startIndex) { + if ( toEnd === void 0 ) toEnd = false; + if ( startIndex === void 0 ) startIndex = 0; + + var seen = [this]; + function search(match, types) { + var finished = match.matchFragment(after, startIndex); + if (finished && (!toEnd || finished.validEnd)) + { return Fragment.from(types.map(function (tp) { return tp.createAndFill(); })) } + + for (var i = 0; i < match.next.length; i += 2) { + var type = match.next[i], next = match.next[i + 1]; + if (!(type.isText || type.hasRequiredAttrs()) && seen.indexOf(next) == -1) { + seen.push(next); + var found = search(next, types.concat(type)); + if (found) { return found } + } + } + } + + return search(this, []) +}; + +// :: (NodeType) → ?[NodeType] +// Find a set of wrapping node types that would allow a node of the +// given type to appear at this position. The result may be empty +// (when it fits directly) and will be null when no such wrapping +// exists. +ContentMatch.prototype.findWrapping = function findWrapping (target) { + for (var i = 0; i < this.wrapCache.length; i += 2) + { if (this.wrapCache[i] == target) { return this.wrapCache[i + 1] } } + var computed = this.computeWrapping(target); + this.wrapCache.push(target, computed); + return computed +}; + +ContentMatch.prototype.computeWrapping = function computeWrapping (target) { + var seen = Object.create(null), active = [{match: this, type: null, via: null}]; + while (active.length) { + var current = active.shift(), match = current.match; + if (match.matchType(target)) { + var result = []; + for (var obj = current; obj.type; obj = obj.via) + { result.push(obj.type); } + return result.reverse() + } + for (var i = 0; i < match.next.length; i += 2) { + var type = match.next[i]; + if (!type.isLeaf && !type.hasRequiredAttrs() && !(type.name in seen) && (!current.type || match.next[i + 1].validEnd)) { + active.push({match: type.contentMatch, type: type, via: current}); + seen[type.name] = true; + } + } + } +}; + +// :: number +// The number of outgoing edges this node has in the finite +// automaton that describes the content expression. +prototypeAccessors$4.edgeCount.get = function () { + return this.next.length >> 1 +}; + +// :: (number) → {type: NodeType, next: ContentMatch} +// Get the _n_​th outgoing edge from this node in the finite +// automaton that describes the content expression. +ContentMatch.prototype.edge = function edge (n) { + var i = n << 1; + if (i >= this.next.length) { throw new RangeError(("There's no " + n + "th edge in this content match")) } + return {type: this.next[i], next: this.next[i + 1]} +}; + +ContentMatch.prototype.toString = function toString () { + var seen = []; + function scan(m) { + seen.push(m); + for (var i = 1; i < m.next.length; i += 2) + { if (seen.indexOf(m.next[i]) == -1) { scan(m.next[i]); } } + } + scan(this); + return seen.map(function (m, i) { + var out = i + (m.validEnd ? "*" : " ") + " "; + for (var i$1 = 0; i$1 < m.next.length; i$1 += 2) + { out += (i$1 ? ", " : "") + m.next[i$1].name + "->" + seen.indexOf(m.next[i$1 + 1]); } + return out + }).join("\n") +}; + +Object.defineProperties( ContentMatch.prototype, prototypeAccessors$4 ); + +ContentMatch.empty = new ContentMatch(true); + +var TokenStream = function TokenStream(string, nodeTypes) { + this.string = string; + this.nodeTypes = nodeTypes; + this.inline = null; + this.pos = 0; + this.tokens = string.split(/\s*(?=\b|\W|$)/); + if (this.tokens[this.tokens.length - 1] == "") { this.tokens.pop(); } + if (this.tokens[0] == "") { this.tokens.unshift(); } +}; + +var prototypeAccessors$1$2 = { next: { configurable: true } }; + +prototypeAccessors$1$2.next.get = function () { return this.tokens[this.pos] }; + +TokenStream.prototype.eat = function eat (tok) { return this.next == tok && (this.pos++ || true) }; + +TokenStream.prototype.err = function err (str) { throw new SyntaxError(str + " (in content expression '" + this.string + "')") }; + +Object.defineProperties( TokenStream.prototype, prototypeAccessors$1$2 ); + +function parseExpr(stream) { + var exprs = []; + do { exprs.push(parseExprSeq(stream)); } + while (stream.eat("|")) + return exprs.length == 1 ? exprs[0] : {type: "choice", exprs: exprs} +} + +function parseExprSeq(stream) { + var exprs = []; + do { exprs.push(parseExprSubscript(stream)); } + while (stream.next && stream.next != ")" && stream.next != "|") + return exprs.length == 1 ? exprs[0] : {type: "seq", exprs: exprs} +} + +function parseExprSubscript(stream) { + var expr = parseExprAtom(stream); + for (;;) { + if (stream.eat("+")) + { expr = {type: "plus", expr: expr}; } + else if (stream.eat("*")) + { expr = {type: "star", expr: expr}; } + else if (stream.eat("?")) + { expr = {type: "opt", expr: expr}; } + else if (stream.eat("{")) + { expr = parseExprRange(stream, expr); } + else { break } + } + return expr +} + +function parseNum(stream) { + if (/\D/.test(stream.next)) { stream.err("Expected number, got '" + stream.next + "'"); } + var result = Number(stream.next); + stream.pos++; + return result +} + +function parseExprRange(stream, expr) { + var min = parseNum(stream), max = min; + if (stream.eat(",")) { + if (stream.next != "}") { max = parseNum(stream); } + else { max = -1; } + } + if (!stream.eat("}")) { stream.err("Unclosed braced range"); } + return {type: "range", min: min, max: max, expr: expr} +} + +function resolveName(stream, name) { + var types = stream.nodeTypes, type = types[name]; + if (type) { return [type] } + var result = []; + for (var typeName in types) { + var type$1 = types[typeName]; + if (type$1.groups.indexOf(name) > -1) { result.push(type$1); } + } + if (result.length == 0) { stream.err("No node type or group '" + name + "' found"); } + return result +} + +function parseExprAtom(stream) { + if (stream.eat("(")) { + var expr = parseExpr(stream); + if (!stream.eat(")")) { stream.err("Missing closing paren"); } + return expr + } else if (!/\W/.test(stream.next)) { + var exprs = resolveName(stream, stream.next).map(function (type) { + if (stream.inline == null) { stream.inline = type.isInline; } + else if (stream.inline != type.isInline) { stream.err("Mixing inline and block content"); } + return {type: "name", value: type} + }); + stream.pos++; + return exprs.length == 1 ? exprs[0] : {type: "choice", exprs: exprs} + } else { + stream.err("Unexpected token '" + stream.next + "'"); + } +} + +// The code below helps compile a regular-expression-like language +// into a deterministic finite automaton. For a good introduction to +// these concepts, see https://swtch.com/~rsc/regexp/regexp1.html + +// : (Object) → [[{term: ?any, to: number}]] +// Construct an NFA from an expression as returned by the parser. The +// NFA is represented as an array of states, which are themselves +// arrays of edges, which are `{term, to}` objects. The first state is +// the entry state and the last node is the success state. +// +// Note that unlike typical NFAs, the edge ordering in this one is +// significant, in that it is used to contruct filler content when +// necessary. +function nfa(expr) { + var nfa = [[]]; + connect(compile(expr, 0), node()); + return nfa + + function node() { return nfa.push([]) - 1 } + function edge(from, to, term) { + var edge = {term: term, to: to}; + nfa[from].push(edge); + return edge + } + function connect(edges, to) { edges.forEach(function (edge) { return edge.to = to; }); } + + function compile(expr, from) { + if (expr.type == "choice") { + return expr.exprs.reduce(function (out, expr) { return out.concat(compile(expr, from)); }, []) + } else if (expr.type == "seq") { + for (var i = 0;; i++) { + var next = compile(expr.exprs[i], from); + if (i == expr.exprs.length - 1) { return next } + connect(next, from = node()); + } + } else if (expr.type == "star") { + var loop = node(); + edge(from, loop); + connect(compile(expr.expr, loop), loop); + return [edge(loop)] + } else if (expr.type == "plus") { + var loop$1 = node(); + connect(compile(expr.expr, from), loop$1); + connect(compile(expr.expr, loop$1), loop$1); + return [edge(loop$1)] + } else if (expr.type == "opt") { + return [edge(from)].concat(compile(expr.expr, from)) + } else if (expr.type == "range") { + var cur = from; + for (var i$1 = 0; i$1 < expr.min; i$1++) { + var next$1 = node(); + connect(compile(expr.expr, cur), next$1); + cur = next$1; + } + if (expr.max == -1) { + connect(compile(expr.expr, cur), cur); + } else { + for (var i$2 = expr.min; i$2 < expr.max; i$2++) { + var next$2 = node(); + edge(cur, next$2); + connect(compile(expr.expr, cur), next$2); + cur = next$2; + } + } + return [edge(cur)] + } else if (expr.type == "name") { + return [edge(from, null, expr.value)] + } + } +} + +function cmp(a, b) { return b - a } + +// Get the set of nodes reachable by null edges from `node`. Omit +// nodes with only a single null-out-edge, since they may lead to +// needless duplicated nodes. +function nullFrom(nfa, node) { + var result = []; + scan(node); + return result.sort(cmp) + + function scan(node) { + var edges = nfa[node]; + if (edges.length == 1 && !edges[0].term) { return scan(edges[0].to) } + result.push(node); + for (var i = 0; i < edges.length; i++) { + var ref = edges[i]; + var term = ref.term; + var to = ref.to; + if (!term && result.indexOf(to) == -1) { scan(to); } + } + } +} + +// : ([[{term: ?any, to: number}]]) → ContentMatch +// Compiles an NFA as produced by `nfa` into a DFA, modeled as a set +// of state objects (`ContentMatch` instances) with transitions +// between them. +function dfa(nfa) { + var labeled = Object.create(null); + return explore(nullFrom(nfa, 0)) + + function explore(states) { + var out = []; + states.forEach(function (node) { + nfa[node].forEach(function (ref) { + var term = ref.term; + var to = ref.to; + + if (!term) { return } + var known = out.indexOf(term), set = known > -1 && out[known + 1]; + nullFrom(nfa, to).forEach(function (node) { + if (!set) { out.push(term, set = []); } + if (set.indexOf(node) == -1) { set.push(node); } + }); + }); + }); + var state = labeled[states.join(",")] = new ContentMatch(states.indexOf(nfa.length - 1) > -1); + for (var i = 0; i < out.length; i += 2) { + var states$1 = out[i + 1].sort(cmp); + state.next.push(out[i], labeled[states$1.join(",")] || explore(states$1)); + } + return state + } +} + +function checkForDeadEnds(match, stream) { + for (var i = 0, work = [match]; i < work.length; i++) { + var state = work[i], dead = !state.validEnd, nodes = []; + for (var j = 0; j < state.next.length; j += 2) { + var node = state.next[j], next = state.next[j + 1]; + nodes.push(node.name); + if (dead && !(node.isText || node.hasRequiredAttrs())) { dead = false; } + if (work.indexOf(next) == -1) { work.push(next); } + } + if (dead) { stream.err("Only non-generatable nodes (" + nodes.join(", ") + ") in a required position"); } + } +} + +// For node types where all attrs have a default value (or which don't +// have any attributes), build up a single reusable default attribute +// object, and use it for all nodes that don't specify specific +// attributes. +function defaultAttrs(attrs) { + var defaults = Object.create(null); + for (var attrName in attrs) { + var attr = attrs[attrName]; + if (!attr.hasDefault) { return null } + defaults[attrName] = attr.default; + } + return defaults +} + +function computeAttrs(attrs, value) { + var built = Object.create(null); + for (var name in attrs) { + var given = value && value[name]; + if (given === undefined) { + var attr = attrs[name]; + if (attr.hasDefault) { given = attr.default; } + else { throw new RangeError("No value supplied for attribute " + name) } + } + built[name] = given; + } + return built +} + +function initAttrs(attrs) { + var result = Object.create(null); + if (attrs) { for (var name in attrs) { result[name] = new Attribute(attrs[name]); } } + return result +} + +// ::- Node types are objects allocated once per `Schema` and used to +// [tag](#model.Node.type) `Node` instances. They contain information +// about the node type, such as its name and what kind of node it +// represents. +var NodeType = function NodeType(name, schema, spec) { + // :: string + // The name the node type has in this schema. + this.name = name; + + // :: Schema + // A link back to the `Schema` the node type belongs to. + this.schema = schema; + + // :: NodeSpec + // The spec that this type is based on + this.spec = spec; + + this.groups = spec.group ? spec.group.split(" ") : []; + this.attrs = initAttrs(spec.attrs); + + this.defaultAttrs = defaultAttrs(this.attrs); + + // :: ContentMatch + // The starting match of the node type's content expression. + this.contentMatch = null; + + // : ?[MarkType] + // The set of marks allowed in this node. `null` means all marks + // are allowed. + this.markSet = null; + + // :: bool + // True if this node type has inline content. + this.inlineContent = null; + + // :: bool + // True if this is a block type + this.isBlock = !(spec.inline || name == "text"); + + // :: bool + // True if this is the text node type. + this.isText = name == "text"; +}; + +var prototypeAccessors$5 = { isInline: { configurable: true },isTextblock: { configurable: true },isLeaf: { configurable: true },isAtom: { configurable: true } }; + +// :: bool +// True if this is an inline type. +prototypeAccessors$5.isInline.get = function () { return !this.isBlock }; + +// :: bool +// True if this is a textblock type, a block that contains inline +// content. +prototypeAccessors$5.isTextblock.get = function () { return this.isBlock && this.inlineContent }; + +// :: bool +// True for node types that allow no content. +prototypeAccessors$5.isLeaf.get = function () { return this.contentMatch == ContentMatch.empty }; + +// :: bool +// True when this node is an atom, i.e. when it does not have +// directly editable content. +prototypeAccessors$5.isAtom.get = function () { return this.isLeaf || this.spec.atom }; + +NodeType.prototype.hasRequiredAttrs = function hasRequiredAttrs (ignore) { + for (var n in this.attrs) + { if (this.attrs[n].isRequired && (!ignore || !(n in ignore))) { return true } } + return false +}; + +NodeType.prototype.compatibleContent = function compatibleContent (other) { + return this == other || this.contentMatch.compatible(other.contentMatch) +}; + +NodeType.prototype.computeAttrs = function computeAttrs$1 (attrs) { + if (!attrs && this.defaultAttrs) { return this.defaultAttrs } + else { return computeAttrs(this.attrs, attrs) } +}; + +// :: (?Object, ?union, ?[Mark]) → Node +// Create a `Node` of this type. The given attributes are +// checked and defaulted (you can pass `null` to use the type's +// defaults entirely, if no required attributes exist). `content` +// may be a `Fragment`, a node, an array of nodes, or +// `null`. Similarly `marks` may be `null` to default to the empty +// set of marks. +NodeType.prototype.create = function create (attrs, content, marks) { + if (this.isText) { throw new Error("NodeType.create can't construct text nodes") } + return new Node(this, this.computeAttrs(attrs), Fragment.from(content), Mark.setFrom(marks)) +}; + +// :: (?Object, ?union, ?[Mark]) → Node +// Like [`create`](#model.NodeType.create), but check the given content +// against the node type's content restrictions, and throw an error +// if it doesn't match. +NodeType.prototype.createChecked = function createChecked (attrs, content, marks) { + content = Fragment.from(content); + if (!this.validContent(content)) + { throw new RangeError("Invalid content for node " + this.name) } + return new Node(this, this.computeAttrs(attrs), content, Mark.setFrom(marks)) +}; + +// :: (?Object, ?union, ?[Mark]) → ?Node +// Like [`create`](#model.NodeType.create), but see if it is necessary to +// add nodes to the start or end of the given fragment to make it +// fit the node. If no fitting wrapping can be found, return null. +// Note that, due to the fact that required nodes can always be +// created, this will always succeed if you pass null or +// `Fragment.empty` as content. +NodeType.prototype.createAndFill = function createAndFill (attrs, content, marks) { + attrs = this.computeAttrs(attrs); + content = Fragment.from(content); + if (content.size) { + var before = this.contentMatch.fillBefore(content); + if (!before) { return null } + content = before.append(content); + } + var after = this.contentMatch.matchFragment(content).fillBefore(Fragment.empty, true); + if (!after) { return null } + return new Node(this, attrs, content.append(after), Mark.setFrom(marks)) +}; + +// :: (Fragment) → bool +// Returns true if the given fragment is valid content for this node +// type with the given attributes. +NodeType.prototype.validContent = function validContent (content) { + var result = this.contentMatch.matchFragment(content); + if (!result || !result.validEnd) { return false } + for (var i = 0; i < content.childCount; i++) + { if (!this.allowsMarks(content.child(i).marks)) { return false } } + return true +}; + +// :: (MarkType) → bool +// Check whether the given mark type is allowed in this node. +NodeType.prototype.allowsMarkType = function allowsMarkType (markType) { + return this.markSet == null || this.markSet.indexOf(markType) > -1 +}; + +// :: ([Mark]) → bool +// Test whether the given set of marks are allowed in this node. +NodeType.prototype.allowsMarks = function allowsMarks (marks) { + if (this.markSet == null) { return true } + for (var i = 0; i < marks.length; i++) { if (!this.allowsMarkType(marks[i].type)) { return false } } + return true +}; + +// :: ([Mark]) → [Mark] +// Removes the marks that are not allowed in this node from the given set. +NodeType.prototype.allowedMarks = function allowedMarks (marks) { + if (this.markSet == null) { return marks } + var copy; + for (var i = 0; i < marks.length; i++) { + if (!this.allowsMarkType(marks[i].type)) { + if (!copy) { copy = marks.slice(0, i); } + } else if (copy) { + copy.push(marks[i]); + } + } + return !copy ? marks : copy.length ? copy : Mark.empty +}; + +NodeType.compile = function compile (nodes, schema) { + var result = Object.create(null); + nodes.forEach(function (name, spec) { return result[name] = new NodeType(name, schema, spec); }); + + var topType = schema.spec.topNode || "doc"; + if (!result[topType]) { throw new RangeError("Schema is missing its top node type ('" + topType + "')") } + if (!result.text) { throw new RangeError("Every schema needs a 'text' type") } + for (var _ in result.text.attrs) { throw new RangeError("The text node type should not have attributes") } + + return result +}; + +Object.defineProperties( NodeType.prototype, prototypeAccessors$5 ); + +// Attribute descriptors + +var Attribute = function Attribute(options) { + this.hasDefault = Object.prototype.hasOwnProperty.call(options, "default"); + this.default = options.default; +}; + +var prototypeAccessors$1$3 = { isRequired: { configurable: true } }; + +prototypeAccessors$1$3.isRequired.get = function () { + return !this.hasDefault +}; + +Object.defineProperties( Attribute.prototype, prototypeAccessors$1$3 ); + +// Marks + +// ::- Like nodes, marks (which are associated with nodes to signify +// things like emphasis or being part of a link) are +// [tagged](#model.Mark.type) with type objects, which are +// instantiated once per `Schema`. +var MarkType = function MarkType(name, rank, schema, spec) { + // :: string + // The name of the mark type. + this.name = name; + + // :: Schema + // The schema that this mark type instance is part of. + this.schema = schema; + + // :: MarkSpec + // The spec on which the type is based. + this.spec = spec; + + this.attrs = initAttrs(spec.attrs); + + this.rank = rank; + this.excluded = null; + var defaults = defaultAttrs(this.attrs); + this.instance = defaults && new Mark(this, defaults); +}; + +// :: (?Object) → Mark +// Create a mark of this type. `attrs` may be `null` or an object +// containing only some of the mark's attributes. The others, if +// they have defaults, will be added. +MarkType.prototype.create = function create (attrs) { + if (!attrs && this.instance) { return this.instance } + return new Mark(this, computeAttrs(this.attrs, attrs)) +}; + +MarkType.compile = function compile (marks, schema) { + var result = Object.create(null), rank = 0; + marks.forEach(function (name, spec) { return result[name] = new MarkType(name, rank++, schema, spec); }); + return result +}; + +// :: ([Mark]) → [Mark] +// When there is a mark of this type in the given set, a new set +// without it is returned. Otherwise, the input set is returned. +MarkType.prototype.removeFromSet = function removeFromSet (set) { + for (var i = 0; i < set.length; i++) + { if (set[i].type == this) + { return set.slice(0, i).concat(set.slice(i + 1)) } } + return set +}; + +// :: ([Mark]) → ?Mark +// Tests whether there is a mark of this type in the given set. +MarkType.prototype.isInSet = function isInSet (set) { + for (var i = 0; i < set.length; i++) + { if (set[i].type == this) { return set[i] } } +}; + +// :: (MarkType) → bool +// Queries whether a given mark type is +// [excluded](#model.MarkSpec.excludes) by this one. +MarkType.prototype.excludes = function excludes (other) { + return this.excluded.indexOf(other) > -1 +}; + +// SchemaSpec:: interface +// An object describing a schema, as passed to the [`Schema`](#model.Schema) +// constructor. +// +// nodes:: union, OrderedMap> +// The node types in this schema. Maps names to +// [`NodeSpec`](#model.NodeSpec) objects that describe the node type +// associated with that name. Their order is significant—it +// determines which [parse rules](#model.NodeSpec.parseDOM) take +// precedence by default, and which nodes come first in a given +// [group](#model.NodeSpec.group). +// +// marks:: ?union, OrderedMap> +// The mark types that exist in this schema. The order in which they +// are provided determines the order in which [mark +// sets](#model.Mark.addToSet) are sorted and in which [parse +// rules](#model.MarkSpec.parseDOM) are tried. +// +// topNode:: ?string +// The name of the default top-level node for the schema. Defaults +// to `"doc"`. + +// NodeSpec:: interface +// +// content:: ?string +// The content expression for this node, as described in the [schema +// guide](/docs/guide/#schema.content_expressions). When not given, +// the node does not allow any content. +// +// marks:: ?string +// The marks that are allowed inside of this node. May be a +// space-separated string referring to mark names or groups, `"_"` +// to explicitly allow all marks, or `""` to disallow marks. When +// not given, nodes with inline content default to allowing all +// marks, other nodes default to not allowing marks. +// +// group:: ?string +// The group or space-separated groups to which this node belongs, +// which can be referred to in the content expressions for the +// schema. +// +// inline:: ?bool +// Should be set to true for inline nodes. (Implied for text nodes.) +// +// atom:: ?bool +// Can be set to true to indicate that, though this isn't a [leaf +// node](#model.NodeType.isLeaf), it doesn't have directly editable +// content and should be treated as a single unit in the view. +// +// attrs:: ?Object +// The attributes that nodes of this type get. +// +// selectable:: ?bool +// Controls whether nodes of this type can be selected as a [node +// selection](#state.NodeSelection). Defaults to true for non-text +// nodes. +// +// draggable:: ?bool +// Determines whether nodes of this type can be dragged without +// being selected. Defaults to false. +// +// code:: ?bool +// Can be used to indicate that this node contains code, which +// causes some commands to behave differently. +// +// defining:: ?bool +// Determines whether this node is considered an important parent +// node during replace operations (such as paste). Non-defining (the +// default) nodes get dropped when their entire content is replaced, +// whereas defining nodes persist and wrap the inserted content. +// Likewise, in _inserted_ content the defining parents of the +// content are preserved when possible. Typically, +// non-default-paragraph textblock types, and possibly list items, +// are marked as defining. +// +// isolating:: ?bool +// When enabled (default is false), the sides of nodes of this type +// count as boundaries that regular editing operations, like +// backspacing or lifting, won't cross. An example of a node that +// should probably have this enabled is a table cell. +// +// toDOM:: ?(node: Node) → DOMOutputSpec +// Defines the default way a node of this type should be serialized +// to DOM/HTML (as used by +// [`DOMSerializer.fromSchema`](#model.DOMSerializer^fromSchema)). +// Should return a DOM node or an [array +// structure](#model.DOMOutputSpec) that describes one, with an +// optional number zero (“hole”) in it to indicate where the node's +// content should be inserted. +// +// For text nodes, the default is to create a text DOM node. Though +// it is possible to create a serializer where text is rendered +// differently, this is not supported inside the editor, so you +// shouldn't override that in your text node spec. +// +// parseDOM:: ?[ParseRule] +// Associates DOM parser information with this node, which can be +// used by [`DOMParser.fromSchema`](#model.DOMParser^fromSchema) to +// automatically derive a parser. The `node` field in the rules is +// implied (the name of this node will be filled in automatically). +// If you supply your own parser, you do not need to also specify +// parsing rules in your schema. +// +// toDebugString:: ?(node: Node) -> string +// Defines the default way a node of this type should be serialized +// to a string representation for debugging (e.g. in error messages). + +// MarkSpec:: interface +// +// attrs:: ?Object +// The attributes that marks of this type get. +// +// inclusive:: ?bool +// Whether this mark should be active when the cursor is positioned +// at its end (or at its start when that is also the start of the +// parent node). Defaults to true. +// +// excludes:: ?string +// Determines which other marks this mark can coexist with. Should +// be a space-separated strings naming other marks or groups of marks. +// When a mark is [added](#model.Mark.addToSet) to a set, all marks +// that it excludes are removed in the process. If the set contains +// any mark that excludes the new mark but is not, itself, excluded +// by the new mark, the mark can not be added an the set. You can +// use the value `"_"` to indicate that the mark excludes all +// marks in the schema. +// +// Defaults to only being exclusive with marks of the same type. You +// can set it to an empty string (or any string not containing the +// mark's own name) to allow multiple marks of a given type to +// coexist (as long as they have different attributes). +// +// group:: ?string +// The group or space-separated groups to which this mark belongs. +// +// spanning:: ?bool +// Determines whether marks of this type can span multiple adjacent +// nodes when serialized to DOM/HTML. Defaults to true. +// +// toDOM:: ?(mark: Mark, inline: bool) → DOMOutputSpec +// Defines the default way marks of this type should be serialized +// to DOM/HTML. When the resulting spec contains a hole, that is +// where the marked content is placed. Otherwise, it is appended to +// the top node. +// +// parseDOM:: ?[ParseRule] +// Associates DOM parser information with this mark (see the +// corresponding [node spec field](#model.NodeSpec.parseDOM)). The +// `mark` field in the rules is implied. + +// AttributeSpec:: interface +// +// Used to [define](#model.NodeSpec.attrs) attributes on nodes or +// marks. +// +// default:: ?any +// The default value for this attribute, to use when no explicit +// value is provided. Attributes that have no default must be +// provided whenever a node or mark of a type that has them is +// created. + +// ::- A document schema. Holds [node](#model.NodeType) and [mark +// type](#model.MarkType) objects for the nodes and marks that may +// occur in conforming documents, and provides functionality for +// creating and deserializing such documents. +var Schema = function Schema(spec) { + // :: SchemaSpec + // The [spec](#model.SchemaSpec) on which the schema is based, + // with the added guarantee that its `nodes` and `marks` + // properties are + // [`OrderedMap`](https://github.com/marijnh/orderedmap) instances + // (not raw objects). + this.spec = {}; + for (var prop in spec) { this.spec[prop] = spec[prop]; } + this.spec.nodes = orderedmap__WEBPACK_IMPORTED_MODULE_0__["default"].from(spec.nodes); + this.spec.marks = orderedmap__WEBPACK_IMPORTED_MODULE_0__["default"].from(spec.marks); + + // :: Object + // An object mapping the schema's node names to node type objects. + this.nodes = NodeType.compile(this.spec.nodes, this); + + // :: Object + // A map from mark names to mark type objects. + this.marks = MarkType.compile(this.spec.marks, this); + + var contentExprCache = Object.create(null); + for (var prop$1 in this.nodes) { + if (prop$1 in this.marks) + { throw new RangeError(prop$1 + " can not be both a node and a mark") } + var type = this.nodes[prop$1], contentExpr = type.spec.content || "", markExpr = type.spec.marks; + type.contentMatch = contentExprCache[contentExpr] || + (contentExprCache[contentExpr] = ContentMatch.parse(contentExpr, this.nodes)); + type.inlineContent = type.contentMatch.inlineContent; + type.markSet = markExpr == "_" ? null : + markExpr ? gatherMarks(this, markExpr.split(" ")) : + markExpr == "" || !type.inlineContent ? [] : null; + } + for (var prop$2 in this.marks) { + var type$1 = this.marks[prop$2], excl = type$1.spec.excludes; + type$1.excluded = excl == null ? [type$1] : excl == "" ? [] : gatherMarks(this, excl.split(" ")); + } + + this.nodeFromJSON = this.nodeFromJSON.bind(this); + this.markFromJSON = this.markFromJSON.bind(this); + + // :: NodeType + // The type of the [default top node](#model.SchemaSpec.topNode) + // for this schema. + this.topNodeType = this.nodes[this.spec.topNode || "doc"]; + + // :: Object + // An object for storing whatever values modules may want to + // compute and cache per schema. (If you want to store something + // in it, try to use property names unlikely to clash.) + this.cached = Object.create(null); + this.cached.wrappings = Object.create(null); +}; + +// :: (union, ?Object, ?union, ?[Mark]) → Node +// Create a node in this schema. The `type` may be a string or a +// `NodeType` instance. Attributes will be extended +// with defaults, `content` may be a `Fragment`, +// `null`, a `Node`, or an array of nodes. +Schema.prototype.node = function node (type, attrs, content, marks) { + if (typeof type == "string") + { type = this.nodeType(type); } + else if (!(type instanceof NodeType)) + { throw new RangeError("Invalid node type: " + type) } + else if (type.schema != this) + { throw new RangeError("Node type from different schema used (" + type.name + ")") } + + return type.createChecked(attrs, content, marks) +}; + +// :: (string, ?[Mark]) → Node +// Create a text node in the schema. Empty text nodes are not +// allowed. +Schema.prototype.text = function text (text$1, marks) { + var type = this.nodes.text; + return new TextNode(type, type.defaultAttrs, text$1, Mark.setFrom(marks)) +}; + +// :: (union, ?Object) → Mark +// Create a mark with the given type and attributes. +Schema.prototype.mark = function mark (type, attrs) { + if (typeof type == "string") { type = this.marks[type]; } + return type.create(attrs) +}; + +// :: (Object) → Node +// Deserialize a node from its JSON representation. This method is +// bound. +Schema.prototype.nodeFromJSON = function nodeFromJSON (json) { + return Node.fromJSON(this, json) +}; + +// :: (Object) → Mark +// Deserialize a mark from its JSON representation. This method is +// bound. +Schema.prototype.markFromJSON = function markFromJSON (json) { + return Mark.fromJSON(this, json) +}; + +Schema.prototype.nodeType = function nodeType (name) { + var found = this.nodes[name]; + if (!found) { throw new RangeError("Unknown node type: " + name) } + return found +}; + +function gatherMarks(schema, marks) { + var found = []; + for (var i = 0; i < marks.length; i++) { + var name = marks[i], mark = schema.marks[name], ok = mark; + if (mark) { + found.push(mark); + } else { + for (var prop in schema.marks) { + var mark$1 = schema.marks[prop]; + if (name == "_" || (mark$1.spec.group && mark$1.spec.group.split(" ").indexOf(name) > -1)) + { found.push(ok = mark$1); } + } + } + if (!ok) { throw new SyntaxError("Unknown mark type: '" + marks[i] + "'") } + } + return found +} + +// ParseOptions:: interface +// These are the options recognized by the +// [`parse`](#model.DOMParser.parse) and +// [`parseSlice`](#model.DOMParser.parseSlice) methods. +// +// preserveWhitespace:: ?union +// By default, whitespace is collapsed as per HTML's rules. Pass +// `true` to preserve whitespace, but normalize newlines to +// spaces, and `"full"` to preserve whitespace entirely. +// +// findPositions:: ?[{node: dom.Node, offset: number}] +// When given, the parser will, beside parsing the content, +// record the document positions of the given DOM positions. It +// will do so by writing to the objects, adding a `pos` property +// that holds the document position. DOM positions that are not +// in the parsed content will not be written to. +// +// from:: ?number +// The child node index to start parsing from. +// +// to:: ?number +// The child node index to stop parsing at. +// +// topNode:: ?Node +// By default, the content is parsed into the schema's default +// [top node type](#model.Schema.topNodeType). You can pass this +// option to use the type and attributes from a different node +// as the top container. +// +// topMatch:: ?ContentMatch +// Provide the starting content match that content parsed into the +// top node is matched against. +// +// context:: ?ResolvedPos +// A set of additional nodes to count as +// [context](#model.ParseRule.context) when parsing, above the +// given [top node](#model.ParseOptions.topNode). + +// ParseRule:: interface +// A value that describes how to parse a given DOM node or inline +// style as a ProseMirror node or mark. +// +// tag:: ?string +// A CSS selector describing the kind of DOM elements to match. A +// single rule should have _either_ a `tag` or a `style` property. +// +// namespace:: ?string +// The namespace to match. This should be used with `tag`. +// Nodes are only matched when the namespace matches or this property +// is null. +// +// style:: ?string +// A CSS property name to match. When given, this rule matches +// inline styles that list that property. May also have the form +// `"property=value"`, in which case the rule only matches if the +// propery's value exactly matches the given value. (For more +// complicated filters, use [`getAttrs`](#model.ParseRule.getAttrs) +// and return false to indicate that the match failed.) +// +// priority:: ?number +// Can be used to change the order in which the parse rules in a +// schema are tried. Those with higher priority come first. Rules +// without a priority are counted as having priority 50. This +// property is only meaningful in a schema—when directly +// constructing a parser, the order of the rule array is used. +// +// context:: ?string +// When given, restricts this rule to only match when the current +// context—the parent nodes into which the content is being +// parsed—matches this expression. Should contain one or more node +// names or node group names followed by single or double slashes. +// For example `"paragraph/"` means the rule only matches when the +// parent node is a paragraph, `"blockquote/paragraph/"` restricts +// it to be in a paragraph that is inside a blockquote, and +// `"section//"` matches any position inside a section—a double +// slash matches any sequence of ancestor nodes. To allow multiple +// different contexts, they can be separated by a pipe (`|`) +// character, as in `"blockquote/|list_item/"`. +// +// node:: ?string +// The name of the node type to create when this rule matches. Only +// valid for rules with a `tag` property, not for style rules. Each +// rule should have one of a `node`, `mark`, or `ignore` property +// (except when it appears in a [node](#model.NodeSpec.parseDOM) or +// [mark spec](#model.MarkSpec.parseDOM), in which case the `node` +// or `mark` property will be derived from its position). +// +// mark:: ?string +// The name of the mark type to wrap the matched content in. +// +// ignore:: ?bool +// When true, ignore content that matches this rule. +// +// skip:: ?bool +// When true, ignore the node that matches this rule, but do parse +// its content. +// +// attrs:: ?Object +// Attributes for the node or mark created by this rule. When +// `getAttrs` is provided, it takes precedence. +// +// getAttrs:: ?(union) → ?union +// A function used to compute the attributes for the node or mark +// created by this rule. Can also be used to describe further +// conditions the DOM element or style must match. When it returns +// `false`, the rule won't match. When it returns null or undefined, +// that is interpreted as an empty/default set of attributes. +// +// Called with a DOM Element for `tag` rules, and with a string (the +// style's value) for `style` rules. +// +// contentElement:: ?union +// For `tag` rules that produce non-leaf nodes or marks, by default +// the content of the DOM element is parsed as content of the mark +// or node. If the child nodes are in a descendent node, this may be +// a CSS selector string that the parser must use to find the actual +// content element, or a function that returns the actual content +// element to the parser. +// +// getContent:: ?(dom.Node, schema: Schema) → Fragment +// Can be used to override the content of a matched node. When +// present, instead of parsing the node's child nodes, the result of +// this function is used. +// +// preserveWhitespace:: ?union +// Controls whether whitespace should be preserved when parsing the +// content inside the matched element. `false` means whitespace may +// be collapsed, `true` means that whitespace should be preserved +// but newlines normalized to spaces, and `"full"` means that +// newlines should also be preserved. + +// ::- A DOM parser represents a strategy for parsing DOM content into +// a ProseMirror document conforming to a given schema. Its behavior +// is defined by an array of [rules](#model.ParseRule). +var DOMParser = function DOMParser(schema, rules) { + var this$1 = this; + + // :: Schema + // The schema into which the parser parses. + this.schema = schema; + // :: [ParseRule] + // The set of [parse rules](#model.ParseRule) that the parser + // uses, in order of precedence. + this.rules = rules; + this.tags = []; + this.styles = []; + + rules.forEach(function (rule) { + if (rule.tag) { this$1.tags.push(rule); } + else if (rule.style) { this$1.styles.push(rule); } + }); +}; + +// :: (dom.Node, ?ParseOptions) → Node +// Parse a document from the content of a DOM node. +DOMParser.prototype.parse = function parse (dom, options) { + if ( options === void 0 ) options = {}; + + var context = new ParseContext(this, options, false); + context.addAll(dom, null, options.from, options.to); + return context.finish() +}; + +// :: (dom.Node, ?ParseOptions) → Slice +// Parses the content of the given DOM node, like +// [`parse`](#model.DOMParser.parse), and takes the same set of +// options. But unlike that method, which produces a whole node, +// this one returns a slice that is open at the sides, meaning that +// the schema constraints aren't applied to the start of nodes to +// the left of the input and the end of nodes at the end. +DOMParser.prototype.parseSlice = function parseSlice (dom, options) { + if ( options === void 0 ) options = {}; + + var context = new ParseContext(this, options, true); + context.addAll(dom, null, options.from, options.to); + return Slice.maxOpen(context.finish()) +}; + +DOMParser.prototype.matchTag = function matchTag (dom, context) { + for (var i = 0; i < this.tags.length; i++) { + var rule = this.tags[i]; + if (matches(dom, rule.tag) && + (rule.namespace === undefined || dom.namespaceURI == rule.namespace) && + (!rule.context || context.matchesContext(rule.context))) { + if (rule.getAttrs) { + var result = rule.getAttrs(dom); + if (result === false) { continue } + rule.attrs = result; + } + return rule + } + } +}; + +DOMParser.prototype.matchStyle = function matchStyle (prop, value, context) { + for (var i = 0; i < this.styles.length; i++) { + var rule = this.styles[i]; + if (rule.style.indexOf(prop) != 0 || + rule.context && !context.matchesContext(rule.context) || + // Test that the style string either precisely matches the prop, + // or has an '=' sign after the prop, followed by the given + // value. + rule.style.length > prop.length && + (rule.style.charCodeAt(prop.length) != 61 || rule.style.slice(prop.length + 1) != value)) + { continue } + if (rule.getAttrs) { + var result = rule.getAttrs(value); + if (result === false) { continue } + rule.attrs = result; + } + return rule + } +}; + +// : (Schema) → [ParseRule] +DOMParser.schemaRules = function schemaRules (schema) { + var result = []; + function insert(rule) { + var priority = rule.priority == null ? 50 : rule.priority, i = 0; + for (; i < result.length; i++) { + var next = result[i], nextPriority = next.priority == null ? 50 : next.priority; + if (nextPriority < priority) { break } + } + result.splice(i, 0, rule); + } + + var loop = function ( name ) { + var rules = schema.marks[name].spec.parseDOM; + if (rules) { rules.forEach(function (rule) { + insert(rule = copy(rule)); + rule.mark = name; + }); } + }; + + for (var name in schema.marks) loop( name ); + var loop$1 = function ( name ) { + var rules$1 = schema.nodes[name$1].spec.parseDOM; + if (rules$1) { rules$1.forEach(function (rule) { + insert(rule = copy(rule)); + rule.node = name$1; + }); } + }; + + for (var name$1 in schema.nodes) loop$1(); + return result +}; + +// :: (Schema) → DOMParser +// Construct a DOM parser using the parsing rules listed in a +// schema's [node specs](#model.NodeSpec.parseDOM), reordered by +// [priority](#model.ParseRule.priority). +DOMParser.fromSchema = function fromSchema (schema) { + return schema.cached.domParser || + (schema.cached.domParser = new DOMParser(schema, DOMParser.schemaRules(schema))) +}; + +// : Object The block-level tags in HTML5 +var blockTags = { + address: true, article: true, aside: true, blockquote: true, canvas: true, + dd: true, div: true, dl: true, fieldset: true, figcaption: true, figure: true, + footer: true, form: true, h1: true, h2: true, h3: true, h4: true, h5: true, + h6: true, header: true, hgroup: true, hr: true, li: true, noscript: true, ol: true, + output: true, p: true, pre: true, section: true, table: true, tfoot: true, ul: true +}; + +// : Object The tags that we normally ignore. +var ignoreTags = { + head: true, noscript: true, object: true, script: true, style: true, title: true +}; + +// : Object List tags. +var listTags = {ol: true, ul: true}; + +// Using a bitfield for node context options +var OPT_PRESERVE_WS = 1, OPT_PRESERVE_WS_FULL = 2, OPT_OPEN_LEFT = 4; + +function wsOptionsFor(preserveWhitespace) { + return (preserveWhitespace ? OPT_PRESERVE_WS : 0) | (preserveWhitespace === "full" ? OPT_PRESERVE_WS_FULL : 0) +} + +var NodeContext = function NodeContext(type, attrs, marks, solid, match, options) { + this.type = type; + this.attrs = attrs; + this.solid = solid; + this.match = match || (options & OPT_OPEN_LEFT ? null : type.contentMatch); + this.options = options; + this.content = []; + this.marks = marks; + this.activeMarks = Mark.none; +}; + +NodeContext.prototype.findWrapping = function findWrapping (node) { + if (!this.match) { + if (!this.type) { return [] } + var fill = this.type.contentMatch.fillBefore(Fragment.from(node)); + if (fill) { + this.match = this.type.contentMatch.matchFragment(fill); + } else { + var start = this.type.contentMatch, wrap; + if (wrap = start.findWrapping(node.type)) { + this.match = start; + return wrap + } else { + return null + } + } + } + return this.match.findWrapping(node.type) +}; + +NodeContext.prototype.finish = function finish (openEnd) { + if (!(this.options & OPT_PRESERVE_WS)) { // Strip trailing whitespace + var last = this.content[this.content.length - 1], m; + if (last && last.isText && (m = /[ \t\r\n\u000c]+$/.exec(last.text))) { + if (last.text.length == m[0].length) { this.content.pop(); } + else { this.content[this.content.length - 1] = last.withText(last.text.slice(0, last.text.length - m[0].length)); } + } + } + var content = Fragment.from(this.content); + if (!openEnd && this.match) + { content = content.append(this.match.fillBefore(Fragment.empty, true)); } + return this.type ? this.type.create(this.attrs, content, this.marks) : content +}; + +var ParseContext = function ParseContext(parser, options, open) { + // : DOMParser The parser we are using. + this.parser = parser; + // : Object The options passed to this parse. + this.options = options; + this.isOpen = open; + this.pendingMarks = []; + var topNode = options.topNode, topContext; + var topOptions = wsOptionsFor(options.preserveWhitespace) | (open ? OPT_OPEN_LEFT : 0); + if (topNode) + { topContext = new NodeContext(topNode.type, topNode.attrs, Mark.none, true, + options.topMatch || topNode.type.contentMatch, topOptions); } + else if (open) + { topContext = new NodeContext(null, null, Mark.none, true, null, topOptions); } + else + { topContext = new NodeContext(parser.schema.topNodeType, null, Mark.none, true, null, topOptions); } + this.nodes = [topContext]; + // : [Mark] The current set of marks + this.open = 0; + this.find = options.findPositions; + this.needsBlock = false; +}; + +var prototypeAccessors$6 = { top: { configurable: true },currentPos: { configurable: true } }; + +prototypeAccessors$6.top.get = function () { + return this.nodes[this.open] +}; + +// : (dom.Node) +// Add a DOM node to the content. Text is inserted as text node, +// otherwise, the node is passed to `addElement` or, if it has a +// `style` attribute, `addElementWithStyles`. +ParseContext.prototype.addDOM = function addDOM (dom) { + if (dom.nodeType == 3) { + this.addTextNode(dom); + } else if (dom.nodeType == 1) { + var style = dom.getAttribute("style"); + var marks = style ? this.readStyles(parseStyles(style)) : null; + if (marks != null) { for (var i = 0; i < marks.length; i++) { this.addPendingMark(marks[i]); } } + this.addElement(dom); + if (marks != null) { for (var i$1 = 0; i$1 < marks.length; i$1++) { this.removePendingMark(marks[i$1]); } } + } +}; + +ParseContext.prototype.addTextNode = function addTextNode (dom) { + var value = dom.nodeValue; + var top = this.top; + if ((top.type ? top.type.inlineContent : top.content.length && top.content[0].isInline) || /[^ \t\r\n\u000c]/.test(value)) { + if (!(top.options & OPT_PRESERVE_WS)) { + value = value.replace(/[ \t\r\n\u000c]+/g, " "); + // If this starts with whitespace, and there is no node before it, or + // a hard break, or a text node that ends with whitespace, strip the + // leading space. + if (/^[ \t\r\n\u000c]/.test(value) && this.open == this.nodes.length - 1) { + var nodeBefore = top.content[top.content.length - 1]; + var domNodeBefore = dom.previousSibling; + if (!nodeBefore || + (domNodeBefore && domNodeBefore.nodeName == 'BR') || + (nodeBefore.isText && /[ \t\r\n\u000c]$/.test(nodeBefore.text))) + { value = value.slice(1); } + } + } else if (!(top.options & OPT_PRESERVE_WS_FULL)) { + value = value.replace(/\r?\n|\r/g, " "); + } + if (value) { this.insertNode(this.parser.schema.text(value)); } + this.findInText(dom); + } else { + this.findInside(dom); + } +}; + +// : (dom.Element) +// Try to find a handler for the given tag and use that to parse. If +// none is found, the element's content nodes are added directly. +ParseContext.prototype.addElement = function addElement (dom) { + var name = dom.nodeName.toLowerCase(); + if (listTags.hasOwnProperty(name)) { normalizeList(dom); } + var rule = (this.options.ruleFromNode && this.options.ruleFromNode(dom)) || this.parser.matchTag(dom, this); + if (rule ? rule.ignore : ignoreTags.hasOwnProperty(name)) { + this.findInside(dom); + } else if (!rule || rule.skip) { + if (rule && rule.skip.nodeType) { dom = rule.skip; } + var sync, top = this.top, oldNeedsBlock = this.needsBlock; + if (blockTags.hasOwnProperty(name)) { + sync = true; + if (!top.type) { this.needsBlock = true; } + } else if (!dom.firstChild) { + this.leafFallback(dom); + return + } + this.addAll(dom); + if (sync) { this.sync(top); } + this.needsBlock = oldNeedsBlock; + } else { + this.addElementByRule(dom, rule); + } +}; + +// Called for leaf DOM nodes that would otherwise be ignored +ParseContext.prototype.leafFallback = function leafFallback (dom) { + if (dom.nodeName == "BR" && this.top.type && this.top.type.inlineContent) + { this.addTextNode(dom.ownerDocument.createTextNode("\n")); } +}; + +// Run any style parser associated with the node's styles. Either +// return an array of marks, or null to indicate some of the styles +// had a rule with `ignore` set. +ParseContext.prototype.readStyles = function readStyles (styles) { + var marks = Mark.none; + for (var i = 0; i < styles.length; i += 2) { + var rule = this.parser.matchStyle(styles[i], styles[i + 1], this); + if (!rule) { continue } + if (rule.ignore) { return null } + marks = this.parser.schema.marks[rule.mark].create(rule.attrs).addToSet(marks); + } + return marks +}; + +// : (dom.Element, ParseRule) → bool +// Look up a handler for the given node. If none are found, return +// false. Otherwise, apply it, use its return value to drive the way +// the node's content is wrapped, and return true. +ParseContext.prototype.addElementByRule = function addElementByRule (dom, rule) { + var this$1 = this; + + var sync, nodeType, markType, mark; + if (rule.node) { + nodeType = this.parser.schema.nodes[rule.node]; + if (!nodeType.isLeaf) { + sync = this.enter(nodeType, rule.attrs, rule.preserveWhitespace); + } else if (!this.insertNode(nodeType.create(rule.attrs))) { + this.leafFallback(dom); + } + } else { + markType = this.parser.schema.marks[rule.mark]; + mark = markType.create(rule.attrs); + this.addPendingMark(mark); + } + var startIn = this.top; + + if (nodeType && nodeType.isLeaf) { + this.findInside(dom); + } else if (rule.getContent) { + this.findInside(dom); + rule.getContent(dom, this.parser.schema).forEach(function (node) { return this$1.insertNode(node); }); + } else { + var contentDOM = rule.contentElement; + if (typeof contentDOM == "string") { contentDOM = dom.querySelector(contentDOM); } + else if (typeof contentDOM == "function") { contentDOM = contentDOM(dom); } + if (!contentDOM) { contentDOM = dom; } + this.findAround(dom, contentDOM, true); + this.addAll(contentDOM, sync); + } + if (sync) { this.sync(startIn); this.open--; } + if (mark) { this.removePendingMark(mark); } +}; + +// : (dom.Node, ?NodeBuilder, ?number, ?number) +// Add all child nodes between `startIndex` and `endIndex` (or the +// whole node, if not given). If `sync` is passed, use it to +// synchronize after every block element. +ParseContext.prototype.addAll = function addAll (parent, sync, startIndex, endIndex) { + var index = startIndex || 0; + for (var dom = startIndex ? parent.childNodes[startIndex] : parent.firstChild, + end = endIndex == null ? null : parent.childNodes[endIndex]; + dom != end; dom = dom.nextSibling, ++index) { + this.findAtPoint(parent, index); + this.addDOM(dom); + if (sync && blockTags.hasOwnProperty(dom.nodeName.toLowerCase())) + { this.sync(sync); } + } + this.findAtPoint(parent, index); +}; + +// Try to find a way to fit the given node type into the current +// context. May add intermediate wrappers and/or leave non-solid +// nodes that we're in. +ParseContext.prototype.findPlace = function findPlace (node) { + var route, sync; + for (var depth = this.open; depth >= 0; depth--) { + var cx = this.nodes[depth]; + var found = cx.findWrapping(node); + if (found && (!route || route.length > found.length)) { + route = found; + sync = cx; + if (!found.length) { break } + } + if (cx.solid) { break } + } + if (!route) { return false } + this.sync(sync); + for (var i = 0; i < route.length; i++) + { this.enterInner(route[i], null, false); } + return true +}; + +// : (Node) → ?Node +// Try to insert the given node, adjusting the context when needed. +ParseContext.prototype.insertNode = function insertNode (node) { + if (node.isInline && this.needsBlock && !this.top.type) { + var block = this.textblockFromContext(); + if (block) { this.enterInner(block); } + } + if (this.findPlace(node)) { + this.closeExtra(); + var top = this.top; + this.applyPendingMarks(top); + if (top.match) { top.match = top.match.matchType(node.type); } + var marks = top.activeMarks; + for (var i = 0; i < node.marks.length; i++) + { if (!top.type || top.type.allowsMarkType(node.marks[i].type)) + { marks = node.marks[i].addToSet(marks); } } + top.content.push(node.mark(marks)); + return true + } + return false +}; + +ParseContext.prototype.applyPendingMarks = function applyPendingMarks (top) { + for (var i = 0; i < this.pendingMarks.length; i++) { + var mark = this.pendingMarks[i]; + if ((!top.type || top.type.allowsMarkType(mark.type)) && !mark.isInSet(top.activeMarks)) { + top.activeMarks = mark.addToSet(top.activeMarks); + this.pendingMarks.splice(i--, 1); + } + } +}; + +// : (NodeType, ?Object) → bool +// Try to start a node of the given type, adjusting the context when +// necessary. +ParseContext.prototype.enter = function enter (type, attrs, preserveWS) { + var ok = this.findPlace(type.create(attrs)); + if (ok) { + this.applyPendingMarks(this.top); + this.enterInner(type, attrs, true, preserveWS); + } + return ok +}; + +// Open a node of the given type +ParseContext.prototype.enterInner = function enterInner (type, attrs, solid, preserveWS) { + this.closeExtra(); + var top = this.top; + top.match = top.match && top.match.matchType(type, attrs); + var options = preserveWS == null ? top.options & ~OPT_OPEN_LEFT : wsOptionsFor(preserveWS); + if ((top.options & OPT_OPEN_LEFT) && top.content.length == 0) { options |= OPT_OPEN_LEFT; } + this.nodes.push(new NodeContext(type, attrs, top.activeMarks, solid, null, options)); + this.open++; +}; + +// Make sure all nodes above this.open are finished and added to +// their parents +ParseContext.prototype.closeExtra = function closeExtra (openEnd) { + var i = this.nodes.length - 1; + if (i > this.open) { + for (; i > this.open; i--) { this.nodes[i - 1].content.push(this.nodes[i].finish(openEnd)); } + this.nodes.length = this.open + 1; + } +}; + +ParseContext.prototype.finish = function finish () { + this.open = 0; + this.closeExtra(this.isOpen); + return this.nodes[0].finish(this.isOpen || this.options.topOpen) +}; + +ParseContext.prototype.sync = function sync (to) { + for (var i = this.open; i >= 0; i--) { if (this.nodes[i] == to) { + this.open = i; + return + } } +}; + +ParseContext.prototype.addPendingMark = function addPendingMark (mark) { + this.pendingMarks.push(mark); +}; + +ParseContext.prototype.removePendingMark = function removePendingMark (mark) { + var found = this.pendingMarks.lastIndexOf(mark); + if (found > -1) { + this.pendingMarks.splice(found, 1); + } else { + var top = this.top; + top.activeMarks = mark.removeFromSet(top.activeMarks); + } +}; + +prototypeAccessors$6.currentPos.get = function () { + this.closeExtra(); + var pos = 0; + for (var i = this.open; i >= 0; i--) { + var content = this.nodes[i].content; + for (var j = content.length - 1; j >= 0; j--) + { pos += content[j].nodeSize; } + if (i) { pos++; } + } + return pos +}; + +ParseContext.prototype.findAtPoint = function findAtPoint (parent, offset) { + if (this.find) { for (var i = 0; i < this.find.length; i++) { + if (this.find[i].node == parent && this.find[i].offset == offset) + { this.find[i].pos = this.currentPos; } + } } +}; + +ParseContext.prototype.findInside = function findInside (parent) { + if (this.find) { for (var i = 0; i < this.find.length; i++) { + if (this.find[i].pos == null && parent.nodeType == 1 && parent.contains(this.find[i].node)) + { this.find[i].pos = this.currentPos; } + } } +}; + +ParseContext.prototype.findAround = function findAround (parent, content, before) { + if (parent != content && this.find) { for (var i = 0; i < this.find.length; i++) { + if (this.find[i].pos == null && parent.nodeType == 1 && parent.contains(this.find[i].node)) { + var pos = content.compareDocumentPosition(this.find[i].node); + if (pos & (before ? 2 : 4)) + { this.find[i].pos = this.currentPos; } + } + } } +}; + +ParseContext.prototype.findInText = function findInText (textNode) { + if (this.find) { for (var i = 0; i < this.find.length; i++) { + if (this.find[i].node == textNode) + { this.find[i].pos = this.currentPos - (textNode.nodeValue.length - this.find[i].offset); } + } } +}; + +// : (string) → bool +// Determines whether the given [context +// string](#ParseRule.context) matches this context. +ParseContext.prototype.matchesContext = function matchesContext (context) { + var this$1 = this; + + if (context.indexOf("|") > -1) + { return context.split(/\s*\|\s*/).some(this.matchesContext, this) } + + var parts = context.split("/"); + var option = this.options.context; + var useRoot = !this.isOpen && (!option || option.parent.type == this.nodes[0].type); + var minDepth = -(option ? option.depth + 1 : 0) + (useRoot ? 0 : 1); + var match = function (i, depth) { + for (; i >= 0; i--) { + var part = parts[i]; + if (part == "") { + if (i == parts.length - 1 || i == 0) { continue } + for (; depth >= minDepth; depth--) + { if (match(i - 1, depth)) { return true } } + return false + } else { + var next = depth > 0 || (depth == 0 && useRoot) ? this$1.nodes[depth].type + : option && depth >= minDepth ? option.node(depth - minDepth).type + : null; + if (!next || (next.name != part && next.groups.indexOf(part) == -1)) + { return false } + depth--; + } + } + return true + }; + return match(parts.length - 1, this.open) +}; + +ParseContext.prototype.textblockFromContext = function textblockFromContext () { + var $context = this.options.context; + if ($context) { for (var d = $context.depth; d >= 0; d--) { + var deflt = $context.node(d).contentMatchAt($context.indexAfter(d)).defaultType; + if (deflt && deflt.isTextblock && deflt.defaultAttrs) { return deflt } + } } + for (var name in this.parser.schema.nodes) { + var type = this.parser.schema.nodes[name]; + if (type.isTextblock && type.defaultAttrs) { return type } + } +}; + +Object.defineProperties( ParseContext.prototype, prototypeAccessors$6 ); + +// Kludge to work around directly nested list nodes produced by some +// tools and allowed by browsers to mean that the nested list is +// actually part of the list item above it. +function normalizeList(dom) { + for (var child = dom.firstChild, prevItem = null; child; child = child.nextSibling) { + var name = child.nodeType == 1 ? child.nodeName.toLowerCase() : null; + if (name && listTags.hasOwnProperty(name) && prevItem) { + prevItem.appendChild(child); + child = prevItem; + } else if (name == "li") { + prevItem = child; + } else if (name) { + prevItem = null; + } + } +} + +// Apply a CSS selector. +function matches(dom, selector) { + return (dom.matches || dom.msMatchesSelector || dom.webkitMatchesSelector || dom.mozMatchesSelector).call(dom, selector) +} + +// : (string) → [string] +// Tokenize a style attribute into property/value pairs. +function parseStyles(style) { + var re = /\s*([\w-]+)\s*:\s*([^;]+)/g, m, result = []; + while (m = re.exec(style)) { result.push(m[1], m[2].trim()); } + return result +} + +function copy(obj) { + var copy = {}; + for (var prop in obj) { copy[prop] = obj[prop]; } + return copy +} + +// DOMOutputSpec:: interface +// A description of a DOM structure. Can be either a string, which is +// interpreted as a text node, a DOM node, which is interpreted as +// itself, or an array. +// +// An array describes a DOM element. The first value in the array +// should be a string—the name of the DOM element. If the second +// element is plain object, it is interpreted as a set of attributes +// for the element. Any elements after that (including the 2nd if it's +// not an attribute object) are interpreted as children of the DOM +// elements, and must either be valid `DOMOutputSpec` values, or the +// number zero. +// +// The number zero (pronounced “hole”) is used to indicate the place +// where a node's child nodes should be inserted. If it occurs in an +// output spec, it should be the only child element in its parent +// node. + +// ::- A DOM serializer knows how to convert ProseMirror nodes and +// marks of various types to DOM nodes. +var DOMSerializer = function DOMSerializer(nodes, marks) { + // :: Object<(node: Node) → DOMOutputSpec> + // The node serialization functions. + this.nodes = nodes || {}; + // :: Object + // The mark serialization functions. + this.marks = marks || {}; +}; + +// :: (Fragment, ?Object) → dom.DocumentFragment +// Serialize the content of this fragment to a DOM fragment. When +// not in the browser, the `document` option, containing a DOM +// document, should be passed so that the serializer can create +// nodes. +DOMSerializer.prototype.serializeFragment = function serializeFragment (fragment, options, target) { + var this$1 = this; + if ( options === void 0 ) options = {}; + + if (!target) { target = doc(options).createDocumentFragment(); } + + var top = target, active = null; + fragment.forEach(function (node) { + if (active || node.marks.length) { + if (!active) { active = []; } + var keep = 0, rendered = 0; + while (keep < active.length && rendered < node.marks.length) { + var next = node.marks[rendered]; + if (!this$1.marks[next.type.name]) { rendered++; continue } + if (!next.eq(active[keep]) || next.type.spec.spanning === false) { break } + keep += 2; rendered++; + } + while (keep < active.length) { + top = active.pop(); + active.pop(); + } + while (rendered < node.marks.length) { + var add = node.marks[rendered++]; + var markDOM = this$1.serializeMark(add, node.isInline, options); + if (markDOM) { + active.push(add, top); + top.appendChild(markDOM.dom); + top = markDOM.contentDOM || markDOM.dom; + } + } + } + top.appendChild(this$1.serializeNode(node, options)); + }); + + return target +}; + +// :: (Node, ?Object) → dom.Node +// Serialize this node to a DOM node. This can be useful when you +// need to serialize a part of a document, as opposed to the whole +// document. To serialize a whole document, use +// [`serializeFragment`](#model.DOMSerializer.serializeFragment) on +// its [content](#model.Node.content). +DOMSerializer.prototype.serializeNode = function serializeNode (node, options) { + if ( options === void 0 ) options = {}; + + var ref = + DOMSerializer.renderSpec(doc(options), this.nodes[node.type.name](node)); + var dom = ref.dom; + var contentDOM = ref.contentDOM; + if (contentDOM) { + if (node.isLeaf) + { throw new RangeError("Content hole not allowed in a leaf node spec") } + if (options.onContent) + { options.onContent(node, contentDOM, options); } + else + { this.serializeFragment(node.content, options, contentDOM); } + } + return dom +}; + +DOMSerializer.prototype.serializeNodeAndMarks = function serializeNodeAndMarks (node, options) { + if ( options === void 0 ) options = {}; + + var dom = this.serializeNode(node, options); + for (var i = node.marks.length - 1; i >= 0; i--) { + var wrap = this.serializeMark(node.marks[i], node.isInline, options); + if (wrap) { +(wrap.contentDOM || wrap.dom).appendChild(dom); + dom = wrap.dom; + } + } + return dom +}; + +DOMSerializer.prototype.serializeMark = function serializeMark (mark, inline, options) { + if ( options === void 0 ) options = {}; + + var toDOM = this.marks[mark.type.name]; + return toDOM && DOMSerializer.renderSpec(doc(options), toDOM(mark, inline)) +}; + +// :: (dom.Document, DOMOutputSpec) → {dom: dom.Node, contentDOM: ?dom.Node} +// Render an [output spec](#model.DOMOutputSpec) to a DOM node. If +// the spec has a hole (zero) in it, `contentDOM` will point at the +// node with the hole. +DOMSerializer.renderSpec = function renderSpec (doc, structure) { + if (typeof structure == "string") + { return {dom: doc.createTextNode(structure)} } + if (structure.nodeType != null) + { return {dom: structure} } + var dom = doc.createElement(structure[0]), contentDOM = null; + var attrs = structure[1], start = 1; + if (attrs && typeof attrs == "object" && attrs.nodeType == null && !Array.isArray(attrs)) { + start = 2; + for (var name in attrs) { + if (attrs[name] != null) { dom.setAttribute(name, attrs[name]); } + } + } + for (var i = start; i < structure.length; i++) { + var child = structure[i]; + if (child === 0) { + if (i < structure.length - 1 || i > start) + { throw new RangeError("Content hole must be the only child of its parent node") } + return {dom: dom, contentDOM: dom} + } else { + var ref = DOMSerializer.renderSpec(doc, child); + var inner = ref.dom; + var innerContent = ref.contentDOM; + dom.appendChild(inner); + if (innerContent) { + if (contentDOM) { throw new RangeError("Multiple content holes") } + contentDOM = innerContent; + } + } + } + return {dom: dom, contentDOM: contentDOM} +}; + +// :: (Schema) → DOMSerializer +// Build a serializer using the [`toDOM`](#model.NodeSpec.toDOM) +// properties in a schema's node and mark specs. +DOMSerializer.fromSchema = function fromSchema (schema) { + return schema.cached.domSerializer || + (schema.cached.domSerializer = new DOMSerializer(this.nodesFromSchema(schema), this.marksFromSchema(schema))) +}; + +// : (Schema) → Object<(node: Node) → DOMOutputSpec> +// Gather the serializers in a schema's node specs into an object. +// This can be useful as a base to build a custom serializer from. +DOMSerializer.nodesFromSchema = function nodesFromSchema (schema) { + var result = gatherToDOM(schema.nodes); + if (!result.text) { result.text = function (node) { return node.text; }; } + return result +}; + +// : (Schema) → Object<(mark: Mark) → DOMOutputSpec> +// Gather the serializers in a schema's mark specs into an object. +DOMSerializer.marksFromSchema = function marksFromSchema (schema) { + return gatherToDOM(schema.marks) +}; + +function gatherToDOM(obj) { + var result = {}; + for (var name in obj) { + var toDOM = obj[name].spec.toDOM; + if (toDOM) { result[name] = toDOM; } + } + return result +} + +function doc(options) { + // declare global: window + return options.document || window.document +} + + +//# sourceMappingURL=index.es.js.map + + +/***/ }), + +/***/ "./node_modules/prosemirror-schema-list/dist/index.es.js": +/*!***************************************************************!*\ + !*** ./node_modules/prosemirror-schema-list/dist/index.es.js ***! + \***************************************************************/ +/*! exports provided: addListNodes, bulletList, liftListItem, listItem, orderedList, sinkListItem, splitListItem, wrapInList */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "addListNodes", function() { return addListNodes; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "bulletList", function() { return bulletList; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "liftListItem", function() { return liftListItem; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "listItem", function() { return listItem; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "orderedList", function() { return orderedList; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "sinkListItem", function() { return sinkListItem; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "splitListItem", function() { return splitListItem; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "wrapInList", function() { return wrapInList; }); +/* harmony import */ var prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! prosemirror-transform */ "./node_modules/prosemirror-transform/dist/index.es.js"); +/* harmony import */ var prosemirror_model__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! prosemirror-model */ "./node_modules/prosemirror-model/dist/index.es.js"); + + + +var olDOM = ["ol", 0], ulDOM = ["ul", 0], liDOM = ["li", 0]; + +// :: NodeSpec +// An ordered list [node spec](#model.NodeSpec). Has a single +// attribute, `order`, which determines the number at which the list +// starts counting, and defaults to 1. Represented as an `
    ` +// element. +var orderedList = { + attrs: {order: {default: 1}}, + parseDOM: [{tag: "ol", getAttrs: function getAttrs(dom) { + return {order: dom.hasAttribute("start") ? +dom.getAttribute("start") : 1} + }}], + toDOM: function toDOM(node) { + return node.attrs.order == 1 ? olDOM : ["ol", {start: node.attrs.order}, 0] + } +}; + +// :: NodeSpec +// A bullet list node spec, represented in the DOM as `
      `. +var bulletList = { + parseDOM: [{tag: "ul"}], + toDOM: function toDOM() { return ulDOM } +}; + +// :: NodeSpec +// A list item (`
    • `) spec. +var listItem = { + parseDOM: [{tag: "li"}], + toDOM: function toDOM() { return liDOM }, + defining: true +}; + +function add(obj, props) { + var copy = {}; + for (var prop in obj) { copy[prop] = obj[prop]; } + for (var prop$1 in props) { copy[prop$1] = props[prop$1]; } + return copy +} + +// :: (OrderedMap, string, ?string) → OrderedMap +// Convenience function for adding list-related node types to a map +// specifying the nodes for a schema. Adds +// [`orderedList`](#schema-list.orderedList) as `"ordered_list"`, +// [`bulletList`](#schema-list.bulletList) as `"bullet_list"`, and +// [`listItem`](#schema-list.listItem) as `"list_item"`. +// +// `itemContent` determines the content expression for the list items. +// If you want the commands defined in this module to apply to your +// list structure, it should have a shape like `"paragraph block*"` or +// `"paragraph (ordered_list | bullet_list)*"`. `listGroup` can be +// given to assign a group name to the list node types, for example +// `"block"`. +function addListNodes(nodes, itemContent, listGroup) { + return nodes.append({ + ordered_list: add(orderedList, {content: "list_item+", group: listGroup}), + bullet_list: add(bulletList, {content: "list_item+", group: listGroup}), + list_item: add(listItem, {content: itemContent}) + }) +} + +// :: (NodeType, ?Object) → (state: EditorState, dispatch: ?(tr: Transaction)) → bool +// Returns a command function that wraps the selection in a list with +// the given type an attributes. If `dispatch` is null, only return a +// value to indicate whether this is possible, but don't actually +// perform the change. +function wrapInList(listType, attrs) { + return function(state, dispatch) { + var ref = state.selection; + var $from = ref.$from; + var $to = ref.$to; + var range = $from.blockRange($to), doJoin = false, outerRange = range; + if (!range) { return false } + // This is at the top of an existing list item + if (range.depth >= 2 && $from.node(range.depth - 1).type.compatibleContent(listType) && range.startIndex == 0) { + // Don't do anything if this is the top of the list + if ($from.index(range.depth - 1) == 0) { return false } + var $insert = state.doc.resolve(range.start - 2); + outerRange = new prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["NodeRange"]($insert, $insert, range.depth); + if (range.endIndex < range.parent.childCount) + { range = new prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["NodeRange"]($from, state.doc.resolve($to.end(range.depth)), range.depth); } + doJoin = true; + } + var wrap = Object(prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__["findWrapping"])(outerRange, listType, attrs, range); + if (!wrap) { return false } + if (dispatch) { dispatch(doWrapInList(state.tr, range, wrap, doJoin, listType).scrollIntoView()); } + return true + } +} + +function doWrapInList(tr, range, wrappers, joinBefore, listType) { + var content = prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].empty; + for (var i = wrappers.length - 1; i >= 0; i--) + { content = prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(wrappers[i].type.create(wrappers[i].attrs, content)); } + + tr.step(new prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__["ReplaceAroundStep"](range.start - (joinBefore ? 2 : 0), range.end, range.start, range.end, + new prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Slice"](content, 0, 0), wrappers.length, true)); + + var found = 0; + for (var i$1 = 0; i$1 < wrappers.length; i$1++) { if (wrappers[i$1].type == listType) { found = i$1 + 1; } } + var splitDepth = wrappers.length - found; + + var splitPos = range.start + wrappers.length - (joinBefore ? 2 : 0), parent = range.parent; + for (var i$2 = range.startIndex, e = range.endIndex, first = true; i$2 < e; i$2++, first = false) { + if (!first && Object(prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__["canSplit"])(tr.doc, splitPos, splitDepth)) { + tr.split(splitPos, splitDepth); + splitPos += 2 * splitDepth; + } + splitPos += parent.child(i$2).nodeSize; + } + return tr +} + +// :: (NodeType) → (state: EditorState, dispatch: ?(tr: Transaction)) → bool +// Build a command that splits a non-empty textblock at the top level +// of a list item by also splitting that list item. +function splitListItem(itemType) { + return function(state, dispatch) { + var ref = state.selection; + var $from = ref.$from; + var $to = ref.$to; + var node = ref.node; + if ((node && node.isBlock) || $from.depth < 2 || !$from.sameParent($to)) { return false } + var grandParent = $from.node(-1); + if (grandParent.type != itemType) { return false } + if ($from.parent.content.size == 0) { + // In an empty block. If this is a nested list, the wrapping + // list item should be split. Otherwise, bail out and let next + // command handle lifting. + if ($from.depth == 2 || $from.node(-3).type != itemType || + $from.index(-2) != $from.node(-2).childCount - 1) { return false } + if (dispatch) { + var wrap = prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].empty, keepItem = $from.index(-1) > 0; + // Build a fragment containing empty versions of the structure + // from the outer list item to the parent node of the cursor + for (var d = $from.depth - (keepItem ? 1 : 2); d >= $from.depth - 3; d--) + { wrap = prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from($from.node(d).copy(wrap)); } + // Add a second list item with an empty default start node + wrap = wrap.append(prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(itemType.createAndFill())); + var tr$1 = state.tr.replace($from.before(keepItem ? null : -1), $from.after(-3), new prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Slice"](wrap, keepItem ? 3 : 2, 2)); + tr$1.setSelection(state.selection.constructor.near(tr$1.doc.resolve($from.pos + (keepItem ? 3 : 2)))); + dispatch(tr$1.scrollIntoView()); + } + return true + } + var nextType = $to.pos == $from.end() ? grandParent.contentMatchAt(0).defaultType : null; + var tr = state.tr.delete($from.pos, $to.pos); + var types = nextType && [null, {type: nextType}]; + if (!Object(prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__["canSplit"])(tr.doc, $from.pos, 2, types)) { return false } + if (dispatch) { dispatch(tr.split($from.pos, 2, types).scrollIntoView()); } + return true + } +} + +// :: (NodeType) → (state: EditorState, dispatch: ?(tr: Transaction)) → bool +// Create a command to lift the list item around the selection up into +// a wrapping list. +function liftListItem(itemType) { + return function(state, dispatch) { + var ref = state.selection; + var $from = ref.$from; + var $to = ref.$to; + var range = $from.blockRange($to, function (node) { return node.childCount && node.firstChild.type == itemType; }); + if (!range) { return false } + if (!dispatch) { return true } + if ($from.node(range.depth - 1).type == itemType) // Inside a parent list + { return liftToOuterList(state, dispatch, itemType, range) } + else // Outer list node + { return liftOutOfList(state, dispatch, range) } + } +} + +function liftToOuterList(state, dispatch, itemType, range) { + var tr = state.tr, end = range.end, endOfList = range.$to.end(range.depth); + if (end < endOfList) { + // There are siblings after the lifted items, which must become + // children of the last item + tr.step(new prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__["ReplaceAroundStep"](end - 1, endOfList, end, endOfList, + new prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Slice"](prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(itemType.create(null, range.parent.copy())), 1, 0), 1, true)); + range = new prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["NodeRange"](tr.doc.resolve(range.$from.pos), tr.doc.resolve(endOfList), range.depth); + } + dispatch(tr.lift(range, Object(prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__["liftTarget"])(range)).scrollIntoView()); + return true +} + +function liftOutOfList(state, dispatch, range) { + var tr = state.tr, list = range.parent; + // Merge the list items into a single big item + for (var pos = range.end, i = range.endIndex - 1, e = range.startIndex; i > e; i--) { + pos -= list.child(i).nodeSize; + tr.delete(pos - 1, pos + 1); + } + var $start = tr.doc.resolve(range.start), item = $start.nodeAfter; + var atStart = range.startIndex == 0, atEnd = range.endIndex == list.childCount; + var parent = $start.node(-1), indexBefore = $start.index(-1); + if (!parent.canReplace(indexBefore + (atStart ? 0 : 1), indexBefore + 1, + item.content.append(atEnd ? prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].empty : prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(list)))) + { return false } + var start = $start.pos, end = start + item.nodeSize; + // Strip off the surrounding list. At the sides where we're not at + // the end of the list, the existing list is closed. At sides where + // this is the end, it is overwritten to its end. + tr.step(new prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__["ReplaceAroundStep"](start - (atStart ? 1 : 0), end + (atEnd ? 1 : 0), start + 1, end - 1, + new prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Slice"]((atStart ? prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].empty : prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(list.copy(prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].empty))) + .append(atEnd ? prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].empty : prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(list.copy(prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].empty))), + atStart ? 0 : 1, atEnd ? 0 : 1), atStart ? 0 : 1)); + dispatch(tr.scrollIntoView()); + return true +} + +// :: (NodeType) → (state: EditorState, dispatch: ?(tr: Transaction)) → bool +// Create a command to sink the list item around the selection down +// into an inner list. +function sinkListItem(itemType) { + return function(state, dispatch) { + var ref = state.selection; + var $from = ref.$from; + var $to = ref.$to; + var range = $from.blockRange($to, function (node) { return node.childCount && node.firstChild.type == itemType; }); + if (!range) { return false } + var startIndex = range.startIndex; + if (startIndex == 0) { return false } + var parent = range.parent, nodeBefore = parent.child(startIndex - 1); + if (nodeBefore.type != itemType) { return false } + + if (dispatch) { + var nestedBefore = nodeBefore.lastChild && nodeBefore.lastChild.type == parent.type; + var inner = prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(nestedBefore ? itemType.create() : null); + var slice = new prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Slice"](prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(itemType.create(null, prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(parent.type.create(null, inner)))), + nestedBefore ? 3 : 1, 0); + var before = range.start, after = range.end; + dispatch(state.tr.step(new prosemirror_transform__WEBPACK_IMPORTED_MODULE_0__["ReplaceAroundStep"](before - (nestedBefore ? 3 : 1), after, + before, after, slice, 1, true)) + .scrollIntoView()); + } + return true + } +} + + +//# sourceMappingURL=index.es.js.map + + +/***/ }), + +/***/ "./node_modules/prosemirror-state/dist/index.es.js": +/*!*********************************************************!*\ + !*** ./node_modules/prosemirror-state/dist/index.es.js ***! + \*********************************************************/ +/*! exports provided: AllSelection, EditorState, NodeSelection, Plugin, PluginKey, Selection, SelectionRange, TextSelection, Transaction */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AllSelection", function() { return AllSelection; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EditorState", function() { return EditorState; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "NodeSelection", function() { return NodeSelection; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Plugin", function() { return Plugin; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "PluginKey", function() { return PluginKey; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Selection", function() { return Selection; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SelectionRange", function() { return SelectionRange; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "TextSelection", function() { return TextSelection; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Transaction", function() { return Transaction; }); +/* harmony import */ var prosemirror_model__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! prosemirror-model */ "./node_modules/prosemirror-model/dist/index.es.js"); +/* harmony import */ var prosemirror_transform__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! prosemirror-transform */ "./node_modules/prosemirror-transform/dist/index.es.js"); + + + +var classesById = Object.create(null); + +// ::- Superclass for editor selections. Every selection type should +// extend this. Should not be instantiated directly. +var Selection = function Selection($anchor, $head, ranges) { + // :: [SelectionRange] + // The ranges covered by the selection. + this.ranges = ranges || [new SelectionRange($anchor.min($head), $anchor.max($head))]; + // :: ResolvedPos + // The resolved anchor of the selection (the side that stays in + // place when the selection is modified). + this.$anchor = $anchor; + // :: ResolvedPos + // The resolved head of the selection (the side that moves when + // the selection is modified). + this.$head = $head; +}; + +var prototypeAccessors = { anchor: { configurable: true },head: { configurable: true },from: { configurable: true },to: { configurable: true },$from: { configurable: true },$to: { configurable: true },empty: { configurable: true } }; + +// :: number +// The selection's anchor, as an unresolved position. +prototypeAccessors.anchor.get = function () { return this.$anchor.pos }; + +// :: number +// The selection's head. +prototypeAccessors.head.get = function () { return this.$head.pos }; + +// :: number +// The lower bound of the selection's main range. +prototypeAccessors.from.get = function () { return this.$from.pos }; + +// :: number +// The upper bound of the selection's main range. +prototypeAccessors.to.get = function () { return this.$to.pos }; + +// :: ResolvedPos +// The resolved lowerbound of the selection's main range. +prototypeAccessors.$from.get = function () { + return this.ranges[0].$from +}; + +// :: ResolvedPos +// The resolved upper bound of the selection's main range. +prototypeAccessors.$to.get = function () { + return this.ranges[0].$to +}; + +// :: bool +// Indicates whether the selection contains any content. +prototypeAccessors.empty.get = function () { + var ranges = this.ranges; + for (var i = 0; i < ranges.length; i++) + { if (ranges[i].$from.pos != ranges[i].$to.pos) { return false } } + return true +}; + +// eq:: (Selection) → bool +// Test whether the selection is the same as another selection. + +// map:: (doc: Node, mapping: Mappable) → Selection +// Map this selection through a [mappable](#transform.Mappable) thing. `doc` +// should be the new document to which we are mapping. + +// :: () → Slice +// Get the content of this selection as a slice. +Selection.prototype.content = function content () { + return this.$from.node(0).slice(this.from, this.to, true) +}; + +// :: (Transaction, ?Slice) +// Replace the selection with a slice or, if no slice is given, +// delete the selection. Will append to the given transaction. +Selection.prototype.replace = function replace (tr, content) { + if ( content === void 0 ) content = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"].empty; + + // Put the new selection at the position after the inserted + // content. When that ended in an inline node, search backwards, + // to get the position after that node. If not, search forward. + var lastNode = content.content.lastChild, lastParent = null; + for (var i = 0; i < content.openEnd; i++) { + lastParent = lastNode; + lastNode = lastNode.lastChild; + } + + var mapFrom = tr.steps.length, ranges = this.ranges; + for (var i$1 = 0; i$1 < ranges.length; i$1++) { + var ref = ranges[i$1]; + var $from = ref.$from; + var $to = ref.$to; + var mapping = tr.mapping.slice(mapFrom); + tr.replaceRange(mapping.map($from.pos), mapping.map($to.pos), i$1 ? prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"].empty : content); + if (i$1 == 0) + { selectionToInsertionEnd(tr, mapFrom, (lastNode ? lastNode.isInline : lastParent && lastParent.isTextblock) ? -1 : 1); } + } +}; + +// :: (Transaction, Node) +// Replace the selection with the given node, appending the changes +// to the given transaction. +Selection.prototype.replaceWith = function replaceWith (tr, node) { + var mapFrom = tr.steps.length, ranges = this.ranges; + for (var i = 0; i < ranges.length; i++) { + var ref = ranges[i]; + var $from = ref.$from; + var $to = ref.$to; + var mapping = tr.mapping.slice(mapFrom); + var from = mapping.map($from.pos), to = mapping.map($to.pos); + if (i) { + tr.deleteRange(from, to); + } else { + tr.replaceRangeWith(from, to, node); + selectionToInsertionEnd(tr, mapFrom, node.isInline ? -1 : 1); + } + } +}; + +// toJSON:: () → Object +// Convert the selection to a JSON representation. When implementing +// this for a custom selection class, make sure to give the object a +// `type` property whose value matches the ID under which you +// [registered](#state.Selection^jsonID) your class. + +// :: (ResolvedPos, number, ?bool) → ?Selection +// Find a valid cursor or leaf node selection starting at the given +// position and searching back if `dir` is negative, and forward if +// positive. When `textOnly` is true, only consider cursor +// selections. Will return null when no valid selection position is +// found. +Selection.findFrom = function findFrom ($pos, dir, textOnly) { + var inner = $pos.parent.inlineContent ? new TextSelection($pos) + : findSelectionIn($pos.node(0), $pos.parent, $pos.pos, $pos.index(), dir, textOnly); + if (inner) { return inner } + + for (var depth = $pos.depth - 1; depth >= 0; depth--) { + var found = dir < 0 + ? findSelectionIn($pos.node(0), $pos.node(depth), $pos.before(depth + 1), $pos.index(depth), dir, textOnly) + : findSelectionIn($pos.node(0), $pos.node(depth), $pos.after(depth + 1), $pos.index(depth) + 1, dir, textOnly); + if (found) { return found } + } +}; + +// :: (ResolvedPos, ?number) → Selection +// Find a valid cursor or leaf node selection near the given +// position. Searches forward first by default, but if `bias` is +// negative, it will search backwards first. +Selection.near = function near ($pos, bias) { + if ( bias === void 0 ) bias = 1; + + return this.findFrom($pos, bias) || this.findFrom($pos, -bias) || new AllSelection($pos.node(0)) +}; + +// :: (Node) → Selection +// Find the cursor or leaf node selection closest to the start of +// the given document. Will return an +// [`AllSelection`](#state.AllSelection) if no valid position +// exists. +Selection.atStart = function atStart (doc) { + return findSelectionIn(doc, doc, 0, 0, 1) || new AllSelection(doc) +}; + +// :: (Node) → Selection +// Find the cursor or leaf node selection closest to the end of the +// given document. +Selection.atEnd = function atEnd (doc) { + return findSelectionIn(doc, doc, doc.content.size, doc.childCount, -1) || new AllSelection(doc) +}; + +// :: (Node, Object) → Selection +// Deserialize the JSON representation of a selection. Must be +// implemented for custom classes (as a static class method). +Selection.fromJSON = function fromJSON (doc, json) { + if (!json || !json.type) { throw new RangeError("Invalid input for Selection.fromJSON") } + var cls = classesById[json.type]; + if (!cls) { throw new RangeError(("No selection type " + (json.type) + " defined")) } + return cls.fromJSON(doc, json) +}; + +// :: (string, constructor) +// To be able to deserialize selections from JSON, custom selection +// classes must register themselves with an ID string, so that they +// can be disambiguated. Try to pick something that's unlikely to +// clash with classes from other modules. +Selection.jsonID = function jsonID (id, selectionClass) { + if (id in classesById) { throw new RangeError("Duplicate use of selection JSON ID " + id) } + classesById[id] = selectionClass; + selectionClass.prototype.jsonID = id; + return selectionClass +}; + +// :: () → SelectionBookmark +// Get a [bookmark](#state.SelectionBookmark) for this selection, +// which is a value that can be mapped without having access to a +// current document, and later resolved to a real selection for a +// given document again. (This is used mostly by the history to +// track and restore old selections.) The default implementation of +// this method just converts the selection to a text selection and +// returns the bookmark for that. +Selection.prototype.getBookmark = function getBookmark () { + return TextSelection.between(this.$anchor, this.$head).getBookmark() +}; + +Object.defineProperties( Selection.prototype, prototypeAccessors ); + +// :: bool +// Controls whether, when a selection of this type is active in the +// browser, the selected range should be visible to the user. Defaults +// to `true`. +Selection.prototype.visible = true; + +// SelectionBookmark:: interface +// A lightweight, document-independent representation of a selection. +// You can define a custom bookmark type for a custom selection class +// to make the history handle it well. +// +// map:: (mapping: Mapping) → SelectionBookmark +// Map the bookmark through a set of changes. +// +// resolve:: (doc: Node) → Selection +// Resolve the bookmark to a real selection again. This may need to +// do some error checking and may fall back to a default (usually +// [`TextSelection.between`](#state.TextSelection^between)) if +// mapping made the bookmark invalid. + +// ::- Represents a selected range in a document. +var SelectionRange = function SelectionRange($from, $to) { + // :: ResolvedPos + // The lower bound of the range. + this.$from = $from; + // :: ResolvedPos + // The upper bound of the range. + this.$to = $to; +}; + +// ::- A text selection represents a classical editor selection, with +// a head (the moving side) and anchor (immobile side), both of which +// point into textblock nodes. It can be empty (a regular cursor +// position). +var TextSelection = /*@__PURE__*/(function (Selection) { + function TextSelection($anchor, $head) { + if ( $head === void 0 ) $head = $anchor; + + Selection.call(this, $anchor, $head); + } + + if ( Selection ) TextSelection.__proto__ = Selection; + TextSelection.prototype = Object.create( Selection && Selection.prototype ); + TextSelection.prototype.constructor = TextSelection; + + var prototypeAccessors$1 = { $cursor: { configurable: true } }; + + // :: ?ResolvedPos + // Returns a resolved position if this is a cursor selection (an + // empty text selection), and null otherwise. + prototypeAccessors$1.$cursor.get = function () { return this.$anchor.pos == this.$head.pos ? this.$head : null }; + + TextSelection.prototype.map = function map (doc, mapping) { + var $head = doc.resolve(mapping.map(this.head)); + if (!$head.parent.inlineContent) { return Selection.near($head) } + var $anchor = doc.resolve(mapping.map(this.anchor)); + return new TextSelection($anchor.parent.inlineContent ? $anchor : $head, $head) + }; + + TextSelection.prototype.replace = function replace (tr, content) { + if ( content === void 0 ) content = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"].empty; + + Selection.prototype.replace.call(this, tr, content); + if (content == prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"].empty) { + var marks = this.$from.marksAcross(this.$to); + if (marks) { tr.ensureMarks(marks); } + } + }; + + TextSelection.prototype.eq = function eq (other) { + return other instanceof TextSelection && other.anchor == this.anchor && other.head == this.head + }; + + TextSelection.prototype.getBookmark = function getBookmark () { + return new TextBookmark(this.anchor, this.head) + }; + + TextSelection.prototype.toJSON = function toJSON () { + return {type: "text", anchor: this.anchor, head: this.head} + }; + + TextSelection.fromJSON = function fromJSON (doc, json) { + if (typeof json.anchor != "number" || typeof json.head != "number") + { throw new RangeError("Invalid input for TextSelection.fromJSON") } + return new TextSelection(doc.resolve(json.anchor), doc.resolve(json.head)) + }; + + // :: (Node, number, ?number) → TextSelection + // Create a text selection from non-resolved positions. + TextSelection.create = function create (doc, anchor, head) { + if ( head === void 0 ) head = anchor; + + var $anchor = doc.resolve(anchor); + return new this($anchor, head == anchor ? $anchor : doc.resolve(head)) + }; + + // :: (ResolvedPos, ResolvedPos, ?number) → Selection + // Return a text selection that spans the given positions or, if + // they aren't text positions, find a text selection near them. + // `bias` determines whether the method searches forward (default) + // or backwards (negative number) first. Will fall back to calling + // [`Selection.near`](#state.Selection^near) when the document + // doesn't contain a valid text position. + TextSelection.between = function between ($anchor, $head, bias) { + var dPos = $anchor.pos - $head.pos; + if (!bias || dPos) { bias = dPos >= 0 ? 1 : -1; } + if (!$head.parent.inlineContent) { + var found = Selection.findFrom($head, bias, true) || Selection.findFrom($head, -bias, true); + if (found) { $head = found.$head; } + else { return Selection.near($head, bias) } + } + if (!$anchor.parent.inlineContent) { + if (dPos == 0) { + $anchor = $head; + } else { + $anchor = (Selection.findFrom($anchor, -bias, true) || Selection.findFrom($anchor, bias, true)).$anchor; + if (($anchor.pos < $head.pos) != (dPos < 0)) { $anchor = $head; } + } + } + return new TextSelection($anchor, $head) + }; + + Object.defineProperties( TextSelection.prototype, prototypeAccessors$1 ); + + return TextSelection; +}(Selection)); + +Selection.jsonID("text", TextSelection); + +var TextBookmark = function TextBookmark(anchor, head) { + this.anchor = anchor; + this.head = head; +}; +TextBookmark.prototype.map = function map (mapping) { + return new TextBookmark(mapping.map(this.anchor), mapping.map(this.head)) +}; +TextBookmark.prototype.resolve = function resolve (doc) { + return TextSelection.between(doc.resolve(this.anchor), doc.resolve(this.head)) +}; + +// ::- A node selection is a selection that points at a single node. +// All nodes marked [selectable](#model.NodeSpec.selectable) can be +// the target of a node selection. In such a selection, `from` and +// `to` point directly before and after the selected node, `anchor` +// equals `from`, and `head` equals `to`.. +var NodeSelection = /*@__PURE__*/(function (Selection) { + function NodeSelection($pos) { + var node = $pos.nodeAfter; + var $end = $pos.node(0).resolve($pos.pos + node.nodeSize); + Selection.call(this, $pos, $end); + // :: Node The selected node. + this.node = node; + } + + if ( Selection ) NodeSelection.__proto__ = Selection; + NodeSelection.prototype = Object.create( Selection && Selection.prototype ); + NodeSelection.prototype.constructor = NodeSelection; + + NodeSelection.prototype.map = function map (doc, mapping) { + var ref = mapping.mapResult(this.anchor); + var deleted = ref.deleted; + var pos = ref.pos; + var $pos = doc.resolve(pos); + if (deleted) { return Selection.near($pos) } + return new NodeSelection($pos) + }; + + NodeSelection.prototype.content = function content () { + return new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].from(this.node), 0, 0) + }; + + NodeSelection.prototype.eq = function eq (other) { + return other instanceof NodeSelection && other.anchor == this.anchor + }; + + NodeSelection.prototype.toJSON = function toJSON () { + return {type: "node", anchor: this.anchor} + }; + + NodeSelection.prototype.getBookmark = function getBookmark () { return new NodeBookmark(this.anchor) }; + + NodeSelection.fromJSON = function fromJSON (doc, json) { + if (typeof json.anchor != "number") + { throw new RangeError("Invalid input for NodeSelection.fromJSON") } + return new NodeSelection(doc.resolve(json.anchor)) + }; + + // :: (Node, number) → NodeSelection + // Create a node selection from non-resolved positions. + NodeSelection.create = function create (doc, from) { + return new this(doc.resolve(from)) + }; + + // :: (Node) → bool + // Determines whether the given node may be selected as a node + // selection. + NodeSelection.isSelectable = function isSelectable (node) { + return !node.isText && node.type.spec.selectable !== false + }; + + return NodeSelection; +}(Selection)); + +NodeSelection.prototype.visible = false; + +Selection.jsonID("node", NodeSelection); + +var NodeBookmark = function NodeBookmark(anchor) { + this.anchor = anchor; +}; +NodeBookmark.prototype.map = function map (mapping) { + var ref = mapping.mapResult(this.anchor); + var deleted = ref.deleted; + var pos = ref.pos; + return deleted ? new TextBookmark(pos, pos) : new NodeBookmark(pos) +}; +NodeBookmark.prototype.resolve = function resolve (doc) { + var $pos = doc.resolve(this.anchor), node = $pos.nodeAfter; + if (node && NodeSelection.isSelectable(node)) { return new NodeSelection($pos) } + return Selection.near($pos) +}; + +// ::- A selection type that represents selecting the whole document +// (which can not necessarily be expressed with a text selection, when +// there are for example leaf block nodes at the start or end of the +// document). +var AllSelection = /*@__PURE__*/(function (Selection) { + function AllSelection(doc) { + Selection.call(this, doc.resolve(0), doc.resolve(doc.content.size)); + } + + if ( Selection ) AllSelection.__proto__ = Selection; + AllSelection.prototype = Object.create( Selection && Selection.prototype ); + AllSelection.prototype.constructor = AllSelection; + + AllSelection.prototype.toJSON = function toJSON () { return {type: "all"} }; + + AllSelection.fromJSON = function fromJSON (doc) { return new AllSelection(doc) }; + + AllSelection.prototype.map = function map (doc) { return new AllSelection(doc) }; + + AllSelection.prototype.eq = function eq (other) { return other instanceof AllSelection }; + + AllSelection.prototype.getBookmark = function getBookmark () { return AllBookmark }; + + return AllSelection; +}(Selection)); + +Selection.jsonID("all", AllSelection); + +var AllBookmark = { + map: function map() { return this }, + resolve: function resolve(doc) { return new AllSelection(doc) } +}; + +// FIXME we'll need some awareness of text direction when scanning for selections + +// Try to find a selection inside the given node. `pos` points at the +// position where the search starts. When `text` is true, only return +// text selections. +function findSelectionIn(doc, node, pos, index, dir, text) { + if (node.inlineContent) { return TextSelection.create(doc, pos) } + for (var i = index - (dir > 0 ? 0 : 1); dir > 0 ? i < node.childCount : i >= 0; i += dir) { + var child = node.child(i); + if (!child.isAtom) { + var inner = findSelectionIn(doc, child, pos + dir, dir < 0 ? child.childCount : 0, dir, text); + if (inner) { return inner } + } else if (!text && NodeSelection.isSelectable(child)) { + return NodeSelection.create(doc, pos - (dir < 0 ? child.nodeSize : 0)) + } + pos += child.nodeSize * dir; + } +} + +function selectionToInsertionEnd(tr, startLen, bias) { + var last = tr.steps.length - 1; + if (last < startLen) { return } + var step = tr.steps[last]; + if (!(step instanceof prosemirror_transform__WEBPACK_IMPORTED_MODULE_1__["ReplaceStep"] || step instanceof prosemirror_transform__WEBPACK_IMPORTED_MODULE_1__["ReplaceAroundStep"])) { return } + var map = tr.mapping.maps[last], end; + map.forEach(function (_from, _to, _newFrom, newTo) { if (end == null) { end = newTo; } }); + tr.setSelection(Selection.near(tr.doc.resolve(end), bias)); +} + +var UPDATED_SEL = 1, UPDATED_MARKS = 2, UPDATED_SCROLL = 4; + +// ::- An editor state transaction, which can be applied to a state to +// create an updated state. Use +// [`EditorState.tr`](#state.EditorState.tr) to create an instance. +// +// Transactions track changes to the document (they are a subclass of +// [`Transform`](#transform.Transform)), but also other state changes, +// like selection updates and adjustments of the set of [stored +// marks](#state.EditorState.storedMarks). In addition, you can store +// metadata properties in a transaction, which are extra pieces of +// information that client code or plugins can use to describe what a +// transacion represents, so that they can update their [own +// state](#state.StateField) accordingly. +// +// The [editor view](#view.EditorView) uses a few metadata properties: +// it will attach a property `"pointer"` with the value `true` to +// selection transactions directly caused by mouse or touch input, and +// a `"uiEvent"` property of that may be `"paste"`, `"cut"`, or `"drop"`. +var Transaction = /*@__PURE__*/(function (Transform) { + function Transaction(state) { + Transform.call(this, state.doc); + // :: number + // The timestamp associated with this transaction, in the same + // format as `Date.now()`. + this.time = Date.now(); + this.curSelection = state.selection; + // The step count for which the current selection is valid. + this.curSelectionFor = 0; + // :: ?[Mark] + // The stored marks set by this transaction, if any. + this.storedMarks = state.storedMarks; + // Bitfield to track which aspects of the state were updated by + // this transaction. + this.updated = 0; + // Object used to store metadata properties for the transaction. + this.meta = Object.create(null); + } + + if ( Transform ) Transaction.__proto__ = Transform; + Transaction.prototype = Object.create( Transform && Transform.prototype ); + Transaction.prototype.constructor = Transaction; + + var prototypeAccessors = { selection: { configurable: true },selectionSet: { configurable: true },storedMarksSet: { configurable: true },isGeneric: { configurable: true },scrolledIntoView: { configurable: true } }; + + // :: Selection + // The transaction's current selection. This defaults to the editor + // selection [mapped](#state.Selection.map) through the steps in the + // transaction, but can be overwritten with + // [`setSelection`](#state.Transaction.setSelection). + prototypeAccessors.selection.get = function () { + if (this.curSelectionFor < this.steps.length) { + this.curSelection = this.curSelection.map(this.doc, this.mapping.slice(this.curSelectionFor)); + this.curSelectionFor = this.steps.length; + } + return this.curSelection + }; + + // :: (Selection) → Transaction + // Update the transaction's current selection. Will determine the + // selection that the editor gets when the transaction is applied. + Transaction.prototype.setSelection = function setSelection (selection) { + if (selection.$from.doc != this.doc) + { throw new RangeError("Selection passed to setSelection must point at the current document") } + this.curSelection = selection; + this.curSelectionFor = this.steps.length; + this.updated = (this.updated | UPDATED_SEL) & ~UPDATED_MARKS; + this.storedMarks = null; + return this + }; + + // :: bool + // Whether the selection was explicitly updated by this transaction. + prototypeAccessors.selectionSet.get = function () { + return (this.updated & UPDATED_SEL) > 0 + }; + + // :: (?[Mark]) → Transaction + // Set the current stored marks. + Transaction.prototype.setStoredMarks = function setStoredMarks (marks) { + this.storedMarks = marks; + this.updated |= UPDATED_MARKS; + return this + }; + + // :: ([Mark]) → Transaction + // Make sure the current stored marks or, if that is null, the marks + // at the selection, match the given set of marks. Does nothing if + // this is already the case. + Transaction.prototype.ensureMarks = function ensureMarks (marks) { + if (!prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Mark"].sameSet(this.storedMarks || this.selection.$from.marks(), marks)) + { this.setStoredMarks(marks); } + return this + }; + + // :: (Mark) → Transaction + // Add a mark to the set of stored marks. + Transaction.prototype.addStoredMark = function addStoredMark (mark) { + return this.ensureMarks(mark.addToSet(this.storedMarks || this.selection.$head.marks())) + }; + + // :: (union) → Transaction + // Remove a mark or mark type from the set of stored marks. + Transaction.prototype.removeStoredMark = function removeStoredMark (mark) { + return this.ensureMarks(mark.removeFromSet(this.storedMarks || this.selection.$head.marks())) + }; + + // :: bool + // Whether the stored marks were explicitly set for this transaction. + prototypeAccessors.storedMarksSet.get = function () { + return (this.updated & UPDATED_MARKS) > 0 + }; + + Transaction.prototype.addStep = function addStep (step, doc) { + Transform.prototype.addStep.call(this, step, doc); + this.updated = this.updated & ~UPDATED_MARKS; + this.storedMarks = null; + }; + + // :: (number) → Transaction + // Update the timestamp for the transaction. + Transaction.prototype.setTime = function setTime (time) { + this.time = time; + return this + }; + + // :: (Slice) → Transaction + // Replace the current selection with the given slice. + Transaction.prototype.replaceSelection = function replaceSelection (slice) { + this.selection.replace(this, slice); + return this + }; + + // :: (Node, ?bool) → Transaction + // Replace the selection with the given node. When `inheritMarks` is + // true and the content is inline, it inherits the marks from the + // place where it is inserted. + Transaction.prototype.replaceSelectionWith = function replaceSelectionWith (node, inheritMarks) { + var selection = this.selection; + if (inheritMarks !== false) + { node = node.mark(this.storedMarks || (selection.empty ? selection.$from.marks() : (selection.$from.marksAcross(selection.$to) || prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Mark"].none))); } + selection.replaceWith(this, node); + return this + }; + + // :: () → Transaction + // Delete the selection. + Transaction.prototype.deleteSelection = function deleteSelection () { + this.selection.replace(this); + return this + }; + + // :: (string, from: ?number, to: ?number) → Transaction + // Replace the given range, or the selection if no range is given, + // with a text node containing the given string. + Transaction.prototype.insertText = function insertText (text, from, to) { + if ( to === void 0 ) to = from; + + var schema = this.doc.type.schema; + if (from == null) { + if (!text) { return this.deleteSelection() } + return this.replaceSelectionWith(schema.text(text), true) + } else { + if (!text) { return this.deleteRange(from, to) } + var marks = this.storedMarks; + if (!marks) { + var $from = this.doc.resolve(from); + marks = to == from ? $from.marks() : $from.marksAcross(this.doc.resolve(to)); + } + this.replaceRangeWith(from, to, schema.text(text, marks)); + if (!this.selection.empty) { this.setSelection(Selection.near(this.selection.$to)); } + return this + } + }; + + // :: (union, any) → Transaction + // Store a metadata property in this transaction, keyed either by + // name or by plugin. + Transaction.prototype.setMeta = function setMeta (key, value) { + this.meta[typeof key == "string" ? key : key.key] = value; + return this + }; + + // :: (union) → any + // Retrieve a metadata property for a given name or plugin. + Transaction.prototype.getMeta = function getMeta (key) { + return this.meta[typeof key == "string" ? key : key.key] + }; + + // :: bool + // Returns true if this transaction doesn't contain any metadata, + // and can thus safely be extended. + prototypeAccessors.isGeneric.get = function () { + for (var _ in this.meta) { return false } + return true + }; + + // :: () → Transaction + // Indicate that the editor should scroll the selection into view + // when updated to the state produced by this transaction. + Transaction.prototype.scrollIntoView = function scrollIntoView () { + this.updated |= UPDATED_SCROLL; + return this + }; + + prototypeAccessors.scrolledIntoView.get = function () { + return (this.updated & UPDATED_SCROLL) > 0 + }; + + Object.defineProperties( Transaction.prototype, prototypeAccessors ); + + return Transaction; +}(prosemirror_transform__WEBPACK_IMPORTED_MODULE_1__["Transform"])); + +function bind(f, self) { + return !self || !f ? f : f.bind(self) +} + +var FieldDesc = function FieldDesc(name, desc, self) { + this.name = name; + this.init = bind(desc.init, self); + this.apply = bind(desc.apply, self); +}; + +var baseFields = [ + new FieldDesc("doc", { + init: function init(config) { return config.doc || config.schema.topNodeType.createAndFill() }, + apply: function apply(tr) { return tr.doc } + }), + + new FieldDesc("selection", { + init: function init(config, instance) { return config.selection || Selection.atStart(instance.doc) }, + apply: function apply(tr) { return tr.selection } + }), + + new FieldDesc("storedMarks", { + init: function init(config) { return config.storedMarks || null }, + apply: function apply(tr, _marks, _old, state) { return state.selection.$cursor ? tr.storedMarks : null } + }), + + new FieldDesc("scrollToSelection", { + init: function init() { return 0 }, + apply: function apply(tr, prev) { return tr.scrolledIntoView ? prev + 1 : prev } + }) +]; + +// Object wrapping the part of a state object that stays the same +// across transactions. Stored in the state's `config` property. +var Configuration = function Configuration(schema, plugins) { + var this$1 = this; + + this.schema = schema; + this.fields = baseFields.concat(); + this.plugins = []; + this.pluginsByKey = Object.create(null); + if (plugins) { plugins.forEach(function (plugin) { + if (this$1.pluginsByKey[plugin.key]) + { throw new RangeError("Adding different instances of a keyed plugin (" + plugin.key + ")") } + this$1.plugins.push(plugin); + this$1.pluginsByKey[plugin.key] = plugin; + if (plugin.spec.state) + { this$1.fields.push(new FieldDesc(plugin.key, plugin.spec.state, plugin)); } + }); } +}; + +// ::- The state of a ProseMirror editor is represented by an object +// of this type. A state is a persistent data structure—it isn't +// updated, but rather a new state value is computed from an old one +// using the [`apply`](#state.EditorState.apply) method. +// +// A state holds a number of built-in fields, and plugins can +// [define](#state.PluginSpec.state) additional fields. +var EditorState = function EditorState(config) { + this.config = config; +}; + +var prototypeAccessors$1 = { schema: { configurable: true },plugins: { configurable: true },tr: { configurable: true } }; + +// doc:: Node +// The current document. + +// selection:: Selection +// The selection. + +// storedMarks:: ?[Mark] +// A set of marks to apply to the next input. Will be null when +// no explicit marks have been set. + +// :: Schema +// The schema of the state's document. +prototypeAccessors$1.schema.get = function () { + return this.config.schema +}; + +// :: [Plugin] +// The plugins that are active in this state. +prototypeAccessors$1.plugins.get = function () { + return this.config.plugins +}; + +// :: (Transaction) → EditorState +// Apply the given transaction to produce a new state. +EditorState.prototype.apply = function apply (tr) { + return this.applyTransaction(tr).state +}; + +// : (Transaction) → bool +EditorState.prototype.filterTransaction = function filterTransaction (tr, ignore) { + if ( ignore === void 0 ) ignore = -1; + + for (var i = 0; i < this.config.plugins.length; i++) { if (i != ignore) { + var plugin = this.config.plugins[i]; + if (plugin.spec.filterTransaction && !plugin.spec.filterTransaction.call(plugin, tr, this)) + { return false } + } } + return true +}; + +// :: (Transaction) → {state: EditorState, transactions: [Transaction]} +// Verbose variant of [`apply`](#state.EditorState.apply) that +// returns the precise transactions that were applied (which might +// be influenced by the [transaction +// hooks](#state.PluginSpec.filterTransaction) of +// plugins) along with the new state. +EditorState.prototype.applyTransaction = function applyTransaction (rootTr) { + if (!this.filterTransaction(rootTr)) { return {state: this, transactions: []} } + + var trs = [rootTr], newState = this.applyInner(rootTr), seen = null; + // This loop repeatedly gives plugins a chance to respond to + // transactions as new transactions are added, making sure to only + // pass the transactions the plugin did not see before. + for (;;) { + var haveNew = false; + for (var i = 0; i < this.config.plugins.length; i++) { + var plugin = this.config.plugins[i]; + if (plugin.spec.appendTransaction) { + var n = seen ? seen[i].n : 0, oldState = seen ? seen[i].state : this; + var tr = n < trs.length && + plugin.spec.appendTransaction.call(plugin, n ? trs.slice(n) : trs, oldState, newState); + if (tr && newState.filterTransaction(tr, i)) { + tr.setMeta("appendedTransaction", rootTr); + if (!seen) { + seen = []; + for (var j = 0; j < this.config.plugins.length; j++) + { seen.push(j < i ? {state: newState, n: trs.length} : {state: this, n: 0}); } + } + trs.push(tr); + newState = newState.applyInner(tr); + haveNew = true; + } + if (seen) { seen[i] = {state: newState, n: trs.length}; } + } + } + if (!haveNew) { return {state: newState, transactions: trs} } + } +}; + +// : (Transaction) → EditorState +EditorState.prototype.applyInner = function applyInner (tr) { + if (!tr.before.eq(this.doc)) { throw new RangeError("Applying a mismatched transaction") } + var newInstance = new EditorState(this.config), fields = this.config.fields; + for (var i = 0; i < fields.length; i++) { + var field = fields[i]; + newInstance[field.name] = field.apply(tr, this[field.name], this, newInstance); + } + for (var i$1 = 0; i$1 < applyListeners.length; i$1++) { applyListeners[i$1](this, tr, newInstance); } + return newInstance +}; + +// :: Transaction +// Start a [transaction](#state.Transaction) from this state. +prototypeAccessors$1.tr.get = function () { return new Transaction(this) }; + +// :: (Object) → EditorState +// Create a new state. +// +// config::- Configuration options. Must contain `schema` or `doc` (or both). +// +// schema:: ?Schema +// The schema to use. +// +// doc:: ?Node +// The starting document. +// +// selection:: ?Selection +// A valid selection in the document. +// +// storedMarks:: ?[Mark] +// The initial set of [stored marks](#state.EditorState.storedMarks). +// +// plugins:: ?[Plugin] +// The plugins that should be active in this state. +EditorState.create = function create (config) { + var $config = new Configuration(config.schema || config.doc.type.schema, config.plugins); + var instance = new EditorState($config); + for (var i = 0; i < $config.fields.length; i++) + { instance[$config.fields[i].name] = $config.fields[i].init(config, instance); } + return instance +}; + +// :: (Object) → EditorState +// Create a new state based on this one, but with an adjusted set of +// active plugins. State fields that exist in both sets of plugins +// are kept unchanged. Those that no longer exist are dropped, and +// those that are new are initialized using their +// [`init`](#state.StateField.init) method, passing in the new +// configuration object.. +// +// config::- configuration options +// +// schema:: ?Schema +// New schema to use. +// +// plugins:: ?[Plugin] +// New set of active plugins. +EditorState.prototype.reconfigure = function reconfigure (config) { + var $config = new Configuration(config.schema || this.schema, config.plugins); + var fields = $config.fields, instance = new EditorState($config); + for (var i = 0; i < fields.length; i++) { + var name = fields[i].name; + instance[name] = this.hasOwnProperty(name) ? this[name] : fields[i].init(config, instance); + } + return instance +}; + +// :: (?union, string, number>) → Object +// Serialize this state to JSON. If you want to serialize the state +// of plugins, pass an object mapping property names to use in the +// resulting JSON object to plugin objects. The argument may also be +// a string or number, in which case it is ignored, to support the +// way `JSON.stringify` calls `toString` methods. +EditorState.prototype.toJSON = function toJSON (pluginFields) { + var result = {doc: this.doc.toJSON(), selection: this.selection.toJSON()}; + if (this.storedMarks) { result.storedMarks = this.storedMarks.map(function (m) { return m.toJSON(); }); } + if (pluginFields && typeof pluginFields == 'object') { for (var prop in pluginFields) { + if (prop == "doc" || prop == "selection") + { throw new RangeError("The JSON fields `doc` and `selection` are reserved") } + var plugin = pluginFields[prop], state = plugin.spec.state; + if (state && state.toJSON) { result[prop] = state.toJSON.call(plugin, this[plugin.key]); } + } } + return result +}; + +// :: (Object, Object, ?Object) → EditorState +// Deserialize a JSON representation of a state. `config` should +// have at least a `schema` field, and should contain array of +// plugins to initialize the state with. `pluginFields` can be used +// to deserialize the state of plugins, by associating plugin +// instances with the property names they use in the JSON object. +// +// config::- configuration options +// +// schema:: Schema +// The schema to use. +// +// plugins:: ?[Plugin] +// The set of active plugins. +EditorState.fromJSON = function fromJSON (config, json, pluginFields) { + if (!json) { throw new RangeError("Invalid input for EditorState.fromJSON") } + if (!config.schema) { throw new RangeError("Required config field 'schema' missing") } + var $config = new Configuration(config.schema, config.plugins); + var instance = new EditorState($config); + $config.fields.forEach(function (field) { + if (field.name == "doc") { + instance.doc = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Node"].fromJSON(config.schema, json.doc); + } else if (field.name == "selection") { + instance.selection = Selection.fromJSON(instance.doc, json.selection); + } else if (field.name == "storedMarks") { + if (json.storedMarks) { instance.storedMarks = json.storedMarks.map(config.schema.markFromJSON); } + } else { + if (pluginFields) { for (var prop in pluginFields) { + var plugin = pluginFields[prop], state = plugin.spec.state; + if (plugin.key == field.name && state && state.fromJSON && + Object.prototype.hasOwnProperty.call(json, prop)) { + // This field belongs to a plugin mapped to a JSON field, read it from there. + instance[field.name] = state.fromJSON.call(plugin, config, json[prop], instance); + return + } + } } + instance[field.name] = field.init(config, instance); + } + }); + return instance +}; + +// Kludge to allow the view to track mappings between different +// instances of a state. +// +// FIXME this is no longer needed as of prosemirror-view 1.9.0, +// though due to backwards-compat we should probably keep it around +// for a while (if only as a no-op) +EditorState.addApplyListener = function addApplyListener (f) { + applyListeners.push(f); +}; +EditorState.removeApplyListener = function removeApplyListener (f) { + var found = applyListeners.indexOf(f); + if (found > -1) { applyListeners.splice(found, 1); } +}; + +Object.defineProperties( EditorState.prototype, prototypeAccessors$1 ); + +var applyListeners = []; + +// PluginSpec:: interface +// +// This is the type passed to the [`Plugin`](#state.Plugin) +// constructor. It provides a definition for a plugin. +// +// props:: ?EditorProps +// The [view props](#view.EditorProps) added by this plugin. Props +// that are functions will be bound to have the plugin instance as +// their `this` binding. +// +// state:: ?StateField +// Allows a plugin to define a [state field](#state.StateField), an +// extra slot in the state object in which it can keep its own data. +// +// key:: ?PluginKey +// Can be used to make this a keyed plugin. You can have only one +// plugin with a given key in a given state, but it is possible to +// access the plugin's configuration and state through the key, +// without having access to the plugin instance object. +// +// view:: ?(EditorView) → Object +// When the plugin needs to interact with the editor view, or +// set something up in the DOM, use this field. The function +// will be called when the plugin's state is associated with an +// editor view. +// +// return::- +// Should return an object with the following optional +// properties: +// +// update:: ?(view: EditorView, prevState: EditorState) +// Called whenever the view's state is updated. +// +// destroy:: ?() +// Called when the view is destroyed or receives a state +// with different plugins. +// +// filterTransaction:: ?(Transaction, EditorState) → bool +// When present, this will be called before a transaction is +// applied by the state, allowing the plugin to cancel it (by +// returning false). +// +// appendTransaction:: ?(transactions: [Transaction], oldState: EditorState, newState: EditorState) → ?Transaction +// Allows the plugin to append another transaction to be applied +// after the given array of transactions. When another plugin +// appends a transaction after this was called, it is called again +// with the new state and new transactions—but only the new +// transactions, i.e. it won't be passed transactions that it +// already saw. + +function bindProps(obj, self, target) { + for (var prop in obj) { + var val = obj[prop]; + if (val instanceof Function) { val = val.bind(self); } + else if (prop == "handleDOMEvents") { val = bindProps(val, self, {}); } + target[prop] = val; + } + return target +} + +// ::- Plugins bundle functionality that can be added to an editor. +// They are part of the [editor state](#state.EditorState) and +// may influence that state and the view that contains it. +var Plugin = function Plugin(spec) { + // :: EditorProps + // The [props](#view.EditorProps) exported by this plugin. + this.props = {}; + if (spec.props) { bindProps(spec.props, this, this.props); } + // :: Object + // The plugin's [spec object](#state.PluginSpec). + this.spec = spec; + this.key = spec.key ? spec.key.key : createKey("plugin"); +}; + +// :: (EditorState) → any +// Extract the plugin's state field from an editor state. +Plugin.prototype.getState = function getState (state) { return state[this.key] }; + +// StateField:: interface +// A plugin spec may provide a state field (under its +// [`state`](#state.PluginSpec.state) property) of this type, which +// describes the state it wants to keep. Functions provided here are +// always called with the plugin instance as their `this` binding. +// +// init:: (config: Object, instance: EditorState) → T +// Initialize the value of the field. `config` will be the object +// passed to [`EditorState.create`](#state.EditorState^create). Note +// that `instance` is a half-initialized state instance, and will +// not have values for plugin fields initialized after this one. +// +// apply:: (tr: Transaction, value: T, oldState: EditorState, newState: EditorState) → T +// Apply the given transaction to this state field, producing a new +// field value. Note that the `newState` argument is again a partially +// constructed state does not yet contain the state from plugins +// coming after this one. +// +// toJSON:: ?(value: T) → * +// Convert this field to JSON. Optional, can be left off to disable +// JSON serialization for the field. +// +// fromJSON:: ?(config: Object, value: *, state: EditorState) → T +// Deserialize the JSON representation of this field. Note that the +// `state` argument is again a half-initialized state. + +var keys = Object.create(null); + +function createKey(name) { + if (name in keys) { return name + "$" + ++keys[name] } + keys[name] = 0; + return name + "$" +} + +// ::- A key is used to [tag](#state.PluginSpec.key) +// plugins in a way that makes it possible to find them, given an +// editor state. Assigning a key does mean only one plugin of that +// type can be active in a state. +var PluginKey = function PluginKey(name) { +if ( name === void 0 ) name = "key"; + this.key = createKey(name); }; + +// :: (EditorState) → ?Plugin +// Get the active plugin with this key, if any, from an editor +// state. +PluginKey.prototype.get = function get (state) { return state.config.pluginsByKey[this.key] }; + +// :: (EditorState) → ?any +// Get the plugin's state from an editor state. +PluginKey.prototype.getState = function getState (state) { return state[this.key] }; + + +//# sourceMappingURL=index.es.js.map + + +/***/ }), + +/***/ "./node_modules/prosemirror-tables/dist/index.es.js": +/*!**********************************************************!*\ + !*** ./node_modules/prosemirror-tables/dist/index.es.js ***! + \**********************************************************/ +/*! exports provided: CellSelection, TableMap, __clipCells, __insertCells, __pastedCells, addColumn, addColumnAfter, addColumnBefore, addRow, addRowAfter, addRowBefore, cellAround, colCount, columnResizing, columnResizingPluginKey, deleteColumn, deleteRow, deleteTable, findCell, fixTables, fixTablesKey, goToNextCell, handlePaste, inSameTable, isInTable, mergeCells, moveCellForward, nextCell, removeColumn, removeRow, rowIsHeader, selectedRect, selectionCell, setCellAttr, splitCell, splitCellWithType, tableEditing, tableEditingKey, tableNodes, toggleHeader, toggleHeaderCell, toggleHeaderColumn, toggleHeaderRow, updateColumnsOnResize */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CellSelection", function() { return CellSelection; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "TableMap", function() { return TableMap; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__clipCells", function() { return clipCells; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__insertCells", function() { return insertCells; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__pastedCells", function() { return pastedCells; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "addColumn", function() { return addColumn; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "addColumnAfter", function() { return addColumnAfter; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "addColumnBefore", function() { return addColumnBefore; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "addRow", function() { return addRow; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "addRowAfter", function() { return addRowAfter; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "addRowBefore", function() { return addRowBefore; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "cellAround", function() { return cellAround; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "colCount", function() { return colCount; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "columnResizing", function() { return columnResizing; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "columnResizingPluginKey", function() { return key$1; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "deleteColumn", function() { return deleteColumn; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "deleteRow", function() { return deleteRow; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "deleteTable", function() { return deleteTable; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "findCell", function() { return findCell; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "fixTables", function() { return fixTables; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "fixTablesKey", function() { return fixTablesKey; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "goToNextCell", function() { return goToNextCell; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "handlePaste", function() { return handlePaste; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "inSameTable", function() { return inSameTable; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isInTable", function() { return isInTable; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "mergeCells", function() { return mergeCells; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "moveCellForward", function() { return moveCellForward; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "nextCell", function() { return nextCell; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "removeColumn", function() { return removeColumn; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "removeRow", function() { return removeRow; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "rowIsHeader", function() { return rowIsHeader; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectedRect", function() { return selectedRect; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectionCell", function() { return selectionCell; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setCellAttr", function() { return setCellAttr; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "splitCell", function() { return splitCell; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "splitCellWithType", function() { return splitCellWithType; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "tableEditing", function() { return tableEditing; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "tableEditingKey", function() { return key; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "tableNodes", function() { return tableNodes; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "toggleHeader", function() { return toggleHeader; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "toggleHeaderCell", function() { return toggleHeaderCell; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "toggleHeaderColumn", function() { return toggleHeaderColumn; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "toggleHeaderRow", function() { return toggleHeaderRow; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "updateColumnsOnResize", function() { return updateColumns; }); +/* harmony import */ var prosemirror_state__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! prosemirror-state */ "./node_modules/prosemirror-state/dist/index.es.js"); +/* harmony import */ var prosemirror_model__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! prosemirror-model */ "./node_modules/prosemirror-model/dist/index.es.js"); +/* harmony import */ var prosemirror_keymap__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! prosemirror-keymap */ "./node_modules/prosemirror-keymap/dist/index.es.js"); +/* harmony import */ var prosemirror_view__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! prosemirror-view */ "./node_modules/prosemirror-view/dist/index.es.js"); +/* harmony import */ var prosemirror_transform__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! prosemirror-transform */ "./node_modules/prosemirror-transform/dist/index.es.js"); + + + + + + +// Because working with row and column-spanning cells is not quite +// trivial, this code builds up a descriptive structure for a given +// table node. The structures are cached with the (persistent) table +// nodes as key, so that they only have to be recomputed when the +// content of the table changes. +// +// This does mean that they have to store table-relative, not +// document-relative positions. So code that uses them will typically +// compute the start position of the table and offset positions passed +// to or gotten from this structure by that amount. + +var readFromCache, addToCache; +// Prefer using a weak map to cache table maps. Fall back on a +// fixed-size cache if that's not supported. +if (typeof WeakMap != "undefined") { + var cache = new WeakMap; + readFromCache = function (key) { return cache.get(key); }; + addToCache = function (key, value) { + cache.set(key, value); + return value + }; +} else { + var cache$1 = [], cacheSize = 10, cachePos = 0; + readFromCache = function (key) { + for (var i = 0; i < cache$1.length; i += 2) + { if (cache$1[i] == key) { return cache$1[i + 1] } } + }; + addToCache = function (key, value) { + if (cachePos == cacheSize) { cachePos = 0; } + cache$1[cachePos++] = key; + return cache$1[cachePos++] = value + }; +} + +var Rect = function Rect(left, top, right, bottom) { + this.left = left; this.top = top; this.right = right; this.bottom = bottom; +}; + +// ::- A table map describes the structore of a given table. To avoid +// recomputing them all the time, they are cached per table node. To +// be able to do that, positions saved in the map are relative to the +// start of the table, rather than the start of the document. +var TableMap = function TableMap(width, height, map, problems) { + // :: number The width of the table + this.width = width; + // :: number The table's height + this.height = height; + // :: [number] A width * height array with the start position of + // the cell covering that part of the table in each slot + this.map = map; + // An optional array of problems (cell overlap or non-rectangular + // shape) for the table, used by the table normalizer. + this.problems = problems; +}; + +// :: (number) → Rect +// Find the dimensions of the cell at the given position. +TableMap.prototype.findCell = function findCell (pos) { + for (var i = 0; i < this.map.length; i++) { + var curPos = this.map[i]; + if (curPos != pos) { continue } + var left = i % this.width, top = (i / this.width) | 0; + var right = left + 1, bottom = top + 1; + for (var j = 1; right < this.width && this.map[i + j] == curPos; j++) { right++; } + for (var j$1 = 1; bottom < this.height && this.map[i + (this.width * j$1)] == curPos; j$1++) { bottom++; } + return new Rect(left, top, right, bottom) + } + throw new RangeError("No cell with offset " + pos + " found") +}; + +// :: (number) → number +// Find the left side of the cell at the given position. +TableMap.prototype.colCount = function colCount (pos) { + for (var i = 0; i < this.map.length; i++) + { if (this.map[i] == pos) { return i % this.width } } + throw new RangeError("No cell with offset " + pos + " found") +}; + +// :: (number, string, number) → ?number +// Find the next cell in the given direction, starting from the cell +// at `pos`, if any. +TableMap.prototype.nextCell = function nextCell (pos, axis, dir) { + var ref = this.findCell(pos); + var left = ref.left; + var right = ref.right; + var top = ref.top; + var bottom = ref.bottom; + if (axis == "horiz") { + if (dir < 0 ? left == 0 : right == this.width) { return null } + return this.map[top * this.width + (dir < 0 ? left - 1 : right)] + } else { + if (dir < 0 ? top == 0 : bottom == this.height) { return null } + return this.map[left + this.width * (dir < 0 ? top - 1 : bottom)] + } +}; + +// :: (number, number) → Rect +// Get the rectangle spanning the two given cells. +TableMap.prototype.rectBetween = function rectBetween (a, b) { + var ref = this.findCell(a); + var leftA = ref.left; + var rightA = ref.right; + var topA = ref.top; + var bottomA = ref.bottom; + var ref$1 = this.findCell(b); + var leftB = ref$1.left; + var rightB = ref$1.right; + var topB = ref$1.top; + var bottomB = ref$1.bottom; + return new Rect(Math.min(leftA, leftB), Math.min(topA, topB), + Math.max(rightA, rightB), Math.max(bottomA, bottomB)) +}; + +// :: (Rect) → [number] +// Return the position of all cells that have the top left corner in +// the given rectangle. +TableMap.prototype.cellsInRect = function cellsInRect (rect) { + var result = [], seen = {}; + for (var row = rect.top; row < rect.bottom; row++) { + for (var col = rect.left; col < rect.right; col++) { + var index = row * this.width + col, pos = this.map[index]; + if (seen[pos]) { continue } + seen[pos] = true; + if ((col != rect.left || !col || this.map[index - 1] != pos) && + (row != rect.top || !row || this.map[index - this.width] != pos)) + { result.push(pos); } + } + } + return result +}; + +// :: (number, number, Node) → number +// Return the position at which the cell at the given row and column +// starts, or would start, if a cell started there. +TableMap.prototype.positionAt = function positionAt (row, col, table) { + for (var i = 0, rowStart = 0;; i++) { + var rowEnd = rowStart + table.child(i).nodeSize; + if (i == row) { + var index = col + row * this.width, rowEndIndex = (row + 1) * this.width; + // Skip past cells from previous rows (via rowspan) + while (index < rowEndIndex && this.map[index] < rowStart) { index++; } + return index == rowEndIndex ? rowEnd - 1 : this.map[index] + } + rowStart = rowEnd; + } +}; + +// :: (Node) → TableMap +// Find the table map for the given table node. +TableMap.get = function get (table) { + return readFromCache(table) || addToCache(table, computeMap(table)) +}; + +// Compute a table map. +function computeMap(table) { + if (table.type.spec.tableRole != "table") { throw new RangeError("Not a table node: " + table.type.name) } + var width = findWidth(table), height = table.childCount; + var map = [], mapPos = 0, problems = null, colWidths = []; + for (var i = 0, e = width * height; i < e; i++) { map[i] = 0; } + + for (var row = 0, pos = 0; row < height; row++) { + var rowNode = table.child(row); + pos++; + for (var i$1 = 0;; i$1++) { + while (mapPos < map.length && map[mapPos] != 0) { mapPos++; } + if (i$1 == rowNode.childCount) { break } + var cellNode = rowNode.child(i$1); + var ref = cellNode.attrs; + var colspan = ref.colspan; + var rowspan = ref.rowspan; + var colwidth = ref.colwidth; + for (var h = 0; h < rowspan; h++) { + if (h + row >= height) { + (problems || (problems = [])).push({type: "overlong_rowspan", pos: pos, n: rowspan - h}); + break + } + var start = mapPos + (h * width); + for (var w = 0; w < colspan; w++) { + if (map[start + w] == 0) + { map[start + w] = pos; } + else + { (problems || (problems = [])).push({type: "collision", row: row, pos: pos, n: colspan - w}); } + var colW = colwidth && colwidth[w]; + if (colW) { + var widthIndex = ((start + w) % width) * 2, prev = colWidths[widthIndex]; + if (prev == null || (prev != colW && colWidths[widthIndex + 1] == 1)) { + colWidths[widthIndex] = colW; + colWidths[widthIndex + 1] = 1; + } else if (prev == colW) { + colWidths[widthIndex + 1]++; + } + } + } + } + mapPos += colspan; + pos += cellNode.nodeSize; + } + var expectedPos = (row + 1) * width, missing = 0; + while (mapPos < expectedPos) { if (map[mapPos++] == 0) { missing++; } } + if (missing) { (problems || (problems = [])).push({type: "missing", row: row, n: missing}); } + pos++; + } + + var tableMap = new TableMap(width, height, map, problems), badWidths = false; + + // For columns that have defined widths, but whose widths disagree + // between rows, fix up the cells whose width doesn't match the + // computed one. + for (var i$2 = 0; !badWidths && i$2 < colWidths.length; i$2 += 2) + { if (colWidths[i$2] != null && colWidths[i$2 + 1] < height) { badWidths = true; } } + if (badWidths) { findBadColWidths(tableMap, colWidths, table); } + + return tableMap +} + +function findWidth(table) { + var width = -1, hasRowSpan = false; + for (var row = 0; row < table.childCount; row++) { + var rowNode = table.child(row), rowWidth = 0; + if (hasRowSpan) { for (var j = 0; j < row; j++) { + var prevRow = table.child(j); + for (var i = 0; i < prevRow.childCount; i++) { + var cell = prevRow.child(i); + if (j + cell.attrs.rowspan > row) { rowWidth += cell.attrs.colspan; } + } + } } + for (var i$1 = 0; i$1 < rowNode.childCount; i$1++) { + var cell$1 = rowNode.child(i$1); + rowWidth += cell$1.attrs.colspan; + if (cell$1.attrs.rowspan > 1) { hasRowSpan = true; } + } + if (width == -1) + { width = rowWidth; } + else if (width != rowWidth) + { width = Math.max(width, rowWidth); } + } + return width +} + +function findBadColWidths(map, colWidths, table) { + if (!map.problems) { map.problems = []; } + for (var i = 0, seen = {}; i < map.map.length; i++) { + var pos = map.map[i]; + if (seen[pos]) { continue } + seen[pos] = true; + var node = table.nodeAt(pos), updated = null; + for (var j = 0; j < node.attrs.colspan; j++) { + var col = (i + j) % map.width, colWidth = colWidths[col * 2]; + if (colWidth != null && (!node.attrs.colwidth || node.attrs.colwidth[j] != colWidth)) + { (updated || (updated = freshColWidth(node.attrs)))[j] = colWidth; } + } + if (updated) { map.problems.unshift({type: "colwidth mismatch", pos: pos, colwidth: updated}); } + } +} + +function freshColWidth(attrs) { + if (attrs.colwidth) { return attrs.colwidth.slice() } + var result = []; + for (var i = 0; i < attrs.colspan; i++) { result.push(0); } + return result +} + +// Various helper function for working with tables + +var key = new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["PluginKey"]("selectingCells"); + +function cellAround($pos) { + for (var d = $pos.depth - 1; d > 0; d--) + { if ($pos.node(d).type.spec.tableRole == "row") { return $pos.node(0).resolve($pos.before(d + 1)) } } + return null +} + +function cellWrapping($pos) { + for (var d = $pos.depth; d > 0; d--) { // Sometimes the cell can be in the same depth. + var role = $pos.node(d).type.spec.tableRole; + if (role === "cell" || role === 'header_cell') { return $pos.node(d) } + } + return null +} + +function isInTable(state) { + var $head = state.selection.$head; + for (var d = $head.depth; d > 0; d--) { if ($head.node(d).type.spec.tableRole == "row") { return true } } + return false +} + +function selectionCell(state) { + var sel = state.selection; + if (sel.$anchorCell) { + return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell; + } else if (sel.node && sel.node.type.spec.tableRole == "cell") { + return sel.$anchor + } + return cellAround(sel.$head) || cellNear(sel.$head) +} + +function cellNear($pos) { + for (var after = $pos.nodeAfter, pos = $pos.pos; after; after = after.firstChild, pos++) { + var role = after.type.spec.tableRole; + if (role == "cell" || role == "header_cell") { return $pos.doc.resolve(pos) } + } + for (var before = $pos.nodeBefore, pos$1 = $pos.pos; before; before = before.lastChild, pos$1--) { + var role$1 = before.type.spec.tableRole; + if (role$1 == "cell" || role$1 == "header_cell") { return $pos.doc.resolve(pos$1 - before.nodeSize) } + } +} + +function pointsAtCell($pos) { + return $pos.parent.type.spec.tableRole == "row" && $pos.nodeAfter +} + +function moveCellForward($pos) { + return $pos.node(0).resolve($pos.pos + $pos.nodeAfter.nodeSize) +} + +function inSameTable($a, $b) { + return $a.depth == $b.depth && $a.pos >= $b.start(-1) && $a.pos <= $b.end(-1) +} + +function findCell($pos) { + return TableMap.get($pos.node(-1)).findCell($pos.pos - $pos.start(-1)) +} + +function colCount($pos) { + return TableMap.get($pos.node(-1)).colCount($pos.pos - $pos.start(-1)) +} + +function nextCell($pos, axis, dir) { + var start = $pos.start(-1), map = TableMap.get($pos.node(-1)); + var moved = map.nextCell($pos.pos - start, axis, dir); + return moved == null ? null : $pos.node(0).resolve(start + moved) +} + +function setAttr(attrs, name, value) { + var result = {}; + for (var prop in attrs) { result[prop] = attrs[prop]; } + result[name] = value; + return result +} + +function rmColSpan(attrs, pos, n) { + if ( n === void 0 ) n=1; + + var result = setAttr(attrs, "colspan", attrs.colspan - n); + if (result.colwidth) { + result.colwidth = result.colwidth.slice(); + result.colwidth.splice(pos, n); + if (!result.colwidth.some(function (w) { return w > 0; })) { result.colwidth = null; } + } + return result +} + +function addColSpan(attrs, pos, n) { + if ( n === void 0 ) n=1; + + var result = setAttr(attrs, "colspan", attrs.colspan + n); + if (result.colwidth) { + result.colwidth = result.colwidth.slice(); + for (var i = 0; i < n; i++) { result.colwidth.splice(pos, 0, 0); } + } + return result +} + +// This file defines a ProseMirror selection subclass that models + +// ::- A [`Selection`](http://prosemirror.net/docs/ref/#state.Selection) +// subclass that represents a cell selection spanning part of a table. +// With the plugin enabled, these will be created when the user +// selects across cells, and will be drawn by giving selected cells a +// `selectedCell` CSS class. +var CellSelection = /*@__PURE__*/(function (Selection) { + function CellSelection($anchorCell, $headCell) { + if ( $headCell === void 0 ) $headCell = $anchorCell; + + var table = $anchorCell.node(-1), map = TableMap.get(table), start = $anchorCell.start(-1); + var rect = map.rectBetween($anchorCell.pos - start, $headCell.pos - start); + var doc = $anchorCell.node(0); + var cells = map.cellsInRect(rect).filter(function (p) { return p != $headCell.pos - start; }); + // Make the head cell the first range, so that it counts as the + // primary part of the selection + cells.unshift($headCell.pos - start); + var ranges = cells.map(function (pos) { + var cell = table.nodeAt(pos), from = pos + start + 1; + return new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["SelectionRange"](doc.resolve(from), doc.resolve(from + cell.content.size)) + }); + Selection.call(this, ranges[0].$from, ranges[0].$to, ranges); + // :: ResolvedPos + // A resolved position pointing _in front of_ the anchor cell (the one + // that doesn't move when extending the selection). + this.$anchorCell = $anchorCell; + // :: ResolvedPos + // A resolved position pointing in front of the head cell (the one + // moves when extending the selection). + this.$headCell = $headCell; + } + + if ( Selection ) CellSelection.__proto__ = Selection; + CellSelection.prototype = Object.create( Selection && Selection.prototype ); + CellSelection.prototype.constructor = CellSelection; + + CellSelection.prototype.map = function map (doc, mapping) { + var $anchorCell = doc.resolve(mapping.map(this.$anchorCell.pos)); + var $headCell = doc.resolve(mapping.map(this.$headCell.pos)); + if (pointsAtCell($anchorCell) && pointsAtCell($headCell) && inSameTable($anchorCell, $headCell)) { + var tableChanged = this.$anchorCell.node(-1) != $anchorCell.node(-1); + if (tableChanged && this.isRowSelection()) + { return CellSelection.rowSelection($anchorCell, $headCell) } + else if (tableChanged && this.isColSelection()) + { return CellSelection.colSelection($anchorCell, $headCell) } + else + { return new CellSelection($anchorCell, $headCell) } + } + return prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"].between($anchorCell, $headCell) + }; + + // :: () → Slice + // Returns a rectangular slice of table rows containing the selected + // cells. + CellSelection.prototype.content = function content () { + var table = this.$anchorCell.node(-1), map = TableMap.get(table), start = this.$anchorCell.start(-1); + var rect = map.rectBetween(this.$anchorCell.pos - start, this.$headCell.pos - start); + var seen = {}, rows = []; + for (var row = rect.top; row < rect.bottom; row++) { + var rowContent = []; + for (var index = row * map.width + rect.left, col = rect.left; col < rect.right; col++, index++) { + var pos = map.map[index]; + if (!seen[pos]) { + seen[pos] = true; + var cellRect = map.findCell(pos), cell = table.nodeAt(pos); + var extraLeft = rect.left - cellRect.left, extraRight = cellRect.right - rect.right; + if (extraLeft > 0 || extraRight > 0) { + var attrs = cell.attrs; + if (extraLeft > 0) { attrs = rmColSpan(attrs, 0, extraLeft); } + if (extraRight > 0) { attrs = rmColSpan(attrs, attrs.colspan - extraRight, extraRight); } + if (cellRect.left < rect.left) { cell = cell.type.createAndFill(attrs); } + else { cell = cell.type.create(attrs, cell.content); } + } + if (cellRect.top < rect.top || cellRect.bottom > rect.bottom) { + var attrs$1 = setAttr(cell.attrs, "rowspan", Math.min(cellRect.bottom, rect.bottom) - Math.max(cellRect.top, rect.top)); + if (cellRect.top < rect.top) { cell = cell.type.createAndFill(attrs$1); } + else { cell = cell.type.create(attrs$1, cell.content); } + } + rowContent.push(cell); + } + } + rows.push(table.child(row).copy(prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(rowContent))); + } + + var fragment = this.isColSelection() && this.isRowSelection() ? table : rows; + return new prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Slice"](prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(fragment), 1, 1) + }; + + CellSelection.prototype.replace = function replace (tr, content) { + if ( content === void 0 ) content = prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Slice"].empty; + + var mapFrom = tr.steps.length, ranges = this.ranges; + for (var i = 0; i < ranges.length; i++) { + var ref = ranges[i]; + var $from = ref.$from; + var $to = ref.$to; + var mapping = tr.mapping.slice(mapFrom); + tr.replace(mapping.map($from.pos), mapping.map($to.pos), i ? prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Slice"].empty : content); + } + var sel = Selection.findFrom(tr.doc.resolve(tr.mapping.slice(mapFrom).map(this.to)), -1); + if (sel) { tr.setSelection(sel); } + }; + + CellSelection.prototype.replaceWith = function replaceWith (tr, node) { + this.replace(tr, new prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Slice"](prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(node), 0, 0)); + }; + + CellSelection.prototype.forEachCell = function forEachCell (f) { + var table = this.$anchorCell.node(-1), map = TableMap.get(table), start = this.$anchorCell.start(-1); + var cells = map.cellsInRect(map.rectBetween(this.$anchorCell.pos - start, this.$headCell.pos - start)); + for (var i = 0; i < cells.length; i++) + { f(table.nodeAt(cells[i]), start + cells[i]); } + }; + + // :: () → bool + // True if this selection goes all the way from the top to the + // bottom of the table. + CellSelection.prototype.isColSelection = function isColSelection () { + var anchorTop = this.$anchorCell.index(-1), headTop = this.$headCell.index(-1); + if (Math.min(anchorTop, headTop) > 0) { return false } + var anchorBot = anchorTop + this.$anchorCell.nodeAfter.attrs.rowspan, + headBot = headTop + this.$headCell.nodeAfter.attrs.rowspan; + return Math.max(anchorBot, headBot) == this.$headCell.node(-1).childCount + }; + + // :: (ResolvedPos, ?ResolvedPos) → CellSelection + // Returns the smallest column selection that covers the given anchor + // and head cell. + CellSelection.colSelection = function colSelection ($anchorCell, $headCell) { + if ( $headCell === void 0 ) $headCell = $anchorCell; + + var map = TableMap.get($anchorCell.node(-1)), start = $anchorCell.start(-1); + var anchorRect = map.findCell($anchorCell.pos - start), headRect = map.findCell($headCell.pos - start); + var doc = $anchorCell.node(0); + if (anchorRect.top <= headRect.top) { + if (anchorRect.top > 0) + { $anchorCell = doc.resolve(start + map.map[anchorRect.left]); } + if (headRect.bottom < map.height) + { $headCell = doc.resolve(start + map.map[map.width * (map.height - 1) + headRect.right - 1]); } + } else { + if (headRect.top > 0) + { $headCell = doc.resolve(start + map.map[headRect.left]); } + if (anchorRect.bottom < map.height) + { $anchorCell = doc.resolve(start + map.map[map.width * (map.height - 1) + anchorRect.right - 1]); } + } + return new CellSelection($anchorCell, $headCell) + }; + + // :: () → bool + // True if this selection goes all the way from the left to the + // right of the table. + CellSelection.prototype.isRowSelection = function isRowSelection () { + var map = TableMap.get(this.$anchorCell.node(-1)), start = this.$anchorCell.start(-1); + var anchorLeft = map.colCount(this.$anchorCell.pos - start), + headLeft = map.colCount(this.$headCell.pos - start); + if (Math.min(anchorLeft, headLeft) > 0) { return false } + var anchorRight = anchorLeft + this.$anchorCell.nodeAfter.attrs.colspan, + headRight = headLeft + this.$headCell.nodeAfter.attrs.colspan; + return Math.max(anchorRight, headRight) == map.width + }; + + CellSelection.prototype.eq = function eq (other) { + return other instanceof CellSelection && other.$anchorCell.pos == this.$anchorCell.pos && + other.$headCell.pos == this.$headCell.pos + }; + + // :: (ResolvedPos, ?ResolvedPos) → CellSelection + // Returns the smallest row selection that covers the given anchor + // and head cell. + CellSelection.rowSelection = function rowSelection ($anchorCell, $headCell) { + if ( $headCell === void 0 ) $headCell = $anchorCell; + + var map = TableMap.get($anchorCell.node(-1)), start = $anchorCell.start(-1); + var anchorRect = map.findCell($anchorCell.pos - start), headRect = map.findCell($headCell.pos - start); + var doc = $anchorCell.node(0); + if (anchorRect.left <= headRect.left) { + if (anchorRect.left > 0) + { $anchorCell = doc.resolve(start + map.map[anchorRect.top * map.width]); } + if (headRect.right < map.width) + { $headCell = doc.resolve(start + map.map[map.width * (headRect.top + 1) - 1]); } + } else { + if (headRect.left > 0) + { $headCell = doc.resolve(start + map.map[headRect.top * map.width]); } + if (anchorRect.right < map.width) + { $anchorCell = doc.resolve(start + map.map[map.width * (anchorRect.top + 1) - 1]); } + } + return new CellSelection($anchorCell, $headCell) + }; + + CellSelection.prototype.toJSON = function toJSON () { + return {type: "cell", anchor: this.$anchorCell.pos, head: this.$headCell.pos} + }; + + CellSelection.fromJSON = function fromJSON (doc, json) { + return new CellSelection(doc.resolve(json.anchor), doc.resolve(json.head)) + }; + + // :: (Node, number, ?number) → CellSelection + CellSelection.create = function create (doc, anchorCell, headCell) { + if ( headCell === void 0 ) headCell = anchorCell; + + return new CellSelection(doc.resolve(anchorCell), doc.resolve(headCell)) + }; + + CellSelection.prototype.getBookmark = function getBookmark () { return new CellBookmark(this.$anchorCell.pos, this.$headCell.pos) }; + + return CellSelection; +}(prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["Selection"])); + +CellSelection.prototype.visible = false; + +prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["Selection"].jsonID("cell", CellSelection); + +var CellBookmark = function CellBookmark(anchor, head) { + this.anchor = anchor; + this.head = head; +}; +CellBookmark.prototype.map = function map (mapping) { + return new CellBookmark(mapping.map(this.anchor), mapping.map(this.head)) +}; +CellBookmark.prototype.resolve = function resolve (doc) { + var $anchorCell = doc.resolve(this.anchor), $headCell = doc.resolve(this.head); + if ($anchorCell.parent.type.spec.tableRole == "row" && + $headCell.parent.type.spec.tableRole == "row" && + $anchorCell.index() < $anchorCell.parent.childCount && + $headCell.index() < $headCell.parent.childCount && + inSameTable($anchorCell, $headCell)) + { return new CellSelection($anchorCell, $headCell) } + else + { return prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["Selection"].near($headCell, 1) } +}; + +function drawCellSelection(state) { + if (!(state.selection instanceof CellSelection)) { return null } + var cells = []; + state.selection.forEachCell(function (node, pos) { + cells.push(prosemirror_view__WEBPACK_IMPORTED_MODULE_3__["Decoration"].node(pos, pos + node.nodeSize, {class: "selectedCell"})); + }); + return prosemirror_view__WEBPACK_IMPORTED_MODULE_3__["DecorationSet"].create(state.doc, cells) +} + +function isCellBoundarySelection(ref) { + var $from = ref.$from; + var $to = ref.$to; + + if ($from.pos == $to.pos || $from.pos < $from.pos - 6) { return false } // Cheap elimination + var afterFrom = $from.pos, beforeTo = $to.pos, depth = $from.depth; + for (; depth >= 0; depth--, afterFrom++) + { if ($from.after(depth + 1) < $from.end(depth)) { break } } + for (var d = $to.depth; d >= 0; d--, beforeTo--) + { if ($to.before(d + 1) > $to.start(d)) { break } } + return afterFrom == beforeTo && /row|table/.test($from.node(depth).type.spec.tableRole) +} + +function isTextSelectionAcrossCells(ref) { + var $from = ref.$from; + var $to = ref.$to; + + var fromCellBoundaryNode; + var toCellBoundaryNode; + + for (var i = $from.depth; i > 0; i--) { + var node = $from.node(i); + if (node.type.spec.tableRole === 'cell' || node.type.spec.tableRole === 'header_cell') { + fromCellBoundaryNode = node; + break; + } + } + + for (var i$1 = $to.depth; i$1 > 0; i$1--) { + var node$1 = $to.node(i$1); + if (node$1.type.spec.tableRole === 'cell' || node$1.type.spec.tableRole === 'header_cell') { + toCellBoundaryNode = node$1; + break; + } + } + + return fromCellBoundaryNode !== toCellBoundaryNode && $to.parentOffset === 0 +} + +function normalizeSelection(state, tr, allowTableNodeSelection) { + var sel = (tr || state).selection, doc = (tr || state).doc, normalize, role; + if (sel instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["NodeSelection"] && (role = sel.node.type.spec.tableRole)) { + if (role == "cell" || role == "header_cell") { + normalize = CellSelection.create(doc, sel.from); + } else if (role == "row") { + var $cell = doc.resolve(sel.from + 1); + normalize = CellSelection.rowSelection($cell, $cell); + } else if (!allowTableNodeSelection) { + var map = TableMap.get(sel.node), start = sel.from + 1; + var lastCell = start + map.map[map.width * map.height - 1]; + normalize = CellSelection.create(doc, start + 1, lastCell); + } + } else if (sel instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"] && isCellBoundarySelection(sel)) { + normalize = prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"].create(doc, sel.from); + } else if (sel instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"] && isTextSelectionAcrossCells(sel)) { + normalize = prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"].create(doc, sel.$from.start(), sel.$from.end()); + } + if (normalize) + { (tr || (tr = state.tr)).setSelection(normalize); } + return tr +} + +// Helper for creating a schema that supports tables. + +function getCellAttrs(dom, extraAttrs) { + var widthAttr = dom.getAttribute("data-colwidth"); + var widths = widthAttr && /^\d+(,\d+)*$/.test(widthAttr) ? widthAttr.split(",").map(function (s) { return Number(s); }) : null; + var colspan = Number(dom.getAttribute("colspan") || 1); + var result = { + colspan: colspan, + rowspan: Number(dom.getAttribute("rowspan") || 1), + colwidth: widths && widths.length == colspan ? widths : null + }; + for (var prop in extraAttrs) { + var getter = extraAttrs[prop].getFromDOM; + var value = getter && getter(dom); + if (value != null) { result[prop] = value; } + } + return result +} + +function setCellAttrs(node, extraAttrs) { + var attrs = {}; + if (node.attrs.colspan != 1) { attrs.colspan = node.attrs.colspan; } + if (node.attrs.rowspan != 1) { attrs.rowspan = node.attrs.rowspan; } + if (node.attrs.colwidth) + { attrs["data-colwidth"] = node.attrs.colwidth.join(","); } + for (var prop in extraAttrs) { + var setter = extraAttrs[prop].setDOMAttr; + if (setter) { setter(node.attrs[prop], attrs); } + } + return attrs +} + +// :: (Object) → Object +// +// This function creates a set of [node +// specs](http://prosemirror.net/docs/ref/#model.SchemaSpec.nodes) for +// `table`, `table_row`, and `table_cell` nodes types as used by this +// module. The result can then be added to the set of nodes when +// creating a a schema. +// +// options::- The following options are understood: +// +// tableGroup:: ?string +// A group name (something like `"block"`) to add to the table +// node type. +// +// cellContent:: string +// The content expression for table cells. +// +// cellAttributes:: ?Object +// Additional attributes to add to cells. Maps attribute names to +// objects with the following properties: +// +// default:: any +// The attribute's default value. +// +// getFromDOM:: ?(dom.Node) → any +// A function to read the attribute's value from a DOM node. +// +// setDOMAttr:: ?(value: any, attrs: Object) +// A function to add the attribute's value to an attribute +// object that's used to render the cell's DOM. +function tableNodes(options) { + var extraAttrs = options.cellAttributes || {}; + var cellAttrs = { + colspan: {default: 1}, + rowspan: {default: 1}, + colwidth: {default: null} + }; + for (var prop in extraAttrs) + { cellAttrs[prop] = {default: extraAttrs[prop].default}; } + + return { + table: { + content: "table_row+", + tableRole: "table", + isolating: true, + group: options.tableGroup, + parseDOM: [{tag: "table"}], + toDOM: function toDOM() { return ["table", ["tbody", 0]] } + }, + table_row: { + content: "(table_cell | table_header)*", + tableRole: "row", + parseDOM: [{tag: "tr"}], + toDOM: function toDOM() { return ["tr", 0] } + }, + table_cell: { + content: options.cellContent, + attrs: cellAttrs, + tableRole: "cell", + isolating: true, + parseDOM: [{tag: "td", getAttrs: function (dom) { return getCellAttrs(dom, extraAttrs); }}], + toDOM: function toDOM(node) { return ["td", setCellAttrs(node, extraAttrs), 0] } + }, + table_header: { + content: options.cellContent, + attrs: cellAttrs, + tableRole: "header_cell", + isolating: true, + parseDOM: [{tag: "th", getAttrs: function (dom) { return getCellAttrs(dom, extraAttrs); }}], + toDOM: function toDOM(node) { return ["th", setCellAttrs(node, extraAttrs), 0] } + } + } +} + +function tableNodeTypes(schema) { + var result = schema.cached.tableNodeTypes; + if (!result) { + result = schema.cached.tableNodeTypes = {}; + for (var name in schema.nodes) { + var type = schema.nodes[name], role = type.spec.tableRole; + if (role) { result[role] = type; } + } + } + return result +} + +// Utilities used for copy/paste handling. + +// Utilities to help with copying and pasting table cells + +// : (Slice) → ?{width: number, height: number, rows: [Fragment]} +// Get a rectangular area of cells from a slice, or null if the outer +// nodes of the slice aren't table cells or rows. +function pastedCells(slice) { + if (!slice.size) { return null } + var content = slice.content; + var openStart = slice.openStart; + var openEnd = slice.openEnd; + while (content.childCount == 1 && (openStart > 0 && openEnd > 0 || content.firstChild.type.spec.tableRole == "table")) { + openStart--; + openEnd--; + content = content.firstChild.content; + } + var first = content.firstChild, role = first.type.spec.tableRole; + var schema = first.type.schema, rows = []; + if (role == "row") { + for (var i = 0; i < content.childCount; i++) { + var cells = content.child(i).content; + var left = i ? 0 : Math.max(0, openStart - 1); + var right = i < content.childCount - 1 ? 0 : Math.max(0, openEnd - 1); + if (left || right) { cells = fitSlice(tableNodeTypes(schema).row, new prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Slice"](cells, left, right)).content; } + rows.push(cells); + } + } else if (role == "cell" || role == "header_cell") { + rows.push(openStart || openEnd ? fitSlice(tableNodeTypes(schema).row, new prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Slice"](content, openStart, openEnd)).content : content); + } else { + return null + } + return ensureRectangular(schema, rows) +} + +// : (Schema, [Fragment]) → {width: number, height: number, rows: [Fragment]} +// Compute the width and height of a set of cells, and make sure each +// row has the same number of cells. +function ensureRectangular(schema, rows) { + var widths = []; + for (var i = 0; i < rows.length; i++) { + var row = rows[i]; + for (var j = row.childCount - 1; j >= 0; j--) { + var ref = row.child(j).attrs; + var rowspan = ref.rowspan; + var colspan = ref.colspan; + for (var r = i; r < i + rowspan; r++) + { widths[r] = (widths[r] || 0) + colspan; } + } + } + var width = 0; + for (var r$1 = 0; r$1 < widths.length; r$1++) { width = Math.max(width, widths[r$1]); } + for (var r$2 = 0; r$2 < widths.length; r$2++) { + if (r$2 >= rows.length) { rows.push(prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].empty); } + if (widths[r$2] < width) { + var empty = tableNodeTypes(schema).cell.createAndFill(), cells = []; + for (var i$1 = widths[r$2]; i$1 < width; i$1++) { cells.push(empty); } + rows[r$2] = rows[r$2].append(prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(cells)); + } + } + return {height: rows.length, width: width, rows: rows} +} + +function fitSlice(nodeType, slice) { + var node = nodeType.createAndFill(); + var tr = new prosemirror_transform__WEBPACK_IMPORTED_MODULE_4__["Transform"](node).replace(0, node.content.size, slice); + return tr.doc +} + +// : ({width: number, height: number, rows: [Fragment]}, number, number) → {width: number, height: number, rows: [Fragment]} +// Clip or extend (repeat) the given set of cells to cover the given +// width and height. Will clip rowspan/colspan cells at the edges when +// they stick out. +function clipCells(ref, newWidth, newHeight) { + var width = ref.width; + var height = ref.height; + var rows = ref.rows; + + if (width != newWidth) { + var added = [], newRows = []; + for (var row = 0; row < rows.length; row++) { + var frag = rows[row], cells = []; + for (var col = added[row] || 0, i = 0; col < newWidth; i++) { + var cell = frag.child(i % frag.childCount); + if (col + cell.attrs.colspan > newWidth) + { cell = cell.type.create(rmColSpan(cell.attrs, cell.attrs.colspan, col + cell.attrs.colspan - newWidth), cell.content); } + cells.push(cell); + col += cell.attrs.colspan; + for (var j = 1; j < cell.attrs.rowspan; j++) + { added[row + j] = (added[row + j] || 0) + cell.attrs.colspan; } + } + newRows.push(prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(cells)); + } + rows = newRows; + width = newWidth; + } + + if (height != newHeight) { + var newRows$1 = []; + for (var row$1 = 0, i$1 = 0; row$1 < newHeight; row$1++, i$1++) { + var cells$1 = [], source = rows[i$1 % height]; + for (var j$1 = 0; j$1 < source.childCount; j$1++) { + var cell$1 = source.child(j$1); + if (row$1 + cell$1.attrs.rowspan > newHeight) + { cell$1 = cell$1.type.create(setAttr(cell$1.attrs, "rowspan", newHeight - cell$1.attrs.rowspan), cell$1.content); } + cells$1.push(cell$1); + } + newRows$1.push(prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(cells$1)); + } + rows = newRows$1; + height = newHeight; + } + + return {width: width, height: height, rows: rows} +} + +// Make sure a table has at least the given width and height. Return +// true if something was changed. +function growTable(tr, map, table, start, width, height, mapFrom) { + var schema = tr.doc.type.schema, types = tableNodeTypes(schema), empty, emptyHead; + if (width > map.width) { + for (var row = 0, rowEnd = 0; row < map.height; row++) { + var rowNode = table.child(row); + rowEnd += rowNode.nodeSize; + var cells = [], add = (void 0); + if (rowNode.lastChild == null || rowNode.lastChild.type == types.cell) + { add = empty || (empty = types.cell.createAndFill()); } + else + { add = emptyHead || (emptyHead = types.header_cell.createAndFill()); } + for (var i = map.width; i < width; i++) { cells.push(add); } + tr.insert(tr.mapping.slice(mapFrom).map(rowEnd - 1 + start), cells); + } + } + if (height > map.height) { + var cells$1 = []; + for (var i$1 = 0, start$1 = (map.height - 1) * map.width; i$1 < Math.max(map.width, width); i$1++) { + var header = i$1 >= map.width ? false : + table.nodeAt(map.map[start$1 + i$1]).type == types.header_cell; + cells$1.push(header + ? (emptyHead || (emptyHead = types.header_cell.createAndFill())) + : (empty || (empty = types.cell.createAndFill()))); + } + + var emptyRow = types.row.create(null, prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(cells$1)), rows = []; + for (var i$2 = map.height; i$2 < height; i$2++) { rows.push(emptyRow); } + tr.insert(tr.mapping.slice(mapFrom).map(start + table.nodeSize - 2), rows); + } + return !!(empty || emptyHead) +} + +// Make sure the given line (left, top) to (right, top) doesn't cross +// any rowspan cells by splitting cells that cross it. Return true if +// something changed. +function isolateHorizontal(tr, map, table, start, left, right, top, mapFrom) { + if (top == 0 || top == map.height) { return false } + var found = false; + for (var col = left; col < right; col++) { + var index = top * map.width + col, pos = map.map[index]; + if (map.map[index - map.width] == pos) { + found = true; + var cell = table.nodeAt(pos); + var ref = map.findCell(pos); + var cellTop = ref.top; + var cellLeft = ref.left; + tr.setNodeMarkup(tr.mapping.slice(mapFrom).map(pos + start), null, setAttr(cell.attrs, "rowspan", top - cellTop)); + tr.insert(tr.mapping.slice(mapFrom).map(map.positionAt(top, cellLeft, table)), + cell.type.createAndFill(setAttr(cell.attrs, "rowspan", (cellTop + cell.attrs.rowspan) - top))); + col += cell.attrs.colspan - 1; + } + } + return found +} + +// Make sure the given line (left, top) to (left, bottom) doesn't +// cross any colspan cells by splitting cells that cross it. Return +// true if something changed. +function isolateVertical(tr, map, table, start, top, bottom, left, mapFrom) { + if (left == 0 || left == map.width) { return false } + var found = false; + for (var row = top; row < bottom; row++) { + var index = row * map.width + left, pos = map.map[index]; + if (map.map[index - 1] == pos) { + found = true; + var cell = table.nodeAt(pos), cellLeft = map.colCount(pos); + var updatePos = tr.mapping.slice(mapFrom).map(pos + start); + tr.setNodeMarkup(updatePos, null, rmColSpan(cell.attrs, left - cellLeft, cell.attrs.colspan - (left - cellLeft))); + tr.insert(updatePos + cell.nodeSize, cell.type.createAndFill(rmColSpan(cell.attrs, 0, left - cellLeft))); + row += cell.attrs.rowspan - 1; + } + } + return found +} + +// Insert the given set of cells (as returned by `pastedCells`) into a +// table, at the position pointed at by rect. +function insertCells(state, dispatch, tableStart, rect, cells) { + var table = tableStart ? state.doc.nodeAt(tableStart - 1) : state.doc, map = TableMap.get(table); + var top = rect.top; + var left = rect.left; + var right = left + cells.width, bottom = top + cells.height; + var tr = state.tr, mapFrom = 0; + function recomp() { + table = tableStart ? tr.doc.nodeAt(tableStart - 1) : tr.doc; + map = TableMap.get(table); + mapFrom = tr.mapping.maps.length; + } + // Prepare the table to be large enough and not have any cells + // crossing the boundaries of the rectangle that we want to + // insert into. If anything about it changes, recompute the table + // map so that subsequent operations can see the current shape. + if (growTable(tr, map, table, tableStart, right, bottom, mapFrom)) { recomp(); } + if (isolateHorizontal(tr, map, table, tableStart, left, right, top, mapFrom)) { recomp(); } + if (isolateHorizontal(tr, map, table, tableStart, left, right, bottom, mapFrom)) { recomp(); } + if (isolateVertical(tr, map, table, tableStart, top, bottom, left, mapFrom)) { recomp(); } + if (isolateVertical(tr, map, table, tableStart, top, bottom, right, mapFrom)) { recomp(); } + + for (var row = top; row < bottom; row++) { + var from = map.positionAt(row, left, table), to = map.positionAt(row, right, table); + tr.replace(tr.mapping.slice(mapFrom).map(from + tableStart), tr.mapping.slice(mapFrom).map(to + tableStart), + new prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Slice"](cells.rows[row - top], 0, 0)); + } + recomp(); + tr.setSelection(new CellSelection(tr.doc.resolve(tableStart + map.positionAt(top, left, table)), + tr.doc.resolve(tableStart + map.positionAt(bottom - 1, right - 1, table)))); + dispatch(tr); +} + +// This file defines a number of helpers for wiring up user input to + +var handleKeyDown = Object(prosemirror_keymap__WEBPACK_IMPORTED_MODULE_2__["keydownHandler"])({ + "ArrowLeft": arrow("horiz", -1), + "ArrowRight": arrow("horiz", 1), + "ArrowUp": arrow("vert", -1), + "ArrowDown": arrow("vert", 1), + + "Shift-ArrowLeft": shiftArrow("horiz", -1), + "Shift-ArrowRight": shiftArrow("horiz", 1), + "Shift-ArrowUp": shiftArrow("vert", -1), + "Shift-ArrowDown": shiftArrow("vert", 1), + + "Backspace": deleteCellSelection, + "Mod-Backspace": deleteCellSelection, + "Delete": deleteCellSelection, + "Mod-Delete": deleteCellSelection +}); + +function maybeSetSelection(state, dispatch, selection) { + if (selection.eq(state.selection)) { return false } + if (dispatch) { dispatch(state.tr.setSelection(selection).scrollIntoView()); } + return true +} + +function arrow(axis, dir) { + return function (state, dispatch, view) { + var sel = state.selection; + if (sel instanceof CellSelection) { + return maybeSetSelection(state, dispatch, prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["Selection"].near(sel.$headCell, dir)) + } + if (axis != "horiz" && !sel.empty) { return false } + var end = atEndOfCell(view, axis, dir); + if (end == null) { return false } + if (axis == "horiz") { + return maybeSetSelection(state, dispatch, prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["Selection"].near(state.doc.resolve(sel.head + dir), dir)) + } else { + var $cell = state.doc.resolve(end), $next = nextCell($cell, axis, dir), newSel; + if ($next) { newSel = prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["Selection"].near($next, 1); } + else if (dir < 0) { newSel = prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["Selection"].near(state.doc.resolve($cell.before(-1)), -1); } + else { newSel = prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["Selection"].near(state.doc.resolve($cell.after(-1)), 1); } + return maybeSetSelection(state, dispatch, newSel) + } + } +} + +function shiftArrow(axis, dir) { + return function (state, dispatch, view) { + var sel = state.selection; + if (!(sel instanceof CellSelection)) { + var end = atEndOfCell(view, axis, dir); + if (end == null) { return false } + sel = new CellSelection(state.doc.resolve(end)); + } + var $head = nextCell(sel.$headCell, axis, dir); + if (!$head) { return false } + return maybeSetSelection(state, dispatch, new CellSelection(sel.$anchorCell, $head)) + } +} + +function deleteCellSelection(state, dispatch) { + var sel = state.selection; + if (!(sel instanceof CellSelection)) { return false } + if (dispatch) { + var tr = state.tr, baseContent = tableNodeTypes(state.schema).cell.createAndFill().content; + sel.forEachCell(function (cell, pos) { + if (!cell.content.eq(baseContent)) + { tr.replace(tr.mapping.map(pos + 1), tr.mapping.map(pos + cell.nodeSize - 1), + new prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Slice"](baseContent, 0, 0)); } + }); + if (tr.docChanged) { dispatch(tr); } + } + return true +} + +function handleTripleClick(view, pos) { + var doc = view.state.doc, $cell = cellAround(doc.resolve(pos)); + if (!$cell) { return false } + view.dispatch(view.state.tr.setSelection(new CellSelection($cell))); + return true +} + +function handlePaste(view, _, slice) { + if (!isInTable(view.state)) { return false } + var cells = pastedCells(slice), sel = view.state.selection; + if (sel instanceof CellSelection) { + if (!cells) { cells = {width: 1, height: 1, rows: [prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(fitSlice(tableNodeTypes(view.state.schema).cell, slice))]}; } + var table = sel.$anchorCell.node(-1), start = sel.$anchorCell.start(-1); + var rect = TableMap.get(table).rectBetween(sel.$anchorCell.pos - start, sel.$headCell.pos - start); + cells = clipCells(cells, rect.right - rect.left, rect.bottom - rect.top); + insertCells(view.state, view.dispatch, start, rect, cells); + return true + } else if (cells) { + var $cell = selectionCell(view.state), start$1 = $cell.start(-1); + insertCells(view.state, view.dispatch, start$1, TableMap.get($cell.node(-1)).findCell($cell.pos - start$1), cells); + return true + } else { + return false + } +} + +function handleMouseDown(view, startEvent) { + if (startEvent.ctrlKey || startEvent.metaKey) { return } + + var startDOMCell = domInCell(view, startEvent.target), $anchor; + if (startEvent.shiftKey && (view.state.selection instanceof CellSelection)) { + // Adding to an existing cell selection + setCellSelection(view.state.selection.$anchorCell, startEvent); + startEvent.preventDefault(); + } else if (startEvent.shiftKey && startDOMCell && + ($anchor = cellAround(view.state.selection.$anchor)) != null && + cellUnderMouse(view, startEvent).pos != $anchor.pos) { + // Adding to a selection that starts in another cell (causing a + // cell selection to be created). + setCellSelection($anchor, startEvent); + startEvent.preventDefault(); + } else if (!startDOMCell) { + // Not in a cell, let the default behavior happen. + return + } + + // Create and dispatch a cell selection between the given anchor and + // the position under the mouse. + function setCellSelection($anchor, event) { + var $head = cellUnderMouse(view, event); + var starting = key.getState(view.state) == null; + if (!$head || !inSameTable($anchor, $head)) { + if (starting) { $head = $anchor; } + else { return } + } + var selection = new CellSelection($anchor, $head); + if (starting || !view.state.selection.eq(selection)) { + var tr = view.state.tr.setSelection(selection); + if (starting) { tr.setMeta(key, $anchor.pos); } + view.dispatch(tr); + } + } + + // Stop listening to mouse motion events. + function stop() { + view.root.removeEventListener("mouseup", stop); + view.root.removeEventListener("dragstart", stop); + view.root.removeEventListener("mousemove", move); + if (key.getState(view.state) != null) { view.dispatch(view.state.tr.setMeta(key, -1)); } + } + + function move(event) { + var anchor = key.getState(view.state), $anchor; + if (anchor != null) { + // Continuing an existing cross-cell selection + $anchor = view.state.doc.resolve(anchor); + } else if (domInCell(view, event.target) != startDOMCell) { + // Moving out of the initial cell -- start a new cell selection + $anchor = cellUnderMouse(view, startEvent); + if (!$anchor) { return stop() } + } + if ($anchor) { setCellSelection($anchor, event); } + } + view.root.addEventListener("mouseup", stop); + view.root.addEventListener("dragstart", stop); + view.root.addEventListener("mousemove", move); +} + +// Check whether the cursor is at the end of a cell (so that further +// motion would move out of the cell) +function atEndOfCell(view, axis, dir) { + if (!(view.state.selection instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"])) { return null } + var ref = view.state.selection; + var $head = ref.$head; + for (var d = $head.depth - 1; d >= 0; d--) { + var parent = $head.node(d), index = dir < 0 ? $head.index(d) : $head.indexAfter(d); + if (index != (dir < 0 ? 0 : parent.childCount)) { return null } + if (parent.type.spec.tableRole == "cell" || parent.type.spec.tableRole == "header_cell") { + var cellPos = $head.before(d); + var dirStr = axis == "vert" ? (dir > 0 ? "down" : "up") : (dir > 0 ? "right" : "left"); + return view.endOfTextblock(dirStr) ? cellPos : null + } + } + return null +} + +function domInCell(view, dom) { + for (; dom && dom != view.dom; dom = dom.parentNode) + { if (dom.nodeName == "TD" || dom.nodeName == "TH") { return dom } } +} + +function cellUnderMouse(view, event) { + var mousePos = view.posAtCoords({left: event.clientX, top: event.clientY}); + if (!mousePos) { return null } + return mousePos ? cellAround(view.state.doc.resolve(mousePos.pos)) : null +} + +// This file defines helpers for normalizing tables, making sure no + +var fixTablesKey = new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["PluginKey"]("fix-tables"); + +// Helper for iterating through the nodes in a document that changed +// compared to the given previous document. Useful for avoiding +// duplicate work on each transaction. +function changedDescendants(old, cur, offset, f) { + var oldSize = old.childCount, curSize = cur.childCount; + outer: for (var i = 0, j = 0; i < curSize; i++) { + var child = cur.child(i); + for (var scan = j, e = Math.min(oldSize, i + 3); scan < e; scan++) { + if (old.child(scan) == child) { + j = scan + 1; + offset += child.nodeSize; + continue outer + } + } + f(child, offset); + if (j < oldSize && old.child(j).sameMarkup(child)) + { changedDescendants(old.child(j), child, offset + 1, f); } + else + { child.nodesBetween(0, child.content.size, f, offset + 1); } + offset += child.nodeSize; + } +} + +// :: (EditorState, ?EditorState) → ?Transaction +// Inspect all tables in the given state's document and return a +// transaction that fixes them, if necessary. If `oldState` was +// provided, that is assumed to hold a previous, known-good state, +// which will be used to avoid re-scanning unchanged parts of the +// document. +function fixTables(state, oldState) { + var tr, check = function (node, pos) { + if (node.type.spec.tableRole == "table") { tr = fixTable(state, node, pos, tr); } + }; + if (!oldState) { state.doc.descendants(check); } + else if (oldState.doc != state.doc) { changedDescendants(oldState.doc, state.doc, 0, check); } + return tr +} + +// : (EditorState, Node, number, ?Transaction) → ?Transaction +// Fix the given table, if necessary. Will append to the transaction +// it was given, if non-null, or create a new one if necessary. +function fixTable(state, table, tablePos, tr) { + var map = TableMap.get(table); + if (!map.problems) { return tr } + if (!tr) { tr = state.tr; } + + // Track which rows we must add cells to, so that we can adjust that + // when fixing collisions. + var mustAdd = []; + for (var i = 0; i < map.height; i++) { mustAdd.push(0); } + for (var i$1 = 0; i$1 < map.problems.length; i$1++) { + var prob = map.problems[i$1]; + if (prob.type == "collision") { + var cell = table.nodeAt(prob.pos); + for (var j = 0; j < cell.attrs.rowspan; j++) { mustAdd[prob.row + j] += prob.n; } + tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, rmColSpan(cell.attrs, cell.attrs.colspan - prob.n, prob.n)); + } else if (prob.type == "missing") { + mustAdd[prob.row] += prob.n; + } else if (prob.type == "overlong_rowspan") { + var cell$1 = table.nodeAt(prob.pos); + tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, setAttr(cell$1.attrs, "rowspan", cell$1.attrs.rowspan - prob.n)); + } else if (prob.type == "colwidth mismatch") { + var cell$2 = table.nodeAt(prob.pos); + tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, setAttr(cell$2.attrs, "colwidth", prob.colwidth)); + } + } + var first, last; + for (var i$2 = 0; i$2 < mustAdd.length; i$2++) { if (mustAdd[i$2]) { + if (first == null) { first = i$2; } + last = i$2; + } } + // Add the necessary cells, using a heuristic for whether to add the + // cells at the start or end of the rows (if it looks like a 'bite' + // was taken out of the table, add cells at the start of the row + // after the bite. Otherwise add them at the end). + for (var i$3 = 0, pos = tablePos + 1; i$3 < map.height; i$3++) { + var row = table.child(i$3); + var end = pos + row.nodeSize; + var add = mustAdd[i$3]; + if (add > 0) { + var tableNodeType = 'cell'; + if (row.firstChild) { + tableNodeType = row.firstChild.type.spec.tableRole; + } + var nodes = []; + for (var j$1 = 0; j$1 < add; j$1++) + { nodes.push(tableNodeTypes(state.schema)[tableNodeType].createAndFill()); } + var side = (i$3 == 0 || first == i$3 - 1) && last == i$3 ? pos + 1 : end - 1; + tr.insert(tr.mapping.map(side), nodes); + } + pos = end; + } + return tr.setMeta(fixTablesKey, { fixTables: true }) +} + +// This file defines a number of table-related commands. + +// Helper to get the selected rectangle in a table, if any. Adds table +// map, table node, and table start offset to the object for +// convenience. +function selectedRect(state) { + var sel = state.selection, $pos = selectionCell(state); + var table = $pos.node(-1), tableStart = $pos.start(-1), map = TableMap.get(table); + var rect; + if (sel instanceof CellSelection) + { rect = map.rectBetween(sel.$anchorCell.pos - tableStart, sel.$headCell.pos - tableStart); } + else + { rect = map.findCell($pos.pos - tableStart); } + rect.tableStart = tableStart; + rect.map = map; + rect.table = table; + return rect +} + +function columnIsHeader(map, table, col) { + var headerCell = tableNodeTypes(table.type.schema).header_cell; + for (var row = 0; row < map.height; row++) + { if (table.nodeAt(map.map[col + row * map.width]).type != headerCell) + { return false } } + return true +} + +// Add a column at the given position in a table. +function addColumn(tr, ref, col) { + var map = ref.map; + var tableStart = ref.tableStart; + var table = ref.table; + + var refColumn = col > 0 ? -1 : 0; + if (columnIsHeader(map, table, col + refColumn)) + { refColumn = col == 0 || col == map.width ? null : 0; } + + for (var row = 0; row < map.height; row++) { + var index = row * map.width + col; + // If this position falls inside a col-spanning cell + if (col > 0 && col < map.width && map.map[index - 1] == map.map[index]) { + var pos = map.map[index], cell = table.nodeAt(pos); + tr.setNodeMarkup(tr.mapping.map(tableStart + pos), null, + addColSpan(cell.attrs, col - map.colCount(pos))); + // Skip ahead if rowspan > 1 + row += cell.attrs.rowspan - 1; + } else { + var type = refColumn == null ? tableNodeTypes(table.type.schema).cell + : table.nodeAt(map.map[index + refColumn]).type; + var pos$1 = map.positionAt(row, col, table); + tr.insert(tr.mapping.map(tableStart + pos$1), type.createAndFill()); + } + } + return tr +} + +// :: (EditorState, dispatch: ?(tr: Transaction)) → bool +// Command to add a column before the column with the selection. +function addColumnBefore(state, dispatch) { + if (!isInTable(state)) { return false } + if (dispatch) { + var rect = selectedRect(state); + dispatch(addColumn(state.tr, rect, rect.left)); + } + return true +} + +// :: (EditorState, dispatch: ?(tr: Transaction)) → bool +// Command to add a column after the column with the selection. +function addColumnAfter(state, dispatch) { + if (!isInTable(state)) { return false } + if (dispatch) { + var rect = selectedRect(state); + dispatch(addColumn(state.tr, rect, rect.right)); + } + return true +} + +function removeColumn(tr, ref, col) { + var map = ref.map; + var table = ref.table; + var tableStart = ref.tableStart; + + var mapStart = tr.mapping.maps.length; + for (var row = 0; row < map.height;) { + var index = row * map.width + col, pos = map.map[index], cell = table.nodeAt(pos); + // If this is part of a col-spanning cell + if ((col > 0 && map.map[index - 1] == pos) || (col < map.width - 1 && map.map[index + 1] == pos)) { + tr.setNodeMarkup(tr.mapping.slice(mapStart).map(tableStart + pos), null, + rmColSpan(cell.attrs, col - map.colCount(pos))); + } else { + var start = tr.mapping.slice(mapStart).map(tableStart + pos); + tr.delete(start, start + cell.nodeSize); + } + row += cell.attrs.rowspan; + } +} + +// :: (EditorState, dispatch: ?(tr: Transaction)) → bool +// Command function that removes the selected columns from a table. +function deleteColumn(state, dispatch) { + if (!isInTable(state)) { return false } + if (dispatch) { + var rect = selectedRect(state), tr = state.tr; + if (rect.left == 0 && rect.right == rect.map.width) { return false } + for (var i = rect.right - 1;; i--) { + removeColumn(tr, rect, i); + if (i == rect.left) { break } + rect.table = rect.tableStart ? tr.doc.nodeAt(rect.tableStart - 1) : tr.doc; + rect.map = TableMap.get(rect.table); + } + dispatch(tr); + } + return true +} + +function rowIsHeader(map, table, row) { + var headerCell = tableNodeTypes(table.type.schema).header_cell; + for (var col = 0; col < map.width; col++) + { if (table.nodeAt(map.map[col + row * map.width]).type != headerCell) + { return false } } + return true +} + +function addRow(tr, ref, row) { + var map = ref.map; + var tableStart = ref.tableStart; + var table = ref.table; + + var rowPos = tableStart; + for (var i = 0; i < row; i++) { rowPos += table.child(i).nodeSize; } + var cells = [], refRow = row > 0 ? -1 : 0; + if (rowIsHeader(map, table, row + refRow)) + { refRow = row == 0 || row == map.height ? null : 0; } + for (var col = 0, index = map.width * row; col < map.width; col++, index++) { + // Covered by a rowspan cell + if (row > 0 && row < map.height && map.map[index] == map.map[index - map.width]) { + var pos = map.map[index], attrs = table.nodeAt(pos).attrs; + tr.setNodeMarkup(tableStart + pos, null, setAttr(attrs, "rowspan", attrs.rowspan + 1)); + col += attrs.colspan - 1; + } else { + var type = refRow == null ? tableNodeTypes(table.type.schema).cell + : table.nodeAt(map.map[index + refRow * map.width]).type; + cells.push(type.createAndFill()); + } + } + tr.insert(rowPos, tableNodeTypes(table.type.schema).row.create(null, cells)); + return tr +} + +// :: (EditorState, dispatch: ?(tr: Transaction)) → bool +// Add a table row before the selection. +function addRowBefore(state, dispatch) { + if (!isInTable(state)) { return false } + if (dispatch) { + var rect = selectedRect(state); + dispatch(addRow(state.tr, rect, rect.top)); + } + return true +} + +// :: (EditorState, dispatch: ?(tr: Transaction)) → bool +// Add a table row after the selection. +function addRowAfter(state, dispatch) { + if (!isInTable(state)) { return false } + if (dispatch) { + var rect = selectedRect(state); + dispatch(addRow(state.tr, rect, rect.bottom)); + } + return true +} + +function removeRow(tr, ref, row) { + var map = ref.map; + var table = ref.table; + var tableStart = ref.tableStart; + + var rowPos = 0; + for (var i = 0; i < row; i++) { rowPos += table.child(i).nodeSize; } + var nextRow = rowPos + table.child(row).nodeSize; + + var mapFrom = tr.mapping.maps.length; + tr.delete(rowPos + tableStart, nextRow + tableStart); + + for (var col = 0, index = row * map.width; col < map.width; col++, index++) { + var pos = map.map[index]; + if (row > 0 && pos == map.map[index - map.width]) { + // If this cell starts in the row above, simply reduce its rowspan + var attrs = table.nodeAt(pos).attrs; + tr.setNodeMarkup(tr.mapping.slice(mapFrom).map(pos + tableStart), null, setAttr(attrs, "rowspan", attrs.rowspan - 1)); + col += attrs.colspan - 1; + } else if (row < map.width && pos == map.map[index + map.width]) { + // Else, if it continues in the row below, it has to be moved down + var cell = table.nodeAt(pos); + var copy = cell.type.create(setAttr(cell.attrs, "rowspan", cell.attrs.rowspan - 1), cell.content); + var newPos = map.positionAt(row + 1, col, table); + tr.insert(tr.mapping.slice(mapFrom).map(tableStart + newPos), copy); + col += cell.attrs.colspan - 1; + } + } +} + +// :: (EditorState, dispatch: ?(tr: Transaction)) → bool +// Remove the selected rows from a table. +function deleteRow(state, dispatch) { + if (!isInTable(state)) { return false } + if (dispatch) { + var rect = selectedRect(state), tr = state.tr; + if (rect.top == 0 && rect.bottom == rect.map.height) { return false } + for (var i = rect.bottom - 1;; i--) { + removeRow(tr, rect, i); + if (i == rect.top) { break } + rect.table = rect.tableStart ? tr.doc.nodeAt(rect.tableStart - 1) : tr.doc; + rect.map = TableMap.get(rect.table); + } + dispatch(tr); + } + return true +} + +function isEmpty(cell) { + var c = cell.content; + return c.childCount == 1 && c.firstChild.isTextblock && c.firstChild.childCount == 0 +} + +function cellsOverlapRectangle(ref, rect) { + var width = ref.width; + var height = ref.height; + var map = ref.map; + + var indexTop = rect.top * width + rect.left, indexLeft = indexTop; + var indexBottom = (rect.bottom - 1) * width + rect.left, indexRight = indexTop + (rect.right - rect.left - 1); + for (var i = rect.top; i < rect.bottom; i++) { + if (rect.left > 0 && map[indexLeft] == map[indexLeft - 1] || + rect.right < width && map[indexRight] == map[indexRight + 1]) { return true } + indexLeft += width; indexRight += width; + } + for (var i$1 = rect.left; i$1 < rect.right; i$1++) { + if (rect.top > 0 && map[indexTop] == map[indexTop - width] || + rect.bottom < height && map[indexBottom] == map[indexBottom + width]) { return true } + indexTop++; indexBottom++; + } + return false +} + +// :: (EditorState, dispatch: ?(tr: Transaction)) → bool +// Merge the selected cells into a single cell. Only available when +// the selected cells' outline forms a rectangle. +function mergeCells(state, dispatch) { + var sel = state.selection; + if (!(sel instanceof CellSelection) || sel.$anchorCell.pos == sel.$headCell.pos) { return false } + var rect = selectedRect(state); + var map = rect.map; + if (cellsOverlapRectangle(map, rect)) { return false } + if (dispatch) { + var tr = state.tr, seen = {}, content = prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].empty, mergedPos, mergedCell; + for (var row = rect.top; row < rect.bottom; row++) { + for (var col = rect.left; col < rect.right; col++) { + var cellPos = map.map[row * map.width + col], cell = rect.table.nodeAt(cellPos); + if (seen[cellPos]) { continue } + seen[cellPos] = true; + if (mergedPos == null) { + mergedPos = cellPos; + mergedCell = cell; + } else { + if (!isEmpty(cell)) { content = content.append(cell.content); } + var mapped = tr.mapping.map(cellPos + rect.tableStart); + tr.delete(mapped, mapped + cell.nodeSize); + } + } + } + tr.setNodeMarkup(mergedPos + rect.tableStart, null, + setAttr(addColSpan(mergedCell.attrs, mergedCell.attrs.colspan, (rect.right - rect.left) - mergedCell.attrs.colspan), + "rowspan", rect.bottom - rect.top)); + if (content.size) { + var end = mergedPos + 1 + mergedCell.content.size; + var start = isEmpty(mergedCell) ? mergedPos + 1 : end; + tr.replaceWith(start + rect.tableStart, end + rect.tableStart, content); + } + tr.setSelection(new CellSelection(tr.doc.resolve(mergedPos + rect.tableStart))); + dispatch(tr); + } + return true +} +// :: (EditorState, dispatch: ?(tr: Transaction)) → bool +// Split a selected cell, whose rowpan or colspan is greater than one, +// into smaller cells. Use the first cell type for the new cells. +function splitCell(state, dispatch) { + var nodeTypes = tableNodeTypes(state.schema); + return splitCellWithType(function (ref) { + var node = ref.node; + + return nodeTypes[node.type.spec.tableRole] + })(state, dispatch) +} + +// :: (getCellType: ({ row: number, col: number, node: Node}) → NodeType) → (EditorState, dispatch: ?(tr: Transaction)) → bool +// Split a selected cell, whose rowpan or colspan is greater than one, +// into smaller cells with the cell type (th, td) returned by getType function. +function splitCellWithType(getCellType) { + return function (state, dispatch) { + var sel = state.selection; + var cellNode, cellPos; + if (!(sel instanceof CellSelection)) { + cellNode = cellWrapping(sel.$from); + if (!cellNode) { return false } + cellPos = cellAround(sel.$from).pos; + } else { + if (sel.$anchorCell.pos != sel.$headCell.pos) { return false } + cellNode = sel.$anchorCell.nodeAfter; + cellPos = sel.$anchorCell.pos; + } + if (cellNode.attrs.colspan == 1 && cellNode.attrs.rowspan == 1) {return false} + if (dispatch) { + var baseAttrs = cellNode.attrs, attrs = [], colwidth = baseAttrs.colwidth; + if (baseAttrs.rowspan > 1) { baseAttrs = setAttr(baseAttrs, "rowspan", 1); } + if (baseAttrs.colspan > 1) { baseAttrs = setAttr(baseAttrs, "colspan", 1); } + var rect = selectedRect(state), tr = state.tr; + for (var i = 0; i < rect.right - rect.left; i++) + { attrs.push(colwidth ? setAttr(baseAttrs, "colwidth", colwidth && colwidth[i] ? [colwidth[i]] : null) : baseAttrs); } + var lastCell; + for (var row = rect.top; row < rect.bottom; row++) { + var pos = rect.map.positionAt(row, rect.left, rect.table); + if (row == rect.top) { pos += cellNode.nodeSize; } + for (var col = rect.left, i$1 = 0; col < rect.right; col++, i$1++) { + if (col == rect.left && row == rect.top) { continue } + tr.insert(lastCell = tr.mapping.map(pos + rect.tableStart, 1), getCellType({ node: cellNode, row: row, col: col}).createAndFill(attrs[i$1])); + } + } + tr.setNodeMarkup(cellPos, getCellType({ node: cellNode, row: rect.top, col: rect.left}), attrs[0]); + if (sel instanceof CellSelection) + { tr.setSelection(new CellSelection(tr.doc.resolve(sel.$anchorCell.pos), + lastCell && tr.doc.resolve(lastCell))); } + dispatch(tr); + } + return true + } +} + +// :: (string, any) → (EditorState, dispatch: ?(tr: Transaction)) → bool +// Returns a command that sets the given attribute to the given value, +// and is only available when the currently selected cell doesn't +// already have that attribute set to that value. +function setCellAttr(name, value) { + return function(state, dispatch) { + if (!isInTable(state)) { return false } + var $cell = selectionCell(state); + if ($cell.nodeAfter.attrs[name] === value) { return false } + if (dispatch) { + var tr = state.tr; + if (state.selection instanceof CellSelection) + { state.selection.forEachCell(function (node, pos) { + if (node.attrs[name] !== value) + { tr.setNodeMarkup(pos, null, setAttr(node.attrs, name, value)); } + }); } + else + { tr.setNodeMarkup($cell.pos, null, setAttr($cell.nodeAfter.attrs, name, value)); } + dispatch(tr); + } + return true + } +} + +function deprecated_toggleHeader(type) { + return function(state, dispatch) { + if (!isInTable(state)) { return false } + if (dispatch) { + var types = tableNodeTypes(state.schema); + var rect = selectedRect(state), tr = state.tr; + var cells = rect.map.cellsInRect(type == "column" ? new Rect(rect.left, 0, rect.right, rect.map.height) : + type == "row" ? new Rect(0, rect.top, rect.map.width, rect.bottom) : rect); + var nodes = cells.map(function (pos) { return rect.table.nodeAt(pos); }); + for (var i = 0; i < cells.length; i++) // Remove headers, if any + { if (nodes[i].type == types.header_cell) + { tr.setNodeMarkup(rect.tableStart + cells[i], types.cell, nodes[i].attrs); } } + if (tr.steps.length == 0) { for (var i$1 = 0; i$1 < cells.length; i$1++) // No headers removed, add instead + { tr.setNodeMarkup(rect.tableStart + cells[i$1], types.header_cell, nodes[i$1].attrs); } } + dispatch(tr); + } + return true + } +} + +function isHeaderEnabledByType(type, rect, types) { + // Get cell positions for first row or first column + var cellPositions = rect.map.cellsInRect({ + left: 0, + top: 0, + right: type == "row" ? rect.map.width : 1, + bottom: type == "column" ? rect.map.height : 1, + }); + + for (var i = 0; i < cellPositions.length; i++) { + var cell = rect.table.nodeAt(cellPositions[i]); + if (cell && cell.type !== types.header_cell) { + return false + } + } + + return true +} + +// :: (string, ?{ useDeprecatedLogic: bool }) → (EditorState, dispatch: ?(tr: Transaction)) → bool +// Toggles between row/column header and normal cells (Only applies to first row/column). +// For deprecated behavior pass `useDeprecatedLogic` in options with true. +function toggleHeader(type, options) { + options = options || { useDeprecatedLogic: false }; + + if (options.useDeprecatedLogic) + { return deprecated_toggleHeader(type) } + + return function(state, dispatch) { + if (!isInTable(state)) { return false } + if (dispatch) { + var types = tableNodeTypes(state.schema); + var rect = selectedRect(state), tr = state.tr; + + var isHeaderRowEnabled = isHeaderEnabledByType("row", rect, types); + var isHeaderColumnEnabled = isHeaderEnabledByType("column", rect, types); + + var isHeaderEnabled = type === "column" ? isHeaderRowEnabled : + type === "row" ? isHeaderColumnEnabled : false; + + var selectionStartsAt = isHeaderEnabled ? 1 : 0; + + var cellsRect = type == "column" ? new Rect(0, selectionStartsAt, 1, rect.map.height) : + type == "row" ? new Rect(selectionStartsAt, 0, rect.map.width, 1) : rect; + + var newType = type == "column" ? isHeaderColumnEnabled ? types.cell : types.header_cell : + type == "row" ? isHeaderRowEnabled ? types.cell : types.header_cell : types.cell; + + rect.map.cellsInRect(cellsRect).forEach(function (relativeCellPos) { + var cellPos = relativeCellPos + rect.tableStart; + var cell = tr.doc.nodeAt(cellPos); + + if (cell) { + tr.setNodeMarkup(cellPos, newType, cell.attrs); + } + }); + + dispatch(tr); + } + return true + } +} + +// :: (EditorState, dispatch: ?(tr: Transaction)) → bool +// Toggles whether the selected row contains header cells. +var toggleHeaderRow = toggleHeader("row", { useDeprecatedLogic: true }); + +// :: (EditorState, dispatch: ?(tr: Transaction)) → bool +// Toggles whether the selected column contains header cells. +var toggleHeaderColumn = toggleHeader("column", { useDeprecatedLogic: true }); + +// :: (EditorState, dispatch: ?(tr: Transaction)) → bool +// Toggles whether the selected cells are header cells. +var toggleHeaderCell = toggleHeader("cell", { useDeprecatedLogic: true }); + +function findNextCell($cell, dir) { + if (dir < 0) { + var before = $cell.nodeBefore; + if (before) { return $cell.pos - before.nodeSize } + for (var row = $cell.index(-1) - 1, rowEnd = $cell.before(); row >= 0; row--) { + var rowNode = $cell.node(-1).child(row); + if (rowNode.childCount) { return rowEnd - 1 - rowNode.lastChild.nodeSize } + rowEnd -= rowNode.nodeSize; + } + } else { + if ($cell.index() < $cell.parent.childCount - 1) { return $cell.pos + $cell.nodeAfter.nodeSize } + var table = $cell.node(-1); + for (var row$1 = $cell.indexAfter(-1), rowStart = $cell.after(); row$1 < table.childCount; row$1++) { + var rowNode$1 = table.child(row$1); + if (rowNode$1.childCount) { return rowStart + 1 } + rowStart += rowNode$1.nodeSize; + } + } +} + +// :: (number) → (EditorState, dispatch: ?(tr: Transaction)) → bool +// Returns a command for selecting the next (direction=1) or previous +// (direction=-1) cell in a table. +function goToNextCell(direction) { + return function(state, dispatch) { + if (!isInTable(state)) { return false } + var cell = findNextCell(selectionCell(state), direction); + if (cell == null) { return } + if (dispatch) { + var $cell = state.doc.resolve(cell); + dispatch(state.tr.setSelection(prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"].between($cell, moveCellForward($cell))).scrollIntoView()); + } + return true + } +} + +// :: (EditorState, ?(tr: Transaction)) → bool +// Deletes the table around the selection, if any. +function deleteTable(state, dispatch) { + var $pos = state.selection.$anchor; + for (var d = $pos.depth; d > 0; d--) { + var node = $pos.node(d); + if (node.type.spec.tableRole == "table") { + if (dispatch) { dispatch(state.tr.delete($pos.before(d), $pos.after(d)).scrollIntoView()); } + return true + } + } + return false +} + +var TableView = function TableView(node, cellMinWidth) { + this.node = node; + this.cellMinWidth = cellMinWidth; + this.dom = document.createElement("div"); + this.dom.className = "tableWrapper"; + this.table = this.dom.appendChild(document.createElement("table")); + this.colgroup = this.table.appendChild(document.createElement("colgroup")); + updateColumns(node, this.colgroup, this.table, cellMinWidth); + this.contentDOM = this.table.appendChild(document.createElement("tbody")); +}; + +TableView.prototype.update = function update (node) { + if (node.type != this.node.type) { return false } + this.node = node; + updateColumns(node, this.colgroup, this.table, this.cellMinWidth); + return true +}; + +TableView.prototype.ignoreMutation = function ignoreMutation (record) { + return record.type == "attributes" && (record.target == this.table || this.colgroup.contains(record.target)) +}; + +function updateColumns(node, colgroup, table, cellMinWidth, overrideCol, overrideValue) { + var totalWidth = 0, fixedWidth = true; + var nextDOM = colgroup.firstChild, row = node.firstChild; + for (var i = 0, col = 0; i < row.childCount; i++) { + var ref = row.child(i).attrs; + var colspan = ref.colspan; + var colwidth = ref.colwidth; + for (var j = 0; j < colspan; j++, col++) { + var hasWidth = overrideCol == col ? overrideValue : colwidth && colwidth[j]; + var cssWidth = hasWidth ? hasWidth + "px" : ""; + totalWidth += hasWidth || cellMinWidth; + if (!hasWidth) { fixedWidth = false; } + if (!nextDOM) { + colgroup.appendChild(document.createElement("col")).style.width = cssWidth; + } else { + if (nextDOM.style.width != cssWidth) { nextDOM.style.width = cssWidth; } + nextDOM = nextDOM.nextSibling; + } + } + } + + while (nextDOM) { + var after = nextDOM.nextSibling; + nextDOM.parentNode.removeChild(nextDOM); + nextDOM = after; + } + + if (fixedWidth) { + table.style.width = totalWidth + "px"; + table.style.minWidth = ""; + } else { + table.style.width = ""; + table.style.minWidth = totalWidth + "px"; + } +} + +var key$1 = new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["PluginKey"]("tableColumnResizing"); + +function columnResizing(ref) { + if ( ref === void 0 ) ref = {}; + var handleWidth = ref.handleWidth; if ( handleWidth === void 0 ) handleWidth = 5; + var cellMinWidth = ref.cellMinWidth; if ( cellMinWidth === void 0 ) cellMinWidth = 25; + var View = ref.View; if ( View === void 0 ) View = TableView; + var lastColumnResizable = ref.lastColumnResizable; if ( lastColumnResizable === void 0 ) lastColumnResizable = true; + + var plugin = new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["Plugin"]({ + key: key$1, + state: { + init: function init(_, state) { + this.spec.props.nodeViews[tableNodeTypes(state.schema).table.name] = + function (node, view) { return new View(node, cellMinWidth, view); }; + return new ResizeState(-1, false) + }, + apply: function apply(tr, prev) { + return prev.apply(tr) + } + }, + props: { + attributes: function attributes(state) { + var pluginState = key$1.getState(state); + return pluginState.activeHandle > -1 ? {class: "resize-cursor"} : null + }, + + handleDOMEvents: { + mousemove: function mousemove(view, event) { handleMouseMove(view, event, handleWidth, cellMinWidth, lastColumnResizable); }, + mouseleave: function mouseleave(view) { handleMouseLeave(view); }, + mousedown: function mousedown(view, event) { handleMouseDown$1(view, event, cellMinWidth); } + }, + + decorations: function decorations(state) { + var pluginState = key$1.getState(state); + if (pluginState.activeHandle > -1) { return handleDecorations(state, pluginState.activeHandle) } + }, + + nodeViews: {} + } + }); + return plugin +} + +var ResizeState = function ResizeState(activeHandle, dragging) { + this.activeHandle = activeHandle; + this.dragging = dragging; +}; + +ResizeState.prototype.apply = function apply (tr) { + var state = this, action = tr.getMeta(key$1); + if (action && action.setHandle != null) + { return new ResizeState(action.setHandle, null) } + if (action && action.setDragging !== undefined) + { return new ResizeState(state.activeHandle, action.setDragging) } + if (state.activeHandle > -1 && tr.docChanged) { + var handle = tr.mapping.map(state.activeHandle, -1); + if (!pointsAtCell(tr.doc.resolve(handle))) { handle = null; } + state = new ResizeState(handle, state.dragging); + } + return state +}; + +function handleMouseMove(view, event, handleWidth, cellMinWidth, lastColumnResizable) { + var pluginState = key$1.getState(view.state); + + if (!pluginState.dragging) { + var target = domCellAround(event.target), cell = -1; + if (target) { + var ref = target.getBoundingClientRect(); + var left = ref.left; + var right = ref.right; + if (event.clientX - left <= handleWidth) + { cell = edgeCell(view, event, "left"); } + else if (right - event.clientX <= handleWidth) + { cell = edgeCell(view, event, "right"); } + } + + if (cell != pluginState.activeHandle) { + if (!lastColumnResizable && cell !== -1) { + var $cell = view.state.doc.resolve(cell); + var table = $cell.node(-1), map = TableMap.get(table), start = $cell.start(-1); + var col = map.colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan - 1; + + if (col == map.width - 1) { + return + } + } + + updateHandle(view, cell); + } + } +} + +function handleMouseLeave(view) { + var pluginState = key$1.getState(view.state); + if (pluginState.activeHandle > -1 && !pluginState.dragging) { updateHandle(view, -1); } +} + +function handleMouseDown$1(view, event, cellMinWidth) { + var pluginState = key$1.getState(view.state); + if (pluginState.activeHandle == -1 || pluginState.dragging) { return false } + + var cell = view.state.doc.nodeAt(pluginState.activeHandle); + var width = currentColWidth(view, pluginState.activeHandle, cell.attrs); + view.dispatch(view.state.tr.setMeta(key$1, {setDragging: {startX: event.clientX, startWidth: width}})); + + function finish(event) { + window.removeEventListener("mouseup", finish); + window.removeEventListener("mousemove", move); + var pluginState = key$1.getState(view.state); + if (pluginState.dragging) { + updateColumnWidth(view, pluginState.activeHandle, draggedWidth(pluginState.dragging, event, cellMinWidth)); + view.dispatch(view.state.tr.setMeta(key$1, {setDragging: null})); + } + } + function move(event) { + if (!event.which) { return finish(event) } + var pluginState = key$1.getState(view.state); + var dragged = draggedWidth(pluginState.dragging, event, cellMinWidth); + displayColumnWidth(view, pluginState.activeHandle, dragged, cellMinWidth); + } + + window.addEventListener("mouseup", finish); + window.addEventListener("mousemove", move); + event.preventDefault(); + return true +} + +function currentColWidth(view, cellPos, ref) { + var colspan = ref.colspan; + var colwidth = ref.colwidth; + + var width = colwidth && colwidth[colwidth.length - 1]; + if (width) { return width } + var dom = view.domAtPos(cellPos); + var node = dom.node.childNodes[dom.offset]; + var domWidth = node.offsetWidth, parts = colspan; + if (colwidth) { for (var i = 0; i < colspan; i++) { if (colwidth[i]) { + domWidth -= colwidth[i]; + parts--; + } } } + return domWidth / parts +} + +function domCellAround(target) { + while (target && target.nodeName != "TD" && target.nodeName != "TH") + { target = target.classList.contains("ProseMirror") ? null : target.parentNode; } + return target +} + +function edgeCell(view, event, side) { + var ref = view.posAtCoords({left: event.clientX, top: event.clientY}); + var pos = ref.pos; + var $cell = cellAround(view.state.doc.resolve(pos)); + if (!$cell) { return -1 } + if (side == "right") { return $cell.pos } + var map = TableMap.get($cell.node(-1)), start = $cell.start(-1); + var index = map.map.indexOf($cell.pos - start); + return index % map.width == 0 ? -1 : start + map.map[index - 1] +} + +function draggedWidth(dragging, event, cellMinWidth) { + var offset = event.clientX - dragging.startX; + return Math.max(cellMinWidth, dragging.startWidth + offset) +} + +function updateHandle(view, value) { + view.dispatch(view.state.tr.setMeta(key$1, {setHandle: value})); +} + +function updateColumnWidth(view, cell, width) { + var $cell = view.state.doc.resolve(cell); + var table = $cell.node(-1), map = TableMap.get(table), start = $cell.start(-1); + var col = map.colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan - 1; + var tr = view.state.tr; + for (var row = 0; row < map.height; row++) { + var mapIndex = row * map.width + col; + // Rowspanning cell that has already been handled + if (row && map.map[mapIndex] == map.map[mapIndex - map.width]) { continue } + var pos = map.map[mapIndex]; + var ref = table.nodeAt(pos); + var attrs = ref.attrs; + var index = attrs.colspan == 1 ? 0 : col - map.colCount(pos); + if (attrs.colwidth && attrs.colwidth[index] == width) { continue } + var colwidth = attrs.colwidth ? attrs.colwidth.slice() : zeroes(attrs.colspan); + colwidth[index] = width; + tr.setNodeMarkup(start + pos, null, setAttr(attrs, "colwidth", colwidth)); + } + if (tr.docChanged) { view.dispatch(tr); } +} + +function displayColumnWidth(view, cell, width, cellMinWidth) { + var $cell = view.state.doc.resolve(cell); + var table = $cell.node(-1), start = $cell.start(-1); + var col = TableMap.get(table).colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan - 1; + var dom = view.domAtPos($cell.start(-1)).node; + while (dom.nodeName != "TABLE") { dom = dom.parentNode; } + updateColumns(table, dom.firstChild, dom, cellMinWidth, col, width); +} + +function zeroes(n) { + var result = []; + for (var i = 0; i < n; i++) { result.push(0); } + return result +} + +function handleDecorations(state, cell) { + var decorations = []; + var $cell = state.doc.resolve(cell); + var table = $cell.node(-1), map = TableMap.get(table), start = $cell.start(-1); + var col = map.colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan; + for (var row = 0; row < map.height; row++) { + var index = col + row * map.width - 1; + // For positions that are have either a different cell or the end + // of the table to their right, and either the top of the table or + // a different cell above them, add a decoration + if ((col == map.width || map.map[index] != map.map[index + 1]) && + (row == 0 || map.map[index - 1] != map.map[index - 1 - map.width])) { + var cellPos = map.map[index]; + var pos = start + cellPos + table.nodeAt(cellPos).nodeSize - 1; + var dom = document.createElement("div"); + dom.className = "column-resize-handle"; + decorations.push(prosemirror_view__WEBPACK_IMPORTED_MODULE_3__["Decoration"].widget(pos, dom)); + } + } + return prosemirror_view__WEBPACK_IMPORTED_MODULE_3__["DecorationSet"].create(state.doc, decorations) +} + +// This file defines a plugin that handles the drawing of cell + +// :: () → Plugin +// +// Creates a [plugin](http://prosemirror.net/docs/ref/#state.Plugin) +// that, when added to an editor, enables cell-selection, handles +// cell-based copy/paste, and makes sure tables stay well-formed (each +// row has the same width, and cells don't overlap). +// +// You should probably put this plugin near the end of your array of +// plugins, since it handles mouse and arrow key events in tables +// rather broadly, and other plugins, like the gap cursor or the +// column-width dragging plugin, might want to get a turn first to +// perform more specific behavior. +function tableEditing(ref) { + if ( ref === void 0 ) ref = {}; + var allowTableNodeSelection = ref.allowTableNodeSelection; if ( allowTableNodeSelection === void 0 ) allowTableNodeSelection = false; + + return new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["Plugin"]({ + key: key, + + // This piece of state is used to remember when a mouse-drag + // cell-selection is happening, so that it can continue even as + // transactions (which might move its anchor cell) come in. + state: { + init: function init() { return null }, + apply: function apply(tr, cur) { + var set = tr.getMeta(key); + if (set != null) { return set == -1 ? null : set } + if (cur == null || !tr.docChanged) { return cur } + var ref = tr.mapping.mapResult(cur); + var deleted = ref.deleted; + var pos = ref.pos; + return deleted ? null : pos + } + }, + + props: { + decorations: drawCellSelection, + + handleDOMEvents: { + mousedown: handleMouseDown + }, + + createSelectionBetween: function createSelectionBetween(view) { + if (key.getState(view.state) != null) { return view.state.selection } + }, + + handleTripleClick: handleTripleClick, + + handleKeyDown: handleKeyDown, + + handlePaste: handlePaste + }, + + appendTransaction: function appendTransaction(_, oldState, state) { + return normalizeSelection(state, fixTables(state, oldState), allowTableNodeSelection) + } + }) +} + + +//# sourceMappingURL=index.es.js.map + + +/***/ }), + +/***/ "./node_modules/prosemirror-transform/dist/index.es.js": +/*!*************************************************************!*\ + !*** ./node_modules/prosemirror-transform/dist/index.es.js ***! + \*************************************************************/ +/*! exports provided: AddMarkStep, MapResult, Mapping, RemoveMarkStep, ReplaceAroundStep, ReplaceStep, Step, StepMap, StepResult, Transform, TransformError, canJoin, canSplit, dropPoint, findWrapping, insertPoint, joinPoint, liftTarget, replaceStep */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AddMarkStep", function() { return AddMarkStep; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MapResult", function() { return MapResult; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Mapping", function() { return Mapping; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "RemoveMarkStep", function() { return RemoveMarkStep; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ReplaceAroundStep", function() { return ReplaceAroundStep; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ReplaceStep", function() { return ReplaceStep; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Step", function() { return Step; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "StepMap", function() { return StepMap; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "StepResult", function() { return StepResult; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Transform", function() { return Transform; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "TransformError", function() { return TransformError; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "canJoin", function() { return canJoin; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "canSplit", function() { return canSplit; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "dropPoint", function() { return dropPoint; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "findWrapping", function() { return findWrapping; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "insertPoint", function() { return insertPoint; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "joinPoint", function() { return joinPoint; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "liftTarget", function() { return liftTarget; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "replaceStep", function() { return replaceStep; }); +/* harmony import */ var prosemirror_model__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! prosemirror-model */ "./node_modules/prosemirror-model/dist/index.es.js"); + + +// Mappable:: interface +// There are several things that positions can be mapped through. +// Such objects conform to this interface. +// +// map:: (pos: number, assoc: ?number) → number +// Map a position through this object. When given, `assoc` (should +// be -1 or 1, defaults to 1) determines with which side the +// position is associated, which determines in which direction to +// move when a chunk of content is inserted at the mapped position. +// +// mapResult:: (pos: number, assoc: ?number) → MapResult +// Map a position, and return an object containing additional +// information about the mapping. The result's `deleted` field tells +// you whether the position was deleted (completely enclosed in a +// replaced range) during the mapping. When content on only one side +// is deleted, the position itself is only considered deleted when +// `assoc` points in the direction of the deleted content. + +// Recovery values encode a range index and an offset. They are +// represented as numbers, because tons of them will be created when +// mapping, for example, a large number of decorations. The number's +// lower 16 bits provide the index, the remaining bits the offset. +// +// Note: We intentionally don't use bit shift operators to en- and +// decode these, since those clip to 32 bits, which we might in rare +// cases want to overflow. A 64-bit float can represent 48-bit +// integers precisely. + +var lower16 = 0xffff; +var factor16 = Math.pow(2, 16); + +function makeRecover(index, offset) { return index + offset * factor16 } +function recoverIndex(value) { return value & lower16 } +function recoverOffset(value) { return (value - (value & lower16)) / factor16 } + +// ::- An object representing a mapped position with extra +// information. +var MapResult = function MapResult(pos, deleted, recover) { + if ( deleted === void 0 ) deleted = false; + if ( recover === void 0 ) recover = null; + + // :: number The mapped version of the position. + this.pos = pos; + // :: bool Tells you whether the position was deleted, that is, + // whether the step removed its surroundings from the document. + this.deleted = deleted; + this.recover = recover; +}; + +// :: class extends Mappable +// A map describing the deletions and insertions made by a step, which +// can be used to find the correspondence between positions in the +// pre-step version of a document and the same position in the +// post-step version. +var StepMap = function StepMap(ranges, inverted) { + if ( inverted === void 0 ) inverted = false; + + this.ranges = ranges; + this.inverted = inverted; +}; + +StepMap.prototype.recover = function recover (value) { + var diff = 0, index = recoverIndex(value); + if (!this.inverted) { for (var i = 0; i < index; i++) + { diff += this.ranges[i * 3 + 2] - this.ranges[i * 3 + 1]; } } + return this.ranges[index * 3] + diff + recoverOffset(value) +}; + +// : (number, ?number) → MapResult +StepMap.prototype.mapResult = function mapResult (pos, assoc) { + if ( assoc === void 0 ) assoc = 1; + return this._map(pos, assoc, false) }; + +// : (number, ?number) → number +StepMap.prototype.map = function map (pos, assoc) { + if ( assoc === void 0 ) assoc = 1; + return this._map(pos, assoc, true) }; + +StepMap.prototype._map = function _map (pos, assoc, simple) { + var diff = 0, oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2; + for (var i = 0; i < this.ranges.length; i += 3) { + var start = this.ranges[i] - (this.inverted ? diff : 0); + if (start > pos) { break } + var oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex], end = start + oldSize; + if (pos <= end) { + var side = !oldSize ? assoc : pos == start ? -1 : pos == end ? 1 : assoc; + var result = start + diff + (side < 0 ? 0 : newSize); + if (simple) { return result } + var recover = makeRecover(i / 3, pos - start); + return new MapResult(result, assoc < 0 ? pos != start : pos != end, recover) + } + diff += newSize - oldSize; + } + return simple ? pos + diff : new MapResult(pos + diff) +}; + +StepMap.prototype.touches = function touches (pos, recover) { + var diff = 0, index = recoverIndex(recover); + var oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2; + for (var i = 0; i < this.ranges.length; i += 3) { + var start = this.ranges[i] - (this.inverted ? diff : 0); + if (start > pos) { break } + var oldSize = this.ranges[i + oldIndex], end = start + oldSize; + if (pos <= end && i == index * 3) { return true } + diff += this.ranges[i + newIndex] - oldSize; + } + return false +}; + +// :: ((oldStart: number, oldEnd: number, newStart: number, newEnd: number)) +// Calls the given function on each of the changed ranges included in +// this map. +StepMap.prototype.forEach = function forEach (f) { + var oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2; + for (var i = 0, diff = 0; i < this.ranges.length; i += 3) { + var start = this.ranges[i], oldStart = start - (this.inverted ? diff : 0), newStart = start + (this.inverted ? 0 : diff); + var oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex]; + f(oldStart, oldStart + oldSize, newStart, newStart + newSize); + diff += newSize - oldSize; + } +}; + +// :: () → StepMap +// Create an inverted version of this map. The result can be used to +// map positions in the post-step document to the pre-step document. +StepMap.prototype.invert = function invert () { + return new StepMap(this.ranges, !this.inverted) +}; + +StepMap.prototype.toString = function toString () { + return (this.inverted ? "-" : "") + JSON.stringify(this.ranges) +}; + +// :: (n: number) → StepMap +// Create a map that moves all positions by offset `n` (which may be +// negative). This can be useful when applying steps meant for a +// sub-document to a larger document, or vice-versa. +StepMap.offset = function offset (n) { + return n == 0 ? StepMap.empty : new StepMap(n < 0 ? [0, -n, 0] : [0, 0, n]) +}; + +StepMap.empty = new StepMap([]); + +// :: class extends Mappable +// A mapping represents a pipeline of zero or more [step +// maps](#transform.StepMap). It has special provisions for losslessly +// handling mapping positions through a series of steps in which some +// steps are inverted versions of earlier steps. (This comes up when +// ‘[rebasing](/docs/guide/#transform.rebasing)’ steps for +// collaboration or history management.) +var Mapping = function Mapping(maps, mirror, from, to) { + // :: [StepMap] + // The step maps in this mapping. + this.maps = maps || []; + // :: number + // The starting position in the `maps` array, used when `map` or + // `mapResult` is called. + this.from = from || 0; + // :: number + // The end position in the `maps` array. + this.to = to == null ? this.maps.length : to; + this.mirror = mirror; +}; + +// :: (?number, ?number) → Mapping +// Create a mapping that maps only through a part of this one. +Mapping.prototype.slice = function slice (from, to) { + if ( from === void 0 ) from = 0; + if ( to === void 0 ) to = this.maps.length; + + return new Mapping(this.maps, this.mirror, from, to) +}; + +Mapping.prototype.copy = function copy () { + return new Mapping(this.maps.slice(), this.mirror && this.mirror.slice(), this.from, this.to) +}; + +// :: (StepMap, ?number) +// Add a step map to the end of this mapping. If `mirrors` is +// given, it should be the index of the step map that is the mirror +// image of this one. +Mapping.prototype.appendMap = function appendMap (map, mirrors) { + this.to = this.maps.push(map); + if (mirrors != null) { this.setMirror(this.maps.length - 1, mirrors); } +}; + +// :: (Mapping) +// Add all the step maps in a given mapping to this one (preserving +// mirroring information). +Mapping.prototype.appendMapping = function appendMapping (mapping) { + for (var i = 0, startSize = this.maps.length; i < mapping.maps.length; i++) { + var mirr = mapping.getMirror(i); + this.appendMap(mapping.maps[i], mirr != null && mirr < i ? startSize + mirr : null); + } +}; + +// :: (number) → ?number +// Finds the offset of the step map that mirrors the map at the +// given offset, in this mapping (as per the second argument to +// `appendMap`). +Mapping.prototype.getMirror = function getMirror (n) { + if (this.mirror) { for (var i = 0; i < this.mirror.length; i++) + { if (this.mirror[i] == n) { return this.mirror[i + (i % 2 ? -1 : 1)] } } } +}; + +Mapping.prototype.setMirror = function setMirror (n, m) { + if (!this.mirror) { this.mirror = []; } + this.mirror.push(n, m); +}; + +// :: (Mapping) +// Append the inverse of the given mapping to this one. +Mapping.prototype.appendMappingInverted = function appendMappingInverted (mapping) { + for (var i = mapping.maps.length - 1, totalSize = this.maps.length + mapping.maps.length; i >= 0; i--) { + var mirr = mapping.getMirror(i); + this.appendMap(mapping.maps[i].invert(), mirr != null && mirr > i ? totalSize - mirr - 1 : null); + } +}; + +// :: () → Mapping +// Create an inverted version of this mapping. +Mapping.prototype.invert = function invert () { + var inverse = new Mapping; + inverse.appendMappingInverted(this); + return inverse +}; + +// : (number, ?number) → number +// Map a position through this mapping. +Mapping.prototype.map = function map (pos, assoc) { + if ( assoc === void 0 ) assoc = 1; + + if (this.mirror) { return this._map(pos, assoc, true) } + for (var i = this.from; i < this.to; i++) + { pos = this.maps[i].map(pos, assoc); } + return pos +}; + +// : (number, ?number) → MapResult +// Map a position through this mapping, returning a mapping +// result. +Mapping.prototype.mapResult = function mapResult (pos, assoc) { + if ( assoc === void 0 ) assoc = 1; + return this._map(pos, assoc, false) }; + +Mapping.prototype._map = function _map (pos, assoc, simple) { + var deleted = false, recoverables = null; + + for (var i = this.from; i < this.to; i++) { + var map = this.maps[i], rec = recoverables && recoverables[i]; + if (rec != null && map.touches(pos, rec)) { + pos = map.recover(rec); + continue + } + + var result = map.mapResult(pos, assoc); + if (result.recover != null) { + var corr = this.getMirror(i); + if (corr != null && corr > i && corr < this.to) { + if (result.deleted) { + i = corr; + pos = this.maps[corr].recover(result.recover); + continue + } else { +(recoverables || (recoverables = Object.create(null)))[corr] = result.recover; + } + } + } + + if (result.deleted) { deleted = true; } + pos = result.pos; + } + + return simple ? pos : new MapResult(pos, deleted) +}; + +function TransformError(message) { + var err = Error.call(this, message); + err.__proto__ = TransformError.prototype; + return err +} + +TransformError.prototype = Object.create(Error.prototype); +TransformError.prototype.constructor = TransformError; +TransformError.prototype.name = "TransformError"; + +// ::- Abstraction to build up and track an array of +// [steps](#transform.Step) representing a document transformation. +// +// Most transforming methods return the `Transform` object itself, so +// that they can be chained. +var Transform = function Transform(doc) { + // :: Node + // The current document (the result of applying the steps in the + // transform). + this.doc = doc; + // :: [Step] + // The steps in this transform. + this.steps = []; + // :: [Node] + // The documents before each of the steps. + this.docs = []; + // :: Mapping + // A mapping with the maps for each of the steps in this transform. + this.mapping = new Mapping; +}; + +var prototypeAccessors = { before: { configurable: true },docChanged: { configurable: true } }; + +// :: Node The starting document. +prototypeAccessors.before.get = function () { return this.docs.length ? this.docs[0] : this.doc }; + +// :: (step: Step) → this +// Apply a new step in this transform, saving the result. Throws an +// error when the step fails. +Transform.prototype.step = function step (object) { + var result = this.maybeStep(object); + if (result.failed) { throw new TransformError(result.failed) } + return this +}; + +// :: (Step) → StepResult +// Try to apply a step in this transformation, ignoring it if it +// fails. Returns the step result. +Transform.prototype.maybeStep = function maybeStep (step) { + var result = step.apply(this.doc); + if (!result.failed) { this.addStep(step, result.doc); } + return result +}; + +// :: bool +// True when the document has been changed (when there are any +// steps). +prototypeAccessors.docChanged.get = function () { + return this.steps.length > 0 +}; + +Transform.prototype.addStep = function addStep (step, doc) { + this.docs.push(this.doc); + this.steps.push(step); + this.mapping.appendMap(step.getMap()); + this.doc = doc; +}; + +Object.defineProperties( Transform.prototype, prototypeAccessors ); + +function mustOverride() { throw new Error("Override me") } + +var stepsByID = Object.create(null); + +// ::- A step object represents an atomic change. It generally applies +// only to the document it was created for, since the positions +// stored in it will only make sense for that document. +// +// New steps are defined by creating classes that extend `Step`, +// overriding the `apply`, `invert`, `map`, `getMap` and `fromJSON` +// methods, and registering your class with a unique +// JSON-serialization identifier using +// [`Step.jsonID`](#transform.Step^jsonID). +var Step = function Step () {}; + +Step.prototype.apply = function apply (_doc) { return mustOverride() }; + +// :: () → StepMap +// Get the step map that represents the changes made by this step, +// and which can be used to transform between positions in the old +// and the new document. +Step.prototype.getMap = function getMap () { return StepMap.empty }; + +// :: (doc: Node) → Step +// Create an inverted version of this step. Needs the document as it +// was before the step as argument. +Step.prototype.invert = function invert (_doc) { return mustOverride() }; + +// :: (mapping: Mappable) → ?Step +// Map this step through a mappable thing, returning either a +// version of that step with its positions adjusted, or `null` if +// the step was entirely deleted by the mapping. +Step.prototype.map = function map (_mapping) { return mustOverride() }; + +// :: (other: Step) → ?Step +// Try to merge this step with another one, to be applied directly +// after it. Returns the merged step when possible, null if the +// steps can't be merged. +Step.prototype.merge = function merge (_other) { return null }; + +// :: () → Object +// Create a JSON-serializeable representation of this step. When +// defining this for a custom subclass, make sure the result object +// includes the step type's [JSON id](#transform.Step^jsonID) under +// the `stepType` property. +Step.prototype.toJSON = function toJSON () { return mustOverride() }; + +// :: (Schema, Object) → Step +// Deserialize a step from its JSON representation. Will call +// through to the step class' own implementation of this method. +Step.fromJSON = function fromJSON (schema, json) { + if (!json || !json.stepType) { throw new RangeError("Invalid input for Step.fromJSON") } + var type = stepsByID[json.stepType]; + if (!type) { throw new RangeError(("No step type " + (json.stepType) + " defined")) } + return type.fromJSON(schema, json) +}; + +// :: (string, constructor) +// To be able to serialize steps to JSON, each step needs a string +// ID to attach to its JSON representation. Use this method to +// register an ID for your step classes. Try to pick something +// that's unlikely to clash with steps from other modules. +Step.jsonID = function jsonID (id, stepClass) { + if (id in stepsByID) { throw new RangeError("Duplicate use of step JSON ID " + id) } + stepsByID[id] = stepClass; + stepClass.prototype.jsonID = id; + return stepClass +}; + +// ::- The result of [applying](#transform.Step.apply) a step. Contains either a +// new document or a failure value. +var StepResult = function StepResult(doc, failed) { + // :: ?Node The transformed document. + this.doc = doc; + // :: ?string Text providing information about a failed step. + this.failed = failed; +}; + +// :: (Node) → StepResult +// Create a successful step result. +StepResult.ok = function ok (doc) { return new StepResult(doc, null) }; + +// :: (string) → StepResult +// Create a failed step result. +StepResult.fail = function fail (message) { return new StepResult(null, message) }; + +// :: (Node, number, number, Slice) → StepResult +// Call [`Node.replace`](#model.Node.replace) with the given +// arguments. Create a successful result if it succeeds, and a +// failed one if it throws a `ReplaceError`. +StepResult.fromReplace = function fromReplace (doc, from, to, slice) { + try { + return StepResult.ok(doc.replace(from, to, slice)) + } catch (e) { + if (e instanceof prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["ReplaceError"]) { return StepResult.fail(e.message) } + throw e + } +}; + +// ::- Replace a part of the document with a slice of new content. +var ReplaceStep = /*@__PURE__*/(function (Step) { + function ReplaceStep(from, to, slice, structure) { + Step.call(this); + this.from = from; + this.to = to; + this.slice = slice; + this.structure = !!structure; + } + + if ( Step ) ReplaceStep.__proto__ = Step; + ReplaceStep.prototype = Object.create( Step && Step.prototype ); + ReplaceStep.prototype.constructor = ReplaceStep; + + ReplaceStep.prototype.apply = function apply (doc) { + if (this.structure && contentBetween(doc, this.from, this.to)) + { return StepResult.fail("Structure replace would overwrite content") } + return StepResult.fromReplace(doc, this.from, this.to, this.slice) + }; + + ReplaceStep.prototype.getMap = function getMap () { + return new StepMap([this.from, this.to - this.from, this.slice.size]) + }; + + ReplaceStep.prototype.invert = function invert (doc) { + return new ReplaceStep(this.from, this.from + this.slice.size, doc.slice(this.from, this.to)) + }; + + ReplaceStep.prototype.map = function map (mapping) { + var from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1); + if (from.deleted && to.deleted) { return null } + return new ReplaceStep(from.pos, Math.max(from.pos, to.pos), this.slice) + }; + + ReplaceStep.prototype.merge = function merge (other) { + if (!(other instanceof ReplaceStep) || other.structure != this.structure) { return null } + + if (this.from + this.slice.size == other.from && !this.slice.openEnd && !other.slice.openStart) { + var slice = this.slice.size + other.slice.size == 0 ? prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"].empty + : new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](this.slice.content.append(other.slice.content), this.slice.openStart, other.slice.openEnd); + return new ReplaceStep(this.from, this.to + (other.to - other.from), slice, this.structure) + } else if (other.to == this.from && !this.slice.openStart && !other.slice.openEnd) { + var slice$1 = this.slice.size + other.slice.size == 0 ? prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"].empty + : new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](other.slice.content.append(this.slice.content), other.slice.openStart, this.slice.openEnd); + return new ReplaceStep(other.from, this.to, slice$1, this.structure) + } else { + return null + } + }; + + ReplaceStep.prototype.toJSON = function toJSON () { + var json = {stepType: "replace", from: this.from, to: this.to}; + if (this.slice.size) { json.slice = this.slice.toJSON(); } + if (this.structure) { json.structure = true; } + return json + }; + + ReplaceStep.fromJSON = function fromJSON (schema, json) { + if (typeof json.from != "number" || typeof json.to != "number") + { throw new RangeError("Invalid input for ReplaceStep.fromJSON") } + return new ReplaceStep(json.from, json.to, prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"].fromJSON(schema, json.slice), !!json.structure) + }; + + return ReplaceStep; +}(Step)); + +Step.jsonID("replace", ReplaceStep); + +// ::- Replace a part of the document with a slice of content, but +// preserve a range of the replaced content by moving it into the +// slice. +var ReplaceAroundStep = /*@__PURE__*/(function (Step) { + function ReplaceAroundStep(from, to, gapFrom, gapTo, slice, insert, structure) { + Step.call(this); + this.from = from; + this.to = to; + this.gapFrom = gapFrom; + this.gapTo = gapTo; + this.slice = slice; + this.insert = insert; + this.structure = !!structure; + } + + if ( Step ) ReplaceAroundStep.__proto__ = Step; + ReplaceAroundStep.prototype = Object.create( Step && Step.prototype ); + ReplaceAroundStep.prototype.constructor = ReplaceAroundStep; + + ReplaceAroundStep.prototype.apply = function apply (doc) { + if (this.structure && (contentBetween(doc, this.from, this.gapFrom) || + contentBetween(doc, this.gapTo, this.to))) + { return StepResult.fail("Structure gap-replace would overwrite content") } + + var gap = doc.slice(this.gapFrom, this.gapTo); + if (gap.openStart || gap.openEnd) + { return StepResult.fail("Gap is not a flat range") } + var inserted = this.slice.insertAt(this.insert, gap.content); + if (!inserted) { return StepResult.fail("Content does not fit in gap") } + return StepResult.fromReplace(doc, this.from, this.to, inserted) + }; + + ReplaceAroundStep.prototype.getMap = function getMap () { + return new StepMap([this.from, this.gapFrom - this.from, this.insert, + this.gapTo, this.to - this.gapTo, this.slice.size - this.insert]) + }; + + ReplaceAroundStep.prototype.invert = function invert (doc) { + var gap = this.gapTo - this.gapFrom; + return new ReplaceAroundStep(this.from, this.from + this.slice.size + gap, + this.from + this.insert, this.from + this.insert + gap, + doc.slice(this.from, this.to).removeBetween(this.gapFrom - this.from, this.gapTo - this.from), + this.gapFrom - this.from, this.structure) + }; + + ReplaceAroundStep.prototype.map = function map (mapping) { + var from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1); + var gapFrom = mapping.map(this.gapFrom, -1), gapTo = mapping.map(this.gapTo, 1); + if ((from.deleted && to.deleted) || gapFrom < from.pos || gapTo > to.pos) { return null } + return new ReplaceAroundStep(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure) + }; + + ReplaceAroundStep.prototype.toJSON = function toJSON () { + var json = {stepType: "replaceAround", from: this.from, to: this.to, + gapFrom: this.gapFrom, gapTo: this.gapTo, insert: this.insert}; + if (this.slice.size) { json.slice = this.slice.toJSON(); } + if (this.structure) { json.structure = true; } + return json + }; + + ReplaceAroundStep.fromJSON = function fromJSON (schema, json) { + if (typeof json.from != "number" || typeof json.to != "number" || + typeof json.gapFrom != "number" || typeof json.gapTo != "number" || typeof json.insert != "number") + { throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON") } + return new ReplaceAroundStep(json.from, json.to, json.gapFrom, json.gapTo, + prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"].fromJSON(schema, json.slice), json.insert, !!json.structure) + }; + + return ReplaceAroundStep; +}(Step)); + +Step.jsonID("replaceAround", ReplaceAroundStep); + +function contentBetween(doc, from, to) { + var $from = doc.resolve(from), dist = to - from, depth = $from.depth; + while (dist > 0 && depth > 0 && $from.indexAfter(depth) == $from.node(depth).childCount) { + depth--; + dist--; + } + if (dist > 0) { + var next = $from.node(depth).maybeChild($from.indexAfter(depth)); + while (dist > 0) { + if (!next || next.isLeaf) { return true } + next = next.firstChild; + dist--; + } + } + return false +} + +function canCut(node, start, end) { + return (start == 0 || node.canReplace(start, node.childCount)) && + (end == node.childCount || node.canReplace(0, end)) +} + +// :: (NodeRange) → ?number +// Try to find a target depth to which the content in the given range +// can be lifted. Will not go across +// [isolating](#model.NodeSpec.isolating) parent nodes. +function liftTarget(range) { + var parent = range.parent; + var content = parent.content.cutByIndex(range.startIndex, range.endIndex); + for (var depth = range.depth;; --depth) { + var node = range.$from.node(depth); + var index = range.$from.index(depth), endIndex = range.$to.indexAfter(depth); + if (depth < range.depth && node.canReplace(index, endIndex, content)) + { return depth } + if (depth == 0 || node.type.spec.isolating || !canCut(node, index, endIndex)) { break } + } +} + +// :: (NodeRange, number) → this +// Split the content in the given range off from its parent, if there +// is sibling content before or after it, and move it up the tree to +// the depth specified by `target`. You'll probably want to use +// [`liftTarget`](#transform.liftTarget) to compute `target`, to make +// sure the lift is valid. +Transform.prototype.lift = function(range, target) { + var $from = range.$from; + var $to = range.$to; + var depth = range.depth; + + var gapStart = $from.before(depth + 1), gapEnd = $to.after(depth + 1); + var start = gapStart, end = gapEnd; + + var before = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty, openStart = 0; + for (var d = depth, splitting = false; d > target; d--) + { if (splitting || $from.index(d) > 0) { + splitting = true; + before = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].from($from.node(d).copy(before)); + openStart++; + } else { + start--; + } } + var after = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty, openEnd = 0; + for (var d$1 = depth, splitting$1 = false; d$1 > target; d$1--) + { if (splitting$1 || $to.after(d$1 + 1) < $to.end(d$1)) { + splitting$1 = true; + after = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].from($to.node(d$1).copy(after)); + openEnd++; + } else { + end++; + } } + + return this.step(new ReplaceAroundStep(start, end, gapStart, gapEnd, + new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](before.append(after), openStart, openEnd), + before.size - openStart, true)) +}; + +// :: (NodeRange, NodeType, ?Object, ?NodeRange) → ?[{type: NodeType, attrs: ?Object}] +// Try to find a valid way to wrap the content in the given range in a +// node of the given type. May introduce extra nodes around and inside +// the wrapper node, if necessary. Returns null if no valid wrapping +// could be found. When `innerRange` is given, that range's content is +// used as the content to fit into the wrapping, instead of the +// content of `range`. +function findWrapping(range, nodeType, attrs, innerRange) { + if ( innerRange === void 0 ) innerRange = range; + + var around = findWrappingOutside(range, nodeType); + var inner = around && findWrappingInside(innerRange, nodeType); + if (!inner) { return null } + return around.map(withAttrs).concat({type: nodeType, attrs: attrs}).concat(inner.map(withAttrs)) +} + +function withAttrs(type) { return {type: type, attrs: null} } + +function findWrappingOutside(range, type) { + var parent = range.parent; + var startIndex = range.startIndex; + var endIndex = range.endIndex; + var around = parent.contentMatchAt(startIndex).findWrapping(type); + if (!around) { return null } + var outer = around.length ? around[0] : type; + return parent.canReplaceWith(startIndex, endIndex, outer) ? around : null +} + +function findWrappingInside(range, type) { + var parent = range.parent; + var startIndex = range.startIndex; + var endIndex = range.endIndex; + var inner = parent.child(startIndex); + var inside = type.contentMatch.findWrapping(inner.type); + if (!inside) { return null } + var lastType = inside.length ? inside[inside.length - 1] : type; + var innerMatch = lastType.contentMatch; + for (var i = startIndex; innerMatch && i < endIndex; i++) + { innerMatch = innerMatch.matchType(parent.child(i).type); } + if (!innerMatch || !innerMatch.validEnd) { return null } + return inside +} + +// :: (NodeRange, [{type: NodeType, attrs: ?Object}]) → this +// Wrap the given [range](#model.NodeRange) in the given set of wrappers. +// The wrappers are assumed to be valid in this position, and should +// probably be computed with [`findWrapping`](#transform.findWrapping). +Transform.prototype.wrap = function(range, wrappers) { + var content = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty; + for (var i = wrappers.length - 1; i >= 0; i--) + { content = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].from(wrappers[i].type.create(wrappers[i].attrs, content)); } + + var start = range.start, end = range.end; + return this.step(new ReplaceAroundStep(start, end, start, end, new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](content, 0, 0), wrappers.length, true)) +}; + +// :: (number, ?number, NodeType, ?Object) → this +// Set the type of all textblocks (partly) between `from` and `to` to +// the given node type with the given attributes. +Transform.prototype.setBlockType = function(from, to, type, attrs) { + var this$1 = this; + if ( to === void 0 ) to = from; + + if (!type.isTextblock) { throw new RangeError("Type given to setBlockType should be a textblock") } + var mapFrom = this.steps.length; + this.doc.nodesBetween(from, to, function (node, pos) { + if (node.isTextblock && !node.hasMarkup(type, attrs) && canChangeType(this$1.doc, this$1.mapping.slice(mapFrom).map(pos), type)) { + // Ensure all markup that isn't allowed in the new node type is cleared + this$1.clearIncompatible(this$1.mapping.slice(mapFrom).map(pos, 1), type); + var mapping = this$1.mapping.slice(mapFrom); + var startM = mapping.map(pos, 1), endM = mapping.map(pos + node.nodeSize, 1); + this$1.step(new ReplaceAroundStep(startM, endM, startM + 1, endM - 1, + new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].from(type.create(attrs, null, node.marks)), 0, 0), 1, true)); + return false + } + }); + return this +}; + +function canChangeType(doc, pos, type) { + var $pos = doc.resolve(pos), index = $pos.index(); + return $pos.parent.canReplaceWith(index, index + 1, type) +} + +// :: (number, ?NodeType, ?Object, ?[Mark]) → this +// Change the type, attributes, and/or marks of the node at `pos`. +// When `type` isn't given, the existing node type is preserved, +Transform.prototype.setNodeMarkup = function(pos, type, attrs, marks) { + var node = this.doc.nodeAt(pos); + if (!node) { throw new RangeError("No node at given position") } + if (!type) { type = node.type; } + var newNode = type.create(attrs, null, marks || node.marks); + if (node.isLeaf) + { return this.replaceWith(pos, pos + node.nodeSize, newNode) } + + if (!type.validContent(node.content)) + { throw new RangeError("Invalid content for node type " + type.name) } + + return this.step(new ReplaceAroundStep(pos, pos + node.nodeSize, pos + 1, pos + node.nodeSize - 1, + new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].from(newNode), 0, 0), 1, true)) +}; + +// :: (Node, number, number, ?[?{type: NodeType, attrs: ?Object}]) → bool +// Check whether splitting at the given position is allowed. +function canSplit(doc, pos, depth, typesAfter) { + if ( depth === void 0 ) depth = 1; + + var $pos = doc.resolve(pos), base = $pos.depth - depth; + var innerType = (typesAfter && typesAfter[typesAfter.length - 1]) || $pos.parent; + if (base < 0 || $pos.parent.type.spec.isolating || + !$pos.parent.canReplace($pos.index(), $pos.parent.childCount) || + !innerType.type.validContent($pos.parent.content.cutByIndex($pos.index(), $pos.parent.childCount))) + { return false } + for (var d = $pos.depth - 1, i = depth - 2; d > base; d--, i--) { + var node = $pos.node(d), index$1 = $pos.index(d); + if (node.type.spec.isolating) { return false } + var rest = node.content.cutByIndex(index$1, node.childCount); + var after = (typesAfter && typesAfter[i]) || node; + if (after != node) { rest = rest.replaceChild(0, after.type.create(after.attrs)); } + if (!node.canReplace(index$1 + 1, node.childCount) || !after.type.validContent(rest)) + { return false } + } + var index = $pos.indexAfter(base); + var baseType = typesAfter && typesAfter[0]; + return $pos.node(base).canReplaceWith(index, index, baseType ? baseType.type : $pos.node(base + 1).type) +} + +// :: (number, ?number, ?[?{type: NodeType, attrs: ?Object}]) → this +// Split the node at the given position, and optionally, if `depth` is +// greater than one, any number of nodes above that. By default, the +// parts split off will inherit the node type of the original node. +// This can be changed by passing an array of types and attributes to +// use after the split. +Transform.prototype.split = function(pos, depth, typesAfter) { + if ( depth === void 0 ) depth = 1; + + var $pos = this.doc.resolve(pos), before = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty, after = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty; + for (var d = $pos.depth, e = $pos.depth - depth, i = depth - 1; d > e; d--, i--) { + before = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].from($pos.node(d).copy(before)); + var typeAfter = typesAfter && typesAfter[i]; + after = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].from(typeAfter ? typeAfter.type.create(typeAfter.attrs, after) : $pos.node(d).copy(after)); + } + return this.step(new ReplaceStep(pos, pos, new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](before.append(after), depth, depth), true)) +}; + +// :: (Node, number) → bool +// Test whether the blocks before and after a given position can be +// joined. +function canJoin(doc, pos) { + var $pos = doc.resolve(pos), index = $pos.index(); + return joinable($pos.nodeBefore, $pos.nodeAfter) && + $pos.parent.canReplace(index, index + 1) +} + +function joinable(a, b) { + return a && b && !a.isLeaf && a.canAppend(b) +} + +// :: (Node, number, ?number) → ?number +// Find an ancestor of the given position that can be joined to the +// block before (or after if `dir` is positive). Returns the joinable +// point, if any. +function joinPoint(doc, pos, dir) { + if ( dir === void 0 ) dir = -1; + + var $pos = doc.resolve(pos); + for (var d = $pos.depth;; d--) { + var before = (void 0), after = (void 0); + if (d == $pos.depth) { + before = $pos.nodeBefore; + after = $pos.nodeAfter; + } else if (dir > 0) { + before = $pos.node(d + 1); + after = $pos.node(d).maybeChild($pos.index(d) + 1); + } else { + before = $pos.node(d).maybeChild($pos.index(d) - 1); + after = $pos.node(d + 1); + } + if (before && !before.isTextblock && joinable(before, after)) { return pos } + if (d == 0) { break } + pos = dir < 0 ? $pos.before(d) : $pos.after(d); + } +} + +// :: (number, ?number) → this +// Join the blocks around the given position. If depth is 2, their +// last and first siblings are also joined, and so on. +Transform.prototype.join = function(pos, depth) { + if ( depth === void 0 ) depth = 1; + + var step = new ReplaceStep(pos - depth, pos + depth, prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"].empty, true); + return this.step(step) +}; + +// :: (Node, number, NodeType) → ?number +// Try to find a point where a node of the given type can be inserted +// near `pos`, by searching up the node hierarchy when `pos` itself +// isn't a valid place but is at the start or end of a node. Return +// null if no position was found. +function insertPoint(doc, pos, nodeType) { + var $pos = doc.resolve(pos); + if ($pos.parent.canReplaceWith($pos.index(), $pos.index(), nodeType)) { return pos } + + if ($pos.parentOffset == 0) + { for (var d = $pos.depth - 1; d >= 0; d--) { + var index = $pos.index(d); + if ($pos.node(d).canReplaceWith(index, index, nodeType)) { return $pos.before(d + 1) } + if (index > 0) { return null } + } } + if ($pos.parentOffset == $pos.parent.content.size) + { for (var d$1 = $pos.depth - 1; d$1 >= 0; d$1--) { + var index$1 = $pos.indexAfter(d$1); + if ($pos.node(d$1).canReplaceWith(index$1, index$1, nodeType)) { return $pos.after(d$1 + 1) } + if (index$1 < $pos.node(d$1).childCount) { return null } + } } +} + +// :: (Node, number, Slice) → ?number +// Finds a position at or around the given position where the given +// slice can be inserted. Will look at parent nodes' nearest boundary +// and try there, even if the original position wasn't directly at the +// start or end of that node. Returns null when no position was found. +function dropPoint(doc, pos, slice) { + var $pos = doc.resolve(pos); + if (!slice.content.size) { return pos } + var content = slice.content; + for (var i = 0; i < slice.openStart; i++) { content = content.firstChild.content; } + for (var pass = 1; pass <= (slice.openStart == 0 && slice.size ? 2 : 1); pass++) { + for (var d = $pos.depth; d >= 0; d--) { + var bias = d == $pos.depth ? 0 : $pos.pos <= ($pos.start(d + 1) + $pos.end(d + 1)) / 2 ? -1 : 1; + var insertPos = $pos.index(d) + (bias > 0 ? 1 : 0); + if (pass == 1 + ? $pos.node(d).canReplace(insertPos, insertPos, content) + : $pos.node(d).contentMatchAt(insertPos).findWrapping(content.firstChild.type)) + { return bias == 0 ? $pos.pos : bias < 0 ? $pos.before(d + 1) : $pos.after(d + 1) } + } + } + return null +} + +function mapFragment(fragment, f, parent) { + var mapped = []; + for (var i = 0; i < fragment.childCount; i++) { + var child = fragment.child(i); + if (child.content.size) { child = child.copy(mapFragment(child.content, f, child)); } + if (child.isInline) { child = f(child, parent, i); } + mapped.push(child); + } + return prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].fromArray(mapped) +} + +// ::- Add a mark to all inline content between two positions. +var AddMarkStep = /*@__PURE__*/(function (Step) { + function AddMarkStep(from, to, mark) { + Step.call(this); + this.from = from; + this.to = to; + this.mark = mark; + } + + if ( Step ) AddMarkStep.__proto__ = Step; + AddMarkStep.prototype = Object.create( Step && Step.prototype ); + AddMarkStep.prototype.constructor = AddMarkStep; + + AddMarkStep.prototype.apply = function apply (doc) { + var this$1 = this; + + var oldSlice = doc.slice(this.from, this.to), $from = doc.resolve(this.from); + var parent = $from.node($from.sharedDepth(this.to)); + var slice = new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](mapFragment(oldSlice.content, function (node, parent) { + if (!parent.type.allowsMarkType(this$1.mark.type)) { return node } + return node.mark(this$1.mark.addToSet(node.marks)) + }, parent), oldSlice.openStart, oldSlice.openEnd); + return StepResult.fromReplace(doc, this.from, this.to, slice) + }; + + AddMarkStep.prototype.invert = function invert () { + return new RemoveMarkStep(this.from, this.to, this.mark) + }; + + AddMarkStep.prototype.map = function map (mapping) { + var from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1); + if (from.deleted && to.deleted || from.pos >= to.pos) { return null } + return new AddMarkStep(from.pos, to.pos, this.mark) + }; + + AddMarkStep.prototype.merge = function merge (other) { + if (other instanceof AddMarkStep && + other.mark.eq(this.mark) && + this.from <= other.to && this.to >= other.from) + { return new AddMarkStep(Math.min(this.from, other.from), + Math.max(this.to, other.to), this.mark) } + }; + + AddMarkStep.prototype.toJSON = function toJSON () { + return {stepType: "addMark", mark: this.mark.toJSON(), + from: this.from, to: this.to} + }; + + AddMarkStep.fromJSON = function fromJSON (schema, json) { + if (typeof json.from != "number" || typeof json.to != "number") + { throw new RangeError("Invalid input for AddMarkStep.fromJSON") } + return new AddMarkStep(json.from, json.to, schema.markFromJSON(json.mark)) + }; + + return AddMarkStep; +}(Step)); + +Step.jsonID("addMark", AddMarkStep); + +// ::- Remove a mark from all inline content between two positions. +var RemoveMarkStep = /*@__PURE__*/(function (Step) { + function RemoveMarkStep(from, to, mark) { + Step.call(this); + this.from = from; + this.to = to; + this.mark = mark; + } + + if ( Step ) RemoveMarkStep.__proto__ = Step; + RemoveMarkStep.prototype = Object.create( Step && Step.prototype ); + RemoveMarkStep.prototype.constructor = RemoveMarkStep; + + RemoveMarkStep.prototype.apply = function apply (doc) { + var this$1 = this; + + var oldSlice = doc.slice(this.from, this.to); + var slice = new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](mapFragment(oldSlice.content, function (node) { + return node.mark(this$1.mark.removeFromSet(node.marks)) + }), oldSlice.openStart, oldSlice.openEnd); + return StepResult.fromReplace(doc, this.from, this.to, slice) + }; + + RemoveMarkStep.prototype.invert = function invert () { + return new AddMarkStep(this.from, this.to, this.mark) + }; + + RemoveMarkStep.prototype.map = function map (mapping) { + var from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1); + if (from.deleted && to.deleted || from.pos >= to.pos) { return null } + return new RemoveMarkStep(from.pos, to.pos, this.mark) + }; + + RemoveMarkStep.prototype.merge = function merge (other) { + if (other instanceof RemoveMarkStep && + other.mark.eq(this.mark) && + this.from <= other.to && this.to >= other.from) + { return new RemoveMarkStep(Math.min(this.from, other.from), + Math.max(this.to, other.to), this.mark) } + }; + + RemoveMarkStep.prototype.toJSON = function toJSON () { + return {stepType: "removeMark", mark: this.mark.toJSON(), + from: this.from, to: this.to} + }; + + RemoveMarkStep.fromJSON = function fromJSON (schema, json) { + if (typeof json.from != "number" || typeof json.to != "number") + { throw new RangeError("Invalid input for RemoveMarkStep.fromJSON") } + return new RemoveMarkStep(json.from, json.to, schema.markFromJSON(json.mark)) + }; + + return RemoveMarkStep; +}(Step)); + +Step.jsonID("removeMark", RemoveMarkStep); + +// :: (number, number, Mark) → this +// Add the given mark to the inline content between `from` and `to`. +Transform.prototype.addMark = function(from, to, mark) { + var this$1 = this; + + var removed = [], added = [], removing = null, adding = null; + this.doc.nodesBetween(from, to, function (node, pos, parent) { + if (!node.isInline) { return } + var marks = node.marks; + if (!mark.isInSet(marks) && parent.type.allowsMarkType(mark.type)) { + var start = Math.max(pos, from), end = Math.min(pos + node.nodeSize, to); + var newSet = mark.addToSet(marks); + + for (var i = 0; i < marks.length; i++) { + if (!marks[i].isInSet(newSet)) { + if (removing && removing.to == start && removing.mark.eq(marks[i])) + { removing.to = end; } + else + { removed.push(removing = new RemoveMarkStep(start, end, marks[i])); } + } + } + + if (adding && adding.to == start) + { adding.to = end; } + else + { added.push(adding = new AddMarkStep(start, end, mark)); } + } + }); + + removed.forEach(function (s) { return this$1.step(s); }); + added.forEach(function (s) { return this$1.step(s); }); + return this +}; + +// :: (number, number, ?union) → this +// Remove marks from inline nodes between `from` and `to`. When `mark` +// is a single mark, remove precisely that mark. When it is a mark type, +// remove all marks of that type. When it is null, remove all marks of +// any type. +Transform.prototype.removeMark = function(from, to, mark) { + var this$1 = this; + if ( mark === void 0 ) mark = null; + + var matched = [], step = 0; + this.doc.nodesBetween(from, to, function (node, pos) { + if (!node.isInline) { return } + step++; + var toRemove = null; + if (mark instanceof prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["MarkType"]) { + var found = mark.isInSet(node.marks); + if (found) { toRemove = [found]; } + } else if (mark) { + if (mark.isInSet(node.marks)) { toRemove = [mark]; } + } else { + toRemove = node.marks; + } + if (toRemove && toRemove.length) { + var end = Math.min(pos + node.nodeSize, to); + for (var i = 0; i < toRemove.length; i++) { + var style = toRemove[i], found$1 = (void 0); + for (var j = 0; j < matched.length; j++) { + var m = matched[j]; + if (m.step == step - 1 && style.eq(matched[j].style)) { found$1 = m; } + } + if (found$1) { + found$1.to = end; + found$1.step = step; + } else { + matched.push({style: style, from: Math.max(pos, from), to: end, step: step}); + } + } + } + }); + matched.forEach(function (m) { return this$1.step(new RemoveMarkStep(m.from, m.to, m.style)); }); + return this +}; + +// :: (number, NodeType, ?ContentMatch) → this +// Removes all marks and nodes from the content of the node at `pos` +// that don't match the given new parent node type. Accepts an +// optional starting [content match](#model.ContentMatch) as third +// argument. +Transform.prototype.clearIncompatible = function(pos, parentType, match) { + if ( match === void 0 ) match = parentType.contentMatch; + + var node = this.doc.nodeAt(pos); + var delSteps = [], cur = pos + 1; + for (var i = 0; i < node.childCount; i++) { + var child = node.child(i), end = cur + child.nodeSize; + var allowed = match.matchType(child.type, child.attrs); + if (!allowed) { + delSteps.push(new ReplaceStep(cur, end, prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"].empty)); + } else { + match = allowed; + for (var j = 0; j < child.marks.length; j++) { if (!parentType.allowsMarkType(child.marks[j].type)) + { this.step(new RemoveMarkStep(cur, end, child.marks[j])); } } + } + cur = end; + } + if (!match.validEnd) { + var fill = match.fillBefore(prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty, true); + this.replace(cur, cur, new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](fill, 0, 0)); + } + for (var i$1 = delSteps.length - 1; i$1 >= 0; i$1--) { this.step(delSteps[i$1]); } + return this +}; + +// :: (Node, number, ?number, ?Slice) → ?Step +// ‘Fit’ a slice into a given position in the document, producing a +// [step](#transform.Step) that inserts it. Will return null if +// there's no meaningful way to insert the slice here, or inserting it +// would be a no-op (an empty slice over an empty range). +function replaceStep(doc, from, to, slice) { + if ( to === void 0 ) to = from; + if ( slice === void 0 ) slice = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"].empty; + + if (from == to && !slice.size) { return null } + + var $from = doc.resolve(from), $to = doc.resolve(to); + // Optimization -- avoid work if it's obvious that it's not needed. + if (fitsTrivially($from, $to, slice)) { return new ReplaceStep(from, to, slice) } + var placed = placeSlice($from, slice); + + var fittedLeft = fitLeft($from, placed); + var fitted = fitRight($from, $to, fittedLeft); + if (!fitted) { return null } + if (fittedLeft.size != fitted.size && canMoveText($from, $to, fittedLeft)) { + var d = $to.depth, after = $to.after(d); + while (d > 1 && after == $to.end(--d)) { ++after; } + var fittedAfter = fitRight($from, doc.resolve(after), fittedLeft); + if (fittedAfter) + { return new ReplaceAroundStep(from, after, to, $to.end(), fittedAfter, fittedLeft.size) } + } + return fitted.size || from != to ? new ReplaceStep(from, to, fitted) : null +} + +// :: (number, ?number, ?Slice) → this +// Replace the part of the document between `from` and `to` with the +// given `slice`. +Transform.prototype.replace = function(from, to, slice) { + if ( to === void 0 ) to = from; + if ( slice === void 0 ) slice = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"].empty; + + var step = replaceStep(this.doc, from, to, slice); + if (step) { this.step(step); } + return this +}; + +// :: (number, number, union) → this +// Replace the given range with the given content, which may be a +// fragment, node, or array of nodes. +Transform.prototype.replaceWith = function(from, to, content) { + return this.replace(from, to, new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].from(content), 0, 0)) +}; + +// :: (number, number) → this +// Delete the content between the given positions. +Transform.prototype.delete = function(from, to) { + return this.replace(from, to, prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"].empty) +}; + +// :: (number, union) → this +// Insert the given content at the given position. +Transform.prototype.insert = function(pos, content) { + return this.replaceWith(pos, pos, content) +}; + + + +function fitLeftInner($from, depth, placed, placedBelow) { + var content = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty, openEnd = 0, placedHere = placed[depth]; + if ($from.depth > depth) { + var inner = fitLeftInner($from, depth + 1, placed, placedBelow || placedHere); + openEnd = inner.openEnd + 1; + content = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].from($from.node(depth + 1).copy(inner.content)); + } + + if (placedHere) { + content = content.append(placedHere.content); + openEnd = placedHere.openEnd; + } + if (placedBelow) { + content = content.append($from.node(depth).contentMatchAt($from.indexAfter(depth)).fillBefore(prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty, true)); + openEnd = 0; + } + + return {content: content, openEnd: openEnd} +} + +function fitLeft($from, placed) { + var ref = fitLeftInner($from, 0, placed, false); + var content = ref.content; + var openEnd = ref.openEnd; + return new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](content, $from.depth, openEnd || 0) +} + +function fitRightJoin(content, parent, $from, $to, depth, openStart, openEnd) { + var match, count = content.childCount, matchCount = count - (openEnd > 0 ? 1 : 0); + var parentNode = openStart < 0 ? parent : $from.node(depth); + if (openStart < 0) + { match = parentNode.contentMatchAt(matchCount); } + else if (count == 1 && openEnd > 0) + { match = parentNode.contentMatchAt(openStart ? $from.index(depth) : $from.indexAfter(depth)); } + else + { match = parentNode.contentMatchAt($from.indexAfter(depth)) + .matchFragment(content, count > 0 && openStart ? 1 : 0, matchCount); } + + var toNode = $to.node(depth); + if (openEnd > 0 && depth < $to.depth) { + var after = toNode.content.cutByIndex($to.indexAfter(depth)).addToStart(content.lastChild); + var joinable$1 = match.fillBefore(after, true); + // Can't insert content if there's a single node stretched across this gap + if (joinable$1 && joinable$1.size && openStart > 0 && count == 1) { joinable$1 = null; } + + if (joinable$1) { + var inner = fitRightJoin(content.lastChild.content, content.lastChild, $from, $to, + depth + 1, count == 1 ? openStart - 1 : -1, openEnd - 1); + if (inner) { + var last = content.lastChild.copy(inner); + if (joinable$1.size) + { return content.cutByIndex(0, count - 1).append(joinable$1).addToEnd(last) } + else + { return content.replaceChild(count - 1, last) } + } + } + } + if (openEnd > 0) + { match = match.matchType((count == 1 && openStart > 0 ? $from.node(depth + 1) : content.lastChild).type); } + + // If we're here, the next level can't be joined, so we see what + // happens if we leave it open. + var toIndex = $to.index(depth); + if (toIndex == toNode.childCount && !toNode.type.compatibleContent(parent.type)) { return null } + var joinable = match.fillBefore(toNode.content, true, toIndex); + for (var i = toIndex; joinable && i < toNode.content.childCount; i++) + { if (!parentNode.type.allowsMarks(toNode.content.child(i).marks)) { joinable = null; } } + if (!joinable) { return null } + + if (openEnd > 0) { + var closed = fitRightClosed(content.lastChild, openEnd - 1, $from, depth + 1, + count == 1 ? openStart - 1 : -1); + content = content.replaceChild(count - 1, closed); + } + content = content.append(joinable); + if ($to.depth > depth) + { content = content.addToEnd(fitRightSeparate($to, depth + 1)); } + return content +} + +function fitRightClosed(node, openEnd, $from, depth, openStart) { + var match, content = node.content, count = content.childCount; + if (openStart >= 0) + { match = $from.node(depth).contentMatchAt($from.indexAfter(depth)) + .matchFragment(content, openStart > 0 ? 1 : 0, count); } + else + { match = node.contentMatchAt(count); } + + if (openEnd > 0) { + var closed = fitRightClosed(content.lastChild, openEnd - 1, $from, depth + 1, + count == 1 ? openStart - 1 : -1); + content = content.replaceChild(count - 1, closed); + } + + return node.copy(content.append(match.fillBefore(prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty, true))) +} + +function fitRightSeparate($to, depth) { + var node = $to.node(depth); + var fill = node.contentMatchAt(0).fillBefore(node.content, true, $to.index(depth)); + if ($to.depth > depth) { fill = fill.addToEnd(fitRightSeparate($to, depth + 1)); } + return node.copy(fill) +} + +function normalizeSlice(content, openStart, openEnd) { + while (openStart > 0 && openEnd > 0 && content.childCount == 1) { + content = content.firstChild.content; + openStart--; + openEnd--; + } + return new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](content, openStart, openEnd) +} + +// : (ResolvedPos, ResolvedPos, number, Slice) → Slice +function fitRight($from, $to, slice) { + var fitted = fitRightJoin(slice.content, $from.node(0), $from, $to, 0, slice.openStart, slice.openEnd); + if (!fitted) { return null } + return normalizeSlice(fitted, slice.openStart, $to.depth) +} + +function fitsTrivially($from, $to, slice) { + return !slice.openStart && !slice.openEnd && $from.start() == $to.start() && + $from.parent.canReplace($from.index(), $to.index(), slice.content) +} + +function canMoveText($from, $to, slice) { + if (!$to.parent.isTextblock) { return false } + + var parent = slice.openEnd ? nodeRight(slice.content, slice.openEnd) + : $from.node($from.depth - (slice.openStart - slice.openEnd)); + if (!parent.isTextblock) { return false } + for (var i = $to.index(); i < $to.parent.childCount; i++) + { if (!parent.type.allowsMarks($to.parent.child(i).marks)) { return false } } + var match; + if (slice.openEnd) { + match = parent.contentMatchAt(parent.childCount); + } else { + match = parent.contentMatchAt(parent.childCount); + if (slice.size) { match = match.matchFragment(slice.content, slice.openStart ? 1 : 0); } + } + match = match.matchFragment($to.parent.content, $to.index()); + return match && match.validEnd +} + +function nodeRight(content, depth) { + for (var i = 1; i < depth; i++) { content = content.lastChild.content; } + return content.lastChild +} + +// Algorithm for 'placing' the elements of a slice into a gap: +// +// We consider the content of each node that is open to the left to be +// independently placeable. I.e. in , when the +// paragraph on the left is open, "foo" can be placed (somewhere on +// the left side of the replacement gap) independently from p("bar"). +// +// So placeSlice splits up a slice into a number of sub-slices, +// along with information on where they can be placed on the given +// left-side edge. It works by walking the open side of the slice, +// from the inside out, and trying to find a landing spot for each +// element, by simultaneously scanning over the gap side. When no +// place is found for an open node's content, it is left in that node. + +// : (ResolvedPos, Slice) → [{content: Fragment, openEnd: number, depth: number}] +function placeSlice($from, slice) { + var frontier = new Frontier($from); + for (var pass = 1; slice.size && pass <= 3; pass++) { + var value = frontier.placeSlice(slice.content, slice.openStart, slice.openEnd, pass); + if (pass == 3 && value != slice && value.size) { pass = 0; } // Restart if the 3rd pass made progress but left content + slice = value; + } + while (frontier.open.length) { frontier.closeNode(); } + return frontier.placed +} + +// Helper class that models the open side of the insert position, +// keeping track of the content match and already inserted content +// at each depth. +var Frontier = function Frontier($pos) { + // : [{parent: Node, match: ContentMatch, content: Fragment, wrapper: bool, openEnd: number, depth: number}] + this.open = []; + for (var d = 0; d <= $pos.depth; d++) { + var parent = $pos.node(d), match = parent.contentMatchAt($pos.indexAfter(d)); + this.open.push({parent: parent, match: match, content: prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty, wrapper: false, openEnd: 0, depth: d}); + } + this.placed = []; +}; + +// : (Fragment, number, number, number, ?Node) → Slice +// Tries to place the content of the given slice, and returns a +// slice containing unplaced content. +// +// pass 1: try to fit directly +// pass 2: allow wrapper nodes to be introduced +// pass 3: allow unwrapping of nodes that aren't open +Frontier.prototype.placeSlice = function placeSlice (fragment, openStart, openEnd, pass, parent) { + if (openStart > 0) { + var first = fragment.firstChild; + var inner = this.placeSlice(first.content, Math.max(0, openStart - 1), + openEnd && fragment.childCount == 1 ? openEnd - 1 : 0, + pass, first); + if (inner.content != first.content) { + if (inner.content.size) { + fragment = fragment.replaceChild(0, first.copy(inner.content)); + openStart = inner.openStart + 1; + } else { + if (fragment.childCount == 1) { openEnd = 0; } + fragment = fragment.cutByIndex(1); + openStart = 0; + } + } + } + var result = this.placeContent(fragment, openStart, openEnd, pass, parent); + if (pass > 2 && result.size && openStart == 0) { + var child = result.content.firstChild, single = result.content.childCount == 1; + this.placeContent(child.content, 0, openEnd && single ? openEnd - 1 : 0, pass, child); + result = single ? prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty : new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](result.content.cutByIndex(1), 0, openEnd); + } + return result +}; + +Frontier.prototype.placeContent = function placeContent (fragment, openStart, openEnd, pass, parent) { + var i = 0; + // Go over the fragment's children + for (; i < fragment.childCount; i++) { + var child = fragment.child(i), placed = false, last = i == fragment.childCount - 1; + // Try each open node in turn, starting from the innermost + for (var d = this.open.length - 1; d >= 0; d--) { + var open = this.open[d], wrap = (void 0); + + // If pass > 1, it is allowed to wrap the node to help find a + // fit, so if findWrapping returns something, we add open + // nodes to the frontier for that wrapping. + if (pass > 1 && (wrap = open.match.findWrapping(child.type)) && + !(parent && wrap.length && wrap[wrap.length - 1] == parent.type)) { + while (this.open.length - 1 > d) { this.closeNode(); } + for (var w = 0; w < wrap.length; w++) { + open.match = open.match.matchType(wrap[w]); + d++; + open = {parent: wrap[w].create(), + match: wrap[w].contentMatch, + content: prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty, wrapper: true, openEnd: 0, depth: d + w}; + this.open.push(open); + } + } + + // See if the child fits here + var match = open.match.matchType(child.type); + if (!match) { + var fill = open.match.fillBefore(prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].from(child)); + if (fill) { + for (var j = 0; j < fill.childCount; j++) { + var ch = fill.child(j); + this.addNode(open, ch, 0); + match = open.match.matchFragment(ch); + } + } else if (parent && open.match.matchType(parent.type)) { + // Don't continue looking further up if the parent node + // would fit here. + break + } else { + continue + } + } + + // Close open nodes above this one, since we're starting to + // add to this. + while (this.open.length - 1 > d) { this.closeNode(); } + // Strip marks from the child or close its start when necessary + child = child.mark(open.parent.type.allowedMarks(child.marks)); + if (openStart) { + child = closeNodeStart(child, openStart, last ? openEnd : 0); + openStart = 0; + } + // Add the child to this open node and adjust its metadata + this.addNode(open, child, last ? openEnd : 0); + open.match = match; + if (last) { openEnd = 0; } + placed = true; + break + } + // As soon as we've failed to place a node we stop looking at + // later nodes + if (!placed) { break } + } + // Close the current open node if it's not the the root and we + // either placed up to the end of the node or the the current + // slice depth's node type matches the open node's type + if (this.open.length > 1 && + (i > 0 && i == fragment.childCount || + parent && this.open[this.open.length - 1].parent.type == parent.type)) + { this.closeNode(); } + + return new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](fragment.cutByIndex(i), openStart, openEnd) +}; + +Frontier.prototype.addNode = function addNode (open, node, openEnd) { + open.content = closeFragmentEnd(open.content, open.openEnd).addToEnd(node); + open.openEnd = openEnd; +}; + +Frontier.prototype.closeNode = function closeNode () { + var open = this.open.pop(); + if (open.content.size == 0) ; else if (open.wrapper) { + this.addNode(this.open[this.open.length - 1], open.parent.copy(open.content), open.openEnd + 1); + } else { + this.placed[open.depth] = {depth: open.depth, content: open.content, openEnd: open.openEnd}; + } +}; + +function closeNodeStart(node, openStart, openEnd) { + var content = node.content; + if (openStart > 1) { + var first = closeNodeStart(node.firstChild, openStart - 1, node.childCount == 1 ? openEnd - 1 : 0); + content = node.content.replaceChild(0, first); + } + var fill = node.type.contentMatch.fillBefore(content, openEnd == 0); + return node.copy(fill.append(content)) +} + +function closeNodeEnd(node, depth) { + var content = node.content; + if (depth > 1) { + var last = closeNodeEnd(node.lastChild, depth - 1); + content = node.content.replaceChild(node.childCount - 1, last); + } + var fill = node.contentMatchAt(node.childCount).fillBefore(prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty, true); + return node.copy(content.append(fill)) +} + +function closeFragmentEnd(fragment, depth) { + return depth ? fragment.replaceChild(fragment.childCount - 1, closeNodeEnd(fragment.lastChild, depth)) : fragment +} + +// :: (number, number, Slice) → this +// Replace a range of the document with a given slice, using `from`, +// `to`, and the slice's [`openStart`](#model.Slice.openStart) property +// as hints, rather than fixed start and end points. This method may +// grow the replaced area or close open nodes in the slice in order to +// get a fit that is more in line with WYSIWYG expectations, by +// dropping fully covered parent nodes of the replaced region when +// they are marked [non-defining](#model.NodeSpec.defining), or +// including an open parent node from the slice that _is_ marked as +// [defining](#model.NodeSpec.defining). +// +// This is the method, for example, to handle paste. The similar +// [`replace`](#transform.Transform.replace) method is a more +// primitive tool which will _not_ move the start and end of its given +// range, and is useful in situations where you need more precise +// control over what happens. +Transform.prototype.replaceRange = function(from, to, slice) { + if (!slice.size) { return this.deleteRange(from, to) } + + var $from = this.doc.resolve(from), $to = this.doc.resolve(to); + if (fitsTrivially($from, $to, slice)) + { return this.step(new ReplaceStep(from, to, slice)) } + + var targetDepths = coveredDepths($from, this.doc.resolve(to)); + // Can't replace the whole document, so remove 0 if it's present + if (targetDepths[targetDepths.length - 1] == 0) { targetDepths.pop(); } + // Negative numbers represent not expansion over the whole node at + // that depth, but replacing from $from.before(-D) to $to.pos. + var preferredTarget = -($from.depth + 1); + targetDepths.unshift(preferredTarget); + // This loop picks a preferred target depth, if one of the covering + // depths is not outside of a defining node, and adds negative + // depths for any depth that has $from at its start and does not + // cross a defining node. + for (var d = $from.depth, pos = $from.pos - 1; d > 0; d--, pos--) { + var spec = $from.node(d).type.spec; + if (spec.defining || spec.isolating) { break } + if (targetDepths.indexOf(d) > -1) { preferredTarget = d; } + else if ($from.before(d) == pos) { targetDepths.splice(1, 0, -d); } + } + // Try to fit each possible depth of the slice into each possible + // target depth, starting with the preferred depths. + var preferredTargetIndex = targetDepths.indexOf(preferredTarget); + + var leftNodes = [], preferredDepth = slice.openStart; + for (var content = slice.content, i = 0;; i++) { + var node = content.firstChild; + leftNodes.push(node); + if (i == slice.openStart) { break } + content = node.content; + } + // Back up if the node directly above openStart, or the node above + // that separated only by a non-defining textblock node, is defining. + if (preferredDepth > 0 && leftNodes[preferredDepth - 1].type.spec.defining && + $from.node(preferredTargetIndex).type != leftNodes[preferredDepth - 1].type) + { preferredDepth -= 1; } + else if (preferredDepth >= 2 && leftNodes[preferredDepth - 1].isTextblock && leftNodes[preferredDepth - 2].type.spec.defining && + $from.node(preferredTargetIndex).type != leftNodes[preferredDepth - 2].type) + { preferredDepth -= 2; } + + for (var j = slice.openStart; j >= 0; j--) { + var openDepth = (j + preferredDepth + 1) % (slice.openStart + 1); + var insert = leftNodes[openDepth]; + if (!insert) { continue } + for (var i$1 = 0; i$1 < targetDepths.length; i$1++) { + // Loop over possible expansion levels, starting with the + // preferred one + var targetDepth = targetDepths[(i$1 + preferredTargetIndex) % targetDepths.length], expand = true; + if (targetDepth < 0) { expand = false; targetDepth = -targetDepth; } + var parent = $from.node(targetDepth - 1), index = $from.index(targetDepth - 1); + if (parent.canReplaceWith(index, index, insert.type, insert.marks)) + { return this.replace($from.before(targetDepth), expand ? $to.after(targetDepth) : to, + new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](closeFragment(slice.content, 0, slice.openStart, openDepth), + openDepth, slice.openEnd)) } + } + } + + var startSteps = this.steps.length; + for (var i$2 = targetDepths.length - 1; i$2 >= 0; i$2--) { + this.replace(from, to, slice); + if (this.steps.length > startSteps) { break } + var depth = targetDepths[i$2]; + if (i$2 < 0) { continue } + from = $from.before(depth); to = $to.after(depth); + } + return this +}; + +function closeFragment(fragment, depth, oldOpen, newOpen, parent) { + if (depth < oldOpen) { + var first = fragment.firstChild; + fragment = fragment.replaceChild(0, first.copy(closeFragment(first.content, depth + 1, oldOpen, newOpen, first))); + } + if (depth > newOpen) { + var match = parent.contentMatchAt(0); + var start = match.fillBefore(fragment).append(fragment); + fragment = start.append(match.matchFragment(start).fillBefore(prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty, true)); + } + return fragment +} + +// :: (number, number, Node) → this +// Replace the given range with a node, but use `from` and `to` as +// hints, rather than precise positions. When from and to are the same +// and are at the start or end of a parent node in which the given +// node doesn't fit, this method may _move_ them out towards a parent +// that does allow the given node to be placed. When the given range +// completely covers a parent node, this method may completely replace +// that parent node. +Transform.prototype.replaceRangeWith = function(from, to, node) { + if (!node.isInline && from == to && this.doc.resolve(from).parent.content.size) { + var point = insertPoint(this.doc, from, node.type); + if (point != null) { from = to = point; } + } + return this.replaceRange(from, to, new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].from(node), 0, 0)) +}; + +// :: (number, number) → this +// Delete the given range, expanding it to cover fully covered +// parent nodes until a valid replace is found. +Transform.prototype.deleteRange = function(from, to) { + var $from = this.doc.resolve(from), $to = this.doc.resolve(to); + var covered = coveredDepths($from, $to); + for (var i = 0; i < covered.length; i++) { + var depth = covered[i], last = i == covered.length - 1; + if ((last && depth == 0) || $from.node(depth).type.contentMatch.validEnd) + { return this.delete($from.start(depth), $to.end(depth)) } + if (depth > 0 && (last || $from.node(depth - 1).canReplace($from.index(depth - 1), $to.indexAfter(depth - 1)))) + { return this.delete($from.before(depth), $to.after(depth)) } + } + for (var d = 1; d <= $from.depth && d <= $to.depth; d++) { + if (from - $from.start(d) == $from.depth - d && to > $from.end(d) && $to.end(d) - to != $to.depth - d) + { return this.delete($from.before(d), to) } + } + return this.delete(from, to) +}; + +// : (ResolvedPos, ResolvedPos) → [number] +// Returns an array of all depths for which $from - $to spans the +// whole content of the nodes at that depth. +function coveredDepths($from, $to) { + var result = [], minDepth = Math.min($from.depth, $to.depth); + for (var d = minDepth; d >= 0; d--) { + var start = $from.start(d); + if (start < $from.pos - ($from.depth - d) || + $to.end(d) > $to.pos + ($to.depth - d) || + $from.node(d).type.spec.isolating || + $to.node(d).type.spec.isolating) { break } + if (start == $to.start(d)) { result.push(d); } + } + return result +} + + +//# sourceMappingURL=index.es.js.map + + +/***/ }), + +/***/ "./node_modules/prosemirror-utils/dist/index.js": +/*!******************************************************!*\ + !*** ./node_modules/prosemirror-utils/dist/index.js ***! + \******************************************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, '__esModule', { value: true }); + +var prosemirrorState = __webpack_require__(/*! prosemirror-state */ "./node_modules/prosemirror-state/dist/index.es.js"); +var prosemirrorModel = __webpack_require__(/*! prosemirror-model */ "./node_modules/prosemirror-model/dist/index.es.js"); +var prosemirrorTables = __webpack_require__(/*! prosemirror-tables */ "./node_modules/prosemirror-tables/dist/index.es.js"); + +// :: (nodeType: union) → (tr: Transaction) → Transaction +// Returns a new transaction that removes a node of a given `nodeType`. It will return an original transaction if parent node hasn't been found. +// +// ```javascript +// dispatch( +// removeParentNodeOfType(schema.nodes.table)(tr) +// ); +// ``` +var removeParentNodeOfType = function removeParentNodeOfType(nodeType) { + return function (tr) { + var parent = findParentNodeOfType(nodeType)(tr.selection); + if (parent) { + return removeNodeAtPos(parent.pos)(tr); + } + return tr; + }; +}; + +// :: (nodeType: union, content: union) → (tr: Transaction) → Transaction +// Returns a new transaction that replaces parent node of a given `nodeType` with the given `content`. It will return an original transaction if either parent node hasn't been found or replacing is not possible. +// +// ```javascript +// const node = schema.nodes.paragraph.createChecked({}, schema.text('new')); +// +// dispatch( +// replaceParentNodeOfType(schema.nodes.table, node)(tr) +// ); +// ``` +var replaceParentNodeOfType = function replaceParentNodeOfType(nodeType, content) { + return function (tr) { + if (!Array.isArray(nodeType)) { + nodeType = [nodeType]; + } + for (var i = 0, count = nodeType.length; i < count; i++) { + var parent = findParentNodeOfType(nodeType[i])(tr.selection); + if (parent) { + var newTr = replaceNodeAtPos(parent.pos, content)(tr); + if (newTr !== tr) { + return newTr; + } + } + } + return tr; + }; +}; + +// :: (tr: Transaction) → Transaction +// Returns a new transaction that removes selected node. It will return an original transaction if current selection is not a `NodeSelection`. +// +// ```javascript +// dispatch( +// removeSelectedNode(tr) +// ); +// ``` +var removeSelectedNode = function removeSelectedNode(tr) { + if (isNodeSelection(tr.selection)) { + var from = tr.selection.$from.pos; + var to = tr.selection.$to.pos; + return cloneTr(tr.delete(from, to)); + } + return tr; +}; + +// :: (content: union) → (tr: Transaction) → Transaction +// Returns a new transaction that replaces selected node with a given `node`, keeping NodeSelection on the new `node`. +// It will return the original transaction if either current selection is not a NodeSelection or replacing is not possible. +// +// ```javascript +// const node = schema.nodes.paragraph.createChecked({}, schema.text('new')); +// dispatch( +// replaceSelectedNode(node)(tr) +// ); +// ``` +var replaceSelectedNode = function replaceSelectedNode(content) { + return function (tr) { + if (isNodeSelection(tr.selection)) { + var _tr$selection = tr.selection, + $from = _tr$selection.$from, + $to = _tr$selection.$to; + + if (content instanceof prosemirrorModel.Fragment && $from.parent.canReplace($from.index(), $from.indexAfter(), content) || $from.parent.canReplaceWith($from.index(), $from.indexAfter(), content.type)) { + return cloneTr(tr.replaceWith($from.pos, $to.pos, content) + // restore node selection + .setSelection(new prosemirrorState.NodeSelection(tr.doc.resolve($from.pos)))); + } + } + return tr; + }; +}; + +// :: (position: number, dir: ?number) → (tr: Transaction) → Transaction +// Returns a new transaction that tries to find a valid cursor selection starting at the given `position` +// and searching back if `dir` is negative, and forward if positive. +// If a valid cursor position hasn't been found, it will return the original transaction. +// +// ```javascript +// dispatch( +// setTextSelection(5)(tr) +// ); +// ``` +var setTextSelection = function setTextSelection(position) { + var dir = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; + return function (tr) { + var nextSelection = prosemirrorState.Selection.findFrom(tr.doc.resolve(position), dir, true); + if (nextSelection) { + return tr.setSelection(nextSelection); + } + return tr; + }; +}; + +var isSelectableNode = function isSelectableNode(node) { + return node.type && node.type.spec.selectable; +}; +var shouldSelectNode = function shouldSelectNode(node) { + return isSelectableNode(node) && node.type.isLeaf; +}; + +var setSelection = function setSelection(node, pos, tr) { + if (shouldSelectNode(node)) { + return tr.setSelection(new prosemirrorState.NodeSelection(tr.doc.resolve(pos))); + } + return setTextSelection(pos)(tr); +}; + +// :: (content: union, position: ?number, tryToReplace?: boolean) → (tr: Transaction) → Transaction +// Returns a new transaction that inserts a given `content` at the current cursor position, or at a given `position`, if it is allowed by schema. If schema restricts such nesting, it will try to find an appropriate place for a given node in the document, looping through parent nodes up until the root document node. +// If `tryToReplace` is true and current selection is a NodeSelection, it will replace selected node with inserted content if its allowed by schema. +// If cursor is inside of an empty paragraph, it will try to replace that paragraph with the given content. If insertion is successful and inserted node has content, it will set cursor inside of that content. +// It will return an original transaction if the place for insertion hasn't been found. +// +// ```javascript +// const node = schema.nodes.extension.createChecked({}); +// dispatch( +// safeInsert(node)(tr) +// ); +// ``` +var safeInsert = function safeInsert(content, position, tryToReplace) { + return function (tr) { + var hasPosition = typeof position === 'number'; + var $from = tr.selection.$from; + + var $insertPos = hasPosition ? tr.doc.resolve(position) : isNodeSelection(tr.selection) ? tr.doc.resolve($from.pos + 1) : $from; + var parent = $insertPos.parent; + + // try to replace selected node + + if (isNodeSelection(tr.selection) && tryToReplace) { + var oldTr = tr; + tr = replaceSelectedNode(content)(tr); + if (oldTr !== tr) { + return tr; + } + } + + // try to replace an empty paragraph + if (isEmptyParagraph(parent)) { + var _oldTr = tr; + tr = replaceParentNodeOfType(parent.type, content)(tr); + if (_oldTr !== tr) { + var pos = isSelectableNode(content) ? // for selectable node, selection position would be the position of the replaced parent + $insertPos.before($insertPos.depth) : $insertPos.pos; + return setSelection(content, pos, tr); + } + } + + // given node is allowed at the current cursor position + if (canInsert($insertPos, content)) { + tr.insert($insertPos.pos, content); + var _pos = hasPosition ? $insertPos.pos : isSelectableNode(content) ? // for atom nodes selection position after insertion is the previous pos + tr.selection.$anchor.pos - 1 : tr.selection.$anchor.pos; + return cloneTr(setSelection(content, _pos, tr)); + } + + // looking for a place in the doc where the node is allowed + for (var i = $insertPos.depth; i > 0; i--) { + var _pos2 = $insertPos.after(i); + var $pos = tr.doc.resolve(_pos2); + if (canInsert($pos, content)) { + tr.insert(_pos2, content); + return cloneTr(setSelection(content, _pos2, tr)); + } + } + return tr; + }; +}; + +// :: (nodeType: union, type: ?union, attrs: ?union, marks?: [Mark]) → (tr: Transaction) → Transaction +// Returns a transaction that changes the type, attributes, and/or marks of the parent node of a given `nodeType`. +// +// ```javascript +// const node = schema.nodes.extension.createChecked({}); +// dispatch( +// setParentNodeMarkup(schema.nodes.panel, null, { panelType })(tr); +// ); +// ``` +var setParentNodeMarkup = function setParentNodeMarkup(nodeType, type, attrs, marks) { + return function (tr) { + var parent = findParentNodeOfType(nodeType)(tr.selection); + if (parent) { + return cloneTr(tr.setNodeMarkup(parent.pos, type, Object.assign({}, parent.node.attrs, attrs), marks)); + } + return tr; + }; +}; + +// :: (nodeType: union) → (tr: Transaction) → Transaction +// Returns a new transaction that sets a `NodeSelection` on a parent node of a `given nodeType`. +// +// ```javascript +// dispatch( +// selectParentNodeOfType([tableCell, tableHeader])(state.tr) +// ); +// ``` +var selectParentNodeOfType = function selectParentNodeOfType(nodeType) { + return function (tr) { + if (!isNodeSelection(tr.selection)) { + var parent = findParentNodeOfType(nodeType)(tr.selection); + if (parent) { + return cloneTr(tr.setSelection(prosemirrorState.NodeSelection.create(tr.doc, parent.pos))); + } + } + return tr; + }; +}; + +// :: (tr: Transaction) → Transaction +// Returns a new transaction that deletes previous node. +// +// ```javascript +// dispatch( +// removeNodeBefore(state.tr) +// ); +// ``` +var removeNodeBefore = function removeNodeBefore(tr) { + var position = findPositionOfNodeBefore(tr.selection); + if (typeof position === 'number') { + return removeNodeAtPos(position)(tr); + } + return tr; +}; + +// :: (selection: Selection) → boolean +// Checks if current selection is a `NodeSelection`. +// +// ```javascript +// if (isNodeSelection(tr.selection)) { +// // ... +// } +// ``` +var isNodeSelection = function isNodeSelection(selection) { + return selection instanceof prosemirrorState.NodeSelection; +}; + +// (nodeType: union) → boolean +// Checks if the type a given `node` equals to a given `nodeType`. +var equalNodeType = function equalNodeType(nodeType, node) { + return Array.isArray(nodeType) && nodeType.indexOf(node.type) > -1 || node.type === nodeType; +}; + +// (tr: Transaction) → Transaction +// Creates a new transaction object from a given transaction +var cloneTr = function cloneTr(tr) { + return Object.assign(Object.create(tr), tr).setTime(Date.now()); +}; + +// (position: number, content: union) → (tr: Transaction) → Transaction +// Returns a `replace` transaction that replaces a node at a given position with the given `content`. +// It will return the original transaction if replacing is not possible. +// `position` should point at the position immediately before the node. +var replaceNodeAtPos = function replaceNodeAtPos(position, content) { + return function (tr) { + var node = tr.doc.nodeAt(position); + var $pos = tr.doc.resolve(position); + if (canReplace($pos, content)) { + tr = tr.replaceWith(position, position + node.nodeSize, content); + var start = tr.selection.$from.pos - 1; + // put cursor inside of the inserted node + tr = setTextSelection(Math.max(start, 0), -1)(tr); + // move cursor to the start of the node + tr = setTextSelection(tr.selection.$from.start())(tr); + return cloneTr(tr); + } + return tr; + }; +}; + +// ($pos: ResolvedPos, doc: ProseMirrorNode, content: union, ) → boolean +// Checks if replacing a node at a given `$pos` inside of the `doc` node with the given `content` is possible. +var canReplace = function canReplace($pos, content) { + var node = $pos.node($pos.depth); + return node && node.type.validContent(content instanceof prosemirrorModel.Fragment ? content : prosemirrorModel.Fragment.from(content)); +}; + +// (position: number) → (tr: Transaction) → Transaction +// Returns a `delete` transaction that removes a node at a given position with the given `node`. +// `position` should point at the position immediately before the node. +var removeNodeAtPos = function removeNodeAtPos(position) { + return function (tr) { + var node = tr.doc.nodeAt(position); + return cloneTr(tr.delete(position, position + node.nodeSize)); + }; +}; + +// (schema: Schema) → {[key: string]: NodeType} +// Returns a map where keys are tableRoles and values are NodeTypes. +var tableNodeTypes = function tableNodeTypes(schema) { + if (schema.cached.tableNodeTypes) { + return schema.cached.tableNodeTypes; + } + var roles = {}; + Object.keys(schema.nodes).forEach(function (type) { + var nodeType = schema.nodes[type]; + if (nodeType.spec.tableRole) { + roles[nodeType.spec.tableRole] = nodeType; + } + }); + schema.cached.tableNodeTypes = roles; + return roles; +}; + +// :: ($pos: ResolvedPos, content: union) → boolean +// Checks if a given `content` can be inserted at the given `$pos` +// +// ```javascript +// const { selection: { $from } } = state; +// const node = state.schema.nodes.atom.createChecked(); +// if (canInsert($from, node)) { +// // ... +// } +// ``` +var canInsert = function canInsert($pos, content) { + var index = $pos.index(); + + if (content instanceof prosemirrorModel.Fragment) { + return $pos.parent.canReplace(index, index, content); + } else if (content instanceof prosemirrorModel.Node) { + return $pos.parent.canReplaceWith(index, index, content.type); + } + return false; +}; + +// (node: ProseMirrorNode) → boolean +// Checks if a given `node` is an empty paragraph +var isEmptyParagraph = function isEmptyParagraph(node) { + return !node || node.type.name === 'paragraph' && node.nodeSize === 2; +}; + +// ($pos: ResolvedPos) → ?{pos: number, start: number, node: ProseMirrorNode} +// Iterates over parent nodes, returning a table node closest to a given `$pos`. +// +// ```javascript +// const table = findTableClosestToPos(state.doc.resolve(10)); +// ``` +var findTableClosestToPos = function findTableClosestToPos($pos) { + var predicate = function predicate(node) { + return node.type.spec.tableRole && /table/i.test(node.type.spec.tableRole); + }; + return findParentNodeClosestToPos($pos, predicate); +}; + +var createCell = function createCell(cellType) { + var cellContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + + if (cellContent) { + return cellType.createChecked(null, cellContent); + } + + return cellType.createAndFill(); +}; + +// (rect: {left: number, right: number, top: number, bottom: number}) → (selection: Selection) → boolean +// Checks if a given CellSelection rect is selected +var isRectSelected = function isRectSelected(rect) { + return function (selection) { + var map = prosemirrorTables.TableMap.get(selection.$anchorCell.node(-1)); + var start = selection.$anchorCell.start(-1); + var cells = map.cellsInRect(rect); + var selectedCells = map.cellsInRect(map.rectBetween(selection.$anchorCell.pos - start, selection.$headCell.pos - start)); + + for (var i = 0, count = cells.length; i < count; i++) { + if (selectedCells.indexOf(cells[i]) === -1) { + return false; + } + } + + return true; + }; +}; + +// This function transposes an array of array flipping the columns for rows, +// transposition is a familiar algebra concept; +// you can get more details here: +// https://en.wikipedia.org/wiki/Transpose +// +// ```javascript +// +// const arr = [ +// ['a1', 'a2', 'a3'], +// ['b1', 'b2', 'b3'], +// ['c1', 'c2', 'c3'], +// ['d1', 'd2', 'd3'], +// ]; +// +// const result = transpose(arr); +// +// result === [ +// ['a1', 'b1', 'c1', 'd1'], +// ['a2', 'b2', 'c2', 'd2'], +// ['a3', 'b3', 'c3', 'd3'], +// ] +// ``` +var transpose = function transpose(array) { + return array[0].map(function (_, i) { + return array.map(function (column) { + return column[i]; + }); + }); +}; + +// :: (tableNode: Node) -> Array +// This function will transform the table node +// into a matrix of rows and columns respecting merged cells, +// for example this table will be convert to the below: +// +// ``` +// ____________________________ +// | | | | +// | A1 | B1 | C1 | +// |______|______|______ ______| +// | | | | +// | A2 | B2 | | +// |______|______ ______| | +// | | | | D1 | +// | A3 | B3 | C2 | | +// |______|______|______|______| +// ``` +// +// +// ```javascript +// array = [ +// [A1, B1, C1, null], +// [A2, B2, null, D1], +// [A3. B3, C2, null], +// ] +// ``` +var convertTableNodeToArrayOfRows = function convertTableNodeToArrayOfRows(tableNode) { + var map = prosemirrorTables.TableMap.get(tableNode); + var rows = []; + for (var rowIndex = 0; rowIndex < map.height; rowIndex++) { + var rowCells = []; + var seen = {}; + + for (var colIndex = 0; colIndex < map.width; colIndex++) { + var cellPos = map.map[rowIndex * map.width + colIndex]; + var cell = tableNode.nodeAt(cellPos); + var rect = map.findCell(cellPos); + if (seen[cellPos] || rect.top !== rowIndex) { + rowCells.push(null); + continue; + } + seen[cellPos] = true; + + rowCells.push(cell); + } + + rows.push(rowCells); + } + + return rows; +}; + +// :: (tableNode: Node, tableArray: Array) -> Node +// This function will transform a matrix of nodes +// into table node respecting merged cells and rows configurations, +// for example this array will be convert to the table below: +// +// ```javascript +// array = [ +// [A1, B1, C1, null], +// [A2, B2, null, D1], +// [A3. B3, C2, null], +// ] +// ``` +// +// ``` +// ____________________________ +// | | | | +// | A1 | B1 | C1 | +// |______|______|______ ______| +// | | | | +// | A2 | B2 | | +// |______|______ ______| | +// | | | | D1 | +// | A3 | B3 | C2 | | +// |______|______|______|______| +// ``` +// +var convertArrayOfRowsToTableNode = function convertArrayOfRowsToTableNode(tableNode, arrayOfNodes) { + var rowsPM = []; + var map = prosemirrorTables.TableMap.get(tableNode); + for (var rowIndex = 0; rowIndex < map.height; rowIndex++) { + var row = tableNode.child(rowIndex); + var rowCells = []; + + for (var colIndex = 0; colIndex < map.width; colIndex++) { + if (!arrayOfNodes[rowIndex][colIndex]) { + continue; + } + var cellPos = map.map[rowIndex * map.width + colIndex]; + + var cell = arrayOfNodes[rowIndex][colIndex]; + var oldCell = tableNode.nodeAt(cellPos); + var newCell = oldCell.type.createChecked(Object.assign({}, cell.attrs), cell.content, cell.marks); + rowCells.push(newCell); + } + + rowsPM.push(row.type.createChecked(row.attrs, rowCells, row.marks)); + } + + var newTable = tableNode.type.createChecked(tableNode.attrs, rowsPM, tableNode.marks); + + return newTable; +}; + +var moveTableColumn = function moveTableColumn(table, indexesOrigin, indexesTarget, direction) { + var rows = transpose(convertTableNodeToArrayOfRows(table.node)); + + rows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, direction); + rows = transpose(rows); + + return convertArrayOfRowsToTableNode(table.node, rows); +}; + +var moveTableRow = function moveTableRow(table, indexesOrigin, indexesTarget, direction) { + var rows = convertTableNodeToArrayOfRows(table.node); + + rows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, direction); + + return convertArrayOfRowsToTableNode(table.node, rows); +}; + +var moveRowInArrayOfRows = function moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, directionOverride) { + var direction = indexesOrigin[0] > indexesTarget[0] ? -1 : 1; + + var rowsExtracted = rows.splice(indexesOrigin[0], indexesOrigin.length); + var positionOffset = rowsExtracted.length % 2 === 0 ? 1 : 0; + var target = void 0; + + if (directionOverride === -1 && direction === 1) { + target = indexesTarget[0] - 1; + } else if (directionOverride === 1 && direction === -1) { + target = indexesTarget[indexesTarget.length - 1] - positionOffset + 1; + } else { + target = direction === -1 ? indexesTarget[0] : indexesTarget[indexesTarget.length - 1] - positionOffset; + } + + rows.splice.apply(rows, [target, 0].concat(rowsExtracted)); + return rows; +}; + +var checkInvalidMovements = function checkInvalidMovements(originIndex, targetIndex, targets, type) { + var direction = originIndex > targetIndex ? -1 : 1; + var errorMessage = 'Target position is invalid, you can\'t move the ' + type + ' ' + originIndex + ' to ' + targetIndex + ', the target can\'t be split. You could use tryToFit option.'; + + if (direction === 1) { + if (targets.slice(0, targets.length - 1).indexOf(targetIndex) !== -1) { + throw new Error(errorMessage); + } + } else { + if (targets.slice(1).indexOf(targetIndex) !== -1) { + throw new Error(errorMessage); + } + } + + return true; +}; + +// :: (predicate: (node: ProseMirrorNode) → boolean) → (selection: Selection) → ?{pos: number, start: number, depth: number, node: ProseMirrorNode} +// Iterates over parent nodes, returning the closest node and its start position `predicate` returns truthy for. `start` points to the start position of the node, `pos` points directly before the node. +// +// ```javascript +// const predicate = node => node.type === schema.nodes.blockquote; +// const parent = findParentNode(predicate)(selection); +// ``` +var findParentNode = function findParentNode(predicate) { + return function (_ref) { + var $from = _ref.$from; + return findParentNodeClosestToPos($from, predicate); + }; +}; + +// :: ($pos: ResolvedPos, predicate: (node: ProseMirrorNode) → boolean) → ?{pos: number, start: number, depth: number, node: ProseMirrorNode} +// Iterates over parent nodes starting from the given `$pos`, returning the closest node and its start position `predicate` returns truthy for. `start` points to the start position of the node, `pos` points directly before the node. +// +// ```javascript +// const predicate = node => node.type === schema.nodes.blockquote; +// const parent = findParentNodeClosestToPos(state.doc.resolve(5), predicate); +// ``` +var findParentNodeClosestToPos = function findParentNodeClosestToPos($pos, predicate) { + for (var i = $pos.depth; i > 0; i--) { + var node = $pos.node(i); + if (predicate(node)) { + return { + pos: i > 0 ? $pos.before(i) : 0, + start: $pos.start(i), + depth: i, + node: node + }; + } + } +}; + +// :: (predicate: (node: ProseMirrorNode) → boolean, domAtPos: (pos: number) → {node: dom.Node, offset: number}) → (selection: Selection) → ?dom.Node +// Iterates over parent nodes, returning DOM reference of the closest node `predicate` returns truthy for. +// +// ```javascript +// const domAtPos = view.domAtPos.bind(view); +// const predicate = node => node.type === schema.nodes.table; +// const parent = findParentDomRef(predicate, domAtPos)(selection); // +// ``` +var findParentDomRef = function findParentDomRef(predicate, domAtPos) { + return function (selection) { + var parent = findParentNode(predicate)(selection); + if (parent) { + return findDomRefAtPos(parent.pos, domAtPos); + } + }; +}; + +// :: (predicate: (node: ProseMirrorNode) → boolean) → (selection: Selection) → boolean +// Checks if there's a parent node `predicate` returns truthy for. +// +// ```javascript +// if (hasParentNode(node => node.type === schema.nodes.table)(selection)) { +// // .... +// } +// ``` +var hasParentNode = function hasParentNode(predicate) { + return function (selection) { + return !!findParentNode(predicate)(selection); + }; +}; + +// :: (nodeType: union) → (selection: Selection) → ?{pos: number, start: number, depth: number, node: ProseMirrorNode} +// Iterates over parent nodes, returning closest node of a given `nodeType`. `start` points to the start position of the node, `pos` points directly before the node. +// +// ```javascript +// const parent = findParentNodeOfType(schema.nodes.paragraph)(selection); +// ``` +var findParentNodeOfType = function findParentNodeOfType(nodeType) { + return function (selection) { + return findParentNode(function (node) { + return equalNodeType(nodeType, node); + })(selection); + }; +}; + +// :: ($pos: ResolvedPos, nodeType: union) → ?{pos: number, start: number, depth: number, node: ProseMirrorNode} +// Iterates over parent nodes starting from the given `$pos`, returning closest node of a given `nodeType`. `start` points to the start position of the node, `pos` points directly before the node. +// +// ```javascript +// const parent = findParentNodeOfTypeClosestToPos(state.doc.resolve(10), schema.nodes.paragraph); +// ``` +var findParentNodeOfTypeClosestToPos = function findParentNodeOfTypeClosestToPos($pos, nodeType) { + return findParentNodeClosestToPos($pos, function (node) { + return equalNodeType(nodeType, node); + }); +}; + +// :: (nodeType: union) → (selection: Selection) → boolean +// Checks if there's a parent node of a given `nodeType`. +// +// ```javascript +// if (hasParentNodeOfType(schema.nodes.table)(selection)) { +// // .... +// } +// ``` +var hasParentNodeOfType = function hasParentNodeOfType(nodeType) { + return function (selection) { + return hasParentNode(function (node) { + return equalNodeType(nodeType, node); + })(selection); + }; +}; + +// :: (nodeType: union, domAtPos: (pos: number) → {node: dom.Node, offset: number}) → (selection: Selection) → ?dom.Node +// Iterates over parent nodes, returning DOM reference of the closest node of a given `nodeType`. +// +// ```javascript +// const domAtPos = view.domAtPos.bind(view); +// const parent = findParentDomRefOfType(schema.nodes.codeBlock, domAtPos)(selection); //
      +// ```
      +var findParentDomRefOfType = function findParentDomRefOfType(nodeType, domAtPos) {
      +  return function (selection) {
      +    return findParentDomRef(function (node) {
      +      return equalNodeType(nodeType, node);
      +    }, domAtPos)(selection);
      +  };
      +};
      +
      +// :: (nodeType: union) → (selection: Selection) → ?{pos: number, start: number, depth: number, node: ProseMirrorNode}
      +// Returns a node of a given `nodeType` if it is selected. `start` points to the start position of the node, `pos` points directly before the node.
      +//
      +// ```javascript
      +// const { extension, inlineExtension, bodiedExtension } = schema.nodes;
      +// const selectedNode = findSelectedNodeOfType([
      +//   extension,
      +//   inlineExtension,
      +//   bodiedExtension,
      +// ])(selection);
      +// ```
      +var findSelectedNodeOfType = function findSelectedNodeOfType(nodeType) {
      +  return function (selection) {
      +    if (isNodeSelection(selection)) {
      +      var node = selection.node,
      +          $from = selection.$from;
      +
      +      if (equalNodeType(nodeType, node)) {
      +        return { node: node, pos: $from.pos, depth: $from.depth };
      +      }
      +    }
      +  };
      +};
      +
      +// :: (selection: Selection) → ?number
      +// Returns position of the previous node.
      +//
      +// ```javascript
      +// const pos = findPositionOfNodeBefore(tr.selection);
      +// ```
      +var findPositionOfNodeBefore = function findPositionOfNodeBefore(selection) {
      +  var nodeBefore = selection.$from.nodeBefore;
      +
      +  var maybeSelection = prosemirrorState.Selection.findFrom(selection.$from, -1);
      +  if (maybeSelection && nodeBefore) {
      +    // leaf node
      +    var parent = findParentNodeOfType(nodeBefore.type)(maybeSelection);
      +    if (parent) {
      +      return parent.pos;
      +    }
      +    return maybeSelection.$from.pos;
      +  }
      +};
      +
      +// :: (position: number, domAtPos: (pos: number) → {node: dom.Node, offset: number}) → dom.Node
      +// Returns DOM reference of a node at a given `position`. If the node type is of type `TEXT_NODE` it will return the reference of the parent node.
      +//
      +// ```javascript
      +// const domAtPos = view.domAtPos.bind(view);
      +// const ref = findDomRefAtPos($from.pos, domAtPos);
      +// ```
      +var findDomRefAtPos = function findDomRefAtPos(position, domAtPos) {
      +  var dom = domAtPos(position);
      +  var node = dom.node.childNodes[dom.offset];
      +
      +  if (dom.node.nodeType === Node.TEXT_NODE) {
      +    return dom.node.parentNode;
      +  }
      +
      +  if (!node || node.nodeType === Node.TEXT_NODE) {
      +    return dom.node;
      +  }
      +
      +  return node;
      +};
      +
      +// :: (node: ProseMirrorNode, descend: ?boolean) → [{ node: ProseMirrorNode, pos: number }]
      +// Flattens descendants of a given `node`. It doesn't descend into a node when descend argument is `false` (defaults to `true`).
      +//
      +// ```javascript
      +// const children = flatten(node);
      +// ```
      +var flatten = function flatten(node) {
      +  var descend = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
      +
      +  if (!node) {
      +    throw new Error('Invalid "node" parameter');
      +  }
      +  var result = [];
      +  node.descendants(function (child, pos) {
      +    result.push({ node: child, pos: pos });
      +    if (!descend) {
      +      return false;
      +    }
      +  });
      +  return result;
      +};
      +
      +// :: (node: ProseMirrorNode, predicate: (node: ProseMirrorNode) → boolean, descend: ?boolean) → [{ node: ProseMirrorNode, pos: number }]
      +// Iterates over descendants of a given `node`, returning child nodes predicate returns truthy for. It doesn't descend into a node when descend argument is `false` (defaults to `true`).
      +//
      +// ```javascript
      +// const textNodes = findChildren(node, child => child.isText, false);
      +// ```
      +var findChildren = function findChildren(node, predicate, descend) {
      +  if (!node) {
      +    throw new Error('Invalid "node" parameter');
      +  } else if (!predicate) {
      +    throw new Error('Invalid "predicate" parameter');
      +  }
      +  return flatten(node, descend).filter(function (child) {
      +    return predicate(child.node);
      +  });
      +};
      +
      +// :: (node: ProseMirrorNode, descend: ?boolean) → [{ node: ProseMirrorNode, pos: number }]
      +// Returns text nodes of a given `node`. It doesn't descend into a node when descend argument is `false` (defaults to `true`).
      +//
      +// ```javascript
      +// const textNodes = findTextNodes(node);
      +// ```
      +var findTextNodes = function findTextNodes(node, descend) {
      +  return findChildren(node, function (child) {
      +    return child.isText;
      +  }, descend);
      +};
      +
      +// :: (node: ProseMirrorNode, descend: ?boolean) → [{ node: ProseMirrorNode, pos: number }]
      +// Returns inline nodes of a given `node`. It doesn't descend into a node when descend argument is `false` (defaults to `true`).
      +//
      +// ```javascript
      +// const inlineNodes = findInlineNodes(node);
      +// ```
      +var findInlineNodes = function findInlineNodes(node, descend) {
      +  return findChildren(node, function (child) {
      +    return child.isInline;
      +  }, descend);
      +};
      +
      +// :: (node: ProseMirrorNode, descend: ?boolean) → [{ node: ProseMirrorNode, pos: number }]
      +// Returns block descendants of a given `node`. It doesn't descend into a node when descend argument is `false` (defaults to `true`).
      +//
      +// ```javascript
      +// const blockNodes = findBlockNodes(node);
      +// ```
      +var findBlockNodes = function findBlockNodes(node, descend) {
      +  return findChildren(node, function (child) {
      +    return child.isBlock;
      +  }, descend);
      +};
      +
      +// :: (node: ProseMirrorNode, predicate: (attrs: ?Object) → boolean, descend: ?boolean) → [{ node: ProseMirrorNode, pos: number }]
      +// Iterates over descendants of a given `node`, returning child nodes predicate returns truthy for. It doesn't descend into a node when descend argument is `false` (defaults to `true`).
      +//
      +// ```javascript
      +// const mergedCells = findChildrenByAttr(table, attrs => attrs.colspan === 2);
      +// ```
      +var findChildrenByAttr = function findChildrenByAttr(node, predicate, descend) {
      +  return findChildren(node, function (child) {
      +    return !!predicate(child.attrs);
      +  }, descend);
      +};
      +
      +// :: (node: ProseMirrorNode, nodeType: NodeType, descend: ?boolean) → [{ node: ProseMirrorNode, pos: number }]
      +// Iterates over descendants of a given `node`, returning child nodes of a given nodeType. It doesn't descend into a node when descend argument is `false` (defaults to `true`).
      +//
      +// ```javascript
      +// const cells = findChildrenByType(table, schema.nodes.tableCell);
      +// ```
      +var findChildrenByType = function findChildrenByType(node, nodeType, descend) {
      +  return findChildren(node, function (child) {
      +    return child.type === nodeType;
      +  }, descend);
      +};
      +
      +// :: (node: ProseMirrorNode, markType: markType, descend: ?boolean) → [{ node: ProseMirrorNode, pos: number }]
      +// Iterates over descendants of a given `node`, returning child nodes that have a mark of a given markType. It doesn't descend into a `node` when descend argument is `false` (defaults to `true`).
      +//
      +// ```javascript
      +// const nodes = findChildrenByMark(state.doc, schema.marks.strong);
      +// ```
      +var findChildrenByMark = function findChildrenByMark(node, markType, descend) {
      +  return findChildren(node, function (child) {
      +    return markType.isInSet(child.marks);
      +  }, descend);
      +};
      +
      +// :: (node: ProseMirrorNode, nodeType: NodeType) → boolean
      +// Returns `true` if a given node contains nodes of a given `nodeType`
      +//
      +// ```javascript
      +// if (contains(panel, schema.nodes.listItem)) {
      +//   // ...
      +// }
      +// ```
      +var contains = function contains(node, nodeType) {
      +  return !!findChildrenByType(node, nodeType).length;
      +};
      +
      +function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
      +
      +// :: (selection: Selection) → ?{pos: number, start: number, node: ProseMirrorNode}
      +// Iterates over parent nodes, returning the closest table node.
      +//
      +// ```javascript
      +// const table = findTable(selection);
      +// ```
      +var findTable = function findTable(selection) {
      +  return findParentNode(function (node) {
      +    return node.type.spec.tableRole && node.type.spec.tableRole === 'table';
      +  })(selection);
      +};
      +
      +// :: (selection: Selection) → boolean
      +// Checks if current selection is a `CellSelection`.
      +//
      +// ```javascript
      +// if (isCellSelection(selection)) {
      +//   // ...
      +// }
      +// ```
      +var isCellSelection = function isCellSelection(selection) {
      +  return selection instanceof prosemirrorTables.CellSelection;
      +};
      +
      +// :: (selection: Selection) → ?{left: number, right: number, top: number, bottom: number}
      +// Get the selection rectangle. Returns `undefined` if selection is not a CellSelection.
      +//
      +// ```javascript
      +// const rect = getSelectionRect(selection);
      +// ```
      +var getSelectionRect = function getSelectionRect(selection) {
      +  if (!isCellSelection(selection)) {
      +    return;
      +  }
      +  var start = selection.$anchorCell.start(-1);
      +  var map = prosemirrorTables.TableMap.get(selection.$anchorCell.node(-1));
      +  return map.rectBetween(selection.$anchorCell.pos - start, selection.$headCell.pos - start);
      +};
      +
      +// :: (columnIndex: number) → (selection: Selection) → boolean
      +// Checks if entire column at index `columnIndex` is selected.
      +//
      +// ```javascript
      +// const className = isColumnSelected(i)(selection) ? 'selected' : '';
      +// ```
      +var isColumnSelected = function isColumnSelected(columnIndex) {
      +  return function (selection) {
      +    if (isCellSelection(selection)) {
      +      var map = prosemirrorTables.TableMap.get(selection.$anchorCell.node(-1));
      +      return isRectSelected({
      +        left: columnIndex,
      +        right: columnIndex + 1,
      +        top: 0,
      +        bottom: map.height
      +      })(selection);
      +    }
      +
      +    return false;
      +  };
      +};
      +
      +// :: (rowIndex: number) → (selection: Selection) → boolean
      +// Checks if entire row at index `rowIndex` is selected.
      +//
      +// ```javascript
      +// const className = isRowSelected(i)(selection) ? 'selected' : '';
      +// ```
      +var isRowSelected = function isRowSelected(rowIndex) {
      +  return function (selection) {
      +    if (isCellSelection(selection)) {
      +      var map = prosemirrorTables.TableMap.get(selection.$anchorCell.node(-1));
      +      return isRectSelected({
      +        left: 0,
      +        right: map.width,
      +        top: rowIndex,
      +        bottom: rowIndex + 1
      +      })(selection);
      +    }
      +
      +    return false;
      +  };
      +};
      +
      +// :: (selection: Selection) → boolean
      +// Checks if entire table is selected
      +//
      +// ```javascript
      +// const className = isTableSelected(selection) ? 'selected' : '';
      +// ```
      +var isTableSelected = function isTableSelected(selection) {
      +  if (isCellSelection(selection)) {
      +    var map = prosemirrorTables.TableMap.get(selection.$anchorCell.node(-1));
      +    return isRectSelected({
      +      left: 0,
      +      right: map.width,
      +      top: 0,
      +      bottom: map.height
      +    })(selection);
      +  }
      +
      +  return false;
      +};
      +
      +// :: (columnIndex: union) → (selection: Selection) → ?[{pos: number, start: number, node: ProseMirrorNode}]
      +// Returns an array of cells in a column(s), where `columnIndex` could be a column index or an array of column indexes.
      +//
      +// ```javascript
      +// const cells = getCellsInColumn(i)(selection); // [{node, pos}, {node, pos}]
      +// ```
      +var getCellsInColumn = function getCellsInColumn(columnIndex) {
      +  return function (selection) {
      +    var table = findTable(selection);
      +    if (table) {
      +      var map = prosemirrorTables.TableMap.get(table.node);
      +      var indexes = Array.isArray(columnIndex) ? columnIndex : Array.from([columnIndex]);
      +      return indexes.reduce(function (acc, index) {
      +        if (index >= 0 && index <= map.width - 1) {
      +          var cells = map.cellsInRect({
      +            left: index,
      +            right: index + 1,
      +            top: 0,
      +            bottom: map.height
      +          });
      +          return acc.concat(cells.map(function (nodePos) {
      +            var node = table.node.nodeAt(nodePos);
      +            var pos = nodePos + table.start;
      +            return { pos: pos, start: pos + 1, node: node };
      +          }));
      +        }
      +      }, []);
      +    }
      +  };
      +};
      +
      +// :: (rowIndex: union) → (selection: Selection) → ?[{pos: number, start: number, node: ProseMirrorNode}]
      +// Returns an array of cells in a row(s), where `rowIndex` could be a row index or an array of row indexes.
      +//
      +// ```javascript
      +// const cells = getCellsInRow(i)(selection); // [{node, pos}, {node, pos}]
      +// ```
      +var getCellsInRow = function getCellsInRow(rowIndex) {
      +  return function (selection) {
      +    var table = findTable(selection);
      +    if (table) {
      +      var map = prosemirrorTables.TableMap.get(table.node);
      +      var indexes = Array.isArray(rowIndex) ? rowIndex : Array.from([rowIndex]);
      +      return indexes.reduce(function (acc, index) {
      +        if (index >= 0 && index <= map.height - 1) {
      +          var cells = map.cellsInRect({
      +            left: 0,
      +            right: map.width,
      +            top: index,
      +            bottom: index + 1
      +          });
      +          return acc.concat(cells.map(function (nodePos) {
      +            var node = table.node.nodeAt(nodePos);
      +            var pos = nodePos + table.start;
      +            return { pos: pos, start: pos + 1, node: node };
      +          }));
      +        }
      +      }, []);
      +    }
      +  };
      +};
      +
      +// :: (selection: Selection) → ?[{pos: number, start: number, node: ProseMirrorNode}]
      +// Returns an array of all cells in a table.
      +//
      +// ```javascript
      +// const cells = getCellsInTable(selection); // [{node, pos}, {node, pos}]
      +// ```
      +var getCellsInTable = function getCellsInTable(selection) {
      +  var table = findTable(selection);
      +  if (table) {
      +    var map = prosemirrorTables.TableMap.get(table.node);
      +    var cells = map.cellsInRect({
      +      left: 0,
      +      right: map.width,
      +      top: 0,
      +      bottom: map.height
      +    });
      +    return cells.map(function (nodePos) {
      +      var node = table.node.nodeAt(nodePos);
      +      var pos = nodePos + table.start;
      +      return { pos: pos, start: pos + 1, node: node };
      +    });
      +  }
      +};
      +
      +var select = function select(type) {
      +  return function (index, expand) {
      +    return function (tr) {
      +      var table = findTable(tr.selection);
      +      var isRowSelection = type === 'row';
      +      if (table) {
      +        var map = prosemirrorTables.TableMap.get(table.node);
      +
      +        // Check if the index is valid
      +        if (index >= 0 && index < (isRowSelection ? map.height : map.width)) {
      +          var left = isRowSelection ? 0 : index;
      +          var top = isRowSelection ? index : 0;
      +          var right = isRowSelection ? map.width : index + 1;
      +          var bottom = isRowSelection ? index + 1 : map.height;
      +
      +          if (expand) {
      +            var cell = findCellClosestToPos(tr.selection.$from);
      +            if (!cell) {
      +              return tr;
      +            }
      +
      +            var selRect = map.findCell(cell.pos - table.start);
      +            if (isRowSelection) {
      +              top = Math.min(top, selRect.top);
      +              bottom = Math.max(bottom, selRect.bottom);
      +            } else {
      +              left = Math.min(left, selRect.left);
      +              right = Math.max(right, selRect.right);
      +            }
      +          }
      +
      +          var cellsInFirstRow = map.cellsInRect({
      +            left: left,
      +            top: top,
      +            right: isRowSelection ? right : left + 1,
      +            bottom: isRowSelection ? top + 1 : bottom
      +          });
      +
      +          var cellsInLastRow = bottom - top === 1 ? cellsInFirstRow : map.cellsInRect({
      +            left: isRowSelection ? left : right - 1,
      +            top: isRowSelection ? bottom - 1 : top,
      +            right: right,
      +            bottom: bottom
      +          });
      +
      +          var head = table.start + cellsInFirstRow[0];
      +          var anchor = table.start + cellsInLastRow[cellsInLastRow.length - 1];
      +          var $head = tr.doc.resolve(head);
      +          var $anchor = tr.doc.resolve(anchor);
      +
      +          return cloneTr(tr.setSelection(new prosemirrorTables.CellSelection($anchor, $head)));
      +        }
      +      }
      +      return tr;
      +    };
      +  };
      +};
      +
      +// :: (columnIndex: number, expand: ?boolean) → (tr: Transaction) → Transaction
      +// Returns a new transaction that creates a `CellSelection` on a column at index `columnIndex`.
      +// Use the optional `expand` param to extend from current selection.
      +//
      +// ```javascript
      +// dispatch(
      +//   selectColumn(i)(state.tr)
      +// );
      +// ```
      +var selectColumn = select('column');
      +
      +// :: (rowIndex: number, expand: ?boolean) → (tr: Transaction) → Transaction
      +// Returns a new transaction that creates a `CellSelection` on a column at index `rowIndex`.
      +// Use the optional `expand` param to extend from current selection.
      +//
      +// ```javascript
      +// dispatch(
      +//   selectRow(i)(state.tr)
      +// );
      +// ```
      +var selectRow = select('row');
      +
      +// :: (selection: Selection) → (tr: Transaction) → Transaction
      +// Returns a new transaction that creates a `CellSelection` on the entire table.
      +//
      +// ```javascript
      +// dispatch(
      +//   selectTable(i)(state.tr)
      +// );
      +// ```
      +var selectTable = function selectTable(tr) {
      +  var table = findTable(tr.selection);
      +  if (table) {
      +    var _TableMap$get = prosemirrorTables.TableMap.get(table.node),
      +        map = _TableMap$get.map;
      +
      +    if (map && map.length) {
      +      var head = table.start + map[0];
      +      var anchor = table.start + map[map.length - 1];
      +      var $head = tr.doc.resolve(head);
      +      var $anchor = tr.doc.resolve(anchor);
      +
      +      return cloneTr(tr.setSelection(new prosemirrorTables.CellSelection($anchor, $head)));
      +    }
      +  }
      +  return tr;
      +};
      +
      +// :: (cell: {pos: number, node: ProseMirrorNode}, schema: Schema) → (tr: Transaction) → Transaction
      +// Returns a new transaction that clears the content of a given `cell`.
      +//
      +// ```javascript
      +// const $pos = state.doc.resolve(13);
      +// dispatch(
      +//   emptyCell(findCellClosestToPos($pos), state.schema)(state.tr)
      +// );
      +// ```
      +var emptyCell = function emptyCell(cell, schema) {
      +  return function (tr) {
      +    if (cell) {
      +      var _tableNodeTypes$cell$ = tableNodeTypes(schema).cell.createAndFill(),
      +          content = _tableNodeTypes$cell$.content;
      +
      +      if (!cell.node.content.eq(content)) {
      +        tr.replaceWith(cell.pos + 1, cell.pos + cell.node.nodeSize, content);
      +        return cloneTr(tr);
      +      }
      +    }
      +    return tr;
      +  };
      +};
      +
      +// :: (columnIndex: number) → (tr: Transaction) → Transaction
      +// Returns a new transaction that adds a new column at index `columnIndex`.
      +//
      +// ```javascript
      +// dispatch(
      +//   addColumnAt(i)(state.tr)
      +// );
      +// ```
      +var addColumnAt = function addColumnAt(columnIndex) {
      +  return function (tr) {
      +    var table = findTable(tr.selection);
      +    if (table) {
      +      var map = prosemirrorTables.TableMap.get(table.node);
      +      if (columnIndex >= 0 && columnIndex <= map.width) {
      +        return cloneTr(prosemirrorTables.addColumn(tr, {
      +          map: map,
      +          tableStart: table.start,
      +          table: table.node
      +        }, columnIndex));
      +      }
      +    }
      +    return tr;
      +  };
      +};
      +
      +// :: (originRowIndex: number, targetRowIndex: targetColumnIndex, options?: MovementOptions) → (tr: Transaction) → Transaction
      +// Returns a new transaction that moves the origin row to the target index;
      +//
      +// by default "tryToFit" is false, that means if you try to move a row to a place
      +// where we will need to split a row with merged cells it'll throw an exception, for example:
      +//
      +// ```
      +//      ____________________________
      +//     |      |      |             |
      +//  0  |  A1  |  B1  |     C1      |
      +//     |______|______|______ ______|
      +//     |      |             |      |
      +//  1  |  A2  |     B2      |      |
      +//     |______|______ ______|      |
      +//     |      |      |      |  D1  |
      +//  2  |  A3  |  B3  |  C2  |      |
      +//     |______|______|______|______|
      +// ```
      +//
      +// if you try to move the row 0 to the row index 1 with tryToFit false,
      +// it'll throw an exception since you can't split the row 1;
      +// but if "tryToFit" is true, it'll move the row using the current direction.
      +//
      +// We defined current direction using the target and origin values
      +// if the origin is greater than the target, that means the course is `bottom-to-top`,
      +// so the `tryToFit` logic will use this direction to determine
      +// if we should move the column to the right or the left.
      +//
      +// for example, if you call the function using `moveRow(0, 1, { tryToFit: true })`
      +// the result will be:
      +// ```
      +//      ____________________________
      +//     |      |             |      |
      +//  0  |  A2  |     B2      |      |
      +//     |______|______ ______|      |
      +//     |      |      |      |  D1  |
      +//  1  |  A3  |  B3  |  C2  |      |
      +//     |______|______|______|______|
      +//     |      |      |             |
      +//  2  |  A1  |  B1  |     C1      |
      +//     |______|______|______ ______|
      +// ```
      +//
      +// since we could put the row zero on index one,
      +// we pushed to the best place to fit the row index 0,
      +// in this case, row index 2.
      +//
      +//
      +// -------- HOW TO OVERRIDE DIRECTION --------
      +//
      +// If you set "tryToFit" to "true", it will try to figure out the best direction
      +// place to fit using the origin and target index, for example:
      +//
      +//
      +// ```
      +//      ____________________________
      +//     |      |      |             |
      +//  0  |  A1  |  B1  |     C1      |
      +//     |______|______|______ ______|
      +//     |      |             |      |
      +//  1  |  A2  |     B2      |      |
      +//     |______|______ ______|      |
      +//     |      |      |      |  D1  |
      +//  2  |  A3  |  B3  |  C2  |      |
      +//     |______|______|______|______|
      +//     |      |             |      |
      +//  3  |  A4  |     B4      |      |
      +//     |______|______ ______|      |
      +//     |      |      |      |  D2  |
      +//  4  |  A5  |  B5  |  C3  |      |
      +//     |______|______|______|______|
      +// ```
      +//
      +//
      +// If you try to move the row 0 to row index 4 with "tryToFit" enabled, by default,
      +// the code will put it on after the merged rows,
      +// but you can override it using the "direction" option.
      +//
      +// -1: Always put the origin before the target
      +// ```
      +//      ____________________________
      +//     |      |             |      |
      +//  0  |  A2  |     B2      |      |
      +//     |______|______ ______|      |
      +//     |      |      |      |  D1  |
      +//  1  |  A3  |  B3  |  C2  |      |
      +//     |______|______|______|______|
      +//     |      |      |             |
      +//  2  |  A1  |  B1  |     C1      |
      +//     |______|______|______ ______|
      +//     |      |             |      |
      +//  3  |  A4  |     B4      |      |
      +//     |______|______ ______|      |
      +//     |      |      |      |  D2  |
      +//  4  |  A5  |  B5  |  C3  |      |
      +//     |______|______|______|______|
      +// ```
      +//
      +//  0: Automatically decide the best place to fit
      +// ```
      +//      ____________________________
      +//     |      |             |      |
      +//  0  |  A2  |     B2      |      |
      +//     |______|______ ______|      |
      +//     |      |      |      |  D1  |
      +//  1  |  A3  |  B3  |  C2  |      |
      +//     |______|______|______|______|
      +//     |      |             |      |
      +//  2  |  A4  |     B4      |      |
      +//     |______|______ ______|      |
      +//     |      |      |      |  D2  |
      +//  3  |  A5  |  B5  |  C3  |      |
      +//     |______|______|______|______|
      +//     |      |      |             |
      +//  4  |  A1  |  B1  |     C1      |
      +//     |______|______|______ ______|
      +// ```
      +//
      +//  1: Always put the origin after the target
      +// ```
      +//      ____________________________
      +//     |      |             |      |
      +//  0  |  A2  |     B2      |      |
      +//     |______|______ ______|      |
      +//     |      |      |      |  D1  |
      +//  1  |  A3  |  B3  |  C2  |      |
      +//     |______|______|______|______|
      +//     |      |             |      |
      +//  2  |  A4  |     B4      |      |
      +//     |______|______ ______|      |
      +//     |      |      |      |  D2  |
      +//  3  |  A5  |  B5  |  C3  |      |
      +//     |______|______|______|______|
      +//     |      |      |             |
      +//  4  |  A1  |  B1  |     C1      |
      +//     |______|______|______ ______|
      +// ```
      +//
      +// ```javascript
      +// dispatch(
      +//   moveRow(x, y, options)(state.tr)
      +// );
      +// ```
      +var moveRow = function moveRow(originRowIndex, targetRowIndex, opts) {
      +  return function (tr) {
      +    var defaultOptions = { tryToFit: false, direction: 0 };
      +    var options = Object.assign(defaultOptions, opts);
      +    var table = findTable(tr.selection);
      +    if (!table) {
      +      return tr;
      +    }
      +
      +    var _getSelectionRangeInR = getSelectionRangeInRow(originRowIndex)(tr),
      +        indexesOriginRow = _getSelectionRangeInR.indexes;
      +
      +    var _getSelectionRangeInR2 = getSelectionRangeInRow(targetRowIndex)(tr),
      +        indexesTargetRow = _getSelectionRangeInR2.indexes;
      +
      +    if (indexesOriginRow.indexOf(targetRowIndex) > -1) {
      +      return tr;
      +    }
      +
      +    if (!options.tryToFit && indexesTargetRow.length > 1) {
      +      checkInvalidMovements(originRowIndex, targetRowIndex, indexesTargetRow, 'row');
      +    }
      +
      +    var newTable = moveTableRow(table, indexesOriginRow, indexesTargetRow, options.direction);
      +
      +    return cloneTr(tr).replaceWith(table.pos, table.pos + table.node.nodeSize, newTable);
      +  };
      +};
      +
      +// :: (originColumnIndex: number, targetColumnIndex: targetColumnIndex, options?: MovementOptions) → (tr: Transaction) → Transaction
      +// Returns a new transaction that moves the origin column to the target index;
      +//
      +// by default "tryToFit" is false, that means if you try to move a column to a place
      +// where we will need to split a column with merged cells it'll throw an exception, for example:
      +//
      +// ```
      +//    0      1         2
      +//  ____________________________
      +// |      |      |             |
      +// |  A1  |  B1  |     C1      |
      +// |______|______|______ ______|
      +// |      |             |      |
      +// |  A2  |     B2      |      |
      +// |______|______ ______|      |
      +// |      |      |      |  D1  |
      +// |  A3  |  B3  |  C2  |      |
      +// |______|______|______|______|
      +// ```
      +//
      +//
      +// if you try to move the column 0 to the column index 1 with tryToFit false,
      +// it'll throw an exception since you can't split the column 1;
      +// but if "tryToFit" is true, it'll move the column using the current direction.
      +//
      +// We defined current direction using the target and origin values
      +// if the origin is greater than the target, that means the course is `right-to-left`,
      +// so the `tryToFit` logic will use this direction to determine
      +// if we should move the column to the right or the left.
      +//
      +// for example, if you call the function using `moveColumn(0, 1, { tryToFit: true })`
      +// the result will be:
      +//
      +// ```
      +//    0       1             2
      +// _____________________ _______
      +// |      |             |      |
      +// |  B1  |     C1      |  A1  |
      +// |______|______ ______|______|
      +// |             |      |      |
      +// |     B2      |      |  A2  |
      +// |______ ______|      |______|
      +// |      |      |  D1  |      |
      +// |  B3  |  C2  |      |  A3  |
      +// |______|______|______|______|
      +// ```
      +//
      +// since we could put the column zero on index one,
      +// we pushed to the best place to fit the column 0, in this case, column index 2.
      +//
      +// -------- HOW TO OVERRIDE DIRECTION --------
      +//
      +// If you set "tryToFit" to "true", it will try to figure out the best direction
      +// place to fit using the origin and target index, for example:
      +//
      +//
      +// ```
      +//     0      1       2     3      4      5       6
      +//   _________________________________________________
      +//  |      |      |             |      |             |
      +//  |  A1  |  B1  |     C1      |  E1  |     F1      |
      +//  |______|______|______ ______|______|______ ______|
      +//  |      |             |      |             |      |
      +//  |  A2  |     B2      |      |     E2      |      |
      +//  |______|______ ______|      |______ ______|      |
      +//  |      |      |      |  D1  |      |      |  G2  |
      +//  |  A3  |  B3  |  C3  |      |  E3  |  F3  |      |
      +//  |______|______|______|______|______|______|______|
      +// ```
      +//
      +//
      +// If you try to move the column 0 to column index 5 with "tryToFit" enabled, by default,
      +// the code will put it on after the merged columns,
      +// but you can override it using the "direction" option.
      +//
      +// -1: Always put the origin before the target
      +//
      +// ```
      +//     0      1       2     3      4      5       6
      +//   _________________________________________________
      +//  |      |             |      |      |             |
      +//  |  B1  |     C1      |  A1  |  E1  |     F1      |
      +//  |______|______ ______|______|______|______ ______|
      +//  |             |      |      |             |      |
      +//  |     B2      |      |  A2  |     E2      |      |
      +//  |______ ______|      |______|______ ______|      |
      +//  |      |      |  D1  |      |      |      |  G2  |
      +//  |  B3  |  C3  |      |  A3  |  E3  |  F3  |      |
      +//  |______|______|______|______|______|______|______|
      +// ```
      +//
      +//  0: Automatically decide the best place to fit
      +//
      +// ```
      +//     0      1       2     3      4      5       6
      +//   _________________________________________________
      +//  |      |             |      |             |      |
      +//  |  B1  |     C1      |  E1  |     F1      |  A1  |
      +//  |______|______ ______|______|______ ______|______|
      +//  |             |      |             |      |      |
      +//  |     B2      |      |     E2      |      |  A2  |
      +//  |______ ______|      |______ ______|      |______|
      +//  |      |      |  D1  |      |      |  G2  |      |
      +//  |  B3  |  C3  |      |  E3  |  F3  |      |  A3  |
      +//  |______|______|______|______|______|______|______|
      +// ```
      +//
      +//  1: Always put the origin after the target
      +//
      +// ```
      +//     0      1       2     3      4      5       6
      +//   _________________________________________________
      +//  |      |             |      |             |      |
      +//  |  B1  |     C1      |  E1  |     F1      |  A1  |
      +//  |______|______ ______|______|______ ______|______|
      +//  |             |      |             |      |      |
      +//  |     B2      |      |     E2      |      |  A2  |
      +//  |______ ______|      |______ ______|      |______|
      +//  |      |      |  D1  |      |      |  G2  |      |
      +//  |  B3  |  C3  |      |  E3  |  F3  |      |  A3  |
      +//  |______|______|______|______|______|______|______|
      +// ```
      +//
      +// ```javascript
      +// dispatch(
      +//   moveColumn(x, y, options)(state.tr)
      +// );
      +// ```
      +var moveColumn = function moveColumn(originColumnIndex, targetColumnIndex, opts) {
      +  return function (tr) {
      +    var defaultOptions = { tryToFit: false, direction: 0 };
      +    var options = Object.assign(defaultOptions, opts);
      +    var table = findTable(tr.selection);
      +    if (!table) {
      +      return tr;
      +    }
      +
      +    var _getSelectionRangeInC = getSelectionRangeInColumn(originColumnIndex)(tr),
      +        indexesOriginColumn = _getSelectionRangeInC.indexes;
      +
      +    var _getSelectionRangeInC2 = getSelectionRangeInColumn(targetColumnIndex)(tr),
      +        indexesTargetColumn = _getSelectionRangeInC2.indexes;
      +
      +    if (indexesOriginColumn.indexOf(targetColumnIndex) > -1) {
      +      return tr;
      +    }
      +
      +    if (!options.tryToFit && indexesTargetColumn.length > 1) {
      +      checkInvalidMovements(originColumnIndex, targetColumnIndex, indexesTargetColumn, 'column');
      +    }
      +
      +    var newTable = moveTableColumn(table, indexesOriginColumn, indexesTargetColumn, options.direction);
      +
      +    return cloneTr(tr).replaceWith(table.pos, table.pos + table.node.nodeSize, newTable);
      +  };
      +};
      +
      +// :: (rowIndex: number, clonePreviousRow?: boolean) → (tr: Transaction) → Transaction
      +// Returns a new transaction that adds a new row at index `rowIndex`. Optionally clone the previous row.
      +//
      +// ```javascript
      +// dispatch(
      +//   addRowAt(i)(state.tr)
      +// );
      +// ```
      +//
      +// ```javascript
      +// dispatch(
      +//   addRowAt(i, true)(state.tr)
      +// );
      +// ```
      +var addRowAt = function addRowAt(rowIndex, clonePreviousRow) {
      +  return function (tr) {
      +    var table = findTable(tr.selection);
      +    if (table) {
      +      var map = prosemirrorTables.TableMap.get(table.node);
      +      var cloneRowIndex = rowIndex - 1;
      +
      +      if (clonePreviousRow && cloneRowIndex >= 0) {
      +        return cloneTr(cloneRowAt(cloneRowIndex)(tr));
      +      }
      +
      +      if (rowIndex >= 0 && rowIndex <= map.height) {
      +        return cloneTr(prosemirrorTables.addRow(tr, {
      +          map: map,
      +          tableStart: table.start,
      +          table: table.node
      +        }, rowIndex));
      +      }
      +    }
      +    return tr;
      +  };
      +};
      +
      +// :: (cloneRowIndex: number) → (tr: Transaction) → Transaction
      +// Returns a new transaction that adds a new row after `cloneRowIndex`, cloning the row attributes at `cloneRowIndex`.
      +//
      +// ```javascript
      +// dispatch(
      +//   cloneRowAt(i)(state.tr)
      +// );
      +// ```
      +var cloneRowAt = function cloneRowAt(rowIndex) {
      +  return function (tr) {
      +    var table = findTable(tr.selection);
      +    if (table) {
      +      var map = prosemirrorTables.TableMap.get(table.node);
      +
      +      if (rowIndex >= 0 && rowIndex <= map.height) {
      +        var tableNode = table.node;
      +        var tableNodes = tableNodeTypes(tableNode.type.schema);
      +
      +        var rowPos = table.start;
      +        for (var i = 0; i < rowIndex + 1; i++) {
      +          rowPos += tableNode.child(i).nodeSize;
      +        }
      +
      +        var cloneRow = tableNode.child(rowIndex);
      +        // Re-create the same nodes with same attrs, dropping the node content.
      +        var cells = [];
      +        var rowWidth = 0;
      +        cloneRow.forEach(function (cell) {
      +          // If we're copying a row with rowspan somewhere, we dont want to copy that cell
      +          // We'll increment its span below.
      +          if (cell.attrs.rowspan === 1) {
      +            rowWidth += cell.attrs.colspan;
      +            cells.push(tableNodes[cell.type.spec.tableRole].createAndFill(cell.attrs, cell.marks));
      +          }
      +        });
      +
      +        // If a higher row spans past our clone row, bump the higher row to cover this new row too.
      +        if (rowWidth < map.width) {
      +          var rowSpanCells = [];
      +
      +          var _loop = function _loop(_i) {
      +            var foundCells = filterCellsInRow(_i, function (cell, tr) {
      +              var rowspan = cell.node.attrs.rowspan;
      +              var spanRange = _i + rowspan;
      +              return rowspan > 1 && spanRange > rowIndex;
      +            })(tr);
      +            rowSpanCells.push.apply(rowSpanCells, _toConsumableArray(foundCells));
      +          };
      +
      +          for (var _i = rowIndex; _i >= 0; _i--) {
      +            _loop(_i);
      +          }
      +
      +          if (rowSpanCells.length) {
      +            rowSpanCells.forEach(function (cell) {
      +              tr = setCellAttrs(cell, {
      +                rowspan: cell.node.attrs.rowspan + 1
      +              })(tr);
      +            });
      +          }
      +        }
      +
      +        return safeInsert(tableNodes.row.create(cloneRow.attrs, cells), rowPos)(tr);
      +      }
      +    }
      +    return tr;
      +  };
      +};
      +
      +// :: (columnIndex: number) → (tr: Transaction) → Transaction
      +// Returns a new transaction that removes a column at index `columnIndex`. If there is only one column left, it will remove the entire table.
      +//
      +// ```javascript
      +// dispatch(
      +//   removeColumnAt(i)(state.tr)
      +// );
      +// ```
      +var removeColumnAt = function removeColumnAt(columnIndex) {
      +  return function (tr) {
      +    var table = findTable(tr.selection);
      +    if (table) {
      +      var map = prosemirrorTables.TableMap.get(table.node);
      +      if (columnIndex === 0 && map.width === 1) {
      +        return removeTable(tr);
      +      } else if (columnIndex >= 0 && columnIndex <= map.width) {
      +        prosemirrorTables.removeColumn(tr, {
      +          map: map,
      +          tableStart: table.start,
      +          table: table.node
      +        }, columnIndex);
      +        return cloneTr(tr);
      +      }
      +    }
      +    return tr;
      +  };
      +};
      +
      +// :: (rowIndex: number) → (tr: Transaction) → Transaction
      +// Returns a new transaction that removes a row at index `rowIndex`. If there is only one row left, it will remove the entire table.
      +//
      +// ```javascript
      +// dispatch(
      +//   removeRowAt(i)(state.tr)
      +// );
      +// ```
      +var removeRowAt = function removeRowAt(rowIndex) {
      +  return function (tr) {
      +    var table = findTable(tr.selection);
      +    if (table) {
      +      var map = prosemirrorTables.TableMap.get(table.node);
      +      if (rowIndex === 0 && map.height === 1) {
      +        return removeTable(tr);
      +      } else if (rowIndex >= 0 && rowIndex <= map.height) {
      +        prosemirrorTables.removeRow(tr, {
      +          map: map,
      +          tableStart: table.start,
      +          table: table.node
      +        }, rowIndex);
      +        return cloneTr(tr);
      +      }
      +    }
      +    return tr;
      +  };
      +};
      +
      +// :: (tr: Transaction) → Transaction
      +// Returns a new transaction that removes a table node if the cursor is inside of it.
      +//
      +// ```javascript
      +// dispatch(
      +//   removeTable(state.tr)
      +// );
      +// ```
      +var removeTable = function removeTable(tr) {
      +  var $from = tr.selection.$from;
      +
      +  for (var depth = $from.depth; depth > 0; depth--) {
      +    var node = $from.node(depth);
      +    if (node.type.spec.tableRole === 'table') {
      +      return cloneTr(tr.delete($from.before(depth), $from.after(depth)));
      +    }
      +  }
      +  return tr;
      +};
      +
      +// :: (tr: Transaction) → Transaction
      +// Returns a new transaction that removes selected columns.
      +//
      +// ```javascript
      +// dispatch(
      +//   removeSelectedColumns(state.tr)
      +// );
      +// ```
      +var removeSelectedColumns = function removeSelectedColumns(tr) {
      +  var selection = tr.selection;
      +
      +  if (isTableSelected(selection)) {
      +    return removeTable(tr);
      +  }
      +  if (isCellSelection(selection)) {
      +    var table = findTable(selection);
      +    if (table) {
      +      var map = prosemirrorTables.TableMap.get(table.node);
      +      var rect = map.rectBetween(selection.$anchorCell.pos - table.start, selection.$headCell.pos - table.start);
      +
      +      if (rect.left == 0 && rect.right == map.width) {
      +        return false;
      +      }
      +
      +      var pmTableRect = Object.assign({}, rect, {
      +        map: map,
      +        table: table.node,
      +        tableStart: table.start
      +      });
      +
      +      for (var i = pmTableRect.right - 1;; i--) {
      +        prosemirrorTables.removeColumn(tr, pmTableRect, i);
      +        if (i === pmTableRect.left) {
      +          break;
      +        }
      +        pmTableRect.table = pmTableRect.tableStart ? tr.doc.nodeAt(pmTableRect.tableStart - 1) : tr.doc;
      +        pmTableRect.map = prosemirrorTables.TableMap.get(pmTableRect.table);
      +      }
      +      return cloneTr(tr);
      +    }
      +  }
      +  return tr;
      +};
      +
      +// :: (tr: Transaction) → Transaction
      +// Returns a new transaction that removes selected rows.
      +//
      +// ```javascript
      +// dispatch(
      +//   removeSelectedRows(state.tr)
      +// );
      +// ```
      +var removeSelectedRows = function removeSelectedRows(tr) {
      +  var selection = tr.selection;
      +
      +  if (isTableSelected(selection)) {
      +    return removeTable(tr);
      +  }
      +  if (isCellSelection(selection)) {
      +    var table = findTable(selection);
      +    if (table) {
      +      var map = prosemirrorTables.TableMap.get(table.node);
      +      var rect = map.rectBetween(selection.$anchorCell.pos - table.start, selection.$headCell.pos - table.start);
      +
      +      if (rect.top == 0 && rect.bottom == map.height) {
      +        return false;
      +      }
      +
      +      var pmTableRect = Object.assign({}, rect, {
      +        map: map,
      +        table: table.node,
      +        tableStart: table.start
      +      });
      +
      +      for (var i = pmTableRect.bottom - 1;; i--) {
      +        prosemirrorTables.removeRow(tr, pmTableRect, i);
      +        if (i === pmTableRect.top) {
      +          break;
      +        }
      +        pmTableRect.table = pmTableRect.tableStart ? tr.doc.nodeAt(pmTableRect.tableStart - 1) : tr.doc;
      +        pmTableRect.map = prosemirrorTables.TableMap.get(pmTableRect.table);
      +      }
      +
      +      return cloneTr(tr);
      +    }
      +  }
      +  return tr;
      +};
      +
      +// :: ($pos: ResolvedPos) → (tr: Transaction) → Transaction
      +// Returns a new transaction that removes a column closest to a given `$pos`.
      +//
      +// ```javascript
      +// dispatch(
      +//   removeColumnClosestToPos(state.doc.resolve(3))(state.tr)
      +// );
      +// ```
      +var removeColumnClosestToPos = function removeColumnClosestToPos($pos) {
      +  return function (tr) {
      +    var rect = findCellRectClosestToPos($pos);
      +    if (rect) {
      +      return removeColumnAt(rect.left)(setTextSelection($pos.pos)(tr));
      +    }
      +    return tr;
      +  };
      +};
      +
      +// :: ($pos: ResolvedPos) → (tr: Transaction) → Transaction
      +// Returns a new transaction that removes a row closest to a given `$pos`.
      +//
      +// ```javascript
      +// dispatch(
      +//   removeRowClosestToPos(state.doc.resolve(3))(state.tr)
      +// );
      +// ```
      +var removeRowClosestToPos = function removeRowClosestToPos($pos) {
      +  return function (tr) {
      +    var rect = findCellRectClosestToPos($pos);
      +    if (rect) {
      +      return removeRowAt(rect.top)(setTextSelection($pos.pos)(tr));
      +    }
      +    return tr;
      +  };
      +};
      +
      +// :: (columnIndex: number, cellTransform: (cell: {pos: number, start: number, node: ProseMirrorNode}, tr: Transaction) → Transaction, setCursorToLastCell: ?boolean) → (tr: Transaction) → Transaction
      +// Returns a new transaction that maps a given `cellTransform` function to each cell in a column at a given `columnIndex`.
      +// It will set the selection into the last cell of the column if `setCursorToLastCell` param is set to `true`.
      +//
      +// ```javascript
      +// dispatch(
      +//   forEachCellInColumn(0, (cell, tr) => emptyCell(cell, state.schema)(tr))(state.tr)
      +// );
      +// ```
      +var forEachCellInColumn = function forEachCellInColumn(columnIndex, cellTransform, setCursorToLastCell) {
      +  return function (tr) {
      +    var cells = getCellsInColumn(columnIndex)(tr.selection);
      +    if (cells) {
      +      for (var i = cells.length - 1; i >= 0; i--) {
      +        tr = cellTransform(cells[i], tr);
      +      }
      +      if (setCursorToLastCell) {
      +        var $pos = tr.doc.resolve(tr.mapping.map(cells[cells.length - 1].pos));
      +        tr.setSelection(prosemirrorState.Selection.near($pos));
      +      }
      +      return cloneTr(tr);
      +    }
      +    return tr;
      +  };
      +};
      +
      +// :: (rowIndex: number, cellTransform: (cell: {pos: number, start: number, node: ProseMirrorNode}, tr: Transaction) → Transaction, setCursorToLastCell: ?boolean) → (tr: Transaction) → Transaction
      +// Returns a new transaction that maps a given `cellTransform` function to each cell in a row at a given `rowIndex`.
      +// It will set the selection into the last cell of the row if `setCursorToLastCell` param is set to `true`.
      +//
      +// ```javascript
      +// dispatch(
      +//   forEachCellInRow(0, (cell, tr) => setCellAttrs(cell, { background: 'red' })(tr))(state.tr)
      +// );
      +// ```
      +var forEachCellInRow = function forEachCellInRow(rowIndex, cellTransform, setCursorToLastCell) {
      +  return function (tr) {
      +    var cells = getCellsInRow(rowIndex)(tr.selection);
      +    if (cells) {
      +      for (var i = cells.length - 1; i >= 0; i--) {
      +        tr = cellTransform(cells[i], tr);
      +      }
      +      if (setCursorToLastCell) {
      +        var $pos = tr.doc.resolve(tr.mapping.map(cells[cells.length - 1].pos));
      +        tr.setSelection(prosemirrorState.Selection.near($pos));
      +      }
      +    }
      +    return tr;
      +  };
      +};
      +
      +// :: (cell: {pos: number, start: number, node: ProseMirrorNode}, attrs: Object) → (tr: Transaction) → Transaction
      +// Returns a new transaction that sets given `attrs` to a given `cell`.
      +//
      +// ```javascript
      +// dispatch(
      +//   setCellAttrs(findCellClosestToPos($pos), { background: 'blue' })(tr);
      +// );
      +// ```
      +var setCellAttrs = function setCellAttrs(cell, attrs) {
      +  return function (tr) {
      +    if (cell) {
      +      tr.setNodeMarkup(cell.pos, null, Object.assign({}, cell.node.attrs, attrs));
      +      return cloneTr(tr);
      +    }
      +    return tr;
      +  };
      +};
      +
      +// :: (schema: Schema, rowsCount: ?number, colsCount: ?number, withHeaderRow: ?boolean, cellContent: ?Node) → Node
      +// Returns a table node of a given size.
      +// `withHeaderRow` defines whether the first row of the table will be a header row.
      +// `cellContent` defines the content of each cell.
      +//
      +// ```javascript
      +// const table = createTable(state.schema); // 3x3 table node
      +// dispatch(
      +//   tr.replaceSelectionWith(table).scrollIntoView()
      +// );
      +// ```
      +var createTable = function createTable(schema) {
      +  var rowsCount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
      +  var colsCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 3;
      +  var withHeaderRow = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
      +  var cellContent = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
      +
      +  var _tableNodeTypes = tableNodeTypes(schema),
      +      tableCell = _tableNodeTypes.cell,
      +      tableHeader = _tableNodeTypes.header_cell,
      +      tableRow = _tableNodeTypes.row,
      +      table = _tableNodeTypes.table;
      +
      +  var cells = [];
      +  var headerCells = [];
      +  for (var i = 0; i < colsCount; i++) {
      +    cells.push(createCell(tableCell, cellContent));
      +
      +    if (withHeaderRow) {
      +      headerCells.push(createCell(tableHeader, cellContent));
      +    }
      +  }
      +
      +  var rows = [];
      +  for (var _i2 = 0; _i2 < rowsCount; _i2++) {
      +    rows.push(tableRow.createChecked(null, withHeaderRow && _i2 === 0 ? headerCells : cells));
      +  }
      +
      +  return table.createChecked(null, rows);
      +};
      +
      +// :: ($pos: ResolvedPos) → ?{pos: number, start: number, node: ProseMirrorNode}
      +// Iterates over parent nodes, returning a table cell or a table header node closest to a given `$pos`.
      +//
      +// ```javascript
      +// const cell = findCellClosestToPos(state.selection.$from);
      +// ```
      +var findCellClosestToPos = function findCellClosestToPos($pos) {
      +  var predicate = function predicate(node) {
      +    return node.type.spec.tableRole && /cell/i.test(node.type.spec.tableRole);
      +  };
      +  return findParentNodeClosestToPos($pos, predicate);
      +};
      +
      +// :: ($pos: ResolvedPos) → ?{left: number, top: number, right: number, bottom: number}
      +// Returns the rectangle spanning a cell closest to a given `$pos`.
      +//
      +// ```javascript
      +// dispatch(
      +//   findCellRectClosestToPos(state.selection.$from)
      +// );
      +// ```
      +var findCellRectClosestToPos = function findCellRectClosestToPos($pos) {
      +  var cell = findCellClosestToPos($pos);
      +  if (cell) {
      +    var table = findTableClosestToPos($pos);
      +    var map = prosemirrorTables.TableMap.get(table.node);
      +    var cellPos = cell.pos - table.start;
      +    return map.rectBetween(cellPos, cellPos);
      +  }
      +};
      +
      +var filterCellsInRow = function filterCellsInRow(rowIndex, predicate) {
      +  return function (tr) {
      +    var foundCells = [];
      +    var cells = getCellsInRow(rowIndex)(tr.selection);
      +    if (cells) {
      +      for (var j = cells.length - 1; j >= 0; j--) {
      +        if (predicate(cells[j], tr)) {
      +          foundCells.push(cells[j]);
      +        }
      +      }
      +    }
      +
      +    return foundCells;
      +  };
      +};
      +
      +// :: (columnIndex: number) → (tr: Transaction) → {$anchor: ResolvedPos, $head: ResolvedPos, indexes: [number]}
      +// Returns a range of rectangular selection spanning all merged cells around a column at index `columnIndex`.
      +//
      +// ```javascript
      +// const range = getSelectionRangeInColumn(3)(state.tr);
      +// ```
      +var getSelectionRangeInColumn = function getSelectionRangeInColumn(columnIndex) {
      +  return function (tr) {
      +    var startIndex = columnIndex;
      +    var endIndex = columnIndex;
      +
      +    // looking for selection start column (startIndex)
      +
      +    var _loop2 = function _loop2(i) {
      +      var cells = getCellsInColumn(i)(tr.selection);
      +      if (cells) {
      +        cells.forEach(function (cell) {
      +          var maybeEndIndex = cell.node.attrs.colspan + i - 1;
      +          if (maybeEndIndex >= startIndex) {
      +            startIndex = i;
      +          }
      +          if (maybeEndIndex > endIndex) {
      +            endIndex = maybeEndIndex;
      +          }
      +        });
      +      }
      +    };
      +
      +    for (var i = columnIndex; i >= 0; i--) {
      +      _loop2(i);
      +    }
      +    // looking for selection end column (endIndex)
      +
      +    var _loop3 = function _loop3(i) {
      +      var cells = getCellsInColumn(i)(tr.selection);
      +      if (cells) {
      +        cells.forEach(function (cell) {
      +          var maybeEndIndex = cell.node.attrs.colspan + i - 1;
      +          if (cell.node.attrs.colspan > 1 && maybeEndIndex > endIndex) {
      +            endIndex = maybeEndIndex;
      +          }
      +        });
      +      }
      +    };
      +
      +    for (var i = columnIndex; i <= endIndex; i++) {
      +      _loop3(i);
      +    }
      +
      +    // filter out columns without cells (where all rows have colspan > 1 in the same column)
      +    var indexes = [];
      +    for (var i = startIndex; i <= endIndex; i++) {
      +      var maybeCells = getCellsInColumn(i)(tr.selection);
      +      if (maybeCells && maybeCells.length) {
      +        indexes.push(i);
      +      }
      +    }
      +    startIndex = indexes[0];
      +    endIndex = indexes[indexes.length - 1];
      +
      +    var firstSelectedColumnCells = getCellsInColumn(startIndex)(tr.selection);
      +    var firstRowCells = getCellsInRow(0)(tr.selection);
      +    var $anchor = tr.doc.resolve(firstSelectedColumnCells[firstSelectedColumnCells.length - 1].pos);
      +
      +    var headCell = void 0;
      +    for (var _i3 = endIndex; _i3 >= startIndex; _i3--) {
      +      var columnCells = getCellsInColumn(_i3)(tr.selection);
      +      if (columnCells && columnCells.length) {
      +        for (var j = firstRowCells.length - 1; j >= 0; j--) {
      +          if (firstRowCells[j].pos === columnCells[0].pos) {
      +            headCell = columnCells[0];
      +            break;
      +          }
      +        }
      +        if (headCell) {
      +          break;
      +        }
      +      }
      +    }
      +
      +    var $head = tr.doc.resolve(headCell.pos);
      +    return { $anchor: $anchor, $head: $head, indexes: indexes };
      +  };
      +};
      +
      +// :: (rowIndex: number) → (tr: Transaction) → {$anchor: ResolvedPos, $head: ResolvedPos, indexes: [number]}
      +// Returns a range of rectangular selection spanning all merged cells around a row at index `rowIndex`.
      +//
      +// ```javascript
      +// const range = getSelectionRangeInRow(3)(state.tr);
      +// ```
      +var getSelectionRangeInRow = function getSelectionRangeInRow(rowIndex) {
      +  return function (tr) {
      +    var startIndex = rowIndex;
      +    var endIndex = rowIndex;
      +    // looking for selection start row (startIndex)
      +
      +    var _loop4 = function _loop4(i) {
      +      var cells = getCellsInRow(i)(tr.selection);
      +      cells.forEach(function (cell) {
      +        var maybeEndIndex = cell.node.attrs.rowspan + i - 1;
      +        if (maybeEndIndex >= startIndex) {
      +          startIndex = i;
      +        }
      +        if (maybeEndIndex > endIndex) {
      +          endIndex = maybeEndIndex;
      +        }
      +      });
      +    };
      +
      +    for (var i = rowIndex; i >= 0; i--) {
      +      _loop4(i);
      +    }
      +    // looking for selection end row (endIndex)
      +
      +    var _loop5 = function _loop5(i) {
      +      var cells = getCellsInRow(i)(tr.selection);
      +      cells.forEach(function (cell) {
      +        var maybeEndIndex = cell.node.attrs.rowspan + i - 1;
      +        if (cell.node.attrs.rowspan > 1 && maybeEndIndex > endIndex) {
      +          endIndex = maybeEndIndex;
      +        }
      +      });
      +    };
      +
      +    for (var i = rowIndex; i <= endIndex; i++) {
      +      _loop5(i);
      +    }
      +
      +    // filter out rows without cells (where all columns have rowspan > 1 in the same row)
      +    var indexes = [];
      +    for (var i = startIndex; i <= endIndex; i++) {
      +      var maybeCells = getCellsInRow(i)(tr.selection);
      +      if (maybeCells && maybeCells.length) {
      +        indexes.push(i);
      +      }
      +    }
      +    startIndex = indexes[0];
      +    endIndex = indexes[indexes.length - 1];
      +
      +    var firstSelectedRowCells = getCellsInRow(startIndex)(tr.selection);
      +    var firstColumnCells = getCellsInColumn(0)(tr.selection);
      +    var $anchor = tr.doc.resolve(firstSelectedRowCells[firstSelectedRowCells.length - 1].pos);
      +
      +    var headCell = void 0;
      +    for (var _i4 = endIndex; _i4 >= startIndex; _i4--) {
      +      var rowCells = getCellsInRow(_i4)(tr.selection);
      +      if (rowCells && rowCells.length) {
      +        for (var j = firstColumnCells.length - 1; j >= 0; j--) {
      +          if (firstColumnCells[j].pos === rowCells[0].pos) {
      +            headCell = rowCells[0];
      +            break;
      +          }
      +        }
      +        if (headCell) {
      +          break;
      +        }
      +      }
      +    }
      +
      +    var $head = tr.doc.resolve(headCell.pos);
      +    return { $anchor: $anchor, $head: $head, indexes: indexes };
      +  };
      +};
      +
      +exports.isNodeSelection = isNodeSelection;
      +exports.canInsert = canInsert;
      +exports.convertTableNodeToArrayOfRows = convertTableNodeToArrayOfRows;
      +exports.convertArrayOfRowsToTableNode = convertArrayOfRowsToTableNode;
      +exports.findParentNode = findParentNode;
      +exports.findParentNodeClosestToPos = findParentNodeClosestToPos;
      +exports.findParentDomRef = findParentDomRef;
      +exports.hasParentNode = hasParentNode;
      +exports.findParentNodeOfType = findParentNodeOfType;
      +exports.findParentNodeOfTypeClosestToPos = findParentNodeOfTypeClosestToPos;
      +exports.hasParentNodeOfType = hasParentNodeOfType;
      +exports.findParentDomRefOfType = findParentDomRefOfType;
      +exports.findSelectedNodeOfType = findSelectedNodeOfType;
      +exports.findPositionOfNodeBefore = findPositionOfNodeBefore;
      +exports.findDomRefAtPos = findDomRefAtPos;
      +exports.flatten = flatten;
      +exports.findChildren = findChildren;
      +exports.findTextNodes = findTextNodes;
      +exports.findInlineNodes = findInlineNodes;
      +exports.findBlockNodes = findBlockNodes;
      +exports.findChildrenByAttr = findChildrenByAttr;
      +exports.findChildrenByType = findChildrenByType;
      +exports.findChildrenByMark = findChildrenByMark;
      +exports.contains = contains;
      +exports.findTable = findTable;
      +exports.isCellSelection = isCellSelection;
      +exports.getSelectionRect = getSelectionRect;
      +exports.isColumnSelected = isColumnSelected;
      +exports.isRowSelected = isRowSelected;
      +exports.isTableSelected = isTableSelected;
      +exports.getCellsInColumn = getCellsInColumn;
      +exports.getCellsInRow = getCellsInRow;
      +exports.getCellsInTable = getCellsInTable;
      +exports.selectColumn = selectColumn;
      +exports.selectRow = selectRow;
      +exports.selectTable = selectTable;
      +exports.emptyCell = emptyCell;
      +exports.addColumnAt = addColumnAt;
      +exports.moveRow = moveRow;
      +exports.moveColumn = moveColumn;
      +exports.addRowAt = addRowAt;
      +exports.cloneRowAt = cloneRowAt;
      +exports.removeColumnAt = removeColumnAt;
      +exports.removeRowAt = removeRowAt;
      +exports.removeTable = removeTable;
      +exports.removeSelectedColumns = removeSelectedColumns;
      +exports.removeSelectedRows = removeSelectedRows;
      +exports.removeColumnClosestToPos = removeColumnClosestToPos;
      +exports.removeRowClosestToPos = removeRowClosestToPos;
      +exports.forEachCellInColumn = forEachCellInColumn;
      +exports.forEachCellInRow = forEachCellInRow;
      +exports.setCellAttrs = setCellAttrs;
      +exports.createTable = createTable;
      +exports.findCellClosestToPos = findCellClosestToPos;
      +exports.findCellRectClosestToPos = findCellRectClosestToPos;
      +exports.getSelectionRangeInColumn = getSelectionRangeInColumn;
      +exports.getSelectionRangeInRow = getSelectionRangeInRow;
      +exports.removeParentNodeOfType = removeParentNodeOfType;
      +exports.replaceParentNodeOfType = replaceParentNodeOfType;
      +exports.removeSelectedNode = removeSelectedNode;
      +exports.replaceSelectedNode = replaceSelectedNode;
      +exports.setTextSelection = setTextSelection;
      +exports.safeInsert = safeInsert;
      +exports.setParentNodeMarkup = setParentNodeMarkup;
      +exports.selectParentNodeOfType = selectParentNodeOfType;
      +exports.removeNodeBefore = removeNodeBefore;
      +//# sourceMappingURL=index.js.map
      +
      +
      +/***/ }),
      +
      +/***/ "./node_modules/prosemirror-view/dist/index.es.js":
      +/*!********************************************************!*\
      +  !*** ./node_modules/prosemirror-view/dist/index.es.js ***!
      +  \********************************************************/
      +/*! exports provided: Decoration, DecorationSet, EditorView, __endComposition, __parseFromClipboard, __serializeForClipboard */
      +/***/ (function(module, __webpack_exports__, __webpack_require__) {
      +
      +"use strict";
      +__webpack_require__.r(__webpack_exports__);
      +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Decoration", function() { return Decoration; });
      +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DecorationSet", function() { return DecorationSet; });
      +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EditorView", function() { return EditorView; });
      +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__endComposition", function() { return endComposition; });
      +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__parseFromClipboard", function() { return parseFromClipboard; });
      +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__serializeForClipboard", function() { return serializeForClipboard; });
      +/* harmony import */ var prosemirror_state__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! prosemirror-state */ "./node_modules/prosemirror-state/dist/index.es.js");
      +/* harmony import */ var prosemirror_model__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! prosemirror-model */ "./node_modules/prosemirror-model/dist/index.es.js");
      +/* harmony import */ var prosemirror_transform__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! prosemirror-transform */ "./node_modules/prosemirror-transform/dist/index.es.js");
      +
      +
      +
      +
      +var result = {};
      +
      +if (typeof navigator != "undefined" && typeof document != "undefined") {
      +  var ie_edge = /Edge\/(\d+)/.exec(navigator.userAgent);
      +  var ie_upto10 = /MSIE \d/.test(navigator.userAgent);
      +  var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);
      +
      +  result.mac = /Mac/.test(navigator.platform);
      +  var ie = result.ie = !!(ie_upto10 || ie_11up || ie_edge);
      +  result.ie_version = ie_upto10 ? document.documentMode || 6 : ie_11up ? +ie_11up[1] : ie_edge ? +ie_edge[1] : null;
      +  result.gecko = !ie && /gecko\/(\d+)/i.test(navigator.userAgent);
      +  result.gecko_version = result.gecko && +(/Firefox\/(\d+)/.exec(navigator.userAgent) || [0, 0])[1];
      +  var chrome = !ie && /Chrome\/(\d+)/.exec(navigator.userAgent);
      +  result.chrome = !!chrome;
      +  result.chrome_version = chrome && +chrome[1];
      +  result.ios = !ie && /AppleWebKit/.test(navigator.userAgent) && /Mobile\/\w+/.test(navigator.userAgent);
      +  result.android = /Android \d/.test(navigator.userAgent);
      +  result.webkit = !ie && 'WebkitAppearance' in document.documentElement.style;
      +  result.safari = /Apple Computer/.test(navigator.vendor);
      +  result.webkit_version = result.webkit && +(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent) || [0, 0])[1];
      +}
      +
      +var domIndex = function(node) {
      +  for (var index = 0;; index++) {
      +    node = node.previousSibling;
      +    if (!node) { return index }
      +  }
      +};
      +
      +var parentNode = function(node) {
      +  var parent = node.parentNode;
      +  return parent && parent.nodeType == 11 ? parent.host : parent
      +};
      +
      +var textRange = function(node, from, to) {
      +  var range = document.createRange();
      +  range.setEnd(node, to == null ? node.nodeValue.length : to);
      +  range.setStart(node, from || 0);
      +  return range
      +};
      +
      +// Scans forward and backward through DOM positions equivalent to the
      +// given one to see if the two are in the same place (i.e. after a
      +// text node vs at the end of that text node)
      +var isEquivalentPosition = function(node, off, targetNode, targetOff) {
      +  return targetNode && (scanFor(node, off, targetNode, targetOff, -1) ||
      +                        scanFor(node, off, targetNode, targetOff, 1))
      +};
      +
      +var atomElements = /^(img|br|input|textarea|hr)$/i;
      +
      +function scanFor(node, off, targetNode, targetOff, dir) {
      +  for (;;) {
      +    if (node == targetNode && off == targetOff) { return true }
      +    if (off == (dir < 0 ? 0 : nodeSize(node))) {
      +      var parent = node.parentNode;
      +      if (parent.nodeType != 1 || hasBlockDesc(node) || atomElements.test(node.nodeName) || node.contentEditable == "false")
      +        { return false }
      +      off = domIndex(node) + (dir < 0 ? 0 : 1);
      +      node = parent;
      +    } else if (node.nodeType == 1) {
      +      node = node.childNodes[off + (dir < 0 ? -1 : 0)];
      +      off = dir < 0 ? nodeSize(node) : 0;
      +    } else {
      +      return false
      +    }
      +  }
      +}
      +
      +function nodeSize(node) {
      +  return node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length
      +}
      +
      +function hasBlockDesc(dom) {
      +  var desc;
      +  for (var cur = dom; cur; cur = cur.parentNode) { if (desc = cur.pmViewDesc) { break } }
      +  return desc && desc.node && desc.node.isBlock && (desc.dom == dom || desc.contentDOM == dom)
      +}
      +
      +// Work around Chrome issue https://bugs.chromium.org/p/chromium/issues/detail?id=447523
      +// (isCollapsed inappropriately returns true in shadow dom)
      +var selectionCollapsed = function(domSel) {
      +  var collapsed = domSel.isCollapsed;
      +  if (collapsed && result.chrome && domSel.rangeCount && !domSel.getRangeAt(0).collapsed)
      +    { collapsed = false; }
      +  return collapsed
      +};
      +
      +function keyEvent(keyCode, key) {
      +  var event = document.createEvent("Event");
      +  event.initEvent("keydown", true, true);
      +  event.keyCode = keyCode;
      +  event.key = event.code = key;
      +  return event
      +}
      +
      +function windowRect(win) {
      +  return {left: 0, right: win.innerWidth,
      +          top: 0, bottom: win.innerHeight}
      +}
      +
      +function getSide(value, side) {
      +  return typeof value == "number" ? value : value[side]
      +}
      +
      +function scrollRectIntoView(view, rect, startDOM) {
      +  var scrollThreshold = view.someProp("scrollThreshold") || 0, scrollMargin = view.someProp("scrollMargin") || 5;
      +  var doc = view.dom.ownerDocument, win = doc.defaultView;
      +  for (var parent = startDOM || view.dom;; parent = parentNode(parent)) {
      +    if (!parent) { break }
      +    if (parent.nodeType != 1) { continue }
      +    var atTop = parent == doc.body || parent.nodeType != 1;
      +    var bounding = atTop ? windowRect(win) : parent.getBoundingClientRect();
      +    var moveX = 0, moveY = 0;
      +    if (rect.top < bounding.top + getSide(scrollThreshold, "top"))
      +      { moveY = -(bounding.top - rect.top + getSide(scrollMargin, "top")); }
      +    else if (rect.bottom > bounding.bottom - getSide(scrollThreshold, "bottom"))
      +      { moveY = rect.bottom - bounding.bottom + getSide(scrollMargin, "bottom"); }
      +    if (rect.left < bounding.left + getSide(scrollThreshold, "left"))
      +      { moveX = -(bounding.left - rect.left + getSide(scrollMargin, "left")); }
      +    else if (rect.right > bounding.right - getSide(scrollThreshold, "right"))
      +      { moveX = rect.right - bounding.right + getSide(scrollMargin, "right"); }
      +    if (moveX || moveY) {
      +      if (atTop) {
      +        win.scrollBy(moveX, moveY);
      +      } else {
      +        if (moveY) { parent.scrollTop += moveY; }
      +        if (moveX) { parent.scrollLeft += moveX; }
      +      }
      +    }
      +    if (atTop) { break }
      +  }
      +}
      +
      +// Store the scroll position of the editor's parent nodes, along with
      +// the top position of an element near the top of the editor, which
      +// will be used to make sure the visible viewport remains stable even
      +// when the size of the content above changes.
      +function storeScrollPos(view) {
      +  var rect = view.dom.getBoundingClientRect(), startY = Math.max(0, rect.top);
      +  var refDOM, refTop;
      +  for (var x = (rect.left + rect.right) / 2, y = startY + 1;
      +       y < Math.min(innerHeight, rect.bottom); y += 5) {
      +    var dom = view.root.elementFromPoint(x, y);
      +    if (dom == view.dom || !view.dom.contains(dom)) { continue }
      +    var localRect = dom.getBoundingClientRect();
      +    if (localRect.top >= startY - 20) {
      +      refDOM = dom;
      +      refTop = localRect.top;
      +      break
      +    }
      +  }
      +  return {refDOM: refDOM, refTop: refTop, stack: scrollStack(view.dom)}
      +}
      +
      +function scrollStack(dom) {
      +  var stack = [], doc = dom.ownerDocument;
      +  for (; dom; dom = parentNode(dom)) {
      +    stack.push({dom: dom, top: dom.scrollTop, left: dom.scrollLeft});
      +    if (dom == doc) { break }
      +  }
      +  return stack
      +}
      +
      +// Reset the scroll position of the editor's parent nodes to that what
      +// it was before, when storeScrollPos was called.
      +function resetScrollPos(ref) {
      +  var refDOM = ref.refDOM;
      +  var refTop = ref.refTop;
      +  var stack = ref.stack;
      +
      +  var newRefTop = refDOM ? refDOM.getBoundingClientRect().top : 0;
      +  restoreScrollStack(stack, newRefTop == 0 ? 0 : newRefTop - refTop);
      +}
      +
      +function restoreScrollStack(stack, dTop) {
      +  for (var i = 0; i < stack.length; i++) {
      +    var ref = stack[i];
      +    var dom = ref.dom;
      +    var top = ref.top;
      +    var left = ref.left;
      +    if (dom.scrollTop != top + dTop) { dom.scrollTop = top + dTop; }
      +    if (dom.scrollLeft != left) { dom.scrollLeft = left; }
      +  }
      +}
      +
      +var preventScrollSupported = null;
      +// Feature-detects support for .focus({preventScroll: true}), and uses
      +// a fallback kludge when not supported.
      +function focusPreventScroll(dom) {
      +  if (dom.setActive) { return dom.setActive() } // in IE
      +  if (preventScrollSupported) { return dom.focus(preventScrollSupported) }
      +
      +  var stored = scrollStack(dom);
      +  dom.focus(preventScrollSupported == null ? {
      +    get preventScroll() {
      +      preventScrollSupported = {preventScroll: true};
      +      return true
      +    }
      +  } : undefined);
      +  if (!preventScrollSupported) {
      +    preventScrollSupported = false;
      +    restoreScrollStack(stored, 0);
      +  }
      +}
      +
      +function findOffsetInNode(node, coords) {
      +  var closest, dxClosest = 2e8, coordsClosest, offset = 0;
      +  var rowBot = coords.top, rowTop = coords.top;
      +  for (var child = node.firstChild, childIndex = 0; child; child = child.nextSibling, childIndex++) {
      +    var rects = (void 0);
      +    if (child.nodeType == 1) { rects = child.getClientRects(); }
      +    else if (child.nodeType == 3) { rects = textRange(child).getClientRects(); }
      +    else { continue }
      +
      +    for (var i = 0; i < rects.length; i++) {
      +      var rect = rects[i];
      +      if (rect.top <= rowBot && rect.bottom >= rowTop) {
      +        rowBot = Math.max(rect.bottom, rowBot);
      +        rowTop = Math.min(rect.top, rowTop);
      +        var dx = rect.left > coords.left ? rect.left - coords.left
      +            : rect.right < coords.left ? coords.left - rect.right : 0;
      +        if (dx < dxClosest) {
      +          closest = child;
      +          dxClosest = dx;
      +          coordsClosest = dx && closest.nodeType == 3 ? {left: rect.right < coords.left ? rect.right : rect.left, top: coords.top} : coords;
      +          if (child.nodeType == 1 && dx)
      +            { offset = childIndex + (coords.left >= (rect.left + rect.right) / 2 ? 1 : 0); }
      +          continue
      +        }
      +      }
      +      if (!closest && (coords.left >= rect.right && coords.top >= rect.top ||
      +                       coords.left >= rect.left && coords.top >= rect.bottom))
      +        { offset = childIndex + 1; }
      +    }
      +  }
      +  if (closest && closest.nodeType == 3) { return findOffsetInText(closest, coordsClosest) }
      +  if (!closest || (dxClosest && closest.nodeType == 1)) { return {node: node, offset: offset} }
      +  return findOffsetInNode(closest, coordsClosest)
      +}
      +
      +function findOffsetInText(node, coords) {
      +  var len = node.nodeValue.length;
      +  var range = document.createRange();
      +  for (var i = 0; i < len; i++) {
      +    range.setEnd(node, i + 1);
      +    range.setStart(node, i);
      +    var rect = singleRect(range, 1);
      +    if (rect.top == rect.bottom) { continue }
      +    if (inRect(coords, rect))
      +      { return {node: node, offset: i + (coords.left >= (rect.left + rect.right) / 2 ? 1 : 0)} }
      +  }
      +  return {node: node, offset: 0}
      +}
      +
      +function inRect(coords, rect) {
      +  return coords.left >= rect.left - 1 && coords.left <= rect.right + 1&&
      +    coords.top >= rect.top - 1 && coords.top <= rect.bottom + 1
      +}
      +
      +function targetKludge(dom, coords) {
      +  var parent = dom.parentNode;
      +  if (parent && /^li$/i.test(parent.nodeName) && coords.left < dom.getBoundingClientRect().left)
      +    { return parent }
      +  return dom
      +}
      +
      +function posFromElement(view, elt, coords) {
      +  var ref = findOffsetInNode(elt, coords);
      +  var node = ref.node;
      +  var offset = ref.offset;
      +  var bias = -1;
      +  if (node.nodeType == 1 && !node.firstChild) {
      +    var rect = node.getBoundingClientRect();
      +    bias = rect.left != rect.right && coords.left > (rect.left + rect.right) / 2 ? 1 : -1;
      +  }
      +  return view.docView.posFromDOM(node, offset, bias)
      +}
      +
      +function posFromCaret(view, node, offset, coords) {
      +  // Browser (in caretPosition/RangeFromPoint) will agressively
      +  // normalize towards nearby inline nodes. Since we are interested in
      +  // positions between block nodes too, we first walk up the hierarchy
      +  // of nodes to see if there are block nodes that the coordinates
      +  // fall outside of. If so, we take the position before/after that
      +  // block. If not, we call `posFromDOM` on the raw node/offset.
      +  var outside = -1;
      +  for (var cur = node;;) {
      +    if (cur == view.dom) { break }
      +    var desc = view.docView.nearestDesc(cur, true);
      +    if (!desc) { return null }
      +    if (desc.node.isBlock && desc.parent) {
      +      var rect = desc.dom.getBoundingClientRect();
      +      if (rect.left > coords.left || rect.top > coords.top) { outside = desc.posBefore; }
      +      else if (rect.right < coords.left || rect.bottom < coords.top) { outside = desc.posAfter; }
      +      else { break }
      +    }
      +    cur = desc.dom.parentNode;
      +  }
      +  return outside > -1 ? outside : view.docView.posFromDOM(node, offset)
      +}
      +
      +function elementFromPoint(element, coords, box) {
      +  var len = element.childNodes.length;
      +  if (len && box.top < box.bottom) {
      +    for (var startI = Math.max(0, Math.min(len - 1, Math.floor(len * (coords.top - box.top) / (box.bottom - box.top)) - 2)), i = startI;;) {
      +      var child = element.childNodes[i];
      +      if (child.nodeType == 1) {
      +        var rects = child.getClientRects();
      +        for (var j = 0; j < rects.length; j++) {
      +          var rect = rects[j];
      +          if (inRect(coords, rect)) { return elementFromPoint(child, coords, rect) }
      +        }
      +      }
      +      if ((i = (i + 1) % len) == startI) { break }
      +    }
      +  }
      +  return element
      +}
      +
      +// Given an x,y position on the editor, get the position in the document.
      +function posAtCoords(view, coords) {
      +  var assign, assign$1;
      +
      +  var root = view.root, node, offset;
      +  if (root.caretPositionFromPoint) {
      +    try { // Firefox throws for this call in hard-to-predict circumstances (#994)
      +      var pos$1 = root.caretPositionFromPoint(coords.left, coords.top);
      +      if (pos$1) { ((assign = pos$1, node = assign.offsetNode, offset = assign.offset)); }
      +    } catch (_) {}
      +  }
      +  if (!node && root.caretRangeFromPoint) {
      +    var range = root.caretRangeFromPoint(coords.left, coords.top);
      +    if (range) { ((assign$1 = range, node = assign$1.startContainer, offset = assign$1.startOffset)); }
      +  }
      +
      +  var elt = root.elementFromPoint(coords.left, coords.top + 1), pos;
      +  if (!elt || !view.dom.contains(elt.nodeType != 1 ? elt.parentNode : elt)) {
      +    var box = view.dom.getBoundingClientRect();
      +    if (!inRect(coords, box)) { return null }
      +    elt = elementFromPoint(view.dom, coords, box);
      +    if (!elt) { return null }
      +  }
      +  elt = targetKludge(elt, coords);
      +  if (node) {
      +    if (result.gecko && node.nodeType == 1) {
      +      // Firefox will sometimes return offsets into  nodes, which
      +      // have no actual children, from caretPositionFromPoint (#953)
      +      offset = Math.min(offset, node.childNodes.length);
      +      // It'll also move the returned position before image nodes,
      +      // even if those are behind it.
      +      if (offset < node.childNodes.length) {
      +        var next = node.childNodes[offset], box$1;
      +        if (next.nodeName == "IMG" && (box$1 = next.getBoundingClientRect()).right <= coords.left &&
      +            box$1.bottom > coords.top)
      +          { offset++; }
      +      }
      +    }
      +    // Suspiciously specific kludge to work around caret*FromPoint
      +    // never returning a position at the end of the document
      +    if (node == view.dom && offset == node.childNodes.length - 1 && node.lastChild.nodeType == 1 &&
      +        coords.top > node.lastChild.getBoundingClientRect().bottom)
      +      { pos = view.state.doc.content.size; }
      +    // Ignore positions directly after a BR, since caret*FromPoint
      +    // 'round up' positions that would be more accurately placed
      +    // before the BR node.
      +    else if (offset == 0 || node.nodeType != 1 || node.childNodes[offset - 1].nodeName != "BR")
      +      { pos = posFromCaret(view, node, offset, coords); }
      +  }
      +  if (pos == null) { pos = posFromElement(view, elt, coords); }
      +
      +  var desc = view.docView.nearestDesc(elt, true);
      +  return {pos: pos, inside: desc ? desc.posAtStart - desc.border : -1}
      +}
      +
      +function singleRect(object, bias) {
      +  var rects = object.getClientRects();
      +  return !rects.length ? object.getBoundingClientRect() : rects[bias < 0 ? 0 : rects.length - 1]
      +}
      +
      +// : (EditorView, number) → {left: number, top: number, right: number, bottom: number}
      +// Given a position in the document model, get a bounding box of the
      +// character at that position, relative to the window.
      +function coordsAtPos(view, pos) {
      +  var ref = view.docView.domFromPos(pos);
      +  var node = ref.node;
      +  var offset = ref.offset;
      +
      +  // These browsers support querying empty text ranges
      +  if (node.nodeType == 3 && (result.chrome || result.gecko)) {
      +    var rect = singleRect(textRange(node, offset, offset), 0);
      +    // Firefox returns bad results (the position before the space)
      +    // when querying a position directly after line-broken
      +    // whitespace. Detect this situation and and kludge around it
      +    if (result.gecko && offset && /\s/.test(node.nodeValue[offset - 1]) && offset < node.nodeValue.length) {
      +      var rectBefore = singleRect(textRange(node, offset - 1, offset - 1), -1);
      +      if (Math.abs(rectBefore.left - rect.left) < 1 && rectBefore.top == rect.top) {
      +        var rectAfter = singleRect(textRange(node, offset, offset + 1), -1);
      +        return flattenV(rectAfter, rectAfter.left < rectBefore.left)
      +      }
      +    }
      +    return rect
      +  }
      +
      +  if (node.nodeType == 1 && !view.state.doc.resolve(pos).parent.inlineContent) {
      +    // Return a horizontal line in block context
      +    var top = true, rect$1;
      +    if (offset < node.childNodes.length) {
      +      var after = node.childNodes[offset];
      +      if (after.nodeType == 1) { rect$1 = after.getBoundingClientRect(); }
      +    }
      +    if (!rect$1 && offset) {
      +      var before = node.childNodes[offset - 1];
      +      if (before.nodeType == 1) { rect$1 = before.getBoundingClientRect(); top = false; }
      +    }
      +    return flattenH(rect$1 || node.getBoundingClientRect(), top)
      +  }
      +
      +  // Not Firefox/Chrome, or not in a text node, so we have to use
      +  // actual element/character rectangles to get a solution (this part
      +  // is not very bidi-safe)
      +  //
      +  // Try the left side first, fall back to the right one if that
      +  // doesn't work.
      +  for (var dir = -1; dir < 2; dir += 2) {
      +    if (dir < 0 && offset) {
      +      var prev = (void 0), target = node.nodeType == 3 ? textRange(node, offset - 1, offset)
      +          : (prev = node.childNodes[offset - 1]).nodeType == 3 ? textRange(prev)
      +          : prev.nodeType == 1 && prev.nodeName != "BR" ? prev : null; // BR nodes tend to only return the rectangle before them
      +      if (target) {
      +        var rect$2 = singleRect(target, 1);
      +        if (rect$2.top < rect$2.bottom) { return flattenV(rect$2, false) }
      +      }
      +    } else if (dir > 0 && offset < nodeSize(node)) {
      +      var next = (void 0), target$1 = node.nodeType == 3 ? textRange(node, offset, offset + 1)
      +          : (next = node.childNodes[offset]).nodeType == 3 ? textRange(next)
      +          : next.nodeType == 1 ? next : null;
      +      if (target$1) {
      +        var rect$3 = singleRect(target$1, -1);
      +        if (rect$3.top < rect$3.bottom) { return flattenV(rect$3, true) }
      +      }
      +    }
      +  }
      +  // All else failed, just try to get a rectangle for the target node
      +  return flattenV(singleRect(node.nodeType == 3 ? textRange(node) : node, 0), false)
      +}
      +
      +function flattenV(rect, left) {
      +  if (rect.width == 0) { return rect }
      +  var x = left ? rect.left : rect.right;
      +  return {top: rect.top, bottom: rect.bottom, left: x, right: x}
      +}
      +
      +function flattenH(rect, top) {
      +  if (rect.height == 0) { return rect }
      +  var y = top ? rect.top : rect.bottom;
      +  return {top: y, bottom: y, left: rect.left, right: rect.right}
      +}
      +
      +function withFlushedState(view, state, f) {
      +  var viewState = view.state, active = view.root.activeElement;
      +  if (viewState != state) { view.updateState(state); }
      +  if (active != view.dom) { view.focus(); }
      +  try {
      +    return f()
      +  } finally {
      +    if (viewState != state) { view.updateState(viewState); }
      +    if (active != view.dom) { active.focus(); }
      +  }
      +}
      +
      +// : (EditorView, number, number)
      +// Whether vertical position motion in a given direction
      +// from a position would leave a text block.
      +function endOfTextblockVertical(view, state, dir) {
      +  var sel = state.selection;
      +  var $pos = dir == "up" ? sel.$anchor.min(sel.$head) : sel.$anchor.max(sel.$head);
      +  return withFlushedState(view, state, function () {
      +    var ref = view.docView.domFromPos($pos.pos);
      +    var dom = ref.node;
      +    for (;;) {
      +      var nearest = view.docView.nearestDesc(dom, true);
      +      if (!nearest) { break }
      +      if (nearest.node.isBlock) { dom = nearest.dom; break }
      +      dom = nearest.dom.parentNode;
      +    }
      +    var coords = coordsAtPos(view, $pos.pos);
      +    for (var child = dom.firstChild; child; child = child.nextSibling) {
      +      var boxes = (void 0);
      +      if (child.nodeType == 1) { boxes = child.getClientRects(); }
      +      else if (child.nodeType == 3) { boxes = textRange(child, 0, child.nodeValue.length).getClientRects(); }
      +      else { continue }
      +      for (var i = 0; i < boxes.length; i++) {
      +        var box = boxes[i];
      +        if (box.bottom > box.top && (dir == "up" ? box.bottom < coords.top + 1 : box.top > coords.bottom - 1))
      +          { return false }
      +      }
      +    }
      +    return true
      +  })
      +}
      +
      +var maybeRTL = /[\u0590-\u08ac]/;
      +
      +function endOfTextblockHorizontal(view, state, dir) {
      +  var ref = state.selection;
      +  var $head = ref.$head;
      +  if (!$head.parent.isTextblock) { return false }
      +  var offset = $head.parentOffset, atStart = !offset, atEnd = offset == $head.parent.content.size;
      +  var sel = getSelection();
      +  // If the textblock is all LTR, or the browser doesn't support
      +  // Selection.modify (Edge), fall back to a primitive approach
      +  if (!maybeRTL.test($head.parent.textContent) || !sel.modify)
      +    { return dir == "left" || dir == "backward" ? atStart : atEnd }
      +
      +  return withFlushedState(view, state, function () {
      +    // This is a huge hack, but appears to be the best we can
      +    // currently do: use `Selection.modify` to move the selection by
      +    // one character, and see if that moves the cursor out of the
      +    // textblock (or doesn't move it at all, when at the start/end of
      +    // the document).
      +    var oldRange = sel.getRangeAt(0), oldNode = sel.focusNode, oldOff = sel.focusOffset;
      +    var oldBidiLevel = sel.caretBidiLevel; // Only for Firefox
      +    sel.modify("move", dir, "character");
      +    var parentDOM = $head.depth ? view.docView.domAfterPos($head.before()) : view.dom;
      +    var result = !parentDOM.contains(sel.focusNode.nodeType == 1 ? sel.focusNode : sel.focusNode.parentNode) ||
      +        (oldNode == sel.focusNode && oldOff == sel.focusOffset);
      +    // Restore the previous selection
      +    sel.removeAllRanges();
      +    sel.addRange(oldRange);
      +    if (oldBidiLevel != null) { sel.caretBidiLevel = oldBidiLevel; }
      +    return result
      +  })
      +}
      +
      +var cachedState = null, cachedDir = null, cachedResult = false;
      +function endOfTextblock(view, state, dir) {
      +  if (cachedState == state && cachedDir == dir) { return cachedResult }
      +  cachedState = state; cachedDir = dir;
      +  return cachedResult = dir == "up" || dir == "down"
      +    ? endOfTextblockVertical(view, state, dir)
      +    : endOfTextblockHorizontal(view, state, dir)
      +}
      +
      +// NodeView:: interface
      +//
      +// By default, document nodes are rendered using the result of the
      +// [`toDOM`](#model.NodeSpec.toDOM) method of their spec, and managed
      +// entirely by the editor. For some use cases, such as embedded
      +// node-specific editing interfaces, you want more control over
      +// the behavior of a node's in-editor representation, and need to
      +// [define](#view.EditorProps.nodeViews) a custom node view.
      +//
      +// Objects returned as node views must conform to this interface.
      +//
      +//   dom:: ?dom.Node
      +//   The outer DOM node that represents the document node. When not
      +//   given, the default strategy is used to create a DOM node.
      +//
      +//   contentDOM:: ?dom.Node
      +//   The DOM node that should hold the node's content. Only meaningful
      +//   if the node view also defines a `dom` property and if its node
      +//   type is not a leaf node type. When this is present, ProseMirror
      +//   will take care of rendering the node's children into it. When it
      +//   is not present, the node view itself is responsible for rendering
      +//   (or deciding not to render) its child nodes.
      +//
      +//   update:: ?(node: Node, decorations: [Decoration]) → bool
      +//   When given, this will be called when the view is updating itself.
      +//   It will be given a node (possibly of a different type), and an
      +//   array of active decorations (which are automatically drawn, and
      +//   the node view may ignore if it isn't interested in them), and
      +//   should return true if it was able to update to that node, and
      +//   false otherwise. If the node view has a `contentDOM` property (or
      +//   no `dom` property), updating its child nodes will be handled by
      +//   ProseMirror.
      +//
      +//   selectNode:: ?()
      +//   Can be used to override the way the node's selected status (as a
      +//   node selection) is displayed.
      +//
      +//   deselectNode:: ?()
      +//   When defining a `selectNode` method, you should also provide a
      +//   `deselectNode` method to remove the effect again.
      +//
      +//   setSelection:: ?(anchor: number, head: number, root: dom.Document)
      +//   This will be called to handle setting the selection inside the
      +//   node. The `anchor` and `head` positions are relative to the start
      +//   of the node. By default, a DOM selection will be created between
      +//   the DOM positions corresponding to those positions, but if you
      +//   override it you can do something else.
      +//
      +//   stopEvent:: ?(event: dom.Event) → bool
      +//   Can be used to prevent the editor view from trying to handle some
      +//   or all DOM events that bubble up from the node view. Events for
      +//   which this returns true are not handled by the editor.
      +//
      +//   ignoreMutation:: ?(dom.MutationRecord) → bool
      +//   Called when a DOM
      +//   [mutation](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver)
      +//   or a selection change happens within the view. When the change is
      +//   a selection change, the record will have a `type` property of
      +//   `"selection"` (which doesn't occur for native mutation records).
      +//   Return false if the editor should re-read the selection or
      +//   re-parse the range around the mutation, true if it can safely be
      +//   ignored.
      +//
      +//   destroy:: ?()
      +//   Called when the node view is removed from the editor or the whole
      +//   editor is destroyed.
      +
      +// View descriptions are data structures that describe the DOM that is
      +// used to represent the editor's content. They are used for:
      +//
      +// - Incremental redrawing when the document changes
      +//
      +// - Figuring out what part of the document a given DOM position
      +//   corresponds to
      +//
      +// - Wiring in custom implementations of the editing interface for a
      +//   given node
      +//
      +// They form a doubly-linked mutable tree, starting at `view.docView`.
      +
      +var NOT_DIRTY = 0, CHILD_DIRTY = 1, CONTENT_DIRTY = 2, NODE_DIRTY = 3;
      +
      +// Superclass for the various kinds of descriptions. Defines their
      +// basic structure and shared methods.
      +var ViewDesc = function ViewDesc(parent, children, dom, contentDOM) {
      +  this.parent = parent;
      +  this.children = children;
      +  this.dom = dom;
      +  // An expando property on the DOM node provides a link back to its
      +  // description.
      +  dom.pmViewDesc = this;
      +  // This is the node that holds the child views. It may be null for
      +  // descs that don't have children.
      +  this.contentDOM = contentDOM;
      +  this.dirty = NOT_DIRTY;
      +};
      +
      +var prototypeAccessors = { beforePosition: { configurable: true },size: { configurable: true },border: { configurable: true },posBefore: { configurable: true },posAtStart: { configurable: true },posAfter: { configurable: true },posAtEnd: { configurable: true },contentLost: { configurable: true } };
      +
      +// Used to check whether a given description corresponds to a
      +// widget/mark/node.
      +ViewDesc.prototype.matchesWidget = function matchesWidget () { return false };
      +ViewDesc.prototype.matchesMark = function matchesMark () { return false };
      +ViewDesc.prototype.matchesNode = function matchesNode () { return false };
      +ViewDesc.prototype.matchesHack = function matchesHack () { return false };
      +
      +prototypeAccessors.beforePosition.get = function () { return false };
      +
      +// : () → ?ParseRule
      +// When parsing in-editor content (in domchange.js), we allow
      +// descriptions to determine the parse rules that should be used to
      +// parse them.
      +ViewDesc.prototype.parseRule = function parseRule () { return null };
      +
      +// : (dom.Event) → bool
      +// Used by the editor's event handler to ignore events that come
      +// from certain descs.
      +ViewDesc.prototype.stopEvent = function stopEvent () { return false };
      +
      +// The size of the content represented by this desc.
      +prototypeAccessors.size.get = function () {
      +  var size = 0;
      +  for (var i = 0; i < this.children.length; i++) { size += this.children[i].size; }
      +  return size
      +};
      +
      +// For block nodes, this represents the space taken up by their
      +// start/end tokens.
      +prototypeAccessors.border.get = function () { return 0 };
      +
      +ViewDesc.prototype.destroy = function destroy () {
      +  this.parent = null;
      +  if (this.dom.pmViewDesc == this) { this.dom.pmViewDesc = null; }
      +  for (var i = 0; i < this.children.length; i++)
      +    { this.children[i].destroy(); }
      +};
      +
      +ViewDesc.prototype.posBeforeChild = function posBeforeChild (child) {
      +  for (var i = 0, pos = this.posAtStart; i < this.children.length; i++) {
      +    var cur = this.children[i];
      +    if (cur == child) { return pos }
      +    pos += cur.size;
      +  }
      +};
      +
      +prototypeAccessors.posBefore.get = function () {
      +  return this.parent.posBeforeChild(this)
      +};
      +
      +prototypeAccessors.posAtStart.get = function () {
      +  return this.parent ? this.parent.posBeforeChild(this) + this.border : 0
      +};
      +
      +prototypeAccessors.posAfter.get = function () {
      +  return this.posBefore + this.size
      +};
      +
      +prototypeAccessors.posAtEnd.get = function () {
      +  return this.posAtStart + this.size - 2 * this.border
      +};
      +
      +// : (dom.Node, number, ?number) → number
      +ViewDesc.prototype.localPosFromDOM = function localPosFromDOM (dom, offset, bias) {
      +  // If the DOM position is in the content, use the child desc after
      +  // it to figure out a position.
      +  if (this.contentDOM && this.contentDOM.contains(dom.nodeType == 1 ? dom : dom.parentNode)) {
      +    if (bias < 0) {
      +      var domBefore, desc;
      +      if (dom == this.contentDOM) {
      +        domBefore = dom.childNodes[offset - 1];
      +      } else {
      +        while (dom.parentNode != this.contentDOM) { dom = dom.parentNode; }
      +        domBefore = dom.previousSibling;
      +      }
      +      while (domBefore && !((desc = domBefore.pmViewDesc) && desc.parent == this)) { domBefore = domBefore.previousSibling; }
      +      return domBefore ? this.posBeforeChild(desc) + desc.size : this.posAtStart
      +    } else {
      +      var domAfter, desc$1;
      +      if (dom == this.contentDOM) {
      +        domAfter = dom.childNodes[offset];
      +      } else {
      +        while (dom.parentNode != this.contentDOM) { dom = dom.parentNode; }
      +        domAfter = dom.nextSibling;
      +      }
      +      while (domAfter && !((desc$1 = domAfter.pmViewDesc) && desc$1.parent == this)) { domAfter = domAfter.nextSibling; }
      +      return domAfter ? this.posBeforeChild(desc$1) : this.posAtEnd
      +    }
      +  }
      +  // Otherwise, use various heuristics, falling back on the bias
      +  // parameter, to determine whether to return the position at the
      +  // start or at the end of this view desc.
      +  var atEnd;
      +  if (this.contentDOM && this.contentDOM != this.dom && this.dom.contains(this.contentDOM)) {
      +    atEnd = dom.compareDocumentPosition(this.contentDOM) & 2;
      +  } else if (this.dom.firstChild) {
      +    if (offset == 0) { for (var search = dom;; search = search.parentNode) {
      +      if (search == this.dom) { atEnd = false; break }
      +      if (search.parentNode.firstChild != search) { break }
      +    } }
      +    if (atEnd == null && offset == dom.childNodes.length) { for (var search$1 = dom;; search$1 = search$1.parentNode) {
      +      if (search$1 == this.dom) { atEnd = true; break }
      +      if (search$1.parentNode.lastChild != search$1) { break }
      +    } }
      +  }
      +  return (atEnd == null ? bias > 0 : atEnd) ? this.posAtEnd : this.posAtStart
      +};
      +
      +// Scan up the dom finding the first desc that is a descendant of
      +// this one.
      +ViewDesc.prototype.nearestDesc = function nearestDesc (dom, onlyNodes) {
      +  for (var first = true, cur = dom; cur; cur = cur.parentNode) {
      +    var desc = this.getDesc(cur);
      +    if (desc && (!onlyNodes || desc.node)) {
      +      // If dom is outside of this desc's nodeDOM, don't count it.
      +      if (first && desc.nodeDOM && !(desc.nodeDOM.nodeType == 1 ? desc.nodeDOM.contains(dom) : desc.nodeDOM == dom)) { first = false; }
      +      else { return desc }
      +    }
      +  }
      +};
      +
      +ViewDesc.prototype.getDesc = function getDesc (dom) {
      +  var desc = dom.pmViewDesc;
      +  for (var cur = desc; cur; cur = cur.parent) { if (cur == this) { return desc } }
      +};
      +
      +ViewDesc.prototype.posFromDOM = function posFromDOM (dom, offset, bias) {
      +  for (var scan = dom;; scan = scan.parentNode) {
      +    var desc = this.getDesc(scan);
      +    if (desc) { return desc.localPosFromDOM(dom, offset, bias) }
      +  }
      +};
      +
      +// : (number) → ?NodeViewDesc
      +// Find the desc for the node after the given pos, if any. (When a
      +// parent node overrode rendering, there might not be one.)
      +ViewDesc.prototype.descAt = function descAt (pos) {
      +  for (var i = 0, offset = 0; i < this.children.length; i++) {
      +    var child = this.children[i], end = offset + child.size;
      +    if (offset == pos && end != offset) {
      +      while (!child.border && child.children.length) { child = child.children[0]; }
      +      return child
      +    }
      +    if (pos < end) { return child.descAt(pos - offset - child.border) }
      +    offset = end;
      +  }
      +};
      +
      +// : (number) → {node: dom.Node, offset: number}
      +ViewDesc.prototype.domFromPos = function domFromPos (pos) {
      +  if (!this.contentDOM) { return {node: this.dom, offset: 0} }
      +  for (var offset = 0, i = 0;; i++) {
      +    if (offset == pos) {
      +      while (i < this.children.length && (this.children[i].beforePosition || this.children[i].dom.parentNode != this.contentDOM)) { i++; }
      +      return {node: this.contentDOM,
      +              offset: i == this.children.length ? this.contentDOM.childNodes.length : domIndex(this.children[i].dom)}
      +    }
      +    if (i == this.children.length) { throw new Error("Invalid position " + pos) }
      +    var child = this.children[i], end = offset + child.size;
      +    if (pos < end) { return child.domFromPos(pos - offset - child.border) }
      +    offset = end;
      +  }
      +};
      +
      +// Used to find a DOM range in a single parent for a given changed
      +// range.
      +ViewDesc.prototype.parseRange = function parseRange (from, to, base) {
      +    if ( base === void 0 ) base = 0;
      +
      +  if (this.children.length == 0)
      +    { return {node: this.contentDOM, from: from, to: to, fromOffset: 0, toOffset: this.contentDOM.childNodes.length} }
      +
      +  var fromOffset = -1, toOffset = -1;
      +  for (var offset = base, i = 0;; i++) {
      +    var child = this.children[i], end = offset + child.size;
      +    if (fromOffset == -1 && from <= end) {
      +      var childBase = offset + child.border;
      +      // FIXME maybe descend mark views to parse a narrower range?
      +      if (from >= childBase && to <= end - child.border && child.node &&
      +          child.contentDOM && this.contentDOM.contains(child.contentDOM))
      +        { return child.parseRange(from, to, childBase) }
      +
      +      from = offset;
      +      for (var j = i; j > 0; j--) {
      +        var prev = this.children[j - 1];
      +        if (prev.size && prev.dom.parentNode == this.contentDOM && !prev.emptyChildAt(1)) {
      +          fromOffset = domIndex(prev.dom) + 1;
      +          break
      +        }
      +        from -= prev.size;
      +      }
      +      if (fromOffset == -1) { fromOffset = 0; }
      +    }
      +    if (fromOffset > -1 && to <= end) {
      +      to = end;
      +      for (var j$1 = i + 1; j$1 < this.children.length; j$1++) {
      +        var next = this.children[j$1];
      +        if (next.size && next.dom.parentNode == this.contentDOM && !next.emptyChildAt(-1)) {
      +          toOffset = domIndex(next.dom);
      +          break
      +        }
      +        to += next.size;
      +      }
      +      if (toOffset == -1) { toOffset = this.contentDOM.childNodes.length; }
      +      break
      +    }
      +    offset = end;
      +  }
      +  return {node: this.contentDOM, from: from, to: to, fromOffset: fromOffset, toOffset: toOffset}
      +};
      +
      +ViewDesc.prototype.emptyChildAt = function emptyChildAt (side) {
      +  if (this.border || !this.contentDOM || !this.children.length) { return false }
      +  var child = this.children[side < 0 ? 0 : this.children.length - 1];
      +  return child.size == 0 || child.emptyChildAt(side)
      +};
      +
      +// : (number) → dom.Node
      +ViewDesc.prototype.domAfterPos = function domAfterPos (pos) {
      +  var ref = this.domFromPos(pos);
      +    var node = ref.node;
      +    var offset = ref.offset;
      +  if (node.nodeType != 1 || offset == node.childNodes.length)
      +    { throw new RangeError("No node after pos " + pos) }
      +  return node.childNodes[offset]
      +};
      +
      +// : (number, number, dom.Document)
      +// View descs are responsible for setting any selection that falls
      +// entirely inside of them, so that custom implementations can do
      +// custom things with the selection. Note that this falls apart when
      +// a selection starts in such a node and ends in another, in which
      +// case we just use whatever domFromPos produces as a best effort.
      +ViewDesc.prototype.setSelection = function setSelection (anchor, head, root, force) {
      +  // If the selection falls entirely in a child, give it to that child
      +  var from = Math.min(anchor, head), to = Math.max(anchor, head);
      +  for (var i = 0, offset = 0; i < this.children.length; i++) {
      +    var child = this.children[i], end = offset + child.size;
      +    if (from > offset && to < end)
      +      { return child.setSelection(anchor - offset - child.border, head - offset - child.border, root, force) }
      +    offset = end;
      +  }
      +
      +  var anchorDOM = this.domFromPos(anchor), headDOM = this.domFromPos(head);
      +  var domSel = root.getSelection(), range = document.createRange();
      +  if (!force &&
      +      isEquivalentPosition(anchorDOM.node, anchorDOM.offset, domSel.anchorNode, domSel.anchorOffset) &&
      +      isEquivalentPosition(headDOM.node, headDOM.offset, domSel.focusNode, domSel.focusOffset))
      +    { return }
      +
      +  // Selection.extend can be used to create an 'inverted' selection
      +  // (one where the focus is before the anchor), but not all
      +  // browsers support it yet.
      +  if (domSel.extend) {
      +    range.setEnd(anchorDOM.node, anchorDOM.offset);
      +    range.collapse(false);
      +  } else {
      +    if (anchor > head) { var tmp = anchorDOM; anchorDOM = headDOM; headDOM = tmp; }
      +    range.setEnd(headDOM.node, headDOM.offset);
      +    range.setStart(anchorDOM.node, anchorDOM.offset);
      +  }
      +  domSel.removeAllRanges();
      +  domSel.addRange(range);
      +  if (domSel.extend)
      +    { domSel.extend(headDOM.node, headDOM.offset); }
      +};
      +
      +// : (dom.MutationRecord) → bool
      +ViewDesc.prototype.ignoreMutation = function ignoreMutation (_mutation) {
      +  return !this.contentDOM
      +};
      +
      +prototypeAccessors.contentLost.get = function () {
      +  return this.contentDOM && this.contentDOM != this.dom && !this.dom.contains(this.contentDOM)
      +};
      +
      +// Remove a subtree of the element tree that has been touched
      +// by a DOM change, so that the next update will redraw it.
      +ViewDesc.prototype.markDirty = function markDirty (from, to) {
      +  for (var offset = 0, i = 0; i < this.children.length; i++) {
      +    var child = this.children[i], end = offset + child.size;
      +    if (offset == end ? from <= end && to >= offset : from < end && to > offset) {
      +      var startInside = offset + child.border, endInside = end - child.border;
      +      if (from >= startInside && to <= endInside) {
      +        this.dirty = from == offset || to == end ? CONTENT_DIRTY : CHILD_DIRTY;
      +        if (from == startInside && to == endInside &&
      +            (child.contentLost || child.dom.parentNode != this.contentDOM)) { child.dirty = NODE_DIRTY; }
      +        else { child.markDirty(from - startInside, to - startInside); }
      +        return
      +      } else {
      +        child.dirty = NODE_DIRTY;
      +      }
      +    }
      +    offset = end;
      +  }
      +  this.dirty = CONTENT_DIRTY;
      +};
      +
      +ViewDesc.prototype.markParentsDirty = function markParentsDirty () {
      +  for (var node = this.parent; node; node = node.parent) {
      +    var dirty =  CONTENT_DIRTY ;
      +    if (node.dirty < dirty) { node.dirty = dirty; }
      +  }
      +};
      +
      +Object.defineProperties( ViewDesc.prototype, prototypeAccessors );
      +
      +// Reused array to avoid allocating fresh arrays for things that will
      +// stay empty anyway.
      +var nothing = [];
      +
      +// A widget desc represents a widget decoration, which is a DOM node
      +// drawn between the document nodes.
      +var WidgetViewDesc = /*@__PURE__*/(function (ViewDesc) {
      +  function WidgetViewDesc(parent, widget, view, pos) {
      +    var self, dom = widget.type.toDOM;
      +    if (typeof dom == "function") { dom = dom(view, function () {
      +      if (!self) { return pos }
      +      if (self.parent) { return self.parent.posBeforeChild(self) }
      +    }); }
      +    if (!widget.type.spec.raw) {
      +      if (dom.nodeType != 1) {
      +        var wrap = document.createElement("span");
      +        wrap.appendChild(dom);
      +        dom = wrap;
      +      }
      +      dom.contentEditable = false;
      +      dom.classList.add("ProseMirror-widget");
      +    }
      +    ViewDesc.call(this, parent, nothing, dom, null);
      +    this.widget = widget;
      +    self = this;
      +  }
      +
      +  if ( ViewDesc ) WidgetViewDesc.__proto__ = ViewDesc;
      +  WidgetViewDesc.prototype = Object.create( ViewDesc && ViewDesc.prototype );
      +  WidgetViewDesc.prototype.constructor = WidgetViewDesc;
      +
      +  var prototypeAccessors$1 = { beforePosition: { configurable: true } };
      +
      +  prototypeAccessors$1.beforePosition.get = function () {
      +    return this.widget.type.side < 0
      +  };
      +
      +  WidgetViewDesc.prototype.matchesWidget = function matchesWidget (widget) {
      +    return this.dirty == NOT_DIRTY && widget.type.eq(this.widget.type)
      +  };
      +
      +  WidgetViewDesc.prototype.parseRule = function parseRule () { return {ignore: true} };
      +
      +  WidgetViewDesc.prototype.stopEvent = function stopEvent (event) {
      +    var stop = this.widget.spec.stopEvent;
      +    return stop ? stop(event) : false
      +  };
      +
      +  Object.defineProperties( WidgetViewDesc.prototype, prototypeAccessors$1 );
      +
      +  return WidgetViewDesc;
      +}(ViewDesc));
      +
      +var CompositionViewDesc = /*@__PURE__*/(function (ViewDesc) {
      +  function CompositionViewDesc(parent, dom, textDOM, text) {
      +    ViewDesc.call(this, parent, nothing, dom, null);
      +    this.textDOM = textDOM;
      +    this.text = text;
      +  }
      +
      +  if ( ViewDesc ) CompositionViewDesc.__proto__ = ViewDesc;
      +  CompositionViewDesc.prototype = Object.create( ViewDesc && ViewDesc.prototype );
      +  CompositionViewDesc.prototype.constructor = CompositionViewDesc;
      +
      +  var prototypeAccessors$2 = { size: { configurable: true } };
      +
      +  prototypeAccessors$2.size.get = function () { return this.text.length };
      +
      +  CompositionViewDesc.prototype.localPosFromDOM = function localPosFromDOM (dom, offset) {
      +    if (dom != this.textDOM) { return this.posAtStart + (offset ? this.size : 0) }
      +    return this.posAtStart + offset
      +  };
      +
      +  CompositionViewDesc.prototype.domFromPos = function domFromPos (pos) {
      +    return {node: this.textDOM, offset: pos}
      +  };
      +
      +  CompositionViewDesc.prototype.ignoreMutation = function ignoreMutation (mut) {
      +    return mut.type === 'characterData' && mut.target.nodeValue == mut.oldValue
      +   };
      +
      +  Object.defineProperties( CompositionViewDesc.prototype, prototypeAccessors$2 );
      +
      +  return CompositionViewDesc;
      +}(ViewDesc));
      +
      +// A mark desc represents a mark. May have multiple children,
      +// depending on how the mark is split. Note that marks are drawn using
      +// a fixed nesting order, for simplicity and predictability, so in
      +// some cases they will be split more often than would appear
      +// necessary.
      +var MarkViewDesc = /*@__PURE__*/(function (ViewDesc) {
      +  function MarkViewDesc(parent, mark, dom, contentDOM) {
      +    ViewDesc.call(this, parent, [], dom, contentDOM);
      +    this.mark = mark;
      +  }
      +
      +  if ( ViewDesc ) MarkViewDesc.__proto__ = ViewDesc;
      +  MarkViewDesc.prototype = Object.create( ViewDesc && ViewDesc.prototype );
      +  MarkViewDesc.prototype.constructor = MarkViewDesc;
      +
      +  MarkViewDesc.create = function create (parent, mark, inline, view) {
      +    var custom = view.nodeViews[mark.type.name];
      +    var spec = custom && custom(mark, view, inline);
      +    if (!spec || !spec.dom)
      +      { spec = prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["DOMSerializer"].renderSpec(document, mark.type.spec.toDOM(mark, inline)); }
      +    return new MarkViewDesc(parent, mark, spec.dom, spec.contentDOM || spec.dom)
      +  };
      +
      +  MarkViewDesc.prototype.parseRule = function parseRule () { return {mark: this.mark.type.name, attrs: this.mark.attrs, contentElement: this.contentDOM} };
      +
      +  MarkViewDesc.prototype.matchesMark = function matchesMark (mark) { return this.dirty != NODE_DIRTY && this.mark.eq(mark) };
      +
      +  MarkViewDesc.prototype.markDirty = function markDirty (from, to) {
      +    ViewDesc.prototype.markDirty.call(this, from, to);
      +    // Move dirty info to nearest node view
      +    if (this.dirty != NOT_DIRTY) {
      +      var parent = this.parent;
      +      while (!parent.node) { parent = parent.parent; }
      +      if (parent.dirty < this.dirty) { parent.dirty = this.dirty; }
      +      this.dirty = NOT_DIRTY;
      +    }
      +  };
      +
      +  MarkViewDesc.prototype.slice = function slice (from, to, view) {
      +    var copy = MarkViewDesc.create(this.parent, this.mark, true, view);
      +    var nodes = this.children, size = this.size;
      +    if (to < size) { nodes = replaceNodes(nodes, to, size, view); }
      +    if (from > 0) { nodes = replaceNodes(nodes, 0, from, view); }
      +    for (var i = 0; i < nodes.length; i++) { nodes[i].parent = copy; }
      +    copy.children = nodes;
      +    return copy
      +  };
      +
      +  return MarkViewDesc;
      +}(ViewDesc));
      +
      +// Node view descs are the main, most common type of view desc, and
      +// correspond to an actual node in the document. Unlike mark descs,
      +// they populate their child array themselves.
      +var NodeViewDesc = /*@__PURE__*/(function (ViewDesc) {
      +  function NodeViewDesc(parent, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM, view, pos) {
      +    ViewDesc.call(this, parent, node.isLeaf ? nothing : [], dom, contentDOM);
      +    this.nodeDOM = nodeDOM;
      +    this.node = node;
      +    this.outerDeco = outerDeco;
      +    this.innerDeco = innerDeco;
      +    if (contentDOM) { this.updateChildren(view, pos); }
      +  }
      +
      +  if ( ViewDesc ) NodeViewDesc.__proto__ = ViewDesc;
      +  NodeViewDesc.prototype = Object.create( ViewDesc && ViewDesc.prototype );
      +  NodeViewDesc.prototype.constructor = NodeViewDesc;
      +
      +  var prototypeAccessors$3 = { size: { configurable: true },border: { configurable: true } };
      +
      +  // By default, a node is rendered using the `toDOM` method from the
      +  // node type spec. But client code can use the `nodeViews` spec to
      +  // supply a custom node view, which can influence various aspects of
      +  // the way the node works.
      +  //
      +  // (Using subclassing for this was intentionally decided against,
      +  // since it'd require exposing a whole slew of finnicky
      +  // implementation details to the user code that they probably will
      +  // never need.)
      +  NodeViewDesc.create = function create (parent, node, outerDeco, innerDeco, view, pos) {
      +    var assign;
      +
      +    var custom = view.nodeViews[node.type.name], descObj;
      +    var spec = custom && custom(node, view, function () {
      +      // (This is a function that allows the custom view to find its
      +      // own position)
      +      if (!descObj) { return pos }
      +      if (descObj.parent) { return descObj.parent.posBeforeChild(descObj) }
      +    }, outerDeco);
      +
      +    var dom = spec && spec.dom, contentDOM = spec && spec.contentDOM;
      +    if (node.isText) {
      +      if (!dom) { dom = document.createTextNode(node.text); }
      +      else if (dom.nodeType != 3) { throw new RangeError("Text must be rendered as a DOM text node") }
      +    } else if (!dom) {
      +((assign = prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["DOMSerializer"].renderSpec(document, node.type.spec.toDOM(node)), dom = assign.dom, contentDOM = assign.contentDOM));
      +    }
      +    if (!contentDOM && !node.isText && dom.nodeName != "BR") { // Chrome gets confused by 
      + if (!dom.hasAttribute("contenteditable")) { dom.contentEditable = false; } + if (node.type.spec.draggable) { dom.draggable = true; } + } + + var nodeDOM = dom; + dom = applyOuterDeco(dom, outerDeco, node); + + if (spec) + { return descObj = new CustomNodeViewDesc(parent, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM, + spec, view, pos + 1) } + else if (node.isText) + { return new TextViewDesc(parent, node, outerDeco, innerDeco, dom, nodeDOM, view) } + else + { return new NodeViewDesc(parent, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM, view, pos + 1) } + }; + + NodeViewDesc.prototype.parseRule = function parseRule () { + var this$1 = this; + + // Experimental kludge to allow opt-in re-parsing of nodes + if (this.node.type.spec.reparseInView) { return null } + // FIXME the assumption that this can always return the current + // attrs means that if the user somehow manages to change the + // attrs in the dom, that won't be picked up. Not entirely sure + // whether this is a problem + var rule = {node: this.node.type.name, attrs: this.node.attrs}; + if (this.node.type.spec.code) { rule.preserveWhitespace = "full"; } + if (this.contentDOM && !this.contentLost) { rule.contentElement = this.contentDOM; } + else { rule.getContent = function () { return this$1.contentDOM ? prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].empty : this$1.node.content; }; } + return rule + }; + + NodeViewDesc.prototype.matchesNode = function matchesNode (node, outerDeco, innerDeco) { + return this.dirty == NOT_DIRTY && node.eq(this.node) && + sameOuterDeco(outerDeco, this.outerDeco) && innerDeco.eq(this.innerDeco) + }; + + prototypeAccessors$3.size.get = function () { return this.node.nodeSize }; + + prototypeAccessors$3.border.get = function () { return this.node.isLeaf ? 0 : 1 }; + + // Syncs `this.children` to match `this.node.content` and the local + // decorations, possibly introducing nesting for marks. Then, in a + // separate step, syncs the DOM inside `this.contentDOM` to + // `this.children`. + NodeViewDesc.prototype.updateChildren = function updateChildren (view, pos) { + var this$1 = this; + + var inline = this.node.inlineContent, off = pos; + var composition = inline && view.composing && this.localCompositionNode(view, pos); + var updater = new ViewTreeUpdater(this, composition && composition.node); + iterDeco(this.node, this.innerDeco, function (widget, i) { + if (widget.spec.marks) + { updater.syncToMarks(widget.spec.marks, inline, view); } + else if (widget.type.side >= 0) + { updater.syncToMarks(i == this$1.node.childCount ? prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Mark"].none : this$1.node.child(i).marks, inline, view); } + // If the next node is a desc matching this widget, reuse it, + // otherwise insert the widget as a new view desc. + updater.placeWidget(widget, view, off); + }, function (child, outerDeco, innerDeco, i) { + // Make sure the wrapping mark descs match the node's marks. + updater.syncToMarks(child.marks, inline, view); + // Either find an existing desc that exactly matches this node, + // and drop the descs before it. + updater.findNodeMatch(child, outerDeco, innerDeco, i) || + // Or try updating the next desc to reflect this node. + updater.updateNextNode(child, outerDeco, innerDeco, view, i) || + // Or just add it as a new desc. + updater.addNode(child, outerDeco, innerDeco, view, off); + off += child.nodeSize; + }); + // Drop all remaining descs after the current position. + updater.syncToMarks(nothing, inline, view); + if (this.node.isTextblock) { updater.addTextblockHacks(); } + updater.destroyRest(); + + // Sync the DOM if anything changed + if (updater.changed || this.dirty == CONTENT_DIRTY) { + // May have to protect focused DOM from being changed if a composition is active + if (composition) { this.protectLocalComposition(view, composition); } + this.renderChildren(); + } + }; + + NodeViewDesc.prototype.renderChildren = function renderChildren () { + renderDescs(this.contentDOM, this.children); + if (result.ios) { iosHacks(this.dom); } + }; + + NodeViewDesc.prototype.localCompositionNode = function localCompositionNode (view, pos) { + // Only do something if both the selection and a focused text node + // are inside of this node, and the node isn't already part of a + // view that's a child of this view + var ref = view.state.selection; + var from = ref.from; + var to = ref.to; + if (!(view.state.selection instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"]) || from < pos || to > pos + this.node.content.size) { return } + var sel = view.root.getSelection(); + var textNode = nearbyTextNode(sel.focusNode, sel.focusOffset); + if (!textNode || !this.dom.contains(textNode.parentNode)) { return } + + // Find the text in the focused node in the node, stop if it's not + // there (may have been modified through other means, in which + // case it should overwritten) + var text = textNode.nodeValue; + var textPos = findTextInFragment(this.node.content, text, from - pos, to - pos); + + return textPos < 0 ? null : {node: textNode, pos: textPos, text: text} + }; + + NodeViewDesc.prototype.protectLocalComposition = function protectLocalComposition (view, ref) { + var node = ref.node; + var pos = ref.pos; + var text = ref.text; + + // The node is already part of a local view desc, leave it there + if (this.getDesc(node)) { return } + + // Create a composition view for the orphaned nodes + var topNode = node; + for (;; topNode = topNode.parentNode) { + if (topNode.parentNode == this.contentDOM) { break } + while (topNode.previousSibling) { topNode.parentNode.removeChild(topNode.previousSibling); } + while (topNode.nextSibling) { topNode.parentNode.removeChild(topNode.nextSibling); } + if (topNode.pmViewDesc) { topNode.pmViewDesc = null; } + } + var desc = new CompositionViewDesc(this, topNode, node, text); + view.compositionNodes.push(desc); + + // Patch up this.children to contain the composition view + this.children = replaceNodes(this.children, pos, pos + text.length, view, desc); + }; + + // : (Node, [Decoration], DecorationSet, EditorView) → bool + // If this desc be updated to match the given node decoration, + // do so and return true. + NodeViewDesc.prototype.update = function update (node, outerDeco, innerDeco, view) { + if (this.dirty == NODE_DIRTY || + !node.sameMarkup(this.node)) { return false } + this.updateInner(node, outerDeco, innerDeco, view); + return true + }; + + NodeViewDesc.prototype.updateInner = function updateInner (node, outerDeco, innerDeco, view) { + this.updateOuterDeco(outerDeco); + this.node = node; + this.innerDeco = innerDeco; + if (this.contentDOM) { this.updateChildren(view, this.posAtStart); } + this.dirty = NOT_DIRTY; + }; + + NodeViewDesc.prototype.updateOuterDeco = function updateOuterDeco (outerDeco) { + if (sameOuterDeco(outerDeco, this.outerDeco)) { return } + var needsWrap = this.nodeDOM.nodeType != 1; + var oldDOM = this.dom; + this.dom = patchOuterDeco(this.dom, this.nodeDOM, + computeOuterDeco(this.outerDeco, this.node, needsWrap), + computeOuterDeco(outerDeco, this.node, needsWrap)); + if (this.dom != oldDOM) { + oldDOM.pmViewDesc = null; + this.dom.pmViewDesc = this; + } + this.outerDeco = outerDeco; + }; + + // Mark this node as being the selected node. + NodeViewDesc.prototype.selectNode = function selectNode () { + this.nodeDOM.classList.add("ProseMirror-selectednode"); + if (this.contentDOM || !this.node.type.spec.draggable) { this.dom.draggable = true; } + }; + + // Remove selected node marking from this node. + NodeViewDesc.prototype.deselectNode = function deselectNode () { + this.nodeDOM.classList.remove("ProseMirror-selectednode"); + if (this.contentDOM || !this.node.type.spec.draggable) { this.dom.draggable = false; } + }; + + Object.defineProperties( NodeViewDesc.prototype, prototypeAccessors$3 ); + + return NodeViewDesc; +}(ViewDesc)); + +// Create a view desc for the top-level document node, to be exported +// and used by the view class. +function docViewDesc(doc, outerDeco, innerDeco, dom, view) { + applyOuterDeco(dom, outerDeco, doc); + return new NodeViewDesc(null, doc, outerDeco, innerDeco, dom, dom, dom, view, 0) +} + +var TextViewDesc = /*@__PURE__*/(function (NodeViewDesc) { + function TextViewDesc(parent, node, outerDeco, innerDeco, dom, nodeDOM, view) { + NodeViewDesc.call(this, parent, node, outerDeco, innerDeco, dom, null, nodeDOM, view); + } + + if ( NodeViewDesc ) TextViewDesc.__proto__ = NodeViewDesc; + TextViewDesc.prototype = Object.create( NodeViewDesc && NodeViewDesc.prototype ); + TextViewDesc.prototype.constructor = TextViewDesc; + + TextViewDesc.prototype.parseRule = function parseRule () { + return {skip: this.nodeDOM.parentNode || true} + }; + + TextViewDesc.prototype.update = function update (node, outerDeco) { + if (this.dirty == NODE_DIRTY || (this.dirty != NOT_DIRTY && !this.inParent()) || + !node.sameMarkup(this.node)) { return false } + this.updateOuterDeco(outerDeco); + if ((this.dirty != NOT_DIRTY || node.text != this.node.text) && node.text != this.nodeDOM.nodeValue) + { this.nodeDOM.nodeValue = node.text; } + this.node = node; + this.dirty = NOT_DIRTY; + return true + }; + + TextViewDesc.prototype.inParent = function inParent () { + var parentDOM = this.parent.contentDOM; + for (var n = this.nodeDOM; n; n = n.parentNode) { if (n == parentDOM) { return true } } + return false + }; + + TextViewDesc.prototype.domFromPos = function domFromPos (pos) { + return {node: this.nodeDOM, offset: pos} + }; + + TextViewDesc.prototype.localPosFromDOM = function localPosFromDOM (dom, offset, bias) { + if (dom == this.nodeDOM) { return this.posAtStart + Math.min(offset, this.node.text.length) } + return NodeViewDesc.prototype.localPosFromDOM.call(this, dom, offset, bias) + }; + + TextViewDesc.prototype.ignoreMutation = function ignoreMutation (mutation) { + return mutation.type != "characterData" && mutation.type != "selection" + }; + + TextViewDesc.prototype.slice = function slice (from, to, view) { + var node = this.node.cut(from, to), dom = document.createTextNode(node.text); + return new TextViewDesc(this.parent, node, this.outerDeco, this.innerDeco, dom, dom, view) + }; + + return TextViewDesc; +}(NodeViewDesc)); + +// A dummy desc used to tag trailing BR or span nodes created to work +// around contentEditable terribleness. +var BRHackViewDesc = /*@__PURE__*/(function (ViewDesc) { + function BRHackViewDesc () { + ViewDesc.apply(this, arguments); + } + + if ( ViewDesc ) BRHackViewDesc.__proto__ = ViewDesc; + BRHackViewDesc.prototype = Object.create( ViewDesc && ViewDesc.prototype ); + BRHackViewDesc.prototype.constructor = BRHackViewDesc; + + BRHackViewDesc.prototype.parseRule = function parseRule () { return {ignore: true} }; + BRHackViewDesc.prototype.matchesHack = function matchesHack () { return this.dirty == NOT_DIRTY }; + + return BRHackViewDesc; +}(ViewDesc)); + +// A separate subclass is used for customized node views, so that the +// extra checks only have to be made for nodes that are actually +// customized. +var CustomNodeViewDesc = /*@__PURE__*/(function (NodeViewDesc) { + function CustomNodeViewDesc(parent, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM, spec, view, pos) { + NodeViewDesc.call(this, parent, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM, view, pos); + this.spec = spec; + } + + if ( NodeViewDesc ) CustomNodeViewDesc.__proto__ = NodeViewDesc; + CustomNodeViewDesc.prototype = Object.create( NodeViewDesc && NodeViewDesc.prototype ); + CustomNodeViewDesc.prototype.constructor = CustomNodeViewDesc; + + // A custom `update` method gets to decide whether the update goes + // through. If it does, and there's a `contentDOM` node, our logic + // updates the children. + CustomNodeViewDesc.prototype.update = function update (node, outerDeco, innerDeco, view) { + if (this.dirty == NODE_DIRTY) { return false } + if (this.spec.update) { + var result = this.spec.update(node, outerDeco); + if (result) { this.updateInner(node, outerDeco, innerDeco, view); } + return result + } else if (!this.contentDOM && !node.isLeaf) { + return false + } else { + return NodeViewDesc.prototype.update.call(this, node, outerDeco, innerDeco, view) + } + }; + + CustomNodeViewDesc.prototype.selectNode = function selectNode () { + this.spec.selectNode ? this.spec.selectNode() : NodeViewDesc.prototype.selectNode.call(this); + }; + + CustomNodeViewDesc.prototype.deselectNode = function deselectNode () { + this.spec.deselectNode ? this.spec.deselectNode() : NodeViewDesc.prototype.deselectNode.call(this); + }; + + CustomNodeViewDesc.prototype.setSelection = function setSelection (anchor, head, root, force) { + this.spec.setSelection ? this.spec.setSelection(anchor, head, root) + : NodeViewDesc.prototype.setSelection.call(this, anchor, head, root, force); + }; + + CustomNodeViewDesc.prototype.destroy = function destroy () { + if (this.spec.destroy) { this.spec.destroy(); } + NodeViewDesc.prototype.destroy.call(this); + }; + + CustomNodeViewDesc.prototype.stopEvent = function stopEvent (event) { + return this.spec.stopEvent ? this.spec.stopEvent(event) : false + }; + + CustomNodeViewDesc.prototype.ignoreMutation = function ignoreMutation (mutation) { + return this.spec.ignoreMutation ? this.spec.ignoreMutation(mutation) : NodeViewDesc.prototype.ignoreMutation.call(this, mutation) + }; + + return CustomNodeViewDesc; +}(NodeViewDesc)); + +// : (dom.Node, [ViewDesc]) +// Sync the content of the given DOM node with the nodes associated +// with the given array of view descs, recursing into mark descs +// because this should sync the subtree for a whole node at a time. +function renderDescs(parentDOM, descs) { + var dom = parentDOM.firstChild; + for (var i = 0; i < descs.length; i++) { + var desc = descs[i], childDOM = desc.dom; + if (childDOM.parentNode == parentDOM) { + while (childDOM != dom) { dom = rm(dom); } + dom = dom.nextSibling; + } else { + parentDOM.insertBefore(childDOM, dom); + } + if (desc instanceof MarkViewDesc) { + var pos = dom ? dom.previousSibling : parentDOM.lastChild; + renderDescs(desc.contentDOM, desc.children); + dom = pos ? pos.nextSibling : parentDOM.firstChild; + } + } + while (dom) { dom = rm(dom); } +} + +function OuterDecoLevel(nodeName) { + if (nodeName) { this.nodeName = nodeName; } +} +OuterDecoLevel.prototype = Object.create(null); + +var noDeco = [new OuterDecoLevel]; + +function computeOuterDeco(outerDeco, node, needsWrap) { + if (outerDeco.length == 0) { return noDeco } + + var top = needsWrap ? noDeco[0] : new OuterDecoLevel, result = [top]; + + for (var i = 0; i < outerDeco.length; i++) { + var attrs = outerDeco[i].type.attrs, cur = top; + if (!attrs) { continue } + if (attrs.nodeName) + { result.push(cur = new OuterDecoLevel(attrs.nodeName)); } + + for (var name in attrs) { + var val = attrs[name]; + if (val == null) { continue } + if (needsWrap && result.length == 1) + { result.push(cur = top = new OuterDecoLevel(node.isInline ? "span" : "div")); } + if (name == "class") { cur.class = (cur.class ? cur.class + " " : "") + val; } + else if (name == "style") { cur.style = (cur.style ? cur.style + ";" : "") + val; } + else if (name != "nodeName") { cur[name] = val; } + } + } + + return result +} + +function patchOuterDeco(outerDOM, nodeDOM, prevComputed, curComputed) { + // Shortcut for trivial case + if (prevComputed == noDeco && curComputed == noDeco) { return nodeDOM } + + var curDOM = nodeDOM; + for (var i = 0; i < curComputed.length; i++) { + var deco = curComputed[i], prev = prevComputed[i]; + if (i) { + var parent = (void 0); + if (prev && prev.nodeName == deco.nodeName && curDOM != outerDOM && + (parent = nodeDOM.parentNode) && parent.tagName.toLowerCase() == deco.nodeName) { + curDOM = parent; + } else { + parent = document.createElement(deco.nodeName); + parent.appendChild(curDOM); + curDOM = parent; + } + } + patchAttributes(curDOM, prev || noDeco[0], deco); + } + return curDOM +} + +function patchAttributes(dom, prev, cur) { + for (var name in prev) + { if (name != "class" && name != "style" && name != "nodeName" && !(name in cur)) + { dom.removeAttribute(name); } } + for (var name$1 in cur) + { if (name$1 != "class" && name$1 != "style" && name$1 != "nodeName" && cur[name$1] != prev[name$1]) + { dom.setAttribute(name$1, cur[name$1]); } } + if (prev.class != cur.class) { + var prevList = prev.class ? prev.class.split(" ") : nothing; + var curList = cur.class ? cur.class.split(" ") : nothing; + for (var i = 0; i < prevList.length; i++) { if (curList.indexOf(prevList[i]) == -1) + { dom.classList.remove(prevList[i]); } } + for (var i$1 = 0; i$1 < curList.length; i$1++) { if (prevList.indexOf(curList[i$1]) == -1) + { dom.classList.add(curList[i$1]); } } + } + if (prev.style != cur.style) { + if (prev.style) { + var prop = /\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g, m; + while (m = prop.exec(prev.style)) + { dom.style[m[1].toLowerCase()] = ""; } + } + if (cur.style) + { dom.style.cssText += cur.style; } + } +} + +function applyOuterDeco(dom, deco, node) { + return patchOuterDeco(dom, dom, noDeco, computeOuterDeco(deco, node, dom.nodeType != 1)) +} + +// : ([Decoration], [Decoration]) → bool +function sameOuterDeco(a, b) { + if (a.length != b.length) { return false } + for (var i = 0; i < a.length; i++) { if (!a[i].type.eq(b[i].type)) { return false } } + return true +} + +// Remove a DOM node and return its next sibling. +function rm(dom) { + var next = dom.nextSibling; + dom.parentNode.removeChild(dom); + return next +} + +// Helper class for incrementally updating a tree of mark descs and +// the widget and node descs inside of them. +var ViewTreeUpdater = function ViewTreeUpdater(top, lockedNode) { + this.top = top; + this.lock = lockedNode; + // Index into `this.top`'s child array, represents the current + // update position. + this.index = 0; + // When entering a mark, the current top and index are pushed + // onto this. + this.stack = []; + // Tracks whether anything was changed + this.changed = false; + + var pre = preMatch(top.node.content, top.children); + this.preMatched = pre.nodes; + this.preMatchOffset = pre.offset; +}; + +ViewTreeUpdater.prototype.getPreMatch = function getPreMatch (index) { + return index >= this.preMatchOffset ? this.preMatched[index - this.preMatchOffset] : null +}; + +// Destroy and remove the children between the given indices in +// `this.top`. +ViewTreeUpdater.prototype.destroyBetween = function destroyBetween (start, end) { + if (start == end) { return } + for (var i = start; i < end; i++) { this.top.children[i].destroy(); } + this.top.children.splice(start, end - start); + this.changed = true; +}; + +// Destroy all remaining children in `this.top`. +ViewTreeUpdater.prototype.destroyRest = function destroyRest () { + this.destroyBetween(this.index, this.top.children.length); +}; + +// : ([Mark], EditorView) +// Sync the current stack of mark descs with the given array of +// marks, reusing existing mark descs when possible. +ViewTreeUpdater.prototype.syncToMarks = function syncToMarks (marks, inline, view) { + var keep = 0, depth = this.stack.length >> 1; + var maxKeep = Math.min(depth, marks.length); + while (keep < maxKeep && + (keep == depth - 1 ? this.top : this.stack[(keep + 1) << 1]).matchesMark(marks[keep]) && marks[keep].type.spec.spanning !== false) + { keep++; } + + while (keep < depth) { + this.destroyRest(); + this.top.dirty = NOT_DIRTY; + this.index = this.stack.pop(); + this.top = this.stack.pop(); + depth--; + } + while (depth < marks.length) { + this.stack.push(this.top, this.index + 1); + var found = -1; + for (var i = this.index; i < Math.min(this.index + 3, this.top.children.length); i++) { + if (this.top.children[i].matchesMark(marks[depth])) { found = i; break } + } + if (found > -1) { + if (found > this.index) { + this.changed = true; + this.destroyBetween(this.index, found); + } + this.top = this.top.children[this.index]; + } else { + var markDesc = MarkViewDesc.create(this.top, marks[depth], inline, view); + this.top.children.splice(this.index, 0, markDesc); + this.top = markDesc; + this.changed = true; + } + this.index = 0; + depth++; + } +}; + +// : (Node, [Decoration], DecorationSet) → bool +// Try to find a node desc matching the given data. Skip over it and +// return true when successful. +ViewTreeUpdater.prototype.findNodeMatch = function findNodeMatch (node, outerDeco, innerDeco, index) { + var found = -1, preMatch = index < 0 ? undefined : this.getPreMatch(index), children = this.top.children; + if (preMatch && preMatch.matchesNode(node, outerDeco, innerDeco)) { + found = children.indexOf(preMatch); + } else { + for (var i = this.index, e = Math.min(children.length, i + 5); i < e; i++) { + var child = children[i]; + if (child.matchesNode(node, outerDeco, innerDeco) && this.preMatched.indexOf(child) < 0) { + found = i; + break + } + } + } + if (found < 0) { return false } + this.destroyBetween(this.index, found); + this.index++; + return true +}; + +// : (Node, [Decoration], DecorationSet, EditorView, Fragment, number) → bool +// Try to update the next node, if any, to the given data. Checks +// pre-matches to avoid overwriting nodes that could still be used. +ViewTreeUpdater.prototype.updateNextNode = function updateNextNode (node, outerDeco, innerDeco, view, index) { + if (this.index == this.top.children.length) { return false } + var next = this.top.children[this.index]; + if (next instanceof NodeViewDesc) { + var preMatch = this.preMatched.indexOf(next); + if (preMatch > -1 && preMatch + this.preMatchOffset != index) { return false } + var nextDOM = next.dom; + + // Can't update if nextDOM is or contains this.lock, except if + // it's a text node whose content already matches the new text + // and whose decorations match the new ones. + var locked = this.lock && (nextDOM == this.lock || nextDOM.nodeType == 1 && nextDOM.contains(this.lock.parentNode)) && + !(node.isText && next.node && next.node.isText && next.nodeDOM.nodeValue == node.text && + next.dirty != NODE_DIRTY && sameOuterDeco(outerDeco, next.outerDeco)); + if (!locked && next.update(node, outerDeco, innerDeco, view)) { + if (next.dom != nextDOM) { this.changed = true; } + this.index++; + return true + } + } + return false +}; + +// : (Node, [Decoration], DecorationSet, EditorView) +// Insert the node as a newly created node desc. +ViewTreeUpdater.prototype.addNode = function addNode (node, outerDeco, innerDeco, view, pos) { + this.top.children.splice(this.index++, 0, NodeViewDesc.create(this.top, node, outerDeco, innerDeco, view, pos)); + this.changed = true; +}; + +ViewTreeUpdater.prototype.placeWidget = function placeWidget (widget, view, pos) { + if (this.index < this.top.children.length && this.top.children[this.index].matchesWidget(widget)) { + this.index++; + } else { + var desc = new WidgetViewDesc(this.top, widget, view, pos); + this.top.children.splice(this.index++, 0, desc); + this.changed = true; + } +}; + +// Make sure a textblock looks and behaves correctly in +// contentEditable. +ViewTreeUpdater.prototype.addTextblockHacks = function addTextblockHacks () { + var lastChild = this.top.children[this.index - 1]; + while (lastChild instanceof MarkViewDesc) { lastChild = lastChild.children[lastChild.children.length - 1]; } + + if (!lastChild || // Empty textblock + !(lastChild instanceof TextViewDesc) || + /\n$/.test(lastChild.node.text)) { + if (this.index < this.top.children.length && this.top.children[this.index].matchesHack()) { + this.index++; + } else { + var dom = document.createElement("br"); + this.top.children.splice(this.index++, 0, new BRHackViewDesc(this.top, nothing, dom, null)); + this.changed = true; + } + } +}; + +// : (Fragment, [ViewDesc]) → [ViewDesc] +// Iterate from the end of the fragment and array of descs to find +// directly matching ones, in order to avoid overeagerly reusing +// those for other nodes. Returns an array whose positions correspond +// to node positions in the fragment, and whose elements are either +// descs matched to the child at that index, or empty. +function preMatch(frag, descs) { + var result = [], end = frag.childCount; + for (var i = descs.length - 1; end > 0 && i >= 0; i--) { + var desc = descs[i], node = desc.node; + if (!node) { continue } + if (node != frag.child(end - 1)) { break } + result.push(desc); + --end; + } + return {nodes: result.reverse(), offset: end} +} + +function compareSide(a, b) { return a.type.side - b.type.side } + +// : (ViewDesc, DecorationSet, (Decoration, number), (Node, [Decoration], DecorationSet, number)) +// This function abstracts iterating over the nodes and decorations in +// a fragment. Calls `onNode` for each node, with its local and child +// decorations. Splits text nodes when there is a decoration starting +// or ending inside of them. Calls `onWidget` for each widget. +function iterDeco(parent, deco, onWidget, onNode) { + var locals = deco.locals(parent), offset = 0; + // Simple, cheap variant for when there are no local decorations + if (locals.length == 0) { + for (var i = 0; i < parent.childCount; i++) { + var child = parent.child(i); + onNode(child, locals, deco.forChild(offset, child), i); + offset += child.nodeSize; + } + return + } + + var decoIndex = 0, active = [], restNode = null; + for (var parentIndex = 0;;) { + if (decoIndex < locals.length && locals[decoIndex].to == offset) { + var widget = locals[decoIndex++], widgets = (void 0); + while (decoIndex < locals.length && locals[decoIndex].to == offset) + { (widgets || (widgets = [widget])).push(locals[decoIndex++]); } + if (widgets) { + widgets.sort(compareSide); + for (var i$1 = 0; i$1 < widgets.length; i$1++) { onWidget(widgets[i$1], parentIndex); } + } else { + onWidget(widget, parentIndex); + } + } + + var child$1 = (void 0), index = (void 0); + if (restNode) { + index = -1; + child$1 = restNode; + restNode = null; + } else if (parentIndex < parent.childCount) { + index = parentIndex; + child$1 = parent.child(parentIndex++); + } else { + break + } + + for (var i$2 = 0; i$2 < active.length; i$2++) { if (active[i$2].to <= offset) { active.splice(i$2--, 1); } } + while (decoIndex < locals.length && locals[decoIndex].from == offset) { active.push(locals[decoIndex++]); } + + var end = offset + child$1.nodeSize; + if (child$1.isText) { + var cutAt = end; + if (decoIndex < locals.length && locals[decoIndex].from < cutAt) { cutAt = locals[decoIndex].from; } + for (var i$3 = 0; i$3 < active.length; i$3++) { if (active[i$3].to < cutAt) { cutAt = active[i$3].to; } } + if (cutAt < end) { + restNode = child$1.cut(cutAt - offset); + child$1 = child$1.cut(0, cutAt - offset); + end = cutAt; + index = -1; + } + } + + onNode(child$1, active.length ? active.slice() : nothing, deco.forChild(offset, child$1), index); + offset = end; + } +} + +// List markers in Mobile Safari will mysteriously disappear +// sometimes. This works around that. +function iosHacks(dom) { + if (dom.nodeName == "UL" || dom.nodeName == "OL") { + var oldCSS = dom.style.cssText; + dom.style.cssText = oldCSS + "; list-style: square !important"; + window.getComputedStyle(dom).listStyle; + dom.style.cssText = oldCSS; + } +} + +function nearbyTextNode(node, offset) { + for (;;) { + if (node.nodeType == 3) { return node } + if (node.nodeType == 1 && offset > 0) { + if (node.childNodes.length > offset && node.childNodes[offset].nodeType == 3) + { return node.childNodes[offset] } + node = node.childNodes[offset - 1]; + offset = nodeSize(node); + } else if (node.nodeType == 1 && offset < node.childNodes.length) { + node = node.childNodes[offset]; + offset = 0; + } else { + return null + } + } +} + +// Find a piece of text in an inline fragment, overlapping from-to +function findTextInFragment(frag, text, from, to) { + for (var str = "", i = 0, childPos = 0; i < frag.childCount; i++) { + var child = frag.child(i), end = childPos + child.nodeSize; + if (child.isText) { + str += child.text; + if (end >= to) { + var strStart = end - str.length, found = str.lastIndexOf(text); + while (found > -1 && strStart + found > from) { found = str.lastIndexOf(text, found - 1); } + if (found > -1 && strStart + found + text.length >= to) { + return strStart + found + } else if (end > to) { + break + } + } + } else { + str = ""; + } + childPos = end; + } + return -1 +} + +// Replace range from-to in an array of view descs with replacement +// (may be null to just delete). This goes very much against the grain +// of the rest of this code, which tends to create nodes with the +// right shape in one go, rather than messing with them after +// creation, but is necessary in the composition hack. +function replaceNodes(nodes, from, to, view, replacement) { + var result = []; + for (var i = 0, off = 0; i < nodes.length; i++) { + var child = nodes[i], start = off, end = off += child.size; + if (start >= to || end <= from) { + result.push(child); + } else { + if (start < from) { result.push(child.slice(0, from - start, view)); } + if (replacement) { + result.push(replacement); + replacement = null; + } + if (end > to) { result.push(child.slice(to - start, child.size, view)); } + } + } + return result +} + +function moveSelectionBlock(state, dir) { + var ref = state.selection; + var $anchor = ref.$anchor; + var $head = ref.$head; + var $side = dir > 0 ? $anchor.max($head) : $anchor.min($head); + var $start = !$side.parent.inlineContent ? $side : $side.depth ? state.doc.resolve(dir > 0 ? $side.after() : $side.before()) : null; + return $start && prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["Selection"].findFrom($start, dir) +} + +function apply(view, sel) { + view.dispatch(view.state.tr.setSelection(sel).scrollIntoView()); + return true +} + +function selectHorizontally(view, dir, mods) { + var sel = view.state.selection; + if (sel instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"]) { + if (!sel.empty || mods.indexOf("s") > -1) { + return false + } else if (view.endOfTextblock(dir > 0 ? "right" : "left")) { + var next = moveSelectionBlock(view.state, dir); + if (next && (next instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["NodeSelection"])) { return apply(view, next) } + return false + } else { + var $head = sel.$head, node = $head.textOffset ? null : dir < 0 ? $head.nodeBefore : $head.nodeAfter, desc; + if (!node || node.isText) { return false } + var nodePos = dir < 0 ? $head.pos - node.nodeSize : $head.pos; + if (!(node.isAtom || (desc = view.docView.descAt(nodePos)) && !desc.contentDOM)) { return false } + if (prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["NodeSelection"].isSelectable(node)) { + return apply(view, new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["NodeSelection"](dir < 0 ? view.state.doc.resolve($head.pos - node.nodeSize) : $head)) + } else if (result.webkit) { + // Chrome and Safari will introduce extra pointless cursor + // positions around inline uneditable nodes, so we have to + // take over and move the cursor past them (#937) + return apply(view, new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"](view.state.doc.resolve(dir < 0 ? nodePos : nodePos + node.nodeSize))) + } else { + return false + } + } + } else if (sel instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["NodeSelection"] && sel.node.isInline) { + return apply(view, new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"](dir > 0 ? sel.$to : sel.$from)) + } else { + var next$1 = moveSelectionBlock(view.state, dir); + if (next$1) { return apply(view, next$1) } + return false + } +} + +function nodeLen(node) { + return node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length +} + +function isIgnorable(dom) { + var desc = dom.pmViewDesc; + return desc && desc.size == 0 && (dom.nextSibling || dom.nodeName != "BR") +} + +// Make sure the cursor isn't directly after one or more ignored +// nodes, which will confuse the browser's cursor motion logic. +function skipIgnoredNodesLeft(view) { + var sel = view.root.getSelection(); + var node = sel.focusNode, offset = sel.focusOffset; + if (!node) { return } + var moveNode, moveOffset, force = false; + // Gecko will do odd things when the selection is directly in front + // of a non-editable node, so in that case, move it into the next + // node if possible. Issue prosemirror/prosemirror#832. + if (result.gecko && node.nodeType == 1 && offset < nodeLen(node) && isIgnorable(node.childNodes[offset])) { force = true; } + for (;;) { + if (offset > 0) { + if (node.nodeType != 1) { + break + } else { + var before = node.childNodes[offset - 1]; + if (isIgnorable(before)) { + moveNode = node; + moveOffset = --offset; + } else if (before.nodeType == 3) { + node = before; + offset = node.nodeValue.length; + } else { break } + } + } else if (isBlockNode(node)) { + break + } else { + var prev = node.previousSibling; + while (prev && isIgnorable(prev)) { + moveNode = node.parentNode; + moveOffset = domIndex(prev); + prev = prev.previousSibling; + } + if (!prev) { + node = node.parentNode; + if (node == view.dom) { break } + offset = 0; + } else { + node = prev; + offset = nodeLen(node); + } + } + } + if (force) { setSelFocus(view, sel, node, offset); } + else if (moveNode) { setSelFocus(view, sel, moveNode, moveOffset); } +} + +// Make sure the cursor isn't directly before one or more ignored +// nodes. +function skipIgnoredNodesRight(view) { + var sel = view.root.getSelection(); + var node = sel.focusNode, offset = sel.focusOffset; + if (!node) { return } + var len = nodeLen(node); + var moveNode, moveOffset; + for (;;) { + if (offset < len) { + if (node.nodeType != 1) { break } + var after = node.childNodes[offset]; + if (isIgnorable(after)) { + moveNode = node; + moveOffset = ++offset; + } + else { break } + } else if (isBlockNode(node)) { + break + } else { + var next = node.nextSibling; + while (next && isIgnorable(next)) { + moveNode = next.parentNode; + moveOffset = domIndex(next) + 1; + next = next.nextSibling; + } + if (!next) { + node = node.parentNode; + if (node == view.dom) { break } + offset = len = 0; + } else { + node = next; + offset = 0; + len = nodeLen(node); + } + } + } + if (moveNode) { setSelFocus(view, sel, moveNode, moveOffset); } +} + +function isBlockNode(dom) { + var desc = dom.pmViewDesc; + return desc && desc.node && desc.node.isBlock +} + +function setSelFocus(view, sel, node, offset) { + if (selectionCollapsed(sel)) { + var range = document.createRange(); + range.setEnd(node, offset); + range.setStart(node, offset); + sel.removeAllRanges(); + sel.addRange(range); + } else if (sel.extend) { + sel.extend(node, offset); + } + view.domObserver.setCurSelection(); +} + +// : (EditorState, number) +// Check whether vertical selection motion would involve node +// selections. If so, apply it (if not, the result is left to the +// browser) +function selectVertically(view, dir, mods) { + var sel = view.state.selection; + if (sel instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"] && !sel.empty || mods.indexOf("s") > -1) { return false } + var $from = sel.$from; + var $to = sel.$to; + + if (!$from.parent.inlineContent || view.endOfTextblock(dir < 0 ? "up" : "down")) { + var next = moveSelectionBlock(view.state, dir); + if (next && (next instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["NodeSelection"])) + { return apply(view, next) } + } + if (!$from.parent.inlineContent) { + var beyond = prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["Selection"].findFrom(dir < 0 ? $from : $to, dir); + return beyond ? apply(view, beyond) : true + } + return false +} + +function stopNativeHorizontalDelete(view, dir) { + if (!(view.state.selection instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"])) { return true } + var ref = view.state.selection; + var $head = ref.$head; + var $anchor = ref.$anchor; + var empty = ref.empty; + if (!$head.sameParent($anchor)) { return true } + if (!empty) { return false } + if (view.endOfTextblock(dir > 0 ? "forward" : "backward")) { return true } + var nextNode = !$head.textOffset && (dir < 0 ? $head.nodeBefore : $head.nodeAfter); + if (nextNode && !nextNode.isText) { + var tr = view.state.tr; + if (dir < 0) { tr.delete($head.pos - nextNode.nodeSize, $head.pos); } + else { tr.delete($head.pos, $head.pos + nextNode.nodeSize); } + view.dispatch(tr); + return true + } + return false +} + +function switchEditable(view, node, state) { + view.domObserver.stop(); + node.contentEditable = state; + view.domObserver.start(); +} + +// Issue #867 / https://bugs.chromium.org/p/chromium/issues/detail?id=903821 +// In which Chrome does really wrong things when the down arrow is +// pressed when the cursor is directly at the start of a textblock and +// has an uneditable node after it +function chromeDownArrowBug(view) { + if (!result.chrome || view.state.selection.$head.parentOffset > 0) { return } + var ref = view.root.getSelection(); + var focusNode = ref.focusNode; + var focusOffset = ref.focusOffset; + if (focusNode && focusNode.nodeType == 1 && focusOffset == 0 && + focusNode.firstChild && focusNode.firstChild.contentEditable == "false") { + var child = focusNode.firstChild; + switchEditable(view, child, true); + setTimeout(function () { return switchEditable(view, child, false); }, 20); + } +} + +// A backdrop key mapping used to make sure we always suppress keys +// that have a dangerous default effect, even if the commands they are +// bound to return false, and to make sure that cursor-motion keys +// find a cursor (as opposed to a node selection) when pressed. For +// cursor-motion keys, the code in the handlers also takes care of +// block selections. + +function getMods(event) { + var result = ""; + if (event.ctrlKey) { result += "c"; } + if (event.metaKey) { result += "m"; } + if (event.altKey) { result += "a"; } + if (event.shiftKey) { result += "s"; } + return result +} + +function captureKeyDown(view, event) { + var code = event.keyCode, mods = getMods(event); + if (code == 8 || (result.mac && code == 72 && mods == "c")) { // Backspace, Ctrl-h on Mac + return stopNativeHorizontalDelete(view, -1) || skipIgnoredNodesLeft(view) + } else if (code == 46 || (result.mac && code == 68 && mods == "c")) { // Delete, Ctrl-d on Mac + return stopNativeHorizontalDelete(view, 1) || skipIgnoredNodesRight(view) + } else if (code == 13 || code == 27) { // Enter, Esc + return true + } else if (code == 37) { // Left arrow + return selectHorizontally(view, -1, mods) || skipIgnoredNodesLeft(view) + } else if (code == 39) { // Right arrow + return selectHorizontally(view, 1, mods) || skipIgnoredNodesRight(view) + } else if (code == 38) { // Up arrow + return selectVertically(view, -1, mods) || skipIgnoredNodesLeft(view) + } else if (code == 40) { // Down arrow + return chromeDownArrowBug(view) || selectVertically(view, 1, mods) || skipIgnoredNodesRight(view) + } else if (mods == (result.mac ? "m" : "c") && + (code == 66 || code == 73 || code == 89 || code == 90)) { // Mod-[biyz] + return true + } + return false +} + +function selectionFromDOM(view, origin) { + var domSel = view.root.getSelection(), doc = view.state.doc; + var nearestDesc = view.docView.nearestDesc(domSel.focusNode), inWidget = nearestDesc && nearestDesc.size == 0; + var head = view.docView.posFromDOM(domSel.focusNode, domSel.focusOffset); + var $head = doc.resolve(head), $anchor, selection; + if (selectionCollapsed(domSel)) { + $anchor = $head; + while (nearestDesc && !nearestDesc.node) { nearestDesc = nearestDesc.parent; } + if (nearestDesc && nearestDesc.node.isAtom && prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["NodeSelection"].isSelectable(nearestDesc.node) && nearestDesc.parent) { + var pos = nearestDesc.posBefore; + selection = new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["NodeSelection"](head == pos ? $head : doc.resolve(pos)); + } + } else { + $anchor = doc.resolve(view.docView.posFromDOM(domSel.anchorNode, domSel.anchorOffset)); + } + + if (!selection) { + var bias = origin == "pointer" || (view.state.selection.head < $head.pos && !inWidget) ? 1 : -1; + selection = selectionBetween(view, $anchor, $head, bias); + } + return selection +} + +function selectionToDOM(view, force) { + var sel = view.state.selection; + syncNodeSelection(view, sel); + + if (view.editable ? !view.hasFocus() : !(hasSelection(view) && document.activeElement.contains(view.dom))) { return } + + view.domObserver.disconnectSelection(); + + if (view.cursorWrapper) { + selectCursorWrapper(view); + } else { + var anchor = sel.anchor; + var head = sel.head; + var resetEditableFrom, resetEditableTo; + if (brokenSelectBetweenUneditable && !(sel instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"])) { + if (!sel.$from.parent.inlineContent) + { resetEditableFrom = temporarilyEditableNear(view, sel.from); } + if (!sel.empty && !sel.$from.parent.inlineContent) + { resetEditableTo = temporarilyEditableNear(view, sel.to); } + } + view.docView.setSelection(anchor, head, view.root, force); + if (brokenSelectBetweenUneditable) { + if (resetEditableFrom) { resetEditableFrom.contentEditable = "false"; } + if (resetEditableTo) { resetEditableTo.contentEditable = "false"; } + } + if (sel.visible) { + view.dom.classList.remove("ProseMirror-hideselection"); + } else if (anchor != head) { + view.dom.classList.add("ProseMirror-hideselection"); + if ("onselectionchange" in document) { removeClassOnSelectionChange(view); } + } + } + + view.domObserver.setCurSelection(); + view.domObserver.connectSelection(); +} + +// Kludge to work around Webkit not allowing a selection to start/end +// between non-editable block nodes. We briefly make something +// editable, set the selection, then set it uneditable again. + +var brokenSelectBetweenUneditable = result.safari || result.chrome && result.chrome_version < 63; + +function temporarilyEditableNear(view, pos) { + var ref = view.docView.domFromPos(pos); + var node = ref.node; + var offset = ref.offset; + var after = offset < node.childNodes.length ? node.childNodes[offset] : null; + var before = offset ? node.childNodes[offset - 1] : null; + if ((!after || after.contentEditable == "false") && (!before || before.contentEditable == "false")) { + if (after) { + after.contentEditable = "true"; + return after + } else if (before) { + before.contentEditable = "true"; + return before + } + } +} + +function removeClassOnSelectionChange(view) { + var doc = view.dom.ownerDocument; + doc.removeEventListener("selectionchange", view.hideSelectionGuard); + var domSel = view.root.getSelection(); + var node = domSel.anchorNode, offset = domSel.anchorOffset; + doc.addEventListener("selectionchange", view.hideSelectionGuard = function () { + if (domSel.anchorNode != node || domSel.anchorOffset != offset) { + doc.removeEventListener("selectionchange", view.hideSelectionGuard); + view.dom.classList.remove("ProseMirror-hideselection"); + } + }); +} + +function selectCursorWrapper(view) { + var domSel = view.root.getSelection(), range = document.createRange(); + var node = view.cursorWrapper.dom, img = node.nodeName == "IMG"; + if (img) { range.setEnd(node.parentNode, domIndex(node) + 1); } + else { range.setEnd(node, 0); } + range.collapse(false); + domSel.removeAllRanges(); + domSel.addRange(range); + // Kludge to kill 'control selection' in IE11 when selecting an + // invisible cursor wrapper, since that would result in those weird + // resize handles and a selection that considers the absolutely + // positioned wrapper, rather than the root editable node, the + // focused element. + if (!img && !view.state.selection.visible && result.ie && result.ie_version <= 11) { + node.disabled = true; + node.disabled = false; + } +} + +function syncNodeSelection(view, sel) { + if (sel instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["NodeSelection"]) { + var desc = view.docView.descAt(sel.from); + if (desc != view.lastSelectedViewDesc) { + clearNodeSelection(view); + if (desc) { desc.selectNode(); } + view.lastSelectedViewDesc = desc; + } + } else { + clearNodeSelection(view); + } +} + +// Clear all DOM statefulness of the last node selection. +function clearNodeSelection(view) { + if (view.lastSelectedViewDesc) { + if (view.lastSelectedViewDesc.parent) + { view.lastSelectedViewDesc.deselectNode(); } + view.lastSelectedViewDesc = null; + } +} + +function selectionBetween(view, $anchor, $head, bias) { + return view.someProp("createSelectionBetween", function (f) { return f(view, $anchor, $head); }) + || prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"].between($anchor, $head, bias) +} + +function hasFocusAndSelection(view) { + if (view.editable && view.root.activeElement != view.dom) { return false } + return hasSelection(view) +} + +function hasSelection(view) { + var sel = view.root.getSelection(); + if (!sel.anchorNode) { return false } + try { + // Firefox will raise 'permission denied' errors when accessing + // properties of `sel.anchorNode` when it's in a generated CSS + // element. + return view.dom.contains(sel.anchorNode.nodeType == 3 ? sel.anchorNode.parentNode : sel.anchorNode) && + (view.editable || view.dom.contains(sel.focusNode.nodeType == 3 ? sel.focusNode.parentNode : sel.focusNode)) + } catch(_) { + return false + } +} + +function anchorInRightPlace(view) { + var anchorDOM = view.docView.domFromPos(view.state.selection.anchor); + var domSel = view.root.getSelection(); + return isEquivalentPosition(anchorDOM.node, anchorDOM.offset, domSel.anchorNode, domSel.anchorOffset) +} + +// Note that all referencing and parsing is done with the +// start-of-operation selection and document, since that's the one +// that the DOM represents. If any changes came in in the meantime, +// the modification is mapped over those before it is applied, in +// readDOMChange. + +function parseBetween(view, from_, to_) { + var ref = view.docView.parseRange(from_, to_); + var parent = ref.node; + var fromOffset = ref.fromOffset; + var toOffset = ref.toOffset; + var from = ref.from; + var to = ref.to; + + var domSel = view.root.getSelection(), find = null, anchor = domSel.anchorNode; + if (anchor && view.dom.contains(anchor.nodeType == 1 ? anchor : anchor.parentNode)) { + find = [{node: anchor, offset: domSel.anchorOffset}]; + if (!selectionCollapsed(domSel)) + { find.push({node: domSel.focusNode, offset: domSel.focusOffset}); } + } + // Work around issue in Chrome where backspacing sometimes replaces + // the deleted content with a random BR node (issues #799, #831) + if (result.chrome && view.lastKeyCode === 8) { + for (var off = toOffset; off > fromOffset; off--) { + var node = parent.childNodes[off - 1], desc = node.pmViewDesc; + if (node.nodeType == "BR" && !desc) { toOffset = off; break } + if (!desc || desc.size) { break } + } + } + var startDoc = view.state.doc; + var parser = view.someProp("domParser") || prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["DOMParser"].fromSchema(view.state.schema); + var $from = startDoc.resolve(from); + + var sel = null, doc = parser.parse(parent, { + topNode: $from.parent, + topMatch: $from.parent.contentMatchAt($from.index()), + topOpen: true, + from: fromOffset, + to: toOffset, + preserveWhitespace: $from.parent.type.spec.code ? "full" : true, + editableContent: true, + findPositions: find, + ruleFromNode: ruleFromNode(parser, $from), + context: $from + }); + if (find && find[0].pos != null) { + var anchor$1 = find[0].pos, head = find[1] && find[1].pos; + if (head == null) { head = anchor$1; } + sel = {anchor: anchor$1 + from, head: head + from}; + } + return {doc: doc, sel: sel, from: from, to: to} +} + +function ruleFromNode(parser, context) { + return function (dom) { + var desc = dom.pmViewDesc; + if (desc) { + return desc.parseRule() + } else if (dom.nodeName == "BR" && dom.parentNode) { + // Safari replaces the list item or table cell with a BR + // directly in the list node (?!) if you delete the last + // character in a list item or table cell (#708, #862) + if (result.safari && /^(ul|ol)$/i.test(dom.parentNode.nodeName)) + { return parser.matchTag(document.createElement("li"), context) } + else if (dom.parentNode.lastChild == dom || result.safari && /^(tr|table)$/i.test(dom.parentNode.nodeName)) + { return {ignore: true} } + } else if (dom.nodeName == "IMG" && dom.getAttribute("mark-placeholder")) { + return {ignore: true} + } + } +} + +function readDOMChange(view, from, to, typeOver) { + if (from < 0) { + var origin = view.lastSelectionTime > Date.now() - 50 ? view.lastSelectionOrigin : null; + var newSel = selectionFromDOM(view, origin); + if (!view.state.selection.eq(newSel)) { + var tr$1 = view.state.tr.setSelection(newSel); + if (origin == "pointer") { tr$1.setMeta("pointer", true); } + else if (origin == "key") { tr$1.scrollIntoView(); } + view.dispatch(tr$1); + } + return + } + + var $before = view.state.doc.resolve(from); + var shared = $before.sharedDepth(to); + from = $before.before(shared + 1); + to = view.state.doc.resolve(to).after(shared + 1); + + var sel = view.state.selection; + var parse = parseBetween(view, from, to); + + var doc = view.state.doc, compare = doc.slice(parse.from, parse.to); + var preferredPos, preferredSide; + // Prefer anchoring to end when Backspace is pressed + if (view.lastKeyCode === 8 && Date.now() - 100 < view.lastKeyCodeTime) { + preferredPos = view.state.selection.to; + preferredSide = "end"; + } else { + preferredPos = view.state.selection.from; + preferredSide = "start"; + } + view.lastKeyCode = null; + + var change = findDiff(compare.content, parse.doc.content, parse.from, preferredPos, preferredSide); + if (!change) { + if (typeOver && sel instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"] && !sel.empty && sel.$head.sameParent(sel.$anchor) && + !view.composing && !(parse.sel && parse.sel.anchor != parse.sel.head)) { + change = {start: sel.from, endA: sel.to, endB: sel.to}; + } else { + if (parse.sel) { + var sel$1 = resolveSelection(view, view.state.doc, parse.sel); + if (sel$1 && !sel$1.eq(view.state.selection)) { view.dispatch(view.state.tr.setSelection(sel$1)); } + } + return + } + } + view.domChangeCount++; + // Handle the case where overwriting a selection by typing matches + // the start or end of the selected content, creating a change + // that's smaller than what was actually overwritten. + if (view.state.selection.from < view.state.selection.to && + change.start == change.endB && + view.state.selection instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"]) { + if (change.start > view.state.selection.from && change.start <= view.state.selection.from + 2) { + change.start = view.state.selection.from; + } else if (change.endA < view.state.selection.to && change.endA >= view.state.selection.to - 2) { + change.endB += (view.state.selection.to - change.endA); + change.endA = view.state.selection.to; + } + } + + // IE11 will insert a non-breaking space _ahead_ of the space after + // the cursor space when adding a space before another space. When + // that happened, adjust the change to cover the space instead. + if (result.ie && result.ie_version <= 11 && change.endB == change.start + 1 && + change.endA == change.start && change.start > parse.from && + parse.doc.textBetween(change.start - parse.from - 1, change.start - parse.from + 1) == " \u00a0") { + change.start--; + change.endA--; + change.endB--; + } + + var $from = parse.doc.resolveNoCache(change.start - parse.from); + var $to = parse.doc.resolveNoCache(change.endB - parse.from); + var nextSel; + // If this looks like the effect of pressing Enter, just dispatch an + // Enter key instead. + if (!$from.sameParent($to) && $from.pos < parse.doc.content.size && + (nextSel = prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["Selection"].findFrom(parse.doc.resolve($from.pos + 1), 1, true)) && + nextSel.head == $to.pos && + view.someProp("handleKeyDown", function (f) { return f(view, keyEvent(13, "Enter")); })) + { return } + // Same for backspace + if (view.state.selection.anchor > change.start && + looksLikeJoin(doc, change.start, change.endA, $from, $to) && + view.someProp("handleKeyDown", function (f) { return f(view, keyEvent(8, "Backspace")); })) { + if (result.android && result.chrome) { view.domObserver.suppressSelectionUpdates(); } // #820 + return + } + + var chFrom = change.start, chTo = change.endA; + + var tr, storedMarks, markChange, $from1; + if ($from.sameParent($to) && $from.parent.inlineContent) { + if ($from.pos == $to.pos) { // Deletion + // IE11 sometimes weirdly moves the DOM selection around after + // backspacing out the first element in a textblock + if (result.ie && result.ie_version <= 11 && $from.parentOffset == 0) { + view.domObserver.suppressSelectionUpdates(); + setTimeout(function () { return selectionToDOM(view); }, 20); + } + tr = view.state.tr.delete(chFrom, chTo); + storedMarks = doc.resolve(change.start).marksAcross(doc.resolve(change.endA)); + } else if ( // Adding or removing a mark + change.endA == change.endB && ($from1 = doc.resolve(change.start)) && + (markChange = isMarkChange($from.parent.content.cut($from.parentOffset, $to.parentOffset), + $from1.parent.content.cut($from1.parentOffset, change.endA - $from1.start()))) + ) { + tr = view.state.tr; + if (markChange.type == "add") { tr.addMark(chFrom, chTo, markChange.mark); } + else { tr.removeMark(chFrom, chTo, markChange.mark); } + } else if ($from.parent.child($from.index()).isText && $from.index() == $to.index() - ($to.textOffset ? 0 : 1)) { + // Both positions in the same text node -- simply insert text + var text = $from.parent.textBetween($from.parentOffset, $to.parentOffset); + if (view.someProp("handleTextInput", function (f) { return f(view, chFrom, chTo, text); })) { return } + tr = view.state.tr.insertText(text, chFrom, chTo); + } + } + + if (!tr) + { tr = view.state.tr.replace(chFrom, chTo, parse.doc.slice(change.start - parse.from, change.endB - parse.from)); } + if (parse.sel) { + var sel$2 = resolveSelection(view, tr.doc, parse.sel); + // Chrome Android will sometimes, during composition, report the + // selection in the wrong place. If it looks like that is + // happening, don't update the selection. + // Edge just doesn't move the cursor forward when you start typing + // in an empty block or between br nodes. + if (sel$2 && !(result.chrome && result.android && view.composing && sel$2.empty && sel$2.head == chFrom || + result.ie && sel$2.empty && sel$2.head == chFrom)) + { tr.setSelection(sel$2); } + } + if (storedMarks) { tr.ensureMarks(storedMarks); } + view.dispatch(tr.scrollIntoView()); +} + +function resolveSelection(view, doc, parsedSel) { + if (Math.max(parsedSel.anchor, parsedSel.head) > doc.content.size) { return null } + return selectionBetween(view, doc.resolve(parsedSel.anchor), doc.resolve(parsedSel.head)) +} + +// : (Fragment, Fragment) → ?{mark: Mark, type: string} +// Given two same-length, non-empty fragments of inline content, +// determine whether the first could be created from the second by +// removing or adding a single mark type. +function isMarkChange(cur, prev) { + var curMarks = cur.firstChild.marks, prevMarks = prev.firstChild.marks; + var added = curMarks, removed = prevMarks, type, mark, update; + for (var i = 0; i < prevMarks.length; i++) { added = prevMarks[i].removeFromSet(added); } + for (var i$1 = 0; i$1 < curMarks.length; i$1++) { removed = curMarks[i$1].removeFromSet(removed); } + if (added.length == 1 && removed.length == 0) { + mark = added[0]; + type = "add"; + update = function (node) { return node.mark(mark.addToSet(node.marks)); }; + } else if (added.length == 0 && removed.length == 1) { + mark = removed[0]; + type = "remove"; + update = function (node) { return node.mark(mark.removeFromSet(node.marks)); }; + } else { + return null + } + var updated = []; + for (var i$2 = 0; i$2 < prev.childCount; i$2++) { updated.push(update(prev.child(i$2))); } + if (prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(updated).eq(cur)) { return {mark: mark, type: type} } +} + +function looksLikeJoin(old, start, end, $newStart, $newEnd) { + if (!$newStart.parent.isTextblock || + // The content must have shrunk + end - start <= $newEnd.pos - $newStart.pos || + // newEnd must point directly at or after the end of the block that newStart points into + skipClosingAndOpening($newStart, true, false) < $newEnd.pos) + { return false } + + var $start = old.resolve(start); + // Start must be at the end of a block + if ($start.parentOffset < $start.parent.content.size || !$start.parent.isTextblock) + { return false } + var $next = old.resolve(skipClosingAndOpening($start, true, true)); + // The next textblock must start before end and end near it + if (!$next.parent.isTextblock || $next.pos > end || + skipClosingAndOpening($next, true, false) < end) + { return false } + + // The fragments after the join point must match + return $newStart.parent.content.cut($newStart.parentOffset).eq($next.parent.content) +} + +function skipClosingAndOpening($pos, fromEnd, mayOpen) { + var depth = $pos.depth, end = fromEnd ? $pos.end() : $pos.pos; + while (depth > 0 && (fromEnd || $pos.indexAfter(depth) == $pos.node(depth).childCount)) { + depth--; + end++; + fromEnd = false; + } + if (mayOpen) { + var next = $pos.node(depth).maybeChild($pos.indexAfter(depth)); + while (next && !next.isLeaf) { + next = next.firstChild; + end++; + } + } + return end +} + +function findDiff(a, b, pos, preferredPos, preferredSide) { + var start = a.findDiffStart(b, pos); + if (start == null) { return null } + var ref = a.findDiffEnd(b, pos + a.size, pos + b.size); + var endA = ref.a; + var endB = ref.b; + if (preferredSide == "end") { + var adjust = Math.max(0, start - Math.min(endA, endB)); + preferredPos -= endA + adjust - start; + } + if (endA < start && a.size < b.size) { + var move = preferredPos <= start && preferredPos >= endA ? start - preferredPos : 0; + start -= move; + endB = start + (endB - endA); + endA = start; + } else if (endB < start) { + var move$1 = preferredPos <= start && preferredPos >= endB ? start - preferredPos : 0; + start -= move$1; + endA = start + (endA - endB); + endB = start; + } + return {start: start, endA: endA, endB: endB} +} + +function serializeForClipboard(view, slice) { + var context = []; + var content = slice.content; + var openStart = slice.openStart; + var openEnd = slice.openEnd; + while (openStart > 1 && openEnd > 1 && content.childCount == 1 && content.firstChild.childCount == 1) { + openStart--; + openEnd--; + var node = content.firstChild; + context.push(node.type.name, node.type.hasRequiredAttrs() ? node.attrs : null); + content = node.content; + } + + var serializer = view.someProp("clipboardSerializer") || prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["DOMSerializer"].fromSchema(view.state.schema); + var doc = detachedDoc(), wrap = doc.createElement("div"); + wrap.appendChild(serializer.serializeFragment(content, {document: doc})); + + var firstChild = wrap.firstChild, needsWrap; + while (firstChild && firstChild.nodeType == 1 && (needsWrap = wrapMap[firstChild.nodeName.toLowerCase()])) { + for (var i = needsWrap.length - 1; i >= 0; i--) { + var wrapper = doc.createElement(needsWrap[i]); + while (wrap.firstChild) { wrapper.appendChild(wrap.firstChild); } + wrap.appendChild(wrapper); + } + firstChild = wrap.firstChild; + } + + if (firstChild && firstChild.nodeType == 1) + { firstChild.setAttribute("data-pm-slice", (openStart + " " + openEnd + " " + (JSON.stringify(context)))); } + + var text = view.someProp("clipboardTextSerializer", function (f) { return f(slice); }) || + slice.content.textBetween(0, slice.content.size, "\n\n"); + + return {dom: wrap, text: text} +} + +// : (EditorView, string, string, ?bool, ResolvedPos) → ?Slice +// Read a slice of content from the clipboard (or drop data). +function parseFromClipboard(view, text, html, plainText, $context) { + var dom, inCode = $context.parent.type.spec.code, slice; + if (!html && !text) { return null } + var asText = text && (plainText || inCode || !html); + if (asText) { + view.someProp("transformPastedText", function (f) { text = f(text); }); + if (inCode) { return new prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Slice"](prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(view.state.schema.text(text)), 0, 0) } + var parsed = view.someProp("clipboardTextParser", function (f) { return f(text, $context); }); + if (parsed) { + slice = parsed; + } else { + dom = document.createElement("div"); + text.trim().split(/(?:\r\n?|\n)+/).forEach(function (block) { + dom.appendChild(document.createElement("p")).textContent = block; + }); + } + } else { + view.someProp("transformPastedHTML", function (f) { html = f(html); }); + dom = readHTML(html); + } + + var contextNode = dom && dom.querySelector("[data-pm-slice]"); + var sliceData = contextNode && /^(\d+) (\d+) (.*)/.exec(contextNode.getAttribute("data-pm-slice")); + if (!slice) { + var parser = view.someProp("clipboardParser") || view.someProp("domParser") || prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["DOMParser"].fromSchema(view.state.schema); + slice = parser.parseSlice(dom, {preserveWhitespace: !!(asText || sliceData), context: $context}); + } + if (sliceData) + { slice = addContext(closeSlice(slice, +sliceData[1], +sliceData[2]), sliceData[3]); } + else // HTML wasn't created by ProseMirror. Make sure top-level siblings are coherent + { slice = prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Slice"].maxOpen(normalizeSiblings(slice.content, $context), false); } + + view.someProp("transformPasted", function (f) { slice = f(slice); }); + return slice +} + +// Takes a slice parsed with parseSlice, which means there hasn't been +// any content-expression checking done on the top nodes, tries to +// find a parent node in the current context that might fit the nodes, +// and if successful, rebuilds the slice so that it fits into that parent. +// +// This addresses the problem that Transform.replace expects a +// coherent slice, and will fail to place a set of siblings that don't +// fit anywhere in the schema. +function normalizeSiblings(fragment, $context) { + if (fragment.childCount < 2) { return fragment } + var loop = function ( d ) { + var parent = $context.node(d); + var match = parent.contentMatchAt($context.index(d)); + var lastWrap = (void 0), result = []; + fragment.forEach(function (node) { + if (!result) { return } + var wrap = match.findWrapping(node.type), inLast; + if (!wrap) { return result = null } + if (inLast = result.length && lastWrap.length && addToSibling(wrap, lastWrap, node, result[result.length - 1], 0)) { + result[result.length - 1] = inLast; + } else { + if (result.length) { result[result.length - 1] = closeRight(result[result.length - 1], lastWrap.length); } + var wrapped = withWrappers(node, wrap); + result.push(wrapped); + match = match.matchType(wrapped.type, wrapped.attrs); + lastWrap = wrap; + } + }); + if (result) { return { v: prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(result) } } + }; + + for (var d = $context.depth; d >= 0; d--) { + var returned = loop( d ); + + if ( returned ) return returned.v; + } + return fragment +} + +function withWrappers(node, wrap, from) { + if ( from === void 0 ) from = 0; + + for (var i = wrap.length - 1; i >= from; i--) + { node = wrap[i].create(null, prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(node)); } + return node +} + +// Used to group adjacent nodes wrapped in similar parents by +// normalizeSiblings into the same parent node +function addToSibling(wrap, lastWrap, node, sibling, depth) { + if (depth < wrap.length && depth < lastWrap.length && wrap[depth] == lastWrap[depth]) { + var inner = addToSibling(wrap, lastWrap, node, sibling.lastChild, depth + 1); + if (inner) { return sibling.copy(sibling.content.replaceChild(sibling.childCount - 1, inner)) } + var match = sibling.contentMatchAt(sibling.childCount); + if (match.matchType(depth == wrap.length - 1 ? node.type : wrap[depth + 1])) + { return sibling.copy(sibling.content.append(prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(withWrappers(node, wrap, depth + 1)))) } + } +} + +function closeRight(node, depth) { + if (depth == 0) { return node } + var fragment = node.content.replaceChild(node.childCount - 1, closeRight(node.lastChild, depth - 1)); + var fill = node.contentMatchAt(node.childCount).fillBefore(prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].empty, true); + return node.copy(fragment.append(fill)) +} + +function closeRange(fragment, side, from, to, depth, openEnd) { + var node = side < 0 ? fragment.firstChild : fragment.lastChild, inner = node.content; + if (depth < to - 1) { inner = closeRange(inner, side, from, to, depth + 1, openEnd); } + if (depth >= from) + { inner = side < 0 ? node.contentMatchAt(0).fillBefore(inner, fragment.childCount > 1 || openEnd <= depth).append(inner) + : inner.append(node.contentMatchAt(node.childCount).fillBefore(prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].empty, true)); } + return fragment.replaceChild(side < 0 ? 0 : fragment.childCount - 1, node.copy(inner)) +} + +function closeSlice(slice, openStart, openEnd) { + if (openStart < slice.openStart) + { slice = new prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Slice"](closeRange(slice.content, -1, openStart, slice.openStart, 0, slice.openEnd), openStart, slice.openEnd); } + if (openEnd < slice.openEnd) + { slice = new prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Slice"](closeRange(slice.content, 1, openEnd, slice.openEnd, 0, 0), slice.openStart, openEnd); } + return slice +} + +// Trick from jQuery -- some elements must be wrapped in other +// elements for innerHTML to work. I.e. if you do `div.innerHTML = +// "
      "` the table cells are ignored. +var wrapMap = {thead: ["table"], colgroup: ["table"], col: ["table", "colgroup"], + tr: ["table", "tbody"], td: ["table", "tbody", "tr"], th: ["table", "tbody", "tr"]}; + +var _detachedDoc = null; +function detachedDoc() { + return _detachedDoc || (_detachedDoc = document.implementation.createHTMLDocument("title")) +} + +function readHTML(html) { + var metas = /(\s*]*>)*/.exec(html); + if (metas) { html = html.slice(metas[0].length); } + var elt = detachedDoc().createElement("div"); + var firstTag = /(?:]*>)*<([a-z][^>\s]+)/i.exec(html), wrap, depth = 0; + if (wrap = firstTag && wrapMap[firstTag[1].toLowerCase()]) { + html = wrap.map(function (n) { return "<" + n + ">"; }).join("") + html + wrap.map(function (n) { return ""; }).reverse().join(""); + depth = wrap.length; + } + elt.innerHTML = html; + for (var i = 0; i < depth; i++) { elt = elt.firstChild; } + return elt +} + +function addContext(slice, context) { + if (!slice.size) { return slice } + var schema = slice.content.firstChild.type.schema, array; + try { array = JSON.parse(context); } + catch(e) { return slice } + var content = slice.content; + var openStart = slice.openStart; + var openEnd = slice.openEnd; + for (var i = array.length - 2; i >= 0; i -= 2) { + var type = schema.nodes[array[i]]; + if (!type || type.hasRequiredAttrs()) { break } + content = prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Fragment"].from(type.create(array[i + 1], content)); + openStart++; openEnd++; + } + return new prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Slice"](content, openStart, openEnd) +} + +var observeOptions = { + childList: true, + characterData: true, + characterDataOldValue: true, + attributes: true, + attributeOldValue: true, + subtree: true +}; +// IE11 has very broken mutation observers, so we also listen to DOMCharacterDataModified +var useCharData = result.ie && result.ie_version <= 11; + +var SelectionState = function SelectionState() { + this.anchorNode = this.anchorOffset = this.focusNode = this.focusOffset = null; +}; + +SelectionState.prototype.set = function set (sel) { + this.anchorNode = sel.anchorNode; this.anchorOffset = sel.anchorOffset; + this.focusNode = sel.focusNode; this.focusOffset = sel.focusOffset; +}; + +SelectionState.prototype.eq = function eq (sel) { + return sel.anchorNode == this.anchorNode && sel.anchorOffset == this.anchorOffset && + sel.focusNode == this.focusNode && sel.focusOffset == this.focusOffset +}; + +var DOMObserver = function DOMObserver(view, handleDOMChange) { + var this$1 = this; + + this.view = view; + this.handleDOMChange = handleDOMChange; + this.queue = []; + this.flushingSoon = false; + this.observer = window.MutationObserver && + new window.MutationObserver(function (mutations) { + for (var i = 0; i < mutations.length; i++) { this$1.queue.push(mutations[i]); } + // IE11 will sometimes (on backspacing out a single character + // text node after a BR node) call the observer callback + // before actually updating the DOM, which will cause + // ProseMirror to miss the change (see #930) + if (result.ie && result.ie_version <= 11 && mutations.some( + function (m) { return m.type == "childList" && m.removedNodes.length || + m.type == "characterData" && m.oldValue.length > m.target.nodeValue.length; })) + { this$1.flushSoon(); } + else + { this$1.flush(); } + }); + this.currentSelection = new SelectionState; + if (useCharData) { + this.onCharData = function (e) { + this$1.queue.push({target: e.target, type: "characterData", oldValue: e.prevValue}); + this$1.flushSoon(); + }; + } + this.onSelectionChange = this.onSelectionChange.bind(this); + this.suppressingSelectionUpdates = false; +}; + +DOMObserver.prototype.flushSoon = function flushSoon () { + var this$1 = this; + + if (!this.flushingSoon) { + this.flushingSoon = true; + window.setTimeout(function () { this$1.flushingSoon = false; this$1.flush(); }, 20); + } +}; + +DOMObserver.prototype.start = function start () { + if (this.observer) + { this.observer.observe(this.view.dom, observeOptions); } + if (useCharData) + { this.view.dom.addEventListener("DOMCharacterDataModified", this.onCharData); } + this.connectSelection(); +}; + +DOMObserver.prototype.stop = function stop () { + var this$1 = this; + + if (this.observer) { + var take = this.observer.takeRecords(); + if (take.length) { + for (var i = 0; i < take.length; i++) { this.queue.push(take[i]); } + window.setTimeout(function () { return this$1.flush(); }, 20); + } + this.observer.disconnect(); + } + if (useCharData) { this.view.dom.removeEventListener("DOMCharacterDataModified", this.onCharData); } + this.disconnectSelection(); +}; + +DOMObserver.prototype.connectSelection = function connectSelection () { + this.view.dom.ownerDocument.addEventListener("selectionchange", this.onSelectionChange); +}; + +DOMObserver.prototype.disconnectSelection = function disconnectSelection () { + this.view.dom.ownerDocument.removeEventListener("selectionchange", this.onSelectionChange); +}; + +DOMObserver.prototype.suppressSelectionUpdates = function suppressSelectionUpdates () { + var this$1 = this; + + this.suppressingSelectionUpdates = true; + setTimeout(function () { return this$1.suppressingSelectionUpdates = false; }, 50); +}; + +DOMObserver.prototype.onSelectionChange = function onSelectionChange () { + if (!hasFocusAndSelection(this.view)) { return } + if (this.suppressingSelectionUpdates) { return selectionToDOM(this.view) } + // Deletions on IE11 fire their events in the wrong order, giving + // us a selection change event before the DOM changes are + // reported. + if (result.ie && result.ie_version <= 11 && !this.view.state.selection.empty) { + var sel = this.view.root.getSelection(); + // Selection.isCollapsed isn't reliable on IE + if (sel.focusNode && isEquivalentPosition(sel.focusNode, sel.focusOffset, sel.anchorNode, sel.anchorOffset)) + { return this.flushSoon() } + } + this.flush(); +}; + +DOMObserver.prototype.setCurSelection = function setCurSelection () { + this.currentSelection.set(this.view.root.getSelection()); +}; + +DOMObserver.prototype.ignoreSelectionChange = function ignoreSelectionChange (sel) { + if (sel.rangeCount == 0) { return true } + var container = sel.getRangeAt(0).commonAncestorContainer; + var desc = this.view.docView.nearestDesc(container); + return desc && desc.ignoreMutation({type: "selection", target: container.nodeType == 3 ? container.parentNode : container}) +}; + +DOMObserver.prototype.flush = function flush () { + if (!this.view.docView || this.flushingSoon) { return } + var mutations = this.observer ? this.observer.takeRecords() : []; + if (this.queue.length) { + mutations = this.queue.concat(mutations); + this.queue.length = 0; + } + + var sel = this.view.root.getSelection(); + var newSel = !this.suppressingSelectionUpdates && !this.currentSelection.eq(sel) && hasSelection(this.view) && !this.ignoreSelectionChange(sel); + + var from = -1, to = -1, typeOver = false, added = []; + if (this.view.editable) { + for (var i = 0; i < mutations.length; i++) { + var result = this.registerMutation(mutations[i], added); + if (result) { + from = from < 0 ? result.from : Math.min(result.from, from); + to = to < 0 ? result.to : Math.max(result.to, to); + if (result.typeOver && !this.view.composing) { typeOver = true; } + } + } + } + + if (from > -1 || newSel) { + if (from > -1) { + this.view.docView.markDirty(from, to); + checkCSS(this.view); + } + this.handleDOMChange(from, to, typeOver); + if (this.view.docView.dirty) { this.view.updateState(this.view.state); } + else if (!this.currentSelection.eq(sel)) { selectionToDOM(this.view); } + } +}; + +DOMObserver.prototype.registerMutation = function registerMutation (mut, added) { + // Ignore mutations inside nodes that were already noted as inserted + if (added.indexOf(mut.target) > -1) { return null } + var desc = this.view.docView.nearestDesc(mut.target); + if (mut.type == "attributes" && + (desc == this.view.docView || mut.attributeName == "contenteditable" || + // Firefox sometimes fires spurious events for null/empty styles + (mut.attributeName == "style" && !mut.oldValue && !mut.target.getAttribute("style")))) + { return null } + if (!desc || desc.ignoreMutation(mut)) { return null } + + if (mut.type == "childList") { + var prev = mut.previousSibling, next = mut.nextSibling; + if (result.ie && result.ie_version <= 11 && mut.addedNodes.length) { + // IE11 gives us incorrect next/prev siblings for some + // insertions, so if there are added nodes, recompute those + for (var i = 0; i < mut.addedNodes.length; i++) { + var ref = mut.addedNodes[i]; + var previousSibling = ref.previousSibling; + var nextSibling = ref.nextSibling; + if (!previousSibling || Array.prototype.indexOf.call(mut.addedNodes, previousSibling) < 0) { prev = previousSibling; } + if (!nextSibling || Array.prototype.indexOf.call(mut.addedNodes, nextSibling) < 0) { next = nextSibling; } + } + } + var fromOffset = prev && prev.parentNode == mut.target + ? domIndex(prev) + 1 : 0; + var from = desc.localPosFromDOM(mut.target, fromOffset, -1); + var toOffset = next && next.parentNode == mut.target + ? domIndex(next) : mut.target.childNodes.length; + for (var i$1 = 0; i$1 < mut.addedNodes.length; i$1++) { added.push(mut.addedNodes[i$1]); } + var to = desc.localPosFromDOM(mut.target, toOffset, 1); + return {from: from, to: to} + } else if (mut.type == "attributes") { + return {from: desc.posAtStart - desc.border, to: desc.posAtEnd + desc.border} + } else { // "characterData" + return { + from: desc.posAtStart, + to: desc.posAtEnd, + // An event was generated for a text change that didn't change + // any text. Mark the dom change to fall back to assuming the + // selection was typed over with an identical value if it can't + // find another change. + typeOver: mut.target.nodeValue == mut.oldValue + } + } +}; + +var cssChecked = false; + +function checkCSS(view) { + if (cssChecked) { return } + cssChecked = true; + if (getComputedStyle(view.dom).whiteSpace == "normal") + { console["warn"]("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package."); } +} + +// A collection of DOM events that occur within the editor, and callback functions +// to invoke when the event fires. +var handlers = {}, editHandlers = {}; + +function initInput(view) { + view.shiftKey = false; + view.mouseDown = null; + view.lastKeyCode = null; + view.lastKeyCodeTime = 0; + view.lastClick = {time: 0, x: 0, y: 0, type: ""}; + view.lastSelectionOrigin = null; + view.lastSelectionTime = 0; + + view.composing = false; + view.composingTimeout = null; + view.compositionNodes = []; + view.compositionEndedAt = -2e8; + + view.domObserver = new DOMObserver(view, function (from, to, typeOver) { return readDOMChange(view, from, to, typeOver); }); + view.domObserver.start(); + // Used by hacks like the beforeinput handler to check whether anything happened in the DOM + view.domChangeCount = 0; + + view.eventHandlers = Object.create(null); + var loop = function ( event ) { + var handler = handlers[event]; + view.dom.addEventListener(event, view.eventHandlers[event] = function (event) { + if (eventBelongsToView(view, event) && !runCustomHandler(view, event) && + (view.editable || !(event.type in editHandlers))) + { handler(view, event); } + }); + }; + + for (var event in handlers) loop( event ); + // On Safari, for reasons beyond my understanding, adding an input + // event handler makes an issue where the composition vanishes when + // you press enter go away. + if (result.safari) { view.dom.addEventListener("input", function () { return null; }); } + + ensureListeners(view); +} + +function setSelectionOrigin(view, origin) { + view.lastSelectionOrigin = origin; + view.lastSelectionTime = Date.now(); +} + +function destroyInput(view) { + view.domObserver.stop(); + for (var type in view.eventHandlers) + { view.dom.removeEventListener(type, view.eventHandlers[type]); } + clearTimeout(view.composingTimeout); +} + +function ensureListeners(view) { + view.someProp("handleDOMEvents", function (currentHandlers) { + for (var type in currentHandlers) { if (!view.eventHandlers[type]) + { view.dom.addEventListener(type, view.eventHandlers[type] = function (event) { return runCustomHandler(view, event); }); } } + }); +} + +function runCustomHandler(view, event) { + return view.someProp("handleDOMEvents", function (handlers) { + var handler = handlers[event.type]; + return handler ? handler(view, event) || event.defaultPrevented : false + }) +} + +function eventBelongsToView(view, event) { + if (!event.bubbles) { return true } + if (event.defaultPrevented) { return false } + for (var node = event.target; node != view.dom; node = node.parentNode) + { if (!node || node.nodeType == 11 || + (node.pmViewDesc && node.pmViewDesc.stopEvent(event))) + { return false } } + return true +} + +function dispatchEvent(view, event) { + if (!runCustomHandler(view, event) && handlers[event.type] && + (view.editable || !(event.type in editHandlers))) + { handlers[event.type](view, event); } +} + +editHandlers.keydown = function (view, event) { + view.shiftKey = event.keyCode == 16 || event.shiftKey; + if (inOrNearComposition(view, event)) { return } + view.lastKeyCode = event.keyCode; + view.lastKeyCodeTime = Date.now(); + if (view.someProp("handleKeyDown", function (f) { return f(view, event); }) || captureKeyDown(view, event)) + { event.preventDefault(); } + else + { setSelectionOrigin(view, "key"); } +}; + +editHandlers.keyup = function (view, e) { + if (e.keyCode == 16) { view.shiftKey = false; } +}; + +editHandlers.keypress = function (view, event) { + if (inOrNearComposition(view, event) || !event.charCode || + event.ctrlKey && !event.altKey || result.mac && event.metaKey) { return } + + if (view.someProp("handleKeyPress", function (f) { return f(view, event); })) { + event.preventDefault(); + return + } + + var sel = view.state.selection; + if (!(sel instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"]) || !sel.$from.sameParent(sel.$to)) { + var text = String.fromCharCode(event.charCode); + if (!view.someProp("handleTextInput", function (f) { return f(view, sel.$from.pos, sel.$to.pos, text); })) + { view.dispatch(view.state.tr.insertText(text).scrollIntoView()); } + event.preventDefault(); + } +}; + +function eventCoords(event) { return {left: event.clientX, top: event.clientY} } + +function isNear(event, click) { + var dx = click.x - event.clientX, dy = click.y - event.clientY; + return dx * dx + dy * dy < 100 +} + +function runHandlerOnContext(view, propName, pos, inside, event) { + if (inside == -1) { return false } + var $pos = view.state.doc.resolve(inside); + var loop = function ( i ) { + if (view.someProp(propName, function (f) { return i > $pos.depth ? f(view, pos, $pos.nodeAfter, $pos.before(i), event, true) + : f(view, pos, $pos.node(i), $pos.before(i), event, false); })) + { return { v: true } } + }; + + for (var i = $pos.depth + 1; i > 0; i--) { + var returned = loop( i ); + + if ( returned ) return returned.v; + } + return false +} + +function updateSelection(view, selection, origin) { + if (!view.focused) { view.focus(); } + var tr = view.state.tr.setSelection(selection); + if (origin == "pointer") { tr.setMeta("pointer", true); } + view.dispatch(tr); +} + +function selectClickedLeaf(view, inside) { + if (inside == -1) { return false } + var $pos = view.state.doc.resolve(inside), node = $pos.nodeAfter; + if (node && node.isAtom && prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["NodeSelection"].isSelectable(node)) { + updateSelection(view, new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["NodeSelection"]($pos), "pointer"); + return true + } + return false +} + +function selectClickedNode(view, inside) { + if (inside == -1) { return false } + var sel = view.state.selection, selectedNode, selectAt; + if (sel instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["NodeSelection"]) { selectedNode = sel.node; } + + var $pos = view.state.doc.resolve(inside); + for (var i = $pos.depth + 1; i > 0; i--) { + var node = i > $pos.depth ? $pos.nodeAfter : $pos.node(i); + if (prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["NodeSelection"].isSelectable(node)) { + if (selectedNode && sel.$from.depth > 0 && + i >= sel.$from.depth && $pos.before(sel.$from.depth + 1) == sel.$from.pos) + { selectAt = $pos.before(sel.$from.depth); } + else + { selectAt = $pos.before(i); } + break + } + } + + if (selectAt != null) { + updateSelection(view, prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["NodeSelection"].create(view.state.doc, selectAt), "pointer"); + return true + } else { + return false + } +} + +function handleSingleClick(view, pos, inside, event, selectNode) { + return runHandlerOnContext(view, "handleClickOn", pos, inside, event) || + view.someProp("handleClick", function (f) { return f(view, pos, event); }) || + (selectNode ? selectClickedNode(view, inside) : selectClickedLeaf(view, inside)) +} + +function handleDoubleClick(view, pos, inside, event) { + return runHandlerOnContext(view, "handleDoubleClickOn", pos, inside, event) || + view.someProp("handleDoubleClick", function (f) { return f(view, pos, event); }) +} + +function handleTripleClick(view, pos, inside, event) { + return runHandlerOnContext(view, "handleTripleClickOn", pos, inside, event) || + view.someProp("handleTripleClick", function (f) { return f(view, pos, event); }) || + defaultTripleClick(view, inside) +} + +function defaultTripleClick(view, inside) { + var doc = view.state.doc; + if (inside == -1) { + if (doc.inlineContent) { + updateSelection(view, prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"].create(doc, 0, doc.content.size), "pointer"); + return true + } + return false + } + + var $pos = doc.resolve(inside); + for (var i = $pos.depth + 1; i > 0; i--) { + var node = i > $pos.depth ? $pos.nodeAfter : $pos.node(i); + var nodePos = $pos.before(i); + if (node.inlineContent) + { updateSelection(view, prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"].create(doc, nodePos + 1, nodePos + 1 + node.content.size), "pointer"); } + else if (prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["NodeSelection"].isSelectable(node)) + { updateSelection(view, prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["NodeSelection"].create(doc, nodePos), "pointer"); } + else + { continue } + return true + } +} + +function forceDOMFlush(view) { + return endComposition(view) +} + +var selectNodeModifier = result.mac ? "metaKey" : "ctrlKey"; + +handlers.mousedown = function (view, event) { + view.shiftKey = event.shiftKey; + var flushed = forceDOMFlush(view); + var now = Date.now(), type = "singleClick"; + if (now - view.lastClick.time < 500 && isNear(event, view.lastClick) && !event[selectNodeModifier]) { + if (view.lastClick.type == "singleClick") { type = "doubleClick"; } + else if (view.lastClick.type == "doubleClick") { type = "tripleClick"; } + } + view.lastClick = {time: now, x: event.clientX, y: event.clientY, type: type}; + + var pos = view.posAtCoords(eventCoords(event)); + if (!pos) { return } + + if (type == "singleClick") + { view.mouseDown = new MouseDown(view, pos, event, flushed); } + else if ((type == "doubleClick" ? handleDoubleClick : handleTripleClick)(view, pos.pos, pos.inside, event)) + { event.preventDefault(); } + else + { setSelectionOrigin(view, "pointer"); } +}; + +var MouseDown = function MouseDown(view, pos, event, flushed) { + var this$1 = this; + + this.view = view; + this.startDoc = view.state.doc; + this.pos = pos; + this.event = event; + this.flushed = flushed; + this.selectNode = event[selectNodeModifier]; + this.allowDefault = event.shiftKey; + + var targetNode, targetPos; + if (pos.inside > -1) { + targetNode = view.state.doc.nodeAt(pos.inside); + targetPos = pos.inside; + } else { + var $pos = view.state.doc.resolve(pos.pos); + targetNode = $pos.parent; + targetPos = $pos.depth ? $pos.before() : 0; + } + + this.mightDrag = null; + + var target = flushed ? null : event.target; + var targetDesc = target ? view.docView.nearestDesc(target, true) : null; + this.target = targetDesc ? targetDesc.dom : null; + + if (targetNode.type.spec.draggable && targetNode.type.spec.selectable !== false || + view.state.selection instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["NodeSelection"] && targetPos == view.state.selection.from) + { this.mightDrag = {node: targetNode, + pos: targetPos, + addAttr: this.target && !this.target.draggable, + setUneditable: this.target && result.gecko && !this.target.hasAttribute("contentEditable")}; } + + if (this.target && this.mightDrag && (this.mightDrag.addAttr || this.mightDrag.setUneditable)) { + this.view.domObserver.stop(); + if (this.mightDrag.addAttr) { this.target.draggable = true; } + if (this.mightDrag.setUneditable) + { setTimeout(function () { return this$1.target.setAttribute("contentEditable", "false"); }, 20); } + this.view.domObserver.start(); + } + + view.root.addEventListener("mouseup", this.up = this.up.bind(this)); + view.root.addEventListener("mousemove", this.move = this.move.bind(this)); + setSelectionOrigin(view, "pointer"); +}; + +MouseDown.prototype.done = function done () { + this.view.root.removeEventListener("mouseup", this.up); + this.view.root.removeEventListener("mousemove", this.move); + if (this.mightDrag && this.target) { + this.view.domObserver.stop(); + if (this.mightDrag.addAttr) { this.target.draggable = false; } + if (this.mightDrag.setUneditable) { this.target.removeAttribute("contentEditable"); } + this.view.domObserver.start(); + } + this.view.mouseDown = null; +}; + +MouseDown.prototype.up = function up (event) { + this.done(); + + if (!this.view.dom.contains(event.target.nodeType == 3 ? event.target.parentNode : event.target)) + { return } + + var pos = this.pos; + if (this.view.state.doc != this.startDoc) { pos = this.view.posAtCoords(eventCoords(event)); } + + if (this.allowDefault || !pos) { + setSelectionOrigin(this.view, "pointer"); + } else if (handleSingleClick(this.view, pos.pos, pos.inside, event, this.selectNode)) { + event.preventDefault(); + } else if (this.flushed || + // Chrome will sometimes treat a node selection as a + // cursor, but still report that the node is selected + // when asked through getSelection. You'll then get a + // situation where clicking at the point where that + // (hidden) cursor is doesn't change the selection, and + // thus doesn't get a reaction from ProseMirror. This + // works around that. + (result.chrome && !(this.view.state.selection instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"]) && + (pos.pos == this.view.state.selection.from || pos.pos == this.view.state.selection.to))) { + updateSelection(this.view, prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["Selection"].near(this.view.state.doc.resolve(pos.pos)), "pointer"); + event.preventDefault(); + } else { + setSelectionOrigin(this.view, "pointer"); + } +}; + +MouseDown.prototype.move = function move (event) { + if (!this.allowDefault && (Math.abs(this.event.x - event.clientX) > 4 || + Math.abs(this.event.y - event.clientY) > 4)) + { this.allowDefault = true; } + setSelectionOrigin(this.view, "pointer"); +}; + +handlers.touchdown = function (view) { + forceDOMFlush(view); + setSelectionOrigin(view, "pointer"); +}; + +handlers.contextmenu = function (view) { return forceDOMFlush(view); }; + +function inOrNearComposition(view, event) { + if (view.composing) { return true } + // See https://www.stum.de/2016/06/24/handling-ime-events-in-javascript/. + // On Japanese input method editors (IMEs), the Enter key is used to confirm character + // selection. On Safari, when Enter is pressed, compositionend and keydown events are + // emitted. The keydown event triggers newline insertion, which we don't want. + // This method returns true if the keydown event should be ignored. + // We only ignore it once, as pressing Enter a second time *should* insert a newline. + // Furthermore, the keydown event timestamp must be close to the compositionEndedAt timestamp. + // This guards against the case where compositionend is triggered without the keyboard + // (e.g. character confirmation may be done with the mouse), and keydown is triggered + // afterwards- we wouldn't want to ignore the keydown event in this case. + if (result.safari && Math.abs(event.timeStamp - view.compositionEndedAt) < 500) { + view.compositionEndedAt = -2e8; + return true + } + return false +} + +// Drop active composition after 5 seconds of inactivity on Android +var timeoutComposition = result.android ? 5000 : -1; + +editHandlers.compositionstart = editHandlers.compositionupdate = function (view) { + if (!view.composing) { + view.domObserver.flush(); + var state = view.state; + var $pos = state.selection.$from; + if (state.selection.empty && + (state.storedMarks || (!$pos.textOffset && $pos.parentOffset && $pos.nodeBefore.marks.some(function (m) { return m.type.spec.inclusive === false; })))) { + // Need to wrap the cursor in mark nodes different from the ones in the DOM context + view.markCursor = view.state.storedMarks || $pos.marks(); + endComposition(view, true); + view.markCursor = null; + } else { + endComposition(view); + // In firefox, if the cursor is after but outside a marked node, + // the inserted text won't inherit the marks. So this moves it + // inside if necessary. + if (result.gecko && state.selection.empty && $pos.parentOffset && !$pos.textOffset && $pos.nodeBefore.marks.length) { + var sel = view.root.getSelection(); + for (var node = sel.focusNode, offset = sel.focusOffset; node && node.nodeType == 1 && offset != 0;) { + var before = offset < 0 ? node.lastChild : node.childNodes[offset - 1]; + if (before.nodeType == 3) { + sel.collapse(before, before.nodeValue.length); + break + } else { + node = before; + offset = -1; + } + } + } + } + view.composing = true; + } + scheduleComposeEnd(view, timeoutComposition); +}; + +editHandlers.compositionend = function (view, event) { + if (view.composing) { + view.composing = false; + view.compositionEndedAt = event.timeStamp; + scheduleComposeEnd(view, 20); + } +}; + +function scheduleComposeEnd(view, delay) { + clearTimeout(view.composingTimeout); + if (delay > -1) { view.composingTimeout = setTimeout(function () { return endComposition(view); }, delay); } +} + +function endComposition(view, forceUpdate) { + view.composing = false; + while (view.compositionNodes.length > 0) { view.compositionNodes.pop().markParentsDirty(); } + if (forceUpdate || view.docView.dirty) { + view.updateState(view.state); + return true + } + return false +} + +function captureCopy(view, dom) { + // The extra wrapper is somehow necessary on IE/Edge to prevent the + // content from being mangled when it is put onto the clipboard + var doc = view.dom.ownerDocument; + var wrap = doc.body.appendChild(doc.createElement("div")); + wrap.appendChild(dom); + wrap.style.cssText = "position: fixed; left: -10000px; top: 10px"; + var sel = getSelection(), range = doc.createRange(); + range.selectNodeContents(dom); + // Done because IE will fire a selectionchange moving the selection + // to its start when removeAllRanges is called and the editor still + // has focus (which will mess up the editor's selection state). + view.dom.blur(); + sel.removeAllRanges(); + sel.addRange(range); + setTimeout(function () { + doc.body.removeChild(wrap); + view.focus(); + }, 50); +} + +// This is very crude, but unfortunately both these browsers _pretend_ +// that they have a clipboard API—all the objects and methods are +// there, they just don't work, and they are hard to test. +var brokenClipboardAPI = (result.ie && result.ie_version < 15) || + (result.ios && result.webkit_version < 604); + +handlers.copy = editHandlers.cut = function (view, e) { + var sel = view.state.selection, cut = e.type == "cut"; + if (sel.empty) { return } + + // IE and Edge's clipboard interface is completely broken + var data = brokenClipboardAPI ? null : e.clipboardData; + var slice = sel.content(); + var ref = serializeForClipboard(view, slice); + var dom = ref.dom; + var text = ref.text; + if (data) { + e.preventDefault(); + data.clearData(); + data.setData("text/html", dom.innerHTML); + data.setData("text/plain", text); + } else { + captureCopy(view, dom); + } + if (cut) { view.dispatch(view.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent", "cut")); } +}; + +function sliceSingleNode(slice) { + return slice.openStart == 0 && slice.openEnd == 0 && slice.content.childCount == 1 ? slice.content.firstChild : null +} + +function capturePaste(view, e) { + var doc = view.dom.ownerDocument; + var plainText = view.shiftKey || view.state.selection.$from.parent.type.spec.code; + var target = doc.body.appendChild(doc.createElement(plainText ? "textarea" : "div")); + if (!plainText) { target.contentEditable = "true"; } + target.style.cssText = "position: fixed; left: -10000px; top: 10px"; + target.focus(); + setTimeout(function () { + view.focus(); + doc.body.removeChild(target); + if (plainText) { doPaste(view, target.value, null, e); } + else { doPaste(view, target.textContent, target.innerHTML, e); } + }, 50); +} + +function doPaste(view, text, html, e) { + var slice = parseFromClipboard(view, text, html, view.shiftKey, view.state.selection.$from); + if (view.someProp("handlePaste", function (f) { return f(view, e, slice || prosemirror_model__WEBPACK_IMPORTED_MODULE_1__["Slice"].empty); }) || !slice) { return } + + var singleNode = sliceSingleNode(slice); + var tr = singleNode ? view.state.tr.replaceSelectionWith(singleNode, view.shiftKey) : view.state.tr.replaceSelection(slice); + view.dispatch(tr.scrollIntoView().setMeta("paste", true).setMeta("uiEvent", "paste")); +} + +editHandlers.paste = function (view, e) { + var data = brokenClipboardAPI ? null : e.clipboardData; + var html = data && data.getData("text/html"), text = data && data.getData("text/plain"); + if (data && (html || text || data.files.length)) { + doPaste(view, text, html, e); + e.preventDefault(); + } else { + capturePaste(view, e); + } +}; + +var Dragging = function Dragging(slice, move) { + this.slice = slice; + this.move = move; +}; + +var dragCopyModifier = result.mac ? "altKey" : "ctrlKey"; + +handlers.dragstart = function (view, e) { + var mouseDown = view.mouseDown; + if (mouseDown) { mouseDown.done(); } + if (!e.dataTransfer) { return } + + var sel = view.state.selection; + var pos = sel.empty ? null : view.posAtCoords(eventCoords(e)); + if (pos && pos.pos >= sel.from && pos.pos <= (sel instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["NodeSelection"] ? sel.to - 1: sel.to)) ; else if (mouseDown && mouseDown.mightDrag) { + view.dispatch(view.state.tr.setSelection(prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["NodeSelection"].create(view.state.doc, mouseDown.mightDrag.pos))); + } else if (e.target && e.target.nodeType == 1) { + var desc = view.docView.nearestDesc(e.target, true); + if (!desc || !desc.node.type.spec.draggable || desc == view.docView) { return } + view.dispatch(view.state.tr.setSelection(prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["NodeSelection"].create(view.state.doc, desc.posBefore))); + } + var slice = view.state.selection.content(); + var ref = serializeForClipboard(view, slice); + var dom = ref.dom; + var text = ref.text; + e.dataTransfer.clearData(); + e.dataTransfer.setData(brokenClipboardAPI ? "Text" : "text/html", dom.innerHTML); + if (!brokenClipboardAPI) { e.dataTransfer.setData("text/plain", text); } + view.dragging = new Dragging(slice, !e[dragCopyModifier]); +}; + +handlers.dragend = function (view) { + window.setTimeout(function () { return view.dragging = null; }, 50); +}; + +editHandlers.dragover = editHandlers.dragenter = function (_, e) { return e.preventDefault(); }; + +editHandlers.drop = function (view, e) { + var dragging = view.dragging; + view.dragging = null; + + if (!e.dataTransfer) { return } + + var eventPos = view.posAtCoords(eventCoords(e)); + if (!eventPos) { return } + var $mouse = view.state.doc.resolve(eventPos.pos); + if (!$mouse) { return } + var slice = dragging && dragging.slice || + parseFromClipboard(view, e.dataTransfer.getData(brokenClipboardAPI ? "Text" : "text/plain"), + brokenClipboardAPI ? null : e.dataTransfer.getData("text/html"), false, $mouse); + if (!slice) { return } + + e.preventDefault(); + if (view.someProp("handleDrop", function (f) { return f(view, e, slice, dragging && dragging.move); })) { return } + var insertPos = slice ? Object(prosemirror_transform__WEBPACK_IMPORTED_MODULE_2__["dropPoint"])(view.state.doc, $mouse.pos, slice) : $mouse.pos; + if (insertPos == null) { insertPos = $mouse.pos; } + + var tr = view.state.tr; + if (dragging && dragging.move) { tr.deleteSelection(); } + + var pos = tr.mapping.map(insertPos); + var isNode = slice.openStart == 0 && slice.openEnd == 0 && slice.content.childCount == 1; + var beforeInsert = tr.doc; + if (isNode) + { tr.replaceRangeWith(pos, pos, slice.content.firstChild); } + else + { tr.replaceRange(pos, pos, slice); } + if (tr.doc.eq(beforeInsert)) { return } + + var $pos = tr.doc.resolve(pos); + if (isNode && prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["NodeSelection"].isSelectable(slice.content.firstChild) && + $pos.nodeAfter && $pos.nodeAfter.sameMarkup(slice.content.firstChild)) + { tr.setSelection(new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["NodeSelection"]($pos)); } + else + { tr.setSelection(selectionBetween(view, $pos, tr.doc.resolve(tr.mapping.map(insertPos)))); } + view.focus(); + view.dispatch(tr.setMeta("uiEvent", "drop")); +}; + +handlers.focus = function (view) { + if (!view.focused) { + view.domObserver.stop(); + view.dom.classList.add("ProseMirror-focused"); + view.domObserver.start(); + view.focused = true; + } +}; + +handlers.blur = function (view) { + if (view.focused) { + view.domObserver.stop(); + view.dom.classList.remove("ProseMirror-focused"); + view.domObserver.start(); + view.domObserver.currentSelection.set({}); + view.focused = false; + } +}; + +handlers.beforeinput = function (view, event) { + // We should probably do more with beforeinput events, but support + // is so spotty that I'm still waiting to see where they are going. + + // Very specific hack to deal with backspace sometimes failing on + // Chrome Android when after an uneditable node. + if (result.chrome && result.android && event.inputType == "deleteContentBackward") { + var domChangeCount = view.domChangeCount; + setTimeout(function () { + if (view.domChangeCount != domChangeCount) { return } // Event already had some effect + // This bug tends to close the virtual keyboard, so we refocus + view.dom.blur(); + view.focus(); + if (view.someProp("handleKeyDown", function (f) { return f(view, keyEvent(8, "Backspace")); })) { return } + var ref = view.state.selection; + var $cursor = ref.$cursor; + // Crude approximation of backspace behavior when no command handled it + if ($cursor && $cursor.pos > 0) { view.dispatch(view.state.tr.delete($cursor.pos - 1, $cursor.pos).scrollIntoView()); } + }, 50); + } +}; + +// Make sure all handlers get registered +for (var prop in editHandlers) { handlers[prop] = editHandlers[prop]; } + +function compareObjs(a, b) { + if (a == b) { return true } + for (var p in a) { if (a[p] !== b[p]) { return false } } + for (var p$1 in b) { if (!(p$1 in a)) { return false } } + return true +} + +var WidgetType = function WidgetType(toDOM, spec) { + this.spec = spec || noSpec; + this.side = this.spec.side || 0; + this.toDOM = toDOM; +}; + +WidgetType.prototype.map = function map (mapping, span, offset, oldOffset) { + var ref = mapping.mapResult(span.from + oldOffset, this.side < 0 ? -1 : 1); + var pos = ref.pos; + var deleted = ref.deleted; + return deleted ? null : new Decoration(pos - offset, pos - offset, this) +}; + +WidgetType.prototype.valid = function valid () { return true }; + +WidgetType.prototype.eq = function eq (other) { + return this == other || + (other instanceof WidgetType && + (this.spec.key && this.spec.key == other.spec.key || + this.toDOM == other.toDOM && compareObjs(this.spec, other.spec))) +}; + +var InlineType = function InlineType(attrs, spec) { + this.spec = spec || noSpec; + this.attrs = attrs; +}; + +InlineType.prototype.map = function map (mapping, span, offset, oldOffset) { + var from = mapping.map(span.from + oldOffset, this.spec.inclusiveStart ? -1 : 1) - offset; + var to = mapping.map(span.to + oldOffset, this.spec.inclusiveEnd ? 1 : -1) - offset; + return from >= to ? null : new Decoration(from, to, this) +}; + +InlineType.prototype.valid = function valid (_, span) { return span.from < span.to }; + +InlineType.prototype.eq = function eq (other) { + return this == other || + (other instanceof InlineType && compareObjs(this.attrs, other.attrs) && + compareObjs(this.spec, other.spec)) +}; + +InlineType.is = function is (span) { return span.type instanceof InlineType }; + +var NodeType = function NodeType(attrs, spec) { + this.spec = spec || noSpec; + this.attrs = attrs; +}; + +NodeType.prototype.map = function map (mapping, span, offset, oldOffset) { + var from = mapping.mapResult(span.from + oldOffset, 1); + if (from.deleted) { return null } + var to = mapping.mapResult(span.to + oldOffset, -1); + if (to.deleted || to.pos <= from.pos) { return null } + return new Decoration(from.pos - offset, to.pos - offset, this) +}; + +NodeType.prototype.valid = function valid (node, span) { + var ref = node.content.findIndex(span.from); + var index = ref.index; + var offset = ref.offset; + return offset == span.from && offset + node.child(index).nodeSize == span.to +}; + +NodeType.prototype.eq = function eq (other) { + return this == other || + (other instanceof NodeType && compareObjs(this.attrs, other.attrs) && + compareObjs(this.spec, other.spec)) +}; + +// ::- Decoration objects can be provided to the view through the +// [`decorations` prop](#view.EditorProps.decorations). They come in +// several variants—see the static members of this class for details. +var Decoration = function Decoration(from, to, type) { + // :: number + // The start position of the decoration. + this.from = from; + // :: number + // The end position. Will be the same as `from` for [widget + // decorations](#view.Decoration^widget). + this.to = to; + this.type = type; +}; + +var prototypeAccessors$1 = { spec: { configurable: true } }; + +Decoration.prototype.copy = function copy (from, to) { + return new Decoration(from, to, this.type) +}; + +Decoration.prototype.eq = function eq (other) { + return this.type.eq(other.type) && this.from == other.from && this.to == other.to +}; + +Decoration.prototype.map = function map (mapping, offset, oldOffset) { + return this.type.map(mapping, this, offset, oldOffset) +}; + +// :: (number, union<(view: EditorView, getPos: () → number) → dom.Node, dom.Node>, ?Object) → Decoration +// Creates a widget decoration, which is a DOM node that's shown in +// the document at the given position. It is recommended that you +// delay rendering the widget by passing a function that will be +// called when the widget is actually drawn in a view, but you can +// also directly pass a DOM node. `getPos` can be used to find the +// widget's current document position. +// +// spec::- These options are supported: +// +// side:: ?number +// Controls which side of the document position this widget is +// associated with. When negative, it is drawn before a cursor +// at its position, and content inserted at that position ends +// up after the widget. When zero (the default) or positive, the +// widget is drawn after the cursor and content inserted there +// ends up before the widget. +// +// When there are multiple widgets at a given position, their +// `side` values determine the order in which they appear. Those +// with lower values appear first. The ordering of widgets with +// the same `side` value is unspecified. +// +// When `marks` is null, `side` also determines the marks that +// the widget is wrapped in—those of the node before when +// negative, those of the node after when positive. +// +// marks:: ?[Mark] +// The precise set of marks to draw around the widget. +// +// stopEvent:: ?(event: dom.Event) → bool +// Can be used to control which DOM events, when they bubble out +// of this widget, the editor view should ignore. +// +// key:: ?string +// When comparing decorations of this type (in order to decide +// whether it needs to be redrawn), ProseMirror will by default +// compare the widget DOM node by identity. If you pass a key, +// that key will be compared instead, which can be useful when +// you generate decorations on the fly and don't want to store +// and reuse DOM nodes. Make sure that any widgets with the same +// key are interchangeable—if widgets differ in, for example, +// the behavior of some event handler, they should get +// different keys. +Decoration.widget = function widget (pos, toDOM, spec) { + return new Decoration(pos, pos, new WidgetType(toDOM, spec)) +}; + +// :: (number, number, DecorationAttrs, ?Object) → Decoration +// Creates an inline decoration, which adds the given attributes to +// each inline node between `from` and `to`. +// +// spec::- These options are recognized: +// +// inclusiveStart:: ?bool +// Determines how the left side of the decoration is +// [mapped](#transform.Position_Mapping) when content is +// inserted directly at that position. By default, the decoration +// won't include the new content, but you can set this to `true` +// to make it inclusive. +// +// inclusiveEnd:: ?bool +// Determines how the right side of the decoration is mapped. +// See +// [`inclusiveStart`](#view.Decoration^inline^spec.inclusiveStart). +Decoration.inline = function inline (from, to, attrs, spec) { + return new Decoration(from, to, new InlineType(attrs, spec)) +}; + +// :: (number, number, DecorationAttrs, ?Object) → Decoration +// Creates a node decoration. `from` and `to` should point precisely +// before and after a node in the document. That node, and only that +// node, will receive the given attributes. +// +// spec::- +// +// Optional information to store with the decoration. It +// is also used when comparing decorators for equality. +Decoration.node = function node (from, to, attrs, spec) { + return new Decoration(from, to, new NodeType(attrs, spec)) +}; + +// :: Object +// The spec provided when creating this decoration. Can be useful +// if you've stored extra information in that object. +prototypeAccessors$1.spec.get = function () { return this.type.spec }; + +Object.defineProperties( Decoration.prototype, prototypeAccessors$1 ); + +// DecorationAttrs:: interface +// A set of attributes to add to a decorated node. Most properties +// simply directly correspond to DOM attributes of the same name, +// which will be set to the property's value. These are exceptions: +// +// class:: ?string +// A CSS class name or a space-separated set of class names to be +// _added_ to the classes that the node already had. +// +// style:: ?string +// A string of CSS to be _added_ to the node's existing `style` property. +// +// nodeName:: ?string +// When non-null, the target node is wrapped in a DOM element of +// this type (and the other attributes are applied to this element). + +var none = [], noSpec = {}; + +// ::- A collection of [decorations](#view.Decoration), organized in +// such a way that the drawing algorithm can efficiently use and +// compare them. This is a persistent data structure—it is not +// modified, updates create a new value. +var DecorationSet = function DecorationSet(local, children) { + this.local = local && local.length ? local : none; + this.children = children && children.length ? children : none; +}; + +// :: (Node, [Decoration]) → DecorationSet +// Create a set of decorations, using the structure of the given +// document. +DecorationSet.create = function create (doc, decorations) { + return decorations.length ? buildTree(decorations, doc, 0, noSpec) : empty +}; + +// :: (?number, ?number, ?(spec: Object) → bool) → [Decoration] +// Find all decorations in this set which touch the given range +// (including decorations that start or end directly at the +// boundaries) and match the given predicate on their spec. When +// `start` and `end` are omitted, all decorations in the set are +// considered. When `predicate` isn't given, all decorations are +// assumed to match. +DecorationSet.prototype.find = function find (start, end, predicate) { + var result = []; + this.findInner(start == null ? 0 : start, end == null ? 1e9 : end, result, 0, predicate); + return result +}; + +DecorationSet.prototype.findInner = function findInner (start, end, result, offset, predicate) { + for (var i = 0; i < this.local.length; i++) { + var span = this.local[i]; + if (span.from <= end && span.to >= start && (!predicate || predicate(span.spec))) + { result.push(span.copy(span.from + offset, span.to + offset)); } + } + for (var i$1 = 0; i$1 < this.children.length; i$1 += 3) { + if (this.children[i$1] < end && this.children[i$1 + 1] > start) { + var childOff = this.children[i$1] + 1; + this.children[i$1 + 2].findInner(start - childOff, end - childOff, result, offset + childOff, predicate); + } + } +}; + +// :: (Mapping, Node, ?Object) → DecorationSet +// Map the set of decorations in response to a change in the +// document. +// +// options::- An optional set of options. +// +// onRemove:: ?(decorationSpec: Object) +// When given, this function will be called for each decoration +// that gets dropped as a result of the mapping, passing the +// spec of that decoration. +DecorationSet.prototype.map = function map (mapping, doc, options) { + if (this == empty || mapping.maps.length == 0) { return this } + return this.mapInner(mapping, doc, 0, 0, options || noSpec) +}; + +DecorationSet.prototype.mapInner = function mapInner (mapping, node, offset, oldOffset, options) { + var newLocal; + for (var i = 0; i < this.local.length; i++) { + var mapped = this.local[i].map(mapping, offset, oldOffset); + if (mapped && mapped.type.valid(node, mapped)) { (newLocal || (newLocal = [])).push(mapped); } + else if (options.onRemove) { options.onRemove(this.local[i].spec); } + } + + if (this.children.length) + { return mapChildren(this.children, newLocal, mapping, node, offset, oldOffset, options) } + else + { return newLocal ? new DecorationSet(newLocal.sort(byPos)) : empty } +}; + +// :: (Node, [Decoration]) → DecorationSet +// Add the given array of decorations to the ones in the set, +// producing a new set. Needs access to the current document to +// create the appropriate tree structure. +DecorationSet.prototype.add = function add (doc, decorations) { + if (!decorations.length) { return this } + if (this == empty) { return DecorationSet.create(doc, decorations) } + return this.addInner(doc, decorations, 0) +}; + +DecorationSet.prototype.addInner = function addInner (doc, decorations, offset) { + var this$1 = this; + + var children, childIndex = 0; + doc.forEach(function (childNode, childOffset) { + var baseOffset = childOffset + offset, found; + if (!(found = takeSpansForNode(decorations, childNode, baseOffset))) { return } + + if (!children) { children = this$1.children.slice(); } + while (childIndex < children.length && children[childIndex] < childOffset) { childIndex += 3; } + if (children[childIndex] == childOffset) + { children[childIndex + 2] = children[childIndex + 2].addInner(childNode, found, baseOffset + 1); } + else + { children.splice(childIndex, 0, childOffset, childOffset + childNode.nodeSize, buildTree(found, childNode, baseOffset + 1, noSpec)); } + childIndex += 3; + }); + + var local = moveSpans(childIndex ? withoutNulls(decorations) : decorations, -offset); + return new DecorationSet(local.length ? this.local.concat(local).sort(byPos) : this.local, + children || this.children) +}; + +// :: ([Decoration]) → DecorationSet +// Create a new set that contains the decorations in this set, minus +// the ones in the given array. +DecorationSet.prototype.remove = function remove (decorations) { + if (decorations.length == 0 || this == empty) { return this } + return this.removeInner(decorations, 0) +}; + +DecorationSet.prototype.removeInner = function removeInner (decorations, offset) { + var children = this.children, local = this.local; + for (var i = 0; i < children.length; i += 3) { + var found = (void 0), from = children[i] + offset, to = children[i + 1] + offset; + for (var j = 0, span = (void 0); j < decorations.length; j++) { if (span = decorations[j]) { + if (span.from > from && span.to < to) { + decorations[j] = null + ;(found || (found = [])).push(span); + } + } } + if (!found) { continue } + if (children == this.children) { children = this.children.slice(); } + var removed = children[i + 2].removeInner(found, from + 1); + if (removed != empty) { + children[i + 2] = removed; + } else { + children.splice(i, 3); + i -= 3; + } + } + if (local.length) { for (var i$1 = 0, span$1 = (void 0); i$1 < decorations.length; i$1++) { if (span$1 = decorations[i$1]) { + for (var j$1 = 0; j$1 < local.length; j$1++) { if (local[j$1].type.eq(span$1.type)) { + if (local == this.local) { local = this.local.slice(); } + local.splice(j$1--, 1); + } } + } } } + if (children == this.children && local == this.local) { return this } + return local.length || children.length ? new DecorationSet(local, children) : empty +}; + +DecorationSet.prototype.forChild = function forChild (offset, node) { + if (this == empty) { return this } + if (node.isLeaf) { return DecorationSet.empty } + + var child, local; + for (var i = 0; i < this.children.length; i += 3) { if (this.children[i] >= offset) { + if (this.children[i] == offset) { child = this.children[i + 2]; } + break + } } + var start = offset + 1, end = start + node.content.size; + for (var i$1 = 0; i$1 < this.local.length; i$1++) { + var dec = this.local[i$1]; + if (dec.from < end && dec.to > start && (dec.type instanceof InlineType)) { + var from = Math.max(start, dec.from) - start, to = Math.min(end, dec.to) - start; + if (from < to) { (local || (local = [])).push(dec.copy(from, to)); } + } + } + if (local) { + var localSet = new DecorationSet(local.sort(byPos)); + return child ? new DecorationGroup([localSet, child]) : localSet + } + return child || empty +}; + +DecorationSet.prototype.eq = function eq (other) { + if (this == other) { return true } + if (!(other instanceof DecorationSet) || + this.local.length != other.local.length || + this.children.length != other.children.length) { return false } + for (var i = 0; i < this.local.length; i++) + { if (!this.local[i].eq(other.local[i])) { return false } } + for (var i$1 = 0; i$1 < this.children.length; i$1 += 3) + { if (this.children[i$1] != other.children[i$1] || + this.children[i$1 + 1] != other.children[i$1 + 1] || + !this.children[i$1 + 2].eq(other.children[i$1 + 2])) { return false } } + return true +}; + +DecorationSet.prototype.locals = function locals (node) { + return removeOverlap(this.localsInner(node)) +}; + +DecorationSet.prototype.localsInner = function localsInner (node) { + if (this == empty) { return none } + if (node.inlineContent || !this.local.some(InlineType.is)) { return this.local } + var result = []; + for (var i = 0; i < this.local.length; i++) { + if (!(this.local[i].type instanceof InlineType)) + { result.push(this.local[i]); } + } + return result +}; + +var empty = new DecorationSet(); + +// :: DecorationSet +// The empty set of decorations. +DecorationSet.empty = empty; + +DecorationSet.removeOverlap = removeOverlap; + +// :- An abstraction that allows the code dealing with decorations to +// treat multiple DecorationSet objects as if it were a single object +// with (a subset of) the same interface. +var DecorationGroup = function DecorationGroup(members) { + this.members = members; +}; + +DecorationGroup.prototype.forChild = function forChild (offset, child) { + if (child.isLeaf) { return DecorationSet.empty } + var found = []; + for (var i = 0; i < this.members.length; i++) { + var result = this.members[i].forChild(offset, child); + if (result == empty) { continue } + if (result instanceof DecorationGroup) { found = found.concat(result.members); } + else { found.push(result); } + } + return DecorationGroup.from(found) +}; + +DecorationGroup.prototype.eq = function eq (other) { + if (!(other instanceof DecorationGroup) || + other.members.length != this.members.length) { return false } + for (var i = 0; i < this.members.length; i++) + { if (!this.members[i].eq(other.members[i])) { return false } } + return true +}; + +DecorationGroup.prototype.locals = function locals (node) { + var result, sorted = true; + for (var i = 0; i < this.members.length; i++) { + var locals = this.members[i].localsInner(node); + if (!locals.length) { continue } + if (!result) { + result = locals; + } else { + if (sorted) { + result = result.slice(); + sorted = false; + } + for (var j = 0; j < locals.length; j++) { result.push(locals[j]); } + } + } + return result ? removeOverlap(sorted ? result : result.sort(byPos)) : none +}; + +// : ([DecorationSet]) → union +// Create a group for the given array of decoration sets, or return +// a single set when possible. +DecorationGroup.from = function from (members) { + switch (members.length) { + case 0: return empty + case 1: return members[0] + default: return new DecorationGroup(members) + } +}; + +function mapChildren(oldChildren, newLocal, mapping, node, offset, oldOffset, options) { + var children = oldChildren.slice(); + + // Mark the children that are directly touched by changes, and + // move those that are after the changes. + var shift = function (oldStart, oldEnd, newStart, newEnd) { + for (var i = 0; i < children.length; i += 3) { + var end = children[i + 1], dSize = (void 0); + if (end == -1 || oldStart > end + oldOffset) { continue } + if (oldEnd >= children[i] + oldOffset) { + children[i + 1] = -1; + } else if (dSize = (newEnd - newStart) - (oldEnd - oldStart) + (oldOffset - offset)) { + children[i] += dSize; + children[i + 1] += dSize; + } + } + }; + for (var i = 0; i < mapping.maps.length; i++) { mapping.maps[i].forEach(shift); } + + // Find the child nodes that still correspond to a single node, + // recursively call mapInner on them and update their positions. + var mustRebuild = false; + for (var i$1 = 0; i$1 < children.length; i$1 += 3) { if (children[i$1 + 1] == -1) { // Touched nodes + var from = mapping.map(children[i$1] + oldOffset), fromLocal = from - offset; + if (fromLocal < 0 || fromLocal >= node.content.size) { + mustRebuild = true; + continue + } + // Must read oldChildren because children was tagged with -1 + var to = mapping.map(oldChildren[i$1 + 1] + oldOffset, -1), toLocal = to - offset; + var ref = node.content.findIndex(fromLocal); + var index = ref.index; + var childOffset = ref.offset; + var childNode = node.maybeChild(index); + if (childNode && childOffset == fromLocal && childOffset + childNode.nodeSize == toLocal) { + var mapped = children[i$1 + 2].mapInner(mapping, childNode, from + 1, children[i$1] + oldOffset + 1, options); + if (mapped != empty) { + children[i$1] = fromLocal; + children[i$1 + 1] = toLocal; + children[i$1 + 2] = mapped; + } else { + children[i$1 + 1] = -2; + mustRebuild = true; + } + } else { + mustRebuild = true; + } + } } + + // Remaining children must be collected and rebuilt into the appropriate structure + if (mustRebuild) { + var decorations = mapAndGatherRemainingDecorations(children, oldChildren, newLocal || [], mapping, + offset, oldOffset, options); + var built = buildTree(decorations, node, 0, options); + newLocal = built.local; + for (var i$2 = 0; i$2 < children.length; i$2 += 3) { if (children[i$2 + 1] < 0) { + children.splice(i$2, 3); + i$2 -= 3; + } } + for (var i$3 = 0, j = 0; i$3 < built.children.length; i$3 += 3) { + var from$1 = built.children[i$3]; + while (j < children.length && children[j] < from$1) { j += 3; } + children.splice(j, 0, built.children[i$3], built.children[i$3 + 1], built.children[i$3 + 2]); + } + } + + return new DecorationSet(newLocal && newLocal.sort(byPos), children) +} + +function moveSpans(spans, offset) { + if (!offset || !spans.length) { return spans } + var result = []; + for (var i = 0; i < spans.length; i++) { + var span = spans[i]; + result.push(new Decoration(span.from + offset, span.to + offset, span.type)); + } + return result +} + +function mapAndGatherRemainingDecorations(children, oldChildren, decorations, mapping, offset, oldOffset, options) { + // Gather all decorations from the remaining marked children + function gather(set, oldOffset) { + for (var i = 0; i < set.local.length; i++) { + var mapped = set.local[i].map(mapping, offset, oldOffset); + if (mapped) { decorations.push(mapped); } + else if (options.onRemove) { options.onRemove(set.local[i].spec); } + } + for (var i$1 = 0; i$1 < set.children.length; i$1 += 3) + { gather(set.children[i$1 + 2], set.children[i$1] + oldOffset + 1); } + } + for (var i = 0; i < children.length; i += 3) { if (children[i + 1] == -1) + { gather(children[i + 2], oldChildren[i] + oldOffset + 1); } } + + return decorations +} + +function takeSpansForNode(spans, node, offset) { + if (node.isLeaf) { return null } + var end = offset + node.nodeSize, found = null; + for (var i = 0, span = (void 0); i < spans.length; i++) { + if ((span = spans[i]) && span.from > offset && span.to < end) { +(found || (found = [])).push(span); + spans[i] = null; + } + } + return found +} + +function withoutNulls(array) { + var result = []; + for (var i = 0; i < array.length; i++) + { if (array[i] != null) { result.push(array[i]); } } + return result +} + +// : ([Decoration], Node, number) → DecorationSet +// Build up a tree that corresponds to a set of decorations. `offset` +// is a base offset that should be subtractet from the `from` and `to` +// positions in the spans (so that we don't have to allocate new spans +// for recursive calls). +function buildTree(spans, node, offset, options) { + var children = [], hasNulls = false; + node.forEach(function (childNode, localStart) { + var found = takeSpansForNode(spans, childNode, localStart + offset); + if (found) { + hasNulls = true; + var subtree = buildTree(found, childNode, offset + localStart + 1, options); + if (subtree != empty) + { children.push(localStart, localStart + childNode.nodeSize, subtree); } + } + }); + var locals = moveSpans(hasNulls ? withoutNulls(spans) : spans, -offset).sort(byPos); + for (var i = 0; i < locals.length; i++) { if (!locals[i].type.valid(node, locals[i])) { + if (options.onRemove) { options.onRemove(locals[i].spec); } + locals.splice(i--, 1); + } } + return locals.length || children.length ? new DecorationSet(locals, children) : empty +} + +// : (Decoration, Decoration) → number +// Used to sort decorations so that ones with a low start position +// come first, and within a set with the same start position, those +// with an smaller end position come first. +function byPos(a, b) { + return a.from - b.from || a.to - b.to +} + +// : ([Decoration]) → [Decoration] +// Scan a sorted array of decorations for partially overlapping spans, +// and split those so that only fully overlapping spans are left (to +// make subsequent rendering easier). Will return the input array if +// no partially overlapping spans are found (the common case). +function removeOverlap(spans) { + var working = spans; + for (var i = 0; i < working.length - 1; i++) { + var span = working[i]; + if (span.from != span.to) { for (var j = i + 1; j < working.length; j++) { + var next = working[j]; + if (next.from == span.from) { + if (next.to != span.to) { + if (working == spans) { working = spans.slice(); } + // Followed by a partially overlapping larger span. Split that + // span. + working[j] = next.copy(next.from, span.to); + insertAhead(working, j + 1, next.copy(span.to, next.to)); + } + continue + } else { + if (next.from < span.to) { + if (working == spans) { working = spans.slice(); } + // The end of this one overlaps with a subsequent span. Split + // this one. + working[i] = span.copy(span.from, next.from); + insertAhead(working, j, span.copy(next.from, span.to)); + } + break + } + } } + } + return working +} + +function insertAhead(array, i, deco) { + while (i < array.length && byPos(deco, array[i]) > 0) { i++; } + array.splice(i, 0, deco); +} + +// : (EditorView) → union +// Get the decorations associated with the current props of a view. +function viewDecorations(view) { + var found = []; + view.someProp("decorations", function (f) { + var result = f(view.state); + if (result && result != empty) { found.push(result); } + }); + if (view.cursorWrapper) + { found.push(DecorationSet.create(view.state.doc, [view.cursorWrapper.deco])); } + return DecorationGroup.from(found) +} + +// ::- An editor view manages the DOM structure that represents an +// editable document. Its state and behavior are determined by its +// [props](#view.DirectEditorProps). +var EditorView = function EditorView(place, props) { + this._props = props; + // :: EditorState + // The view's current [state](#state.EditorState). + this.state = props.state; + + this.dispatch = this.dispatch.bind(this); + + this._root = null; + this.focused = false; + + // :: dom.Element + // An editable DOM node containing the document. (You probably + // should not directly interfere with its content.) + this.dom = (place && place.mount) || document.createElement("div"); + if (place) { + if (place.appendChild) { place.appendChild(this.dom); } + else if (place.apply) { place(this.dom); } + else if (place.mount) { this.mounted = true; } + } + + // :: bool + // Indicates whether the editor is currently [editable](#view.EditorProps.editable). + this.editable = getEditable(this); + this.markCursor = null; + this.cursorWrapper = null; + updateCursorWrapper(this); + this.nodeViews = buildNodeViews(this); + this.docView = docViewDesc(this.state.doc, computeDocDeco(this), viewDecorations(this), this.dom, this); + + this.lastSelectedViewDesc = null; + // :: ?{slice: Slice, move: bool} + // When editor content is being dragged, this object contains + // information about the dragged slice and whether it is being + // copied or moved. At any other time, it is null. + this.dragging = null; + + initInput(this); + + this.pluginViews = []; + this.updatePluginViews(); +}; + +var prototypeAccessors$2 = { props: { configurable: true },root: { configurable: true } }; + +// composing:: boolean +// Holds `true` when a +// [composition](https://developer.mozilla.org/en-US/docs/Mozilla/IME_handling_guide) +// is active. + +// :: DirectEditorProps +// The view's current [props](#view.EditorProps). +prototypeAccessors$2.props.get = function () { + if (this._props.state != this.state) { + var prev = this._props; + this._props = {}; + for (var name in prev) { this._props[name] = prev[name]; } + this._props.state = this.state; + } + return this._props +}; + +// :: (DirectEditorProps) +// Update the view's props. Will immediately cause an update to +// the DOM. +EditorView.prototype.update = function update (props) { + if (props.handleDOMEvents != this._props.handleDOMEvents) { ensureListeners(this); } + this._props = props; + this.updateStateInner(props.state, true); +}; + +// :: (DirectEditorProps) +// Update the view by updating existing props object with the object +// given as argument. Equivalent to `view.update(Object.assign({}, +// view.props, props))`. +EditorView.prototype.setProps = function setProps (props) { + var updated = {}; + for (var name in this._props) { updated[name] = this._props[name]; } + updated.state = this.state; + for (var name$1 in props) { updated[name$1] = props[name$1]; } + this.update(updated); +}; + +// :: (EditorState) +// Update the editor's `state` prop, without touching any of the +// other props. +EditorView.prototype.updateState = function updateState (state) { + this.updateStateInner(state, this.state.plugins != state.plugins); +}; + +EditorView.prototype.updateStateInner = function updateStateInner (state, reconfigured) { + var this$1 = this; + + var prev = this.state, redraw = false; + this.state = state; + if (reconfigured) { + var nodeViews = buildNodeViews(this); + if (changedNodeViews(nodeViews, this.nodeViews)) { + this.nodeViews = nodeViews; + redraw = true; + } + ensureListeners(this); + } + + this.editable = getEditable(this); + updateCursorWrapper(this); + var innerDeco = viewDecorations(this), outerDeco = computeDocDeco(this); + + var scroll = reconfigured ? "reset" + : state.scrollToSelection > prev.scrollToSelection ? "to selection" : "preserve"; + var updateDoc = redraw || !this.docView.matchesNode(state.doc, outerDeco, innerDeco); + var updateSel = updateDoc || !state.selection.eq(prev.selection); + var oldScrollPos = scroll == "preserve" && updateSel && this.dom.style.overflowAnchor == null && storeScrollPos(this); + + if (updateSel) { + this.domObserver.stop(); + var forceSelUpdate = false; + if (updateDoc) { + // Work around an issue in Chrome where changing the DOM + // around the active selection puts it into a broken state + // where the thing the user sees differs from the selection + // reported by the Selection object (#710) + var startSelContext = result.chrome && selectionContext(this.root); + if (redraw || !this.docView.update(state.doc, outerDeco, innerDeco, this)) { + this.docView.destroy(); + this.docView = docViewDesc(state.doc, outerDeco, innerDeco, this.dom, this); + } + if (startSelContext) + { forceSelUpdate = !this.composing && needChromeSelectionForce(startSelContext, this.root); } + // IE11 will sometimes _report_ the selection as being in the + // right place but actually draw/use a different selection + // after a deletion (#973). + if (result.ie && result.ie_version <= 11 && !prev.selection.empty && state.selection.empty && + state.doc.content.size < prev.doc.content.size) + { forceSelUpdate = true; } + } + // Work around for an issue where an update arriving right between + // a DOM selection change and the "selectionchange" event for it + // can cause a spurious DOM selection update, disrupting mouse + // drag selection. + if (forceSelUpdate || + !(this.mouseDown && this.domObserver.currentSelection.eq(this.root.getSelection()) && anchorInRightPlace(this))) { + selectionToDOM(this, forceSelUpdate); + } else { + syncNodeSelection(this, state.selection); + this.domObserver.setCurSelection(); + } + this.domObserver.start(); + } + + this.updatePluginViews(prev); + + if (scroll == "reset") { + this.dom.scrollTop = 0; + } else if (scroll == "to selection") { + var startDOM = this.root.getSelection().focusNode; + if (this.someProp("handleScrollToSelection", function (f) { return f(this$1); })) + ; // Handled + else if (state.selection instanceof prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["NodeSelection"]) + { scrollRectIntoView(this, this.docView.domAfterPos(state.selection.from).getBoundingClientRect(), startDOM); } + else + { scrollRectIntoView(this, this.coordsAtPos(state.selection.head), startDOM); } + } else if (oldScrollPos) { + resetScrollPos(oldScrollPos); + } +}; + +EditorView.prototype.destroyPluginViews = function destroyPluginViews () { + var view; + while (view = this.pluginViews.pop()) { if (view.destroy) { view.destroy(); } } +}; + +EditorView.prototype.updatePluginViews = function updatePluginViews (prevState) { + if (!prevState || prevState.plugins != this.state.plugins) { + this.destroyPluginViews(); + for (var i = 0; i < this.state.plugins.length; i++) { + var plugin = this.state.plugins[i]; + if (plugin.spec.view) { this.pluginViews.push(plugin.spec.view(this)); } + } + } else { + for (var i$1 = 0; i$1 < this.pluginViews.length; i$1++) { + var pluginView = this.pluginViews[i$1]; + if (pluginView.update) { pluginView.update(this, prevState); } + } + } +}; + +// :: (string, ?(prop: *) → *) → * +// Goes over the values of a prop, first those provided directly, +// then those from plugins (in order), and calls `f` every time a +// non-undefined value is found. When `f` returns a truthy value, +// that is immediately returned. When `f` isn't provided, it is +// treated as the identity function (the prop value is returned +// directly). +EditorView.prototype.someProp = function someProp (propName, f) { + var prop = this._props && this._props[propName], value; + if (prop != null && (value = f ? f(prop) : prop)) { return value } + var plugins = this.state.plugins; + if (plugins) { for (var i = 0; i < plugins.length; i++) { + var prop$1 = plugins[i].props[propName]; + if (prop$1 != null && (value = f ? f(prop$1) : prop$1)) { return value } + } } +}; + +// :: () → bool +// Query whether the view has focus. +EditorView.prototype.hasFocus = function hasFocus () { + return this.root.activeElement == this.dom +}; + +// :: () +// Focus the editor. +EditorView.prototype.focus = function focus () { + this.domObserver.stop(); + if (this.editable) { focusPreventScroll(this.dom); } + selectionToDOM(this); + this.domObserver.start(); +}; + +// :: union +// Get the document root in which the editor exists. This will +// usually be the top-level `document`, but might be a [shadow +// DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Shadow_DOM) +// root if the editor is inside one. +prototypeAccessors$2.root.get = function () { + var cached = this._root; + if (cached == null) { for (var search = this.dom.parentNode; search; search = search.parentNode) { + if (search.nodeType == 9 || (search.nodeType == 11 && search.host)) + { return this._root = search } + } } + return cached || document +}; + +// :: ({left: number, top: number}) → ?{pos: number, inside: number} +// Given a pair of viewport coordinates, return the document +// position that corresponds to them. May return null if the given +// coordinates aren't inside of the editor. When an object is +// returned, its `pos` property is the position nearest to the +// coordinates, and its `inside` property holds the position of the +// inner node that the position falls inside of, or -1 if it is at +// the top level, not in any node. +EditorView.prototype.posAtCoords = function posAtCoords$1 (coords) { + return posAtCoords(this, coords) +}; + +// :: (number) → {left: number, right: number, top: number, bottom: number} +// Returns the viewport rectangle at a given document position. `left` +// and `right` will be the same number, as this returns a flat +// cursor-ish rectangle. +EditorView.prototype.coordsAtPos = function coordsAtPos$1 (pos) { + return coordsAtPos(this, pos) +}; + +// :: (number) → {node: dom.Node, offset: number} +// Find the DOM position that corresponds to the given document +// position. Note that you should **not** mutate the editor's +// internal DOM, only inspect it (and even that is usually not +// necessary). +EditorView.prototype.domAtPos = function domAtPos (pos) { + return this.docView.domFromPos(pos) +}; + +// :: (number) → ?dom.Node +// Find the DOM node that represents the document node after the +// given position. May return `null` when the position doesn't point +// in front of a node or if the node is inside an opaque node view. +// +// This is intended to be able to call things like +// `getBoundingClientRect` on that DOM node. Do **not** mutate the +// editor DOM directly, or add styling this way, since that will be +// immediately overriden by the editor as it redraws the node. +EditorView.prototype.nodeDOM = function nodeDOM (pos) { + var desc = this.docView.descAt(pos); + return desc ? desc.nodeDOM : null +}; + +// :: (dom.Node, number, ?number) → number +// Find the document position that corresponds to a given DOM +// position. (Whenever possible, it is preferable to inspect the +// document structure directly, rather than poking around in the +// DOM, but sometimes—for example when interpreting an event +// target—you don't have a choice.) +// +// The `bias` parameter can be used to influence which side of a DOM +// node to use when the position is inside a leaf node. +EditorView.prototype.posAtDOM = function posAtDOM (node, offset, bias) { + if ( bias === void 0 ) bias = -1; + + var pos = this.docView.posFromDOM(node, offset, bias); + if (pos == null) { throw new RangeError("DOM position not inside the editor") } + return pos +}; + +// :: (union<"up", "down", "left", "right", "forward", "backward">, ?EditorState) → bool +// Find out whether the selection is at the end of a textblock when +// moving in a given direction. When, for example, given `"left"`, +// it will return true if moving left from the current cursor +// position would leave that position's parent textblock. Will apply +// to the view's current state by default, but it is possible to +// pass a different state. +EditorView.prototype.endOfTextblock = function endOfTextblock$1 (dir, state) { + return endOfTextblock(this, state || this.state, dir) +}; + +// :: () +// Removes the editor from the DOM and destroys all [node +// views](#view.NodeView). +EditorView.prototype.destroy = function destroy () { + if (!this.docView) { return } + destroyInput(this); + this.destroyPluginViews(); + if (this.mounted) { + this.docView.update(this.state.doc, [], viewDecorations(this), this); + this.dom.textContent = ""; + } else if (this.dom.parentNode) { + this.dom.parentNode.removeChild(this.dom); + } + this.docView.destroy(); + this.docView = null; +}; + +// Used for testing. +EditorView.prototype.dispatchEvent = function dispatchEvent$1 (event) { + return dispatchEvent(this, event) +}; + +// :: (Transaction) +// Dispatch a transaction. Will call +// [`dispatchTransaction`](#view.DirectEditorProps.dispatchTransaction) +// when given, and otherwise defaults to applying the transaction to +// the current state and calling +// [`updateState`](#view.EditorView.updateState) with the result. +// This method is bound to the view instance, so that it can be +// easily passed around. +EditorView.prototype.dispatch = function dispatch (tr) { + var dispatchTransaction = this._props.dispatchTransaction; + if (dispatchTransaction) { dispatchTransaction.call(this, tr); } + else { this.updateState(this.state.apply(tr)); } +}; + +Object.defineProperties( EditorView.prototype, prototypeAccessors$2 ); + +function computeDocDeco(view) { + var attrs = Object.create(null); + attrs.class = "ProseMirror"; + attrs.contenteditable = String(view.editable); + + view.someProp("attributes", function (value) { + if (typeof value == "function") { value = value(view.state); } + if (value) { for (var attr in value) { + if (attr == "class") + { attrs.class += " " + value[attr]; } + else if (!attrs[attr] && attr != "contenteditable" && attr != "nodeName") + { attrs[attr] = String(value[attr]); } + } } + }); + + return [Decoration.node(0, view.state.doc.content.size, attrs)] +} + +function updateCursorWrapper(view) { + var ref = view.state.selection; + var $head = ref.$head; + var $anchor = ref.$anchor; + var visible = ref.visible; + if (view.markCursor) { + var dom = document.createElement("img"); + dom.setAttribute("mark-placeholder", "true"); + view.cursorWrapper = {dom: dom, deco: Decoration.widget($head.pos, dom, {raw: true, marks: view.markCursor})}; + } else if (visible || $head.pos != $anchor.pos) { + view.cursorWrapper = null; + } else { + var dom$1; + if (!view.cursorWrapper || view.cursorWrapper.dom.childNodes.length) { + dom$1 = document.createElement("div"); + dom$1.style.position = "absolute"; + dom$1.style.left = "-100000px"; + } else if (view.cursorWrapper.deco.pos != $head.pos) { + dom$1 = view.cursorWrapper.dom; + } + if (dom$1) + { view.cursorWrapper = {dom: dom$1, deco: Decoration.widget($head.pos, dom$1, {raw: true})}; } + } +} + +function getEditable(view) { + return !view.someProp("editable", function (value) { return value(view.state) === false; }) +} + +function selectionContext(root) { + var ref = root.getSelection(); + var offset = ref.focusOffset; + var node = ref.focusNode; + if (!node || node.nodeType == 3) { return null } + return [node, offset, + node.nodeType == 1 ? node.childNodes[offset - 1] : null, + node.nodeType == 1 ? node.childNodes[offset] : null] +} + +function needChromeSelectionForce(context, root) { + var newContext = selectionContext(root); + if (!newContext || newContext[0].nodeType == 3) { return false } + for (var i = 0; i < context.length; i++) { if (newContext[i] != context[i]) { return true } } + return false +} + +function buildNodeViews(view) { + var result = {}; + view.someProp("nodeViews", function (obj) { + for (var prop in obj) { if (!Object.prototype.hasOwnProperty.call(result, prop)) + { result[prop] = obj[prop]; } } + }); + return result +} + +function changedNodeViews(a, b) { + var nA = 0, nB = 0; + for (var prop in a) { + if (a[prop] != b[prop]) { return true } + nA++; + } + for (var _ in b) { nB++; } + return nA != nB +} + +// EditorProps:: interface +// +// Props are configuration values that can be passed to an editor view +// or included in a plugin. This interface lists the supported props. +// +// The various event-handling functions may all return `true` to +// indicate that they handled the given event. The view will then take +// care to call `preventDefault` on the event, except with +// `handleDOMEvents`, where the handler itself is responsible for that. +// +// How a prop is resolved depends on the prop. Handler functions are +// called one at a time, starting with the base props and then +// searching through the plugins (in order of appearance) until one of +// them returns true. For some props, the first plugin that yields a +// value gets precedence. +// +// handleDOMEvents:: ?Object<(view: EditorView, event: dom.Event) → bool> +// Can be an object mapping DOM event type names to functions that +// handle them. Such functions will be called before any handling +// ProseMirror does of events fired on the editable DOM element. +// Contrary to the other event handling props, when returning true +// from such a function, you are responsible for calling +// `preventDefault` yourself (or not, if you want to allow the +// default behavior). +// +// handleKeyDown:: ?(view: EditorView, event: dom.KeyboardEvent) → bool +// Called when the editor receives a `keydown` event. +// +// handleKeyPress:: ?(view: EditorView, event: dom.KeyboardEvent) → bool +// Handler for `keypress` events. +// +// handleTextInput:: ?(view: EditorView, from: number, to: number, text: string) → bool +// Whenever the user directly input text, this handler is called +// before the input is applied. If it returns `true`, the default +// behavior of actually inserting the text is suppressed. +// +// handleClickOn:: ?(view: EditorView, pos: number, node: Node, nodePos: number, event: dom.MouseEvent, direct: bool) → bool +// Called for each node around a click, from the inside out. The +// `direct` flag will be true for the inner node. +// +// handleClick:: ?(view: EditorView, pos: number, event: dom.MouseEvent) → bool +// Called when the editor is clicked, after `handleClickOn` handlers +// have been called. +// +// handleDoubleClickOn:: ?(view: EditorView, pos: number, node: Node, nodePos: number, event: dom.MouseEvent, direct: bool) → bool +// Called for each node around a double click. +// +// handleDoubleClick:: ?(view: EditorView, pos: number, event: dom.MouseEvent) → bool +// Called when the editor is double-clicked, after `handleDoubleClickOn`. +// +// handleTripleClickOn:: ?(view: EditorView, pos: number, node: Node, nodePos: number, event: dom.MouseEvent, direct: bool) → bool +// Called for each node around a triple click. +// +// handleTripleClick:: ?(view: EditorView, pos: number, event: dom.MouseEvent) → bool +// Called when the editor is triple-clicked, after `handleTripleClickOn`. +// +// handlePaste:: ?(view: EditorView, event: dom.Event, slice: Slice) → bool +// Can be used to override the behavior of pasting. `slice` is the +// pasted content parsed by the editor, but you can directly access +// the event to get at the raw content. +// +// handleDrop:: ?(view: EditorView, event: dom.Event, slice: Slice, moved: bool) → bool +// Called when something is dropped on the editor. `moved` will be +// true if this drop moves from the current selection (which should +// thus be deleted). +// +// handleScrollToSelection:: ?(view: EditorView) → bool +// Called when the view, after updating its state, tries to scroll +// the selection into view. A handler function may return false to +// indicate that it did not handle the scrolling and further +// handlers or the default behavior should be tried. +// +// createSelectionBetween:: ?(view: EditorView, anchor: ResolvedPos, head: ResolvedPos) → ?Selection +// Can be used to override the way a selection is created when +// reading a DOM selection between the given anchor and head. +// +// domParser:: ?DOMParser +// The [parser](#model.DOMParser) to use when reading editor changes +// from the DOM. Defaults to calling +// [`DOMParser.fromSchema`](#model.DOMParser^fromSchema) on the +// editor's schema. +// +// transformPastedHTML:: ?(html: string) → string +// Can be used to transform pasted HTML text, _before_ it is parsed, +// for example to clean it up. +// +// clipboardParser:: ?DOMParser +// The [parser](#model.DOMParser) to use when reading content from +// the clipboard. When not given, the value of the +// [`domParser`](#view.EditorProps.domParser) prop is used. +// +// transformPastedText:: ?(text: string) → string +// Transform pasted plain text. +// +// clipboardTextParser:: ?(text: string, $context: ResolvedPos) → Slice +// A function to parse text from the clipboard into a document +// slice. Called after +// [`transformPastedText`](#view.EditorProps.transformPastedText). +// The default behavior is to split the text into lines, wrap them +// in `

      ` tags, and call +// [`clipboardParser`](#view.EditorProps.clipboardParser) on it. +// +// transformPasted:: ?(Slice) → Slice +// Can be used to transform pasted content before it is applied to +// the document. +// +// nodeViews:: ?Object<(node: Node, view: EditorView, getPos: () → number, decorations: [Decoration]) → NodeView> +// Allows you to pass custom rendering and behavior logic for nodes +// and marks. Should map node and mark names to constructor +// functions that produce a [`NodeView`](#view.NodeView) object +// implementing the node's display behavior. For nodes, the third +// argument `getPos` is a function that can be called to get the +// node's current position, which can be useful when creating +// transactions to update it. For marks, the third argument is a +// boolean that indicates whether the mark's content is inline. +// +// `decorations` is an array of node or inline decorations that are +// active around the node. They are automatically drawn in the +// normal way, and you will usually just want to ignore this, but +// they can also be used as a way to provide context information to +// the node view without adding it to the document itself. +// +// clipboardSerializer:: ?DOMSerializer +// The DOM serializer to use when putting content onto the +// clipboard. If not given, the result of +// [`DOMSerializer.fromSchema`](#model.DOMSerializer^fromSchema) +// will be used. +// +// clipboardTextSerializer:: ?(Slice) → string +// A function that will be called to get the text for the current +// selection when copying text to the clipboard. By default, the +// editor will use [`textBetween`](#model.Node.textBetween) on the +// selected range. +// +// decorations:: ?(state: EditorState) → ?DecorationSet +// A set of [document decorations](#view.Decoration) to show in the +// view. +// +// editable:: ?(state: EditorState) → bool +// When this returns false, the content of the view is not directly +// editable. +// +// attributes:: ?union, (EditorState) → ?Object> +// Control the DOM attributes of the editable element. May be either +// an object or a function going from an editor state to an object. +// By default, the element will get a class `"ProseMirror"`, and +// will have its `contentEditable` attribute determined by the +// [`editable` prop](#view.EditorProps.editable). Additional classes +// provided here will be added to the class. For other attributes, +// the value provided first (as in +// [`someProp`](#view.EditorView.someProp)) will be used. +// +// scrollThreshold:: ?union +// Determines the distance (in pixels) between the cursor and the +// end of the visible viewport at which point, when scrolling the +// cursor into view, scrolling takes place. Defaults to 0. +// +// scrollMargin:: ?union +// Determines the extra space (in pixels) that is left above or +// below the cursor when it is scrolled into view. Defaults to 5. + +// DirectEditorProps:: interface extends EditorProps +// +// The props object given directly to the editor view supports two +// fields that can't be used in plugins: +// +// state:: EditorState +// The current state of the editor. +// +// dispatchTransaction:: ?(tr: Transaction) +// The callback over which to send transactions (state updates) +// produced by the view. If you specify this, you probably want to +// make sure this ends up calling the view's +// [`updateState`](#view.EditorView.updateState) method with a new +// state that has the transaction +// [applied](#state.EditorState.apply). The callback will be bound to have +// the view instance as its `this` binding. + + +//# sourceMappingURL=index.es.js.map + + +/***/ }), + +/***/ "./node_modules/rope-sequence/dist/index.es.js": +/*!*****************************************************!*\ + !*** ./node_modules/rope-sequence/dist/index.es.js ***! + \*****************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +var GOOD_LEAF_SIZE = 200; + +// :: class A rope sequence is a persistent sequence data structure +// that supports appending, prepending, and slicing without doing a +// full copy. It is represented as a mostly-balanced tree. +var RopeSequence = function RopeSequence () {}; + +RopeSequence.prototype.append = function append (other) { + if (!other.length) { return this } + other = RopeSequence.from(other); + + return (!this.length && other) || + (other.length < GOOD_LEAF_SIZE && this.leafAppend(other)) || + (this.length < GOOD_LEAF_SIZE && other.leafPrepend(this)) || + this.appendInner(other) +}; + +// :: (union<[T], RopeSequence>) → RopeSequence +// Prepend an array or other rope to this one, returning a new rope. +RopeSequence.prototype.prepend = function prepend (other) { + if (!other.length) { return this } + return RopeSequence.from(other).append(this) +}; + +RopeSequence.prototype.appendInner = function appendInner (other) { + return new Append(this, other) +}; + +// :: (?number, ?number) → RopeSequence +// Create a rope repesenting a sub-sequence of this rope. +RopeSequence.prototype.slice = function slice (from, to) { + if ( from === void 0 ) from = 0; + if ( to === void 0 ) to = this.length; + + if (from >= to) { return RopeSequence.empty } + return this.sliceInner(Math.max(0, from), Math.min(this.length, to)) +}; + +// :: (number) → T +// Retrieve the element at the given position from this rope. +RopeSequence.prototype.get = function get (i) { + if (i < 0 || i >= this.length) { return undefined } + return this.getInner(i) +}; + +// :: ((element: T, index: number) → ?bool, ?number, ?number) +// Call the given function for each element between the given +// indices. This tends to be more efficient than looping over the +// indices and calling `get`, because it doesn't have to descend the +// tree for every element. +RopeSequence.prototype.forEach = function forEach (f, from, to) { + if ( from === void 0 ) from = 0; + if ( to === void 0 ) to = this.length; + + if (from <= to) + { this.forEachInner(f, from, to, 0); } + else + { this.forEachInvertedInner(f, from, to, 0); } +}; + +// :: ((element: T, index: number) → U, ?number, ?number) → [U] +// Map the given functions over the elements of the rope, producing +// a flat array. +RopeSequence.prototype.map = function map (f, from, to) { + if ( from === void 0 ) from = 0; + if ( to === void 0 ) to = this.length; + + var result = []; + this.forEach(function (elt, i) { return result.push(f(elt, i)); }, from, to); + return result +}; + +// :: (?union<[T], RopeSequence>) → RopeSequence +// Create a rope representing the given array, or return the rope +// itself if a rope was given. +RopeSequence.from = function from (values) { + if (values instanceof RopeSequence) { return values } + return values && values.length ? new Leaf(values) : RopeSequence.empty +}; + +var Leaf = /*@__PURE__*/(function (RopeSequence) { + function Leaf(values) { + RopeSequence.call(this); + this.values = values; + } + + if ( RopeSequence ) Leaf.__proto__ = RopeSequence; + Leaf.prototype = Object.create( RopeSequence && RopeSequence.prototype ); + Leaf.prototype.constructor = Leaf; + + var prototypeAccessors = { length: { configurable: true },depth: { configurable: true } }; + + Leaf.prototype.flatten = function flatten () { + return this.values + }; + + Leaf.prototype.sliceInner = function sliceInner (from, to) { + if (from == 0 && to == this.length) { return this } + return new Leaf(this.values.slice(from, to)) + }; + + Leaf.prototype.getInner = function getInner (i) { + return this.values[i] + }; + + Leaf.prototype.forEachInner = function forEachInner (f, from, to, start) { + for (var i = from; i < to; i++) + { if (f(this.values[i], start + i) === false) { return false } } + }; + + Leaf.prototype.forEachInvertedInner = function forEachInvertedInner (f, from, to, start) { + for (var i = from - 1; i >= to; i--) + { if (f(this.values[i], start + i) === false) { return false } } + }; + + Leaf.prototype.leafAppend = function leafAppend (other) { + if (this.length + other.length <= GOOD_LEAF_SIZE) + { return new Leaf(this.values.concat(other.flatten())) } + }; + + Leaf.prototype.leafPrepend = function leafPrepend (other) { + if (this.length + other.length <= GOOD_LEAF_SIZE) + { return new Leaf(other.flatten().concat(this.values)) } + }; + + prototypeAccessors.length.get = function () { return this.values.length }; + + prototypeAccessors.depth.get = function () { return 0 }; + + Object.defineProperties( Leaf.prototype, prototypeAccessors ); + + return Leaf; +}(RopeSequence)); + +// :: RopeSequence +// The empty rope sequence. +RopeSequence.empty = new Leaf([]); + +var Append = /*@__PURE__*/(function (RopeSequence) { + function Append(left, right) { + RopeSequence.call(this); + this.left = left; + this.right = right; + this.length = left.length + right.length; + this.depth = Math.max(left.depth, right.depth) + 1; + } + + if ( RopeSequence ) Append.__proto__ = RopeSequence; + Append.prototype = Object.create( RopeSequence && RopeSequence.prototype ); + Append.prototype.constructor = Append; + + Append.prototype.flatten = function flatten () { + return this.left.flatten().concat(this.right.flatten()) + }; + + Append.prototype.getInner = function getInner (i) { + return i < this.left.length ? this.left.get(i) : this.right.get(i - this.left.length) + }; + + Append.prototype.forEachInner = function forEachInner (f, from, to, start) { + var leftLen = this.left.length; + if (from < leftLen && + this.left.forEachInner(f, from, Math.min(to, leftLen), start) === false) + { return false } + if (to > leftLen && + this.right.forEachInner(f, Math.max(from - leftLen, 0), Math.min(this.length, to) - leftLen, start + leftLen) === false) + { return false } + }; + + Append.prototype.forEachInvertedInner = function forEachInvertedInner (f, from, to, start) { + var leftLen = this.left.length; + if (from > leftLen && + this.right.forEachInvertedInner(f, from - leftLen, Math.max(to, leftLen) - leftLen, start + leftLen) === false) + { return false } + if (to < leftLen && + this.left.forEachInvertedInner(f, Math.min(from, leftLen), to, start) === false) + { return false } + }; + + Append.prototype.sliceInner = function sliceInner (from, to) { + if (from == 0 && to == this.length) { return this } + var leftLen = this.left.length; + if (to <= leftLen) { return this.left.slice(from, to) } + if (from >= leftLen) { return this.right.slice(from - leftLen, to - leftLen) } + return this.left.slice(from, leftLen).append(this.right.slice(0, to - leftLen)) + }; + + Append.prototype.leafAppend = function leafAppend (other) { + var inner = this.right.leafAppend(other); + if (inner) { return new Append(this.left, inner) } + }; + + Append.prototype.leafPrepend = function leafPrepend (other) { + var inner = this.left.leafPrepend(other); + if (inner) { return new Append(inner, this.right) } + }; + + Append.prototype.appendInner = function appendInner (other) { + if (this.left.depth >= Math.max(this.right.depth, other.depth) + 1) + { return new Append(this.left, new Append(this.right, other)) } + return new Append(this, other) + }; + + return Append; +}(RopeSequence)); + +var ropeSequence = RopeSequence; + +/* harmony default export */ __webpack_exports__["default"] = (ropeSequence); + + /***/ }), /***/ "./node_modules/setimmediate/setImmediate.js": @@ -2646,6 +23293,7743 @@ exports.clearImmediate = (typeof self !== "undefined" && self.clearImmediate) || /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js"))) +/***/ }), + +/***/ "./node_modules/tiptap-commands/dist/commands.esm.js": +/*!***********************************************************!*\ + !*** ./node_modules/tiptap-commands/dist/commands.esm.js ***! + \***********************************************************/ +/*! exports provided: autoJoin, baseKeymap, chainCommands, createParagraphNear, deleteSelection, exitCode, joinBackward, joinDown, joinForward, joinUp, lift, liftEmptyBlock, macBaseKeymap, newlineInCode, pcBaseKeymap, selectAll, selectNodeBackward, selectNodeForward, selectParentNode, setBlockType, splitBlock, splitBlockKeepMarks, toggleMark, wrapIn, addListNodes, liftListItem, sinkListItem, splitListItem, wrapInList, textblockTypeInputRule, wrappingInputRule, insertText, markInputRule, markPasteRule, nodeInputRule, pasteRule, removeMark, replaceText, setInlineBlockType, splitToDefaultListItem, toggleBlockType, toggleList, toggleWrap, updateMark */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "insertText", function() { return insertText; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "markInputRule", function() { return markInputRule; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "markPasteRule", function() { return markPasteRule; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "nodeInputRule", function() { return nodeInputRule; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pasteRule", function() { return pasteRule; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "removeMark", function() { return removeMark; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "replaceText", function() { return replaceText; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setInlineBlockType", function() { return setInlineBlockType; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "splitToDefaultListItem", function() { return splitToDefaultListItem; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "toggleBlockType", function() { return toggleBlockType; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "toggleList", function() { return toggleList; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "toggleWrap", function() { return toggleWrap; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "updateMark", function() { return updateMark; }); +/* harmony import */ var prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! prosemirror-commands */ "./node_modules/prosemirror-commands/dist/index.es.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "autoJoin", function() { return prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["autoJoin"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "baseKeymap", function() { return prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["baseKeymap"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "chainCommands", function() { return prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["chainCommands"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "createParagraphNear", function() { return prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["createParagraphNear"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "deleteSelection", function() { return prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["deleteSelection"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "exitCode", function() { return prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["exitCode"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "joinBackward", function() { return prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["joinBackward"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "joinDown", function() { return prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["joinDown"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "joinForward", function() { return prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["joinForward"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "joinUp", function() { return prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["joinUp"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "lift", function() { return prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["lift"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "liftEmptyBlock", function() { return prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["liftEmptyBlock"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "macBaseKeymap", function() { return prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["macBaseKeymap"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "newlineInCode", function() { return prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["newlineInCode"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "pcBaseKeymap", function() { return prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["pcBaseKeymap"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectAll", function() { return prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["selectAll"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectNodeBackward", function() { return prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["selectNodeBackward"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectNodeForward", function() { return prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["selectNodeForward"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectParentNode", function() { return prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["selectParentNode"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "setBlockType", function() { return prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["setBlockType"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "splitBlock", function() { return prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["splitBlock"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "splitBlockKeepMarks", function() { return prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["splitBlockKeepMarks"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "toggleMark", function() { return prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["toggleMark"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "wrapIn", function() { return prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["wrapIn"]; }); + +/* harmony import */ var prosemirror_schema_list__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! prosemirror-schema-list */ "./node_modules/prosemirror-schema-list/dist/index.es.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "addListNodes", function() { return prosemirror_schema_list__WEBPACK_IMPORTED_MODULE_1__["addListNodes"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "liftListItem", function() { return prosemirror_schema_list__WEBPACK_IMPORTED_MODULE_1__["liftListItem"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "sinkListItem", function() { return prosemirror_schema_list__WEBPACK_IMPORTED_MODULE_1__["sinkListItem"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "splitListItem", function() { return prosemirror_schema_list__WEBPACK_IMPORTED_MODULE_1__["splitListItem"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "wrapInList", function() { return prosemirror_schema_list__WEBPACK_IMPORTED_MODULE_1__["wrapInList"]; }); + +/* harmony import */ var prosemirror_inputrules__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! prosemirror-inputrules */ "./node_modules/prosemirror-inputrules/dist/index.es.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "textblockTypeInputRule", function() { return prosemirror_inputrules__WEBPACK_IMPORTED_MODULE_2__["textblockTypeInputRule"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "wrappingInputRule", function() { return prosemirror_inputrules__WEBPACK_IMPORTED_MODULE_2__["wrappingInputRule"]; }); + +/* harmony import */ var prosemirror_state__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! prosemirror-state */ "./node_modules/prosemirror-state/dist/index.es.js"); +/* harmony import */ var prosemirror_model__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! prosemirror-model */ "./node_modules/prosemirror-model/dist/index.es.js"); +/* harmony import */ var tiptap_utils__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! tiptap-utils */ "./node_modules/tiptap-utils/dist/utils.esm.js"); +/* harmony import */ var prosemirror_utils__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! prosemirror-utils */ "./node_modules/prosemirror-utils/dist/index.js"); +/* harmony import */ var prosemirror_utils__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(prosemirror_utils__WEBPACK_IMPORTED_MODULE_6__); + + /*! + * tiptap-commands v1.12.4 + * (c) 2019 Scrumpy UG (limited liability) + * @license MIT + */ + + + + + + + + + + + + +function insertText () { + var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; + return function (state, dispatch) { + var $from = state.selection.$from; + var pos = $from.pos.pos; + dispatch(state.tr.insertText(text, pos)); + return true; + }; +} + +function _toConsumableArray(arr) { + return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); +} + +function _arrayWithoutHoles(arr) { + if (Array.isArray(arr)) { + for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; + + return arr2; + } +} + +function _iterableToArray(iter) { + if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); +} + +function _nonIterableSpread() { + throw new TypeError("Invalid attempt to spread non-iterable instance"); +} + +function getMarksBetween(start, end, state) { + var marks = []; + state.doc.nodesBetween(start, end, function (node, pos) { + marks = [].concat(_toConsumableArray(marks), _toConsumableArray(node.marks.map(function (mark) { + return { + start: pos, + end: pos + node.nodeSize, + mark: mark + }; + }))); + }); + return marks; +} + +function markInputRule (regexp, markType, getAttrs) { + return new prosemirror_inputrules__WEBPACK_IMPORTED_MODULE_2__["InputRule"](regexp, function (state, match, start, end) { + var attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; + var tr = state.tr; + var m = match.length - 1; + var markEnd = end; + var markStart = start; + + if (match[m]) { + var matchStart = start + match[0].indexOf(match[m - 1]); + var matchEnd = matchStart + match[m - 1].length - 1; + var textStart = matchStart + match[m - 1].lastIndexOf(match[m]); + var textEnd = textStart + match[m].length; + var excludedMarks = getMarksBetween(start, end, state).filter(function (item) { + var excluded = item.mark.type.excluded; + return excluded.find(function (type) { + return type.name === markType.name; + }); + }).filter(function (item) { + return item.end > matchStart; + }); + + if (excludedMarks.length) { + return false; + } + + if (textEnd < matchEnd) { + tr.delete(textEnd, matchEnd); + } + + if (textStart > matchStart) { + tr.delete(matchStart, textStart); + } + + markStart = matchStart; + markEnd = markStart + match[m].length; + } + + tr.addMark(markStart, markEnd, markType.create(attrs)); + tr.removeStoredMark(markType); + return tr; + }); +} + +function nodeInputRule (regexp, type, getAttrs) { + return new prosemirror_inputrules__WEBPACK_IMPORTED_MODULE_2__["InputRule"](regexp, function (state, match, start, end) { + var attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; + var tr = state.tr; + + if (match[0]) { + tr.replaceWith(start - 1, end, type.create(attrs)); + } + + return tr; + }); +} + +function pasteRule (regexp, type, getAttrs) { + var handler = function handler(fragment) { + var nodes = []; + fragment.forEach(function (child) { + if (child.isText) { + var text = child.text; + var pos = 0; + var match; + + do { + match = regexp.exec(text); + + if (match) { + var start = match.index; + var end = start + match[0].length; + var attrs = getAttrs instanceof Function ? getAttrs(match[0]) : getAttrs; + + if (start > 0) { + nodes.push(child.cut(pos, start)); + } + + nodes.push(child.cut(start, end).mark(type.create(attrs).addToSet(child.marks))); + pos = end; + } + } while (match); + + if (pos < text.length) { + nodes.push(child.cut(pos)); + } + } else { + nodes.push(child.copy(handler(child.content))); + } + }); + return prosemirror_model__WEBPACK_IMPORTED_MODULE_4__["Fragment"].fromArray(nodes); + }; + + return new prosemirror_state__WEBPACK_IMPORTED_MODULE_3__["Plugin"]({ + props: { + transformPasted: function transformPasted(slice) { + return new prosemirror_model__WEBPACK_IMPORTED_MODULE_4__["Slice"](handler(slice.content), slice.openStart, slice.openEnd); + } + } + }); +} + +function markPasteRule (regexp, type, getAttrs) { + var handler = function handler(fragment) { + var nodes = []; + fragment.forEach(function (child) { + if (child.isText) { + var text = child.text, + marks = child.marks; + var pos = 0; + var match; + var isLink = !!marks.filter(function (x) { + return x.type.name === 'link'; + })[0]; // eslint-disable-next-line + + while (!isLink && (match = regexp.exec(text)) !== null) { + if (match[1]) { + var start = match.index; + var end = start + match[0].length; + var textStart = start + match[0].indexOf(match[1]); + var textEnd = textStart + match[1].length; + var attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; // adding text before markdown to nodes + + if (start > 0) { + nodes.push(child.cut(pos, start)); + } // adding the markdown part to nodes + + + nodes.push(child.cut(textStart, textEnd).mark(type.create(attrs).addToSet(child.marks))); + pos = end; + } + } // adding rest of text to nodes + + + if (pos < text.length) { + nodes.push(child.cut(pos)); + } + } else { + nodes.push(child.copy(handler(child.content))); + } + }); + return prosemirror_model__WEBPACK_IMPORTED_MODULE_4__["Fragment"].fromArray(nodes); + }; + + return new prosemirror_state__WEBPACK_IMPORTED_MODULE_3__["Plugin"]({ + props: { + transformPasted: function transformPasted(slice) { + return new prosemirror_model__WEBPACK_IMPORTED_MODULE_4__["Slice"](handler(slice.content), slice.openStart, slice.openEnd); + } + } + }); +} + +function removeMark (type) { + return function (state, dispatch) { + var tr = state.tr, + selection = state.selection; + var from = selection.from, + to = selection.to; + var $from = selection.$from, + empty = selection.empty; + + if (empty) { + var range = Object(tiptap_utils__WEBPACK_IMPORTED_MODULE_5__["getMarkRange"])($from, type); + from = range.from; + to = range.to; + } + + tr.removeMark(from, to, type); + return dispatch(tr); + }; +} + +function replaceText () { + var range = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + var type = arguments.length > 1 ? arguments[1] : undefined; + var attrs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + return function (state, dispatch) { + var _state$selection = state.selection, + $from = _state$selection.$from, + $to = _state$selection.$to; + var index = $from.index(); + var from = range ? range.from : $from.pos; + var to = range ? range.to : $to.pos; + + if (!$from.parent.canReplaceWith(index, index, type)) { + return false; + } + + if (dispatch) { + dispatch(state.tr.replaceWith(from, to, type.create(attrs))); + } + + return true; + }; +} + +function setInlineBlockType (type) { + var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + return function (state, dispatch) { + var $from = state.selection.$from; + var index = $from.index(); + + if (!$from.parent.canReplaceWith(index, index, type)) { + return false; + } + + if (dispatch) { + dispatch(state.tr.replaceSelectionWith(type.create(attrs))); + } + + return true; + }; +} + +// see https://github.com/ProseMirror/prosemirror-transform/blob/master/src/structure.js +// Since this piece of code was "borrowed" from prosemirror, ESLint rules are ignored. + +/* eslint-disable max-len, no-plusplus, no-undef, eqeqeq */ + +function canSplit(doc, pos) { + var depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; + var typesAfter = arguments.length > 3 ? arguments[3] : undefined; + var $pos = doc.resolve(pos); + var base = $pos.depth - depth; + var innerType = typesAfter && typesAfter[typesAfter.length - 1] || $pos.parent; + if (base < 0 || $pos.parent.type.spec.isolating || !$pos.parent.canReplace($pos.index(), $pos.parent.childCount) || !innerType.type.validContent($pos.parent.content.cutByIndex($pos.index(), $pos.parent.childCount))) return false; + + for (var d = $pos.depth - 1, i = depth - 2; d > base; d--, i--) { + var node = $pos.node(d); + + var _index = $pos.index(d); + + if (node.type.spec.isolating) return false; + var rest = node.content.cutByIndex(_index, node.childCount); + var after = typesAfter && typesAfter[i] || node; + if (after != node) rest = rest.replaceChild(0, after.type.create(after.attrs)); + /* Change starts from here */ + // if (!node.canReplace(index + 1, node.childCount) || !after.type.validContent(rest)) + // return false + + if (!node.canReplace(_index + 1, node.childCount)) return false; + /* Change ends here */ + } + + var index = $pos.indexAfter(base); + var baseType = typesAfter && typesAfter[0]; + return $pos.node(base).canReplaceWith(index, index, baseType ? baseType.type : $pos.node(base + 1).type); +} // this is a copy of splitListItem +// see https://github.com/ProseMirror/prosemirror-schema-list/blob/master/src/schema-list.js + + +function splitToDefaultListItem(itemType) { + return function (state, dispatch) { + var _state$selection = state.selection, + $from = _state$selection.$from, + $to = _state$selection.$to, + node = _state$selection.node; + if (node && node.isBlock || $from.depth < 2 || !$from.sameParent($to)) return false; + var grandParent = $from.node(-1); + if (grandParent.type != itemType) return false; + + if ($from.parent.content.size == 0) { + // In an empty block. If this is a nested list, the wrapping + // list item should be split. Otherwise, bail out and let next + // command handle lifting. + if ($from.depth == 2 || $from.node(-3).type != itemType || $from.index(-2) != $from.node(-2).childCount - 1) return false; + + if (dispatch) { + var wrap = prosemirror_model__WEBPACK_IMPORTED_MODULE_4__["Fragment"].empty; + var keepItem = $from.index(-1) > 0; // Build a fragment containing empty versions of the structure + // from the outer list item to the parent node of the cursor + + for (var d = $from.depth - (keepItem ? 1 : 2); d >= $from.depth - 3; d--) { + wrap = prosemirror_model__WEBPACK_IMPORTED_MODULE_4__["Fragment"].from($from.node(d).copy(wrap)); + } // Add a second list item with an empty default start node + + + wrap = wrap.append(prosemirror_model__WEBPACK_IMPORTED_MODULE_4__["Fragment"].from(itemType.createAndFill())); + + var _tr = state.tr.replace($from.before(keepItem ? null : -1), $from.after(-3), new prosemirror_model__WEBPACK_IMPORTED_MODULE_4__["Slice"](wrap, keepItem ? 3 : 2, 2)); + + _tr.setSelection(state.selection.constructor.near(_tr.doc.resolve($from.pos + (keepItem ? 3 : 2)))); + + dispatch(_tr.scrollIntoView()); + } + + return true; + } + + var nextType = $to.pos == $from.end() ? grandParent.contentMatchAt($from.indexAfter(-1)).defaultType : null; + var tr = state.tr.delete($from.pos, $to.pos); + /* Change starts from here */ + // let types = nextType && [null, {type: nextType}] + + var types = nextType && [{ + type: itemType + }, { + type: nextType + }]; + if (!types) types = [{ + type: itemType + }, null]; + /* Change ends here */ + + if (!canSplit(tr.doc, $from.pos, 2, types)) return false; + if (dispatch) dispatch(tr.split($from.pos, 2, types).scrollIntoView()); + return true; + }; +} +/* eslint-enable max-len, no-plusplus, no-undef, eqeqeq */ + +function toggleBlockType (type, toggletype) { + var attrs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + return function (state, dispatch, view) { + var isActive = Object(tiptap_utils__WEBPACK_IMPORTED_MODULE_5__["nodeIsActive"])(state, type, attrs); + + if (isActive) { + return Object(prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["setBlockType"])(toggletype)(state, dispatch, view); + } + + return Object(prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["setBlockType"])(type, attrs)(state, dispatch, view); + }; +} + +function isList(node, schema) { + return node.type === schema.nodes.bullet_list || node.type === schema.nodes.ordered_list || node.type === schema.nodes.todo_list; +} + +function toggleList(listType, itemType) { + return function (state, dispatch, view) { + var schema = state.schema, + selection = state.selection; + var $from = selection.$from, + $to = selection.$to; + var range = $from.blockRange($to); + + if (!range) { + return false; + } + + var parentList = Object(prosemirror_utils__WEBPACK_IMPORTED_MODULE_6__["findParentNode"])(function (node) { + return isList(node, schema); + })(selection); + + if (range.depth >= 1 && parentList && range.depth - parentList.depth <= 1) { + if (parentList.node.type === listType) { + return Object(prosemirror_schema_list__WEBPACK_IMPORTED_MODULE_1__["liftListItem"])(itemType)(state, dispatch, view); + } + + if (isList(parentList.node, schema) && listType.validContent(parentList.node.content)) { + var tr = state.tr; + tr.setNodeMarkup(parentList.pos, listType); + + if (dispatch) { + dispatch(tr); + } + + return false; + } + } + + return Object(prosemirror_schema_list__WEBPACK_IMPORTED_MODULE_1__["wrapInList"])(listType)(state, dispatch, view); + }; +} + +function toggleWrap (type) { + return function (state, dispatch, view) { + var isActive = Object(tiptap_utils__WEBPACK_IMPORTED_MODULE_5__["nodeIsActive"])(state, type); + + if (isActive) { + return Object(prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["lift"])(state, dispatch); + } + + return Object(prosemirror_commands__WEBPACK_IMPORTED_MODULE_0__["wrapIn"])(type)(state, dispatch, view); + }; +} + +function updateMark (type, attrs) { + return function (state, dispatch) { + var tr = state.tr, + selection = state.selection, + doc = state.doc; + var from = selection.from, + to = selection.to; + var $from = selection.$from, + empty = selection.empty; + + if (empty) { + var range = Object(tiptap_utils__WEBPACK_IMPORTED_MODULE_5__["getMarkRange"])($from, type); + from = range.from; + to = range.to; + } + + var hasMark = doc.rangeHasMark(from, to, type); + + if (hasMark) { + tr.removeMark(from, to, type); + } + + tr.addMark(from, to, type.create(attrs)); + return dispatch(tr); + }; +} + + + + +/***/ }), + +/***/ "./node_modules/tiptap-extensions/dist/extensions.esm.js": +/*!***************************************************************!*\ + !*** ./node_modules/tiptap-extensions/dist/extensions.esm.js ***! + \***************************************************************/ +/*! exports provided: Blockquote, Bold, BulletList, Code, CodeBlock, CodeBlockHighlight, Collaboration, Focus, HardBreak, Heading, Highlight, History, HorizontalRule, Image, Italic, Link, ListItem, Mention, OrderedList, Placeholder, Search, Strike, Suggestions, Table, TableCell, TableHeader, TableRow, TodoItem, TodoList, TrailingNode, Underline */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Blockquote", function() { return Blockquote; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Bold", function() { return Bold; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "BulletList", function() { return BulletList; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Code", function() { return Code; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CodeBlock", function() { return CodeBlock; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CodeBlockHighlight", function() { return CodeBlockHighlight; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Collaboration", function() { return Collaboration; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Focus", function() { return Focus; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "HardBreak", function() { return HardBreak; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Heading", function() { return Heading; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Highlight", function() { return HighlightPlugin; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "History", function() { return History; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "HorizontalRule", function() { return HorizontalRule; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Image", function() { return Image; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Italic", function() { return Italic; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Link", function() { return Link; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ListItem", function() { return ListItem; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Mention", function() { return Mention; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "OrderedList", function() { return OrderedList; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Placeholder", function() { return Placeholder; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Search", function() { return Search; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Strike", function() { return Strike; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Suggestions", function() { return SuggestionsPlugin; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Table", function() { return Table; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "TableCell", function() { return TableCell; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "TableHeader", function() { return TableHeader; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "TableRow", function() { return TableRow; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "TodoItem", function() { return TodoItem; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "TodoList", function() { return TodoList; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "TrailingNode", function() { return TrailingNode; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Underline", function() { return Underline; }); +/* harmony import */ var tiptap__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tiptap */ "./node_modules/tiptap/dist/tiptap.esm.js"); +/* harmony import */ var tiptap_commands__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! tiptap-commands */ "./node_modules/tiptap-commands/dist/commands.esm.js"); +/* harmony import */ var lowlight_lib_core__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! lowlight/lib/core */ "./node_modules/lowlight/lib/core.js"); +/* harmony import */ var lowlight_lib_core__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(lowlight_lib_core__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var prosemirror_view__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! prosemirror-view */ "./node_modules/prosemirror-view/dist/index.es.js"); +/* harmony import */ var prosemirror_utils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! prosemirror-utils */ "./node_modules/prosemirror-utils/dist/index.js"); +/* harmony import */ var prosemirror_utils__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(prosemirror_utils__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var prosemirror_state__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! prosemirror-state */ "./node_modules/prosemirror-state/dist/index.es.js"); +/* harmony import */ var prosemirror_tables__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! prosemirror-tables */ "./node_modules/prosemirror-tables/dist/index.es.js"); +/* harmony import */ var tiptap_utils__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! tiptap-utils */ "./node_modules/tiptap-utils/dist/utils.esm.js"); +/* harmony import */ var prosemirror_transform__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! prosemirror-transform */ "./node_modules/tiptap-extensions/node_modules/prosemirror-transform/dist/index.es.js"); +/* harmony import */ var prosemirror_collab__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! prosemirror-collab */ "./node_modules/prosemirror-collab/dist/index.es.js"); +/* harmony import */ var prosemirror_history__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! prosemirror-history */ "./node_modules/prosemirror-history/dist/index.es.js"); + + /*! + * tiptap-extensions v1.28.5 + * (c) 2019 Scrumpy UG (limited liability) + * @license MIT + */ + + + + + + + + + + + + + +function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } +} + +function _defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } +} + +function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + return Constructor; +} + +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; +} + +function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + if (enumerableOnly) symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + }); + keys.push.apply(keys, symbols); + } + + return keys; +} + +function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = arguments[i] != null ? arguments[i] : {}; + + if (i % 2) { + ownKeys(Object(source), true).forEach(function (key) { + _defineProperty(target, key, source[key]); + }); + } else if (Object.getOwnPropertyDescriptors) { + Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + } else { + ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + } + + return target; +} + +function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function"); + } + + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + writable: true, + configurable: true + } + }); + if (superClass) _setPrototypeOf(subClass, superClass); +} + +function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); +} + +function _setPrototypeOf(o, p) { + _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { + o.__proto__ = p; + return o; + }; + + return _setPrototypeOf(o, p); +} + +function _assertThisInitialized(self) { + if (self === void 0) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } + + return self; +} + +function _possibleConstructorReturn(self, call) { + if (call && (typeof call === "object" || typeof call === "function")) { + return call; + } + + return _assertThisInitialized(self); +} + +function _slicedToArray(arr, i) { + return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); +} + +function _toConsumableArray(arr) { + return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); +} + +function _arrayWithoutHoles(arr) { + if (Array.isArray(arr)) { + for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; + + return arr2; + } +} + +function _arrayWithHoles(arr) { + if (Array.isArray(arr)) return arr; +} + +function _iterableToArray(iter) { + if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); +} + +function _iterableToArrayLimit(arr, i) { + if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { + return; + } + + var _arr = []; + var _n = true; + var _d = false; + var _e = undefined; + + try { + for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { + _arr.push(_s.value); + + if (i && _arr.length === i) break; + } + } catch (err) { + _d = true; + _e = err; + } finally { + try { + if (!_n && _i["return"] != null) _i["return"](); + } finally { + if (_d) throw _e; + } + } + + return _arr; +} + +function _nonIterableSpread() { + throw new TypeError("Invalid attempt to spread non-iterable instance"); +} + +function _nonIterableRest() { + throw new TypeError("Invalid attempt to destructure non-iterable instance"); +} + +var Blockquote = +/*#__PURE__*/ +function (_Node) { + _inherits(Blockquote, _Node); + + function Blockquote() { + _classCallCheck(this, Blockquote); + + return _possibleConstructorReturn(this, _getPrototypeOf(Blockquote).apply(this, arguments)); + } + + _createClass(Blockquote, [{ + key: "commands", + value: function commands(_ref) { + var type = _ref.type, + schema = _ref.schema; + return function () { + return Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["toggleWrap"])(type, schema.nodes.paragraph); + }; + } + }, { + key: "keys", + value: function keys(_ref2) { + var type = _ref2.type; + return { + 'Ctrl->': Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["toggleWrap"])(type) + }; + } + }, { + key: "inputRules", + value: function inputRules(_ref3) { + var type = _ref3.type; + return [Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["wrappingInputRule"])(/^\s*>\s$/, type)]; + } + }, { + key: "name", + get: function get() { + return 'blockquote'; + } + }, { + key: "schema", + get: function get() { + return { + content: 'block*', + group: 'block', + defining: true, + draggable: false, + parseDOM: [{ + tag: 'blockquote' + }], + toDOM: function toDOM() { + return ['blockquote', 0]; + } + }; + } + }]); + + return Blockquote; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Node"]); + +var BulletList = +/*#__PURE__*/ +function (_Node) { + _inherits(BulletList, _Node); + + function BulletList() { + _classCallCheck(this, BulletList); + + return _possibleConstructorReturn(this, _getPrototypeOf(BulletList).apply(this, arguments)); + } + + _createClass(BulletList, [{ + key: "commands", + value: function commands(_ref) { + var type = _ref.type, + schema = _ref.schema; + return function () { + return Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["toggleList"])(type, schema.nodes.list_item); + }; + } + }, { + key: "keys", + value: function keys(_ref2) { + var type = _ref2.type, + schema = _ref2.schema; + return { + 'Shift-Ctrl-8': Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["toggleList"])(type, schema.nodes.list_item) + }; + } + }, { + key: "inputRules", + value: function inputRules(_ref3) { + var type = _ref3.type; + return [Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["wrappingInputRule"])(/^\s*([-+*])\s$/, type)]; + } + }, { + key: "name", + get: function get() { + return 'bullet_list'; + } + }, { + key: "schema", + get: function get() { + return { + content: 'list_item+', + group: 'block', + parseDOM: [{ + tag: 'ul' + }], + toDOM: function toDOM() { + return ['ul', 0]; + } + }; + } + }]); + + return BulletList; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Node"]); + +var CodeBlock = +/*#__PURE__*/ +function (_Node) { + _inherits(CodeBlock, _Node); + + function CodeBlock() { + _classCallCheck(this, CodeBlock); + + return _possibleConstructorReturn(this, _getPrototypeOf(CodeBlock).apply(this, arguments)); + } + + _createClass(CodeBlock, [{ + key: "commands", + value: function commands(_ref) { + var type = _ref.type, + schema = _ref.schema; + return function () { + return Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["toggleBlockType"])(type, schema.nodes.paragraph); + }; + } + }, { + key: "keys", + value: function keys(_ref2) { + var type = _ref2.type; + return { + 'Shift-Ctrl-\\': Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["setBlockType"])(type) + }; + } + }, { + key: "inputRules", + value: function inputRules(_ref3) { + var type = _ref3.type; + return [Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["textblockTypeInputRule"])(/^```$/, type)]; + } + }, { + key: "name", + get: function get() { + return 'code_block'; + } + }, { + key: "schema", + get: function get() { + return { + content: 'text*', + marks: '', + group: 'block', + code: true, + defining: true, + draggable: false, + parseDOM: [{ + tag: 'pre', + preserveWhitespace: 'full' + }], + toDOM: function toDOM() { + return ['pre', ['code', 0]]; + } + }; + } + }]); + + return CodeBlock; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Node"]); + +function getDecorations(_ref) { + var doc = _ref.doc, + name = _ref.name; + var decorations = []; + var blocks = Object(prosemirror_utils__WEBPACK_IMPORTED_MODULE_4__["findBlockNodes"])(doc).filter(function (item) { + return item.node.type.name === name; + }); + + var flatten = function flatten(list) { + return list.reduce(function (a, b) { + return a.concat(Array.isArray(b) ? flatten(b) : b); + }, []); + }; + + function parseNodes(nodes) { + var className = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; + return nodes.map(function (node) { + var classes = [].concat(_toConsumableArray(className), _toConsumableArray(node.properties ? node.properties.className : [])); + + if (node.children) { + return parseNodes(node.children, classes); + } + + return { + text: node.value, + classes: classes + }; + }); + } + + blocks.forEach(function (block) { + var startPos = block.pos + 1; + var nodes = lowlight_lib_core__WEBPACK_IMPORTED_MODULE_2___default.a.highlightAuto(block.node.textContent).value; + flatten(parseNodes(nodes)).map(function (node) { + var from = startPos; + var to = from + node.text.length; + startPos = to; + return _objectSpread2({}, node, { + from: from, + to: to + }); + }).forEach(function (node) { + var decoration = prosemirror_view__WEBPACK_IMPORTED_MODULE_3__["Decoration"].inline(node.from, node.to, { + class: node.classes.join(' ') + }); + decorations.push(decoration); + }); + }); + return prosemirror_view__WEBPACK_IMPORTED_MODULE_3__["DecorationSet"].create(doc, decorations); +} + +function HighlightPlugin(_ref2) { + var name = _ref2.name; + return new tiptap__WEBPACK_IMPORTED_MODULE_0__["Plugin"]({ + name: new tiptap__WEBPACK_IMPORTED_MODULE_0__["PluginKey"]('highlight'), + state: { + init: function init(_, _ref3) { + var doc = _ref3.doc; + return getDecorations({ + doc: doc, + name: name + }); + }, + apply: function apply(transaction, decorationSet, oldState, state) { + // TODO: find way to cache decorations + // see: https://discuss.prosemirror.net/t/how-to-update-multiple-inline-decorations-on-node-change/1493 + var nodeName = state.selection.$head.parent.type.name; + var previousNodeName = oldState.selection.$head.parent.type.name; + + if (transaction.docChanged && [nodeName, previousNodeName].includes(name)) { + return getDecorations({ + doc: transaction.doc, + name: name + }); + } + + return decorationSet.map(transaction.mapping, transaction.doc); + } + }, + props: { + decorations: function decorations(state) { + return this.getState(state); + } + } + }); +} + +var CodeBlockHighlight = +/*#__PURE__*/ +function (_Node) { + _inherits(CodeBlockHighlight, _Node); + + function CodeBlockHighlight() { + var _this; + + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _classCallCheck(this, CodeBlockHighlight); + + _this = _possibleConstructorReturn(this, _getPrototypeOf(CodeBlockHighlight).call(this, options)); + + try { + Object.entries(_this.options.languages).forEach(function (_ref) { + var _ref2 = _slicedToArray(_ref, 2), + name = _ref2[0], + mapping = _ref2[1]; + + lowlight_lib_core__WEBPACK_IMPORTED_MODULE_2___default.a.registerLanguage(name, mapping); + }); + } catch (err) { + throw new Error('Invalid syntax highlight definitions: define at least one highlight.js language mapping'); + } + + return _this; + } + + _createClass(CodeBlockHighlight, [{ + key: "commands", + value: function commands(_ref3) { + var type = _ref3.type, + schema = _ref3.schema; + return function () { + return Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["toggleBlockType"])(type, schema.nodes.paragraph); + }; + } + }, { + key: "keys", + value: function keys(_ref4) { + var type = _ref4.type; + return { + 'Shift-Ctrl-\\': Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["setBlockType"])(type) + }; + } + }, { + key: "inputRules", + value: function inputRules(_ref5) { + var type = _ref5.type; + return [Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["textblockTypeInputRule"])(/^```$/, type)]; + } + }, { + key: "name", + get: function get() { + return 'code_block'; + } + }, { + key: "defaultOptions", + get: function get() { + return { + languages: {} + }; + } + }, { + key: "schema", + get: function get() { + return { + content: 'text*', + marks: '', + group: 'block', + code: true, + defining: true, + draggable: false, + parseDOM: [{ + tag: 'pre', + preserveWhitespace: 'full' + }], + toDOM: function toDOM() { + return ['pre', ['code', 0]]; + } + }; + } + }, { + key: "plugins", + get: function get() { + return [HighlightPlugin({ + name: this.name + })]; + } + }]); + + return CodeBlockHighlight; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Node"]); + +var HardBreak = +/*#__PURE__*/ +function (_Node) { + _inherits(HardBreak, _Node); + + function HardBreak() { + _classCallCheck(this, HardBreak); + + return _possibleConstructorReturn(this, _getPrototypeOf(HardBreak).apply(this, arguments)); + } + + _createClass(HardBreak, [{ + key: "keys", + value: function keys(_ref) { + var type = _ref.type; + var command = Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["chainCommands"])(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["exitCode"], function (state, dispatch) { + dispatch(state.tr.replaceSelectionWith(type.create()).scrollIntoView()); + return true; + }); + return { + 'Mod-Enter': command, + 'Shift-Enter': command + }; + } + }, { + key: "name", + get: function get() { + return 'hard_break'; + } + }, { + key: "schema", + get: function get() { + return { + inline: true, + group: 'inline', + selectable: false, + parseDOM: [{ + tag: 'br' + }], + toDOM: function toDOM() { + return ['br']; + } + }; + } + }]); + + return HardBreak; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Node"]); + +var Heading = +/*#__PURE__*/ +function (_Node) { + _inherits(Heading, _Node); + + function Heading() { + _classCallCheck(this, Heading); + + return _possibleConstructorReturn(this, _getPrototypeOf(Heading).apply(this, arguments)); + } + + _createClass(Heading, [{ + key: "commands", + value: function commands(_ref) { + var type = _ref.type, + schema = _ref.schema; + return function (attrs) { + return Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["toggleBlockType"])(type, schema.nodes.paragraph, attrs); + }; + } + }, { + key: "keys", + value: function keys(_ref2) { + var type = _ref2.type; + return this.options.levels.reduce(function (items, level) { + return _objectSpread2({}, items, {}, _defineProperty({}, "Shift-Ctrl-".concat(level), Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["setBlockType"])(type, { + level: level + }))); + }, {}); + } + }, { + key: "inputRules", + value: function inputRules(_ref3) { + var type = _ref3.type; + return this.options.levels.map(function (level) { + return Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["textblockTypeInputRule"])(new RegExp("^(#{1,".concat(level, "})\\s$")), type, function () { + return { + level: level + }; + }); + }); + } + }, { + key: "name", + get: function get() { + return 'heading'; + } + }, { + key: "defaultOptions", + get: function get() { + return { + levels: [1, 2, 3, 4, 5, 6] + }; + } + }, { + key: "schema", + get: function get() { + return { + attrs: { + level: { + default: 1 + } + }, + content: 'inline*', + group: 'block', + defining: true, + draggable: false, + parseDOM: this.options.levels.map(function (level) { + return { + tag: "h".concat(level), + attrs: { + level: level + } + }; + }), + toDOM: function toDOM(node) { + return ["h".concat(node.attrs.level), 0]; + } + }; + } + }]); + + return Heading; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Node"]); + +var HorizontalRule = +/*#__PURE__*/ +function (_Node) { + _inherits(HorizontalRule, _Node); + + function HorizontalRule() { + _classCallCheck(this, HorizontalRule); + + return _possibleConstructorReturn(this, _getPrototypeOf(HorizontalRule).apply(this, arguments)); + } + + _createClass(HorizontalRule, [{ + key: "commands", + value: function commands(_ref) { + var type = _ref.type; + return function () { + return function (state, dispatch) { + return dispatch(state.tr.replaceSelectionWith(type.create())); + }; + }; + } + }, { + key: "inputRules", + value: function inputRules(_ref2) { + var type = _ref2.type; + return [Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["nodeInputRule"])(/^(?:---|___\s|\*\*\*\s)$/, type)]; + } + }, { + key: "name", + get: function get() { + return 'horizontal_rule'; + } + }, { + key: "schema", + get: function get() { + return { + group: 'block', + parseDOM: [{ + tag: 'hr' + }], + toDOM: function toDOM() { + return ['hr']; + } + }; + } + }]); + + return HorizontalRule; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Node"]); + +/** + * Matches following attributes in Markdown-typed image: [, alt, src, title] + * + * Example: + * ![Lorem](image.jpg) -> [, "Lorem", "image.jpg"] + * ![](image.jpg "Ipsum") -> [, "", "image.jpg", "Ipsum"] + * ![Lorem](image.jpg "Ipsum") -> [, "Lorem", "image.jpg", "Ipsum"] + */ + +var IMAGE_INPUT_REGEX = /!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\)/; + +var Image = +/*#__PURE__*/ +function (_Node) { + _inherits(Image, _Node); + + function Image() { + _classCallCheck(this, Image); + + return _possibleConstructorReturn(this, _getPrototypeOf(Image).apply(this, arguments)); + } + + _createClass(Image, [{ + key: "commands", + value: function commands(_ref) { + var type = _ref.type; + return function (attrs) { + return function (state, dispatch) { + var selection = state.selection; + var position = selection.$cursor ? selection.$cursor.pos : selection.$to.pos; + var node = type.create(attrs); + var transaction = state.tr.insert(position, node); + dispatch(transaction); + }; + }; + } + }, { + key: "inputRules", + value: function inputRules(_ref2) { + var type = _ref2.type; + return [Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["nodeInputRule"])(IMAGE_INPUT_REGEX, type, function (match) { + var _match = _slicedToArray(match, 4), + alt = _match[1], + src = _match[2], + title = _match[3]; + + return { + src: src, + alt: alt, + title: title + }; + })]; + } + }, { + key: "name", + get: function get() { + return 'image'; + } + }, { + key: "schema", + get: function get() { + return { + inline: true, + attrs: { + src: {}, + alt: { + default: null + }, + title: { + default: null + } + }, + group: 'inline', + draggable: true, + parseDOM: [{ + tag: 'img[src]', + getAttrs: function getAttrs(dom) { + return { + src: dom.getAttribute('src'), + title: dom.getAttribute('title'), + alt: dom.getAttribute('alt') + }; + } + }], + toDOM: function toDOM(node) { + return ['img', node.attrs]; + } + }; + } + }, { + key: "plugins", + get: function get() { + return [new tiptap__WEBPACK_IMPORTED_MODULE_0__["Plugin"]({ + props: { + handleDOMEvents: { + drop: function drop(view, event) { + var hasFiles = event.dataTransfer && event.dataTransfer.files && event.dataTransfer.files.length; + + if (!hasFiles) { + return; + } + + var images = Array.from(event.dataTransfer.files).filter(function (file) { + return /image/i.test(file.type); + }); + + if (images.length === 0) { + return; + } + + event.preventDefault(); + var schema = view.state.schema; + var coordinates = view.posAtCoords({ + left: event.clientX, + top: event.clientY + }); + images.forEach(function (image) { + var reader = new FileReader(); + + reader.onload = function (readerEvent) { + var node = schema.nodes.image.create({ + src: readerEvent.target.result + }); + var transaction = view.state.tr.insert(coordinates.pos, node); + view.dispatch(transaction); + }; + + reader.readAsDataURL(image); + }); + } + } + } + })]; + } + }]); + + return Image; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Node"]); + +var ListItem = +/*#__PURE__*/ +function (_Node) { + _inherits(ListItem, _Node); + + function ListItem() { + _classCallCheck(this, ListItem); + + return _possibleConstructorReturn(this, _getPrototypeOf(ListItem).apply(this, arguments)); + } + + _createClass(ListItem, [{ + key: "keys", + value: function keys(_ref) { + var type = _ref.type; + return { + Enter: Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["splitListItem"])(type), + Tab: Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["sinkListItem"])(type), + 'Shift-Tab': Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["liftListItem"])(type) + }; + } + }, { + key: "name", + get: function get() { + return 'list_item'; + } + }, { + key: "schema", + get: function get() { + return { + content: 'paragraph block*', + defining: true, + draggable: false, + parseDOM: [{ + tag: 'li' + }], + toDOM: function toDOM() { + return ['li', 0]; + } + }; + } + }]); + + return ListItem; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Node"]); + +function triggerCharacter(_ref) { + var _ref$char = _ref.char, + char = _ref$char === void 0 ? '@' : _ref$char, + _ref$allowSpaces = _ref.allowSpaces, + allowSpaces = _ref$allowSpaces === void 0 ? false : _ref$allowSpaces, + _ref$startOfLine = _ref.startOfLine, + startOfLine = _ref$startOfLine === void 0 ? false : _ref$startOfLine; + return function ($position) { + // cancel if top level node + if ($position.depth <= 0) { + return false; + } // Matching expressions used for later + + + var escapedChar = "\\".concat(char); + var suffix = new RegExp("\\s".concat(escapedChar, "$")); + var prefix = startOfLine ? '^' : ''; + var regexp = allowSpaces ? new RegExp("".concat(prefix).concat(escapedChar, ".*?(?=\\s").concat(escapedChar, "|$)"), 'gm') : new RegExp("".concat(prefix, "(?:^)?").concat(escapedChar, "[^\\s").concat(escapedChar, "]*"), 'gm'); // Lookup the boundaries of the current node + + var textFrom = $position.before(); + var textTo = $position.end(); + var text = $position.doc.textBetween(textFrom, textTo, '\0', '\0'); + var match = regexp.exec(text); + var position; + + while (match !== null) { + // JavaScript doesn't have lookbehinds; this hacks a check that first character is " " + // or the line beginning + var matchPrefix = match.input.slice(Math.max(0, match.index - 1), match.index); + + if (/^[\s\0]?$/.test(matchPrefix)) { + // The absolute position of the match in the document + var from = match.index + $position.start(); + var to = from + match[0].length; // Edge case handling; if spaces are allowed and we're directly in between + // two triggers + + if (allowSpaces && suffix.test(text.slice(to - 1, to + 1))) { + match[0] += ' '; + to += 1; + } // If the $position is located within the matched substring, return that range + + + if (from < $position.pos && to >= $position.pos) { + position = { + range: { + from: from, + to: to + }, + query: match[0].slice(char.length), + text: match[0] + }; + } + } + + match = regexp.exec(text); + } + + return position; + }; +} + +function SuggestionsPlugin(_ref2) { + var _ref2$matcher = _ref2.matcher, + matcher = _ref2$matcher === void 0 ? { + char: '@', + allowSpaces: false, + startOfLine: false + } : _ref2$matcher, + _ref2$appendText = _ref2.appendText, + appendText = _ref2$appendText === void 0 ? null : _ref2$appendText, + _ref2$suggestionClass = _ref2.suggestionClass, + suggestionClass = _ref2$suggestionClass === void 0 ? 'suggestion' : _ref2$suggestionClass, + _ref2$command = _ref2.command, + _command = _ref2$command === void 0 ? function () { + return false; + } : _ref2$command, + _ref2$items = _ref2.items, + items = _ref2$items === void 0 ? [] : _ref2$items, + _ref2$onEnter = _ref2.onEnter, + onEnter = _ref2$onEnter === void 0 ? function () { + return false; + } : _ref2$onEnter, + _ref2$onChange = _ref2.onChange, + onChange = _ref2$onChange === void 0 ? function () { + return false; + } : _ref2$onChange, + _ref2$onExit = _ref2.onExit, + onExit = _ref2$onExit === void 0 ? function () { + return false; + } : _ref2$onExit, + _ref2$onKeyDown = _ref2.onKeyDown, + onKeyDown = _ref2$onKeyDown === void 0 ? function () { + return false; + } : _ref2$onKeyDown, + _ref2$onFilter = _ref2.onFilter, + onFilter = _ref2$onFilter === void 0 ? function (searchItems, query) { + if (!query) { + return searchItems; + } + + return searchItems.filter(function (item) { + return JSON.stringify(item).toLowerCase().includes(query.toLowerCase()); + }); + } : _ref2$onFilter; + + return new prosemirror_state__WEBPACK_IMPORTED_MODULE_5__["Plugin"]({ + key: new prosemirror_state__WEBPACK_IMPORTED_MODULE_5__["PluginKey"]('suggestions'), + view: function view() { + var _this = this; + + return { + update: function update(view, prevState) { + var prev = _this.key.getState(prevState); + + var next = _this.key.getState(view.state); // See how the state changed + + + var moved = prev.active && next.active && prev.range.from !== next.range.from; + var started = !prev.active && next.active; + var stopped = prev.active && !next.active; + var changed = !started && !stopped && prev.query !== next.query; + var handleStart = started || moved; + var handleChange = changed && !moved; + var handleExit = stopped || moved; // Cancel when suggestion isn't active + + if (!handleStart && !handleChange && !handleExit) { + return; + } + + var state = handleExit ? prev : next; + var decorationNode = document.querySelector("[data-decoration-id=\"".concat(state.decorationId, "\"]")); // build a virtual node for popper.js or tippy.js + // this can be used for building popups without a DOM node + + var virtualNode = decorationNode ? { + getBoundingClientRect: function getBoundingClientRect() { + return decorationNode.getBoundingClientRect(); + }, + clientWidth: decorationNode.clientWidth, + clientHeight: decorationNode.clientHeight + } : null; + var props = { + view: view, + range: state.range, + query: state.query, + text: state.text, + decorationNode: decorationNode, + virtualNode: virtualNode, + items: onFilter(Array.isArray(items) ? items : items(), state.query), + command: function command(_ref3) { + var range = _ref3.range, + attrs = _ref3.attrs; + + _command({ + range: range, + attrs: attrs, + schema: view.state.schema + })(view.state, view.dispatch, view); + + if (appendText) { + Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["insertText"])(appendText)(view.state, view.dispatch, view); + } + } + }; // Trigger the hooks when necessary + + if (handleExit) { + onExit(props); + } + + if (handleChange) { + onChange(props); + } + + if (handleStart) { + onEnter(props); + } + } + }; + }, + state: { + // Initialize the plugin's internal state. + init: function init() { + return { + active: false, + range: {}, + query: null, + text: null + }; + }, + // Apply changes to the plugin state from a view transaction. + apply: function apply(tr, prev) { + var selection = tr.selection; + + var next = _objectSpread2({}, prev); // We can only be suggesting if there is no selection + + + if (selection.from === selection.to) { + // Reset active state if we just left the previous suggestion range + if (selection.from < prev.range.from || selection.from > prev.range.to) { + next.active = false; + } // Try to match against where our cursor currently is + + + var $position = selection.$from; + var match = triggerCharacter(matcher)($position); + var decorationId = (Math.random() + 1).toString(36).substr(2, 5); // If we found a match, update the current state to show it + + if (match) { + next.active = true; + next.decorationId = prev.decorationId ? prev.decorationId : decorationId; + next.range = match.range; + next.query = match.query; + next.text = match.text; + } else { + next.active = false; + } + } else { + next.active = false; + } // Make sure to empty the range if suggestion is inactive + + + if (!next.active) { + next.decorationId = null; + next.range = {}; + next.query = null; + next.text = null; + } + + return next; + } + }, + props: { + // Call the keydown hook if suggestion is active. + handleKeyDown: function handleKeyDown(view, event) { + var _this$getState = this.getState(view.state), + active = _this$getState.active, + range = _this$getState.range; + + if (!active) return false; + return onKeyDown({ + view: view, + event: event, + range: range + }); + }, + // Setup decorator on the currently active suggestion. + decorations: function decorations(editorState) { + var _this$getState2 = this.getState(editorState), + active = _this$getState2.active, + range = _this$getState2.range, + decorationId = _this$getState2.decorationId; + + if (!active) return null; + return prosemirror_view__WEBPACK_IMPORTED_MODULE_3__["DecorationSet"].create(editorState.doc, [prosemirror_view__WEBPACK_IMPORTED_MODULE_3__["Decoration"].inline(range.from, range.to, { + nodeName: 'span', + class: suggestionClass, + 'data-decoration-id': decorationId + })]); + } + } + }); +} + +var Mention = +/*#__PURE__*/ +function (_Node) { + _inherits(Mention, _Node); + + function Mention() { + _classCallCheck(this, Mention); + + return _possibleConstructorReturn(this, _getPrototypeOf(Mention).apply(this, arguments)); + } + + _createClass(Mention, [{ + key: "commands", + value: function commands(_ref) { + var _this = this; + + var schema = _ref.schema; + return function (attrs) { + return Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["replaceText"])(null, schema.nodes[_this.name], attrs); + }; + } + }, { + key: "name", + get: function get() { + return 'mention'; + } + }, { + key: "defaultOptions", + get: function get() { + return { + matcher: { + char: '@', + allowSpaces: false, + startOfLine: false + }, + mentionClass: 'mention', + suggestionClass: 'mention-suggestion' + }; + } + }, { + key: "schema", + get: function get() { + var _this2 = this; + + return { + attrs: { + id: {}, + label: {} + }, + group: 'inline', + inline: true, + selectable: false, + atom: true, + toDOM: function toDOM(node) { + return ['span', { + class: _this2.options.mentionClass, + 'data-mention-id': node.attrs.id + }, "".concat(_this2.options.matcher.char).concat(node.attrs.label)]; + }, + parseDOM: [{ + tag: 'span[data-mention-id]', + getAttrs: function getAttrs(dom) { + var id = dom.getAttribute('data-mention-id'); + var label = dom.innerText.split(_this2.options.matcher.char).join(''); + return { + id: id, + label: label + }; + } + }] + }; + } + }, { + key: "plugins", + get: function get() { + var _this3 = this; + + return [SuggestionsPlugin({ + command: function command(_ref2) { + var range = _ref2.range, + attrs = _ref2.attrs, + schema = _ref2.schema; + return Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["replaceText"])(range, schema.nodes[_this3.name], attrs); + }, + appendText: ' ', + matcher: this.options.matcher, + items: this.options.items, + onEnter: this.options.onEnter, + onChange: this.options.onChange, + onExit: this.options.onExit, + onKeyDown: this.options.onKeyDown, + onFilter: this.options.onFilter, + suggestionClass: this.options.suggestionClass + })]; + } + }]); + + return Mention; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Node"]); + +var OrderedList = +/*#__PURE__*/ +function (_Node) { + _inherits(OrderedList, _Node); + + function OrderedList() { + _classCallCheck(this, OrderedList); + + return _possibleConstructorReturn(this, _getPrototypeOf(OrderedList).apply(this, arguments)); + } + + _createClass(OrderedList, [{ + key: "commands", + value: function commands(_ref) { + var type = _ref.type, + schema = _ref.schema; + return function () { + return Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["toggleList"])(type, schema.nodes.list_item); + }; + } + }, { + key: "keys", + value: function keys(_ref2) { + var type = _ref2.type, + schema = _ref2.schema; + return { + 'Shift-Ctrl-9': Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["toggleList"])(type, schema.nodes.list_item) + }; + } + }, { + key: "inputRules", + value: function inputRules(_ref3) { + var type = _ref3.type; + return [Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["wrappingInputRule"])(/^(\d+)\.\s$/, type, function (match) { + return { + order: +match[1] + }; + }, function (match, node) { + return node.childCount + node.attrs.order === +match[1]; + })]; + } + }, { + key: "name", + get: function get() { + return 'ordered_list'; + } + }, { + key: "schema", + get: function get() { + return { + attrs: { + order: { + default: 1 + } + }, + content: 'list_item+', + group: 'block', + parseDOM: [{ + tag: 'ol', + getAttrs: function getAttrs(dom) { + return { + order: dom.hasAttribute('start') ? +dom.getAttribute('start') : 1 + }; + } + }], + toDOM: function toDOM(node) { + return node.attrs.order === 1 ? ['ol', 0] : ['ol', { + start: node.attrs.order + }, 0]; + } + }; + } + }]); + + return OrderedList; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Node"]); + +var TableNodes = Object(prosemirror_tables__WEBPACK_IMPORTED_MODULE_6__["tableNodes"])({ + tableGroup: 'block', + cellContent: 'block+', + cellAttributes: { + background: { + default: null, + getFromDOM: function getFromDOM(dom) { + return dom.style.backgroundColor || null; + }, + setDOMAttr: function setDOMAttr(value, attrs) { + if (value) { + var style = { + style: "".concat(attrs.style || '', "background-color: ").concat(value, ";") + }; + Object.assign(attrs, style); + } + } + } + } +}); + +var Table = +/*#__PURE__*/ +function (_Node) { + _inherits(Table, _Node); + + function Table() { + _classCallCheck(this, Table); + + return _possibleConstructorReturn(this, _getPrototypeOf(Table).apply(this, arguments)); + } + + _createClass(Table, [{ + key: "commands", + value: function commands(_ref) { + var schema = _ref.schema; + return { + createTable: function createTable$1(_ref2) { + var rowsCount = _ref2.rowsCount, + colsCount = _ref2.colsCount, + withHeaderRow = _ref2.withHeaderRow; + return function (state, dispatch) { + var offset = state.tr.selection.anchor + 1; + + var nodes = Object(prosemirror_utils__WEBPACK_IMPORTED_MODULE_4__["createTable"])(schema, rowsCount, colsCount, withHeaderRow); + + var tr = state.tr.replaceSelectionWith(nodes).scrollIntoView(); + var resolvedPos = tr.doc.resolve(offset); + tr.setSelection(prosemirror_state__WEBPACK_IMPORTED_MODULE_5__["TextSelection"].near(resolvedPos)); + dispatch(tr); + }; + }, + addColumnBefore: function addColumnBefore$1() { + return prosemirror_tables__WEBPACK_IMPORTED_MODULE_6__["addColumnBefore"]; + }, + addColumnAfter: function addColumnAfter$1() { + return prosemirror_tables__WEBPACK_IMPORTED_MODULE_6__["addColumnAfter"]; + }, + deleteColumn: function deleteColumn$1() { + return prosemirror_tables__WEBPACK_IMPORTED_MODULE_6__["deleteColumn"]; + }, + addRowBefore: function addRowBefore$1() { + return prosemirror_tables__WEBPACK_IMPORTED_MODULE_6__["addRowBefore"]; + }, + addRowAfter: function addRowAfter$1() { + return prosemirror_tables__WEBPACK_IMPORTED_MODULE_6__["addRowAfter"]; + }, + deleteRow: function deleteRow$1() { + return prosemirror_tables__WEBPACK_IMPORTED_MODULE_6__["deleteRow"]; + }, + deleteTable: function deleteTable$1() { + return prosemirror_tables__WEBPACK_IMPORTED_MODULE_6__["deleteTable"]; + }, + toggleCellMerge: function toggleCellMerge() { + return function (state, dispatch) { + if (Object(prosemirror_tables__WEBPACK_IMPORTED_MODULE_6__["mergeCells"])(state, dispatch)) { + return; + } + + Object(prosemirror_tables__WEBPACK_IMPORTED_MODULE_6__["splitCell"])(state, dispatch); + }; + }, + mergeCells: function mergeCells$1() { + return prosemirror_tables__WEBPACK_IMPORTED_MODULE_6__["mergeCells"]; + }, + splitCell: function splitCell$1() { + return prosemirror_tables__WEBPACK_IMPORTED_MODULE_6__["splitCell"]; + }, + toggleHeaderColumn: function toggleHeaderColumn$1() { + return prosemirror_tables__WEBPACK_IMPORTED_MODULE_6__["toggleHeaderColumn"]; + }, + toggleHeaderRow: function toggleHeaderRow$1() { + return prosemirror_tables__WEBPACK_IMPORTED_MODULE_6__["toggleHeaderRow"]; + }, + toggleHeaderCell: function toggleHeaderCell$1() { + return prosemirror_tables__WEBPACK_IMPORTED_MODULE_6__["toggleHeaderCell"]; + }, + setCellAttr: function setCellAttr$1() { + return prosemirror_tables__WEBPACK_IMPORTED_MODULE_6__["setCellAttr"]; + }, + fixTables: function fixTables$1() { + return prosemirror_tables__WEBPACK_IMPORTED_MODULE_6__["fixTables"]; + } + }; + } + }, { + key: "keys", + value: function keys() { + return { + Tab: Object(prosemirror_tables__WEBPACK_IMPORTED_MODULE_6__["goToNextCell"])(1), + 'Shift-Tab': Object(prosemirror_tables__WEBPACK_IMPORTED_MODULE_6__["goToNextCell"])(-1) + }; + } + }, { + key: "name", + get: function get() { + return 'table'; + } + }, { + key: "defaultOptions", + get: function get() { + return { + resizable: false + }; + } + }, { + key: "schema", + get: function get() { + return TableNodes.table; + } + }, { + key: "plugins", + get: function get() { + return [].concat(_toConsumableArray(this.options.resizable ? [Object(prosemirror_tables__WEBPACK_IMPORTED_MODULE_6__["columnResizing"])()] : []), [Object(prosemirror_tables__WEBPACK_IMPORTED_MODULE_6__["tableEditing"])()]); + } + }]); + + return Table; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Node"]); + +var TableHeader = +/*#__PURE__*/ +function (_Node) { + _inherits(TableHeader, _Node); + + function TableHeader() { + _classCallCheck(this, TableHeader); + + return _possibleConstructorReturn(this, _getPrototypeOf(TableHeader).apply(this, arguments)); + } + + _createClass(TableHeader, [{ + key: "name", + get: function get() { + return 'table_header'; + } + }, { + key: "schema", + get: function get() { + return TableNodes.table_header; + } + }]); + + return TableHeader; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Node"]); + +var TableCell = +/*#__PURE__*/ +function (_Node) { + _inherits(TableCell, _Node); + + function TableCell() { + _classCallCheck(this, TableCell); + + return _possibleConstructorReturn(this, _getPrototypeOf(TableCell).apply(this, arguments)); + } + + _createClass(TableCell, [{ + key: "name", + get: function get() { + return 'table_cell'; + } + }, { + key: "schema", + get: function get() { + return TableNodes.table_cell; + } + }]); + + return TableCell; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Node"]); + +var TableRow = +/*#__PURE__*/ +function (_Node) { + _inherits(TableRow, _Node); + + function TableRow() { + _classCallCheck(this, TableRow); + + return _possibleConstructorReturn(this, _getPrototypeOf(TableRow).apply(this, arguments)); + } + + _createClass(TableRow, [{ + key: "name", + get: function get() { + return 'table_row'; + } + }, { + key: "schema", + get: function get() { + return TableNodes.table_row; + } + }]); + + return TableRow; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Node"]); + +var TodoItem = +/*#__PURE__*/ +function (_Node) { + _inherits(TodoItem, _Node); + + function TodoItem() { + _classCallCheck(this, TodoItem); + + return _possibleConstructorReturn(this, _getPrototypeOf(TodoItem).apply(this, arguments)); + } + + _createClass(TodoItem, [{ + key: "keys", + value: function keys(_ref) { + var type = _ref.type; + return { + Enter: Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["splitToDefaultListItem"])(type), + Tab: this.options.nested ? Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["sinkListItem"])(type) : function () {}, + 'Shift-Tab': Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["liftListItem"])(type) + }; + } + }, { + key: "name", + get: function get() { + return 'todo_item'; + } + }, { + key: "defaultOptions", + get: function get() { + return { + nested: false + }; + } + }, { + key: "view", + get: function get() { + return { + props: ['node', 'updateAttrs', 'view'], + methods: { + onChange: function onChange() { + this.updateAttrs({ + done: !this.node.attrs.done + }); + } + }, + template: "\n

    • \n \n
      \n
    • \n " + }; + } + }, { + key: "schema", + get: function get() { + var _this = this; + + return { + attrs: { + done: { + default: false + } + }, + draggable: true, + content: this.options.nested ? '(paragraph|todo_list)+' : 'paragraph+', + toDOM: function toDOM(node) { + var done = node.attrs.done; + return ['li', { + 'data-type': _this.name, + 'data-done': done.toString() + }, ['span', { + class: 'todo-checkbox', + contenteditable: 'false' + }], ['div', { + class: 'todo-content' + }, 0]]; + }, + parseDOM: [{ + priority: 51, + tag: "[data-type=\"".concat(this.name, "\"]"), + getAttrs: function getAttrs(dom) { + return { + done: dom.getAttribute('data-done') === 'true' + }; + } + }] + }; + } + }]); + + return TodoItem; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Node"]); + +var TodoList = +/*#__PURE__*/ +function (_Node) { + _inherits(TodoList, _Node); + + function TodoList() { + _classCallCheck(this, TodoList); + + return _possibleConstructorReturn(this, _getPrototypeOf(TodoList).apply(this, arguments)); + } + + _createClass(TodoList, [{ + key: "commands", + value: function commands(_ref) { + var type = _ref.type, + schema = _ref.schema; + return function () { + return Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["toggleList"])(type, schema.nodes.todo_item); + }; + } + }, { + key: "inputRules", + value: function inputRules(_ref2) { + var type = _ref2.type; + return [Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["wrappingInputRule"])(/^\s*(\[ \])\s$/, type)]; + } + }, { + key: "name", + get: function get() { + return 'todo_list'; + } + }, { + key: "schema", + get: function get() { + var _this = this; + + return { + group: 'block', + content: 'todo_item+', + toDOM: function toDOM() { + return ['ul', { + 'data-type': _this.name + }, 0]; + }, + parseDOM: [{ + priority: 51, + tag: "[data-type=\"".concat(this.name, "\"]") + }] + }; + } + }]); + + return TodoList; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Node"]); + +var Bold = +/*#__PURE__*/ +function (_Mark) { + _inherits(Bold, _Mark); + + function Bold() { + _classCallCheck(this, Bold); + + return _possibleConstructorReturn(this, _getPrototypeOf(Bold).apply(this, arguments)); + } + + _createClass(Bold, [{ + key: "keys", + value: function keys(_ref) { + var type = _ref.type; + return { + 'Mod-b': Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["toggleMark"])(type) + }; + } + }, { + key: "commands", + value: function commands(_ref2) { + var type = _ref2.type; + return function () { + return Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["toggleMark"])(type); + }; + } + }, { + key: "inputRules", + value: function inputRules(_ref3) { + var type = _ref3.type; + return [Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["markInputRule"])(/(?:\*\*|__)([^*_]+)(?:\*\*|__)$/, type)]; + } + }, { + key: "pasteRules", + value: function pasteRules(_ref4) { + var type = _ref4.type; + return [Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["markPasteRule"])(/(?:\*\*|__)([^*_]+)(?:\*\*|__)/g, type)]; + } + }, { + key: "name", + get: function get() { + return 'bold'; + } + }, { + key: "schema", + get: function get() { + return { + parseDOM: [{ + tag: 'strong' + }, { + tag: 'b', + getAttrs: function getAttrs(node) { + return node.style.fontWeight !== 'normal' && null; + } + }, { + style: 'font-weight', + getAttrs: function getAttrs(value) { + return /^(bold(er)?|[5-9]\d{2,})$/.test(value) && null; + } + }], + toDOM: function toDOM() { + return ['strong', 0]; + } + }; + } + }]); + + return Bold; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Mark"]); + +var Code = +/*#__PURE__*/ +function (_Mark) { + _inherits(Code, _Mark); + + function Code() { + _classCallCheck(this, Code); + + return _possibleConstructorReturn(this, _getPrototypeOf(Code).apply(this, arguments)); + } + + _createClass(Code, [{ + key: "keys", + value: function keys(_ref) { + var type = _ref.type; + return { + 'Mod-`': Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["toggleMark"])(type) + }; + } + }, { + key: "commands", + value: function commands(_ref2) { + var type = _ref2.type; + return function () { + return Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["toggleMark"])(type); + }; + } + }, { + key: "inputRules", + value: function inputRules(_ref3) { + var type = _ref3.type; + return [Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["markInputRule"])(/(?:`)([^`]+)(?:`)$/, type)]; + } + }, { + key: "pasteRules", + value: function pasteRules(_ref4) { + var type = _ref4.type; + return [Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["markPasteRule"])(/(?:`)([^`]+)(?:`)/g, type)]; + } + }, { + key: "name", + get: function get() { + return 'code'; + } + }, { + key: "schema", + get: function get() { + return { + excludes: '_', + parseDOM: [{ + tag: 'code' + }], + toDOM: function toDOM() { + return ['code', 0]; + } + }; + } + }]); + + return Code; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Mark"]); + +var Italic = +/*#__PURE__*/ +function (_Mark) { + _inherits(Italic, _Mark); + + function Italic() { + _classCallCheck(this, Italic); + + return _possibleConstructorReturn(this, _getPrototypeOf(Italic).apply(this, arguments)); + } + + _createClass(Italic, [{ + key: "keys", + value: function keys(_ref) { + var type = _ref.type; + return { + 'Mod-i': Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["toggleMark"])(type) + }; + } + }, { + key: "commands", + value: function commands(_ref2) { + var type = _ref2.type; + return function () { + return Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["toggleMark"])(type); + }; + } + }, { + key: "inputRules", + value: function inputRules(_ref3) { + var type = _ref3.type; + return [Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["markInputRule"])(/(?:^|[^_])(_([^_]+)_)$/, type), Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["markInputRule"])(/(?:^|[^*])(\*([^*]+)\*)$/, type)]; + } + }, { + key: "pasteRules", + value: function pasteRules(_ref4) { + var type = _ref4.type; + return [Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["markPasteRule"])(/_([^_]+)_/g, type), Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["markPasteRule"])(/\*([^*]+)\*/g, type)]; + } + }, { + key: "name", + get: function get() { + return 'italic'; + } + }, { + key: "schema", + get: function get() { + return { + parseDOM: [{ + tag: 'i' + }, { + tag: 'em' + }, { + style: 'font-style=italic' + }], + toDOM: function toDOM() { + return ['em', 0]; + } + }; + } + }]); + + return Italic; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Mark"]); + +var Link = +/*#__PURE__*/ +function (_Mark) { + _inherits(Link, _Mark); + + function Link() { + _classCallCheck(this, Link); + + return _possibleConstructorReturn(this, _getPrototypeOf(Link).apply(this, arguments)); + } + + _createClass(Link, [{ + key: "commands", + value: function commands(_ref) { + var type = _ref.type; + return function (attrs) { + if (attrs.href) { + return Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["updateMark"])(type, attrs); + } + + return Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["removeMark"])(type); + }; + } + }, { + key: "pasteRules", + value: function pasteRules(_ref2) { + var type = _ref2.type; + return [Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["pasteRule"])(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-zA-Z]{2,}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/g, type, function (url) { + return { + href: url + }; + })]; + } + }, { + key: "name", + get: function get() { + return 'link'; + } + }, { + key: "defaultOptions", + get: function get() { + return { + openOnClick: true + }; + } + }, { + key: "schema", + get: function get() { + return { + attrs: { + href: { + default: null + } + }, + inclusive: false, + parseDOM: [{ + tag: 'a[href]', + getAttrs: function getAttrs(dom) { + return { + href: dom.getAttribute('href') + }; + } + }], + toDOM: function toDOM(node) { + return ['a', _objectSpread2({}, node.attrs, { + rel: 'noopener noreferrer nofollow' + }), 0]; + } + }; + } + }, { + key: "plugins", + get: function get() { + if (!this.options.openOnClick) { + return []; + } + + return [new tiptap__WEBPACK_IMPORTED_MODULE_0__["Plugin"]({ + props: { + handleClick: function handleClick(view, pos, event) { + var schema = view.state.schema; + var attrs = Object(tiptap_utils__WEBPACK_IMPORTED_MODULE_7__["getMarkAttrs"])(view.state, schema.marks.link); + + if (attrs.href && event.target instanceof HTMLAnchorElement) { + event.stopPropagation(); + window.open(attrs.href); + } + } + } + })]; + } + }]); + + return Link; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Mark"]); + +var Strike = +/*#__PURE__*/ +function (_Mark) { + _inherits(Strike, _Mark); + + function Strike() { + _classCallCheck(this, Strike); + + return _possibleConstructorReturn(this, _getPrototypeOf(Strike).apply(this, arguments)); + } + + _createClass(Strike, [{ + key: "keys", + value: function keys(_ref) { + var type = _ref.type; + return { + 'Mod-d': Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["toggleMark"])(type) + }; + } + }, { + key: "commands", + value: function commands(_ref2) { + var type = _ref2.type; + return function () { + return Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["toggleMark"])(type); + }; + } + }, { + key: "inputRules", + value: function inputRules(_ref3) { + var type = _ref3.type; + return [Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["markInputRule"])(/~([^~]+)~$/, type)]; + } + }, { + key: "pasteRules", + value: function pasteRules(_ref4) { + var type = _ref4.type; + return [Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["markPasteRule"])(/~([^~]+)~/g, type)]; + } + }, { + key: "name", + get: function get() { + return 'strike'; + } + }, { + key: "schema", + get: function get() { + return { + parseDOM: [{ + tag: 's' + }, { + tag: 'del' + }, { + tag: 'strike' + }, { + style: 'text-decoration', + getAttrs: function getAttrs(value) { + return value === 'line-through'; + } + }], + toDOM: function toDOM() { + return ['s', 0]; + } + }; + } + }]); + + return Strike; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Mark"]); + +var Underline = +/*#__PURE__*/ +function (_Mark) { + _inherits(Underline, _Mark); + + function Underline() { + _classCallCheck(this, Underline); + + return _possibleConstructorReturn(this, _getPrototypeOf(Underline).apply(this, arguments)); + } + + _createClass(Underline, [{ + key: "keys", + value: function keys(_ref) { + var type = _ref.type; + return { + 'Mod-u': Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["toggleMark"])(type) + }; + } + }, { + key: "commands", + value: function commands(_ref2) { + var type = _ref2.type; + return function () { + return Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_1__["toggleMark"])(type); + }; + } + }, { + key: "name", + get: function get() { + return 'underline'; + } + }, { + key: "schema", + get: function get() { + return { + parseDOM: [{ + tag: 'u' + }, { + style: 'text-decoration', + getAttrs: function getAttrs(value) { + return value === 'underline'; + } + }], + toDOM: function toDOM() { + return ['u', 0]; + } + }; + } + }]); + + return Underline; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Mark"]); + +var Collaboration = +/*#__PURE__*/ +function (_Extension) { + _inherits(Collaboration, _Extension); + + function Collaboration() { + _classCallCheck(this, Collaboration); + + return _possibleConstructorReturn(this, _getPrototypeOf(Collaboration).apply(this, arguments)); + } + + _createClass(Collaboration, [{ + key: "init", + value: function init() { + var _this = this; + + this.getSendableSteps = this.debounce(function (state) { + var sendable = Object(prosemirror_collab__WEBPACK_IMPORTED_MODULE_9__["sendableSteps"])(state); + + if (sendable) { + _this.options.onSendable({ + editor: _this.editor, + sendable: { + version: sendable.version, + steps: sendable.steps.map(function (step) { + return step.toJSON(); + }), + clientID: sendable.clientID + } + }); + } + }, this.options.debounce); + this.editor.on('transaction', function (_ref) { + var state = _ref.state; + + _this.getSendableSteps(state); + }); + } + }, { + key: "debounce", + value: function debounce(fn, delay) { + var timeout; + return function () { + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + if (timeout) { + clearTimeout(timeout); + } + + timeout = setTimeout(function () { + fn.apply(void 0, args); + timeout = null; + }, delay); + }; + } + }, { + key: "name", + get: function get() { + return 'collaboration'; + } + }, { + key: "defaultOptions", + get: function get() { + var _this2 = this; + + return { + version: 0, + clientID: Math.floor(Math.random() * 0xFFFFFFFF), + debounce: 250, + onSendable: function onSendable() {}, + update: function update(_ref2) { + var steps = _ref2.steps, + version = _ref2.version; + var _this2$editor = _this2.editor, + state = _this2$editor.state, + view = _this2$editor.view, + schema = _this2$editor.schema; + + if (Object(prosemirror_collab__WEBPACK_IMPORTED_MODULE_9__["getVersion"])(state) > version) { + return; + } + + view.dispatch(Object(prosemirror_collab__WEBPACK_IMPORTED_MODULE_9__["receiveTransaction"])(state, steps.map(function (item) { + return prosemirror_transform__WEBPACK_IMPORTED_MODULE_8__["Step"].fromJSON(schema, item.step); + }), steps.map(function (item) { + return item.clientID; + }))); + } + }; + } + }, { + key: "plugins", + get: function get() { + return [Object(prosemirror_collab__WEBPACK_IMPORTED_MODULE_9__["collab"])({ + version: this.options.version, + clientID: this.options.clientID + })]; + } + }]); + + return Collaboration; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Extension"]); + +var Focus = +/*#__PURE__*/ +function (_Extension) { + _inherits(Focus, _Extension); + + function Focus() { + _classCallCheck(this, Focus); + + return _possibleConstructorReturn(this, _getPrototypeOf(Focus).apply(this, arguments)); + } + + _createClass(Focus, [{ + key: "name", + get: function get() { + return 'focus'; + } + }, { + key: "defaultOptions", + get: function get() { + return { + className: 'has-focus', + nested: false + }; + } + }, { + key: "plugins", + get: function get() { + var _this = this; + + return [new tiptap__WEBPACK_IMPORTED_MODULE_0__["Plugin"]({ + props: { + decorations: function decorations(_ref) { + var doc = _ref.doc, + plugins = _ref.plugins, + selection = _ref.selection; + var editablePlugin = plugins.find(function (plugin) { + return plugin.key.startsWith('editable$'); + }); + var editable = editablePlugin.props.editable(); + var active = editable && _this.options.className; + var focused = _this.editor.focused; + var anchor = selection.anchor; + var decorations = []; + + if (!active || !focused) { + return false; + } + + doc.descendants(function (node, pos) { + var hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize; + + if (hasAnchor && !node.isText) { + var decoration = prosemirror_view__WEBPACK_IMPORTED_MODULE_3__["Decoration"].node(pos, pos + node.nodeSize, { + class: _this.options.className + }); + decorations.push(decoration); + } + + return _this.options.nested; + }); + return prosemirror_view__WEBPACK_IMPORTED_MODULE_3__["DecorationSet"].create(doc, decorations); + } + } + })]; + } + }]); + + return Focus; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Extension"]); + +var History = +/*#__PURE__*/ +function (_Extension) { + _inherits(History, _Extension); + + function History() { + _classCallCheck(this, History); + + return _possibleConstructorReturn(this, _getPrototypeOf(History).apply(this, arguments)); + } + + _createClass(History, [{ + key: "keys", + value: function keys() { + var keymap = { + 'Mod-z': prosemirror_history__WEBPACK_IMPORTED_MODULE_10__["undo"], + 'Mod-y': prosemirror_history__WEBPACK_IMPORTED_MODULE_10__["redo"], + 'Shift-Mod-z': prosemirror_history__WEBPACK_IMPORTED_MODULE_10__["redo"] + }; + return keymap; + } + }, { + key: "commands", + value: function commands() { + return { + undo: function undo$1() { + return prosemirror_history__WEBPACK_IMPORTED_MODULE_10__["undo"]; + }, + redo: function redo$1() { + return prosemirror_history__WEBPACK_IMPORTED_MODULE_10__["redo"]; + }, + undoDepth: function undoDepth$1() { + return prosemirror_history__WEBPACK_IMPORTED_MODULE_10__["undoDepth"]; + }, + redoDepth: function redoDepth$1() { + return prosemirror_history__WEBPACK_IMPORTED_MODULE_10__["redoDepth"]; + } + }; + } + }, { + key: "name", + get: function get() { + return 'history'; + } + }, { + key: "defaultOptions", + get: function get() { + return { + depth: '', + newGroupDelay: '' + }; + } + }, { + key: "plugins", + get: function get() { + return [Object(prosemirror_history__WEBPACK_IMPORTED_MODULE_10__["history"])({ + depth: this.options.depth, + newGroupDelay: this.options.newGroupDelay + })]; + } + }]); + + return History; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Extension"]); + +var Placeholder = +/*#__PURE__*/ +function (_Extension) { + _inherits(Placeholder, _Extension); + + function Placeholder() { + _classCallCheck(this, Placeholder); + + return _possibleConstructorReturn(this, _getPrototypeOf(Placeholder).apply(this, arguments)); + } + + _createClass(Placeholder, [{ + key: "name", + get: function get() { + return 'placeholder'; + } + }, { + key: "defaultOptions", + get: function get() { + return { + emptyEditorClass: 'is-editor-empty', + emptyNodeClass: 'is-empty', + emptyNodeText: 'Write something …', + showOnlyWhenEditable: true, + showOnlyCurrent: true + }; + } + }, { + key: "update", + get: function get() { + return function (view) { + view.updateState(view.state); + }; + } + }, { + key: "plugins", + get: function get() { + var _this = this; + + return [new tiptap__WEBPACK_IMPORTED_MODULE_0__["Plugin"]({ + props: { + decorations: function decorations(_ref) { + var doc = _ref.doc, + plugins = _ref.plugins, + selection = _ref.selection; + var editablePlugin = plugins.find(function (plugin) { + return plugin.key.startsWith('editable$'); + }); + var editable = editablePlugin.props.editable(); + var active = editable || !_this.options.showOnlyWhenEditable; + var anchor = selection.anchor; + var decorations = []; + var isEditorEmpty = doc.textContent.length === 0; + + if (!active) { + return false; + } + + doc.descendants(function (node, pos) { + var hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize; + var isNodeEmpty = node.content.size === 0; + + if ((hasAnchor || !_this.options.showOnlyCurrent) && isNodeEmpty) { + var classes = [_this.options.emptyNodeClass]; + + if (isEditorEmpty) { + classes.push(_this.options.emptyEditorClass); + } + + var decoration = prosemirror_view__WEBPACK_IMPORTED_MODULE_3__["Decoration"].node(pos, pos + node.nodeSize, { + class: classes.join(' '), + 'data-empty-text': typeof _this.options.emptyNodeText === 'function' ? _this.options.emptyNodeText(node) : _this.options.emptyNodeText + }); + decorations.push(decoration); + } + + return false; + }); + return prosemirror_view__WEBPACK_IMPORTED_MODULE_3__["DecorationSet"].create(doc, decorations); + } + } + })]; + } + }]); + + return Placeholder; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Extension"]); + +var Search = +/*#__PURE__*/ +function (_Extension) { + _inherits(Search, _Extension); + + function Search() { + var _this; + + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _classCallCheck(this, Search); + + _this = _possibleConstructorReturn(this, _getPrototypeOf(Search).call(this, options)); + _this.results = []; + _this.searchTerm = null; + _this._updating = false; + return _this; + } + + _createClass(Search, [{ + key: "commands", + value: function commands() { + var _this2 = this; + + return { + find: function find(attrs) { + return _this2.find(attrs); + }, + replace: function replace(attrs) { + return _this2.replace(attrs); + }, + replaceAll: function replaceAll(attrs) { + return _this2.replaceAll(attrs); + }, + clearSearch: function clearSearch() { + return _this2.clear(); + } + }; + } + }, { + key: "_search", + value: function _search(doc) { + var _this3 = this; + + this.results = []; + var mergedTextNodes = []; + var index = 0; + + if (!this.searchTerm) { + return; + } + + doc.descendants(function (node, pos) { + if (node.isText) { + if (mergedTextNodes[index]) { + mergedTextNodes[index] = { + text: mergedTextNodes[index].text + node.text, + pos: mergedTextNodes[index].pos + }; + } else { + mergedTextNodes[index] = { + text: node.text, + pos: pos + }; + } + } else { + index += 1; + } + }); + mergedTextNodes.forEach(function (_ref) { + var text = _ref.text, + pos = _ref.pos; + var search = _this3.findRegExp; + var m; // eslint-disable-next-line no-cond-assign + + while (m = search.exec(text)) { + if (m[0] === '') { + break; + } + + _this3.results.push({ + from: pos + m.index, + to: pos + m.index + m[0].length + }); + } + }); + } + }, { + key: "replace", + value: function replace(_replace) { + var _this4 = this; + + return function (state, dispatch) { + var firstResult = _this4.results[0]; + + if (!firstResult) { + return; + } + + var _this4$results$ = _this4.results[0], + from = _this4$results$.from, + to = _this4$results$.to; + dispatch(state.tr.insertText(_replace, from, to)); + + _this4.editor.commands.find(_this4.searchTerm); + }; + } + }, { + key: "rebaseNextResult", + value: function rebaseNextResult(replace, index) { + var lastOffset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + var nextIndex = index + 1; + + if (!this.results[nextIndex]) { + return null; + } + + var _this$results$index = this.results[index], + currentFrom = _this$results$index.from, + currentTo = _this$results$index.to; + var offset = currentTo - currentFrom - replace.length + lastOffset; + var _this$results$nextInd = this.results[nextIndex], + from = _this$results$nextInd.from, + to = _this$results$nextInd.to; + this.results[nextIndex] = { + to: to - offset, + from: from - offset + }; + return offset; + } + }, { + key: "replaceAll", + value: function replaceAll(replace) { + var _this5 = this; + + return function (_ref2, dispatch) { + var tr = _ref2.tr; + var offset; + + if (!_this5.results.length) { + return; + } + + _this5.results.forEach(function (_ref3, index) { + var from = _ref3.from, + to = _ref3.to; + tr.insertText(replace, from, to); + offset = _this5.rebaseNextResult(replace, index, offset); + }); + + dispatch(tr); + + _this5.editor.commands.find(_this5.searchTerm); + }; + } + }, { + key: "find", + value: function find(searchTerm) { + var _this6 = this; + + return function (state, dispatch) { + _this6.searchTerm = _this6.options.disableRegex ? searchTerm.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&') : searchTerm; + + _this6.updateView(state, dispatch); + }; + } + }, { + key: "clear", + value: function clear() { + var _this7 = this; + + return function (state, dispatch) { + _this7.searchTerm = null; + + _this7.updateView(state, dispatch); + }; + } + }, { + key: "updateView", + value: function updateView(_ref4, dispatch) { + var tr = _ref4.tr; + this._updating = true; + dispatch(tr); + this._updating = false; + } + }, { + key: "createDeco", + value: function createDeco(doc) { + this._search(doc); + + return this.decorations ? prosemirror_view__WEBPACK_IMPORTED_MODULE_3__["DecorationSet"].create(doc, this.decorations) : []; + } + }, { + key: "name", + get: function get() { + return 'search'; + } + }, { + key: "defaultOptions", + get: function get() { + return { + autoSelectNext: true, + findClass: 'find', + searching: false, + caseSensitive: false, + disableRegex: true, + alwaysSearch: false + }; + } + }, { + key: "findRegExp", + get: function get() { + return RegExp(this.searchTerm, !this.options.caseSensitive ? 'gui' : 'gu'); + } + }, { + key: "decorations", + get: function get() { + var _this8 = this; + + return this.results.map(function (deco) { + return prosemirror_view__WEBPACK_IMPORTED_MODULE_3__["Decoration"].inline(deco.from, deco.to, { + class: _this8.options.findClass + }); + }); + } + }, { + key: "plugins", + get: function get() { + var _this9 = this; + + return [new tiptap__WEBPACK_IMPORTED_MODULE_0__["Plugin"]({ + state: { + init: function init() { + return prosemirror_view__WEBPACK_IMPORTED_MODULE_3__["DecorationSet"].empty; + }, + apply: function apply(tr, old) { + if (_this9._updating || _this9.options.searching || tr.docChanged && _this9.options.alwaysSearch) { + return _this9.createDeco(tr.doc); + } + + if (tr.docChanged) { + return old.map(tr.mapping, tr.doc); + } + + return old; + } + }, + props: { + decorations: function decorations(state) { + return this.getState(state); + } + } + })]; + } + }]); + + return Search; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Extension"]); + +var TrailingNode = +/*#__PURE__*/ +function (_Extension) { + _inherits(TrailingNode, _Extension); + + function TrailingNode() { + _classCallCheck(this, TrailingNode); + + return _possibleConstructorReturn(this, _getPrototypeOf(TrailingNode).apply(this, arguments)); + } + + _createClass(TrailingNode, [{ + key: "name", + get: function get() { + return 'trailing_node'; + } + }, { + key: "defaultOptions", + get: function get() { + return { + node: 'paragraph', + notAfter: ['paragraph'] + }; + } + }, { + key: "plugins", + get: function get() { + var _this = this; + + var plugin = new tiptap__WEBPACK_IMPORTED_MODULE_0__["PluginKey"](this.name); + var disabledNodes = Object.entries(this.editor.schema.nodes).map(function (_ref) { + var _ref2 = _slicedToArray(_ref, 2), + value = _ref2[1]; + + return value; + }).filter(function (node) { + return _this.options.notAfter.includes(node.name); + }); + return [new tiptap__WEBPACK_IMPORTED_MODULE_0__["Plugin"]({ + key: plugin, + view: function view() { + return { + update: function update(view) { + var state = view.state; + var insertNodeAtEnd = plugin.getState(state); + + if (!insertNodeAtEnd) { + return; + } + + var doc = state.doc, + schema = state.schema, + tr = state.tr; + var type = schema.nodes[_this.options.node]; + var transaction = tr.insert(doc.content.size, type.create()); + view.dispatch(transaction); + } + }; + }, + state: { + init: function init(_, state) { + var lastNode = state.tr.doc.lastChild; + return !Object(tiptap_utils__WEBPACK_IMPORTED_MODULE_7__["nodeEqualsType"])({ + node: lastNode, + types: disabledNodes + }); + }, + apply: function apply(tr, value) { + if (!tr.docChanged) { + return value; + } + + var lastNode = tr.doc.lastChild; + return !Object(tiptap_utils__WEBPACK_IMPORTED_MODULE_7__["nodeEqualsType"])({ + node: lastNode, + types: disabledNodes + }); + } + } + })]; + } + }]); + + return TrailingNode; +}(tiptap__WEBPACK_IMPORTED_MODULE_0__["Extension"]); + + + + +/***/ }), + +/***/ "./node_modules/tiptap-extensions/node_modules/prosemirror-transform/dist/index.es.js": +/*!********************************************************************************************!*\ + !*** ./node_modules/tiptap-extensions/node_modules/prosemirror-transform/dist/index.es.js ***! + \********************************************************************************************/ +/*! exports provided: AddMarkStep, MapResult, Mapping, RemoveMarkStep, ReplaceAroundStep, ReplaceStep, Step, StepMap, StepResult, Transform, TransformError, canJoin, canSplit, dropPoint, findWrapping, insertPoint, joinPoint, liftTarget, replaceStep */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AddMarkStep", function() { return AddMarkStep; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MapResult", function() { return MapResult; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Mapping", function() { return Mapping; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "RemoveMarkStep", function() { return RemoveMarkStep; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ReplaceAroundStep", function() { return ReplaceAroundStep; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ReplaceStep", function() { return ReplaceStep; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Step", function() { return Step; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "StepMap", function() { return StepMap; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "StepResult", function() { return StepResult; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Transform", function() { return Transform; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "TransformError", function() { return TransformError; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "canJoin", function() { return canJoin; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "canSplit", function() { return canSplit; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "dropPoint", function() { return dropPoint; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "findWrapping", function() { return findWrapping; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "insertPoint", function() { return insertPoint; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "joinPoint", function() { return joinPoint; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "liftTarget", function() { return liftTarget; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "replaceStep", function() { return replaceStep; }); +/* harmony import */ var prosemirror_model__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! prosemirror-model */ "./node_modules/prosemirror-model/dist/index.es.js"); + + +// Mappable:: interface +// There are several things that positions can be mapped through. +// Such objects conform to this interface. +// +// map:: (pos: number, assoc: ?number) → number +// Map a position through this object. When given, `assoc` (should +// be -1 or 1, defaults to 1) determines with which side the +// position is associated, which determines in which direction to +// move when a chunk of content is inserted at the mapped position. +// +// mapResult:: (pos: number, assoc: ?number) → MapResult +// Map a position, and return an object containing additional +// information about the mapping. The result's `deleted` field tells +// you whether the position was deleted (completely enclosed in a +// replaced range) during the mapping. When content on only one side +// is deleted, the position itself is only considered deleted when +// `assoc` points in the direction of the deleted content. + +// Recovery values encode a range index and an offset. They are +// represented as numbers, because tons of them will be created when +// mapping, for example, a large number of decorations. The number's +// lower 16 bits provide the index, the remaining bits the offset. +// +// Note: We intentionally don't use bit shift operators to en- and +// decode these, since those clip to 32 bits, which we might in rare +// cases want to overflow. A 64-bit float can represent 48-bit +// integers precisely. + +var lower16 = 0xffff; +var factor16 = Math.pow(2, 16); + +function makeRecover(index, offset) { return index + offset * factor16 } +function recoverIndex(value) { return value & lower16 } +function recoverOffset(value) { return (value - (value & lower16)) / factor16 } + +// ::- An object representing a mapped position with extra +// information. +var MapResult = function MapResult(pos, deleted, recover) { + if ( deleted === void 0 ) deleted = false; + if ( recover === void 0 ) recover = null; + + // :: number The mapped version of the position. + this.pos = pos; + // :: bool Tells you whether the position was deleted, that is, + // whether the step removed its surroundings from the document. + this.deleted = deleted; + this.recover = recover; +}; + +// :: class extends Mappable +// A map describing the deletions and insertions made by a step, which +// can be used to find the correspondence between positions in the +// pre-step version of a document and the same position in the +// post-step version. +var StepMap = function StepMap(ranges, inverted) { + if ( inverted === void 0 ) inverted = false; + + this.ranges = ranges; + this.inverted = inverted; +}; + +StepMap.prototype.recover = function recover (value) { + var diff = 0, index = recoverIndex(value); + if (!this.inverted) { for (var i = 0; i < index; i++) + { diff += this.ranges[i * 3 + 2] - this.ranges[i * 3 + 1]; } } + return this.ranges[index * 3] + diff + recoverOffset(value) +}; + +// : (number, ?number) → MapResult +StepMap.prototype.mapResult = function mapResult (pos, assoc) { + if ( assoc === void 0 ) assoc = 1; + return this._map(pos, assoc, false) }; + +// : (number, ?number) → number +StepMap.prototype.map = function map (pos, assoc) { + if ( assoc === void 0 ) assoc = 1; + return this._map(pos, assoc, true) }; + +StepMap.prototype._map = function _map (pos, assoc, simple) { + var diff = 0, oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2; + for (var i = 0; i < this.ranges.length; i += 3) { + var start = this.ranges[i] - (this.inverted ? diff : 0); + if (start > pos) { break } + var oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex], end = start + oldSize; + if (pos <= end) { + var side = !oldSize ? assoc : pos == start ? -1 : pos == end ? 1 : assoc; + var result = start + diff + (side < 0 ? 0 : newSize); + if (simple) { return result } + var recover = makeRecover(i / 3, pos - start); + return new MapResult(result, assoc < 0 ? pos != start : pos != end, recover) + } + diff += newSize - oldSize; + } + return simple ? pos + diff : new MapResult(pos + diff) +}; + +StepMap.prototype.touches = function touches (pos, recover) { + var diff = 0, index = recoverIndex(recover); + var oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2; + for (var i = 0; i < this.ranges.length; i += 3) { + var start = this.ranges[i] - (this.inverted ? diff : 0); + if (start > pos) { break } + var oldSize = this.ranges[i + oldIndex], end = start + oldSize; + if (pos <= end && i == index * 3) { return true } + diff += this.ranges[i + newIndex] - oldSize; + } + return false +}; + +// :: ((oldStart: number, oldEnd: number, newStart: number, newEnd: number)) +// Calls the given function on each of the changed ranges included in +// this map. +StepMap.prototype.forEach = function forEach (f) { + var oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2; + for (var i = 0, diff = 0; i < this.ranges.length; i += 3) { + var start = this.ranges[i], oldStart = start - (this.inverted ? diff : 0), newStart = start + (this.inverted ? 0 : diff); + var oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex]; + f(oldStart, oldStart + oldSize, newStart, newStart + newSize); + diff += newSize - oldSize; + } +}; + +// :: () → StepMap +// Create an inverted version of this map. The result can be used to +// map positions in the post-step document to the pre-step document. +StepMap.prototype.invert = function invert () { + return new StepMap(this.ranges, !this.inverted) +}; + +StepMap.prototype.toString = function toString () { + return (this.inverted ? "-" : "") + JSON.stringify(this.ranges) +}; + +// :: (n: number) → StepMap +// Create a map that moves all positions by offset `n` (which may be +// negative). This can be useful when applying steps meant for a +// sub-document to a larger document, or vice-versa. +StepMap.offset = function offset (n) { + return n == 0 ? StepMap.empty : new StepMap(n < 0 ? [0, -n, 0] : [0, 0, n]) +}; + +StepMap.empty = new StepMap([]); + +// :: class extends Mappable +// A mapping represents a pipeline of zero or more [step +// maps](#transform.StepMap). It has special provisions for losslessly +// handling mapping positions through a series of steps in which some +// steps are inverted versions of earlier steps. (This comes up when +// ‘[rebasing](/docs/guide/#transform.rebasing)’ steps for +// collaboration or history management.) +var Mapping = function Mapping(maps, mirror, from, to) { + // :: [StepMap] + // The step maps in this mapping. + this.maps = maps || []; + // :: number + // The starting position in the `maps` array, used when `map` or + // `mapResult` is called. + this.from = from || 0; + // :: number + // The end position in the `maps` array. + this.to = to == null ? this.maps.length : to; + this.mirror = mirror; +}; + +// :: (?number, ?number) → Mapping +// Create a mapping that maps only through a part of this one. +Mapping.prototype.slice = function slice (from, to) { + if ( from === void 0 ) from = 0; + if ( to === void 0 ) to = this.maps.length; + + return new Mapping(this.maps, this.mirror, from, to) +}; + +Mapping.prototype.copy = function copy () { + return new Mapping(this.maps.slice(), this.mirror && this.mirror.slice(), this.from, this.to) +}; + +// :: (StepMap, ?number) +// Add a step map to the end of this mapping. If `mirrors` is +// given, it should be the index of the step map that is the mirror +// image of this one. +Mapping.prototype.appendMap = function appendMap (map, mirrors) { + this.to = this.maps.push(map); + if (mirrors != null) { this.setMirror(this.maps.length - 1, mirrors); } +}; + +// :: (Mapping) +// Add all the step maps in a given mapping to this one (preserving +// mirroring information). +Mapping.prototype.appendMapping = function appendMapping (mapping) { + for (var i = 0, startSize = this.maps.length; i < mapping.maps.length; i++) { + var mirr = mapping.getMirror(i); + this.appendMap(mapping.maps[i], mirr != null && mirr < i ? startSize + mirr : null); + } +}; + +// :: (number) → ?number +// Finds the offset of the step map that mirrors the map at the +// given offset, in this mapping (as per the second argument to +// `appendMap`). +Mapping.prototype.getMirror = function getMirror (n) { + if (this.mirror) { for (var i = 0; i < this.mirror.length; i++) + { if (this.mirror[i] == n) { return this.mirror[i + (i % 2 ? -1 : 1)] } } } +}; + +Mapping.prototype.setMirror = function setMirror (n, m) { + if (!this.mirror) { this.mirror = []; } + this.mirror.push(n, m); +}; + +// :: (Mapping) +// Append the inverse of the given mapping to this one. +Mapping.prototype.appendMappingInverted = function appendMappingInverted (mapping) { + for (var i = mapping.maps.length - 1, totalSize = this.maps.length + mapping.maps.length; i >= 0; i--) { + var mirr = mapping.getMirror(i); + this.appendMap(mapping.maps[i].invert(), mirr != null && mirr > i ? totalSize - mirr - 1 : null); + } +}; + +// :: () → Mapping +// Create an inverted version of this mapping. +Mapping.prototype.invert = function invert () { + var inverse = new Mapping; + inverse.appendMappingInverted(this); + return inverse +}; + +// : (number, ?number) → number +// Map a position through this mapping. +Mapping.prototype.map = function map (pos, assoc) { + if ( assoc === void 0 ) assoc = 1; + + if (this.mirror) { return this._map(pos, assoc, true) } + for (var i = this.from; i < this.to; i++) + { pos = this.maps[i].map(pos, assoc); } + return pos +}; + +// : (number, ?number) → MapResult +// Map a position through this mapping, returning a mapping +// result. +Mapping.prototype.mapResult = function mapResult (pos, assoc) { + if ( assoc === void 0 ) assoc = 1; + return this._map(pos, assoc, false) }; + +Mapping.prototype._map = function _map (pos, assoc, simple) { + var deleted = false, recoverables = null; + + for (var i = this.from; i < this.to; i++) { + var map = this.maps[i], rec = recoverables && recoverables[i]; + if (rec != null && map.touches(pos, rec)) { + pos = map.recover(rec); + continue + } + + var result = map.mapResult(pos, assoc); + if (result.recover != null) { + var corr = this.getMirror(i); + if (corr != null && corr > i && corr < this.to) { + if (result.deleted) { + i = corr; + pos = this.maps[corr].recover(result.recover); + continue + } else { +(recoverables || (recoverables = Object.create(null)))[corr] = result.recover; + } + } + } + + if (result.deleted) { deleted = true; } + pos = result.pos; + } + + return simple ? pos : new MapResult(pos, deleted) +}; + +function TransformError(message) { + var err = Error.call(this, message); + err.__proto__ = TransformError.prototype; + return err +} + +TransformError.prototype = Object.create(Error.prototype); +TransformError.prototype.constructor = TransformError; +TransformError.prototype.name = "TransformError"; + +// ::- Abstraction to build up and track an array of +// [steps](#transform.Step) representing a document transformation. +// +// Most transforming methods return the `Transform` object itself, so +// that they can be chained. +var Transform = function Transform(doc) { + // :: Node + // The current document (the result of applying the steps in the + // transform). + this.doc = doc; + // :: [Step] + // The steps in this transform. + this.steps = []; + // :: [Node] + // The documents before each of the steps. + this.docs = []; + // :: Mapping + // A mapping with the maps for each of the steps in this transform. + this.mapping = new Mapping; +}; + +var prototypeAccessors = { before: { configurable: true },docChanged: { configurable: true } }; + +// :: Node The starting document. +prototypeAccessors.before.get = function () { return this.docs.length ? this.docs[0] : this.doc }; + +// :: (step: Step) → this +// Apply a new step in this transform, saving the result. Throws an +// error when the step fails. +Transform.prototype.step = function step (object) { + var result = this.maybeStep(object); + if (result.failed) { throw new TransformError(result.failed) } + return this +}; + +// :: (Step) → StepResult +// Try to apply a step in this transformation, ignoring it if it +// fails. Returns the step result. +Transform.prototype.maybeStep = function maybeStep (step) { + var result = step.apply(this.doc); + if (!result.failed) { this.addStep(step, result.doc); } + return result +}; + +// :: bool +// True when the document has been changed (when there are any +// steps). +prototypeAccessors.docChanged.get = function () { + return this.steps.length > 0 +}; + +Transform.prototype.addStep = function addStep (step, doc) { + this.docs.push(this.doc); + this.steps.push(step); + this.mapping.appendMap(step.getMap()); + this.doc = doc; +}; + +Object.defineProperties( Transform.prototype, prototypeAccessors ); + +function mustOverride() { throw new Error("Override me") } + +var stepsByID = Object.create(null); + +// ::- A step object represents an atomic change. It generally applies +// only to the document it was created for, since the positions +// stored in it will only make sense for that document. +// +// New steps are defined by creating classes that extend `Step`, +// overriding the `apply`, `invert`, `map`, `getMap` and `fromJSON` +// methods, and registering your class with a unique +// JSON-serialization identifier using +// [`Step.jsonID`](#transform.Step^jsonID). +var Step = function Step () {}; + +Step.prototype.apply = function apply (_doc) { return mustOverride() }; + +// :: () → StepMap +// Get the step map that represents the changes made by this step, +// and which can be used to transform between positions in the old +// and the new document. +Step.prototype.getMap = function getMap () { return StepMap.empty }; + +// :: (doc: Node) → Step +// Create an inverted version of this step. Needs the document as it +// was before the step as argument. +Step.prototype.invert = function invert (_doc) { return mustOverride() }; + +// :: (mapping: Mappable) → ?Step +// Map this step through a mappable thing, returning either a +// version of that step with its positions adjusted, or `null` if +// the step was entirely deleted by the mapping. +Step.prototype.map = function map (_mapping) { return mustOverride() }; + +// :: (other: Step) → ?Step +// Try to merge this step with another one, to be applied directly +// after it. Returns the merged step when possible, null if the +// steps can't be merged. +Step.prototype.merge = function merge (_other) { return null }; + +// :: () → Object +// Create a JSON-serializeable representation of this step. When +// defining this for a custom subclass, make sure the result object +// includes the step type's [JSON id](#transform.Step^jsonID) under +// the `stepType` property. +Step.prototype.toJSON = function toJSON () { return mustOverride() }; + +// :: (Schema, Object) → Step +// Deserialize a step from its JSON representation. Will call +// through to the step class' own implementation of this method. +Step.fromJSON = function fromJSON (schema, json) { + if (!json || !json.stepType) { throw new RangeError("Invalid input for Step.fromJSON") } + var type = stepsByID[json.stepType]; + if (!type) { throw new RangeError(("No step type " + (json.stepType) + " defined")) } + return type.fromJSON(schema, json) +}; + +// :: (string, constructor) +// To be able to serialize steps to JSON, each step needs a string +// ID to attach to its JSON representation. Use this method to +// register an ID for your step classes. Try to pick something +// that's unlikely to clash with steps from other modules. +Step.jsonID = function jsonID (id, stepClass) { + if (id in stepsByID) { throw new RangeError("Duplicate use of step JSON ID " + id) } + stepsByID[id] = stepClass; + stepClass.prototype.jsonID = id; + return stepClass +}; + +// ::- The result of [applying](#transform.Step.apply) a step. Contains either a +// new document or a failure value. +var StepResult = function StepResult(doc, failed) { + // :: ?Node The transformed document. + this.doc = doc; + // :: ?string Text providing information about a failed step. + this.failed = failed; +}; + +// :: (Node) → StepResult +// Create a successful step result. +StepResult.ok = function ok (doc) { return new StepResult(doc, null) }; + +// :: (string) → StepResult +// Create a failed step result. +StepResult.fail = function fail (message) { return new StepResult(null, message) }; + +// :: (Node, number, number, Slice) → StepResult +// Call [`Node.replace`](#model.Node.replace) with the given +// arguments. Create a successful result if it succeeds, and a +// failed one if it throws a `ReplaceError`. +StepResult.fromReplace = function fromReplace (doc, from, to, slice) { + try { + return StepResult.ok(doc.replace(from, to, slice)) + } catch (e) { + if (e instanceof prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["ReplaceError"]) { return StepResult.fail(e.message) } + throw e + } +}; + +// ::- Replace a part of the document with a slice of new content. +var ReplaceStep = /*@__PURE__*/(function (Step) { + function ReplaceStep(from, to, slice, structure) { + Step.call(this); + this.from = from; + this.to = to; + this.slice = slice; + this.structure = !!structure; + } + + if ( Step ) ReplaceStep.__proto__ = Step; + ReplaceStep.prototype = Object.create( Step && Step.prototype ); + ReplaceStep.prototype.constructor = ReplaceStep; + + ReplaceStep.prototype.apply = function apply (doc) { + if (this.structure && contentBetween(doc, this.from, this.to)) + { return StepResult.fail("Structure replace would overwrite content") } + return StepResult.fromReplace(doc, this.from, this.to, this.slice) + }; + + ReplaceStep.prototype.getMap = function getMap () { + return new StepMap([this.from, this.to - this.from, this.slice.size]) + }; + + ReplaceStep.prototype.invert = function invert (doc) { + return new ReplaceStep(this.from, this.from + this.slice.size, doc.slice(this.from, this.to)) + }; + + ReplaceStep.prototype.map = function map (mapping) { + var from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1); + if (from.deleted && to.deleted) { return null } + return new ReplaceStep(from.pos, Math.max(from.pos, to.pos), this.slice) + }; + + ReplaceStep.prototype.merge = function merge (other) { + if (!(other instanceof ReplaceStep) || other.structure != this.structure) { return null } + + if (this.from + this.slice.size == other.from && !this.slice.openEnd && !other.slice.openStart) { + var slice = this.slice.size + other.slice.size == 0 ? prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"].empty + : new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](this.slice.content.append(other.slice.content), this.slice.openStart, other.slice.openEnd); + return new ReplaceStep(this.from, this.to + (other.to - other.from), slice, this.structure) + } else if (other.to == this.from && !this.slice.openStart && !other.slice.openEnd) { + var slice$1 = this.slice.size + other.slice.size == 0 ? prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"].empty + : new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](other.slice.content.append(this.slice.content), other.slice.openStart, this.slice.openEnd); + return new ReplaceStep(other.from, this.to, slice$1, this.structure) + } else { + return null + } + }; + + ReplaceStep.prototype.toJSON = function toJSON () { + var json = {stepType: "replace", from: this.from, to: this.to}; + if (this.slice.size) { json.slice = this.slice.toJSON(); } + if (this.structure) { json.structure = true; } + return json + }; + + ReplaceStep.fromJSON = function fromJSON (schema, json) { + if (typeof json.from != "number" || typeof json.to != "number") + { throw new RangeError("Invalid input for ReplaceStep.fromJSON") } + return new ReplaceStep(json.from, json.to, prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"].fromJSON(schema, json.slice), !!json.structure) + }; + + return ReplaceStep; +}(Step)); + +Step.jsonID("replace", ReplaceStep); + +// ::- Replace a part of the document with a slice of content, but +// preserve a range of the replaced content by moving it into the +// slice. +var ReplaceAroundStep = /*@__PURE__*/(function (Step) { + function ReplaceAroundStep(from, to, gapFrom, gapTo, slice, insert, structure) { + Step.call(this); + this.from = from; + this.to = to; + this.gapFrom = gapFrom; + this.gapTo = gapTo; + this.slice = slice; + this.insert = insert; + this.structure = !!structure; + } + + if ( Step ) ReplaceAroundStep.__proto__ = Step; + ReplaceAroundStep.prototype = Object.create( Step && Step.prototype ); + ReplaceAroundStep.prototype.constructor = ReplaceAroundStep; + + ReplaceAroundStep.prototype.apply = function apply (doc) { + if (this.structure && (contentBetween(doc, this.from, this.gapFrom) || + contentBetween(doc, this.gapTo, this.to))) + { return StepResult.fail("Structure gap-replace would overwrite content") } + + var gap = doc.slice(this.gapFrom, this.gapTo); + if (gap.openStart || gap.openEnd) + { return StepResult.fail("Gap is not a flat range") } + var inserted = this.slice.insertAt(this.insert, gap.content); + if (!inserted) { return StepResult.fail("Content does not fit in gap") } + return StepResult.fromReplace(doc, this.from, this.to, inserted) + }; + + ReplaceAroundStep.prototype.getMap = function getMap () { + return new StepMap([this.from, this.gapFrom - this.from, this.insert, + this.gapTo, this.to - this.gapTo, this.slice.size - this.insert]) + }; + + ReplaceAroundStep.prototype.invert = function invert (doc) { + var gap = this.gapTo - this.gapFrom; + return new ReplaceAroundStep(this.from, this.from + this.slice.size + gap, + this.from + this.insert, this.from + this.insert + gap, + doc.slice(this.from, this.to).removeBetween(this.gapFrom - this.from, this.gapTo - this.from), + this.gapFrom - this.from, this.structure) + }; + + ReplaceAroundStep.prototype.map = function map (mapping) { + var from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1); + var gapFrom = mapping.map(this.gapFrom, -1), gapTo = mapping.map(this.gapTo, 1); + if ((from.deleted && to.deleted) || gapFrom < from.pos || gapTo > to.pos) { return null } + return new ReplaceAroundStep(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure) + }; + + ReplaceAroundStep.prototype.toJSON = function toJSON () { + var json = {stepType: "replaceAround", from: this.from, to: this.to, + gapFrom: this.gapFrom, gapTo: this.gapTo, insert: this.insert}; + if (this.slice.size) { json.slice = this.slice.toJSON(); } + if (this.structure) { json.structure = true; } + return json + }; + + ReplaceAroundStep.fromJSON = function fromJSON (schema, json) { + if (typeof json.from != "number" || typeof json.to != "number" || + typeof json.gapFrom != "number" || typeof json.gapTo != "number" || typeof json.insert != "number") + { throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON") } + return new ReplaceAroundStep(json.from, json.to, json.gapFrom, json.gapTo, + prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"].fromJSON(schema, json.slice), json.insert, !!json.structure) + }; + + return ReplaceAroundStep; +}(Step)); + +Step.jsonID("replaceAround", ReplaceAroundStep); + +function contentBetween(doc, from, to) { + var $from = doc.resolve(from), dist = to - from, depth = $from.depth; + while (dist > 0 && depth > 0 && $from.indexAfter(depth) == $from.node(depth).childCount) { + depth--; + dist--; + } + if (dist > 0) { + var next = $from.node(depth).maybeChild($from.indexAfter(depth)); + while (dist > 0) { + if (!next || next.isLeaf) { return true } + next = next.firstChild; + dist--; + } + } + return false +} + +function canCut(node, start, end) { + return (start == 0 || node.canReplace(start, node.childCount)) && + (end == node.childCount || node.canReplace(0, end)) +} + +// :: (NodeRange) → ?number +// Try to find a target depth to which the content in the given range +// can be lifted. Will not go across +// [isolating](#model.NodeSpec.isolating) parent nodes. +function liftTarget(range) { + var parent = range.parent; + var content = parent.content.cutByIndex(range.startIndex, range.endIndex); + for (var depth = range.depth;; --depth) { + var node = range.$from.node(depth); + var index = range.$from.index(depth), endIndex = range.$to.indexAfter(depth); + if (depth < range.depth && node.canReplace(index, endIndex, content)) + { return depth } + if (depth == 0 || node.type.spec.isolating || !canCut(node, index, endIndex)) { break } + } +} + +// :: (NodeRange, number) → this +// Split the content in the given range off from its parent, if there +// is sibling content before or after it, and move it up the tree to +// the depth specified by `target`. You'll probably want to use +// [`liftTarget`](#transform.liftTarget) to compute `target`, to make +// sure the lift is valid. +Transform.prototype.lift = function(range, target) { + var $from = range.$from; + var $to = range.$to; + var depth = range.depth; + + var gapStart = $from.before(depth + 1), gapEnd = $to.after(depth + 1); + var start = gapStart, end = gapEnd; + + var before = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty, openStart = 0; + for (var d = depth, splitting = false; d > target; d--) + { if (splitting || $from.index(d) > 0) { + splitting = true; + before = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].from($from.node(d).copy(before)); + openStart++; + } else { + start--; + } } + var after = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty, openEnd = 0; + for (var d$1 = depth, splitting$1 = false; d$1 > target; d$1--) + { if (splitting$1 || $to.after(d$1 + 1) < $to.end(d$1)) { + splitting$1 = true; + after = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].from($to.node(d$1).copy(after)); + openEnd++; + } else { + end++; + } } + + return this.step(new ReplaceAroundStep(start, end, gapStart, gapEnd, + new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](before.append(after), openStart, openEnd), + before.size - openStart, true)) +}; + +// :: (NodeRange, NodeType, ?Object, ?NodeRange) → ?[{type: NodeType, attrs: ?Object}] +// Try to find a valid way to wrap the content in the given range in a +// node of the given type. May introduce extra nodes around and inside +// the wrapper node, if necessary. Returns null if no valid wrapping +// could be found. When `innerRange` is given, that range's content is +// used as the content to fit into the wrapping, instead of the +// content of `range`. +function findWrapping(range, nodeType, attrs, innerRange) { + if ( innerRange === void 0 ) innerRange = range; + + var around = findWrappingOutside(range, nodeType); + var inner = around && findWrappingInside(innerRange, nodeType); + if (!inner) { return null } + return around.map(withAttrs).concat({type: nodeType, attrs: attrs}).concat(inner.map(withAttrs)) +} + +function withAttrs(type) { return {type: type, attrs: null} } + +function findWrappingOutside(range, type) { + var parent = range.parent; + var startIndex = range.startIndex; + var endIndex = range.endIndex; + var around = parent.contentMatchAt(startIndex).findWrapping(type); + if (!around) { return null } + var outer = around.length ? around[0] : type; + return parent.canReplaceWith(startIndex, endIndex, outer) ? around : null +} + +function findWrappingInside(range, type) { + var parent = range.parent; + var startIndex = range.startIndex; + var endIndex = range.endIndex; + var inner = parent.child(startIndex); + var inside = type.contentMatch.findWrapping(inner.type); + if (!inside) { return null } + var lastType = inside.length ? inside[inside.length - 1] : type; + var innerMatch = lastType.contentMatch; + for (var i = startIndex; innerMatch && i < endIndex; i++) + { innerMatch = innerMatch.matchType(parent.child(i).type); } + if (!innerMatch || !innerMatch.validEnd) { return null } + return inside +} + +// :: (NodeRange, [{type: NodeType, attrs: ?Object}]) → this +// Wrap the given [range](#model.NodeRange) in the given set of wrappers. +// The wrappers are assumed to be valid in this position, and should +// probably be computed with [`findWrapping`](#transform.findWrapping). +Transform.prototype.wrap = function(range, wrappers) { + var content = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty; + for (var i = wrappers.length - 1; i >= 0; i--) + { content = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].from(wrappers[i].type.create(wrappers[i].attrs, content)); } + + var start = range.start, end = range.end; + return this.step(new ReplaceAroundStep(start, end, start, end, new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](content, 0, 0), wrappers.length, true)) +}; + +// :: (number, ?number, NodeType, ?Object) → this +// Set the type of all textblocks (partly) between `from` and `to` to +// the given node type with the given attributes. +Transform.prototype.setBlockType = function(from, to, type, attrs) { + var this$1 = this; + if ( to === void 0 ) to = from; + + if (!type.isTextblock) { throw new RangeError("Type given to setBlockType should be a textblock") } + var mapFrom = this.steps.length; + this.doc.nodesBetween(from, to, function (node, pos) { + if (node.isTextblock && !node.hasMarkup(type, attrs) && canChangeType(this$1.doc, this$1.mapping.slice(mapFrom).map(pos), type)) { + // Ensure all markup that isn't allowed in the new node type is cleared + this$1.clearIncompatible(this$1.mapping.slice(mapFrom).map(pos, 1), type); + var mapping = this$1.mapping.slice(mapFrom); + var startM = mapping.map(pos, 1), endM = mapping.map(pos + node.nodeSize, 1); + this$1.step(new ReplaceAroundStep(startM, endM, startM + 1, endM - 1, + new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].from(type.create(attrs, null, node.marks)), 0, 0), 1, true)); + return false + } + }); + return this +}; + +function canChangeType(doc, pos, type) { + var $pos = doc.resolve(pos), index = $pos.index(); + return $pos.parent.canReplaceWith(index, index + 1, type) +} + +// :: (number, ?NodeType, ?Object, ?[Mark]) → this +// Change the type, attributes, and/or marks of the node at `pos`. +// When `type` isn't given, the existing node type is preserved, +Transform.prototype.setNodeMarkup = function(pos, type, attrs, marks) { + var node = this.doc.nodeAt(pos); + if (!node) { throw new RangeError("No node at given position") } + if (!type) { type = node.type; } + var newNode = type.create(attrs, null, marks || node.marks); + if (node.isLeaf) + { return this.replaceWith(pos, pos + node.nodeSize, newNode) } + + if (!type.validContent(node.content)) + { throw new RangeError("Invalid content for node type " + type.name) } + + return this.step(new ReplaceAroundStep(pos, pos + node.nodeSize, pos + 1, pos + node.nodeSize - 1, + new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].from(newNode), 0, 0), 1, true)) +}; + +// :: (Node, number, number, ?[?{type: NodeType, attrs: ?Object}]) → bool +// Check whether splitting at the given position is allowed. +function canSplit(doc, pos, depth, typesAfter) { + if ( depth === void 0 ) depth = 1; + + var $pos = doc.resolve(pos), base = $pos.depth - depth; + var innerType = (typesAfter && typesAfter[typesAfter.length - 1]) || $pos.parent; + if (base < 0 || $pos.parent.type.spec.isolating || + !$pos.parent.canReplace($pos.index(), $pos.parent.childCount) || + !innerType.type.validContent($pos.parent.content.cutByIndex($pos.index(), $pos.parent.childCount))) + { return false } + for (var d = $pos.depth - 1, i = depth - 2; d > base; d--, i--) { + var node = $pos.node(d), index$1 = $pos.index(d); + if (node.type.spec.isolating) { return false } + var rest = node.content.cutByIndex(index$1, node.childCount); + var after = (typesAfter && typesAfter[i]) || node; + if (after != node) { rest = rest.replaceChild(0, after.type.create(after.attrs)); } + if (!node.canReplace(index$1 + 1, node.childCount) || !after.type.validContent(rest)) + { return false } + } + var index = $pos.indexAfter(base); + var baseType = typesAfter && typesAfter[0]; + return $pos.node(base).canReplaceWith(index, index, baseType ? baseType.type : $pos.node(base + 1).type) +} + +// :: (number, ?number, ?[?{type: NodeType, attrs: ?Object}]) → this +// Split the node at the given position, and optionally, if `depth` is +// greater than one, any number of nodes above that. By default, the +// parts split off will inherit the node type of the original node. +// This can be changed by passing an array of types and attributes to +// use after the split. +Transform.prototype.split = function(pos, depth, typesAfter) { + if ( depth === void 0 ) depth = 1; + + var $pos = this.doc.resolve(pos), before = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty, after = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty; + for (var d = $pos.depth, e = $pos.depth - depth, i = depth - 1; d > e; d--, i--) { + before = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].from($pos.node(d).copy(before)); + var typeAfter = typesAfter && typesAfter[i]; + after = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].from(typeAfter ? typeAfter.type.create(typeAfter.attrs, after) : $pos.node(d).copy(after)); + } + return this.step(new ReplaceStep(pos, pos, new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](before.append(after), depth, depth), true)) +}; + +// :: (Node, number) → bool +// Test whether the blocks before and after a given position can be +// joined. +function canJoin(doc, pos) { + var $pos = doc.resolve(pos), index = $pos.index(); + return joinable($pos.nodeBefore, $pos.nodeAfter) && + $pos.parent.canReplace(index, index + 1) +} + +function joinable(a, b) { + return a && b && !a.isLeaf && a.canAppend(b) +} + +// :: (Node, number, ?number) → ?number +// Find an ancestor of the given position that can be joined to the +// block before (or after if `dir` is positive). Returns the joinable +// point, if any. +function joinPoint(doc, pos, dir) { + if ( dir === void 0 ) dir = -1; + + var $pos = doc.resolve(pos); + for (var d = $pos.depth;; d--) { + var before = (void 0), after = (void 0); + if (d == $pos.depth) { + before = $pos.nodeBefore; + after = $pos.nodeAfter; + } else if (dir > 0) { + before = $pos.node(d + 1); + after = $pos.node(d).maybeChild($pos.index(d) + 1); + } else { + before = $pos.node(d).maybeChild($pos.index(d) - 1); + after = $pos.node(d + 1); + } + if (before && !before.isTextblock && joinable(before, after)) { return pos } + if (d == 0) { break } + pos = dir < 0 ? $pos.before(d) : $pos.after(d); + } +} + +// :: (number, ?number) → this +// Join the blocks around the given position. If depth is 2, their +// last and first siblings are also joined, and so on. +Transform.prototype.join = function(pos, depth) { + if ( depth === void 0 ) depth = 1; + + var step = new ReplaceStep(pos - depth, pos + depth, prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"].empty, true); + return this.step(step) +}; + +// :: (Node, number, NodeType) → ?number +// Try to find a point where a node of the given type can be inserted +// near `pos`, by searching up the node hierarchy when `pos` itself +// isn't a valid place but is at the start or end of a node. Return +// null if no position was found. +function insertPoint(doc, pos, nodeType) { + var $pos = doc.resolve(pos); + if ($pos.parent.canReplaceWith($pos.index(), $pos.index(), nodeType)) { return pos } + + if ($pos.parentOffset == 0) + { for (var d = $pos.depth - 1; d >= 0; d--) { + var index = $pos.index(d); + if ($pos.node(d).canReplaceWith(index, index, nodeType)) { return $pos.before(d + 1) } + if (index > 0) { return null } + } } + if ($pos.parentOffset == $pos.parent.content.size) + { for (var d$1 = $pos.depth - 1; d$1 >= 0; d$1--) { + var index$1 = $pos.indexAfter(d$1); + if ($pos.node(d$1).canReplaceWith(index$1, index$1, nodeType)) { return $pos.after(d$1 + 1) } + if (index$1 < $pos.node(d$1).childCount) { return null } + } } +} + +// :: (Node, number, Slice) → ?number +// Finds a position at or around the given position where the given +// slice can be inserted. Will look at parent nodes' nearest boundary +// and try there, even if the original position wasn't directly at the +// start or end of that node. Returns null when no position was found. +function dropPoint(doc, pos, slice) { + var $pos = doc.resolve(pos); + if (!slice.content.size) { return pos } + var content = slice.content; + for (var i = 0; i < slice.openStart; i++) { content = content.firstChild.content; } + for (var pass = 1; pass <= (slice.openStart == 0 && slice.size ? 2 : 1); pass++) { + for (var d = $pos.depth; d >= 0; d--) { + var bias = d == $pos.depth ? 0 : $pos.pos <= ($pos.start(d + 1) + $pos.end(d + 1)) / 2 ? -1 : 1; + var insertPos = $pos.index(d) + (bias > 0 ? 1 : 0); + if (pass == 1 + ? $pos.node(d).canReplace(insertPos, insertPos, content) + : $pos.node(d).contentMatchAt(insertPos).findWrapping(content.firstChild.type)) + { return bias == 0 ? $pos.pos : bias < 0 ? $pos.before(d + 1) : $pos.after(d + 1) } + } + } + return null +} + +function mapFragment(fragment, f, parent) { + var mapped = []; + for (var i = 0; i < fragment.childCount; i++) { + var child = fragment.child(i); + if (child.content.size) { child = child.copy(mapFragment(child.content, f, child)); } + if (child.isInline) { child = f(child, parent, i); } + mapped.push(child); + } + return prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].fromArray(mapped) +} + +// ::- Add a mark to all inline content between two positions. +var AddMarkStep = /*@__PURE__*/(function (Step) { + function AddMarkStep(from, to, mark) { + Step.call(this); + this.from = from; + this.to = to; + this.mark = mark; + } + + if ( Step ) AddMarkStep.__proto__ = Step; + AddMarkStep.prototype = Object.create( Step && Step.prototype ); + AddMarkStep.prototype.constructor = AddMarkStep; + + AddMarkStep.prototype.apply = function apply (doc) { + var this$1 = this; + + var oldSlice = doc.slice(this.from, this.to), $from = doc.resolve(this.from); + var parent = $from.node($from.sharedDepth(this.to)); + var slice = new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](mapFragment(oldSlice.content, function (node, parent) { + if (!parent.type.allowsMarkType(this$1.mark.type)) { return node } + return node.mark(this$1.mark.addToSet(node.marks)) + }, parent), oldSlice.openStart, oldSlice.openEnd); + return StepResult.fromReplace(doc, this.from, this.to, slice) + }; + + AddMarkStep.prototype.invert = function invert () { + return new RemoveMarkStep(this.from, this.to, this.mark) + }; + + AddMarkStep.prototype.map = function map (mapping) { + var from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1); + if (from.deleted && to.deleted || from.pos >= to.pos) { return null } + return new AddMarkStep(from.pos, to.pos, this.mark) + }; + + AddMarkStep.prototype.merge = function merge (other) { + if (other instanceof AddMarkStep && + other.mark.eq(this.mark) && + this.from <= other.to && this.to >= other.from) + { return new AddMarkStep(Math.min(this.from, other.from), + Math.max(this.to, other.to), this.mark) } + }; + + AddMarkStep.prototype.toJSON = function toJSON () { + return {stepType: "addMark", mark: this.mark.toJSON(), + from: this.from, to: this.to} + }; + + AddMarkStep.fromJSON = function fromJSON (schema, json) { + if (typeof json.from != "number" || typeof json.to != "number") + { throw new RangeError("Invalid input for AddMarkStep.fromJSON") } + return new AddMarkStep(json.from, json.to, schema.markFromJSON(json.mark)) + }; + + return AddMarkStep; +}(Step)); + +Step.jsonID("addMark", AddMarkStep); + +// ::- Remove a mark from all inline content between two positions. +var RemoveMarkStep = /*@__PURE__*/(function (Step) { + function RemoveMarkStep(from, to, mark) { + Step.call(this); + this.from = from; + this.to = to; + this.mark = mark; + } + + if ( Step ) RemoveMarkStep.__proto__ = Step; + RemoveMarkStep.prototype = Object.create( Step && Step.prototype ); + RemoveMarkStep.prototype.constructor = RemoveMarkStep; + + RemoveMarkStep.prototype.apply = function apply (doc) { + var this$1 = this; + + var oldSlice = doc.slice(this.from, this.to); + var slice = new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](mapFragment(oldSlice.content, function (node) { + return node.mark(this$1.mark.removeFromSet(node.marks)) + }), oldSlice.openStart, oldSlice.openEnd); + return StepResult.fromReplace(doc, this.from, this.to, slice) + }; + + RemoveMarkStep.prototype.invert = function invert () { + return new AddMarkStep(this.from, this.to, this.mark) + }; + + RemoveMarkStep.prototype.map = function map (mapping) { + var from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1); + if (from.deleted && to.deleted || from.pos >= to.pos) { return null } + return new RemoveMarkStep(from.pos, to.pos, this.mark) + }; + + RemoveMarkStep.prototype.merge = function merge (other) { + if (other instanceof RemoveMarkStep && + other.mark.eq(this.mark) && + this.from <= other.to && this.to >= other.from) + { return new RemoveMarkStep(Math.min(this.from, other.from), + Math.max(this.to, other.to), this.mark) } + }; + + RemoveMarkStep.prototype.toJSON = function toJSON () { + return {stepType: "removeMark", mark: this.mark.toJSON(), + from: this.from, to: this.to} + }; + + RemoveMarkStep.fromJSON = function fromJSON (schema, json) { + if (typeof json.from != "number" || typeof json.to != "number") + { throw new RangeError("Invalid input for RemoveMarkStep.fromJSON") } + return new RemoveMarkStep(json.from, json.to, schema.markFromJSON(json.mark)) + }; + + return RemoveMarkStep; +}(Step)); + +Step.jsonID("removeMark", RemoveMarkStep); + +// :: (number, number, Mark) → this +// Add the given mark to the inline content between `from` and `to`. +Transform.prototype.addMark = function(from, to, mark) { + var this$1 = this; + + var removed = [], added = [], removing = null, adding = null; + this.doc.nodesBetween(from, to, function (node, pos, parent) { + if (!node.isInline) { return } + var marks = node.marks; + if (!mark.isInSet(marks) && parent.type.allowsMarkType(mark.type)) { + var start = Math.max(pos, from), end = Math.min(pos + node.nodeSize, to); + var newSet = mark.addToSet(marks); + + for (var i = 0; i < marks.length; i++) { + if (!marks[i].isInSet(newSet)) { + if (removing && removing.to == start && removing.mark.eq(marks[i])) + { removing.to = end; } + else + { removed.push(removing = new RemoveMarkStep(start, end, marks[i])); } + } + } + + if (adding && adding.to == start) + { adding.to = end; } + else + { added.push(adding = new AddMarkStep(start, end, mark)); } + } + }); + + removed.forEach(function (s) { return this$1.step(s); }); + added.forEach(function (s) { return this$1.step(s); }); + return this +}; + +// :: (number, number, ?union) → this +// Remove marks from inline nodes between `from` and `to`. When `mark` +// is a single mark, remove precisely that mark. When it is a mark type, +// remove all marks of that type. When it is null, remove all marks of +// any type. +Transform.prototype.removeMark = function(from, to, mark) { + var this$1 = this; + if ( mark === void 0 ) mark = null; + + var matched = [], step = 0; + this.doc.nodesBetween(from, to, function (node, pos) { + if (!node.isInline) { return } + step++; + var toRemove = null; + if (mark instanceof prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["MarkType"]) { + var found = mark.isInSet(node.marks); + if (found) { toRemove = [found]; } + } else if (mark) { + if (mark.isInSet(node.marks)) { toRemove = [mark]; } + } else { + toRemove = node.marks; + } + if (toRemove && toRemove.length) { + var end = Math.min(pos + node.nodeSize, to); + for (var i = 0; i < toRemove.length; i++) { + var style = toRemove[i], found$1 = (void 0); + for (var j = 0; j < matched.length; j++) { + var m = matched[j]; + if (m.step == step - 1 && style.eq(matched[j].style)) { found$1 = m; } + } + if (found$1) { + found$1.to = end; + found$1.step = step; + } else { + matched.push({style: style, from: Math.max(pos, from), to: end, step: step}); + } + } + } + }); + matched.forEach(function (m) { return this$1.step(new RemoveMarkStep(m.from, m.to, m.style)); }); + return this +}; + +// :: (number, NodeType, ?ContentMatch) → this +// Removes all marks and nodes from the content of the node at `pos` +// that don't match the given new parent node type. Accepts an +// optional starting [content match](#model.ContentMatch) as third +// argument. +Transform.prototype.clearIncompatible = function(pos, parentType, match) { + if ( match === void 0 ) match = parentType.contentMatch; + + var node = this.doc.nodeAt(pos); + var delSteps = [], cur = pos + 1; + for (var i = 0; i < node.childCount; i++) { + var child = node.child(i), end = cur + child.nodeSize; + var allowed = match.matchType(child.type, child.attrs); + if (!allowed) { + delSteps.push(new ReplaceStep(cur, end, prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"].empty)); + } else { + match = allowed; + for (var j = 0; j < child.marks.length; j++) { if (!parentType.allowsMarkType(child.marks[j].type)) + { this.step(new RemoveMarkStep(cur, end, child.marks[j])); } } + } + cur = end; + } + if (!match.validEnd) { + var fill = match.fillBefore(prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty, true); + this.replace(cur, cur, new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](fill, 0, 0)); + } + for (var i$1 = delSteps.length - 1; i$1 >= 0; i$1--) { this.step(delSteps[i$1]); } + return this +}; + +// :: (Node, number, ?number, ?Slice) → ?Step +// ‘Fit’ a slice into a given position in the document, producing a +// [step](#transform.Step) that inserts it. Will return null if +// there's no meaningful way to insert the slice here, or inserting it +// would be a no-op (an empty slice over an empty range). +function replaceStep(doc, from, to, slice) { + if ( to === void 0 ) to = from; + if ( slice === void 0 ) slice = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"].empty; + + if (from == to && !slice.size) { return null } + + var $from = doc.resolve(from), $to = doc.resolve(to); + // Optimization -- avoid work if it's obvious that it's not needed. + if (fitsTrivially($from, $to, slice)) { return new ReplaceStep(from, to, slice) } + var placed = placeSlice($from, slice); + + var fittedLeft = fitLeft($from, placed); + var fitted = fitRight($from, $to, fittedLeft); + if (!fitted) { return null } + if (fittedLeft.size != fitted.size && canMoveText($from, $to, fittedLeft)) { + var d = $to.depth, after = $to.after(d); + while (d > 1 && after == $to.end(--d)) { ++after; } + var fittedAfter = fitRight($from, doc.resolve(after), fittedLeft); + if (fittedAfter) + { return new ReplaceAroundStep(from, after, to, $to.end(), fittedAfter, fittedLeft.size) } + } + return fitted.size || from != to ? new ReplaceStep(from, to, fitted) : null +} + +// :: (number, ?number, ?Slice) → this +// Replace the part of the document between `from` and `to` with the +// given `slice`. +Transform.prototype.replace = function(from, to, slice) { + if ( to === void 0 ) to = from; + if ( slice === void 0 ) slice = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"].empty; + + var step = replaceStep(this.doc, from, to, slice); + if (step) { this.step(step); } + return this +}; + +// :: (number, number, union) → this +// Replace the given range with the given content, which may be a +// fragment, node, or array of nodes. +Transform.prototype.replaceWith = function(from, to, content) { + return this.replace(from, to, new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].from(content), 0, 0)) +}; + +// :: (number, number) → this +// Delete the content between the given positions. +Transform.prototype.delete = function(from, to) { + return this.replace(from, to, prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"].empty) +}; + +// :: (number, union) → this +// Insert the given content at the given position. +Transform.prototype.insert = function(pos, content) { + return this.replaceWith(pos, pos, content) +}; + + + +function fitLeftInner($from, depth, placed, placedBelow) { + var content = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty, openEnd = 0, placedHere = placed[depth]; + if ($from.depth > depth) { + var inner = fitLeftInner($from, depth + 1, placed, placedBelow || placedHere); + openEnd = inner.openEnd + 1; + content = prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].from($from.node(depth + 1).copy(inner.content)); + } + + if (placedHere) { + content = content.append(placedHere.content); + openEnd = placedHere.openEnd; + } + if (placedBelow) { + content = content.append($from.node(depth).contentMatchAt($from.indexAfter(depth)).fillBefore(prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty, true)); + openEnd = 0; + } + + return {content: content, openEnd: openEnd} +} + +function fitLeft($from, placed) { + var ref = fitLeftInner($from, 0, placed, false); + var content = ref.content; + var openEnd = ref.openEnd; + return new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](content, $from.depth, openEnd || 0) +} + +function fitRightJoin(content, parent, $from, $to, depth, openStart, openEnd) { + var match, count = content.childCount, matchCount = count - (openEnd > 0 ? 1 : 0); + var parentNode = openStart < 0 ? parent : $from.node(depth); + if (openStart < 0) + { match = parentNode.contentMatchAt(matchCount); } + else if (count == 1 && openEnd > 0) + { match = parentNode.contentMatchAt(openStart ? $from.index(depth) : $from.indexAfter(depth)); } + else + { match = parentNode.contentMatchAt($from.indexAfter(depth)) + .matchFragment(content, count > 0 && openStart ? 1 : 0, matchCount); } + + var toNode = $to.node(depth); + if (openEnd > 0 && depth < $to.depth) { + var after = toNode.content.cutByIndex($to.indexAfter(depth)).addToStart(content.lastChild); + var joinable$1 = match.fillBefore(after, true); + // Can't insert content if there's a single node stretched across this gap + if (joinable$1 && joinable$1.size && openStart > 0 && count == 1) { joinable$1 = null; } + + if (joinable$1) { + var inner = fitRightJoin(content.lastChild.content, content.lastChild, $from, $to, + depth + 1, count == 1 ? openStart - 1 : -1, openEnd - 1); + if (inner) { + var last = content.lastChild.copy(inner); + if (joinable$1.size) + { return content.cutByIndex(0, count - 1).append(joinable$1).addToEnd(last) } + else + { return content.replaceChild(count - 1, last) } + } + } + } + if (openEnd > 0) + { match = match.matchType((count == 1 && openStart > 0 ? $from.node(depth + 1) : content.lastChild).type); } + + // If we're here, the next level can't be joined, so we see what + // happens if we leave it open. + var toIndex = $to.index(depth); + if (toIndex == toNode.childCount && !toNode.type.compatibleContent(parent.type)) { return null } + var joinable = match.fillBefore(toNode.content, true, toIndex); + for (var i = toIndex; joinable && i < toNode.content.childCount; i++) + { if (!parentNode.type.allowsMarks(toNode.content.child(i).marks)) { joinable = null; } } + if (!joinable) { return null } + + if (openEnd > 0) { + var closed = fitRightClosed(content.lastChild, openEnd - 1, $from, depth + 1, + count == 1 ? openStart - 1 : -1); + content = content.replaceChild(count - 1, closed); + } + content = content.append(joinable); + if ($to.depth > depth) + { content = content.addToEnd(fitRightSeparate($to, depth + 1)); } + return content +} + +function fitRightClosed(node, openEnd, $from, depth, openStart) { + var match, content = node.content, count = content.childCount; + if (openStart >= 0) + { match = $from.node(depth).contentMatchAt($from.indexAfter(depth)) + .matchFragment(content, openStart > 0 ? 1 : 0, count); } + else + { match = node.contentMatchAt(count); } + + if (openEnd > 0) { + var closed = fitRightClosed(content.lastChild, openEnd - 1, $from, depth + 1, + count == 1 ? openStart - 1 : -1); + content = content.replaceChild(count - 1, closed); + } + + return node.copy(content.append(match.fillBefore(prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty, true))) +} + +function fitRightSeparate($to, depth) { + var node = $to.node(depth); + var fill = node.contentMatchAt(0).fillBefore(node.content, true, $to.index(depth)); + if ($to.depth > depth) { fill = fill.addToEnd(fitRightSeparate($to, depth + 1)); } + return node.copy(fill) +} + +function normalizeSlice(content, openStart, openEnd) { + while (openStart > 0 && openEnd > 0 && content.childCount == 1) { + content = content.firstChild.content; + openStart--; + openEnd--; + } + return new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](content, openStart, openEnd) +} + +// : (ResolvedPos, ResolvedPos, number, Slice) → Slice +function fitRight($from, $to, slice) { + var fitted = fitRightJoin(slice.content, $from.node(0), $from, $to, 0, slice.openStart, slice.openEnd); + if (!fitted) { return null } + return normalizeSlice(fitted, slice.openStart, $to.depth) +} + +function fitsTrivially($from, $to, slice) { + return !slice.openStart && !slice.openEnd && $from.start() == $to.start() && + $from.parent.canReplace($from.index(), $to.index(), slice.content) +} + +function canMoveText($from, $to, slice) { + if (!$to.parent.isTextblock) { return false } + + var parent = slice.openEnd ? nodeRight(slice.content, slice.openEnd) + : $from.node($from.depth - (slice.openStart - slice.openEnd)); + if (!parent.isTextblock) { return false } + for (var i = $to.index(); i < $to.parent.childCount; i++) + { if (!parent.type.allowsMarks($to.parent.child(i).marks)) { return false } } + var match; + if (slice.openEnd) { + match = parent.contentMatchAt(parent.childCount); + } else { + match = parent.contentMatchAt(parent.childCount); + if (slice.size) { match = match.matchFragment(slice.content, slice.openStart ? 1 : 0); } + } + match = match.matchFragment($to.parent.content, $to.index()); + return match && match.validEnd +} + +function nodeRight(content, depth) { + for (var i = 1; i < depth; i++) { content = content.lastChild.content; } + return content.lastChild +} + +// Algorithm for 'placing' the elements of a slice into a gap: +// +// We consider the content of each node that is open to the left to be +// independently placeable. I.e. in , when the +// paragraph on the left is open, "foo" can be placed (somewhere on +// the left side of the replacement gap) independently from p("bar"). +// +// So placeSlice splits up a slice into a number of sub-slices, +// along with information on where they can be placed on the given +// left-side edge. It works by walking the open side of the slice, +// from the inside out, and trying to find a landing spot for each +// element, by simultaneously scanning over the gap side. When no +// place is found for an open node's content, it is left in that node. + +// : (ResolvedPos, Slice) → [{content: Fragment, openEnd: number, depth: number}] +function placeSlice($from, slice) { + var frontier = new Frontier($from); + for (var pass = 1; slice.size && pass <= 3; pass++) { + var value = frontier.placeSlice(slice.content, slice.openStart, slice.openEnd, pass); + if (pass == 3 && value != slice && value.size) { pass = 0; } // Restart if the 3rd pass made progress but left content + slice = value; + } + while (frontier.open.length) { frontier.closeNode(); } + return frontier.placed +} + +// Helper class that models the open side of the insert position, +// keeping track of the content match and already inserted content +// at each depth. +var Frontier = function Frontier($pos) { + // : [{parent: Node, match: ContentMatch, content: Fragment, wrapper: bool, openEnd: number, depth: number}] + this.open = []; + for (var d = 0; d <= $pos.depth; d++) { + var parent = $pos.node(d), match = parent.contentMatchAt($pos.indexAfter(d)); + this.open.push({parent: parent, match: match, content: prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty, wrapper: false, openEnd: 0, depth: d}); + } + this.placed = []; +}; + +// : (Fragment, number, number, number, ?Node) → Slice +// Tries to place the content of the given slice, and returns a +// slice containing unplaced content. +// +// pass 1: try to fit directly +// pass 2: allow wrapper nodes to be introduced +// pass 3: allow unwrapping of nodes that aren't open +Frontier.prototype.placeSlice = function placeSlice (fragment, openStart, openEnd, pass, parent) { + if (openStart > 0) { + var first = fragment.firstChild; + var inner = this.placeSlice(first.content, Math.max(0, openStart - 1), + openEnd && fragment.childCount == 1 ? openEnd - 1 : 0, + pass, first); + if (inner.content != first.content) { + if (inner.content.size) { + fragment = fragment.replaceChild(0, first.copy(inner.content)); + openStart = inner.openStart + 1; + } else { + if (fragment.childCount == 1) { openEnd = 0; } + fragment = fragment.cutByIndex(1); + openStart = 0; + } + } + } + var result = this.placeContent(fragment, openStart, openEnd, pass, parent); + if (pass > 2 && result.size && openStart == 0) { + var child = result.content.firstChild, single = result.content.childCount == 1; + this.placeContent(child.content, 0, openEnd && single ? openEnd - 1 : 0, pass, child); + result = single ? prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty : new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](result.content.cutByIndex(1), 0, openEnd); + } + return result +}; + +Frontier.prototype.placeContent = function placeContent (fragment, openStart, openEnd, pass, parent) { + var i = 0; + // Go over the fragment's children + for (; i < fragment.childCount; i++) { + var child = fragment.child(i), placed = false, last = i == fragment.childCount - 1; + // Try each open node in turn, starting from the innermost + for (var d = this.open.length - 1; d >= 0; d--) { + var open = this.open[d], wrap = (void 0); + + // If pass > 1, it is allowed to wrap the node to help find a + // fit, so if findWrapping returns something, we add open + // nodes to the frontier for that wrapping. + if (pass > 1 && (wrap = open.match.findWrapping(child.type)) && + !(parent && wrap.length && wrap[wrap.length - 1] == parent.type)) { + while (this.open.length - 1 > d) { this.closeNode(); } + for (var w = 0; w < wrap.length; w++) { + open.match = open.match.matchType(wrap[w]); + d++; + open = {parent: wrap[w].create(), + match: wrap[w].contentMatch, + content: prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty, wrapper: true, openEnd: 0, depth: d + w}; + this.open.push(open); + } + } + + // See if the child fits here + var match = open.match.matchType(child.type); + if (!match) { + var fill = open.match.fillBefore(prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].from(child)); + if (fill) { + for (var j = 0; j < fill.childCount; j++) { + var ch = fill.child(j); + this.addNode(open, ch, 0); + match = open.match.matchFragment(ch); + } + } else if (parent && open.match.matchType(parent.type)) { + // Don't continue looking further up if the parent node + // would fit here. + break + } else { + continue + } + } + + // Close open nodes above this one, since we're starting to + // add to this. + while (this.open.length - 1 > d) { this.closeNode(); } + // Strip marks from the child or close its start when necessary + child = child.mark(open.parent.type.allowedMarks(child.marks)); + if (openStart) { + child = closeNodeStart(child, openStart, last ? openEnd : 0); + openStart = 0; + } + // Add the child to this open node and adjust its metadata + this.addNode(open, child, last ? openEnd : 0); + open.match = match; + if (last) { openEnd = 0; } + placed = true; + break + } + // As soon as we've failed to place a node we stop looking at + // later nodes + if (!placed) { break } + } + // Close the current open node if it's not the the root and we + // either placed up to the end of the node or the the current + // slice depth's node type matches the open node's type + if (this.open.length > 1 && + (i > 0 && i == fragment.childCount || + parent && this.open[this.open.length - 1].parent.type == parent.type)) + { this.closeNode(); } + + return new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](fragment.cutByIndex(i), openStart, openEnd) +}; + +Frontier.prototype.addNode = function addNode (open, node, openEnd) { + open.content = closeFragmentEnd(open.content, open.openEnd).addToEnd(node); + open.openEnd = openEnd; +}; + +Frontier.prototype.closeNode = function closeNode () { + var open = this.open.pop(); + if (open.content.size == 0) ; else if (open.wrapper) { + this.addNode(this.open[this.open.length - 1], open.parent.copy(open.content), open.openEnd + 1); + } else { + this.placed[open.depth] = {depth: open.depth, content: open.content, openEnd: open.openEnd}; + } +}; + +function closeNodeStart(node, openStart, openEnd) { + var content = node.content; + if (openStart > 1) { + var first = closeNodeStart(node.firstChild, openStart - 1, node.childCount == 1 ? openEnd - 1 : 0); + content = node.content.replaceChild(0, first); + } + var fill = node.type.contentMatch.fillBefore(content, openEnd == 0); + return node.copy(fill.append(content)) +} + +function closeNodeEnd(node, depth) { + var content = node.content; + if (depth > 1) { + var last = closeNodeEnd(node.lastChild, depth - 1); + content = node.content.replaceChild(node.childCount - 1, last); + } + var fill = node.contentMatchAt(node.childCount).fillBefore(prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty, true); + return node.copy(content.append(fill)) +} + +function closeFragmentEnd(fragment, depth) { + return depth ? fragment.replaceChild(fragment.childCount - 1, closeNodeEnd(fragment.lastChild, depth)) : fragment +} + +// :: (number, number, Slice) → this +// Replace a range of the document with a given slice, using `from`, +// `to`, and the slice's [`openStart`](#model.Slice.openStart) property +// as hints, rather than fixed start and end points. This method may +// grow the replaced area or close open nodes in the slice in order to +// get a fit that is more in line with WYSIWYG expectations, by +// dropping fully covered parent nodes of the replaced region when +// they are marked [non-defining](#model.NodeSpec.defining), or +// including an open parent node from the slice that _is_ marked as +// [defining](#model.NodeSpec.defining). +// +// This is the method, for example, to handle paste. The similar +// [`replace`](#transform.Transform.replace) method is a more +// primitive tool which will _not_ move the start and end of its given +// range, and is useful in situations where you need more precise +// control over what happens. +Transform.prototype.replaceRange = function(from, to, slice) { + if (!slice.size) { return this.deleteRange(from, to) } + + var $from = this.doc.resolve(from), $to = this.doc.resolve(to); + if (fitsTrivially($from, $to, slice)) + { return this.step(new ReplaceStep(from, to, slice)) } + + var targetDepths = coveredDepths($from, this.doc.resolve(to)); + // Can't replace the whole document, so remove 0 if it's present + if (targetDepths[targetDepths.length - 1] == 0) { targetDepths.pop(); } + // Negative numbers represent not expansion over the whole node at + // that depth, but replacing from $from.before(-D) to $to.pos. + var preferredTarget = -($from.depth + 1); + targetDepths.unshift(preferredTarget); + // This loop picks a preferred target depth, if one of the covering + // depths is not outside of a defining node, and adds negative + // depths for any depth that has $from at its start and does not + // cross a defining node. + for (var d = $from.depth, pos = $from.pos - 1; d > 0; d--, pos--) { + var spec = $from.node(d).type.spec; + if (spec.defining || spec.isolating) { break } + if (targetDepths.indexOf(d) > -1) { preferredTarget = d; } + else if ($from.before(d) == pos) { targetDepths.splice(1, 0, -d); } + } + // Try to fit each possible depth of the slice into each possible + // target depth, starting with the preferred depths. + var preferredTargetIndex = targetDepths.indexOf(preferredTarget); + + var leftNodes = [], preferredDepth = slice.openStart; + for (var content = slice.content, i = 0;; i++) { + var node = content.firstChild; + leftNodes.push(node); + if (i == slice.openStart) { break } + content = node.content; + } + // Back up if the node directly above openStart, or the node above + // that separated only by a non-defining textblock node, is defining. + if (preferredDepth > 0 && leftNodes[preferredDepth - 1].type.spec.defining && + $from.node(preferredTargetIndex).type != leftNodes[preferredDepth - 1].type) + { preferredDepth -= 1; } + else if (preferredDepth >= 2 && leftNodes[preferredDepth - 1].isTextblock && leftNodes[preferredDepth - 2].type.spec.defining && + $from.node(preferredTargetIndex).type != leftNodes[preferredDepth - 2].type) + { preferredDepth -= 2; } + + for (var j = slice.openStart; j >= 0; j--) { + var openDepth = (j + preferredDepth + 1) % (slice.openStart + 1); + var insert = leftNodes[openDepth]; + if (!insert) { continue } + for (var i$1 = 0; i$1 < targetDepths.length; i$1++) { + // Loop over possible expansion levels, starting with the + // preferred one + var targetDepth = targetDepths[(i$1 + preferredTargetIndex) % targetDepths.length], expand = true; + if (targetDepth < 0) { expand = false; targetDepth = -targetDepth; } + var parent = $from.node(targetDepth - 1), index = $from.index(targetDepth - 1); + if (parent.canReplaceWith(index, index, insert.type, insert.marks)) + { return this.replace($from.before(targetDepth), expand ? $to.after(targetDepth) : to, + new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](closeFragment(slice.content, 0, slice.openStart, openDepth), + openDepth, slice.openEnd)) } + } + } + + var startSteps = this.steps.length; + for (var i$2 = targetDepths.length - 1; i$2 >= 0; i$2--) { + this.replace(from, to, slice); + if (this.steps.length > startSteps) { break } + var depth = targetDepths[i$2]; + if (i$2 < 0) { continue } + from = $from.before(depth); to = $to.after(depth); + } + return this +}; + +function closeFragment(fragment, depth, oldOpen, newOpen, parent) { + if (depth < oldOpen) { + var first = fragment.firstChild; + fragment = fragment.replaceChild(0, first.copy(closeFragment(first.content, depth + 1, oldOpen, newOpen, first))); + } + if (depth > newOpen) { + var match = parent.contentMatchAt(0); + var start = match.fillBefore(fragment).append(fragment); + fragment = start.append(match.matchFragment(start).fillBefore(prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].empty, true)); + } + return fragment +} + +// :: (number, number, Node) → this +// Replace the given range with a node, but use `from` and `to` as +// hints, rather than precise positions. When from and to are the same +// and are at the start or end of a parent node in which the given +// node doesn't fit, this method may _move_ them out towards a parent +// that does allow the given node to be placed. When the given range +// completely covers a parent node, this method may completely replace +// that parent node. +Transform.prototype.replaceRangeWith = function(from, to, node) { + if (!node.isInline && from == to && this.doc.resolve(from).parent.content.size) { + var point = insertPoint(this.doc, from, node.type); + if (point != null) { from = to = point; } + } + return this.replaceRange(from, to, new prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Slice"](prosemirror_model__WEBPACK_IMPORTED_MODULE_0__["Fragment"].from(node), 0, 0)) +}; + +// :: (number, number) → this +// Delete the given range, expanding it to cover fully covered +// parent nodes until a valid replace is found. +Transform.prototype.deleteRange = function(from, to) { + var $from = this.doc.resolve(from), $to = this.doc.resolve(to); + var covered = coveredDepths($from, $to); + for (var i = 0; i < covered.length; i++) { + var depth = covered[i], last = i == covered.length - 1; + if ((last && depth == 0) || $from.node(depth).type.contentMatch.validEnd) + { return this.delete($from.start(depth), $to.end(depth)) } + if (depth > 0 && (last || $from.node(depth - 1).canReplace($from.index(depth - 1), $to.indexAfter(depth - 1)))) + { return this.delete($from.before(depth), $to.after(depth)) } + } + for (var d = 1; d <= $from.depth; d++) { + if (from - $from.start(d) == $from.depth - d && to > $from.end(d) && $to.end(d) - to != $to.depth - d) + { return this.delete($from.before(d), to) } + } + return this.delete(from, to) +}; + +// : (ResolvedPos, ResolvedPos) → [number] +// Returns an array of all depths for which $from - $to spans the +// whole content of the nodes at that depth. +function coveredDepths($from, $to) { + var result = [], minDepth = Math.min($from.depth, $to.depth); + for (var d = minDepth; d >= 0; d--) { + var start = $from.start(d); + if (start < $from.pos - ($from.depth - d) || + $to.end(d) > $to.pos + ($to.depth - d) || + $from.node(d).type.spec.isolating || + $to.node(d).type.spec.isolating) { break } + if (start == $to.start(d)) { result.push(d); } + } + return result +} + + +//# sourceMappingURL=index.es.js.map + + +/***/ }), + +/***/ "./node_modules/tiptap-utils/dist/utils.esm.js": +/*!*****************************************************!*\ + !*** ./node_modules/tiptap-utils/dist/utils.esm.js ***! + \*****************************************************/ +/*! exports provided: getMarkAttrs, getMarkRange, markIsActive, nodeEqualsType, nodeIsActive */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getMarkAttrs", function() { return getMarkAttrs; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getMarkRange", function() { return getMarkRange; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "markIsActive", function() { return markIsActive; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "nodeEqualsType", function() { return nodeEqualsType; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "nodeIsActive", function() { return nodeIsActive; }); +/* harmony import */ var prosemirror_utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! prosemirror-utils */ "./node_modules/prosemirror-utils/dist/index.js"); +/* harmony import */ var prosemirror_utils__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(prosemirror_utils__WEBPACK_IMPORTED_MODULE_0__); + + /*! + * tiptap-utils v1.8.2 + * (c) 2019 Scrumpy UG (limited liability) + * @license MIT + */ + + + +function _toConsumableArray(arr) { + return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); +} + +function _arrayWithoutHoles(arr) { + if (Array.isArray(arr)) { + for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; + + return arr2; + } +} + +function _iterableToArray(iter) { + if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); +} + +function _nonIterableSpread() { + throw new TypeError("Invalid attempt to spread non-iterable instance"); +} + +function getMarkAttrs(state, type) { + var _state$selection = state.selection, + from = _state$selection.from, + to = _state$selection.to; + var marks = []; + state.doc.nodesBetween(from, to, function (node) { + marks = [].concat(_toConsumableArray(marks), _toConsumableArray(node.marks)); + }); + var mark = marks.find(function (markItem) { + return markItem.type.name === type.name; + }); + + if (mark) { + return mark.attrs; + } + + return {}; +} + +function getMarkRange() { + var $pos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + + if (!$pos || !type) { + return false; + } + + var start = $pos.parent.childAfter($pos.parentOffset); + + if (!start.node) { + return false; + } + + var link = start.node.marks.find(function (mark) { + return mark.type === type; + }); + + if (!link) { + return false; + } + + var startIndex = $pos.index(); + var startPos = $pos.start() + start.offset; + var endIndex = startIndex + 1; + var endPos = startPos + start.node.nodeSize; + + while (startIndex > 0 && link.isInSet($pos.parent.child(startIndex - 1).marks)) { + startIndex -= 1; + startPos -= $pos.parent.child(startIndex).nodeSize; + } + + while (endIndex < $pos.parent.childCount && link.isInSet($pos.parent.child(endIndex).marks)) { + endPos += $pos.parent.child(endIndex).nodeSize; + endIndex += 1; + } + + return { + from: startPos, + to: endPos + }; +} + +function markIsActive(state, type) { + var _state$selection = state.selection, + from = _state$selection.from, + $from = _state$selection.$from, + to = _state$selection.to, + empty = _state$selection.empty; + + if (empty) { + return !!type.isInSet(state.storedMarks || $from.marks()); + } + + return !!state.doc.rangeHasMark(from, to, type); +} + +function nodeEqualsType(_ref) { + var types = _ref.types, + node = _ref.node; + return Array.isArray(types) && types.includes(node.type) || node.type === types; +} + +function nodeIsActive(state, type) { + var attrs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + + var predicate = function predicate(node) { + return node.type === type; + }; + + var node = Object(prosemirror_utils__WEBPACK_IMPORTED_MODULE_0__["findSelectedNodeOfType"])(type)(state.selection) || Object(prosemirror_utils__WEBPACK_IMPORTED_MODULE_0__["findParentNode"])(predicate)(state.selection); + + if (!Object.keys(attrs).length || !node) { + return !!node; + } + + return node.node.hasMarkup(type, attrs); +} + + + + +/***/ }), + +/***/ "./node_modules/tiptap/dist/tiptap.esm.js": +/*!************************************************!*\ + !*** ./node_modules/tiptap/dist/tiptap.esm.js ***! + \************************************************/ +/*! exports provided: NodeSelection, Plugin, PluginKey, TextSelection, Doc, Editor, EditorContent, EditorFloatingMenu, EditorMenuBar, EditorMenuBubble, Extension, Mark, Node, Paragraph, Text */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Doc", function() { return Doc; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Editor", function() { return Editor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EditorContent", function() { return EditorContent; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EditorFloatingMenu", function() { return EditorFloatingMenu; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EditorMenuBar", function() { return EditorMenuBar; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EditorMenuBubble", function() { return EditorMenuBubble; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Extension", function() { return Extension; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Mark", function() { return Mark; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Node", function() { return Node; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Paragraph", function() { return Paragraph; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Text", function() { return Text; }); +/* harmony import */ var prosemirror_state__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! prosemirror-state */ "./node_modules/prosemirror-state/dist/index.es.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "NodeSelection", function() { return prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["NodeSelection"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Plugin", function() { return prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["Plugin"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "PluginKey", function() { return prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["PluginKey"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "TextSelection", function() { return prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"]; }); + +/* harmony import */ var prosemirror_view__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! prosemirror-view */ "./node_modules/prosemirror-view/dist/index.es.js"); +/* harmony import */ var prosemirror_model__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! prosemirror-model */ "./node_modules/prosemirror-model/dist/index.es.js"); +/* harmony import */ var prosemirror_dropcursor__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! prosemirror-dropcursor */ "./node_modules/prosemirror-dropcursor/dist/index.es.js"); +/* harmony import */ var prosemirror_gapcursor__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! prosemirror-gapcursor */ "./node_modules/prosemirror-gapcursor/dist/index.es.js"); +/* harmony import */ var prosemirror_keymap__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! prosemirror-keymap */ "./node_modules/prosemirror-keymap/dist/index.es.js"); +/* harmony import */ var prosemirror_commands__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! prosemirror-commands */ "./node_modules/prosemirror-commands/dist/index.es.js"); +/* harmony import */ var prosemirror_inputrules__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! prosemirror-inputrules */ "./node_modules/prosemirror-inputrules/dist/index.es.js"); +/* harmony import */ var tiptap_utils__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! tiptap-utils */ "./node_modules/tiptap-utils/dist/utils.esm.js"); +/* harmony import */ var vue__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! vue */ "./node_modules/vue/dist/vue.common.js"); +/* harmony import */ var vue__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__webpack_require__.n(vue__WEBPACK_IMPORTED_MODULE_9__); +/* harmony import */ var tiptap_commands__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! tiptap-commands */ "./node_modules/tiptap-commands/dist/commands.esm.js"); + + /*! + * tiptap v1.26.5 + * (c) 2019 Scrumpy UG (limited liability) + * @license MIT + */ + + + + + + + + + + + + + + +function _typeof(obj) { + if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { + _typeof = function (obj) { + return typeof obj; + }; + } else { + _typeof = function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }; + } + + return _typeof(obj); +} + +function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } +} + +function _defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } +} + +function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + return Constructor; +} + +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; +} + +function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + if (enumerableOnly) symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + }); + keys.push.apply(keys, symbols); + } + + return keys; +} + +function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = arguments[i] != null ? arguments[i] : {}; + + if (i % 2) { + ownKeys(Object(source), true).forEach(function (key) { + _defineProperty(target, key, source[key]); + }); + } else if (Object.getOwnPropertyDescriptors) { + Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + } else { + ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + } + + return target; +} + +function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function"); + } + + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + writable: true, + configurable: true + } + }); + if (superClass) _setPrototypeOf(subClass, superClass); +} + +function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); +} + +function _setPrototypeOf(o, p) { + _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { + o.__proto__ = p; + return o; + }; + + return _setPrototypeOf(o, p); +} + +function _assertThisInitialized(self) { + if (self === void 0) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } + + return self; +} + +function _possibleConstructorReturn(self, call) { + if (call && (typeof call === "object" || typeof call === "function")) { + return call; + } + + return _assertThisInitialized(self); +} + +function _slicedToArray(arr, i) { + return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); +} + +function _toConsumableArray(arr) { + return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); +} + +function _arrayWithoutHoles(arr) { + if (Array.isArray(arr)) { + for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; + + return arr2; + } +} + +function _arrayWithHoles(arr) { + if (Array.isArray(arr)) return arr; +} + +function _iterableToArray(iter) { + if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); +} + +function _iterableToArrayLimit(arr, i) { + if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { + return; + } + + var _arr = []; + var _n = true; + var _d = false; + var _e = undefined; + + try { + for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { + _arr.push(_s.value); + + if (i && _arr.length === i) break; + } + } catch (err) { + _d = true; + _e = err; + } finally { + try { + if (!_n && _i["return"] != null) _i["return"](); + } finally { + if (_d) throw _e; + } + } + + return _arr; +} + +function _nonIterableSpread() { + throw new TypeError("Invalid attempt to spread non-iterable instance"); +} + +function _nonIterableRest() { + throw new TypeError("Invalid attempt to destructure non-iterable instance"); +} + +function camelCase (str) { + return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) { + return index === 0 ? word.toLowerCase() : word.toUpperCase(); + }).replace(/\s+/g, ''); +} + +var ComponentView = +/*#__PURE__*/ +function () { + function ComponentView(component, _ref) { + var editor = _ref.editor, + extension = _ref.extension, + parent = _ref.parent, + node = _ref.node, + view = _ref.view, + decorations = _ref.decorations, + getPos = _ref.getPos; + + _classCallCheck(this, ComponentView); + + this.component = component; + this.editor = editor; + this.extension = extension; + this.parent = parent; + this.node = node; + this.view = view; + this.decorations = decorations; + this.isNode = !!this.node.marks; + this.isMark = !this.isNode; + this.getPos = this.isMark ? this.getMarkPos : getPos; + this.captureEvents = true; + this.dom = this.createDOM(); + this.contentDOM = this.vm.$refs.content; + } + + _createClass(ComponentView, [{ + key: "createDOM", + value: function createDOM() { + var _this = this; + + var Component = vue__WEBPACK_IMPORTED_MODULE_9___default.a.extend(this.component); + var props = { + editor: this.editor, + node: this.node, + view: this.view, + getPos: function getPos() { + return _this.getPos(); + }, + decorations: this.decorations, + selected: false, + options: this.extension.options, + updateAttrs: function updateAttrs(attrs) { + return _this.updateAttrs(attrs); + } + }; + + if (typeof this.extension.setSelection === 'function') { + this.setSelection = this.extension.setSelection; + } + + this.vm = new Component({ + parent: this.parent, + propsData: props + }).$mount(); + return this.vm.$el; + } + }, { + key: "update", + value: function update(node, decorations) { + if (node.type !== this.node.type) { + return false; + } + + if (node === this.node && this.decorations === decorations) { + return true; + } + + this.node = node; + this.decorations = decorations; + this.updateComponentProps({ + node: node, + decorations: decorations + }); + return true; + } + }, { + key: "updateComponentProps", + value: function updateComponentProps(props) { + var _this2 = this; + + if (!this.vm._props) { + return; + } // Update props in component + // TODO: Avoid mutating a prop directly. + // Maybe there is a better way to do this? + + + var originalSilent = vue__WEBPACK_IMPORTED_MODULE_9___default.a.config.silent; + vue__WEBPACK_IMPORTED_MODULE_9___default.a.config.silent = true; + Object.entries(props).forEach(function (_ref2) { + var _ref3 = _slicedToArray(_ref2, 2), + key = _ref3[0], + value = _ref3[1]; + + _this2.vm._props[key] = value; + }); // this.vm._props.node = node + // this.vm._props.decorations = decorations + + vue__WEBPACK_IMPORTED_MODULE_9___default.a.config.silent = originalSilent; + } + }, { + key: "updateAttrs", + value: function updateAttrs(attrs) { + if (!this.view.editable) { + return; + } + + var state = this.view.state; + var type = this.node.type; + var pos = this.getPos(); + + var newAttrs = _objectSpread2({}, this.node.attrs, {}, attrs); + + var transaction = this.isMark ? state.tr.removeMark(pos.from, pos.to, type).addMark(pos.from, pos.to, type.create(newAttrs)) : state.tr.setNodeMarkup(pos, null, newAttrs); + this.view.dispatch(transaction); + } // prevent a full re-render of the vue component on update + // we'll handle prop updates in `update()` + + }, { + key: "ignoreMutation", + value: function ignoreMutation(mutation) { + // allow leaf nodes to be selected + if (mutation.type === 'selection') { + return false; + } + + if (!this.contentDOM) { + return true; + } + + return !this.contentDOM.contains(mutation.target); + } // disable (almost) all prosemirror event listener for node views + + }, { + key: "stopEvent", + value: function stopEvent(event) { + var _this3 = this; + + if (typeof this.extension.stopEvent === 'function') { + return this.extension.stopEvent(event); + } + + var draggable = !!this.extension.schema.draggable; // support a custom drag handle + + if (draggable && event.type === 'mousedown') { + var dragHandle = event.target.closest && event.target.closest('[data-drag-handle]'); + var isValidDragHandle = dragHandle && (this.dom === dragHandle || this.dom.contains(dragHandle)); + + if (isValidDragHandle) { + this.captureEvents = false; + document.addEventListener('dragend', function () { + _this3.captureEvents = true; + }, { + once: true + }); + } + } + + var isCopy = event.type === 'copy'; + var isPaste = event.type === 'paste'; + var isCut = event.type === 'cut'; + var isDrag = event.type.startsWith('drag') || event.type === 'drop'; + + if (draggable && isDrag || isCopy || isPaste || isCut) { + return false; + } + + return this.captureEvents; + } + }, { + key: "selectNode", + value: function selectNode() { + this.updateComponentProps({ + selected: true + }); + } + }, { + key: "deselectNode", + value: function deselectNode() { + this.updateComponentProps({ + selected: false + }); + } + }, { + key: "getMarkPos", + value: function getMarkPos() { + var pos = this.view.posAtDOM(this.dom); + var resolvedPos = this.view.state.doc.resolve(pos); + var range = Object(tiptap_utils__WEBPACK_IMPORTED_MODULE_8__["getMarkRange"])(resolvedPos, this.node.type); + return range; + } + }, { + key: "destroy", + value: function destroy() { + this.vm.$destroy(); + } + }]); + + return ComponentView; +}(); + +var Emitter = +/*#__PURE__*/ +function () { + function Emitter() { + _classCallCheck(this, Emitter); + } + + _createClass(Emitter, [{ + key: "on", + // Add an event listener for given event + value: function on(event, fn) { + this._callbacks = this._callbacks || {}; // Create namespace for this event + + if (!this._callbacks[event]) { + this._callbacks[event] = []; + } + + this._callbacks[event].push(fn); + + return this; + } + }, { + key: "emit", + value: function emit(event) { + var _this = this; + + for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + args[_key - 1] = arguments[_key]; + } + + this._callbacks = this._callbacks || {}; + var callbacks = this._callbacks[event]; + + if (callbacks) { + callbacks.forEach(function (callback) { + return callback.apply(_this, args); + }); + } + + return this; + } // Remove event listener for given event. + // If fn is not provided, all event listeners for that event will be removed. + // If neither is provided, all event listeners will be removed. + + }, { + key: "off", + value: function off(event, fn) { + if (!arguments.length) { + this._callbacks = {}; + } else { + // event listeners for the given event + var callbacks = this._callbacks ? this._callbacks[event] : null; + + if (callbacks) { + if (fn) { + this._callbacks[event] = callbacks.filter(function (cb) { + return cb !== fn; + }); // remove specific handler + } else { + delete this._callbacks[event]; // remove all handlers + } + } + } + + return this; + } + }]); + + return Emitter; +}(); + +var Extension = +/*#__PURE__*/ +function () { + function Extension() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _classCallCheck(this, Extension); + + this.options = _objectSpread2({}, this.defaultOptions, {}, options); + } + + _createClass(Extension, [{ + key: "init", + value: function init() { + return null; + } + }, { + key: "bindEditor", + value: function bindEditor() { + var editor = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + this.editor = editor; + } + }, { + key: "inputRules", + value: function inputRules() { + return []; + } + }, { + key: "pasteRules", + value: function pasteRules() { + return []; + } + }, { + key: "keys", + value: function keys() { + return {}; + } + }, { + key: "name", + get: function get() { + return null; + } + }, { + key: "type", + get: function get() { + return 'extension'; + } + }, { + key: "update", + get: function get() { + return function () {}; + } + }, { + key: "defaultOptions", + get: function get() { + return {}; + } + }, { + key: "plugins", + get: function get() { + return []; + } + }]); + + return Extension; +}(); + +var ExtensionManager = +/*#__PURE__*/ +function () { + function ExtensionManager() { + var extensions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; + var editor = arguments.length > 1 ? arguments[1] : undefined; + + _classCallCheck(this, ExtensionManager); + + extensions.forEach(function (extension) { + extension.bindEditor(editor); + extension.init(); + }); + this.extensions = extensions; + } + + _createClass(ExtensionManager, [{ + key: "keymaps", + value: function keymaps(_ref) { + var schema = _ref.schema; + var extensionKeymaps = this.extensions.filter(function (extension) { + return ['extension'].includes(extension.type); + }).filter(function (extension) { + return extension.keys; + }).map(function (extension) { + return extension.keys({ + schema: schema + }); + }); + var nodeMarkKeymaps = this.extensions.filter(function (extension) { + return ['node', 'mark'].includes(extension.type); + }).filter(function (extension) { + return extension.keys; + }).map(function (extension) { + return extension.keys({ + type: schema["".concat(extension.type, "s")][extension.name], + schema: schema + }); + }); + return [].concat(_toConsumableArray(extensionKeymaps), _toConsumableArray(nodeMarkKeymaps)).map(function (keys) { + return Object(prosemirror_keymap__WEBPACK_IMPORTED_MODULE_5__["keymap"])(keys); + }); + } + }, { + key: "inputRules", + value: function inputRules(_ref2) { + var schema = _ref2.schema, + excludedExtensions = _ref2.excludedExtensions; + if (!(excludedExtensions instanceof Array) && excludedExtensions) return []; + var allowedExtensions = excludedExtensions instanceof Array ? this.extensions.filter(function (extension) { + return !excludedExtensions.includes(extension.name); + }) : this.extensions; + var extensionInputRules = allowedExtensions.filter(function (extension) { + return ['extension'].includes(extension.type); + }).filter(function (extension) { + return extension.inputRules; + }).map(function (extension) { + return extension.inputRules({ + schema: schema + }); + }); + var nodeMarkInputRules = allowedExtensions.filter(function (extension) { + return ['node', 'mark'].includes(extension.type); + }).filter(function (extension) { + return extension.inputRules; + }).map(function (extension) { + return extension.inputRules({ + type: schema["".concat(extension.type, "s")][extension.name], + schema: schema + }); + }); + return [].concat(_toConsumableArray(extensionInputRules), _toConsumableArray(nodeMarkInputRules)).reduce(function (allInputRules, inputRules) { + return [].concat(_toConsumableArray(allInputRules), _toConsumableArray(inputRules)); + }, []); + } + }, { + key: "pasteRules", + value: function pasteRules(_ref3) { + var schema = _ref3.schema, + excludedExtensions = _ref3.excludedExtensions; + if (!(excludedExtensions instanceof Array) && excludedExtensions) return []; + var allowedExtensions = excludedExtensions instanceof Array ? this.extensions.filter(function (extension) { + return !excludedExtensions.includes(extension.name); + }) : this.extensions; + var extensionPasteRules = allowedExtensions.filter(function (extension) { + return ['extension'].includes(extension.type); + }).filter(function (extension) { + return extension.pasteRules; + }).map(function (extension) { + return extension.pasteRules({ + schema: schema + }); + }); + var nodeMarkPasteRules = allowedExtensions.filter(function (extension) { + return ['node', 'mark'].includes(extension.type); + }).filter(function (extension) { + return extension.pasteRules; + }).map(function (extension) { + return extension.pasteRules({ + type: schema["".concat(extension.type, "s")][extension.name], + schema: schema + }); + }); + return [].concat(_toConsumableArray(extensionPasteRules), _toConsumableArray(nodeMarkPasteRules)).reduce(function (allPasteRules, pasteRules) { + return [].concat(_toConsumableArray(allPasteRules), _toConsumableArray(pasteRules)); + }, []); + } + }, { + key: "commands", + value: function commands(_ref4) { + var schema = _ref4.schema, + view = _ref4.view; + return this.extensions.filter(function (extension) { + return extension.commands; + }).reduce(function (allCommands, extension) { + var name = extension.name, + type = extension.type; + var commands = {}; + var value = extension.commands(_objectSpread2({ + schema: schema + }, ['node', 'mark'].includes(type) ? { + type: schema["".concat(type, "s")][name] + } : {})); + + var apply = function apply(cb, attrs) { + if (!view.editable) { + return false; + } + + view.focus(); + return cb(attrs)(view.state, view.dispatch, view); + }; + + var handle = function handle(_name, _value) { + if (Array.isArray(_value)) { + commands[_name] = function (attrs) { + return _value.forEach(function (callback) { + return apply(callback, attrs); + }); + }; + } else if (typeof _value === 'function') { + commands[_name] = function (attrs) { + return apply(_value, attrs); + }; + } + }; + + if (_typeof(value) === 'object') { + Object.entries(value).forEach(function (_ref5) { + var _ref6 = _slicedToArray(_ref5, 2), + commandName = _ref6[0], + commandValue = _ref6[1]; + + handle(commandName, commandValue); + }); + } else { + handle(name, value); + } + + return _objectSpread2({}, allCommands, {}, commands); + }, {}); + } + }, { + key: "nodes", + get: function get() { + return this.extensions.filter(function (extension) { + return extension.type === 'node'; + }).reduce(function (nodes, _ref7) { + var name = _ref7.name, + schema = _ref7.schema; + return _objectSpread2({}, nodes, _defineProperty({}, name, schema)); + }, {}); + } + }, { + key: "options", + get: function get() { + var view = this.view; + return this.extensions.reduce(function (nodes, extension) { + return _objectSpread2({}, nodes, _defineProperty({}, extension.name, new Proxy(extension.options, { + set: function set(obj, prop, value) { + var changed = obj[prop] !== value; + Object.assign(obj, _defineProperty({}, prop, value)); + + if (changed) { + extension.update(view); + } + + return true; + } + }))); + }, {}); + } + }, { + key: "marks", + get: function get() { + return this.extensions.filter(function (extension) { + return extension.type === 'mark'; + }).reduce(function (marks, _ref8) { + var name = _ref8.name, + schema = _ref8.schema; + return _objectSpread2({}, marks, _defineProperty({}, name, schema)); + }, {}); + } + }, { + key: "plugins", + get: function get() { + return this.extensions.filter(function (extension) { + return extension.plugins; + }).reduce(function (allPlugins, _ref9) { + var plugins = _ref9.plugins; + return [].concat(_toConsumableArray(allPlugins), _toConsumableArray(plugins)); + }, []); + } + }]); + + return ExtensionManager; +}(); + +function injectCSS (css) { + if (true) { + var style = document.createElement('style'); + style.type = 'text/css'; + style.textContent = css; + var _document = document, + head = _document.head; + var firstChild = head.firstChild; + + if (firstChild) { + head.insertBefore(style, firstChild); + } else { + head.appendChild(style); + } + } +} + +var Mark = +/*#__PURE__*/ +function (_Extension) { + _inherits(Mark, _Extension); + + function Mark() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _classCallCheck(this, Mark); + + return _possibleConstructorReturn(this, _getPrototypeOf(Mark).call(this, options)); + } + + _createClass(Mark, [{ + key: "command", + value: function command() { + return function () {}; + } + }, { + key: "type", + get: function get() { + return 'mark'; + } + }, { + key: "view", + get: function get() { + return null; + } + }, { + key: "schema", + get: function get() { + return null; + } + }]); + + return Mark; +}(Extension); + +function minMax() { + var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + var min = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + var max = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + return Math.min(Math.max(parseInt(value, 10), min), max); +} + +var Node = +/*#__PURE__*/ +function (_Extension) { + _inherits(Node, _Extension); + + function Node() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _classCallCheck(this, Node); + + return _possibleConstructorReturn(this, _getPrototypeOf(Node).call(this, options)); + } + + _createClass(Node, [{ + key: "command", + value: function command() { + return function () {}; + } + }, { + key: "type", + get: function get() { + return 'node'; + } + }, { + key: "view", + get: function get() { + return null; + } + }, { + key: "schema", + get: function get() { + return null; + } + }]); + + return Node; +}(Extension); + +var Doc = +/*#__PURE__*/ +function (_Node) { + _inherits(Doc, _Node); + + function Doc() { + _classCallCheck(this, Doc); + + return _possibleConstructorReturn(this, _getPrototypeOf(Doc).apply(this, arguments)); + } + + _createClass(Doc, [{ + key: "name", + get: function get() { + return 'doc'; + } + }, { + key: "schema", + get: function get() { + return { + content: 'block+' + }; + } + }]); + + return Doc; +}(Node); + +var Paragraph = +/*#__PURE__*/ +function (_Node) { + _inherits(Paragraph, _Node); + + function Paragraph() { + _classCallCheck(this, Paragraph); + + return _possibleConstructorReturn(this, _getPrototypeOf(Paragraph).apply(this, arguments)); + } + + _createClass(Paragraph, [{ + key: "commands", + value: function commands(_ref) { + var type = _ref.type; + return function () { + return Object(tiptap_commands__WEBPACK_IMPORTED_MODULE_10__["setBlockType"])(type); + }; + } + }, { + key: "name", + get: function get() { + return 'paragraph'; + } + }, { + key: "schema", + get: function get() { + return { + content: 'inline*', + group: 'block', + draggable: false, + parseDOM: [{ + tag: 'p' + }], + toDOM: function toDOM() { + return ['p', 0]; + } + }; + } + }]); + + return Paragraph; +}(Node); + +var Text = +/*#__PURE__*/ +function (_Node) { + _inherits(Text, _Node); + + function Text() { + _classCallCheck(this, Text); + + return _possibleConstructorReturn(this, _getPrototypeOf(Text).apply(this, arguments)); + } + + _createClass(Text, [{ + key: "name", + get: function get() { + return 'text'; + } + }, { + key: "schema", + get: function get() { + return { + group: 'inline' + }; + } + }]); + + return Text; +}(Node); + +var css = ".ProseMirror {\n position: relative;\n}\n\n.ProseMirror {\n word-wrap: break-word;\n white-space: pre-wrap;\n -webkit-font-variant-ligatures: none;\n font-variant-ligatures: none;\n}\n\n.ProseMirror pre {\n white-space: pre-wrap;\n}\n\n.ProseMirror-gapcursor {\n display: none;\n pointer-events: none;\n position: absolute;\n}\n\n.ProseMirror-gapcursor:after {\n content: \"\";\n display: block;\n position: absolute;\n top: -2px;\n width: 20px;\n border-top: 1px solid black;\n animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite;\n}\n\n@keyframes ProseMirror-cursor-blink {\n to {\n visibility: hidden;\n }\n}\n\n.ProseMirror-hideselection *::selection {\n background: transparent;\n}\n\n.ProseMirror-hideselection *::-moz-selection {\n background: transparent;\n}\n\n.ProseMirror-hideselection * {\n caret-color: transparent;\n}\n\n.ProseMirror-focused .ProseMirror-gapcursor {\n display: block;\n}\n"; + +var Editor = +/*#__PURE__*/ +function (_Emitter) { + _inherits(Editor, _Emitter); + + function Editor() { + var _this; + + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _classCallCheck(this, Editor); + + _this = _possibleConstructorReturn(this, _getPrototypeOf(Editor).call(this)); + _this.defaultOptions = { + editorProps: {}, + editable: true, + autoFocus: null, + extensions: [], + content: '', + topNode: 'doc', + emptyDocument: { + type: 'doc', + content: [{ + type: 'paragraph' + }] + }, + useBuiltInExtensions: true, + disableInputRules: false, + disablePasteRules: false, + dropCursor: {}, + parseOptions: {}, + injectCSS: true, + onInit: function onInit() {}, + onTransaction: function onTransaction() {}, + onUpdate: function onUpdate() {}, + onFocus: function onFocus() {}, + onBlur: function onBlur() {}, + onPaste: function onPaste() {}, + onDrop: function onDrop() {} + }; + _this.events = ['init', 'transaction', 'update', 'focus', 'blur', 'paste', 'drop']; + + _this.init(options); + + return _this; + } + + _createClass(Editor, [{ + key: "init", + value: function init() { + var _this2 = this; + + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + this.setOptions(_objectSpread2({}, this.defaultOptions, {}, options)); + this.focused = false; + this.selection = { + from: 0, + to: 0 + }; + this.element = document.createElement('div'); + this.extensions = this.createExtensions(); + this.nodes = this.createNodes(); + this.marks = this.createMarks(); + this.schema = this.createSchema(); + this.plugins = this.createPlugins(); + this.keymaps = this.createKeymaps(); + this.inputRules = this.createInputRules(); + this.pasteRules = this.createPasteRules(); + this.view = this.createView(); + this.commands = this.createCommands(); + this.setActiveNodesAndMarks(); + + if (this.options.injectCSS) { + injectCSS(css); + } + + if (this.options.autoFocus !== null) { + this.focus(this.options.autoFocus); + } + + this.events.forEach(function (name) { + _this2.on(name, _this2.options[camelCase("on ".concat(name))] || function () {}); + }); + this.emit('init', { + view: this.view, + state: this.state + }); // give extension manager access to our view + + this.extensions.view = this.view; + } + }, { + key: "setOptions", + value: function setOptions(options) { + this.options = _objectSpread2({}, this.options, {}, options); + + if (this.view && this.state) { + this.view.updateState(this.state); + } + } + }, { + key: "createExtensions", + value: function createExtensions() { + return new ExtensionManager([].concat(_toConsumableArray(this.builtInExtensions), _toConsumableArray(this.options.extensions)), this); + } + }, { + key: "createPlugins", + value: function createPlugins() { + return this.extensions.plugins; + } + }, { + key: "createKeymaps", + value: function createKeymaps() { + return this.extensions.keymaps({ + schema: this.schema + }); + } + }, { + key: "createInputRules", + value: function createInputRules() { + return this.extensions.inputRules({ + schema: this.schema, + excludedExtensions: this.options.disableInputRules + }); + } + }, { + key: "createPasteRules", + value: function createPasteRules() { + return this.extensions.pasteRules({ + schema: this.schema, + excludedExtensions: this.options.disablePasteRules + }); + } + }, { + key: "createCommands", + value: function createCommands() { + return this.extensions.commands({ + schema: this.schema, + view: this.view + }); + } + }, { + key: "createNodes", + value: function createNodes() { + return this.extensions.nodes; + } + }, { + key: "createMarks", + value: function createMarks() { + return this.extensions.marks; + } + }, { + key: "createSchema", + value: function createSchema() { + return new prosemirror_model__WEBPACK_IMPORTED_MODULE_2__["Schema"]({ + topNode: this.options.topNode, + nodes: this.nodes, + marks: this.marks + }); + } + }, { + key: "createState", + value: function createState() { + var _this3 = this; + + return prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["EditorState"].create({ + schema: this.schema, + doc: this.createDocument(this.options.content), + plugins: [].concat(_toConsumableArray(this.plugins), [Object(prosemirror_inputrules__WEBPACK_IMPORTED_MODULE_7__["inputRules"])({ + rules: this.inputRules + })], _toConsumableArray(this.pasteRules), _toConsumableArray(this.keymaps), [Object(prosemirror_keymap__WEBPACK_IMPORTED_MODULE_5__["keymap"])({ + Backspace: prosemirror_inputrules__WEBPACK_IMPORTED_MODULE_7__["undoInputRule"] + }), Object(prosemirror_keymap__WEBPACK_IMPORTED_MODULE_5__["keymap"])(prosemirror_commands__WEBPACK_IMPORTED_MODULE_6__["baseKeymap"]), Object(prosemirror_dropcursor__WEBPACK_IMPORTED_MODULE_3__["dropCursor"])(this.options.dropCursor), Object(prosemirror_gapcursor__WEBPACK_IMPORTED_MODULE_4__["gapCursor"])(), new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["Plugin"]({ + key: new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["PluginKey"]('editable'), + props: { + editable: function editable() { + return _this3.options.editable; + } + } + }), new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["Plugin"]({ + props: { + attributes: { + tabindex: 0 + }, + handleDOMEvents: { + focus: function focus(view, event) { + _this3.focused = true; + + _this3.emit('focus', { + event: event, + state: view.state, + view: view + }); + + var transaction = _this3.state.tr.setMeta('focused', true); + + _this3.view.dispatch(transaction); + }, + blur: function blur(view, event) { + _this3.focused = false; + + _this3.emit('blur', { + event: event, + state: view.state, + view: view + }); + + var transaction = _this3.state.tr.setMeta('focused', false); + + _this3.view.dispatch(transaction); + } + } + } + }), new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["Plugin"]({ + props: this.options.editorProps + })]) + }); + } + }, { + key: "createDocument", + value: function createDocument(content) { + var parseOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.options.parseOptions; + + if (content === null) { + return this.schema.nodeFromJSON(this.options.emptyDocument); + } + + if (_typeof(content) === 'object') { + try { + return this.schema.nodeFromJSON(content); + } catch (error) { + console.warn('[tiptap warn]: Invalid content.', 'Passed value:', content, 'Error:', error); + return this.schema.nodeFromJSON(this.options.emptyDocument); + } + } + + if (typeof content === 'string') { + var element = document.createElement('div'); + element.innerHTML = content.trim(); + return prosemirror_model__WEBPACK_IMPORTED_MODULE_2__["DOMParser"].fromSchema(this.schema).parse(element, parseOptions); + } + + return false; + } + }, { + key: "createView", + value: function createView() { + var _this4 = this; + + return new prosemirror_view__WEBPACK_IMPORTED_MODULE_1__["EditorView"](this.element, { + state: this.createState(), + handlePaste: function handlePaste() { + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + _this4.emit.apply(_this4, ['paste'].concat(args)); + }, + handleDrop: function handleDrop() { + for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { + args[_key2] = arguments[_key2]; + } + + _this4.emit.apply(_this4, ['drop'].concat(args)); + }, + dispatchTransaction: this.dispatchTransaction.bind(this) + }); + } + }, { + key: "setParentComponent", + value: function setParentComponent() { + var component = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + + if (!component) { + return; + } + + this.view.setProps({ + nodeViews: this.initNodeViews({ + parent: component, + extensions: [].concat(_toConsumableArray(this.builtInExtensions), _toConsumableArray(this.options.extensions)) + }) + }); + } + }, { + key: "initNodeViews", + value: function initNodeViews(_ref) { + var _this5 = this; + + var parent = _ref.parent, + extensions = _ref.extensions; + return extensions.filter(function (extension) { + return ['node', 'mark'].includes(extension.type); + }).filter(function (extension) { + return extension.view; + }).reduce(function (nodeViews, extension) { + var nodeView = function nodeView(node, view, getPos, decorations) { + var component = extension.view; + return new ComponentView(component, { + editor: _this5, + extension: extension, + parent: parent, + node: node, + view: view, + getPos: getPos, + decorations: decorations + }); + }; + + return _objectSpread2({}, nodeViews, _defineProperty({}, extension.name, nodeView)); + }, {}); + } + }, { + key: "dispatchTransaction", + value: function dispatchTransaction(transaction) { + var newState = this.state.apply(transaction); + this.view.updateState(newState); + this.selection = { + from: this.state.selection.from, + to: this.state.selection.to + }; + this.setActiveNodesAndMarks(); + this.emit('transaction', { + getHTML: this.getHTML.bind(this), + getJSON: this.getJSON.bind(this), + state: this.state, + transaction: transaction + }); + + if (!transaction.docChanged || transaction.getMeta('preventUpdate')) { + return; + } + + this.emitUpdate(transaction); + } + }, { + key: "emitUpdate", + value: function emitUpdate(transaction) { + this.emit('update', { + getHTML: this.getHTML.bind(this), + getJSON: this.getJSON.bind(this), + state: this.state, + transaction: transaction + }); + } + }, { + key: "resolveSelection", + value: function resolveSelection() { + var position = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + + if (this.selection && position === null) { + return this.selection; + } + + if (position === 'start' || position === true) { + return { + from: 0, + to: 0 + }; + } + + if (position === 'end') { + var doc = this.state.doc; + return { + from: doc.content.size, + to: doc.content.size + }; + } + + return { + from: position, + to: position + }; + } + }, { + key: "focus", + value: function focus() { + var _this6 = this; + + var position = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + + if (this.view.focused && position === null || position === false) { + return; + } + + var _this$resolveSelectio = this.resolveSelection(position), + from = _this$resolveSelectio.from, + to = _this$resolveSelectio.to; + + this.setSelection(from, to); + setTimeout(function () { + return _this6.view.focus(); + }, 10); + } + }, { + key: "setSelection", + value: function setSelection() { + var from = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + var to = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + var _this$state = this.state, + doc = _this$state.doc, + tr = _this$state.tr; + var resolvedFrom = minMax(from, 0, doc.content.size); + var resolvedEnd = minMax(to, 0, doc.content.size); + var selection = prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"].create(doc, resolvedFrom, resolvedEnd); + var transaction = tr.setSelection(selection); + this.view.dispatch(transaction); + } + }, { + key: "blur", + value: function blur() { + this.view.dom.blur(); + } + }, { + key: "getSchemaJSON", + value: function getSchemaJSON() { + return JSON.parse(JSON.stringify({ + nodes: this.extensions.nodes, + marks: this.extensions.marks + })); + } + }, { + key: "getHTML", + value: function getHTML() { + var div = document.createElement('div'); + var fragment = prosemirror_model__WEBPACK_IMPORTED_MODULE_2__["DOMSerializer"].fromSchema(this.schema).serializeFragment(this.state.doc.content); + div.appendChild(fragment); + return div.innerHTML; + } + }, { + key: "getJSON", + value: function getJSON() { + return this.state.doc.toJSON(); + } + }, { + key: "setContent", + value: function setContent() { + var content = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var emitUpdate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + var parseOptions = arguments.length > 2 ? arguments[2] : undefined; + var _this$state2 = this.state, + doc = _this$state2.doc, + tr = _this$state2.tr; + var document = this.createDocument(content, parseOptions); + var selection = prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["TextSelection"].create(doc, 0, doc.content.size); + var transaction = tr.setSelection(selection).replaceSelectionWith(document, false).setMeta('preventUpdate', !emitUpdate); + this.view.dispatch(transaction); + } + }, { + key: "clearContent", + value: function clearContent() { + var emitUpdate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + this.setContent(this.options.emptyDocument, emitUpdate); + } + }, { + key: "setActiveNodesAndMarks", + value: function setActiveNodesAndMarks() { + var _this7 = this; + + this.activeMarks = Object.entries(this.schema.marks).reduce(function (marks, _ref2) { + var _ref3 = _slicedToArray(_ref2, 2), + name = _ref3[0], + mark = _ref3[1]; + + return _objectSpread2({}, marks, _defineProperty({}, name, function () { + var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + return Object(tiptap_utils__WEBPACK_IMPORTED_MODULE_8__["markIsActive"])(_this7.state, mark, attrs); + })); + }, {}); + this.activeMarkAttrs = Object.entries(this.schema.marks).reduce(function (marks, _ref4) { + var _ref5 = _slicedToArray(_ref4, 2), + name = _ref5[0], + mark = _ref5[1]; + + return _objectSpread2({}, marks, _defineProperty({}, name, Object(tiptap_utils__WEBPACK_IMPORTED_MODULE_8__["getMarkAttrs"])(_this7.state, mark))); + }, {}); + this.activeNodes = Object.entries(this.schema.nodes).reduce(function (nodes, _ref6) { + var _ref7 = _slicedToArray(_ref6, 2), + name = _ref7[0], + node = _ref7[1]; + + return _objectSpread2({}, nodes, _defineProperty({}, name, function () { + var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + return Object(tiptap_utils__WEBPACK_IMPORTED_MODULE_8__["nodeIsActive"])(_this7.state, node, attrs); + })); + }, {}); + } + }, { + key: "getMarkAttrs", + value: function getMarkAttrs() { + var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + return this.activeMarkAttrs[type]; + } + }, { + key: "registerPlugin", + value: function registerPlugin() { + var plugin = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + + if (!plugin) { + return; + } + + var newState = this.state.reconfigure({ + plugins: this.state.plugins.concat([plugin]) + }); + this.view.updateState(newState); + } + }, { + key: "unregisterPlugin", + value: function unregisterPlugin() { + var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + + if (!name || !this.view.docView) { + return; + } + + var newState = this.state.reconfigure({ + plugins: this.state.plugins.filter(function (plugin) { + return !plugin.key.startsWith("".concat(name, "$")); + }) + }); + this.view.updateState(newState); + } + }, { + key: "destroy", + value: function destroy() { + if (!this.view) { + return; + } + + this.view.destroy(); + } + }, { + key: "builtInExtensions", + get: function get() { + if (!this.options.useBuiltInExtensions) { + return []; + } + + return [new Doc(), new Text(), new Paragraph()]; + } + }, { + key: "state", + get: function get() { + return this.view ? this.view.state : null; + } + }, { + key: "isActive", + get: function get() { + return Object.entries(_objectSpread2({}, this.activeMarks, {}, this.activeNodes)).reduce(function (types, _ref8) { + var _ref9 = _slicedToArray(_ref8, 2), + name = _ref9[0], + value = _ref9[1]; + + return _objectSpread2({}, types, _defineProperty({}, name, function () { + var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + return value(attrs); + })); + }, {}); + } + }]); + + return Editor; +}(Emitter); + +var EditorContent = { + props: { + editor: { + default: null, + type: Object + } + }, + watch: { + editor: { + immediate: true, + handler: function handler(editor) { + var _this = this; + + if (editor && editor.element) { + this.$nextTick(function () { + _this.$el.appendChild(editor.element.firstChild); + + editor.setParentComponent(_this); + }); + } + } + } + }, + render: function render(createElement) { + return createElement('div'); + }, + beforeDestroy: function beforeDestroy() { + this.editor.element = this.$el; + } +}; + +var Menu = +/*#__PURE__*/ +function () { + function Menu(_ref) { + var _this = this; + + var options = _ref.options; + + _classCallCheck(this, Menu); + + this.options = options; + this.preventHide = false; // the mousedown event is fired before blur so we can prevent it + + this.mousedownHandler = this.handleClick.bind(this); + this.options.element.addEventListener('mousedown', this.mousedownHandler); + this.options.editor.on('blur', function () { + if (_this.preventHide) { + _this.preventHide = false; + return; + } + + _this.options.editor.emit('menubar:focusUpdate', false); + }); + } + + _createClass(Menu, [{ + key: "handleClick", + value: function handleClick() { + this.preventHide = true; + } + }, { + key: "destroy", + value: function destroy() { + this.options.element.removeEventListener('mousedown', this.mousedownHandler); + } + }]); + + return Menu; +}(); + +function MenuBar (options) { + return new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["Plugin"]({ + key: new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["PluginKey"]('menu_bar'), + view: function view(editorView) { + return new Menu({ + editorView: editorView, + options: options + }); + } + }); +} + +var EditorMenuBar = { + props: { + editor: { + default: null, + type: Object + } + }, + data: function data() { + return { + focused: false + }; + }, + watch: { + editor: { + immediate: true, + handler: function handler(editor) { + var _this = this; + + if (editor) { + this.$nextTick(function () { + editor.registerPlugin(MenuBar({ + editor: editor, + element: _this.$el + })); + _this.focused = editor.focused; + editor.on('focus', function () { + _this.focused = true; + }); + editor.on('menubar:focusUpdate', function (focused) { + _this.focused = focused; + }); + }); + } + } + } + }, + render: function render() { + if (!this.editor) { + return null; + } + + return this.$scopedSlots.default({ + focused: this.focused, + focus: this.editor.focus, + commands: this.editor.commands, + isActive: this.editor.isActive, + getMarkAttrs: this.editor.getMarkAttrs.bind(this.editor) + }); + } +}; + +function textRange(node, from, to) { + var range = document.createRange(); + range.setEnd(node, to == null ? node.nodeValue.length : to); + range.setStart(node, from || 0); + return range; +} + +function singleRect(object, bias) { + var rects = object.getClientRects(); + return !rects.length ? object.getBoundingClientRect() : rects[bias < 0 ? 0 : rects.length - 1]; +} + +function coordsAtPos(view, pos) { + var end = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; + + var _view$docView$domFrom = view.docView.domFromPos(pos), + node = _view$docView$domFrom.node, + offset = _view$docView$domFrom.offset; + + var side; + var rect; + + if (node.nodeType === 3) { + if (end && offset < node.nodeValue.length) { + rect = singleRect(textRange(node, offset - 1, offset), -1); + side = 'right'; + } else if (offset < node.nodeValue.length) { + rect = singleRect(textRange(node, offset, offset + 1), -1); + side = 'left'; + } + } else if (node.firstChild) { + if (offset < node.childNodes.length) { + var child = node.childNodes[offset]; + rect = singleRect(child.nodeType === 3 ? textRange(child) : child, -1); + side = 'left'; + } + + if ((!rect || rect.top === rect.bottom) && offset) { + var _child = node.childNodes[offset - 1]; + rect = singleRect(_child.nodeType === 3 ? textRange(_child) : _child, 1); + side = 'right'; + } + } else { + rect = node.getBoundingClientRect(); + side = 'left'; + } + + var x = rect[side]; + return { + top: rect.top, + bottom: rect.bottom, + left: x, + right: x + }; +} + +var Menu$1 = +/*#__PURE__*/ +function () { + function Menu(_ref) { + var _this = this; + + var options = _ref.options, + editorView = _ref.editorView; + + _classCallCheck(this, Menu); + + this.options = _objectSpread2({}, { + element: null, + keepInBounds: true, + onUpdate: function onUpdate() { + return false; + } + }, {}, options); + this.editorView = editorView; + this.isActive = false; + this.left = 0; + this.bottom = 0; + this.top = 0; + this.preventHide = false; // the mousedown event is fired before blur so we can prevent it + + this.mousedownHandler = this.handleClick.bind(this); + this.options.element.addEventListener('mousedown', this.mousedownHandler); + this.options.editor.on('focus', function (_ref2) { + var view = _ref2.view; + + _this.update(view); + }); + this.options.editor.on('blur', function (_ref3) { + var event = _ref3.event; + + if (_this.preventHide) { + _this.preventHide = false; + return; + } + + _this.hide(event); + }); + } + + _createClass(Menu, [{ + key: "handleClick", + value: function handleClick() { + this.preventHide = true; + } + }, { + key: "update", + value: function update(view, lastState) { + var state = view.state; + + if (view.composing) { + return; + } // Don't do anything if the document/selection didn't change + + + if (lastState && lastState.doc.eq(state.doc) && lastState.selection.eq(state.selection)) { + return; + } // Hide the tooltip if the selection is empty + + + if (state.selection.empty) { + this.hide(); + return; + } // Otherwise, reposition it and update its content + + + var _state$selection = state.selection, + from = _state$selection.from, + to = _state$selection.to; // These are in screen coordinates + // We can't use EditorView.cordsAtPos here because it can't handle linebreaks correctly + // See: https://github.com/ProseMirror/prosemirror-view/pull/47 + + var start = coordsAtPos(view, from); + var end = coordsAtPos(view, to, true); // The box in which the tooltip is positioned, to use as base + + var parent = this.options.element.offsetParent; + + if (!parent) { + this.hide(); + return; + } + + var box = parent.getBoundingClientRect(); + var el = this.options.element.getBoundingClientRect(); // Find a center-ish x position from the selection endpoints (when + // crossing lines, end may be more to the left) + + var left = (start.left + end.left) / 2 - box.left; // Keep the menuBubble in the bounding box of the offsetParent i + + this.left = Math.round(this.options.keepInBounds ? Math.min(box.width - el.width / 2, Math.max(left, el.width / 2)) : left); + this.bottom = Math.round(box.bottom - start.top); + this.top = Math.round(end.bottom - box.top); + this.isActive = true; + this.sendUpdate(); + } + }, { + key: "sendUpdate", + value: function sendUpdate() { + this.options.onUpdate({ + isActive: this.isActive, + left: this.left, + bottom: this.bottom, + top: this.top + }); + } + }, { + key: "hide", + value: function hide(event) { + if (event && event.relatedTarget && this.options.element.parentNode.contains(event.relatedTarget)) { + return; + } + + this.isActive = false; + this.sendUpdate(); + } + }, { + key: "destroy", + value: function destroy() { + this.options.element.removeEventListener('mousedown', this.mousedownHandler); + } + }]); + + return Menu; +}(); + +function MenuBubble (options) { + return new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["Plugin"]({ + key: new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["PluginKey"]('menu_bubble'), + view: function view(editorView) { + return new Menu$1({ + editorView: editorView, + options: options + }); + } + }); +} + +var EditorMenuBubble = { + props: { + editor: { + default: null, + type: Object + }, + keepInBounds: { + default: true, + type: Boolean + } + }, + data: function data() { + return { + menu: { + isActive: false, + left: 0, + bottom: 0 + } + }; + }, + watch: { + editor: { + immediate: true, + handler: function handler(editor) { + var _this = this; + + if (editor) { + this.$nextTick(function () { + editor.registerPlugin(MenuBubble({ + editor: editor, + element: _this.$el, + keepInBounds: _this.keepInBounds, + onUpdate: function onUpdate(menu) { + // the second check ensures event is fired only once + if (menu.isActive && _this.menu.isActive === false) { + _this.$emit('show', menu); + } else if (!menu.isActive && _this.menu.isActive === true) { + _this.$emit('hide', menu); + } + + _this.menu = menu; + } + })); + }); + } + } + } + }, + render: function render() { + if (!this.editor) { + return null; + } + + return this.$scopedSlots.default({ + focused: this.editor.view.focused, + focus: this.editor.focus, + commands: this.editor.commands, + isActive: this.editor.isActive, + getMarkAttrs: this.editor.getMarkAttrs.bind(this.editor), + menu: this.menu + }); + }, + beforeDestroy: function beforeDestroy() { + this.editor.unregisterPlugin('menu_bubble'); + } +}; + +var Menu$2 = +/*#__PURE__*/ +function () { + function Menu(_ref) { + var _this = this; + + var options = _ref.options, + editorView = _ref.editorView; + + _classCallCheck(this, Menu); + + this.options = _objectSpread2({}, { + resizeObserver: true, + element: null, + onUpdate: function onUpdate() { + return false; + } + }, {}, options); + this.preventHide = false; + this.editorView = editorView; + this.isActive = false; + this.top = 0; // the mousedown event is fired before blur so we can prevent it + + this.mousedownHandler = this.handleClick.bind(this); + this.options.element.addEventListener('mousedown', this.mousedownHandler); + this.options.editor.on('focus', function (_ref2) { + var view = _ref2.view; + + _this.update(view); + }); + this.options.editor.on('blur', function (_ref3) { + var event = _ref3.event; + + if (_this.preventHide) { + _this.preventHide = false; + return; + } + + _this.hide(event); + }); // sometimes we have to update the position + // because of a loaded images for example + + if (this.options.resizeObserver && window.ResizeObserver) { + this.resizeObserver = new ResizeObserver(function () { + if (_this.isActive) { + _this.update(_this.editorView); + } + }); + this.resizeObserver.observe(this.editorView.dom); + } + } + + _createClass(Menu, [{ + key: "handleClick", + value: function handleClick() { + this.preventHide = true; + } + }, { + key: "update", + value: function update(view, lastState) { + var state = view.state; // Don't do anything if the document/selection didn't change + + if (lastState && lastState.doc.eq(state.doc) && lastState.selection.eq(state.selection)) { + return; + } + + if (!state.selection.empty) { + this.hide(); + return; + } + + var currentDom = view.domAtPos(state.selection.anchor); + var isActive = currentDom.node.innerHTML === '
      ' && currentDom.node.tagName === 'P' && currentDom.node.parentNode === view.dom; + + if (!isActive) { + this.hide(); + return; + } + + var parent = this.options.element.offsetParent; + + if (!parent) { + this.hide(); + return; + } + + var editorBoundings = parent.getBoundingClientRect(); + var cursorBoundings = view.coordsAtPos(state.selection.anchor); + var top = cursorBoundings.top - editorBoundings.top; + this.isActive = true; + this.top = top; + this.sendUpdate(); + } + }, { + key: "sendUpdate", + value: function sendUpdate() { + this.options.onUpdate({ + isActive: this.isActive, + top: this.top + }); + } + }, { + key: "hide", + value: function hide(event) { + if (event && event.relatedTarget && this.options.element.parentNode.contains(event.relatedTarget)) { + return; + } + + this.isActive = false; + this.sendUpdate(); + } + }, { + key: "destroy", + value: function destroy() { + this.options.element.removeEventListener('mousedown', this.mousedownHandler); + + if (this.resizeObserver) { + this.resizeObserver.unobserve(this.editorView.dom); + } + } + }]); + + return Menu; +}(); + +function FloatingMenu (options) { + return new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["Plugin"]({ + key: new prosemirror_state__WEBPACK_IMPORTED_MODULE_0__["PluginKey"]('floating_menu'), + view: function view(editorView) { + return new Menu$2({ + editorView: editorView, + options: options + }); + } + }); +} + +var EditorFloatingMenu = { + props: { + editor: { + default: null, + type: Object + } + }, + data: function data() { + return { + menu: { + isActive: false, + left: 0, + bottom: 0 + } + }; + }, + watch: { + editor: { + immediate: true, + handler: function handler(editor) { + var _this = this; + + if (editor) { + this.$nextTick(function () { + editor.registerPlugin(FloatingMenu({ + editor: editor, + element: _this.$el, + onUpdate: function onUpdate(menu) { + // the second check ensures event is fired only once + if (menu.isActive && _this.menu.isActive === false) { + _this.$emit('show', menu); + } else if (!menu.isActive && _this.menu.isActive === true) { + _this.$emit('hide', menu); + } + + _this.menu = menu; + } + })); + }); + } + } + } + }, + render: function render() { + if (!this.editor) { + return null; + } + + return this.$scopedSlots.default({ + focused: this.editor.view.focused, + focus: this.editor.focus, + commands: this.editor.commands, + isActive: this.editor.isActive, + getMarkAttrs: this.editor.getMarkAttrs.bind(this.editor), + menu: this.menu + }); + }, + beforeDestroy: function beforeDestroy() { + this.editor.unregisterPlugin('floating_menu'); + } +}; + + + + +/***/ }), + +/***/ "./node_modules/vue-loader/lib/loaders/templateLoader.js?!./node_modules/vue-loader/lib/index.js?!./resources/js/views/EditPage.vue?vue&type=template&id=15baaf58&": +/*!******************************************************************************************************************************************************************************************************!*\ + !*** ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./resources/js/views/EditPage.vue?vue&type=template&id=15baaf58& ***! + \******************************************************************************************************************************************************************************************************/ +/*! exports provided: render, staticRenderFns */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "render", function() { return render; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "staticRenderFns", function() { return staticRenderFns; }); +var render = function() { + var _vm = this + var _h = _vm.$createElement + var _c = _vm._self._c || _h + return _c("div", { attrs: { id: "root" } }, [ + _c("div", { staticClass: "title level-item has-text-centered" }, [ + _vm._v("Motorrad IG\n ") + ]), + _vm._v(" "), + _c( + "div", + { staticClass: "has-text-centered" }, + [ + _c( + "button", + { + staticClass: "button", + on: { + click: function($event) { + return _vm.changeMainText("Über uns") + } + } + }, + [_vm._v("Über uns")] + ), + _vm._v(" "), + _c( + "button", + { + staticClass: "button", + on: { + click: function($event) { + return _vm.changeMainText("Aktuelles") + } + } + }, + [_vm._v("Aktuelles")] + ), + _vm._v(" "), + _c( + "button", + { + staticClass: "button", + on: { + click: function($event) { + return _vm.changeMainText("Mitgliedsantrag") + } + } + }, + [_vm._v("Mitgliedsantrag")] + ), + _vm._v(" "), + !this.$store.state.user.hasOwnProperty("role") + ? _c("span", [ + _c( + "button", + { + staticClass: "button", + on: { + click: function($event) { + return _vm.changeMainText("Tourplan") + } + } + }, + [_vm._v("Tourplan (Beispiel)")] + ) + ]) + : this.$store.state.user.role === "GUEST" + ? _c("span", [ + _c( + "button", + { + staticClass: "button", + on: { + click: function($event) { + return _vm.changeMainText("Tourplan") + } + } + }, + [_vm._v("Tourplan (Gast)")] + ) + ]) + : this.$store.state.user.role === "MEMBER" + ? _c("span", [ + _c( + "button", + { + staticClass: "button", + on: { + click: function($event) { + return _vm.changeMainText("Tourplan") + } + } + }, + [_vm._v("Tourplan (komplett)")] + ) + ]) + : this.$store.state.user.role === "ADMIN" + ? _c("span", [ + _c( + "button", + { + staticClass: "button", + on: { + click: function($event) { + return _vm.changeMainText("Tourplan") + } + } + }, + [_vm._v("Tourplan (komplett)")] + ) + ]) + : _vm._e(), + _vm._v(" "), + _c( + "button", + { + staticClass: "button", + on: { + click: function($event) { + return _vm.changeMainText("Wetter") + } + } + }, + [_vm._v("Wetter")] + ), + _vm._v(" "), + _c( + "button", + { + staticClass: "button", + on: { + click: function($event) { + return _vm.changeMainText("Links") + } + } + }, + [_vm._v("Links")] + ), + _vm._v(" "), + _c( + "button", + { + staticClass: "button", + on: { + click: function($event) { + return _vm.changeMainText("Impressum") + } + } + }, + [_vm._v("Impressum")] + ), + _vm._v(" "), + _c( + "router-link", + { staticClass: "button", attrs: { to: { name: "Login" } } }, + [_vm._v("Log-In")] + ) + ], + 1 + ), + _vm._v(" "), + _c("p", [_vm._v(" ")]), + _vm._v(" "), + _c( + "div", + [ + _c("editor-menu-bar", { + attrs: { editor: _vm.editor }, + scopedSlots: _vm._u([ + { + key: "default", + fn: function(ref) { + var commands = ref.commands + var isActive = ref.isActive + return [ + _c("div", { staticClass: "menubar" }, [ + _c( + "button", + { + class: { "is-active": isActive.bold() }, + on: { click: commands.bold } + }, + [ + _vm._v( + "\n Bold\n " + ) + ] + ), + _vm._v(" "), + _c( + "button", + { + class: { "is-active": isActive.underline() }, + on: { click: commands.bold } + }, + [ + _vm._v( + "\n Underline\n " + ) + ] + ) + ]) + ] + } + } + ]) + }), + _vm._v(" "), + _c("editor-content", { attrs: { editor: _vm.editor } }) + ], + 1 + ) + ]) +} +var staticRenderFns = [] +render._withStripped = true + + + /***/ }), /***/ "./node_modules/vue-loader/lib/loaders/templateLoader.js?!./node_modules/vue-loader/lib/index.js?!./resources/js/views/Main.vue?vue&type=template&id=2ad93e50&": @@ -2816,51 +31200,22 @@ var render = function() { "router-link", { staticClass: "button", attrs: { to: { name: "Login" } } }, [_vm._v("Log-In")] - ), - _vm._v(" "), - this.$store.state.user.role === "ADMIN" - ? _c("span", [ - _c("button", { staticClass: "button" }, [ - _vm._v("Administration") - ]) - ]) - : _vm._e() + ) ], 1 ), _vm._v(" "), _c("p", [_vm._v(" ")]), _vm._v(" "), - _vm._m(0) - ]) -} -var staticRenderFns = [ - function() { - var _vm = this - var _h = _vm.$createElement - var _c = _vm._self._c || _h - return _c("div", [ + _c("div", [ + _vm._m(0), + _vm._v(" "), _c( "p", - { - staticStyle: { "text-align": "center" }, - attrs: { id: "main", visible: "true" } - }, + { staticStyle: { "text-align": "center" }, attrs: { visible: "true" } }, [ - _vm._v("Das alte Problem: Die Sonne scheint und Dein Motorrad ruft,"), - _c("br"), _vm._v( - "\n doch alle Deine Freunde sind plötzlich verhindert." - ), - _c("br"), - _c("br"), - _vm._v("\n Die Idee!!"), - _c("br"), - _c("br"), - _vm._v("\n Selber anrufen und angerufen werden."), - _c("br"), - _vm._v( - "\n Einmal im Jahr erhältst Du eine Liste aller IG-Mitglieder inkl. Telefonnummern." + " Einmal im Jahr erhältst Du eine Liste aller IG-Mitglieder\n inkl. Telefonnummern." ), _c("br"), _vm._v( @@ -2868,7 +31223,7 @@ var staticRenderFns = [ ), _c("br"), _vm._v( - "\n abgestimmt, ca: März, Juni und September (Saisonstart, -mitte, -ende). Für Eure (Urlaubs) Planung und" + "\n abgestimmt, ca: März, Juni und September (Saisonstart, -mitte, -ende). Für Eure (Urlaubs) Planung\n und" ), _c("br"), _vm._v( @@ -2876,7 +31231,7 @@ var staticRenderFns = [ ), _c("br"), _vm._v( - "\n Tourenkalender für das nächste Jahr für Euch bereit. Zusätzlich eröffnet Dir die Liste die Möglichkeit zur" + "\n Tourenkalender für das nächste Jahr für Euch bereit. Zusätzlich eröffnet Dir die Liste die Möglichkeit\n zur" ), _c("br"), _vm._v( @@ -2904,30 +31259,71 @@ var staticRenderFns = [ ), _c("br"), _vm._v( - "\n Stammtisch Düsseldorf: Wir treffen uns jeden 2. Mittwoch im Monat ab ca. 19 Uhr in der" + "\n Stammtisch Düsseldorf: Wir treffen uns jeden 2. Mittwoch im Monat ab ca. 19 Uhr in:" ), _c("br"), - _vm._v( - "\n Trattoria and Bar Antonio, Roßstr. 87, 40476 Düsseldorf-Derendorf, Tel.: 0211/43637525." - ), - _c("br"), - _vm._v( - "\n Stadtplan und Anfahrt mit öffentlichen Verkehrsmitteln findet ihr unter:" - ), + _vm._v("\n Tannenbaum Düsseldorf:"), _c("br"), _vm._v(" "), - _c("a", { attrs: { href: "http://www.douro-restaurant.de/" } }, [ - _vm._v("http://www.douro-restaurant.de/") - ]), - _vm._v(". Das Douro befindet sich direkt neben der Kirche."), + _c("br"), + _vm._v(" "), + _c( + "a", + { attrs: { href: "https://www.tannenbaum-duesseldorf.de/" } }, + [_vm._v("https://www.tannenbaum-duesseldorf.de/")] + ), + _vm._v( + ". Das Douro befindet sich\n direkt neben der Kirche." + ), _c("br"), _vm._v( "\n Parkmöglichkeiten sind im Umkreis um den Italiener genügend vorhanden." ), - _c("br") + _c("br"), + _vm._v(" "), + this.$store.state.user.role === "ADMIN" + ? _c("span", [ + _c("br"), + _c( + "button", + { staticClass: "button", on: { click: _vm.editPage } }, + [_vm._v("Text bearbeiten")] + ) + ]) + : _vm._e() ] ) ]) + ]) +} +var staticRenderFns = [ + function() { + var _vm = this + var _h = _vm.$createElement + var _c = _vm._self._c || _h + return _c( + "p", + { + staticStyle: { "text-align": "center" }, + attrs: { id: "main", visible: "true" } + }, + [ + _vm._v( + "Das alte Problem: Die Sonne scheint und Dein Motorrad\n ruft," + ), + _c("br"), + _vm._v( + "\n doch alle Deine Freunde sind plötzlich verhindert." + ), + _c("br"), + _c("br"), + _vm._v("\n Die Idee!!"), + _c("br"), + _c("br"), + _vm._v("\n Selber anrufen und angerufen werden."), + _c("br") + ] + ) } ] render._withStripped = true @@ -19381,6 +47777,157 @@ var index_esm = { /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js"))) +/***/ }), + +/***/ "./node_modules/w3c-keyname/index.es.js": +/*!**********************************************!*\ + !*** ./node_modules/w3c-keyname/index.es.js ***! + \**********************************************/ +/*! exports provided: default, base, keyName, shift */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "base", function() { return base_1; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "keyName", function() { return keyName; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "shift", function() { return shift_1; }); +var base = { + 8: "Backspace", + 9: "Tab", + 10: "Enter", + 12: "NumLock", + 13: "Enter", + 16: "Shift", + 17: "Control", + 18: "Alt", + 20: "CapsLock", + 27: "Escape", + 32: " ", + 33: "PageUp", + 34: "PageDown", + 35: "End", + 36: "Home", + 37: "ArrowLeft", + 38: "ArrowUp", + 39: "ArrowRight", + 40: "ArrowDown", + 44: "PrintScreen", + 45: "Insert", + 46: "Delete", + 59: ";", + 61: "=", + 91: "Meta", + 92: "Meta", + 106: "*", + 107: "+", + 108: ",", + 109: "-", + 110: ".", + 111: "/", + 144: "NumLock", + 145: "ScrollLock", + 160: "Shift", + 161: "Shift", + 162: "Control", + 163: "Control", + 164: "Alt", + 165: "Alt", + 173: "-", + 186: ";", + 187: "=", + 188: ",", + 189: "-", + 190: ".", + 191: "/", + 192: "`", + 219: "[", + 220: "\\", + 221: "]", + 222: "'", + 229: "q" +}; +var base_1 = base; + +var shift = { + 48: ")", + 49: "!", + 50: "@", + 51: "#", + 52: "$", + 53: "%", + 54: "^", + 55: "&", + 56: "*", + 57: "(", + 59: ";", + 61: "+", + 173: "_", + 186: ":", + 187: "+", + 188: "<", + 189: "_", + 190: ">", + 191: "?", + 192: "~", + 219: "{", + 220: "|", + 221: "}", + 222: "\"", + 229: "Q" +}; +var shift_1 = shift; + +var chrome = typeof navigator != "undefined" && /Chrome\/(\d+)/.exec(navigator.userAgent); +var safari = typeof navigator != "undefined" && /Apple Computer/.test(navigator.vendor); +var gecko = typeof navigator != "undefined" && /Gecko\/\d+/.test(navigator.userAgent); +var mac = typeof navigator != "undefined" && /Mac/.test(navigator.platform); +var ie = typeof navigator != "undefined" && /MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent); +var brokenModifierNames = chrome && (mac || +chrome[1] < 57) || gecko && mac; + +// Fill in the digit keys +for (var i = 0; i < 10; i++) base[48 + i] = base[96 + i] = String(i); + +// The function keys +for (var i = 1; i <= 24; i++) base[i + 111] = "F" + i; + +// And the alphabetic keys +for (var i = 65; i <= 90; i++) { + base[i] = String.fromCharCode(i + 32); + shift[i] = String.fromCharCode(i); +} + +// For each code that doesn't have a shift-equivalent, copy the base name +for (var code in base) if (!shift.hasOwnProperty(code)) shift[code] = base[code]; + +var keyName = function(event) { + // Don't trust event.key in Chrome when there are modifiers until + // they fix https://bugs.chromium.org/p/chromium/issues/detail?id=633838 + var ignoreKey = brokenModifierNames && (event.ctrlKey || event.altKey || event.metaKey) || + (safari || ie) && event.shiftKey && event.key && event.key.length == 1; + var name = (!ignoreKey && event.key) || + (event.shiftKey ? shift : base)[event.keyCode] || + event.key || "Unidentified"; + // Edge sometimes produces wrong names (Issue #3) + if (name == "Esc") name = "Escape"; + if (name == "Del") name = "Delete"; + // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8860571/ + if (name == "Left") name = "ArrowLeft"; + if (name == "Up") name = "ArrowUp"; + if (name == "Right") name = "ArrowRight"; + if (name == "Down") name = "ArrowDown"; + return name +}; + +var w3cKeyname = { + base: base_1, + shift: shift_1, + keyName: keyName +}; + +/* harmony default export */ __webpack_exports__["default"] = (w3cKeyname); + + + /***/ }), /***/ "./node_modules/webpack/buildin/global.js": @@ -19427,8 +47974,9 @@ __webpack_require__.r(__webpack_exports__); /* harmony import */ var vue__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(vue__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var vue_router__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! vue-router */ "./node_modules/vue-router/dist/vue-router.esm.js"); /* harmony import */ var vuex__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! vuex */ "./node_modules/vuex/dist/vuex.esm.js"); -/* harmony import */ var _routes_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./routes.js */ "./resources/js/routes.js"); -/* harmony import */ var _store_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./store.js */ "./resources/js/store.js"); +/* harmony import */ var tiptap__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! tiptap */ "./node_modules/tiptap/dist/tiptap.esm.js"); +/* harmony import */ var _routes_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./routes.js */ "./resources/js/routes.js"); +/* harmony import */ var _store_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./store.js */ "./resources/js/store.js"); /** * First, we will load all of this project's Javascript utilities and other * dependencies. Then, we will be ready to develop a robust and powerful @@ -19437,19 +47985,20 @@ __webpack_require__.r(__webpack_exports__); + window.Vue = __webpack_require__(/*! vue */ "./node_modules/vue/dist/vue.common.js"); window.axios = __webpack_require__(/*! axios */ "./node_modules/axios/index.js"); var router = new vue_router__WEBPACK_IMPORTED_MODULE_1__["default"]({ mode: 'history', - routes: _routes_js__WEBPACK_IMPORTED_MODULE_3__["routes"] + routes: _routes_js__WEBPACK_IMPORTED_MODULE_4__["routes"] }); vue__WEBPACK_IMPORTED_MODULE_0___default.a.use(vue_router__WEBPACK_IMPORTED_MODULE_1__["default"]); // Activate plugin new vue__WEBPACK_IMPORTED_MODULE_0___default.a({ el: '#root', - store: _store_js__WEBPACK_IMPORTED_MODULE_4__["store"], + store: _store_js__WEBPACK_IMPORTED_MODULE_5__["store"], router: router }); @@ -19468,9 +48017,11 @@ __webpack_require__.r(__webpack_exports__); /* harmony import */ var _views_auth_Login__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./views/auth/Login */ "./resources/js/views/auth/Login.vue"); /* harmony import */ var _views_auth_Register__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./views/auth/Register */ "./resources/js/views/auth/Register.vue"); /* harmony import */ var _views_Main__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./views/Main */ "./resources/js/views/Main.vue"); -/* harmony import */ var vue__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! vue */ "./node_modules/vue/dist/vue.common.js"); -/* harmony import */ var vue__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(vue__WEBPACK_IMPORTED_MODULE_3__); -/* harmony import */ var vue_router__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! vue-router */ "./node_modules/vue-router/dist/vue-router.esm.js"); +/* harmony import */ var _views_EditPage__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./views/EditPage */ "./resources/js/views/EditPage.vue"); +/* harmony import */ var vue__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! vue */ "./node_modules/vue/dist/vue.common.js"); +/* harmony import */ var vue__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(vue__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var vue_router__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! vue-router */ "./node_modules/vue-router/dist/vue-router.esm.js"); + @@ -19488,8 +48039,12 @@ var routes = [{ path: '/register', name: 'register', component: _views_auth_Register__WEBPACK_IMPORTED_MODULE_1__["default"] +}, { + path: '/edit_page', + name: 'edit_page', + component: _views_EditPage__WEBPACK_IMPORTED_MODULE_3__["default"] }]; -vue__WEBPACK_IMPORTED_MODULE_3___default.a.use(vue_router__WEBPACK_IMPORTED_MODULE_4__["default"]); +vue__WEBPACK_IMPORTED_MODULE_4___default.a.use(vue_router__WEBPACK_IMPORTED_MODULE_5__["default"]); /***/ }), @@ -19516,6 +48071,75 @@ var store = new vuex__WEBPACK_IMPORTED_MODULE_1__["default"].Store({ } }); +/***/ }), + +/***/ "./resources/js/views/EditPage.vue": +/*!*****************************************!*\ + !*** ./resources/js/views/EditPage.vue ***! + \*****************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _EditPage_vue_vue_type_template_id_15baaf58___WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./EditPage.vue?vue&type=template&id=15baaf58& */ "./resources/js/views/EditPage.vue?vue&type=template&id=15baaf58&"); +/* harmony import */ var _EditPage_vue_vue_type_script_lang_js___WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./EditPage.vue?vue&type=script&lang=js& */ "./resources/js/views/EditPage.vue?vue&type=script&lang=js&"); +/* empty/unused harmony star reexport *//* harmony import */ var _node_modules_vue_loader_lib_runtime_componentNormalizer_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../../node_modules/vue-loader/lib/runtime/componentNormalizer.js */ "./node_modules/vue-loader/lib/runtime/componentNormalizer.js"); + + + + + +/* normalize component */ + +var component = Object(_node_modules_vue_loader_lib_runtime_componentNormalizer_js__WEBPACK_IMPORTED_MODULE_2__["default"])( + _EditPage_vue_vue_type_script_lang_js___WEBPACK_IMPORTED_MODULE_1__["default"], + _EditPage_vue_vue_type_template_id_15baaf58___WEBPACK_IMPORTED_MODULE_0__["render"], + _EditPage_vue_vue_type_template_id_15baaf58___WEBPACK_IMPORTED_MODULE_0__["staticRenderFns"], + false, + null, + null, + null + +) + +/* hot reload */ +if (false) { var api; } +component.options.__file = "resources/js/views/EditPage.vue" +/* harmony default export */ __webpack_exports__["default"] = (component.exports); + +/***/ }), + +/***/ "./resources/js/views/EditPage.vue?vue&type=script&lang=js&": +/*!******************************************************************!*\ + !*** ./resources/js/views/EditPage.vue?vue&type=script&lang=js& ***! + \******************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _node_modules_babel_loader_lib_index_js_ref_4_0_node_modules_vue_loader_lib_index_js_vue_loader_options_EditPage_vue_vue_type_script_lang_js___WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! -!../../../node_modules/babel-loader/lib??ref--4-0!../../../node_modules/vue-loader/lib??vue-loader-options!./EditPage.vue?vue&type=script&lang=js& */ "./node_modules/babel-loader/lib/index.js?!./node_modules/vue-loader/lib/index.js?!./resources/js/views/EditPage.vue?vue&type=script&lang=js&"); +/* empty/unused harmony star reexport */ /* harmony default export */ __webpack_exports__["default"] = (_node_modules_babel_loader_lib_index_js_ref_4_0_node_modules_vue_loader_lib_index_js_vue_loader_options_EditPage_vue_vue_type_script_lang_js___WEBPACK_IMPORTED_MODULE_0__["default"]); + +/***/ }), + +/***/ "./resources/js/views/EditPage.vue?vue&type=template&id=15baaf58&": +/*!************************************************************************!*\ + !*** ./resources/js/views/EditPage.vue?vue&type=template&id=15baaf58& ***! + \************************************************************************/ +/*! exports provided: render, staticRenderFns */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _node_modules_vue_loader_lib_loaders_templateLoader_js_vue_loader_options_node_modules_vue_loader_lib_index_js_vue_loader_options_EditPage_vue_vue_type_template_id_15baaf58___WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! -!../../../node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!../../../node_modules/vue-loader/lib??vue-loader-options!./EditPage.vue?vue&type=template&id=15baaf58& */ "./node_modules/vue-loader/lib/loaders/templateLoader.js?!./node_modules/vue-loader/lib/index.js?!./resources/js/views/EditPage.vue?vue&type=template&id=15baaf58&"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "render", function() { return _node_modules_vue_loader_lib_loaders_templateLoader_js_vue_loader_options_node_modules_vue_loader_lib_index_js_vue_loader_options_EditPage_vue_vue_type_template_id_15baaf58___WEBPACK_IMPORTED_MODULE_0__["render"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "staticRenderFns", function() { return _node_modules_vue_loader_lib_loaders_templateLoader_js_vue_loader_options_node_modules_vue_loader_lib_index_js_vue_loader_options_EditPage_vue_vue_type_template_id_15baaf58___WEBPACK_IMPORTED_MODULE_0__["staticRenderFns"]; }); + + + /***/ }), /***/ "./resources/js/views/Main.vue": diff --git a/motorradig/resources/js/app.js b/motorradig/resources/js/app.js index 5784c26..5e275b1 100644 --- a/motorradig/resources/js/app.js +++ b/motorradig/resources/js/app.js @@ -7,10 +7,12 @@ import Vue from 'vue'; import VueRouter from 'vue-router'; import Vuex from 'vuex'; +import { Editor } from 'tiptap' window.Vue=require('vue'); window.axios=require('axios'); + import {routes} from './routes.js'; import {store} from './store.js'; diff --git a/motorradig/resources/js/routes.js b/motorradig/resources/js/routes.js index cf58a45..90b31b6 100644 --- a/motorradig/resources/js/routes.js +++ b/motorradig/resources/js/routes.js @@ -1,6 +1,7 @@ import Login from "./views/auth/Login"; import Register from "./views/auth/Register"; import Main from "./views/Main"; +import EditPage from "./views/EditPage"; import Vue from 'vue'; import VueRouter from "vue-router"; @@ -9,6 +10,7 @@ export const routes= [ { path:'', name : 'main', component: Main }, { path:'/login', name : 'Login', component: Login }, { path:'/register', name : 'register', component: Register }, + { path:'/edit_page', name : 'edit_page', component: EditPage }, ]; Vue.use(VueRouter); diff --git a/motorradig/resources/js/views/EditPage.vue b/motorradig/resources/js/views/EditPage.vue new file mode 100644 index 0000000..6737b80 --- /dev/null +++ b/motorradig/resources/js/views/EditPage.vue @@ -0,0 +1,131 @@ + + + diff --git a/motorradig/resources/js/views/Main.vue b/motorradig/resources/js/views/Main.vue index 48eb325..4a60699 100644 --- a/motorradig/resources/js/views/Main.vue +++ b/motorradig/resources/js/views/Main.vue @@ -21,21 +21,26 @@ Log-In - +

       

      -

      Das alte Problem: Die Sonne scheint und Dein Motorrad ruft,
      +

      Das alte Problem: Die Sonne scheint und Dein Motorrad + ruft,
      doch alle Deine Freunde sind plötzlich verhindert.

      Die Idee!!

      Selber anrufen und angerufen werden.
      - Einmal im Jahr erhältst Du eine Liste aller IG-Mitglieder inkl. Telefonnummern.
      +

      +

      Einmal im Jahr erhältst Du eine Liste aller IG-Mitglieder + inkl. Telefonnummern.
      Die Erscheinungstermine unserer Mitgliederliste + News sind natürlich auf die Motorrad-Saison
      - abgestimmt, ca: März, Juni und September (Saisonstart, -mitte, -ende). Für Eure (Urlaubs) Planung und
      + abgestimmt, ca: März, Juni und September (Saisonstart, -mitte, -ende). Für Eure (Urlaubs) Planung + und
      damit der Winter nicht zu lange wird, halten wir in der November- Dezember-Ausgabe schon den
      - Tourenkalender für das nächste Jahr für Euch bereit. Zusätzlich eröffnet Dir die Liste die Möglichkeit zur
      + Tourenkalender für das nächste Jahr für Euch bereit. Zusätzlich eröffnet Dir die Liste die Möglichkeit + zur
      Teilnahme an einem regelmäßigen Stammtisch, gemeinsame Ausfahrten an Wochenenden, einer
      Urlaubsbörse sowie Saisonauftakt- und Jahrestreffen. Eigeninitiative ist hierbei erwünscht.
      @@ -43,11 +48,14 @@ müssen wir einmal jährlich einen Selbstkostenbeitrag in Höhe von 20,- EUR erheben.
      Diese Kosten entstehen durch Werbung, Porto, Erfassungsmaterialien etc..
      Hast Du jetzt immer noch eine positive Einstellung zu dieser Idee? Dann nichts wie hin.
      - Stammtisch Düsseldorf: Wir treffen uns jeden 2. Mittwoch im Monat ab ca. 19 Uhr in der
      - Trattoria and Bar Antonio, Roßstr. 87, 40476 Düsseldorf-Derendorf, Tel.: 0211/43637525.
      - Stadtplan und Anfahrt mit öffentlichen Verkehrsmitteln findet ihr unter:
      - http://www.douro-restaurant.de/. Das Douro befindet sich direkt neben der Kirche.
      + Stammtisch Düsseldorf: Wir treffen uns jeden 2. Mittwoch im Monat ab ca. 19 Uhr in:
      + Tannenbaum Düsseldorf:
      +
      + https://www.tannenbaum-duesseldorf.de/. Das Douro befindet sich + direkt neben der Kirche.
      Parkmöglichkeiten sind im Umkreis um den Italiener genügend vorhanden.
      + +

      @@ -85,6 +93,9 @@ console.log("Logout unsuccessful."); console.log(error); }) + }, + editPage() { + this.$router.push('/edit_page'); } } ,
      ..