@zappie/foundations 0.17.0 → 0.19.0
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/CHANGELOG.md +29 -0
- package/README.md +215 -23
- package/dist/bag/index.d.ts +173 -0
- package/dist/bag/index.js +2 -0
- package/dist/bag/index.js.map +6 -0
- package/dist/bag/param.js +2 -0
- package/dist/bag/param.js.map +6 -0
- package/dist/bag/server.d.ts +17 -0
- package/dist/bag/server.js +2 -0
- package/dist/bag/server.js.map +6 -0
- package/dist/branch-finder/index.d.ts +60 -0
- package/dist/branch-finder/index.js +2 -0
- package/dist/branch-finder/index.js.map +6 -0
- package/dist/branch-list/index.d.ts +100 -0
- package/dist/branch-list/index.js +2 -0
- package/dist/branch-list/index.js.map +6 -0
- package/dist/branch-list/nearest.js +2 -0
- package/dist/branch-list/nearest.js.map +6 -0
- package/dist/branch-list/offers.js +2 -0
- package/dist/branch-list/offers.js.map +6 -0
- package/dist/branch-switch/index.d.ts +101 -7
- package/dist/branch-switch/index.js +1 -1
- package/dist/branch-switch/index.js.map +1 -1
- package/dist/checkout/index.d.ts +5 -18
- package/dist/index.d.ts +1 -1
- package/dist/item-sheet/index.d.ts +2 -2
- package/dist/item-sheet/index.js +1 -1
- package/dist/item-sheet/index.js.map +1 -1
- package/dist/offers-fDZ0bZ0i.d.ts +19 -0
- package/dist/overlay/deferred-host.js +2 -0
- package/dist/overlay/deferred-host.js.map +6 -0
- package/dist/{react-CFPTPzAO.d.ts → react-C1KQB_W3.d.ts} +2 -2
- package/dist/version.js +1 -1
- package/package.json +19 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @zappie/foundations
|
|
2
2
|
|
|
3
|
+
## 0.19.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- d71cdc5: `@zappie/foundations/branch-switch` now covers every site's branch choice. `useBranchChoice` starts the branch's menu read, moves a bag with lines there, keeps the choice in your branch cookie and goes to the destination with `?branch=` in its address, back to an item with the line kept when the finder was opened from one. `useRememberLinkedBranch` keeps a branch a link names, `rememberBranch` and `atBranch` are the pieces, and `createBranchSwitchLoader`'s `shopAt` defaults to `shopAtBranch`, which sets the branch, its menu and `config.branch` and marks it chosen.
|
|
8
|
+
|
|
9
|
+
`@zappie/foundations/branch-finder` opens your own branch picker or locator from any control. `BranchFinder.Root` holds it and loads its code with `deferred()`, `BranchFinder.Trigger` opens it with a destination, and `useBranchFinder()` opens it from code.
|
|
10
|
+
|
|
11
|
+
`@zappie/foundations/branch-list` is the data behind a branch list. `useHere` asks for the shopper's location only when they tap, `nearestFirst` sorts the branches nearest first, `whereIs` and `kilometres` place and measure them, and `useBranchOffers` reads what each branch sells without its items. `menusLabel` names a branch's menus.
|
|
12
|
+
|
|
13
|
+
The starter keeps the shopper's branch in a cookie, so a page without `?branch=` shows the branch they chose, and its page cache keeps a page apart for each branch. The header's picker opens through `BranchFinder` and chooses with `useBranchChoice`. A new Our branches page lists every branch nearest first once the shopper shares their location, with what each sells and a button to order there.
|
|
14
|
+
|
|
15
|
+
## 0.18.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- 8622a50: `@zappie/foundations/bag` is the bag's plumbing for a React Router site. `Bag.Root` holds whether the bag is open. Opening it adds `?bag=open` to the address as a history entry of its own, so Back closes the bag on the page and a reload opens it again, with no loader run and no page view counted. A page that arrives with `?bag=open` opens the bag and takes `?bag=open` and the sign-in marker off its own address. Going to another page closes the bag. `inline` lets a page that shows the bag as a column bring it into view instead, with `revealBagColumn`.
|
|
20
|
+
|
|
21
|
+
`Bag.Content` is the bag itself, a foundations `Overlay` holding the site's own body, loaded with `deferred()`. It opens once its code is in, shows `failed` with a way to try again when it didn't load, returns focus to the control that opened it, and drags to close on phones. Its code loads when the browser is idle, on a trigger's intent and when a line goes in. `Bag.Trigger` and `useBag()` open it. `hasBagParam` and `openBagAt`, from `@zappie/foundations/bag/server`, cover page views and the `/cart` and `/checkout` redirects.
|
|
22
|
+
|
|
23
|
+
`CartNotice` shows a change the server refused, or a line `useAddToBag()` just added, with an Undo. A line just added is announced to screen readers. The notice has no styles of its own.
|
|
24
|
+
|
|
25
|
+
The starter's bag moves onto it, and its `/cart` and `/checkout` redirects use `openBagAt`. Its cart notice offers Undo for a line just added from the item sheet.
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Updated dependencies [b5b272b]
|
|
30
|
+
- @zappie/sdk@0.19.0
|
|
31
|
+
|
|
3
32
|
## 0.17.0
|
|
4
33
|
|
|
5
34
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -36,10 +36,14 @@ Want ready-made, styled components instead? Copy them into your project from the
|
|
|
36
36
|
| `@zappie/foundations` | Every part |
|
|
37
37
|
| `@zappie/foundations/next` | Keeping overlays in step with Back and Forward in a Next.js app |
|
|
38
38
|
| `@zappie/foundations/branch-switch` | Choosing a branch in a React Router site without waiting for the server |
|
|
39
|
+
| `@zappie/foundations/branch-finder` | Opening the site's branch picker or locator from any control |
|
|
40
|
+
| `@zappie/foundations/branch-list` | Nearest-first branch lists and what each branch sells |
|
|
39
41
|
| `@zappie/foundations/checkout` | Checkout behaviour for a bag or a cart page, with no markup |
|
|
40
42
|
| `@zappie/foundations/loyalty` | The rewards sheet's parts, the bag's rewards row and the claim toast |
|
|
41
43
|
| `@zappie/foundations/order` | A customer's order details page, as parts or one default layout |
|
|
42
44
|
| `@zappie/foundations/item-sheet` | A product sheet over the current page in a React Router site |
|
|
45
|
+
| `@zappie/foundations/bag` | The bag over the page, its address and the "added" notice |
|
|
46
|
+
| `@zappie/foundations/bag/server` | The `/cart` and `/checkout` redirects that open the bag |
|
|
43
47
|
| `@zappie/foundations/rich-text` | Sanitising and parsing merchant rich text before you render it |
|
|
44
48
|
|
|
45
49
|
## Docs
|
|
@@ -354,6 +358,82 @@ layout("routes/catalogue.tsx", [
|
|
|
354
358
|
|
|
355
359
|
An item opened from a page outside the layout replaces that page with the item route's page. The sheet needs React Router 8.4 or later.
|
|
356
360
|
|
|
361
|
+
## Bag
|
|
362
|
+
|
|
363
|
+
`@zappie/foundations/bag` is the bag's plumbing in a React Router site: whether it is open, its address, the frame it opens in and the notice that says a line went in. What the bag shows stays yours.
|
|
364
|
+
|
|
365
|
+
Opening the bag adds `?bag=open` to the address as a history entry of its own. Back closes the bag and leaves the shopper on the page, and a reload opens it again. React Router never sees that entry, so no loader runs and page views don't count it. A page that arrives with `?bag=open` opens the bag: a `/cart` or `/checkout` redirect, the return from "Sign in to pay", payment's cancel, a reload or a shared link. The page's own address loses `?bag=open` and the sign-in marker, so the page counts once. Going to another page closes the bag.
|
|
366
|
+
|
|
367
|
+
```tsx
|
|
368
|
+
// app/root.tsx
|
|
369
|
+
import { deferred, OverlayRetry } from "@zappie/foundations";
|
|
370
|
+
import { Bag, CartNotice } from "@zappie/foundations/bag";
|
|
371
|
+
|
|
372
|
+
const body = deferred(() => import("./ui/bag-body"));
|
|
373
|
+
const checkout = deferred(() => import("./ui/bag-checkout"));
|
|
374
|
+
|
|
375
|
+
<Bag.Root body={body} preload={[checkout]}>
|
|
376
|
+
<Header /> {/* <Bag.Trigger className="bag-button">Bag</Bag.Trigger> */}
|
|
377
|
+
<Outlet />
|
|
378
|
+
<Bag.Content
|
|
379
|
+
className="bag"
|
|
380
|
+
presentation={{ base: "drawer", lg: "sheet" }}
|
|
381
|
+
failed={(retry, close) => (
|
|
382
|
+
<OverlayRetry
|
|
383
|
+
message="Your bag didn't load."
|
|
384
|
+
retry={retry}
|
|
385
|
+
close={close}
|
|
386
|
+
/>
|
|
387
|
+
)}
|
|
388
|
+
/>
|
|
389
|
+
<CartNotice className="cart-notice">
|
|
390
|
+
{(notice) =>
|
|
391
|
+
notice.kind === "added" ? (
|
|
392
|
+
<>
|
|
393
|
+
Added {notice.line.name}.{" "}
|
|
394
|
+
<button type="button" onClick={notice.undo}>
|
|
395
|
+
Undo
|
|
396
|
+
</button>
|
|
397
|
+
</>
|
|
398
|
+
) : (
|
|
399
|
+
notice.message
|
|
400
|
+
)
|
|
401
|
+
}
|
|
402
|
+
</CartNotice>
|
|
403
|
+
</Bag.Root>;
|
|
404
|
+
|
|
405
|
+
// app/ui/bag-body.tsx
|
|
406
|
+
export default function BagBody({ close, empty }: BagBodyProps) {
|
|
407
|
+
return (
|
|
408
|
+
<>
|
|
409
|
+
<Bag.Title>Your bag</Bag.Title>
|
|
410
|
+
<Bag.Close aria-label="Close bag">×</Bag.Close>
|
|
411
|
+
{empty ? <EmptyBag onBrowse={close} /> : <Lines />}
|
|
412
|
+
</>
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// app/routes/cart.tsx
|
|
417
|
+
import { openBagAt } from "@zappie/foundations/bag/server";
|
|
418
|
+
export function loader({ request }: LoaderFunctionArgs) {
|
|
419
|
+
throw openBagAt(request, { to: "/menu" });
|
|
420
|
+
}
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
- `Bag.Root` goes around the shell once, inside the router. It takes `body` (the bag's content, loaded with `deferred()`), `preload` (other parts the bag shows, such as its checkout, which load with it but never hold it) and `inline`. Where the page shows the bag as a column, `inline` brings it into view and returns `true`, and nothing opens over it. `revealBagColumn(id, query)` does that for a column with an `id`, shown where a media query matches. The bag's code loads once the browser is idle, when a shopper reaches for a trigger and when a line goes in.
|
|
424
|
+
- `Bag.Content` is the bag. It is a foundations `Overlay`, with Escape, the focus trap, the scroll lock, drag to close on phones and the exit. It takes the props of `Overlay.Content`, `presentation` (`sheet` by default) and `failed`. It opens once its code is in, so it never paints unstyled, and focus returns to the control that opened it. It marks the dialog with `data-zappie-overlay="bag"`.
|
|
425
|
+
- The body receives `close` and `empty`. `empty` is true once the cart has loaded with no lines.
|
|
426
|
+
- `Bag.Trigger` is a button that opens the bag, marked `data-zappie-overlay-trigger="bag"`, with `aria-expanded`. Use `asChild` for your own button.
|
|
427
|
+
- `useBag()` gives `open`, `close`, `toggle` and `preload`. They never change, so a control that only opens the bag doesn't render again when it opens. `close()` resolves once the address is the page's again: navigate from inside the bag after it, with `bag.close().then(() => navigate(to))`. `useBagOpen()` says whether the bag is open.
|
|
428
|
+
- `hasBagParam(url)` says whether an address carries `?bag=open`, for page views and analytics. It takes a search string, a path, a URL or `URLSearchParams`. `BAG_PARAM` and `PAY_PARAM` are the query names.
|
|
429
|
+
- `openBagAt(request, { to })` from `@zappie/foundations/bag/server` answers `/cart` and `/checkout` with a 302 to `to` (`/` by default) with `?bag=open` and the request's query, such as the branch, marked `noindex`.
|
|
430
|
+
|
|
431
|
+
### Cart notice
|
|
432
|
+
|
|
433
|
+
`CartNotice` shows one message at a time over the page and the bag. It shows a change the server refused and the cart put back, such as "Only 2 left", or a line just added, with its Undo. Add with `useAddToBag()` instead of `useCart().actions.add` to raise "added". Its Undo takes the line out again, or puts it back to its quantity before when the add joined a line already in the bag.
|
|
434
|
+
|
|
435
|
+
The notice sits in the top layer, so it shows over an open bag. It leaves after `duration` (6 seconds by default), which waits while the pointer or focus is on it, and Escape dismisses it. Screen readers hear a line just added through a polite status (`announce` sets the words). They don't hear a refusal again, because the SDK has announced it. It has no styles of its own: pass `className` and render its content with `children`. `useCartNoticeValue()` gives the same notice for a notice of your own.
|
|
436
|
+
|
|
357
437
|
## Branch switch
|
|
358
438
|
|
|
359
439
|
Choosing a branch shows that branch's menu without waiting for the server. A
|
|
@@ -366,19 +446,9 @@ that don't use it never load it. Use it in a React Router root route:
|
|
|
366
446
|
import {
|
|
367
447
|
createBranchSwitchLoader,
|
|
368
448
|
useReloadingBranch,
|
|
369
|
-
} from "@zappie/foundations";
|
|
449
|
+
} from "@zappie/foundations/branch-switch";
|
|
370
450
|
|
|
371
451
|
const branchSwitch = createBranchSwitchLoader<ShopData>({
|
|
372
|
-
// What your loader returns for ?branch=<that branch>. Recompute every field
|
|
373
|
-
// that depends on the branch.
|
|
374
|
-
shopAt: (shop, branch, menu) => ({
|
|
375
|
-
...shop,
|
|
376
|
-
config: { ...shop.config, branch: branch.id },
|
|
377
|
-
branch,
|
|
378
|
-
menu,
|
|
379
|
-
branchChosen: true,
|
|
380
|
-
mustChoose: false,
|
|
381
|
-
}),
|
|
382
452
|
// Paths your loader redirects go to the server.
|
|
383
453
|
serverOnly: (url, shop) => Boolean(redirectFor(shop.store, url.pathname)),
|
|
384
454
|
});
|
|
@@ -396,34 +466,35 @@ export default function App() {
|
|
|
396
466
|
}
|
|
397
467
|
```
|
|
398
468
|
|
|
399
|
-
- `createBranchSwitchLoader({ shopAt
|
|
469
|
+
- `createBranchSwitchLoader({ shopAt?, serverOnly?, param? })` returns
|
|
400
470
|
`remember`, `shouldRevalidate` and `clientLoader`. Your loader data needs
|
|
401
471
|
`store`, `branch` and, when the shopper chooses a branch, `branchChosen`.
|
|
402
472
|
Without `branchChosen` the loaded branch counts as chosen.
|
|
403
473
|
- `clientLoader` builds the shop with `shopAt` from the shop the root last
|
|
404
474
|
rendered. An unknown branch, a `serverOnly` URL or a failed read calls
|
|
405
475
|
`serverLoader()`. A cancelled navigation throws.
|
|
476
|
+
- `shopAt` is what your loader returns for `?branch=<that branch>`. It
|
|
477
|
+
defaults to `shopAtBranch`, which sets `branch`, `menu` and
|
|
478
|
+
`config.branch`, marks the branch chosen and clears `mustChoose` where your
|
|
479
|
+
shop has them. Pass your own when another field depends on the branch, such
|
|
480
|
+
as a home link per branch.
|
|
406
481
|
- `shouldRevalidate` reloads the shop only for a link that names another
|
|
407
482
|
branch. A link without `?branch=` keeps the branch, and so does a link to the
|
|
408
483
|
branch already loaded and chosen. Form submissions keep React Router's rule.
|
|
409
484
|
- `reloadsShop`, `branchNamed` and `loadedBranchOf` are the rules behind them,
|
|
410
485
|
for your own code.
|
|
411
486
|
|
|
412
|
-
|
|
487
|
+
Choose a branch from a picker, a locator or a card:
|
|
413
488
|
|
|
414
489
|
```tsx
|
|
415
490
|
import {
|
|
491
|
+
useBranchChoice,
|
|
416
492
|
useBranchIntent,
|
|
417
|
-
useChooseBranch,
|
|
418
493
|
} from "@zappie/foundations/branch-switch";
|
|
419
494
|
|
|
420
495
|
function BranchCard({ branch }: { branch: Branch }) {
|
|
421
496
|
const intent = useBranchIntent(branch);
|
|
422
|
-
const
|
|
423
|
-
const choose = useChooseBranch((next) => {
|
|
424
|
-
rememberBranch(next.id);
|
|
425
|
-
navigate(`/menu?branch=${next.slug}`);
|
|
426
|
-
});
|
|
497
|
+
const choose = useBranchChoice({ cookie: "site_branch", to: "/menu" });
|
|
427
498
|
return (
|
|
428
499
|
<button type="button" {...intent} onClick={() => void choose(branch)}>
|
|
429
500
|
Order from {branch.name}
|
|
@@ -435,10 +506,24 @@ function BranchCard({ branch }: { branch: Branch }) {
|
|
|
435
506
|
- `useBranchIntent(branch)` returns `{ onPointerEnter, onPointerDown, onFocus }`.
|
|
436
507
|
Each starts the branch's menu read. The client shares one read per branch,
|
|
437
508
|
so the click and the loader reuse it.
|
|
438
|
-
- `
|
|
439
|
-
branch,
|
|
440
|
-
|
|
441
|
-
the
|
|
509
|
+
- `useBranchChoice({ cookie?, rememberBy?, to?, param?, then? })` returns
|
|
510
|
+
`choose(branch, destination?)`. It starts the menu read, moves a bag with
|
|
511
|
+
lines to the branch, keeps the choice in `cookie`, and navigates to the
|
|
512
|
+
destination with the branch in its address. The cookie keeps the branch ID
|
|
513
|
+
unless `rememberBy` is `"slug"`. Give the server's `loadStoreAndMenu` (in
|
|
514
|
+
`@zappie/sdk/server`) the same cookie, and the page cache its
|
|
515
|
+
`branchCookie`. Without a destination the shopper goes to `to`, `/` by
|
|
516
|
+
default, or to what `to(branch)` returns. A destination is
|
|
517
|
+
`{ path, state?, replace?, preventScrollReset? }`, so a finder opened from an
|
|
518
|
+
item can go back to it with the line chosen so far. `then(branch,
|
|
519
|
+
destination)` runs once the navigation has started: close the finder there,
|
|
520
|
+
or scroll to the menu. Call it inside the router.
|
|
521
|
+
- `useRememberLinkedBranch(branch, { cookie, rememberBy?, param? })` keeps a
|
|
522
|
+
branch a link names in the cookie, so pages without `?branch=` stay on it.
|
|
523
|
+
- `rememberBranch(cookie, value)` and `atBranch(path, branch, param?)` are the
|
|
524
|
+
pieces, for your own code.
|
|
525
|
+
- `useChooseBranch(then)` only moves the bag and calls `then` once the move is
|
|
526
|
+
done, for a choice that remembers and navigates its own way.
|
|
442
527
|
|
|
443
528
|
Show your own skeleton while the shop reloads for a branch:
|
|
444
529
|
|
|
@@ -458,6 +543,113 @@ return reloading?.pathname === "/menu" ? (
|
|
|
458
543
|
`{ branch, pathname }` while a navigation reloads the shop for a branch the
|
|
459
544
|
store has, and undefined otherwise.
|
|
460
545
|
|
|
546
|
+
## Branch finder
|
|
547
|
+
|
|
548
|
+
`@zappie/foundations/branch-finder` opens the site's own branch picker or
|
|
549
|
+
locator from the header, the hero, an item card or the footer. Its code loads
|
|
550
|
+
with `deferred()`, starts loading when a shopper reaches for a control, and
|
|
551
|
+
mounts on the first open. The finder's look, its list and its frame stay
|
|
552
|
+
yours.
|
|
553
|
+
|
|
554
|
+
```tsx
|
|
555
|
+
import { deferred, OverlayRetry } from "@zappie/foundations";
|
|
556
|
+
import { BranchFinder } from "@zappie/foundations/branch-finder";
|
|
557
|
+
|
|
558
|
+
const finder = deferred(() => import("./ui/branch-dialog"));
|
|
559
|
+
|
|
560
|
+
<BranchFinder.Root
|
|
561
|
+
finder={finder}
|
|
562
|
+
preloadWhenIdle
|
|
563
|
+
failed={(retry, close) => (
|
|
564
|
+
<OverlayRetry
|
|
565
|
+
message="The branch list didn't load."
|
|
566
|
+
retry={retry}
|
|
567
|
+
close={close}
|
|
568
|
+
/>
|
|
569
|
+
)}
|
|
570
|
+
>
|
|
571
|
+
<Header />{" "}
|
|
572
|
+
{/* <BranchFinder.Trigger className="branch">Choose a branch</BranchFinder.Trigger> */}
|
|
573
|
+
<Outlet />
|
|
574
|
+
</BranchFinder.Root>;
|
|
575
|
+
|
|
576
|
+
// app/ui/branch-dialog.tsx
|
|
577
|
+
export default function BranchDialog({
|
|
578
|
+
open,
|
|
579
|
+
onClose,
|
|
580
|
+
then,
|
|
581
|
+
}: BranchFinderProps) {
|
|
582
|
+
const choose = useBranchChoice({
|
|
583
|
+
cookie: "site_branch",
|
|
584
|
+
to: "/menu",
|
|
585
|
+
then: onClose,
|
|
586
|
+
});
|
|
587
|
+
// … each branch calls choose(branch, then)
|
|
588
|
+
}
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
- `BranchFinder.Root` goes around the shell once. It renders `finder` with
|
|
592
|
+
`open`, `onClose` and `then`, the destination the control asked for.
|
|
593
|
+
`preloadWhenIdle` loads its code once the page is idle. `failed` shows while
|
|
594
|
+
open when the code didn't load.
|
|
595
|
+
- `BranchFinder.Trigger` is a button marked
|
|
596
|
+
`data-zappie-overlay-trigger="branch"` with `aria-haspopup="dialog"`. `then`
|
|
597
|
+
is where the shopper goes once they choose, such as the item the card
|
|
598
|
+
shows. Your `onClick` runs first and can cancel with `preventDefault()`. Use
|
|
599
|
+
`asChild` for your own button.
|
|
600
|
+
- `useBranchFinder()` gives `open(then?)` and `close()`. They never change.
|
|
601
|
+
|
|
602
|
+
## Branch list
|
|
603
|
+
|
|
604
|
+
`@zappie/foundations/branch-list` is the data behind a picker or a locator:
|
|
605
|
+
the branches nearest first, and what each one sells. It loads only on the
|
|
606
|
+
pages that use it.
|
|
607
|
+
|
|
608
|
+
```tsx
|
|
609
|
+
import {
|
|
610
|
+
kilometres,
|
|
611
|
+
menusLabel,
|
|
612
|
+
nearestFirst,
|
|
613
|
+
useBranchOffers,
|
|
614
|
+
useHere,
|
|
615
|
+
whereIs,
|
|
616
|
+
} from "@zappie/foundations/branch-list";
|
|
617
|
+
|
|
618
|
+
const { here, locate, locating, refused } = useHere();
|
|
619
|
+
const offers = useBranchOffers(store.branches, { active: open });
|
|
620
|
+
<button type="button" onClick={locate} disabled={locating}>
|
|
621
|
+
Use my location
|
|
622
|
+
</button>;
|
|
623
|
+
{
|
|
624
|
+
nearestFirst(store.branches, here).map((branch) => (
|
|
625
|
+
<BranchCard
|
|
626
|
+
key={branch.id}
|
|
627
|
+
branch={branch}
|
|
628
|
+
menus={offers[branch.id]?.menus}
|
|
629
|
+
/>
|
|
630
|
+
));
|
|
631
|
+
}
|
|
632
|
+
```
|
|
633
|
+
|
|
634
|
+
- `useHere(timeout?)` asks the browser where the shopper is when `locate`
|
|
635
|
+
runs, never before. It gives `here`, `setHere`, `locating`, `refused` and
|
|
636
|
+
`locate`. `refused` is true when the shopper says no, the browser has no
|
|
637
|
+
location or the lookup fails. `setHere` takes a location from elsewhere,
|
|
638
|
+
such as a saved address.
|
|
639
|
+
- `nearestFirst(branches, here)` sorts nearest first, puts a branch with no
|
|
640
|
+
location last and keeps ties in order. Without `here` the order stays.
|
|
641
|
+
- `whereIs(branch)` is the branch's pin, else its pickup point's. A pin at
|
|
642
|
+
0, 0 counts as none. `kilometres(from, to)` is the distance along the
|
|
643
|
+
earth's surface.
|
|
644
|
+
- `useBranchOffers(branches, { active?, typesOf? })` reads each branch's menus
|
|
645
|
+
without their items, once per branch for the page's life. It returns
|
|
646
|
+
`{ menus, types }` by branch ID: the names of menus that have categories, and
|
|
647
|
+
the order types they take, from `checkoutOffers` unless you pass `typesOf`.
|
|
648
|
+
A branch is absent until its answer arrives and stays absent when the read
|
|
649
|
+
fails. An empty `menus` means it has nothing to sell yet.
|
|
650
|
+
- `menusLabel(names)` joins the names with " · ", and reads "Breakfast only"
|
|
651
|
+
for one.
|
|
652
|
+
|
|
461
653
|
## Item form focus
|
|
462
654
|
|
|
463
655
|
When an add fails validation, `ItemForm.Root` focuses the first invalid group
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { O as OverlayQuery } from '../history-BlytQinP.js';
|
|
2
|
+
import { P as PartOwnedAttributes } from '../slot-CHfqzPTd.js';
|
|
3
|
+
import * as react from 'react';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
5
|
+
import { CartLine, Item, CartLineInput } from '@zappie/sdk';
|
|
6
|
+
import { Deferred } from '../index.js';
|
|
7
|
+
import { O as OverlayContentProps, R as ResponsivePresentation } from '../react-C1KQB_W3.js';
|
|
8
|
+
import '../overlay/engine.js';
|
|
9
|
+
import '@base-ui/react/dialog';
|
|
10
|
+
|
|
11
|
+
/** The query that opens the bag: `/cart`, `/checkout`, sign-in's return, payment's cancel and an open bag's address carry it. */
|
|
12
|
+
declare const BAG_PARAM = "bag";
|
|
13
|
+
|
|
14
|
+
/** The query that marks a return from "Sign in to pay". The bag takes it off the address with its own. */
|
|
15
|
+
declare const PAY_PARAM = "zappie_pay";
|
|
16
|
+
/**
|
|
17
|
+
* Whether an address carries the bag parameter. Page views and analytics wait it out, so the address the bag
|
|
18
|
+
* leaves behind counts once. Takes a search string (`?bag=open`), a path, a full URL, a `URL` or `URLSearchParams`.
|
|
19
|
+
*/
|
|
20
|
+
declare function hasBagParam(url: string | URL | URLSearchParams): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Bring a column that shows the bag inside the page into view, and say whether it shows: the element with `id`
|
|
23
|
+
* exists and, when given, `query` matches. Use it in `Bag.Root`'s `inline`, so the bag button scrolls to the column
|
|
24
|
+
* instead of opening the bag over it. A column already on screen stays put, and focus stays where it was.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* <Bag.Root body={body} inline={() => revealBagColumn("bag-column", "(min-width: 1280px)")}>
|
|
28
|
+
*/
|
|
29
|
+
declare function revealBagColumn(id: string, query?: string): boolean;
|
|
30
|
+
/** The controls from `useBag()`. They never change, so a control that only opens the bag doesn't render again. */
|
|
31
|
+
type BagControls = {
|
|
32
|
+
/** Open the bag over the page. Back closes it. */
|
|
33
|
+
open: () => void;
|
|
34
|
+
/**
|
|
35
|
+
* Close the bag. It resolves once the address is the page's again, so navigate from inside the bag after it:
|
|
36
|
+
* `bag.close().then(() => navigate(to))`.
|
|
37
|
+
*/
|
|
38
|
+
close: () => Promise<void>;
|
|
39
|
+
/** Open a closed bag, close an open one. */
|
|
40
|
+
toggle: () => void;
|
|
41
|
+
/** Start loading the bag's body, the overlay engine and the root's `preload` parts. */
|
|
42
|
+
preload: () => void;
|
|
43
|
+
};
|
|
44
|
+
/** What the site's bag body receives. */
|
|
45
|
+
type BagBodyProps = {
|
|
46
|
+
/** Close the bag, as its close button does. */
|
|
47
|
+
close: () => Promise<void>;
|
|
48
|
+
/** The cart has loaded and has no lines: show the empty state. */
|
|
49
|
+
empty: boolean;
|
|
50
|
+
};
|
|
51
|
+
type Preloadable = {
|
|
52
|
+
preload(): Promise<unknown>;
|
|
53
|
+
};
|
|
54
|
+
/** The controls that open and close the bag, inside `Bag.Root`. */
|
|
55
|
+
declare function useBag(): BagControls;
|
|
56
|
+
/** Whether the bag is open. Only what shows the bag should read it, so opening renders that alone. */
|
|
57
|
+
declare function useBagOpen(): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Holds the bag for the pages under it. Put it around the shell once, inside the router.
|
|
60
|
+
*
|
|
61
|
+
* Opening the bag adds a history entry with `?bag=open`, so Back closes the bag and leaves the shopper on the page,
|
|
62
|
+
* and a reload opens it again. React Router never sees that entry, so no loader runs and page views don't count it.
|
|
63
|
+
* A page that arrives with `?bag=open` (a `/cart` redirect, sign-in's return, payment's cancel, a reload or a shared
|
|
64
|
+
* link) opens the bag and takes `?bag=open` and the sign-in marker off the page's own address, so the page counts
|
|
65
|
+
* once. Going to another page closes the bag. The bag's code loads when the browser is idle.
|
|
66
|
+
*/
|
|
67
|
+
declare function Root({ body, preload, inline, children, }: {
|
|
68
|
+
/** The site's bag body: `deferred(() => import("./bag-body"))`. Its default export takes `BagBodyProps`. */
|
|
69
|
+
body: Deferred<BagBodyProps>;
|
|
70
|
+
/** Other parts the bag shows, such as its checkout. They load with the body but never hold it. */
|
|
71
|
+
preload?: Preloadable[];
|
|
72
|
+
/** Where the page shows the bag as a column, bring it into view and return `true`: nothing opens over it. */
|
|
73
|
+
inline?: () => boolean;
|
|
74
|
+
children?: ReactNode;
|
|
75
|
+
}): react.JSX.Element;
|
|
76
|
+
/** Props for `Bag.Content`: the dialog's own props, its presentation and its failure state. */
|
|
77
|
+
type BagContentProps = Omit<OverlayContentProps, "children" | "forceMount"> & {
|
|
78
|
+
/** A `sheet` or `drawer` drags to close on phones. Use `{ base, md, … }` for responsive layouts. Defaults to `sheet`. */
|
|
79
|
+
presentation?: ResponsivePresentation;
|
|
80
|
+
/** Shown when the bag's code, or the overlay engine, didn't load. `retry` loads it again. */
|
|
81
|
+
failed: (retry: () => void, close: () => void) => ReactNode;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* The bag itself: a foundations `Overlay` (focus trap, Escape, scroll lock, drag to close and the exit) holding the
|
|
85
|
+
* site's body. It opens once the body's code is in, so it never paints unstyled, and focus goes back to the control
|
|
86
|
+
* that opened it. A line added to the cart starts loading the bag, since an open usually follows.
|
|
87
|
+
*/
|
|
88
|
+
declare function Content({ presentation, failed, ...props }: BagContentProps): react.JSX.Element;
|
|
89
|
+
/**
|
|
90
|
+
* The bag over the page, for React Router route modules. `Root` goes around the shell, `Content` anywhere under it,
|
|
91
|
+
* and `Trigger` on the bag button. The body is the site's own, loaded with `deferred()`.
|
|
92
|
+
*/
|
|
93
|
+
declare const Bag: {
|
|
94
|
+
Root: typeof Root;
|
|
95
|
+
Content: typeof Content;
|
|
96
|
+
Trigger: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
|
|
97
|
+
asChild?: boolean;
|
|
98
|
+
children?: ReactNode | ((state: BagControls) => ReactNode);
|
|
99
|
+
} & react.RefAttributes<HTMLElement>>;
|
|
100
|
+
Title: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
|
|
101
|
+
asChild?: boolean;
|
|
102
|
+
children?: ReactNode | ((state: {
|
|
103
|
+
isOpen: boolean;
|
|
104
|
+
open: (query?: OverlayQuery) => void;
|
|
105
|
+
close: () => void;
|
|
106
|
+
}) => ReactNode);
|
|
107
|
+
} & react.RefAttributes<HTMLElement>>;
|
|
108
|
+
Close: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
|
|
109
|
+
asChild?: boolean;
|
|
110
|
+
children?: ReactNode | ((state: {
|
|
111
|
+
isOpen: boolean;
|
|
112
|
+
open: (query?: OverlayQuery) => void;
|
|
113
|
+
close: () => void;
|
|
114
|
+
}) => ReactNode);
|
|
115
|
+
} & react.RefAttributes<HTMLElement>>;
|
|
116
|
+
};
|
|
117
|
+
/** A line just added, from `useAddToBag()`. `undo` takes it out again, or back to its quantity before. */
|
|
118
|
+
type AddedNotice = {
|
|
119
|
+
kind: "added";
|
|
120
|
+
id: number;
|
|
121
|
+
line: CartLine;
|
|
122
|
+
undo: () => void;
|
|
123
|
+
};
|
|
124
|
+
/** What `CartNotice` shows: a change the server refused and the cart put back, or a line just added. */
|
|
125
|
+
type CartNoticeValue = {
|
|
126
|
+
kind: "refused";
|
|
127
|
+
id: number;
|
|
128
|
+
code: string;
|
|
129
|
+
message: string;
|
|
130
|
+
} | AddedNotice;
|
|
131
|
+
/**
|
|
132
|
+
* Add to the cart as `useCart().actions.add` does, and show "added" in `CartNotice` with an Undo. Undo takes the line
|
|
133
|
+
* out again, or puts it back to its quantity before when the add joined a line already in the bag.
|
|
134
|
+
*/
|
|
135
|
+
declare function useAddToBag(): (item: Item | string, input?: Omit<CartLineInput, "itemId">, options?: {
|
|
136
|
+
key?: string;
|
|
137
|
+
}) => CartLine;
|
|
138
|
+
/** The notice `CartNotice` shows now, the newer of a refusal and an add, and `dismiss` to clear it. */
|
|
139
|
+
declare function useCartNoticeValue(): {
|
|
140
|
+
notice: CartNoticeValue | null;
|
|
141
|
+
dismiss: () => void;
|
|
142
|
+
};
|
|
143
|
+
/** Props for `CartNotice`. */
|
|
144
|
+
type CartNoticeProps = {
|
|
145
|
+
/** Milliseconds before it leaves, counted while neither the pointer nor focus is on it. Defaults to 6000. */
|
|
146
|
+
duration?: number;
|
|
147
|
+
/** What screen readers hear for a line just added. Defaults to "{name} added to your bag." */
|
|
148
|
+
announce?: (notice: AddedNotice) => string;
|
|
149
|
+
/** Your class. The notice has no styles of its own. */
|
|
150
|
+
className?: string;
|
|
151
|
+
/**
|
|
152
|
+
* What it shows. Render a button that calls `notice.undo` for a line just added. Defaults to a refusal's message,
|
|
153
|
+
* and nothing for an add.
|
|
154
|
+
*/
|
|
155
|
+
children?: (notice: CartNoticeValue, dismiss: () => void) => ReactNode;
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* One message at a time over the page and the bag: a change the server refused and the cart put back, such as
|
|
159
|
+
* "Only 2 left", or a line `useAddToBag()` just added, with its Undo. It sits in the top layer, so it shows over an
|
|
160
|
+
* open bag, and leaves after `duration`; Escape dismisses it. A line just added is announced politely to screen
|
|
161
|
+
* readers. A refusal isn't, because the SDK has announced it. Render it once, in the shell.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* <CartNotice className="notice">
|
|
165
|
+
* {(notice) => notice.kind === "added"
|
|
166
|
+
* ? <>Added {notice.line.name}. <button type="button" onClick={notice.undo}>Undo</button></>
|
|
167
|
+
* : notice.message}
|
|
168
|
+
* </CartNotice>
|
|
169
|
+
*/
|
|
170
|
+
declare function CartNotice({ duration, announce, className, children, }: CartNoticeProps): react.JSX.Element;
|
|
171
|
+
|
|
172
|
+
export { BAG_PARAM, Bag, CartNotice, PAY_PARAM, hasBagParam, revealBagColumn, useAddToBag, useBag, useBagOpen, useCartNoticeValue };
|
|
173
|
+
export type { AddedNotice, BagBodyProps, BagContentProps, BagControls, CartNoticeProps, CartNoticeValue };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";import{useCart,useCartNotice,useZappie}from"@zappie/sdk/react";import{createContext,forwardRef,Fragment,useCallback,useContext,useEffect,useMemo,useRef,useState,useSyncExternalStore}from"react";import{useLocation,useNavigate}from"react-router";import{part}from"../internal/slot.js";import{DeferredHost,loadBody}from"../overlay/deferred-host.js";import{Overlay}from"../overlay/react.js";import{BAG_PARAM}from"./param.js";import{jsx,jsxs}from"react/jsx-runtime";var PAY_PARAM="zappie_pay";var MARK="__zappieBag";function hasBagParam(url){const query=typeof url==="string"?new URL(url===""||/^(\?|\/|[a-z][a-z\d+.-]*:)/i.test(url)?url:`?${url}`,"https://bag.invalid").searchParams:url instanceof URL?url.searchParams:url;return query.has(BAG_PARAM)}function revealBagColumn(id,query){const column=document.getElementById(id);if(!column||query&&!window.matchMedia(query).matches){return false}const box=column.getBoundingClientRect();if(box.top>=window.innerHeight||box.bottom<=0){column.scrollIntoView({block:"nearest",behavior:window.matchMedia("(prefers-reduced-motion: reduce)").matches?"auto":"smooth"})}return true}var Controls=/*@__PURE__ */createContext(null);var Open=/*@__PURE__ */createContext(false);function useShared(){const value=useContext(Controls);if(!value){throw new Error("Bag parts require Bag.Root")}return value}function useBag(){return useShared()}function useBagOpen(){return useContext(Open)}var ignore=()=>{};var marked=state=>!!state?.[MARK];function pageOf(href){const url=new URL(href,window.location.href);url.searchParams.delete(BAG_PARAM);return url.pathname+url.search}function write(push){const url=new URL(window.location.href);url.searchParams.set(BAG_PARAM,"open");const history=Object.getPrototypeOf(window.history);history[push?"pushState":"replaceState"].call(window.history,{...window.history.state,[MARK]:1},"",url.href)}function Root({body,preload=[],inline,children}){const[open,setOpen]=useState(false);const location=useLocation();const navigate=useNavigate();const opener=useRef(null);const latest=useRef({open,inline,location,preload,page:location.pathname,closing:[]});Object.assign(latest.current,{inline,location,preload});const controls=useMemo(()=>{const set=value=>{latest.current.open=value;setOpen(value)};const show=()=>{if(latest.current.open||latest.current.inline?.()){return}opener.current=document.activeElement instanceof HTMLElement?document.activeElement:null;set(true);write(true)};const close=()=>new Promise(resolve=>{if(latest.current.open){set(false)}if(marked(window.history.state)){latest.current.closing.push(resolve);window.history.back()}else{resolve()}});return{open:show,close,toggle:()=>{if(latest.current.open){void close()}else{show()}},preload:()=>{loadBody(body).catch(ignore);for(const part2 of latest.current.preload){part2.preload().catch(ignore)}},body,opener}},[body]);useEffect(()=>{const onPop=event=>{const{location:location2,open:open2,closing}=latest.current;const bag=marked(event.state)&&hasBagParam(window.location.href);if(pageOf(window.location.href)===pageOf(location2.pathname+location2.search)&&(bag||open2||closing.length>0)){event.stopImmediatePropagation();latest.current.open=bag;setOpen(bag);latest.current.closing=[];closing.forEach(resolve=>resolve())}};window.addEventListener("popstate",onPop,true);return()=>window.removeEventListener("popstate",onPop,true)},[]);useEffect(()=>{const state=latest.current;const query=new URLSearchParams(location.search);if(query.get(BAG_PARAM)!=="open"){if(state.page!==location.pathname&&state.open){state.open=false;setOpen(false)}state.page=location.pathname;return}state.page=location.pathname;const again=marked(window.history.state);query.delete(BAG_PARAM);query.delete(PAY_PARAM);const shown=!state.inline?.();state.open=shown;setOpen(shown);void Promise.resolve(navigate(location.pathname+(query.size?`?${query}`:"")+location.hash,{replace:true,preventScrollReset:true,state:location.state})).then(()=>{if(latest.current.open){write(!again)}})},[location.key]);useEffect(()=>{if(typeof window.requestIdleCallback==="function"){const handle2=window.requestIdleCallback(controls.preload);return()=>window.cancelIdleCallback(handle2)}const handle=window.setTimeout(controls.preload,1);return()=>window.clearTimeout(handle)},[controls]);return jsx(Controls.Provider,{value:controls,children:jsx(Open.Provider,{value:open,children})})}function Content({presentation="sheet",failed,...props}){const{body,close,opener,open:show,preload}=useShared();const open=useBagOpen();const cart=useCart();const lines=cart.isHydrated?cart.lines.length:void 0;const before=useRef(lines);useEffect(()=>{if(lines!==void 0&&(before.current??lines)<lines){preload()}before.current=lines},[lines,preload]);const navigation=useMemo(()=>({isOpen:open,open:show,close:()=>void close(),trigger:opener}),[open,show,close,opener]);return jsx(DeferredHost,{body,param:BAG_PARAM,id:"open",navigation,presentation,failed,props,children:jsx(body.Component,{open:true,close,empty:cart.isHydrated&&cart.lines.length===0})})}var Trigger=/*@__PURE__ */forwardRef(function Trigger2(props,ref){const bag=useShared();return part("button",props,bag,{type:"button","aria-haspopup":"dialog","aria-expanded":useBagOpen(),"data-zappie-overlay-trigger":"bag",onPointerEnter:bag.preload,onPointerDown:bag.preload,onFocus:bag.preload,onClick:bag.open},ref)});var Bag={Root,Content,Trigger,Title:Overlay.Title,Close:Overlay.Close};var stores=new WeakMap;function storeFor(cart){let store=stores.get(cart);if(!store){store={value:null,listeners:new Set};stores.set(cart,store)}return store}function put(store,value){store.value=value;store.listeners.forEach(listener=>listener())}var sequence=0;function useAddToBag(){const{cart}=useZappie();const{actions}=useCart();return useCallback((item,input,options)=>{const before=new Map(cart.lines.map(entry=>[entry.id,entry]));const line=actions.add(item,input,options);const was=before.get(line.id);const store=storeFor(cart);put(store,{kind:"added",id:++sequence,line,undo:()=>{if(was){actions.update(line.id,{quantity:was.quantity})}else{actions.remove(line.id)}put(store,null)}});return line},[cart,actions])}function useCartNoticeValue(){const{cart}=useZappie();const refused=useCartNotice();const store=storeFor(cart);const subscribe=useCallback(listener=>{store.listeners.add(listener);return()=>{store.listeners.delete(listener)}},[store]);const added=useSyncExternalStore(subscribe,()=>store.value,()=>null);const[seen,setSeen]=useState({at:0});if(refused.notice&&refused.notice.id!==seen.id){setSeen({id:refused.notice.id,at:++sequence})}const notice=refused.notice&&(!added||seen.at>added.id)?{kind:"refused",...refused.notice,id:seen.at}:added;const{dismiss:dismissRefused}=refused;const dismiss=useCallback(()=>{dismissRefused();put(store,null)},[dismissRefused,store]);return{notice,dismiss}}var HIDDEN={position:"absolute",width:1,height:1,overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"};function CartNotice({duration=6e3,announce=notice=>`${notice.line.name} added to your bag.`,className,children=notice=>notice.kind==="refused"?notice.message:null}){const{notice,dismiss}=useCartNoticeValue();const ref=useRef(null);const[held,setHeld]=useState(false);const id=notice?.id;useEffect(()=>{setHeld(false);const node=ref.current;if(id===void 0||!node){return}node.showPopover?.();const hold=()=>setHeld(true);const release=()=>setHeld(false);const onKey=event=>{if(event.key==="Escape"){dismiss()}};const listeners=[["pointerenter",hold],["pointerleave",release],["focusin",hold],["focusout",release],["keydown",onKey]];for(const[type,listener]of listeners){node.addEventListener(type,listener)}return()=>{for(const[type,listener]of listeners){node.removeEventListener(type,listener)}}},[id,dismiss]);useEffect(()=>{if(id===void 0||held){return}const timer=setTimeout(dismiss,duration);return()=>clearTimeout(timer)},[id,held,duration,dismiss]);const shown=notice?children(notice,dismiss):null;return jsxs(Fragment,{children:[jsx("p",{role:"status",style:HIDDEN,"data-zappie-cart-announcer":"",children:notice?.kind==="added"?announce(notice):""}),notice&&shown!=null&&shown!==false&&jsx("div",{ref,popover:"manual",className,"data-zappie-cart-notice":notice.kind==="refused"?notice.code:"added",children:shown},notice.id)]})}export{BAG_PARAM,Bag,CartNotice,PAY_PARAM,hasBagParam,revealBagColumn,useAddToBag,useBag,useBagOpen,useCartNoticeValue};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/bag/index.tsx"],
|
|
4
|
+
"mappings": "aAEA,OAAS,QAAS,cAAe,cAAiB,oBAClD,OACE,cACA,WACA,SACA,YACA,WACA,UACA,QACA,OACA,SACA,yBAEK,QACP,OAAS,YAAa,gBAAmB,eAEzC,OAAS,SAA4B,sBACrC,OAAS,aAAc,aAAgB,8BACvC,OACE,YAGK,sBAEP,OAAS,cAAiB,aA4QpB,WAqSF,SArSE,oBAxQC,IAAM,UAAY,aAEzB,IAAM,KAAO,cAMN,SAAS,YAAY,IAA8C,CACxE,MAAM,MACJ,OAAO,MAAQ,SACX,IAAI,IACF,MAAQ,IAAM,8BAA8B,KAAK,GAAG,EAChD,IACA,IAAI,GAAG,GACX,qBACF,EAAE,aACF,eAAe,IACb,IAAI,aACJ,IACR,OAAO,MAAM,IAAI,SAAS,CAC5B,CAUO,SAAS,gBAAgB,GAAY,MAAyB,CACnE,MAAM,OAAS,SAAS,eAAe,EAAE,EACzC,GAAI,CAAC,QAAW,OAA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Y,CAChB,CAAC,eAAgB,IAAI,EACrB,CAAC,eAAgB,OAAO,EACxB,CAAC,UAAW,IAAI,EAChB,CAAC,WAAY,OAAO,EACpB,CAAC,UAAW,KAAK,CACnB,EACA,SAAW,CAAC,KAAM,QAAQ,IAAK,UAAW,CACxC,KAAK,iBAAiB,KAAM,QAAyB,CACvD,CACA,MAAO,IAAM,CACX,SAAW,CAAC,KAAM,QAAQ,IAAK,UAAW,CACxC,KAAK,oBAAoB,KAAM,QAAyB,CAC1D,CACF,CACF,EAAG,CAAC,GAAI,OAAO,CAAC,EAChB,UAAU,IAAM,CACd,GAAI,KAAO,QAAa,KAAM,CAC5B,MACF,CACA,MAAM,MAAQ,WAAW,QAAS,QAAQ,EAC1C,MAAO,IAAM,aAAa,KAAK,CACjC,EAAG,CAAC,GAAI,KAAM,SAAU,OAAO,CAAC,EAChC,MAAM,MAAQ,OAAS,SAAS,OAAQ,OAAO,EAAI,KACnD,OACE,KAAC,UACC,cAAC,KAAE,KAAK,SAAS,MAAO,OAAQ,6BAA2B,GACxD,iBAAQ,OAAS,QAAU,SAAS,MAAM,EAAI,GACjD,EACC,QAAU,OAAS,MAAQ,QAAU,OACpC,IAAC,OAEC,IACA,QAAQ,SACR,UACA,0BACE,OAAO,OAAS,UAAY,OAAO,KAAO,QAG3C,gBARI,OAAO,EASd,GAEJ,CAEJ",
|
|
5
|
+
"names": ["part", "location", "open", "handle", "Trigger"]
|
|
6
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Answer a request for `/cart` or `/checkout` with a 302 to the page the bag opens over, with `?bag=open` and the
|
|
3
|
+
* request's own query, such as the branch. The bag is the only review, so those paths have no page. A 302, not a 301,
|
|
4
|
+
* so a merchant can add a page there later, and `X-Robots-Tag: noindex` keeps the redirect out of search.
|
|
5
|
+
*
|
|
6
|
+
* @param request - The request for `/cart` or `/checkout`.
|
|
7
|
+
* @param options - `to`: the path the bag opens over, such as `/menu`. Defaults to `/`.
|
|
8
|
+
* @example
|
|
9
|
+
* export function loader({ request }: LoaderFunctionArgs) {
|
|
10
|
+
* throw openBagAt(request, { to: "/menu" });
|
|
11
|
+
* }
|
|
12
|
+
*/
|
|
13
|
+
declare function openBagAt(request: Request, { to }?: {
|
|
14
|
+
to?: string;
|
|
15
|
+
}): Response;
|
|
16
|
+
|
|
17
|
+
export { openBagAt };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{safeRedirect}from"@zappie/sdk/redirect";import{BAG_PARAM}from"./param.js";function openBagAt(request,{to="/"}={}){const target=new URL(to,"https://bag.invalid");new URL(request.url).searchParams.forEach((value,key)=>target.searchParams.set(key,value));target.searchParams.set(BAG_PARAM,"open");return new Response(null,{status:302,headers:{Location:safeRedirect(target.pathname+target.search,`${target.pathname}?${BAG_PARAM}=open`),"X-Robots-Tag":"noindex"}})}export{openBagAt};
|
|
2
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/bag/server.ts"],
|
|
4
|
+
"mappings": "AAAA,OAAS,iBAAoB,uBAC7B,OAAS,cAAiB,aAcnB,SAAS,UACd,QACA,CAAE,GAAK,GAAI,EAAqB,CAAC,EACvB,CACV,MAAM,OAAS,IAAI,IAAI,GAAI,qBAAqB,EAChD,IAAI,IAAI,QAAQ,GAAG,EAAE,aAAa,QAAQ,CAAC,MAAO,MAChD,OAAO,aAAa,IAAI,IAAK,KAAK,CACpC,EACA,OAAO,aAAa,IAAI,UAAW,MAAM,EACzC,OAAO,IAAI,SAAS,KAAM,CACxB,OAAQ,IACR,QAAS,CACP,SAAU,aACR,OAAO,SAAW,OAAO,OACzB,GAAG,OAAO,QAAQ,IAAI,SAAS,OACjC,EACA,eAAgB,SAClB,CACF,CAAC,CACH",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|