@ravishranjan/cart 2.0.6 → 2.0.7
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/chunk-K3ENNZKF.mjs +15 -0
- package/dist/react/CartContext.d.mts +10 -2
- package/dist/react/CartContext.d.ts +10 -2
- package/dist/react/index.d.mts +1 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +5 -5
- package/dist/react/index.mjs +1 -1
- package/dist/react/useCart.d.mts +6 -1
- package/dist/react/useCart.d.ts +6 -1
- package/dist/react/useCart.js +5 -5
- package/dist/react/useCart.mjs +1 -1
- package/package.json +1 -1
@@ -0,0 +1,15 @@
|
|
1
|
+
import {
|
2
|
+
CartContext
|
3
|
+
} from "./chunk-3AB6KTDB.mjs";
|
4
|
+
|
5
|
+
// src/react/useCart.tsx
|
6
|
+
import { useContext } from "react";
|
7
|
+
function useCart() {
|
8
|
+
const context = useContext(CartContext);
|
9
|
+
if (!context) throw new Error("useCart must be used within CartProvider");
|
10
|
+
return context;
|
11
|
+
}
|
12
|
+
|
13
|
+
export {
|
14
|
+
useCart
|
15
|
+
};
|
@@ -1,9 +1,17 @@
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
2
2
|
import * as react from 'react';
|
3
|
+
import { CartItem } from '../core/cart.mjs';
|
3
4
|
|
4
|
-
|
5
|
+
type CartContextType = {
|
6
|
+
cart: CartItem[];
|
7
|
+
addItem: (item: CartItem) => void;
|
8
|
+
removeItem: (id: string | number) => void;
|
9
|
+
clear: () => void;
|
10
|
+
total: number;
|
11
|
+
};
|
12
|
+
declare const CartContext: react.Context<CartContextType | null>;
|
5
13
|
declare const CartProvider: ({ children }: {
|
6
14
|
children: React.ReactNode;
|
7
15
|
}) => react_jsx_runtime.JSX.Element;
|
8
16
|
|
9
|
-
export { CartContext, CartProvider };
|
17
|
+
export { CartContext, type CartContextType, CartProvider };
|
@@ -1,9 +1,17 @@
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
2
2
|
import * as react from 'react';
|
3
|
+
import { CartItem } from '../core/cart.js';
|
3
4
|
|
4
|
-
|
5
|
+
type CartContextType = {
|
6
|
+
cart: CartItem[];
|
7
|
+
addItem: (item: CartItem) => void;
|
8
|
+
removeItem: (id: string | number) => void;
|
9
|
+
clear: () => void;
|
10
|
+
total: number;
|
11
|
+
};
|
12
|
+
declare const CartContext: react.Context<CartContextType | null>;
|
5
13
|
declare const CartProvider: ({ children }: {
|
6
14
|
children: React.ReactNode;
|
7
15
|
}) => react_jsx_runtime.JSX.Element;
|
8
16
|
|
9
|
-
export { CartContext, CartProvider };
|
17
|
+
export { CartContext, type CartContextType, CartProvider };
|
package/dist/react/index.d.mts
CHANGED
package/dist/react/index.d.ts
CHANGED
package/dist/react/index.js
CHANGED
@@ -118,11 +118,11 @@ var CartProvider = ({ children }) => {
|
|
118
118
|
};
|
119
119
|
|
120
120
|
// src/react/useCart.tsx
|
121
|
-
|
122
|
-
const
|
123
|
-
if (!
|
124
|
-
return
|
125
|
-
}
|
121
|
+
function useCart() {
|
122
|
+
const context = (0, import_react2.useContext)(CartContext);
|
123
|
+
if (!context) throw new Error("useCart must be used within CartProvider");
|
124
|
+
return context;
|
125
|
+
}
|
126
126
|
// Annotate the CommonJS export names for ESM import in node:
|
127
127
|
0 && (module.exports = {
|
128
128
|
CartProvider,
|
package/dist/react/index.mjs
CHANGED
package/dist/react/useCart.d.mts
CHANGED
package/dist/react/useCart.d.ts
CHANGED
package/dist/react/useCart.js
CHANGED
@@ -31,11 +31,11 @@ var import_jsx_runtime = require("react/jsx-runtime");
|
|
31
31
|
var CartContext = (0, import_react.createContext)(null);
|
32
32
|
|
33
33
|
// src/react/useCart.tsx
|
34
|
-
|
35
|
-
const
|
36
|
-
if (!
|
37
|
-
return
|
38
|
-
}
|
34
|
+
function useCart() {
|
35
|
+
const context = (0, import_react2.useContext)(CartContext);
|
36
|
+
if (!context) throw new Error("useCart must be used within CartProvider");
|
37
|
+
return context;
|
38
|
+
}
|
39
39
|
// Annotate the CommonJS export names for ESM import in node:
|
40
40
|
0 && (module.exports = {
|
41
41
|
useCart
|
package/dist/react/useCart.mjs
CHANGED