@novu/react 2.6.6 → 3.0.0-canary.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/cjs/components/Bell.cjs +63 -0
- package/dist/cjs/components/Bell.cjs.map +1 -0
- package/dist/cjs/components/Bell.d.cts +12 -0
- package/dist/cjs/components/Inbox.cjs +198 -0
- package/dist/cjs/components/Inbox.cjs.map +1 -0
- package/dist/cjs/components/Inbox.d.cts +9 -0
- package/dist/cjs/components/InboxContent.cjs +94 -0
- package/dist/cjs/components/InboxContent.cjs.map +1 -0
- package/dist/cjs/components/InboxContent.d.cts +16 -0
- package/dist/cjs/components/Mounter.cjs +51 -0
- package/dist/cjs/components/Mounter.cjs.map +1 -0
- package/dist/cjs/components/Mounter.d.cts +11 -0
- package/dist/cjs/components/Notifications.cjs +88 -0
- package/dist/cjs/components/Notifications.cjs.map +1 -0
- package/dist/cjs/components/Notifications.d.cts +14 -0
- package/dist/cjs/components/NovuUI.cjs +60 -0
- package/dist/cjs/components/NovuUI.cjs.map +1 -0
- package/dist/cjs/components/NovuUI.d.cts +12 -0
- package/dist/cjs/components/Preferences.cjs +54 -0
- package/dist/cjs/components/Preferences.cjs.map +1 -0
- package/dist/cjs/components/Preferences.d.cts +5 -0
- package/dist/cjs/components/Renderer.cjs +70 -0
- package/dist/cjs/components/Renderer.cjs.map +1 -0
- package/dist/cjs/components/Renderer.d.cts +8 -0
- package/dist/cjs/components/index.cjs +35 -0
- package/dist/cjs/components/index.cjs.map +1 -0
- package/dist/cjs/components/index.d.cts +11 -0
- package/dist/cjs/context/NovuUIContext.cjs +40 -0
- package/dist/cjs/context/NovuUIContext.cjs.map +1 -0
- package/dist/cjs/context/NovuUIContext.d.cts +14 -0
- package/dist/cjs/context/RendererContext.cjs +40 -0
- package/dist/cjs/context/RendererContext.cjs.map +1 -0
- package/dist/cjs/context/RendererContext.d.cts +15 -0
- package/dist/cjs/hooks/NovuProvider.cjs +101 -0
- package/dist/cjs/hooks/NovuProvider.cjs.map +1 -0
- package/dist/cjs/hooks/NovuProvider.d.cts +20 -0
- package/dist/cjs/hooks/index.cjs +40 -0
- package/dist/cjs/hooks/index.cjs.map +1 -0
- package/dist/cjs/hooks/index.d.cts +7 -0
- package/dist/cjs/hooks/internal/useBrowserTabsChannel.cjs +52 -0
- package/dist/cjs/hooks/internal/useBrowserTabsChannel.cjs.map +1 -0
- package/dist/cjs/hooks/internal/useBrowserTabsChannel.d.cts +8 -0
- package/dist/cjs/hooks/internal/useDataRef.cjs +36 -0
- package/dist/cjs/hooks/internal/useDataRef.cjs.map +1 -0
- package/dist/cjs/hooks/internal/useDataRef.d.cts +5 -0
- package/dist/cjs/hooks/internal/useWebsocketEvent.cjs +57 -0
- package/dist/cjs/hooks/internal/useWebsocketEvent.cjs.map +1 -0
- package/dist/cjs/hooks/internal/useWebsocketEvent.d.cts +8 -0
- package/dist/cjs/hooks/useCounts.cjs +104 -0
- package/dist/cjs/hooks/useCounts.cjs.map +1 -0
- package/dist/cjs/hooks/useCounts.d.cts +21 -0
- package/dist/cjs/hooks/useNotifications.cjs +121 -0
- package/dist/cjs/hooks/useNotifications.cjs.map +1 -0
- package/dist/cjs/hooks/useNotifications.d.cts +34 -0
- package/dist/cjs/hooks/usePreferences.cjs +80 -0
- package/dist/cjs/hooks/usePreferences.cjs.map +1 -0
- package/dist/cjs/hooks/usePreferences.d.cts +19 -0
- package/dist/cjs/index.cjs +27 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +14 -0
- package/dist/cjs/server/index.cjs +92 -0
- package/dist/cjs/server/index.cjs.map +1 -0
- package/dist/cjs/server/index.d.cts +29 -0
- package/dist/cjs/themes/index.cjs +25 -0
- package/dist/cjs/themes/index.cjs.map +1 -0
- package/dist/cjs/utils/createContextAndHook.cjs +63 -0
- package/dist/cjs/utils/createContextAndHook.cjs.map +1 -0
- package/dist/cjs/utils/createContextAndHook.d.cts +19 -0
- package/dist/cjs/utils/requestLock.cjs +52 -0
- package/dist/cjs/utils/requestLock.cjs.map +1 -0
- package/dist/cjs/utils/requestLock.d.cts +3 -0
- package/dist/cjs/utils/types.cjs +19 -0
- package/dist/cjs/utils/types.cjs.map +1 -0
- package/dist/cjs/utils/types.d.cts +54 -0
- package/dist/client/{index.d.mts → components/index.d.mts} +23 -6
- package/dist/client/{index.d.ts → components/index.d.ts} +23 -6
- package/dist/client/{index.js → components/index.js} +92 -8
- package/dist/client/components/index.js.map +1 -0
- package/dist/client/{index.mjs → components/index.mjs} +77 -8
- package/dist/client/components/index.mjs.map +1 -0
- package/dist/{hooks → client/hooks}/index.js +8 -0
- package/dist/client/hooks/index.js.map +1 -0
- package/dist/client/hooks/index.mjs.map +1 -0
- package/dist/client/themes/index.d.ts +1 -0
- package/dist/{themes → client/themes}/index.js +4 -0
- package/dist/client/themes/index.js.map +1 -0
- package/dist/client/themes/index.mjs.map +1 -0
- package/dist/esm/components/Bell.d.ts +12 -0
- package/dist/esm/components/Bell.js +28 -0
- package/dist/esm/components/Bell.js.map +1 -0
- package/dist/esm/components/Inbox.d.ts +9 -0
- package/dist/esm/components/Inbox.js +163 -0
- package/dist/esm/components/Inbox.js.map +1 -0
- package/dist/esm/components/InboxContent.d.ts +16 -0
- package/dist/esm/components/InboxContent.js +59 -0
- package/dist/esm/components/InboxContent.js.map +1 -0
- package/dist/esm/components/Mounter.d.ts +11 -0
- package/dist/esm/components/Mounter.js +26 -0
- package/dist/esm/components/Mounter.js.map +1 -0
- package/dist/esm/components/Notifications.d.ts +14 -0
- package/dist/esm/components/Notifications.js +53 -0
- package/dist/esm/components/Notifications.js.map +1 -0
- package/dist/esm/components/NovuUI.d.ts +12 -0
- package/dist/esm/components/NovuUI.js +35 -0
- package/dist/esm/components/NovuUI.js.map +1 -0
- package/dist/esm/components/Preferences.d.ts +5 -0
- package/dist/esm/components/Preferences.js +19 -0
- package/dist/esm/components/Preferences.js.map +1 -0
- package/dist/esm/components/Renderer.d.ts +8 -0
- package/dist/esm/components/Renderer.js +44 -0
- package/dist/esm/components/Renderer.js.map +1 -0
- package/dist/esm/components/index.d.ts +11 -0
- package/dist/esm/components/index.js +8 -0
- package/dist/esm/components/index.js.map +1 -0
- package/dist/esm/context/NovuUIContext.d.ts +14 -0
- package/dist/esm/context/NovuUIContext.js +13 -0
- package/dist/esm/context/NovuUIContext.js.map +1 -0
- package/dist/esm/context/RendererContext.d.ts +15 -0
- package/dist/esm/context/RendererContext.js +13 -0
- package/dist/esm/context/RendererContext.js.map +1 -0
- package/dist/esm/hooks/NovuProvider.d.ts +20 -0
- package/dist/esm/hooks/NovuProvider.js +73 -0
- package/dist/esm/hooks/NovuProvider.js.map +1 -0
- package/dist/esm/hooks/index.d.ts +7 -0
- package/dist/esm/hooks/index.js +10 -0
- package/dist/esm/hooks/index.js.map +1 -0
- package/dist/esm/hooks/internal/useBrowserTabsChannel.d.ts +8 -0
- package/dist/esm/hooks/internal/useBrowserTabsChannel.js +27 -0
- package/dist/esm/hooks/internal/useBrowserTabsChannel.js.map +1 -0
- package/dist/esm/hooks/internal/useDataRef.d.ts +5 -0
- package/dist/esm/hooks/internal/useDataRef.js +11 -0
- package/dist/esm/hooks/internal/useDataRef.js.map +1 -0
- package/dist/esm/hooks/internal/useWebsocketEvent.d.ts +8 -0
- package/dist/esm/hooks/internal/useWebsocketEvent.js +32 -0
- package/dist/esm/hooks/internal/useWebsocketEvent.js.map +1 -0
- package/dist/esm/hooks/useCounts.d.ts +21 -0
- package/dist/esm/hooks/useCounts.js +76 -0
- package/dist/esm/hooks/useCounts.js.map +1 -0
- package/dist/esm/hooks/useNotifications.d.ts +34 -0
- package/dist/esm/hooks/useNotifications.js +96 -0
- package/dist/esm/hooks/useNotifications.js.map +1 -0
- package/dist/esm/hooks/usePreferences.d.ts +19 -0
- package/dist/esm/hooks/usePreferences.js +55 -0
- package/dist/esm/hooks/usePreferences.js.map +1 -0
- package/dist/esm/index.d.ts +14 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/server/index.d.ts +29 -0
- package/dist/esm/server/index.js +56 -0
- package/dist/esm/server/index.js.map +1 -0
- package/dist/esm/themes/index.d.ts +1 -0
- package/dist/esm/themes/index.js +3 -0
- package/dist/esm/themes/index.js.map +1 -0
- package/dist/esm/utils/createContextAndHook.d.ts +19 -0
- package/dist/esm/utils/createContextAndHook.js +27 -0
- package/dist/esm/utils/createContextAndHook.js.map +1 -0
- package/dist/esm/utils/requestLock.d.ts +3 -0
- package/dist/esm/utils/requestLock.js +27 -0
- package/dist/esm/utils/requestLock.js.map +1 -0
- package/dist/esm/utils/types.d.ts +54 -0
- package/dist/esm/utils/types.js +1 -0
- package/dist/esm/utils/types.js.map +1 -0
- package/dist/server/{server.d.mts → index.d.mts} +26 -5
- package/dist/server/{server.d.ts → index.d.ts} +26 -5
- package/dist/server/{server.js → index.js} +17 -20
- package/dist/server/index.js.map +1 -0
- package/dist/server/{server.mjs → index.mjs} +16 -19
- package/dist/server/index.mjs.map +1 -0
- package/hooks/package.json +3 -3
- package/package.json +61 -39
- package/server/package.json +5 -0
- package/themes/package.json +3 -3
- package/dist/client/index.js.map +0 -1
- package/dist/client/index.mjs.map +0 -1
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/index.mjs.map +0 -1
- package/dist/server/server.js.map +0 -1
- package/dist/server/server.mjs.map +0 -1
- package/dist/themes/index.js.map +0 -1
- package/dist/themes/index.mjs.map +0 -1
- /package/dist/{themes/index.d.mts → cjs/themes/index.d.cts} +0 -0
- /package/dist/{hooks → client/hooks}/index.d.mts +0 -0
- /package/dist/{hooks → client/hooks}/index.d.ts +0 -0
- /package/dist/{hooks → client/hooks}/index.mjs +0 -0
- /package/dist/{themes/index.d.ts → client/themes/index.d.mts} +0 -0
- /package/dist/{themes → client/themes}/index.mjs +0 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// src/hooks/useNotifications.ts
|
|
2
|
+
import { useState, useEffect, useRef } from "react";
|
|
3
|
+
import { isSameFilter } from "@novu/js";
|
|
4
|
+
import { useNovu } from "./NovuProvider.js";
|
|
5
|
+
var useNotifications = (props) => {
|
|
6
|
+
const { tags, read, archived = false, limit, onSuccess, onError } = props || {};
|
|
7
|
+
const filterRef = useRef(void 0);
|
|
8
|
+
const { notifications, on } = useNovu();
|
|
9
|
+
const [data, setData] = useState();
|
|
10
|
+
const [error, setError] = useState();
|
|
11
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
12
|
+
const [isFetching, setIsFetching] = useState(false);
|
|
13
|
+
const [hasMore, setHasMore] = useState(false);
|
|
14
|
+
const length = data?.length;
|
|
15
|
+
const after = length ? data[length - 1].id : void 0;
|
|
16
|
+
const sync = (event) => {
|
|
17
|
+
if (!event.data || filterRef.current && !isSameFilter(filterRef.current, event.data.filter)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
setData(event.data.notifications);
|
|
21
|
+
setHasMore(event.data.hasMore);
|
|
22
|
+
};
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
const cleanup = on("notifications.list.updated", sync);
|
|
25
|
+
return () => {
|
|
26
|
+
cleanup();
|
|
27
|
+
};
|
|
28
|
+
}, []);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const newFilter = { tags, read, archived };
|
|
31
|
+
if (filterRef.current && isSameFilter(filterRef.current, newFilter)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
notifications.clearCache({ filter: filterRef.current });
|
|
35
|
+
filterRef.current = newFilter;
|
|
36
|
+
fetchNotifications({ refetch: true });
|
|
37
|
+
}, [tags, read, archived]);
|
|
38
|
+
const fetchNotifications = async (options) => {
|
|
39
|
+
if (options?.refetch) {
|
|
40
|
+
setError(void 0);
|
|
41
|
+
setIsLoading(true);
|
|
42
|
+
setIsFetching(false);
|
|
43
|
+
}
|
|
44
|
+
setIsFetching(true);
|
|
45
|
+
const response = await notifications.list({
|
|
46
|
+
tags,
|
|
47
|
+
read,
|
|
48
|
+
archived,
|
|
49
|
+
limit,
|
|
50
|
+
after: options?.refetch ? void 0 : after
|
|
51
|
+
});
|
|
52
|
+
if (response.error) {
|
|
53
|
+
setError(response.error);
|
|
54
|
+
onError?.(response.error);
|
|
55
|
+
} else {
|
|
56
|
+
onSuccess?.(response.data.notifications);
|
|
57
|
+
setData(response.data.notifications);
|
|
58
|
+
setHasMore(response.data.hasMore);
|
|
59
|
+
}
|
|
60
|
+
setIsLoading(false);
|
|
61
|
+
setIsFetching(false);
|
|
62
|
+
};
|
|
63
|
+
const refetch = () => {
|
|
64
|
+
notifications.clearCache({ filter: { tags, read, archived } });
|
|
65
|
+
return fetchNotifications({ refetch: true });
|
|
66
|
+
};
|
|
67
|
+
const fetchMore = async () => {
|
|
68
|
+
if (!hasMore || isFetching) return;
|
|
69
|
+
return fetchNotifications();
|
|
70
|
+
};
|
|
71
|
+
const readAll = async () => {
|
|
72
|
+
return await notifications.readAll({ tags });
|
|
73
|
+
};
|
|
74
|
+
const archiveAll = async () => {
|
|
75
|
+
return await notifications.archiveAll({ tags });
|
|
76
|
+
};
|
|
77
|
+
const archiveAllRead = async () => {
|
|
78
|
+
return await notifications.archiveAllRead({ tags });
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
readAll,
|
|
82
|
+
archiveAll,
|
|
83
|
+
archiveAllRead,
|
|
84
|
+
notifications: data,
|
|
85
|
+
error,
|
|
86
|
+
isLoading,
|
|
87
|
+
isFetching,
|
|
88
|
+
refetch,
|
|
89
|
+
fetchMore,
|
|
90
|
+
hasMore
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
export {
|
|
94
|
+
useNotifications
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=useNotifications.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/useNotifications.ts"],"sourcesContent":["import { useState, useEffect, useRef } from 'react';\nimport { ListNotificationsResponse, Notification, NovuError, isSameFilter, NotificationFilter } from '@novu/js';\nimport { useNovu } from './NovuProvider';\n\nexport type UseNotificationsProps = {\n tags?: string[];\n read?: boolean;\n archived?: boolean;\n limit?: number;\n onSuccess?: (data: Notification[]) => void;\n onError?: (error: NovuError) => void;\n};\n\nexport type UseNotificationsResult = {\n notifications?: Notification[];\n error?: NovuError;\n isLoading: boolean;\n isFetching: boolean;\n hasMore: boolean;\n readAll: () => Promise<{\n data?: void | undefined;\n error?: NovuError | undefined;\n }>;\n archiveAll: () => Promise<{\n data?: void | undefined;\n error?: NovuError | undefined;\n }>;\n archiveAllRead: () => Promise<{\n data?: void | undefined;\n error?: NovuError | undefined;\n }>;\n refetch: () => Promise<void>;\n fetchMore: () => Promise<void>;\n};\n\nexport const useNotifications = (props?: UseNotificationsProps): UseNotificationsResult => {\n const { tags, read, archived = false, limit, onSuccess, onError } = props || {};\n const filterRef = useRef<NotificationFilter | undefined>(undefined);\n const { notifications, on } = useNovu();\n const [data, setData] = useState<Array<Notification>>();\n const [error, setError] = useState<NovuError>();\n const [isLoading, setIsLoading] = useState(true);\n const [isFetching, setIsFetching] = useState(false);\n const [hasMore, setHasMore] = useState(false);\n const length = data?.length;\n const after = length ? data[length - 1].id : undefined;\n\n const sync = (event: { data?: ListNotificationsResponse }) => {\n if (!event.data || (filterRef.current && !isSameFilter(filterRef.current, event.data.filter))) {\n return;\n }\n setData(event.data.notifications);\n setHasMore(event.data.hasMore);\n };\n\n useEffect(() => {\n const cleanup = on('notifications.list.updated', sync);\n\n return () => {\n cleanup();\n };\n }, []);\n\n useEffect(() => {\n const newFilter = { tags, read, archived };\n if (filterRef.current && isSameFilter(filterRef.current, newFilter)) {\n return;\n }\n\n notifications.clearCache({ filter: filterRef.current });\n filterRef.current = newFilter;\n\n fetchNotifications({ refetch: true });\n }, [tags, read, archived]);\n\n const fetchNotifications = async (options?: { refetch: boolean }) => {\n if (options?.refetch) {\n setError(undefined);\n setIsLoading(true);\n setIsFetching(false);\n }\n setIsFetching(true);\n const response = await notifications.list({\n tags,\n read,\n archived,\n limit,\n after: options?.refetch ? undefined : after,\n });\n if (response.error) {\n setError(response.error);\n onError?.(response.error);\n } else {\n onSuccess?.(response.data!.notifications);\n setData(response.data!.notifications);\n setHasMore(response.data!.hasMore);\n }\n setIsLoading(false);\n setIsFetching(false);\n };\n\n const refetch = () => {\n notifications.clearCache({ filter: { tags, read, archived } });\n\n return fetchNotifications({ refetch: true });\n };\n\n const fetchMore = async () => {\n if (!hasMore || isFetching) return;\n\n return fetchNotifications();\n };\n\n const readAll = async () => {\n return await notifications.readAll({ tags });\n };\n\n const archiveAll = async () => {\n return await notifications.archiveAll({ tags });\n };\n\n const archiveAllRead = async () => {\n return await notifications.archiveAllRead({ tags });\n };\n\n return {\n readAll,\n archiveAll,\n archiveAllRead,\n notifications: data,\n error,\n isLoading,\n isFetching,\n refetch,\n fetchMore,\n hasMore,\n };\n};\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Preference, NovuError } from '@novu/js';
|
|
2
|
+
|
|
3
|
+
type UsePreferencesProps = {
|
|
4
|
+
filter?: {
|
|
5
|
+
tags?: string[];
|
|
6
|
+
};
|
|
7
|
+
onSuccess?: (data: Preference[]) => void;
|
|
8
|
+
onError?: (error: NovuError) => void;
|
|
9
|
+
};
|
|
10
|
+
type UsePreferencesResult = {
|
|
11
|
+
preferences?: Preference[];
|
|
12
|
+
error?: NovuError;
|
|
13
|
+
isLoading: boolean;
|
|
14
|
+
isFetching: boolean;
|
|
15
|
+
refetch: () => Promise<void>;
|
|
16
|
+
};
|
|
17
|
+
declare const usePreferences: (props?: UsePreferencesProps) => UsePreferencesResult;
|
|
18
|
+
|
|
19
|
+
export { type UsePreferencesProps, type UsePreferencesResult, usePreferences };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// src/hooks/usePreferences.ts
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { useNovu } from "./NovuProvider.js";
|
|
4
|
+
var usePreferences = (props) => {
|
|
5
|
+
const { onSuccess, onError } = props || {};
|
|
6
|
+
const [data, setData] = useState();
|
|
7
|
+
const { preferences, on } = useNovu();
|
|
8
|
+
const [error, setError] = useState();
|
|
9
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
10
|
+
const [isFetching, setIsFetching] = useState(false);
|
|
11
|
+
const sync = (event) => {
|
|
12
|
+
if (!event.data) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
setData(event.data);
|
|
16
|
+
};
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
fetchPreferences();
|
|
19
|
+
const listUpdatedCleanup = on("preferences.list.updated", sync);
|
|
20
|
+
const listPendingCleanup = on("preferences.list.pending", sync);
|
|
21
|
+
const listResolvedCleanup = on("preferences.list.resolved", sync);
|
|
22
|
+
return () => {
|
|
23
|
+
listUpdatedCleanup();
|
|
24
|
+
listPendingCleanup();
|
|
25
|
+
listResolvedCleanup();
|
|
26
|
+
};
|
|
27
|
+
}, []);
|
|
28
|
+
const fetchPreferences = async () => {
|
|
29
|
+
setIsFetching(true);
|
|
30
|
+
const response = await preferences.list(props?.filter);
|
|
31
|
+
if (response.error) {
|
|
32
|
+
setError(response.error);
|
|
33
|
+
onError?.(response.error);
|
|
34
|
+
} else {
|
|
35
|
+
onSuccess?.(response.data);
|
|
36
|
+
}
|
|
37
|
+
setIsLoading(false);
|
|
38
|
+
setIsFetching(false);
|
|
39
|
+
};
|
|
40
|
+
const refetch = () => {
|
|
41
|
+
preferences.cache.clearAll();
|
|
42
|
+
return fetchPreferences();
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
preferences: data,
|
|
46
|
+
error,
|
|
47
|
+
isLoading,
|
|
48
|
+
isFetching,
|
|
49
|
+
refetch
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export {
|
|
53
|
+
usePreferences
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=usePreferences.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/usePreferences.ts"],"sourcesContent":["import { NovuError, Preference } from '@novu/js';\nimport { useEffect, useState } from 'react';\nimport { useNovu } from './NovuProvider';\n\nexport type UsePreferencesProps = {\n filter?: { tags?: string[] };\n onSuccess?: (data: Preference[]) => void;\n onError?: (error: NovuError) => void;\n};\n\nexport type UsePreferencesResult = {\n preferences?: Preference[];\n error?: NovuError;\n isLoading: boolean; // initial loading\n isFetching: boolean; // the request is in flight\n refetch: () => Promise<void>;\n};\n\nexport const usePreferences = (props?: UsePreferencesProps): UsePreferencesResult => {\n const { onSuccess, onError } = props || {};\n const [data, setData] = useState<Preference[]>();\n const { preferences, on } = useNovu();\n const [error, setError] = useState<NovuError>();\n const [isLoading, setIsLoading] = useState(true);\n const [isFetching, setIsFetching] = useState(false);\n\n const sync = (event: { data?: Preference[] }) => {\n if (!event.data) {\n return;\n }\n setData(event.data);\n };\n\n useEffect(() => {\n fetchPreferences();\n\n const listUpdatedCleanup = on('preferences.list.updated', sync);\n const listPendingCleanup = on('preferences.list.pending', sync);\n const listResolvedCleanup = on('preferences.list.resolved', sync);\n\n return () => {\n listUpdatedCleanup();\n listPendingCleanup();\n listResolvedCleanup();\n };\n }, []);\n\n const fetchPreferences = async () => {\n setIsFetching(true);\n const response = await preferences.list(props?.filter);\n if (response.error) {\n setError(response.error);\n onError?.(response.error);\n } else {\n onSuccess?.(response.data!);\n }\n setIsLoading(false);\n setIsFetching(false);\n };\n\n const refetch = () => {\n preferences.cache.clearAll();\n\n return fetchPreferences();\n };\n\n return {\n preferences: data,\n error,\n isLoading,\n isFetching,\n refetch,\n };\n};\n"],"mappings":";AACA,SAAS,WAAW,gBAAgB;AACpC,SAAS,eAAe;AAgBjB,IAAM,iBAAiB,CAAC,UAAsD;AACnF,QAAM,EAAE,WAAW,QAAQ,IAAI,SAAS,CAAC;AACzC,QAAM,CAAC,MAAM,OAAO,IAAI,SAAuB;AAC/C,QAAM,EAAE,aAAa,GAAG,IAAI,QAAQ;AACpC,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAoB;AAC9C,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,IAAI;AAC/C,QAAM,CAAC,YAAY,aAAa,IAAI,SAAS,KAAK;AAElD,QAAM,OAAO,CAAC,UAAmC;AAC/C,QAAI,CAAC,MAAM,MAAM;AACf;AAAA,IACF;AACA,YAAQ,MAAM,IAAI;AAAA,EACpB;AAEA,YAAU,MAAM;AACd,qBAAiB;AAEjB,UAAM,qBAAqB,GAAG,4BAA4B,IAAI;AAC9D,UAAM,qBAAqB,GAAG,4BAA4B,IAAI;AAC9D,UAAM,sBAAsB,GAAG,6BAA6B,IAAI;AAEhE,WAAO,MAAM;AACX,yBAAmB;AACnB,yBAAmB;AACnB,0BAAoB;AAAA,IACtB;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,QAAM,mBAAmB,YAAY;AACnC,kBAAc,IAAI;AAClB,UAAM,WAAW,MAAM,YAAY,KAAK,OAAO,MAAM;AACrD,QAAI,SAAS,OAAO;AAClB,eAAS,SAAS,KAAK;AACvB,gBAAU,SAAS,KAAK;AAAA,IAC1B,OAAO;AACL,kBAAY,SAAS,IAAK;AAAA,IAC5B;AACA,iBAAa,KAAK;AAClB,kBAAc,KAAK;AAAA,EACrB;AAEA,QAAM,UAAU,MAAM;AACpB,gBAAY,MAAM,SAAS;AAE3B,WAAO,iBAAiB;AAAA,EAC1B;AAEA,SAAO;AAAA,IACL,aAAa;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { Bell, BellProps } from './components/Bell.js';
|
|
2
|
+
export { Inbox, InboxProps } from './components/Inbox.js';
|
|
3
|
+
export { Preferences } from './components/Preferences.js';
|
|
4
|
+
export { NotificationProps, Notifications } from './components/Notifications.js';
|
|
5
|
+
export { InboxContent, InboxContentProps } from './components/InboxContent.js';
|
|
6
|
+
export { InternalNovuProvider, NovuProvider, NovuProviderProps, useNovu, useUnsafeNovu } from './hooks/NovuProvider.js';
|
|
7
|
+
export { UseNotificationsProps, UseNotificationsResult, useNotifications } from './hooks/useNotifications.js';
|
|
8
|
+
export { UsePreferencesProps, UsePreferencesResult, usePreferences } from './hooks/usePreferences.js';
|
|
9
|
+
export { UseCountsProps, UseCountsResult, useCounts } from './hooks/useCounts.js';
|
|
10
|
+
export { BaseProps, BellRenderer, BodyRenderer, DefaultInboxProps, DefaultProps, NoRendererProps, NotificationRendererProps, NotificationsRenderer, SubjectBodyRendererProps, SubjectRenderer, WithChildrenProps } from './utils/types.js';
|
|
11
|
+
export { Notification } from '@novu/js/ui';
|
|
12
|
+
import 'react';
|
|
13
|
+
import 'react/jsx-runtime';
|
|
14
|
+
import '@novu/js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './components';\nexport * from './hooks';\nexport type * from './utils/types';\n"],"mappings":";AAAA,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { InboxProps } from '../components/Inbox.js';
|
|
2
|
+
import { UseNotificationsProps, UseNotificationsResult } from '../hooks/useNotifications.js';
|
|
3
|
+
import { UsePreferencesProps, UsePreferencesResult } from '../hooks/usePreferences.js';
|
|
4
|
+
import { UseCountsProps, UseCountsResult } from '../hooks/useCounts.js';
|
|
5
|
+
import { NovuProviderProps } from '../hooks/NovuProvider.js';
|
|
6
|
+
export { BaseProps, BellRenderer, BodyRenderer, DefaultInboxProps, DefaultProps, NoRendererProps, NotificationRendererProps, NotificationsRenderer, SubjectBodyRendererProps, SubjectRenderer, WithChildrenProps } from '../utils/types.js';
|
|
7
|
+
export { Notification } from '@novu/js/ui';
|
|
8
|
+
import 'react/jsx-runtime';
|
|
9
|
+
import 'react';
|
|
10
|
+
import '@novu/js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Exporting all components from the components folder
|
|
14
|
+
* as empty functions to fix build errors in SSR
|
|
15
|
+
* This will be replaced with actual components
|
|
16
|
+
* when we implement the SSR components in @novu/js/ui
|
|
17
|
+
*/
|
|
18
|
+
declare function Inbox(props: InboxProps): void;
|
|
19
|
+
declare function InboxContent(): void;
|
|
20
|
+
declare function Notifications(): void;
|
|
21
|
+
declare function Preferences(): void;
|
|
22
|
+
declare function Bell(): void;
|
|
23
|
+
declare function NovuProvider(props: NovuProviderProps): void;
|
|
24
|
+
declare function useNovu(): null;
|
|
25
|
+
declare function useCounts(_: UseCountsProps): UseCountsResult;
|
|
26
|
+
declare function useNotifications(_: UseNotificationsProps): UseNotificationsResult;
|
|
27
|
+
declare function usePreferences(_: UsePreferencesProps): UsePreferencesResult;
|
|
28
|
+
|
|
29
|
+
export { Bell, Inbox, InboxContent, Notifications, NovuProvider, Preferences, useCounts, useNotifications, useNovu, usePreferences };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/server/index.tsx
|
|
2
|
+
export * from "../utils/types.js";
|
|
3
|
+
function Inbox(props) {
|
|
4
|
+
}
|
|
5
|
+
function InboxContent() {
|
|
6
|
+
}
|
|
7
|
+
function Notifications() {
|
|
8
|
+
}
|
|
9
|
+
function Preferences() {
|
|
10
|
+
}
|
|
11
|
+
function Bell() {
|
|
12
|
+
}
|
|
13
|
+
function NovuProvider(props) {
|
|
14
|
+
}
|
|
15
|
+
function useNovu() {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
function useCounts(_) {
|
|
19
|
+
return {
|
|
20
|
+
isLoading: false,
|
|
21
|
+
isFetching: false,
|
|
22
|
+
refetch: () => Promise.resolve()
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function useNotifications(_) {
|
|
26
|
+
return {
|
|
27
|
+
isLoading: false,
|
|
28
|
+
isFetching: false,
|
|
29
|
+
hasMore: false,
|
|
30
|
+
readAll: () => Promise.resolve({ data: void 0, error: void 0 }),
|
|
31
|
+
archiveAll: () => Promise.resolve({ data: void 0, error: void 0 }),
|
|
32
|
+
archiveAllRead: () => Promise.resolve({ data: void 0, error: void 0 }),
|
|
33
|
+
refetch: () => Promise.resolve(),
|
|
34
|
+
fetchMore: () => Promise.resolve()
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function usePreferences(_) {
|
|
38
|
+
return {
|
|
39
|
+
isLoading: false,
|
|
40
|
+
isFetching: false,
|
|
41
|
+
refetch: () => Promise.resolve()
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export {
|
|
45
|
+
Bell,
|
|
46
|
+
Inbox,
|
|
47
|
+
InboxContent,
|
|
48
|
+
Notifications,
|
|
49
|
+
NovuProvider,
|
|
50
|
+
Preferences,
|
|
51
|
+
useCounts,
|
|
52
|
+
useNotifications,
|
|
53
|
+
useNovu,
|
|
54
|
+
usePreferences
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/server/index.tsx"],"sourcesContent":["import type { InboxProps } from '../components/Inbox';\nimport type {\n UseNotificationsProps,\n UseNotificationsResult,\n UsePreferencesProps,\n UsePreferencesResult,\n} from '../hooks';\nimport type { NovuProviderProps } from '../hooks/NovuProvider';\nimport type { UseCountsProps, UseCountsResult } from '../hooks/useCounts';\n\nexport * from '../utils/types';\n\n/**\n * Exporting all components from the components folder\n * as empty functions to fix build errors in SSR\n * This will be replaced with actual components\n * when we implement the SSR components in @novu/js/ui\n */\nexport function Inbox(props: InboxProps) {}\n\nexport function InboxContent() {}\n\nexport function Notifications() {}\n\nexport function Preferences() {}\n\nexport function Bell() {}\n\nexport function NovuProvider(props: NovuProviderProps) {}\n\nexport function useNovu() {\n return null;\n}\n\nexport function useCounts(_: UseCountsProps): UseCountsResult {\n return {\n isLoading: false,\n isFetching: false,\n refetch: () => Promise.resolve(),\n };\n}\n\nexport function useNotifications(_: UseNotificationsProps): UseNotificationsResult {\n return {\n isLoading: false,\n isFetching: false,\n hasMore: false,\n readAll: () => Promise.resolve({ data: undefined, error: undefined }),\n archiveAll: () => Promise.resolve({ data: undefined, error: undefined }),\n archiveAllRead: () => Promise.resolve({ data: undefined, error: undefined }),\n refetch: () => Promise.resolve(),\n fetchMore: () => Promise.resolve(),\n };\n}\n\nexport function usePreferences(_: UsePreferencesProps): UsePreferencesResult {\n return {\n isLoading: false,\n isFetching: false,\n refetch: () => Promise.resolve(),\n };\n}\n"],"mappings":";AAUA,cAAc;AAQP,SAAS,MAAM,OAAmB;AAAC;AAEnC,SAAS,eAAe;AAAC;AAEzB,SAAS,gBAAgB;AAAC;AAE1B,SAAS,cAAc;AAAC;AAExB,SAAS,OAAO;AAAC;AAEjB,SAAS,aAAa,OAA0B;AAAC;AAEjD,SAAS,UAAU;AACxB,SAAO;AACT;AAEO,SAAS,UAAU,GAAoC;AAC5D,SAAO;AAAA,IACL,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,SAAS,MAAM,QAAQ,QAAQ;AAAA,EACjC;AACF;AAEO,SAAS,iBAAiB,GAAkD;AACjF,SAAO;AAAA,IACL,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,SAAS;AAAA,IACT,SAAS,MAAM,QAAQ,QAAQ,EAAE,MAAM,QAAW,OAAO,OAAU,CAAC;AAAA,IACpE,YAAY,MAAM,QAAQ,QAAQ,EAAE,MAAM,QAAW,OAAO,OAAU,CAAC;AAAA,IACvE,gBAAgB,MAAM,QAAQ,QAAQ,EAAE,MAAM,QAAW,OAAO,OAAU,CAAC;AAAA,IAC3E,SAAS,MAAM,QAAQ,QAAQ;AAAA,IAC/B,WAAW,MAAM,QAAQ,QAAQ;AAAA,EACnC;AACF;AAEO,SAAS,eAAe,GAA8C;AAC3E,SAAO;AAAA,IACL,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,SAAS,MAAM,QAAQ,QAAQ;AAAA,EACjC;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@novu/js/themes';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/themes/index.ts"],"sourcesContent":["export * from '@novu/js/themes';\n"],"mappings":";AAAA,cAAc;","names":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React__default from 'react';
|
|
2
|
+
|
|
3
|
+
declare function assertContextExists(contextVal: unknown, msgOrCtx: string | React__default.Context<any>): asserts contextVal;
|
|
4
|
+
type Options = {
|
|
5
|
+
assertCtxFn?: (v: unknown, msg: string) => void;
|
|
6
|
+
};
|
|
7
|
+
type ContextOf<T> = React__default.Context<{
|
|
8
|
+
value: T;
|
|
9
|
+
} | undefined>;
|
|
10
|
+
type UseCtxFn<T> = () => T;
|
|
11
|
+
/**
|
|
12
|
+
* Creates and returns a Context and two hooks that return the context value.
|
|
13
|
+
* The Context type is derived from the type passed in by the user.
|
|
14
|
+
* The first hook returned guarantees that the context exists so the returned value is always CtxValue
|
|
15
|
+
* The second hook makes no guarantees, so the returned value can be CtxValue | undefined
|
|
16
|
+
*/
|
|
17
|
+
declare const createContextAndHook: <CtxVal>(displayName: string, options?: Options) => [ContextOf<CtxVal>, UseCtxFn<CtxVal>, UseCtxFn<CtxVal | Partial<CtxVal>>];
|
|
18
|
+
|
|
19
|
+
export { assertContextExists, createContextAndHook };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/utils/createContextAndHook.ts
|
|
2
|
+
import React from "react";
|
|
3
|
+
function assertContextExists(contextVal, msgOrCtx) {
|
|
4
|
+
if (!contextVal) {
|
|
5
|
+
throw typeof msgOrCtx === "string" ? new Error(msgOrCtx) : new Error(`${msgOrCtx.displayName} not found`);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
var createContextAndHook = (displayName, options) => {
|
|
9
|
+
const { assertCtxFn = assertContextExists } = options || {};
|
|
10
|
+
const Ctx = React.createContext(void 0);
|
|
11
|
+
Ctx.displayName = displayName;
|
|
12
|
+
const useCtx = () => {
|
|
13
|
+
const ctx = React.useContext(Ctx);
|
|
14
|
+
assertCtxFn(ctx, `Component must be wrapped with ${Ctx.displayName}`);
|
|
15
|
+
return ctx.value;
|
|
16
|
+
};
|
|
17
|
+
const useCtxWithoutGuarantee = () => {
|
|
18
|
+
const ctx = React.useContext(Ctx);
|
|
19
|
+
return ctx ? ctx.value : {};
|
|
20
|
+
};
|
|
21
|
+
return [Ctx, useCtx, useCtxWithoutGuarantee];
|
|
22
|
+
};
|
|
23
|
+
export {
|
|
24
|
+
assertContextExists,
|
|
25
|
+
createContextAndHook
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=createContextAndHook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/createContextAndHook.ts"],"sourcesContent":["import React from 'react';\n\nexport function assertContextExists(contextVal: unknown, msgOrCtx: string | React.Context<any>): asserts contextVal {\n if (!contextVal) {\n throw typeof msgOrCtx === 'string' ? new Error(msgOrCtx) : new Error(`${msgOrCtx.displayName} not found`);\n }\n}\n\ntype Options = { assertCtxFn?: (v: unknown, msg: string) => void };\ntype ContextOf<T> = React.Context<{ value: T } | undefined>;\ntype UseCtxFn<T> = () => T;\n\n/**\n * Creates and returns a Context and two hooks that return the context value.\n * The Context type is derived from the type passed in by the user.\n * The first hook returned guarantees that the context exists so the returned value is always CtxValue\n * The second hook makes no guarantees, so the returned value can be CtxValue | undefined\n */\nexport const createContextAndHook = <CtxVal>(\n displayName: string,\n options?: Options\n): [ContextOf<CtxVal>, UseCtxFn<CtxVal>, UseCtxFn<CtxVal | Partial<CtxVal>>] => {\n const { assertCtxFn = assertContextExists } = options || {};\n const Ctx = React.createContext<{ value: CtxVal } | undefined>(undefined);\n Ctx.displayName = displayName;\n\n const useCtx = () => {\n const ctx = React.useContext(Ctx);\n assertCtxFn(ctx, `Component must be wrapped with ${Ctx.displayName}`);\n\n return (ctx as any).value as CtxVal;\n };\n\n const useCtxWithoutGuarantee = () => {\n const ctx = React.useContext(Ctx);\n\n return ctx ? ctx.value : {};\n };\n\n return [Ctx, useCtx, useCtxWithoutGuarantee];\n};\n"],"mappings":";AAAA,OAAO,WAAW;AAEX,SAAS,oBAAoB,YAAqB,UAA2D;AAClH,MAAI,CAAC,YAAY;AACf,UAAM,OAAO,aAAa,WAAW,IAAI,MAAM,QAAQ,IAAI,IAAI,MAAM,GAAG,SAAS,WAAW,YAAY;AAAA,EAC1G;AACF;AAYO,IAAM,uBAAuB,CAClC,aACA,YAC8E;AAC9E,QAAM,EAAE,cAAc,oBAAoB,IAAI,WAAW,CAAC;AAC1D,QAAM,MAAM,MAAM,cAA6C,MAAS;AACxE,MAAI,cAAc;AAElB,QAAM,SAAS,MAAM;AACnB,UAAM,MAAM,MAAM,WAAW,GAAG;AAChC,gBAAY,KAAK,kCAAkC,IAAI,WAAW,EAAE;AAEpE,WAAQ,IAAY;AAAA,EACtB;AAEA,QAAM,yBAAyB,MAAM;AACnC,UAAM,MAAM,MAAM,WAAW,GAAG;AAEhC,WAAO,MAAM,IAAI,QAAQ,CAAC;AAAA,EAC5B;AAEA,SAAO,CAAC,KAAK,QAAQ,sBAAsB;AAC7C;","names":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/utils/requestLock.ts
|
|
2
|
+
function requestLock(id, cb) {
|
|
3
|
+
if (!("locks" in navigator)) {
|
|
4
|
+
cb(id);
|
|
5
|
+
return () => {
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
let isFulfilled = false;
|
|
9
|
+
let promiseResolve;
|
|
10
|
+
const promise = new Promise((resolve) => {
|
|
11
|
+
promiseResolve = resolve;
|
|
12
|
+
});
|
|
13
|
+
navigator.locks.request(id, () => {
|
|
14
|
+
if (!isFulfilled) {
|
|
15
|
+
cb(id);
|
|
16
|
+
}
|
|
17
|
+
return promise;
|
|
18
|
+
});
|
|
19
|
+
return () => {
|
|
20
|
+
isFulfilled = true;
|
|
21
|
+
promiseResolve();
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
requestLock
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=requestLock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/requestLock.ts"],"sourcesContent":["export function requestLock(id: string, cb: (id: string) => void) {\n // Check if the Lock API is available\n if (!('locks' in navigator)) {\n // If Lock API is not available, immediately invoke the callback and return a no-op function\n cb(id);\n return () => {};\n }\n\n let isFulfilled = false;\n let promiseResolve: () => void;\n\n const promise = new Promise<void>((resolve) => {\n promiseResolve = resolve;\n });\n\n navigator.locks.request(id, () => {\n if (!isFulfilled) {\n cb(id);\n }\n\n return promise;\n });\n\n return () => {\n isFulfilled = true;\n promiseResolve();\n };\n}\n"],"mappings":";AAAO,SAAS,YAAY,IAAY,IAA0B;AAEhE,MAAI,EAAE,WAAW,YAAY;AAE3B,OAAG,EAAE;AACL,WAAO,MAAM;AAAA,IAAC;AAAA,EAChB;AAEA,MAAI,cAAc;AAClB,MAAI;AAEJ,QAAM,UAAU,IAAI,QAAc,CAAC,YAAY;AAC7C,qBAAiB;AAAA,EACnB,CAAC;AAED,YAAU,MAAM,QAAQ,IAAI,MAAM;AAChC,QAAI,CAAC,aAAa;AAChB,SAAG,EAAE;AAAA,IACP;AAEA,WAAO;AAAA,EACT,CAAC;AAED,SAAO,MAAM;AACX,kBAAc;AACd,mBAAe;AAAA,EACjB;AACF;","names":[]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Notification, NotificationClickHandler, NotificationActionClickHandler, InboxProps, Appearance, Localization, Tab, PreferencesFilter, RouterPush } from '@novu/js/ui';
|
|
2
|
+
export { Notification } from '@novu/js/ui';
|
|
3
|
+
|
|
4
|
+
type NotificationsRenderer = (notification: Notification) => React.ReactNode;
|
|
5
|
+
type SubjectRenderer = (notification: Notification) => React.ReactNode;
|
|
6
|
+
type BodyRenderer = (notification: Notification) => React.ReactNode;
|
|
7
|
+
type BellRenderer = (unreadCount: number) => React.ReactNode;
|
|
8
|
+
type DefaultInboxProps = {
|
|
9
|
+
open?: boolean;
|
|
10
|
+
renderNotification?: NotificationsRenderer;
|
|
11
|
+
renderSubject?: SubjectRenderer;
|
|
12
|
+
renderBody?: BodyRenderer;
|
|
13
|
+
renderBell?: BellRenderer;
|
|
14
|
+
onNotificationClick?: NotificationClickHandler;
|
|
15
|
+
onPrimaryActionClick?: NotificationActionClickHandler;
|
|
16
|
+
onSecondaryActionClick?: NotificationActionClickHandler;
|
|
17
|
+
placement?: InboxProps['placement'];
|
|
18
|
+
placementOffset?: InboxProps['placementOffset'];
|
|
19
|
+
};
|
|
20
|
+
type BaseProps = {
|
|
21
|
+
applicationIdentifier: string;
|
|
22
|
+
subscriberId: string;
|
|
23
|
+
subscriberHash?: string;
|
|
24
|
+
backendUrl?: string;
|
|
25
|
+
socketUrl?: string;
|
|
26
|
+
appearance?: Appearance;
|
|
27
|
+
localization?: Localization;
|
|
28
|
+
tabs?: Array<Tab>;
|
|
29
|
+
preferencesFilter?: PreferencesFilter;
|
|
30
|
+
routerPush?: RouterPush;
|
|
31
|
+
};
|
|
32
|
+
type NotificationRendererProps = {
|
|
33
|
+
renderNotification: NotificationsRenderer;
|
|
34
|
+
renderSubject?: never;
|
|
35
|
+
renderBody?: never;
|
|
36
|
+
};
|
|
37
|
+
type SubjectBodyRendererProps = {
|
|
38
|
+
renderNotification?: never;
|
|
39
|
+
renderSubject?: SubjectRenderer;
|
|
40
|
+
renderBody?: BodyRenderer;
|
|
41
|
+
};
|
|
42
|
+
type NoRendererProps = {
|
|
43
|
+
renderNotification?: undefined;
|
|
44
|
+
renderSubject?: undefined;
|
|
45
|
+
renderBody?: undefined;
|
|
46
|
+
};
|
|
47
|
+
type DefaultProps = BaseProps & DefaultInboxProps & {
|
|
48
|
+
children?: never;
|
|
49
|
+
} & (NotificationRendererProps | SubjectBodyRendererProps | NoRendererProps);
|
|
50
|
+
type WithChildrenProps = BaseProps & {
|
|
51
|
+
children: React.ReactNode;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type { BaseProps, BellRenderer, BodyRenderer, DefaultInboxProps, DefaultProps, NoRendererProps, NotificationRendererProps, NotificationsRenderer, SubjectBodyRendererProps, SubjectRenderer, WithChildrenProps };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
import { Notification, NotificationClickHandler, NotificationActionClickHandler, InboxProps, Appearance, Localization, Tab, PreferencesFilter, RouterPush } from '@novu/js/ui';
|
|
1
|
+
import { Notification, NotificationClickHandler, NotificationActionClickHandler, InboxProps as InboxProps$1, Appearance, Localization, Tab, PreferencesFilter, RouterPush } from '@novu/js/ui';
|
|
2
2
|
export { Notification } from '@novu/js/ui';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
import { Novu, NovuOptions, Notification as Notification$1, NovuError, Preference, NotificationFilter } from '@novu/js';
|
|
5
5
|
import { ReactNode } from 'react';
|
|
6
6
|
|
|
7
7
|
type NotificationsRenderer = (notification: Notification) => React.ReactNode;
|
|
8
|
+
type SubjectRenderer = (notification: Notification) => React.ReactNode;
|
|
9
|
+
type BodyRenderer = (notification: Notification) => React.ReactNode;
|
|
8
10
|
type BellRenderer = (unreadCount: number) => React.ReactNode;
|
|
9
11
|
type DefaultInboxProps = {
|
|
10
12
|
open?: boolean;
|
|
11
13
|
renderNotification?: NotificationsRenderer;
|
|
14
|
+
renderSubject?: SubjectRenderer;
|
|
15
|
+
renderBody?: BodyRenderer;
|
|
12
16
|
renderBell?: BellRenderer;
|
|
13
17
|
onNotificationClick?: NotificationClickHandler;
|
|
14
18
|
onPrimaryActionClick?: NotificationActionClickHandler;
|
|
15
19
|
onSecondaryActionClick?: NotificationActionClickHandler;
|
|
16
|
-
placement?: InboxProps['placement'];
|
|
17
|
-
placementOffset?: InboxProps['placementOffset'];
|
|
20
|
+
placement?: InboxProps$1['placement'];
|
|
21
|
+
placementOffset?: InboxProps$1['placementOffset'];
|
|
18
22
|
};
|
|
19
23
|
type BaseProps = {
|
|
20
24
|
applicationIdentifier: string;
|
|
@@ -28,13 +32,30 @@ type BaseProps = {
|
|
|
28
32
|
preferencesFilter?: PreferencesFilter;
|
|
29
33
|
routerPush?: RouterPush;
|
|
30
34
|
};
|
|
35
|
+
type NotificationRendererProps = {
|
|
36
|
+
renderNotification: NotificationsRenderer;
|
|
37
|
+
renderSubject?: never;
|
|
38
|
+
renderBody?: never;
|
|
39
|
+
};
|
|
40
|
+
type SubjectBodyRendererProps = {
|
|
41
|
+
renderNotification?: never;
|
|
42
|
+
renderSubject?: SubjectRenderer;
|
|
43
|
+
renderBody?: BodyRenderer;
|
|
44
|
+
};
|
|
45
|
+
type NoRendererProps = {
|
|
46
|
+
renderNotification?: undefined;
|
|
47
|
+
renderSubject?: undefined;
|
|
48
|
+
renderBody?: undefined;
|
|
49
|
+
};
|
|
31
50
|
type DefaultProps = BaseProps & DefaultInboxProps & {
|
|
32
51
|
children?: never;
|
|
33
|
-
};
|
|
52
|
+
} & (NotificationRendererProps | SubjectBodyRendererProps | NoRendererProps);
|
|
34
53
|
type WithChildrenProps = BaseProps & {
|
|
35
54
|
children: React.ReactNode;
|
|
36
55
|
};
|
|
37
56
|
|
|
57
|
+
type InboxProps = DefaultProps | WithChildrenProps;
|
|
58
|
+
|
|
38
59
|
type NovuProviderProps = NovuOptions & {
|
|
39
60
|
children: ReactNode;
|
|
40
61
|
};
|
|
@@ -117,4 +138,4 @@ declare function Notifications(): void;
|
|
|
117
138
|
declare function Preferences(): void;
|
|
118
139
|
declare function Bell(): void;
|
|
119
140
|
|
|
120
|
-
export { type BaseProps, Bell, type BellRenderer, type DefaultInboxProps, type DefaultProps, Inbox, InboxContent, Notifications, type NotificationsRenderer, NovuProvider, Preferences, type UseNotificationsProps, type WithChildrenProps, useCounts, useNotifications, useNovu, usePreferences };
|
|
141
|
+
export { type BaseProps, Bell, type BellRenderer, type BodyRenderer, type DefaultInboxProps, type DefaultProps, Inbox, InboxContent, type InboxProps, type NoRendererProps, type NotificationRendererProps, Notifications, type NotificationsRenderer, NovuProvider, Preferences, type SubjectBodyRendererProps, type SubjectRenderer, type UseNotificationsProps, type WithChildrenProps, useCounts, useNotifications, useNovu, usePreferences };
|
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
import { Notification, NotificationClickHandler, NotificationActionClickHandler, InboxProps, Appearance, Localization, Tab, PreferencesFilter, RouterPush } from '@novu/js/ui';
|
|
1
|
+
import { Notification, NotificationClickHandler, NotificationActionClickHandler, InboxProps as InboxProps$1, Appearance, Localization, Tab, PreferencesFilter, RouterPush } from '@novu/js/ui';
|
|
2
2
|
export { Notification } from '@novu/js/ui';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
import { Novu, NovuOptions, Notification as Notification$1, NovuError, Preference, NotificationFilter } from '@novu/js';
|
|
5
5
|
import { ReactNode } from 'react';
|
|
6
6
|
|
|
7
7
|
type NotificationsRenderer = (notification: Notification) => React.ReactNode;
|
|
8
|
+
type SubjectRenderer = (notification: Notification) => React.ReactNode;
|
|
9
|
+
type BodyRenderer = (notification: Notification) => React.ReactNode;
|
|
8
10
|
type BellRenderer = (unreadCount: number) => React.ReactNode;
|
|
9
11
|
type DefaultInboxProps = {
|
|
10
12
|
open?: boolean;
|
|
11
13
|
renderNotification?: NotificationsRenderer;
|
|
14
|
+
renderSubject?: SubjectRenderer;
|
|
15
|
+
renderBody?: BodyRenderer;
|
|
12
16
|
renderBell?: BellRenderer;
|
|
13
17
|
onNotificationClick?: NotificationClickHandler;
|
|
14
18
|
onPrimaryActionClick?: NotificationActionClickHandler;
|
|
15
19
|
onSecondaryActionClick?: NotificationActionClickHandler;
|
|
16
|
-
placement?: InboxProps['placement'];
|
|
17
|
-
placementOffset?: InboxProps['placementOffset'];
|
|
20
|
+
placement?: InboxProps$1['placement'];
|
|
21
|
+
placementOffset?: InboxProps$1['placementOffset'];
|
|
18
22
|
};
|
|
19
23
|
type BaseProps = {
|
|
20
24
|
applicationIdentifier: string;
|
|
@@ -28,13 +32,30 @@ type BaseProps = {
|
|
|
28
32
|
preferencesFilter?: PreferencesFilter;
|
|
29
33
|
routerPush?: RouterPush;
|
|
30
34
|
};
|
|
35
|
+
type NotificationRendererProps = {
|
|
36
|
+
renderNotification: NotificationsRenderer;
|
|
37
|
+
renderSubject?: never;
|
|
38
|
+
renderBody?: never;
|
|
39
|
+
};
|
|
40
|
+
type SubjectBodyRendererProps = {
|
|
41
|
+
renderNotification?: never;
|
|
42
|
+
renderSubject?: SubjectRenderer;
|
|
43
|
+
renderBody?: BodyRenderer;
|
|
44
|
+
};
|
|
45
|
+
type NoRendererProps = {
|
|
46
|
+
renderNotification?: undefined;
|
|
47
|
+
renderSubject?: undefined;
|
|
48
|
+
renderBody?: undefined;
|
|
49
|
+
};
|
|
31
50
|
type DefaultProps = BaseProps & DefaultInboxProps & {
|
|
32
51
|
children?: never;
|
|
33
|
-
};
|
|
52
|
+
} & (NotificationRendererProps | SubjectBodyRendererProps | NoRendererProps);
|
|
34
53
|
type WithChildrenProps = BaseProps & {
|
|
35
54
|
children: React.ReactNode;
|
|
36
55
|
};
|
|
37
56
|
|
|
57
|
+
type InboxProps = DefaultProps | WithChildrenProps;
|
|
58
|
+
|
|
38
59
|
type NovuProviderProps = NovuOptions & {
|
|
39
60
|
children: ReactNode;
|
|
40
61
|
};
|
|
@@ -117,4 +138,4 @@ declare function Notifications(): void;
|
|
|
117
138
|
declare function Preferences(): void;
|
|
118
139
|
declare function Bell(): void;
|
|
119
140
|
|
|
120
|
-
export { type BaseProps, Bell, type BellRenderer, type DefaultInboxProps, type DefaultProps, Inbox, InboxContent, Notifications, type NotificationsRenderer, NovuProvider, Preferences, type UseNotificationsProps, type WithChildrenProps, useCounts, useNotifications, useNovu, usePreferences };
|
|
141
|
+
export { type BaseProps, Bell, type BellRenderer, type BodyRenderer, type DefaultInboxProps, type DefaultProps, Inbox, InboxContent, type InboxProps, type NoRendererProps, type NotificationRendererProps, Notifications, type NotificationsRenderer, NovuProvider, Preferences, type SubjectBodyRendererProps, type SubjectRenderer, type UseNotificationsProps, type WithChildrenProps, useCounts, useNotifications, useNovu, usePreferences };
|