@vuu-ui/vuu-shell 0.6.9-debug → 0.6.9

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/esm/index.js CHANGED
@@ -1,581 +1,2 @@
1
- // src/feature/Feature.tsx
2
- import React2, { Suspense } from "react";
3
- import { registerComponent } from "@vuu-ui/vuu-layout";
4
-
5
- // src/feature/ErrorBoundary.jsx
6
- import React from "react";
7
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
- var ErrorBoundary = class extends React.Component {
9
- constructor(props) {
10
- super(props);
11
- this.state = { errorMessage: null };
12
- }
13
- static getDerivedStateFromError(error) {
14
- return { errorMessage: error.message };
15
- }
16
- componentDidCatch(error, errorInfo) {
17
- console.log(error, errorInfo);
18
- }
19
- render() {
20
- if (this.state.errorMessage) {
21
- return /* @__PURE__ */ jsxs(Fragment, { children: [
22
- /* @__PURE__ */ jsx("h1", { children: "Something went wrong." }),
23
- /* @__PURE__ */ jsx("p", { children: this.state.errorMessage })
24
- ] });
25
- }
26
- return this.props.children;
27
- }
28
- };
29
-
30
- // src/feature/Loader.tsx
31
- import { jsx as jsx2 } from "react/jsx-runtime";
32
- var Loader = () => /* @__PURE__ */ jsx2("div", { className: "hwLoader", children: "loading" });
33
-
34
- // src/feature/css-module-loader.ts
35
- var importCSS = async (path) => {
36
- const container = new CSSStyleSheet();
37
- return fetch(path).then((x) => x.text()).then((x) => container.replace(x));
38
- };
39
-
40
- // src/feature/Feature.tsx
41
- import { jsx as jsx3 } from "react/jsx-runtime";
42
- function RawFeature({
43
- url,
44
- css,
45
- params,
46
- ...props
47
- }) {
48
- if (css) {
49
- importCSS(css).then((styleSheet) => {
50
- document.adoptedStyleSheets = [
51
- ...document.adoptedStyleSheets,
52
- styleSheet
53
- ];
54
- });
55
- }
56
- const LazyFeature = React2.lazy(() => import(
57
- /* @vite-ignore */
58
- url
59
- ));
60
- return /* @__PURE__ */ jsx3(ErrorBoundary, { children: /* @__PURE__ */ jsx3(Suspense, { fallback: /* @__PURE__ */ jsx3(Loader, {}), children: /* @__PURE__ */ jsx3(LazyFeature, { ...props, ...params }) }) });
61
- }
62
- var Feature = React2.memo(RawFeature);
63
- Feature.displayName = "Feature";
64
- registerComponent("Feature", Feature, "view");
65
-
66
- // src/login/LoginPanel.tsx
67
- import { useState } from "react";
68
- import { Button } from "@salt-ds/core";
69
- import { FormField, Input } from "@heswell/salt-lab";
70
- import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
71
- var classBase = "vuuLoginPanel";
72
- var LoginPanel = ({ onSubmit }) => {
73
- const [username, setUserName] = useState("");
74
- const [password, setPassword] = useState("");
75
- const login = () => {
76
- onSubmit(username, password);
77
- };
78
- const handleUsername = (_event, value) => {
79
- setUserName(value);
80
- };
81
- const handlePassword = (_event, value) => {
82
- setPassword(value);
83
- };
84
- const dataIsValid = username.trim() !== "" && password.trim() !== "";
85
- return /* @__PURE__ */ jsxs2("div", { className: classBase, children: [
86
- /* @__PURE__ */ jsx4(FormField, { label: "Username", style: { width: 200 }, children: /* @__PURE__ */ jsx4(Input, { value: username, id: "text-username", onChange: handleUsername }) }),
87
- /* @__PURE__ */ jsx4(FormField, { label: "Password", style: { width: 200 }, children: /* @__PURE__ */ jsx4(
88
- Input,
89
- {
90
- type: "password",
91
- value: password,
92
- id: "text-password",
93
- onChange: handlePassword
94
- }
95
- ) }),
96
- /* @__PURE__ */ jsx4(
97
- Button,
98
- {
99
- className: `${classBase}-login`,
100
- disabled: !dataIsValid,
101
- onClick: login,
102
- variant: "cta",
103
- children: "Login"
104
- }
105
- )
106
- ] });
107
- };
108
-
109
- // src/login/login-utils.ts
110
- var getCookieValue = (name) => {
111
- var _a;
112
- return (_a = document.cookie.split("; ").find((row) => row.startsWith(`${name}=`))) == null ? void 0 : _a.split("=")[1];
113
- };
114
- var getAuthDetailsFromCookies = () => {
115
- const username = getCookieValue("vuu-username");
116
- const token = getCookieValue("vuu-auth-token");
117
- return [username, token];
118
- };
119
- var redirectToLogin = (loginUrl = "/login.html") => {
120
- window.location.href = loginUrl;
121
- };
122
- var logout = (loginUrl) => {
123
- document.cookie = "vuu-username= ; expires = Thu, 01 Jan 1970 00:00:00 GMT";
124
- document.cookie = "vuu-auth-token= ; expires = Thu, 01 Jan 1970 00:00:00 GMT";
125
- redirectToLogin(loginUrl);
126
- };
127
-
128
- // src/shell.tsx
129
- import { connectToServer } from "@vuu-ui/vuu-data";
130
- import {
131
- useCallback as useCallback5,
132
- useEffect as useEffect3,
133
- useRef,
134
- useState as useState4
135
- } from "react";
136
-
137
- // src/use-layout-config.js
138
- import { useCallback, useEffect, useState as useState2 } from "react";
139
- var useLayoutConfig = (user, defaultLayout) => {
140
- const [layout, _setLayout] = useState2(defaultLayout);
141
- const setLayout = (layout2) => {
142
- _setLayout(layout2);
143
- };
144
- const load = useCallback(
145
- async (id = "latest") => {
146
- fetch(`api/vui/${user.username}/${id}`, {}).then((response) => {
147
- return response.ok ? response.json() : defaultLayout;
148
- }).then(setLayout).catch(() => {
149
- setLayout(defaultLayout);
150
- });
151
- },
152
- [defaultLayout, user.username]
153
- );
154
- useEffect(() => {
155
- load();
156
- }, [load]);
157
- const saveData = useCallback(
158
- (data) => {
159
- fetch(`api/vui/${user.username}`, {
160
- method: "POST",
161
- headers: {
162
- "Content-Type": "application/json"
163
- },
164
- body: JSON.stringify(data)
165
- }).then((response) => {
166
- return response.ok ? response.json() : defaultLayout;
167
- });
168
- },
169
- [defaultLayout, user]
170
- );
171
- const loadLayoutById = useCallback(
172
- (id) => {
173
- load(id);
174
- },
175
- [load]
176
- );
177
- return [layout, saveData, loadLayoutById];
178
- };
179
- var use_layout_config_default = useLayoutConfig;
180
-
181
- // src/ShellContextProvider.tsx
182
- import { createContext, useContext } from "react";
183
- import { jsx as jsx5 } from "react/jsx-runtime";
184
- var defaultConfig = {};
185
- var ShellContext = createContext(defaultConfig);
186
- var Provider = ({
187
- children,
188
- context,
189
- inheritedContext
190
- }) => {
191
- const mergedContext = {
192
- ...inheritedContext,
193
- ...context
194
- };
195
- return /* @__PURE__ */ jsx5(ShellContext.Provider, { value: mergedContext, children });
196
- };
197
- var ShellContextProvider = ({
198
- children,
199
- value
200
- }) => {
201
- return /* @__PURE__ */ jsx5(ShellContext.Consumer, { children: (context) => /* @__PURE__ */ jsx5(Provider, { context: value, inheritedContext: context, children }) });
202
- };
203
- var useShellContext = () => {
204
- return useContext(ShellContext);
205
- };
206
-
207
- // src/shell.tsx
208
- import cx3 from "classnames";
209
- import {
210
- Chest,
211
- DraggableLayout,
212
- Drawer,
213
- Flexbox,
214
- LayoutProvider,
215
- View
216
- } from "@vuu-ui/vuu-layout";
217
-
218
- // src/app-header/AppHeader.tsx
219
- import { useCallback as useCallback4 } from "react";
220
-
221
- // src/user-profile/UserProfile.tsx
222
- import { Button as Button3 } from "@salt-ds/core";
223
- import { DropdownBase } from "@heswell/salt-lab";
224
- import { UserSolidIcon } from "@salt-ds/icons";
225
-
226
- // src/user-profile/UserPanel.tsx
227
- import { formatDate } from "@vuu-ui/vuu-utils";
228
- import { List, ListItem } from "@heswell/salt-lab";
229
- import { Button as Button2 } from "@salt-ds/core";
230
- import { ExportIcon } from "@salt-ds/icons";
231
- import {
232
- forwardRef,
233
- useCallback as useCallback2,
234
- useEffect as useEffect2,
235
- useState as useState3
236
- } from "react";
237
-
238
- // src/get-layout-history.ts
239
- var getLayoutHistory = async (user) => {
240
- const history = await fetch(`api/vui/${user.username}`, {}).then((response) => {
241
- return response.ok ? response.json() : null;
242
- }).catch(() => {
243
- console.log(`error getting history`);
244
- });
245
- return history;
246
- };
247
-
248
- // src/user-profile/UserPanel.tsx
249
- import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
250
- var byLastUpdate = ({ lastUpdate: l1 }, { lastUpdate: l2 }) => {
251
- return l2 === l1 ? 0 : l2 < l1 ? -1 : 1;
252
- };
253
- var HistoryListItem = (props) => {
254
- return /* @__PURE__ */ jsx6(ListItem, { ...props });
255
- };
256
- var UserPanel = forwardRef(function UserPanel2({ loginUrl, onNavigate, user, layoutId = "latest" }, forwardedRef) {
257
- const [history, setHistory] = useState3([]);
258
- useEffect2(() => {
259
- async function getHistory() {
260
- const history2 = await getLayoutHistory(user);
261
- const sortedHistory = history2.filter((item) => item.id !== "latest").sort(byLastUpdate).map(({ id, lastUpdate }) => ({
262
- lastUpdate,
263
- id,
264
- label: `Saved at ${formatDate(new Date(lastUpdate), "kk:mm:ss")}`
265
- }));
266
- console.log({ sortedHistory });
267
- setHistory(sortedHistory);
268
- }
269
- getHistory();
270
- }, [user]);
271
- const handleHisorySelected = useCallback2(
272
- (evt, selected2) => {
273
- if (selected2) {
274
- onNavigate(selected2.id);
275
- }
276
- },
277
- [onNavigate]
278
- );
279
- const handleLogout = useCallback2(() => {
280
- logout(loginUrl);
281
- }, [loginUrl]);
282
- const selected = history.length === 0 ? null : layoutId === "latest" ? history[0] : history.find((i) => i.id === layoutId);
283
- return /* @__PURE__ */ jsxs3("div", { className: "vuuUserPanel", ref: forwardedRef, children: [
284
- /* @__PURE__ */ jsx6(
285
- List,
286
- {
287
- ListItem: HistoryListItem,
288
- className: "vuuUserPanel-history",
289
- onSelect: handleHisorySelected,
290
- selected,
291
- source: history
292
- }
293
- ),
294
- /* @__PURE__ */ jsx6("div", { className: "vuuUserPanel-buttonBar", children: /* @__PURE__ */ jsxs3(Button2, { "aria-label": "logout", onClick: handleLogout, children: [
295
- /* @__PURE__ */ jsx6(ExportIcon, {}),
296
- " Logout"
297
- ] }) })
298
- ] });
299
- });
300
-
301
- // src/user-profile/UserProfile.tsx
302
- import { jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
303
- var UserProfile = ({
304
- layoutId,
305
- loginUrl,
306
- onNavigate,
307
- user
308
- }) => {
309
- const handleNavigate = (id) => {
310
- onNavigate(id);
311
- };
312
- return /* @__PURE__ */ jsxs4(DropdownBase, { className: "vuuUserProfile", placement: "bottom-end", children: [
313
- /* @__PURE__ */ jsx7(Button3, { variant: "secondary", children: /* @__PURE__ */ jsx7(UserSolidIcon, {}) }),
314
- /* @__PURE__ */ jsx7(
315
- UserPanel,
316
- {
317
- layoutId,
318
- loginUrl,
319
- onNavigate: handleNavigate,
320
- user
321
- }
322
- )
323
- ] });
324
- };
325
-
326
- // src/theme-switch/ThemeSwitch.tsx
327
- import {
328
- ToggleButton,
329
- ToggleButtonGroup
330
- } from "@heswell/salt-lab";
331
- import cx from "classnames";
332
- import { useControlled } from "@salt-ds/core";
333
- import { useCallback as useCallback3 } from "react";
334
- import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
335
- var classBase2 = "vuuThemeSwitch";
336
- var modes = ["light", "dark"];
337
- var ThemeSwitch = ({
338
- className: classNameProp,
339
- defaultMode: defaultModeProp,
340
- mode: modeProp,
341
- onChange,
342
- ...htmlAttributes
343
- }) => {
344
- const [mode, setMode] = useControlled({
345
- controlled: modeProp,
346
- default: defaultModeProp != null ? defaultModeProp : "light",
347
- name: "ThemeSwitch",
348
- state: "mode"
349
- });
350
- const selectedIndex = modes.indexOf(mode);
351
- const handleChangeSecondary = useCallback3(
352
- (_evt, index) => {
353
- const mode2 = modes[index];
354
- setMode(mode2);
355
- onChange(mode2);
356
- },
357
- [onChange, setMode]
358
- );
359
- const className = cx(classBase2, classNameProp);
360
- return /* @__PURE__ */ jsxs5(
361
- ToggleButtonGroup,
362
- {
363
- className,
364
- ...htmlAttributes,
365
- onChange: handleChangeSecondary,
366
- selectedIndex,
367
- children: [
368
- /* @__PURE__ */ jsx8(
369
- ToggleButton,
370
- {
371
- "aria-label": "alert",
372
- tooltipText: "Light Theme",
373
- "data-icon": "light"
374
- }
375
- ),
376
- /* @__PURE__ */ jsx8(
377
- ToggleButton,
378
- {
379
- "aria-label": "home",
380
- tooltipText: "Dark Theme",
381
- "data-icon": "dark"
382
- }
383
- )
384
- ]
385
- }
386
- );
387
- };
388
-
389
- // src/app-header/AppHeader.tsx
390
- import cx2 from "classnames";
391
- import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
392
- var classBase3 = "vuuAppHeader";
393
- var AppHeader = ({
394
- className: classNameProp,
395
- layoutId,
396
- loginUrl,
397
- onNavigate,
398
- onSwitchTheme,
399
- themeMode = "light",
400
- user,
401
- ...htmlAttributes
402
- }) => {
403
- const className = cx2(classBase3, classNameProp, "salt-density-medium");
404
- const handleSwitchTheme = useCallback4(
405
- (mode) => onSwitchTheme == null ? void 0 : onSwitchTheme(mode),
406
- [onSwitchTheme]
407
- );
408
- return /* @__PURE__ */ jsxs6("header", { className, ...htmlAttributes, children: [
409
- /* @__PURE__ */ jsx9(ThemeSwitch, { defaultMode: themeMode, onChange: handleSwitchTheme }),
410
- /* @__PURE__ */ jsx9(
411
- UserProfile,
412
- {
413
- layoutId,
414
- loginUrl,
415
- onNavigate,
416
- user
417
- }
418
- )
419
- ] });
420
- };
421
-
422
- // src/shell.tsx
423
- import { jsx as jsx10, jsxs as jsxs7 } from "react/jsx-runtime";
424
- var warningLayout = {
425
- type: "View",
426
- props: {
427
- style: { height: "calc(100% - 6px)" }
428
- },
429
- children: [
430
- {
431
- props: {
432
- className: "vuuShell-warningPlaceholder"
433
- },
434
- type: "Placeholder"
435
- }
436
- ]
437
- };
438
- var Shell = ({
439
- children,
440
- className: classNameProp,
441
- defaultLayout = warningLayout,
442
- leftSidePanel,
443
- loginUrl,
444
- serverUrl,
445
- user,
446
- ...htmlAttributes
447
- }) => {
448
- const rootRef = useRef(null);
449
- const [density] = useState4("high");
450
- const paletteView = useRef(null);
451
- const [open, setOpen] = useState4(false);
452
- const layoutId = useRef("latest");
453
- const [layout, setLayoutConfig, loadLayoutById] = use_layout_config_default(
454
- user,
455
- defaultLayout
456
- );
457
- const handleLayoutChange = useCallback5(
458
- (layout2) => {
459
- setLayoutConfig(layout2);
460
- },
461
- [setLayoutConfig]
462
- );
463
- const handleSwitchTheme = useCallback5((mode) => {
464
- if (rootRef.current) {
465
- rootRef.current.dataset.mode = mode;
466
- }
467
- }, []);
468
- const handleDrawerClick = (e) => {
469
- var _a;
470
- const target = e.target;
471
- if (!((_a = paletteView.current) == null ? void 0 : _a.contains(target))) {
472
- setOpen(!open);
473
- }
474
- };
475
- const handleNavigate = useCallback5(
476
- (id) => {
477
- layoutId.current = id;
478
- loadLayoutById(id);
479
- },
480
- [loadLayoutById]
481
- );
482
- useEffect3(() => {
483
- if (serverUrl && user.token) {
484
- connectToServer(serverUrl, user.token);
485
- }
486
- }, [serverUrl, user.token]);
487
- const getDrawers = () => {
488
- const drawers = [];
489
- if (leftSidePanel) {
490
- drawers.push(
491
- /* @__PURE__ */ jsx10(
492
- Drawer,
493
- {
494
- onClick: handleDrawerClick,
495
- open,
496
- position: "left",
497
- inline: true,
498
- peekaboo: true,
499
- sizeOpen: 200,
500
- toggleButton: "end",
501
- children: /* @__PURE__ */ jsx10(
502
- View,
503
- {
504
- className: "vuuShell-palette",
505
- id: "vw-app-palette",
506
- ref: paletteView,
507
- style: { height: "100%" },
508
- children: leftSidePanel
509
- },
510
- "app-palette"
511
- )
512
- },
513
- "left-panel"
514
- )
515
- );
516
- }
517
- return drawers;
518
- };
519
- const className = cx3(
520
- "vuuShell",
521
- classNameProp,
522
- "salt-theme",
523
- `salt-density-${density}`
524
- );
525
- return (
526
- // ShellContext TBD
527
- /* @__PURE__ */ jsxs7(ShellContextProvider, { value: void 0, children: [
528
- /* @__PURE__ */ jsx10(LayoutProvider, { layout, onLayoutChange: handleLayoutChange, children: /* @__PURE__ */ jsx10(
529
- DraggableLayout,
530
- {
531
- className,
532
- "data-mode": "light",
533
- ref: rootRef,
534
- ...htmlAttributes,
535
- children: /* @__PURE__ */ jsxs7(
536
- Flexbox,
537
- {
538
- className: "App",
539
- style: { flexDirection: "column", height: "100%", width: "100%" },
540
- children: [
541
- /* @__PURE__ */ jsx10(
542
- AppHeader,
543
- {
544
- layoutId: layoutId.current,
545
- loginUrl,
546
- user,
547
- onNavigate: handleNavigate,
548
- onSwitchTheme: handleSwitchTheme
549
- }
550
- ),
551
- /* @__PURE__ */ jsx10(Chest, { style: { flex: 1 }, children: getDrawers().concat(
552
- /* @__PURE__ */ jsx10(
553
- DraggableLayout,
554
- {
555
- dropTarget: true,
556
- style: { width: "100%", height: "100%" }
557
- },
558
- "main-content"
559
- )
560
- ) })
561
- ]
562
- }
563
- )
564
- }
565
- ) }),
566
- children
567
- ] })
568
- );
569
- };
570
- export {
571
- Feature,
572
- LoginPanel,
573
- Shell,
574
- ShellContextProvider,
575
- ThemeSwitch,
576
- getAuthDetailsFromCookies,
577
- logout,
578
- redirectToLogin,
579
- useShellContext
580
- };
1
+ import D,{Suspense as he}from"react";import{registerComponent as ge}from"@vuu-ui/vuu-layout";import ue from"react";import{Fragment as ce,jsx as U,jsxs as de}from"react/jsx-runtime";var x=class extends ue.Component{constructor(e){super(e),this.state={errorMessage:null}}static getDerivedStateFromError(e){return{errorMessage:e.message}}componentDidCatch(e,o){console.log(e,o)}render(){return this.state.errorMessage?de(ce,{children:[U("h1",{children:"Something went wrong."}),U("p",{children:this.state.errorMessage})]}):this.props.children}};import{jsx as pe}from"react/jsx-runtime";var k=()=>pe("div",{className:"hwLoader",children:"loading"});var E=async t=>{let e=new CSSStyleSheet;return fetch(t).then(o=>o.text()).then(o=>e.replace(o))};import{jsx as C}from"react/jsx-runtime";function fe({url:t,css:e,params:o,...r}){e&&E(e).then(n=>{document.adoptedStyleSheets=[...document.adoptedStyleSheets,n]});let s=D.lazy(()=>import(t));return C(x,{children:C(he,{fallback:C(k,{}),children:C(s,{...r,...o})})})}var I=D.memo(fe);I.displayName="Feature";ge("Feature",I,"view");import{useState as R}from"react";import{Button as ye}from"@salt-ds/core";import{FormField as B,Input as F}from"@heswell/salt-lab";import{jsx as v,jsxs as ve}from"react/jsx-runtime";var A="vuuLoginPanel",Nt=({onSubmit:t})=>{let[e,o]=R(""),[r,s]=R(""),n=()=>{t(e,r)},a=(l,u)=>{o(u)},m=(l,u)=>{s(u)},i=e.trim()!==""&&r.trim()!=="";return ve("div",{className:A,children:[v(B,{label:"Username",style:{width:200},children:v(F,{value:e,id:"text-username",onChange:a})}),v(B,{label:"Password",style:{width:200},children:v(F,{type:"password",value:r,id:"text-password",onChange:m})}),v(ye,{className:`${A}-login`,disabled:!i,onClick:n,variant:"cta",children:"Login"})]})};var V=t=>{var e;return(e=document.cookie.split("; ").find(o=>o.startsWith(`${t}=`)))==null?void 0:e.split("=")[1]},Et=()=>{let t=V("vuu-username"),e=V("vuu-auth-token");return[t,e]},xe=(t="/login.html")=>{window.location.href=t},O=t=>{document.cookie="vuu-username= ; expires = Thu, 01 Jan 1970 00:00:00 GMT",document.cookie="vuu-auth-token= ; expires = Thu, 01 Jan 1970 00:00:00 GMT",xe(t)};import{connectToServer as Ye}from"@vuu-ui/vuu-data";import{useCallback as H,useEffect as Ze,useRef as M,useState as ee}from"react";import{useCallback as P,useEffect as Ce,useState as Le}from"react";var Pe=(t,e)=>{let[o,r]=Le(e),s=i=>{r(i)},n=P(async(i="latest")=>{fetch(`api/vui/${t.username}/${i}`,{}).then(l=>l.ok?l.json():e).then(s).catch(()=>{s(e)})},[e,t.username]);Ce(()=>{n()},[n]);let a=P(i=>{fetch(`api/vui/${t.username}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)}).then(l=>l.ok?l.json():e)},[e,t]),m=P(i=>{n(i)},[n]);return[o,a,m]},$=Pe;import{createContext as Se,useContext as Te}from"react";import{jsx as S}from"react/jsx-runtime";var we={},T=Se(we),He=({children:t,context:e,inheritedContext:o})=>{let r={...o,...e};return S(T.Provider,{value:r,children:t})},G=({children:t,value:e})=>S(T.Consumer,{children:o=>S(He,{context:e,inheritedContext:o,children:t})}),Gt=()=>Te(T);import je from"classnames";import{Chest as et,DraggableLayout as te,Drawer as tt,Flexbox as ot,LayoutProvider as rt,View as nt}from"@vuu-ui/vuu-layout";import{useCallback as We}from"react";import{Button as Fe}from"@salt-ds/core";import{DropdownBase as Ae}from"@heswell/salt-lab";import{UserSolidIcon as Ve}from"@salt-ds/icons";import{formatDate as Me}from"@vuu-ui/vuu-utils";import{List as be,ListItem as Ne}from"@heswell/salt-lab";import{Button as Ue}from"@salt-ds/core";import{ExportIcon as ke}from"@salt-ds/icons";import{forwardRef as Ee,useCallback as _,useEffect as De,useState as Ie}from"react";var J=async t=>await fetch(`api/vui/${t.username}`,{}).then(o=>o.ok?o.json():null).catch(()=>{console.log("error getting history")});import{jsx as L,jsxs as z}from"react/jsx-runtime";var Re=({lastUpdate:t},{lastUpdate:e})=>e===t?0:e<t?-1:1,Be=t=>L(Ne,{...t}),q=Ee(function({loginUrl:e,onNavigate:o,user:r,layoutId:s="latest"},n){let[a,m]=Ie([]);De(()=>{async function d(){let g=(await J(r)).filter(f=>f.id!=="latest").sort(Re).map(({id:f,lastUpdate:y})=>({lastUpdate:y,id:f,label:`Saved at ${Me(new Date(y),"kk:mm:ss")}`}));console.log({sortedHistory:g}),m(g)}d()},[r]);let i=_((d,p)=>{p&&o(p.id)},[o]),l=_(()=>{O(e)},[e]),u=a.length===0?null:s==="latest"?a[0]:a.find(d=>d.id===s);return z("div",{className:"vuuUserPanel",ref:n,children:[L(be,{ListItem:Be,className:"vuuUserPanel-history",onSelect:i,selected:u,source:a}),L("div",{className:"vuuUserPanel-buttonBar",children:z(Ue,{"aria-label":"logout",onClick:l,children:[L(ke,{})," Logout"]})})]})});import{jsx as w,jsxs as Oe}from"react/jsx-runtime";var W=({layoutId:t,loginUrl:e,onNavigate:o,user:r})=>Oe(Ae,{className:"vuuUserProfile",placement:"bottom-end",children:[w(Fe,{variant:"secondary",children:w(Ve,{})}),w(q,{layoutId:t,loginUrl:e,onNavigate:n=>{o(n)},user:r})]});import{ToggleButton as K,ToggleButtonGroup as $e}from"@heswell/salt-lab";import Ge from"classnames";import{useControlled as Je}from"@salt-ds/core";import{useCallback as _e}from"react";import{jsx as X,jsxs as qe}from"react/jsx-runtime";var ze="vuuThemeSwitch",Q=["light","dark"],Y=({className:t,defaultMode:e,mode:o,onChange:r,...s})=>{let[n,a]=Je({controlled:o,default:e!=null?e:"light",name:"ThemeSwitch",state:"mode"}),m=Q.indexOf(n),i=_e((u,d)=>{let p=Q[d];a(p),r(p)},[r,a]),l=Ge(ze,t);return qe($e,{className:l,...s,onChange:i,selectedIndex:m,children:[X(K,{"aria-label":"alert",tooltipText:"Light Theme","data-icon":"light"}),X(K,{"aria-label":"home",tooltipText:"Dark Theme","data-icon":"dark"})]})};import Ke from"classnames";import{jsx as Z,jsxs as Xe}from"react/jsx-runtime";var Qe="vuuAppHeader",j=({className:t,layoutId:e,loginUrl:o,onNavigate:r,onSwitchTheme:s,themeMode:n="light",user:a,...m})=>{let i=Ke(Qe,t,"salt-density-medium"),l=We(u=>s==null?void 0:s(u),[s]);return Xe("header",{className:i,...m,children:[Z(Y,{defaultMode:n,onChange:l}),Z(W,{layoutId:e,loginUrl:o,onNavigate:r,user:a})]})};import{jsx as h,jsxs as oe}from"react/jsx-runtime";var st={type:"View",props:{style:{height:"calc(100% - 6px)"}},children:[{props:{className:"vuuShell-warningPlaceholder"},type:"Placeholder"}]},ar=({children:t,className:e,defaultLayout:o=st,leftSidePanel:r,loginUrl:s,serverUrl:n,user:a,...m})=>{let i=M(null),[l]=ee("high"),u=M(null),[d,p]=ee(!1),g=M("latest"),[f,y,b]=$(a,o),re=H(c=>{y(c)},[y]),ne=H(c=>{i.current&&(i.current.dataset.mode=c)},[]),se=c=>{var N;let me=c.target;(N=u.current)!=null&&N.contains(me)||p(!d)},ae=H(c=>{g.current=c,b(c)},[b]);Ze(()=>{n&&a.token&&Ye(n,a.token)},[n,a.token]);let ie=()=>{let c=[];return r&&c.push(h(tt,{onClick:se,open:d,position:"left",inline:!0,peekaboo:!0,sizeOpen:200,toggleButton:"end",children:h(nt,{className:"vuuShell-palette",id:"vw-app-palette",ref:u,style:{height:"100%"},children:r},"app-palette")},"left-panel")),c},le=je("vuuShell",e,"salt-theme",`salt-density-${l}`);return oe(G,{value:void 0,children:[h(rt,{layout:f,onLayoutChange:re,children:h(te,{className:le,"data-mode":"light",ref:i,...m,children:oe(ot,{className:"App",style:{flexDirection:"column",height:"100%",width:"100%"},children:[h(j,{layoutId:g.current,loginUrl:s,user:a,onNavigate:ae,onSwitchTheme:ne}),h(et,{style:{flex:1},children:ie().concat(h(te,{dropTarget:!0,style:{width:"100%",height:"100%"}},"main-content"))})]})})}),t]})};export{I as Feature,Nt as LoginPanel,ar as Shell,G as ShellContextProvider,Y as ThemeSwitch,Et as getAuthDetailsFromCookies,O as logout,xe as redirectToLogin,Gt as useShellContext};
581
2
  //# sourceMappingURL=index.js.map