d9-toast 1.4.26 → 1.4.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Icons.js CHANGED
@@ -1,7 +1,12 @@
1
+ "use client";
2
+
3
+ import { memo } from "react";
1
4
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
5
  var Icons = function Icons(_ref) {
6
+ var _icons$name;
3
7
  var name = _ref.name,
4
- className = _ref.className;
8
+ _ref$className = _ref.className,
9
+ className = _ref$className === void 0 ? " " : _ref$className;
5
10
  var icons = {
6
11
  success: /*#__PURE__*/_jsx("svg", {
7
12
  xmlns: "http://www.w3.org/2000/svg",
@@ -199,6 +204,6 @@ var Icons = function Icons(_ref) {
199
204
  })
200
205
  })
201
206
  };
202
- return icons[name];
207
+ return (_icons$name = icons[name]) !== null && _icons$name !== void 0 ? _icons$name : null;
203
208
  };
204
- export default Icons;
209
+ export default /*#__PURE__*/memo(Icons);
package/dist/Toast.js CHANGED
@@ -1,3 +1,5 @@
1
+ "use client";
2
+
1
3
  function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
2
4
  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."); }
3
5
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
@@ -1,3 +1,5 @@
1
+ "use client";
2
+
1
3
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
4
  function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
3
5
  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."); }
@@ -16,15 +18,15 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
16
18
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
17
19
  import React, { createContext, useCallback, useContext, useRef, useState } from "react";
18
20
  import Toast from "./Toast";
19
- import mySound from "./assets/sounds/toast.m4a";
20
21
  import "./toast.css";
21
22
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
23
+ export var DEFAULT_TOAST_SOUND = "https://cdn.jsdelivr.net/gh/psathul073/d9-toast-assets@main/toast.m4a";
22
24
  var ToastContext = /*#__PURE__*/createContext();
23
25
  export var useToast = function useToast() {
24
26
  return useContext(ToastContext);
25
27
  };
26
28
  var audioSettings = {
27
- audioFile: mySound,
29
+ audioFile: DEFAULT_TOAST_SOUND,
28
30
  volume: 0.8,
29
31
  enabled: true,
30
32
  cooldown: 500
@@ -41,10 +43,8 @@ export var ToastProvider = function ToastProvider(_ref) {
41
43
  var playAudio = useCallback(function (_ref2) {
42
44
  var audioFile = _ref2.audioFile,
43
45
  _ref2$volume = _ref2.volume,
44
- volume = _ref2$volume === void 0 ? 0.6 : _ref2$volume,
45
- _ref2$enabled = _ref2.enabled,
46
- enabled = _ref2$enabled === void 0 ? true : _ref2$enabled;
47
- if (!enabled || !audioFile) return;
46
+ volume = _ref2$volume === void 0 ? 0.8 : _ref2$volume;
47
+ if (!audioFile || typeof window === "undefined") return;
48
48
  try {
49
49
  var audio = new Audio(audioFile);
50
50
  audio.volume = volume;
@@ -56,12 +56,9 @@ export var ToastProvider = function ToastProvider(_ref) {
56
56
 
57
57
  // Generate unique ID safely
58
58
  var generateId = function generateId() {
59
- return Date.now() + Math.random();
59
+ return typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : Date.now().toString() + Math.random().toString(36);
60
60
  };
61
61
 
62
- // Positions.
63
- // const positions = [
64
-
65
62
  // Show toast..
66
63
  var showToast = useCallback(function (toast) {
67
64
  var _toast$audio$enabled, _toast$audio, _toast$audio$volume, _toast$audio2, _toast$audio$audioFil, _toast$audio3, _toast$audio$cooldown, _toast$audio4;
@@ -117,10 +114,8 @@ export var ToastProvider = function ToastProvider(_ref) {
117
114
 
118
115
  // Remove all toast.
119
116
  var removeToastAll = useCallback(function () {
120
- if (toasts.length > 0) {
121
- setToasts([]);
122
- }
123
- }, [toasts.length]);
117
+ setToasts([]);
118
+ }, []);
124
119
 
125
120
  // Group toasts by there positions..
126
121
  var groupedToasts = toasts.reduce(function (acc, toast) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "d9-toast",
3
- "version": "1.4.26",
3
+ "version": "1.4.28",
4
4
  "description": "Customizable toast notifications for React",
5
5
  "homepage": "https://codesandbox.io/embed/cqkyzm?view=preview",
6
6
  "repository": {
Binary file