@basthon/gui-base 0.41.4 → 0.41.7

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
@@ -73,7 +73,7 @@ export declare class GUIBase {
73
73
  /**
74
74
  * The error notification system.
75
75
  */
76
- notifyError(error: ErrorEvent | PromiseRejectionEvent): void;
76
+ notifyError(error: Error | ErrorEvent | PromiseRejectionEvent): void;
77
77
  /**
78
78
  * Initialize the GUI.
79
79
  */
@@ -181,15 +181,11 @@ export declare class GUIBase {
181
181
  /**
182
182
  * Download content to file.
183
183
  */
184
- download(filename: string): void;
184
+ download(filename?: string): void;
185
185
  /**
186
186
  * Copy a text to clipboard.
187
187
  */
188
188
  static copyToClipboard: (text: string) => void;
189
- /**
190
- * Binding to kernel's XHR.
191
- */
192
- static xhr(params: any): Promise<unknown>;
193
189
  /**
194
190
  * Compress a string to another string (URL safe).
195
191
  */
package/lib/main.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { PromiseDelegate } from "promise-delegate";
2
2
  import { CheckpointsManager } from "@basthon/checkpoints";
3
- import { KernelBase } from "@basthon/kernel-base";
4
3
  import { KernelLoader } from "@basthon/kernel-loader";
5
4
  /**
6
5
  * Base class for console and notebook GUI.
@@ -108,6 +107,7 @@ export class GUIBase {
108
107
  * Loading the content from query string (ipynb=/script= or from=).
109
108
  */
110
109
  async loadFromQS(key) {
110
+ var _a;
111
111
  const url = new URL(window.location.href);
112
112
  const from_key = 'from';
113
113
  let content = null;
@@ -127,14 +127,13 @@ export class GUIBase {
127
127
  if (fileURL != null)
128
128
  fileURL = decodeURIComponent(fileURL);
129
129
  try {
130
- content = await GUIBase.xhr({
131
- url: fileURL,
132
- method: 'GET'
133
- });
130
+ const response = await fetch(fileURL);
131
+ if (!response.ok)
132
+ throw new Error(response.statusText);
133
+ content = await response.text();
134
134
  }
135
135
  catch (error) {
136
- const message = `Le chargement de ${fileURL} a échoué.`;
137
- throw new ErrorEvent(message, { message: message });
136
+ throw new Error(`Le chargement de ${fileURL} a échoué : ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error.toString()}`);
138
137
  }
139
138
  }
140
139
  if (content != null)
@@ -250,7 +249,7 @@ export class GUIBase {
250
249
  const onerror = this.notifyError.bind(this);
251
250
  window.addEventListener('error', onerror);
252
251
  window.addEventListener("unhandledrejection", onerror);
253
- console.error = (message) => onerror(new ErrorEvent(message, { message: message }));
252
+ console.error = (message) => onerror(new Error(message));
254
253
  await ((_a = this._checkpoints) === null || _a === void 0 ? void 0 : _a.ready());
255
254
  await this.setupUI(options);
256
255
  await this.loadInitialContent(options);
@@ -296,18 +295,16 @@ export class GUIBase {
296
295
  for (let fileURL of url.searchParams.getAll(key)) {
297
296
  fileURL = decodeURIComponent(fileURL);
298
297
  const filename = fileURL.split('/').pop() || "";
299
- let promise = GUIBase.xhr({
300
- method: "GET",
301
- url: fileURL,
302
- responseType: "arraybuffer"
303
- });
304
- promise = promise.then(function (data) {
298
+ promises.push(fetch(fileURL).then((response) => {
299
+ if (!response.ok)
300
+ throw new Error(response.statusText);
301
+ return response.arrayBuffer();
302
+ }).then((data) => {
305
303
  return put(filename, data);
306
- }).catch(function () {
307
- const message = `Impossible de charger le fichier ${filename}.`;
308
- throw new ErrorEvent(message, { message: message });
309
- });
310
- promises.push(promise);
304
+ }).catch((error) => {
305
+ var _a;
306
+ throw new Error(`Impossible de charger le fichier ${filename} : ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error.toString()}`);
307
+ }));
311
308
  }
312
309
  await Promise.all(promises);
313
310
  }
@@ -442,12 +439,6 @@ Un lien permanant vers le contenu actuel a été créé.
442
439
  let blob = new Blob([content], { type: "text/plain" });
443
440
  GUIBase.openURL(window.URL.createObjectURL(blob), filename !== null && filename !== void 0 ? filename : this._contentFilename);
444
441
  }
445
- /**
446
- * Binding to kernel's XHR.
447
- */
448
- static async xhr(params) {
449
- return await KernelBase.xhr(params);
450
- }
451
442
  /**
452
443
  * Compress a string to another string (URL safe).
453
444
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basthon/gui-base",
3
- "version": "0.41.4",
3
+ "version": "0.41.7",
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.41.4",
29
- "@basthon/kernel-base": "^0.41.4",
30
- "@basthon/kernel-loader": "^0.41.4",
28
+ "@basthon/checkpoints": "^0.41.7",
29
+ "@basthon/kernel-base": "^0.41.7",
30
+ "@basthon/kernel-loader": "^0.41.7",
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": "1407ac3233c5e73aca3c5acd1b47c780f169873c"
44
+ "gitHead": "1d9ded08f7081824e600a74f7b4fd47fbd254de9"
45
45
  }