@v-c/notification 0.0.3 → 2.0.0-beta.1
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/Notification.d.ts +286 -0
- package/dist/Notification.js +237 -0
- package/dist/NotificationList/Content.d.ts +88 -0
- package/dist/NotificationList/Content.js +74 -0
- package/dist/NotificationList/index.d.ts +156 -0
- package/dist/NotificationList/index.js +204 -0
- package/dist/NotificationProvider.d.ts +20 -1
- package/dist/NotificationProvider.js +16 -3
- package/dist/Notifications.d.ts +136 -8
- package/dist/Notifications.js +118 -109
- package/dist/Progress.d.ts +8 -0
- package/dist/Progress.js +18 -0
- package/dist/hooks/useClosable.d.ts +22 -0
- package/dist/hooks/useClosable.js +33 -0
- package/dist/hooks/useListPosition/index.d.ts +17 -0
- package/dist/hooks/useListPosition/index.js +48 -0
- package/dist/hooks/useListPosition/useSizes.d.ts +13 -0
- package/dist/hooks/useListPosition/useSizes.js +29 -0
- package/dist/hooks/useNoticeTimer.d.ts +6 -0
- package/dist/hooks/useNoticeTimer.js +71 -0
- package/dist/hooks/useNotification.d.ts +8 -24
- package/dist/hooks/useNotification.js +33 -22
- package/dist/hooks/useStack.d.ts +8 -4
- package/dist/hooks/useStack.js +15 -18
- package/dist/index.d.ts +7 -5
- package/dist/index.js +5 -3
- package/docs/context.vue +1 -1
- package/docs/hooks.vue +4 -4
- package/docs/index.less +62 -143
- package/docs/maxCount.vue +1 -1
- package/docs/showProgress.vue +2 -2
- package/docs/stack.vue +1 -1
- package/package.json +5 -4
- package/src/Notification.tsx +363 -0
- package/src/NotificationList/Content.tsx +84 -0
- package/src/NotificationList/index.tsx +298 -0
- package/src/NotificationProvider.tsx +23 -3
- package/src/Notifications.tsx +103 -87
- package/src/Progress.tsx +23 -0
- package/src/hooks/useClosable.ts +54 -0
- package/src/hooks/useListPosition/index.ts +85 -0
- package/src/hooks/useListPosition/useSizes.ts +42 -0
- package/src/hooks/useNoticeTimer.ts +96 -0
- package/src/hooks/useNotification.tsx +54 -80
- package/src/hooks/useStack.ts +26 -18
- package/src/index.ts +31 -5
- package/tests/index.spec.tsx +200 -0
- package/vite.config.ts +4 -3
- package/vitest.config.ts +3 -1
- package/dist/Notice.cjs +0 -235
- package/dist/Notice.d.ts +0 -15
- package/dist/Notice.js +0 -227
- package/dist/NoticeList.cjs +0 -170
- package/dist/NoticeList.d.ts +0 -13
- package/dist/NoticeList.js +0 -164
- package/dist/NotificationProvider.cjs +0 -14
- package/dist/Notifications.cjs +0 -146
- package/dist/_virtual/rolldown_runtime.cjs +0 -21
- package/dist/hooks/useNotification.cjs +0 -93
- package/dist/hooks/useStack.cjs +0 -27
- package/dist/index.cjs +0 -7
- package/dist/interface.cjs +0 -1
- package/dist/interface.d.ts +0 -55
- package/dist/interface.js +0 -0
- package/src/Notice.tsx +0 -212
- package/src/NoticeList.tsx +0 -219
- package/src/interface.ts +0 -61
package/dist/NoticeList.cjs
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
6
|
-
const require_Notice = require("./Notice.cjs");
|
|
7
|
-
const require_useStack = require("./hooks/useStack.cjs");
|
|
8
|
-
const require_NotificationProvider = require("./NotificationProvider.cjs");
|
|
9
|
-
let vue = require("vue");
|
|
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");
|
|
13
|
-
function _isSlot(s) {
|
|
14
|
-
return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !(0, vue.isVNode)(s);
|
|
15
|
-
}
|
|
16
|
-
var NoticeList = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs }) => {
|
|
17
|
-
const ctx = require_NotificationProvider.useNotificationContext();
|
|
18
|
-
const dictRef = (0, vue.reactive)({});
|
|
19
|
-
const keys = (0, vue.computed)(() => (props.configList ?? []).map((config) => ({
|
|
20
|
-
config,
|
|
21
|
-
key: String(config.key)
|
|
22
|
-
})));
|
|
23
|
-
const latestNotice = (0, vue.shallowRef)(null);
|
|
24
|
-
const hoverKeys = (0, vue.ref)([]);
|
|
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
|
-
});
|
|
33
|
-
const placementMotion = (0, vue.computed)(() => {
|
|
34
|
-
if (typeof props.motion === "function") return props.placement ? props.motion(props.placement) : void 0;
|
|
35
|
-
return props.motion;
|
|
36
|
-
});
|
|
37
|
-
(0, vue.watch)([
|
|
38
|
-
hoverKeys,
|
|
39
|
-
keys,
|
|
40
|
-
stackEnabled
|
|
41
|
-
], () => {
|
|
42
|
-
if (stackEnabled.value && hoverKeys.value.length > 1) hoverKeys.value = hoverKeys.value.filter((key) => keys.value.some(({ key: dataKey }) => key === dataKey));
|
|
43
|
-
});
|
|
44
|
-
(0, vue.watch)(stackEnabled, (enabled) => {
|
|
45
|
-
if (!enabled && hoverKeys.value.length) hoverKeys.value = [];
|
|
46
|
-
});
|
|
47
|
-
(0, vue.watchEffect)(() => {
|
|
48
|
-
if (!stackActive.value) {
|
|
49
|
-
latestNotice.value = null;
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const lastKey = keys.value[keys.value.length - 1]?.key;
|
|
53
|
-
latestNotice.value = lastKey ? dictRef[lastKey] ?? null : null;
|
|
54
|
-
}, { flush: "post" });
|
|
55
|
-
const checkAllClosed = () => {
|
|
56
|
-
if (!props.placement) return;
|
|
57
|
-
if (keys.value.length === 0) props.onAllNoticeRemoved?.(props.placement);
|
|
58
|
-
};
|
|
59
|
-
return () => {
|
|
60
|
-
let _slot;
|
|
61
|
-
const { prefixCls = "", placement = "topRight", onNoticeClose } = props;
|
|
62
|
-
const renderNotify = () => keys.value.map(({ config }, motionIndex) => {
|
|
63
|
-
const { key, times } = config;
|
|
64
|
-
const strKey = String(key);
|
|
65
|
-
const { className: configClassName, style: configStyle, classNames: configClassNames, styles: configStyles, ...restConfig } = config;
|
|
66
|
-
const dataIndex = keys.value.findIndex((item) => item.key === strKey);
|
|
67
|
-
const stackStyle = {};
|
|
68
|
-
if (stackActive.value) {
|
|
69
|
-
const index = keys.value.length - 1 - (dataIndex > -1 ? dataIndex : motionIndex - 1);
|
|
70
|
-
const transformX = placement === "top" || placement === "bottom" ? "-50%" : "0";
|
|
71
|
-
if (index > 0) {
|
|
72
|
-
stackStyle.height = expanded.value ? dictRef[strKey]?.offsetHeight : latestNotice.value?.offsetHeight;
|
|
73
|
-
if (stackStyle.height && typeof stackStyle.height === "number") stackStyle.height = `${stackStyle.height}px`;
|
|
74
|
-
let verticalOffset = 0;
|
|
75
|
-
for (let i = 0; i < index; i += 1) {
|
|
76
|
-
const targetKey = keys.value[keys.value.length - 1 - i]?.key;
|
|
77
|
-
const node = targetKey ? dictRef[targetKey] : null;
|
|
78
|
-
verticalOffset += (node?.offsetHeight ?? 0) + stackOptions.gap.value;
|
|
79
|
-
}
|
|
80
|
-
const transformY = (expanded.value ? verticalOffset : index * stackOptions.offset.value) * (placement.startsWith("top") ? 1 : -1);
|
|
81
|
-
const currentWidth = dictRef[strKey]?.offsetWidth;
|
|
82
|
-
const latestWidth = latestNotice.value?.offsetWidth;
|
|
83
|
-
stackStyle.transform = `translate3d(${transformX}, ${transformY}px, 0) scaleX(${!expanded.value && latestWidth && currentWidth ? (latestWidth - stackOptions.offset.value * 2 * (index < 3 ? index : 3)) / currentWidth : 1})`;
|
|
84
|
-
} else stackStyle.transform = `translate3d(${transformX}, 0, 0)`;
|
|
85
|
-
}
|
|
86
|
-
return (0, vue.createVNode)("div", {
|
|
87
|
-
"key": strKey,
|
|
88
|
-
"class": (0, _v_c_util.classNames)(`${prefixCls}-notice-wrapper`, configClassNames?.wrapper),
|
|
89
|
-
"style": {
|
|
90
|
-
...stackStyle,
|
|
91
|
-
...configStyles?.wrapper
|
|
92
|
-
},
|
|
93
|
-
"onMouseenter": () => {
|
|
94
|
-
if (!stackEnabled.value) return;
|
|
95
|
-
hoverKeys.value = hoverKeys.value.includes(strKey) ? hoverKeys.value : [...hoverKeys.value, strKey];
|
|
96
|
-
},
|
|
97
|
-
"onMouseleave": () => {
|
|
98
|
-
if (!stackEnabled.value) return;
|
|
99
|
-
hoverKeys.value = hoverKeys.value.filter((k) => k !== strKey);
|
|
100
|
-
}
|
|
101
|
-
}, [(0, vue.createVNode)(require_Notice.default, (0, vue.mergeProps)(restConfig, {
|
|
102
|
-
"ref": (el) => {
|
|
103
|
-
const element = (0, _v_c_util_dist_vueuse_unref_element.unrefElement)(el) ?? void 0;
|
|
104
|
-
if (dataIndex > -1) dictRef[strKey] = element;
|
|
105
|
-
else delete dictRef[strKey];
|
|
106
|
-
},
|
|
107
|
-
"prefixCls": prefixCls,
|
|
108
|
-
"classNames": configClassNames,
|
|
109
|
-
"styles": configStyles,
|
|
110
|
-
"class": (0, _v_c_util.classNames)(configClassName, ctx.value?.classNames?.notice),
|
|
111
|
-
"style": configStyle,
|
|
112
|
-
"times": times,
|
|
113
|
-
"eventKey": key,
|
|
114
|
-
"onNoticeClose": onNoticeClose,
|
|
115
|
-
"hovering": stackEnabled.value && hoverKeys.value.length > 0
|
|
116
|
-
}), null)]);
|
|
117
|
-
});
|
|
118
|
-
let motionGroupProps = {};
|
|
119
|
-
if (placementMotion.value) motionGroupProps = (0, _v_c_util_dist_utils_transition.getTransitionGroupProps)(placementMotion.value.name, placementMotion.value);
|
|
120
|
-
return (0, vue.createVNode)(vue.TransitionGroup, (0, vue.mergeProps)({
|
|
121
|
-
"key": placement,
|
|
122
|
-
"tag": "div",
|
|
123
|
-
"appear": true
|
|
124
|
-
}, {
|
|
125
|
-
class: (0, _v_c_util.classNames)(prefixCls, `${prefixCls}-${placement}`, ctx.value?.classNames?.list, attrs.class, {
|
|
126
|
-
[`${prefixCls}-stack-expanded`]: expanded.value,
|
|
127
|
-
[`${prefixCls}-stack`]: stackActive.value
|
|
128
|
-
}),
|
|
129
|
-
style: attrs.style
|
|
130
|
-
}, motionGroupProps, { "onAfterLeave": checkAllClosed }), _isSlot(_slot = renderNotify()) ? _slot : { default: () => [_slot] });
|
|
131
|
-
};
|
|
132
|
-
}, { props: {
|
|
133
|
-
configList: {
|
|
134
|
-
type: Array,
|
|
135
|
-
required: false,
|
|
136
|
-
default: void 0
|
|
137
|
-
},
|
|
138
|
-
placement: {
|
|
139
|
-
type: String,
|
|
140
|
-
required: false,
|
|
141
|
-
default: void 0
|
|
142
|
-
},
|
|
143
|
-
prefixCls: {
|
|
144
|
-
type: String,
|
|
145
|
-
required: false,
|
|
146
|
-
default: void 0
|
|
147
|
-
},
|
|
148
|
-
motion: {
|
|
149
|
-
type: [Object, Function],
|
|
150
|
-
required: false,
|
|
151
|
-
default: void 0
|
|
152
|
-
},
|
|
153
|
-
stack: {
|
|
154
|
-
type: [Boolean, Object],
|
|
155
|
-
required: false,
|
|
156
|
-
default: void 0
|
|
157
|
-
},
|
|
158
|
-
onAllNoticeRemoved: {
|
|
159
|
-
type: Function,
|
|
160
|
-
required: false,
|
|
161
|
-
default: void 0
|
|
162
|
-
},
|
|
163
|
-
onNoticeClose: {
|
|
164
|
-
type: Function,
|
|
165
|
-
required: false,
|
|
166
|
-
default: void 0
|
|
167
|
-
}
|
|
168
|
-
} });
|
|
169
|
-
var NoticeList_default = NoticeList;
|
|
170
|
-
exports.default = NoticeList_default;
|
package/dist/NoticeList.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
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;
|
package/dist/NoticeList.js
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import Notice_default from "./Notice.js";
|
|
2
|
-
import useStack_default from "./hooks/useStack.js";
|
|
3
|
-
import { useNotificationContext } from "./NotificationProvider.js";
|
|
4
|
-
import { TransitionGroup, computed, createVNode, defineComponent, isVNode, mergeProps, reactive, ref, shallowRef, toRef, watch, watchEffect } from "vue";
|
|
5
|
-
import { classNames } from "@v-c/util";
|
|
6
|
-
import { getTransitionGroupProps } from "@v-c/util/dist/utils/transition";
|
|
7
|
-
import { unrefElement } from "@v-c/util/dist/vueuse/unref-element";
|
|
8
|
-
function _isSlot(s) {
|
|
9
|
-
return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
|
|
10
|
-
}
|
|
11
|
-
var NoticeList_default = /* @__PURE__ */ defineComponent((props, { attrs }) => {
|
|
12
|
-
const ctx = useNotificationContext();
|
|
13
|
-
const dictRef = reactive({});
|
|
14
|
-
const keys = computed(() => (props.configList ?? []).map((config) => ({
|
|
15
|
-
config,
|
|
16
|
-
key: String(config.key)
|
|
17
|
-
})));
|
|
18
|
-
const latestNotice = shallowRef(null);
|
|
19
|
-
const hoverKeys = ref([]);
|
|
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
|
-
});
|
|
28
|
-
const placementMotion = computed(() => {
|
|
29
|
-
if (typeof props.motion === "function") return props.placement ? props.motion(props.placement) : void 0;
|
|
30
|
-
return props.motion;
|
|
31
|
-
});
|
|
32
|
-
watch([
|
|
33
|
-
hoverKeys,
|
|
34
|
-
keys,
|
|
35
|
-
stackEnabled
|
|
36
|
-
], () => {
|
|
37
|
-
if (stackEnabled.value && hoverKeys.value.length > 1) hoverKeys.value = hoverKeys.value.filter((key) => keys.value.some(({ key: dataKey }) => key === dataKey));
|
|
38
|
-
});
|
|
39
|
-
watch(stackEnabled, (enabled) => {
|
|
40
|
-
if (!enabled && hoverKeys.value.length) hoverKeys.value = [];
|
|
41
|
-
});
|
|
42
|
-
watchEffect(() => {
|
|
43
|
-
if (!stackActive.value) {
|
|
44
|
-
latestNotice.value = null;
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
const lastKey = keys.value[keys.value.length - 1]?.key;
|
|
48
|
-
latestNotice.value = lastKey ? dictRef[lastKey] ?? null : null;
|
|
49
|
-
}, { flush: "post" });
|
|
50
|
-
const checkAllClosed = () => {
|
|
51
|
-
if (!props.placement) return;
|
|
52
|
-
if (keys.value.length === 0) props.onAllNoticeRemoved?.(props.placement);
|
|
53
|
-
};
|
|
54
|
-
return () => {
|
|
55
|
-
let _slot;
|
|
56
|
-
const { prefixCls = "", placement = "topRight", onNoticeClose } = props;
|
|
57
|
-
const renderNotify = () => keys.value.map(({ config }, motionIndex) => {
|
|
58
|
-
const { key, times } = config;
|
|
59
|
-
const strKey = String(key);
|
|
60
|
-
const { className: configClassName, style: configStyle, classNames: configClassNames, styles: configStyles, ...restConfig } = config;
|
|
61
|
-
const dataIndex = keys.value.findIndex((item) => item.key === strKey);
|
|
62
|
-
const stackStyle = {};
|
|
63
|
-
if (stackActive.value) {
|
|
64
|
-
const index = keys.value.length - 1 - (dataIndex > -1 ? dataIndex : motionIndex - 1);
|
|
65
|
-
const transformX = placement === "top" || placement === "bottom" ? "-50%" : "0";
|
|
66
|
-
if (index > 0) {
|
|
67
|
-
stackStyle.height = expanded.value ? dictRef[strKey]?.offsetHeight : latestNotice.value?.offsetHeight;
|
|
68
|
-
if (stackStyle.height && typeof stackStyle.height === "number") stackStyle.height = `${stackStyle.height}px`;
|
|
69
|
-
let verticalOffset = 0;
|
|
70
|
-
for (let i = 0; i < index; i += 1) {
|
|
71
|
-
const targetKey = keys.value[keys.value.length - 1 - i]?.key;
|
|
72
|
-
const node = targetKey ? dictRef[targetKey] : null;
|
|
73
|
-
verticalOffset += (node?.offsetHeight ?? 0) + stackOptions.gap.value;
|
|
74
|
-
}
|
|
75
|
-
const transformY = (expanded.value ? verticalOffset : index * stackOptions.offset.value) * (placement.startsWith("top") ? 1 : -1);
|
|
76
|
-
const currentWidth = dictRef[strKey]?.offsetWidth;
|
|
77
|
-
const latestWidth = latestNotice.value?.offsetWidth;
|
|
78
|
-
stackStyle.transform = `translate3d(${transformX}, ${transformY}px, 0) scaleX(${!expanded.value && latestWidth && currentWidth ? (latestWidth - stackOptions.offset.value * 2 * (index < 3 ? index : 3)) / currentWidth : 1})`;
|
|
79
|
-
} else stackStyle.transform = `translate3d(${transformX}, 0, 0)`;
|
|
80
|
-
}
|
|
81
|
-
return createVNode("div", {
|
|
82
|
-
"key": strKey,
|
|
83
|
-
"class": classNames(`${prefixCls}-notice-wrapper`, configClassNames?.wrapper),
|
|
84
|
-
"style": {
|
|
85
|
-
...stackStyle,
|
|
86
|
-
...configStyles?.wrapper
|
|
87
|
-
},
|
|
88
|
-
"onMouseenter": () => {
|
|
89
|
-
if (!stackEnabled.value) return;
|
|
90
|
-
hoverKeys.value = hoverKeys.value.includes(strKey) ? hoverKeys.value : [...hoverKeys.value, strKey];
|
|
91
|
-
},
|
|
92
|
-
"onMouseleave": () => {
|
|
93
|
-
if (!stackEnabled.value) return;
|
|
94
|
-
hoverKeys.value = hoverKeys.value.filter((k) => k !== strKey);
|
|
95
|
-
}
|
|
96
|
-
}, [createVNode(Notice_default, mergeProps(restConfig, {
|
|
97
|
-
"ref": (el) => {
|
|
98
|
-
const element = unrefElement(el) ?? void 0;
|
|
99
|
-
if (dataIndex > -1) dictRef[strKey] = element;
|
|
100
|
-
else delete dictRef[strKey];
|
|
101
|
-
},
|
|
102
|
-
"prefixCls": prefixCls,
|
|
103
|
-
"classNames": configClassNames,
|
|
104
|
-
"styles": configStyles,
|
|
105
|
-
"class": classNames(configClassName, ctx.value?.classNames?.notice),
|
|
106
|
-
"style": configStyle,
|
|
107
|
-
"times": times,
|
|
108
|
-
"eventKey": key,
|
|
109
|
-
"onNoticeClose": onNoticeClose,
|
|
110
|
-
"hovering": stackEnabled.value && hoverKeys.value.length > 0
|
|
111
|
-
}), null)]);
|
|
112
|
-
});
|
|
113
|
-
let motionGroupProps = {};
|
|
114
|
-
if (placementMotion.value) motionGroupProps = getTransitionGroupProps(placementMotion.value.name, placementMotion.value);
|
|
115
|
-
return createVNode(TransitionGroup, mergeProps({
|
|
116
|
-
"key": placement,
|
|
117
|
-
"tag": "div",
|
|
118
|
-
"appear": true
|
|
119
|
-
}, {
|
|
120
|
-
class: classNames(prefixCls, `${prefixCls}-${placement}`, ctx.value?.classNames?.list, attrs.class, {
|
|
121
|
-
[`${prefixCls}-stack-expanded`]: expanded.value,
|
|
122
|
-
[`${prefixCls}-stack`]: stackActive.value
|
|
123
|
-
}),
|
|
124
|
-
style: attrs.style
|
|
125
|
-
}, motionGroupProps, { "onAfterLeave": checkAllClosed }), _isSlot(_slot = renderNotify()) ? _slot : { default: () => [_slot] });
|
|
126
|
-
};
|
|
127
|
-
}, { props: {
|
|
128
|
-
configList: {
|
|
129
|
-
type: Array,
|
|
130
|
-
required: false,
|
|
131
|
-
default: void 0
|
|
132
|
-
},
|
|
133
|
-
placement: {
|
|
134
|
-
type: String,
|
|
135
|
-
required: false,
|
|
136
|
-
default: void 0
|
|
137
|
-
},
|
|
138
|
-
prefixCls: {
|
|
139
|
-
type: String,
|
|
140
|
-
required: false,
|
|
141
|
-
default: void 0
|
|
142
|
-
},
|
|
143
|
-
motion: {
|
|
144
|
-
type: [Object, Function],
|
|
145
|
-
required: false,
|
|
146
|
-
default: void 0
|
|
147
|
-
},
|
|
148
|
-
stack: {
|
|
149
|
-
type: [Boolean, Object],
|
|
150
|
-
required: false,
|
|
151
|
-
default: void 0
|
|
152
|
-
},
|
|
153
|
-
onAllNoticeRemoved: {
|
|
154
|
-
type: Function,
|
|
155
|
-
required: false,
|
|
156
|
-
default: void 0
|
|
157
|
-
},
|
|
158
|
-
onNoticeClose: {
|
|
159
|
-
type: Function,
|
|
160
|
-
required: false,
|
|
161
|
-
default: void 0
|
|
162
|
-
}
|
|
163
|
-
} });
|
|
164
|
-
export { NoticeList_default as default };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
3
|
-
let vue = require("vue");
|
|
4
|
-
const NotificationContext = Symbol("NotificationContext");
|
|
5
|
-
function useNotificationProvider(props) {
|
|
6
|
-
(0, vue.provide)(NotificationContext, props);
|
|
7
|
-
return props;
|
|
8
|
-
}
|
|
9
|
-
function useNotificationContext() {
|
|
10
|
-
return (0, vue.inject)(NotificationContext, (0, vue.ref)({}));
|
|
11
|
-
}
|
|
12
|
-
exports.NotificationContext = NotificationContext;
|
|
13
|
-
exports.useNotificationContext = useNotificationContext;
|
|
14
|
-
exports.useNotificationProvider = useNotificationProvider;
|
package/dist/Notifications.cjs
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
6
|
-
const require_NoticeList = require("./NoticeList.cjs");
|
|
7
|
-
let vue = require("vue");
|
|
8
|
-
function _isSlot(s) {
|
|
9
|
-
return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !(0, vue.isVNode)(s);
|
|
10
|
-
}
|
|
11
|
-
var defaults = { prefixCls: "vc-notification" };
|
|
12
|
-
var Notifications = /* @__PURE__ */ (0, vue.defineComponent)((props, { expose }) => {
|
|
13
|
-
const configList = (0, vue.shallowRef)([]);
|
|
14
|
-
const onNoticeClose = (key) => {
|
|
15
|
-
const config = configList.value.find((item) => item.key === key);
|
|
16
|
-
const closable = config?.closable;
|
|
17
|
-
(closable && typeof closable === "object" ? closable : {}).onClose?.();
|
|
18
|
-
config?.onClose?.();
|
|
19
|
-
configList.value = configList.value.filter((item) => item.key !== key);
|
|
20
|
-
};
|
|
21
|
-
expose({
|
|
22
|
-
open: (config) => {
|
|
23
|
-
const list = configList.value;
|
|
24
|
-
let clone = [...configList.value];
|
|
25
|
-
const index = clone.findIndex((item) => item.key === config.key);
|
|
26
|
-
const innerConfig = { ...config };
|
|
27
|
-
if (index >= 0) {
|
|
28
|
-
innerConfig.times = (list[index]?.times || 0) + 1;
|
|
29
|
-
clone[index] = innerConfig;
|
|
30
|
-
} else {
|
|
31
|
-
innerConfig.times = 0;
|
|
32
|
-
clone.push(innerConfig);
|
|
33
|
-
}
|
|
34
|
-
const maxCount = props.maxCount ?? 0;
|
|
35
|
-
if (maxCount > 0 && clone.length > maxCount) clone = clone.slice(-maxCount);
|
|
36
|
-
configList.value = clone;
|
|
37
|
-
},
|
|
38
|
-
close: onNoticeClose,
|
|
39
|
-
destroy: () => {
|
|
40
|
-
configList.value = [];
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
const placements = (0, vue.shallowRef)({});
|
|
44
|
-
(0, vue.watch)(configList, () => {
|
|
45
|
-
const nextPlacements = {};
|
|
46
|
-
configList.value.forEach((config) => {
|
|
47
|
-
const { placement = "topRight" } = config;
|
|
48
|
-
if (placement) {
|
|
49
|
-
nextPlacements[placement] = nextPlacements[placement] || [];
|
|
50
|
-
nextPlacements[placement].push(config);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
Object.keys(placements.value).forEach((_placement) => {
|
|
54
|
-
const placement = _placement;
|
|
55
|
-
nextPlacements[placement] = nextPlacements[placement] || [];
|
|
56
|
-
});
|
|
57
|
-
placements.value = nextPlacements;
|
|
58
|
-
});
|
|
59
|
-
const onAllNoticeRemoved = (placement) => {
|
|
60
|
-
const clone = { ...placements.value };
|
|
61
|
-
if (!(clone[placement] || []).length) delete clone[placement];
|
|
62
|
-
placements.value = clone;
|
|
63
|
-
};
|
|
64
|
-
const emptyRef = (0, vue.shallowRef)(false);
|
|
65
|
-
(0, vue.watch)(placements, () => {
|
|
66
|
-
if (Object.keys(placements.value).length > 0) emptyRef.value = true;
|
|
67
|
-
else if (emptyRef.value) {
|
|
68
|
-
props?.onAllRemoved?.();
|
|
69
|
-
emptyRef.value = false;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
return () => {
|
|
73
|
-
let _slot;
|
|
74
|
-
const { container } = props;
|
|
75
|
-
const prefixCls = props.prefixCls ?? defaults.prefixCls ?? "";
|
|
76
|
-
if (!container) return null;
|
|
77
|
-
return (0, vue.createVNode)(vue.Teleport, { "to": container }, _isSlot(_slot = Object.keys(placements.value).map((placement) => {
|
|
78
|
-
const placementConfigList = placements.value[placement];
|
|
79
|
-
const list = (0, vue.createVNode)(require_NoticeList.default, {
|
|
80
|
-
"key": placement,
|
|
81
|
-
"configList": placementConfigList,
|
|
82
|
-
"placement": placement,
|
|
83
|
-
"prefixCls": prefixCls,
|
|
84
|
-
"class": props.className?.(placement),
|
|
85
|
-
"style": props.style?.(placement),
|
|
86
|
-
"motion": props.motion,
|
|
87
|
-
"stack": props.stack,
|
|
88
|
-
"onAllNoticeRemoved": () => onAllNoticeRemoved(placement),
|
|
89
|
-
"onNoticeClose": onNoticeClose
|
|
90
|
-
}, null);
|
|
91
|
-
return props.renderNotifications ? props.renderNotifications(list, {
|
|
92
|
-
prefixCls,
|
|
93
|
-
key: placement
|
|
94
|
-
}) : list;
|
|
95
|
-
})) ? _slot : { default: () => [_slot] });
|
|
96
|
-
};
|
|
97
|
-
}, {
|
|
98
|
-
props: /* @__PURE__ */ (0, vue.mergeDefaults)({
|
|
99
|
-
prefixCls: {
|
|
100
|
-
type: String,
|
|
101
|
-
required: false,
|
|
102
|
-
default: void 0
|
|
103
|
-
},
|
|
104
|
-
motion: {
|
|
105
|
-
type: [Object, Function],
|
|
106
|
-
required: false,
|
|
107
|
-
default: void 0
|
|
108
|
-
},
|
|
109
|
-
container: {
|
|
110
|
-
required: false,
|
|
111
|
-
default: void 0
|
|
112
|
-
},
|
|
113
|
-
maxCount: {
|
|
114
|
-
type: Number,
|
|
115
|
-
required: false,
|
|
116
|
-
default: void 0
|
|
117
|
-
},
|
|
118
|
-
className: {
|
|
119
|
-
type: Function,
|
|
120
|
-
required: false,
|
|
121
|
-
default: void 0
|
|
122
|
-
},
|
|
123
|
-
style: {
|
|
124
|
-
type: Function,
|
|
125
|
-
required: false,
|
|
126
|
-
default: void 0
|
|
127
|
-
},
|
|
128
|
-
onAllRemoved: {
|
|
129
|
-
required: false,
|
|
130
|
-
default: void 0
|
|
131
|
-
},
|
|
132
|
-
stack: {
|
|
133
|
-
type: [Boolean, Object],
|
|
134
|
-
required: false,
|
|
135
|
-
default: void 0
|
|
136
|
-
},
|
|
137
|
-
renderNotifications: {
|
|
138
|
-
type: Function,
|
|
139
|
-
required: false,
|
|
140
|
-
default: void 0
|
|
141
|
-
}
|
|
142
|
-
}, defaults),
|
|
143
|
-
name: "Notifications"
|
|
144
|
-
});
|
|
145
|
-
var Notifications_default = Notifications;
|
|
146
|
-
exports.default = Notifications_default;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __copyProps = (to, from, except, desc) => {
|
|
8
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
9
|
-
key = keys[i];
|
|
10
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
11
|
-
get: ((k) => from[k]).bind(null, key),
|
|
12
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
18
|
-
value: mod,
|
|
19
|
-
enumerable: true
|
|
20
|
-
}) : target, mod));
|
|
21
|
-
exports.__toESM = __toESM;
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
6
|
-
const require_Notifications = require("../Notifications.cjs");
|
|
7
|
-
let vue = require("vue");
|
|
8
|
-
var defaultGetContainer = () => document.body;
|
|
9
|
-
var uniqueKey = 0;
|
|
10
|
-
function mergeConfig(...objList) {
|
|
11
|
-
const clone = {};
|
|
12
|
-
objList.forEach((obj) => {
|
|
13
|
-
if (obj) Object.keys(obj).forEach((key) => {
|
|
14
|
-
const val = obj[key];
|
|
15
|
-
if (val !== void 0) clone[key] = val;
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
return clone;
|
|
19
|
-
}
|
|
20
|
-
function useNotification(rootConfig = {}) {
|
|
21
|
-
const configRef = (0, vue.computed)(() => (0, vue.unref)(rootConfig) || {});
|
|
22
|
-
const container = (0, vue.shallowRef)();
|
|
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
|
-
};
|
|
31
|
-
const contextHolder = () => (0, vue.createVNode)(require_Notifications.default, {
|
|
32
|
-
"container": container.value,
|
|
33
|
-
"ref": notificationRef,
|
|
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
|
|
42
|
-
}, null);
|
|
43
|
-
const taskQueue = (0, vue.shallowRef)([]);
|
|
44
|
-
const api = {
|
|
45
|
-
open(config) {
|
|
46
|
-
const mergedConfig = mergeConfig(shareConfig.value, config);
|
|
47
|
-
if (mergedConfig.key === null || mergedConfig.key === void 0) {
|
|
48
|
-
mergedConfig.key = `vc-notification-${uniqueKey}`;
|
|
49
|
-
uniqueKey += 1;
|
|
50
|
-
}
|
|
51
|
-
taskQueue.value = [...taskQueue.value, {
|
|
52
|
-
type: "open",
|
|
53
|
-
config: mergedConfig
|
|
54
|
-
}];
|
|
55
|
-
},
|
|
56
|
-
close(key) {
|
|
57
|
-
taskQueue.value = [...taskQueue.value, {
|
|
58
|
-
type: "close",
|
|
59
|
-
key
|
|
60
|
-
}];
|
|
61
|
-
},
|
|
62
|
-
destroy() {
|
|
63
|
-
taskQueue.value = [...taskQueue.value, { type: "destroy" }];
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
(0, vue.onMounted)(() => {
|
|
67
|
-
container.value = resolveContainer();
|
|
68
|
-
});
|
|
69
|
-
(0, vue.watch)(() => configRef.value.getContainer, () => {
|
|
70
|
-
container.value = resolveContainer();
|
|
71
|
-
});
|
|
72
|
-
(0, vue.watch)(taskQueue, () => {
|
|
73
|
-
if (notificationRef.value && taskQueue.value.length) {
|
|
74
|
-
taskQueue.value.forEach((task) => {
|
|
75
|
-
switch (task.type) {
|
|
76
|
-
case "open":
|
|
77
|
-
notificationRef.value?.open(task.config);
|
|
78
|
-
break;
|
|
79
|
-
case "close":
|
|
80
|
-
notificationRef.value?.close(task.key);
|
|
81
|
-
break;
|
|
82
|
-
case "destroy":
|
|
83
|
-
notificationRef.value?.destroy();
|
|
84
|
-
break;
|
|
85
|
-
default: break;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
taskQueue.value = taskQueue.value.filter((task) => !taskQueue.value.includes(task));
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
return [api, contextHolder];
|
|
92
|
-
}
|
|
93
|
-
exports.default = useNotification;
|
package/dist/hooks/useStack.cjs
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
6
|
-
let vue = require("vue");
|
|
7
|
-
var DEFAULT_OFFSET = 8;
|
|
8
|
-
var DEFAULT_THRESHOLD = 3;
|
|
9
|
-
var DEFAULT_GAP = 16;
|
|
10
|
-
var useStack = (config) => {
|
|
11
|
-
const result = (0, vue.reactive)({
|
|
12
|
-
offset: DEFAULT_OFFSET,
|
|
13
|
-
threshold: DEFAULT_THRESHOLD,
|
|
14
|
-
gap: DEFAULT_GAP
|
|
15
|
-
});
|
|
16
|
-
(0, vue.watchEffect)(() => {
|
|
17
|
-
const _config = (0, vue.unref)(config);
|
|
18
|
-
if (_config && typeof _config === "object") {
|
|
19
|
-
result.offset = _config.offset ?? DEFAULT_OFFSET;
|
|
20
|
-
result.threshold = _config.threshold ?? DEFAULT_THRESHOLD;
|
|
21
|
-
result.gap = _config.gap ?? DEFAULT_GAP;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
return [(0, vue.computed)(() => !!(0, vue.unref)(config)), (0, vue.toRefs)(result)];
|
|
25
|
-
};
|
|
26
|
-
var useStack_default = useStack;
|
|
27
|
-
exports.default = useStack_default;
|
package/dist/index.cjs
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_Notice = require("./Notice.cjs");
|
|
3
|
-
const require_NotificationProvider = require("./NotificationProvider.cjs");
|
|
4
|
-
const require_useNotification = require("./hooks/useNotification.cjs");
|
|
5
|
-
exports.Notice = require_Notice.default;
|
|
6
|
-
exports.useNotification = require_useNotification.default;
|
|
7
|
-
exports.useNotificationProvider = require_NotificationProvider.useNotificationProvider;
|
package/dist/interface.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|