@vibes.diy/prompts 14.3.204 → 14.3.206
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/index.d.ts +0 -1
- package/index.js +0 -1
- package/index.js.map +1 -1
- package/llms/backend.md +17 -1
- package/llms/github.md +5 -0
- package/llms/stripe-subscriptions.js +1 -1
- package/llms/stripe-subscriptions.js.map +1 -1
- package/llms/stripe-subscriptions.md +179 -35
- package/llms/stripe.js +21 -1
- package/llms/stripe.js.map +1 -1
- package/llms/stripe.md +245 -56
- package/llms/touch-games.md +38 -6
- package/llms/types.d.ts +2 -0
- package/llms/ui-storefront.js +1 -1
- package/llms/ui-storefront.js.map +1 -1
- package/llms/ui-storefront.md +326 -151
- package/llms/voxel.md +8 -9
- package/package.json +5 -5
- package/system-prompt-initial-oneshot.md +1 -1
- package/system-prompt-initial.md +1 -1
- package/system-prompt.md +1 -1
- package/look-restyle.d.ts +0 -49
- package/look-restyle.js +0 -199
- package/look-restyle.js.map +0 -1
package/llms/ui-storefront.md
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
# Storefront
|
|
2
2
|
|
|
3
|
-
A small shop: product cards to browse, a category filter and a search, a bag that adds things up, and a checkout that places the order. It fits a potter's ceramics, a bakery's preorders, a club's merch table or a school fair's stall. Reach for it whenever the app's core is a short catalogue that people pick from and then order. The catalogue
|
|
3
|
+
A small shop: product cards to browse, a category filter and a search, a bag that adds things up, and a checkout that places the order. It fits a potter's ceramics, a bakery's preorders, a club's merch table or a school fair's stall. Reach for it whenever the app's core is a short catalogue that people pick from and then order. The catalogue is the owner's: each thing for sale is a `product` record the owner adds on the app's own Products screen, with its name, price, a short line, a category and a photo, so changing what the shop sells is an edit in the app, never a rebuild. The bag lives in the page while someone shops. Each placed order persists as its own document, so the shop can see what to make and the buyer can see what they ordered. It records orders; taking card payment is the `stripe` skill, which reads these same product records.
|
|
4
4
|
|
|
5
5
|
Built from @vibes.diy/ui components; persisted state lives in Fireproof. Every write surface is gated on `useVibe(dbName).can`.
|
|
6
6
|
|
|
7
7
|
## The block
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Two screens, one job each. The **Shop** fills the bag and places the order: a `Navbar` carries the brand and a quiet bag button with a live count, and the `Heading` puts an `orange` `Highlight` on one word beside a muted line. A `Segmented` category filter (`tone="info"`) and a search `Input` in a `Field` sit above a `Grid cols="sidebar"`: on the main side a two-column grid of product `Card`s, each fronted by its photo in a `Figure` (or the category's decorative `orange` `IconTile` until a photo is added), an `info` `Badge` for "New" or "Bestseller", the price in numeric `Text` and a quiet `Add to bag` (an `Empty` stands in when nothing matches); on the side the bag's `Card`, one line per product with its total and `IconButton`s to take one away or add one, then the subtotal, shipping and total. `Place order` is the shop's one lead; it shows `loading` while the write lands, and the bag empties only after it does.
|
|
10
|
+
|
|
11
|
+
The **Products** screen is the owner's, behind `can.create` on a product draft: a form for the name, price, short line, category and photo, then one row per product whose price edits in place and whose `On sale` checkbox puts it in front of buyers or takes it away. The catalogue starts empty, and an owner who opens an empty shop lands on this screen with "Add the first thing you sell"; a visitor sees a warm `Empty` until the first product goes on sale. Every price is a whole number in the currency's smallest unit (cents for usd, whole yen for jpy) beside its `currency`, the unit card payments charge in, and the page shows, edits and adds prices through that unit.
|
|
12
|
+
|
|
13
|
+
An order is one document holding a snapshot of each line's title, unit price and quantity, the totals, the currency and the buyer's handle, so a later price change never rewrites an order already placed; the person's own orders list under the bag, each with a `Badge` for its status (`info` received, `warn` ready to collect, `up` collected). Checkout waits on its `can` verdict from `useVibe("orders")`: a `Skeleton` inside an `aria-busy` wrapper while it resolves, a sentence in the app's own words when ordering is closed, and for a visitor who has not signed in a `Sign in to place your order` lead wired to `useViewer().requestLogin()`, with the bag they filled kept in place. Sign-in is required here, unlike a local-first note, because a signed-out write stays on the device until sign-in: an order placed that way would never reach the shop.
|
|
10
14
|
|
|
11
15
|
### `App.jsx`
|
|
12
16
|
```jsx
|
|
13
|
-
import React, { useState } from "react";
|
|
17
|
+
import React, { useEffect, useState } from "react";
|
|
14
18
|
import { useFireproof } from "use-fireproof";
|
|
15
19
|
import { useViewer, useVibe } from "use-vibes";
|
|
16
20
|
import {
|
|
@@ -21,6 +25,7 @@ import {
|
|
|
21
25
|
Empty,
|
|
22
26
|
Eyebrow,
|
|
23
27
|
Field,
|
|
28
|
+
Figure,
|
|
24
29
|
Grid,
|
|
25
30
|
Heading,
|
|
26
31
|
Highlight,
|
|
@@ -35,51 +40,191 @@ import {
|
|
|
35
40
|
Stack,
|
|
36
41
|
Text,
|
|
37
42
|
} from "@vibes.diy/ui";
|
|
38
|
-
import { Separator, Toaster, toast } from "@vibes.diy/ui/interactive";
|
|
43
|
+
import { Checkbox, Select, Separator, Toaster, toast } from "@vibes.diy/ui/interactive";
|
|
44
|
+
|
|
45
|
+
// Prices are whole numbers in the currency's smallest unit: cents for usd, whole yen for jpy.
|
|
46
|
+
// Show, edit and add them through that unit, never a fixed 100.
|
|
47
|
+
const CURRENCY = "usd"; // the currency new products are priced in
|
|
48
|
+
const digits = (currency) => new Intl.NumberFormat("en", { style: "currency", currency }).resolvedOptions().maximumFractionDigits;
|
|
49
|
+
const money = (amount, currency) => new Intl.NumberFormat(undefined, { style: "currency", currency }).format(amount / 10 ** digits(currency));
|
|
50
|
+
const toMinor = (text, currency) => Math.round(Number(text) * 10 ** digits(currency));
|
|
51
|
+
const shown = (amount, currency) => (amount / 10 ** digits(currency)).toFixed(digits(currency));
|
|
39
52
|
|
|
40
|
-
const PRODUCTS = [
|
|
41
|
-
{ id: "mug", name: "Speckled mug", blurb: "Holds a generous coffee, glazed oatmeal.", price: 28, category: "table", icon: "drop", badge: "Bestseller" },
|
|
42
|
-
{ id: "bowl", name: "Nesting bowls", blurb: "A set of three for salads and snacks.", price: 64, category: "table", icon: "home" },
|
|
43
|
-
{ id: "vase", name: "Bud vase", blurb: "A small home for a few stems.", price: 36, category: "home", icon: "sparkle", badge: "New" },
|
|
44
|
-
{ id: "planter", name: "Hanging planter", blurb: "Thrown stoneware with a jute cord.", price: 48, category: "home", icon: "sun" },
|
|
45
|
-
{ id: "dish", name: "Ring dish", blurb: "A shallow dish for keys and rings.", price: 18, category: "gifts", icon: "heart" },
|
|
46
|
-
{ id: "card", name: "Gift card", blurb: "Let them pick their own favourite.", price: 50, category: "gifts", icon: "tag" },
|
|
47
|
-
];
|
|
48
53
|
const CATEGORIES = [
|
|
49
|
-
{ value: "
|
|
50
|
-
{ value: "
|
|
51
|
-
{ value: "
|
|
52
|
-
{ value: "gifts", label: "Gifts" },
|
|
54
|
+
{ value: "table", label: "Table", icon: "drop" },
|
|
55
|
+
{ value: "home", label: "Home", icon: "home" },
|
|
56
|
+
{ value: "gifts", label: "Gifts", icon: "heart" },
|
|
53
57
|
];
|
|
54
|
-
const
|
|
55
|
-
const
|
|
58
|
+
const FILTERS = [{ value: "all", label: "All" }, ...CATEGORIES.map(({ value, label }) => ({ value, label }))];
|
|
59
|
+
const BADGES = [
|
|
60
|
+
{ value: "", label: "No badge" },
|
|
61
|
+
{ value: "New", label: "New" },
|
|
62
|
+
{ value: "Bestseller", label: "Bestseller" },
|
|
63
|
+
];
|
|
64
|
+
const PRODUCT_DRAFT = { _id: "product-draft", type: "product", title: "Draft", amount: 100, currency: CURRENCY, onSale: true };
|
|
65
|
+
const iconOf = (category) => CATEGORIES.find((c) => c.value === category)?.icon ?? "tag";
|
|
66
|
+
// Shipping in the same smallest unit: a flat rate, free over a threshold.
|
|
67
|
+
const SHIPPING = 800;
|
|
68
|
+
const FREE_SHIPPING = 10000;
|
|
56
69
|
const ORDER_STATUS = {
|
|
57
70
|
received: { label: "Received", tone: "info" },
|
|
58
71
|
ready: { label: "Ready to collect", tone: "warn" },
|
|
59
72
|
collected: { label: "Collected", tone: "up" },
|
|
60
73
|
};
|
|
74
|
+
const MAX_QTY = 99; // the most of one thing a bag holds
|
|
61
75
|
const plural = (n, one, many) => (n === 1 ? `1 ${one}` : `${n} ${many}`);
|
|
62
76
|
|
|
77
|
+
// One product on the owner's list: its price edits in place, and On sale puts it in front of
|
|
78
|
+
// buyers or takes it away. A refused write puts the shown price back.
|
|
79
|
+
function ProductRow({ product, save }) {
|
|
80
|
+
const [price, setPrice] = useState(shown(product.amount, product.currency));
|
|
81
|
+
useEffect(() => setPrice(shown(product.amount, product.currency)), [product.amount]);
|
|
82
|
+
const commit = () => {
|
|
83
|
+
const amount = toMinor(price, product.currency);
|
|
84
|
+
if (Number.isInteger(amount) && amount > 0 && amount !== product.amount) save({ ...product, amount }, () => setPrice(shown(product.amount, product.currency)));
|
|
85
|
+
else setPrice(shown(product.amount, product.currency));
|
|
86
|
+
};
|
|
87
|
+
return (
|
|
88
|
+
<Row gap={3} wrap={false}>
|
|
89
|
+
{product._files?.photo?.url ? (
|
|
90
|
+
<Figure src={product._files.photo.url} alt={product.title} width={48} height={48} />
|
|
91
|
+
) : (
|
|
92
|
+
<IconTile icon={iconOf(product.category)} tone="orange" size="sm" />
|
|
93
|
+
)}
|
|
94
|
+
<Text truncate>{product.title}</Text>
|
|
95
|
+
<Spacer />
|
|
96
|
+
<Field label="Price">
|
|
97
|
+
{(id, describedBy) => (
|
|
98
|
+
<Input id={id} describedBy={describedBy} value={price} onChange={setPrice} onBlur={commit} onKeyDown={(e) => e.key === "Enter" && commit()} inputMode="decimal" />
|
|
99
|
+
)}
|
|
100
|
+
</Field>
|
|
101
|
+
<Checkbox label="On sale" checked={product.onSale} onChange={(on) => save({ ...product, onSale: on === true })} />
|
|
102
|
+
</Row>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// The owner's catalogue: what is for sale and what it costs. Each save is a `product` record that
|
|
107
|
+
// access.js takes from the owner alone. Empty, the form for the first product leads.
|
|
108
|
+
function Products({ products, onAdd }) {
|
|
109
|
+
const { database } = useFireproof("orders");
|
|
110
|
+
const blank = { title: "", price: "", blurb: "", category: CATEGORIES[0].value, badge: "", photo: null };
|
|
111
|
+
const [draft, setDraft] = useState(blank);
|
|
112
|
+
const [adding, setAdding] = useState(false);
|
|
113
|
+
const [error, setError] = useState(null);
|
|
114
|
+
// A file input keeps its pick until it remounts, so each new draft gets a fresh one.
|
|
115
|
+
const [pickerKey, setPickerKey] = useState(0);
|
|
116
|
+
const edit = (key, value) => setDraft((d) => ({ ...d, [key]: value }));
|
|
117
|
+
|
|
118
|
+
// A plain put lands on this device at once and the server's verdict arrives on its receipt; a
|
|
119
|
+
// put carrying a photo uploads first and rejects instead. Either way the owner hears why.
|
|
120
|
+
async function save(product, undo) {
|
|
121
|
+
setError(null);
|
|
122
|
+
try {
|
|
123
|
+
const { synced } = await database.put(product);
|
|
124
|
+
synced.on((s) => {
|
|
125
|
+
if (s.status !== "refused") return;
|
|
126
|
+
undo?.();
|
|
127
|
+
setError(s.message ?? "That did not save: a product needs a name and a price like 12.50.");
|
|
128
|
+
});
|
|
129
|
+
} catch (err) {
|
|
130
|
+
undo?.();
|
|
131
|
+
setError(err.message);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function add() {
|
|
136
|
+
const amount = toMinor(draft.price, CURRENCY);
|
|
137
|
+
if (!draft.title.trim() || !Number.isInteger(amount) || amount <= 0) return setError("Give it a name and a price like 12.50.");
|
|
138
|
+
const product = {
|
|
139
|
+
_id: "product-" + crypto.randomUUID(),
|
|
140
|
+
type: "product",
|
|
141
|
+
title: draft.title.trim(),
|
|
142
|
+
blurb: draft.blurb.trim(),
|
|
143
|
+
category: draft.category,
|
|
144
|
+
badge: draft.badge || null,
|
|
145
|
+
amount,
|
|
146
|
+
currency: CURRENCY,
|
|
147
|
+
onSale: true,
|
|
148
|
+
createdAt: Date.now(),
|
|
149
|
+
_files: draft.photo ? { photo: draft.photo } : {},
|
|
150
|
+
};
|
|
151
|
+
// The owner stays here: the first product would otherwise flip an empty shop's default screen.
|
|
152
|
+
onAdd();
|
|
153
|
+
setAdding(true);
|
|
154
|
+
const cleared = { ...blank };
|
|
155
|
+
setDraft(cleared);
|
|
156
|
+
setPickerKey((k) => k + 1);
|
|
157
|
+
// A refused write hands the draft back, unless the owner has touched the next one.
|
|
158
|
+
await save(product, () => setDraft((d) => (d === cleared ? draft : d)));
|
|
159
|
+
setAdding(false);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<Stack gap={5}>
|
|
164
|
+
<Card>
|
|
165
|
+
<Stack gap={4}>
|
|
166
|
+
<Heading level={2}>{products.length === 0 ? "Add the first thing you sell" : "Add a product"}</Heading>
|
|
167
|
+
<Grid cols={2} gap={3}>
|
|
168
|
+
<Field label="Name">{(id, describedBy) => <Input id={id} describedBy={describedBy} value={draft.title} onChange={(v) => edit("title", v)} placeholder="Speckled mug" />}</Field>
|
|
169
|
+
<Field label="Price">{(id, describedBy) => <Input id={id} describedBy={describedBy} value={draft.price} onChange={(v) => edit("price", v)} placeholder="28.00" inputMode="decimal" />}</Field>
|
|
170
|
+
<Field label="Short line">{(id, describedBy) => <Input id={id} describedBy={describedBy} value={draft.blurb} onChange={(v) => edit("blurb", v)} placeholder="Holds a generous coffee." />}</Field>
|
|
171
|
+
<Field label="Category">{(id, describedBy) => <Select id={id} describedBy={describedBy} value={draft.category} onChange={(v) => edit("category", v)} options={CATEGORIES} />}</Field>
|
|
172
|
+
<Field label="Badge">{(id, describedBy) => <Select id={id} describedBy={describedBy} value={draft.badge} onChange={(v) => edit("badge", v)} options={BADGES} />}</Field>
|
|
173
|
+
<Field label="Photo">{(id, describedBy) => <input key={pickerKey} id={id} aria-describedby={describedBy} type="file" accept="image/*" onChange={(e) => edit("photo", e.target.files?.[0] ?? null)} />}</Field>
|
|
174
|
+
</Grid>
|
|
175
|
+
{error && <Text>{error}</Text>}
|
|
176
|
+
<Button loading={adding} onClick={add}>
|
|
177
|
+
Add to the shop
|
|
178
|
+
</Button>
|
|
179
|
+
</Stack>
|
|
180
|
+
</Card>
|
|
181
|
+
{products.length > 0 && (
|
|
182
|
+
<Card>
|
|
183
|
+
<Stack gap={3}>
|
|
184
|
+
<Heading level={2}>Products</Heading>
|
|
185
|
+
{products.map((p) => (
|
|
186
|
+
<ProductRow key={p._id} product={p} save={save} />
|
|
187
|
+
))}
|
|
188
|
+
</Stack>
|
|
189
|
+
</Card>
|
|
190
|
+
)}
|
|
191
|
+
</Stack>
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
63
195
|
export default function App() {
|
|
64
|
-
const { database, useLiveQuery } = useFireproof("
|
|
196
|
+
const { database, useLiveQuery } = useFireproof("orders");
|
|
65
197
|
const { docs: orders } = useLiveQuery("type", { key: "order" });
|
|
66
|
-
const {
|
|
198
|
+
const { docs: products } = useLiveQuery("type", { key: "product" });
|
|
199
|
+
const { can, me } = useVibe("orders");
|
|
67
200
|
const { requestLogin } = useViewer();
|
|
68
201
|
|
|
202
|
+
// The owner's verdict on a product draft carrying every field add() stamps: access.js takes
|
|
203
|
+
// product records from the owner alone, and only with a name, a whole-unit price and a currency.
|
|
204
|
+
const canStock = can.create(PRODUCT_DRAFT);
|
|
205
|
+
// An owner with an empty shop starts on Products; after that the shop leads until they switch.
|
|
206
|
+
const [view, setView] = useState(null);
|
|
207
|
+
const screen = view ?? (!canStock.pending && canStock.ok && products.length === 0 ? "products" : "shop");
|
|
208
|
+
|
|
69
209
|
const [category, setCategory] = useState("all");
|
|
70
210
|
const [query, setQuery] = useState("");
|
|
71
211
|
// The bag is a draft: it lives in the page until the order is placed.
|
|
72
212
|
const [bag, setBag] = useState({});
|
|
73
213
|
const [placing, setPlacing] = useState(false);
|
|
74
214
|
|
|
215
|
+
// One currency per bag: the shop sells in CURRENCY, so a record priced in another stays off the shelf.
|
|
216
|
+
const forSale = products.filter((p) => p.onSale && p.currency === CURRENCY).sort((a, b) => a.createdAt - b.createdAt);
|
|
75
217
|
const needle = query.trim().toLowerCase();
|
|
76
|
-
const visible =
|
|
77
|
-
(p) => (category === "all" || p.category === category) && (needle === "" || `${p.
|
|
218
|
+
const visible = forSale.filter(
|
|
219
|
+
(p) => (category === "all" || p.category === category) && (needle === "" || `${p.title} ${p.blurb ?? ""}`.toLowerCase().includes(needle))
|
|
78
220
|
);
|
|
79
|
-
|
|
221
|
+
// A product taken off sale drops out of the bag's lines as well as the grid.
|
|
222
|
+
const lines = forSale
|
|
223
|
+
.filter((p) => (bag[p._id] ?? 0) > 0)
|
|
224
|
+
.map((p) => ({ productId: p._id, title: p.title, unitAmount: p.amount, qty: bag[p._id] }));
|
|
80
225
|
const count = lines.reduce((n, l) => n + l.qty, 0);
|
|
81
|
-
const subtotal = lines.reduce((n, l) => n + l.
|
|
82
|
-
const shipping = subtotal === 0 || subtotal >= FREE_SHIPPING ? 0 :
|
|
226
|
+
const subtotal = lines.reduce((n, l) => n + l.unitAmount * l.qty, 0);
|
|
227
|
+
const shipping = subtotal === 0 || subtotal >= FREE_SHIPPING ? 0 : SHIPPING;
|
|
83
228
|
const mine = me ? orders.filter((o) => o.authorHandle === me.userHandle).sort((a, b) => b.createdAt - a.createdAt) : [];
|
|
84
229
|
|
|
85
230
|
// The verdict for the order placeOrder writes, carrying the same fields it stamps.
|
|
@@ -88,7 +233,7 @@ export default function App() {
|
|
|
88
233
|
|
|
89
234
|
function change(id, delta) {
|
|
90
235
|
setBag((b) => {
|
|
91
|
-
const qty = Math.max(0, (b[id] ?? 0) + delta);
|
|
236
|
+
const qty = Math.min(MAX_QTY, Math.max(0, (b[id] ?? 0) + delta));
|
|
92
237
|
const { [id]: _gone, ...rest } = b;
|
|
93
238
|
return qty === 0 ? rest : { ...rest, [id]: qty };
|
|
94
239
|
});
|
|
@@ -97,7 +242,7 @@ export default function App() {
|
|
|
97
242
|
async function placeOrder() {
|
|
98
243
|
setPlacing(true);
|
|
99
244
|
try {
|
|
100
|
-
await database.put({ ...orderDraft, lines, subtotal, shipping, total: subtotal + shipping, createdAt: Date.now() });
|
|
245
|
+
await database.put({ ...orderDraft, lines, currency: CURRENCY, subtotal, shipping, total: subtotal + shipping, createdAt: Date.now() });
|
|
101
246
|
// Emptied only once the order lands, so a local failure keeps the bag.
|
|
102
247
|
setBag({});
|
|
103
248
|
toast.success("Order placed. We'll be in touch about collection.");
|
|
@@ -138,141 +283,170 @@ export default function App() {
|
|
|
138
283
|
</Row>
|
|
139
284
|
}
|
|
140
285
|
actions={
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
286
|
+
<>
|
|
287
|
+
{!canStock.pending && canStock.ok && (
|
|
288
|
+
<Button size="sm" variant="quiet" onClick={() => setView(screen === "products" ? "shop" : "products")}>
|
|
289
|
+
<Icon name={screen === "products" ? "cart" : "tag"} size="sm" />
|
|
290
|
+
{screen === "products" ? "Shop" : "Products"}
|
|
291
|
+
</Button>
|
|
292
|
+
)}
|
|
293
|
+
{screen === "shop" && (
|
|
294
|
+
<Button size="sm" variant="quiet" onClick={() => document.getElementById("bag")?.scrollIntoView({ block: "nearest" })}>
|
|
295
|
+
<Icon name="cart" size="sm" />
|
|
296
|
+
Bag ({count})
|
|
297
|
+
</Button>
|
|
298
|
+
)}
|
|
299
|
+
</>
|
|
145
300
|
}
|
|
146
301
|
/>
|
|
147
302
|
|
|
148
|
-
|
|
149
|
-
<
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
{(id, describedBy) => <Input id={id} describedBy={describedBy} value={query} onChange={setQuery} inputMode="search" placeholder="Mug, vase…" />}
|
|
160
|
-
</Field>
|
|
161
|
-
</Row>
|
|
303
|
+
{screen === "products" ? (
|
|
304
|
+
<Products products={products} onAdd={() => setView("products")} />
|
|
305
|
+
) : (
|
|
306
|
+
<>
|
|
307
|
+
<Stack gap={2}>
|
|
308
|
+
<Eyebrow>Handmade in small batches</Eyebrow>
|
|
309
|
+
<Heading level={1}>
|
|
310
|
+
Pots for <Highlight tone="orange">everyday</Highlight> things.
|
|
311
|
+
</Heading>
|
|
312
|
+
<Text muted>Free shipping over {money(FREE_SHIPPING, CURRENCY)}. Every piece is thrown and glazed by hand.</Text>
|
|
313
|
+
</Stack>
|
|
162
314
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
<Grid cols={2} gap={4}>
|
|
170
|
-
{visible.map((p) => (
|
|
171
|
-
<Card key={p.id}>
|
|
172
|
-
<Stack gap={3}>
|
|
173
|
-
<Row justify="between" align="top">
|
|
174
|
-
<IconTile icon={p.icon} tone="orange" />
|
|
175
|
-
{p.badge && <Badge tone="info">{p.badge}</Badge>}
|
|
176
|
-
</Row>
|
|
177
|
-
<Stack gap={1}>
|
|
178
|
-
<Heading level={3}>{p.name}</Heading>
|
|
179
|
-
<Text size="sm" muted>
|
|
180
|
-
{p.blurb}
|
|
181
|
-
</Text>
|
|
182
|
-
</Stack>
|
|
183
|
-
<Row justify="between">
|
|
184
|
-
<Text num>{MONEY.format(p.price)}</Text>
|
|
185
|
-
<Button size="sm" variant="quiet" onClick={() => change(p.id, 1)}>
|
|
186
|
-
Add to bag
|
|
187
|
-
</Button>
|
|
188
|
-
</Row>
|
|
189
|
-
</Stack>
|
|
190
|
-
</Card>
|
|
191
|
-
))}
|
|
192
|
-
</Grid>
|
|
193
|
-
)}
|
|
315
|
+
<Row justify="between" align="top">
|
|
316
|
+
<Segmented label="Category" tone="info" value={category} onChange={setCategory} options={FILTERS} />
|
|
317
|
+
<Field label="Search the shop">
|
|
318
|
+
{(id, describedBy) => <Input id={id} describedBy={describedBy} value={query} onChange={setQuery} inputMode="search" placeholder="Mug, vase…" />}
|
|
319
|
+
</Field>
|
|
320
|
+
</Row>
|
|
194
321
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
<
|
|
215
|
-
|
|
216
|
-
|
|
322
|
+
<Grid cols="sidebar" gap={5}>
|
|
323
|
+
{forSale.length === 0 ? (
|
|
324
|
+
<Empty icon="sparkle" title="New pieces are on their way">
|
|
325
|
+
The shop opens with its first products. Check back soon.
|
|
326
|
+
</Empty>
|
|
327
|
+
) : visible.length === 0 ? (
|
|
328
|
+
<Empty icon="search" title="Nothing matches">
|
|
329
|
+
Try another word or a different category.
|
|
330
|
+
</Empty>
|
|
331
|
+
) : (
|
|
332
|
+
<Grid cols={2} gap={4}>
|
|
333
|
+
{visible.map((p) => (
|
|
334
|
+
<Card key={p._id}>
|
|
335
|
+
<Stack gap={3}>
|
|
336
|
+
{p._files?.photo?.url ? (
|
|
337
|
+
<Figure src={p._files.photo.url} alt={p.title} width={400} height={300} />
|
|
338
|
+
) : (
|
|
339
|
+
<Row justify="between" align="top">
|
|
340
|
+
<IconTile icon={iconOf(p.category)} tone="orange" />
|
|
341
|
+
{p.badge && <Badge tone="info">{p.badge}</Badge>}
|
|
342
|
+
</Row>
|
|
343
|
+
)}
|
|
344
|
+
<Stack gap={1}>
|
|
345
|
+
<Row justify="between" align="top">
|
|
346
|
+
<Heading level={3}>{p.title}</Heading>
|
|
347
|
+
{p._files?.photo?.url && p.badge && <Badge tone="info">{p.badge}</Badge>}
|
|
348
|
+
</Row>
|
|
349
|
+
{p.blurb && (
|
|
350
|
+
<Text size="sm" muted>
|
|
351
|
+
{p.blurb}
|
|
217
352
|
</Text>
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
<Text num>{
|
|
222
|
-
<
|
|
353
|
+
)}
|
|
354
|
+
</Stack>
|
|
355
|
+
<Row justify="between">
|
|
356
|
+
<Text num>{money(p.amount, p.currency)}</Text>
|
|
357
|
+
<Button size="sm" variant="quiet" onClick={() => change(p._id, 1)}>
|
|
358
|
+
Add to bag
|
|
359
|
+
</Button>
|
|
223
360
|
</Row>
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
361
|
+
</Stack>
|
|
362
|
+
</Card>
|
|
363
|
+
))}
|
|
364
|
+
</Grid>
|
|
365
|
+
)}
|
|
366
|
+
|
|
367
|
+
<div id="bag">
|
|
368
|
+
<Stack gap={4}>
|
|
369
|
+
<Card>
|
|
370
|
+
<Stack gap={4}>
|
|
234
371
|
<Row justify="between">
|
|
372
|
+
<Heading level={2}>Your bag</Heading>
|
|
235
373
|
<Text size="sm" muted>
|
|
236
|
-
|
|
374
|
+
{plural(count, "item", "items")}
|
|
237
375
|
</Text>
|
|
238
|
-
<Text size="sm" num>
|
|
239
|
-
{shipping === 0 ? "Free" : MONEY.format(shipping)}
|
|
240
|
-
</Text>
|
|
241
|
-
</Row>
|
|
242
|
-
<Row justify="between">
|
|
243
|
-
<Text>Total</Text>
|
|
244
|
-
<Text num>{MONEY.format(subtotal + shipping)}</Text>
|
|
245
376
|
</Row>
|
|
377
|
+
{lines.length === 0 ? (
|
|
378
|
+
<Empty icon="cart" title="Your bag is empty">
|
|
379
|
+
Add something you love and it waits here.
|
|
380
|
+
</Empty>
|
|
381
|
+
) : (
|
|
382
|
+
<Stack gap={3}>
|
|
383
|
+
{lines.map((l) => (
|
|
384
|
+
<Row key={l.productId} gap={2} wrap={false}>
|
|
385
|
+
<Stack gap={1}>
|
|
386
|
+
<Text truncate>{l.title}</Text>
|
|
387
|
+
<Text size="sm" muted num>
|
|
388
|
+
{money(l.unitAmount * l.qty, CURRENCY)}
|
|
389
|
+
</Text>
|
|
390
|
+
</Stack>
|
|
391
|
+
<Spacer />
|
|
392
|
+
<IconButton size="sm" variant="quiet" icon={<Icon name="remove" size="sm" />} label={`One fewer ${l.title}`} onClick={() => change(l.productId, -1)} />
|
|
393
|
+
<Text num>{l.qty}</Text>
|
|
394
|
+
<IconButton size="sm" variant="quiet" icon={<Icon name="add" size="sm" />} label={`One more ${l.title}`} onClick={() => change(l.productId, 1)} />
|
|
395
|
+
</Row>
|
|
396
|
+
))}
|
|
397
|
+
<Separator />
|
|
398
|
+
<Row justify="between">
|
|
399
|
+
<Text size="sm" muted>
|
|
400
|
+
Subtotal
|
|
401
|
+
</Text>
|
|
402
|
+
<Text size="sm" num>
|
|
403
|
+
{money(subtotal, CURRENCY)}
|
|
404
|
+
</Text>
|
|
405
|
+
</Row>
|
|
406
|
+
<Row justify="between">
|
|
407
|
+
<Text size="sm" muted>
|
|
408
|
+
Shipping
|
|
409
|
+
</Text>
|
|
410
|
+
<Text size="sm" num>
|
|
411
|
+
{shipping === 0 ? "Free" : money(shipping, CURRENCY)}
|
|
412
|
+
</Text>
|
|
413
|
+
</Row>
|
|
414
|
+
<Row justify="between">
|
|
415
|
+
<Text>Total</Text>
|
|
416
|
+
<Text num>{money(subtotal + shipping, CURRENCY)}</Text>
|
|
417
|
+
</Row>
|
|
418
|
+
</Stack>
|
|
419
|
+
)}
|
|
420
|
+
{checkout}
|
|
421
|
+
<Text size="sm" muted>
|
|
422
|
+
We confirm your order and you pay when you collect.
|
|
423
|
+
</Text>
|
|
246
424
|
</Stack>
|
|
425
|
+
</Card>
|
|
426
|
+
|
|
427
|
+
{mine.length > 0 && (
|
|
428
|
+
<Card variant="tight">
|
|
429
|
+
<Stack gap={3}>
|
|
430
|
+
<Heading level={3}>Your orders</Heading>
|
|
431
|
+
{mine.map((o) => (
|
|
432
|
+
<Row key={o._id} justify="between" wrap={false}>
|
|
433
|
+
<Stack gap={1}>
|
|
434
|
+
<Text num>{money(o.total, o.currency ?? CURRENCY)}</Text>
|
|
435
|
+
<Text size="sm" muted>
|
|
436
|
+
{new Date(o.createdAt).toLocaleDateString()} · {plural(o.lines.reduce((n, l) => n + l.qty, 0), "item", "items")}
|
|
437
|
+
</Text>
|
|
438
|
+
</Stack>
|
|
439
|
+
<Badge tone={ORDER_STATUS[o.status]?.tone ?? "info"}>{ORDER_STATUS[o.status]?.label ?? "Received"}</Badge>
|
|
440
|
+
</Row>
|
|
441
|
+
))}
|
|
442
|
+
</Stack>
|
|
443
|
+
</Card>
|
|
247
444
|
)}
|
|
248
|
-
{checkout}
|
|
249
|
-
<Text size="sm" muted>
|
|
250
|
-
No payment is taken here. We confirm your order and arrange payment when you collect.
|
|
251
|
-
</Text>
|
|
252
445
|
</Stack>
|
|
253
|
-
</
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
<Stack gap={3}>
|
|
258
|
-
<Heading level={3}>Your orders</Heading>
|
|
259
|
-
{mine.map((o) => (
|
|
260
|
-
<Row key={o._id} justify="between" wrap={false}>
|
|
261
|
-
<Stack gap={1}>
|
|
262
|
-
<Text num>{MONEY.format(o.total)}</Text>
|
|
263
|
-
<Text size="sm" muted>
|
|
264
|
-
{new Date(o.createdAt).toLocaleDateString()} · {plural(o.lines.reduce((n, l) => n + l.qty, 0), "item", "items")}
|
|
265
|
-
</Text>
|
|
266
|
-
</Stack>
|
|
267
|
-
<Badge tone={ORDER_STATUS[o.status]?.tone ?? "info"}>{ORDER_STATUS[o.status]?.label ?? "Received"}</Badge>
|
|
268
|
-
</Row>
|
|
269
|
-
))}
|
|
270
|
-
</Stack>
|
|
271
|
-
</Card>
|
|
272
|
-
)}
|
|
273
|
-
</Stack>
|
|
274
|
-
</div>
|
|
275
|
-
</Grid>
|
|
446
|
+
</div>
|
|
447
|
+
</Grid>
|
|
448
|
+
</>
|
|
449
|
+
)}
|
|
276
450
|
</Stack>
|
|
277
451
|
<div className="ui-toasts">
|
|
278
452
|
<Toaster />
|
|
@@ -284,10 +458,11 @@ export default function App() {
|
|
|
284
458
|
|
|
285
459
|
## Adapting
|
|
286
460
|
|
|
287
|
-
-
|
|
288
|
-
-
|
|
461
|
+
- The catalogue is records, so a shop with three things and a shop with forty are the same code. It ships empty: example products for a first look go in the app's seed data, which the owner clears, and the owner adds the real ones on **Products**. Swap `CATEGORIES`, `BADGES`, the shipping rule and `CURRENCY` for the shop's own.
|
|
462
|
+
- Product records belong to the owner: `access.js` takes a `product` only from the owner (`ctx.requireRole("owner")`), with an `amount` that is a positive whole number, a three-letter lowercase `currency` and an `onSale` true or false, and puts it on a channel every visitor reads. Keep the `orders` database and the field names `title`, `amount`, `currency` and `onSale`: they are the `stripe` skill's, so its checkout reads these records and prices this bag unchanged.
|
|
463
|
+
- Keep the order a snapshot of titles, unit prices and quantities: an order is a record of what was agreed, so a later price change must not touch it.
|
|
289
464
|
- Orders hold who bought what, so `access.js` and the app's sharing should keep each order between its buyer and the shop: a buyer creates and reads their own, the shop reads them all and moves each through `ORDER_STATUS` behind `can.edit(order)`.
|
|
290
|
-
-
|
|
465
|
+
- Card payment is the `stripe` skill, and it comes in when the person asks to take money: its checkout replaces `Place order` with one `pay(...)` that sends each product and its quantity, `backend.js` prices every line from these records, and the order becomes the one `/checkout` writes. Until then, keep the pay-when-you-collect line truthful, and offer `▸ [pay] Take card payments with Stripe` as the capability option.
|
|
291
466
|
- A new write surface gets its own verdict: `can.create(draft)` with the fields the write stamps, `can.edit(doc)` or `can.delete(doc)` on the document it changes, always on `useVibe` of the database it writes.
|
|
292
467
|
|
|
293
468
|
Adapted from 1st-Pouf (MIT) https://1st-pouf.worksonmy.dev/r/storefront.json
|
package/llms/voxel.md
CHANGED
|
@@ -422,14 +422,13 @@ and nothing happens, or they don't know the mouse controls the camera at all.
|
|
|
422
422
|
and only request lock from that click: its button calls the hook's `requestLock()`, and the hook's
|
|
423
423
|
`locked` brings the overlay back when the player presses Esc. The overlay JSX is in `touch-games`;
|
|
424
424
|
the voxel legend reads "WASD move · Mouse look · Shift sprint · Space jump · Click build ·
|
|
425
|
-
Right-click break · G fly · 1–9 blocks".
|
|
425
|
+
Right-click break · G fly · V views · 1–9 blocks".
|
|
426
426
|
|
|
427
427
|
### View switcher: see your own character
|
|
428
428
|
|
|
429
429
|
Include a view switcher between first-person and third-person so players can see their own avatar.
|
|
430
|
-
The 🎥 camera button outside the menu cycles **Free cam → First person → Shoulder view**, and a
|
|
431
|
-
|
|
432
|
-
ignoring key repeat. On a phone the world opens in Free cam, an overview that frames the island;
|
|
430
|
+
The 🎥 camera button outside the menu cycles **Free cam → First person → Shoulder view**, and the V key cycles them the same way on a keyboard, named in the control legend as `V views`.
|
|
431
|
+
Toggle once per press, ignoring key repeat. On a phone the world opens in Free cam, an overview that frames the island;
|
|
433
432
|
back its radius off on a narrow screen as `touch-games` shows.
|
|
434
433
|
Render a simple blocky local-player avatar in third-person, following
|
|
435
434
|
the player's position and heading, and hide it in first-person so it does not
|
|
@@ -439,10 +438,10 @@ terrain blocks the view. Preserve aiming and the player's block-interaction
|
|
|
439
438
|
reach as the camera moves. Keep the button reachable when pointer lock is
|
|
440
439
|
released, and let the shortcut switch views during locked play.
|
|
441
440
|
|
|
442
|
-
###
|
|
441
|
+
### Fullscreen in the menu: keep the HUD with the world
|
|
443
442
|
|
|
444
|
-
|
|
445
|
-
|
|
443
|
+
The ☰ menu offers a Fullscreen entry for a larger play area, right after the views and before How to play; the Vibes iframe allows fullscreen.
|
|
444
|
+
Call `requestFullscreen()` directly from the entry's user
|
|
446
445
|
gesture on the game container that includes both the canvas and HUD. Check
|
|
447
446
|
`document.fullscreenEnabled` and method availability, and handle a rejected
|
|
448
447
|
request by keeping play usable in the embedded view. Derive the Enter/Exit
|
|
@@ -457,8 +456,8 @@ when needed. Remove the fullscreen listener on unmount.
|
|
|
457
456
|
The world fills the screen (the `CanvasStage` above is `absolute inset-0` inside a
|
|
458
457
|
`relative h-dvh w-full` root). Keep the crosshair, the block chip (the material in hand; a tap
|
|
459
458
|
opens the palette), the hotbar (1–9 and 0 on a keyboard), undo and the 🎥 camera button on screen;
|
|
460
|
-
put
|
|
461
|
-
|
|
459
|
+
put everything else behind **one** top-right menu button (`IconButton`) that toggles an overlay.
|
|
460
|
+
The menu opens with the views by name, then Fullscreen, then How to play (the gestures and keys, one tap away once the hint has moved on), then the title, settings, crafting recipes, the world-reset control and the player list. The bottom-right corner
|
|
462
461
|
belongs to the platform. A smaller boxed world is only for when the person asks for one.
|
|
463
462
|
|
|
464
463
|
### No text selection on the game surface
|