fixing some bug caused by lazyness

This commit is contained in:
2023-11-13 00:27:09 +01:00
parent a2dcfbad7d
commit 32f6d2cbf2
4 changed files with 52 additions and 70 deletions

View File

@ -21,20 +21,22 @@ if (!self.define) {
const singleRequire = (uri, parentUri) => { const singleRequire = (uri, parentUri) => {
uri = new URL(uri + ".js", parentUri).href; uri = new URL(uri + ".js", parentUri).href;
return ( return registry[uri] || (
registry[uri] ||
new Promise((resolve) => { new Promise(resolve => {
if ("document" in self) { if ("document" in self) {
const script = document.createElement("script"); const script = document.createElement("script");
script.src = uri; script.src = uri;
script.onload = resolve; script.onload = resolve;
document.head.appendChild(script); document.head.appendChild(script);
} else { } else {
nextDefineUri = uri; nextDefineUri = uri;
importScripts(uri); importScripts(uri);
resolve(); resolve();
} }
}).then(() => { })
.then(() => {
let promise = registry[uri]; let promise = registry[uri];
if (!promise) { if (!promise) {
throw new Error(`Module ${uri} didnt register its module`); throw new Error(`Module ${uri} didnt register its module`);
@ -45,31 +47,27 @@ if (!self.define) {
}; };
self.define = (depsNames, factory) => { self.define = (depsNames, factory) => {
const uri = const uri = nextDefineUri || ("document" in self ? document.currentScript.src : "") || location.href;
nextDefineUri ||
("document" in self ? document.currentScript.src : "") ||
location.href;
if (registry[uri]) { if (registry[uri]) {
// Module is already loading or loaded. // Module is already loading or loaded.
return; return;
} }
let exports = {}; let exports = {};
const require = (depUri) => singleRequire(depUri, uri); const require = depUri => singleRequire(depUri, uri);
const specialDeps = { const specialDeps = {
module: { uri }, module: { uri },
exports, exports,
require, require
}; };
registry[uri] = Promise.all( registry[uri] = Promise.all(depsNames.map(
depsNames.map((depName) => specialDeps[depName] || require(depName)) depName => specialDeps[depName] || require(depName)
).then((deps) => { )).then(deps => {
factory(...deps); factory(...deps);
return exports; return exports;
}); });
}; };
} }
define(["./workbox-b7fccfec"], function (workbox) { define(['./workbox-b7fccfec'], (function (workbox) { 'use strict';
"use strict";
self.skipWaiting(); self.skipWaiting();
workbox.clientsClaim(); workbox.clientsClaim();
@ -79,44 +77,28 @@ define(["./workbox-b7fccfec"], function (workbox) {
* requests for URLs in the manifest. * requests for URLs in the manifest.
* See https://goo.gl/S9QRab * See https://goo.gl/S9QRab
*/ */
workbox.precacheAndRoute( workbox.precacheAndRoute([{
[ "url": "registerSW.js",
{ "revision": "3ca0b8505b4bec776b69afdba2768812"
url: "registerSW.js", }, {
revision: "3ca0b8505b4bec776b69afdba2768812", "url": "index.html",
}, "revision": "0.93gcaii03k8"
{ }], {});
url: "index.html",
revision: "0.djkmkn674mo",
},
],
{}
);
workbox.cleanupOutdatedCaches(); workbox.cleanupOutdatedCaches();
workbox.registerRoute( workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), { allowlist: [/^\/$/]
allowlist: [/^\/$/], }));
}) workbox.registerRoute(({
); url
workbox.registerRoute( }) => [/^https:\/\/raw\.githubusercontent\.com\/.*/i, /^https:\/\/shabda\.ndre\.gr\/.*/i].some(regex => regex.test(url)), new workbox.CacheFirst({
({ url }) => "cacheName": "external-samples",
[ plugins: [new workbox.ExpirationPlugin({
/^https:\/\/raw\.githubusercontent\.com\/.*/i, maxEntries: 5000,
/^https:\/\/shabda\.ndre\.gr\/.*/i, maxAgeSeconds: 2592000
].some((regex) => regex.test(url)), }), new workbox.CacheableResponsePlugin({
new workbox.CacheFirst({ statuses: [0, 200]
cacheName: "external-samples", })]
plugins: [ }), 'GET');
new workbox.ExpirationPlugin({
maxEntries: 5000, }));
maxAgeSeconds: 2592000,
}),
new workbox.CacheableResponsePlugin({
statuses: [0, 200],
}),
],
}),
"GET"
);
});
//# sourceMappingURL=sw.js.map //# sourceMappingURL=sw.js.map

File diff suppressed because one or more lines are too long

View File

@ -17,8 +17,6 @@ const handleResize = (canvas: HTMLCanvasElement) => {
}; };
export const saveBeforeExit = (app: Editor): null => { export const saveBeforeExit = (app: Editor): null => {
// @ts-ignore
event.preventDefault();
// Iterate over all local files and set the candidate to the committed // Iterate over all local files and set the candidate to the committed
app.currentFile().candidate = app.view.state.doc.toString(); app.currentFile().candidate = app.view.state.doc.toString();
app.currentFile().committed = app.view.state.doc.toString(); app.currentFile().committed = app.view.state.doc.toString();
@ -38,10 +36,12 @@ export const installWindowBehaviors = (
window.addEventListener("resize", () => window.addEventListener("resize", () =>
handleResize(app.interface.feedback as HTMLCanvasElement) handleResize(app.interface.feedback as HTMLCanvasElement)
); );
window.addEventListener("beforeunload", () => { window.addEventListener("beforeunload", (event) => {
event.preventDefault()
saveBeforeExit(app) saveBeforeExit(app)
}); });
window.addEventListener("visibilitychange", () => { window.addEventListener("visibilitychange", (event) => {
event.preventDefault();
saveBeforeExit(app) saveBeforeExit(app)
}); });

View File

@ -30,7 +30,7 @@ const vitePWAconfiguration = {
workbox: { workbox: {
sourcemap: true, sourcemap: true,
cleanupOutdatedCaches: true, cleanupOutdatedCaches: true,
globPatterns: ["**/*.{js,css,html,json,ogg,wav,mp3,ico,png,svg}"], globPatterns: ["**/*.{js,css,html,gif,png,json,woff,json,ogg,wav,mp3,ico,png,svg}"],
// Thanks Froos :) // Thanks Froos :)
runtimeCaching: [ runtimeCaching: [
{ {