@king-design/vue 3.6.2 → 3.7.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/components/anchor/constants.d.ts +2 -0
- package/components/anchor/constants.js +2 -0
- package/components/anchor/index.d.ts +41 -0
- package/components/anchor/index.js +141 -0
- package/components/anchor/index.spec.d.ts +1 -0
- package/components/anchor/index.spec.js +230 -0
- package/components/anchor/index.vdt.js +31 -0
- package/components/anchor/link.d.ts +16 -0
- package/components/anchor/link.js +52 -0
- package/components/anchor/link.vdt.js +49 -0
- package/components/anchor/styles.d.ts +5 -0
- package/components/anchor/styles.js +30 -0
- package/components/anchor/useScroll.d.ts +7 -0
- package/components/anchor/useScroll.js +218 -0
- package/components/dialog/base.vdt.js +1 -1
- package/components/drawer/index.d.ts +3 -0
- package/components/drawer/index.js +22 -3
- package/components/drawer/index.spec.js +83 -0
- package/components/drawer/index.vdt.js +23 -3
- package/components/drawer/styles.js +1 -1
- package/components/drawer/useDrawerResizable.d.ts +10 -0
- package/components/drawer/useDrawerResizable.js +162 -0
- package/components/menu/styles.d.ts +1 -0
- package/components/menu/styles.js +4 -1
- package/components/notification/index.d.ts +1 -0
- package/components/notification/index.js +1 -0
- package/components/notification/index.spec.d.ts +1 -0
- package/components/notification/index.spec.js +317 -0
- package/components/notification/notification.d.ts +39 -0
- package/components/notification/notification.js +183 -0
- package/components/notification/notification.vdt.js +56 -0
- package/components/notification/notifications.d.ts +16 -0
- package/components/notification/notifications.js +51 -0
- package/components/notification/notifications.vdt.js +24 -0
- package/components/notification/styles.d.ts +9 -0
- package/components/notification/styles.js +110 -0
- package/components/select/styles.js +1 -1
- package/components/table/styles.js +1 -1
- package/components/tabs/useActiveBar.js +7 -3
- package/components/tag/base.d.ts +2 -0
- package/components/tag/base.js +3 -0
- package/components/tag/index.spec.js +17 -0
- package/components/tag/index.vdt.js +12 -5
- package/components/tag/styles.d.ts +9 -0
- package/components/tag/styles.js +14 -1
- package/components/tag/useColor.d.ts +7 -0
- package/components/tag/useColor.js +71 -0
- package/components/timepicker/index.spec.js +70 -42
- package/components/timepicker/useDefaultValue.js +12 -7
- package/components/timepicker/useStep.js +4 -2
- package/components/transfer/index.d.ts +13 -0
- package/components/transfer/index.js +6 -2
- package/components/transfer/index.spec.js +197 -0
- package/components/transfer/index.vdt.js +28 -5
- package/components/transfer/styles.js +4 -1
- package/components/transfer/useCheck.js +2 -1
- package/components/transfer/usePagination.d.ts +12 -0
- package/components/transfer/usePagination.js +79 -0
- package/dist/fonts/iconfont.eot +0 -0
- package/dist/fonts/iconfont.svg +235 -0
- package/dist/fonts/iconfont.ttf +0 -0
- package/dist/fonts/iconfont.woff +0 -0
- package/dist/fonts/iconfont.woff2 +0 -0
- package/dist/fonts/ionicons.eot +0 -0
- package/dist/fonts/ionicons.svg +2230 -0
- package/dist/fonts/ionicons.ttf +0 -0
- package/dist/fonts/ionicons.woff +0 -0
- package/dist/fonts/ionicons.woff2 +0 -0
- package/dist/i18n/en-US.js +1411 -0
- package/dist/i18n/en-US.js.map +1 -0
- package/dist/i18n/en-US.min.js +1 -0
- package/dist/i18n/index.js +283 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/i18n/index.min.js +1 -0
- package/dist/index.js +58128 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +1 -0
- package/index.d.ts +4 -2
- package/index.js +4 -2
- package/install.js +2 -0
- package/package.json +3 -1
- package/styles/fonts/iconfont.eot +0 -0
- package/styles/fonts/iconfont.js +1 -1
- package/styles/fonts/iconfont.svg +38 -0
- package/styles/fonts/iconfont.ttf +0 -0
- package/styles/fonts/iconfont.woff +0 -0
- package/styles/fonts/iconfont.woff2 +0 -0
- package/styles/theme.d.ts +8 -0
- package/styles/theme.js +5 -1
- package/yarn-error.log +43 -44
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
|
|
3
|
+
import TypesDemo from '~/components/notification/demos/types';
|
|
4
|
+
import EventDemo from '~/components/notification/demos/events';
|
|
5
|
+
import { mount, unmount, dispatchEvent, getElement, wait } from '../../test/utils';
|
|
6
|
+
import { Notification } from './';
|
|
7
|
+
import { createVNode as h } from 'intact-vue-next';
|
|
8
|
+
describe('Notification', function () {
|
|
9
|
+
afterEach(function () {
|
|
10
|
+
unmount();
|
|
11
|
+
});
|
|
12
|
+
it('show basic notification', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
13
|
+
var notification;
|
|
14
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
15
|
+
while (1) switch (_context.prev = _context.next) {
|
|
16
|
+
case 0:
|
|
17
|
+
Notification.notice({
|
|
18
|
+
title: 'Hello, Kingcloud Design!',
|
|
19
|
+
content: '这是一条基础用法的通知'
|
|
20
|
+
});
|
|
21
|
+
_context.next = 3;
|
|
22
|
+
return wait();
|
|
23
|
+
case 3:
|
|
24
|
+
notification = getElement('.k-notification');
|
|
25
|
+
expect(notification.outerHTML).to.matchSnapshot();
|
|
26
|
+
case 5:
|
|
27
|
+
case "end":
|
|
28
|
+
return _context.stop();
|
|
29
|
+
}
|
|
30
|
+
}, _callee);
|
|
31
|
+
})));
|
|
32
|
+
it('show notifications with different types', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
33
|
+
var _mount, instance, element, _element$querySelecto, info, error, warning, success, notification;
|
|
34
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
35
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
36
|
+
case 0:
|
|
37
|
+
_mount = mount(TypesDemo), instance = _mount[0], element = _mount[1];
|
|
38
|
+
_element$querySelecto = element.querySelectorAll('.k-btn'), info = _element$querySelecto[0], error = _element$querySelecto[1], warning = _element$querySelecto[2], success = _element$querySelecto[3];
|
|
39
|
+
info.click();
|
|
40
|
+
_context2.next = 5;
|
|
41
|
+
return wait();
|
|
42
|
+
case 5:
|
|
43
|
+
notification = getElement('.k-notification');
|
|
44
|
+
expect(notification.outerHTML).to.matchSnapshot();
|
|
45
|
+
error.click();
|
|
46
|
+
_context2.next = 10;
|
|
47
|
+
return wait();
|
|
48
|
+
case 10:
|
|
49
|
+
expect(getElement('.k-notification').outerHTML).to.matchSnapshot();
|
|
50
|
+
warning.click();
|
|
51
|
+
_context2.next = 14;
|
|
52
|
+
return wait();
|
|
53
|
+
case 14:
|
|
54
|
+
expect(getElement('.k-notification').outerHTML).to.matchSnapshot();
|
|
55
|
+
success.click();
|
|
56
|
+
_context2.next = 18;
|
|
57
|
+
return wait();
|
|
58
|
+
case 18:
|
|
59
|
+
expect(getElement('.k-notification').outerHTML).to.matchSnapshot();
|
|
60
|
+
case 19:
|
|
61
|
+
case "end":
|
|
62
|
+
return _context2.stop();
|
|
63
|
+
}
|
|
64
|
+
}, _callee2);
|
|
65
|
+
})));
|
|
66
|
+
it('set duration', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
67
|
+
var notification, notification1;
|
|
68
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
69
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
70
|
+
case 0:
|
|
71
|
+
this.timeout(0);
|
|
72
|
+
Notification.info({
|
|
73
|
+
title: '测试标题',
|
|
74
|
+
content: '测试内容',
|
|
75
|
+
duration: 500
|
|
76
|
+
});
|
|
77
|
+
_context3.next = 4;
|
|
78
|
+
return wait();
|
|
79
|
+
case 4:
|
|
80
|
+
notification = getElement('.k-notification');
|
|
81
|
+
expect(notification.outerHTML).to.matchSnapshot();
|
|
82
|
+
// should not remove when mouseenter
|
|
83
|
+
dispatchEvent(notification, 'mouseenter');
|
|
84
|
+
_context3.next = 9;
|
|
85
|
+
return wait(1000);
|
|
86
|
+
case 9:
|
|
87
|
+
notification1 = getElement('.k-notification');
|
|
88
|
+
expect(notification1).eql(notification);
|
|
89
|
+
dispatchEvent(notification, 'mouseleave');
|
|
90
|
+
_context3.next = 14;
|
|
91
|
+
return wait(500);
|
|
92
|
+
case 14:
|
|
93
|
+
notification1 = getElement('.k-notification');
|
|
94
|
+
expect(notification1).eql(notification);
|
|
95
|
+
_context3.next = 18;
|
|
96
|
+
return wait(700);
|
|
97
|
+
case 18:
|
|
98
|
+
notification1 = getElement('.k-notification');
|
|
99
|
+
expect(notification1).not.eql(notification);
|
|
100
|
+
case 20:
|
|
101
|
+
case "end":
|
|
102
|
+
return _context3.stop();
|
|
103
|
+
}
|
|
104
|
+
}, _callee3, this);
|
|
105
|
+
})));
|
|
106
|
+
it('set duration to 0 should not auto close', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
|
|
107
|
+
var notification, notification1;
|
|
108
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
109
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
110
|
+
case 0:
|
|
111
|
+
this.timeout(0);
|
|
112
|
+
Notification.warning({
|
|
113
|
+
title: '不会自动关闭',
|
|
114
|
+
content: '这条通知不会自动关闭',
|
|
115
|
+
duration: 0
|
|
116
|
+
});
|
|
117
|
+
_context4.next = 4;
|
|
118
|
+
return wait();
|
|
119
|
+
case 4:
|
|
120
|
+
notification = getElement('.k-notification'); // wait for a long time, should still exist
|
|
121
|
+
_context4.next = 7;
|
|
122
|
+
return wait(2000);
|
|
123
|
+
case 7:
|
|
124
|
+
notification1 = getElement('.k-notification');
|
|
125
|
+
expect(notification1).eql(notification);
|
|
126
|
+
case 9:
|
|
127
|
+
case "end":
|
|
128
|
+
return _context4.stop();
|
|
129
|
+
}
|
|
130
|
+
}, _callee4, this);
|
|
131
|
+
})));
|
|
132
|
+
it('hide close button when closable is false', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
|
|
133
|
+
var notification, closeButton;
|
|
134
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
135
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
136
|
+
case 0:
|
|
137
|
+
Notification.info({
|
|
138
|
+
title: '隐藏关闭按钮',
|
|
139
|
+
content: '这条通知隐藏了关闭按钮',
|
|
140
|
+
closable: false
|
|
141
|
+
});
|
|
142
|
+
_context5.next = 3;
|
|
143
|
+
return wait();
|
|
144
|
+
case 3:
|
|
145
|
+
notification = getElement('.k-notification');
|
|
146
|
+
closeButton = notification.querySelector('.k-notification-close');
|
|
147
|
+
expect(closeButton).to.be.null;
|
|
148
|
+
expect(notification.outerHTML).to.matchSnapshot();
|
|
149
|
+
case 7:
|
|
150
|
+
case "end":
|
|
151
|
+
return _context5.stop();
|
|
152
|
+
}
|
|
153
|
+
}, _callee5);
|
|
154
|
+
})));
|
|
155
|
+
it('should not show icon when type is empty string and icon is not provided', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
|
|
156
|
+
var notification, icon;
|
|
157
|
+
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
158
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
159
|
+
case 0:
|
|
160
|
+
Notification.notice({
|
|
161
|
+
title: '无类型通知',
|
|
162
|
+
content: '这条通知没有类型,不应该显示图标',
|
|
163
|
+
type: ''
|
|
164
|
+
});
|
|
165
|
+
_context6.next = 3;
|
|
166
|
+
return wait();
|
|
167
|
+
case 3:
|
|
168
|
+
notification = getElement('.k-notification');
|
|
169
|
+
icon = notification.querySelector('.k-notification-icon');
|
|
170
|
+
expect(icon).to.be.null;
|
|
171
|
+
expect(notification.outerHTML).to.matchSnapshot();
|
|
172
|
+
case 7:
|
|
173
|
+
case "end":
|
|
174
|
+
return _context6.stop();
|
|
175
|
+
}
|
|
176
|
+
}, _callee6);
|
|
177
|
+
})));
|
|
178
|
+
it('show notification at different positions', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
|
|
179
|
+
var positions, _i, _positions, position, containers, container, notification;
|
|
180
|
+
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
181
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
182
|
+
case 0:
|
|
183
|
+
positions = ['topRight', 'topLeft', 'bottomRight', 'bottomLeft', 'top', 'bottom'];
|
|
184
|
+
_i = 0, _positions = positions;
|
|
185
|
+
case 2:
|
|
186
|
+
if (!(_i < _positions.length)) {
|
|
187
|
+
_context7.next = 16;
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
position = _positions[_i];
|
|
191
|
+
Notification.info({
|
|
192
|
+
title: '位置测试',
|
|
193
|
+
content: "\u901A\u77E5\u51FA\u73B0\u5728" + position + "\u4F4D\u7F6E",
|
|
194
|
+
position: position
|
|
195
|
+
});
|
|
196
|
+
_context7.next = 7;
|
|
197
|
+
return wait();
|
|
198
|
+
case 7:
|
|
199
|
+
containers = document.querySelectorAll(".k-notifications");
|
|
200
|
+
container = containers[containers.length - 1];
|
|
201
|
+
expect(container).to.exist;
|
|
202
|
+
notification = container == null ? void 0 : container.querySelector(".k-notification.k-position-" + position);
|
|
203
|
+
expect(notification).to.exist;
|
|
204
|
+
expect(notification.outerHTML).to.matchSnapshot();
|
|
205
|
+
case 13:
|
|
206
|
+
_i++;
|
|
207
|
+
_context7.next = 2;
|
|
208
|
+
break;
|
|
209
|
+
case 16:
|
|
210
|
+
case "end":
|
|
211
|
+
return _context7.stop();
|
|
212
|
+
}
|
|
213
|
+
}, _callee7);
|
|
214
|
+
})));
|
|
215
|
+
it('should trigger onClose callback when notification auto closes', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
|
|
216
|
+
var onCloseSpy, notification;
|
|
217
|
+
return _regeneratorRuntime.wrap(function _callee8$(_context8) {
|
|
218
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
219
|
+
case 0:
|
|
220
|
+
this.timeout(0);
|
|
221
|
+
onCloseSpy = sinon.spy();
|
|
222
|
+
Notification.info({
|
|
223
|
+
title: '自动关闭测试',
|
|
224
|
+
content: '这条通知会自动关闭',
|
|
225
|
+
onClose: onCloseSpy,
|
|
226
|
+
duration: 500
|
|
227
|
+
});
|
|
228
|
+
_context8.next = 5;
|
|
229
|
+
return wait();
|
|
230
|
+
case 5:
|
|
231
|
+
notification = getElement('.k-notification');
|
|
232
|
+
expect(notification).to.exist;
|
|
233
|
+
// 等待自动关闭
|
|
234
|
+
_context8.next = 9;
|
|
235
|
+
return wait(700);
|
|
236
|
+
case 9:
|
|
237
|
+
expect(onCloseSpy.callCount).to.eql(1);
|
|
238
|
+
expect(onCloseSpy.calledOnce).to.be.true;
|
|
239
|
+
case 11:
|
|
240
|
+
case "end":
|
|
241
|
+
return _context8.stop();
|
|
242
|
+
}
|
|
243
|
+
}, _callee8, this);
|
|
244
|
+
})));
|
|
245
|
+
it('test notification click and close event', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
|
|
246
|
+
var _mount2, instance, element, _element$querySelecto2, btn, notification, message1, closeButton, message2;
|
|
247
|
+
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
|
248
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
249
|
+
case 0:
|
|
250
|
+
_mount2 = mount(EventDemo), instance = _mount2[0], element = _mount2[1];
|
|
251
|
+
_element$querySelecto2 = element.querySelectorAll('.k-btn'), btn = _element$querySelecto2[0];
|
|
252
|
+
btn.click();
|
|
253
|
+
_context9.next = 5;
|
|
254
|
+
return wait();
|
|
255
|
+
case 5:
|
|
256
|
+
notification = document.querySelector('.event-test');
|
|
257
|
+
dispatchEvent(notification, 'click');
|
|
258
|
+
_context9.next = 9;
|
|
259
|
+
return wait(500);
|
|
260
|
+
case 9:
|
|
261
|
+
message1 = document.querySelector('.k-info');
|
|
262
|
+
expect(message1.outerHTML).to.matchSnapshot();
|
|
263
|
+
_context9.next = 13;
|
|
264
|
+
return wait(500);
|
|
265
|
+
case 13:
|
|
266
|
+
closeButton = notification.querySelector('.k-notification-close');
|
|
267
|
+
closeButton.click();
|
|
268
|
+
_context9.next = 17;
|
|
269
|
+
return wait(500);
|
|
270
|
+
case 17:
|
|
271
|
+
message2 = document.querySelector('.k-warning');
|
|
272
|
+
expect(message2.outerHTML).to.matchSnapshot();
|
|
273
|
+
case 19:
|
|
274
|
+
case "end":
|
|
275
|
+
return _context9.stop();
|
|
276
|
+
}
|
|
277
|
+
}, _callee9);
|
|
278
|
+
})));
|
|
279
|
+
it('should support VNode as title and content', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
|
|
280
|
+
var notification, titleContainer, title, contentContainer, content;
|
|
281
|
+
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
|
|
282
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
283
|
+
case 0:
|
|
284
|
+
Notification.info({
|
|
285
|
+
title: h('div', {
|
|
286
|
+
class: 'custom-title'
|
|
287
|
+
}, '自定义标题'),
|
|
288
|
+
content: h('div', {
|
|
289
|
+
class: 'custom-content'
|
|
290
|
+
}, [h('span', {
|
|
291
|
+
style: 'color: red;'
|
|
292
|
+
}, '这是'), '一段', h('strong', null, '自定义内容')]),
|
|
293
|
+
className: 'custom-notification'
|
|
294
|
+
});
|
|
295
|
+
_context10.next = 3;
|
|
296
|
+
return wait(100);
|
|
297
|
+
case 3:
|
|
298
|
+
notification = document.querySelector('.custom-notification');
|
|
299
|
+
expect(notification.outerHTML).to.matchSnapshot();
|
|
300
|
+
titleContainer = notification.querySelector('.k-notification-title');
|
|
301
|
+
expect(titleContainer).to.exist;
|
|
302
|
+
title = titleContainer.querySelector('.custom-title');
|
|
303
|
+
expect(title).to.exist;
|
|
304
|
+
expect(title.textContent).to.eql('自定义标题');
|
|
305
|
+
contentContainer = notification.querySelector('.k-notification-body');
|
|
306
|
+
expect(contentContainer).to.exist;
|
|
307
|
+
content = contentContainer.querySelector('.custom-content');
|
|
308
|
+
expect(content).to.exist;
|
|
309
|
+
expect(content.querySelector('span')).to.exist;
|
|
310
|
+
expect(content.querySelector('strong')).to.exist;
|
|
311
|
+
case 16:
|
|
312
|
+
case "end":
|
|
313
|
+
return _context10.stop();
|
|
314
|
+
}
|
|
315
|
+
}, _callee10);
|
|
316
|
+
})));
|
|
317
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Component, VNode, TypeDefs, Children } from 'intact-vue-next';
|
|
2
|
+
export interface NotificationProps {
|
|
3
|
+
title?: Children;
|
|
4
|
+
content?: Children;
|
|
5
|
+
duration?: number;
|
|
6
|
+
type?: 'info' | 'error' | 'success' | 'warning' | '';
|
|
7
|
+
closable?: boolean;
|
|
8
|
+
icon?: string | VNode;
|
|
9
|
+
position?: 'topRight' | 'topLeft' | 'bottomRight' | 'bottomLeft' | 'top' | 'bottom';
|
|
10
|
+
className?: string;
|
|
11
|
+
onClick?: (e: MouseEvent) => void;
|
|
12
|
+
onClose?: () => void;
|
|
13
|
+
}
|
|
14
|
+
export declare class Notification extends Component<NotificationProps> {
|
|
15
|
+
static template: string | import('intact-vue-next').Template<any>;
|
|
16
|
+
static typeDefs: Required<TypeDefs<NotificationProps>>;
|
|
17
|
+
static defaults: () => Partial<NotificationProps>;
|
|
18
|
+
static classNamePrefix: string;
|
|
19
|
+
/**
|
|
20
|
+
* 显示通知
|
|
21
|
+
* @param props 通知配置对象
|
|
22
|
+
* @returns 返回通知的唯一 ID,可用于调用 close 方法关闭通知
|
|
23
|
+
*/
|
|
24
|
+
static notice(props: Partial<NotificationProps>): number;
|
|
25
|
+
/**
|
|
26
|
+
* 关闭指定 ID 的通知
|
|
27
|
+
* @param id 通知的唯一 ID,由 notice 方法返回
|
|
28
|
+
*/
|
|
29
|
+
static close(id: number): void;
|
|
30
|
+
static info(props: Partial<NotificationProps>): number;
|
|
31
|
+
static error(props: Partial<NotificationProps>): number;
|
|
32
|
+
static success(props: Partial<NotificationProps>): number;
|
|
33
|
+
static warning(props: Partial<NotificationProps>): number;
|
|
34
|
+
private delayClose;
|
|
35
|
+
private config;
|
|
36
|
+
onClick(e: MouseEvent): void;
|
|
37
|
+
onCloseClick(e: MouseEvent): void;
|
|
38
|
+
close(): void;
|
|
39
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js/instance/slice";
|
|
2
|
+
import _Array$from from "@babel/runtime-corejs3/core-js/array/from";
|
|
3
|
+
import _Symbol from "@babel/runtime-corejs3/core-js/symbol";
|
|
4
|
+
import _getIteratorMethod from "@babel/runtime-corejs3/core-js/get-iterator-method";
|
|
5
|
+
import _extends from "@babel/runtime-corejs3/helpers/extends";
|
|
6
|
+
import _inheritsLoose from "@babel/runtime-corejs3/helpers/inheritsLoose";
|
|
7
|
+
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof _Symbol !== "undefined" && _getIteratorMethod(o) || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
8
|
+
function _unsupportedIterableToArray(o, minLen) { var _context2; if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = _sliceInstanceProperty(_context2 = Object.prototype.toString.call(o)).call(_context2, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return _Array$from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
9
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
10
|
+
import _Map from "@babel/runtime-corejs3/core-js/map";
|
|
11
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js/instance/concat";
|
|
12
|
+
import _entriesInstanceProperty from "@babel/runtime-corejs3/core-js/instance/entries";
|
|
13
|
+
import { __decorate } from "tslib";
|
|
14
|
+
import { Component, VNode, render, createVNode as h } from 'intact-vue-next';
|
|
15
|
+
import template from './notification.vdt';
|
|
16
|
+
import { Notifications } from './notifications';
|
|
17
|
+
import { useDelayClose } from '../../hooks/useDelayClose';
|
|
18
|
+
import { bind } from '../utils';
|
|
19
|
+
import { useConfigContext } from '../config';
|
|
20
|
+
var typeDefs = {
|
|
21
|
+
title: [String, VNode],
|
|
22
|
+
content: [String, VNode],
|
|
23
|
+
duration: Number,
|
|
24
|
+
type: ['info', 'error', 'success', 'warning', ''],
|
|
25
|
+
closable: Boolean,
|
|
26
|
+
icon: [String, VNode],
|
|
27
|
+
position: ['topRight', 'topLeft', 'bottomRight', 'bottomLeft', 'top', 'bottom'],
|
|
28
|
+
className: String,
|
|
29
|
+
onClick: Function,
|
|
30
|
+
onClose: Function
|
|
31
|
+
};
|
|
32
|
+
var id = 0;
|
|
33
|
+
var defaults = function defaults() {
|
|
34
|
+
return {
|
|
35
|
+
duration: 4500,
|
|
36
|
+
type: '',
|
|
37
|
+
closable: true,
|
|
38
|
+
position: 'topRight'
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
// 按位置维护多个容器实例
|
|
42
|
+
var notificationsMap = new _Map();
|
|
43
|
+
// 存储 notificationId -> { position, key } 的映射,用于通过 id 关闭通知
|
|
44
|
+
var notificationIdMap = new _Map();
|
|
45
|
+
export var Notification = /*#__PURE__*/function (_Component) {
|
|
46
|
+
_inheritsLoose(Notification, _Component);
|
|
47
|
+
function Notification() {
|
|
48
|
+
var _context;
|
|
49
|
+
var _this;
|
|
50
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
51
|
+
args[_key] = arguments[_key];
|
|
52
|
+
}
|
|
53
|
+
_this = _Component.call.apply(_Component, _concatInstanceProperty(_context = [this]).call(_context, args)) || this;
|
|
54
|
+
_this.delayClose = useDelayClose(_this.close, _this.get('duration'));
|
|
55
|
+
_this.config = useConfigContext();
|
|
56
|
+
return _this;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 显示通知
|
|
60
|
+
* @param props 通知配置对象
|
|
61
|
+
* @returns 返回通知的唯一 ID,可用于调用 close 方法关闭通知
|
|
62
|
+
*/
|
|
63
|
+
Notification.notice = function notice(props) {
|
|
64
|
+
var _props$type, _props$duration;
|
|
65
|
+
var notificationId = id++;
|
|
66
|
+
var key = notificationId;
|
|
67
|
+
var finalProps = _extends({}, props, {
|
|
68
|
+
key: key,
|
|
69
|
+
type: (_props$type = props.type) != null ? _props$type : '',
|
|
70
|
+
duration: (_props$duration = props.duration) != null ? _props$duration : 4500,
|
|
71
|
+
position: props.position || 'topRight'
|
|
72
|
+
});
|
|
73
|
+
var position = finalProps.position;
|
|
74
|
+
// 存储 notificationId 到 position 和 key 的映射
|
|
75
|
+
notificationIdMap.set(notificationId, {
|
|
76
|
+
position: position,
|
|
77
|
+
key: key
|
|
78
|
+
});
|
|
79
|
+
// 如果该位置的容器不存在,创建并挂载
|
|
80
|
+
if (!notificationsMap.has(position)) {
|
|
81
|
+
var container = document.createElement('div');
|
|
82
|
+
document.body.append(container);
|
|
83
|
+
// @ts-ignore 类型实例化过深
|
|
84
|
+
render(h(Notifications, {
|
|
85
|
+
ref: function ref(i) {
|
|
86
|
+
if (i) {
|
|
87
|
+
notificationsMap.set(position, i);
|
|
88
|
+
// 设置清理回调
|
|
89
|
+
i.__cleanup = function () {
|
|
90
|
+
notificationsMap.delete(position);
|
|
91
|
+
render(null, container);
|
|
92
|
+
container.remove();
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
classNamePrefix: Notification.classNamePrefix,
|
|
97
|
+
position: position
|
|
98
|
+
}), container);
|
|
99
|
+
}
|
|
100
|
+
// @ts-ignore 类型实例化过深
|
|
101
|
+
notificationsMap.get(position).notice(h(Notification, finalProps));
|
|
102
|
+
return notificationId;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* 关闭指定 ID 的通知
|
|
106
|
+
* @param id 通知的唯一 ID,由 notice 方法返回
|
|
107
|
+
*/;
|
|
108
|
+
Notification.close = function close(id) {
|
|
109
|
+
var notificationInfo = notificationIdMap.get(id);
|
|
110
|
+
if (!notificationInfo) {
|
|
111
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
112
|
+
console.warn("Notification with id " + id + " does not exist.");
|
|
113
|
+
}
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
var position = notificationInfo.position,
|
|
117
|
+
key = notificationInfo.key;
|
|
118
|
+
var notifications = notificationsMap.get(position);
|
|
119
|
+
if (notifications) {
|
|
120
|
+
notifications.delete(key);
|
|
121
|
+
}
|
|
122
|
+
// 从映射中移除
|
|
123
|
+
notificationIdMap.delete(id);
|
|
124
|
+
};
|
|
125
|
+
Notification.info = function info(props) {
|
|
126
|
+
return Notification.notice(_extends({}, props, {
|
|
127
|
+
type: 'info'
|
|
128
|
+
}));
|
|
129
|
+
};
|
|
130
|
+
Notification.error = function error(props) {
|
|
131
|
+
return Notification.notice(_extends({}, props, {
|
|
132
|
+
type: 'error'
|
|
133
|
+
}));
|
|
134
|
+
};
|
|
135
|
+
Notification.success = function success(props) {
|
|
136
|
+
return Notification.notice(_extends({}, props, {
|
|
137
|
+
type: 'success'
|
|
138
|
+
}));
|
|
139
|
+
};
|
|
140
|
+
Notification.warning = function warning(props) {
|
|
141
|
+
return Notification.notice(_extends({}, props, {
|
|
142
|
+
type: 'warning'
|
|
143
|
+
}));
|
|
144
|
+
};
|
|
145
|
+
var _proto = Notification.prototype;
|
|
146
|
+
_proto.onClick = function onClick(e) {
|
|
147
|
+
var onClick = this.get('onClick');
|
|
148
|
+
if (onClick) {
|
|
149
|
+
onClick(e);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
_proto.onCloseClick = function onCloseClick(e) {
|
|
153
|
+
e.stopPropagation(); // 阻止事件冒泡,避免触发外层的 onClick
|
|
154
|
+
this.close();
|
|
155
|
+
};
|
|
156
|
+
_proto.close = function close() {
|
|
157
|
+
var onClose = this.get('onClose');
|
|
158
|
+
if (onClose) {
|
|
159
|
+
onClose();
|
|
160
|
+
}
|
|
161
|
+
var position = this.get('position') || 'topRight';
|
|
162
|
+
var key = this.get('key');
|
|
163
|
+
// 从 notificationIdMap 中移除对应的映射
|
|
164
|
+
for (var _iterator = _createForOfIteratorHelperLoose(_entriesInstanceProperty(notificationIdMap).call(notificationIdMap)), _step; !(_step = _iterator()).done;) {
|
|
165
|
+
var _step$value = _step.value,
|
|
166
|
+
notificationId = _step$value[0],
|
|
167
|
+
info = _step$value[1];
|
|
168
|
+
if (info.position === position && info.key === key) {
|
|
169
|
+
notificationIdMap.delete(notificationId);
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
notificationsMap.get(position).delete(key);
|
|
174
|
+
};
|
|
175
|
+
return Notification;
|
|
176
|
+
}(Component);
|
|
177
|
+
Notification.template = template;
|
|
178
|
+
Notification.typeDefs = typeDefs;
|
|
179
|
+
Notification.defaults = defaults;
|
|
180
|
+
Notification.classNamePrefix = void 0;
|
|
181
|
+
__decorate([bind], Notification.prototype, "onClick", null);
|
|
182
|
+
__decorate([bind], Notification.prototype, "onCloseClick", null);
|
|
183
|
+
__decorate([bind], Notification.prototype, "close", null);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/extends";
|
|
2
|
+
import { createVNode as _$cv, className as _$cn, createElementVNode as _$ce, createUnknownComponentVNode as _$cc } from 'intact-vue-next';
|
|
3
|
+
import { Button } from '../button';
|
|
4
|
+
import { Icon } from '../icon';
|
|
5
|
+
import { getRestProps } from '../utils';
|
|
6
|
+
import { makeNotificationStyles } from './styles';
|
|
7
|
+
import { theme } from '../../styles/theme';
|
|
8
|
+
export default function ($props, $blocks, $__proto__) {
|
|
9
|
+
var _classNameObj, _$cn2;
|
|
10
|
+
$blocks || ($blocks = {});
|
|
11
|
+
$props || ($props = {});
|
|
12
|
+
var $this = this;
|
|
13
|
+
var _this$get = this.get(),
|
|
14
|
+
type = _this$get.type,
|
|
15
|
+
title = _this$get.title,
|
|
16
|
+
content = _this$get.content,
|
|
17
|
+
children = _this$get.children,
|
|
18
|
+
closable = _this$get.closable,
|
|
19
|
+
icon = _this$get.icon,
|
|
20
|
+
classNamePrefix = _this$get.classNamePrefix,
|
|
21
|
+
position = _this$get.position,
|
|
22
|
+
className = _this$get.className;
|
|
23
|
+
var k = this.config.k;
|
|
24
|
+
var classNameObj = (_classNameObj = {}, _classNameObj[k + "-notification"] = true, _classNameObj[className] = className, _classNameObj[k + "-" + type] = type && (type === 'info' || type === 'error' || type === 'success' || type === 'warning'), _classNameObj[k + "-position-" + (position || 'topRight')] = true, _classNameObj[makeNotificationStyles(k)] = true, _classNameObj);
|
|
25
|
+
var iconMap = {
|
|
26
|
+
info: k + "-icon-information-fill",
|
|
27
|
+
warning: k + "-icon-warning-fill",
|
|
28
|
+
success: k + "-icon-success-fill",
|
|
29
|
+
error: k + "-icon-error-fill"
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// type 优先级大于 icon,如果 type 存在且是四种类型之一,使用 type 对应的 icon
|
|
33
|
+
// 否则如果 icon 有值,使用自定义 icon
|
|
34
|
+
var hasIcon = type && iconMap[type] || icon;
|
|
35
|
+
var iconName = type && iconMap[type] ? iconMap[type] : typeof icon === 'string' ? icon : null;
|
|
36
|
+
var iconColor = type ? theme.color[type === 'error' ? 'danger' : type] : 'default';
|
|
37
|
+
return _$cv('div', _extends({}, getRestProps(this), {
|
|
38
|
+
'className': _$cn(classNameObj),
|
|
39
|
+
'ev-mouseenter': this.delayClose.onMouseEnter,
|
|
40
|
+
'ev-mouseleave': this.delayClose.onMouseLeave,
|
|
41
|
+
'ev-click': this.onClick
|
|
42
|
+
}), _$ce(2, 'div', [_$ce(2, 'div', [hasIcon && iconName ? _$ce(2, 'div', _$cc(Icon, {
|
|
43
|
+
'className': _$cn(iconName),
|
|
44
|
+
'color': iconColor
|
|
45
|
+
}), 2, _$cn(k + "-notification-icon")) : hasIcon && !iconName ? _$ce(2, 'div', icon, 0, _$cn(k + "-notification-icon")) : undefined, _$ce(2, 'div', [title ? _$ce(2, 'div', title, 0, _$cn(k + "-notification-title")) : undefined, content || children ? _$ce(2, 'div', content || children, 0, _$cn(k + "-notification-body")) : undefined], 0, _$cn(k + "-notification-content"))], 0, _$cn((_$cn2 = {}, _$cn2[k + "-notification-wrapper"] = true, _$cn2[k + "-with-icon"] = hasIcon, _$cn2))), closable ? _$cc(Button, {
|
|
46
|
+
'type': 'none',
|
|
47
|
+
'icon': true,
|
|
48
|
+
'className': _$cn(k + "-notification-close"),
|
|
49
|
+
'ev-click': this.onCloseClick,
|
|
50
|
+
'children': _$cc(Icon, {
|
|
51
|
+
'className': _$cn(k + "-icon-close"),
|
|
52
|
+
'hoverable': true
|
|
53
|
+
})
|
|
54
|
+
}) : undefined], 0, _$cn(k + "-notification-container")));
|
|
55
|
+
}
|
|
56
|
+
;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Component, VNodeComponentClass, TypeDefs } from 'intact-vue-next';
|
|
2
|
+
import type { Notification } from './notification';
|
|
3
|
+
export interface NotificationsProps {
|
|
4
|
+
classNamePrefix?: string;
|
|
5
|
+
position?: 'topRight' | 'topLeft' | 'bottomRight' | 'bottomLeft' | 'top' | 'bottom';
|
|
6
|
+
}
|
|
7
|
+
export declare class Notifications extends Component {
|
|
8
|
+
static template: string | import('intact-vue-next').Template<any>;
|
|
9
|
+
static typeDefs: Required<TypeDefs<NotificationsProps>>;
|
|
10
|
+
private notifications;
|
|
11
|
+
private config;
|
|
12
|
+
__cleanup?: () => void;
|
|
13
|
+
notice(notification: VNodeComponentClass<Notification>): void;
|
|
14
|
+
delete(key: number | string): void;
|
|
15
|
+
onAfterLeave(): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime-corejs3/helpers/inheritsLoose";
|
|
2
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js/instance/concat";
|
|
3
|
+
import _findIndexInstanceProperty from "@babel/runtime-corejs3/core-js/instance/find-index";
|
|
4
|
+
import _spliceInstanceProperty from "@babel/runtime-corejs3/core-js/instance/splice";
|
|
5
|
+
import { Component } from 'intact-vue-next';
|
|
6
|
+
import template from './notifications.vdt';
|
|
7
|
+
import { useConfigContext } from '../config';
|
|
8
|
+
var typeDefs = {
|
|
9
|
+
classNamePrefix: String,
|
|
10
|
+
position: ['topRight', 'topLeft', 'bottomRight', 'bottomLeft', 'top', 'bottom']
|
|
11
|
+
};
|
|
12
|
+
export var Notifications = /*#__PURE__*/function (_Component) {
|
|
13
|
+
_inheritsLoose(Notifications, _Component);
|
|
14
|
+
function Notifications() {
|
|
15
|
+
var _context;
|
|
16
|
+
var _this;
|
|
17
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
18
|
+
args[_key] = arguments[_key];
|
|
19
|
+
}
|
|
20
|
+
_this = _Component.call.apply(_Component, _concatInstanceProperty(_context = [this]).call(_context, args)) || this;
|
|
21
|
+
_this.notifications = [];
|
|
22
|
+
_this.config = useConfigContext();
|
|
23
|
+
_this.__cleanup = void 0;
|
|
24
|
+
return _this;
|
|
25
|
+
}
|
|
26
|
+
var _proto = Notifications.prototype;
|
|
27
|
+
_proto.notice = function notice(notification) {
|
|
28
|
+
this.notifications.push(notification);
|
|
29
|
+
this.forceUpdate();
|
|
30
|
+
};
|
|
31
|
+
_proto.delete = function _delete(key) {
|
|
32
|
+
var notifications = this.notifications;
|
|
33
|
+
var index = _findIndexInstanceProperty(notifications).call(notifications, function (notification) {
|
|
34
|
+
return notification.key === key;
|
|
35
|
+
});
|
|
36
|
+
if (process.env.NODE_ENV !== 'production' && !~index) {
|
|
37
|
+
throw new Error('You are removing a notification that does not exist.');
|
|
38
|
+
}
|
|
39
|
+
_spliceInstanceProperty(notifications).call(notifications, index, 1);
|
|
40
|
+
this.forceUpdate();
|
|
41
|
+
};
|
|
42
|
+
_proto.onAfterLeave = function onAfterLeave() {
|
|
43
|
+
// 当离开动画完成后,如果该位置 通知列表为空,则清理容器
|
|
44
|
+
if (this.notifications.length === 0 && this.__cleanup) {
|
|
45
|
+
this.__cleanup();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
return Notifications;
|
|
49
|
+
}(Component);
|
|
50
|
+
Notifications.template = template;
|
|
51
|
+
Notifications.typeDefs = typeDefs;
|