@brokr/sdk 1.0.0 → 2.0.0
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/account.js +34 -0
- package/dist/account.mjs +7 -0
- package/dist/auth.js +628 -114
- package/dist/auth.mjs +611 -111
- package/dist/chat.js +34 -0
- package/dist/chat.mjs +7 -0
- package/dist/events.js +64 -0
- package/dist/events.mjs +37 -0
- package/dist/feature.js +6304 -0
- package/dist/feature.mjs +6278 -0
- package/dist/files.js +428 -0
- package/dist/files.mjs +408 -0
- package/dist/index.d.ts +18 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4069 -454
- package/dist/index.mjs +4040 -448
- package/dist/logs.js +148 -0
- package/dist/logs.mjs +124 -0
- package/dist/management.js +14 -13
- package/dist/management.mjs +14 -13
- package/dist/next.js +2725 -0
- package/dist/next.mjs +2710 -0
- package/dist/notifications.js +140 -0
- package/dist/notifications.mjs +110 -0
- package/dist/payments.js +32 -0
- package/dist/payments.mjs +7 -0
- package/dist/react-notifications.js +286 -0
- package/dist/react-notifications.mjs +254 -0
- package/dist/react-styles.js +2718 -0
- package/dist/react-styles.mjs +2682 -0
- package/dist/react-theme.js +4194 -0
- package/dist/react-theme.mjs +4170 -0
- package/dist/react.js +8512 -209
- package/dist/react.mjs +8488 -179
- package/dist/runtime.js +2113 -385
- package/dist/runtime.mjs +2085 -397
- package/dist/src/account/config.d.ts +42 -0
- package/dist/src/account/config.d.ts.map +1 -0
- package/dist/src/account/index.d.ts +3 -0
- package/dist/src/account/index.d.ts.map +1 -0
- package/dist/src/ai/client.d.ts +58 -0
- package/dist/src/ai/client.d.ts.map +1 -0
- package/dist/src/ai/conversation-title.d.ts +13 -0
- package/dist/src/ai/conversation-title.d.ts.map +1 -0
- package/dist/src/ai/types.d.ts +81 -0
- package/dist/src/ai/types.d.ts.map +1 -0
- package/dist/src/auth.d.ts +133 -20
- package/dist/src/auth.d.ts.map +1 -1
- package/dist/src/chat/config.d.ts +61 -0
- package/dist/src/chat/config.d.ts.map +1 -0
- package/dist/src/chat/index.d.ts +3 -0
- package/dist/src/chat/index.d.ts.map +1 -0
- package/dist/src/chat/sse-parser.d.ts +44 -0
- package/dist/src/chat/sse-parser.d.ts.map +1 -0
- package/dist/src/dev-console.d.ts +18 -0
- package/dist/src/dev-console.d.ts.map +1 -0
- package/dist/src/email/client.d.ts +33 -0
- package/dist/src/email/client.d.ts.map +1 -0
- package/dist/src/email/templates.d.ts +15 -0
- package/dist/src/email/templates.d.ts.map +1 -0
- package/dist/src/email/types.d.ts +35 -0
- package/dist/src/email/types.d.ts.map +1 -0
- package/dist/src/env-detect.d.ts +25 -0
- package/dist/src/env-detect.d.ts.map +1 -0
- package/dist/src/errors.d.ts +53 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/events/client.d.ts +25 -0
- package/dist/src/events/client.d.ts.map +1 -0
- package/dist/src/events/index.d.ts +9 -0
- package/dist/src/events/index.d.ts.map +1 -0
- package/dist/src/events/types.d.ts +10 -0
- package/dist/src/events/types.d.ts.map +1 -0
- package/dist/src/feature/canonical.d.ts +33 -0
- package/dist/src/feature/canonical.d.ts.map +1 -0
- package/dist/src/feature/create-feature.d.ts +33 -0
- package/dist/src/feature/create-feature.d.ts.map +1 -0
- package/dist/src/feature/db.d.ts +16 -0
- package/dist/src/feature/db.d.ts.map +1 -0
- package/dist/src/feature/handlers.d.ts +28 -0
- package/dist/src/feature/handlers.d.ts.map +1 -0
- package/dist/src/feature/index.d.ts +21 -0
- package/dist/src/feature/index.d.ts.map +1 -0
- package/dist/src/feature/manifest.d.ts +173 -0
- package/dist/src/feature/manifest.d.ts.map +1 -0
- package/dist/src/feature/mapping.d.ts +18 -0
- package/dist/src/feature/mapping.d.ts.map +1 -0
- package/dist/src/feature/runtime.d.ts +45 -0
- package/dist/src/feature/runtime.d.ts.map +1 -0
- package/dist/src/feature/types.d.ts +65 -0
- package/dist/src/feature/types.d.ts.map +1 -0
- package/dist/src/files/client.d.ts +28 -0
- package/dist/src/files/client.d.ts.map +1 -0
- package/dist/src/files/types.d.ts +28 -0
- package/dist/src/files/types.d.ts.map +1 -0
- package/dist/src/fix-registry.d.ts +8 -0
- package/dist/src/fix-registry.d.ts.map +1 -0
- package/dist/src/gateway.d.ts +32 -0
- package/dist/src/gateway.d.ts.map +1 -0
- package/dist/src/logs/capture.d.ts +56 -0
- package/dist/src/logs/capture.d.ts.map +1 -0
- package/dist/src/logs/index.d.ts +2 -0
- package/dist/src/logs/index.d.ts.map +1 -0
- package/dist/src/management.d.ts +1 -1
- package/dist/src/management.d.ts.map +1 -1
- package/dist/src/models.d.ts +32 -0
- package/dist/src/models.d.ts.map +1 -0
- package/dist/src/next/auth.d.ts +54 -0
- package/dist/src/next/auth.d.ts.map +1 -0
- package/dist/src/next/chat.d.ts +31 -0
- package/dist/src/next/chat.d.ts.map +1 -0
- package/dist/src/next/index.d.ts +14 -0
- package/dist/src/next/index.d.ts.map +1 -0
- package/dist/src/next/notifications.d.ts +67 -0
- package/dist/src/next/notifications.d.ts.map +1 -0
- package/dist/src/notifications/built-ins.d.ts +9 -0
- package/dist/src/notifications/built-ins.d.ts.map +1 -0
- package/dist/src/notifications/client.d.ts +38 -0
- package/dist/src/notifications/client.d.ts.map +1 -0
- package/dist/src/notifications/config.d.ts +71 -0
- package/dist/src/notifications/config.d.ts.map +1 -0
- package/dist/src/notifications/index.d.ts +6 -0
- package/dist/src/notifications/index.d.ts.map +1 -0
- package/dist/src/notifications/registry.d.ts +67 -0
- package/dist/src/notifications/registry.d.ts.map +1 -0
- package/dist/src/notifications/types.d.ts +48 -0
- package/dist/src/notifications/types.d.ts.map +1 -0
- package/dist/src/payments/client.d.ts +64 -0
- package/dist/src/payments/client.d.ts.map +1 -0
- package/dist/src/payments/config.d.ts +46 -0
- package/dist/src/payments/config.d.ts.map +1 -0
- package/dist/src/payments/entitlements.d.ts +48 -0
- package/dist/src/payments/entitlements.d.ts.map +1 -0
- package/dist/src/payments/types.d.ts +135 -0
- package/dist/src/payments/types.d.ts.map +1 -0
- package/dist/src/react/BrokrErrorBoundary.d.ts +23 -0
- package/dist/src/react/BrokrErrorBoundary.d.ts.map +1 -0
- package/dist/src/react/account/AccountPanel.d.ts +12 -0
- package/dist/src/react/account/AccountPanel.d.ts.map +1 -0
- package/dist/src/react/account/Avatar.d.ts +11 -0
- package/dist/src/react/account/Avatar.d.ts.map +1 -0
- package/dist/src/react/account/ProfilePhotoButton.d.ts +7 -0
- package/dist/src/react/account/ProfilePhotoButton.d.ts.map +1 -0
- package/dist/src/react/account/UserButton.d.ts +7 -0
- package/dist/src/react/account/UserButton.d.ts.map +1 -0
- package/dist/src/react/auth-pages/AuthPageShell.d.ts +9 -0
- package/dist/src/react/auth-pages/AuthPageShell.d.ts.map +1 -0
- package/dist/src/react/auth-pages/SignInPage.d.ts +9 -0
- package/dist/src/react/auth-pages/SignInPage.d.ts.map +1 -0
- package/dist/src/react/auth-pages/SignUpPage.d.ts +8 -0
- package/dist/src/react/auth-pages/SignUpPage.d.ts.map +1 -0
- package/dist/src/react/auth.d.ts +1 -49
- package/dist/src/react/auth.d.ts.map +1 -1
- package/dist/src/react/chat/AIChat.d.ts +4 -0
- package/dist/src/react/chat/AIChat.d.ts.map +1 -0
- package/dist/src/react/chat/ChatContext.d.ts +76 -0
- package/dist/src/react/chat/ChatContext.d.ts.map +1 -0
- package/dist/src/react/chat/ChatInput.d.ts +3 -0
- package/dist/src/react/chat/ChatInput.d.ts.map +1 -0
- package/dist/src/react/chat/MarkdownRenderer.d.ts +5 -0
- package/dist/src/react/chat/MarkdownRenderer.d.ts.map +1 -0
- package/dist/src/react/chat/MessageBubble.d.ts +14 -0
- package/dist/src/react/chat/MessageBubble.d.ts.map +1 -0
- package/dist/src/react/chat/MessagePane.d.ts +10 -0
- package/dist/src/react/chat/MessagePane.d.ts.map +1 -0
- package/dist/src/react/chat/ModelSelector.d.ts +13 -0
- package/dist/src/react/chat/ModelSelector.d.ts.map +1 -0
- package/dist/src/react/chat/ThreadSidebar.d.ts +3 -0
- package/dist/src/react/chat/ThreadSidebar.d.ts.map +1 -0
- package/dist/src/react/chat/index.d.ts +5 -0
- package/dist/src/react/chat/index.d.ts.map +1 -0
- package/dist/src/react/chat/token-limit.d.ts +14 -0
- package/dist/src/react/chat/token-limit.d.ts.map +1 -0
- package/dist/src/react/chat/types.d.ts +65 -0
- package/dist/src/react/chat/types.d.ts.map +1 -0
- package/dist/src/react/chat/useChat.d.ts +57 -0
- package/dist/src/react/chat/useChat.d.ts.map +1 -0
- package/dist/src/react/composites/FabAI.d.ts +15 -0
- package/dist/src/react/composites/FabAI.d.ts.map +1 -0
- package/dist/src/react/composites/FeedbackWidget.d.ts +10 -0
- package/dist/src/react/composites/FeedbackWidget.d.ts.map +1 -0
- package/dist/src/react/composites/SmartUpload.d.ts +12 -0
- package/dist/src/react/composites/SmartUpload.d.ts.map +1 -0
- package/dist/src/react/config.d.ts +23 -0
- package/dist/src/react/config.d.ts.map +1 -0
- package/dist/src/react/context.d.ts +4 -0
- package/dist/src/react/context.d.ts.map +1 -0
- package/dist/src/react/css/account.d.ts +2 -0
- package/dist/src/react/css/account.d.ts.map +1 -0
- package/dist/src/react/css/animations.d.ts +2 -0
- package/dist/src/react/css/animations.d.ts.map +1 -0
- package/dist/src/react/css/auth.d.ts +2 -0
- package/dist/src/react/css/auth.d.ts.map +1 -0
- package/dist/src/react/css/chat-extras.d.ts +2 -0
- package/dist/src/react/css/chat-extras.d.ts.map +1 -0
- package/dist/src/react/css/chat.d.ts +2 -0
- package/dist/src/react/css/chat.d.ts.map +1 -0
- package/dist/src/react/css/composites.d.ts +2 -0
- package/dist/src/react/css/composites.d.ts.map +1 -0
- package/dist/src/react/css/gates.d.ts +2 -0
- package/dist/src/react/css/gates.d.ts.map +1 -0
- package/dist/src/react/css/index.d.ts +3 -0
- package/dist/src/react/css/index.d.ts.map +1 -0
- package/dist/src/react/css/markdown.d.ts +2 -0
- package/dist/src/react/css/markdown.d.ts.map +1 -0
- package/dist/src/react/css/notifications.d.ts +2 -0
- package/dist/src/react/css/notifications.d.ts.map +1 -0
- package/dist/src/react/css/primitives.d.ts +2 -0
- package/dist/src/react/css/primitives.d.ts.map +1 -0
- package/dist/src/react/css/reset.d.ts +2 -0
- package/dist/src/react/css/reset.d.ts.map +1 -0
- package/dist/src/react/css/responsive.d.ts +2 -0
- package/dist/src/react/css/responsive.d.ts.map +1 -0
- package/dist/src/react/css/skeleton.d.ts +2 -0
- package/dist/src/react/css/skeleton.d.ts.map +1 -0
- package/dist/src/react/css/tokens.d.ts +2 -0
- package/dist/src/react/css/tokens.d.ts.map +1 -0
- package/dist/src/react/gates/AuthWall.d.ts +7 -0
- package/dist/src/react/gates/AuthWall.d.ts.map +1 -0
- package/dist/src/react/gates/BillingBoundary.d.ts +4 -0
- package/dist/src/react/gates/BillingBoundary.d.ts.map +1 -0
- package/dist/src/react/gates/Gate.d.ts +9 -0
- package/dist/src/react/gates/Gate.d.ts.map +1 -0
- package/dist/src/react/gates/RequirePlan.d.ts +4 -0
- package/dist/src/react/gates/RequirePlan.d.ts.map +1 -0
- package/dist/src/react/gates/RequireUser.d.ts +4 -0
- package/dist/src/react/gates/RequireUser.d.ts.map +1 -0
- package/dist/src/react/gates/UsageGate.d.ts +4 -0
- package/dist/src/react/gates/UsageGate.d.ts.map +1 -0
- package/dist/src/react/helpers.d.ts +7 -0
- package/dist/src/react/helpers.d.ts.map +1 -0
- package/dist/src/react/hooks/use-theme.d.ts +15 -0
- package/dist/src/react/hooks/use-theme.d.ts.map +1 -0
- package/dist/src/react/hooks/use-user.d.ts +12 -0
- package/dist/src/react/hooks/use-user.d.ts.map +1 -0
- package/dist/src/react/icons.d.ts +26 -0
- package/dist/src/react/icons.d.ts.map +1 -0
- package/dist/src/react/index.d.ts +48 -0
- package/dist/src/react/index.d.ts.map +1 -0
- package/dist/src/react/notifications/NotificationBell.d.ts +7 -0
- package/dist/src/react/notifications/NotificationBell.d.ts.map +1 -0
- package/dist/src/react/notifications/NotificationList.d.ts +7 -0
- package/dist/src/react/notifications/NotificationList.d.ts.map +1 -0
- package/dist/src/react/notifications/Toast.d.ts +13 -0
- package/dist/src/react/notifications/Toast.d.ts.map +1 -0
- package/dist/src/react/notifications/index.d.ts +8 -0
- package/dist/src/react/notifications/index.d.ts.map +1 -0
- package/dist/src/react/notifications/provider.d.ts +14 -0
- package/dist/src/react/notifications/provider.d.ts.map +1 -0
- package/dist/src/react/notifications/use-notifications.d.ts +24 -0
- package/dist/src/react/notifications/use-notifications.d.ts.map +1 -0
- package/dist/src/react/payments/AutoReloadToggle.d.ts +6 -0
- package/dist/src/react/payments/AutoReloadToggle.d.ts.map +1 -0
- package/dist/src/react/payments/Balance.d.ts +8 -0
- package/dist/src/react/payments/Balance.d.ts.map +1 -0
- package/dist/src/react/payments/CancelSubscription.d.ts +6 -0
- package/dist/src/react/payments/CancelSubscription.d.ts.map +1 -0
- package/dist/src/react/payments/CheckoutButton.d.ts +7 -0
- package/dist/src/react/payments/CheckoutButton.d.ts.map +1 -0
- package/dist/src/react/payments/CustomerPortalButton.d.ts +6 -0
- package/dist/src/react/payments/CustomerPortalButton.d.ts.map +1 -0
- package/dist/src/react/payments/FeatureMeter.d.ts +6 -0
- package/dist/src/react/payments/FeatureMeter.d.ts.map +1 -0
- package/dist/src/react/payments/Plans.d.ts +8 -0
- package/dist/src/react/payments/Plans.d.ts.map +1 -0
- package/dist/src/react/payments/TopUpButton.d.ts +8 -0
- package/dist/src/react/payments/TopUpButton.d.ts.map +1 -0
- package/dist/src/react/payments/UpdateBilling.d.ts +3 -0
- package/dist/src/react/payments/UpdateBilling.d.ts.map +1 -0
- package/dist/src/react/payments/UpgradePrompt.d.ts +8 -0
- package/dist/src/react/payments/UpgradePrompt.d.ts.map +1 -0
- package/dist/src/react/primitives/Skeleton.d.ts +15 -0
- package/dist/src/react/primitives/Skeleton.d.ts.map +1 -0
- package/dist/src/react/provider.d.ts +21 -0
- package/dist/src/react/provider.d.ts.map +1 -0
- package/dist/src/react/request.d.ts +2 -0
- package/dist/src/react/request.d.ts.map +1 -0
- package/dist/src/react/styles-entry.d.ts +4 -0
- package/dist/src/react/styles-entry.d.ts.map +1 -0
- package/dist/src/react/styles.d.ts +2 -0
- package/dist/src/react/styles.d.ts.map +1 -0
- package/dist/src/react/theme-entry.d.ts +3 -0
- package/dist/src/react/theme-entry.d.ts.map +1 -0
- package/dist/src/react/theme.d.ts +6 -0
- package/dist/src/react/theme.d.ts.map +1 -0
- package/dist/src/react/types.d.ts +191 -0
- package/dist/src/react/types.d.ts.map +1 -0
- package/dist/src/react/use-brokr-theme.d.ts +6 -0
- package/dist/src/react/use-brokr-theme.d.ts.map +1 -0
- package/dist/src/runtime.d.ts +69 -180
- package/dist/src/runtime.d.ts.map +1 -1
- package/dist/src/storage/client.d.ts +113 -0
- package/dist/src/storage/client.d.ts.map +1 -0
- package/dist/src/storage/types.d.ts +60 -0
- package/dist/src/storage/types.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +70 -9
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/react/notifications/NotificationBell.tsx
|
|
4
|
+
import React3, { useCallback as useCallback3, useEffect as useEffect3, useMemo as useMemo3, useRef as useRef3, useState as useState3 } from "react";
|
|
5
|
+
|
|
6
|
+
// src/react/notifications/use-notifications.ts
|
|
7
|
+
import { useContext } from "react";
|
|
8
|
+
|
|
9
|
+
// src/react/notifications/provider.tsx
|
|
10
|
+
import React2, {
|
|
11
|
+
createContext,
|
|
12
|
+
useCallback as useCallback2,
|
|
13
|
+
useEffect as useEffect2,
|
|
14
|
+
useMemo as useMemo2,
|
|
15
|
+
useRef as useRef2,
|
|
16
|
+
useState as useState2
|
|
17
|
+
} from "react";
|
|
18
|
+
|
|
19
|
+
// src/notifications/config.ts
|
|
20
|
+
function defineNotifications(config) {
|
|
21
|
+
return config;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// src/notifications/registry.ts
|
|
25
|
+
function resolveNotificationType(registry, type, data) {
|
|
26
|
+
const entry = registry[type ?? "default"];
|
|
27
|
+
if (!entry) {
|
|
28
|
+
return { image: null, href: null, variant: "default", suppressKey: null };
|
|
29
|
+
}
|
|
30
|
+
let image = null;
|
|
31
|
+
try {
|
|
32
|
+
image = entry.imageResolver?.(data) ?? null;
|
|
33
|
+
} catch {
|
|
34
|
+
}
|
|
35
|
+
let href = null;
|
|
36
|
+
try {
|
|
37
|
+
href = entry.hrefResolver?.(data) ?? null;
|
|
38
|
+
} catch {
|
|
39
|
+
}
|
|
40
|
+
let suppressKey = null;
|
|
41
|
+
try {
|
|
42
|
+
suppressKey = entry.suppressKey?.(data) ?? null;
|
|
43
|
+
} catch {
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
image,
|
|
47
|
+
href,
|
|
48
|
+
variant: entry.defaultVariant ?? "default",
|
|
49
|
+
suppressKey
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/react/notifications/Toast.tsx
|
|
54
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
55
|
+
|
|
56
|
+
// src/react/notifications/provider.tsx
|
|
57
|
+
var NotificationsContext = createContext(null);
|
|
58
|
+
|
|
59
|
+
// src/react/notifications/use-notifications.ts
|
|
60
|
+
function useNotifications() {
|
|
61
|
+
const ctx = useContext(NotificationsContext);
|
|
62
|
+
if (!ctx) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
"useNotifications() requires <BrokrProvider notifications> or <BrokrProvider notifications={config}>. Pass the notifications prop to enable the notification system."
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
return ctx;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/react/notifications/NotificationBell.tsx
|
|
71
|
+
function timeAgo(iso) {
|
|
72
|
+
const diff = Date.now() - new Date(iso).getTime();
|
|
73
|
+
const mins = Math.floor(diff / 6e4);
|
|
74
|
+
if (mins < 1) return "just now";
|
|
75
|
+
if (mins < 60) return `${mins}m ago`;
|
|
76
|
+
const hours = Math.floor(mins / 60);
|
|
77
|
+
if (hours < 24) return `${hours}h ago`;
|
|
78
|
+
const days = Math.floor(hours / 24);
|
|
79
|
+
return `${days}d ago`;
|
|
80
|
+
}
|
|
81
|
+
function NotificationBell() {
|
|
82
|
+
const { notifications, unreadCount, markRead, markAllRead, isLoading, registry } = useNotifications();
|
|
83
|
+
const [open, setOpen] = useState3(false);
|
|
84
|
+
const containerRef = useRef3(null);
|
|
85
|
+
const markReadTimerRef = useRef3(null);
|
|
86
|
+
const toggle = useCallback3(() => setOpen((o) => !o), []);
|
|
87
|
+
useEffect3(() => {
|
|
88
|
+
if (markReadTimerRef.current) {
|
|
89
|
+
clearTimeout(markReadTimerRef.current);
|
|
90
|
+
markReadTimerRef.current = null;
|
|
91
|
+
}
|
|
92
|
+
if (open && unreadCount > 0) {
|
|
93
|
+
markReadTimerRef.current = setTimeout(() => {
|
|
94
|
+
markAllRead();
|
|
95
|
+
}, 800);
|
|
96
|
+
}
|
|
97
|
+
return () => {
|
|
98
|
+
if (markReadTimerRef.current) {
|
|
99
|
+
clearTimeout(markReadTimerRef.current);
|
|
100
|
+
markReadTimerRef.current = null;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}, [open, unreadCount, markAllRead]);
|
|
104
|
+
useEffect3(() => {
|
|
105
|
+
if (!open) return;
|
|
106
|
+
function handleClick(e) {
|
|
107
|
+
if (containerRef.current && !containerRef.current.contains(e.target)) {
|
|
108
|
+
setOpen(false);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
document.addEventListener("mousedown", handleClick);
|
|
112
|
+
return () => document.removeEventListener("mousedown", handleClick);
|
|
113
|
+
}, [open]);
|
|
114
|
+
useEffect3(() => {
|
|
115
|
+
if (!open) return;
|
|
116
|
+
function handleKey(e) {
|
|
117
|
+
if (e.key === "Escape") setOpen(false);
|
|
118
|
+
}
|
|
119
|
+
document.addEventListener("keydown", handleKey);
|
|
120
|
+
return () => document.removeEventListener("keydown", handleKey);
|
|
121
|
+
}, [open]);
|
|
122
|
+
const sorted = useMemo3(
|
|
123
|
+
() => [...notifications].sort(
|
|
124
|
+
(a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
|
|
125
|
+
),
|
|
126
|
+
[notifications]
|
|
127
|
+
);
|
|
128
|
+
const handleItemClick = useCallback3((notif) => {
|
|
129
|
+
if (!notif.read) markRead(notif.id);
|
|
130
|
+
const notifData = notif.data ?? {};
|
|
131
|
+
const notifType = notif.type ?? notifData.type ?? "default";
|
|
132
|
+
const resolved = resolveNotificationType(registry, notifType, notifData);
|
|
133
|
+
const href = resolved.href ?? notif.href ?? notifData.href ?? null;
|
|
134
|
+
if (href) {
|
|
135
|
+
window.location.assign(href);
|
|
136
|
+
}
|
|
137
|
+
}, [markRead, registry]);
|
|
138
|
+
return /* @__PURE__ */ React3.createElement("div", { className: "brokr-notif-bell-wrap", ref: containerRef }, /* @__PURE__ */ React3.createElement(
|
|
139
|
+
"button",
|
|
140
|
+
{
|
|
141
|
+
type: "button",
|
|
142
|
+
className: "brokr-notif-bell",
|
|
143
|
+
onClick: toggle,
|
|
144
|
+
"aria-label": `Notifications${unreadCount > 0 ? ` (${unreadCount} unread)` : ""}`,
|
|
145
|
+
"aria-expanded": open
|
|
146
|
+
},
|
|
147
|
+
/* @__PURE__ */ React3.createElement("svg", { "aria-hidden": "true", width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.75", strokeLinecap: "round", strokeLinejoin: "round" }, /* @__PURE__ */ React3.createElement("path", { d: "M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9" }), /* @__PURE__ */ React3.createElement("path", { d: "M10.3 21a1.94 1.94 0 0 0 3.4 0" })),
|
|
148
|
+
unreadCount > 0 && /* @__PURE__ */ React3.createElement("span", { className: "brokr-notif-badge" }, unreadCount > 99 ? "99+" : unreadCount)
|
|
149
|
+
), open && /* @__PURE__ */ React3.createElement("div", { className: "brokr-notif-dropdown", role: "menu" }, /* @__PURE__ */ React3.createElement("div", { className: "brokr-notif-dropdown-header" }, /* @__PURE__ */ React3.createElement("span", { className: "brokr-notif-dropdown-title" }, "Notifications"), unreadCount > 0 && /* @__PURE__ */ React3.createElement(
|
|
150
|
+
"button",
|
|
151
|
+
{
|
|
152
|
+
type: "button",
|
|
153
|
+
className: "brokr-notif-mark-all",
|
|
154
|
+
onClick: markAllRead
|
|
155
|
+
},
|
|
156
|
+
"Mark all read"
|
|
157
|
+
)), /* @__PURE__ */ React3.createElement("div", { className: "brokr-notif-dropdown-list" }, isLoading ? /* @__PURE__ */ React3.createElement("div", { className: "brokr-notif-empty" }, /* @__PURE__ */ React3.createElement("span", { className: "brokr-notif-empty-text" }, "Loading\u2026")) : sorted.length === 0 ? /* @__PURE__ */ React3.createElement("div", { className: "brokr-notif-empty" }, /* @__PURE__ */ React3.createElement("span", { className: "brokr-notif-empty-text" }, "No notifications yet")) : sorted.map((notif) => {
|
|
158
|
+
const notifData = notif.data ?? {};
|
|
159
|
+
const notifType = notifData.type ?? "default";
|
|
160
|
+
const resolved = resolveNotificationType(registry, notifType, notifData);
|
|
161
|
+
return /* @__PURE__ */ React3.createElement(
|
|
162
|
+
"button",
|
|
163
|
+
{
|
|
164
|
+
key: notif.id,
|
|
165
|
+
type: "button",
|
|
166
|
+
className: `brokr-notif-item${notif.read ? "" : " brokr-notif-item--unread"}`,
|
|
167
|
+
onClick: () => handleItemClick(notif),
|
|
168
|
+
role: "menuitem"
|
|
169
|
+
},
|
|
170
|
+
resolved.image ? /* @__PURE__ */ React3.createElement(
|
|
171
|
+
"img",
|
|
172
|
+
{
|
|
173
|
+
src: resolved.image.url,
|
|
174
|
+
alt: resolved.image.alt,
|
|
175
|
+
className: "brokr-notif-item-logo"
|
|
176
|
+
}
|
|
177
|
+
) : /* @__PURE__ */ React3.createElement("span", { className: `brokr-notif-item-dot brokr-notif-item-dot--${notif.variant}` }),
|
|
178
|
+
/* @__PURE__ */ React3.createElement("div", { className: "brokr-notif-item-body" }, /* @__PURE__ */ React3.createElement("span", { className: "brokr-notif-item-title" }, notif.title), /* @__PURE__ */ React3.createElement("span", { className: "brokr-notif-item-message" }, notif.message)),
|
|
179
|
+
/* @__PURE__ */ React3.createElement("span", { className: "brokr-notif-item-time" }, timeAgo(notif.createdAt))
|
|
180
|
+
);
|
|
181
|
+
}))));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// src/react/notifications/NotificationList.tsx
|
|
185
|
+
import React4, { useCallback as useCallback4, useMemo as useMemo4 } from "react";
|
|
186
|
+
function formatTimestamp(iso) {
|
|
187
|
+
const date = new Date(iso);
|
|
188
|
+
return new Intl.DateTimeFormat("en-US", {
|
|
189
|
+
month: "short",
|
|
190
|
+
day: "numeric",
|
|
191
|
+
hour: "numeric",
|
|
192
|
+
minute: "2-digit"
|
|
193
|
+
}).format(date);
|
|
194
|
+
}
|
|
195
|
+
function NotificationListSkeleton() {
|
|
196
|
+
return /* @__PURE__ */ React4.createElement("div", { className: "brokr-notif-list-items" }, [1, 2, 3].map((i) => /* @__PURE__ */ React4.createElement("div", { key: i, className: "brokr-notif-list-row brokr-notif-list-row--skeleton" }, /* @__PURE__ */ React4.createElement("span", { className: "brokr-notif-item-dot brokr-notif-item-dot--skeleton" }), /* @__PURE__ */ React4.createElement("div", { className: "brokr-notif-item-body" }, /* @__PURE__ */ React4.createElement("span", { className: "brokr-notif-item-title brokr-skeleton-line", style: { width: "60%" } }), /* @__PURE__ */ React4.createElement("span", { className: "brokr-notif-item-message brokr-skeleton-line", style: { width: "80%" } })), /* @__PURE__ */ React4.createElement("span", { className: "brokr-notif-item-time brokr-skeleton-line", style: { width: 48 } }))));
|
|
197
|
+
}
|
|
198
|
+
function NotificationList() {
|
|
199
|
+
const { notifications, unreadCount, markRead, markAllRead, isLoading, registry } = useNotifications();
|
|
200
|
+
const sorted = useMemo4(
|
|
201
|
+
() => [...notifications].sort(
|
|
202
|
+
(a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
|
|
203
|
+
),
|
|
204
|
+
[notifications]
|
|
205
|
+
);
|
|
206
|
+
const handleClick = useCallback4((notif) => {
|
|
207
|
+
if (!notif.read) markRead(notif.id);
|
|
208
|
+
const notifData = notif.data ?? {};
|
|
209
|
+
const notifType = notif.type ?? notifData.type ?? "default";
|
|
210
|
+
const resolved = resolveNotificationType(registry, notifType, notifData);
|
|
211
|
+
const href = resolved.href ?? notif.href ?? notifData.href ?? null;
|
|
212
|
+
if (href) {
|
|
213
|
+
window.location.assign(href);
|
|
214
|
+
}
|
|
215
|
+
}, [markRead, registry]);
|
|
216
|
+
return /* @__PURE__ */ React4.createElement("div", { className: "brokr-notif-list" }, /* @__PURE__ */ React4.createElement("div", { className: "brokr-notif-list-header" }, /* @__PURE__ */ React4.createElement("span", { className: "brokr-notif-list-title" }, "Notifications"), unreadCount > 0 && /* @__PURE__ */ React4.createElement(
|
|
217
|
+
"button",
|
|
218
|
+
{
|
|
219
|
+
type: "button",
|
|
220
|
+
className: "brokr-notif-mark-all",
|
|
221
|
+
onClick: markAllRead
|
|
222
|
+
},
|
|
223
|
+
"Mark all read"
|
|
224
|
+
)), isLoading ? /* @__PURE__ */ React4.createElement(NotificationListSkeleton, null) : sorted.length === 0 ? /* @__PURE__ */ React4.createElement("div", { className: "brokr-notif-empty" }, /* @__PURE__ */ React4.createElement("svg", { "aria-hidden": "true", width: "40", height: "40", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1", strokeLinecap: "round", strokeLinejoin: "round", style: { opacity: 0.3 } }, /* @__PURE__ */ React4.createElement("path", { d: "M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9" }), /* @__PURE__ */ React4.createElement("path", { d: "M10.3 21a1.94 1.94 0 0 0 3.4 0" })), /* @__PURE__ */ React4.createElement("span", { className: "brokr-notif-empty-text" }, "No notifications yet")) : /* @__PURE__ */ React4.createElement("div", { className: "brokr-notif-list-items" }, sorted.map((notif) => {
|
|
225
|
+
const notifData = notif.data ?? {};
|
|
226
|
+
const notifType = notif.type ?? notifData.type ?? "default";
|
|
227
|
+
const resolved = resolveNotificationType(registry, notifType, notifData);
|
|
228
|
+
return /* @__PURE__ */ React4.createElement(
|
|
229
|
+
"button",
|
|
230
|
+
{
|
|
231
|
+
key: notif.id,
|
|
232
|
+
type: "button",
|
|
233
|
+
className: `brokr-notif-list-row${notif.read ? "" : " brokr-notif-list-row--unread"}`,
|
|
234
|
+
onClick: () => handleClick(notif)
|
|
235
|
+
},
|
|
236
|
+
resolved.image ? /* @__PURE__ */ React4.createElement(
|
|
237
|
+
"img",
|
|
238
|
+
{
|
|
239
|
+
src: resolved.image.url,
|
|
240
|
+
alt: resolved.image.alt,
|
|
241
|
+
className: "brokr-notif-item-logo"
|
|
242
|
+
}
|
|
243
|
+
) : /* @__PURE__ */ React4.createElement("span", { className: `brokr-notif-item-dot brokr-notif-item-dot--${notif.variant}` }),
|
|
244
|
+
/* @__PURE__ */ React4.createElement("div", { className: "brokr-notif-item-body" }, /* @__PURE__ */ React4.createElement("span", { className: "brokr-notif-item-title" }, notif.title), /* @__PURE__ */ React4.createElement("span", { className: "brokr-notif-item-message" }, notif.message)),
|
|
245
|
+
/* @__PURE__ */ React4.createElement("span", { className: "brokr-notif-item-time" }, formatTimestamp(notif.createdAt))
|
|
246
|
+
);
|
|
247
|
+
})));
|
|
248
|
+
}
|
|
249
|
+
export {
|
|
250
|
+
NotificationBell,
|
|
251
|
+
NotificationList,
|
|
252
|
+
defineNotifications,
|
|
253
|
+
useNotifications
|
|
254
|
+
};
|