@novu/react 2.1.2 → 2.3.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 +25 -6
- package/dist/client/index.d.ts +25 -6
- package/dist/client/index.js +232 -155
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +231 -154
- package/dist/client/index.mjs.map +1 -1
- package/dist/hooks/index.d.mts +3 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/index.js +1 -1
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +1 -1
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/server/server.d.mts +5 -1
- package/dist/server/server.d.ts +5 -1
- package/dist/server/server.js +1 -1
- package/dist/server/server.js.map +1 -1
- package/dist/server/server.mjs +1 -1
- package/dist/server/server.mjs.map +1 -1
- package/dist/themes/index.d.mts +1 -0
- package/dist/themes/index.d.ts +1 -0
- package/dist/themes/index.js +21 -0
- package/dist/themes/index.js.map +1 -0
- package/dist/themes/index.mjs +3 -0
- package/dist/themes/index.mjs.map +1 -0
- package/package.json +18 -5
- package/themes/package.json +5 -0
package/dist/client/index.js
CHANGED
|
@@ -32,7 +32,7 @@ var src_exports = {};
|
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
Bell: () => Bell,
|
|
34
34
|
Inbox: () => Inbox,
|
|
35
|
-
|
|
35
|
+
InboxContent: () => InboxContent,
|
|
36
36
|
Notifications: () => Notifications,
|
|
37
37
|
NovuProvider: () => NovuProvider,
|
|
38
38
|
Preferences: () => Preferences,
|
|
@@ -45,10 +45,36 @@ __export(src_exports, {
|
|
|
45
45
|
module.exports = __toCommonJS(src_exports);
|
|
46
46
|
|
|
47
47
|
// src/components/Bell.tsx
|
|
48
|
-
var
|
|
48
|
+
var import_react4 = __toESM(require("react"));
|
|
49
|
+
|
|
50
|
+
// src/components/Mounter.tsx
|
|
51
|
+
var import_react = require("react");
|
|
52
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
53
|
+
function Mounter({ mount }) {
|
|
54
|
+
const ref = (0, import_react.useRef)(null);
|
|
55
|
+
(0, import_react.useEffect)(() => {
|
|
56
|
+
let unmount;
|
|
57
|
+
const element = ref.current;
|
|
58
|
+
if (element && mount) {
|
|
59
|
+
const possibleUnmount = mount(element);
|
|
60
|
+
if (possibleUnmount) {
|
|
61
|
+
unmount = possibleUnmount;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return () => {
|
|
65
|
+
if (element && unmount) {
|
|
66
|
+
unmount(element);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}, [ref, mount]);
|
|
70
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/components/Renderer.tsx
|
|
74
|
+
var import_react3 = require("react");
|
|
49
75
|
|
|
50
76
|
// src/utils/createContextAndHook.ts
|
|
51
|
-
var
|
|
77
|
+
var import_react2 = __toESM(require("react"));
|
|
52
78
|
function assertContextExists(contextVal, msgOrCtx) {
|
|
53
79
|
if (!contextVal) {
|
|
54
80
|
throw typeof msgOrCtx === "string" ? new Error(msgOrCtx) : new Error(`${msgOrCtx.displayName} not found`);
|
|
@@ -56,56 +82,79 @@ function assertContextExists(contextVal, msgOrCtx) {
|
|
|
56
82
|
}
|
|
57
83
|
var createContextAndHook = (displayName, options) => {
|
|
58
84
|
const { assertCtxFn = assertContextExists } = options || {};
|
|
59
|
-
const Ctx =
|
|
85
|
+
const Ctx = import_react2.default.createContext(void 0);
|
|
60
86
|
Ctx.displayName = displayName;
|
|
61
87
|
const useCtx = () => {
|
|
62
|
-
const ctx =
|
|
63
|
-
assertCtxFn(ctx, `Component must be wrapped with
|
|
88
|
+
const ctx = import_react2.default.useContext(Ctx);
|
|
89
|
+
assertCtxFn(ctx, `Component must be wrapped with ${Ctx.displayName}`);
|
|
64
90
|
return ctx.value;
|
|
65
91
|
};
|
|
66
92
|
const useCtxWithoutGuarantee = () => {
|
|
67
|
-
const ctx =
|
|
93
|
+
const ctx = import_react2.default.useContext(Ctx);
|
|
68
94
|
return ctx ? ctx.value : {};
|
|
69
95
|
};
|
|
70
96
|
return [Ctx, useCtx, useCtxWithoutGuarantee];
|
|
71
97
|
};
|
|
72
98
|
|
|
73
|
-
// src/context/
|
|
74
|
-
var
|
|
75
|
-
var [RendererContext, useRendererContext] = createContextAndHook("RendererContext");
|
|
99
|
+
// src/context/RendererContext.tsx
|
|
100
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
101
|
+
var [RendererContext, useRendererContext, useUnsafeRendererContext] = createContextAndHook("RendererContext");
|
|
76
102
|
var RendererProvider = (props) => {
|
|
77
|
-
return /* @__PURE__ */ (0,
|
|
103
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RendererContext.Provider, { value: { value: props.value }, children: props.children });
|
|
78
104
|
};
|
|
79
105
|
|
|
80
|
-
// src/components/
|
|
81
|
-
var
|
|
82
|
-
var
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
106
|
+
// src/components/Renderer.tsx
|
|
107
|
+
var import_react_dom = require("react-dom");
|
|
108
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
109
|
+
var Renderer = (props) => {
|
|
110
|
+
const { children } = props;
|
|
111
|
+
const [mountedElements, setMountedElements] = (0, import_react3.useState)(/* @__PURE__ */ new Map());
|
|
112
|
+
const mountElement = (0, import_react3.useCallback)(
|
|
113
|
+
(el, mountedElement) => {
|
|
114
|
+
setMountedElements((prev) => {
|
|
115
|
+
const newMountedElements = new Map(prev);
|
|
116
|
+
newMountedElements.set(el, mountedElement);
|
|
117
|
+
return newMountedElements;
|
|
118
|
+
});
|
|
119
|
+
return () => {
|
|
120
|
+
setMountedElements((prev) => {
|
|
121
|
+
const newMountedElements = new Map(prev);
|
|
122
|
+
newMountedElements.delete(el);
|
|
123
|
+
return newMountedElements;
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
},
|
|
127
|
+
[setMountedElements]
|
|
128
|
+
);
|
|
129
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(RendererProvider, { value: { mountElement }, children: [
|
|
130
|
+
[...mountedElements].map(([element, mountedElement]) => {
|
|
131
|
+
return (0, import_react_dom.createPortal)(mountedElement, element);
|
|
132
|
+
}),
|
|
133
|
+
children
|
|
134
|
+
] });
|
|
135
|
+
};
|
|
136
|
+
var withRenderer = (WrappedComponent) => {
|
|
137
|
+
const HOC = (props) => {
|
|
138
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Renderer, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(WrappedComponent, { ...props }) });
|
|
139
|
+
};
|
|
140
|
+
HOC.displayName = `WithRenderer(${WrappedComponent.displayName || WrappedComponent.name || "Component"})`;
|
|
141
|
+
return HOC;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// src/context/NovuUIContext.tsx
|
|
145
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
146
|
+
var [NovuUIContext, useNovuUIContext, useUnsafeNovuUIContext] = createContextAndHook("NovuUIContext");
|
|
147
|
+
var NovuUIProvider = (props) => {
|
|
148
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(NovuUIContext.Provider, { value: { value: props.value }, children: props.children });
|
|
149
|
+
};
|
|
102
150
|
|
|
103
151
|
// src/components/Bell.tsx
|
|
104
|
-
var
|
|
105
|
-
var
|
|
152
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
153
|
+
var _Bell = import_react4.default.memo((props) => {
|
|
106
154
|
const { renderBell } = props;
|
|
107
|
-
const { novuUI
|
|
108
|
-
const
|
|
155
|
+
const { novuUI } = useNovuUIContext();
|
|
156
|
+
const { mountElement } = useRendererContext();
|
|
157
|
+
const mount = import_react4.default.useCallback(
|
|
109
158
|
(element) => {
|
|
110
159
|
return novuUI.mountComponent({
|
|
111
160
|
name: "Bell",
|
|
@@ -115,56 +164,70 @@ var Bell = import_react3.default.memo((props) => {
|
|
|
115
164
|
},
|
|
116
165
|
[renderBell]
|
|
117
166
|
);
|
|
118
|
-
return /* @__PURE__ */ (0,
|
|
167
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Mounter, { mount });
|
|
119
168
|
});
|
|
169
|
+
var Bell = withRenderer(_Bell);
|
|
120
170
|
|
|
121
171
|
// src/components/Inbox.tsx
|
|
122
|
-
var
|
|
172
|
+
var import_react8 = __toESM(require("react"));
|
|
123
173
|
|
|
124
|
-
// src/
|
|
174
|
+
// src/hooks/NovuProvider.tsx
|
|
175
|
+
var import_js = require("@novu/js");
|
|
125
176
|
var import_react5 = require("react");
|
|
126
|
-
var
|
|
177
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
178
|
+
var NovuContext = (0, import_react5.createContext)(void 0);
|
|
179
|
+
var NovuProvider = ({
|
|
180
|
+
children,
|
|
181
|
+
applicationIdentifier,
|
|
182
|
+
subscriberId,
|
|
183
|
+
subscriberHash,
|
|
184
|
+
backendUrl,
|
|
185
|
+
socketUrl,
|
|
186
|
+
useCache
|
|
187
|
+
}) => {
|
|
188
|
+
const novu = (0, import_react5.useMemo)(
|
|
189
|
+
() => new import_js.Novu({ applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl, useCache }),
|
|
190
|
+
[applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl, useCache]
|
|
191
|
+
);
|
|
192
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(NovuContext.Provider, { value: novu, children });
|
|
193
|
+
};
|
|
194
|
+
var useNovu = () => {
|
|
195
|
+
const context = (0, import_react5.useContext)(NovuContext);
|
|
196
|
+
if (!context) {
|
|
197
|
+
throw new Error("useNovu must be used within a <NovuProvider />");
|
|
198
|
+
}
|
|
199
|
+
return context;
|
|
200
|
+
};
|
|
201
|
+
var useUnsafeNovu = () => {
|
|
202
|
+
const context = (0, import_react5.useContext)(NovuContext);
|
|
203
|
+
return context;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
// src/components/NovuUI.tsx
|
|
127
207
|
var import_ui = require("@novu/js/ui");
|
|
208
|
+
var import_react7 = require("react");
|
|
128
209
|
|
|
129
210
|
// src/hooks/internal/useDataRef.ts
|
|
130
|
-
var
|
|
211
|
+
var import_react6 = require("react");
|
|
131
212
|
var useDataRef = (data) => {
|
|
132
|
-
const ref = (0,
|
|
213
|
+
const ref = (0, import_react6.useRef)(data);
|
|
133
214
|
ref.current = data;
|
|
134
215
|
return ref;
|
|
135
216
|
};
|
|
136
217
|
|
|
137
|
-
// src/components/
|
|
138
|
-
var
|
|
139
|
-
var
|
|
218
|
+
// src/components/NovuUI.tsx
|
|
219
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
220
|
+
var NovuUI = ({ options, novu, children }) => {
|
|
140
221
|
const optionsRef = useDataRef({ ...options, novu });
|
|
141
|
-
const [novuUI, setNovuUI] = (0,
|
|
142
|
-
|
|
143
|
-
const mountElement = (0, import_react5.useCallback)(
|
|
144
|
-
(el, mountedElement) => {
|
|
145
|
-
setMountedElements((prev) => {
|
|
146
|
-
const newMountedElements = new Map(prev);
|
|
147
|
-
newMountedElements.set(el, mountedElement);
|
|
148
|
-
return newMountedElements;
|
|
149
|
-
});
|
|
150
|
-
return () => {
|
|
151
|
-
setMountedElements((prev) => {
|
|
152
|
-
const newMountedElements = new Map(prev);
|
|
153
|
-
newMountedElements.delete(el);
|
|
154
|
-
return newMountedElements;
|
|
155
|
-
});
|
|
156
|
-
};
|
|
157
|
-
},
|
|
158
|
-
[setMountedElements]
|
|
159
|
-
);
|
|
160
|
-
(0, import_react5.useEffect)(() => {
|
|
222
|
+
const [novuUI, setNovuUI] = (0, import_react7.useState)();
|
|
223
|
+
(0, import_react7.useEffect)(() => {
|
|
161
224
|
const novu2 = new import_ui.NovuUI(optionsRef.current);
|
|
162
225
|
setNovuUI(novu2);
|
|
163
226
|
return () => {
|
|
164
227
|
novu2.unmount();
|
|
165
228
|
};
|
|
166
229
|
}, []);
|
|
167
|
-
(0,
|
|
230
|
+
(0, import_react7.useEffect)(() => {
|
|
168
231
|
if (!novuUI) {
|
|
169
232
|
return;
|
|
170
233
|
}
|
|
@@ -177,20 +240,16 @@ var Renderer = ({ options, novu, children }) => {
|
|
|
177
240
|
if (!novuUI) {
|
|
178
241
|
return null;
|
|
179
242
|
}
|
|
180
|
-
return /* @__PURE__ */ (0,
|
|
181
|
-
[...mountedElements].map(([element, mountedElement]) => {
|
|
182
|
-
return import_react_dom.default.createPortal(mountedElement, element);
|
|
183
|
-
}),
|
|
184
|
-
children
|
|
185
|
-
] });
|
|
243
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(NovuUIProvider, { value: { novuUI }, children });
|
|
186
244
|
};
|
|
187
245
|
|
|
188
246
|
// src/components/Inbox.tsx
|
|
189
|
-
var
|
|
190
|
-
var
|
|
247
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
248
|
+
var _DefaultInbox = (props) => {
|
|
191
249
|
const { open, renderNotification, renderBell, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick } = props;
|
|
192
|
-
const { novuUI
|
|
193
|
-
const
|
|
250
|
+
const { novuUI } = useNovuUIContext();
|
|
251
|
+
const { mountElement } = useRendererContext();
|
|
252
|
+
const mount = import_react8.default.useCallback(
|
|
194
253
|
(element) => {
|
|
195
254
|
return novuUI.mountComponent({
|
|
196
255
|
name: "Inbox",
|
|
@@ -207,15 +266,16 @@ var DefaultInbox = (props) => {
|
|
|
207
266
|
},
|
|
208
267
|
[open, renderNotification, renderBell, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick]
|
|
209
268
|
);
|
|
210
|
-
return /* @__PURE__ */ (0,
|
|
269
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Mounter, { mount });
|
|
211
270
|
};
|
|
212
|
-
var
|
|
271
|
+
var DefaultInbox = withRenderer(_DefaultInbox);
|
|
272
|
+
var Inbox = import_react8.default.memo((props) => {
|
|
213
273
|
const { applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl } = props;
|
|
214
274
|
const novu = useUnsafeNovu();
|
|
215
275
|
if (novu) {
|
|
216
|
-
return /* @__PURE__ */ (0,
|
|
276
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(InboxChild, { ...props });
|
|
217
277
|
}
|
|
218
|
-
return /* @__PURE__ */ (0,
|
|
278
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
219
279
|
NovuProvider,
|
|
220
280
|
{
|
|
221
281
|
applicationIdentifier,
|
|
@@ -223,15 +283,16 @@ var Inbox = import_react6.default.memo((props) => {
|
|
|
223
283
|
subscriberHash,
|
|
224
284
|
backendUrl,
|
|
225
285
|
socketUrl,
|
|
226
|
-
children: /* @__PURE__ */ (0,
|
|
286
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(InboxChild, { ...props })
|
|
227
287
|
}
|
|
228
288
|
);
|
|
229
289
|
});
|
|
230
|
-
var InboxChild =
|
|
290
|
+
var InboxChild = import_react8.default.memo((props) => {
|
|
231
291
|
const {
|
|
232
292
|
localization,
|
|
233
293
|
appearance,
|
|
234
294
|
tabs,
|
|
295
|
+
preferencesFilter,
|
|
235
296
|
routerPush,
|
|
236
297
|
applicationIdentifier,
|
|
237
298
|
subscriberId,
|
|
@@ -240,20 +301,31 @@ var InboxChild = import_react6.default.memo((props) => {
|
|
|
240
301
|
socketUrl
|
|
241
302
|
} = props;
|
|
242
303
|
const novu = useNovu();
|
|
243
|
-
const options = (0,
|
|
304
|
+
const options = (0, import_react8.useMemo)(() => {
|
|
244
305
|
return {
|
|
245
306
|
localization,
|
|
246
307
|
appearance,
|
|
247
308
|
tabs,
|
|
309
|
+
preferencesFilter,
|
|
248
310
|
routerPush,
|
|
249
311
|
options: { applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl }
|
|
250
312
|
};
|
|
251
|
-
}, [
|
|
313
|
+
}, [
|
|
314
|
+
localization,
|
|
315
|
+
appearance,
|
|
316
|
+
tabs,
|
|
317
|
+
preferencesFilter,
|
|
318
|
+
applicationIdentifier,
|
|
319
|
+
subscriberId,
|
|
320
|
+
subscriberHash,
|
|
321
|
+
backendUrl,
|
|
322
|
+
socketUrl
|
|
323
|
+
]);
|
|
252
324
|
if (isWithChildrenProps(props)) {
|
|
253
|
-
return /* @__PURE__ */ (0,
|
|
325
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(NovuUI, { options, novu, children: props.children });
|
|
254
326
|
}
|
|
255
327
|
const { open, renderNotification, renderBell, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick } = props;
|
|
256
|
-
return /* @__PURE__ */ (0,
|
|
328
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(NovuUI, { options, novu, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
257
329
|
DefaultInbox,
|
|
258
330
|
{
|
|
259
331
|
open,
|
|
@@ -270,26 +342,27 @@ function isWithChildrenProps(props) {
|
|
|
270
342
|
}
|
|
271
343
|
|
|
272
344
|
// src/components/Preferences.tsx
|
|
273
|
-
var
|
|
274
|
-
var
|
|
345
|
+
var import_react9 = __toESM(require("react"));
|
|
346
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
275
347
|
var Preferences = () => {
|
|
276
|
-
const { novuUI } =
|
|
277
|
-
const mount =
|
|
348
|
+
const { novuUI } = useNovuUIContext();
|
|
349
|
+
const mount = import_react9.default.useCallback((element) => {
|
|
278
350
|
return novuUI.mountComponent({
|
|
279
351
|
name: "Preferences",
|
|
280
352
|
element
|
|
281
353
|
});
|
|
282
354
|
}, []);
|
|
283
|
-
return /* @__PURE__ */ (0,
|
|
355
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Mounter, { mount });
|
|
284
356
|
};
|
|
285
357
|
|
|
286
358
|
// src/components/Notifications.tsx
|
|
287
|
-
var
|
|
288
|
-
var
|
|
289
|
-
var
|
|
359
|
+
var import_react10 = __toESM(require("react"));
|
|
360
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
361
|
+
var _Notifications = import_react10.default.memo((props) => {
|
|
290
362
|
const { onNotificationClick, onPrimaryActionClick, renderNotification, onSecondaryActionClick } = props;
|
|
291
|
-
const { novuUI
|
|
292
|
-
const
|
|
363
|
+
const { novuUI } = useNovuUIContext();
|
|
364
|
+
const { mountElement } = useRendererContext();
|
|
365
|
+
const mount = import_react10.default.useCallback(
|
|
293
366
|
(element) => {
|
|
294
367
|
return novuUI.mountComponent({
|
|
295
368
|
name: "Notifications",
|
|
@@ -304,53 +377,57 @@ var Notifications = import_react8.default.memo((props) => {
|
|
|
304
377
|
},
|
|
305
378
|
[renderNotification, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick]
|
|
306
379
|
);
|
|
307
|
-
return /* @__PURE__ */ (0,
|
|
380
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Mounter, { mount });
|
|
308
381
|
});
|
|
382
|
+
var Notifications = withRenderer(_Notifications);
|
|
309
383
|
|
|
310
|
-
// src/
|
|
311
|
-
var
|
|
312
|
-
var
|
|
313
|
-
var
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
}
|
|
324
|
-
const
|
|
325
|
-
() =>
|
|
326
|
-
|
|
384
|
+
// src/components/InboxContent.tsx
|
|
385
|
+
var import_react11 = __toESM(require("react"));
|
|
386
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
387
|
+
var _InboxContent = import_react11.default.memo((props) => {
|
|
388
|
+
const {
|
|
389
|
+
onNotificationClick,
|
|
390
|
+
onPrimaryActionClick,
|
|
391
|
+
renderNotification,
|
|
392
|
+
onSecondaryActionClick,
|
|
393
|
+
initialPage,
|
|
394
|
+
hideNav
|
|
395
|
+
} = props;
|
|
396
|
+
const { novuUI } = useNovuUIContext();
|
|
397
|
+
const { mountElement } = useRendererContext();
|
|
398
|
+
const mount = import_react11.default.useCallback(
|
|
399
|
+
(element) => {
|
|
400
|
+
return novuUI.mountComponent({
|
|
401
|
+
name: "InboxContent",
|
|
402
|
+
element,
|
|
403
|
+
props: {
|
|
404
|
+
renderNotification: renderNotification ? (el, notification) => mountElement(el, renderNotification(notification)) : void 0,
|
|
405
|
+
onNotificationClick,
|
|
406
|
+
onPrimaryActionClick,
|
|
407
|
+
onSecondaryActionClick,
|
|
408
|
+
initialPage,
|
|
409
|
+
hideNav
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
},
|
|
413
|
+
[renderNotification, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick]
|
|
327
414
|
);
|
|
328
|
-
return /* @__PURE__ */ (0,
|
|
329
|
-
};
|
|
330
|
-
var
|
|
331
|
-
const context = (0, import_react9.useContext)(NovuContext);
|
|
332
|
-
if (!context) {
|
|
333
|
-
throw new Error("useNovu must be used within a <NovuProvider />");
|
|
334
|
-
}
|
|
335
|
-
return context;
|
|
336
|
-
};
|
|
337
|
-
var useUnsafeNovu = () => {
|
|
338
|
-
const context = (0, import_react9.useContext)(NovuContext);
|
|
339
|
-
return context;
|
|
340
|
-
};
|
|
415
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Mounter, { mount });
|
|
416
|
+
});
|
|
417
|
+
var InboxContent = withRenderer(_InboxContent);
|
|
341
418
|
|
|
342
419
|
// src/hooks/useNotifications.ts
|
|
343
|
-
var
|
|
420
|
+
var import_react12 = require("react");
|
|
344
421
|
var import_js2 = require("@novu/js");
|
|
345
422
|
var useNotifications = (props) => {
|
|
346
423
|
const { tags, read, archived = false, limit, onSuccess, onError } = props || {};
|
|
347
|
-
const filterRef = (0,
|
|
424
|
+
const filterRef = (0, import_react12.useRef)(void 0);
|
|
348
425
|
const { notifications, on, off } = useNovu();
|
|
349
|
-
const [data, setData] = (0,
|
|
350
|
-
const [error, setError] = (0,
|
|
351
|
-
const [isLoading, setIsLoading] = (0,
|
|
352
|
-
const [isFetching, setIsFetching] = (0,
|
|
353
|
-
const [hasMore, setHasMore] = (0,
|
|
426
|
+
const [data, setData] = (0, import_react12.useState)();
|
|
427
|
+
const [error, setError] = (0, import_react12.useState)();
|
|
428
|
+
const [isLoading, setIsLoading] = (0, import_react12.useState)(true);
|
|
429
|
+
const [isFetching, setIsFetching] = (0, import_react12.useState)(false);
|
|
430
|
+
const [hasMore, setHasMore] = (0, import_react12.useState)(false);
|
|
354
431
|
const length = data?.length;
|
|
355
432
|
const after = length ? data[length - 1].id : void 0;
|
|
356
433
|
const sync = (event) => {
|
|
@@ -360,13 +437,13 @@ var useNotifications = (props) => {
|
|
|
360
437
|
setData(event.data.notifications);
|
|
361
438
|
setHasMore(event.data.hasMore);
|
|
362
439
|
};
|
|
363
|
-
(0,
|
|
440
|
+
(0, import_react12.useEffect)(() => {
|
|
364
441
|
on("notifications.list.updated", sync);
|
|
365
442
|
return () => {
|
|
366
443
|
off("notifications.list.updated", sync);
|
|
367
444
|
};
|
|
368
445
|
}, []);
|
|
369
|
-
(0,
|
|
446
|
+
(0, import_react12.useEffect)(() => {
|
|
370
447
|
const newFilter = { tags, read, archived };
|
|
371
448
|
if (filterRef.current && (0, import_js2.isSameFilter)(filterRef.current, newFilter)) {
|
|
372
449
|
return;
|
|
@@ -432,21 +509,21 @@ var useNotifications = (props) => {
|
|
|
432
509
|
};
|
|
433
510
|
|
|
434
511
|
// src/hooks/usePreferences.ts
|
|
435
|
-
var
|
|
512
|
+
var import_react13 = require("react");
|
|
436
513
|
var usePreferences = (props) => {
|
|
437
514
|
const { onSuccess, onError } = props || {};
|
|
438
|
-
const [data, setData] = (0,
|
|
515
|
+
const [data, setData] = (0, import_react13.useState)();
|
|
439
516
|
const { preferences, on, off } = useNovu();
|
|
440
|
-
const [error, setError] = (0,
|
|
441
|
-
const [isLoading, setIsLoading] = (0,
|
|
442
|
-
const [isFetching, setIsFetching] = (0,
|
|
517
|
+
const [error, setError] = (0, import_react13.useState)();
|
|
518
|
+
const [isLoading, setIsLoading] = (0, import_react13.useState)(true);
|
|
519
|
+
const [isFetching, setIsFetching] = (0, import_react13.useState)(false);
|
|
443
520
|
const sync = (event) => {
|
|
444
521
|
if (!event.data) {
|
|
445
522
|
return;
|
|
446
523
|
}
|
|
447
524
|
setData(event.data);
|
|
448
525
|
};
|
|
449
|
-
(0,
|
|
526
|
+
(0, import_react13.useEffect)(() => {
|
|
450
527
|
fetchPreferences();
|
|
451
528
|
on("preferences.list.updated", sync);
|
|
452
529
|
on("preferences.list.pending", sync);
|
|
@@ -459,7 +536,7 @@ var usePreferences = (props) => {
|
|
|
459
536
|
}, []);
|
|
460
537
|
const fetchPreferences = async () => {
|
|
461
538
|
setIsFetching(true);
|
|
462
|
-
const response = await preferences.list();
|
|
539
|
+
const response = await preferences.list(props?.filter);
|
|
463
540
|
if (response.error) {
|
|
464
541
|
setError(response.error);
|
|
465
542
|
onError?.(response.error);
|
|
@@ -483,11 +560,11 @@ var usePreferences = (props) => {
|
|
|
483
560
|
};
|
|
484
561
|
|
|
485
562
|
// src/hooks/useCounts.ts
|
|
486
|
-
var
|
|
563
|
+
var import_react16 = require("react");
|
|
487
564
|
var import_js3 = require("@novu/js");
|
|
488
565
|
|
|
489
566
|
// src/hooks/internal/useWebsocketEvent.ts
|
|
490
|
-
var
|
|
567
|
+
var import_react15 = require("react");
|
|
491
568
|
|
|
492
569
|
// src/utils/requestLock.ts
|
|
493
570
|
function requestLock(id, cb) {
|
|
@@ -514,18 +591,18 @@ function requestLock(id, cb) {
|
|
|
514
591
|
}
|
|
515
592
|
|
|
516
593
|
// src/hooks/internal/useBrowserTabsChannel.ts
|
|
517
|
-
var
|
|
594
|
+
var import_react14 = require("react");
|
|
518
595
|
var useBrowserTabsChannel = ({
|
|
519
596
|
channelName,
|
|
520
597
|
onMessage
|
|
521
598
|
}) => {
|
|
522
|
-
const [tabsChannel] = (0,
|
|
599
|
+
const [tabsChannel] = (0, import_react14.useState)(
|
|
523
600
|
typeof BroadcastChannel !== "undefined" ? new BroadcastChannel(channelName) : void 0
|
|
524
601
|
);
|
|
525
602
|
const postMessage = (data) => {
|
|
526
603
|
tabsChannel?.postMessage(data);
|
|
527
604
|
};
|
|
528
|
-
(0,
|
|
605
|
+
(0, import_react14.useEffect)(() => {
|
|
529
606
|
const listener = (event) => {
|
|
530
607
|
onMessage(event.data);
|
|
531
608
|
};
|
|
@@ -548,7 +625,7 @@ var useWebSocketEvent = ({
|
|
|
548
625
|
onMessage(data);
|
|
549
626
|
postMessage(data);
|
|
550
627
|
};
|
|
551
|
-
(0,
|
|
628
|
+
(0, import_react15.useEffect)(() => {
|
|
552
629
|
const resolveLock = requestLock(`nv.${webSocketEvent}`, () => {
|
|
553
630
|
novu.on(webSocketEvent, updateReadCount);
|
|
554
631
|
});
|
|
@@ -563,10 +640,10 @@ var useWebSocketEvent = ({
|
|
|
563
640
|
var useCounts = (props) => {
|
|
564
641
|
const { filters, onSuccess, onError } = props;
|
|
565
642
|
const { notifications } = useNovu();
|
|
566
|
-
const [error, setError] = (0,
|
|
567
|
-
const [counts, setCounts] = (0,
|
|
568
|
-
const [isLoading, setIsLoading] = (0,
|
|
569
|
-
const [isFetching, setIsFetching] = (0,
|
|
643
|
+
const [error, setError] = (0, import_react16.useState)();
|
|
644
|
+
const [counts, setCounts] = (0, import_react16.useState)();
|
|
645
|
+
const [isLoading, setIsLoading] = (0, import_react16.useState)(true);
|
|
646
|
+
const [isFetching, setIsFetching] = (0, import_react16.useState)(false);
|
|
570
647
|
const sync = async (notification) => {
|
|
571
648
|
const existingCounts = counts ?? new Array(filters.length).fill(void 0);
|
|
572
649
|
let countFiltersToFetch = [];
|
|
@@ -616,7 +693,7 @@ var useCounts = (props) => {
|
|
|
616
693
|
sync();
|
|
617
694
|
}
|
|
618
695
|
});
|
|
619
|
-
(0,
|
|
696
|
+
(0, import_react16.useEffect)(() => {
|
|
620
697
|
setError(void 0);
|
|
621
698
|
setIsLoading(true);
|
|
622
699
|
setIsFetching(false);
|