@basthon/gui-base 0.50.3 → 0.50.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/main.d.ts CHANGED
@@ -24,7 +24,6 @@ export declare class GUIBase {
24
24
  protected _contentFilename: string;
25
25
  protected _urlKey: string;
26
26
  private _extensions;
27
- private _urlExtensions;
28
27
  private _console_error;
29
28
  constructor(options: GUIOptions);
30
29
  /**
@@ -92,6 +91,11 @@ export declare class GUIBase {
92
91
  * Loading the content from query string (ipynb=/script= or from=).
93
92
  */
94
93
  loadFromQS(key: string): Promise<string | null>;
94
+ /**
95
+ * Load all URL requested (and registered) extensions
96
+ * (call submited callback).
97
+ */
98
+ private _loadExtensions;
95
99
  /**
96
100
  * Setup the UI (typically connect events, load extensions etc..).
97
101
  */
@@ -158,7 +162,7 @@ export declare class GUIBase {
158
162
  /**
159
163
  * Register an extension and its callback.
160
164
  */
161
- registerExtension(name: string, callback: (() => void)): void;
165
+ registerExtension(name: string, callback: (() => Promise<void>)): void;
162
166
  /**
163
167
  * Opening file: If it has ext as extension, loading it in
164
168
  * the editor or put on (emulated) local filesystem
package/lib/main.js CHANGED
@@ -20,9 +20,6 @@ export class GUIBase {
20
20
  /* per language checkpoints */
21
21
  if (!options.noCheckpointsInit)
22
22
  this._checkpoints = new CheckpointsManager(`${options.uiName}.${options.language}`, this._maxCheckpoints);
23
- /* get requested extensions from URL */
24
- const url = new URL(window.location.href);
25
- this._urlExtensions = (url.searchParams.get("extensions") || "").split(',');
26
23
  }
27
24
  /**
28
25
  * Language getter.
@@ -145,17 +142,28 @@ export class GUIBase {
145
142
  return content;
146
143
  }
147
144
  /**
148
- * Setup the UI (typically connect events, load extensions etc..).
145
+ * Load all URL requested (and registered) extensions
146
+ * (call submited callback).
149
147
  */
150
- async setupUI(options) {
151
- /* load extensions */
152
- for (const ext of this._urlExtensions) {
148
+ async _loadExtensions() {
149
+ /* get requested extensions from URL */
150
+ const url = new URL(window.location.href);
151
+ const extensions = (url.searchParams.get("extensions") || "").split(',');
152
+ // call callbacks for requested extensions
153
+ const promises = [];
154
+ for (const ext of extensions) {
153
155
  const callback = this._extensions.get(ext);
154
156
  if (callback != null)
155
- callback();
157
+ promises.push(callback());
156
158
  else
157
159
  console.error(`Extension '${ext}' not supported.`);
158
160
  }
161
+ await Promise.all(promises);
162
+ }
163
+ /**
164
+ * Setup the UI (typically connect events, load extensions etc..).
165
+ */
166
+ async setupUI(options) {
159
167
  /* wait for kernel load */
160
168
  const kernel = await this.kernelLoader.kernelAvailable();
161
169
  // this is ugly but it seems complicated to make
@@ -262,6 +270,7 @@ export class GUIBase {
262
270
  window.addEventListener('error', onerror);
263
271
  window.addEventListener("unhandledrejection", onerror);
264
272
  console.error = (message) => onerror(new Error(message));
273
+ await this._loadExtensions();
265
274
  await ((_a = this._checkpoints) === null || _a === void 0 ? void 0 : _a.ready());
266
275
  await this.setupUI(options);
267
276
  await this.loadInitialContent(options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basthon/gui-base",
3
- "version": "0.50.3",
3
+ "version": "0.50.4",
4
4
  "description": "Basthon - Base GUI",
5
5
  "homepage": "https://basthon.fr",
6
6
  "bugs": {
@@ -25,9 +25,9 @@
25
25
  "clean": "rm -rf lib/"
26
26
  },
27
27
  "dependencies": {
28
- "@basthon/checkpoints": "0.50.3",
29
- "@basthon/kernel-base": "0.50.3",
30
- "@basthon/kernel-loader": "0.50.3",
28
+ "@basthon/checkpoints": "0.50.4",
29
+ "@basthon/kernel-base": "0.50.4",
30
+ "@basthon/kernel-loader": "0.50.4",
31
31
  "js-base64": "^3.7.2",
32
32
  "pako": "^2.0.4",
33
33
  "promise-delegate": "^1.0.1"
@@ -41,5 +41,5 @@
41
41
  "publishConfig": {
42
42
  "access": "public"
43
43
  },
44
- "gitHead": "9283011a642c404226f1c63f93fbed1cfc0aae8e"
44
+ "gitHead": "e5551d308c66dbc081600522fe2d68ee8d34884c"
45
45
  }