@zappie/foundations 0.12.13 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/README.md +58 -0
- package/dist/checkout/attempt.js +1 -0
- package/dist/checkout/attempt.js.map +1 -1
- package/dist/checkout/use-checkout-flow.js +2 -0
- package/dist/checkout/use-checkout-flow.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/loyalty/index.d.ts +171 -0
- package/dist/loyalty/index.js +279 -0
- package/dist/loyalty/index.js.map +6 -0
- package/dist/order/index.d.ts +200 -0
- package/dist/order/index.js +576 -0
- package/dist/order/index.js.map +6 -0
- package/dist/order/model.js +84 -0
- package/dist/order/model.js.map +6 -0
- package/dist/order/use-customer-order.js +56 -0
- package/dist/order/use-customer-order.js.map +6 -0
- package/dist/overlay/engine.d.ts +57 -3
- package/dist/slot-CHfqzPTd.d.ts +13 -0
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +11 -3
- package/dist/engine-TxMNPD2g.d.ts +0 -65
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/order/model.ts"],
|
|
4
|
+
"mappings": ";AAAA,SAAS,aAAwC;AAI1C,IAAM,aAAa,CAAC,UACzB,MAAM,MAAM,cAAc,MAAM,QAAoB;AAuB/C,SAAS,YAAY,OAAuC;AACjE,QAAM,OAAwB;AAAA,IAC5B,EAAE,MAAM,YAAY,OAAO,YAAY,QAAQ,WAAW,MAAM,QAAQ,EAAE;AAAA,EAC5E;AACA,MAAI,WAAW;AACf,aAAW,UAAU,MAAM,SAAS;AAClC,UAAM,aAAa,OAAO,SAAS;AACnC,4BAAa;AACb,SAAK,KAAK;AAAA,MACR,MAAM,aAAa,aAAa;AAAA,MAChC,OAAO,OAAO;AAAA,MACd,QAAQ,WAAW,OAAO,MAAM;AAAA,MAChC,GAAI,OAAO,SAC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,OAG1B;AACA,QAAM,OAAO,MAAM,SAAS,GAAG,EAAE;AACjC,SAAO,OACH,EAAE,OAAO,KAAK,OAAO,aAAa,KAAK,YAAY,IACnD;AAAA,IACE,OAAO,MAAM,OACV,WAAW,KAAK,GAAG,EACnB,QAAQ,MAAM,CAAC,UAAU,MAAM,YAAY,CAAC;AAAA,IAC/C,aAAa;AAAA,EACf;AACN;AAMO,SAAS,UAAU,KAAa,UAA2B;AAChE,QAAM,OAAO,IAAI,KAAK,GAAG;AACzB,MAAI,OAAO,MAAM,KAAK,QAAQ,CAAC,GAAG;AAChC,WAAO;AAAA,EACT;AACA,SAAO,IAAI,KAAK,eAAe,SAAS;AAAA,IACtC,KAAK;AAAA,IACL,OAAO;AAAA,IACP,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,GAAI,WAAW,EAAE,SAAS,IAAI,CAAC;AAAA,EACjC,CAAC,EAAE,OAAO,IAAI;AAChB;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/order/use-customer-order.ts
|
|
4
|
+
import { useCallback, useEffect, useState } from "react";
|
|
5
|
+
import { orderEnded } from "./model.js";
|
|
6
|
+
function useCustomerOrder(customer, orderId, options = {}) {
|
|
7
|
+
const initial = options.initialOrder?.id === orderId ? options.initialOrder : void 0;
|
|
8
|
+
const [state, setState] = useState({ id: orderId, order: initial, error: void 0 });
|
|
9
|
+
const [attempt, setAttempt] = useState(0);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const abort = new AbortController();
|
|
12
|
+
const show = (order2) => {
|
|
13
|
+
if (!abort.signal.aborted) {
|
|
14
|
+
setState({ id: orderId, order: order2, error: void 0 });
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
let stop;
|
|
18
|
+
customer.order(orderId, abort.signal).then(
|
|
19
|
+
(order2) => {
|
|
20
|
+
show(order2);
|
|
21
|
+
if (!abort.signal.aborted && !orderEnded(order2)) {
|
|
22
|
+
stop = customer.watchOrder(orderId, {
|
|
23
|
+
signal: abort.signal,
|
|
24
|
+
onOrder: show
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
(error2) => {
|
|
29
|
+
if (!abort.signal.aborted) {
|
|
30
|
+
setState((last) => ({
|
|
31
|
+
id: orderId,
|
|
32
|
+
order: last.id === orderId ? last.order : void 0,
|
|
33
|
+
error: error2
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
return () => {
|
|
39
|
+
abort.abort();
|
|
40
|
+
stop?.();
|
|
41
|
+
};
|
|
42
|
+
}, [customer, orderId, attempt]);
|
|
43
|
+
const retry = useCallback(() => setAttempt((value) => value + 1), []);
|
|
44
|
+
const order = state.id === orderId ? state.order : initial;
|
|
45
|
+
const error = state.id === orderId ? state.error : void 0;
|
|
46
|
+
return {
|
|
47
|
+
order,
|
|
48
|
+
error,
|
|
49
|
+
status: error === void 0 ? order ? "ready" : "loading" : error.status === 404 ? "not_found" : "error",
|
|
50
|
+
retry
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
useCustomerOrder
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=use-customer-order.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/order/use-customer-order.ts"],
|
|
4
|
+
"mappings": ";;;AAEA,SAAS,aAAa,WAAW,gBAAgB;AACjD,SAAS,kBAAkB;AAwBpB,SAAS,iBACd,UACA,SACA,UAA4C,CAAC,GACzB;AACpB,QAAM,UACJ,QAAQ,cAAc,OAAO,UAAU,QAAQ,eAAe;AAChE,QAAM,CAAC,OAAO,QAAQ,IAAI,SAIvB,EAAE,IAAI,SAAS,OAAO,SAAS,OAAO,OAAU,CAAC;AACpD,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,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-
import '
|
|
3
|
-
import '
|
|
1
|
+
import { P as PartOwnedAttributes } from '../slot-CHfqzPTd.js';
|
|
2
|
+
import { PartProps } from '../index.js';
|
|
3
|
+
import * as react from 'react';
|
|
4
|
+
import { ReactNode, Ref } from 'react';
|
|
5
|
+
import { Dialog } from '@base-ui/react/dialog';
|
|
6
|
+
|
|
7
|
+
type Presentation = "dialog" | "drawer" | "sheet";
|
|
8
|
+
type SwipeDirection = "up" | "down" | "left" | "right";
|
|
9
|
+
type SurfaceProps = {
|
|
10
|
+
open: boolean;
|
|
11
|
+
presentation: Presentation;
|
|
12
|
+
swipeDirection: SwipeDirection;
|
|
13
|
+
/** Drag drawers and sheets off the screen to close them, on phones. */
|
|
14
|
+
dragToClose: boolean;
|
|
15
|
+
/** The drag's direction, when the Root names one. Otherwise the edge the panel is attached to. */
|
|
16
|
+
dragDirection?: SwipeDirection | undefined;
|
|
17
|
+
/** Ids the trigger points at; caller-supplied ids win. */
|
|
18
|
+
contentId: string;
|
|
19
|
+
titleId?: string | undefined;
|
|
20
|
+
trigger: {
|
|
21
|
+
current: HTMLElement | null;
|
|
22
|
+
};
|
|
23
|
+
onOpen: () => void;
|
|
24
|
+
onClose: () => void;
|
|
25
|
+
onEscape?: ((event: KeyboardEvent) => void) | undefined;
|
|
26
|
+
onInteractOutside?: ((event: Event) => void) | undefined;
|
|
27
|
+
forceMount?: true | undefined;
|
|
28
|
+
container?: HTMLElement | null | undefined;
|
|
29
|
+
state: unknown;
|
|
30
|
+
contentProps: PartProps<never>;
|
|
31
|
+
contentRef: Ref<HTMLElement>;
|
|
32
|
+
};
|
|
33
|
+
type Parts = {
|
|
34
|
+
Title: typeof Dialog.Title;
|
|
35
|
+
Close: typeof Dialog.Close;
|
|
36
|
+
};
|
|
37
|
+
declare function useEngineParts(): Parts;
|
|
38
|
+
declare function Surface(props: SurfaceProps & {
|
|
39
|
+
children?: ReactNode;
|
|
40
|
+
}): react.JSX.Element;
|
|
41
|
+
declare const EngineTitle: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
|
|
42
|
+
asChild?: boolean;
|
|
43
|
+
children?: ReactNode | ((state: unknown) => ReactNode);
|
|
44
|
+
} & {
|
|
45
|
+
id?: string | undefined;
|
|
46
|
+
state: unknown;
|
|
47
|
+
} & react.RefAttributes<HTMLElement>>;
|
|
48
|
+
declare const EngineClose: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
|
|
49
|
+
asChild?: boolean;
|
|
50
|
+
children?: ReactNode | ((state: unknown) => ReactNode);
|
|
51
|
+
} & {
|
|
52
|
+
id?: string | undefined;
|
|
53
|
+
state: unknown;
|
|
54
|
+
} & react.RefAttributes<HTMLElement>>;
|
|
55
|
+
|
|
56
|
+
export { EngineClose, EngineTitle, Surface, useEngineParts };
|
|
57
|
+
export type { Presentation, SurfaceProps, SwipeDirection };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AllHTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
type PartOwnedAttributes = "children" | "defaultValue" | "value";
|
|
4
|
+
/**
|
|
5
|
+
* HTML attributes shared by foundation parts, with optional render-function children.
|
|
6
|
+
* Set asChild to merge the part props and ref into a single child element.
|
|
7
|
+
*/
|
|
8
|
+
type PartProps<S = Record<string, never>> = Omit<AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
|
|
9
|
+
asChild?: boolean;
|
|
10
|
+
children?: ReactNode | ((state: S) => ReactNode);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type { PartOwnedAttributes as P, PartProps as a };
|
package/dist/version.js
CHANGED
package/dist/version.js.map
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zappie/foundations",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "UI-less React primitives for Zappie storefronts: behaviour, state and accessibility without styles.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -25,6 +25,14 @@
|
|
|
25
25
|
"types": "./dist/checkout/index.d.ts",
|
|
26
26
|
"import": "./dist/checkout/index.js"
|
|
27
27
|
},
|
|
28
|
+
"./loyalty": {
|
|
29
|
+
"types": "./dist/loyalty/index.d.ts",
|
|
30
|
+
"import": "./dist/loyalty/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./order": {
|
|
33
|
+
"types": "./dist/order/index.d.ts",
|
|
34
|
+
"import": "./dist/order/index.js"
|
|
35
|
+
},
|
|
28
36
|
"./phone": {
|
|
29
37
|
"types": "./dist/phone/index.d.ts",
|
|
30
38
|
"import": "./dist/phone/index.js"
|
|
@@ -57,7 +65,7 @@
|
|
|
57
65
|
"peerDependencies": {
|
|
58
66
|
"react": "^18.2.0 || ^19.0.0",
|
|
59
67
|
"react-dom": "^18.2.0 || ^19.0.0",
|
|
60
|
-
"@zappie/sdk": "^0.
|
|
68
|
+
"@zappie/sdk": "^0.17.0"
|
|
61
69
|
},
|
|
62
70
|
"repository": {
|
|
63
71
|
"type": "git",
|
|
@@ -67,7 +75,7 @@
|
|
|
67
75
|
"devDependencies": {
|
|
68
76
|
"@types/google.maps": "^3.66.7",
|
|
69
77
|
"esbuild": "^0.28.2",
|
|
70
|
-
"@zappie/sdk": "0.
|
|
78
|
+
"@zappie/sdk": "0.17.0"
|
|
71
79
|
},
|
|
72
80
|
"license": "MIT",
|
|
73
81
|
"homepage": "https://github.com/zappie/storefront-packages#readme",
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import * as react from 'react';
|
|
2
|
-
import { AllHTMLAttributes, ReactNode, Ref } from 'react';
|
|
3
|
-
import { Dialog } from '@base-ui/react/dialog';
|
|
4
|
-
|
|
5
|
-
type PartOwnedAttributes = "children" | "defaultValue" | "value";
|
|
6
|
-
/**
|
|
7
|
-
* HTML attributes shared by foundation parts, with optional render-function children.
|
|
8
|
-
* Set asChild to merge the part props and ref into a single child element.
|
|
9
|
-
*/
|
|
10
|
-
type PartProps<S = Record<string, never>> = Omit<AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
|
|
11
|
-
asChild?: boolean;
|
|
12
|
-
children?: ReactNode | ((state: S) => ReactNode);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
type Presentation = "dialog" | "drawer" | "sheet";
|
|
16
|
-
type SwipeDirection = "up" | "down" | "left" | "right";
|
|
17
|
-
type SurfaceProps = {
|
|
18
|
-
open: boolean;
|
|
19
|
-
presentation: Presentation;
|
|
20
|
-
swipeDirection: SwipeDirection;
|
|
21
|
-
/** Drag drawers and sheets off the screen to close them, on phones. */
|
|
22
|
-
dragToClose: boolean;
|
|
23
|
-
/** The drag's direction, when the Root names one. Otherwise the edge the panel is attached to. */
|
|
24
|
-
dragDirection?: SwipeDirection | undefined;
|
|
25
|
-
/** Ids the trigger points at; caller-supplied ids win. */
|
|
26
|
-
contentId: string;
|
|
27
|
-
titleId?: string | undefined;
|
|
28
|
-
trigger: {
|
|
29
|
-
current: HTMLElement | null;
|
|
30
|
-
};
|
|
31
|
-
onOpen: () => void;
|
|
32
|
-
onClose: () => void;
|
|
33
|
-
onEscape?: ((event: KeyboardEvent) => void) | undefined;
|
|
34
|
-
onInteractOutside?: ((event: Event) => void) | undefined;
|
|
35
|
-
forceMount?: true | undefined;
|
|
36
|
-
container?: HTMLElement | null | undefined;
|
|
37
|
-
state: unknown;
|
|
38
|
-
contentProps: PartProps<never>;
|
|
39
|
-
contentRef: Ref<HTMLElement>;
|
|
40
|
-
};
|
|
41
|
-
type Parts = {
|
|
42
|
-
Title: typeof Dialog.Title;
|
|
43
|
-
Close: typeof Dialog.Close;
|
|
44
|
-
};
|
|
45
|
-
declare function useEngineParts(): Parts;
|
|
46
|
-
declare function Surface(props: SurfaceProps & {
|
|
47
|
-
children?: ReactNode;
|
|
48
|
-
}): react.JSX.Element;
|
|
49
|
-
declare const EngineTitle: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
|
|
50
|
-
asChild?: boolean;
|
|
51
|
-
children?: ReactNode | ((state: unknown) => ReactNode);
|
|
52
|
-
} & {
|
|
53
|
-
id?: string | undefined;
|
|
54
|
-
state: unknown;
|
|
55
|
-
} & react.RefAttributes<HTMLElement>>;
|
|
56
|
-
declare const EngineClose: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
|
|
57
|
-
asChild?: boolean;
|
|
58
|
-
children?: ReactNode | ((state: unknown) => ReactNode);
|
|
59
|
-
} & {
|
|
60
|
-
id?: string | undefined;
|
|
61
|
-
state: unknown;
|
|
62
|
-
} & react.RefAttributes<HTMLElement>>;
|
|
63
|
-
|
|
64
|
-
export { EngineClose as E, EngineTitle as c, Surface as d, useEngineParts as u };
|
|
65
|
-
export type { PartOwnedAttributes as P, SwipeDirection as S, PartProps as a, Presentation as b, SurfaceProps as e };
|