Debian Codegraph @

jupyter-widgets-base-manager/lib/manager-base.d.ts

raw
1 import * as services from '@jupyterlab/services';
2 import { JSONObject, PartialJSONObject } from '@lumino/coreutils';
3 import { DOMWidgetView, WidgetModel, WidgetView, DOMWidgetModel, IClassicComm, ICallbacks, IWidgetManager, IModelOptions, IWidgetOptions } from '@jupyter-widgets/base';
4 /**
5 * The control comm target name.
6 */
7 export declare const CONTROL_COMM_TARGET = "jupyter.widget.control";
8 /**
9 * The supported version for the control comm channel.
10 */
11 export declare const CONTROL_COMM_PROTOCOL_VERSION = "1.0.0";
12 /**
13 * Time (in ms) after which we consider the control comm target not responding.
14 */
15 export declare const CONTROL_COMM_TIMEOUT = 4000;
16 export interface IState extends PartialJSONObject {
17 buffers?: IBase64Buffers[];
18 model_name: string;
19 model_module: string;
20 model_module_version: string;
21 state: JSONObject;
22 }
23 export interface IManagerStateMap extends PartialJSONObject {
24 [key: string]: IState;
25 }
26 /**
27 * Widget manager state.
28 *
29 * The JSON schema for this is in @jupyter-widgets/schema/v2/state.schema.json.
30 */
31 export interface IManagerState extends PartialJSONObject {
32 version_major: number;
33 version_minor: number;
34 state: IManagerStateMap;
35 }
36 export interface IBase64Buffers extends PartialJSONObject {
37 data: string;
38 path: (string | number)[];
39 encoding: 'base64';
40 }
41 /**
42 * Make all properties in K (of T) required
43 */
44 export type RequiredSome<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
45 /**
46 * Manager abstract base class
47 */
48 export declare abstract class ManagerBase implements IWidgetManager {
49 /**
50 * Modifies view options. Generally overloaded in custom widget manager
51 * implementations.
52 */
53 setViewOptions(options?: any): any;
54 /**
55 * Creates a promise for a view of a given model
56 *
57 * #### Notes
58 * The implementation must trigger the Lumino 'after-attach' and 'after-show' events when appropriate, which in turn will trigger the view's 'displayed' events.
59 *
60 * Make sure the view creation is not out of order with
61 * any state updates.
62 *
63 */
64 create_view<VT extends DOMWidgetView = DOMWidgetView>(model: DOMWidgetModel, options?: any): Promise<VT>;
65 create_view<VT extends WidgetView = WidgetView>(model: WidgetModel, options?: any): Promise<VT>;
66 /**
67 * callback handlers specific to a view
68 */
69 callbacks(view?: WidgetView): ICallbacks;
70 /**
71 * Get a promise for a model by model id.
72 *
73 * #### Notes
74 * If the model is not found, the returned Promise object is rejected.
75 *
76 * If you would like to synchronously test if a model exists, use .has_model().
77 */
78 get_model(model_id: string): Promise<WidgetModel>;
79 /**
80 * Returns true if the given model is registered, otherwise false.
81 *
82 * #### Notes
83 * This is a synchronous way to check if a model is registered.
84 */
85 has_model(model_id: string): boolean;
86 /**
87 * Handle when a comm is opened.
88 */
89 handle_comm_open(comm: IClassicComm, msg: services.KernelMessage.ICommOpenMsg): Promise<WidgetModel>;
90 /**
91 * Create a comm and new widget model.
92 * @param options - same options as new_model but comm is not
93 * required and additional options are available.
94 * @param serialized_state - serialized model attributes.
95 */
96 new_widget(options: IWidgetOptions, serialized_state?: JSONObject): Promise<WidgetModel>;
97 register_model(model_id: string, modelPromise: Promise<WidgetModel>): void;
98 /**
99 * Create and return a promise for a new widget model
100 *
101 * @param options - the options for creating the model.
102 * @param serialized_state - attribute values for the model.
103 *
104 * @example
105 * widget_manager.new_model({
106 * model_name: 'IntSlider',
107 * model_module: '@jupyter-widgets/controls',
108 * model_module_version: '1.0.0',
109 * model_id: 'u-u-i-d'
110 * }).then((model) => { console.log('Create success!', model); },
111 * (err) => {console.error(err)});
112 *
113 */
114 new_model(options: IModelOptions, serialized_state?: any): Promise<WidgetModel>;
115 /**
116 * Fetch all widgets states from the kernel using the control comm channel
117 * If this fails (control comm handler not implemented kernel side),
118 * it will fall back to `_loadFromKernelModels`.
119 *
120 * This is a utility function that can be used in subclasses.
121 */
122 protected _loadFromKernel(): Promise<void>;
123 /**
124 * Old implementation of fetching widget models one by one using
125 * the request_state message on each comm.
126 *
127 * This is a utility function that can be used in subclasses.
128 */
129 protected _loadFromKernelModels(): Promise<void>;
130 _make_model(options: RequiredSome<IModelOptions, 'model_id'>, serialized_state?: any): Promise<WidgetModel>;
131 /**
132 * Close all widgets and empty the widget state.
133 * @return Promise that resolves when the widget state is cleared.
134 */
135 clear_state(): Promise<void>;
136 /**
137 * Asynchronously get the state of the widget manager.
138 *
139 * This includes all of the widget models, and follows the format given in
140 * the @jupyter-widgets/schema package.
141 *
142 * @param options - The options for what state to return.
143 * @returns Promise for a state dictionary
144 */
145 get_state(options?: IStateOptions): Promise<IManagerState>;
146 /**
147 * Set the widget manager state.
148 *
149 * @param state - a Javascript object conforming to the application/vnd.jupyter.widget-state+json spec.
150 *
151 * Reconstructs all of the widget models in the state, merges that with the
152 * current manager state, and then attempts to redisplay the widgets in the
153 * state.
154 */
155 set_state(state: IManagerState): Promise<WidgetModel[]>;
156 /**
157 * Disconnect the widget manager from the kernel, setting each model's comm
158 * as dead.
159 */
160 disconnect(): void;
161 /**
162 * Resolve a URL relative to the current notebook location.
163 *
164 * The default implementation just returns the original url.
165 */
166 resolveUrl(url: string): Promise<string>;
167 inline_sanitize(source: string): string;
168 /**
169 * The comm target name to register
170 */
171 readonly comm_target_name = "jupyter.widget";
172 /**
173 * Load a class and return a promise to the loaded object.
174 */
175 protected abstract loadClass(className: string, moduleName: string, moduleVersion: string): Promise<typeof WidgetModel | typeof WidgetView>;
176 protected loadModelClass(className: string, moduleName: string, moduleVersion: string): Promise<typeof WidgetModel>;
177 protected loadViewClass(className: string, moduleName: string, moduleVersion: string): Promise<typeof WidgetView>;
178 /**
179 * Create a comm which can be used for communication for a widget.
180 *
181 * If the data/metadata is passed in, open the comm before returning (i.e.,
182 * send the comm_open message). If the data and metadata is undefined, we
183 * want to reconstruct a comm that already exists in the kernel, so do not
184 * open the comm by sending the comm_open message.
185 *
186 * @param comm_target_name Comm target name
187 * @param model_id The comm id
188 * @param data The initial data for the comm
189 * @param metadata The metadata in the open message
190 */
191 protected abstract _create_comm(comm_target_name: string, model_id?: string, data?: JSONObject, metadata?: JSONObject, buffers?: ArrayBuffer[] | ArrayBufferView[]): Promise<IClassicComm>;
192 protected abstract _get_comm_info(): Promise<{}>;
193 /**
194 * Filter serialized widget state to remove any ID's already present in manager.
195 *
196 * @param {*} state Serialized state to filter
197 *
198 * @returns {*} A copy of the state, with its 'state' attribute filtered
199 */
200 protected filterExistingModelState(serialized_state: any): any;
201 /**
202 * Dictionary of model ids and model instance promises
203 */
204 private _models;
205 }
206 export interface IStateOptions {
207 /**
208 * Drop model attributes that are equal to their default value.
209 *
210 * @default false
211 */
212 drop_defaults?: boolean;
213 }
214 /**
215 * Serialize an array of widget models
216 *
217 * #### Notes
218 * The return value follows the format given in the
219 * @jupyter-widgets/schema package.
220 */
221 export declare function serialize_state(models: WidgetModel[], options?: IStateOptions): IManagerState;
222 //# sourceMappingURL=manager-base.d.ts.map