Fixing universe save/load logic
This commit is contained in:
110
dev-dist/sw.js
110
dev-dist/sw.js
@ -21,20 +21,22 @@ if (!self.define) {
|
||||
|
||||
const singleRequire = (uri, parentUri) => {
|
||||
uri = new URL(uri + ".js", parentUri).href;
|
||||
return (
|
||||
registry[uri] ||
|
||||
new Promise((resolve) => {
|
||||
if ("document" in self) {
|
||||
const script = document.createElement("script");
|
||||
script.src = uri;
|
||||
script.onload = resolve;
|
||||
document.head.appendChild(script);
|
||||
} else {
|
||||
nextDefineUri = uri;
|
||||
importScripts(uri);
|
||||
resolve();
|
||||
}
|
||||
}).then(() => {
|
||||
return registry[uri] || (
|
||||
|
||||
new Promise(resolve => {
|
||||
if ("document" in self) {
|
||||
const script = document.createElement("script");
|
||||
script.src = uri;
|
||||
script.onload = resolve;
|
||||
document.head.appendChild(script);
|
||||
} else {
|
||||
nextDefineUri = uri;
|
||||
importScripts(uri);
|
||||
resolve();
|
||||
}
|
||||
})
|
||||
|
||||
.then(() => {
|
||||
let promise = registry[uri];
|
||||
if (!promise) {
|
||||
throw new Error(`Module ${uri} didn’t register its module`);
|
||||
@ -45,31 +47,27 @@ if (!self.define) {
|
||||
};
|
||||
|
||||
self.define = (depsNames, factory) => {
|
||||
const uri =
|
||||
nextDefineUri ||
|
||||
("document" in self ? document.currentScript.src : "") ||
|
||||
location.href;
|
||||
const uri = nextDefineUri || ("document" in self ? document.currentScript.src : "") || location.href;
|
||||
if (registry[uri]) {
|
||||
// Module is already loading or loaded.
|
||||
return;
|
||||
}
|
||||
let exports = {};
|
||||
const require = (depUri) => singleRequire(depUri, uri);
|
||||
const require = depUri => singleRequire(depUri, uri);
|
||||
const specialDeps = {
|
||||
module: { uri },
|
||||
exports,
|
||||
require,
|
||||
require
|
||||
};
|
||||
registry[uri] = Promise.all(
|
||||
depsNames.map((depName) => specialDeps[depName] || require(depName))
|
||||
).then((deps) => {
|
||||
registry[uri] = Promise.all(depsNames.map(
|
||||
depName => specialDeps[depName] || require(depName)
|
||||
)).then(deps => {
|
||||
factory(...deps);
|
||||
return exports;
|
||||
});
|
||||
};
|
||||
}
|
||||
define(["./workbox-b7fccfec"], function (workbox) {
|
||||
"use strict";
|
||||
define(['./workbox-b7fccfec'], (function (workbox) { 'use strict';
|
||||
|
||||
self.skipWaiting();
|
||||
workbox.clientsClaim();
|
||||
@ -79,44 +77,28 @@ define(["./workbox-b7fccfec"], function (workbox) {
|
||||
* requests for URLs in the manifest.
|
||||
* See https://goo.gl/S9QRab
|
||||
*/
|
||||
workbox.precacheAndRoute(
|
||||
[
|
||||
{
|
||||
url: "registerSW.js",
|
||||
revision: "3ca0b8505b4bec776b69afdba2768812",
|
||||
},
|
||||
{
|
||||
url: "index.html",
|
||||
revision: "0.0ufj7f4tmog",
|
||||
},
|
||||
],
|
||||
{}
|
||||
);
|
||||
workbox.precacheAndRoute([{
|
||||
"url": "registerSW.js",
|
||||
"revision": "3ca0b8505b4bec776b69afdba2768812"
|
||||
}, {
|
||||
"url": "index.html",
|
||||
"revision": "0.fnf2e5c80tg"
|
||||
}], {});
|
||||
workbox.cleanupOutdatedCaches();
|
||||
workbox.registerRoute(
|
||||
new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
|
||||
allowlist: [/^\/$/],
|
||||
})
|
||||
);
|
||||
workbox.registerRoute(
|
||||
({ url }) =>
|
||||
[
|
||||
/^https:\/\/raw\.githubusercontent\.com\/.*/i,
|
||||
/^https:\/\/shabda\.ndre\.gr\/.*/i,
|
||||
].some((regex) => regex.test(url)),
|
||||
new workbox.CacheFirst({
|
||||
cacheName: "external-samples",
|
||||
plugins: [
|
||||
new workbox.ExpirationPlugin({
|
||||
maxEntries: 5000,
|
||||
maxAgeSeconds: 2592000,
|
||||
}),
|
||||
new workbox.CacheableResponsePlugin({
|
||||
statuses: [0, 200],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
"GET"
|
||||
);
|
||||
});
|
||||
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
|
||||
allowlist: [/^\/$/]
|
||||
}));
|
||||
workbox.registerRoute(({
|
||||
url
|
||||
}) => [/^https:\/\/raw\.githubusercontent\.com\/.*/i, /^https:\/\/shabda\.ndre\.gr\/.*/i].some(regex => regex.test(url)), new workbox.CacheFirst({
|
||||
"cacheName": "external-samples",
|
||||
plugins: [new workbox.ExpirationPlugin({
|
||||
maxEntries: 5000,
|
||||
maxAgeSeconds: 2592000
|
||||
}), new workbox.CacheableResponsePlugin({
|
||||
statuses: [0, 200]
|
||||
})]
|
||||
}), 'GET');
|
||||
|
||||
}));
|
||||
//# sourceMappingURL=sw.js.map
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -78,12 +78,18 @@ export class UserAPI {
|
||||
}
|
||||
|
||||
_loadUniverseFromInterface = (universe: string) => {
|
||||
this.app.selected_universe = universe.trim();
|
||||
this.app.settings.selected_universe = universe.trim();
|
||||
loadUniverse(this.app, universe as string);
|
||||
openUniverseModal();
|
||||
};
|
||||
|
||||
_deleteUniverseFromInterface = (universe: string) => {
|
||||
delete this.app.universes[universe];
|
||||
if (this.app.settings.selected_universe === universe) {
|
||||
this.app.settings.selected_universe = "Welcome";
|
||||
this.app.selected_universe = "Welcome";
|
||||
}
|
||||
this.app.settings.saveApplicationToLocalStorage(
|
||||
this.app.universes,
|
||||
this.app.settings
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { tutorial_universe } from "./universes/tutorial";
|
||||
// import { tutorial_universe } from "./universes/tutorial";
|
||||
import { gzipSync, decompressSync, strFromU8 } from "fflate";
|
||||
import { examples } from "./examples/excerpts";
|
||||
import { type Editor } from "./main";
|
||||
@ -109,7 +109,7 @@ export const template_universes = {
|
||||
example: { candidate: "", committed: "", evaluations: 0 },
|
||||
notes: { candidate: "" },
|
||||
},
|
||||
Help: tutorial_universe,
|
||||
//Help: tutorial_universe,
|
||||
};
|
||||
|
||||
export class AppSettings {
|
||||
@ -247,13 +247,21 @@ export const initializeSelectedUniverse = (app: Editor): void => {
|
||||
*/
|
||||
if (app.settings.load_demo_songs) {
|
||||
let random_example = examples[Math.floor(Math.random() * examples.length)];
|
||||
app.selected_universe = "Welcome";
|
||||
app.selected_universe = "Demo";
|
||||
app.universes[app.selected_universe] = structuredClone(template_universe);
|
||||
app.universes[app.selected_universe].global.committed = random_example;
|
||||
app.universes[app.selected_universe].global.candidate = random_example;
|
||||
} else {
|
||||
app.selected_universe = app.settings.selected_universe;
|
||||
if (app.universes[app.selected_universe] === undefined)
|
||||
try {
|
||||
app.selected_universe = app.settings.selected_universe;
|
||||
if (app.universes[app.selected_universe] === undefined)
|
||||
app.universes[app.selected_universe] =
|
||||
structuredClone(template_universe);
|
||||
} catch (error) {
|
||||
app.settings.selected_universe = "Welcome";
|
||||
app.selected_universe = app.settings.selected_universe;
|
||||
app.universes[app.selected_universe] = structuredClone(template_universe);
|
||||
}
|
||||
}
|
||||
app.interface.universe_viewer.innerHTML = `Topos: ${app.selected_universe}`;
|
||||
};
|
||||
@ -315,22 +323,20 @@ export const loadUniverse = (
|
||||
universeName: string,
|
||||
universe: Universe = template_universe
|
||||
): void => {
|
||||
console.log(universeName, universe);
|
||||
app.currentFile().candidate = app.view.state.doc.toString();
|
||||
|
||||
// Getting the new universe name and moving on
|
||||
let selectedUniverse = universeName.trim();
|
||||
if (app.universes[selectedUniverse] === undefined) {
|
||||
app.settings.universes[selectedUniverse] = universe;
|
||||
app.universes[selectedUniverse] = universe;
|
||||
// Pushing a freshly cloned template universe to:
|
||||
// 1) the current session 2) the settings
|
||||
const freshUniverse = structuredClone(universe);
|
||||
app.universes[selectedUniverse] = freshUniverse;
|
||||
app.settings.universes[selectedUniverse] = freshUniverse;
|
||||
}
|
||||
// Updating references to the currently selected universe
|
||||
app.settings.selected_universe = selectedUniverse;
|
||||
app.selected_universe = selectedUniverse;
|
||||
app.settings.selected_universe = app.selected_universe;
|
||||
app.interface.universe_viewer.innerHTML = `Topos: ${selectedUniverse}`;
|
||||
|
||||
// Updating the editor View to reflect the selected universe
|
||||
app.updateEditorView();
|
||||
|
||||
// Evaluating the initialisation script for the selected universe
|
||||
tryEvaluate(app, app.universes[app.selected_universe.toString()].init);
|
||||
};
|
||||
|
||||
@ -23,6 +23,7 @@ import { inlineHoveringTips } from "./documentation/inlineHelp";
|
||||
import { lineNumbers } from "@codemirror/view";
|
||||
import { jsCompletions } from "./EditorSetup";
|
||||
import { createDocumentationStyle } from "./DomElements";
|
||||
import { saveState } from "./WindowBehavior";
|
||||
|
||||
export const installInterfaceLogic = (app: Editor) => {
|
||||
// Initialize style
|
||||
@ -184,8 +185,8 @@ export const installInterfaceLogic = (app: Editor) => {
|
||||
app.interface.load_universe_button.addEventListener("click", () => {
|
||||
let query = (app.interface.buffer_search as HTMLInputElement).value;
|
||||
if (query.length > 2 && query.length < 20 && !query.includes(" ")) {
|
||||
loadUniverse(app, query);
|
||||
app.settings.selected_universe = query;
|
||||
loadUniverse(app, query);
|
||||
(app.interface.buffer_search as HTMLInputElement).value = "";
|
||||
closeUniverseModal();
|
||||
app.view.focus();
|
||||
@ -336,6 +337,7 @@ export const installInterfaceLogic = (app: Editor) => {
|
||||
});
|
||||
|
||||
app.interface.close_universes_button.addEventListener("click", () => {
|
||||
saveState(app);
|
||||
openUniverseModal();
|
||||
});
|
||||
|
||||
@ -443,8 +445,10 @@ export const installInterfaceLogic = (app: Editor) => {
|
||||
|
||||
if (universeName) {
|
||||
if (universeName.length > 2 && universeName.length < 20) {
|
||||
loadUniverse(app, universeName);
|
||||
universeName = universeName.trim();
|
||||
app.settings.selected_universe = universeName;
|
||||
app.selected_universe = universeName;
|
||||
loadUniverse(app, universeName);
|
||||
(app.interface.buffer_search as HTMLInputElement).value = "";
|
||||
closeUniverseModal();
|
||||
app.view.focus();
|
||||
|
||||
@ -68,22 +68,4 @@ export const installWindowBehaviors = (
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
window.addEventListener(
|
||||
"error",
|
||||
(e) => {
|
||||
console.log("Je suis bien installé !");
|
||||
console.log(
|
||||
e.message,
|
||||
"\n",
|
||||
e.filename,
|
||||
":",
|
||||
e.lineno,
|
||||
e.colno ? ":" + e.colno : "",
|
||||
e.error && e.error.stack ? "\n" : "",
|
||||
e.error ? e.error.stack : undefined
|
||||
);
|
||||
},
|
||||
false
|
||||
);
|
||||
};
|
||||
|
||||
@ -20,7 +20,7 @@ import * as oeis from "jisg";
|
||||
import * as zpatterns from "zifferjs/src/patterns.ts";
|
||||
import { makeArrayExtensions } from "./extensions/ArrayExtensions";
|
||||
import "./style.css";
|
||||
import { Universes, File, template_universes } from "./FileManagement";
|
||||
import { Universes, File } from "./FileManagement";
|
||||
import { tryEvaluate } from "./Evaluator";
|
||||
// @ts-ignore
|
||||
import showdown from "showdown";
|
||||
@ -39,7 +39,7 @@ if ("serviceWorker" in navigator) {
|
||||
export class Editor {
|
||||
// Universes and settings
|
||||
settings: AppSettings = new AppSettings();
|
||||
universes: Universes = template_universes;
|
||||
universes: Universes = {};
|
||||
selected_universe: string = "Welcome";
|
||||
|
||||
fill: boolean = false;
|
||||
@ -115,7 +115,7 @@ export class Editor {
|
||||
|
||||
this.universes = {
|
||||
...this.settings.universes,
|
||||
...template_universes,
|
||||
//...template_universes,
|
||||
};
|
||||
initializeSelectedUniverse(this);
|
||||
|
||||
@ -237,7 +237,7 @@ export class Editor {
|
||||
list.append(
|
||||
...Object.keys(this.universes).map((it) => {
|
||||
let item = itemTemplate.content.cloneNode(true) as DocumentFragment;
|
||||
let api = window as unknown as UserAPI; // It's dirty but okey
|
||||
let api = window as unknown as UserAPI;
|
||||
item.querySelector(".universe-name")!.textContent = it;
|
||||
item
|
||||
.querySelector(".load-universe")
|
||||
|
||||
@ -61,7 +61,7 @@ const init_buffer = `// ,,
|
||||
// be available from the start. It is only executed once, so if you want to change something, you need to
|
||||
// reload the universe or force the reloading: Ctrl+Shift+Enter.
|
||||
|
||||
bpm(140) // set the bpm to 140
|
||||
tempo(140) // set the bpm to 140
|
||||
`;
|
||||
|
||||
const note_buffer = `# Notes
|
||||
|
||||
@ -28,9 +28,11 @@ const vitePWAconfiguration = {
|
||||
enabled: true,
|
||||
},
|
||||
workbox: {
|
||||
sourcemap: true,
|
||||
sourcemap: false,
|
||||
cleanupOutdatedCaches: true,
|
||||
globPatterns: ["**/*.{js,css,html,gif,png,json,woff,json,ogg,wav,mp3,ico,png,svg}"],
|
||||
globPatterns: [
|
||||
"**/*.{js,css,html,gif,png,json,woff,json,ogg,wav,mp3,ico,png,svg}",
|
||||
],
|
||||
// Thanks Froos :)
|
||||
runtimeCaching: [
|
||||
{
|
||||
@ -39,9 +41,9 @@ const vitePWAconfiguration = {
|
||||
/^https:\/\/raw\.githubusercontent\.com\/.*/i,
|
||||
/^https:\/\/shabda\.ndre\.gr\/.*/i,
|
||||
].some((regex) => regex.test(url)),
|
||||
handler: 'CacheFirst',
|
||||
handler: "CacheFirst",
|
||||
options: {
|
||||
cacheName: 'external-samples',
|
||||
cacheName: "external-samples",
|
||||
expiration: {
|
||||
maxEntries: 5000,
|
||||
maxAgeSeconds: 60 * 60 * 24 * 30, // <== 14 days
|
||||
|
||||
Reference in New Issue
Block a user