@basthon/gui-base 0.38.2 → 0.38.6

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,3 +1,4 @@
1
+ import { CheckpointsManager } from "@basthon/checkpoints";
1
2
  import { KernelBase } from "@basthon/kernel-base";
2
3
  import { KernelLoader } from "@basthon/kernel-loader";
3
4
  declare global {
@@ -9,6 +10,7 @@ export interface GUIOptions {
9
10
  kernelRootPath: string;
10
11
  language: string;
11
12
  uiName?: string;
13
+ noCheckpointsInit?: boolean;
12
14
  }
13
15
  /**
14
16
  * Base class for console and notebook GUI.
@@ -17,7 +19,7 @@ export declare class GUIBase {
17
19
  private readonly _language;
18
20
  private readonly _loaded;
19
21
  private _loader;
20
- private _checkpoints;
22
+ private _checkpoints?;
21
23
  private _maxCheckpoints;
22
24
  protected _contentFilename: string;
23
25
  protected _urlKey: string;
@@ -40,6 +42,11 @@ export declare class GUIBase {
40
42
  * Check if GUI is loaded.
41
43
  */
42
44
  loaded(): Promise<void>;
45
+ /**
46
+ * Set the checkpoints manager
47
+ * (typically use with GUIOptions.noCheckpointsInit set to true).
48
+ */
49
+ setCheckpointsManager(checkpoints: CheckpointsManager<string>): void;
43
50
  /**
44
51
  * Notify the user.
45
52
  */
@@ -70,11 +77,11 @@ export declare class GUIBase {
70
77
  /**
71
78
  * Get the content (script or notebook content).
72
79
  */
73
- protected content(): string;
80
+ content(): string;
74
81
  /**
75
82
  * Set the content (script or notebook content).
76
83
  */
77
- protected setContent(content: string): void;
84
+ setContent(content: string): void;
78
85
  /**
79
86
  * Loading the content from query string (ipynb=/script= or from=).
80
87
  */
@@ -90,11 +97,15 @@ export declare class GUIBase {
90
97
  /**
91
98
  * Load content from local forage.
92
99
  */
93
- protected loadFromStorage(): Promise<string | null>;
100
+ loadFromStorage(): Promise<string | null>;
94
101
  /**
95
102
  * Tag last backup as "approved".
96
103
  */
97
104
  validateBackup(): Promise<void>;
105
+ /**
106
+ * Is last backup tagged as "approved"?
107
+ */
108
+ lastBackupValid(): Promise<boolean | null | undefined>;
98
109
  /**
99
110
  * Select a checkpoint to load in the script.
100
111
  */
@@ -102,7 +113,7 @@ export declare class GUIBase {
102
113
  /**
103
114
  * Backup to checkpoints.
104
115
  */
105
- backup(approved?: boolean): Promise<string>;
116
+ backup(approved?: boolean): Promise<string | undefined>;
106
117
  /**
107
118
  * Internal GUI init.
108
119
  * It calls setupUI then loadInitialContent.
package/lib/main.js CHANGED
@@ -18,7 +18,8 @@ export class GUIBase {
18
18
  // loading Basthon (errors are fatal)
19
19
  this._loader.showLoader("Chargement de Basthon...", false, false);
20
20
  /* per language checkpoints */
21
- this._checkpoints = new CheckpointsManager(`${options.uiName}.${options.language}`, this._maxCheckpoints);
21
+ if (!options.noCheckpointsInit)
22
+ this._checkpoints = new CheckpointsManager(`${options.uiName}.${options.language}`, this._maxCheckpoints);
22
23
  }
23
24
  /**
24
25
  * Language getter.
@@ -37,6 +38,13 @@ export class GUIBase {
37
38
  * Check if GUI is loaded.
38
39
  */
39
40
  async loaded() { await this._loaded.promise; }
41
+ /**
42
+ * Set the checkpoints manager
43
+ * (typically use with GUIOptions.noCheckpointsInit set to true).
44
+ */
45
+ setCheckpointsManager(checkpoints) {
46
+ this._checkpoints = checkpoints;
47
+ }
40
48
  /**
41
49
  * Notify the user.
42
50
  */
@@ -165,13 +173,14 @@ export class GUIBase {
165
173
  * Load content from local forage.
166
174
  */
167
175
  async loadFromStorage() {
168
- const approved = await this._checkpoints.lastHasTag("approved");
176
+ var _a;
177
+ const approved = await this.lastBackupValid();
169
178
  let content = null;
170
179
  if (approved == null) {
171
180
  content = null;
172
181
  }
173
182
  else if (approved) {
174
- content = await this._checkpoints.getLast();
183
+ content = await ((_a = this._checkpoints) === null || _a === void 0 ? void 0 : _a.getLast());
175
184
  }
176
185
  else {
177
186
  const promise = new PromiseDelegate();
@@ -188,17 +197,26 @@ export class GUIBase {
188
197
  * Tag last backup as "approved".
189
198
  */
190
199
  async validateBackup() {
191
- await this._checkpoints.tagLast("approved");
200
+ var _a;
201
+ await ((_a = this._checkpoints) === null || _a === void 0 ? void 0 : _a.tagLast("approved"));
202
+ }
203
+ /**
204
+ * Is last backup tagged as "approved"?
205
+ */
206
+ async lastBackupValid() {
207
+ var _a;
208
+ return await ((_a = this._checkpoints) === null || _a === void 0 ? void 0 : _a.lastHasTag("approved"));
192
209
  }
193
210
  /**
194
211
  * Select a checkpoint to load in the script.
195
212
  */
196
213
  async selectCheckpoint() {
197
- const times = await this._checkpoints.times();
214
+ var _a;
215
+ const times = await ((_a = this._checkpoints) === null || _a === void 0 ? void 0 : _a.times());
198
216
  const promise = new PromiseDelegate();
199
217
  const choices = times === null || times === void 0 ? void 0 : times.map((t, i) => ({
200
218
  text: CheckpointsManager.toHumanDate(parseInt(t, 10)),
201
- handler: async () => { var _a; promise.resolve((_a = (await this._checkpoints.getIndex(i))) !== null && _a !== void 0 ? _a : null); }
219
+ handler: async () => { var _a, _b; promise.resolve((_b = (await ((_a = this._checkpoints) === null || _a === void 0 ? void 0 : _a.getIndex(i)))) !== null && _b !== void 0 ? _b : null); }
202
220
  }));
203
221
  if (choices == null)
204
222
  return null;
@@ -209,19 +227,21 @@ export class GUIBase {
209
227
  * Backup to checkpoints.
210
228
  */
211
229
  async backup(approved = true) {
212
- return await this._checkpoints.push(this.content(), approved ? ["approved"] : []);
230
+ var _a;
231
+ return await ((_a = this._checkpoints) === null || _a === void 0 ? void 0 : _a.push(this.content(), approved ? ["approved"] : []));
213
232
  }
214
233
  /**
215
234
  * Internal GUI init.
216
235
  * It calls setupUI then loadInitialContent.
217
236
  */
218
237
  async _init(options = null) {
238
+ var _a;
219
239
  /* all errors redirected to notification system */
220
240
  const onerror = this.notifyError.bind(this);
221
241
  window.addEventListener('error', onerror);
222
242
  window.addEventListener("unhandledrejection", onerror);
223
243
  console.error = (message) => onerror(new ErrorEvent(message, { message: message }));
224
- await this._checkpoints.ready();
244
+ await ((_a = this._checkpoints) === null || _a === void 0 ? void 0 : _a.ready());
225
245
  await this.setupUI(options);
226
246
  await this.loadInitialContent(options);
227
247
  await this.kernelLoader.kernelLoaded();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basthon/gui-base",
3
- "version": "0.38.2",
3
+ "version": "0.38.6",
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.38.2",
29
- "@basthon/kernel-base": "^0.38.2",
30
- "@basthon/kernel-loader": "^0.38.2",
28
+ "@basthon/checkpoints": "^0.38.6",
29
+ "@basthon/kernel-base": "^0.38.6",
30
+ "@basthon/kernel-loader": "^0.38.6",
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": "df6a3eb261122c31b25c971e1d97e442054432cd"
44
+ "gitHead": "1598210257bd6c9be809971802a41134835d1cf9"
45
45
  }