UNPKG

9.05 kBTypeScriptView Raw
1import { ICellModel } from '@jupyterlab/cells';
2import { IModelDB, IObservableList, IObservableUndoableList } from '@jupyterlab/observables';
3import * as models from '@jupyterlab/shared-models';
4import { IIterator, IterableOrArrayLike } from '@lumino/algorithm';
5import { ISignal } from '@lumino/signaling';
6import { NotebookModel } from './model';
7/**
8 * A cell list object that supports undo/redo.
9 */
10export declare class CellList implements IObservableUndoableList<ICellModel> {
11 /**
12 * Construct the cell list.
13 */
14 constructor(modelDB: IModelDB, factory: NotebookModel.IContentFactory, model: models.ISharedNotebook);
15 type: 'List';
16 nbmodel: models.ISharedNotebook;
17 /**
18 * Prevents that the modeldb event handler is executed when the shared-model event handler is executed and vice-versa.
19 */
20 private readonly _mutex;
21 private onModelDBChanged;
22 private onSharedModelChanged;
23 /**
24 * A signal emitted when the cell list has changed.
25 */
26 get changed(): ISignal<this, IObservableList.IChangedArgs<ICellModel>>;
27 /**
28 * Test whether the cell list has been disposed.
29 */
30 get isDisposed(): boolean;
31 /**
32 * Test whether the list is empty.
33 *
34 * @returns `true` if the cell list is empty, `false` otherwise.
35 *
36 * #### Notes
37 * This is a read-only property.
38 *
39 * #### Complexity
40 * Constant.
41 *
42 * #### Iterator Validity
43 * No changes.
44 */
45 get isEmpty(): boolean;
46 /**
47 * Get the length of the cell list.
48 *
49 * @return The number of cells in the cell list.
50 *
51 * #### Notes
52 * This is a read-only property.
53 *
54 * #### Complexity
55 * Constant.
56 *
57 * #### Iterator Validity
58 * No changes.
59 */
60 get length(): number;
61 /**
62 * Create an iterator over the cells in the cell list.
63 *
64 * @returns A new iterator starting at the front of the cell list.
65 *
66 * #### Complexity
67 * Constant.
68 *
69 * #### Iterator Validity
70 * No changes.
71 */
72 iter(): IIterator<ICellModel>;
73 /**
74 * Dispose of the resources held by the cell list.
75 */
76 dispose(): void;
77 /**
78 * Get the cell at the specified index.
79 *
80 * @param index - The positive integer index of interest.
81 *
82 * @returns The cell at the specified index.
83 *
84 * #### Complexity
85 * Constant.
86 *
87 * #### Iterator Validity
88 * No changes.
89 *
90 * #### Undefined Behavior
91 * An `index` which is non-integral or out of range.
92 */
93 get(index: number): ICellModel;
94 /**
95 * Set the cell at the specified index.
96 *
97 * @param index - The positive integer index of interest.
98 *
99 * @param cell - The cell to set at the specified index.
100 *
101 * #### Complexity
102 * Constant.
103 *
104 * #### Iterator Validity
105 * No changes.
106 *
107 * #### Undefined Behavior
108 * An `index` which is non-integral or out of range.
109 *
110 * #### Notes
111 * This should be considered to transfer ownership of the
112 * cell to the `CellList`. As such, `cell.dispose()` should
113 * not be called by other actors.
114 */
115 set(index: number, cell: ICellModel): void;
116 /**
117 * Add a cell to the back of the cell list.
118 *
119 * @param cell - The cell to add to the back of the cell list.
120 *
121 * @returns The new length of the cell list.
122 *
123 * #### Complexity
124 * Constant.
125 *
126 * #### Iterator Validity
127 * No changes.
128 *
129 * #### Notes
130 * This should be considered to transfer ownership of the
131 * cell to the `CellList`. As such, `cell.dispose()` should
132 * not be called by other actors.
133 */
134 push(cell: ICellModel): number;
135 /**
136 * Insert a cell into the cell list at a specific index.
137 *
138 * @param index - The index at which to insert the cell.
139 *
140 * @param cell - The cell to set at the specified index.
141 *
142 * @returns The new length of the cell list.
143 *
144 * #### Complexity
145 * Linear.
146 *
147 * #### Iterator Validity
148 * No changes.
149 *
150 * #### Notes
151 * The `index` will be clamped to the bounds of the cell list.
152 *
153 * #### Undefined Behavior
154 * An `index` which is non-integral.
155 *
156 * #### Notes
157 * This should be considered to transfer ownership of the
158 * cell to the `CellList`. As such, `cell.dispose()` should
159 * not be called by other actors.
160 */
161 insert(index: number, cell: ICellModel): void;
162 /**
163 * Remove the first occurrence of a cell from the cell list.
164 *
165 * @param cell - The cell of interest.
166 *
167 * @returns The index of the removed cell, or `-1` if the cell
168 * is not contained in the cell list.
169 *
170 * #### Complexity
171 * Linear.
172 *
173 * #### Iterator Validity
174 * Iterators pointing at the removed cell and beyond are invalidated.
175 */
176 removeValue(cell: ICellModel): number;
177 /**
178 * Remove and return the cell at a specific index.
179 *
180 * @param index - The index of the cell of interest.
181 *
182 * @returns The cell at the specified index, or `undefined` if the
183 * index is out of range.
184 *
185 * #### Complexity
186 * Constant.
187 *
188 * #### Iterator Validity
189 * Iterators pointing at the removed cell and beyond are invalidated.
190 *
191 * #### Undefined Behavior
192 * An `index` which is non-integral.
193 */
194 remove(index: number): ICellModel;
195 /**
196 * Remove all cells from the cell list.
197 *
198 * #### Complexity
199 * Linear.
200 *
201 * #### Iterator Validity
202 * All current iterators are invalidated.
203 */
204 clear(): void;
205 /**
206 * Move a cell from one index to another.
207 *
208 * @parm fromIndex - The index of the element to move.
209 *
210 * @param toIndex - The index to move the element to.
211 *
212 * #### Complexity
213 * Constant.
214 *
215 * #### Iterator Validity
216 * Iterators pointing at the lesser of the `fromIndex` and the `toIndex`
217 * and beyond are invalidated.
218 *
219 * #### Undefined Behavior
220 * A `fromIndex` or a `toIndex` which is non-integral.
221 */
222 move(fromIndex: number, toIndex: number): void;
223 /**
224 * Push a set of cells to the back of the cell list.
225 *
226 * @param cells - An iterable or array-like set of cells to add.
227 *
228 * @returns The new length of the cell list.
229 *
230 * #### Complexity
231 * Linear.
232 *
233 * #### Iterator Validity
234 * No changes.
235 *
236 * #### Notes
237 * This should be considered to transfer ownership of the
238 * cells to the `CellList`. As such, `cell.dispose()` should
239 * not be called by other actors.
240 */
241 pushAll(cells: IterableOrArrayLike<ICellModel>): number;
242 /**
243 * Insert a set of items into the cell list at the specified index.
244 *
245 * @param index - The index at which to insert the cells.
246 *
247 * @param cells - The cells to insert at the specified index.
248 *
249 * @returns The new length of the cell list.
250 *
251 * #### Complexity.
252 * Linear.
253 *
254 * #### Iterator Validity
255 * No changes.
256 *
257 * #### Notes
258 * The `index` will be clamped to the bounds of the cell list.
259 *
260 * #### Undefined Behavior.
261 * An `index` which is non-integral.
262 *
263 * #### Notes
264 * This should be considered to transfer ownership of the
265 * cells to the `CellList`. As such, `cell.dispose()` should
266 * not be called by other actors.
267 */
268 insertAll(index: number, cells: IterableOrArrayLike<ICellModel>): number;
269 /**
270 * Remove a range of items from the cell list.
271 *
272 * @param startIndex - The start index of the range to remove (inclusive).
273 *
274 * @param endIndex - The end index of the range to remove (exclusive).
275 *
276 * @returns The new length of the cell list.
277 *
278 * #### Complexity
279 * Linear.
280 *
281 * #### Iterator Validity
282 * Iterators pointing to the first removed cell and beyond are invalid.
283 *
284 * #### Undefined Behavior
285 * A `startIndex` or `endIndex` which is non-integral.
286 */
287 removeRange(startIndex: number, endIndex: number): number;
288 /**
289 * Whether the object can redo changes.
290 */
291 get canRedo(): boolean;
292 /**
293 * Whether the object can undo changes.
294 */
295 get canUndo(): boolean;
296 /**
297 * Begin a compound operation.
298 *
299 * @param isUndoAble - Whether the operation is undoable.
300 * The default is `true`.
301 */
302 beginCompoundOperation(isUndoAble?: boolean): void;
303 /**
304 * End a compound operation.
305 */
306 endCompoundOperation(): void;
307 /**
308 * Undo an operation.
309 */
310 undo(): void;
311 /**
312 * Redo an operation.
313 */
314 redo(): void;
315 /**
316 * Clear the change stack.
317 */
318 clearUndo(): void;
319 private _onOrderChanged;
320 private _isDisposed;
321 private _cellOrder;
322 private _cellMap;
323 private _changed;
324 private _factory;
325}