@mantine-vue/notifications 1.1.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/cjs/index.cjs +637 -0
- package/cjs/index.cjs.map +1 -0
- package/esm/index.mjs +626 -0
- package/esm/index.mjs.map +1 -0
- package/lib/NotificationContainer.d.ts +82 -0
- package/lib/Notifications.d.ts +314 -0
- package/lib/get-auto-close/get-auto-close.d.ts +1 -0
- package/lib/get-grouped-notifications/get-grouped-notifications.d.ts +4 -0
- package/lib/get-notification-state-styles.d.ts +11 -0
- package/lib/index.d.mts +4 -0
- package/lib/index.d.ts +4 -0
- package/lib/notifications.store.d.ts +39 -0
- package/package.json +46 -0
- package/styles.css +43 -0
- package/styles.layer.css +45 -0
package/cjs/index.cjs
ADDED
|
@@ -0,0 +1,637 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _mantine_vue_store = require("@mantine-vue/store");
|
|
3
|
+
let vue = require("vue");
|
|
4
|
+
let _mantine_vue_core = require("@mantine-vue/core");
|
|
5
|
+
let _mantine_vue_hooks = require("@mantine-vue/hooks");
|
|
6
|
+
//#region src/notifications.store.ts
|
|
7
|
+
function randomId() {
|
|
8
|
+
return `mantine-${Math.random().toString(36).slice(2, 11)}`;
|
|
9
|
+
}
|
|
10
|
+
function getDistributedNotifications(data, defaultPosition, limit) {
|
|
11
|
+
const queue = [];
|
|
12
|
+
const notifications = [];
|
|
13
|
+
const count = {};
|
|
14
|
+
for (const item of data) {
|
|
15
|
+
const position = item.position || defaultPosition;
|
|
16
|
+
count[position] = count[position] || 0;
|
|
17
|
+
count[position] += 1;
|
|
18
|
+
if (count[position] <= limit) notifications.push(item);
|
|
19
|
+
else queue.push(item);
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
notifications,
|
|
23
|
+
queue
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
var createNotificationsStore = () => (0, _mantine_vue_store.createStore)({
|
|
27
|
+
notifications: [],
|
|
28
|
+
queue: [],
|
|
29
|
+
defaultPosition: "bottom-right",
|
|
30
|
+
limit: 5
|
|
31
|
+
});
|
|
32
|
+
var notificationsStore = createNotificationsStore();
|
|
33
|
+
var useNotifications = (store = notificationsStore) => store.value;
|
|
34
|
+
function updateNotificationsState(store, update) {
|
|
35
|
+
const state = store.getState();
|
|
36
|
+
const updated = getDistributedNotifications(update([...state.notifications, ...state.queue]), state.defaultPosition, state.limit);
|
|
37
|
+
store.setState({
|
|
38
|
+
notifications: updated.notifications,
|
|
39
|
+
queue: updated.queue,
|
|
40
|
+
limit: state.limit,
|
|
41
|
+
defaultPosition: state.defaultPosition
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function showNotification(notification, store = notificationsStore) {
|
|
45
|
+
const id = notification.id || randomId();
|
|
46
|
+
updateNotificationsState(store, (notifications) => {
|
|
47
|
+
if (notification.id && notifications.some((n) => n.id === notification.id)) return notifications;
|
|
48
|
+
return [...notifications, {
|
|
49
|
+
...notification,
|
|
50
|
+
id
|
|
51
|
+
}];
|
|
52
|
+
});
|
|
53
|
+
return id;
|
|
54
|
+
}
|
|
55
|
+
function hideNotification(id, store = notificationsStore) {
|
|
56
|
+
updateNotificationsState(store, (notifications) => notifications.filter((notification) => {
|
|
57
|
+
if (notification.id === id) {
|
|
58
|
+
notification.onClose?.(notification);
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
}));
|
|
63
|
+
return id;
|
|
64
|
+
}
|
|
65
|
+
function updateNotification(notification, store = notificationsStore) {
|
|
66
|
+
updateNotificationsState(store, (notifications) => notifications.map((item) => item.id === notification.id ? {
|
|
67
|
+
...item,
|
|
68
|
+
...notification
|
|
69
|
+
} : item));
|
|
70
|
+
return notification.id;
|
|
71
|
+
}
|
|
72
|
+
function cleanNotifications(store = notificationsStore) {
|
|
73
|
+
updateNotificationsState(store, () => []);
|
|
74
|
+
}
|
|
75
|
+
function cleanNotificationsQueue(store = notificationsStore) {
|
|
76
|
+
updateNotificationsState(store, (notifications) => notifications.slice(0, store.getState().limit));
|
|
77
|
+
}
|
|
78
|
+
var notifications = {
|
|
79
|
+
show: showNotification,
|
|
80
|
+
hide: hideNotification,
|
|
81
|
+
update: updateNotification,
|
|
82
|
+
clean: cleanNotifications,
|
|
83
|
+
cleanQueue: cleanNotificationsQueue,
|
|
84
|
+
updateState: updateNotificationsState
|
|
85
|
+
};
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/get-grouped-notifications/get-grouped-notifications.ts
|
|
88
|
+
var positions = [
|
|
89
|
+
"bottom-center",
|
|
90
|
+
"bottom-left",
|
|
91
|
+
"bottom-right",
|
|
92
|
+
"top-center",
|
|
93
|
+
"top-left",
|
|
94
|
+
"top-right"
|
|
95
|
+
];
|
|
96
|
+
function getGroupedNotifications(notifications, defaultPosition) {
|
|
97
|
+
return notifications.reduce((acc, notification) => {
|
|
98
|
+
acc[notification.position || defaultPosition].push(notification);
|
|
99
|
+
return acc;
|
|
100
|
+
}, positions.reduce((acc, item) => {
|
|
101
|
+
acc[item] = [];
|
|
102
|
+
return acc;
|
|
103
|
+
}, {}));
|
|
104
|
+
}
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/get-notification-state-styles.ts
|
|
107
|
+
var transforms = {
|
|
108
|
+
left: "translateX(-100%)",
|
|
109
|
+
right: "translateX(100%)",
|
|
110
|
+
"top-center": "translateY(-100%)",
|
|
111
|
+
"bottom-center": "translateY(100%)"
|
|
112
|
+
};
|
|
113
|
+
var noTransform = {
|
|
114
|
+
left: "translateX(0)",
|
|
115
|
+
right: "translateX(0)",
|
|
116
|
+
"top-center": "translateY(0)",
|
|
117
|
+
"bottom-center": "translateY(0)"
|
|
118
|
+
};
|
|
119
|
+
function toCssLength(value) {
|
|
120
|
+
return typeof value === "number" ? `${value}px` : value;
|
|
121
|
+
}
|
|
122
|
+
function getNotificationStateStyles({ state, maxHeight, position, transitionDuration }) {
|
|
123
|
+
const [vertical, horizontal] = position.split("-");
|
|
124
|
+
const property = horizontal === "center" ? `${vertical}-center` : horizontal;
|
|
125
|
+
const commonStyles = {
|
|
126
|
+
opacity: 0,
|
|
127
|
+
maxHeight: toCssLength(maxHeight),
|
|
128
|
+
transform: transforms[property],
|
|
129
|
+
transitionDuration: `${transitionDuration}ms, ${transitionDuration}ms, ${transitionDuration}ms`,
|
|
130
|
+
transitionTimingFunction: "cubic-bezier(.51,.3,0,1.21), cubic-bezier(.51,.3,0,1.21), linear",
|
|
131
|
+
transitionProperty: "opacity, transform, max-height"
|
|
132
|
+
};
|
|
133
|
+
const inState = {
|
|
134
|
+
opacity: 1,
|
|
135
|
+
transform: noTransform[property]
|
|
136
|
+
};
|
|
137
|
+
const outState = {
|
|
138
|
+
opacity: 0,
|
|
139
|
+
maxHeight: toCssLength(0),
|
|
140
|
+
transform: transforms[property]
|
|
141
|
+
};
|
|
142
|
+
const transitionStyles = {
|
|
143
|
+
entering: inState,
|
|
144
|
+
entered: inState,
|
|
145
|
+
exiting: outState,
|
|
146
|
+
exited: outState
|
|
147
|
+
};
|
|
148
|
+
return {
|
|
149
|
+
...commonStyles,
|
|
150
|
+
...transitionStyles[state]
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/get-auto-close/get-auto-close.ts
|
|
155
|
+
function getAutoClose(autoClose, notificationAutoClose) {
|
|
156
|
+
if (typeof notificationAutoClose === "number") return notificationAutoClose;
|
|
157
|
+
if (notificationAutoClose === false || autoClose === false) return false;
|
|
158
|
+
return autoClose;
|
|
159
|
+
}
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region src/NotificationContainer.ts
|
|
162
|
+
var SCROLL_DISMISS_RESET_TIMEOUT = 120;
|
|
163
|
+
function normalizeStyle(style) {
|
|
164
|
+
if (!style) return {};
|
|
165
|
+
if (Array.isArray(style)) return style.reduce((acc, item) => Object.assign(acc, normalizeStyle(item)), {});
|
|
166
|
+
return typeof style === "object" ? style : {};
|
|
167
|
+
}
|
|
168
|
+
function renderContent(value) {
|
|
169
|
+
return typeof value === "function" ? value() : value;
|
|
170
|
+
}
|
|
171
|
+
function getNotificationProps(data) {
|
|
172
|
+
const omittedKeys = new Set([
|
|
173
|
+
"autoClose",
|
|
174
|
+
"message",
|
|
175
|
+
"allowClose",
|
|
176
|
+
"position",
|
|
177
|
+
"style",
|
|
178
|
+
"withCloseButton",
|
|
179
|
+
"onOpen",
|
|
180
|
+
"onClose",
|
|
181
|
+
"id"
|
|
182
|
+
]);
|
|
183
|
+
return Object.entries(data).reduce((acc, [key, value]) => {
|
|
184
|
+
if (!omittedKeys.has(key)) acc[key] = value;
|
|
185
|
+
return acc;
|
|
186
|
+
}, {});
|
|
187
|
+
}
|
|
188
|
+
var NotificationContainer = (0, vue.defineComponent)({
|
|
189
|
+
name: "NotificationContainer",
|
|
190
|
+
inheritAttrs: false,
|
|
191
|
+
props: {
|
|
192
|
+
data: {
|
|
193
|
+
type: Object,
|
|
194
|
+
required: true
|
|
195
|
+
},
|
|
196
|
+
autoClose: {
|
|
197
|
+
type: [Boolean, Number],
|
|
198
|
+
required: true
|
|
199
|
+
},
|
|
200
|
+
transitionDuration: {
|
|
201
|
+
type: Number,
|
|
202
|
+
required: true
|
|
203
|
+
},
|
|
204
|
+
allowDragDismiss: {
|
|
205
|
+
type: Boolean,
|
|
206
|
+
required: true
|
|
207
|
+
},
|
|
208
|
+
allowScrollDismiss: {
|
|
209
|
+
type: Boolean,
|
|
210
|
+
required: true
|
|
211
|
+
},
|
|
212
|
+
paused: {
|
|
213
|
+
type: Boolean,
|
|
214
|
+
required: true
|
|
215
|
+
},
|
|
216
|
+
onHide: {
|
|
217
|
+
type: Function,
|
|
218
|
+
required: true
|
|
219
|
+
},
|
|
220
|
+
onHoverStart: {
|
|
221
|
+
type: Function,
|
|
222
|
+
default: void 0
|
|
223
|
+
},
|
|
224
|
+
onHoverEnd: {
|
|
225
|
+
type: Function,
|
|
226
|
+
default: void 0
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
setup(props, { attrs }) {
|
|
230
|
+
const notificationRef = (0, vue.ref)(null);
|
|
231
|
+
const offset = (0, vue.ref)(0);
|
|
232
|
+
const dismissed = (0, vue.ref)(false);
|
|
233
|
+
const dismissDirection = (0, vue.ref)(1);
|
|
234
|
+
const active = (0, vue.ref)(false);
|
|
235
|
+
const scrollDismissActive = (0, vue.ref)(false);
|
|
236
|
+
const hovered = (0, vue.ref)(false);
|
|
237
|
+
const startX = (0, vue.ref)(0);
|
|
238
|
+
const startTime = (0, vue.ref)(0);
|
|
239
|
+
let autoCloseTimeout = -1;
|
|
240
|
+
let hideTimeout = -1;
|
|
241
|
+
let scrollDismissTimeout = -1;
|
|
242
|
+
const autoCloseDuration = (0, vue.computed)(() => getAutoClose(props.autoClose, props.data.autoClose));
|
|
243
|
+
const isCloseDisabled = (0, vue.computed)(() => props.data.allowClose === false);
|
|
244
|
+
const cancelAutoClose = () => window.clearTimeout(autoCloseTimeout);
|
|
245
|
+
const cancelHide = () => window.clearTimeout(hideTimeout);
|
|
246
|
+
const cancelScrollDismissReset = () => window.clearTimeout(scrollDismissTimeout);
|
|
247
|
+
const setSwipeOffset = (value) => {
|
|
248
|
+
offset.value = value;
|
|
249
|
+
};
|
|
250
|
+
const handleHide = () => {
|
|
251
|
+
props.onHide(props.data.id);
|
|
252
|
+
cancelAutoClose();
|
|
253
|
+
cancelHide();
|
|
254
|
+
cancelScrollDismissReset();
|
|
255
|
+
};
|
|
256
|
+
const handleAutoClose = () => {
|
|
257
|
+
if (typeof window === "undefined" || dismissed.value || active.value || props.paused || hovered.value || typeof autoCloseDuration.value !== "number") return;
|
|
258
|
+
cancelAutoClose();
|
|
259
|
+
autoCloseTimeout = window.setTimeout(handleHide, autoCloseDuration.value);
|
|
260
|
+
};
|
|
261
|
+
const getExitOffset = (direction) => {
|
|
262
|
+
return direction * ((notificationRef.value?.offsetWidth ?? 440) + 40);
|
|
263
|
+
};
|
|
264
|
+
const shouldDismiss = (movement, velocity) => {
|
|
265
|
+
const width = notificationRef.value?.offsetWidth ?? 440;
|
|
266
|
+
return Math.abs(movement) > width * .35 || velocity > .5;
|
|
267
|
+
};
|
|
268
|
+
const resetSwipe = () => {
|
|
269
|
+
cancelScrollDismissReset();
|
|
270
|
+
scrollDismissActive.value = false;
|
|
271
|
+
setSwipeOffset(0);
|
|
272
|
+
};
|
|
273
|
+
const dismissNotification = (direction) => {
|
|
274
|
+
dismissDirection.value = direction;
|
|
275
|
+
dismissed.value = true;
|
|
276
|
+
scrollDismissActive.value = false;
|
|
277
|
+
setSwipeOffset(getExitOffset(direction));
|
|
278
|
+
cancelAutoClose();
|
|
279
|
+
cancelHide();
|
|
280
|
+
cancelScrollDismissReset();
|
|
281
|
+
hideTimeout = window.setTimeout(handleHide, props.transitionDuration);
|
|
282
|
+
};
|
|
283
|
+
const scheduleScrollDismissReset = () => {
|
|
284
|
+
cancelScrollDismissReset();
|
|
285
|
+
scrollDismissTimeout = window.setTimeout(() => {
|
|
286
|
+
scrollDismissActive.value = false;
|
|
287
|
+
setSwipeOffset(0);
|
|
288
|
+
handleAutoClose();
|
|
289
|
+
}, SCROLL_DISMISS_RESET_TIMEOUT);
|
|
290
|
+
};
|
|
291
|
+
const handlePointerMove = (event) => {
|
|
292
|
+
if (!active.value || dismissed.value) return;
|
|
293
|
+
setSwipeOffset(event.clientX - startX.value);
|
|
294
|
+
};
|
|
295
|
+
const finishPointerDrag = (event) => {
|
|
296
|
+
if (!active.value) return;
|
|
297
|
+
active.value = false;
|
|
298
|
+
window.removeEventListener("pointermove", handlePointerMove);
|
|
299
|
+
window.removeEventListener("pointerup", finishPointerDrag);
|
|
300
|
+
window.removeEventListener("pointercancel", cancelPointerDragEvent);
|
|
301
|
+
const movement = event.clientX - startX.value;
|
|
302
|
+
const elapsed = Math.max(Date.now() - startTime.value, 1);
|
|
303
|
+
const velocity = Math.abs(movement) / elapsed;
|
|
304
|
+
const direction = movement === 0 ? 1 : movement > 0 ? 1 : -1;
|
|
305
|
+
if (shouldDismiss(movement, velocity)) dismissNotification(direction);
|
|
306
|
+
else {
|
|
307
|
+
setSwipeOffset(0);
|
|
308
|
+
handleAutoClose();
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
function cancelPointerDrag(shouldRestartAutoClose = true) {
|
|
312
|
+
active.value = false;
|
|
313
|
+
window.removeEventListener("pointermove", handlePointerMove);
|
|
314
|
+
window.removeEventListener("pointerup", finishPointerDrag);
|
|
315
|
+
window.removeEventListener("pointercancel", cancelPointerDragEvent);
|
|
316
|
+
setSwipeOffset(0);
|
|
317
|
+
if (shouldRestartAutoClose) handleAutoClose();
|
|
318
|
+
}
|
|
319
|
+
const cancelPointerDragEvent = () => cancelPointerDrag();
|
|
320
|
+
const handlePointerDown = (event) => {
|
|
321
|
+
if (!props.allowDragDismiss || isCloseDisabled.value || dismissed.value || event.button !== 0) return;
|
|
322
|
+
cancelAutoClose();
|
|
323
|
+
active.value = true;
|
|
324
|
+
startX.value = event.clientX;
|
|
325
|
+
startTime.value = Date.now();
|
|
326
|
+
window.addEventListener("pointermove", handlePointerMove);
|
|
327
|
+
window.addEventListener("pointerup", finishPointerDrag);
|
|
328
|
+
window.addEventListener("pointercancel", cancelPointerDragEvent);
|
|
329
|
+
};
|
|
330
|
+
const handleWheel = (event) => {
|
|
331
|
+
if (dismissed.value || active.value) return;
|
|
332
|
+
const isDocumentEvent = event.currentTarget === document;
|
|
333
|
+
if (!isDocumentEvent && !hovered.value) return;
|
|
334
|
+
const { deltaX, deltaY } = event;
|
|
335
|
+
if (Math.abs(deltaX) <= Math.abs(deltaY) || deltaX === 0) return;
|
|
336
|
+
if (!props.allowScrollDismiss || isCloseDisabled.value) return;
|
|
337
|
+
if (!isDocumentEvent) {
|
|
338
|
+
event.preventDefault();
|
|
339
|
+
event.stopPropagation();
|
|
340
|
+
}
|
|
341
|
+
cancelAutoClose();
|
|
342
|
+
scrollDismissActive.value = true;
|
|
343
|
+
const nextOffset = offset.value - deltaX;
|
|
344
|
+
const direction = nextOffset > 0 ? 1 : -1;
|
|
345
|
+
if (shouldDismiss(nextOffset, 0)) {
|
|
346
|
+
dismissNotification(direction);
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
setSwipeOffset(nextOffset);
|
|
350
|
+
scheduleScrollDismissReset();
|
|
351
|
+
};
|
|
352
|
+
const handleMouseEnter = () => {
|
|
353
|
+
hovered.value = true;
|
|
354
|
+
cancelAutoClose();
|
|
355
|
+
props.onHoverStart?.();
|
|
356
|
+
};
|
|
357
|
+
const handleMouseLeave = () => {
|
|
358
|
+
hovered.value = false;
|
|
359
|
+
if (!scrollDismissActive.value) {
|
|
360
|
+
resetSwipe();
|
|
361
|
+
handleAutoClose();
|
|
362
|
+
}
|
|
363
|
+
props.onHoverEnd?.();
|
|
364
|
+
};
|
|
365
|
+
const handleResize = () => {
|
|
366
|
+
if (dismissed.value) setSwipeOffset(getExitOffset(dismissDirection.value));
|
|
367
|
+
};
|
|
368
|
+
(0, vue.watch)(() => scrollDismissActive.value, (value, _, onCleanup) => {
|
|
369
|
+
if (!value) return;
|
|
370
|
+
document.addEventListener("wheel", handleWheel, { passive: false });
|
|
371
|
+
onCleanup(() => document.removeEventListener("wheel", handleWheel));
|
|
372
|
+
});
|
|
373
|
+
(0, vue.watch)([
|
|
374
|
+
autoCloseDuration,
|
|
375
|
+
active,
|
|
376
|
+
dismissed,
|
|
377
|
+
() => props.paused
|
|
378
|
+
], () => {
|
|
379
|
+
if (props.paused) cancelAutoClose();
|
|
380
|
+
else handleAutoClose();
|
|
381
|
+
}, { immediate: true });
|
|
382
|
+
(0, vue.onMounted)(() => {
|
|
383
|
+
props.data.onOpen?.(props.data);
|
|
384
|
+
notificationRef.value?.addEventListener("wheel", handleWheel, { passive: false });
|
|
385
|
+
window.addEventListener("resize", handleResize);
|
|
386
|
+
});
|
|
387
|
+
(0, vue.onBeforeUnmount)(() => {
|
|
388
|
+
cancelAutoClose();
|
|
389
|
+
cancelHide();
|
|
390
|
+
cancelScrollDismissReset();
|
|
391
|
+
cancelPointerDrag(false);
|
|
392
|
+
notificationRef.value?.removeEventListener("wheel", handleWheel);
|
|
393
|
+
window.removeEventListener("resize", handleResize);
|
|
394
|
+
});
|
|
395
|
+
return () => {
|
|
396
|
+
const resolvedAttrsStyle = normalizeStyle(attrs.style);
|
|
397
|
+
const resolvedDataStyle = normalizeStyle(props.data.style);
|
|
398
|
+
const baseStyle = {
|
|
399
|
+
...resolvedAttrsStyle,
|
|
400
|
+
...resolvedDataStyle
|
|
401
|
+
};
|
|
402
|
+
const baseOpacity = typeof baseStyle.opacity === "number" ? baseStyle.opacity : 1;
|
|
403
|
+
const swipeOpacity = dismissed.value ? 0 : 1 - Math.min(Math.abs(offset.value) / 200, 1) * .6;
|
|
404
|
+
const resolvedTransitionDuration = baseStyle.transitionDuration ?? `${props.transitionDuration}ms, ${props.transitionDuration}ms, ${props.transitionDuration}ms`;
|
|
405
|
+
const notificationStyle = {
|
|
406
|
+
...baseStyle,
|
|
407
|
+
"--notifications-state-transform": typeof baseStyle.transform === "string" ? baseStyle.transform : "translateX(0)",
|
|
408
|
+
"--notifications-state-opacity": String(baseOpacity),
|
|
409
|
+
"--notifications-swipe-offset": `${offset.value}px`,
|
|
410
|
+
"--notifications-swipe-opacity": String(swipeOpacity),
|
|
411
|
+
transform: "var(--notifications-state-transform) translate3d(var(--notifications-swipe-offset), 0, 0)",
|
|
412
|
+
opacity: "calc(var(--notifications-state-opacity) * var(--notifications-swipe-opacity))",
|
|
413
|
+
transitionDuration: active.value || scrollDismissActive.value ? "0ms, 0ms, 0ms" : resolvedTransitionDuration,
|
|
414
|
+
cursor: "default",
|
|
415
|
+
touchAction: "pan-y"
|
|
416
|
+
};
|
|
417
|
+
return (0, vue.h)(_mantine_vue_core.Notification, {
|
|
418
|
+
...attrs,
|
|
419
|
+
...getNotificationProps(props.data),
|
|
420
|
+
ref: (node) => {
|
|
421
|
+
notificationRef.value = node?.$el ?? node;
|
|
422
|
+
},
|
|
423
|
+
style: notificationStyle,
|
|
424
|
+
withCloseButton: isCloseDisabled.value ? false : props.data.withCloseButton,
|
|
425
|
+
onClose: handleHide,
|
|
426
|
+
onMouseenter: handleMouseEnter,
|
|
427
|
+
onMouseleave: handleMouseLeave,
|
|
428
|
+
onPointerdown: handlePointerDown
|
|
429
|
+
}, () => renderContent(props.data.message));
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
var Notifications_module_default = {
|
|
434
|
+
root: "_root_1izcx_1",
|
|
435
|
+
notification: "_notification_1izcx_40"
|
|
436
|
+
};
|
|
437
|
+
//#endregion
|
|
438
|
+
//#region src/Notifications.ts
|
|
439
|
+
var defaultProps = {
|
|
440
|
+
position: "bottom-right",
|
|
441
|
+
autoClose: 4e3,
|
|
442
|
+
transitionDuration: 250,
|
|
443
|
+
allowDragDismiss: true,
|
|
444
|
+
allowScrollDismiss: true,
|
|
445
|
+
containerWidth: 440,
|
|
446
|
+
notificationMaxHeight: 200,
|
|
447
|
+
limit: 5,
|
|
448
|
+
zIndex: (0, _mantine_vue_core.getDefaultZIndex)("overlay"),
|
|
449
|
+
store: notificationsStore,
|
|
450
|
+
withinPortal: true,
|
|
451
|
+
pauseResetOnHover: "all"
|
|
452
|
+
};
|
|
453
|
+
var varsResolver = (0, _mantine_vue_core.createVarsResolver)((_, { zIndex, containerWidth }) => ({ root: {
|
|
454
|
+
"--notifications-z-index": zIndex?.toString(),
|
|
455
|
+
"--notifications-container-width": (0, _mantine_vue_core.rem)(containerWidth)
|
|
456
|
+
} }));
|
|
457
|
+
function applyTransitionStyles(element, state, position, transitionDuration, maxHeight) {
|
|
458
|
+
Object.assign(element.style, getNotificationStateStyles({
|
|
459
|
+
state,
|
|
460
|
+
position,
|
|
461
|
+
transitionDuration,
|
|
462
|
+
maxHeight
|
|
463
|
+
}));
|
|
464
|
+
}
|
|
465
|
+
var NotificationsBase = (0, vue.defineComponent)({
|
|
466
|
+
name: "Notifications",
|
|
467
|
+
inheritAttrs: false,
|
|
468
|
+
props: {
|
|
469
|
+
position: {
|
|
470
|
+
type: String,
|
|
471
|
+
default: void 0
|
|
472
|
+
},
|
|
473
|
+
autoClose: {
|
|
474
|
+
type: [Number, Boolean],
|
|
475
|
+
default: void 0
|
|
476
|
+
},
|
|
477
|
+
transitionDuration: {
|
|
478
|
+
type: Number,
|
|
479
|
+
default: void 0
|
|
480
|
+
},
|
|
481
|
+
allowDragDismiss: {
|
|
482
|
+
type: Boolean,
|
|
483
|
+
default: void 0
|
|
484
|
+
},
|
|
485
|
+
allowScrollDismiss: {
|
|
486
|
+
type: Boolean,
|
|
487
|
+
default: void 0
|
|
488
|
+
},
|
|
489
|
+
containerWidth: {
|
|
490
|
+
type: [Number, String],
|
|
491
|
+
default: void 0
|
|
492
|
+
},
|
|
493
|
+
notificationMaxHeight: {
|
|
494
|
+
type: [Number, String],
|
|
495
|
+
default: void 0
|
|
496
|
+
},
|
|
497
|
+
limit: {
|
|
498
|
+
type: Number,
|
|
499
|
+
default: void 0
|
|
500
|
+
},
|
|
501
|
+
zIndex: {
|
|
502
|
+
type: [Number, String],
|
|
503
|
+
default: void 0
|
|
504
|
+
},
|
|
505
|
+
portalProps: {
|
|
506
|
+
type: Object,
|
|
507
|
+
default: void 0
|
|
508
|
+
},
|
|
509
|
+
store: {
|
|
510
|
+
type: Object,
|
|
511
|
+
default: void 0
|
|
512
|
+
},
|
|
513
|
+
withinPortal: {
|
|
514
|
+
type: Boolean,
|
|
515
|
+
default: void 0
|
|
516
|
+
},
|
|
517
|
+
pauseResetOnHover: {
|
|
518
|
+
type: String,
|
|
519
|
+
default: void 0
|
|
520
|
+
},
|
|
521
|
+
classNames: {
|
|
522
|
+
type: [Object, Function],
|
|
523
|
+
default: void 0
|
|
524
|
+
},
|
|
525
|
+
styles: {
|
|
526
|
+
type: [Object, Function],
|
|
527
|
+
default: void 0
|
|
528
|
+
},
|
|
529
|
+
vars: {
|
|
530
|
+
type: [Object, Function],
|
|
531
|
+
default: void 0
|
|
532
|
+
},
|
|
533
|
+
unstyled: {
|
|
534
|
+
type: Boolean,
|
|
535
|
+
default: false
|
|
536
|
+
}
|
|
537
|
+
},
|
|
538
|
+
setup(rawProps, { attrs }) {
|
|
539
|
+
const props = (0, _mantine_vue_core.useProps)("Notifications", defaultProps, rawProps);
|
|
540
|
+
const theme = (0, _mantine_vue_core.useMantineTheme)();
|
|
541
|
+
const shouldReduceMotion = (0, _mantine_vue_hooks.useReducedMotion)();
|
|
542
|
+
const hoveredCount = (0, vue.ref)(0);
|
|
543
|
+
const data = useNotifications(props.store);
|
|
544
|
+
const reduceMotion = (0, vue.computed)(() => theme.value.respectReducedMotion ? shouldReduceMotion.value : false);
|
|
545
|
+
const duration = (0, vue.computed)(() => reduceMotion.value ? 1 : props.transitionDuration);
|
|
546
|
+
const getStyles = (0, _mantine_vue_core.useStyles)({
|
|
547
|
+
name: "Notifications",
|
|
548
|
+
classes: Notifications_module_default,
|
|
549
|
+
props,
|
|
550
|
+
className: attrs.class,
|
|
551
|
+
style: attrs.style,
|
|
552
|
+
classNames: props.classNames,
|
|
553
|
+
styles: props.styles,
|
|
554
|
+
unstyled: props.unstyled,
|
|
555
|
+
vars: props.vars,
|
|
556
|
+
varsResolver
|
|
557
|
+
});
|
|
558
|
+
(0, vue.watch)(() => [
|
|
559
|
+
props.limit,
|
|
560
|
+
props.position,
|
|
561
|
+
props.store
|
|
562
|
+
], () => {
|
|
563
|
+
props.store?.setState((current) => ({
|
|
564
|
+
...current,
|
|
565
|
+
limit: props.limit || 5,
|
|
566
|
+
defaultPosition: props.position
|
|
567
|
+
}));
|
|
568
|
+
}, { immediate: true });
|
|
569
|
+
const handleHoverStart = () => {
|
|
570
|
+
hoveredCount.value += 1;
|
|
571
|
+
};
|
|
572
|
+
const handleHoverEnd = () => {
|
|
573
|
+
hoveredCount.value = Math.max(0, hoveredCount.value - 1);
|
|
574
|
+
};
|
|
575
|
+
return () => {
|
|
576
|
+
const grouped = getGroupedNotifications(data.value.notifications, props.position);
|
|
577
|
+
const rootProps = (position) => ({
|
|
578
|
+
...attrs,
|
|
579
|
+
...getStyles("root"),
|
|
580
|
+
"data-position": position
|
|
581
|
+
});
|
|
582
|
+
const renderGroup = (position) => (0, vue.h)(_mantine_vue_core.Box, rootProps(position), () => (0, vue.h)(vue.TransitionGroup, {
|
|
583
|
+
css: false,
|
|
584
|
+
onBeforeEnter: (el) => applyTransitionStyles(el, "exited", position, duration.value, props.notificationMaxHeight),
|
|
585
|
+
onEnter: (el, done) => {
|
|
586
|
+
el.offsetHeight;
|
|
587
|
+
applyTransitionStyles(el, "entered", position, duration.value, props.notificationMaxHeight);
|
|
588
|
+
window.setTimeout(done, duration.value);
|
|
589
|
+
},
|
|
590
|
+
onLeave: (el, done) => {
|
|
591
|
+
applyTransitionStyles(el, "exiting", position, duration.value, props.notificationMaxHeight);
|
|
592
|
+
window.setTimeout(done, duration.value);
|
|
593
|
+
}
|
|
594
|
+
}, () => grouped[position].map(({ style: notificationStyle, ...notification }) => (0, vue.h)(NotificationContainer, {
|
|
595
|
+
key: notification.id,
|
|
596
|
+
data: notification,
|
|
597
|
+
onHide: (id) => hideNotification(id, props.store),
|
|
598
|
+
autoClose: props.autoClose,
|
|
599
|
+
transitionDuration: duration.value,
|
|
600
|
+
allowDragDismiss: props.allowDragDismiss,
|
|
601
|
+
allowScrollDismiss: props.allowScrollDismiss,
|
|
602
|
+
paused: props.pauseResetOnHover === "all" ? hoveredCount.value > 0 : false,
|
|
603
|
+
onHoverStart: handleHoverStart,
|
|
604
|
+
onHoverEnd: handleHoverEnd,
|
|
605
|
+
...getStyles("notification", { style: notificationStyle })
|
|
606
|
+
}))));
|
|
607
|
+
return (0, vue.h)(_mantine_vue_core.OptionalPortal, {
|
|
608
|
+
withinPortal: props.withinPortal,
|
|
609
|
+
...props.portalProps
|
|
610
|
+
}, () => positions.map((position) => renderGroup(position)));
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
});
|
|
614
|
+
var Notifications = Object.assign(NotificationsBase, {
|
|
615
|
+
classes: Notifications_module_default,
|
|
616
|
+
varsResolver,
|
|
617
|
+
show: notifications.show,
|
|
618
|
+
hide: notifications.hide,
|
|
619
|
+
update: notifications.update,
|
|
620
|
+
clean: notifications.clean,
|
|
621
|
+
cleanQueue: notifications.cleanQueue,
|
|
622
|
+
updateState: notifications.updateState
|
|
623
|
+
});
|
|
624
|
+
//#endregion
|
|
625
|
+
exports.Notifications = Notifications;
|
|
626
|
+
exports.cleanNotifications = cleanNotifications;
|
|
627
|
+
exports.cleanNotificationsQueue = cleanNotificationsQueue;
|
|
628
|
+
exports.createNotificationsStore = createNotificationsStore;
|
|
629
|
+
exports.hideNotification = hideNotification;
|
|
630
|
+
exports.notifications = notifications;
|
|
631
|
+
exports.notificationsStore = notificationsStore;
|
|
632
|
+
exports.showNotification = showNotification;
|
|
633
|
+
exports.updateNotification = updateNotification;
|
|
634
|
+
exports.updateNotificationsState = updateNotificationsState;
|
|
635
|
+
exports.useNotifications = useNotifications;
|
|
636
|
+
|
|
637
|
+
//# sourceMappingURL=index.cjs.map
|