react-summernote
Version:
Summernote (Super simple WYSIWYG editor) adaptation for react
2,024 lines (1,704 loc) • 393 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("jquery"), require("react"));
else if(typeof define === 'function' && define.amd)
define(["jquery", "react"], factory);
else if(typeof exports === 'object')
exports["ReactSummernote"] = factory(require("jquery"), require("react"));
else
root["ReactSummernote"] = factory(root["$"], root["React"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_1__, __WEBPACK_EXTERNAL_MODULE_8__) {
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;
/******/
/******/ // identity function for calling harmony imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 9);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {
// shim for using process in browser
var process = module.exports = {};
// cached from whatever global is present so that test runners that stub it
// don't break things. But we need to wrap it in a try catch in case it is
// wrapped in strict mode code which doesn't define any globals. It's inside a
// function because try/catches deoptimize in certain engines.
var cachedSetTimeout;
var cachedClearTimeout;
function defaultSetTimout() {
throw new Error('setTimeout has not been defined');
}
function defaultClearTimeout () {
throw new Error('clearTimeout has not been defined');
}
(function () {
try {
if (typeof setTimeout === 'function') {
cachedSetTimeout = setTimeout;
} else {
cachedSetTimeout = defaultSetTimout;
}
} catch (e) {
cachedSetTimeout = defaultSetTimout;
}
try {
if (typeof clearTimeout === 'function') {
cachedClearTimeout = clearTimeout;
} else {
cachedClearTimeout = defaultClearTimeout;
}
} catch (e) {
cachedClearTimeout = defaultClearTimeout;
}
} ())
function runTimeout(fun) {
if (cachedSetTimeout === setTimeout) {
//normal enviroments in sane situations
return setTimeout(fun, 0);
}
// if setTimeout wasn't available but was latter defined
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
cachedSetTimeout = setTimeout;
return setTimeout(fun, 0);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedSetTimeout(fun, 0);
} catch(e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedSetTimeout.call(null, fun, 0);
} catch(e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
return cachedSetTimeout.call(this, fun, 0);
}
}
}
function runClearTimeout(marker) {
if (cachedClearTimeout === clearTimeout) {
//normal enviroments in sane situations
return clearTimeout(marker);
}
// if clearTimeout wasn't available but was latter defined
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
cachedClearTimeout = clearTimeout;
return clearTimeout(marker);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedClearTimeout(marker);
} catch (e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedClearTimeout.call(null, marker);
} catch (e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
return cachedClearTimeout.call(this, marker);
}
}
}
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
if (!draining || !currentQueue) {
return;
}
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
drainQueue();
}
}
function drainQueue() {
if (draining) {
return;
}
var timeout = runTimeout(cleanUpNextTick);
draining = true;
var len = queue.length;
while(len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
if (currentQueue) {
currentQueue[queueIndex].run();
}
}
queueIndex = -1;
len = queue.length;
}
currentQueue = null;
draining = false;
runClearTimeout(timeout);
}
process.nextTick = function (fun) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining) {
runTimeout(drainQueue);
}
};
// v8 likes predictible objects
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = ''; // empty string to avoid regexp issues
process.versions = {};
function noop() {}
process.on = noop;
process.addListener = noop;
process.once = noop;
process.off = noop;
process.removeListener = noop;
process.removeAllListeners = noop;
process.emit = noop;
process.prependListener = noop;
process.prependOnceListener = noop;
process.listeners = function (name) { return [] }
process.binding = function (name) {
throw new Error('process.binding is not supported');
};
process.cwd = function () { return '/' };
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
process.umask = function() { return 0; };
/***/ }),
/* 1 */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_1__;
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
module.exports = ReactPropTypesSecret;
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/* WEBPACK VAR INJECTION */(function(process) {
if (process.env.NODE_ENV === 'production') {
module.exports = __webpack_require__(15);
} else {
module.exports = __webpack_require__(14);
}
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0)))
/***/ }),
/* 4 */
/***/ (function(module, exports) {
// removed by extract-text-webpack-plugin
/***/ }),
/* 5 */
/***/ (function(module, exports) {
// removed by extract-text-webpack-plugin
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(process) {/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
if (process.env.NODE_ENV !== 'production') {
var ReactIs = __webpack_require__(3);
// By explicitly using `prop-types` you are opting into new development behavior.
// http://fb.me/prop-types-in-prod
var throwOnDirectAccess = true;
module.exports = __webpack_require__(13)(ReactIs.isElement, throwOnDirectAccess);
} else {
// By explicitly using `prop-types` you are opting into new production behavior.
// http://fb.me/prop-types-in-prod
module.exports = __webpack_require__(12)();
}
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0)))
/***/ }),
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(jQuery) {/*!
*
* Super simple wysiwyg editor v0.8.18
* https://summernote.org
*
*
* Copyright 2013- Alan Hong. and other contributors
* summernote may be freely distributed under the MIT license.
*
* Date: 2020-05-20T16:47Z
*
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(true)
module.exports = factory(__webpack_require__(1));
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 = 52);
/******/ })
/************************************************************************/
/******/ ({
/***/ 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__);
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(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; }
var Renderer = /*#__PURE__*/function () {
function Renderer(markup, children, options, callback) {
_classCallCheck(this, Renderer);
this.markup = markup;
this.children = children;
this.options = options;
this.callback = callback;
}
_createClass(Renderer, [{
key: "render",
value: function render($parent) {
var $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, function (k, v) {
$node.attr('data-' + k, v);
});
}
if (this.options && this.options.click) {
$node.on('click', this.options.click);
}
if (this.children) {
var $container = $node.find('.note-children-container');
this.children.forEach(function (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;
}
}]);
return Renderer;
}();
/* harmony default export */ __webpack_exports__["a"] = ({
create: function create(markup, callback) {
return function () {
var options = _typeof(arguments[1]) === 'object' ? arguments[1] : arguments[0];
var 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: {
'escape': 'Escape',
'insertParagraph': 'Insert Paragraph',
'undo': 'Undo the last command',
'redo': 'Redo 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
var isSupportAmd = "function" === 'function' && __webpack_require__(2); // eslint-disable-line
/**
* returns whether font is installed or not.
*
* @param {String} fontName
* @return {Boolean}
*/
var 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 ? "'".concat(fontName, "'") : fontName;
}
function env_isFontInstalled(fontName) {
var testFontName = fontName === 'Comic Sans MS' ? 'Courier New' : 'Comic Sans MS';
var testText = 'mmmmmmmmmmwwwww';
var testSize = '200px';
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
context.font = testSize + " '" + testFontName + "'";
var originalWidth = context.measureText(testText).width;
context.font = testSize + ' ' + validFontName(fontName) + ', "' + testFontName + '"';
var width = context.measureText(testText).width;
return originalWidth !== width;
}
var userAgent = navigator.userAgent;
var isMSIE = /MSIE|Trident/i.test(userAgent);
var browserVersion;
if (isMSIE) {
var 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]);
}
}
var isEdge = /Edge\/\d+/.test(userAgent);
var isSupportTouch = 'ontouchstart' in window || navigator.MaxTouchPoints > 0 || navigator.msMaxTouchPoints > 0; // [workaround] IE doesn't have input events for contentEditable
// - see: https://goo.gl/4bfIvA
var 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: isMSIE,
isEdge: 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: browserVersion,
jqueryVersion: parseFloat(external_root_jQuery_commonjs2_jquery_commonjs_jquery_amd_jquery_default.a.fn.jquery),
isSupportAmd: isSupportAmd,
isSupportTouch: isSupportTouch,
isFontInstalled: env_isFontInstalled,
isW3CRangeSupport: !!document.createRange,
inputEventName: inputEventName,
genericFontFamilies: genericFontFamilies,
validFontName: 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 func_invoke(obj, method) {
return function () {
return obj[method].apply(obj, arguments);
};
}
var idCounter = 0;
/**
* reset globally-unique id
*
*/
function resetUniqueId() {
idCounter = 0;
}
/**
* generate a globally-unique id
*
* @param {String} [prefix]
*/
function uniqueId(prefix) {
var 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) {
var $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) {
var inverted = {};
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, 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) {
var timeout;
return function () {
var context = this;
var args = arguments;
var later = function later() {
timeout = null;
if (!immediate) {
func.apply(context, args);
}
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) {
func.apply(context, args);
}
};
}
/**
*
* @param {String} url
* @return {Boolean}
*/
function isValidUrl(url) {
var 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: eq,
eq2: eq2,
peq2: peq2,
ok: ok,
fail: fail,
self: func_self,
not: not,
and: and,
invoke: func_invoke,
resetUniqueId: resetUniqueId,
uniqueId: uniqueId,
rect2bnd: rect2bnd,
invertObject: invertObject,
namespaceToCamel: namespaceToCamel,
debounce: debounce,
isValidUrl: 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 (var idx = 0, len = array.length; idx < len; idx++) {
var 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 (var 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) {
var result = [];
var length = collection.length;
var idx = -1;
while (++idx < length) {
result[idx] = collection[idx];
}
return result;
}
/**
* returns whether list is empty or not
*/
function lists_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 [];
}
var aTail = tail(array);
return aTail.reduce(function (memo, v) {
var 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) {
var aResult = [];
for (var 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) {
var results = [];
for (var 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) {
var 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) {
var 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: initial,
tail: tail,
prev: prev,
next: lists_next,
find: find,
contains: contains,
all: lists_all,
sum: sum,
from: from,
isEmpty: lists_isEmpty,
clusterBy: clusterBy,
compact: compact,
unique: unique
});
// CONCATENATED MODULE: ./src/js/base/core/dom.js
var NBSP_CHAR = String.fromCharCode(160);
var 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());
}
var isPre = makePredByNodeName('PRE');
var isLi = makePredByNodeName('LI');
function isPurePara(node) {
return isPara(node) && !isLi(node);
}
var isTable = makePredByNodeName('TABLE');
var 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());
}
var isHr = makePredByNodeName('HR');
function dom_isCell(node) {
return node && /^TD|^TH/.test(node.nodeName.toUpperCase());
}
var isBlockquote = makePredByNodeName('BLOCKQUOTE');
function isBodyContainer(node) {
return dom_isCell(node) || isBlockquote(node) || isEditable(node);
}
var 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);
}
var 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;
var 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
*/
var blankHTML = env.isMSIE && env.browserVersion < 11 ? ' ' : '<br>';
/**
* @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) {
var len = nodeLength(node);
if (len === 0) {
return true;
} else if (!isText(node) && len === 1 && node.innerHTML === blankHTML) {
// ex) <p><br></p>, <span><br></span>
return true;
} else if (lists.all(node.childNodes, isText) && node.innerHTML === '') {
// ex) <p></p>, <span></span>
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;
var 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) {
var ancestors = listAncestor(node);
return lists.last(ancestors.filter(pred));
}
/**
* returns common ancestor node between two nodes.
*
* @param {Node} nodeA
* @param {Node} nodeB
*/
function dom_commonAncestor(nodeA, nodeB) {
var ancestors = listAncestor(nodeA);
for (var 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;
var 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;
var 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) {
var descendants = [];
pred = pred || func.ok; // start DFS(depth first search) with node
(function fnWalk(current) {
if (node !== current && pred(current)) {
descendants.push(current);
}
for (var 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) {
var parent = node.parentNode;
var 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) {
var next = preceding.nextSibling;
var 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 dom_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) && dom_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) {
var 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) {
var node;
var 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) {
var node, offset;
if (nodeLength(point.node) === point.offset) {
if (isEditable(point.node)) {
return null;
}
var nextTextNode = getNextTextNode(point.node);
if (nextTextNode) {
node = nextTextNode;
offset = 0;
} else {
node = point.node.parentNode;
offset = dom_position(point.node) + 1;
}
} else if (hasChildren(point.node)) {
node = point.node.childNodes[point.offset];
offset = 0;
} else {
node = point.node;
offset = isSkipInnerOffset ? nodeLength(point.node) : point.offset + 1;
}
return {
node: node,
offset: offset
};
}
/**
* returns next boundaryPoint with empty node
*
* @param {BoundaryPoint} point
* @param {Boolean} isSkipInnerOffset
* @return {BoundaryPoint}
*/
function nextPointWithEmptyNode(point, isSkipInnerOffset) {
var node, offset; // if node is empty string node, return current node's sibling.
if (dom_isEmpty(point.node)) {
node = point.node.nextSibling;
offset = 0;
return {
node: node,
offset: offset
};
}
if (nodeLength(point.node) === point.offset) {
if (isEditable(point.node)) {
return null;
}
var nextTextNode = getNextTextNode(point.node);
if (nextTextNode) {
node = nextTextNode;
offset = 0;
} else {
node = point.node.parentNode;
offset = dom_position(point.node) + 1;
} // if next node is editable, return current node's sibling node.
if (isEditable(node)) {
node = point.node.nextSibling;
offset = 0;
}
} 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 the next Text node index or 0 if not found.
*/
function getNextTextNode(actual) {
if (!actual.nextSibling) return undefined;
if (actual.parent !== actual.nextSibling.parent) return undefined;
if (isText(actual.nextSibling)) return actual.nextSibling;
return getNextTextNode(actual.nextSibling);
}
/**
* 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;
}
var leftNode = point.node.childNodes[point.offset - 1];
var rightNode = p