manager.d.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. import * as Backbone from 'backbone';
  2. import { ManagerBase, IClassicComm, IWidgetRegistryData, WidgetModel, WidgetView, IStateOptions } from '@jupyter-widgets/base';
  3. import { IDisposable } from '@lumino/disposable';
  4. import { Widget } from '@lumino/widgets';
  5. import { INotebookModel } from '@jupyterlab/notebook';
  6. import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
  7. import { Kernel, KernelMessage, Session } from '@jupyterlab/services';
  8. import { DocumentRegistry } from '@jupyterlab/docregistry';
  9. import { ISignal } from '@lumino/signaling';
  10. /**
  11. * The mime type for a widget view.
  12. */
  13. export declare const WIDGET_VIEW_MIMETYPE = "application/vnd.jupyter.widget-view+json";
  14. /**
  15. * The mime type for widget state data.
  16. */
  17. export declare const WIDGET_STATE_MIMETYPE = "application/vnd.jupyter.widget-state+json";
  18. export declare class BackboneViewWrapper extends Widget {
  19. /**
  20. * Construct a new `Backbone` wrapper widget.
  21. *
  22. * @param view - The `Backbone.View` instance being wrapped.
  23. */
  24. constructor(view: Backbone.View<any>);
  25. onAfterAttach(msg: any): void;
  26. dispose(): void;
  27. private _view;
  28. }
  29. /**
  30. * A widget manager that returns phosphor widgets.
  31. */
  32. export declare class WidgetManager extends ManagerBase<Widget> implements IDisposable {
  33. constructor(context: DocumentRegistry.IContext<INotebookModel>, rendermime: IRenderMimeRegistry, settings: WidgetManager.Settings);
  34. /**
  35. * Save the widget state to the context model.
  36. */
  37. private _saveState;
  38. /**
  39. * Default callback handler to emit unhandled kernel messages.
  40. */
  41. callbacks(view?: WidgetView): {
  42. iopub: {
  43. output: (msg: KernelMessage.IIOPubMessage) => void;
  44. };
  45. };
  46. /**
  47. * Register a new kernel
  48. */
  49. _handleKernelChanged({ oldValue, newValue }: Session.ISessionConnection.IKernelChangedArgs): void;
  50. _handleKernelConnectionStatusChange(status: Kernel.ConnectionStatus): void;
  51. _handleKernelStatusChange(status: Kernel.Status): void;
  52. /**
  53. * Restore widgets from kernel and saved state.
  54. */
  55. restoreWidgets(notebook: INotebookModel, { loadKernel, loadNotebook }?: {
  56. loadKernel: boolean;
  57. loadNotebook: boolean;
  58. }): Promise<void>;
  59. /**
  60. * Disconnect the widget manager from the kernel, setting each model's comm
  61. * as dead.
  62. */
  63. disconnect(): void;
  64. _loadFromKernel(): Promise<void>;
  65. /**
  66. * Load widget state from notebook metadata
  67. */
  68. _loadFromNotebook(notebook: INotebookModel): Promise<void>;
  69. /**
  70. * Return a phosphor widget representing the view
  71. */
  72. display_view(msg: any, view: Backbone.View<Backbone.Model>, options: any): Promise<Widget>;
  73. /**
  74. * Create a comm.
  75. */
  76. _create_comm(target_name: string, model_id: string, data?: any, metadata?: any, buffers?: ArrayBuffer[] | ArrayBufferView[]): Promise<IClassicComm>;
  77. /**
  78. * Get the currently-registered comms.
  79. */
  80. _get_comm_info(): Promise<any>;
  81. /**
  82. * Get whether the manager is disposed.
  83. *
  84. * #### Notes
  85. * This is a read-only property.
  86. */
  87. get isDisposed(): boolean;
  88. /**
  89. * Dispose the resources held by the manager.
  90. */
  91. dispose(): void;
  92. /**
  93. * Resolve a URL relative to the current notebook location.
  94. */
  95. resolveUrl(url: string): Promise<string>;
  96. /**
  97. * Load a class and return a promise to the loaded object.
  98. */
  99. protected loadClass(className: string, moduleName: string, moduleVersion: string): Promise<typeof WidgetModel | typeof WidgetView>;
  100. get context(): DocumentRegistry.IContext<INotebookModel>;
  101. get rendermime(): IRenderMimeRegistry;
  102. /**
  103. * A signal emitted when state is restored to the widget manager.
  104. *
  105. * #### Notes
  106. * This indicates that previously-unavailable widget models might be available now.
  107. */
  108. get restored(): ISignal<this, void>;
  109. /**
  110. * Whether the state has been restored yet or not.
  111. */
  112. get restoredStatus(): boolean;
  113. /**
  114. * A signal emitted for unhandled iopub kernel messages.
  115. *
  116. */
  117. get onUnhandledIOPubMessage(): ISignal<this, KernelMessage.IIOPubMessage>;
  118. register(data: IWidgetRegistryData): void;
  119. /**
  120. * Get a model
  121. *
  122. * #### Notes
  123. * Unlike super.get_model(), this implementation always returns a promise and
  124. * never returns undefined. The promise will reject if the model is not found.
  125. */
  126. get_model(model_id: string): Promise<WidgetModel>;
  127. /**
  128. * Register a widget model.
  129. */
  130. register_model(model_id: string, modelPromise: Promise<WidgetModel>): void;
  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. * Synchronously get the state of the live widgets in the widget manager.
  138. *
  139. * This includes all of the live 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_sync(options?: IStateOptions): {
  146. version_major: number;
  147. version_minor: number;
  148. state: {
  149. [key: string]: any;
  150. };
  151. };
  152. /**
  153. * Set the dirty state of the notebook model if applicable.
  154. *
  155. * TODO: perhaps should also set dirty when any model changes any data
  156. */
  157. setDirty(): void;
  158. private _handleCommOpen;
  159. private _context;
  160. private _registry;
  161. private _rendermime;
  162. _commRegistration: IDisposable;
  163. private _restored;
  164. private _restoredStatus;
  165. private _initialRestoredStatus;
  166. private _modelsSync;
  167. private _settings;
  168. private _onUnhandledIOPubMessage;
  169. }
  170. export declare namespace WidgetManager {
  171. type Settings = {
  172. saveState: boolean;
  173. };
  174. }