funda-ui 4.7.103 → 4.7.105

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/Chatbox/index.js +6 -1
  2. package/Checkbox/index.js +10 -1
  3. package/Date/index.js +12 -2
  4. package/Input/index.js +6 -1
  5. package/LiveSearch/index.js +5 -0
  6. package/MultipleCheckboxes/index.js +27 -1
  7. package/NumberInput/index.js +6 -1
  8. package/Radio/index.js +22 -1
  9. package/RangeSlider/index.js +6 -1
  10. package/Stepper/index.css +7 -8
  11. package/Stepper/index.d.ts +1 -1
  12. package/Stepper/index.js +7 -1
  13. package/TagInput/index.js +10 -1
  14. package/Textarea/index.js +6 -1
  15. package/Toast/index.css +23 -75
  16. package/Toast/index.d.ts +3 -34
  17. package/Toast/index.js +652 -175
  18. package/lib/cjs/Chatbox/index.js +6 -1
  19. package/lib/cjs/Checkbox/index.js +10 -1
  20. package/lib/cjs/Date/index.js +12 -2
  21. package/lib/cjs/Input/index.js +6 -1
  22. package/lib/cjs/LiveSearch/index.js +5 -0
  23. package/lib/cjs/MultipleCheckboxes/index.js +27 -1
  24. package/lib/cjs/NumberInput/index.js +6 -1
  25. package/lib/cjs/Radio/index.js +22 -1
  26. package/lib/cjs/RangeSlider/index.js +6 -1
  27. package/lib/cjs/Stepper/index.d.ts +1 -1
  28. package/lib/cjs/Stepper/index.js +7 -1
  29. package/lib/cjs/TagInput/index.js +10 -1
  30. package/lib/cjs/Textarea/index.js +6 -1
  31. package/lib/cjs/Toast/index.d.ts +3 -34
  32. package/lib/cjs/Toast/index.js +652 -175
  33. package/lib/css/Stepper/index.css +7 -8
  34. package/lib/css/Toast/index.css +23 -75
  35. package/lib/esm/Checkbox/index.tsx +12 -1
  36. package/lib/esm/Date/index.tsx +8 -1
  37. package/lib/esm/Input/index.tsx +8 -1
  38. package/lib/esm/LiveSearch/index.tsx +7 -0
  39. package/lib/esm/MultipleCheckboxes/index.tsx +19 -1
  40. package/lib/esm/NumberInput/index.tsx +8 -1
  41. package/lib/esm/Radio/index.tsx +17 -1
  42. package/lib/esm/Stepper/index.scss +7 -8
  43. package/lib/esm/Stepper/index.tsx +2 -2
  44. package/lib/esm/TagInput/index.tsx +8 -1
  45. package/lib/esm/Textarea/index.tsx +8 -1
  46. package/lib/esm/Toast/Item.tsx +52 -11
  47. package/lib/esm/Toast/Toast.tsx +391 -0
  48. package/lib/esm/Toast/ToastContext.tsx +104 -0
  49. package/lib/esm/Toast/__toast.vanilla.js +422 -0
  50. package/lib/esm/Toast/index.scss +24 -96
  51. package/lib/esm/Toast/index.tsx +3 -374
  52. package/lib/esm/Toast/types.ts +60 -0
  53. package/lib/esm/Toast/useToast.tsx +72 -0
  54. package/package.json +1 -1
package/Toast/index.js CHANGED
@@ -206,6 +206,220 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
206
206
 
207
207
  /***/ }),
208
208
 
209
+ /***/ 188:
210
+ /***/ (function(module, exports, __webpack_require__) {
211
+
212
+ /* module decorator */ module = __webpack_require__.nmd(module);
213
+ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;function _typeof2(obj) { "@babel/helpers - typeof"; return _typeof2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof2(obj); }
214
+ (function webpackUniversalModuleDefinition(root, factory) {
215
+ if (( false ? 0 : _typeof2(exports)) === 'object' && ( false ? 0 : _typeof2(module)) === 'object') module.exports = factory();else if (true) !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory),
216
+ __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
217
+ (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__),
218
+ __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));else {}
219
+ })(this, function () {
220
+ return (/******/function () {
221
+ // webpackBootstrap
222
+ /******/
223
+ "use strict";
224
+
225
+ /******/ // The require scope
226
+ /******/
227
+ var __nested_webpack_require_993__ = {};
228
+ /******/
229
+ /************************************************************************/
230
+ /******/ /* webpack/runtime/define property getters */
231
+ /******/
232
+ (function () {
233
+ /******/ // define getter functions for harmony exports
234
+ /******/__nested_webpack_require_993__.d = function (exports, definition) {
235
+ /******/for (var key in definition) {
236
+ /******/if (__nested_webpack_require_993__.o(definition, key) && !__nested_webpack_require_993__.o(exports, key)) {
237
+ /******/Object.defineProperty(exports, key, {
238
+ enumerable: true,
239
+ get: definition[key]
240
+ });
241
+ /******/
242
+ }
243
+ /******/
244
+ }
245
+ /******/
246
+ };
247
+ /******/
248
+ })();
249
+ /******/
250
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
251
+ /******/
252
+ (function () {
253
+ /******/__nested_webpack_require_993__.o = function (obj, prop) {
254
+ return Object.prototype.hasOwnProperty.call(obj, prop);
255
+ };
256
+ /******/
257
+ })();
258
+ /******/
259
+ /******/ /* webpack/runtime/make namespace object */
260
+ /******/
261
+ (function () {
262
+ /******/ // define __esModule on exports
263
+ /******/__nested_webpack_require_993__.r = function (exports) {
264
+ /******/if (typeof Symbol !== 'undefined' && Symbol.toStringTag) {
265
+ /******/Object.defineProperty(exports, Symbol.toStringTag, {
266
+ value: 'Module'
267
+ });
268
+ /******/
269
+ }
270
+ /******/
271
+ Object.defineProperty(exports, '__esModule', {
272
+ value: true
273
+ });
274
+ /******/
275
+ };
276
+ /******/
277
+ })();
278
+ /******/
279
+ /************************************************************************/
280
+ var __webpack_exports__ = {};
281
+ __nested_webpack_require_993__.r(__webpack_exports__);
282
+ /* harmony export */
283
+ __nested_webpack_require_993__.d(__webpack_exports__, {
284
+ /* harmony export */"clsWrite": function clsWrite() {
285
+ return (/* binding */_clsWrite
286
+ );
287
+ },
288
+ /* harmony export */"combinedCls": function combinedCls() {
289
+ return (/* binding */_combinedCls
290
+ );
291
+ }
292
+ /* harmony export */
293
+ });
294
+ function _slicedToArray(arr, i) {
295
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
296
+ }
297
+ function _nonIterableRest() {
298
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
299
+ }
300
+ function _unsupportedIterableToArray(o, minLen) {
301
+ if (!o) return;
302
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
303
+ var n = Object.prototype.toString.call(o).slice(8, -1);
304
+ if (n === "Object" && o.constructor) n = o.constructor.name;
305
+ if (n === "Map" || n === "Set") return Array.from(o);
306
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
307
+ }
308
+ function _arrayLikeToArray(arr, len) {
309
+ if (len == null || len > arr.length) len = arr.length;
310
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
311
+ return arr2;
312
+ }
313
+ function _iterableToArrayLimit(arr, i) {
314
+ var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
315
+ if (null != _i) {
316
+ var _s,
317
+ _e,
318
+ _x,
319
+ _r,
320
+ _arr = [],
321
+ _n = !0,
322
+ _d = !1;
323
+ try {
324
+ if (_x = (_i = _i.call(arr)).next, 0 === i) {
325
+ if (Object(_i) !== _i) return;
326
+ _n = !1;
327
+ } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
328
+ } catch (err) {
329
+ _d = !0, _e = err;
330
+ } finally {
331
+ try {
332
+ if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return;
333
+ } finally {
334
+ if (_d) throw _e;
335
+ }
336
+ }
337
+ return _arr;
338
+ }
339
+ }
340
+ function _arrayWithHoles(arr) {
341
+ if (Array.isArray(arr)) return arr;
342
+ }
343
+ function _typeof(obj) {
344
+ "@babel/helpers - typeof";
345
+
346
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
347
+ return typeof obj;
348
+ } : function (obj) {
349
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
350
+ }, _typeof(obj);
351
+ }
352
+ /**
353
+ * Output of class name
354
+ * @param {*} s - Any
355
+ * @param {String} defaultCls - Default string
356
+ * @param {?*} targetCls - Any
357
+ * @returns {*}
358
+ */
359
+ function _clsWrite(s, defaultCls) {
360
+ var targetCls = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
361
+ return s || s === '' ? typeof targetCls === 'undefined' ? s : targetCls : defaultCls;
362
+ }
363
+
364
+ /**
365
+ * Combined classnames
366
+ * @param {*} args
367
+ * @returns {String|undefined}
368
+ */
369
+ /* Usage:
370
+
371
+ console.log(combinedCls('a-1', 'a-2', 'a-3', {
372
+ 'p-1': null,
373
+ 'p-2': undefined,
374
+ 'p-3': true,
375
+ 'p-4': false,
376
+ 'p-5': 'kkk',
377
+ 'p-6': 0,
378
+ 'p-7': 1,
379
+ 'p-8': '',
380
+ undefined
381
+ })); // a-1 a-2 a-3 p-3 p-5 p-7
382
+ */
383
+ function _combinedCls() {
384
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
385
+ args[_key] = arguments[_key];
386
+ }
387
+ if (args) {
388
+ var classes = [];
389
+ for (var i = 0; i < args.length; i++) {
390
+ var className = args[i];
391
+ if (!className) {
392
+ continue;
393
+ }
394
+ var type = _typeof(className);
395
+ if (type === 'string' || type === 'number') {
396
+ classes.push(className);
397
+ } else if (type === 'object') {
398
+ var _classes = Array.isArray(className) ? className : Object.entries(className).map(function (_ref) {
399
+ var _ref2 = _slicedToArray(_ref, 2),
400
+ key = _ref2[0],
401
+ value = _ref2[1];
402
+ return value ? key : null;
403
+ });
404
+ classes = _classes.length ? classes.concat(_classes.filter(function (c) {
405
+ return !!c;
406
+ })) : classes;
407
+ }
408
+ }
409
+ return classes.join(' ').trim();
410
+ }
411
+ return undefined;
412
+ }
413
+
414
+ /******/
415
+ return __webpack_exports__;
416
+ /******/
417
+ }()
418
+ );
419
+ });
420
+
421
+ /***/ }),
422
+
209
423
  /***/ 85:
210
424
  /***/ (function(module, exports, __webpack_require__) {
211
425
 
@@ -479,29 +693,35 @@ __webpack_require__.r(__webpack_exports__);
479
693
 
480
694
  // EXPORTS
481
695
  __webpack_require__.d(__webpack_exports__, {
482
- "default": () => (/* binding */ src)
696
+ "ToastProvider": () => (/* reexport */ ToastProvider),
697
+ "useToast": () => (/* reexport */ useToast)
483
698
  });
484
699
 
485
700
  // EXTERNAL MODULE: external {"root":"React","commonjs2":"react","commonjs":"react","amd":"react"}
486
701
  var external_root_React_commonjs2_react_commonjs_react_amd_react_ = __webpack_require__(787);
487
702
  var external_root_React_commonjs2_react_commonjs_react_amd_react_default = /*#__PURE__*/__webpack_require__.n(external_root_React_commonjs2_react_commonjs_react_amd_react_);
488
- // EXTERNAL MODULE: ../Utils/dist/cjs/useComId.js
489
- var useComId = __webpack_require__(85);
490
- var useComId_default = /*#__PURE__*/__webpack_require__.n(useComId);
491
703
  // EXTERNAL MODULE: ../RootPortal/dist/cjs/index.js
492
704
  var cjs = __webpack_require__(909);
493
705
  var cjs_default = /*#__PURE__*/__webpack_require__.n(cjs);
706
+ // EXTERNAL MODULE: ../Utils/dist/cjs/useComId.js
707
+ var useComId = __webpack_require__(85);
708
+ var useComId_default = /*#__PURE__*/__webpack_require__.n(useComId);
709
+ // EXTERNAL MODULE: ../Utils/dist/cjs/cls.js
710
+ var cls = __webpack_require__(188);
494
711
  ;// CONCATENATED MODULE: ./src/Item.tsx
495
712
 
713
+
496
714
  ;
497
715
  var Item = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.forwardRef)(function (props, externalRef) {
498
- var onlyOne = props.onlyOne,
716
+ var depth = props.depth,
499
717
  index = props.index,
718
+ isNew = props.isNew,
719
+ uniqueID = props.uniqueID,
720
+ onlyOne = props.onlyOne,
500
721
  title = props.title,
501
722
  note = props.note,
502
723
  theme = props.theme,
503
724
  message = props.message,
504
- depth = props.depth,
505
725
  lock = props.lock,
506
726
  cascading = props.cascading,
507
727
  schemeBody = props.schemeBody,
@@ -513,10 +733,16 @@ var Item = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_react_am
513
733
  evPause = props.evPause,
514
734
  evClose = props.evClose;
515
735
  var containerRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
736
+ var hideTitle = (title === '' || title === false) && (note === '' || note === false);
516
737
  return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement((external_root_React_commonjs2_react_commonjs_react_amd_react_default()).Fragment, null, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
517
738
  ref: containerRef,
518
- className: "toast-container ".concat(onlyOne ? 'only-one' : ''),
739
+ id: "toast-".concat(uniqueID),
740
+ "data-toast-id": uniqueID,
741
+ "data-new": isNew,
519
742
  "data-index": index,
743
+ className: (0,cls.combinedCls)('toast-container', {
744
+ 'only-one': onlyOne
745
+ }),
520
746
  style: cascading ? {
521
747
  transform: "perspective(100px) translateZ(-".concat(2 * index, "px) translateY(").concat(35 * index, "px)"),
522
748
  zIndex: depth
@@ -526,10 +752,10 @@ var Item = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_react_am
526
752
  onMouseEnter: evPause,
527
753
  onMouseLeave: evStart
528
754
  }, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
529
- className: "toast fade show ".concat(schemeBody ? schemeBody : '', " ").concat(theme ? "bg-".concat(theme) : ''),
755
+ className: (0,cls.combinedCls)("toast fade show ".concat(theme ? "bg-".concat(theme) : ''), (0,cls.clsWrite)(schemeBody, '')),
530
756
  role: "alert"
531
- }, (title === '' || title === false) && (note === '' || note === false) ? null : /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement((external_root_React_commonjs2_react_commonjs_react_amd_react_default()).Fragment, null, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
532
- className: "toast-header ".concat(schemeHeader ? schemeHeader : '')
757
+ }, hideTitle ? null : /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement((external_root_React_commonjs2_react_commonjs_react_amd_react_default()).Fragment, null, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
758
+ className: (0,cls.combinedCls)('toast-header', (0,cls.clsWrite)(schemeHeader, ''))
533
759
  }, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("strong", {
534
760
  className: "me-auto"
535
761
  }, title === '' || title === false ? '' : /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement((external_root_React_commonjs2_react_commonjs_react_amd_react_default()).Fragment, null, title)), /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("small", {
@@ -553,7 +779,7 @@ var Item = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_react_am
553
779
  fillRule: "evenodd"
554
780
  }))) : null) : null)), /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
555
781
  className: "toast-body"
556
- }, message, (title === '' || title === false) && (note === '' || note === false) ? /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement((external_root_React_commonjs2_react_commonjs_react_amd_react_default()).Fragment, null, !closeDisabled ? /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("button", {
782
+ }, message, hideTitle ? /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement((external_root_React_commonjs2_react_commonjs_react_amd_react_default()).Fragment, null, !closeDisabled ? /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("button", {
557
783
  "data-close": "1",
558
784
  "data-index": index,
559
785
  tabIndex: -1,
@@ -573,14 +799,20 @@ var Item = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_react_am
573
799
  }))) : null) : null, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
574
800
  ref: externalRef,
575
801
  "data-progress-index": index,
576
- className: "progress active toast-progress ".concat(autoCloseTime === false ? 'd-none' : ''),
802
+ className: (0,cls.combinedCls)('progress active toast-progress', {
803
+ 'd-none': autoCloseTime === false
804
+ }),
577
805
  role: "progressbar"
578
806
  }, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
579
807
  className: "progress-bar"
580
808
  }))))));
581
809
  });
582
810
  /* harmony default export */ const src_Item = (Item);
583
- ;// CONCATENATED MODULE: ./src/index.tsx
811
+ ;// CONCATENATED MODULE: ./src/Toast.tsx
812
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
813
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
814
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
815
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
584
816
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
585
817
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
586
818
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(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); }
@@ -591,58 +823,86 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
591
823
 
592
824
 
593
825
 
594
- var Toast = function Toast(props) {
595
- var wrapperClassName = props.wrapperClassName,
596
- async = props.async,
597
- autoHideMultiple = props.autoHideMultiple,
598
- direction = props.direction,
599
- autoCloseTime = props.autoCloseTime,
600
- lock = props.lock,
601
- cascading = props.cascading,
602
- data = props.data,
603
- schemeBody = props.schemeBody,
604
- schemeHeader = props.schemeHeader,
605
- closeBtnColor = props.closeBtnColor,
606
- closeDisabled = props.closeDisabled,
607
- id = props.id,
608
- onClose = props.onClose;
826
+
827
+ var Toast = function Toast(_ref) {
828
+ var data = _ref.data,
829
+ defaultWrapperClassName = _ref.defaultWrapperClassName,
830
+ defaultOnlyShowOne = _ref.defaultOnlyShowOne,
831
+ defaultDirection = _ref.defaultDirection,
832
+ defaultCascading = _ref.defaultCascading,
833
+ defaultReverseDisplay = _ref.defaultReverseDisplay,
834
+ onUpdate = _ref.onUpdate;
609
835
  var ANIM_SPEED = 300;
610
836
  var DEFAULT_AUTO_CLOSE_TIME = 3000;
611
837
  var uniqueID = useComId_default()();
612
- var idRes = id || uniqueID;
613
838
  var rootRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
614
- var depth = autoHideMultiple ? data.slice(-2).length + 1 : data.length + 1;
615
- var cascadingEnabled = typeof cascading === 'undefined' ? true : cascading;
616
839
 
617
- // force display
618
- var _useState = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(false),
840
+ // action id
841
+ var _useState = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(undefined),
619
842
  _useState2 = _slicedToArray(_useState, 2),
620
- initPopRoot = _useState2[0],
621
- setInitPopRoot = _useState2[1];
843
+ currentActionId = _useState2[0],
844
+ setCurrentActionId = _useState2[1];
622
845
 
623
- // auto close
624
- var AUTO_CLOSE_TIME = typeof autoCloseTime === 'undefined' || autoCloseTime === false ? false : autoCloseTime;
846
+ // 追踪每个 toast 的动画状态
847
+ var _useState3 = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(new Set()),
848
+ _useState4 = _slicedToArray(_useState3, 2),
849
+ animatedToasts = _useState4[0],
850
+ setAnimatedToasts = _useState4[1];
851
+
852
+ // force display
853
+ var _useState5 = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(false),
854
+ _useState6 = _slicedToArray(_useState5, 2),
855
+ initPopRoot = _useState6[0],
856
+ setInitPopRoot = _useState6[1];
857
+
858
+ // Get the global configuration from the first toast item (if it exists)
859
+ var firstToast = data[0] || {};
860
+
861
+ // Use default values but allow individual toast overrides
862
+ var wrapperClassName = firstToast.wrapperClassName || defaultWrapperClassName;
863
+ var direction = firstToast.direction || defaultDirection;
864
+ var cascadingEnabled = typeof firstToast.cascading !== 'undefined' ? firstToast.cascading : defaultCascading;
865
+ var onlyShowOne = typeof firstToast.onlyShowOne !== 'undefined' ? firstToast.onlyShowOne : defaultOnlyShowOne;
866
+ var reverseDisplay = typeof firstToast.reverseDisplay !== 'undefined' ? firstToast.reverseDisplay : defaultReverseDisplay;
867
+ var depth = data.length + 1;
868
+
869
+ // Processes the order of data based on the "direction" and "reverseDisplay" parameters
870
+ var getProcessedData = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)(function () {
871
+ var processedData = _toConsumableArray(data);
872
+ if ((direction !== null && direction !== void 0 && direction.startsWith('top-') || direction !== null && direction !== void 0 && direction.startsWith('vertical-')) && reverseDisplay) {
873
+ processedData.reverse();
874
+ } else if (direction !== null && direction !== void 0 && direction.startsWith('bottom-') && !reverseDisplay) {
875
+ processedData.reverse();
876
+ }
877
+
878
+ // If only one is displayed, only the last one is returned
879
+ return onlyShowOne ? [processedData[processedData.length - 1]] : processedData;
880
+ }, [data, direction, reverseDisplay, onlyShowOne]);
881
+
882
+ // Store the status of each toast
883
+ var progressPausedRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(new Map());
884
+ var progressObjRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(new Map());
885
+ var progressIntervalRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(new Map());
886
+ var startProgressTimer = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)(function (el, toastId, i) {
887
+ // If the toast already has a timer running, do not add it again
888
+ if (progressIntervalRef.current.has(toastId)) {
889
+ return;
890
+ }
891
+ var currentToast = data[i];
892
+
893
+ // progress animation
894
+ var PROGRESS_TRANSITION_TIME = typeof currentToast.autoCloseTime === 'undefined' || currentToast.autoCloseTime === false ? DEFAULT_AUTO_CLOSE_TIME : currentToast.autoCloseTime;
625
895
 
626
- // progress animation
627
- var PROGRESS_TRANSITION_TIME = typeof autoCloseTime === 'undefined' || autoCloseTime === false ? DEFAULT_AUTO_CLOSE_TIME : autoCloseTime;
628
- var progressPausedRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(data.map(function (v) {
629
- return false;
630
- }));
631
- var progressObjRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)([]);
632
- var progressIntervalRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(data.map(function (v) {
633
- return null;
634
- }));
635
- var startProgressTimer = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)(function (el, i) {
636
896
  // init progress
637
897
  var progressCurrentChunk = 100 / (PROGRESS_TRANSITION_TIME / 100);
638
898
  el.firstChild.style.width = 100 + '%';
639
899
  el.firstChild.ariaValueNow = 100;
640
900
 
641
901
  // animation
642
- progressIntervalRef.current[i] = setInterval(function () {
902
+ var intervalId = setInterval(function () {
643
903
  // console.log('toast setInterval');
644
904
 
645
- if (!progressPausedRef.current[i]) {
905
+ if (!progressPausedRef.current.get(toastId)) {
646
906
  var progPercent = 100 - progressCurrentChunk;
647
907
  el.firstChild.style.width = progPercent + '%';
648
908
  el.firstChild.ariaValueNow = progPercent;
@@ -654,7 +914,7 @@ var Toast = function Toast(props) {
654
914
  el.classList.add('complete');
655
915
 
656
916
  // stop current animation
657
- stopProgressTimer(i);
917
+ stopProgressTimer(toastId);
658
918
 
659
919
  // hide toast item
660
920
  var currentItem = el.closest('.toast-container');
@@ -662,111 +922,46 @@ var Toast = function Toast(props) {
662
922
  }
663
923
  }
664
924
  }, PROGRESS_TRANSITION_TIME / 100);
665
- }, []);
666
- var clearAllProgressTimer = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)(function () {
667
- var curIndex = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
668
- if (typeof curIndex === 'undefined') {
669
- data.forEach(function (item, i) {
670
- clearInterval(progressIntervalRef.current[i]);
671
- progressIntervalRef.current[i] = null;
672
- });
673
- } else {
674
- data.forEach(function (item, i) {
675
- if (i === curIndex) {
676
- clearInterval(progressIntervalRef.current[i]);
677
- progressIntervalRef.current[i] = null;
678
- }
679
- });
680
- }
681
- }, [data]);
682
- var stopProgressTimer = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)(function (index) {
683
- clearInterval(progressIntervalRef.current[index]);
684
- progressIntervalRef.current[index] = null;
925
+
926
+ // Save the timer ID
927
+ progressIntervalRef.current.set(toastId, intervalId);
685
928
  }, [data]);
686
- function progressAnimBegin() {
687
- data.forEach(function (item, i) {
688
- var el = progressObjRef.current[i];
689
- if (el !== null && typeof el !== 'undefined') startProgressTimer(el, i);
929
+ var clearAllProgressTimer = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)(function () {
930
+ progressIntervalRef.current.forEach(function (timer, id) {
931
+ if (timer) {
932
+ clearInterval(timer);
933
+ progressIntervalRef.current.set(id, null);
934
+ }
690
935
  });
691
- }
936
+ progressIntervalRef.current.clear();
937
+ }, []);
938
+ var stopProgressTimer = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)(function (toastId) {
939
+ var timer = progressIntervalRef.current.get(toastId);
940
+ if (timer) {
941
+ clearInterval(timer);
942
+ progressIntervalRef.current["delete"](toastId);
943
+ }
944
+ }, []);
692
945
  function handleProgressPaused(e) {
693
- var _currentIndex = e.currentTarget.dataset.index;
694
- progressPausedRef.current[_currentIndex] = true;
946
+ var toastId = e.currentTarget.dataset.toastId;
947
+ progressPausedRef.current.set(toastId, true);
695
948
  }
696
949
  function handleProgressStart(e) {
697
- var _currentIndex = e.currentTarget.dataset.index;
698
- progressPausedRef.current[_currentIndex] = false;
699
- }
700
-
701
- //
702
- function init() {
703
- if (rootRef.current === null) return;
704
- var $toast = rootRef.current;
705
-
706
- // Automatically hide multiple items
707
- // It creates a transition animation effect with multiple records and only one displayed.
708
- //------------------------------------------
709
- if (autoHideMultiple) {
710
- var _list = [].slice.call($toast.querySelectorAll('.toast-container'));
711
- if (_list.length === 2) {
712
- _list.forEach(function (node, i) {
713
- node.classList.remove('auto-anim-switch', 'auto-anim-switch--initfirst', 'auto-anim-switch--first');
714
- if (i !== _list.length - 1) {
715
- node.classList.add('auto-anim-switch--initfirst'); // top element of source code
716
- } else {
717
- node.classList.add('auto-anim-switch--initfirst'); // bottom element of source code
718
- }
719
- });
720
-
721
- setTimeout(function () {
722
- _list.forEach(function (node, i) {
723
- if (i !== _list.length - 1) {
724
- node.classList.add('auto-anim-switch');
725
- } else {
726
- node.classList.add('auto-anim-switch--initfirst', 'auto-anim-switch--first');
727
- }
728
- });
729
- }, ANIM_SPEED / 2);
730
- } else {
731
- _list.forEach(function (node, i) {
732
- if (i !== _list.length - 1) {
733
- node.classList.add('auto-anim-switch');
734
- } else {
735
- node.classList.add('auto-anim-switch--initfirst', 'auto-anim-switch--first');
736
- }
737
- });
738
- }
739
- }
740
-
741
- // Initialize data
742
- //--------------
743
- if ($toast.dataset.async == 'true') {
744
- var _list2 = [].slice.call($toast.querySelectorAll('.toast-container'));
745
- _list2.forEach(function (node, i) {
746
- node.classList.remove('hide-end');
747
- // rearrange
748
- if (cascadingEnabled) node.style.transform = "perspective(100px) translateZ(-".concat(2 * i, "px) translateY(").concat(35 * i, "px)");
749
- });
750
- }
751
- }
752
- function autoClose() {
753
- // Auto hide
754
- //--------------
755
- if (AUTO_CLOSE_TIME !== false) {
756
- // start animation
757
- progressAnimBegin();
758
- }
950
+ var toastId = e.currentTarget.dataset.toastId;
951
+ progressPausedRef.current.set(toastId, false);
759
952
  }
760
953
  function handleClose(e, index, currentItem) {
761
954
  if (typeof e !== 'undefined' && e !== null) e.preventDefault();
762
955
  if (rootRef.current === null) return;
763
956
  var curIndex = Number(index);
957
+ var currentToast = data[curIndex];
958
+ var toastId = currentToast.id;
764
959
  var _list = [].slice.call(rootRef.current.querySelectorAll('.toast-container'));
765
960
  currentItem.classList.add('hide-start');
766
961
 
767
962
  //Let the removed animation show
768
963
  setTimeout(function () {
769
- _list.forEach(function (node, i) {
964
+ _list.forEach(function (node) {
770
965
  node.classList.remove('hide-start');
771
966
  });
772
967
 
@@ -783,76 +978,358 @@ var Toast = function Toast(props) {
783
978
  }
784
979
 
785
980
  // stop all animations or current animation
786
- if (_list.length === 1 || autoHideMultiple) {
787
- clearAllProgressTimer();
788
- } else {
789
- clearAllProgressTimer(curIndex);
981
+ stopProgressTimer(toastId);
982
+
983
+ // close callback
984
+ var currentToast = data[curIndex];
985
+ if (currentToast.onClose) {
986
+ currentToast.onClose(rootRef.current, curIndex, _list.filter(function (node) {
987
+ return !node.classList.contains('hide-end');
988
+ }));
790
989
  }
791
990
 
792
- //
793
- onClose === null || onClose === void 0 ? void 0 : onClose(rootRef.current, curIndex, _list.filter(function (node) {
794
- return !node.classList.contains('hide-end');
795
- }));
991
+ // After the animation ends, remove the item from the data source
992
+ if (onUpdate) {
993
+ var newData = _toConsumableArray(data);
994
+ newData.splice(curIndex, 1);
995
+ onUpdate(newData);
996
+ }
796
997
  }, ANIM_SPEED);
797
998
  }
798
999
  (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function () {
799
1000
  if (initPopRoot) {
800
- // Initialize Toast Item
801
- //------------------------------------------
802
- init();
1001
+ var $toast = rootRef.current;
1002
+ if (!$toast) return;
803
1003
 
804
- // Initialize Progress
805
- //------------------------------------------
806
- autoClose();
1004
+ // When "onlyShowOne" is true, only the latest toast is kept
1005
+ //--------------
1006
+ if (onlyShowOne && data.length > 1) {
1007
+ // Clear all old timers
1008
+ data.slice(0, -1).forEach(function (toast, index) {
1009
+ stopProgressTimer(toast.id);
1010
+ });
1011
+
1012
+ //Only keep the latest toast
1013
+ if (onUpdate) {
1014
+ onUpdate([data[data.length - 1]]);
1015
+ }
1016
+ return;
1017
+ }
807
1018
 
808
- // Remove the global list of events, especially as scroll and interval.
1019
+ // Auto hide
809
1020
  //--------------
810
- return function () {
811
- // Stop all animations
812
- clearAllProgressTimer();
813
- };
1021
+ data.forEach(function (toast, i) {
1022
+ // auto close
1023
+ var AUTO_CLOSE_TIME = typeof toast.autoCloseTime === 'undefined' || toast.autoCloseTime === false ? false : toast.autoCloseTime;
1024
+ if (AUTO_CLOSE_TIME !== false) {
1025
+ var el = progressObjRef.current.get(toast.id);
1026
+ if (el) {
1027
+ startProgressTimer(el, toast.id, i);
1028
+ }
1029
+ }
1030
+ });
1031
+ }
1032
+ }, [data, initPopRoot, onlyShowOne]);
1033
+
1034
+ // Handling animation when data changes
1035
+ (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function () {
1036
+ if (initPopRoot && data.length > 0) {
1037
+ // Add animation to the new toast
1038
+ var newToasts = data.filter(function (toast) {
1039
+ return !animatedToasts.has(toast.id);
1040
+ });
1041
+ if (newToasts.length > 0) {
1042
+ // Keep the new toast hidden first
1043
+ newToasts.forEach(function (toast) {
1044
+ var progressEl = progressObjRef.current.get(toast.id);
1045
+ if (progressEl) {
1046
+ var currentItem = progressEl.closest('.toast-container');
1047
+ currentItem.classList.add('animate-ready');
1048
+ }
1049
+ });
1050
+
1051
+ // Use "requestAnimationFrame" to ensure the DOM is updated before adding animation classes
1052
+ requestAnimationFrame(function () {
1053
+ setTimeout(function () {
1054
+ newToasts.forEach(function (toast) {
1055
+ var progressEl = progressObjRef.current.get(toast.id);
1056
+ if (progressEl) {
1057
+ var currentItem = progressEl.closest('.toast-container');
1058
+ currentItem.classList.remove('animate-ready');
1059
+ currentItem.classList.add('animate-in');
1060
+ }
1061
+ });
1062
+
1063
+ // Update the animated toast list
1064
+ setAnimatedToasts(function (prev) {
1065
+ var newSet = new Set(prev);
1066
+ newToasts.forEach(function (toast) {
1067
+ return newSet.add(toast.id);
1068
+ });
1069
+ return newSet;
1070
+ });
1071
+ }, 50); // A small delay ensures that animate-ready styles are applied
1072
+ });
1073
+ }
814
1074
  }
815
1075
  }, [data, initPopRoot]);
1076
+
1077
+ // Monitor the currently displayed toast id
1078
+ (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function () {
1079
+ if (onlyShowOne && data.length > 0) {
1080
+ var latestToast = data[data.length - 1];
1081
+ setCurrentActionId(latestToast.actionId);
1082
+ } else if (data.length > 0) {
1083
+ var currentIds = data.map(function (toast) {
1084
+ return toast.actionId;
1085
+ });
1086
+ setCurrentActionId(currentIds[currentIds.length - 1]);
1087
+ } else {
1088
+ setCurrentActionId(null);
1089
+ }
1090
+ }, [data, onlyShowOne]);
1091
+
1092
+ // The timer and data are emptied each time "useToast().show()" is executed
1093
+ (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function () {
1094
+ if (currentActionId === null || typeof currentActionId === 'undefined') return;
1095
+ if (onUpdate) {
1096
+ onUpdate([data[data.length - 1]]);
1097
+ }
1098
+
1099
+ // Remove the global list of events, especially as scroll and interval.
1100
+ //--------------
1101
+ return function () {
1102
+ clearAllProgressTimer();
1103
+ };
1104
+ }, [currentActionId]);
1105
+
1106
+ // init
816
1107
  (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function () {
817
1108
  setInitPopRoot(true);
1109
+
1110
+ // Remove the global list of events, especially as scroll and interval.
1111
+ //--------------
1112
+ return function () {
1113
+ clearAllProgressTimer();
1114
+ };
818
1115
  }, []);
819
- return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement((external_root_React_commonjs2_react_commonjs_react_amd_react_default()).Fragment, null, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement((cjs_default()), {
1116
+ return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement((cjs_default()), {
820
1117
  show: initPopRoot,
821
1118
  containerClassName: "Toast"
822
1119
  }, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
823
- id: "toasts__wrapper-".concat(idRes),
824
- "data-async": async ? async : false,
825
- className: "toasts__wrapper toasts__wrapper--".concat(direction ? direction : 'bottom-center', " ").concat(cascadingEnabled ? 'toasts__wrapper--cascading' : '', " ").concat(wrapperClassName || ''),
1120
+ id: "toasts__wrapper-".concat(uniqueID),
1121
+ className: (0,cls.combinedCls)('toasts__wrapper', "toasts__wrapper--".concat(direction), (0,cls.clsWrite)(wrapperClassName, ''), {
1122
+ 'toasts__wrapper--cascading': cascadingEnabled,
1123
+ 'toasts__wrapper--only-one"': onlyShowOne
1124
+ }),
826
1125
  ref: rootRef
827
1126
  }, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
828
1127
  className: "toasts"
829
- }, (autoHideMultiple ? data.slice(-2) : data).map(function (item, i) {
1128
+ }, getProcessedData().map(function (item, i) {
830
1129
  return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement(src_Item, {
831
1130
  ref: function ref(el) {
832
- return progressObjRef.current[i] = el;
1131
+ return progressObjRef.current.set(item.id, el);
833
1132
  },
834
- onlyOne: data.length === 1 ? true : false,
1133
+ key: item.id,
1134
+ uniqueID: item.id,
1135
+ isNew: !progressObjRef.current.has(item.id) // Mark the new toast
1136
+ ,
1137
+ onlyOne: data.length === 1,
835
1138
  depth: depth - i,
836
- key: i,
837
1139
  index: i,
838
1140
  title: item.title,
839
1141
  note: item.note,
840
1142
  theme: item.theme,
841
- lock: lock,
1143
+ lock: item.lock,
842
1144
  cascading: cascadingEnabled,
843
- schemeBody: schemeBody,
844
- schemeHeader: schemeHeader,
845
- closeBtnColor: closeBtnColor,
846
- closeDisabled: closeDisabled,
1145
+ schemeBody: item.schemeBody,
1146
+ schemeHeader: item.schemeHeader,
1147
+ closeBtnColor: item.closeBtnColor,
1148
+ closeDisabled: item.closeDisabled,
847
1149
  message: item.message,
848
- autoCloseTime: AUTO_CLOSE_TIME,
1150
+ autoCloseTime: item.autoCloseTime,
849
1151
  evStart: handleProgressStart,
850
1152
  evPause: handleProgressPaused,
851
1153
  evClose: handleClose
852
1154
  });
853
- })))));
1155
+ }))));
854
1156
  };
855
- /* harmony default export */ const src = (Toast);
1157
+ /* harmony default export */ const src_Toast = ((/* unused pure expression or super */ null && (Toast)));
1158
+ ;// CONCATENATED MODULE: ./src/ToastContext.tsx
1159
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
1160
+ function ToastContext_slicedToArray(arr, i) { return ToastContext_arrayWithHoles(arr) || ToastContext_iterableToArrayLimit(arr, i) || ToastContext_unsupportedIterableToArray(arr, i) || ToastContext_nonIterableRest(); }
1161
+ function ToastContext_nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
1162
+ function ToastContext_iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
1163
+ function ToastContext_arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
1164
+ function ToastContext_toConsumableArray(arr) { return ToastContext_arrayWithoutHoles(arr) || ToastContext_iterableToArray(arr) || ToastContext_unsupportedIterableToArray(arr) || ToastContext_nonIterableSpread(); }
1165
+ function ToastContext_nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
1166
+ function ToastContext_unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return ToastContext_arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(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 ToastContext_arrayLikeToArray(o, minLen); }
1167
+ function ToastContext_iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
1168
+ function ToastContext_arrayWithoutHoles(arr) { if (Array.isArray(arr)) return ToastContext_arrayLikeToArray(arr); }
1169
+ function ToastContext_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; }
1170
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
1171
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
1172
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
1173
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
1174
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
1175
+
1176
+
1177
+ var defaultConfig = {
1178
+ defaultWrapperClassName: '',
1179
+ defaultOnlyShowOne: false,
1180
+ defaultDirection: 'bottom-center',
1181
+ defaultCascading: false,
1182
+ defaultReverseDisplay: false
1183
+ };
1184
+ var ToastContext = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.createContext)(undefined);
1185
+ var toastReducer = function toastReducer(state, action) {
1186
+ switch (action.type) {
1187
+ case 'ADD_TOAST':
1188
+ return _objectSpread(_objectSpread({}, state), {}, {
1189
+ toasts: [].concat(ToastContext_toConsumableArray(state.toasts), [action.payload])
1190
+ });
1191
+ case 'REMOVE_TOAST':
1192
+ return _objectSpread(_objectSpread({}, state), {}, {
1193
+ toasts: state.toasts.filter(function (toast) {
1194
+ return toast.id !== action.payload;
1195
+ })
1196
+ });
1197
+ case 'REMOVE_ALL':
1198
+ return _objectSpread(_objectSpread({}, state), {}, {
1199
+ toasts: []
1200
+ });
1201
+ case 'UPDATE_CONFIG':
1202
+ return _objectSpread(_objectSpread({}, state), {}, {
1203
+ config: _objectSpread(_objectSpread({}, state.config), action.payload)
1204
+ });
1205
+ default:
1206
+ return state;
1207
+ }
1208
+ };
1209
+ var ToastProvider = function ToastProvider(_ref) {
1210
+ var children = _ref.children,
1211
+ _ref$config = _ref.config,
1212
+ config = _ref$config === void 0 ? {} : _ref$config;
1213
+ var _useReducer = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useReducer)(toastReducer, {
1214
+ toasts: [],
1215
+ config: _objectSpread(_objectSpread({}, defaultConfig), config)
1216
+ }),
1217
+ _useReducer2 = ToastContext_slicedToArray(_useReducer, 2),
1218
+ state = _useReducer2[0],
1219
+ dispatch = _useReducer2[1];
1220
+ return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement(ToastContext.Provider, {
1221
+ value: {
1222
+ state: state,
1223
+ dispatch: dispatch
1224
+ }
1225
+ }, children, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement(Toast, {
1226
+ data: state.toasts
1227
+
1228
+ // default props
1229
+ ,
1230
+ defaultWrapperClassName: state.config.defaultWrapperClassName,
1231
+ defaultDirection: state.config.defaultDirection,
1232
+ defaultOnlyShowOne: state.config.defaultOnlyShowOne,
1233
+ defaultCascading: state.config.defaultCascading,
1234
+ defaultReverseDisplay: state.config.defaultReverseDisplay
1235
+
1236
+ //
1237
+ ,
1238
+ onUpdate: function onUpdate(updatedData) {
1239
+ // Iterate through the current toasts and remove the toasts that are not in the "updatedData"
1240
+ state.toasts.forEach(function (toast) {
1241
+ if (!updatedData.find(function (item) {
1242
+ return item.id === toast.id;
1243
+ })) {
1244
+ dispatch({
1245
+ type: 'REMOVE_TOAST',
1246
+ payload: toast.id
1247
+ });
1248
+ }
1249
+ });
1250
+ }
1251
+ }));
1252
+ };
1253
+ var useToastContext = function useToastContext() {
1254
+ var context = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useContext)(ToastContext);
1255
+ if (!context) {
1256
+ throw new Error('useToastContext must be used within a ToastProvider');
1257
+ }
1258
+ return context;
1259
+ };
1260
+ ;// CONCATENATED MODULE: ./src/useToast.tsx
1261
+ function useToast_typeof(obj) { "@babel/helpers - typeof"; return useToast_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, useToast_typeof(obj); }
1262
+ function useToast_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
1263
+ function useToast_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? useToast_ownKeys(Object(source), !0).forEach(function (key) { useToast_defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : useToast_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
1264
+ function useToast_defineProperty(obj, key, value) { key = useToast_toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
1265
+ function useToast_toPropertyKey(arg) { var key = useToast_toPrimitive(arg, "string"); return useToast_typeof(key) === "symbol" ? key : String(key); }
1266
+ function useToast_toPrimitive(input, hint) { if (useToast_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (useToast_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
1267
+
1268
+
1269
+ var useToast = function useToast() {
1270
+ var _useToastContext = useToastContext(),
1271
+ state = _useToastContext.state,
1272
+ dispatch = _useToastContext.dispatch;
1273
+ var show = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)(function (options) {
1274
+ var id = Math.random().toString(36).substring(2, 9);
1275
+ var toast = useToast_objectSpread({
1276
+ id: id,
1277
+ // Configure the interface globally, but overrides are allowed to be overridden by the instance configuration.
1278
+ wrapperClassName: state.config.defaultWrapperClassName,
1279
+ direction: state.config.defaultDirection,
1280
+ onlyShowOne: state.config.defaultOnlyShowOne,
1281
+ cascading: state.config.defaultCascading,
1282
+ reverseDisplay: state.config.defaultReverseDisplay
1283
+ }, options);
1284
+ dispatch({
1285
+ type: 'ADD_TOAST',
1286
+ payload: toast
1287
+ });
1288
+ return toast; // Returns the full toast object
1289
+ }, [dispatch, state.config]);
1290
+ var updateConfig = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)(function (config) {
1291
+ dispatch({
1292
+ type: 'UPDATE_CONFIG',
1293
+ payload: config
1294
+ });
1295
+ }, [dispatch]);
1296
+ var close = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)(function (id) {
1297
+ dispatch({
1298
+ type: 'REMOVE_TOAST',
1299
+ payload: id
1300
+ });
1301
+ }, [dispatch]);
1302
+ var closeByIndex = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)(function (index) {
1303
+ var toast = state.toasts[index];
1304
+ if (toast) {
1305
+ dispatch({
1306
+ type: 'REMOVE_TOAST',
1307
+ payload: toast.id
1308
+ });
1309
+ }
1310
+ }, [state.toasts, dispatch]);
1311
+ var closeAll = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)(function () {
1312
+ dispatch({
1313
+ type: 'REMOVE_ALL'
1314
+ });
1315
+ }, [dispatch]);
1316
+
1317
+ // Get all current toasts
1318
+ var getToasts = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)(function () {
1319
+ return state.toasts;
1320
+ }, [state.toasts]);
1321
+ return {
1322
+ show: show,
1323
+ close: close,
1324
+ closeByIndex: closeByIndex,
1325
+ closeAll: closeAll,
1326
+ getToasts: getToasts,
1327
+ updateConfig: updateConfig
1328
+ };
1329
+ };
1330
+ ;// CONCATENATED MODULE: ./src/index.tsx
1331
+
1332
+
856
1333
  })();
857
1334
 
858
1335
  /******/ return __webpack_exports__;