UNPKG

11 kBTypeScriptView Raw
1import * as managerBase from './manager-base';
2import * as utils from './utils';
3import * as Backbone from 'backbone';
4import { NativeView } from './nativeview';
5import { Widget, Panel } from '@lumino/widgets';
6import { Message } from '@lumino/messaging';
7import { IClassicComm, ICallbacks } from './services-shim';
8import { KernelMessage } from '@jupyterlab/services';
9/**
10 * Replace model ids with models recursively.
11 */
12export declare function unpack_models(value: any, manager: managerBase.ManagerBase<any>): Promise<any>;
13/**
14 * Type declaration for general widget serializers.
15 */
16export interface ISerializers {
17 [key: string]: {
18 deserialize?: (value?: any, manager?: managerBase.ManagerBase<any>) => any;
19 serialize?: (value?: any, widget?: WidgetModel) => any;
20 };
21}
22export declare class WidgetModel extends Backbone.Model {
23 /**
24 * The default attributes.
25 */
26 defaults(): {
27 _model_module: string;
28 _model_name: string;
29 _model_module_version: string;
30 _view_module: string;
31 _view_name: string;
32 _view_module_version: string;
33 _view_count: number;
34 };
35 /**
36 * Test to see if the model has been synced with the server.
37 *
38 * #### Notes
39 * As of backbone 1.1, backbone ignores `patch` if it thinks the
40 * model has never been pushed.
41 */
42 isNew(): boolean;
43 /**
44 * Constructor
45 *
46 * Initializes a WidgetModel instance. Called by the Backbone constructor.
47 *
48 * Parameters
49 * ----------
50 * widget_manager : WidgetManager instance
51 * model_id : string
52 * An ID unique to this model.
53 * comm : Comm instance (optional)
54 */
55 initialize(attributes: any, options: {
56 model_id: string;
57 comm?: any;
58 widget_manager: any;
59 }): void;
60 get comm_live(): boolean;
61 set comm_live(x: boolean);
62 /**
63 * Send a custom msg over the comm.
64 */
65 send(content: {}, callbacks: {}, buffers?: ArrayBuffer[] | ArrayBufferView[]): void;
66 /**
67 * Close model
68 *
69 * @param comm_closed - true if the comm is already being closed. If false, the comm will be closed.
70 *
71 * @returns - a promise that is fulfilled when all the associated views have been removed.
72 */
73 close(comm_closed?: boolean): Promise<void>;
74 /**
75 * Handle when a widget comm is closed.
76 */
77 _handle_comm_closed(msg: KernelMessage.ICommCloseMsg): void;
78 /**
79 * Handle incoming comm msg.
80 */
81 _handle_comm_msg(msg: KernelMessage.ICommMsgMsg): Promise<void>;
82 /**
83 * Handle when a widget is updated from the backend.
84 *
85 * This function is meant for internal use only. Values set here will not be propagated on a sync.
86 */
87 set_state(state: any): void;
88 /**
89 * Get the serializable state of the model.
90 *
91 * If drop_default is truthy, attributes that are equal to their default
92 * values are dropped.
93 */
94 get_state(drop_defaults: boolean): any;
95 /**
96 * Handle status msgs.
97 *
98 * execution_state : ('busy', 'idle', 'starting')
99 */
100 _handle_status(msg: KernelMessage.IStatusMsg): void;
101 /**
102 * Create msg callbacks for a comm msg.
103 */
104 callbacks(view?: WidgetView): ICallbacks;
105 /**
106 * Set one or more values.
107 *
108 * We just call the super method, in which val and options are optional.
109 * Handles both "key", value and {key: value} -style arguments.
110 */
111 set(key: any, val?: any, options?: any): any;
112 /**
113 * Handle sync to the back-end. Called when a model.save() is called.
114 *
115 * Make sure a comm exists.
116 *
117 * Parameters
118 * ----------
119 * method : create, update, patch, delete, read
120 * create/update always send the full attribute set
121 * patch - only send attributes listed in options.attrs, and if we
122 * are queuing up messages, combine with previous messages that have
123 * not been sent yet
124 * model : the model we are syncing
125 * will normally be the same as `this`
126 * options : dict
127 * the `attrs` key, if it exists, gives an {attr: value} dict that
128 * should be synced, otherwise, sync all attributes.
129 *
130 */
131 sync(method: string, model: WidgetModel, options?: any): any;
132 rememberLastUpdateFor(msgId: string): void;
133 /**
134 * Serialize widget state.
135 *
136 * A serializer is a function which takes in a state attribute and a widget,
137 * and synchronously returns a JSONable object. The returned object will
138 * have toJSON called if possible, and the final result should be a
139 * primitive object that is a snapshot of the widget state that may have
140 * binary array buffers.
141 */
142 serialize(state: {
143 [key: string]: any;
144 }): {
145 [key: string]: any;
146 };
147 /**
148 * Send a sync message to the kernel.
149 */
150 send_sync_message(state: {}, callbacks?: any): string;
151 /**
152 * Push this model's state to the back-end
153 *
154 * This invokes a Backbone.Sync.
155 */
156 save_changes(callbacks?: {}): void;
157 /**
158 * on_some_change(['key1', 'key2'], foo, context) differs from
159 * on('change:key1 change:key2', foo, context).
160 * If the widget attributes key1 and key2 are both modified,
161 * the second form will result in foo being called twice
162 * while the first will call foo only once.
163 */
164 on_some_change(keys: string[], callback: (...args: any[]) => void, context: any): void;
165 /**
166 * Serialize the model. See the deserialization function at the top of this file
167 * and the kernel-side serializer/deserializer.
168 */
169 toJSON(options: any): string;
170 /**
171 * Returns a promise for the deserialized state. The second argument
172 * is an instance of widget manager, which is required for the
173 * deserialization of widget models.
174 */
175 static _deserialize_state(state: {
176 [key: string]: any;
177 }, manager: managerBase.ManagerBase<any>): Promise<utils.Dict<unknown>>;
178 static serializers: ISerializers;
179 widget_manager: managerBase.ManagerBase<any>;
180 model_id: string;
181 views: {
182 [key: string]: Promise<WidgetView>;
183 };
184 state_change: Promise<any>;
185 comm: IClassicComm;
186 name: string;
187 module: string;
188 private _comm_live;
189 private _closed;
190 private _state_lock;
191 private _buffered_state_diff;
192 private _msg_buffer;
193 private _msg_buffer_callbacks;
194 private _pending_msgs;
195 private _expectedEchoMsgIds;
196 private _attrsToUpdate;
197}
198export declare class DOMWidgetModel extends WidgetModel {
199 static serializers: ISerializers;
200 defaults(): any;
201}
202export declare class WidgetView extends NativeView<WidgetModel> {
203 /**
204 * Public constructor.
205 */
206 constructor(options?: Backbone.ViewOptions<WidgetModel> & {
207 options?: any;
208 });
209 /**
210 * Initializer, called at the end of the constructor.
211 */
212 initialize(parameters: WidgetView.InitializeParameters): void;
213 /**
214 * Triggered on model change.
215 *
216 * Update view to be consistent with this.model
217 */
218 update(options?: any): void;
219 /**
220 * Render a view
221 *
222 * @returns the view or a promise to the view.
223 */
224 render(): any;
225 /**
226 * Create and promise that resolves to a child view of a given model
227 */
228 create_child_view(child_model: WidgetModel, options?: {}): Promise<DOMWidgetView>;
229 /**
230 * Create msg callbacks for a comm msg.
231 */
232 callbacks(): ICallbacks;
233 /**
234 * Send a custom msg associated with this view.
235 */
236 send(content: {}, buffers?: ArrayBuffer[] | ArrayBufferView[]): void;
237 touch(): void;
238 remove(): any;
239 options: any;
240 /**
241 * A promise that resolves to the parent view when a child view is displayed.
242 */
243 displayed: Promise<WidgetView>;
244}
245export declare namespace WidgetView {
246 interface InitializeParameters<T extends WidgetModel = WidgetModel> extends Backbone.ViewOptions<T> {
247 options: any;
248 }
249}
250export declare namespace JupyterPhosphorWidget {
251 interface IOptions {
252 view: DOMWidgetView;
253 }
254}
255export declare class JupyterPhosphorWidget extends Widget {
256 constructor(options: Widget.IOptions & JupyterPhosphorWidget.IOptions);
257 /**
258 * Dispose the widget.
259 *
260 * This causes the view to be destroyed as well with 'remove'
261 */
262 dispose(): void;
263 /**
264 * Process the phosphor message.
265 *
266 * Any custom phosphor widget used inside a Jupyter widget should override
267 * the processMessage function like this.
268 */
269 processMessage(msg: Message): void;
270 private _view;
271}
272export declare class JupyterPhosphorPanelWidget extends Panel {
273 constructor(options: JupyterPhosphorWidget.IOptions & Panel.IOptions);
274 /**
275 * Process the phosphor message.
276 *
277 * Any custom phosphor widget used inside a Jupyter widget should override
278 * the processMessage function like this.
279 */
280 processMessage(msg: Message): void;
281 /**
282 * Dispose the widget.
283 *
284 * This causes the view to be destroyed as well with 'remove'
285 */
286 dispose(): void;
287 private _view;
288}
289export declare class DOMWidgetView extends WidgetView {
290 /**
291 * Public constructor
292 */
293 initialize(parameters: WidgetView.InitializeParameters): void;
294 setLayout(layout: WidgetModel, oldLayout?: WidgetModel): void;
295 setStyle(style: WidgetModel, oldStyle?: WidgetModel): void;
296 /**
297 * Update the DOM classes applied to an element, default to this.el.
298 */
299 update_classes(old_classes: string[], new_classes: string[], el?: HTMLElement): void;
300 /**
301 * Update the DOM classes applied to the widget based on a single
302 * trait's value.
303 *
304 * Given a trait value classes map, this function automatically
305 * handles applying the appropriate classes to the widget element
306 * and removing classes that are no longer valid.
307 *
308 * Parameters
309 * ----------
310 * class_map: dictionary
311 * Dictionary of trait values to class lists.
312 * Example:
313 * {
314 * success: ['alert', 'alert-success'],
315 * info: ['alert', 'alert-info'],
316 * warning: ['alert', 'alert-warning'],
317 * danger: ['alert', 'alert-danger']
318 * };
319 * trait_name: string
320 * Name of the trait to check the value of.
321 * el: optional DOM element handle, defaults to this.el
322 * Element that the classes are applied to.
323 */
324 update_mapped_classes(class_map: {
325 [key: string]: string[];
326 }, trait_name: string, el?: HTMLElement): void;
327 set_mapped_classes(class_map: {
328 [key: string]: string[];
329 }, trait_name: string, el?: HTMLElement): void;
330 _setElement(el: HTMLElement): void;
331 remove(): any;
332 processPhosphorMessage(msg: Message): void;
333 private _comm_live_update;
334 '$el': any;
335 pWidget: Widget;
336 layoutPromise: Promise<any>;
337 stylePromise: Promise<any>;
338}