@katn30/trakr 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 +1208 -0
- package/dist/dev/index.cjs +1273 -0
- package/dist/dev/index.cjs.map +1 -0
- package/dist/dev/index.d.cts +369 -0
- package/dist/dev/index.d.ts +369 -0
- package/dist/dev/index.js +1239 -0
- package/dist/dev/index.js.map +1 -0
- package/dist/prod/index.cjs +1273 -0
- package/dist/prod/index.cjs.map +1 -0
- package/dist/prod/index.js +1239 -0
- package/dist/prod/index.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
declare class TypedEvent<T> {
|
|
2
|
+
private readonly _handlers;
|
|
3
|
+
subscribe(handler: (event: T) => void): () => void;
|
|
4
|
+
unsubscribe(handler: (event: T) => void): void;
|
|
5
|
+
emit(event: T): void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare enum State {
|
|
9
|
+
Unchanged = "Unchanged",
|
|
10
|
+
Insert = "Insert",
|
|
11
|
+
Changed = "Changed",
|
|
12
|
+
Deleted = "Deleted"
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface ITracked {
|
|
16
|
+
tracker: Tracker;
|
|
17
|
+
isDirty: boolean;
|
|
18
|
+
dirtyCounter: number;
|
|
19
|
+
state: State;
|
|
20
|
+
/** @internal */
|
|
21
|
+
_setState(value: State): void;
|
|
22
|
+
/** @internal */
|
|
23
|
+
_validate(property: string, errorMessage: string | undefined): void;
|
|
24
|
+
/** @internal */
|
|
25
|
+
_applyValidation(messages: Map<string, string>): void;
|
|
26
|
+
destroy(): void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare enum PropertyType {
|
|
30
|
+
Boolean = 0,
|
|
31
|
+
String = 1,
|
|
32
|
+
Number = 2,
|
|
33
|
+
Collection = 3,
|
|
34
|
+
Object = 4,
|
|
35
|
+
Date = 5
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
declare class OperationProperties {
|
|
39
|
+
readonly trackedObject: ITracked;
|
|
40
|
+
readonly property: string | undefined;
|
|
41
|
+
readonly type: PropertyType;
|
|
42
|
+
readonly validator?: ((trackedObjects: any, newValue: any) => string | undefined) | undefined;
|
|
43
|
+
readonly coalesceWithin?: number | undefined;
|
|
44
|
+
constructor(trackedObject: ITracked, property: string | undefined, type: PropertyType, validator?: ((trackedObjects: any, newValue: any) => string | undefined) | undefined, coalesceWithin?: number | undefined);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
declare class Change {
|
|
48
|
+
readonly number: number;
|
|
49
|
+
readonly redoAction: () => void;
|
|
50
|
+
readonly undoAction: () => void;
|
|
51
|
+
readonly properties: OperationProperties;
|
|
52
|
+
readonly time: Date;
|
|
53
|
+
constructor(number: number, redoAction: () => void, undoAction: () => void, properties: OperationProperties);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
declare class Operation {
|
|
57
|
+
readonly time: Date;
|
|
58
|
+
readonly actions: Change[];
|
|
59
|
+
private _hasActions;
|
|
60
|
+
get hasActions(): boolean;
|
|
61
|
+
private set hasActions(value);
|
|
62
|
+
add(redoAction: () => void, undoAction: () => void, properties: OperationProperties): void;
|
|
63
|
+
updateOrAdd(redoAction: () => void, undoAction: () => void, properties: OperationProperties): void;
|
|
64
|
+
redo(): void;
|
|
65
|
+
undo(): void;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
declare class TrackedCollection<T> implements Array<T>, ITracked {
|
|
69
|
+
readonly tracker: Tracker;
|
|
70
|
+
private readonly _validator?;
|
|
71
|
+
private _collection;
|
|
72
|
+
private _isDirty;
|
|
73
|
+
private _isValid;
|
|
74
|
+
private _dirtyCounter;
|
|
75
|
+
private _error;
|
|
76
|
+
private readAccess;
|
|
77
|
+
get dirtyCounter(): number;
|
|
78
|
+
private set dirtyCounter(value);
|
|
79
|
+
get isDirty(): boolean;
|
|
80
|
+
private set isDirty(value);
|
|
81
|
+
get isValid(): boolean;
|
|
82
|
+
private set isValid(value);
|
|
83
|
+
get length(): number;
|
|
84
|
+
get lastItemIndex(): number | undefined;
|
|
85
|
+
get collection(): T[];
|
|
86
|
+
private set collection(value);
|
|
87
|
+
get [Symbol.iterator](): () => ArrayIterator<T>;
|
|
88
|
+
get [Symbol.unscopables](): {
|
|
89
|
+
[x: number]: boolean | undefined;
|
|
90
|
+
length?: boolean | undefined;
|
|
91
|
+
toString?: boolean | undefined;
|
|
92
|
+
toLocaleString?: boolean | undefined;
|
|
93
|
+
pop?: boolean | undefined;
|
|
94
|
+
push?: boolean | undefined;
|
|
95
|
+
concat?: boolean | undefined;
|
|
96
|
+
join?: boolean | undefined;
|
|
97
|
+
reverse?: boolean | undefined;
|
|
98
|
+
shift?: boolean | undefined;
|
|
99
|
+
slice?: boolean | undefined;
|
|
100
|
+
sort?: boolean | undefined;
|
|
101
|
+
splice?: boolean | undefined;
|
|
102
|
+
unshift?: boolean | undefined;
|
|
103
|
+
indexOf?: boolean | undefined;
|
|
104
|
+
lastIndexOf?: boolean | undefined;
|
|
105
|
+
every?: boolean | undefined;
|
|
106
|
+
some?: boolean | undefined;
|
|
107
|
+
forEach?: boolean | undefined;
|
|
108
|
+
map?: boolean | undefined;
|
|
109
|
+
filter?: boolean | undefined;
|
|
110
|
+
reduce?: boolean | undefined;
|
|
111
|
+
reduceRight?: boolean | undefined;
|
|
112
|
+
find?: boolean | undefined;
|
|
113
|
+
findIndex?: boolean | undefined;
|
|
114
|
+
fill?: boolean | undefined;
|
|
115
|
+
copyWithin?: boolean | undefined;
|
|
116
|
+
entries?: boolean | undefined;
|
|
117
|
+
keys?: boolean | undefined;
|
|
118
|
+
values?: boolean | undefined;
|
|
119
|
+
includes?: boolean | undefined;
|
|
120
|
+
flatMap?: boolean | undefined;
|
|
121
|
+
flat?: boolean | undefined;
|
|
122
|
+
at?: boolean | undefined;
|
|
123
|
+
findLast?: boolean | undefined;
|
|
124
|
+
findLastIndex?: boolean | undefined;
|
|
125
|
+
toReversed?: boolean | undefined;
|
|
126
|
+
toSorted?: boolean | undefined;
|
|
127
|
+
toSpliced?: boolean | undefined;
|
|
128
|
+
with?: boolean | undefined;
|
|
129
|
+
[Symbol.iterator]?: boolean | undefined;
|
|
130
|
+
readonly [Symbol.unscopables]?: boolean | undefined;
|
|
131
|
+
};
|
|
132
|
+
readonly changed: TypedEvent<TrackedCollectionChanged<T>>;
|
|
133
|
+
readonly trackedChanged: TypedEvent<TrackedCollectionChanged<T>>;
|
|
134
|
+
[n: number]: T;
|
|
135
|
+
get error(): string | undefined;
|
|
136
|
+
set error(value: string | undefined);
|
|
137
|
+
constructor(tracker: Tracker, items?: T[], _validator?: ((value: T[]) => string | undefined) | undefined);
|
|
138
|
+
/** @internal */
|
|
139
|
+
readonly state: State;
|
|
140
|
+
/** @internal */
|
|
141
|
+
_setState(_value: State): void;
|
|
142
|
+
/** @internal */
|
|
143
|
+
_validate(): void;
|
|
144
|
+
/** @internal */
|
|
145
|
+
_applyValidation(_messages: Map<string, string>): void;
|
|
146
|
+
splice(start: number, deleteCount: number, ...items: T[]): T[];
|
|
147
|
+
private doSplice;
|
|
148
|
+
private trackRemovedObjectDeletions;
|
|
149
|
+
private trackAddedObjectInsertions;
|
|
150
|
+
private undoSplice;
|
|
151
|
+
reset(newItems: T[]): void;
|
|
152
|
+
reverse(): T[];
|
|
153
|
+
sort(compareFn?: (a: T, b: T) => number): this;
|
|
154
|
+
clear(): void;
|
|
155
|
+
remove(item: T): boolean;
|
|
156
|
+
replace(item: T, replace: T): boolean;
|
|
157
|
+
replaceAt(index: number, replace: T): void;
|
|
158
|
+
pop(): T | undefined;
|
|
159
|
+
push(...items: T[]): number;
|
|
160
|
+
concat(...items: (T | ConcatArray<T>)[]): T[];
|
|
161
|
+
join(separator?: string): string;
|
|
162
|
+
shift(): T | undefined;
|
|
163
|
+
slice(start?: number, end?: number): T[];
|
|
164
|
+
unshift(...items: T[]): number;
|
|
165
|
+
indexOf(searchElement: T, fromIndex?: number): number;
|
|
166
|
+
lastIndexOf(searchElement: T, fromIndex?: number): number;
|
|
167
|
+
every<S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any): this is S[];
|
|
168
|
+
every(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean;
|
|
169
|
+
some(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean;
|
|
170
|
+
forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void;
|
|
171
|
+
map<U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[];
|
|
172
|
+
filter(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): T[];
|
|
173
|
+
find(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): T | undefined;
|
|
174
|
+
findIndex(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): number;
|
|
175
|
+
flatMap<U, This = undefined>(callback: (this: This, value: T, index: number, array: T[]) => U | ReadonlyArray<U>, thisArg?: This): U[];
|
|
176
|
+
includes(searchElement: T, fromIndex?: number): boolean;
|
|
177
|
+
toString(): string;
|
|
178
|
+
toLocaleString(): string;
|
|
179
|
+
entries(): ArrayIterator<[number, T]>;
|
|
180
|
+
keys(): ArrayIterator<number>;
|
|
181
|
+
values(): ArrayIterator<T>;
|
|
182
|
+
at(index: number): T | undefined;
|
|
183
|
+
fill(value: T, start?: number, end?: number): this;
|
|
184
|
+
copyWithin(target: number, start: number, end?: number): this;
|
|
185
|
+
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T;
|
|
186
|
+
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T;
|
|
187
|
+
flat<A, D extends number = 1>(this: A, depth?: D): FlatArray<A, D>[];
|
|
188
|
+
findLast(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): T | undefined;
|
|
189
|
+
findLastIndex(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): number;
|
|
190
|
+
toReversed(): T[];
|
|
191
|
+
toSorted(compareFn?: (a: T, b: T) => number): T[];
|
|
192
|
+
toSpliced(start: number, deleteCount: number, ...items: T[]): T[];
|
|
193
|
+
with(index: number, value: T): T[];
|
|
194
|
+
first(): T | undefined;
|
|
195
|
+
destroy(): void;
|
|
196
|
+
}
|
|
197
|
+
declare class TrackedCollectionChanged<T> {
|
|
198
|
+
readonly added: T[];
|
|
199
|
+
readonly removed: T[];
|
|
200
|
+
readonly newCollection: T[];
|
|
201
|
+
constructor(added: T[], removed: T[], newCollection: T[]);
|
|
202
|
+
}
|
|
203
|
+
declare global {
|
|
204
|
+
interface ArrayIterator<T> extends IterableIterator<T> {
|
|
205
|
+
map<U>(callback: (value: T) => U): ArrayIterator<U>;
|
|
206
|
+
filter(predicate: (value: T) => boolean): ArrayIterator<T>;
|
|
207
|
+
take(count: number): ArrayIterator<T>;
|
|
208
|
+
drop(count: number): ArrayIterator<T>;
|
|
209
|
+
flatMap<U>(callback: (value: T) => U[]): ArrayIterator<U>;
|
|
210
|
+
reduce<U>(callback: (acc: U, value: T) => U, initialValue: U): U;
|
|
211
|
+
toArray(): T[];
|
|
212
|
+
forEach(callback: (value: T) => void): void;
|
|
213
|
+
some(predicate: (value: T) => boolean): boolean;
|
|
214
|
+
every(predicate: (value: T) => boolean): boolean;
|
|
215
|
+
find(predicate: (value: T) => boolean): T | undefined;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
interface IdAssignment {
|
|
220
|
+
placeholder: number;
|
|
221
|
+
value: number;
|
|
222
|
+
}
|
|
223
|
+
declare function AutoId<This extends object, Value>(_target: undefined, context: ClassFieldDecoratorContext<This, Value>): void;
|
|
224
|
+
|
|
225
|
+
interface StateTarget {
|
|
226
|
+
idPlaceholder: number | null;
|
|
227
|
+
state: State;
|
|
228
|
+
_setState(value: State): void;
|
|
229
|
+
_getDirtyCounter(): number;
|
|
230
|
+
_setDirtyCounter(value: number): void;
|
|
231
|
+
readonly tracker: {
|
|
232
|
+
_nextPlaceholder(): number;
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
interface TrackedPropertyChanged {
|
|
237
|
+
property: string;
|
|
238
|
+
oldValue: unknown;
|
|
239
|
+
newValue: unknown;
|
|
240
|
+
}
|
|
241
|
+
declare abstract class TrackedObject implements ITracked, StateTarget {
|
|
242
|
+
readonly tracker: Tracker;
|
|
243
|
+
private _dirtyCounter;
|
|
244
|
+
private _validationMessages;
|
|
245
|
+
private _isValid;
|
|
246
|
+
private _state;
|
|
247
|
+
idPlaceholder: number | null;
|
|
248
|
+
readonly changed: TypedEvent<TrackedPropertyChanged>;
|
|
249
|
+
readonly trackedChanged: TypedEvent<TrackedPropertyChanged>;
|
|
250
|
+
/** @internal */
|
|
251
|
+
get state(): State;
|
|
252
|
+
/** @internal */
|
|
253
|
+
_setState(value: State): void;
|
|
254
|
+
/** @internal */
|
|
255
|
+
_getDirtyCounter(): number;
|
|
256
|
+
/** @internal */
|
|
257
|
+
_setDirtyCounter(value: number): void;
|
|
258
|
+
get validationMessages(): Map<string, string | undefined>;
|
|
259
|
+
private set validationMessages(value);
|
|
260
|
+
get isValid(): boolean;
|
|
261
|
+
private set isValid(value);
|
|
262
|
+
get isDirty(): boolean;
|
|
263
|
+
get dirtyCounter(): number;
|
|
264
|
+
protected set dirtyCounter(value: number);
|
|
265
|
+
constructor(tracker: Tracker);
|
|
266
|
+
/** @internal */
|
|
267
|
+
_onCommitted(lastOp?: Operation, keys?: IdAssignment[]): void;
|
|
268
|
+
/** @internal */
|
|
269
|
+
_markRemoved(): void;
|
|
270
|
+
/** @internal */
|
|
271
|
+
_markAdded(): void;
|
|
272
|
+
/** @internal */
|
|
273
|
+
_validate(property: string, errorMessage: string | undefined): void;
|
|
274
|
+
/** @internal */
|
|
275
|
+
_applyValidation(messages: Map<string, string>): void;
|
|
276
|
+
destroy(): void;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
declare class Tracker {
|
|
280
|
+
private _currentOperation;
|
|
281
|
+
private readonly _redoOperations;
|
|
282
|
+
private readonly _undoOperations;
|
|
283
|
+
private _commitStateOperation;
|
|
284
|
+
private _isDirty;
|
|
285
|
+
private _canUndo;
|
|
286
|
+
private _canRedo;
|
|
287
|
+
private _suppressTrackingCounter;
|
|
288
|
+
private _currentOperationOwner;
|
|
289
|
+
private _currentOperationPropertyName;
|
|
290
|
+
private _isValid;
|
|
291
|
+
private _canCommit;
|
|
292
|
+
private _placeholderCounter;
|
|
293
|
+
private _invalidCount;
|
|
294
|
+
private _constructionDepth;
|
|
295
|
+
private _composingBaseIndex;
|
|
296
|
+
private _composingRedoLength;
|
|
297
|
+
private _version;
|
|
298
|
+
_isReplaying: boolean;
|
|
299
|
+
readonly trackedObjects: TrackedObject[];
|
|
300
|
+
get deletedObjects(): TrackedObject[];
|
|
301
|
+
readonly trackedCollections: TrackedCollection<any>[];
|
|
302
|
+
get isDirty(): boolean;
|
|
303
|
+
set isDirty(value: boolean);
|
|
304
|
+
readonly isDirtyChanged: TypedEvent<boolean>;
|
|
305
|
+
get version(): number;
|
|
306
|
+
readonly versionChanged: TypedEvent<number>;
|
|
307
|
+
get isValid(): boolean;
|
|
308
|
+
private set isValid(value);
|
|
309
|
+
readonly isValidChanged: TypedEvent<boolean>;
|
|
310
|
+
get canCommit(): boolean;
|
|
311
|
+
private set canCommit(value);
|
|
312
|
+
readonly canCommitChanged: TypedEvent<boolean>;
|
|
313
|
+
private updateCanCommit;
|
|
314
|
+
get canUndo(): boolean;
|
|
315
|
+
private set canUndo(value);
|
|
316
|
+
get canRedo(): boolean;
|
|
317
|
+
private set canRedo(value);
|
|
318
|
+
/** @internal */
|
|
319
|
+
get _isTrackingSuppressed(): boolean;
|
|
320
|
+
/** @internal */
|
|
321
|
+
get _isConstructing(): boolean;
|
|
322
|
+
constructor();
|
|
323
|
+
/** @internal */
|
|
324
|
+
_trackObject(trackedObject: TrackedObject): void;
|
|
325
|
+
/** @internal */
|
|
326
|
+
_untrackObject(trackedObject: TrackedObject): void;
|
|
327
|
+
/** @internal */
|
|
328
|
+
_trackCollection(trackedCollection: TrackedCollection<any>): void;
|
|
329
|
+
/** @internal */
|
|
330
|
+
_untrackCollection(trackedCollection: TrackedCollection<any>): void;
|
|
331
|
+
/** @internal */
|
|
332
|
+
_onValidityChanged(wasValid: boolean, isNowValid: boolean): void;
|
|
333
|
+
construct<T>(action: () => T): T;
|
|
334
|
+
withTrackingSuppressed(action: () => void): void;
|
|
335
|
+
beginSuppressTracking(): void;
|
|
336
|
+
endSuppressTracking(): void;
|
|
337
|
+
/** @internal */
|
|
338
|
+
_doAndTrack(redoAction: () => void, undoAction: () => void, properties: OperationProperties): void;
|
|
339
|
+
private revalidateTargeted;
|
|
340
|
+
private isEndingCurrentOperation;
|
|
341
|
+
private isStartingNewOperation;
|
|
342
|
+
private shouldCoalesceChanges;
|
|
343
|
+
private isCoalescibleType;
|
|
344
|
+
private hasLastOperation;
|
|
345
|
+
private lastOperationTargetsSameProperty;
|
|
346
|
+
private lastActionIsRecent;
|
|
347
|
+
/** @internal */
|
|
348
|
+
_nextPlaceholder(): number;
|
|
349
|
+
onCommit(keys?: IdAssignment[]): void;
|
|
350
|
+
/** @internal */
|
|
351
|
+
_isInUndoStack(op: Operation): boolean;
|
|
352
|
+
private reset;
|
|
353
|
+
startComposing(): void;
|
|
354
|
+
endComposing(): void;
|
|
355
|
+
rollbackComposing(): void;
|
|
356
|
+
undo(): void;
|
|
357
|
+
redo(): void;
|
|
358
|
+
revalidate(): void;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
declare function Tracked(validator?: (self: any, newValue: any) => string | undefined, onChange?: (self: any, newValue: any, oldValue: any) => void, options?: {
|
|
362
|
+
coalesceWithin?: number;
|
|
363
|
+
}): {
|
|
364
|
+
<T extends TrackedObject, V>(target: ClassAccessorDecoratorTarget<T, V>, context: ClassAccessorDecoratorContext<T, V>): ClassAccessorDecoratorResult<T, V>;
|
|
365
|
+
<T extends TrackedObject, V>(target: (this: T, value: V) => void, context: ClassSetterDecoratorContext<T, V>): (this: T, value: V) => void;
|
|
366
|
+
<T extends TrackedObject, V>(target: (this: T) => V, context: ClassGetterDecoratorContext<T, V>): (this: T) => V;
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
export { AutoId, type ITracked, type IdAssignment, State, Tracked, TrackedCollection, TrackedCollectionChanged, TrackedObject, type TrackedPropertyChanged, Tracker, TypedEvent };
|