Fix nasty auto-save bug
This commit is contained in:
@ -36,22 +36,6 @@ 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(() => {
|
.then(() => {
|
||||||
let promise = registry[uri];
|
let promise = registry[uri];
|
||||||
if (!promise) {
|
if (!promise) {
|
||||||
@ -70,15 +54,11 @@ if (!self.define) {
|
|||||||
}
|
}
|
||||||
let exports = {};
|
let exports = {};
|
||||||
const require = depUri => singleRequire(depUri, uri);
|
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(depsNames.map(
|
|
||||||
depName => specialDeps[depName] || require(depName)
|
|
||||||
)).then(deps => {
|
|
||||||
registry[uri] = Promise.all(depsNames.map(
|
registry[uri] = Promise.all(depsNames.map(
|
||||||
depName => specialDeps[depName] || require(depName)
|
depName => specialDeps[depName] || require(depName)
|
||||||
)).then(deps => {
|
)).then(deps => {
|
||||||
@ -87,7 +67,6 @@ if (!self.define) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
define(['./workbox-b7fccfec'], (function (workbox) { 'use strict';
|
|
||||||
define(['./workbox-b7fccfec'], (function (workbox) { 'use strict';
|
define(['./workbox-b7fccfec'], (function (workbox) { 'use strict';
|
||||||
|
|
||||||
self.skipWaiting();
|
self.skipWaiting();
|
||||||
@ -103,7 +82,7 @@ define(['./workbox-b7fccfec'], (function (workbox) { 'use strict';
|
|||||||
"revision": "3ca0b8505b4bec776b69afdba2768812"
|
"revision": "3ca0b8505b4bec776b69afdba2768812"
|
||||||
}, {
|
}, {
|
||||||
"url": "index.html",
|
"url": "index.html",
|
||||||
"revision": "0.93gcaii03k8"
|
"revision": "0.0ufj7f4tmog"
|
||||||
}], {});
|
}], {});
|
||||||
workbox.cleanupOutdatedCaches();
|
workbox.cleanupOutdatedCaches();
|
||||||
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
|
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
|
||||||
@ -121,21 +100,5 @@ define(['./workbox-b7fccfec'], (function (workbox) { 'use strict';
|
|||||||
})]
|
})]
|
||||||
}), 'GET');
|
}), '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
|
//# sourceMappingURL=sw.js.map
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -1322,6 +1322,12 @@ export class UserAPI {
|
|||||||
return results.some((value) => value === true);
|
return results.some((value) => value === true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public dur = (n: number | number[]): boolean => {
|
||||||
|
let nums: number[] = Array.isArray(n) ? n : [n];
|
||||||
|
// @ts-ignore
|
||||||
|
return this.beat(nums.dur(...nums));
|
||||||
|
};
|
||||||
|
|
||||||
// =============================================================
|
// =============================================================
|
||||||
// Modulo based time filters
|
// Modulo based time filters
|
||||||
// =============================================================
|
// =============================================================
|
||||||
|
|||||||
@ -16,6 +16,11 @@ const handleResize = (canvas: HTMLCanvasElement) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const saveState = (app: Editor): null => {
|
||||||
|
app.settings.saveApplicationToLocalStorage(app.universes, app.settings);
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
export const saveBeforeExit = (app: Editor): null => {
|
export const saveBeforeExit = (app: Editor): null => {
|
||||||
// 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();
|
||||||
@ -29,7 +34,6 @@ export const installWindowBehaviors = (
|
|||||||
window: Window,
|
window: Window,
|
||||||
preventMultipleTabs: boolean = false
|
preventMultipleTabs: boolean = false
|
||||||
) => {
|
) => {
|
||||||
|
|
||||||
window.addEventListener("resize", () =>
|
window.addEventListener("resize", () =>
|
||||||
handleResize(app.interface.scope as HTMLCanvasElement)
|
handleResize(app.interface.scope as HTMLCanvasElement)
|
||||||
);
|
);
|
||||||
@ -37,12 +41,12 @@ export const installWindowBehaviors = (
|
|||||||
handleResize(app.interface.feedback as HTMLCanvasElement)
|
handleResize(app.interface.feedback as HTMLCanvasElement)
|
||||||
);
|
);
|
||||||
window.addEventListener("beforeunload", (event) => {
|
window.addEventListener("beforeunload", (event) => {
|
||||||
event.preventDefault()
|
event.preventDefault();
|
||||||
saveBeforeExit(app)
|
saveBeforeExit(app);
|
||||||
});
|
});
|
||||||
window.addEventListener("visibilitychange", (event) => {
|
window.addEventListener("visibilitychange", (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
saveBeforeExit(app)
|
saveBeforeExit(app);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (preventMultipleTabs) {
|
if (preventMultipleTabs) {
|
||||||
@ -65,11 +69,21 @@ export const installWindowBehaviors = (
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('error', e => {
|
window.addEventListener(
|
||||||
console.log("Je suis bien installé !")
|
"error",
|
||||||
console.log(e.message
|
(e) => {
|
||||||
, '\n', e.filename, ':', e.lineno, (e.colno ? ':' + e.colno : '')
|
console.log("Je suis bien installé !");
|
||||||
, e.error && e.error.stack ? '\n' : '', e.error ? e.error.stack : undefined
|
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
|
||||||
);
|
);
|
||||||
}, false);
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -8,8 +8,8 @@ declare global {
|
|||||||
sub(amount: number): number[];
|
sub(amount: number): number[];
|
||||||
mult(amount: number): number[];
|
mult(amount: number): number[];
|
||||||
div(amount: number): number[];
|
div(amount: number): number[];
|
||||||
mouseX(): T[],
|
mouseX(): T[];
|
||||||
mouseY(): T[],
|
mouseY(): T[];
|
||||||
palindrome(): T[];
|
palindrome(): T[];
|
||||||
random(index: number): T;
|
random(index: number): T;
|
||||||
rand(index: number): T;
|
rand(index: number): T;
|
||||||
@ -37,7 +37,6 @@ declare global {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const makeArrayExtensions = (api: UserAPI) => {
|
export const makeArrayExtensions = (api: UserAPI) => {
|
||||||
|
|
||||||
Array.prototype.mouseX = function <T>(this: T[]): T {
|
Array.prototype.mouseX = function <T>(this: T[]): T {
|
||||||
/**
|
/**
|
||||||
* @returns Value from list based on mouse X position
|
* @returns Value from list based on mouse X position
|
||||||
@ -171,46 +170,29 @@ export const makeArrayExtensions = (api: UserAPI) => {
|
|||||||
};
|
};
|
||||||
Array.prototype.b = Array.prototype.beat;
|
Array.prototype.b = Array.prototype.beat;
|
||||||
|
|
||||||
// Array.prototype.dur = function(...durations) {
|
|
||||||
// const timepos = api.app.clock.pulses_since_origin;
|
|
||||||
// const ppqn = api.ppqn();
|
|
||||||
// let adjustedDurations = [];
|
|
||||||
// for (let i = 0; i < this.length; i++) {
|
|
||||||
// adjustedDurations.push(durations[i % durations.length]);
|
|
||||||
// }
|
|
||||||
// let cumulativeDuration = 0;
|
|
||||||
// let totalDuration = adjustedDurations.reduce((acc, duration) => acc + duration * ppqn, 0);
|
|
||||||
// let modulatedTimePos = timepos % totalDuration;
|
|
||||||
// for (let i = 0; i < this.length; i++) {
|
|
||||||
// const valueDuration = adjustedDurations[i] as any * ppqn;
|
|
||||||
// if (modulatedTimePos < cumulativeDuration + valueDuration) {
|
|
||||||
// return this[i];
|
|
||||||
// }
|
|
||||||
// cumulativeDuration += valueDuration;
|
|
||||||
// }
|
|
||||||
// // This point should not be reached if durations are correctly specified
|
|
||||||
// throw new Error('Durations array does not match the pattern length.');
|
|
||||||
// };
|
|
||||||
|
|
||||||
Array.prototype.dur = function (...durations) {
|
Array.prototype.dur = function (...durations) {
|
||||||
const timepos = api.app.clock.pulses_since_origin;
|
const timepos = api.app.clock.pulses_since_origin;
|
||||||
const ppqn = api.ppqn();
|
const ppqn = api.ppqn();
|
||||||
const adjustedDurations = this.map((_, index) => durations[index % durations.length]);
|
const adjustedDurations = this.map(
|
||||||
|
(_, index) => durations[index % durations.length]
|
||||||
|
);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const totalDurationInPulses = adjustedDurations.reduce((acc, duration) => acc + duration * ppqn, 0);
|
const totalDurationInPulses = adjustedDurations.reduce(
|
||||||
|
(acc, duration) => acc + duration * ppqn,
|
||||||
|
0
|
||||||
|
);
|
||||||
const loopPosition = timepos % totalDurationInPulses;
|
const loopPosition = timepos % totalDurationInPulses;
|
||||||
let cumulativeDuration = 0;
|
let cumulativeDuration = 0;
|
||||||
for (let i = 0; i < this.length; i++) {
|
for (let i = 0; i < this.length; i++) {
|
||||||
const valueDurationInPulses = adjustedDurations[i] as any * ppqn;
|
const valueDurationInPulses = (adjustedDurations[i] as any) * ppqn;
|
||||||
cumulativeDuration += valueDurationInPulses;
|
cumulativeDuration += valueDurationInPulses;
|
||||||
if (loopPosition < cumulativeDuration) {
|
if (loopPosition < cumulativeDuration) {
|
||||||
return this[i];
|
return this[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new Error('Durations array does not match the pattern length.');
|
throw new Error("Durations array does not match the pattern length.");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Array.prototype.shuffle = function () {
|
Array.prototype.shuffle = function () {
|
||||||
/**
|
/**
|
||||||
* Shuffles the array in place.
|
* Shuffles the array in place.
|
||||||
|
|||||||
@ -16,8 +16,8 @@ import { documentation_factory } from "./Documentation";
|
|||||||
import { EditorView } from "codemirror";
|
import { EditorView } from "codemirror";
|
||||||
import { Clock } from "./Clock";
|
import { Clock } from "./Clock";
|
||||||
import { loadSamples, UserAPI } from "./API";
|
import { loadSamples, UserAPI } from "./API";
|
||||||
import * as oeis from 'jisg'
|
import * as oeis from "jisg";
|
||||||
import * as zpatterns from 'zifferjs/src/patterns.ts'
|
import * as zpatterns from "zifferjs/src/patterns.ts";
|
||||||
import { makeArrayExtensions } from "./extensions/ArrayExtensions";
|
import { makeArrayExtensions } from "./extensions/ArrayExtensions";
|
||||||
import "./style.css";
|
import "./style.css";
|
||||||
import { Universes, File, template_universes } from "./FileManagement";
|
import { Universes, File, template_universes } from "./FileManagement";
|
||||||
@ -26,7 +26,7 @@ import { tryEvaluate } from "./Evaluator";
|
|||||||
import showdown from "showdown";
|
import showdown from "showdown";
|
||||||
import { makeStringExtensions } from "./extensions/StringExtensions";
|
import { makeStringExtensions } from "./extensions/StringExtensions";
|
||||||
import { installInterfaceLogic } from "./InterfaceLogic";
|
import { installInterfaceLogic } from "./InterfaceLogic";
|
||||||
import { installWindowBehaviors, saveBeforeExit } from "./WindowBehavior";
|
import { installWindowBehaviors, saveState } from "./WindowBehavior";
|
||||||
import { drawEmptyBlinkers } from "./AudioVisualisation";
|
import { drawEmptyBlinkers } from "./AudioVisualisation";
|
||||||
import { makeNumberExtensions } from "./extensions/NumberExtensions";
|
import { makeNumberExtensions } from "./extensions/NumberExtensions";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@ -514,7 +514,7 @@ export class Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private setPeriodicSave(interval: number): void {
|
private setPeriodicSave(interval: number): void {
|
||||||
setInterval(() => saveBeforeExit(this), interval)
|
setInterval(() => saveState(this), interval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user