Socket
Socket
Sign inDemoInstall

quill

Package Overview
Dependencies
7
Maintainers
2
Versions
94
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0-dev.4 to 2.0.0-rc.0

blots/block.d.ts

158

blots/block.js

@@ -1,22 +0,19 @@

import extend from 'extend';
import Delta from 'quill-delta';
import {
AttributorStore,
BlockBlot,
EmbedBlot,
LeafBlot,
Scope,
} from 'parchment';
import Break from './break';
import Inline from './inline';
import TextBlot from './text';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.BlockEmbed = void 0;
exports.blockDelta = blockDelta;
exports.bubbleFormats = bubbleFormats;
exports.default = void 0;
var _parchment = require("parchment");
var _quillDelta = _interopRequireDefault(require("quill-delta"));
var _break = _interopRequireDefault(require("./break"));
var _inline = _interopRequireDefault(require("./inline"));
var _text = _interopRequireDefault(require("./text"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const NEWLINE_LENGTH = 1;
class Block extends BlockBlot {
constructor(scroll, domNode) {
super(scroll, domNode);
this.cache = {};
}
class Block extends _parchment.BlockBlot {
cache = {};
delta() {

@@ -28,3 +25,2 @@ if (this.cache.delta == null) {

}
deleteAt(index, length) {

@@ -34,6 +30,5 @@ super.deleteAt(index, length);

}
formatAt(index, length, name, value) {
if (length <= 0) return;
if (this.scroll.query(name, Scope.BLOCK)) {
if (this.scroll.query(name, _parchment.Scope.BLOCK)) {
if (index + length === this.length()) {

@@ -43,12 +38,6 @@ this.format(name, value);

} else {
super.formatAt(
index,
Math.min(length, this.length() - index - 1),
name,
value,
);
super.formatAt(index, Math.min(length, this.length() - index - 1), name, value);
}
this.cache = {};
}
insertAt(index, value, def) {

@@ -71,4 +60,7 @@ if (def != null) {

}
// TODO: Fix this next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-this-alias
let block = this;
lines.reduce((lineIndex, line) => {
// @ts-expect-error Fix me later
block = block.split(lineIndex, true);

@@ -79,7 +71,8 @@ block.insertAt(0, line);

}
insertBefore(blot, ref) {
const { head } = this.children;
const {
head
} = this.children;
super.insertBefore(blot, ref);
if (head instanceof Break) {
if (head instanceof _break.default) {
head.remove();

@@ -89,3 +82,2 @@ }

}
length() {

@@ -97,8 +89,7 @@ if (this.cache.length == null) {

}
moveChildren(target, ref) {
// @ts-expect-error Parchment types are wrong
super.moveChildren(target, ref);
this.cache = {};
}
optimize(context) {

@@ -108,7 +99,5 @@ super.optimize(context);

}
path(index) {
return super.path(index, true);
}
removeChild(child) {

@@ -118,4 +107,4 @@ super.removeChild(child);

}
split(index, force = false) {
split(index) {
let force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (force && (index === 0 || index >= this.length() - NEWLINE_LENGTH)) {

@@ -127,2 +116,3 @@ const clone = this.clone();

}
// @ts-expect-error Fix me later
this.parent.insertBefore(clone, this.next);

@@ -136,60 +126,73 @@ return clone;

}
exports.default = Block;
Block.blotName = 'block';
Block.tagName = 'P';
Block.defaultChild = Break;
Block.allowedChildren = [Break, Inline, EmbedBlot, TextBlot];
class BlockEmbed extends EmbedBlot {
Block.defaultChild = _break.default;
Block.allowedChildren = [_break.default, _inline.default, _parchment.EmbedBlot, _text.default];
class BlockEmbed extends _parchment.EmbedBlot {
attach() {
super.attach();
this.attributes = new AttributorStore(this.domNode);
this.attributes = new _parchment.AttributorStore(this.domNode);
}
delta() {
return new Delta().insert(
this.value(),
extend(this.formats(), this.attributes.values()),
);
return new _quillDelta.default().insert(this.value(), {
...this.formats(),
...this.attributes.values()
});
}
format(name, value) {
const attribute = this.scroll.query(name, Scope.BLOCK_ATTRIBUTE);
const attribute = this.scroll.query(name, _parchment.Scope.BLOCK_ATTRIBUTE);
if (attribute != null) {
// @ts-expect-error TODO: Scroll#query() should return Attributor when scope is attribute
this.attributes.attribute(attribute, value);
}
}
formatAt(index, length, name, value) {
this.format(name, value);
}
insertAt(index, value, def) {
if (typeof value === 'string' && value.endsWith('\n')) {
const block = this.scroll.create(Block.blotName);
this.parent.insertBefore(block, index === 0 ? this : this.next);
block.insertAt(0, value.slice(0, -1));
} else {
if (def != null) {
super.insertAt(index, value, def);
return;
}
const lines = value.split('\n');
const text = lines.pop();
const blocks = lines.map(line => {
const block = this.scroll.create(Block.blotName);
block.insertAt(0, line);
return block;
});
const ref = this.split(index);
blocks.forEach(block => {
// @ts-expect-error Fix me later
this.parent.insertBefore(block, ref);
});
if (text) {
// @ts-expect-error Fix me later
this.parent.insertBefore(this.scroll.create('text', text), ref);
}
}
}
BlockEmbed.scope = Scope.BLOCK_BLOT;
exports.BlockEmbed = BlockEmbed;
BlockEmbed.scope = _parchment.Scope.BLOCK_BLOT;
// It is important for cursor behavior BlockEmbeds use tags that are block level elements
function blockDelta(blot, filter = true) {
return blot
.descendants(LeafBlot)
.reduce((delta, leaf) => {
if (leaf.length() === 0) {
return delta;
}
return delta.insert(leaf.value(), bubbleFormats(leaf, {}, filter));
}, new Delta())
.insert('\n', bubbleFormats(blot));
function blockDelta(blot) {
let filter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
return blot.descendants(_parchment.LeafBlot).reduce((delta, leaf) => {
if (leaf.length() === 0) {
return delta;
}
return delta.insert(leaf.value(), bubbleFormats(leaf, {}, filter));
}, new _quillDelta.default()).insert('\n', bubbleFormats(blot));
}
function bubbleFormats(blot, formats = {}, filter = true) {
function bubbleFormats(blot) {
let formats = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
let filter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
if (blot == null) return formats;
if (typeof blot.formats === 'function') {
formats = extend(formats, blot.formats());
if ('formats' in blot && typeof blot.formats === 'function') {
formats = {
...formats,
...blot.formats()
};
if (filter) {

@@ -200,7 +203,3 @@ // exclude syntax highlighting from deltas and getFormat()

}
if (
blot.parent == null ||
blot.parent.statics.blotName === 'scroll' ||
blot.parent.statics.scope !== blot.statics.scope
) {
if (blot.parent == null || blot.parent.statics.blotName === 'scroll' || blot.parent.statics.scope !== blot.statics.scope) {
return formats;

@@ -210,3 +209,2 @@ }

}
export { blockDelta, bubbleFormats, BlockEmbed, Block as default };
//# sourceMappingURL=block.js.map

@@ -1,8 +0,12 @@

import { EmbedBlot } from 'parchment';
"use strict";
class Break extends EmbedBlot {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _parchment = require("parchment");
class Break extends _parchment.EmbedBlot {
static value() {
return undefined;
}
optimize() {

@@ -13,7 +17,5 @@ if (this.prev || this.next) {

}
length() {
return 0;
}
value() {

@@ -25,3 +27,3 @@ return '';

Break.tagName = 'BR';
export default Break;
var _default = exports.default = Break;
//# sourceMappingURL=break.js.map

@@ -1,5 +0,10 @@

import { ContainerBlot } from 'parchment';
"use strict";
class Container extends ContainerBlot {}
export default Container;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _parchment = require("parchment");
class Container extends _parchment.ContainerBlot {}
var _default = exports.default = Container;
//# sourceMappingURL=container.js.map

@@ -1,9 +0,19 @@

import { EmbedBlot, Scope } from 'parchment';
import TextBlot from './text';
"use strict";
class Cursor extends EmbedBlot {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _parchment = require("parchment");
var _text = _interopRequireDefault(require("./text"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class Cursor extends _parchment.EmbedBlot {
static blotName = 'cursor';
static className = 'ql-cursor';
static tagName = 'span';
static CONTENTS = '\uFEFF'; // Zero width no break space
static value() {
return undefined;
}
constructor(scroll, domNode, selection) {

@@ -16,3 +26,2 @@ super(scroll, domNode);

}
detach() {

@@ -22,3 +31,2 @@ // super.detach() will also clear domNode.__blot

}
format(name, value) {

@@ -29,5 +37,7 @@ if (this.savedLength !== 0) {

}
// TODO: Fix this next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-this-alias
let target = this;
let index = 0;
while (target != null && target.statics.scope !== Scope.BLOCK_BLOT) {
while (target != null && target.statics.scope !== _parchment.Scope.BLOCK_BLOT) {
index += target.offset(target.parent);

@@ -38,2 +48,3 @@ target = target.parent;

this.savedLength = Cursor.CONTENTS.length;
// @ts-expect-error TODO: allow empty context in Parchment
target.optimize();

@@ -44,3 +55,2 @@ target.formatAt(index, Cursor.CONTENTS.length, name, value);

}
index(node, offset) {

@@ -50,35 +60,30 @@ if (node === this.textNode) return 0;

}
length() {
return this.savedLength;
}
position() {
return [this.textNode, this.textNode.data.length];
}
remove() {
super.remove();
// @ts-expect-error Fix me later
this.parent = null;
}
restore() {
if (this.selection.composing || this.parent == null) return null;
const range = this.selection.getNativeRange();
// Link format will insert text outside of anchor tag
while (
this.domNode.lastChild != null &&
this.domNode.lastChild !== this.textNode
) {
this.domNode.parentNode.insertBefore(
this.domNode.lastChild,
this.domNode,
);
// Browser may push down styles/nodes inside the cursor blot.
// https://dvcs.w3.org/hg/editing/raw-file/tip/editing.html#push-down-values
while (this.domNode.lastChild != null && this.domNode.lastChild !== this.textNode) {
// @ts-expect-error Fix me later
this.domNode.parentNode.insertBefore(this.domNode.lastChild, this.domNode);
}
const prevTextBlot = this.prev instanceof TextBlot ? this.prev : null;
const prevTextBlot = this.prev instanceof _text.default ? this.prev : null;
const prevTextLength = prevTextBlot ? prevTextBlot.length() : 0;
const nextTextBlot = this.next instanceof TextBlot ? this.next : null;
const nextTextBlot = this.next instanceof _text.default ? this.next : null;
// @ts-expect-error TODO: make TextBlot.text public
const nextText = nextTextBlot ? nextTextBlot.text : '';
const { textNode } = this;
const {
textNode
} = this;
// take text from inside this blot and reset it

@@ -109,3 +114,2 @@ const newText = textNode.data.split(Cursor.CONTENTS).join('');

}
this.remove();

@@ -126,3 +130,2 @@ if (range) {

};
const start = remapOffset(range.start.node, range.start.offset);

@@ -135,3 +138,3 @@ const end = remapOffset(range.end.node, range.end.offset);

endNode: mergedTextBlot.domNode,
endOffset: end,
endOffset: end
};

@@ -142,11 +145,6 @@ }

}
update(mutations, context) {
if (
mutations.some(mutation => {
return (
mutation.type === 'characterData' && mutation.target === this.textNode
);
})
) {
if (mutations.some(mutation => {
return mutation.type === 'characterData' && mutation.target === this.textNode;
})) {
const range = this.restore();

@@ -157,2 +155,29 @@ if (range) context.range = range;

// Avoid .ql-cursor being a descendant of `<a/>`.
// The reason is Safari pushes down `<a/>` on text insertion.
// That will cause DOM nodes not sync with the model.
//
// For example ({I} is the caret), given the markup:
// <a><span class="ql-cursor">\uFEFF{I}</span></a>
// When typing a char "x", `<a/>` will be pushed down inside the `<span>` first:
// <span class="ql-cursor"><a>\uFEFF{I}</a></span>
// And then "x" will be inserted after `<a/>`:
// <span class="ql-cursor"><a>\uFEFF</a>d{I}</span>
optimize(context) {
// @ts-expect-error Fix me later
super.optimize(context);
let {
parent
} = this;
while (parent) {
if (parent.domNode.tagName === 'A') {
this.savedLength = Cursor.CONTENTS.length;
// @ts-expect-error TODO: make isolate generic
parent.isolate(this.offset(parent), this.length()).unwrap();
this.savedLength = 0;
break;
}
parent = parent.parent;
}
}
value() {

@@ -162,7 +187,3 @@ return '';

}
Cursor.blotName = 'cursor';
Cursor.className = 'ql-cursor';
Cursor.tagName = 'span';
Cursor.CONTENTS = '\uFEFF'; // Zero width no break space
export default Cursor;
var _default = exports.default = Cursor;
//# sourceMappingURL=cursor.js.map

@@ -1,11 +0,16 @@

import { EmbedBlot } from 'parchment';
import TextBlot from './text';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _parchment = require("parchment");
var _text = _interopRequireDefault(require("./text"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const GUARD_TEXT = '\uFEFF';
class Embed extends EmbedBlot {
class Embed extends _parchment.EmbedBlot {
constructor(scroll, node) {
super(scroll, node);
this.contentNode = document.createElement('span');
this.contentNode.setAttribute('contenteditable', false);
this.contentNode.setAttribute('contenteditable', 'false');
Array.from(this.domNode.childNodes).forEach(childNode => {

@@ -20,3 +25,2 @@ this.contentNode.appendChild(childNode);

}
index(node, offset) {

@@ -27,9 +31,8 @@ if (node === this.leftGuard) return 0;

}
restore(node) {
let range;
let range = null;
let textNode;
const text = node.data.split(GUARD_TEXT).join('');
if (node === this.leftGuard) {
if (this.prev instanceof TextBlot) {
if (this.prev instanceof _text.default) {
const prevLength = this.prev.length();

@@ -39,3 +42,3 @@ this.prev.insertAt(prevLength, text);

startNode: this.prev.domNode,
startOffset: prevLength + text.length,
startOffset: prevLength + text.length
};

@@ -47,18 +50,19 @@ } else {

startNode: textNode,
startOffset: text.length,
startOffset: text.length
};
}
} else if (node === this.rightGuard) {
if (this.next instanceof TextBlot) {
if (this.next instanceof _text.default) {
this.next.insertAt(0, text);
range = {
startNode: this.next.domNode,
startOffset: text.length,
startOffset: text.length
};
} else {
textNode = document.createTextNode(text);
// @ts-expect-error Fix me later
this.parent.insertBefore(this.scroll.create(textNode), this.next);
range = {
startNode: textNode,
startOffset: text.length,
startOffset: text.length
};

@@ -70,10 +74,5 @@ }

}
update(mutations, context) {
mutations.forEach(mutation => {
if (
mutation.type === 'characterData' &&
(mutation.target === this.leftGuard ||
mutation.target === this.rightGuard)
) {
if (mutation.type === 'characterData' && (mutation.target === this.leftGuard || mutation.target === this.rightGuard)) {
const range = this.restore(mutation.target);

@@ -85,3 +84,3 @@ if (range) context.range = range;

}
export default Embed;
var _default = exports.default = Embed;
//# sourceMappingURL=embed.js.map

@@ -1,6 +0,21 @@

import { EmbedBlot, InlineBlot, Scope } from 'parchment';
import Break from './break';
import Text from './text';
"use strict";
class Inline extends InlineBlot {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _parchment = require("parchment");
var _break = _interopRequireDefault(require("./break"));
var _text = _interopRequireDefault(require("./text"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class Inline extends _parchment.InlineBlot {
static allowedChildren = [Inline, _break.default, _parchment.EmbedBlot, _text.default];
// Lower index means deeper in the DOM tree, since not found (-1) is for embeds
static order = ['cursor', 'inline',
// Must be lower
'link',
// Chrome wants <a> to be lower
'underline', 'strike', 'italic', 'bold', 'script', 'code' // Must be higher
];
static compare(self, other) {

@@ -20,8 +35,4 @@ const selfIndex = Inline.order.indexOf(self);

}
formatAt(index, length, name, value) {
if (
Inline.compare(this.statics.blotName, name) < 0 &&
this.scroll.query(name, Scope.BLOT)
) {
if (Inline.compare(this.statics.blotName, name) < 0 && this.scroll.query(name, _parchment.Scope.BLOT)) {
const blot = this.isolate(index, length);

@@ -35,10 +46,7 @@ if (value) {

}
optimize(context) {
super.optimize(context);
if (
this.parent instanceof Inline &&
Inline.compare(this.statics.blotName, this.parent.statics.blotName) > 0
) {
if (this.parent instanceof Inline && Inline.compare(this.statics.blotName, this.parent.statics.blotName) > 0) {
const parent = this.parent.isolate(this.offset(), this.length());
// @ts-expect-error TODO: make isolate generic
this.moveChildren(parent);

@@ -49,16 +57,3 @@ parent.wrap(this);

}
Inline.allowedChildren = [Inline, Break, EmbedBlot, Text];
// Lower index means deeper in the DOM tree, since not found (-1) is for embeds
Inline.order = [
'cursor',
'inline', // Must be lower
'link', // Chrome wants <a> to be lower
'underline',
'strike',
'italic',
'bold',
'script',
'code', // Must be higher
];
export default Inline;
var _default = exports.default = Inline;
//# sourceMappingURL=inline.js.map

@@ -1,13 +0,32 @@

import { Scope, ScrollBlot, ContainerBlot } from 'parchment';
import Emitter from '../core/emitter';
import Block, { BlockEmbed } from './block';
import Break from './break';
import Container from './container';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _parchment = require("parchment");
var _quillDelta = _interopRequireWildcard(require("quill-delta"));
var _emitter = _interopRequireDefault(require("../core/emitter"));
var _block = _interopRequireWildcard(require("./block"));
var _break = _interopRequireDefault(require("./break"));
var _container = _interopRequireDefault(require("./container"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function isLine(blot) {
return blot instanceof Block || blot instanceof BlockEmbed;
return blot instanceof _block.default || blot instanceof _block.BlockEmbed;
}
class Scroll extends ScrollBlot {
constructor(registry, domNode, { emitter }) {
function isUpdatable(blot) {
return typeof blot.updateContent === 'function';
}
class Scroll extends _parchment.ScrollBlot {
static blotName = 'scroll';
static className = 'ql-editor';
static tagName = 'DIV';
static defaultChild = _block.default;
static allowedChildren = [_block.default, _block.BlockEmbed, _container.default];
constructor(registry, domNode, _ref) {
let {
emitter
} = _ref;
super(registry, domNode);

@@ -20,3 +39,2 @@ this.emitter = emitter;

}
batchStart() {

@@ -27,4 +45,4 @@ if (!Array.isArray(this.batch)) {

}
batchEnd() {
if (!this.batch) return;
const mutations = this.batch;

@@ -34,11 +52,11 @@ this.batch = false;

}
emitMount(blot) {
this.emitter.emit(Emitter.events.SCROLL_BLOT_MOUNT, blot);
this.emitter.emit(_emitter.default.events.SCROLL_BLOT_MOUNT, blot);
}
emitUnmount(blot) {
this.emitter.emit(Emitter.events.SCROLL_BLOT_UNMOUNT, blot);
this.emitter.emit(_emitter.default.events.SCROLL_BLOT_UNMOUNT, blot);
}
emitEmbedUpdate(blot, change) {
this.emitter.emit(_emitter.default.events.SCROLL_EMBED_UPDATE, blot, change);
}
deleteAt(index, length) {

@@ -49,9 +67,10 @@ const [first, offset] = this.line(index);

if (last != null && first !== last && offset > 0) {
if (first instanceof BlockEmbed || last instanceof BlockEmbed) {
if (first instanceof _block.BlockEmbed || last instanceof _block.BlockEmbed) {
this.optimize();
return;
}
const ref =
last.children.head instanceof Break ? null : last.children.head;
const ref = last.children.head instanceof _break.default ? null : last.children.head;
// @ts-expect-error
first.moveChildren(last, ref);
// @ts-expect-error
first.remove();

@@ -61,7 +80,6 @@ }

}
enable(enabled = true) {
this.domNode.setAttribute('contenteditable', enabled);
enable() {
let enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
this.domNode.setAttribute('contenteditable', enabled ? 'true' : 'false');
}
formatAt(index, length, format, value) {

@@ -71,10 +89,5 @@ super.formatAt(index, length, format, value);

}
handleDragStart(event) {
event.preventDefault();
}
insertAt(index, value, def) {
if (index >= this.length()) {
if (def == null || this.scroll.query(value, Scope.BLOCK) == null) {
if (def == null || this.scroll.query(value, _parchment.Scope.BLOCK) == null) {
const blot = this.scroll.create(this.statics.defaultChild.blotName);

@@ -96,5 +109,4 @@ this.appendChild(blot);

}
insertBefore(blot, ref) {
if (blot.statics.scope === Scope.INLINE_BLOT) {
if (blot.statics.scope === _parchment.Scope.INLINE_BLOT) {
const wrapper = this.scroll.create(this.statics.defaultChild.blotName);

@@ -107,11 +119,63 @@ wrapper.appendChild(blot);

}
insertContents(index, delta) {
const renderBlocks = this.deltaToRenderBlocks(delta.concat(new _quillDelta.default().insert('\n')));
const last = renderBlocks.pop();
if (last == null) return;
this.batchStart();
const first = renderBlocks.shift();
if (first) {
const shouldInsertNewlineChar = first.type === 'block' && (first.delta.length() === 0 || !this.descendant(_block.BlockEmbed, index)[0] && index < this.length());
const delta = first.type === 'block' ? first.delta : new _quillDelta.default().insert({
[first.key]: first.value
});
insertInlineContents(this, index, delta);
const newlineCharLength = first.type === 'block' ? 1 : 0;
const lineEndIndex = index + delta.length() + newlineCharLength;
if (shouldInsertNewlineChar) {
this.insertAt(lineEndIndex - 1, '\n');
}
const formats = (0, _block.bubbleFormats)(this.line(index)[0]);
const attributes = _quillDelta.AttributeMap.diff(formats, first.attributes) || {};
Object.keys(attributes).forEach(name => {
this.formatAt(lineEndIndex - 1, 1, name, attributes[name]);
});
index = lineEndIndex;
}
let [refBlot, refBlotOffset] = this.children.find(index);
if (renderBlocks.length) {
if (refBlot) {
refBlot = refBlot.split(refBlotOffset);
refBlotOffset = 0;
}
renderBlocks.forEach(renderBlock => {
if (renderBlock.type === 'block') {
const block = this.createBlock(renderBlock.attributes, refBlot || undefined);
insertInlineContents(block, 0, renderBlock.delta);
} else {
const blockEmbed = this.create(renderBlock.key, renderBlock.value);
this.insertBefore(blockEmbed, refBlot || undefined);
Object.keys(renderBlock.attributes).forEach(name => {
blockEmbed.format(name, renderBlock.attributes[name]);
});
}
});
}
if (last.type === 'block' && last.delta.length()) {
const offset = refBlot ? refBlot.offset(refBlot.scroll) + refBlotOffset : this.length();
insertInlineContents(this, offset, last.delta);
}
this.batchEnd();
this.optimize();
}
isEnabled() {
return this.domNode.getAttribute('contenteditable') === 'true';
}
leaf(index) {
return this.path(index).pop() || [null, -1];
const last = this.path(index).pop();
if (!last) {
return [null, -1];
}
const [blot, offset] = last;
return blot instanceof _parchment.LeafBlot ? [blot, offset] : [null, -1];
}
line(index) {

@@ -121,21 +185,19 @@ if (index === this.length()) {

}
// @ts-expect-error TODO: make descendant() generic
return this.descendant(isLine, index);
}
lines(index = 0, length = Number.MAX_VALUE) {
lines() {
let index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
let length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Number.MAX_VALUE;
const getLines = (blot, blotIndex, blotLength) => {
let lines = [];
let lengthLeft = blotLength;
blot.children.forEachAt(
blotIndex,
blotLength,
(child, childIndex, childLength) => {
if (isLine(child)) {
lines.push(child);
} else if (child instanceof ContainerBlot) {
lines = lines.concat(getLines(child, childIndex, lengthLeft));
}
lengthLeft -= childLength;
},
);
blot.children.forEachAt(blotIndex, blotLength, (child, childIndex, childLength) => {
if (isLine(child)) {
lines.push(child);
} else if (child instanceof _parchment.ContainerBlot) {
lines = lines.concat(getLines(child, childIndex, lengthLeft));
}
lengthLeft -= childLength;
});
return lines;

@@ -145,11 +207,11 @@ };

}
optimize(mutations = [], context = {}) {
optimize() {
let mutations = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
let context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (this.batch) return;
super.optimize(mutations, context);
if (mutations.length > 0) {
this.emitter.emit(Emitter.events.SCROLL_OPTIMIZE, mutations, context);
this.emitter.emit(_emitter.default.events.SCROLL_OPTIMIZE, mutations, context);
}
}
path(index) {

@@ -162,3 +224,2 @@ return super.path(index).slice(1); // Exclude self

}
update(mutations) {

@@ -171,3 +232,3 @@ if (this.batch) {

}
let source = Emitter.sources.USER;
let source = _emitter.default.sources.USER;
if (typeof mutations === 'string') {

@@ -179,17 +240,133 @@ source = mutations;

}
mutations = mutations.filter(_ref2 => {
let {
target
} = _ref2;
const blot = this.find(target, true);
return blot && !isUpdatable(blot);
});
if (mutations.length > 0) {
this.emitter.emit(Emitter.events.SCROLL_BEFORE_UPDATE, source, mutations);
this.emitter.emit(_emitter.default.events.SCROLL_BEFORE_UPDATE, source, mutations);
}
super.update(mutations.concat([])); // pass copy
if (mutations.length > 0) {
this.emitter.emit(Emitter.events.SCROLL_UPDATE, source, mutations);
this.emitter.emit(_emitter.default.events.SCROLL_UPDATE, source, mutations);
}
}
updateEmbedAt(index, key, change) {
// Currently it only supports top-level embeds (BlockEmbed).
// We can update `ParentBlot` in parchment to support inline embeds.
const [blot] = this.descendant(b => b instanceof _block.BlockEmbed, index);
if (blot && blot.statics.blotName === key && isUpdatable(blot)) {
blot.updateContent(change);
}
}
handleDragStart(event) {
event.preventDefault();
}
deltaToRenderBlocks(delta) {
const renderBlocks = [];
let currentBlockDelta = new _quillDelta.default();
delta.forEach(op => {
const insert = op?.insert;
if (!insert) return;
if (typeof insert === 'string') {
const splitted = insert.split('\n');
splitted.slice(0, -1).forEach(text => {
currentBlockDelta.insert(text, op.attributes);
renderBlocks.push({
type: 'block',
delta: currentBlockDelta,
attributes: op.attributes ?? {}
});
currentBlockDelta = new _quillDelta.default();
});
const last = splitted[splitted.length - 1];
if (last) {
currentBlockDelta.insert(last, op.attributes);
}
} else {
const key = Object.keys(insert)[0];
if (!key) return;
if (this.query(key, _parchment.Scope.INLINE)) {
currentBlockDelta.push(op);
} else {
if (currentBlockDelta.length()) {
renderBlocks.push({
type: 'block',
delta: currentBlockDelta,
attributes: {}
});
}
currentBlockDelta = new _quillDelta.default();
renderBlocks.push({
type: 'blockEmbed',
key,
value: insert[key],
attributes: op.attributes ?? {}
});
}
}
});
if (currentBlockDelta.length()) {
renderBlocks.push({
type: 'block',
delta: currentBlockDelta,
attributes: {}
});
}
return renderBlocks;
}
createBlock(attributes, refBlot) {
let blotName;
const formats = {};
Object.entries(attributes).forEach(_ref3 => {
let [key, value] = _ref3;
const isBlockBlot = this.query(key, _parchment.Scope.BLOCK & _parchment.Scope.BLOT) != null;
if (isBlockBlot) {
blotName = key;
} else {
formats[key] = value;
}
});
const block = this.create(blotName || this.statics.defaultChild.blotName, blotName ? attributes[blotName] : undefined);
this.insertBefore(block, refBlot || undefined);
const length = block.length();
Object.entries(formats).forEach(_ref4 => {
let [key, value] = _ref4;
block.formatAt(0, length, key, value);
});
return block;
}
}
Scroll.blotName = 'scroll';
Scroll.className = 'ql-editor';
Scroll.tagName = 'DIV';
Scroll.defaultChild = Block;
Scroll.allowedChildren = [Block, BlockEmbed, Container];
export default Scroll;
function insertInlineContents(parent, index, inlineContents) {
inlineContents.reduce((index, op) => {
const length = _quillDelta.Op.length(op);
let attributes = op.attributes || {};
if (op.insert != null) {
if (typeof op.insert === 'string') {
const text = op.insert;
parent.insertAt(index, text);
const [leaf] = parent.descendant(_parchment.LeafBlot, index);
const formats = (0, _block.bubbleFormats)(leaf);
attributes = _quillDelta.AttributeMap.diff(formats, attributes) || {};
} else if (typeof op.insert === 'object') {
const key = Object.keys(op.insert)[0]; // There should only be one key
if (key == null) return index;
parent.insertAt(index, key, op.insert[key]);
const isInlineEmbed = parent.scroll.query(key, _parchment.Scope.INLINE) != null;
if (isInlineEmbed) {
const [leaf] = parent.descendant(_parchment.LeafBlot, index);
const formats = (0, _block.bubbleFormats)(leaf);
attributes = _quillDelta.AttributeMap.diff(formats, attributes) || {};
}
}
}
Object.keys(attributes).forEach(key => {
parent.formatAt(index, length, key, attributes[key]);
});
return index + length;
}, index);
}
var _default = exports.default = Scroll;
//# sourceMappingURL=scroll.js.map

@@ -1,5 +0,11 @@

import { TextBlot } from 'parchment';
"use strict";
class Text extends TextBlot {}
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
exports.escapeText = escapeText;
var _parchment = require("parchment");
class Text extends _parchment.TextBlot {}
exports.default = Text;
function escapeText(text) {

@@ -13,3 +19,3 @@ return text.replace(/[&<>"']/g, s => {

'"': '&quot;',
"'": '&#39;',
"'": '&#39;'
};

@@ -19,3 +25,2 @@ return entityMap[s];

}
export { Text as default, escapeText };
//# sourceMappingURL=text.js.map

@@ -1,34 +0,68 @@

import Quill from './core/quill';
"use strict";
import Block, { BlockEmbed } from './blots/block';
import Break from './blots/break';
import Container from './blots/container';
import Cursor from './blots/cursor';
import Embed from './blots/embed';
import Inline from './blots/inline';
import Scroll from './blots/scroll';
import TextBlot from './blots/text';
import Clipboard from './modules/clipboard';
import History from './modules/history';
import Keyboard from './modules/keyboard';
import Uploader from './modules/uploader';
Quill.register({
'blots/block': Block,
'blots/block/embed': BlockEmbed,
'blots/break': Break,
'blots/container': Container,
'blots/cursor': Cursor,
'blots/embed': Embed,
'blots/inline': Inline,
'blots/scroll': Scroll,
'blots/text': TextBlot,
'modules/clipboard': Clipboard,
'modules/history': History,
'modules/keyboard': Keyboard,
'modules/uploader': Uploader,
Object.defineProperty(exports, "__esModule", {
value: true
});
export default Quill;
Object.defineProperty(exports, "AttributeMap", {
enumerable: true,
get: function () {
return _quillDelta.AttributeMap;
}
});
Object.defineProperty(exports, "Delta", {
enumerable: true,
get: function () {
return _quillDelta.default;
}
});
Object.defineProperty(exports, "Op", {
enumerable: true,
get: function () {
return _quillDelta.Op;
}
});
Object.defineProperty(exports, "OpIterator", {
enumerable: true,
get: function () {
return _quillDelta.OpIterator;
}
});
exports.default = void 0;
var _quill = _interopRequireDefault(require("./core/quill"));
var _block = _interopRequireWildcard(require("./blots/block"));
var _break = _interopRequireDefault(require("./blots/break"));
var _container = _interopRequireDefault(require("./blots/container"));
var _cursor = _interopRequireDefault(require("./blots/cursor"));
var _embed = _interopRequireDefault(require("./blots/embed"));
var _inline = _interopRequireDefault(require("./blots/inline"));
var _scroll = _interopRequireDefault(require("./blots/scroll"));
var _text = _interopRequireDefault(require("./blots/text"));
var _clipboard = _interopRequireDefault(require("./modules/clipboard"));
var _history = _interopRequireDefault(require("./modules/history"));
var _keyboard = _interopRequireDefault(require("./modules/keyboard"));
var _uploader = _interopRequireDefault(require("./modules/uploader"));
var _quillDelta = _interopRequireWildcard(require("quill-delta"));
var _input = _interopRequireDefault(require("./modules/input"));
var _uiNode = _interopRequireDefault(require("./modules/uiNode"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
_quill.default.register({
'blots/block': _block.default,
'blots/block/embed': _block.BlockEmbed,
'blots/break': _break.default,
'blots/container': _container.default,
'blots/cursor': _cursor.default,
'blots/embed': _embed.default,
'blots/inline': _inline.default,
'blots/scroll': _scroll.default,
'blots/text': _text.default,
'modules/clipboard': _clipboard.default,
'modules/history': _history.default,
'modules/keyboard': _keyboard.default,
'modules/uploader': _uploader.default,
'modules/input': _input.default,
'modules/uiNode': _uiNode.default
});
var _default = exports.default = _quill.default;
//# sourceMappingURL=core.js.map

@@ -1,14 +0,19 @@

import clone from 'clone';
import equal from 'deep-equal';
import extend from 'extend';
import Delta, { AttributeMap } from 'quill-delta';
import { LeafBlot } from 'parchment';
import { Range } from './selection';
import CursorBlot from '../blots/cursor';
import Block, { BlockEmbed, bubbleFormats } from '../blots/block';
import Break from '../blots/break';
import TextBlot, { escapeText } from '../blots/text';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _lodashEs = require("lodash-es");
var _parchment = require("parchment");
var _quillDelta = _interopRequireWildcard(require("quill-delta"));
var _block = _interopRequireWildcard(require("../blots/block"));
var _break = _interopRequireDefault(require("../blots/break"));
var _cursor = _interopRequireDefault(require("../blots/cursor"));
var _text = _interopRequireWildcard(require("../blots/text"));
var _selection = require("./selection");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
const ASCII = /^[ -~]*$/;
class Editor {

@@ -19,5 +24,3 @@ constructor(scroll) {

}
applyDelta(delta) {
let consumeNextNewline = false;
this.scroll.update();

@@ -27,33 +30,60 @@ let scrollLength = this.scroll.length();

const normalizedDelta = normalizeDelta(delta);
normalizedDelta.reduce((index, op) => {
const length = op.retain || op.delete || op.insert.length || 1;
const deleteDelta = new _quillDelta.default();
const normalizedOps = splitOpLines(normalizedDelta.ops.slice());
normalizedOps.reduce((index, op) => {
const length = _quillDelta.Op.length(op);
let attributes = op.attributes || {};
let isImplicitNewlinePrepended = false;
let isImplicitNewlineAppended = false;
if (op.insert != null) {
deleteDelta.retain(length);
if (typeof op.insert === 'string') {
let text = op.insert;
if (text.endsWith('\n') && consumeNextNewline) {
consumeNextNewline = false;
text = text.slice(0, -1);
}
if (
(index >= scrollLength ||
this.scroll.descendant(BlockEmbed, index)[0]) &&
!text.endsWith('\n')
) {
consumeNextNewline = true;
}
const text = op.insert;
isImplicitNewlineAppended = !text.endsWith('\n') && (scrollLength <= index || !!this.scroll.descendant(_block.BlockEmbed, index)[0]);
this.scroll.insertAt(index, text);
const [line, offset] = this.scroll.line(index);
let formats = extend({}, bubbleFormats(line));
if (line instanceof Block) {
const [leaf] = line.descendant(LeafBlot, offset);
formats = extend(formats, bubbleFormats(leaf));
let formats = (0, _lodashEs.merge)({}, (0, _block.bubbleFormats)(line));
if (line instanceof _block.default) {
const [leaf] = line.descendant(_parchment.LeafBlot, offset);
if (leaf) {
formats = (0, _lodashEs.merge)(formats, (0, _block.bubbleFormats)(leaf));
}
}
attributes = AttributeMap.diff(formats, attributes) || {};
attributes = _quillDelta.AttributeMap.diff(formats, attributes) || {};
} else if (typeof op.insert === 'object') {
const key = Object.keys(op.insert)[0]; // There should only be one key
if (key == null) return index;
const isInlineEmbed = this.scroll.query(key, _parchment.Scope.INLINE) != null;
if (isInlineEmbed) {
if (scrollLength <= index || !!this.scroll.descendant(_block.BlockEmbed, index)[0]) {
isImplicitNewlineAppended = true;
}
} else if (index > 0) {
const [leaf, offset] = this.scroll.descendant(_parchment.LeafBlot, index - 1);
if (leaf instanceof _text.default) {
const text = leaf.value();
if (text[offset] !== '\n') {
isImplicitNewlinePrepended = true;
}
} else if (leaf instanceof _parchment.EmbedBlot && leaf.statics.scope === _parchment.Scope.INLINE_BLOT) {
isImplicitNewlinePrepended = true;
}
}
this.scroll.insertAt(index, key, op.insert[key]);
if (isInlineEmbed) {
const [leaf] = this.scroll.descendant(_parchment.LeafBlot, index);
if (leaf) {
const formats = (0, _lodashEs.merge)({}, (0, _block.bubbleFormats)(leaf));
attributes = _quillDelta.AttributeMap.diff(formats, attributes) || {};
}
}
}
scrollLength += length;
} else {
deleteDelta.push(op);
if (op.retain !== null && typeof op.retain === 'object') {
const key = Object.keys(op.retain)[0];
if (key == null) return index;
this.scroll.updateEmbedAt(index, key, op.retain[key]);
}
}

@@ -63,5 +93,10 @@ Object.keys(attributes).forEach(name => {

});
return index + length;
const prependedLength = isImplicitNewlinePrepended ? 1 : 0;
const addedLength = isImplicitNewlineAppended ? 1 : 0;
scrollLength += prependedLength + addedLength;
deleteDelta.retain(prependedLength);
deleteDelta.delete(addedLength);
return index + length + prependedLength + addedLength;
}, 0);
normalizedDelta.reduce((index, op) => {
deleteDelta.reduce((index, op) => {
if (typeof op.delete === 'number') {

@@ -71,3 +106,3 @@ this.scroll.deleteAt(index, op.delete);

}
return index + (op.retain || op.insert.length || 1);
return index + _quillDelta.Op.length(op);
}, 0);

@@ -78,9 +113,8 @@ this.scroll.batchEnd();

}
deleteText(index, length) {
this.scroll.deleteAt(index, length);
return this.update(new Delta().retain(index).delete(length));
return this.update(new _quillDelta.default().retain(index).delete(length));
}
formatLine(index, length, formats = {}) {
formatLine(index, length) {
let formats = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
this.scroll.update();

@@ -93,25 +127,23 @@ Object.keys(formats).forEach(format => {

this.scroll.optimize();
const delta = new Delta().retain(index).retain(length, clone(formats));
const delta = new _quillDelta.default().retain(index).retain(length, (0, _lodashEs.cloneDeep)(formats));
return this.update(delta);
}
formatText(index, length, formats = {}) {
formatText(index, length) {
let formats = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
Object.keys(formats).forEach(format => {
this.scroll.formatAt(index, length, format, formats[format]);
});
const delta = new Delta().retain(index).retain(length, clone(formats));
const delta = new _quillDelta.default().retain(index).retain(length, (0, _lodashEs.cloneDeep)(formats));
return this.update(delta);
}
getContents(index, length) {
return this.delta.slice(index, index + length);
}
getDelta() {
return this.scroll.lines().reduce((delta, line) => {
return delta.concat(line.delta());
}, new Delta());
}, new _quillDelta.default());
}
getFormat(index, length = 0) {
getFormat(index) {
let length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
let lines = [];

@@ -122,5 +154,5 @@ let leaves = [];

const [blot] = path;
if (blot instanceof Block) {
if (blot instanceof _block.default) {
lines.push(blot);
} else if (blot instanceof LeafBlot) {
} else if (blot instanceof _parchment.LeafBlot) {
leaves.push(blot);

@@ -131,38 +163,49 @@ }

lines = this.scroll.lines(index, length);
leaves = this.scroll.descendants(LeafBlot, index, length);
leaves = this.scroll.descendants(_parchment.LeafBlot, index, length);
}
const formatsArr = [lines, leaves].map(blots => {
if (blots.length === 0) return {};
let formats = bubbleFormats(blots.shift());
const [lineFormats, leafFormats] = [lines, leaves].map(blots => {
const blot = blots.shift();
if (blot == null) return {};
let formats = (0, _block.bubbleFormats)(blot);
while (Object.keys(formats).length > 0) {
const blot = blots.shift();
if (blot == null) return formats;
formats = combineFormats(bubbleFormats(blot), formats);
formats = combineFormats((0, _block.bubbleFormats)(blot), formats);
}
return formats;
});
return extend.apply(extend, formatsArr);
return {
...lineFormats,
...leafFormats
};
}
getHTML(index, length) {
const [line, lineOffset] = this.scroll.line(index);
if (line.length() >= lineOffset + length) {
return convertHTML(line, lineOffset, length, true);
if (line) {
const lineLength = line.length();
if (line.length() >= lineOffset + length) {
const excludeOuterTag = !(lineOffset === 0 && length === lineLength);
return convertHTML(line, lineOffset, length, excludeOuterTag);
}
return convertHTML(this.scroll, index, length, true);
}
return convertHTML(this.scroll, index, length, true);
return '';
}
getText(index, length) {
return this.getContents(index, length)
.filter(op => typeof op.insert === 'string')
.map(op => op.insert)
.join('');
return this.getContents(index, length).filter(op => typeof op.insert === 'string').map(op => op.insert).join('');
}
insertContents(index, contents) {
const normalizedDelta = normalizeDelta(contents);
const change = new _quillDelta.default().retain(index).concat(normalizedDelta);
this.scroll.insertContents(index, normalizedDelta);
return this.update(change);
}
insertEmbed(index, embed, value) {
this.scroll.insertAt(index, embed, value);
return this.update(new Delta().retain(index).insert({ [embed]: value }));
return this.update(new _quillDelta.default().retain(index).insert({
[embed]: value
}));
}
insertText(index, text, formats = {}) {
insertText(index, text) {
let formats = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
text = text.replace(/\r\n/g, '\n').replace(/\r/g, '\n');

@@ -173,14 +216,13 @@ this.scroll.insertAt(index, text);

});
return this.update(new Delta().retain(index).insert(text, clone(formats)));
return this.update(new _quillDelta.default().retain(index).insert(text, (0, _lodashEs.cloneDeep)(formats)));
}
isBlank() {
if (this.scroll.children.length === 0) return true;
if (this.scroll.children.length > 1) return false;
const block = this.scroll.children.head;
if (block.statics.blotName !== Block.blotName) return false;
const blot = this.scroll.children.head;
if (blot?.statics.blotName !== _block.default.blotName) return false;
const block = blot;
if (block.children.length > 1) return false;
return block.children.head instanceof Break;
return block.children.head instanceof _break.default;
}
removeFormat(index, length) {

@@ -190,38 +232,33 @@ const text = this.getText(index, length);

let suffixLength = 0;
let suffix = new Delta();
let suffix = new _quillDelta.default();
if (line != null) {
suffixLength = line.length() - offset;
suffix = line
.delta()
.slice(offset, offset + suffixLength - 1)
.insert('\n');
suffix = line.delta().slice(offset, offset + suffixLength - 1).insert('\n');
}
const contents = this.getContents(index, length + suffixLength);
const diff = contents.diff(new Delta().insert(text).concat(suffix));
const delta = new Delta().retain(index).concat(diff);
const diff = contents.diff(new _quillDelta.default().insert(text).concat(suffix));
const delta = new _quillDelta.default().retain(index).concat(diff);
return this.applyDelta(delta);
}
update(change, mutations = [], selectionInfo = undefined) {
update(change) {
let mutations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
let selectionInfo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
const oldDelta = this.delta;
if (
mutations.length === 1 &&
mutations[0].type === 'characterData' &&
mutations[0].target.data.match(ASCII) &&
this.scroll.find(mutations[0].target)
) {
if (mutations.length === 1 && mutations[0].type === 'characterData' &&
// @ts-expect-error Fix me later
mutations[0].target.data.match(ASCII) && this.scroll.find(mutations[0].target)) {
// Optimization for character changes
const textBlot = this.scroll.find(mutations[0].target);
const formats = bubbleFormats(textBlot);
const formats = (0, _block.bubbleFormats)(textBlot);
const index = textBlot.offset(this.scroll);
const oldValue = mutations[0].oldValue.replace(CursorBlot.CONTENTS, '');
const oldText = new Delta().insert(oldValue);
const newText = new Delta().insert(textBlot.value());
// @ts-expect-error Fix me later
const oldValue = mutations[0].oldValue.replace(_cursor.default.CONTENTS, '');
const oldText = new _quillDelta.default().insert(oldValue);
// @ts-expect-error
const newText = new _quillDelta.default().insert(textBlot.value());
const relativeSelectionInfo = selectionInfo && {
oldRange: shiftRange(selectionInfo.oldRange, -index),
newRange: shiftRange(selectionInfo.newRange, -index),
newRange: shiftRange(selectionInfo.newRange, -index)
};
const diffDelta = new Delta()
.retain(index)
.concat(oldText.diff(newText, relativeSelectionInfo));
const diffDelta = new _quillDelta.default().retain(index).concat(oldText.diff(newText, relativeSelectionInfo));
change = diffDelta.reduce((delta, op) => {

@@ -232,7 +269,7 @@ if (op.insert) {

return delta.push(op);
}, new Delta());
}, new _quillDelta.default());
this.delta = oldDelta.compose(change);
} else {
this.delta = this.getDelta();
if (!change || !equal(oldDelta.compose(change), this.delta)) {
if (!change || !(0, _lodashEs.isEqual)(oldDelta.compose(change), this.delta)) {
change = oldDelta.diff(this.delta, selectionInfo);

@@ -244,3 +281,2 @@ }

}
function convertListHTML(items, lastIndent, types) {

@@ -254,3 +290,9 @@ if (items.length === 0) {

}
const [{ child, offset, length, indent, type }, ...rest] = items;
const [{
child,
offset,
length,
indent,
type
}, ...rest] = items;
const [tag, attribute] = getListType(type);

@@ -260,7 +302,3 @@ if (indent > lastIndent) {

if (indent === lastIndent + 1) {
return `<${tag}><li${attribute}>${convertHTML(
child,
offset,
length,
)}${convertListHTML(rest, indent, types)}`;
return `<${tag}><li${attribute}>${convertHTML(child, offset, length)}${convertListHTML(rest, indent, types)}`;
}

@@ -271,7 +309,3 @@ return `<${tag}><li>${convertListHTML(items, lastIndent + 1, types)}`;

if (indent === lastIndent && type === previousType) {
return `</li><li${attribute}>${convertHTML(
child,
offset,
length,
)}${convertListHTML(rest, indent, types)}`;
return `</li><li${attribute}>${convertHTML(child, offset, length)}${convertListHTML(rest, indent, types)}`;
}

@@ -281,11 +315,11 @@ const [endTag] = getListType(types.pop());

}
function convertHTML(blot, index, length, isRoot = false) {
if (typeof blot.html === 'function') {
function convertHTML(blot, index, length) {
let excludeOuterTag = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
if ('html' in blot && typeof blot.html === 'function') {
return blot.html(index, length);
}
if (blot instanceof TextBlot) {
return escapeText(blot.value().slice(index, index + length));
if (blot instanceof _text.default) {
return (0, _text.escapeText)(blot.value().slice(index, index + length));
}
if (blot.children) {
if (blot instanceof _parchment.ParentBlot) {
// TODO fix API

@@ -295,3 +329,3 @@ if (blot.statics.blotName === 'list-container') {

blot.children.forEachAt(index, length, (child, offset, childLength) => {
const formats = child.formats();
const formats = 'formats' in child && typeof child.formats === 'function' ? child.formats() : {};
items.push({

@@ -302,3 +336,3 @@ child,

indent: formats.indent || 0,
type: formats.list,
type: formats.list
});

@@ -312,6 +346,9 @@ });

});
if (isRoot || blot.statics.blotName === 'list') {
if (excludeOuterTag || blot.statics.blotName === 'list') {
return parts.join('');
}
const { outerHTML, innerHTML } = blot.domNode;
const {
outerHTML,
innerHTML
} = blot.domNode;
const [start, end] = outerHTML.split(`>${innerHTML}<`);

@@ -324,16 +361,19 @@ // TODO cleanup

}
return blot.domNode.outerHTML;
return blot.domNode instanceof Element ? blot.domNode.outerHTML : '';
}
function combineFormats(formats, combined) {
return Object.keys(combined).reduce((merged, name) => {
if (formats[name] == null) return merged;
if (combined[name] === formats[name]) {
merged[name] = combined[name];
} else if (Array.isArray(combined[name])) {
if (combined[name].indexOf(formats[name]) < 0) {
merged[name] = combined[name].concat([formats[name]]);
const combinedValue = combined[name];
if (combinedValue === formats[name]) {
merged[name] = combinedValue;
} else if (Array.isArray(combinedValue)) {
if (combinedValue.indexOf(formats[name]) < 0) {
merged[name] = combinedValue.concat([formats[name]]);
} else {
// If style already exists, don't add to an array, but don't lose other styles
merged[name] = combinedValue;
}
} else {
merged[name] = [combined[name], formats[name]];
merged[name] = [combinedValue, formats[name]];
}

@@ -343,3 +383,2 @@ return merged;

}
function getListType(type) {

@@ -356,3 +395,2 @@ const tag = type === 'ordered' ? 'ol' : 'ul';

}
function normalizeDelta(delta) {

@@ -365,9 +403,33 @@ return delta.reduce((normalizedDelta, op) => {

return normalizedDelta.push(op);
}, new Delta());
}, new _quillDelta.default());
}
function shiftRange({ index, length }, amount) {
return new Range(index + amount, length);
function shiftRange(_ref, amount) {
let {
index,
length
} = _ref;
return new _selection.Range(index + amount, length);
}
export default Editor;
function splitOpLines(ops) {
const split = [];
ops.forEach(op => {
if (typeof op.insert === 'string') {
const lines = op.insert.split('\n');
lines.forEach((line, index) => {
if (index) split.push({
insert: '\n',
attributes: op.attributes
});
if (line) split.push({
insert: line,
attributes: op.attributes
});
});
} else {
split.push(op);
}
});
return split;
}
var _default = exports.default = Editor;
//# sourceMappingURL=editor.js.map

@@ -1,12 +0,20 @@

import EventEmitter from 'eventemitter3';
import instances from './instances';
import logger from './logger';
"use strict";
const debug = logger('quill:events');
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _eventemitter = _interopRequireDefault(require("eventemitter3"));
var _instances = _interopRequireDefault(require("./instances"));
var _logger = _interopRequireDefault(require("./logger"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const debug = (0, _logger.default)('quill:events');
const EVENTS = ['selectionchange', 'mousedown', 'mouseup', 'click'];
EVENTS.forEach(eventName => {
document.addEventListener(eventName, (...args) => {
document.addEventListener(eventName, function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
Array.from(document.querySelectorAll('.ql-container')).forEach(node => {
const quill = instances.get(node);
const quill = _instances.default.get(node);
if (quill && quill.emitter) {

@@ -18,17 +26,45 @@ quill.emitter.handleDOM(...args);

});
class Emitter extends EventEmitter {
class Emitter extends _eventemitter.default {
static events = {
EDITOR_CHANGE: 'editor-change',
SCROLL_BEFORE_UPDATE: 'scroll-before-update',
SCROLL_BLOT_MOUNT: 'scroll-blot-mount',
SCROLL_BLOT_UNMOUNT: 'scroll-blot-unmount',
SCROLL_OPTIMIZE: 'scroll-optimize',
SCROLL_UPDATE: 'scroll-update',
SCROLL_EMBED_UPDATE: 'scroll-embed-update',
SELECTION_CHANGE: 'selection-change',
TEXT_CHANGE: 'text-change',
COMPOSITION_BEFORE_START: 'composition-before-start',
COMPOSITION_START: 'composition-start',
COMPOSITION_BEFORE_END: 'composition-before-end',
COMPOSITION_END: 'composition-end'
};
static sources = {
API: 'api',
SILENT: 'silent',
USER: 'user'
};
constructor() {
super();
this.listeners = {};
this.domListeners = {};
this.on('error', debug.error);
}
emit(...args) {
emit() {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
debug.log.call(debug, ...args);
super.emit(...args);
// @ts-expect-error
return super.emit(...args);
}
handleDOM(event, ...args) {
(this.listeners[event.type] || []).forEach(({ node, handler }) => {
handleDOM(event) {
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
args[_key3 - 1] = arguments[_key3];
}
(this.domListeners[event.type] || []).forEach(_ref => {
let {
node,
handler
} = _ref;
if (event.target === node || node.contains(event.target)) {

@@ -39,27 +75,13 @@ handler(event, ...args);

}
listenDOM(eventName, node, handler) {
if (!this.listeners[eventName]) {
this.listeners[eventName] = [];
if (!this.domListeners[eventName]) {
this.domListeners[eventName] = [];
}
this.listeners[eventName].push({ node, handler });
this.domListeners[eventName].push({
node,
handler
});
}
}
Emitter.events = {
EDITOR_CHANGE: 'editor-change',
SCROLL_BEFORE_UPDATE: 'scroll-before-update',
SCROLL_BLOT_MOUNT: 'scroll-blot-mount',
SCROLL_BLOT_UNMOUNT: 'scroll-blot-unmount',
SCROLL_OPTIMIZE: 'scroll-optimize',
SCROLL_UPDATE: 'scroll-update',
SELECTION_CHANGE: 'selection-change',
TEXT_CHANGE: 'text-change',
};
Emitter.sources = {
API: 'api',
SILENT: 'silent',
USER: 'user',
};
export default Emitter;
var _default = exports.default = Emitter;
//# sourceMappingURL=emitter.js.map

@@ -1,1 +0,8 @@

export default new WeakMap();
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _default = exports.default = new WeakMap();
//# sourceMappingURL=instances.js.map

@@ -0,7 +1,17 @@

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
const levels = ['error', 'warn', 'log', 'info'];
let level = 'warn';
function debug(method, ...args) {
if (levels.indexOf(method) <= levels.indexOf(level)) {
console[method](...args); // eslint-disable-line no-console
function debug(method) {
if (level) {
if (levels.indexOf(method) <= levels.indexOf(level)) {
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
console[method](...args); // eslint-disable-line no-console
}
}

@@ -16,3 +26,2 @@ }

}
namespace.level = newLevel => {

@@ -22,3 +31,3 @@ level = newLevel;

debug.level = namespace.level;
export default namespace;
var _default = exports.default = namespace;
//# sourceMappingURL=logger.js.map

@@ -0,3 +1,11 @@

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
class Module {
constructor(quill, options = {}) {
static DEFAULTS = {};
constructor(quill) {
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
this.quill = quill;

@@ -7,4 +15,3 @@ this.options = options;

}
Module.DEFAULTS = {};
export default Module;
var _default = exports.default = Module;
//# sourceMappingURL=module.js.map

@@ -1,18 +0,46 @@

import Delta from 'quill-delta';
import * as Parchment from 'parchment';
import extend from 'extend';
import Editor from './editor';
import Emitter from './emitter';
import Module from './module';
import Selection, { Range } from './selection';
import instances from './instances';
import logger from './logger';
import Theme from './theme';
"use strict";
const debug = logger('quill');
const globalRegistry = new Parchment.Registry();
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
exports.expandConfig = expandConfig;
exports.globalRegistry = void 0;
exports.overload = overload;
var _lodashEs = require("lodash-es");
var Parchment = _interopRequireWildcard(require("parchment"));
var _quillDelta = _interopRequireDefault(require("quill-delta"));
var _editor = _interopRequireDefault(require("./editor"));
var _emitter = _interopRequireDefault(require("./emitter"));
var _instances = _interopRequireDefault(require("./instances"));
var _logger = _interopRequireDefault(require("./logger"));
var _module = _interopRequireDefault(require("./module"));
var _selection = _interopRequireWildcard(require("./selection"));
var _composition = _interopRequireDefault(require("./composition"));
var _theme = _interopRequireDefault(require("./theme"));
var _scrollRectIntoView = _interopRequireDefault(require("./utils/scrollRectIntoView"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
const debug = (0, _logger.default)('quill');
const globalRegistry = exports.globalRegistry = new Parchment.Registry();
Parchment.ParentBlot.uiClass = 'ql-ui';
class Quill {
static DEFAULTS = {
bounds: null,
modules: {},
placeholder: '',
readOnly: false,
registry: globalRegistry,
theme: 'default'
};
static events = _emitter.default.events;
static sources = _emitter.default.sources;
static version = typeof "2.0.0-rc.0" === 'undefined' ? 'dev' : "2.0.0-rc.0";
static imports = {
delta: _quillDelta.default,
parchment: Parchment,
'core/module': _module.default,
'core/theme': _theme.default
};
static debug(limit) {

@@ -22,9 +50,8 @@ if (limit === true) {

}
logger.level(limit);
_logger.default.level(limit);
}
static find(node) {
return instances.get(node) || globalRegistry.find(node);
let bubble = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
return _instances.default.get(node) || globalRegistry.find(node, bubble);
}
static import(name) {

@@ -36,11 +63,13 @@ if (this.imports[name] == null) {

}
static register(path, target, overwrite = false) {
static register(path, target) {
let overwrite = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
if (typeof path !== 'string') {
const name = path.attrName || path.blotName;
const name = 'attrName' in path ? path.attrName : path.blotName;
if (typeof name === 'string') {
// register(Blot | Attributor, overwrite)
// @ts-expect-error
this.register(`formats/${name}`, path, target);
} else {
Object.keys(path).forEach(key => {
// @ts-expect-error
this.register(key, path[key], target);

@@ -54,9 +83,10 @@ });

this.imports[path] = target;
if (
(path.startsWith('blots/') || path.startsWith('formats/')) &&
target.blotName !== 'abstract'
) {
if ((path.startsWith('blots/') || path.startsWith('formats/')) && target && typeof target !== 'boolean' &&
// @ts-expect-error
target.blotName !== 'abstract') {
globalRegistry.register(target);
}
// @ts-expect-error
if (typeof target.register === 'function') {
// @ts-expect-error
target.register(globalRegistry);

@@ -66,8 +96,9 @@ }

}
constructor(container, options = {}) {
constructor(container) {
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
this.options = expandConfig(container, options);
this.container = this.options.container;
if (this.container == null) {
return debug.error('Invalid Quill container', container);
debug.error('Invalid Quill container', container);
return;
}

@@ -80,16 +111,17 @@ if (this.options.debug) {

this.container.innerHTML = '';
instances.set(this.container, this);
_instances.default.set(this.container, this);
this.root = this.addContainer('ql-editor');
this.root.classList.add('ql-blank');
this.root.setAttribute('data-gramm', false);
this.scrollingContainer = this.options.scrollingContainer || this.root;
this.emitter = new Emitter();
const ScrollBlot = this.options.registry.query(
Parchment.ScrollBlot.blotName,
);
this.emitter = new _emitter.default();
const scrollBlotName = Parchment.ScrollBlot.blotName;
const ScrollBlot = this.options.registry.query(scrollBlotName);
if (!ScrollBlot || !('blotName' in ScrollBlot)) {
throw new Error(`Cannot initialize Quill without "${scrollBlotName}" blot`);
}
this.scroll = new ScrollBlot(this.options.registry, this.root, {
emitter: this.emitter,
emitter: this.emitter
});
this.editor = new Editor(this.scroll);
this.selection = new Selection(this.scroll, this.emitter);
this.editor = new _editor.default(this.scroll);
this.selection = new _selection.default(this.scroll, this.emitter);
this.composition = new _composition.default(this.scroll, this.emitter);
this.theme = new this.options.theme(this, this.options); // eslint-disable-line new-cap

@@ -100,24 +132,40 @@ this.keyboard = this.theme.addModule('keyboard');

this.uploader = this.theme.addModule('uploader');
this.theme.addModule('input');
this.theme.addModule('uiNode');
this.theme.init();
this.emitter.on(Emitter.events.EDITOR_CHANGE, type => {
if (type === Emitter.events.TEXT_CHANGE) {
this.emitter.on(_emitter.default.events.EDITOR_CHANGE, type => {
if (type === _emitter.default.events.TEXT_CHANGE) {
this.root.classList.toggle('ql-blank', this.editor.isBlank());
}
});
this.emitter.on(Emitter.events.SCROLL_UPDATE, (source, mutations) => {
this.emitter.on(_emitter.default.events.SCROLL_UPDATE, (source, mutations) => {
const oldRange = this.selection.lastRange;
const [newRange] = this.selection.getRange();
const selectionInfo =
oldRange && newRange ? { oldRange, newRange } : undefined;
modify.call(
this,
() => this.editor.update(null, mutations, selectionInfo),
source,
);
const selectionInfo = oldRange && newRange ? {
oldRange,
newRange
} : undefined;
modify.call(this, () => this.editor.update(null, mutations, selectionInfo), source);
});
const contents = this.clipboard.convert({
html: `${html}<p><br></p>`,
text: '\n',
this.emitter.on(_emitter.default.events.SCROLL_EMBED_UPDATE, (blot, delta) => {
const oldRange = this.selection.lastRange;
const [newRange] = this.selection.getRange();
const selectionInfo = oldRange && newRange ? {
oldRange,
newRange
} : undefined;
modify.call(this, () => {
const change = new _quillDelta.default().retain(blot.offset(this)).retain({
[blot.statics.blotName]: delta
});
return this.editor.update(change, [], selectionInfo);
}, Quill.sources.USER);
});
this.setContents(contents);
if (html) {
const contents = this.clipboard.convert({
html: `${html}<p><br></p>`,
text: '\n'
});
this.setContents(contents);
}
this.history.clear();

@@ -132,4 +180,4 @@ if (this.options.placeholder) {

}
addContainer(container, refNode = null) {
addContainer(container) {
let refNode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
if (typeof container === 'string') {

@@ -143,24 +191,16 @@ const className = container;

}
blur() {
this.selection.setRange(null);
}
deleteText(index, length, source) {
[index, length, , source] = overload(index, length, source);
return modify.call(
this,
() => {
return this.editor.deleteText(index, length);
},
source,
index,
-1 * length,
);
// @ts-expect-error
[index, length,, source] = overload(index, length, source);
return modify.call(this, () => {
// @ts-expect-error
return this.editor.deleteText(index, length);
}, source, index, -1 * length);
}
disable() {
this.enable(false);
}
editReadOnly(modifier) {

@@ -172,62 +212,46 @@ this.allowReadOnlyEdits = true;

}
enable(enabled = true) {
enable() {
let enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
this.scroll.enable(enabled);
this.container.classList.toggle('ql-disabled', !enabled);
}
focus() {
const { scrollTop } = this.scrollingContainer;
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
this.selection.focus();
this.scrollingContainer.scrollTop = scrollTop;
this.scrollIntoView();
if (!options.preventScroll) {
this.scrollSelectionIntoView();
}
}
format(name, value, source = Emitter.sources.API) {
return modify.call(
this,
() => {
const range = this.getSelection(true);
let change = new Delta();
if (range == null) return change;
if (this.scroll.query(name, Parchment.Scope.BLOCK)) {
change = this.editor.formatLine(range.index, range.length, {
[name]: value,
});
} else if (range.length === 0) {
this.selection.format(name, value);
return change;
} else {
change = this.editor.formatText(range.index, range.length, {
[name]: value,
});
}
this.setSelection(range, Emitter.sources.SILENT);
format(name, value) {
let source = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _emitter.default.sources.API;
return modify.call(this, () => {
const range = this.getSelection(true);
let change = new _quillDelta.default();
if (range == null) return change;
if (this.scroll.query(name, Parchment.Scope.BLOCK)) {
change = this.editor.formatLine(range.index, range.length, {
[name]: value
});
} else if (range.length === 0) {
this.selection.format(name, value);
return change;
},
source,
);
} else {
change = this.editor.formatText(range.index, range.length, {
[name]: value
});
}
this.setSelection(range, _emitter.default.sources.SILENT);
return change;
}, source);
}
formatLine(index, length, name, value, source) {
let formats;
// eslint-disable-next-line prefer-const
[index, length, formats, source] = overload(
index,
length,
name,
value,
source,
);
return modify.call(
this,
() => {
return this.editor.formatLine(index, length, formats);
},
source,
index,
0,
);
[index, length, formats, source] = overload(index, length,
// @ts-expect-error
name, value, source);
return modify.call(this, () => {
return this.editor.formatLine(index, length, formats);
}, source, index, 0);
}
formatText(index, length, name, value, source) {

@@ -237,21 +261,12 @@ let formats;

[index, length, formats, source] = overload(
index,
length,
name,
value,
source,
);
return modify.call(
this,
() => {
return this.editor.formatText(index, length, formats);
},
source,
index,
0,
);
// @ts-expect-error
index, length, name, value, source);
return modify.call(this, () => {
// @ts-expect-error
return this.editor.formatText(index, length, formats);
}, source, index, 0);
}
getBounds(index, length = 0) {
let bounds;
getBounds(index) {
let length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
let bounds = null;
if (typeof index === 'number') {

@@ -262,2 +277,3 @@ bounds = this.selection.getBounds(index, length);

}
if (!bounds) return null;
const containerBounds = this.container.getBoundingClientRect();

@@ -270,12 +286,14 @@ return {

top: bounds.top - containerBounds.top,
width: bounds.width,
width: bounds.width
};
}
getContents(index = 0, length = this.getLength() - index) {
getContents() {
let index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
let length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getLength() - index;
[index, length] = overload(index, length);
return this.editor.getContents(index, length);
}
getFormat(index = this.getSelection(true), length = 0) {
getFormat() {
let index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.getSelection(true);
let length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
if (typeof index === 'number') {

@@ -286,20 +304,17 @@ return this.editor.getFormat(index, length);

}
getIndex(blot) {
return blot.offset(this.scroll);
}
getLength() {
return this.scroll.length();
}
getLeaf(index) {
return this.scroll.leaf(index);
}
getLine(index) {
return this.scroll.line(index);
}
getLines(index = 0, length = Number.MAX_VALUE) {
getLines() {
let index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
let length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Number.MAX_VALUE;
if (typeof index !== 'number') {

@@ -310,8 +325,7 @@ return this.scroll.lines(index.index, index.length);

}
getModule(name) {
return this.theme.modules[name];
}
getSelection(focus = false) {
getSelection() {
let focus = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
if (focus) this.focus();

@@ -321,116 +335,117 @@ this.update(); // Make sure we access getRange with editor in consistent state

}
getSemanticHTML(index = 0, length = this.getLength() - index) {
getSemanticHTML() {
let index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
let length = arguments.length > 1 ? arguments[1] : undefined;
if (typeof index === 'number') {
length = length ?? this.getLength() - index;
}
// @ts-expect-error
[index, length] = overload(index, length);
return this.editor.getHTML(index, length);
}
getText(index = 0, length = this.getLength() - index) {
getText() {
let index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
let length = arguments.length > 1 ? arguments[1] : undefined;
if (typeof index === 'number') {
length = length ?? this.getLength() - index;
}
// @ts-expect-error
[index, length] = overload(index, length);
return this.editor.getText(index, length);
}
hasFocus() {
return this.selection.hasFocus();
}
insertEmbed(index, embed, value, source = Quill.sources.API) {
return modify.call(
this,
() => {
return this.editor.insertEmbed(index, embed, value);
},
source,
index,
);
insertEmbed(index, embed, value) {
let source = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : Quill.sources.API;
return modify.call(this, () => {
return this.editor.insertEmbed(index, embed, value);
}, source, index);
}
insertText(index, text, name, value, source) {
let formats;
// eslint-disable-next-line prefer-const
[index, , formats, source] = overload(index, 0, name, value, source);
return modify.call(
this,
() => {
return this.editor.insertText(index, text, formats);
},
source,
index,
text.length,
);
// @ts-expect-error
[index,, formats, source] = overload(index, 0, name, value, source);
return modify.call(this, () => {
return this.editor.insertText(index, text, formats);
}, source, index, text.length);
}
isEnabled() {
return this.scroll.isEnabled();
}
off(...args) {
return this.emitter.off(...args);
off() {
return this.emitter.off(...arguments);
}
on(...args) {
return this.emitter.on(...args);
}
// @ts-expect-error
once(...args) {
return this.emitter.once(...args);
on() {
return this.emitter.on(...arguments);
}
removeFormat(index, length, source) {
[index, length, , source] = overload(index, length, source);
return modify.call(
this,
() => {
return this.editor.removeFormat(index, length);
},
source,
index,
);
once() {
return this.emitter.once(...arguments);
}
removeFormat() {
const [index, length,, source] = overload(...arguments);
return modify.call(this, () => {
return this.editor.removeFormat(index, length);
}, source, index);
}
scrollRectIntoView(rect) {
(0, _scrollRectIntoView.default)(this.root, rect);
}
/**
* @deprecated Use Quill#scrollSelectionIntoView() instead.
*/
scrollIntoView() {
this.selection.scrollIntoView(this.scrollingContainer);
console.warn('Quill#scrollIntoView() has been deprecated and will be removed in the near future. Please use Quill#scrollSelectionIntoView() instead.');
this.scrollSelectionIntoView();
}
setContents(delta, source = Emitter.sources.API) {
return modify.call(
this,
() => {
delta = new Delta(delta);
const length = this.getLength();
const deleted = this.editor.deleteText(0, length);
const applied = this.editor.applyDelta(delta);
const lastOp = applied.ops[applied.ops.length - 1];
if (
lastOp != null &&
typeof lastOp.insert === 'string' &&
lastOp.insert[lastOp.insert.length - 1] === '\n'
) {
this.editor.deleteText(this.getLength() - 1, 1);
applied.delete(1);
}
return deleted.compose(applied);
},
source,
);
/**
* Scroll the current selection into the visible area.
* If the selection is already visible, no scrolling will occur.
*/
scrollSelectionIntoView() {
const range = this.selection.lastRange;
const bounds = range && this.selection.getBounds(range.index, range.length);
if (bounds) {
this.scrollRectIntoView(bounds);
}
}
setContents(delta) {
let source = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _emitter.default.sources.API;
return modify.call(this, () => {
delta = new _quillDelta.default(delta);
const length = this.getLength();
// Quill will set empty editor to \n
const delete1 = this.editor.deleteText(0, length);
const applied = this.editor.insertContents(0, delta);
// Remove extra \n from empty editor initialization
const delete2 = this.editor.deleteText(this.getLength() - 1, 1);
return delete1.compose(applied).compose(delete2);
}, source);
}
setSelection(index, length, source) {
if (index == null) {
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/22609
this.selection.setRange(null, length || Quill.sources.API);
} else {
[index, length, , source] = overload(index, length, source);
this.selection.setRange(new Range(Math.max(0, index), length), source);
if (source !== Emitter.sources.SILENT) {
this.selection.scrollIntoView(this.scrollingContainer);
// @ts-expect-error
[index, length,, source] = overload(index, length, source);
this.selection.setRange(new _selection.Range(Math.max(0, index), length), source);
if (source !== _emitter.default.sources.SILENT) {
this.scrollSelectionIntoView();
}
}
}
setText(text, source = Emitter.sources.API) {
const delta = new Delta().insert(text);
setText(text) {
let source = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _emitter.default.sources.API;
const delta = new _quillDelta.default().insert(text);
return this.setContents(delta, source);
}
update(source = Emitter.sources.USER) {
update() {
let source = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _emitter.default.sources.USER;
const change = this.scroll.update(source); // Will update selection before selection.update() does if text changes

@@ -441,62 +456,35 @@ this.selection.update(source);

}
updateContents(delta, source = Emitter.sources.API) {
return modify.call(
this,
() => {
delta = new Delta(delta);
return this.editor.applyDelta(delta, source);
},
source,
true,
);
updateContents(delta) {
let source = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _emitter.default.sources.API;
return modify.call(this, () => {
delta = new _quillDelta.default(delta);
return this.editor.applyDelta(delta);
}, source, true);
}
}
Quill.DEFAULTS = {
bounds: null,
modules: {},
placeholder: '',
readOnly: false,
registry: globalRegistry,
scrollingContainer: null,
theme: 'default',
};
Quill.events = Emitter.events;
Quill.sources = Emitter.sources;
// eslint-disable-next-line no-undef
Quill.version = typeof QUILL_VERSION === 'undefined' ? 'dev' : QUILL_VERSION;
exports.default = Quill;
function expandConfig(container, userConfig) {
// @ts-expect-error -- TODO fix this later
let expandedConfig = (0, _lodashEs.merge)({
container,
modules: {
clipboard: true,
keyboard: true,
history: true,
uploader: true
}
}, userConfig);
Quill.imports = {
delta: Delta,
parchment: Parchment,
'core/module': Module,
'core/theme': Theme,
};
function expandConfig(container, userConfig) {
userConfig = extend(
true,
{
container,
modules: {
clipboard: true,
keyboard: true,
history: true,
uploader: true,
},
},
userConfig,
);
if (!userConfig.theme || userConfig.theme === Quill.DEFAULTS.theme) {
userConfig.theme = Theme;
// @ts-expect-error -- TODO fix this later
if (!expandedConfig.theme || expandedConfig.theme === Quill.DEFAULTS.theme) {
expandedConfig.theme = _theme.default;
} else {
userConfig.theme = Quill.import(`themes/${userConfig.theme}`);
if (userConfig.theme == null) {
throw new Error(
`Invalid theme ${userConfig.theme}. Did you register it?`,
);
expandedConfig.theme = Quill.import(`themes/${expandedConfig.theme}`);
if (expandedConfig.theme == null) {
throw new Error(`Invalid theme ${expandedConfig.theme}. Did you register it?`);
}
}
const themeConfig = extend(true, {}, userConfig.theme.DEFAULTS);
[themeConfig, userConfig].forEach(config => {
// @ts-expect-error -- TODO fix this later
const themeConfig = (0, _lodashEs.cloneDeep)(expandedConfig.theme.DEFAULTS);
[themeConfig, expandedConfig].forEach(config => {
config.modules = config.modules || {};

@@ -509,12 +497,9 @@ Object.keys(config.modules).forEach(module => {

});
const moduleNames = Object.keys(themeConfig.modules).concat(
Object.keys(userConfig.modules),
);
const moduleNames = Object.keys(themeConfig.modules).concat(Object.keys(expandedConfig.modules));
const moduleConfig = moduleNames.reduce((config, name) => {
const moduleClass = Quill.import(`modules/${name}`);
if (moduleClass == null) {
debug.error(
`Cannot load ${name} module. Are you sure you registered it?`,
);
debug.error(`Cannot load ${name} module. Are you sure you registered it?`);
} else {
// @ts-expect-error
config[name] = moduleClass.DEFAULTS || {};

@@ -525,34 +510,24 @@ }

// Special case toolbar shorthand
if (
userConfig.modules != null &&
userConfig.modules.toolbar &&
userConfig.modules.toolbar.constructor !== Object
) {
userConfig.modules.toolbar = {
container: userConfig.modules.toolbar,
if (expandedConfig.modules != null && expandedConfig.modules.toolbar && expandedConfig.modules.toolbar.constructor !== Object) {
expandedConfig.modules.toolbar = {
container: expandedConfig.modules.toolbar
};
}
userConfig = extend(
true,
{},
Quill.DEFAULTS,
{ modules: moduleConfig },
themeConfig,
userConfig,
);
['bounds', 'container', 'scrollingContainer'].forEach(key => {
if (typeof userConfig[key] === 'string') {
userConfig[key] = document.querySelector(userConfig[key]);
expandedConfig = (0, _lodashEs.merge)({}, Quill.DEFAULTS, {
modules: moduleConfig
}, themeConfig, expandedConfig);
['bounds', 'container'].forEach(key => {
const selector = expandedConfig[key];
if (typeof selector === 'string') {
// @ts-expect-error Handle null case
expandedConfig[key] = document.querySelector(selector);
}
});
userConfig.modules = Object.keys(userConfig.modules).reduce(
(config, name) => {
if (userConfig.modules[name]) {
config[name] = userConfig.modules[name];
}
return config;
},
{},
);
return userConfig;
expandedConfig.modules = Object.keys(expandedConfig.modules).reduce((config, name) => {
if (expandedConfig.modules[name]) {
config[name] = expandedConfig.modules[name];
}
return config;
}, {});
return expandedConfig;
}

@@ -563,8 +538,4 @@

function modify(modifier, source, index, shift) {
if (
!this.isEnabled() &&
source === Emitter.sources.USER &&
!this.allowReadOnlyEdits
) {
return new Delta();
if (!this.isEnabled() && source === _emitter.default.sources.USER && !this.allowReadOnlyEdits) {
return new _quillDelta.default();
}

@@ -578,13 +549,15 @@ let range = index == null ? null : this.getSelection();

}
if (shift == null) {
range = shiftRange(range, change, source);
} else if (shift !== 0) {
// @ts-expect-error index should always be number
range = shiftRange(range, index, shift, source);
}
this.setSelection(range, Emitter.sources.SILENT);
this.setSelection(range, _emitter.default.sources.SILENT);
}
if (change.length() > 0) {
const args = [Emitter.events.TEXT_CHANGE, change, oldDelta, source];
this.emitter.emit(Emitter.events.EDITOR_CHANGE, ...args);
if (source !== Emitter.sources.SILENT) {
const args = [_emitter.default.events.TEXT_CHANGE, change, oldDelta, source];
this.emitter.emit(_emitter.default.events.EDITOR_CHANGE, ...args);
if (source !== _emitter.default.sources.SILENT) {
this.emitter.emit(...args);

@@ -595,18 +568,24 @@ }

}
function overload(index, length, name, value, source) {
let formats = {};
// @ts-expect-error
if (typeof index.index === 'number' && typeof index.length === 'number') {
// Allow for throwaway end (used by insertText/insertEmbed)
if (typeof length !== 'number') {
// @ts-expect-error
source = value;
value = name;
name = length;
// @ts-expect-error
length = index.length; // eslint-disable-line prefer-destructuring
// @ts-expect-error
index = index.index; // eslint-disable-line prefer-destructuring
} else {
// @ts-expect-error
length = index.length; // eslint-disable-line prefer-destructuring
// @ts-expect-error
index = index.index; // eslint-disable-line prefer-destructuring
}
} else if (typeof length !== 'number') {
// @ts-expect-error
source = value;

@@ -619,3 +598,5 @@ value = name;

if (typeof name === 'object') {
// @ts-expect-error Fix me later
formats = name;
// @ts-expect-error
source = value;

@@ -626,2 +607,3 @@ } else if (typeof name === 'string') {

} else {
// @ts-expect-error
source = name;

@@ -631,27 +613,29 @@ }

// Handle optional source
source = source || Emitter.sources.API;
source = source || _emitter.default.sources.API;
// @ts-expect-error
return [index, length, formats, source];
}
function shiftRange(range, index, length, source) {
function shiftRange(range, index, lengthOrSource, source) {
const length = typeof lengthOrSource === 'number' ? lengthOrSource : 0;
if (range == null) return null;
let start;
let end;
if (index instanceof Delta) {
// @ts-expect-error -- TODO: add a better type guard around `index`
if (index && typeof index.transformPosition === 'function') {
[start, end] = [range.index, range.index + range.length].map(pos =>
index.transformPosition(pos, source !== Emitter.sources.USER),
);
// @ts-expect-error -- TODO: add a better type guard around `index`
index.transformPosition(pos, source !== _emitter.default.sources.USER));
} else {
[start, end] = [range.index, range.index + range.length].map(pos => {
if (pos < index || (pos === index && source === Emitter.sources.USER))
return pos;
// @ts-expect-error -- TODO: add a better type guard around `index`
if (pos < index || pos === index && source === _emitter.default.sources.USER) return pos;
if (length >= 0) {
return pos + length;
}
// @ts-expect-error -- TODO: add a better type guard around `index`
return Math.max(index, pos + length);
});
}
return new Range(start, end - start);
return new _selection.Range(start, end - start);
}
export { globalRegistry, expandConfig, overload, Quill as default };
//# sourceMappingURL=quill.js.map

@@ -1,11 +0,16 @@

import { LeafBlot, Scope } from 'parchment';
import clone from 'clone';
import equal from 'deep-equal';
import Emitter from './emitter';
import logger from './logger';
"use strict";
const debug = logger('quill:selection');
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.Range = void 0;
var _parchment = require("parchment");
var _lodashEs = require("lodash-es");
var _emitter = _interopRequireDefault(require("./emitter"));
var _logger = _interopRequireDefault(require("./logger"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const debug = (0, _logger.default)('quill:selection');
class Range {
constructor(index, length = 0) {
constructor(index) {
let length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
this.index = index;

@@ -15,3 +20,3 @@ this.length = length;

}
exports.Range = Range;
class Selection {

@@ -24,2 +29,3 @@ constructor(scroll, emitter) {

this.root = this.scroll.domNode;
// @ts-expect-error
this.cursor = this.scroll.create('cursor', this);

@@ -34,6 +40,6 @@ // savedRange is last non-null range

if (!this.mouseDown && !this.composing) {
setTimeout(this.update.bind(this, Emitter.sources.USER), 1);
setTimeout(this.update.bind(this, _emitter.default.sources.USER), 1);
}
});
this.emitter.on(Emitter.events.SCROLL_BEFORE_UPDATE, () => {
this.emitter.on(_emitter.default.events.SCROLL_BEFORE_UPDATE, () => {
if (!this.hasFocus()) return;

@@ -43,16 +49,9 @@ const native = this.getNativeRange();

if (native.start.node === this.cursor.textNode) return; // cursor.restore() will handle
this.emitter.once(Emitter.events.SCROLL_UPDATE, () => {
this.emitter.once(_emitter.default.events.SCROLL_UPDATE, (source, mutations) => {
try {
if (
this.root.contains(native.start.node) &&
this.root.contains(native.end.node)
) {
this.setNativeRange(
native.start.node,
native.start.offset,
native.end.node,
native.end.offset,
);
if (this.root.contains(native.start.node) && this.root.contains(native.end.node)) {
this.setNativeRange(native.start.node, native.start.offset, native.end.node, native.end.offset);
}
this.update(Emitter.sources.SILENT);
const triggeredByTyping = mutations.some(mutation => mutation.type === 'characterData' || mutation.type === 'childList' || mutation.type === 'attributes' && mutation.target === this.root);
this.update(triggeredByTyping ? _emitter.default.sources.SILENT : source);
} catch (ignored) {

@@ -63,19 +62,21 @@ // ignore

});
this.emitter.on(Emitter.events.SCROLL_OPTIMIZE, (mutations, context) => {
this.emitter.on(_emitter.default.events.SCROLL_OPTIMIZE, (mutations, context) => {
if (context.range) {
const { startNode, startOffset, endNode, endOffset } = context.range;
const {
startNode,
startOffset,
endNode,
endOffset
} = context.range;
this.setNativeRange(startNode, startOffset, endNode, endOffset);
this.update(Emitter.sources.SILENT);
this.update(_emitter.default.sources.SILENT);
}
});
this.update(Emitter.sources.SILENT);
this.update(_emitter.default.sources.SILENT);
}
handleComposition() {
this.root.addEventListener('compositionstart', () => {
this.emitter.on(_emitter.default.events.COMPOSITION_BEFORE_START, () => {
this.composing = true;
this.scroll.batchStart();
});
this.root.addEventListener('compositionend', () => {
this.scroll.batchEnd();
this.emitter.on(_emitter.default.events.COMPOSITION_END, () => {
this.composing = false;

@@ -86,8 +87,3 @@ if (this.cursor.parent) {

setTimeout(() => {
this.setNativeRange(
range.startNode,
range.startOffset,
range.endNode,
range.endOffset,
);
this.setNativeRange(range.startNode, range.startOffset, range.endNode, range.endOffset);
}, 1);

@@ -97,3 +93,2 @@ }

}
handleDragging() {

@@ -105,21 +100,16 @@ this.emitter.listenDOM('mousedown', document.body, () => {

this.mouseDown = false;
this.update(Emitter.sources.USER);
this.update(_emitter.default.sources.USER);
});
}
focus() {
if (this.hasFocus()) return;
this.root.focus();
this.root.focus({
preventScroll: true
});
this.setRange(this.savedRange);
}
format(format, value) {
this.scroll.update();
const nativeRange = this.getNativeRange();
if (
nativeRange == null ||
!nativeRange.native.collapsed ||
this.scroll.query(format, Scope.BLOCK)
)
return;
if (nativeRange == null || !nativeRange.native.collapsed || this.scroll.query(format, _parchment.Scope.BLOCK)) return;
if (nativeRange.start.node !== this.cursor.textNode) {

@@ -129,8 +119,11 @@ const blot = this.scroll.find(nativeRange.start.node, false);

// TODO Give blot ability to not split
if (blot instanceof LeafBlot) {
if (blot instanceof _parchment.LeafBlot) {
const after = blot.split(nativeRange.start.offset);
// @ts-expect-error Fix me later
blot.parent.insertBefore(this.cursor, after);
} else {
// @ts-expect-error TODO: nativeRange.start.node doesn't seem to match function signature
blot.insertBefore(this.cursor, nativeRange.start.node); // Should never happen
}
this.cursor.attach();

@@ -143,4 +136,4 @@ }

}
getBounds(index, length = 0) {
getBounds(index) {
let length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
const scrollLength = this.scroll.length();

@@ -165,2 +158,10 @@ index = Math.min(index, scrollLength - 1);

if (node instanceof Text) {
// Return null if the text node is empty because it is
// not able to get a useful client rect:
// https://github.com/w3c/csswg-drafts/issues/2514.
// Empty text nodes are most likely caused by TextBlot#optimize()
// not getting called when editor content changes.
if (!node.data.length) {
return null;
}
if (offset < node.data.length) {

@@ -176,2 +177,3 @@ range.setStart(node, offset);

} else {
if (!(leaf.domNode instanceof Element)) return null;
rect = leaf.domNode.getBoundingClientRect();

@@ -186,6 +188,5 @@ if (offset > 0) side = 'right';

top: rect.top,
width: 0,
width: 0
};
}
getNativeRange() {

@@ -200,4 +201,9 @@ const selection = document.getSelection();

}
getRange() {
const root = this.scroll.domNode;
if ('isConnected' in root && !root.isConnected) {
// document.getSelection() forces layout on Blink, so we trend to
// not calling it.
return [null, null];
}
const normalized = this.getNativeRange();

@@ -208,10 +214,5 @@ if (normalized == null) return [null, null];

}
hasFocus() {
return (
document.activeElement === this.root ||
contains(this.root, document.activeElement)
);
return document.activeElement === this.root || document.activeElement != null && contains(this.root, document.activeElement);
}
normalizedToRange(range) {

@@ -225,2 +226,3 @@ const positions = [[range.start.node, range.start.offset]];

const blot = this.scroll.find(node, true);
// @ts-expect-error Fix me later
const index = blot.offset(this.scroll);

@@ -230,5 +232,6 @@ if (offset === 0) {

}
if (blot instanceof LeafBlot) {
if (blot instanceof _parchment.LeafBlot) {
return index + blot.index(node, offset);
}
// @ts-expect-error Fix me later
return index + blot.length();

@@ -240,8 +243,4 @@ });

}
normalizeNative(nativeRange) {
if (
!contains(this.root, nativeRange.startContainer) ||
(!nativeRange.collapsed && !contains(this.root, nativeRange.endContainer))
) {
if (!contains(this.root, nativeRange.startContainer) || !nativeRange.collapsed && !contains(this.root, nativeRange.endContainer)) {
return null;

@@ -252,9 +251,15 @@ }

node: nativeRange.startContainer,
offset: nativeRange.startOffset,
offset: nativeRange.startOffset
},
end: { node: nativeRange.endContainer, offset: nativeRange.endOffset },
native: nativeRange,
end: {
node: nativeRange.endContainer,
offset: nativeRange.endOffset
},
native: nativeRange
};
[range.start, range.end].forEach(position => {
let { node, offset } = position;
let {
node,
offset
} = position;
while (!(node instanceof Text) && node.childNodes.length > 0) {

@@ -265,2 +270,3 @@ if (node.childNodes.length > offset) {

} else if (node.childNodes.length === offset) {
// @ts-expect-error Fix me later
node = node.lastChild;

@@ -285,55 +291,19 @@ if (node instanceof Text) {

}
rangeToNative(range) {
const indexes = range.collapsed
? [range.index]
: [range.index, range.index + range.length];
const args = [];
const scrollLength = this.scroll.length();
indexes.forEach((index, i) => {
const getPosition = (index, inclusive) => {
index = Math.min(scrollLength - 1, index);
const [leaf, leafOffset] = this.scroll.leaf(index);
const [node, offset] = leaf.position(leafOffset, i !== 0);
args.push(node, offset);
});
if (args.length < 2) {
return args.concat(args);
}
return args;
return leaf ? leaf.position(leafOffset, inclusive) : [null, -1];
};
return [...getPosition(range.index, false), ...getPosition(range.index + range.length, true)];
}
scrollIntoView(scrollingContainer) {
const range = this.lastRange;
if (range == null) return;
const bounds = this.getBounds(range.index, range.length);
if (bounds == null) return;
const limit = this.scroll.length() - 1;
const [first] = this.scroll.line(Math.min(range.index, limit));
let last = first;
if (range.length > 0) {
[last] = this.scroll.line(Math.min(range.index + range.length, limit));
}
if (first == null || last == null) return;
const scrollBounds = scrollingContainer.getBoundingClientRect();
if (bounds.top < scrollBounds.top) {
scrollingContainer.scrollTop -= scrollBounds.top - bounds.top;
} else if (bounds.bottom > scrollBounds.bottom) {
scrollingContainer.scrollTop += bounds.bottom - scrollBounds.bottom;
}
}
setNativeRange(
startNode,
startOffset,
endNode = startNode,
endOffset = startOffset,
force = false,
) {
setNativeRange(startNode, startOffset) {
let endNode = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : startNode;
let endOffset = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : startOffset;
let force = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
debug.info('setNativeRange', startNode, startOffset, endNode, endOffset);
if (
startNode != null &&
(this.root.parentNode == null ||
startNode.parentNode == null ||
endNode.parentNode == null)
) {
if (startNode != null && (this.root.parentNode == null || startNode.parentNode == null ||
// @ts-expect-error Fix me later
endNode.parentNode == null)) {
return;

@@ -344,26 +314,23 @@ }

if (startNode != null) {
if (!this.hasFocus()) this.root.focus();
const { native } = this.getNativeRange() || {};
if (
native == null ||
force ||
startNode !== native.startContainer ||
startOffset !== native.startOffset ||
endNode !== native.endContainer ||
endOffset !== native.endOffset
) {
if (startNode.tagName === 'BR') {
startOffset = Array.from(startNode.parentNode.childNodes).indexOf(
startNode,
);
if (!this.hasFocus()) this.root.focus({
preventScroll: true
});
const {
native
} = this.getNativeRange() || {};
if (native == null || force || startNode !== native.startContainer || startOffset !== native.startOffset || endNode !== native.endContainer || endOffset !== native.endOffset) {
if (startNode instanceof Element && startNode.tagName === 'BR') {
// @ts-expect-error Fix me later
startOffset = Array.from(startNode.parentNode.childNodes).indexOf(startNode);
startNode = startNode.parentNode;
}
if (endNode.tagName === 'BR') {
endOffset = Array.from(endNode.parentNode.childNodes).indexOf(
endNode,
);
if (endNode instanceof Element && endNode.tagName === 'BR') {
// @ts-expect-error Fix me later
endOffset = Array.from(endNode.parentNode.childNodes).indexOf(endNode);
endNode = endNode.parentNode;
}
const range = document.createRange();
// @ts-expect-error Fix me later
range.setStart(startNode, startOffset);
// @ts-expect-error Fix me later
range.setEnd(endNode, endOffset);

@@ -378,4 +345,5 @@ selection.removeAllRanges();

}
setRange(range, force = false, source = Emitter.sources.API) {
setRange(range) {
let force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
let source = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _emitter.default.sources.API;
if (typeof force === 'string') {

@@ -394,4 +362,4 @@ source = force;

}
update(source = Emitter.sources.USER) {
update() {
let source = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _emitter.default.sources.USER;
const oldRange = this.lastRange;

@@ -404,27 +372,12 @@ const [lastRange, nativeRange] = this.getRange();

}
if (!equal(oldRange, this.lastRange)) {
if (
!this.composing &&
nativeRange != null &&
nativeRange.native.collapsed &&
nativeRange.start.node !== this.cursor.textNode
) {
if (!(0, _lodashEs.isEqual)(oldRange, this.lastRange)) {
if (!this.composing && nativeRange != null && nativeRange.native.collapsed && nativeRange.start.node !== this.cursor.textNode) {
const range = this.cursor.restore();
if (range) {
this.setNativeRange(
range.startNode,
range.startOffset,
range.endNode,
range.endOffset,
);
this.setNativeRange(range.startNode, range.startOffset, range.endNode, range.endOffset);
}
}
const args = [
Emitter.events.SELECTION_CHANGE,
clone(this.lastRange),
clone(oldRange),
source,
];
this.emitter.emit(Emitter.events.EDITOR_CHANGE, ...args);
if (source !== Emitter.sources.SILENT) {
const args = [_emitter.default.events.SELECTION_CHANGE, (0, _lodashEs.cloneDeep)(this.lastRange), (0, _lodashEs.cloneDeep)(oldRange), source];
this.emitter.emit(_emitter.default.events.EDITOR_CHANGE, ...args);
if (source !== _emitter.default.sources.SILENT) {
this.emitter.emit(...args);

@@ -435,7 +388,7 @@ }

}
exports.default = Selection;
function contains(parent, descendant) {
try {
// Firefox inserts inaccessible nodes around video elements
descendant.parentNode; // eslint-disable-line no-unused-expressions
descendant.parentNode; // eslint-disable-line @typescript-eslint/no-unused-expressions
} catch (e) {

@@ -446,3 +399,2 @@ return false;

}
export { Range, Selection as default };
//# sourceMappingURL=selection.js.map

@@ -0,8 +1,19 @@

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
class Theme {
static DEFAULTS = {
modules: {}
};
static themes = {
default: Theme
};
modules = {};
constructor(quill, options) {
this.quill = quill;
this.options = options;
this.modules = {};
}
init() {

@@ -15,19 +26,10 @@ Object.keys(this.options.modules).forEach(name => {

}
addModule(name) {
// @ts-expect-error
const ModuleClass = this.quill.constructor.import(`modules/${name}`);
this.modules[name] = new ModuleClass(
this.quill,
this.options.modules[name] || {},
);
this.modules[name] = new ModuleClass(this.quill, this.options.modules[name] || {});
return this.modules[name];
}
}
Theme.DEFAULTS = {
modules: {},
};
Theme.themes = {
default: Theme,
};
export default Theme;
var _default = exports.default = Theme;
//# sourceMappingURL=theme.js.map

@@ -1,12 +0,15 @@

import { Attributor, ClassAttributor, Scope, StyleAttributor } from 'parchment';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.AlignStyle = exports.AlignClass = exports.AlignAttribute = void 0;
var _parchment = require("parchment");
const config = {
scope: Scope.BLOCK,
whitelist: ['right', 'center', 'justify'],
scope: _parchment.Scope.BLOCK,
whitelist: ['right', 'center', 'justify']
};
const AlignAttribute = new Attributor('align', 'align', config);
const AlignClass = new ClassAttributor('align', 'ql-align', config);
const AlignStyle = new StyleAttributor('align', 'text-align', config);
export { AlignAttribute, AlignClass, AlignStyle };
const AlignAttribute = exports.AlignAttribute = new _parchment.Attributor('align', 'align', config);
const AlignClass = exports.AlignClass = new _parchment.ClassAttributor('align', 'ql-align', config);
const AlignStyle = exports.AlignStyle = new _parchment.StyleAttributor('align', 'text-align', config);
//# sourceMappingURL=align.js.map

@@ -1,11 +0,15 @@

import { ClassAttributor, Scope } from 'parchment';
import { ColorAttributor } from './color';
"use strict";
const BackgroundClass = new ClassAttributor('background', 'ql-bg', {
scope: Scope.INLINE,
Object.defineProperty(exports, "__esModule", {
value: true
});
const BackgroundStyle = new ColorAttributor('background', 'background-color', {
scope: Scope.INLINE,
exports.BackgroundStyle = exports.BackgroundClass = void 0;
var _parchment = require("parchment");
var _color = require("./color");
const BackgroundClass = exports.BackgroundClass = new _parchment.ClassAttributor('background', 'ql-bg', {
scope: _parchment.Scope.INLINE
});
export { BackgroundClass, BackgroundStyle };
const BackgroundStyle = exports.BackgroundStyle = new _color.ColorAttributor('background', 'background-color', {
scope: _parchment.Scope.INLINE
});
//# sourceMappingURL=background.js.map

@@ -1,7 +0,14 @@

import Block from '../blots/block';
"use strict";
class Blockquote extends Block {}
Blockquote.blotName = 'blockquote';
Blockquote.tagName = 'blockquote';
export default Blockquote;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _block = _interopRequireDefault(require("../blots/block"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class Blockquote extends _block.default {
static blotName = 'blockquote';
static tagName = 'blockquote';
}
var _default = exports.default = Blockquote;
//# sourceMappingURL=blockquote.js.map

@@ -1,12 +0,18 @@

import Inline from '../blots/inline';
"use strict";
class Bold extends Inline {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _inline = _interopRequireDefault(require("../blots/inline"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class Bold extends _inline.default {
static blotName = 'bold';
static tagName = ['STRONG', 'B'];
static create() {
return super.create();
}
static formats() {
return true;
}
optimize(context) {

@@ -19,5 +25,3 @@ super.optimize(context);

}
Bold.blotName = 'bold';
Bold.tagName = ['STRONG', 'B'];
export default Bold;
var _default = exports.default = Bold;
//# sourceMappingURL=bold.js.map

@@ -1,35 +0,46 @@

import Block from '../blots/block';
import Break from '../blots/break';
import Cursor from '../blots/cursor';
import Inline from '../blots/inline';
import TextBlot, { escapeText } from '../blots/text';
import Container from '../blots/container';
import Quill from '../core/quill';
"use strict";
class CodeBlockContainer extends Container {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.CodeBlockContainer = exports.Code = void 0;
var _block = _interopRequireDefault(require("../blots/block"));
var _break = _interopRequireDefault(require("../blots/break"));
var _cursor = _interopRequireDefault(require("../blots/cursor"));
var _inline = _interopRequireDefault(require("../blots/inline"));
var _text = _interopRequireWildcard(require("../blots/text"));
var _container = _interopRequireDefault(require("../blots/container"));
var _quill = _interopRequireDefault(require("../core/quill"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class CodeBlockContainer extends _container.default {
static create(value) {
const domNode = super.create(value);
domNode.setAttribute('spellcheck', false);
domNode.setAttribute('spellcheck', 'false');
return domNode;
}
code(index, length) {
return this.children
// @ts-expect-error
.map(child => child.length() <= 1 ? '' : child.domNode.innerText).join('\n').slice(index, index + length);
}
html(index, length) {
const text = this.children
.map(child => child.domNode.innerText)
.join('\n')
.slice(index, index + length);
return `<pre>${escapeText(text)}</pre>`;
// `\n`s are needed in order to support empty lines at the beginning and the end.
// https://html.spec.whatwg.org/multipage/syntax.html#element-restrictions
return `<pre>\n${(0, _text.escapeText)(this.code(index, length))}\n</pre>`;
}
}
class CodeBlock extends Block {
exports.CodeBlockContainer = CodeBlockContainer;
class CodeBlock extends _block.default {
static TAB = ' ';
static register() {
Quill.register(CodeBlockContainer);
_quill.default.register(CodeBlockContainer);
}
}
class Code extends Inline {}
exports.default = CodeBlock;
class Code extends _inline.default {}
exports.Code = Code;
Code.blotName = 'code';
Code.tagName = 'CODE';
CodeBlock.blotName = 'code-block';

@@ -41,9 +52,5 @@ CodeBlock.className = 'ql-code-block';

CodeBlockContainer.tagName = 'DIV';
CodeBlockContainer.allowedChildren = [CodeBlock];
CodeBlock.allowedChildren = [TextBlot, Break, Cursor];
CodeBlock.allowedChildren = [_text.default, _break.default, _cursor.default];
CodeBlock.requiredContainer = CodeBlockContainer;
CodeBlock.TAB = ' ';
export { Code, CodeBlockContainer, CodeBlock as default };
//# sourceMappingURL=code.js.map

@@ -1,4 +0,9 @@

import { ClassAttributor, Scope, StyleAttributor } from 'parchment';
"use strict";
class ColorAttributor extends StyleAttributor {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ColorStyle = exports.ColorClass = exports.ColorAttributor = void 0;
var _parchment = require("parchment");
class ColorAttributor extends _parchment.StyleAttributor {
value(domNode) {

@@ -8,17 +13,13 @@ let value = super.value(domNode);

value = value.replace(/^[^\d]+/, '').replace(/[^\d]+$/, '');
const hex = value
.split(',')
.map(component => `00${parseInt(component, 10).toString(16)}`.slice(-2))
.join('');
const hex = value.split(',').map(component => `00${parseInt(component, 10).toString(16)}`.slice(-2)).join('');
return `#${hex}`;
}
}
const ColorClass = new ClassAttributor('color', 'ql-color', {
scope: Scope.INLINE,
exports.ColorAttributor = ColorAttributor;
const ColorClass = exports.ColorClass = new _parchment.ClassAttributor('color', 'ql-color', {
scope: _parchment.Scope.INLINE
});
const ColorStyle = new ColorAttributor('color', 'color', {
scope: Scope.INLINE,
const ColorStyle = exports.ColorStyle = new ColorAttributor('color', 'color', {
scope: _parchment.Scope.INLINE
});
export { ColorAttributor, ColorClass, ColorStyle };
//# sourceMappingURL=color.js.map

@@ -1,12 +0,15 @@

import { Attributor, ClassAttributor, Scope, StyleAttributor } from 'parchment';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.DirectionStyle = exports.DirectionClass = exports.DirectionAttribute = void 0;
var _parchment = require("parchment");
const config = {
scope: Scope.BLOCK,
whitelist: ['rtl'],
scope: _parchment.Scope.BLOCK,
whitelist: ['rtl']
};
const DirectionAttribute = new Attributor('direction', 'dir', config);
const DirectionClass = new ClassAttributor('direction', 'ql-direction', config);
const DirectionStyle = new StyleAttributor('direction', 'direction', config);
export { DirectionAttribute, DirectionClass, DirectionStyle };
const DirectionAttribute = exports.DirectionAttribute = new _parchment.Attributor('direction', 'dir', config);
const DirectionClass = exports.DirectionClass = new _parchment.ClassAttributor('direction', 'ql-direction', config);
const DirectionStyle = exports.DirectionStyle = new _parchment.StyleAttributor('direction', 'direction', config);
//# sourceMappingURL=direction.js.map

@@ -1,11 +0,14 @@

import { ClassAttributor, Scope, StyleAttributor } from 'parchment';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.FontStyle = exports.FontClass = void 0;
var _parchment = require("parchment");
const config = {
scope: Scope.INLINE,
whitelist: ['serif', 'monospace'],
scope: _parchment.Scope.INLINE,
whitelist: ['serif', 'monospace']
};
const FontClass = new ClassAttributor('font', 'ql-font', config);
class FontStyleAttributor extends StyleAttributor {
const FontClass = exports.FontClass = new _parchment.ClassAttributor('font', 'ql-font', config);
class FontStyleAttributor extends _parchment.StyleAttributor {
value(node) {

@@ -15,5 +18,3 @@ return super.value(node).replace(/["']/g, '');

}
const FontStyle = new FontStyleAttributor('font', 'font-family', config);
export { FontStyle, FontClass };
const FontStyle = exports.FontStyle = new FontStyleAttributor('font', 'font-family', config);
//# sourceMappingURL=font.js.map

@@ -1,5 +0,15 @@

import Embed from '../blots/embed';
"use strict";
class Formula extends Embed {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _embed = _interopRequireDefault(require("../blots/embed"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class Formula extends _embed.default {
static blotName = 'formula';
static className = 'ql-formula';
static tagName = 'SPAN';
static create(value) {
// @ts-expect-error
if (window.katex == null) {

@@ -10,5 +20,6 @@ throw new Error('Formula module requires KaTeX.');

if (typeof value === 'string') {
// @ts-expect-error
window.katex.render(value, node, {
throwOnError: false,
errorColor: '#f00',
errorColor: '#f00'
});

@@ -19,16 +30,13 @@ node.setAttribute('data-value', value);

}
static value(domNode) {
return domNode.getAttribute('data-value');
}
html() {
const { formula } = this.value();
const {
formula
} = this.value();
return `<span>${formula}</span>`;
}
}
Formula.blotName = 'formula';
Formula.className = 'ql-formula';
Formula.tagName = 'SPAN';
export default Formula;
var _default = exports.default = Formula;
//# sourceMappingURL=formula.js.map

@@ -1,4 +0,12 @@

import Block from '../blots/block';
"use strict";
class Header extends Block {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _block = _interopRequireDefault(require("../blots/block"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class Header extends _block.default {
static blotName = 'header';
static tagName = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6'];
static formats(domNode) {

@@ -8,5 +16,3 @@ return this.tagName.indexOf(domNode.tagName) + 1;

}
Header.blotName = 'header';
Header.tagName = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6'];
export default Header;
var _default = exports.default = Header;
//# sourceMappingURL=header.js.map

@@ -1,7 +0,13 @@

import { EmbedBlot } from 'parchment';
import { sanitize } from './link';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _parchment = require("parchment");
var _link = require("./link");
const ATTRIBUTES = ['alt', 'height', 'width'];
class Image extends EmbedBlot {
class Image extends _parchment.EmbedBlot {
static blotName = 'image';
static tagName = 'IMG';
static create(value) {

@@ -14,3 +20,2 @@ const node = super.create(value);

}
static formats(domNode) {

@@ -24,7 +29,5 @@ return ATTRIBUTES.reduce((formats, attribute) => {

}
static match(url) {
return /\.(jpe?g|gif|png)$/.test(url) || /^data:image\/.+;base64/.test(url);
}
static register() {

@@ -34,2 +37,3 @@ if (/Firefox/i.test(navigator.userAgent)) {

// Disable image resizing in Firefox
// @ts-expect-error
document.execCommand('enableObjectResizing', false, false);

@@ -39,11 +43,8 @@ }, 1);

}
static sanitize(url) {
return sanitize(url, ['http', 'https', 'data']) ? url : '//:0';
return (0, _link.sanitize)(url, ['http', 'https', 'data']) ? url : '//:0';
}
static value(domNode) {
return domNode.getAttribute('src');
}
format(name, value) {

@@ -61,5 +62,3 @@ if (ATTRIBUTES.indexOf(name) > -1) {

}
Image.blotName = 'image';
Image.tagName = 'IMG';
export default Image;
var _default = exports.default = Image;
//# sourceMappingURL=image.js.map

@@ -1,20 +0,26 @@

import { ClassAttributor, Scope } from 'parchment';
"use strict";
class IndentAttributor extends ClassAttributor {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _parchment = require("parchment");
class IndentAttributor extends _parchment.ClassAttributor {
add(node, value) {
let normalizedValue = 0;
if (value === '+1' || value === '-1') {
const indent = this.value(node) || 0;
value = value === '+1' ? indent + 1 : indent - 1;
normalizedValue = value === '+1' ? indent + 1 : indent - 1;
} else if (typeof value === 'number') {
normalizedValue = value;
}
if (value === 0) {
if (normalizedValue === 0) {
this.remove(node);
return true;
}
return super.add(node, value);
return super.add(node, normalizedValue.toString());
}
canAdd(node, value) {
return super.canAdd(node, value) || super.canAdd(node, parseInt(value, 10));
}
value(node) {

@@ -26,6 +32,7 @@ return parseInt(super.value(node), 10) || undefined; // Don't return NaN

const IndentClass = new IndentAttributor('indent', 'ql-indent', {
scope: Scope.BLOCK,
whitelist: [1, 2, 3, 4, 5, 6, 7, 8],
scope: _parchment.Scope.BLOCK,
// @ts-expect-error
whitelist: [1, 2, 3, 4, 5, 6, 7, 8]
});
export default IndentClass;
var _default = exports.default = IndentClass;
//# sourceMappingURL=indent.js.map

@@ -1,7 +0,14 @@

import Bold from './bold';
"use strict";
class Italic extends Bold {}
Italic.blotName = 'italic';
Italic.tagName = ['EM', 'I'];
export default Italic;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _bold = _interopRequireDefault(require("./bold"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class Italic extends _bold.default {
static blotName = 'italic';
static tagName = ['EM', 'I'];
}
var _default = exports.default = Italic;
//# sourceMappingURL=italic.js.map

@@ -1,4 +0,15 @@

import Inline from '../blots/inline';
"use strict";
class Link extends Inline {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
exports.sanitize = sanitize;
var _inline = _interopRequireDefault(require("../blots/inline"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class Link extends _inline.default {
static blotName = 'link';
static tagName = 'A';
static SANITIZED_URL = 'about:blank';
static PROTOCOL_WHITELIST = ['http', 'https', 'mailto', 'tel', 'sms'];
static create(value) {

@@ -11,11 +22,8 @@ const node = super.create(value);

}
static formats(domNode) {
return domNode.getAttribute('href');
}
static sanitize(url) {
return sanitize(url, this.PROTOCOL_WHITELIST) ? url : this.SANITIZED_URL;
}
format(name, value) {

@@ -25,2 +33,3 @@ if (name !== this.statics.blotName || !value) {

} else {
// @ts-expect-error
this.domNode.setAttribute('href', this.constructor.sanitize(value));

@@ -30,7 +39,3 @@ }

}
Link.blotName = 'link';
Link.tagName = 'A';
Link.SANITIZED_URL = 'about:blank';
Link.PROTOCOL_WHITELIST = ['http', 'https', 'mailto', 'tel'];
exports.default = Link;
function sanitize(url, protocols) {

@@ -42,3 +47,2 @@ const anchor = document.createElement('a');

}
export { Link as default, sanitize };
//# sourceMappingURL=link.js.map

@@ -1,10 +0,16 @@

import Block from '../blots/block';
import Container from '../blots/container';
import Quill from '../core/quill';
"use strict";
class ListContainer extends Container {}
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.ListContainer = void 0;
var _block = _interopRequireDefault(require("../blots/block"));
var _container = _interopRequireDefault(require("../blots/container"));
var _quill = _interopRequireDefault(require("../core/quill"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class ListContainer extends _container.default {}
exports.ListContainer = ListContainer;
ListContainer.blotName = 'list-container';
ListContainer.tagName = 'OL';
class ListItem extends Block {
class ListItem extends _block.default {
static create(value) {

@@ -15,11 +21,8 @@ const node = super.create();

}
static formats(domNode) {
return domNode.getAttribute('data-list') || undefined;
}
static register() {
Quill.register(ListContainer);
_quill.default.register(ListContainer);
}
constructor(scroll, domNode) {

@@ -43,3 +46,2 @@ super(scroll, domNode);

}
format(name, value) {

@@ -53,8 +55,7 @@ if (name === this.statics.blotName && value) {

}
exports.default = ListItem;
ListItem.blotName = 'list';
ListItem.tagName = 'LI';
ListContainer.allowedChildren = [ListItem];
ListItem.requiredContainer = ListContainer;
export { ListContainer, ListItem as default };
//# sourceMappingURL=list.js.map

@@ -1,4 +0,12 @@

import Inline from '../blots/inline';
"use strict";
class Script extends Inline {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _inline = _interopRequireDefault(require("../blots/inline"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class Script extends _inline.default {
static blotName = 'script';
static tagName = ['SUB', 'SUP'];
static create(value) {

@@ -13,3 +21,2 @@ if (value === 'super') {

}
static formats(domNode) {

@@ -21,5 +28,3 @@ if (domNode.tagName === 'SUB') return 'sub';

}
Script.blotName = 'script';
Script.tagName = ['SUB', 'SUP'];
export default Script;
var _default = exports.default = Script;
//# sourceMappingURL=script.js.map

@@ -1,12 +0,16 @@

import { ClassAttributor, Scope, StyleAttributor } from 'parchment';
"use strict";
const SizeClass = new ClassAttributor('size', 'ql-size', {
scope: Scope.INLINE,
whitelist: ['small', 'large', 'huge'],
Object.defineProperty(exports, "__esModule", {
value: true
});
const SizeStyle = new StyleAttributor('size', 'font-size', {
scope: Scope.INLINE,
whitelist: ['10px', '18px', '32px'],
exports.SizeStyle = exports.SizeClass = void 0;
var _parchment = require("parchment");
const SizeClass = exports.SizeClass = new _parchment.ClassAttributor('size', 'ql-size', {
scope: _parchment.Scope.INLINE,
whitelist: ['small', 'large', 'huge']
});
export { SizeClass, SizeStyle };
const SizeStyle = exports.SizeStyle = new _parchment.StyleAttributor('size', 'font-size', {
scope: _parchment.Scope.INLINE,
whitelist: ['10px', '18px', '32px']
});
//# sourceMappingURL=size.js.map

@@ -1,7 +0,14 @@

import Bold from './bold';
"use strict";
class Strike extends Bold {}
Strike.blotName = 'strike';
Strike.tagName = ['S', 'STRIKE'];
export default Strike;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _bold = _interopRequireDefault(require("./bold"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class Strike extends _bold.default {
static blotName = 'strike';
static tagName = ['S', 'STRIKE'];
}
var _default = exports.default = Strike;
//# sourceMappingURL=strike.js.map

@@ -1,5 +0,14 @@

import Block from '../blots/block';
import Container from '../blots/container';
"use strict";
class TableCell extends Block {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.TableRow = exports.TableContainer = exports.TableCell = exports.TableBody = void 0;
exports.tableId = tableId;
var _block = _interopRequireDefault(require("../blots/block"));
var _container = _interopRequireDefault(require("../blots/container"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class TableCell extends _block.default {
static blotName = 'table';
static tagName = 'TD';
static create(value) {

@@ -14,3 +23,2 @@ const node = super.create();

}
static formats(domNode) {

@@ -22,3 +30,2 @@ if (domNode.hasAttribute('data-row')) {

}
cellOffset() {

@@ -30,3 +37,2 @@ if (this.parent) {

}
format(name, value) {

@@ -39,7 +45,5 @@ if (name === TableCell.blotName && value) {

}
row() {
return this.parent;
}
rowOffset() {

@@ -51,3 +55,2 @@ if (this.row()) {

}
table() {

@@ -57,23 +60,23 @@ return this.row() && this.row().table();

}
TableCell.blotName = 'table';
TableCell.tagName = 'TD';
class TableRow extends Container {
exports.TableCell = TableCell;
class TableRow extends _container.default {
static blotName = 'table-row';
static tagName = 'TR';
checkMerge() {
// @ts-expect-error
if (super.checkMerge() && this.next.children.head != null) {
// @ts-expect-error
const thisHead = this.children.head.formats();
// @ts-expect-error
const thisTail = this.children.tail.formats();
// @ts-expect-error
const nextHead = this.next.children.head.formats();
// @ts-expect-error
const nextTail = this.next.children.tail.formats();
return (
thisHead.table === thisTail.table &&
thisHead.table === nextHead.table &&
thisHead.table === nextTail.table
);
return thisHead.table === thisTail.table && thisHead.table === nextHead.table && thisHead.table === nextTail.table;
}
return false;
}
optimize(...args) {
super.optimize(...args);
optimize(context) {
super.optimize(context);
this.children.forEach(child => {

@@ -86,2 +89,3 @@ if (child.next == null) return;

if (next) {
// @ts-expect-error TODO: parameters of optimize() should be a optional
next.optimize();

@@ -91,2 +95,3 @@ }

if (this.prev) {
// @ts-expect-error TODO: parameters of optimize() should be a optional
this.prev.optimize();

@@ -97,3 +102,2 @@ }

}
rowOffset() {

@@ -105,3 +109,2 @@ if (this.parent) {

}
table() {

@@ -111,10 +114,11 @@ return this.parent && this.parent.parent;

}
TableRow.blotName = 'table-row';
TableRow.tagName = 'TR';
class TableBody extends Container {}
TableBody.blotName = 'table-body';
TableBody.tagName = 'TBODY';
class TableContainer extends Container {
exports.TableRow = TableRow;
class TableBody extends _container.default {
static blotName = 'table-body';
static tagName = 'TBODY';
}
exports.TableBody = TableBody;
class TableContainer extends _container.default {
static blotName = 'table-container';
static tagName = 'TABLE';
balanceCells() {

@@ -133,2 +137,3 @@ const rows = this.descendants(TableRow);

row.appendChild(blot);
// @ts-expect-error TODO: parameters of optimize() should be a optional
blot.optimize(); // Add break blot

@@ -142,4 +147,4 @@ });

}
deleteColumn(index) {
// @ts-expect-error
const [body] = this.descendant(TableBody);

@@ -154,4 +159,4 @@ if (body == null || body.children.head == null) return;

}
insertColumn(index) {
// @ts-expect-error
const [body] = this.descendant(TableBody);

@@ -161,2 +166,3 @@ if (body == null || body.children.head == null) return;

const ref = row.children.at(index);
// @ts-expect-error
const value = TableCell.formats(row.children.head.domNode);

@@ -167,4 +173,4 @@ const cell = this.scroll.create(TableCell.blotName, value);

}
insertRow(index) {
// @ts-expect-error
const [body] = this.descendant(TableBody);

@@ -181,3 +187,2 @@ if (body == null || body.children.head == null) return;

}
rows() {

@@ -189,21 +194,13 @@ const body = this.children.head;

}
TableContainer.blotName = 'table-container';
TableContainer.tagName = 'TABLE';
exports.TableContainer = TableContainer;
TableContainer.allowedChildren = [TableBody];
TableBody.requiredContainer = TableContainer;
TableBody.allowedChildren = [TableRow];
TableRow.requiredContainer = TableBody;
TableRow.allowedChildren = [TableCell];
TableCell.requiredContainer = TableRow;
function tableId() {
const id = Math.random()
.toString(36)
.slice(2, 6);
const id = Math.random().toString(36).slice(2, 6);
return `row-${id}`;
}
export { TableCell, TableRow, TableBody, TableContainer, tableId };
//# sourceMappingURL=table.js.map

@@ -1,7 +0,14 @@

import Inline from '../blots/inline';
"use strict";
class Underline extends Inline {}
Underline.blotName = 'underline';
Underline.tagName = 'U';
export default Underline;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _inline = _interopRequireDefault(require("../blots/inline"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class Underline extends _inline.default {
static blotName = 'underline';
static tagName = 'U';
}
var _default = exports.default = Underline;
//# sourceMappingURL=underline.js.map

@@ -1,15 +0,22 @@

import { BlockEmbed } from '../blots/block';
import Link from './link';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _block = require("../blots/block");
var _link = _interopRequireDefault(require("./link"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const ATTRIBUTES = ['height', 'width'];
class Video extends BlockEmbed {
class Video extends _block.BlockEmbed {
static blotName = 'video';
static className = 'ql-video';
static tagName = 'IFRAME';
static create(value) {
const node = super.create(value);
node.setAttribute('frameborder', '0');
node.setAttribute('allowfullscreen', true);
node.setAttribute('allowfullscreen', 'true');
node.setAttribute('src', this.sanitize(value));
return node;
}
static formats(domNode) {

@@ -23,11 +30,8 @@ return ATTRIBUTES.reduce((formats, attribute) => {

}
static sanitize(url) {
return Link.sanitize(url); // eslint-disable-line import/no-named-as-default-member
return _link.default.sanitize(url);
}
static value(domNode) {
return domNode.getAttribute('src');
}
format(name, value) {

@@ -44,12 +48,10 @@ if (ATTRIBUTES.indexOf(name) > -1) {

}
html() {
const { video } = this.value();
const {
video
} = this.value();
return `<a href="${video}">${video}</a>`;
}
}
Video.blotName = 'video';
Video.className = 'ql-video';
Video.tagName = 'IFRAME';
export default Video;
var _default = exports.default = Video;
//# sourceMappingURL=video.js.map

@@ -1,65 +0,39 @@

import extend from 'extend';
import Delta from 'quill-delta';
import {
Attributor,
ClassAttributor,
EmbedBlot,
Scope,
StyleAttributor,
BlockBlot,
} from 'parchment';
import { BlockEmbed } from '../blots/block';
import Quill from '../core/quill';
import logger from '../core/logger';
import Module from '../core/module';
"use strict";
import { AlignAttribute, AlignStyle } from '../formats/align';
import { BackgroundStyle } from '../formats/background';
import CodeBlock from '../formats/code';
import { ColorStyle } from '../formats/color';
import { DirectionAttribute, DirectionStyle } from '../formats/direction';
import { FontStyle } from '../formats/font';
import { SizeStyle } from '../formats/size';
const debug = logger('quill:clipboard');
const CLIPBOARD_CONFIG = [
[Node.TEXT_NODE, matchText],
[Node.TEXT_NODE, matchNewline],
['br', matchBreak],
[Node.ELEMENT_NODE, matchNewline],
[Node.ELEMENT_NODE, matchBlot],
[Node.ELEMENT_NODE, matchAttributor],
[Node.ELEMENT_NODE, matchStyles],
['li', matchIndent],
['ol, ul', matchList],
['pre', matchCodeBlock],
['tr', matchTable],
['b', matchAlias.bind(matchAlias, 'bold')],
['i', matchAlias.bind(matchAlias, 'italic')],
['strike', matchAlias.bind(matchAlias, 'strike')],
['style', matchIgnore],
];
const ATTRIBUTE_ATTRIBUTORS = [AlignAttribute, DirectionAttribute].reduce(
(memo, attr) => {
memo[attr.keyName] = attr;
return memo;
},
{},
);
const STYLE_ATTRIBUTORS = [
AlignStyle,
BackgroundStyle,
ColorStyle,
DirectionStyle,
FontStyle,
SizeStyle,
].reduce((memo, attr) => {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
exports.matchAttributor = matchAttributor;
exports.matchBlot = matchBlot;
exports.matchNewline = matchNewline;
exports.matchText = matchText;
exports.traverse = traverse;
var _parchment = require("parchment");
var _quillDelta = _interopRequireDefault(require("quill-delta"));
var _block = require("../blots/block");
var _logger = _interopRequireDefault(require("../core/logger"));
var _module = _interopRequireDefault(require("../core/module"));
var _quill = _interopRequireDefault(require("../core/quill"));
var _align = require("../formats/align");
var _background = require("../formats/background");
var _code = _interopRequireDefault(require("../formats/code"));
var _color = require("../formats/color");
var _direction = require("../formats/direction");
var _font = require("../formats/font");
var _size = require("../formats/size");
var _keyboard = require("./keyboard");
var _normalizeExternalHTML = _interopRequireDefault(require("./normalizeExternalHTML"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const debug = (0, _logger.default)('quill:clipboard');
const CLIPBOARD_CONFIG = [[Node.TEXT_NODE, matchText], [Node.TEXT_NODE, matchNewline], ['br', matchBreak], [Node.ELEMENT_NODE, matchNewline], [Node.ELEMENT_NODE, matchBlot], [Node.ELEMENT_NODE, matchAttributor], [Node.ELEMENT_NODE, matchStyles], ['li', matchIndent], ['ol, ul', matchList], ['pre', matchCodeBlock], ['tr', matchTable], ['b', createMatchAlias('bold')], ['i', createMatchAlias('italic')], ['strike', createMatchAlias('strike')], ['style', matchIgnore]];
const ATTRIBUTE_ATTRIBUTORS = [_align.AlignAttribute, _direction.DirectionAttribute].reduce((memo, attr) => {
memo[attr.keyName] = attr;
return memo;
}, {});
class Clipboard extends Module {
const STYLE_ATTRIBUTORS = [_align.AlignStyle, _background.BackgroundStyle, _color.ColorStyle, _direction.DirectionStyle, _font.FontStyle, _size.SizeStyle].reduce((memo, attr) => {
memo[attr.keyName] = attr;
return memo;
}, {});
class Clipboard extends _module.default {
constructor(quill, options) {

@@ -71,62 +45,64 @@ super(quill, options);

this.matchers = [];
CLIPBOARD_CONFIG.concat(this.options.matchers).forEach(
([selector, matcher]) => {
this.addMatcher(selector, matcher);
},
);
// @ts-expect-error Fix me later
CLIPBOARD_CONFIG.concat(this.options.matchers).forEach(_ref => {
let [selector, matcher] = _ref;
this.addMatcher(selector, matcher);
});
}
addMatcher(selector, matcher) {
this.matchers.push([selector, matcher]);
}
convert({ html, text }, formats = {}) {
if (formats[CodeBlock.blotName]) {
return new Delta().insert(text, {
[CodeBlock.blotName]: formats[CodeBlock.blotName],
convert(_ref2) {
let {
html,
text
} = _ref2;
let formats = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (formats[_code.default.blotName]) {
return new _quillDelta.default().insert(text || '', {
[_code.default.blotName]: formats[_code.default.blotName]
});
}
if (!html) {
return new Delta().insert(text || '');
return new _quillDelta.default().insert(text || '', formats);
}
const doc = new DOMParser().parseFromString(html, 'text/html');
const container = doc.body;
const nodeMatches = new WeakMap();
const [elementMatchers, textMatchers] = this.prepareMatching(
container,
nodeMatches,
);
const delta = traverse(
this.quill.scroll,
container,
elementMatchers,
textMatchers,
nodeMatches,
);
const delta = this.convertHTML(html);
// Remove trailing newline
if (
deltaEndsWith(delta, '\n') &&
(delta.ops[delta.ops.length - 1].attributes == null || formats.table)
) {
return delta.compose(new Delta().retain(delta.length() - 1).delete(1));
if (deltaEndsWith(delta, '\n') && (delta.ops[delta.ops.length - 1].attributes == null || formats.table)) {
return delta.compose(new _quillDelta.default().retain(delta.length() - 1).delete(1));
}
return delta;
}
dangerouslyPasteHTML(index, html, source = Quill.sources.API) {
normalizeHTML(doc) {
(0, _normalizeExternalHTML.default)(doc);
}
convertHTML(html) {
const doc = new DOMParser().parseFromString(html, 'text/html');
this.normalizeHTML(doc);
const container = doc.body;
const nodeMatches = new WeakMap();
const [elementMatchers, textMatchers] = this.prepareMatching(container, nodeMatches);
return traverse(this.quill.scroll, container, elementMatchers, textMatchers, nodeMatches);
}
dangerouslyPasteHTML(index, html) {
let source = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _quill.default.sources.API;
if (typeof index === 'string') {
const delta = this.convert({ html: index, text: '' });
const delta = this.convert({
html: index,
text: ''
});
// @ts-expect-error
this.quill.setContents(delta, html);
this.quill.setSelection(0, Quill.sources.SILENT);
this.quill.setSelection(0, _quill.default.sources.SILENT);
} else {
const paste = this.convert({ html, text: '' });
this.quill.updateContents(
new Delta().retain(index).concat(paste),
source,
);
this.quill.setSelection(index + paste.length(), Quill.sources.SILENT);
const paste = this.convert({
html,
text: ''
});
this.quill.updateContents(new _quillDelta.default().retain(index).concat(paste), source);
this.quill.setSelection(index + paste.length(), _quill.default.sources.SILENT);
}
}
onCaptureCopy(e, isCut = false) {
onCaptureCopy(e) {
let isCut = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (e.defaultPrevented) return;

@@ -136,10 +112,15 @@ e.preventDefault();

if (range == null) return;
const { html, text } = this.onCopy(range, isCut);
e.clipboardData.setData('text/plain', text);
e.clipboardData.setData('text/html', html);
const {
html,
text
} = this.onCopy(range, isCut);
e.clipboardData?.setData('text/plain', text);
e.clipboardData?.setData('text/html', html);
if (isCut) {
this.quill.deleteText(range, Quill.sources.USER);
(0, _keyboard.deleteRange)({
range,
quill: this.quill
});
}
}
onCapturePaste(e) {

@@ -150,35 +131,49 @@ if (e.defaultPrevented || !this.quill.isEnabled()) return;

if (range == null) return;
const html = e.clipboardData.getData('text/html');
const text = e.clipboardData.getData('text/plain');
const files = Array.from(e.clipboardData.files || []);
const html = e.clipboardData?.getData('text/html');
const text = e.clipboardData?.getData('text/plain');
const files = Array.from(e.clipboardData?.files || []);
if (!html && files.length > 0) {
this.quill.uploader.upload(range, files);
} else {
this.onPaste(range, { html, text });
return;
}
if (html && files.length > 0) {
const doc = new DOMParser().parseFromString(html, 'text/html');
if (doc.body.childElementCount === 1 && doc.body.firstElementChild?.tagName === 'IMG') {
this.quill.uploader.upload(range, files);
return;
}
}
this.onPaste(range, {
html,
text
});
}
onCopy(range) {
const text = this.quill.getText(range);
const html = this.quill.getSemanticHTML(range);
return { html, text };
return {
html,
text
};
}
onPaste(range, { text, html }) {
onPaste(range, _ref3) {
let {
text,
html
} = _ref3;
const formats = this.quill.getFormat(range.index);
const pastedDelta = this.convert({ text, html }, formats);
debug.log('onPaste', pastedDelta, { text, html });
const delta = new Delta()
.retain(range.index)
.delete(range.length)
.concat(pastedDelta);
this.quill.updateContents(delta, Quill.sources.USER);
const pastedDelta = this.convert({
text,
html
}, formats);
debug.log('onPaste', pastedDelta, {
text,
html
});
const delta = new _quillDelta.default().retain(range.index).delete(range.length).concat(pastedDelta);
this.quill.updateContents(delta, _quill.default.sources.USER);
// range.length contributes to delta.length()
this.quill.setSelection(
delta.length() - range.length,
Quill.sources.SILENT,
);
this.quill.scrollIntoView();
this.quill.setSelection(delta.length() - range.length, _quill.default.sources.SILENT);
this.quill.scrollSelectionIntoView();
}
prepareMatching(container, nodeMatches) {

@@ -200,3 +195,3 @@ const elementMatchers = [];

const matches = nodeMatches.get(node);
matches.push(matcher);
matches?.push(matcher);
} else {

@@ -212,11 +207,9 @@ nodeMatches.set(node, [matcher]);

}
exports.default = Clipboard;
Clipboard.DEFAULTS = {
matchers: [],
matchers: []
};
function applyFormat(delta, format, value) {
if (typeof format === 'object') {
return Object.keys(format).reduce((newDelta, key) => {
return applyFormat(newDelta, key, format[key]);
}, delta);
function applyFormat(delta, format, value, scroll) {
if (!scroll.query(format)) {
return delta;
}

@@ -227,15 +220,15 @@ return delta.reduce((newDelta, op) => {

}
return newDelta.insert(
op.insert,
extend({}, { [format]: value }, op.attributes),
);
}, new Delta());
const formats = value ? {
[format]: value
} : {};
// @ts-expect-error Fix me later
return newDelta.insert(op.insert, {
...formats,
...op.attributes
});
}, new _quillDelta.default());
}
function deltaEndsWith(delta, text) {
let endText = '';
for (
let i = delta.ops.length - 1;
i >= 0 && endText.length < text.length;
--i // eslint-disable-line no-plusplus
for (let i = delta.ops.length - 1; i >= 0 && endText.length < text.length; --i // eslint-disable-line no-plusplus
) {

@@ -248,43 +241,12 @@ const op = delta.ops[i];

}
function isLine(node) {
if (node.childNodes.length === 0) return false; // Exclude embed blocks
return [
'address',
'article',
'blockquote',
'canvas',
'dd',
'div',
'dl',
'dt',
'fieldset',
'figcaption',
'figure',
'footer',
'form',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'header',
'iframe',
'li',
'main',
'nav',
'ol',
'output',
'p',
'pre',
'section',
'table',
'td',
'tr',
'ul',
'video',
].includes(node.tagName.toLowerCase());
function isLine(node, scroll) {
if (!(node instanceof Element)) return false;
const match = scroll.query(node);
// @ts-expect-error
if (match && match.prototype instanceof _parchment.EmbedBlot) return false;
return ['address', 'article', 'blockquote', 'canvas', 'dd', 'div', 'dl', 'dt', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'iframe', 'li', 'main', 'nav', 'ol', 'output', 'p', 'pre', 'section', 'table', 'td', 'tr', 'ul', 'video'].includes(node.tagName.toLowerCase());
}
function isBetweenInlineElements(node, scroll) {
return node.previousElementSibling && node.nextElementSibling && !isLine(node.previousElementSibling, scroll) && !isLine(node.nextElementSibling, scroll);
}
const preNodes = new WeakMap();

@@ -294,2 +256,3 @@ function isPre(node) {

if (!preNodes.has(node)) {
// @ts-expect-error
if (node.tagName === 'PRE') {

@@ -303,3 +266,2 @@ preNodes.set(node, true);

}
function traverse(scroll, node, elementMatchers, textMatchers, nodeMatches) {

@@ -310,13 +272,7 @@ // Post-order

return matcher(node, delta, scroll);
}, new Delta());
}, new _quillDelta.default());
}
if (node.nodeType === node.ELEMENT_NODE) {
return Array.from(node.childNodes || []).reduce((delta, childNode) => {
let childrenDelta = traverse(
scroll,
childNode,
elementMatchers,
textMatchers,
nodeMatches,
);
let childrenDelta = traverse(scroll, childNode, elementMatchers, textMatchers, nodeMatches);
if (childNode.nodeType === node.ELEMENT_NODE) {

@@ -326,65 +282,63 @@ childrenDelta = elementMatchers.reduce((reducedDelta, matcher) => {

}, childrenDelta);
childrenDelta = (nodeMatches.get(childNode) || []).reduce(
(reducedDelta, matcher) => {
return matcher(childNode, reducedDelta, scroll);
},
childrenDelta,
);
childrenDelta = (nodeMatches.get(childNode) || []).reduce((reducedDelta, matcher) => {
return matcher(childNode, reducedDelta, scroll);
}, childrenDelta);
}
return delta.concat(childrenDelta);
}, new Delta());
}, new _quillDelta.default());
}
return new Delta();
return new _quillDelta.default();
}
function matchAlias(format, node, delta) {
return applyFormat(delta, format, true);
function createMatchAlias(format) {
return (_node, delta, scroll) => {
return applyFormat(delta, format, true, scroll);
};
}
function matchAttributor(node, delta, scroll) {
const attributes = Attributor.keys(node);
const classes = ClassAttributor.keys(node);
const styles = StyleAttributor.keys(node);
const attributes = _parchment.Attributor.keys(node);
const classes = _parchment.ClassAttributor.keys(node);
const styles = _parchment.StyleAttributor.keys(node);
const formats = {};
attributes
.concat(classes)
.concat(styles)
.forEach(name => {
let attr = scroll.query(name, Scope.ATTRIBUTE);
if (attr != null) {
formats[attr.attrName] = attr.value(node);
if (formats[attr.attrName]) return;
}
attr = ATTRIBUTE_ATTRIBUTORS[name];
if (attr != null && (attr.attrName === name || attr.keyName === name)) {
formats[attr.attrName] = attr.value(node) || undefined;
}
attributes.concat(classes).concat(styles).forEach(name => {
let attr = scroll.query(name, _parchment.Scope.ATTRIBUTE);
if (attr != null) {
formats[attr.attrName] = attr.value(node);
if (formats[attr.attrName]) return;
}
attr = ATTRIBUTE_ATTRIBUTORS[name];
if (attr != null && (attr.attrName === name || attr.keyName === name)) {
formats[attr.attrName] = attr.value(node) || undefined;
}
attr = STYLE_ATTRIBUTORS[name];
if (attr != null && (attr.attrName === name || attr.keyName === name)) {
attr = STYLE_ATTRIBUTORS[name];
if (attr != null && (attr.attrName === name || attr.keyName === name)) {
attr = STYLE_ATTRIBUTORS[name];
formats[attr.attrName] = attr.value(node) || undefined;
}
});
if (Object.keys(formats).length > 0) {
return applyFormat(delta, formats);
}
return delta;
formats[attr.attrName] = attr.value(node) || undefined;
}
});
return Object.entries(formats).reduce((newDelta, _ref4) => {
let [name, value] = _ref4;
return applyFormat(newDelta, name, value, scroll);
}, delta);
}
function matchBlot(node, delta, scroll) {
const match = scroll.query(node);
if (match == null) return delta;
if (match.prototype instanceof EmbedBlot) {
// @ts-expect-error
if (match.prototype instanceof _parchment.EmbedBlot) {
const embed = {};
// @ts-expect-error
const value = match.value(node);
if (value != null) {
// @ts-expect-error
embed[match.blotName] = value;
return new Delta().insert(embed, match.formats(node, scroll));
// @ts-expect-error
return new _quillDelta.default().insert(embed, match.formats(node, scroll));
}
} else {
if (match.prototype instanceof BlockBlot && !deltaEndsWith(delta, '\n')) {
// @ts-expect-error
if (match.prototype instanceof _parchment.BlockBlot && !deltaEndsWith(delta, '\n')) {
delta.insert('\n');
}
if (typeof match.formats === 'function') {
return applyFormat(delta, match.blotName, match.formats(node, scroll));
if ('blotName' in match && 'formats' in match && typeof match.formats === 'function') {
return applyFormat(delta, match.blotName, match.formats(node, scroll), scroll);
}

@@ -394,3 +348,2 @@ }

}
function matchBreak(node, delta) {

@@ -402,20 +355,15 @@ if (!deltaEndsWith(delta, '\n')) {

}
function matchCodeBlock(node, delta, scroll) {
const match = scroll.query('code-block');
const language = match ? match.formats(node, scroll) : true;
return applyFormat(delta, 'code-block', language);
const language = match && 'formats' in match && typeof match.formats === 'function' ? match.formats(node, scroll) : true;
return applyFormat(delta, 'code-block', language, scroll);
}
function matchIgnore() {
return new Delta();
return new _quillDelta.default();
}
function matchIndent(node, delta, scroll) {
const match = scroll.query(node);
if (
match == null ||
match.blotName !== 'list' ||
!deltaEndsWith(delta, '\n')
) {
if (match == null ||
// @ts-expect-error
match.blotName !== 'list' || !deltaEndsWith(delta, '\n')) {
return delta;

@@ -426,2 +374,3 @@ }

while (parent != null) {
// @ts-expect-error
if (['OL', 'UL'].includes(parent.tagName)) {

@@ -434,27 +383,31 @@ indent += 1;

return delta.reduce((composed, op) => {
if (op.attributes && op.attributes.list) {
if (op.attributes && typeof op.attributes.indent === 'number') {
return composed.push(op);
}
return composed.insert(op.insert, { indent, ...(op.attributes || {}) });
}, new Delta());
// @ts-expect-error Fix me later
return composed.insert(op.insert, {
indent,
...(op.attributes || {})
});
}, new _quillDelta.default());
}
function matchList(node, delta) {
function matchList(node, delta, scroll) {
// @ts-expect-error
const list = node.tagName === 'OL' ? 'ordered' : 'bullet';
return applyFormat(delta, 'list', list);
return applyFormat(delta, 'list', list, scroll);
}
function matchNewline(node, delta, scroll) {
if (!deltaEndsWith(delta, '\n')) {
if (isLine(node)) {
if (isLine(node, scroll)) {
return delta.insert('\n');
}
if (delta.length() > 0 && node.nextSibling) {
let { nextSibling } = node;
let nextSibling = node.nextSibling;
while (nextSibling != null) {
if (isLine(nextSibling)) {
if (isLine(nextSibling, scroll)) {
return delta.insert('\n');
}
const match = scroll.query(nextSibling);
if (match && match.prototype instanceof BlockEmbed) {
// @ts-expect-error
if (match && match.prototype instanceof _block.BlockEmbed) {
return delta.insert('\n');

@@ -468,4 +421,3 @@ }

}
function matchStyles(node, delta) {
function matchStyles(node, delta, scroll) {
const formats = {};

@@ -482,38 +434,38 @@ const style = node.style || {};

}
if (
style.fontWeight.startsWith('bold') ||
parseInt(style.fontWeight, 10) >= 700
) {
if (style.fontWeight?.startsWith('bold') ||
// @ts-expect-error Fix me later
parseInt(style.fontWeight, 10) >= 700) {
formats.bold = true;
}
if (Object.keys(formats).length > 0) {
delta = applyFormat(delta, formats);
}
delta = Object.entries(formats).reduce((newDelta, _ref5) => {
let [name, value] = _ref5;
return applyFormat(newDelta, name, value, scroll);
}, delta);
// @ts-expect-error
if (parseFloat(style.textIndent || 0) > 0) {
// Could be 0.5in
return new Delta().insert('\t').concat(delta);
return new _quillDelta.default().insert('\t').concat(delta);
}
return delta;
}
function matchTable(node, delta) {
const table =
node.parentNode.tagName === 'TABLE'
? node.parentNode
: node.parentNode.parentNode;
const rows = Array.from(table.querySelectorAll('tr'));
const row = rows.indexOf(node) + 1;
return applyFormat(delta, 'table', row);
function matchTable(node, delta, scroll) {
const table = node.parentElement?.tagName === 'TABLE' ? node.parentElement : node.parentElement?.parentElement;
if (table != null) {
const rows = Array.from(table.querySelectorAll('tr'));
const row = rows.indexOf(node) + 1;
return applyFormat(delta, 'table', row, scroll);
}
return delta;
}
function matchText(node, delta) {
function matchText(node, delta, scroll) {
// @ts-expect-error
let text = node.data;
// Word represents empty line with <o:p>&nbsp;</o:p>
if (node.parentNode.tagName === 'O:P') {
if (node.parentElement?.tagName === 'O:P') {
return delta.insert(text.trim());
}
if (text.trim().length === 0 && text.includes('\n')) {
return delta;
}
if (!isPre(node)) {
if (text.trim().length === 0 && text.includes('\n') && !isBetweenInlineElements(node, scroll)) {
return delta;
}
const replacer = (collapse, match) => {

@@ -525,12 +477,6 @@ const replaced = match.replace(/[^\u00a0]/g, ''); // \u00a0 is nbsp;

text = text.replace(/\s\s+/g, replacer.bind(replacer, true)); // collapse whitespace
if (
(node.previousSibling == null && isLine(node.parentNode)) ||
(node.previousSibling != null && isLine(node.previousSibling))
) {
if (node.previousSibling == null && node.parentElement != null && isLine(node.parentElement, scroll) || node.previousSibling instanceof Element && isLine(node.previousSibling, scroll)) {
text = text.replace(/^\s+/, replacer.bind(replacer, false));
}
if (
(node.nextSibling == null && isLine(node.parentNode)) ||
(node.nextSibling != null && isLine(node.nextSibling))
) {
if (node.nextSibling == null && node.parentElement != null && isLine(node.parentElement, scroll) || node.nextSibling instanceof Element && isLine(node.nextSibling, scroll)) {
text = text.replace(/\s+$/, replacer.bind(replacer, false));

@@ -541,10 +487,2 @@ }

}
export {
Clipboard as default,
matchAttributor,
matchBlot,
matchNewline,
matchText,
traverse,
};
//# sourceMappingURL=clipboard.js.map

@@ -1,60 +0,88 @@

import { Scope } from 'parchment';
import Quill from '../core/quill';
import Module from '../core/module';
"use strict";
class History extends Module {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
exports.getLastChangeIndex = getLastChangeIndex;
var _parchment = require("parchment");
var _module = _interopRequireDefault(require("../core/module"));
var _quill = _interopRequireDefault(require("../core/quill"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class History extends _module.default {
lastRecorded = 0;
ignoreChange = false;
stack = {
undo: [],
redo: []
};
currentRange = null;
constructor(quill, options) {
super(quill, options);
this.lastRecorded = 0;
this.ignoreChange = false;
this.clear();
this.quill.on(
Quill.events.EDITOR_CHANGE,
(eventName, delta, oldDelta, source) => {
if (eventName !== Quill.events.TEXT_CHANGE || this.ignoreChange) return;
if (!this.options.userOnly || source === Quill.sources.USER) {
this.record(delta, oldDelta);
} else {
this.transform(delta);
this.quill.on(_quill.default.events.EDITOR_CHANGE, (eventName, value, oldValue, source) => {
if (eventName === _quill.default.events.SELECTION_CHANGE) {
if (value && source !== _quill.default.sources.SILENT) {
this.currentRange = value;
}
},
);
this.quill.keyboard.addBinding(
{ key: 'z', shortKey: true },
this.undo.bind(this),
);
this.quill.keyboard.addBinding(
{ key: 'z', shortKey: true, shiftKey: true },
this.redo.bind(this),
);
} else if (eventName === _quill.default.events.TEXT_CHANGE) {
if (!this.ignoreChange) {
if (!this.options.userOnly || source === _quill.default.sources.USER) {
this.record(value, oldValue);
} else {
this.transform(value);
}
}
this.currentRange = transformRange(this.currentRange, value);
}
});
this.quill.keyboard.addBinding({
key: 'z',
shortKey: true
}, this.undo.bind(this));
this.quill.keyboard.addBinding({
key: ['z', 'Z'],
shortKey: true,
shiftKey: true
}, this.redo.bind(this));
if (/Win/i.test(navigator.platform)) {
this.quill.keyboard.addBinding(
{ key: 'y', shortKey: true },
this.redo.bind(this),
);
this.quill.keyboard.addBinding({
key: 'y',
shortKey: true
}, this.redo.bind(this));
}
this.quill.root.addEventListener('beforeinput', event => {
if (event.inputType === 'historyUndo') {
this.undo();
event.preventDefault();
} else if (event.inputType === 'historyRedo') {
this.redo();
event.preventDefault();
}
});
}
change(source, dest) {
if (this.stack[source].length === 0) return;
const delta = this.stack[source].pop();
const item = this.stack[source].pop();
if (!item) return;
const base = this.quill.getContents();
const inverseDelta = delta.invert(base);
this.stack[dest].push(inverseDelta);
const inverseDelta = item.delta.invert(base);
this.stack[dest].push({
delta: inverseDelta,
range: transformRange(item.range, inverseDelta)
});
this.lastRecorded = 0;
this.ignoreChange = true;
this.quill.updateContents(delta, Quill.sources.USER);
this.quill.updateContents(item.delta, _quill.default.sources.USER);
this.ignoreChange = false;
const index = getLastChangeIndex(this.quill.scroll, delta);
this.quill.setSelection(index);
this.restoreSelection(item);
}
clear() {
this.stack = { undo: [], redo: [] };
this.stack = {
undo: [],
redo: []
};
}
cutoff() {
this.lastRecorded = 0;
}
record(changeDelta, oldDelta) {

@@ -64,9 +92,12 @@ if (changeDelta.ops.length === 0) return;

let undoDelta = changeDelta.invert(oldDelta);
let undoRange = this.currentRange;
const timestamp = Date.now();
if (
this.lastRecorded + this.options.delay > timestamp &&
this.stack.undo.length > 0
) {
const delta = this.stack.undo.pop();
undoDelta = undoDelta.compose(delta);
// @ts-expect-error Fix me later
this.lastRecorded + this.options.delay > timestamp && this.stack.undo.length > 0) {
const item = this.stack.undo.pop();
if (item) {
undoDelta = undoDelta.compose(item.delta);
undoRange = item.range;
}
} else {

@@ -76,3 +107,7 @@ this.lastRecorded = timestamp;

if (undoDelta.length() === 0) return;
this.stack.undo.push(undoDelta);
this.stack.undo.push({
delta: undoDelta,
range: undoRange
});
// @ts-expect-error Fix me later
if (this.stack.undo.length > this.options.maxStack) {

@@ -82,7 +117,5 @@ this.stack.undo.shift();

}
redo() {
this.change('redo', 'undo');
}
transform(delta) {

@@ -92,20 +125,30 @@ transformStack(this.stack.undo, delta);

}
undo() {
this.change('undo', 'redo');
}
restoreSelection(stackItem) {
if (stackItem.range) {
this.quill.setSelection(stackItem.range, _quill.default.sources.USER);
} else {
const index = getLastChangeIndex(this.quill.scroll, stackItem.delta);
this.quill.setSelection(index, _quill.default.sources.USER);
}
}
}
exports.default = History;
History.DEFAULTS = {
delay: 1000,
maxStack: 100,
userOnly: false,
userOnly: false
};
function transformStack(stack, delta) {
let remoteDelta = delta;
for (let i = stack.length - 1; i >= 0; i -= 1) {
const oldDelta = stack[i];
stack[i] = remoteDelta.transform(oldDelta, true);
remoteDelta = oldDelta.transform(remoteDelta);
if (stack[i].length() === 0) {
const oldItem = stack[i];
stack[i] = {
delta: remoteDelta.transform(oldItem.delta, true),
range: oldItem.range && transformRange(oldItem.range, remoteDelta)
};
remoteDelta = oldItem.delta.transform(remoteDelta);
if (stack[i].delta.length() === 0) {
stack.splice(i, 1);

@@ -115,3 +158,2 @@ }

}
function endsWithNewlineChange(scroll, delta) {

@@ -125,3 +167,3 @@ const lastOp = delta.ops[delta.ops.length - 1];

return Object.keys(lastOp.attributes).some(attr => {
return scroll.query(attr, Scope.BLOCK) != null;
return scroll.query(attr, _parchment.Scope.BLOCK) != null;
});

@@ -131,3 +173,2 @@ }

}
function getLastChangeIndex(scroll, delta) {

@@ -143,3 +184,11 @@ const deleteLength = delta.reduce((length, op) => {

}
export { History as default, getLastChangeIndex };
function transformRange(range, delta) {
if (!range) return range;
const start = delta.transformPosition(range.index);
const end = delta.transformPosition(range.index + range.length);
return {
index: start,
length: end - start
};
}
//# sourceMappingURL=history.js.map

@@ -1,21 +0,25 @@

import clone from 'clone';
import equal from 'deep-equal';
import extend from 'extend';
import Delta, { AttributeMap } from 'quill-delta';
import { EmbedBlot, Scope, TextBlot } from 'parchment';
import Quill from '../core/quill';
import logger from '../core/logger';
import Module from '../core/module';
"use strict";
const debug = logger('quill:keyboard');
const SHORTKEY = /Mac/i.test(navigator.platform) ? 'metaKey' : 'ctrlKey';
class Keyboard extends Module {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.SHORTKEY = void 0;
exports.deleteRange = deleteRange;
exports.normalize = normalize;
var _lodashEs = require("lodash-es");
var _quillDelta = _interopRequireWildcard(require("quill-delta"));
var _parchment = require("parchment");
var _quill = _interopRequireDefault(require("../core/quill"));
var _logger = _interopRequireDefault(require("../core/logger"));
var _module = _interopRequireDefault(require("../core/module"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
const debug = (0, _logger.default)('quill:keyboard');
const SHORTKEY = exports.SHORTKEY = /Mac/i.test(navigator.platform) ? 'metaKey' : 'ctrlKey';
class Keyboard extends _module.default {
static match(evt, binding) {
if (
['altKey', 'ctrlKey', 'metaKey', 'shiftKey'].some(key => {
return !!binding[key] !== evt[key] && binding[key] !== null;
})
) {
if (['altKey', 'ctrlKey', 'metaKey', 'shiftKey'].some(key => {
return !!binding[key] !== evt[key] && binding[key] !== null;
})) {
return false;

@@ -25,65 +29,74 @@ }

}
constructor(quill, options) {
super(quill, options);
this.bindings = {};
// @ts-expect-error Fix me later
Object.keys(this.options.bindings).forEach(name => {
// @ts-expect-error Fix me later
if (this.options.bindings[name]) {
// @ts-expect-error Fix me later
this.addBinding(this.options.bindings[name]);
}
});
this.addBinding({ key: 'Enter', shiftKey: null }, this.handleEnter);
this.addBinding(
{ key: 'Enter', metaKey: null, ctrlKey: null, altKey: null },
() => {},
);
this.addBinding({
key: 'Enter',
shiftKey: null
}, this.handleEnter);
this.addBinding({
key: 'Enter',
metaKey: null,
ctrlKey: null,
altKey: null
}, () => {});
if (/Firefox/i.test(navigator.userAgent)) {
// Need to handle delete and backspace for Firefox in the general case #1171
this.addBinding(
{ key: 'Backspace' },
{ collapsed: true },
this.handleBackspace,
);
this.addBinding(
{ key: 'Delete' },
{ collapsed: true },
this.handleDelete,
);
this.addBinding({
key: 'Backspace'
}, {
collapsed: true
}, this.handleBackspace);
this.addBinding({
key: 'Delete'
}, {
collapsed: true
}, this.handleDelete);
} else {
this.addBinding(
{ key: 'Backspace' },
{ collapsed: true, prefix: /^.?$/ },
this.handleBackspace,
);
this.addBinding(
{ key: 'Delete' },
{ collapsed: true, suffix: /^.?$/ },
this.handleDelete,
);
this.addBinding({
key: 'Backspace'
}, {
collapsed: true,
prefix: /^.?$/
}, this.handleBackspace);
this.addBinding({
key: 'Delete'
}, {
collapsed: true,
suffix: /^.?$/
}, this.handleDelete);
}
this.addBinding(
{ key: 'Backspace' },
{ collapsed: false },
this.handleDeleteRange,
);
this.addBinding(
{ key: 'Delete' },
{ collapsed: false },
this.handleDeleteRange,
);
this.addBinding(
{
key: 'Backspace',
altKey: null,
ctrlKey: null,
metaKey: null,
shiftKey: null,
},
{ collapsed: true, offset: 0 },
this.handleBackspace,
);
this.addBinding({
key: 'Backspace'
}, {
collapsed: false
}, this.handleDeleteRange);
this.addBinding({
key: 'Delete'
}, {
collapsed: false
}, this.handleDeleteRange);
this.addBinding({
key: 'Backspace',
altKey: null,
ctrlKey: null,
metaKey: null,
shiftKey: null
}, {
collapsed: true,
offset: 0
}, this.handleBackspace);
this.listen();
}
addBinding(keyBinding, context = {}, handler = {}) {
addBinding(keyBinding) {
let context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
let handler = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
const binding = normalize(keyBinding);

@@ -95,10 +108,19 @@ if (binding == null) {

if (typeof context === 'function') {
context = { handler: context };
context = {
handler: context
};
}
if (typeof handler === 'function') {
handler = { handler };
handler = {
handler
};
}
const keys = Array.isArray(binding.key) ? binding.key : [binding.key];
keys.forEach(key => {
const singleBinding = extend({}, binding, { key }, context, handler);
const singleBinding = {
...binding,
key,
...context,
...handler
};
this.bindings[singleBinding.key] = this.bindings[singleBinding.key] || [];

@@ -108,11 +130,11 @@ this.bindings[singleBinding.key].push(singleBinding);

}
listen() {
this.quill.root.addEventListener('keydown', evt => {
if (evt.defaultPrevented || evt.isComposing) return;
const bindings = (this.bindings[evt.key] || []).concat(
this.bindings[evt.which] || [],
);
const bindings = (this.bindings[evt.key] || []).concat(this.bindings[evt.which] || []);
const matches = bindings.filter(binding => Keyboard.match(evt, binding));
if (matches.length === 0) return;
// @ts-expect-error
const blot = _quill.default.find(evt.target, true);
if (blot && blot.scroll !== this.quill.scroll) return;
const range = this.quill.getSelection();

@@ -122,14 +144,8 @@ if (range == null || !this.quill.hasFocus()) return;

const [leafStart, offsetStart] = this.quill.getLeaf(range.index);
const [leafEnd, offsetEnd] =
range.length === 0
? [leafStart, offsetStart]
: this.quill.getLeaf(range.index + range.length);
const prefixText =
leafStart instanceof TextBlot
? leafStart.value().slice(0, offsetStart)
: '';
const suffixText =
leafEnd instanceof TextBlot ? leafEnd.value().slice(offsetEnd) : '';
const [leafEnd, offsetEnd] = range.length === 0 ? [leafStart, offsetStart] : this.quill.getLeaf(range.index + range.length);
const prefixText = leafStart instanceof _parchment.TextBlot ? leafStart.value().slice(0, offsetStart) : '';
const suffixText = leafEnd instanceof _parchment.TextBlot ? leafEnd.value().slice(offsetEnd) : '';
const curContext = {
collapsed: range.length === 0,
// @ts-expect-error Fix me later
empty: range.length === 0 && line.length() <= 1,

@@ -141,9 +157,6 @@ format: this.quill.getFormat(range),

suffix: suffixText,
event: evt,
event: evt
};
const prevented = matches.some(binding => {
if (
binding.collapsed != null &&
binding.collapsed !== curContext.collapsed
) {
if (binding.collapsed != null && binding.collapsed !== curContext.collapsed) {
return false;

@@ -164,11 +177,10 @@ }

// all formats must match
if (
!Object.keys(binding.format).every(name => {
if (binding.format[name] === true)
return curContext.format[name] != null;
if (binding.format[name] === false)
return curContext.format[name] == null;
return equal(binding.format[name], curContext.format[name]);
})
) {
if (!Object.keys(binding.format).every(name => {
// @ts-expect-error Fix me later
if (binding.format[name] === true) return curContext.format[name] != null;
// @ts-expect-error Fix me later
if (binding.format[name] === false) return curContext.format[name] == null;
// @ts-expect-error Fix me later
return (0, _lodashEs.isEqual)(binding.format[name], curContext.format[name]);
})) {
return false;

@@ -183,2 +195,3 @@ }

}
// @ts-expect-error Fix me later
return binding.handler.call(this, range, curContext, binding) !== true;

@@ -191,12 +204,9 @@ });

}
handleBackspace(range, context) {
// Check for astral symbols
const length = /[\uD800-\uDBFF][\uDC00-\uDFFF]$/.test(context.prefix)
? 2
: 1;
const length = /[\uD800-\uDBFF][\uDC00-\uDFFF]$/.test(context.prefix) ? 2 : 1;
if (range.index === 0 || this.quill.getLength() <= 1) return;
let formats = {};
const [line] = this.quill.getLine(range.index);
let delta = new Delta().retain(range.index - length).delete(length);
let delta = new _quillDelta.default().retain(range.index - length).delete(length);
if (context.offset === 0) {

@@ -206,33 +216,36 @@ // Always deleting newline here, length always 1

if (prev) {
const curFormats = line.formats();
const prevFormats = this.quill.getFormat(range.index - 1, 1);
formats = AttributeMap.diff(curFormats, prevFormats) || {};
if (Object.keys(formats).length > 0) {
// line.length() - 1 targets \n in line, another -1 for newline being deleted
const formatDelta = new Delta()
.retain(range.index + line.length() - 2)
.retain(1, formats);
delta = delta.compose(formatDelta);
const isPrevLineEmpty = prev.statics.blotName === 'block' && prev.length() <= 1;
if (!isPrevLineEmpty) {
// @ts-expect-error Fix me later
const curFormats = line.formats();
const prevFormats = this.quill.getFormat(range.index - 1, 1);
formats = _quillDelta.AttributeMap.diff(curFormats, prevFormats) || {};
if (Object.keys(formats).length > 0) {
// line.length() - 1 targets \n in line, another -1 for newline being deleted
const formatDelta = new _quillDelta.default()
// @ts-expect-error Fix me later
.retain(range.index + line.length() - 2).retain(1, formats);
delta = delta.compose(formatDelta);
}
}
}
}
this.quill.updateContents(delta, Quill.sources.USER);
this.quill.updateContents(delta, _quill.default.sources.USER);
this.quill.focus();
}
handleDelete(range, context) {
// Check for astral symbols
const length = /^[\uD800-\uDBFF][\uDC00-\uDFFF]/.test(context.suffix)
? 2
: 1;
const length = /^[\uD800-\uDBFF][\uDC00-\uDFFF]/.test(context.suffix) ? 2 : 1;
if (range.index >= this.quill.getLength() - length) return;
let formats = {};
const [line] = this.quill.getLine(range.index);
let delta = new Delta().retain(range.index).delete(length);
let delta = new _quillDelta.default().retain(range.index).delete(length);
// @ts-expect-error Fix me later
if (context.offset >= line.length() - 1) {
const [next] = this.quill.getLine(range.index + 1);
if (next) {
// @ts-expect-error Fix me later
const curFormats = line.formats();
const nextFormats = this.quill.getFormat(range.index, 1);
formats = AttributeMap.diff(curFormats, nextFormats) || {};
formats = _quillDelta.AttributeMap.diff(curFormats, nextFormats) || {};
if (Object.keys(formats).length > 0) {

@@ -243,53 +256,27 @@ delta = delta.retain(next.length() - 1).retain(1, formats);

}
this.quill.updateContents(delta, Quill.sources.USER);
this.quill.updateContents(delta, _quill.default.sources.USER);
this.quill.focus();
}
handleDeleteRange(range) {
const lines = this.quill.getLines(range);
let formats = {};
if (lines.length > 1) {
const firstFormats = lines[0].formats();
const lastFormats = lines[lines.length - 1].formats();
formats = AttributeMap.diff(lastFormats, firstFormats) || {};
}
this.quill.deleteText(range, Quill.sources.USER);
if (Object.keys(formats).length > 0) {
this.quill.formatLine(range.index, 1, formats, Quill.sources.USER);
}
this.quill.setSelection(range.index, Quill.sources.SILENT);
deleteRange({
range,
quill: this.quill
});
this.quill.focus();
}
handleEnter(range, context) {
const lineFormats = Object.keys(context.format).reduce(
(formats, format) => {
if (
this.quill.scroll.query(format, Scope.BLOCK) &&
!Array.isArray(context.format[format])
) {
formats[format] = context.format[format];
}
return formats;
},
{},
);
const delta = new Delta()
.retain(range.index)
.delete(range.length)
.insert('\n', lineFormats);
this.quill.updateContents(delta, Quill.sources.USER);
this.quill.setSelection(range.index + 1, Quill.sources.SILENT);
const lineFormats = Object.keys(context.format).reduce((formats, format) => {
if (this.quill.scroll.query(format, _parchment.Scope.BLOCK) && !Array.isArray(context.format[format])) {
formats[format] = context.format[format];
}
return formats;
}, {});
const delta = new _quillDelta.default().retain(range.index).delete(range.length).insert('\n', lineFormats);
this.quill.updateContents(delta, _quill.default.sources.USER);
this.quill.setSelection(range.index + 1, _quill.default.sources.SILENT);
this.quill.focus();
Object.keys(context.format).forEach(name => {
if (lineFormats[name] != null) return;
if (Array.isArray(context.format[name])) return;
if (name === 'code' || name === 'link') return;
this.quill.format(name, context.format[name], Quill.sources.USER);
});
}
}
Keyboard.DEFAULTS = {
exports.default = Keyboard;
const defaultOptions = {
bindings: {

@@ -305,5 +292,5 @@ bold: makeFormatHandler('bold'),

if (context.collapsed && context.offset !== 0) return true;
this.quill.format('indent', '+1', Quill.sources.USER);
this.quill.format('indent', '+1', _quill.default.sources.USER);
return false;
},
}
},

@@ -317,5 +304,5 @@ outdent: {

if (context.collapsed && context.offset !== 0) return true;
this.quill.format('indent', '-1', Quill.sources.USER);
this.quill.format('indent', '-1', _quill.default.sources.USER);
return false;
},
}
},

@@ -333,7 +320,7 @@ 'outdent backspace': {

if (context.format.indent != null) {
this.quill.format('indent', '-1', Quill.sources.USER);
this.quill.format('indent', '-1', _quill.default.sources.USER);
} else if (context.format.list != null) {
this.quill.format('list', false, Quill.sources.USER);
this.quill.format('list', false, _quill.default.sources.USER);
}
},
}
},

@@ -348,4 +335,4 @@ 'indent code-block': makeCodeBlockHandler(true),

handler(range) {
this.quill.deleteText(range.index - 1, 1, Quill.sources.USER);
},
this.quill.deleteText(range.index - 1, 1, _quill.default.sources.USER);
}
},

@@ -357,11 +344,8 @@ tab: {

this.quill.history.cutoff();
const delta = new Delta()
.retain(range.index)
.delete(range.length)
.insert('\t');
this.quill.updateContents(delta, Quill.sources.USER);
const delta = new _quillDelta.default().retain(range.index).delete(range.length).insert('\t');
this.quill.updateContents(delta, _quill.default.sources.USER);
this.quill.history.cutoff();
this.quill.setSelection(range.index + 1, Quill.sources.SILENT);
this.quill.setSelection(range.index + 1, _quill.default.sources.SILENT);
return false;
},
}
},

@@ -374,4 +358,4 @@ 'blockquote empty enter': {

handler() {
this.quill.format('blockquote', false, Quill.sources.USER);
},
this.quill.format('blockquote', false, _quill.default.sources.USER);
}
},

@@ -384,13 +368,10 @@ 'list empty enter': {

handler(range, context) {
const formats = { list: false };
const formats = {
list: false
};
if (context.format.indent) {
formats.indent = false;
}
this.quill.formatLine(
range.index,
range.length,
formats,
Quill.sources.USER,
);
},
this.quill.formatLine(range.index, range.length, formats, _quill.default.sources.USER);
}
},

@@ -400,15 +381,21 @@ 'checklist enter': {

collapsed: true,
format: { list: 'checked' },
format: {
list: 'checked'
},
handler(range) {
const [line, offset] = this.quill.getLine(range.index);
const formats = extend({}, line.formats(), { list: 'checked' });
const delta = new Delta()
.retain(range.index)
.insert('\n', formats)
.retain(line.length() - offset - 1)
.retain(1, { list: 'unchecked' });
this.quill.updateContents(delta, Quill.sources.USER);
this.quill.setSelection(range.index + 1, Quill.sources.SILENT);
this.quill.scrollIntoView();
},
const formats = {
// @ts-expect-error Fix me later
...line.formats(),
list: 'checked'
};
const delta = new _quillDelta.default().retain(range.index).insert('\n', formats)
// @ts-expect-error Fix me later
.retain(line.length() - offset - 1).retain(1, {
list: 'unchecked'
});
this.quill.updateContents(delta, _quill.default.sources.USER);
this.quill.setSelection(range.index + 1, _quill.default.sources.SILENT);
this.quill.scrollSelectionIntoView();
}
},

@@ -422,11 +409,11 @@ 'header enter': {

const [line, offset] = this.quill.getLine(range.index);
const delta = new Delta()
.retain(range.index)
.insert('\n', context.format)
.retain(line.length() - offset - 1)
.retain(1, { header: null });
this.quill.updateContents(delta, Quill.sources.USER);
this.quill.setSelection(range.index + 1, Quill.sources.SILENT);
this.quill.scrollIntoView();
},
const delta = new _quillDelta.default().retain(range.index).insert('\n', context.format)
// @ts-expect-error Fix me later
.retain(line.length() - offset - 1).retain(1, {
header: null
});
this.quill.updateContents(delta, _quill.default.sources.USER);
this.quill.setSelection(range.index + 1, _quill.default.sources.SILENT);
this.quill.scrollSelectionIntoView();
}
},

@@ -438,3 +425,3 @@ 'table backspace': {

offset: 0,
handler() {},
handler() {}
},

@@ -446,3 +433,3 @@ 'table delete': {

suffix: /^$/,
handler() {},
handler() {}
},

@@ -456,2 +443,3 @@ 'table enter': {

if (module) {
// @ts-expect-error
const [table, row, cell, offset] = module.getTable(range);

@@ -462,17 +450,13 @@ const shift = tableSide(table, row, cell, offset);

if (shift < 0) {
const delta = new Delta().retain(index).insert('\n');
this.quill.updateContents(delta, Quill.sources.USER);
this.quill.setSelection(
range.index + 1,
range.length,
Quill.sources.SILENT,
);
const delta = new _quillDelta.default().retain(index).insert('\n');
this.quill.updateContents(delta, _quill.default.sources.USER);
this.quill.setSelection(range.index + 1, range.length, _quill.default.sources.SILENT);
} else if (shift > 0) {
index += table.length();
const delta = new Delta().retain(index).insert('\n');
this.quill.updateContents(delta, Quill.sources.USER);
this.quill.setSelection(index, Quill.sources.USER);
const delta = new _quillDelta.default().retain(index).insert('\n');
this.quill.updateContents(delta, _quill.default.sources.USER);
this.quill.setSelection(index, _quill.default.sources.USER);
}
}
},
}
},

@@ -484,10 +468,13 @@ 'table tab': {

handler(range, context) {
const { event, line: cell } = context;
const {
event,
line: cell
} = context;
const offset = cell.offset(this.quill.scroll);
if (event.shiftKey) {
this.quill.setSelection(offset - 1, Quill.sources.USER);
this.quill.setSelection(offset - 1, _quill.default.sources.USER);
} else {
this.quill.setSelection(offset + cell.length(), Quill.sources.USER);
this.quill.setSelection(offset + cell.length(), _quill.default.sources.USER);
}
},
}
},

@@ -499,7 +486,5 @@ 'list autofill': {

format: {
list: false,
'code-block': false,
blockquote: false,
header: false,
table: false,
table: false
},

@@ -509,3 +494,5 @@ prefix: /^\s*?(\d+\.|-|\*|\[ ?\]|\[x\])$/,

if (this.quill.scroll.query('list') == null) return true;
const { length } = context.prefix;
const {
length
} = context.prefix;
const [line, offset] = this.quill.getLine(range.index);

@@ -529,14 +516,14 @@ if (offset > length) return true;

}
this.quill.insertText(range.index, ' ', Quill.sources.USER);
this.quill.insertText(range.index, ' ', _quill.default.sources.USER);
this.quill.history.cutoff();
const delta = new Delta()
.retain(range.index - offset)
.delete(length + 1)
.retain(line.length() - 2 - offset)
.retain(1, { list: value });
this.quill.updateContents(delta, Quill.sources.USER);
const delta = new _quillDelta.default().retain(range.index - offset).delete(length + 1)
// @ts-expect-error Fix me later
.retain(line.length() - 2 - offset).retain(1, {
list: value
});
this.quill.updateContents(delta, _quill.default.sources.USER);
this.quill.history.cutoff();
this.quill.setSelection(range.index - length, Quill.sources.SILENT);
this.quill.setSelection(range.index - length, _quill.default.sources.SILENT);
return false;
},
}
},

@@ -553,7 +540,4 @@ 'code exit': {

let cur = line;
while (
cur != null &&
cur.length() <= 1 &&
cur.formats()['code-block']
) {
while (cur != null && cur.length() <= 1 && cur.formats()['code-block']) {
// @ts-expect-error
cur = cur.prev;

@@ -563,8 +547,9 @@ numLines -= 1;

if (numLines <= 0) {
const delta = new Delta()
.retain(range.index + line.length() - offset - 2)
.retain(1, { 'code-block': null })
.delete(1);
this.quill.updateContents(delta, Quill.sources.USER);
this.quill.setSelection(range.index - 1, Quill.sources.SILENT);
const delta = new _quillDelta.default()
// @ts-expect-error Fix me later
.retain(range.index + line.length() - offset - 2).retain(1, {
'code-block': null
}).delete(1);
this.quill.updateContents(delta, _quill.default.sources.USER);
this.quill.setSelection(range.index - 1, _quill.default.sources.SILENT);
return false;

@@ -574,3 +559,3 @@ }

return true;
},
}
},

@@ -582,6 +567,6 @@ 'embed left': makeEmbedArrowHandler('ArrowLeft', false),

'table down': makeTableArrowHandler(false),
'table up': makeTableArrowHandler(true),
},
'table up': makeTableArrowHandler(true)
}
};
Keyboard.DEFAULTS = defaultOptions;
function makeCodeBlockHandler(indent) {

@@ -591,33 +576,47 @@ return {

shiftKey: !indent,
format: { 'code-block': true },
handler(range) {
format: {
'code-block': true
},
handler(range, _ref) {
let {
event
} = _ref;
const CodeBlock = this.quill.scroll.query('code-block');
const lines =
range.length === 0
? this.quill.getLines(range.index, 1)
: this.quill.getLines(range);
let { index, length } = range;
// @ts-expect-error
const {
TAB
} = CodeBlock;
if (range.length === 0 && !event.shiftKey) {
this.quill.insertText(range.index, TAB, _quill.default.sources.USER);
this.quill.setSelection(range.index + TAB.length, _quill.default.sources.SILENT);
return;
}
const lines = range.length === 0 ? this.quill.getLines(range.index, 1) : this.quill.getLines(range);
let {
index,
length
} = range;
lines.forEach((line, i) => {
if (indent) {
line.insertAt(0, CodeBlock.TAB);
line.insertAt(0, TAB);
if (i === 0) {
index += CodeBlock.TAB.length;
index += TAB.length;
} else {
length += CodeBlock.TAB.length;
length += TAB.length;
}
} else if (line.domNode.textContent.startsWith(CodeBlock.TAB)) {
line.deleteAt(0, CodeBlock.TAB.length);
// @ts-expect-error Fix me later
} else if (line.domNode.textContent.startsWith(TAB)) {
line.deleteAt(0, TAB.length);
if (i === 0) {
index -= CodeBlock.TAB.length;
index -= TAB.length;
} else {
length -= CodeBlock.TAB.length;
length -= TAB.length;
}
}
});
this.quill.update(Quill.sources.USER);
this.quill.setSelection(index, length, Quill.sources.SILENT);
},
this.quill.update(_quill.default.sources.USER);
this.quill.setSelection(index, length, _quill.default.sources.SILENT);
}
};
}
function makeEmbedArrowHandler(key, shiftKey) {

@@ -631,3 +630,5 @@ const where = key === 'ArrowLeft' ? 'prefix' : 'suffix';

handler(range) {
let { index } = range;
let {
index
} = range;
if (key === 'ArrowRight') {

@@ -637,30 +638,18 @@ index += range.length + 1;

const [leaf] = this.quill.getLeaf(index);
if (!(leaf instanceof EmbedBlot)) return true;
if (!(leaf instanceof _parchment.EmbedBlot)) return true;
if (key === 'ArrowLeft') {
if (shiftKey) {
this.quill.setSelection(
range.index - 1,
range.length + 1,
Quill.sources.USER,
);
this.quill.setSelection(range.index - 1, range.length + 1, _quill.default.sources.USER);
} else {
this.quill.setSelection(range.index - 1, Quill.sources.USER);
this.quill.setSelection(range.index - 1, _quill.default.sources.USER);
}
} else if (shiftKey) {
this.quill.setSelection(
range.index,
range.length + 1,
Quill.sources.USER,
);
this.quill.setSelection(range.index, range.length + 1, _quill.default.sources.USER);
} else {
this.quill.setSelection(
range.index + range.length + 1,
Quill.sources.USER,
);
this.quill.setSelection(range.index + range.length + 1, _quill.default.sources.USER);
}
return false;
},
}
};
}
function makeFormatHandler(format) {

@@ -671,7 +660,6 @@ return {

handler(range, context) {
this.quill.format(format, !context.format[format], Quill.sources.USER);
},
this.quill.format(format, !context.format[format], _quill.default.sources.USER);
}
};
}
function makeTableArrowHandler(up) {

@@ -689,28 +677,21 @@ return {

if (targetRow.statics.blotName === 'table-row') {
// @ts-expect-error
let targetCell = targetRow.children.head;
let cur = cell;
while (cur.prev != null) {
// @ts-expect-error
cur = cur.prev;
targetCell = targetCell.next;
}
const index =
targetCell.offset(this.quill.scroll) +
Math.min(context.offset, targetCell.length() - 1);
this.quill.setSelection(index, 0, Quill.sources.USER);
const index = targetCell.offset(this.quill.scroll) + Math.min(context.offset, targetCell.length() - 1);
this.quill.setSelection(index, 0, _quill.default.sources.USER);
}
} else {
// @ts-expect-error
const targetLine = cell.table()[key];
if (targetLine != null) {
if (up) {
this.quill.setSelection(
targetLine.offset(this.quill.scroll) + targetLine.length() - 1,
0,
Quill.sources.USER,
);
this.quill.setSelection(targetLine.offset(this.quill.scroll) + targetLine.length() - 1, 0, _quill.default.sources.USER);
} else {
this.quill.setSelection(
targetLine.offset(this.quill.scroll),
0,
Quill.sources.USER,
);
this.quill.setSelection(targetLine.offset(this.quill.scroll), 0, _quill.default.sources.USER);
}

@@ -720,11 +701,12 @@ }

return false;
},
}
};
}
function normalize(binding) {
if (typeof binding === 'string' || typeof binding === 'number') {
binding = { key: binding };
binding = {
key: binding
};
} else if (typeof binding === 'object') {
binding = clone(binding, false);
binding = (0, _lodashEs.cloneDeep)(binding);
} else {

@@ -740,3 +722,22 @@ return null;

function tableSide(table, row, cell, offset) {
// TODO: Move into quill.ts or editor.ts
function deleteRange(_ref2) {
let {
quill,
range
} = _ref2;
const lines = quill.getLines(range);
let formats = {};
if (lines.length > 1) {
const firstFormats = lines[0].formats();
const lastFormats = lines[lines.length - 1].formats();
formats = _quillDelta.AttributeMap.diff(lastFormats, firstFormats) || {};
}
quill.deleteText(range, _quill.default.sources.USER);
if (Object.keys(formats).length > 0) {
quill.formatLine(range.index, 1, formats, _quill.default.sources.USER);
}
quill.setSelection(range.index, _quill.default.sources.SILENT);
}
function tableSide(_table, row, cell, offset) {
if (row.prev == null && row.next == null) {

@@ -756,3 +757,2 @@ if (cell.prev == null && cell.next == null) {

}
export { Keyboard as default, SHORTKEY, normalize };
//# sourceMappingURL=keyboard.js.map

@@ -1,22 +0,32 @@

import Delta from 'quill-delta';
import { ClassAttributor, Scope } from 'parchment';
import Inline from '../blots/inline';
import Quill from '../core/quill';
import Module from '../core/module';
import { blockDelta } from '../blots/block';
import BreakBlot from '../blots/break';
import CursorBlot from '../blots/cursor';
import TextBlot, { escapeText } from '../blots/text';
import CodeBlock, { CodeBlockContainer } from '../formats/code';
import { traverse } from './clipboard';
"use strict";
const TokenAttributor = new ClassAttributor('code-token', 'hljs', {
scope: Scope.INLINE,
Object.defineProperty(exports, "__esModule", {
value: true
});
class CodeToken extends Inline {
exports.default = exports.CodeToken = exports.CodeBlock = void 0;
var _quillDelta = _interopRequireDefault(require("quill-delta"));
var _parchment = require("parchment");
var _inline = _interopRequireDefault(require("../blots/inline"));
var _quill = _interopRequireDefault(require("../core/quill"));
var _module = _interopRequireDefault(require("../core/module"));
var _block = require("../blots/block");
var _break = _interopRequireDefault(require("../blots/break"));
var _cursor = _interopRequireDefault(require("../blots/cursor"));
var _text = _interopRequireWildcard(require("../blots/text"));
var _code = _interopRequireWildcard(require("../formats/code"));
var _clipboard = require("./clipboard");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const TokenAttributor = new _parchment.ClassAttributor('code-token', 'hljs', {
scope: _parchment.Scope.INLINE
});
class CodeToken extends _inline.default {
static formats(node, scroll) {
while (node != null && node !== scroll.domNode) {
if (node.classList && node.classList.contains(CodeBlock.className)) {
if (node.classList && node.classList.contains(_code.default.className)) {
// @ts-expect-error
return super.formats(node, scroll);
}
// @ts-expect-error
node = node.parentNode;

@@ -26,8 +36,7 @@ }

}
constructor(scroll, domNode, value) {
// @ts-expect-error
super(scroll, domNode, value);
TokenAttributor.add(this.domNode, value);
}
format(format, value) {

@@ -43,5 +52,5 @@ if (format !== CodeToken.blotName) {

}
optimize(...args) {
super.optimize(...args);
optimize() {
// @ts-expect-error
super.optimize(...arguments);
if (!TokenAttributor.value(this.domNode)) {

@@ -52,6 +61,6 @@ this.unwrap();

}
exports.CodeToken = CodeToken;
CodeToken.blotName = 'code-token';
CodeToken.className = 'ql-token';
class SyntaxCodeBlock extends CodeBlock {
class SyntaxCodeBlock extends _code.default {
static create(value) {

@@ -64,7 +73,6 @@ const domNode = super.create(value);

}
static formats(domNode) {
// @ts-expect-error
return domNode.getAttribute('data-language') || 'plain';
}
static register() {} // Syntax module will register

@@ -74,2 +82,3 @@

if (name === this.statics.blotName && value) {
// @ts-expect-error
this.domNode.setAttribute('data-language', value);

@@ -80,3 +89,2 @@ } else {

}
replaceWith(name, value) {

@@ -87,10 +95,10 @@ this.formatAt(0, this.length(), CodeToken.blotName, false);

}
class SyntaxCodeBlockContainer extends CodeBlockContainer {
exports.CodeBlock = SyntaxCodeBlock;
class SyntaxCodeBlockContainer extends _code.CodeBlockContainer {
attach() {
super.attach();
this.forceNext = false;
// @ts-expect-error
this.scroll.emitMount(this);
}
format(name, value) {

@@ -100,2 +108,3 @@ if (name === SyntaxCodeBlock.blotName) {

this.children.forEach(child => {
// @ts-expect-error
child.format(name, value);

@@ -105,3 +114,2 @@ });

}
formatAt(index, length, name, value) {

@@ -113,8 +121,6 @@ if (name === SyntaxCodeBlock.blotName) {

}
highlight(highlight, forced = false) {
highlight(highlight) {
let forced = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (this.children.head == null) return;
const nodes = Array.from(this.domNode.childNodes).filter(
node => node !== this.uiNode,
);
const nodes = Array.from(this.domNode.childNodes).filter(node => node !== this.uiNode);
const text = `${nodes.map(node => node.textContent).join('\n')}\n`;

@@ -125,6 +131,11 @@ const language = SyntaxCodeBlock.formats(this.children.head.domNode);

const oldDelta = this.children.reduce((delta, child) => {
return delta.concat(blockDelta(child, false));
}, new Delta());
// @ts-expect-error
return delta.concat((0, _block.blockDelta)(child, false));
}, new _quillDelta.default());
const delta = highlight(text, language);
oldDelta.diff(delta).reduce((index, { retain, attributes }) => {
oldDelta.diff(delta).reduce((index, _ref) => {
let {
retain,
attributes
} = _ref;
// Should be all retains

@@ -134,5 +145,4 @@ if (!retain) return index;

Object.keys(attributes).forEach(format => {
if (
[SyntaxCodeBlock.blotName, CodeToken.blotName].includes(format)
) {
if ([SyntaxCodeBlock.blotName, CodeToken.blotName].includes(format)) {
// @ts-expect-error
this.formatAt(index, retain, format, attributes[format]);

@@ -142,2 +152,3 @@ }

}
// @ts-expect-error
return index + retain;

@@ -150,12 +161,14 @@ }, 0);

}
html(index, length) {
const [codeBlock] = this.children.find(index);
const language = codeBlock ? SyntaxCodeBlock.formats(codeBlock.domNode) : 'plain';
return `<pre data-language="${language}">\n${(0, _text.escapeText)(this.code(index, length))}\n</pre>`;
}
optimize(context) {
super.optimize(context);
if (
this.parent != null &&
this.children.head != null &&
this.uiNode != null
) {
if (this.parent != null && this.children.head != null && this.uiNode != null) {
const language = SyntaxCodeBlock.formats(this.children.head.domNode);
// @ts-expect-error
if (language !== this.uiNode.value) {
// @ts-expect-error
this.uiNode.value = language;

@@ -166,21 +179,34 @@ }

}
// @ts-expect-error
SyntaxCodeBlockContainer.allowedChildren = [SyntaxCodeBlock];
SyntaxCodeBlock.requiredContainer = SyntaxCodeBlockContainer;
SyntaxCodeBlock.allowedChildren = [CodeToken, CursorBlot, TextBlot, BreakBlot];
class Syntax extends Module {
SyntaxCodeBlock.allowedChildren = [CodeToken, _cursor.default, _text.default, _break.default];
const highlight = (lib, language, text) => {
if (typeof lib.versionString === 'string') {
const majorVersion = lib.versionString.split('.')[0];
if (parseInt(majorVersion, 10) >= 11) {
return lib.highlight(text, {
language
}).value;
}
}
return lib.highlight(language, text).value;
};
class Syntax extends _module.default {
static register() {
Quill.register(CodeToken, true);
Quill.register(SyntaxCodeBlock, true);
Quill.register(SyntaxCodeBlockContainer, true);
_quill.default.register(CodeToken, true);
// @ts-expect-error
_quill.default.register(SyntaxCodeBlock, true);
_quill.default.register(SyntaxCodeBlockContainer, true);
}
constructor(quill, options) {
super(quill, options);
if (this.options.hljs == null) {
throw new Error(
'Syntax module requires highlight.js. Please include the library on the page before Quill.',
);
throw new Error('Syntax module requires highlight.js. Please include the library on the page before Quill.');
}
this.languages = this.options.languages.reduce((memo, { key }) => {
// @ts-expect-error Fix me later
this.languages = this.options.languages.reduce((memo, _ref2) => {
let {
key
} = _ref2;
memo[key] = true;

@@ -193,8 +219,12 @@ return memo;

}
initListener() {
this.quill.on(Quill.events.SCROLL_BLOT_MOUNT, blot => {
this.quill.on(_quill.default.events.SCROLL_BLOT_MOUNT, blot => {
if (!(blot instanceof SyntaxCodeBlockContainer)) return;
const select = this.quill.root.ownerDocument.createElement('select');
this.options.languages.forEach(({ key, label }) => {
// @ts-expect-error Fix me later
this.options.languages.forEach(_ref3 => {
let {
key,
label
} = _ref3;
const option = select.ownerDocument.createElement('option');

@@ -218,7 +248,8 @@ option.textContent = label;

}
initTimer() {
let timer = null;
this.quill.on(Quill.events.SCROLL_OPTIMIZE, () => {
clearTimeout(timer);
this.quill.on(_quill.default.events.SCROLL_OPTIMIZE, () => {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {

@@ -230,63 +261,54 @@ this.highlight();

}
highlight(blot = null, force = false) {
highlight() {
let blot = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
let force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (this.quill.selection.composing) return;
this.quill.update(Quill.sources.USER);
this.quill.update(_quill.default.sources.USER);
const range = this.quill.getSelection();
const blots =
blot == null
? this.quill.scroll.descendants(SyntaxCodeBlockContainer)
: [blot];
const blots = blot == null ? this.quill.scroll.descendants(SyntaxCodeBlockContainer) : [blot];
blots.forEach(container => {
container.highlight(this.highlightBlot, force);
});
this.quill.update(Quill.sources.SILENT);
this.quill.update(_quill.default.sources.SILENT);
if (range != null) {
this.quill.setSelection(range, Quill.sources.SILENT);
this.quill.setSelection(range, _quill.default.sources.SILENT);
}
}
highlightBlot(text, language = 'plain') {
highlightBlot(text) {
let language = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'plain';
language = this.languages[language] ? language : 'plain';
if (language === 'plain') {
return escapeText(text)
.split('\n')
.reduce((delta, line, i) => {
if (i !== 0) {
delta.insert('\n', { [CodeBlock.blotName]: language });
}
return delta.insert(line);
}, new Delta());
return (0, _text.escapeText)(text).split('\n').reduce((delta, line, i) => {
if (i !== 0) {
delta.insert('\n', {
[_code.default.blotName]: language
});
}
return delta.insert(line);
}, new _quillDelta.default());
}
const container = this.quill.root.ownerDocument.createElement('div');
container.classList.add(CodeBlock.className);
container.innerHTML = this.options.hljs.highlight(language, text).value;
return traverse(
this.quill.scroll,
container,
[
(node, delta) => {
const value = TokenAttributor.value(node);
if (value) {
return delta.compose(
new Delta().retain(delta.length(), {
[CodeToken.blotName]: value,
}),
);
}
return delta;
},
],
[
(node, delta) => {
return node.data.split('\n').reduce((memo, nodeText, i) => {
if (i !== 0) memo.insert('\n', { [CodeBlock.blotName]: language });
return memo.insert(nodeText);
}, delta);
},
],
new WeakMap(),
);
container.classList.add(_code.default.className);
container.innerHTML = highlight(this.options.hljs, language, text);
return (0, _clipboard.traverse)(this.quill.scroll, container, [(node, delta) => {
// @ts-expect-error
const value = TokenAttributor.value(node);
if (value) {
return delta.compose(new _quillDelta.default().retain(delta.length(), {
[CodeToken.blotName]: value
}));
}
return delta;
}], [(node, delta) => {
// @ts-expect-error
return node.data.split('\n').reduce((memo, nodeText, i) => {
if (i !== 0) memo.insert('\n', {
[_code.default.blotName]: language
});
return memo.insert(nodeText);
}, delta);
}], new WeakMap());
}
}
exports.default = Syntax;
Syntax.DEFAULTS = {

@@ -297,20 +319,46 @@ hljs: (() => {

interval: 1000,
languages: [
{ key: 'plain', label: 'Plain' },
{ key: 'bash', label: 'Bash' },
{ key: 'cpp', label: 'C++' },
{ key: 'cs', label: 'C#' },
{ key: 'css', label: 'CSS' },
{ key: 'diff', label: 'Diff' },
{ key: 'xml', label: 'HTML/XML' },
{ key: 'java', label: 'Java' },
{ key: 'javascript', label: 'Javascript' },
{ key: 'markdown', label: 'Markdown' },
{ key: 'php', label: 'PHP' },
{ key: 'python', label: 'Python' },
{ key: 'ruby', label: 'Ruby' },
{ key: 'sql', label: 'SQL' },
],
languages: [{
key: 'plain',
label: 'Plain'
}, {
key: 'bash',
label: 'Bash'
}, {
key: 'cpp',
label: 'C++'
}, {
key: 'cs',
label: 'C#'
}, {
key: 'css',
label: 'CSS'
}, {
key: 'diff',
label: 'Diff'
}, {
key: 'xml',
label: 'HTML/XML'
}, {
key: 'java',
label: 'Java'
}, {
key: 'javascript',
label: 'JavaScript'
}, {
key: 'markdown',
label: 'Markdown'
}, {
key: 'php',
label: 'PHP'
}, {
key: 'python',
label: 'Python'
}, {
key: 'ruby',
label: 'Ruby'
}, {
key: 'sql',
label: 'SQL'
}]
};
export { SyntaxCodeBlock as CodeBlock, CodeToken, Syntax as default };
//# sourceMappingURL=syntax.js.map

@@ -1,38 +0,35 @@

import Delta from 'quill-delta';
import Quill from '../core/quill';
import Module from '../core/module';
import {
TableCell,
TableRow,
TableBody,
TableContainer,
tableId,
} from '../formats/table';
"use strict";
class Table extends Module {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _quillDelta = _interopRequireDefault(require("quill-delta"));
var _quill = _interopRequireDefault(require("../core/quill"));
var _module = _interopRequireDefault(require("../core/module"));
var _table = require("../formats/table");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class Table extends _module.default {
static register() {
Quill.register(TableCell);
Quill.register(TableRow);
Quill.register(TableBody);
Quill.register(TableContainer);
_quill.default.register(_table.TableCell);
_quill.default.register(_table.TableRow);
_quill.default.register(_table.TableBody);
_quill.default.register(_table.TableContainer);
}
constructor(...args) {
super(...args);
constructor() {
super(...arguments);
this.listenBalanceCells();
}
balanceTables() {
this.quill.scroll.descendants(TableContainer).forEach(table => {
this.quill.scroll.descendants(_table.TableContainer).forEach(table => {
table.balanceCells();
});
}
deleteColumn() {
const [table, , cell] = this.getTable();
const [table,, cell] = this.getTable();
if (cell == null) return;
// @ts-expect-error
table.deleteColumn(cell.cellOffset());
this.quill.update(Quill.sources.USER);
this.quill.update(_quill.default.sources.USER);
}
deleteRow() {

@@ -42,18 +39,19 @@ const [, row] = this.getTable();

row.remove();
this.quill.update(Quill.sources.USER);
this.quill.update(_quill.default.sources.USER);
}
deleteTable() {
const [table] = this.getTable();
if (table == null) return;
// @ts-expect-error
const offset = table.offset();
// @ts-expect-error
table.remove();
this.quill.update(Quill.sources.USER);
this.quill.setSelection(offset, Quill.sources.SILENT);
this.quill.update(_quill.default.sources.USER);
this.quill.setSelection(offset, _quill.default.sources.SILENT);
}
getTable(range = this.quill.getSelection()) {
getTable() {
let range = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.quill.getSelection();
if (range == null) return [null, null, null, -1];
const [cell, offset] = this.quill.getLine(range.index);
if (cell == null || cell.statics.blotName !== TableCell.blotName) {
if (cell == null || cell.statics.blotName !== _table.TableCell.blotName) {
return [null, null, null, -1];

@@ -63,7 +61,8 @@ }

const table = row.parent.parent;
// @ts-expect-error
return [table, row, cell, offset];
}
insertColumn(offset) {
const range = this.quill.getSelection();
if (!range) return;
const [table, row, cell] = this.getTable(range);

@@ -73,3 +72,3 @@ if (cell == null) return;

table.insertColumn(column + offset);
this.quill.update(Quill.sources.USER);
this.quill.update(_quill.default.sources.USER);
let shift = row.rowOffset();

@@ -79,19 +78,13 @@ if (offset === 0) {

}
this.quill.setSelection(
range.index + shift,
range.length,
Quill.sources.SILENT,
);
this.quill.setSelection(range.index + shift, range.length, _quill.default.sources.SILENT);
}
insertColumnLeft() {
this.insertColumn(0);
}
insertColumnRight() {
this.insertColumn(1);
}
insertRow(offset) {
const range = this.quill.getSelection();
if (!range) return;
const [table, row, cell] = this.getTable(range);

@@ -101,22 +94,15 @@ if (cell == null) return;

table.insertRow(index + offset);
this.quill.update(Quill.sources.USER);
this.quill.update(_quill.default.sources.USER);
if (offset > 0) {
this.quill.setSelection(range, Quill.sources.SILENT);
this.quill.setSelection(range, _quill.default.sources.SILENT);
} else {
this.quill.setSelection(
range.index + row.children.length,
range.length,
Quill.sources.SILENT,
);
this.quill.setSelection(range.index + row.children.length, range.length, _quill.default.sources.SILENT);
}
}
insertRowAbove() {
this.insertRow(0);
}
insertRowBelow() {
this.insertRow(1);
}
insertTable(rows, columns) {

@@ -127,15 +113,16 @@ const range = this.quill.getSelection();

const text = new Array(columns).fill('\n').join('');
return memo.insert(text, { table: tableId() });
}, new Delta().retain(range.index));
this.quill.updateContents(delta, Quill.sources.USER);
this.quill.setSelection(range.index, Quill.sources.SILENT);
return memo.insert(text, {
table: (0, _table.tableId)()
});
}, new _quillDelta.default().retain(range.index));
this.quill.updateContents(delta, _quill.default.sources.USER);
this.quill.setSelection(range.index, _quill.default.sources.SILENT);
this.balanceTables();
}
listenBalanceCells() {
this.quill.on(Quill.events.SCROLL_OPTIMIZE, mutations => {
this.quill.on(_quill.default.events.SCROLL_OPTIMIZE, mutations => {
mutations.some(mutation => {
if (['TD', 'TR', 'TBODY', 'TABLE'].includes(mutation.target.tagName)) {
this.quill.once(Quill.events.TEXT_CHANGE, (delta, old, source) => {
if (source !== Quill.sources.USER) return;
this.quill.once(_quill.default.events.TEXT_CHANGE, (delta, old, source) => {
if (source !== _quill.default.sources.USER) return;
this.balanceTables();

@@ -150,3 +137,3 @@ });

}
export default Table;
var _default = exports.default = Table;
//# sourceMappingURL=table.js.map

@@ -1,10 +0,16 @@

import Delta from 'quill-delta';
import { EmbedBlot, Scope } from 'parchment';
import Quill from '../core/quill';
import logger from '../core/logger';
import Module from '../core/module';
"use strict";
const debug = logger('quill:toolbar');
class Toolbar extends Module {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.addControls = addControls;
exports.default = void 0;
var _quillDelta = _interopRequireDefault(require("quill-delta"));
var _parchment = require("parchment");
var _quill = _interopRequireDefault(require("../core/quill"));
var _logger = _interopRequireDefault(require("../core/logger"));
var _module = _interopRequireDefault(require("../core/module"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const debug = (0, _logger.default)('quill:toolbar');
class Toolbar extends _module.default {
constructor(quill, options) {

@@ -14,4 +20,5 @@ super(quill, options);

const container = document.createElement('div');
container.setAttribute('role', 'toolbar');
addControls(container, this.options.container);
quill.container.parentNode.insertBefore(container, quill.container);
quill.container?.parentNode?.insertBefore(container, quill.container);
this.container = container;

@@ -24,3 +31,4 @@ } else if (typeof this.options.container === 'string') {

if (!(this.container instanceof HTMLElement)) {
return debug.error('Container required for toolbar', this.options);
debug.error('Container required for toolbar', this.options);
return;
}

@@ -30,16 +38,20 @@ this.container.classList.add('ql-toolbar');

this.handlers = {};
Object.keys(this.options.handlers).forEach(format => {
this.addHandler(format, this.options.handlers[format]);
if (this.options.handlers) {
Object.keys(this.options.handlers).forEach(format => {
const handler = this.options.handlers?.[format];
if (handler) {
this.addHandler(format, handler);
}
});
}
Array.from(this.container.querySelectorAll('button, select')).forEach(input => {
// @ts-expect-error
this.attach(input);
});
Array.from(this.container.querySelectorAll('button, select')).forEach(
input => {
this.attach(input);
},
);
this.quill.on(Quill.events.EDITOR_CHANGE, (type, range) => {
if (type === Quill.events.SELECTION_CHANGE) {
this.quill.on(_quill.default.events.EDITOR_CHANGE, (type, range) => {
if (type === _quill.default.events.SELECTION_CHANGE) {
this.update(range);
}
});
this.quill.on(Quill.events.SCROLL_OPTIMIZE, () => {
this.quill.on(_quill.default.events.SCROLL_OPTIMIZE, () => {
const [range] = this.quill.selection.getRange(); // quill.getSelection triggers update

@@ -49,7 +61,5 @@ this.update(range);

}
addHandler(format, handler) {
this.handlers[format] = handler;
}
attach(input) {

@@ -64,6 +74,3 @@ let format = Array.from(input.classList).find(className => {

}
if (
this.handlers[format] == null &&
this.quill.scroll.query(format) == null
) {
if (this.handlers[format] == null && this.quill.scroll.query(format) == null) {
debug.warn('ignoring attaching to nonexistent format', format, input);

@@ -76,3 +83,5 @@ return;

if (input.tagName === 'SELECT') {
// @ts-expect-error
if (input.selectedIndex < 0) return;
// @ts-expect-error
const selected = input.options[input.selectedIndex];

@@ -88,2 +97,3 @@ if (selected.hasAttribute('selected')) {

} else {
// @ts-expect-error
value = input.value || !input.hasAttribute('value');

@@ -95,18 +105,23 @@ }

const [range] = this.quill.selection.getRange();
// @ts-expect-error Fix me later
if (this.handlers[format] != null) {
// @ts-expect-error Fix me later
this.handlers[format].call(this, value);
} else if (
this.quill.scroll.query(format).prototype instanceof EmbedBlot
) {
// @ts-expect-error
this.quill.scroll.query(format).prototype instanceof _parchment.EmbedBlot) {
value = prompt(`Enter ${format}`); // eslint-disable-line no-alert
if (!value) return;
this.quill.updateContents(
new Delta()
.retain(range.index)
.delete(range.length)
.insert({ [format]: value }),
Quill.sources.USER,
);
this.quill.updateContents(new _quillDelta.default()
// @ts-expect-error Fix me later
.retain(range.index)
// @ts-expect-error Fix me later
.delete(range.length)
// @ts-expect-error Fix me later
.insert({
[format]: value
}), _quill.default.sources.USER);
} else {
this.quill.format(format, value, Quill.sources.USER);
// @ts-expect-error Fix me later
this.quill.format(format, value, _quill.default.sources.USER);
}

@@ -117,3 +132,2 @@ this.update(range);

}
update(range) {

@@ -124,3 +138,3 @@ const formats = range == null ? {} : this.quill.getFormat(range);

if (input.tagName === 'SELECT') {
let option;
let option = null;
if (range == null) {

@@ -138,3 +152,5 @@ option = null;

if (option == null) {
// @ts-expect-error TODO fix me later
input.value = ''; // TODO make configurable?
// @ts-expect-error TODO fix me later
input.selectedIndex = -1;

@@ -146,13 +162,14 @@ } else {

input.classList.remove('ql-active');
input.setAttribute('aria-pressed', 'false');
} else if (input.hasAttribute('value')) {
// both being null should match (default values)
// '1' should match with 1 (headers)
const isActive =
formats[format] === input.getAttribute('value') ||
(formats[format] != null &&
formats[format].toString() === input.getAttribute('value')) ||
(formats[format] == null && !input.getAttribute('value'));
const value = formats[format];
const isActive = value === input.getAttribute('value') || value != null && value.toString() === input.getAttribute('value') || value == null && !input.getAttribute('value');
input.classList.toggle('ql-active', isActive);
input.setAttribute('aria-pressed', isActive.toString());
} else {
input.classList.toggle('ql-active', formats[format] != null);
const isActive = formats[format] != null;
input.classList.toggle('ql-active', isActive);
input.setAttribute('aria-pressed', isActive.toString());
}

@@ -162,4 +179,4 @@ });

}
exports.default = Toolbar;
Toolbar.DEFAULTS = {};
function addButton(container, format, value) {

@@ -169,10 +186,14 @@ const input = document.createElement('button');

input.classList.add(`ql-${format}`);
input.setAttribute('aria-pressed', 'false');
if (value != null) {
input.value = value;
input.setAttribute('aria-label', `${format}: ${value}`);
} else {
input.setAttribute('aria-label', format);
}
container.appendChild(input);
}
function addControls(container, groups) {
if (!Array.isArray(groups[0])) {
// @ts-expect-error
groups = [groups];

@@ -199,3 +220,2 @@ }

}
function addSelect(container, format, values) {

@@ -207,3 +227,3 @@ const input = document.createElement('select');

if (value !== false) {
option.setAttribute('value', value);
option.setAttribute('value', String(value));
} else {

@@ -216,3 +236,2 @@ option.setAttribute('selected', 'selected');

}
Toolbar.DEFAULTS = {

@@ -228,18 +247,20 @@ container: null,

// Clean functionality in existing apps only clean inline formats
if (this.quill.scroll.query(name, Scope.INLINE) != null) {
this.quill.format(name, false, Quill.sources.USER);
if (this.quill.scroll.query(name, _parchment.Scope.INLINE) != null) {
this.quill.format(name, false, _quill.default.sources.USER);
}
});
} else {
this.quill.removeFormat(range, Quill.sources.USER);
this.quill.removeFormat(range, _quill.default.sources.USER);
}
},
direction(value) {
const { align } = this.quill.getFormat();
const {
align
} = this.quill.getFormat();
if (value === 'rtl' && align == null) {
this.quill.format('align', 'right', Quill.sources.USER);
this.quill.format('align', 'right', _quill.default.sources.USER);
} else if (!value && align === 'right') {
this.quill.format('align', false, Quill.sources.USER);
this.quill.format('align', false, _quill.default.sources.USER);
}
this.quill.format('direction', value, Quill.sources.USER);
this.quill.format('direction', value, _quill.default.sources.USER);
},

@@ -253,3 +274,3 @@ indent(value) {

if (formats.direction === 'rtl') modifier *= -1;
this.quill.format('indent', indent + modifier, Quill.sources.USER);
this.quill.format('indent', indent + modifier, _quill.default.sources.USER);
}

@@ -261,3 +282,4 @@ },

}
this.quill.format('link', value, Quill.sources.USER);
this.quill.format('link', value, _quill.default.sources.USER);
},

@@ -269,13 +291,12 @@ list(value) {

if (formats.list === 'checked' || formats.list === 'unchecked') {
this.quill.format('list', false, Quill.sources.USER);
this.quill.format('list', false, _quill.default.sources.USER);
} else {
this.quill.format('list', 'unchecked', Quill.sources.USER);
this.quill.format('list', 'unchecked', _quill.default.sources.USER);
}
} else {
this.quill.format('list', value, Quill.sources.USER);
this.quill.format('list', value, _quill.default.sources.USER);
}
},
},
}
}
};
export { Toolbar as default, addControls };
//# sourceMappingURL=toolbar.js.map

@@ -1,6 +0,12 @@

import Delta from 'quill-delta';
import Emitter from '../core/emitter';
import Module from '../core/module';
"use strict";
class Uploader extends Module {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _quillDelta = _interopRequireDefault(require("quill-delta"));
var _emitter = _interopRequireDefault(require("../core/emitter"));
var _module = _interopRequireDefault(require("../core/module"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class Uploader extends _module.default {
constructor(quill, options) {

@@ -10,6 +16,8 @@ super(quill, options);

e.preventDefault();
let native;
let native = null;
if (document.caretRangeFromPoint) {
native = document.caretRangeFromPoint(e.clientX, e.clientY);
// @ts-expect-error
} else if (document.caretPositionFromPoint) {
// @ts-expect-error
const position = document.caretPositionFromPoint(e.clientX, e.clientY);

@@ -19,15 +27,16 @@ native = document.createRange();

native.setEnd(position.offsetNode, position.offset);
} else {
return;
}
const normalized = quill.selection.normalizeNative(native);
const range = quill.selection.normalizedToRange(normalized);
this.upload(range, e.dataTransfer.files);
const normalized = native && quill.selection.normalizeNative(native);
if (normalized) {
const range = quill.selection.normalizedToRange(normalized);
if (e.dataTransfer?.files) {
this.upload(range, e.dataTransfer.files);
}
}
});
}
upload(range, files) {
const uploads = [];
Array.from(files).forEach(file => {
if (file && this.options.mimetypes.includes(file.type)) {
if (file && this.options.mimetypes?.includes(file.type)) {
uploads.push(file);

@@ -37,2 +46,3 @@ }

if (uploads.length > 0) {
// @ts-expect-error Fix me later
this.options.handler.call(this, range, uploads);

@@ -42,3 +52,2 @@ }

}
Uploader.DEFAULTS = {

@@ -51,2 +60,3 @@ mimetypes: ['image/png', 'image/jpeg'],

reader.onload = e => {
// @ts-expect-error Fix me later
resolve(e.target.result);

@@ -59,13 +69,12 @@ };

const update = images.reduce((delta, image) => {
return delta.insert({ image });
}, new Delta().retain(range.index).delete(range.length));
this.quill.updateContents(update, Emitter.sources.USER);
this.quill.setSelection(
range.index + images.length,
Emitter.sources.SILENT,
);
return delta.insert({
image
});
}, new _quillDelta.default().retain(range.index).delete(range.length));
this.quill.updateContents(update, _emitter.default.sources.USER);
this.quill.setSelection(range.index + images.length, _emitter.default.sources.SILENT);
});
},
}
};
export default Uploader;
var _default = exports.default = Uploader;
//# sourceMappingURL=uploader.js.map
{
"name": "quill",
"version": "2.0.0-dev.4",
"version": "2.0.0-rc.0",
"description": "Your powerful, rich text editor",
"author": "Jason Chen <jhchen7@gmail.com>",
"homepage": "http://quilljs.com",
"main": "dist/quill.js",
"files": [
"assets",
"blots",
"core",
"formats",
"modules",
"themes",
"ui",
"dist/quill.bubble.css",
"dist/quill.snow.css",
"dist/quill.core.css",
"dist/quill.js",
"dist/quill.core.js",
"dist/quill.min.js.map",
"dist/quill.min.js",
"core.js",
"quill.js"
],
"config": {
"ports": {
"proxy": "9000",
"jekyll": "4000",
"karma": "9876",
"webpack": "9080"
}
},
"homepage": "https://quilljs.com",
"main": "quill.js",
"dependencies": {
"clone": "^2.1.2",
"deep-equal": "^2.0.2",
"eventemitter3": "^4.0.0",
"extend": "^3.0.2",
"parchment": "2.0.0-dev.2",
"quill-delta": "4.2.1"
"eventemitter3": "^5.0.1",
"lodash-es": "^4.17.21",
"parchment": "^3.0.0-alpha.2",
"quill-delta": "^5.1.0"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.5",
"babel-loader": "^8.1.0",
"babel-plugin-istanbul": "^6.0.0",
"css-loader": "^3.5.1",
"eslint": "^6.8.0",
"eslint-config-airbnb": "^18.1.0",
"eslint-config-prettier": "^6.10.1",
"eslint-import-resolver-webpack": "~0.12.1",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-react": "^7.19.0",
"eslint-plugin-react-hooks": "^3.0.0",
"@babel/cli": "^7.23.4",
"@babel/core": "^7.23.3",
"@babel/preset-env": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
"@playwright/test": "1.38.1",
"@types/highlight.js": "^9.12.4",
"@types/lodash-es": "^4.17.12",
"@types/node": "^20.10.0",
"@types/webpack": "^5.28.5",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
"@vitest/browser": "^1.1.3",
"babel-loader": "^9.1.3",
"babel-plugin-transform-define": "^2.1.4",
"css-loader": "^6.8.1",
"eslint": "^8.54.0",
"eslint-config-prettier": "^9.0.0",
"eslint-import-resolver-webpack": "^0.13.8",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-prettier": "^5.0.1",
"highlight.js": "^9.18.1",
"html-loader": "~1.1.0",
"http-proxy": "^1.18.0",
"jasmine": "^3.5.0",
"jasmine-core": "^3.5.0",
"karma": "^5.0.1",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage": "^2.0.1",
"karma-jasmine": "^3.1.1",
"karma-sauce-launcher": "^4.1.2",
"lodash": "^4.17.15",
"mini-css-extract-plugin": "~0.9.0",
"prettier": "^1.17.0",
"puppeteer": "^2.1.1",
"style-loader": "~1.1.3",
"stylus": "~0.54.7",
"stylus-loader": "^3.0.2",
"ts-loader": "^6.2.2",
"typescript": "^3.8.3",
"webpack": "^4.42.1",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.3"
"html-loader": "^4.2.0",
"html-webpack-plugin": "^5.5.3",
"jsdom": "^22.1.0",
"mini-css-extract-plugin": "^2.7.6",
"prettier": "^3.0.3",
"style-loader": "^3.3.3",
"stylus": "^0.62.0",
"stylus-loader": "^7.1.3",
"svgo": "^3.2.0",
"terser-webpack-plugin": "^5.3.9",
"transpile-webpack-plugin": "^1.1.3",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.1",
"typescript": "5.2.2",
"vitest": "^1.1.3",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1",
"webpack-merge": "^5.10.0"
},

@@ -83,3 +60,4 @@ "license": "BSD-3-Clause",

"type": "git",
"url": "https://github.com/quilljs/quill"
"url": "git+https://github.com/quilljs/quill.git",
"directory": "packages/quill"
},

@@ -89,84 +67,32 @@ "bugs": {

},
"eslintConfig": {
"extends": [
"airbnb",
"prettier"
],
"env": {
"browser": true,
"commonjs": true,
"es6": true
},
"plugins": [
"prettier"
],
"settings": {
"import/resolver": {
"webpack": {
"config": "_develop/webpack.config.js"
}
}
},
"rules": {
"arrow-body-style": [
"off"
],
"class-methods-use-this": [
"off"
],
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": [
"_develop/*.js",
"test/**/*.js"
]
}
],
"no-param-reassign": [
"off"
],
"no-use-before-define": [
"error",
{
"functions": false
}
],
"import/named": [
"error"
],
"max-classes-per-file": [
"off"
],
"prettier/prettier": "error"
}
"prettier": {
"singleQuote": true
},
"eslintIgnore": [
"dist/",
"docs/",
"node_modules/"
"browserslist": [
"defaults"
],
"prettier": {
"singleQuote": true,
"trailingComma": "all"
},
"scripts": {
"build": "npm run lint && npm run build:webpack",
"build:webpack": "webpack --config _develop/webpack.config.js; rm dist/quill.core dist/quill.bubble dist/quill.snow",
"build:release": "./_develop/scripts/release.sh",
"develop": "npm run start",
"lint": "eslint blots core formats modules themes ui test",
"start": "npm run build:webpack; bundle exec foreman start -f _develop/procfile",
"test": "npm run test:unit",
"test:all": "npm run test:unit; npm run test:functional",
"test:functional": "./_develop/scripts/puppeteer.sh",
"test:unit": "npm run build; karma start _develop/karma.config.js",
"test:coverage": "webpack --env.coverage --config _develop/webpack.config.js; karma start _develop/karma.config.js --reporters coverage",
"travis": "npm run lint && karma start _develop/karma.config.js --reporters dots,saucelabs"
"build": "./scripts/build production",
"lint": "run-s lint:*",
"lint:eslint": "eslint .",
"lint:tsc": "tsc --noEmit --skipLibCheck",
"start": "[[ -z \"$npm_package_config_ports_webpack\" ]] && webpack-dev-server || webpack-dev-server --port $npm_package_config_ports_webpack",
"test": "run-s test:*",
"test:unit": "vitest --config test/unit/vitest.config.ts",
"test:fuzz": "vitest --config test/fuzz/vitest.config.ts",
"test:e2e": "playwright test"
},
"keywords": [
"quill",
"editor",
"rich text",
"wysiwyg"
]
"wysiwyg",
"operational transformation",
"ot",
"framework"
],
"engines": {
"npm": ">=8.2.3"
},
"engineStrict": true
}

@@ -1,111 +0,90 @@

import Quill from './core';
"use strict";
import { AlignClass, AlignStyle } from './formats/align';
import {
DirectionAttribute,
DirectionClass,
DirectionStyle,
} from './formats/direction';
import Indent from './formats/indent';
import Blockquote from './formats/blockquote';
import Header from './formats/header';
import List from './formats/list';
import { BackgroundClass, BackgroundStyle } from './formats/background';
import { ColorClass, ColorStyle } from './formats/color';
import { FontClass, FontStyle } from './formats/font';
import { SizeClass, SizeStyle } from './formats/size';
import Bold from './formats/bold';
import Italic from './formats/italic';
import Link from './formats/link';
import Script from './formats/script';
import Strike from './formats/strike';
import Underline from './formats/underline';
import Formula from './formats/formula';
import Image from './formats/image';
import Video from './formats/video';
import CodeBlock, { Code as InlineCode } from './formats/code';
import Syntax from './modules/syntax';
import Table from './modules/table';
import Toolbar from './modules/toolbar';
import Icons from './ui/icons';
import Picker from './ui/picker';
import ColorPicker from './ui/color-picker';
import IconPicker from './ui/icon-picker';
import Tooltip from './ui/tooltip';
import BubbleTheme from './themes/bubble';
import SnowTheme from './themes/snow';
Quill.register(
{
'attributors/attribute/direction': DirectionAttribute,
'attributors/class/align': AlignClass,
'attributors/class/background': BackgroundClass,
'attributors/class/color': ColorClass,
'attributors/class/direction': DirectionClass,
'attributors/class/font': FontClass,
'attributors/class/size': SizeClass,
'attributors/style/align': AlignStyle,
'attributors/style/background': BackgroundStyle,
'attributors/style/color': ColorStyle,
'attributors/style/direction': DirectionStyle,
'attributors/style/font': FontStyle,
'attributors/style/size': SizeStyle,
},
true,
);
Quill.register(
{
'formats/align': AlignClass,
'formats/direction': DirectionClass,
'formats/indent': Indent,
'formats/background': BackgroundStyle,
'formats/color': ColorStyle,
'formats/font': FontClass,
'formats/size': SizeClass,
'formats/blockquote': Blockquote,
'formats/code-block': CodeBlock,
'formats/header': Header,
'formats/list': List,
'formats/bold': Bold,
'formats/code': InlineCode,
'formats/italic': Italic,
'formats/link': Link,
'formats/script': Script,
'formats/strike': Strike,
'formats/underline': Underline,
'formats/formula': Formula,
'formats/image': Image,
'formats/video': Video,
'modules/syntax': Syntax,
'modules/table': Table,
'modules/toolbar': Toolbar,
'themes/bubble': BubbleTheme,
'themes/snow': SnowTheme,
'ui/icons': Icons,
'ui/picker': Picker,
'ui/icon-picker': IconPicker,
'ui/color-picker': ColorPicker,
'ui/tooltip': Tooltip,
},
true,
);
export default Quill;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _core = _interopRequireDefault(require("./core"));
var _align = require("./formats/align");
var _direction = require("./formats/direction");
var _indent = _interopRequireDefault(require("./formats/indent"));
var _blockquote = _interopRequireDefault(require("./formats/blockquote"));
var _header = _interopRequireDefault(require("./formats/header"));
var _list = _interopRequireDefault(require("./formats/list"));
var _background = require("./formats/background");
var _color = require("./formats/color");
var _font = require("./formats/font");
var _size = require("./formats/size");
var _bold = _interopRequireDefault(require("./formats/bold"));
var _italic = _interopRequireDefault(require("./formats/italic"));
var _link = _interopRequireDefault(require("./formats/link"));
var _script = _interopRequireDefault(require("./formats/script"));
var _strike = _interopRequireDefault(require("./formats/strike"));
var _underline = _interopRequireDefault(require("./formats/underline"));
var _formula = _interopRequireDefault(require("./formats/formula"));
var _image = _interopRequireDefault(require("./formats/image"));
var _video = _interopRequireDefault(require("./formats/video"));
var _code = _interopRequireWildcard(require("./formats/code"));
var _syntax = _interopRequireDefault(require("./modules/syntax"));
var _table = _interopRequireDefault(require("./modules/table"));
var _toolbar = _interopRequireDefault(require("./modules/toolbar"));
var _icons = _interopRequireDefault(require("./ui/icons"));
var _picker = _interopRequireDefault(require("./ui/picker"));
var _colorPicker = _interopRequireDefault(require("./ui/color-picker"));
var _iconPicker = _interopRequireDefault(require("./ui/icon-picker"));
var _tooltip = _interopRequireDefault(require("./ui/tooltip"));
var _bubble = _interopRequireDefault(require("./themes/bubble"));
var _snow = _interopRequireDefault(require("./themes/snow"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
_core.default.register({
'attributors/attribute/direction': _direction.DirectionAttribute,
'attributors/class/align': _align.AlignClass,
'attributors/class/background': _background.BackgroundClass,
'attributors/class/color': _color.ColorClass,
'attributors/class/direction': _direction.DirectionClass,
'attributors/class/font': _font.FontClass,
'attributors/class/size': _size.SizeClass,
'attributors/style/align': _align.AlignStyle,
'attributors/style/background': _background.BackgroundStyle,
'attributors/style/color': _color.ColorStyle,
'attributors/style/direction': _direction.DirectionStyle,
'attributors/style/font': _font.FontStyle,
'attributors/style/size': _size.SizeStyle
}, true);
_core.default.register({
'formats/align': _align.AlignClass,
'formats/direction': _direction.DirectionClass,
'formats/indent': _indent.default,
'formats/background': _background.BackgroundStyle,
'formats/color': _color.ColorStyle,
'formats/font': _font.FontClass,
'formats/size': _size.SizeClass,
'formats/blockquote': _blockquote.default,
'formats/code-block': _code.default,
'formats/header': _header.default,
'formats/list': _list.default,
'formats/bold': _bold.default,
'formats/code': _code.Code,
'formats/italic': _italic.default,
'formats/link': _link.default,
'formats/script': _script.default,
'formats/strike': _strike.default,
'formats/underline': _underline.default,
'formats/formula': _formula.default,
'formats/image': _image.default,
'formats/video': _video.default,
'modules/syntax': _syntax.default,
'modules/table': _table.default,
'modules/toolbar': _toolbar.default,
'themes/bubble': _bubble.default,
'themes/snow': _snow.default,
'ui/icons': _icons.default,
'ui/picker': _picker.default,
'ui/icon-picker': _iconPicker.default,
'ui/color-picker': _colorPicker.default,
'ui/tooltip': _tooltip.default
}, true);
var _default = exports.default = _core.default;
//# sourceMappingURL=quill.js.map

@@ -10,4 +10,2 @@ Note: This branch and README covers the upcoming 2.0 release. View [1.x docs here](https://github.com/quilljs/quill/tree/1.3.6).

<p align="center">
<a title="Quickstart" href="#quickstart"><strong>Quickstart</strong></a>
&#x2022;
<a title="Documentation" href="https://quilljs.com/docs/"><strong>Documentation</strong></a>

@@ -22,4 +20,4 @@ &#x2022;

<p align="center">
<a href="https://travis-ci.org/quilljs/quill" title="Build Status">
<img src="https://travis-ci.org/quilljs/quill.svg?branch=master" alt="Build Status">
<a href="https://github.com/quilljs/quill/actions" title="Build Status">
<img src="https://github.com/quilljs/quill/actions/workflows/main.yml/badge.svg" alt="Build Status">
</a>

@@ -33,7 +31,2 @@ <a href="https://npmjs.com/package/quill" title="Version">

</p>
<p align="center">
<a href="https://saucelabs.com/u/quill" title="Test Status">
<img src="https://cdn.quilljs.com/badge.svg?v=2" alt="Test Status">
</a>
</p>

@@ -44,60 +37,2 @@ [Quill](https://quilljs.com/) is a modern rich text editor built for compatibility and extensibility. It was created by [Jason Chen](https://twitter.com/jhchen) and [Byron Milligan](https://twitter.com/byronmilligan) and actively maintained by [Slab](https://slab.com).

## Quickstart
Instantiate a new Quill object with a css selector for the div that should become the editor.
```html
<!-- Include Quill stylesheet -->
<link href="https://cdn.quilljs.com/1.0.0/quill.snow.css" rel="stylesheet">
<!-- Create the toolbar container -->
<div id="toolbar">
<button class="ql-bold">Bold</button>
<button class="ql-italic">Italic</button>
</div>
<!-- Create the editor container -->
<div id="editor">
<p>Hello World!</p>
</div>
<!-- Include the Quill library -->
<script src="https://cdn.quilljs.com/1.0.0/quill.js"></script>
<!-- Initialize Quill editor -->
<script>
var editor = new Quill('#editor', {
modules: { toolbar: '#toolbar' },
theme: 'snow'
});
</script>
```
Take a look at the [Quill](https://quilljs.com/) website for more documentation, guides and [live playground](https://quilljs.com/playground/)!
## Download
- [npm](https://www.npmjs.com/package/quill) - `npm install quill`
- tar - https://github.com/quilljs/quill/releases
### CDN
```html
<!-- Main Quill library -->
<script src="//cdn.quilljs.com/1.0.0/quill.js"></script>
<script src="//cdn.quilljs.com/1.0.0/quill.min.js"></script>
<!-- Theme included stylesheets -->
<link href="//cdn.quilljs.com/1.0.0/quill.snow.css" rel="stylesheet">
<link href="//cdn.quilljs.com/1.0.0/quill.bubble.css" rel="stylesheet">
<!-- Core build with no theme, formatting, non-essential modules -->
<link href="//cdn.quilljs.com/1.0.0/quill.core.css" rel="stylesheet">
<script src="//cdn.quilljs.com/1.0.0/quill.core.js"></script>
```
## Community

@@ -111,6 +46,1 @@

- If privacy is required, email support@quilljs.com
## License
BSD 3-clause

@@ -1,56 +0,21 @@

import extend from 'extend';
import Emitter from '../core/emitter';
import Theme from '../core/theme';
import ColorPicker from '../ui/color-picker';
import IconPicker from '../ui/icon-picker';
import Picker from '../ui/picker';
import Tooltip from '../ui/tooltip';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.BaseTooltip = void 0;
var _lodashEs = require("lodash-es");
var _emitter = _interopRequireDefault(require("../core/emitter"));
var _theme = _interopRequireDefault(require("../core/theme"));
var _colorPicker = _interopRequireDefault(require("../ui/color-picker"));
var _iconPicker = _interopRequireDefault(require("../ui/icon-picker"));
var _picker = _interopRequireDefault(require("../ui/picker"));
var _tooltip = _interopRequireDefault(require("../ui/tooltip"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const ALIGNS = [false, 'center', 'right', 'justify'];
const COLORS = [
'#000000',
'#e60000',
'#ff9900',
'#ffff00',
'#008a00',
'#0066cc',
'#9933ff',
'#ffffff',
'#facccc',
'#ffebcc',
'#ffffcc',
'#cce8cc',
'#cce0f5',
'#ebd6ff',
'#bbbbbb',
'#f06666',
'#ffc266',
'#ffff66',
'#66b966',
'#66a3e0',
'#c285ff',
'#888888',
'#a10000',
'#b26b00',
'#b2b200',
'#006100',
'#0047b2',
'#6b24b2',
'#444444',
'#5c0000',
'#663d00',
'#666600',
'#003700',
'#002966',
'#3d1466',
];
const COLORS = ['#000000', '#e60000', '#ff9900', '#ffff00', '#008a00', '#0066cc', '#9933ff', '#ffffff', '#facccc', '#ffebcc', '#ffffcc', '#cce8cc', '#cce0f5', '#ebd6ff', '#bbbbbb', '#f06666', '#ffc266', '#ffff66', '#66b966', '#66a3e0', '#c285ff', '#888888', '#a10000', '#b26b00', '#b2b200', '#006100', '#0047b2', '#6b24b2', '#444444', '#5c0000', '#663d00', '#666600', '#003700', '#002966', '#3d1466'];
const FONTS = [false, 'serif', 'monospace'];
const HEADERS = ['1', '2', '3', false];
const SIZES = ['small', false, 'large', 'huge'];
class BaseTheme extends Theme {
class BaseTheme extends _theme.default {
constructor(quill, options) {

@@ -63,8 +28,7 @@ super(quill, options);

}
if (
this.tooltip != null &&
!this.tooltip.root.contains(e.target) &&
document.activeElement !== this.tooltip.textbox &&
!this.quill.hasFocus()
) {
if (this.tooltip != null &&
// @ts-expect-error
!this.tooltip.root.contains(e.target) &&
// @ts-expect-error
document.activeElement !== this.tooltip.textbox && !this.quill.hasFocus()) {
this.tooltip.hide();

@@ -74,2 +38,3 @@ }

this.pickers.forEach(picker => {
// @ts-expect-error
if (!picker.container.contains(e.target)) {

@@ -83,6 +48,6 @@ picker.close();

}
addModule(name) {
const module = super.addModule(name);
if (name === 'toolbar') {
// @ts-expect-error
this.extendToolbar(module);

@@ -92,3 +57,2 @@ }

}
buildButtons(buttons, icons) {

@@ -102,8 +66,13 @@ Array.from(buttons).forEach(button => {

if (name === 'direction') {
// @ts-expect-error
button.innerHTML = icons[name][''] + icons[name].rtl;
} else if (typeof icons[name] === 'string') {
// @ts-expect-error
button.innerHTML = icons[name];
} else {
// @ts-expect-error
const value = button.value || '';
// @ts-expect-error
if (value != null && icons[name][value]) {
// @ts-expect-error
button.innerHTML = icons[name][value];

@@ -115,3 +84,2 @@ }

}
buildPickers(selects, icons) {

@@ -123,19 +91,12 @@ this.pickers = Array.from(selects).map(select => {

}
return new IconPicker(select, icons.align);
if (typeof icons.align === 'object') {
return new _iconPicker.default(select, icons.align);
}
}
if (
select.classList.contains('ql-background') ||
select.classList.contains('ql-color')
) {
const format = select.classList.contains('ql-background')
? 'background'
: 'color';
if (select.classList.contains('ql-background') || select.classList.contains('ql-color')) {
const format = select.classList.contains('ql-background') ? 'background' : 'color';
if (select.querySelector('option') == null) {
fillSelect(
select,
COLORS,
format === 'background' ? '#ffffff' : '#000000',
);
fillSelect(select, COLORS, format === 'background' ? '#ffffff' : '#000000');
}
return new ColorPicker(select, icons[format]);
return new _colorPicker.default(select, icons[format]);
}

@@ -151,3 +112,3 @@ if (select.querySelector('option') == null) {

}
return new Picker(select);
return new _picker.default(select);
});

@@ -159,6 +120,7 @@ const update = () => {

};
this.quill.on(Emitter.events.EDITOR_CHANGE, update);
this.quill.on(_emitter.default.events.EDITOR_CHANGE, update);
}
}
BaseTheme.DEFAULTS = extend(true, {}, Theme.DEFAULTS, {
exports.default = BaseTheme;
BaseTheme.DEFAULTS = (0, _lodashEs.merge)({}, _theme.default.DEFAULTS, {
modules: {

@@ -171,12 +133,7 @@ toolbar: {

image() {
let fileInput = this.container.querySelector(
'input.ql-image[type=file]',
);
let fileInput = this.container.querySelector('input.ql-image[type=file]');
if (fileInput == null) {
fileInput = document.createElement('input');
fileInput.setAttribute('type', 'file');
fileInput.setAttribute(
'accept',
this.quill.uploader.options.mimetypes.join(', '),
);
fileInput.setAttribute('accept', this.quill.uploader.options.mimetypes.join(', '));
fileInput.classList.add('ql-image');

@@ -194,9 +151,8 @@ fileInput.addEventListener('change', () => {

this.quill.theme.tooltip.edit('video');
},
},
},
},
}
}
}
}
});
class BaseTooltip extends Tooltip {
class BaseTooltip extends _tooltip.default {
constructor(quill, boundsContainer) {

@@ -207,4 +163,4 @@ super(quill, boundsContainer);

}
listen() {
// @ts-expect-error Fix me later
this.textbox.addEventListener('keydown', event => {

@@ -220,10 +176,12 @@ if (event.key === 'Enter') {

}
cancel() {
this.hide();
this.restoreFocus();
}
edit(mode = 'link', preview = null) {
edit() {
let mode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'link';
let preview = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
this.root.classList.remove('ql-hidden');
this.root.classList.add('ql-editing');
if (this.textbox == null) return;
if (preview != null) {

@@ -234,60 +192,60 @@ this.textbox.value = preview;

}
this.position(this.quill.getBounds(this.quill.selection.savedRange));
const bounds = this.quill.getBounds(this.quill.selection.savedRange);
if (bounds != null) {
this.position(bounds);
}
this.textbox.select();
this.textbox.setAttribute(
'placeholder',
this.textbox.getAttribute(`data-${mode}`) || '',
);
this.textbox.setAttribute('placeholder', this.textbox.getAttribute(`data-${mode}`) || '');
this.root.setAttribute('data-mode', mode);
}
restoreFocus() {
const { scrollTop } = this.quill.scrollingContainer;
this.quill.focus();
this.quill.scrollingContainer.scrollTop = scrollTop;
this.quill.focus({
preventScroll: true
});
}
save() {
let { value } = this.textbox;
// @ts-expect-error Fix me later
let {
value
} = this.textbox;
switch (this.root.getAttribute('data-mode')) {
case 'link': {
const { scrollTop } = this.quill.root;
if (this.linkRange) {
this.quill.formatText(
this.linkRange,
'link',
value,
Emitter.sources.USER,
);
delete this.linkRange;
} else {
this.restoreFocus();
this.quill.format('link', value, Emitter.sources.USER);
case 'link':
{
const {
scrollTop
} = this.quill.root;
if (this.linkRange) {
this.quill.formatText(this.linkRange, 'link', value, _emitter.default.sources.USER);
delete this.linkRange;
} else {
this.restoreFocus();
this.quill.format('link', value, _emitter.default.sources.USER);
}
this.quill.root.scrollTop = scrollTop;
break;
}
this.quill.root.scrollTop = scrollTop;
break;
}
case 'video': {
value = extractVideoUrl(value);
} // eslint-disable-next-line no-fallthrough
case 'formula': {
if (!value) break;
const range = this.quill.getSelection(true);
if (range != null) {
const index = range.index + range.length;
this.quill.insertEmbed(
index,
this.root.getAttribute('data-mode'),
value,
Emitter.sources.USER,
);
if (this.root.getAttribute('data-mode') === 'formula') {
this.quill.insertText(index + 1, ' ', Emitter.sources.USER);
case 'video':
{
value = extractVideoUrl(value);
}
// eslint-disable-next-line no-fallthrough
case 'formula':
{
if (!value) break;
const range = this.quill.getSelection(true);
if (range != null) {
const index = range.index + range.length;
this.quill.insertEmbed(index,
// @ts-expect-error Fix me later
this.root.getAttribute('data-mode'), value, _emitter.default.sources.USER);
if (this.root.getAttribute('data-mode') === 'formula') {
this.quill.insertText(index + 1, ' ', _emitter.default.sources.USER);
}
this.quill.setSelection(index + 2, _emitter.default.sources.USER);
}
this.quill.setSelection(index + 2, Emitter.sources.USER);
break;
}
break;
}
default:
}
// @ts-expect-error Fix me later
this.textbox.value = '';

@@ -297,16 +255,10 @@ this.hide();

}
exports.BaseTooltip = BaseTooltip;
function extractVideoUrl(url) {
let match =
url.match(
/^(?:(https?):\/\/)?(?:(?:www|m)\.)?youtube\.com\/watch.*v=([a-zA-Z0-9_-]+)/,
) ||
url.match(/^(?:(https?):\/\/)?(?:(?:www|m)\.)?youtu\.be\/([a-zA-Z0-9_-]+)/);
let match = url.match(/^(?:(https?):\/\/)?(?:(?:www|m)\.)?youtube\.com\/watch.*v=([a-zA-Z0-9_-]+)/) || url.match(/^(?:(https?):\/\/)?(?:(?:www|m)\.)?youtu\.be\/([a-zA-Z0-9_-]+)/);
if (match) {
return `${match[1] || 'https'}://www.youtube.com/embed/${
match[2]
}?showinfo=0`;
return `${match[1] || 'https'}://www.youtube.com/embed/${match[2]}?showinfo=0`;
}
// eslint-disable-next-line no-cond-assign
if ((match = url.match(/^(?:(https?):\/\/)?(?:www\.)?vimeo\.com\/(\d+)/))) {
if (match = url.match(/^(?:(https?):\/\/)?(?:www\.)?vimeo\.com\/(\d+)/)) {
return `${match[1] || 'https'}://player.vimeo.com/video/${match[2]}/`;

@@ -316,4 +268,4 @@ }

}
function fillSelect(select, values, defaultValue = false) {
function fillSelect(select, values) {
let defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
values.forEach(value => {

@@ -324,3 +276,3 @@ const option = document.createElement('option');

} else {
option.setAttribute('value', value);
option.setAttribute('value', String(value));
}

@@ -330,3 +282,2 @@ select.appendChild(option);

}
export { BaseTooltip, BaseTheme as default };
//# sourceMappingURL=base.js.map

@@ -1,58 +0,59 @@

import extend from 'extend';
import Emitter from '../core/emitter';
import BaseTheme, { BaseTooltip } from './base';
import { Range } from '../core/selection';
import icons from '../ui/icons';
"use strict";
const TOOLBAR_CONFIG = [
['bold', 'italic', 'link'],
[{ header: 1 }, { header: 2 }, 'blockquote'],
];
class BubbleTooltip extends BaseTooltip {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.BubbleTooltip = void 0;
var _lodashEs = require("lodash-es");
var _emitter = _interopRequireDefault(require("../core/emitter"));
var _base = _interopRequireWildcard(require("./base"));
var _selection = require("../core/selection");
var _icons = _interopRequireDefault(require("../ui/icons"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const TOOLBAR_CONFIG = [['bold', 'italic', 'link'], [{
header: 1
}, {
header: 2
}, 'blockquote']];
class BubbleTooltip extends _base.BaseTooltip {
static TEMPLATE = ['<span class="ql-tooltip-arrow"></span>', '<div class="ql-tooltip-editor">', '<input type="text" data-formula="e=mc^2" data-link="https://quilljs.com" data-video="Embed URL">', '<a class="ql-close"></a>', '</div>'].join('');
constructor(quill, bounds) {
super(quill, bounds);
this.quill.on(
Emitter.events.EDITOR_CHANGE,
(type, range, oldRange, source) => {
if (type !== Emitter.events.SELECTION_CHANGE) return;
if (
range != null &&
range.length > 0 &&
source === Emitter.sources.USER
) {
this.show();
// Lock our width so we will expand beyond our offsetParent boundaries
this.root.style.left = '0px';
this.root.style.width = '';
this.root.style.width = `${this.root.offsetWidth}px`;
const lines = this.quill.getLines(range.index, range.length);
if (lines.length === 1) {
this.position(this.quill.getBounds(range));
} else {
const lastLine = lines[lines.length - 1];
const index = this.quill.getIndex(lastLine);
const length = Math.min(
lastLine.length() - 1,
range.index + range.length - index,
);
const indexBounds = this.quill.getBounds(new Range(index, length));
this.quill.on(_emitter.default.events.EDITOR_CHANGE, (type, range, oldRange, source) => {
if (type !== _emitter.default.events.SELECTION_CHANGE) return;
if (range != null && range.length > 0 && source === _emitter.default.sources.USER) {
this.show();
// Lock our width so we will expand beyond our offsetParent boundaries
this.root.style.left = '0px';
this.root.style.width = '';
this.root.style.width = `${this.root.offsetWidth}px`;
const lines = this.quill.getLines(range.index, range.length);
if (lines.length === 1) {
const bounds = this.quill.getBounds(range);
if (bounds != null) {
this.position(bounds);
}
} else {
const lastLine = lines[lines.length - 1];
const index = this.quill.getIndex(lastLine);
const length = Math.min(lastLine.length() - 1, range.index + range.length - index);
const indexBounds = this.quill.getBounds(new _selection.Range(index, length));
if (indexBounds != null) {
this.position(indexBounds);
}
} else if (
document.activeElement !== this.textbox &&
this.quill.hasFocus()
) {
this.hide();
}
},
);
} else if (document.activeElement !== this.textbox && this.quill.hasFocus()) {
this.hide();
}
});
}
listen() {
super.listen();
// @ts-expect-error Fix me later
this.root.querySelector('.ql-close').addEventListener('click', () => {
this.root.classList.remove('ql-editing');
});
this.quill.on(Emitter.events.SCROLL_OPTIMIZE, () => {
this.quill.on(_emitter.default.events.SCROLL_OPTIMIZE, () => {
// Let selection be restored by toolbar handlers before repositioning

@@ -63,3 +64,6 @@ setTimeout(() => {

if (range != null) {
this.position(this.quill.getBounds(range));
const bounds = this.quill.getBounds(range);
if (bounds != null) {
this.position(bounds);
}
}

@@ -69,12 +73,12 @@ }, 1);

}
cancel() {
this.show();
}
position(reference) {
const shift = super.position(reference);
const arrow = this.root.querySelector('.ql-tooltip-arrow');
// @ts-expect-error
arrow.style.marginLeft = '';
if (shift !== 0) {
// @ts-expect-error
arrow.style.marginLeft = `${-1 * shift - arrow.offsetWidth / 2}px`;

@@ -85,16 +89,6 @@ }

}
BubbleTooltip.TEMPLATE = [
'<span class="ql-tooltip-arrow"></span>',
'<div class="ql-tooltip-editor">',
'<input type="text" data-formula="e=mc^2" data-link="https://quilljs.com" data-video="Embed URL">',
'<a class="ql-close"></a>',
'</div>',
].join('');
class BubbleTheme extends BaseTheme {
exports.BubbleTooltip = BubbleTooltip;
class BubbleTheme extends _base.default {
constructor(quill, options) {
if (
options.modules.toolbar != null &&
options.modules.toolbar.container == null
) {
if (options.modules.toolbar != null && options.modules.toolbar.container == null) {
options.modules.toolbar.container = TOOLBAR_CONFIG;

@@ -105,11 +99,14 @@ }

}
extendToolbar(toolbar) {
// @ts-expect-error
this.tooltip = new BubbleTooltip(this.quill, this.options.bounds);
this.tooltip.root.appendChild(toolbar.container);
this.buildButtons(toolbar.container.querySelectorAll('button'), icons);
this.buildPickers(toolbar.container.querySelectorAll('select'), icons);
if (toolbar.container != null) {
this.tooltip.root.appendChild(toolbar.container);
this.buildButtons(toolbar.container.querySelectorAll('button'), _icons.default);
this.buildPickers(toolbar.container.querySelectorAll('select'), _icons.default);
}
}
}
BubbleTheme.DEFAULTS = extend(true, {}, BaseTheme.DEFAULTS, {
exports.default = BubbleTheme;
BubbleTheme.DEFAULTS = (0, _lodashEs.merge)({}, _base.default.DEFAULTS, {
modules: {

@@ -124,8 +121,7 @@ toolbar: {

}
},
},
},
},
}
}
}
}
});
export { BubbleTooltip, BubbleTheme as default };
//# sourceMappingURL=bubble.js.map

@@ -1,23 +0,29 @@

import extend from 'extend';
import Emitter from '../core/emitter';
import BaseTheme, { BaseTooltip } from './base';
import LinkBlot from '../formats/link';
import { Range } from '../core/selection';
import icons from '../ui/icons';
"use strict";
const TOOLBAR_CONFIG = [
[{ header: ['1', '2', '3', false] }],
['bold', 'italic', 'underline', 'link'],
[{ list: 'ordered' }, { list: 'bullet' }],
['clean'],
];
class SnowTooltip extends BaseTooltip {
constructor(quill, bounds) {
super(quill, bounds);
this.preview = this.root.querySelector('a.ql-preview');
}
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _lodashEs = require("lodash-es");
var _emitter = _interopRequireDefault(require("../core/emitter"));
var _base = _interopRequireWildcard(require("./base"));
var _link = _interopRequireDefault(require("../formats/link"));
var _selection = require("../core/selection");
var _icons = _interopRequireDefault(require("../ui/icons"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const TOOLBAR_CONFIG = [[{
header: ['1', '2', '3', false]
}], ['bold', 'italic', 'underline', 'link'], [{
list: 'ordered'
}, {
list: 'bullet'
}], ['clean']];
class SnowTooltip extends _base.BaseTooltip {
static TEMPLATE = ['<a class="ql-preview" rel="noopener noreferrer" target="_blank" href="about:blank"></a>', '<input type="text" data-formula="e=mc^2" data-link="https://quilljs.com" data-video="Embed URL">', '<a class="ql-action"></a>', '<a class="ql-remove"></a>'].join('');
preview = this.root.querySelector('a.ql-preview');
listen() {
super.listen();
// @ts-expect-error Fix me later
this.root.querySelector('a.ql-action').addEventListener('click', event => {

@@ -27,2 +33,3 @@ if (this.root.classList.contains('ql-editing')) {

} else {
// @ts-expect-error Fix me later
this.edit('link', this.preview.textContent);

@@ -32,2 +39,3 @@ }

});
// @ts-expect-error Fix me later
this.root.querySelector('a.ql-remove').addEventListener('click', event => {

@@ -37,3 +45,3 @@ if (this.linkRange != null) {

this.restoreFocus();
this.quill.formatText(range, 'link', false, Emitter.sources.USER);
this.quill.formatText(range, 'link', false, _emitter.default.sources.USER);
delete this.linkRange;

@@ -44,28 +52,26 @@ }

});
this.quill.on(
Emitter.events.SELECTION_CHANGE,
(range, oldRange, source) => {
if (range == null) return;
if (range.length === 0 && source === Emitter.sources.USER) {
const [link, offset] = this.quill.scroll.descendant(
LinkBlot,
range.index,
);
if (link != null) {
this.linkRange = new Range(range.index - offset, link.length());
const preview = LinkBlot.formats(link.domNode);
this.preview.textContent = preview;
this.preview.setAttribute('href', preview);
this.show();
this.position(this.quill.getBounds(this.linkRange));
return;
this.quill.on(_emitter.default.events.SELECTION_CHANGE, (range, oldRange, source) => {
if (range == null) return;
if (range.length === 0 && source === _emitter.default.sources.USER) {
const [link, offset] = this.quill.scroll.descendant(_link.default, range.index);
if (link != null) {
this.linkRange = new _selection.Range(range.index - offset, link.length());
const preview = _link.default.formats(link.domNode);
// @ts-expect-error Fix me later
this.preview.textContent = preview;
// @ts-expect-error Fix me later
this.preview.setAttribute('href', preview);
this.show();
const bounds = this.quill.getBounds(this.linkRange);
if (bounds != null) {
this.position(bounds);
}
} else {
delete this.linkRange;
return;
}
this.hide();
},
);
} else {
delete this.linkRange;
}
this.hide();
});
}
show() {

@@ -76,15 +82,5 @@ super.show();

}
SnowTooltip.TEMPLATE = [
'<a class="ql-preview" rel="noopener noreferrer" target="_blank" href="about:blank"></a>',
'<input type="text" data-formula="e=mc^2" data-link="https://quilljs.com" data-video="Embed URL">',
'<a class="ql-action"></a>',
'<a class="ql-remove"></a>',
].join('');
class SnowTheme extends BaseTheme {
class SnowTheme extends _base.default {
constructor(quill, options) {
if (
options.modules.toolbar != null &&
options.modules.toolbar.container == null
) {
if (options.modules.toolbar != null && options.modules.toolbar.container == null) {
options.modules.toolbar.container = TOOLBAR_CONFIG;

@@ -95,19 +91,21 @@ }

}
extendToolbar(toolbar) {
toolbar.container.classList.add('ql-snow');
this.buildButtons(toolbar.container.querySelectorAll('button'), icons);
this.buildPickers(toolbar.container.querySelectorAll('select'), icons);
this.tooltip = new SnowTooltip(this.quill, this.options.bounds);
if (toolbar.container.querySelector('.ql-link')) {
this.quill.keyboard.addBinding(
{ key: 'k', shortKey: true },
(range, context) => {
if (toolbar.container != null) {
toolbar.container.classList.add('ql-snow');
this.buildButtons(toolbar.container.querySelectorAll('button'), _icons.default);
this.buildPickers(toolbar.container.querySelectorAll('select'), _icons.default);
// @ts-expect-error
this.tooltip = new SnowTooltip(this.quill, this.options.bounds);
if (toolbar.container.querySelector('.ql-link')) {
this.quill.keyboard.addBinding({
key: 'k',
shortKey: true
}, (_range, context) => {
toolbar.handlers.link.call(toolbar, !context.format.link);
},
);
});
}
}
}
}
SnowTheme.DEFAULTS = extend(true, {}, BaseTheme.DEFAULTS, {
SnowTheme.DEFAULTS = (0, _lodashEs.merge)({}, _base.default.DEFAULTS, {
modules: {

@@ -121,9 +119,8 @@ toolbar: {

let preview = this.quill.getText(range);
if (
/^\S+@\S+\.\S+$/.test(preview) &&
preview.indexOf('mailto:') !== 0
) {
if (/^\S+@\S+\.\S+$/.test(preview) && preview.indexOf('mailto:') !== 0) {
preview = `mailto:${preview}`;
}
const { tooltip } = this.quill.theme;
const {
tooltip
} = this.quill.theme;
tooltip.edit('link', preview);

@@ -133,8 +130,8 @@ } else {

}
},
},
},
},
}
}
}
}
});
export default SnowTheme;
var _default = exports.default = SnowTheme;
//# sourceMappingURL=snow.js.map

@@ -1,4 +0,10 @@

import Picker from './picker';
"use strict";
class ColorPicker extends Picker {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _picker = _interopRequireDefault(require("./picker"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class ColorPicker extends _picker.default {
constructor(select, label) {

@@ -8,9 +14,6 @@ super(select);

this.container.classList.add('ql-color-picker');
Array.from(this.container.querySelectorAll('.ql-picker-item'))
.slice(0, 7)
.forEach(item => {
item.classList.add('ql-primary');
});
Array.from(this.container.querySelectorAll('.ql-picker-item')).slice(0, 7).forEach(item => {
item.classList.add('ql-primary');
});
}
buildItem(option) {

@@ -21,3 +24,2 @@ const item = super.buildItem(option);

}
selectItem(item, trigger) {

@@ -36,3 +38,3 @@ super.selectItem(item, trigger);

}
export default ColorPicker;
var _default = exports.default = ColorPicker;
//# sourceMappingURL=color-picker.js.map

@@ -1,24 +0,29 @@

import Picker from './picker';
"use strict";
class IconPicker extends Picker {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _picker = _interopRequireDefault(require("./picker"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class IconPicker extends _picker.default {
constructor(select, icons) {
super(select);
this.container.classList.add('ql-icon-picker');
Array.from(this.container.querySelectorAll('.ql-picker-item')).forEach(
item => {
item.innerHTML = icons[item.getAttribute('data-value') || ''];
},
);
Array.from(this.container.querySelectorAll('.ql-picker-item')).forEach(item => {
item.innerHTML = icons[item.getAttribute('data-value') || ''];
});
this.defaultItem = this.container.querySelector('.ql-selected');
this.selectItem(this.defaultItem);
}
selectItem(target, trigger) {
super.selectItem(target, trigger);
const item = target || this.defaultItem;
if (this.label.innerHTML === item.innerHTML) return;
this.label.innerHTML = item.innerHTML;
if (item != null) {
if (this.label.innerHTML === item.innerHTML) return;
this.label.innerHTML = item.innerHTML;
}
}
}
export default IconPicker;
var _default = exports.default = IconPicker;
//# sourceMappingURL=icon-picker.js.map

@@ -1,32 +0,37 @@

import alignLeftIcon from '../assets/icons/align-left.svg';
import alignCenterIcon from '../assets/icons/align-center.svg';
import alignRightIcon from '../assets/icons/align-right.svg';
import alignJustifyIcon from '../assets/icons/align-justify.svg';
import backgroundIcon from '../assets/icons/background.svg';
import blockquoteIcon from '../assets/icons/blockquote.svg';
import boldIcon from '../assets/icons/bold.svg';
import cleanIcon from '../assets/icons/clean.svg';
import codeIcon from '../assets/icons/code.svg';
import colorIcon from '../assets/icons/color.svg';
import directionLeftToRightIcon from '../assets/icons/direction-ltr.svg';
import directionRightToLeftIcon from '../assets/icons/direction-rtl.svg';
import formulaIcon from '../assets/icons/formula.svg';
import headerIcon from '../assets/icons/header.svg';
import header2Icon from '../assets/icons/header-2.svg';
import italicIcon from '../assets/icons/italic.svg';
import imageIcon from '../assets/icons/image.svg';
import indentIcon from '../assets/icons/indent.svg';
import outdentIcon from '../assets/icons/outdent.svg';
import linkIcon from '../assets/icons/link.svg';
import listBulletIcon from '../assets/icons/list-bullet.svg';
import listCheckIcon from '../assets/icons/list-check.svg';
import listOrderedIcon from '../assets/icons/list-ordered.svg';
import subscriptIcon from '../assets/icons/subscript.svg';
import superscriptIcon from '../assets/icons/superscript.svg';
import strikeIcon from '../assets/icons/strike.svg';
import tableIcon from '../assets/icons/table.svg';
import underlineIcon from '../assets/icons/underline.svg';
import videoIcon from '../assets/icons/video.svg';
"use strict";
export default {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
const alignLeftIcon = "<svg viewbox=\"0 0 18 18\"><line class=\"ql-stroke\" x1=\"3\" x2=\"15\" y1=\"9\" y2=\"9\"/><line class=\"ql-stroke\" x1=\"3\" x2=\"13\" y1=\"14\" y2=\"14\"/><line class=\"ql-stroke\" x1=\"3\" x2=\"9\" y1=\"4\" y2=\"4\"/></svg>";
const alignCenterIcon = "<svg viewbox=\"0 0 18 18\"><line class=\"ql-stroke\" x1=\"15\" x2=\"3\" y1=\"9\" y2=\"9\"/><line class=\"ql-stroke\" x1=\"14\" x2=\"4\" y1=\"14\" y2=\"14\"/><line class=\"ql-stroke\" x1=\"12\" x2=\"6\" y1=\"4\" y2=\"4\"/></svg>";
const alignRightIcon = "<svg viewbox=\"0 0 18 18\"><line class=\"ql-stroke\" x1=\"15\" x2=\"3\" y1=\"9\" y2=\"9\"/><line class=\"ql-stroke\" x1=\"15\" x2=\"5\" y1=\"14\" y2=\"14\"/><line class=\"ql-stroke\" x1=\"15\" x2=\"9\" y1=\"4\" y2=\"4\"/></svg>";
const alignJustifyIcon = "<svg viewbox=\"0 0 18 18\"><line class=\"ql-stroke\" x1=\"15\" x2=\"3\" y1=\"9\" y2=\"9\"/><line class=\"ql-stroke\" x1=\"15\" x2=\"3\" y1=\"14\" y2=\"14\"/><line class=\"ql-stroke\" x1=\"15\" x2=\"3\" y1=\"4\" y2=\"4\"/></svg>";
const backgroundIcon = "<svg viewbox=\"0 0 18 18\"><g class=\"ql-fill ql-color-label\"><polygon points=\"6 6.868 6 6 5 6 5 7 5.942 7 6 6.868\"/><rect height=\"1\" width=\"1\" x=\"4\" y=\"4\"/><polygon points=\"6.817 5 6 5 6 6 6.38 6 6.817 5\"/><rect height=\"1\" width=\"1\" x=\"2\" y=\"6\"/><rect height=\"1\" width=\"1\" x=\"3\" y=\"5\"/><rect height=\"1\" width=\"1\" x=\"4\" y=\"7\"/><polygon points=\"4 11.439 4 11 3 11 3 12 3.755 12 4 11.439\"/><rect height=\"1\" width=\"1\" x=\"2\" y=\"12\"/><rect height=\"1\" width=\"1\" x=\"2\" y=\"9\"/><rect height=\"1\" width=\"1\" x=\"2\" y=\"15\"/><polygon points=\"4.63 10 4 10 4 11 4.192 11 4.63 10\"/><rect height=\"1\" width=\"1\" x=\"3\" y=\"8\"/><path d=\"M10.832,4.2L11,4.582V4H10.708A1.948,1.948,0,0,1,10.832,4.2Z\"/><path d=\"M7,4.582L7.168,4.2A1.929,1.929,0,0,1,7.292,4H7V4.582Z\"/><path d=\"M8,13H7.683l-0.351.8a1.933,1.933,0,0,1-.124.2H8V13Z\"/><rect height=\"1\" width=\"1\" x=\"12\" y=\"2\"/><rect height=\"1\" width=\"1\" x=\"11\" y=\"3\"/><path d=\"M9,3H8V3.282A1.985,1.985,0,0,1,9,3Z\"/><rect height=\"1\" width=\"1\" x=\"2\" y=\"3\"/><rect height=\"1\" width=\"1\" x=\"6\" y=\"2\"/><rect height=\"1\" width=\"1\" x=\"3\" y=\"2\"/><rect height=\"1\" width=\"1\" x=\"5\" y=\"3\"/><rect height=\"1\" width=\"1\" x=\"9\" y=\"2\"/><rect height=\"1\" width=\"1\" x=\"15\" y=\"14\"/><polygon points=\"13.447 10.174 13.469 10.225 13.472 10.232 13.808 11 14 11 14 10 13.37 10 13.447 10.174\"/><rect height=\"1\" width=\"1\" x=\"13\" y=\"7\"/><rect height=\"1\" width=\"1\" x=\"15\" y=\"5\"/><rect height=\"1\" width=\"1\" x=\"14\" y=\"6\"/><rect height=\"1\" width=\"1\" x=\"15\" y=\"8\"/><rect height=\"1\" width=\"1\" x=\"14\" y=\"9\"/><path d=\"M3.775,14H3v1H4V14.314A1.97,1.97,0,0,1,3.775,14Z\"/><rect height=\"1\" width=\"1\" x=\"14\" y=\"3\"/><polygon points=\"12 6.868 12 6 11.62 6 12 6.868\"/><rect height=\"1\" width=\"1\" x=\"15\" y=\"2\"/><rect height=\"1\" width=\"1\" x=\"12\" y=\"5\"/><rect height=\"1\" width=\"1\" x=\"13\" y=\"4\"/><polygon points=\"12.933 9 13 9 13 8 12.495 8 12.933 9\"/><rect height=\"1\" width=\"1\" x=\"9\" y=\"14\"/><rect height=\"1\" width=\"1\" x=\"8\" y=\"15\"/><path d=\"M6,14.926V15H7V14.316A1.993,1.993,0,0,1,6,14.926Z\"/><rect height=\"1\" width=\"1\" x=\"5\" y=\"15\"/><path d=\"M10.668,13.8L10.317,13H10v1h0.792A1.947,1.947,0,0,1,10.668,13.8Z\"/><rect height=\"1\" width=\"1\" x=\"11\" y=\"15\"/><path d=\"M14.332,12.2a1.99,1.99,0,0,1,.166.8H15V12H14.245Z\"/><rect height=\"1\" width=\"1\" x=\"14\" y=\"15\"/><rect height=\"1\" width=\"1\" x=\"15\" y=\"11\"/></g><polyline class=\"ql-stroke\" points=\"5.5 13 9 5 12.5 13\"/><line class=\"ql-stroke\" x1=\"11.63\" x2=\"6.38\" y1=\"11\" y2=\"11\"/></svg>";
const blockquoteIcon = "<svg viewbox=\"0 0 18 18\"><rect class=\"ql-fill ql-stroke\" height=\"3\" width=\"3\" x=\"4\" y=\"5\"/><rect class=\"ql-fill ql-stroke\" height=\"3\" width=\"3\" x=\"11\" y=\"5\"/><path class=\"ql-even ql-fill ql-stroke\" d=\"M7,8c0,4.031-3,5-3,5\"/><path class=\"ql-even ql-fill ql-stroke\" d=\"M14,8c0,4.031-3,5-3,5\"/></svg>";
const boldIcon = "<svg viewbox=\"0 0 18 18\"><path class=\"ql-stroke\" d=\"M5,4H9.5A2.5,2.5,0,0,1,12,6.5v0A2.5,2.5,0,0,1,9.5,9H5A0,0,0,0,1,5,9V4A0,0,0,0,1,5,4Z\"/><path class=\"ql-stroke\" d=\"M5,9h5.5A2.5,2.5,0,0,1,13,11.5v0A2.5,2.5,0,0,1,10.5,14H5a0,0,0,0,1,0,0V9A0,0,0,0,1,5,9Z\"/></svg>";
const cleanIcon = "<svg class=\"\" viewbox=\"0 0 18 18\"><line class=\"ql-stroke\" x1=\"5\" x2=\"13\" y1=\"3\" y2=\"3\"/><line class=\"ql-stroke\" x1=\"6\" x2=\"9.35\" y1=\"12\" y2=\"3\"/><line class=\"ql-stroke\" x1=\"11\" x2=\"15\" y1=\"11\" y2=\"15\"/><line class=\"ql-stroke\" x1=\"15\" x2=\"11\" y1=\"11\" y2=\"15\"/><rect class=\"ql-fill\" height=\"1\" rx=\"0.5\" ry=\"0.5\" width=\"7\" x=\"2\" y=\"14\"/></svg>";
const codeIcon = "<svg viewbox=\"0 0 18 18\"><polyline class=\"ql-even ql-stroke\" points=\"5 7 3 9 5 11\"/><polyline class=\"ql-even ql-stroke\" points=\"13 7 15 9 13 11\"/><line class=\"ql-stroke\" x1=\"10\" x2=\"8\" y1=\"5\" y2=\"13\"/></svg>";
const colorIcon = "<svg viewbox=\"0 0 18 18\"><line class=\"ql-color-label ql-stroke ql-transparent\" x1=\"3\" x2=\"15\" y1=\"15\" y2=\"15\"/><polyline class=\"ql-stroke\" points=\"5.5 11 9 3 12.5 11\"/><line class=\"ql-stroke\" x1=\"11.63\" x2=\"6.38\" y1=\"9\" y2=\"9\"/></svg>";
const directionLeftToRightIcon = "<svg viewbox=\"0 0 18 18\"><polygon class=\"ql-stroke ql-fill\" points=\"3 11 5 9 3 7 3 11\"/><line class=\"ql-stroke ql-fill\" x1=\"15\" x2=\"11\" y1=\"4\" y2=\"4\"/><path class=\"ql-fill\" d=\"M11,3a3,3,0,0,0,0,6h1V3H11Z\"/><rect class=\"ql-fill\" height=\"11\" width=\"1\" x=\"11\" y=\"4\"/><rect class=\"ql-fill\" height=\"11\" width=\"1\" x=\"13\" y=\"4\"/></svg>";
const directionRightToLeftIcon = "<svg viewbox=\"0 0 18 18\"><polygon class=\"ql-stroke ql-fill\" points=\"15 12 13 10 15 8 15 12\"/><line class=\"ql-stroke ql-fill\" x1=\"9\" x2=\"5\" y1=\"4\" y2=\"4\"/><path class=\"ql-fill\" d=\"M5,3A3,3,0,0,0,5,9H6V3H5Z\"/><rect class=\"ql-fill\" height=\"11\" width=\"1\" x=\"5\" y=\"4\"/><rect class=\"ql-fill\" height=\"11\" width=\"1\" x=\"7\" y=\"4\"/></svg>";
const formulaIcon = "<svg viewbox=\"0 0 18 18\"><path class=\"ql-fill\" d=\"M11.759,2.482a2.561,2.561,0,0,0-3.53.607A7.656,7.656,0,0,0,6.8,6.2C6.109,9.188,5.275,14.677,4.15,14.927a1.545,1.545,0,0,0-1.3-.933A0.922,0.922,0,0,0,2,15.036S1.954,16,4.119,16s3.091-2.691,3.7-5.553c0.177-.826.36-1.726,0.554-2.6L8.775,6.2c0.381-1.421.807-2.521,1.306-2.676a1.014,1.014,0,0,0,1.02.56A0.966,0.966,0,0,0,11.759,2.482Z\"/><rect class=\"ql-fill\" height=\"1.6\" rx=\"0.8\" ry=\"0.8\" width=\"5\" x=\"5.15\" y=\"6.2\"/><path class=\"ql-fill\" d=\"M13.663,12.027a1.662,1.662,0,0,1,.266-0.276q0.193,0.069.456,0.138a2.1,2.1,0,0,0,.535.069,1.075,1.075,0,0,0,.767-0.3,1.044,1.044,0,0,0,.314-0.8,0.84,0.84,0,0,0-.238-0.619,0.8,0.8,0,0,0-.594-0.239,1.154,1.154,0,0,0-.781.3,4.607,4.607,0,0,0-.781,1q-0.091.15-.218,0.346l-0.246.38c-0.068-.288-0.137-0.582-0.212-0.885-0.459-1.847-2.494-.984-2.941-0.8-0.482.2-.353,0.647-0.094,0.529a0.869,0.869,0,0,1,1.281.585c0.217,0.751.377,1.436,0.527,2.038a5.688,5.688,0,0,1-.362.467,2.69,2.69,0,0,1-.264.271q-0.221-.08-0.471-0.147a2.029,2.029,0,0,0-.522-0.066,1.079,1.079,0,0,0-.768.3A1.058,1.058,0,0,0,9,15.131a0.82,0.82,0,0,0,.832.852,1.134,1.134,0,0,0,.787-0.3,5.11,5.11,0,0,0,.776-0.993q0.141-.219.215-0.34c0.046-.076.122-0.194,0.223-0.346a2.786,2.786,0,0,0,.918,1.726,2.582,2.582,0,0,0,2.376-.185c0.317-.181.212-0.565,0-0.494A0.807,0.807,0,0,1,14.176,15a5.159,5.159,0,0,1-.913-2.446l0,0Q13.487,12.24,13.663,12.027Z\"/></svg>";
const headerIcon = "<svg viewBox=\"0 0 18 18\"><path class=\"ql-fill\" d=\"M10,4V14a1,1,0,0,1-2,0V10H3v4a1,1,0,0,1-2,0V4A1,1,0,0,1,3,4V8H8V4a1,1,0,0,1,2,0Zm6.06787,9.209H14.98975V7.59863a.54085.54085,0,0,0-.605-.60547h-.62744a1.01119,1.01119,0,0,0-.748.29688L11.645,8.56641a.5435.5435,0,0,0-.022.8584l.28613.30762a.53861.53861,0,0,0,.84717.0332l.09912-.08789a1.2137,1.2137,0,0,0,.2417-.35254h.02246s-.01123.30859-.01123.60547V13.209H12.041a.54085.54085,0,0,0-.605.60547v.43945a.54085.54085,0,0,0,.605.60547h4.02686a.54085.54085,0,0,0,.605-.60547v-.43945A.54085.54085,0,0,0,16.06787,13.209Z\"/></svg>";
const header2Icon = "<svg viewBox=\"0 0 18 18\"><path class=\"ql-fill\" d=\"M16.73975,13.81445v.43945a.54085.54085,0,0,1-.605.60547H11.855a.58392.58392,0,0,1-.64893-.60547V14.0127c0-2.90527,3.39941-3.42187,3.39941-4.55469a.77675.77675,0,0,0-.84717-.78125,1.17684,1.17684,0,0,0-.83594.38477c-.2749.26367-.561.374-.85791.13184l-.4292-.34082c-.30811-.24219-.38525-.51758-.1543-.81445a2.97155,2.97155,0,0,1,2.45361-1.17676,2.45393,2.45393,0,0,1,2.68408,2.40918c0,2.45312-3.1792,2.92676-3.27832,3.93848h2.79443A.54085.54085,0,0,1,16.73975,13.81445ZM9,3A.99974.99974,0,0,0,8,4V8H3V4A1,1,0,0,0,1,4V14a1,1,0,0,0,2,0V10H8v4a1,1,0,0,0,2,0V4A.99974.99974,0,0,0,9,3Z\"/></svg>";
const italicIcon = "<svg viewbox=\"0 0 18 18\"><line class=\"ql-stroke\" x1=\"7\" x2=\"13\" y1=\"4\" y2=\"4\"/><line class=\"ql-stroke\" x1=\"5\" x2=\"11\" y1=\"14\" y2=\"14\"/><line class=\"ql-stroke\" x1=\"8\" x2=\"10\" y1=\"14\" y2=\"4\"/></svg>";
const imageIcon = "<svg viewbox=\"0 0 18 18\"><rect class=\"ql-stroke\" height=\"10\" width=\"12\" x=\"3\" y=\"4\"/><circle class=\"ql-fill\" cx=\"6\" cy=\"7\" r=\"1\"/><polyline class=\"ql-even ql-fill\" points=\"5 12 5 11 7 9 8 10 11 7 13 9 13 12 5 12\"/></svg>";
const indentIcon = "<svg viewbox=\"0 0 18 18\"><line class=\"ql-stroke\" x1=\"3\" x2=\"15\" y1=\"14\" y2=\"14\"/><line class=\"ql-stroke\" x1=\"3\" x2=\"15\" y1=\"4\" y2=\"4\"/><line class=\"ql-stroke\" x1=\"9\" x2=\"15\" y1=\"9\" y2=\"9\"/><polyline class=\"ql-fill ql-stroke\" points=\"3 7 3 11 5 9 3 7\"/></svg>";
const outdentIcon = "<svg viewbox=\"0 0 18 18\"><line class=\"ql-stroke\" x1=\"3\" x2=\"15\" y1=\"14\" y2=\"14\"/><line class=\"ql-stroke\" x1=\"3\" x2=\"15\" y1=\"4\" y2=\"4\"/><line class=\"ql-stroke\" x1=\"9\" x2=\"15\" y1=\"9\" y2=\"9\"/><polyline class=\"ql-stroke\" points=\"5 7 5 11 3 9 5 7\"/></svg>";
const linkIcon = "<svg viewbox=\"0 0 18 18\"><line class=\"ql-stroke\" x1=\"7\" x2=\"11\" y1=\"7\" y2=\"11\"/><path class=\"ql-even ql-stroke\" d=\"M8.9,4.577a3.476,3.476,0,0,1,.36,4.679A3.476,3.476,0,0,1,4.577,8.9C3.185,7.5,2.035,6.4,4.217,4.217S7.5,3.185,8.9,4.577Z\"/><path class=\"ql-even ql-stroke\" d=\"M13.423,9.1a3.476,3.476,0,0,0-4.679-.36,3.476,3.476,0,0,0,.36,4.679c1.392,1.392,2.5,2.542,4.679.36S14.815,10.5,13.423,9.1Z\"/></svg>";
const listBulletIcon = "<svg viewbox=\"0 0 18 18\"><line class=\"ql-stroke\" x1=\"6\" x2=\"15\" y1=\"4\" y2=\"4\"/><line class=\"ql-stroke\" x1=\"6\" x2=\"15\" y1=\"9\" y2=\"9\"/><line class=\"ql-stroke\" x1=\"6\" x2=\"15\" y1=\"14\" y2=\"14\"/><line class=\"ql-stroke\" x1=\"3\" x2=\"3\" y1=\"4\" y2=\"4\"/><line class=\"ql-stroke\" x1=\"3\" x2=\"3\" y1=\"9\" y2=\"9\"/><line class=\"ql-stroke\" x1=\"3\" x2=\"3\" y1=\"14\" y2=\"14\"/></svg>";
const listCheckIcon = "<svg class=\"\" viewbox=\"0 0 18 18\"><line class=\"ql-stroke\" x1=\"9\" x2=\"15\" y1=\"4\" y2=\"4\"/><polyline class=\"ql-stroke\" points=\"3 4 4 5 6 3\"/><line class=\"ql-stroke\" x1=\"9\" x2=\"15\" y1=\"14\" y2=\"14\"/><polyline class=\"ql-stroke\" points=\"3 14 4 15 6 13\"/><line class=\"ql-stroke\" x1=\"9\" x2=\"15\" y1=\"9\" y2=\"9\"/><polyline class=\"ql-stroke\" points=\"3 9 4 10 6 8\"/></svg>";
const listOrderedIcon = "<svg viewbox=\"0 0 18 18\"><line class=\"ql-stroke\" x1=\"7\" x2=\"15\" y1=\"4\" y2=\"4\"/><line class=\"ql-stroke\" x1=\"7\" x2=\"15\" y1=\"9\" y2=\"9\"/><line class=\"ql-stroke\" x1=\"7\" x2=\"15\" y1=\"14\" y2=\"14\"/><line class=\"ql-stroke ql-thin\" x1=\"2.5\" x2=\"4.5\" y1=\"5.5\" y2=\"5.5\"/><path class=\"ql-fill\" d=\"M3.5,6A0.5,0.5,0,0,1,3,5.5V3.085l-0.276.138A0.5,0.5,0,0,1,2.053,3c-0.124-.247-0.023-0.324.224-0.447l1-.5A0.5,0.5,0,0,1,4,2.5v3A0.5,0.5,0,0,1,3.5,6Z\"/><path class=\"ql-stroke ql-thin\" d=\"M4.5,10.5h-2c0-.234,1.85-1.076,1.85-2.234A0.959,0.959,0,0,0,2.5,8.156\"/><path class=\"ql-stroke ql-thin\" d=\"M2.5,14.846a0.959,0.959,0,0,0,1.85-.109A0.7,0.7,0,0,0,3.75,14a0.688,0.688,0,0,0,.6-0.736,0.959,0.959,0,0,0-1.85-.109\"/></svg>";
const subscriptIcon = "<svg viewbox=\"0 0 18 18\"><path class=\"ql-fill\" d=\"M15.5,15H13.861a3.858,3.858,0,0,0,1.914-2.975,1.8,1.8,0,0,0-1.6-1.751A1.921,1.921,0,0,0,12.021,11.7a0.50013,0.50013,0,1,0,.957.291h0a0.914,0.914,0,0,1,1.053-.725,0.81,0.81,0,0,1,.744.762c0,1.076-1.16971,1.86982-1.93971,2.43082A1.45639,1.45639,0,0,0,12,15.5a0.5,0.5,0,0,0,.5.5h3A0.5,0.5,0,0,0,15.5,15Z\"/><path class=\"ql-fill\" d=\"M9.65,5.241a1,1,0,0,0-1.409.108L6,7.964,3.759,5.349A1,1,0,0,0,2.192,6.59178Q2.21541,6.6213,2.241,6.649L4.684,9.5,2.241,12.35A1,1,0,0,0,3.71,13.70722q0.02557-.02768.049-0.05722L6,11.036,8.241,13.65a1,1,0,1,0,1.567-1.24277Q9.78459,12.3777,9.759,12.35L7.316,9.5,9.759,6.651A1,1,0,0,0,9.65,5.241Z\"/></svg>";
const superscriptIcon = "<svg viewbox=\"0 0 18 18\"><path class=\"ql-fill\" d=\"M15.5,7H13.861a4.015,4.015,0,0,0,1.914-2.975,1.8,1.8,0,0,0-1.6-1.751A1.922,1.922,0,0,0,12.021,3.7a0.5,0.5,0,1,0,.957.291,0.917,0.917,0,0,1,1.053-.725,0.81,0.81,0,0,1,.744.762c0,1.077-1.164,1.925-1.934,2.486A1.423,1.423,0,0,0,12,7.5a0.5,0.5,0,0,0,.5.5h3A0.5,0.5,0,0,0,15.5,7Z\"/><path class=\"ql-fill\" d=\"M9.651,5.241a1,1,0,0,0-1.41.108L6,7.964,3.759,5.349a1,1,0,1,0-1.519,1.3L4.683,9.5,2.241,12.35a1,1,0,1,0,1.519,1.3L6,11.036,8.241,13.65a1,1,0,0,0,1.519-1.3L7.317,9.5,9.759,6.651A1,1,0,0,0,9.651,5.241Z\"/></svg>";
const strikeIcon = "<svg viewbox=\"0 0 18 18\"><line class=\"ql-stroke ql-thin\" x1=\"15.5\" x2=\"2.5\" y1=\"8.5\" y2=\"9.5\"/><path class=\"ql-fill\" d=\"M9.007,8C6.542,7.791,6,7.519,6,6.5,6,5.792,7.283,5,9,5c1.571,0,2.765.679,2.969,1.309a1,1,0,0,0,1.9-.617C13.356,4.106,11.354,3,9,3,6.2,3,4,4.538,4,6.5a3.2,3.2,0,0,0,.5,1.843Z\"/><path class=\"ql-fill\" d=\"M8.984,10C11.457,10.208,12,10.479,12,11.5c0,0.708-1.283,1.5-3,1.5-1.571,0-2.765-.679-2.969-1.309a1,1,0,1,0-1.9.617C4.644,13.894,6.646,15,9,15c2.8,0,5-1.538,5-3.5a3.2,3.2,0,0,0-.5-1.843Z\"/></svg>";
const tableIcon = "<svg viewbox=\"0 0 18 18\"><rect class=\"ql-stroke\" height=\"12\" width=\"12\" x=\"3\" y=\"3\"/><rect class=\"ql-fill\" height=\"2\" width=\"3\" x=\"5\" y=\"5\"/><rect class=\"ql-fill\" height=\"2\" width=\"4\" x=\"9\" y=\"5\"/><g class=\"ql-fill ql-transparent\"><rect height=\"2\" width=\"3\" x=\"5\" y=\"8\"/><rect height=\"2\" width=\"4\" x=\"9\" y=\"8\"/><rect height=\"2\" width=\"3\" x=\"5\" y=\"11\"/><rect height=\"2\" width=\"4\" x=\"9\" y=\"11\"/></g></svg>";
const underlineIcon = "<svg viewbox=\"0 0 18 18\"><path class=\"ql-stroke\" d=\"M5,3V9a4.012,4.012,0,0,0,4,4H9a4.012,4.012,0,0,0,4-4V3\"/><rect class=\"ql-fill\" height=\"1\" rx=\"0.5\" ry=\"0.5\" width=\"12\" x=\"3\" y=\"15\"/></svg>";
const videoIcon = "<svg viewbox=\"0 0 18 18\"><rect class=\"ql-stroke\" height=\"12\" width=\"12\" x=\"3\" y=\"3\"/><rect class=\"ql-fill\" height=\"12\" width=\"1\" x=\"5\" y=\"3\"/><rect class=\"ql-fill\" height=\"12\" width=\"1\" x=\"12\" y=\"3\"/><rect class=\"ql-fill\" height=\"2\" width=\"8\" x=\"5\" y=\"8\"/><rect class=\"ql-fill\" height=\"1\" width=\"3\" x=\"3\" y=\"5\"/><rect class=\"ql-fill\" height=\"1\" width=\"3\" x=\"3\" y=\"7\"/><rect class=\"ql-fill\" height=\"1\" width=\"3\" x=\"3\" y=\"10\"/><rect class=\"ql-fill\" height=\"1\" width=\"3\" x=\"3\" y=\"12\"/><rect class=\"ql-fill\" height=\"1\" width=\"3\" x=\"12\" y=\"5\"/><rect class=\"ql-fill\" height=\"1\" width=\"3\" x=\"12\" y=\"7\"/><rect class=\"ql-fill\" height=\"1\" width=\"3\" x=\"12\" y=\"10\"/><rect class=\"ql-fill\" height=\"1\" width=\"3\" x=\"12\" y=\"12\"/></svg>";
var _default = exports.default = {
align: {

@@ -36,3 +41,3 @@ '': alignLeftIcon,

right: alignRightIcon,
justify: alignJustifyIcon,
justify: alignJustifyIcon
},

@@ -48,3 +53,3 @@ background: backgroundIcon,

'': directionLeftToRightIcon,
rtl: directionRightToLeftIcon,
rtl: directionRightToLeftIcon
},

@@ -54,3 +59,3 @@ formula: formulaIcon,

'1': headerIcon,
'2': header2Icon,
'2': header2Icon
},

@@ -61,3 +66,3 @@ italic: italicIcon,

'+1': indentIcon,
'-1': outdentIcon,
'-1': outdentIcon
},

@@ -68,7 +73,7 @@ link: linkIcon,

check: listCheckIcon,
ordered: listOrderedIcon,
ordered: listOrderedIcon
},
script: {
sub: subscriptIcon,
super: superscriptIcon,
super: superscriptIcon
},

@@ -78,3 +83,4 @@ strike: strikeIcon,

underline: underlineIcon,
video: videoIcon,
video: videoIcon
};
//# sourceMappingURL=icons.js.map

@@ -1,12 +0,12 @@

import DropdownIcon from '../assets/icons/dropdown.svg';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
const DropdownIcon = "<svg viewbox=\"0 0 18 18\"><polygon class=\"ql-stroke\" points=\"7 11 9 13 11 11 7 11\"/><polygon class=\"ql-stroke\" points=\"7 7 9 5 11 7 7 7\"/></svg>";
let optionsCounter = 0;
function toggleAriaAttribute(element, attribute) {
element.setAttribute(
attribute,
!(element.getAttribute(attribute) === 'true'),
);
element.setAttribute(attribute, `${!(element.getAttribute(attribute) === 'true')}`);
}
class Picker {

@@ -18,4 +18,4 @@ constructor(select) {

this.select.style.display = 'none';
// @ts-expect-error Fix me later
this.select.parentNode.insertBefore(this.container, this.select);
this.label.addEventListener('mousedown', () => {

@@ -38,3 +38,2 @@ this.togglePicker();

}
togglePicker() {

@@ -44,12 +43,14 @@ this.container.classList.toggle('ql-expanded');

toggleAriaAttribute(this.label, 'aria-expanded');
// @ts-expect-error
toggleAriaAttribute(this.options, 'aria-hidden');
}
buildItem(option) {
const item = document.createElement('span');
// @ts-expect-error
item.tabIndex = '0';
item.setAttribute('role', 'button');
item.classList.add('ql-picker-item');
if (option.hasAttribute('value')) {
item.setAttribute('data-value', option.getAttribute('value'));
const value = option.getAttribute('value');
if (value) {
item.setAttribute('data-value', value);
}

@@ -75,6 +76,4 @@ if (option.textContent) {

});
return item;
}
buildLabel() {

@@ -84,2 +83,3 @@ const label = document.createElement('span');

label.innerHTML = DropdownIcon;
// @ts-expect-error
label.tabIndex = '0';

@@ -91,3 +91,2 @@ label.setAttribute('role', 'button');

}
buildOptions() {

@@ -99,2 +98,3 @@ const options = document.createElement('span');

options.setAttribute('aria-hidden', 'true');
// @ts-expect-error
options.tabIndex = '-1';

@@ -107,4 +107,4 @@

// @ts-expect-error
this.options = options;
Array.from(this.select.options).forEach(option => {

@@ -119,3 +119,2 @@ const item = this.buildItem(option);

}
buildPicker() {

@@ -129,3 +128,2 @@ Array.from(this.select.attributes).forEach(item => {

}
escape() {

@@ -138,10 +136,10 @@ // Close menu and return focus to trigger label

}
close() {
this.container.classList.remove('ql-expanded');
this.label.setAttribute('aria-expanded', 'false');
// @ts-expect-error
this.options.setAttribute('aria-hidden', 'true');
}
selectItem(item, trigger = false) {
selectItem(item) {
let trigger = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
const selected = this.container.querySelector('.ql-selected');

@@ -154,6 +152,6 @@ if (item === selected) return;

item.classList.add('ql-selected');
this.select.selectedIndex = Array.from(item.parentNode.children).indexOf(
item,
);
// @ts-expect-error Fix me later
this.select.selectedIndex = Array.from(item.parentNode.children).indexOf(item);
if (item.hasAttribute('data-value')) {
// @ts-expect-error Fix me later
this.label.setAttribute('data-value', item.getAttribute('data-value'));

@@ -164,2 +162,3 @@ } else {

if (item.hasAttribute('data-label')) {
// @ts-expect-error Fix me later
this.label.setAttribute('data-label', item.getAttribute('data-label'));

@@ -174,10 +173,10 @@ } else {

}
update() {
let option;
if (this.select.selectedIndex > -1) {
const item = this.container.querySelector('.ql-picker-options').children[
this.select.selectedIndex
];
const item =
// @ts-expect-error Fix me later
this.container.querySelector('.ql-picker-options').children[this.select.selectedIndex];
option = this.select.options[this.select.selectedIndex];
// @ts-expect-error
this.selectItem(item);

@@ -187,9 +186,7 @@ } else {

}
const isActive =
option != null &&
option !== this.select.querySelector('option[selected]');
const isActive = option != null && option !== this.select.querySelector('option[selected]');
this.label.classList.toggle('ql-active', isActive);
}
}
export default Picker;
var _default = exports.default = Picker;
//# sourceMappingURL=picker.js.map

@@ -0,1 +1,13 @@

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
const isScrollable = el => {
const {
overflowY
} = getComputedStyle(el, null);
return overflowY !== 'visible' && overflowY !== 'clip';
};
class Tooltip {

@@ -6,4 +18,5 @@ constructor(quill, boundsContainer) {

this.root = quill.addContainer('ql-tooltip');
// @ts-expect-error
this.root.innerHTML = this.constructor.TEMPLATE;
if (this.quill.root === this.quill.scrollingContainer) {
if (isScrollable(this.quill.root)) {
this.quill.root.addEventListener('scroll', () => {

@@ -15,10 +28,7 @@ this.root.style.marginTop = `${-1 * this.quill.root.scrollTop}px`;

}
hide() {
this.root.classList.add('ql-hidden');
}
position(reference) {
const left =
reference.left + reference.width / 2 - this.root.offsetWidth / 2;
const left = reference.left + reference.width / 2 - this.root.offsetWidth / 2;
// root.scrollTop should be 0 if scrollContainer !== root

@@ -48,3 +58,2 @@ const top = reference.bottom + this.quill.root.scrollTop;

}
show() {

@@ -55,3 +64,3 @@ this.root.classList.remove('ql-editing');

}
export default Tooltip;
var _default = exports.default = Tooltip;
//# sourceMappingURL=tooltip.js.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc