@nextblock-cms/ecom 0.8.0 → 0.8.6
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/AddToCartButton-DsSEH9yp.cjs +1 -0
- package/AddToCartButton-ffE0DhHu.js +59 -0
- package/CouponForm-BI_5SBHQ.js +152 -0
- package/CouponForm-D_uu2bLP.cjs +1 -0
- package/CurrencyProvider-Cg-Q6ucj.cjs +1 -0
- package/CurrencyProvider-OzlRN96V.js +120 -0
- package/CurrencyProvider.cjs.js +1 -0
- package/CurrencyProvider.es.js +10 -0
- package/ProductDetailsLayout-BxJH_BxR.cjs +1 -0
- package/ProductDetailsLayout-Dg8dRTYp.js +530 -0
- package/ProductGrid-BdL7iglO.cjs +1 -0
- package/ProductGrid-D3AWM8sr.js +130 -0
- package/actions-AHmBrS5e.cjs +48 -0
- package/actions-j5fuSZX-.js +820 -0
- package/cart-store.cjs.js +1 -0
- package/cart-store.es.js +116 -0
- package/components/Cart.cjs.js +1 -0
- package/components/Cart.es.js +259 -0
- package/components/CartDrawer.cjs.js +1 -0
- package/components/CartDrawer.es.js +118 -0
- package/components/CartIcon.cjs.js +1 -0
- package/components/CartIcon.es.js +33 -0
- package/components/Checkout.cjs.js +1 -0
- package/components/Checkout.es.js +1020 -0
- package/components/CurrencySwitcher.cjs.js +1 -0
- package/components/CurrencySwitcher.es.js +17 -0
- package/components/FeaturedProduct.cjs.js +1 -0
- package/components/FeaturedProduct.es.js +71 -0
- package/components/ProductDetailsLayout.cjs.js +1 -0
- package/components/ProductDetailsLayout.es.js +19 -0
- package/components/ProductGrid.cjs.js +1 -0
- package/components/ProductGrid.es.js +6 -0
- package/components/SimpleTiptapRenderer.cjs.js +1 -0
- package/components/SimpleTiptapRenderer.es.js +187 -0
- package/coupon-server-C9ySm3I5.cjs +1 -0
- package/coupon-server-DUKVtyYs.js +248 -0
- package/currency-constants.cjs.js +1 -0
- package/currency-constants.es.js +4 -0
- package/currency.cjs.js +1 -0
- package/currency.es.js +312 -0
- package/customer-C-UPvrYN.cjs +1 -0
- package/customer-C3xccjUg.js +57 -0
- package/index.cjs.js +1 -1
- package/index.es.js +414 -3105
- package/invoice-ui-CAnJPu6n.cjs +29 -0
- package/invoice-ui-DtpbTJE1.js +2886 -0
- package/package.json +10 -5
- package/product-actions-CONBF8i6.cjs +251 -0
- package/product-actions-DjlIWCMH.js +691 -0
- package/resolver-Fz_FKsfX.cjs +7 -0
- package/resolver-cfrCaHpE.js +128 -0
- package/server-actions/product-actions.cjs.js +1 -0
- package/server-actions/product-actions.es.js +15 -0
- package/server.cjs.js +27 -27
- package/server.es.js +478 -463
- package/shipping-actions-BnHjlo2q.js +25 -0
- package/shipping-actions-D6zt20gg.cjs +1 -0
- package/states-CWYRxV4B.cjs +1 -0
- package/states-DlHJezQ1.js +200 -0
- package/tax-calculation-Dab89aHd.js +181 -0
- package/tax-calculation-MkDKOEkL.cjs +1 -0
- package/trials-DvZaOtNy.cjs +1 -0
- package/trials-RDcRAZKx.js +29 -0
- package/types.cjs.js +1 -0
- package/types.es.js +33 -0
- package/use-cart.cjs.js +1 -0
- package/use-cart.es.js +43 -0
- package/variation-utils.cjs.js +1 -0
- package/variation-utils.es.js +246 -0
- package/invoice-ui-BJZfedDd.cjs +0 -332
- package/invoice-ui-GJ1ADAjn.js +0 -5759
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { normalizeSalePriceMap as S, normalizePriceMap as g, isSaleWindowActive as E } from "./currency.es.js";
|
|
2
|
+
function p(e) {
|
|
3
|
+
return !e || typeof e != "object" || Array.isArray(e) ? null : Object.entries(e).reduce((r, [i, t]) => (typeof t == "string" && t.trim() && (r[i] = t.trim()), r), {});
|
|
4
|
+
}
|
|
5
|
+
function f(e, r, i) {
|
|
6
|
+
return !i || !r ? e : r[i]?.trim() || e;
|
|
7
|
+
}
|
|
8
|
+
function j(e, r) {
|
|
9
|
+
return f(e.name, e.name_translations, r);
|
|
10
|
+
}
|
|
11
|
+
function L(e, r) {
|
|
12
|
+
return f(e.value, e.value_translations, r);
|
|
13
|
+
}
|
|
14
|
+
function B(e) {
|
|
15
|
+
return e ? e.startsWith("http") ? e : process.env.NEXT_PUBLIC_R2_BASE_URL ? `${process.env.NEXT_PUBLIC_R2_BASE_URL}/${e}` : process.env.NEXT_PUBLIC_SUPABASE_URL ? `${process.env.NEXT_PUBLIC_SUPABASE_URL}/storage/v1/object/public/media/${e}` : e : null;
|
|
16
|
+
}
|
|
17
|
+
function I(e) {
|
|
18
|
+
return e.toLowerCase().trim().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
19
|
+
}
|
|
20
|
+
function y(e) {
|
|
21
|
+
return [...e].sort().join("__");
|
|
22
|
+
}
|
|
23
|
+
function T(e) {
|
|
24
|
+
return e.map((r) => r.term_value).join(" / ");
|
|
25
|
+
}
|
|
26
|
+
function M(e) {
|
|
27
|
+
return e.length === 0 ? [] : e.reduce(
|
|
28
|
+
(r, i) => r.flatMap((t) => i.map((s) => [...t, s])),
|
|
29
|
+
[[]]
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
function P(e) {
|
|
33
|
+
const {
|
|
34
|
+
baseSku: r,
|
|
35
|
+
basePrice: i,
|
|
36
|
+
basePrices: t = {},
|
|
37
|
+
baseSalePrice: s = null,
|
|
38
|
+
baseSalePrices: n = {},
|
|
39
|
+
selectedAttributes: u,
|
|
40
|
+
previousVariants: c = []
|
|
41
|
+
} = e;
|
|
42
|
+
if (u.length === 0 || u.some((l) => l.terms.length === 0))
|
|
43
|
+
return [];
|
|
44
|
+
const o = new Map(
|
|
45
|
+
c.map((l) => [l.combination_key, l])
|
|
46
|
+
), a = u.map(
|
|
47
|
+
(l) => l.terms.map((d) => ({
|
|
48
|
+
attribute_id: l.attribute_id,
|
|
49
|
+
attribute_name: l.attribute_name,
|
|
50
|
+
term: d
|
|
51
|
+
}))
|
|
52
|
+
);
|
|
53
|
+
return M(a).map((l) => {
|
|
54
|
+
const d = l.map(({ attribute_id: m, attribute_name: k, term: b }) => ({
|
|
55
|
+
attribute_id: m,
|
|
56
|
+
attribute_name: k,
|
|
57
|
+
term_id: b.id,
|
|
58
|
+
term_value: b.value,
|
|
59
|
+
term_slug: b.slug
|
|
60
|
+
})), A = d.map((m) => m.term_id), h = y(A), _ = o.get(h), v = d.map((m) => (m.term_slug ? m.term_slug : I(m.term_value)).toUpperCase()).filter(Boolean).join("-");
|
|
61
|
+
return {
|
|
62
|
+
id: _?.id,
|
|
63
|
+
combination_key: h,
|
|
64
|
+
sku: _?.sku || [r.trim(), v].filter(Boolean).join("-"),
|
|
65
|
+
upc: _?.upc ?? null,
|
|
66
|
+
price: _?.price ?? i,
|
|
67
|
+
prices: _?.prices ?? g(t),
|
|
68
|
+
sale_price: _?.sale_price ?? s,
|
|
69
|
+
sale_prices: _?.sale_prices ?? S(n),
|
|
70
|
+
// IMPORTANT (future agents): every per-variant field a user can edit MUST
|
|
71
|
+
// be carried over from `previous` here. This function re-runs whenever the
|
|
72
|
+
// variations editor mounts or attributes/base prices change, replacing the
|
|
73
|
+
// draft list. If a field is omitted, it silently resets to null on the next
|
|
74
|
+
// regenerate and then gets autosaved away — which is exactly how the sale
|
|
75
|
+
// window (sale_start_at/sale_end_at) used to "revert after publish".
|
|
76
|
+
sale_start_at: _?.sale_start_at ?? null,
|
|
77
|
+
sale_end_at: _?.sale_end_at ?? null,
|
|
78
|
+
stock_quantity: _?.stock_quantity ?? 0,
|
|
79
|
+
main_media_id: _?.main_media_id ?? null,
|
|
80
|
+
main_image_url: _?.main_image_url ?? null,
|
|
81
|
+
attribute_term_ids: A,
|
|
82
|
+
selected_options: d,
|
|
83
|
+
label: T(d)
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function N(e) {
|
|
88
|
+
const r = {};
|
|
89
|
+
for (const i of e)
|
|
90
|
+
for (const t of i.selected_options ?? []) {
|
|
91
|
+
const s = new Set(r[t.attribute_id] ?? []);
|
|
92
|
+
s.add(t.term_id), r[t.attribute_id] = [...s];
|
|
93
|
+
}
|
|
94
|
+
return r;
|
|
95
|
+
}
|
|
96
|
+
function O(e, r) {
|
|
97
|
+
const i = Object.values(r).filter(Boolean);
|
|
98
|
+
return i.length === 0 ? null : e.find(
|
|
99
|
+
(t) => t.attribute_term_ids.length === i.length && i.every((s) => t.attribute_term_ids.includes(s))
|
|
100
|
+
) ?? null;
|
|
101
|
+
}
|
|
102
|
+
function U(e, r, i) {
|
|
103
|
+
const t = /* @__PURE__ */ new Set();
|
|
104
|
+
for (const s of e) {
|
|
105
|
+
if (!Object.entries(i).every(([c, o]) => !o || c === r ? !0 : s.attribute_term_ids.includes(o)))
|
|
106
|
+
continue;
|
|
107
|
+
const u = s.selected_options.find((c) => c.attribute_id === r);
|
|
108
|
+
u && t.add(u.term_id);
|
|
109
|
+
}
|
|
110
|
+
return t;
|
|
111
|
+
}
|
|
112
|
+
function V(e, r) {
|
|
113
|
+
const i = r.find((t) => t.stock_quantity > 0) ?? r[0] ?? null;
|
|
114
|
+
return i ? i.selected_options.reduce((t, s) => (t[s.attribute_id] = s.term_id, t), {}) : e.reduce((t, s) => {
|
|
115
|
+
const n = s.terms[0];
|
|
116
|
+
return n && (t[s.id] = n.id), t;
|
|
117
|
+
}, {});
|
|
118
|
+
}
|
|
119
|
+
function w(e, r, i) {
|
|
120
|
+
const t = { ...i };
|
|
121
|
+
for (const s of e) {
|
|
122
|
+
const n = U(r, s.id, t);
|
|
123
|
+
if (n.size === 0) {
|
|
124
|
+
delete t[s.id];
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const u = t[s.id];
|
|
128
|
+
if (u && n.has(u))
|
|
129
|
+
continue;
|
|
130
|
+
const c = s.terms.find((o) => n.has(o.id));
|
|
131
|
+
c && (t[s.id] = c.id);
|
|
132
|
+
}
|
|
133
|
+
return t;
|
|
134
|
+
}
|
|
135
|
+
function x(e = [], r) {
|
|
136
|
+
const i = /* @__PURE__ */ new Map(), t = e.map((n) => {
|
|
137
|
+
const u = (n.variant_attribute_mapping || []).map((o) => {
|
|
138
|
+
const a = o.product_attribute_terms, l = a?.product_attributes;
|
|
139
|
+
if (!a || !l)
|
|
140
|
+
return null;
|
|
141
|
+
const d = i.get(l.id) || {
|
|
142
|
+
id: l.id,
|
|
143
|
+
name: f(
|
|
144
|
+
l.name,
|
|
145
|
+
p(l.name_translations),
|
|
146
|
+
r
|
|
147
|
+
),
|
|
148
|
+
slug: l.slug,
|
|
149
|
+
name_translations: p(l.name_translations),
|
|
150
|
+
terms: [],
|
|
151
|
+
_termIds: /* @__PURE__ */ new Set()
|
|
152
|
+
};
|
|
153
|
+
return d._termIds.has(a.id) || (d.terms.push({
|
|
154
|
+
id: a.id,
|
|
155
|
+
attribute_id: a.attribute_id,
|
|
156
|
+
value: f(
|
|
157
|
+
a.value,
|
|
158
|
+
p(a.value_translations),
|
|
159
|
+
r
|
|
160
|
+
),
|
|
161
|
+
slug: a.slug,
|
|
162
|
+
sort_order: a.sort_order ?? null,
|
|
163
|
+
value_translations: p(a.value_translations)
|
|
164
|
+
}), d._termIds.add(a.id)), i.set(l.id, d), {
|
|
165
|
+
attribute_id: l.id,
|
|
166
|
+
attribute_name: f(
|
|
167
|
+
l.name,
|
|
168
|
+
p(l.name_translations),
|
|
169
|
+
r
|
|
170
|
+
),
|
|
171
|
+
term_id: a.id,
|
|
172
|
+
term_value: f(
|
|
173
|
+
a.value,
|
|
174
|
+
p(a.value_translations),
|
|
175
|
+
r
|
|
176
|
+
),
|
|
177
|
+
term_slug: a.slug
|
|
178
|
+
};
|
|
179
|
+
}).filter(
|
|
180
|
+
(o) => o !== null
|
|
181
|
+
).sort(
|
|
182
|
+
(o, a) => o.attribute_name.localeCompare(a.attribute_name)
|
|
183
|
+
), c = u.map((o) => o.term_id);
|
|
184
|
+
return {
|
|
185
|
+
id: n.id,
|
|
186
|
+
combination_key: y(c),
|
|
187
|
+
sku: n.sku,
|
|
188
|
+
upc: n.upc ?? null,
|
|
189
|
+
price: n.price ?? 0,
|
|
190
|
+
prices: g(n.prices),
|
|
191
|
+
sale_price: n.sale_price ?? null,
|
|
192
|
+
sale_prices: S(n.sale_prices),
|
|
193
|
+
sale_start_at: n.sale_start_at ?? null,
|
|
194
|
+
sale_end_at: n.sale_end_at ?? null,
|
|
195
|
+
scheduled_price: n.scheduled_price ?? null,
|
|
196
|
+
scheduled_prices: g(n.scheduled_prices),
|
|
197
|
+
scheduled_price_at: n.scheduled_price_at ?? null,
|
|
198
|
+
stock_quantity: n.stock_quantity ?? 0,
|
|
199
|
+
main_media_id: n.main_media_id ?? null,
|
|
200
|
+
image_url: B(
|
|
201
|
+
n.media?.file_path ?? n.media?.object_key ?? null
|
|
202
|
+
),
|
|
203
|
+
attribute_term_ids: c,
|
|
204
|
+
selected_options: u,
|
|
205
|
+
label: T(u)
|
|
206
|
+
};
|
|
207
|
+
});
|
|
208
|
+
return { attributes: [...i.values()].map((n) => ({
|
|
209
|
+
id: n.id,
|
|
210
|
+
name: n.name,
|
|
211
|
+
slug: n.slug,
|
|
212
|
+
name_translations: n.name_translations,
|
|
213
|
+
terms: [...n.terms].sort((u, c) => {
|
|
214
|
+
const o = u.sort_order ?? Number.MAX_SAFE_INTEGER, a = c.sort_order ?? Number.MAX_SAFE_INTEGER;
|
|
215
|
+
return o !== a ? o - a : u.value.localeCompare(c.value);
|
|
216
|
+
})
|
|
217
|
+
})).sort((n, u) => n.name.localeCompare(u.name)), variants: t };
|
|
218
|
+
}
|
|
219
|
+
function z(e, r) {
|
|
220
|
+
if (!e.length)
|
|
221
|
+
return null;
|
|
222
|
+
const i = e.map((t) => E({
|
|
223
|
+
saleStartAt: t.sale_start_at,
|
|
224
|
+
saleEndAt: t.sale_end_at,
|
|
225
|
+
now: r
|
|
226
|
+
}) && typeof t.sale_price == "number" ? t.sale_price : t.price);
|
|
227
|
+
return {
|
|
228
|
+
min: Math.min(...i),
|
|
229
|
+
max: Math.max(...i)
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
export {
|
|
233
|
+
y as buildCombinationKey,
|
|
234
|
+
T as buildVariantLabel,
|
|
235
|
+
V as chooseInitialVariantSelections,
|
|
236
|
+
N as extractSelectedTermsByAttribute,
|
|
237
|
+
O as findMatchingVariant,
|
|
238
|
+
P as generateVariantDrafts,
|
|
239
|
+
U as getAvailableTermIdsForAttribute,
|
|
240
|
+
z as getVariantEffectivePriceRange,
|
|
241
|
+
x as mapRawVariantRelations,
|
|
242
|
+
w as normalizeSelectionsToAvailableVariants,
|
|
243
|
+
j as resolveAttributeName,
|
|
244
|
+
L as resolveTermValue,
|
|
245
|
+
f as resolveTranslatedText
|
|
246
|
+
};
|