hadron-document 7.9.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.
Files changed (109) hide show
  1. package/README.md +5 -5
  2. package/dist/document.d.ts +53 -0
  3. package/dist/document.d.ts.map +1 -0
  4. package/dist/document.js +248 -0
  5. package/dist/document.js.map +1 -0
  6. package/dist/editor/date.d.ts +13 -0
  7. package/dist/editor/date.d.ts.map +1 -0
  8. package/dist/editor/date.js +65 -0
  9. package/dist/editor/date.js.map +1 -0
  10. package/dist/editor/decimal128.d.ts +9 -0
  11. package/dist/editor/decimal128.d.ts.map +1 -0
  12. package/dist/editor/decimal128.js +32 -0
  13. package/dist/editor/decimal128.js.map +1 -0
  14. package/dist/editor/double.d.ts +10 -0
  15. package/dist/editor/double.d.ts.map +1 -0
  16. package/dist/editor/double.js +44 -0
  17. package/dist/editor/double.js.map +1 -0
  18. package/dist/editor/index.d.ts +38 -0
  19. package/dist/editor/index.d.ts.map +1 -0
  20. package/dist/editor/index.js +51 -0
  21. package/dist/editor/index.js.map +1 -0
  22. package/dist/editor/int32.d.ts +7 -0
  23. package/dist/editor/int32.d.ts.map +1 -0
  24. package/dist/editor/int32.js +17 -0
  25. package/dist/editor/int32.js.map +1 -0
  26. package/dist/editor/int64.d.ts +9 -0
  27. package/dist/editor/int64.d.ts.map +1 -0
  28. package/dist/editor/int64.js +32 -0
  29. package/dist/editor/int64.js.map +1 -0
  30. package/dist/editor/null.d.ts +8 -0
  31. package/dist/editor/null.d.ts.map +1 -0
  32. package/dist/editor/null.js +20 -0
  33. package/dist/editor/null.js.map +1 -0
  34. package/dist/editor/objectid.d.ts +10 -0
  35. package/dist/editor/objectid.d.ts.map +1 -0
  36. package/dist/editor/objectid.js +38 -0
  37. package/dist/editor/objectid.js.map +1 -0
  38. package/dist/editor/standard.d.ts +16 -0
  39. package/dist/editor/standard.d.ts.map +1 -0
  40. package/dist/editor/standard.js +49 -0
  41. package/dist/editor/standard.js.map +1 -0
  42. package/dist/editor/string.d.ts +7 -0
  43. package/dist/editor/string.d.ts.map +1 -0
  44. package/dist/editor/string.js +15 -0
  45. package/dist/editor/string.js.map +1 -0
  46. package/dist/editor/undefined.d.ts +8 -0
  47. package/dist/editor/undefined.d.ts.map +1 -0
  48. package/dist/editor/undefined.js +20 -0
  49. package/dist/editor/undefined.js.map +1 -0
  50. package/dist/element-events.d.ts +11 -0
  51. package/dist/element-events.d.ts.map +1 -0
  52. package/dist/element-events.js +12 -0
  53. package/dist/element-events.js.map +1 -0
  54. package/dist/element.d.ts +112 -0
  55. package/dist/element.d.ts.map +1 -0
  56. package/dist/element.js +652 -0
  57. package/dist/element.js.map +1 -0
  58. package/dist/index.d.ts +6 -0
  59. package/dist/index.d.ts.map +1 -0
  60. package/dist/index.js +35 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/object-generator.d.ts +9 -0
  63. package/dist/object-generator.d.ts.map +1 -0
  64. package/dist/object-generator.js +82 -0
  65. package/dist/object-generator.js.map +1 -0
  66. package/dist/utils.d.ts +11 -0
  67. package/dist/utils.d.ts.map +1 -0
  68. package/dist/utils.js +37 -0
  69. package/dist/utils.js.map +1 -0
  70. package/package.json +45 -27
  71. package/.babelrc.js +0 -14
  72. package/.depcheckrc +0 -6
  73. package/.eslintignore +0 -1
  74. package/index.d.ts +0 -192
  75. package/index.js +0 -1
  76. package/lib/document.js +0 -624
  77. package/lib/editor/date.js +0 -151
  78. package/lib/editor/decimal128.js +0 -88
  79. package/lib/editor/double.js +0 -113
  80. package/lib/editor/index.js +0 -50
  81. package/lib/editor/int32.js +0 -68
  82. package/lib/editor/int64.js +0 -88
  83. package/lib/editor/null.js +0 -81
  84. package/lib/editor/objectid.js +0 -98
  85. package/lib/editor/standard.js +0 -108
  86. package/lib/editor/string.js +0 -48
  87. package/lib/editor/undefined.js +0 -81
  88. package/lib/element-events.js +0 -15
  89. package/lib/element.js +0 -1307
  90. package/lib/index.js +0 -7
  91. package/lib/object-generator.js +0 -180
  92. package/lib/utils.js +0 -10
  93. package/src/document.js +0 -432
  94. package/src/editor/date.js +0 -95
  95. package/src/editor/decimal128.js +0 -46
  96. package/src/editor/double.js +0 -70
  97. package/src/editor/index.js +0 -40
  98. package/src/editor/int32.js +0 -29
  99. package/src/editor/int64.js +0 -46
  100. package/src/editor/null.js +0 -42
  101. package/src/editor/objectid.js +0 -54
  102. package/src/editor/standard.js +0 -78
  103. package/src/editor/string.js +0 -20
  104. package/src/editor/undefined.js +0 -42
  105. package/src/element-events.js +0 -14
  106. package/src/element.js +0 -1002
  107. package/src/index.js +0 -5
  108. package/src/object-generator.js +0 -96
  109. package/src/utils.js +0 -6
package/lib/index.js DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
-
3
- module.exports = require('./document');
4
- module.exports.DocumentEvents = module.exports.Events;
5
- module.exports.Element = require('./element');
6
- module.exports.ElementEvents = module.exports.Element.Events;
7
- module.exports.ElementEditor = require('./editor');
@@ -1,180 +0,0 @@
1
- 'use strict';
2
- /**
3
- * Generates javascript objects from elements.
4
- */
5
-
6
- 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; } } }; }
7
-
8
- 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); }
9
-
10
- 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; }
11
-
12
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13
-
14
- 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); } }
15
-
16
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
17
-
18
- var ObjectGenerator = /*#__PURE__*/function () {
19
- function ObjectGenerator() {
20
- _classCallCheck(this, ObjectGenerator);
21
- }
22
-
23
- _createClass(ObjectGenerator, [{
24
- key: "generate",
25
- value:
26
- /**
27
- * Generate a javascript object from the elements.
28
- *
29
- * @param {Array} elements - The elements.
30
- *
31
- * @returns {Object} The javascript object.
32
- */
33
- function generate(elements) {
34
- if (elements) {
35
- var object = {};
36
-
37
- var _iterator = _createForOfIteratorHelper(elements),
38
- _step;
39
-
40
- try {
41
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
42
- var element = _step.value;
43
-
44
- if (!element.isRemoved() && element.currentKey !== '') {
45
- object[element.currentKey] = element.generateObject();
46
- }
47
- }
48
- } catch (err) {
49
- _iterator.e(err);
50
- } finally {
51
- _iterator.f();
52
- }
53
-
54
- return object;
55
- }
56
-
57
- return elements;
58
- }
59
- /**
60
- * Generate a javascript object from the elements with their original keys
61
- * and values. This can be used in a query with an update to
62
- * ensure the values on the document to edit are still up to date.
63
- *
64
- * @param {Array} elements - The elements.
65
- *
66
- * @returns {Object} The javascript object.
67
- */
68
-
69
- }, {
70
- key: "generateOriginal",
71
- value: function generateOriginal(elements) {
72
- if (elements) {
73
- var object = {};
74
-
75
- var _iterator2 = _createForOfIteratorHelper(elements),
76
- _step2;
77
-
78
- try {
79
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
80
- var element = _step2.value;
81
-
82
- if (!element.isAdded()) {
83
- object[element.key] = element.generateOriginalObject();
84
- }
85
- }
86
- } catch (err) {
87
- _iterator2.e(err);
88
- } finally {
89
- _iterator2.f();
90
- }
91
-
92
- return object;
93
- }
94
-
95
- return elements;
96
- }
97
- /**
98
- * Generate an array from the elements.
99
- *
100
- * @param {Array} elements - The elements.
101
- *
102
- * @returns {Array} The array.
103
- */
104
-
105
- }, {
106
- key: "generateArray",
107
- value: function generateArray(elements) {
108
- if (elements) {
109
- var array = [];
110
-
111
- var _iterator3 = _createForOfIteratorHelper(elements),
112
- _step3;
113
-
114
- try {
115
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
116
- var element = _step3.value;
117
-
118
- if (!element.isRemoved()) {
119
- if (element.elements) {
120
- array.push(element.generateObject());
121
- } else {
122
- array.push(element.currentValue);
123
- }
124
- }
125
- }
126
- } catch (err) {
127
- _iterator3.e(err);
128
- } finally {
129
- _iterator3.f();
130
- }
131
-
132
- return array;
133
- }
134
-
135
- return elements;
136
- }
137
- /**
138
- * Generate an array from the elements using their original values.
139
- *
140
- * @param {Array} elements - The elements.
141
- *
142
- * @returns {Array} The array.
143
- */
144
-
145
- }, {
146
- key: "generateOriginalArray",
147
- value: function generateOriginalArray(elements) {
148
- if (elements) {
149
- var array = [];
150
-
151
- var _iterator4 = _createForOfIteratorHelper(elements),
152
- _step4;
153
-
154
- try {
155
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
156
- var element = _step4.value;
157
-
158
- if (element.originalExpandableValue) {
159
- array.push(element.generateOriginalObject());
160
- } else if (!element.isAdded()) {
161
- array.push(element.value);
162
- }
163
- }
164
- } catch (err) {
165
- _iterator4.e(err);
166
- } finally {
167
- _iterator4.f();
168
- }
169
-
170
- return array;
171
- }
172
-
173
- return elements;
174
- }
175
- }]);
176
-
177
- return ObjectGenerator;
178
- }();
179
-
180
- module.exports = new ObjectGenerator();
package/lib/utils.js DELETED
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- var fieldStringLen = function fieldStringLen(value) {
4
- var length = String(value).length;
5
- return length === 0 ? 1 : length;
6
- };
7
-
8
- module.exports = {
9
- fieldStringLen: fieldStringLen
10
- };
package/src/document.js DELETED
@@ -1,432 +0,0 @@
1
- 'use strict';
2
-
3
- const EventEmitter = require('eventemitter3');
4
- const uuid = require('uuid');
5
- const Element = require('./element');
6
- const LinkedList = Element.LinkedList;
7
- const ObjectGenerator = require('./object-generator');
8
-
9
- /**
10
- * The event constant.
11
- */
12
- const Events = {
13
- 'Cancel': 'Document::Cancel'
14
- };
15
-
16
- /**
17
- * The id field.
18
- */
19
- const ID = '_id';
20
-
21
- /**
22
- * Represents a document.
23
- */
24
- class Document extends EventEmitter {
25
- /**
26
- * Send cancel event.
27
- */
28
- cancel() {
29
- // Cancel will remove elements from iterator, clone it before iterating
30
- // otherwise we will skip items
31
- for (let element of Array.from(this.elements)) {
32
- element.cancel();
33
- }
34
- this.emit(Events.Cancel);
35
- }
36
-
37
- /**
38
- * Create the new document from the provided object.
39
- *
40
- * @param {Object} doc - The document.
41
- * @param {boolean} cloned - If it is a cloned document.
42
- */
43
- constructor(doc, cloned) {
44
- super();
45
- this.uuid = uuid.v4();
46
- this.doc = doc;
47
- this.cloned = cloned || false;
48
- this.isUpdatable = true;
49
- this.elements = this._generateElements();
50
- this.type = 'Document';
51
- this.currentType = 'Document';
52
- }
53
-
54
- apply(doc) {
55
- let updatedKeys = [];
56
- let prevKey = null;
57
- for (const [key, value] of Object.entries(doc)) {
58
- if (this.get(key)) {
59
- this.get(key).edit(value);
60
- } else if (prevKey) {
61
- this.insertAfter(this.get(prevKey), key, value);
62
- } else {
63
- this.insertBeginning(key, value);
64
- }
65
- prevKey = key;
66
- updatedKeys.push(key);
67
- }
68
- for (const el of [...this.elements]) {
69
- if (!updatedKeys.includes(el.currentKey)) {
70
- el.remove();
71
- }
72
- }
73
- }
74
-
75
- /**
76
- * Generate the javascript object for this document.
77
- *
78
- * @returns {Object} The javascript object.
79
- */
80
- generateObject() {
81
- return ObjectGenerator.generate(this.elements);
82
- }
83
-
84
- /**
85
- * Generate the javascript object with the original elements in this document.
86
- *
87
- * @returns {Object} The original javascript object.
88
- */
89
- generateOriginalObject() {
90
- return ObjectGenerator.generateOriginal(this.elements);
91
- }
92
-
93
- /**
94
- * Generate the `query` and `updateDoc` to be used in an update operation
95
- * where the update only succeeds when the changed document's elements have
96
- * not been changed in the background.
97
- *
98
- * @param {Object} alwaysIncludeKeys - An object whose keys are used as keys
99
- * that are always included in the generated query.
100
- *
101
- * @returns {Object} An object containing the `query` and `updateDoc` to be
102
- * used in an update operation.
103
- */
104
- generateUpdateUnlessChangedInBackgroundQuery(
105
- alwaysIncludeKeys = null
106
- ) {
107
- // Build a query that will find the document to update only if it has the
108
- // values of elements that were changed with their original value.
109
- // This query won't find the document if an updated element's value isn't
110
- // the same value as it was when it was originally loaded.
111
- const originalFieldsThatWillBeUpdated = this.getOriginalKeysAndValuesForFieldsThatWereUpdated(
112
- alwaysIncludeKeys
113
- );
114
- const query = {
115
- _id: this.getId(),
116
- ...originalFieldsThatWillBeUpdated
117
- };
118
-
119
- // Build the update document to be used in an update operation with `$set`
120
- // and `$unset` reflecting the changes that have occured in the document.
121
- const setUpdateObject = this.getSetUpdateForDocumentChanges();
122
- const unsetUpdateObject = this.getUnsetUpdateForDocumentChanges();
123
- const updateDoc = { };
124
- if (setUpdateObject && Object.keys(setUpdateObject).length > 0) {
125
- updateDoc.$set = setUpdateObject;
126
- }
127
- if (unsetUpdateObject && Object.keys(unsetUpdateObject).length > 0) {
128
- updateDoc.$unset = unsetUpdateObject;
129
- }
130
-
131
- return {
132
- query,
133
- updateDoc
134
- };
135
- }
136
-
137
- /**
138
- * Get an element by its key.
139
- *
140
- * @param {String} key
141
- *
142
- * @returns {Element} The element.
143
- */
144
- get(key) {
145
- return this.elements.get(key);
146
- }
147
-
148
- /**
149
- * Get an element by a series of segment names.
150
- *
151
- * @param {Array} path - The series of fieldnames. Cannot be empty.
152
- *
153
- * @returns {Element} The element.
154
- */
155
- getChild(path) {
156
- if (!path) {
157
- return undefined;
158
- }
159
- let element = (this.currentType === 'Array') ? this.elements.at(path[0]) : this.elements.get(path[0]);
160
- let i = 1;
161
- while (i < path.length) {
162
- if (element === undefined) {
163
- return undefined;
164
- }
165
- element = element.currentType === 'Array' ? element.at(path[i]) : element.get(path[i]);
166
- i++;
167
- }
168
- return element;
169
- }
170
-
171
- /**
172
- * Get the _id value for the document.
173
- *
174
- * @returns {Object} The id.
175
- */
176
- getId() {
177
- const element = this.get(ID);
178
- return element ? element.generateObject() : null;
179
- }
180
-
181
- /**
182
- * Generate the query javascript object reflecting the elements that
183
- * were updated in this document. The values of this object are the original
184
- * values, this can be used when querying for an update to see if the original
185
- * document was changed in the background while it was being updated elsewhere.
186
- *
187
- * @param {Object} alwaysIncludeKeys - An object whose keys are used as keys
188
- * that are always included in the generated query.
189
- *
190
- * @returns {Object} The javascript object.
191
- */
192
- getOriginalKeysAndValuesForFieldsThatWereUpdated(
193
- alwaysIncludeKeys = null
194
- ) {
195
- const object = {};
196
-
197
- if (this.elements) {
198
- for (const element of this.elements) {
199
- if ((element.isModified() && !element.isAdded()) ||
200
- (alwaysIncludeKeys && element.key in alwaysIncludeKeys)) {
201
- // Using `.key` instead of `.currentKey` to ensure we look at
202
- // the original field's value.
203
- object[element.key] = element.generateOriginalObject();
204
- }
205
- if (element.isAdded() && element.currentKey !== '') {
206
- // When a new field is added, check if that field
207
- // was already added in the background.
208
- object[element.currentKey] = { $exists: false };
209
- }
210
- }
211
- }
212
-
213
- return object;
214
- }
215
-
216
- /**
217
- * Generate the query javascript object reflecting the elements that
218
- * are specified by the keys listed in `keys`. The values of this object are
219
- * the original values, this can be used when querying for an update based
220
- * on multiple criteria.
221
- *
222
- * @param {Object} keys - An object whose keys are used as keys
223
- * that are included in the generated query.
224
- *
225
- * @returns {Object} The javascript object.
226
- */
227
- getOriginalKeysAndValuesForSpecifiedKeys(keys) {
228
- const object = {};
229
-
230
- if (this.elements) {
231
- for (const element of this.elements) {
232
- if (element.key in keys) {
233
- // Using `.key` instead of `.currentKey` to ensure we look at
234
- // the original field's value.
235
- object[element.key] = element.generateOriginalObject();
236
- }
237
- }
238
- }
239
-
240
- return object;
241
- }
242
-
243
- /**
244
- * Generate an $set javascript object, that can be used in update operations to
245
- * set the changes which have occured in the document since it was loaded.
246
- *
247
- * @returns {Object} The javascript update object.
248
- **/
249
- getSetUpdateForDocumentChanges() {
250
- const object = {};
251
-
252
- if (this.elements) {
253
- for (const element of this.elements) {
254
- if (
255
- !element.isRemoved()
256
- && element.currentKey !== ''
257
- && element.isModified()
258
- ) {
259
- // Include the full modified element.
260
- // We don't individually set nested fields because we can't guarantee a
261
- // path to the element using '.' dot notation will update
262
- // the correct field, because field names can contain dots as of 3.6.
263
- // When a nested field has been altered (changed/added/removed) it is
264
- // set at the top level field. This means we overwrite possible
265
- // background changes that occur within sub documents.
266
- object[element.currentKey] = element.generateObject();
267
- }
268
- }
269
- }
270
- return object;
271
- }
272
-
273
- /**
274
- * Get the _id value as a string. Required if _id is not always an ObjectId.
275
- *
276
- * @returns {String} The string id.
277
- */
278
- getStringId() {
279
- const element = this.get(ID);
280
- if (!element) {
281
- return null;
282
- } else if (element.currentType === 'Array' || element.currentType === 'Object') {
283
- return JSON.stringify(element.generateObject());
284
- }
285
- return '' + element.value;
286
- }
287
-
288
- /**
289
- * Generate an $unset javascript object, that can be used in update
290
- * operations, with the removals from the document.
291
- *
292
- * @returns {Object} The javascript update object.
293
- **/
294
- getUnsetUpdateForDocumentChanges() {
295
- const object = {};
296
-
297
- if (this.elements) {
298
- for (const element of this.elements) {
299
- if (!element.isAdded() && element.isRemoved() && element.key !== '') {
300
- object[element.key] = true;
301
- }
302
- if (!element.isAdded() && element.isRenamed() && element.key !== '') {
303
- // Remove the original field when an element is renamed.
304
- object[element.key] = true;
305
- }
306
- }
307
- }
308
- return object;
309
- }
310
-
311
- /**
312
- * Insert a placeholder element at the end of the document.
313
- *
314
- * @returns {Element} The placeholder element.
315
- */
316
- insertPlaceholder() {
317
- return this.insertEnd('', '');
318
- }
319
-
320
- /**
321
- * Add a new element to this document.
322
- *
323
- * @param {String} key - The element key.
324
- * @param {Object} value - The value.
325
- *
326
- * @returns {Element} The new element.
327
- */
328
- insertBeginning(key, value) {
329
- var newElement = this.elements.insertBeginning(key, value, true, this);
330
- newElement._bubbleUp(Element.Events.Added, newElement, this);
331
- return newElement;
332
- }
333
-
334
- /**
335
- * Add a new element to this document.
336
- *
337
- * @param {String} key - The element key.
338
- * @param {Object} value - The value.
339
- *
340
- * @returns {Element} The new element.
341
- */
342
- insertEnd(key, value) {
343
- var newElement = this.elements.insertEnd(key, value, true, this);
344
- newElement._bubbleUp(Element.Events.Added, newElement, this);
345
- return newElement;
346
- }
347
-
348
- /**
349
- * Insert an element after the provided element.
350
- *
351
- * @param {Element} element - The element to insert after.
352
- * @param {String} key - The key.
353
- * @param {Object} value - The value.
354
- *
355
- * @returns {Element} The new element.
356
- */
357
- insertAfter(element, key, value) {
358
- var newElement = this.elements.insertAfter(element, key, value, true, this);
359
- newElement._bubbleUp(Element.Events.Added, newElement, this);
360
- return newElement;
361
- }
362
-
363
- /**
364
- * A document always exists, is never added.
365
- *
366
- * @returns {false} Always false.
367
- */
368
- isAdded() {
369
- return false;
370
- }
371
-
372
- /**
373
- * Determine if the element is modified at all.
374
- *
375
- * @returns {Boolean} If the element is modified.
376
- */
377
- isModified() {
378
- for (let element of this.elements) {
379
- if (element.isModified()) {
380
- return true;
381
- }
382
- }
383
- return false;
384
- }
385
-
386
- /**
387
- * A document is never removed
388
- *
389
- * @returns {false} Always false.
390
- */
391
- isRemoved() {
392
- return false;
393
- }
394
-
395
- /**
396
- * The document object is always the root object.
397
- *
398
- * @returns {true} Always true.
399
- */
400
- isRoot() {
401
- return true;
402
- }
403
-
404
- /**
405
- * Handle the next element in the document.
406
- */
407
- next() {
408
- this.elements.flush();
409
- const lastElement = this.elements.lastElement;
410
- if (lastElement && lastElement.isAdded()) {
411
- if (lastElement.isBlank()) {
412
- lastElement.remove();
413
- } else {
414
- this.insertPlaceholder();
415
- }
416
- } else {
417
- this.insertPlaceholder();
418
- }
419
- }
420
-
421
- /**
422
- * Generates a sequence of elements.
423
- *
424
- * @returns {Array} The elements.
425
- */
426
- _generateElements() {
427
- return new LinkedList(this, this.doc);
428
- }
429
- }
430
-
431
- module.exports = Document;
432
- module.exports.Events = Events;