@marimo-team/islands 0.22.1-dev8 → 0.22.1-dev9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ import { t as toDate } from "./toDate-D6VXexnV.js";
5
5
  import { a as cva, v as cn } from "./button-qsiIHncQ.js";
6
6
  import { t as require_jsx_runtime } from "./jsx-runtime-9hcJiI23.js";
7
7
  import { C as dequal } from "./useTheme-Dm1WaAGy.js";
8
- import { i as tableFromIPC } from "./loader-3c9hT4kT.js";
8
+ import { i as tableFromIPC } from "./loader-CMMa6QVT.js";
9
9
  function isDate(t) {
10
10
  return t instanceof Date || typeof t == "object" && Object.prototype.toString.call(t) === "[object Date]";
11
11
  }
@@ -10,10 +10,10 @@ import { t as Tooltip } from "./tooltip-DGHTbHl5.js";
10
10
  import { i as debounce_default } from "./constants-D1Am36hX.js";
11
11
  import { n as useTheme, w as useEvent_default } from "./useTheme-Dm1WaAGy.js";
12
12
  import { s as uniq } from "./arrays-Du-jRBAy.js";
13
- import { a as AlertTitle, n as arrow, o as isValid, r as Alert, t as useDeepCompareMemoize } from "./useDeepCompareMemoize-X7clcrcQ.js";
13
+ import { a as AlertTitle, n as arrow, o as isValid, r as Alert, t as useDeepCompareMemoize } from "./useDeepCompareMemoize-DOzKCTzc.js";
14
14
  import { n as ErrorBanner } from "./error-banner-Bx9kIgrs.js";
15
15
  import { n as formats } from "./vega-loader.browser-DqEcFOPD.js";
16
- import { a as getContainerWidth, n as vegaLoadData, s as tooltipHandler } from "./loader-3c9hT4kT.js";
16
+ import { a as getContainerWidth, n as vegaLoadData, s as tooltipHandler } from "./loader-CMMa6QVT.js";
17
17
  import { t as useAsyncData } from "./useAsyncData-Cd4Urlww.js";
18
18
  import { t as j } from "./react-vega-CzRAIHrv.js";
19
19
  import "./defaultLocale-qS7DaAmi.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marimo-team/islands",
3
- "version": "0.22.1-dev8",
3
+ "version": "0.22.1-dev9",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -33,4 +33,72 @@ describe("getContainerWidth", () => {
33
33
  it("should return undefined when width is explicitly undefined", () => {
34
34
  expect(getContainerWidth({ width: undefined })).toBeUndefined();
35
35
  });
36
+
37
+ it("should find width in nested facet spec", () => {
38
+ expect(
39
+ getContainerWidth({
40
+ $schema: "https://vega.github.io/schema/vega-lite/v6.json",
41
+ facet: { column: { field: "Origin", type: "nominal" } },
42
+ spec: {
43
+ mark: "point",
44
+ encoding: {},
45
+ width: "container",
46
+ },
47
+ }),
48
+ ).toBe("container");
49
+ });
50
+
51
+ it("should find width in nested repeat spec", () => {
52
+ expect(
53
+ getContainerWidth({
54
+ $schema: "https://vega.github.io/schema/vega-lite/v6.json",
55
+ repeat: { row: ["A", "B"] },
56
+ spec: {
57
+ mark: "point",
58
+ encoding: {},
59
+ width: "container",
60
+ },
61
+ }),
62
+ ).toBe("container");
63
+ });
64
+
65
+ it("should return undefined for nested spec without width", () => {
66
+ expect(
67
+ getContainerWidth({
68
+ facet: { column: { field: "Origin" } },
69
+ spec: { mark: "point", encoding: {} },
70
+ }),
71
+ ).toBeUndefined();
72
+ });
73
+
74
+ it("should return undefined for hconcat (width on sub-specs)", () => {
75
+ expect(
76
+ getContainerWidth({
77
+ hconcat: [{ width: "container" }, { width: "container" }],
78
+ }),
79
+ ).toBeUndefined();
80
+ });
81
+
82
+ it("should return undefined for vconcat (width on sub-specs)", () => {
83
+ expect(
84
+ getContainerWidth({
85
+ vconcat: [{ width: "container" }, { width: "container" }],
86
+ }),
87
+ ).toBeUndefined();
88
+ });
89
+
90
+ it("should return undefined for compiled Vega spec (width as signal)", () => {
91
+ expect(
92
+ getContainerWidth({
93
+ $schema: "https://vega.github.io/schema/vega/v6.json",
94
+ autosize: { contains: "padding", type: "fit-x" },
95
+ signals: [
96
+ {
97
+ name: "width",
98
+ init: "isFinite(containerSize()[0]) ? containerSize()[0] : 300",
99
+ },
100
+ ],
101
+ }),
102
+ ).toBeUndefined();
103
+ });
36
104
  });
@@ -6,13 +6,22 @@ import type { DataType, FieldTypes, VegaDataType } from "./vega-loader";
6
6
  export type ContainerWidth = number | "container";
7
7
 
8
8
  /**
9
- * Get the container width from a VegaLite spec.
10
- * @param spec - The VegaLite spec.
11
- * @returns The container width.
9
+ * Get the container width from a Vega-Lite spec.
10
+ *
11
+ * For unit specs, `width` is at the top level. For facet/repeat specs,
12
+ * `width` is nested inside `spec`. This does not handle hconcat/vconcat and Vega spec
13
+ * where the width may be a signal. These cases are covered by
14
+ * the CSS fallback `.vega-embed:has(> .chart-wrapper.fit-x)`.
12
15
  */
13
16
  export function getContainerWidth(spec: unknown): ContainerWidth | undefined {
14
- if (typeof spec === "object" && spec !== null && "width" in spec) {
15
- return spec.width as ContainerWidth | undefined;
17
+ if (typeof spec === "object" && spec !== null) {
18
+ if ("width" in spec) {
19
+ return spec.width as ContainerWidth | undefined;
20
+ }
21
+ // Faceted/repeated spec
22
+ if ("spec" in spec) {
23
+ return getContainerWidth(spec.spec);
24
+ }
16
25
  }
17
26
  return undefined;
18
27
  }
@@ -4,7 +4,8 @@
4
4
  max-width: 100%;
5
5
  }
6
6
 
7
- .vega-embed[data-container-width="container"] {
7
+ .vega-embed[data-container-width="container"],
8
+ .vega-embed:has(> .chart-wrapper.fit-x) {
8
9
  width: 100%;
9
10
  }
10
11