/*! * * Super simple wysiwyg editor v0.8.15 * https://summernote.org * * * Copyright 2013- Alan Hong. and other contributors * summernote may be freely distributed under the MIT license. * * Date: 2020-01-04T11:44Z * */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("jquery")); else if(typeof define === 'function' && define.amd) define(["jquery"], factory); else { var a = typeof exports === 'object' ? factory(require("jquery")) : factory(root["jQuery"]); for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i]; } })(window, function(__WEBPACK_EXTERNAL_MODULE__0__) { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { 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 = 51); /******/ }) /************************************************************************/ /******/ ({ /***/ 0: /***/ (function(module, exports) { module.exports = __WEBPACK_EXTERNAL_MODULE__0__; /***/ }), /***/ 1: /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0); /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_0__); class Renderer { constructor(markup, children, options, callback) { this.markup = markup; this.children = children; this.options = options; this.callback = callback; } render($parent) { const $node = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this.markup); if (this.options && this.options.contents) { $node.html(this.options.contents); } if (this.options && this.options.className) { $node.addClass(this.options.className); } if (this.options && this.options.data) { jquery__WEBPACK_IMPORTED_MODULE_0___default.a.each(this.options.data, (k, v) => { $node.attr('data-' + k, v); }); } if (this.options && this.options.click) { $node.on('click', this.options.click); } if (this.children) { const $container = $node.find('.note-children-container'); this.children.forEach(child => { child.render($container.length ? $container : $node); }); } if (this.callback) { this.callback($node, this.options); } if (this.options && this.options.callback) { this.options.callback($node); } if ($parent) { $parent.append($node); } return $node; } } /* harmony default export */ __webpack_exports__["a"] = ({ create: (markup, callback) => { return function () { const options = typeof arguments[1] === 'object' ? arguments[1] : arguments[0]; let children = Array.isArray(arguments[0]) ? arguments[0] : []; if (options && options.children) { children = options.children; } return new Renderer(markup, children, options, callback); }; } }); /***/ }), /***/ 2: /***/ (function(module, exports) { /* WEBPACK VAR INJECTION */(function(__webpack_amd_options__) {/* globals __webpack_amd_options__ */ module.exports = __webpack_amd_options__; /* WEBPACK VAR INJECTION */}.call(this, {})) /***/ }), /***/ 3: /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; // EXTERNAL MODULE: external {"root":"jQuery","commonjs2":"jquery","commonjs":"jquery","amd":"jquery"} var external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_ = __webpack_require__(0); var external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default = /*#__PURE__*/__webpack_require__.n(external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_); // CONCATENATED MODULE: ./src/js/base/summernote-en-US.js external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.summernote = external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.summernote || { lang: {} }; external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.extend(external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.summernote.lang, { 'en-US': { font: { bold: 'Bold', italic: 'Italic', underline: 'Underline', clear: 'Remove Font Style', height: 'Line Height', name: 'Font Family', strikethrough: 'Strikethrough', subscript: 'Subscript', superscript: 'Superscript', size: 'Font Size', sizeunit: 'Font Size Unit' }, image: { image: 'Picture', insert: 'Insert Image', resizeFull: 'Resize full', resizeHalf: 'Resize half', resizeQuarter: 'Resize quarter', resizeNone: 'Original size', floatLeft: 'Float Left', floatRight: 'Float Right', floatNone: 'Remove float', shapeRounded: 'Shape: Rounded', shapeCircle: 'Shape: Circle', shapeThumbnail: 'Shape: Thumbnail', shapeNone: 'Shape: None', dragImageHere: 'Drag image or text here', dropImage: 'Drop image or Text', selectFromFiles: 'Select from files', maximumFileSize: 'Maximum file size', maximumFileSizeError: 'Maximum file size exceeded.', url: 'Image URL', remove: 'Remove Image', original: 'Original' }, video: { video: 'Video', videoLink: 'Video Link', insert: 'Insert Video', url: 'Video URL', providers: '(YouTube, Vimeo, Vine, Instagram, DailyMotion or Youku)' }, link: { link: 'Link', insert: 'Insert Link', unlink: 'Unlink', edit: 'Edit', textToDisplay: 'Text to display', url: 'To what URL should this link go?', openInNewWindow: 'Open in new window', useProtocol: 'Use default protocol' }, table: { table: 'Table', addRowAbove: 'Add row above', addRowBelow: 'Add row below', addColLeft: 'Add column left', addColRight: 'Add column right', delRow: 'Delete row', delCol: 'Delete column', delTable: 'Delete table' }, hr: { insert: 'Insert Horizontal Rule' }, style: { style: 'Style', p: 'Normal', blockquote: 'Quote', pre: 'Code', h1: 'Header 1', h2: 'Header 2', h3: 'Header 3', h4: 'Header 4', h5: 'Header 5', h6: 'Header 6' }, lists: { unordered: 'Unordered list', ordered: 'Ordered list' }, options: { help: 'Help', fullscreen: 'Full Screen', codeview: 'Code View' }, paragraph: { paragraph: 'Paragraph', outdent: 'Outdent', indent: 'Indent', left: 'Align left', center: 'Align center', right: 'Align right', justify: 'Justify full' }, color: { recent: 'Recent Color', more: 'More Color', background: 'Background Color', foreground: 'Text Color', transparent: 'Transparent', setTransparent: 'Set transparent', reset: 'Reset', resetToDefault: 'Reset to default', cpSelect: 'Select' }, shortcut: { shortcuts: 'Keyboard shortcuts', close: 'Close', textFormatting: 'Text formatting', action: 'Action', paragraphFormatting: 'Paragraph formatting', documentStyle: 'Document Style', extraKeys: 'Extra keys' }, help: { 'insertParagraph': 'Insert Paragraph', 'undo': 'Undoes the last command', 'redo': 'Redoes the last command', 'tab': 'Tab', 'untab': 'Untab', 'bold': 'Set a bold style', 'italic': 'Set a italic style', 'underline': 'Set a underline style', 'strikethrough': 'Set a strikethrough style', 'removeFormat': 'Clean a style', 'justifyLeft': 'Set left align', 'justifyCenter': 'Set center align', 'justifyRight': 'Set right align', 'justifyFull': 'Set full align', 'insertUnorderedList': 'Toggle unordered list', 'insertOrderedList': 'Toggle ordered list', 'outdent': 'Outdent on current paragraph', 'indent': 'Indent on current paragraph', 'formatPara': 'Change current block\'s format as a paragraph(P tag)', 'formatH1': 'Change current block\'s format as H1', 'formatH2': 'Change current block\'s format as H2', 'formatH3': 'Change current block\'s format as H3', 'formatH4': 'Change current block\'s format as H4', 'formatH5': 'Change current block\'s format as H5', 'formatH6': 'Change current block\'s format as H6', 'insertHorizontalRule': 'Insert horizontal rule', 'linkDialog.show': 'Show Link Dialog' }, history: { undo: 'Undo', redo: 'Redo' }, specialChar: { specialChar: 'SPECIAL CHARACTERS', select: 'Select Special characters' }, output: { noSelection: 'No Selection Made!' } } }); // CONCATENATED MODULE: ./src/js/base/core/env.js const isSupportAmd = typeof define === 'function' && __webpack_require__(2); // eslint-disable-line /** * returns whether font is installed or not. * * @param {String} fontName * @return {Boolean} */ const genericFontFamilies = ['sans-serif', 'serif', 'monospace', 'cursive', 'fantasy']; function validFontName(fontName) { return external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.inArray(fontName.toLowerCase(), genericFontFamilies) === -1 ? `'${fontName}'` : fontName; } function isFontInstalled(fontName) { const testFontName = fontName === 'Comic Sans MS' ? 'Courier New' : 'Comic Sans MS'; const testText = 'mmmmmmmmmmwwwww'; const testSize = '200px'; var canvas = document.createElement('canvas'); var context = canvas.getContext('2d'); context.font = testSize + " '" + testFontName + "'"; const originalWidth = context.measureText(testText).width; context.font = testSize + ' ' + validFontName(fontName) + ', "' + testFontName + '"'; const width = context.measureText(testText).width; return originalWidth !== width; } const userAgent = navigator.userAgent; const isMSIE = /MSIE|Trident/i.test(userAgent); let browserVersion; if (isMSIE) { let matches = /MSIE (\d+[.]\d+)/.exec(userAgent); if (matches) { browserVersion = parseFloat(matches[1]); } matches = /Trident\/.*rv:([0-9]{1,}[.0-9]{0,})/.exec(userAgent); if (matches) { browserVersion = parseFloat(matches[1]); } } const isEdge = /Edge\/\d+/.test(userAgent); let hasCodeMirror = !!window.CodeMirror; const isSupportTouch = 'ontouchstart' in window || navigator.MaxTouchPoints > 0 || navigator.msMaxTouchPoints > 0; // [workaround] IE doesn't have input events for contentEditable // - see: https://goo.gl/4bfIvA const inputEventName = isMSIE ? 'DOMCharacterDataModified DOMSubtreeModified DOMNodeInserted' : 'input'; /** * @class core.env * * Object which check platform and agent * * @singleton * @alternateClassName env */ /* harmony default export */ var env = ({ isMac: navigator.appVersion.indexOf('Mac') > -1, isMSIE, isEdge, isFF: !isEdge && /firefox/i.test(userAgent), isPhantom: /PhantomJS/i.test(userAgent), isWebkit: !isEdge && /webkit/i.test(userAgent), isChrome: !isEdge && /chrome/i.test(userAgent), isSafari: !isEdge && /safari/i.test(userAgent) && !/chrome/i.test(userAgent), browserVersion, jqueryVersion: parseFloat(external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.fn.jquery), isSupportAmd, isSupportTouch, hasCodeMirror, isFontInstalled, isW3CRangeSupport: !!document.createRange, inputEventName, genericFontFamilies, validFontName }); // CONCATENATED MODULE: ./src/js/base/core/func.js /** * @class core.func * * func utils (for high-order func's arg) * * @singleton * @alternateClassName func */ function eq(itemA) { return function (itemB) { return itemA === itemB; }; } function eq2(itemA, itemB) { return itemA === itemB; } function peq2(propName) { return function (itemA, itemB) { return itemA[propName] === itemB[propName]; }; } function ok() { return true; } function fail() { return false; } function not(f) { return function () { return !f.apply(f, arguments); }; } function and(fA, fB) { return function (item) { return fA(item) && fB(item); }; } function func_self(a) { return a; } function invoke(obj, method) { return function () { return obj[method].apply(obj, arguments); }; } let idCounter = 0; /** * reset globally-unique id * */ function resetUniqueId() { idCounter = 0; } /** * generate a globally-unique id * * @param {String} [prefix] */ function uniqueId(prefix) { const id = ++idCounter + ''; return prefix ? prefix + id : id; } /** * returns bnd (bounds) from rect * * - IE Compatibility Issue: http://goo.gl/sRLOAo * - Scroll Issue: http://goo.gl/sNjUc * * @param {Rect} rect * @return {Object} bounds * @return {Number} bounds.top * @return {Number} bounds.left * @return {Number} bounds.width * @return {Number} bounds.height */ function rect2bnd(rect) { const $document = external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default()(document); return { top: rect.top + $document.scrollTop(), left: rect.left + $document.scrollLeft(), width: rect.right - rect.left, height: rect.bottom - rect.top }; } /** * returns a copy of the object where the keys have become the values and the values the keys. * @param {Object} obj * @return {Object} */ function invertObject(obj) { const inverted = {}; for (const key in obj) { if (obj.hasOwnProperty(key)) { inverted[obj[key]] = key; } } return inverted; } /** * @param {String} namespace * @param {String} [prefix] * @return {String} */ function namespaceToCamel(namespace, prefix) { prefix = prefix || ''; return prefix + namespace.split('.').map(function (name) { return name.substring(0, 1).toUpperCase() + name.substring(1); }).join(''); } /** * Returns a function, that, as long as it continues to be invoked, will not * be triggered. The function will be called after it stops being called for * N milliseconds. If `immediate` is passed, trigger the function on the * leading edge, instead of the trailing. * @param {Function} func * @param {Number} wait * @param {Boolean} immediate * @return {Function} */ function debounce(func, wait, immediate) { let timeout; return function () { const context = this; const args = arguments; const later = () => { timeout = null; if (!immediate) { func.apply(context, args); } }; const callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) { func.apply(context, args); } }; } /** * * @param {String} url * @return {Boolean} */ function isValidUrl(url) { const expression = /[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/gi; return expression.test(url); } /* harmony default export */ var func = ({ eq, eq2, peq2, ok, fail, self: func_self, not, and, invoke, resetUniqueId, uniqueId, rect2bnd, invertObject, namespaceToCamel, debounce, isValidUrl }); // CONCATENATED MODULE: ./src/js/base/core/lists.js /** * returns the first item of an array. * * @param {Array} array */ function lists_head(array) { return array[0]; } /** * returns the last item of an array. * * @param {Array} array */ function lists_last(array) { return array[array.length - 1]; } /** * returns everything but the last entry of the array. * * @param {Array} array */ function initial(array) { return array.slice(0, array.length - 1); } /** * returns the rest of the items in an array. * * @param {Array} array */ function tail(array) { return array.slice(1); } /** * returns item of array */ function find(array, pred) { for (let idx = 0, len = array.length; idx < len; idx++) { const item = array[idx]; if (pred(item)) { return item; } } } /** * returns true if all of the values in the array pass the predicate truth test. */ function lists_all(array, pred) { for (let idx = 0, len = array.length; idx < len; idx++) { if (!pred(array[idx])) { return false; } } return true; } /** * returns true if the value is present in the list. */ function contains(array, item) { if (array && array.length && item) { if (array.indexOf) { return array.indexOf(item) !== -1; } else if (array.contains) { // `DOMTokenList` doesn't implement `.indexOf`, but it implements `.contains` return array.contains(item); } } return false; } /** * get sum from a list * * @param {Array} array - array * @param {Function} fn - iterator */ function sum(array, fn) { fn = fn || func.self; return array.reduce(function (memo, v) { return memo + fn(v); }, 0); } /** * returns a copy of the collection with array type. * @param {Collection} collection - collection eg) node.childNodes, ... */ function from(collection) { const result = []; const length = collection.length; let idx = -1; while (++idx < length) { result[idx] = collection[idx]; } return result; } /** * returns whether list is empty or not */ function isEmpty(array) { return !array || !array.length; } /** * cluster elements by predicate function. * * @param {Array} array - array * @param {Function} fn - predicate function for cluster rule * @param {Array[]} */ function clusterBy(array, fn) { if (!array.length) { return []; } const aTail = tail(array); return aTail.reduce(function (memo, v) { const aLast = lists_last(memo); if (fn(lists_last(aLast), v)) { aLast[aLast.length] = v; } else { memo[memo.length] = [v]; } return memo; }, [[lists_head(array)]]); } /** * returns a copy of the array with all false values removed * * @param {Array} array - array * @param {Function} fn - predicate function for cluster rule */ function compact(array) { const aResult = []; for (let idx = 0, len = array.length; idx < len; idx++) { if (array[idx]) { aResult.push(array[idx]); } } return aResult; } /** * produces a duplicate-free version of the array * * @param {Array} array */ function unique(array) { const results = []; for (let idx = 0, len = array.length; idx < len; idx++) { if (!contains(results, array[idx])) { results.push(array[idx]); } } return results; } /** * returns next item. * @param {Array} array */ function lists_next(array, item) { if (array && array.length && item) { const idx = array.indexOf(item); return idx === -1 ? null : array[idx + 1]; } return null; } /** * returns prev item. * @param {Array} array */ function prev(array, item) { if (array && array.length && item) { const idx = array.indexOf(item); return idx === -1 ? null : array[idx - 1]; } return null; } /** * @class core.list * * list utils * * @singleton * @alternateClassName list */ /* harmony default export */ var lists = ({ head: lists_head, last: lists_last, initial, tail, prev, next: lists_next, find, contains, all: lists_all, sum, from, isEmpty, clusterBy, compact, unique }); // CONCATENATED MODULE: ./src/js/base/core/dom.js const NBSP_CHAR = String.fromCharCode(160); const ZERO_WIDTH_NBSP_CHAR = '\ufeff'; /** * @method isEditable * * returns whether node is `note-editable` or not. * * @param {Node} node * @return {Boolean} */ function isEditable(node) { return node && external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default()(node).hasClass('note-editable'); } /** * @method isControlSizing * * returns whether node is `note-control-sizing` or not. * * @param {Node} node * @return {Boolean} */ function isControlSizing(node) { return node && external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default()(node).hasClass('note-control-sizing'); } /** * @method makePredByNodeName * * returns predicate which judge whether nodeName is same * * @param {String} nodeName * @return {Function} */ function makePredByNodeName(nodeName) { nodeName = nodeName.toUpperCase(); return function (node) { return node && node.nodeName.toUpperCase() === nodeName; }; } /** * @method isText * * * * @param {Node} node * @return {Boolean} true if node's type is text(3) */ function isText(node) { return node && node.nodeType === 3; } /** * @method isElement * * * * @param {Node} node * @return {Boolean} true if node's type is element(1) */ function isElement(node) { return node && node.nodeType === 1; } /** * ex) br, col, embed, hr, img, input, ... * @see http://www.w3.org/html/wg/drafts/html/master/syntax.html#void-elements */ function isVoid(node) { return node && /^BR|^IMG|^HR|^IFRAME|^BUTTON|^INPUT|^AUDIO|^VIDEO|^EMBED/.test(node.nodeName.toUpperCase()); } function isPara(node) { if (isEditable(node)) { return false; } // Chrome(v31.0), FF(v25.0.1) use DIV for paragraph return node && /^DIV|^P|^LI|^H[1-7]/.test(node.nodeName.toUpperCase()); } function isHeading(node) { return node && /^H[1-7]/.test(node.nodeName.toUpperCase()); } const isPre = makePredByNodeName('PRE'); const isLi = makePredByNodeName('LI'); function isPurePara(node) { return isPara(node) && !isLi(node); } const isTable = makePredByNodeName('TABLE'); const isData = makePredByNodeName('DATA'); function dom_isInline(node) { return !isBodyContainer(node) && !isList(node) && !isHr(node) && !isPara(node) && !isTable(node) && !isBlockquote(node) && !isData(node); } function isList(node) { return node && /^UL|^OL/.test(node.nodeName.toUpperCase()); } const isHr = makePredByNodeName('HR'); function dom_isCell(node) { return node && /^TD|^TH/.test(node.nodeName.toUpperCase()); } const isBlockquote = makePredByNodeName('BLOCKQUOTE'); function isBodyContainer(node) { return dom_isCell(node) || isBlockquote(node) || isEditable(node); } const isAnchor = makePredByNodeName('A'); function isParaInline(node) { return dom_isInline(node) && !!dom_ancestor(node, isPara); } function isBodyInline(node) { return dom_isInline(node) && !dom_ancestor(node, isPara); } const isBody = makePredByNodeName('BODY'); /** * returns whether nodeB is closest sibling of nodeA * * @param {Node} nodeA * @param {Node} nodeB * @return {Boolean} */ function isClosestSibling(nodeA, nodeB) { return nodeA.nextSibling === nodeB || nodeA.previousSibling === nodeB; } /** * returns array of closest siblings with node * * @param {Node} node * @param {function} [pred] - predicate function * @return {Node[]} */ function withClosestSiblings(node, pred) { pred = pred || func.ok; const siblings = []; if (node.previousSibling && pred(node.previousSibling)) { siblings.push(node.previousSibling); } siblings.push(node); if (node.nextSibling && pred(node.nextSibling)) { siblings.push(node.nextSibling); } return siblings; } /** * blank HTML for cursor position * - [workaround] old IE only works with   * - [workaround] IE11 and other browser works with bogus br */ const blankHTML = env.isMSIE && env.browserVersion < 11 ? ' ' : '
'; /** * @method nodeLength * * returns #text's text size or element's childNodes size * * @param {Node} node */ function nodeLength(node) { if (isText(node)) { return node.nodeValue.length; } if (node) { return node.childNodes.length; } return 0; } /** * returns whether deepest child node is empty or not. * * @param {Node} node * @return {Boolean} */ function deepestChildIsEmpty(node) { do { if (node.firstElementChild === null || node.firstElementChild.innerHTML === '') break; } while (node = node.firstElementChild); return dom_isEmpty(node); } /** * returns whether node is empty or not. * * @param {Node} node * @return {Boolean} */ function dom_isEmpty(node) { const len = nodeLength(node); if (len === 0) { return true; } else if (!isText(node) && len === 1 && node.innerHTML === blankHTML) { // ex)


,
return true; } else if (lists.all(node.childNodes, isText) && node.innerHTML === '') { // ex)

, return true; } return false; } /** * padding blankHTML if node is empty (for cursor position) */ function paddingBlankHTML(node) { if (!isVoid(node) && !nodeLength(node)) { node.innerHTML = blankHTML; } } /** * find nearest ancestor predicate hit * * @param {Node} node * @param {Function} pred - predicate function */ function dom_ancestor(node, pred) { while (node) { if (pred(node)) { return node; } if (isEditable(node)) { break; } node = node.parentNode; } return null; } /** * find nearest ancestor only single child blood line and predicate hit * * @param {Node} node * @param {Function} pred - predicate function */ function singleChildAncestor(node, pred) { node = node.parentNode; while (node) { if (nodeLength(node) !== 1) { break; } if (pred(node)) { return node; } if (isEditable(node)) { break; } node = node.parentNode; } return null; } /** * returns new array of ancestor nodes (until predicate hit). * * @param {Node} node * @param {Function} [optional] pred - predicate function */ function listAncestor(node, pred) { pred = pred || func.fail; const ancestors = []; dom_ancestor(node, function (el) { if (!isEditable(el)) { ancestors.push(el); } return pred(el); }); return ancestors; } /** * find farthest ancestor predicate hit */ function lastAncestor(node, pred) { const ancestors = listAncestor(node); return lists.last(ancestors.filter(pred)); } /** * returns common ancestor node between two nodes. * * @param {Node} nodeA * @param {Node} nodeB */ function commonAncestor(nodeA, nodeB) { const ancestors = listAncestor(nodeA); for (let n = nodeB; n; n = n.parentNode) { if (ancestors.indexOf(n) > -1) return n; } return null; // difference document area } /** * listing all previous siblings (until predicate hit). * * @param {Node} node * @param {Function} [optional] pred - predicate function */ function listPrev(node, pred) { pred = pred || func.fail; const nodes = []; while (node) { if (pred(node)) { break; } nodes.push(node); node = node.previousSibling; } return nodes; } /** * listing next siblings (until predicate hit). * * @param {Node} node * @param {Function} [pred] - predicate function */ function listNext(node, pred) { pred = pred || func.fail; const nodes = []; while (node) { if (pred(node)) { break; } nodes.push(node); node = node.nextSibling; } return nodes; } /** * listing descendant nodes * * @param {Node} node * @param {Function} [pred] - predicate function */ function listDescendant(node, pred) { const descendants = []; pred = pred || func.ok; // start DFS(depth first search) with node (function fnWalk(current) { if (node !== current && pred(current)) { descendants.push(current); } for (let idx = 0, len = current.childNodes.length; idx < len; idx++) { fnWalk(current.childNodes[idx]); } })(node); return descendants; } /** * wrap node with new tag. * * @param {Node} node * @param {Node} tagName of wrapper * @return {Node} - wrapper */ function wrap(node, wrapperName) { const parent = node.parentNode; const wrapper = external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default()('<' + wrapperName + '>')[0]; parent.insertBefore(wrapper, node); wrapper.appendChild(node); return wrapper; } /** * insert node after preceding * * @param {Node} node * @param {Node} preceding - predicate function */ function insertAfter(node, preceding) { const next = preceding.nextSibling; let parent = preceding.parentNode; if (next) { parent.insertBefore(node, next); } else { parent.appendChild(node); } return node; } /** * append elements. * * @param {Node} node * @param {Collection} aChild */ function appendChildNodes(node, aChild) { external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.each(aChild, function (idx, child) { node.appendChild(child); }); return node; } /** * returns whether boundaryPoint is left edge or not. * * @param {BoundaryPoint} point * @return {Boolean} */ function isLeftEdgePoint(point) { return point.offset === 0; } /** * returns whether boundaryPoint is right edge or not. * * @param {BoundaryPoint} point * @return {Boolean} */ function isRightEdgePoint(point) { return point.offset === nodeLength(point.node); } /** * returns whether boundaryPoint is edge or not. * * @param {BoundaryPoint} point * @return {Boolean} */ function isEdgePoint(point) { return isLeftEdgePoint(point) || isRightEdgePoint(point); } /** * returns whether node is left edge of ancestor or not. * * @param {Node} node * @param {Node} ancestor * @return {Boolean} */ function isLeftEdgeOf(node, ancestor) { while (node && node !== ancestor) { if (dom_position(node) !== 0) { return false; } node = node.parentNode; } return true; } /** * returns whether node is right edge of ancestor or not. * * @param {Node} node * @param {Node} ancestor * @return {Boolean} */ function isRightEdgeOf(node, ancestor) { if (!ancestor) { return false; } while (node && node !== ancestor) { if (dom_position(node) !== nodeLength(node.parentNode) - 1) { return false; } node = node.parentNode; } return true; } /** * returns whether point is left edge of ancestor or not. * @param {BoundaryPoint} point * @param {Node} ancestor * @return {Boolean} */ function isLeftEdgePointOf(point, ancestor) { return isLeftEdgePoint(point) && isLeftEdgeOf(point.node, ancestor); } /** * returns whether point is right edge of ancestor or not. * @param {BoundaryPoint} point * @param {Node} ancestor * @return {Boolean} */ function isRightEdgePointOf(point, ancestor) { return isRightEdgePoint(point) && isRightEdgeOf(point.node, ancestor); } /** * returns offset from parent. * * @param {Node} node */ function dom_position(node) { let offset = 0; while (node = node.previousSibling) { offset += 1; } return offset; } function hasChildren(node) { return !!(node && node.childNodes && node.childNodes.length); } /** * returns previous boundaryPoint * * @param {BoundaryPoint} point * @param {Boolean} isSkipInnerOffset * @return {BoundaryPoint} */ function dom_prevPoint(point, isSkipInnerOffset) { let node; let offset; if (point.offset === 0) { if (isEditable(point.node)) { return null; } node = point.node.parentNode; offset = dom_position(point.node); } else if (hasChildren(point.node)) { node = point.node.childNodes[point.offset - 1]; offset = nodeLength(node); } else { node = point.node; offset = isSkipInnerOffset ? 0 : point.offset - 1; } return { node: node, offset: offset }; } /** * returns next boundaryPoint * * @param {BoundaryPoint} point * @param {Boolean} isSkipInnerOffset * @return {BoundaryPoint} */ function dom_nextPoint(point, isSkipInnerOffset) { let node, offset; if (dom_isEmpty(point.node)) { return null; } if (nodeLength(point.node) === point.offset) { if (isEditable(point.node)) { return null; } node = point.node.parentNode; offset = dom_position(point.node) + 1; } else if (hasChildren(point.node)) { node = point.node.childNodes[point.offset]; offset = 0; if (dom_isEmpty(node)) { return null; } } else { node = point.node; offset = isSkipInnerOffset ? nodeLength(point.node) : point.offset + 1; if (dom_isEmpty(node)) { return null; } } return { node: node, offset: offset }; } /** * returns whether pointA and pointB is same or not. * * @param {BoundaryPoint} pointA * @param {BoundaryPoint} pointB * @return {Boolean} */ function isSamePoint(pointA, pointB) { return pointA.node === pointB.node && pointA.offset === pointB.offset; } /** * returns whether point is visible (can set cursor) or not. * * @param {BoundaryPoint} point * @return {Boolean} */ function isVisiblePoint(point) { if (isText(point.node) || !hasChildren(point.node) || dom_isEmpty(point.node)) { return true; } const leftNode = point.node.childNodes[point.offset - 1]; const rightNode = point.node.childNodes[point.offset]; if ((!leftNode || isVoid(leftNode)) && (!rightNode || isVoid(rightNode))) { return true; } return false; } /** * @method prevPointUtil * * @param {BoundaryPoint} point * @param {Function} pred * @return {BoundaryPoint} */ function prevPointUntil(point, pred) { while (point) { if (pred(point)) { return point; } point = dom_prevPoint(point); } return null; } /** * @method nextPointUntil * * @param {BoundaryPoint} point * @param {Function} pred * @return {BoundaryPoint} */ function nextPointUntil(point, pred) { while (point) { if (pred(point)) { return point; } point = dom_nextPoint(point); } return null; } /** * returns whether point has character or not. * * @param {Point} point * @return {Boolean} */ function isCharPoint(point) { if (!isText(point.node)) { return false; } const ch = point.node.nodeValue.charAt(point.offset - 1); return ch && ch !== ' ' && ch !== NBSP_CHAR; } /** * returns whether point has space or not. * * @param {Point} point * @return {Boolean} */ function isSpacePoint(point) { if (!isText(point.node)) { return false; } const ch = point.node.nodeValue.charAt(point.offset - 1); return ch === ' ' || ch === NBSP_CHAR; } ; /** * @method walkPoint * * @param {BoundaryPoint} startPoint * @param {BoundaryPoint} endPoint * @param {Function} handler * @param {Boolean} isSkipInnerOffset */ function walkPoint(startPoint, endPoint, handler, isSkipInnerOffset) { let point = startPoint; while (point) { handler(point); if (isSamePoint(point, endPoint)) { break; } const isSkipOffset = isSkipInnerOffset && startPoint.node !== point.node && endPoint.node !== point.node; point = dom_nextPoint(point, isSkipOffset); } } /** * @method makeOffsetPath * * return offsetPath(array of offset) from ancestor * * @param {Node} ancestor - ancestor node * @param {Node} node */ function makeOffsetPath(ancestor, node) { const ancestors = listAncestor(node, func.eq(ancestor)); return ancestors.map(dom_position).reverse(); } /** * @method fromOffsetPath * * return element from offsetPath(array of offset) * * @param {Node} ancestor - ancestor node * @param {array} offsets - offsetPath */ function fromOffsetPath(ancestor, offsets) { let current = ancestor; for (let i = 0, len = offsets.length; i < len; i++) { if (current.childNodes.length <= offsets[i]) { current = current.childNodes[current.childNodes.length - 1]; } else { current = current.childNodes[offsets[i]]; } } return current; } /** * @method splitNode * * split element or #text * * @param {BoundaryPoint} point * @param {Object} [options] * @param {Boolean} [options.isSkipPaddingBlankHTML] - default: false * @param {Boolean} [options.isNotSplitEdgePoint] - default: false * @param {Boolean} [options.isDiscardEmptySplits] - default: false * @return {Node} right node of boundaryPoint */ function splitNode(point, options) { let isSkipPaddingBlankHTML = options && options.isSkipPaddingBlankHTML; const isNotSplitEdgePoint = options && options.isNotSplitEdgePoint; const isDiscardEmptySplits = options && options.isDiscardEmptySplits; if (isDiscardEmptySplits) { isSkipPaddingBlankHTML = true; } // edge case if (isEdgePoint(point) && (isText(point.node) || isNotSplitEdgePoint)) { if (isLeftEdgePoint(point)) { return point.node; } else if (isRightEdgePoint(point)) { return point.node.nextSibling; } } // split #text if (isText(point.node)) { return point.node.splitText(point.offset); } else { const childNode = point.node.childNodes[point.offset]; const clone = insertAfter(point.node.cloneNode(false), point.node); appendChildNodes(clone, listNext(childNode)); if (!isSkipPaddingBlankHTML) { paddingBlankHTML(point.node); paddingBlankHTML(clone); } if (isDiscardEmptySplits) { if (dom_isEmpty(point.node)) { remove(point.node); } if (dom_isEmpty(clone)) { remove(clone); return point.node.nextSibling; } } return clone; } } /** * @method splitTree * * split tree by point * * @param {Node} root - split root * @param {BoundaryPoint} point * @param {Object} [options] * @param {Boolean} [options.isSkipPaddingBlankHTML] - default: false * @param {Boolean} [options.isNotSplitEdgePoint] - default: false * @return {Node} right node of boundaryPoint */ function splitTree(root, point, options) { // ex) [#text, ,

] const ancestors = listAncestor(point.node, func.eq(root)); if (!ancestors.length) { return null; } else if (ancestors.length === 1) { return splitNode(point, options); } return ancestors.reduce(function (node, parent) { if (node === point.node) { node = splitNode(point, options); } return splitNode({ node: parent, offset: node ? dom_position(node) : nodeLength(parent) }, options); }); } /** * split point * * @param {Point} point * @param {Boolean} isInline * @return {Object} */ function splitPoint(point, isInline) { // find splitRoot, container // - inline: splitRoot is a child of paragraph // - block: splitRoot is a child of bodyContainer const pred = isInline ? isPara : isBodyContainer; const ancestors = listAncestor(point.node, pred); const topAncestor = lists.last(ancestors) || point.node; let splitRoot, container; if (pred(topAncestor)) { splitRoot = ancestors[ancestors.length - 2]; container = topAncestor; } else { splitRoot = topAncestor; container = splitRoot.parentNode; } // if splitRoot is exists, split with splitTree let pivot = splitRoot && splitTree(splitRoot, point, { isSkipPaddingBlankHTML: isInline, isNotSplitEdgePoint: isInline }); // if container is point.node, find pivot with point.offset if (!pivot && container === point.node) { pivot = point.node.childNodes[point.offset]; } return { rightNode: pivot, container: container }; } function create(nodeName) { return document.createElement(nodeName); } function createText(text) { return document.createTextNode(text); } /** * @method remove * * remove node, (isRemoveChild: remove child or not) * * @param {Node} node * @param {Boolean} isRemoveChild */ function remove(node, isRemoveChild) { if (!node || !node.parentNode) { return; } if (node.removeNode) { return node.removeNode(isRemoveChild); } const parent = node.parentNode; if (!isRemoveChild) { const nodes = []; for (let i = 0, len = node.childNodes.length; i < len; i++) { nodes.push(node.childNodes[i]); } for (let i = 0, len = nodes.length; i < len; i++) { parent.insertBefore(nodes[i], node); } } parent.removeChild(node); } /** * @method removeWhile * * @param {Node} node * @param {Function} pred */ function removeWhile(node, pred) { while (node) { if (isEditable(node) || !pred(node)) { break; } const parent = node.parentNode; remove(node); node = parent; } } /** * @method replace * * replace node with provided nodeName * * @param {Node} node * @param {String} nodeName * @return {Node} - new node */ function replace(node, nodeName) { if (node.nodeName.toUpperCase() === nodeName.toUpperCase()) { return node; } const newNode = create(nodeName); if (node.style.cssText) { newNode.style.cssText = node.style.cssText; } appendChildNodes(newNode, lists.from(node.childNodes)); insertAfter(newNode, node); remove(node); return newNode; } const isTextarea = makePredByNodeName('TEXTAREA'); /** * @param {jQuery} $node * @param {Boolean} [stripLinebreaks] - default: false */ function dom_value($node, stripLinebreaks) { const val = isTextarea($node[0]) ? $node.val() : $node.html(); if (stripLinebreaks) { return val.replace(/[\n\r]/g, ''); } return val; } /** * @method html * * get the HTML contents of node * * @param {jQuery} $node * @param {Boolean} [isNewlineOnBlock] */ function dom_html($node, isNewlineOnBlock) { let markup = dom_value($node); if (isNewlineOnBlock) { const regexTag = /<(\/?)(\b(?!!)[^>\s]*)(.*?)(\s*\/?>)/g; markup = markup.replace(regexTag, function (match, endSlash, name) { name = name.toUpperCase(); const isEndOfInlineContainer = /^DIV|^TD|^TH|^P|^LI|^H[1-7]/.test(name) && !!endSlash; const isBlockNode = /^BLOCKQUOTE|^TABLE|^TBODY|^TR|^HR|^UL|^OL/.test(name); return match + (isEndOfInlineContainer || isBlockNode ? '\n' : ''); }); markup = markup.trim(); } return markup; } function posFromPlaceholder(placeholder) { const $placeholder = external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default()(placeholder); const pos = $placeholder.offset(); const height = $placeholder.outerHeight(true); // include margin return { left: pos.left, top: pos.top + height }; } function attachEvents($node, events) { Object.keys(events).forEach(function (key) { $node.on(key, events[key]); }); } function detachEvents($node, events) { Object.keys(events).forEach(function (key) { $node.off(key, events[key]); }); } /** * @method isCustomStyleTag * * assert if a node contains a "note-styletag" class, * which implies that's a custom-made style tag node * * @param {Node} an HTML DOM node */ function isCustomStyleTag(node) { return node && !isText(node) && lists.contains(node.classList, 'note-styletag'); } /* harmony default export */ var dom = ({ /** @property {String} NBSP_CHAR */ NBSP_CHAR, /** @property {String} ZERO_WIDTH_NBSP_CHAR */ ZERO_WIDTH_NBSP_CHAR, /** @property {String} blank */ blank: blankHTML, /** @property {String} emptyPara */ emptyPara: `

${blankHTML}

`, makePredByNodeName, isEditable, isControlSizing, isText, isElement, isVoid, isPara, isPurePara, isHeading, isInline: dom_isInline, isBlock: func.not(dom_isInline), isBodyInline, isBody, isParaInline, isPre, isList, isTable, isData, isCell: dom_isCell, isBlockquote, isBodyContainer, isAnchor, isDiv: makePredByNodeName('DIV'), isLi, isBR: makePredByNodeName('BR'), isSpan: makePredByNodeName('SPAN'), isB: makePredByNodeName('B'), isU: makePredByNodeName('U'), isS: makePredByNodeName('S'), isI: makePredByNodeName('I'), isImg: makePredByNodeName('IMG'), isTextarea, deepestChildIsEmpty, isEmpty: dom_isEmpty, isEmptyAnchor: func.and(isAnchor, dom_isEmpty), isClosestSibling, withClosestSiblings, nodeLength, isLeftEdgePoint, isRightEdgePoint, isEdgePoint, isLeftEdgeOf, isRightEdgeOf, isLeftEdgePointOf, isRightEdgePointOf, prevPoint: dom_prevPoint, nextPoint: dom_nextPoint, isSamePoint, isVisiblePoint, prevPointUntil, nextPointUntil, isCharPoint, isSpacePoint, walkPoint, ancestor: dom_ancestor, singleChildAncestor, listAncestor, lastAncestor, listNext, listPrev, listDescendant, commonAncestor, wrap, insertAfter, appendChildNodes, position: dom_position, hasChildren, makeOffsetPath, fromOffsetPath, splitTree, splitPoint, create, createText, remove, removeWhile, replace, html: dom_html, value: dom_value, posFromPlaceholder, attachEvents, detachEvents, isCustomStyleTag }); // CONCATENATED MODULE: ./src/js/base/Context.js class Context_Context { /** * @param {jQuery} $note * @param {Object} options */ constructor($note, options) { this.$note = $note; this.memos = {}; this.modules = {}; this.layoutInfo = {}; this.options = external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.extend(true, {}, options); // init ui with options external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.summernote.ui = external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.summernote.ui_template(this.options); this.ui = external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.summernote.ui; this.initialize(); } /** * create layout and initialize modules and other resources */ initialize() { this.layoutInfo = this.ui.createLayout(this.$note); this._initialize(); this.$note.hide(); return this; } /** * destroy modules and other resources and remove layout */ destroy() { this._destroy(); this.$note.removeData('summernote'); this.ui.removeLayout(this.$note, this.layoutInfo); } /** * destory modules and other resources and initialize it again */ reset() { const disabled = this.isDisabled(); this.code(dom.emptyPara); this._destroy(); this._initialize(); if (disabled) { this.disable(); } } _initialize() { // set own id this.options.id = func.uniqueId(external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.now()); // set default container for tooltips, popovers, and dialogs this.options.container = this.options.container || this.layoutInfo.editor; // add optional buttons const buttons = external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.extend({}, this.options.buttons); Object.keys(buttons).forEach(key => { this.memo('button.' + key, buttons[key]); }); const modules = external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.extend({}, this.options.modules, external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.summernote.plugins || {}); // add and initialize modules Object.keys(modules).forEach(key => { this.module(key, modules[key], true); }); Object.keys(this.modules).forEach(key => { this.initializeModule(key); }); } _destroy() { // destroy modules with reversed order Object.keys(this.modules).reverse().forEach(key => { this.removeModule(key); }); Object.keys(this.memos).forEach(key => { this.removeMemo(key); }); // trigger custom onDestroy callback this.triggerEvent('destroy', this); } code(html) { const isActivated = this.invoke('codeview.isActivated'); if (html === undefined) { this.invoke('codeview.sync'); return isActivated ? this.layoutInfo.codable.val() : this.layoutInfo.editable.html(); } else { if (isActivated) { this.layoutInfo.codable.val(html); } else { this.layoutInfo.editable.html(html); } this.$note.val(html); this.triggerEvent('change', html, this.layoutInfo.editable); } } isDisabled() { return this.layoutInfo.editable.attr('contenteditable') === 'false'; } enable() { this.layoutInfo.editable.attr('contenteditable', true); this.invoke('toolbar.activate', true); this.triggerEvent('disable', false); this.options.editing = true; } disable() { // close codeview if codeview is opend if (this.invoke('codeview.isActivated')) { this.invoke('codeview.deactivate'); } this.layoutInfo.editable.attr('contenteditable', false); this.options.editing = false; this.invoke('toolbar.deactivate', true); this.triggerEvent('disable', true); } triggerEvent() { const namespace = lists.head(arguments); const args = lists.tail(lists.from(arguments)); const callback = this.options.callbacks[func.namespaceToCamel(namespace, 'on')]; if (callback) { callback.apply(this.$note[0], args); } this.$note.trigger('summernote.' + namespace, args); } initializeModule(key) { const module = this.modules[key]; module.shouldInitialize = module.shouldInitialize || func.ok; if (!module.shouldInitialize()) { return; } // initialize module if (module.initialize) { module.initialize(); } // attach events if (module.events) { dom.attachEvents(this.$note, module.events); } } module(key, ModuleClass, withoutIntialize) { if (arguments.length === 1) { return this.modules[key]; } this.modules[key] = new ModuleClass(this); if (!withoutIntialize) { this.initializeModule(key); } } removeModule(key) { const module = this.modules[key]; if (module.shouldInitialize()) { if (module.events) { dom.detachEvents(this.$note, module.events); } if (module.destroy) { module.destroy(); } } delete this.modules[key]; } memo(key, obj) { if (arguments.length === 1) { return this.memos[key]; } this.memos[key] = obj; } removeMemo(key) { if (this.memos[key] && this.memos[key].destroy) { this.memos[key].destroy(); } delete this.memos[key]; } /** * Some buttons need to change their visual style immediately once they get pressed */ createInvokeHandlerAndUpdateState(namespace, value) { return event => { this.createInvokeHandler(namespace, value)(event); this.invoke('buttons.updateCurrentStyle'); }; } createInvokeHandler(namespace, value) { return event => { event.preventDefault(); const $target = external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default()(event.target); this.invoke(namespace, value || $target.closest('[data-value]').data('value'), $target); }; } invoke() { const namespace = lists.head(arguments); const args = lists.tail(lists.from(arguments)); const splits = namespace.split('.'); const hasSeparator = splits.length > 1; const moduleName = hasSeparator && lists.head(splits); const methodName = hasSeparator ? lists.last(splits) : lists.head(splits); const module = this.modules[moduleName || 'editor']; if (!moduleName && this[methodName]) { return this[methodName].apply(this, args); } else if (module && module[methodName] && module.shouldInitialize()) { return module[methodName].apply(module, args); } } } // CONCATENATED MODULE: ./src/js/summernote.js external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.fn.extend({ /** * Summernote API * * @param {Object|String} * @return {this} */ summernote: function () { const type = external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.type(lists.head(arguments)); const isExternalAPICalled = type === 'string'; const hasInitOptions = type === 'object'; const options = external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.extend({}, external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.summernote.options, hasInitOptions ? lists.head(arguments) : {}); // Update options options.langInfo = external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.extend(true, {}, external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.summernote.lang['en-US'], external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.summernote.lang[options.lang]); options.icons = external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.extend(true, {}, external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.summernote.options.icons, options.icons); options.tooltip = options.tooltip === 'auto' ? !env.isSupportTouch : options.tooltip; this.each((idx, note) => { const $note = external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default()(note); if (!$note.data('summernote')) { const context = new Context_Context($note, options); $note.data('summernote', context); $note.data('summernote').triggerEvent('init', context.layoutInfo); } }); const $note = this.first(); if ($note.length) { const context = $note.data('summernote'); if (isExternalAPICalled) { return context.invoke.apply(context, lists.from(arguments)); } else if (options.focus) { context.invoke('editor.focus'); } } return this; } }); // CONCATENATED MODULE: ./src/js/base/core/range.js /** * return boundaryPoint from TextRange, inspired by Andy Na's HuskyRange.js * * @param {TextRange} textRange * @param {Boolean} isStart * @return {BoundaryPoint} * * @see http://msdn.microsoft.com/en-us/library/ie/ms535872(v=vs.85).aspx */ function textRangeToPoint(textRange, isStart) { let container = textRange.parentElement(); let offset; const tester = document.body.createTextRange(); let prevContainer; const childNodes = lists.from(container.childNodes); for (offset = 0; offset < childNodes.length; offset++) { if (dom.isText(childNodes[offset])) { continue; } tester.moveToElementText(childNodes[offset]); if (tester.compareEndPoints('StartToStart', textRange) >= 0) { break; } prevContainer = childNodes[offset]; } if (offset !== 0 && dom.isText(childNodes[offset - 1])) { const textRangeStart = document.body.createTextRange(); let curTextNode = null; textRangeStart.moveToElementText(prevContainer || container); textRangeStart.collapse(!prevContainer); curTextNode = prevContainer ? prevContainer.nextSibling : container.firstChild; const pointTester = textRange.duplicate(); pointTester.setEndPoint('StartToStart', textRangeStart); let textCount = pointTester.text.replace(/[\r\n]/g, '').length; while (textCount > curTextNode.nodeValue.length && curTextNode.nextSibling) { textCount -= curTextNode.nodeValue.length; curTextNode = curTextNode.nextSibling; } // [workaround] enforce IE to re-reference curTextNode, hack const dummy = curTextNode.nodeValue; // eslint-disable-line if (isStart && curTextNode.nextSibling && dom.isText(curTextNode.nextSibling) && textCount === curTextNode.nodeValue.length) { textCount -= curTextNode.nodeValue.length; curTextNode = curTextNode.nextSibling; } container = curTextNode; offset = textCount; } return { cont: container, offset: offset }; } /** * return TextRange from boundary point (inspired by google closure-library) * @param {BoundaryPoint} point * @return {TextRange} */ function pointToTextRange(point) { const textRangeInfo = function (container, offset) { let node, isCollapseToStart; if (dom.isText(container)) { const prevTextNodes = dom.listPrev(container, func.not(dom.isText)); const prevContainer = lists.last(prevTextNodes).previousSibling; node = prevContainer || container.parentNode; offset += lists.sum(lists.tail(prevTextNodes), dom.nodeLength); isCollapseToStart = !prevContainer; } else { node = container.childNodes[offset] || container; if (dom.isText(node)) { return textRangeInfo(node, 0); } offset = 0; isCollapseToStart = false; } return { node: node, collapseToStart: isCollapseToStart, offset: offset }; }; const textRange = document.body.createTextRange(); const info = textRangeInfo(point.node, point.offset); textRange.moveToElementText(info.node); textRange.collapse(info.collapseToStart); textRange.moveStart('character', info.offset); return textRange; } /** * Wrapped Range * * @constructor * @param {Node} sc - start container * @param {Number} so - start offset * @param {Node} ec - end container * @param {Number} eo - end offset */ class range_WrappedRange { constructor(sc, so, ec, eo) { this.sc = sc; this.so = so; this.ec = ec; this.eo = eo; // isOnEditable: judge whether range is on editable or not this.isOnEditable = this.makeIsOn(dom.isEditable); // isOnList: judge whether range is on list node or not this.isOnList = this.makeIsOn(dom.isList); // isOnAnchor: judge whether range is on anchor node or not this.isOnAnchor = this.makeIsOn(dom.isAnchor); // isOnCell: judge whether range is on cell node or not this.isOnCell = this.makeIsOn(dom.isCell); // isOnData: judge whether range is on data node or not this.isOnData = this.makeIsOn(dom.isData); } // nativeRange: get nativeRange from sc, so, ec, eo nativeRange() { if (env.isW3CRangeSupport) { const w3cRange = document.createRange(); w3cRange.setStart(this.sc, this.sc.data && this.so > this.sc.data.length ? 0 : this.so); w3cRange.setEnd(this.ec, this.sc.data ? Math.min(this.eo, this.sc.data.length) : this.eo); return w3cRange; } else { const textRange = pointToTextRange({ node: this.sc, offset: this.so }); textRange.setEndPoint('EndToEnd', pointToTextRange({ node: this.ec, offset: this.eo })); return textRange; } } getPoints() { return { sc: this.sc, so: this.so, ec: this.ec, eo: this.eo }; } getStartPoint() { return { node: this.sc, offset: this.so }; } getEndPoint() { return { node: this.ec, offset: this.eo }; } /** * select update visible range */ select() { const nativeRng = this.nativeRange(); if (env.isW3CRangeSupport) { const selection = document.getSelection(); if (selection.rangeCount > 0) { selection.removeAllRanges(); } selection.addRange(nativeRng); } else { nativeRng.select(); } return this; } /** * Moves the scrollbar to start container(sc) of current range * * @return {WrappedRange} */ scrollIntoView(container) { const height = external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default()(container).height(); if (container.scrollTop + height < this.sc.offsetTop) { container.scrollTop += Math.abs(container.scrollTop + height - this.sc.offsetTop); } return this; } /** * @return {WrappedRange} */ normalize() { /** * @param {BoundaryPoint} point * @param {Boolean} isLeftToRight - true: prefer to choose right node * - false: prefer to choose left node * @return {BoundaryPoint} */ const getVisiblePoint = function (point, isLeftToRight) { if (!point) { return point; } // Just use the given point [XXX:Adhoc] // - case 01. if the point is on the middle of the node // - case 02. if the point is on the right edge and prefer to choose left node // - case 03. if the point is on the left edge and prefer to choose right node // - case 04. if the point is on the right edge and prefer to choose right node but the node is void // - case 05. if the point is on the left edge and prefer to choose left node but the node is void // - case 06. if the point is on the block node and there is no children if (dom.isVisiblePoint(point)) { if (!dom.isEdgePoint(point) || dom.isRightEdgePoint(point) && !isLeftToRight || dom.isLeftEdgePoint(point) && isLeftToRight || dom.isRightEdgePoint(point) && isLeftToRight && dom.isVoid(point.node.nextSibling) || dom.isLeftEdgePoint(point) && !isLeftToRight && dom.isVoid(point.node.previousSibling) || dom.isBlock(point.node) && dom.isEmpty(point.node)) { return point; } } // point on block's edge const block = dom.ancestor(point.node, dom.isBlock); let hasRightNode = false; if (!hasRightNode) { const prevPoint = dom.prevPoint(point) || { node: null }; hasRightNode = (dom.isLeftEdgePointOf(point, block) || dom.isVoid(prevPoint.node)) && !isLeftToRight; } let hasLeftNode = false; if (!hasLeftNode) { const nextPoint = dom.nextPoint(point) || { node: null }; hasLeftNode = (dom.isRightEdgePointOf(point, block) || dom.isVoid(nextPoint.node)) && isLeftToRight; } if (hasRightNode || hasLeftNode) { // returns point already on visible point if (dom.isVisiblePoint(point)) { return point; } // reverse direction isLeftToRight = !isLeftToRight; } const nextPoint = isLeftToRight ? dom.nextPointUntil(dom.nextPoint(point), dom.isVisiblePoint) : dom.prevPointUntil(dom.prevPoint(point), dom.isVisiblePoint); return nextPoint || point; }; const endPoint = getVisiblePoint(this.getEndPoint(), false); const startPoint = this.isCollapsed() ? endPoint : getVisiblePoint(this.getStartPoint(), true); return new range_WrappedRange(startPoint.node, startPoint.offset, endPoint.node, endPoint.offset); } /** * returns matched nodes on range * * @param {Function} [pred] - predicate function * @param {Object} [options] * @param {Boolean} [options.includeAncestor] * @param {Boolean} [options.fullyContains] * @return {Node[]} */ nodes(pred, options) { pred = pred || func.ok; const includeAncestor = options && options.includeAncestor; const fullyContains = options && options.fullyContains; // TODO compare points and sort const startPoint = this.getStartPoint(); const endPoint = this.getEndPoint(); const nodes = []; const leftEdgeNodes = []; dom.walkPoint(startPoint, endPoint, function (point) { if (dom.isEditable(point.node)) { return; } let node; if (fullyContains) { if (dom.isLeftEdgePoint(point)) { leftEdgeNodes.push(point.node); } if (dom.isRightEdgePoint(point) && lists.contains(leftEdgeNodes, point.node)) { node = point.node; } } else if (includeAncestor) { node = dom.ancestor(point.node, pred); } else { node = point.node; } if (node && pred(node)) { nodes.push(node); } }, true); return lists.unique(nodes); } /** * returns commonAncestor of range * @return {Element} - commonAncestor */ commonAncestor() { return dom.commonAncestor(this.sc, this.ec); } /** * returns expanded range by pred * * @param {Function} pred - predicate function * @return {WrappedRange} */ expand(pred) { const startAncestor = dom.ancestor(this.sc, pred); const endAncestor = dom.ancestor(this.ec, pred); if (!startAncestor && !endAncestor) { return new range_WrappedRange(this.sc, this.so, this.ec, this.eo); } const boundaryPoints = this.getPoints(); if (startAncestor) { boundaryPoints.sc = startAncestor; boundaryPoints.so = 0; } if (endAncestor) { boundaryPoints.ec = endAncestor; boundaryPoints.eo = dom.nodeLength(endAncestor); } return new range_WrappedRange(boundaryPoints.sc, boundaryPoints.so, boundaryPoints.ec, boundaryPoints.eo); } /** * @param {Boolean} isCollapseToStart * @return {WrappedRange} */ collapse(isCollapseToStart) { if (isCollapseToStart) { return new range_WrappedRange(this.sc, this.so, this.sc, this.so); } else { return new range_WrappedRange(this.ec, this.eo, this.ec, this.eo); } } /** * splitText on range */ splitText() { const isSameContainer = this.sc === this.ec; const boundaryPoints = this.getPoints(); if (dom.isText(this.ec) && !dom.isEdgePoint(this.getEndPoint())) { this.ec.splitText(this.eo); } if (dom.isText(this.sc) && !dom.isEdgePoint(this.getStartPoint())) { boundaryPoints.sc = this.sc.splitText(this.so); boundaryPoints.so = 0; if (isSameContainer) { boundaryPoints.ec = boundaryPoints.sc; boundaryPoints.eo = this.eo - this.so; } } return new range_WrappedRange(boundaryPoints.sc, boundaryPoints.so, boundaryPoints.ec, boundaryPoints.eo); } /** * delete contents on range * @return {WrappedRange} */ deleteContents() { if (this.isCollapsed()) { return this; } const rng = this.splitText(); const nodes = rng.nodes(null, { fullyContains: true }); // find new cursor point const point = dom.prevPointUntil(rng.getStartPoint(), function (point) { return !lists.contains(nodes, point.node); }); const emptyParents = []; external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.each(nodes, function (idx, node) { // find empty parents const parent = node.parentNode; if (point.node !== parent && dom.nodeLength(parent) === 1) { emptyParents.push(parent); } dom.remove(node, false); }); // remove empty parents external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.each(emptyParents, function (idx, node) { dom.remove(node, false); }); return new range_WrappedRange(point.node, point.offset, point.node, point.offset).normalize(); } /** * makeIsOn: return isOn(pred) function */ makeIsOn(pred) { return function () { const ancestor = dom.ancestor(this.sc, pred); return !!ancestor && ancestor === dom.ancestor(this.ec, pred); }; } /** * @param {Function} pred * @return {Boolean} */ isLeftEdgeOf(pred) { if (!dom.isLeftEdgePoint(this.getStartPoint())) { return false; } const node = dom.ancestor(this.sc, pred); return node && dom.isLeftEdgeOf(this.sc, node); } /** * returns whether range was collapsed or not */ isCollapsed() { return this.sc === this.ec && this.so === this.eo; } /** * wrap inline nodes which children of body with paragraph * * @return {WrappedRange} */ wrapBodyInlineWithPara() { if (dom.isBodyContainer(this.sc) && dom.isEmpty(this.sc)) { this.sc.innerHTML = dom.emptyPara; return new range_WrappedRange(this.sc.firstChild, 0, this.sc.firstChild, 0); } /** * [workaround] firefox often create range on not visible point. so normalize here. * - firefox: |

text

| * - chrome:

|text|

*/ const rng = this.normalize(); if (dom.isParaInline(this.sc) || dom.isPara(this.sc)) { return rng; } // find inline top ancestor let topAncestor; if (dom.isInline(rng.sc)) { const ancestors = dom.listAncestor(rng.sc, func.not(dom.isInline)); topAncestor = lists.last(ancestors); if (!dom.isInline(topAncestor)) { topAncestor = ancestors[ancestors.length - 2] || rng.sc.childNodes[rng.so]; } } else { topAncestor = rng.sc.childNodes[rng.so > 0 ? rng.so - 1 : 0]; } if (topAncestor) { // siblings not in paragraph let inlineSiblings = dom.listPrev(topAncestor, dom.isParaInline).reverse(); inlineSiblings = inlineSiblings.concat(dom.listNext(topAncestor.nextSibling, dom.isParaInline)); // wrap with paragraph if (inlineSiblings.length) { const para = dom.wrap(lists.head(inlineSiblings), 'p'); dom.appendChildNodes(para, lists.tail(inlineSiblings)); } } return this.normalize(); } /** * insert node at current cursor * * @param {Node} node * @return {Node} */ insertNode(node) { let rng = this; if (dom.isText(node) || dom.isInline(node)) { rng = this.wrapBodyInlineWithPara().deleteContents(); } const info = dom.splitPoint(rng.getStartPoint(), dom.isInline(node)); if (info.rightNode) { info.rightNode.parentNode.insertBefore(node, info.rightNode); } else { info.container.appendChild(node); } return node; } /** * insert html at current cursor */ pasteHTML(markup) { markup = external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.trim(markup); const contentsContainer = external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default()('
').html(markup)[0]; let childNodes = lists.from(contentsContainer.childNodes); // const rng = this.wrapBodyInlineWithPara().deleteContents(); const rng = this; if (rng.so >= 0) { childNodes = childNodes.reverse(); } childNodes = childNodes.map(function (childNode) { return rng.insertNode(childNode); }); if (rng.so > 0) { childNodes = childNodes.reverse(); } return childNodes; } /** * returns text in range * * @return {String} */ toString() { const nativeRng = this.nativeRange(); return env.isW3CRangeSupport ? nativeRng.toString() : nativeRng.text; } /** * returns range for word before cursor * * @param {Boolean} [findAfter] - find after cursor, default: false * @return {WrappedRange} */ getWordRange(findAfter) { let endPoint = this.getEndPoint(); if (!dom.isCharPoint(endPoint)) { return this; } const startPoint = dom.prevPointUntil(endPoint, function (point) { return !dom.isCharPoint(point); }); if (findAfter) { endPoint = dom.nextPointUntil(endPoint, function (point) { return !dom.isCharPoint(point); }); } return new range_WrappedRange(startPoint.node, startPoint.offset, endPoint.node, endPoint.offset); } /** * returns range for words before cursor * * @param {Boolean} [findAfter] - find after cursor, default: false * @return {WrappedRange} */ getWordsRange(findAfter) { var endPoint = this.getEndPoint(); var isNotTextPoint = function (point) { return !dom.isCharPoint(point) && !dom.isSpacePoint(point); }; if (isNotTextPoint(endPoint)) { return this; } var startPoint = dom.prevPointUntil(endPoint, isNotTextPoint); if (findAfter) { endPoint = dom.nextPointUntil(endPoint, isNotTextPoint); } return new range_WrappedRange(startPoint.node, startPoint.offset, endPoint.node, endPoint.offset); } /** * returns range for words before cursor that match with a Regex * * example: * range: 'hi @Peter Pan' * regex: '/@[a-z ]+/i' * return range: '@Peter Pan' * * @param {RegExp} [regex] * @return {WrappedRange|null} */ getWordsMatchRange(regex) { var endPoint = this.getEndPoint(); var startPoint = dom.prevPointUntil(endPoint, function (point) { if (!dom.isCharPoint(point) && !dom.isSpacePoint(point)) { return true; } var rng = new range_WrappedRange(point.node, point.offset, endPoint.node, endPoint.offset); var result = regex.exec(rng.toString()); return result && result.index === 0; }); var rng = new range_WrappedRange(startPoint.node, startPoint.offset, endPoint.node, endPoint.offset); var text = rng.toString(); var result = regex.exec(text); if (result && result[0].length === text.length) { return rng; } else { return null; } } /** * create offsetPath bookmark * * @param {Node} editable */ bookmark(editable) { return { s: { path: dom.makeOffsetPath(editable, this.sc), offset: this.so }, e: { path: dom.makeOffsetPath(editable, this.ec), offset: this.eo } }; } /** * create offsetPath bookmark base on paragraph * * @param {Node[]} paras */ paraBookmark(paras) { return { s: { path: lists.tail(dom.makeOffsetPath(lists.head(paras), this.sc)), offset: this.so }, e: { path: lists.tail(dom.makeOffsetPath(lists.last(paras), this.ec)), offset: this.eo } }; } /** * getClientRects * @return {Rect[]} */ getClientRects() { const nativeRng = this.nativeRange(); return nativeRng.getClientRects(); } } /** * Data structure * * BoundaryPoint: a point of dom tree * * BoundaryPoints: two boundaryPoints corresponding to the start and the end of the Range * * See to http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html#Level-2-Range-Position */ /* harmony default export */ var core_range = ({ /** * create Range Object From arguments or Browser Selection * * @param {Node} sc - start container * @param {Number} so - start offset * @param {Node} ec - end container * @param {Number} eo - end offset * @return {WrappedRange} */ create: function (sc, so, ec, eo) { if (arguments.length === 4) { return new range_WrappedRange(sc, so, ec, eo); } else if (arguments.length === 2) { // collapsed ec = sc; eo = so; return new range_WrappedRange(sc, so, ec, eo); } else { let wrappedRange = this.createFromSelection(); if (!wrappedRange && arguments.length === 1) { let bodyElement = arguments[0]; if (dom.isEditable(bodyElement)) { bodyElement = bodyElement.lastChild; } return this.createFromBodyElement(bodyElement, dom.emptyPara === arguments[0].innerHTML); } return wrappedRange; } }, createFromBodyElement: function (bodyElement, isCollapseToStart = false) { var wrappedRange = this.createFromNode(bodyElement); return wrappedRange.collapse(isCollapseToStart); }, createFromSelection: function () { let sc, so, ec, eo; if (env.isW3CRangeSupport) { const selection = document.getSelection(); if (!selection || selection.rangeCount === 0) { return null; } else if (dom.isBody(selection.anchorNode)) { // Firefox: returns entire body as range on initialization. // We won't never need it. return null; } const nativeRng = selection.getRangeAt(0); sc = nativeRng.startContainer; so = nativeRng.startOffset; ec = nativeRng.endContainer; eo = nativeRng.endOffset; } else { // IE8: TextRange const textRange = document.selection.createRange(); const textRangeEnd = textRange.duplicate(); textRangeEnd.collapse(false); const textRangeStart = textRange; textRangeStart.collapse(true); let startPoint = textRangeToPoint(textRangeStart, true); let endPoint = textRangeToPoint(textRangeEnd, false); // same visible point case: range was collapsed. if (dom.isText(startPoint.node) && dom.isLeftEdgePoint(startPoint) && dom.isTextNode(endPoint.node) && dom.isRightEdgePoint(endPoint) && endPoint.node.nextSibling === startPoint.node) { startPoint = endPoint; } sc = startPoint.cont; so = startPoint.offset; ec = endPoint.cont; eo = endPoint.offset; } return new range_WrappedRange(sc, so, ec, eo); }, /** * @method * * create WrappedRange from node * * @param {Node} node * @return {WrappedRange} */ createFromNode: function (node) { let sc = node; let so = 0; let ec = node; let eo = dom.nodeLength(ec); // browsers can't target a picture or void node if (dom.isVoid(sc)) { so = dom.listPrev(sc).length - 1; sc = sc.parentNode; } if (dom.isBR(ec)) { eo = dom.listPrev(ec).length - 1; ec = ec.parentNode; } else if (dom.isVoid(ec)) { eo = dom.listPrev(ec).length; ec = ec.parentNode; } return this.create(sc, so, ec, eo); }, /** * create WrappedRange from node after position * * @param {Node} node * @return {WrappedRange} */ createFromNodeBefore: function (node) { return this.createFromNode(node).collapse(true); }, /** * create WrappedRange from node after position * * @param {Node} node * @return {WrappedRange} */ createFromNodeAfter: function (node) { return this.createFromNode(node).collapse(); }, /** * @method * * create WrappedRange from bookmark * * @param {Node} editable * @param {Object} bookmark * @return {WrappedRange} */ createFromBookmark: function (editable, bookmark) { const sc = dom.fromOffsetPath(editable, bookmark.s.path); const so = bookmark.s.offset; const ec = dom.fromOffsetPath(editable, bookmark.e.path); const eo = bookmark.e.offset; return new range_WrappedRange(sc, so, ec, eo); }, /** * @method * * create WrappedRange from paraBookmark * * @param {Object} bookmark * @param {Node[]} paras * @return {WrappedRange} */ createFromParaBookmark: function (bookmark, paras) { const so = bookmark.s.offset; const eo = bookmark.e.offset; const sc = dom.fromOffsetPath(lists.head(paras), bookmark.s.path); const ec = dom.fromOffsetPath(lists.last(paras), bookmark.e.path); return new range_WrappedRange(sc, so, ec, eo); } }); // CONCATENATED MODULE: ./src/js/base/core/key.js const KEY_MAP = { 'BACKSPACE': 8, 'TAB': 9, 'ENTER': 13, 'SPACE': 32, 'DELETE': 46, // Arrow 'LEFT': 37, 'UP': 38, 'RIGHT': 39, 'DOWN': 40, // Number: 0-9 'NUM0': 48, 'NUM1': 49, 'NUM2': 50, 'NUM3': 51, 'NUM4': 52, 'NUM5': 53, 'NUM6': 54, 'NUM7': 55, 'NUM8': 56, // Alphabet: a-z 'B': 66, 'E': 69, 'I': 73, 'J': 74, 'K': 75, 'L': 76, 'R': 82, 'S': 83, 'U': 85, 'V': 86, 'Y': 89, 'Z': 90, 'SLASH': 191, 'LEFTBRACKET': 219, 'BACKSLASH': 220, 'RIGHTBRACKET': 221, // Navigation 'HOME': 36, 'END': 35, 'PAGEUP': 33, 'PAGEDOWN': 34 }; /** * @class core.key * * Object for keycodes. * * @singleton * @alternateClassName key */ /* harmony default export */ var core_key = ({ /** * @method isEdit * * @param {Number} keyCode * @return {Boolean} */ isEdit: keyCode => { return lists.contains([KEY_MAP.BACKSPACE, KEY_MAP.TAB, KEY_MAP.ENTER, KEY_MAP.SPACE, KEY_MAP.DELETE], keyCode); }, /** * @method isMove * * @param {Number} keyCode * @return {Boolean} */ isMove: keyCode => { return lists.contains([KEY_MAP.LEFT, KEY_MAP.UP, KEY_MAP.RIGHT, KEY_MAP.DOWN], keyCode); }, /** * @method isNavigation * * @param {Number} keyCode * @return {Boolean} */ isNavigation: keyCode => { return lists.contains([KEY_MAP.HOME, KEY_MAP.END, KEY_MAP.PAGEUP, KEY_MAP.PAGEDOWN], keyCode); }, /** * @property {Object} nameFromCode * @property {String} nameFromCode.8 "BACKSPACE" */ nameFromCode: func.invertObject(KEY_MAP), code: KEY_MAP }); // CONCATENATED MODULE: ./src/js/base/core/async.js /** * @method readFileAsDataURL * * read contents of file as representing URL * * @param {File} file * @return {Promise} - then: dataUrl */ function readFileAsDataURL(file) { return external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.Deferred(deferred => { external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.extend(new FileReader(), { onload: e => { const dataURL = e.target.result; deferred.resolve(dataURL); }, onerror: err => { deferred.reject(err); } }).readAsDataURL(file); }).promise(); } /** * @method createImage * * create `` from url string * * @param {String} url * @return {Promise} - then: $image */ function createImage(url) { return external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.Deferred(deferred => { const $img = external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default()(''); $img.one('load', () => { $img.off('error abort'); deferred.resolve($img); }).one('error abort', () => { $img.off('load').detach(); deferred.reject($img); }).css({ display: 'none' }).appendTo(document.body).attr('src', url); }).promise(); } // CONCATENATED MODULE: ./src/js/base/editing/History.js class History_History { constructor($editable) { this.stack = []; this.stackOffset = -1; this.$editable = $editable; this.editable = $editable[0]; } makeSnapshot() { const rng = core_range.create(this.editable); const emptyBookmark = { s: { path: [], offset: 0 }, e: { path: [], offset: 0 } }; return { contents: this.$editable.html(), bookmark: rng && rng.isOnEditable() ? rng.bookmark(this.editable) : emptyBookmark }; } applySnapshot(snapshot) { if (snapshot.contents !== null) { this.$editable.html(snapshot.contents); } if (snapshot.bookmark !== null) { core_range.createFromBookmark(this.editable, snapshot.bookmark).select(); } } /** * @method rewind * Rewinds the history stack back to the first snapshot taken. * Leaves the stack intact, so that "Redo" can still be used. */ rewind() { // Create snap shot if not yet recorded if (this.$editable.html() !== this.stack[this.stackOffset].contents) { this.recordUndo(); } // Return to the first available snapshot. this.stackOffset = 0; // Apply that snapshot. this.applySnapshot(this.stack[this.stackOffset]); } /** * @method commit * Resets history stack, but keeps current editor's content. */ commit() { // Clear the stack. this.stack = []; // Restore stackOffset to its original value. this.stackOffset = -1; // Record our first snapshot (of nothing). this.recordUndo(); } /** * @method reset * Resets the history stack completely; reverting to an empty editor. */ reset() { // Clear the stack. this.stack = []; // Restore stackOffset to its original value. this.stackOffset = -1; // Clear the editable area. this.$editable.html(''); // Record our first snapshot (of nothing). this.recordUndo(); } /** * undo */ undo() { // Create snap shot if not yet recorded if (this.$editable.html() !== this.stack[this.stackOffset].contents) { this.recordUndo(); } if (this.stackOffset > 0) { this.stackOffset--; this.applySnapshot(this.stack[this.stackOffset]); } } /** * redo */ redo() { if (this.stack.length - 1 > this.stackOffset) { this.stackOffset++; this.applySnapshot(this.stack[this.stackOffset]); } } /** * recorded undo */ recordUndo() { this.stackOffset++; // Wash out stack after stackOffset if (this.stack.length > this.stackOffset) { this.stack = this.stack.slice(0, this.stackOffset); } // Create new snapshot and push it to the end this.stack.push(this.makeSnapshot()); } } // CONCATENATED MODULE: ./src/js/base/editing/Style.js class Style_Style { /** * @method jQueryCSS * * [workaround] for old jQuery * passing an array of style properties to .css() * will result in an object of property-value pairs. * (compability with version < 1.9) * * @private * @param {jQuery} $obj * @param {Array} propertyNames - An array of one or more CSS properties. * @return {Object} */ jQueryCSS($obj, propertyNames) { if (env.jqueryVersion < 1.9) { const result = {}; external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.each(propertyNames, (idx, propertyName) => { result[propertyName] = $obj.css(propertyName); }); return result; } return $obj.css(propertyNames); } /** * returns style object from node * * @param {jQuery} $node * @return {Object} */ fromNode($node) { const properties = ['font-family', 'font-size', 'text-align', 'list-style-type', 'line-height']; const styleInfo = this.jQueryCSS($node, properties) || {}; const fontSize = $node[0].style.fontSize || styleInfo['font-size']; styleInfo['font-size'] = parseInt(fontSize, 10); styleInfo['font-size-unit'] = fontSize.match(/[a-z%]+$/); return styleInfo; } /** * paragraph level style * * @param {WrappedRange} rng * @param {Object} styleInfo */ stylePara(rng, styleInfo) { external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.each(rng.nodes(dom.isPara, { includeAncestor: true }), (idx, para) => { external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default()(para).css(styleInfo); }); } /** * insert and returns styleNodes on range. * * @param {WrappedRange} rng * @param {Object} [options] - options for styleNodes * @param {String} [options.nodeName] - default: `SPAN` * @param {Boolean} [options.expandClosestSibling] - default: `false` * @param {Boolean} [options.onlyPartialContains] - default: `false` * @return {Node[]} */ styleNodes(rng, options) { rng = rng.splitText(); const nodeName = options && options.nodeName || 'SPAN'; const expandClosestSibling = !!(options && options.expandClosestSibling); const onlyPartialContains = !!(options && options.onlyPartialContains); if (rng.isCollapsed()) { return [rng.insertNode(dom.create(nodeName))]; } let pred = dom.makePredByNodeName(nodeName); const nodes = rng.nodes(dom.isText, { fullyContains: true }).map(text => { return dom.singleChildAncestor(text, pred) || dom.wrap(text, nodeName); }); if (expandClosestSibling) { if (onlyPartialContains) { const nodesInRange = rng.nodes(); // compose with partial contains predication pred = func.and(pred, node => { return lists.contains(nodesInRange, node); }); } return nodes.map(node => { const siblings = dom.withClosestSiblings(node, pred); const head = lists.head(siblings); const tails = lists.tail(siblings); external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.each(tails, (idx, elem) => { dom.appendChildNodes(head, elem.childNodes); dom.remove(elem); }); return lists.head(siblings); }); } else { return nodes; } } /** * get current style on cursor * * @param {WrappedRange} rng * @return {Object} - object contains style properties. */ current(rng) { const $cont = external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default()(!dom.isElement(rng.sc) ? rng.sc.parentNode : rng.sc); let styleInfo = this.fromNode($cont); // document.queryCommandState for toggle state // [workaround] prevent Firefox nsresult: "0x80004005 (NS_ERROR_FAILURE)" try { styleInfo = external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.extend(styleInfo, { 'font-bold': document.queryCommandState('bold') ? 'bold' : 'normal', 'font-italic': document.queryCommandState('italic') ? 'italic' : 'normal', 'font-underline': document.queryCommandState('underline') ? 'underline' : 'normal', 'font-subscript': document.queryCommandState('subscript') ? 'subscript' : 'normal', 'font-superscript': document.queryCommandState('superscript') ? 'superscript' : 'normal', 'font-strikethrough': document.queryCommandState('strikethrough') ? 'strikethrough' : 'normal', 'font-family': document.queryCommandValue('fontname') || styleInfo['font-family'] }); } catch (e) {} // list-style-type to list-style(unordered, ordered) if (!rng.isOnList()) { styleInfo['list-style'] = 'none'; } else { const orderedTypes = ['circle', 'disc', 'disc-leading-zero', 'square']; const isUnordered = orderedTypes.indexOf(styleInfo['list-style-type']) > -1; styleInfo['list-style'] = isUnordered ? 'unordered' : 'ordered'; } const para = dom.ancestor(rng.sc, dom.isPara); if (para && para.style['line-height']) { styleInfo['line-height'] = para.style.lineHeight; } else { const lineHeight = parseInt(styleInfo['line-height'], 10) / parseInt(styleInfo['font-size'], 10); styleInfo['line-height'] = lineHeight.toFixed(1); } styleInfo.anchor = rng.isOnAnchor() && dom.ancestor(rng.sc, dom.isAnchor); styleInfo.ancestors = dom.listAncestor(rng.sc, dom.isEditable); styleInfo.range = rng; return styleInfo; } } // CONCATENATED MODULE: ./src/js/base/editing/Bullet.js class Bullet_Bullet { /** * toggle ordered list */ insertOrderedList(editable) { this.toggleList('OL', editable); } /** * toggle unordered list */ insertUnorderedList(editable) { this.toggleList('UL', editable); } /** * indent */ indent(editable) { const rng = core_range.create(editable).wrapBodyInlineWithPara(); const paras = rng.nodes(dom.isPara, { includeAncestor: true }); const clustereds = lists.clusterBy(paras, func.peq2('parentNode')); external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.each(clustereds, (idx, paras) => { const head = lists.head(paras); if (dom.isLi(head)) { const previousList = this.findList(head.previousSibling); if (previousList) { paras.map(para => previousList.appendChild(para)); } else { this.wrapList(paras, head.parentNode.nodeName); paras.map(para => para.parentNode).map(para => this.appendToPrevious(para)); } } else { external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.each(paras, (idx, para) => { external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default()(para).css('marginLeft', (idx, val) => { return (parseInt(val, 10) || 0) + 25; }); }); } }); rng.select(); } /** * outdent */ outdent(editable) { const rng = core_range.create(editable).wrapBodyInlineWithPara(); const paras = rng.nodes(dom.isPara, { includeAncestor: true }); const clustereds = lists.clusterBy(paras, func.peq2('parentNode')); external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.each(clustereds, (idx, paras) => { const head = lists.head(paras); if (dom.isLi(head)) { this.releaseList([paras]); } else { external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.each(paras, (idx, para) => { external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default()(para).css('marginLeft', (idx, val) => { val = parseInt(val, 10) || 0; return val > 25 ? val - 25 : ''; }); }); } }); rng.select(); } /** * toggle list * * @param {String} listName - OL or UL */ toggleList(listName, editable) { const rng = core_range.create(editable).wrapBodyInlineWithPara(); let paras = rng.nodes(dom.isPara, { includeAncestor: true }); const bookmark = rng.paraBookmark(paras); const clustereds = lists.clusterBy(paras, func.peq2('parentNode')); // paragraph to list if (lists.find(paras, dom.isPurePara)) { let wrappedParas = []; external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.each(clustereds, (idx, paras) => { wrappedParas = wrappedParas.concat(this.wrapList(paras, listName)); }); paras = wrappedParas; // list to paragraph or change list style } else { const diffLists = rng.nodes(dom.isList, { includeAncestor: true }).filter(listNode => { return !external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.nodeName(listNode, listName); }); if (diffLists.length) { external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.each(diffLists, (idx, listNode) => { dom.replace(listNode, listName); }); } else { paras = this.releaseList(clustereds, true); } } core_range.createFromParaBookmark(bookmark, paras).select(); } /** * @param {Node[]} paras * @param {String} listName * @return {Node[]} */ wrapList(paras, listName) { const head = lists.head(paras); const last = lists.last(paras); const prevList = dom.isList(head.previousSibling) && head.previousSibling; const nextList = dom.isList(last.nextSibling) && last.nextSibling; const listNode = prevList || dom.insertAfter(dom.create(listName || 'UL'), last); // P to LI paras = paras.map(para => { return dom.isPurePara(para) ? dom.replace(para, 'LI') : para; }); // append to list(