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) => {
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} didnt 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.djkmkn674mo",
},
],
{}
);
workbox.precacheAndRoute([{
"url": "registerSW.js",
"revision": "3ca0b8505b4bec776b69afdba2768812"
}, {
"url": "index.html",
"revision": "0.93gcaii03k8"
}], {});
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

View File

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

View File

@ -30,7 +30,7 @@ const vitePWAconfiguration = {
workbox: {
sourcemap: 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 :)
runtimeCaching: [
{