1 |
|
2 |
|
3 | import { PathExt } from '@jupyterlab/coreutils';
|
4 | import { nullTranslator } from '@jupyterlab/translation';
|
5 | import { fileIcon, folderIcon, imageIcon, jsonIcon, juliaIcon, markdownIcon, notebookIcon, pdfIcon, pythonIcon, rKernelIcon, spreadsheetIcon, yamlIcon } from '@jupyterlab/ui-components';
|
6 | import { ArrayExt, find } from '@lumino/algorithm';
|
7 | import { DisposableDelegate } from '@lumino/disposable';
|
8 | import { Signal } from '@lumino/signaling';
|
9 | import { TextModelFactory } from './default';
|
10 |
|
11 |
|
12 |
|
13 | export class DocumentRegistry {
|
14 | |
15 |
|
16 |
|
17 | constructor(options = {}) {
|
18 | this._modelFactories = Object.create(null);
|
19 | this._widgetFactories = Object.create(null);
|
20 | this._defaultWidgetFactory = '';
|
21 | this._defaultWidgetFactoryOverrides = Object.create(null);
|
22 | this._defaultWidgetFactories = Object.create(null);
|
23 | this._defaultRenderedWidgetFactories = Object.create(null);
|
24 | this._widgetFactoriesForFileType = Object.create(null);
|
25 | this._fileTypes = [];
|
26 | this._extenders = Object.create(null);
|
27 | this._changed = new Signal(this);
|
28 | this._isDisposed = false;
|
29 | const factory = options.textModelFactory;
|
30 | this.translator = options.translator || nullTranslator;
|
31 | if (factory && factory.name !== 'text') {
|
32 | throw new Error('Text model factory must have the name `text`');
|
33 | }
|
34 | this._modelFactories['text'] = factory || new TextModelFactory(true);
|
35 | const fts = options.initialFileTypes ||
|
36 | DocumentRegistry.getDefaultFileTypes(this.translator);
|
37 | fts.forEach(ft => {
|
38 | const value = {
|
39 | ...DocumentRegistry.getFileTypeDefaults(this.translator),
|
40 | ...ft
|
41 | };
|
42 | this._fileTypes.push(value);
|
43 | });
|
44 | }
|
45 | |
46 |
|
47 |
|
48 | get changed() {
|
49 | return this._changed;
|
50 | }
|
51 | |
52 |
|
53 |
|
54 | get isDisposed() {
|
55 | return this._isDisposed;
|
56 | }
|
57 | |
58 |
|
59 |
|
60 | dispose() {
|
61 | if (this.isDisposed) {
|
62 | return;
|
63 | }
|
64 | this._isDisposed = true;
|
65 | for (const modelName in this._modelFactories) {
|
66 | this._modelFactories[modelName].dispose();
|
67 | }
|
68 | for (const widgetName in this._widgetFactories) {
|
69 | this._widgetFactories[widgetName].dispose();
|
70 | }
|
71 | for (const widgetName in this._extenders) {
|
72 | this._extenders[widgetName].length = 0;
|
73 | }
|
74 | this._fileTypes.length = 0;
|
75 | Signal.clearData(this);
|
76 | }
|
77 | |
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | addWidgetFactory(factory) {
|
94 | const name = factory.name.toLowerCase();
|
95 | if (!name || name === 'default') {
|
96 | throw Error('Invalid factory name');
|
97 | }
|
98 | if (this._widgetFactories[name]) {
|
99 | console.warn(`Duplicate registered factory ${name}`);
|
100 | return new DisposableDelegate(Private.noOp);
|
101 | }
|
102 | this._widgetFactories[name] = factory;
|
103 | for (const ft of factory.defaultFor || []) {
|
104 | if (factory.fileTypes.indexOf(ft) === -1) {
|
105 | continue;
|
106 | }
|
107 | if (ft === '*') {
|
108 | this._defaultWidgetFactory = name;
|
109 | }
|
110 | else {
|
111 | this._defaultWidgetFactories[ft] = name;
|
112 | }
|
113 | }
|
114 | for (const ft of factory.defaultRendered || []) {
|
115 | if (factory.fileTypes.indexOf(ft) === -1) {
|
116 | continue;
|
117 | }
|
118 | this._defaultRenderedWidgetFactories[ft] = name;
|
119 | }
|
120 |
|
121 | for (const ft of factory.fileTypes) {
|
122 | if (!this._widgetFactoriesForFileType[ft]) {
|
123 | this._widgetFactoriesForFileType[ft] = [];
|
124 | }
|
125 | this._widgetFactoriesForFileType[ft].push(name);
|
126 | }
|
127 | this._changed.emit({
|
128 | type: 'widgetFactory',
|
129 | name,
|
130 | change: 'added'
|
131 | });
|
132 | return new DisposableDelegate(() => {
|
133 | delete this._widgetFactories[name];
|
134 | if (this._defaultWidgetFactory === name) {
|
135 | this._defaultWidgetFactory = '';
|
136 | }
|
137 | for (const ext of Object.keys(this._defaultWidgetFactories)) {
|
138 | if (this._defaultWidgetFactories[ext] === name) {
|
139 | delete this._defaultWidgetFactories[ext];
|
140 | }
|
141 | }
|
142 | for (const ext of Object.keys(this._defaultRenderedWidgetFactories)) {
|
143 | if (this._defaultRenderedWidgetFactories[ext] === name) {
|
144 | delete this._defaultRenderedWidgetFactories[ext];
|
145 | }
|
146 | }
|
147 | for (const ext of Object.keys(this._widgetFactoriesForFileType)) {
|
148 | ArrayExt.removeFirstOf(this._widgetFactoriesForFileType[ext], name);
|
149 | if (this._widgetFactoriesForFileType[ext].length === 0) {
|
150 | delete this._widgetFactoriesForFileType[ext];
|
151 | }
|
152 | }
|
153 | for (const ext of Object.keys(this._defaultWidgetFactoryOverrides)) {
|
154 | if (this._defaultWidgetFactoryOverrides[ext] === name) {
|
155 | delete this._defaultWidgetFactoryOverrides[ext];
|
156 | }
|
157 | }
|
158 | this._changed.emit({
|
159 | type: 'widgetFactory',
|
160 | name,
|
161 | change: 'removed'
|
162 | });
|
163 | });
|
164 | }
|
165 | |
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 | addModelFactory(factory) {
|
178 | const name = factory.name.toLowerCase();
|
179 | if (this._modelFactories[name]) {
|
180 | console.warn(`Duplicate registered factory ${name}`);
|
181 | return new DisposableDelegate(Private.noOp);
|
182 | }
|
183 | this._modelFactories[name] = factory;
|
184 | this._changed.emit({
|
185 | type: 'modelFactory',
|
186 | name,
|
187 | change: 'added'
|
188 | });
|
189 | return new DisposableDelegate(() => {
|
190 | delete this._modelFactories[name];
|
191 | this._changed.emit({
|
192 | type: 'modelFactory',
|
193 | name,
|
194 | change: 'removed'
|
195 | });
|
196 | });
|
197 | }
|
198 | |
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 | addWidgetExtension(widgetName, extension) {
|
212 | widgetName = widgetName.toLowerCase();
|
213 | if (!(widgetName in this._extenders)) {
|
214 | this._extenders[widgetName] = [];
|
215 | }
|
216 | const extenders = this._extenders[widgetName];
|
217 | const index = ArrayExt.firstIndexOf(extenders, extension);
|
218 | if (index !== -1) {
|
219 | console.warn(`Duplicate registered extension for ${widgetName}`);
|
220 | return new DisposableDelegate(Private.noOp);
|
221 | }
|
222 | this._extenders[widgetName].push(extension);
|
223 | this._changed.emit({
|
224 | type: 'widgetExtension',
|
225 | name: widgetName,
|
226 | change: 'added'
|
227 | });
|
228 | return new DisposableDelegate(() => {
|
229 | ArrayExt.removeFirstOf(this._extenders[widgetName], extension);
|
230 | this._changed.emit({
|
231 | type: 'widgetExtension',
|
232 | name: widgetName,
|
233 | change: 'removed'
|
234 | });
|
235 | });
|
236 | }
|
237 | |
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 | addFileType(fileType, factories) {
|
252 | const value = {
|
253 | ...DocumentRegistry.getFileTypeDefaults(this.translator),
|
254 | ...fileType,
|
255 |
|
256 | ...(!(fileType.icon || fileType.iconClass) && { icon: fileIcon })
|
257 | };
|
258 | this._fileTypes.push(value);
|
259 |
|
260 |
|
261 | if (factories) {
|
262 | const fileTypeName = value.name.toLowerCase();
|
263 | factories
|
264 | .map(factory => factory.toLowerCase())
|
265 | .forEach(factory => {
|
266 | if (!this._widgetFactoriesForFileType[fileTypeName]) {
|
267 | this._widgetFactoriesForFileType[fileTypeName] = [];
|
268 | }
|
269 | if (!this._widgetFactoriesForFileType[fileTypeName].includes(factory)) {
|
270 | this._widgetFactoriesForFileType[fileTypeName].push(factory);
|
271 | }
|
272 | });
|
273 | if (!this._defaultWidgetFactories[fileTypeName]) {
|
274 | this._defaultWidgetFactories[fileTypeName] =
|
275 | this._widgetFactoriesForFileType[fileTypeName][0];
|
276 | }
|
277 | }
|
278 | this._changed.emit({
|
279 | type: 'fileType',
|
280 | name: value.name,
|
281 | change: 'added'
|
282 | });
|
283 | return new DisposableDelegate(() => {
|
284 | ArrayExt.removeFirstOf(this._fileTypes, value);
|
285 | if (factories) {
|
286 | const fileTypeName = value.name.toLowerCase();
|
287 | for (const name of factories.map(factory => factory.toLowerCase())) {
|
288 | ArrayExt.removeFirstOf(this._widgetFactoriesForFileType[fileTypeName], name);
|
289 | }
|
290 | if (this._defaultWidgetFactories[fileTypeName] ===
|
291 | factories[0].toLowerCase()) {
|
292 | delete this._defaultWidgetFactories[fileTypeName];
|
293 | }
|
294 | }
|
295 | this._changed.emit({
|
296 | type: 'fileType',
|
297 | name: fileType.name,
|
298 | change: 'removed'
|
299 | });
|
300 | });
|
301 | }
|
302 | |
303 |
|
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 | preferredWidgetFactories(path) {
|
321 | const factories = new Set();
|
322 |
|
323 | const fts = this.getFileTypesForPath(PathExt.basename(path));
|
324 |
|
325 | fts.forEach(ft => {
|
326 | if (ft.name in this._defaultWidgetFactoryOverrides) {
|
327 | factories.add(this._defaultWidgetFactoryOverrides[ft.name]);
|
328 | }
|
329 | });
|
330 |
|
331 | fts.forEach(ft => {
|
332 | if (ft.name in this._defaultWidgetFactories) {
|
333 | factories.add(this._defaultWidgetFactories[ft.name]);
|
334 | }
|
335 | });
|
336 |
|
337 | fts.forEach(ft => {
|
338 | if (ft.name in this._defaultRenderedWidgetFactories) {
|
339 | factories.add(this._defaultRenderedWidgetFactories[ft.name]);
|
340 | }
|
341 | });
|
342 |
|
343 | if (this._defaultWidgetFactory) {
|
344 | factories.add(this._defaultWidgetFactory);
|
345 | }
|
346 |
|
347 | for (const ft of fts) {
|
348 | if (ft.name in this._widgetFactoriesForFileType) {
|
349 | for (const n of this._widgetFactoriesForFileType[ft.name]) {
|
350 | factories.add(n);
|
351 | }
|
352 | }
|
353 | }
|
354 |
|
355 | if ('*' in this._widgetFactoriesForFileType) {
|
356 | for (const n of this._widgetFactoriesForFileType['*']) {
|
357 | factories.add(n);
|
358 | }
|
359 | }
|
360 |
|
361 |
|
362 | const factoryList = [];
|
363 | for (const name of factories) {
|
364 | const factory = this._widgetFactories[name];
|
365 | if (!factory) {
|
366 | continue;
|
367 | }
|
368 | const modelName = factory.modelName || 'text';
|
369 | if (modelName in this._modelFactories) {
|
370 | factoryList.push(factory);
|
371 | }
|
372 | }
|
373 | return factoryList;
|
374 | }
|
375 | |
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 | defaultRenderedWidgetFactory(path) {
|
391 |
|
392 | const ftNames = this.getFileTypesForPath(PathExt.basename(path)).map(ft => ft.name);
|
393 |
|
394 | for (const name in ftNames) {
|
395 | if (name in this._defaultWidgetFactoryOverrides) {
|
396 | return this._widgetFactories[this._defaultWidgetFactoryOverrides[name]];
|
397 | }
|
398 | }
|
399 |
|
400 | for (const name in ftNames) {
|
401 | if (name in this._defaultRenderedWidgetFactories) {
|
402 | return this._widgetFactories[this._defaultRenderedWidgetFactories[name]];
|
403 | }
|
404 | }
|
405 |
|
406 | return this.defaultWidgetFactory(path);
|
407 | }
|
408 | |
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 | defaultWidgetFactory(path) {
|
419 | if (!path) {
|
420 | return this._widgetFactories[this._defaultWidgetFactory];
|
421 | }
|
422 | return this.preferredWidgetFactories(path)[0];
|
423 | }
|
424 | |
425 |
|
426 |
|
427 |
|
428 |
|
429 |
|
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 |
|
437 |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 | setDefaultWidgetFactory(fileType, factory) {
|
445 | fileType = fileType.toLowerCase();
|
446 | if (!this.getFileType(fileType)) {
|
447 | throw Error(`Cannot find file type ${fileType}`);
|
448 | }
|
449 | if (!factory) {
|
450 | if (this._defaultWidgetFactoryOverrides[fileType]) {
|
451 | delete this._defaultWidgetFactoryOverrides[fileType];
|
452 | }
|
453 | return;
|
454 | }
|
455 | if (!this.getWidgetFactory(factory)) {
|
456 | throw Error(`Cannot find widget factory ${factory}`);
|
457 | }
|
458 | factory = factory.toLowerCase();
|
459 | const factories = this._widgetFactoriesForFileType[fileType];
|
460 | if (factory !== this._defaultWidgetFactory &&
|
461 | !(factories && factories.includes(factory))) {
|
462 | throw Error(`Factory ${factory} cannot view file type ${fileType}`);
|
463 | }
|
464 | this._defaultWidgetFactoryOverrides[fileType] = factory;
|
465 | }
|
466 | |
467 |
|
468 |
|
469 |
|
470 |
|
471 | *widgetFactories() {
|
472 | for (const name in this._widgetFactories) {
|
473 | yield this._widgetFactories[name];
|
474 | }
|
475 | }
|
476 | |
477 |
|
478 |
|
479 |
|
480 |
|
481 | *modelFactories() {
|
482 | for (const name in this._modelFactories) {
|
483 | yield this._modelFactories[name];
|
484 | }
|
485 | }
|
486 | |
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 |
|
493 | *widgetExtensions(widgetName) {
|
494 | widgetName = widgetName.toLowerCase();
|
495 | if (widgetName in this._extenders) {
|
496 | for (const extension of this._extenders[widgetName]) {
|
497 | yield extension;
|
498 | }
|
499 | }
|
500 | }
|
501 | |
502 |
|
503 |
|
504 |
|
505 |
|
506 | *fileTypes() {
|
507 | for (const type of this._fileTypes) {
|
508 | yield type;
|
509 | }
|
510 | }
|
511 | |
512 |
|
513 |
|
514 |
|
515 |
|
516 |
|
517 |
|
518 | getWidgetFactory(widgetName) {
|
519 | return this._widgetFactories[widgetName.toLowerCase()];
|
520 | }
|
521 | |
522 |
|
523 |
|
524 |
|
525 |
|
526 |
|
527 |
|
528 | getModelFactory(name) {
|
529 | return this._modelFactories[name.toLowerCase()];
|
530 | }
|
531 | |
532 |
|
533 |
|
534 | getFileType(name) {
|
535 | name = name.toLowerCase();
|
536 | return find(this._fileTypes, fileType => {
|
537 | return fileType.name.toLowerCase() === name;
|
538 | });
|
539 | }
|
540 | |
541 |
|
542 |
|
543 |
|
544 |
|
545 |
|
546 |
|
547 |
|
548 |
|
549 |
|
550 |
|
551 | getKernelPreference(path, widgetName, kernel) {
|
552 | widgetName = widgetName.toLowerCase();
|
553 | const widgetFactory = this._widgetFactories[widgetName];
|
554 | if (!widgetFactory) {
|
555 | return void 0;
|
556 | }
|
557 | const modelFactory = this.getModelFactory(widgetFactory.modelName || 'text');
|
558 | if (!modelFactory) {
|
559 | return void 0;
|
560 | }
|
561 | const language = modelFactory.preferredLanguage(PathExt.basename(path));
|
562 | const name = kernel && kernel.name;
|
563 | const id = kernel && kernel.id;
|
564 | return {
|
565 | id,
|
566 | name,
|
567 | language,
|
568 | shouldStart: widgetFactory.preferKernel,
|
569 | canStart: widgetFactory.canStartKernel,
|
570 | shutdownOnDispose: widgetFactory.shutdownOnClose,
|
571 | autoStartDefault: widgetFactory.autoStartDefault
|
572 | };
|
573 | }
|
574 | |
575 |
|
576 |
|
577 |
|
578 |
|
579 |
|
580 |
|
581 | getFileTypeForModel(model) {
|
582 | let ft = null;
|
583 | if (model.name || model.path) {
|
584 | const name = model.name || PathExt.basename(model.path);
|
585 | const fts = this.getFileTypesForPath(name);
|
586 | if (fts.length > 0) {
|
587 | ft = fts[0];
|
588 | }
|
589 | }
|
590 | switch (model.type) {
|
591 | case 'directory':
|
592 | if (ft !== null && ft.contentType === 'directory') {
|
593 | return ft;
|
594 | }
|
595 | return (find(this._fileTypes, ft => ft.contentType === 'directory') ||
|
596 | DocumentRegistry.getDefaultDirectoryFileType(this.translator));
|
597 | case 'notebook':
|
598 | if (ft !== null && ft.contentType === 'notebook') {
|
599 | return ft;
|
600 | }
|
601 | return (find(this._fileTypes, ft => ft.contentType === 'notebook') ||
|
602 | DocumentRegistry.getDefaultNotebookFileType(this.translator));
|
603 | default:
|
604 |
|
605 | if (ft !== null) {
|
606 | return ft;
|
607 | }
|
608 | return (this.getFileType('text') ||
|
609 | DocumentRegistry.getDefaultTextFileType(this.translator));
|
610 | }
|
611 | }
|
612 | |
613 |
|
614 |
|
615 |
|
616 |
|
617 |
|
618 |
|
619 | getFileTypesForPath(path) {
|
620 | const fts = [];
|
621 | const name = PathExt.basename(path);
|
622 |
|
623 | let ft = find(this._fileTypes, ft => {
|
624 | return !!(ft.pattern && name.match(ft.pattern) !== null);
|
625 | });
|
626 | if (ft) {
|
627 | fts.push(ft);
|
628 | }
|
629 |
|
630 | let ext = Private.extname(name);
|
631 | while (ext.length > 1) {
|
632 | const ftSubset = this._fileTypes.filter(ft =>
|
633 |
|
634 | ft.extensions.map(extension => extension.toLowerCase()).includes(ext));
|
635 | fts.push(...ftSubset);
|
636 | ext = '.' + ext.split('.').slice(2).join('.');
|
637 | }
|
638 | return fts;
|
639 | }
|
640 | }
|
641 |
|
642 |
|
643 |
|
644 | (function (DocumentRegistry) {
|
645 | |
646 |
|
647 |
|
648 |
|
649 |
|
650 |
|
651 |
|
652 | function getFileTypeDefaults(translator) {
|
653 | translator = translator || nullTranslator;
|
654 | const trans = translator === null || translator === void 0 ? void 0 : translator.load('jupyterlab');
|
655 | return {
|
656 | name: 'default',
|
657 | displayName: trans.__('default'),
|
658 | extensions: [],
|
659 | mimeTypes: [],
|
660 | contentType: 'file',
|
661 | fileFormat: 'text'
|
662 | };
|
663 | }
|
664 | DocumentRegistry.getFileTypeDefaults = getFileTypeDefaults;
|
665 | |
666 |
|
667 |
|
668 |
|
669 |
|
670 |
|
671 |
|
672 | function getDefaultTextFileType(translator) {
|
673 | translator = translator || nullTranslator;
|
674 | const trans = translator === null || translator === void 0 ? void 0 : translator.load('jupyterlab');
|
675 | const fileTypeDefaults = getFileTypeDefaults(translator);
|
676 | return {
|
677 | ...fileTypeDefaults,
|
678 | name: 'text',
|
679 | displayName: trans.__('Text'),
|
680 | mimeTypes: ['text/plain'],
|
681 | extensions: ['.txt'],
|
682 | icon: fileIcon
|
683 | };
|
684 | }
|
685 | DocumentRegistry.getDefaultTextFileType = getDefaultTextFileType;
|
686 | |
687 |
|
688 |
|
689 |
|
690 |
|
691 |
|
692 |
|
693 | function getDefaultNotebookFileType(translator) {
|
694 | translator = translator || nullTranslator;
|
695 | const trans = translator === null || translator === void 0 ? void 0 : translator.load('jupyterlab');
|
696 | return {
|
697 | ...getFileTypeDefaults(translator),
|
698 | name: 'notebook',
|
699 | displayName: trans.__('Notebook'),
|
700 | mimeTypes: ['application/x-ipynb+json'],
|
701 | extensions: ['.ipynb'],
|
702 | contentType: 'notebook',
|
703 | fileFormat: 'json',
|
704 | icon: notebookIcon
|
705 | };
|
706 | }
|
707 | DocumentRegistry.getDefaultNotebookFileType = getDefaultNotebookFileType;
|
708 | |
709 |
|
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 | function getDefaultDirectoryFileType(translator) {
|
716 | translator = translator || nullTranslator;
|
717 | const trans = translator === null || translator === void 0 ? void 0 : translator.load('jupyterlab');
|
718 | return {
|
719 | ...getFileTypeDefaults(translator),
|
720 | name: 'directory',
|
721 | displayName: trans.__('Directory'),
|
722 | extensions: [],
|
723 | mimeTypes: ['text/directory'],
|
724 | contentType: 'directory',
|
725 | icon: folderIcon
|
726 | };
|
727 | }
|
728 | DocumentRegistry.getDefaultDirectoryFileType = getDefaultDirectoryFileType;
|
729 | |
730 |
|
731 |
|
732 |
|
733 |
|
734 |
|
735 |
|
736 | function getDefaultFileTypes(translator) {
|
737 | translator = translator || nullTranslator;
|
738 | const trans = translator === null || translator === void 0 ? void 0 : translator.load('jupyterlab');
|
739 | return [
|
740 | getDefaultTextFileType(translator),
|
741 | getDefaultNotebookFileType(translator),
|
742 | getDefaultDirectoryFileType(translator),
|
743 | {
|
744 | name: 'markdown',
|
745 | displayName: trans.__('Markdown File'),
|
746 | extensions: ['.md'],
|
747 | mimeTypes: ['text/markdown'],
|
748 | icon: markdownIcon
|
749 | },
|
750 | {
|
751 | name: 'PDF',
|
752 | displayName: trans.__('PDF File'),
|
753 | extensions: ['.pdf'],
|
754 | mimeTypes: ['application/pdf'],
|
755 | icon: pdfIcon
|
756 | },
|
757 | {
|
758 | name: 'python',
|
759 | displayName: trans.__('Python File'),
|
760 | extensions: ['.py'],
|
761 | mimeTypes: ['text/x-python'],
|
762 | icon: pythonIcon
|
763 | },
|
764 | {
|
765 | name: 'json',
|
766 | displayName: trans.__('JSON File'),
|
767 | extensions: ['.json'],
|
768 | mimeTypes: ['application/json'],
|
769 | icon: jsonIcon
|
770 | },
|
771 | {
|
772 | name: 'jsonl',
|
773 | displayName: trans.__('JSONLines File'),
|
774 | extensions: ['.jsonl', '.ndjson'],
|
775 | mimeTypes: [
|
776 | 'text/jsonl',
|
777 | 'application/jsonl',
|
778 | 'application/json-lines'
|
779 | ],
|
780 | icon: jsonIcon
|
781 | },
|
782 | {
|
783 | name: 'julia',
|
784 | displayName: trans.__('Julia File'),
|
785 | extensions: ['.jl'],
|
786 | mimeTypes: ['text/x-julia'],
|
787 | icon: juliaIcon
|
788 | },
|
789 | {
|
790 | name: 'csv',
|
791 | displayName: trans.__('CSV File'),
|
792 | extensions: ['.csv'],
|
793 | mimeTypes: ['text/csv'],
|
794 | icon: spreadsheetIcon
|
795 | },
|
796 | {
|
797 | name: 'tsv',
|
798 | displayName: trans.__('TSV File'),
|
799 | extensions: ['.tsv'],
|
800 | mimeTypes: ['text/csv'],
|
801 | icon: spreadsheetIcon
|
802 | },
|
803 | {
|
804 | name: 'r',
|
805 | displayName: trans.__('R File'),
|
806 | mimeTypes: ['text/x-rsrc'],
|
807 | extensions: ['.R'],
|
808 | icon: rKernelIcon
|
809 | },
|
810 | {
|
811 | name: 'yaml',
|
812 | displayName: trans.__('YAML File'),
|
813 | mimeTypes: ['text/x-yaml', 'text/yaml'],
|
814 | extensions: ['.yaml', '.yml'],
|
815 | icon: yamlIcon
|
816 | },
|
817 | {
|
818 | name: 'svg',
|
819 | displayName: trans.__('Image'),
|
820 | mimeTypes: ['image/svg+xml'],
|
821 | extensions: ['.svg'],
|
822 | icon: imageIcon,
|
823 | fileFormat: 'base64'
|
824 | },
|
825 | {
|
826 | name: 'tiff',
|
827 | displayName: trans.__('Image'),
|
828 | mimeTypes: ['image/tiff'],
|
829 | extensions: ['.tif', '.tiff'],
|
830 | icon: imageIcon,
|
831 | fileFormat: 'base64'
|
832 | },
|
833 | {
|
834 | name: 'jpeg',
|
835 | displayName: trans.__('Image'),
|
836 | mimeTypes: ['image/jpeg'],
|
837 | extensions: ['.jpg', '.jpeg'],
|
838 | icon: imageIcon,
|
839 | fileFormat: 'base64'
|
840 | },
|
841 | {
|
842 | name: 'gif',
|
843 | displayName: trans.__('Image'),
|
844 | mimeTypes: ['image/gif'],
|
845 | extensions: ['.gif'],
|
846 | icon: imageIcon,
|
847 | fileFormat: 'base64'
|
848 | },
|
849 | {
|
850 | name: 'png',
|
851 | displayName: trans.__('Image'),
|
852 | mimeTypes: ['image/png'],
|
853 | extensions: ['.png'],
|
854 | icon: imageIcon,
|
855 | fileFormat: 'base64'
|
856 | },
|
857 | {
|
858 | name: 'bmp',
|
859 | displayName: trans.__('Image'),
|
860 | mimeTypes: ['image/bmp'],
|
861 | extensions: ['.bmp'],
|
862 | icon: imageIcon,
|
863 | fileFormat: 'base64'
|
864 | },
|
865 | {
|
866 | name: 'webp',
|
867 | displayName: trans.__('Image'),
|
868 | mimeTypes: ['image/webp'],
|
869 | extensions: ['.webp'],
|
870 | icon: imageIcon,
|
871 | fileFormat: 'base64'
|
872 | }
|
873 | ];
|
874 | }
|
875 | DocumentRegistry.getDefaultFileTypes = getDefaultFileTypes;
|
876 | })(DocumentRegistry || (DocumentRegistry = {}));
|
877 |
|
878 |
|
879 |
|
880 | var Private;
|
881 | (function (Private) {
|
882 | |
883 |
|
884 |
|
885 |
|
886 |
|
887 |
|
888 |
|
889 |
|
890 | function extname(path) {
|
891 | const parts = PathExt.basename(path).split('.');
|
892 | parts.shift();
|
893 | const ext = '.' + parts.join('.');
|
894 | return ext.toLowerCase();
|
895 | }
|
896 | Private.extname = extname;
|
897 | |
898 |
|
899 |
|
900 | function noOp() {
|
901 |
|
902 | }
|
903 | Private.noOp = noOp;
|
904 | })(Private || (Private = {}));
|
905 |
|
\ | No newline at end of file |