@tapcart/mobile-components 0.11.1 → 0.11.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"use-block-conditional-rendering.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-block-conditional-rendering.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,YAAY,EAGb,MAAM,kBAAkB,CAAA;AAczB,eAAO,MAAM,4BAA4B,WAC/B;IACN,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,eAAe,EAAE,GAAG,CAAA;IACpB,iBAAiB,EAAE,GAAG,CAAA;CACvB,UACO,YAAY;;;CA8NrB,CAAA"}
1
+ {"version":3,"file":"use-block-conditional-rendering.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-block-conditional-rendering.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,YAAY,EAGb,MAAM,kBAAkB,CAAA;AAczB,eAAO,MAAM,4BAA4B,WAC/B;IACN,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,eAAe,EAAE,GAAG,CAAA;IACpB,iBAAiB,EAAE,GAAG,CAAA;CACvB,UACO,YAAY;;;CAqPrB,CAAA"}
@@ -16,12 +16,10 @@ import { useCollection } from "./use-collection";
16
16
  import { useSearchParams } from "next/navigation";
17
17
  import { gidFromId, countNumberOfTagsInState, getEnvState, shouldShowBlock, evaluateConditions, } from "../../lib/utils";
18
18
  export const useBlockConditionalRendering = (_props, _block) => {
19
- var _a, _b, _c, _d, _e;
20
- const _f = ((_a = _block === null || _block === void 0 ? void 0 : _block.visibilityConditions) === null || _a === void 0 ? void 0 : _a.conditions) || {}, { enabled: conditionalsV1IsEnabled = false, exclude: isInverse = false } = _f, restOfProps = __rest(_f, ["enabled", "exclude"]);
19
+ var _a, _b, _c, _d, _e, _f;
20
+ const _g = ((_a = _block === null || _block === void 0 ? void 0 : _block.visibilityConditions) === null || _a === void 0 ? void 0 : _a.conditions) || {}, { enabled: conditionalsV1IsEnabled = false, exclude: isInverse = false } = _g, restOfProps = __rest(_g, ["enabled", "exclude"]);
21
21
  const { _version = 1, conditions, enabled: conditionalsV2IsEnabled = false, } = (_block === null || _block === void 0 ? void 0 : _block.visibilityConditions) || {};
22
- if (!conditionalsV1IsEnabled && !conditionalsV2IsEnabled) {
23
- return { shouldShow: true, isLoading: false };
24
- }
22
+ const isConditionalsEnabled = conditionalsV1IsEnabled || conditionalsV2IsEnabled;
25
23
  const blockState = restOfProps;
26
24
  const { appId = "", apiUrl = "", deviceVariables, customerVariables } = _props;
27
25
  const searchParams = useSearchParams();
@@ -29,6 +27,7 @@ export const useBlockConditionalRendering = (_props, _block) => {
29
27
  const [language = "en", country = "US"] = ((_b = deviceVariables === null || deviceVariables === void 0 ? void 0 : deviceVariables.locale) === null || _b === void 0 ? void 0 : _b.split("_")) || [];
30
28
  const { id: deviceId = "" } = deviceVariables || {};
31
29
  const productId = (_c = searchParams === null || searchParams === void 0 ? void 0 : searchParams.get("productId")) !== null && _c !== void 0 ? _c : undefined;
30
+ const productHandle = (_d = searchParams === null || searchParams === void 0 ? void 0 : searchParams.get("productHandle")) !== null && _d !== void 0 ? _d : undefined;
32
31
  const location = {
33
32
  country,
34
33
  language,
@@ -36,6 +35,9 @@ export const useBlockConditionalRendering = (_props, _block) => {
36
35
  };
37
36
  const productMetafieldsQuery = useMemo(() => {
38
37
  var _a;
38
+ if (!isConditionalsEnabled) {
39
+ return [];
40
+ }
39
41
  if (conditionalsV1IsEnabled && (blockState === null || blockState === void 0 ? void 0 : blockState.productMetafield)) {
40
42
  return blockState.productMetafield;
41
43
  }
@@ -60,20 +62,26 @@ export const useBlockConditionalRendering = (_props, _block) => {
60
62
  conditionalsV1IsEnabled,
61
63
  conditionalsV2IsEnabled,
62
64
  _block === null || _block === void 0 ? void 0 : _block.visibilityConditions,
65
+ isConditionalsEnabled,
63
66
  ]);
64
- // Fetch product if productId is present
65
- const { products, error: useProductsError, isLoading: isProductsLoading, } = useProducts({
66
- productIds: productId !== undefined ? [gidFromId(productId)] : [],
67
- baseURL: apiUrl,
68
- productHandles: [],
69
- metafields: productMetafieldsQuery,
70
- queryVariables: {
71
- language,
72
- country,
73
- },
74
- });
67
+ const shouldFetchProduct = isConditionalsEnabled && (productId || productHandle);
68
+ const { products, error: useProductsError, isLoading: isProductsLoading, } = useProducts(shouldFetchProduct
69
+ ? {
70
+ productIds: productId ? [gidFromId(productId)] : [],
71
+ baseURL: apiUrl,
72
+ productHandles: productHandle ? [productHandle] : [],
73
+ metafields: productMetafieldsQuery,
74
+ queryVariables: {
75
+ language,
76
+ country,
77
+ },
78
+ }
79
+ : null);
75
80
  const blockCollectionMetafields = useMemo(() => {
76
81
  var _a;
82
+ if (!isConditionalsEnabled) {
83
+ return [];
84
+ }
77
85
  if (conditionalsV1IsEnabled && (blockState === null || blockState === void 0 ? void 0 : blockState.collectionMetafield)) {
78
86
  return blockState.collectionMetafield;
79
87
  }
@@ -98,35 +106,47 @@ export const useBlockConditionalRendering = (_props, _block) => {
98
106
  conditionalsV1IsEnabled,
99
107
  conditionalsV2IsEnabled,
100
108
  _block === null || _block === void 0 ? void 0 : _block.visibilityConditions,
109
+ isConditionalsEnabled,
101
110
  ]);
102
- const collectionMetafieldsQuery = useMemo(() => blockCollectionMetafields.map((item) => {
103
- // these are the fields used in the query.
104
- return {
105
- namespace: item.namespace,
106
- key: item.key,
107
- };
108
- }), [blockCollectionMetafields]);
109
- const memoizedMetafields = useMemo(() => collectionMetafieldsQuery
110
- ? collectionMetafieldsQuery
111
+ const collectionMetafieldsQuery = useMemo(() => {
112
+ if (!blockCollectionMetafields.length) {
113
+ return [];
114
+ }
115
+ return blockCollectionMetafields.map((item) => {
116
+ // these are the fields used in the query.
117
+ return {
118
+ namespace: item.namespace,
119
+ key: item.key,
120
+ };
121
+ });
122
+ }, [blockCollectionMetafields]);
123
+ const memoizedMetafields = useMemo(() => {
124
+ if (!isConditionalsEnabled || !collectionMetafieldsQuery.length) {
125
+ return undefined;
126
+ }
127
+ return collectionMetafieldsQuery
111
128
  .map((m) => `${m.namespace}.${m.key}`)
112
- .join(",")
113
- : undefined, [collectionMetafieldsQuery]);
114
- const collectionId = (_d = searchParams === null || searchParams === void 0 ? void 0 : searchParams.get("collectionId")) !== null && _d !== void 0 ? _d : undefined;
115
- const collectionHandle = (_e = searchParams === null || searchParams === void 0 ? void 0 : searchParams.get("collectionHandle")) !== null && _e !== void 0 ? _e : undefined;
129
+ .join(",");
130
+ }, [collectionMetafieldsQuery, isConditionalsEnabled]);
131
+ const collectionId = (_e = searchParams === null || searchParams === void 0 ? void 0 : searchParams.get("collectionId")) !== null && _e !== void 0 ? _e : undefined;
132
+ const collectionHandle = (_f = searchParams === null || searchParams === void 0 ? void 0 : searchParams.get("collectionHandle")) !== null && _f !== void 0 ? _f : undefined;
133
+ const shouldFetchCollection = isConditionalsEnabled && (collectionId || collectionHandle);
116
134
  const { specificCollection = {}, error: useCollectionError, loading: isCollectionLoading, } = useCollection({
117
135
  appId,
118
136
  apiUrl,
119
- collectionId,
120
- collectionHandle,
137
+ collectionId: shouldFetchCollection ? collectionId : undefined,
138
+ collectionHandle: shouldFetchCollection ? collectionHandle : undefined,
121
139
  language: location === null || location === void 0 ? void 0 : location.language,
122
- metafields: memoizedMetafields,
140
+ metafields: shouldFetchCollection ? memoizedMetafields : undefined,
123
141
  });
124
142
  const isLoading = isProductsLoading || isCollectionLoading;
125
143
  if (useProductsError || useCollectionError) {
126
144
  console.error("Unable to load products in conditional block rendering hook: ", useProductsError !== null && useProductsError !== void 0 ? useProductsError : useCollectionError);
127
145
  }
146
+ if (!isConditionalsEnabled) {
147
+ return { shouldShow: true, isLoading: false };
148
+ }
128
149
  let shouldShow = true;
129
- const blockConditionalsIsEnabled = conditionalsV1IsEnabled || conditionalsV2IsEnabled;
130
150
  const blockHasTags = countNumberOfTagsInState(blockState) > 0;
131
151
  const product = products.length === 1 ? products[0] : undefined;
132
152
  const envState = getEnvState({
@@ -150,7 +170,7 @@ export const useBlockConditionalRendering = (_props, _block) => {
150
170
  return evaluateConditions(conditions, envState);
151
171
  };
152
172
  try {
153
- if (blockConditionalsIsEnabled) {
173
+ if (isConditionalsEnabled) {
154
174
  switch (_version) {
155
175
  case 2:
156
176
  shouldShow = evaluateV2Conditions();
@@ -1 +1 @@
1
- {"version":3,"file":"use-infinite-scroll.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-infinite-scroll.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,uBAAuB,EAAmB,MAAM,iBAAiB,CAAA;AAE1E,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAE5D,UAAU,QAAQ;IAChB,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,GAAG,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAA;CACxC;AAED,UAAU,sBAAsB;IAE9B,YAAY,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAA;IAGxC,WAAW,CAAC,EAAE,QAAQ,CAAA;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAGpC,SAAS,CAAC,EAAE,UAAU,GAAG,YAAY,CAAA;IACrC,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,aAAa,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;IAChD,YAAY,CAAC,EAAE,CACb,SAAS,EAAE,MAAM,EACjB,gBAAgB,EAAE,GAAG,GAAG,IAAI,EAC5B,GAAG,I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+65,22 @@ customFetcher, customGetKey, }) => {
65
65
  return Boolean((searchParams === null || searchParams === void 0 ? void 0 : searchParams.get("collectionId")) ||
66
66
  (searchParams === null || searchParams === void 0 ? void 0 : searchParams.get("collectionHandle")) ||
67
67
  handle ||
68
- id);
69
- }, [searchParams, handle, id]);
68
+ id ||
69
+ (queryVariableProps === null || queryVariableProps === void 0 ? void 0 : queryVariableProps.collectionId) ||
70
+ (queryVariableProps === null || queryVariableProps === void 0 ? void 0 : queryVariableProps.collectionHandle));
71
+ }, [
72
+ searchParams,
73
+ handle,
74
+ id,
75
+ queryVariableProps === null || queryVariableProps === void 0 ? void 0 : queryVariableProps.collectionId,
76
+ queryVariableProps === null || queryVariableProps === void 0 ? void 0 : queryVariableProps.collectionHandle,
77
+ ]);
70
78
  const hasQuery = useMemo(() => {
71
- return Boolean(searchParams === null || searchParams === void 0 ? void 0 : searchParams.get("searchQuery")) || query;
72
- }, [searchParams, query]);
73
- const shouldSkipSearchClientFetch = usingSearchClient && !hasCollection && !hasQuery;
79
+ return (Boolean(searchParams === null || searchParams === void 0 ? void 0 : searchParams.get("searchQuery")) ||
80
+ query ||
81
+ (queryVariableProps === null || queryVariableProps === void 0 ? void 0 : queryVariableProps.searchQuery));
82
+ }, [searchParams, query, queryVariableProps === null || queryVariableProps === void 0 ? void 0 : queryVariableProps.searchQuery]);
83
+ const shouldSkipFetch = !hasCollection && !hasQuery;
74
84
  // Search client approach - getKey and fetcher
75
85
  const searchClientGetKey = useMemo(() => customGetKey || (searchClient === null || searchClient === void 0 ? void 0 : searchClient.getKey), [customGetKey, searchClient === null || searchClient === void 0 ? void 0 : searchClient.getKey]);
76
86
  const searchClientFetcher = useMemo(() => customFetcher || (searchClient === null || searchClient === void 0 ? void 0 : searchClient.fetcher), [customFetcher, searchClient === null || searchClient === void 0 ? void 0 : searchClient.fetcher]);
@@ -106,17 +116,17 @@ customFetcher, customGetKey, }) => {
106
116
  // Determine which approach to use
107
117
  const getKey = usingSearchClient
108
118
  ? (pageIndex, previousPageData) => {
109
- if (shouldSkipSearchClientFetch)
110
- return null;
111
119
  if (!searchClientGetKey)
112
120
  return null;
113
121
  return searchClientGetKey(pageIndex, previousPageData);
114
122
  }
115
- : (pageIndex, previousPageData) => (customGetKey || apiGetKey)(pageIndex, previousPageData, queryVariables !== null && queryVariables !== void 0 ? queryVariables : {});
123
+ : (pageIndex, previousPageData) => {
124
+ return (customGetKey || apiGetKey)(pageIndex, previousPageData, queryVariables !== null && queryVariables !== void 0 ? queryVariables : {});
125
+ };
116
126
  const fetcher = usingSearchClient
117
127
  ? (...args) => __awaiter(void 0, void 0, void 0, function* () {
118
128
  var _h, _j;
119
- if (shouldSkipSearchClientFetch)
129
+ if (shouldSkipFetch)
120
130
  return null;
121
131
  if (!searchClientFetcher)
122
132
  return null;
@@ -124,7 +134,12 @@ customFetcher, customGetKey, }) => {
124
134
  productCount.current += (_j = (_h = result === null || result === void 0 ? void 0 : result.products) === null || _h === void 0 ? void 0 : _h.length) !== null && _j !== void 0 ? _j : 0;
125
135
  return result;
126
136
  })
127
- : customFetcher || apiFetcher;
137
+ : (...args) => __awaiter(void 0, void 0, void 0, function* () {
138
+ if (shouldSkipFetch)
139
+ return null;
140
+ const effectiveFetcher = customFetcher || apiFetcher;
141
+ return effectiveFetcher(...args);
142
+ });
128
143
  const { data, error, size, setSize, isLoading, isValidating, mutate, } = useSWRInfinite(getKey, fetcher, {
129
144
  revalidateFirstPage: false,
130
145
  initialSize: 1,
@@ -190,7 +205,7 @@ customFetcher, customGetKey, }) => {
190
205
  return data.map((page) => { var _a; return (_a = page === null || page === void 0 ? void 0 : page.integrationResponse) !== null && _a !== void 0 ? _a : null; });
191
206
  }, [data, usingSearchClient]);
192
207
  // Elegant conditional overrides when skipping
193
- const applySkip = (value, override) => shouldSkipSearchClientFetch ? override : value;
208
+ const applySkip = useCallback((value, override) => (shouldSkipFetch ? override : value), [shouldSkipFetch]);
194
209
  return useMemo(() => ({
195
210
  data,
196
211
  error,
@@ -215,7 +230,7 @@ customFetcher, customGetKey, }) => {
215
230
  integrationResponses,
216
231
  isLoading,
217
232
  isValidating,
218
- shouldSkipSearchClientFetch,
233
+ applySkip,
219
234
  ]);
220
235
  };
221
236
  export { useInfiniteScroll, constructURL };
@@ -1 +1 @@
1
- {"version":3,"file":"money.d.ts","sourceRoot":"","sources":["../../../components/ui/money.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAEjE,UAAU,SAAS;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;CACd;AAED,QAAA,MAAM,aAAa,gGAMjB,CAAA;AAEF,MAAM,WAAW,UACf,SAAQ,SAAS,EACf,YAAY,CAAC,OAAO,aAAa,CAAC;IACpC,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,MAAM,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;CAC7B;AAED,iBAAS,KAAK,CAAC,EACb,KAAK,EACL,MAAM,EACN,QAAQ,EACR,aAAqB,EACrB,MAAM,EACN,GAAG,KAAK,EACT,EAAE,UAAU,2CA6BZ;AAED,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,CAAA"}
1
+ {"version":3,"file":"money.d.ts","sourceRoot":"","sources":["../../../components/ui/money.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAGjE,UAAU,SAAS;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;CACd;AAED,QAAA,MAAM,aAAa,gGAMjB,CAAA;AAEF,MAAM,WAAW,UACf,SAAQ,SAAS,EACf,YAAY,CAAC,OAAO,aAAa,CAAC;IACpC,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,MAAM,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;CAC7B;AAED,iBAAS,KAAK,CAAC,EACb,KAAK,EACL,MAAM,EACN,QAAQ,EACR,aAAqB,EACrB,MAAM,EACN,GAAG,KAAK,EACT,EAAE,UAAU,2CAgCZ;AAED,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,CAAA"}
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  var __rest = (this && this.__rest) || function (s, e) {
2
3
  var t = {};
3
4
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -12,6 +13,7 @@ var __rest = (this && this.__rest) || function (s, e) {
12
13
  import { jsx as _jsx } from "react/jsx-runtime";
13
14
  import * as React from "react";
14
15
  import { cva } from "class-variance-authority";
16
+ import { usePathname } from "next/navigation";
15
17
  const moneyVariants = cva("", {
16
18
  variants: {},
17
19
  defaultVariants: {
@@ -20,8 +22,12 @@ const moneyVariants = cva("", {
20
22
  },
21
23
  });
22
24
  function Money(_a) {
25
+ var _b, _c;
23
26
  var { price, locale, currency, hideZeroCents = false, styles } = _a, props = __rest(_a, ["price", "locale", "currency", "hideZeroCents", "styles"]);
24
- let language = locale;
27
+ // Only use routeLocale if it contains a hyphen (e.g., "en-US")
28
+ const routeLocale = ((_c = (_b = usePathname()) === null || _b === void 0 ? void 0 : _b.split("/")) === null || _c === void 0 ? void 0 : _c.pop()) || "";
29
+ const isValidLocale = routeLocale && routeLocale.includes("-");
30
+ let language = isValidLocale ? routeLocale : locale;
25
31
  // Fix for when we want to format in USD in english
26
32
  // but language only contains two letter region
27
33
  if (currency === "USD" && !(locale === null || locale === void 0 ? void 0 : locale.includes("-"))) {
@@ -31,7 +37,7 @@ function Money(_a) {
31
37
  style: "currency",
32
38
  currency: currency,
33
39
  currencyDisplay: "narrowSymbol",
34
- }), [locale, currency]);
40
+ }), [language, currency]);
35
41
  const formattedPrice = React.useMemo(() => {
36
42
  const formatted = formatter.format(Number(price));
37
43
  return hideZeroCents ? formatted.replace(/(\.|,)00$/, "") : formatted;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tapcart/mobile-components",
3
- "version": "0.11.1",
3
+ "version": "0.11.3",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "style": "dist/styles.css",