@zappie/foundations 0.22.3 → 0.24.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 +18 -0
- package/README.md +35 -4
- package/dist/index.d.ts +34 -9
- package/dist/internal/labelled-control.js +2 -0
- package/dist/internal/labelled-control.js.map +6 -0
- package/dist/item-form/option-group.js +1 -1
- package/dist/item-form/option-group.js.map +1 -1
- package/dist/item-form/root.js +1 -1
- package/dist/item-form/root.js.map +1 -1
- package/dist/payment/methods.js +1 -1
- package/dist/payment/methods.js.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @zappie/foundations
|
|
2
2
|
|
|
3
|
+
## 0.24.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 6186e4f: Choice and PaymentMethods.Item are real form controls now. Each is a `<label>` around a native `<input type="radio">` or `<input type="checkbox">`, so the browser draws a round radio for a group that takes exactly one and a square checkbox for every other group, and owns the arrows, Tab and Space. The label keeps every data attribute it had as a button (`data-zappie-option`, `data-control`, `data-state`, `data-selected`, `data-disabled`, `data-sold-out`, `data-limit-reached`) and the template's `className`. The input carries `checked`, `disabled` for a sold-out choice or one the template passes `disabled`, `aria-disabled` for a choice held back by the group's limit, and `data-zappie-choice-input` for styling. A template that draws its own mark restyles or hides that input, styles its focus ring with `:has(> [data-zappie-choice-input]:focus-visible)` and its disabled look with `[data-disabled]`. Put quantity steppers beside a Choice, not inside it. The base theme draws its marks on the input. V05 skips sold-out choices by `data-disabled` as well as `aria-disabled`.
|
|
8
|
+
|
|
9
|
+
## 0.23.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- b2f87d3: An item on more than one of the branch's menus can be added without naming a menu. `cart.add(item)` and `cart.validate` file such a line under the first menu in display order that lists it, `withDefaultMenu(menu, input)`, and the line follows that menu's hours and pre-order terms. The cart refuses the line only when no menu lists the item. `ItemForm.Root` takes a `menuId` prop for the menu the shopper opened the item from, and uses the same default without one. The form state has `itemIssues`, the issues that belong to no option group, and `onInvalid` receives them as its second argument. The menu messages name a fix the shopper can make.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [3a92894]
|
|
18
|
+
- Updated dependencies [b2f87d3]
|
|
19
|
+
- @zappie/sdk@0.25.0
|
|
20
|
+
|
|
3
21
|
## 0.22.3
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -719,13 +719,32 @@ closedForOrders(branch); // closed, and not taking orders for later
|
|
|
719
719
|
|
|
720
720
|
`src/hours/ADOPTING.md` maps each site's own copies onto these.
|
|
721
721
|
|
|
722
|
+
## Item form menu
|
|
723
|
+
|
|
724
|
+
Pass `menuId` to `ItemForm.Root` with the menu the shopper opened the item
|
|
725
|
+
from. When the item is on more than one of the branch's menus, it decides the
|
|
726
|
+
line's hours and pre-order terms. A `menuId` in `value` or `defaultValue` wins
|
|
727
|
+
over the prop. Without either, the form uses the first menu in display order
|
|
728
|
+
that lists the item, the same default `cart.add` uses, and `state.value.menuId`
|
|
729
|
+
says which.
|
|
730
|
+
|
|
731
|
+
```tsx
|
|
732
|
+
<ItemForm.Root item={item} menuId={openedFrom?.id} onAdded={close}>
|
|
733
|
+
```
|
|
734
|
+
|
|
722
735
|
## Item form focus
|
|
723
736
|
|
|
724
737
|
When an add fails validation, `ItemForm.Root` focuses the first invalid group
|
|
725
|
-
with `preventScroll`, so the page doesn't jump. Pass `onInvalid(groups
|
|
726
|
-
scroll it into view yourself. `groups` lists the invalid groups
|
|
727
|
-
order, each with its `groupId`, its `group` (undefined for a group
|
|
728
|
-
template renders from its own model), its `element` and its `issues`.
|
|
738
|
+
with `preventScroll`, so the page doesn't jump. Pass `onInvalid(groups,
|
|
739
|
+
itemIssues)` to scroll it into view yourself. `groups` lists the invalid groups
|
|
740
|
+
in display order, each with its `groupId`, its `group` (undefined for a group
|
|
741
|
+
the template renders from its own model), its `element` and its `issues`.
|
|
742
|
+
|
|
743
|
+
`itemIssues` holds the issues that belong to no group: the item is sold out,
|
|
744
|
+
no menu here lists it, or the quantity is out of range. No group shows them,
|
|
745
|
+
so show them by Add. The form state has the same list as `state.itemIssues`,
|
|
746
|
+
next to `state.issues`, which holds every issue. Keep Add enabled: a disabled
|
|
747
|
+
Add can't explain why it does nothing.
|
|
729
748
|
|
|
730
749
|
```tsx
|
|
731
750
|
<ItemForm.Root
|
|
@@ -734,6 +753,18 @@ template renders from its own model), its `element` and its `issues`.
|
|
|
734
753
|
groups[0]?.element?.scrollIntoView({ behavior: "smooth", block: "center" })
|
|
735
754
|
}
|
|
736
755
|
>
|
|
756
|
+
{(state) => (
|
|
757
|
+
<Fragment>
|
|
758
|
+
…
|
|
759
|
+
{state.itemIssues.map((issue) => (
|
|
760
|
+
<p key={issue.code} role="alert">
|
|
761
|
+
{issue.message}
|
|
762
|
+
</p>
|
|
763
|
+
))}
|
|
764
|
+
<ItemForm.Add>Add</ItemForm.Add>
|
|
765
|
+
</Fragment>
|
|
766
|
+
)}
|
|
767
|
+
</ItemForm.Root>
|
|
737
768
|
```
|
|
738
769
|
|
|
739
770
|
## Branch map
|
package/dist/index.d.ts
CHANGED
|
@@ -581,7 +581,13 @@ type ItemFormContext = {
|
|
|
581
581
|
setQuantity: (quantity: number) => void;
|
|
582
582
|
unitPrice: Money$1;
|
|
583
583
|
total: Money$1;
|
|
584
|
+
/** Every issue the shopper should see, shown once they try to add. */
|
|
584
585
|
issues: CartIssue[];
|
|
586
|
+
/**
|
|
587
|
+
* The issues in `issues` that belong to no option group, such as an item that is sold out or on
|
|
588
|
+
* no menu here, or a quantity out of range. No group shows these, so show them by Add.
|
|
589
|
+
*/
|
|
590
|
+
itemIssues: CartIssue[];
|
|
585
591
|
canAdd: boolean;
|
|
586
592
|
add: () => CartLine | null;
|
|
587
593
|
status: "incomplete" | "valid" | "added";
|
|
@@ -618,9 +624,18 @@ type ItemFormProps = Omit<PartProps<ItemFormContext>, "onInvalid"> & {
|
|
|
618
624
|
* Called when an add fails validation, after the first invalid group gets
|
|
619
625
|
* focus without scrolling. Groups are in display order. Scroll to
|
|
620
626
|
* `groups[0].element` yourself, for example smoothly. The list is empty
|
|
621
|
-
* when no issue belongs to a group.
|
|
627
|
+
* when no issue belongs to a group. `itemIssues` holds the issues that
|
|
628
|
+
* belong to no group, the same as the context's `itemIssues`: show them,
|
|
629
|
+
* since no group will.
|
|
630
|
+
*/
|
|
631
|
+
onInvalid?: (groups: ItemFormInvalidGroup[], itemIssues: CartIssue[]) => void;
|
|
632
|
+
/**
|
|
633
|
+
* The menu the shopper opened the item from. It decides the line's hours and pre-order terms
|
|
634
|
+
* when the item is on more than one of the branch's menus. A `menuId` in `value` or
|
|
635
|
+
* `defaultValue` wins over it. Without either, the line goes under the first menu in display
|
|
636
|
+
* order that lists the item (`withDefaultMenu` in `@zappie/sdk`).
|
|
622
637
|
*/
|
|
623
|
-
|
|
638
|
+
menuId?: string;
|
|
624
639
|
/**
|
|
625
640
|
* True when the shopper hasn't chosen a branch yet, for example on a shared
|
|
626
641
|
* product link. Add then adds nothing and calls `onBranchRequired` instead,
|
|
@@ -634,7 +649,7 @@ type ItemFormProps = Omit<PartProps<ItemFormContext>, "onInvalid"> & {
|
|
|
634
649
|
*/
|
|
635
650
|
onBranchRequired?: (input: CartLineInput) => void;
|
|
636
651
|
};
|
|
637
|
-
declare function Root$2({ item, value, defaultValue, onValueChange, defaultQuantity, onAdded, onCommit, onInvalid, branchRequired, onBranchRequired, ...props }: ItemFormProps): react.JSX.Element;
|
|
652
|
+
declare function Root$2({ item, value, defaultValue, onValueChange, defaultQuantity, onAdded, onCommit, onInvalid, branchRequired, onBranchRequired, menuId, ...props }: ItemFormProps): react.JSX.Element;
|
|
638
653
|
|
|
639
654
|
type GroupState = {
|
|
640
655
|
group: OptionGroup$1;
|
|
@@ -677,10 +692,15 @@ type ChoiceState = {
|
|
|
677
692
|
setQuantity: (quantity: number) => void;
|
|
678
693
|
};
|
|
679
694
|
/**
|
|
680
|
-
* Render a selectable option within an OptionGroup
|
|
681
|
-
*
|
|
682
|
-
*
|
|
683
|
-
*
|
|
695
|
+
* Render a selectable option within an OptionGroup as a `<label>` around a
|
|
696
|
+
* native `<input>`: radios for a required group of exactly one, checkboxes for
|
|
697
|
+
* every other group. The input comes first, so the browser draws a round radio
|
|
698
|
+
* or a square checkbox unless the template restyles it. Style the label through
|
|
699
|
+
* its data attributes and the input through `[data-zappie-choice-input]`.
|
|
700
|
+
* Unavailable choices are disabled, and so is a choice given `disabled`, which
|
|
701
|
+
* goes to the input. While the group is at its limit, unchosen
|
|
702
|
+
* choices are aria-disabled and data-limit-reached but stay focusable. Put
|
|
703
|
+
* quantity steppers beside the Choice, not inside it.
|
|
684
704
|
*/
|
|
685
705
|
declare const Choice: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
|
|
686
706
|
asChild?: boolean;
|
|
@@ -890,6 +910,8 @@ type PaymentState = {
|
|
|
890
910
|
methods: PaymentMethod[];
|
|
891
911
|
value: PaymentMethodKind | null;
|
|
892
912
|
setValue: (value: PaymentMethodKind) => void;
|
|
913
|
+
/** The name the methods' native radios share. */
|
|
914
|
+
name: string;
|
|
893
915
|
};
|
|
894
916
|
declare function Root$1({ methods, value, defaultValue, onValueChange, ...props }: PartProps<PaymentState> & {
|
|
895
917
|
methods: (PaymentMethod | PaymentMethodKind)[];
|
|
@@ -898,8 +920,11 @@ declare function Root$1({ methods, value, defaultValue, onValueChange, ...props
|
|
|
898
920
|
onValueChange?: (value: PaymentMethodKind | null) => void;
|
|
899
921
|
}): react.JSX.Element;
|
|
900
922
|
/**
|
|
901
|
-
* Composable payment-method
|
|
902
|
-
* Root manages the selection. Item renders each method
|
|
923
|
+
* Composable payment-method radios.
|
|
924
|
+
* Root manages the selection and is a radiogroup. Item renders each method as a
|
|
925
|
+
* `<label>` around a native radio, which the browser draws round unless the
|
|
926
|
+
* template restyles it through `[data-zappie-choice-input]`. A disabled method
|
|
927
|
+
* can't be selected.
|
|
903
928
|
*/
|
|
904
929
|
declare const PaymentMethods: {
|
|
905
930
|
Root: typeof Root$1;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{Children,cloneElement,Fragment,isValidElement}from"react";import{part}from"./slot.js";import{jsxs}from"react/jsx-runtime";function labelledControl(props,state,defaults,control,ref){const{asChild,children,...dom}=props;const content=typeof children==="function"?children(state):children;if(asChild){const child=Children.only(content);if(!isValidElement(child)){throw new Error("asChild requires one React element")}return part("label",{...dom,asChild:true,children:cloneElement(child,void 0,control,child.props.children)},state,defaults,ref)}return part("label",{...dom,children:jsxs(Fragment,{children:[control,content]})},state,defaults,ref)}export{labelledControl};
|
|
2
|
+
//# sourceMappingURL=labelled-control.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/internal/labelled-control.tsx"],
|
|
4
|
+
"mappings": "AAAA,OACE,SACA,aACA,SACA,mBAIK,QACP,OAAS,SAA4B,YA0C7B,oCApCD,SAAS,gBACd,MACA,MACA,SACA,QACA,IACA,CACA,KAAM,CAAE,QAAS,SAAU,GAAG,GAAI,EAAI,MACtC,MAAM,QAAU,OAAO,WAAa,WAAa,SAAS,KAAK,EAAI,SACnE,GAAI,QAAS,CACX,MAAM,MAAQ,SAAS,KAAK,OAAO,EACnC,GAAI,CAAC,eAAyC,KAAK,EAAG,CACpD,MAAM,IAAI,MAAM,oCAAoC,CACtD,CACA,OAAO,KACL,QACA,CACE,GAAG,IACH,QAAS,KACT,SAAU,aACR,MACA,OACA,QACA,MAAM,MAAM,QACd,CACF,EACA,MACA,SACA,GACF,CACF,CACA,OAAO,KACL,QACA,CACE,GAAG,IACH,SACE,KAAC,UACE,kBACA,SACH,CAEJ,EACA,MACA,SACA,GACF,CACF",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{canChoose,choiceQuantityMax,atLimit as groupAtLimit,groupRoom,LIMIT_REACHED_HINT,selectionControl,selectionCount}from"@zappie/sdk/options";import{cloneElement,createContext,forwardRef,Fragment,isValidElement,memo,useContext,useMemo,useRef}from"react";import{flag}from"../internal/data-attrs.js";import{usePartId}from"../internal/ids.js";import{composeRefs,part}from"../internal/slot.js";import{GroupRegistry,useItemForm}from"./root.js";import{jsx,jsxs}from"react/jsx-runtime";var Context=/*@__PURE__ */createContext(null);function useGroup(){const value=useContext(Context);if(!value){throw new Error("Choice and OptionGroup.Input require OptionGroup")}return value}var Group=/*@__PURE__ */forwardRef(function OptionGroup({group:supplied,requiredNote="Required",limitHint:hintText,"aria-describedby":describedBy,children,...props},ref){const ctx=useItemForm();const registry=useContext(GroupRegistry);const group=ctx.groups.find(candidate=>candidate.id===supplied.id)??supplied;const mine=ctx.value.choices?.filter(choice=>choice.groupId===group.id)??[];const selected=mine.map(choice=>choice.choiceId);const quantities=Object.fromEntries(mine.map(choice=>[choice.choiceId,choice.quantity??1]));const invalid=ctx.issues.some(issue=>issue.groupId===group.id);const input=ctx.value.inputs?.[group.id]??"";const latest=useRef({ctx,group});latest.current={ctx,group};const actions=useMemo(()=>{const write=(id,quantity)=>{const{ctx:ctx2,group:group2}=latest.current;const previous=ctx2.value.choices??[];const isThis=candidate=>candidate.groupId===group2.id&&candidate.choiceId===id;const choice=group2.choices.find(candidate=>candidate.id===id);if(!choice||!Number.isInteger(quantity)||quantity>0&&!canChoose(group2,previous,id)){return}const choices=previous.filter(candidate=>!isThis(candidate)&&(quantity<=0||candidate.groupId!==group2.id||group2.selection.max!==1));if(quantity>0){choices.push({groupId:group2.id,choiceId:id,quantity:Math.max(choice.quantity?.min??1,Math.min(choiceQuantityMax(group2,previous,id),quantity))})}const inputs={...ctx2.value.inputs};delete inputs[group2.id];ctx2.setValue({...ctx2.value,choices,inputs})};return{toggle:id=>{const{ctx:ctx2,group:group2}=latest.current;const chosen=ctx2.value.choices?.some(candidate=>candidate.groupId===group2.id&&candidate.choiceId===id);if(!chosen||selectionControl(group2)!=="radio"){write(id,chosen?0:group2.choices.find(candidate=>candidate.id===id)?.quantity?.min??1)}},setQuantity:write,setInput:value=>{const{ctx:ctx2,group:group2}=latest.current;ctx2.setValue({...ctx2.value,choices:(ctx2.value.choices??[]).filter(choice=>choice.groupId!==group2.id),inputs:{...ctx2.value.inputs,[group2.id]:value.slice(0,group2.input?.maxLength??500)}})}}},[]);const selectionKey=JSON.stringify(quantities);const control=selectionControl(group);const count=selectionCount(group,mine);const full=group.kind==="select"&&groupAtLimit(group,mine);const heldBack=full&&group.choices.some(choice=>choice.isAvailable&&!selected.includes(choice.id));const text=heldBack&&(hintText||LIMIT_REACHED_HINT)||void 0;const limitHint=hintText===false?void 0:text;const hintId=usePartId();const state=useMemo(()=>({group,selected,quantities,invalid,input,control,count,room:groupRoom(group,mine),atLimit:full,limitHint:text,hintId:limitHint&&hintId,mine,...actions}),[group,selectionKey,invalid,input,hintText,hintId,actions]);const radio=group.kind==="select"&&control==="radio";const noteId=usePartId();const note=group.required&&group.kind==="select"&&!radio&&requiredNote;const content=typeof children==="function"?children(state):children;const child=props.asChild&&isValidElement(content)?content:void 0;const own=describedBy??child?.props["aria-describedby"];const description=[note&¬eId,limitHint&&hintId,own].filter(Boolean).join(" ")||void 0;const hint=limitHint?jsx("p",{id:hintId,role:"status","data-zappie-limit-hint":"",children:limitHint}):null;return jsxs(Context.Provider,{value:state,children:[note&&jsx("span",{id:noteId,hidden:true,children:note}),part("div",child?{...props,children:cloneElement(child,{"aria-describedby":description},child.props.children,hint)}:{...props,children:jsxs(Fragment,{children:[content,hint]})},state,{role:radio?"radiogroup":"group",tabIndex:-1,"aria-label":group.name,"aria-required":radio?group.required:void 0,"aria-describedby":description,"data-zappie-required":group.required?"true":void 0,"aria-invalid":invalid||void 0,"data-invalid":flag(invalid),"data-state":invalid?"invalid":"valid","data-limit-reached":flag(full),"data-zappie-option-group":group.id
|
|
1
|
+
"use client";import{canChoose,choiceQuantityMax,atLimit as groupAtLimit,groupRoom,LIMIT_REACHED_HINT,selectionControl,selectionCount}from"@zappie/sdk/options";import{cloneElement,createContext,forwardRef,Fragment,isValidElement,memo,useContext,useMemo,useRef}from"react";import{flag}from"../internal/data-attrs.js";import{usePartId}from"../internal/ids.js";import{labelledControl}from"../internal/labelled-control.js";import{composeRefs,part}from"../internal/slot.js";import{GroupRegistry,useItemForm}from"./root.js";import{jsx,jsxs}from"react/jsx-runtime";var Context=/*@__PURE__ */createContext(null);function useGroup(){const value=useContext(Context);if(!value){throw new Error("Choice and OptionGroup.Input require OptionGroup")}return value}var Group=/*@__PURE__ */forwardRef(function OptionGroup({group:supplied,requiredNote="Required",limitHint:hintText,"aria-describedby":describedBy,children,...props},ref){const ctx=useItemForm();const registry=useContext(GroupRegistry);const group=ctx.groups.find(candidate=>candidate.id===supplied.id)??supplied;const mine=ctx.value.choices?.filter(choice=>choice.groupId===group.id)??[];const selected=mine.map(choice=>choice.choiceId);const quantities=Object.fromEntries(mine.map(choice=>[choice.choiceId,choice.quantity??1]));const invalid=ctx.issues.some(issue=>issue.groupId===group.id);const input=ctx.value.inputs?.[group.id]??"";const latest=useRef({ctx,group});latest.current={ctx,group};const actions=useMemo(()=>{const write=(id,quantity)=>{const{ctx:ctx2,group:group2}=latest.current;const previous=ctx2.value.choices??[];const isThis=candidate=>candidate.groupId===group2.id&&candidate.choiceId===id;const choice=group2.choices.find(candidate=>candidate.id===id);if(!choice||!Number.isInteger(quantity)||quantity>0&&!canChoose(group2,previous,id)){return}const choices=previous.filter(candidate=>!isThis(candidate)&&(quantity<=0||candidate.groupId!==group2.id||group2.selection.max!==1));if(quantity>0){choices.push({groupId:group2.id,choiceId:id,quantity:Math.max(choice.quantity?.min??1,Math.min(choiceQuantityMax(group2,previous,id),quantity))})}const inputs={...ctx2.value.inputs};delete inputs[group2.id];ctx2.setValue({...ctx2.value,choices,inputs})};return{toggle:id=>{const{ctx:ctx2,group:group2}=latest.current;const chosen=ctx2.value.choices?.some(candidate=>candidate.groupId===group2.id&&candidate.choiceId===id);if(!chosen||selectionControl(group2)!=="radio"){write(id,chosen?0:group2.choices.find(candidate=>candidate.id===id)?.quantity?.min??1)}},setQuantity:write,setInput:value=>{const{ctx:ctx2,group:group2}=latest.current;ctx2.setValue({...ctx2.value,choices:(ctx2.value.choices??[]).filter(choice=>choice.groupId!==group2.id),inputs:{...ctx2.value.inputs,[group2.id]:value.slice(0,group2.input?.maxLength??500)}})}}},[]);const selectionKey=JSON.stringify(quantities);const control=selectionControl(group);const count=selectionCount(group,mine);const full=group.kind==="select"&&groupAtLimit(group,mine);const heldBack=full&&group.choices.some(choice=>choice.isAvailable&&!selected.includes(choice.id));const text=heldBack&&(hintText||LIMIT_REACHED_HINT)||void 0;const limitHint=hintText===false?void 0:text;const hintId=usePartId();const name=usePartId();const state=useMemo(()=>({group,selected,quantities,invalid,input,control,count,room:groupRoom(group,mine),atLimit:full,limitHint:text,hintId:limitHint&&hintId,mine,name,...actions}),[group,selectionKey,invalid,input,hintText,hintId,name,actions]);const radio=group.kind==="select"&&control==="radio";const noteId=usePartId();const note=group.required&&group.kind==="select"&&!radio&&requiredNote;const content=typeof children==="function"?children(state):children;const child=props.asChild&&isValidElement(content)?content:void 0;const own=describedBy??child?.props["aria-describedby"];const description=[note&¬eId,limitHint&&hintId,own].filter(Boolean).join(" ")||void 0;const hint=limitHint?jsx("p",{id:hintId,role:"status","data-zappie-limit-hint":"",children:limitHint}):null;return jsxs(Context.Provider,{value:state,children:[note&&jsx("span",{id:noteId,hidden:true,children:note}),part("div",child?{...props,children:cloneElement(child,{"aria-describedby":description},child.props.children,hint)}:{...props,children:jsxs(Fragment,{children:[content,hint]})},state,{role:radio?"radiogroup":"group",tabIndex:-1,"aria-label":group.name,"aria-required":radio?group.required:void 0,"aria-describedby":description,"data-zappie-required":group.required?"true":void 0,"aria-invalid":invalid||void 0,"data-invalid":flag(invalid),"data-state":invalid?"invalid":"valid","data-limit-reached":flag(full),"data-zappie-option-group":group.id},composeRefs(ref,node=>{if(node){registry.set(group.id,node)}else{registry.delete(group.id)}}))]})});var ChoiceView=/*@__PURE__ */memo(forwardRef(function ChoiceView2({choice,selected,control,limitReached,hintId,name,quantity,max,toggleChoice,setChoiceQuantity,disabled:held,...props},ref){const toggle=()=>toggleChoice(choice.id);const unavailable=!choice.isAvailable||Boolean(held);const state={choice,selected,disabled:unavailable||limitReached,limitReached,control,toggle,quantity,min:choice.quantity?.min??1,max,setQuantity:next=>setChoiceQuantity(choice.id,next)};const input=jsx("input",{type:control,name,value:choice.id,checked:selected,disabled:unavailable,"aria-disabled":limitReached||void 0,"aria-describedby":limitReached?hintId:void 0,"data-zappie-choice-input":"",onChange:toggle});return labelledControl(props,state,{"data-selected":flag(selected),"data-sold-out":flag(unavailable),"data-disabled":flag(unavailable||limitReached),"data-limit-reached":flag(limitReached),"data-control":control,"data-state":selected?"checked":"unchecked","data-zappie-option":choice.id},input,ref)}));var Choice=/*@__PURE__ */forwardRef(function Choice2(props,ref){const ctx=useGroup();const id=props.choice.id;const selected=ctx.selected.includes(id);const limitReached=props.choice.isAvailable&&!canChoose(ctx.group,ctx.mine,id);return jsx(ChoiceView,{...props,ref,selected,control:ctx.control,limitReached,hintId:ctx.hintId,name:ctx.name,quantity:ctx.quantities[id]??0,max:choiceQuantityMax(ctx.group,ctx.mine,id),toggleChoice:ctx.toggle,setChoiceQuantity:ctx.setQuantity})});var Input=/*@__PURE__ */forwardRef(function Input2(props,ref){const ctx=useGroup();const id=usePartId(props.id);const toggle=ctx.group.kind==="toggle";return part("input",props,ctx,{id,type:toggle?"checkbox":ctx.group.kind==="select"?"text":ctx.group.kind,value:toggle?void 0:ctx.input,checked:toggle?ctx.input==="true":void 0,required:ctx.group.required,"aria-label":ctx.group.name,"aria-invalid":ctx.invalid||void 0,"data-invalid":flag(ctx.invalid),maxLength:ctx.group.input?.maxLength??500,placeholder:ctx.group.input?.placeholder,onChange:event=>ctx.setInput(toggle?String(event.target.checked):event.target.value)},ref)});var OptionGroup2=/*@__PURE__ */Object.assign(Group,{Input});export{Choice,OptionGroup2 as OptionGroup};
|
|
2
2
|
//# sourceMappingURL=option-group.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/item-form/option-group.tsx"],
|
|
4
|
-
"mappings": "aAKA,OACE,UACA,kBACA,WAAW,aACX,UACA,mBACA,iBACA,mBAGK,sBACP,OACE,aACA,cACA,WACA,SACA,eACA,KACA,WACA,QACA,
|
|
4
|
+
"mappings": "aAKA,OACE,UACA,kBACA,WAAW,aACX,UACA,mBACA,iBACA,mBAGK,sBACP,OACE,aACA,cACA,WACA,SACA,eACA,KACA,WACA,QACA,WAIK,QACP,OAAS,SAAY,4BACrB,OAAS,cAAiB,qBAC1B,OAAS,oBAAuB,kCAChC,OAAS,YAAa,SAA4B,sBAClD,OAAS,cAAe,gBAAmB,YAgNvC,WA2BY,SA3BZ,oBArLJ,IAAM,QAAU,eAAgB,cAQ9B,IAAI,EACN,SAAS,UAAW,CAClB,MAAM,MAAQ,WAAW,OAAO,EAChC,GAAI,CAAC,MAAO,CACV,MAAM,IAAI,MAAM,kDAAkD,CACpE,CACA,OAAO,KACT,CACA,IAAM,MAAQ,eAAgB,WAiB5B,SAAS,YACT,CACE,MAAO,SACP,aAAe,WACf,UAAW,SACX,mBAAoB,YACpB,SACA,GAAG,KACL,EACA,IACA,CACA,MAAM,IAAM,YAAY,EACxB,MAAM,SAAW,WAAW,aAAa,EACzC,MAAM,MACJ,IAAI,OAAO,KAAM,WAAc,UAAU,KAAO,SAAS,EAAE,GAAK,SAClE,MAAM,KACJ,IAAI,MAAM,SAAS,OAAQ,QAAW,OAAO,UAAY,MAAM,EAAE,GAAK,CAAC,EACzE,MAAM,SAAW,KAAK,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AgB,WAC5B,SAASC,OAAM,MAAO,IAAK,CACzB,MAAM,IAAM,SAAS,EACrB,MAAM,GAAK,UAAU,MAAM,EAAE,EAC7B,MAAM,OAAS,IAAI,MAAM,OAAS,SAClC,OAAO,KACL,QACA,MACA,IACA,CACE,GACA,KAAM,OACF,WACA,IAAI,MAAM,OAAS,SACjB,OACA,IAAI,MAAM,KAChB,MAAO,OAAS,OAAY,IAAI,MAChC,QAAS,OAAS,IAAI,QAAU,OAAS,OACzC,SAAU,IAAI,MAAM,SACpB,aAAc,IAAI,MAAM,KACxB,eAAgB,IAAI,SAAW,OAC/B,eAAgB,KAAK,IAAI,OAAO,EAChC,UAAW,IAAI,MAAM,OAAO,WAAa,IACzC,YAAa,IAAI,MAAM,OAAO,YAC9B,SAAW,OACT,IAAI,SACF,OAAS,OAAO,MAAM,OAAO,OAAO,EAAI,MAAM,OAAO,KACvD,CACJ,EACA,GACF,CACF,CACF,EAKO,IAAMC,aAAc,eAAgB,OAAO,OAAO,MAAO,CAAE,KAAM,CAAC",
|
|
5
5
|
"names": ["ctx", "group", "ChoiceView", "Choice", "Input", "OptionGroup"]
|
|
6
6
|
}
|
package/dist/item-form/root.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{previewItem,ZappieCartError}from"@zappie/sdk";import{useCart,useCartCatalogue,useZappie}from"@zappie/sdk/react";import{createContext,useCallback,useContext,useMemo,useRef,useState}from"react";import{part}from"../internal/slot.js";import{useControllableState}from"../internal/use-controllable-state.js";import{jsx}from"react/jsx-runtime";var ItemFormStateContext=/*@__PURE__ */createContext(null);function useItemForm(){const value=useContext(ItemFormStateContext);if(!value){throw new Error("ItemForm parts require ItemForm.Root")}return value}var GroupRegistry=/*@__PURE__ */createContext(null);function Root({item,value,defaultValue,onValueChange,defaultQuantity,onAdded,onCommit,onInvalid,branchRequired=false,onBranchRequired,...props}){const client=useZappie();const{actions}=useCart();const menu=useCartCatalogue();const[input,setInput]=useControllableState({value,defaultValue:{...defaultValue,itemId:item.id,quantity:defaultQuantity??defaultValue?.quantity??item.quantity.min},onChange:onValueChange});const registry=useRef(new Map);const[added,setAdded]=useState(false);const[attempted,setAttempted]=useState(false);const[failure,setFailure]=useState(null);const normalized=useMemo(()=>
|
|
1
|
+
"use client";import{previewItem,withDefaultMenu,ZappieCartError}from"@zappie/sdk";import{useCart,useCartCatalogue,useZappie}from"@zappie/sdk/react";import{createContext,useCallback,useContext,useMemo,useRef,useState}from"react";import{part}from"../internal/slot.js";import{useControllableState}from"../internal/use-controllable-state.js";import{jsx}from"react/jsx-runtime";var ItemFormStateContext=/*@__PURE__ */createContext(null);function useItemForm(){const value=useContext(ItemFormStateContext);if(!value){throw new Error("ItemForm parts require ItemForm.Root")}return value}var GroupRegistry=/*@__PURE__ */createContext(null);var ungrouped=issues=>issues.filter(issue=>!issue.groupId);function Root({item,value,defaultValue,onValueChange,defaultQuantity,onAdded,onCommit,onInvalid,branchRequired=false,onBranchRequired,menuId,...props}){const client=useZappie();const{actions}=useCart();const menu=useCartCatalogue();const[input,setInput]=useControllableState({value,defaultValue:{...defaultValue,itemId:item.id,quantity:defaultQuantity??defaultValue?.quantity??item.quantity.min},onChange:onValueChange});const registry=useRef(new Map);const[added,setAdded]=useState(false);const[attempted,setAttempted]=useState(false);const[failure,setFailure]=useState(null);const normalized=useMemo(()=>{const line={...input,itemId:item.id};if(line.menuId===void 0&&menuId!==void 0){line.menuId=menuId}return menu?withDefaultMenu(menu,line):line},[input,item.id,menuId,menu]);const preview=useMemo(()=>previewItem(item,normalized),[item,normalized]);const validation=useMemo(()=>client.cart.validate(normalized),[client,normalized,menu]);const issues=failure??(attempted&&!validation.ok?validation.issues:[]);const setValue=useCallback(next=>{setAdded(false);setFailure(null);setInput({...next,itemId:item.id})},[setInput,item.id]);const setQuantity=useCallback(quantity=>setValue({...normalized,quantity}),[setValue,normalized]);const focusIssue=useCallback(errors=>{const ids=new Set([...registry.current.keys(),...preview.groups.map(group=>group.id)]);const invalid=[...ids].flatMap(groupId=>{const issues2=errors.filter(issue=>issue.groupId===groupId);return issues2.length?[{groupId,group:preview.groups.find(group=>group.id===groupId),element:registry.current.get(groupId),issues:issues2}]:[]});invalid[0]?.element?.focus({preventScroll:true});onInvalid?.(invalid,ungrouped(errors))},[preview.groups,onInvalid]);const add=useCallback(()=>{if(branchRequired){onBranchRequired?.(normalized);return null}const result=client.cart.validate(normalized);if(!result.ok){setAttempted(true);setFailure(result.issues);focusIssue(result.issues);return null}try{const line=onCommit?onCommit(normalized):actions.add(item,normalized);setAttempted(false);setAdded(true);onAdded?.(line);return line}catch(error){if(error instanceof ZappieCartError){setAttempted(true);setFailure([...error.issues]);focusIssue([...error.issues]);return null}throw error}},[client,actions,normalized,item,onAdded,onCommit,focusIssue,branchRequired,onBranchRequired]);const context=useMemo(()=>({item,...preview,quantity:normalized.quantity??item.quantity.min,setQuantity,issues,itemIssues:ungrouped(issues),canAdd:validation.ok&&!failure,add,status:added?"added":validation.ok?"valid":"incomplete",value:normalized,setValue,branchRequired}),[item,preview,normalized,setQuantity,issues,validation.ok,failure,add,added,setValue,branchRequired]);return jsx(ItemFormStateContext.Provider,{value:context,children:jsx(GroupRegistry.Provider,{value:registry.current,children:part("div",props,context,{"data-zappie-item":item.id,"data-state":issues.length?"invalid":"valid","data-sold-out":item.isAvailable?void 0:""})})})}export{GroupRegistry,ItemFormStateContext,Root,useItemForm};
|
|
2
2
|
//# sourceMappingURL=root.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/item-form/root.tsx"],
|
|
4
|
-
"mappings": "aACA,OACE,YACA,oBAOK,cACP,OAAS,QAAS,iBAAkB,cAAiB,oBACrD,OACE,cACA,YACA,WACA,QACA,OACA,aACK,QACP,OAAS,SAA4B,sBACrC,OAAS,yBAA4B,
|
|
4
|
+
"mappings": "aACA,OACE,YACA,gBACA,oBAOK,cACP,OAAS,QAAS,iBAAkB,cAAiB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xB,OAAO,IACT,CACA,GAAI,CACF,MAAM,KAAO,SACT,SAAS,UAAU,EACnB,QAAQ,IAAI,KAAM,UAAU,EAChC,aAAa,KAAK,EAClB,SAAS,IAAI,EACb,UAAU,IAAI,EACd,OAAO,IACT,OAAS,MAAO,CACd,GAAI,iBAAiB,gBAAiB,CACpC,aAAa,IAAI,EACjB,WAAW,CAAC,GAAG,MAAM,MAAM,CAAC,EAC5B,WAAW,CAAC,GAAG,MAAM,MAAM,CAAC,EAC5B,OAAO,IACT,CACA,MAAM,KACR,CACF,EAAG,CACD,OACA,QACA,WACA,KACA,QACA,SACA,WACA,eACA,gBACF,CAAC,EACD,MAAM,QAA2B,QAC/B,KAAO,CACL,KACA,GAAG,QACH,SAAU,WAAW,UAAY,KAAK,SAAS,IAC/C,YACA,OACA,WAAY,UAAU,MAAM,EAC5B,OAAQ,WAAW,IAAM,CAAC,QAC1B,IACA,OAAQ,MAAQ,QAAU,WAAW,GAAK,QAAU,aACpD,MAAO,WACP,SACA,cACF,GACA,CACE,KACA,QACA,WACA,YACA,OACA,WAAW,GACX,QACA,IACA,MACA,SACA,cACF,CACF,EACA,OACE,IAAC,qBAAqB,SAArB,CAA8B,MAAO,QACpC,aAAC,cAAc,SAAd,CAAuB,MAAO,SAAS,QACrC,cAAK,MAAO,MAAO,QAAS,CAC3B,mBAAoB,KAAK,GACzB,aAAc,OAAO,OAAS,UAAY,QAC1C,gBAAiB,KAAK,YAAc,OAAY,EAClD,CAAC,EACH,EACF,CAEJ",
|
|
5
5
|
"names": ["issues"]
|
|
6
6
|
}
|
package/dist/payment/methods.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{createContext,forwardRef,useContext}from"react";import{usePartId}from"../internal/ids.js";import{part}from"../internal/slot.js";import{useControllableState}from"../internal/use-controllable-state.js";import{jsx}from"react/jsx-runtime";var Context=/*@__PURE__ */createContext(null);function Root({methods,value,defaultValue=null,onValueChange,...props}){const[selected,set]=useControllableState({value,defaultValue,onChange:onValueChange});const normalized=methods.map(method=>typeof method==="string"?{value:method}:method);const setValue=next=>{if(normalized.some(method=>method.value===next&&!method.disabled)){set(next)}};const state={methods:normalized,value:selected,setValue};return jsx(Context.Provider,{value:state,children:part("div",props,state,{role:"radiogroup"
|
|
1
|
+
"use client";import{createContext,forwardRef,Fragment,useContext}from"react";import{usePartId}from"../internal/ids.js";import{labelledControl}from"../internal/labelled-control.js";import{part}from"../internal/slot.js";import{useControllableState}from"../internal/use-controllable-state.js";import{jsx,jsxs}from"react/jsx-runtime";var Context=/*@__PURE__ */createContext(null);function Root({methods,value,defaultValue=null,onValueChange,...props}){const[selected,set]=useControllableState({value,defaultValue,onChange:onValueChange});const normalized=methods.map(method=>typeof method==="string"?{value:method}:method);const setValue=next=>{if(normalized.some(method=>method.value===next&&!method.disabled)){set(next)}};const name=usePartId();const state={methods:normalized,value:selected,setValue,name};return jsx(Context.Provider,{value:state,children:part("div",props,state,{role:"radiogroup"})})}var Item=/*@__PURE__ */forwardRef(function Item2({value,...props},ref){const ctx=useContext(Context);const id=usePartId();if(!ctx){throw new Error("PaymentMethods.Item requires PaymentMethods.Root")}const method=ctx.methods.find(method2=>method2.value===value);if(!method){return null}const selected=ctx.value===value;const reasonId=`${id}-reason`;const input=jsxs(Fragment,{children:[jsx("input",{id,type:"radio",name:ctx.name,value,checked:selected,disabled:method.disabled,"aria-describedby":method.reason?reasonId:void 0,"data-zappie-choice-input":"",onChange:()=>ctx.setValue(value)}),method.reason?jsx("span",{id:reasonId,hidden:true,children:method.reason}):null]});return labelledControl(props,{...method,selected},{"data-disabled":method.disabled?"":void 0,"data-selected":selected?"":void 0,"data-state":selected?"checked":"unchecked","data-control":"radio"},input,ref)});var PaymentMethods={Root,Item};export{PaymentMethods};
|
|
2
2
|
//# sourceMappingURL=methods.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/payment/methods.tsx"],
|
|
4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AAO,SACjB,mBAAkB,OAAO,OAAS,SAAW,OAC7C,2BAAyB,GACzB,SAAU,IAAM,IAAI,SAAS,KAAK,EACpC,EACC,OAAO,OACN,IAAC,QAAK,GAAI,SAAU,OAAM,KACvB,gBAAO,OACV,EACE,MACN,EAEF,OAAO,gBACL,MACA,CAAE,GAAG,OAAQ,QAAS,EACtB,CACE,gBAAiB,OAAO,SAAW,GAAK,OACxC,gBAAiB,SAAW,GAAK,OACjC,aAAc,SAAW,UAAY,YACrC,eAAgB,OAClB,EACA,MACA,GACF,CACF,CAAC,EAQM,IAAM,eAAiB,CAAE,KAAM,IAAK",
|
|
5
5
|
"names": ["Item", "method"]
|
|
6
6
|
}
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var PACKAGE_VERSION=true?"0.
|
|
1
|
+
var PACKAGE_VERSION=true?"0.24.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.
|
|
3
|
+
"version": "0.24.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,
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
"peerDependencies": {
|
|
102
102
|
"react": "^18.2.0 || ^19.0.0",
|
|
103
103
|
"react-dom": "^18.2.0 || ^19.0.0",
|
|
104
|
-
"@zappie/sdk": "^0.
|
|
104
|
+
"@zappie/sdk": "^0.25.0",
|
|
105
105
|
"react-router": "^8.4.0"
|
|
106
106
|
},
|
|
107
107
|
"peerDependenciesMeta": {
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
"@types/google.maps": "^3.66.7",
|
|
119
119
|
"esbuild": "^0.28.2",
|
|
120
120
|
"react-router": "8.5.0",
|
|
121
|
-
"@zappie/sdk": "0.
|
|
121
|
+
"@zappie/sdk": "0.25.0"
|
|
122
122
|
},
|
|
123
123
|
"license": "MIT",
|
|
124
124
|
"homepage": "https://github.com/zappie/storefront-packages#readme",
|