1 | import { MainAreaWidget } from '@jupyterlab/apputils';
|
2 | import { CodeEditor } from '@jupyterlab/codeeditor';
|
3 | import { IChangedArgs } from '@jupyterlab/coreutils';
|
4 | import { IModelDB } from '@jupyterlab/observables';
|
5 | import { Contents } from '@jupyterlab/services';
|
6 | import * as models from '@jupyter/ydoc';
|
7 | import { ITranslator } from '@jupyterlab/translation';
|
8 | import { PartialJSONValue } from '@lumino/coreutils';
|
9 | import { ISignal } from '@lumino/signaling';
|
10 | import { Widget } from '@lumino/widgets';
|
11 | import { DocumentRegistry, IDocumentWidget } from './index';
|
12 |
|
13 |
|
14 |
|
15 | export declare class DocumentModel extends CodeEditor.Model implements DocumentRegistry.ICodeModel {
|
16 | |
17 |
|
18 |
|
19 | constructor(languagePreference?: string, modelDB?: IModelDB, collaborationEnabled?: boolean);
|
20 | /**
|
21 | * A signal emitted when the document content changes.
|
22 | */
|
23 | get contentChanged(): ISignal<this, void>;
|
24 | /**
|
25 | * A signal emitted when the document state changes.
|
26 | */
|
27 | get stateChanged(): ISignal<this, IChangedArgs<any>>;
|
28 | /**
|
29 | * The dirty state of the document.
|
30 | */
|
31 | get dirty(): boolean;
|
32 | set dirty(newValue: boolean);
|
33 | /**
|
34 | * The read only state of the document.
|
35 | */
|
36 | get readOnly(): boolean;
|
37 | set readOnly(newValue: boolean);
|
38 | /**
|
39 | * The default kernel name of the document.
|
40 | *
|
41 | * #### Notes
|
42 | * This is a read-only property.
|
43 | */
|
44 | get defaultKernelName(): string;
|
45 | /**
|
46 | * The default kernel language of the document.
|
47 | *
|
48 | * #### Notes
|
49 | * This is a read-only property.
|
50 | */
|
51 | get defaultKernelLanguage(): string;
|
52 | /**
|
53 | * Whether the model is collaborative or not.
|
54 | */
|
55 | get collaborative(): boolean;
|
56 | /**
|
57 | * Serialize the model to a string.
|
58 | */
|
59 | toString(): string;
|
60 | /**
|
61 | * Deserialize the model from a string.
|
62 | *
|
63 | * #### Notes
|
64 | * Should emit a [contentChanged] signal.
|
65 | */
|
66 | fromString(value: string): void;
|
67 | /**
|
68 | * Serialize the model to JSON.
|
69 | */
|
70 | toJSON(): PartialJSONValue;
|
71 | /**
|
72 | * Deserialize the model from JSON.
|
73 | *
|
74 | * #### Notes
|
75 | * Should emit a [contentChanged] signal.
|
76 | */
|
77 | fromJSON(value: PartialJSONValue): void;
|
78 | /**
|
79 | * Initialize the model with its current state.
|
80 | */
|
81 | initialize(): void;
|
82 | /**
|
83 | * Trigger a state change signal.
|
84 | */
|
85 | protected triggerStateChange(args: IChangedArgs<any>): void;
|
86 | /**
|
87 | * Trigger a content changed signal.
|
88 | */
|
89 | protected triggerContentChange(): void;
|
90 | private _onStateChanged;
|
91 | /**
|
92 | * The shared notebook model.
|
93 | */
|
94 | readonly sharedModel: models.ISharedFile;
|
95 | private _defaultLang;
|
96 | private _dirty;
|
97 | private _readOnly;
|
98 | private _contentChanged;
|
99 | private _stateChanged;
|
100 | private _collaborationEnabled;
|
101 | }
|
102 | /**
|
103 | * An implementation of a model factory for text files.
|
104 | */
|
105 | export declare class TextModelFactory implements DocumentRegistry.CodeModelFactory {
|
106 | |
107 |
|
108 |
|
109 | constructor(collaborative?: boolean);
|
110 | /**
|
111 | * The name of the model type.
|
112 | *
|
113 | * #### Notes
|
114 | * This is a read-only property.
|
115 | */
|
116 | get name(): string;
|
117 | /**
|
118 | * The type of the file.
|
119 | *
|
120 | * #### Notes
|
121 | * This is a read-only property.
|
122 | */
|
123 | get contentType(): Contents.ContentType;
|
124 | /**
|
125 | * The format of the file.
|
126 | *
|
127 | * This is a read-only property.
|
128 | */
|
129 | get fileFormat(): Contents.FileFormat;
|
130 | /**
|
131 | * Whether the model is collaborative or not.
|
132 | */
|
133 | get collaborative(): boolean;
|
134 | /**
|
135 | * Get whether the model factory has been disposed.
|
136 | */
|
137 | get isDisposed(): boolean;
|
138 | /**
|
139 | * Dispose of the resources held by the model factory.
|
140 | */
|
141 | dispose(): void;
|
142 | /**
|
143 | * Create a new model.
|
144 | *
|
145 | * @param languagePreference - An optional kernel language preference.
|
146 | * @param modelDB - An optional model storage.
|
147 | * @param isInitialized - Whether the model is initialized or not.
|
148 | * @param collaborationEnabled - Whether collaboration is enabled at the application level or not (default `false`).
|
149 | *
|
150 | * @returns A new document model.
|
151 | */
|
152 | createNew(languagePreference?: string, modelDB?: IModelDB, isInitialized?: boolean, collaborationEnabled?: boolean): DocumentRegistry.ICodeModel;
|
153 | /**
|
154 | * Get the preferred kernel language given a file path.
|
155 | */
|
156 | preferredLanguage(path: string): string;
|
157 | private _isDisposed;
|
158 | private _collaborative;
|
159 | }
|
160 | /**
|
161 | * An implementation of a model factory for base64 files.
|
162 | */
|
163 | export declare class Base64ModelFactory extends TextModelFactory {
|
164 | |
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 | get name(): string;
|
171 | |
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 | get contentType(): Contents.ContentType;
|
178 | |
179 |
|
180 |
|
181 |
|
182 |
|
183 | get fileFormat(): Contents.FileFormat;
|
184 | }
|
185 |
|
186 |
|
187 |
|
188 | export declare abstract class ABCWidgetFactory<T extends IDocumentWidget, U extends DocumentRegistry.IModel = DocumentRegistry.IModel> implements DocumentRegistry.IWidgetFactory<T, U> {
|
189 | |
190 |
|
191 |
|
192 | constructor(options: DocumentRegistry.IWidgetFactoryOptions<T>);
|
193 | /**
|
194 | * A signal emitted when a widget is created.
|
195 | */
|
196 | get widgetCreated(): ISignal<DocumentRegistry.IWidgetFactory<T, U>, T>;
|
197 | /**
|
198 | * Get whether the model factory has been disposed.
|
199 | */
|
200 | get isDisposed(): boolean;
|
201 | /**
|
202 | * Dispose of the resources used by the document manager.
|
203 | */
|
204 | dispose(): void;
|
205 | /**
|
206 | * Whether the widget factory is read only.
|
207 | */
|
208 | get readOnly(): boolean;
|
209 | /**
|
210 | * The name of the widget to display in dialogs.
|
211 | */
|
212 | get name(): string;
|
213 | /**
|
214 | * The file types the widget can view.
|
215 | */
|
216 | get fileTypes(): string[];
|
217 | /**
|
218 | * The registered name of the model type used to create the widgets.
|
219 | */
|
220 | get modelName(): string;
|
221 | /**
|
222 | * The file types for which the factory should be the default.
|
223 | */
|
224 | get defaultFor(): string[];
|
225 | /**
|
226 | * The file types for which the factory should be the default for
|
227 | * rendering a document model, if different from editing.
|
228 | */
|
229 | get defaultRendered(): string[];
|
230 | /**
|
231 | * Whether the widgets prefer having a kernel started.
|
232 | */
|
233 | get preferKernel(): boolean;
|
234 | /**
|
235 | * Whether the widgets can start a kernel when opened.
|
236 | */
|
237 | get canStartKernel(): boolean;
|
238 | /**
|
239 | * The application language translator.
|
240 | */
|
241 | get translator(): ITranslator;
|
242 | /**
|
243 | * Whether the kernel should be shutdown when the widget is closed.
|
244 | */
|
245 | get shutdownOnClose(): boolean;
|
246 | set shutdownOnClose(value: boolean);
|
247 | /**
|
248 | * Create a new widget given a document model and a context.
|
249 | *
|
250 | * #### Notes
|
251 | * It should emit the [widgetCreated] signal with the new widget.
|
252 | */
|
253 | createNew(context: DocumentRegistry.IContext<U>, source?: T): T;
|
254 | /**
|
255 | * Create a widget for a context.
|
256 | */
|
257 | protected abstract createNewWidget(context: DocumentRegistry.IContext<U>, source?: T): T;
|
258 | /**
|
259 | * Default factory for toolbar items to be added after the widget is created.
|
260 | */
|
261 | protected defaultToolbarFactory(widget: T): DocumentRegistry.IToolbarItem[];
|
262 | private _toolbarFactory;
|
263 | private _isDisposed;
|
264 | private _translator;
|
265 | private _name;
|
266 | private _readOnly;
|
267 | private _canStartKernel;
|
268 | private _shutdownOnClose;
|
269 | private _preferKernel;
|
270 | private _modelName;
|
271 | private _fileTypes;
|
272 | private _defaultFor;
|
273 | private _defaultRendered;
|
274 | private _widgetCreated;
|
275 | }
|
276 | /**
|
277 | * A document widget implementation.
|
278 | */
|
279 | export declare class DocumentWidget<T extends Widget = Widget, U extends DocumentRegistry.IModel = DocumentRegistry.IModel> extends MainAreaWidget<T> implements IDocumentWidget<T, U> {
|
280 | constructor(options: DocumentWidget.IOptions<T, U>);
|
281 | /**
|
282 | * Set URI fragment identifier.
|
283 | */
|
284 | setFragment(fragment: string): void;
|
285 | /**
|
286 | * Handle a title change.
|
287 | */
|
288 | private _onTitleChanged;
|
289 | /**
|
290 | * Handle a path change.
|
291 | */
|
292 | private _onPathChanged;
|
293 | /**
|
294 | * Handle a change to the context model state.
|
295 | */
|
296 | private _onModelStateChanged;
|
297 | /**
|
298 | * Handle the dirty state of the context model.
|
299 | */
|
300 | private _handleDirtyState;
|
301 | readonly context: DocumentRegistry.IContext<U>;
|
302 | /**
|
303 | * Whether the document has an auto-generated name or not.
|
304 | *
|
305 | * #### Notes
|
306 | * A document has auto-generated name if its name is untitled and up
|
307 | * to the instant the user saves it manually for the first time.
|
308 | */
|
309 | isUntitled?: boolean;
|
310 | }
|
311 | export declare namespace DocumentWidget {
|
312 | interface IOptions<T extends Widget = Widget, U extends DocumentRegistry.IModel = DocumentRegistry.IModel> extends MainAreaWidget.IOptions<T> {
|
313 | context: DocumentRegistry.IContext<U>;
|
314 | }
|
315 | interface IOptionsOptionalContent<T extends Widget = Widget, U extends DocumentRegistry.IModel = DocumentRegistry.IModel> extends MainAreaWidget.IOptionsOptionalContent<T> {
|
316 | context: DocumentRegistry.IContext<U>;
|
317 | |
318 |
|
319 |
|
320 | translator?: ITranslator;
|
321 | }
|
322 | }
|