@stacksjs/defaults 0.75.520 → 0.75.524
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/ai/skills/stacks-native/CATALOG.md +4 -4
- package/ai/skills/stacks-ui/SKILL.md +18 -0
- package/ide/vscode/package.json +1 -1
- package/package.json +3 -3
- package/resources/components/Storefront/OrderSummary.stx +13 -3
- package/resources/components/Storefront/ProductCard.stx +21 -7
- package/resources/components/Storefront/QuantitySelector.stx +34 -97
|
@@ -21,13 +21,13 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
|
|
|
21
21
|
| `@stacksjs/auth` | [`stacks-auth`](../stacks-auth/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/index.ts) | 131 |
|
|
22
22
|
| `@stacksjs/browser` | [`stacks-browser`](../stacks-browser/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/browser/src/index.ts) | 9 |
|
|
23
23
|
| `@stacksjs/browser-extension` | [`stacks-browser-extension`](../stacks-browser-extension/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/browser-extension/src/index.ts) | 9 |
|
|
24
|
-
| `@stacksjs/buddy` | [`stacks-buddy`](../stacks-buddy/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/buddy/src/index.ts) |
|
|
24
|
+
| `@stacksjs/buddy` | [`stacks-buddy`](../stacks-buddy/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/buddy/src/index.ts) | 185 |
|
|
25
25
|
| `@stacksjs/build` | [`stacks-build`](../stacks-build/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/build/src/index.ts) | 7 |
|
|
26
26
|
| `@stacksjs/cache` | [`stacks-cache`](../stacks-cache/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cache/src/index.ts) | 24 |
|
|
27
27
|
| `@stacksjs/calendar-api` | [`stacks-calendar`](../stacks-calendar/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/calendar-api/src/index.ts) | 5 |
|
|
28
28
|
| `@stacksjs/charts` | [`stacks-charts`](../stacks-charts/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/charts/src/index.ts) | 3 |
|
|
29
29
|
| `@stacksjs/chat` | [`stacks-chat`](../stacks-chat/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/chat/src/index.ts) | 6 |
|
|
30
|
-
| `@stacksjs/cli` | [`stacks-cli`](../stacks-cli/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cli/src/index.ts) |
|
|
30
|
+
| `@stacksjs/cli` | [`stacks-cli`](../stacks-cli/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cli/src/index.ts) | 14 |
|
|
31
31
|
| `@stacksjs/cloud` | [`stacks-cloud`](../stacks-cloud/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cloud/src/index.ts) | 10 |
|
|
32
32
|
| `@stacksjs/cms` | [`stacks-cms`](../stacks-cms/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cms/src/index.ts) | 5 |
|
|
33
33
|
| `@stacksjs/collections` | [`stacks-collections`](../stacks-collections/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/collections/src/index.ts) | 2 |
|
|
@@ -219,7 +219,7 @@ Read the entrypoint and package export map for re-exported or type-only surfaces
|
|
|
219
219
|
|
|
220
220
|
Local source modules: [src/commands/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/buddy/src/commands/index.ts).
|
|
221
221
|
|
|
222
|
-
Evidence directory: [
|
|
222
|
+
Evidence directory: [185 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/buddy/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
|
|
223
223
|
|
|
224
224
|
### @stacksjs/build
|
|
225
225
|
|
|
@@ -279,7 +279,7 @@ Read the entrypoint and package export map for re-exported or type-only surfaces
|
|
|
279
279
|
|
|
280
280
|
Local source modules: [src/actions/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cli/src/actions/index.ts), [src/cli.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cli/src/cli.ts), [src/commands.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cli/src/commands.ts), [src/exec.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cli/src/exec.ts), [src/helpers.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cli/src/helpers.ts), [src/output.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cli/src/output.ts), [src/parse.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cli/src/parse.ts), [src/process.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cli/src/process.ts), [src/prompts.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cli/src/prompts.ts), [src/run.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cli/src/run.ts), [src/signals.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cli/src/signals.ts), [src/spinner.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cli/src/spinner.ts), [src/terminal.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cli/src/terminal.ts), [src/utils.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cli/src/utils.ts).
|
|
281
281
|
|
|
282
|
-
Evidence directory: [
|
|
282
|
+
Evidence directory: [14 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cli/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
|
|
283
283
|
|
|
284
284
|
### @stacksjs/cloud
|
|
285
285
|
|
|
@@ -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.
|
package/ide/vscode/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"publisher": "Stacks",
|
|
3
3
|
"name": "vscode-stacks",
|
|
4
4
|
"displayName": "Stacks",
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.524",
|
|
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.
|
|
5
|
+
"version": "0.75.524",
|
|
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.
|
|
48
|
+
"@stacksjs/mobile": "0.75.524",
|
|
49
49
|
"@stacksjs/sanitizer": "0.2.807",
|
|
50
50
|
"@stacksjs/stx": "0.2.807",
|
|
51
|
-
"@stacksjs/strings": "0.75.
|
|
51
|
+
"@stacksjs/strings": "0.75.524",
|
|
52
52
|
"@xterm/addon-fit": "^0.11.0",
|
|
53
53
|
"@xterm/xterm": "^6.0.0",
|
|
54
54
|
"ts-qr-codes": "^0.1.8"
|
|
@@ -7,6 +7,10 @@ interface OrderSummaryItem {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
interface OrderSummaryProps {
|
|
10
|
+
/** Labels let a basket distinguish an item subtotal from a quoted final total. */
|
|
11
|
+
heading?: string
|
|
12
|
+
totalTitle?: string
|
|
13
|
+
taxLabel?: string
|
|
10
14
|
items?: OrderSummaryItem[]
|
|
11
15
|
/** Pre-formatted price labels — STX defineProps numerics aren't in scope
|
|
12
16
|
* for SSR template evaluation, so .toFixed() etc. has to happen at the
|
|
@@ -26,6 +30,9 @@ interface OrderSummaryProps {
|
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
const {
|
|
33
|
+
heading = 'Order summary',
|
|
34
|
+
totalTitle = 'Total',
|
|
35
|
+
taxLabel = '',
|
|
29
36
|
items = [],
|
|
30
37
|
subtotalLabel,
|
|
31
38
|
shippingLabel,
|
|
@@ -40,8 +47,8 @@ const {
|
|
|
40
47
|
} = defineProps<OrderSummaryProps>()
|
|
41
48
|
</script>
|
|
42
49
|
|
|
43
|
-
<aside class="rounded-2xl border border-stone-200 p-6 {{ sticky ? 'lg:sticky lg:top-28' : '' }}">
|
|
44
|
-
<p class="font-semibold text-stone-500 text-xs tracking-wider uppercase">
|
|
50
|
+
<aside class="storefront-summary rounded-2xl border border-stone-200 p-6 {{ sticky ? 'lg:sticky lg:top-28' : '' }}">
|
|
51
|
+
<p class="font-semibold text-stone-500 text-xs tracking-wider uppercase">{{ heading }}</p>
|
|
45
52
|
|
|
46
53
|
@if (showItems && items.length > 0)
|
|
47
54
|
<ul class="mt-4 space-y-2 text-sm">
|
|
@@ -58,6 +65,9 @@ const {
|
|
|
58
65
|
<dl class="space-y-3 text-sm {{ showItems ? '' : 'mt-4' }}">
|
|
59
66
|
<div class="flex justify-between"><dt class="text-stone-600">Subtotal</dt><dd class="font-semibold text-stone-900">{{ subtotalLabel }}</dd></div>
|
|
60
67
|
<div class="flex justify-between"><dt class="text-stone-600">Shipping</dt><dd class="font-semibold text-stone-900">{{ shippingLabel }}</dd></div>
|
|
68
|
+
@if (taxLabel)
|
|
69
|
+
<div class="flex justify-between"><dt class="text-stone-600">Tax</dt><dd class="font-semibold text-stone-900">{{ taxLabel }}</dd></div>
|
|
70
|
+
@endif
|
|
61
71
|
@if (freeShippingNote)
|
|
62
72
|
<p class="px-3 py-2 text-emerald-700 text-xs bg-emerald-50 rounded-lg">{{ freeShippingNote }}</p>
|
|
63
73
|
@endif
|
|
@@ -66,7 +76,7 @@ const {
|
|
|
66
76
|
<hr class="my-4 border-stone-200">
|
|
67
77
|
|
|
68
78
|
<div class="flex justify-between text-base">
|
|
69
|
-
<p class="font-semibold text-stone-900">
|
|
79
|
+
<p class="font-semibold text-stone-900">{{ totalTitle }}</p>
|
|
70
80
|
<p class="font-bold text-stone-900">{{ totalLabel }}</p>
|
|
71
81
|
</div>
|
|
72
82
|
|
|
@@ -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/
|
|
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-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
<
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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>
|