@basthon/gui-base 0.50.15 → 0.50.17
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 +4 -4
- package/lib/main.js +75 -46
- package/package.json +5 -5
package/lib/main.d.ts
CHANGED
|
@@ -63,14 +63,14 @@ export declare class GUIBase {
|
|
|
63
63
|
/**
|
|
64
64
|
* Ask the user to confirm or cancel.
|
|
65
65
|
*/
|
|
66
|
-
confirm(title: string, message: string, text: string, callback: (
|
|
66
|
+
confirm(title: string, message: string, text: string, callback: () => void, textCancel: string, callbackCancel: () => void): void;
|
|
67
67
|
/**
|
|
68
68
|
* Ask the user to select a choice.
|
|
69
69
|
*/
|
|
70
70
|
select(title: string, message: string, choices: {
|
|
71
71
|
text: string;
|
|
72
72
|
handler: () => void;
|
|
73
|
-
}[], textCancel: string, callbackCancel: (
|
|
73
|
+
}[], textCancel: string, callbackCancel: () => void): void;
|
|
74
74
|
/**
|
|
75
75
|
* The error notification system.
|
|
76
76
|
*/
|
|
@@ -170,7 +170,7 @@ export declare class GUIBase {
|
|
|
170
170
|
/**
|
|
171
171
|
* Register an extension and its callback.
|
|
172
172
|
*/
|
|
173
|
-
registerExtension(name: string, callback: (
|
|
173
|
+
registerExtension(name: string, callback: () => Promise<void>): void;
|
|
174
174
|
/**
|
|
175
175
|
* Opening file: If it has ext as extension, loading it in
|
|
176
176
|
* the editor or put on (emulated) local filesystem
|
|
@@ -178,7 +178,7 @@ export declare class GUIBase {
|
|
|
178
178
|
* filesystem.
|
|
179
179
|
*/
|
|
180
180
|
protected _openFile(callbacks: {
|
|
181
|
-
[key: string]: (
|
|
181
|
+
[key: string]: (_: File) => Promise<void>;
|
|
182
182
|
}): Promise<void>;
|
|
183
183
|
/**
|
|
184
184
|
* Open an URL in a new tab or download a file.
|
package/lib/main.js
CHANGED
|
@@ -27,24 +27,36 @@ export class GUIBase {
|
|
|
27
27
|
/**
|
|
28
28
|
* Language getter.
|
|
29
29
|
*/
|
|
30
|
-
get language() {
|
|
30
|
+
get language() {
|
|
31
|
+
return this._language;
|
|
32
|
+
}
|
|
31
33
|
/**
|
|
32
34
|
* Kernel getter.
|
|
33
35
|
*/
|
|
34
|
-
get kernel() {
|
|
35
|
-
|
|
36
|
+
get kernel() {
|
|
37
|
+
return this._loader.kernel;
|
|
38
|
+
}
|
|
39
|
+
get kernelSafe() {
|
|
40
|
+
return this._loader.kernelSafe;
|
|
41
|
+
}
|
|
36
42
|
/**
|
|
37
43
|
* KernelLoader getter.
|
|
38
44
|
*/
|
|
39
|
-
get kernelLoader() {
|
|
45
|
+
get kernelLoader() {
|
|
46
|
+
return this._loader;
|
|
47
|
+
}
|
|
40
48
|
/**
|
|
41
49
|
* Check if GUI is loaded.
|
|
42
50
|
*/
|
|
43
|
-
async loaded() {
|
|
51
|
+
async loaded() {
|
|
52
|
+
await this._loaded.promise;
|
|
53
|
+
}
|
|
44
54
|
/**
|
|
45
55
|
* Wait for par load (document.body available).
|
|
46
56
|
*/
|
|
47
|
-
async pageLoad() {
|
|
57
|
+
async pageLoad() {
|
|
58
|
+
await this._loader.pageLoad();
|
|
59
|
+
}
|
|
48
60
|
/**
|
|
49
61
|
* Set the checkpoints manager
|
|
50
62
|
* (typically use with GUIOptions.noCheckpointsInit set to true).
|
|
@@ -79,7 +91,7 @@ export class GUIBase {
|
|
|
79
91
|
message = (_b = (_a = error) === null || _a === void 0 ? void 0 : _a.reason) === null || _b === void 0 ? void 0 : _b.message;
|
|
80
92
|
if (message == null)
|
|
81
93
|
message = error.toString();
|
|
82
|
-
message = message.split(
|
|
94
|
+
message = message.split("\n").join("<br>");
|
|
83
95
|
this.error("Erreur", `Erreur : ${message}`);
|
|
84
96
|
// In case of error, force loader hiding.
|
|
85
97
|
try {
|
|
@@ -102,7 +114,9 @@ export class GUIBase {
|
|
|
102
114
|
/**
|
|
103
115
|
* Get the content (script or notebook content).
|
|
104
116
|
*/
|
|
105
|
-
content() {
|
|
117
|
+
content() {
|
|
118
|
+
return "";
|
|
119
|
+
}
|
|
106
120
|
/**
|
|
107
121
|
* Set the content (script or notebook content).
|
|
108
122
|
*/
|
|
@@ -113,7 +127,7 @@ export class GUIBase {
|
|
|
113
127
|
async loadFromQS(key) {
|
|
114
128
|
var _a;
|
|
115
129
|
const url = new URL(window.location.href);
|
|
116
|
-
const from_key =
|
|
130
|
+
const from_key = "from";
|
|
117
131
|
let content = null;
|
|
118
132
|
if (url.searchParams.has(key)) {
|
|
119
133
|
content = url.searchParams.get(key) || "";
|
|
@@ -130,14 +144,17 @@ export class GUIBase {
|
|
|
130
144
|
let fileURL = url.searchParams.get(from_key);
|
|
131
145
|
if (fileURL != null)
|
|
132
146
|
fileURL = decodeURIComponent(fileURL);
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
147
|
+
// empty from param gives empty content
|
|
148
|
+
if (fileURL !== "") {
|
|
149
|
+
try {
|
|
150
|
+
const response = await fetch(fileURL);
|
|
151
|
+
if (!response.ok)
|
|
152
|
+
throw new Error(response.statusText);
|
|
153
|
+
content = await response.text();
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
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()}`);
|
|
157
|
+
}
|
|
141
158
|
}
|
|
142
159
|
}
|
|
143
160
|
if (content != null)
|
|
@@ -152,7 +169,7 @@ export class GUIBase {
|
|
|
152
169
|
var _a, _b;
|
|
153
170
|
/* get requested extensions from URL */
|
|
154
171
|
const url = new URL(window.location.href);
|
|
155
|
-
const extensions = (_b = (_a = url.searchParams.get("extensions")) === null || _a === void 0 ? void 0 : _a.split(
|
|
172
|
+
const extensions = (_b = (_a = url.searchParams.get("extensions")) === null || _a === void 0 ? void 0 : _a.split(",")) !== null && _b !== void 0 ? _b : [];
|
|
156
173
|
// call callbacks for requested extensions
|
|
157
174
|
const promises = [];
|
|
158
175
|
for (const ext of extensions) {
|
|
@@ -193,7 +210,7 @@ export class GUIBase {
|
|
|
193
210
|
*/
|
|
194
211
|
async getState(state, def) {
|
|
195
212
|
var _a;
|
|
196
|
-
return (_a = await this._stateStorage.get(state)) !== null && _a !== void 0 ? _a : def;
|
|
213
|
+
return (_a = (await this._stateStorage.get(state))) !== null && _a !== void 0 ? _a : def;
|
|
197
214
|
}
|
|
198
215
|
/**
|
|
199
216
|
* Set state in storage.
|
|
@@ -207,7 +224,7 @@ export class GUIBase {
|
|
|
207
224
|
async loadInitialContent(options) {
|
|
208
225
|
if (window._basthonEmptyContent)
|
|
209
226
|
return;
|
|
210
|
-
if (await this.loadFromQS(this._urlKey) != null)
|
|
227
|
+
if ((await this.loadFromQS(this._urlKey)) != null)
|
|
211
228
|
return;
|
|
212
229
|
this.loadFromStorage();
|
|
213
230
|
}
|
|
@@ -222,13 +239,15 @@ export class GUIBase {
|
|
|
222
239
|
content = null;
|
|
223
240
|
}
|
|
224
241
|
else if (approved) {
|
|
225
|
-
content = await ((_a = this._checkpoints) === null || _a === void 0 ? void 0 : _a.getLast());
|
|
242
|
+
content = (await ((_a = this._checkpoints) === null || _a === void 0 ? void 0 : _a.getLast()));
|
|
226
243
|
}
|
|
227
244
|
else {
|
|
228
245
|
const promise = new PromiseDelegate();
|
|
229
246
|
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 () => {
|
|
230
247
|
promise.resolve(await this.selectCheckpoint());
|
|
231
|
-
}, "Annuler", () => {
|
|
248
|
+
}, "Annuler", () => {
|
|
249
|
+
promise.resolve(null);
|
|
250
|
+
});
|
|
232
251
|
content = await promise.promise;
|
|
233
252
|
}
|
|
234
253
|
if (setContent && content != null)
|
|
@@ -258,7 +277,10 @@ export class GUIBase {
|
|
|
258
277
|
const promise = new PromiseDelegate();
|
|
259
278
|
const choices = times === null || times === void 0 ? void 0 : times.map((t, i) => ({
|
|
260
279
|
text: CheckpointsManager.toHumanDate(parseInt(t, 10)),
|
|
261
|
-
handler: async () => {
|
|
280
|
+
handler: async () => {
|
|
281
|
+
var _a, _b;
|
|
282
|
+
promise.resolve((_b = (await ((_a = this._checkpoints) === null || _a === void 0 ? void 0 : _a.getIndex(i)))) !== null && _b !== void 0 ? _b : null);
|
|
283
|
+
},
|
|
262
284
|
}));
|
|
263
285
|
if (choices == null)
|
|
264
286
|
return null;
|
|
@@ -267,7 +289,9 @@ export class GUIBase {
|
|
|
267
289
|
promise.resolve(null);
|
|
268
290
|
}
|
|
269
291
|
else {
|
|
270
|
-
this.select("Choisissez une sauvegarde", "De quelle sauvegarde souhaitez-vous reprendre ?", choices, "Annuler", () => {
|
|
292
|
+
this.select("Choisissez une sauvegarde", "De quelle sauvegarde souhaitez-vous reprendre ?", choices, "Annuler", () => {
|
|
293
|
+
promise.resolve(null);
|
|
294
|
+
});
|
|
271
295
|
}
|
|
272
296
|
return await promise.promise;
|
|
273
297
|
}
|
|
@@ -286,7 +310,7 @@ export class GUIBase {
|
|
|
286
310
|
var _a;
|
|
287
311
|
/* all errors redirected to notification system */
|
|
288
312
|
const onerror = this.notifyError.bind(this);
|
|
289
|
-
window.addEventListener(
|
|
313
|
+
window.addEventListener("error", onerror);
|
|
290
314
|
window.addEventListener("unhandledrejection", onerror);
|
|
291
315
|
console.error = (message) => onerror(new Error(message));
|
|
292
316
|
await this._loadExtensions();
|
|
@@ -321,7 +345,9 @@ export class GUIBase {
|
|
|
321
345
|
/**
|
|
322
346
|
* Get mode as a string (dark/light).
|
|
323
347
|
*/
|
|
324
|
-
async theme() {
|
|
348
|
+
async theme() {
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
325
351
|
/**
|
|
326
352
|
* Restart the kernel.
|
|
327
353
|
*/
|
|
@@ -339,7 +365,7 @@ export class GUIBase {
|
|
|
339
365
|
let promises = [];
|
|
340
366
|
for (let fileURL of url.searchParams.getAll(key)) {
|
|
341
367
|
fileURL = decodeURIComponent(fileURL);
|
|
342
|
-
const filename = fileURL.split(
|
|
368
|
+
const filename = fileURL.split("/").pop() || "";
|
|
343
369
|
promises.push((async () => {
|
|
344
370
|
var _a;
|
|
345
371
|
let data;
|
|
@@ -379,7 +405,7 @@ export class GUIBase {
|
|
|
379
405
|
async loadURLAux() {
|
|
380
406
|
if (this.kernelSafe == null)
|
|
381
407
|
return;
|
|
382
|
-
await this._loadFromURL(
|
|
408
|
+
await this._loadFromURL("aux", this.kernelSafe.putFile.bind(this.kernelSafe));
|
|
383
409
|
}
|
|
384
410
|
/**
|
|
385
411
|
* Load modules submited via URL (module= parameter) (async).
|
|
@@ -387,7 +413,7 @@ export class GUIBase {
|
|
|
387
413
|
async loadURLModules() {
|
|
388
414
|
if (this.kernelSafe == null)
|
|
389
415
|
return;
|
|
390
|
-
await this._loadFromURL(
|
|
416
|
+
await this._loadFromURL("module", this.kernelSafe.putModule.bind(this.kernelSafe));
|
|
391
417
|
}
|
|
392
418
|
/**
|
|
393
419
|
* Register an extension and its callback.
|
|
@@ -403,14 +429,14 @@ export class GUIBase {
|
|
|
403
429
|
*/
|
|
404
430
|
_openFile(callbacks) {
|
|
405
431
|
return new Promise((resolve, reject) => {
|
|
406
|
-
let input = document.createElement(
|
|
407
|
-
input.type =
|
|
432
|
+
let input = document.createElement("input");
|
|
433
|
+
input.type = "file";
|
|
408
434
|
input.style.display = "none";
|
|
409
435
|
input.onchange = async () => {
|
|
410
436
|
if (input.files == null)
|
|
411
437
|
return;
|
|
412
438
|
for (let file of input.files) {
|
|
413
|
-
const ext = file.name.split(
|
|
439
|
+
const ext = file.name.split(".").pop();
|
|
414
440
|
const callback = callbacks[ext !== null && ext !== void 0 ? ext : ""];
|
|
415
441
|
if (callback != null) {
|
|
416
442
|
await callback(file);
|
|
@@ -453,8 +479,11 @@ export class GUIBase {
|
|
|
453
479
|
try {
|
|
454
480
|
content = await this.deflate(content);
|
|
455
481
|
}
|
|
456
|
-
catch (e) {
|
|
457
|
-
|
|
482
|
+
catch (e) {
|
|
483
|
+
// fallback
|
|
484
|
+
content = encodeURIComponent(content)
|
|
485
|
+
.replace(/\(/g, "%28")
|
|
486
|
+
.replace(/\)/g, "%29");
|
|
458
487
|
}
|
|
459
488
|
url.searchParams.set(key, content);
|
|
460
489
|
return url.href;
|
|
@@ -510,7 +539,7 @@ Un lien permanant vers le contenu actuel a été créé.
|
|
|
510
539
|
// dynamic import for webpack
|
|
511
540
|
const pako = await import("pako");
|
|
512
541
|
const { Base64 } = await import("js-base64");
|
|
513
|
-
return pako.inflate(Base64.toUint8Array(content), { to:
|
|
542
|
+
return pako.inflate(Base64.toUint8Array(content), { to: "string" });
|
|
514
543
|
}
|
|
515
544
|
}
|
|
516
545
|
/**
|
|
@@ -524,32 +553,32 @@ GUIBase.copyToClipboard = function (text) {
|
|
|
524
553
|
let textArea = document.createElement("textarea");
|
|
525
554
|
// Precautions from https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript
|
|
526
555
|
// Place in top-left corner of screen regardless of scroll position.
|
|
527
|
-
textArea.style.position =
|
|
556
|
+
textArea.style.position = "fixed";
|
|
528
557
|
textArea.style.top = "0px";
|
|
529
558
|
textArea.style.left = "0px";
|
|
530
559
|
// Ensure it has a small width and height. Setting to 1px / 1em
|
|
531
560
|
// doesn't work as this gives a negative w/h on some browsers.
|
|
532
|
-
textArea.style.width =
|
|
533
|
-
textArea.style.height =
|
|
561
|
+
textArea.style.width = "2em";
|
|
562
|
+
textArea.style.height = "2em";
|
|
534
563
|
// We don't need padding, reducing the size if it does flash render.
|
|
535
564
|
textArea.style.padding = "0px";
|
|
536
565
|
// Clean up any borders.
|
|
537
|
-
textArea.style.border =
|
|
538
|
-
textArea.style.outline =
|
|
539
|
-
textArea.style.boxShadow =
|
|
566
|
+
textArea.style.border = "none";
|
|
567
|
+
textArea.style.outline = "none";
|
|
568
|
+
textArea.style.boxShadow = "none";
|
|
540
569
|
// Avoid flash of white box if rendered for any reason.
|
|
541
|
-
textArea.style.background =
|
|
570
|
+
textArea.style.background = "transparent";
|
|
542
571
|
textArea.value = text;
|
|
543
572
|
document.body.appendChild(textArea);
|
|
544
573
|
textArea.focus();
|
|
545
574
|
textArea.select();
|
|
546
575
|
try {
|
|
547
|
-
let successful = document.execCommand(
|
|
548
|
-
let msg = successful ?
|
|
549
|
-
console.log(
|
|
576
|
+
let successful = document.execCommand("copy");
|
|
577
|
+
let msg = successful ? "successful" : "unsuccessful";
|
|
578
|
+
console.log("Copying text command was " + msg);
|
|
550
579
|
}
|
|
551
580
|
catch (err) {
|
|
552
|
-
console.log(
|
|
581
|
+
console.log("Oops, unable to copy");
|
|
553
582
|
}
|
|
554
583
|
document.body.removeChild(textArea);
|
|
555
584
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@basthon/gui-base",
|
|
3
|
-
"version": "0.50.
|
|
3
|
+
"version": "0.50.17",
|
|
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.
|
|
29
|
-
"@basthon/kernel-base": "0.50.
|
|
30
|
-
"@basthon/kernel-loader": "0.50.
|
|
28
|
+
"@basthon/checkpoints": "0.50.17",
|
|
29
|
+
"@basthon/kernel-base": "0.50.17",
|
|
30
|
+
"@basthon/kernel-loader": "0.50.17",
|
|
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": "
|
|
44
|
+
"gitHead": "543c9b25b5711d5cb292c935a14255eec74ffd8c"
|
|
45
45
|
}
|