This commit is contained in:
2023-11-13 02:01:23 +02:00
5 changed files with 45 additions and 7 deletions

3
.gitignore vendored
View File

@ -42,4 +42,5 @@ yarn.lock
.DS_Store
.vs
.vs
dev-dist/**/*

View File

@ -36,6 +36,22 @@ if (!self.define) {
}
})
.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) {
@ -54,11 +70,15 @@ if (!self.define) {
}
let exports = {};
const require = depUri => singleRequire(depUri, uri);
const require = depUri => singleRequire(depUri, uri);
const specialDeps = {
module: { uri },
exports,
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 => {
@ -67,6 +87,7 @@ if (!self.define) {
});
};
}
define(['./workbox-b7fccfec'], (function (workbox) { 'use strict';
define(['./workbox-b7fccfec'], (function (workbox) { 'use strict';
self.skipWaiting();
@ -100,5 +121,21 @@ define(['./workbox-b7fccfec'], (function (workbox) { 'use strict';
})]
}), '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: [
{