fix: autoupdate

This commit is contained in:
2026-04-23 12:37:09 +07:00
parent 994a13da52
commit 3e36cfcb39
3 changed files with 19 additions and 3 deletions
+16
View File
@@ -59,6 +59,10 @@ window.EditorCore = (function () {
_wireButton('btn-reset', () => opts.onReset(_currentPage + 1));
}
// Disconnect browser-sync to prevent auto-reload.
// Editors maintain DOM state — reload would wipe unsaved changes.
_disconnectBrowserSync();
// Load worksheet, then optionally load data.json
_loadWorksheet(_config.filePath, opts.onReady, opts.onDataLoaded);
@@ -240,6 +244,18 @@ window.EditorCore = (function () {
// ---- Helpers ----
function _disconnectBrowserSync() {
function tryDisconnect() {
if (window.___browserSync___) {
window.___browserSync___.socket.close();
}
}
// Browser-sync client may connect after our script runs
tryDisconnect();
setTimeout(tryDisconnect, 500);
setTimeout(tryDisconnect, 2000);
}
function _wireButton(id, handler) {
const btn = document.getElementById(id);
if (btn) btn.addEventListener('click', handler);