bd2797add581de69c3ba48eeef0d39880f33f93d3dd98199e5f6992ac88e4bfdf7c5ab5821ec86024fcfdee3f28df840e5e5927424152f5bcc9139f5bbc322 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var notification = require('./notification2.js');
  5. var notification$1 = require('./notification.js');
  6. var core = require('@vueuse/core');
  7. var shared = require('@vue/shared');
  8. var types = require('../../../utils/types.js');
  9. const notifications = {
  10. "top-left": [],
  11. "top-right": [],
  12. "bottom-left": [],
  13. "bottom-right": []
  14. };
  15. const GAP_SIZE = 16;
  16. let seed = 1;
  17. const notify = function(options = {}, context) {
  18. if (!core.isClient)
  19. return { close: () => void 0 };
  20. if (shared.isString(options) || vue.isVNode(options)) {
  21. options = { message: options };
  22. }
  23. const position = options.position || "top-right";
  24. let verticalOffset = options.offset || 0;
  25. notifications[position].forEach(({ vm: vm2 }) => {
  26. var _a;
  27. verticalOffset += (((_a = vm2.el) == null ? void 0 : _a.offsetHeight) || 0) + GAP_SIZE;
  28. });
  29. verticalOffset += GAP_SIZE;
  30. const id = `notification_${seed++}`;
  31. const userOnClose = options.onClose;
  32. const props = {
  33. ...options,
  34. offset: verticalOffset,
  35. id,
  36. onClose: () => {
  37. close(id, position, userOnClose);
  38. }
  39. };
  40. let appendTo = document.body;
  41. if (types.isElement(options.appendTo)) {
  42. appendTo = options.appendTo;
  43. } else if (shared.isString(options.appendTo)) {
  44. appendTo = document.querySelector(options.appendTo);
  45. }
  46. if (!types.isElement(appendTo)) {
  47. appendTo = document.body;
  48. }
  49. const container = document.createElement("div");
  50. const vm = vue.createVNode(notification["default"], props, shared.isFunction(props.message) ? props.message : vue.isVNode(props.message) ? () => props.message : null);
  51. vm.appContext = types.isUndefined(context) ? notify._context : context;
  52. vm.props.onDestroy = () => {
  53. vue.render(null, container);
  54. };
  55. vue.render(vm, container);
  56. notifications[position].push({ vm });
  57. appendTo.appendChild(container.firstElementChild);
  58. return {
  59. close: () => {
  60. vm.component.exposed.visible.value = false;
  61. }
  62. };
  63. };
  64. notification$1.notificationTypes.forEach((type) => {
  65. notify[type] = (options = {}, appContext) => {
  66. if (shared.isString(options) || vue.isVNode(options)) {
  67. options = {
  68. message: options
  69. };
  70. }
  71. return notify({ ...options, type }, appContext);
  72. };
  73. });
  74. function close(id, position, userOnClose) {
  75. const orientedNotifications = notifications[position];
  76. const idx = orientedNotifications.findIndex(({ vm: vm2 }) => {
  77. var _a;
  78. return ((_a = vm2.component) == null ? void 0 : _a.props.id) === id;
  79. });
  80. if (idx === -1)
  81. return;
  82. const { vm } = orientedNotifications[idx];
  83. if (!vm)
  84. return;
  85. userOnClose == null ? void 0 : userOnClose(vm);
  86. const removedHeight = vm.el.offsetHeight;
  87. const verticalPos = position.split("-")[0];
  88. orientedNotifications.splice(idx, 1);
  89. const len = orientedNotifications.length;
  90. if (len < 1)
  91. return;
  92. for (let i = idx; i < len; i++) {
  93. const { el, component } = orientedNotifications[i].vm;
  94. const pos = Number.parseInt(el.style[verticalPos], 10) - removedHeight - GAP_SIZE;
  95. component.props.offset = pos;
  96. }
  97. }
  98. function closeAll() {
  99. for (const orientedNotifications of Object.values(notifications)) {
  100. orientedNotifications.forEach(({ vm }) => {
  101. vm.component.exposed.visible.value = false;
  102. });
  103. }
  104. }
  105. function updateOffsets(position = "top-right") {
  106. var _a, _b, _c, _d;
  107. let verticalOffset = ((_c = (_b = (_a = notifications[position][0]) == null ? void 0 : _a.vm.component) == null ? void 0 : _b.props) == null ? void 0 : _c.offset) || 0;
  108. for (const { vm } of notifications[position]) {
  109. vm.component.props.offset = verticalOffset;
  110. verticalOffset += (((_d = vm.el) == null ? void 0 : _d.offsetHeight) || 0) + GAP_SIZE;
  111. }
  112. }
  113. notify.closeAll = closeAll;
  114. notify.updateOffsets = updateOffsets;
  115. notify._context = null;
  116. exports.close = close;
  117. exports.closeAll = closeAll;
  118. exports["default"] = notify;
  119. exports.updateOffsets = updateOffsets;
  120. //# sourceMappingURL=notify.js.map