@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/observablemap.js
CHANGED
|
@@ -1,180 +1,180 @@
|
|
|
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 signaling_1 = require("@phosphor/signaling");
|
|
6
|
-
/**
|
|
7
|
-
* A concrete implementation of IObservbleMap<T>.
|
|
8
|
-
*/
|
|
9
|
-
class ObservableMap {
|
|
10
|
-
/**
|
|
11
|
-
* Construct a new observable map.
|
|
12
|
-
*/
|
|
13
|
-
constructor(options = {}) {
|
|
14
|
-
this._map = new Map();
|
|
15
|
-
this._changed = new signaling_1.Signal(this);
|
|
16
|
-
this._isDisposed = false;
|
|
17
|
-
this._itemCmp = options.itemCmp || Private.itemCmp;
|
|
18
|
-
if (options.values) {
|
|
19
|
-
for (let key in options.values) {
|
|
20
|
-
this._map.set(key, options.values[key]);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* The type of the Observable.
|
|
26
|
-
*/
|
|
27
|
-
get type() {
|
|
28
|
-
return 'Map';
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* A signal emitted when the map has changed.
|
|
32
|
-
*/
|
|
33
|
-
get changed() {
|
|
34
|
-
return this._changed;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Whether this map has been disposed.
|
|
38
|
-
*/
|
|
39
|
-
get isDisposed() {
|
|
40
|
-
return this._isDisposed;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* The number of key-value pairs in the map.
|
|
44
|
-
*/
|
|
45
|
-
get size() {
|
|
46
|
-
return this._map.size;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Set a key-value pair in the map
|
|
50
|
-
*
|
|
51
|
-
* @param key - The key to set.
|
|
52
|
-
*
|
|
53
|
-
* @param value - The value for the key.
|
|
54
|
-
*
|
|
55
|
-
* @returns the old value for the key, or undefined
|
|
56
|
-
* if that did not exist.
|
|
57
|
-
*
|
|
58
|
-
* @throws if the new value is undefined.
|
|
59
|
-
*
|
|
60
|
-
* #### Notes
|
|
61
|
-
* This is a no-op if the value does not change.
|
|
62
|
-
*/
|
|
63
|
-
set(key, value) {
|
|
64
|
-
let oldVal = this._map.get(key);
|
|
65
|
-
if (value === undefined) {
|
|
66
|
-
throw Error('Cannot set an undefined value, use remove');
|
|
67
|
-
}
|
|
68
|
-
// Bail if the value does not change.
|
|
69
|
-
let itemCmp = this._itemCmp;
|
|
70
|
-
if (oldVal !== undefined && itemCmp(oldVal, value)) {
|
|
71
|
-
return oldVal;
|
|
72
|
-
}
|
|
73
|
-
this._map.set(key, value);
|
|
74
|
-
this._changed.emit({
|
|
75
|
-
type: oldVal ? 'change' : 'add',
|
|
76
|
-
key: key,
|
|
77
|
-
oldValue: oldVal,
|
|
78
|
-
newValue: value
|
|
79
|
-
});
|
|
80
|
-
return oldVal;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Get a value for a given key.
|
|
84
|
-
*
|
|
85
|
-
* @param key - the key.
|
|
86
|
-
*
|
|
87
|
-
* @returns the value for that key.
|
|
88
|
-
*/
|
|
89
|
-
get(key) {
|
|
90
|
-
return this._map.get(key);
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Check whether the map has a key.
|
|
94
|
-
*
|
|
95
|
-
* @param key - the key to check.
|
|
96
|
-
*
|
|
97
|
-
* @returns `true` if the map has the key, `false` otherwise.
|
|
98
|
-
*/
|
|
99
|
-
has(key) {
|
|
100
|
-
return this._map.has(key);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Get a list of the keys in the map.
|
|
104
|
-
*
|
|
105
|
-
* @returns - a list of keys.
|
|
106
|
-
*/
|
|
107
|
-
keys() {
|
|
108
|
-
let keyList = [];
|
|
109
|
-
this._map.forEach((v, k) => {
|
|
110
|
-
keyList.push(k);
|
|
111
|
-
});
|
|
112
|
-
return keyList;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Get a list of the values in the map.
|
|
116
|
-
*
|
|
117
|
-
* @returns - a list of values.
|
|
118
|
-
*/
|
|
119
|
-
values() {
|
|
120
|
-
let valList = [];
|
|
121
|
-
this._map.forEach((v, k) => {
|
|
122
|
-
valList.push(v);
|
|
123
|
-
});
|
|
124
|
-
return valList;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Remove a key from the map
|
|
128
|
-
*
|
|
129
|
-
* @param key - the key to remove.
|
|
130
|
-
*
|
|
131
|
-
* @returns the value of the given key,
|
|
132
|
-
* or undefined if that does not exist.
|
|
133
|
-
*/
|
|
134
|
-
delete(key) {
|
|
135
|
-
let oldVal = this._map.get(key);
|
|
136
|
-
this._map.delete(key);
|
|
137
|
-
this._changed.emit({
|
|
138
|
-
type: 'remove',
|
|
139
|
-
key: key,
|
|
140
|
-
oldValue: oldVal,
|
|
141
|
-
newValue: undefined
|
|
142
|
-
});
|
|
143
|
-
return oldVal;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Set the ObservableMap to an empty map.
|
|
147
|
-
*/
|
|
148
|
-
clear() {
|
|
149
|
-
// Delete one by one to emit the correct signals.
|
|
150
|
-
let keyList = this.keys();
|
|
151
|
-
for (let i = 0; i < keyList.length; i++) {
|
|
152
|
-
this.delete(keyList[i]);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Dispose of the resources held by the map.
|
|
157
|
-
*/
|
|
158
|
-
dispose() {
|
|
159
|
-
if (this.isDisposed) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
this._isDisposed = true;
|
|
163
|
-
signaling_1.Signal.clearData(this);
|
|
164
|
-
this._map.clear();
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
exports.ObservableMap = ObservableMap;
|
|
168
|
-
/**
|
|
169
|
-
* The namespace for module private data.
|
|
170
|
-
*/
|
|
171
|
-
var Private;
|
|
172
|
-
(function (Private) {
|
|
173
|
-
/**
|
|
174
|
-
* The default strict equality item comparator.
|
|
175
|
-
*/
|
|
176
|
-
function itemCmp(first, second) {
|
|
177
|
-
return first === second;
|
|
178
|
-
}
|
|
179
|
-
Private.itemCmp = itemCmp;
|
|
180
|
-
})(Private || (Private = {}));
|
|
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 signaling_1 = require("@phosphor/signaling");
|
|
6
|
+
/**
|
|
7
|
+
* A concrete implementation of IObservbleMap<T>.
|
|
8
|
+
*/
|
|
9
|
+
class ObservableMap {
|
|
10
|
+
/**
|
|
11
|
+
* Construct a new observable map.
|
|
12
|
+
*/
|
|
13
|
+
constructor(options = {}) {
|
|
14
|
+
this._map = new Map();
|
|
15
|
+
this._changed = new signaling_1.Signal(this);
|
|
16
|
+
this._isDisposed = false;
|
|
17
|
+
this._itemCmp = options.itemCmp || Private.itemCmp;
|
|
18
|
+
if (options.values) {
|
|
19
|
+
for (let key in options.values) {
|
|
20
|
+
this._map.set(key, options.values[key]);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The type of the Observable.
|
|
26
|
+
*/
|
|
27
|
+
get type() {
|
|
28
|
+
return 'Map';
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A signal emitted when the map has changed.
|
|
32
|
+
*/
|
|
33
|
+
get changed() {
|
|
34
|
+
return this._changed;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Whether this map has been disposed.
|
|
38
|
+
*/
|
|
39
|
+
get isDisposed() {
|
|
40
|
+
return this._isDisposed;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The number of key-value pairs in the map.
|
|
44
|
+
*/
|
|
45
|
+
get size() {
|
|
46
|
+
return this._map.size;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Set a key-value pair in the map
|
|
50
|
+
*
|
|
51
|
+
* @param key - The key to set.
|
|
52
|
+
*
|
|
53
|
+
* @param value - The value for the key.
|
|
54
|
+
*
|
|
55
|
+
* @returns the old value for the key, or undefined
|
|
56
|
+
* if that did not exist.
|
|
57
|
+
*
|
|
58
|
+
* @throws if the new value is undefined.
|
|
59
|
+
*
|
|
60
|
+
* #### Notes
|
|
61
|
+
* This is a no-op if the value does not change.
|
|
62
|
+
*/
|
|
63
|
+
set(key, value) {
|
|
64
|
+
let oldVal = this._map.get(key);
|
|
65
|
+
if (value === undefined) {
|
|
66
|
+
throw Error('Cannot set an undefined value, use remove');
|
|
67
|
+
}
|
|
68
|
+
// Bail if the value does not change.
|
|
69
|
+
let itemCmp = this._itemCmp;
|
|
70
|
+
if (oldVal !== undefined && itemCmp(oldVal, value)) {
|
|
71
|
+
return oldVal;
|
|
72
|
+
}
|
|
73
|
+
this._map.set(key, value);
|
|
74
|
+
this._changed.emit({
|
|
75
|
+
type: oldVal ? 'change' : 'add',
|
|
76
|
+
key: key,
|
|
77
|
+
oldValue: oldVal,
|
|
78
|
+
newValue: value
|
|
79
|
+
});
|
|
80
|
+
return oldVal;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get a value for a given key.
|
|
84
|
+
*
|
|
85
|
+
* @param key - the key.
|
|
86
|
+
*
|
|
87
|
+
* @returns the value for that key.
|
|
88
|
+
*/
|
|
89
|
+
get(key) {
|
|
90
|
+
return this._map.get(key);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Check whether the map has a key.
|
|
94
|
+
*
|
|
95
|
+
* @param key - the key to check.
|
|
96
|
+
*
|
|
97
|
+
* @returns `true` if the map has the key, `false` otherwise.
|
|
98
|
+
*/
|
|
99
|
+
has(key) {
|
|
100
|
+
return this._map.has(key);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get a list of the keys in the map.
|
|
104
|
+
*
|
|
105
|
+
* @returns - a list of keys.
|
|
106
|
+
*/
|
|
107
|
+
keys() {
|
|
108
|
+
let keyList = [];
|
|
109
|
+
this._map.forEach((v, k) => {
|
|
110
|
+
keyList.push(k);
|
|
111
|
+
});
|
|
112
|
+
return keyList;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get a list of the values in the map.
|
|
116
|
+
*
|
|
117
|
+
* @returns - a list of values.
|
|
118
|
+
*/
|
|
119
|
+
values() {
|
|
120
|
+
let valList = [];
|
|
121
|
+
this._map.forEach((v, k) => {
|
|
122
|
+
valList.push(v);
|
|
123
|
+
});
|
|
124
|
+
return valList;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Remove a key from the map
|
|
128
|
+
*
|
|
129
|
+
* @param key - the key to remove.
|
|
130
|
+
*
|
|
131
|
+
* @returns the value of the given key,
|
|
132
|
+
* or undefined if that does not exist.
|
|
133
|
+
*/
|
|
134
|
+
delete(key) {
|
|
135
|
+
let oldVal = this._map.get(key);
|
|
136
|
+
this._map.delete(key);
|
|
137
|
+
this._changed.emit({
|
|
138
|
+
type: 'remove',
|
|
139
|
+
key: key,
|
|
140
|
+
oldValue: oldVal,
|
|
141
|
+
newValue: undefined
|
|
142
|
+
});
|
|
143
|
+
return oldVal;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Set the ObservableMap to an empty map.
|
|
147
|
+
*/
|
|
148
|
+
clear() {
|
|
149
|
+
// Delete one by one to emit the correct signals.
|
|
150
|
+
let keyList = this.keys();
|
|
151
|
+
for (let i = 0; i < keyList.length; i++) {
|
|
152
|
+
this.delete(keyList[i]);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Dispose of the resources held by the map.
|
|
157
|
+
*/
|
|
158
|
+
dispose() {
|
|
159
|
+
if (this.isDisposed) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
this._isDisposed = true;
|
|
163
|
+
signaling_1.Signal.clearData(this);
|
|
164
|
+
this._map.clear();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
exports.ObservableMap = ObservableMap;
|
|
168
|
+
/**
|
|
169
|
+
* The namespace for module private data.
|
|
170
|
+
*/
|
|
171
|
+
var Private;
|
|
172
|
+
(function (Private) {
|
|
173
|
+
/**
|
|
174
|
+
* The default strict equality item comparator.
|
|
175
|
+
*/
|
|
176
|
+
function itemCmp(first, second) {
|
|
177
|
+
return first === second;
|
|
178
|
+
}
|
|
179
|
+
Private.itemCmp = itemCmp;
|
|
180
|
+
})(Private || (Private = {}));
|
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
import { IDisposable } from '@phosphor/disposable';
|
|
2
|
-
import { ISignal } from '@phosphor/signaling';
|
|
3
|
-
import { IObservable } from './modeldb';
|
|
4
|
-
/**
|
|
5
|
-
* A string which can be observed for changes.
|
|
6
|
-
*/
|
|
7
|
-
export interface IObservableString extends IDisposable, IObservable {
|
|
8
|
-
/**
|
|
9
|
-
* The type of the Observable.
|
|
10
|
-
*/
|
|
11
|
-
type: 'String';
|
|
12
|
-
/**
|
|
13
|
-
* A signal emitted when the string has changed.
|
|
14
|
-
*/
|
|
15
|
-
readonly changed: ISignal<this, IObservableString.IChangedArgs>;
|
|
16
|
-
/**
|
|
17
|
-
* The value of the string.
|
|
18
|
-
*/
|
|
19
|
-
text: string;
|
|
20
|
-
/**
|
|
21
|
-
* Insert a substring.
|
|
22
|
-
*
|
|
23
|
-
* @param index - The starting index.
|
|
24
|
-
*
|
|
25
|
-
* @param text - The substring to insert.
|
|
26
|
-
*/
|
|
27
|
-
insert(index: number, text: string): void;
|
|
28
|
-
/**
|
|
29
|
-
* Remove a substring.
|
|
30
|
-
*
|
|
31
|
-
* @param start - The starting index.
|
|
32
|
-
*
|
|
33
|
-
* @param end - The ending index.
|
|
34
|
-
*/
|
|
35
|
-
remove(start: number, end: number): void;
|
|
36
|
-
/**
|
|
37
|
-
* Set the ObservableString to an empty string.
|
|
38
|
-
*/
|
|
39
|
-
clear(): void;
|
|
40
|
-
/**
|
|
41
|
-
* Dispose of the resources held by the string.
|
|
42
|
-
*/
|
|
43
|
-
dispose(): void;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* The namespace for `IObservableString` associate interfaces.
|
|
47
|
-
*/
|
|
48
|
-
export declare namespace IObservableString {
|
|
49
|
-
/**
|
|
50
|
-
* The change types which occur on an observable string.
|
|
51
|
-
*/
|
|
52
|
-
type ChangeType = 'insert'
|
|
53
|
-
/**
|
|
54
|
-
* Text was removed.
|
|
55
|
-
*/
|
|
56
|
-
| 'remove'
|
|
57
|
-
/**
|
|
58
|
-
* Text was set.
|
|
59
|
-
*/
|
|
60
|
-
| 'set';
|
|
61
|
-
/**
|
|
62
|
-
* The changed args object which is emitted by an observable string.
|
|
63
|
-
*/
|
|
64
|
-
interface IChangedArgs {
|
|
65
|
-
/**
|
|
66
|
-
* The type of change undergone by the list.
|
|
67
|
-
*/
|
|
68
|
-
type: ChangeType;
|
|
69
|
-
/**
|
|
70
|
-
* The starting index of the change.
|
|
71
|
-
*/
|
|
72
|
-
start: number;
|
|
73
|
-
/**
|
|
74
|
-
* The end index of the change.
|
|
75
|
-
*/
|
|
76
|
-
end: number;
|
|
77
|
-
/**
|
|
78
|
-
* The value of the change.
|
|
79
|
-
*
|
|
80
|
-
* ### Notes
|
|
81
|
-
* If `ChangeType` is `set`, then
|
|
82
|
-
* this is the new value of the string.
|
|
83
|
-
*
|
|
84
|
-
* If `ChangeType` is `insert` this is
|
|
85
|
-
* the value of the inserted string.
|
|
86
|
-
*
|
|
87
|
-
* If `ChangeType` is remove this is the
|
|
88
|
-
* value of the removed substring.
|
|
89
|
-
*/
|
|
90
|
-
value: string;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* A concrete implementation of [[IObservableString]]
|
|
95
|
-
*/
|
|
96
|
-
export declare class ObservableString implements IObservableString {
|
|
97
|
-
/**
|
|
98
|
-
* Construct a new observable string.
|
|
99
|
-
*/
|
|
100
|
-
constructor(initialText?: string);
|
|
101
|
-
/**
|
|
102
|
-
* The type of the Observable.
|
|
103
|
-
*/
|
|
104
|
-
readonly type: 'String';
|
|
105
|
-
/**
|
|
106
|
-
* A signal emitted when the string has changed.
|
|
107
|
-
*/
|
|
108
|
-
readonly changed: ISignal<this, IObservableString.IChangedArgs>;
|
|
109
|
-
/**
|
|
110
|
-
* Set the value of the string.
|
|
111
|
-
*/
|
|
112
|
-
/**
|
|
113
|
-
* Get the value of the string.
|
|
114
|
-
*/
|
|
115
|
-
text: string;
|
|
116
|
-
/**
|
|
117
|
-
* Insert a substring.
|
|
118
|
-
*
|
|
119
|
-
* @param index - The starting index.
|
|
120
|
-
*
|
|
121
|
-
* @param text - The substring to insert.
|
|
122
|
-
*/
|
|
123
|
-
insert(index: number, text: string): void;
|
|
124
|
-
/**
|
|
125
|
-
* Remove a substring.
|
|
126
|
-
*
|
|
127
|
-
* @param start - The starting index.
|
|
128
|
-
*
|
|
129
|
-
* @param end - The ending index.
|
|
130
|
-
*/
|
|
131
|
-
remove(start: number, end: number): void;
|
|
132
|
-
/**
|
|
133
|
-
* Set the ObservableString to an empty string.
|
|
134
|
-
*/
|
|
135
|
-
clear(): void;
|
|
136
|
-
/**
|
|
137
|
-
* Test whether the string has been disposed.
|
|
138
|
-
*/
|
|
139
|
-
readonly isDisposed: boolean;
|
|
140
|
-
/**
|
|
141
|
-
* Dispose of the resources held by the string.
|
|
142
|
-
*/
|
|
143
|
-
dispose(): void;
|
|
144
|
-
private _text;
|
|
145
|
-
private _isDisposed;
|
|
146
|
-
private _changed;
|
|
147
|
-
}
|
|
1
|
+
import { IDisposable } from '@phosphor/disposable';
|
|
2
|
+
import { ISignal } from '@phosphor/signaling';
|
|
3
|
+
import { IObservable } from './modeldb';
|
|
4
|
+
/**
|
|
5
|
+
* A string which can be observed for changes.
|
|
6
|
+
*/
|
|
7
|
+
export interface IObservableString extends IDisposable, IObservable {
|
|
8
|
+
/**
|
|
9
|
+
* The type of the Observable.
|
|
10
|
+
*/
|
|
11
|
+
type: 'String';
|
|
12
|
+
/**
|
|
13
|
+
* A signal emitted when the string has changed.
|
|
14
|
+
*/
|
|
15
|
+
readonly changed: ISignal<this, IObservableString.IChangedArgs>;
|
|
16
|
+
/**
|
|
17
|
+
* The value of the string.
|
|
18
|
+
*/
|
|
19
|
+
text: string;
|
|
20
|
+
/**
|
|
21
|
+
* Insert a substring.
|
|
22
|
+
*
|
|
23
|
+
* @param index - The starting index.
|
|
24
|
+
*
|
|
25
|
+
* @param text - The substring to insert.
|
|
26
|
+
*/
|
|
27
|
+
insert(index: number, text: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Remove a substring.
|
|
30
|
+
*
|
|
31
|
+
* @param start - The starting index.
|
|
32
|
+
*
|
|
33
|
+
* @param end - The ending index.
|
|
34
|
+
*/
|
|
35
|
+
remove(start: number, end: number): void;
|
|
36
|
+
/**
|
|
37
|
+
* Set the ObservableString to an empty string.
|
|
38
|
+
*/
|
|
39
|
+
clear(): void;
|
|
40
|
+
/**
|
|
41
|
+
* Dispose of the resources held by the string.
|
|
42
|
+
*/
|
|
43
|
+
dispose(): void;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The namespace for `IObservableString` associate interfaces.
|
|
47
|
+
*/
|
|
48
|
+
export declare namespace IObservableString {
|
|
49
|
+
/**
|
|
50
|
+
* The change types which occur on an observable string.
|
|
51
|
+
*/
|
|
52
|
+
type ChangeType = 'insert'
|
|
53
|
+
/**
|
|
54
|
+
* Text was removed.
|
|
55
|
+
*/
|
|
56
|
+
| 'remove'
|
|
57
|
+
/**
|
|
58
|
+
* Text was set.
|
|
59
|
+
*/
|
|
60
|
+
| 'set';
|
|
61
|
+
/**
|
|
62
|
+
* The changed args object which is emitted by an observable string.
|
|
63
|
+
*/
|
|
64
|
+
interface IChangedArgs {
|
|
65
|
+
/**
|
|
66
|
+
* The type of change undergone by the list.
|
|
67
|
+
*/
|
|
68
|
+
type: ChangeType;
|
|
69
|
+
/**
|
|
70
|
+
* The starting index of the change.
|
|
71
|
+
*/
|
|
72
|
+
start: number;
|
|
73
|
+
/**
|
|
74
|
+
* The end index of the change.
|
|
75
|
+
*/
|
|
76
|
+
end: number;
|
|
77
|
+
/**
|
|
78
|
+
* The value of the change.
|
|
79
|
+
*
|
|
80
|
+
* ### Notes
|
|
81
|
+
* If `ChangeType` is `set`, then
|
|
82
|
+
* this is the new value of the string.
|
|
83
|
+
*
|
|
84
|
+
* If `ChangeType` is `insert` this is
|
|
85
|
+
* the value of the inserted string.
|
|
86
|
+
*
|
|
87
|
+
* If `ChangeType` is remove this is the
|
|
88
|
+
* value of the removed substring.
|
|
89
|
+
*/
|
|
90
|
+
value: string;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* A concrete implementation of [[IObservableString]]
|
|
95
|
+
*/
|
|
96
|
+
export declare class ObservableString implements IObservableString {
|
|
97
|
+
/**
|
|
98
|
+
* Construct a new observable string.
|
|
99
|
+
*/
|
|
100
|
+
constructor(initialText?: string);
|
|
101
|
+
/**
|
|
102
|
+
* The type of the Observable.
|
|
103
|
+
*/
|
|
104
|
+
readonly type: 'String';
|
|
105
|
+
/**
|
|
106
|
+
* A signal emitted when the string has changed.
|
|
107
|
+
*/
|
|
108
|
+
readonly changed: ISignal<this, IObservableString.IChangedArgs>;
|
|
109
|
+
/**
|
|
110
|
+
* Set the value of the string.
|
|
111
|
+
*/
|
|
112
|
+
/**
|
|
113
|
+
* Get the value of the string.
|
|
114
|
+
*/
|
|
115
|
+
text: string;
|
|
116
|
+
/**
|
|
117
|
+
* Insert a substring.
|
|
118
|
+
*
|
|
119
|
+
* @param index - The starting index.
|
|
120
|
+
*
|
|
121
|
+
* @param text - The substring to insert.
|
|
122
|
+
*/
|
|
123
|
+
insert(index: number, text: string): void;
|
|
124
|
+
/**
|
|
125
|
+
* Remove a substring.
|
|
126
|
+
*
|
|
127
|
+
* @param start - The starting index.
|
|
128
|
+
*
|
|
129
|
+
* @param end - The ending index.
|
|
130
|
+
*/
|
|
131
|
+
remove(start: number, end: number): void;
|
|
132
|
+
/**
|
|
133
|
+
* Set the ObservableString to an empty string.
|
|
134
|
+
*/
|
|
135
|
+
clear(): void;
|
|
136
|
+
/**
|
|
137
|
+
* Test whether the string has been disposed.
|
|
138
|
+
*/
|
|
139
|
+
readonly isDisposed: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Dispose of the resources held by the string.
|
|
142
|
+
*/
|
|
143
|
+
dispose(): void;
|
|
144
|
+
private _text;
|
|
145
|
+
private _isDisposed;
|
|
146
|
+
private _changed;
|
|
147
|
+
}
|