@techninja/staticart 0.1.10 → 0.1.12

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@techninja/staticart",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "StatiCart — a full-featured e-commerce platform built 99% on static hosting",
5
5
  "repository": {
6
6
  "type": "git",
@@ -74,7 +74,7 @@ export default define({
74
74
  class="btn btn-primary btn-sm"
75
75
  data-vid="${v.id}"
76
76
  onclick="${handlePick}"
77
- disabled="${v.stock <= 0}"
77
+ disabled="${v.stock === 0}"
78
78
  >
79
79
  ${v.label}
80
80
  </button>
@@ -87,7 +87,7 @@ export default define({
87
87
  <button
88
88
  class="btn btn-primary product-card__add"
89
89
  onclick="${handleAdd}"
90
- disabled="${stock <= 0}"
90
+ disabled="${stock === 0}"
91
91
  >
92
92
  ${t('cart.add')}
93
93
  </button>
@@ -50,11 +50,10 @@ export default define({
50
50
  .filter(
51
51
  (p) =>
52
52
  p.sku !== currentSku &&
53
- p.stock > 0 &&
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 > 0)
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 = s <= 0 ? 'product.outOfStock' : s <= 5 ? 'product.lowStock' : 'product.inStock';
53
- const color = s <= 0 ? 'danger' : s <= 5 ? 'warning' : 'success';
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 */
@@ -115,7 +115,7 @@ export default define({
115
115
  <button
116
116
  class="btn btn-primary"
117
117
  onclick="${handleAdd}"
118
- disabled="${stock <= 0 || (variants.length > 0 && !selectedVariant)}"
118
+ disabled="${stock === 0 || (variants.length > 0 && !selectedVariant)}"
119
119
  >
120
120
  <app-icon name="cart" size="sm"></app-icon> ${t('cart.add')}
121
121
  </button>
@@ -20,14 +20,16 @@ export function effectiveStock(p, vid) {
20
20
 
21
21
  /** @param {number} stock */
22
22
  export function stockLabel(stock) {
23
- if (stock <= 0) return t('product.outOfStock');
23
+ if (stock < 0) return t('product.inStock');
24
+ if (stock === 0) return t('product.outOfStock');
24
25
  if (stock <= 5) return t('product.lowStock');
25
26
  return t('product.inStock');
26
27
  }
27
28
 
28
29
  /** @param {number} stock */
29
30
  export function stockColor(stock) {
30
- if (stock <= 0) return 'danger';
31
+ if (stock < 0) return 'success';
32
+ if (stock === 0) return 'danger';
31
33
  if (stock <= 5) return 'warning';
32
34
  return 'success';
33
35
  }
@@ -74,7 +74,7 @@ export default define({
74
74
  class="btn btn-primary btn-sm"
75
75
  data-vid="${v.id}"
76
76
  onclick="${handlePick}"
77
- disabled="${v.stock <= 0}"
77
+ disabled="${v.stock === 0}"
78
78
  >
79
79
  ${v.label}
80
80
  </button>
@@ -87,7 +87,7 @@ export default define({
87
87
  <button
88
88
  class="btn btn-primary product-card__add"
89
89
  onclick="${handleAdd}"
90
- disabled="${stock <= 0}"
90
+ disabled="${stock === 0}"
91
91
  >
92
92
  ${t('cart.add')}
93
93
  </button>
@@ -50,11 +50,10 @@ export default define({
50
50
  .filter(
51
51
  (p) =>
52
52
  p.sku !== currentSku &&
53
- p.stock > 0 &&
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 > 0)
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`
package/vendor/icons.json CHANGED
@@ -21,5 +21,6 @@
21
21
  "circle-check": "circle-check",
22
22
  "circle-x": "circle-x",
23
23
  "alert-triangle": "alert-triangle",
24
- "image": "image"
24
+ "image": "image",
25
+ "globe": "globe"
25
26
  }
@@ -49,8 +49,8 @@ export function renderNotFound(CatalogView) {
49
49
 
50
50
  /** @param {number} s */
51
51
  export function stockBadge(s) {
52
- const label = s <= 0 ? 'product.outOfStock' : s <= 5 ? 'product.lowStock' : 'product.inStock';
53
- const color = s <= 0 ? 'danger' : s <= 5 ? 'warning' : 'success';
52
+ const label = s < 0 ? 'product.inStock' : s === 0 ? 'product.outOfStock' : s <= 5 ? 'product.lowStock' : 'product.inStock';
53
+ const color = s < 0 ? 'success' : s === 0 ? 'danger' : s <= 5 ? 'warning' : 'success';
54
54
  return html`<app-badge label="${t(label)}" color="${color}"></app-badge>`;
55
55
  }
56
56
 
@@ -59,7 +59,7 @@ export function handleAdd(host) {
59
59
  if (!store.ready(host.cart) || !store.ready(host.product)) return;
60
60
  const { product: p, selectedVariant: vid, qty } = host;
61
61
  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);
62
+ if (stock < 0 || (qty <= stock && stock > 0)) addToCart(host.cart, p.sku, vid, qty);
63
63
  }
64
64
 
65
65
  /** @param {any} host */
@@ -115,7 +115,7 @@ export default define({
115
115
  <button
116
116
  class="btn btn-primary"
117
117
  onclick="${handleAdd}"
118
- disabled="${stock <= 0 || (variants.length > 0 && !selectedVariant)}"
118
+ disabled="${stock === 0 || (variants.length > 0 && !selectedVariant)}"
119
119
  >
120
120
  <app-icon name="cart" size="sm"></app-icon> ${t('cart.add')}
121
121
  </button>
@@ -20,14 +20,16 @@ export function effectiveStock(p, vid) {
20
20
 
21
21
  /** @param {number} stock */
22
22
  export function stockLabel(stock) {
23
- if (stock <= 0) return t('product.outOfStock');
23
+ if (stock < 0) return t('product.inStock');
24
+ if (stock === 0) return t('product.outOfStock');
24
25
  if (stock <= 5) return t('product.lowStock');
25
26
  return t('product.inStock');
26
27
  }
27
28
 
28
29
  /** @param {number} stock */
29
30
  export function stockColor(stock) {
30
- if (stock <= 0) return 'danger';
31
+ if (stock < 0) return 'success';
32
+ if (stock === 0) return 'danger';
31
33
  if (stock <= 5) return 'warning';
32
34
  return 'success';
33
35
  }