@zuzjs/ui 0.9.7 → 0.9.82

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.
Files changed (82) hide show
  1. package/dist/cjs/comps/Calendar/index.d.ts +3 -0
  2. package/dist/cjs/comps/Calendar/index.js +109 -0
  3. package/dist/cjs/comps/Calendar/types.d.ts +6 -0
  4. package/dist/cjs/comps/Calendar/types.js +1 -0
  5. package/dist/cjs/comps/Crumb/index.d.ts +1 -1
  6. package/dist/cjs/comps/DatePicker/index.d.ts +11 -0
  7. package/dist/cjs/comps/DatePicker/index.js +73 -0
  8. package/dist/cjs/comps/DatePicker/types.d.ts +6 -0
  9. package/dist/cjs/comps/DatePicker/types.js +1 -0
  10. package/dist/cjs/comps/Icon/index.d.ts +2 -0
  11. package/dist/cjs/comps/Icon/index.js +5 -2
  12. package/dist/cjs/comps/List/index.d.ts +1 -1
  13. package/dist/cjs/comps/Select/optionItem.d.ts +2 -1
  14. package/dist/cjs/comps/Select/optionItem.js +3 -2
  15. package/dist/cjs/comps/Select/types.d.ts +2 -0
  16. package/dist/cjs/comps/Table/index.js +2 -2
  17. package/dist/cjs/comps/Table/row.js +2 -2
  18. package/dist/cjs/comps/Table/types.d.ts +2 -0
  19. package/dist/cjs/comps/TextArea/commands.d.ts +12 -0
  20. package/dist/cjs/comps/TextArea/commands.js +16 -0
  21. package/dist/cjs/comps/TextArea/index.d.ts +13 -6
  22. package/dist/cjs/comps/TextArea/index.js +88 -6
  23. package/dist/cjs/comps/TextArea/types.d.ts +21 -0
  24. package/dist/cjs/comps/TextArea/types.js +1 -0
  25. package/dist/cjs/comps/index.d.ts +5 -1
  26. package/dist/cjs/comps/index.js +3 -0
  27. package/dist/cjs/comps/svgicons.d.ts +1 -0
  28. package/dist/cjs/comps/svgicons.js +1 -0
  29. package/dist/cjs/funs/index.d.ts +5 -0
  30. package/dist/cjs/funs/index.js +42 -0
  31. package/dist/cjs/funs/stylesheet.js +1 -0
  32. package/dist/cjs/hooks/index.d.ts +2 -0
  33. package/dist/cjs/hooks/index.js +2 -0
  34. package/dist/cjs/hooks/useCommandActions.d.ts +29 -0
  35. package/dist/cjs/hooks/useCommandActions.js +104 -0
  36. package/dist/cjs/hooks/usePosition.d.ts +2 -1
  37. package/dist/cjs/hooks/usePushNotifications.d.ts +45 -0
  38. package/dist/cjs/hooks/usePushNotifications.js +166 -0
  39. package/dist/cjs/hooks/useSlider.d.ts +1 -1
  40. package/dist/css/styles.css +1 -1
  41. package/dist/esm/comps/Calendar/index.d.ts +3 -0
  42. package/dist/esm/comps/Calendar/index.js +109 -0
  43. package/dist/esm/comps/Calendar/types.d.ts +6 -0
  44. package/dist/esm/comps/Calendar/types.js +1 -0
  45. package/dist/esm/comps/Crumb/index.d.ts +1 -1
  46. package/dist/esm/comps/DatePicker/index.d.ts +11 -0
  47. package/dist/esm/comps/DatePicker/index.js +73 -0
  48. package/dist/esm/comps/DatePicker/types.d.ts +6 -0
  49. package/dist/esm/comps/DatePicker/types.js +1 -0
  50. package/dist/esm/comps/Icon/index.d.ts +2 -0
  51. package/dist/esm/comps/Icon/index.js +5 -2
  52. package/dist/esm/comps/List/index.d.ts +1 -1
  53. package/dist/esm/comps/Select/optionItem.d.ts +2 -1
  54. package/dist/esm/comps/Select/optionItem.js +3 -2
  55. package/dist/esm/comps/Select/types.d.ts +2 -0
  56. package/dist/esm/comps/Table/index.js +2 -2
  57. package/dist/esm/comps/Table/row.js +2 -2
  58. package/dist/esm/comps/Table/types.d.ts +2 -0
  59. package/dist/esm/comps/TextArea/commands.d.ts +12 -0
  60. package/dist/esm/comps/TextArea/commands.js +16 -0
  61. package/dist/esm/comps/TextArea/index.d.ts +13 -6
  62. package/dist/esm/comps/TextArea/index.js +88 -6
  63. package/dist/esm/comps/TextArea/types.d.ts +21 -0
  64. package/dist/esm/comps/TextArea/types.js +1 -0
  65. package/dist/esm/comps/index.d.ts +5 -1
  66. package/dist/esm/comps/index.js +3 -0
  67. package/dist/esm/comps/svgicons.d.ts +1 -0
  68. package/dist/esm/comps/svgicons.js +1 -0
  69. package/dist/esm/funs/index.d.ts +5 -0
  70. package/dist/esm/funs/index.js +42 -0
  71. package/dist/esm/funs/stylesheet.js +1 -0
  72. package/dist/esm/hooks/index.d.ts +2 -0
  73. package/dist/esm/hooks/index.js +2 -0
  74. package/dist/esm/hooks/useCommandActions.d.ts +29 -0
  75. package/dist/esm/hooks/useCommandActions.js +104 -0
  76. package/dist/esm/hooks/usePosition.d.ts +2 -1
  77. package/dist/esm/hooks/usePushNotifications.d.ts +45 -0
  78. package/dist/esm/hooks/usePushNotifications.js +166 -0
  79. package/dist/esm/hooks/useSlider.d.ts +1 -1
  80. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  81. package/dist/tsconfig.tsbuildinfo +1 -1
  82. package/package.json +2 -1
@@ -0,0 +1,45 @@
1
+ export type PushSubscriptionMeta = {
2
+ endpoint: string;
3
+ keys: {
4
+ p256dh: string;
5
+ auth: string;
6
+ };
7
+ };
8
+ export type PushNotificationsOptions = {
9
+ /**
10
+ * VAPID public key (required for subscription)
11
+ */
12
+ vapidPublicKey: string;
13
+ /**
14
+ * Path to your service worker file
15
+ * @default '/sw.js'
16
+ */
17
+ serviceWorkerPath?: string;
18
+ /**
19
+ * Auto-request permission on mount
20
+ * @default false
21
+ */
22
+ requestPermissionOnMount?: boolean;
23
+ };
24
+ export type PushNotificationsResult = {
25
+ /** Current permission state */
26
+ permission: NotificationPermission;
27
+ /** Push subscription object (or null if not subscribed) */
28
+ subscription: PushSubscription | null;
29
+ /** JSON representation of subscription (easy to send to backend) */
30
+ subscriptionMeta: PushSubscriptionMeta | null;
31
+ /** Is push supported in this browser? */
32
+ isSupported: boolean;
33
+ /** Request permission and subscribe */
34
+ subscribe: () => Promise<PushSubscription | null>;
35
+ /** Unsubscribe from push */
36
+ unsubscribe: () => Promise<boolean>;
37
+ /** Request notification permission only */
38
+ requestPermission: () => Promise<NotificationPermission>;
39
+ /** Error state */
40
+ error: string | null;
41
+ /** Loading state */
42
+ isLoading: boolean;
43
+ };
44
+ declare const usePushNotifications: (options: PushNotificationsOptions) => PushNotificationsResult;
45
+ export default usePushNotifications;
@@ -0,0 +1,166 @@
1
+ import { useCallback, useEffect, useState } from "react";
2
+ import { urlBase64ToUint8Array } from "../funs";
3
+ const usePushNotifications = (options) => {
4
+ const { vapidPublicKey, serviceWorkerPath = '/sw.js', requestPermissionOnMount = false, } = options;
5
+ const [permission, setPermission] = useState('default');
6
+ const [subscription, setSubscription] = useState(null);
7
+ const [subscriptionMeta, setSubscriptionMeta] = useState(null);
8
+ const [error, setError] = useState(null);
9
+ const [isLoading, setIsLoading] = useState(false);
10
+ const [registration, setRegistration] = useState(null);
11
+ const [isSupported, setIsSupported] = useState(false);
12
+ // Register service worker
13
+ const registerServiceWorker = useCallback(async () => {
14
+ if (!isSupported)
15
+ return null;
16
+ try {
17
+ const reg = await navigator.serviceWorker.register(serviceWorkerPath, {
18
+ scope: '/',
19
+ updateViaCache: 'all',
20
+ });
21
+ setRegistration(reg);
22
+ return reg;
23
+ }
24
+ catch (err) {
25
+ console.error('Service Worker registration failed:', err);
26
+ setError('Failed to register service worker');
27
+ return null;
28
+ }
29
+ }, [serviceWorkerPath, isSupported]);
30
+ // Get current subscription
31
+ const getCurrentSubscription = useCallback(async (reg) => {
32
+ try {
33
+ const sub = await reg.pushManager.getSubscription();
34
+ setSubscription(sub);
35
+ if (sub) {
36
+ setSubscriptionMeta(sub.toJSON());
37
+ }
38
+ else {
39
+ setSubscriptionMeta(null);
40
+ }
41
+ return sub;
42
+ }
43
+ catch (err) {
44
+ console.error('Failed to get subscription:', err);
45
+ setError('Failed to get subscription');
46
+ return null;
47
+ }
48
+ }, []);
49
+ // Subscribe to push
50
+ const subscribe = useCallback(async () => {
51
+ if (!isSupported || !registration) {
52
+ setError('Push not supported or service worker not registered');
53
+ return null;
54
+ }
55
+ setIsLoading(true);
56
+ setError(null);
57
+ try {
58
+ const permissionResult = await Notification.requestPermission();
59
+ setPermission(permissionResult);
60
+ if (permissionResult !== 'granted') {
61
+ setError('Permission not granted for notifications');
62
+ setIsLoading(false);
63
+ return null;
64
+ }
65
+ const applicationServerKey = urlBase64ToUint8Array(vapidPublicKey);
66
+ const pushSubscription = await registration.pushManager.subscribe({
67
+ userVisibleOnly: true,
68
+ applicationServerKey,
69
+ });
70
+ setSubscription(pushSubscription);
71
+ setSubscriptionMeta(pushSubscription.toJSON());
72
+ setIsLoading(false);
73
+ return pushSubscription;
74
+ }
75
+ catch (err) {
76
+ console.error('Subscription failed:', err);
77
+ setError(err.message || 'Failed to subscribe');
78
+ setIsLoading(false);
79
+ return null;
80
+ }
81
+ }, [isSupported, registration, vapidPublicKey]);
82
+ // Unsubscribe
83
+ const unsubscribe = useCallback(async () => {
84
+ if (!subscription)
85
+ return true;
86
+ try {
87
+ const result = await subscription.unsubscribe();
88
+ if (result) {
89
+ setSubscription(null);
90
+ setSubscriptionMeta(null);
91
+ }
92
+ return result;
93
+ }
94
+ catch (err) {
95
+ console.error('Failed to unsubscribe:', err);
96
+ return false;
97
+ }
98
+ }, [subscription]);
99
+ // Request permission only
100
+ const requestPermission = useCallback(async () => {
101
+ const result = await Notification.requestPermission();
102
+ setPermission(result);
103
+ return result;
104
+ }, []);
105
+ // Initialize
106
+ useEffect(() => {
107
+ const _isSupported = 'PushManager' in window && 'serviceWorker' in navigator;
108
+ setIsSupported(_isSupported);
109
+ if (!_isSupported) {
110
+ setError('Push notifications not supported in this browser');
111
+ return;
112
+ }
113
+ let isMounted = true;
114
+ const init = async () => {
115
+ const reg = await registerServiceWorker();
116
+ if (!reg || !isMounted)
117
+ return;
118
+ setPermission(Notification.permission);
119
+ await getCurrentSubscription(reg);
120
+ if (requestPermissionOnMount && Notification.permission === 'default') {
121
+ await requestPermission();
122
+ }
123
+ };
124
+ init();
125
+ return () => {
126
+ isMounted = false;
127
+ };
128
+ }, [
129
+ isSupported,
130
+ registerServiceWorker,
131
+ getCurrentSubscription,
132
+ requestPermissionOnMount,
133
+ requestPermission,
134
+ ]);
135
+ // Listen for permission changes
136
+ useEffect(() => {
137
+ if (!('permissions' in navigator))
138
+ return;
139
+ let revoked = false;
140
+ const checkPermission = async () => {
141
+ if (revoked)
142
+ return;
143
+ const perm = await navigator.permissions.query({ name: 'notifications' });
144
+ perm.onchange = () => {
145
+ setPermission(Notification.permission);
146
+ if (Notification.permission === 'denied') {
147
+ revoked = true;
148
+ unsubscribe();
149
+ }
150
+ };
151
+ };
152
+ checkPermission();
153
+ }, [unsubscribe]);
154
+ return {
155
+ permission,
156
+ subscription,
157
+ subscriptionMeta,
158
+ isSupported,
159
+ subscribe,
160
+ unsubscribe,
161
+ requestPermission,
162
+ error,
163
+ isLoading,
164
+ };
165
+ };
166
+ export default usePushNotifications;
@@ -2,6 +2,6 @@ declare const useSlider: () => {
2
2
  push: (key: string) => void;
3
3
  goBack: () => void;
4
4
  prevKey: string | null;
5
- direction: "left" | "right";
5
+ direction: "right" | "left";
6
6
  };
7
7
  export default useSlider;