@techninja/staticart 0.1.11 → 0.1.13
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/package.json +1 -1
- package/scripts/vendor-deps.js +15 -3
- package/src/components/molecules/related-products/related-products.js +1 -2
- package/src/components/molecules/series-gallery/series-gallery.js +1 -1
- package/src/pages/product-detail/helpers.js +10 -3
- package/vendor/components/molecules/related-products/related-products.js +1 -2
- package/vendor/components/molecules/series-gallery/series-gallery.js +1 -1
- package/vendor/pages/product-detail/helpers.js +10 -3
package/package.json
CHANGED
package/scripts/vendor-deps.js
CHANGED
|
@@ -8,17 +8,29 @@
|
|
|
8
8
|
import { cpSync, mkdirSync } from 'node:fs';
|
|
9
9
|
import { resolve, dirname } from 'node:path';
|
|
10
10
|
import { fileURLToPath } from 'node:url';
|
|
11
|
+
import { createRequire } from 'node:module';
|
|
11
12
|
|
|
12
13
|
const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
13
14
|
const VENDOR_DIR = resolve(ROOT, 'src/vendor');
|
|
15
|
+
const require = createRequire(import.meta.url);
|
|
14
16
|
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
+
/** Resolve a package's source dir, handling npm hoisting. */
|
|
18
|
+
function findPkgSrc(pkg, subdir) {
|
|
19
|
+
try {
|
|
20
|
+
const entry = require.resolve(`${pkg}/package.json`);
|
|
21
|
+
return resolve(dirname(entry), subdir);
|
|
22
|
+
} catch {
|
|
23
|
+
return resolve(ROOT, 'node_modules', pkg, subdir);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** @type {{ name: string, src: string, subdir: string }[]} */
|
|
28
|
+
const DEPS = [{ name: 'hybrids', src: 'hybrids', subdir: 'src' }];
|
|
17
29
|
|
|
18
30
|
mkdirSync(VENDOR_DIR, { recursive: true });
|
|
19
31
|
|
|
20
32
|
for (const dep of DEPS) {
|
|
21
|
-
const src =
|
|
33
|
+
const src = findPkgSrc(dep.src, dep.subdir);
|
|
22
34
|
const dest = resolve(VENDOR_DIR, dep.name);
|
|
23
35
|
cpSync(src, dest, { recursive: true });
|
|
24
36
|
console.log(`✓ Vendored: ${dep.name} → src/vendor/${dep.name}/`);
|
|
@@ -50,11 +50,10 @@ export default define({
|
|
|
50
50
|
.filter(
|
|
51
51
|
(p) =>
|
|
52
52
|
p.sku !== currentSku &&
|
|
53
|
-
p.stock
|
|
53
|
+
p.stock !== 0 &&
|
|
54
54
|
(!excludeSeries || p.metadata?.seriesTitle !== excludeSeries),
|
|
55
55
|
)
|
|
56
56
|
.map((p) => ({ product: p, score: relevanceScore(current, p) }))
|
|
57
|
-
.filter((r) => r.score > 0)
|
|
58
57
|
.sort((a, b) => b.score - a.score)
|
|
59
58
|
.slice(0, MAX_RELATED)
|
|
60
59
|
.map((r) => r.product);
|
|
@@ -26,7 +26,7 @@ export default define({
|
|
|
26
26
|
value: ({ series, currentSku, products }) => {
|
|
27
27
|
if (!series || !(/** @type {any} */ (store).ready(products))) return html``;
|
|
28
28
|
const related = /** @type {any[]} */ (products)
|
|
29
|
-
.filter((p) => p.metadata?.seriesTitle === series && p.sku !== currentSku && p.stock
|
|
29
|
+
.filter((p) => p.metadata?.seriesTitle === series && p.sku !== currentSku && p.stock !== 0)
|
|
30
30
|
.sort((a, b) => a.name.localeCompare(b.name));
|
|
31
31
|
if (!related.length) return html``;
|
|
32
32
|
return html`
|
|
@@ -49,8 +49,15 @@ export function renderNotFound(CatalogView) {
|
|
|
49
49
|
|
|
50
50
|
/** @param {number} s */
|
|
51
51
|
export function stockBadge(s) {
|
|
52
|
-
const label =
|
|
53
|
-
|
|
52
|
+
const label =
|
|
53
|
+
s < 0
|
|
54
|
+
? 'product.inStock'
|
|
55
|
+
: s === 0
|
|
56
|
+
? 'product.outOfStock'
|
|
57
|
+
: s <= 5
|
|
58
|
+
? 'product.lowStock'
|
|
59
|
+
: 'product.inStock';
|
|
60
|
+
const color = s < 0 ? 'success' : s === 0 ? 'danger' : s <= 5 ? 'warning' : 'success';
|
|
54
61
|
return html`<app-badge label="${t(label)}" color="${color}"></app-badge>`;
|
|
55
62
|
}
|
|
56
63
|
|
|
@@ -59,7 +66,7 @@ export function handleAdd(host) {
|
|
|
59
66
|
if (!store.ready(host.cart) || !store.ready(host.product)) return;
|
|
60
67
|
const { product: p, selectedVariant: vid, qty } = host;
|
|
61
68
|
const stock = vid ? (p.variants.find((v) => v.id === vid)?.stock ?? 0) : p.stock;
|
|
62
|
-
if (qty <= stock && stock > 0) addToCart(host.cart, p.sku, vid, qty);
|
|
69
|
+
if (stock < 0 || (qty <= stock && stock > 0)) addToCart(host.cart, p.sku, vid, qty);
|
|
63
70
|
}
|
|
64
71
|
|
|
65
72
|
/** @param {any} host */
|
|
@@ -50,11 +50,10 @@ export default define({
|
|
|
50
50
|
.filter(
|
|
51
51
|
(p) =>
|
|
52
52
|
p.sku !== currentSku &&
|
|
53
|
-
p.stock
|
|
53
|
+
p.stock !== 0 &&
|
|
54
54
|
(!excludeSeries || p.metadata?.seriesTitle !== excludeSeries),
|
|
55
55
|
)
|
|
56
56
|
.map((p) => ({ product: p, score: relevanceScore(current, p) }))
|
|
57
|
-
.filter((r) => r.score > 0)
|
|
58
57
|
.sort((a, b) => b.score - a.score)
|
|
59
58
|
.slice(0, MAX_RELATED)
|
|
60
59
|
.map((r) => r.product);
|
|
@@ -26,7 +26,7 @@ export default define({
|
|
|
26
26
|
value: ({ series, currentSku, products }) => {
|
|
27
27
|
if (!series || !(/** @type {any} */ (store).ready(products))) return html``;
|
|
28
28
|
const related = /** @type {any[]} */ (products)
|
|
29
|
-
.filter((p) => p.metadata?.seriesTitle === series && p.sku !== currentSku && p.stock
|
|
29
|
+
.filter((p) => p.metadata?.seriesTitle === series && p.sku !== currentSku && p.stock !== 0)
|
|
30
30
|
.sort((a, b) => a.name.localeCompare(b.name));
|
|
31
31
|
if (!related.length) return html``;
|
|
32
32
|
return html`
|
|
@@ -49,8 +49,15 @@ export function renderNotFound(CatalogView) {
|
|
|
49
49
|
|
|
50
50
|
/** @param {number} s */
|
|
51
51
|
export function stockBadge(s) {
|
|
52
|
-
const label =
|
|
53
|
-
|
|
52
|
+
const label =
|
|
53
|
+
s < 0
|
|
54
|
+
? 'product.inStock'
|
|
55
|
+
: s === 0
|
|
56
|
+
? 'product.outOfStock'
|
|
57
|
+
: s <= 5
|
|
58
|
+
? 'product.lowStock'
|
|
59
|
+
: 'product.inStock';
|
|
60
|
+
const color = s < 0 ? 'success' : s === 0 ? 'danger' : s <= 5 ? 'warning' : 'success';
|
|
54
61
|
return html`<app-badge label="${t(label)}" color="${color}"></app-badge>`;
|
|
55
62
|
}
|
|
56
63
|
|
|
@@ -59,7 +66,7 @@ export function handleAdd(host) {
|
|
|
59
66
|
if (!store.ready(host.cart) || !store.ready(host.product)) return;
|
|
60
67
|
const { product: p, selectedVariant: vid, qty } = host;
|
|
61
68
|
const stock = vid ? (p.variants.find((v) => v.id === vid)?.stock ?? 0) : p.stock;
|
|
62
|
-
if (qty <= stock && stock > 0) addToCart(host.cart, p.sku, vid, qty);
|
|
69
|
+
if (stock < 0 || (qty <= stock && stock > 0)) addToCart(host.cart, p.sku, vid, qty);
|
|
63
70
|
}
|
|
64
71
|
|
|
65
72
|
/** @param {any} host */
|