@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.
@@ -1,109 +1,109 @@
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 [[IObservableString]]
8
- */
9
- class ObservableString {
10
- /**
11
- * Construct a new observable string.
12
- */
13
- constructor(initialText = '') {
14
- this._text = '';
15
- this._isDisposed = false;
16
- this._changed = new signaling_1.Signal(this);
17
- this._text = initialText;
18
- }
19
- /**
20
- * The type of the Observable.
21
- */
22
- get type() {
23
- return 'String';
24
- }
25
- /**
26
- * A signal emitted when the string has changed.
27
- */
28
- get changed() {
29
- return this._changed;
30
- }
31
- /**
32
- * Set the value of the string.
33
- */
34
- set text(value) {
35
- if (value.length === this._text.length && value === this._text) {
36
- return;
37
- }
38
- this._text = value;
39
- this._changed.emit({
40
- type: 'set',
41
- start: 0,
42
- end: value.length,
43
- value: value
44
- });
45
- }
46
- /**
47
- * Get the value of the string.
48
- */
49
- get text() {
50
- return this._text;
51
- }
52
- /**
53
- * Insert a substring.
54
- *
55
- * @param index - The starting index.
56
- *
57
- * @param text - The substring to insert.
58
- */
59
- insert(index, text) {
60
- this._text = this._text.slice(0, index) + text + this._text.slice(index);
61
- this._changed.emit({
62
- type: 'insert',
63
- start: index,
64
- end: index + text.length,
65
- value: text
66
- });
67
- }
68
- /**
69
- * Remove a substring.
70
- *
71
- * @param start - The starting index.
72
- *
73
- * @param end - The ending index.
74
- */
75
- remove(start, end) {
76
- let oldValue = this._text.slice(start, end);
77
- this._text = this._text.slice(0, start) + this._text.slice(end);
78
- this._changed.emit({
79
- type: 'remove',
80
- start: start,
81
- end: end,
82
- value: oldValue
83
- });
84
- }
85
- /**
86
- * Set the ObservableString to an empty string.
87
- */
88
- clear() {
89
- this.text = '';
90
- }
91
- /**
92
- * Test whether the string has been disposed.
93
- */
94
- get isDisposed() {
95
- return this._isDisposed;
96
- }
97
- /**
98
- * Dispose of the resources held by the string.
99
- */
100
- dispose() {
101
- if (this._isDisposed) {
102
- return;
103
- }
104
- this._isDisposed = true;
105
- signaling_1.Signal.clearData(this);
106
- this.clear();
107
- }
108
- }
109
- exports.ObservableString = ObservableString;
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 [[IObservableString]]
8
+ */
9
+ class ObservableString {
10
+ /**
11
+ * Construct a new observable string.
12
+ */
13
+ constructor(initialText = '') {
14
+ this._text = '';
15
+ this._isDisposed = false;
16
+ this._changed = new signaling_1.Signal(this);
17
+ this._text = initialText;
18
+ }
19
+ /**
20
+ * The type of the Observable.
21
+ */
22
+ get type() {
23
+ return 'String';
24
+ }
25
+ /**
26
+ * A signal emitted when the string has changed.
27
+ */
28
+ get changed() {
29
+ return this._changed;
30
+ }
31
+ /**
32
+ * Set the value of the string.
33
+ */
34
+ set text(value) {
35
+ if (value.length === this._text.length && value === this._text) {
36
+ return;
37
+ }
38
+ this._text = value;
39
+ this._changed.emit({
40
+ type: 'set',
41
+ start: 0,
42
+ end: value.length,
43
+ value: value
44
+ });
45
+ }
46
+ /**
47
+ * Get the value of the string.
48
+ */
49
+ get text() {
50
+ return this._text;
51
+ }
52
+ /**
53
+ * Insert a substring.
54
+ *
55
+ * @param index - The starting index.
56
+ *
57
+ * @param text - The substring to insert.
58
+ */
59
+ insert(index, text) {
60
+ this._text = this._text.slice(0, index) + text + this._text.slice(index);
61
+ this._changed.emit({
62
+ type: 'insert',
63
+ start: index,
64
+ end: index + text.length,
65
+ value: text
66
+ });
67
+ }
68
+ /**
69
+ * Remove a substring.
70
+ *
71
+ * @param start - The starting index.
72
+ *
73
+ * @param end - The ending index.
74
+ */
75
+ remove(start, end) {
76
+ let oldValue = this._text.slice(start, end);
77
+ this._text = this._text.slice(0, start) + this._text.slice(end);
78
+ this._changed.emit({
79
+ type: 'remove',
80
+ start: start,
81
+ end: end,
82
+ value: oldValue
83
+ });
84
+ }
85
+ /**
86
+ * Set the ObservableString to an empty string.
87
+ */
88
+ clear() {
89
+ this.text = '';
90
+ }
91
+ /**
92
+ * Test whether the string has been disposed.
93
+ */
94
+ get isDisposed() {
95
+ return this._isDisposed;
96
+ }
97
+ /**
98
+ * Dispose of the resources held by the string.
99
+ */
100
+ dispose() {
101
+ if (this._isDisposed) {
102
+ return;
103
+ }
104
+ this._isDisposed = true;
105
+ signaling_1.Signal.clearData(this);
106
+ this.clear();
107
+ }
108
+ }
109
+ exports.ObservableString = ObservableString;
@@ -1,132 +1,132 @@
1
- import { JSONValue } from '@phosphor/coreutils';
2
- import { IObservableList, ObservableList } from './observablelist';
3
- /**
4
- * An object which knows how to serialize and
5
- * deserialize the type T.
6
- */
7
- export interface ISerializer<T> {
8
- /**
9
- * Convert the object to JSON.
10
- */
11
- toJSON(value: T): JSONValue;
12
- /**
13
- * Deserialize the object from JSON.
14
- */
15
- fromJSON(value: JSONValue): T;
16
- }
17
- /**
18
- * An observable list that supports undo/redo.
19
- */
20
- export interface IObservableUndoableList<T> extends IObservableList<T> {
21
- /**
22
- * Whether the object can redo changes.
23
- */
24
- readonly canRedo: boolean;
25
- /**
26
- * Whether the object can undo changes.
27
- */
28
- readonly canUndo: boolean;
29
- /**
30
- * Begin a compound operation.
31
- *
32
- * @param isUndoAble - Whether the operation is undoable.
33
- * The default is `false`.
34
- */
35
- beginCompoundOperation(isUndoAble?: boolean): void;
36
- /**
37
- * End a compound operation.
38
- */
39
- endCompoundOperation(): void;
40
- /**
41
- * Undo an operation.
42
- */
43
- undo(): void;
44
- /**
45
- * Redo an operation.
46
- */
47
- redo(): void;
48
- /**
49
- * Clear the change stack.
50
- */
51
- clearUndo(): void;
52
- }
53
- /**
54
- * A concrete implementation of an observable undoable list.
55
- */
56
- export declare class ObservableUndoableList<T> extends ObservableList<T> implements IObservableUndoableList<T> {
57
- /**
58
- * Construct a new undoable observable list.
59
- */
60
- constructor(serializer: ISerializer<T>);
61
- /**
62
- * Whether the object can redo changes.
63
- */
64
- readonly canRedo: boolean;
65
- /**
66
- * Whether the object can undo changes.
67
- */
68
- readonly canUndo: boolean;
69
- /**
70
- * Begin a compound operation.
71
- *
72
- * @param isUndoAble - Whether the operation is undoable.
73
- * The default is `true`.
74
- */
75
- beginCompoundOperation(isUndoAble?: boolean): void;
76
- /**
77
- * End a compound operation.
78
- */
79
- endCompoundOperation(): void;
80
- /**
81
- * Undo an operation.
82
- */
83
- undo(): void;
84
- /**
85
- * Redo an operation.
86
- */
87
- redo(): void;
88
- /**
89
- * Clear the change stack.
90
- */
91
- clearUndo(): void;
92
- /**
93
- * Handle a change in the list.
94
- */
95
- private _onListChanged;
96
- /**
97
- * Undo a change event.
98
- */
99
- private _undoChange;
100
- /**
101
- * Redo a change event.
102
- */
103
- private _redoChange;
104
- /**
105
- * Copy a change as JSON.
106
- */
107
- private _copyChange;
108
- private _inCompound;
109
- private _isUndoable;
110
- private _madeCompoundChange;
111
- private _index;
112
- private _stack;
113
- private _serializer;
114
- }
115
- /**
116
- * Namespace for ObservableUndoableList utilities.
117
- */
118
- export declare namespace ObservableUndoableList {
119
- /**
120
- * A default, identity serializer.
121
- */
122
- class IdentitySerializer<T extends JSONValue> implements ISerializer<T> {
123
- /**
124
- * Identity serialize.
125
- */
126
- toJSON(value: T): JSONValue;
127
- /**
128
- * Identity deserialize.
129
- */
130
- fromJSON(value: JSONValue): T;
131
- }
132
- }
1
+ import { JSONValue } from '@phosphor/coreutils';
2
+ import { IObservableList, ObservableList } from './observablelist';
3
+ /**
4
+ * An object which knows how to serialize and
5
+ * deserialize the type T.
6
+ */
7
+ export interface ISerializer<T> {
8
+ /**
9
+ * Convert the object to JSON.
10
+ */
11
+ toJSON(value: T): JSONValue;
12
+ /**
13
+ * Deserialize the object from JSON.
14
+ */
15
+ fromJSON(value: JSONValue): T;
16
+ }
17
+ /**
18
+ * An observable list that supports undo/redo.
19
+ */
20
+ export interface IObservableUndoableList<T> extends IObservableList<T> {
21
+ /**
22
+ * Whether the object can redo changes.
23
+ */
24
+ readonly canRedo: boolean;
25
+ /**
26
+ * Whether the object can undo changes.
27
+ */
28
+ readonly canUndo: boolean;
29
+ /**
30
+ * Begin a compound operation.
31
+ *
32
+ * @param isUndoAble - Whether the operation is undoable.
33
+ * The default is `false`.
34
+ */
35
+ beginCompoundOperation(isUndoAble?: boolean): void;
36
+ /**
37
+ * End a compound operation.
38
+ */
39
+ endCompoundOperation(): void;
40
+ /**
41
+ * Undo an operation.
42
+ */
43
+ undo(): void;
44
+ /**
45
+ * Redo an operation.
46
+ */
47
+ redo(): void;
48
+ /**
49
+ * Clear the change stack.
50
+ */
51
+ clearUndo(): void;
52
+ }
53
+ /**
54
+ * A concrete implementation of an observable undoable list.
55
+ */
56
+ export declare class ObservableUndoableList<T> extends ObservableList<T> implements IObservableUndoableList<T> {
57
+ /**
58
+ * Construct a new undoable observable list.
59
+ */
60
+ constructor(serializer: ISerializer<T>);
61
+ /**
62
+ * Whether the object can redo changes.
63
+ */
64
+ readonly canRedo: boolean;
65
+ /**
66
+ * Whether the object can undo changes.
67
+ */
68
+ readonly canUndo: boolean;
69
+ /**
70
+ * Begin a compound operation.
71
+ *
72
+ * @param isUndoAble - Whether the operation is undoable.
73
+ * The default is `true`.
74
+ */
75
+ beginCompoundOperation(isUndoAble?: boolean): void;
76
+ /**
77
+ * End a compound operation.
78
+ */
79
+ endCompoundOperation(): void;
80
+ /**
81
+ * Undo an operation.
82
+ */
83
+ undo(): void;
84
+ /**
85
+ * Redo an operation.
86
+ */
87
+ redo(): void;
88
+ /**
89
+ * Clear the change stack.
90
+ */
91
+ clearUndo(): void;
92
+ /**
93
+ * Handle a change in the list.
94
+ */
95
+ private _onListChanged;
96
+ /**
97
+ * Undo a change event.
98
+ */
99
+ private _undoChange;
100
+ /**
101
+ * Redo a change event.
102
+ */
103
+ private _redoChange;
104
+ /**
105
+ * Copy a change as JSON.
106
+ */
107
+ private _copyChange;
108
+ private _inCompound;
109
+ private _isUndoable;
110
+ private _madeCompoundChange;
111
+ private _index;
112
+ private _stack;
113
+ private _serializer;
114
+ }
115
+ /**
116
+ * Namespace for ObservableUndoableList utilities.
117
+ */
118
+ export declare namespace ObservableUndoableList {
119
+ /**
120
+ * A default, identity serializer.
121
+ */
122
+ class IdentitySerializer<T extends JSONValue> implements ISerializer<T> {
123
+ /**
124
+ * Identity serialize.
125
+ */
126
+ toJSON(value: T): JSONValue;
127
+ /**
128
+ * Identity deserialize.
129
+ */
130
+ fromJSON(value: JSONValue): T;
131
+ }
132
+ }