@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.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ReactNode, CSSProperties } from 'react';
|
|
2
|
-
import { IconButtonProps } from '@mui/material';
|
|
2
|
+
import { AlertColor, IconButtonProps } from '@mui/material';
|
|
3
3
|
import { Highlighter } from 'shiki';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -122,6 +122,77 @@ interface ReadmeViewerProps {
|
|
|
122
122
|
}
|
|
123
123
|
declare const ReadmeViewer: React.FC<ReadmeViewerProps>;
|
|
124
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Notification type representing a toast message
|
|
127
|
+
*/
|
|
128
|
+
interface Notification {
|
|
129
|
+
id: string;
|
|
130
|
+
message: string;
|
|
131
|
+
type: AlertColor;
|
|
132
|
+
duration?: number;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Context interface for notification management
|
|
136
|
+
*/
|
|
137
|
+
interface NotificationContextType {
|
|
138
|
+
showNotification: (message: string, type: AlertColor, duration?: number) => void;
|
|
139
|
+
success: (message: string, duration?: number) => void;
|
|
140
|
+
error: (message: string, duration?: number) => void;
|
|
141
|
+
warning: (message: string, duration?: number) => void;
|
|
142
|
+
info: (message: string, duration?: number) => void;
|
|
143
|
+
}
|
|
144
|
+
interface NotificationProviderProps {
|
|
145
|
+
/** Components to wrap with notification context */
|
|
146
|
+
children: ReactNode;
|
|
147
|
+
/** Default duration for notifications in milliseconds. Defaults to 6000ms */
|
|
148
|
+
defaultDuration?: number;
|
|
149
|
+
/** Maximum number of notifications to show at once. Defaults to 3 */
|
|
150
|
+
maxNotifications?: number;
|
|
151
|
+
/** Position of the notifications. Defaults to top-right */
|
|
152
|
+
anchorOrigin?: {
|
|
153
|
+
vertical: 'top' | 'bottom';
|
|
154
|
+
horizontal: 'left' | 'center' | 'right';
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* NotificationProvider manages toast notifications using Material-UI Snackbar and Alert.
|
|
159
|
+
* Provides methods to show success, error, warning, and info notifications.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```tsx
|
|
163
|
+
* <NotificationProvider>
|
|
164
|
+
* <App />
|
|
165
|
+
* </NotificationProvider>
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* // In a component:
|
|
169
|
+
* ```tsx
|
|
170
|
+
* const { success, error } = useNotification()
|
|
171
|
+
* success('Operation completed!')
|
|
172
|
+
* error('Something went wrong')
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
declare const NotificationProvider: React.FC<NotificationProviderProps>;
|
|
176
|
+
/**
|
|
177
|
+
* Hook to access notification context
|
|
178
|
+
* Must be used within a NotificationProvider
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```tsx
|
|
182
|
+
* const { success, error, warning, info } = useNotification()
|
|
183
|
+
*
|
|
184
|
+
* // Show notifications
|
|
185
|
+
* success('Data saved successfully!')
|
|
186
|
+
* error('Failed to save data')
|
|
187
|
+
* warning('This action cannot be undone')
|
|
188
|
+
* info('New update available')
|
|
189
|
+
*
|
|
190
|
+
* // With custom duration
|
|
191
|
+
* success('Quick message', 3000)
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
declare const useNotification: () => NotificationContextType;
|
|
195
|
+
|
|
125
196
|
/**
|
|
126
197
|
* Theme mode options
|
|
127
198
|
* - 'light': Always use light theme
|
|
@@ -274,9 +345,14 @@ interface ThemeToggleProps extends Omit<IconButtonProps, 'onClick'> {
|
|
|
274
345
|
lightModeTooltip?: string;
|
|
275
346
|
/**
|
|
276
347
|
* Tooltip text for dark mode
|
|
277
|
-
* @default "Switch to
|
|
348
|
+
* @default "Switch to system mode"
|
|
278
349
|
*/
|
|
279
350
|
darkModeTooltip?: string;
|
|
351
|
+
/**
|
|
352
|
+
* Tooltip text for system mode
|
|
353
|
+
* @default "Switch to light mode"
|
|
354
|
+
*/
|
|
355
|
+
systemModeTooltip?: string;
|
|
280
356
|
/**
|
|
281
357
|
* Whether to show tooltip
|
|
282
358
|
* @default true
|
|
@@ -284,8 +360,7 @@ interface ThemeToggleProps extends Omit<IconButtonProps, 'onClick'> {
|
|
|
284
360
|
showTooltip?: boolean;
|
|
285
361
|
}
|
|
286
362
|
/**
|
|
287
|
-
* A round button component for toggling between light and
|
|
288
|
-
* Note: Toggling skips 'system' mode and switches directly between light and dark
|
|
363
|
+
* A round button component for toggling between light, dark, and system themes
|
|
289
364
|
*/
|
|
290
365
|
declare const ThemeToggle: React.FC<ThemeToggleProps>;
|
|
291
366
|
|
|
@@ -562,4 +637,4 @@ declare class PermissionManager {
|
|
|
562
637
|
static hasPermission(permission: string): boolean;
|
|
563
638
|
}
|
|
564
639
|
|
|
565
|
-
export { type AuthContextType, AuthProvider, type AuthProviderProps, HttpClient, type HttpClientConfig, type HttpResponse, LocalStorage, type MenuItem, PermissionManager, ReadmeViewer, type RequestConfig, type ResolvedThemeMode, SidebarLayout, type SidebarLayoutProps, type Theme, type ThemeContextValue, type ThemeMode, ThemeProvider, ThemeToggle, borderRadius, cn, darkTheme, debounce, elevation, fontSize, fontWeight, formatDate, getHighlighter, lightTheme, lineHeight, spacing, throttle, tokens, transition, useAuth, useTheme, zIndex };
|
|
640
|
+
export { type AuthContextType, AuthProvider, type AuthProviderProps, HttpClient, type HttpClientConfig, type HttpResponse, LocalStorage, type MenuItem, type Notification, type NotificationContextType, NotificationProvider, type NotificationProviderProps, PermissionManager, ReadmeViewer, type RequestConfig, type ResolvedThemeMode, SidebarLayout, type SidebarLayoutProps, type Theme, type ThemeContextValue, type ThemeMode, ThemeProvider, ThemeToggle, borderRadius, cn, darkTheme, debounce, elevation, fontSize, fontWeight, formatDate, getHighlighter, lightTheme, lineHeight, spacing, throttle, tokens, transition, useAuth, useNotification, useTheme, zIndex };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ReactNode, CSSProperties } from 'react';
|
|
2
|
-
import { IconButtonProps } from '@mui/material';
|
|
2
|
+
import { AlertColor, IconButtonProps } from '@mui/material';
|
|
3
3
|
import { Highlighter } from 'shiki';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -122,6 +122,77 @@ interface ReadmeViewerProps {
|
|
|
122
122
|
}
|
|
123
123
|
declare const ReadmeViewer: React.FC<ReadmeViewerProps>;
|
|
124
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Notification type representing a toast message
|
|
127
|
+
*/
|
|
128
|
+
interface Notification {
|
|
129
|
+
id: string;
|
|
130
|
+
message: string;
|
|
131
|
+
type: AlertColor;
|
|
132
|
+
duration?: number;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Context interface for notification management
|
|
136
|
+
*/
|
|
137
|
+
interface NotificationContextType {
|
|
138
|
+
showNotification: (message: string, type: AlertColor, duration?: number) => void;
|
|
139
|
+
success: (message: string, duration?: number) => void;
|
|
140
|
+
error: (message: string, duration?: number) => void;
|
|
141
|
+
warning: (message: string, duration?: number) => void;
|
|
142
|
+
info: (message: string, duration?: number) => void;
|
|
143
|
+
}
|
|
144
|
+
interface NotificationProviderProps {
|
|
145
|
+
/** Components to wrap with notification context */
|
|
146
|
+
children: ReactNode;
|
|
147
|
+
/** Default duration for notifications in milliseconds. Defaults to 6000ms */
|
|
148
|
+
defaultDuration?: number;
|
|
149
|
+
/** Maximum number of notifications to show at once. Defaults to 3 */
|
|
150
|
+
maxNotifications?: number;
|
|
151
|
+
/** Position of the notifications. Defaults to top-right */
|
|
152
|
+
anchorOrigin?: {
|
|
153
|
+
vertical: 'top' | 'bottom';
|
|
154
|
+
horizontal: 'left' | 'center' | 'right';
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* NotificationProvider manages toast notifications using Material-UI Snackbar and Alert.
|
|
159
|
+
* Provides methods to show success, error, warning, and info notifications.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```tsx
|
|
163
|
+
* <NotificationProvider>
|
|
164
|
+
* <App />
|
|
165
|
+
* </NotificationProvider>
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* // In a component:
|
|
169
|
+
* ```tsx
|
|
170
|
+
* const { success, error } = useNotification()
|
|
171
|
+
* success('Operation completed!')
|
|
172
|
+
* error('Something went wrong')
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
declare const NotificationProvider: React.FC<NotificationProviderProps>;
|
|
176
|
+
/**
|
|
177
|
+
* Hook to access notification context
|
|
178
|
+
* Must be used within a NotificationProvider
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```tsx
|
|
182
|
+
* const { success, error, warning, info } = useNotification()
|
|
183
|
+
*
|
|
184
|
+
* // Show notifications
|
|
185
|
+
* success('Data saved successfully!')
|
|
186
|
+
* error('Failed to save data')
|
|
187
|
+
* warning('This action cannot be undone')
|
|
188
|
+
* info('New update available')
|
|
189
|
+
*
|
|
190
|
+
* // With custom duration
|
|
191
|
+
* success('Quick message', 3000)
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
declare const useNotification: () => NotificationContextType;
|
|
195
|
+
|
|
125
196
|
/**
|
|
126
197
|
* Theme mode options
|
|
127
198
|
* - 'light': Always use light theme
|
|
@@ -274,9 +345,14 @@ interface ThemeToggleProps extends Omit<IconButtonProps, 'onClick'> {
|
|
|
274
345
|
lightModeTooltip?: string;
|
|
275
346
|
/**
|
|
276
347
|
* Tooltip text for dark mode
|
|
277
|
-
* @default "Switch to
|
|
348
|
+
* @default "Switch to system mode"
|
|
278
349
|
*/
|
|
279
350
|
darkModeTooltip?: string;
|
|
351
|
+
/**
|
|
352
|
+
* Tooltip text for system mode
|
|
353
|
+
* @default "Switch to light mode"
|
|
354
|
+
*/
|
|
355
|
+
systemModeTooltip?: string;
|
|
280
356
|
/**
|
|
281
357
|
* Whether to show tooltip
|
|
282
358
|
* @default true
|
|
@@ -284,8 +360,7 @@ interface ThemeToggleProps extends Omit<IconButtonProps, 'onClick'> {
|
|
|
284
360
|
showTooltip?: boolean;
|
|
285
361
|
}
|
|
286
362
|
/**
|
|
287
|
-
* A round button component for toggling between light and
|
|
288
|
-
* Note: Toggling skips 'system' mode and switches directly between light and dark
|
|
363
|
+
* A round button component for toggling between light, dark, and system themes
|
|
289
364
|
*/
|
|
290
365
|
declare const ThemeToggle: React.FC<ThemeToggleProps>;
|
|
291
366
|
|
|
@@ -562,4 +637,4 @@ declare class PermissionManager {
|
|
|
562
637
|
static hasPermission(permission: string): boolean;
|
|
563
638
|
}
|
|
564
639
|
|
|
565
|
-
export { type AuthContextType, AuthProvider, type AuthProviderProps, HttpClient, type HttpClientConfig, type HttpResponse, LocalStorage, type MenuItem, PermissionManager, ReadmeViewer, type RequestConfig, type ResolvedThemeMode, SidebarLayout, type SidebarLayoutProps, type Theme, type ThemeContextValue, type ThemeMode, ThemeProvider, ThemeToggle, borderRadius, cn, darkTheme, debounce, elevation, fontSize, fontWeight, formatDate, getHighlighter, lightTheme, lineHeight, spacing, throttle, tokens, transition, useAuth, useTheme, zIndex };
|
|
640
|
+
export { type AuthContextType, AuthProvider, type AuthProviderProps, HttpClient, type HttpClientConfig, type HttpResponse, LocalStorage, type MenuItem, type Notification, type NotificationContextType, NotificationProvider, type NotificationProviderProps, PermissionManager, ReadmeViewer, type RequestConfig, type ResolvedThemeMode, SidebarLayout, type SidebarLayoutProps, type Theme, type ThemeContextValue, type ThemeMode, ThemeProvider, ThemeToggle, borderRadius, cn, darkTheme, debounce, elevation, fontSize, fontWeight, formatDate, getHighlighter, lightTheme, lineHeight, spacing, throttle, tokens, transition, useAuth, useNotification, useTheme, zIndex };
|
package/dist/index.js
CHANGED
|
@@ -495,6 +495,82 @@ var ReadmeViewer = ({
|
|
|
495
495
|
) });
|
|
496
496
|
};
|
|
497
497
|
var ReadmeViewer_default = ReadmeViewer;
|
|
498
|
+
var NotificationContext = react.createContext(void 0);
|
|
499
|
+
var NotificationProvider = ({
|
|
500
|
+
children,
|
|
501
|
+
defaultDuration = 6e3,
|
|
502
|
+
maxNotifications = 3,
|
|
503
|
+
anchorOrigin = { vertical: "top", horizontal: "right" }
|
|
504
|
+
}) => {
|
|
505
|
+
const [notifications, setNotifications] = react.useState([]);
|
|
506
|
+
const showNotification = react.useCallback((message, type, duration = defaultDuration) => {
|
|
507
|
+
const id = `${Date.now()}-${Math.random()}`;
|
|
508
|
+
const newNotification = { id, message, type, duration };
|
|
509
|
+
setNotifications((prev) => {
|
|
510
|
+
const updated = [...prev, newNotification];
|
|
511
|
+
if (updated.length > maxNotifications) {
|
|
512
|
+
return updated.slice(updated.length - maxNotifications);
|
|
513
|
+
}
|
|
514
|
+
return updated;
|
|
515
|
+
});
|
|
516
|
+
}, [defaultDuration, maxNotifications]);
|
|
517
|
+
const handleClose = react.useCallback((id) => {
|
|
518
|
+
setNotifications((prev) => prev.filter((notif) => notif.id !== id));
|
|
519
|
+
}, []);
|
|
520
|
+
const success = react.useCallback((message, duration) => {
|
|
521
|
+
showNotification(message, "success", duration);
|
|
522
|
+
}, [showNotification]);
|
|
523
|
+
const error = react.useCallback((message, duration) => {
|
|
524
|
+
showNotification(message, "error", duration);
|
|
525
|
+
}, [showNotification]);
|
|
526
|
+
const warning = react.useCallback((message, duration) => {
|
|
527
|
+
showNotification(message, "warning", duration);
|
|
528
|
+
}, [showNotification]);
|
|
529
|
+
const info = react.useCallback((message, duration) => {
|
|
530
|
+
showNotification(message, "info", duration);
|
|
531
|
+
}, [showNotification]);
|
|
532
|
+
const contextValue = {
|
|
533
|
+
showNotification,
|
|
534
|
+
success,
|
|
535
|
+
error,
|
|
536
|
+
warning,
|
|
537
|
+
info
|
|
538
|
+
};
|
|
539
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(NotificationContext.Provider, { value: contextValue, children: [
|
|
540
|
+
children,
|
|
541
|
+
notifications.map((notification, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
542
|
+
material.Snackbar,
|
|
543
|
+
{
|
|
544
|
+
open: true,
|
|
545
|
+
autoHideDuration: notification.duration,
|
|
546
|
+
onClose: () => handleClose(notification.id),
|
|
547
|
+
anchorOrigin,
|
|
548
|
+
style: {
|
|
549
|
+
marginTop: index * 70
|
|
550
|
+
// Stack notifications vertically
|
|
551
|
+
},
|
|
552
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
553
|
+
material.Alert,
|
|
554
|
+
{
|
|
555
|
+
onClose: () => handleClose(notification.id),
|
|
556
|
+
severity: notification.type,
|
|
557
|
+
variant: "filled",
|
|
558
|
+
sx: { width: "100%" },
|
|
559
|
+
children: notification.message
|
|
560
|
+
}
|
|
561
|
+
)
|
|
562
|
+
},
|
|
563
|
+
notification.id
|
|
564
|
+
))
|
|
565
|
+
] });
|
|
566
|
+
};
|
|
567
|
+
var useNotification = () => {
|
|
568
|
+
const context = react.useContext(NotificationContext);
|
|
569
|
+
if (!context) {
|
|
570
|
+
throw new Error("useNotification must be used within a NotificationProvider");
|
|
571
|
+
}
|
|
572
|
+
return context;
|
|
573
|
+
};
|
|
498
574
|
|
|
499
575
|
// src/theme/tokens.ts
|
|
500
576
|
var tokens_exports = {};
|
|
@@ -922,9 +998,12 @@ var ThemeProvider = ({
|
|
|
922
998
|
setCustomTheme(newTheme);
|
|
923
999
|
}, []);
|
|
924
1000
|
const toggleTheme = react.useCallback(() => {
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
1001
|
+
setThemeModeState((prevMode) => {
|
|
1002
|
+
if (prevMode === "light") return "dark";
|
|
1003
|
+
if (prevMode === "dark") return "system";
|
|
1004
|
+
return "light";
|
|
1005
|
+
});
|
|
1006
|
+
}, []);
|
|
928
1007
|
const contextValue = react.useMemo(() => ({
|
|
929
1008
|
theme,
|
|
930
1009
|
themeMode,
|
|
@@ -972,12 +1051,37 @@ var useTheme = () => {
|
|
|
972
1051
|
};
|
|
973
1052
|
var ThemeToggle = ({
|
|
974
1053
|
lightModeTooltip = "Switch to dark mode",
|
|
975
|
-
darkModeTooltip = "Switch to
|
|
1054
|
+
darkModeTooltip = "Switch to system theme",
|
|
1055
|
+
systemModeTooltip = "Switch to light theme",
|
|
976
1056
|
showTooltip = true,
|
|
977
1057
|
sx,
|
|
978
1058
|
...props
|
|
979
1059
|
}) => {
|
|
980
|
-
const {
|
|
1060
|
+
const { themeMode, toggleTheme } = useTheme();
|
|
1061
|
+
const getIcon = () => {
|
|
1062
|
+
switch (themeMode) {
|
|
1063
|
+
case "light":
|
|
1064
|
+
return /* @__PURE__ */ jsxRuntime.jsx(iconsMaterial.LightMode, {});
|
|
1065
|
+
case "dark":
|
|
1066
|
+
return /* @__PURE__ */ jsxRuntime.jsx(iconsMaterial.DarkMode, {});
|
|
1067
|
+
case "system":
|
|
1068
|
+
return /* @__PURE__ */ jsxRuntime.jsx(iconsMaterial.BrightnessAuto, {});
|
|
1069
|
+
default:
|
|
1070
|
+
return /* @__PURE__ */ jsxRuntime.jsx(iconsMaterial.BrightnessAuto, {});
|
|
1071
|
+
}
|
|
1072
|
+
};
|
|
1073
|
+
const getTooltip = () => {
|
|
1074
|
+
switch (themeMode) {
|
|
1075
|
+
case "light":
|
|
1076
|
+
return lightModeTooltip;
|
|
1077
|
+
case "dark":
|
|
1078
|
+
return darkModeTooltip;
|
|
1079
|
+
case "system":
|
|
1080
|
+
return systemModeTooltip;
|
|
1081
|
+
default:
|
|
1082
|
+
return lightModeTooltip;
|
|
1083
|
+
}
|
|
1084
|
+
};
|
|
981
1085
|
const button = /* @__PURE__ */ jsxRuntime.jsx(
|
|
982
1086
|
material.IconButton,
|
|
983
1087
|
{
|
|
@@ -988,20 +1092,13 @@ var ThemeToggle = ({
|
|
|
988
1092
|
...sx
|
|
989
1093
|
},
|
|
990
1094
|
...props,
|
|
991
|
-
children:
|
|
1095
|
+
children: getIcon()
|
|
992
1096
|
}
|
|
993
1097
|
);
|
|
994
1098
|
if (!showTooltip) {
|
|
995
1099
|
return button;
|
|
996
1100
|
}
|
|
997
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
998
|
-
material.Tooltip,
|
|
999
|
-
{
|
|
1000
|
-
title: resolvedThemeMode === "light" ? lightModeTooltip : darkModeTooltip,
|
|
1001
|
-
arrow: true,
|
|
1002
|
-
children: button
|
|
1003
|
-
}
|
|
1004
|
-
);
|
|
1101
|
+
return /* @__PURE__ */ jsxRuntime.jsx(material.Tooltip, { title: getTooltip(), arrow: true, children: button });
|
|
1005
1102
|
};
|
|
1006
1103
|
|
|
1007
1104
|
// src/http/HttpClient.ts
|
|
@@ -1277,6 +1374,7 @@ PermissionManager.cachedPermissions = null;
|
|
|
1277
1374
|
exports.AuthProvider = AuthProvider;
|
|
1278
1375
|
exports.HttpClient = HttpClient;
|
|
1279
1376
|
exports.LocalStorage = LocalStorage;
|
|
1377
|
+
exports.NotificationProvider = NotificationProvider;
|
|
1280
1378
|
exports.PermissionManager = PermissionManager;
|
|
1281
1379
|
exports.ReadmeViewer = ReadmeViewer_default;
|
|
1282
1380
|
exports.SidebarLayout = SidebarLayout;
|
|
@@ -1298,6 +1396,7 @@ exports.throttle = throttle;
|
|
|
1298
1396
|
exports.tokens = tokens_exports;
|
|
1299
1397
|
exports.transition = transition;
|
|
1300
1398
|
exports.useAuth = useAuth;
|
|
1399
|
+
exports.useNotification = useNotification;
|
|
1301
1400
|
exports.useTheme = useTheme;
|
|
1302
1401
|
exports.zIndex = zIndex;
|
|
1303
1402
|
//# sourceMappingURL=index.js.map
|