@stacksjs/defaults 0.75.520 → 0.75.522

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.
@@ -82,6 +82,24 @@ Pass `memberId` and a localized `memberIdLabel` to engrave a permanent account i
82
82
 
83
83
  Theme the finish through inherited CSS custom properties on the card's container or the application's root. Every property falls back to the original graphite finish: `--membership-card-background`, `--membership-card-color`, `--membership-card-border`, `--membership-card-shadow`, `--membership-card-inset-border`, `--membership-card-grain`, `--membership-card-label`, `--membership-card-name`, `--membership-card-divider`, `--membership-card-serial`, and `--membership-card-detail`. `--membership-card-confetti-1` through `--membership-card-confetti-4` color the celebration. Keep label and name colors readable against every stop of a custom gradient; the component's layout, stable identifier and reduced-motion behavior remain the same.
84
84
 
85
+ ## Storefront components
86
+
87
+ `<ProductCard>` accepts generic `description`, `priceNote`, `href` and
88
+ `imageAlt` props alongside the legacy food-specific `ingredient` prop.
89
+ `description` takes precedence over `ingredient`; `priceNote` can explain a
90
+ target or per-unit price without implying a discount. Status badges appear
91
+ with the product copy below the image. Format money at the caller.
92
+
93
+ `<QuantitySelector>` uses STX component state rather than document listeners.
94
+ It binds `value` through `useModel`, supports `min`/`max`, defaults to whole
95
+ quantities from 1 through 99, and keeps its named native number input ready
96
+ for normal form submission. Use `label` for the input's accessible name.
97
+ Buttons emit native input/change events for existing form integrations;
98
+ `v-model:value` supports reactive parents; `change` remains a single bubbling
99
+ native input event, without an additional custom event.
100
+ Validate quantities again on the server. Multiple selectors keep independent
101
+ state and do not install global click handlers.
102
+
85
103
  ## Gotchas
86
104
 
87
105
  - `config/ui.ts` configures STX topology; `config/css.ts` configures utilities.
@@ -2,7 +2,7 @@
2
2
  "publisher": "Stacks",
3
3
  "name": "vscode-stacks",
4
4
  "displayName": "Stacks",
5
- "version": "0.75.520",
5
+ "version": "0.75.522",
6
6
  "description": "Stacks, built into VS Code: stx templates, pickier linting and formatting, encrypted env files, the dev server preview and every buddy command. No other extensions required.",
7
7
  "license": "MIT",
8
8
  "funding": "https://github.com/sponsors/chrisbbreuer",
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/defaults",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.520",
5
+ "version": "0.75.522",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/stacksjs/stacks.git",
@@ -45,10 +45,10 @@
45
45
  "dependencies": {
46
46
  "@iconify-json/f7": "^1.2.2",
47
47
  "@iconify-json/hugeicons": "^1.2.35",
48
- "@stacksjs/mobile": "0.75.520",
48
+ "@stacksjs/mobile": "0.75.522",
49
49
  "@stacksjs/sanitizer": "0.2.807",
50
50
  "@stacksjs/stx": "0.2.807",
51
- "@stacksjs/strings": "0.75.520",
51
+ "@stacksjs/strings": "0.75.522",
52
52
  "@xterm/addon-fit": "^0.11.0",
53
53
  "@xterm/xterm": "^6.0.0",
54
54
  "ts-qr-codes": "^0.1.8"
@@ -10,6 +10,13 @@ interface ProductCardProps {
10
10
  weight?: string
11
11
  badge?: string
12
12
  speciesLabel?: string
13
+ /** Generic product copy, preferred over the legacy food-specific ingredient. */
14
+ description?: string
15
+ /** Explain a price's status, such as a target price or price per unit. */
16
+ priceNote?: string
17
+ /** An application may use a shared configurator instead of a slug route. */
18
+ href?: string
19
+ imageAlt?: string
13
20
  }
14
21
 
15
22
  const {
@@ -21,10 +28,14 @@ const {
21
28
  weight = '',
22
29
  badge = '',
23
30
  speciesLabel = '',
31
+ description = '',
32
+ priceNote = '',
33
+ href = '',
34
+ imageAlt = '',
24
35
  } = defineProps<ProductCardProps>()
25
36
  </script>
26
37
 
27
- <a href="/products/{{ slug }}" class="block overflow-hidden bg-stone-50 border border-stone-200 rounded-2xl hover:border-stone-900 transition-colors group">
38
+ <a href="{{ href || '/products/' + slug }}" class="block overflow-hidden bg-stone-50 border border-stone-200 rounded-2xl focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-4 hover:border-stone-900 transition-colors group">
28
39
  <div class="aspect-square overflow-hidden relative bg-stone-200">
29
40
  {{-- decoding=async + loading=lazy so a long catalog grid below the fold
30
41
  doesn't block first paint, and explicit width/height (matched to a
@@ -33,18 +44,18 @@ const {
33
44
  (home featured, /products grid) so lazy is always safe. --}}
34
45
  <img
35
46
  src="{{ image }}"
36
- alt="{{ name }}"
47
+ alt="{{ imageAlt || name }}"
37
48
  width="600"
38
49
  height="600"
39
50
  loading="lazy"
40
51
  decoding="async"
41
52
  class="object-cover h-full w-full duration-500 transition-transform group-hover:scale-105"
42
53
  >
43
- @if (badge)
44
- <span class="absolute left-3 top-3 px-2 py-0.5 font-semibold text-[10px] text-stone-900 tracking-wider uppercase bg-stone-50 rounded-full">{{ badge }}</span>
45
- @endif
46
54
  </div>
47
55
  <div class="p-4">
56
+ @if (badge)
57
+ <p class="mb-2 font-medium text-stone-600 text-xs">{{ badge }}</p>
58
+ @endif
48
59
  <div class="flex items-center justify-between">
49
60
  <span class="font-semibold text-[10px] text-stone-500 tracking-wider uppercase">{{ speciesLabel }}</span>
50
61
  @if (weight)
@@ -52,12 +63,15 @@ const {
52
63
  @endif
53
64
  </div>
54
65
  <h3 class="mt-2 font-semibold leading-snug text-stone-900">{{ name }}</h3>
55
- @if (ingredient)
56
- <p class="mt-1 text-stone-500 text-xs">{{ ingredient }}</p>
66
+ @if (description || ingredient)
67
+ <p class="mt-1 text-sm text-stone-600">{{ description || ingredient }}</p>
57
68
  @endif
58
69
  <div class="flex items-center justify-between mt-3">
59
70
  <p class="font-bold text-stone-900">{{ priceLabel }}</p>
60
71
  <span class="font-medium text-stone-500 text-xs group-hover:text-stone-900">View →</span>
61
72
  </div>
73
+ @if (priceNote)
74
+ <p class="mt-1 text-stone-600 text-xs">{{ priceNote }}</p>
75
+ @endif
62
76
  </div>
63
77
  </a>
@@ -1,102 +1,39 @@
1
- <script>
2
- interface QuantitySelectorProps {
3
- name?: string
4
- value?: number
5
- min?: number
6
- max?: number
7
- className?: string
8
- }
9
-
10
- const {
11
- name = 'quantity',
12
- value = 1,
13
- min = 1,
14
- max = 99,
15
- className = '',
16
- } = defineProps<QuantitySelectorProps>()
1
+ <script server>
2
+ export const name = $props.name || 'quantity'
3
+ export const min = Number.isSafeInteger(Number($props.min)) ? Number($props.min) : 1
4
+ export const max = Math.max(min, Number.isSafeInteger(Number($props.max)) ? Number($props.max) : 99)
5
+ export const value = Math.max(min, Math.min(max, Number.isSafeInteger(Number($props.value)) ? Number($props.value) : min))
6
+ export const className = $props.className || ''
7
+ export const label = $props.label || 'Quantity'
17
8
  </script>
18
9
 
19
- <div
20
- class="flex items-center rounded-full border border-stone-300 overflow-hidden {{ className }}"
21
- data-stx-qty
22
- data-min="{{ min }}"
23
- data-max="{{ max }}"
24
- >
25
- <button type="button" class="px-4 py-3 text-stone-500 hover:text-stone-900 focus-visible:bg-stone-100 focus-visible:outline-none transition-colors" data-stx-qty-dec aria-label="Decrease quantity">−</button>
26
- <input
27
- name="{{ name }}"
28
- value="{{ value }}"
29
- type="number"
30
- min="{{ min }}"
31
- max="{{ max }}"
32
- class="w-12 text-center bg-transparent focus:outline-none [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none [appearance:textfield]"
33
- >
34
- <button type="button" class="px-4 py-3 text-stone-500 hover:text-stone-900 focus-visible:bg-stone-100 focus-visible:outline-none transition-colors" data-stx-qty-inc aria-label="Increase quantity">+</button>
35
- </div>
36
-
37
- <script data-stx-scoped>
38
- ;(() => {
39
- // Delegate one document-level click handler so:
40
- // 1. Repeated SSR'd <script data-stx-scoped> blocks (one per
41
- // QuantitySelector instance) don't stack listeners on the same
42
- // buttons. Without delegation, two QuantitySelectors on a page
43
- // = two listeners per button = doubled increments per click.
44
- // 2. SPA fragment swaps that re-inject our scoped script don't
45
- // keep multiplying handlers; the guard below early-returns.
46
- const w = window as Window & {
47
- /** Set by this block so a fragment swap cannot stack a second set of listeners. */
48
- __stxQtyWired?: boolean
49
- }
50
-
51
- if (w.__stxQtyWired) return
52
- w.__stxQtyWired = true
53
-
54
- // Default min/max chosen to match the component's defineProps fallbacks.
55
- // STX SSR doesn't reliably propagate defineProps default values into
56
- // template attribute interpolation, so the rendered HTML can carry
57
- // empty `min=""` / `max=""` attributes. Number("") is 0, so without
58
- // these fallbacks Math.min(0, qty+1) capped every increment at 0 and
59
- // the +/- buttons appeared dead. Read either the data-* on the wrapper
60
- // or the input attribute, whichever is non-empty.
61
- function bound(wrap: HTMLElement, kind: string, fallback: number) {
62
- const fromData = wrap.getAttribute('data-' + kind)
63
- if (fromData && fromData.trim() !== '') {
64
- const n = Number(fromData)
65
- if (Number.isFinite(n)) return n
66
- }
67
- const input = wrap.querySelector<HTMLInputElement>('input[type="number"]')
68
- const fromAttr = input && input.getAttribute(kind)
69
- if (fromAttr && fromAttr.trim() !== '') {
70
- const n = Number(fromAttr)
71
- if (Number.isFinite(n)) return n
72
- }
73
- return fallback
74
- }
10
+ <script client>
11
+ const lower = useReactiveProp('min', {{ min }})
12
+ const upper = useReactiveProp('max', {{ max }})
13
+ const quantity = useModel('value', { default: {{ value }} })
14
+ const input = useRef('quantityInput')
15
+ const normalized = derived(() => Math.max(lower(), Math.min(Math.max(lower(), upper()), Number.isSafeInteger(Number(quantity())) ? Number(quantity()) : lower())))
16
+ effect(() => {
17
+ const next = normalized()
18
+ if (quantity() !== next)
19
+ quantity.set(next)
20
+ })
75
21
 
76
- function step(wrap: HTMLElement, delta: number) {
77
- const input = wrap.querySelector<HTMLInputElement>('input[type="number"]')
78
- if (!input) return
79
- const min = bound(wrap, 'min', 1)
80
- const max = bound(wrap, 'max', 99)
81
- const current = Number(input.value)
82
- const seed = Number.isFinite(current) ? current : min
83
- const next = Math.max(min, Math.min(max, seed + delta))
84
- if (next === seed) return
85
- input.value = String(next)
86
- input.dispatchEvent(new Event('input', { bubbles: true }))
87
- input.dispatchEvent(new Event('change', { bubbles: true }))
88
- }
89
-
90
- document.addEventListener('click', (e) => {
91
- const target = e.target instanceof Element ? e.target : null
92
- if (!target) return
93
- const dec = target.closest('[data-stx-qty-dec]')
94
- const inc = target.closest('[data-stx-qty-inc]')
95
- if (!dec && !inc) return
96
- const wrap = (dec ?? inc)?.closest<HTMLElement>('[data-stx-qty]')
97
- if (!wrap) return
98
- e.preventDefault()
99
- step(wrap, dec ? -1 : 1)
22
+ function commit(next: number): void {
23
+ quantity.set(Math.max(lower(), Math.min(Math.max(lower(), upper()), next)))
24
+ // Preserve native form integrations without a document-level listener.
25
+ void nextTick(() => {
26
+ input.current?.dispatchEvent(new Event('input', { bubbles: true }))
27
+ input.current?.dispatchEvent(new Event('change', { bubbles: true }))
100
28
  })
101
- })()
29
+ }
30
+ function normalize(): void {
31
+ quantity.set(normalized())
32
+ }
102
33
  </script>
34
+
35
+ <div class="flex items-center rounded-full border border-stone-300 overflow-hidden {{ className }}" data-stx-qty>
36
+ <button type="button" class="px-4 py-3 text-stone-700 hover:bg-stone-100 focus-visible:outline focus-visible:outline-2 disabled:opacity-40" data-stx-qty-dec aria-label="Decrease quantity" :disabled="normalized() <= lower()" @click="commit(normalized() - 1)">−</button>
37
+ <input ref="quantityInput" name="{{ name }}" value="{{ value }}" type="number" min="{{ min }}" max="{{ max }}" :min="lower()" :max="upper()" step="1" aria-label="{{ label }}" x-model.number="quantity" @change="normalize()" class="py-3 w-12 text-center bg-transparent focus-visible:outline focus-visible:outline-2 [appearance:textfield]">
38
+ <button type="button" class="px-4 py-3 text-stone-700 hover:bg-stone-100 focus-visible:outline focus-visible:outline-2 disabled:opacity-40" data-stx-qty-inc aria-label="Increase quantity" :disabled="normalized() >= upper()" @click="commit(normalized() + 1)">+</button>
39
+ </div>