mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-24 20:18:34 +00:00
REPL: solo and sync configuration
This commit is contained in:
parent
ae335ac40c
commit
b913e1c50d
@ -133,6 +133,7 @@ export class StrudelMirror {
|
|||||||
autodraw,
|
autodraw,
|
||||||
prebake,
|
prebake,
|
||||||
bgFill = true,
|
bgFill = true,
|
||||||
|
solo = true,
|
||||||
...replOptions
|
...replOptions
|
||||||
} = options;
|
} = options;
|
||||||
this.code = initialCode;
|
this.code = initialCode;
|
||||||
@ -143,6 +144,7 @@ export class StrudelMirror {
|
|||||||
this.drawContext = drawContext;
|
this.drawContext = drawContext;
|
||||||
this.onDraw = onDraw || this.draw;
|
this.onDraw = onDraw || this.draw;
|
||||||
this.id = id || s4();
|
this.id = id || s4();
|
||||||
|
this.solo = solo;
|
||||||
|
|
||||||
this.drawer = new Drawer((haps, time, _, painters) => {
|
this.drawer = new Drawer((haps, time, _, painters) => {
|
||||||
const currentFrame = haps.filter((hap) => hap.isActive(time));
|
const currentFrame = haps.filter((hap) => hap.isActive(time));
|
||||||
@ -159,12 +161,14 @@ export class StrudelMirror {
|
|||||||
replOptions?.onToggle?.(started);
|
replOptions?.onToggle?.(started);
|
||||||
if (started) {
|
if (started) {
|
||||||
this.drawer.start(this.repl.scheduler);
|
this.drawer.start(this.repl.scheduler);
|
||||||
// stop other repls when this one is started
|
if (this.solo) {
|
||||||
document.dispatchEvent(
|
// stop other repls when this one is started
|
||||||
new CustomEvent('start-repl', {
|
document.dispatchEvent(
|
||||||
detail: this.id,
|
new CustomEvent('start-repl', {
|
||||||
}),
|
detail: this.id,
|
||||||
);
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.drawer.stop();
|
this.drawer.stop();
|
||||||
updateMiniLocations(this.editor, []);
|
updateMiniLocations(this.editor, []);
|
||||||
@ -219,7 +223,7 @@ export class StrudelMirror {
|
|||||||
|
|
||||||
// stop this repl when another repl is started
|
// stop this repl when another repl is started
|
||||||
this.onStartRepl = (e) => {
|
this.onStartRepl = (e) => {
|
||||||
if (e.detail !== this.id) {
|
if (this.solo && e.detail !== this.id) {
|
||||||
this.stop();
|
this.stop();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -10,6 +10,8 @@ if (typeof HTMLElement !== 'undefined') {
|
|||||||
static observedAttributes = ['code'];
|
static observedAttributes = ['code'];
|
||||||
settings = codemirrorSettings.get();
|
settings = codemirrorSettings.get();
|
||||||
editor = null;
|
editor = null;
|
||||||
|
sync = false;
|
||||||
|
solo = true;
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@ -49,6 +51,8 @@ if (typeof HTMLElement !== 'undefined') {
|
|||||||
});
|
});
|
||||||
this.dispatchEvent(event);
|
this.dispatchEvent(event);
|
||||||
},
|
},
|
||||||
|
solo: this.solo,
|
||||||
|
sync: this.sync,
|
||||||
});
|
});
|
||||||
// init settings
|
// init settings
|
||||||
this.editor.updateSettings(this.settings);
|
this.editor.updateSettings(this.settings);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user