@basthon/gui-base 0.41.6 → 0.41.9

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
  */
@@ -101,7 +101,7 @@ export declare class GUIBase {
101
101
  /**
102
102
  * Load content from local forage.
103
103
  */
104
- loadFromStorage(): Promise<string | null>;
104
+ loadFromStorage(setContent?: boolean): Promise<string | null>;
105
105
  /**
106
106
  * Tag last backup as "approved".
107
107
  */
@@ -186,10 +186,6 @@ export declare class GUIBase {
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)
@@ -176,7 +175,7 @@ export class GUIBase {
176
175
  /**
177
176
  * Load content from local forage.
178
177
  */
179
- async loadFromStorage() {
178
+ async loadFromStorage(setContent = true) {
180
179
  var _a;
181
180
  const approved = await this.lastBackupValid();
182
181
  let content = null;
@@ -190,10 +189,10 @@ export class GUIBase {
190
189
  const promise = new PromiseDelegate();
191
190
  this.confirm("Récupération", "Il semble que Basthon ait rencontré un problème à sa dernière utilisation. Que voulez-vous faire ?", "Choisir une sauvegarde", async () => {
192
191
  promise.resolve(await this.selectCheckpoint());
193
- }, "Laisser le document vide", () => { promise.resolve(null); });
192
+ }, "Annuler", () => { promise.resolve(null); });
194
193
  content = await promise.promise;
195
194
  }
196
- if (content != null)
195
+ if (setContent && content != null)
197
196
  this.setContent(content);
198
197
  return content;
199
198
  }
@@ -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.6",
3
+ "version": "0.41.9",
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.6",
29
- "@basthon/kernel-base": "^0.41.6",
30
- "@basthon/kernel-loader": "^0.41.6",
28
+ "@basthon/checkpoints": "^0.41.9",
29
+ "@basthon/kernel-base": "^0.41.9",
30
+ "@basthon/kernel-loader": "^0.41.9",
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": "65c171a20b16334c757d4f801d94c7bc68d0efec"
44
+ "gitHead": "7063ce35c8205ef6894405e49fbf1b0eb05d0630"
45
45
  }