@jupyterlab/observables 2.1.1-alpha.0 → 2.1.1
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/lib/index.d.ts +6 -6
- package/lib/index.js +15 -15
- package/lib/modeldb.d.ts +427 -427
- package/lib/modeldb.js +294 -294
- package/lib/observablejson.d.ts +61 -61
- package/lib/observablejson.js +54 -54
- package/lib/observablelist.d.ts +504 -504
- package/lib/observablelist.js +384 -384
- package/lib/observablemap.d.ts +226 -226
- package/lib/observablemap.js +180 -180
- package/lib/observablestring.d.ts +147 -147
- package/lib/observablestring.js +109 -109
- package/lib/undoablelist.d.ts +132 -132
- package/lib/undoablelist.js +228 -228
- package/package.json +7 -4
package/lib/undoablelist.js
CHANGED
|
@@ -1,228 +1,228 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright (c) Jupyter Development Team.
|
|
3
|
-
// Distributed under the terms of the Modified BSD License.
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
const algorithm_1 = require("@phosphor/algorithm");
|
|
6
|
-
const observablelist_1 = require("./observablelist");
|
|
7
|
-
/**
|
|
8
|
-
* A concrete implementation of an observable undoable list.
|
|
9
|
-
*/
|
|
10
|
-
class ObservableUndoableList extends observablelist_1.ObservableList {
|
|
11
|
-
/**
|
|
12
|
-
* Construct a new undoable observable list.
|
|
13
|
-
*/
|
|
14
|
-
constructor(serializer) {
|
|
15
|
-
super();
|
|
16
|
-
this._inCompound = false;
|
|
17
|
-
this._isUndoable = true;
|
|
18
|
-
this._madeCompoundChange = false;
|
|
19
|
-
this._index = -1;
|
|
20
|
-
this._stack = [];
|
|
21
|
-
this._serializer = serializer;
|
|
22
|
-
this.changed.connect(this._onListChanged, this);
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Whether the object can redo changes.
|
|
26
|
-
*/
|
|
27
|
-
get canRedo() {
|
|
28
|
-
return this._index < this._stack.length - 1;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Whether the object can undo changes.
|
|
32
|
-
*/
|
|
33
|
-
get canUndo() {
|
|
34
|
-
return this._index >= 0;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Begin a compound operation.
|
|
38
|
-
*
|
|
39
|
-
* @param isUndoAble - Whether the operation is undoable.
|
|
40
|
-
* The default is `true`.
|
|
41
|
-
*/
|
|
42
|
-
beginCompoundOperation(isUndoAble) {
|
|
43
|
-
this._inCompound = true;
|
|
44
|
-
this._isUndoable = isUndoAble !== false;
|
|
45
|
-
this._madeCompoundChange = false;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* End a compound operation.
|
|
49
|
-
*/
|
|
50
|
-
endCompoundOperation() {
|
|
51
|
-
this._inCompound = false;
|
|
52
|
-
this._isUndoable = true;
|
|
53
|
-
if (this._madeCompoundChange) {
|
|
54
|
-
this._index++;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Undo an operation.
|
|
59
|
-
*/
|
|
60
|
-
undo() {
|
|
61
|
-
if (!this.canUndo) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
let changes = this._stack[this._index];
|
|
65
|
-
this._isUndoable = false;
|
|
66
|
-
for (let change of changes.reverse()) {
|
|
67
|
-
this._undoChange(change);
|
|
68
|
-
}
|
|
69
|
-
this._isUndoable = true;
|
|
70
|
-
this._index--;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Redo an operation.
|
|
74
|
-
*/
|
|
75
|
-
redo() {
|
|
76
|
-
if (!this.canRedo) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
this._index++;
|
|
80
|
-
let changes = this._stack[this._index];
|
|
81
|
-
this._isUndoable = false;
|
|
82
|
-
for (let change of changes) {
|
|
83
|
-
this._redoChange(change);
|
|
84
|
-
}
|
|
85
|
-
this._isUndoable = true;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Clear the change stack.
|
|
89
|
-
*/
|
|
90
|
-
clearUndo() {
|
|
91
|
-
this._index = -1;
|
|
92
|
-
this._stack = [];
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Handle a change in the list.
|
|
96
|
-
*/
|
|
97
|
-
_onListChanged(list, change) {
|
|
98
|
-
if (this.isDisposed || !this._isUndoable) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
// Clear everything after this position if necessary.
|
|
102
|
-
if (!this._inCompound || !this._madeCompoundChange) {
|
|
103
|
-
this._stack = this._stack.slice(0, this._index + 1);
|
|
104
|
-
}
|
|
105
|
-
// Copy the change.
|
|
106
|
-
let evt = this._copyChange(change);
|
|
107
|
-
// Put the change in the stack.
|
|
108
|
-
if (this._stack[this._index + 1]) {
|
|
109
|
-
this._stack[this._index + 1].push(evt);
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
this._stack.push([evt]);
|
|
113
|
-
}
|
|
114
|
-
// If not in a compound operation, increase index.
|
|
115
|
-
if (!this._inCompound) {
|
|
116
|
-
this._index++;
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
this._madeCompoundChange = true;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Undo a change event.
|
|
124
|
-
*/
|
|
125
|
-
_undoChange(change) {
|
|
126
|
-
let index = 0;
|
|
127
|
-
let serializer = this._serializer;
|
|
128
|
-
switch (change.type) {
|
|
129
|
-
case 'add':
|
|
130
|
-
algorithm_1.each(change.newValues, () => {
|
|
131
|
-
this.remove(change.newIndex);
|
|
132
|
-
});
|
|
133
|
-
break;
|
|
134
|
-
case 'set':
|
|
135
|
-
index = change.oldIndex;
|
|
136
|
-
algorithm_1.each(change.oldValues, value => {
|
|
137
|
-
this.set(index++, serializer.fromJSON(value));
|
|
138
|
-
});
|
|
139
|
-
break;
|
|
140
|
-
case 'remove':
|
|
141
|
-
index = change.oldIndex;
|
|
142
|
-
algorithm_1.each(change.oldValues, value => {
|
|
143
|
-
this.insert(index++, serializer.fromJSON(value));
|
|
144
|
-
});
|
|
145
|
-
break;
|
|
146
|
-
case 'move':
|
|
147
|
-
this.move(change.newIndex, change.oldIndex);
|
|
148
|
-
break;
|
|
149
|
-
default:
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Redo a change event.
|
|
155
|
-
*/
|
|
156
|
-
_redoChange(change) {
|
|
157
|
-
let index = 0;
|
|
158
|
-
let serializer = this._serializer;
|
|
159
|
-
switch (change.type) {
|
|
160
|
-
case 'add':
|
|
161
|
-
index = change.newIndex;
|
|
162
|
-
algorithm_1.each(change.newValues, value => {
|
|
163
|
-
this.insert(index++, serializer.fromJSON(value));
|
|
164
|
-
});
|
|
165
|
-
break;
|
|
166
|
-
case 'set':
|
|
167
|
-
index = change.newIndex;
|
|
168
|
-
algorithm_1.each(change.newValues, value => {
|
|
169
|
-
this.set(change.newIndex++, serializer.fromJSON(value));
|
|
170
|
-
});
|
|
171
|
-
break;
|
|
172
|
-
case 'remove':
|
|
173
|
-
algorithm_1.each(change.oldValues, () => {
|
|
174
|
-
this.remove(change.oldIndex);
|
|
175
|
-
});
|
|
176
|
-
break;
|
|
177
|
-
case 'move':
|
|
178
|
-
this.move(change.oldIndex, change.newIndex);
|
|
179
|
-
break;
|
|
180
|
-
default:
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Copy a change as JSON.
|
|
186
|
-
*/
|
|
187
|
-
_copyChange(change) {
|
|
188
|
-
let oldValues = [];
|
|
189
|
-
algorithm_1.each(change.oldValues, value => {
|
|
190
|
-
oldValues.push(this._serializer.toJSON(value));
|
|
191
|
-
});
|
|
192
|
-
let newValues = [];
|
|
193
|
-
algorithm_1.each(change.newValues, value => {
|
|
194
|
-
newValues.push(this._serializer.toJSON(value));
|
|
195
|
-
});
|
|
196
|
-
return {
|
|
197
|
-
type: change.type,
|
|
198
|
-
oldIndex: change.oldIndex,
|
|
199
|
-
newIndex: change.newIndex,
|
|
200
|
-
oldValues,
|
|
201
|
-
newValues
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
exports.ObservableUndoableList = ObservableUndoableList;
|
|
206
|
-
/**
|
|
207
|
-
* Namespace for ObservableUndoableList utilities.
|
|
208
|
-
*/
|
|
209
|
-
(function (ObservableUndoableList) {
|
|
210
|
-
/**
|
|
211
|
-
* A default, identity serializer.
|
|
212
|
-
*/
|
|
213
|
-
class IdentitySerializer {
|
|
214
|
-
/**
|
|
215
|
-
* Identity serialize.
|
|
216
|
-
*/
|
|
217
|
-
toJSON(value) {
|
|
218
|
-
return value;
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Identity deserialize.
|
|
222
|
-
*/
|
|
223
|
-
fromJSON(value) {
|
|
224
|
-
return value;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
ObservableUndoableList.IdentitySerializer = IdentitySerializer;
|
|
228
|
-
})(ObservableUndoableList = exports.ObservableUndoableList || (exports.ObservableUndoableList = {}));
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Jupyter Development Team.
|
|
3
|
+
// Distributed under the terms of the Modified BSD License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
const algorithm_1 = require("@phosphor/algorithm");
|
|
6
|
+
const observablelist_1 = require("./observablelist");
|
|
7
|
+
/**
|
|
8
|
+
* A concrete implementation of an observable undoable list.
|
|
9
|
+
*/
|
|
10
|
+
class ObservableUndoableList extends observablelist_1.ObservableList {
|
|
11
|
+
/**
|
|
12
|
+
* Construct a new undoable observable list.
|
|
13
|
+
*/
|
|
14
|
+
constructor(serializer) {
|
|
15
|
+
super();
|
|
16
|
+
this._inCompound = false;
|
|
17
|
+
this._isUndoable = true;
|
|
18
|
+
this._madeCompoundChange = false;
|
|
19
|
+
this._index = -1;
|
|
20
|
+
this._stack = [];
|
|
21
|
+
this._serializer = serializer;
|
|
22
|
+
this.changed.connect(this._onListChanged, this);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Whether the object can redo changes.
|
|
26
|
+
*/
|
|
27
|
+
get canRedo() {
|
|
28
|
+
return this._index < this._stack.length - 1;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Whether the object can undo changes.
|
|
32
|
+
*/
|
|
33
|
+
get canUndo() {
|
|
34
|
+
return this._index >= 0;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Begin a compound operation.
|
|
38
|
+
*
|
|
39
|
+
* @param isUndoAble - Whether the operation is undoable.
|
|
40
|
+
* The default is `true`.
|
|
41
|
+
*/
|
|
42
|
+
beginCompoundOperation(isUndoAble) {
|
|
43
|
+
this._inCompound = true;
|
|
44
|
+
this._isUndoable = isUndoAble !== false;
|
|
45
|
+
this._madeCompoundChange = false;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* End a compound operation.
|
|
49
|
+
*/
|
|
50
|
+
endCompoundOperation() {
|
|
51
|
+
this._inCompound = false;
|
|
52
|
+
this._isUndoable = true;
|
|
53
|
+
if (this._madeCompoundChange) {
|
|
54
|
+
this._index++;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Undo an operation.
|
|
59
|
+
*/
|
|
60
|
+
undo() {
|
|
61
|
+
if (!this.canUndo) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
let changes = this._stack[this._index];
|
|
65
|
+
this._isUndoable = false;
|
|
66
|
+
for (let change of changes.reverse()) {
|
|
67
|
+
this._undoChange(change);
|
|
68
|
+
}
|
|
69
|
+
this._isUndoable = true;
|
|
70
|
+
this._index--;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Redo an operation.
|
|
74
|
+
*/
|
|
75
|
+
redo() {
|
|
76
|
+
if (!this.canRedo) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
this._index++;
|
|
80
|
+
let changes = this._stack[this._index];
|
|
81
|
+
this._isUndoable = false;
|
|
82
|
+
for (let change of changes) {
|
|
83
|
+
this._redoChange(change);
|
|
84
|
+
}
|
|
85
|
+
this._isUndoable = true;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Clear the change stack.
|
|
89
|
+
*/
|
|
90
|
+
clearUndo() {
|
|
91
|
+
this._index = -1;
|
|
92
|
+
this._stack = [];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Handle a change in the list.
|
|
96
|
+
*/
|
|
97
|
+
_onListChanged(list, change) {
|
|
98
|
+
if (this.isDisposed || !this._isUndoable) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
// Clear everything after this position if necessary.
|
|
102
|
+
if (!this._inCompound || !this._madeCompoundChange) {
|
|
103
|
+
this._stack = this._stack.slice(0, this._index + 1);
|
|
104
|
+
}
|
|
105
|
+
// Copy the change.
|
|
106
|
+
let evt = this._copyChange(change);
|
|
107
|
+
// Put the change in the stack.
|
|
108
|
+
if (this._stack[this._index + 1]) {
|
|
109
|
+
this._stack[this._index + 1].push(evt);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
this._stack.push([evt]);
|
|
113
|
+
}
|
|
114
|
+
// If not in a compound operation, increase index.
|
|
115
|
+
if (!this._inCompound) {
|
|
116
|
+
this._index++;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
this._madeCompoundChange = true;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Undo a change event.
|
|
124
|
+
*/
|
|
125
|
+
_undoChange(change) {
|
|
126
|
+
let index = 0;
|
|
127
|
+
let serializer = this._serializer;
|
|
128
|
+
switch (change.type) {
|
|
129
|
+
case 'add':
|
|
130
|
+
algorithm_1.each(change.newValues, () => {
|
|
131
|
+
this.remove(change.newIndex);
|
|
132
|
+
});
|
|
133
|
+
break;
|
|
134
|
+
case 'set':
|
|
135
|
+
index = change.oldIndex;
|
|
136
|
+
algorithm_1.each(change.oldValues, value => {
|
|
137
|
+
this.set(index++, serializer.fromJSON(value));
|
|
138
|
+
});
|
|
139
|
+
break;
|
|
140
|
+
case 'remove':
|
|
141
|
+
index = change.oldIndex;
|
|
142
|
+
algorithm_1.each(change.oldValues, value => {
|
|
143
|
+
this.insert(index++, serializer.fromJSON(value));
|
|
144
|
+
});
|
|
145
|
+
break;
|
|
146
|
+
case 'move':
|
|
147
|
+
this.move(change.newIndex, change.oldIndex);
|
|
148
|
+
break;
|
|
149
|
+
default:
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Redo a change event.
|
|
155
|
+
*/
|
|
156
|
+
_redoChange(change) {
|
|
157
|
+
let index = 0;
|
|
158
|
+
let serializer = this._serializer;
|
|
159
|
+
switch (change.type) {
|
|
160
|
+
case 'add':
|
|
161
|
+
index = change.newIndex;
|
|
162
|
+
algorithm_1.each(change.newValues, value => {
|
|
163
|
+
this.insert(index++, serializer.fromJSON(value));
|
|
164
|
+
});
|
|
165
|
+
break;
|
|
166
|
+
case 'set':
|
|
167
|
+
index = change.newIndex;
|
|
168
|
+
algorithm_1.each(change.newValues, value => {
|
|
169
|
+
this.set(change.newIndex++, serializer.fromJSON(value));
|
|
170
|
+
});
|
|
171
|
+
break;
|
|
172
|
+
case 'remove':
|
|
173
|
+
algorithm_1.each(change.oldValues, () => {
|
|
174
|
+
this.remove(change.oldIndex);
|
|
175
|
+
});
|
|
176
|
+
break;
|
|
177
|
+
case 'move':
|
|
178
|
+
this.move(change.oldIndex, change.newIndex);
|
|
179
|
+
break;
|
|
180
|
+
default:
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Copy a change as JSON.
|
|
186
|
+
*/
|
|
187
|
+
_copyChange(change) {
|
|
188
|
+
let oldValues = [];
|
|
189
|
+
algorithm_1.each(change.oldValues, value => {
|
|
190
|
+
oldValues.push(this._serializer.toJSON(value));
|
|
191
|
+
});
|
|
192
|
+
let newValues = [];
|
|
193
|
+
algorithm_1.each(change.newValues, value => {
|
|
194
|
+
newValues.push(this._serializer.toJSON(value));
|
|
195
|
+
});
|
|
196
|
+
return {
|
|
197
|
+
type: change.type,
|
|
198
|
+
oldIndex: change.oldIndex,
|
|
199
|
+
newIndex: change.newIndex,
|
|
200
|
+
oldValues,
|
|
201
|
+
newValues
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
exports.ObservableUndoableList = ObservableUndoableList;
|
|
206
|
+
/**
|
|
207
|
+
* Namespace for ObservableUndoableList utilities.
|
|
208
|
+
*/
|
|
209
|
+
(function (ObservableUndoableList) {
|
|
210
|
+
/**
|
|
211
|
+
* A default, identity serializer.
|
|
212
|
+
*/
|
|
213
|
+
class IdentitySerializer {
|
|
214
|
+
/**
|
|
215
|
+
* Identity serialize.
|
|
216
|
+
*/
|
|
217
|
+
toJSON(value) {
|
|
218
|
+
return value;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Identity deserialize.
|
|
222
|
+
*/
|
|
223
|
+
fromJSON(value) {
|
|
224
|
+
return value;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
ObservableUndoableList.IdentitySerializer = IdentitySerializer;
|
|
228
|
+
})(ObservableUndoableList = exports.ObservableUndoableList || (exports.ObservableUndoableList = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyterlab/observables",
|
|
3
|
-
"version": "2.1.1
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Data structures which may be observed for changes.",
|
|
5
5
|
"homepage": "https://github.com/jupyterlab/jupyterlab",
|
|
6
6
|
"bugs": {
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"url": "https://github.com/jupyterlab/jupyterlab.git"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
|
-
"build": "tsc -b
|
|
25
|
+
"build": "tsc -b",
|
|
26
26
|
"clean": "rimraf lib",
|
|
27
27
|
"docs": "typedoc --options tdoptions.json --theme ../../typedoc-theme src",
|
|
28
28
|
"prepublishOnly": "npm run build",
|
|
29
|
-
"watch": "tsc -b
|
|
29
|
+
"watch": "tsc -b --watch"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@phosphor/algorithm": "^1.1.2",
|
|
@@ -40,5 +40,8 @@
|
|
|
40
40
|
"typedoc": "~0.12.0",
|
|
41
41
|
"typescript": "~3.1.1"
|
|
42
42
|
},
|
|
43
|
-
"
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"gitHead": "7fc900168981e58051253ecc66a18015a052cd2f"
|
|
44
47
|
}
|