@xyo-network/react-embed 2.78.0 → 2.78.2

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.
@@ -1,2 +1,514 @@
1
- "use strict";var X=Object.defineProperty;var ar=Object.getOwnPropertyDescriptor;var ir=Object.getOwnPropertyNames;var lr=Object.prototype.hasOwnProperty;var nr=(r,e)=>{for(var o in e)X(r,o,{get:e[o],enumerable:!0})},sr=(r,e,o,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of ir(e))!lr.call(r,a)&&a!==o&&X(r,a,{get:()=>e[a],enumerable:!(t=ar(e,a))||t.enumerable});return r};var dr=r=>sr(X({},"__esModule",{value:!0}),r);var yr={};nr(yr,{ApiEmbedPluginCard:()=>hr,BusyCard:()=>Y,EmbedCardHeader:()=>ae,EmbedPlugin:()=>$,EmbedPluginCard:()=>$,EmbedPluginCardInner:()=>er,EmbedPluginContext:()=>I,EmbedPluginInner:()=>ie,EmbedPluginProvider:()=>Z,RefreshPayloadProvider:()=>j,ResolvePayloadContext:()=>B,ResolvePayloadProvider:()=>ee,ValidatePayloadProvider:()=>oe,useEmbedPluginState:()=>c,useRefreshPayload:()=>L,useResolvePayload:()=>s,useValidatePayload:()=>te});module.exports=dr(yr);var ne=require("@mui/material"),se=require("@xylabs/react-flexbox"),V=require("@xylabs/react-shared"),A=require("react/jsx-runtime"),Y=({busy:r,busyMinimum:e=500,busyVariant:o="circular",busyVariantProps:t,children:a,...l})=>{let i=(0,se.useBusyTiming)(r,e);return(0,A.jsxs)(ne.Card,{...l,children:[a,o==="circular"&&i?(0,A.jsx)(V.BusyCircularProgress,{...t}):null,o==="linear"&&i?(0,A.jsx)(V.BusyLinearProgress,{...t}):null]})};var We=require("@mui/icons-material"),x=require("@mui/material"),Ve=require("@xylabs/react-flexbox");var de=require("@xyo-network/react-shared"),I=(0,de.createContextEx)();var w=require("react");var me=require("react/jsx-runtime"),Z=({children:r,refreshTitle:e,timestampLabel:o,hideElementsConfig:t,plugins:a,embedPluginConfig:l})=>{let[i,n]=(0,w.useState)(a?a[0]:void 0);return(0,w.useEffect)(()=>{n(a?a[0]:void 0)},[a]),(0,me.jsx)(I.Provider,{value:{activePlugin:i,embedPluginConfig:l,hideElementsConfig:t,provided:!0,refreshTitle:e,setActivePlugin:n,timestampLabel:o},children:r})};var pe=require("@xyo-network/react-shared");var c=()=>(0,pe.useContextEx)(I,"EmbedPlugin",!0);var Pe=require("react");var ue=require("@xyo-network/react-shared"),T=(0,ue.createContextEx)();var ce=require("react/jsx-runtime"),j=({children:r,onRefresh:e,refreshPayload:o})=>{let[t,a]=(0,Pe.useState)(o);return(0,ce.jsx)(T.Provider,{value:{onRefresh:e,provided:!0,refreshPayload:t,setRefreshPayload:a},children:r})};var fe=require("@xyo-network/react-shared");var L=()=>(0,fe.useContextEx)(T,"RefreshPayload",!0);var Ce=require("@xyo-network/react-shared"),B=(0,Ce.createContextEx)();var he=require("@xylabs/delay"),ye=require("@xylabs/react-async-effect"),Ee=require("@xyo-network/huri"),ve=require("@xyo-network/payload-model"),E=require("react");var be=require("react/jsx-runtime"),ee=({children:r,huriPayload:e})=>{let[o,t]=(0,E.useState)(),[a,l]=(0,E.useState)(),{refreshPayload:i,setRefreshPayload:n,onRefresh:P}=L();(0,E.useEffect)(()=>{typeof e=="string"&&l(e),typeof e=="object"&&(t(e),n?.(!0))},[e,n]);let[F,b]=(0,E.useState)(),[Q,rr]=(0,E.useState)();(0,ye.useAsyncEffect)(async tr=>{if(a&&!i)try{let U=await new Ee.Huri(a).fetch();await(0,he.delay)(500),tr()&&(b(U===null),t(U),n?.(!0))}catch(le){rr({message:le.message,schema:ve.ModuleErrorSchema,sources:[]})}},[a,o,i,n]);let or=()=>{P?.(),a&&n?.(!1)};return(0,be.jsx)(B.Provider,{value:{huri:a,huriError:Q,notFound:F,payload:o,provided:!0,refreshHuri:or,setPayload:t},children:r})};var Re=require("@xyo-network/react-shared");var s=()=>(0,Re.useContextEx)(B,"ResolvePayload",!0);var xe=require("@mui/material"),Me=require("@xylabs/react-async-effect"),H=require("@xyo-network/schema-cache"),re=require("react");var ge=require("@xyo-network/react-shared"),k=(0,ge.createContextEx)();var R=require("react/jsx-runtime"),oe=({children:r,enabled:e=!1})=>{let{payload:o}=s(),[t,a]=(0,re.useState)(!1),[l,i]=(0,re.useState)();return(0,Me.useAsyncEffect)(async()=>{if(o&&e){await H.SchemaCache.instance.get(o.schema);let n=o.schema;if(H.SchemaCache.instance.validators[n]){let P=H.SchemaCache.instance.validators[n];i(P?.(o))}a(!0)}},[o,e]),(0,R.jsx)(k.Provider,{value:{enabled:e,provided:!0,schema:o?.schema,validPayload:l},children:e?(0,R.jsx)(R.Fragment,{children:t?r:(0,R.jsx)(xe.Chip,{label:"Validating Payload..."})}):r})};var Se=require("@xyo-network/react-shared");var te=()=>(0,Se.useContextEx)(k,"ValidateSchema",!0);var Ie=require("@mui/icons-material"),D=require("@mui/material"),Le=require("react");var Fe=require("@mui/icons-material"),g=require("@mui/material");var f=require("react/jsx-runtime"),Ae=r=>{let{huri:e}=s();return(0,f.jsx)(f.Fragment,{children:e?(0,f.jsxs)(g.MenuItem,{title:"Source Payload JSON",onClick:()=>window.open(e,"_blank"),...r,children:[(0,f.jsx)(g.ListItemText,{sx:{mr:1},children:"JSON"}),(0,f.jsx)(g.ListItemIcon,{sx:{justifyContent:"end"},children:(0,f.jsx)(Fe.OpenInNew,{fontSize:"small"})})]}):null})};var C=require("react/jsx-runtime"),Be=r=>{let[e,o]=(0,Le.useState)(null),t=!!e,a=i=>{o(i.currentTarget)},l=()=>{o(null)};return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(D.IconButton,{onClick:a,...r,children:(0,C.jsx)(Ie.MoreVert,{})}),(0,C.jsx)(D.Menu,{anchorEl:e,open:t,onClose:l,PaperProps:{variant:"elevation"},MenuListProps:{dense:!0},children:(0,C.jsx)(Ae,{})})]})};var d=require("react/jsx-runtime"),ae=()=>{let{refreshHuri:r,huri:e}=s(),{activePlugin:o,timestampLabel:t,hideElementsConfig:a}=c(),{hideAvatar:l,hideTitle:i,hideRefreshButton:n,hideTimestamp:P,hideCardActions:F}=a??{},b=Date.now();return(0,d.jsx)(x.CardHeader,{sx:{flexWrap:"wrap",rowGap:1},avatar:l?(0,d.jsx)(d.Fragment,{}):(0,d.jsx)(x.Avatar,{sx:{bgcolor:Q=>Q.palette.primary.main},"aria-label":o?.name,children:o?.name?.charAt(0)}),action:(0,d.jsxs)(Ve.FlexRow,{flexWrap:"wrap",columnGap:.5,children:[b?P&&n?"":(0,d.jsx)(x.Chip,{avatar:n?(0,d.jsx)(d.Fragment,{}):(0,d.jsx)(We.Refresh,{}),clickable:!n,onClick:r,label:P?"":`${t} ${new Date(b).toLocaleString()}`}):null,F||e===void 0?null:(0,d.jsx)(Be,{})]}),title:i?"":o?.name})};var Oe=require("@mui/material"),Je=require("@xylabs/react-flexbox"),$e=require("@xyo-network/react-shared");var z=require("@mui/material"),N=require("react/jsx-runtime"),G=({formId:r,formLabel:e,children:o,...t})=>(0,N.jsxs)(z.FormControl,{...t,children:[(0,N.jsx)(z.InputLabel,{id:r,children:e}),o]});var O=require("@mui/material"),ke=require("@xylabs/react-select"),He=require("@xyo-network/react-shared");var y=require("react/jsx-runtime"),we="listmode-select-id",Te="List Mode",mr=r=>{let{listMode:e,setListMode:o}=(0,He.useListMode)();return(0,y.jsxs)(ke.SelectEx,{value:e??"default",onChange:t=>{o?.(t.target.value)},...r,children:[(0,y.jsx)(O.MenuItem,{value:"default",children:"Default"},"default"),(0,y.jsx)(O.MenuItem,{value:"table",children:"Table"},"table"),(0,y.jsx)(O.MenuItem,{value:"grid",children:"Grid"},"grid")]})},De=r=>(0,y.jsx)(G,{formId:we,formLabel:Te,children:(0,y.jsx)(mr,{size:"small",label:Te,labelId:we,...r})});var ze=require("@mui/material"),Ge=require("@xylabs/react-select");var J=require("react/jsx-runtime"),pr="render-select-id",ur="Renderer",Ne=r=>{let{activePlugin:e,setActivePlugin:o,plugins:t}=c();return(0,J.jsx)(G,{formId:pr,formLabel:ur,children:(0,J.jsx)(Ge.SelectEx,{size:"small",value:e?.name,...r,children:t?.map(a=>(0,J.jsx)(ze.MenuItem,{value:a.name,onClick:()=>o?.(a),children:a.name},a.name))})})};var h=require("react/jsx-runtime"),$=({...r})=>{let{payload:e}=s(),{activePlugin:o,plugins:t,hideElementsConfig:a}=c(),{listMode:l}=(0,$e.useListMode)(),i=o?.components?.box?.listModes?.length??!1;return(0,h.jsxs)(Y,{...r,children:[a?.hideCardHeader?null:(0,h.jsx)(ae,{}),t&&t.length>0||i?(0,h.jsxs)(Je.FlexGrowRow,{columnGap:2,rowGap:2,flexWrap:"wrap",pb:1,children:[t&&t.length>1?(0,h.jsx)(Ne,{}):null,i?(0,h.jsx)(De,{}):null]}):null,(0,h.jsx)(Oe.CardContent,{sx:{height:"100%"},children:o?(0,h.jsx)(o.components.box.detailsBox,{payload:e,...i&&{listMode:l}}):null})]})};var je=require("@mui/material");var _=require("@xyo-network/react-shared");var Ke=require("@xyo-network/react-shared");var qe=require("react/jsx-runtime"),_e=({children:r})=>{let{payload:e,notFound:o,huriError:t}=s();return(0,qe.jsx)(Ke.LoadResult,{searchResult:e,notFound:!!o,error:!!t,children:r})};var Qe=require("@mui/material");var M=require("react/jsx-runtime"),Ue=({children:r,...e})=>{let{validPayload:o,enabled:t,schema:a}=te();return t&&o===!1?(0,M.jsxs)(Qe.Alert,{severity:"error",title:"Invalid Payload!",...e,children:["Payload schema claimed to be ",a," but failed to validate."]}):(0,M.jsx)(M.Fragment,{children:r})};var K=require("@mui/material");var v=require("react/jsx-runtime"),Xe=({children:r,...e})=>{let{payload:o}=s(),{plugins:t}=c();return o&&t?.length===0?(0,v.jsxs)(K.Alert,{severity:"warning",...e,children:[(0,v.jsx)(K.AlertTitle,{children:"Missing plugins!"}),"Payload found but no plugins were present."]}):(0,v.jsx)(v.Fragment,{children:r})};var p=require("react/jsx-runtime"),ie=({validateSchema:r,plugins:e=[],huriPayload:o,refreshTitle:t="",timestampLabel:a="Data From",hideElementsConfig:l,embedPluginConfig:i,onRefresh:n,children:P})=>(0,p.jsx)(_.ErrorBoundary,{children:(0,p.jsx)(Z,{refreshTitle:t,timestampLabel:a,hideElementsConfig:l,plugins:e,embedPluginConfig:i,children:(0,p.jsx)(Pr,{onRefresh:n,huriPayload:o,children:(0,p.jsx)(cr,{validateSchema:r,children:(0,p.jsx)(_.ListModeProvider,{defaultListMode:i?.listMode,children:P})})})})}),Pr=({children:r,onRefresh:e,huriPayload:o})=>(0,p.jsx)(j,{onRefresh:e,children:(0,p.jsx)(ee,{huriPayload:o,children:(0,p.jsx)(_e,{children:r})})}),cr=({children:r,validateSchema:e})=>(0,p.jsx)(oe,{enabled:e,children:(0,p.jsx)(Xe,{children:(0,p.jsx)(Ue,{children:r})})});var q=require("@xyo-network/react-error");var u=require("@mui/material"),m=require("react/jsx-runtime"),Ye=r=>{let{alertProps:e,error:o,hideErrorDetails:t=!0,children:a,...l}=r;return(0,m.jsx)(u.Card,{...l,children:(0,m.jsx)(u.CardContent,{children:a??(0,m.jsx)(fr,{...{alertProps:e,error:o,hideErrorDetails:t}})})})},fr=({alertProps:r,hideErrorDetails:e,error:o})=>(0,m.jsxs)(u.Alert,{severity:"error",...r,children:[(0,m.jsx)(u.AlertTitle,{children:"Whoops! Something went wrong"}),!e&&o?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(u.Typography,{variant:"caption",children:"Error: "}),(0,m.jsx)(u.Typography,{variant:"caption",children:o?.message})]}):(0,m.jsx)(u.Typography,{variant:"caption",fontSize:"small",children:"Error Loading Plugin"})]});var W=require("react/jsx-runtime"),Ze=({xyoError:r,children:e,...o})=>(0,W.jsx)(q.ErrorRender,{error:r,noReAuth:!0,noErrorDisplay:!0,customError:(0,W.jsx)(Cr,{xyoError:r,...o}),children:e}),Cr=({xyoError:r,...e})=>(0,W.jsx)(Ye,{...e,children:(0,W.jsx)(q.ErrorAlert,{error:r})});var S=require("react/jsx-runtime"),hr=({children:r,...e})=>{let{validateSchema:o,plugins:t=[],huriPayload:a,refreshTitle:l="",timestampLabel:i="Data From",hideElementsConfig:n,embedPluginConfig:P,onRefresh:F,...b}=e;return(0,S.jsxs)(ie,{embedPluginConfig:P,hideElementsConfig:n,huriPayload:a,onRefresh:F,plugins:t,refreshTitle:l,timestampLabel:i,validateSchema:o,children:[(0,S.jsx)(er,{...b}),r]})},er=r=>{let{payload:e,huriError:o}=s(),{refreshPayload:t}=L(),a=(0,je.useTheme)();return(0,S.jsx)(Ze,{xyoError:o,children:(0,S.jsx)($,{elevation:3,variant:"elevation",busy:!!(!t&&e),busyVariantProps:{style:{alignItems:"start",paddingTop:a.spacing(2),zIndex:2}},sx:{position:"relative"},...r})})};
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ ApiEmbedPluginCard: () => ApiEmbedPluginCard,
24
+ BusyCard: () => BusyCard,
25
+ EmbedCardHeader: () => EmbedCardHeader,
26
+ EmbedPlugin: () => EmbedPluginCard,
27
+ EmbedPluginCard: () => EmbedPluginCard,
28
+ EmbedPluginCardInner: () => EmbedPluginCardInner,
29
+ EmbedPluginContext: () => EmbedPluginContext,
30
+ EmbedPluginInner: () => EmbedPluginInner,
31
+ EmbedPluginProvider: () => EmbedPluginProvider,
32
+ RefreshPayloadProvider: () => RefreshPayloadProvider,
33
+ ResolvePayloadContext: () => ResolvePayloadContext,
34
+ ResolvePayloadProvider: () => ResolvePayloadProvider,
35
+ ValidatePayloadProvider: () => ValidatePayloadProvider,
36
+ useEmbedPluginState: () => useEmbedPluginState,
37
+ useRefreshPayload: () => useRefreshPayload,
38
+ useResolvePayload: () => useResolvePayload,
39
+ useValidatePayload: () => useValidatePayload
40
+ });
41
+ module.exports = __toCommonJS(src_exports);
42
+
43
+ // src/components/embed-card/card/BusyCard.tsx
44
+ var import_material = require("@mui/material");
45
+ var import_react_flexbox = require("@xylabs/react-flexbox");
46
+ var import_react_shared = require("@xylabs/react-shared");
47
+ var import_jsx_runtime = require("react/jsx-runtime");
48
+ var BusyCard = ({
49
+ busy,
50
+ busyMinimum = 500,
51
+ busyVariant = "circular",
52
+ busyVariantProps,
53
+ children,
54
+ ...props
55
+ }) => {
56
+ const internalBusy = (0, import_react_flexbox.useBusyTiming)(busy, busyMinimum);
57
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_material.Card, { ...props, children: [
58
+ children,
59
+ busyVariant === "circular" && internalBusy ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_shared.BusyCircularProgress, { ...busyVariantProps }) : null,
60
+ busyVariant === "linear" && internalBusy ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_shared.BusyLinearProgress, { ...busyVariantProps }) : null
61
+ ] });
62
+ };
63
+
64
+ // src/components/embed-card/card/EmbedCardHeader.tsx
65
+ var import_icons_material3 = require("@mui/icons-material");
66
+ var import_material5 = require("@mui/material");
67
+ var import_react_flexbox2 = require("@xylabs/react-flexbox");
68
+
69
+ // src/contexts/EmbedPluginContext/Context.tsx
70
+ var import_react_shared2 = require("@xyo-network/react-shared");
71
+ var EmbedPluginContext = (0, import_react_shared2.createContextEx)();
72
+
73
+ // src/contexts/EmbedPluginContext/Provider.tsx
74
+ var import_react = require("react");
75
+ var import_jsx_runtime2 = require("react/jsx-runtime");
76
+ var EmbedPluginProvider = ({
77
+ children,
78
+ refreshTitle,
79
+ timestampLabel,
80
+ hideElementsConfig,
81
+ plugins,
82
+ embedPluginConfig
83
+ }) => {
84
+ const [activePlugin, setActivePlugin] = (0, import_react.useState)(plugins ? plugins[0] : void 0);
85
+ (0, import_react.useEffect)(() => {
86
+ setActivePlugin(plugins ? plugins[0] : void 0);
87
+ }, [plugins]);
88
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
89
+ EmbedPluginContext.Provider,
90
+ {
91
+ value: {
92
+ activePlugin,
93
+ embedPluginConfig,
94
+ hideElementsConfig,
95
+ provided: true,
96
+ refreshTitle,
97
+ setActivePlugin,
98
+ timestampLabel
99
+ },
100
+ children
101
+ }
102
+ );
103
+ };
104
+
105
+ // src/contexts/EmbedPluginContext/use.tsx
106
+ var import_react_shared3 = require("@xyo-network/react-shared");
107
+ var useEmbedPluginState = () => (0, import_react_shared3.useContextEx)(EmbedPluginContext, "EmbedPlugin", true);
108
+
109
+ // src/contexts/RefreshPayloadContext/Provider.tsx
110
+ var import_react2 = require("react");
111
+
112
+ // src/contexts/RefreshPayloadContext/Context.tsx
113
+ var import_react_shared4 = require("@xyo-network/react-shared");
114
+ var RefreshPayloadContext = (0, import_react_shared4.createContextEx)();
115
+
116
+ // src/contexts/RefreshPayloadContext/Provider.tsx
117
+ var import_jsx_runtime3 = require("react/jsx-runtime");
118
+ var RefreshPayloadProvider = ({ children, onRefresh, refreshPayload }) => {
119
+ const [localRefreshPayload, setRefreshPayload] = (0, import_react2.useState)(refreshPayload);
120
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(RefreshPayloadContext.Provider, { value: { onRefresh, provided: true, refreshPayload: localRefreshPayload, setRefreshPayload }, children });
121
+ };
122
+
123
+ // src/contexts/RefreshPayloadContext/use.tsx
124
+ var import_react_shared5 = require("@xyo-network/react-shared");
125
+ var useRefreshPayload = () => (0, import_react_shared5.useContextEx)(RefreshPayloadContext, "RefreshPayload", true);
126
+
127
+ // src/contexts/ResolvePayloadContext/Context.ts
128
+ var import_react_shared6 = require("@xyo-network/react-shared");
129
+ var ResolvePayloadContext = (0, import_react_shared6.createContextEx)();
130
+
131
+ // src/contexts/ResolvePayloadContext/Provider.tsx
132
+ var import_delay = require("@xylabs/delay");
133
+ var import_react_async_effect = require("@xylabs/react-async-effect");
134
+ var import_huri = require("@xyo-network/huri");
135
+ var import_payload_model = require("@xyo-network/payload-model");
136
+ var import_react3 = require("react");
137
+ var import_jsx_runtime4 = require("react/jsx-runtime");
138
+ var ResolvePayloadProvider = ({ children, huriPayload }) => {
139
+ const [payload, setPayload] = (0, import_react3.useState)();
140
+ const [huri, setHuri] = (0, import_react3.useState)();
141
+ const { refreshPayload, setRefreshPayload, onRefresh } = useRefreshPayload();
142
+ (0, import_react3.useEffect)(() => {
143
+ typeof huriPayload === "string" ? setHuri(huriPayload) : void 0;
144
+ if (typeof huriPayload === "object") {
145
+ setPayload(huriPayload);
146
+ setRefreshPayload?.(true);
147
+ }
148
+ }, [huriPayload, setRefreshPayload]);
149
+ const [notFound, setNotFound] = (0, import_react3.useState)();
150
+ const [huriError, setHuriError] = (0, import_react3.useState)();
151
+ (0, import_react_async_effect.useAsyncEffect)(
152
+ // eslint-disable-next-line react-hooks/exhaustive-deps
153
+ async (mounted) => {
154
+ if (huri && !refreshPayload) {
155
+ try {
156
+ const huriInstance = new import_huri.Huri(huri);
157
+ const result = await huriInstance.fetch();
158
+ await (0, import_delay.delay)(500);
159
+ if (mounted()) {
160
+ setNotFound(result === null);
161
+ setPayload(result);
162
+ setRefreshPayload?.(true);
163
+ }
164
+ } catch (e) {
165
+ const error = e;
166
+ setHuriError({ message: error.message, schema: import_payload_model.ModuleErrorSchema, sources: [] });
167
+ }
168
+ }
169
+ },
170
+ [huri, payload, refreshPayload, setRefreshPayload]
171
+ );
172
+ const refreshHuri = () => {
173
+ onRefresh?.();
174
+ if (huri) {
175
+ setRefreshPayload?.(false);
176
+ }
177
+ };
178
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ResolvePayloadContext.Provider, { value: { huri, huriError, notFound, payload, provided: true, refreshHuri, setPayload }, children });
179
+ };
180
+
181
+ // src/contexts/ResolvePayloadContext/use.tsx
182
+ var import_react_shared7 = require("@xyo-network/react-shared");
183
+ var useResolvePayload = () => (0, import_react_shared7.useContextEx)(ResolvePayloadContext, "ResolvePayload", true);
184
+
185
+ // src/contexts/ValidatePayloadContext/Provider.tsx
186
+ var import_material2 = require("@mui/material");
187
+ var import_react_async_effect2 = require("@xylabs/react-async-effect");
188
+ var import_schema_cache = require("@xyo-network/schema-cache");
189
+ var import_react4 = require("react");
190
+
191
+ // src/contexts/ValidatePayloadContext/Context.ts
192
+ var import_react_shared8 = require("@xyo-network/react-shared");
193
+ var ValidatePayloadContext = (0, import_react_shared8.createContextEx)();
194
+
195
+ // src/contexts/ValidatePayloadContext/Provider.tsx
196
+ var import_jsx_runtime5 = require("react/jsx-runtime");
197
+ var ValidatePayloadProvider = ({ children, enabled = false }) => {
198
+ const { payload } = useResolvePayload();
199
+ const [initialized, setInitialized] = (0, import_react4.useState)(false);
200
+ const [valid, setValid] = (0, import_react4.useState)();
201
+ (0, import_react_async_effect2.useAsyncEffect)(
202
+ // eslint-disable-next-line react-hooks/exhaustive-deps
203
+ async () => {
204
+ if (payload && enabled) {
205
+ await import_schema_cache.SchemaCache.instance.get(payload.schema);
206
+ const possibleKnownSchema = payload.schema;
207
+ if (import_schema_cache.SchemaCache.instance.validators[possibleKnownSchema]) {
208
+ const validator = import_schema_cache.SchemaCache.instance.validators[possibleKnownSchema];
209
+ setValid(validator?.(payload));
210
+ }
211
+ setInitialized(true);
212
+ }
213
+ },
214
+ [payload, enabled]
215
+ );
216
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ValidatePayloadContext.Provider, { value: { enabled, provided: true, schema: payload?.schema, validPayload: valid }, children: enabled ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: initialized ? children : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_material2.Chip, { label: "Validating Payload..." }) }) : children });
217
+ };
218
+
219
+ // src/contexts/ValidatePayloadContext/use.tsx
220
+ var import_react_shared9 = require("@xyo-network/react-shared");
221
+ var useValidatePayload = () => (0, import_react_shared9.useContextEx)(ValidatePayloadContext, "ValidateSchema", true);
222
+
223
+ // src/components/embed-card/menu/EmbedMenu.tsx
224
+ var import_icons_material2 = require("@mui/icons-material");
225
+ var import_material4 = require("@mui/material");
226
+ var import_react5 = require("react");
227
+
228
+ // src/components/embed-card/menu/JsonMenuItem.tsx
229
+ var import_icons_material = require("@mui/icons-material");
230
+ var import_material3 = require("@mui/material");
231
+ var import_jsx_runtime6 = require("react/jsx-runtime");
232
+ var JsonMenuItem = (props) => {
233
+ const { huri } = useResolvePayload();
234
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_jsx_runtime6.Fragment, { children: huri ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_material3.MenuItem, { title: "Source Payload JSON", onClick: () => window.open(huri, "_blank"), ...props, children: [
235
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_material3.ListItemText, { sx: { mr: 1 }, children: "JSON" }),
236
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_material3.ListItemIcon, { sx: { justifyContent: "end" }, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_icons_material.OpenInNew, { fontSize: "small" }) })
237
+ ] }) : null });
238
+ };
239
+
240
+ // src/components/embed-card/menu/EmbedMenu.tsx
241
+ var import_jsx_runtime7 = require("react/jsx-runtime");
242
+ var EmbedMenu = (props) => {
243
+ const [anchorEl, setAnchorEl] = (0, import_react5.useState)(null);
244
+ const open = Boolean(anchorEl);
245
+ const handleClick = (event) => {
246
+ setAnchorEl(event.currentTarget);
247
+ };
248
+ const handleClose = () => {
249
+ setAnchorEl(null);
250
+ };
251
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
252
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_material4.IconButton, { onClick: handleClick, ...props, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_icons_material2.MoreVert, {}) }),
253
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_material4.Menu, { anchorEl, open, onClose: handleClose, PaperProps: { variant: "elevation" }, MenuListProps: { dense: true }, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(JsonMenuItem, {}) })
254
+ ] });
255
+ };
256
+
257
+ // src/components/embed-card/card/EmbedCardHeader.tsx
258
+ var import_jsx_runtime8 = require("react/jsx-runtime");
259
+ var EmbedCardHeader = () => {
260
+ const { refreshHuri, huri } = useResolvePayload();
261
+ const { activePlugin, timestampLabel, hideElementsConfig } = useEmbedPluginState();
262
+ const { hideAvatar, hideTitle, hideRefreshButton, hideTimestamp, hideCardActions } = hideElementsConfig ?? {};
263
+ const timestamp = Date.now();
264
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
265
+ import_material5.CardHeader,
266
+ {
267
+ sx: { flexWrap: "wrap", rowGap: 1 },
268
+ avatar: hideAvatar ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, {}) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_material5.Avatar, { sx: { bgcolor: (theme) => theme.palette.primary.main }, "aria-label": activePlugin?.name, children: activePlugin?.name?.charAt(0) }),
269
+ action: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_react_flexbox2.FlexRow, { flexWrap: "wrap", columnGap: 0.5, children: [
270
+ timestamp ? hideTimestamp && hideRefreshButton ? "" : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
271
+ import_material5.Chip,
272
+ {
273
+ avatar: hideRefreshButton ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, {}) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_icons_material3.Refresh, {}),
274
+ clickable: hideRefreshButton ? false : true,
275
+ onClick: refreshHuri,
276
+ label: hideTimestamp ? "" : `${timestampLabel} ${new Date(timestamp).toLocaleString()}`
277
+ }
278
+ ) : null,
279
+ hideCardActions || huri === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(EmbedMenu, {})
280
+ ] }),
281
+ title: hideTitle ? "" : activePlugin?.name
282
+ }
283
+ );
284
+ };
285
+
286
+ // src/components/embed-card/card/EmbedPluginCard.tsx
287
+ var import_material9 = require("@mui/material");
288
+ var import_react_flexbox3 = require("@xylabs/react-flexbox");
289
+ var import_react_shared11 = require("@xyo-network/react-shared");
290
+
291
+ // src/components/controls/EmbedFormControl.tsx
292
+ var import_material6 = require("@mui/material");
293
+ var import_jsx_runtime9 = require("react/jsx-runtime");
294
+ var EmbedFormControl = ({ formId, formLabel, children, ...props }) => {
295
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_material6.FormControl, { ...props, children: [
296
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_material6.InputLabel, { id: formId, children: formLabel }),
297
+ children
298
+ ] });
299
+ };
300
+
301
+ // src/components/controls/ListModeSelect.tsx
302
+ var import_material7 = require("@mui/material");
303
+ var import_react_select = require("@xylabs/react-select");
304
+ var import_react_shared10 = require("@xyo-network/react-shared");
305
+ var import_jsx_runtime10 = require("react/jsx-runtime");
306
+ var listModeSelectId = "listmode-select-id";
307
+ var listModeSelectLabel = "List Mode";
308
+ var ListModeSelect = (props) => {
309
+ const { listMode, setListMode } = (0, import_react_shared10.useListMode)();
310
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
311
+ import_react_select.SelectEx,
312
+ {
313
+ value: listMode ?? "default",
314
+ onChange: (event) => {
315
+ setListMode?.(event.target.value);
316
+ },
317
+ ...props,
318
+ children: [
319
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_material7.MenuItem, { value: "default", children: "Default" }, "default"),
320
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_material7.MenuItem, { value: "table", children: "Table" }, "table"),
321
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_material7.MenuItem, { value: "grid", children: "Grid" }, "grid")
322
+ ]
323
+ }
324
+ );
325
+ };
326
+ var ListModeSelectFormControl = (props) => {
327
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(EmbedFormControl, { formId: listModeSelectId, formLabel: listModeSelectLabel, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ListModeSelect, { size: "small", label: listModeSelectLabel, labelId: listModeSelectId, ...props }) });
328
+ };
329
+
330
+ // src/components/controls/RenderSelect.tsx
331
+ var import_material8 = require("@mui/material");
332
+ var import_react_select2 = require("@xylabs/react-select");
333
+ var import_jsx_runtime11 = require("react/jsx-runtime");
334
+ var renderSelectId = "render-select-id";
335
+ var renderSelectLabel = "Renderer";
336
+ var EmbedRenderSelect = (props) => {
337
+ const { activePlugin, setActivePlugin, plugins } = useEmbedPluginState();
338
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(EmbedFormControl, { formId: renderSelectId, formLabel: renderSelectLabel, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react_select2.SelectEx, { size: "small", value: activePlugin?.name, ...props, children: plugins?.map((plugin) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_material8.MenuItem, { value: plugin.name, onClick: () => setActivePlugin?.(plugin), children: plugin.name }, plugin.name)) }) });
339
+ };
340
+
341
+ // src/components/embed-card/card/EmbedPluginCard.tsx
342
+ var import_jsx_runtime12 = require("react/jsx-runtime");
343
+ var EmbedPluginCard = ({ ...props }) => {
344
+ const { payload } = useResolvePayload();
345
+ const { activePlugin: ActivePlugin, plugins, hideElementsConfig } = useEmbedPluginState();
346
+ const { listMode } = (0, import_react_shared11.useListMode)();
347
+ const supportsListMode = ActivePlugin?.components?.box?.listModes?.length ?? 0 > 1;
348
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(BusyCard, { ...props, children: [
349
+ hideElementsConfig?.hideCardHeader ? null : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(EmbedCardHeader, {}),
350
+ plugins && plugins.length > 0 || supportsListMode ? /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_react_flexbox3.FlexGrowRow, { columnGap: 2, rowGap: 2, flexWrap: "wrap", pb: 1, children: [
351
+ plugins && plugins.length > 1 ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(EmbedRenderSelect, {}) : null,
352
+ supportsListMode ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ListModeSelectFormControl, {}) : null
353
+ ] }) : null,
354
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material9.CardContent, { sx: { height: "100%" }, children: ActivePlugin ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ActivePlugin.components.box.detailsBox, { payload, ...supportsListMode && { listMode } }) : null })
355
+ ] });
356
+ };
357
+
358
+ // src/components/embed-card/EmbedPluginCard.tsx
359
+ var import_material13 = require("@mui/material");
360
+
361
+ // src/components/EmbedPlugin.tsx
362
+ var import_react_shared13 = require("@xyo-network/react-shared");
363
+
364
+ // src/components/EmbedResolver.tsx
365
+ var import_react_shared12 = require("@xyo-network/react-shared");
366
+ var import_jsx_runtime13 = require("react/jsx-runtime");
367
+ var EmbedResolver = ({ children }) => {
368
+ const { payload, notFound, huriError } = useResolvePayload();
369
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_react_shared12.LoadResult, { searchResult: payload, notFound: !!notFound, error: !!huriError, children });
370
+ };
371
+
372
+ // src/components/validation-alerts/ValidatePayload.tsx
373
+ var import_material10 = require("@mui/material");
374
+ var import_jsx_runtime14 = require("react/jsx-runtime");
375
+ var ValidatePayloadAlert = ({ children, ...props }) => {
376
+ const { validPayload, enabled, schema } = useValidatePayload();
377
+ if (enabled && validPayload === false) {
378
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_material10.Alert, { severity: "error", title: "Invalid Payload!", ...props, children: [
379
+ "Payload schema claimed to be ",
380
+ schema,
381
+ " but failed to validate."
382
+ ] });
383
+ }
384
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_jsx_runtime14.Fragment, { children });
385
+ };
386
+
387
+ // src/components/validation-alerts/ValidatePlugins.tsx
388
+ var import_material11 = require("@mui/material");
389
+ var import_jsx_runtime15 = require("react/jsx-runtime");
390
+ var ValidatePluginsAlert = ({ children, ...props }) => {
391
+ const { payload } = useResolvePayload();
392
+ const { plugins } = useEmbedPluginState();
393
+ if (payload && plugins?.length === 0) {
394
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_material11.Alert, { severity: "warning", ...props, children: [
395
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_material11.AlertTitle, { children: "Missing plugins!" }),
396
+ "Payload found but no plugins were present."
397
+ ] });
398
+ }
399
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children });
400
+ };
401
+
402
+ // src/components/EmbedPlugin.tsx
403
+ var import_jsx_runtime16 = require("react/jsx-runtime");
404
+ var EmbedPluginInner = ({
405
+ validateSchema,
406
+ plugins = [],
407
+ huriPayload,
408
+ refreshTitle = "",
409
+ timestampLabel = "Data From",
410
+ hideElementsConfig,
411
+ embedPluginConfig,
412
+ onRefresh,
413
+ children
414
+ }) => {
415
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_react_shared13.ErrorBoundary, { children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
416
+ EmbedPluginProvider,
417
+ {
418
+ refreshTitle,
419
+ timestampLabel,
420
+ hideElementsConfig,
421
+ plugins,
422
+ embedPluginConfig,
423
+ children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(WithResolvers, { onRefresh, huriPayload, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(WithValidators, { validateSchema, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_react_shared13.ListModeProvider, { defaultListMode: embedPluginConfig?.listMode, children }) }) })
424
+ }
425
+ ) });
426
+ };
427
+ var WithResolvers = ({ children, onRefresh, huriPayload }) => {
428
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(RefreshPayloadProvider, { onRefresh, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ResolvePayloadProvider, { huriPayload, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(EmbedResolver, { children }) }) });
429
+ };
430
+ var WithValidators = ({ children, validateSchema }) => {
431
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ValidatePayloadProvider, { enabled: validateSchema, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ValidatePluginsAlert, { children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ValidatePayloadAlert, { children }) }) });
432
+ };
433
+
434
+ // src/components/embed-card/error-handling/EmbedCardApiErrorRenderer.tsx
435
+ var import_react_error = require("@xyo-network/react-error");
436
+
437
+ // src/components/embed-card/error-handling/EmbedErrorCard.tsx
438
+ var import_material12 = require("@mui/material");
439
+ var import_jsx_runtime17 = require("react/jsx-runtime");
440
+ var EmbedErrorCard = (props) => {
441
+ const { alertProps, error, hideErrorDetails = true, children, ...cardProps } = props;
442
+ const errorProps = { alertProps, error, hideErrorDetails };
443
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_material12.Card, { ...cardProps, children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_material12.CardContent, { children: children ?? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(DefaultErrorAlert, { ...errorProps }) }) });
444
+ };
445
+ var DefaultErrorAlert = ({ alertProps, hideErrorDetails, error }) => {
446
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_material12.Alert, { severity: "error", ...alertProps, children: [
447
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_material12.AlertTitle, { children: "Whoops! Something went wrong" }),
448
+ !hideErrorDetails && error ? /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
449
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_material12.Typography, { variant: "caption", children: "Error: " }),
450
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_material12.Typography, { variant: "caption", children: error?.message })
451
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_material12.Typography, { variant: "caption", fontSize: "small", children: "Error Loading Plugin" })
452
+ ] });
453
+ };
454
+
455
+ // src/components/embed-card/error-handling/EmbedCardApiErrorRenderer.tsx
456
+ var import_jsx_runtime18 = require("react/jsx-runtime");
457
+ var EmbedCardApiErrorRenderer = ({ xyoError, children, ...props }) => {
458
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react_error.ErrorRender, { error: xyoError, noReAuth: true, noErrorDisplay: true, customError: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(CustomApiErrorCard, { xyoError, ...props }), children });
459
+ };
460
+ var CustomApiErrorCard = ({ xyoError, ...props }) => {
461
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(EmbedErrorCard, { ...props, children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react_error.ErrorAlert, { error: xyoError }) });
462
+ };
463
+
464
+ // src/components/embed-card/EmbedPluginCard.tsx
465
+ var import_jsx_runtime19 = require("react/jsx-runtime");
466
+ var ApiEmbedPluginCard = ({ children, ...props }) => {
467
+ const {
468
+ validateSchema,
469
+ plugins = [],
470
+ huriPayload,
471
+ refreshTitle = "",
472
+ timestampLabel = "Data From",
473
+ hideElementsConfig,
474
+ embedPluginConfig,
475
+ onRefresh,
476
+ ...busyCardProps
477
+ } = props;
478
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
479
+ EmbedPluginInner,
480
+ {
481
+ ...{
482
+ embedPluginConfig,
483
+ hideElementsConfig,
484
+ huriPayload,
485
+ onRefresh,
486
+ plugins,
487
+ refreshTitle,
488
+ timestampLabel,
489
+ validateSchema
490
+ },
491
+ children: [
492
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(EmbedPluginCardInner, { ...busyCardProps }),
493
+ children
494
+ ]
495
+ }
496
+ );
497
+ };
498
+ var EmbedPluginCardInner = (props) => {
499
+ const { payload, huriError } = useResolvePayload();
500
+ const { refreshPayload } = useRefreshPayload();
501
+ const theme = (0, import_material13.useTheme)();
502
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(EmbedCardApiErrorRenderer, { xyoError: huriError, children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
503
+ EmbedPluginCard,
504
+ {
505
+ elevation: 3,
506
+ variant: "elevation",
507
+ busy: Boolean(!refreshPayload && payload),
508
+ busyVariantProps: { style: { alignItems: "start", paddingTop: theme.spacing(2), zIndex: 2 } },
509
+ sx: { position: "relative" },
510
+ ...props
511
+ }
512
+ ) });
513
+ };
2
514
  //# sourceMappingURL=index.cjs.map