forked from jupyter-widgets/ipywidgets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanager.ts
195 lines (168 loc) · 4.5 KB
/
manager.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import { JSONObject } from '@lumino/coreutils';
import { IClassicComm, ICallbacks } from './services-shim';
import {
DOMWidgetModel,
DOMWidgetView,
WidgetModel,
WidgetView,
} from './widget';
/**
* The options for a model.
*
* #### Notes
* Either a comm or a model_id must be provided.
*/
export interface IModelOptions {
/**
* Target name of the widget model to create.
*/
model_name: string;
/**
* Module name of the widget model to create.
*/
model_module: string;
/**
* Semver version requirement for the model module.
*/
model_module_version: string;
/**
* Target name of the widget view to create.
*/
view_name?: string | null;
/**
* Module name of the widget view to create.
*/
view_module?: string | null;
/**
* Semver version requirement for the view module.
*/
view_module_version?: string;
/**
* Comm object associated with the widget.
*/
comm?: any;
/**
* The model id to use. If not provided, the comm id of the comm is used.
*/
model_id?: string;
}
/**
* The options for a connected model.
*
* This gives all of the information needed to instantiate a comm to a new
* widget on the kernel side (so view information is mandatory).
*
* #### Notes
* Either a comm or a model_id must be provided.
*/
export interface IWidgetOptions extends IModelOptions {
/**
* Target name of the widget model to create.
*/
model_name: string;
/**
* Module name of the widget model to create.
*/
model_module: string;
/**
* Semver version requirement for the model module.
*/
model_module_version: string;
/**
* Target name of the widget view to create.
*/
view_name: string | null;
/**
* Module name of the widget view to create.
*/
view_module: string | null;
/**
* Semver version requirement for the view module.
*/
view_module_version: string;
/**
* Comm object associated with the widget.
*/
comm?: IClassicComm;
/**
* The model id to use. If not provided, the comm id of the comm is used.
*/
model_id?: string;
}
/**
* The widget manager interface exposed on the Widget instances
*/
export interface IWidgetManager {
/**
* Get a promise for a model by model id.
*
* #### Notes
* If a model is not found, undefined is returned (NOT a promise). However,
* the calling code should also deal with the case where a rejected promise
* is returned, and should treat that also as a model not found.
*/
get_model(model_id: string): Promise<WidgetModel> | undefined;
/**
* Register a model instance promise with the manager.
*
* By registering the model, it can later be retrieved with `get_model`.
*/
register_model(model_id: string, modelPromise: Promise<WidgetModel>): void;
/**
* Create a comm and new widget model.
* @param options - same options as new_model but comm is not
* required and additional options are available.
* @param serialized_state - serialized model attributes.
*/
new_widget(
options: IWidgetOptions,
serialized_state?: JSONObject
): Promise<WidgetModel>;
/**
* Create and return a promise for a new widget model
*
* @param options - the options for creating the model.
* @param serialized_state - attribute values for the model.
*
* @example
* widget_manager.new_model({
* model_name: 'IntSlider',
* model_module: '@jupyter-widgets/controls',
* model_module_version: '1.0.0',
* model_id: 'u-u-i-d'
* }).then((model) => { console.log('Create success!', model); },
* (err) => {console.error(err)});
*
*/
new_model(
options: IModelOptions,
serialized_state?: JSONObject
): Promise<WidgetModel>;
/**
* Creates a promise for a view of a given model
*
* Make sure the view creation is not out of order with
* any state updates.
*/
create_view<VT extends DOMWidgetView = DOMWidgetView>(
model: DOMWidgetModel,
options?: unknown
): Promise<VT>;
create_view<VT extends WidgetView = WidgetView>(
model: WidgetModel,
options?: unknown
): Promise<VT>;
/**
* callback handlers specific to a view
*/
callbacks(view?: WidgetView): ICallbacks;
/**
* Resolve a URL relative to the current notebook location.
*
* The default implementation just returns the original url.
*/
resolveUrl(url: string): Promise<string>;
inline_sanitize(s: string): string;
}