1 | import { ISanitizer, ISessionContext } from '@jupyterlab/apputils';
|
2 | import { IRenderMime } from '@jupyterlab/rendermime-interfaces';
|
3 | import { Contents, Session } from '@jupyterlab/services';
|
4 | import { ITranslator } from '@jupyterlab/translation';
|
5 | import { ReadonlyPartialJSONObject } from '@lumino/coreutils';
|
6 | import { MimeModel } from './mimemodel';
|
7 | import { IRenderMimeRegistry } from './tokens';
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | export declare class RenderMimeRegistry implements IRenderMimeRegistry {
|
19 | |
20 |
|
21 |
|
22 |
|
23 |
|
24 | constructor(options?: RenderMimeRegistry.IOptions);
|
25 | /**
|
26 | * The sanitizer used by the rendermime instance.
|
27 | */
|
28 | readonly sanitizer: ISanitizer;
|
29 | /**
|
30 | * The object used to resolve relative urls for the rendermime instance.
|
31 | */
|
32 | readonly resolver: IRenderMime.IResolver | null;
|
33 | /**
|
34 | * The object used to handle path opening links.
|
35 | */
|
36 | readonly linkHandler: IRenderMime.ILinkHandler | null;
|
37 | /**
|
38 | * The LaTeX typesetter for the rendermime.
|
39 | */
|
40 | readonly latexTypesetter: IRenderMime.ILatexTypesetter | null;
|
41 | /**
|
42 | * The application language translator.
|
43 | */
|
44 | readonly translator: ITranslator;
|
45 | /**
|
46 | * The ordered list of mimeTypes.
|
47 | */
|
48 | get mimeTypes(): ReadonlyArray<string>;
|
49 | /**
|
50 | * Find the preferred mime type for a mime bundle.
|
51 | *
|
52 | * @param bundle - The bundle of mime data.
|
53 | *
|
54 | * @param safe - How to consider safe/unsafe factories. If 'ensure',
|
55 | * it will only consider safe factories. If 'any', any factory will be
|
56 | * considered. If 'prefer', unsafe factories will be considered, but
|
57 | * only after the safe options have been exhausted.
|
58 | *
|
59 | * @returns The preferred mime type from the available factories,
|
60 | * or `undefined` if the mime type cannot be rendered.
|
61 | */
|
62 | preferredMimeType(bundle: ReadonlyPartialJSONObject, safe?: 'ensure' | 'prefer' | 'any'): string | undefined;
|
63 | /**
|
64 | * Create a renderer for a mime type.
|
65 | *
|
66 | * @param mimeType - The mime type of interest.
|
67 | *
|
68 | * @returns A new renderer for the given mime type.
|
69 | *
|
70 | * @throws An error if no factory exists for the mime type.
|
71 | */
|
72 | createRenderer(mimeType: string): IRenderMime.IRenderer;
|
73 | /**
|
74 | * Create a new mime model. This is a convenience method.
|
75 | *
|
76 | * @options - The options used to create the model.
|
77 | *
|
78 | * @returns A new mime model.
|
79 | */
|
80 | createModel(options?: MimeModel.IOptions): MimeModel;
|
81 | /**
|
82 | * Create a clone of this rendermime instance.
|
83 | *
|
84 | * @param options - The options for configuring the clone.
|
85 | *
|
86 | * @returns A new independent clone of the rendermime.
|
87 | */
|
88 | clone(options?: IRenderMimeRegistry.ICloneOptions): RenderMimeRegistry;
|
89 | /**
|
90 | * Get the renderer factory registered for a mime type.
|
91 | *
|
92 | * @param mimeType - The mime type of interest.
|
93 | *
|
94 | * @returns The factory for the mime type, or `undefined`.
|
95 | */
|
96 | getFactory(mimeType: string): IRenderMime.IRendererFactory | undefined;
|
97 | /**
|
98 | * Add a renderer factory to the rendermime.
|
99 | *
|
100 | * @param factory - The renderer factory of interest.
|
101 | *
|
102 | * @param rank - The rank of the renderer. A lower rank indicates
|
103 | * a higher priority for rendering. If not given, the rank will
|
104 | * defer to the `defaultRank` of the factory. If no `defaultRank`
|
105 | * is given, it will default to 100.
|
106 | *
|
107 | * #### Notes
|
108 | * The renderer will replace an existing renderer for the given
|
109 | * mimeType.
|
110 | */
|
111 | addFactory(factory: IRenderMime.IRendererFactory, rank?: number): void;
|
112 | /**
|
113 | * Remove a mime type.
|
114 | *
|
115 | * @param mimeType - The mime type of interest.
|
116 | */
|
117 | removeMimeType(mimeType: string): void;
|
118 | /**
|
119 | * Get the rank for a given mime type.
|
120 | *
|
121 | * @param mimeType - The mime type of interest.
|
122 | *
|
123 | * @returns The rank of the mime type or undefined.
|
124 | */
|
125 | getRank(mimeType: string): number | undefined;
|
126 | /**
|
127 | * Set the rank of a given mime type.
|
128 | *
|
129 | * @param mimeType - The mime type of interest.
|
130 | *
|
131 | * @param rank - The new rank to assign.
|
132 | *
|
133 | * #### Notes
|
134 | * This is a no-op if the mime type is not registered.
|
135 | */
|
136 | setRank(mimeType: string, rank: number): void;
|
137 | private _id;
|
138 | private _ranks;
|
139 | private _types;
|
140 | private _factories;
|
141 | }
|
142 | /**
|
143 | * The namespace for `RenderMimeRegistry` class statics.
|
144 | */
|
145 | export declare namespace RenderMimeRegistry {
|
146 | |
147 |
|
148 |
|
149 | interface IOptions {
|
150 | |
151 |
|
152 |
|
153 | initialFactories?: ReadonlyArray<IRenderMime.IRendererFactory>;
|
154 | |
155 |
|
156 |
|
157 |
|
158 |
|
159 | sanitizer?: IRenderMime.ISanitizer;
|
160 | |
161 |
|
162 |
|
163 |
|
164 |
|
165 | resolver?: IRenderMime.IResolver;
|
166 | |
167 |
|
168 |
|
169 | linkHandler?: IRenderMime.ILinkHandler;
|
170 | |
171 |
|
172 |
|
173 | latexTypesetter?: IRenderMime.ILatexTypesetter;
|
174 | |
175 |
|
176 |
|
177 | translator?: ITranslator;
|
178 | }
|
179 | |
180 |
|
181 |
|
182 | class UrlResolver implements IRenderMime.IResolver {
|
183 | |
184 |
|
185 |
|
186 | constructor(options: IUrlResolverOptions);
|
187 | /**
|
188 | * The path of the object, from which local urls can be derived.
|
189 | */
|
190 | get path(): string;
|
191 | set path(value: string);
|
192 | /**
|
193 | * Resolve a relative url to an absolute url path.
|
194 | */
|
195 | resolveUrl(url: string): Promise<string>;
|
196 | /**
|
197 | * Get the download url of a given absolute url path.
|
198 | *
|
199 | * #### Notes
|
200 | * The returned URL may include a query parameter.
|
201 | */
|
202 | getDownloadUrl(urlPath: string): Promise<string>;
|
203 | /**
|
204 | * Whether the URL should be handled by the resolver
|
205 | * or not.
|
206 | *
|
207 | * #### Notes
|
208 | * This is similar to the `isLocal` check in `URLExt`,
|
209 | * but it also checks whether the path points to any
|
210 | * of the `IDrive`s that may be registered with the contents
|
211 | * manager.
|
212 | */
|
213 | isLocal(url: string): boolean;
|
214 | /**
|
215 | * Whether the URL can be decoded using `decodeURI`.
|
216 | */
|
217 | isMalformed(url: string): boolean;
|
218 | private _path;
|
219 | private _session;
|
220 | private _contents;
|
221 | }
|
222 | /**
|
223 | * The options used to create a UrlResolver.
|
224 | */
|
225 | interface IUrlResolverOptions {
|
226 | |
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 | path?: string;
|
233 | |
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 | session?: ISessionContext | Session.ISessionConnection;
|
245 | |
246 |
|
247 |
|
248 | contents: Contents.IManager;
|
249 | }
|
250 | }
|