@gem-sdk/core 1.10.42 → 1.11.0
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/cjs/contexts/ProductContext.js +2 -2
- package/dist/cjs/helpers/variant.js +8 -0
- package/dist/cjs/hooks/useProduct.js +4 -8
- package/dist/esm/contexts/ProductContext.js +1 -1
- package/dist/esm/helpers/variant.js +6 -0
- package/dist/esm/hooks/useProduct.js +2 -5
- package/dist/types/index.d.ts +69 -0
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
4
4
|
var zustand = require('zustand');
|
|
5
5
|
var react = require('react');
|
|
6
6
|
var flattenConnection = require('../helpers/flatten-connection.js');
|
|
7
|
-
var
|
|
7
|
+
var variant = require('../helpers/variant.js');
|
|
8
8
|
|
|
9
9
|
// const { Provider, useStore } = createContext<StoreApi<ProductContextProps>>();
|
|
10
10
|
const ProductContext = /*#__PURE__*/ react.createContext(null);
|
|
@@ -104,7 +104,7 @@ const ProductProvider = ({ children , product , initialVariantId , quantity =1
|
|
|
104
104
|
if (product) {
|
|
105
105
|
const variants = flattenConnection.flattenConnection(product.variants);
|
|
106
106
|
const firstVariant = variants[0];
|
|
107
|
-
const firstVariantInStock = variants.find((item)=>
|
|
107
|
+
const firstVariantInStock = variants.find((item)=>variant.checkInStock(item));
|
|
108
108
|
const initialVariant = variants.find((v)=>v?.id === initialVariantId) ?? firstVariantInStock ?? firstVariant;
|
|
109
109
|
selectedOptions = initialVariant?.selectedOptions.reduce((acc, option)=>{
|
|
110
110
|
if (option.name) {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function checkInStock(variant) {
|
|
4
|
+
if (!variant) return false;
|
|
5
|
+
return variant?.inventoryQuantity && variant.inventoryQuantity > 0 || !variant?.manageInventory || variant.inventoryPolicy === 'CONTINUE';
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
exports.checkInStock = checkInStock;
|
|
@@ -6,6 +6,7 @@ var flattenConnection = require('../helpers/flatten-connection.js');
|
|
|
6
6
|
require('swr');
|
|
7
7
|
var product = require('../helpers/product.js');
|
|
8
8
|
require('../helpers/convert.js');
|
|
9
|
+
var variant = require('../helpers/variant.js');
|
|
9
10
|
|
|
10
11
|
const useUniqProductID = ()=>{
|
|
11
12
|
return ProductContext.useProductStore((s)=>s.uiqueId);
|
|
@@ -81,13 +82,9 @@ const useCurrentVariant = ()=>{
|
|
|
81
82
|
variants
|
|
82
83
|
]);
|
|
83
84
|
};
|
|
84
|
-
function checkInStock(variant) {
|
|
85
|
-
if (!variant) return false;
|
|
86
|
-
return variant?.inventoryQuantity && variant.inventoryQuantity > 0 || !variant?.manageInventory || variant.inventoryPolicy === 'CONTINUE';
|
|
87
|
-
}
|
|
88
85
|
const useCurrentVariantInStock = ()=>{
|
|
89
86
|
const currentVariant = useCurrentVariant();
|
|
90
|
-
const isInStock = checkInStock(currentVariant);
|
|
87
|
+
const isInStock = variant.checkInStock(currentVariant);
|
|
91
88
|
return isInStock;
|
|
92
89
|
};
|
|
93
90
|
const useVariantOutStock = (optionId, optionValue)=>{
|
|
@@ -97,7 +94,7 @@ const useVariantOutStock = (optionId, optionValue)=>{
|
|
|
97
94
|
...selectedOptions,
|
|
98
95
|
[optionId]: optionValue
|
|
99
96
|
});
|
|
100
|
-
const isInStock = checkInStock(matchedVariant);
|
|
97
|
+
const isInStock = variant.checkInStock(matchedVariant);
|
|
101
98
|
return !isInStock;
|
|
102
99
|
};
|
|
103
100
|
const useCheckAvailableVariantInStock = (optionId, optionValue)=>{
|
|
@@ -107,7 +104,7 @@ const useCheckAvailableVariantInStock = (optionId, optionValue)=>{
|
|
|
107
104
|
if (item) {
|
|
108
105
|
const { selectedOptions } = item;
|
|
109
106
|
const opt = selectedOptions?.find((option)=>option?.name === optionId && option.value === optionValue);
|
|
110
|
-
const isInStock = checkInStock(item);
|
|
107
|
+
const isInStock = variant.checkInStock(item);
|
|
111
108
|
if (opt && isInStock) {
|
|
112
109
|
available = true;
|
|
113
110
|
}
|
|
@@ -116,7 +113,6 @@ const useCheckAvailableVariantInStock = (optionId, optionValue)=>{
|
|
|
116
113
|
return available;
|
|
117
114
|
};
|
|
118
115
|
|
|
119
|
-
exports.checkInStock = checkInStock;
|
|
120
116
|
exports.useCheckAvailableVariantInStock = useCheckAvailableVariantInStock;
|
|
121
117
|
exports.useCurrentVariant = useCurrentVariant;
|
|
122
118
|
exports.useCurrentVariantInStock = useCurrentVariantInStock;
|
|
@@ -2,7 +2,7 @@ import { jsx, Fragment } from 'react/jsx-runtime';
|
|
|
2
2
|
import { useStore, createStore } from 'zustand';
|
|
3
3
|
import { useId, useMemo, useContext, createContext } from 'react';
|
|
4
4
|
import { flattenConnection } from '../helpers/flatten-connection.js';
|
|
5
|
-
import { checkInStock } from '../
|
|
5
|
+
import { checkInStock } from '../helpers/variant.js';
|
|
6
6
|
|
|
7
7
|
// const { Provider, useStore } = createContext<StoreApi<ProductContextProps>>();
|
|
8
8
|
const ProductContext = /*#__PURE__*/ createContext(null);
|
|
@@ -4,6 +4,7 @@ import { flattenConnection } from '../helpers/flatten-connection.js';
|
|
|
4
4
|
import 'swr';
|
|
5
5
|
import { getSelectedVariant } from '../helpers/product.js';
|
|
6
6
|
import '../helpers/convert.js';
|
|
7
|
+
import { checkInStock } from '../helpers/variant.js';
|
|
7
8
|
|
|
8
9
|
const useUniqProductID = ()=>{
|
|
9
10
|
return useProductStore((s)=>s.uiqueId);
|
|
@@ -79,10 +80,6 @@ const useCurrentVariant = ()=>{
|
|
|
79
80
|
variants
|
|
80
81
|
]);
|
|
81
82
|
};
|
|
82
|
-
function checkInStock(variant) {
|
|
83
|
-
if (!variant) return false;
|
|
84
|
-
return variant?.inventoryQuantity && variant.inventoryQuantity > 0 || !variant?.manageInventory || variant.inventoryPolicy === 'CONTINUE';
|
|
85
|
-
}
|
|
86
83
|
const useCurrentVariantInStock = ()=>{
|
|
87
84
|
const currentVariant = useCurrentVariant();
|
|
88
85
|
const isInStock = checkInStock(currentVariant);
|
|
@@ -114,4 +111,4 @@ const useCheckAvailableVariantInStock = (optionId, optionValue)=>{
|
|
|
114
111
|
return available;
|
|
115
112
|
};
|
|
116
113
|
|
|
117
|
-
export {
|
|
114
|
+
export { useCheckAvailableVariantInStock, useCurrentVariant, useCurrentVariantInStock, useFeaturedImageGlobal, useProduct, useProductProperties, useQuantity, useSelectedOption, useUniqProductID, useVariant, useVariantOutStock, useVariants };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -4111,6 +4111,7 @@ type Product = {
|
|
|
4111
4111
|
baseID?: Maybe<Scalars['String']>;
|
|
4112
4112
|
collections?: Maybe<CollectionConnection>;
|
|
4113
4113
|
createdAt?: Maybe<Scalars['Time']>;
|
|
4114
|
+
currencyCode?: Maybe<Scalars['String']>;
|
|
4114
4115
|
currentVersion?: Maybe<Scalars['String']>;
|
|
4115
4116
|
deletedAt?: Maybe<Scalars['Time']>;
|
|
4116
4117
|
description?: Maybe<Scalars['String']>;
|
|
@@ -4939,6 +4940,22 @@ type ProductWhereInput = {
|
|
|
4939
4940
|
createdAtLTE?: InputMaybe<Scalars['Time']>;
|
|
4940
4941
|
createdAtNEQ?: InputMaybe<Scalars['Time']>;
|
|
4941
4942
|
createdAtNotIn?: InputMaybe<Array<Scalars['Time']>>;
|
|
4943
|
+
/** currency_code field predicates */
|
|
4944
|
+
currencyCode?: InputMaybe<Scalars['String']>;
|
|
4945
|
+
currencyCodeContains?: InputMaybe<Scalars['String']>;
|
|
4946
|
+
currencyCodeContainsFold?: InputMaybe<Scalars['String']>;
|
|
4947
|
+
currencyCodeEqualFold?: InputMaybe<Scalars['String']>;
|
|
4948
|
+
currencyCodeGT?: InputMaybe<Scalars['String']>;
|
|
4949
|
+
currencyCodeGTE?: InputMaybe<Scalars['String']>;
|
|
4950
|
+
currencyCodeHasPrefix?: InputMaybe<Scalars['String']>;
|
|
4951
|
+
currencyCodeHasSuffix?: InputMaybe<Scalars['String']>;
|
|
4952
|
+
currencyCodeIn?: InputMaybe<Array<Scalars['String']>>;
|
|
4953
|
+
currencyCodeIsNil?: InputMaybe<Scalars['Boolean']>;
|
|
4954
|
+
currencyCodeLT?: InputMaybe<Scalars['String']>;
|
|
4955
|
+
currencyCodeLTE?: InputMaybe<Scalars['String']>;
|
|
4956
|
+
currencyCodeNEQ?: InputMaybe<Scalars['String']>;
|
|
4957
|
+
currencyCodeNotIn?: InputMaybe<Array<Scalars['String']>>;
|
|
4958
|
+
currencyCodeNotNil?: InputMaybe<Scalars['Boolean']>;
|
|
4942
4959
|
/** current_version field predicates */
|
|
4943
4960
|
currentVersion?: InputMaybe<Scalars['String']>;
|
|
4944
4961
|
currentVersionContains?: InputMaybe<Scalars['String']>;
|
|
@@ -6220,6 +6237,56 @@ type SelectedOption = {
|
|
|
6220
6237
|
optionType?: Maybe<Scalars['String']>;
|
|
6221
6238
|
value?: Maybe<Scalars['String']>;
|
|
6222
6239
|
};
|
|
6240
|
+
/**
|
|
6241
|
+
* ShopDatabaseWhereInput is used for filtering ShopDatabase objects.
|
|
6242
|
+
* Input was generated by ent.
|
|
6243
|
+
*/
|
|
6244
|
+
type ShopDatabaseWhereInput = {
|
|
6245
|
+
and?: InputMaybe<Array<ShopDatabaseWhereInput>>;
|
|
6246
|
+
/** created_at field predicates */
|
|
6247
|
+
createdAt?: InputMaybe<Scalars['Time']>;
|
|
6248
|
+
createdAtGT?: InputMaybe<Scalars['Time']>;
|
|
6249
|
+
createdAtGTE?: InputMaybe<Scalars['Time']>;
|
|
6250
|
+
createdAtIn?: InputMaybe<Array<Scalars['Time']>>;
|
|
6251
|
+
createdAtLT?: InputMaybe<Scalars['Time']>;
|
|
6252
|
+
createdAtLTE?: InputMaybe<Scalars['Time']>;
|
|
6253
|
+
createdAtNEQ?: InputMaybe<Scalars['Time']>;
|
|
6254
|
+
createdAtNotIn?: InputMaybe<Array<Scalars['Time']>>;
|
|
6255
|
+
/** database field predicates */
|
|
6256
|
+
database?: InputMaybe<Scalars['String']>;
|
|
6257
|
+
databaseContains?: InputMaybe<Scalars['String']>;
|
|
6258
|
+
databaseContainsFold?: InputMaybe<Scalars['String']>;
|
|
6259
|
+
databaseEqualFold?: InputMaybe<Scalars['String']>;
|
|
6260
|
+
databaseGT?: InputMaybe<Scalars['String']>;
|
|
6261
|
+
databaseGTE?: InputMaybe<Scalars['String']>;
|
|
6262
|
+
databaseHasPrefix?: InputMaybe<Scalars['String']>;
|
|
6263
|
+
databaseHasSuffix?: InputMaybe<Scalars['String']>;
|
|
6264
|
+
databaseIn?: InputMaybe<Array<Scalars['String']>>;
|
|
6265
|
+
databaseLT?: InputMaybe<Scalars['String']>;
|
|
6266
|
+
databaseLTE?: InputMaybe<Scalars['String']>;
|
|
6267
|
+
databaseNEQ?: InputMaybe<Scalars['String']>;
|
|
6268
|
+
databaseNotIn?: InputMaybe<Array<Scalars['String']>>;
|
|
6269
|
+
/** id field predicates */
|
|
6270
|
+
id?: InputMaybe<Scalars['ID']>;
|
|
6271
|
+
idGT?: InputMaybe<Scalars['ID']>;
|
|
6272
|
+
idGTE?: InputMaybe<Scalars['ID']>;
|
|
6273
|
+
idIn?: InputMaybe<Array<Scalars['ID']>>;
|
|
6274
|
+
idLT?: InputMaybe<Scalars['ID']>;
|
|
6275
|
+
idLTE?: InputMaybe<Scalars['ID']>;
|
|
6276
|
+
idNEQ?: InputMaybe<Scalars['ID']>;
|
|
6277
|
+
idNotIn?: InputMaybe<Array<Scalars['ID']>>;
|
|
6278
|
+
not?: InputMaybe<ShopDatabaseWhereInput>;
|
|
6279
|
+
or?: InputMaybe<Array<ShopDatabaseWhereInput>>;
|
|
6280
|
+
/** updated_at field predicates */
|
|
6281
|
+
updatedAt?: InputMaybe<Scalars['Time']>;
|
|
6282
|
+
updatedAtGT?: InputMaybe<Scalars['Time']>;
|
|
6283
|
+
updatedAtGTE?: InputMaybe<Scalars['Time']>;
|
|
6284
|
+
updatedAtIn?: InputMaybe<Array<Scalars['Time']>>;
|
|
6285
|
+
updatedAtLT?: InputMaybe<Scalars['Time']>;
|
|
6286
|
+
updatedAtLTE?: InputMaybe<Scalars['Time']>;
|
|
6287
|
+
updatedAtNEQ?: InputMaybe<Scalars['Time']>;
|
|
6288
|
+
updatedAtNotIn?: InputMaybe<Array<Scalars['Time']>>;
|
|
6289
|
+
};
|
|
6223
6290
|
/**
|
|
6224
6291
|
* ShopTokenWhereInput is used for filtering ShopToken objects.
|
|
6225
6292
|
* Input was generated by ent.
|
|
@@ -6625,6 +6692,7 @@ type shop_QueryPublishedThemePagesArgs = QueryPublishedThemePagesArgs;
|
|
|
6625
6692
|
type shop_Query_EntitiesArgs = Query_EntitiesArgs;
|
|
6626
6693
|
type shop_Scalars = Scalars;
|
|
6627
6694
|
type shop_SelectedOption = SelectedOption;
|
|
6695
|
+
type shop_ShopDatabaseWhereInput = ShopDatabaseWhereInput;
|
|
6628
6696
|
type shop_ShopTokenWhereInput = ShopTokenWhereInput;
|
|
6629
6697
|
type shop_StoreProperty = StoreProperty;
|
|
6630
6698
|
type shop_TagType = TagType;
|
|
@@ -6816,6 +6884,7 @@ declare namespace shop {
|
|
|
6816
6884
|
shop_Query_EntitiesArgs as Query_EntitiesArgs,
|
|
6817
6885
|
shop_Scalars as Scalars,
|
|
6818
6886
|
shop_SelectedOption as SelectedOption,
|
|
6887
|
+
shop_ShopDatabaseWhereInput as ShopDatabaseWhereInput,
|
|
6819
6888
|
shop_ShopTokenWhereInput as ShopTokenWhereInput,
|
|
6820
6889
|
shop_StoreProperty as StoreProperty,
|
|
6821
6890
|
shop_TagType as TagType,
|