@malloy-publisher/sdk 0.12.6 → 0.13.0
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.
- package/dist/{RenderedResult-ozKMHmvL.cjs.js → RenderedResult-C4rimzu4.cjs.js} +3 -3
- package/dist/{RenderedResult-DAW_Cfc-.es.js → RenderedResult-D5HJr2Xo.es.js} +139 -125
- package/dist/{ServerProvider-Qd3zdOsC.es.js → ServerProvider-8Eul_YOl.es.js} +1468 -1437
- package/dist/ServerProvider-Cvllj0GN.cjs.js +1 -0
- package/dist/builder/index.cjs.js +1 -1
- package/dist/builder/index.es.js +335 -335
- package/dist/client/api.d.ts +321 -24
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +75 -71
- package/dist/components/Package/usePackageVersions.d.ts +2 -2
- package/dist/components/RenderedResult/RenderedResult.d.ts +1 -0
- package/dist/components/ServerProvider.d.ts +18 -2
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +5 -5
- package/dist/{useCompiledDocument-XJMCZF8O.es.js → useCompiledDocument-CwMwrEXo.es.js} +2 -2
- package/dist/{useCompiledDocument-BpP4Clt3.cjs.js → useCompiledDocument-UADoxvYb.cjs.js} +2 -2
- package/package.json +13 -12
- package/src/components/Package/usePackageVersions.ts +2 -2
- package/src/components/RenderedResult/RenderedResult.tsx +25 -0
- package/src/components/ServerProvider.host.isolated.spec.tsx +95 -0
- package/src/components/ServerProvider.tsx +25 -5
- package/test/README.md +5 -3
- package/dist/ServerProvider-CqL6xzta.cjs.js +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";const $=require("react/jsx-runtime"),
|
|
2
|
-
`},...o.annotations??[]]})}),changed:r}}function
|
|
1
|
+
"use strict";const $=require("react/jsx-runtime"),de=require("@mui/material"),w=require("react"),u=require("./useCompiledDocument-UADoxvYb.cjs.js"),G=require("./ServerProvider-Cvllj0GN.cjs.js"),v=u.reportClasses.drillCell;function me(e,t){const r=new Set;let a;try{a=e.getMetadata()?.getAllFields()??[]}catch{return r}const o=new Set;for(const n of a)!n||t(n)||n.tag?.tag("hidden")===void 0&&o.add(n.tag?.text("label")??n.name);for(const n of a){if(!n||!t(n))continue;const l=n.tag?.text("label")??n.name;o.has(l)||r.add(l)}return r}function j(e){const t=/^\s*(\d+)/.exec(e.style?.gridColumn??"");return t?t[1]:void 0}function be(e,t){if(t.size!==0)for(const r of e.querySelectorAll(".malloy-table")){const a=l=>l.closest(".malloy-table")===r,o=new Set;for(const l of r.querySelectorAll(".column-cell.th")){if(!a(l))continue;const i=(l.textContent??"").replace(/\u200b/g,"").trim(),m=j(l);m&&t.has(i)&&o.add(m)}if(o.size===0)continue;const n=new Set;for(const l of r.querySelectorAll(`.${v}[tabindex="0"]`)){if(!a(l))continue;const i=j(l);i&&(n.has(i)?l.tabIndex=-1:n.add(i))}for(const l of r.querySelectorAll(".column-cell.td")){if(!a(l))continue;const i=j(l),m=!l.querySelector(".value-null")&&(l.textContent??"").trim()!=="";if(i&&m&&o.has(i)&&!l.querySelector(".malloy-table")){if(l.classList.add(v),l.tabIndex===0)n.add(i);else{const p=n.has(i);p||n.add(i),l.tabIndex=p?-1:0}l.setAttribute("role","button")}}}}function Ce(e){const t=e.closest(".malloy-table"),r=j(e);return!t||!r?[]:Array.from(t.querySelectorAll(`.${v}`)).filter(a=>a.closest(".malloy-table")===t&&j(a)===r)}function ce(e,t){const r=Ce(e),a=r.indexOf(e);if(a===-1)return;const o=t==="first"?r[0]:t==="last"?r[r.length-1]:r[Math.min(Math.max(a+t,0),r.length-1)];if(o){for(const n of r)n.tabIndex=n===o?0:-1;return o}}function fe(e){return{background:e.dashboardRoot,tableBackground:e.tableBackground,tableHeaderColor:e.tableHeader,tableBodyColor:e.tableBody,tableBorder:e.border,tablePinnedBackground:e.tableHeaderBackground,tablePinnedBorder:e.pinnedBorder,tableFontSize:`${e.font.size}px`,fontFamily:e.font.family,mapColor:e.mapColor}}function ye(e){const{foreground:t,axisFaint:r,gridline:a,font:o}=e,n={background:e.background,font:o.family,title:{color:t,font:o.family},axis:{labelColor:t,titleColor:t,domainColor:r,tickColor:r,gridColor:a,labelFont:o.family,titleFont:o.family},legend:{labelColor:t,titleColor:t,labelFont:o.family,titleFont:o.family},header:{labelColor:t,titleColor:t},range:{category:e.series}},l={...n,legend:{...n.legend,orient:"bottom"}};return i=>i==="shape_map"?l:n}function pe(e){if(!e)return;const t=e.tag("theme");if(!t)return;const r={},a=t.tag("palette");if(a){const n={},l=a.textArray("series");l&&l.length>0&&(n.series=l);for(const i of G.PER_MODE_COLOR_KEYS){const m=a.tag(i);if(!m)continue;const p={},C=m.text("light"),x=m.text("dark");C&&(p.light=C),x&&(p.dark=x),Object.keys(p).length>0&&(n[i]=p)}Object.keys(n).length>0&&(r.palette=n)}const o=t.tag("font");if(o){const n={},l=o.text("family");l&&(n.family=l);const i=o.numeric("size");typeof i=="number"&&Number.isFinite(i)&&(n.size=i),Object.keys(n).length>0&&(r.font=n)}return Object.keys(r).length>0?r:void 0}const ee=e=>(e??[]).map(t=>t?.value).filter(t=>typeof t=="string");function Re(e){const t=e.replace(/[-_]+/g," ").replace(/\s+/g," ").trim();return t.charAt(0).toUpperCase()+t.slice(1)}const Te=e=>ee(e.annotations).some(t=>{const r=t.trim();return/^#[^("]/.test(r)&&/(?:^#|[\s{])label\s*=/.test(r)}),Ae=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`,Ee=e=>e.type?.element_type?.fields??e.type?.fields;function ge(e,t){let r=!1;return{fields:e.map(o=>{const n=Ee(o);if(n){const i=ge(n,u.requestsRowChart(ee(o.annotations)));if(!i.changed)return o;r=!0;const m=o.type?.element_type?{...o.type,element_type:{...o.type.element_type,fields:i.fields}}:{...o.type,fields:i.fields};return{...o,type:m}}if(!t||!o.name||Te(o))return o;const l=Re(o.name);return l===o.name?o:(r=!0,{...o,annotations:[{value:`# label=${Ae(l)}
|
|
2
|
+
`},...o.annotations??[]]})}),changed:r}}function Se(e){if(!e||typeof e!="object")return e;const t=e,r=t.schema?.fields;if(!Array.isArray(r))return e;const{fields:a,changed:o}=ge(r,u.requestsRowChart(ee(t.annotations)));return o?{...t,schema:{...t.schema,fields:a}}:e}const ue=320,_e=10,De=96,Oe=4e3;function Fe(e,t){if(e!=="bar"&&e!=="combo"&&e!=="line"&&e!=="chart"&&e!=="scatter_chart")return;if(e!=="bar"&&e!=="combo")return ue;const r=t?.data?.array_value?.length,a=r===void 0?0:r*_e+De;return Math.min(Math.max(ue,a),Oe)}function Le(e){let t;return{onClick:r=>{const a={...r,...ze(r)};t=a,queueMicrotask(()=>{t===a&&(t=void 0),e(a)})},onDrill:r=>{const a=t;t=void 0,a&&r.stableDrillClauses!==void 0&&(a.drillClauses=r.stableDrillClauses)}}}function ze(e){const t=e.field;try{const r=t?.getEffectiveQueryTimezone?.();return r?{timezone:r}:{}}catch{return{}}}function Ie(e){const t=r=>{let a=!1;try{a=r.isArray?.()===!0}catch{a=!1}a&&"stableDrillFilters"in r&&Object.defineProperty(r,"stableDrillFilters",{configurable:!0,get:()=>[]});for(const o of r.fields??[])t(o)};e&&t(e)}const B="data-publisher-fill";let X;function ve(){if(X===void 0)try{X=new Function("return true")()===!0}catch{X=!1}return X}const Me=async(e,t,r)=>{if(typeof window>"u")throw new Error("MalloyRenderer can only be used in browser environment");const{MalloyRenderer:a}=await u.loadMalloyRenderer();return new a({onClick:t,...r?{onDrill:r,tableConfig:{enableDrill:!0}}:{},vegaConfigOverride:ye(e),...ve()?{}:{useVegaInterpreter:!0},theme:fe(e),onError:n=>{console.error("Error rendering visualization:",typeof n,n)}}).createViz()};async function $e(e){if(!e||typeof e!="object")return;const t=e,r=[...Array.isArray(t.model_annotations)?t.model_annotations:[],...Array.isArray(t.source_annotations)?t.source_annotations:[],...Array.isArray(t.annotations)?t.annotations:[]].map(o=>typeof o?.value=="string"?o.value:void 0).filter(o=>!!o);if(r.length===0)return;let a;try{({parseAnnotation:a}=await u.loadMalloyTag())}catch{return}try{const{tag:o}=a(r);return pe(o)}catch(o){console.warn("Failed to parse # theme.* annotations; chart will render with the shell theme.",{error:o,lines:r});return}}function Be(e,t,r){const a=u.buildTableCssVars(t,r);for(const[o,n]of Object.entries(a))e.style.setProperty(o,n)}const je=`
|
|
3
3
|
/* Card geometry, through the renderer's OWN theme vars rather than over the top
|
|
4
4
|
of them. It declares --malloy-theme--dashboard-* on .malloy-render itself and
|
|
5
5
|
passes each through to the --malloy-render--* the card CSS reads, so a value
|
|
@@ -176,4 +176,4 @@ div.malloy-render .malloy-dashboard .dashboard-row-header {
|
|
|
176
176
|
.malloy-render .malloy-table .td.highlight:not(.${v}) {
|
|
177
177
|
cursor: inherit;
|
|
178
178
|
}
|
|
179
|
-
`,
|
|
179
|
+
`,he="publisher-malloy-renderer-overrides";function Ne(){if(typeof document>"u"||document.getElementById(he))return;const e=document.createElement("style");e.id=he,e.textContent=je,document.head.appendChild(e)}function Pe({result:e,height:t,drill:r,onSizeChange:a,onSizing:o,fill:n}){const l=w.useRef(null),i=w.useRef(r);i.current=r;const m=w.useMemo(()=>Le(d=>i.current?.onClick(d)),[]),p=r!==void 0,C=w.useRef(!1),x=w.useRef(null),W=w.useRef(0),{theme:N,layers:K,mode:te}=G.usePublisherTheme(),re=w.useMemo(()=>({radius:N.ui.radius.tile,padding:`${u.DASHBOARD_CARD_PADDING_PX}px`}),[N.ui.radius.tile]);return w.useEffect(()=>()=>{W.current+=1;const d=x.current;d?.viz.remove(),d?.node.remove(),x.current=null},[]),w.useLayoutEffect(()=>{if(!l.current||!e)return;Ne();const d=l.current,ke=W.current+=1;let U=!1;const Y=()=>!U&&ke===W.current;let c,f,P=null,J=0,q=null,H=null,V=null,F=null,L=null,z=null,oe=null,ae=0,S=null;C.current=!1;let g,_;const Q=k=>{if(U||!k.firstElementChild||u.resultSizing(g,_)==="container")return;const I=u.remeasuresAfterReady(g,_);if(C.current&&!I)return;const M=d.hasAttribute(B);M&&d.removeAttribute(B);const R=d.closest(`.${u.RESULT_SCROLLER_CLASS}`),h=R?.style.overflowY;R&&(R.style.overflowY="hidden");const D=u.measureContentHeight(k,u.contentNodeDepth(g));R&&(R.style.overflowY=h??""),M&&d.setAttribute(B,""),D>0&&(C.current=!0,a&&D!==ae&&(ae=D,a(D)));const T=u.contentNode(k,u.contentNodeDepth(g));I&&T&&oe!==T&&(oe=T,z?.disconnect(),z=new ResizeObserver(()=>Q(k)),z.observe(T))};return(async()=>{let k;try{k=JSON.parse(e)}catch(b){console.error("Error parsing visualization result:",b);return}const I=await $e(k),M=I?G.resolveTheme([...K,G.chartThemeLayer(K,I)],te):N;if(!Y())return;try{f=await Me(M,m.onClick,p?m.onDrill:void 0)}catch(b){console.error("Failed to create renderer:",b);return}if(!Y()){f.remove(),f=void 0;return}const R=x.current;c=document.createElement("div"),c.style.width="100%",c.style.height="100%",Be(c,M,re),d.childElementCount>0&&(d.style.position="relative",c.style.position="absolute",c.style.inset="0",c.style.visibility="hidden"),d.appendChild(c);const h=c;F=new MutationObserver(()=>{L&&clearTimeout(L),L=setTimeout(()=>{Q(h),C.current&&F?.disconnect()},100)}),F.observe(c,{childList:!0,subtree:!0,attributes:!0});const D=f;let T=!1;const ne=()=>{if(!(T||!Y())){T=!0,S&&(clearTimeout(S),S=null),R?.viz.remove();for(const b of Array.from(d.children))b!==h&&d.removeChild(b);h.style.position="",h.style.inset="",h.style.visibility="",d.style.position="",x.current={viz:D,node:h},Q(h)}};try{f.setResult(Se(k));try{const A=f.getMetadata(),E=A?.getRootField();p&&Ie(E),g=E?.renderAs(),_=E?A?.getPluginsForField(E.key)?.[0]?.sizingStrategy:void 0}catch{g=void 0,_=void 0}o?.(u.resultSizing(g,_),g),c.dataset.malloyRenderAs=g??"unknown",c.dataset.malloySizing=u.resultSizing(g,_);const b=Fe(g,k);c.style.minWidth=b===void 0?"":`${b}px`,d.style.overflowX=b===void 0?"":"auto",d.style.overflowY=b===void 0?"":"hidden",f.render(c);const le=i.current;try{if(le){const A=me(f,le.canDrill),E=()=>{try{be(h,A)}catch(s){console.warn("Drill affordance skipped:",s)}};E();const ie=s=>{const O=s.querySelector(".cell-content")??s,Z=O.getBoundingClientRect();O.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0,view:O.ownerDocument.defaultView,clientX:Math.round(Z.left+Z.width/2),clientY:Math.round(Z.bottom)}))},se=s=>s.target?.closest?.(`.${v}`)??null,xe=(s,y)=>{ce(s,y)?.focus()};q=s=>{const y=se(s);if(!y)return;const O=s.key==="ArrowDown"?1:s.key==="ArrowUp"?-1:s.key==="Home"?"first":s.key==="End"?"last":void 0;if(O!==void 0){s.preventDefault(),xe(y,O);return}s.key==="Enter"?(s.preventDefault(),ie(y)):s.key===" "&&s.preventDefault()},H=s=>{if(s.key!==" ")return;const y=se(s);y&&(s.preventDefault(),ie(y))},V=s=>{const y=s.target?.closest?.(`.${v}`);y&&ce(y,0)},h.addEventListener("keydown",q),h.addEventListener("keyup",H),h.addEventListener("focusin",V),A.size>0&&typeof MutationObserver<"u"&&(P=new MutationObserver(()=>{cancelAnimationFrame(J),J=requestAnimationFrame(E)}),P.observe(h,{childList:!0,subtree:!0}))}}catch(A){console.warn("Drill affordance skipped:",A)}f.onReady(ne),S=setTimeout(ne,1e4)}catch(b){console.error("Error rendering visualization:",b),F?.disconnect(),z?.disconnect(),P?.disconnect(),f.remove(),f=void 0,h.parentNode===d&&d.removeChild(h)}})(),()=>{U=!0,F?.disconnect(),z?.disconnect(),L&&clearTimeout(L),S&&clearTimeout(S),c&&x.current?.node!==c&&(q&&c.removeEventListener("keydown",q),H&&c.removeEventListener("keyup",H),V&&c.removeEventListener("focusin",V),P?.disconnect(),cancelAnimationFrame(J),f?.remove(),c.parentNode===d&&d.removeChild(c),d.style.position="")}},[e,m,p,a,o,N,K,te,re]),$.jsx("div",{ref:l,...n?{[B]:""}:{},style:{width:"100%",height:t?`${t}px`:"400px"}})}function we(e){return typeof window>"u"?$.jsx(de.Box,{sx:{width:"100%",height:e.height?`${e.height}px`:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"text.secondary"},children:"Loading..."}):$.jsx(w.Suspense,{fallback:$.jsx(de.Box,{sx:{width:"100%",height:e.height?`${e.height}px`:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"text.secondary"},children:"Loading visualization..."}),children:$.jsx(Pe,{...e})})}const qe=Object.freeze(Object.defineProperty({__proto__:null,default:we,pageAllowsEval:ve},Symbol.toStringTag,{value:"Module"}));exports.DRILL_CELL_CLASS=v;exports.RenderedResult=we;exports.RenderedResult$1=qe;exports.buildMalloyExplicitTheme=fe;exports.buildVegaThemeOverride=ye;exports.drillableFieldNames=me;exports.markDrillableCells=be;exports.readChartAnnotations=pe;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx as I } from "react/jsx-runtime";
|
|
2
|
-
import { Box as
|
|
3
|
-
import { Suspense as
|
|
4
|
-
import { r as
|
|
5
|
-
import {
|
|
6
|
-
const g =
|
|
7
|
-
function
|
|
2
|
+
import { Box as de } from "@mui/material";
|
|
3
|
+
import { Suspense as we, useRef as M, useMemo as ce, useEffect as ke, useLayoutEffect as xe } from "react";
|
|
4
|
+
import { r as Ce, a as fe, D as Re, b as Z, T as V, l as Ee, c as Ae, d as Te, e as Se, R as _e, m as De, f as Oe, g as ue } from "./useCompiledDocument-CwMwrEXo.es.js";
|
|
5
|
+
import { bx as Fe, bv as ze, by as Le, bz as Me } from "./ServerProvider-8Eul_YOl.es.js";
|
|
6
|
+
const g = Ce.drillCell;
|
|
7
|
+
function Ie(e, t) {
|
|
8
8
|
const r = /* @__PURE__ */ new Set();
|
|
9
9
|
let a;
|
|
10
10
|
try {
|
|
@@ -26,7 +26,7 @@ function B(e) {
|
|
|
26
26
|
const t = /^\s*(\d+)/.exec(e.style?.gridColumn ?? "");
|
|
27
27
|
return t ? t[1] : void 0;
|
|
28
28
|
}
|
|
29
|
-
function
|
|
29
|
+
function $e(e, t) {
|
|
30
30
|
if (t.size !== 0)
|
|
31
31
|
for (const r of e.querySelectorAll(
|
|
32
32
|
".malloy-table"
|
|
@@ -65,7 +65,7 @@ function Me(e, t) {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
function
|
|
68
|
+
function Be(e) {
|
|
69
69
|
const t = e.closest(".malloy-table"), r = B(e);
|
|
70
70
|
return !t || !r ? [] : Array.from(
|
|
71
71
|
t.querySelectorAll(`.${g}`)
|
|
@@ -73,8 +73,8 @@ function Ie(e) {
|
|
|
73
73
|
(a) => a.closest(".malloy-table") === t && B(a) === r
|
|
74
74
|
);
|
|
75
75
|
}
|
|
76
|
-
function
|
|
77
|
-
const r =
|
|
76
|
+
function he(e, t) {
|
|
77
|
+
const r = Be(e), a = r.indexOf(e);
|
|
78
78
|
if (a === -1) return;
|
|
79
79
|
const o = t === "first" ? r[0] : t === "last" ? r[r.length - 1] : r[Math.min(Math.max(a + t, 0), r.length - 1)];
|
|
80
80
|
if (o) {
|
|
@@ -82,7 +82,7 @@ function ue(e, t) {
|
|
|
82
82
|
return o;
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
-
function
|
|
85
|
+
function Ne(e) {
|
|
86
86
|
return {
|
|
87
87
|
background: e.dashboardRoot,
|
|
88
88
|
tableBackground: e.tableBackground,
|
|
@@ -104,7 +104,7 @@ function $e(e) {
|
|
|
104
104
|
mapColor: e.mapColor
|
|
105
105
|
};
|
|
106
106
|
}
|
|
107
|
-
function
|
|
107
|
+
function Pe(e) {
|
|
108
108
|
const { foreground: t, axisFaint: r, gridline: a, font: o } = e, n = {
|
|
109
109
|
background: e.background,
|
|
110
110
|
font: o.family,
|
|
@@ -132,7 +132,7 @@ function Be(e) {
|
|
|
132
132
|
};
|
|
133
133
|
return (i) => i === "shape_map" ? l : n;
|
|
134
134
|
}
|
|
135
|
-
function
|
|
135
|
+
function je(e) {
|
|
136
136
|
if (!e) return;
|
|
137
137
|
const t = e.tag("theme");
|
|
138
138
|
if (!t) return;
|
|
@@ -140,7 +140,7 @@ function Ne(e) {
|
|
|
140
140
|
if (a) {
|
|
141
141
|
const n = {}, l = a.textArray("series");
|
|
142
142
|
l && l.length > 0 && (n.series = l);
|
|
143
|
-
for (const i of
|
|
143
|
+
for (const i of Fe) {
|
|
144
144
|
const h = a.tag(i);
|
|
145
145
|
if (!h) continue;
|
|
146
146
|
const y = {}, k = h.text("light"), w = h.text("dark");
|
|
@@ -157,23 +157,23 @@ function Ne(e) {
|
|
|
157
157
|
}
|
|
158
158
|
return Object.keys(r).length > 0 ? r : void 0;
|
|
159
159
|
}
|
|
160
|
-
const
|
|
161
|
-
function
|
|
160
|
+
const ee = (e) => (e ?? []).map((t) => t?.value).filter((t) => typeof t == "string");
|
|
161
|
+
function He(e) {
|
|
162
162
|
const t = e.replace(/[-_]+/g, " ").replace(/\s+/g, " ").trim();
|
|
163
163
|
return t.charAt(0).toUpperCase() + t.slice(1);
|
|
164
164
|
}
|
|
165
|
-
const
|
|
165
|
+
const qe = (e) => ee(e.annotations).some((t) => {
|
|
166
166
|
const r = t.trim();
|
|
167
167
|
return /^#[^("]/.test(r) && /(?:^#|[\s{])label\s*=/.test(r);
|
|
168
|
-
}),
|
|
169
|
-
function
|
|
168
|
+
}), Ve = (e) => `"${e.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`, Xe = (e) => e.type?.element_type?.fields ?? e.type?.fields;
|
|
169
|
+
function ye(e, t) {
|
|
170
170
|
let r = !1;
|
|
171
171
|
return { fields: e.map((o) => {
|
|
172
|
-
const n =
|
|
172
|
+
const n = Xe(o);
|
|
173
173
|
if (n) {
|
|
174
|
-
const i =
|
|
174
|
+
const i = ye(
|
|
175
175
|
n,
|
|
176
|
-
|
|
176
|
+
fe(ee(o.annotations))
|
|
177
177
|
);
|
|
178
178
|
if (!i.changed) return o;
|
|
179
179
|
r = !0;
|
|
@@ -186,43 +186,43 @@ function fe(e, t) {
|
|
|
186
186
|
} : { ...o.type, fields: i.fields };
|
|
187
187
|
return { ...o, type: h };
|
|
188
188
|
}
|
|
189
|
-
if (!t || !o.name ||
|
|
190
|
-
const l =
|
|
189
|
+
if (!t || !o.name || qe(o)) return o;
|
|
190
|
+
const l = He(o.name);
|
|
191
191
|
return l === o.name ? o : (r = !0, {
|
|
192
192
|
...o,
|
|
193
193
|
annotations: [
|
|
194
|
-
{ value: `# label=${
|
|
194
|
+
{ value: `# label=${Ve(l)}
|
|
195
195
|
` },
|
|
196
196
|
...o.annotations ?? []
|
|
197
197
|
]
|
|
198
198
|
});
|
|
199
199
|
}), changed: r };
|
|
200
200
|
}
|
|
201
|
-
function
|
|
201
|
+
function We(e) {
|
|
202
202
|
if (!e || typeof e != "object") return e;
|
|
203
203
|
const t = e, r = t.schema?.fields;
|
|
204
204
|
if (!Array.isArray(r)) return e;
|
|
205
|
-
const { fields: a, changed: o } =
|
|
205
|
+
const { fields: a, changed: o } = ye(
|
|
206
206
|
r,
|
|
207
|
-
|
|
207
|
+
fe(ee(t.annotations))
|
|
208
208
|
);
|
|
209
209
|
return o ? { ...t, schema: { ...t.schema, fields: a } } : e;
|
|
210
210
|
}
|
|
211
|
-
const
|
|
212
|
-
function
|
|
211
|
+
const me = 320, Ke = 10, Ue = 96, Ye = 4e3;
|
|
212
|
+
function Ge(e, t) {
|
|
213
213
|
if (e !== "bar" && e !== "combo" && e !== "line" && e !== "chart" && e !== "scatter_chart")
|
|
214
214
|
return;
|
|
215
|
-
if (e !== "bar" && e !== "combo") return
|
|
216
|
-
const r = t?.data?.array_value?.length, a = r === void 0 ? 0 : r *
|
|
217
|
-
return Math.min(Math.max(
|
|
215
|
+
if (e !== "bar" && e !== "combo") return me;
|
|
216
|
+
const r = t?.data?.array_value?.length, a = r === void 0 ? 0 : r * Ke + Ue;
|
|
217
|
+
return Math.min(Math.max(me, a), Ye);
|
|
218
218
|
}
|
|
219
|
-
function
|
|
219
|
+
function Je(e) {
|
|
220
220
|
let t;
|
|
221
221
|
return {
|
|
222
222
|
onClick: (r) => {
|
|
223
223
|
const a = {
|
|
224
224
|
...r,
|
|
225
|
-
...
|
|
225
|
+
...Qe(r)
|
|
226
226
|
};
|
|
227
227
|
t = a, queueMicrotask(() => {
|
|
228
228
|
t === a && (t = void 0), e(a);
|
|
@@ -234,7 +234,7 @@ function Ye(e) {
|
|
|
234
234
|
}
|
|
235
235
|
};
|
|
236
236
|
}
|
|
237
|
-
function
|
|
237
|
+
function Qe(e) {
|
|
238
238
|
const t = e.field;
|
|
239
239
|
try {
|
|
240
240
|
const r = t?.getEffectiveQueryTimezone?.();
|
|
@@ -243,7 +243,7 @@ function Ge(e) {
|
|
|
243
243
|
return {};
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
|
-
function
|
|
246
|
+
function Ze(e) {
|
|
247
247
|
const t = (r) => {
|
|
248
248
|
let a = !1;
|
|
249
249
|
try {
|
|
@@ -259,28 +259,41 @@ function Je(e) {
|
|
|
259
259
|
};
|
|
260
260
|
e && t(e);
|
|
261
261
|
}
|
|
262
|
-
const $ = "data-publisher-fill"
|
|
262
|
+
const $ = "data-publisher-fill";
|
|
263
|
+
let X;
|
|
264
|
+
function pe() {
|
|
265
|
+
if (X === void 0)
|
|
266
|
+
try {
|
|
267
|
+
X = new Function("return true")() === !0;
|
|
268
|
+
} catch {
|
|
269
|
+
X = !1;
|
|
270
|
+
}
|
|
271
|
+
return X;
|
|
272
|
+
}
|
|
273
|
+
const et = async (e, t, r) => {
|
|
263
274
|
if (typeof window > "u")
|
|
264
275
|
throw new Error("MalloyRenderer can only be used in browser environment");
|
|
265
|
-
const { MalloyRenderer: a } = await
|
|
276
|
+
const { MalloyRenderer: a } = await Ae();
|
|
266
277
|
return new a({
|
|
267
278
|
onClick: t,
|
|
268
279
|
// A table cell's row reaches the host only through the renderer's drill,
|
|
269
280
|
// which it reports only with `enableDrill` set; see `drillClickRelay`.
|
|
270
281
|
...r ? { onDrill: r, tableConfig: { enableDrill: !0 } } : {},
|
|
271
|
-
vegaConfigOverride:
|
|
282
|
+
vegaConfigOverride: Pe(e),
|
|
283
|
+
// Charts under a CSP that refuses eval; see `pageAllowsEval`.
|
|
284
|
+
...pe() ? {} : { useVegaInterpreter: !0 },
|
|
272
285
|
// Pass the explicit theme so table chrome and dashboard tiles
|
|
273
286
|
// pick up the operator's colours directly. Without this the
|
|
274
287
|
// renderer's own inline style writes `--malloy-render--*` values
|
|
275
288
|
// sourced from its built-in defaults and shadows whatever we set
|
|
276
289
|
// on the outer wrapper.
|
|
277
|
-
theme:
|
|
290
|
+
theme: Ne(e),
|
|
278
291
|
onError: (n) => {
|
|
279
292
|
console.error("Error rendering visualization:", typeof n, n);
|
|
280
293
|
}
|
|
281
294
|
}).createViz();
|
|
282
295
|
};
|
|
283
|
-
async function
|
|
296
|
+
async function tt(e) {
|
|
284
297
|
if (!e || typeof e != "object") return;
|
|
285
298
|
const t = e, r = [
|
|
286
299
|
...Array.isArray(t.model_annotations) ? t.model_annotations : [],
|
|
@@ -290,13 +303,13 @@ async function Ze(e) {
|
|
|
290
303
|
if (r.length === 0) return;
|
|
291
304
|
let a;
|
|
292
305
|
try {
|
|
293
|
-
({ parseAnnotation: a } = await
|
|
306
|
+
({ parseAnnotation: a } = await Ee());
|
|
294
307
|
} catch {
|
|
295
308
|
return;
|
|
296
309
|
}
|
|
297
310
|
try {
|
|
298
311
|
const { tag: o } = a(r);
|
|
299
|
-
return
|
|
312
|
+
return je(o);
|
|
300
313
|
} catch (o) {
|
|
301
314
|
console.warn(
|
|
302
315
|
"Failed to parse # theme.* annotations; chart will render with the shell theme.",
|
|
@@ -305,12 +318,12 @@ async function Ze(e) {
|
|
|
305
318
|
return;
|
|
306
319
|
}
|
|
307
320
|
}
|
|
308
|
-
function
|
|
309
|
-
const a =
|
|
321
|
+
function rt(e, t, r) {
|
|
322
|
+
const a = Te(t, r);
|
|
310
323
|
for (const [o, n] of Object.entries(a))
|
|
311
324
|
e.style.setProperty(o, n);
|
|
312
325
|
}
|
|
313
|
-
const
|
|
326
|
+
const ot = `
|
|
314
327
|
/* Card geometry, through the renderer's OWN theme vars rather than over the top
|
|
315
328
|
of them. It declares --malloy-theme--dashboard-* on .malloy-render itself and
|
|
316
329
|
passes each through to the --malloy-render--* the card CSS reads, so a value
|
|
@@ -487,13 +500,13 @@ div.malloy-render .malloy-dashboard .dashboard-row-header {
|
|
|
487
500
|
.malloy-render .malloy-table .td.highlight:not(.${g}) {
|
|
488
501
|
cursor: inherit;
|
|
489
502
|
}
|
|
490
|
-
`,
|
|
491
|
-
function
|
|
492
|
-
if (typeof document > "u" || document.getElementById(
|
|
503
|
+
`, be = "publisher-malloy-renderer-overrides";
|
|
504
|
+
function at() {
|
|
505
|
+
if (typeof document > "u" || document.getElementById(be)) return;
|
|
493
506
|
const e = document.createElement("style");
|
|
494
|
-
e.id =
|
|
507
|
+
e.id = be, e.textContent = ot, document.head.appendChild(e);
|
|
495
508
|
}
|
|
496
|
-
function
|
|
509
|
+
function nt({
|
|
497
510
|
result: e,
|
|
498
511
|
height: t,
|
|
499
512
|
drill: r,
|
|
@@ -503,48 +516,48 @@ function ot({
|
|
|
503
516
|
}) {
|
|
504
517
|
const l = M(null), i = M(r);
|
|
505
518
|
i.current = r;
|
|
506
|
-
const h =
|
|
507
|
-
() =>
|
|
519
|
+
const h = ce(
|
|
520
|
+
() => Je((d) => i.current?.onClick(d)),
|
|
508
521
|
[]
|
|
509
522
|
), y = r !== void 0, k = M(!1), w = M(
|
|
510
523
|
null
|
|
511
|
-
),
|
|
524
|
+
), W = M(0), { theme: N, layers: K, mode: te } = ze(), re = ce(
|
|
512
525
|
() => ({
|
|
513
526
|
radius: N.ui.radius.tile,
|
|
514
|
-
padding: `${
|
|
527
|
+
padding: `${Re}px`
|
|
515
528
|
}),
|
|
516
529
|
[N.ui.radius.tile]
|
|
517
530
|
);
|
|
518
|
-
return
|
|
519
|
-
|
|
531
|
+
return ke(() => () => {
|
|
532
|
+
W.current += 1;
|
|
520
533
|
const d = w.current;
|
|
521
534
|
d?.viz.remove(), d?.node.remove(), w.current = null;
|
|
522
|
-
}, []),
|
|
535
|
+
}, []), xe(() => {
|
|
523
536
|
if (!l.current || !e) return;
|
|
524
|
-
|
|
525
|
-
const d = l.current,
|
|
526
|
-
let
|
|
527
|
-
const
|
|
528
|
-
let c, b, P = null,
|
|
537
|
+
at();
|
|
538
|
+
const d = l.current, ge = W.current += 1;
|
|
539
|
+
let U = !1;
|
|
540
|
+
const Y = () => !U && ge === W.current;
|
|
541
|
+
let c, b, P = null, G = 0, j = null, H = null, q = null, D = null, O = null, F = null, oe = null, ae = 0, A = null;
|
|
529
542
|
k.current = !1;
|
|
530
|
-
let p,
|
|
531
|
-
const
|
|
532
|
-
if (
|
|
533
|
-
const z =
|
|
543
|
+
let p, T;
|
|
544
|
+
const J = (v) => {
|
|
545
|
+
if (U || !v.firstElementChild || Z(p, T) === "container") return;
|
|
546
|
+
const z = Se(p, T);
|
|
534
547
|
if (k.current && !z) return;
|
|
535
548
|
const L = d.hasAttribute($);
|
|
536
549
|
L && d.removeAttribute($);
|
|
537
550
|
const x = d.closest(
|
|
538
|
-
`.${
|
|
551
|
+
`.${_e}`
|
|
539
552
|
), u = x?.style.overflowY;
|
|
540
553
|
x && (x.style.overflowY = "hidden");
|
|
541
|
-
const S =
|
|
554
|
+
const S = De(
|
|
542
555
|
v,
|
|
543
|
-
|
|
556
|
+
ue(p)
|
|
544
557
|
);
|
|
545
|
-
x && (x.style.overflowY = u ?? ""), L && d.setAttribute($, ""), S > 0 && (k.current = !0, a && S !==
|
|
546
|
-
const C =
|
|
547
|
-
z && C &&
|
|
558
|
+
x && (x.style.overflowY = u ?? ""), L && d.setAttribute($, ""), S > 0 && (k.current = !0, a && S !== ae && (ae = S, a(S)));
|
|
559
|
+
const C = Oe(v, ue(p));
|
|
560
|
+
z && C && oe !== C && (oe = C, F?.disconnect(), F = new ResizeObserver(() => J(v)), F.observe(C));
|
|
548
561
|
};
|
|
549
562
|
return (async () => {
|
|
550
563
|
let v;
|
|
@@ -554,10 +567,10 @@ function ot({
|
|
|
554
567
|
console.error("Error parsing visualization result:", m);
|
|
555
568
|
return;
|
|
556
569
|
}
|
|
557
|
-
const z = await
|
|
558
|
-
if (!
|
|
570
|
+
const z = await tt(v), L = z ? Le([...K, Me(K, z)], te) : N;
|
|
571
|
+
if (!Y()) return;
|
|
559
572
|
try {
|
|
560
|
-
b = await
|
|
573
|
+
b = await et(
|
|
561
574
|
L,
|
|
562
575
|
h.onClick,
|
|
563
576
|
y ? h.onDrill : void 0
|
|
@@ -566,16 +579,16 @@ function ot({
|
|
|
566
579
|
console.error("Failed to create renderer:", m);
|
|
567
580
|
return;
|
|
568
581
|
}
|
|
569
|
-
if (!
|
|
582
|
+
if (!Y()) {
|
|
570
583
|
b.remove(), b = void 0;
|
|
571
584
|
return;
|
|
572
585
|
}
|
|
573
586
|
const x = w.current;
|
|
574
|
-
c = document.createElement("div"), c.style.width = "100%", c.style.height = "100%",
|
|
587
|
+
c = document.createElement("div"), c.style.width = "100%", c.style.height = "100%", rt(c, L, re), d.childElementCount > 0 && (d.style.position = "relative", c.style.position = "absolute", c.style.inset = "0", c.style.visibility = "hidden"), d.appendChild(c);
|
|
575
588
|
const u = c;
|
|
576
589
|
D = new MutationObserver(() => {
|
|
577
590
|
O && clearTimeout(O), O = setTimeout(() => {
|
|
578
|
-
|
|
591
|
+
J(u), k.current && D?.disconnect();
|
|
579
592
|
}, 100);
|
|
580
593
|
}), D.observe(c, {
|
|
581
594
|
childList: !0,
|
|
@@ -584,68 +597,68 @@ function ot({
|
|
|
584
597
|
});
|
|
585
598
|
const S = b;
|
|
586
599
|
let C = !1;
|
|
587
|
-
const
|
|
588
|
-
if (!(C || !
|
|
589
|
-
C = !0,
|
|
600
|
+
const ne = () => {
|
|
601
|
+
if (!(C || !Y())) {
|
|
602
|
+
C = !0, A && (clearTimeout(A), A = null), x?.viz.remove();
|
|
590
603
|
for (const m of Array.from(d.children))
|
|
591
604
|
m !== u && d.removeChild(m);
|
|
592
|
-
u.style.position = "", u.style.inset = "", u.style.visibility = "", d.style.position = "", w.current = { viz: S, node: u },
|
|
605
|
+
u.style.position = "", u.style.inset = "", u.style.visibility = "", d.style.position = "", w.current = { viz: S, node: u }, J(u);
|
|
593
606
|
}
|
|
594
607
|
};
|
|
595
608
|
try {
|
|
596
|
-
b.setResult(
|
|
609
|
+
b.setResult(We(v));
|
|
597
610
|
try {
|
|
598
611
|
const R = b.getMetadata(), E = R?.getRootField();
|
|
599
|
-
y &&
|
|
612
|
+
y && Ze(E), p = E?.renderAs(), T = E ? R?.getPluginsForField(E.key)?.[0]?.sizingStrategy : void 0;
|
|
600
613
|
} catch {
|
|
601
|
-
p = void 0,
|
|
614
|
+
p = void 0, T = void 0;
|
|
602
615
|
}
|
|
603
|
-
o?.(
|
|
604
|
-
const m =
|
|
616
|
+
o?.(Z(p, T), p), c.dataset.malloyRenderAs = p ?? "unknown", c.dataset.malloySizing = Z(p, T);
|
|
617
|
+
const m = Ge(p, v);
|
|
605
618
|
c.style.minWidth = m === void 0 ? "" : `${m}px`, d.style.overflowX = m === void 0 ? "" : "auto", d.style.overflowY = m === void 0 ? "" : "hidden", b.render(c);
|
|
606
|
-
const
|
|
619
|
+
const le = i.current;
|
|
607
620
|
try {
|
|
608
|
-
if (
|
|
609
|
-
const R =
|
|
621
|
+
if (le) {
|
|
622
|
+
const R = Ie(b, le.canDrill), E = () => {
|
|
610
623
|
try {
|
|
611
|
-
|
|
624
|
+
$e(u, R);
|
|
612
625
|
} catch (s) {
|
|
613
626
|
console.warn("Drill affordance skipped:", s);
|
|
614
627
|
}
|
|
615
628
|
};
|
|
616
629
|
E();
|
|
617
|
-
const
|
|
618
|
-
const _ = s.querySelector(".cell-content") ?? s,
|
|
630
|
+
const ie = (s) => {
|
|
631
|
+
const _ = s.querySelector(".cell-content") ?? s, Q = _.getBoundingClientRect();
|
|
619
632
|
_.dispatchEvent(
|
|
620
633
|
new MouseEvent("click", {
|
|
621
634
|
bubbles: !0,
|
|
622
635
|
cancelable: !0,
|
|
623
636
|
view: _.ownerDocument.defaultView,
|
|
624
|
-
clientX: Math.round(
|
|
625
|
-
clientY: Math.round(
|
|
637
|
+
clientX: Math.round(Q.left + Q.width / 2),
|
|
638
|
+
clientY: Math.round(Q.bottom)
|
|
626
639
|
})
|
|
627
640
|
);
|
|
628
|
-
},
|
|
629
|
-
|
|
641
|
+
}, se = (s) => s.target?.closest?.(`.${g}`) ?? null, ve = (s, f) => {
|
|
642
|
+
he(s, f)?.focus();
|
|
630
643
|
};
|
|
631
644
|
j = (s) => {
|
|
632
|
-
const f =
|
|
645
|
+
const f = se(s);
|
|
633
646
|
if (!f) return;
|
|
634
647
|
const _ = s.key === "ArrowDown" ? 1 : s.key === "ArrowUp" ? -1 : s.key === "Home" ? "first" : s.key === "End" ? "last" : void 0;
|
|
635
648
|
if (_ !== void 0) {
|
|
636
|
-
s.preventDefault(),
|
|
649
|
+
s.preventDefault(), ve(f, _);
|
|
637
650
|
return;
|
|
638
651
|
}
|
|
639
|
-
s.key === "Enter" ? (s.preventDefault(),
|
|
652
|
+
s.key === "Enter" ? (s.preventDefault(), ie(f)) : s.key === " " && s.preventDefault();
|
|
640
653
|
}, H = (s) => {
|
|
641
654
|
if (s.key !== " ") return;
|
|
642
|
-
const f =
|
|
643
|
-
f && (s.preventDefault(),
|
|
655
|
+
const f = se(s);
|
|
656
|
+
f && (s.preventDefault(), ie(f));
|
|
644
657
|
}, q = (s) => {
|
|
645
658
|
const f = s.target?.closest?.(`.${g}`);
|
|
646
|
-
f &&
|
|
659
|
+
f && he(f, 0);
|
|
647
660
|
}, u.addEventListener("keydown", j), u.addEventListener("keyup", H), u.addEventListener("focusin", q), R.size > 0 && typeof MutationObserver < "u" && (P = new MutationObserver(() => {
|
|
648
|
-
cancelAnimationFrame(
|
|
661
|
+
cancelAnimationFrame(G), G = requestAnimationFrame(E);
|
|
649
662
|
}), P.observe(u, {
|
|
650
663
|
childList: !0,
|
|
651
664
|
subtree: !0
|
|
@@ -654,12 +667,12 @@ function ot({
|
|
|
654
667
|
} catch (R) {
|
|
655
668
|
console.warn("Drill affordance skipped:", R);
|
|
656
669
|
}
|
|
657
|
-
b.onReady(
|
|
670
|
+
b.onReady(ne), A = setTimeout(ne, 1e4);
|
|
658
671
|
} catch (m) {
|
|
659
672
|
console.error("Error rendering visualization:", m), D?.disconnect(), F?.disconnect(), P?.disconnect(), b.remove(), b = void 0, u.parentNode === d && d.removeChild(u);
|
|
660
673
|
}
|
|
661
674
|
})(), () => {
|
|
662
|
-
|
|
675
|
+
U = !0, D?.disconnect(), F?.disconnect(), O && clearTimeout(O), A && clearTimeout(A), c && w.current?.node !== c && (j && c.removeEventListener("keydown", j), H && c.removeEventListener("keyup", H), q && c.removeEventListener("focusin", q), P?.disconnect(), cancelAnimationFrame(G), b?.remove(), c.parentNode === d && d.removeChild(c), d.style.position = "");
|
|
663
676
|
};
|
|
664
677
|
}, [
|
|
665
678
|
e,
|
|
@@ -668,9 +681,9 @@ function ot({
|
|
|
668
681
|
a,
|
|
669
682
|
o,
|
|
670
683
|
N,
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
684
|
+
K,
|
|
685
|
+
te,
|
|
686
|
+
re
|
|
674
687
|
]), /* @__PURE__ */ I(
|
|
675
688
|
"div",
|
|
676
689
|
{
|
|
@@ -683,9 +696,9 @@ function ot({
|
|
|
683
696
|
}
|
|
684
697
|
);
|
|
685
698
|
}
|
|
686
|
-
function
|
|
699
|
+
function lt(e) {
|
|
687
700
|
return typeof window > "u" ? /* @__PURE__ */ I(
|
|
688
|
-
|
|
701
|
+
de,
|
|
689
702
|
{
|
|
690
703
|
sx: {
|
|
691
704
|
width: "100%",
|
|
@@ -698,10 +711,10 @@ function at(e) {
|
|
|
698
711
|
children: "Loading..."
|
|
699
712
|
}
|
|
700
713
|
) : /* @__PURE__ */ I(
|
|
701
|
-
|
|
714
|
+
we,
|
|
702
715
|
{
|
|
703
716
|
fallback: /* @__PURE__ */ I(
|
|
704
|
-
|
|
717
|
+
de,
|
|
705
718
|
{
|
|
706
719
|
sx: {
|
|
707
720
|
width: "100%",
|
|
@@ -714,21 +727,22 @@ function at(e) {
|
|
|
714
727
|
children: "Loading visualization..."
|
|
715
728
|
}
|
|
716
729
|
),
|
|
717
|
-
children: /* @__PURE__ */ I(
|
|
730
|
+
children: /* @__PURE__ */ I(nt, { ...e })
|
|
718
731
|
}
|
|
719
732
|
);
|
|
720
733
|
}
|
|
721
|
-
const
|
|
734
|
+
const ht = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
722
735
|
__proto__: null,
|
|
723
|
-
default:
|
|
736
|
+
default: lt,
|
|
737
|
+
pageAllowsEval: pe
|
|
724
738
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
725
739
|
export {
|
|
726
740
|
g as D,
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
741
|
+
lt as R,
|
|
742
|
+
Pe as a,
|
|
743
|
+
Ne as b,
|
|
744
|
+
ht as c,
|
|
745
|
+
Ie as d,
|
|
746
|
+
$e as m,
|
|
747
|
+
je as r
|
|
734
748
|
};
|