135 lines
3.9 KiB
Java
135 lines
3.9 KiB
Java
![]() |
"use strict";
|
||
|
/**
|
||
|
* Copyright (c) 2018-present, Ephox, Inc.
|
||
|
*
|
||
|
* This source code is licensed under the Apache 2 license found in the
|
||
|
* LICENSE file in the root directory of this source tree.
|
||
|
*
|
||
|
*/
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
var validEvents = [
|
||
|
'onActivate',
|
||
|
'onAddUndo',
|
||
|
'onBeforeAddUndo',
|
||
|
'onBeforeExecCommand',
|
||
|
'onBeforeGetContent',
|
||
|
'onBeforeRenderUI',
|
||
|
'onBeforeSetContent',
|
||
|
'onBeforePaste',
|
||
|
'onBlur',
|
||
|
'onChange',
|
||
|
'onClearUndos',
|
||
|
'onClick',
|
||
|
'onContextMenu',
|
||
|
'onCopy',
|
||
|
'onCut',
|
||
|
'onDblclick',
|
||
|
'onDeactivate',
|
||
|
'onDirty',
|
||
|
'onDrag',
|
||
|
'onDragDrop',
|
||
|
'onDragEnd',
|
||
|
'onDragGesture',
|
||
|
'onDragOver',
|
||
|
'onDrop',
|
||
|
'onExecCommand',
|
||
|
'onFocus',
|
||
|
'onFocusIn',
|
||
|
'onFocusOut',
|
||
|
'onGetContent',
|
||
|
'onHide',
|
||
|
'onInit',
|
||
|
'onKeyDown',
|
||
|
'onKeyPress',
|
||
|
'onKeyUp',
|
||
|
'onLoadContent',
|
||
|
'onMouseDown',
|
||
|
'onMouseEnter',
|
||
|
'onMouseLeave',
|
||
|
'onMouseMove',
|
||
|
'onMouseOut',
|
||
|
'onMouseOver',
|
||
|
'onMouseUp',
|
||
|
'onNodeChange',
|
||
|
'onObjectResizeStart',
|
||
|
'onObjectResized',
|
||
|
'onObjectSelected',
|
||
|
'onPaste',
|
||
|
'onPostProcess',
|
||
|
'onPostRender',
|
||
|
'onPreProcess',
|
||
|
'onProgressState',
|
||
|
'onRedo',
|
||
|
'onRemove',
|
||
|
'onReset',
|
||
|
'onSaveContent',
|
||
|
'onSelectionChange',
|
||
|
'onSetAttrib',
|
||
|
'onSetContent',
|
||
|
'onShow',
|
||
|
'onSubmit',
|
||
|
'onUndo',
|
||
|
'onVisualAid'
|
||
|
];
|
||
|
var isValidKey = function (key) { return validEvents.indexOf(key) !== -1; };
|
||
|
exports.bindHandlers = function (initEvent, listeners, editor) {
|
||
|
Object.keys(listeners)
|
||
|
.filter(isValidKey)
|
||
|
.forEach(function (key) {
|
||
|
var handler = listeners[key];
|
||
|
if (typeof handler === 'function') {
|
||
|
if (key === 'onInit') {
|
||
|
handler(initEvent, editor);
|
||
|
}
|
||
|
else {
|
||
|
editor.on(key.substring(2), function (e) { return handler(e, editor); });
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
};
|
||
|
exports.bindModelHandlers = function (ctx, editor) {
|
||
|
var modelEvents = ctx.$props.modelEvents ? ctx.$props.modelEvents : null;
|
||
|
var normalizedEvents = Array.isArray(modelEvents) ? modelEvents.join(' ') : modelEvents;
|
||
|
var currentContent;
|
||
|
ctx.$watch('value', function (val, prevVal) {
|
||
|
if (editor && typeof val === 'string' && val !== currentContent && val !== prevVal) {
|
||
|
editor.setContent(val);
|
||
|
currentContent = val;
|
||
|
}
|
||
|
});
|
||
|
editor.on(normalizedEvents ? normalizedEvents : 'change keyup undo redo', function () {
|
||
|
currentContent = editor.getContent();
|
||
|
ctx.$emit('input', currentContent);
|
||
|
});
|
||
|
};
|
||
|
exports.initEditor = function (initEvent, ctx, editor) {
|
||
|
var value = ctx.$props.value ? ctx.$props.value : '';
|
||
|
var initialValue = ctx.$props.initialValue ? ctx.$props.initialValue : '';
|
||
|
editor.setContent(value || initialValue);
|
||
|
// checks if the v-model shorthand is used (which sets an v-on:input listener) and then binds either
|
||
|
// specified the events or defaults to "change keyup" event and emits the editor content on that event
|
||
|
if (ctx.$listeners.input) {
|
||
|
exports.bindModelHandlers(ctx, editor);
|
||
|
}
|
||
|
exports.bindHandlers(initEvent, ctx.$listeners, editor);
|
||
|
};
|
||
|
var unique = 0;
|
||
|
exports.uuid = function (prefix) {
|
||
|
var time = Date.now();
|
||
|
var random = Math.floor(Math.random() * 1000000000);
|
||
|
unique++;
|
||
|
return prefix + '_' + random + unique + String(time);
|
||
|
};
|
||
|
exports.isTextarea = function (element) {
|
||
|
return element !== null && element.tagName.toLowerCase() === 'textarea';
|
||
|
};
|
||
|
var normalizePluginArray = function (plugins) {
|
||
|
if (typeof plugins === 'undefined' || plugins === '') {
|
||
|
return [];
|
||
|
}
|
||
|
return Array.isArray(plugins) ? plugins : plugins.split(' ');
|
||
|
};
|
||
|
exports.mergePlugins = function (initPlugins, inputPlugins) {
|
||
|
return normalizePluginArray(initPlugins).concat(normalizePluginArray(inputPlugins));
|
||
|
};
|