UNPKG

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