@basthon/gui-base 0.36.0 → 0.36.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
@@ -1,20 +1,14 @@
1
1
  import { KernelBase } from "@basthon/kernel-base";
2
2
  import { KernelLoader } from "@basthon/kernel-loader";
3
- declare global {
4
- interface Window {
5
- Basthon?: any;
6
- }
7
- }
8
3
  /**
9
4
  * Base class for console and notebook GUI.
10
5
  */
11
6
  export declare class GUIBase {
12
7
  private readonly _language;
13
8
  private readonly _loaded;
14
- private _kernel;
15
9
  private _loader;
16
10
  private _console_error;
17
- constructor(language: string);
11
+ constructor(kernelRootPath: string, language: string);
18
12
  /**
19
13
  * Language getter.
20
14
  */
@@ -106,4 +100,8 @@ export declare class GUIBase {
106
100
  * Copy a text to clipboard.
107
101
  */
108
102
  static copyToClipboard: (text: string) => void;
103
+ /**
104
+ * Binding to kernel's XHR.
105
+ */
106
+ static xhr(params: any): Promise<unknown>;
109
107
  }
package/lib/main.js CHANGED
@@ -5,19 +5,14 @@ import { KernelLoader } from "@basthon/kernel-loader";
5
5
  * Base class for console and notebook GUI.
6
6
  */
7
7
  export class GUIBase {
8
- constructor(language) {
8
+ constructor(kernelRootPath, language) {
9
9
  this._loaded = new PromiseDelegate();
10
- this._kernel = null;
11
10
  /* console errors redirected to notification system */
12
11
  this._console_error = console.error;
13
12
  this._language = language;
14
- this._loader = new KernelLoader(language);
13
+ this._loader = new KernelLoader(kernelRootPath, language);
15
14
  // loading Basthon (errors are fatal)
16
15
  this._loader.showLoader("Chargement de Basthon...", false);
17
- this._loader.kernelAvailable().then(() => {
18
- this._kernel = this._loader.kernel;
19
- window.Basthon = this._kernel;
20
- });
21
16
  }
22
17
  /**
23
18
  * Language getter.
@@ -26,7 +21,7 @@ export class GUIBase {
26
21
  /**
27
22
  * Kernel getter.
28
23
  */
29
- get kernel() { return this._kernel; }
24
+ get kernel() { return this._loader.kernel; }
30
25
  /**
31
26
  * KernelLoader getter.
32
27
  */
@@ -108,7 +103,7 @@ export class GUIBase {
108
103
  /**
109
104
  * Restart the kernel.
110
105
  */
111
- kernelRestart() { var _a; (_a = this._kernel) === null || _a === void 0 ? void 0 : _a.restart(); }
106
+ kernelRestart() { var _a; (_a = this.kernel) === null || _a === void 0 ? void 0 : _a.restart(); }
112
107
  /**
113
108
  * Load ressources from URL (common part to files and modules).
114
109
  */
@@ -118,7 +113,7 @@ export class GUIBase {
118
113
  for (let fileURL of url.searchParams.getAll(key)) {
119
114
  fileURL = decodeURIComponent(fileURL);
120
115
  const filename = fileURL.split('/').pop() || "";
121
- let promise = KernelBase.xhr({
116
+ let promise = GUIBase.xhr({
122
117
  method: "GET",
123
118
  url: fileURL,
124
119
  responseType: "arraybuffer"
@@ -143,7 +138,7 @@ export class GUIBase {
143
138
  reader.onload = async (event) => {
144
139
  var _a, _b;
145
140
  (_a = this.kernel) === null || _a === void 0 ? void 0 : _a.putRessource(file.name, reader.result);
146
- this.info("Fichier utilisable depuis Python", `${file.name} est maintenant utilisable depuis ${(_b = this._kernel) === null || _b === void 0 ? void 0 : _b.languageName()}`);
141
+ this.info("Fichier utilisable depuis Python", `${file.name} est maintenant utilisable depuis ${(_b = this.kernel) === null || _b === void 0 ? void 0 : _b.languageName()}`);
147
142
  resolve();
148
143
  };
149
144
  reader.onerror = reject;
@@ -153,17 +148,17 @@ export class GUIBase {
153
148
  * Load auxiliary files submited via URL (aux= parameter) (async).
154
149
  */
155
150
  async loadURLAux() {
156
- if (this._kernel == null)
151
+ if (this.kernel == null)
157
152
  return;
158
- await this._loadFromURL('aux', this._kernel.putFile.bind(this._kernel));
153
+ await this._loadFromURL('aux', this.kernel.putFile.bind(this.kernel));
159
154
  }
160
155
  /**
161
156
  * Load modules submited via URL (module= parameter) (async).
162
157
  */
163
158
  async loadURLModules() {
164
- if (this._kernel == null)
159
+ if (this.kernel == null)
165
160
  return;
166
- await this._loadFromURL('module', this._kernel.putModule.bind(this._kernel));
161
+ await this._loadFromURL('module', this.kernel.putModule.bind(this.kernel));
167
162
  }
168
163
  /**
169
164
  * Opening file: If it has ext as extension, loading it in
@@ -217,6 +212,12 @@ export class GUIBase {
217
212
  async _share(url, message) {
218
213
  this.confirm("Partager ce notebook", message, "Copier dans le presse-papier", () => GUIBase.copyToClipboard(url), "Tester le lien", () => GUIBase.openURL(url));
219
214
  }
215
+ /**
216
+ * Binding to kernel's XHR.
217
+ */
218
+ static async xhr(params) {
219
+ return await KernelBase.xhr(params);
220
+ }
220
221
  }
221
222
  /**
222
223
  * Copy a text to clipboard.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basthon/gui-base",
3
- "version": "0.36.0",
3
+ "version": "0.36.4",
4
4
  "description": "Basthon - Base GUI",
5
5
  "homepage": "https://basthon.fr",
6
6
  "bugs": {
@@ -25,8 +25,8 @@
25
25
  "clean": "rm -rf lib/"
26
26
  },
27
27
  "dependencies": {
28
- "@basthon/kernel-base": "^0.36.0",
29
- "@basthon/kernel-loader": "^0.36.0",
28
+ "@basthon/kernel-base": "^0.36.4",
29
+ "@basthon/kernel-loader": "^0.36.4",
30
30
  "promise-delegate": "^1.0.1"
31
31
  },
32
32
  "devDependencies": {
@@ -37,5 +37,5 @@
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "1b7d7fe5eccb791eb4b78c650facd39c84061d4b"
40
+ "gitHead": "edcb6d1d099440e2fadbeb12acf34b5cc77486a2"
41
41
  }