trakked 1.0.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/LICENSE +21 -0
- package/README.md +974 -0
- package/dist/dev/index.cjs +1247 -0
- package/dist/dev/index.cjs.map +1 -0
- package/dist/dev/index.d.cts +336 -0
- package/dist/dev/index.d.ts +336 -0
- package/dist/dev/index.js +1208 -0
- package/dist/dev/index.js.map +1 -0
- package/dist/index.cjs +1071 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +328 -0
- package/dist/index.d.ts +328 -0
- package/dist/index.js +1031 -0
- package/dist/index.js.map +1 -0
- package/dist/prod/index.cjs +1247 -0
- package/dist/prod/index.cjs.map +1 -0
- package/dist/prod/index.js +1208 -0
- package/dist/prod/index.js.map +1 -0
- package/package.json +52 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1071 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
ExternallyAssigned: () => ExternallyAssigned,
|
|
24
|
+
InitializeTracked: () => InitializeTracked,
|
|
25
|
+
ObjectState: () => ObjectState,
|
|
26
|
+
OperationProperties: () => OperationProperties,
|
|
27
|
+
PropertyType: () => PropertyType,
|
|
28
|
+
Tracked: () => Tracked,
|
|
29
|
+
TrackedCollection: () => TrackedCollection,
|
|
30
|
+
TrackedCollectionChanged: () => TrackedCollectionChanged,
|
|
31
|
+
TrackedObject: () => TrackedObject,
|
|
32
|
+
TrackedObjectBase: () => TrackedObjectBase,
|
|
33
|
+
Tracker: () => Tracker,
|
|
34
|
+
TypedEvent: () => TypedEvent,
|
|
35
|
+
VersionedObjectState: () => VersionedObjectState,
|
|
36
|
+
VersionedTrackedObject: () => VersionedTrackedObject
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(index_exports);
|
|
39
|
+
|
|
40
|
+
// src/TypedEvent.ts
|
|
41
|
+
var TypedEvent = class {
|
|
42
|
+
constructor() {
|
|
43
|
+
this._handlers = [];
|
|
44
|
+
}
|
|
45
|
+
subscribe(handler) {
|
|
46
|
+
this._handlers.push(handler);
|
|
47
|
+
return () => this.unsubscribe(handler);
|
|
48
|
+
}
|
|
49
|
+
unsubscribe(handler) {
|
|
50
|
+
const index = this._handlers.indexOf(handler);
|
|
51
|
+
if (index >= 0) {
|
|
52
|
+
this._handlers.splice(index, 1);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
emit(event) {
|
|
56
|
+
this._handlers.forEach((h) => h(event));
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// src/Change.ts
|
|
61
|
+
var Change = class {
|
|
62
|
+
constructor(number, redoAction, undoAction, properties) {
|
|
63
|
+
this.number = number;
|
|
64
|
+
this.redoAction = redoAction;
|
|
65
|
+
this.undoAction = undoAction;
|
|
66
|
+
this.properties = properties;
|
|
67
|
+
this.time = /* @__PURE__ */ new Date();
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// src/Operation.ts
|
|
72
|
+
var Operation = class {
|
|
73
|
+
constructor() {
|
|
74
|
+
this.time = /* @__PURE__ */ new Date();
|
|
75
|
+
this.actions = [];
|
|
76
|
+
this._hasActions = false;
|
|
77
|
+
}
|
|
78
|
+
get hasActions() {
|
|
79
|
+
return this._hasActions;
|
|
80
|
+
}
|
|
81
|
+
set hasActions(value) {
|
|
82
|
+
this._hasActions = value;
|
|
83
|
+
}
|
|
84
|
+
add(redoAction, undoAction, properties) {
|
|
85
|
+
const action = new Change(
|
|
86
|
+
this.actions.length,
|
|
87
|
+
redoAction,
|
|
88
|
+
undoAction,
|
|
89
|
+
properties
|
|
90
|
+
);
|
|
91
|
+
this.actions.push(action);
|
|
92
|
+
this.hasActions = true;
|
|
93
|
+
}
|
|
94
|
+
updateOrAdd(redoAction, undoAction, properties) {
|
|
95
|
+
const idx = this.actions.findLastIndex(
|
|
96
|
+
(c) => c.properties.trackedObject === properties.trackedObject && c.properties.property === properties.property
|
|
97
|
+
);
|
|
98
|
+
if (idx >= 0) {
|
|
99
|
+
this.actions[idx] = new Change(this.actions[idx].number, redoAction, undoAction, properties);
|
|
100
|
+
} else {
|
|
101
|
+
this.add(redoAction, undoAction, properties);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
redo() {
|
|
105
|
+
this.actions.reverse().forEach((x) => x.redoAction());
|
|
106
|
+
}
|
|
107
|
+
undo() {
|
|
108
|
+
this.actions.reverse().forEach((x) => x.undoAction());
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// src/PropertyType.ts
|
|
113
|
+
var PropertyType = /* @__PURE__ */ ((PropertyType2) => {
|
|
114
|
+
PropertyType2[PropertyType2["Boolean"] = 0] = "Boolean";
|
|
115
|
+
PropertyType2[PropertyType2["String"] = 1] = "String";
|
|
116
|
+
PropertyType2[PropertyType2["Number"] = 2] = "Number";
|
|
117
|
+
PropertyType2[PropertyType2["Collection"] = 3] = "Collection";
|
|
118
|
+
PropertyType2[PropertyType2["Object"] = 4] = "Object";
|
|
119
|
+
PropertyType2[PropertyType2["Date"] = 5] = "Date";
|
|
120
|
+
return PropertyType2;
|
|
121
|
+
})(PropertyType || {});
|
|
122
|
+
|
|
123
|
+
// src/CollectionUtilities.ts
|
|
124
|
+
var CollectionUtilities = class {
|
|
125
|
+
static getLast(array) {
|
|
126
|
+
return array.length > 0 ? array[array.length - 1] : void 0;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// src/ExternallyAssigned.ts
|
|
131
|
+
var EXTERNALLY_ASSIGNED = /* @__PURE__ */ Symbol("externallyAssigned");
|
|
132
|
+
function ExternallyAssigned(_target, context) {
|
|
133
|
+
context.addInitializer(function() {
|
|
134
|
+
Object.defineProperty(Object.getPrototypeOf(this), EXTERNALLY_ASSIGNED, {
|
|
135
|
+
value: String(context.name),
|
|
136
|
+
configurable: true
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
function getExternallyAssignedProperty(proto) {
|
|
141
|
+
return EXTERNALLY_ASSIGNED in proto ? proto[EXTERNALLY_ASSIGNED] : void 0;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/Registry.ts
|
|
145
|
+
var VALIDATORS = /* @__PURE__ */ Symbol("validators");
|
|
146
|
+
function registerPropertyValidator(proto, property, validator) {
|
|
147
|
+
if (!(VALIDATORS in proto)) {
|
|
148
|
+
Object.defineProperty(proto, VALIDATORS, {
|
|
149
|
+
value: /* @__PURE__ */ new Map(),
|
|
150
|
+
configurable: true
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
const map = proto[VALIDATORS];
|
|
154
|
+
if (!map.has(property)) {
|
|
155
|
+
map.set(property, validator);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function validate(model) {
|
|
159
|
+
const proto = Object.getPrototypeOf(model);
|
|
160
|
+
if (!(VALIDATORS in proto)) return;
|
|
161
|
+
const validators = proto[VALIDATORS];
|
|
162
|
+
validators.forEach((validatorFn, property) => {
|
|
163
|
+
model.validate(property, validatorFn(model));
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// src/Tracker.ts
|
|
168
|
+
var Tracker = class {
|
|
169
|
+
constructor(coalescingWindowMs = 3e3) {
|
|
170
|
+
this._suppressTrackingCounter = 0;
|
|
171
|
+
this._externallyAssignedPlaceholderCounter = -1;
|
|
172
|
+
this.trackedObjects = [];
|
|
173
|
+
this.trackedCollections = [];
|
|
174
|
+
this.isDirtyChanged = new TypedEvent();
|
|
175
|
+
this.isValidChanged = new TypedEvent();
|
|
176
|
+
this.canCommitChanged = new TypedEvent();
|
|
177
|
+
this.coalescingWindowMs = coalescingWindowMs;
|
|
178
|
+
this._currentOperation = void 0;
|
|
179
|
+
this._redoOperations = [];
|
|
180
|
+
this._undoOperations = [];
|
|
181
|
+
this._commitStateOperation = void 0;
|
|
182
|
+
this._isDirty = false;
|
|
183
|
+
this._canUndo = false;
|
|
184
|
+
this._canRedo = false;
|
|
185
|
+
this._suppressTrackingCounter = 0;
|
|
186
|
+
this._currentOperationOwner = void 0;
|
|
187
|
+
this._currentOperationPropertyName = void 0;
|
|
188
|
+
this._isValid = true;
|
|
189
|
+
this._canCommit = false;
|
|
190
|
+
}
|
|
191
|
+
get isDirty() {
|
|
192
|
+
return this._isDirty;
|
|
193
|
+
}
|
|
194
|
+
set isDirty(value) {
|
|
195
|
+
if (this._isDirty !== value) {
|
|
196
|
+
this._isDirty = value;
|
|
197
|
+
this.isDirtyChanged.emit(value);
|
|
198
|
+
this.updateCanCommit();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
get isValid() {
|
|
202
|
+
return this._isValid;
|
|
203
|
+
}
|
|
204
|
+
set isValid(value) {
|
|
205
|
+
if (this._isValid !== value) {
|
|
206
|
+
this._isValid = value;
|
|
207
|
+
this.isValidChanged.emit(value);
|
|
208
|
+
this.updateCanCommit();
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
get canCommit() {
|
|
212
|
+
return this._canCommit;
|
|
213
|
+
}
|
|
214
|
+
set canCommit(value) {
|
|
215
|
+
if (this._canCommit !== value) {
|
|
216
|
+
this._canCommit = value;
|
|
217
|
+
this.canCommitChanged.emit(value);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
updateCanCommit() {
|
|
221
|
+
this.canCommit = this._isDirty && this._isValid;
|
|
222
|
+
}
|
|
223
|
+
get canUndo() {
|
|
224
|
+
return this._canUndo;
|
|
225
|
+
}
|
|
226
|
+
set canUndo(value) {
|
|
227
|
+
this._canUndo = value;
|
|
228
|
+
}
|
|
229
|
+
get canRedo() {
|
|
230
|
+
return this._canRedo;
|
|
231
|
+
}
|
|
232
|
+
set canRedo(value) {
|
|
233
|
+
this._canRedo = value;
|
|
234
|
+
}
|
|
235
|
+
get isTrackingSuppressed() {
|
|
236
|
+
return this._suppressTrackingCounter > 0;
|
|
237
|
+
}
|
|
238
|
+
trackObject(trackedObject) {
|
|
239
|
+
this.trackedObjects.push(trackedObject);
|
|
240
|
+
this.isValid = this.isValid && trackedObject.isValid;
|
|
241
|
+
}
|
|
242
|
+
untrackObject(trackedObject) {
|
|
243
|
+
this.trackedObjects.splice(this.trackedObjects.indexOf(trackedObject), 1);
|
|
244
|
+
this.revalidate();
|
|
245
|
+
}
|
|
246
|
+
trackCollection(trackedCollection) {
|
|
247
|
+
this.trackedCollections.push(trackedCollection);
|
|
248
|
+
this.isValid = this.isValid && trackedCollection.isValid;
|
|
249
|
+
}
|
|
250
|
+
untrackCollection(trackedCollection) {
|
|
251
|
+
this.trackedCollections.splice(
|
|
252
|
+
this.trackedCollections.indexOf(trackedCollection),
|
|
253
|
+
1
|
|
254
|
+
);
|
|
255
|
+
this.revalidate();
|
|
256
|
+
}
|
|
257
|
+
withTrackingSuppressed(action) {
|
|
258
|
+
this._suppressTrackingCounter++;
|
|
259
|
+
action();
|
|
260
|
+
this._suppressTrackingCounter--;
|
|
261
|
+
}
|
|
262
|
+
beginSuppressTracking() {
|
|
263
|
+
this._suppressTrackingCounter++;
|
|
264
|
+
}
|
|
265
|
+
endSuppressTracking() {
|
|
266
|
+
this._suppressTrackingCounter--;
|
|
267
|
+
}
|
|
268
|
+
doAndTrack(redoAction, undoAction, properties) {
|
|
269
|
+
if (this.isTrackingSuppressed) {
|
|
270
|
+
redoAction();
|
|
271
|
+
this.revalidate();
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
if (this.isStartingNewOperation()) {
|
|
275
|
+
this._currentOperationOwner = properties.trackedObject;
|
|
276
|
+
this._currentOperationPropertyName = properties.property;
|
|
277
|
+
if (this.shouldCoalesceChanges(properties)) {
|
|
278
|
+
this._currentOperation = CollectionUtilities.getLast(this._undoOperations);
|
|
279
|
+
} else {
|
|
280
|
+
this._currentOperation = new Operation();
|
|
281
|
+
this._undoOperations.push(this._currentOperation);
|
|
282
|
+
this._redoOperations.length = 0;
|
|
283
|
+
this.reset();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
this._currentOperation?.add(
|
|
287
|
+
() => redoAction(),
|
|
288
|
+
() => undoAction(),
|
|
289
|
+
properties
|
|
290
|
+
);
|
|
291
|
+
redoAction();
|
|
292
|
+
if (this.isEndingCurrentOperation(properties)) {
|
|
293
|
+
this._currentOperation = void 0;
|
|
294
|
+
this._currentOperationOwner = void 0;
|
|
295
|
+
this._currentOperationPropertyName = void 0;
|
|
296
|
+
this.revalidate();
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
isEndingCurrentOperation(properties) {
|
|
300
|
+
return this._currentOperationOwner === properties.trackedObject && this._currentOperationPropertyName === properties.property;
|
|
301
|
+
}
|
|
302
|
+
isStartingNewOperation() {
|
|
303
|
+
return this._currentOperationOwner === void 0 && this._currentOperationPropertyName === void 0;
|
|
304
|
+
}
|
|
305
|
+
shouldCoalesceChanges(properties) {
|
|
306
|
+
const lastOperation = CollectionUtilities.getLast(this._undoOperations);
|
|
307
|
+
return this.isCoalescibleType(properties) && this.hasLastOperation(lastOperation) && this.lastOperationTargetsSameProperty(lastOperation, properties) && this.lastActionIsRecent(lastOperation);
|
|
308
|
+
}
|
|
309
|
+
isCoalescibleType(properties) {
|
|
310
|
+
return !properties.noCoalesce && (properties.type === 1 /* String */ || properties.type === 2 /* Number */);
|
|
311
|
+
}
|
|
312
|
+
hasLastOperation(lastOperation) {
|
|
313
|
+
return !!lastOperation;
|
|
314
|
+
}
|
|
315
|
+
lastOperationTargetsSameProperty(lastOperation, properties) {
|
|
316
|
+
return lastOperation.actions.every(
|
|
317
|
+
(x) => x.properties.trackedObject === properties.trackedObject && x.properties.property === properties.property
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
lastActionIsRecent(lastOperation) {
|
|
321
|
+
if (this.coalescingWindowMs === void 0) return false;
|
|
322
|
+
return (/* @__PURE__ */ new Date()).getTime() - CollectionUtilities.getLast(lastOperation.actions).time.getTime() < this.coalescingWindowMs;
|
|
323
|
+
}
|
|
324
|
+
onCommit(keys) {
|
|
325
|
+
const lastOp = CollectionUtilities.getLast(this._undoOperations);
|
|
326
|
+
if (keys) {
|
|
327
|
+
this.trackedObjects.forEach((obj) => obj.applyExternalAssignments(keys, lastOp));
|
|
328
|
+
}
|
|
329
|
+
this.trackedObjects.forEach((obj) => obj.onCommitted(lastOp));
|
|
330
|
+
this._commitStateOperation = lastOp;
|
|
331
|
+
this.reset();
|
|
332
|
+
}
|
|
333
|
+
isInUndoStack(op) {
|
|
334
|
+
return this._undoOperations.includes(op);
|
|
335
|
+
}
|
|
336
|
+
beforeCommit() {
|
|
337
|
+
this.trackedObjects.forEach((model) => {
|
|
338
|
+
const propertyName = getExternallyAssignedProperty(
|
|
339
|
+
Object.getPrototypeOf(model)
|
|
340
|
+
);
|
|
341
|
+
if (propertyName && model[propertyName] <= 0) {
|
|
342
|
+
model[propertyName] = this._externallyAssignedPlaceholderCounter--;
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
reset() {
|
|
347
|
+
this.canUndo = this._undoOperations.length > 0;
|
|
348
|
+
this.canRedo = this._redoOperations.length > 0;
|
|
349
|
+
this.isDirty = CollectionUtilities.getLast(this._undoOperations) !== this._commitStateOperation;
|
|
350
|
+
}
|
|
351
|
+
undo() {
|
|
352
|
+
if (!this.canUndo) {
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
const undoOperation = this._undoOperations.pop();
|
|
356
|
+
this.withTrackingSuppressed(() => undoOperation.undo());
|
|
357
|
+
this._redoOperations.push(undoOperation);
|
|
358
|
+
this.reset();
|
|
359
|
+
this.revalidate();
|
|
360
|
+
}
|
|
361
|
+
redo() {
|
|
362
|
+
if (!this.canRedo) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
const redoOperation = this._redoOperations.pop();
|
|
366
|
+
this.withTrackingSuppressed(() => redoOperation.redo());
|
|
367
|
+
this._undoOperations.push(redoOperation);
|
|
368
|
+
this.reset();
|
|
369
|
+
this.revalidate();
|
|
370
|
+
}
|
|
371
|
+
revalidate() {
|
|
372
|
+
this.trackedObjects.forEach((x) => validate(x));
|
|
373
|
+
this.trackedCollections.forEach((x) => x.validate());
|
|
374
|
+
this.isValid = this.trackedObjects.every((x) => x.isValid) && this.trackedCollections.every((x) => x.isValid);
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
// src/OperationProperties.ts
|
|
379
|
+
var OperationProperties = class {
|
|
380
|
+
constructor(trackedObject, property, type, validator, noCoalesce) {
|
|
381
|
+
this.trackedObject = trackedObject;
|
|
382
|
+
this.property = property;
|
|
383
|
+
this.type = type;
|
|
384
|
+
this.validator = validator;
|
|
385
|
+
this.noCoalesce = noCoalesce;
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
// src/TrackedObjectBase.ts
|
|
390
|
+
var TrackedObjectBase = class {
|
|
391
|
+
constructor(tracker) {
|
|
392
|
+
this.tracker = tracker;
|
|
393
|
+
this._dirtyCounter = 0;
|
|
394
|
+
this._isValid = true;
|
|
395
|
+
this.validationMessages = /* @__PURE__ */ new Map();
|
|
396
|
+
tracker.trackObject(this);
|
|
397
|
+
}
|
|
398
|
+
get validationMessages() {
|
|
399
|
+
return this._validationMessages ?? /* @__PURE__ */ new Map();
|
|
400
|
+
}
|
|
401
|
+
set validationMessages(value) {
|
|
402
|
+
this._validationMessages = value;
|
|
403
|
+
}
|
|
404
|
+
get isValid() {
|
|
405
|
+
return this._isValid;
|
|
406
|
+
}
|
|
407
|
+
set isValid(value) {
|
|
408
|
+
this._isValid = value;
|
|
409
|
+
}
|
|
410
|
+
get isDirty() {
|
|
411
|
+
return this._dirtyCounter !== 0;
|
|
412
|
+
}
|
|
413
|
+
get dirtyCounter() {
|
|
414
|
+
return this._dirtyCounter;
|
|
415
|
+
}
|
|
416
|
+
set dirtyCounter(value) {
|
|
417
|
+
this._dirtyCounter = value;
|
|
418
|
+
}
|
|
419
|
+
applyExternalAssignments(keys, lastOp) {
|
|
420
|
+
const propertyName = getExternallyAssignedProperty(Object.getPrototypeOf(this));
|
|
421
|
+
if (!propertyName || this[propertyName] >= 0) return;
|
|
422
|
+
const response = keys.find((x) => x.placeholder === this[propertyName]);
|
|
423
|
+
if (!response) return;
|
|
424
|
+
const previousValue = this[propertyName];
|
|
425
|
+
const newValue = response.value;
|
|
426
|
+
const redoFn = () => {
|
|
427
|
+
this[propertyName] = newValue;
|
|
428
|
+
};
|
|
429
|
+
const undoFn = () => {
|
|
430
|
+
this[propertyName] = previousValue;
|
|
431
|
+
};
|
|
432
|
+
if (lastOp) {
|
|
433
|
+
lastOp.add(redoFn, undoFn, new OperationProperties(this, propertyName, 2 /* Number */));
|
|
434
|
+
}
|
|
435
|
+
redoFn();
|
|
436
|
+
}
|
|
437
|
+
validate(property, errorMessage) {
|
|
438
|
+
if (errorMessage) {
|
|
439
|
+
this.validationMessages.set(property, errorMessage);
|
|
440
|
+
} else {
|
|
441
|
+
this.validationMessages.delete(property);
|
|
442
|
+
}
|
|
443
|
+
this.validationMessages = new Map(this.validationMessages);
|
|
444
|
+
this.isValid = this.validationMessages.size === 0;
|
|
445
|
+
}
|
|
446
|
+
destroy() {
|
|
447
|
+
this.tracker.untrackObject(this);
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
function validateDecorated(model) {
|
|
451
|
+
validate(model);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// src/ObjectState.ts
|
|
455
|
+
var ObjectState = /* @__PURE__ */ ((ObjectState2) => {
|
|
456
|
+
ObjectState2["New"] = "New";
|
|
457
|
+
ObjectState2["Unchanged"] = "Unchanged";
|
|
458
|
+
ObjectState2["Edited"] = "Edited";
|
|
459
|
+
ObjectState2["Deleted"] = "Deleted";
|
|
460
|
+
return ObjectState2;
|
|
461
|
+
})(ObjectState || {});
|
|
462
|
+
|
|
463
|
+
// src/TrackedObject.ts
|
|
464
|
+
var TrackedObject = class extends TrackedObjectBase {
|
|
465
|
+
constructor(tracker, initialState = "Unchanged" /* Unchanged */) {
|
|
466
|
+
super(tracker);
|
|
467
|
+
this._committedState = "Unchanged" /* Unchanged */;
|
|
468
|
+
this._committedState = initialState;
|
|
469
|
+
}
|
|
470
|
+
get state() {
|
|
471
|
+
if (this._committedState === "Unchanged" /* Unchanged */ && this.isDirty) {
|
|
472
|
+
return "Edited" /* Edited */;
|
|
473
|
+
}
|
|
474
|
+
return this._committedState;
|
|
475
|
+
}
|
|
476
|
+
onCommitted(_lastOp) {
|
|
477
|
+
this.dirtyCounter = 0;
|
|
478
|
+
}
|
|
479
|
+
markDeletion() {
|
|
480
|
+
const prev = this._committedState;
|
|
481
|
+
const target = prev === "New" /* New */ ? "Unchanged" /* Unchanged */ : "Deleted" /* Deleted */;
|
|
482
|
+
this.tracker.doAndTrack(
|
|
483
|
+
() => {
|
|
484
|
+
this._committedState = target;
|
|
485
|
+
},
|
|
486
|
+
() => {
|
|
487
|
+
this._committedState = prev;
|
|
488
|
+
},
|
|
489
|
+
new OperationProperties(this, "__saveState__", 4 /* Object */)
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
markAsNew() {
|
|
493
|
+
if (this._committedState !== "Unchanged" /* Unchanged */) return;
|
|
494
|
+
if (this.tracker.isTrackingSuppressed) return;
|
|
495
|
+
const prev = this._committedState;
|
|
496
|
+
this.tracker.doAndTrack(
|
|
497
|
+
() => {
|
|
498
|
+
this._committedState = "New" /* New */;
|
|
499
|
+
},
|
|
500
|
+
() => {
|
|
501
|
+
this._committedState = prev;
|
|
502
|
+
},
|
|
503
|
+
new OperationProperties(this, "__saveState__", 4 /* Object */)
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
// src/VersionedObjectState.ts
|
|
509
|
+
var VersionedObjectState = /* @__PURE__ */ ((VersionedObjectState2) => {
|
|
510
|
+
VersionedObjectState2["New"] = "New";
|
|
511
|
+
VersionedObjectState2["Unchanged"] = "Unchanged";
|
|
512
|
+
VersionedObjectState2["Edited"] = "Edited";
|
|
513
|
+
VersionedObjectState2["Deleted"] = "Deleted";
|
|
514
|
+
VersionedObjectState2["InsertReverted"] = "InsertReverted";
|
|
515
|
+
VersionedObjectState2["EditReverted"] = "EditReverted";
|
|
516
|
+
VersionedObjectState2["DeleteReverted"] = "DeleteReverted";
|
|
517
|
+
return VersionedObjectState2;
|
|
518
|
+
})(VersionedObjectState || {});
|
|
519
|
+
|
|
520
|
+
// src/VersionedTrackedObject.ts
|
|
521
|
+
var VersionedTrackedObject = class extends TrackedObjectBase {
|
|
522
|
+
constructor(tracker, initialState = "Unchanged" /* Unchanged */) {
|
|
523
|
+
super(tracker);
|
|
524
|
+
this._committedState = "Unchanged" /* Unchanged */;
|
|
525
|
+
this.pendingHardDeletes = /* @__PURE__ */ new Set();
|
|
526
|
+
this._committedState = initialState;
|
|
527
|
+
}
|
|
528
|
+
get state() {
|
|
529
|
+
if (this._committedState === "Unchanged" /* Unchanged */ && this.isDirty) {
|
|
530
|
+
return "Edited" /* Edited */;
|
|
531
|
+
}
|
|
532
|
+
return this._committedState;
|
|
533
|
+
}
|
|
534
|
+
onCommitted(lastOp) {
|
|
535
|
+
const revertedState = this.revertedStateFor(this.state);
|
|
536
|
+
if (revertedState !== null) {
|
|
537
|
+
const reverted = revertedState;
|
|
538
|
+
const redoFn = () => {
|
|
539
|
+
this._committedState = "Unchanged" /* Unchanged */;
|
|
540
|
+
};
|
|
541
|
+
const undoFn = () => {
|
|
542
|
+
this._committedState = reverted;
|
|
543
|
+
};
|
|
544
|
+
if (lastOp) {
|
|
545
|
+
lastOp.updateOrAdd(redoFn, undoFn, new OperationProperties(this, "__saveState__", 4 /* Object */));
|
|
546
|
+
}
|
|
547
|
+
redoFn();
|
|
548
|
+
}
|
|
549
|
+
this.dirtyCounter = 0;
|
|
550
|
+
}
|
|
551
|
+
applyExternalAssignments(keys, lastOp) {
|
|
552
|
+
const propertyName = getExternallyAssignedProperty(Object.getPrototypeOf(this));
|
|
553
|
+
const response = propertyName && this[propertyName] < 0 ? keys.find((x) => x.placeholder === this[propertyName]) : void 0;
|
|
554
|
+
super.applyExternalAssignments(keys, lastOp);
|
|
555
|
+
if (!response) return;
|
|
556
|
+
const newValue = response.value;
|
|
557
|
+
const redoFn = () => {
|
|
558
|
+
this.pendingHardDeletes.delete(newValue);
|
|
559
|
+
};
|
|
560
|
+
const undoFn = () => {
|
|
561
|
+
this.pendingHardDeletes.add(newValue);
|
|
562
|
+
};
|
|
563
|
+
if (lastOp) {
|
|
564
|
+
lastOp.add(redoFn, undoFn, new OperationProperties(this, "__pendingHardDeletes__", 4 /* Object */));
|
|
565
|
+
}
|
|
566
|
+
redoFn();
|
|
567
|
+
}
|
|
568
|
+
markAsNew() {
|
|
569
|
+
if (this._committedState !== "Unchanged" /* Unchanged */) return;
|
|
570
|
+
if (this.tracker.isTrackingSuppressed) return;
|
|
571
|
+
const prev = this._committedState;
|
|
572
|
+
this.tracker.doAndTrack(
|
|
573
|
+
() => {
|
|
574
|
+
this._committedState = "New" /* New */;
|
|
575
|
+
},
|
|
576
|
+
() => {
|
|
577
|
+
this._committedState = prev;
|
|
578
|
+
},
|
|
579
|
+
new OperationProperties(this, "__saveState__", 4 /* Object */)
|
|
580
|
+
);
|
|
581
|
+
}
|
|
582
|
+
markDeletion() {
|
|
583
|
+
const prev = this._committedState;
|
|
584
|
+
const isNeverPersisted = prev === "New" /* New */ || prev === "InsertReverted" /* InsertReverted */;
|
|
585
|
+
const target = isNeverPersisted ? "Unchanged" /* Unchanged */ : "Deleted" /* Deleted */;
|
|
586
|
+
const propertyName = getExternallyAssignedProperty(Object.getPrototypeOf(this));
|
|
587
|
+
const prevId = propertyName !== void 0 ? this[propertyName] : void 0;
|
|
588
|
+
const prevPendingHardDeletes = new Set(this.pendingHardDeletes);
|
|
589
|
+
const prevDirtyCounter = this.dirtyCounter;
|
|
590
|
+
this.tracker.doAndTrack(
|
|
591
|
+
() => {
|
|
592
|
+
this._committedState = target;
|
|
593
|
+
if (isNeverPersisted) {
|
|
594
|
+
this.dirtyCounter = 0;
|
|
595
|
+
}
|
|
596
|
+
if (propertyName !== void 0 && prevId !== 0) {
|
|
597
|
+
this[propertyName] = 0;
|
|
598
|
+
}
|
|
599
|
+
},
|
|
600
|
+
() => {
|
|
601
|
+
this._committedState = prev;
|
|
602
|
+
if (isNeverPersisted) {
|
|
603
|
+
this.dirtyCounter = prevDirtyCounter;
|
|
604
|
+
}
|
|
605
|
+
if (propertyName !== void 0) {
|
|
606
|
+
this[propertyName] = prevId;
|
|
607
|
+
}
|
|
608
|
+
this.pendingHardDeletes.clear();
|
|
609
|
+
prevPendingHardDeletes.forEach((id) => this.pendingHardDeletes.add(id));
|
|
610
|
+
},
|
|
611
|
+
new OperationProperties(this, "__saveState__", 4 /* Object */)
|
|
612
|
+
);
|
|
613
|
+
}
|
|
614
|
+
revertedStateFor(state) {
|
|
615
|
+
switch (state) {
|
|
616
|
+
case "New" /* New */:
|
|
617
|
+
return "InsertReverted" /* InsertReverted */;
|
|
618
|
+
case "Edited" /* Edited */:
|
|
619
|
+
return "EditReverted" /* EditReverted */;
|
|
620
|
+
case "Deleted" /* Deleted */:
|
|
621
|
+
return "DeleteReverted" /* DeleteReverted */;
|
|
622
|
+
case "InsertReverted" /* InsertReverted */:
|
|
623
|
+
return "InsertReverted" /* InsertReverted */;
|
|
624
|
+
case "EditReverted" /* EditReverted */:
|
|
625
|
+
return "EditReverted" /* EditReverted */;
|
|
626
|
+
case "DeleteReverted" /* DeleteReverted */:
|
|
627
|
+
return "DeleteReverted" /* DeleteReverted */;
|
|
628
|
+
default:
|
|
629
|
+
return null;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
|
|
634
|
+
// src/InitializeTracked.ts
|
|
635
|
+
function InitializeTracked(target, context) {
|
|
636
|
+
const wrapped = class extends target {
|
|
637
|
+
constructor(...args) {
|
|
638
|
+
const tracker = args.find((a) => a instanceof Tracker);
|
|
639
|
+
const outerSuppressed = tracker?.isTrackingSuppressed ?? false;
|
|
640
|
+
if (tracker) {
|
|
641
|
+
tracker.beginSuppressTracking();
|
|
642
|
+
}
|
|
643
|
+
super(...args);
|
|
644
|
+
if (tracker) {
|
|
645
|
+
tracker.endSuppressTracking();
|
|
646
|
+
}
|
|
647
|
+
validateDecorated(this);
|
|
648
|
+
if (tracker && !outerSuppressed) {
|
|
649
|
+
tracker.revalidate();
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
Object.defineProperty(wrapped, "name", { value: target.name });
|
|
654
|
+
return wrapped;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// src/Tracked.ts
|
|
658
|
+
function Tracked(validator, options) {
|
|
659
|
+
function decorator(target, context) {
|
|
660
|
+
const propertyName = String(context.name);
|
|
661
|
+
if (context.kind === "accessor") {
|
|
662
|
+
const accessorTarget = target;
|
|
663
|
+
if (validator) {
|
|
664
|
+
context.addInitializer(function() {
|
|
665
|
+
registerPropertyValidator(
|
|
666
|
+
Object.getPrototypeOf(this),
|
|
667
|
+
propertyName,
|
|
668
|
+
(model) => validator(model, accessorTarget.get.call(model))
|
|
669
|
+
);
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
return {
|
|
673
|
+
set(newValue) {
|
|
674
|
+
const oldValue = accessorTarget.get.call(this);
|
|
675
|
+
if (isSameValue(oldValue, newValue)) {
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
if (!this.tracker || this.tracker.isTrackingSuppressed) {
|
|
679
|
+
accessorTarget.set.call(this, newValue);
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
const properties = new OperationProperties(
|
|
683
|
+
this,
|
|
684
|
+
propertyName,
|
|
685
|
+
getPropertyType(newValue, oldValue),
|
|
686
|
+
validator ? (model, v) => validator(model, v) : void 0,
|
|
687
|
+
options?.noCoalesce
|
|
688
|
+
);
|
|
689
|
+
this.tracker.doAndTrack(
|
|
690
|
+
() => {
|
|
691
|
+
accessorTarget.set.call(this, newValue);
|
|
692
|
+
this.dirtyCounter++;
|
|
693
|
+
},
|
|
694
|
+
() => {
|
|
695
|
+
accessorTarget.set.call(this, oldValue);
|
|
696
|
+
this.dirtyCounter--;
|
|
697
|
+
},
|
|
698
|
+
properties
|
|
699
|
+
);
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
} else {
|
|
703
|
+
const setterFn = target;
|
|
704
|
+
if (validator) {
|
|
705
|
+
context.addInitializer(function() {
|
|
706
|
+
registerPropertyValidator(
|
|
707
|
+
Object.getPrototypeOf(this),
|
|
708
|
+
propertyName,
|
|
709
|
+
(model) => validator(model, model[propertyName])
|
|
710
|
+
);
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
return function(newValue) {
|
|
714
|
+
const oldValue = this[propertyName];
|
|
715
|
+
if (isSameValue(oldValue, newValue)) {
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
if (!this.tracker || this.tracker.isTrackingSuppressed) {
|
|
719
|
+
setterFn.call(this, newValue);
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
const properties = new OperationProperties(
|
|
723
|
+
this,
|
|
724
|
+
propertyName,
|
|
725
|
+
getPropertyType(newValue, oldValue),
|
|
726
|
+
validator ? (model, v) => validator(model, v) : void 0
|
|
727
|
+
);
|
|
728
|
+
this.tracker.doAndTrack(
|
|
729
|
+
() => {
|
|
730
|
+
setterFn.call(this, newValue);
|
|
731
|
+
this.dirtyCounter++;
|
|
732
|
+
},
|
|
733
|
+
() => {
|
|
734
|
+
setterFn.call(this, oldValue);
|
|
735
|
+
this.dirtyCounter--;
|
|
736
|
+
},
|
|
737
|
+
properties
|
|
738
|
+
);
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
return decorator;
|
|
743
|
+
}
|
|
744
|
+
function isSameValue(value1, value2) {
|
|
745
|
+
return value1 === value2 || (value1 === void 0 || value1 === null) && value2 === "" || (value2 === void 0 || value2 === null) && value1 === "";
|
|
746
|
+
}
|
|
747
|
+
function getPropertyType(newValue, oldValue) {
|
|
748
|
+
const v = newValue ?? oldValue;
|
|
749
|
+
if (v instanceof Date) return 5 /* Date */;
|
|
750
|
+
switch (typeof v) {
|
|
751
|
+
case "string":
|
|
752
|
+
return 1 /* String */;
|
|
753
|
+
case "boolean":
|
|
754
|
+
return 0 /* Boolean */;
|
|
755
|
+
case "number":
|
|
756
|
+
return 2 /* Number */;
|
|
757
|
+
case "object":
|
|
758
|
+
return 4 /* Object */;
|
|
759
|
+
default:
|
|
760
|
+
throw new Error(`Property type '${typeof v}' not supported`);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
// src/TrackedCollection.ts
|
|
765
|
+
var TrackedCollection = class {
|
|
766
|
+
constructor(tracker, items, _validator) {
|
|
767
|
+
this.tracker = tracker;
|
|
768
|
+
this._validator = _validator;
|
|
769
|
+
this._dirtyCounter = 0;
|
|
770
|
+
this.changed = new TypedEvent();
|
|
771
|
+
this._isValid = true;
|
|
772
|
+
this._isDirty = false;
|
|
773
|
+
this._collection = items ? [...items] : [];
|
|
774
|
+
this.validate();
|
|
775
|
+
this.tracker.trackCollection(this);
|
|
776
|
+
}
|
|
777
|
+
get dirtyCounter() {
|
|
778
|
+
return this._dirtyCounter;
|
|
779
|
+
}
|
|
780
|
+
set dirtyCounter(value) {
|
|
781
|
+
this._dirtyCounter = value;
|
|
782
|
+
}
|
|
783
|
+
get isDirty() {
|
|
784
|
+
return this._isDirty;
|
|
785
|
+
}
|
|
786
|
+
set isDirty(value) {
|
|
787
|
+
this._isDirty = value;
|
|
788
|
+
}
|
|
789
|
+
get isValid() {
|
|
790
|
+
return this._isValid;
|
|
791
|
+
}
|
|
792
|
+
set isValid(value) {
|
|
793
|
+
this._isValid = value;
|
|
794
|
+
}
|
|
795
|
+
get length() {
|
|
796
|
+
return this.collection.length;
|
|
797
|
+
}
|
|
798
|
+
get lastItemIndex() {
|
|
799
|
+
return this.collection.length > 0 ? this.collection.length - 1 : void 0;
|
|
800
|
+
}
|
|
801
|
+
get collection() {
|
|
802
|
+
return this._collection;
|
|
803
|
+
}
|
|
804
|
+
set collection(value) {
|
|
805
|
+
this._collection = value;
|
|
806
|
+
}
|
|
807
|
+
get [Symbol.iterator]() {
|
|
808
|
+
return this.collection[Symbol.iterator].bind(this.collection);
|
|
809
|
+
}
|
|
810
|
+
get [Symbol.unscopables]() {
|
|
811
|
+
return this.collection[Symbol.unscopables];
|
|
812
|
+
}
|
|
813
|
+
get error() {
|
|
814
|
+
return this._error;
|
|
815
|
+
}
|
|
816
|
+
set error(value) {
|
|
817
|
+
this._error = value;
|
|
818
|
+
}
|
|
819
|
+
validate() {
|
|
820
|
+
this.error = this._validator ? this._validator(this.collection) : void 0;
|
|
821
|
+
this.isValid = this.error === void 0;
|
|
822
|
+
}
|
|
823
|
+
splice(start, deleteCount, ...items) {
|
|
824
|
+
let removed;
|
|
825
|
+
this.tracker.doAndTrack(
|
|
826
|
+
() => {
|
|
827
|
+
if (removed !== void 0) {
|
|
828
|
+
this.doSplice(start, deleteCount, items, removed);
|
|
829
|
+
} else {
|
|
830
|
+
removed = this.doSplice(start, deleteCount, items);
|
|
831
|
+
}
|
|
832
|
+
this.trackRemovedObjectDeletions(removed);
|
|
833
|
+
this.trackAddedObjectInsertions(items);
|
|
834
|
+
},
|
|
835
|
+
() => this.undoSplice(start, items, removed),
|
|
836
|
+
new OperationProperties(this, void 0, 3 /* Collection */)
|
|
837
|
+
);
|
|
838
|
+
return removed;
|
|
839
|
+
}
|
|
840
|
+
doSplice(start, deleteCount, items, reusedRemoved) {
|
|
841
|
+
let removed;
|
|
842
|
+
let event;
|
|
843
|
+
this.tracker.withTrackingSuppressed(() => {
|
|
844
|
+
removed = this.collection.splice(start, deleteCount, ...items);
|
|
845
|
+
this.collection = [...this.collection];
|
|
846
|
+
event = new TrackedCollectionChanged(items, removed, this.collection);
|
|
847
|
+
});
|
|
848
|
+
this.changed.emit(event);
|
|
849
|
+
return reusedRemoved ?? removed;
|
|
850
|
+
}
|
|
851
|
+
trackRemovedObjectDeletions(removed) {
|
|
852
|
+
for (const item of removed) {
|
|
853
|
+
if (item instanceof TrackedObjectBase) {
|
|
854
|
+
item.markDeletion();
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
trackAddedObjectInsertions(added) {
|
|
859
|
+
for (const item of added) {
|
|
860
|
+
if (item instanceof TrackedObjectBase) {
|
|
861
|
+
item.markAsNew();
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
undoSplice(start, items, removed) {
|
|
866
|
+
this.tracker.withTrackingSuppressed(() => {
|
|
867
|
+
this.collection.splice(start, items?.length ?? 0, ...removed);
|
|
868
|
+
this.collection = [...this.collection];
|
|
869
|
+
const event = new TrackedCollectionChanged(
|
|
870
|
+
removed,
|
|
871
|
+
items,
|
|
872
|
+
this.collection
|
|
873
|
+
);
|
|
874
|
+
this.changed.emit(event);
|
|
875
|
+
});
|
|
876
|
+
}
|
|
877
|
+
reset(newItems) {
|
|
878
|
+
this.splice(0, this.collection.length, ...newItems);
|
|
879
|
+
}
|
|
880
|
+
reverse() {
|
|
881
|
+
this.collection.reverse();
|
|
882
|
+
return this.collection;
|
|
883
|
+
}
|
|
884
|
+
sort(compareFn) {
|
|
885
|
+
if (this.length === 0) {
|
|
886
|
+
return this;
|
|
887
|
+
}
|
|
888
|
+
this.collection.sort(compareFn);
|
|
889
|
+
return this;
|
|
890
|
+
}
|
|
891
|
+
clear() {
|
|
892
|
+
if (this.length === 0) {
|
|
893
|
+
return;
|
|
894
|
+
}
|
|
895
|
+
this.splice(0, this.length);
|
|
896
|
+
}
|
|
897
|
+
remove(item) {
|
|
898
|
+
const itemIndex = this.collection.indexOf(item);
|
|
899
|
+
if (itemIndex < 0) {
|
|
900
|
+
return false;
|
|
901
|
+
}
|
|
902
|
+
this.splice(itemIndex, 1);
|
|
903
|
+
return true;
|
|
904
|
+
}
|
|
905
|
+
replace(item, replace) {
|
|
906
|
+
const itemIndex = this.collection.indexOf(item);
|
|
907
|
+
if (itemIndex < 0) {
|
|
908
|
+
return false;
|
|
909
|
+
}
|
|
910
|
+
this.splice(itemIndex, 1, replace);
|
|
911
|
+
return true;
|
|
912
|
+
}
|
|
913
|
+
replaceAt(index, replace) {
|
|
914
|
+
this.splice(index, 1, replace);
|
|
915
|
+
}
|
|
916
|
+
pop() {
|
|
917
|
+
return this.length === 0 ? void 0 : this.splice(this.collection.length - 1, 1)[0];
|
|
918
|
+
}
|
|
919
|
+
push(...items) {
|
|
920
|
+
if (!items || items.length === 0) {
|
|
921
|
+
return this.length;
|
|
922
|
+
}
|
|
923
|
+
this.splice((this.lastItemIndex ?? -1) + 1, 0, ...items);
|
|
924
|
+
return this.length;
|
|
925
|
+
}
|
|
926
|
+
concat(...items) {
|
|
927
|
+
return this.collection.concat(...items);
|
|
928
|
+
}
|
|
929
|
+
join(separator) {
|
|
930
|
+
return this.collection.join(separator);
|
|
931
|
+
}
|
|
932
|
+
shift() {
|
|
933
|
+
return this.length === 0 ? void 0 : this.splice(0, 1)[0];
|
|
934
|
+
}
|
|
935
|
+
slice(start, end) {
|
|
936
|
+
return this.collection.slice(start, end);
|
|
937
|
+
}
|
|
938
|
+
unshift(...items) {
|
|
939
|
+
this.splice(0, 0, ...items);
|
|
940
|
+
return this.length;
|
|
941
|
+
}
|
|
942
|
+
indexOf(searchElement, fromIndex) {
|
|
943
|
+
return this.collection.indexOf(searchElement, fromIndex);
|
|
944
|
+
}
|
|
945
|
+
lastIndexOf(searchElement, fromIndex) {
|
|
946
|
+
return fromIndex !== void 0 ? this.collection.lastIndexOf(searchElement, fromIndex) : this.collection.lastIndexOf(searchElement);
|
|
947
|
+
}
|
|
948
|
+
every(predicate, thisArg) {
|
|
949
|
+
return this.collection.every(predicate, thisArg);
|
|
950
|
+
}
|
|
951
|
+
some(predicate, thisArg) {
|
|
952
|
+
return this.collection.some(predicate, thisArg);
|
|
953
|
+
}
|
|
954
|
+
forEach(callbackfn, thisArg) {
|
|
955
|
+
this.collection.forEach(callbackfn, thisArg);
|
|
956
|
+
}
|
|
957
|
+
map(callbackfn, thisArg) {
|
|
958
|
+
return this.collection.map(callbackfn, thisArg);
|
|
959
|
+
}
|
|
960
|
+
filter(predicate, thisArg) {
|
|
961
|
+
return this.collection.filter(predicate, thisArg);
|
|
962
|
+
}
|
|
963
|
+
find(predicate, thisArg) {
|
|
964
|
+
return this.collection.find(predicate, thisArg);
|
|
965
|
+
}
|
|
966
|
+
findIndex(predicate, thisArg) {
|
|
967
|
+
return this.collection.findIndex(predicate, thisArg);
|
|
968
|
+
}
|
|
969
|
+
flatMap(callback, thisArg) {
|
|
970
|
+
return this.collection.flatMap(callback, thisArg);
|
|
971
|
+
}
|
|
972
|
+
includes(searchElement, fromIndex) {
|
|
973
|
+
return this.collection.includes(searchElement, fromIndex);
|
|
974
|
+
}
|
|
975
|
+
toString() {
|
|
976
|
+
return this.collection.toString();
|
|
977
|
+
}
|
|
978
|
+
toLocaleString() {
|
|
979
|
+
return this.collection.toLocaleString();
|
|
980
|
+
}
|
|
981
|
+
entries() {
|
|
982
|
+
return this.collection.entries();
|
|
983
|
+
}
|
|
984
|
+
keys() {
|
|
985
|
+
return this.collection.keys();
|
|
986
|
+
}
|
|
987
|
+
values() {
|
|
988
|
+
return this.collection.values();
|
|
989
|
+
}
|
|
990
|
+
at(index) {
|
|
991
|
+
return this.collection.at(index);
|
|
992
|
+
}
|
|
993
|
+
fill(value, start, end) {
|
|
994
|
+
const len = this.length;
|
|
995
|
+
const s = start === void 0 ? 0 : start < 0 ? Math.max(len + start, 0) : Math.min(start, len);
|
|
996
|
+
const e = end === void 0 ? len : end < 0 ? Math.max(len + end, 0) : Math.min(end, len);
|
|
997
|
+
if (s >= e) return this;
|
|
998
|
+
this.splice(s, e - s, ...new Array(e - s).fill(value));
|
|
999
|
+
return this;
|
|
1000
|
+
}
|
|
1001
|
+
copyWithin(target, start, end) {
|
|
1002
|
+
const len = this.length;
|
|
1003
|
+
const t = target < 0 ? Math.max(len + target, 0) : Math.min(target, len);
|
|
1004
|
+
const s = start < 0 ? Math.max(len + start, 0) : Math.min(start, len);
|
|
1005
|
+
const e = end === void 0 ? len : end < 0 ? Math.max(len + end, 0) : Math.min(end, len);
|
|
1006
|
+
const itemsToCopy = this.collection.slice(s, e);
|
|
1007
|
+
const count = Math.min(itemsToCopy.length, len - t);
|
|
1008
|
+
if (count > 0) {
|
|
1009
|
+
this.splice(t, count, ...itemsToCopy.slice(0, count));
|
|
1010
|
+
}
|
|
1011
|
+
return this;
|
|
1012
|
+
}
|
|
1013
|
+
reduce(callbackfn, initialValue) {
|
|
1014
|
+
return initialValue !== void 0 ? this.collection.reduce(callbackfn, initialValue) : this.collection.reduce(callbackfn);
|
|
1015
|
+
}
|
|
1016
|
+
reduceRight(callbackfn, initialValue) {
|
|
1017
|
+
return initialValue !== void 0 ? this.collection.reduceRight(callbackfn, initialValue) : this.collection.reduceRight(callbackfn);
|
|
1018
|
+
}
|
|
1019
|
+
flat(depth) {
|
|
1020
|
+
return this._collection.flat(depth);
|
|
1021
|
+
}
|
|
1022
|
+
findLast(predicate, thisArg) {
|
|
1023
|
+
return this.collection.findLast(predicate, thisArg);
|
|
1024
|
+
}
|
|
1025
|
+
findLastIndex(predicate, thisArg) {
|
|
1026
|
+
return this.collection.findLastIndex(predicate, thisArg);
|
|
1027
|
+
}
|
|
1028
|
+
toReversed() {
|
|
1029
|
+
return this.collection.toReversed();
|
|
1030
|
+
}
|
|
1031
|
+
toSorted(compareFn) {
|
|
1032
|
+
return this.collection.toSorted(compareFn);
|
|
1033
|
+
}
|
|
1034
|
+
toSpliced(start, deleteCount, ...items) {
|
|
1035
|
+
return this.collection.toSpliced(start, deleteCount, ...items);
|
|
1036
|
+
}
|
|
1037
|
+
with(index, value) {
|
|
1038
|
+
return this.collection.with(index, value);
|
|
1039
|
+
}
|
|
1040
|
+
first() {
|
|
1041
|
+
return this.collection.length > 0 ? this.collection[0] : void 0;
|
|
1042
|
+
}
|
|
1043
|
+
destroy() {
|
|
1044
|
+
this.tracker.untrackCollection(this);
|
|
1045
|
+
}
|
|
1046
|
+
};
|
|
1047
|
+
var TrackedCollectionChanged = class {
|
|
1048
|
+
constructor(added, removed, newCollection) {
|
|
1049
|
+
this.added = added;
|
|
1050
|
+
this.removed = removed;
|
|
1051
|
+
this.newCollection = newCollection;
|
|
1052
|
+
}
|
|
1053
|
+
};
|
|
1054
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1055
|
+
0 && (module.exports = {
|
|
1056
|
+
ExternallyAssigned,
|
|
1057
|
+
InitializeTracked,
|
|
1058
|
+
ObjectState,
|
|
1059
|
+
OperationProperties,
|
|
1060
|
+
PropertyType,
|
|
1061
|
+
Tracked,
|
|
1062
|
+
TrackedCollection,
|
|
1063
|
+
TrackedCollectionChanged,
|
|
1064
|
+
TrackedObject,
|
|
1065
|
+
TrackedObjectBase,
|
|
1066
|
+
Tracker,
|
|
1067
|
+
TypedEvent,
|
|
1068
|
+
VersionedObjectState,
|
|
1069
|
+
VersionedTrackedObject
|
|
1070
|
+
});
|
|
1071
|
+
//# sourceMappingURL=index.cjs.map
|