Skip to content

Commit 64e5c86

Browse files
committed
Working with jupytercad app
1 parent 1de03b0 commit 64e5c86

File tree

4 files changed

+199
-11
lines changed

4 files changed

+199
-11
lines changed

python/jupytercad_app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"@jupyterlab/filebrowser": "^4.0.0",
7676
"@jupyterlab/filebrowser-extension": "^4.0.0",
7777
"@jupyterlab/fileeditor": "^4.2.0",
78+
"@jupyterlab/json-extension": "^4.0.0",
7879
"@jupyterlab/launcher": "^4.0.0",
7980
"@jupyterlab/launcher-extension": "^4.0.0",
8081
"@jupyterlab/logconsole": "^4.0.0",

python/jupytercad_app/src/app/app.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import {
2+
createRendermimePlugins,
23
JupyterFrontEnd,
34
JupyterFrontEndPlugin
45
} from '@jupyterlab/application';
56

67
import { PageConfig } from '@jupyterlab/coreutils';
78

89
import { IShell, Shell } from './shell';
10+
import { IRenderMime } from '@jupyterlab/rendermime';
911

1012
/**
1113
* App is the main application class. It is instantiated once and shared.
@@ -16,10 +18,16 @@ export class App extends JupyterFrontEnd<IShell> {
1618
*
1719
* @param options The instantiation options for an application.
1820
*/
19-
constructor(options: App.IOptions = { shell: new Shell() }) {
21+
constructor(options: App.IOptions) {
2022
super({
21-
shell: options.shell
23+
...options,
24+
shell: options.shell ?? new Shell()
2225
});
26+
if (options.mimeExtensions) {
27+
for (const plugin of createRendermimePlugins(options.mimeExtensions)) {
28+
this.registerPlugin(plugin);
29+
}
30+
}
2331
}
2432

2533
/**
@@ -112,7 +120,21 @@ export namespace App {
112120
/**
113121
* The instantiation options for an App application.
114122
*/
115-
export type IOptions = JupyterFrontEnd.IOptions<IShell>;
123+
export interface IOptions
124+
extends JupyterFrontEnd.IOptions<IShell>,
125+
Partial<IInfo> {
126+
paths?: Partial<JupyterFrontEnd.IPaths>;
127+
}
128+
129+
/**
130+
* The information about a application.
131+
*/
132+
export interface IInfo {
133+
/**
134+
* The mime renderer extensions.
135+
*/
136+
readonly mimeExtensions: IRenderMime.IExtensionModule[];
137+
}
116138

117139
/**
118140
* The interface for a module that exports a plugin or plugins as

python/jupytercad_app/src/main.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import '@jupyterlab/console/style/index.js';
1515
import '@jupyterlab/completer/style/index.js';
1616
import '../style/index.css';
1717
import './sharedscope';
18+
import { Shell } from './app/shell';
1819

1920
function loadScript(url: string) {
2021
return new Promise((resolve, reject) => {
@@ -61,7 +62,6 @@ async function createModule(scope: string, module: string) {
6162
async function main(): Promise<void> {
6263
// Inject some packages in the shared scope
6364

64-
const app = new App();
6565
// populate the list of disabled extensions
6666
const disabled: any[] = [
6767
'jupytercad:serverInfoPlugin',
@@ -142,8 +142,12 @@ async function main(): Promise<void> {
142142
require('./app/plugins/browser'),
143143
require('./app/plugins/launcher')
144144
];
145+
const mimeExtensions = [
146+
require('@jupyterlab/json-extension'),
147+
];
145148

146149
const federatedExtensionPromises: Promise<any>[] = [];
150+
const federatedMimeExtensionPromises: Promise<any>[] = [];
147151
const federatedStylePromises: Promise<any>[] = [];
148152

149153
const extension_data = JSON.parse(
@@ -176,8 +180,9 @@ async function main(): Promise<void> {
176180
federatedExtensionPromises.push(createModule(data.name, data.extension));
177181
}
178182
if (data.mimeExtension) {
179-
// TODO Do we need mime extensions?
180-
return;
183+
federatedMimeExtensionPromises.push(
184+
createModule(data.name, data.mimeExtension)
185+
);
181186
}
182187
if (data.style && !PageConfig.Extension.isDisabled(data.name)) {
183188
federatedStylePromises.push(createModule(data.name, data.style));
@@ -200,13 +205,28 @@ async function main(): Promise<void> {
200205
}
201206
});
202207

208+
// Add the federated mime extensions.
209+
const federatedMimeExtensions = await Promise.allSettled(
210+
federatedMimeExtensionPromises
211+
);
212+
federatedMimeExtensions.forEach((p) => {
213+
if (p.status === 'fulfilled') {
214+
for (const plugin of activePlugins(p.value)) {
215+
mimeExtensions.push(plugin);
216+
}
217+
} else {
218+
console.error(p.reason);
219+
}
220+
});
221+
203222
// Load all federated component styles and log errors for any that do not
204223
(await Promise.allSettled(federatedStylePromises))
205224
.filter(({ status }) => status === 'rejected')
206225
.forEach(e => {
207226
console.error((e as any).reason);
208227
});
209228

229+
const app = new App({ mimeExtensions, shell: new Shell() });
210230
app.registerPluginModules(mods);
211231

212232
await app.start();

0 commit comments

Comments
 (0)