@zappie/foundations 0.17.0 → 0.18.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 CHANGED
@@ -1,5 +1,22 @@
1
1
  # @zappie/foundations
2
2
 
3
+ ## 0.18.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 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`.
8
+
9
+ `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.
10
+
11
+ `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.
12
+
13
+ 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.
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [b5b272b]
18
+ - @zappie/sdk@0.19.0
19
+
3
20
  ## 0.17.0
4
21
 
5
22
  ### Minor Changes
package/README.md CHANGED
@@ -40,6 +40,8 @@ Want ready-made, styled components instead? Copy them into your project from the
40
40
  | `@zappie/foundations/loyalty` | The rewards sheet's parts, the bag's rewards row and the claim toast |
41
41
  | `@zappie/foundations/order` | A customer's order details page, as parts or one default layout |
42
42
  | `@zappie/foundations/item-sheet` | A product sheet over the current page in a React Router site |
43
+ | `@zappie/foundations/bag` | The bag over the page, its address and the "added" notice |
44
+ | `@zappie/foundations/bag/server` | The `/cart` and `/checkout` redirects that open the bag |
43
45
  | `@zappie/foundations/rich-text` | Sanitising and parsing merchant rich text before you render it |
44
46
 
45
47
  ## Docs
@@ -354,6 +356,82 @@ layout("routes/catalogue.tsx", [
354
356
 
355
357
  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
358
 
359
+ ## Bag
360
+
361
+ `@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.
362
+
363
+ 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.
364
+
365
+ ```tsx
366
+ // app/root.tsx
367
+ import { deferred, OverlayRetry } from "@zappie/foundations";
368
+ import { Bag, CartNotice } from "@zappie/foundations/bag";
369
+
370
+ const body = deferred(() => import("./ui/bag-body"));
371
+ const checkout = deferred(() => import("./ui/bag-checkout"));
372
+
373
+ <Bag.Root body={body} preload={[checkout]}>
374
+ <Header /> {/* <Bag.Trigger className="bag-button">Bag</Bag.Trigger> */}
375
+ <Outlet />
376
+ <Bag.Content
377
+ className="bag"
378
+ presentation={{ base: "drawer", lg: "sheet" }}
379
+ failed={(retry, close) => (
380
+ <OverlayRetry
381
+ message="Your bag didn't load."
382
+ retry={retry}
383
+ close={close}
384
+ />
385
+ )}
386
+ />
387
+ <CartNotice className="cart-notice">
388
+ {(notice) =>
389
+ notice.kind === "added" ? (
390
+ <>
391
+ Added {notice.line.name}.{" "}
392
+ <button type="button" onClick={notice.undo}>
393
+ Undo
394
+ </button>
395
+ </>
396
+ ) : (
397
+ notice.message
398
+ )
399
+ }
400
+ </CartNotice>
401
+ </Bag.Root>;
402
+
403
+ // app/ui/bag-body.tsx
404
+ export default function BagBody({ close, empty }: BagBodyProps) {
405
+ return (
406
+ <>
407
+ <Bag.Title>Your bag</Bag.Title>
408
+ <Bag.Close aria-label="Close bag">×</Bag.Close>
409
+ {empty ? <EmptyBag onBrowse={close} /> : <Lines />}
410
+ </>
411
+ );
412
+ }
413
+
414
+ // app/routes/cart.tsx
415
+ import { openBagAt } from "@zappie/foundations/bag/server";
416
+ export function loader({ request }: LoaderFunctionArgs) {
417
+ throw openBagAt(request, { to: "/menu" });
418
+ }
419
+ ```
420
+
421
+ - `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.
422
+ - `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"`.
423
+ - The body receives `close` and `empty`. `empty` is true once the cart has loaded with no lines.
424
+ - `Bag.Trigger` is a button that opens the bag, marked `data-zappie-overlay-trigger="bag"`, with `aria-expanded`. Use `asChild` for your own button.
425
+ - `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.
426
+ - `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.
427
+ - `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`.
428
+
429
+ ### Cart notice
430
+
431
+ `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.
432
+
433
+ 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.
434
+
357
435
  ## Branch switch
358
436
 
359
437
  Choosing a branch shows that branch's menu without waiting for the server. A
@@ -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
@@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ACnD,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,2 @@
1
+ var BAG_PARAM="bag";export{BAG_PARAM};
2
+ //# sourceMappingURL=param.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/bag/param.ts"],
4
+ "mappings": "AACO,IAAM,UAAY",
5
+ "names": []
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
+ }
package/dist/index.d.ts CHANGED
@@ -9,7 +9,7 @@ import { useCart } from '@zappie/sdk/react';
9
9
  export { D as Deferred, a as DeferredIdleOptions, b as DeferredProps, I as IntentPreloadHandlers, d as deferred, u as useIntentPreload } from './index-B1mCF3ft.js';
10
10
  import { S as ScheduleBlock, a as ScheduleSlot } from './window-BAFAfQnw.js';
11
11
  export { b as ScheduleDay, c as ScheduleMenu, d as ScheduleOptions } from './window-BAFAfQnw.js';
12
- export { O as Overlay, u as useOverlay } from './react-CFPTPzAO.js';
12
+ export { a as Overlay, u as useOverlay } from './react-C1KQB_W3.js';
13
13
  import { SelectionControl } from '@zappie/sdk/options';
14
14
  import './overlay/engine.js';
15
15
  import '@base-ui/react/dialog';
@@ -4,7 +4,7 @@ import * as react from 'react';
4
4
  import { ReactNode } from 'react';
5
5
  import { CartLineInput, Item } from '@zappie/sdk';
6
6
  import { Deferred } from '../index.js';
7
- import { a as OverlayContentProps, R as ResponsivePresentation } from '../react-CFPTPzAO.js';
7
+ import { O as OverlayContentProps, R as ResponsivePresentation } from '../react-C1KQB_W3.js';
8
8
  import '../overlay/engine.js';
9
9
  import '@base-ui/react/dialog';
10
10
 
@@ -83,7 +83,7 @@ type ItemSheetContentProps = Omit<OverlayContentProps, "children" | "forceMount"
83
83
  * exit) holding the site's body. It stays mounted after closing so its exit can play, and focus
84
84
  * goes back to the card that opened it.
85
85
  */
86
- declare function Content({ presentation, fallback, failed, ...props }: ItemSheetContentProps): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | react.JSX.Element | null | undefined;
86
+ declare function Content({ presentation, fallback, failed, ...props }: ItemSheetContentProps): react.JSX.Element | null;
87
87
  /**
88
88
  * The product sheet over the current page, for React Router route modules. `Root` and `Page`
89
89
  * go in the layout that holds the item route, `Content` anywhere under `Root`, and `Trigger` on
@@ -1,2 +1,2 @@
1
- "use client";import{createContext,forwardRef,useContext,useEffect,useMemo,useRef,useState}from"react";import{flushSync}from"react-dom";import{UNSAFE_DataRouterDataContext as DataContext,Link,UNSAFE_LocationContext as LocationContext,matchPath,useLocation,useNavigate,useOutlet}from"react-router";import{part}from"../internal/slot.js";import{loadOverlayEngine}from"../overlay/load.js";import{Overlay}from"../overlay/react.js";import{jsx}from"react/jsx-runtime";var SheetContext=/*@__PURE__ */createContext(null);function useItemSheet(){const value=useContext(SheetContext);if(!value){throw new Error("ItemSheet parts require ItemSheet.Root")}return value}var loaded=new WeakSet;var ignore=()=>{};var load=sheet=>Promise.all([sheet.preload(),loadOverlayEngine()]).then(()=>{loaded.add(sheet)});function cardFor(itemId,card){return card?.isConnected&&card.dataset.zappieItemLink===itemId?card:itemId?document.querySelector(`[data-zappie-item-link="${CSS.escape(itemId)}"]`):null}function returnFocusToCard(itemId){cardFor(itemId)?.focus({preventScroll:true})}function Root({sheet,href,closeTo="/",path="/item/:id",children}){const{pathname}=useLocation();const navigate=useNavigate();const routed=matchPath(path,pathname)?.params.id;const[tapped,setTapped]=useState();const[leaving,setLeaving]=useState();const pending=useRef(void 0);const latest=useRef({navigate,href,closeTo,routed});latest.current={navigate,href,closeTo,routed};const card=useRef(void 0);useEffect(()=>{if(routed){setTapped(void 0);pending.current=void 0;if(routed===leaving){setLeaving(void 0);void latest.current.navigate(-1)}}},[routed]);useEffect(()=>{const start=()=>load(sheet).catch(ignore);if(typeof window.requestIdleCallback==="function"){const handle2=window.requestIdleCallback(start);return()=>window.cancelIdleCallback(handle2)}const handle=window.setTimeout(start,1);return()=>window.clearTimeout(handle)},[sheet]);const itemId=(routed!==leaving?routed:void 0)??tapped;const actions=useMemo(()=>({href:id=>latest.current.href(id),preload:()=>{load(sheet).catch(ignore)},open:id=>{setLeaving(void 0);flushSync(()=>setTapped(id));const step={frame:requestAnimationFrame(()=>{step.timer=window.setTimeout(()=>{step.sent=id;void latest.current.navigate(latest.current.href(id),{preventScrollReset:true})})})};pending.current=step},close:()=>{const{navigate:navigate2,closeTo:closeTo2,routed:routed2}=latest.current;const step=pending.current;if(!routed2){pending.current=void 0;if(step?.sent){setLeaving(step.sent)}else if(step){cancelAnimationFrame(step.frame);window.clearTimeout(step.timer)}setTapped(void 0)}else if((window.history.state?.idx??0)>0){void navigate2(-1)}else{void navigate2(typeof closeTo2==="string"?closeTo2:closeTo2(routed2),{replace:true,preventScrollReset:true})}}}),[sheet]);const value=useMemo(()=>({...actions,itemId,routed:!!routed,sheet,card}),[actions,itemId,routed,sheet]);return jsx(SheetContext.Provider,{value,children})}function Page(){const{routed}=useItemSheet();const live={outlet:useOutlet(),location:useContext(LocationContext),data:useContext(DataContext)};const[kept,setKept]=useState(live);if(!routed&&(kept.outlet!==live.outlet||kept.location!==live.location||kept.data!==live.data)){setKept(live)}const{outlet,location,data}=routed?kept:live;return jsx(LocationContext.Provider,{value:location,children:jsx(DataContext.Provider,{value:data,children:outlet})})}function Content({presentation="drawer",fallback,failed,...props}){const{itemId,close,sheet,card}=useItemSheet();const[last,setLast]=useState(itemId);if(itemId&&itemId!==last){setLast(itemId)}const[arrived,setArrived]=useState();const[tries,setTries]=useState(0);const open=!!itemId;useEffect(()=>{let live=open;if(live){setArrived(value=>value||void 0);load(sheet).then(()=>live&&setArrived(true),()=>live&&setArrived(false))}return()=>{live=false}},[open,sheet,tries]);const navigation=useMemo(()=>({isOpen:open,open:ignore,close,trigger:{get current(){return cardFor(last,card.current)}}}),[open,close,last,card]);if(!last){return null}if(arrived===false){return open?failed(()=>{setArrived(void 0);setTries(count=>count+1)},close):null}if(!(fallback||arrived||loaded.has(sheet))){return null}return jsx(Overlay.Root,{param:"item",id:last,navigation,presentation,children:jsx(Overlay.Content,{"data-zappie-overlay":"item",...props,children:jsx(sheet.Component,{open:true,itemId:last,close,fallback:fallback?.(last),failed:retry=>failed(retry,close)},last)})})}var Trigger=/*@__PURE__ */forwardRef(function Trigger2({itemId,prefetch="viewport",...props},ref){const state=useItemSheet();const href=state.href(itemId);return part(props.asChild?"a":Link,props,state,{...props.asChild?{href}:{to:href,prefetch},"data-zappie-item-link":itemId,"data-zappie-overlay-trigger":"item",onPointerEnter:state.preload,onPointerDown:state.preload,onFocus:state.preload,onClick:event=>{if(event.button===0&&!(event.metaKey||event.ctrlKey||event.shiftKey||event.altKey)){event.preventDefault();state.card.current=event.currentTarget;state.open(itemId)}}},ref)});var ItemSheet={Root,Page,Content,Trigger,Title:Overlay.Title,Close:Overlay.Close};function keptLine(state,itemId){const line=state?.line;return line&&typeof line==="object"&&line.itemId===itemId?line:void 0}function restoreLine(item,line){const groups=new Map(item.optionGroups.map(group=>[group.id,group]));const chosen=line.choices??[];const asked=Object.entries(line.inputs??{});const choices=chosen.filter(entry=>groups.get(entry.groupId)?.choices.some(choice=>choice.id===entry.choiceId&&choice.isAvailable));const inputs=asked.filter(([groupId])=>groups.has(groupId));return{value:{itemId:item.id,quantity:Math.min(Math.max(line.quantity??item.quantity.min,item.quantity.min),item.quantity.max??Infinity),...choices.length>0?{choices}:{},...inputs.length>0?{inputs:Object.fromEntries(inputs)}:{},...line.note?{note:line.note}:{}},dropped:choices.length!==chosen.length||inputs.length!==asked.length}}export{ItemSheet,keptLine,restoreLine,returnFocusToCard,useItemSheet};
1
+ "use client";import{createContext,forwardRef,useContext,useEffect,useMemo,useRef,useState}from"react";import{flushSync}from"react-dom";import{UNSAFE_DataRouterDataContext as DataContext,Link,UNSAFE_LocationContext as LocationContext,matchPath,useLocation,useNavigate,useOutlet}from"react-router";import{part}from"../internal/slot.js";import{DeferredHost,loadBody}from"../overlay/deferred-host.js";import{Overlay}from"../overlay/react.js";import{jsx}from"react/jsx-runtime";var SheetContext=/*@__PURE__ */createContext(null);function useItemSheet(){const value=useContext(SheetContext);if(!value){throw new Error("ItemSheet parts require ItemSheet.Root")}return value}var ignore=()=>{};var load=loadBody;function cardFor(itemId,card){return card?.isConnected&&card.dataset.zappieItemLink===itemId?card:itemId?document.querySelector(`[data-zappie-item-link="${CSS.escape(itemId)}"]`):null}function returnFocusToCard(itemId){cardFor(itemId)?.focus({preventScroll:true})}function Root({sheet,href,closeTo="/",path="/item/:id",children}){const{pathname}=useLocation();const navigate=useNavigate();const routed=matchPath(path,pathname)?.params.id;const[tapped,setTapped]=useState();const[leaving,setLeaving]=useState();const pending=useRef(void 0);const latest=useRef({navigate,href,closeTo,routed});latest.current={navigate,href,closeTo,routed};const card=useRef(void 0);useEffect(()=>{if(routed){setTapped(void 0);pending.current=void 0;if(routed===leaving){setLeaving(void 0);void latest.current.navigate(-1)}}},[routed]);useEffect(()=>{const start=()=>load(sheet).catch(ignore);if(typeof window.requestIdleCallback==="function"){const handle2=window.requestIdleCallback(start);return()=>window.cancelIdleCallback(handle2)}const handle=window.setTimeout(start,1);return()=>window.clearTimeout(handle)},[sheet]);const itemId=(routed!==leaving?routed:void 0)??tapped;const actions=useMemo(()=>({href:id=>latest.current.href(id),preload:()=>{load(sheet).catch(ignore)},open:id=>{setLeaving(void 0);flushSync(()=>setTapped(id));const step={frame:requestAnimationFrame(()=>{step.timer=window.setTimeout(()=>{step.sent=id;void latest.current.navigate(latest.current.href(id),{preventScrollReset:true})})})};pending.current=step},close:()=>{const{navigate:navigate2,closeTo:closeTo2,routed:routed2}=latest.current;const step=pending.current;if(!routed2){pending.current=void 0;if(step?.sent){setLeaving(step.sent)}else if(step){cancelAnimationFrame(step.frame);window.clearTimeout(step.timer)}setTapped(void 0)}else if((window.history.state?.idx??0)>0){void navigate2(-1)}else{void navigate2(typeof closeTo2==="string"?closeTo2:closeTo2(routed2),{replace:true,preventScrollReset:true})}}}),[sheet]);const value=useMemo(()=>({...actions,itemId,routed:!!routed,sheet,card}),[actions,itemId,routed,sheet]);return jsx(SheetContext.Provider,{value,children})}function Page(){const{routed}=useItemSheet();const live={outlet:useOutlet(),location:useContext(LocationContext),data:useContext(DataContext)};const[kept,setKept]=useState(live);if(!routed&&(kept.outlet!==live.outlet||kept.location!==live.location||kept.data!==live.data)){setKept(live)}const{outlet,location,data}=routed?kept:live;return jsx(LocationContext.Provider,{value:location,children:jsx(DataContext.Provider,{value:data,children:outlet})})}function Content({presentation="drawer",fallback,failed,...props}){const{itemId,close,sheet,card}=useItemSheet();const[last,setLast]=useState(itemId);if(itemId&&itemId!==last){setLast(itemId)}const open=!!itemId;const navigation=useMemo(()=>({isOpen:open,open:ignore,close,trigger:{get current(){return cardFor(last,card.current)}}}),[open,close,last,card]);if(!last){return null}return jsx(DeferredHost,{body:sheet,param:"item",id:last,navigation,presentation,eager:!!fallback,failed,props,children:jsx(sheet.Component,{open:true,itemId:last,close,fallback:fallback?.(last),failed:retry=>failed(retry,close)},last)})}var Trigger=/*@__PURE__ */forwardRef(function Trigger2({itemId,prefetch="viewport",...props},ref){const state=useItemSheet();const href=state.href(itemId);return part(props.asChild?"a":Link,props,state,{...props.asChild?{href}:{to:href,prefetch},"data-zappie-item-link":itemId,"data-zappie-overlay-trigger":"item",onPointerEnter:state.preload,onPointerDown:state.preload,onFocus:state.preload,onClick:event=>{if(event.button===0&&!(event.metaKey||event.ctrlKey||event.shiftKey||event.altKey)){event.preventDefault();state.card.current=event.currentTarget;state.open(itemId)}}},ref)});var ItemSheet={Root,Page,Content,Trigger,Title:Overlay.Title,Close:Overlay.Close};function keptLine(state,itemId){const line=state?.line;return line&&typeof line==="object"&&line.itemId===itemId?line:void 0}function restoreLine(item,line){const groups=new Map(item.optionGroups.map(group=>[group.id,group]));const chosen=line.choices??[];const asked=Object.entries(line.inputs??{});const choices=chosen.filter(entry=>groups.get(entry.groupId)?.choices.some(choice=>choice.id===entry.choiceId&&choice.isAvailable));const inputs=asked.filter(([groupId])=>groups.has(groupId));return{value:{itemId:item.id,quantity:Math.min(Math.max(line.quantity??item.quantity.min,item.quantity.min),item.quantity.max??Infinity),...choices.length>0?{choices}:{},...inputs.length>0?{inputs:Object.fromEntries(inputs)}:{},...line.note?{note:line.note}:{}},dropped:choices.length!==chosen.length||inputs.length!==asked.length}}export{ItemSheet,keptLine,restoreLine,returnFocusToCard,useItemSheet};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/item-sheet/index.tsx"],
4
- "mappings": "aAEA,OACE,cACA,WACA,WACA,UACA,QACA,OACA,aAEK,QACP,OAAS,cAAiB,YAC1B,OACE,gCAAgC,YAChC,KACA,0BAA0B,gBAC1B,UACA,YACA,YACA,cACK,eAEP,OAAS,SAA4B,sBACrC,OAAS,sBAAyB,qBAClC,OACE,YAGK,sBAoLH,mCAvJJ,IAAM,aAAe,eAAgB,cAA8B,IAAI,EAMhE,SAAS,cAA+B,CAC7C,MAAM,MAAQ,WAAW,YAAY,EACrC,GAAI,CAAC,MAAO,CACV,MAAM,IAAI,MAAM,wCAAwC,CAC1D,CACA,OAAO,KACT,CAGA,IAAM,OAAS,IAAI,QACnB,IAAM,OAAS,IAAM,CAAC,EAEtB,IAAM,KAAQ,OACZ,QAAQ,IAAI,CAAC,MAAM,QAAQ,EAAG,kBAAkB,CAAC,CAAC,EAAE,KAAK,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,SAAS,GAAG,EAC9D,KAAK,SAAS,KAAO,QACvB,EACA,GAAI,QAAQ,OAAS,EAAI,CAAE,OAAQ,EAAI,CAAC,EACxC,GAAI,OAAO,OAAS,EAAI,CAAE,OAAQ,OAAO,YAAY,MAAM,CAAE,EAAI,CAAC,EAClE,GAAI,KAAK,KAAO,CAAE,KAAM,KAAK,IAAK,EAAI,CAAC,CACzC,EACA,QAAS,QAAQ,SAAW,OAAO,QAAU,OAAO,SAAW,MAAM,MACvE,CACF",
5
5
  "names": ["handle", "navigate", "closeTo", "routed", "Trigger"]
6
6
  }
@@ -0,0 +1,2 @@
1
+ "use client";import{useEffect,useState}from"react";import{loadOverlayEngine}from"./load.js";import{Overlay}from"./react.js";import{jsx}from"react/jsx-runtime";var loaded=new WeakSet;var loadBody=body=>Promise.all([body.preload(),loadOverlayEngine()]).then(()=>{loaded.add(body)});function DeferredHost({body,param,id,navigation,presentation,eager,failed,props,children}){const open=navigation.isOpen;const[arrived,setArrived]=useState();const[tries,setTries]=useState(0);useEffect(()=>{let live=open;if(live){setArrived(value=>value||void 0);loadBody(body).then(()=>live&&setArrived(true),()=>live&&setArrived(false))}return()=>{live=false}},[open,body,tries]);if(arrived===false){return open?failed(()=>{setArrived(void 0);setTries(count=>count+1)},navigation.close):null}if(!(eager||arrived||loaded.has(body))){return null}return jsx(Overlay.Root,{param,id,navigation,presentation,children:jsx(Overlay.Content,{"data-zappie-overlay":param,...props,children})})}export{DeferredHost,loadBody};
2
+ //# sourceMappingURL=deferred-host.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/overlay/deferred-host.tsx"],
4
+ "mappings": "aACA,OAAS,UAAW,aAAgC,QACpD,OAAS,sBAAyB,YAClC,OACE,YAGK,aA+ED,mCAxEN,IAAM,OAAS,IAAI,QAGZ,IAAM,SAAY,MACvB,QAAQ,IAAI,CAAC,KAAK,QAAQ,EAAG,kBAAkB,CAAC,CAAC,EAAE,KAAK,IAAM,CAC5D,OAAO,IAAI,IAAI,CACjB,CAAC,EASI,SAAS,aAAa,CAC3B,KACA,MACA,GACA,WACA,aACA,MACA,OACA,MACA,QACF,EAWG,CACD,MAAM,KAAO,WAAW,OAExB,KAAM,CAAC,QAAS,UAAU,EAAI,SAAkB,EAChD,KAAM,CAAC,MAAO,QAAQ,EAAI,SAAS,CAAC,EACpC,UAAU,IAAM,CACd,IAAI,KAAO,KACX,GAAI,KAAM,CACR,WAAY,OAAU,OAAS,MAAS,EACxC,SAAS,IAAI,EAAE,KACb,IAAM,MAAQ,WAAW,IAAI,EAC7B,IAAM,MAAQ,WAAW,KAAK,CAChC,CACF,CACA,MAAO,IAAM,CACX,KAAO,KACT,CACF,EAAG,CAAC,KAAM,KAAM,KAAK,CAAC,EACtB,GAAI,UAAY,MAAO,CACrB,OAAO,KACH,OAAO,IAAM,CACX,WAAW,MAAS,EACpB,SAAU,OAAU,MAAQ,CAAC,CAC/B,EAAG,WAAW,KAAK,EACnB,IACN,CACA,GAAI,EAAE,OAAS,SAAW,OAAO,IAAI,IAAI,GAAI,CAC3C,OAAO,IACT,CACA,OACE,IAAC,QAAQ,KAAR,CACC,MACA,GACA,WACA,aAEA,aAAC,QAAQ,QAAR,CAAgB,sBAAqB,MAAQ,GAAG,MAC9C,SACH,EACF,CAEJ",
5
+ "names": []
6
+ }
@@ -116,5 +116,5 @@ declare const Overlay: {
116
116
  } & react.RefAttributes<HTMLElement>>;
117
117
  };
118
118
 
119
- export { Overlay as O, useOverlay as u };
120
- export type { ResponsivePresentation as R, OverlayContentProps as a };
119
+ export { Overlay as a, useOverlay as u };
120
+ export type { OverlayContentProps as O, ResponsivePresentation as R };
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
- var PACKAGE_VERSION=true?"0.17.0":"0.0.0-development";export{PACKAGE_VERSION};
1
+ var PACKAGE_VERSION=true?"0.18.0":"0.0.0-development";export{PACKAGE_VERSION};
2
2
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zappie/foundations",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "UI-less React primitives for Zappie storefronts: behaviour, state and accessibility without styles.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -37,6 +37,14 @@
37
37
  "types": "./dist/item-sheet/index.d.ts",
38
38
  "import": "./dist/item-sheet/index.js"
39
39
  },
40
+ "./bag": {
41
+ "types": "./dist/bag/index.d.ts",
42
+ "import": "./dist/bag/index.js"
43
+ },
44
+ "./bag/server": {
45
+ "types": "./dist/bag/server.d.ts",
46
+ "import": "./dist/bag/server.js"
47
+ },
40
48
  "./phone": {
41
49
  "types": "./dist/phone/index.d.ts",
42
50
  "import": "./dist/phone/index.js"
@@ -69,7 +77,7 @@
69
77
  "peerDependencies": {
70
78
  "react": "^18.2.0 || ^19.0.0",
71
79
  "react-dom": "^18.2.0 || ^19.0.0",
72
- "@zappie/sdk": "^0.18.1",
80
+ "@zappie/sdk": "^0.19.0",
73
81
  "react-router": "^8.4.0"
74
82
  },
75
83
  "peerDependenciesMeta": {
@@ -86,7 +94,7 @@
86
94
  "@types/google.maps": "^3.66.7",
87
95
  "esbuild": "^0.28.2",
88
96
  "react-router": "8.5.0",
89
- "@zappie/sdk": "0.18.1"
97
+ "@zappie/sdk": "0.19.0"
90
98
  },
91
99
  "license": "MIT",
92
100
  "homepage": "https://github.com/zappie/storefront-packages#readme",