@novu/react 3.11.0 → 3.12.0-rc.2
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/README.md +10 -18
- package/dist/cjs/components/Inbox.cjs +5 -1
- package/dist/cjs/components/Inbox.cjs.map +1 -1
- package/dist/cjs/components/NovuUI.cjs +3 -1
- package/dist/cjs/components/NovuUI.cjs.map +1 -1
- package/dist/cjs/components/NovuUI.d.cts +9 -9
- package/dist/cjs/components/index.cjs +7 -1
- package/dist/cjs/components/index.cjs.map +1 -1
- package/dist/cjs/components/index.d.cts +5 -0
- package/dist/cjs/components/subscription/DefaultSubscription.cjs +59 -0
- package/dist/cjs/components/subscription/DefaultSubscription.cjs.map +1 -0
- package/dist/cjs/components/subscription/DefaultSubscription.d.cts +11 -0
- package/dist/cjs/components/subscription/Subscription.cjs +80 -0
- package/dist/cjs/components/subscription/Subscription.cjs.map +1 -0
- package/dist/cjs/components/subscription/Subscription.d.cts +22 -0
- package/dist/cjs/components/subscription/SubscriptionButton.cjs +91 -0
- package/dist/cjs/components/subscription/SubscriptionButton.cjs.map +1 -0
- package/dist/cjs/components/subscription/SubscriptionButton.d.cts +8 -0
- package/dist/cjs/components/subscription/SubscriptionPreferences.cjs +91 -0
- package/dist/cjs/components/subscription/SubscriptionPreferences.cjs.map +1 -0
- package/dist/cjs/components/subscription/SubscriptionPreferences.d.cts +8 -0
- package/dist/cjs/hooks/NovuProvider.cjs +21 -18
- package/dist/cjs/hooks/NovuProvider.cjs.map +1 -1
- package/dist/cjs/hooks/index.cjs +11 -1
- package/dist/cjs/hooks/index.cjs.map +1 -1
- package/dist/cjs/hooks/index.d.cts +7 -1
- package/dist/cjs/hooks/useCreateSubscription.cjs +61 -0
- package/dist/cjs/hooks/useCreateSubscription.cjs.map +1 -0
- package/dist/cjs/hooks/useCreateSubscription.d.cts +17 -0
- package/dist/cjs/hooks/useDeleteSubscription.cjs +61 -0
- package/dist/cjs/hooks/useDeleteSubscription.cjs.map +1 -0
- package/dist/cjs/hooks/useDeleteSubscription.d.cts +17 -0
- package/dist/cjs/hooks/useSubscription.cjs +156 -0
- package/dist/cjs/hooks/useSubscription.cjs.map +1 -0
- package/dist/cjs/hooks/useSubscription.d.cts +21 -0
- package/dist/cjs/hooks/useSubscriptions.cjs +121 -0
- package/dist/cjs/hooks/useSubscriptions.cjs.map +1 -0
- package/dist/cjs/hooks/useSubscriptions.d.cts +36 -0
- package/dist/cjs/hooks/useUpdateSubscription.cjs +61 -0
- package/dist/cjs/hooks/useUpdateSubscription.cjs.map +1 -0
- package/dist/cjs/hooks/useUpdateSubscription.d.cts +18 -0
- package/dist/cjs/index.cjs +18 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +14 -3
- package/dist/cjs/server/index.cjs +61 -2
- package/dist/cjs/server/index.cjs.map +1 -1
- package/dist/cjs/server/index.d.cts +18 -4
- package/dist/cjs/utils/appearance.cjs.map +1 -1
- package/dist/cjs/utils/appearance.d.cts +3 -3
- package/dist/cjs/utils/types.cjs.map +1 -1
- package/dist/cjs/utils/types.d.cts +32 -11
- package/dist/esm/components/Inbox.js +5 -1
- package/dist/esm/components/Inbox.js.map +1 -1
- package/dist/esm/components/NovuUI.d.ts +9 -9
- package/dist/esm/components/NovuUI.js +3 -1
- package/dist/esm/components/NovuUI.js.map +1 -1
- package/dist/esm/components/index.d.ts +5 -0
- package/dist/esm/components/index.js +3 -0
- package/dist/esm/components/index.js.map +1 -1
- package/dist/esm/components/subscription/DefaultSubscription.d.ts +11 -0
- package/dist/esm/components/subscription/DefaultSubscription.js +34 -0
- package/dist/esm/components/subscription/DefaultSubscription.js.map +1 -0
- package/dist/esm/components/subscription/Subscription.d.ts +22 -0
- package/dist/esm/components/subscription/Subscription.js +45 -0
- package/dist/esm/components/subscription/Subscription.js.map +1 -0
- package/dist/esm/components/subscription/SubscriptionButton.d.ts +8 -0
- package/dist/esm/components/subscription/SubscriptionButton.js +56 -0
- package/dist/esm/components/subscription/SubscriptionButton.js.map +1 -0
- package/dist/esm/components/subscription/SubscriptionPreferences.d.ts +8 -0
- package/dist/esm/components/subscription/SubscriptionPreferences.js +56 -0
- package/dist/esm/components/subscription/SubscriptionPreferences.js.map +1 -0
- package/dist/esm/hooks/NovuProvider.js +22 -19
- package/dist/esm/hooks/NovuProvider.js.map +1 -1
- package/dist/esm/hooks/index.d.ts +7 -1
- package/dist/esm/hooks/index.js +5 -0
- package/dist/esm/hooks/index.js.map +1 -1
- package/dist/esm/hooks/useCreateSubscription.d.ts +17 -0
- package/dist/esm/hooks/useCreateSubscription.js +36 -0
- package/dist/esm/hooks/useCreateSubscription.js.map +1 -0
- package/dist/esm/hooks/useDeleteSubscription.d.ts +17 -0
- package/dist/esm/hooks/useDeleteSubscription.js +36 -0
- package/dist/esm/hooks/useDeleteSubscription.js.map +1 -0
- package/dist/esm/hooks/useSubscription.d.ts +21 -0
- package/dist/esm/hooks/useSubscription.js +129 -0
- package/dist/esm/hooks/useSubscription.js.map +1 -0
- package/dist/esm/hooks/useSubscriptions.d.ts +36 -0
- package/dist/esm/hooks/useSubscriptions.js +96 -0
- package/dist/esm/hooks/useSubscriptions.js.map +1 -0
- package/dist/esm/hooks/useUpdateSubscription.d.ts +18 -0
- package/dist/esm/hooks/useUpdateSubscription.js +36 -0
- package/dist/esm/hooks/useUpdateSubscription.js.map +1 -0
- package/dist/esm/index.d.ts +14 -3
- package/dist/esm/index.js +32 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/server/index.d.ts +18 -4
- package/dist/esm/server/index.js +53 -2
- package/dist/esm/server/index.js.map +1 -1
- package/dist/esm/utils/appearance.d.ts +3 -3
- package/dist/esm/utils/appearance.js.map +1 -1
- package/dist/esm/utils/types.d.ts +32 -11
- package/package.json +11 -11
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UnreadCount, DefaultSchedule, Context, Subscriber } from '@novu/js';
|
|
2
|
-
import { Notification,
|
|
2
|
+
import { Notification, InboxIconKey, InboxTheme, SubscriptionIconKey, SubscriptionTheme, AllIconKey, AllTheme, NotificationClickHandler, NotificationActionClickHandler, InboxProps, InboxLocalization, Tab, PreferencesFilter, PreferenceGroups, PreferencesSort, RouterPush } from '@novu/js/ui';
|
|
3
3
|
import { ReactNode } from 'react';
|
|
4
4
|
|
|
5
5
|
type NotificationsRenderer = (notification: Notification) => React.ReactNode;
|
|
@@ -13,14 +13,32 @@ type ReactIconRendererProps = {
|
|
|
13
13
|
class?: string;
|
|
14
14
|
};
|
|
15
15
|
type ReactIconRenderer = (props: ReactIconRendererProps) => ReactNode;
|
|
16
|
-
type
|
|
17
|
-
[key in
|
|
16
|
+
type ReactInboxIconOverrides = {
|
|
17
|
+
[key in InboxIconKey]?: ReactIconRenderer;
|
|
18
18
|
};
|
|
19
|
-
type
|
|
20
|
-
icons?:
|
|
19
|
+
type ReactInboxTheme = Omit<InboxTheme, 'icons'> & {
|
|
20
|
+
icons?: ReactInboxIconOverrides;
|
|
21
21
|
};
|
|
22
|
-
type
|
|
23
|
-
|
|
22
|
+
type ReactSubscriptionIconOverrides = {
|
|
23
|
+
[key in SubscriptionIconKey]?: ReactIconRenderer;
|
|
24
|
+
};
|
|
25
|
+
type ReactSubscriptionTheme = Omit<SubscriptionTheme, 'icons'> & {
|
|
26
|
+
icons?: ReactSubscriptionIconOverrides;
|
|
27
|
+
};
|
|
28
|
+
type ReactAllIconOverrides = {
|
|
29
|
+
[key in AllIconKey]?: ReactIconRenderer;
|
|
30
|
+
};
|
|
31
|
+
type ReactAllTheme = Omit<AllTheme, 'icons'> & {
|
|
32
|
+
icons?: ReactAllIconOverrides;
|
|
33
|
+
};
|
|
34
|
+
type ReactInboxAppearance = ReactInboxTheme & {
|
|
35
|
+
baseTheme?: InboxTheme | InboxTheme[];
|
|
36
|
+
};
|
|
37
|
+
type ReactSubscriptionAppearance = ReactSubscriptionTheme & {
|
|
38
|
+
baseTheme?: SubscriptionTheme | SubscriptionTheme[];
|
|
39
|
+
};
|
|
40
|
+
type ReactAllAppearance = ReactAllTheme & {
|
|
41
|
+
baseTheme?: ReactAllTheme | ReactAllTheme[];
|
|
24
42
|
};
|
|
25
43
|
type DefaultInboxProps = {
|
|
26
44
|
open?: boolean;
|
|
@@ -42,8 +60,8 @@ type StandardBaseProps = {
|
|
|
42
60
|
contextHash?: string;
|
|
43
61
|
backendUrl?: string;
|
|
44
62
|
socketUrl?: string;
|
|
45
|
-
appearance?:
|
|
46
|
-
localization?:
|
|
63
|
+
appearance?: ReactInboxAppearance;
|
|
64
|
+
localization?: InboxLocalization;
|
|
47
65
|
tabs?: Array<Tab>;
|
|
48
66
|
preferencesFilter?: PreferencesFilter;
|
|
49
67
|
preferenceGroups?: PreferenceGroups;
|
|
@@ -65,7 +83,10 @@ type StandardBaseProps = {
|
|
|
65
83
|
subscriberId?: never;
|
|
66
84
|
applicationIdentifier?: never;
|
|
67
85
|
});
|
|
68
|
-
type
|
|
86
|
+
type InboxBaseProps = Omit<StandardBaseProps, 'appearance'> & {
|
|
87
|
+
appearance?: ReactInboxAppearance;
|
|
88
|
+
};
|
|
89
|
+
type BaseProps = InboxBaseProps;
|
|
69
90
|
type NotificationRendererProps = {
|
|
70
91
|
renderNotification: NotificationsRenderer;
|
|
71
92
|
renderAvatar?: never;
|
|
@@ -97,4 +118,4 @@ type WithChildrenProps = BaseProps & {
|
|
|
97
118
|
children: React.ReactNode;
|
|
98
119
|
};
|
|
99
120
|
|
|
100
|
-
export type { AvatarRenderer, BaseProps, BellRenderer, BodyRenderer, CustomActionsRenderer, DefaultActionsRenderer, DefaultInboxProps, DefaultProps, NoRendererProps, NotificationRendererProps, NotificationsRenderer,
|
|
121
|
+
export type { AvatarRenderer, BaseProps, BellRenderer, BodyRenderer, CustomActionsRenderer, DefaultActionsRenderer, DefaultInboxProps, DefaultProps, NoRendererProps, NotificationRendererProps, NotificationsRenderer, ReactAllAppearance, ReactAllIconOverrides, ReactAllTheme, ReactIconRenderer, ReactIconRendererProps, ReactInboxAppearance, ReactInboxIconOverrides, ReactInboxTheme, ReactSubscriptionAppearance, ReactSubscriptionIconOverrides, ReactSubscriptionTheme, SubjectBodyRendererProps, SubjectRenderer, WithChildrenProps };
|
|
@@ -81,7 +81,10 @@ var DefaultInbox = (props) => {
|
|
|
81
81
|
};
|
|
82
82
|
var Inbox = React.memo((props) => {
|
|
83
83
|
const { subscriberId, ...propsWithoutSubscriberId } = props;
|
|
84
|
-
const subscriber =
|
|
84
|
+
const subscriber = useMemo(
|
|
85
|
+
() => buildSubscriber({ subscriberId: props.subscriberId, subscriber: props.subscriber }),
|
|
86
|
+
[props.subscriberId, props.subscriber]
|
|
87
|
+
);
|
|
85
88
|
const applicationIdentifier = props.applicationIdentifier ? props.applicationIdentifier : "";
|
|
86
89
|
const novu = useUnsafeNovu();
|
|
87
90
|
if (novu) {
|
|
@@ -195,6 +198,7 @@ var InboxChild = withRenderer(
|
|
|
195
198
|
) });
|
|
196
199
|
})
|
|
197
200
|
);
|
|
201
|
+
InboxChild.displayName = "InboxChild";
|
|
198
202
|
function isWithChildrenProps(props) {
|
|
199
203
|
return "children" in props;
|
|
200
204
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/Inbox.tsx"],"sourcesContent":["import { StandardNovuOptions } from '@novu/js';\nimport { buildSubscriber } from '@novu/js/internal';\nimport React, { useMemo } from 'react';\nimport { useNovuUI } from '../context/NovuUIContext';\nimport { useRenderer } from '../context/RendererContext';\nimport { InternalNovuProvider, useNovu, useUnsafeNovu } from '../hooks/NovuProvider';\nimport { DefaultInboxProps, DefaultProps, WithChildrenProps } from '../utils/types';\nimport { Mounter } from './Mounter';\nimport { NovuUI } from './NovuUI';\nimport { withRenderer } from './Renderer';\n\nexport type InboxProps = DefaultProps | WithChildrenProps;\n\nconst DefaultInbox = (props: DefaultInboxProps) => {\n const {\n open,\n renderNotification,\n renderAvatar,\n renderSubject,\n renderBody,\n renderDefaultActions,\n renderCustomActions,\n renderBell,\n onNotificationClick,\n onPrimaryActionClick,\n onSecondaryActionClick,\n placement,\n placementOffset,\n } = props;\n const { novuUI } = useNovuUI();\n const { mountElement } = useRenderer();\n\n const mount = React.useCallback(\n (element: HTMLElement) => {\n if (renderNotification) {\n return novuUI.mountComponent({\n name: 'Inbox',\n props: {\n open,\n renderNotification: renderNotification\n ? (el, notification) => mountElement(el, renderNotification(notification))\n : undefined,\n renderBell: renderBell ? (el, unreadCount) => mountElement(el, renderBell(unreadCount)) : undefined,\n onNotificationClick,\n onPrimaryActionClick,\n onSecondaryActionClick,\n placementOffset,\n placement,\n },\n element,\n });\n }\n\n return novuUI.mountComponent({\n name: 'Inbox',\n props: {\n open,\n renderAvatar: renderAvatar ? (el, notification) => mountElement(el, renderAvatar(notification)) : undefined,\n renderSubject: renderSubject\n ? (el, notification) => mountElement(el, renderSubject(notification))\n : undefined,\n renderBody: renderBody ? (el, notification) => mountElement(el, renderBody(notification)) : undefined,\n renderDefaultActions: renderDefaultActions\n ? (el, notification) => mountElement(el, renderDefaultActions(notification))\n : undefined,\n renderCustomActions: renderCustomActions\n ? (el, notification) => mountElement(el, renderCustomActions(notification))\n : undefined,\n renderBell: renderBell ? (el, unreadCount) => mountElement(el, renderBell(unreadCount)) : undefined,\n onNotificationClick,\n onPrimaryActionClick,\n onSecondaryActionClick,\n placementOffset,\n placement,\n },\n element,\n });\n },\n [\n open,\n renderNotification,\n renderAvatar,\n renderSubject,\n renderBody,\n renderDefaultActions,\n renderCustomActions,\n renderBell,\n onNotificationClick,\n onPrimaryActionClick,\n onSecondaryActionClick,\n ]\n );\n\n return <Mounter mount={mount} />;\n};\n\nexport const Inbox = React.memo((props: InboxProps) => {\n const { subscriberId, ...propsWithoutSubscriberId } = props;\n const subscriber = buildSubscriber({ subscriberId: props.subscriberId, subscriber: props.subscriber });\n const applicationIdentifier = props.applicationIdentifier ? props.applicationIdentifier : ''; // for keyless we provide an empty string, the api will generate a identifier\n const novu = useUnsafeNovu();\n\n if (novu) {\n return (\n <InboxChild {...propsWithoutSubscriberId} applicationIdentifier={applicationIdentifier} subscriber={subscriber} />\n );\n }\n\n const providerProps = {\n applicationIdentifier,\n subscriberHash: props.subscriberHash,\n contextHash: props.contextHash,\n backendUrl: props.backendUrl,\n socketUrl: props.socketUrl,\n subscriber,\n defaultSchedule: props.defaultSchedule,\n context: props.context,\n } satisfies StandardNovuOptions;\n\n return (\n <InternalNovuProvider {...providerProps} userAgentType=\"components\">\n <InboxChild {...propsWithoutSubscriberId} applicationIdentifier={applicationIdentifier} subscriber={subscriber} />\n </InternalNovuProvider>\n );\n});\n\nconst InboxChild = withRenderer(\n React.memo((props: InboxProps) => {\n const {\n localization,\n appearance,\n tabs,\n preferencesFilter,\n preferenceGroups,\n preferencesSort,\n routerPush,\n applicationIdentifier = '', // for keyless we provide an empty string, the api will generate a identifier\n subscriberId,\n subscriberHash,\n contextHash,\n backendUrl,\n socketUrl,\n subscriber,\n defaultSchedule,\n context,\n } = props;\n const novu = useNovu();\n\n const options = useMemo(() => {\n return {\n localization,\n appearance,\n tabs,\n preferencesFilter,\n preferenceGroups,\n preferencesSort,\n routerPush,\n options: {\n applicationIdentifier,\n subscriberHash,\n contextHash,\n backendUrl,\n socketUrl,\n subscriber: buildSubscriber({ subscriberId, subscriber }),\n defaultSchedule,\n context,\n },\n };\n }, [\n localization,\n appearance,\n tabs,\n preferencesFilter,\n preferenceGroups,\n preferencesSort,\n applicationIdentifier,\n subscriberId,\n subscriberHash,\n contextHash,\n backendUrl,\n socketUrl,\n subscriber,\n context,\n ]);\n\n if (isWithChildrenProps(props)) {\n return (\n <NovuUI options={options} novu={novu}>\n {props.children}\n </NovuUI>\n );\n }\n\n const {\n open,\n renderNotification,\n renderAvatar,\n renderSubject,\n renderBody,\n renderDefaultActions,\n renderCustomActions,\n renderBell,\n onNotificationClick,\n onPrimaryActionClick,\n onSecondaryActionClick,\n placementOffset,\n placement,\n } = props;\n\n return (\n <NovuUI options={options} novu={novu}>\n <DefaultInbox\n open={open}\n renderNotification={renderNotification}\n renderAvatar={renderAvatar}\n renderSubject={renderSubject}\n renderBody={renderBody}\n renderDefaultActions={renderDefaultActions}\n renderCustomActions={renderCustomActions}\n renderBell={renderBell}\n onNotificationClick={onNotificationClick}\n onPrimaryActionClick={onPrimaryActionClick}\n onSecondaryActionClick={onSecondaryActionClick}\n placement={placement}\n placementOffset={placementOffset}\n />\n </NovuUI>\n );\n })\n);\n\nfunction isWithChildrenProps(props: InboxProps): props is WithChildrenProps {\n return 'children' in props;\n}\n"],"mappings":";AACA,SAAS,uBAAuB;AAChC,OAAO,SAAS,eAAe;AAC/B,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAC5B,SAAS,sBAAsB,SAAS,qBAAqB;AAE7D,SAAS,eAAe;AACxB,SAAS,cAAc;AACvB,SAAS,oBAAoB;AAoFpB;AAhFT,IAAM,eAAe,CAAC,UAA6B;AACjD,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AACJ,QAAM,EAAE,OAAO,IAAI,UAAU;AAC7B,QAAM,EAAE,aAAa,IAAI,YAAY;AAErC,QAAM,QAAQ,MAAM;AAAA,IAClB,CAAC,YAAyB;AACxB,UAAI,oBAAoB;AACtB,eAAO,OAAO,eAAe;AAAA,UAC3B,MAAM;AAAA,UACN,OAAO;AAAA,YACL;AAAA,YACA,oBAAoB,qBAChB,CAAC,IAAI,iBAAiB,aAAa,IAAI,mBAAmB,YAAY,CAAC,IACvE;AAAA,YACJ,YAAY,aAAa,CAAC,IAAI,gBAAgB,aAAa,IAAI,WAAW,WAAW,CAAC,IAAI;AAAA,YAC1F;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,UACA;AAAA,QACF,CAAC;AAAA,MACH;AAEA,aAAO,OAAO,eAA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A;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,IAAI;AAEJ,WACE,oBAAC,UAAO,SAAkB,MACxB;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA;AAAA,IACF,GACF;AAAA,EAEJ,CAAC;AACH;AAEA,SAAS,oBAAoB,OAA+C;AAC1E,SAAO,cAAc;AACvB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Inbox.tsx"],"sourcesContent":["import { StandardNovuOptions } from '@novu/js';\nimport { buildSubscriber } from '@novu/js/internal';\nimport React, { useMemo } from 'react';\nimport { useNovuUI } from '../context/NovuUIContext';\nimport { useRenderer } from '../context/RendererContext';\nimport { InternalNovuProvider, useNovu, useUnsafeNovu } from '../hooks/NovuProvider';\nimport { DefaultInboxProps, DefaultProps, WithChildrenProps } from '../utils/types';\nimport { Mounter } from './Mounter';\nimport { NovuUI } from './NovuUI';\nimport { withRenderer } from './Renderer';\n\nexport type InboxProps = DefaultProps | WithChildrenProps;\n\nconst DefaultInbox = (props: DefaultInboxProps) => {\n const {\n open,\n renderNotification,\n renderAvatar,\n renderSubject,\n renderBody,\n renderDefaultActions,\n renderCustomActions,\n renderBell,\n onNotificationClick,\n onPrimaryActionClick,\n onSecondaryActionClick,\n placement,\n placementOffset,\n } = props;\n const { novuUI } = useNovuUI();\n const { mountElement } = useRenderer();\n\n const mount = React.useCallback(\n (element: HTMLElement) => {\n if (renderNotification) {\n return novuUI.mountComponent({\n name: 'Inbox',\n props: {\n open,\n renderNotification: renderNotification\n ? (el, notification) => mountElement(el, renderNotification(notification))\n : undefined,\n renderBell: renderBell ? (el, unreadCount) => mountElement(el, renderBell(unreadCount)) : undefined,\n onNotificationClick,\n onPrimaryActionClick,\n onSecondaryActionClick,\n placementOffset,\n placement,\n },\n element,\n });\n }\n\n return novuUI.mountComponent({\n name: 'Inbox',\n props: {\n open,\n renderAvatar: renderAvatar ? (el, notification) => mountElement(el, renderAvatar(notification)) : undefined,\n renderSubject: renderSubject\n ? (el, notification) => mountElement(el, renderSubject(notification))\n : undefined,\n renderBody: renderBody ? (el, notification) => mountElement(el, renderBody(notification)) : undefined,\n renderDefaultActions: renderDefaultActions\n ? (el, notification) => mountElement(el, renderDefaultActions(notification))\n : undefined,\n renderCustomActions: renderCustomActions\n ? (el, notification) => mountElement(el, renderCustomActions(notification))\n : undefined,\n renderBell: renderBell ? (el, unreadCount) => mountElement(el, renderBell(unreadCount)) : undefined,\n onNotificationClick,\n onPrimaryActionClick,\n onSecondaryActionClick,\n placementOffset,\n placement,\n },\n element,\n });\n },\n [\n open,\n renderNotification,\n renderAvatar,\n renderSubject,\n renderBody,\n renderDefaultActions,\n renderCustomActions,\n renderBell,\n onNotificationClick,\n onPrimaryActionClick,\n onSecondaryActionClick,\n ]\n );\n\n return <Mounter mount={mount} />;\n};\n\nexport const Inbox = React.memo((props: InboxProps) => {\n const { subscriberId, ...propsWithoutSubscriberId } = props;\n const subscriber = useMemo(\n () => buildSubscriber({ subscriberId: props.subscriberId, subscriber: props.subscriber }),\n [props.subscriberId, props.subscriber]\n );\n const applicationIdentifier = props.applicationIdentifier ? props.applicationIdentifier : ''; // for keyless we provide an empty string, the api will generate a identifier\n const novu = useUnsafeNovu();\n\n if (novu) {\n return (\n <InboxChild {...propsWithoutSubscriberId} applicationIdentifier={applicationIdentifier} subscriber={subscriber} />\n );\n }\n\n const providerProps = {\n applicationIdentifier,\n subscriberHash: props.subscriberHash,\n contextHash: props.contextHash,\n backendUrl: props.backendUrl,\n socketUrl: props.socketUrl,\n subscriber,\n defaultSchedule: props.defaultSchedule,\n context: props.context,\n } satisfies StandardNovuOptions;\n\n return (\n <InternalNovuProvider {...providerProps} userAgentType=\"components\">\n <InboxChild {...propsWithoutSubscriberId} applicationIdentifier={applicationIdentifier} subscriber={subscriber} />\n </InternalNovuProvider>\n );\n});\n\nconst InboxChild = withRenderer(\n React.memo((props: InboxProps) => {\n const {\n localization,\n appearance,\n tabs,\n preferencesFilter,\n preferenceGroups,\n preferencesSort,\n routerPush,\n applicationIdentifier = '', // for keyless we provide an empty string, the api will generate a identifier\n subscriberId,\n subscriberHash,\n contextHash,\n backendUrl,\n socketUrl,\n subscriber,\n defaultSchedule,\n context,\n } = props;\n const novu = useNovu();\n\n const options = useMemo(() => {\n return {\n localization,\n appearance,\n tabs,\n preferencesFilter,\n preferenceGroups,\n preferencesSort,\n routerPush,\n options: {\n applicationIdentifier,\n subscriberHash,\n contextHash,\n backendUrl,\n socketUrl,\n subscriber: buildSubscriber({ subscriberId, subscriber }),\n defaultSchedule,\n context,\n },\n };\n }, [\n localization,\n appearance,\n tabs,\n preferencesFilter,\n preferenceGroups,\n preferencesSort,\n applicationIdentifier,\n subscriberId,\n subscriberHash,\n contextHash,\n backendUrl,\n socketUrl,\n subscriber,\n context,\n ]);\n\n if (isWithChildrenProps(props)) {\n return (\n <NovuUI options={options} novu={novu}>\n {props.children}\n </NovuUI>\n );\n }\n\n const {\n open,\n renderNotification,\n renderAvatar,\n renderSubject,\n renderBody,\n renderDefaultActions,\n renderCustomActions,\n renderBell,\n onNotificationClick,\n onPrimaryActionClick,\n onSecondaryActionClick,\n placementOffset,\n placement,\n } = props;\n\n return (\n <NovuUI options={options} novu={novu}>\n <DefaultInbox\n open={open}\n renderNotification={renderNotification}\n renderAvatar={renderAvatar}\n renderSubject={renderSubject}\n renderBody={renderBody}\n renderDefaultActions={renderDefaultActions}\n renderCustomActions={renderCustomActions}\n renderBell={renderBell}\n onNotificationClick={onNotificationClick}\n onPrimaryActionClick={onPrimaryActionClick}\n onSecondaryActionClick={onSecondaryActionClick}\n placement={placement}\n placementOffset={placementOffset}\n />\n </NovuUI>\n );\n })\n);\n\nInboxChild.displayName = 'InboxChild';\n\nfunction isWithChildrenProps(props: InboxProps): props is WithChildrenProps {\n return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A;AAAA,QACA;AAAA;AAAA,IACF,GACF;AAAA,EAEJ,CAAC;AACH;AAEA,WAAW,cAAc;AAEzB,SAAS,oBAAoB,OAA+C;AAC1E,SAAO,cAAc;AACvB;","names":[]}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { Novu } from '@novu/js';
|
|
3
|
-
import { NovuUIOptions } from '@novu/js/ui';
|
|
3
|
+
import { NovuUIOptions as NovuUIOptions$1 } from '@novu/js/ui';
|
|
4
4
|
import React__default from 'react';
|
|
5
|
-
import {
|
|
5
|
+
import { ReactInboxAppearance, ReactSubscriptionAppearance } from '../utils/types.js';
|
|
6
6
|
|
|
7
|
-
type
|
|
8
|
-
appearance?:
|
|
7
|
+
type NovuUIOptions = Omit<NovuUIOptions$1, 'appearance'> & {
|
|
8
|
+
appearance?: ReactInboxAppearance | ReactSubscriptionAppearance;
|
|
9
9
|
};
|
|
10
|
-
type
|
|
11
|
-
options:
|
|
12
|
-
novu
|
|
10
|
+
type NovuUIProps = React__default.PropsWithChildren<{
|
|
11
|
+
options: NovuUIOptions;
|
|
12
|
+
novu: Novu;
|
|
13
13
|
}>;
|
|
14
|
-
declare const NovuUI: ({ options, novu, children }:
|
|
14
|
+
declare const NovuUI: ({ options, novu, children }: NovuUIProps) => react_jsx_runtime.JSX.Element;
|
|
15
15
|
|
|
16
|
-
export { NovuUI };
|
|
16
|
+
export { NovuUI, type NovuUIOptions };
|
|
@@ -64,6 +64,7 @@ var NovuUI = ({ options, novu, children }) => {
|
|
|
64
64
|
novuUI.updateTabs(options.tabs);
|
|
65
65
|
novuUI.updateOptions(options.options);
|
|
66
66
|
novuUI.updateRouterPush(options.routerPush);
|
|
67
|
+
novuUI.updateNovu(novu);
|
|
67
68
|
}, [
|
|
68
69
|
shadowRootDetector,
|
|
69
70
|
novuUI,
|
|
@@ -71,7 +72,8 @@ var NovuUI = ({ options, novu, children }) => {
|
|
|
71
72
|
options.localization,
|
|
72
73
|
options.tabs,
|
|
73
74
|
options.options,
|
|
74
|
-
options.routerPush
|
|
75
|
+
options.routerPush,
|
|
76
|
+
novu
|
|
75
77
|
]);
|
|
76
78
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
77
79
|
/* @__PURE__ */ jsx(ShadowRootDetector, { ref: shadowRootDetector }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/NovuUI.tsx"],"sourcesContent":["import { Novu } from '@novu/js';\nimport type { NovuUIOptions as JsNovuUIOptions } from '@novu/js/ui';\nimport { NovuUI as NovuUIClass } from '@novu/js/ui';\nimport React, { useEffect, useMemo, useRef, useState } from 'react';\nimport { NovuUIProvider } from '../context/NovuUIContext';\nimport { useRenderer } from '../context/RendererContext';\nimport { useDataRef } from '../hooks/internal/useDataRef';\nimport { adaptAppearanceForJs } from '../utils/appearance';\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../src/components/NovuUI.tsx"],"sourcesContent":["import { Novu } from '@novu/js';\nimport type { NovuUIOptions as JsNovuUIOptions } from '@novu/js/ui';\nimport { NovuUI as NovuUIClass } from '@novu/js/ui';\nimport React, { useEffect, useMemo, useRef, useState } from 'react';\nimport { NovuUIProvider } from '../context/NovuUIContext';\nimport { useRenderer } from '../context/RendererContext';\nimport { useDataRef } from '../hooks/internal/useDataRef';\nimport { adaptAppearanceForJs } from '../utils/appearance';\nimport type { ReactInboxAppearance, ReactSubscriptionAppearance } from '../utils/types';\nimport { ShadowRootDetector } from './ShadowRootDetector';\n\nexport type NovuUIOptions = Omit<JsNovuUIOptions, 'appearance'> & {\n appearance?: ReactInboxAppearance | ReactSubscriptionAppearance;\n};\n\ntype NovuUIProps = React.PropsWithChildren<{\n options: NovuUIOptions;\n novu: Novu;\n}>;\n\nconst findParentShadowRoot = (child?: HTMLDivElement | null): Node | null => {\n if (!child) {\n return null;\n }\n\n let node: Node | null = child;\n\n while (node) {\n if (node instanceof Element && node.shadowRoot) {\n return node.shadowRoot;\n }\n\n if (node instanceof ShadowRoot) {\n return node;\n }\n\n node = node.parentNode;\n\n if (!node || node === document) {\n break;\n }\n }\n\n return null;\n};\n\nexport const NovuUI = ({ options, novu, children }: NovuUIProps) => {\n const shadowRootDetector = useRef<HTMLDivElement>(null);\n const { mountElement } = useRenderer();\n\n const adaptedAppearanceForUpdate = useMemo(\n () => adaptAppearanceForJs(options.appearance || {}, mountElement),\n [options.appearance, mountElement]\n );\n\n const adaptedOptions = useMemo(() => {\n return {\n ...options,\n appearance: adaptedAppearanceForUpdate,\n novu,\n };\n }, [options, novu, adaptedAppearanceForUpdate]);\n\n const optionsRef = useDataRef(adaptedOptions);\n const [novuUI, setNovuUI] = useState<NovuUIClass | undefined>();\n\n useEffect(() => {\n const parentShadowRoot = findParentShadowRoot(shadowRootDetector.current);\n const instance = new NovuUIClass({\n ...optionsRef.current,\n container: optionsRef.current.container ?? parentShadowRoot,\n });\n setNovuUI(instance);\n\n return () => {\n instance.unmount();\n };\n }, []);\n\n useEffect(() => {\n if (!novuUI) {\n return;\n }\n\n const parentShadowRoot = findParentShadowRoot(shadowRootDetector.current);\n novuUI.updateContainer(options.container ?? parentShadowRoot);\n novuUI.updateAppearance(adaptedAppearanceForUpdate);\n novuUI.updateLocalization(options.localization);\n novuUI.updateTabs(options.tabs);\n novuUI.updateOptions(options.options);\n novuUI.updateRouterPush(options.routerPush);\n novuUI.updateNovu(novu);\n }, [\n shadowRootDetector,\n novuUI,\n adaptedAppearanceForUpdate,\n options.localization,\n options.tabs,\n options.options,\n options.routerPush,\n novu,\n ]);\n\n return (\n <>\n <ShadowRootDetector ref={shadowRootDetector} />\n {novuUI && <NovuUIProvider value={{ novuUI }}>{children}</NovuUIProvider>}\n </>\n );\n};\n"],"mappings":";AAEA,SAAS,UAAU,mBAAmB;AACtC,SAAgB,WAAW,SAAS,QAAQ,gBAAgB;AAC5D,SAAS,sBAAsB;AAC/B,SAAS,mBAAmB;AAC5B,SAAS,kBAAkB;A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B,mBAAmB,OAAO;AACxE,WAAO,gBAAgB,QAAQ,aAAa,gBAAgB;AAC5D,WAAO,iBAAiB,0BAA0B;AAClD,WAAO,mBAAmB,QAAQ,YAAY;AAC9C,WAAO,WAAW,QAAQ,IAAI;AAC9B,WAAO,cAAc,QAAQ,OAAO;AACpC,WAAO,iBAAiB,QAAQ,UAAU;AAC1C,WAAO,WAAW,IAAI;AAAA,EACxB,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR;AAAA,EACF,CAAC;AAED,SACE,iCACE;AAAA,wBAAC,sBAAmB,KAAK,oBAAoB;AAAA,IAC5C,UAAU,oBAAC,kBAAe,OAAO,EAAE,OAAO,GAAI,UAAS;AAAA,KAC1D;AAEJ;","names":[]}
|
|
@@ -4,8 +4,13 @@ export { Inbox, InboxProps } from './Inbox.js';
|
|
|
4
4
|
export { InboxContent, InboxContentProps } from './InboxContent.js';
|
|
5
5
|
export { NotificationProps, Notifications } from './Notifications.js';
|
|
6
6
|
export { Preferences } from './Preferences.js';
|
|
7
|
+
export { Subscription, SubscriptionProps } from './subscription/Subscription.js';
|
|
8
|
+
export { SubscriptionButton, SubscriptionButtonProps } from './subscription/SubscriptionButton.js';
|
|
9
|
+
export { SubscriptionPreferences, SubscriptionPreferencesProps } from './subscription/SubscriptionPreferences.js';
|
|
7
10
|
import 'react/jsx-runtime';
|
|
8
11
|
import '@novu/js';
|
|
9
12
|
import 'react';
|
|
10
13
|
import '../utils/types.js';
|
|
11
14
|
import '@novu/js/ui';
|
|
15
|
+
import './NovuUI.js';
|
|
16
|
+
import './subscription/DefaultSubscription.js';
|
|
@@ -5,4 +5,7 @@ export * from "./Inbox.js";
|
|
|
5
5
|
export * from "./InboxContent.js";
|
|
6
6
|
export * from "./Notifications.js";
|
|
7
7
|
export * from "./Preferences.js";
|
|
8
|
+
export * from "./subscription/Subscription.js";
|
|
9
|
+
export * from "./subscription/SubscriptionButton.js";
|
|
10
|
+
export * from "./subscription/SubscriptionPreferences.js";
|
|
8
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/index.ts"],"sourcesContent":["export * from '../hooks/NovuProvider';\nexport * from './Bell';\nexport * from './Inbox';\nexport * from './InboxContent';\nexport * from './Notifications';\nexport * from './Preferences';\n"],"mappings":";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/index.ts"],"sourcesContent":["export * from '../hooks/NovuProvider';\nexport * from './Bell';\nexport * from './Inbox';\nexport * from './InboxContent';\nexport * from './Notifications';\nexport * from './Preferences';\nexport * from './subscription/Subscription';\nexport * from './subscription/SubscriptionButton';\nexport * from './subscription/SubscriptionPreferences';\n"],"mappings":";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { TopicSubscription } from '@novu/js';
|
|
3
|
+
import { SubscriptionProps } from '@novu/js/ui';
|
|
4
|
+
|
|
5
|
+
type PreferencesRenderer = (subscription?: TopicSubscription, loading?: boolean) => React.ReactNode;
|
|
6
|
+
type DefaultSubscriptionProps = {
|
|
7
|
+
renderPreferences?: PreferencesRenderer;
|
|
8
|
+
} & Pick<SubscriptionProps, 'open' | 'placement' | 'placementOffset' | 'topicKey' | 'identifier' | 'preferences'>;
|
|
9
|
+
declare const DefaultSubscription: (props: DefaultSubscriptionProps) => react_jsx_runtime.JSX.Element;
|
|
10
|
+
|
|
11
|
+
export { DefaultSubscription, type DefaultSubscriptionProps, type PreferencesRenderer };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// src/components/subscription/DefaultSubscription.tsx
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
import { useNovuUI } from "../../context/NovuUIContext.js";
|
|
4
|
+
import { useRenderer } from "../../context/RendererContext.js";
|
|
5
|
+
import { Mounter } from "../Mounter.js";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
var DefaultSubscription = (props) => {
|
|
8
|
+
const { topicKey, identifier, preferences, open, placement, placementOffset, renderPreferences } = props;
|
|
9
|
+
const { novuUI } = useNovuUI();
|
|
10
|
+
const { mountElement } = useRenderer();
|
|
11
|
+
const mount = useCallback(
|
|
12
|
+
(element) => {
|
|
13
|
+
return novuUI.mountComponent({
|
|
14
|
+
name: "Subscription",
|
|
15
|
+
props: {
|
|
16
|
+
topicKey,
|
|
17
|
+
identifier,
|
|
18
|
+
preferences,
|
|
19
|
+
open,
|
|
20
|
+
placementOffset,
|
|
21
|
+
placement,
|
|
22
|
+
renderPreferences: renderPreferences ? (el, subscription, loading) => mountElement(el, renderPreferences(subscription, loading)) : void 0
|
|
23
|
+
},
|
|
24
|
+
element
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
[topicKey, identifier, preferences, open, placementOffset, placement, renderPreferences, novuUI, mountElement]
|
|
28
|
+
);
|
|
29
|
+
return /* @__PURE__ */ jsx(Mounter, { mount });
|
|
30
|
+
};
|
|
31
|
+
export {
|
|
32
|
+
DefaultSubscription
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=DefaultSubscription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/subscription/DefaultSubscription.tsx"],"sourcesContent":["import { TopicSubscription } from '@novu/js';\nimport { SubscriptionProps } from '@novu/js/ui';\nimport { useCallback } from 'react';\nimport { useNovuUI } from '../../context/NovuUIContext';\nimport { useRenderer } from '../../context/RendererContext';\nimport { Mounter } from '../Mounter';\n\nexport type PreferencesRenderer = (subscription?: TopicSubscription, loading?: boolean) => React.ReactNode;\n\nexport type DefaultSubscriptionProps = {\n renderPreferences?: PreferencesRenderer;\n} & Pick<SubscriptionProps, 'open' | 'placement' | 'placementOffset' | 'topicKey' | 'identifier' | 'preferences'>;\n\nexport const DefaultSubscription = (props: DefaultSubscriptionProps) => {\n const { topicKey, identifier, preferences, open, placement, placementOffset, renderPreferences } = props;\n const { novuUI } = useNovuUI();\n const { mountElement } = useRenderer();\n\n const mount = useCallback(\n (element: HTMLElement) => {\n return novuUI.mountComponent({\n name: 'Subscription',\n props: {\n topicKey,\n identifier,\n preferences,\n open,\n placementOffset,\n placement,\n renderPreferences: renderPreferences\n ? (el, subscription, loading) => mountElement(el, renderPreferences(subscription, loading))\n : undefined,\n },\n element,\n });\n },\n [topicKey, identifier, preferences, open, placementOffset, placement, renderPreferences, novuUI, mountElement]\n );\n\n return <Mounter mount={mount} />;\n};\n"],"mappings":";AAEA,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAC5B,SAAS,eAAe;AAkCf;AA1BF,IAAM,sBAAsB,CAAC,UAAoC;AACtE,QAAM,EAAE,UAAU,YAAY,aAAa,MAAM,WAAW,iBAAiB,kBAAkB,IAAI;AACnG,QAAM,EAAE,OAAO,IAAI,UAAU;AAC7B,QAAM,EAAE,aAAa,IAAI,YAAY;AAErC,QAAM,QAAQ;AAAA,IACZ,CAAC,YAAyB;AACxB,aAAO,OAAO,eAAe;AAAA,QAC3B,MAAM;AAAA,QACN,OAAO;AAAA,UACL;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA,mBAAmB,oBACf,CAAC,IAAI,cAAc,YAAY,aAAa,IAAI,kBAAkB,cAAc,OAAO,CAAC,IACxF;AAAA,QACN;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAAA,IACA,CAAC,UAAU,YAAY,aAAa,MAAM,iBAAiB,WAAW,mBAAmB,QAAQ,YAAY;AAAA,EAC/G;AAEA,SAAO,oBAAC,WAAQ,OAAc;AAChC;","names":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { SubscriptionLocalization } from '@novu/js/ui';
|
|
3
|
+
import React__default from 'react';
|
|
4
|
+
import { ReactSubscriptionAppearance } from '../../utils/types.js';
|
|
5
|
+
import { NovuUIOptions } from '../NovuUI.js';
|
|
6
|
+
import { DefaultSubscriptionProps } from './DefaultSubscription.js';
|
|
7
|
+
import '@novu/js';
|
|
8
|
+
|
|
9
|
+
type BaseSubscriptionProps = {
|
|
10
|
+
localization?: SubscriptionLocalization;
|
|
11
|
+
appearance?: ReactSubscriptionAppearance;
|
|
12
|
+
} & Pick<NovuUIOptions, 'container'>;
|
|
13
|
+
type SubscriptionPropsWithChildren = {
|
|
14
|
+
children?: React__default.ReactNode;
|
|
15
|
+
} & Exclude<DefaultSubscriptionProps, 'renderPreferences'> & BaseSubscriptionProps;
|
|
16
|
+
type SubscriptionPropsWithoutChildren = {
|
|
17
|
+
children?: never;
|
|
18
|
+
} & DefaultSubscriptionProps & BaseSubscriptionProps;
|
|
19
|
+
type SubscriptionProps = SubscriptionPropsWithChildren | SubscriptionPropsWithoutChildren;
|
|
20
|
+
declare const Subscription: React__default.MemoExoticComponent<(props: SubscriptionProps) => react_jsx_runtime.JSX.Element>;
|
|
21
|
+
|
|
22
|
+
export { Subscription, type SubscriptionProps };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// src/components/subscription/Subscription.tsx
|
|
2
|
+
import React, { useMemo } from "react";
|
|
3
|
+
import { useNovu } from "../../hooks/NovuProvider.js";
|
|
4
|
+
import { NovuUI } from "../NovuUI.js";
|
|
5
|
+
import { withRenderer } from "../Renderer.js";
|
|
6
|
+
import { DefaultSubscription } from "./DefaultSubscription.js";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
var SubscriptionInternal = withRenderer((props) => {
|
|
9
|
+
const { container, localization, appearance, ...defaultSubscriptionProps } = props;
|
|
10
|
+
const novu = useNovu();
|
|
11
|
+
const options = useMemo(() => {
|
|
12
|
+
return {
|
|
13
|
+
container,
|
|
14
|
+
localization,
|
|
15
|
+
appearance,
|
|
16
|
+
options: novu.options
|
|
17
|
+
};
|
|
18
|
+
}, [localization, appearance, container, novu.options]);
|
|
19
|
+
if (isWithChildrenProps(props)) {
|
|
20
|
+
const clonedChildren = React.Children.map(props.children, (child) => {
|
|
21
|
+
if (React.isValidElement(child)) {
|
|
22
|
+
return React.cloneElement(child, {
|
|
23
|
+
...child.props,
|
|
24
|
+
topicKey: defaultSubscriptionProps.topicKey,
|
|
25
|
+
identifier: defaultSubscriptionProps.identifier,
|
|
26
|
+
preferences: defaultSubscriptionProps.preferences
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return child;
|
|
30
|
+
});
|
|
31
|
+
return /* @__PURE__ */ jsx(NovuUI, { options, novu, children: clonedChildren });
|
|
32
|
+
}
|
|
33
|
+
return /* @__PURE__ */ jsx(NovuUI, { options, novu, children: /* @__PURE__ */ jsx(DefaultSubscription, { ...defaultSubscriptionProps }) });
|
|
34
|
+
});
|
|
35
|
+
SubscriptionInternal.displayName = "SubscriptionInternal";
|
|
36
|
+
var Subscription = React.memo((props) => {
|
|
37
|
+
return /* @__PURE__ */ jsx(SubscriptionInternal, { ...props });
|
|
38
|
+
});
|
|
39
|
+
function isWithChildrenProps(props) {
|
|
40
|
+
return "children" in props;
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
Subscription
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=Subscription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/subscription/Subscription.tsx"],"sourcesContent":["import { SubscriptionLocalization } from '@novu/js/ui';\nimport React, { useMemo } from 'react';\nimport { useNovu } from '../../hooks/NovuProvider';\nimport { ReactSubscriptionAppearance } from '../../utils/types';\nimport { NovuUI, NovuUIOptions } from '../NovuUI';\nimport { withRenderer } from '../Renderer';\nimport { DefaultSubscription, DefaultSubscriptionProps } from './DefaultSubscription';\n\ntype BaseSubscriptionProps = {\n localization?: SubscriptionLocalization;\n appearance?: ReactSubscriptionAppearance;\n} & Pick<NovuUIOptions, 'container'>;\n\ntype SubscriptionPropsWithChildren = {\n children?: React.ReactNode;\n} & Exclude<DefaultSubscriptionProps, 'renderPreferences'> &\n BaseSubscriptionProps;\n\ntype SubscriptionPropsWithoutChildren = {\n children?: never;\n} & DefaultSubscriptionProps &\n BaseSubscriptionProps;\n\nexport type SubscriptionProps = SubscriptionPropsWithChildren | SubscriptionPropsWithoutChildren;\n\nconst SubscriptionInternal = withRenderer<SubscriptionProps>((props) => {\n const { container, localization, appearance, ...defaultSubscriptionProps } = props;\n const novu = useNovu();\n\n const options: NovuUIOptions = useMemo(() => {\n return {\n container,\n localization,\n appearance,\n options: novu.options,\n };\n }, [localization, appearance, container, novu.options]);\n\n if (isWithChildrenProps(props)) {\n const clonedChildren = React.Children.map(props.children, (child) => {\n if (React.isValidElement(child)) {\n return React.cloneElement(child, {\n ...child.props,\n topicKey: defaultSubscriptionProps.topicKey,\n identifier: defaultSubscriptionProps.identifier,\n preferences: defaultSubscriptionProps.preferences,\n });\n }\n\n return child;\n });\n\n return (\n <NovuUI options={options} novu={novu}>\n {clonedChildren}\n </NovuUI>\n );\n }\n\n return (\n <NovuUI options={options} novu={novu}>\n <DefaultSubscription {...defaultSubscriptionProps} />\n </NovuUI>\n );\n});\n\nSubscriptionInternal.displayName = 'SubscriptionInternal';\n\nexport const Subscription = React.memo((props: SubscriptionProps) => {\n return <SubscriptionInternal {...props} />;\n});\n\nfunction isWithChildrenProps(props: SubscriptionProps): props is SubscriptionPropsWithChildren {\n return 'children' in props;\n}\n"],"mappings":";AACA,OAAO,SAAS,eAAe;AAC/B,SAAS,eAAe;AAExB,SAAS,cAA6B;AACtC,SAAS,oBAAoB;AAC7B,SAAS,2BAAqD;AA+CxD;AA5BN,IAAM,uBAAuB,aAAgC,CAAC,UAAU;AACtE,QAAM,EAAE,WAAW,cAAc,YAAY,GAAG,yBAAyB,IAAI;AAC7E,QAAM,OAAO,QAAQ;AAErB,QAAM,UAAyB,QAAQ,MAAM;AAC3C,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA,SAAS,KAAK;AAAA,IAChB;AAAA,EACF,GAAG,CAAC,cAAc,YAAY,WAAW,KAAK,OAAO,CAAC;AAEtD,MAAI,oBAAoB,KAAK,GAAG;AAC9B,UAAM,iBAAiB,MAAM,SAAS,IAAI,MAAM,UAAU,CAAC,UAAU;AACnE,UAAI,MAAM,eAAe,KAAK,GAAG;AAC/B,eAAO,MAAM,aAAa,OAAO;AAAA,UAC/B,GAAG,MAAM;AAAA,UACT,UAAU,yBAAyB;AAAA,UACnC,YAAY,yBAAyB;AAAA,UACrC,aAAa,yBAAyB;AAAA,QACxC,CAAC;AAAA,MACH;AAEA,aAAO;AAAA,IACT,CAAC;AAED,WACE,oBAAC,UAAO,SAAkB,MACvB,0BACH;AAAA,EAEJ;AAEA,SACE,oBAAC,UAAO,SAAkB,MACxB,8BAAC,uBAAqB,GAAG,0BAA0B,GACrD;AAEJ,CAAC;AAED,qBAAqB,cAAc;AAE5B,IAAM,eAAe,MAAM,KAAK,CAAC,UAA6B;AACnE,SAAO,oBAAC,wBAAsB,GAAG,OAAO;AAC1C,CAAC;AAED,SAAS,oBAAoB,OAAkE;AAC7F,SAAO,cAAc;AACvB;","names":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { SubscriptionButtonWrapperProps } from '@novu/js/ui';
|
|
3
|
+
import React__default from 'react';
|
|
4
|
+
|
|
5
|
+
type SubscriptionButtonProps = Partial<SubscriptionButtonWrapperProps>;
|
|
6
|
+
declare const SubscriptionButton: React__default.MemoExoticComponent<({ topicKey, identifier, preferences, onClick, onDeleteError, onDeleteSuccess, onCreateError, onCreateSuccess, }: SubscriptionButtonProps) => react_jsx_runtime.JSX.Element>;
|
|
7
|
+
|
|
8
|
+
export { SubscriptionButton, type SubscriptionButtonProps };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/components/subscription/SubscriptionButton.tsx
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { useNovuUI } from "../../context/NovuUIContext.js";
|
|
4
|
+
import { Mounter } from "../Mounter.js";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
var SubscriptionButton = React.memo(
|
|
7
|
+
({
|
|
8
|
+
topicKey,
|
|
9
|
+
identifier,
|
|
10
|
+
preferences,
|
|
11
|
+
onClick,
|
|
12
|
+
onDeleteError,
|
|
13
|
+
onDeleteSuccess,
|
|
14
|
+
onCreateError,
|
|
15
|
+
onCreateSuccess
|
|
16
|
+
}) => {
|
|
17
|
+
const { novuUI } = useNovuUI();
|
|
18
|
+
const mount = React.useCallback(
|
|
19
|
+
(element) => {
|
|
20
|
+
if (!topicKey || !preferences) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
return novuUI.mountComponent({
|
|
24
|
+
name: "SubscriptionButton",
|
|
25
|
+
element,
|
|
26
|
+
props: {
|
|
27
|
+
topicKey,
|
|
28
|
+
identifier,
|
|
29
|
+
preferences,
|
|
30
|
+
onClick,
|
|
31
|
+
onDeleteError,
|
|
32
|
+
onDeleteSuccess,
|
|
33
|
+
onCreateError,
|
|
34
|
+
onCreateSuccess
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
[
|
|
39
|
+
novuUI,
|
|
40
|
+
topicKey,
|
|
41
|
+
identifier,
|
|
42
|
+
preferences,
|
|
43
|
+
onClick,
|
|
44
|
+
onDeleteError,
|
|
45
|
+
onDeleteSuccess,
|
|
46
|
+
onCreateError,
|
|
47
|
+
onCreateSuccess
|
|
48
|
+
]
|
|
49
|
+
);
|
|
50
|
+
return /* @__PURE__ */ jsx(Mounter, { mount });
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
export {
|
|
54
|
+
SubscriptionButton
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=SubscriptionButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/subscription/SubscriptionButton.tsx"],"sourcesContent":["import type { SubscriptionButtonWrapperProps } from '@novu/js/ui';\nimport React from 'react';\nimport { useNovuUI } from '../../context/NovuUIContext';\nimport { Mounter } from '../Mounter';\n\nexport type SubscriptionButtonProps = Partial<SubscriptionButtonWrapperProps>;\n\nexport const SubscriptionButton = React.memo(\n ({\n topicKey,\n identifier,\n preferences,\n onClick,\n onDeleteError,\n onDeleteSuccess,\n onCreateError,\n onCreateSuccess,\n }: SubscriptionButtonProps) => {\n const { novuUI } = useNovuUI();\n\n const mount = React.useCallback(\n (element: HTMLElement) => {\n if (!topicKey || !preferences) {\n return;\n }\n\n return novuUI.mountComponent({\n name: 'SubscriptionButton',\n element,\n props: {\n topicKey,\n identifier,\n preferences,\n onClick,\n onDeleteError,\n onDeleteSuccess,\n onCreateError,\n onCreateSuccess,\n },\n });\n },\n [\n novuUI,\n topicKey,\n identifier,\n preferences,\n onClick,\n onDeleteError,\n onDeleteSuccess,\n onCreateError,\n onCreateSuccess,\n ]\n );\n\n return <Mounter mount={mount} />;\n }\n);\n"],"mappings":";AACA,OAAO,WAAW;AAClB,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AAmDb;AA/CJ,IAAM,qBAAqB,MAAM;AAAA,EACtC,CAAC;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,MAA+B;AAC7B,UAAM,EAAE,OAAO,IAAI,UAAU;AAE7B,UAAM,QAAQ,MAAM;AAAA,MAClB,CAAC,YAAyB;AACxB,YAAI,CAAC,YAAY,CAAC,aAAa;AAC7B;AAAA,QACF;AAEA,eAAO,OAAO,eAAe;AAAA,UAC3B,MAAM;AAAA,UACN;AAAA,UACA,OAAO;AAAA,YACL;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH;AAAA,MACA;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,oBAAC,WAAQ,OAAc;AAAA,EAChC;AACF;","names":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { SubscriptionPreferencesWrapperProps } from '@novu/js/ui';
|
|
3
|
+
import React__default from 'react';
|
|
4
|
+
|
|
5
|
+
type SubscriptionPreferencesProps = Partial<SubscriptionPreferencesWrapperProps>;
|
|
6
|
+
declare const SubscriptionPreferences: React__default.MemoExoticComponent<({ topicKey, identifier, preferences, onClick, onDeleteError, onDeleteSuccess, onCreateError, onCreateSuccess, }: SubscriptionPreferencesProps) => react_jsx_runtime.JSX.Element>;
|
|
7
|
+
|
|
8
|
+
export { SubscriptionPreferences, type SubscriptionPreferencesProps };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/components/subscription/SubscriptionPreferences.tsx
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { useNovuUI } from "../../context/NovuUIContext.js";
|
|
4
|
+
import { Mounter } from "../Mounter.js";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
var SubscriptionPreferences = React.memo(
|
|
7
|
+
({
|
|
8
|
+
topicKey,
|
|
9
|
+
identifier,
|
|
10
|
+
preferences,
|
|
11
|
+
onClick,
|
|
12
|
+
onDeleteError,
|
|
13
|
+
onDeleteSuccess,
|
|
14
|
+
onCreateError,
|
|
15
|
+
onCreateSuccess
|
|
16
|
+
}) => {
|
|
17
|
+
const { novuUI } = useNovuUI();
|
|
18
|
+
const mount = React.useCallback(
|
|
19
|
+
(element) => {
|
|
20
|
+
if (!topicKey || !preferences) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
return novuUI.mountComponent({
|
|
24
|
+
name: "SubscriptionPreferences",
|
|
25
|
+
element,
|
|
26
|
+
props: {
|
|
27
|
+
topicKey,
|
|
28
|
+
identifier,
|
|
29
|
+
preferences,
|
|
30
|
+
onClick,
|
|
31
|
+
onDeleteError,
|
|
32
|
+
onDeleteSuccess,
|
|
33
|
+
onCreateError,
|
|
34
|
+
onCreateSuccess
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
[
|
|
39
|
+
novuUI,
|
|
40
|
+
topicKey,
|
|
41
|
+
identifier,
|
|
42
|
+
preferences,
|
|
43
|
+
onClick,
|
|
44
|
+
onDeleteError,
|
|
45
|
+
onDeleteSuccess,
|
|
46
|
+
onCreateError,
|
|
47
|
+
onCreateSuccess
|
|
48
|
+
]
|
|
49
|
+
);
|
|
50
|
+
return /* @__PURE__ */ jsx(Mounter, { mount });
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
export {
|
|
54
|
+
SubscriptionPreferences
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=SubscriptionPreferences.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/subscription/SubscriptionPreferences.tsx"],"sourcesContent":["import type { SubscriptionPreferencesWrapperProps } from '@novu/js/ui';\nimport React from 'react';\nimport { useNovuUI } from '../../context/NovuUIContext';\nimport { Mounter } from '../Mounter';\n\nexport type SubscriptionPreferencesProps = Partial<SubscriptionPreferencesWrapperProps>;\n\nexport const SubscriptionPreferences = React.memo(\n ({\n topicKey,\n identifier,\n preferences,\n onClick,\n onDeleteError,\n onDeleteSuccess,\n onCreateError,\n onCreateSuccess,\n }: SubscriptionPreferencesProps) => {\n const { novuUI } = useNovuUI();\n\n const mount = React.useCallback(\n (element: HTMLElement) => {\n if (!topicKey || !preferences) {\n return;\n }\n\n return novuUI.mountComponent({\n name: 'SubscriptionPreferences',\n element,\n props: {\n topicKey,\n identifier,\n preferences,\n onClick,\n onDeleteError,\n onDeleteSuccess,\n onCreateError,\n onCreateSuccess,\n },\n });\n },\n [\n novuUI,\n topicKey,\n identifier,\n preferences,\n onClick,\n onDeleteError,\n onDeleteSuccess,\n onCreateError,\n onCreateSuccess,\n ]\n );\n\n return <Mounter mount={mount} />;\n }\n);\n"],"mappings":";AACA,OAAO,WAAW;AAClB,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AAmDb;AA/CJ,IAAM,0BAA0B,MAAM;AAAA,EAC3C,CAAC;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,MAAoC;AAClC,UAAM,EAAE,OAAO,IAAI,UAAU;AAE7B,UAAM,QAAQ,MAAM;AAAA,MAClB,CAAC,YAAyB;AACxB,YAAI,CAAC,YAAY,CAAC,aAAa;AAC7B;AAAA,QACF;AAEA,eAAO,OAAO,eAAe;AAAA,UAC3B,MAAM;AAAA,UACN;AAAA,UACA,OAAO;AAAA,YACL;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH;AAAA,MACA;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,oBAAC,WAAQ,OAAc;AAAA,EAChC;AACF;","names":[]}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
// src/hooks/NovuProvider.tsx
|
|
2
2
|
import { Novu } from "@novu/js";
|
|
3
3
|
import { buildSubscriber } from "@novu/js/internal";
|
|
4
|
-
import { createContext, useContext,
|
|
4
|
+
import { createContext, useContext, useMemo } from "react";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
|
-
var version = "3.
|
|
6
|
+
var version = "3.12.0-rc.1";
|
|
7
7
|
var name = "@novu/react";
|
|
8
8
|
var baseUserAgent = `${name}@${version}`;
|
|
9
9
|
var NovuContext = createContext(void 0);
|
|
10
10
|
var NovuProvider = (props) => {
|
|
11
11
|
const { subscriberId, ...propsWithoutSubscriberId } = props;
|
|
12
|
-
const subscriberObj =
|
|
12
|
+
const subscriberObj = useMemo(
|
|
13
|
+
() => buildSubscriber({ subscriberId, subscriber: props.subscriber }),
|
|
14
|
+
[subscriberId, props.subscriber]
|
|
15
|
+
);
|
|
13
16
|
const applicationIdentifier = propsWithoutSubscriberId.applicationIdentifier ? propsWithoutSubscriberId.applicationIdentifier : "";
|
|
14
17
|
const providerProps = {
|
|
15
18
|
...propsWithoutSubscriberId,
|
|
@@ -20,7 +23,10 @@ var NovuProvider = (props) => {
|
|
|
20
23
|
};
|
|
21
24
|
var InternalNovuProvider = (props) => {
|
|
22
25
|
const applicationIdentifier = props.applicationIdentifier || "";
|
|
23
|
-
const subscriberObj =
|
|
26
|
+
const subscriberObj = useMemo(
|
|
27
|
+
() => buildSubscriber({ subscriberId: props.subscriberId, subscriber: props.subscriber }),
|
|
28
|
+
[props.subscriberId, props.subscriber]
|
|
29
|
+
);
|
|
24
30
|
const {
|
|
25
31
|
children,
|
|
26
32
|
subscriberHash,
|
|
@@ -47,22 +53,19 @@ var InternalNovuProvider = (props) => {
|
|
|
47
53
|
defaultSchedule,
|
|
48
54
|
context
|
|
49
55
|
}),
|
|
50
|
-
[
|
|
56
|
+
[
|
|
57
|
+
applicationIdentifier,
|
|
58
|
+
subscriberHash,
|
|
59
|
+
subscriberObj,
|
|
60
|
+
context,
|
|
61
|
+
contextHash,
|
|
62
|
+
backendUrl,
|
|
63
|
+
apiUrl,
|
|
64
|
+
socketUrl,
|
|
65
|
+
useCache,
|
|
66
|
+
userAgentType
|
|
67
|
+
]
|
|
51
68
|
);
|
|
52
|
-
useEffect(() => {
|
|
53
|
-
novu.changeSubscriber({
|
|
54
|
-
subscriber: subscriberObj,
|
|
55
|
-
subscriberHash: props.subscriberHash
|
|
56
|
-
});
|
|
57
|
-
}, [subscriberObj.subscriberId, props.subscriberHash, novu]);
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
if (context && contextHash) {
|
|
60
|
-
novu.changeContext({
|
|
61
|
-
context,
|
|
62
|
-
contextHash
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}, [context, contextHash, novu]);
|
|
66
69
|
return /* @__PURE__ */ jsx(NovuContext.Provider, { value: novu, children });
|
|
67
70
|
};
|
|
68
71
|
var useNovu = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/hooks/NovuProvider.tsx"],"sourcesContent":["import { Novu, NovuOptions } from '@novu/js';\nimport { buildSubscriber } from '@novu/js/internal';\nimport { createContext, ReactNode, useContext,
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/NovuProvider.tsx"],"sourcesContent":["import { Novu, NovuOptions } from '@novu/js';\nimport { buildSubscriber } from '@novu/js/internal';\nimport { createContext, ReactNode, useContext, useMemo } from 'react';\n\n// @ts-expect-error\nconst version = PACKAGE_VERSION;\n// @ts-expect-error\nconst name = PACKAGE_NAME;\nconst baseUserAgent = `${name}@${version}`;\n\nexport type NovuProviderProps = NovuOptions & {\n children: ReactNode;\n};\n\nconst NovuContext = createContext<Novu | undefined>(undefined);\n\nexport const NovuProvider = (props: NovuProviderProps) => {\n const { subscriberId, ...propsWithoutSubscriberId } = props;\n const subscriberObj = useMemo(\n () => buildSubscriber({ subscriberId, subscriber: props.subscriber }),\n [subscriberId, props.subscriber]\n );\n const applicationIdentifier = propsWithoutSubscriberId.applicationIdentifier\n ? propsWithoutSubscriberId.applicationIdentifier\n : '';\n\n const providerProps: NovuProviderProps = {\n ...propsWithoutSubscriberId,\n applicationIdentifier,\n subscriber: subscriberObj,\n };\n\n return (\n <InternalNovuProvider {...providerProps} applicationIdentifier={applicationIdentifier} userAgentType=\"hooks\">\n {props.children}\n </InternalNovuProvider>\n );\n};\n\n/**\n * @internal Should be used internally not to be exposed outside of the library\n * This is needed to differentiate between the hooks and components user agents\n * Better to use this internally to avoid confusion.\n */\nexport const InternalNovuProvider = (props: NovuProviderProps & { userAgentType: 'components' | 'hooks' }) => {\n const applicationIdentifier = props.applicationIdentifier || '';\n const subscriberObj = useMemo(\n () => buildSubscriber({ subscriberId: props.subscriberId, subscriber: props.subscriber }),\n [props.subscriberId, props.subscriber]\n );\n\n const {\n children,\n subscriberHash,\n contextHash,\n backendUrl,\n apiUrl,\n socketUrl,\n useCache,\n userAgentType,\n defaultSchedule,\n context,\n } = props;\n\n const novu = useMemo(\n () =>\n new Novu({\n applicationIdentifier,\n subscriberHash,\n contextHash,\n backendUrl,\n apiUrl,\n socketUrl,\n useCache,\n __userAgent: `${baseUserAgent} ${userAgentType}`,\n subscriber: subscriberObj,\n defaultSchedule,\n context,\n }),\n [\n applicationIdentifier,\n subscriberHash,\n subscriberObj,\n context,\n contextHash,\n backendUrl,\n apiUrl,\n socketUrl,\n useCache,\n userAgentType,\n ]\n );\n\n return <NovuContext.Provider value={novu}>{children}</NovuContext.Provider>;\n};\n\nexport const useNovu = () => {\n const context = useContext(NovuContext);\n if (!context) {\n throw new Error('useNovu must be used within a <NovuProvider />');\n }\n\n return context;\n};\n\nexport const useUnsafeNovu = () => {\n const context = useContext(NovuContext);\n\n return context;\n};\n"],"mappings":";AAAA,SAAS,YAAyB;AAClC,SAAS,uBAAuB;AAChC,SAAS,eAA0B,YAAY,eAAe;AA+B1D;AA5BJ,IAAM,UAAU;AAEhB,IAAM,OAAO;AACb,IAAM,gBAAgB,GAAG,IAAI,IAAI,OAAO;AAMxC,IAAM,cAAc,cAAgC,MAAS;AAEtD,IAAM,eAAe,CAAC,UAA6B;AACxD,QAAM,EAAE,cAAc,GAAG,yBA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