reactronic 0.22.205 → 0.22.300

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.
@@ -1,130 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EditJournalImpl = exports.EditJournal = void 0;
4
- const Hooks_1 = require("./Hooks");
5
- const Data_1 = require("./Data");
6
- const Snapshot_1 = require("./Snapshot");
7
- const Transaction_1 = require("./Transaction");
8
- const Sealant_1 = require("../util/Sealant");
9
- class EditJournal extends Hooks_1.ObservableObject {
10
- static create() { return new EditJournalImpl(); }
11
- }
12
- exports.EditJournal = EditJournal;
13
- class EditJournalImpl extends EditJournal {
14
- constructor() {
15
- super(...arguments);
16
- this._capacity = 5;
17
- this._isSaving = false;
18
- this._edits = [];
19
- this._position = 0;
20
- this._saved = 0;
21
- }
22
- get capacity() { return this._capacity; }
23
- set capacity(value) { this._capacity = value; if (value < this._edits.length)
24
- this._edits.splice(0, this._edits.length - value); }
25
- get isSaving() { return this._isSaving; }
26
- get edits() { return this._edits; }
27
- get canUndo() { return this._edits.length > 0 && this._position > 0; }
28
- get canRedo() { return this._position < this._edits.length; }
29
- undo(count = 1) {
30
- Transaction_1.Transaction.run({ hint: 'EditJournal.undo', standalone: 'isolated' }, () => {
31
- let i = this._position - 1;
32
- while (i >= 0 && count > 0) {
33
- const patch = this._edits[i];
34
- EditJournalImpl.applyPatch(patch, true);
35
- i--, count--;
36
- }
37
- this._position = i + 1;
38
- });
39
- }
40
- redo(count = 1) {
41
- Transaction_1.Transaction.run({ hint: 'EditJournal.redo', standalone: 'isolated' }, () => {
42
- let i = this._position;
43
- while (i < this._edits.length && count > 0) {
44
- const patch = this._edits[i];
45
- EditJournalImpl.applyPatch(patch, false);
46
- i++, count--;
47
- }
48
- this._position = i;
49
- });
50
- }
51
- getUnsaved() {
52
- let result = undefined;
53
- const length = Math.abs(this._position - this._saved);
54
- if (length !== 0) {
55
- result = { hint: 'unsaved changes', objects: new Map() };
56
- const direction = Math.sign(this._position - this._saved);
57
- let i = 0;
58
- while (i < length) {
59
- const patch = this._edits[this._position + direction * (i + 1)];
60
- patch.objects.forEach((p, obj) => {
61
- });
62
- i++;
63
- }
64
- }
65
- return result;
66
- }
67
- beginSave() {
68
- this._isSaving = true;
69
- }
70
- endSave(success) {
71
- if (success)
72
- this._saved = this._position;
73
- this._isSaving = false;
74
- }
75
- register(p) {
76
- Transaction_1.Transaction.run({ hint: 'EditJournal.remember', standalone: 'isolated' }, () => {
77
- const items = this._edits = this._edits.toMutable();
78
- if (items.length >= this._capacity)
79
- items.shift();
80
- else
81
- items.splice(this._position);
82
- items.push(p);
83
- this._position = items.length;
84
- });
85
- }
86
- static buildPatch(hint, changeset) {
87
- const patch = { hint, objects: new Map() };
88
- changeset.forEach((r, h) => {
89
- const p = { current: {}, former: {} };
90
- const old = r.prev.revision !== Snapshot_1.ROOT_REV ? r.prev.revision.data : undefined;
91
- r.changes.forEach((episode, m) => {
92
- p.current[m] = unseal(r.data[m]);
93
- if (old)
94
- p.former[m] = unseal(old[m]);
95
- });
96
- if (!old) {
97
- delete p.current[Data_1.Meta.Disposed];
98
- p.former[Data_1.Meta.Disposed] = Data_1.Meta.Disposed;
99
- }
100
- patch.objects.set(h.proxy, p);
101
- });
102
- return patch;
103
- }
104
- static applyPatch(patch, undo) {
105
- const ctx = Snapshot_1.Snapshot.edit();
106
- patch.objects.forEach((p, obj) => {
107
- const h = Data_1.Meta.get(obj, Data_1.Meta.Holder);
108
- const data = undo ? p.former : p.current;
109
- if (data[Data_1.Meta.Disposed] === undefined) {
110
- for (const m in data) {
111
- const value = data[m];
112
- const r = ctx.getEditableRevision(h, m, value);
113
- if (r.snapshot === ctx) {
114
- r.data[m] = new Data_1.Observable(value);
115
- const v = r.prev.revision.data[m];
116
- Snapshot_1.Snapshot.markEdited(v, value, v !== value, r, m, h);
117
- }
118
- }
119
- }
120
- else
121
- Snapshot_1.Snapshot.doDispose(ctx, h);
122
- });
123
- }
124
- }
125
- exports.EditJournalImpl = EditJournalImpl;
126
- function unseal(observable) {
127
- const result = observable.value;
128
- const createCopy = result === null || result === void 0 ? void 0 : result[Sealant_1.Sealant.CreateCopy];
129
- return createCopy !== undefined ? createCopy.call(result) : result;
130
- }