@94ai/nf-notification 3.1.13

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.
@@ -0,0 +1,537 @@
1
+ import { defineComponent, Vue2 } from "vue-demi";
2
+ import { normalizeComponent } from "@94ai/vue2-runtime-helpers";
3
+ import Vue from "vue";
4
+ const typeMap = {
5
+ success: "success",
6
+ info: "info",
7
+ warning: "warning",
8
+ error: "error"
9
+ };
10
+ const _sfc_main = defineComponent({
11
+ name: "nf-notification",
12
+ data() {
13
+ return {
14
+ visible: false,
15
+ title: "",
16
+ message: "",
17
+ duration: 4500,
18
+ type: "",
19
+ showClose: true,
20
+ customClass: "",
21
+ iconClass: "",
22
+ onClose: null,
23
+ onClick: null,
24
+ onCancel: null,
25
+ onConfirm: null,
26
+ closed: false,
27
+ verticalOffset: 0,
28
+ timer: null,
29
+ dangerouslyUseHTMLString: false,
30
+ position: "top-right",
31
+ cancelButtonText: "",
32
+ confirmButtonText: ""
33
+ };
34
+ },
35
+ computed: {
36
+ typeClass() {
37
+ return this.type && typeMap[this.type] ? `el-icon-${typeMap[this.type]}` : "";
38
+ },
39
+ horizontalClass() {
40
+ return this.position.indexOf("right") > -1 ? "right" : "left";
41
+ },
42
+ verticalProperty() {
43
+ return /^top-/.test(this.position) ? "top" : "bottom";
44
+ },
45
+ positionStyle() {
46
+ return {
47
+ [this.verticalProperty]: `${this.verticalOffset}px`
48
+ };
49
+ }
50
+ },
51
+ watch: {
52
+ closed(newVal) {
53
+ if (newVal) {
54
+ this.visible = false;
55
+ this.$el.addEventListener("transitionend", this.destroyElement);
56
+ }
57
+ }
58
+ },
59
+ methods: {
60
+ destroyElement() {
61
+ this.$el.removeEventListener("transitionend", this.destroyElement);
62
+ this.$destroy(true);
63
+ this.$el.parentNode.removeChild(this.$el);
64
+ },
65
+ click() {
66
+ if (typeof this.onClick === "function") {
67
+ this.onClick();
68
+ }
69
+ },
70
+ handleCancel() {
71
+ if (typeof this.onCancel === "function") {
72
+ this.onCancel();
73
+ }
74
+ },
75
+ handleConfirm() {
76
+ if (typeof this.onConfirm === "function") {
77
+ this.onConfirm();
78
+ }
79
+ },
80
+ close() {
81
+ this.closed = true;
82
+ if (typeof this.onClose === "function") {
83
+ this.onClose();
84
+ }
85
+ },
86
+ clearTimer() {
87
+ clearTimeout(this.timer);
88
+ },
89
+ startTimer() {
90
+ if (this.duration > 0) {
91
+ this.timer = setTimeout(() => {
92
+ if (!this.closed) {
93
+ this.close();
94
+ }
95
+ }, this.duration);
96
+ }
97
+ },
98
+ keydown(e) {
99
+ if (e.keyCode === 46 || e.keyCode === 8) {
100
+ this.clearTimer();
101
+ } else if (e.keyCode === 27) {
102
+ if (!this.closed) {
103
+ this.close();
104
+ }
105
+ } else {
106
+ this.startTimer();
107
+ }
108
+ }
109
+ },
110
+ mounted() {
111
+ if (this.duration > 0) {
112
+ this.timer = setTimeout(() => {
113
+ if (!this.closed) {
114
+ this.close();
115
+ }
116
+ }, this.duration);
117
+ }
118
+ document.addEventListener("keydown", this.keydown);
119
+ },
120
+ beforeDestroy() {
121
+ document.removeEventListener("keydown", this.keydown);
122
+ }
123
+ });
124
+ var _sfc_render = function render() {
125
+ var _vm = this, _c = _vm._self._c;
126
+ _vm._self._setupProxy;
127
+ return _c("transition", {
128
+ attrs: {
129
+ "name": "el-notification-fade"
130
+ }
131
+ }, [_c("div", {
132
+ directives: [{
133
+ name: "show",
134
+ rawName: "v-show",
135
+ value: _vm.visible,
136
+ expression: "visible"
137
+ }],
138
+ class: ["nf-notification", _vm.customClass, _vm.horizontalClass],
139
+ style: _vm.positionStyle,
140
+ attrs: {
141
+ "role": "alert"
142
+ },
143
+ on: {
144
+ "mouseenter": function($event) {
145
+ return _vm.clearTimer();
146
+ },
147
+ "mouseleave": function($event) {
148
+ return _vm.startTimer();
149
+ },
150
+ "click": _vm.click
151
+ }
152
+ }, [_vm.type || _vm.iconClass ? _c("i", {
153
+ staticClass: "nf-notification__icon",
154
+ class: [_vm.typeClass, _vm.iconClass]
155
+ }) : _vm._e(), _c("div", {
156
+ staticClass: "nf-notification__group",
157
+ class: {
158
+ "is-with-icon": _vm.typeClass || _vm.iconClass
159
+ }
160
+ }, [_c("h2", {
161
+ staticClass: "nf-notification__title",
162
+ domProps: {
163
+ "textContent": _vm._s(_vm.title)
164
+ }
165
+ }), _c("div", {
166
+ directives: [{
167
+ name: "show",
168
+ rawName: "v-show",
169
+ value: _vm.message,
170
+ expression: "message"
171
+ }],
172
+ staticClass: "nf-notification__content"
173
+ }, [_vm._t("default", function() {
174
+ return [!_vm.dangerouslyUseHTMLString ? _c("p", [_vm._v(_vm._s(_vm.message))]) : _c("p", {
175
+ domProps: {
176
+ "innerHTML": _vm._s(_vm.message)
177
+ }
178
+ })];
179
+ })], 2), _vm.cancelButtonText || _vm.confirmButtonText ? _c("div", {
180
+ staticClass: "nf-notification__btns"
181
+ }, [_vm.cancelButtonText ? _c("nf-button", {
182
+ on: {
183
+ "click": function($event) {
184
+ $event.stopPropagation();
185
+ return _vm.handleCancel.apply(null, arguments);
186
+ }
187
+ }
188
+ }, [_vm._v(_vm._s(_vm.cancelButtonText))]) : _vm._e(), _vm.confirmButtonText ? _c("nf-button", {
189
+ attrs: {
190
+ "type": "primary"
191
+ },
192
+ on: {
193
+ "click": function($event) {
194
+ $event.stopPropagation();
195
+ return _vm.handleConfirm.apply(null, arguments);
196
+ }
197
+ }
198
+ }, [_vm._v(_vm._s(_vm.confirmButtonText))]) : _vm._e()], 1) : _vm._e(), _vm.showClose ? _c("div", {
199
+ staticClass: "nf-notification__closeBtn el-icon-close",
200
+ on: {
201
+ "click": function($event) {
202
+ $event.stopPropagation();
203
+ return _vm.close.apply(null, arguments);
204
+ }
205
+ }
206
+ }) : _vm._e()])])]);
207
+ };
208
+ var _sfc_staticRenderFns = [];
209
+ var __component__ = /* @__PURE__ */ normalizeComponent(_sfc_main, _sfc_render, _sfc_staticRenderFns, false, null, null, null, null);
210
+ const NfNotification = __component__.exports;
211
+ function merge(target) {
212
+ for (let i = 1, j = arguments.length; i < j; i++) {
213
+ let source = arguments[i] || {};
214
+ for (let prop in source) {
215
+ if (source.hasOwnProperty(prop)) {
216
+ let value = source[prop];
217
+ if (value !== void 0) {
218
+ target[prop] = value;
219
+ }
220
+ }
221
+ }
222
+ }
223
+ return target;
224
+ }
225
+ Vue.prototype.$isServer;
226
+ const trim = function(string) {
227
+ return (string || "").replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g, "");
228
+ };
229
+ function hasClass(el, cls) {
230
+ if (!el || !cls)
231
+ return false;
232
+ if (cls.indexOf(" ") !== -1)
233
+ throw new Error("className should not contain space.");
234
+ if (el.classList) {
235
+ return el.classList.contains(cls);
236
+ } else {
237
+ return (" " + el.className + " ").indexOf(" " + cls + " ") > -1;
238
+ }
239
+ }
240
+ function addClass(el, cls) {
241
+ if (!el)
242
+ return;
243
+ var curClass = el.className;
244
+ var classes = (cls || "").split(" ");
245
+ for (var i = 0, j = classes.length; i < j; i++) {
246
+ var clsName = classes[i];
247
+ if (!clsName)
248
+ continue;
249
+ if (el.classList) {
250
+ el.classList.add(clsName);
251
+ } else if (!hasClass(el, clsName)) {
252
+ curClass += " " + clsName;
253
+ }
254
+ }
255
+ if (!el.classList) {
256
+ el.className = curClass;
257
+ }
258
+ }
259
+ function removeClass(el, cls) {
260
+ if (!el || !cls)
261
+ return;
262
+ var classes = cls.split(" ");
263
+ var curClass = " " + el.className + " ";
264
+ for (var i = 0, j = classes.length; i < j; i++) {
265
+ var clsName = classes[i];
266
+ if (!clsName)
267
+ continue;
268
+ if (el.classList) {
269
+ el.classList.remove(clsName);
270
+ } else if (hasClass(el, clsName)) {
271
+ curClass = curClass.replace(" " + clsName + " ", " ");
272
+ }
273
+ }
274
+ if (!el.classList) {
275
+ el.className = trim(curClass);
276
+ }
277
+ }
278
+ let hasModal = false;
279
+ let hasInitZIndex = false;
280
+ let zIndex;
281
+ const getModal = function() {
282
+ if (Vue.prototype.$isServer)
283
+ return;
284
+ let modalDom = PopupManager.modalDom;
285
+ if (modalDom) {
286
+ hasModal = true;
287
+ } else {
288
+ hasModal = false;
289
+ modalDom = document.createElement("div");
290
+ PopupManager.modalDom = modalDom;
291
+ modalDom.addEventListener("touchmove", function(event) {
292
+ event.preventDefault();
293
+ event.stopPropagation();
294
+ });
295
+ modalDom.addEventListener("click", function() {
296
+ PopupManager.doOnModalClick && PopupManager.doOnModalClick();
297
+ });
298
+ }
299
+ return modalDom;
300
+ };
301
+ const instances$1 = {};
302
+ const PopupManager = {
303
+ modalFade: true,
304
+ getInstance: function(id) {
305
+ return instances$1[id];
306
+ },
307
+ register: function(id, instance2) {
308
+ if (id && instance2) {
309
+ instances$1[id] = instance2;
310
+ }
311
+ },
312
+ deregister: function(id) {
313
+ if (id) {
314
+ instances$1[id] = null;
315
+ delete instances$1[id];
316
+ }
317
+ },
318
+ nextZIndex: function() {
319
+ return PopupManager.zIndex++;
320
+ },
321
+ modalStack: [],
322
+ doOnModalClick: function() {
323
+ const topItem = PopupManager.modalStack[PopupManager.modalStack.length - 1];
324
+ if (!topItem)
325
+ return;
326
+ const instance2 = PopupManager.getInstance(topItem.id);
327
+ if (instance2 && instance2.closeOnClickModal) {
328
+ instance2.close();
329
+ }
330
+ },
331
+ openModal: function(id, zIndex2, dom, modalClass, modalFade) {
332
+ if (Vue.prototype.$isServer)
333
+ return;
334
+ if (!id || zIndex2 === void 0)
335
+ return;
336
+ this.modalFade = modalFade;
337
+ const modalStack = this.modalStack;
338
+ for (let i = 0, j = modalStack.length; i < j; i++) {
339
+ const item = modalStack[i];
340
+ if (item.id === id) {
341
+ return;
342
+ }
343
+ }
344
+ const modalDom = getModal();
345
+ addClass(modalDom, "v-modal");
346
+ if (this.modalFade && !hasModal) {
347
+ addClass(modalDom, "v-modal-enter");
348
+ }
349
+ if (modalClass) {
350
+ let classArr = modalClass.trim().split(/\s+/);
351
+ classArr.forEach((item) => addClass(modalDom, item));
352
+ }
353
+ setTimeout(() => {
354
+ removeClass(modalDom, "v-modal-enter");
355
+ }, 200);
356
+ if (dom && dom.parentNode && dom.parentNode.nodeType !== 11) {
357
+ dom.parentNode.appendChild(modalDom);
358
+ } else {
359
+ document.body.appendChild(modalDom);
360
+ }
361
+ if (zIndex2) {
362
+ modalDom.style.zIndex = zIndex2;
363
+ }
364
+ modalDom.tabIndex = 0;
365
+ modalDom.style.display = "";
366
+ this.modalStack.push({
367
+ id,
368
+ zIndex: zIndex2,
369
+ modalClass
370
+ });
371
+ },
372
+ closeModal: function(id) {
373
+ const modalStack = this.modalStack;
374
+ const modalDom = getModal();
375
+ if (modalStack.length > 0) {
376
+ const topItem = modalStack[modalStack.length - 1];
377
+ if (topItem.id === id) {
378
+ if (topItem.modalClass) {
379
+ let classArr = topItem.modalClass.trim().split(/\s+/);
380
+ classArr.forEach((item) => removeClass(modalDom, item));
381
+ }
382
+ modalStack.pop();
383
+ if (modalStack.length > 0) {
384
+ modalDom.style.zIndex = modalStack[modalStack.length - 1].zIndex;
385
+ }
386
+ } else {
387
+ for (let i = modalStack.length - 1; i >= 0; i--) {
388
+ if (modalStack[i].id === id) {
389
+ modalStack.splice(i, 1);
390
+ break;
391
+ }
392
+ }
393
+ }
394
+ }
395
+ if (modalStack.length === 0) {
396
+ if (this.modalFade) {
397
+ addClass(modalDom, "v-modal-leave");
398
+ }
399
+ setTimeout(() => {
400
+ if (modalStack.length === 0) {
401
+ if (modalDom.parentNode)
402
+ modalDom.parentNode.removeChild(modalDom);
403
+ modalDom.style.display = "none";
404
+ PopupManager.modalDom = void 0;
405
+ }
406
+ removeClass(modalDom, "v-modal-leave");
407
+ }, 200);
408
+ }
409
+ }
410
+ };
411
+ Object.defineProperty(PopupManager, "zIndex", {
412
+ configurable: true,
413
+ get() {
414
+ if (!hasInitZIndex) {
415
+ zIndex = zIndex || (Vue.prototype.$ELEMENT || {}).zIndex || 2e3;
416
+ hasInitZIndex = true;
417
+ }
418
+ return zIndex;
419
+ },
420
+ set(value) {
421
+ zIndex = value;
422
+ }
423
+ });
424
+ const getTopPopup = function() {
425
+ if (Vue.prototype.$isServer)
426
+ return;
427
+ if (PopupManager.modalStack.length > 0) {
428
+ const topPopup = PopupManager.modalStack[PopupManager.modalStack.length - 1];
429
+ if (!topPopup)
430
+ return;
431
+ const instance2 = PopupManager.getInstance(topPopup.id);
432
+ return instance2;
433
+ }
434
+ };
435
+ if (!Vue.prototype.$isServer) {
436
+ window.addEventListener("keydown", function(event) {
437
+ if (event.keyCode === 27) {
438
+ const topPopup = getTopPopup();
439
+ if (topPopup && topPopup.closeOnPressEscape) {
440
+ topPopup.handleClose ? topPopup.handleClose() : topPopup.handleAction ? topPopup.handleAction("cancel") : topPopup.close();
441
+ }
442
+ }
443
+ });
444
+ }
445
+ const hasOwnProperty = Object.prototype.hasOwnProperty;
446
+ function hasOwn(obj, key) {
447
+ return hasOwnProperty.call(obj, key);
448
+ }
449
+ function isVNode(node) {
450
+ return node !== null && typeof node === "object" && hasOwn(node, "componentOptions");
451
+ }
452
+ const NotificationConstructor = Vue2.extend(NfNotification);
453
+ let instance;
454
+ let instances = [];
455
+ let seed = 1;
456
+ const Notification = function(options) {
457
+ var _a;
458
+ if ((_a = Vue2.prototype) == null ? void 0 : _a.$isServer)
459
+ return;
460
+ options = merge({}, options);
461
+ const userOnClose = options.onClose;
462
+ const id = "notification_" + seed++;
463
+ const position = options.position || "top-right";
464
+ options.onClose = function() {
465
+ Notification.close(id, userOnClose);
466
+ };
467
+ instance = new NotificationConstructor({
468
+ data: options
469
+ });
470
+ if (isVNode(options.message)) {
471
+ instance.$slots.default = [options.message];
472
+ options.message = "REPLACED_BY_VNODE";
473
+ }
474
+ instance.id = id;
475
+ instance.$mount();
476
+ document.body.appendChild(instance.$el);
477
+ instance.visible = true;
478
+ instance.dom = instance.$el;
479
+ instance.dom.style.zIndex = PopupManager.nextZIndex() + 1e3;
480
+ let verticalOffset = options.offset || 0;
481
+ instances.filter((item) => item.position === position).forEach((item) => {
482
+ verticalOffset += item.$el.offsetHeight + 16;
483
+ });
484
+ verticalOffset += 16;
485
+ instance.verticalOffset = verticalOffset;
486
+ instances.push(instance);
487
+ return instance;
488
+ };
489
+ ["success", "warning", "info", "error"].forEach((type) => {
490
+ Notification[type] = (options) => {
491
+ if (typeof options === "string" || isVNode(options)) {
492
+ options = {
493
+ message: options
494
+ };
495
+ }
496
+ options.type = type;
497
+ return Notification(options);
498
+ };
499
+ });
500
+ Notification.close = function(id, userOnClose) {
501
+ let index = -1;
502
+ const len = instances.length;
503
+ const instance2 = instances.filter((instance3, i) => {
504
+ if (instance3.id === id) {
505
+ index = i;
506
+ return true;
507
+ }
508
+ return false;
509
+ })[0];
510
+ if (!instance2)
511
+ return;
512
+ if (typeof userOnClose === "function") {
513
+ userOnClose(instance2);
514
+ }
515
+ instances.splice(index, 1);
516
+ if (len <= 1)
517
+ return;
518
+ const position = instance2.position;
519
+ const removedHeight = instance2.dom.offsetHeight;
520
+ for (let i = index; i < len - 1; i++) {
521
+ if (instances[i].position === position) {
522
+ instances[i].dom.style[instance2.verticalProperty] = parseInt(instances[i].dom.style[instance2.verticalProperty], 10) - removedHeight - 16 + "px";
523
+ }
524
+ }
525
+ };
526
+ Notification.closeAll = function() {
527
+ for (let i = instances.length - 1; i >= 0; i--) {
528
+ instances[i].close();
529
+ }
530
+ };
531
+ NfNotification.install = (app) => {
532
+ app.component("nf-notification", NfNotification);
533
+ app.prototype.$openNotify = Notification;
534
+ };
535
+ export {
536
+ NfNotification as default
537
+ };
@@ -0,0 +1,29 @@
1
+ declare const _default: import("vue-demi").DefineComponent<{}, any, {
2
+ visible: boolean;
3
+ title: string;
4
+ message: string;
5
+ duration: number;
6
+ type: string;
7
+ showClose: boolean;
8
+ customClass: string;
9
+ iconClass: string;
10
+ onClose: null;
11
+ onClick: null;
12
+ onCancel: null;
13
+ onConfirm: null;
14
+ closed: boolean;
15
+ verticalOffset: number;
16
+ timer: null;
17
+ dangerouslyUseHTMLString: boolean;
18
+ position: string;
19
+ cancelButtonText: string;
20
+ confirmButtonText: string;
21
+ }, {
22
+ typeClass(): string;
23
+ horizontalClass(): "right" | "left";
24
+ verticalProperty(): "top" | "bottom";
25
+ positionStyle(): {
26
+ [x: string]: string;
27
+ };
28
+ }, {}, import("vue/types/v3-component-options").ComponentOptionsMixin, import("vue/types/v3-component-options").ComponentOptionsMixin, {}, string, Readonly<import("vue-demi").ExtractPropTypes<{}>>, {}>;
29
+ export default _default;
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+ import '@94ai/nf-theme-chalk/lib/css/nf-notification.css'
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+ import '@94ai/nf-theme-chalk/lib/nf-notification.scss'
@@ -0,0 +1,10 @@
1
+ import NfNotification from './nf-notification.vue'
2
+ import { Vue2, PluginObject } from 'vue-demi'
3
+ import Main from './main'
4
+
5
+ NfNotification.install = (app: typeof Vue2) => {
6
+ app!.component('nf-notification', NfNotification)
7
+ app!.prototype.$openNotify = Main
8
+ }
9
+
10
+ export default NfNotification as typeof NfNotification & PluginObject<undefined>
@@ -0,0 +1,94 @@
1
+ import {Vue2} from 'vue-demi';
2
+ import Main from './nf-notification.vue';
3
+ import merge from 'element-ui/src/utils/merge';
4
+ import { PopupManager } from 'element-ui/src/utils/popup';
5
+ import { isVNode } from 'element-ui/src/utils/vdom';
6
+ const NotificationConstructor = Vue2!.extend(Main);
7
+
8
+ let instance: any;
9
+ let instances: any[] = [];
10
+ let seed = 1;
11
+
12
+ const Notification = function(options) {
13
+ if (Vue2!.prototype?.$isServer) return;
14
+ options = merge({}, options);
15
+ const userOnClose = options.onClose;
16
+ const id = 'notification_' + seed++;
17
+ const position = options.position || 'top-right';
18
+
19
+ options.onClose = function() {
20
+ Notification.close(id, userOnClose);
21
+ };
22
+
23
+ instance = new NotificationConstructor({
24
+ data: options
25
+ });
26
+
27
+ if (isVNode(options.message)) {
28
+ instance.$slots.default = [options.message];
29
+ options.message = 'REPLACED_BY_VNODE';
30
+ }
31
+ instance.id = id;
32
+ instance.$mount();
33
+ document.body.appendChild(instance.$el);
34
+ instance.visible = true;
35
+ instance.dom = instance.$el;
36
+ instance.dom.style.zIndex = PopupManager.nextZIndex() + 1000;
37
+
38
+ let verticalOffset = options.offset || 0;
39
+ instances.filter(item => item.position === position).forEach(item => {
40
+ verticalOffset += item.$el.offsetHeight + 16;
41
+ });
42
+ verticalOffset += 16;
43
+ instance.verticalOffset = verticalOffset;
44
+ instances.push(instance);
45
+ return instance;
46
+ };
47
+
48
+ ['success', 'warning', 'info', 'error'].forEach(type => {
49
+ Notification[type] = options => {
50
+ if (typeof options === 'string' || isVNode(options)) {
51
+ options = {
52
+ message: options
53
+ };
54
+ }
55
+ options.type = type;
56
+ return Notification(options);
57
+ };
58
+ });
59
+
60
+ Notification.close = function(id, userOnClose) {
61
+ let index = -1;
62
+ const len = instances.length;
63
+ const instance = instances.filter((instance, i) => {
64
+ if (instance.id === id) {
65
+ index = i;
66
+ return true;
67
+ }
68
+ return false;
69
+ })[0];
70
+ if (!instance) return;
71
+
72
+ if (typeof userOnClose === 'function') {
73
+ userOnClose(instance);
74
+ }
75
+ instances.splice(index, 1);
76
+
77
+ if (len <= 1) return;
78
+ const position = instance.position;
79
+ const removedHeight = instance.dom.offsetHeight;
80
+ for (let i = index; i < len - 1 ; i++) {
81
+ if (instances[i].position === position) {
82
+ instances[i].dom.style[instance.verticalProperty] =
83
+ parseInt(instances[i].dom.style[instance.verticalProperty], 10) - removedHeight - 16 + 'px';
84
+ }
85
+ }
86
+ };
87
+
88
+ Notification.closeAll = function() {
89
+ for (let i = instances.length - 1; i >= 0; i--) {
90
+ instances[i].close();
91
+ }
92
+ };
93
+
94
+ export default Notification;