@shellui/core 0.0.5 → 0.0.7

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,642 +0,0 @@
1
- import { jsx as r, jsxs as f, Fragment as S } from "react/jsx-runtime";
2
- import { shellui as h } from "@shellui/sdk";
3
- import { useState as C, useCallback as O, useEffect as T, createContext as A, useContext as I, forwardRef as L, Children as Z } from "react";
4
- import { toast as m, Toaster as G } from "sonner";
5
- import { useNavigate as X } from "react-router";
6
- import { useTranslation as q } from "react-i18next";
7
- import * as y from "@radix-ui/react-dialog";
8
- import { Z as E, c as D, a as J, r as K } from "./index-PsePV0Ng.js";
9
- import { Drawer as b } from "vaul";
10
- import { C as R } from "./ContentView-CZG-ro_B.js";
11
- const Q = (e) => {
12
- if (!e || typeof e != "string")
13
- return null;
14
- try {
15
- if (e.startsWith("http://") || e.startsWith("https://")) {
16
- const o = new URL(e), a = typeof window < "u" ? window.location.origin : "";
17
- return o.origin === a || o.hostname === "localhost" || o.hostname === "127.0.0.1" ? e : null;
18
- }
19
- if (e.startsWith("/") || e.startsWith("./") || !e.startsWith("//")) {
20
- const o = typeof window < "u" ? window.location.origin : "", a = e.startsWith("/") ? e : `/${e}`;
21
- return `${o}${a}`;
22
- }
23
- return null;
24
- } catch (o) {
25
- return console.error("Invalid URL:", e, o), null;
26
- }
27
- }, W = A(void 0), z = () => {
28
- const e = I(W);
29
- if (!e)
30
- throw new Error("useModal must be used within a ModalProvider");
31
- return e;
32
- }, ee = ({ children: e }) => {
33
- const [o, a] = C(!1), [i, n] = C(null), t = O((d) => {
34
- const c = d ? Q(d) : null;
35
- n(c), a(!0);
36
- }, []), s = O(() => {
37
- a(!1), setTimeout(() => n(null), 200);
38
- }, []);
39
- return T(() => {
40
- const d = h.addMessageListener(
41
- "SHELLUI_OPEN_MODAL",
42
- (p) => {
43
- const u = p.payload;
44
- t(u.url);
45
- }
46
- ), c = h.addMessageListener("SHELLUI_CLOSE_MODAL", () => {
47
- s();
48
- });
49
- return () => {
50
- d(), c();
51
- };
52
- }, [t, s]), /* @__PURE__ */ r(W.Provider, { value: { isOpen: o, modalUrl: i, openModal: t, closeModal: s }, children: e });
53
- }, te = (e) => {
54
- if (!e || typeof e != "string")
55
- return null;
56
- try {
57
- if (e.startsWith("http://") || e.startsWith("https://"))
58
- return new URL(e), e;
59
- if (e.startsWith("/") || e.startsWith("./") || !e.startsWith("//")) {
60
- const o = typeof window < "u" ? window.location.origin : "", a = e.startsWith("/") ? e : `/${e}`;
61
- return `${o}${a}`;
62
- }
63
- return null;
64
- } catch {
65
- return null;
66
- }
67
- }, P = "right", H = A(void 0), oe = () => {
68
- const e = I(H);
69
- if (!e)
70
- throw new Error("useDrawer must be used within a DrawerProvider");
71
- return e;
72
- }, re = ({ children: e }) => {
73
- const { closeModal: o } = z(), [a, i] = C(!1), [n, t] = C(null), [s, d] = C(P), [c, p] = C(null), u = O(
74
- (v) => {
75
- o();
76
- const l = v?.url, g = l ? te(l) : null;
77
- t(g), d(v?.position ?? P), p(v?.size ?? null), i(!0);
78
- },
79
- [o]
80
- ), x = O(() => {
81
- i(!1);
82
- }, []);
83
- return T(() => {
84
- const v = h.addMessageListener(
85
- "SHELLUI_OPEN_DRAWER",
86
- (g) => {
87
- const k = g.payload;
88
- u({ url: k.url, position: k.position, size: k.size });
89
- }
90
- ), l = h.addMessageListener("SHELLUI_CLOSE_DRAWER", () => {
91
- x();
92
- });
93
- return () => {
94
- v(), l();
95
- };
96
- }, [u, x]), /* @__PURE__ */ r(H.Provider, { value: { isOpen: a, drawerUrl: n, position: s, size: c, openDrawer: u, closeDrawer: x }, children: e });
97
- }, ae = A(void 0), ne = ({ children: e }) => {
98
- const o = O((a) => {
99
- const {
100
- id: i,
101
- title: n,
102
- description: t,
103
- type: s = "default",
104
- duration: d,
105
- position: c,
106
- action: p,
107
- cancel: u,
108
- onDismiss: x,
109
- onAutoClose: v
110
- } = a, l = {
111
- id: i,
112
- duration: d,
113
- position: c,
114
- action: p ? {
115
- label: p.label,
116
- onClick: p.onClick
117
- } : void 0,
118
- cancel: u ? {
119
- label: u.label,
120
- onClick: u.onClick
121
- } : void 0,
122
- onDismiss: x,
123
- onAutoClose: v
124
- };
125
- if (i) {
126
- switch (s) {
127
- case "success":
128
- m.success(n || "Success", {
129
- id: i,
130
- description: t,
131
- ...l
132
- });
133
- break;
134
- case "error":
135
- m.error(n || "Error", {
136
- id: i,
137
- description: t,
138
- ...l
139
- });
140
- break;
141
- case "warning":
142
- m.warning(n || "Warning", {
143
- id: i,
144
- description: t,
145
- ...l
146
- });
147
- break;
148
- case "info":
149
- m.info(n || "Info", {
150
- id: i,
151
- description: t,
152
- ...l
153
- });
154
- break;
155
- case "loading":
156
- m.loading(n || "Loading...", {
157
- id: i,
158
- description: t,
159
- ...l
160
- });
161
- break;
162
- default:
163
- m(n || "Notification", {
164
- id: i,
165
- description: t,
166
- ...l
167
- });
168
- break;
169
- }
170
- return;
171
- }
172
- switch (s) {
173
- case "success":
174
- m.success(n || "Success", {
175
- description: t,
176
- ...l
177
- });
178
- break;
179
- case "error":
180
- m.error(n || "Error", {
181
- description: t,
182
- ...l
183
- });
184
- break;
185
- case "warning":
186
- m.warning(n || "Warning", {
187
- description: t,
188
- ...l
189
- });
190
- break;
191
- case "info":
192
- m.info(n || "Info", {
193
- description: t,
194
- ...l
195
- });
196
- break;
197
- case "loading":
198
- m.loading(n || "Loading...", {
199
- description: t,
200
- ...l
201
- });
202
- break;
203
- default:
204
- m(n || "Notification", {
205
- description: t,
206
- ...l
207
- });
208
- break;
209
- }
210
- }, []);
211
- return T(() => {
212
- const a = h.addMessageListener("SHELLUI_TOAST", (n) => {
213
- const t = n.payload;
214
- o({
215
- ...t,
216
- onDismiss: () => {
217
- h.sendMessage({
218
- type: "SHELLUI_TOAST_CLEAR",
219
- payload: { id: t.id },
220
- to: n.from
221
- });
222
- },
223
- onAutoClose: () => {
224
- h.sendMessage({
225
- type: "SHELLUI_TOAST_CLEAR",
226
- payload: { id: t.id },
227
- to: n.from
228
- });
229
- },
230
- action: t.action && (() => {
231
- let s = !1;
232
- return {
233
- label: t.action?.label ?? void 0,
234
- onClick: () => {
235
- s || (s = !0, h.sendMessage({
236
- type: "SHELLUI_TOAST_ACTION",
237
- payload: { id: t.id },
238
- to: n.from
239
- }));
240
- }
241
- };
242
- })(),
243
- cancel: t.cancel && (() => {
244
- let s = !1;
245
- return {
246
- label: t.cancel?.label ?? void 0,
247
- onClick: () => {
248
- s || (s = !0, h.sendMessage({
249
- type: "SHELLUI_TOAST_CANCEL",
250
- payload: { id: t.id },
251
- to: n.from
252
- }));
253
- }
254
- };
255
- })()
256
- });
257
- }), i = h.addMessageListener(
258
- "SHELLUI_TOAST_UPDATE",
259
- (n) => {
260
- const t = n.payload;
261
- o({
262
- ...t,
263
- // Re-register action handlers so the button works after update
264
- // These handlers send messages that trigger the callbackRegistry
265
- action: t.action && (() => {
266
- let s = !1;
267
- return {
268
- label: t.action?.label ?? void 0,
269
- onClick: () => {
270
- s || (s = !0, h.sendMessage({
271
- type: "SHELLUI_TOAST_ACTION",
272
- payload: { id: t.id },
273
- to: n.from
274
- }));
275
- }
276
- };
277
- })(),
278
- cancel: t.cancel && (() => {
279
- let s = !1;
280
- return {
281
- label: t.cancel?.label ?? void 0,
282
- onClick: () => {
283
- s || (s = !0, h.sendMessage({
284
- type: "SHELLUI_TOAST_CANCEL",
285
- payload: { id: t.id },
286
- to: n.from
287
- }));
288
- }
289
- };
290
- })()
291
- });
292
- }
293
- );
294
- return () => {
295
- a(), i();
296
- };
297
- }, [o]), /* @__PURE__ */ r(ae.Provider, { value: { toast: o }, children: e });
298
- };
299
- function Oe({ children: e }) {
300
- return /* @__PURE__ */ r(ee, { children: /* @__PURE__ */ r(re, { children: /* @__PURE__ */ r(ne, { children: e }) }) });
301
- }
302
- const se = y.Root, ie = y.Portal, $ = L(({ className: e, ...o }, a) => /* @__PURE__ */ r(
303
- y.Overlay,
304
- {
305
- ref: a,
306
- "data-dialog-overlay": !0,
307
- className: D("fixed inset-0 bg-[hsl(var(--background)/0.8)] backdrop-blur-[1px]", e),
308
- style: { zIndex: E.MODAL_OVERLAY },
309
- ...o
310
- }
311
- ));
312
- $.displayName = y.Overlay.displayName;
313
- const j = L(
314
- ({ className: e, children: o, onPointerDownOutside: a, hideCloseButton: i, ...n }, t) => {
315
- const s = Z.count(o) > 2, d = O(
316
- (c) => {
317
- c?.target?.closest?.("[data-sonner-toaster]") && c.preventDefault(), a?.(c);
318
- },
319
- [a]
320
- );
321
- return /* @__PURE__ */ f(ie, { children: [
322
- /* @__PURE__ */ r($, {}),
323
- /* @__PURE__ */ f(
324
- y.Content,
325
- {
326
- ref: t,
327
- "data-dialog-content": !0,
328
- "data-has-content": s,
329
- className: D(
330
- "fixed left-[50%] top-[50%] grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-6 border bg-background px-6 pt-0 pb-0 shadow-lg sm:rounded-lg",
331
- "data-[has-content=false]:gap-0 data-[has-content=false]:[&>[data-dialog-header]]:border-b-0 data-[has-content=false]:[&>[data-dialog-header]]:pb-0",
332
- e
333
- ),
334
- style: { backgroundColor: "hsl(var(--background))", zIndex: E.MODAL_CONTENT },
335
- onPointerDownOutside: d,
336
- ...n,
337
- children: [
338
- o,
339
- !i && /* @__PURE__ */ f(y.Close, { className: "absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground cursor-pointer", children: [
340
- /* @__PURE__ */ f(
341
- "svg",
342
- {
343
- xmlns: "http://www.w3.org/2000/svg",
344
- width: "24",
345
- height: "24",
346
- viewBox: "0 0 24 24",
347
- fill: "none",
348
- stroke: "currentColor",
349
- strokeWidth: "2",
350
- strokeLinecap: "round",
351
- strokeLinejoin: "round",
352
- className: "h-4 w-4",
353
- children: [
354
- /* @__PURE__ */ r("path", { d: "M18 6 6 18" }),
355
- /* @__PURE__ */ r("path", { d: "m6 6 12 12" })
356
- ]
357
- }
358
- ),
359
- /* @__PURE__ */ r("span", { className: "sr-only", children: "Close" })
360
- ] })
361
- ]
362
- }
363
- )
364
- ] });
365
- }
366
- );
367
- j.displayName = y.Content.displayName;
368
- const U = L(({ className: e, ...o }, a) => /* @__PURE__ */ r(
369
- y.Title,
370
- {
371
- ref: a,
372
- className: D("text-lg font-semibold leading-none tracking-tight", e),
373
- ...o
374
- }
375
- ));
376
- U.displayName = y.Title.displayName;
377
- const M = L(({ className: e, ...o }, a) => /* @__PURE__ */ r(
378
- y.Description,
379
- {
380
- ref: a,
381
- className: D("text-sm text-muted-foreground", e),
382
- ...o
383
- }
384
- ));
385
- M.displayName = y.Description.displayName;
386
- const B = ({
387
- open: e,
388
- onOpenChange: o,
389
- direction: a = "right",
390
- ...i
391
- }) => /* @__PURE__ */ r(
392
- b.Root,
393
- {
394
- open: e,
395
- onOpenChange: o,
396
- direction: a,
397
- ...i
398
- }
399
- );
400
- B.displayName = "Drawer";
401
- const le = b.Trigger;
402
- le.displayName = "DrawerTrigger";
403
- const V = b.Portal;
404
- V.displayName = "DrawerPortal";
405
- const F = L(({ className: e, ...o }, a) => /* @__PURE__ */ r(
406
- b.Overlay,
407
- {
408
- ref: a,
409
- "data-drawer-overlay": !0,
410
- className: D("fixed inset-0 bg-[hsl(var(--background)/0.8)] backdrop-blur-[1px]", e),
411
- style: { zIndex: E.DRAWER_OVERLAY },
412
- ...o
413
- }
414
- ));
415
- F.displayName = b.Overlay.displayName;
416
- const de = {
417
- bottom: "fixed inset-x-0 bottom-0 mt-24 flex h-auto flex-col border border-border bg-background",
418
- top: "fixed inset-x-0 top-0 mb-24 flex h-auto flex-col border border-border bg-background",
419
- left: "fixed inset-y-0 left-0 mr-24 flex h-full w-auto flex-col border border-border bg-background",
420
- right: "fixed inset-y-0 right-0 ml-24 flex h-full w-auto flex-col border border-border bg-background"
421
- }, Y = L(
422
- ({ className: e, direction: o = "right", size: a, children: i, style: n, ...t }, s) => {
423
- const d = o, c = d === "top" || d === "bottom", p = a?.trim() || (c ? "80vh" : "80vw"), u = c ? { height: p, maxHeight: p } : { width: p, maxWidth: p };
424
- return /* @__PURE__ */ f(V, { children: [
425
- /* @__PURE__ */ r(F, {}),
426
- /* @__PURE__ */ f(
427
- b.Content,
428
- {
429
- ref: s,
430
- "data-drawer-content": !0,
431
- className: D("outline-none", de[d], e),
432
- style: {
433
- backgroundColor: "hsl(var(--background))",
434
- zIndex: E.DRAWER_CONTENT,
435
- ...u,
436
- ...n
437
- },
438
- ...t,
439
- children: [
440
- i,
441
- /* @__PURE__ */ f(
442
- b.Close,
443
- {
444
- className: "absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground cursor-pointer",
445
- "aria-label": "Close",
446
- children: [
447
- /* @__PURE__ */ f(
448
- "svg",
449
- {
450
- xmlns: "http://www.w3.org/2000/svg",
451
- width: "24",
452
- height: "24",
453
- viewBox: "0 0 24 24",
454
- fill: "none",
455
- stroke: "currentColor",
456
- strokeWidth: "2",
457
- strokeLinecap: "round",
458
- strokeLinejoin: "round",
459
- className: "h-4 w-4",
460
- children: [
461
- /* @__PURE__ */ r("path", { d: "M18 6 6 18" }),
462
- /* @__PURE__ */ r("path", { d: "m6 6 12 12" })
463
- ]
464
- }
465
- ),
466
- /* @__PURE__ */ r("span", { className: "sr-only", children: "Close" })
467
- ]
468
- }
469
- )
470
- ]
471
- }
472
- )
473
- ] });
474
- }
475
- );
476
- Y.displayName = "DrawerContent";
477
- const ce = b.Close;
478
- ce.displayName = "DrawerClose";
479
- const ue = L(({ className: e, ...o }, a) => /* @__PURE__ */ r(
480
- b.Title,
481
- {
482
- ref: a,
483
- className: D("text-lg font-semibold leading-none tracking-tight", e),
484
- ...o
485
- }
486
- ));
487
- ue.displayName = b.Title.displayName;
488
- const pe = L(({ className: e, ...o }, a) => /* @__PURE__ */ r(
489
- b.Description,
490
- {
491
- ref: a,
492
- className: D("text-sm text-muted-foreground", e),
493
- ...o
494
- }
495
- ));
496
- pe.displayName = b.Description.displayName;
497
- const ge = ({ ...e }) => {
498
- const { settings: o } = J();
499
- return /* @__PURE__ */ r(
500
- G,
501
- {
502
- position: "top-center",
503
- theme: o.appearance.theme,
504
- className: "toaster group",
505
- style: {
506
- zIndex: E.TOAST,
507
- // Re-enable pointer events so toasts stay clickable when a Radix modal is open
508
- // (Radix sets body.style.pointerEvents = 'none' and only the dialog content gets 'auto')
509
- pointerEvents: "auto"
510
- },
511
- toastOptions: {
512
- classNames: {
513
- toast: "group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",
514
- description: "group-[.toast]:text-muted-foreground",
515
- actionButton: "group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",
516
- cancelButton: "group-[.toast]:bg-muted group-[.toast]:text-muted-foreground"
517
- }
518
- },
519
- ...e
520
- }
521
- );
522
- };
523
- function ke({ navigationItems: e, children: o }) {
524
- const a = X(), { isOpen: i, modalUrl: n, closeModal: t } = z(), {
525
- isOpen: s,
526
- drawerUrl: d,
527
- position: c,
528
- size: p,
529
- closeDrawer: u
530
- } = oe(), { t: x, i18n: v } = q("common"), l = v.language || "en";
531
- return T(() => {
532
- const g = h.addMessageListener("SHELLUI_OPEN_MODAL", () => {
533
- u();
534
- });
535
- return () => g();
536
- }, [u]), T(() => {
537
- const g = h.addMessageListener("SHELLUI_NAVIGATE", (k) => {
538
- const w = k.payload?.url;
539
- if (typeof w != "string" || !w.trim()) return;
540
- let N;
541
- if (w.startsWith("http://") || w.startsWith("https://"))
542
- try {
543
- N = new URL(w).pathname;
544
- } catch {
545
- N = w.startsWith("/") ? w : `/${w}`;
546
- }
547
- else
548
- N = w.startsWith("/") ? w : `/${w}`;
549
- t(), u(), N === "/" || N === "" || e.some(
550
- (_) => N === `/${_.path}` || N.startsWith(`/${_.path}/`)
551
- ) ? a(N || "/") : h.toast({
552
- type: "error",
553
- title: x("navigationError") ?? "Navigation error",
554
- description: x("navigationNotAllowed") ?? "This URL is not configured in the app navigation."
555
- });
556
- });
557
- return () => g();
558
- }, [a, t, u, e, x]), /* @__PURE__ */ f(S, { children: [
559
- o,
560
- /* @__PURE__ */ r(
561
- se,
562
- {
563
- open: i,
564
- onOpenChange: t,
565
- children: /* @__PURE__ */ r(j, { className: "max-w-4xl w-full h-[80vh] max-h-[680px] flex flex-col p-0 overflow-hidden", children: n ? /* @__PURE__ */ f(S, { children: [
566
- /* @__PURE__ */ r(U, { className: "sr-only", children: K(
567
- e.find((g) => g.url === n)?.label,
568
- l
569
- ) }),
570
- /* @__PURE__ */ r(M, { className: "sr-only", children: x("modalContent") ?? "Modal content" }),
571
- /* @__PURE__ */ r(
572
- "div",
573
- {
574
- className: "flex-1",
575
- style: { minHeight: 0 },
576
- children: /* @__PURE__ */ r(
577
- R,
578
- {
579
- url: n,
580
- pathPrefix: "settings",
581
- ignoreMessages: !0,
582
- navItem: e.find((g) => g.url === n)
583
- }
584
- )
585
- }
586
- )
587
- ] }) : /* @__PURE__ */ f(S, { children: [
588
- /* @__PURE__ */ r(U, { className: "sr-only", children: "Error: Modal URL is undefined" }),
589
- /* @__PURE__ */ r(M, { className: "sr-only", children: "The openModal function was called without a valid URL parameter." }),
590
- /* @__PURE__ */ r("div", { className: "flex-1 p-4", children: /* @__PURE__ */ f("div", { className: "rounded-lg border border-destructive/50 bg-destructive/10 p-4", children: [
591
- /* @__PURE__ */ r("h3", { className: "font-semibold text-destructive mb-2", children: "Error: Modal URL is undefined" }),
592
- /* @__PURE__ */ f("p", { className: "text-sm text-muted-foreground", children: [
593
- "The ",
594
- /* @__PURE__ */ r("code", { className: "text-xs bg-background px-1 py-0.5 rounded", children: "openModal" }),
595
- " ",
596
- "function was called without a valid URL parameter. Please ensure you provide a URL when opening the modal."
597
- ] })
598
- ] }) })
599
- ] }) })
600
- }
601
- ),
602
- /* @__PURE__ */ r(
603
- B,
604
- {
605
- open: s,
606
- onOpenChange: (g) => !g && u(),
607
- direction: c,
608
- children: /* @__PURE__ */ r(
609
- Y,
610
- {
611
- direction: c,
612
- size: p,
613
- className: "p-0 overflow-hidden flex flex-col",
614
- children: d ? /* @__PURE__ */ r("div", { className: "flex-1 min-h-0 flex flex-col", children: /* @__PURE__ */ r(
615
- R,
616
- {
617
- url: d,
618
- pathPrefix: "settings",
619
- ignoreMessages: !0,
620
- navItem: e.find((g) => g.url === d)
621
- }
622
- ) }) : /* @__PURE__ */ r("div", { className: "flex-1 p-4", children: /* @__PURE__ */ f("div", { className: "rounded-lg border border-destructive/50 bg-destructive/10 p-4", children: [
623
- /* @__PURE__ */ r("h3", { className: "font-semibold text-destructive mb-2", children: "Error: Drawer URL is undefined" }),
624
- /* @__PURE__ */ f("p", { className: "text-sm text-muted-foreground", children: [
625
- "The ",
626
- /* @__PURE__ */ r("code", { className: "text-xs bg-background px-1 py-0.5 rounded", children: "openDrawer" }),
627
- " ",
628
- "function was called without a valid URL parameter. Please ensure you provide a URL when opening the drawer."
629
- ] })
630
- ] }) })
631
- }
632
- )
633
- }
634
- ),
635
- /* @__PURE__ */ r(ge, {})
636
- ] });
637
- }
638
- export {
639
- Oe as L,
640
- ke as O
641
- };
642
- //# sourceMappingURL=OverlayShell-CGjN4rTu.js.map