@malloy-publisher/app 0.0.77 → 0.0.78

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.
@@ -0,0 +1 @@
1
+ "use strict";var b=Object.create;var p=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var C=(e,t,n,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of v(t))!j.call(e,i)&&i!==n&&p(e,i,{get:()=>t[i],enumerable:!(l=m(t,i))||l.enumerable});return e};var E=(e,t,n)=>(n=e!=null?b(x(e)):{},C(t||!e||!e.__esModule?p(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),f=require("react"),L=async e=>{if(typeof window>"u")throw new Error("MalloyRenderer can only be used in browser environment");const{MalloyRenderer:t}=await import("@malloydata/render");return new t({onClick:e}).createViz()};function N({result:e,height:t,isFillElement:n,onSizeChange:l,onDrill:i}){const d=f.useRef(null),[g,h]=f.useState(!1);return f.useLayoutEffect(()=>{if(!d.current||!e)return;let r=!0;const o=d.current;for(;o.firstChild;)o.removeChild(o.firstChild);return L(i).then(u=>{if(!r)return;const s=new MutationObserver(c=>{for(const y of c)if(y.type==="childList"&&y.addedNodes.length>0&&Array.from(y.addedNodes).some(w=>w.nodeType===Node.ELEMENT_NODE)){s.disconnect(),setTimeout(()=>{r&&h(!0)},50);break}});s.observe(o,{childList:!0,subtree:!0,characterData:!0});try{u.setResult(JSON.parse(e)),u.render(o)}catch(c){console.error("Error rendering visualization:",c),s.disconnect(),r&&h(!0)}}).catch(u=>{console.error("Failed to create renderer:",u),r&&h(!0)}),()=>{r=!1}},[e,i]),f.useEffect(()=>{if(!d.current||!g)return;const r=d.current,o=()=>{if(r){const c=r.offsetHeight;c>0?l&&l(c):n&&r.firstChild&&(r.firstChild.offsetHeight==0?n(!0):n(!1))}},u=setTimeout(o,100);let s=null;return s=new MutationObserver(o),s.observe(r,{childList:!0,subtree:!0,attributes:!0}),()=>{clearTimeout(u),s?.disconnect()}},[l,e,n,g]),a.jsx("div",{ref:d,style:{width:"100%",height:t?`${t}px`:"100%"}})}function M(e){return typeof window>"u"?a.jsx("div",{style:{width:"100%",height:e.height?`${e.height}px`:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#666"},children:"Loading..."}):a.jsx(f.Suspense,{fallback:a.jsx("div",{style:{width:"100%",height:e.height?`${e.height}px`:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#666"},children:"Loading visualization..."}),children:a.jsx(N,{...e})})}exports.default=M;
@@ -0,0 +1,117 @@
1
+ import { jsx as l } from "react/jsx-runtime";
2
+ import { Suspense as p, useRef as m, useState as w, useLayoutEffect as b, useEffect as v } from "react";
3
+ const C = async (e) => {
4
+ if (typeof window > "u")
5
+ throw new Error("MalloyRenderer can only be used in browser environment");
6
+ const { MalloyRenderer: u } = await import("@malloydata/render");
7
+ return new u({
8
+ onClick: e
9
+ }).createViz();
10
+ };
11
+ function E({
12
+ result: e,
13
+ height: u,
14
+ isFillElement: c,
15
+ onSizeChange: d,
16
+ onDrill: h
17
+ }) {
18
+ const s = m(null), [y, a] = w(!1);
19
+ return b(() => {
20
+ if (!s.current || !e) return;
21
+ let t = !0;
22
+ const r = s.current;
23
+ for (; r.firstChild; )
24
+ r.removeChild(r.firstChild);
25
+ return C(h).then((i) => {
26
+ if (!t) return;
27
+ const n = new MutationObserver((o) => {
28
+ for (const f of o)
29
+ if (f.type === "childList" && f.addedNodes.length > 0 && Array.from(f.addedNodes).some(
30
+ (g) => g.nodeType === Node.ELEMENT_NODE
31
+ )) {
32
+ n.disconnect(), setTimeout(() => {
33
+ t && a(!0);
34
+ }, 50);
35
+ break;
36
+ }
37
+ });
38
+ n.observe(r, {
39
+ childList: !0,
40
+ subtree: !0,
41
+ characterData: !0
42
+ });
43
+ try {
44
+ i.setResult(JSON.parse(e)), i.render(r);
45
+ } catch (o) {
46
+ console.error("Error rendering visualization:", o), n.disconnect(), t && a(!0);
47
+ }
48
+ }).catch((i) => {
49
+ console.error("Failed to create renderer:", i), t && a(!0);
50
+ }), () => {
51
+ t = !1;
52
+ };
53
+ }, [e, h]), v(() => {
54
+ if (!s.current || !y) return;
55
+ const t = s.current, r = () => {
56
+ if (t) {
57
+ const o = t.offsetHeight;
58
+ o > 0 ? d && d(o) : c && t.firstChild && (t.firstChild.offsetHeight == 0 ? c(!0) : c(!1));
59
+ }
60
+ }, i = setTimeout(r, 100);
61
+ let n = null;
62
+ return n = new MutationObserver(r), n.observe(t, {
63
+ childList: !0,
64
+ subtree: !0,
65
+ attributes: !0
66
+ }), () => {
67
+ clearTimeout(i), n?.disconnect();
68
+ };
69
+ }, [d, e, c, y]), /* @__PURE__ */ l(
70
+ "div",
71
+ {
72
+ ref: s,
73
+ style: {
74
+ width: "100%",
75
+ height: u ? `${u}px` : "100%"
76
+ }
77
+ }
78
+ );
79
+ }
80
+ function N(e) {
81
+ return typeof window > "u" ? /* @__PURE__ */ l(
82
+ "div",
83
+ {
84
+ style: {
85
+ width: "100%",
86
+ height: e.height ? `${e.height}px` : "100%",
87
+ display: "flex",
88
+ alignItems: "center",
89
+ justifyContent: "center",
90
+ color: "#666"
91
+ },
92
+ children: "Loading..."
93
+ }
94
+ ) : /* @__PURE__ */ l(
95
+ p,
96
+ {
97
+ fallback: /* @__PURE__ */ l(
98
+ "div",
99
+ {
100
+ style: {
101
+ width: "100%",
102
+ height: e.height ? `${e.height}px` : "100%",
103
+ display: "flex",
104
+ alignItems: "center",
105
+ justifyContent: "center",
106
+ color: "#666"
107
+ },
108
+ children: "Loading visualization..."
109
+ }
110
+ ),
111
+ children: /* @__PURE__ */ l(E, { ...e })
112
+ }
113
+ );
114
+ }
115
+ export {
116
+ N as default
117
+ };