@v-c/notification 0.0.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Notice.cjs +19 -14
- package/dist/Notice.js +7 -5
- package/dist/NoticeList.cjs +30 -17
- package/dist/NoticeList.js +18 -8
- package/dist/NotificationProvider.cjs +1 -0
- package/dist/Notifications.cjs +5 -5
- package/dist/Notifications.js +1 -4
- package/dist/hooks/useNotification.cjs +25 -12
- package/dist/hooks/useNotification.d.ts +2 -2
- package/dist/hooks/useNotification.js +22 -12
- package/dist/hooks/useStack.cjs +4 -1
- package/dist/index.cjs +1 -0
- package/dist/interface.cjs +1 -0
- package/package.json +2 -2
- package/src/NoticeList.tsx +24 -8
- package/src/hooks/useNotification.tsx +41 -25
- package/src/interface.ts +1 -1
- package/vitest.config.ts +1 -1
package/dist/Notice.cjs
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
Object.
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
2
5
|
const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
3
6
|
let vue = require("vue");
|
|
4
|
-
let
|
|
5
|
-
let
|
|
6
|
-
|
|
7
|
-
let
|
|
8
|
-
|
|
7
|
+
let _v_c_util = require("@v-c/util");
|
|
8
|
+
let _v_c_util_dist_KeyCode = require("@v-c/util/dist/KeyCode");
|
|
9
|
+
_v_c_util_dist_KeyCode = require_rolldown_runtime.__toESM(_v_c_util_dist_KeyCode);
|
|
10
|
+
let _v_c_util_dist_pickAttrs = require("@v-c/util/dist/pickAttrs");
|
|
11
|
+
_v_c_util_dist_pickAttrs = require_rolldown_runtime.__toESM(_v_c_util_dist_pickAttrs);
|
|
9
12
|
var defaults = {
|
|
10
13
|
duration: 4.5,
|
|
11
14
|
pauseOnHover: true,
|
|
@@ -28,7 +31,7 @@ var Notify = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs }) => {
|
|
|
28
31
|
props.onNoticeClose?.(props.eventKey);
|
|
29
32
|
};
|
|
30
33
|
const onCloseKeyDown = (e) => {
|
|
31
|
-
if (e.key === "Enter" || e.code === "Enter" || e.keyCode ===
|
|
34
|
+
if (e.key === "Enter" || e.code === "Enter" || e.keyCode === _v_c_util_dist_KeyCode.default.ENTER) onInternalClose();
|
|
32
35
|
};
|
|
33
36
|
(0, vue.watch)([
|
|
34
37
|
() => props.times,
|
|
@@ -82,7 +85,7 @@ var Notify = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs }) => {
|
|
|
82
85
|
return () => {
|
|
83
86
|
const { closable, prefixCls, props: divProps, onClick, content, className, style } = props;
|
|
84
87
|
const closableConfig = typeof closable === "object" && closable !== null ? closable : closable ? { closeIcon: mergedCloseIcon.value } : {};
|
|
85
|
-
const ariaProps = (0,
|
|
88
|
+
const ariaProps = (0, _v_c_util_dist_pickAttrs.default)(closableConfig, true);
|
|
86
89
|
const validPercent = 100 - (percent.value <= 0 ? 0 : percent.value > 100 ? 100 : percent.value);
|
|
87
90
|
const noticePrefixCls = `${prefixCls}-notice`;
|
|
88
91
|
const mergedStyle = {
|
|
@@ -91,7 +94,7 @@ var Notify = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs }) => {
|
|
|
91
94
|
...typeof style === "object" && style ? style : {}
|
|
92
95
|
};
|
|
93
96
|
return (0, vue.createVNode)("div", (0, vue.mergeProps)(divProps, {
|
|
94
|
-
"class": (0,
|
|
97
|
+
"class": (0, _v_c_util.classNames)(noticePrefixCls, className, attrs.class, { [`${noticePrefixCls}-closable`]: !!closable }),
|
|
95
98
|
"style": mergedStyle,
|
|
96
99
|
"onMouseenter": (e) => {
|
|
97
100
|
hovering.value = true;
|
|
@@ -154,6 +157,8 @@ var Notify = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs }) => {
|
|
|
154
157
|
},
|
|
155
158
|
content: {
|
|
156
159
|
type: [
|
|
160
|
+
Object,
|
|
161
|
+
Function,
|
|
157
162
|
String,
|
|
158
163
|
Number,
|
|
159
164
|
null,
|
|
@@ -161,7 +166,6 @@ var Notify = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs }) => {
|
|
|
161
166
|
Array
|
|
162
167
|
],
|
|
163
168
|
required: false,
|
|
164
|
-
skipCheck: true,
|
|
165
169
|
default: void 0
|
|
166
170
|
},
|
|
167
171
|
duration: {
|
|
@@ -185,6 +189,8 @@ var Notify = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs }) => {
|
|
|
185
189
|
},
|
|
186
190
|
closeIcon: {
|
|
187
191
|
type: [
|
|
192
|
+
Object,
|
|
193
|
+
Function,
|
|
188
194
|
String,
|
|
189
195
|
Number,
|
|
190
196
|
null,
|
|
@@ -192,7 +198,6 @@ var Notify = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs }) => {
|
|
|
192
198
|
Array
|
|
193
199
|
],
|
|
194
200
|
required: false,
|
|
195
|
-
skipCheck: true,
|
|
196
201
|
default: void 0
|
|
197
202
|
},
|
|
198
203
|
closable: {
|
|
@@ -206,17 +211,17 @@ var Notify = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs }) => {
|
|
|
206
211
|
default: void 0
|
|
207
212
|
},
|
|
208
213
|
style: {
|
|
209
|
-
type:
|
|
214
|
+
type: Object,
|
|
210
215
|
required: false,
|
|
211
216
|
default: void 0
|
|
212
217
|
},
|
|
213
218
|
classNames: {
|
|
214
|
-
type:
|
|
219
|
+
type: Object,
|
|
215
220
|
required: false,
|
|
216
221
|
default: void 0
|
|
217
222
|
},
|
|
218
223
|
styles: {
|
|
219
|
-
type:
|
|
224
|
+
type: Object,
|
|
220
225
|
required: false,
|
|
221
226
|
default: void 0
|
|
222
227
|
},
|
package/dist/Notice.js
CHANGED
|
@@ -150,6 +150,8 @@ var Notice_default = /* @__PURE__ */ defineComponent((props, { attrs }) => {
|
|
|
150
150
|
},
|
|
151
151
|
content: {
|
|
152
152
|
type: [
|
|
153
|
+
Object,
|
|
154
|
+
Function,
|
|
153
155
|
String,
|
|
154
156
|
Number,
|
|
155
157
|
null,
|
|
@@ -157,7 +159,6 @@ var Notice_default = /* @__PURE__ */ defineComponent((props, { attrs }) => {
|
|
|
157
159
|
Array
|
|
158
160
|
],
|
|
159
161
|
required: false,
|
|
160
|
-
skipCheck: true,
|
|
161
162
|
default: void 0
|
|
162
163
|
},
|
|
163
164
|
duration: {
|
|
@@ -181,6 +182,8 @@ var Notice_default = /* @__PURE__ */ defineComponent((props, { attrs }) => {
|
|
|
181
182
|
},
|
|
182
183
|
closeIcon: {
|
|
183
184
|
type: [
|
|
185
|
+
Object,
|
|
186
|
+
Function,
|
|
184
187
|
String,
|
|
185
188
|
Number,
|
|
186
189
|
null,
|
|
@@ -188,7 +191,6 @@ var Notice_default = /* @__PURE__ */ defineComponent((props, { attrs }) => {
|
|
|
188
191
|
Array
|
|
189
192
|
],
|
|
190
193
|
required: false,
|
|
191
|
-
skipCheck: true,
|
|
192
194
|
default: void 0
|
|
193
195
|
},
|
|
194
196
|
closable: {
|
|
@@ -202,17 +204,17 @@ var Notice_default = /* @__PURE__ */ defineComponent((props, { attrs }) => {
|
|
|
202
204
|
default: void 0
|
|
203
205
|
},
|
|
204
206
|
style: {
|
|
205
|
-
type:
|
|
207
|
+
type: Object,
|
|
206
208
|
required: false,
|
|
207
209
|
default: void 0
|
|
208
210
|
},
|
|
209
211
|
classNames: {
|
|
210
|
-
type:
|
|
212
|
+
type: Object,
|
|
211
213
|
required: false,
|
|
212
214
|
default: void 0
|
|
213
215
|
},
|
|
214
216
|
styles: {
|
|
215
|
-
type:
|
|
217
|
+
type: Object,
|
|
216
218
|
required: false,
|
|
217
219
|
default: void 0
|
|
218
220
|
},
|
package/dist/NoticeList.cjs
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
Object.
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
2
5
|
const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
3
6
|
const require_Notice = require("./Notice.cjs");
|
|
4
7
|
const require_useStack = require("./hooks/useStack.cjs");
|
|
5
8
|
const require_NotificationProvider = require("./NotificationProvider.cjs");
|
|
6
9
|
let vue = require("vue");
|
|
7
|
-
let
|
|
8
|
-
let
|
|
9
|
-
let
|
|
10
|
+
let _v_c_util = require("@v-c/util");
|
|
11
|
+
let _v_c_util_dist_utils_transition = require("@v-c/util/dist/utils/transition");
|
|
12
|
+
let _v_c_util_dist_vueuse_unref_element = require("@v-c/util/dist/vueuse/unref-element");
|
|
10
13
|
function _isSlot(s) {
|
|
11
14
|
return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !(0, vue.isVNode)(s);
|
|
12
15
|
}
|
|
@@ -19,8 +22,14 @@ var NoticeList = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs }) =>
|
|
|
19
22
|
})));
|
|
20
23
|
const latestNotice = (0, vue.shallowRef)(null);
|
|
21
24
|
const hoverKeys = (0, vue.ref)([]);
|
|
22
|
-
const
|
|
23
|
-
const
|
|
25
|
+
const stackConfig = (0, vue.toRef)(props, "stack");
|
|
26
|
+
const [stackEnabled, stackOptions] = require_useStack.default(stackConfig);
|
|
27
|
+
const stackActive = (0, vue.computed)(() => stackEnabled.value || stackConfig.value === false);
|
|
28
|
+
const expanded = (0, vue.computed)(() => {
|
|
29
|
+
if (!stackActive.value) return false;
|
|
30
|
+
if (!stackEnabled.value) return true;
|
|
31
|
+
return hoverKeys.value.length > 0 || keys.value.length <= stackOptions.threshold.value;
|
|
32
|
+
});
|
|
24
33
|
const placementMotion = (0, vue.computed)(() => {
|
|
25
34
|
if (typeof props.motion === "function") return props.placement ? props.motion(props.placement) : void 0;
|
|
26
35
|
return props.motion;
|
|
@@ -32,8 +41,11 @@ var NoticeList = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs }) =>
|
|
|
32
41
|
], () => {
|
|
33
42
|
if (stackEnabled.value && hoverKeys.value.length > 1) hoverKeys.value = hoverKeys.value.filter((key) => keys.value.some(({ key: dataKey }) => key === dataKey));
|
|
34
43
|
});
|
|
44
|
+
(0, vue.watch)(stackEnabled, (enabled) => {
|
|
45
|
+
if (!enabled && hoverKeys.value.length) hoverKeys.value = [];
|
|
46
|
+
});
|
|
35
47
|
(0, vue.watchEffect)(() => {
|
|
36
|
-
if (!
|
|
48
|
+
if (!stackActive.value) {
|
|
37
49
|
latestNotice.value = null;
|
|
38
50
|
return;
|
|
39
51
|
}
|
|
@@ -50,10 +62,10 @@ var NoticeList = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs }) =>
|
|
|
50
62
|
const renderNotify = () => keys.value.map(({ config }, motionIndex) => {
|
|
51
63
|
const { key, times } = config;
|
|
52
64
|
const strKey = String(key);
|
|
53
|
-
const { className: configClassName, style: configStyle, classNames: configClassNames, styles: configStyles
|
|
65
|
+
const { className: configClassName, style: configStyle, classNames: configClassNames, styles: configStyles, ...restConfig } = config;
|
|
54
66
|
const dataIndex = keys.value.findIndex((item) => item.key === strKey);
|
|
55
67
|
const stackStyle = {};
|
|
56
|
-
if (
|
|
68
|
+
if (stackActive.value) {
|
|
57
69
|
const index = keys.value.length - 1 - (dataIndex > -1 ? dataIndex : motionIndex - 1);
|
|
58
70
|
const transformX = placement === "top" || placement === "bottom" ? "-50%" : "0";
|
|
59
71
|
if (index > 0) {
|
|
@@ -73,27 +85,29 @@ var NoticeList = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs }) =>
|
|
|
73
85
|
}
|
|
74
86
|
return (0, vue.createVNode)("div", {
|
|
75
87
|
"key": strKey,
|
|
76
|
-
"class": (0,
|
|
88
|
+
"class": (0, _v_c_util.classNames)(`${prefixCls}-notice-wrapper`, configClassNames?.wrapper),
|
|
77
89
|
"style": {
|
|
78
90
|
...stackStyle,
|
|
79
91
|
...configStyles?.wrapper
|
|
80
92
|
},
|
|
81
93
|
"onMouseenter": () => {
|
|
94
|
+
if (!stackEnabled.value) return;
|
|
82
95
|
hoverKeys.value = hoverKeys.value.includes(strKey) ? hoverKeys.value : [...hoverKeys.value, strKey];
|
|
83
96
|
},
|
|
84
97
|
"onMouseleave": () => {
|
|
98
|
+
if (!stackEnabled.value) return;
|
|
85
99
|
hoverKeys.value = hoverKeys.value.filter((k) => k !== strKey);
|
|
86
100
|
}
|
|
87
101
|
}, [(0, vue.createVNode)(require_Notice.default, (0, vue.mergeProps)(restConfig, {
|
|
88
102
|
"ref": (el) => {
|
|
89
|
-
const element = (0,
|
|
103
|
+
const element = (0, _v_c_util_dist_vueuse_unref_element.unrefElement)(el) ?? void 0;
|
|
90
104
|
if (dataIndex > -1) dictRef[strKey] = element;
|
|
91
105
|
else delete dictRef[strKey];
|
|
92
106
|
},
|
|
93
107
|
"prefixCls": prefixCls,
|
|
94
108
|
"classNames": configClassNames,
|
|
95
109
|
"styles": configStyles,
|
|
96
|
-
"class": (0,
|
|
110
|
+
"class": (0, _v_c_util.classNames)(configClassName, ctx.value?.classNames?.notice),
|
|
97
111
|
"style": configStyle,
|
|
98
112
|
"times": times,
|
|
99
113
|
"eventKey": key,
|
|
@@ -102,15 +116,15 @@ var NoticeList = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs }) =>
|
|
|
102
116
|
}), null)]);
|
|
103
117
|
});
|
|
104
118
|
let motionGroupProps = {};
|
|
105
|
-
if (placementMotion.value) motionGroupProps = (0,
|
|
119
|
+
if (placementMotion.value) motionGroupProps = (0, _v_c_util_dist_utils_transition.getTransitionGroupProps)(placementMotion.value.name, placementMotion.value);
|
|
106
120
|
return (0, vue.createVNode)(vue.TransitionGroup, (0, vue.mergeProps)({
|
|
107
121
|
"key": placement,
|
|
108
122
|
"tag": "div",
|
|
109
123
|
"appear": true
|
|
110
124
|
}, {
|
|
111
|
-
class: (0,
|
|
125
|
+
class: (0, _v_c_util.classNames)(prefixCls, `${prefixCls}-${placement}`, ctx.value?.classNames?.list, attrs.class, {
|
|
112
126
|
[`${prefixCls}-stack-expanded`]: expanded.value,
|
|
113
|
-
[`${prefixCls}-stack`]:
|
|
127
|
+
[`${prefixCls}-stack`]: stackActive.value
|
|
114
128
|
}),
|
|
115
129
|
style: attrs.style
|
|
116
130
|
}, motionGroupProps, { "onAfterLeave": checkAllClosed }), _isSlot(_slot = renderNotify()) ? _slot : { default: () => [_slot] });
|
|
@@ -132,9 +146,8 @@ var NoticeList = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs }) =>
|
|
|
132
146
|
default: void 0
|
|
133
147
|
},
|
|
134
148
|
motion: {
|
|
135
|
-
type: Function,
|
|
149
|
+
type: [Object, Function],
|
|
136
150
|
required: false,
|
|
137
|
-
skipCheck: true,
|
|
138
151
|
default: void 0
|
|
139
152
|
},
|
|
140
153
|
stack: {
|
package/dist/NoticeList.js
CHANGED
|
@@ -17,8 +17,14 @@ var NoticeList_default = /* @__PURE__ */ defineComponent((props, { attrs }) => {
|
|
|
17
17
|
})));
|
|
18
18
|
const latestNotice = shallowRef(null);
|
|
19
19
|
const hoverKeys = ref([]);
|
|
20
|
-
const
|
|
21
|
-
const
|
|
20
|
+
const stackConfig = toRef(props, "stack");
|
|
21
|
+
const [stackEnabled, stackOptions] = useStack_default(stackConfig);
|
|
22
|
+
const stackActive = computed(() => stackEnabled.value || stackConfig.value === false);
|
|
23
|
+
const expanded = computed(() => {
|
|
24
|
+
if (!stackActive.value) return false;
|
|
25
|
+
if (!stackEnabled.value) return true;
|
|
26
|
+
return hoverKeys.value.length > 0 || keys.value.length <= stackOptions.threshold.value;
|
|
27
|
+
});
|
|
22
28
|
const placementMotion = computed(() => {
|
|
23
29
|
if (typeof props.motion === "function") return props.placement ? props.motion(props.placement) : void 0;
|
|
24
30
|
return props.motion;
|
|
@@ -30,8 +36,11 @@ var NoticeList_default = /* @__PURE__ */ defineComponent((props, { attrs }) => {
|
|
|
30
36
|
], () => {
|
|
31
37
|
if (stackEnabled.value && hoverKeys.value.length > 1) hoverKeys.value = hoverKeys.value.filter((key) => keys.value.some(({ key: dataKey }) => key === dataKey));
|
|
32
38
|
});
|
|
39
|
+
watch(stackEnabled, (enabled) => {
|
|
40
|
+
if (!enabled && hoverKeys.value.length) hoverKeys.value = [];
|
|
41
|
+
});
|
|
33
42
|
watchEffect(() => {
|
|
34
|
-
if (!
|
|
43
|
+
if (!stackActive.value) {
|
|
35
44
|
latestNotice.value = null;
|
|
36
45
|
return;
|
|
37
46
|
}
|
|
@@ -48,10 +57,10 @@ var NoticeList_default = /* @__PURE__ */ defineComponent((props, { attrs }) => {
|
|
|
48
57
|
const renderNotify = () => keys.value.map(({ config }, motionIndex) => {
|
|
49
58
|
const { key, times } = config;
|
|
50
59
|
const strKey = String(key);
|
|
51
|
-
const { className: configClassName, style: configStyle, classNames: configClassNames, styles: configStyles
|
|
60
|
+
const { className: configClassName, style: configStyle, classNames: configClassNames, styles: configStyles, ...restConfig } = config;
|
|
52
61
|
const dataIndex = keys.value.findIndex((item) => item.key === strKey);
|
|
53
62
|
const stackStyle = {};
|
|
54
|
-
if (
|
|
63
|
+
if (stackActive.value) {
|
|
55
64
|
const index = keys.value.length - 1 - (dataIndex > -1 ? dataIndex : motionIndex - 1);
|
|
56
65
|
const transformX = placement === "top" || placement === "bottom" ? "-50%" : "0";
|
|
57
66
|
if (index > 0) {
|
|
@@ -77,9 +86,11 @@ var NoticeList_default = /* @__PURE__ */ defineComponent((props, { attrs }) => {
|
|
|
77
86
|
...configStyles?.wrapper
|
|
78
87
|
},
|
|
79
88
|
"onMouseenter": () => {
|
|
89
|
+
if (!stackEnabled.value) return;
|
|
80
90
|
hoverKeys.value = hoverKeys.value.includes(strKey) ? hoverKeys.value : [...hoverKeys.value, strKey];
|
|
81
91
|
},
|
|
82
92
|
"onMouseleave": () => {
|
|
93
|
+
if (!stackEnabled.value) return;
|
|
83
94
|
hoverKeys.value = hoverKeys.value.filter((k) => k !== strKey);
|
|
84
95
|
}
|
|
85
96
|
}, [createVNode(Notice_default, mergeProps(restConfig, {
|
|
@@ -108,7 +119,7 @@ var NoticeList_default = /* @__PURE__ */ defineComponent((props, { attrs }) => {
|
|
|
108
119
|
}, {
|
|
109
120
|
class: classNames(prefixCls, `${prefixCls}-${placement}`, ctx.value?.classNames?.list, attrs.class, {
|
|
110
121
|
[`${prefixCls}-stack-expanded`]: expanded.value,
|
|
111
|
-
[`${prefixCls}-stack`]:
|
|
122
|
+
[`${prefixCls}-stack`]: stackActive.value
|
|
112
123
|
}),
|
|
113
124
|
style: attrs.style
|
|
114
125
|
}, motionGroupProps, { "onAfterLeave": checkAllClosed }), _isSlot(_slot = renderNotify()) ? _slot : { default: () => [_slot] });
|
|
@@ -130,9 +141,8 @@ var NoticeList_default = /* @__PURE__ */ defineComponent((props, { attrs }) => {
|
|
|
130
141
|
default: void 0
|
|
131
142
|
},
|
|
132
143
|
motion: {
|
|
133
|
-
type: Function,
|
|
144
|
+
type: [Object, Function],
|
|
134
145
|
required: false,
|
|
135
|
-
skipCheck: true,
|
|
136
146
|
default: void 0
|
|
137
147
|
},
|
|
138
148
|
stack: {
|
package/dist/Notifications.cjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
Object.
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
2
5
|
const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
3
6
|
const require_NoticeList = require("./NoticeList.cjs");
|
|
4
7
|
let vue = require("vue");
|
|
@@ -99,13 +102,11 @@ var Notifications = /* @__PURE__ */ (0, vue.defineComponent)((props, { expose })
|
|
|
99
102
|
default: void 0
|
|
100
103
|
},
|
|
101
104
|
motion: {
|
|
102
|
-
type: Function,
|
|
105
|
+
type: [Object, Function],
|
|
103
106
|
required: false,
|
|
104
|
-
skipCheck: true,
|
|
105
107
|
default: void 0
|
|
106
108
|
},
|
|
107
109
|
container: {
|
|
108
|
-
type: null,
|
|
109
110
|
required: false,
|
|
110
111
|
default: void 0
|
|
111
112
|
},
|
|
@@ -125,7 +126,6 @@ var Notifications = /* @__PURE__ */ (0, vue.defineComponent)((props, { expose })
|
|
|
125
126
|
default: void 0
|
|
126
127
|
},
|
|
127
128
|
onAllRemoved: {
|
|
128
|
-
type: null,
|
|
129
129
|
required: false,
|
|
130
130
|
default: void 0
|
|
131
131
|
},
|
package/dist/Notifications.js
CHANGED
|
@@ -97,13 +97,11 @@ var Notifications_default = /* @__PURE__ */ defineComponent((props, { expose })
|
|
|
97
97
|
default: void 0
|
|
98
98
|
},
|
|
99
99
|
motion: {
|
|
100
|
-
type: Function,
|
|
100
|
+
type: [Object, Function],
|
|
101
101
|
required: false,
|
|
102
|
-
skipCheck: true,
|
|
103
102
|
default: void 0
|
|
104
103
|
},
|
|
105
104
|
container: {
|
|
106
|
-
type: null,
|
|
107
105
|
required: false,
|
|
108
106
|
default: void 0
|
|
109
107
|
},
|
|
@@ -123,7 +121,6 @@ var Notifications_default = /* @__PURE__ */ defineComponent((props, { expose })
|
|
|
123
121
|
default: void 0
|
|
124
122
|
},
|
|
125
123
|
onAllRemoved: {
|
|
126
|
-
type: null,
|
|
127
124
|
required: false,
|
|
128
125
|
default: void 0
|
|
129
126
|
},
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
Object.
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
2
5
|
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
6
|
const require_Notifications = require("../Notifications.cjs");
|
|
4
7
|
let vue = require("vue");
|
|
@@ -15,25 +18,32 @@ function mergeConfig(...objList) {
|
|
|
15
18
|
return clone;
|
|
16
19
|
}
|
|
17
20
|
function useNotification(rootConfig = {}) {
|
|
18
|
-
const
|
|
21
|
+
const configRef = (0, vue.computed)(() => (0, vue.unref)(rootConfig) || {});
|
|
19
22
|
const container = (0, vue.shallowRef)();
|
|
20
23
|
const notificationRef = (0, vue.shallowRef)();
|
|
24
|
+
const shareConfig = (0, vue.computed)(() => {
|
|
25
|
+
const { getContainer, motion, prefixCls, maxCount, className, style, onAllRemoved, stack, renderNotifications, ...restConfig } = configRef.value;
|
|
26
|
+
return restConfig;
|
|
27
|
+
});
|
|
28
|
+
const resolveContainer = () => {
|
|
29
|
+
return (configRef.value.getContainer || defaultGetContainer)();
|
|
30
|
+
};
|
|
21
31
|
const contextHolder = () => (0, vue.createVNode)(require_Notifications.default, {
|
|
22
32
|
"container": container.value,
|
|
23
33
|
"ref": notificationRef,
|
|
24
|
-
"prefixCls": prefixCls,
|
|
25
|
-
"motion": motion,
|
|
26
|
-
"maxCount": maxCount,
|
|
27
|
-
"className": className,
|
|
28
|
-
"style": style,
|
|
29
|
-
"onAllRemoved": onAllRemoved,
|
|
30
|
-
"stack": stack,
|
|
31
|
-
"renderNotifications": renderNotifications
|
|
34
|
+
"prefixCls": configRef.value.prefixCls,
|
|
35
|
+
"motion": configRef.value.motion,
|
|
36
|
+
"maxCount": configRef.value.maxCount,
|
|
37
|
+
"className": configRef.value.className,
|
|
38
|
+
"style": configRef.value.style,
|
|
39
|
+
"onAllRemoved": configRef.value.onAllRemoved,
|
|
40
|
+
"stack": configRef.value.stack,
|
|
41
|
+
"renderNotifications": configRef.value.renderNotifications
|
|
32
42
|
}, null);
|
|
33
43
|
const taskQueue = (0, vue.shallowRef)([]);
|
|
34
44
|
const api = {
|
|
35
45
|
open(config) {
|
|
36
|
-
const mergedConfig = mergeConfig(shareConfig, config);
|
|
46
|
+
const mergedConfig = mergeConfig(shareConfig.value, config);
|
|
37
47
|
if (mergedConfig.key === null || mergedConfig.key === void 0) {
|
|
38
48
|
mergedConfig.key = `vc-notification-${uniqueKey}`;
|
|
39
49
|
uniqueKey += 1;
|
|
@@ -54,7 +64,10 @@ function useNotification(rootConfig = {}) {
|
|
|
54
64
|
}
|
|
55
65
|
};
|
|
56
66
|
(0, vue.onMounted)(() => {
|
|
57
|
-
container.value =
|
|
67
|
+
container.value = resolveContainer();
|
|
68
|
+
});
|
|
69
|
+
(0, vue.watch)(() => configRef.value.getContainer, () => {
|
|
70
|
+
container.value = resolveContainer();
|
|
58
71
|
});
|
|
59
72
|
(0, vue.watch)(taskQueue, () => {
|
|
60
73
|
if (notificationRef.value && taskQueue.value.length) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { VueNode } from '@v-c/util/dist/type';
|
|
2
|
-
import { CSSProperties, TransitionGroupProps } from 'vue';
|
|
2
|
+
import { CSSProperties, MaybeRef, TransitionGroupProps } from 'vue';
|
|
3
3
|
import { Key, OpenConfig, Placement, StackConfig } from '../interface';
|
|
4
4
|
import { NotificationsProps } from '../Notifications';
|
|
5
5
|
type OptionalConfig = Partial<OpenConfig>;
|
|
@@ -32,5 +32,5 @@ export interface NotificationAPI {
|
|
|
32
32
|
close: (key: Key) => void;
|
|
33
33
|
destroy: () => void;
|
|
34
34
|
}
|
|
35
|
-
export default function useNotification(rootConfig?: NotificationConfig): [NotificationAPI, () => VueNode];
|
|
35
|
+
export default function useNotification(rootConfig?: MaybeRef<NotificationConfig>): [NotificationAPI, () => VueNode];
|
|
36
36
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Notifications_default from "../Notifications.js";
|
|
2
|
-
import { createVNode, onMounted, shallowRef, watch } from "vue";
|
|
2
|
+
import { computed, createVNode, onMounted, shallowRef, unref, watch } from "vue";
|
|
3
3
|
var defaultGetContainer = () => document.body;
|
|
4
4
|
var uniqueKey = 0;
|
|
5
5
|
function mergeConfig(...objList) {
|
|
@@ -13,25 +13,32 @@ function mergeConfig(...objList) {
|
|
|
13
13
|
return clone;
|
|
14
14
|
}
|
|
15
15
|
function useNotification(rootConfig = {}) {
|
|
16
|
-
const
|
|
16
|
+
const configRef = computed(() => unref(rootConfig) || {});
|
|
17
17
|
const container = shallowRef();
|
|
18
18
|
const notificationRef = shallowRef();
|
|
19
|
+
const shareConfig = computed(() => {
|
|
20
|
+
const { getContainer, motion, prefixCls, maxCount, className, style, onAllRemoved, stack, renderNotifications, ...restConfig } = configRef.value;
|
|
21
|
+
return restConfig;
|
|
22
|
+
});
|
|
23
|
+
const resolveContainer = () => {
|
|
24
|
+
return (configRef.value.getContainer || defaultGetContainer)();
|
|
25
|
+
};
|
|
19
26
|
const contextHolder = () => createVNode(Notifications_default, {
|
|
20
27
|
"container": container.value,
|
|
21
28
|
"ref": notificationRef,
|
|
22
|
-
"prefixCls": prefixCls,
|
|
23
|
-
"motion": motion,
|
|
24
|
-
"maxCount": maxCount,
|
|
25
|
-
"className": className,
|
|
26
|
-
"style": style,
|
|
27
|
-
"onAllRemoved": onAllRemoved,
|
|
28
|
-
"stack": stack,
|
|
29
|
-
"renderNotifications": renderNotifications
|
|
29
|
+
"prefixCls": configRef.value.prefixCls,
|
|
30
|
+
"motion": configRef.value.motion,
|
|
31
|
+
"maxCount": configRef.value.maxCount,
|
|
32
|
+
"className": configRef.value.className,
|
|
33
|
+
"style": configRef.value.style,
|
|
34
|
+
"onAllRemoved": configRef.value.onAllRemoved,
|
|
35
|
+
"stack": configRef.value.stack,
|
|
36
|
+
"renderNotifications": configRef.value.renderNotifications
|
|
30
37
|
}, null);
|
|
31
38
|
const taskQueue = shallowRef([]);
|
|
32
39
|
const api = {
|
|
33
40
|
open(config) {
|
|
34
|
-
const mergedConfig = mergeConfig(shareConfig, config);
|
|
41
|
+
const mergedConfig = mergeConfig(shareConfig.value, config);
|
|
35
42
|
if (mergedConfig.key === null || mergedConfig.key === void 0) {
|
|
36
43
|
mergedConfig.key = `vc-notification-${uniqueKey}`;
|
|
37
44
|
uniqueKey += 1;
|
|
@@ -52,7 +59,10 @@ function useNotification(rootConfig = {}) {
|
|
|
52
59
|
}
|
|
53
60
|
};
|
|
54
61
|
onMounted(() => {
|
|
55
|
-
container.value =
|
|
62
|
+
container.value = resolveContainer();
|
|
63
|
+
});
|
|
64
|
+
watch(() => configRef.value.getContainer, () => {
|
|
65
|
+
container.value = resolveContainer();
|
|
56
66
|
});
|
|
57
67
|
watch(taskQueue, () => {
|
|
58
68
|
if (notificationRef.value && taskQueue.value.length) {
|
package/dist/hooks/useStack.cjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
Object.
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
2
5
|
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
6
|
let vue = require("vue");
|
|
4
7
|
var DEFAULT_OFFSET = 8;
|
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
1
2
|
const require_Notice = require("./Notice.cjs");
|
|
2
3
|
const require_NotificationProvider = require("./NotificationProvider.cjs");
|
|
3
4
|
const require_useNotification = require("./hooks/useNotification.cjs");
|
package/dist/interface.cjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@v-c/notification",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "1.0.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"vue": "^3.0.0"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@v-c/util": "
|
|
22
|
+
"@v-c/util": "^1.0.9"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build": "vite build",
|
package/src/NoticeList.tsx
CHANGED
|
@@ -34,11 +34,16 @@ const NoticeList = defineComponent<NoticeListProps>((props, { attrs }) => {
|
|
|
34
34
|
|
|
35
35
|
const stackConfig = toRef(props, 'stack')
|
|
36
36
|
const [stackEnabled, stackOptions] = useStack(stackConfig)
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
const stackActive = computed(() => stackEnabled.value || stackConfig.value === false)
|
|
38
|
+
const expanded = computed(() => {
|
|
39
|
+
if (!stackActive.value) {
|
|
40
|
+
return false
|
|
41
|
+
}
|
|
42
|
+
if (!stackEnabled.value) {
|
|
43
|
+
return true
|
|
44
|
+
}
|
|
45
|
+
return hoverKeys.value.length > 0 || keys.value.length <= stackOptions.threshold!.value!
|
|
46
|
+
})
|
|
42
47
|
const placementMotion = computed(() => {
|
|
43
48
|
if (typeof props.motion === 'function') {
|
|
44
49
|
return props.placement ? props.motion(props.placement) : undefined
|
|
@@ -54,11 +59,16 @@ const NoticeList = defineComponent<NoticeListProps>((props, { attrs }) => {
|
|
|
54
59
|
)
|
|
55
60
|
}
|
|
56
61
|
})
|
|
62
|
+
watch(stackEnabled, (enabled) => {
|
|
63
|
+
if (!enabled && hoverKeys.value.length) {
|
|
64
|
+
hoverKeys.value = []
|
|
65
|
+
}
|
|
66
|
+
})
|
|
57
67
|
|
|
58
68
|
// Sync latest notice after DOM updates so collapsed stack uses accurate height
|
|
59
69
|
watchEffect(
|
|
60
70
|
() => {
|
|
61
|
-
if (!
|
|
71
|
+
if (!stackActive.value) {
|
|
62
72
|
latestNotice.value = null
|
|
63
73
|
return
|
|
64
74
|
}
|
|
@@ -95,7 +105,7 @@ const NoticeList = defineComponent<NoticeListProps>((props, { attrs }) => {
|
|
|
95
105
|
const dataIndex = keys.value.findIndex(item => item.key === strKey)
|
|
96
106
|
const stackStyle: CSSProperties = {}
|
|
97
107
|
|
|
98
|
-
if (
|
|
108
|
+
if (stackActive.value) {
|
|
99
109
|
const index = keys.value.length - 1 - (dataIndex > -1 ? dataIndex : motionIndex - 1)
|
|
100
110
|
const transformX = placement === 'top' || placement === 'bottom' ? '-50%' : '0'
|
|
101
111
|
if (index > 0) {
|
|
@@ -137,11 +147,17 @@ const NoticeList = defineComponent<NoticeListProps>((props, { attrs }) => {
|
|
|
137
147
|
...configStyles?.wrapper,
|
|
138
148
|
}}
|
|
139
149
|
onMouseenter={() => {
|
|
150
|
+
if (!stackEnabled.value) {
|
|
151
|
+
return
|
|
152
|
+
}
|
|
140
153
|
hoverKeys.value = hoverKeys.value.includes(strKey)
|
|
141
154
|
? hoverKeys.value
|
|
142
155
|
: [...hoverKeys.value, strKey]
|
|
143
156
|
}}
|
|
144
157
|
onMouseleave={() => {
|
|
158
|
+
if (!stackEnabled.value) {
|
|
159
|
+
return
|
|
160
|
+
}
|
|
145
161
|
hoverKeys.value = hoverKeys.value.filter(k => k !== strKey)
|
|
146
162
|
}}
|
|
147
163
|
>
|
|
@@ -186,7 +202,7 @@ const NoticeList = defineComponent<NoticeListProps>((props, { attrs }) => {
|
|
|
186
202
|
(attrs as any).class,
|
|
187
203
|
{
|
|
188
204
|
[`${prefixCls}-stack-expanded`]: expanded.value,
|
|
189
|
-
[`${prefixCls}-stack`]:
|
|
205
|
+
[`${prefixCls}-stack`]: stackActive.value,
|
|
190
206
|
},
|
|
191
207
|
),
|
|
192
208
|
style: (attrs as any).style,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { VueNode } from '@v-c/util/dist/type'
|
|
2
|
-
import type { CSSProperties, TransitionGroupProps } from 'vue'
|
|
2
|
+
import type { CSSProperties, MaybeRef, TransitionGroupProps } from 'vue'
|
|
3
3
|
import type { Key, OpenConfig, Placement, StackConfig } from '../interface'
|
|
4
4
|
import type { NotificationsProps, NotificationsRef } from '../Notifications'
|
|
5
|
-
import { onMounted, shallowRef, watch } from 'vue'
|
|
5
|
+
import { computed, onMounted, shallowRef, unref, watch } from 'vue'
|
|
6
6
|
import Notifications from '../Notifications'
|
|
7
7
|
|
|
8
8
|
const defaultGetContainer = () => document.body
|
|
@@ -75,35 +75,45 @@ function mergeConfig<T>(...objList: Partial<T>[]): T {
|
|
|
75
75
|
return clone
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
export default function useNotification(rootConfig: NotificationConfig = {}) {
|
|
79
|
-
const {
|
|
80
|
-
getContainer = defaultGetContainer,
|
|
81
|
-
motion,
|
|
82
|
-
prefixCls,
|
|
83
|
-
maxCount,
|
|
84
|
-
className,
|
|
85
|
-
style,
|
|
86
|
-
onAllRemoved,
|
|
87
|
-
stack,
|
|
88
|
-
renderNotifications,
|
|
89
|
-
...shareConfig
|
|
90
|
-
} = rootConfig
|
|
78
|
+
export default function useNotification(rootConfig: MaybeRef<NotificationConfig> = {}) {
|
|
79
|
+
const configRef = computed(() => unref(rootConfig) || {})
|
|
91
80
|
const container = shallowRef<HTMLElement | ShadowRoot>()
|
|
92
81
|
|
|
93
82
|
const notificationRef = shallowRef<NotificationsRef>()
|
|
94
83
|
|
|
84
|
+
const shareConfig = computed(() => {
|
|
85
|
+
const {
|
|
86
|
+
getContainer,
|
|
87
|
+
motion,
|
|
88
|
+
prefixCls,
|
|
89
|
+
maxCount,
|
|
90
|
+
className,
|
|
91
|
+
style,
|
|
92
|
+
onAllRemoved,
|
|
93
|
+
stack,
|
|
94
|
+
renderNotifications,
|
|
95
|
+
...restConfig
|
|
96
|
+
} = configRef.value
|
|
97
|
+
return restConfig
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
const resolveContainer = () => {
|
|
101
|
+
const getContainer = configRef.value.getContainer || defaultGetContainer
|
|
102
|
+
return getContainer()
|
|
103
|
+
}
|
|
104
|
+
|
|
95
105
|
const contextHolder = () => (
|
|
96
106
|
<Notifications
|
|
97
107
|
container={container.value}
|
|
98
108
|
ref={notificationRef}
|
|
99
|
-
prefixCls={prefixCls}
|
|
100
|
-
motion={motion}
|
|
101
|
-
maxCount={maxCount}
|
|
102
|
-
className={className}
|
|
103
|
-
style={style}
|
|
104
|
-
onAllRemoved={onAllRemoved}
|
|
105
|
-
stack={stack}
|
|
106
|
-
renderNotifications={renderNotifications}
|
|
109
|
+
prefixCls={configRef.value.prefixCls}
|
|
110
|
+
motion={configRef.value.motion}
|
|
111
|
+
maxCount={configRef.value.maxCount}
|
|
112
|
+
className={configRef.value.className}
|
|
113
|
+
style={configRef.value.style}
|
|
114
|
+
onAllRemoved={configRef.value.onAllRemoved}
|
|
115
|
+
stack={configRef.value.stack}
|
|
116
|
+
renderNotifications={configRef.value.renderNotifications}
|
|
107
117
|
/>
|
|
108
118
|
)
|
|
109
119
|
|
|
@@ -113,7 +123,7 @@ export default function useNotification(rootConfig: NotificationConfig = {}) {
|
|
|
113
123
|
|
|
114
124
|
const api: NotificationAPI = {
|
|
115
125
|
open(config) {
|
|
116
|
-
const mergedConfig = mergeConfig(shareConfig, config)
|
|
126
|
+
const mergedConfig = mergeConfig(shareConfig.value, config)
|
|
117
127
|
if (mergedConfig.key === null || mergedConfig.key === undefined) {
|
|
118
128
|
mergedConfig.key = `vc-notification-${uniqueKey}`
|
|
119
129
|
uniqueKey += 1
|
|
@@ -134,7 +144,13 @@ export default function useNotification(rootConfig: NotificationConfig = {}) {
|
|
|
134
144
|
// Which means getContainer should be stable.
|
|
135
145
|
onMounted(
|
|
136
146
|
() => {
|
|
137
|
-
container.value =
|
|
147
|
+
container.value = resolveContainer()
|
|
148
|
+
},
|
|
149
|
+
)
|
|
150
|
+
watch(
|
|
151
|
+
() => configRef.value.getContainer,
|
|
152
|
+
() => {
|
|
153
|
+
container.value = resolveContainer()
|
|
138
154
|
},
|
|
139
155
|
)
|
|
140
156
|
watch(taskQueue, () => {
|
package/src/interface.ts
CHANGED
|
@@ -14,7 +14,7 @@ export interface NoticeConfig {
|
|
|
14
14
|
closeIcon?: VueNode
|
|
15
15
|
closable?:
|
|
16
16
|
| boolean
|
|
17
|
-
| ({ closeIcon?: VueNode
|
|
17
|
+
| ({ closeIcon?: VueNode, onClose?: VoidFunction } & Record<string, any>)
|
|
18
18
|
className?: string
|
|
19
19
|
style?: CSSProperties
|
|
20
20
|
classNames?: {
|
package/vitest.config.ts
CHANGED