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