easy-richtextarea 3.0.154 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/example.js +836 -1
- package/lib/browser.js +33 -1
- package/lib/constants.js +13 -0
- package/lib/content/transform.js +17 -0
- package/lib/main.js +45 -4
- package/lib/operation/delete.js +240 -0
- package/lib/operation/empty.js +101 -0
- package/lib/operation/insert.js +198 -0
- package/lib/operations/fromJSON.js +40 -0
- package/lib/operations/generate.js +42 -0
- package/lib/operations/toJSON.js +17 -0
- package/lib/operations/transform.js +35 -0
- package/lib/stringCompare.js +33 -0
- package/lib/types.js +34 -0
- package/package.json +6 -2
- package/src/browser.js +10 -1
- package/src/constants.js +3 -0
- package/src/content/transform.js +5 -0
- package/src/main.js +10 -0
- package/src/operation/delete.js +206 -0
- package/src/operation/empty.js +71 -0
- package/src/operation/insert.js +163 -0
- package/src/operations/fromJSON.js +34 -0
- package/src/operations/generate.js +42 -0
- package/src/operations/toJSON.js +5 -0
- package/src/operations/transform.js +57 -0
- package/src/stringCompare.js +33 -0
- package/src/types.js +11 -0
- package/test/content/transform.js +59 -0
- package/test/helpers.js +85 -0
- package/test/operation/delete.js +245 -0
- package/test/operation/empty.js +83 -0
- package/test/operation/insert.js +201 -0
- package/test/operations/generate.js +81 -0
- package/test/operations/transform.js +130 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { assert } = require("chai"),
|
|
4
|
+
{ arrayUtilities } = require("necessary"),
|
|
5
|
+
{ types, InsertOperation, DeleteOperation, generateOperations } = require("../../lib/main"); ///
|
|
6
|
+
|
|
7
|
+
const helpers = require("../helpers");
|
|
8
|
+
|
|
9
|
+
const{ first, second } = arrayUtilities,
|
|
10
|
+
{ insertType, deleteType } = types;
|
|
11
|
+
|
|
12
|
+
describe("generateOperations", () => {
|
|
13
|
+
describe("the contents are the same", () => {
|
|
14
|
+
it("generates a zero length array of operations", () => {
|
|
15
|
+
const content = helpers.content(),
|
|
16
|
+
operations = generateOperations(content, content);
|
|
17
|
+
|
|
18
|
+
assert.lengthOf(operations, 0);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe("the second content is a subset of the first content", () => {
|
|
23
|
+
it("generates a array of operations containing an insert operation", () => {
|
|
24
|
+
const contentA = helpers.content(),
|
|
25
|
+
contentB = `123${contentA}`,
|
|
26
|
+
operations = generateOperations(contentA, contentB);
|
|
27
|
+
|
|
28
|
+
assert.lengthOf(operations, 1);
|
|
29
|
+
|
|
30
|
+
const firstOperation = first(operations),
|
|
31
|
+
insertOperation = InsertOperation.fromStringAndPosition("123", 0),
|
|
32
|
+
operation = firstOperation, ///
|
|
33
|
+
expectedOperation = insertOperation, ///
|
|
34
|
+
operationJSON = operation.toJSON(),
|
|
35
|
+
expectedOperationJSON = expectedOperation.toJSON();
|
|
36
|
+
|
|
37
|
+
assert.deepEqual(operationJSON, expectedOperationJSON);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe("the first content is a subset of second content", () => {
|
|
42
|
+
it("generates array of operations containing a delete operation", () => {
|
|
43
|
+
const contentB = helpers.content(),
|
|
44
|
+
contentA = `xyz${contentB}`,
|
|
45
|
+
operations = generateOperations(contentA, contentB);
|
|
46
|
+
|
|
47
|
+
assert.lengthOf(operations, 1);
|
|
48
|
+
|
|
49
|
+
const firstOperation = first(operations),
|
|
50
|
+
deleteOperation = DeleteOperation.fromLengthAndPosition(3, 0),
|
|
51
|
+
operation = firstOperation, ///
|
|
52
|
+
expectedOperation = deleteOperation, ///
|
|
53
|
+
operationJSON = operation.toJSON(),
|
|
54
|
+
expectedOperationJSON = expectedOperation.toJSON();
|
|
55
|
+
|
|
56
|
+
assert.deepEqual(operationJSON, expectedOperationJSON);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe("the contents are different", () => {
|
|
61
|
+
it("generates array of operations containing one delete operation followed by an insert operation", () => {
|
|
62
|
+
const contentA = helpers.content(),
|
|
63
|
+
contentB = helpers.content(),
|
|
64
|
+
operations = generateOperations(contentA, contentB);
|
|
65
|
+
|
|
66
|
+
assert.lengthOf(operations, 2);
|
|
67
|
+
|
|
68
|
+
const firstOperation = first(operations),
|
|
69
|
+
secondOperation = second(operations),
|
|
70
|
+
firstOperationJSON = firstOperation.toJSON(),
|
|
71
|
+
secondOperationJSON = secondOperation.toJSON(),
|
|
72
|
+
firstOperationType = firstOperationJSON["type"],
|
|
73
|
+
secondOperationType = secondOperationJSON["type"],
|
|
74
|
+
expectedFirstOperationType = deleteType, ///
|
|
75
|
+
expectedSecondOperationType = insertType; ///
|
|
76
|
+
|
|
77
|
+
assert.deepEqual(firstOperationType, expectedFirstOperationType);
|
|
78
|
+
assert.deepEqual(secondOperationType, expectedSecondOperationType);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { assert } = require("chai"),
|
|
4
|
+
{ transformContent, operationsFromJSON, transformOperations } = require("../../lib/main"); ///
|
|
5
|
+
|
|
6
|
+
const helpers = require("../helpers");
|
|
7
|
+
|
|
8
|
+
describe("transformOperations", () => {
|
|
9
|
+
describe("for two empty sequences of operations", () => {
|
|
10
|
+
it("The intentions are preserved", () => {
|
|
11
|
+
const firstOperationsJSON = [],
|
|
12
|
+
secondOperationsJSON = [],
|
|
13
|
+
firstOperations = operationsFromJSON(firstOperationsJSON),
|
|
14
|
+
secondOperations = operationsFromJSON(secondOperationsJSON);
|
|
15
|
+
|
|
16
|
+
assertIntentionsPreserved(firstOperations, secondOperations);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe("for an array containing one operation and an empty sequence", () => {
|
|
21
|
+
it("The intentions are preserved", () => {
|
|
22
|
+
const firstOperationsJSON = [{
|
|
23
|
+
"type": "insert",
|
|
24
|
+
"string": "xyz",
|
|
25
|
+
"position": 1
|
|
26
|
+
}],
|
|
27
|
+
secondOperationsJSON = [],
|
|
28
|
+
firstOperations = operationsFromJSON(firstOperationsJSON),
|
|
29
|
+
secondOperations = operationsFromJSON(secondOperationsJSON);
|
|
30
|
+
|
|
31
|
+
assertIntentionsPreserved(firstOperations, secondOperations);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe("for two sequences each containing one operation", () => {
|
|
36
|
+
it("The intentions are preserved", () => {
|
|
37
|
+
const firstOperationsJSON = [{
|
|
38
|
+
"type": "insert",
|
|
39
|
+
"string": "xyz",
|
|
40
|
+
"position": 1
|
|
41
|
+
}],
|
|
42
|
+
secondOperationsJSON = [{
|
|
43
|
+
"type": "delete",
|
|
44
|
+
"length": 2,
|
|
45
|
+
"position": 1
|
|
46
|
+
}],
|
|
47
|
+
firstOperations = operationsFromJSON(firstOperationsJSON),
|
|
48
|
+
secondOperations = operationsFromJSON(secondOperationsJSON);
|
|
49
|
+
|
|
50
|
+
assertIntentionsPreserved(firstOperations, secondOperations);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe("for an array containing one operation and a sequence containing two operations", () => {
|
|
55
|
+
it("The intentions are preserved", () => {
|
|
56
|
+
const firstOperationsJSON = [{
|
|
57
|
+
"type": "insert",
|
|
58
|
+
"string": "xyz",
|
|
59
|
+
"position": 1,
|
|
60
|
+
}],
|
|
61
|
+
secondOperationsJSON = [{
|
|
62
|
+
"type": "insert",
|
|
63
|
+
"string": "abc",
|
|
64
|
+
"position": 3
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"type": "delete",
|
|
68
|
+
"length": 2,
|
|
69
|
+
"position": 1,
|
|
70
|
+
}],
|
|
71
|
+
firstOperations = operationsFromJSON(firstOperationsJSON),
|
|
72
|
+
secondOperations = operationsFromJSON(secondOperationsJSON);
|
|
73
|
+
|
|
74
|
+
assertIntentionsPreserved(firstOperations, secondOperations);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe("for two sequences each containing two operations", () => {
|
|
79
|
+
it("The intentions are preserved", () => {
|
|
80
|
+
const firstOperationsJSON = [{
|
|
81
|
+
"type": "delete",
|
|
82
|
+
"length": 6,
|
|
83
|
+
"position": 0
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"type": "insert",
|
|
87
|
+
"string": "JQ",
|
|
88
|
+
"position": 0
|
|
89
|
+
}],
|
|
90
|
+
secondOperationsJSON = [{
|
|
91
|
+
"type": "delete",
|
|
92
|
+
"length": 4,
|
|
93
|
+
"position": 0
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"type": "insert",
|
|
97
|
+
"string": "bkW",
|
|
98
|
+
"position": 0
|
|
99
|
+
}],
|
|
100
|
+
firstOperations = operationsFromJSON(firstOperationsJSON),
|
|
101
|
+
secondOperations = operationsFromJSON(secondOperationsJSON);
|
|
102
|
+
|
|
103
|
+
assertIntentionsPreserved(firstOperations, secondOperations);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe("for two sequences each containing a hundred operations", () => {
|
|
108
|
+
it("The intentions are preserved", () => {
|
|
109
|
+
const content = helpers.content(100),
|
|
110
|
+
firstOperations = helpers.operations(content, 100),
|
|
111
|
+
secondOperations = helpers.operations(content, 100);
|
|
112
|
+
|
|
113
|
+
assertIntentionsPreserved(firstOperations, secondOperations);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
function assertIntentionsPreserved(firstOperations, secondOperations) {
|
|
119
|
+
const content = helpers.content(100),
|
|
120
|
+
transformedFirstOperations = transformOperations(firstOperations, secondOperations),
|
|
121
|
+
transformedSecondOperations = transformOperations(secondOperations, firstOperations);
|
|
122
|
+
|
|
123
|
+
firstOperations = firstOperations.concat(transformedSecondOperations);
|
|
124
|
+
secondOperations = secondOperations.concat(transformedFirstOperations);
|
|
125
|
+
|
|
126
|
+
const firstTransformedContent = transformContent(content, firstOperations),
|
|
127
|
+
secondTransformedContent = transformContent(content, secondOperations);
|
|
128
|
+
|
|
129
|
+
assert.equal(firstTransformedContent, secondTransformedContent);
|
|
130
|
+
}
|