@novu/react 2.3.1 → 2.4.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/client/index.d.mts +9 -1
- package/dist/client/index.d.ts +9 -1
- package/dist/client/index.js +42 -5
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +40 -3
- package/dist/client/index.mjs.map +1 -1
- package/dist/hooks/index.js +39 -4
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +37 -2
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/server/server.js +39 -4
- package/dist/server/server.js.map +1 -1
- package/dist/server/server.mjs +37 -2
- package/dist/server/server.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/index.d.mts +0 -34
- package/dist/index.d.ts +0 -34
- package/dist/index.js +0 -167
- package/dist/index.mjs +0 -157
package/dist/index.mjs
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import React5 from 'react';
|
|
2
|
-
import ReactDOM from 'react-dom';
|
|
3
|
-
|
|
4
|
-
// src/components/Bell.tsx
|
|
5
|
-
function assertContextExists(contextVal, msgOrCtx) {
|
|
6
|
-
if (!contextVal) {
|
|
7
|
-
throw typeof msgOrCtx === "string" ? new Error(msgOrCtx) : new Error(`${msgOrCtx.displayName} not found`);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
var createContextAndHook = (displayName, options) => {
|
|
11
|
-
const { assertCtxFn = assertContextExists } = {};
|
|
12
|
-
const Ctx = React5.createContext(void 0);
|
|
13
|
-
Ctx.displayName = displayName;
|
|
14
|
-
const useCtx = () => {
|
|
15
|
-
const ctx = React5.useContext(Ctx);
|
|
16
|
-
assertCtxFn(ctx, `${displayName} not found`);
|
|
17
|
-
return ctx.value;
|
|
18
|
-
};
|
|
19
|
-
const useCtxWithoutGuarantee = () => {
|
|
20
|
-
const ctx = React5.useContext(Ctx);
|
|
21
|
-
return ctx ? ctx.value : {};
|
|
22
|
-
};
|
|
23
|
-
return [Ctx, useCtx, useCtxWithoutGuarantee];
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// src/context/RenderContext.tsx
|
|
27
|
-
var [RendererContext, useRendererContext] = createContextAndHook("RendererContext");
|
|
28
|
-
var RendererProvider = (props) => {
|
|
29
|
-
return /* @__PURE__ */ React5.createElement(RendererContext.Provider, { value: { value: props.value } }, props.children);
|
|
30
|
-
};
|
|
31
|
-
function Mounter({ mount }) {
|
|
32
|
-
const ref = React5.useRef(null);
|
|
33
|
-
React5.useEffect(() => {
|
|
34
|
-
let unmount;
|
|
35
|
-
const element = ref.current;
|
|
36
|
-
if (element && mount) {
|
|
37
|
-
const possibleUnmount = mount(element);
|
|
38
|
-
if (possibleUnmount) {
|
|
39
|
-
unmount = possibleUnmount;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return () => {
|
|
43
|
-
if (element && unmount) {
|
|
44
|
-
unmount(element);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
}, [ref, mount]);
|
|
48
|
-
return /* @__PURE__ */ React5.createElement("div", { ref });
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// src/components/Bell.tsx
|
|
52
|
-
var Bell = (props) => {
|
|
53
|
-
const { novuUI, mountElement } = useRendererContext();
|
|
54
|
-
const mount = React5.useCallback((element) => {
|
|
55
|
-
return novuUI.mountComponent({
|
|
56
|
-
name: "Bell",
|
|
57
|
-
element,
|
|
58
|
-
props: props.children ? { mountBell: (el, { unreadCount }) => mountElement(el, props.children?.({ unreadCount })) } : void 0
|
|
59
|
-
});
|
|
60
|
-
}, []);
|
|
61
|
-
return /* @__PURE__ */ React5.createElement(Mounter, { mount });
|
|
62
|
-
};
|
|
63
|
-
var Renderer = (props) => {
|
|
64
|
-
const { options, children } = props;
|
|
65
|
-
const [novuUI, setNovuUI] = React5.useState();
|
|
66
|
-
const [mountedElements, setMountedElements] = React5.useState(/* @__PURE__ */ new Map());
|
|
67
|
-
const mountElement = React5.useCallback(
|
|
68
|
-
(el, mountedElement) => {
|
|
69
|
-
setMountedElements((prev) => {
|
|
70
|
-
const newMountedElements = new Map(prev);
|
|
71
|
-
newMountedElements.set(el, mountedElement);
|
|
72
|
-
return newMountedElements;
|
|
73
|
-
});
|
|
74
|
-
return () => {
|
|
75
|
-
setMountedElements((prev) => {
|
|
76
|
-
const newMountedElements = new Map(prev);
|
|
77
|
-
newMountedElements.delete(el);
|
|
78
|
-
return newMountedElements;
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
},
|
|
82
|
-
[setMountedElements]
|
|
83
|
-
);
|
|
84
|
-
React5.useEffect(() => {
|
|
85
|
-
const loadNovuUI = async () => {
|
|
86
|
-
const { NovuUI } = await import('@novu/js/ui');
|
|
87
|
-
const ui = new NovuUI(options);
|
|
88
|
-
setNovuUI(ui);
|
|
89
|
-
};
|
|
90
|
-
loadNovuUI();
|
|
91
|
-
}, [options]);
|
|
92
|
-
if (!novuUI) {
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
return /* @__PURE__ */ React5.createElement(RendererProvider, { value: { mountElement, novuUI } }, [...mountedElements].map(([element, mountedElement]) => {
|
|
96
|
-
return ReactDOM.createPortal(mountedElement, element);
|
|
97
|
-
}), children);
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
// src/components/Inbox.tsx
|
|
101
|
-
var InboxDefault = (props) => {
|
|
102
|
-
const { renderNotification, renderBell, ...rest } = props;
|
|
103
|
-
const { novuUI, mountElement } = useRendererContext();
|
|
104
|
-
const mount = React5.useCallback(
|
|
105
|
-
(element) => {
|
|
106
|
-
return novuUI.mountComponent({
|
|
107
|
-
name: "Inbox",
|
|
108
|
-
props: {
|
|
109
|
-
...rest,
|
|
110
|
-
mountNotification: renderNotification ? (el, { notification }) => {
|
|
111
|
-
return mountElement(el, renderNotification(notification));
|
|
112
|
-
} : void 0,
|
|
113
|
-
mountBell: renderBell ? (el, { unreadCount }) => {
|
|
114
|
-
return mountElement(el, renderBell({ unreadCount }));
|
|
115
|
-
} : void 0
|
|
116
|
-
},
|
|
117
|
-
element
|
|
118
|
-
});
|
|
119
|
-
},
|
|
120
|
-
[renderNotification]
|
|
121
|
-
);
|
|
122
|
-
return /* @__PURE__ */ React5.createElement(Mounter, { mount });
|
|
123
|
-
};
|
|
124
|
-
var Inbox = (props) => {
|
|
125
|
-
if ("children" in props) {
|
|
126
|
-
const { children, ...options2 } = props;
|
|
127
|
-
return /* @__PURE__ */ React5.createElement(Renderer, { options: options2 }, children);
|
|
128
|
-
}
|
|
129
|
-
const { renderNotification, renderBell, ...options } = props;
|
|
130
|
-
return /* @__PURE__ */ React5.createElement(Renderer, { options }, /* @__PURE__ */ React5.createElement(InboxDefault, { renderNotification, renderBell }));
|
|
131
|
-
};
|
|
132
|
-
var SettingsDefault = () => {
|
|
133
|
-
const { novuUI } = useRendererContext();
|
|
134
|
-
const mount = React5.useCallback((element) => {
|
|
135
|
-
return novuUI.mountComponent({
|
|
136
|
-
name: "Settings",
|
|
137
|
-
element
|
|
138
|
-
});
|
|
139
|
-
}, []);
|
|
140
|
-
return /* @__PURE__ */ React5.createElement(Mounter, { mount });
|
|
141
|
-
};
|
|
142
|
-
var Settings = () => {
|
|
143
|
-
return /* @__PURE__ */ React5.createElement(SettingsDefault, null);
|
|
144
|
-
};
|
|
145
|
-
var Notifications = (props) => {
|
|
146
|
-
const { novuUI, mountElement } = useRendererContext();
|
|
147
|
-
const mount = React5.useCallback((element) => {
|
|
148
|
-
return novuUI.mountComponent({
|
|
149
|
-
name: "NotificationList",
|
|
150
|
-
element,
|
|
151
|
-
props: props.children ? { mountNotification: (el, { notification }) => mountElement(el, props.children?.(notification)) } : void 0
|
|
152
|
-
});
|
|
153
|
-
}, []);
|
|
154
|
-
return /* @__PURE__ */ React5.createElement(Mounter, { mount });
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
export { Bell, Inbox, Notifications, Settings };
|