@tapcart/mobile-components 0.8.41 → 0.8.42

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":"icon.d.ts","sourceRoot":"","sources":["../../../components/ui/icon.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAEL,eAAe,EAwChB,MAAM,qBAAqB,CAAA;AAI5B,QAAA,MAAM,YAAY;;;mFAiBjB,CAAA;AA8DD,MAAM,WAAW,SACf,SAAQ,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC,EACzD,YAAY,CAAC,OAAO,YAAY,CAAC;IACnC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC/B;AA0HD,iBAAS,IAAI,CAAC,EACZ,SAAS,EACT,IAAI,EACJ,IAAW,EACX,KAAK,EACL,GAAG,EACH,SAAS,EACT,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,cAAc,EACd,GAAG,KAAK,EACT,EAAE,SAAS,2CAoBX;AAED,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,eAAe,EAAE,CAAA"}
1
+ {"version":3,"file":"icon.d.ts","sourceRoot":"","sources":["../../../components/ui/icon.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAEL,eAAe,EAwChB,MAAM,qBAAqB,CAAA;AAI5B,QAAA,MAAM,YAAY;;;mFAiBjB,CAAA;AA8DD,MAAM,WAAW,SACf,SAAQ,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC,EACzD,YAAY,CAAC,OAAO,YAAY,CAAC;IACnC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC/B;AAyLD,iBAAS,IAAI,CAAC,EACZ,SAAS,EACT,IAAI,EACJ,IAAW,EACX,KAAK,EACL,GAAG,EACH,SAAS,EACT,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,cAAc,EACd,GAAG,KAAK,EACT,EAAE,SAAS,2CAoBX;AAED,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,eAAe,EAAE,CAAA"}
@@ -94,50 +94,87 @@ const TablerIcon = ({ name, size }) => {
94
94
  const CustomIcon = ({ url, size, color, strokeColor, strokeWidth, fillColor, fillPercentage, secondaryFillColor, }) => {
95
95
  return (_jsx(ReactSVG, { src: url, beforeInjection: (svg) => {
96
96
  svg.setAttribute("style", `width: ${sizeMapping[size]}px; height: ${sizeMapping[size]}px`);
97
+ const uniqueId = crypto.randomUUID();
98
+ const fillGradientId = `fill-gradient-${uniqueId}`;
99
+ const strokeGradientId = `stroke-gradient-${uniqueId}`;
100
+ const percentage = Math.min(Math.max(fillPercentage, 0), 1);
101
+ let defs = svg.querySelector("defs");
102
+ if (!defs) {
103
+ defs = document.createElementNS("http://www.w3.org/2000/svg", "defs");
104
+ svg.prepend(defs);
105
+ }
106
+ if (percentage > 0 && percentage < 1) {
107
+ const fillGradient = document.createElementNS("http://www.w3.org/2000/svg", "linearGradient");
108
+ fillGradient.setAttribute("id", fillGradientId);
109
+ fillGradient.setAttribute("x1", "0%");
110
+ fillGradient.setAttribute("y1", "0%");
111
+ fillGradient.setAttribute("x2", "100%");
112
+ fillGradient.setAttribute("y2", "0%");
113
+ const fillStop1 = document.createElementNS("http://www.w3.org/2000/svg", "stop");
114
+ fillStop1.setAttribute("offset", `${percentage * 100}%`);
115
+ fillStop1.setAttribute("stop-color", color || fillColor || "currentColor");
116
+ fillGradient.appendChild(fillStop1);
117
+ const fillStop2 = document.createElementNS("http://www.w3.org/2000/svg", "stop");
118
+ fillStop2.setAttribute("offset", `${percentage * 100}%`);
119
+ fillStop2.setAttribute("stop-color", secondaryFillColor || "transparent");
120
+ fillGradient.appendChild(fillStop2);
121
+ defs.appendChild(fillGradient);
122
+ const strokeGradient = document.createElementNS("http://www.w3.org/2000/svg", "linearGradient");
123
+ strokeGradient.setAttribute("id", strokeGradientId);
124
+ strokeGradient.setAttribute("x1", "0%");
125
+ strokeGradient.setAttribute("y1", "0%");
126
+ strokeGradient.setAttribute("x2", "100%");
127
+ strokeGradient.setAttribute("y2", "0%");
128
+ const strokeStop1 = document.createElementNS("http://www.w3.org/2000/svg", "stop");
129
+ strokeStop1.setAttribute("offset", `${percentage * 100}%`);
130
+ strokeStop1.setAttribute("stop-color", color || strokeColor || fillColor || "currentColor");
131
+ strokeGradient.appendChild(strokeStop1);
132
+ const strokeStop2 = document.createElementNS("http://www.w3.org/2000/svg", "stop");
133
+ strokeStop2.setAttribute("offset", `${percentage * 100}%`);
134
+ strokeStop2.setAttribute("stop-color", secondaryFillColor || "transparent");
135
+ strokeGradient.appendChild(strokeStop2);
136
+ defs.appendChild(strokeGradient);
137
+ }
97
138
  const paths = svg.querySelectorAll("path");
98
139
  paths.forEach((path) => {
99
- if (color) {
100
- if (path.hasAttribute("fill") && fillPercentage === 1) {
101
- path.setAttribute("fill", color);
140
+ if (path.hasAttribute("fill") &&
141
+ path.getAttribute("fill") !== "none") {
142
+ if (percentage === 1) {
143
+ path.setAttribute("fill", color ||
144
+ fillColor ||
145
+ path.getAttribute("fill") ||
146
+ "currentColor");
102
147
  }
103
- path.setAttribute("stroke", color);
104
- }
105
- else {
106
- if (fillColor &&
107
- path.hasAttribute("fill") &&
108
- fillPercentage === 1) {
109
- path.setAttribute("fill", fillColor);
148
+ else if (percentage === 0) {
149
+ path.setAttribute("fill", secondaryFillColor || "transparent");
110
150
  }
111
- if (strokeColor) {
112
- path.setAttribute("stroke", strokeColor);
151
+ else {
152
+ path.setAttribute("fill", `url(#${fillGradientId})`);
113
153
  }
114
154
  }
115
- if (path.hasAttribute("stroke")) {
116
- path.setAttribute("stroke-width", strokeWidthMapping[size].toString());
117
- }
118
- if (strokeWidth != null && path.hasAttribute("stroke")) {
119
- path.setAttribute("stroke-width", strokeWidth.toString());
155
+ if (path.hasAttribute("stroke") &&
156
+ path.getAttribute("stroke") !== "none") {
157
+ if (percentage === 1) {
158
+ path.setAttribute("stroke", color ||
159
+ strokeColor ||
160
+ path.getAttribute("stroke") ||
161
+ "currentColor");
162
+ }
163
+ else if (percentage === 0) {
164
+ path.setAttribute("stroke", secondaryFillColor || "transparent");
165
+ }
166
+ else {
167
+ path.setAttribute("stroke", `url(#${strokeGradientId})`);
168
+ }
120
169
  }
121
- // Create a gradient fill based on the fillPercentage
122
- if (fillPercentage && fillPercentage > 0 && fillPercentage < 1) {
123
- const percentage = Math.min(Math.max(fillPercentage, 0), 1);
124
- const gradientId = `gradient-${Math.random()}`;
125
- const gradient = document.createElementNS("http://www.w3.org/2000/svg", "linearGradient");
126
- gradient.setAttribute("id", gradientId);
127
- gradient.setAttribute("x1", "0%");
128
- gradient.setAttribute("y1", "0%");
129
- gradient.setAttribute("x2", "100%");
130
- gradient.setAttribute("y2", "0%");
131
- const stop1 = document.createElementNS("http://www.w3.org/2000/svg", "stop");
132
- stop1.setAttribute("offset", `${percentage * 100}%`);
133
- stop1.setAttribute("stop-color", color || fillColor || "currentColor");
134
- gradient.appendChild(stop1);
135
- const stop2 = document.createElementNS("http://www.w3.org/2000/svg", "stop");
136
- stop2.setAttribute("offset", `${percentage * 100}%`);
137
- stop2.setAttribute("stop-color", secondaryFillColor || "transparent"); // Use secondary fill color
138
- gradient.appendChild(stop2);
139
- svg.appendChild(gradient);
140
- path.setAttribute("fill", `url(#${gradientId})`);
170
+ if (path.hasAttribute("stroke") &&
171
+ path.getAttribute("stroke") !== "none") {
172
+ if (strokeWidth != null) {
173
+ path.setAttribute("stroke-width", strokeWidth.toString());
174
+ }
175
+ else {
176
+ path.setAttribute("stroke-width", strokeWidthMapping[size].toString());
177
+ }
141
178
  }
142
179
  });
143
180
  } }));
@@ -2,7 +2,7 @@
2
2
  import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
3
3
  import React, { useState, useEffect, useCallback, useRef, } from "react";
4
4
  // @ts-ignore -- webbridge-react is not typed (yet)
5
- import { useActions } from "@tapcart/webbridge-react";
5
+ import { useActions } from "@tapcart/app-studio-sdk";
6
6
  // Shared manager for all instances of the hook
7
7
  const tapManager = (() => {
8
8
  const elements = new Map();
@@ -39,10 +39,39 @@ export type CalculatedData = {
39
39
  };
40
40
  export declare const DEFAULT_CALCULATED_DATA: CalculatedData;
41
41
  export declare const getCalculatedCartData: (cart: EnrichedCart) => CalculatedData;
42
- export declare const getCartItemKey: (variantId: string, sellingPlanId?: string, attributes?: {
43
- [key: string]: string;
44
- } | {
45
- key: string;
46
- value: string;
47
- }[] | undefined) => string;
42
+ export declare const getUniqueCartItemID: (options: {
43
+ variantId: string;
44
+ sellingPlanId?: string | undefined;
45
+ attributes?: {
46
+ [key: string]: string;
47
+ } | {
48
+ key: string;
49
+ value: string;
50
+ }[] | undefined;
51
+ discounts?: string[] | {
52
+ discountedAmount?: {
53
+ amount: string;
54
+ currencyCode: string;
55
+ } | undefined;
56
+ amount?: number | undefined;
57
+ title: string;
58
+ targetType?: string | undefined;
59
+ type?: string | undefined;
60
+ code?: string | undefined;
61
+ }[] | {
62
+ amount: number;
63
+ code: string;
64
+ title?: string | undefined;
65
+ type: string;
66
+ readOnly?: boolean | undefined;
67
+ }[] | {
68
+ discountedAmount: {
69
+ amount: string;
70
+ currencyCode: string;
71
+ };
72
+ targetType: string;
73
+ code?: string | undefined;
74
+ title?: string | undefined;
75
+ }[] | undefined;
76
+ }) => string;
48
77
  //# sourceMappingURL=cart.util.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cart.util.d.ts","sourceRoot":"","sources":["../../lib/cart.util.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,6BAA6B,EAE7B,cAAc,EACf,MAAM,kBAAkB,CAAA;AAGzB,eAAO,MAAM,eAAe;cAKhB,MAAM;aACP,cAAc;;0BAEH;YAChB,gBAAgB,CAAC,EAAE;gBACjB,MAAM,EAAE,MAAM,CAAA;gBACd,YAAY,EAAE,MAAM,CAAA;aACrB,CAAA;YACD,KAAK,EAAE;gBACL,MAAM,EAAE,MAAM,CAAA;gBACd,YAAY,EAAE,MAAM,CAAA;aACrB,CAAA;YACD,cAAc,CAAC,EAAE;gBACf,MAAM,EAAE,MAAM,CAAA;gBACd,YAAY,EAAE,MAAM,CAAA;aACrB,CAAA;SACF,EAAE;;;;;;;CAgCN,CAAA;AA2CD,eAAO,MAAM,oBAAoB,SAAU,MAAM,QAAQ,YAAY,YAMpE,CAAA;AAED,eAAO,MAAM,kBAAkB,SAAU,MAAM,QAAQ,YAAY,YAMlE,CAAA;AAoHD,MAAM,MAAM,cAAc,GAAG;IAC3B,yB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EAAE,CAAA;IACnD,gBAAgB,EAAE,6BAA6B,EAAE,CAAA;IACjD,cAAc,EAAE,OAAO,CAAA;IACvB,oBAAoB,EAAE,MAAM,CAAA;IAC5B,oBAAoB,EAAE,MAAM,CAAA;IAC5B,WAAW,EAAE,MAAM,CAAA;IACnB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,oBAAoB,EAAE,MAAM,CAAA;IAC5B,gBAAgB,EAAE,MAAM,CAAA;CACzB,CAAA;AAED,eAAO,MAAM,uBAAuB,EAAE,cAUrC,CAAA;AAED,eAAO,MAAM,qBAAqB,SAAU,YAAY,KAAG,cA8B1D,CAAA;AAGD,eAAO,MAAM,mBAAmB;eACnB,MAAM;;;;;aAEG,MAAM;eAAS,MAAM;;;;oBAIN,MAAM;0BAAgB,MAAM;;;eAElD,MAAM;;;;;gBAML,MAAM;cACR,MAAM;;cAEN,MAAM;;;0BAIM;YAAE,MAAM,EAAE,MAAM,CAAC;YAAC,YAAY,EAAE,MAAM,CAAA;SAAE;oBAC9C,MAAM;;;;YAsCzB,CAAA"}
@@ -28,12 +28,12 @@ export const getVariantPrice = ({ quantity, variant, sellingPlanAllocation = { p
28
28
  const getOrderLevelDiscounts = (cart) => {
29
29
  var _a;
30
30
  const discountMap = (_a = cart.discountAllocations) === null || _a === void 0 ? void 0 : _a.filter((discount) => discount.targetType !== "SHIPPING_LINE").reduce((acc, discount) => {
31
- var _a;
31
+ var _a, _b;
32
32
  const code = ((_a = discount.code) !== null && _a !== void 0 ? _a : "unknown").toUpperCase();
33
33
  if (!acc[code]) {
34
34
  acc[code] = 0;
35
35
  }
36
- acc[code] += parseFloat(discount.discountedAmount.amount);
36
+ acc[code] += parseFloat(((_b = discount === null || discount === void 0 ? void 0 : discount.discountedAmount) === null || _b === void 0 ? void 0 : _b.amount) || "0");
37
37
  return acc;
38
38
  }, {});
39
39
  if (!discountMap)
@@ -53,11 +53,14 @@ const getShippingDiscounts = (cart) => {
53
53
  var _a;
54
54
  if (!(cart === null || cart === void 0 ? void 0 : cart.discountAllocations))
55
55
  return [];
56
- return (_a = cart.discountAllocations) === null || _a === void 0 ? void 0 : _a.filter((discount) => discount.targetType === "SHIPPING_LINE").map((discount) => ({
57
- amount: discount.discountedAmount.amount,
58
- code: discount.code,
59
- type: discount.targetType,
60
- }));
56
+ return (_a = cart.discountAllocations) === null || _a === void 0 ? void 0 : _a.filter((discount) => discount.targetType === "SHIPPING_LINE").map((discount) => {
57
+ var _a;
58
+ return ({
59
+ amount: (_a = discount === null || discount === void 0 ? void 0 : discount.discountedAmount) === null || _a === void 0 ? void 0 : _a.amount,
60
+ code: discount === null || discount === void 0 ? void 0 : discount.code,
61
+ type: discount === null || discount === void 0 ? void 0 : discount.targetType,
62
+ });
63
+ });
61
64
  };
62
65
  export const isOrderLevelDiscount = (code, cart) => {
63
66
  const orderLevelDiscounts = getOrderLevelDiscounts(cart);
@@ -187,11 +190,29 @@ export const getCalculatedCartData = (cart) => {
187
190
  totalSavedAmount,
188
191
  };
189
192
  };
190
- export const getCartItemKey = (variantId, sellingPlanId, attributes) => {
191
- const key = `${getIdFromGid(variantId)}:${sellingPlanId || "no-plan"}:${Array.isArray(attributes)
192
- ? attributes === null || attributes === void 0 ? void 0 : attributes.map((attr) => `${attr.key}-${attr.value}`).join("-")
193
+ // Until the actual CartItem ID is available via webbridge, we use this unique identifier
194
+ export const getUniqueCartItemID = (options) => {
195
+ const { variantId, sellingPlanId, attributes, discounts } = options;
196
+ const attributesString = Array.isArray(attributes)
197
+ ? attributes === null || attributes === void 0 ? void 0 : attributes.map((attr) => `${attr.key}-${attr.value}`).sort().reverse().join("-")
193
198
  : Object.entries(attributes || {})
199
+ .sort()
200
+ .reverse()
194
201
  .map(([key, value]) => `${key}-${value}`)
195
- .join("-")}`;
202
+ .join("-");
203
+ const discountsString = discounts
204
+ ? Array.isArray(discounts) && typeof discounts[0] === "string"
205
+ ? discounts.join("-")
206
+ : discounts
207
+ .map((discount) => {
208
+ var _a;
209
+ const amount = parseFloat(((_a = discount.discountedAmount) === null || _a === void 0 ? void 0 : _a.amount) || discount.amount || "0");
210
+ const title = discount.title || "";
211
+ const code = discount.code || "";
212
+ return `${amount}-${title || code}`;
213
+ })
214
+ .join("-")
215
+ : "";
216
+ const key = `${getIdFromGid(variantId)}~~~~${sellingPlanId ? getIdFromGid(sellingPlanId) : "no-plan"}~~~~${attributesString}${discountsString ? "~~~~" + discountsString : ""}`;
196
217
  return key;
197
218
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tapcart/mobile-components",
3
- "version": "0.8.41",
3
+ "version": "0.8.42",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "style": "dist/styles.css",
@@ -72,7 +72,7 @@
72
72
  "@radix-ui/react-toggle-group": "^1.0.4",
73
73
  "@tabler/icons-react": "^3.2.0",
74
74
  "@tanstack/react-virtual": "^3.13.6",
75
- "@tapcart/webbridge-react": "^1.15.0",
75
+ "@tapcart/app-studio-sdk": "^2.0.0",
76
76
  "apple-pay-button": "^1.1.7",
77
77
  "class-variance-authority": "^0.6.0",
78
78
  "clsx": "^1.2.1",