@zappie/foundations 0.9.1 → 0.9.3
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 +27 -0
- package/README.md +110 -5
- package/dist/account/index.js +3 -3
- package/dist/account/index.js.map +1 -1
- package/dist/account/zappie-account.js +1 -1
- package/dist/account/zappie-account.js.map +1 -1
- package/dist/branch-map/fit.js +3 -18
- package/dist/branch-map/fit.js.map +1 -1
- package/dist/branch-map/geometry.js +6 -8
- package/dist/branch-map/geometry.js.map +1 -1
- package/dist/branch-switch/index.d.ts +168 -0
- package/dist/branch-switch/index.js +126 -0
- package/dist/branch-switch/index.js.map +6 -0
- package/dist/cart/index.js +61 -63
- package/dist/cart/index.js.map +1 -1
- package/dist/fulfilment/address-picker.js +17 -19
- package/dist/fulfilment/address-picker.js.map +1 -1
- package/dist/fulfilment/branch-picker.js +1 -1
- package/dist/fulfilment/branch-picker.js.map +1 -1
- package/dist/fulfilment/schedule.js +1 -1
- package/dist/fulfilment/schedule.js.map +1 -1
- package/dist/fulfilment/switch.js +1 -1
- package/dist/fulfilment/switch.js.map +1 -1
- package/dist/index-B1NMxq0i.d.ts +91 -0
- package/dist/index.d.ts +76 -104
- package/dist/internal/slot.js +1 -1
- package/dist/internal/slot.js.map +1 -1
- package/dist/item-form/index.js +2 -0
- package/dist/item-form/index.js.map +1 -1
- package/dist/item-form/option-group.js +132 -90
- package/dist/item-form/option-group.js.map +1 -1
- package/dist/item-form/options.js +56 -21
- package/dist/item-form/options.js.map +2 -2
- package/dist/item-form/quantity.js +2 -2
- package/dist/item-form/quantity.js.map +1 -1
- package/dist/item-form/root.js +38 -24
- package/dist/item-form/root.js.map +2 -2
- package/dist/money.js +1 -1
- package/dist/money.js.map +1 -1
- package/dist/otp/input.js +1 -1
- package/dist/otp/input.js.map +1 -1
- package/dist/overlay/engine.js +31 -35
- package/dist/overlay/engine.js.map +1 -1
- package/dist/overlay/react.js +120 -117
- package/dist/overlay/react.js.map +1 -1
- package/dist/payment/methods.js +2 -2
- package/dist/payment/methods.js.map +1 -1
- package/dist/search/index.js +4 -4
- package/dist/search/index.js.map +1 -1
- package/dist/status/open-status.js +1 -1
- package/dist/status/open-status.js.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +6 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @zappie/foundations
|
|
2
2
|
|
|
3
|
+
## 0.9.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ad0e714: New `@zappie/foundations/branch-switch` entry for React Router sites. `createBranchSwitchLoader({ shopAt })` gives the root route a `clientLoader` that reads only the chosen branch's menu in the browser when a link names another branch of the store already loaded, and a `shouldRevalidate` that reloads the shop only for another branch. `useBranchIntent(branch)` starts the menu read on pointer, touch and focus. `useChooseBranch(then)` moves a bag with lines to the branch before `then` navigates. `useReloadingBranch(shop, { location, navigation })` names the branch the shop is reloading for, so you can show your own skeleton. `reloadsShop`, `branchNamed` and `loadedBranchOf` are exported too.
|
|
8
|
+
- Updated dependencies [ad0e714]
|
|
9
|
+
- @zappie/sdk@0.10.3
|
|
10
|
+
|
|
11
|
+
## 0.9.2
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- f54c5a9: `OptionGroup` and `Choice` now hold a selection to the group's limit. Picking a choice in a full group does nothing, and its unchosen choices get `aria-disabled="true"` and `data-limit-reached` but stay focusable, with a visible "Limit reached. Remove one to choose another." hint at the end of the group. Pass `limitHint={false}` to place the hint yourself, or a string to change it. Quantity changes are capped by the room left in the group.
|
|
16
|
+
|
|
17
|
+
Only a required group of exactly one uses radios. An optional group of one now uses checkboxes, so ticking another choice swaps it and unticking leaves none. Choices carry `data-control="radio"` or `"checkbox"` for styling.
|
|
18
|
+
|
|
19
|
+
The group's render state adds `control`, `count`, `room`, `atLimit` and `limitHint`. Show a live count with `countLabel(group, count)` and a group's error with `boundMessage(group, count)` from `@zappie/sdk/options`.
|
|
20
|
+
|
|
21
|
+
New `ItemNote`, a textarea bound to the line's note and limited to 280 characters, the same limit the cart checks. Place it inside `ItemForm.Root`. `ItemForm.Root` takes `branchRequired` and `onBranchRequired`, so Add can ask the shopper for a branch first instead of adding.
|
|
22
|
+
|
|
23
|
+
Unused parts now drop out of an app's bundle. Every part is marked as free of side effects, so a bundler leaves out the ones a page never renders, such as `ItemNote` on a page without a note.
|
|
24
|
+
|
|
25
|
+
- 5047cb4: `BranchMap` now finds the nearest branch with `nearestBranch` from `@zappie/sdk/branches`, so the map and your site use the same distance rule.
|
|
26
|
+
- Updated dependencies [5047cb4]
|
|
27
|
+
- Updated dependencies [fbcbb2d]
|
|
28
|
+
- @zappie/sdk@0.10.1
|
|
29
|
+
|
|
3
30
|
## 0.9.1
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -31,11 +31,12 @@ Want ready-made, styled components instead? Copy them into your project from the
|
|
|
31
31
|
|
|
32
32
|
## Entry points
|
|
33
33
|
|
|
34
|
-
| Import
|
|
35
|
-
|
|
|
36
|
-
| `@zappie/foundations`
|
|
37
|
-
| `@zappie/foundations/next`
|
|
38
|
-
| `@zappie/foundations/
|
|
34
|
+
| Import | For |
|
|
35
|
+
| ----------------------------------- | ----------------------------------------------------------------------- |
|
|
36
|
+
| `@zappie/foundations` | Every part |
|
|
37
|
+
| `@zappie/foundations/next` | Keeping overlays in step with Back and Forward in a Next.js app |
|
|
38
|
+
| `@zappie/foundations/branch-switch` | Choosing a branch in a React Router site without waiting for the server |
|
|
39
|
+
| `@zappie/foundations/rich-text` | Sanitising and parsing merchant rich text before you render it |
|
|
39
40
|
|
|
40
41
|
## Docs
|
|
41
42
|
|
|
@@ -110,6 +111,110 @@ then the panel is hidden from assistive technology and takes no keys, presses or
|
|
|
110
111
|
scrolls, apart from Escape and an outside press, which close it. Style the panel
|
|
111
112
|
and `[data-zappie-backdrop]` as usual: both frames match them.
|
|
112
113
|
|
|
114
|
+
## Branch switch
|
|
115
|
+
|
|
116
|
+
Choosing a branch shows that branch's menu without waiting for the server. A
|
|
117
|
+
link to another branch of the store already loaded reads only that branch's
|
|
118
|
+
menu in the browser, and the read starts when the shopper reaches for the
|
|
119
|
+
button. It has its own entry, `@zappie/foundations/branch-switch`, so pages
|
|
120
|
+
that don't use it never load it. Use it in a React Router root route:
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
import {
|
|
124
|
+
createBranchSwitchLoader,
|
|
125
|
+
useReloadingBranch,
|
|
126
|
+
} from "@zappie/foundations";
|
|
127
|
+
|
|
128
|
+
const branchSwitch = createBranchSwitchLoader<ShopData>({
|
|
129
|
+
// What your loader returns for ?branch=<that branch>. Recompute every field
|
|
130
|
+
// that depends on the branch.
|
|
131
|
+
shopAt: (shop, branch, menu) => ({
|
|
132
|
+
...shop,
|
|
133
|
+
config: { ...shop.config, branch: branch.id },
|
|
134
|
+
branch,
|
|
135
|
+
menu,
|
|
136
|
+
branchChosen: true,
|
|
137
|
+
mustChoose: false,
|
|
138
|
+
}),
|
|
139
|
+
// Paths your loader redirects go to the server.
|
|
140
|
+
serverOnly: (url, shop) => Boolean(redirectFor(shop.store, url.pathname)),
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
export const shouldRevalidate: ShouldRevalidateFunction = (args) =>
|
|
144
|
+
branchSwitch.shouldRevalidate(args);
|
|
145
|
+
export const clientLoader = (args: Route.ClientLoaderArgs) =>
|
|
146
|
+
branchSwitch.clientLoader(args);
|
|
147
|
+
|
|
148
|
+
export default function App() {
|
|
149
|
+
const shop = useLoaderData<typeof loader>();
|
|
150
|
+
const client = useMemo(() => createZappie(shop.config), [shop.config.branch]);
|
|
151
|
+
branchSwitch.remember(shop, client);
|
|
152
|
+
return <ZappieProvider client={client}>…</ZappieProvider>;
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
- `createBranchSwitchLoader({ shopAt, serverOnly?, param? })` returns
|
|
157
|
+
`remember`, `shouldRevalidate` and `clientLoader`. Your loader data needs
|
|
158
|
+
`store`, `branch` and, when the shopper chooses a branch, `branchChosen`.
|
|
159
|
+
Without `branchChosen` the loaded branch counts as chosen.
|
|
160
|
+
- `clientLoader` builds the shop with `shopAt` from the shop the root last
|
|
161
|
+
rendered. An unknown branch, a `serverOnly` URL or a failed read calls
|
|
162
|
+
`serverLoader()`. A cancelled navigation throws.
|
|
163
|
+
- `shouldRevalidate` reloads the shop only for a link that names another
|
|
164
|
+
branch. A link without `?branch=` keeps the branch, and so does a link to the
|
|
165
|
+
branch already loaded and chosen. Form submissions keep React Router's rule.
|
|
166
|
+
- `reloadsShop`, `branchNamed` and `loadedBranchOf` are the rules behind them,
|
|
167
|
+
for your own code.
|
|
168
|
+
|
|
169
|
+
Read the menu on intent, and move the bag before you navigate:
|
|
170
|
+
|
|
171
|
+
```tsx
|
|
172
|
+
import {
|
|
173
|
+
useBranchIntent,
|
|
174
|
+
useChooseBranch,
|
|
175
|
+
} from "@zappie/foundations/branch-switch";
|
|
176
|
+
|
|
177
|
+
function BranchCard({ branch }: { branch: Branch }) {
|
|
178
|
+
const intent = useBranchIntent(branch);
|
|
179
|
+
const navigate = useNavigate();
|
|
180
|
+
const choose = useChooseBranch((next) => {
|
|
181
|
+
rememberBranch(next.id);
|
|
182
|
+
navigate(`/menu?branch=${next.slug}`);
|
|
183
|
+
});
|
|
184
|
+
return (
|
|
185
|
+
<button type="button" {...intent} onClick={() => void choose(branch)}>
|
|
186
|
+
Order from {branch.name}
|
|
187
|
+
</button>
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
- `useBranchIntent(branch)` returns `{ onPointerEnter, onPointerDown, onFocus }`.
|
|
193
|
+
Each starts the branch's menu read. The client shares one read per branch,
|
|
194
|
+
so the click and the loader reuse it.
|
|
195
|
+
- `useChooseBranch(then)` starts the menu read, moves a bag with lines to the
|
|
196
|
+
branch, and calls `then` once the move is done. Remember the choice and
|
|
197
|
+
navigate in `then`. Keep the branch ID in your cookie: the server then reads
|
|
198
|
+
the store and the menu at once (`loadStoreAndMenu` in `@zappie/sdk/server`).
|
|
199
|
+
|
|
200
|
+
Show your own skeleton while the shop reloads for a branch:
|
|
201
|
+
|
|
202
|
+
```tsx
|
|
203
|
+
const reloading = useReloadingBranch(shop, {
|
|
204
|
+
location: useLocation(),
|
|
205
|
+
navigation: useNavigation(),
|
|
206
|
+
});
|
|
207
|
+
return reloading?.pathname === "/menu" ? (
|
|
208
|
+
<MenuSkeleton branch={reloading.branch} />
|
|
209
|
+
) : (
|
|
210
|
+
<Outlet />
|
|
211
|
+
);
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
`useReloadingBranch(shop, { location, navigation }, param?)` returns
|
|
215
|
+
`{ branch, pathname }` while a navigation reloads the shop for a branch the
|
|
216
|
+
store has, and undefined otherwise.
|
|
217
|
+
|
|
113
218
|
## Item form focus
|
|
114
219
|
|
|
115
220
|
When an add fails validation, `ItemForm.Root` focuses the first invalid group
|
package/dist/account/index.js
CHANGED
|
@@ -14,7 +14,7 @@ async function signIn(_options) {
|
|
|
14
14
|
async function signOut(_options) {
|
|
15
15
|
throw new AccountNotConfiguredError();
|
|
16
16
|
}
|
|
17
|
-
var SignIn = forwardRef(function SignIn2(props, ref) {
|
|
17
|
+
var SignIn = /* @__PURE__ */ forwardRef(function SignIn2(props, ref) {
|
|
18
18
|
return part(
|
|
19
19
|
"div",
|
|
20
20
|
props,
|
|
@@ -23,7 +23,7 @@ var SignIn = forwardRef(function SignIn2(props, ref) {
|
|
|
23
23
|
ref
|
|
24
24
|
);
|
|
25
25
|
});
|
|
26
|
-
var SignOut = forwardRef(function SignOut2(props, ref) {
|
|
26
|
+
var SignOut = /* @__PURE__ */ forwardRef(function SignOut2(props, ref) {
|
|
27
27
|
return part(
|
|
28
28
|
"div",
|
|
29
29
|
props,
|
|
@@ -32,7 +32,7 @@ var SignOut = forwardRef(function SignOut2(props, ref) {
|
|
|
32
32
|
ref
|
|
33
33
|
);
|
|
34
34
|
});
|
|
35
|
-
var CustomerPart = forwardRef(function Customer(props, ref) {
|
|
35
|
+
var CustomerPart = /* @__PURE__ */ forwardRef(function Customer(props, ref) {
|
|
36
36
|
return part(
|
|
37
37
|
"div",
|
|
38
38
|
props,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/account/index.tsx"],
|
|
4
|
-
"mappings": ";AAAA,SAAS,kBAAkB;AAC3B,SAAS,YAA4B;AAyB9B,IAAM,4BAAN,cAAwC,MAAM;AAAA,EAEnD,cAAc;AACZ,UAAM,oEAAoE;AAF5E,SAAS,OAAO;AAGd,SAAK,OAAO;AAAA,EACd;AACF;AACA,eAAe,OAAO,UAAyC;AAC7D,QAAM,IAAI,0BAA0B;AACtC;AACA,eAAe,QAAQ,UAAoD;AACzE,QAAM,IAAI,0BAA0B;AACtC;AACA,IAAM,
|
|
4
|
+
"mappings": ";AAAA,SAAS,kBAAkB;AAC3B,SAAS,YAA4B;AAyB9B,IAAM,4BAAN,cAAwC,MAAM;AAAA,EAEnD,cAAc;AACZ,UAAM,oEAAoE;AAF5E,SAAS,OAAO;AAGd,SAAK,OAAO;AAAA,EACd;AACF;AACA,eAAe,OAAO,UAAyC;AAC7D,QAAM,IAAI,0BAA0B;AACtC;AACA,eAAe,QAAQ,UAAoD;AACzE,QAAM,IAAI,0BAA0B;AACtC;AACA,IAAM,SAAyB,2BAG7B,SAASA,QAAO,OAAO,KAAK;AAC5B,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,EAAE,QAAQ,QAAQ,iBAAiB;AAAA,IACnC,EAAE,cAAc,UAAU;AAAA,IAC1B;AAAA,EACF;AACF,CAAC;AACD,IAAM,UAA0B,2BAG9B,SAASC,SAAQ,OAAO,KAAK;AAC7B,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,EAAE,SAAS,QAAQ,iBAAiB;AAAA,IACpC,EAAE,cAAc,UAAU;AAAA,IAC1B;AAAA,EACF;AACF,CAAC;AACD,IAAM,eAA+B,2BAGnC,SAAS,SAAS,OAAO,KAAK;AAC9B,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,EAAE,UAAU,MAAM,QAAQ,iBAAiB;AAAA,IAC3C,EAAE,cAAc,UAAU;AAAA,IAC1B;AAAA,EACF;AACF,CAAC;AAKM,IAAM,UAAU,EAAE,QAAQ,SAAS,UAAU,aAAa;",
|
|
5
5
|
"names": ["SignIn", "SignOut"]
|
|
6
6
|
}
|
|
@@ -20,7 +20,7 @@ function useZappieAccountUrl(returnTo) {
|
|
|
20
20
|
}, [returnTo]);
|
|
21
21
|
return url;
|
|
22
22
|
}
|
|
23
|
-
var ZappieAccountLink = forwardRef(function ZappieAccountLink2({ returnTo, ...props }, ref) {
|
|
23
|
+
var ZappieAccountLink = /* @__PURE__ */ forwardRef(function ZappieAccountLink2({ returnTo, ...props }, ref) {
|
|
24
24
|
const href = useZappieAccountUrl(returnTo);
|
|
25
25
|
return part(
|
|
26
26
|
"a",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/account/zappie-account.tsx"],
|
|
4
|
-
"mappings": ";AAAA,SAAS,mBAAmB;AAE5B,SAAS,YAAY,WAAW,gBAAgB;AAChD,SAAS,YAA4B;AAErC,IAAM,WAAW,oBAAI,IAAI,CAAC,aAAa,aAAa,SAAS,KAAK,CAAC;AAU5D,SAAS,kBAAkB,MAAiC;AACjE,QAAM,OAAO,KAAK,KAAK,EAAE,YAAY,EAAE,QAAQ,OAAO,EAAE;AACxD,SAAO,SAAS,IAAI,IAAI,KACtB,KAAK,SAAS,YAAY,KAC1B,KAAK,SAAS,cAAc,KAC5B,KAAK,SAAS,mBAAmB,KACjC,KAAK,SAAS,OAAO,IACnB,YACA;AACN;AASO,SAAS,iBAAiB,MAA4B;AAC3D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AAU,GAAG,MAAM,GAAG,KAAK;AACxD,QAAM,OAAO,oBAAoB,QAAQ;AACzC,SAAO;AAAA,IACL;AAAA,IACA,EAAE,GAAG,OAAO,UAAU,MAAM,YAAY,sBAAsB;AAAA,IAC9D,EAAE,KAAK;AAAA,IACP,EAAE,MAAM,uBAAuB,GAAG;AAAA,IAClC;AAAA,EACF;AACF,CAAC;",
|
|
5
5
|
"names": ["ZappieAccountLink"]
|
|
6
6
|
}
|
package/dist/branch-map/fit.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/branch-map/fit.ts
|
|
2
|
+
import { nearestBranch } from "@zappie/sdk/branches";
|
|
2
3
|
import {
|
|
3
4
|
validCoordinates,
|
|
4
5
|
visibleBranches
|
|
@@ -18,29 +19,14 @@ var COMPACT_ROUTE_PADDING = {
|
|
|
18
19
|
};
|
|
19
20
|
var SINGLE_POINT_ZOOM = 14;
|
|
20
21
|
var COMPACT_SINGLE_POINT_ZOOM = 13;
|
|
21
|
-
function distanceKm(from, to) {
|
|
22
|
-
const radians = (degrees) => degrees * Math.PI / 180;
|
|
23
|
-
const dLat = radians(to.lat - from.lat);
|
|
24
|
-
const dLng = radians(to.lng - from.lng);
|
|
25
|
-
const a = Math.sin(dLat / 2) ** 2 + Math.cos(radians(from.lat)) * Math.cos(radians(to.lat)) * Math.sin(dLng / 2) ** 2;
|
|
26
|
-
return 6371 * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
27
|
-
}
|
|
28
22
|
function focusedBranch(branches, selectedId, shopper) {
|
|
29
23
|
const visible = visibleBranches(branches);
|
|
30
24
|
const selected = visible.find((branch) => branch.id === selectedId);
|
|
31
25
|
if (selected || !validCoordinates(shopper)) {
|
|
32
26
|
return selected;
|
|
33
27
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
for (const branch of visible) {
|
|
37
|
-
const distance = distanceKm(shopper, branch.coordinates);
|
|
38
|
-
if (distance < best) {
|
|
39
|
-
best = distance;
|
|
40
|
-
nearest = branch;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return nearest;
|
|
28
|
+
const nearest = nearestBranch(visible, shopper);
|
|
29
|
+
return nearest && visible.find((branch) => branch.id === nearest.id);
|
|
44
30
|
}
|
|
45
31
|
function clusterSize(count) {
|
|
46
32
|
return count < 10 ? 40 : count < 50 ? 48 : 56;
|
|
@@ -115,7 +101,6 @@ export {
|
|
|
115
101
|
SINGLE_POINT_ZOOM,
|
|
116
102
|
branchBounds,
|
|
117
103
|
clusterSize,
|
|
118
|
-
distanceKm,
|
|
119
104
|
fitPlan,
|
|
120
105
|
focusedBranch,
|
|
121
106
|
pointBounds
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/branch-map/fit.ts"],
|
|
4
|
-
"mappings": ";AACA;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAMA,IAAM,mBAAmB;AAEzB,IAAM,gBAAyB;AAAA,EACpC,KAAK;AAAA,EACL,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,MAAM;AACR;AAEO,IAAM,wBAAiC;AAAA,EAC5C,KAAK;AAAA,EACL,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,MAAM;AACR;AAEO,IAAM,oBAAoB;AAC1B,IAAM,4BAA4B;
|
|
4
|
+
"mappings": ";AACA,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAMA,IAAM,mBAAmB;AAEzB,IAAM,gBAAyB;AAAA,EACpC,KAAK;AAAA,EACL,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,MAAM;AACR;AAEO,IAAM,wBAAiC;AAAA,EAC5C,KAAK;AAAA,EACL,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,MAAM;AACR;AAEO,IAAM,oBAAoB;AAC1B,IAAM,4BAA4B;AAMlC,SAAS,cACd,UACA,YACA,SACA;AACA,QAAM,UAAU,gBAAgB,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AAM,SAAS,gBAAgB,QAAQ,EAAE,IAAI,CAAC,WAAW,OAAO,WAAW;AAC3E,MAAI,iBAAiB,QAAQ,GAAG;AAC9B,WAAO,KAAK,QAAQ;AAAA,EACtB;AACA,SAAO,YAAY,MAAM;AAC3B;AAWO,SAAS,QAAQ;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AACZ,GAMwB;AACtB,QAAM,WAAW,iBAAiB,OAAO,IAAI,UAAU;AACvD,QAAM,SACJ,YAAY,UACR,CAAC,UAAU,QAAQ,WAAW,IAC9B;AAAA,IACE,GAAI,WAAW,CAAC,QAAQ,IAAI,CAAC;AAAA,IAC7B,GAAG,gBAAgB,QAAQ,EAAE,IAAI,CAAC,WAAW,OAAO,WAAW;AAAA,EACjE;AACN,MAAI,CAAC,OAAO,QAAQ;AAClB,WAAO;AAAA,EACT;AACA,QAAM,QAAQ,CAAC,EAAE,YAAY;AAC7B,MAAI,OAAO,WAAW,GAAG;AACvB,WAAO;AAAA,MACL,MAAM;AAAA,MACN,QAAQ,OAAO,CAAC;AAAA,MAChB,MAAM,KAAK;AAAA,QACT;AAAA,QACA,UAAU,4BAA4B;AAAA,MACxC;AAAA,IACF;AAAA,EACF;AACA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ,YAAY,MAAM;AAAA,IAC1B,SAAS,QACL,UACE,wBACA,gBACF;AAAA,IACJ;AAAA,EACF;AACF;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
// src/branch-map/geometry.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
);
|
|
9
|
-
}
|
|
2
|
+
import {
|
|
3
|
+
isCoordinates,
|
|
4
|
+
locatedBranches
|
|
5
|
+
} from "@zappie/sdk/branches";
|
|
6
|
+
var validCoordinates = isCoordinates;
|
|
7
|
+
var visibleBranches = locatedBranches;
|
|
10
8
|
export {
|
|
11
9
|
validCoordinates,
|
|
12
10
|
visibleBranches
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/branch-map/geometry.ts"],
|
|
4
|
-
"mappings": ";
|
|
4
|
+
"mappings": ";AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AAUA,IAAM,mBAAmB;AAGzB,IAAM,kBAAkB;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { Store, Branch, Zappie, Menu } from '@zappie/sdk';
|
|
2
|
+
import { IntentPreloadHandlers } from '../index.js';
|
|
3
|
+
import 'react';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The parts of a site's root loader data the branch switch reads: the store,
|
|
7
|
+
* the branch the shop was loaded for, and whether the shopper chose it. A site
|
|
8
|
+
* without a branch choice leaves `branchChosen` out, and the loaded branch
|
|
9
|
+
* counts as chosen.
|
|
10
|
+
*/
|
|
11
|
+
type BranchSwitchShop = {
|
|
12
|
+
store: Store;
|
|
13
|
+
branch?: Branch | undefined;
|
|
14
|
+
branchChosen?: boolean | undefined;
|
|
15
|
+
};
|
|
16
|
+
/** The branch a shop was loaded for, and whether the shopper chose it. */
|
|
17
|
+
type LoadedBranch = {
|
|
18
|
+
id?: string | undefined;
|
|
19
|
+
slug?: string | undefined;
|
|
20
|
+
chosen: boolean;
|
|
21
|
+
};
|
|
22
|
+
/** Settings for `createBranchSwitchLoader`. */
|
|
23
|
+
type BranchSwitchOptions<T extends BranchSwitchShop> = {
|
|
24
|
+
/**
|
|
25
|
+
* The shop at another branch: what your root loader returns for
|
|
26
|
+
* `?branch=<that branch>`, built from the shop already loaded and that
|
|
27
|
+
* branch's menu. Recompute every field that depends on the branch here.
|
|
28
|
+
*/
|
|
29
|
+
shopAt(shop: T, branch: Branch, menu: Menu): T;
|
|
30
|
+
/**
|
|
31
|
+
* Return true to send this URL to the server loader anyway, such as a path
|
|
32
|
+
* your loader redirects.
|
|
33
|
+
*/
|
|
34
|
+
serverOnly?(url: URL, shop: T): boolean;
|
|
35
|
+
/** The query parameter that names a branch in a link. Defaults to `branch`. */
|
|
36
|
+
param?: string;
|
|
37
|
+
};
|
|
38
|
+
/** The arguments React Router passes to `shouldRevalidate` that the branch switch reads. */
|
|
39
|
+
type BranchSwitchRevalidateArgs = {
|
|
40
|
+
currentUrl: URL;
|
|
41
|
+
nextUrl: URL;
|
|
42
|
+
formMethod?: string | undefined;
|
|
43
|
+
defaultShouldRevalidate: boolean;
|
|
44
|
+
};
|
|
45
|
+
/** The arguments React Router passes to a `clientLoader` that the branch switch reads. */
|
|
46
|
+
type BranchSwitchClientLoaderArgs<S> = {
|
|
47
|
+
request: Request;
|
|
48
|
+
serverLoader: () => Promise<S>;
|
|
49
|
+
};
|
|
50
|
+
/** The root route's `clientLoader` and `shouldRevalidate` for a fast branch switch. */
|
|
51
|
+
type BranchSwitchLoader<T extends BranchSwitchShop> = {
|
|
52
|
+
/**
|
|
53
|
+
* Keep the shop the root rendered and the client it reads with. Call it in
|
|
54
|
+
* the root component on every render, before `ZappieProvider`. It does
|
|
55
|
+
* nothing on the server.
|
|
56
|
+
*/
|
|
57
|
+
remember(shop: T, client: Zappie): void;
|
|
58
|
+
/** Reload the shop only for a link to another branch. Form submissions keep React Router's rule. */
|
|
59
|
+
shouldRevalidate(args: BranchSwitchRevalidateArgs): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* A link to another branch of the store already loaded reads only that
|
|
62
|
+
* branch's menu, in the browser, and builds the shop with `shopAt`. Any
|
|
63
|
+
* other link, or a failed read, calls `serverLoader`.
|
|
64
|
+
*/
|
|
65
|
+
clientLoader<S>(args: BranchSwitchClientLoaderArgs<S>): Promise<T | S>;
|
|
66
|
+
};
|
|
67
|
+
/** The branch the shop was loaded for, and whether the shopper chose it. */
|
|
68
|
+
declare function loadedBranchOf(shop: BranchSwitchShop): LoadedBranch;
|
|
69
|
+
/**
|
|
70
|
+
* The store's branch a link names, by ID or slug, as `resolveBranch` matches it.
|
|
71
|
+
*
|
|
72
|
+
* @param store - The store, with its branches.
|
|
73
|
+
* @param wanted - The value of the link's branch parameter.
|
|
74
|
+
*/
|
|
75
|
+
declare function branchNamed(store: Store, wanted: string | null | undefined): Branch | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Whether moving from one URL to the next loads the shop again. Only a link
|
|
78
|
+
* that names another branch does. A link without the branch parameter keeps
|
|
79
|
+
* the branch already loaded, and a link to the branch already loaded and
|
|
80
|
+
* chosen reads nothing again.
|
|
81
|
+
*
|
|
82
|
+
* @param current - The current URL's query.
|
|
83
|
+
* @param next - The next URL's query.
|
|
84
|
+
* @param loaded - The branch the shop was loaded for.
|
|
85
|
+
* @param param - The query parameter that names a branch. Defaults to `branch`.
|
|
86
|
+
*/
|
|
87
|
+
declare function reloadsShop(current: URLSearchParams, next: URLSearchParams, loaded: LoadedBranch | undefined, param?: string): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* The root route's `clientLoader` and `shouldRevalidate` for choosing a
|
|
90
|
+
* branch without waiting for the server. Moving to another branch of the
|
|
91
|
+
* store already loaded reads only that branch's menu from the browser: one
|
|
92
|
+
* request instead of the server reading the store and then the menu, and none
|
|
93
|
+
* when `useBranchIntent` already read it. Create it once at module scope.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* const branchSwitch = createBranchSwitchLoader<ShopData>({
|
|
97
|
+
* shopAt: (shop, branch, menu) => ({ ...shop, config: { ...shop.config, branch: branch.id }, branch, menu, branchChosen: true, mustChoose: false }),
|
|
98
|
+
* serverOnly: (url, shop) => Boolean(redirectFor(shop.store, url.pathname)),
|
|
99
|
+
* });
|
|
100
|
+
* export const shouldRevalidate: ShouldRevalidateFunction = (args) => branchSwitch.shouldRevalidate(args);
|
|
101
|
+
* export const clientLoader = (args: Route.ClientLoaderArgs) => branchSwitch.clientLoader(args);
|
|
102
|
+
*/
|
|
103
|
+
declare function createBranchSwitchLoader<T extends BranchSwitchShop>({ shopAt, serverOnly, param, }: BranchSwitchOptions<T>): BranchSwitchLoader<T>;
|
|
104
|
+
/**
|
|
105
|
+
* Pointer, touch and focus handlers that start reading a branch's menu when
|
|
106
|
+
* the shopper reaches for the control that chooses it. The client keeps one
|
|
107
|
+
* read per branch, so the branch switch picks up this read, or its result,
|
|
108
|
+
* instead of starting another. Spread the result on the control.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* const intent = useBranchIntent(branch);
|
|
112
|
+
* <button {...intent} onClick={() => choose(branch)}>Order from {branch.name}</button>
|
|
113
|
+
*
|
|
114
|
+
* @param branch - The branch the control chooses, or its ID.
|
|
115
|
+
*/
|
|
116
|
+
declare function useBranchIntent(branch: Branch | string): IntentPreloadHandlers;
|
|
117
|
+
/**
|
|
118
|
+
* Choose a branch to order from. The branch's menu starts loading at once.
|
|
119
|
+
* A bag with lines from another branch moves there first, and `then` runs
|
|
120
|
+
* once the move is done, so the shopper never lands on a branch whose bag is
|
|
121
|
+
* still moving. Remember the choice and navigate in `then`.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* const choose = useChooseBranch((branch) => {
|
|
125
|
+
* rememberBranch(branch.id);
|
|
126
|
+
* navigate(`/menu?branch=${branch.slug}`);
|
|
127
|
+
* });
|
|
128
|
+
*
|
|
129
|
+
* @param then - What to do once the bag is at the branch.
|
|
130
|
+
* @returns A function that chooses a branch and resolves after `then`.
|
|
131
|
+
*/
|
|
132
|
+
declare function useChooseBranch(then: (branch: Branch) => void | Promise<void>): (branch: Branch) => Promise<void>;
|
|
133
|
+
/** The router state `useReloadingBranch` reads: React Router's `useLocation()` and `useNavigation()`. */
|
|
134
|
+
type BranchSwitchRouterState = {
|
|
135
|
+
location: {
|
|
136
|
+
search: string;
|
|
137
|
+
};
|
|
138
|
+
navigation: {
|
|
139
|
+
state: string;
|
|
140
|
+
location?: {
|
|
141
|
+
pathname: string;
|
|
142
|
+
search: string;
|
|
143
|
+
} | undefined;
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
/** A branch the shop is reloading for, and the path the shopper is moving to. */
|
|
147
|
+
type ReloadingBranch = {
|
|
148
|
+
branch: Branch;
|
|
149
|
+
pathname: string;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* The branch the shop is reloading for while the shopper moves to another
|
|
153
|
+
* branch of the store, so you can show your own skeleton, such as the menu's,
|
|
154
|
+
* from the tap. Undefined while nothing reloads, or the link names a branch
|
|
155
|
+
* the store doesn't have.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* const reloading = useReloadingBranch(shop, { location: useLocation(), navigation: useNavigation() });
|
|
159
|
+
* {reloading?.pathname === "/menu" ? <MenuSkeleton branch={reloading.branch} /> : <Outlet />}
|
|
160
|
+
*
|
|
161
|
+
* @param shop - The shop the root rendered.
|
|
162
|
+
* @param router - The current location and navigation.
|
|
163
|
+
* @param param - The query parameter that names a branch. Defaults to `branch`.
|
|
164
|
+
*/
|
|
165
|
+
declare function useReloadingBranch(shop: BranchSwitchShop, { location, navigation }: BranchSwitchRouterState, param?: string): ReloadingBranch | undefined;
|
|
166
|
+
|
|
167
|
+
export { branchNamed, createBranchSwitchLoader, loadedBranchOf, reloadsShop, useBranchIntent, useChooseBranch, useReloadingBranch };
|
|
168
|
+
export type { BranchSwitchClientLoaderArgs, BranchSwitchLoader, BranchSwitchOptions, BranchSwitchRevalidateArgs, BranchSwitchRouterState, BranchSwitchShop, LoadedBranch, ReloadingBranch };
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/branch-switch/index.ts
|
|
4
|
+
import { useCart, useZappie } from "@zappie/sdk/react";
|
|
5
|
+
import { useMemo } from "react";
|
|
6
|
+
import { useIntentPreload } from "../deferred/index.js";
|
|
7
|
+
function loadedBranchOf(shop) {
|
|
8
|
+
return {
|
|
9
|
+
...shop.branch ? { id: shop.branch.id, slug: shop.branch.slug } : {},
|
|
10
|
+
chosen: shop.branchChosen ?? true
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function branchNamed(store, wanted) {
|
|
14
|
+
return wanted ? store.branches.find(
|
|
15
|
+
(branch) => branch.id === wanted || branch.slug === wanted
|
|
16
|
+
) : void 0;
|
|
17
|
+
}
|
|
18
|
+
function reloadsShop(current, next, loaded, param = "branch") {
|
|
19
|
+
const wanted = next.get(param);
|
|
20
|
+
if (wanted === null || wanted === current.get(param)) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return !(loaded?.chosen && (wanted === loaded.id || wanted === loaded.slug));
|
|
24
|
+
}
|
|
25
|
+
function createBranchSwitchLoader({
|
|
26
|
+
shopAt,
|
|
27
|
+
serverOnly,
|
|
28
|
+
param = "branch"
|
|
29
|
+
}) {
|
|
30
|
+
let live;
|
|
31
|
+
return {
|
|
32
|
+
remember(shop, client) {
|
|
33
|
+
if (typeof window !== "undefined") {
|
|
34
|
+
live = { shop, client };
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
shouldRevalidate({
|
|
38
|
+
currentUrl,
|
|
39
|
+
nextUrl,
|
|
40
|
+
formMethod,
|
|
41
|
+
defaultShouldRevalidate
|
|
42
|
+
}) {
|
|
43
|
+
if (formMethod && formMethod.toUpperCase() !== "GET") {
|
|
44
|
+
return defaultShouldRevalidate;
|
|
45
|
+
}
|
|
46
|
+
return reloadsShop(
|
|
47
|
+
currentUrl.searchParams,
|
|
48
|
+
nextUrl.searchParams,
|
|
49
|
+
live && loadedBranchOf(live.shop),
|
|
50
|
+
param
|
|
51
|
+
);
|
|
52
|
+
},
|
|
53
|
+
async clientLoader({ request, serverLoader }) {
|
|
54
|
+
const url = new URL(request.url);
|
|
55
|
+
const current = live;
|
|
56
|
+
const branch = current ? branchNamed(current.shop.store, url.searchParams.get(param)) : void 0;
|
|
57
|
+
if (current && branch && !serverOnly?.(url, current.shop)) {
|
|
58
|
+
try {
|
|
59
|
+
const menu = await current.client.menu.get({
|
|
60
|
+
branch: branch.id,
|
|
61
|
+
signal: request.signal
|
|
62
|
+
});
|
|
63
|
+
return shopAt(current.shop, branch, menu);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (request.signal.aborted) {
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return serverLoader();
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
var readMenu = (client, branch) => client.menu.get({ branch: typeof branch === "string" ? branch : branch.id });
|
|
75
|
+
function useBranchIntent(branch) {
|
|
76
|
+
const client = useZappie();
|
|
77
|
+
return useIntentPreload(
|
|
78
|
+
useMemo(
|
|
79
|
+
() => ({ preload: () => readMenu(client, branch) }),
|
|
80
|
+
[client, branch]
|
|
81
|
+
)
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
function useChooseBranch(then) {
|
|
85
|
+
const client = useZappie();
|
|
86
|
+
const cart = useCart();
|
|
87
|
+
return async (branch) => {
|
|
88
|
+
readMenu(client, branch).catch(() => {
|
|
89
|
+
});
|
|
90
|
+
if (cart.lines.length > 0 && branch.id !== cart.branchId) {
|
|
91
|
+
await cart.actions.moveTo(branch.id);
|
|
92
|
+
}
|
|
93
|
+
await then(branch);
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function useReloadingBranch(shop, { location, navigation }, param = "branch") {
|
|
97
|
+
const next = navigation.state === "loading" ? navigation.location : void 0;
|
|
98
|
+
const pathname = next?.pathname;
|
|
99
|
+
const search = next?.search;
|
|
100
|
+
return useMemo(() => {
|
|
101
|
+
if (pathname === void 0 || search === void 0) {
|
|
102
|
+
return void 0;
|
|
103
|
+
}
|
|
104
|
+
const wanted = new URLSearchParams(search);
|
|
105
|
+
if (!reloadsShop(
|
|
106
|
+
new URLSearchParams(location.search),
|
|
107
|
+
wanted,
|
|
108
|
+
loadedBranchOf(shop),
|
|
109
|
+
param
|
|
110
|
+
)) {
|
|
111
|
+
return void 0;
|
|
112
|
+
}
|
|
113
|
+
const branch = branchNamed(shop.store, wanted.get(param));
|
|
114
|
+
return branch ? { branch, pathname } : void 0;
|
|
115
|
+
}, [shop, location.search, pathname, search, param]);
|
|
116
|
+
}
|
|
117
|
+
export {
|
|
118
|
+
branchNamed,
|
|
119
|
+
createBranchSwitchLoader,
|
|
120
|
+
loadedBranchOf,
|
|
121
|
+
reloadsShop,
|
|
122
|
+
useBranchIntent,
|
|
123
|
+
useChooseBranch,
|
|
124
|
+
useReloadingBranch
|
|
125
|
+
};
|
|
126
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/branch-switch/index.ts"],
|
|
4
|
+
"mappings": ";;;AAEA,SAAS,SAAS,iBAAiB;AACnC,SAAS,eAAe;AACxB,SAAS,wBAAoD;AAuEtD,SAAS,eAAe,MAAsC;AACnE,SAAO;AAAA,IACL,GAAI,KAAK,SAAS,EAAE,IAAI,KAAK,OAAO,IAAI,MAAM,KAAK,OAAO,KAAK,IAAI,CAAC;AAAA,IACpE,QAAQ,KAAK,gBAAgB;AAAA,EAC/B;AACF;AAQO,SAAS,YACd,OACA,QACoB;AACpB,SAAO,SACH,MAAM,SAAS;AAAA,IACb,CAAC,WAAW,OAAO,OAAO,UAAU,OAAO,SAAS;AAAA,EACtD,IACA;AACN;AAaO,SAAS,YACd,SACA,MACA,QACA,QAAQ,UACC;AACT,QAAM,SAAS,KAAK,IAAI,KAAK;AAC7B,MAAI,WAAW,QAAQ,WAAW,QAAQ,IAAI,KAAK,GAAG;AACpD,WAAO;AAAA,EACT;AACA,SAAO,EAAE,QAAQ,WAAW,WAAW,OAAO,MAAM,WAAW,OAAO;AACxE;AAiBO,SAAS,yBAAqD;AAAA,EACnE;AAAA,EACA;AAAA,EACA,QAAQ;AACV,GAAkD;AAChD,M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