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