@gofreego/tsutils 0.1.5 → 0.1.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.
- package/dist/index.d.mts +80 -5
- package/dist/index.d.ts +80 -5
- package/dist/index.js +113 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +115 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createContext, useState, useEffect,
|
|
2
|
-
import { createTheme, ThemeProvider as ThemeProvider$1, CssBaseline, IconButton, Tooltip, Box, Drawer, List, Typography, ListItem, ListItemButton, ListItemIcon, ListItemText, Collapse } from '@mui/material';
|
|
3
|
-
import {
|
|
1
|
+
import { createContext, useState, useEffect, useCallback, useContext, useMemo } from 'react';
|
|
2
|
+
import { Snackbar, Alert, createTheme, ThemeProvider as ThemeProvider$1, CssBaseline, IconButton, Tooltip, Box, Drawer, List, Typography, ListItem, ListItemButton, ListItemIcon, ListItemText, Collapse } from '@mui/material';
|
|
3
|
+
import { BrightnessAuto, DarkMode, LightMode, ExpandLess, ExpandMore } from '@mui/icons-material';
|
|
4
4
|
import { BrowserRouter, useLocation, Routes, Route, Outlet, NavLink } from 'react-router-dom';
|
|
5
5
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
6
6
|
import ReactMarkdown from 'react-markdown';
|
|
@@ -486,6 +486,82 @@ var ReadmeViewer = ({
|
|
|
486
486
|
) });
|
|
487
487
|
};
|
|
488
488
|
var ReadmeViewer_default = ReadmeViewer;
|
|
489
|
+
var NotificationContext = createContext(void 0);
|
|
490
|
+
var NotificationProvider = ({
|
|
491
|
+
children,
|
|
492
|
+
defaultDuration = 6e3,
|
|
493
|
+
maxNotifications = 3,
|
|
494
|
+
anchorOrigin = { vertical: "top", horizontal: "right" }
|
|
495
|
+
}) => {
|
|
496
|
+
const [notifications, setNotifications] = useState([]);
|
|
497
|
+
const showNotification = useCallback((message, type, duration = defaultDuration) => {
|
|
498
|
+
const id = `${Date.now()}-${Math.random()}`;
|
|
499
|
+
const newNotification = { id, message, type, duration };
|
|
500
|
+
setNotifications((prev) => {
|
|
501
|
+
const updated = [...prev, newNotification];
|
|
502
|
+
if (updated.length > maxNotifications) {
|
|
503
|
+
return updated.slice(updated.length - maxNotifications);
|
|
504
|
+
}
|
|
505
|
+
return updated;
|
|
506
|
+
});
|
|
507
|
+
}, [defaultDuration, maxNotifications]);
|
|
508
|
+
const handleClose = useCallback((id) => {
|
|
509
|
+
setNotifications((prev) => prev.filter((notif) => notif.id !== id));
|
|
510
|
+
}, []);
|
|
511
|
+
const success = useCallback((message, duration) => {
|
|
512
|
+
showNotification(message, "success", duration);
|
|
513
|
+
}, [showNotification]);
|
|
514
|
+
const error = useCallback((message, duration) => {
|
|
515
|
+
showNotification(message, "error", duration);
|
|
516
|
+
}, [showNotification]);
|
|
517
|
+
const warning = useCallback((message, duration) => {
|
|
518
|
+
showNotification(message, "warning", duration);
|
|
519
|
+
}, [showNotification]);
|
|
520
|
+
const info = useCallback((message, duration) => {
|
|
521
|
+
showNotification(message, "info", duration);
|
|
522
|
+
}, [showNotification]);
|
|
523
|
+
const contextValue = {
|
|
524
|
+
showNotification,
|
|
525
|
+
success,
|
|
526
|
+
error,
|
|
527
|
+
warning,
|
|
528
|
+
info
|
|
529
|
+
};
|
|
530
|
+
return /* @__PURE__ */ jsxs(NotificationContext.Provider, { value: contextValue, children: [
|
|
531
|
+
children,
|
|
532
|
+
notifications.map((notification, index) => /* @__PURE__ */ jsx(
|
|
533
|
+
Snackbar,
|
|
534
|
+
{
|
|
535
|
+
open: true,
|
|
536
|
+
autoHideDuration: notification.duration,
|
|
537
|
+
onClose: () => handleClose(notification.id),
|
|
538
|
+
anchorOrigin,
|
|
539
|
+
style: {
|
|
540
|
+
marginTop: index * 70
|
|
541
|
+
// Stack notifications vertically
|
|
542
|
+
},
|
|
543
|
+
children: /* @__PURE__ */ jsx(
|
|
544
|
+
Alert,
|
|
545
|
+
{
|
|
546
|
+
onClose: () => handleClose(notification.id),
|
|
547
|
+
severity: notification.type,
|
|
548
|
+
variant: "filled",
|
|
549
|
+
sx: { width: "100%" },
|
|
550
|
+
children: notification.message
|
|
551
|
+
}
|
|
552
|
+
)
|
|
553
|
+
},
|
|
554
|
+
notification.id
|
|
555
|
+
))
|
|
556
|
+
] });
|
|
557
|
+
};
|
|
558
|
+
var useNotification = () => {
|
|
559
|
+
const context = useContext(NotificationContext);
|
|
560
|
+
if (!context) {
|
|
561
|
+
throw new Error("useNotification must be used within a NotificationProvider");
|
|
562
|
+
}
|
|
563
|
+
return context;
|
|
564
|
+
};
|
|
489
565
|
|
|
490
566
|
// src/theme/tokens.ts
|
|
491
567
|
var tokens_exports = {};
|
|
@@ -913,9 +989,12 @@ var ThemeProvider = ({
|
|
|
913
989
|
setCustomTheme(newTheme);
|
|
914
990
|
}, []);
|
|
915
991
|
const toggleTheme = useCallback(() => {
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
992
|
+
setThemeModeState((prevMode) => {
|
|
993
|
+
if (prevMode === "light") return "dark";
|
|
994
|
+
if (prevMode === "dark") return "system";
|
|
995
|
+
return "light";
|
|
996
|
+
});
|
|
997
|
+
}, []);
|
|
919
998
|
const contextValue = useMemo(() => ({
|
|
920
999
|
theme,
|
|
921
1000
|
themeMode,
|
|
@@ -963,12 +1042,37 @@ var useTheme = () => {
|
|
|
963
1042
|
};
|
|
964
1043
|
var ThemeToggle = ({
|
|
965
1044
|
lightModeTooltip = "Switch to dark mode",
|
|
966
|
-
darkModeTooltip = "Switch to
|
|
1045
|
+
darkModeTooltip = "Switch to system theme",
|
|
1046
|
+
systemModeTooltip = "Switch to light theme",
|
|
967
1047
|
showTooltip = true,
|
|
968
1048
|
sx,
|
|
969
1049
|
...props
|
|
970
1050
|
}) => {
|
|
971
|
-
const {
|
|
1051
|
+
const { themeMode, toggleTheme } = useTheme();
|
|
1052
|
+
const getIcon = () => {
|
|
1053
|
+
switch (themeMode) {
|
|
1054
|
+
case "light":
|
|
1055
|
+
return /* @__PURE__ */ jsx(LightMode, {});
|
|
1056
|
+
case "dark":
|
|
1057
|
+
return /* @__PURE__ */ jsx(DarkMode, {});
|
|
1058
|
+
case "system":
|
|
1059
|
+
return /* @__PURE__ */ jsx(BrightnessAuto, {});
|
|
1060
|
+
default:
|
|
1061
|
+
return /* @__PURE__ */ jsx(BrightnessAuto, {});
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1064
|
+
const getTooltip = () => {
|
|
1065
|
+
switch (themeMode) {
|
|
1066
|
+
case "light":
|
|
1067
|
+
return lightModeTooltip;
|
|
1068
|
+
case "dark":
|
|
1069
|
+
return darkModeTooltip;
|
|
1070
|
+
case "system":
|
|
1071
|
+
return systemModeTooltip;
|
|
1072
|
+
default:
|
|
1073
|
+
return lightModeTooltip;
|
|
1074
|
+
}
|
|
1075
|
+
};
|
|
972
1076
|
const button = /* @__PURE__ */ jsx(
|
|
973
1077
|
IconButton,
|
|
974
1078
|
{
|
|
@@ -979,20 +1083,13 @@ var ThemeToggle = ({
|
|
|
979
1083
|
...sx
|
|
980
1084
|
},
|
|
981
1085
|
...props,
|
|
982
|
-
children:
|
|
1086
|
+
children: getIcon()
|
|
983
1087
|
}
|
|
984
1088
|
);
|
|
985
1089
|
if (!showTooltip) {
|
|
986
1090
|
return button;
|
|
987
1091
|
}
|
|
988
|
-
return /* @__PURE__ */ jsx(
|
|
989
|
-
Tooltip,
|
|
990
|
-
{
|
|
991
|
-
title: resolvedThemeMode === "light" ? lightModeTooltip : darkModeTooltip,
|
|
992
|
-
arrow: true,
|
|
993
|
-
children: button
|
|
994
|
-
}
|
|
995
|
-
);
|
|
1092
|
+
return /* @__PURE__ */ jsx(Tooltip, { title: getTooltip(), arrow: true, children: button });
|
|
996
1093
|
};
|
|
997
1094
|
|
|
998
1095
|
// src/http/HttpClient.ts
|
|
@@ -1265,6 +1362,6 @@ var PermissionManager = class {
|
|
|
1265
1362
|
};
|
|
1266
1363
|
PermissionManager.cachedPermissions = null;
|
|
1267
1364
|
|
|
1268
|
-
export { AuthProvider, HttpClient, LocalStorage, PermissionManager, ReadmeViewer_default as ReadmeViewer, SidebarLayout, ThemeProvider, ThemeToggle, borderRadius, cn, darkTheme, debounce, elevation, fontSize, fontWeight, formatDate, getHighlighter, lightTheme, lineHeight, spacing, throttle, tokens_exports as tokens, transition, useAuth, useTheme, zIndex };
|
|
1365
|
+
export { AuthProvider, HttpClient, LocalStorage, NotificationProvider, PermissionManager, ReadmeViewer_default as ReadmeViewer, SidebarLayout, ThemeProvider, ThemeToggle, borderRadius, cn, darkTheme, debounce, elevation, fontSize, fontWeight, formatDate, getHighlighter, lightTheme, lineHeight, spacing, throttle, tokens_exports as tokens, transition, useAuth, useNotification, useTheme, zIndex };
|
|
1269
1366
|
//# sourceMappingURL=index.mjs.map
|
|
1270
1367
|
//# sourceMappingURL=index.mjs.map
|