@v-c/notification 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/bump.config.ts +6 -0
  3. package/dist/Notice.cjs +230 -0
  4. package/dist/Notice.d.ts +15 -0
  5. package/dist/Notice.js +225 -0
  6. package/dist/NoticeList.cjs +157 -0
  7. package/dist/NoticeList.d.ts +13 -0
  8. package/dist/NoticeList.js +154 -0
  9. package/dist/NotificationProvider.cjs +13 -0
  10. package/dist/NotificationProvider.d.ts +10 -0
  11. package/dist/NotificationProvider.js +10 -0
  12. package/dist/Notifications.cjs +146 -0
  13. package/dist/Notifications.d.ts +24 -0
  14. package/dist/Notifications.js +143 -0
  15. package/dist/_virtual/rolldown_runtime.cjs +21 -0
  16. package/dist/hooks/useNotification.cjs +80 -0
  17. package/dist/hooks/useNotification.d.ts +36 -0
  18. package/dist/hooks/useNotification.js +78 -0
  19. package/dist/hooks/useStack.cjs +24 -0
  20. package/dist/hooks/useStack.d.ts +6 -0
  21. package/dist/hooks/useStack.js +22 -0
  22. package/dist/index.cjs +6 -0
  23. package/dist/index.d.ts +6 -0
  24. package/dist/index.js +4 -0
  25. package/dist/interface.cjs +0 -0
  26. package/dist/interface.d.ts +55 -0
  27. package/dist/interface.js +0 -0
  28. package/docs/context.vue +34 -0
  29. package/docs/hooks.vue +89 -0
  30. package/docs/index.less +265 -0
  31. package/docs/maxCount.vue +24 -0
  32. package/docs/motion.ts +33 -0
  33. package/docs/notification.stories.vue +31 -0
  34. package/docs/showProgress.vue +34 -0
  35. package/docs/stack.vue +39 -0
  36. package/package.json +30 -0
  37. package/src/Notice.tsx +212 -0
  38. package/src/NoticeList.tsx +203 -0
  39. package/src/NotificationProvider.tsx +19 -0
  40. package/src/Notifications.tsx +164 -0
  41. package/src/hooks/useNotification.tsx +163 -0
  42. package/src/hooks/useStack.ts +32 -0
  43. package/src/index.ts +9 -0
  44. package/src/interface.ts +61 -0
  45. package/tsconfig.json +7 -0
  46. package/vite.config.ts +18 -0
  47. package/vitest.config.ts +9 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 antdv-community
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/bump.config.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { defineConfig } from 'bumpp'
2
+
3
+ export default defineConfig({
4
+ commit: 'chore(release): @v-c/notification %s',
5
+ tag: '@v-c/notification@%s',
6
+ })
@@ -0,0 +1,230 @@
1
+ Object.defineProperty(exports, "__esModule", { value: true });
2
+ const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
3
+ let vue = require("vue");
4
+ let __v_c_util = require("@v-c/util");
5
+ let __v_c_util_dist_KeyCode = require("@v-c/util/dist/KeyCode");
6
+ __v_c_util_dist_KeyCode = require_rolldown_runtime.__toESM(__v_c_util_dist_KeyCode);
7
+ let __v_c_util_dist_pickAttrs = require("@v-c/util/dist/pickAttrs");
8
+ __v_c_util_dist_pickAttrs = require_rolldown_runtime.__toESM(__v_c_util_dist_pickAttrs);
9
+ var defaults = {
10
+ duration: 4.5,
11
+ pauseOnHover: true,
12
+ closeIcon: "x"
13
+ };
14
+ var Notify = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs }) => {
15
+ const hovering = (0, vue.shallowRef)(false);
16
+ const percent = (0, vue.shallowRef)(0);
17
+ const spentTime = (0, vue.shallowRef)(0);
18
+ const mergedHovering = (0, vue.computed)(() => props.hovering || hovering.value);
19
+ const mergedDuration = (0, vue.computed)(() => {
20
+ if (typeof props.duration === "number") return props.duration;
21
+ if (props.duration === void 0) return defaults.duration;
22
+ return 0;
23
+ });
24
+ const mergedPauseOnHover = (0, vue.computed)(() => props.pauseOnHover === void 0 ? defaults.pauseOnHover : props.pauseOnHover);
25
+ const mergedShowProgress = (0, vue.computed)(() => mergedDuration.value > 0 && props.showProgress);
26
+ const mergedCloseIcon = (0, vue.computed)(() => props.closeIcon ?? defaults.closeIcon);
27
+ const onInternalClose = () => {
28
+ props.onNoticeClose?.(props.eventKey);
29
+ };
30
+ const onCloseKeyDown = (e) => {
31
+ if (e.key === "Enter" || e.code === "Enter" || e.keyCode === __v_c_util_dist_KeyCode.default.ENTER) onInternalClose();
32
+ };
33
+ (0, vue.watch)([
34
+ () => props.times,
35
+ mergedDuration,
36
+ mergedHovering
37
+ ], (_n, _, onCleanup) => {
38
+ const duration = mergedDuration.value;
39
+ const hoveringValue = mergedHovering.value;
40
+ const pauseOnHover = mergedPauseOnHover.value;
41
+ if (!hoveringValue && duration > 0) {
42
+ const start = Date.now() - spentTime.value;
43
+ const timeoutId = window.setTimeout(() => {
44
+ onInternalClose();
45
+ }, duration * 1e3 - spentTime.value);
46
+ onCleanup(() => {
47
+ if (pauseOnHover) clearTimeout(timeoutId);
48
+ spentTime.value = Date.now() - start;
49
+ });
50
+ }
51
+ }, { immediate: true });
52
+ (0, vue.watch)([
53
+ () => props.times,
54
+ mergedDuration,
55
+ spentTime,
56
+ mergedHovering,
57
+ mergedShowProgress
58
+ ], (_n, _, onCleanup) => {
59
+ const hoveringValue = mergedHovering.value;
60
+ const showProgress = mergedShowProgress.value;
61
+ const pauseOnHover = mergedPauseOnHover.value;
62
+ const duration = mergedDuration.value;
63
+ const baseSpentTime = spentTime.value;
64
+ if (!hoveringValue && showProgress && (pauseOnHover || baseSpentTime === 0)) {
65
+ const start = performance.now();
66
+ let animationFrame = 0;
67
+ const calculate = () => {
68
+ cancelAnimationFrame(animationFrame);
69
+ animationFrame = requestAnimationFrame((timestamp) => {
70
+ const runtime = timestamp + baseSpentTime - start;
71
+ const progress = Math.min(runtime / (duration * 1e3), 1);
72
+ percent.value = progress * 100;
73
+ if (progress < 1) calculate();
74
+ });
75
+ };
76
+ calculate();
77
+ onCleanup(() => {
78
+ if (pauseOnHover) cancelAnimationFrame(animationFrame);
79
+ });
80
+ }
81
+ }, { immediate: true });
82
+ return () => {
83
+ const { closable, prefixCls, props: divProps, onClick, content, className, style } = props;
84
+ const closableConfig = typeof closable === "object" && closable !== null ? closable : closable ? { closeIcon: mergedCloseIcon.value } : {};
85
+ const ariaProps = (0, __v_c_util_dist_pickAttrs.default)(closableConfig, true);
86
+ const validPercent = 100 - (percent.value <= 0 ? 0 : percent.value > 100 ? 100 : percent.value);
87
+ const noticePrefixCls = `${prefixCls}-notice`;
88
+ const mergedStyle = {
89
+ ...typeof divProps?.style === "object" && divProps?.style ? divProps.style : {},
90
+ ...typeof attrs.style === "object" && attrs.style ? attrs.style : {},
91
+ ...typeof style === "object" && style ? style : {}
92
+ };
93
+ return (0, vue.createVNode)("div", (0, vue.mergeProps)(divProps, {
94
+ "class": (0, __v_c_util.classNames)(noticePrefixCls, className, attrs.class, { [`${noticePrefixCls}-closable`]: !!closable }),
95
+ "style": mergedStyle,
96
+ "onMouseenter": (e) => {
97
+ hovering.value = true;
98
+ divProps?.onMouseEnter?.(e);
99
+ },
100
+ "onMouseleave": (e) => {
101
+ hovering.value = false;
102
+ divProps?.onMouseLeave?.(e);
103
+ },
104
+ "onClick": onClick
105
+ }), [
106
+ (0, vue.createVNode)("div", { "class": `${noticePrefixCls}-content` }, [content]),
107
+ closable && (0, vue.createVNode)("button", (0, vue.mergeProps)({
108
+ "type": "button",
109
+ "class": `${noticePrefixCls}-close`,
110
+ "onKeydown": onCloseKeyDown,
111
+ "aria-label": "Close"
112
+ }, ariaProps, { "onClick": (e) => {
113
+ e.preventDefault();
114
+ e.stopPropagation();
115
+ onInternalClose();
116
+ } }), [closableConfig.closeIcon ?? mergedCloseIcon.value]),
117
+ mergedShowProgress.value && (0, vue.createVNode)("progress", {
118
+ "class": `${noticePrefixCls}-progress`,
119
+ "max": "100",
120
+ "value": validPercent
121
+ }, [`${validPercent}%`])
122
+ ]);
123
+ };
124
+ }, { props: {
125
+ prefixCls: {
126
+ type: String,
127
+ required: true,
128
+ default: void 0
129
+ },
130
+ eventKey: {
131
+ type: [String, Number],
132
+ required: true,
133
+ default: void 0
134
+ },
135
+ onClick: {
136
+ type: Function,
137
+ required: false,
138
+ default: void 0
139
+ },
140
+ onNoticeClose: {
141
+ type: Function,
142
+ required: false,
143
+ default: void 0
144
+ },
145
+ hovering: {
146
+ type: Boolean,
147
+ required: false,
148
+ default: void 0
149
+ },
150
+ props: {
151
+ type: Object,
152
+ required: false,
153
+ default: void 0
154
+ },
155
+ content: {
156
+ type: [
157
+ String,
158
+ Number,
159
+ null,
160
+ Boolean,
161
+ Array
162
+ ],
163
+ required: false,
164
+ skipCheck: true,
165
+ default: void 0
166
+ },
167
+ duration: {
168
+ type: [
169
+ Number,
170
+ Boolean,
171
+ null
172
+ ],
173
+ required: false,
174
+ default: void 0
175
+ },
176
+ showProgress: {
177
+ type: Boolean,
178
+ required: false,
179
+ default: void 0
180
+ },
181
+ pauseOnHover: {
182
+ type: Boolean,
183
+ required: false,
184
+ default: void 0
185
+ },
186
+ closeIcon: {
187
+ type: [
188
+ String,
189
+ Number,
190
+ null,
191
+ Boolean,
192
+ Array
193
+ ],
194
+ required: false,
195
+ skipCheck: true,
196
+ default: void 0
197
+ },
198
+ closable: {
199
+ type: [Boolean, Object],
200
+ required: false,
201
+ default: void 0
202
+ },
203
+ className: {
204
+ type: String,
205
+ required: false,
206
+ default: void 0
207
+ },
208
+ style: {
209
+ type: null,
210
+ required: false,
211
+ default: void 0
212
+ },
213
+ classNames: {
214
+ type: null,
215
+ required: false,
216
+ default: void 0
217
+ },
218
+ styles: {
219
+ type: null,
220
+ required: false,
221
+ default: void 0
222
+ },
223
+ times: {
224
+ type: Number,
225
+ required: false,
226
+ default: void 0
227
+ }
228
+ } });
229
+ var Notice_default = Notify;
230
+ exports.default = Notice_default;
@@ -0,0 +1,15 @@
1
+ import { Key, NoticeConfig } from './interface.ts';
2
+ export interface NoticeProps extends Omit<NoticeConfig, 'onClose'> {
3
+ prefixCls: string;
4
+ eventKey: Key;
5
+ onClick?: (event: Event) => void;
6
+ onNoticeClose?: (key: Key) => void;
7
+ hovering?: boolean;
8
+ props?: Record<string, any>;
9
+ }
10
+ declare const Notify: import('vue').DefineSetupFnComponent<NoticeProps & {
11
+ times?: number;
12
+ }, {}, {}, NoticeProps & {
13
+ times?: number;
14
+ } & {}, import('vue').PublicProps>;
15
+ export default Notify;
package/dist/Notice.js ADDED
@@ -0,0 +1,225 @@
1
+ import { computed, createVNode, defineComponent, mergeProps, shallowRef, watch } from "vue";
2
+ import { classNames } from "@v-c/util";
3
+ import KeyCode from "@v-c/util/dist/KeyCode";
4
+ import pickAttrs from "@v-c/util/dist/pickAttrs";
5
+ var defaults = {
6
+ duration: 4.5,
7
+ pauseOnHover: true,
8
+ closeIcon: "x"
9
+ };
10
+ var Notice_default = /* @__PURE__ */ defineComponent((props, { attrs }) => {
11
+ const hovering = shallowRef(false);
12
+ const percent = shallowRef(0);
13
+ const spentTime = shallowRef(0);
14
+ const mergedHovering = computed(() => props.hovering || hovering.value);
15
+ const mergedDuration = computed(() => {
16
+ if (typeof props.duration === "number") return props.duration;
17
+ if (props.duration === void 0) return defaults.duration;
18
+ return 0;
19
+ });
20
+ const mergedPauseOnHover = computed(() => props.pauseOnHover === void 0 ? defaults.pauseOnHover : props.pauseOnHover);
21
+ const mergedShowProgress = computed(() => mergedDuration.value > 0 && props.showProgress);
22
+ const mergedCloseIcon = computed(() => props.closeIcon ?? defaults.closeIcon);
23
+ const onInternalClose = () => {
24
+ props.onNoticeClose?.(props.eventKey);
25
+ };
26
+ const onCloseKeyDown = (e) => {
27
+ if (e.key === "Enter" || e.code === "Enter" || e.keyCode === KeyCode.ENTER) onInternalClose();
28
+ };
29
+ watch([
30
+ () => props.times,
31
+ mergedDuration,
32
+ mergedHovering
33
+ ], (_n, _, onCleanup) => {
34
+ const duration = mergedDuration.value;
35
+ const hoveringValue = mergedHovering.value;
36
+ const pauseOnHover = mergedPauseOnHover.value;
37
+ if (!hoveringValue && duration > 0) {
38
+ const start = Date.now() - spentTime.value;
39
+ const timeoutId = window.setTimeout(() => {
40
+ onInternalClose();
41
+ }, duration * 1e3 - spentTime.value);
42
+ onCleanup(() => {
43
+ if (pauseOnHover) clearTimeout(timeoutId);
44
+ spentTime.value = Date.now() - start;
45
+ });
46
+ }
47
+ }, { immediate: true });
48
+ watch([
49
+ () => props.times,
50
+ mergedDuration,
51
+ spentTime,
52
+ mergedHovering,
53
+ mergedShowProgress
54
+ ], (_n, _, onCleanup) => {
55
+ const hoveringValue = mergedHovering.value;
56
+ const showProgress = mergedShowProgress.value;
57
+ const pauseOnHover = mergedPauseOnHover.value;
58
+ const duration = mergedDuration.value;
59
+ const baseSpentTime = spentTime.value;
60
+ if (!hoveringValue && showProgress && (pauseOnHover || baseSpentTime === 0)) {
61
+ const start = performance.now();
62
+ let animationFrame = 0;
63
+ const calculate = () => {
64
+ cancelAnimationFrame(animationFrame);
65
+ animationFrame = requestAnimationFrame((timestamp) => {
66
+ const runtime = timestamp + baseSpentTime - start;
67
+ const progress = Math.min(runtime / (duration * 1e3), 1);
68
+ percent.value = progress * 100;
69
+ if (progress < 1) calculate();
70
+ });
71
+ };
72
+ calculate();
73
+ onCleanup(() => {
74
+ if (pauseOnHover) cancelAnimationFrame(animationFrame);
75
+ });
76
+ }
77
+ }, { immediate: true });
78
+ return () => {
79
+ const { closable, prefixCls, props: divProps, onClick, content, className, style } = props;
80
+ const closableConfig = typeof closable === "object" && closable !== null ? closable : closable ? { closeIcon: mergedCloseIcon.value } : {};
81
+ const ariaProps = pickAttrs(closableConfig, true);
82
+ const validPercent = 100 - (percent.value <= 0 ? 0 : percent.value > 100 ? 100 : percent.value);
83
+ const noticePrefixCls = `${prefixCls}-notice`;
84
+ const mergedStyle = {
85
+ ...typeof divProps?.style === "object" && divProps?.style ? divProps.style : {},
86
+ ...typeof attrs.style === "object" && attrs.style ? attrs.style : {},
87
+ ...typeof style === "object" && style ? style : {}
88
+ };
89
+ return createVNode("div", mergeProps(divProps, {
90
+ "class": classNames(noticePrefixCls, className, attrs.class, { [`${noticePrefixCls}-closable`]: !!closable }),
91
+ "style": mergedStyle,
92
+ "onMouseenter": (e) => {
93
+ hovering.value = true;
94
+ divProps?.onMouseEnter?.(e);
95
+ },
96
+ "onMouseleave": (e) => {
97
+ hovering.value = false;
98
+ divProps?.onMouseLeave?.(e);
99
+ },
100
+ "onClick": onClick
101
+ }), [
102
+ createVNode("div", { "class": `${noticePrefixCls}-content` }, [content]),
103
+ closable && createVNode("button", mergeProps({
104
+ "type": "button",
105
+ "class": `${noticePrefixCls}-close`,
106
+ "onKeydown": onCloseKeyDown,
107
+ "aria-label": "Close"
108
+ }, ariaProps, { "onClick": (e) => {
109
+ e.preventDefault();
110
+ e.stopPropagation();
111
+ onInternalClose();
112
+ } }), [closableConfig.closeIcon ?? mergedCloseIcon.value]),
113
+ mergedShowProgress.value && createVNode("progress", {
114
+ "class": `${noticePrefixCls}-progress`,
115
+ "max": "100",
116
+ "value": validPercent
117
+ }, [`${validPercent}%`])
118
+ ]);
119
+ };
120
+ }, { props: {
121
+ prefixCls: {
122
+ type: String,
123
+ required: true,
124
+ default: void 0
125
+ },
126
+ eventKey: {
127
+ type: [String, Number],
128
+ required: true,
129
+ default: void 0
130
+ },
131
+ onClick: {
132
+ type: Function,
133
+ required: false,
134
+ default: void 0
135
+ },
136
+ onNoticeClose: {
137
+ type: Function,
138
+ required: false,
139
+ default: void 0
140
+ },
141
+ hovering: {
142
+ type: Boolean,
143
+ required: false,
144
+ default: void 0
145
+ },
146
+ props: {
147
+ type: Object,
148
+ required: false,
149
+ default: void 0
150
+ },
151
+ content: {
152
+ type: [
153
+ String,
154
+ Number,
155
+ null,
156
+ Boolean,
157
+ Array
158
+ ],
159
+ required: false,
160
+ skipCheck: true,
161
+ default: void 0
162
+ },
163
+ duration: {
164
+ type: [
165
+ Number,
166
+ Boolean,
167
+ null
168
+ ],
169
+ required: false,
170
+ default: void 0
171
+ },
172
+ showProgress: {
173
+ type: Boolean,
174
+ required: false,
175
+ default: void 0
176
+ },
177
+ pauseOnHover: {
178
+ type: Boolean,
179
+ required: false,
180
+ default: void 0
181
+ },
182
+ closeIcon: {
183
+ type: [
184
+ String,
185
+ Number,
186
+ null,
187
+ Boolean,
188
+ Array
189
+ ],
190
+ required: false,
191
+ skipCheck: true,
192
+ default: void 0
193
+ },
194
+ closable: {
195
+ type: [Boolean, Object],
196
+ required: false,
197
+ default: void 0
198
+ },
199
+ className: {
200
+ type: String,
201
+ required: false,
202
+ default: void 0
203
+ },
204
+ style: {
205
+ type: null,
206
+ required: false,
207
+ default: void 0
208
+ },
209
+ classNames: {
210
+ type: null,
211
+ required: false,
212
+ default: void 0
213
+ },
214
+ styles: {
215
+ type: null,
216
+ required: false,
217
+ default: void 0
218
+ },
219
+ times: {
220
+ type: Number,
221
+ required: false,
222
+ default: void 0
223
+ }
224
+ } });
225
+ export { Notice_default as default };
@@ -0,0 +1,157 @@
1
+ Object.defineProperty(exports, "__esModule", { value: true });
2
+ const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
3
+ const require_Notice = require("./Notice.cjs");
4
+ const require_useStack = require("./hooks/useStack.cjs");
5
+ const require_NotificationProvider = require("./NotificationProvider.cjs");
6
+ let vue = require("vue");
7
+ let __v_c_util = require("@v-c/util");
8
+ let __v_c_util_dist_utils_transition = require("@v-c/util/dist/utils/transition");
9
+ let __v_c_util_dist_vueuse_unref_element = require("@v-c/util/dist/vueuse/unref-element");
10
+ function _isSlot(s) {
11
+ return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !(0, vue.isVNode)(s);
12
+ }
13
+ var NoticeList = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs }) => {
14
+ const ctx = require_NotificationProvider.useNotificationContext();
15
+ const dictRef = (0, vue.reactive)({});
16
+ const keys = (0, vue.computed)(() => (props.configList ?? []).map((config) => ({
17
+ config,
18
+ key: String(config.key)
19
+ })));
20
+ const latestNotice = (0, vue.shallowRef)(null);
21
+ const hoverKeys = (0, vue.ref)([]);
22
+ const [stackEnabled, stackOptions] = require_useStack.default((0, vue.toRef)(props, "stack"));
23
+ const expanded = (0, vue.computed)(() => stackEnabled.value && (hoverKeys.value.length > 0 || keys.value.length <= stackOptions.threshold.value));
24
+ const placementMotion = (0, vue.computed)(() => {
25
+ if (typeof props.motion === "function") return props.placement ? props.motion(props.placement) : void 0;
26
+ return props.motion;
27
+ });
28
+ (0, vue.watch)([
29
+ hoverKeys,
30
+ keys,
31
+ stackEnabled
32
+ ], () => {
33
+ if (stackEnabled.value && hoverKeys.value.length > 1) hoverKeys.value = hoverKeys.value.filter((key) => keys.value.some(({ key: dataKey }) => key === dataKey));
34
+ });
35
+ (0, vue.watchEffect)(() => {
36
+ if (!stackEnabled.value) {
37
+ latestNotice.value = null;
38
+ return;
39
+ }
40
+ const lastKey = keys.value[keys.value.length - 1]?.key;
41
+ latestNotice.value = lastKey ? dictRef[lastKey] ?? null : null;
42
+ }, { flush: "post" });
43
+ const checkAllClosed = () => {
44
+ if (!props.placement) return;
45
+ if (keys.value.length === 0) props.onAllNoticeRemoved?.(props.placement);
46
+ };
47
+ return () => {
48
+ let _slot;
49
+ const { prefixCls = "", placement = "topRight", onNoticeClose } = props;
50
+ const renderNotify = () => keys.value.map(({ config }, motionIndex) => {
51
+ const { key, times } = config;
52
+ const strKey = String(key);
53
+ const { className: configClassName, style: configStyle, classNames: configClassNames, styles: configStyles,...restConfig } = config;
54
+ const dataIndex = keys.value.findIndex((item) => item.key === strKey);
55
+ const stackStyle = {};
56
+ if (stackEnabled.value) {
57
+ const index = keys.value.length - 1 - (dataIndex > -1 ? dataIndex : motionIndex - 1);
58
+ const transformX = placement === "top" || placement === "bottom" ? "-50%" : "0";
59
+ if (index > 0) {
60
+ stackStyle.height = expanded.value ? dictRef[strKey]?.offsetHeight : latestNotice.value?.offsetHeight;
61
+ if (stackStyle.height && typeof stackStyle.height === "number") stackStyle.height = `${stackStyle.height}px`;
62
+ let verticalOffset = 0;
63
+ for (let i = 0; i < index; i += 1) {
64
+ const targetKey = keys.value[keys.value.length - 1 - i]?.key;
65
+ const node = targetKey ? dictRef[targetKey] : null;
66
+ verticalOffset += (node?.offsetHeight ?? 0) + stackOptions.gap.value;
67
+ }
68
+ const transformY = (expanded.value ? verticalOffset : index * stackOptions.offset.value) * (placement.startsWith("top") ? 1 : -1);
69
+ const currentWidth = dictRef[strKey]?.offsetWidth;
70
+ const latestWidth = latestNotice.value?.offsetWidth;
71
+ stackStyle.transform = `translate3d(${transformX}, ${transformY}px, 0) scaleX(${!expanded.value && latestWidth && currentWidth ? (latestWidth - stackOptions.offset.value * 2 * (index < 3 ? index : 3)) / currentWidth : 1})`;
72
+ } else stackStyle.transform = `translate3d(${transformX}, 0, 0)`;
73
+ }
74
+ return (0, vue.createVNode)("div", {
75
+ "key": strKey,
76
+ "class": (0, __v_c_util.classNames)(`${prefixCls}-notice-wrapper`, configClassNames?.wrapper),
77
+ "style": {
78
+ ...stackStyle,
79
+ ...configStyles?.wrapper
80
+ },
81
+ "onMouseenter": () => {
82
+ hoverKeys.value = hoverKeys.value.includes(strKey) ? hoverKeys.value : [...hoverKeys.value, strKey];
83
+ },
84
+ "onMouseleave": () => {
85
+ hoverKeys.value = hoverKeys.value.filter((k) => k !== strKey);
86
+ }
87
+ }, [(0, vue.createVNode)(require_Notice.default, (0, vue.mergeProps)(restConfig, {
88
+ "ref": (el) => {
89
+ const element = (0, __v_c_util_dist_vueuse_unref_element.unrefElement)(el) ?? void 0;
90
+ if (dataIndex > -1) dictRef[strKey] = element;
91
+ else delete dictRef[strKey];
92
+ },
93
+ "prefixCls": prefixCls,
94
+ "classNames": configClassNames,
95
+ "styles": configStyles,
96
+ "class": (0, __v_c_util.classNames)(configClassName, ctx.value?.classNames?.notice),
97
+ "style": configStyle,
98
+ "times": times,
99
+ "eventKey": key,
100
+ "onNoticeClose": onNoticeClose,
101
+ "hovering": stackEnabled.value && hoverKeys.value.length > 0
102
+ }), null)]);
103
+ });
104
+ let motionGroupProps = {};
105
+ if (placementMotion.value) motionGroupProps = (0, __v_c_util_dist_utils_transition.getTransitionGroupProps)(placementMotion.value.name, placementMotion.value);
106
+ return (0, vue.createVNode)(vue.TransitionGroup, (0, vue.mergeProps)({
107
+ "key": placement,
108
+ "tag": "div",
109
+ "appear": true
110
+ }, {
111
+ class: (0, __v_c_util.classNames)(prefixCls, `${prefixCls}-${placement}`, ctx.value?.classNames?.list, attrs.class, {
112
+ [`${prefixCls}-stack-expanded`]: expanded.value,
113
+ [`${prefixCls}-stack`]: stackEnabled.value
114
+ }),
115
+ style: attrs.style
116
+ }, motionGroupProps, { "onAfterLeave": checkAllClosed }), _isSlot(_slot = renderNotify()) ? _slot : { default: () => [_slot] });
117
+ };
118
+ }, { props: {
119
+ configList: {
120
+ type: Array,
121
+ required: false,
122
+ default: void 0
123
+ },
124
+ placement: {
125
+ type: String,
126
+ required: false,
127
+ default: void 0
128
+ },
129
+ prefixCls: {
130
+ type: String,
131
+ required: false,
132
+ default: void 0
133
+ },
134
+ motion: {
135
+ type: Function,
136
+ required: false,
137
+ skipCheck: true,
138
+ default: void 0
139
+ },
140
+ stack: {
141
+ type: [Boolean, Object],
142
+ required: false,
143
+ default: void 0
144
+ },
145
+ onAllNoticeRemoved: {
146
+ type: Function,
147
+ required: false,
148
+ default: void 0
149
+ },
150
+ onNoticeClose: {
151
+ type: Function,
152
+ required: false,
153
+ default: void 0
154
+ }
155
+ } });
156
+ var NoticeList_default = NoticeList;
157
+ exports.default = NoticeList_default;
@@ -0,0 +1,13 @@
1
+ import { TransitionGroupProps } from 'vue';
2
+ import { Key, OpenConfig, Placement, StackConfig } from './interface.ts';
3
+ export interface NoticeListProps {
4
+ configList?: OpenConfig[];
5
+ placement?: Placement;
6
+ prefixCls?: string;
7
+ motion?: TransitionGroupProps | ((placement: Placement) => TransitionGroupProps);
8
+ stack?: StackConfig;
9
+ onAllNoticeRemoved?: (placement: Placement) => void;
10
+ onNoticeClose?: (key: Key) => void;
11
+ }
12
+ declare const NoticeList: import('vue').DefineSetupFnComponent<NoticeListProps, {}, {}, NoticeListProps & {}, import('vue').PublicProps>;
13
+ export default NoticeList;