@clicktap/state 0.2.0 → 0.9.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/index.esm.d.ts +1 -0
- package/index.esm.js +996 -0
- package/package.json +7 -9
- package/src/auth/AuthProvider.d.ts +418 -34
- package/src/auth/auth.d.ts +147 -21
- package/src/helpers/request.d.ts +2 -0
- package/src/quote/actions/addItems.d.ts +8 -0
- package/src/quote/actions/index.d.ts +2 -0
- package/src/quote/actions/removeItems.d.ts +8 -0
- package/src/quote/actors/addItems.d.ts +7 -0
- package/src/quote/actors/index.d.ts +3 -0
- package/src/quote/actors/refresh.d.ts +6 -0
- package/src/quote/actors/removeItems.d.ts +7 -0
- package/src/quote/guards/hasItems.d.ts +5 -0
- package/src/quote/guards/index.d.ts +1 -0
- package/src/quote/quote.d.ts +113 -0
- package/src/quote/types.d.ts +135 -0
- package/src/toast/ToastProvider.d.ts +63 -11
- package/src/toast/timer.d.ts +25 -25
- package/src/toast/toast.d.ts +32 -46
- package/src/toast/types.d.ts +59 -0
- package/index.js +0 -724
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { QuoteMachineContext, QuoteMachineEvents } from '../types';
|
|
2
|
+
export declare function addItems({ context, event, }: {
|
|
3
|
+
context: QuoteMachineContext;
|
|
4
|
+
event: QuoteMachineEvents;
|
|
5
|
+
}): QuoteMachineContext | {
|
|
6
|
+
items: Record<string, any>[];
|
|
7
|
+
};
|
|
8
|
+
export default addItems;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { QuoteMachineContext, QuoteMachineEvents } from '../types';
|
|
2
|
+
export declare function removeItems({ context, event, }: {
|
|
3
|
+
context: QuoteMachineContext;
|
|
4
|
+
event: QuoteMachineEvents;
|
|
5
|
+
}): QuoteMachineContext | {
|
|
6
|
+
items: Record<string, any>[];
|
|
7
|
+
};
|
|
8
|
+
export default removeItems;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AddItemsEvent, AddItemsSuccessEvent, QuoteMachineContext } from '../types';
|
|
2
|
+
export declare const addItems: import("xstate").PromiseActorLogic<AddItemsSuccessEvent, {
|
|
3
|
+
endpoint: QuoteMachineContext['endpoints']['addItems'];
|
|
4
|
+
items: AddItemsEvent['items'];
|
|
5
|
+
quoteId: QuoteMachineContext['quoteId'];
|
|
6
|
+
}>;
|
|
7
|
+
export default addItems;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RefreshSuccessEvent, QuoteMachineContext } from '../types';
|
|
2
|
+
export declare const refresh: import("xstate").PromiseActorLogic<RefreshSuccessEvent, {
|
|
3
|
+
endpoint: QuoteMachineContext['endpoints']['refresh'];
|
|
4
|
+
quoteId: QuoteMachineContext['quoteId'];
|
|
5
|
+
}>;
|
|
6
|
+
export default refresh;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RemoveItemsEvent, RemoveItemsSuccessEvent, QuoteMachineContext } from '../types';
|
|
2
|
+
export declare const removeItems: import("xstate").PromiseActorLogic<RemoveItemsSuccessEvent, {
|
|
3
|
+
endpoint: QuoteMachineContext['endpoints']['removeItems'];
|
|
4
|
+
items: RemoveItemsEvent['items'];
|
|
5
|
+
quoteId: QuoteMachineContext['quoteId'];
|
|
6
|
+
}>;
|
|
7
|
+
export default removeItems;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './hasItems';
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { QuoteMachineContext } from './types';
|
|
2
|
+
export declare const quoteMachine: import("xstate").StateMachine<QuoteMachineContext, import("./types").SetEmptyEvent | import("./types").SetActiveEvent | import("./types").AddItemsEvent | import("./types").RemoveItemsEvent | import("./types").ClearItemsEvent | import("./types").RefreshEvent | import("./types").ApplyPromotionEvent | import("./types").RemovePromotionEvent | import("./types").AddAddressEvent | import("./types").RemoveAddressEvent | import("./types").ApplyPaymentMethodEvent | import("./types").AddRewardEvent | import("./types").RemoveRewardEvent | import("./types").AddStoreCreditEvent | import("./types").RemoveStoreCreditEvent | import("./types").AddGiftCardEvent | import("./types").RemoveGiftCardEvent | import("xstate").DoneActorEvent<import("./types").AddItemsSuccessEvent> | import("xstate").DoneActorEvent<import("./types").RemoveItemsSuccessEvent> | import("xstate").DoneActorEvent<import("./types").ClearItemsSuccessEvent> | import("xstate").DoneActorEvent<import("./types").RefreshSuccessEvent>, {
|
|
3
|
+
[x: string]: import("xstate").ActorRef<import("xstate").PromiseSnapshot<import("./types").AddItemsSuccessEvent, {
|
|
4
|
+
endpoint: "";
|
|
5
|
+
items: {
|
|
6
|
+
id: string;
|
|
7
|
+
quantity: number;
|
|
8
|
+
options: Record<string, any>;
|
|
9
|
+
}[];
|
|
10
|
+
quoteId: string;
|
|
11
|
+
}>, {
|
|
12
|
+
[k: string]: unknown;
|
|
13
|
+
type: string;
|
|
14
|
+
}> | import("xstate").ActorRef<import("xstate").PromiseSnapshot<import("./types").RemoveItemsSuccessEvent, {
|
|
15
|
+
endpoint: "";
|
|
16
|
+
items: {
|
|
17
|
+
id: string;
|
|
18
|
+
quantity: number;
|
|
19
|
+
}[];
|
|
20
|
+
quoteId: string;
|
|
21
|
+
}>, {
|
|
22
|
+
[k: string]: unknown;
|
|
23
|
+
type: string;
|
|
24
|
+
}> | import("xstate").ActorRef<import("xstate").PromiseSnapshot<import("./types").RefreshSuccessEvent, {
|
|
25
|
+
endpoint: "";
|
|
26
|
+
quoteId: string;
|
|
27
|
+
}>, {
|
|
28
|
+
[k: string]: unknown;
|
|
29
|
+
type: string;
|
|
30
|
+
}> | undefined;
|
|
31
|
+
}, {
|
|
32
|
+
src: "addItems";
|
|
33
|
+
logic: import("xstate").PromiseActorLogic<import("./types").AddItemsSuccessEvent, {
|
|
34
|
+
endpoint: "";
|
|
35
|
+
items: {
|
|
36
|
+
id: string;
|
|
37
|
+
quantity: number;
|
|
38
|
+
options: Record<string, any>;
|
|
39
|
+
}[];
|
|
40
|
+
quoteId: string;
|
|
41
|
+
}>;
|
|
42
|
+
id: string | undefined;
|
|
43
|
+
} | {
|
|
44
|
+
src: "removeItems";
|
|
45
|
+
logic: import("xstate").PromiseActorLogic<import("./types").RemoveItemsSuccessEvent, {
|
|
46
|
+
endpoint: "";
|
|
47
|
+
items: {
|
|
48
|
+
id: string;
|
|
49
|
+
quantity: number;
|
|
50
|
+
}[];
|
|
51
|
+
quoteId: string;
|
|
52
|
+
}>;
|
|
53
|
+
id: string | undefined;
|
|
54
|
+
} | {
|
|
55
|
+
src: "refresh";
|
|
56
|
+
logic: import("xstate").PromiseActorLogic<import("./types").RefreshSuccessEvent, {
|
|
57
|
+
endpoint: "";
|
|
58
|
+
quoteId: string;
|
|
59
|
+
}>;
|
|
60
|
+
id: string | undefined;
|
|
61
|
+
}, {
|
|
62
|
+
type: "addItems";
|
|
63
|
+
params: import("xstate").NonReducibleUnknown;
|
|
64
|
+
} | {
|
|
65
|
+
type: "removeItems";
|
|
66
|
+
params: import("xstate").NonReducibleUnknown;
|
|
67
|
+
}, {
|
|
68
|
+
type: "hasItems";
|
|
69
|
+
params: unknown;
|
|
70
|
+
}, string, {}, string, {
|
|
71
|
+
initialContext: Partial<QuoteMachineContext>;
|
|
72
|
+
initialState?: string | undefined;
|
|
73
|
+
}, import("xstate").NonReducibleUnknown, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, import("./types").SetEmptyEvent | import("./types").SetActiveEvent | import("./types").AddItemsEvent | import("./types").RemoveItemsEvent | import("./types").ClearItemsEvent | import("./types").RefreshEvent | import("./types").ApplyPromotionEvent | import("./types").RemovePromotionEvent | import("./types").AddAddressEvent | import("./types").RemoveAddressEvent | import("./types").ApplyPaymentMethodEvent | import("./types").AddRewardEvent | import("./types").RemoveRewardEvent | import("./types").AddStoreCreditEvent | import("./types").RemoveStoreCreditEvent | import("./types").AddGiftCardEvent | import("./types").RemoveGiftCardEvent | import("xstate").DoneActorEvent<import("./types").AddItemsSuccessEvent> | import("xstate").DoneActorEvent<import("./types").RemoveItemsSuccessEvent> | import("xstate").DoneActorEvent<import("./types").ClearItemsSuccessEvent> | import("xstate").DoneActorEvent<import("./types").RefreshSuccessEvent>, {
|
|
74
|
+
src: "addItems";
|
|
75
|
+
logic: import("xstate").PromiseActorLogic<import("./types").AddItemsSuccessEvent, {
|
|
76
|
+
endpoint: "";
|
|
77
|
+
items: {
|
|
78
|
+
id: string;
|
|
79
|
+
quantity: number;
|
|
80
|
+
options: Record<string, any>;
|
|
81
|
+
}[];
|
|
82
|
+
quoteId: string;
|
|
83
|
+
}>;
|
|
84
|
+
id: string | undefined;
|
|
85
|
+
} | {
|
|
86
|
+
src: "removeItems";
|
|
87
|
+
logic: import("xstate").PromiseActorLogic<import("./types").RemoveItemsSuccessEvent, {
|
|
88
|
+
endpoint: "";
|
|
89
|
+
items: {
|
|
90
|
+
id: string;
|
|
91
|
+
quantity: number;
|
|
92
|
+
}[];
|
|
93
|
+
quoteId: string;
|
|
94
|
+
}>;
|
|
95
|
+
id: string | undefined;
|
|
96
|
+
} | {
|
|
97
|
+
src: "refresh";
|
|
98
|
+
logic: import("xstate").PromiseActorLogic<import("./types").RefreshSuccessEvent, {
|
|
99
|
+
endpoint: "";
|
|
100
|
+
quoteId: string;
|
|
101
|
+
}>;
|
|
102
|
+
id: string | undefined;
|
|
103
|
+
}, {
|
|
104
|
+
type: "addItems";
|
|
105
|
+
params: import("xstate").NonReducibleUnknown;
|
|
106
|
+
} | {
|
|
107
|
+
type: "removeItems";
|
|
108
|
+
params: import("xstate").NonReducibleUnknown;
|
|
109
|
+
}, {
|
|
110
|
+
type: "hasItems";
|
|
111
|
+
params: unknown;
|
|
112
|
+
}, string, string>>;
|
|
113
|
+
export default quoteMachine;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { DoneActorEvent } from 'xstate';
|
|
2
|
+
/** @todo how do we want to handle quote items? */
|
|
3
|
+
export interface QuoteMachineContext {
|
|
4
|
+
quoteId: string;
|
|
5
|
+
currency: string;
|
|
6
|
+
items: Array<Record<string, any>>;
|
|
7
|
+
promotions: Array<Record<string, any>>;
|
|
8
|
+
addresses: {
|
|
9
|
+
billing: {
|
|
10
|
+
available: Array<Record<string, any>>;
|
|
11
|
+
};
|
|
12
|
+
shipping: {
|
|
13
|
+
available: Array<Record<string, any>>;
|
|
14
|
+
selected: string | null;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
totals: {
|
|
18
|
+
discount: number;
|
|
19
|
+
tax: number;
|
|
20
|
+
shipping: number;
|
|
21
|
+
shippingTax: number;
|
|
22
|
+
subtotal: number;
|
|
23
|
+
grandTotal: number;
|
|
24
|
+
};
|
|
25
|
+
payments: Array<Record<string, any>>;
|
|
26
|
+
storeCredit: Array<Record<string, any>>;
|
|
27
|
+
rewards: Array<Record<string, any>>;
|
|
28
|
+
giftCards: Array<Record<string, any>>;
|
|
29
|
+
settings: Array<Record<string, any>>;
|
|
30
|
+
endpoints: {
|
|
31
|
+
addItems: '';
|
|
32
|
+
removeItems: '';
|
|
33
|
+
clearItems: '';
|
|
34
|
+
refresh: '';
|
|
35
|
+
applyPromotion: '';
|
|
36
|
+
removePromotion: '';
|
|
37
|
+
addAddress: '';
|
|
38
|
+
removeAddress: '';
|
|
39
|
+
applyPaymentMethod: '';
|
|
40
|
+
addReward: '';
|
|
41
|
+
removeReward: '';
|
|
42
|
+
addStoreCredit: '';
|
|
43
|
+
removeStoreCredit: '';
|
|
44
|
+
addGiftCard: '';
|
|
45
|
+
removeGiftCard: '';
|
|
46
|
+
};
|
|
47
|
+
errors: Array<string>;
|
|
48
|
+
}
|
|
49
|
+
export interface SetEmptyEvent {
|
|
50
|
+
type: 'SET_EMPTY';
|
|
51
|
+
}
|
|
52
|
+
export interface SetActiveEvent {
|
|
53
|
+
type: 'SET_ACTIVE';
|
|
54
|
+
}
|
|
55
|
+
export interface AddItemsEvent {
|
|
56
|
+
type: 'ADD_ITEMS';
|
|
57
|
+
items: Array<{
|
|
58
|
+
id: string;
|
|
59
|
+
quantity: number;
|
|
60
|
+
options: Record<string, any>;
|
|
61
|
+
}>;
|
|
62
|
+
}
|
|
63
|
+
export interface RemoveItemsEvent {
|
|
64
|
+
type: 'REMOVE_ITEMS';
|
|
65
|
+
items: Array<{
|
|
66
|
+
id: string;
|
|
67
|
+
quantity: number;
|
|
68
|
+
}>;
|
|
69
|
+
}
|
|
70
|
+
export interface ClearItemsEvent {
|
|
71
|
+
type: 'CLEAR_ITEMS';
|
|
72
|
+
}
|
|
73
|
+
export interface RefreshEvent {
|
|
74
|
+
type: 'REFRESH';
|
|
75
|
+
}
|
|
76
|
+
export interface ApplyPromotionEvent {
|
|
77
|
+
type: 'APPLY_PROMOTION';
|
|
78
|
+
}
|
|
79
|
+
export interface RemovePromotionEvent {
|
|
80
|
+
type: 'REMOVE_PROMOTION';
|
|
81
|
+
}
|
|
82
|
+
export interface AddAddressEvent {
|
|
83
|
+
type: 'ADD_ADDRESS';
|
|
84
|
+
}
|
|
85
|
+
export interface RemoveAddressEvent {
|
|
86
|
+
type: 'REMOVE_ADDRESS';
|
|
87
|
+
}
|
|
88
|
+
export interface ApplyPaymentMethodEvent {
|
|
89
|
+
type: 'APPLY_PAYMENT_METHOD';
|
|
90
|
+
}
|
|
91
|
+
export interface AddRewardEvent {
|
|
92
|
+
type: 'ADD_REWARD';
|
|
93
|
+
}
|
|
94
|
+
export interface RemoveRewardEvent {
|
|
95
|
+
type: 'REMOVE_REWARD';
|
|
96
|
+
}
|
|
97
|
+
export interface AddStoreCreditEvent {
|
|
98
|
+
type: 'ADD_STORE_CREDIT';
|
|
99
|
+
}
|
|
100
|
+
export interface RemoveStoreCreditEvent {
|
|
101
|
+
type: 'REMOVE_STORE_CREDIT';
|
|
102
|
+
}
|
|
103
|
+
export interface AddGiftCardEvent {
|
|
104
|
+
type: 'ADD_GIFT_CARD';
|
|
105
|
+
}
|
|
106
|
+
export interface RemoveGiftCardEvent {
|
|
107
|
+
type: 'REMOVE_GIFT_CARD';
|
|
108
|
+
}
|
|
109
|
+
export interface AddItemsSuccessEvent {
|
|
110
|
+
type: 'ADD_ITEMS_SUCCESS';
|
|
111
|
+
items: Array<Record<string, any>>;
|
|
112
|
+
}
|
|
113
|
+
export interface RemoveItemsSuccessEvent {
|
|
114
|
+
type: 'REMOVE_ITEMS_SUCCESS';
|
|
115
|
+
items: Array<Record<string, any>>;
|
|
116
|
+
}
|
|
117
|
+
export interface ClearItemsSuccessEvent {
|
|
118
|
+
type: 'CLEAR_ITEMS_SUCCESS';
|
|
119
|
+
}
|
|
120
|
+
export interface RefreshSuccessEvent {
|
|
121
|
+
type: 'REFRESH_SUCCESS';
|
|
122
|
+
}
|
|
123
|
+
export type QuoteMachineEvents = SetEmptyEvent | SetActiveEvent | AddItemsEvent | RemoveItemsEvent | ClearItemsEvent | RefreshEvent | ApplyPromotionEvent | RemovePromotionEvent | AddAddressEvent | RemoveAddressEvent | ApplyPaymentMethodEvent | AddRewardEvent | RemoveRewardEvent | AddStoreCreditEvent | RemoveStoreCreditEvent | AddGiftCardEvent | RemoveGiftCardEvent | DoneActorEvent<AddItemsSuccessEvent> | DoneActorEvent<RemoveItemsSuccessEvent> | DoneActorEvent<ClearItemsSuccessEvent> | DoneActorEvent<RefreshSuccessEvent>;
|
|
124
|
+
export type AddItemsResponse = {
|
|
125
|
+
message?: string;
|
|
126
|
+
success: boolean;
|
|
127
|
+
};
|
|
128
|
+
export type RemoveItemsResponse = {
|
|
129
|
+
message?: string;
|
|
130
|
+
success: boolean;
|
|
131
|
+
};
|
|
132
|
+
export type RefreshResponse = {
|
|
133
|
+
message?: string;
|
|
134
|
+
success: boolean;
|
|
135
|
+
};
|
|
@@ -1,17 +1,69 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Actor } from 'xstate';
|
|
2
2
|
import type { ReactNode } from 'react';
|
|
3
3
|
import { toastMachine } from './toast';
|
|
4
|
-
export declare const ToastContext: import("react").Context<import("xstate").
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
4
|
+
export declare const ToastContext: import("react").Context<Actor<import("xstate").StateMachine<import("./types").ToastMachineContext, import("./types").AddItemEvent | import("./types").RemoveItemEvent | import("./types").SetIdleEvent | import("./types").SetActiveEvent | import("./types").ResumeTimerEvent | import("./types").PauseTimerEvent | import("./types").TimerDoneEvent, Record<string, import("xstate").AnyActorRef>, {
|
|
5
|
+
src: string;
|
|
6
|
+
logic: import("xstate").UnknownActorLogic;
|
|
7
|
+
id: string | undefined;
|
|
8
|
+
}, {
|
|
9
|
+
type: "addItem";
|
|
10
|
+
params: import("xstate").NonReducibleUnknown;
|
|
11
|
+
} | {
|
|
12
|
+
type: "removeItem";
|
|
13
|
+
params: import("xstate").NonReducibleUnknown;
|
|
14
|
+
}, {
|
|
15
|
+
type: "itemHasTimeout";
|
|
16
|
+
params: unknown;
|
|
17
|
+
}, "ITEM_TIMEOUT", {}, string, {
|
|
18
|
+
initialContext: Partial<import("./types").ToastMachineContext>;
|
|
19
|
+
initialState?: string | undefined;
|
|
20
|
+
}, import("xstate").NonReducibleUnknown, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, import("./types").AddItemEvent | import("./types").RemoveItemEvent | import("./types").SetIdleEvent | import("./types").SetActiveEvent | import("./types").ResumeTimerEvent | import("./types").PauseTimerEvent | import("./types").TimerDoneEvent, {
|
|
21
|
+
src: string;
|
|
22
|
+
logic: import("xstate").UnknownActorLogic;
|
|
23
|
+
id: string | undefined;
|
|
24
|
+
}, {
|
|
25
|
+
type: "addItem";
|
|
26
|
+
params: import("xstate").NonReducibleUnknown;
|
|
27
|
+
} | {
|
|
28
|
+
type: "removeItem";
|
|
29
|
+
params: import("xstate").NonReducibleUnknown;
|
|
30
|
+
}, {
|
|
31
|
+
type: "itemHasTimeout";
|
|
32
|
+
params: unknown;
|
|
33
|
+
}, "ITEM_TIMEOUT", string>>>>;
|
|
34
|
+
export declare const useToast: () => Actor<import("xstate").StateMachine<import("./types").ToastMachineContext, import("./types").AddItemEvent | import("./types").RemoveItemEvent | import("./types").SetIdleEvent | import("./types").SetActiveEvent | import("./types").ResumeTimerEvent | import("./types").PauseTimerEvent | import("./types").TimerDoneEvent, Record<string, import("xstate").AnyActorRef>, {
|
|
35
|
+
src: string;
|
|
36
|
+
logic: import("xstate").UnknownActorLogic;
|
|
37
|
+
id: string | undefined;
|
|
38
|
+
}, {
|
|
39
|
+
type: "addItem";
|
|
40
|
+
params: import("xstate").NonReducibleUnknown;
|
|
41
|
+
} | {
|
|
42
|
+
type: "removeItem";
|
|
43
|
+
params: import("xstate").NonReducibleUnknown;
|
|
44
|
+
}, {
|
|
45
|
+
type: "itemHasTimeout";
|
|
46
|
+
params: unknown;
|
|
47
|
+
}, "ITEM_TIMEOUT", {}, string, {
|
|
48
|
+
initialContext: Partial<import("./types").ToastMachineContext>;
|
|
49
|
+
initialState?: string | undefined;
|
|
50
|
+
}, import("xstate").NonReducibleUnknown, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, import("./types").AddItemEvent | import("./types").RemoveItemEvent | import("./types").SetIdleEvent | import("./types").SetActiveEvent | import("./types").ResumeTimerEvent | import("./types").PauseTimerEvent | import("./types").TimerDoneEvent, {
|
|
51
|
+
src: string;
|
|
52
|
+
logic: import("xstate").UnknownActorLogic;
|
|
53
|
+
id: string | undefined;
|
|
54
|
+
}, {
|
|
55
|
+
type: "addItem";
|
|
56
|
+
params: import("xstate").NonReducibleUnknown;
|
|
57
|
+
} | {
|
|
58
|
+
type: "removeItem";
|
|
59
|
+
params: import("xstate").NonReducibleUnknown;
|
|
60
|
+
}, {
|
|
61
|
+
type: "itemHasTimeout";
|
|
62
|
+
params: unknown;
|
|
63
|
+
}, "ITEM_TIMEOUT", string>>>;
|
|
12
64
|
type Props = {
|
|
13
65
|
children: ReactNode;
|
|
14
|
-
|
|
66
|
+
actor: Actor<typeof toastMachine>;
|
|
15
67
|
};
|
|
16
|
-
export declare function ToastProvider({ children,
|
|
68
|
+
export declare function ToastProvider({ children, actor, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
17
69
|
export {};
|
package/src/toast/timer.d.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} | {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
type:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
},
|
|
1
|
+
import { TimerContext, TimerTickEvent } from './types';
|
|
2
|
+
export declare const timerMachine: import("xstate").StateMachine<TimerContext, import("./types").StartTimerEvent | import("./types").ResumeTimerEvent | import("./types").PauseTimerEvent | TimerTickEvent | import("./types").TimerDurationUpdateEvent | import("./types").ResetTimerEvent, Record<string, import("xstate").AnyActorRef>, {
|
|
3
|
+
src: string;
|
|
4
|
+
logic: import("xstate").UnknownActorLogic;
|
|
5
|
+
id: string | undefined;
|
|
6
|
+
}, {
|
|
7
|
+
type: string;
|
|
8
|
+
params: import("xstate").NonReducibleUnknown;
|
|
9
|
+
}, {
|
|
10
|
+
type: string;
|
|
11
|
+
params: import("xstate").NonReducibleUnknown;
|
|
12
|
+
}, string, "running" | "paused" | "completed", string, {
|
|
13
|
+
initialContext: Partial<TimerContext>;
|
|
14
|
+
initialState?: string | undefined;
|
|
15
|
+
}, import("xstate").NonReducibleUnknown, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, import("./types").StartTimerEvent | import("./types").ResumeTimerEvent | import("./types").PauseTimerEvent | TimerTickEvent | import("./types").TimerDurationUpdateEvent | import("./types").ResetTimerEvent, {
|
|
16
|
+
src: string;
|
|
17
|
+
logic: import("xstate").UnknownActorLogic;
|
|
18
|
+
id: string | undefined;
|
|
19
|
+
}, {
|
|
20
|
+
type: string;
|
|
21
|
+
params: import("xstate").NonReducibleUnknown;
|
|
22
|
+
}, {
|
|
23
|
+
type: string;
|
|
24
|
+
params: import("xstate").NonReducibleUnknown;
|
|
25
|
+
}, string, string>>;
|
|
26
26
|
export default timerMachine;
|
package/src/toast/toast.d.ts
CHANGED
|
@@ -1,46 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
id: string |
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
export interface PauseTimerEvent {
|
|
34
|
-
type: 'PAUSE_TIMER';
|
|
35
|
-
}
|
|
36
|
-
export interface TimeoutEvent {
|
|
37
|
-
type: 'xstate.after(ITEM_TIMEOUT)#toast.active';
|
|
38
|
-
}
|
|
39
|
-
export interface TimerDoneEvent {
|
|
40
|
-
type: 'done.invoke.timer';
|
|
41
|
-
}
|
|
42
|
-
export type ToastMachineEvents = AddItemEvent | RemoveItemEvent | SetIdleEvent | SetActiveEvent | TimeoutEvent | ResumeTimerEvent | PauseTimerEvent | TimerDoneEvent;
|
|
43
|
-
export declare const toastMachine: import("xstate").StateMachine<ToastMachineContext, any, ToastMachineEvents, {
|
|
44
|
-
value: any;
|
|
45
|
-
context: ToastMachineContext;
|
|
46
|
-
}, import("xstate").BaseActionObject, import("xstate").ServiceMap, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, ToastMachineEvents, import("xstate").BaseActionObject, import("xstate").ServiceMap>>;
|
|
1
|
+
import { ToastMachineContext } from './types';
|
|
2
|
+
export declare const toastMachine: import("xstate").StateMachine<ToastMachineContext, import("./types").AddItemEvent | import("./types").RemoveItemEvent | import("./types").SetIdleEvent | import("./types").SetActiveEvent | import("./types").ResumeTimerEvent | import("./types").PauseTimerEvent | import("./types").TimerDoneEvent, Record<string, import("xstate").AnyActorRef>, {
|
|
3
|
+
src: string;
|
|
4
|
+
logic: import("xstate").UnknownActorLogic;
|
|
5
|
+
id: string | undefined;
|
|
6
|
+
}, {
|
|
7
|
+
type: "addItem";
|
|
8
|
+
params: import("xstate").NonReducibleUnknown;
|
|
9
|
+
} | {
|
|
10
|
+
type: "removeItem";
|
|
11
|
+
params: import("xstate").NonReducibleUnknown;
|
|
12
|
+
}, {
|
|
13
|
+
type: "itemHasTimeout";
|
|
14
|
+
params: unknown;
|
|
15
|
+
}, "ITEM_TIMEOUT", {}, string, {
|
|
16
|
+
initialContext: Partial<ToastMachineContext>;
|
|
17
|
+
initialState?: string | undefined;
|
|
18
|
+
}, import("xstate").NonReducibleUnknown, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, import("./types").AddItemEvent | import("./types").RemoveItemEvent | import("./types").SetIdleEvent | import("./types").SetActiveEvent | import("./types").ResumeTimerEvent | import("./types").PauseTimerEvent | import("./types").TimerDoneEvent, {
|
|
19
|
+
src: string;
|
|
20
|
+
logic: import("xstate").UnknownActorLogic;
|
|
21
|
+
id: string | undefined;
|
|
22
|
+
}, {
|
|
23
|
+
type: "addItem";
|
|
24
|
+
params: import("xstate").NonReducibleUnknown;
|
|
25
|
+
} | {
|
|
26
|
+
type: "removeItem";
|
|
27
|
+
params: import("xstate").NonReducibleUnknown;
|
|
28
|
+
}, {
|
|
29
|
+
type: "itemHasTimeout";
|
|
30
|
+
params: unknown;
|
|
31
|
+
}, "ITEM_TIMEOUT", string>>;
|
|
32
|
+
export default toastMachine;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ReactElement, ReactNode } from 'react';
|
|
3
|
+
/** @todo figure out TS here */
|
|
4
|
+
export type ToastItem = {
|
|
5
|
+
id: string | null;
|
|
6
|
+
duration: number;
|
|
7
|
+
element: ReactNode;
|
|
8
|
+
};
|
|
9
|
+
export interface ToastMachineContext {
|
|
10
|
+
/** @todo create proper type for Array items */
|
|
11
|
+
items: Array<ToastItem>;
|
|
12
|
+
order: 'asc' | 'desc';
|
|
13
|
+
duration: number;
|
|
14
|
+
activeItem: string | null;
|
|
15
|
+
}
|
|
16
|
+
export interface AddItemEvent {
|
|
17
|
+
type: 'ADD_ITEM';
|
|
18
|
+
item: ReactElement;
|
|
19
|
+
duration?: number;
|
|
20
|
+
}
|
|
21
|
+
export interface RemoveItemEvent {
|
|
22
|
+
type: 'REMOVE_ITEM';
|
|
23
|
+
}
|
|
24
|
+
export interface SetIdleEvent {
|
|
25
|
+
type: 'SET_IDLE';
|
|
26
|
+
}
|
|
27
|
+
export interface SetActiveEvent {
|
|
28
|
+
type: 'SET_ACTIVE';
|
|
29
|
+
}
|
|
30
|
+
export interface ResumeTimerEvent {
|
|
31
|
+
type: 'RESUME_TIMER';
|
|
32
|
+
}
|
|
33
|
+
export interface PauseTimerEvent {
|
|
34
|
+
type: 'PAUSE_TIMER';
|
|
35
|
+
}
|
|
36
|
+
export interface TimerDoneEvent {
|
|
37
|
+
type: 'xstate.done.actor.timer';
|
|
38
|
+
}
|
|
39
|
+
export type ToastMachineEvents = AddItemEvent | RemoveItemEvent | SetIdleEvent | SetActiveEvent | ResumeTimerEvent | PauseTimerEvent | TimerDoneEvent;
|
|
40
|
+
export interface TimerContext {
|
|
41
|
+
elapsed: number;
|
|
42
|
+
duration: number;
|
|
43
|
+
interval: number;
|
|
44
|
+
intervalId: NodeJS.Timer | null;
|
|
45
|
+
}
|
|
46
|
+
export type StartTimerEvent = {
|
|
47
|
+
type: 'START_TIMER';
|
|
48
|
+
};
|
|
49
|
+
export type TimerTickEvent = {
|
|
50
|
+
type: 'TICK';
|
|
51
|
+
};
|
|
52
|
+
export type TimerDurationUpdateEvent = {
|
|
53
|
+
type: 'DURATION.UPDATE';
|
|
54
|
+
value: number;
|
|
55
|
+
};
|
|
56
|
+
export type ResetTimerEvent = {
|
|
57
|
+
type: 'RESET_TIMER';
|
|
58
|
+
};
|
|
59
|
+
export type TimerEvents = StartTimerEvent | ResumeTimerEvent | PauseTimerEvent | TimerTickEvent | TimerDurationUpdateEvent | ResetTimerEvent;
|