@zappie/foundations 0.10.1 → 0.11.1
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 +21 -0
- package/dist/fulfilment/schedule.js +37 -80
- package/dist/fulfilment/schedule.js.map +1 -1
- package/dist/fulfilment/window.js +155 -0
- package/dist/fulfilment/window.js.map +6 -0
- package/dist/index.d.ts +19 -33
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/schedule/index.d.ts +51 -0
- package/dist/schedule/index.js +37 -0
- package/dist/schedule/index.js.map +6 -0
- package/dist/version.js +1 -1
- package/dist/window-BAFAfQnw.d.ts +53 -0
- package/package.json +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @zappie/foundations
|
|
2
2
|
|
|
3
|
+
## 0.11.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f94c4fa: `Schedule` recovers from the failures that left the bag's When step saying the times didn't load until the page was reloaded.
|
|
8
|
+
|
|
9
|
+
- Hours that have loaded stay `ready` when a later background refresh of the menu fails. Before, a failed refresh of the catalogue the menu page had loaded put `Schedule` in `error`, and `retry` fetched a different read, so the error never cleared.
|
|
10
|
+
- When the scheduling rules fail to load, `Schedule` fetches them once more before it reports `error`, so a dropped request recovers on its own. If they fail again, the page's scripts are usually from an earlier deploy, so `retry` reloads the page, which fetches the current ones. The cart is kept.
|
|
11
|
+
|
|
12
|
+
## 0.11.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- 1444c8d: `Schedule` and `scheduleSlots` follow each menu's own ordering window, not only the branch's. A bag gets only the times every menu in it allows: the longest notice a pre-order menu asks for, the shortest days-ahead limit, and the hours all its menus are served. A pre-order menu's days-ahead limit no longer reaches past the branch's `orderAheadDays`. At a branch that takes orders only while open, a pre-order menu still uses its own limit.
|
|
17
|
+
|
|
18
|
+
`Schedule` reads the bag's menus from the source menus of the cart's lines, or from `menuIds` when you pass it. `canAsap` is true only while every menu in the bag is served and none needs notice. When nothing can be ordered, `blocker` says why and names the menu that blocks the bag.
|
|
19
|
+
|
|
20
|
+
`scheduleSlots` moves to `@zappie/foundations/schedule` with the same signature, so the scheduling rules stay out of the initial entry. Import it from there instead of `@zappie/foundations`. `Schedule` loads the rules when it first mounts, and `status` stays `loading` until they arrive. A test with fake timers can wait for them with `vi.dynamicImportSettled()`.
|
|
21
|
+
|
|
22
|
+
`scheduleSlots` takes the bag's `menus`. `scheduleDays(branch, timezone, now, menus, { days })` answers, for each day from today, whether the menus can be ordered for that day, with its slots or the reason: the branch is closed, a menu isn't served that day, the day is too far ahead, or it is too soon for the notice the menu needs. `scheduleBlocker` gives the same reason for the whole bag. Both come from `@zappie/foundations/schedule`. The types `ScheduleBlock`, `ScheduleDay`, `ScheduleMenu`, `ScheduleOptions` and `ScheduleSlot` come from either entry. The initial entry grows by about 30 B gzip.
|
|
23
|
+
|
|
3
24
|
## 0.10.1
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
|
@@ -1,76 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
// src/fulfilment/schedule.tsx
|
|
4
|
-
import { useMenu, useStore, useZappie } from "@zappie/sdk/react";
|
|
4
|
+
import { useCart, useMenu, useStore, useZappie } from "@zappie/sdk/react";
|
|
5
5
|
import { forwardRef, useEffect, useMemo, useState } from "react";
|
|
6
6
|
import { part } from "../internal/slot.js";
|
|
7
7
|
import { useControllableState } from "../internal/use-controllable-state.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
function scheduleSlots(branch, timezone, now, {
|
|
15
|
-
intervalMinutes = 30,
|
|
16
|
-
maxDays = 90,
|
|
17
|
-
noticeMinutes = 0,
|
|
18
|
-
menuSchedule
|
|
19
|
-
} = {}) {
|
|
20
|
-
if (!Number.isInteger(intervalMinutes) || intervalMinutes < 1 || !Number.isInteger(maxDays) || maxDays < 1 || maxDays > 90 || !Number.isFinite(noticeMinutes) || noticeMinutes < 0) {
|
|
21
|
-
throw new RangeError(
|
|
22
|
-
"Schedule requires a positive interval, 1\u201390 days and a non-negative notice"
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
const preorder = menuSchedule?.preorder ? menuSchedule : void 0;
|
|
26
|
-
if (!branch.fulfilment.scheduling || !preorder && !canOrderAhead(branch)) {
|
|
27
|
-
return [];
|
|
28
|
-
}
|
|
29
|
-
const days = Math.min(
|
|
30
|
-
maxDays,
|
|
31
|
-
preorder?.preorderMaxDays && preorder.preorderMaxDays > 0 ? preorder.preorderMaxDays : branch.orderAheadDays ?? 14
|
|
32
|
-
);
|
|
33
|
-
const earliest = now.getTime() + Math.max(noticeMinutes, (preorder?.preorderNoticeHours ?? 0) * 60) * 6e4;
|
|
34
|
-
const latest = now.getTime() + days * 864e5;
|
|
35
|
-
const menuIntervals = menuSchedule?.openingTimes.length ? openingIntervals(
|
|
36
|
-
{
|
|
37
|
-
...branch,
|
|
38
|
-
openingTimes: menuSchedule.openingTimes,
|
|
39
|
-
specialHours: []
|
|
40
|
-
},
|
|
41
|
-
timezone,
|
|
42
|
-
now,
|
|
43
|
-
days + 1
|
|
44
|
-
) : void 0;
|
|
45
|
-
const slots = [];
|
|
46
|
-
for (const { start, end } of openingIntervals(
|
|
47
|
-
branch,
|
|
48
|
-
timezone,
|
|
49
|
-
now,
|
|
50
|
-
days + 1
|
|
51
|
-
)) {
|
|
52
|
-
const first = start + Math.max(0, Math.ceil((earliest - start) / (intervalMinutes * 6e4))) * intervalMinutes * 6e4;
|
|
53
|
-
for (let instant = first; instant < end && instant <= latest; instant += intervalMinutes * 6e4) {
|
|
54
|
-
if (menuIntervals && !menuIntervals.some(
|
|
55
|
-
(interval) => interval.start <= instant && interval.end > instant
|
|
56
|
-
)) {
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
const date = new Date(instant);
|
|
60
|
-
slots.push({
|
|
61
|
-
value: date.toISOString(),
|
|
62
|
-
date: localParts(date, timezone).date,
|
|
63
|
-
label: new Intl.DateTimeFormat("en", {
|
|
64
|
-
timeZone: timezone,
|
|
65
|
-
hour: "numeric",
|
|
66
|
-
minute: "2-digit",
|
|
67
|
-
timeZoneName: "shortOffset"
|
|
68
|
-
}).format(date)
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return slots;
|
|
73
|
-
}
|
|
8
|
+
var windowModule;
|
|
9
|
+
var windowLoad;
|
|
10
|
+
var loadRules = () => windowLoad ?? (windowLoad = import("./window.js").catch(() => import("./window.js")).then((module) => windowModule = module).catch((error) => {
|
|
11
|
+
windowLoad = void 0;
|
|
12
|
+
throw error;
|
|
13
|
+
}));
|
|
74
14
|
var Schedule = /* @__PURE__ */ forwardRef(function Schedule2({
|
|
75
15
|
branch,
|
|
76
16
|
timezone: suppliedTimezone,
|
|
@@ -80,13 +20,24 @@ var Schedule = /* @__PURE__ */ forwardRef(function Schedule2({
|
|
|
80
20
|
intervalMinutes,
|
|
81
21
|
maxDays,
|
|
82
22
|
noticeMinutes,
|
|
23
|
+
menuIds,
|
|
83
24
|
...props
|
|
84
25
|
}, ref) {
|
|
85
26
|
const client = useZappie();
|
|
86
27
|
const store = useStore();
|
|
87
28
|
const menu = useMenu(branch.id, { metadataOnly: true });
|
|
29
|
+
const cart = useCart();
|
|
30
|
+
const ids = (menuIds ?? cart.lines.map((line) => line.menuId)).join(" ");
|
|
88
31
|
const [retrying, setRetrying] = useState(false);
|
|
89
|
-
const
|
|
32
|
+
const [rules, setRules] = useState(windowModule);
|
|
33
|
+
const [failed, setFailed] = useState(false);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!rules) {
|
|
36
|
+
loadRules().then(setRules, () => setFailed(true));
|
|
37
|
+
}
|
|
38
|
+
}, []);
|
|
39
|
+
const menuFailed = !menu.data && menu.error !== void 0;
|
|
40
|
+
const status = menu.isLoading || retrying || !rules && !failed ? "loading" : menuFailed || failed ? "error" : "ready";
|
|
90
41
|
const ready = status === "ready";
|
|
91
42
|
const timezone = suppliedTimezone ?? branch.timezone ?? store.data?.timezone ?? "UTC";
|
|
92
43
|
const [now, setNow] = useState(() => /* @__PURE__ */ new Date());
|
|
@@ -102,31 +53,37 @@ var Schedule = /* @__PURE__ */ forwardRef(function Schedule2({
|
|
|
102
53
|
defaultValue,
|
|
103
54
|
onChange: onValueChange
|
|
104
55
|
});
|
|
105
|
-
const
|
|
106
|
-
() =>
|
|
56
|
+
const result = useMemo(
|
|
57
|
+
() => rules?.bagWindow(branch, timezone, now, menu.data, ids, {
|
|
107
58
|
intervalMinutes,
|
|
108
59
|
maxDays,
|
|
109
|
-
noticeMinutes
|
|
110
|
-
menuSchedule: menu.data?.schedule
|
|
60
|
+
noticeMinutes
|
|
111
61
|
}),
|
|
112
62
|
[
|
|
63
|
+
rules,
|
|
113
64
|
branch,
|
|
114
65
|
timezone,
|
|
115
66
|
now,
|
|
67
|
+
menu.data,
|
|
68
|
+
ids,
|
|
116
69
|
intervalMinutes,
|
|
117
70
|
maxDays,
|
|
118
|
-
noticeMinutes
|
|
119
|
-
menu.data?.schedule,
|
|
120
|
-
ready
|
|
71
|
+
noticeMinutes
|
|
121
72
|
]
|
|
122
73
|
);
|
|
74
|
+
const slots = ready && result?.slots || [];
|
|
123
75
|
const days = Array.from(new Set(slots.map((slot) => slot.date))).map(
|
|
124
76
|
(date) => ({ date, slots: slots.filter((slot) => slot.date === date) })
|
|
125
77
|
);
|
|
126
|
-
const canAsap = ready &&
|
|
78
|
+
const canAsap = ready && result.canAsap;
|
|
79
|
+
const isClosed = ready && !canAsap && slots.length === 0;
|
|
127
80
|
const isValid = selection === null ? canAsap : slots.some((slot) => slot.value === selection);
|
|
128
81
|
const retry = () => {
|
|
129
|
-
if (
|
|
82
|
+
if (failed) {
|
|
83
|
+
location.reload();
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (retrying || !menuFailed) {
|
|
130
87
|
return;
|
|
131
88
|
}
|
|
132
89
|
setRetrying(true);
|
|
@@ -144,7 +101,8 @@ var Schedule = /* @__PURE__ */ forwardRef(function Schedule2({
|
|
|
144
101
|
{
|
|
145
102
|
status,
|
|
146
103
|
retry,
|
|
147
|
-
isClosed
|
|
104
|
+
isClosed,
|
|
105
|
+
blocker: isClosed ? result.why() : void 0,
|
|
148
106
|
days,
|
|
149
107
|
slots,
|
|
150
108
|
value: selection,
|
|
@@ -164,7 +122,6 @@ var Schedule = /* @__PURE__ */ forwardRef(function Schedule2({
|
|
|
164
122
|
);
|
|
165
123
|
});
|
|
166
124
|
export {
|
|
167
|
-
Schedule
|
|
168
|
-
scheduleSlots
|
|
125
|
+
Schedule
|
|
169
126
|
};
|
|
170
127
|
//# sourceMappingURL=schedule.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/fulfilment/schedule.tsx"],
|
|
4
|
-
"mappings": ";;;AAEA,SAAS,SAAS,UAAU,iBAAiB;
|
|
4
|
+
"mappings": ";;;AAEA,SAAS,SAAS,SAAS,UAAU,iBAAiB;AACtD,SAAS,YAAY,WAAW,SAAS,gBAAgB;AACzD,SAAS,YAA4B;AACrC,SAAS,4BAA4B;AAIrC,IAAI;AACJ,IAAI;AAIJ,IAAM,YAAY,MACf,4BAAe,OAAO,aAAU,EAC9B,MAAM,MAAM,OAAO,aAAU,CAAC,EAC9B,KAAK,CAAC,WAAY,eAAe,MAAO,EACxC,MAAM,CAAC,UAAmB;AACzB,eAAa;AACb,QAAM;AACR,CAAC;AAyCE,IAAM,WAA2B,2BActC,SAASA,UACT;AAAA,EACE;AAAA,EACA,UAAU;AAAA,EACV;AAAA,EACA,eAAe;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GACA,KACA;AACA,Q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AAW,YAAY,OAAO;AAAA,MAC3C,eAAe;AAAA,MACf,cAAc,UAAU,UAAU;AAAA,MAClC,gBAAgB,WAAW,CAAC,QAAQ,SAAY;AAAA,IAClD;AAAA,IACA;AAAA,EACF;AACF,CAAC;",
|
|
5
5
|
"names": ["Schedule"]
|
|
6
6
|
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// src/fulfilment/window.ts
|
|
2
|
+
import {
|
|
3
|
+
canOrderAhead,
|
|
4
|
+
getOpenStatus,
|
|
5
|
+
localParts,
|
|
6
|
+
openingIntervals
|
|
7
|
+
} from "../status/hours.js";
|
|
8
|
+
var labels = /* @__PURE__ */ new Map();
|
|
9
|
+
function grid(branch, timezone, now, menus, step, days, earliest) {
|
|
10
|
+
const latest = now.getTime() + days * 864e5;
|
|
11
|
+
const menuIntervals = menus.flatMap(
|
|
12
|
+
({ schedule }) => schedule?.openingTimes.length ? [
|
|
13
|
+
openingIntervals(
|
|
14
|
+
{
|
|
15
|
+
...branch,
|
|
16
|
+
openingTimes: schedule.openingTimes,
|
|
17
|
+
specialHours: []
|
|
18
|
+
},
|
|
19
|
+
timezone,
|
|
20
|
+
now,
|
|
21
|
+
days + 1
|
|
22
|
+
)
|
|
23
|
+
] : []
|
|
24
|
+
);
|
|
25
|
+
let label = labels.get(timezone);
|
|
26
|
+
if (!label) {
|
|
27
|
+
label = new Intl.DateTimeFormat("en", {
|
|
28
|
+
timeZone: timezone,
|
|
29
|
+
hour: "numeric",
|
|
30
|
+
minute: "2-digit",
|
|
31
|
+
timeZoneName: "shortOffset"
|
|
32
|
+
});
|
|
33
|
+
labels.set(timezone, label);
|
|
34
|
+
}
|
|
35
|
+
const slots = [];
|
|
36
|
+
for (const { start, end } of openingIntervals(
|
|
37
|
+
branch,
|
|
38
|
+
timezone,
|
|
39
|
+
now,
|
|
40
|
+
days + 1
|
|
41
|
+
)) {
|
|
42
|
+
for (let instant = start + Math.max(0, Math.ceil((earliest - start) / step)) * step; instant < end && instant <= latest; instant += step) {
|
|
43
|
+
if (menuIntervals.every(
|
|
44
|
+
(intervals) => intervals.some(
|
|
45
|
+
(interval) => interval.start <= instant && interval.end > instant
|
|
46
|
+
)
|
|
47
|
+
)) {
|
|
48
|
+
const date = new Date(instant);
|
|
49
|
+
slots.push({
|
|
50
|
+
value: date.toISOString(),
|
|
51
|
+
date: localParts(date, timezone).date,
|
|
52
|
+
label: label.format(date)
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return slots;
|
|
58
|
+
}
|
|
59
|
+
function explain(branch, timezone, now, menus, {
|
|
60
|
+
intervalMinutes = 30,
|
|
61
|
+
maxDays = 90,
|
|
62
|
+
noticeMinutes = 0
|
|
63
|
+
} = {}, span = 0) {
|
|
64
|
+
if (!Number.isInteger(intervalMinutes) || intervalMinutes < 1 || !Number.isInteger(maxDays) || maxDays < 1 || maxDays > 90 || !(noticeMinutes >= 0 && noticeMinutes < Infinity) || !Number.isInteger(span) || span < 0 || span > 90) {
|
|
65
|
+
throw new RangeError(
|
|
66
|
+
"Schedule requires a positive interval, 1\u201390 days and a non-negative notice"
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
const preorders = menus.filter((menu) => menu.schedule?.preorder);
|
|
70
|
+
const ahead = branch.orderAheadDays;
|
|
71
|
+
let days = Math.min(
|
|
72
|
+
maxDays,
|
|
73
|
+
ahead > 0 || !preorders.some((menu) => menu.schedule.preorderMaxDays > 0) ? ahead ?? 14 : 90
|
|
74
|
+
);
|
|
75
|
+
let notice = noticeMinutes;
|
|
76
|
+
let daysMenu;
|
|
77
|
+
let noticeMenu;
|
|
78
|
+
for (const { id, schedule } of preorders) {
|
|
79
|
+
const limit = schedule.preorderMaxDays;
|
|
80
|
+
if (limit > 0 && limit < days) {
|
|
81
|
+
days = limit;
|
|
82
|
+
daysMenu = id;
|
|
83
|
+
}
|
|
84
|
+
if (schedule.preorderNoticeHours * 60 > notice) {
|
|
85
|
+
notice = schedule.preorderNoticeHours * 60;
|
|
86
|
+
noticeMenu = id;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const step = intervalMinutes * 6e4;
|
|
90
|
+
const scheduling = branch.fulfilment.scheduling && (preorders.length > 0 || canOrderAhead(branch));
|
|
91
|
+
const slots = scheduling ? grid(
|
|
92
|
+
branch,
|
|
93
|
+
timezone,
|
|
94
|
+
now,
|
|
95
|
+
menus,
|
|
96
|
+
step,
|
|
97
|
+
days,
|
|
98
|
+
now.getTime() + notice * 6e4
|
|
99
|
+
) : [];
|
|
100
|
+
let why;
|
|
101
|
+
return {
|
|
102
|
+
slots,
|
|
103
|
+
why(date) {
|
|
104
|
+
if (!scheduling) {
|
|
105
|
+
return { reason: "no-scheduling" };
|
|
106
|
+
}
|
|
107
|
+
if (!why) {
|
|
108
|
+
const open = (list) => grid(
|
|
109
|
+
branch,
|
|
110
|
+
timezone,
|
|
111
|
+
now,
|
|
112
|
+
list,
|
|
113
|
+
step,
|
|
114
|
+
Math.max(span, days, 7),
|
|
115
|
+
-Infinity
|
|
116
|
+
);
|
|
117
|
+
const branchOpen = open([]);
|
|
118
|
+
const menusOpen = menus.map(
|
|
119
|
+
(_, index) => open(menus.slice(0, index + 1))
|
|
120
|
+
);
|
|
121
|
+
why = (on) => {
|
|
122
|
+
const at = (list) => list.filter(
|
|
123
|
+
(slot) => on ? slot.date === on : Date.parse(slot.value) >= now.getTime()
|
|
124
|
+
);
|
|
125
|
+
const index = menusOpen.findIndex((list) => !at(list).length);
|
|
126
|
+
return at(slots).length ? void 0 : !at(branchOpen).length ? { reason: "closed" } : index >= 0 ? { reason: "menu-closed", menuId: menus[index].id } : at(menusOpen.at(-1) ?? branchOpen).every(
|
|
127
|
+
(slot) => Date.parse(slot.value) > now.getTime() + days * 864e5
|
|
128
|
+
) ? { reason: "too-far", maxDays: days, menuId: daysMenu } : {
|
|
129
|
+
reason: "too-soon",
|
|
130
|
+
noticeHours: notice / 60,
|
|
131
|
+
menuId: noticeMenu
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
return why(date);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function bagWindow(branch, timezone, now, menu, ids, options) {
|
|
140
|
+
const sections = menu?.menus?.filter(
|
|
141
|
+
(section) => ids.split(" ").includes(section.id)
|
|
142
|
+
);
|
|
143
|
+
const menus = sections?.length ? sections : menu?.schedule ? [menu] : [];
|
|
144
|
+
return {
|
|
145
|
+
...explain(branch, timezone, now, menus, options),
|
|
146
|
+
canAsap: getOpenStatus(branch, timezone, now).isOpen && menus.every(
|
|
147
|
+
({ schedule }) => !schedule?.preorder && (!schedule?.openingTimes.length || getOpenStatus({ ...branch, ...schedule }, timezone, now).isOpen)
|
|
148
|
+
)
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
export {
|
|
152
|
+
bagWindow,
|
|
153
|
+
explain
|
|
154
|
+
};
|
|
155
|
+
//# sourceMappingURL=window.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/fulfilment/window.ts"],
|
|
4
|
+
"mappings": ";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAqCP,IAAM,SAAS,oBAAI,IAAiC;AACpD,SAAS,KACP,QACA,UACA,KACA,OACA,MACA,MACA,UACA;AACA,QAAM,SAAS,IAAI,QAAQ,IAAI,OAAO;AACtC,QAAM,gBAAgB,MAAM;AAAA,IAAQ,CAAC,EAAE,SAAS,MAC9C,UAAU,aAAa,SACnB;AAAA,MACE;AAAA,QACE;AAAA,UACE,GAAG;AAAA,UACH,cAAc,SAAS;AAAA,UACvB,cAAc,CAAC;AAAA,QACjB;AAAA,QACA;AAAA,QACA;AAAA,QACA,OAAO;AAAA,MACT;AAAA,IACF,IACA,CAAC;AAAA,EACP;AACA,MAAI,QAAQ,OAAO,IAAI,QAAQ;A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4,12 @@ import * as react from 'react';
|
|
|
4
4
|
import { HTMLAttributes, ReactNode, KeyboardEvent as KeyboardEvent$1, ImgHTMLAttributes, ChangeEvent, ClipboardEvent } from 'react';
|
|
5
5
|
import { ZappieEnvironment } from '@zappie/sdk/services';
|
|
6
6
|
import * as _zappie_sdk from '@zappie/sdk';
|
|
7
|
-
import { Branch as Branch$1, CartLine, Money as Money$1, CartLineInput, CartIssue, CartFix, Quote, DeliveryAddress,
|
|
7
|
+
import { Branch as Branch$1, CartLine, Money as Money$1, CartLineInput, CartIssue, CartFix, Quote, DeliveryAddress, CartFulfilment, OptionGroup as OptionGroup$1, Item, Choice as Choice$1, MoneyFormatOptions, PaymentMethodKind, Category, Menu, Store, OpeningTime } from '@zappie/sdk';
|
|
8
8
|
import { Coordinates } from '@zappie/sdk/branches';
|
|
9
9
|
import { useCart } from '@zappie/sdk/react';
|
|
10
10
|
export { D as Deferred, a as DeferredIdleOptions, b as DeferredProps, I as IntentPreloadHandlers, d as deferred, u as useIntentPreload } from './index-B1NMxq0i.js';
|
|
11
|
+
import { S as ScheduleBlock, a as ScheduleSlot } from './window-BAFAfQnw.js';
|
|
12
|
+
export { b as ScheduleDay, c as ScheduleMenu, d as ScheduleOptions } from './window-BAFAfQnw.js';
|
|
11
13
|
import { C as CloseOptions, O as OverlayQuery } from './history-BlytQinP.js';
|
|
12
14
|
import { SelectionControl } from '@zappie/sdk/options';
|
|
13
15
|
import '@base-ui/react/dialog';
|
|
@@ -424,14 +426,6 @@ declare const Branch: {
|
|
|
424
426
|
} & react.RefAttributes<HTMLElement>>;
|
|
425
427
|
};
|
|
426
428
|
|
|
427
|
-
/**
|
|
428
|
-
* A selectable time with an ISO instant, local date and display label including the UTC offset.
|
|
429
|
-
*/
|
|
430
|
-
type ScheduleSlot = {
|
|
431
|
-
value: string;
|
|
432
|
-
label: string;
|
|
433
|
-
date: string;
|
|
434
|
-
};
|
|
435
429
|
/**
|
|
436
430
|
* Whether the branch's menu hours have loaded. `loading` and `error` say nothing about whether the
|
|
437
431
|
* branch is open.
|
|
@@ -445,12 +439,18 @@ type ScheduleStatus = "loading" | "error" | "ready";
|
|
|
445
439
|
* the branch is closed is only right when `isClosed` is true.
|
|
446
440
|
*/
|
|
447
441
|
type ScheduleState = {
|
|
448
|
-
/** `loading` while the menu hours load, `error` when
|
|
442
|
+
/** `loading` while the menu hours and scheduling rules load, `error` when either failed, and `ready` once both are known. */
|
|
449
443
|
status: ScheduleStatus;
|
|
450
|
-
/**
|
|
444
|
+
/**
|
|
445
|
+
* Load the menu hours again after an error. When the scheduling rules failed to load, reload
|
|
446
|
+
* the page instead: the page's scripts are from an earlier deploy or unreachable, and a fresh
|
|
447
|
+
* page fetches the current ones. The cart is kept.
|
|
448
|
+
*/
|
|
451
449
|
retry: () => void;
|
|
452
|
-
/** True when the hours are known and the
|
|
450
|
+
/** True when the hours are known and the bag can be ordered neither ASAP nor for a later slot. */
|
|
453
451
|
isClosed: boolean;
|
|
452
|
+
/** Why nothing can be ordered when `isClosed` is true, naming the menu that blocks the bag when one does. */
|
|
453
|
+
blocker?: ScheduleBlock | undefined;
|
|
454
454
|
days: {
|
|
455
455
|
date: string;
|
|
456
456
|
slots: ScheduleSlot[];
|
|
@@ -459,30 +459,14 @@ type ScheduleState = {
|
|
|
459
459
|
value: string | null;
|
|
460
460
|
setValue: (value: string | null) => void;
|
|
461
461
|
isAsap: boolean;
|
|
462
|
-
/** True when the hours are known
|
|
462
|
+
/** True when the hours are known, the branch takes an order now and every menu in the bag is served now without notice. */
|
|
463
463
|
canAsap: boolean;
|
|
464
464
|
isValid: boolean;
|
|
465
465
|
};
|
|
466
|
-
/**
|
|
467
|
-
* Generate scheduling slots within branch hours and any supplied menu hours and preorder limits.
|
|
468
|
-
* Slots reach as far as the branch's `orderAheadDays`, or a pre-order menu's own limit, and never
|
|
469
|
-
* past `maxDays` when you pass it. A closed branch still gets its later slots. Returns no slots
|
|
470
|
-
* when the branch doesn't take orders ahead (`canOrderAhead`), unless the menu is a pre-order menu.
|
|
471
|
-
*
|
|
472
|
-
* @param branch - The branch whose hours and scheduling capability apply.
|
|
473
|
-
* @param timezone - The time zone used to interpret opening hours and label slots.
|
|
474
|
-
* @param now - The instant from which notice and scheduling limits are measured.
|
|
475
|
-
* @returns Slots with ISO values, local dates and display labels.
|
|
476
|
-
*/
|
|
477
|
-
declare function scheduleSlots(branch: Branch$1, timezone: string, now: Date, { intervalMinutes, maxDays, noticeMinutes, menuSchedule, }?: {
|
|
478
|
-
intervalMinutes?: number | undefined;
|
|
479
|
-
maxDays?: number | undefined;
|
|
480
|
-
noticeMinutes?: number | undefined;
|
|
481
|
-
menuSchedule?: MenuSchedule | undefined;
|
|
482
|
-
}): ScheduleSlot[];
|
|
483
466
|
/**
|
|
484
467
|
* Expose valid fulfilment slots and ASAP eligibility using branch hours and loaded menu metadata.
|
|
485
|
-
*
|
|
468
|
+
* The slots fit every menu in the bag: `menuIds`, or else the source menus of the cart's lines.
|
|
469
|
+
* See `scheduleSlots` for how the menus combine. Use null for ASAP. Requires a ZappieProvider and refreshes the available times each minute.
|
|
486
470
|
* While the menu hours load or after they fail, `status` says so. Don't show those states as closed.
|
|
487
471
|
*/
|
|
488
472
|
declare const Schedule: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
|
|
@@ -497,6 +481,8 @@ declare const Schedule: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttrib
|
|
|
497
481
|
intervalMinutes?: number | undefined;
|
|
498
482
|
maxDays?: number | undefined;
|
|
499
483
|
noticeMinutes?: number;
|
|
484
|
+
/** The bag's source menus. Defaults to the menus of the cart's lines. */
|
|
485
|
+
menuIds?: readonly string[] | undefined;
|
|
500
486
|
} & react.RefAttributes<HTMLElement>>;
|
|
501
487
|
|
|
502
488
|
type FulfilmentState = {
|
|
@@ -1163,5 +1149,5 @@ declare const OpenStatus: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttr
|
|
|
1163
1149
|
/** The installed @zappie/foundations version. */
|
|
1164
1150
|
declare const FOUNDATIONS_VERSION: string;
|
|
1165
1151
|
|
|
1166
|
-
export { Account, AccountNotConfiguredError, Address, Branch, BranchMap, Cart, Choice, DeliveryMap, FOUNDATIONS_VERSION, Fulfilment, Image, ItemForm, ItemNote, Money, OpenStatus, OptionGroup, Otp, Overlay, PartProps, PaymentMethods, Quantity, Schedule, Search, Totals, ZappieAccountLink, canOrderAhead, contactLinks, createSearchIndex, formatOpeningHours, formatWallClock, getOpenStatus, parseWallClock, preloadOverlay,
|
|
1167
|
-
export type { ActiveGroup, AddressState, AddressSuggestion, BranchMapLoadErrorState, BranchMapProps, ContactLink, Customer, DeliveryMapProps, DragDirection, DragToCloseOptions, ImageProps, ItemFormContext, ItemFormInvalidGroup, ItemFormProps, MapLoadErrorState, NoteState, PaymentMethod, QuantityProps, QuantityState,
|
|
1152
|
+
export { Account, AccountNotConfiguredError, Address, Branch, BranchMap, Cart, Choice, DeliveryMap, FOUNDATIONS_VERSION, Fulfilment, Image, ItemForm, ItemNote, Money, OpenStatus, OptionGroup, Otp, Overlay, PartProps, PaymentMethods, Quantity, Schedule, ScheduleBlock, ScheduleSlot, Search, Totals, ZappieAccountLink, canOrderAhead, contactLinks, createSearchIndex, formatOpeningHours, formatWallClock, getOpenStatus, parseWallClock, preloadOverlay, useControllableState, useDragToClose, useOverlay, useZappieAccountUrl, zappieAccountUrl, zappieEnvironment, zappieSupportUrl };
|
|
1153
|
+
export type { ActiveGroup, AddressState, AddressSuggestion, BranchMapLoadErrorState, BranchMapProps, ContactLink, Customer, DeliveryMapProps, DragDirection, DragToCloseOptions, ImageProps, ItemFormContext, ItemFormInvalidGroup, ItemFormProps, MapLoadErrorState, NoteState, PaymentMethod, QuantityProps, QuantityState, ScheduleState, ScheduleStatus, SearchResult, SearchSource, SearchState, SignInOptions, TotalsState, ZappieSupportContext };
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ import { Cart, Totals } from "./cart/index.js";
|
|
|
14
14
|
import { deferred, useIntentPreload } from "./deferred/index.js";
|
|
15
15
|
import { Address } from "./fulfilment/address-picker.js";
|
|
16
16
|
import { Branch } from "./fulfilment/branch-picker.js";
|
|
17
|
-
import { Schedule
|
|
17
|
+
import { Schedule } from "./fulfilment/schedule.js";
|
|
18
18
|
import { Fulfilment } from "./fulfilment/switch.js";
|
|
19
19
|
import { useControllableState } from "./internal/use-controllable-state.js";
|
|
20
20
|
export * from "./item-form/index.js";
|
|
@@ -65,7 +65,6 @@ export {
|
|
|
65
65
|
getOpenStatus,
|
|
66
66
|
parseWallClock,
|
|
67
67
|
preloadOverlay,
|
|
68
|
-
scheduleSlots,
|
|
69
68
|
useControllableState,
|
|
70
69
|
useDragToClose,
|
|
71
70
|
useIntentPreload,
|
package/dist/index.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"mappings": ";;;AACA,SAAS,uBAAuB;AAIhC,SAAS,SAAS,iCAAiC;AAEnD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,WAAW,mBAAmB;AAOvC,SAAS,MAAM,cAAc;AAE7B,SAAS,UAAU,wBAAwB;AAO3C,SAAS,eAAe;AAKxB,SAAS,cAAc;
|
|
4
|
+
"mappings": ";;;AACA,SAAS,uBAAuB;AAIhC,SAAS,SAAS,iCAAiC;AAEnD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,WAAW,mBAAmB;AAOvC,SAAS,MAAM,cAAc;AAE7B,SAAS,UAAU,wBAAwB;AAO3C,SAAS,eAAe;AAKxB,SAAS,cAAc;AAEvB,SAAS,gBAAgB;AAEzB,SAAS,kBAAkB;AAS3B,SAAS,4BAA4B;AACrC,cAAc;AACd,SAAS,aAAa;AAEtB,SAAS,aAAa;AACtB,SAAS,WAAW;AACpB,SAAS,sBAAsB;AAK/B,SAAS,sBAAsB;AAC/B,SAAS,SAAS,kBAAkB;AACpC,SAAS,sBAAsB;AAE/B,SAAS,mBAAmB,cAAc;AAE1C,SAAS,cAAc,wBAAwB;AAE/C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,kBAAkB;AArEpB,IAAM,sBAA8B;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Branch, MenuSchedule } from '@zappie/sdk';
|
|
2
|
+
import { c as ScheduleMenu, d as ScheduleOptions, S as ScheduleBlock, b as ScheduleDay, a as ScheduleSlot } from '../window-BAFAfQnw.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Generate scheduling slots within branch hours and the hours and pre-order terms of each menu.
|
|
6
|
+
* A bag holding items from several menus gets only the times every menu allows: the longest
|
|
7
|
+
* notice, the shortest days-ahead limit and the hours all the menus share.
|
|
8
|
+
*
|
|
9
|
+
* Slots reach as far as the branch's `orderAheadDays`, or a pre-order menu's shorter limit, and
|
|
10
|
+
* never past `maxDays` when you pass it. A pre-order menu at a branch that takes orders only while
|
|
11
|
+
* open uses its own limit. A closed branch still gets its later slots. Returns no slots when the
|
|
12
|
+
* branch doesn't take orders ahead (`canOrderAhead`), unless a menu is a pre-order menu.
|
|
13
|
+
*
|
|
14
|
+
* @param branch - The branch whose hours and scheduling capability apply.
|
|
15
|
+
* @param timezone - The time zone used to interpret opening hours and label slots.
|
|
16
|
+
* @param now - The instant from which notice and scheduling limits are measured.
|
|
17
|
+
* @param options - Site limits, the bag's `menus`, or one `menuSchedule` without a menu ID.
|
|
18
|
+
* @returns Slots with ISO values, local dates and display labels.
|
|
19
|
+
*/
|
|
20
|
+
declare function scheduleSlots(branch: Branch, timezone: string, now: Date, { menuSchedule, menus, ...options }?: ScheduleOptions & {
|
|
21
|
+
menuSchedule?: MenuSchedule | undefined;
|
|
22
|
+
menus?: readonly ScheduleMenu[] | undefined;
|
|
23
|
+
}): ScheduleSlot[];
|
|
24
|
+
/**
|
|
25
|
+
* Say why a bag holding items from `menus` has no slot, naming the menu that blocks it when one
|
|
26
|
+
* does. Returns undefined when the bag has a slot.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* scheduleBlocker(branch, "Africa/Lagos", new Date(), [brunch, surfAndTurf]);
|
|
31
|
+
* // { reason: "menu-closed", menuId: surfAndTurf.id }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
declare function scheduleBlocker(branch: Branch, timezone: string, now: Date, menus: readonly ScheduleMenu[], options?: ScheduleOptions): ScheduleBlock | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Answer, for each local day from today, whether a bag holding items from `menus` can be
|
|
37
|
+
* fulfilled that day, with the slots it can or the reason it can't. Pass one menu to ask whether
|
|
38
|
+
* that menu can make each day.
|
|
39
|
+
*
|
|
40
|
+
* @param days - How many days to answer, from today in the branch's time zone. Defaults to 14.
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* scheduleDays(branch, "Africa/Lagos", new Date(), [catering]);
|
|
44
|
+
* // [{ date: "2026-11-12", slots: [], blocker: { reason: "too-soon", noticeHours: 18, menuId: catering.id } }, ...]
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
declare function scheduleDays(branch: Branch, timezone: string, now: Date, menus: readonly ScheduleMenu[], { days, ...options }?: ScheduleOptions & {
|
|
48
|
+
days?: number;
|
|
49
|
+
}): ScheduleDay[];
|
|
50
|
+
|
|
51
|
+
export { ScheduleBlock, ScheduleDay, ScheduleMenu, ScheduleOptions, ScheduleSlot, scheduleBlocker, scheduleDays, scheduleSlots };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// src/schedule/index.ts
|
|
2
|
+
import {
|
|
3
|
+
explain
|
|
4
|
+
} from "../fulfilment/window.js";
|
|
5
|
+
import { dateOffset, localParts } from "../status/hours.js";
|
|
6
|
+
function scheduleSlots(branch, timezone, now, {
|
|
7
|
+
menuSchedule,
|
|
8
|
+
menus = [],
|
|
9
|
+
...options
|
|
10
|
+
} = {}) {
|
|
11
|
+
return explain(
|
|
12
|
+
branch,
|
|
13
|
+
timezone,
|
|
14
|
+
now,
|
|
15
|
+
menuSchedule ? [...menus, { id: "", schedule: menuSchedule }] : [...menus],
|
|
16
|
+
options
|
|
17
|
+
).slots;
|
|
18
|
+
}
|
|
19
|
+
function scheduleBlocker(branch, timezone, now, menus, options) {
|
|
20
|
+
return explain(branch, timezone, now, [...menus], options).why();
|
|
21
|
+
}
|
|
22
|
+
function scheduleDays(branch, timezone, now, menus, { days = 14, ...options } = {}) {
|
|
23
|
+
const result = explain(branch, timezone, now, [...menus], options, days);
|
|
24
|
+
const today = localParts(now, timezone).date;
|
|
25
|
+
return Array.from({ length: days }, (_, offset) => {
|
|
26
|
+
const date = dateOffset(today, offset);
|
|
27
|
+
const slots = result.slots.filter((slot) => slot.date === date);
|
|
28
|
+
const blocker = slots.length ? void 0 : result.why(date);
|
|
29
|
+
return blocker ? { date, slots, blocker } : { date, slots };
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
scheduleBlocker,
|
|
34
|
+
scheduleDays,
|
|
35
|
+
scheduleSlots
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/schedule/index.ts"],
|
|
4
|
+
"mappings": ";AACA;AAAA,EACE;AAAA,OAMK;AACP,SAAS,YAAY,kBAAkB;AAwBhC,SAAS,cACd,QACA,UACA,KACA;AAAA,EACE;AAAA,EACA,QAAQ,CAAC;AAAA,EACT,GAAG;AACL,IAGI,CAAC,GACW;AAChB,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe,CAAC,GAAG,OAAO,EAAE,IAAI,IAAI,UAAU,aAAa,CAAC,IAAI,CAAC,GAAG,KAAK;AAAA,IACzE;AAAA,EACF,EAAE;AACJ;AAWO,SAAS,gBACd,QACA,UACA,KACA,OACA,SAC2B;AAC3B,SAAO,QAAQ,QAAQ,UAAU,KAAK,CAAC,GAAG,KAAK,GAAG,OAAO,EAAE,IAAI;AACjE;AAaO,SAAS,aACd,QACA,UACA,KACA,OACA,EAAE,OAAO,IAAI,GAAG,QAAQ,IAAyC,CAAC,GACnD;AACf,QAAM,SAAS,QAAQ,QAAQ,UAAU,KAAK,CAAC,GAAG,KAAK,GAAG,SAAS,IAAI;AACvE,QAAM,QAAQ,WAAW,KAAK,QAAQ,EAAE;AACxC,SAAO,MAAM,KAAK,EAAE,QAAQ,KAAK,GAAG,CAAC,GAAG,WAAW;AACjD,UAAM,OAAO,WAAW,OAAO,MAAM;AACrC,UAAM,QAAQ,OAAO,MAAM,OAAO,CAAC,SAAS,KAAK,SAAS,IAAI;AAC9D,UAAM,UAAU,MAAM,SAAS,SAAY,OAAO,IAAI,IAAI;AAC1D,WAAO,UAAU,EAAE,MAAM,OAAO,QAAQ,IAAI,EAAE,MAAM,MAAM;AAAA,EAC5D,CAAC;AACH;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
package/dist/version.js
CHANGED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { MenuSection } from '@zappie/sdk';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A selectable time with an ISO instant, local date and display label including the UTC offset.
|
|
5
|
+
*/
|
|
6
|
+
type ScheduleSlot = {
|
|
7
|
+
value: string;
|
|
8
|
+
label: string;
|
|
9
|
+
date: string;
|
|
10
|
+
};
|
|
11
|
+
/** A source menu whose hours and pre-order terms limit when a bag can be fulfilled. */
|
|
12
|
+
type ScheduleMenu = Pick<MenuSection, "id" | "schedule">;
|
|
13
|
+
/** Limits that a site adds to the branch and menu rules. */
|
|
14
|
+
type ScheduleOptions = {
|
|
15
|
+
/** Minutes between slots. Defaults to 30. */
|
|
16
|
+
intervalMinutes?: number | undefined;
|
|
17
|
+
/** The furthest day ahead to offer, 1 to 90. Defaults to 90. */
|
|
18
|
+
maxDays?: number | undefined;
|
|
19
|
+
/** Minutes of lead time every order needs. Defaults to 0. */
|
|
20
|
+
noticeMinutes?: number | undefined;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Why a day, or a whole bag, has no slot.
|
|
24
|
+
*
|
|
25
|
+
* - `no-scheduling`: the branch takes no scheduled orders for these menus.
|
|
26
|
+
* - `closed`: the branch is closed.
|
|
27
|
+
* - `menu-closed`: the menu named by `menuId` isn't served then, or shares no time with the menus before it.
|
|
28
|
+
* - `too-far`: the day is past the `maxDays` limit. `menuId` names the menu that sets it, when one does.
|
|
29
|
+
* - `too-soon`: the remaining times are within the `noticeHours` the order needs. `menuId` names the
|
|
30
|
+
* menu that asks for that notice, when one does. Zero `noticeHours` means the day's times have passed.
|
|
31
|
+
*/
|
|
32
|
+
type ScheduleBlock = {
|
|
33
|
+
reason: "no-scheduling" | "closed";
|
|
34
|
+
} | {
|
|
35
|
+
reason: "menu-closed";
|
|
36
|
+
menuId: string;
|
|
37
|
+
} | {
|
|
38
|
+
reason: "too-far";
|
|
39
|
+
maxDays: number;
|
|
40
|
+
menuId?: string | undefined;
|
|
41
|
+
} | {
|
|
42
|
+
reason: "too-soon";
|
|
43
|
+
noticeHours: number;
|
|
44
|
+
menuId?: string | undefined;
|
|
45
|
+
};
|
|
46
|
+
/** One local day with its slots, and why it has none when `slots` is empty. */
|
|
47
|
+
type ScheduleDay = {
|
|
48
|
+
date: string;
|
|
49
|
+
slots: ScheduleSlot[];
|
|
50
|
+
blocker?: ScheduleBlock;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export type { ScheduleBlock as S, ScheduleSlot as a, ScheduleDay as b, ScheduleMenu as c, ScheduleOptions as d };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zappie/foundations",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "UI-less React primitives for Zappie storefronts: behaviour, state and accessibility without styles.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -17,6 +17,10 @@
|
|
|
17
17
|
"types": "./dist/branch-switch/index.d.ts",
|
|
18
18
|
"import": "./dist/branch-switch/index.js"
|
|
19
19
|
},
|
|
20
|
+
"./schedule": {
|
|
21
|
+
"types": "./dist/schedule/index.d.ts",
|
|
22
|
+
"import": "./dist/schedule/index.js"
|
|
23
|
+
},
|
|
20
24
|
"./rich-text": {
|
|
21
25
|
"types": "./dist/rich-text/index.d.ts",
|
|
22
26
|
"import": "./dist/rich-text/index.js"
|