diff --git a/inventory/static/js/components/draw.js b/inventory/static/js/components/draw.js
index f5a3f5d..5e2a7dc 100644
--- a/inventory/static/js/components/draw.js
+++ b/inventory/static/js/components/draw.js
@@ -1,9 +1,15 @@
-let activeGridWidget = null;
+(function bindGridGlobalKeydownOnce() {
+ if (window.__gridKeydownBound) return;
+ window.__gridKeydownBound = true;
-document.addEventListener('keydown', (e) => {
- if (!activeGridWidget) return;
- activeGridWidget.handleKeyDown(e);
-});
+ window.activeGridWidget = null; // define it once, globally
+
+ document.addEventListener('keydown', (e) => {
+ const w = window.activeGridWidget;
+ if (!w) return;
+ w.handleKeyDown(e);
+ });
+})();
function initGridWidget(root, opts = {}) {
const mode = opts.mode || 'editor';
@@ -335,10 +341,10 @@ function initGridWidget(root, opts = {}) {
}
};
- root.addEventListener('focusin', () => { activeGridWidget = api; });
+ root.addEventListener('focusin', () => { window.activeGridWidget = api; });
root.addEventListener('pointerdown', () => {
- activeGridWidget = api;
+ window.activeGridWidget = api;
}, { capture: true });
function setGrid() {
@@ -1018,9 +1024,10 @@ function initGridWidget(root, opts = {}) {
}
(function autoBootGridWidgets() {
+ const GRID_BOOT = new WeakMap();
function bootRoot(root) {
- if (root.__gridBooted) return;
- root.__gridBooted = true;
+ if (GRID_BOOT.has(root)) return;
+ GRID_BOOT.set(root, true);
const mode = root.dataset.mode || 'editor';
const storageKey = root.dataset.storageKey || root.dataset.key || 'gridDoc';
diff --git a/inventory/templates/components/draw.html b/inventory/templates/components/draw.html
index 263aafa..ac23e28 100644
--- a/inventory/templates/components/draw.html
+++ b/inventory/templates/components/draw.html
@@ -196,7 +196,7 @@