first commit

This commit is contained in:
2026-06-24 09:48:54 +02:00
commit 41e62ddcad
33739 changed files with 4266226 additions and 0 deletions
+97
View File
@@ -0,0 +1,97 @@
var Authorship, Delta, Quill, dom, _;
Quill = require('../quill');
_ = Quill.require('lodash');
dom = Quill.require('dom');
Delta = Quill.require('delta');
Authorship = (function() {
Authorship.DEFAULTS = {
authorId: null,
color: 'transparent',
enabled: false
};
function Authorship(quill, options) {
this.quill = quill;
this.options = options;
if (this.options.button != null) {
this.attachButton(this.options.button);
}
if (this.options.enabled) {
this.enable();
}
this.quill.addFormat('author', {
"class": 'author-'
});
if (this.options.authorId == null) {
return;
}
this.quill.on(this.quill.constructor.events.PRE_EVENT, (function(_this) {
return function(eventName, delta, origin) {
var authorDelta, authorFormat;
if (eventName === _this.quill.constructor.events.TEXT_CHANGE && origin === 'user') {
authorDelta = new Delta();
authorFormat = {
author: _this.options.authorId
};
_.each(delta.ops, function(op) {
if (op["delete"] != null) {
return;
}
if ((op.insert != null) || ((op.retain != null) && (op.attributes != null))) {
op.attributes || (op.attributes = {});
op.attributes.author = _this.options.authorId;
return authorDelta.retain(op.retain || op.insert.length || 1, authorFormat);
} else {
return authorDelta.retain(op.retain);
}
});
return _this.quill.updateContents(authorDelta, Quill.sources.SILENT);
}
};
})(this));
this.addAuthor(this.options.authorId, this.options.color);
}
Authorship.prototype.addAuthor = function(id, color) {
var styles;
styles = {};
styles[".authorship .author-" + id] = {
"background-color": "" + color
};
return this.quill.addStyles(styles);
};
Authorship.prototype.attachButton = function(button) {
var $button;
$button = dom(button);
return $button.on('click', (function(_this) {
return function() {
$button.toggleClass('ql-on');
return _this.enable($dom.hasClass('ql-on'));
};
})(this));
};
Authorship.prototype.enable = function(enabled) {
if (enabled == null) {
enabled = true;
}
return dom(this.quill.root).toggleClass('authorship', enabled);
};
Authorship.prototype.disable = function() {
return this.enable(false);
};
return Authorship;
})();
Quill.registerModule('authorship', Authorship);
module.exports = Authorship;
+158
View File
@@ -0,0 +1,158 @@
var Delta, ImageTooltip, Quill, Tooltip, dom, _,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Quill = require('../quill');
Tooltip = require('./tooltip');
_ = Quill.require('lodash');
dom = Quill.require('dom');
Delta = Quill.require('delta');
ImageTooltip = (function(_super) {
__extends(ImageTooltip, _super);
ImageTooltip.DEFAULTS = {
styles: {
'.image-tooltip-container': {
'margin': '25px',
'padding': '10px',
'width': '300px'
},
'.image-tooltip-container:after': {
'clear': 'both',
'content': '""',
'display': 'table'
},
'.image-tooltip-container .preview': {
'margin': '10px 0px',
'position': 'relative',
'border': '1px dashed #000',
'height': '200px'
},
'.image-tooltip-container .preview span': {
'display': 'inline-block',
'position': 'absolute',
'text-align': 'center',
'top': '40%',
'width': '100%'
},
'.image-tooltip-container img': {
'bottom': '0',
'left': '0',
'margin': 'auto',
'max-height': '100%',
'max-width': '100%',
'position': 'absolute',
'right': '0',
'top': '0'
},
'.image-tooltip-container .input': {
'box-sizing': 'border-box',
'width': '100%'
},
'.image-tooltip-container a': {
'border': '1px solid black',
'box-sizing': 'border-box',
'display': 'inline-block',
'float': 'left',
'padding': '5px',
'text-align': 'center',
'width': '50%'
}
},
template: '<input class="input" type="textbox"> <div class="preview"> <span>Preview</span> </div> <a href="javascript:;" class="cancel">Cancel</a> <a href="javascript:;" class="insert">Insert</a>'
};
function ImageTooltip(quill, options) {
this.quill = quill;
this.options = options;
this.options.styles = _.defaults(this.options.styles, Tooltip.DEFAULTS.styles);
this.options = _.defaults(this.options, Tooltip.DEFAULTS);
ImageTooltip.__super__.constructor.call(this, this.quill, this.options);
this.preview = this.container.querySelector('.preview');
this.textbox = this.container.querySelector('.input');
dom(this.container).addClass('image-tooltip-container');
this.initListeners();
}
ImageTooltip.prototype.initListeners = function() {
dom(this.container.querySelector('.insert')).on('click', _.bind(this.insertImage, this));
dom(this.container.querySelector('.cancel')).on('click', _.bind(this.hide, this));
dom(this.textbox).on('input', _.bind(this._preview, this));
this.initTextbox(this.textbox, this.insertImage, this.hide);
return this.quill.onModuleLoad('toolbar', (function(_this) {
return function(toolbar) {
return toolbar.initFormat('image', _.bind(_this._onToolbar, _this));
};
})(this));
};
ImageTooltip.prototype.insertImage = function() {
var index, url;
url = this._normalizeURL(this.textbox.value);
if (this.range == null) {
this.range = new Range(0, 0);
}
if (this.range) {
this.preview.innerHTML = '<span>Preview</span>';
this.textbox.value = '';
index = this.range.end;
this.quill.insertEmbed(index, 'image', url, 'user');
this.quill.setSelection(index + 1, index + 1);
}
return this.hide();
};
ImageTooltip.prototype._onToolbar = function(range, value) {
if (value) {
if (!this.textbox.value) {
this.textbox.value = 'http://';
}
this.show();
this.textbox.focus();
return _.defer((function(_this) {
return function() {
return _this.textbox.setSelectionRange(_this.textbox.value.length, _this.textbox.value.length);
};
})(this));
} else {
return this.quill.deleteText(range, 'user');
}
};
ImageTooltip.prototype._preview = function() {
var img;
if (!this._matchImageURL(this.textbox.value)) {
return;
}
if (this.preview.firstChild.tagName === 'IMG') {
return this.preview.firstChild.setAttribute('src', this.textbox.value);
} else {
img = this.preview.ownerDocument.createElement('img');
img.setAttribute('src', this.textbox.value);
return this.preview.replaceChild(img, this.preview.firstChild);
}
};
ImageTooltip.prototype._matchImageURL = function(url) {
return /^https?:\/\/.+\.(jp?g|gif|png)$/.test(url);
};
ImageTooltip.prototype._normalizeURL = function(url) {
if (!/^https?:\/\//.test(url)) {
url = 'http://' + url;
}
return url;
};
return ImageTooltip;
})(Tooltip);
Quill.registerModule('image-tooltip', ImageTooltip);
module.exports = ImageTooltip;
+155
View File
@@ -0,0 +1,155 @@
var Delta, Keyboard, Quill, dom, _;
Quill = require('../quill');
_ = Quill.require('lodash');
dom = Quill.require('dom');
Delta = Quill.require('delta');
Keyboard = (function() {
Keyboard.hotkeys = {
BOLD: {
key: 'B',
metaKey: true
},
INDENT: {
key: dom.KEYS.TAB
},
ITALIC: {
key: 'I',
metaKey: true
},
OUTDENT: {
key: dom.KEYS.TAB,
shiftKey: true
},
UNDERLINE: {
key: 'U',
metaKey: true
}
};
function Keyboard(quill, options) {
this.quill = quill;
this.hotkeys = {};
this._initListeners();
this._initHotkeys();
this._initDeletes();
}
Keyboard.prototype.addHotkey = function(hotkeys, callback) {
if (!_.isArray(hotkeys)) {
hotkeys = [hotkeys];
}
return _.each(hotkeys, (function(_this) {
return function(hotkey) {
var which, _base;
hotkey = _.isObject(hotkey) ? _.clone(hotkey) : {
key: hotkey
};
hotkey.callback = callback;
which = _.isNumber(hotkey.key) ? hotkey.key : hotkey.key.toUpperCase().charCodeAt(0);
if ((_base = _this.hotkeys)[which] == null) {
_base[which] = [];
}
return _this.hotkeys[which].push(hotkey);
};
})(this));
};
Keyboard.prototype.toggleFormat = function(range, format) {
var delta, toolbar, value;
if (range.isCollapsed()) {
delta = this.quill.getContents(Math.max(0, range.start - 1), range.end);
} else {
delta = this.quill.getContents(range);
}
value = delta.ops.length === 0 || !_.all(delta.ops, function(op) {
var _ref;
return (_ref = op.attributes) != null ? _ref[format] : void 0;
});
if (range.isCollapsed()) {
this.quill.prepareFormat(format, value);
} else {
this.quill.formatText(range, format, value, 'user');
}
toolbar = this.quill.getModule('toolbar');
if (toolbar != null) {
return toolbar.setActive(format, value);
}
};
Keyboard.prototype._initDeletes = function() {
return this.addHotkey([dom.KEYS.DELETE, dom.KEYS.BACKSPACE], (function(_this) {
return function() {
return _this.quill.getLength() > 1;
};
})(this));
};
Keyboard.prototype._initHotkeys = function() {
this.addHotkey(Keyboard.hotkeys.INDENT, (function(_this) {
return function(range) {
_this._onTab(range, false);
return false;
};
})(this));
this.addHotkey(Keyboard.hotkeys.OUTDENT, (function(_this) {
return function(range) {
return false;
};
})(this));
return _.each(['bold', 'italic', 'underline'], (function(_this) {
return function(format) {
return _this.addHotkey(Keyboard.hotkeys[format.toUpperCase()], function(range) {
_this.toggleFormat(range, format);
return false;
});
};
})(this));
};
Keyboard.prototype._initListeners = function() {
return dom(this.quill.root).on('keydown', (function(_this) {
return function(event) {
var prevent;
prevent = false;
_.each(_this.hotkeys[event.which], function(hotkey) {
var metaKey;
metaKey = dom.isMac() ? event.metaKey : event.metaKey || event.ctrlKey;
if (!!hotkey.metaKey !== !!metaKey) {
return;
}
if (!!hotkey.shiftKey !== !!event.shiftKey) {
return;
}
if (!!hotkey.altKey !== !!event.altKey) {
return;
}
prevent = hotkey.callback(_this.quill.getSelection()) === false || prevent;
return true;
});
return !prevent;
};
})(this));
};
Keyboard.prototype._onTab = function(range, shift) {
var delta;
if (shift == null) {
shift = false;
}
delta = new Delta().retain(range.start).insert("\t")["delete"](range.end - range.start).retain(this.quill.getLength() - range.end);
this.quill.updateContents(delta);
return this.quill.setSelection(range.start + 1, range.start + 1);
};
return Keyboard;
})();
Quill.registerModule('keyboard', Keyboard);
module.exports = Keyboard;
+163
View File
@@ -0,0 +1,163 @@
var LinkTooltip, Quill, Tooltip, dom, _,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Quill = require('../quill');
Tooltip = require('./tooltip');
_ = Quill.require('lodash');
dom = Quill.require('dom');
LinkTooltip = (function(_super) {
__extends(LinkTooltip, _super);
LinkTooltip.DEFAULTS = {
maxLength: 50,
styles: {
'.link-tooltip-container': {
'padding': '5px 10px'
},
'.link-tooltip-container input.input': {
'width': '170px'
},
'.link-tooltip-container input.input, .link-tooltip-container a.done, .link-tooltip-container.editing a.url, .link-tooltip-container.editing a.change': {
'display': 'none'
},
'.link-tooltip-container.editing input.input, .link-tooltip-container.editing a.done': {
'display': 'inline-block'
}
},
template: '<span class="title">Visit URL:&nbsp;</span> <a href="#" class="url" target="_blank" href="about:blank"></a> <input class="input" type="text"> <span>&nbsp;&#45;&nbsp;</span> <a href="javascript:;" class="change">Change</a> <a href="javascript:;" class="done">Done</a>'
};
function LinkTooltip(quill, options) {
this.quill = quill;
this.options = options;
this.options.styles = _.defaults(this.options.styles, Tooltip.DEFAULTS.styles);
this.options = _.defaults(this.options, Tooltip.DEFAULTS);
LinkTooltip.__super__.constructor.call(this, this.quill, this.options);
dom(this.container).addClass('link-tooltip-container');
this.textbox = this.container.querySelector('.input');
this.link = this.container.querySelector('.url');
this.initListeners();
}
LinkTooltip.prototype.initListeners = function() {
this.quill.on(this.quill.constructor.events.SELECTION_CHANGE, (function(_this) {
return function(range) {
var anchor;
if (!((range != null) && range.isCollapsed())) {
return;
}
anchor = _this._findAnchor(range);
if (anchor) {
_this.setMode(anchor.href, false);
return _this.show(anchor);
} else {
_this.range = null;
return _this.hide();
}
};
})(this));
dom(this.container.querySelector('.done')).on('click', _.bind(this.saveLink, this));
dom(this.container.querySelector('.change')).on('click', (function(_this) {
return function() {
return _this.setMode(_this.link.href, true);
};
})(this));
this.initTextbox(this.textbox, this.saveLink, this.hide);
return this.quill.onModuleLoad('toolbar', (function(_this) {
return function(toolbar) {
return toolbar.initFormat('link', _.bind(_this._onToolbar, _this));
};
})(this));
};
LinkTooltip.prototype.saveLink = function() {
var anchor, url;
url = this._normalizeURL(this.textbox.value);
if (this.range != null) {
if (this.range.isCollapsed()) {
anchor = this._findAnchor(this.range);
if (anchor != null) {
anchor.href = url;
}
} else {
this.quill.formatText(this.range, 'link', url, 'user');
}
}
return this.setMode(url, false);
};
LinkTooltip.prototype.setMode = function(url, edit) {
var text;
if (edit == null) {
edit = false;
}
if (edit) {
this.textbox.value = url;
_.defer((function(_this) {
return function() {
_this.textbox.focus();
return _this.textbox.setSelectionRange(url.length, url.length);
};
})(this));
} else {
this.link.href = url;
text = url.length > this.options.maxLength ? url.slice(0, this.options.maxLength) + '...' : url;
dom(this.link).text(text);
}
return dom(this.container).toggleClass('editing', edit);
};
LinkTooltip.prototype._findAnchor = function(range) {
var leaf, node, offset, _ref;
_ref = this.quill.editor.doc.findLeafAt(range.start, true), leaf = _ref[0], offset = _ref[1];
if (leaf != null) {
node = leaf.node;
}
while (node != null) {
if (node.tagName === 'A') {
return node;
}
node = node.parentNode;
}
return null;
};
LinkTooltip.prototype._onToolbar = function(range, value) {
var nativeRange;
if (!(range && !range.isCollapsed())) {
return;
}
if (value) {
this.setMode(this._suggestURL(range), true);
nativeRange = this.quill.editor.selection._getNativeRange();
return this.show(nativeRange);
} else {
return this.quill.formatText(range, 'link', false, 'user');
}
};
LinkTooltip.prototype._normalizeURL = function(url) {
if (!/^(https?:\/\/|mailto:)/.test(url)) {
url = 'http://' + url;
}
return url;
};
LinkTooltip.prototype._suggestURL = function(range) {
var text;
text = this.quill.getText(range);
return this._normalizeURL(text);
};
return LinkTooltip;
})(Tooltip);
Quill.registerModule('link-tooltip', LinkTooltip);
module.exports = LinkTooltip;
+226
View File
@@ -0,0 +1,226 @@
var EventEmitter2, MultiCursor, Quill, dom, _,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Quill = require('../quill');
EventEmitter2 = require('eventemitter2').EventEmitter2;
_ = Quill.require('lodash');
dom = Quill.require('dom');
MultiCursor = (function(_super) {
__extends(MultiCursor, _super);
MultiCursor.DEFAULTS = {
template: '<span class="cursor-flag"> <span class="cursor-name"></span> </span> <span class="cursor-caret"></span>',
timeout: 2500
};
MultiCursor.events = {
CURSOR_ADDED: 'cursor-addded',
CURSOR_MOVED: 'cursor-moved',
CURSOR_REMOVED: 'cursor-removed'
};
function MultiCursor(quill, options) {
this.quill = quill;
this.options = options;
this.cursors = {};
this.container = this.quill.addContainer('cursor-container', true);
this.quill.addStyles({
'.cursor-container': {
'position': 'absolute',
'left': '0',
'top': '0',
'z-index': '1000'
},
'.cursor': {
'margin-left': '-1px',
'position': 'absolute'
},
'.cursor-flag': {
'bottom': '100%',
'position': 'absolute',
'white-space': 'nowrap'
},
'.cursor-name': {
'display': 'inline-block',
'color': 'white',
'padding': '2px 8px'
},
'.cursor-caret': {
'height': '100%',
'position': 'absolute',
'width': '2px'
},
'.cursor.hidden .cursor-flag': {
'display': 'none'
},
'.cursor.top > .cursor-flag': {
'bottom': 'auto',
'top': '100%'
},
'.cursor.right > .cursor-flag': {
'right': '-2px'
}
});
this.quill.on(this.quill.constructor.events.TEXT_CHANGE, _.bind(this._applyDelta, this));
}
MultiCursor.prototype.clearCursors = function() {
_.each(_.keys(this.cursors), _.bind(this.removeCursor, this));
return this.cursors = {};
};
MultiCursor.prototype.moveCursor = function(userId, index) {
var cursor;
cursor = this.cursors[userId];
cursor.index = index;
dom(cursor.elem).removeClass('hidden');
clearTimeout(cursor.timer);
cursor.timer = setTimeout((function(_this) {
return function() {
dom(cursor.elem).addClass('hidden');
return cursor.timer = null;
};
})(this), this.options.timeout);
this._updateCursor(cursor);
return cursor;
};
MultiCursor.prototype.removeCursor = function(userId) {
var cursor;
cursor = this.cursors[userId];
this.emit(MultiCursor.events.CURSOR_REMOVED, cursor);
if (cursor != null) {
cursor.elem.parentNode.removeChild(cursor.elem);
}
return delete this.cursors[userId];
};
MultiCursor.prototype.setCursor = function(userId, index, name, color) {
var cursor;
if (this.cursors[userId] == null) {
this.cursors[userId] = cursor = {
userId: userId,
index: index,
color: color,
elem: this._buildCursor(name, color)
};
this.emit(MultiCursor.events.CURSOR_ADDED, cursor);
}
_.defer((function(_this) {
return function() {
return _this.moveCursor(userId, index);
};
})(this));
return this.cursors[userId];
};
MultiCursor.prototype.shiftCursors = function(index, length, authorId) {
if (authorId == null) {
authorId = null;
}
return _.each(this.cursors, (function(_this) {
return function(cursor, id) {
if (!(cursor && (cursor.index > index || cursor.userId === authorId))) {
return;
}
return cursor.index += Math.max(length, index - cursor.index);
};
})(this));
};
MultiCursor.prototype.update = function() {
return _.each(this.cursors, (function(_this) {
return function(cursor, id) {
if (cursor == null) {
return;
}
_this._updateCursor(cursor);
return true;
};
})(this));
};
MultiCursor.prototype._applyDelta = function(delta) {
var index;
index = 0;
_.each(delta.ops, (function(_this) {
return function(op) {
var length, _ref;
length = 0;
if (op.insert != null) {
length = op.insert.length || 1;
_this.shiftCursors(index, length, (_ref = op.attributes) != null ? _ref['author'] : void 0);
} else if (op["delete"] != null) {
_this.shiftCursors(index, -1 * op["delete"], null);
} else if (op.retain != null) {
_this.shiftCursors(index, 0, null);
length = op.retain;
}
return index += length;
};
})(this));
return this.update();
};
MultiCursor.prototype._buildCursor = function(name, color) {
var cursor, cursorCaret, cursorFlag, cursorName;
cursor = this.container.ownerDocument.createElement('span');
dom(cursor).addClass('cursor');
cursor.innerHTML = this.options.template;
cursorFlag = cursor.querySelector('.cursor-flag');
cursorName = cursor.querySelector('.cursor-name');
dom(cursorName).text(name);
cursorCaret = cursor.querySelector('.cursor-caret');
cursorCaret.style.backgroundColor = cursorName.style.backgroundColor = color;
this.container.appendChild(cursor);
return cursor;
};
MultiCursor.prototype._moveCursor = function(cursor, reference, side) {
var bounds, flag, win;
if (side == null) {
side = 'left';
}
win = dom(reference).window();
bounds = reference.getBoundingClientRect();
cursor.elem.style.top = bounds.top + win.pageYOffset + 'px';
cursor.elem.style.left = bounds[side] + 'px';
cursor.elem.style.height = bounds.height + 'px';
flag = cursor.elem.querySelector('.cursor-flag');
dom(cursor.elem).toggleClass('top', parseInt(cursor.elem.style.top) <= flag.offsetHeight).toggleClass('left', parseInt(cursor.elem.style.left) <= flag.offsetWidth).toggleClass('right', this.quill.root.offsetWidth - parseInt(cursor.elem.style.left) <= flag.offsetWidth);
return this.emit(MultiCursor.events.CURSOR_MOVED, cursor);
};
MultiCursor.prototype._updateCursor = function(cursor) {
var didSplit, guide, leaf, leftNode, offset, rightNode, _ref, _ref1;
this.quill.editor.checkUpdate();
_ref = this.quill.editor.doc.findLeafAt(cursor.index, true), leaf = _ref[0], offset = _ref[1];
guide = this.container.ownerDocument.createElement('span');
if (leaf != null) {
_ref1 = dom(leaf.node).split(offset), leftNode = _ref1[0], rightNode = _ref1[1], didSplit = _ref1[2];
dom(guide).text(dom.ZERO_WIDTH_NOBREAK_SPACE);
leaf.node.parentNode.insertBefore(guide, rightNode);
} else {
dom(guide).text(dom.NOBREAK_SPACE);
this.quill.root.appendChild(guide);
}
this._moveCursor(cursor, guide);
dom(guide).remove();
if (didSplit) {
dom(leaf.node.parentNode).normalize();
}
return this.quill.editor.selection.update(Quill.sources.SILENT);
};
return MultiCursor;
})(EventEmitter2);
Quill.registerModule('multi-cursor', MultiCursor);
module.exports = MultiCursor;
+74
View File
@@ -0,0 +1,74 @@
var Delta, Document, PasteManager, Quill, dom, _;
Quill = require('../quill');
Document = require('../core/document');
_ = Quill.require('lodash');
dom = Quill.require('dom');
Delta = Quill.require('delta');
PasteManager = (function() {
function PasteManager(quill, options) {
this.quill = quill;
this.options = options;
this.container = this.quill.addContainer('paste-container');
this.container.setAttribute('contenteditable', true);
this.quill.addStyles({
'.paste-container': {
'left': '-10000px',
'position': 'absolute',
'top': '50%'
}
});
dom(this.quill.root).on('paste', _.bind(this._paste, this));
}
PasteManager.prototype._paste = function() {
var iframe, iframeScrollY, oldDocLength, range, windowScrollX, windowScrollY;
oldDocLength = this.quill.getLength();
range = this.quill.getSelection();
if (range == null) {
return;
}
this.container.innerHTML = "";
iframe = dom(this.quill.root).window();
iframeScrollY = iframe.scrollY;
windowScrollX = window.scrollX;
windowScrollY = window.scrollY;
this.container.focus();
return _.defer((function(_this) {
return function() {
var delta, doc, lengthAdded, line, lineBottom, offset, _ref;
doc = new Document(_this.container, _this.quill.options);
delta = doc.toDelta();
lengthAdded = delta.length() - 1;
delta.compose(new Delta().retain(lengthAdded)["delete"](1));
if (range.start > 0) {
delta.ops.unshift({
retain: range.start
});
}
delta["delete"](range.end - range.start);
_this.quill.updateContents(delta, 'user');
_this.quill.setSelection(range.start + lengthAdded, range.start + lengthAdded);
_ref = _this.quill.editor.doc.findLineAt(range.start + lengthAdded), line = _ref[0], offset = _ref[1];
lineBottom = line.node.offsetTop + line.node.offsetHeight;
if (lineBottom > iframeScrollY + _this.quill.root.offsetHeight) {
iframeScrollY = line.node.offsetTop - _this.quill.root.offsetHeight / 2;
}
iframe.scrollTo(0, iframeScrollY);
return window.scrollTo(windowScrollX, windowScrollY);
};
})(this));
};
return PasteManager;
})();
Quill.registerModule('paste-manager', PasteManager);
module.exports = PasteManager;
+261
View File
@@ -0,0 +1,261 @@
var Quill, Toolbar, dom, _;
Quill = require('../quill');
_ = Quill.require('lodash');
dom = Quill.require('dom');
Toolbar = (function() {
Toolbar.DEFAULTS = {
container: null
};
Toolbar.formats = {
LINE: {
'align': 'align',
'bullet': 'bullet',
'list': 'list'
},
SELECT: {
'align': 'align',
'background': 'background',
'color': 'color',
'font': 'font',
'size': 'size'
},
TOGGLE: {
'bold': 'bold',
'bullet': 'bullet',
'image': 'image',
'italic': 'italic',
'link': 'link',
'list': 'list',
'strike': 'strike',
'underline': 'underline'
},
TOOLTIP: {
'image': 'image',
'link': 'link'
}
};
function Toolbar(quill, options) {
this.quill = quill;
this.options = options;
if (this.options.container == null) {
throw new Error('container required for toolbar', this.options);
}
this.container = _.isString(this.options.container) ? document.querySelector(this.options.container) : this.options.container;
this.inputs = {};
this.preventUpdate = false;
this.triggering = false;
_.each(this.quill.options.formats, (function(_this) {
return function(format) {
if (Toolbar.formats.TOOLTIP[format] != null) {
return;
}
return _this.initFormat(format, function(range, value) {
if (_this.triggering) {
return;
}
if (range.isCollapsed()) {
_this.quill.prepareFormat(format, value);
} else if (Toolbar.formats.LINE[format] != null) {
_this.quill.formatLine(range, format, value, 'user');
} else {
_this.quill.formatText(range, format, value, 'user');
}
return _.defer(function() {
_this.updateActive(range, ['bullet', 'list']);
return _this.setActive(format, value);
});
});
};
})(this));
this.quill.on(this.quill.constructor.events.SELECTION_CHANGE, (function(_this) {
return function(range) {
if (range != null) {
return _this.updateActive(range);
}
};
})(this));
this.quill.onModuleLoad('keyboard', (function(_this) {
return function(keyboard) {
return keyboard.addHotkey([dom.KEYS.BACKSPACE, dom.KEYS.DELETE, dom.KEYS.ENTER], function() {
return _.defer(_.bind(_this.updateActive, _this));
});
};
})(this));
dom(this.container).addClass('ql-toolbar-container');
if (dom.isIOS()) {
dom(this.container).addClass('ios');
}
if (dom.isIE(11)) {
dom(this.container).on('mousedown', (function(_this) {
return function() {
return false;
};
})(this));
}
}
Toolbar.prototype.initFormat = function(format, callback) {
var eventName, input, selector;
selector = ".ql-" + format;
if (Toolbar.formats.SELECT[format] != null) {
selector = "select" + selector;
eventName = 'change';
} else {
eventName = 'click';
}
input = this.container.querySelector(selector);
if (input == null) {
return;
}
this.inputs[format] = input;
return dom(input).on(eventName, (function(_this) {
return function() {
var range, value;
value = eventName === 'change' ? dom(input).value() : !dom(input).hasClass('ql-active');
_this.preventUpdate = true;
_this.quill.focus();
range = _this.quill.getSelection();
if (range != null) {
callback(range, value);
}
_this.preventUpdate = false;
return true;
};
})(this));
};
Toolbar.prototype.setActive = function(format, value) {
var $input, input, selectValue, _ref;
input = this.inputs[format];
if (input == null) {
return;
}
$input = dom(input);
if (input.tagName === 'SELECT') {
this.triggering = true;
selectValue = $input.value(input);
if (value == null) {
value = (_ref = $input["default"]()) != null ? _ref.value : void 0;
}
if (_.isArray(value)) {
value = '';
}
if (value !== selectValue) {
if (value != null) {
$input.option(value, false);
} else {
$input.reset(false);
}
}
return this.triggering = false;
} else {
return $input.toggleClass('ql-active', value || false);
}
};
Toolbar.prototype.updateActive = function(range, formats) {
var activeFormats;
if (formats == null) {
formats = null;
}
range || (range = this.quill.getSelection());
if (!((range != null) && !this.preventUpdate)) {
return;
}
activeFormats = this._getActive(range);
return _.each(this.inputs, (function(_this) {
return function(input, format) {
if (!_.isArray(formats) || formats.indexOf(format) > -1) {
_this.setActive(format, activeFormats[format]);
}
return true;
};
})(this));
};
Toolbar.prototype._getActive = function(range) {
var leafFormats, lineFormats;
leafFormats = this._getLeafActive(range);
lineFormats = this._getLineActive(range);
return _.defaults({}, leafFormats, lineFormats);
};
Toolbar.prototype._getLeafActive = function(range) {
var contents, formatsArr, line, offset, _ref;
if (range.isCollapsed()) {
_ref = this.quill.editor.doc.findLineAt(range.start), line = _ref[0], offset = _ref[1];
if (offset === 0) {
contents = this.quill.getContents(range.start, range.end + 1);
} else {
contents = this.quill.getContents(range.start - 1, range.end);
}
} else {
contents = this.quill.getContents(range);
}
formatsArr = _.map(contents.ops, 'attributes');
return this._intersectFormats(formatsArr);
};
Toolbar.prototype._getLineActive = function(range) {
var firstLine, formatsArr, lastLine, offset, _ref, _ref1;
formatsArr = [];
_ref = this.quill.editor.doc.findLineAt(range.start), firstLine = _ref[0], offset = _ref[1];
_ref1 = this.quill.editor.doc.findLineAt(range.end), lastLine = _ref1[0], offset = _ref1[1];
if ((lastLine != null) && lastLine === firstLine) {
lastLine = lastLine.next;
}
while ((firstLine != null) && firstLine !== lastLine) {
formatsArr.push(_.clone(firstLine.formats));
firstLine = firstLine.next;
}
return this._intersectFormats(formatsArr);
};
Toolbar.prototype._intersectFormats = function(formatsArr) {
return _.reduce(formatsArr.slice(1), function(activeFormats, formats) {
var activeKeys, added, formatKeys, intersection, missing;
activeKeys = _.keys(activeFormats);
formatKeys = _.keys(formats);
intersection = _.intersection(activeKeys, formatKeys);
missing = _.difference(activeKeys, formatKeys);
added = _.difference(formatKeys, activeKeys);
_.each(intersection, function(name) {
if (Toolbar.formats.SELECT[name] != null) {
if (_.isArray(activeFormats[name])) {
if (_.indexOf(activeFormats[name], formats[name]) < 0) {
return activeFormats[name].push(formats[name]);
}
} else if (activeFormats[name] !== formats[name]) {
return activeFormats[name] = [activeFormats[name], formats[name]];
}
}
});
_.each(missing, function(name) {
if (Toolbar.formats.TOGGLE[name] != null) {
return delete activeFormats[name];
} else if ((Toolbar.formats.SELECT[name] != null) && !_.isArray(activeFormats[name])) {
return activeFormats[name] = [activeFormats[name]];
}
});
_.each(added, function(name) {
if (Toolbar.formats.SELECT[name] != null) {
return activeFormats[name] = [formats[name]];
}
});
return activeFormats;
}, formatsArr[0] || {});
};
return Toolbar;
})();
Quill.registerModule('toolbar', Toolbar);
module.exports = Toolbar;
+138
View File
@@ -0,0 +1,138 @@
var Normalizer, Quill, Tooltip, dom, _;
Quill = require('../quill');
Normalizer = require('../lib/normalizer');
_ = Quill.require('lodash');
dom = Quill.require('dom');
Tooltip = (function() {
Tooltip.DEFAULTS = {
offset: 10,
styles: {
'.tooltip': {
'background-color': '#fff',
'border': '1px solid #000',
'top': '0px',
'white-space': 'nowrap',
'z-index': '2000'
},
'.tooltip a': {
'cursor': 'pointer',
'text-decoration': 'none'
}
},
template: ''
};
Tooltip.HIDE_MARGIN = '-10000px';
function Tooltip(quill, options) {
this.quill = quill;
this.options = options;
this.quill.addStyles(this.options.styles);
this.container = this.quill.addContainer('tooltip');
this.container.innerHTML = Normalizer.stripWhitespace(this.options.template);
this.container.style.position = 'absolute';
dom(this.quill.root).on('focus', _.bind(this.hide, this));
this.hide();
this.quill.on(this.quill.constructor.events.TEXT_CHANGE, (function(_this) {
return function(delta, source) {
if (source === 'user' && _this.container.style.left !== Tooltip.HIDE_MARGIN) {
_this.range = null;
return _this.hide();
}
};
})(this));
}
Tooltip.prototype.initTextbox = function(textbox, enterCallback, escapeCallback) {
return dom(textbox).on('keyup', (function(_this) {
return function(event) {
switch (event.which) {
case dom.KEYS.ENTER:
return enterCallback.call(_this);
case dom.KEYS.ESCAPE:
return escapeCallback.call(_this);
default:
return true;
}
};
})(this));
};
Tooltip.prototype.hide = function() {
this.container.style.left = Tooltip.HIDE_MARGIN;
if (this.range) {
this.quill.setSelection(this.range);
}
return this.range = null;
};
Tooltip.prototype.show = function(reference) {
var left, top, win, _ref, _ref1;
this.range = this.quill.getSelection();
_ref = this._position(reference), left = _ref[0], top = _ref[1];
_ref1 = this._limit(left, top), left = _ref1[0], top = _ref1[1];
win = dom(this.quill.root).window();
left += win.pageXOffset;
top += win.pageYOffset;
this.container.style.left = "" + left + "px";
this.container.style.top = "" + top + "px";
return this.container.focus();
};
Tooltip.prototype._getBounds = function() {
var bounds, scrollX, scrollY, win;
bounds = this.quill.root.getBoundingClientRect();
win = dom(this.quill.root).window();
scrollX = win.pageXOffset;
scrollY = win.pageYOffset;
return {
left: bounds.left + scrollX,
right: bounds.right + scrollX,
top: bounds.top + scrollY,
bottom: bounds.bottom + scrollY,
width: bounds.width,
height: bounds.height
};
};
Tooltip.prototype._limit = function(left, top) {
var editorRect, toolbarRect;
editorRect = this._getBounds();
toolbarRect = this.container.getBoundingClientRect();
left = Math.min(editorRect.right - toolbarRect.width, left);
left = Math.max(editorRect.left, left);
top = Math.min(editorRect.bottom - toolbarRect.height, top);
top = Math.max(editorRect.top, top);
return [left, top];
};
Tooltip.prototype._position = function(reference) {
var editorRect, left, referenceBounds, toolbarRect, top;
toolbarRect = this.container.getBoundingClientRect();
editorRect = this._getBounds();
if (reference != null) {
referenceBounds = reference.getBoundingClientRect();
left = referenceBounds.left + referenceBounds.width / 2 - toolbarRect.width / 2;
top = referenceBounds.top + referenceBounds.height + this.options.offset;
if (top + toolbarRect.height > editorRect.bottom) {
top = referenceBounds.top - toolbarRect.height - this.options.offset;
}
} else {
left = editorRect.left + editorRect.width / 2 - toolbarRect.width / 2;
top = editorRect.top + editorRect.height / 2 - toolbarRect.height / 2;
}
return [left, top];
};
return Tooltip;
})();
Quill.registerModule('tooltip', Tooltip);
module.exports = Tooltip;
+145
View File
@@ -0,0 +1,145 @@
var Delta, Quill, UndoManager, _;
Quill = require('../quill');
_ = Quill.require('lodash');
Delta = Quill.require('delta');
UndoManager = (function() {
UndoManager.DEFAULTS = {
delay: 1000,
maxStack: 100
};
UndoManager.hotkeys = {
UNDO: {
key: 'Z',
metaKey: true
},
REDO: {
key: 'Z',
metaKey: true,
shiftKey: true
}
};
function UndoManager(quill, options) {
this.quill = quill;
this.options = options != null ? options : {};
this.lastRecorded = 0;
this.emittedDelta = null;
this.clear();
this.initListeners();
}
UndoManager.prototype.initListeners = function() {
this.quill.onModuleLoad('keyboard', (function(_this) {
return function(keyboard) {
keyboard.addHotkey(UndoManager.hotkeys.UNDO, function() {
_this.undo();
return false;
});
return keyboard.addHotkey(UndoManager.hotkeys.REDO, function() {
_this.redo();
return false;
});
};
})(this));
return this.quill.on(this.quill.constructor.events.TEXT_CHANGE, (function(_this) {
return function(delta, origin) {
if (_.isEqual(delta, _this.emittedDelta)) {
return;
}
_this.record(delta, _this.oldDelta);
return _this.oldDelta = _this.quill.getContents();
};
})(this));
};
UndoManager.prototype.clear = function() {
this.stack = {
undo: [],
redo: []
};
return this.oldDelta = this.quill.getContents();
};
UndoManager.prototype.record = function(changeDelta, oldDelta) {
var change, ignored, timestamp, undoDelta;
if (!(changeDelta.ops.length > 0)) {
return;
}
this.stack.redo = [];
try {
undoDelta = this.quill.getContents().diff(this.oldDelta);
timestamp = new Date().getTime();
if (this.lastRecorded + this.options.delay > timestamp && this.stack.undo.length > 0) {
change = this.stack.undo.pop();
undoDelta = undoDelta.compose(change.undo);
changeDelta = change.redo.compose(changeDelta);
} else {
this.lastRecorded = timestamp;
}
this.stack.undo.push({
redo: changeDelta,
undo: undoDelta
});
if (this.stack.undo.length > this.options.maxStack) {
return this.stack.undo.unshift();
}
} catch (_error) {
ignored = _error;
return this.clear();
}
};
UndoManager.prototype.redo = function() {
return this._change('redo', 'undo');
};
UndoManager.prototype.undo = function() {
return this._change('undo', 'redo');
};
UndoManager.prototype._getLastChangeIndex = function(delta) {
var index, lastIndex;
lastIndex = 0;
index = 0;
delta.ops.forEach(function(op) {
if (op.insert != null) {
return lastIndex = Math.max(index + (op.insert.length || 1), lastIndex);
} else if (op["delete"] != null) {
return lastIndex = Math.max(index, lastIndex);
} else if (op.retain != null) {
if (op.attributes != null) {
lastIndex = Math.max(index + op.retain, lastIndex);
}
return index += op.retain;
}
});
return lastIndex;
};
UndoManager.prototype._change = function(source, dest) {
var change, index;
if (this.stack[source].length > 0) {
change = this.stack[source].pop();
this.lastRecorded = 0;
this.emittedDelta = change[source];
this.quill.updateContents(change[source], 'user');
this.emittedDelta = null;
index = this._getLastChangeIndex(change[source]);
this.quill.setSelection(index, index);
this.oldDelta = this.quill.getContents();
return this.stack[dest].push(change);
}
};
return UndoManager;
})();
Quill.registerModule('undo-manager', UndoManager);
module.exports = UndoManager;