@novu/react 2.2.0 → 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 +21 -6
- package/dist/client/index.d.ts +21 -6
- package/dist/client/index.js +218 -154
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +217 -153
- package/dist/client/index.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 +15 -3
- 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
|
}
|
|
@@ -173,25 +236,20 @@ var Renderer = ({ options, novu, children }) => {
|
|
|
173
236
|
novuUI.updateTabs(options.tabs);
|
|
174
237
|
novuUI.updateOptions(options.options);
|
|
175
238
|
novuUI.updateRouterPush(options.routerPush);
|
|
176
|
-
novuUI.updatePreferencesFilter(options.preferencesFilter);
|
|
177
239
|
}, [options]);
|
|
178
240
|
if (!novuUI) {
|
|
179
241
|
return null;
|
|
180
242
|
}
|
|
181
|
-
return /* @__PURE__ */ (0,
|
|
182
|
-
[...mountedElements].map(([element, mountedElement]) => {
|
|
183
|
-
return import_react_dom.default.createPortal(mountedElement, element);
|
|
184
|
-
}),
|
|
185
|
-
children
|
|
186
|
-
] });
|
|
243
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(NovuUIProvider, { value: { novuUI }, children });
|
|
187
244
|
};
|
|
188
245
|
|
|
189
246
|
// src/components/Inbox.tsx
|
|
190
|
-
var
|
|
191
|
-
var
|
|
247
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
248
|
+
var _DefaultInbox = (props) => {
|
|
192
249
|
const { open, renderNotification, renderBell, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick } = props;
|
|
193
|
-
const { novuUI
|
|
194
|
-
const
|
|
250
|
+
const { novuUI } = useNovuUIContext();
|
|
251
|
+
const { mountElement } = useRendererContext();
|
|
252
|
+
const mount = import_react8.default.useCallback(
|
|
195
253
|
(element) => {
|
|
196
254
|
return novuUI.mountComponent({
|
|
197
255
|
name: "Inbox",
|
|
@@ -208,15 +266,16 @@ var DefaultInbox = (props) => {
|
|
|
208
266
|
},
|
|
209
267
|
[open, renderNotification, renderBell, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick]
|
|
210
268
|
);
|
|
211
|
-
return /* @__PURE__ */ (0,
|
|
269
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Mounter, { mount });
|
|
212
270
|
};
|
|
213
|
-
var
|
|
271
|
+
var DefaultInbox = withRenderer(_DefaultInbox);
|
|
272
|
+
var Inbox = import_react8.default.memo((props) => {
|
|
214
273
|
const { applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl } = props;
|
|
215
274
|
const novu = useUnsafeNovu();
|
|
216
275
|
if (novu) {
|
|
217
|
-
return /* @__PURE__ */ (0,
|
|
276
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(InboxChild, { ...props });
|
|
218
277
|
}
|
|
219
|
-
return /* @__PURE__ */ (0,
|
|
278
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
220
279
|
NovuProvider,
|
|
221
280
|
{
|
|
222
281
|
applicationIdentifier,
|
|
@@ -224,11 +283,11 @@ var Inbox = import_react6.default.memo((props) => {
|
|
|
224
283
|
subscriberHash,
|
|
225
284
|
backendUrl,
|
|
226
285
|
socketUrl,
|
|
227
|
-
children: /* @__PURE__ */ (0,
|
|
286
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(InboxChild, { ...props })
|
|
228
287
|
}
|
|
229
288
|
);
|
|
230
289
|
});
|
|
231
|
-
var InboxChild =
|
|
290
|
+
var InboxChild = import_react8.default.memo((props) => {
|
|
232
291
|
const {
|
|
233
292
|
localization,
|
|
234
293
|
appearance,
|
|
@@ -242,7 +301,7 @@ var InboxChild = import_react6.default.memo((props) => {
|
|
|
242
301
|
socketUrl
|
|
243
302
|
} = props;
|
|
244
303
|
const novu = useNovu();
|
|
245
|
-
const options = (0,
|
|
304
|
+
const options = (0, import_react8.useMemo)(() => {
|
|
246
305
|
return {
|
|
247
306
|
localization,
|
|
248
307
|
appearance,
|
|
@@ -263,10 +322,10 @@ var InboxChild = import_react6.default.memo((props) => {
|
|
|
263
322
|
socketUrl
|
|
264
323
|
]);
|
|
265
324
|
if (isWithChildrenProps(props)) {
|
|
266
|
-
return /* @__PURE__ */ (0,
|
|
325
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(NovuUI, { options, novu, children: props.children });
|
|
267
326
|
}
|
|
268
327
|
const { open, renderNotification, renderBell, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick } = props;
|
|
269
|
-
return /* @__PURE__ */ (0,
|
|
328
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(NovuUI, { options, novu, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
270
329
|
DefaultInbox,
|
|
271
330
|
{
|
|
272
331
|
open,
|
|
@@ -283,26 +342,27 @@ function isWithChildrenProps(props) {
|
|
|
283
342
|
}
|
|
284
343
|
|
|
285
344
|
// src/components/Preferences.tsx
|
|
286
|
-
var
|
|
287
|
-
var
|
|
345
|
+
var import_react9 = __toESM(require("react"));
|
|
346
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
288
347
|
var Preferences = () => {
|
|
289
|
-
const { novuUI } =
|
|
290
|
-
const mount =
|
|
348
|
+
const { novuUI } = useNovuUIContext();
|
|
349
|
+
const mount = import_react9.default.useCallback((element) => {
|
|
291
350
|
return novuUI.mountComponent({
|
|
292
351
|
name: "Preferences",
|
|
293
352
|
element
|
|
294
353
|
});
|
|
295
354
|
}, []);
|
|
296
|
-
return /* @__PURE__ */ (0,
|
|
355
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Mounter, { mount });
|
|
297
356
|
};
|
|
298
357
|
|
|
299
358
|
// src/components/Notifications.tsx
|
|
300
|
-
var
|
|
301
|
-
var
|
|
302
|
-
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) => {
|
|
303
362
|
const { onNotificationClick, onPrimaryActionClick, renderNotification, onSecondaryActionClick } = props;
|
|
304
|
-
const { novuUI
|
|
305
|
-
const
|
|
363
|
+
const { novuUI } = useNovuUIContext();
|
|
364
|
+
const { mountElement } = useRendererContext();
|
|
365
|
+
const mount = import_react10.default.useCallback(
|
|
306
366
|
(element) => {
|
|
307
367
|
return novuUI.mountComponent({
|
|
308
368
|
name: "Notifications",
|
|
@@ -317,53 +377,57 @@ var Notifications = import_react8.default.memo((props) => {
|
|
|
317
377
|
},
|
|
318
378
|
[renderNotification, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick]
|
|
319
379
|
);
|
|
320
|
-
return /* @__PURE__ */ (0,
|
|
380
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Mounter, { mount });
|
|
321
381
|
});
|
|
382
|
+
var Notifications = withRenderer(_Notifications);
|
|
322
383
|
|
|
323
|
-
// src/
|
|
324
|
-
var
|
|
325
|
-
var
|
|
326
|
-
var
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
}
|
|
337
|
-
const
|
|
338
|
-
() =>
|
|
339
|
-
|
|
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]
|
|
340
414
|
);
|
|
341
|
-
return /* @__PURE__ */ (0,
|
|
342
|
-
};
|
|
343
|
-
var
|
|
344
|
-
const context = (0, import_react9.useContext)(NovuContext);
|
|
345
|
-
if (!context) {
|
|
346
|
-
throw new Error("useNovu must be used within a <NovuProvider />");
|
|
347
|
-
}
|
|
348
|
-
return context;
|
|
349
|
-
};
|
|
350
|
-
var useUnsafeNovu = () => {
|
|
351
|
-
const context = (0, import_react9.useContext)(NovuContext);
|
|
352
|
-
return context;
|
|
353
|
-
};
|
|
415
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Mounter, { mount });
|
|
416
|
+
});
|
|
417
|
+
var InboxContent = withRenderer(_InboxContent);
|
|
354
418
|
|
|
355
419
|
// src/hooks/useNotifications.ts
|
|
356
|
-
var
|
|
420
|
+
var import_react12 = require("react");
|
|
357
421
|
var import_js2 = require("@novu/js");
|
|
358
422
|
var useNotifications = (props) => {
|
|
359
423
|
const { tags, read, archived = false, limit, onSuccess, onError } = props || {};
|
|
360
|
-
const filterRef = (0,
|
|
424
|
+
const filterRef = (0, import_react12.useRef)(void 0);
|
|
361
425
|
const { notifications, on, off } = useNovu();
|
|
362
|
-
const [data, setData] = (0,
|
|
363
|
-
const [error, setError] = (0,
|
|
364
|
-
const [isLoading, setIsLoading] = (0,
|
|
365
|
-
const [isFetching, setIsFetching] = (0,
|
|
366
|
-
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);
|
|
367
431
|
const length = data?.length;
|
|
368
432
|
const after = length ? data[length - 1].id : void 0;
|
|
369
433
|
const sync = (event) => {
|
|
@@ -373,13 +437,13 @@ var useNotifications = (props) => {
|
|
|
373
437
|
setData(event.data.notifications);
|
|
374
438
|
setHasMore(event.data.hasMore);
|
|
375
439
|
};
|
|
376
|
-
(0,
|
|
440
|
+
(0, import_react12.useEffect)(() => {
|
|
377
441
|
on("notifications.list.updated", sync);
|
|
378
442
|
return () => {
|
|
379
443
|
off("notifications.list.updated", sync);
|
|
380
444
|
};
|
|
381
445
|
}, []);
|
|
382
|
-
(0,
|
|
446
|
+
(0, import_react12.useEffect)(() => {
|
|
383
447
|
const newFilter = { tags, read, archived };
|
|
384
448
|
if (filterRef.current && (0, import_js2.isSameFilter)(filterRef.current, newFilter)) {
|
|
385
449
|
return;
|
|
@@ -445,21 +509,21 @@ var useNotifications = (props) => {
|
|
|
445
509
|
};
|
|
446
510
|
|
|
447
511
|
// src/hooks/usePreferences.ts
|
|
448
|
-
var
|
|
512
|
+
var import_react13 = require("react");
|
|
449
513
|
var usePreferences = (props) => {
|
|
450
514
|
const { onSuccess, onError } = props || {};
|
|
451
|
-
const [data, setData] = (0,
|
|
515
|
+
const [data, setData] = (0, import_react13.useState)();
|
|
452
516
|
const { preferences, on, off } = useNovu();
|
|
453
|
-
const [error, setError] = (0,
|
|
454
|
-
const [isLoading, setIsLoading] = (0,
|
|
455
|
-
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);
|
|
456
520
|
const sync = (event) => {
|
|
457
521
|
if (!event.data) {
|
|
458
522
|
return;
|
|
459
523
|
}
|
|
460
524
|
setData(event.data);
|
|
461
525
|
};
|
|
462
|
-
(0,
|
|
526
|
+
(0, import_react13.useEffect)(() => {
|
|
463
527
|
fetchPreferences();
|
|
464
528
|
on("preferences.list.updated", sync);
|
|
465
529
|
on("preferences.list.pending", sync);
|
|
@@ -496,11 +560,11 @@ var usePreferences = (props) => {
|
|
|
496
560
|
};
|
|
497
561
|
|
|
498
562
|
// src/hooks/useCounts.ts
|
|
499
|
-
var
|
|
563
|
+
var import_react16 = require("react");
|
|
500
564
|
var import_js3 = require("@novu/js");
|
|
501
565
|
|
|
502
566
|
// src/hooks/internal/useWebsocketEvent.ts
|
|
503
|
-
var
|
|
567
|
+
var import_react15 = require("react");
|
|
504
568
|
|
|
505
569
|
// src/utils/requestLock.ts
|
|
506
570
|
function requestLock(id, cb) {
|
|
@@ -527,18 +591,18 @@ function requestLock(id, cb) {
|
|
|
527
591
|
}
|
|
528
592
|
|
|
529
593
|
// src/hooks/internal/useBrowserTabsChannel.ts
|
|
530
|
-
var
|
|
594
|
+
var import_react14 = require("react");
|
|
531
595
|
var useBrowserTabsChannel = ({
|
|
532
596
|
channelName,
|
|
533
597
|
onMessage
|
|
534
598
|
}) => {
|
|
535
|
-
const [tabsChannel] = (0,
|
|
599
|
+
const [tabsChannel] = (0, import_react14.useState)(
|
|
536
600
|
typeof BroadcastChannel !== "undefined" ? new BroadcastChannel(channelName) : void 0
|
|
537
601
|
);
|
|
538
602
|
const postMessage = (data) => {
|
|
539
603
|
tabsChannel?.postMessage(data);
|
|
540
604
|
};
|
|
541
|
-
(0,
|
|
605
|
+
(0, import_react14.useEffect)(() => {
|
|
542
606
|
const listener = (event) => {
|
|
543
607
|
onMessage(event.data);
|
|
544
608
|
};
|
|
@@ -561,7 +625,7 @@ var useWebSocketEvent = ({
|
|
|
561
625
|
onMessage(data);
|
|
562
626
|
postMessage(data);
|
|
563
627
|
};
|
|
564
|
-
(0,
|
|
628
|
+
(0, import_react15.useEffect)(() => {
|
|
565
629
|
const resolveLock = requestLock(`nv.${webSocketEvent}`, () => {
|
|
566
630
|
novu.on(webSocketEvent, updateReadCount);
|
|
567
631
|
});
|
|
@@ -576,10 +640,10 @@ var useWebSocketEvent = ({
|
|
|
576
640
|
var useCounts = (props) => {
|
|
577
641
|
const { filters, onSuccess, onError } = props;
|
|
578
642
|
const { notifications } = useNovu();
|
|
579
|
-
const [error, setError] = (0,
|
|
580
|
-
const [counts, setCounts] = (0,
|
|
581
|
-
const [isLoading, setIsLoading] = (0,
|
|
582
|
-
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);
|
|
583
647
|
const sync = async (notification) => {
|
|
584
648
|
const existingCounts = counts ?? new Array(filters.length).fill(void 0);
|
|
585
649
|
let countFiltersToFetch = [];
|
|
@@ -629,7 +693,7 @@ var useCounts = (props) => {
|
|
|
629
693
|
sync();
|
|
630
694
|
}
|
|
631
695
|
});
|
|
632
|
-
(0,
|
|
696
|
+
(0, import_react16.useEffect)(() => {
|
|
633
697
|
setError(void 0);
|
|
634
698
|
setIsLoading(true);
|
|
635
699
|
setIsFetching(false);
|