@gofreego/tsutils 0.1.6 → 0.1.8
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 +73 -2
- package/dist/index.d.ts +73 -2
- package/dist/index.js +81 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +82 -5
- 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
|
|
@@ -566,4 +637,4 @@ declare class PermissionManager {
|
|
|
566
637
|
static hasPermission(permission: string): boolean;
|
|
567
638
|
}
|
|
568
639
|
|
|
569
|
-
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
|
|
@@ -566,4 +637,4 @@ declare class PermissionManager {
|
|
|
566
637
|
static hasPermission(permission: string): boolean;
|
|
567
638
|
}
|
|
568
639
|
|
|
569
|
-
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
|
@@ -32,6 +32,7 @@ var RouterMenuItem = ({ item, depth = 0, expanded, onToggle }) => {
|
|
|
32
32
|
{
|
|
33
33
|
component: hasChildren ? "div" : reactRouterDom.NavLink,
|
|
34
34
|
to: !hasChildren ? item.path || `/${item.id}` : void 0,
|
|
35
|
+
end: false,
|
|
35
36
|
onClick: hasChildren ? () => onToggle(item.id) : void 0,
|
|
36
37
|
sx: {
|
|
37
38
|
pl: 2 + depth * 2,
|
|
@@ -166,7 +167,7 @@ var SidebarLayoutRouterInner = ({
|
|
|
166
167
|
...sidebarStyle
|
|
167
168
|
}
|
|
168
169
|
},
|
|
169
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(material.List, { sx: { p: 0 }, children: menuItems.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
170
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(material.List, { sx: { p: 0 }, children: menuItems.filter((item) => item.label).map((item) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
170
171
|
RouterMenuItem,
|
|
171
172
|
{
|
|
172
173
|
item,
|
|
@@ -342,7 +343,7 @@ var SidebarLayoutWithState = ({
|
|
|
342
343
|
...sidebarStyle
|
|
343
344
|
}
|
|
344
345
|
},
|
|
345
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(material.List, { sx: { p: 0 }, children: menuItems.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
346
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(material.List, { sx: { p: 0 }, children: menuItems.filter((item) => item.label).map((item) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
346
347
|
StateMenuItem,
|
|
347
348
|
{
|
|
348
349
|
item,
|
|
@@ -495,6 +496,82 @@ var ReadmeViewer = ({
|
|
|
495
496
|
) });
|
|
496
497
|
};
|
|
497
498
|
var ReadmeViewer_default = ReadmeViewer;
|
|
499
|
+
var NotificationContext = react.createContext(void 0);
|
|
500
|
+
var NotificationProvider = ({
|
|
501
|
+
children,
|
|
502
|
+
defaultDuration = 6e3,
|
|
503
|
+
maxNotifications = 3,
|
|
504
|
+
anchorOrigin = { vertical: "top", horizontal: "right" }
|
|
505
|
+
}) => {
|
|
506
|
+
const [notifications, setNotifications] = react.useState([]);
|
|
507
|
+
const showNotification = react.useCallback((message, type, duration = defaultDuration) => {
|
|
508
|
+
const id = `${Date.now()}-${Math.random()}`;
|
|
509
|
+
const newNotification = { id, message, type, duration };
|
|
510
|
+
setNotifications((prev) => {
|
|
511
|
+
const updated = [...prev, newNotification];
|
|
512
|
+
if (updated.length > maxNotifications) {
|
|
513
|
+
return updated.slice(updated.length - maxNotifications);
|
|
514
|
+
}
|
|
515
|
+
return updated;
|
|
516
|
+
});
|
|
517
|
+
}, [defaultDuration, maxNotifications]);
|
|
518
|
+
const handleClose = react.useCallback((id) => {
|
|
519
|
+
setNotifications((prev) => prev.filter((notif) => notif.id !== id));
|
|
520
|
+
}, []);
|
|
521
|
+
const success = react.useCallback((message, duration) => {
|
|
522
|
+
showNotification(message, "success", duration);
|
|
523
|
+
}, [showNotification]);
|
|
524
|
+
const error = react.useCallback((message, duration) => {
|
|
525
|
+
showNotification(message, "error", duration);
|
|
526
|
+
}, [showNotification]);
|
|
527
|
+
const warning = react.useCallback((message, duration) => {
|
|
528
|
+
showNotification(message, "warning", duration);
|
|
529
|
+
}, [showNotification]);
|
|
530
|
+
const info = react.useCallback((message, duration) => {
|
|
531
|
+
showNotification(message, "info", duration);
|
|
532
|
+
}, [showNotification]);
|
|
533
|
+
const contextValue = {
|
|
534
|
+
showNotification,
|
|
535
|
+
success,
|
|
536
|
+
error,
|
|
537
|
+
warning,
|
|
538
|
+
info
|
|
539
|
+
};
|
|
540
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(NotificationContext.Provider, { value: contextValue, children: [
|
|
541
|
+
children,
|
|
542
|
+
notifications.map((notification, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
543
|
+
material.Snackbar,
|
|
544
|
+
{
|
|
545
|
+
open: true,
|
|
546
|
+
autoHideDuration: notification.duration,
|
|
547
|
+
onClose: () => handleClose(notification.id),
|
|
548
|
+
anchorOrigin,
|
|
549
|
+
style: {
|
|
550
|
+
marginTop: index * 70
|
|
551
|
+
// Stack notifications vertically
|
|
552
|
+
},
|
|
553
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
554
|
+
material.Alert,
|
|
555
|
+
{
|
|
556
|
+
onClose: () => handleClose(notification.id),
|
|
557
|
+
severity: notification.type,
|
|
558
|
+
variant: "filled",
|
|
559
|
+
sx: { width: "100%" },
|
|
560
|
+
children: notification.message
|
|
561
|
+
}
|
|
562
|
+
)
|
|
563
|
+
},
|
|
564
|
+
notification.id
|
|
565
|
+
))
|
|
566
|
+
] });
|
|
567
|
+
};
|
|
568
|
+
var useNotification = () => {
|
|
569
|
+
const context = react.useContext(NotificationContext);
|
|
570
|
+
if (!context) {
|
|
571
|
+
throw new Error("useNotification must be used within a NotificationProvider");
|
|
572
|
+
}
|
|
573
|
+
return context;
|
|
574
|
+
};
|
|
498
575
|
|
|
499
576
|
// src/theme/tokens.ts
|
|
500
577
|
var tokens_exports = {};
|
|
@@ -1298,6 +1375,7 @@ PermissionManager.cachedPermissions = null;
|
|
|
1298
1375
|
exports.AuthProvider = AuthProvider;
|
|
1299
1376
|
exports.HttpClient = HttpClient;
|
|
1300
1377
|
exports.LocalStorage = LocalStorage;
|
|
1378
|
+
exports.NotificationProvider = NotificationProvider;
|
|
1301
1379
|
exports.PermissionManager = PermissionManager;
|
|
1302
1380
|
exports.ReadmeViewer = ReadmeViewer_default;
|
|
1303
1381
|
exports.SidebarLayout = SidebarLayout;
|
|
@@ -1319,6 +1397,7 @@ exports.throttle = throttle;
|
|
|
1319
1397
|
exports.tokens = tokens_exports;
|
|
1320
1398
|
exports.transition = transition;
|
|
1321
1399
|
exports.useAuth = useAuth;
|
|
1400
|
+
exports.useNotification = useNotification;
|
|
1322
1401
|
exports.useTheme = useTheme;
|
|
1323
1402
|
exports.zIndex = zIndex;
|
|
1324
1403
|
//# sourceMappingURL=index.js.map
|