From 123509ae72b5d3c478810cfa00a4e2da60f1fcc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Wed, 11 Sep 2024 20:54:49 +0200 Subject: [PATCH 1/2] =?UTF-8?q?use=20the=20context=E2=80=99s=20document=20?= =?UTF-8?q?to=20create=20the=20input=20Event?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #2159 --- src/plot.js | 3 ++- test/event-test.js | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 test/event-test.js diff --git a/src/plot.js b/src/plot.js index 9fc6a3e138..944b9165c9 100644 --- a/src/plot.js +++ b/src/plot.js @@ -175,7 +175,8 @@ export function plot(options = {}) { context.dispatchValue = (value) => { if (figure.value === value) return; figure.value = value; - figure.dispatchEvent(new Event("input", {bubbles: true})); + const Event = context.document.defaultView?.Event; + if (Event) figure.dispatchEvent(new Event("input", {bubbles: true})); }; // Reinitialize; for deriving channels dependent on other channels. diff --git a/test/event-test.js b/test/event-test.js new file mode 100644 index 0000000000..2b0c1d0e2f --- /dev/null +++ b/test/event-test.js @@ -0,0 +1,8 @@ +import * as Plot from "@observablehq/plot"; +import * as assert from "assert"; +import {JSDOM} from "jsdom"; + +it("Plot uses the context’s event", () => { + Plot.lineY([1, 2, 3], {tip: true}).plot({document: new JSDOM("").window.document}); + assert.ok(true); +}); From e5d7d9754daf156f580b4a03ca5ac17132c59b9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Wed, 11 Sep 2024 21:52:59 +0200 Subject: [PATCH 2/2] Update src/plot.js Co-authored-by: Mike Bostock --- src/plot.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/plot.js b/src/plot.js index 944b9165c9..a7383a66c7 100644 --- a/src/plot.js +++ b/src/plot.js @@ -175,8 +175,7 @@ export function plot(options = {}) { context.dispatchValue = (value) => { if (figure.value === value) return; figure.value = value; - const Event = context.document.defaultView?.Event; - if (Event) figure.dispatchEvent(new Event("input", {bubbles: true})); + figure.dispatchEvent(new context.document.defaultView.Event("input", {bubbles: true})); }; // Reinitialize; for deriving channels dependent on other channels.