@ravishranjan/cart 2.0.7 → 2.0.8
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/package.json +4 -4
- package/dist/chunk-K4RESSJQ.mjs +0 -15
- package/dist/chunk-RX26FWTT.mjs +0 -48
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ravishranjan/cart",
|
3
|
-
"version": "2.0.
|
3
|
+
"version": "2.0.8",
|
4
4
|
"description": "A native cart system for web apps with optional React hooks",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"module": "dist/index.mjs",
|
@@ -35,12 +35,12 @@
|
|
35
35
|
"license": "ISC",
|
36
36
|
"devDependencies": {
|
37
37
|
"@types/react": "^19.2.2",
|
38
|
-
"tsup": "^8.5.0"
|
38
|
+
"tsup": "^8.5.0",
|
39
|
+
"typescript": "^5.9.3"
|
39
40
|
},
|
40
41
|
"peerDependencies": {
|
41
42
|
"react": "^18.0.0 || ^19.0.0",
|
42
|
-
"react-dom": "^18.0.0 || ^19.0.0"
|
43
|
-
"typescript": "^5.9.3"
|
43
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
44
44
|
},
|
45
45
|
"peerDependenciesMeta": {
|
46
46
|
"react": {
|
package/dist/chunk-K4RESSJQ.mjs
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
CartContext
|
3
|
-
} from "./chunk-3AB6KTDB.mjs";
|
4
|
-
|
5
|
-
// src/react/useCart.tsx
|
6
|
-
import { useContext } from "react";
|
7
|
-
var useCart = () => {
|
8
|
-
const ctx = useContext(CartContext);
|
9
|
-
if (!ctx) throw new Error("useCart must be used within CartProvider");
|
10
|
-
return ctx;
|
11
|
-
};
|
12
|
-
|
13
|
-
export {
|
14
|
-
useCart
|
15
|
-
};
|
package/dist/chunk-RX26FWTT.mjs
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
Cart
|
3
|
-
} from "./chunk-YTW5MCYO.mjs";
|
4
|
-
|
5
|
-
// src/react/useCart.tsx
|
6
|
-
import { createContext, useContext, useEffect, useState } from "react";
|
7
|
-
import { jsx } from "react/jsx-runtime";
|
8
|
-
var CartContext = createContext(null);
|
9
|
-
var CartProvider = ({ children }) => {
|
10
|
-
const cartInstance = new Cart();
|
11
|
-
const [items, setItems] = useState(cartInstance.getItems());
|
12
|
-
const sync = () => setItems(cartInstance.getItems());
|
13
|
-
const api = {
|
14
|
-
cart: items,
|
15
|
-
addItem: (item) => {
|
16
|
-
cartInstance.addItem(item);
|
17
|
-
sync();
|
18
|
-
},
|
19
|
-
removeItem: (id) => {
|
20
|
-
cartInstance.removeItem(id);
|
21
|
-
sync();
|
22
|
-
},
|
23
|
-
getItems: (category) => {
|
24
|
-
cartInstance.getItems(category);
|
25
|
-
},
|
26
|
-
clear: () => {
|
27
|
-
cartInstance.clear();
|
28
|
-
sync();
|
29
|
-
},
|
30
|
-
total: cartInstance.getTotal()
|
31
|
-
};
|
32
|
-
useEffect(() => {
|
33
|
-
const handleSync = () => sync();
|
34
|
-
window.addEventListener("storage", handleSync);
|
35
|
-
return () => window.removeEventListener("storage", handleSync);
|
36
|
-
}, []);
|
37
|
-
return /* @__PURE__ */ jsx(CartContext.Provider, { value: api, children });
|
38
|
-
};
|
39
|
-
var useCart = () => {
|
40
|
-
const ctx = useContext(CartContext);
|
41
|
-
if (!ctx) throw new Error("useCart must be used within CartProvider");
|
42
|
-
return ctx;
|
43
|
-
};
|
44
|
-
|
45
|
-
export {
|
46
|
-
CartProvider,
|
47
|
-
useCart
|
48
|
-
};
|