@vuu-ui/vuu-shell 0.6.24-debug → 0.6.25

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