tokens.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import { IChangedArgs } from '@jupyterlab/coreutils';
  4. import { ISettingRegistry } from '@jupyterlab/settingregistry';
  5. import { Token } from '@lumino/coreutils';
  6. import { IDisposable } from '@lumino/disposable';
  7. import { ISignal } from '@lumino/signaling';
  8. import { Widget } from '@lumino/widgets';
  9. import { ISessionContext } from './sessioncontext';
  10. /**
  11. * An interface for the session context dialogs.
  12. */
  13. export interface ISessionContextDialogs extends ISessionContext.IDialogs {}
  14. /* tslint:disable */
  15. /**
  16. * The session context dialogs token.
  17. */
  18. export const ISessionContextDialogs = new Token<ISessionContext.IDialogs>(
  19. '@jupyterlab/apputils:ISessionContextDialogs'
  20. );
  21. /* tslint:enable */
  22. /* tslint:disable */
  23. /**
  24. * The theme manager token.
  25. */
  26. export const IThemeManager = new Token<IThemeManager>(
  27. '@jupyterlab/apputils:IThemeManager'
  28. );
  29. /* tslint:enable */
  30. /**
  31. * An interface for a theme manager.
  32. */
  33. export interface IThemeManager {
  34. /**
  35. * Get the name of the current theme.
  36. */
  37. readonly theme: string | null;
  38. /**
  39. * The names of the registered themes.
  40. */
  41. readonly themes: ReadonlyArray<string>;
  42. /**
  43. * A signal fired when the application theme changes.
  44. */
  45. readonly themeChanged: ISignal<this, IChangedArgs<string, string | null>>;
  46. /**
  47. * Load a theme CSS file by path.
  48. *
  49. * @param path - The path of the file to load.
  50. */
  51. loadCSS(path: string): Promise<void>;
  52. /**
  53. * Register a theme with the theme manager.
  54. *
  55. * @param theme - The theme to register.
  56. *
  57. * @returns A disposable that can be used to unregister the theme.
  58. */
  59. register(theme: IThemeManager.ITheme): IDisposable;
  60. /**
  61. * Set the current theme.
  62. */
  63. setTheme(name: string): Promise<void>;
  64. /**
  65. * Test whether a given theme is light.
  66. */
  67. isLight(name: string): boolean;
  68. /**
  69. * Test whether a given theme styles scrollbars,
  70. * and if the user has scrollbar styling enabled.
  71. */
  72. themeScrollbars(name: string): boolean;
  73. /**
  74. * Get display name for theme.
  75. */
  76. getDisplayName(name: string): string;
  77. }
  78. /**
  79. * A namespace for the `IThemeManager` sub-types.
  80. */
  81. export namespace IThemeManager {
  82. /**
  83. * An interface for a theme.
  84. */
  85. export interface ITheme {
  86. /**
  87. * The unique identifier name of the theme.
  88. */
  89. name: string;
  90. /**
  91. * The display name of the theme.
  92. */
  93. displayName?: string;
  94. /**
  95. * Whether the theme is light or dark. Downstream authors
  96. * of extensions can use this information to customize their
  97. * UI depending upon the current theme.
  98. */
  99. isLight: boolean;
  100. /**
  101. * Whether the theme includes styling for the scrollbar.
  102. * If set to false, this theme will leave the native scrollbar untouched.
  103. */
  104. themeScrollbars?: boolean;
  105. /**
  106. * Load the theme.
  107. *
  108. * @returns A promise that resolves when the theme has loaded.
  109. */
  110. load(): Promise<void>;
  111. /**
  112. * Unload the theme.
  113. *
  114. * @returns A promise that resolves when the theme has unloaded.
  115. */
  116. unload(): Promise<void>;
  117. }
  118. }
  119. /**
  120. * The sanitizer token.
  121. */
  122. export const ISanitizer = new Token<ISanitizer>(
  123. '@jupyterlab/apputils:ISanitizer'
  124. );
  125. export interface ISanitizer {
  126. /**
  127. * Sanitize an HTML string.
  128. *
  129. * @param dirty - The dirty text.
  130. *
  131. * @param options - The optional sanitization options.
  132. *
  133. * @returns The sanitized string.
  134. */
  135. sanitize(dirty: string, options?: ISanitizer.IOptions): string;
  136. }
  137. /**
  138. * The namespace for `ISanitizer` related interfaces.
  139. */
  140. export namespace ISanitizer {
  141. /**
  142. * The options used to sanitize.
  143. */
  144. export interface IOptions {
  145. /**
  146. * The allowed tags.
  147. */
  148. allowedTags?: string[];
  149. /**
  150. * The allowed attributes for a given tag.
  151. */
  152. allowedAttributes?: { [key: string]: string[] };
  153. /**
  154. * The allowed style values for a given tag.
  155. */
  156. allowedStyles?: { [key: string]: { [key: string]: RegExp[] } };
  157. }
  158. }
  159. /**
  160. * The namespace for `IToolbarWidgetRegistry` related interfaces
  161. */
  162. export namespace ToolbarRegistry {
  163. /**
  164. * Interface of item to be inserted in a toolbar
  165. */
  166. export interface IToolbarItem {
  167. /**
  168. * Unique item name
  169. */
  170. name: string;
  171. /**
  172. * Toolbar widget
  173. */
  174. widget: Widget;
  175. }
  176. /**
  177. * Interface describing a toolbar item widget
  178. */
  179. export interface IWidget extends ISettingRegistry.IToolbarItem {}
  180. /**
  181. * Options to set up the toolbar widget registry
  182. */
  183. export interface IOptions {
  184. /**
  185. * Default toolbar widget factory
  186. *
  187. * The factory is receiving 3 arguments:
  188. * @param widgetFactory The widget factory name that creates the toolbar
  189. * @param widget The newly widget containing the toolbar
  190. * @param toolbarItem The toolbar item definition
  191. * @returns The widget to be inserted in the toolbar.
  192. */
  193. defaultFactory: (
  194. widgetFactory: string,
  195. widget: Widget,
  196. toolbarItem: IWidget
  197. ) => Widget;
  198. }
  199. }
  200. /**
  201. * Toolbar widget registry interface
  202. */
  203. export interface IToolbarWidgetRegistry {
  204. /**
  205. * Default toolbar item factory
  206. */
  207. defaultFactory: (
  208. widgetFactory: string,
  209. widget: Widget,
  210. toolbarItem: ToolbarRegistry.IWidget
  211. ) => Widget;
  212. /**
  213. * Create a toolbar item widget
  214. *
  215. * @param widgetFactory The widget factory name that creates the toolbar
  216. * @param widget The newly widget containing the toolbar
  217. * @param toolbarItem The toolbar item definition
  218. * @returns The widget to be inserted in the toolbar.
  219. */
  220. createWidget(
  221. widgetFactory: string,
  222. widget: Widget,
  223. toolbarItem: ToolbarRegistry.IWidget
  224. ): Widget;
  225. /**
  226. * Register a new toolbar item factory
  227. *
  228. * @param widgetFactory The widget factory name that creates the toolbar
  229. * @param toolbarItemName The unique toolbar item
  230. * @param factory The factory function that receives the widget containing the toolbar and returns the toolbar widget.
  231. * @returns The previously defined factory
  232. */
  233. registerFactory<T extends Widget = Widget>(
  234. widgetFactory: string,
  235. toolbarItemName: string,
  236. factory: (main: T) => Widget
  237. ): ((main: T) => Widget) | undefined;
  238. }
  239. /**
  240. * The toolbar registry token.
  241. */
  242. export const IToolbarWidgetRegistry = new Token<IToolbarWidgetRegistry>(
  243. '@jupyterlab/apputils:IToolbarWidgetRegistry'
  244. );