@zappie/theme-base 0.1.28 → 0.1.30
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 +19 -0
- package/dist/address.js +1 -99
- package/dist/address.js.map +1 -1
- package/dist/cart/address-sheet.js +1 -142
- package/dist/cart/address-sheet.js.map +1 -1
- package/dist/cart/cart-issues.js +1 -71
- package/dist/cart/cart-issues.js.map +1 -1
- package/dist/cart/cart-line-groups.js +1 -33
- package/dist/cart/cart-line-groups.js.map +1 -1
- package/dist/cart/cart-line.js +1 -84
- package/dist/cart/cart-line.js.map +1 -1
- package/dist/cart/cart-lines.js +1 -26
- package/dist/cart/cart-lines.js.map +1 -1
- package/dist/cart/cart-schedule.js +1 -23
- package/dist/cart/cart-schedule.js.map +1 -1
- package/dist/cart/cart-sheet.js +1 -34
- package/dist/cart/cart-sheet.js.map +1 -1
- package/dist/cart/checkout-cta.js +1 -80
- package/dist/cart/checkout-cta.js.map +1 -1
- package/dist/cart/checkout-state.js +1 -73
- package/dist/cart/checkout-state.js.map +1 -1
- package/dist/cart/clear-cart.js +1 -43
- package/dist/cart/clear-cart.js.map +1 -1
- package/dist/cart/customer-details.js +1 -69
- package/dist/cart/customer-details.js.map +1 -1
- package/dist/cart/delivery-distance.js +1 -21
- package/dist/cart/delivery-distance.js.map +1 -1
- package/dist/cart/empty-cart.js +1 -13
- package/dist/cart/empty-cart.js.map +1 -1
- package/dist/cart/fulfilment-panel.js +1 -82
- package/dist/cart/fulfilment-panel.js.map +1 -1
- package/dist/cart/line-editor.js +1 -34
- package/dist/cart/line-editor.js.map +1 -1
- package/dist/cart/line-options.js +1 -96
- package/dist/cart/line-options.js.map +1 -1
- package/dist/cart/loading.js +1 -16
- package/dist/cart/loading.js.map +1 -1
- package/dist/cart/promo-sheet.js +1 -102
- package/dist/cart/promo-sheet.js.map +1 -1
- package/dist/cart/region-picker.js +1 -39
- package/dist/cart/region-picker.js.map +1 -1
- package/dist/cart/rewards-sheet.js +1 -85
- package/dist/cart/rewards-sheet.js.map +1 -1
- package/dist/cart/schedule-sheet.js +1 -86
- package/dist/cart/schedule-sheet.js.map +1 -1
- package/dist/cart/theme-class.js +1 -14
- package/dist/cart/theme-class.js.map +1 -1
- package/dist/cart/totals.js +1 -78
- package/dist/cart/totals.js.map +1 -1
- package/dist/cart/use-address-selection.js +1 -129
- package/dist/cart/use-address-selection.js.map +1 -1
- package/dist/cart.js +1 -91
- package/dist/cart.js.map +1 -1
- package/dist/catalogue/catalogue-cart.js +1 -24
- package/dist/catalogue/catalogue-cart.js.map +1 -1
- package/dist/catalogue/catalogue-header.js +1 -87
- package/dist/catalogue/catalogue-header.js.map +1 -1
- package/dist/catalogue/catalogue-pages.js +1 -67
- package/dist/catalogue/catalogue-pages.js.map +1 -1
- package/dist/catalogue/catalogue-search.js +1 -88
- package/dist/catalogue/catalogue-search.js.map +1 -1
- package/dist/catalogue/category-navigation.js +1 -97
- package/dist/catalogue/category-navigation.js.map +1 -1
- package/dist/catalogue/category-section.js +1 -112
- package/dist/catalogue/category-section.js.map +1 -1
- package/dist/catalogue/info-banners.js +1 -149
- package/dist/catalogue/info-banners.js.map +1 -1
- package/dist/catalogue/item-tile.js +1 -54
- package/dist/catalogue/item-tile.js.map +1 -1
- package/dist/catalogue/loader.js +1 -135
- package/dist/catalogue/loader.js.map +1 -1
- package/dist/catalogue/presentation.js +1 -49
- package/dist/catalogue/presentation.js.map +1 -1
- package/dist/catalogue/saved-catalogue-sync.js +1 -114
- package/dist/catalogue/saved-catalogue-sync.js.map +1 -1
- package/dist/catalogue/use-catalogue-data.js +1 -87
- package/dist/catalogue/use-catalogue-data.js.map +1 -1
- package/dist/catalogue/use-category-scroll.js +1 -114
- package/dist/catalogue/use-category-scroll.js.map +1 -1
- package/dist/catalogue/use-item-opener.js +1 -45
- package/dist/catalogue/use-item-opener.js.map +1 -1
- package/dist/catalogue/use-search-source.js +1 -131
- package/dist/catalogue/use-search-source.js.map +1 -1
- package/dist/catalogue.js +1 -198
- package/dist/catalogue.js.map +1 -1
- package/dist/checkout.js +1 -151
- package/dist/checkout.js.map +1 -1
- package/dist/host-bridge.js +1 -23
- package/dist/host-bridge.js.map +1 -1
- package/dist/index.js +1 -5
- package/dist/index.js.map +1 -1
- package/dist/item/configurator-commit.js +1 -14
- package/dist/item/configurator-commit.js.map +1 -1
- package/dist/item/configurator-draft.js +1 -62
- package/dist/item/configurator-draft.js.map +1 -1
- package/dist/item/configurator.js +1 -134
- package/dist/item/configurator.js.map +1 -1
- package/dist/item/note.js +1 -64
- package/dist/item/note.js.map +1 -1
- package/dist/item/variant-status.js +1 -22
- package/dist/item/variant-status.js.map +1 -1
- package/dist/item-frame.js +1 -61
- package/dist/item-frame.js.map +1 -1
- package/dist/item.js +1 -152
- package/dist/item.js.map +1 -1
- package/dist/navigation.js +1 -40
- package/dist/navigation.js.map +1 -1
- package/dist/url-navigation-state.js +1 -60
- package/dist/url-navigation-state.js.map +1 -1
- package/dist/url-navigation.js +1 -139
- package/dist/url-navigation.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @zappie/theme-base
|
|
2
2
|
|
|
3
|
+
## 0.1.30
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 295d5e1: The published JavaScript carries no whitespace or comments. Identifiers, function names, directives such as `"use client"` and pure annotations stay as written, and each module's source map still points into its source, so a site's own bundle is the same size as before. The packed archives are smaller: the SDK by about 17 KB, foundations by about 9 KB and the base theme by about 7 KB.
|
|
8
|
+
- Updated dependencies [2ea70d8]
|
|
9
|
+
- Updated dependencies [295d5e1]
|
|
10
|
+
- @zappie/foundations@0.16.0
|
|
11
|
+
- @zappie/sdk@0.18.1
|
|
12
|
+
|
|
13
|
+
## 0.1.29
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [b2d1af9]
|
|
18
|
+
- Updated dependencies [59968bd]
|
|
19
|
+
- @zappie/sdk@0.18.0
|
|
20
|
+
- @zappie/foundations@0.15.0
|
|
21
|
+
|
|
3
22
|
## 0.1.28
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/address.js
CHANGED
|
@@ -1,100 +1,2 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
// src/address.tsx
|
|
4
|
-
import {
|
|
5
|
-
createContext,
|
|
6
|
-
useContext
|
|
7
|
-
} from "react";
|
|
8
|
-
import { jsx } from "react/jsx-runtime";
|
|
9
|
-
function deliveryAddress(place, source) {
|
|
10
|
-
const result = {
|
|
11
|
-
line1: place.line1,
|
|
12
|
-
placeId: place.place_id,
|
|
13
|
-
coordinates: { lat: place.lat, lng: place.lng }
|
|
14
|
-
};
|
|
15
|
-
if (place.city !== void 0) {
|
|
16
|
-
result.city = place.city;
|
|
17
|
-
}
|
|
18
|
-
if (source?.line2 !== void 0) {
|
|
19
|
-
result.line2 = source.line2;
|
|
20
|
-
}
|
|
21
|
-
if (source?.instructions !== void 0) {
|
|
22
|
-
result.instructions = source.instructions;
|
|
23
|
-
}
|
|
24
|
-
return result;
|
|
25
|
-
}
|
|
26
|
-
var Context = createContext(null);
|
|
27
|
-
function AddressLookupProvider({
|
|
28
|
-
lookup,
|
|
29
|
-
children
|
|
30
|
-
}) {
|
|
31
|
-
return /* @__PURE__ */ jsx(Context.Provider, { value: lookup, children });
|
|
32
|
-
}
|
|
33
|
-
function useAddressLookup() {
|
|
34
|
-
const lookup = useContext(Context);
|
|
35
|
-
if (!lookup) {
|
|
36
|
-
throw new Error("useAddressLookup requires AddressLookupProvider");
|
|
37
|
-
}
|
|
38
|
-
return lookup;
|
|
39
|
-
}
|
|
40
|
-
function createSdkAddressLookup({
|
|
41
|
-
places,
|
|
42
|
-
branchId
|
|
43
|
-
}) {
|
|
44
|
-
let sessionToken = crypto.randomUUID();
|
|
45
|
-
const Map = ({ address }) => {
|
|
46
|
-
if (!address.coordinates) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
return (
|
|
50
|
-
// The theme can't use next/image; the map's size is fixed by the API.
|
|
51
|
-
/* @__PURE__ */ jsx(
|
|
52
|
-
"img",
|
|
53
|
-
{
|
|
54
|
-
className: "z-base-address-map",
|
|
55
|
-
src: places.staticMapUrl(
|
|
56
|
-
address.coordinates.lat,
|
|
57
|
-
address.coordinates.lng,
|
|
58
|
-
branchId
|
|
59
|
-
),
|
|
60
|
-
alt: `Map of ${address.line1}`,
|
|
61
|
-
width: 640,
|
|
62
|
-
height: 320,
|
|
63
|
-
loading: "lazy"
|
|
64
|
-
}
|
|
65
|
-
)
|
|
66
|
-
);
|
|
67
|
-
};
|
|
68
|
-
return {
|
|
69
|
-
async suggest(query) {
|
|
70
|
-
const suggestions = await places.autocomplete(query, sessionToken);
|
|
71
|
-
return suggestions.map((suggestion) => ({
|
|
72
|
-
placeId: suggestion.place_id,
|
|
73
|
-
address: suggestion.secondary ? `${suggestion.text}, ${suggestion.secondary}` : suggestion.text,
|
|
74
|
-
sessionToken
|
|
75
|
-
}));
|
|
76
|
-
},
|
|
77
|
-
async resolve(address, token) {
|
|
78
|
-
if (!address.placeId) {
|
|
79
|
-
throw new Error("Choose a suggested delivery address");
|
|
80
|
-
}
|
|
81
|
-
const place = await places.place(address.placeId, {
|
|
82
|
-
branchId,
|
|
83
|
-
sessionToken: token ?? sessionToken
|
|
84
|
-
});
|
|
85
|
-
sessionToken = crypto.randomUUID();
|
|
86
|
-
return deliveryAddress(place, address);
|
|
87
|
-
},
|
|
88
|
-
async reverse({ lat, lng }) {
|
|
89
|
-
const place = await places.reverse(lat, lng);
|
|
90
|
-
return deliveryAddress(place);
|
|
91
|
-
},
|
|
92
|
-
Map
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
export {
|
|
96
|
-
AddressLookupProvider,
|
|
97
|
-
createSdkAddressLookup,
|
|
98
|
-
useAddressLookup
|
|
99
|
-
};
|
|
1
|
+
"use client";import{createContext,useContext}from"react";import{jsx}from"react/jsx-runtime";function deliveryAddress(place,source){const result={line1:place.line1,placeId:place.place_id,coordinates:{lat:place.lat,lng:place.lng}};if(place.city!==void 0){result.city=place.city}if(source?.line2!==void 0){result.line2=source.line2}if(source?.instructions!==void 0){result.instructions=source.instructions}return result}var Context=createContext(null);function AddressLookupProvider({lookup,children}){return jsx(Context.Provider,{value:lookup,children})}function useAddressLookup(){const lookup=useContext(Context);if(!lookup){throw new Error("useAddressLookup requires AddressLookupProvider")}return lookup}function createSdkAddressLookup({places,branchId}){let sessionToken=crypto.randomUUID();const Map=({address})=>{if(!address.coordinates){return null}return jsx("img",{className:"z-base-address-map",src:places.staticMapUrl(address.coordinates.lat,address.coordinates.lng,branchId),alt:`Map of ${address.line1}`,width:640,height:320,loading:"lazy"})};return{async suggest(query){const suggestions=await places.autocomplete(query,sessionToken);return suggestions.map(suggestion=>({placeId:suggestion.place_id,address:suggestion.secondary?`${suggestion.text}, ${suggestion.secondary}`:suggestion.text,sessionToken}))},async resolve(address,token){if(!address.placeId){throw new Error("Choose a suggested delivery address")}const place=await places.place(address.placeId,{branchId,sessionToken:token??sessionToken});sessionToken=crypto.randomUUID();return deliveryAddress(place,address)},async reverse({lat,lng}){const place=await places.reverse(lat,lng);return deliveryAddress(place)},Map}}export{AddressLookupProvider,createSdkAddressLookup,useAddressLookup};
|
|
100
2
|
//# sourceMappingURL=address.js.map
|
package/dist/address.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/address.tsx"],
|
|
4
4
|
"sourcesContent": ["\"use client\";\n\nimport type { DeliveryAddress } from \"@zappie/sdk\";\nimport type { Place, PlacesClient } from \"@zappie/sdk/places\";\nimport {\n createContext,\n useContext,\n type ComponentType,\n type ReactNode,\n} from \"react\";\n\nexport type AddressSuggestion = {\n placeId: string;\n address: string;\n sessionToken?: string;\n};\n\nexport type AddressLookup = {\n suggest(query: string): Promise<AddressSuggestion[]>;\n reverse?(coordinates: { lat: number; lng: number }): Promise<DeliveryAddress>;\n resolve?(\n address: DeliveryAddress,\n sessionToken?: string,\n ): Promise<DeliveryAddress>;\n Map?: ComponentType<{ address: DeliveryAddress }>;\n};\n\nfunction deliveryAddress(\n place: Place,\n source?: DeliveryAddress,\n): DeliveryAddress {\n const result: DeliveryAddress = {\n line1: place.line1,\n placeId: place.place_id,\n coordinates: { lat: place.lat, lng: place.lng },\n };\n if (place.city !== undefined) {\n result.city = place.city;\n }\n if (source?.line2 !== undefined) {\n result.line2 = source.line2;\n }\n if (source?.instructions !== undefined) {\n result.instructions = source.instructions;\n }\n return result;\n}\n\nconst Context = createContext<AddressLookup | null>(null);\n\nexport function AddressLookupProvider({\n lookup,\n children,\n}: {\n lookup: AddressLookup;\n children: ReactNode;\n}) {\n return <Context.Provider value={lookup}>{children}</Context.Provider>;\n}\n\nexport function useAddressLookup() {\n const lookup = useContext(Context);\n if (!lookup) {\n throw new Error(\"useAddressLookup requires AddressLookupProvider\");\n }\n return lookup;\n}\n\nexport function createSdkAddressLookup({\n places,\n branchId,\n}: {\n places: PlacesClient;\n branchId: string;\n}): AddressLookup {\n let sessionToken = crypto.randomUUID();\n const Map = ({ address }: { address: DeliveryAddress }) => {\n if (!address.coordinates) {\n return null;\n }\n return (\n // The theme can't use next/image; the map's size is fixed by the API.\n <img\n className=\"z-base-address-map\"\n src={places.staticMapUrl(\n address.coordinates.lat,\n address.coordinates.lng,\n branchId,\n )}\n alt={`Map of ${address.line1}`}\n width={640}\n height={320}\n loading=\"lazy\"\n />\n );\n };\n return {\n async suggest(query) {\n const suggestions = await places.autocomplete(query, sessionToken);\n return suggestions.map((suggestion) => ({\n placeId: suggestion.place_id,\n address: suggestion.secondary\n ? `${suggestion.text}, ${suggestion.secondary}`\n : suggestion.text,\n sessionToken,\n }));\n },\n async resolve(address, token) {\n if (!address.placeId) {\n throw new Error(\"Choose a suggested delivery address\");\n }\n const place = await places.place(address.placeId, {\n branchId,\n sessionToken: token ?? sessionToken,\n });\n sessionToken = crypto.randomUUID();\n return deliveryAddress(place, address);\n },\n async reverse({ lat, lng }) {\n const place = await places.reverse(lat, lng);\n return deliveryAddress(place);\n },\n Map,\n };\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": "aAIA,OACE,cACA,eAGK,QAgDE,mCA9BT,SAAS,gBACP,MACA,OACiB,CACjB,MAAM,OAA0B,CAC9B,MAAO,MAAM,MACb,QAAS,MAAM,SACf,YAAa,CAAE,IAAK,MAAM,IAAK,IAAK,MAAM,GAAI,CAChD,EACA,GAAI,MAAM,OAAS,OAAW,CAC5B,OAAO,KAAO,MAAM,IACtB,CACA,GAAI,QAAQ,QAAU,OAAW,CAC/B,OAAO,MAAQ,OAAO,KACxB,CACA,GAAI,QAAQ,eAAiB,OAAW,CACtC,OAAO,aAAe,OAAO,YAC/B,CACA,OAAO,MACT,CAEA,IAAM,QAAU,cAAoC,IAAI,EAEjD,SAAS,sBAAsB,CACpC,OACA,QACF,EAGG,CACD,OAAO,IAAC,QAAQ,SAAR,CAAiB,MAAO,OAAS,SAAS,CACpD,CAEO,SAAS,kBAAmB,CACjC,MAAM,OAAS,WAAW,OAAO,EACjC,GAAI,CAAC,OAAQ,CACX,MAAM,IAAI,MAAM,iDAAiD,CACnE,CACA,OAAO,MACT,CAEO,SAAS,uBAAuB,CACrC,OACA,QACF,EAGkB,CAChB,IAAI,aAAe,OAAO,WAAW,EACrC,MAAM,IAAM,CAAC,CAAE,OAAQ,IAAoC,CACzD,GAAI,CAAC,QAAQ,YAAa,CACxB,OAAO,IACT,CACA,OAEE,IAAC,OACC,UAAU,qBACV,IAAK,OAAO,aACV,QAAQ,YAAY,IACpB,QAAQ,YAAY,IACpB,QACF,EACA,IAAK,UAAU,QAAQ,KAAK,GAC5B,MAAO,IACP,OAAQ,IACR,QAAQ,OACV,CAEJ,EACA,MAAO,CACL,MAAM,QAAQ,MAAO,CACnB,MAAM,YAAc,MAAM,OAAO,aAAa,MAAO,YAAY,EACjE,OAAO,YAAY,IAAK,aAAgB,CACtC,QAAS,WAAW,SACpB,QAAS,WAAW,UAChB,GAAG,WAAW,IAAI,KAAK,WAAW,SAAS,GAC3C,WAAW,KACf,YACF,EAAE,CACJ,EACA,MAAM,QAAQ,QAAS,MAAO,CAC5B,GAAI,CAAC,QAAQ,QAAS,CACpB,MAAM,IAAI,MAAM,qCAAqC,CACvD,CACA,MAAM,MAAQ,MAAM,OAAO,MAAM,QAAQ,QAAS,CAChD,SACA,aAAc,OAAS,YACzB,CAAC,EACD,aAAe,OAAO,WAAW,EACjC,OAAO,gBAAgB,MAAO,OAAO,CACvC,EACA,MAAM,QAAQ,CAAE,IAAK,GAAI,EAAG,CAC1B,MAAM,MAAQ,MAAM,OAAO,QAAQ,IAAK,GAAG,EAC3C,OAAO,gBAAgB,KAAK,CAC9B,EACA,GACF,CACF",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,143 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { Address, useOverlay } from "@zappie/foundations";
|
|
3
|
-
import { useCart } from "@zappie/sdk/react";
|
|
4
|
-
import { Fragment, useState } from "react";
|
|
5
|
-
import { useAddressLookup } from "../address.js";
|
|
6
|
-
import { useBaseHostBridge } from "../host-bridge.js";
|
|
7
|
-
import { CartSheet } from "./cart-sheet.js";
|
|
8
|
-
import { useAddressSelection } from "./use-address-selection.js";
|
|
9
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
-
function AddressForm() {
|
|
11
|
-
const cart = useCart();
|
|
12
|
-
const lookup = useAddressLookup();
|
|
13
|
-
const bridge = useBaseHostBridge();
|
|
14
|
-
const overlay = useOverlay("cart_sheet", "address");
|
|
15
|
-
const current = cart.fulfilment?.type === "delivery" ? cart.fulfilment.address : void 0;
|
|
16
|
-
const {
|
|
17
|
-
selected,
|
|
18
|
-
query,
|
|
19
|
-
busy,
|
|
20
|
-
error: lookupError,
|
|
21
|
-
suggestions,
|
|
22
|
-
changeQuery,
|
|
23
|
-
select,
|
|
24
|
-
findCurrentLocation,
|
|
25
|
-
locating
|
|
26
|
-
} = useAddressSelection(current);
|
|
27
|
-
const [instructions, setInstructions] = useState(current?.instructions ?? "");
|
|
28
|
-
const [error, setError] = useState(null);
|
|
29
|
-
const save = () => {
|
|
30
|
-
if (!selected || !cart.branchId || busy) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
setError(null);
|
|
34
|
-
try {
|
|
35
|
-
const fulfilment = {
|
|
36
|
-
type: "delivery",
|
|
37
|
-
branchId: cart.branchId,
|
|
38
|
-
address: { ...selected, instructions },
|
|
39
|
-
...cart.fulfilment && "scheduledFor" in cart.fulfilment ? { scheduledFor: cart.fulfilment.scheduledFor } : {}
|
|
40
|
-
};
|
|
41
|
-
cart.actions.setFulfilment(fulfilment);
|
|
42
|
-
bridge.saveFulfilment?.(fulfilment);
|
|
43
|
-
overlay.close();
|
|
44
|
-
} catch (failure) {
|
|
45
|
-
setError(
|
|
46
|
-
failure instanceof Error ? failure.message : "Unable to save this address"
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
51
|
-
lookup.reverse && typeof navigator !== "undefined" && navigator.geolocation && /* @__PURE__ */ jsx(
|
|
52
|
-
"button",
|
|
53
|
-
{
|
|
54
|
-
type: "button",
|
|
55
|
-
className: "z-base-button-secondary",
|
|
56
|
-
disabled: busy,
|
|
57
|
-
onClick: findCurrentLocation,
|
|
58
|
-
children: locating ? "Finding your location\u2026" : "Use my current location"
|
|
59
|
-
}
|
|
60
|
-
),
|
|
61
|
-
/* @__PURE__ */ jsx(
|
|
62
|
-
Address.Picker,
|
|
63
|
-
{
|
|
64
|
-
query,
|
|
65
|
-
onQueryChange: changeQuery,
|
|
66
|
-
getSuggestions: suggestions,
|
|
67
|
-
onSelect: (value) => {
|
|
68
|
-
if ("address" in value) {
|
|
69
|
-
void select(value.address);
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
children: ({ suggestions: suggestions2, status, isOpen }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
73
|
-
/* @__PURE__ */ jsxs("label", { className: "z-base-field", htmlFor: "z-base-delivery-address", children: [
|
|
74
|
-
"Delivery address",
|
|
75
|
-
/* @__PURE__ */ jsx(
|
|
76
|
-
Address.Input,
|
|
77
|
-
{
|
|
78
|
-
className: "z-base-input",
|
|
79
|
-
id: "z-base-delivery-address",
|
|
80
|
-
"aria-label": "Delivery address"
|
|
81
|
-
}
|
|
82
|
-
)
|
|
83
|
-
] }),
|
|
84
|
-
status === "loading" && /* @__PURE__ */ jsx("p", { role: "status", children: "Finding addresses\u2026" }),
|
|
85
|
-
status === "error" && /* @__PURE__ */ jsx("p", { role: "alert", children: "Unable to find addresses. Try again." }),
|
|
86
|
-
isOpen && /* @__PURE__ */ jsx(Address.Suggestions, { className: "z-base-suggestions", children: suggestions2.map((value, index) => /* @__PURE__ */ jsx(
|
|
87
|
-
Address.Suggestion,
|
|
88
|
-
{
|
|
89
|
-
index,
|
|
90
|
-
className: "z-base-choice",
|
|
91
|
-
children: value.label
|
|
92
|
-
},
|
|
93
|
-
value.id
|
|
94
|
-
)) }),
|
|
95
|
-
isOpen && status === "ready" && query && suggestions2.length === 0 && /* @__PURE__ */ jsx("p", { children: "No matching addresses." })
|
|
96
|
-
] })
|
|
97
|
-
}
|
|
98
|
-
),
|
|
99
|
-
/* @__PURE__ */ jsxs("label", { className: "z-base-field", children: [
|
|
100
|
-
"Delivery instructions",
|
|
101
|
-
/* @__PURE__ */ jsx(
|
|
102
|
-
"textarea",
|
|
103
|
-
{
|
|
104
|
-
className: "z-base-input",
|
|
105
|
-
maxLength: 500,
|
|
106
|
-
value: instructions,
|
|
107
|
-
onChange: (event) => setInstructions(event.target.value)
|
|
108
|
-
}
|
|
109
|
-
)
|
|
110
|
-
] }),
|
|
111
|
-
selected && lookup.Map && /* @__PURE__ */ jsx(lookup.Map, { address: selected }),
|
|
112
|
-
lookupError && /* @__PURE__ */ jsx("p", { role: "alert", children: lookupError }),
|
|
113
|
-
error && /* @__PURE__ */ jsx("p", { role: "alert", children: error }),
|
|
114
|
-
/* @__PURE__ */ jsx(
|
|
115
|
-
"button",
|
|
116
|
-
{
|
|
117
|
-
type: "button",
|
|
118
|
-
className: "z-base-button",
|
|
119
|
-
disabled: !selected || busy,
|
|
120
|
-
onClick: () => {
|
|
121
|
-
void save();
|
|
122
|
-
},
|
|
123
|
-
children: busy ? "Locating address\u2026" : "Save address"
|
|
124
|
-
}
|
|
125
|
-
)
|
|
126
|
-
] });
|
|
127
|
-
}
|
|
128
|
-
function AddressSheet() {
|
|
129
|
-
const cart = useCart();
|
|
130
|
-
return /* @__PURE__ */ jsx(
|
|
131
|
-
CartSheet,
|
|
132
|
-
{
|
|
133
|
-
id: "address",
|
|
134
|
-
title: "Delivery address",
|
|
135
|
-
trigger: cart.fulfilment?.type === "delivery" ? "Change address" : "Add delivery address",
|
|
136
|
-
children: /* @__PURE__ */ jsx(AddressForm, {})
|
|
137
|
-
}
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
export {
|
|
141
|
-
AddressSheet
|
|
142
|
-
};
|
|
1
|
+
import{Address,useOverlay}from"@zappie/foundations";import{useCart}from"@zappie/sdk/react";import{Fragment,useState}from"react";import{useAddressLookup}from"../address.js";import{useBaseHostBridge}from"../host-bridge.js";import{CartSheet}from"./cart-sheet.js";import{useAddressSelection}from"./use-address-selection.js";import{jsx,jsxs}from"react/jsx-runtime";function AddressForm(){const cart=useCart();const lookup=useAddressLookup();const bridge=useBaseHostBridge();const overlay=useOverlay("cart_sheet","address");const current=cart.fulfilment?.type==="delivery"?cart.fulfilment.address:void 0;const{selected,query,busy,error:lookupError,suggestions,changeQuery,select,findCurrentLocation,locating}=useAddressSelection(current);const[instructions,setInstructions]=useState(current?.instructions??"");const[error,setError]=useState(null);const save=()=>{if(!selected||!cart.branchId||busy){return}setError(null);try{const fulfilment={type:"delivery",branchId:cart.branchId,address:{...selected,instructions},...cart.fulfilment&&"scheduledFor"in cart.fulfilment?{scheduledFor:cart.fulfilment.scheduledFor}:{}};cart.actions.setFulfilment(fulfilment);bridge.saveFulfilment?.(fulfilment);overlay.close()}catch(failure){setError(failure instanceof Error?failure.message:"Unable to save this address")}};return jsxs(Fragment,{children:[lookup.reverse&&typeof navigator!=="undefined"&&navigator.geolocation&&jsx("button",{type:"button",className:"z-base-button-secondary",disabled:busy,onClick:findCurrentLocation,children:locating?"Finding your location\u2026":"Use my current location"}),jsx(Address.Picker,{query,onQueryChange:changeQuery,getSuggestions:suggestions,onSelect:value=>{if("address"in value){void select(value.address)}},children:({suggestions:suggestions2,status,isOpen})=>jsxs(Fragment,{children:[jsxs("label",{className:"z-base-field",htmlFor:"z-base-delivery-address",children:["Delivery address",jsx(Address.Input,{className:"z-base-input",id:"z-base-delivery-address","aria-label":"Delivery address"})]}),status==="loading"&&jsx("p",{role:"status",children:"Finding addresses\u2026"}),status==="error"&&jsx("p",{role:"alert",children:"Unable to find addresses. Try again."}),isOpen&&jsx(Address.Suggestions,{className:"z-base-suggestions",children:suggestions2.map((value,index)=>jsx(Address.Suggestion,{index,className:"z-base-choice",children:value.label},value.id))}),isOpen&&status==="ready"&&query&&suggestions2.length===0&&jsx("p",{children:"No matching addresses."})]})}),jsxs("label",{className:"z-base-field",children:["Delivery instructions",jsx("textarea",{className:"z-base-input",maxLength:500,value:instructions,onChange:event=>setInstructions(event.target.value)})]}),selected&&lookup.Map&&jsx(lookup.Map,{address:selected}),lookupError&&jsx("p",{role:"alert",children:lookupError}),error&&jsx("p",{role:"alert",children:error}),jsx("button",{type:"button",className:"z-base-button",disabled:!selected||busy,onClick:()=>{void save()},children:busy?"Locating address\u2026":"Save address"})]})}function AddressSheet(){const cart=useCart();return jsx(CartSheet,{id:"address",title:"Delivery address",trigger:cart.fulfilment?.type==="delivery"?"Change address":"Add delivery address",children:jsx(AddressForm,{})})}export{AddressSheet};
|
|
143
2
|
//# sourceMappingURL=address-sheet.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/cart/address-sheet.tsx"],
|
|
4
4
|
"sourcesContent": ["import { Address, useOverlay } from \"@zappie/foundations\";\nimport { useCart } from \"@zappie/sdk/react\";\nimport { Fragment, useState } from \"react\";\nimport { useAddressLookup } from \"../address\";\nimport { useBaseHostBridge } from \"../host-bridge\";\nimport { CartSheet } from \"./cart-sheet\";\nimport { useAddressSelection } from \"./use-address-selection\";\nfunction AddressForm() {\n const cart = useCart();\n const lookup = useAddressLookup();\n const bridge = useBaseHostBridge();\n const overlay = useOverlay(\"cart_sheet\", \"address\");\n const current =\n cart.fulfilment?.type === \"delivery\" ? cart.fulfilment.address : undefined;\n const {\n selected,\n query,\n busy,\n error: lookupError,\n suggestions,\n changeQuery,\n select,\n findCurrentLocation,\n locating,\n } = useAddressSelection(current);\n const [instructions, setInstructions] = useState(current?.instructions ?? \"\");\n const [error, setError] = useState<string | null>(null);\n const save = () => {\n if (!selected || !cart.branchId || busy) {\n return;\n }\n setError(null);\n try {\n const fulfilment = {\n type: \"delivery\" as const,\n branchId: cart.branchId,\n address: { ...selected, instructions },\n ...(cart.fulfilment && \"scheduledFor\" in cart.fulfilment\n ? { scheduledFor: cart.fulfilment.scheduledFor }\n : {}),\n };\n cart.actions.setFulfilment(fulfilment);\n bridge.saveFulfilment?.(fulfilment);\n overlay.close();\n } catch (failure) {\n setError(\n failure instanceof Error\n ? failure.message\n : \"Unable to save this address\",\n );\n }\n };\n return (\n <Fragment>\n {lookup.reverse &&\n typeof navigator !== \"undefined\" &&\n navigator.geolocation && (\n <button\n type=\"button\"\n className=\"z-base-button-secondary\"\n disabled={busy}\n onClick={findCurrentLocation}\n >\n {locating ? \"Finding your location\u2026\" : \"Use my current location\"}\n </button>\n )}\n <Address.Picker\n query={query}\n onQueryChange={changeQuery}\n getSuggestions={suggestions}\n onSelect={(value) => {\n if (\"address\" in value) {\n void select(value.address);\n }\n }}\n >\n {({ suggestions, status, isOpen }) => (\n <Fragment>\n <label className=\"z-base-field\" htmlFor=\"z-base-delivery-address\">\n Delivery address\n <Address.Input\n className=\"z-base-input\"\n id=\"z-base-delivery-address\"\n aria-label=\"Delivery address\"\n />\n </label>\n {status === \"loading\" && <p role=\"status\">Finding addresses\u2026</p>}\n {status === \"error\" && (\n <p role=\"alert\">Unable to find addresses. Try again.</p>\n )}\n {isOpen && (\n <Address.Suggestions className=\"z-base-suggestions\">\n {suggestions.map((value, index) => (\n <Address.Suggestion\n key={value.id}\n index={index}\n className=\"z-base-choice\"\n >\n {value.label}\n </Address.Suggestion>\n ))}\n </Address.Suggestions>\n )}\n {isOpen &&\n status === \"ready\" &&\n query &&\n suggestions.length === 0 && <p>No matching addresses.</p>}\n </Fragment>\n )}\n </Address.Picker>\n <label className=\"z-base-field\">\n Delivery instructions\n <textarea\n className=\"z-base-input\"\n maxLength={500}\n value={instructions}\n onChange={(event) => setInstructions(event.target.value)}\n />\n </label>\n {selected && lookup.Map && <lookup.Map address={selected} />}\n {lookupError && <p role=\"alert\">{lookupError}</p>}\n {error && <p role=\"alert\">{error}</p>}\n <button\n type=\"button\"\n className=\"z-base-button\"\n disabled={!selected || busy}\n onClick={() => {\n void save();\n }}\n >\n {busy ? \"Locating address\u2026\" : \"Save address\"}\n </button>\n </Fragment>\n );\n}\nexport function AddressSheet() {\n const cart = useCart();\n return (\n <CartSheet\n id=\"address\"\n title=\"Delivery address\"\n trigger={\n cart.fulfilment?.type === \"delivery\"\n ? \"Change address\"\n : \"Add delivery address\"\n }\n >\n <AddressForm />\n </CartSheet>\n );\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": "AAAA,OAAS,QAAS,eAAkB,sBACpC,OAAS,YAAe,oBACxB,OAAS,SAAU,aAAgB,QACnC,OAAS,qBAAwB,gBACjC,OAAS,sBAAyB,oBAClC,OAAS,cAAiB,kBAC1B,OAAS,wBAA2B,6BAmD1B,WAqBE,SArBF,oBAlDV,SAAS,aAAc,CACrB,MAAM,KAAO,QAAQ,EACrB,MAAM,OAAS,iBAAiB,EAChC,MAAM,OAAS,kBAAkB,EACjC,MAAM,QAAU,WAAW,aAAc,SAAS,EAClD,MAAM,QACJ,KAAK,YAAY,OAAS,WAAa,KAAK,WAAW,QAAU,OACnE,KAAM,CACJ,SACA,MACA,KACA,MAAO,YACP,YACA,YACA,OACA,oBACA,QACF,EAAI,oBAAoB,OAAO,EAC/B,KAAM,CAAC,aAAc,eAAe,EAAI,SAAS,SAAS,cAAgB,EAAE,EAC5E,KAAM,CAAC,MAAO,QAAQ,EAAI,SAAwB,IAAI,EACtD,MAAM,KAAO,IAAM,CACjB,GAAI,CAAC,UAAY,CAAC,KAAK,UAAY,KAAM,CACvC,MACF,CACA,SAAS,IAAI,EACb,GAAI,CACF,MAAM,WAAa,CACjB,KAAM,WACN,SAAU,KAAK,SACf,QAAS,CAAE,GAAG,SAAU,YAAa,EACrC,GAAI,KAAK,YAAc,iBAAkB,KAAK,WAC1C,CAAE,aAAc,KAAK,WAAW,YAAa,EAC7C,CAAC,CACP,EACA,KAAK,QAAQ,cAAc,UAAU,EACrC,OAAO,iBAAiB,UAAU,EAClC,QAAQ,MAAM,CAChB,OAAS,QAAS,CAChB,SACE,mBAAmB,MACf,QAAQ,QACR,6BACN,CACF,CACF,EACA,OACE,KAAC,UACE,iBAAO,SACN,OAAO,YAAc,aACrB,UAAU,aACR,IAAC,UACC,KAAK,SACL,UAAU,0BACV,SAAU,KACV,QAAS,oBAER,kBAAW,8BAA2B,0BACzC,EAEJ,IAAC,QAAQ,OAAR,CACC,MACA,cAAe,YACf,eAAgB,YAChB,SAAW,OAAU,CACnB,GAAI,YAAa,MAAO,CACtB,KAAK,OAAO,MAAM,OAAO,CAC3B,CACF,EAEC,UAAC,CAAE,YAAAA,aAAa,OAAQ,MAAO,IAC9B,KAAC,UACC,eAAC,SAAM,UAAU,eAAe,QAAQ,0BAA0B,6BAEhE,IAAC,QAAQ,MAAR,CACC,UAAU,eACV,GAAG,0BACH,aAAW,mBACb,GACF,EACC,SAAW,WAAa,IAAC,KAAE,KAAK,SAAS,mCAAkB,EAC3D,SAAW,SACV,IAAC,KAAE,KAAK,QAAQ,gDAAoC,EAErD,QACC,IAAC,QAAQ,YAAR,CAAoB,UAAU,qBAC5B,SAAAA,aAAY,IAAI,CAAC,MAAO,QACvB,IAAC,QAAQ,WAAR,CAEC,MACA,UAAU,gBAET,eAAM,OAJF,MAAM,EAKb,CACD,EACH,EAED,QACC,SAAW,SACX,OACAA,aAAY,SAAW,GAAK,IAAC,KAAE,kCAAsB,GACzD,EAEJ,EACA,KAAC,SAAM,UAAU,eAAe,kCAE9B,IAAC,YACC,UAAU,eACV,UAAW,IACX,MAAO,aACP,SAAW,OAAU,gBAAgB,MAAM,OAAO,KAAK,EACzD,GACF,EACC,UAAY,OAAO,KAAO,IAAC,OAAO,IAAP,CAAW,QAAS,SAAU,EACzD,aAAe,IAAC,KAAE,KAAK,QAAS,qBAAY,EAC5C,OAAS,IAAC,KAAE,KAAK,QAAS,eAAM,EACjC,IAAC,UACC,KAAK,SACL,UAAU,gBACV,SAAU,CAAC,UAAY,KACvB,QAAS,IAAM,CACb,KAAK,KAAK,CACZ,EAEC,cAAO,yBAAsB,eAChC,GACF,CAEJ,CACO,SAAS,cAAe,CAC7B,MAAM,KAAO,QAAQ,EACrB,OACE,IAAC,WACC,GAAG,UACH,MAAM,mBACN,QACE,KAAK,YAAY,OAAS,WACtB,iBACA,uBAGN,aAAC,cAAY,EACf,CAEJ",
|
|
6
6
|
"names": ["suggestions"]
|
|
7
7
|
}
|
package/dist/cart/cart-issues.js
CHANGED
|
@@ -1,72 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { Cart, useOverlay } from "@zappie/foundations";
|
|
3
|
-
import { useState } from "react";
|
|
4
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
-
var labels = {
|
|
6
|
-
remove_line: "Remove item",
|
|
7
|
-
accept_price: "Accept new price",
|
|
8
|
-
remove_promo: "Remove promo",
|
|
9
|
-
set_quantity: "Update quantity",
|
|
10
|
-
choose_option: "Choose options",
|
|
11
|
-
choose_other_option: "Change options",
|
|
12
|
-
change_address: "Change delivery address",
|
|
13
|
-
schedule: "Choose order time"
|
|
14
|
-
};
|
|
15
|
-
function Issue({
|
|
16
|
-
issue,
|
|
17
|
-
applyFix
|
|
18
|
-
}) {
|
|
19
|
-
const editor = useOverlay("cart_edit", issue.lineId ?? "");
|
|
20
|
-
const address = useOverlay("cart_sheet", "address");
|
|
21
|
-
const schedule = useOverlay("cart_sheet", "schedule");
|
|
22
|
-
const [error, setError] = useState(null);
|
|
23
|
-
const fix = (value) => {
|
|
24
|
-
setError(null);
|
|
25
|
-
try {
|
|
26
|
-
if (value.action === "choose_option" || value.action === "choose_other_option") {
|
|
27
|
-
editor.open();
|
|
28
|
-
} else if (value.action === "change_address") {
|
|
29
|
-
address.open();
|
|
30
|
-
} else if (value.action === "schedule") {
|
|
31
|
-
schedule.open();
|
|
32
|
-
} else {
|
|
33
|
-
applyFix(issue, value);
|
|
34
|
-
}
|
|
35
|
-
} catch (error2) {
|
|
36
|
-
setError(
|
|
37
|
-
error2 instanceof Error ? error2.message : "Unable to apply this change"
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
return /* @__PURE__ */ jsxs("li", { children: [
|
|
42
|
-
/* @__PURE__ */ jsx("p", { children: issue.message }),
|
|
43
|
-
issue.fixes.filter((value) => labels[value.action]).map((value, index) => /* @__PURE__ */ jsx(
|
|
44
|
-
"button",
|
|
45
|
-
{
|
|
46
|
-
type: "button",
|
|
47
|
-
className: "z-base-button-secondary",
|
|
48
|
-
onClick: () => fix(value),
|
|
49
|
-
children: value.action === "set_quantity" ? `Set quantity to ${value.quantity}` : labels[value.action]
|
|
50
|
-
},
|
|
51
|
-
index
|
|
52
|
-
)),
|
|
53
|
-
error && /* @__PURE__ */ jsx("p", { role: "alert", children: error })
|
|
54
|
-
] });
|
|
55
|
-
}
|
|
56
|
-
function CartIssues() {
|
|
57
|
-
return /* @__PURE__ */ jsx(Cart.Issues, { children: ({ issues, applyFix }) => issues.length > 0 && /* @__PURE__ */ jsxs("section", { className: "z-base-issues", "aria-label": "Cart issues", children: [
|
|
58
|
-
/* @__PURE__ */ jsx("h2", { children: "Review your cart" }),
|
|
59
|
-
/* @__PURE__ */ jsx("ul", { children: issues.map((issue, index) => /* @__PURE__ */ jsx(
|
|
60
|
-
Issue,
|
|
61
|
-
{
|
|
62
|
-
issue,
|
|
63
|
-
applyFix
|
|
64
|
-
},
|
|
65
|
-
`${issue.lineId}:${issue.code}:${index}`
|
|
66
|
-
)) })
|
|
67
|
-
] }) });
|
|
68
|
-
}
|
|
69
|
-
export {
|
|
70
|
-
CartIssues
|
|
71
|
-
};
|
|
1
|
+
import{Cart,useOverlay}from"@zappie/foundations";import{useState}from"react";import{jsx,jsxs}from"react/jsx-runtime";var labels={remove_line:"Remove item",accept_price:"Accept new price",remove_promo:"Remove promo",set_quantity:"Update quantity",choose_option:"Choose options",choose_other_option:"Change options",change_address:"Change delivery address",schedule:"Choose order time"};function Issue({issue,applyFix}){const editor=useOverlay("cart_edit",issue.lineId??"");const address=useOverlay("cart_sheet","address");const schedule=useOverlay("cart_sheet","schedule");const[error,setError]=useState(null);const fix=value=>{setError(null);try{if(value.action==="choose_option"||value.action==="choose_other_option"){editor.open()}else if(value.action==="change_address"){address.open()}else if(value.action==="schedule"){schedule.open()}else{applyFix(issue,value)}}catch(error2){setError(error2 instanceof Error?error2.message:"Unable to apply this change")}};return jsxs("li",{children:[jsx("p",{children:issue.message}),issue.fixes.filter(value=>labels[value.action]).map((value,index)=>jsx("button",{type:"button",className:"z-base-button-secondary",onClick:()=>fix(value),children:value.action==="set_quantity"?`Set quantity to ${value.quantity}`:labels[value.action]},index)),error&&jsx("p",{role:"alert",children:error})]})}function CartIssues(){return jsx(Cart.Issues,{children:({issues,applyFix})=>issues.length>0&&jsxs("section",{className:"z-base-issues","aria-label":"Cart issues",children:[jsx("h2",{children:"Review your cart"}),jsx("ul",{children:issues.map((issue,index)=>jsx(Issue,{issue,applyFix},`${issue.lineId}:${issue.code}:${index}`))})]})})}export{CartIssues};
|
|
72
2
|
//# sourceMappingURL=cart-issues.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/cart/cart-issues.tsx"],
|
|
4
4
|
"sourcesContent": ["import { Cart, useOverlay } from \"@zappie/foundations\";\nimport type { CartFix, CartIssue } from \"@zappie/sdk\";\nimport { useState } from \"react\";\nconst labels: Partial<Record<CartFix[\"action\"], string>> = {\n remove_line: \"Remove item\",\n accept_price: \"Accept new price\",\n remove_promo: \"Remove promo\",\n set_quantity: \"Update quantity\",\n choose_option: \"Choose options\",\n choose_other_option: \"Change options\",\n change_address: \"Change delivery address\",\n schedule: \"Choose order time\",\n};\nfunction Issue({\n issue,\n applyFix,\n}: {\n issue: CartIssue;\n applyFix: (issue: CartIssue, fix: CartFix) => void;\n}) {\n const editor = useOverlay(\"cart_edit\", issue.lineId ?? \"\");\n const address = useOverlay(\"cart_sheet\", \"address\");\n const schedule = useOverlay(\"cart_sheet\", \"schedule\");\n const [error, setError] = useState<string | null>(null);\n const fix = (value: CartFix) => {\n setError(null);\n try {\n if (\n value.action === \"choose_option\" ||\n value.action === \"choose_other_option\"\n ) {\n editor.open();\n } else if (value.action === \"change_address\") {\n address.open();\n } else if (value.action === \"schedule\") {\n schedule.open();\n } else {\n applyFix(issue, value);\n }\n } catch (error) {\n setError(\n error instanceof Error ? error.message : \"Unable to apply this change\",\n );\n }\n };\n return (\n <li>\n <p>{issue.message}</p>\n {issue.fixes\n .filter((value) => labels[value.action])\n .map((value, index) => (\n <button\n key={index}\n type=\"button\"\n className=\"z-base-button-secondary\"\n onClick={() => fix(value)}\n >\n {value.action === \"set_quantity\"\n ? `Set quantity to ${value.quantity}`\n : labels[value.action]}\n </button>\n ))}\n {error && <p role=\"alert\">{error}</p>}\n </li>\n );\n}\nexport function CartIssues() {\n return (\n <Cart.Issues>\n {({ issues, applyFix }) =>\n issues.length > 0 && (\n <section className=\"z-base-issues\" aria-label=\"Cart issues\">\n <h2>Review your cart</h2>\n <ul>\n {issues.map((issue, index) => (\n <Issue\n key={`${issue.lineId}:${issue.code}:${index}`}\n issue={issue}\n applyFix={applyFix}\n />\n ))}\n </ul>\n </section>\n )\n }\n </Cart.Issues>\n );\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": "AAAA,OAAS,KAAM,eAAkB,sBAEjC,OAAS,aAAgB,QA4CrB,OACE,IADF,6BA3CJ,IAAM,OAAqD,CACzD,YAAa,cACb,aAAc,mBACd,aAAc,eACd,aAAc,kBACd,cAAe,iBACf,oBAAqB,iBACrB,eAAgB,0BAChB,SAAU,mBACZ,EACA,SAAS,MAAM,CACb,MACA,QACF,EAGG,CACD,MAAM,OAAS,WAAW,YAAa,MAAM,QAAU,EAAE,EACzD,MAAM,QAAU,WAAW,aAAc,SAAS,EAClD,MAAM,SAAW,WAAW,aAAc,UAAU,EACpD,KAAM,CAAC,MAAO,QAAQ,EAAI,SAAwB,IAAI,EACtD,MAAM,IAAO,OAAmB,CAC9B,SAAS,IAAI,EACb,GAAI,CACF,GACE,MAAM,SAAW,iBACjB,MAAM,SAAW,sBACjB,CACA,OAAO,KAAK,CACd,SAAW,MAAM,SAAW,iBAAkB,CAC5C,QAAQ,KAAK,CACf,SAAW,MAAM,SAAW,WAAY,CACtC,SAAS,KAAK,CAChB,KAAO,CACL,SAAS,MAAO,KAAK,CACvB,CACF,OAASA,OAAO,CACd,SACEA,kBAAiB,MAAQA,OAAM,QAAU,6BAC3C,CACF,CACF,EACA,OACE,KAAC,MACC,cAAC,KAAG,eAAM,QAAQ,EACjB,MAAM,MACJ,OAAQ,OAAU,OAAO,MAAM,MAAM,CAAC,EACtC,IAAI,CAAC,MAAO,QACX,IAAC,UAEC,KAAK,SACL,UAAU,0BACV,QAAS,IAAM,IAAI,KAAK,EAEvB,eAAM,SAAW,eACd,mBAAmB,MAAM,QAAQ,GACjC,OAAO,MAAM,MAAM,GAPlB,KAQP,CACD,EACF,OAAS,IAAC,KAAE,KAAK,QAAS,eAAM,GACnC,CAEJ,CACO,SAAS,YAAa,CAC3B,OACE,IAAC,KAAK,OAAL,CACE,UAAC,CAAE,OAAQ,QAAS,IACnB,OAAO,OAAS,GACd,KAAC,WAAQ,UAAU,gBAAgB,aAAW,cAC5C,cAAC,MAAG,4BAAgB,EACpB,IAAC,MACE,gBAAO,IAAI,CAAC,MAAO,QAClB,IAAC,OAEC,MACA,UAFK,GAAG,MAAM,MAAM,IAAI,MAAM,IAAI,IAAI,KAAK,EAG7C,CACD,EACH,GACF,EAGN,CAEJ",
|
|
6
6
|
"names": ["error"]
|
|
7
7
|
}
|
|
@@ -1,34 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
function groupCartLinesByMenu(lines, catalogue) {
|
|
3
|
-
const names = new Map(
|
|
4
|
-
(catalogue?.menus ?? []).map((menu) => [menu.id, menu.name])
|
|
5
|
-
);
|
|
6
|
-
const groups = /* @__PURE__ */ new Map();
|
|
7
|
-
for (const line of lines) {
|
|
8
|
-
const menuId = line.menuId ?? "unknown";
|
|
9
|
-
const group = groups.get(menuId);
|
|
10
|
-
if (group) {
|
|
11
|
-
group.lines.push(line);
|
|
12
|
-
continue;
|
|
13
|
-
}
|
|
14
|
-
const menuName = names.get(menuId);
|
|
15
|
-
groups.set(menuId, {
|
|
16
|
-
menuId,
|
|
17
|
-
...menuName !== void 0 ? { menuName } : {},
|
|
18
|
-
lines: [line]
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
const ordered = [];
|
|
22
|
-
for (const menu of catalogue?.menus ?? []) {
|
|
23
|
-
const group = groups.get(menu.id);
|
|
24
|
-
if (group) {
|
|
25
|
-
ordered.push(group);
|
|
26
|
-
groups.delete(menu.id);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return [...ordered, ...groups.values()];
|
|
30
|
-
}
|
|
31
|
-
export {
|
|
32
|
-
groupCartLinesByMenu
|
|
33
|
-
};
|
|
1
|
+
function groupCartLinesByMenu(lines,catalogue){const names=new Map((catalogue?.menus??[]).map(menu=>[menu.id,menu.name]));const groups=new Map;for(const line of lines){const menuId=line.menuId??"unknown";const group=groups.get(menuId);if(group){group.lines.push(line);continue}const menuName=names.get(menuId);groups.set(menuId,{menuId,...menuName!==void 0?{menuName}:{},lines:[line]})}const ordered=[];for(const menu of catalogue?.menus??[]){const group=groups.get(menu.id);if(group){ordered.push(group);groups.delete(menu.id)}}return[...ordered,...groups.values()]}export{groupCartLinesByMenu};
|
|
34
2
|
//# sourceMappingURL=cart-line-groups.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/cart/cart-line-groups.ts"],
|
|
4
4
|
"sourcesContent": ["import type { CartLine, Menu } from \"@zappie/sdk\";\n\nexport type CartLineGroup = {\n menuId: string;\n menuName?: string;\n lines: CartLine[];\n};\n\nexport function groupCartLinesByMenu(\n lines: readonly CartLine[],\n catalogue?: Menu,\n): CartLineGroup[] {\n const names = new Map(\n (catalogue?.menus ?? []).map((menu) => [menu.id, menu.name]),\n );\n const groups = new Map<string, CartLineGroup>();\n for (const line of lines) {\n const menuId = line.menuId ?? \"unknown\";\n const group = groups.get(menuId);\n if (group) {\n group.lines.push(line);\n continue;\n }\n const menuName = names.get(menuId);\n groups.set(menuId, {\n menuId,\n ...(menuName !== undefined ? { menuName } : {}),\n lines: [line],\n });\n }\n const ordered: CartLineGroup[] = [];\n for (const menu of catalogue?.menus ?? []) {\n const group = groups.get(menu.id);\n if (group) {\n ordered.push(group);\n groups.delete(menu.id);\n }\n }\n return [...ordered, ...groups.values()];\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": "AAQO,SAAS,qBACd,MACA,UACiB,CACjB,MAAM,MAAQ,IAAI,KACf,WAAW,OAAS,CAAC,GAAG,IAAK,MAAS,CAAC,KAAK,GAAI,KAAK,IAAI,CAAC,CAC7D,EACA,MAAM,OAAS,IAAI,IACnB,UAAW,QAAQ,MAAO,CACxB,MAAM,OAAS,KAAK,QAAU,UAC9B,MAAM,MAAQ,OAAO,IAAI,MAAM,EAC/B,GAAI,MAAO,CACT,MAAM,MAAM,KAAK,IAAI,EACrB,QACF,CACA,MAAM,SAAW,MAAM,IAAI,MAAM,EACjC,OAAO,IAAI,OAAQ,CACjB,OACA,GAAI,WAAa,OAAY,CAAE,QAAS,EAAI,CAAC,EAC7C,MAAO,CAAC,IAAI,CACd,CAAC,CACH,CACA,MAAM,QAA2B,CAAC,EAClC,UAAW,QAAQ,WAAW,OAAS,CAAC,EAAG,CACzC,MAAM,MAAQ,OAAO,IAAI,KAAK,EAAE,EAChC,GAAI,MAAO,CACT,QAAQ,KAAK,KAAK,EAClB,OAAO,OAAO,KAAK,EAAE,CACvB,CACF,CACA,MAAO,CAAC,GAAG,QAAS,GAAG,OAAO,OAAO,CAAC,CACxC",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cart/cart-line.js
CHANGED
|
@@ -1,85 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { Cart, Money, Overlay, Quantity } from "@zappie/foundations";
|
|
3
|
-
import { useCart } from "@zappie/sdk/react";
|
|
4
|
-
import { LineEditor } from "./line-editor.js";
|
|
5
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
function CartLine({ line }) {
|
|
7
|
-
const cart = useCart();
|
|
8
|
-
const invalid = cart.issues.some(
|
|
9
|
-
(issue) => issue.lineId === line.id && issue.severity === "blocking"
|
|
10
|
-
);
|
|
11
|
-
return /* @__PURE__ */ jsx(Cart.Line, { line, className: "z-base-line", children: ({ item }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
12
|
-
/* @__PURE__ */ jsxs("div", { className: "z-base-line-heading", children: [
|
|
13
|
-
/* @__PURE__ */ jsx("h3", { children: line.name }),
|
|
14
|
-
item && !invalid ? /* @__PURE__ */ jsx(Money, { value: line.lineSubtotal }) : /* @__PURE__ */ jsx("span", { children: "Price unavailable" })
|
|
15
|
-
] }),
|
|
16
|
-
/* @__PURE__ */ jsxs("ul", { className: "z-base-line-options", children: [
|
|
17
|
-
line.choices.map((selection) => {
|
|
18
|
-
const group = item?.optionGroups.find(
|
|
19
|
-
(group2) => group2.id === selection.groupId
|
|
20
|
-
);
|
|
21
|
-
const choice = group?.choices.find(
|
|
22
|
-
(choice2) => choice2.id === selection.choiceId
|
|
23
|
-
);
|
|
24
|
-
return /* @__PURE__ */ jsxs("li", { children: [
|
|
25
|
-
choice?.name ?? "Unavailable option",
|
|
26
|
-
selection.quantity > 1 ? ` \xD7 ${selection.quantity}` : ""
|
|
27
|
-
] }, `${selection.groupId}:${selection.choiceId}`);
|
|
28
|
-
}),
|
|
29
|
-
Object.entries(line.inputs).map(([id, value]) => /* @__PURE__ */ jsxs("li", { children: [
|
|
30
|
-
item?.optionGroups.find((group) => group.id === id)?.name ?? "Details",
|
|
31
|
-
": ",
|
|
32
|
-
value
|
|
33
|
-
] }, id))
|
|
34
|
-
] }),
|
|
35
|
-
line.note && /* @__PURE__ */ jsx("p", { className: "z-base-muted", children: line.note }),
|
|
36
|
-
/* @__PURE__ */ jsxs("div", { className: "z-base-line-actions", children: [
|
|
37
|
-
/* @__PURE__ */ jsxs(
|
|
38
|
-
Cart.Quantity,
|
|
39
|
-
{
|
|
40
|
-
lineId: line.id,
|
|
41
|
-
disabled: invalid,
|
|
42
|
-
className: "z-base-quantity",
|
|
43
|
-
children: [
|
|
44
|
-
/* @__PURE__ */ jsx(Quantity.Decrement, { "aria-label": `Decrease ${line.name} quantity`, children: "\u2212" }),
|
|
45
|
-
/* @__PURE__ */ jsx(Quantity.Value, { "aria-label": `${line.name} quantity` }),
|
|
46
|
-
/* @__PURE__ */ jsx(Quantity.Increment, { "aria-label": `Increase ${line.name} quantity`, children: "+" })
|
|
47
|
-
]
|
|
48
|
-
}
|
|
49
|
-
),
|
|
50
|
-
/* @__PURE__ */ jsxs(
|
|
51
|
-
Overlay.Root,
|
|
52
|
-
{
|
|
53
|
-
param: "cart_edit",
|
|
54
|
-
id: line.id,
|
|
55
|
-
presentation: { base: "sheet", lg: "dialog" },
|
|
56
|
-
children: [
|
|
57
|
-
/* @__PURE__ */ jsx(
|
|
58
|
-
Overlay.Trigger,
|
|
59
|
-
{
|
|
60
|
-
className: "z-base-button-secondary",
|
|
61
|
-
disabled: !item,
|
|
62
|
-
"aria-label": `Edit ${line.name}`,
|
|
63
|
-
children: "Edit"
|
|
64
|
-
}
|
|
65
|
-
),
|
|
66
|
-
item && /* @__PURE__ */ jsx(LineEditor, { line, item })
|
|
67
|
-
]
|
|
68
|
-
}
|
|
69
|
-
),
|
|
70
|
-
/* @__PURE__ */ jsx(
|
|
71
|
-
Cart.Remove,
|
|
72
|
-
{
|
|
73
|
-
lineId: line.id,
|
|
74
|
-
className: "z-base-button-secondary",
|
|
75
|
-
"aria-label": `Remove ${line.name}`,
|
|
76
|
-
children: "Remove"
|
|
77
|
-
}
|
|
78
|
-
)
|
|
79
|
-
] })
|
|
80
|
-
] }) });
|
|
81
|
-
}
|
|
82
|
-
export {
|
|
83
|
-
CartLine
|
|
84
|
-
};
|
|
1
|
+
import{Cart,Money,Overlay,Quantity}from"@zappie/foundations";import{useCart}from"@zappie/sdk/react";import{LineEditor}from"./line-editor.js";import{Fragment,jsx,jsxs}from"react/jsx-runtime";function CartLine({line}){const cart=useCart();const invalid=cart.issues.some(issue=>issue.lineId===line.id&&issue.severity==="blocking");return jsx(Cart.Line,{line,className:"z-base-line",children:({item})=>jsxs(Fragment,{children:[jsxs("div",{className:"z-base-line-heading",children:[jsx("h3",{children:line.name}),item&&!invalid?jsx(Money,{value:line.lineSubtotal}):jsx("span",{children:"Price unavailable"})]}),jsxs("ul",{className:"z-base-line-options",children:[line.choices.map(selection=>{const group=item?.optionGroups.find(group2=>group2.id===selection.groupId);const choice=group?.choices.find(choice2=>choice2.id===selection.choiceId);return jsxs("li",{children:[choice?.name??"Unavailable option",selection.quantity>1?` \xD7 ${selection.quantity}`:""]},`${selection.groupId}:${selection.choiceId}`)}),Object.entries(line.inputs).map(([id,value])=>jsxs("li",{children:[item?.optionGroups.find(group=>group.id===id)?.name??"Details",": ",value]},id))]}),line.note&&jsx("p",{className:"z-base-muted",children:line.note}),jsxs("div",{className:"z-base-line-actions",children:[jsxs(Cart.Quantity,{lineId:line.id,disabled:invalid,className:"z-base-quantity",children:[jsx(Quantity.Decrement,{"aria-label":`Decrease ${line.name} quantity`,children:"\u2212"}),jsx(Quantity.Value,{"aria-label":`${line.name} quantity`}),jsx(Quantity.Increment,{"aria-label":`Increase ${line.name} quantity`,children:"+"})]}),jsxs(Overlay.Root,{param:"cart_edit",id:line.id,presentation:{base:"sheet",lg:"dialog"},children:[jsx(Overlay.Trigger,{className:"z-base-button-secondary",disabled:!item,"aria-label":`Edit ${line.name}`,children:"Edit"}),item&&jsx(LineEditor,{line,item})]}),jsx(Cart.Remove,{lineId:line.id,className:"z-base-button-secondary","aria-label":`Remove ${line.name}`,children:"Remove"})]})]})})}export{CartLine};
|
|
85
2
|
//# sourceMappingURL=cart-line.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/cart/cart-line.tsx"],
|
|
4
4
|
"sourcesContent": ["import { Cart, Money, Overlay, Quantity } from \"@zappie/foundations\";\nimport type { CartLine as Line } from \"@zappie/sdk\";\nimport { useCart } from \"@zappie/sdk/react\";\nimport { LineEditor } from \"./line-editor\";\nexport function CartLine({ line }: { line: Line }) {\n const cart = useCart();\n const invalid = cart.issues.some(\n (issue) => issue.lineId === line.id && issue.severity === \"blocking\",\n );\n return (\n <Cart.Line line={line} className=\"z-base-line\">\n {({ item }) => (\n <>\n <div className=\"z-base-line-heading\">\n <h3>{line.name}</h3>\n {item && !invalid ? (\n <Money value={line.lineSubtotal} />\n ) : (\n <span>Price unavailable</span>\n )}\n </div>\n <ul className=\"z-base-line-options\">\n {line.choices.map((selection) => {\n const group = item?.optionGroups.find(\n (group) => group.id === selection.groupId,\n );\n const choice = group?.choices.find(\n (choice) => choice.id === selection.choiceId,\n );\n return (\n <li key={`${selection.groupId}:${selection.choiceId}`}>\n {choice?.name ?? \"Unavailable option\"}\n {selection.quantity > 1 ? ` \u00D7 ${selection.quantity}` : \"\"}\n </li>\n );\n })}\n {Object.entries(line.inputs).map(([id, value]) => (\n <li key={id}>\n {item?.optionGroups.find((group) => group.id === id)?.name ??\n \"Details\"}\n : {value}\n </li>\n ))}\n </ul>\n {line.note && <p className=\"z-base-muted\">{line.note}</p>}\n <div className=\"z-base-line-actions\">\n <Cart.Quantity\n lineId={line.id}\n disabled={invalid}\n className=\"z-base-quantity\"\n >\n <Quantity.Decrement aria-label={`Decrease ${line.name} quantity`}>\n \u2212\n </Quantity.Decrement>\n <Quantity.Value aria-label={`${line.name} quantity`} />\n <Quantity.Increment aria-label={`Increase ${line.name} quantity`}>\n +\n </Quantity.Increment>\n </Cart.Quantity>\n <Overlay.Root\n param=\"cart_edit\"\n id={line.id}\n presentation={{ base: \"sheet\", lg: \"dialog\" }}\n >\n <Overlay.Trigger\n className=\"z-base-button-secondary\"\n disabled={!item}\n aria-label={`Edit ${line.name}`}\n >\n Edit\n </Overlay.Trigger>\n {item && <LineEditor line={line} item={item} />}\n </Overlay.Root>\n <Cart.Remove\n lineId={line.id}\n className=\"z-base-button-secondary\"\n aria-label={`Remove ${line.name}`}\n >\n Remove\n </Cart.Remove>\n </div>\n </>\n )}\n </Cart.Line>\n );\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": "AAAA,OAAS,KAAM,MAAO,QAAS,aAAgB,sBAE/C,OAAS,YAAe,oBACxB,OAAS,eAAkB,mBASnB,gBAEI,IADF,SADF,oBARD,SAAS,SAAS,CAAE,IAAK,EAAmB,CACjD,MAAM,KAAO,QAAQ,EACrB,MAAM,QAAU,KAAK,OAAO,KACzB,OAAU,MAAM,SAAW,KAAK,IAAM,MAAM,WAAa,UAC5D,EACA,OACE,IAAC,KAAK,KAAL,CAAU,KAAY,UAAU,cAC9B,UAAC,CAAE,IAAK,IACP,eACE,eAAC,OAAI,UAAU,sBACb,cAAC,MAAI,cAAK,KAAK,EACd,MAAQ,CAAC,QACR,IAAC,OAAM,MAAO,KAAK,aAAc,EAEjC,IAAC,QAAK,6BAAiB,GAE3B,EACA,KAAC,MAAG,UAAU,sBACX,eAAK,QAAQ,IAAK,WAAc,CAC/B,MAAM,MAAQ,MAAM,aAAa,KAC9BA,QAAUA,OAAM,KAAO,UAAU,OACpC,EACA,MAAM,OAAS,OAAO,QAAQ,KAC3BC,SAAWA,QAAO,KAAO,UAAU,QACtC,EACA,OACE,KAAC,MACE,kBAAQ,MAAQ,qBAChB,UAAU,SAAW,EAAI,SAAM,UAAU,QAAQ,GAAK,KAFhD,GAAG,UAAU,OAAO,IAAI,UAAU,QAAQ,EAGnD,CAEJ,CAAC,EACA,OAAO,QAAQ,KAAK,MAAM,EAAE,IAAI,CAAC,CAAC,GAAI,KAAK,IAC1C,KAAC,MACE,gBAAM,aAAa,KAAM,OAAU,MAAM,KAAO,EAAE,GAAG,MACpD,UAAU,KACT,QAHI,EAIT,CACD,GACH,EACC,KAAK,MAAQ,IAAC,KAAE,UAAU,eAAgB,cAAK,KAAK,EACrD,KAAC,OAAI,UAAU,sBACb,eAAC,KAAK,SAAL,CACC,OAAQ,KAAK,GACb,SAAU,QACV,UAAU,kBAEV,cAAC,SAAS,UAAT,CAAmB,aAAY,YAAY,KAAK,IAAI,YAAa,kBAElE,EACA,IAAC,SAAS,MAAT,CAAe,aAAY,GAAG,KAAK,IAAI,YAAa,EACrD,IAAC,SAAS,UAAT,CAAmB,aAAY,YAAY,KAAK,IAAI,YAAa,aAElE,GACF,EACA,KAAC,QAAQ,KAAR,CACC,MAAM,YACN,GAAI,KAAK,GACT,aAAc,CAAE,KAAM,QAAS,GAAI,QAAS,EAE5C,cAAC,QAAQ,QAAR,CACC,UAAU,0BACV,SAAU,CAAC,KACX,aAAY,QAAQ,KAAK,IAAI,GAC9B,gBAED,EACC,MAAQ,IAAC,YAAW,KAAY,KAAY,GAC/C,EACA,IAAC,KAAK,OAAL,CACC,OAAQ,KAAK,GACb,UAAU,0BACV,aAAY,UAAU,KAAK,IAAI,GAChC,kBAED,GACF,GACF,EAEJ,CAEJ",
|
|
6
6
|
"names": ["group", "choice"]
|
|
7
7
|
}
|