Latest repo

This commit is contained in:
Marc
2025-06-02 16:42:16 +00:00
parent 53ddf1a329
commit cde5fae175
27907 changed files with 3875388 additions and 1 deletions

7
node_modules/quill-delta/.travis.yml generated vendored Normal file
View File

@@ -0,0 +1,7 @@
language: node_js
node_js: '6'
script:
- npm test
after_success:
- npm run test:coverage
- npm run test:coverage:report

60
node_modules/quill-delta/CHANGELOG.md generated vendored Normal file
View File

@@ -0,0 +1,60 @@
## v3.6.3
- Performance optimization for `compose`
## v3.6.2
- Documentation fixes
## v3.6.1
- Stop using `=>` because of IE11
## v3.6.0
- Add experimental method `changeLength()`
## v3.5.0
- Add counter and early return to `eachLine()`
## v3.4.0
- Support index suggestion in `diff()`
## v3.3.0
- Add `partition()`
## v3.2.0
- Add `eachLine()`, `map()`, `reduce()`, `filter()`, `forEach()`
## v3.1.0
- Pull out quilljs/delta from ottypes/rich-text
## v3.0.0
#### Breaking Changes
- Deep copy and compare attributes and deltas
## v2.1.0
- Add `concat()` method for document Deltas
## v2.0.0
#### Breaking Changes
- `compose()` returns a new Delta instead of self-modifying
#### Features
- Support embed being any non-string type

21
node_modules/quill-delta/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014 Jason Chen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

639
node_modules/quill-delta/README.md generated vendored Normal file
View File

@@ -0,0 +1,639 @@
# Delta [![Build Status](https://travis-ci.org/quilljs/delta.svg?branch=master)](http://travis-ci.org/quilljs/delta) [![Coverage Status](https://img.shields.io/coveralls/quilljs/delta.svg)](https://coveralls.io/r/quilljs/delta)
Deltas are a simple, yet expressive format that can be used to describe contents and changes. The format is JSON based, and is human readable, yet easily parsible by machines. Deltas can describe any rich text document, includes all text and formatting information, without the ambiguity and complexity of HTML.
A Delta is made up of an [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) of Operations, which describe changes to a document. They can be an [`insert`](#insert-operation), [`delete`](#delete-operation) or [`retain`](#retain-operation). Note operations do not take an index. They always describe the change at the current index. Use retains to "keep" or "skip" certain parts of the document.
Dont be confused by its name Delta—Deltas represents both documents and changes to documents. If you think of Deltas as the instructions from going from one document to another, the way Deltas represent a document is by expressing the instructions starting from an empty document.
## Quick Example
```js
// Document with text "Gandalf the Grey"
// with "Gandalf" bolded, and "Grey" in grey
var delta = new Delta([
{ insert: 'Gandalf', attributes: { bold: true } },
{ insert: ' the ' },
{ insert: 'Grey', attributes: { color: '#ccc' } }
]);
// Change intended to be applied to above:
// Keep the first 12 characters, delete the next 4,
// and insert a white 'White'
var death = new Delta().retain(12)
.delete(4)
.insert('White', { color: '#fff' });
// {
// ops: [
// { retain: 12 },
// { delete: 4 },
// { insert: 'White', attributes: { color: '#fff' } }
// ]
// }
// Applying the above:
var restored = delta.compose(death);
// {
// ops: [
// { insert: 'Gandalf ', attributes: { bold: true } },
// { insert: 'the ' },
// { insert: 'White', attributes: { color: '#fff' } }
// ]
// }
```
This README describes Deltas in its general form and API functionality. Additional information on the way Quill specifically uses Deltas can be found on its own [Delta docs](http://quilljs.com/docs/delta/). A walkthough of the motivation and design thinking behind Deltas are on [Designing the Delta Format](http://quilljs.com/guides/designing-the-delta-format/).
This format is suitable for [Operational Transform](https://en.wikipedia.org/wiki/Operational_transformation) and defines several functions to support this use case.
## Contents
#### Operations
- [`insert`](#insert-operation)
- [`delete`](#delete-operation)
- [`retain`](#retain-operation)
#### Construction
- [`constructor`](#constructor)
- [`insert`](#insert)
- [`delete`](#delete)
- [`retain`](#retain)
#### Documents
These methods called on or with non-document Deltas will result in undefined behavior.
- [`concat`](#concat)
- [`diff`](#diff)
- [`eachLine`](#eachline)
#### Utility
- [`filter`](#filter)
- [`forEach`](#foreach)
- [`length`](#length)
- [`map`](#map)
- [`partition`](#partition)
- [`reduce`](#reduce)
- [`slice`](#slice)
#### Operational Transform
- [`compose`](#compose)
- [`transform`](#transform)
- [`transformPosition`](#transformposition)
## Operations
### Insert Operation
Insert operations have an `insert` key defined. A String value represents inserting text. Any other type represents inserting an embed (however only one level of object comparison will be performed for equality).
In both cases of text and embeds, an optional `attributes` key can be defined with an Object to describe additonal formatting information. Formats can be changed by the [retain](#retain) operation.
```js
// Insert a bolded "Text"
{ insert: "Text", attributes: { bold: true } }
// Insert a link
{ insert: "Google", attributes: { link: 'https://www.google.com' } }
// Insert an embed
{
insert: { image: 'https://octodex.github.com/images/labtocat.png' },
attributes: { alt: "Lab Octocat" }
}
// Insert another embed
{
insert: { video: 'https://www.youtube.com/watch?v=dMH0bHeiRNg' },
attributes: {
width: 420,
height: 315
}
}
```
### Delete Operation
Delete operations have a Number `delete` key defined representing the number of characters to delete. All embeds have a length of 1.
```js
// Delete the next 10 characters
{ delete: 10 }
```
### Retain Operation
Retain operations have a Number `retain` key defined representing the number of characters to keep (other libraries might use the name keep or skip). An optional `attributes` key can be defined with an Object to describe formatting changes to the character range. A value of `null` in the `attributes` Object represents removal of that key.
*Note: It is not necessary to retain the last characters of a document as this is implied.*
```js
// Keep the next 5 characters
{ retain: 5 }
// Keep and bold the next 5 characters
{ retain: 5, attributes: { bold: true } }
// Keep and unbold the next 5 characters
// More specifically, remove the bold key in the attributes Object
// in the next 5 characters
{ retain: 5, attributes: { bold: null } }
```
## Construction
### constructor
Creates a new Delta object.
#### Methods
- `new Delta()`
- `new Delta(ops)`
- `new Delta(delta)`
#### Parameters
- `ops` - Array of operations
- `delta` - Object with an `ops` key set to an array of operations
*Note: No validity/sanity check is performed when constructed with ops or delta. The new delta's internal ops array will also be assigned from ops or delta.ops without deep copying.*
#### Example
```js
var delta = new Delta([
{ insert: 'Hello World' },
{ insert: '!', attributes: { bold: true }}
]);
var packet = JSON.stringify(delta);
var other = new Delta(JSON.parse(packet));
var chained = new Delta().insert('Hello World').insert('!', { bold: true });
```
---
### insert()
Appends an insert operation. Returns `this` for chainability.
#### Methods
- `insert(text, attributes)`
- `insert(embed, attributes)`
#### Parameters
- `text` - String representing text to insert
- `embed` - Object representing embed type to insert
- `attributes` - Optional attributes to apply
#### Example
```js
delta.insert('Text', { bold: true, color: '#ccc' });
delta.insert({ image: 'https://octodex.github.com/images/labtocat.png' });
```
---
### delete()
Appends a delete operation. Returns `this` for chainability.
#### Methods
- `delete(length)`
#### Parameters
- `length` - Number of characters to delete
#### Example
```js
delta.delete(5);
```
---
### retain()
Appends a retain operation. Returns `this` for chainability.
#### Methods
- `retain(length, attributes)`
#### Parameters
- `length` - Number of characters to retain
- `attributes` - Optional attributes to apply
#### Example
```js
delta.retain(4).retain(5, { color: '#0c6' });
```
## Documents
### concat()
Returns a new Delta representing the concatenation of this and another document Delta's operations.
#### Methods
- `concat(other)`
#### Parameters
- `other` - Document Delta to concatenate
#### Returns
- `Delta` - Concatenated document Delta
#### Example
```js
var a = new Delta().insert('Hello');
var b = new Delta().insert('!', { bold: true });
// {
// ops: [
// { insert: 'Hello' },
// { insert: '!', attributes: { bold: true } }
// ]
// }
var concat = a.concat(b);
```
---
### diff()
Returns a Delta representing the difference between two documents. Optionally, accepts a suggested index where change took place, often representing a cursor position *before* change.
#### Methods
- `diff(other)`
- `diff(other, index)`
#### Parameters
- `other` - Document Delta to diff against
- `index` - Suggested index where change took place
#### Returns
- `Delta` - difference between the two documents
#### Example
```js
var a = new Delta().insert('Hello');
var b = new Delta().insert('Hello!');
var diff = a.diff(b); // { ops: [{ retain: 5 }, { insert: '!' }] }
// a.compose(diff) == b
```
---
### eachLine()
Iterates through document Delta, calling a given function with a Delta and attributes object, representing the line segment.
#### Methods
- `eachLine(predicate, newline)`
#### Parameters
- `predicate` - function to call on each line group
- `newline` - newline character, defaults to `\n`
#### Example
```js
var delta = new Delta().insert('Hello\n\n')
.insert('World')
.insert({ image: 'octocat.png' })
.insert('\n', { align: 'right' })
.insert('!');
delta.eachLine(function(line, attributes, i) {
console.log(line, attributes, i);
// Can return false to exit loop early
});
// Should log:
// { ops: [{ insert: 'Hello' }] }, {}, 0
// { ops: [] }, {}, 1
// { ops: [{ insert: 'World' }, { insert: { image: 'octocat.png' } }] }, { align: 'right' }, 2
// { ops: [{ insert: '!' }] }, {}, 3
```
## Utility
### filter()
Returns an array of operations that passes a given function.
#### Methods
- `filter(predicate)`
#### Parameters
- `predicate` - Function to test each operation against. Return `true` to keep the operation, `false` otherwise.
#### Returns
- `Array` - Filtered resulting array
#### Example
```js
var delta = new Delta().insert('Hello', { bold: true })
.insert({ image: 'https://octodex.github.com/images/labtocat.png' })
.insert('World!');
var text = delta.filter(function(op) {
return typeof op.insert === 'string';
}).map(function(op) {
return op.insert;
}).join('');
```
---
### forEach()
Iterates through operations, calling the provided function for each operation.
#### Methods
- `forEach(predicate)`
#### Parameters
- `predicate` - Function to call during iteration, passing in the current operation.
#### Example
```js
delta.forEach(function(op) {
console.log(op);
});
```
---
### length()
Returns length of a Delta, which is the sum of the lengths of its operations.
#### Methods
- `length()`
#### Example
```js
new Delta().insert('Hello').length(); // Returns 5
new Delta().insert('A').retain(2).delete(1) // Returns 4
```
---
### map()
Returns a new array with the results of calling provided function on each operation.
#### Methods
- `map(predicate)`
#### Parameters
- `predicate` - Function to call, passing in the current operation, returning an element of the new array to be returned
#### Returns
- `Array` - A new array with each element being the result of the given function.
#### Example
```js
var delta = new Delta().insert('Hello', { bold: true })
.insert({ image: 'https://octodex.github.com/images/labtocat.png' })
.insert('World!');
var text = delta.map(function(op) {
if (typeof op.insert === 'string') {
return op.insert;
} else {
return '';
}
}).join('');
```
---
### partition()
Create an array of two arrays, the first with operations that pass the given function, the other that failed.
#### Methods
- `partition(predicate)`
#### Parameters
- `predicate` - Function to call, passing in the current operation, returning whether that operation passed
#### Returns
- `Array` - A new array of two Arrays, the first with passed operations, the other with failed operations
#### Example
```js
var delta = new Delta().insert('Hello', { bold: true })
.insert({ image: 'https://octodex.github.com/images/labtocat.png' })
.insert('World!');
var results = delta.partition(function(op) {
return typeof op.insert === 'string';
});
var passed = results[0]; // [{ insert: 'Hello', attributes: { bold: true }},
// { insert: 'World'}]
var failed = results[1]; // [{ insert: { image: 'https://octodex.github.com/images/labtocat.png' }}]
```
---
### reduce()
Applies given function against an accumulator and each operation to reduce to a single value.
#### Methods
- `reduce(predicate, initialValue)`
#### Parameters
- `predicate` - Function to call per iteration, returning an accumulated value
- `initialValue` - Initial value to pass to first call to predicate
#### Returns
- `any` - the accumulated value
#### Example
```js
var delta = new Delta().insert('Hello', { bold: true })
.insert({ image: 'https://octodex.github.com/images/labtocat.png' })
.insert('World!');
var length = delta.reduce(function(length, op) {
return length + (op.insert.length || 1);
}, 0);
```
---
### slice()
Returns copy of delta with subset of operations.
#### Methods
- `slice()`
- `slice(start)`
- `slice(start, end)`
#### Parameters
- `start` - Start index of subset, defaults to 0
- `end` - End index of subset, defaults to rest of operations
#### Example
```js
var delta = new Delta().insert('Hello', { bold: true }).insert(' World');
// {
// ops: [
// { insert: 'Hello', attributes: { bold: true } },
// { insert: ' World' }
// ]
// }
var copy = delta.slice();
// { ops: [{ insert: 'World' }] }
var world = delta.slice(6);
// { ops: [{ insert: ' ' }] }
var space = delta.slice(5, 6);
```
## Operational Transform
### compose()
Returns a Delta that is equivalent to applying the operations of own Delta, followed by another Delta.
#### Methods
- `compose(other)`
#### Parameters
- `other` - Delta to compose
#### Example
```js
var a = new Delta().insert('abc');
var b = new Delta().retain(1).delete(1);
var composed = a.compose(b); // composed == new Delta().insert('ac');
```
---
### transform()
Transform given Delta against own operations.
#### Methods
- `transform(other, priority = false)`
- `transform(index, priority = false)` - Alias for [`transformPosition`](#tranformposition)
#### Parameters
- `other` - Delta to transform
- `priority` - Boolean used to break ties. If `true`, then `this` takes priority
over `other`, that is, its actions are considered to happen "first."
#### Returns
- `Delta` - transformed Delta
#### Example
```js
var a = new Delta().insert('a');
var b = new Delta().insert('b').retain(5).insert('c');
a.transform(b, true); // new Delta().retain(1).insert('b').retain(5).insert('c');
a.transform(b, false); // new Delta().insert('b').retain(6).insert('c');
```
---
### transformPosition()
Transform an index against the delta. Useful for representing cursor/selection positions.
#### Methods
- `transformPosition(index, priority = false)`
#### Parameters
- `index` - index to transform
#### Returns
- `Number` - transformed index
#### Example
```js
var delta = new Delta().retain(5).insert('a');
delta.transformPosition(4); // 4
delta.transformPosition(5); // 6
```

344
node_modules/quill-delta/lib/delta.js generated vendored Normal file
View File

@@ -0,0 +1,344 @@
var diff = require('fast-diff');
var equal = require('deep-equal');
var extend = require('extend');
var op = require('./op');
var NULL_CHARACTER = String.fromCharCode(0); // Placeholder char for embed in diff()
var Delta = function (ops) {
// Assume we are given a well formed ops
if (Array.isArray(ops)) {
this.ops = ops;
} else if (ops != null && Array.isArray(ops.ops)) {
this.ops = ops.ops;
} else {
this.ops = [];
}
};
Delta.prototype.insert = function (text, attributes) {
var newOp = {};
if (text.length === 0) return this;
newOp.insert = text;
if (attributes != null && typeof attributes === 'object' && Object.keys(attributes).length > 0) {
newOp.attributes = attributes;
}
return this.push(newOp);
};
Delta.prototype['delete'] = function (length) {
if (length <= 0) return this;
return this.push({ 'delete': length });
};
Delta.prototype.retain = function (length, attributes) {
if (length <= 0) return this;
var newOp = { retain: length };
if (attributes != null && typeof attributes === 'object' && Object.keys(attributes).length > 0) {
newOp.attributes = attributes;
}
return this.push(newOp);
};
Delta.prototype.push = function (newOp) {
var index = this.ops.length;
var lastOp = this.ops[index - 1];
newOp = extend(true, {}, newOp);
if (typeof lastOp === 'object') {
if (typeof newOp['delete'] === 'number' && typeof lastOp['delete'] === 'number') {
this.ops[index - 1] = { 'delete': lastOp['delete'] + newOp['delete'] };
return this;
}
// Since it does not matter if we insert before or after deleting at the same index,
// always prefer to insert first
if (typeof lastOp['delete'] === 'number' && newOp.insert != null) {
index -= 1;
lastOp = this.ops[index - 1];
if (typeof lastOp !== 'object') {
this.ops.unshift(newOp);
return this;
}
}
if (equal(newOp.attributes, lastOp.attributes)) {
if (typeof newOp.insert === 'string' && typeof lastOp.insert === 'string') {
this.ops[index - 1] = { insert: lastOp.insert + newOp.insert };
if (typeof newOp.attributes === 'object') this.ops[index - 1].attributes = newOp.attributes
return this;
} else if (typeof newOp.retain === 'number' && typeof lastOp.retain === 'number') {
this.ops[index - 1] = { retain: lastOp.retain + newOp.retain };
if (typeof newOp.attributes === 'object') this.ops[index - 1].attributes = newOp.attributes
return this;
}
}
}
if (index === this.ops.length) {
this.ops.push(newOp);
} else {
this.ops.splice(index, 0, newOp);
}
return this;
};
Delta.prototype.chop = function () {
var lastOp = this.ops[this.ops.length - 1];
if (lastOp && lastOp.retain && !lastOp.attributes) {
this.ops.pop();
}
return this;
};
Delta.prototype.filter = function (predicate) {
return this.ops.filter(predicate);
};
Delta.prototype.forEach = function (predicate) {
this.ops.forEach(predicate);
};
Delta.prototype.map = function (predicate) {
return this.ops.map(predicate);
};
Delta.prototype.partition = function (predicate) {
var passed = [], failed = [];
this.forEach(function(op) {
var target = predicate(op) ? passed : failed;
target.push(op);
});
return [passed, failed];
};
Delta.prototype.reduce = function (predicate, initial) {
return this.ops.reduce(predicate, initial);
};
Delta.prototype.changeLength = function () {
return this.reduce(function (length, elem) {
if (elem.insert) {
return length + op.length(elem);
} else if (elem.delete) {
return length - elem.delete;
}
return length;
}, 0);
};
Delta.prototype.length = function () {
return this.reduce(function (length, elem) {
return length + op.length(elem);
}, 0);
};
Delta.prototype.slice = function (start, end) {
start = start || 0;
if (typeof end !== 'number') end = Infinity;
var ops = [];
var iter = op.iterator(this.ops);
var index = 0;
while (index < end && iter.hasNext()) {
var nextOp;
if (index < start) {
nextOp = iter.next(start - index);
} else {
nextOp = iter.next(end - index);
ops.push(nextOp);
}
index += op.length(nextOp);
}
return new Delta(ops);
};
Delta.prototype.compose = function (other) {
var thisIter = op.iterator(this.ops);
var otherIter = op.iterator(other.ops);
var ops = [];
var firstOther = otherIter.peek();
if (firstOther != null && typeof firstOther.retain === 'number' && firstOther.attributes == null) {
var firstLeft = firstOther.retain;
while (thisIter.peekType() === 'insert' && thisIter.peekLength() <= firstLeft) {
firstLeft -= thisIter.peekLength();
ops.push(thisIter.next());
}
if (firstOther.retain - firstLeft > 0) {
otherIter.next(firstOther.retain - firstLeft);
}
}
var delta = new Delta(ops);
while (thisIter.hasNext() || otherIter.hasNext()) {
if (otherIter.peekType() === 'insert') {
delta.push(otherIter.next());
} else if (thisIter.peekType() === 'delete') {
delta.push(thisIter.next());
} else {
var length = Math.min(thisIter.peekLength(), otherIter.peekLength());
var thisOp = thisIter.next(length);
var otherOp = otherIter.next(length);
if (typeof otherOp.retain === 'number') {
var newOp = {};
if (typeof thisOp.retain === 'number') {
newOp.retain = length;
} else {
newOp.insert = thisOp.insert;
}
// Preserve null when composing with a retain, otherwise remove it for inserts
var attributes = op.attributes.compose(thisOp.attributes, otherOp.attributes, typeof thisOp.retain === 'number');
if (attributes) newOp.attributes = attributes;
delta.push(newOp);
// Optimization if rest of other is just retain
if (!otherIter.hasNext() && equal(delta.ops[delta.ops.length - 1], newOp)) {
var rest = new Delta(thisIter.rest());
return delta.concat(rest).chop();
}
// Other op should be delete, we could be an insert or retain
// Insert + delete cancels out
} else if (typeof otherOp['delete'] === 'number' && typeof thisOp.retain === 'number') {
delta.push(otherOp);
}
}
}
return delta.chop();
};
Delta.prototype.concat = function (other) {
var delta = new Delta(this.ops.slice());
if (other.ops.length > 0) {
delta.push(other.ops[0]);
delta.ops = delta.ops.concat(other.ops.slice(1));
}
return delta;
};
Delta.prototype.diff = function (other, index) {
if (this.ops === other.ops) {
return new Delta();
}
var strings = [this, other].map(function (delta) {
return delta.map(function (op) {
if (op.insert != null) {
return typeof op.insert === 'string' ? op.insert : NULL_CHARACTER;
}
var prep = (delta === other) ? 'on' : 'with';
throw new Error('diff() called ' + prep + ' non-document');
}).join('');
});
var delta = new Delta();
var diffResult = diff(strings[0], strings[1], index);
var thisIter = op.iterator(this.ops);
var otherIter = op.iterator(other.ops);
diffResult.forEach(function (component) {
var length = component[1].length;
while (length > 0) {
var opLength = 0;
switch (component[0]) {
case diff.INSERT:
opLength = Math.min(otherIter.peekLength(), length);
delta.push(otherIter.next(opLength));
break;
case diff.DELETE:
opLength = Math.min(length, thisIter.peekLength());
thisIter.next(opLength);
delta['delete'](opLength);
break;
case diff.EQUAL:
opLength = Math.min(thisIter.peekLength(), otherIter.peekLength(), length);
var thisOp = thisIter.next(opLength);
var otherOp = otherIter.next(opLength);
if (equal(thisOp.insert, otherOp.insert)) {
delta.retain(opLength, op.attributes.diff(thisOp.attributes, otherOp.attributes));
} else {
delta.push(otherOp)['delete'](opLength);
}
break;
}
length -= opLength;
}
});
return delta.chop();
};
Delta.prototype.eachLine = function (predicate, newline) {
newline = newline || '\n';
var iter = op.iterator(this.ops);
var line = new Delta();
var i = 0;
while (iter.hasNext()) {
if (iter.peekType() !== 'insert') return;
var thisOp = iter.peek();
var start = op.length(thisOp) - iter.peekLength();
var index = typeof thisOp.insert === 'string' ?
thisOp.insert.indexOf(newline, start) - start : -1;
if (index < 0) {
line.push(iter.next());
} else if (index > 0) {
line.push(iter.next(index));
} else {
if (predicate(line, iter.next(1).attributes || {}, i) === false) {
return;
}
i += 1;
line = new Delta();
}
}
if (line.length() > 0) {
predicate(line, {}, i);
}
};
Delta.prototype.transform = function (other, priority) {
priority = !!priority;
if (typeof other === 'number') {
return this.transformPosition(other, priority);
}
var thisIter = op.iterator(this.ops);
var otherIter = op.iterator(other.ops);
var delta = new Delta();
while (thisIter.hasNext() || otherIter.hasNext()) {
if (thisIter.peekType() === 'insert' && (priority || otherIter.peekType() !== 'insert')) {
delta.retain(op.length(thisIter.next()));
} else if (otherIter.peekType() === 'insert') {
delta.push(otherIter.next());
} else {
var length = Math.min(thisIter.peekLength(), otherIter.peekLength());
var thisOp = thisIter.next(length);
var otherOp = otherIter.next(length);
if (thisOp['delete']) {
// Our delete either makes their delete redundant or removes their retain
continue;
} else if (otherOp['delete']) {
delta.push(otherOp);
} else {
// We retain either their retain or insert
delta.retain(length, op.attributes.transform(thisOp.attributes, otherOp.attributes, priority));
}
}
}
return delta.chop();
};
Delta.prototype.transformPosition = function (index, priority) {
priority = !!priority;
var thisIter = op.iterator(this.ops);
var offset = 0;
while (thisIter.hasNext() && offset <= index) {
var length = thisIter.peekLength();
var nextType = thisIter.peekType();
thisIter.next();
if (nextType === 'delete') {
index -= Math.min(length, index - offset);
continue;
} else if (nextType === 'insert' && (offset < index || !priority)) {
index += length;
}
offset += length;
}
return index;
};
module.exports = Delta;

155
node_modules/quill-delta/lib/op.js generated vendored Normal file
View File

@@ -0,0 +1,155 @@
var equal = require('deep-equal');
var extend = require('extend');
var lib = {
attributes: {
compose: function (a, b, keepNull) {
if (typeof a !== 'object') a = {};
if (typeof b !== 'object') b = {};
var attributes = extend(true, {}, b);
if (!keepNull) {
attributes = Object.keys(attributes).reduce(function (copy, key) {
if (attributes[key] != null) {
copy[key] = attributes[key];
}
return copy;
}, {});
}
for (var key in a) {
if (a[key] !== undefined && b[key] === undefined) {
attributes[key] = a[key];
}
}
return Object.keys(attributes).length > 0 ? attributes : undefined;
},
diff: function(a, b) {
if (typeof a !== 'object') a = {};
if (typeof b !== 'object') b = {};
var attributes = Object.keys(a).concat(Object.keys(b)).reduce(function (attributes, key) {
if (!equal(a[key], b[key])) {
attributes[key] = b[key] === undefined ? null : b[key];
}
return attributes;
}, {});
return Object.keys(attributes).length > 0 ? attributes : undefined;
},
transform: function (a, b, priority) {
if (typeof a !== 'object') return b;
if (typeof b !== 'object') return undefined;
if (!priority) return b; // b simply overwrites us without priority
var attributes = Object.keys(b).reduce(function (attributes, key) {
if (a[key] === undefined) attributes[key] = b[key]; // null is a valid value
return attributes;
}, {});
return Object.keys(attributes).length > 0 ? attributes : undefined;
}
},
iterator: function (ops) {
return new Iterator(ops);
},
length: function (op) {
if (typeof op['delete'] === 'number') {
return op['delete'];
} else if (typeof op.retain === 'number') {
return op.retain;
} else {
return typeof op.insert === 'string' ? op.insert.length : 1;
}
}
};
function Iterator(ops) {
this.ops = ops;
this.index = 0;
this.offset = 0;
};
Iterator.prototype.hasNext = function () {
return this.peekLength() < Infinity;
};
Iterator.prototype.next = function (length) {
if (!length) length = Infinity;
var nextOp = this.ops[this.index];
if (nextOp) {
var offset = this.offset;
var opLength = lib.length(nextOp)
if (length >= opLength - offset) {
length = opLength - offset;
this.index += 1;
this.offset = 0;
} else {
this.offset += length;
}
if (typeof nextOp['delete'] === 'number') {
return { 'delete': length };
} else {
var retOp = {};
if (nextOp.attributes) {
retOp.attributes = nextOp.attributes;
}
if (typeof nextOp.retain === 'number') {
retOp.retain = length;
} else if (typeof nextOp.insert === 'string') {
retOp.insert = nextOp.insert.substr(offset, length);
} else {
// offset should === 0, length should === 1
retOp.insert = nextOp.insert;
}
return retOp;
}
} else {
return { retain: Infinity };
}
};
Iterator.prototype.peek = function () {
return this.ops[this.index];
};
Iterator.prototype.peekLength = function () {
if (this.ops[this.index]) {
// Should never return 0 if our index is being managed correctly
return lib.length(this.ops[this.index]) - this.offset;
} else {
return Infinity;
}
};
Iterator.prototype.peekType = function () {
if (this.ops[this.index]) {
if (typeof this.ops[this.index]['delete'] === 'number') {
return 'delete';
} else if (typeof this.ops[this.index].retain === 'number') {
return 'retain';
} else {
return 'insert';
}
}
return 'retain';
};
Iterator.prototype.rest = function () {
if (!this.hasNext()) {
return [];
} else if (this.offset === 0) {
return this.ops.slice(this.index);
} else {
var offset = this.offset;
var index = this.index;
var next = this.next();
var rest = this.ops.slice(this.index);
this.offset = offset;
this.index = index;
return [next].concat(rest);
}
};
module.exports = lib;

40
node_modules/quill-delta/package.json generated vendored Normal file
View File

@@ -0,0 +1,40 @@
{
"name": "quill-delta",
"version": "3.6.3",
"description": "Format for representing rich text documents and changes.",
"author": "Jason Chen <jhchen7@gmail.com>",
"homepage": "https://github.com/quilljs/delta",
"main": "lib/delta.js",
"dependencies": {
"deep-equal": "^1.0.1",
"extend": "^3.0.2",
"fast-diff": "1.1.2"
},
"devDependencies": {
"coveralls": "^3.0.2",
"istanbul": "~0.4.5",
"jasmine": "^3.1.0"
},
"engines": {
"node": ">=0.10"
},
"license": "MIT",
"scripts": {
"test": "jasmine test/*.js test/**/*.js",
"test:coverage": "istanbul cover jasmine test/**/*.js",
"test:coverage:report": "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
},
"repository": {
"type": "git",
"url": "https://github.com/quilljs/delta"
},
"bugs": {
"url": "https://github.com/quilljs/delta/issues"
},
"keywords": [
"rich text",
"ot",
"operational transform",
"delta"
]
}

111
node_modules/quill-delta/test/attributes.js generated vendored Normal file
View File

@@ -0,0 +1,111 @@
var op = require('../lib/op');
describe('attributes', function () {
describe('compose()', function () {
var attributes = { bold: true, color: 'red' };
it('left is undefined', function () {
expect(op.attributes.compose(undefined, attributes)).toEqual(attributes);
});
it('right is undefined', function () {
expect(op.attributes.compose(attributes, undefined)).toEqual(attributes);
});
it('both are undefined', function () {
expect(op.attributes.compose(undefined, undefined)).toBe(undefined);
});
it('missing', function () {
expect(op.attributes.compose(attributes, { italic: true })).toEqual({
bold: true,
italic: true,
color: 'red'
});
});
it('overwrite', function () {
expect(op.attributes.compose(attributes, { bold: false, color: 'blue' })).toEqual({
bold: false,
color: 'blue'
});
});
it('remove', function () {
expect(op.attributes.compose(attributes, { bold: null })).toEqual({
color: 'red'
});
});
it('remove to none', function () {
expect(op.attributes.compose(attributes, { bold: null, color: null })).toEqual(undefined);
});
it('remove missing', function () {
expect(op.attributes.compose(attributes, { italic: null })).toEqual(attributes);
});
});
describe('diff()', function () {
var format = { bold: true, color: 'red' };
it('left is undefined', function () {
expect(op.attributes.diff(undefined, format)).toEqual(format);
});
it('right is undefined', function () {
var expected = { bold: null, color: null };
expect(op.attributes.diff(format, undefined)).toEqual(expected);
});
it('same format', function () {
expect(op.attributes.diff(format, format)).toEqual(undefined);
});
it('add format', function () {
var added = { bold: true, italic: true, color: 'red' };
var expected = { italic: true };
expect(op.attributes.diff(format, added)).toEqual(expected);
});
it('remove format', function () {
var removed = { bold: true };
var expected = { color: null };
expect(op.attributes.diff(format, removed)).toEqual(expected);
});
it('overwrite format', function () {
var overwritten = { bold: true, color: 'blue' };
var expected = { color: 'blue' };
expect(op.attributes.diff(format, overwritten)).toEqual(expected);
});
});
describe('transform()', function () {
var left = { bold: true, color: 'red', font: null };
var right = { color: 'blue', font: 'serif', italic: true };
it('left is undefined', function () {
expect(op.attributes.transform(undefined, left, false)).toEqual(left);
});
it('right is undefined', function () {
expect(op.attributes.transform(left, undefined, false)).toEqual(undefined);
});
it('both are undefined', function () {
expect(op.attributes.transform(undefined, undefined, false)).toEqual(undefined);
});
it('with priority', function () {
expect(op.attributes.transform(left, right, true)).toEqual({
italic: true
});
});
it('without priority', function () {
expect(op.attributes.transform(left, right, false)).toEqual(right);
});
});
});

212
node_modules/quill-delta/test/delta/builder.js generated vendored Normal file
View File

@@ -0,0 +1,212 @@
var Delta = require('../../lib/delta');
describe('constructor', function () {
var ops = [
{ insert: 'abc' },
{ retain: 1, attributes: { color: 'red' } },
{ delete: 4 },
{ insert: 'def', attributes: { bold: true } },
{ retain: 6 }
];
it('empty', function () {
var delta = new Delta();
expect(delta).toBeDefined();
expect(delta.ops).toBeDefined();
expect(delta.ops.length).toEqual(0);
});
it('empty ops', function () {
var delta = new Delta().insert('').delete(0).retain(0);
expect(delta).toBeDefined();
expect(delta.ops).toBeDefined();
expect(delta.ops.length).toEqual(0);
});
it('array of ops', function () {
var delta = new Delta(ops);
expect(delta.ops).toEqual(ops);
});
it('delta in object form', function () {
var delta = new Delta({ ops: ops });
expect(delta.ops).toEqual(ops);
});
it('delta', function () {
var original = new Delta(ops);
var delta = new Delta(original);
expect(delta.ops).toEqual(original.ops);
expect(delta.ops).toEqual(ops);
});
});
describe('insert()', function () {
it('insert(text)', function () {
var delta = new Delta().insert('test');
expect(delta.ops.length).toEqual(1);
expect(delta.ops[0]).toEqual({ insert: 'test' });
});
it('insert(text, null)', function () {
var delta = new Delta().insert('test', null);
expect(delta.ops.length).toEqual(1);
expect(delta.ops[0]).toEqual({ insert: 'test' });
});
it('insert(embed)', function () {
var delta = new Delta().insert(1);
expect(delta.ops.length).toEqual(1);
expect(delta.ops[0]).toEqual({ insert: 1 });
});
it('insert(embed, attributes)', function () {
var obj = { url: 'http://quilljs.com', alt: 'Quill' };
var delta = new Delta().insert(1, obj);
expect(delta.ops.length).toEqual(1);
expect(delta.ops[0]).toEqual({ insert: 1, attributes: obj });
});
it('insert(embed) non-integer', function () {
var embed = { url: 'http://quilljs.com' };
var attr = { alt: 'Quill' };
var delta = new Delta().insert(embed, attr);
expect(delta.ops.length).toEqual(1);
expect(delta.ops[0]).toEqual({ insert: embed, attributes: attr });
});
it('insert(text, attributes)', function () {
var delta = new Delta().insert('test', { bold: true });
expect(delta.ops.length).toEqual(1);
expect(delta.ops[0]).toEqual({ insert: 'test', attributes: { bold: true } });
});
it('insert(text) after delete', function () {
var delta = new Delta().delete(1).insert('a');
var expected = new Delta().insert('a').delete(1);
expect(delta).toEqual(expected);
});
it('insert(text) after delete with merge', function () {
var delta = new Delta().insert('a').delete(1).insert('b');
var expected = new Delta().insert('ab').delete(1);
expect(delta).toEqual(expected);
});
it('insert(text) after delete no merge', function () {
var delta = new Delta().insert(1).delete(1).insert('a');
var expected = new Delta().insert(1).insert('a').delete(1);
expect(delta).toEqual(expected);
});
it('insert(text) after delete no merge', function () {
var delta = new Delta().insert(1).delete(1).insert('a');
var expected = new Delta().insert(1).insert('a').delete(1);
expect(delta).toEqual(expected);
});
it('insert(text, {})', function () {
var delta = new Delta().insert('a', {});
var expected = new Delta().insert('a');
expect(delta).toEqual(expected);
});
});
describe('delete()', function () {
it('delete(0)', function () {
var delta = new Delta().delete(0);
expect(delta.ops.length).toEqual(0);
});
it('delete(positive)', function () {
var delta = new Delta().delete(1);
expect(delta.ops.length).toEqual(1);
expect(delta.ops[0]).toEqual({ delete: 1 });
});
});
describe('retain()', function () {
it('retain(0)', function () {
var delta = new Delta().retain(0);
expect(delta.ops.length).toEqual(0);
});
it('retain(length)', function () {
var delta = new Delta().retain(2);
expect(delta.ops.length).toEqual(1);
expect(delta.ops[0]).toEqual({ retain: 2 });
});
it('retain(length, null)', function () {
var delta = new Delta().retain(2, null);
expect(delta.ops.length).toEqual(1);
expect(delta.ops[0]).toEqual({ retain: 2 });
});
it('retain(length, attributes)', function () {
var delta = new Delta().retain(1, { bold: true });
expect(delta.ops.length).toEqual(1);
expect(delta.ops[0]).toEqual({ retain: 1, attributes: { bold: true } });
});
it('retain(length, {})', function () {
var delta = new Delta().retain(2, {}).delete(1); // Delete prevents chop
var expected = new Delta().retain(2).delete(1);
expect(delta).toEqual(expected);
});
});
describe('push()', function () {
it('push(op) into empty', function () {
var delta = new Delta();
delta.push({ insert: 'test' });
expect(delta.ops.length).toEqual(1);
});
it('push(op) consecutive delete', function () {
var delta = new Delta().delete(2);
delta.push({ delete: 3 });
expect(delta.ops.length).toEqual(1);
expect(delta.ops[0]).toEqual({ delete: 5 });
});
it('push(op) consecutive text', function () {
var delta = new Delta().insert('a');
delta.push({ insert: 'b' });
expect(delta.ops.length).toEqual(1);
expect(delta.ops[0]).toEqual({ insert: 'ab' });
});
it('push(op) consecutive texts with matching attributes', function () {
var delta = new Delta().insert('a', { bold: true });
delta.push({ insert: 'b', attributes: { bold: true } });
expect(delta.ops.length).toEqual(1);
expect(delta.ops[0]).toEqual({ insert: 'ab', attributes: { bold: true } });
});
it('push(op) consecutive retains with matching attributes', function () {
var delta = new Delta().retain(1, { bold: true });
delta.push({ retain: 3, attributes: { bold : true } });
expect(delta.ops.length).toEqual(1);
expect(delta.ops[0]).toEqual({ retain: 4, attributes: { bold: true } });
});
it('push(op) consecutive texts with mismatched attributes', function () {
var delta = new Delta().insert('a', { bold: true });
delta.push({ insert: 'b' });
expect(delta.ops.length).toEqual(2);
});
it('push(op) consecutive retains with mismatched attributes', function () {
var delta = new Delta().retain(1, { bold: true });
delta.push({ retain: 3 });
expect(delta.ops.length).toEqual(2);
});
it('push(op) consecutive embeds with matching attributes', function () {
var delta = new Delta().insert(1, { alt: 'Description' });
delta.push({ insert: { url: 'http://quilljs.com' }, attributes: { alt: 'Description' } });
expect(delta.ops.length).toEqual(2);
});
});

195
node_modules/quill-delta/test/delta/compose.js generated vendored Normal file
View File

@@ -0,0 +1,195 @@
var Delta = require('../../lib/delta');
describe('compose()', function () {
it('insert + insert', function () {
var a = new Delta().insert('A');
var b = new Delta().insert('B');
var expected = new Delta().insert('B').insert('A');
expect(a.compose(b)).toEqual(expected);
});
it('insert + retain', function () {
var a = new Delta().insert('A');
var b = new Delta().retain(1, { bold: true, color: 'red', font: null });
var expected = new Delta().insert('A', { bold: true, color: 'red' });
expect(a.compose(b)).toEqual(expected);
});
it('insert + delete', function () {
var a = new Delta().insert('A');
var b = new Delta().delete(1);
var expected = new Delta();
expect(a.compose(b)).toEqual(expected);
});
it('delete + insert', function () {
var a = new Delta().delete(1);
var b = new Delta().insert('B');
var expected = new Delta().insert('B').delete(1);
expect(a.compose(b)).toEqual(expected);
});
it('delete + retain', function () {
var a = new Delta().delete(1);
var b = new Delta().retain(1, { bold: true, color: 'red' });
var expected = new Delta().delete(1).retain(1, { bold: true, color: 'red' });
expect(a.compose(b)).toEqual(expected);
});
it('delete + delete', function () {
var a = new Delta().delete(1);
var b = new Delta().delete(1);
var expected = new Delta().delete(2);
expect(a.compose(b)).toEqual(expected);
});
it('retain + insert', function () {
var a = new Delta().retain(1, { color: 'blue' });
var b = new Delta().insert('B');
var expected = new Delta().insert('B').retain(1, { color: 'blue' });
expect(a.compose(b)).toEqual(expected);
});
it('retain + retain', function () {
var a = new Delta().retain(1, { color: 'blue' });
var b = new Delta().retain(1, { bold: true, color: 'red', font: null });
var expected = new Delta().retain(1, { bold: true, color: 'red', font: null });
expect(a.compose(b)).toEqual(expected);
});
it('retain + delete', function () {
var a = new Delta().retain(1, { color: 'blue' });
var b = new Delta().delete(1);
var expected = new Delta().delete(1);
expect(a.compose(b)).toEqual(expected);
});
it('insert in middle of text', function () {
var a = new Delta().insert('Hello');
var b = new Delta().retain(3).insert('X');
var expected = new Delta().insert('HelXlo');
expect(a.compose(b)).toEqual(expected);
});
it('insert and delete ordering', function () {
var a = new Delta().insert('Hello');
var b = new Delta().insert('Hello');
var insertFirst = new Delta().retain(3).insert('X').delete(1);
var deleteFirst = new Delta().retain(3).delete(1).insert('X');
var expected = new Delta().insert('HelXo');
expect(a.compose(insertFirst)).toEqual(expected);
expect(b.compose(deleteFirst)).toEqual(expected);
});
it('insert embed', function () {
var a = new Delta().insert(1, { src: 'http://quilljs.com/image.png' });
var b = new Delta().retain(1, { alt: 'logo' });
var expected = new Delta().insert(1, { src: 'http://quilljs.com/image.png', alt: 'logo' });
expect(a.compose(b)).toEqual(expected);
});
it('delete entire text', function () {
var a = new Delta().retain(4).insert('Hello');
var b = new Delta().delete(9);
var expected = new Delta().delete(4);
expect(a.compose(b)).toEqual(expected);
});
it('retain more than length of text', function () {
var a = new Delta().insert('Hello');
var b = new Delta().retain(10);
var expected = new Delta().insert('Hello');
expect(a.compose(b)).toEqual(expected);
});
it('retain empty embed', function () {
var a = new Delta().insert(1);
var b = new Delta().retain(1);
var expected = new Delta().insert(1);
expect(a.compose(b)).toEqual(expected);
});
it('remove all attributes', function () {
var a = new Delta().insert('A', { bold: true });
var b = new Delta().retain(1, { bold: null });
var expected = new Delta().insert('A');
expect(a.compose(b)).toEqual(expected);
});
it('remove all embed attributes', function () {
var a = new Delta().insert(2, { bold: true });
var b = new Delta().retain(1, { bold: null });
var expected = new Delta().insert(2);
expect(a.compose(b)).toEqual(expected);
});
it('immutability', function () {
var attr1 = { bold: true };
var attr2 = { bold: true };
var a1 = new Delta().insert('Test', attr1);
var a2 = new Delta().insert('Test', attr1);
var b1 = new Delta().retain(1, { color: 'red' }).delete(2);
var b2 = new Delta().retain(1, { color: 'red' }).delete(2);
var expected = new Delta().insert('T', { color: 'red', bold: true }).insert('t', attr1);
expect(a1.compose(b1)).toEqual(expected);
expect(a1).toEqual(a2);
expect(b1).toEqual(b2);
expect(attr1).toEqual(attr2);
});
it('retain start optimization', function () {
var a = new Delta().insert('A', { bold: true })
.insert('B')
.insert('C', { bold: true })
.delete(1);
var b = new Delta().retain(3).insert('D');
var expected = new Delta().insert('A', { bold: true })
.insert('B')
.insert('C', { bold: true })
.insert('D')
.delete(1);
expect(a.compose(b)).toEqual(expected);
});
it('retain start optimization split', function () {
var a = new Delta().insert('A', { bold: true })
.insert('B')
.insert('C', { bold: true })
.retain(5)
.delete(1);
var b = new Delta().retain(4).insert('D');
var expected = new Delta().insert('A', { bold: true })
.insert('B')
.insert('C', { bold: true })
.retain(1)
.insert('D')
.retain(4)
.delete(1);
expect(a.compose(b)).toEqual(expected);
});
it('retain end optimization', function () {
var a = new Delta().insert('A', { bold: true })
.insert('B')
.insert('C', { bold: true });
var b = new Delta().delete(1);
var expected = new Delta().insert('B').insert('C', { bold: true })
expect(a.compose(b)).toEqual(expected);
});
it('retain end optimization join', function () {
var a = new Delta().insert('A', { bold: true })
.insert('B')
.insert('C', { bold: true })
.insert('D')
.insert('E', { bold: true })
.insert('F')
var b = new Delta().retain(1).delete(1);
var expected = new Delta().insert('AC', { bold: true })
.insert('D')
.insert('E', { bold: true })
.insert('F')
expect(a.compose(b)).toEqual(expected);
});
});

136
node_modules/quill-delta/test/delta/diff.js generated vendored Normal file
View File

@@ -0,0 +1,136 @@
var Delta = require('../../lib/delta');
describe('diff()', function () {
it('insert', function () {
var a = new Delta().insert('A');
var b = new Delta().insert('AB');
var expected = new Delta().retain(1).insert('B');
expect(a.diff(b)).toEqual(expected);
});
it('delete', function () {
var a = new Delta().insert('AB');
var b = new Delta().insert('A');
var expected = new Delta().retain(1).delete(1);
expect(a.diff(b)).toEqual(expected);
});
it('retain', function () {
var a = new Delta().insert('A');
var b = new Delta().insert('A');
var expected = new Delta();
expect(a.diff(b)).toEqual(expected);
});
it('format', function () {
var a = new Delta().insert('A');
var b = new Delta().insert('A', { bold: true });
var expected = new Delta().retain(1, { bold: true });
expect(a.diff(b)).toEqual(expected);
});
it('object attributes', function () {
var a = new Delta().insert('A', { font: { family: 'Helvetica', size: '15px' } });
var b = new Delta().insert('A', { font: { family: 'Helvetica', size: '15px' } });
var expected = new Delta();
expect(a.diff(b)).toEqual(expected);
});
it('embed integer match', function () {
var a = new Delta().insert(1);
var b = new Delta().insert(1);
var expected = new Delta();
expect(a.diff(b)).toEqual(expected);
});
it('embed integer mismatch', function () {
var a = new Delta().insert(1);
var b = new Delta().insert(2);
var expected = new Delta().delete(1).insert(2);
expect(a.diff(b)).toEqual(expected);
});
it('embed object match', function () {
var a = new Delta().insert({ image: 'http://quilljs.com' });
var b = new Delta().insert({ image: 'http://quilljs.com' });
var expected = new Delta();
expect(a.diff(b)).toEqual(expected);
});
it('embed object mismatch', function () {
var a = new Delta().insert({ image: 'http://quilljs.com', alt: 'Overwrite' });
var b = new Delta().insert({ image: 'http://quilljs.com' });
var expected = new Delta().insert({ image: 'http://quilljs.com' }).delete(1);
expect(a.diff(b)).toEqual(expected);
});
it('embed object change', function () {
var embed = { image: 'http://quilljs.com' };
var a = new Delta().insert(embed);
embed.image = 'http://github.com';
var b = new Delta().insert(embed);
var expected = new Delta().insert({ image: 'http://github.com' }).delete(1);
expect(a.diff(b)).toEqual(expected);
});
it('embed false positive', function () {
var a = new Delta().insert(1);
var b = new Delta().insert(String.fromCharCode(0)); // Placeholder char for embed in diff()
var expected = new Delta().insert(String.fromCharCode(0)).delete(1);
expect(a.diff(b)).toEqual(expected);
});
it('error on non-documents', function () {
var a = new Delta().insert('A');
var b = new Delta().retain(1).insert('B');
expect(function () {
a.diff(b);
}).toThrow();
expect(function () {
b.diff(a);
}).toThrow();
});
it('inconvenient indexes', function () {
var a = new Delta().insert('12', { bold: true }).insert('34', { italic: true });
var b = new Delta().insert('123', { color: 'red' });
var expected = new Delta().retain(2, { bold: null, color: 'red' }).retain(1, { italic: null, color: 'red' }).delete(1);
expect(a.diff(b)).toEqual(expected);
});
it('combination', function () {
var a = new Delta().insert('Bad', { color: 'red' }).insert('cat', { color: 'blue' });
var b = new Delta().insert('Good', { bold: true }).insert('dog', { italic: true });
var expected = new Delta().insert('Good', { bold: true }).delete(2).retain(1, { italic: true, color: null }).delete(3).insert('og', { italic: true });
expect(a.diff(b)).toEqual(expected);
});
it('same document', function () {
var a = new Delta().insert('A').insert('B', { bold: true });
expected = new Delta();
expect(a.diff(a)).toEqual(expected);
});
it('immutability', function () {
var attr1 = { color: 'red' };
var attr2 = { color: 'red' };
var a1 = new Delta().insert('A', attr1);
var a2 = new Delta().insert('A', attr1);
var b1 = new Delta().insert('A', { bold: true }).insert('B');
var b2 = new Delta().insert('A', { bold: true }).insert('B');
var expected = new Delta().retain(1, { bold: true, color: null }).insert('B');
expect(a1.diff(b1)).toEqual(expected);
expect(a1).toEqual(a2);
expect(b2).toEqual(b2);
expect(attr1).toEqual(attr2);
});
it('non-document', function () {
var a = new Delta().insert('Test');
var b = new Delta().delete(4);
expect(function() {
a.diff(b);
}).toThrow(new Error('diff() called on non-document'));
});
});

204
node_modules/quill-delta/test/delta/helpers.js generated vendored Normal file
View File

@@ -0,0 +1,204 @@
var Delta = require('../../lib/delta');
describe('helpers', function () {
describe('concat()', function () {
it('empty delta', function () {
var delta = new Delta().insert('Test');
var concat = new Delta();
var expected = new Delta().insert('Test');
expect(delta.concat(concat)).toEqual(expected);
});
it('unmergeable', function () {
var delta = new Delta().insert('Test');
var original = new Delta(JSON.parse(JSON.stringify(delta)));
var concat = new Delta().insert('!', { bold: true });
var expected = new Delta().insert('Test').insert('!', { bold: true });
expect(delta.concat(concat)).toEqual(expected);
expect(delta).toEqual(original);
});
it('mergeable', function () {
var delta = new Delta().insert('Test', { bold: true });
var original = new Delta(JSON.parse(JSON.stringify(delta)));
var concat = new Delta().insert('!', { bold: true }).insert('\n');
var expected = new Delta().insert('Test!', { bold: true }).insert('\n');
expect(delta.concat(concat)).toEqual(expected);
expect(delta).toEqual(original);
});
});
describe('chop()', function () {
it('retain', function () {
var delta = new Delta().insert('Test').retain(4);
var expected = new Delta().insert('Test');
expect(delta.chop()).toEqual(expected);
});
it('insert', function () {
var delta = new Delta().insert('Test');
var expected = new Delta().insert('Test');
expect(delta.chop()).toEqual(expected);
});
it('formatted retain', function () {
var delta = new Delta().insert('Test').retain(4, { bold: true });
var expected = new Delta().insert('Test').retain(4, { bold: true });
expect(delta.chop()).toEqual(expected);
})
});
describe('eachLine()', function () {
var spy = { predicate: function () {} };
beforeEach(function () {
spyOn(spy, 'predicate').and.callThrough();
});
it('expected', function () {
var delta = new Delta().insert('Hello\n\n')
.insert('World', { bold: true })
.insert({ image: 'octocat.png' })
.insert('\n', { align: 'right' })
.insert('!');
delta.eachLine(spy.predicate);
expect(spy.predicate.calls.count()).toEqual(4);
expect(spy.predicate.calls.argsFor(0)).toEqual([ new Delta().insert('Hello'), {}, 0 ]);
expect(spy.predicate.calls.argsFor(1)).toEqual([ new Delta(), {}, 1 ]);
expect(spy.predicate.calls.argsFor(2)).toEqual([
new Delta().insert('World', { bold: true }).insert({ image: 'octocat.png' }),
{ align: 'right' },
2
]);
expect(spy.predicate.calls.argsFor(3)).toEqual([ new Delta().insert('!'), {}, 3 ]);
});
it('trailing newline', function () {
var delta = new Delta().insert('Hello\nWorld!\n');
delta.eachLine(spy.predicate);
expect(spy.predicate.calls.count()).toEqual(2);
expect(spy.predicate.calls.argsFor(0)).toEqual([ new Delta().insert('Hello'), {}, 0 ]);
expect(spy.predicate.calls.argsFor(1)).toEqual([ new Delta().insert('World!'), {}, 1 ]);
});
it('non-document', function () {
var delta = new Delta().retain(1).delete(2);
delta.eachLine(spy.predicate);
expect(spy.predicate.calls.count()).toEqual(0);
});
it('early return', function () {
var delta = new Delta().insert('Hello\nNew\nWorld!');
var count = 0;
var spy = {
predicate: function() {
if (count === 1) return false;
count += 1;
}
};
spyOn(spy, 'predicate').and.callThrough();
delta.eachLine(spy.predicate);
expect(spy.predicate.calls.count()).toEqual(2);
});
});
describe('iteration', function () {
beforeEach(function() {
this.delta = new Delta().insert('Hello').insert({ image: true }).insert('World!');
});
it('filter()', function () {
var arr = this.delta.filter(function (op) {
return typeof op.insert === 'string';
});
expect(arr.length).toEqual(2);
})
it('forEach()', function () {
var spy = { predicate: function () {} };
spyOn(spy, 'predicate').and.callThrough();
this.delta.forEach(spy.predicate);
expect(spy.predicate.calls.count()).toEqual(3);
});
it('map()', function () {
var arr = this.delta.map(function (op) {
return typeof op.insert === 'string' ? op.insert : '';
});
expect(arr).toEqual(['Hello', '', 'World!']);
});
it('partition()', function () {
var arr = this.delta.partition(function (op) {
return typeof op.insert === 'string';
});
var passed = arr[0], failed = arr[1];
expect(passed).toEqual([this.delta.ops[0], this.delta.ops[2]]);
expect(failed).toEqual([this.delta.ops[1]]);
});
});
describe('length()', function () {
it('document', function () {
var delta = new Delta().insert('AB', { bold: true }).insert(1);
expect(delta.length()).toEqual(3);
});
it('mixed', function () {
var delta = new Delta().insert('AB', { bold: true }).insert(1).retain(2, { bold: null }).delete(1);
expect(delta.length()).toEqual(6);
});
});
describe('changeLength()', function () {
it('mixed', function () {
var delta = new Delta().insert('AB', { bold: true }).retain(2, { bold: null }).delete(1);
expect(delta.changeLength()).toEqual(1);
});
});
describe('slice()', function () {
it('start', function () {
var slice = new Delta().retain(2).insert('A').slice(2);
var expected = new Delta().insert('A');
expect(slice).toEqual(expected);
});
it('start and end chop', function () {
var slice = new Delta().insert('0123456789').slice(2, 7);
var expected = new Delta().insert('23456');
expect(slice).toEqual(expected);
});
it('start and end multiple chop', function () {
var slice = new Delta().insert('0123', { bold: true }).insert('4567').slice(3, 5);
var expected = new Delta().insert('3', { bold: true }).insert('4');
expect(slice).toEqual(expected);
});
it('start and end', function () {
var slice = new Delta().retain(2).insert('A', { bold: true }).insert('B').slice(2, 3);
var expected = new Delta().insert('A', { bold: true });
expect(slice).toEqual(expected);
});
it('no params', function () {
var delta = new Delta().retain(2).insert('A', { bold: true }).insert('B');
var slice = delta.slice();
expect(slice).toEqual(delta);
});
it('split ops', function () {
var slice = new Delta().insert('AB', { bold: true }).insert('C').slice(1, 2);
var expected = new Delta().insert('B', { bold: true });
expect(slice).toEqual(expected);
});
it('split ops multiple times', function () {
var slice = new Delta().insert('ABC', { bold: true }).insert('D').slice(1, 2);
var expected = new Delta().insert('B', { bold: true });
expect(slice).toEqual(expected);
});
});
});

View File

@@ -0,0 +1,50 @@
var Delta = require('../../lib/delta');
describe('transformPosition()', function () {
it('insert before position', function () {
var delta = new Delta().insert('A');
expect(delta.transform(2)).toEqual(3);
});
it('insert after position', function () {
var delta = new Delta().retain(2).insert('A');
expect(delta.transform(1)).toEqual(1);
});
it('insert at position', function () {
var delta = new Delta().retain(2).insert('A');
expect(delta.transform(2, true)).toEqual(2);
expect(delta.transform(2, false)).toEqual(3);
});
it('delete before position', function () {
var delta = new Delta().delete(2);
expect(delta.transform(4)).toEqual(2);
});
it('delete after position', function () {
var delta = new Delta().retain(4).delete(2);
expect(delta.transform(2)).toEqual(2);
});
it('delete across position', function () {
var delta = new Delta().retain(1).delete(4);
expect(delta.transform(2)).toEqual(1);
});
it('insert and delete before position', function () {
var delta = new Delta().retain(2).insert('A').delete(2);
expect(delta.transform(4)).toEqual(3);
});
it('insert before and delete across position', function () {
var delta = new Delta().retain(2).insert('A').delete(4);
expect(delta.transform(4)).toEqual(3);
});
it('delete before and delete across position', function () {
var delta = new Delta().delete(1).retain(1).delete(4);
expect(delta.transform(4)).toEqual(1);
});
});

141
node_modules/quill-delta/test/delta/transform.js generated vendored Normal file
View File

@@ -0,0 +1,141 @@
var Delta = require('../../lib/delta');
describe('transform()', function () {
it('insert + insert', function () {
var a1 = new Delta().insert('A');
var b1 = new Delta().insert('B');
var a2 = new Delta(a1);
var b2 = new Delta(b1);
var expected1 = new Delta().retain(1).insert('B');
var expected2 = new Delta().insert('B');
expect(a1.transform(b1, true)).toEqual(expected1);
expect(a2.transform(b2, false)).toEqual(expected2);
});
it('insert + retain', function () {
var a = new Delta().insert('A');
var b = new Delta().retain(1, { bold: true, color: 'red' });
var expected = new Delta().retain(1).retain(1, { bold: true, color: 'red' });
expect(a.transform(b, true)).toEqual(expected);
});
it('insert + delete', function () {
var a = new Delta().insert('A');
var b = new Delta().delete(1);
var expected = new Delta().retain(1).delete(1);
expect(a.transform(b, true)).toEqual(expected);
});
it('delete + insert', function () {
var a = new Delta().delete(1);
var b = new Delta().insert('B');
var expected = new Delta().insert('B');
expect(a.transform(b, true)).toEqual(expected);
});
it('delete + retain', function () {
var a = new Delta().delete(1);
var b = new Delta().retain(1, { bold: true, color: 'red' });
var expected = new Delta();
expect(a.transform(b, true)).toEqual(expected);
});
it('delete + delete', function () {
var a = new Delta().delete(1);
var b = new Delta().delete(1);
var expected = new Delta();
expect(a.transform(b, true)).toEqual(expected);
});
it('retain + insert', function () {
var a = new Delta().retain(1, { color: 'blue' });
var b = new Delta().insert('B');
var expected = new Delta().insert('B');
expect(a.transform(b, true)).toEqual(expected);
});
it('retain + retain', function () {
var a1 = new Delta().retain(1, { color: 'blue' });
var b1 = new Delta().retain(1, { bold: true, color: 'red' });
var a2 = new Delta().retain(1, { color: 'blue' });
var b2 = new Delta().retain(1, { bold: true, color: 'red' });
var expected1 = new Delta().retain(1, { bold: true });
var expected2 = new Delta();
expect(a1.transform(b1, true)).toEqual(expected1);
expect(b2.transform(a2, true)).toEqual(expected2);
});
it('retain + retain without priority', function () {
var a1 = new Delta().retain(1, { color: 'blue' });
var b1 = new Delta().retain(1, { bold: true, color: 'red' });
var a2 = new Delta().retain(1, { color: 'blue' });
var b2 = new Delta().retain(1, { bold: true, color: 'red' });
var expected1 = new Delta().retain(1, { bold: true, color: 'red' });
var expected2 = new Delta().retain(1, { color: 'blue' });
expect(a1.transform(b1, false)).toEqual(expected1);
expect(b2.transform(a2, false)).toEqual(expected2);
});
it('retain + delete', function () {
var a = new Delta().retain(1, { color: 'blue' });
var b = new Delta().delete(1);
var expected = new Delta().delete(1);
expect(a.transform(b, true)).toEqual(expected);
});
it('alternating edits', function () {
var a1 = new Delta().retain(2).insert('si').delete(5);
var b1 = new Delta().retain(1).insert('e').delete(5).retain(1).insert('ow');
var a2 = new Delta(a1);
var b2 = new Delta(b1);
var expected1 = new Delta().retain(1).insert('e').delete(1).retain(2).insert('ow');
var expected2 = new Delta().retain(2).insert('si').delete(1);
expect(a1.transform(b1, false)).toEqual(expected1);
expect(b2.transform(a2, false)).toEqual(expected2);
});
it('conflicting appends', function () {
var a1 = new Delta().retain(3).insert('aa');
var b1 = new Delta().retain(3).insert('bb');
var a2 = new Delta(a1);
var b2 = new Delta(b1);
var expected1 = new Delta().retain(5).insert('bb');
var expected2 = new Delta().retain(3).insert('aa');
expect(a1.transform(b1, true)).toEqual(expected1);
expect(b2.transform(a2, false)).toEqual(expected2);
});
it('prepend + append', function () {
var a1 = new Delta().insert('aa');
var b1 = new Delta().retain(3).insert('bb');
var expected1 = new Delta().retain(5).insert('bb');
var a2 = new Delta(a1);
var b2 = new Delta(b1);
var expected2 = new Delta().insert('aa');
expect(a1.transform(b1, false)).toEqual(expected1);
expect(b2.transform(a2, false)).toEqual(expected2);
});
it('trailing deletes with differing lengths', function () {
var a1 = new Delta().retain(2).delete(1);
var b1 = new Delta().delete(3);
var expected1 = new Delta().delete(2);
var a2 = new Delta(a1);
var b2 = new Delta(b1);
var expected2 = new Delta();
expect(a1.transform(b1, false)).toEqual(expected1);
expect(b2.transform(a2, false)).toEqual(expected2);
});
it('immutability', function () {
var a1 = new Delta().insert('A');
var a2 = new Delta().insert('A');
var b1 = new Delta().insert('B');
var b2 = new Delta().insert('B');
var expected = new Delta().retain(1).insert('B');
expect(a1.transform(b1, true)).toEqual(expected);
expect(a1).toEqual(a2);
expect(b1).toEqual(b2);
});
});

113
node_modules/quill-delta/test/op.js generated vendored Normal file
View File

@@ -0,0 +1,113 @@
var Delta = require('../lib/delta');
var op = require('../lib/op');
describe('op', function () {
describe('length()', function () {
it('delete', function () {
expect(op.length({ delete: 5 })).toEqual(5);
});
it('retain', function () {
expect(op.length({ retain: 2 })).toEqual(2);
});
it('insert text', function () {
expect(op.length({ insert: 'text' })).toEqual(4);
});
it('insert embed', function () {
expect(op.length({ insert: 2 })).toEqual(1);
});
});
describe('iterator()', function () {
beforeEach(function () {
this.delta = new Delta().insert('Hello', { bold: true }).retain(3).insert(2, { src: 'http://quilljs.com/' }).delete(4);
});
it('hasNext() true', function () {
var iter = op.iterator(this.delta.ops);
expect(iter.hasNext()).toEqual(true);
});
it('hasNext() false', function () {
var iter = op.iterator([]);
expect(iter.hasNext()).toEqual(false);
});
it('peekLength() offset === 0', function () {
var iter = op.iterator(this.delta.ops);
expect(iter.peekLength()).toEqual(5);
iter.next();
expect(iter.peekLength()).toEqual(3);
iter.next();
expect(iter.peekLength()).toEqual(1);
iter.next();
expect(iter.peekLength()).toEqual(4);
});
it('peekLength() offset > 0', function () {
var iter = op.iterator(this.delta.ops);
iter.next(2);
expect(iter.peekLength()).toEqual(5 - 2);
});
it('peekLength() no ops left', function () {
var iter = op.iterator([]);
expect(iter.peekLength()).toEqual(Infinity);
});
it('peekType()', function () {
var iter = op.iterator(this.delta.ops);
expect(iter.peekType()).toEqual('insert');
iter.next();
expect(iter.peekType()).toEqual('retain');
iter.next();
expect(iter.peekType()).toEqual('insert');
iter.next();
expect(iter.peekType()).toEqual('delete');
iter.next();
expect(iter.peekType()).toEqual('retain');
});
it('next()', function () {
var iter = op.iterator(this.delta.ops);
for (var i = 0; i < this.delta.ops.length; i += 1) {
expect(iter.next()).toEqual(this.delta.ops[i]);
}
expect(iter.next()).toEqual({ retain: Infinity });
expect(iter.next(4)).toEqual({ retain: Infinity });
expect(iter.next()).toEqual({ retain: Infinity });
});
it('next(length)', function () {
var iter = op.iterator(this.delta.ops);
expect(iter.next(2)).toEqual({ insert: 'He', attributes: { bold: true }});
expect(iter.next(10)).toEqual({ insert: 'llo', attributes: { bold: true }});
expect(iter.next(1)).toEqual({ retain: 1 });
expect(iter.next(2)).toEqual({ retain: 2 });
});
it('rest()', function () {
var iter = op.iterator(this.delta.ops);
iter.next(2);
expect(iter.rest()).toEqual([
{ insert: 'llo', attributes: { bold: true }},
{ retain: 3 },
{ insert: 2, attributes: { src: 'http://quilljs.com/' } },
{ delete: 4 }
]);
iter.next(3);
expect(iter.rest()).toEqual([
{ retain: 3 },
{ insert: 2, attributes: { src: 'http://quilljs.com/' } },
{ delete: 4 }
]);
iter.next(3);
iter.next(2);
iter.next(4);
expect(iter.rest()).toEqual([]);
})
});
});