hadron-document 7.7.0 → 7.10.0
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 +5 -5
- package/dist/document.d.ts +53 -0
- package/dist/document.d.ts.map +1 -0
- package/dist/document.js +248 -0
- package/dist/document.js.map +1 -0
- package/dist/editor/date.d.ts +13 -0
- package/dist/editor/date.d.ts.map +1 -0
- package/dist/editor/date.js +65 -0
- package/dist/editor/date.js.map +1 -0
- package/dist/editor/decimal128.d.ts +9 -0
- package/dist/editor/decimal128.d.ts.map +1 -0
- package/dist/editor/decimal128.js +32 -0
- package/dist/editor/decimal128.js.map +1 -0
- package/dist/editor/double.d.ts +10 -0
- package/dist/editor/double.d.ts.map +1 -0
- package/dist/editor/double.js +44 -0
- package/dist/editor/double.js.map +1 -0
- package/dist/editor/index.d.ts +38 -0
- package/dist/editor/index.d.ts.map +1 -0
- package/dist/editor/index.js +51 -0
- package/dist/editor/index.js.map +1 -0
- package/dist/editor/int32.d.ts +7 -0
- package/dist/editor/int32.d.ts.map +1 -0
- package/dist/editor/int32.js +17 -0
- package/dist/editor/int32.js.map +1 -0
- package/dist/editor/int64.d.ts +9 -0
- package/dist/editor/int64.d.ts.map +1 -0
- package/dist/editor/int64.js +32 -0
- package/dist/editor/int64.js.map +1 -0
- package/dist/editor/null.d.ts +8 -0
- package/dist/editor/null.d.ts.map +1 -0
- package/dist/editor/null.js +20 -0
- package/dist/editor/null.js.map +1 -0
- package/dist/editor/objectid.d.ts +10 -0
- package/dist/editor/objectid.d.ts.map +1 -0
- package/dist/editor/objectid.js +38 -0
- package/dist/editor/objectid.js.map +1 -0
- package/dist/editor/standard.d.ts +16 -0
- package/dist/editor/standard.d.ts.map +1 -0
- package/dist/editor/standard.js +49 -0
- package/dist/editor/standard.js.map +1 -0
- package/dist/editor/string.d.ts +7 -0
- package/dist/editor/string.d.ts.map +1 -0
- package/dist/editor/string.js +15 -0
- package/dist/editor/string.js.map +1 -0
- package/dist/editor/undefined.d.ts +8 -0
- package/dist/editor/undefined.d.ts.map +1 -0
- package/dist/editor/undefined.js +20 -0
- package/dist/editor/undefined.js.map +1 -0
- package/dist/element-events.d.ts +11 -0
- package/dist/element-events.d.ts.map +1 -0
- package/dist/element-events.js +12 -0
- package/dist/element-events.js.map +1 -0
- package/dist/element.d.ts +112 -0
- package/dist/element.d.ts.map +1 -0
- package/dist/element.js +652 -0
- package/dist/element.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/object-generator.d.ts +9 -0
- package/dist/object-generator.d.ts.map +1 -0
- package/dist/object-generator.js +82 -0
- package/dist/object-generator.js.map +1 -0
- package/dist/utils.d.ts +11 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +37 -0
- package/dist/utils.js.map +1 -0
- package/package.json +45 -28
- package/.babelrc.js +0 -14
- package/.depcheckrc +0 -8
- package/.eslintignore +0 -1
- package/index.js +0 -1
- package/lib/document.js +0 -557
- package/lib/element.js +0 -1236
- package/lib/index.js +0 -4
- package/lib/object-generator.js +0 -180
- package/src/document.js +0 -391
- package/src/element.js +0 -951
- package/src/index.js +0 -2
- package/src/object-generator.js +0 -96
package/lib/element.js
DELETED
|
@@ -1,1236 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
-
|
|
5
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
6
|
-
|
|
7
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
|
-
|
|
9
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
10
|
-
|
|
11
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
|
-
|
|
13
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
14
|
-
|
|
15
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
16
|
-
|
|
17
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
18
|
-
|
|
19
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
20
|
-
|
|
21
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
22
|
-
|
|
23
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
24
|
-
|
|
25
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
26
|
-
|
|
27
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
28
|
-
|
|
29
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
30
|
-
|
|
31
|
-
var EventEmitter = require('eventemitter3');
|
|
32
|
-
|
|
33
|
-
var keys = require('lodash.keys');
|
|
34
|
-
|
|
35
|
-
var isObject = require('lodash.isplainobject');
|
|
36
|
-
|
|
37
|
-
var isArray = require('lodash.isarray');
|
|
38
|
-
|
|
39
|
-
var isEqual = require('lodash.isequal');
|
|
40
|
-
|
|
41
|
-
var isString = require('lodash.isstring');
|
|
42
|
-
|
|
43
|
-
var ObjectGenerator = require('./object-generator');
|
|
44
|
-
|
|
45
|
-
var TypeChecker = require('hadron-type-checker');
|
|
46
|
-
|
|
47
|
-
var uuid = require('uuid');
|
|
48
|
-
|
|
49
|
-
var DATE_FORMAT = 'YYYY-MM-DD HH:mm:ss.SSS';
|
|
50
|
-
/**
|
|
51
|
-
* The event constant.
|
|
52
|
-
*/
|
|
53
|
-
|
|
54
|
-
var Events = {
|
|
55
|
-
'Added': 'Element::Added',
|
|
56
|
-
'Edited': 'Element::Edited',
|
|
57
|
-
'Removed': 'Element::Removed',
|
|
58
|
-
'Reverted': 'Element::Reverted',
|
|
59
|
-
'Converted': 'Element::Converted',
|
|
60
|
-
'Invalid': 'Element::Invalid',
|
|
61
|
-
'Valid': 'Element::Valid'
|
|
62
|
-
};
|
|
63
|
-
/**
|
|
64
|
-
* Id field constant.
|
|
65
|
-
*/
|
|
66
|
-
|
|
67
|
-
var ID = '_id';
|
|
68
|
-
/**
|
|
69
|
-
* Types that are not editable.
|
|
70
|
-
*/
|
|
71
|
-
|
|
72
|
-
var UNEDITABLE_TYPES = ['Binary', 'Code', 'MinKey', 'MaxKey', 'Timestamp', 'BSONRegExp', 'Undefined', 'Null'];
|
|
73
|
-
/**
|
|
74
|
-
* Curly brace constant.
|
|
75
|
-
*/
|
|
76
|
-
|
|
77
|
-
var CURLY = '{';
|
|
78
|
-
/**
|
|
79
|
-
* Bracket constant.
|
|
80
|
-
*/
|
|
81
|
-
|
|
82
|
-
var BRACKET = '[';
|
|
83
|
-
/**
|
|
84
|
-
* Regex to match an array or object string.
|
|
85
|
-
*/
|
|
86
|
-
|
|
87
|
-
var ARRAY_OR_OBJECT = /^(\[|\{)(.+)(\]|\})$/;
|
|
88
|
-
/**
|
|
89
|
-
* Represents an element in a document.
|
|
90
|
-
*/
|
|
91
|
-
|
|
92
|
-
var Element = /*#__PURE__*/function (_EventEmitter) {
|
|
93
|
-
_inherits(Element, _EventEmitter);
|
|
94
|
-
|
|
95
|
-
var _super = _createSuper(Element);
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Create the element.
|
|
99
|
-
*
|
|
100
|
-
* @param {String} key - The key.
|
|
101
|
-
* @param {Object} value - The value.
|
|
102
|
-
* @param {Boolean} added - Is the element a new 'addition'?
|
|
103
|
-
* @param {Element} parent - The parent element.
|
|
104
|
-
* @param {Element} previousElement - The previous element in the list.
|
|
105
|
-
* @param {Element} nextElement - The next element in the list.
|
|
106
|
-
*/
|
|
107
|
-
function Element(key, value, added, parent, previousElement, nextElement) {
|
|
108
|
-
var _this;
|
|
109
|
-
|
|
110
|
-
_classCallCheck(this, Element);
|
|
111
|
-
|
|
112
|
-
_this = _super.call(this);
|
|
113
|
-
_this.uuid = uuid.v4();
|
|
114
|
-
_this.key = key;
|
|
115
|
-
_this.currentKey = key;
|
|
116
|
-
_this.parent = parent;
|
|
117
|
-
_this.previousElement = previousElement;
|
|
118
|
-
_this.nextElement = nextElement;
|
|
119
|
-
_this.added = added;
|
|
120
|
-
_this.removed = false;
|
|
121
|
-
_this.type = TypeChecker.type(value);
|
|
122
|
-
_this.currentType = _this.type;
|
|
123
|
-
|
|
124
|
-
_this.setValid();
|
|
125
|
-
|
|
126
|
-
if (_this._isExpandable(value)) {
|
|
127
|
-
_this.elements = _this._generateElements(value);
|
|
128
|
-
_this.originalExpandableValue = value;
|
|
129
|
-
} else {
|
|
130
|
-
_this.value = value;
|
|
131
|
-
_this.currentValue = value;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return _this;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Edit the element.
|
|
138
|
-
*
|
|
139
|
-
* @param {Object} value - The new value.
|
|
140
|
-
*/
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
_createClass(Element, [{
|
|
144
|
-
key: "bulkEdit",
|
|
145
|
-
value:
|
|
146
|
-
/**
|
|
147
|
-
* Bulk edit the element. Can accept JSON strings.
|
|
148
|
-
*
|
|
149
|
-
* @param {String} value - The JSON string value.
|
|
150
|
-
*/
|
|
151
|
-
function bulkEdit(value) {
|
|
152
|
-
if (value.match(ARRAY_OR_OBJECT)) {
|
|
153
|
-
this.edit(JSON.parse(value));
|
|
154
|
-
|
|
155
|
-
this._bubbleUp(Events.Converted);
|
|
156
|
-
} else {
|
|
157
|
-
this.edit(value);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Cancel any modifications to the element.
|
|
162
|
-
*/
|
|
163
|
-
|
|
164
|
-
}, {
|
|
165
|
-
key: "cancel",
|
|
166
|
-
value: function cancel() {
|
|
167
|
-
if (this.elements) {
|
|
168
|
-
var _iterator = _createForOfIteratorHelper(this.elements),
|
|
169
|
-
_step;
|
|
170
|
-
|
|
171
|
-
try {
|
|
172
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
173
|
-
var element = _step.value;
|
|
174
|
-
element.cancel();
|
|
175
|
-
}
|
|
176
|
-
} catch (err) {
|
|
177
|
-
_iterator.e(err);
|
|
178
|
-
} finally {
|
|
179
|
-
_iterator.f();
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (this.isModified()) {
|
|
184
|
-
this.revert();
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}, {
|
|
188
|
-
key: "edit",
|
|
189
|
-
value: function edit(value) {
|
|
190
|
-
this.currentType = TypeChecker.type(value);
|
|
191
|
-
|
|
192
|
-
if (this._isExpandable(value) && !this._isExpandable(this.currentValue)) {
|
|
193
|
-
this.currentValue = null;
|
|
194
|
-
this.elements = this._generateElements(value);
|
|
195
|
-
} else if (!this._isExpandable(value) && this.elements) {
|
|
196
|
-
this.currentValue = value;
|
|
197
|
-
this.elements = undefined;
|
|
198
|
-
} else {
|
|
199
|
-
this.currentValue = value;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
this.setValid();
|
|
203
|
-
|
|
204
|
-
this._bubbleUp(Events.Edited);
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Get an element by its key.
|
|
208
|
-
*
|
|
209
|
-
* @param {String} key - The key name.
|
|
210
|
-
*
|
|
211
|
-
* @returns {Element} The element.
|
|
212
|
-
*/
|
|
213
|
-
|
|
214
|
-
}, {
|
|
215
|
-
key: "get",
|
|
216
|
-
value: function get(key) {
|
|
217
|
-
return this.elements ? this.elements.get(key) : undefined;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Get an element by its index.
|
|
221
|
-
*
|
|
222
|
-
* @param {Number} i - The index.
|
|
223
|
-
*
|
|
224
|
-
* @returns {Element} The element.
|
|
225
|
-
*/
|
|
226
|
-
|
|
227
|
-
}, {
|
|
228
|
-
key: "at",
|
|
229
|
-
value: function at(i) {
|
|
230
|
-
return this.elements ? this.elements.at(i) : undefined;
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Go to the next edit.
|
|
234
|
-
*
|
|
235
|
-
* Will check if the value is either { or [ and take appropriate action.
|
|
236
|
-
*
|
|
237
|
-
* @returns {Element} The next element.
|
|
238
|
-
*/
|
|
239
|
-
|
|
240
|
-
}, {
|
|
241
|
-
key: "next",
|
|
242
|
-
value: function next() {
|
|
243
|
-
if (this.currentValue === CURLY) {
|
|
244
|
-
return this._convertToEmptyObject();
|
|
245
|
-
} else if (this.currentValue === BRACKET) {
|
|
246
|
-
return this._convertToEmptyArray();
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
return this._next();
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Rename the element. Update the parent's mapping if available.
|
|
253
|
-
*
|
|
254
|
-
* @param {String} key - The new key.
|
|
255
|
-
*/
|
|
256
|
-
|
|
257
|
-
}, {
|
|
258
|
-
key: "rename",
|
|
259
|
-
value: function rename(key) {
|
|
260
|
-
if (this.parent !== undefined) {
|
|
261
|
-
var elm = this.parent.elements._map[this.currentKey];
|
|
262
|
-
delete this.parent.elements._map[this.currentKey];
|
|
263
|
-
this.parent.elements._map[key] = elm;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
this.currentKey = key;
|
|
267
|
-
|
|
268
|
-
this._bubbleUp(Events.Edited);
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Generate the javascript object for this element.
|
|
272
|
-
*
|
|
273
|
-
* @returns {Object} The javascript object.
|
|
274
|
-
*/
|
|
275
|
-
|
|
276
|
-
}, {
|
|
277
|
-
key: "generateObject",
|
|
278
|
-
value: function generateObject() {
|
|
279
|
-
if (this.currentType === 'Array') {
|
|
280
|
-
return ObjectGenerator.generateArray(this.elements);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
if (this.elements) {
|
|
284
|
-
return ObjectGenerator.generate(this.elements);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
return this.currentValue;
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Generate the javascript object representing the original values
|
|
291
|
-
* for this element (pre-element removal, renaming, editing).
|
|
292
|
-
*
|
|
293
|
-
* @returns {Object} The javascript object.
|
|
294
|
-
*/
|
|
295
|
-
|
|
296
|
-
}, {
|
|
297
|
-
key: "generateOriginalObject",
|
|
298
|
-
value: function generateOriginalObject() {
|
|
299
|
-
if (this.type === 'Array') {
|
|
300
|
-
var originalElements = this._generateElements(this.originalExpandableValue);
|
|
301
|
-
|
|
302
|
-
return ObjectGenerator.generateOriginalArray(originalElements);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
if (this.type === 'Object') {
|
|
306
|
-
var _originalElements = this._generateElements(this.originalExpandableValue);
|
|
307
|
-
|
|
308
|
-
return ObjectGenerator.generateOriginal(_originalElements);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
return this.value;
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Insert an element after the provided element. If this element is an array,
|
|
315
|
-
* then ignore the key specified by the caller and use the correct index.
|
|
316
|
-
* Update the keys of the rest of the elements in the LinkedList.
|
|
317
|
-
*
|
|
318
|
-
* @param {Element} element - The element to insert after.
|
|
319
|
-
* @param {String} key - The key.
|
|
320
|
-
* @param {Object} value - The value.
|
|
321
|
-
*
|
|
322
|
-
* @returns {Element} The new element.
|
|
323
|
-
*/
|
|
324
|
-
|
|
325
|
-
}, {
|
|
326
|
-
key: "insertAfter",
|
|
327
|
-
value: function insertAfter(element, key, value) {
|
|
328
|
-
if (this.currentType === 'Array') {
|
|
329
|
-
if (element.currentKey === '') {
|
|
330
|
-
this.elements.handleEmptyKeys(element);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
key = element.currentKey + 1;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
var newElement = this.elements.insertAfter(element, key, value, true, this);
|
|
337
|
-
|
|
338
|
-
if (this.currentType === 'Array') {
|
|
339
|
-
this.elements.updateKeys(newElement, 1);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
this._bubbleUp(Events.Added);
|
|
343
|
-
|
|
344
|
-
return newElement;
|
|
345
|
-
}
|
|
346
|
-
/**
|
|
347
|
-
* Add a new element to this element.
|
|
348
|
-
*
|
|
349
|
-
* @param {String | Number} key - The element key.
|
|
350
|
-
* @param {Object} value - The value.
|
|
351
|
-
*
|
|
352
|
-
* @returns {Element} The new element.
|
|
353
|
-
*/
|
|
354
|
-
|
|
355
|
-
}, {
|
|
356
|
-
key: "insertEnd",
|
|
357
|
-
value: function insertEnd(key, value) {
|
|
358
|
-
if (this.currentType === 'Array') {
|
|
359
|
-
this.elements.flush();
|
|
360
|
-
key = 0;
|
|
361
|
-
|
|
362
|
-
if (this.elements.lastElement) {
|
|
363
|
-
if (this.elements.lastElement.currentKey === '') {
|
|
364
|
-
this.elements.handleEmptyKeys(this.elements.lastElement);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
key = this.elements.lastElement.currentKey + 1;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
var newElement = this.elements.insertEnd(key, value, true, this);
|
|
372
|
-
|
|
373
|
-
this._bubbleUp(Events.Added);
|
|
374
|
-
|
|
375
|
-
return newElement;
|
|
376
|
-
}
|
|
377
|
-
/**
|
|
378
|
-
* Insert a placeholder element at the end of the element.
|
|
379
|
-
*
|
|
380
|
-
* @returns {Element} The placeholder element.
|
|
381
|
-
*/
|
|
382
|
-
|
|
383
|
-
}, {
|
|
384
|
-
key: "insertPlaceholder",
|
|
385
|
-
value: function insertPlaceholder() {
|
|
386
|
-
var newElement = this.elements.insertEnd('', '', true, this);
|
|
387
|
-
|
|
388
|
-
this._bubbleUp(Events.Added);
|
|
389
|
-
|
|
390
|
-
return newElement;
|
|
391
|
-
}
|
|
392
|
-
/**
|
|
393
|
-
* Is the element a newly added element?
|
|
394
|
-
*
|
|
395
|
-
* @returns {Boolean} If the element is newly added.
|
|
396
|
-
*/
|
|
397
|
-
|
|
398
|
-
}, {
|
|
399
|
-
key: "isAdded",
|
|
400
|
-
value: function isAdded() {
|
|
401
|
-
return this.added || this.parent && this.parent.isAdded();
|
|
402
|
-
}
|
|
403
|
-
/**
|
|
404
|
-
* Is the element blank?
|
|
405
|
-
*
|
|
406
|
-
* @returns {Boolean} If the element is blank.
|
|
407
|
-
*/
|
|
408
|
-
|
|
409
|
-
}, {
|
|
410
|
-
key: "isBlank",
|
|
411
|
-
value: function isBlank() {
|
|
412
|
-
return this.currentKey === '' && this.currentValue === '';
|
|
413
|
-
}
|
|
414
|
-
/**
|
|
415
|
-
* Does the element have a valid value for the current type?
|
|
416
|
-
*
|
|
417
|
-
* @returns {Boolean} If the value is valid.
|
|
418
|
-
*/
|
|
419
|
-
|
|
420
|
-
}, {
|
|
421
|
-
key: "isCurrentTypeValid",
|
|
422
|
-
value: function isCurrentTypeValid() {
|
|
423
|
-
return this.currentTypeValid;
|
|
424
|
-
}
|
|
425
|
-
/**
|
|
426
|
-
* Set the element as valid.
|
|
427
|
-
*/
|
|
428
|
-
|
|
429
|
-
}, {
|
|
430
|
-
key: "setValid",
|
|
431
|
-
value: function setValid() {
|
|
432
|
-
this.currentTypeValid = true;
|
|
433
|
-
this.invalidTypeMessage = undefined;
|
|
434
|
-
|
|
435
|
-
this._bubbleUp(Events.Valid, this.uuid);
|
|
436
|
-
}
|
|
437
|
-
/**
|
|
438
|
-
* Set the element as invalid.
|
|
439
|
-
*
|
|
440
|
-
* @param {Object} value - The value.
|
|
441
|
-
* @param {String} newType - The new type.
|
|
442
|
-
* @param {String} message - The error message.
|
|
443
|
-
*/
|
|
444
|
-
|
|
445
|
-
}, {
|
|
446
|
-
key: "setInvalid",
|
|
447
|
-
value: function setInvalid(value, newType, message) {
|
|
448
|
-
this.currentValue = value;
|
|
449
|
-
this.currentType = newType;
|
|
450
|
-
this.currentTypeValid = false;
|
|
451
|
-
this.invalidTypeMessage = message;
|
|
452
|
-
|
|
453
|
-
this._bubbleUp(Events.Invalid, this.uuid);
|
|
454
|
-
}
|
|
455
|
-
/**
|
|
456
|
-
* Determine if the key is a duplicate.
|
|
457
|
-
*
|
|
458
|
-
* @param {String} value - The value to check.
|
|
459
|
-
*
|
|
460
|
-
* @returns {Boolean} If the key is a duplicate.
|
|
461
|
-
*/
|
|
462
|
-
|
|
463
|
-
}, {
|
|
464
|
-
key: "isDuplicateKey",
|
|
465
|
-
value: function isDuplicateKey(value) {
|
|
466
|
-
if (value === this.currentKey) {
|
|
467
|
-
return false;
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
var _iterator2 = _createForOfIteratorHelper(this.parent.elements),
|
|
471
|
-
_step2;
|
|
472
|
-
|
|
473
|
-
try {
|
|
474
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
475
|
-
var element = _step2.value;
|
|
476
|
-
|
|
477
|
-
if (element.currentKey === value) {
|
|
478
|
-
return true;
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
} catch (err) {
|
|
482
|
-
_iterator2.e(err);
|
|
483
|
-
} finally {
|
|
484
|
-
_iterator2.f();
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
return false;
|
|
488
|
-
}
|
|
489
|
-
/**
|
|
490
|
-
* Determine if the element is edited - returns true if
|
|
491
|
-
* the key or value changed. Does not count array values whose keys have
|
|
492
|
-
* changed as edited.
|
|
493
|
-
*
|
|
494
|
-
* @returns {Boolean} If the element is edited.
|
|
495
|
-
*/
|
|
496
|
-
|
|
497
|
-
}, {
|
|
498
|
-
key: "isEdited",
|
|
499
|
-
value: function isEdited() {
|
|
500
|
-
return (this.isRenamed() || !this._valuesEqual() || this.type !== this.currentType) && !this.isAdded();
|
|
501
|
-
}
|
|
502
|
-
/**
|
|
503
|
-
* Check for value equality.
|
|
504
|
-
* @returns {Boolean} If the value is equal.
|
|
505
|
-
*/
|
|
506
|
-
|
|
507
|
-
}, {
|
|
508
|
-
key: "_valuesEqual",
|
|
509
|
-
value: function _valuesEqual() {
|
|
510
|
-
if (this.currentType === 'Date' && isString(this.currentValue)) {
|
|
511
|
-
return isEqual(this.value, new Date(this.currentValue));
|
|
512
|
-
} else if (this.currentType === 'ObjectId' && isString(this.currentValue)) {
|
|
513
|
-
return this._isObjectIdEqual();
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
return isEqual(this.value, this.currentValue);
|
|
517
|
-
}
|
|
518
|
-
}, {
|
|
519
|
-
key: "_isObjectIdEqual",
|
|
520
|
-
value: function _isObjectIdEqual() {
|
|
521
|
-
try {
|
|
522
|
-
return this.value.toHexString() === this.currentValue;
|
|
523
|
-
} catch (_) {
|
|
524
|
-
return false;
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
/**
|
|
528
|
-
* Is the element the last in the elements.
|
|
529
|
-
*
|
|
530
|
-
* @returns {Boolean} If the element is last.
|
|
531
|
-
*/
|
|
532
|
-
|
|
533
|
-
}, {
|
|
534
|
-
key: "isLast",
|
|
535
|
-
value: function isLast() {
|
|
536
|
-
return this.parent.elements.lastElement === this;
|
|
537
|
-
}
|
|
538
|
-
/**
|
|
539
|
-
* Determine if the element is renamed.
|
|
540
|
-
*
|
|
541
|
-
* @returns {Boolean} If the element was renamed.
|
|
542
|
-
*/
|
|
543
|
-
|
|
544
|
-
}, {
|
|
545
|
-
key: "isRenamed",
|
|
546
|
-
value: function isRenamed() {
|
|
547
|
-
var keyChanged = false;
|
|
548
|
-
|
|
549
|
-
if (!this.parent || this.parent.isRoot() || this.parent.currentType === 'Object') {
|
|
550
|
-
keyChanged = this.key !== this.currentKey;
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
return keyChanged;
|
|
554
|
-
}
|
|
555
|
-
/**
|
|
556
|
-
* Can changes to the elemnt be reverted?
|
|
557
|
-
*
|
|
558
|
-
* @returns {Boolean} If the element can be reverted.
|
|
559
|
-
*/
|
|
560
|
-
|
|
561
|
-
}, {
|
|
562
|
-
key: "isRevertable",
|
|
563
|
-
value: function isRevertable() {
|
|
564
|
-
return this.isEdited() || this.isRemoved();
|
|
565
|
-
}
|
|
566
|
-
/**
|
|
567
|
-
* Can the element be removed?
|
|
568
|
-
*
|
|
569
|
-
* @returns {Boolean} If the element can be removed.
|
|
570
|
-
*/
|
|
571
|
-
|
|
572
|
-
}, {
|
|
573
|
-
key: "isRemovable",
|
|
574
|
-
value: function isRemovable() {
|
|
575
|
-
return !this.parent.isRemoved();
|
|
576
|
-
}
|
|
577
|
-
/**
|
|
578
|
-
* Can no action be taken on the element?
|
|
579
|
-
*
|
|
580
|
-
* @returns {Boolean} If no action can be taken.
|
|
581
|
-
*/
|
|
582
|
-
|
|
583
|
-
}, {
|
|
584
|
-
key: "isNotActionable",
|
|
585
|
-
value: function isNotActionable() {
|
|
586
|
-
return this.key === ID && !this.isAdded() || !this.isRemovable();
|
|
587
|
-
}
|
|
588
|
-
/**
|
|
589
|
-
* Determine if the value is editable.
|
|
590
|
-
*
|
|
591
|
-
* @returns {Boolean} If the value is editable.
|
|
592
|
-
*/
|
|
593
|
-
|
|
594
|
-
}, {
|
|
595
|
-
key: "isValueEditable",
|
|
596
|
-
value: function isValueEditable() {
|
|
597
|
-
return this.isKeyEditable() && !UNEDITABLE_TYPES.includes(this.currentType);
|
|
598
|
-
}
|
|
599
|
-
/**
|
|
600
|
-
* Determine if the key of the parent element is editable.
|
|
601
|
-
*
|
|
602
|
-
* @returns {Boolean} If the parent's key is editable.
|
|
603
|
-
*/
|
|
604
|
-
|
|
605
|
-
}, {
|
|
606
|
-
key: "isParentEditable",
|
|
607
|
-
value: function isParentEditable() {
|
|
608
|
-
if (this.parent && !this.parent.isRoot()) {
|
|
609
|
-
return this.parent.isKeyEditable();
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
return true;
|
|
613
|
-
}
|
|
614
|
-
/**
|
|
615
|
-
* Determine if the key is editable.
|
|
616
|
-
*
|
|
617
|
-
* @returns {Boolean} If the key is editable.
|
|
618
|
-
*/
|
|
619
|
-
|
|
620
|
-
}, {
|
|
621
|
-
key: "isKeyEditable",
|
|
622
|
-
value: function isKeyEditable() {
|
|
623
|
-
return this.isParentEditable() && (this.isAdded() || this.currentKey !== ID);
|
|
624
|
-
}
|
|
625
|
-
/**
|
|
626
|
-
* Determine if the element is modified at all.
|
|
627
|
-
*
|
|
628
|
-
* @returns {Boolean} If the element is modified.
|
|
629
|
-
*/
|
|
630
|
-
|
|
631
|
-
}, {
|
|
632
|
-
key: "isModified",
|
|
633
|
-
value: function isModified() {
|
|
634
|
-
if (this.elements) {
|
|
635
|
-
var _iterator3 = _createForOfIteratorHelper(this.elements),
|
|
636
|
-
_step3;
|
|
637
|
-
|
|
638
|
-
try {
|
|
639
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
640
|
-
var element = _step3.value;
|
|
641
|
-
|
|
642
|
-
if (element.isModified()) {
|
|
643
|
-
return true;
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
} catch (err) {
|
|
647
|
-
_iterator3.e(err);
|
|
648
|
-
} finally {
|
|
649
|
-
_iterator3.f();
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
return this.isAdded() || this.isEdited() || this.isRemoved();
|
|
654
|
-
}
|
|
655
|
-
/**
|
|
656
|
-
* Is the element flagged for removal?
|
|
657
|
-
*
|
|
658
|
-
* @returns {Boolean} If the element is flagged for removal.
|
|
659
|
-
*/
|
|
660
|
-
|
|
661
|
-
}, {
|
|
662
|
-
key: "isRemoved",
|
|
663
|
-
value: function isRemoved() {
|
|
664
|
-
return this.removed;
|
|
665
|
-
}
|
|
666
|
-
/**
|
|
667
|
-
* Elements themselves are not the root.
|
|
668
|
-
*
|
|
669
|
-
* @returns {false} Always false.
|
|
670
|
-
*/
|
|
671
|
-
|
|
672
|
-
}, {
|
|
673
|
-
key: "isRoot",
|
|
674
|
-
value: function isRoot() {
|
|
675
|
-
return false;
|
|
676
|
-
}
|
|
677
|
-
/**
|
|
678
|
-
* Flag the element for removal.
|
|
679
|
-
*/
|
|
680
|
-
|
|
681
|
-
}, {
|
|
682
|
-
key: "remove",
|
|
683
|
-
value: function remove() {
|
|
684
|
-
this.revert();
|
|
685
|
-
this.removed = true;
|
|
686
|
-
|
|
687
|
-
this._bubbleUp(Events.Removed);
|
|
688
|
-
}
|
|
689
|
-
/**
|
|
690
|
-
* Revert the changes to the element.
|
|
691
|
-
*/
|
|
692
|
-
|
|
693
|
-
}, {
|
|
694
|
-
key: "revert",
|
|
695
|
-
value: function revert() {
|
|
696
|
-
if (this.isAdded()) {
|
|
697
|
-
if (this.parent && this.parent.currentType === 'Array') {
|
|
698
|
-
this.parent.elements.updateKeys(this, -1);
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
this.parent.elements.remove(this);
|
|
702
|
-
this.parent.emit(Events.Removed);
|
|
703
|
-
this.parent = null;
|
|
704
|
-
} else {
|
|
705
|
-
if (this.originalExpandableValue) {
|
|
706
|
-
this.elements = this._generateElements(this.originalExpandableValue);
|
|
707
|
-
this.currentValue = undefined;
|
|
708
|
-
} else {
|
|
709
|
-
if (this.currentValue === null && this.value !== null) {
|
|
710
|
-
this.elements = null;
|
|
711
|
-
} else {
|
|
712
|
-
this._removeAddedElements();
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
this.currentValue = this.value;
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
this.currentKey = this.key;
|
|
719
|
-
this.currentType = this.type;
|
|
720
|
-
this.removed = false;
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
this.setValid();
|
|
724
|
-
|
|
725
|
-
this._bubbleUp(Events.Reverted);
|
|
726
|
-
}
|
|
727
|
-
/**
|
|
728
|
-
* Fire and bubble up the event.
|
|
729
|
-
*
|
|
730
|
-
* @param {Event} evt - The event.
|
|
731
|
-
* @param {*} data - Optional.
|
|
732
|
-
*/
|
|
733
|
-
|
|
734
|
-
}, {
|
|
735
|
-
key: "_bubbleUp",
|
|
736
|
-
value: function _bubbleUp(evt, data) {
|
|
737
|
-
this.emit(evt, data);
|
|
738
|
-
var element = this.parent;
|
|
739
|
-
|
|
740
|
-
if (element) {
|
|
741
|
-
if (element.isRoot()) {
|
|
742
|
-
element.emit(evt, data);
|
|
743
|
-
} else {
|
|
744
|
-
element._bubbleUp(evt, data);
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
/**
|
|
749
|
-
* Convert this element to an empty object.
|
|
750
|
-
*/
|
|
751
|
-
|
|
752
|
-
}, {
|
|
753
|
-
key: "_convertToEmptyObject",
|
|
754
|
-
value: function _convertToEmptyObject() {
|
|
755
|
-
this.edit({});
|
|
756
|
-
this.insertPlaceholder();
|
|
757
|
-
}
|
|
758
|
-
/**
|
|
759
|
-
* Convert to an empty array.
|
|
760
|
-
*/
|
|
761
|
-
|
|
762
|
-
}, {
|
|
763
|
-
key: "_convertToEmptyArray",
|
|
764
|
-
value: function _convertToEmptyArray() {
|
|
765
|
-
this.edit([]);
|
|
766
|
-
this.insertPlaceholder();
|
|
767
|
-
}
|
|
768
|
-
/**
|
|
769
|
-
* Is the element empty?
|
|
770
|
-
*
|
|
771
|
-
* @param {Element} element - The element to check.
|
|
772
|
-
*
|
|
773
|
-
* @returns {Boolean} If the element is empty.
|
|
774
|
-
*/
|
|
775
|
-
|
|
776
|
-
}, {
|
|
777
|
-
key: "_isElementEmpty",
|
|
778
|
-
value: function _isElementEmpty(element) {
|
|
779
|
-
return element && element.isAdded() && element.isBlank();
|
|
780
|
-
}
|
|
781
|
-
/**
|
|
782
|
-
* Check if the value is expandable.
|
|
783
|
-
*
|
|
784
|
-
* @param {Object} value - The value to check.
|
|
785
|
-
*
|
|
786
|
-
* @returns {Boolean} If the value is expandable.
|
|
787
|
-
*/
|
|
788
|
-
|
|
789
|
-
}, {
|
|
790
|
-
key: "_isExpandable",
|
|
791
|
-
value: function _isExpandable(value) {
|
|
792
|
-
return isObject(value) || isArray(value);
|
|
793
|
-
}
|
|
794
|
-
/**
|
|
795
|
-
* Generates a sequence of child elements.
|
|
796
|
-
*
|
|
797
|
-
* @param {Object} object - The object to generate from.
|
|
798
|
-
*
|
|
799
|
-
* @returns {Array} The elements.
|
|
800
|
-
*/
|
|
801
|
-
|
|
802
|
-
}, {
|
|
803
|
-
key: "_generateElements",
|
|
804
|
-
value: function _generateElements(object) {
|
|
805
|
-
return new LinkedList(this, object); // eslint-disable-line no-use-before-define
|
|
806
|
-
}
|
|
807
|
-
/**
|
|
808
|
-
* Get the key for the element.
|
|
809
|
-
*
|
|
810
|
-
* @param {String} key
|
|
811
|
-
* @param {Number} index
|
|
812
|
-
*
|
|
813
|
-
* @returns {String|Number} The index if the type is an array, or the key.
|
|
814
|
-
*/
|
|
815
|
-
|
|
816
|
-
}, {
|
|
817
|
-
key: "_key",
|
|
818
|
-
value: function _key(key, index) {
|
|
819
|
-
return this.currentType === 'Array' ? index : key;
|
|
820
|
-
}
|
|
821
|
-
/**
|
|
822
|
-
* Add a new element to the parent.
|
|
823
|
-
*/
|
|
824
|
-
|
|
825
|
-
}, {
|
|
826
|
-
key: "_next",
|
|
827
|
-
value: function _next() {
|
|
828
|
-
if (!this._isElementEmpty(this.nextElement) && !this._isElementEmpty(this)) {
|
|
829
|
-
this.parent.insertAfter(this, '', '');
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
/**
|
|
833
|
-
* Removes the added elements from the element.
|
|
834
|
-
*/
|
|
835
|
-
|
|
836
|
-
}, {
|
|
837
|
-
key: "_removeAddedElements",
|
|
838
|
-
value: function _removeAddedElements() {
|
|
839
|
-
if (this.elements) {
|
|
840
|
-
var _iterator4 = _createForOfIteratorHelper(this.elements),
|
|
841
|
-
_step4;
|
|
842
|
-
|
|
843
|
-
try {
|
|
844
|
-
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
845
|
-
var element = _step4.value;
|
|
846
|
-
|
|
847
|
-
if (element.isAdded()) {
|
|
848
|
-
this.elements.remove(element);
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
} catch (err) {
|
|
852
|
-
_iterator4.e(err);
|
|
853
|
-
} finally {
|
|
854
|
-
_iterator4.f();
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
}]);
|
|
859
|
-
|
|
860
|
-
return Element;
|
|
861
|
-
}(EventEmitter);
|
|
862
|
-
/**
|
|
863
|
-
* Represents a doubly linked list.
|
|
864
|
-
*/
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
var LinkedList = /*#__PURE__*/function (_Symbol$iterator) {
|
|
868
|
-
// Instantiate the new doubly linked list.
|
|
869
|
-
function LinkedList(doc, originalDoc) {
|
|
870
|
-
_classCallCheck(this, LinkedList);
|
|
871
|
-
|
|
872
|
-
this.firstElement = null;
|
|
873
|
-
this.lastElement = null;
|
|
874
|
-
this.doc = doc;
|
|
875
|
-
this.originalDoc = originalDoc;
|
|
876
|
-
this.keys = keys(this.originalDoc);
|
|
877
|
-
|
|
878
|
-
if (this.doc.currentType === 'Array') {
|
|
879
|
-
this.keys = this.keys.map(function (k) {
|
|
880
|
-
return parseInt(k, 10);
|
|
881
|
-
});
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
this.size = this.keys.length;
|
|
885
|
-
this.loaded = 0;
|
|
886
|
-
this._map = {};
|
|
887
|
-
}
|
|
888
|
-
/**
|
|
889
|
-
* Insert data after the provided element.
|
|
890
|
-
*
|
|
891
|
-
* @param {Element} element - The element to insert after.
|
|
892
|
-
* @param {String} key - The element key.
|
|
893
|
-
* @param {Object} value - The element value.
|
|
894
|
-
* @param {Boolean} added - If the element is new.
|
|
895
|
-
* @param {Object} parent - The parent.
|
|
896
|
-
*
|
|
897
|
-
* @returns {Element} The inserted element.
|
|
898
|
-
*/
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
_createClass(LinkedList, [{
|
|
902
|
-
key: "at",
|
|
903
|
-
value:
|
|
904
|
-
/**
|
|
905
|
-
* Get the element at the provided index.
|
|
906
|
-
*
|
|
907
|
-
* @param {Integer} index - The index.
|
|
908
|
-
*
|
|
909
|
-
* @returns {Element} The matching element.
|
|
910
|
-
*/
|
|
911
|
-
function at(index) {
|
|
912
|
-
this.flush();
|
|
913
|
-
|
|
914
|
-
if (!Number.isInteger(index)) {
|
|
915
|
-
return undefined;
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
var element = this.firstElement;
|
|
919
|
-
|
|
920
|
-
for (var i = 0; i < index; i++) {
|
|
921
|
-
if (!element) {
|
|
922
|
-
return undefined;
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
element = element.nextElement;
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
return element === null ? undefined : element;
|
|
929
|
-
}
|
|
930
|
-
}, {
|
|
931
|
-
key: "get",
|
|
932
|
-
value: function get(key) {
|
|
933
|
-
this.flush();
|
|
934
|
-
return this._map[key];
|
|
935
|
-
}
|
|
936
|
-
}, {
|
|
937
|
-
key: "insertAfter",
|
|
938
|
-
value: function insertAfter(element, key, value, added, parent) {
|
|
939
|
-
this.flush();
|
|
940
|
-
return this._insertAfter(element, key, value, added, parent);
|
|
941
|
-
}
|
|
942
|
-
/**
|
|
943
|
-
* Update the currentKey of each element if array elements.
|
|
944
|
-
*
|
|
945
|
-
* @param {Element} element - The element to insert after.
|
|
946
|
-
* @param {Number} add - 1 if adding a new element, -1 if removing.
|
|
947
|
-
*/
|
|
948
|
-
|
|
949
|
-
}, {
|
|
950
|
-
key: "updateKeys",
|
|
951
|
-
value: function updateKeys(element, add) {
|
|
952
|
-
this.flush();
|
|
953
|
-
|
|
954
|
-
while (element.nextElement) {
|
|
955
|
-
element.nextElement.currentKey += add;
|
|
956
|
-
element = element.nextElement;
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
/**
|
|
960
|
-
* If an element is added after a placeholder, convert that placeholder
|
|
961
|
-
* into an empty element with the correct key.
|
|
962
|
-
*
|
|
963
|
-
* @param {Element} element - The placeholder element.
|
|
964
|
-
*/
|
|
965
|
-
|
|
966
|
-
}, {
|
|
967
|
-
key: "handleEmptyKeys",
|
|
968
|
-
value: function handleEmptyKeys(element) {
|
|
969
|
-
if (element.currentKey === '') {
|
|
970
|
-
var e = element;
|
|
971
|
-
|
|
972
|
-
while (e.currentKey === '') {
|
|
973
|
-
if (!e.previousElement) {
|
|
974
|
-
e.currentKey = 0;
|
|
975
|
-
break;
|
|
976
|
-
} else {
|
|
977
|
-
e = e.previousElement;
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
while (e.nextElement) {
|
|
982
|
-
e.nextElement.currentKey = e.currentKey + 1;
|
|
983
|
-
e = e.nextElement;
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
/**
|
|
988
|
-
* Insert data before the provided element.
|
|
989
|
-
*
|
|
990
|
-
* @param {Element} element - The element to insert before.
|
|
991
|
-
* @param {String} key - The element key.
|
|
992
|
-
* @param {Object} value - The element value.
|
|
993
|
-
* @param {Boolean} added - If the element is new.
|
|
994
|
-
* @param {Object} parent - The parent.
|
|
995
|
-
*
|
|
996
|
-
* @returns {Element} The inserted element.
|
|
997
|
-
*/
|
|
998
|
-
|
|
999
|
-
}, {
|
|
1000
|
-
key: "insertBefore",
|
|
1001
|
-
value: function insertBefore(element, key, value, added, parent) {
|
|
1002
|
-
this.flush();
|
|
1003
|
-
return this._insertBefore(element, key, value, added, parent);
|
|
1004
|
-
}
|
|
1005
|
-
/**
|
|
1006
|
-
* Insert data at the beginning of the list.
|
|
1007
|
-
*
|
|
1008
|
-
* @param {String} key - The element key.
|
|
1009
|
-
* @param {Object} value - The element value.
|
|
1010
|
-
* @param {Boolean} added - If the element is new.
|
|
1011
|
-
* @param {Object} parent - The parent.
|
|
1012
|
-
*
|
|
1013
|
-
* @returns {Element} The data element.
|
|
1014
|
-
*/
|
|
1015
|
-
|
|
1016
|
-
}, {
|
|
1017
|
-
key: "insertBeginning",
|
|
1018
|
-
value: function insertBeginning(key, value, added, parent) {
|
|
1019
|
-
this.flush();
|
|
1020
|
-
return this._insertBeginning(key, value, added, parent);
|
|
1021
|
-
}
|
|
1022
|
-
/**
|
|
1023
|
-
* Insert data at the end of the list.
|
|
1024
|
-
*
|
|
1025
|
-
* @param {String} key - The element key.
|
|
1026
|
-
* @param {Object} value - The element value.
|
|
1027
|
-
* @param {Boolean} added - If the element is new.
|
|
1028
|
-
* @param {Object} parent - The parent.
|
|
1029
|
-
*
|
|
1030
|
-
* @returns {Element} The data element.
|
|
1031
|
-
*/
|
|
1032
|
-
|
|
1033
|
-
}, {
|
|
1034
|
-
key: "insertEnd",
|
|
1035
|
-
value: function insertEnd(key, value, added, parent) {
|
|
1036
|
-
this.flush();
|
|
1037
|
-
|
|
1038
|
-
if (!this.lastElement) {
|
|
1039
|
-
return this.insertBeginning(key, value, added, parent);
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1042
|
-
return this.insertAfter(this.lastElement, key, value, added, parent);
|
|
1043
|
-
}
|
|
1044
|
-
}, {
|
|
1045
|
-
key: "flush",
|
|
1046
|
-
value: function flush() {
|
|
1047
|
-
if (this.loaded < this.size) {
|
|
1048
|
-
// Only iterate from the loaded index to the size.
|
|
1049
|
-
var _iterator5 = _createForOfIteratorHelper(this),
|
|
1050
|
-
_step5;
|
|
1051
|
-
|
|
1052
|
-
try {
|
|
1053
|
-
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
1054
|
-
var element = _step5.value;
|
|
1055
|
-
|
|
1056
|
-
if (element && element.elements) {
|
|
1057
|
-
element.elements.flush();
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
} catch (err) {
|
|
1061
|
-
_iterator5.e(err);
|
|
1062
|
-
} finally {
|
|
1063
|
-
_iterator5.f();
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
/**
|
|
1068
|
-
* Get an iterator for the list.
|
|
1069
|
-
*
|
|
1070
|
-
* @returns {Iterator} The iterator.
|
|
1071
|
-
*/
|
|
1072
|
-
|
|
1073
|
-
}, {
|
|
1074
|
-
key: _Symbol$iterator,
|
|
1075
|
-
value: function value() {
|
|
1076
|
-
var _this2 = this;
|
|
1077
|
-
|
|
1078
|
-
var currentElement;
|
|
1079
|
-
var index = 0;
|
|
1080
|
-
return {
|
|
1081
|
-
next: function next() {
|
|
1082
|
-
if (_this2._needsLazyLoad(index)) {
|
|
1083
|
-
var key = _this2.keys[index];
|
|
1084
|
-
index += 1;
|
|
1085
|
-
currentElement = _this2._lazyInsertEnd(key);
|
|
1086
|
-
return {
|
|
1087
|
-
value: currentElement
|
|
1088
|
-
};
|
|
1089
|
-
} else if (_this2._needsStandardIteration(index)) {
|
|
1090
|
-
if (currentElement) {
|
|
1091
|
-
currentElement = currentElement.nextElement;
|
|
1092
|
-
} else {
|
|
1093
|
-
currentElement = _this2.firstElement;
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
if (currentElement) {
|
|
1097
|
-
index += 1;
|
|
1098
|
-
return {
|
|
1099
|
-
value: currentElement
|
|
1100
|
-
};
|
|
1101
|
-
}
|
|
1102
|
-
|
|
1103
|
-
return {
|
|
1104
|
-
done: true
|
|
1105
|
-
};
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
return {
|
|
1109
|
-
done: true
|
|
1110
|
-
};
|
|
1111
|
-
}
|
|
1112
|
-
};
|
|
1113
|
-
}
|
|
1114
|
-
}, {
|
|
1115
|
-
key: "_needsLazyLoad",
|
|
1116
|
-
value: function _needsLazyLoad(index) {
|
|
1117
|
-
return index === 0 && this.loaded === 0 && this.size > 0 || this.loaded <= index && index < this.size;
|
|
1118
|
-
}
|
|
1119
|
-
}, {
|
|
1120
|
-
key: "_needsStandardIteration",
|
|
1121
|
-
value: function _needsStandardIteration(index) {
|
|
1122
|
-
return this.loaded > 0 && index < this.loaded && index < this.size;
|
|
1123
|
-
}
|
|
1124
|
-
/**
|
|
1125
|
-
* Insert on the end of the list lazily.
|
|
1126
|
-
*
|
|
1127
|
-
* @param {String} key - The key.
|
|
1128
|
-
*
|
|
1129
|
-
* @returns {Element} The inserted element.
|
|
1130
|
-
*/
|
|
1131
|
-
|
|
1132
|
-
}, {
|
|
1133
|
-
key: "_lazyInsertEnd",
|
|
1134
|
-
value: function _lazyInsertEnd(key) {
|
|
1135
|
-
this.size -= 1;
|
|
1136
|
-
return this._insertEnd(key, this.originalDoc[key], this.doc.cloned, this.doc);
|
|
1137
|
-
}
|
|
1138
|
-
}, {
|
|
1139
|
-
key: "_insertEnd",
|
|
1140
|
-
value: function _insertEnd(key, value, added, parent) {
|
|
1141
|
-
if (!this.lastElement) {
|
|
1142
|
-
return this._insertBeginning(key, value, added, parent);
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
|
-
return this._insertAfter(this.lastElement, key, value, added, parent);
|
|
1146
|
-
}
|
|
1147
|
-
}, {
|
|
1148
|
-
key: "_insertBefore",
|
|
1149
|
-
value: function _insertBefore(element, key, value, added, parent) {
|
|
1150
|
-
var newElement = new Element(key, value, added, parent, element.previousElement, element);
|
|
1151
|
-
|
|
1152
|
-
if (element.previousElement) {
|
|
1153
|
-
element.previousElement.nextElement = newElement;
|
|
1154
|
-
} else {
|
|
1155
|
-
this.firstElement = newElement;
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
|
-
element.previousElement = newElement;
|
|
1159
|
-
this._map[newElement.key] = newElement;
|
|
1160
|
-
this.size += 1;
|
|
1161
|
-
this.loaded += 1;
|
|
1162
|
-
return newElement;
|
|
1163
|
-
}
|
|
1164
|
-
}, {
|
|
1165
|
-
key: "_insertBeginning",
|
|
1166
|
-
value: function _insertBeginning(key, value, added, parent) {
|
|
1167
|
-
if (!this.firstElement) {
|
|
1168
|
-
var element = new Element(key, value, added, parent, null, null);
|
|
1169
|
-
this.firstElement = this.lastElement = element;
|
|
1170
|
-
this.size += 1;
|
|
1171
|
-
this.loaded += 1;
|
|
1172
|
-
this._map[element.key] = element;
|
|
1173
|
-
return element;
|
|
1174
|
-
}
|
|
1175
|
-
|
|
1176
|
-
var newElement = this.insertBefore(this.firstElement, key, value, added, parent);
|
|
1177
|
-
this._map[newElement.key] = newElement;
|
|
1178
|
-
return newElement;
|
|
1179
|
-
}
|
|
1180
|
-
}, {
|
|
1181
|
-
key: "_insertAfter",
|
|
1182
|
-
value: function _insertAfter(element, key, value, added, parent) {
|
|
1183
|
-
var newElement = new Element(key, value, added, parent, element, element.nextElement);
|
|
1184
|
-
|
|
1185
|
-
if (element.nextElement) {
|
|
1186
|
-
element.nextElement.previousElement = newElement;
|
|
1187
|
-
} else {
|
|
1188
|
-
this.lastElement = newElement;
|
|
1189
|
-
}
|
|
1190
|
-
|
|
1191
|
-
element.nextElement = newElement;
|
|
1192
|
-
this._map[newElement.key] = newElement;
|
|
1193
|
-
this.size += 1;
|
|
1194
|
-
this.loaded += 1;
|
|
1195
|
-
return newElement;
|
|
1196
|
-
}
|
|
1197
|
-
/**
|
|
1198
|
-
* Remove the element from the list.
|
|
1199
|
-
*
|
|
1200
|
-
* @param {Element} element - The element to remove.
|
|
1201
|
-
*
|
|
1202
|
-
* @returns {DoublyLinkedList} The list with the element removed.
|
|
1203
|
-
*/
|
|
1204
|
-
|
|
1205
|
-
}, {
|
|
1206
|
-
key: "remove",
|
|
1207
|
-
value: function remove(element) {
|
|
1208
|
-
this.flush();
|
|
1209
|
-
|
|
1210
|
-
if (element.previousElement) {
|
|
1211
|
-
element.previousElement.nextElement = element.nextElement;
|
|
1212
|
-
} else {
|
|
1213
|
-
this.firstElement = element.nextElement;
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
|
-
if (element.nextElement) {
|
|
1217
|
-
element.nextElement.previousElement = element.previousElement;
|
|
1218
|
-
} else {
|
|
1219
|
-
this.lastElement = element.previousElement;
|
|
1220
|
-
}
|
|
1221
|
-
|
|
1222
|
-
element.nextElement = element.previousElement = null;
|
|
1223
|
-
delete this._map[element.currentKey];
|
|
1224
|
-
this.size -= 1;
|
|
1225
|
-
this.loaded -= 1;
|
|
1226
|
-
return this;
|
|
1227
|
-
}
|
|
1228
|
-
}]);
|
|
1229
|
-
|
|
1230
|
-
return LinkedList;
|
|
1231
|
-
}(Symbol.iterator);
|
|
1232
|
-
|
|
1233
|
-
module.exports = Element;
|
|
1234
|
-
module.exports.LinkedList = LinkedList;
|
|
1235
|
-
module.exports.Events = Events;
|
|
1236
|
-
module.exports.DATE_FORMAT = DATE_FORMAT;
|