@zag-js/toast 0.0.0-dev-20220713183215 → 0.0.0-dev-20220730065001
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/LICENSE +21 -0
- package/dist/index.d.ts +198 -8
- package/dist/index.js +57 -88
- package/dist/index.mjs +51 -92
- package/package.json +12 -11
- package/dist/toast-group.connect.d.ts +0 -24
- package/dist/toast-group.machine.d.ts +0 -2
- package/dist/toast.connect.d.ts +0 -17
- package/dist/toast.dom.d.ts +0 -26
- package/dist/toast.machine.d.ts +0 -2
- package/dist/toast.types.d.ts +0 -154
- package/dist/toast.utils.d.ts +0 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Chakra UI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,201 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import * as _zag_js_core from '@zag-js/core';
|
|
2
|
+
import { Machine, StateMachine } from '@zag-js/core';
|
|
3
|
+
import { RootProperties, CommonProperties, Direction, DirectionProperty, Context, RequiredBy, PropTypes, NormalizeProps } from '@zag-js/types';
|
|
4
|
+
|
|
5
|
+
declare type Type = "success" | "error" | "loading" | "info" | "custom";
|
|
6
|
+
declare type Placement = "top-start" | "top" | "top-end" | "bottom-start" | "bottom" | "bottom-end";
|
|
7
|
+
declare type SharedContext = {
|
|
8
|
+
/**
|
|
9
|
+
* Whether to pause toast when the user leaves the browser tab
|
|
10
|
+
*/
|
|
11
|
+
pauseOnPageIdle?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Whether to pause the toast when interacted with
|
|
14
|
+
*/
|
|
15
|
+
pauseOnInteraction?: boolean;
|
|
16
|
+
};
|
|
17
|
+
declare type ToastOptions = {
|
|
18
|
+
/**
|
|
19
|
+
* The unique id of the toast
|
|
20
|
+
*/
|
|
21
|
+
id: string;
|
|
22
|
+
/**
|
|
23
|
+
* The type of the toast
|
|
24
|
+
*/
|
|
25
|
+
type: Type;
|
|
26
|
+
/**
|
|
27
|
+
* The placement of the toast
|
|
28
|
+
*/
|
|
29
|
+
placement: Placement;
|
|
30
|
+
/**
|
|
31
|
+
* The message of the toast
|
|
32
|
+
*/
|
|
33
|
+
title?: string;
|
|
34
|
+
/**
|
|
35
|
+
* The description of the toast
|
|
36
|
+
*/
|
|
37
|
+
description?: string;
|
|
38
|
+
/**
|
|
39
|
+
* The duration the toast will be visible
|
|
40
|
+
*/
|
|
41
|
+
duration: number;
|
|
42
|
+
/**
|
|
43
|
+
* Custom function to render the toast element.
|
|
44
|
+
*/
|
|
45
|
+
render?: (options: RenderOptions) => any;
|
|
46
|
+
/**
|
|
47
|
+
* The duration for the toast to kept alive before it is removed.
|
|
48
|
+
* Useful for exit transitions.
|
|
49
|
+
*/
|
|
50
|
+
removeDelay?: number;
|
|
51
|
+
/**
|
|
52
|
+
* Function called when the toast has been closed and removed
|
|
53
|
+
*/
|
|
54
|
+
onClose?: VoidFunction;
|
|
55
|
+
/**
|
|
56
|
+
* Function called when the toast is leaving
|
|
57
|
+
*/
|
|
58
|
+
onClosing?: VoidFunction;
|
|
59
|
+
/**
|
|
60
|
+
* Function called when the toast is shown
|
|
61
|
+
*/
|
|
62
|
+
onOpen?: VoidFunction;
|
|
63
|
+
/**
|
|
64
|
+
* Function called when the toast is updated
|
|
65
|
+
*/
|
|
66
|
+
onUpdate?: VoidFunction;
|
|
67
|
+
};
|
|
68
|
+
declare type Options = Partial<ToastOptions>;
|
|
69
|
+
declare type RenderOptions = Omit<ToastOptions, "render"> & {
|
|
70
|
+
dismiss(): void;
|
|
71
|
+
};
|
|
72
|
+
declare type MachineContext = SharedContext & RootProperties & CommonProperties & Omit<ToastOptions, "removeDelay"> & {
|
|
73
|
+
/**
|
|
74
|
+
* The duration for the toast to kept alive before it is removed.
|
|
75
|
+
* Useful for exit transitions.
|
|
76
|
+
*/
|
|
77
|
+
removeDelay: number;
|
|
78
|
+
/**
|
|
79
|
+
* The document's text/writing direction.
|
|
80
|
+
*/
|
|
81
|
+
dir?: Direction;
|
|
82
|
+
/**
|
|
83
|
+
* The time the toast was created
|
|
84
|
+
*/
|
|
85
|
+
createdAt: number;
|
|
86
|
+
/**
|
|
87
|
+
* The time left before the toast is removed
|
|
88
|
+
*/
|
|
89
|
+
remaining: number;
|
|
90
|
+
};
|
|
91
|
+
declare type MachineState = {
|
|
92
|
+
value: "active" | "active:temp" | "dismissing" | "inactive" | "persist";
|
|
93
|
+
tags: "visible" | "paused" | "updating";
|
|
94
|
+
};
|
|
95
|
+
declare type State = StateMachine.State<MachineContext, MachineState>;
|
|
96
|
+
declare type Send = StateMachine.Send;
|
|
97
|
+
declare type Service = Machine<MachineContext, MachineState>;
|
|
98
|
+
declare type GroupPublicContext = SharedContext & DirectionProperty & CommonProperties & {
|
|
99
|
+
/**
|
|
100
|
+
* The gutter or spacing between toasts
|
|
101
|
+
*/
|
|
102
|
+
gutter: string;
|
|
103
|
+
/**
|
|
104
|
+
* The z-index applied to each toast group
|
|
105
|
+
*/
|
|
106
|
+
zIndex: number;
|
|
107
|
+
/**
|
|
108
|
+
* The maximum number of toasts that can be shown at once
|
|
109
|
+
*/
|
|
110
|
+
max: number;
|
|
111
|
+
/**
|
|
112
|
+
* The offset from the safe environment edge of the viewport
|
|
113
|
+
*/
|
|
114
|
+
offsets: string | Record<"left" | "right" | "bottom" | "top", string>;
|
|
115
|
+
};
|
|
116
|
+
declare type UserDefinedGroupContext = RequiredBy<GroupPublicContext, "id">;
|
|
117
|
+
declare type GroupComputedContext = Readonly<{
|
|
118
|
+
/**
|
|
119
|
+
* @computed
|
|
120
|
+
* The total number of toasts in the group
|
|
121
|
+
*/
|
|
122
|
+
readonly count: number;
|
|
123
|
+
}>;
|
|
124
|
+
declare type GroupPrivateContext = Context<{}>;
|
|
125
|
+
declare type GroupMachineContext = GroupPublicContext & GroupComputedContext & GroupPrivateContext;
|
|
126
|
+
declare type GroupState = StateMachine.State<GroupMachineContext>;
|
|
127
|
+
declare type GroupSend = (event: StateMachine.Event<StateMachine.AnyEventObject>) => void;
|
|
128
|
+
declare type MaybeFunction<Value, Args> = Value | ((arg: Args) => Value);
|
|
129
|
+
declare type PromiseOptions<Value> = {
|
|
130
|
+
loading: ToastOptions;
|
|
131
|
+
success: MaybeFunction<ToastOptions, Value>;
|
|
132
|
+
error: MaybeFunction<ToastOptions, Error>;
|
|
133
|
+
};
|
|
134
|
+
declare type GroupProps = {
|
|
135
|
+
placement: Placement;
|
|
136
|
+
label?: string;
|
|
137
|
+
};
|
|
138
|
+
declare type Toaster = {
|
|
139
|
+
count: number;
|
|
140
|
+
isVisible(id: string): boolean;
|
|
141
|
+
upsert(options: ToastOptions): string | undefined;
|
|
142
|
+
create(options: ToastOptions): string | undefined;
|
|
143
|
+
success(options: ToastOptions): string | undefined;
|
|
144
|
+
error(options: ToastOptions): string | undefined;
|
|
145
|
+
loading(options: ToastOptions): string | undefined;
|
|
146
|
+
dismiss(id?: string | undefined): void;
|
|
147
|
+
remove(id?: string | undefined): void;
|
|
148
|
+
promise<T>(promise: Promise<T>, options: PromiseOptions<T>, shared?: ToastOptions): Promise<T>;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
declare function groupConnect<T extends PropTypes>(state: GroupState, send: GroupSend, normalize: NormalizeProps<T>): {
|
|
152
|
+
count: number;
|
|
153
|
+
toasts: Service[];
|
|
154
|
+
toastsByPlacement: Partial<Record<Placement, Service[]>>;
|
|
155
|
+
isVisible(id: string): boolean;
|
|
156
|
+
create(options: Options): string | undefined;
|
|
157
|
+
upsert(options: Options): string | undefined;
|
|
158
|
+
dismiss(id?: string): void;
|
|
159
|
+
remove(id?: string): void;
|
|
160
|
+
dismissByPlacement(placement: Placement): void;
|
|
161
|
+
update(id: string, options: Options): string | undefined;
|
|
162
|
+
loading(options: Options): string | undefined;
|
|
163
|
+
success(options: Options): string | undefined;
|
|
164
|
+
error(options: Options): string | undefined;
|
|
165
|
+
promise<T_1>(promise: Promise<T_1>, options: PromiseOptions<T_1>, shared?: Options): Promise<T_1>;
|
|
166
|
+
pause(id?: string): void;
|
|
167
|
+
resume(id?: string): void;
|
|
168
|
+
getGroupProps(options: GroupProps): T["element"];
|
|
169
|
+
createPortal(): HTMLElement;
|
|
170
|
+
subscribe(fn: (toasts: GroupMachineContext["toasts"]) => void): () => void;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
declare function groupMachine(ctx: UserDefinedGroupContext): _zag_js_core.Machine<GroupMachineContext, _zag_js_core.StateMachine.StateSchema, _zag_js_core.StateMachine.AnyEventObject>;
|
|
174
|
+
|
|
175
|
+
declare function createToastMachine(options?: Options): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
|
|
176
|
+
|
|
177
|
+
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
|
|
178
|
+
type: Type;
|
|
179
|
+
title: string | undefined;
|
|
180
|
+
description: string | undefined;
|
|
181
|
+
placement: Placement;
|
|
182
|
+
isVisible: boolean;
|
|
183
|
+
isPaused: boolean;
|
|
184
|
+
pause(): void;
|
|
185
|
+
resume(): void;
|
|
186
|
+
dismiss(): void;
|
|
187
|
+
rootProps: T["element"];
|
|
188
|
+
progressbarProps: T["element"];
|
|
189
|
+
titleProps: T["element"];
|
|
190
|
+
descriptionProps: T["element"];
|
|
191
|
+
closeButtonProps: T["button"];
|
|
192
|
+
render(): any;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
declare const group: {
|
|
8
196
|
connect: typeof groupConnect;
|
|
9
197
|
machine: typeof groupMachine;
|
|
10
198
|
};
|
|
11
|
-
|
|
199
|
+
declare function api(): Toaster | undefined;
|
|
200
|
+
|
|
201
|
+
export { GroupMachineContext, MachineContext, MachineState, Placement, Service, Type, api, connect, createToastMachine as createMachine, group };
|
package/dist/index.js
CHANGED
|
@@ -1,37 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
-
var __spreadValues = (a, b) => {
|
|
12
|
-
for (var prop in b || (b = {}))
|
|
13
|
-
if (__hasOwnProp.call(b, prop))
|
|
14
|
-
__defNormalProp(a, prop, b[prop]);
|
|
15
|
-
if (__getOwnPropSymbols)
|
|
16
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
-
if (__propIsEnum.call(b, prop))
|
|
18
|
-
__defNormalProp(a, prop, b[prop]);
|
|
19
|
-
}
|
|
20
|
-
return a;
|
|
21
|
-
};
|
|
22
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
-
var __objRest = (source, exclude) => {
|
|
24
|
-
var target = {};
|
|
25
|
-
for (var prop in source)
|
|
26
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
27
|
-
target[prop] = source[prop];
|
|
28
|
-
if (source != null && __getOwnPropSymbols)
|
|
29
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
30
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
31
|
-
target[prop] = source[prop];
|
|
32
|
-
}
|
|
33
|
-
return target;
|
|
34
|
-
};
|
|
35
6
|
var __export = (target, all) => {
|
|
36
7
|
for (var name in all)
|
|
37
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -57,29 +28,13 @@ __export(src_exports, {
|
|
|
57
28
|
module.exports = __toCommonJS(src_exports);
|
|
58
29
|
|
|
59
30
|
// ../../utilities/dom/dist/index.mjs
|
|
60
|
-
var __defProp2 = Object.defineProperty;
|
|
61
|
-
var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
|
|
62
|
-
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
63
|
-
var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
|
|
64
|
-
var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
65
|
-
var __spreadValues2 = (a, b) => {
|
|
66
|
-
for (var prop in b || (b = {}))
|
|
67
|
-
if (__hasOwnProp2.call(b, prop))
|
|
68
|
-
__defNormalProp2(a, prop, b[prop]);
|
|
69
|
-
if (__getOwnPropSymbols2)
|
|
70
|
-
for (var prop of __getOwnPropSymbols2(b)) {
|
|
71
|
-
if (__propIsEnum2.call(b, prop))
|
|
72
|
-
__defNormalProp2(a, prop, b[prop]);
|
|
73
|
-
}
|
|
74
|
-
return a;
|
|
75
|
-
};
|
|
76
31
|
var dataAttr = (guard) => {
|
|
77
32
|
return guard ? "" : void 0;
|
|
78
33
|
};
|
|
79
34
|
var MAX_Z_INDEX = 2147483647;
|
|
80
35
|
var runIfFn = (v, ...a) => {
|
|
81
36
|
const res = typeof v === "function" ? v(...a) : v;
|
|
82
|
-
return res
|
|
37
|
+
return res ?? void 0;
|
|
83
38
|
};
|
|
84
39
|
var cast = (v) => v;
|
|
85
40
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
@@ -91,28 +46,27 @@ function isWindow(value) {
|
|
|
91
46
|
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
92
47
|
}
|
|
93
48
|
function getDocument(el) {
|
|
94
|
-
var _a;
|
|
95
49
|
if (isWindow(el))
|
|
96
50
|
return el.document;
|
|
97
51
|
if (isDocument(el))
|
|
98
52
|
return el;
|
|
99
|
-
return (
|
|
53
|
+
return (el == null ? void 0 : el.ownerDocument) ?? document;
|
|
100
54
|
}
|
|
101
55
|
function defineDomHelpers(helpers) {
|
|
102
56
|
const dom2 = {
|
|
103
57
|
getRootNode: (ctx) => {
|
|
104
|
-
var _a, _b;
|
|
105
|
-
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
106
|
-
},
|
|
107
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
108
|
-
getWin: (ctx) => {
|
|
109
58
|
var _a;
|
|
110
|
-
return (_a =
|
|
59
|
+
return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
|
|
111
60
|
},
|
|
61
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
62
|
+
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
112
63
|
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
113
64
|
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
114
65
|
};
|
|
115
|
-
return
|
|
66
|
+
return {
|
|
67
|
+
...dom2,
|
|
68
|
+
...helpers
|
|
69
|
+
};
|
|
116
70
|
}
|
|
117
71
|
var isRef = (v) => hasProp(v, "current");
|
|
118
72
|
function addDomEvent(target, eventName, handler, options) {
|
|
@@ -133,7 +87,7 @@ function trackDocumentVisibility(_doc, callback) {
|
|
|
133
87
|
// ../../utilities/core/dist/index.mjs
|
|
134
88
|
var runIfFn2 = (v, ...a) => {
|
|
135
89
|
const res = typeof v === "function" ? v(...a) : v;
|
|
136
|
-
return res
|
|
90
|
+
return res ?? void 0;
|
|
137
91
|
};
|
|
138
92
|
var uuid = /* @__PURE__ */ (() => {
|
|
139
93
|
let id = 0;
|
|
@@ -145,7 +99,7 @@ var uuid = /* @__PURE__ */ (() => {
|
|
|
145
99
|
function warn(...a) {
|
|
146
100
|
const m = a.length === 1 ? a[0] : a[1];
|
|
147
101
|
const c = a.length === 2 ? a[0] : true;
|
|
148
|
-
if (c &&
|
|
102
|
+
if (c && process.env.NODE_ENV !== "production") {
|
|
149
103
|
console.warn(m);
|
|
150
104
|
}
|
|
151
105
|
}
|
|
@@ -158,6 +112,7 @@ var dom = defineDomHelpers({
|
|
|
158
112
|
getGroupId: (placement) => `toast-group:${placement}`,
|
|
159
113
|
getContainerId: (ctx) => `toast:${ctx.id}`,
|
|
160
114
|
getTitleId: (ctx) => `toast-title:${ctx.id}`,
|
|
115
|
+
getDescriptionId: (ctx) => `toast-description:${ctx.id}`,
|
|
161
116
|
getCloseButtonId: (ctx) => `toast-close-button:${ctx.id}`,
|
|
162
117
|
getPortalId: (ctx) => `toast-portal:${ctx.id}`,
|
|
163
118
|
getPortalEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getPortalId(ctx)),
|
|
@@ -189,7 +144,7 @@ var defaultTimeouts = {
|
|
|
189
144
|
custom: 5e3
|
|
190
145
|
};
|
|
191
146
|
function getToastDuration(duration, type) {
|
|
192
|
-
return duration
|
|
147
|
+
return duration ?? defaultTimeouts[type];
|
|
193
148
|
}
|
|
194
149
|
function getGroupPlacementStyle(ctx, placement) {
|
|
195
150
|
const offset = ctx.offsets;
|
|
@@ -248,7 +203,7 @@ function groupConnect(state, send, normalize) {
|
|
|
248
203
|
const id = options.id ? options.id : uid;
|
|
249
204
|
if (group2.isVisible(id))
|
|
250
205
|
return;
|
|
251
|
-
send({ type: "ADD_TOAST", toast:
|
|
206
|
+
send({ type: "ADD_TOAST", toast: { ...options, id } });
|
|
252
207
|
return id;
|
|
253
208
|
},
|
|
254
209
|
upsert(options) {
|
|
@@ -299,13 +254,13 @@ function groupConnect(state, send, normalize) {
|
|
|
299
254
|
return group2.upsert(options);
|
|
300
255
|
},
|
|
301
256
|
promise(promise, options, shared = {}) {
|
|
302
|
-
const id = group2.loading(
|
|
257
|
+
const id = group2.loading({ ...shared, ...options.loading });
|
|
303
258
|
promise.then((response) => {
|
|
304
259
|
const successOptions = runIfFn2(options.success, response);
|
|
305
|
-
group2.success(
|
|
260
|
+
group2.success({ ...shared, ...successOptions, id });
|
|
306
261
|
}).catch((error) => {
|
|
307
262
|
const errorOptions = runIfFn2(options.error, error);
|
|
308
|
-
group2.error(
|
|
263
|
+
group2.error({ ...shared, ...errorOptions, id });
|
|
309
264
|
});
|
|
310
265
|
return promise;
|
|
311
266
|
},
|
|
@@ -361,21 +316,22 @@ var import_core3 = require("@zag-js/core");
|
|
|
361
316
|
var import_core2 = require("@zag-js/core");
|
|
362
317
|
var { not, and, or } = import_core2.guards;
|
|
363
318
|
function createToastMachine(options = {}) {
|
|
364
|
-
const
|
|
319
|
+
const { type = "info", duration, id = "toast", placement = "bottom", removeDelay = 500, ...rest } = options;
|
|
365
320
|
const __duration = getToastDuration(duration, type);
|
|
366
321
|
return (0, import_core2.createMachine)({
|
|
367
322
|
id,
|
|
368
323
|
entry: "invokeOnOpen",
|
|
369
324
|
initial: type === "loading" ? "persist" : "active",
|
|
370
|
-
context:
|
|
325
|
+
context: {
|
|
371
326
|
id,
|
|
372
327
|
type,
|
|
373
328
|
remaining: __duration,
|
|
374
329
|
duration: __duration,
|
|
375
330
|
removeDelay,
|
|
376
331
|
createdAt: Date.now(),
|
|
377
|
-
placement
|
|
378
|
-
|
|
332
|
+
placement,
|
|
333
|
+
...rest
|
|
334
|
+
},
|
|
379
335
|
on: {
|
|
380
336
|
UPDATE: [
|
|
381
337
|
{
|
|
@@ -452,17 +408,17 @@ function createToastMachine(options = {}) {
|
|
|
452
408
|
},
|
|
453
409
|
guards: {
|
|
454
410
|
isChangingToLoading: (_, evt) => {
|
|
455
|
-
var
|
|
456
|
-
return ((
|
|
411
|
+
var _a;
|
|
412
|
+
return ((_a = evt.toast) == null ? void 0 : _a.type) === "loading";
|
|
457
413
|
},
|
|
458
414
|
isLoadingType: (ctx) => ctx.type === "loading",
|
|
459
415
|
hasTypeChanged: (ctx, evt) => {
|
|
460
|
-
var
|
|
461
|
-
return ((
|
|
416
|
+
var _a;
|
|
417
|
+
return ((_a = evt.toast) == null ? void 0 : _a.type) !== ctx.type;
|
|
462
418
|
},
|
|
463
419
|
hasDurationChanged: (ctx, evt) => {
|
|
464
|
-
var
|
|
465
|
-
return ((
|
|
420
|
+
var _a;
|
|
421
|
+
return ((_a = evt.toast) == null ? void 0 : _a.duration) !== ctx.duration;
|
|
466
422
|
}
|
|
467
423
|
},
|
|
468
424
|
delays: {
|
|
@@ -480,25 +436,25 @@ function createToastMachine(options = {}) {
|
|
|
480
436
|
self.sendParent({ type: "REMOVE_TOAST", id: self.id });
|
|
481
437
|
},
|
|
482
438
|
invokeOnClosing(ctx) {
|
|
483
|
-
var
|
|
484
|
-
(
|
|
439
|
+
var _a;
|
|
440
|
+
(_a = ctx.onClosing) == null ? void 0 : _a.call(ctx);
|
|
485
441
|
},
|
|
486
442
|
invokeOnClose(ctx) {
|
|
487
|
-
var
|
|
488
|
-
(
|
|
443
|
+
var _a;
|
|
444
|
+
(_a = ctx.onClose) == null ? void 0 : _a.call(ctx);
|
|
489
445
|
},
|
|
490
446
|
invokeOnOpen(ctx) {
|
|
491
|
-
var
|
|
492
|
-
(
|
|
447
|
+
var _a;
|
|
448
|
+
(_a = ctx.onOpen) == null ? void 0 : _a.call(ctx);
|
|
493
449
|
},
|
|
494
450
|
invokeOnUpdate(ctx) {
|
|
495
|
-
var
|
|
496
|
-
(
|
|
451
|
+
var _a;
|
|
452
|
+
(_a = ctx.onUpdate) == null ? void 0 : _a.call(ctx);
|
|
497
453
|
},
|
|
498
454
|
setContext(ctx, evt) {
|
|
499
455
|
const { duration: duration2, type: type2 } = evt.toast;
|
|
500
456
|
const time = getToastDuration(duration2, type2);
|
|
501
|
-
Object.assign(ctx,
|
|
457
|
+
Object.assign(ctx, { ...evt.toast, duration: time, remaining: time });
|
|
502
458
|
}
|
|
503
459
|
}
|
|
504
460
|
});
|
|
@@ -509,7 +465,7 @@ function groupMachine(ctx) {
|
|
|
509
465
|
return (0, import_core3.createMachine)({
|
|
510
466
|
id: "toaster",
|
|
511
467
|
initial: "active",
|
|
512
|
-
context:
|
|
468
|
+
context: {
|
|
513
469
|
dir: "ltr",
|
|
514
470
|
max: Number.MAX_SAFE_INTEGER,
|
|
515
471
|
toasts: [],
|
|
@@ -517,8 +473,9 @@ function groupMachine(ctx) {
|
|
|
517
473
|
zIndex: MAX_Z_INDEX,
|
|
518
474
|
pauseOnPageIdle: false,
|
|
519
475
|
pauseOnInteraction: true,
|
|
520
|
-
offsets: { left: "0px", right: "0px", top: "0px", bottom: "0px" }
|
|
521
|
-
|
|
476
|
+
offsets: { left: "0px", right: "0px", top: "0px", bottom: "0px" },
|
|
477
|
+
...ctx
|
|
478
|
+
},
|
|
522
479
|
computed: {
|
|
523
480
|
count: (ctx2) => ctx2.toasts.length
|
|
524
481
|
},
|
|
@@ -547,13 +504,13 @@ function groupMachine(ctx) {
|
|
|
547
504
|
ADD_TOAST: {
|
|
548
505
|
guard: (ctx2) => ctx2.toasts.length < ctx2.max,
|
|
549
506
|
actions: (ctx2, evt, { self }) => {
|
|
550
|
-
|
|
551
|
-
|
|
507
|
+
const options = {
|
|
508
|
+
...evt.toast,
|
|
552
509
|
pauseOnPageIdle: ctx2.pauseOnPageIdle,
|
|
553
510
|
pauseOnInteraction: ctx2.pauseOnInteraction,
|
|
554
511
|
dir: ctx2.dir,
|
|
555
|
-
|
|
556
|
-
}
|
|
512
|
+
getRootNode: ctx2.getRootNode
|
|
513
|
+
};
|
|
557
514
|
const toast = createToastMachine(options);
|
|
558
515
|
const actor = self.spawn(toast);
|
|
559
516
|
ctx2.toasts.push(actor);
|
|
@@ -604,6 +561,7 @@ function connect(state, send, normalize) {
|
|
|
604
561
|
return {
|
|
605
562
|
type: state.context.type,
|
|
606
563
|
title: state.context.title,
|
|
564
|
+
description: state.context.description,
|
|
607
565
|
placement,
|
|
608
566
|
isVisible,
|
|
609
567
|
isPaused,
|
|
@@ -676,6 +634,10 @@ function connect(state, send, normalize) {
|
|
|
676
634
|
"data-part": "title",
|
|
677
635
|
id: dom.getTitleId(state.context)
|
|
678
636
|
}),
|
|
637
|
+
descriptionProps: normalize.element({
|
|
638
|
+
"data-part": "description",
|
|
639
|
+
id: dom.getDescriptionId(state.context)
|
|
640
|
+
}),
|
|
679
641
|
closeButtonProps: normalize.button({
|
|
680
642
|
id: dom.getCloseButtonId(state.context),
|
|
681
643
|
"data-part": "close-button",
|
|
@@ -714,3 +676,10 @@ function api() {
|
|
|
714
676
|
return toaster;
|
|
715
677
|
}
|
|
716
678
|
}
|
|
679
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
680
|
+
0 && (module.exports = {
|
|
681
|
+
api,
|
|
682
|
+
connect,
|
|
683
|
+
createMachine,
|
|
684
|
+
group
|
|
685
|
+
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,59 +1,11 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __objRest = (source, exclude) => {
|
|
21
|
-
var target = {};
|
|
22
|
-
for (var prop in source)
|
|
23
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
-
target[prop] = source[prop];
|
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
1
|
// ../../utilities/dom/dist/index.mjs
|
|
34
|
-
var __defProp2 = Object.defineProperty;
|
|
35
|
-
var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
|
|
36
|
-
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
37
|
-
var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
|
|
38
|
-
var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
39
|
-
var __spreadValues2 = (a, b) => {
|
|
40
|
-
for (var prop in b || (b = {}))
|
|
41
|
-
if (__hasOwnProp2.call(b, prop))
|
|
42
|
-
__defNormalProp2(a, prop, b[prop]);
|
|
43
|
-
if (__getOwnPropSymbols2)
|
|
44
|
-
for (var prop of __getOwnPropSymbols2(b)) {
|
|
45
|
-
if (__propIsEnum2.call(b, prop))
|
|
46
|
-
__defNormalProp2(a, prop, b[prop]);
|
|
47
|
-
}
|
|
48
|
-
return a;
|
|
49
|
-
};
|
|
50
2
|
var dataAttr = (guard) => {
|
|
51
3
|
return guard ? "" : void 0;
|
|
52
4
|
};
|
|
53
5
|
var MAX_Z_INDEX = 2147483647;
|
|
54
6
|
var runIfFn = (v, ...a) => {
|
|
55
7
|
const res = typeof v === "function" ? v(...a) : v;
|
|
56
|
-
return res
|
|
8
|
+
return res ?? void 0;
|
|
57
9
|
};
|
|
58
10
|
var cast = (v) => v;
|
|
59
11
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
@@ -65,28 +17,27 @@ function isWindow(value) {
|
|
|
65
17
|
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
66
18
|
}
|
|
67
19
|
function getDocument(el) {
|
|
68
|
-
var _a;
|
|
69
20
|
if (isWindow(el))
|
|
70
21
|
return el.document;
|
|
71
22
|
if (isDocument(el))
|
|
72
23
|
return el;
|
|
73
|
-
return (
|
|
24
|
+
return (el == null ? void 0 : el.ownerDocument) ?? document;
|
|
74
25
|
}
|
|
75
26
|
function defineDomHelpers(helpers) {
|
|
76
27
|
const dom2 = {
|
|
77
28
|
getRootNode: (ctx) => {
|
|
78
|
-
var _a, _b;
|
|
79
|
-
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
80
|
-
},
|
|
81
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
82
|
-
getWin: (ctx) => {
|
|
83
29
|
var _a;
|
|
84
|
-
return (_a =
|
|
30
|
+
return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
|
|
85
31
|
},
|
|
32
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
33
|
+
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
86
34
|
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
87
35
|
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
88
36
|
};
|
|
89
|
-
return
|
|
37
|
+
return {
|
|
38
|
+
...dom2,
|
|
39
|
+
...helpers
|
|
40
|
+
};
|
|
90
41
|
}
|
|
91
42
|
var isRef = (v) => hasProp(v, "current");
|
|
92
43
|
function addDomEvent(target, eventName, handler, options) {
|
|
@@ -107,7 +58,7 @@ function trackDocumentVisibility(_doc, callback) {
|
|
|
107
58
|
// ../../utilities/core/dist/index.mjs
|
|
108
59
|
var runIfFn2 = (v, ...a) => {
|
|
109
60
|
const res = typeof v === "function" ? v(...a) : v;
|
|
110
|
-
return res
|
|
61
|
+
return res ?? void 0;
|
|
111
62
|
};
|
|
112
63
|
var uuid = /* @__PURE__ */ (() => {
|
|
113
64
|
let id = 0;
|
|
@@ -119,7 +70,7 @@ var uuid = /* @__PURE__ */ (() => {
|
|
|
119
70
|
function warn(...a) {
|
|
120
71
|
const m = a.length === 1 ? a[0] : a[1];
|
|
121
72
|
const c = a.length === 2 ? a[0] : true;
|
|
122
|
-
if (c &&
|
|
73
|
+
if (c && process.env.NODE_ENV !== "production") {
|
|
123
74
|
console.warn(m);
|
|
124
75
|
}
|
|
125
76
|
}
|
|
@@ -132,6 +83,7 @@ var dom = defineDomHelpers({
|
|
|
132
83
|
getGroupId: (placement) => `toast-group:${placement}`,
|
|
133
84
|
getContainerId: (ctx) => `toast:${ctx.id}`,
|
|
134
85
|
getTitleId: (ctx) => `toast-title:${ctx.id}`,
|
|
86
|
+
getDescriptionId: (ctx) => `toast-description:${ctx.id}`,
|
|
135
87
|
getCloseButtonId: (ctx) => `toast-close-button:${ctx.id}`,
|
|
136
88
|
getPortalId: (ctx) => `toast-portal:${ctx.id}`,
|
|
137
89
|
getPortalEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getPortalId(ctx)),
|
|
@@ -163,7 +115,7 @@ var defaultTimeouts = {
|
|
|
163
115
|
custom: 5e3
|
|
164
116
|
};
|
|
165
117
|
function getToastDuration(duration, type) {
|
|
166
|
-
return duration
|
|
118
|
+
return duration ?? defaultTimeouts[type];
|
|
167
119
|
}
|
|
168
120
|
function getGroupPlacementStyle(ctx, placement) {
|
|
169
121
|
const offset = ctx.offsets;
|
|
@@ -222,7 +174,7 @@ function groupConnect(state, send, normalize) {
|
|
|
222
174
|
const id = options.id ? options.id : uid;
|
|
223
175
|
if (group2.isVisible(id))
|
|
224
176
|
return;
|
|
225
|
-
send({ type: "ADD_TOAST", toast:
|
|
177
|
+
send({ type: "ADD_TOAST", toast: { ...options, id } });
|
|
226
178
|
return id;
|
|
227
179
|
},
|
|
228
180
|
upsert(options) {
|
|
@@ -273,13 +225,13 @@ function groupConnect(state, send, normalize) {
|
|
|
273
225
|
return group2.upsert(options);
|
|
274
226
|
},
|
|
275
227
|
promise(promise, options, shared = {}) {
|
|
276
|
-
const id = group2.loading(
|
|
228
|
+
const id = group2.loading({ ...shared, ...options.loading });
|
|
277
229
|
promise.then((response) => {
|
|
278
230
|
const successOptions = runIfFn2(options.success, response);
|
|
279
|
-
group2.success(
|
|
231
|
+
group2.success({ ...shared, ...successOptions, id });
|
|
280
232
|
}).catch((error) => {
|
|
281
233
|
const errorOptions = runIfFn2(options.error, error);
|
|
282
|
-
group2.error(
|
|
234
|
+
group2.error({ ...shared, ...errorOptions, id });
|
|
283
235
|
});
|
|
284
236
|
return promise;
|
|
285
237
|
},
|
|
@@ -329,27 +281,28 @@ function groupConnect(state, send, normalize) {
|
|
|
329
281
|
}
|
|
330
282
|
|
|
331
283
|
// src/toast-group.machine.ts
|
|
332
|
-
import { createMachine as createMachine2
|
|
284
|
+
import { createMachine as createMachine2 } from "@zag-js/core";
|
|
333
285
|
|
|
334
286
|
// src/toast.machine.ts
|
|
335
287
|
import { createMachine, guards } from "@zag-js/core";
|
|
336
288
|
var { not, and, or } = guards;
|
|
337
289
|
function createToastMachine(options = {}) {
|
|
338
|
-
const
|
|
290
|
+
const { type = "info", duration, id = "toast", placement = "bottom", removeDelay = 500, ...rest } = options;
|
|
339
291
|
const __duration = getToastDuration(duration, type);
|
|
340
292
|
return createMachine({
|
|
341
293
|
id,
|
|
342
294
|
entry: "invokeOnOpen",
|
|
343
295
|
initial: type === "loading" ? "persist" : "active",
|
|
344
|
-
context:
|
|
296
|
+
context: {
|
|
345
297
|
id,
|
|
346
298
|
type,
|
|
347
299
|
remaining: __duration,
|
|
348
300
|
duration: __duration,
|
|
349
301
|
removeDelay,
|
|
350
302
|
createdAt: Date.now(),
|
|
351
|
-
placement
|
|
352
|
-
|
|
303
|
+
placement,
|
|
304
|
+
...rest
|
|
305
|
+
},
|
|
353
306
|
on: {
|
|
354
307
|
UPDATE: [
|
|
355
308
|
{
|
|
@@ -426,17 +379,17 @@ function createToastMachine(options = {}) {
|
|
|
426
379
|
},
|
|
427
380
|
guards: {
|
|
428
381
|
isChangingToLoading: (_, evt) => {
|
|
429
|
-
var
|
|
430
|
-
return ((
|
|
382
|
+
var _a;
|
|
383
|
+
return ((_a = evt.toast) == null ? void 0 : _a.type) === "loading";
|
|
431
384
|
},
|
|
432
385
|
isLoadingType: (ctx) => ctx.type === "loading",
|
|
433
386
|
hasTypeChanged: (ctx, evt) => {
|
|
434
|
-
var
|
|
435
|
-
return ((
|
|
387
|
+
var _a;
|
|
388
|
+
return ((_a = evt.toast) == null ? void 0 : _a.type) !== ctx.type;
|
|
436
389
|
},
|
|
437
390
|
hasDurationChanged: (ctx, evt) => {
|
|
438
|
-
var
|
|
439
|
-
return ((
|
|
391
|
+
var _a;
|
|
392
|
+
return ((_a = evt.toast) == null ? void 0 : _a.duration) !== ctx.duration;
|
|
440
393
|
}
|
|
441
394
|
},
|
|
442
395
|
delays: {
|
|
@@ -454,25 +407,25 @@ function createToastMachine(options = {}) {
|
|
|
454
407
|
self.sendParent({ type: "REMOVE_TOAST", id: self.id });
|
|
455
408
|
},
|
|
456
409
|
invokeOnClosing(ctx) {
|
|
457
|
-
var
|
|
458
|
-
(
|
|
410
|
+
var _a;
|
|
411
|
+
(_a = ctx.onClosing) == null ? void 0 : _a.call(ctx);
|
|
459
412
|
},
|
|
460
413
|
invokeOnClose(ctx) {
|
|
461
|
-
var
|
|
462
|
-
(
|
|
414
|
+
var _a;
|
|
415
|
+
(_a = ctx.onClose) == null ? void 0 : _a.call(ctx);
|
|
463
416
|
},
|
|
464
417
|
invokeOnOpen(ctx) {
|
|
465
|
-
var
|
|
466
|
-
(
|
|
418
|
+
var _a;
|
|
419
|
+
(_a = ctx.onOpen) == null ? void 0 : _a.call(ctx);
|
|
467
420
|
},
|
|
468
421
|
invokeOnUpdate(ctx) {
|
|
469
|
-
var
|
|
470
|
-
(
|
|
422
|
+
var _a;
|
|
423
|
+
(_a = ctx.onUpdate) == null ? void 0 : _a.call(ctx);
|
|
471
424
|
},
|
|
472
425
|
setContext(ctx, evt) {
|
|
473
426
|
const { duration: duration2, type: type2 } = evt.toast;
|
|
474
427
|
const time = getToastDuration(duration2, type2);
|
|
475
|
-
Object.assign(ctx,
|
|
428
|
+
Object.assign(ctx, { ...evt.toast, duration: time, remaining: time });
|
|
476
429
|
}
|
|
477
430
|
}
|
|
478
431
|
});
|
|
@@ -483,7 +436,7 @@ function groupMachine(ctx) {
|
|
|
483
436
|
return createMachine2({
|
|
484
437
|
id: "toaster",
|
|
485
438
|
initial: "active",
|
|
486
|
-
context:
|
|
439
|
+
context: {
|
|
487
440
|
dir: "ltr",
|
|
488
441
|
max: Number.MAX_SAFE_INTEGER,
|
|
489
442
|
toasts: [],
|
|
@@ -491,8 +444,9 @@ function groupMachine(ctx) {
|
|
|
491
444
|
zIndex: MAX_Z_INDEX,
|
|
492
445
|
pauseOnPageIdle: false,
|
|
493
446
|
pauseOnInteraction: true,
|
|
494
|
-
offsets: { left: "0px", right: "0px", top: "0px", bottom: "0px" }
|
|
495
|
-
|
|
447
|
+
offsets: { left: "0px", right: "0px", top: "0px", bottom: "0px" },
|
|
448
|
+
...ctx
|
|
449
|
+
},
|
|
496
450
|
computed: {
|
|
497
451
|
count: (ctx2) => ctx2.toasts.length
|
|
498
452
|
},
|
|
@@ -521,13 +475,13 @@ function groupMachine(ctx) {
|
|
|
521
475
|
ADD_TOAST: {
|
|
522
476
|
guard: (ctx2) => ctx2.toasts.length < ctx2.max,
|
|
523
477
|
actions: (ctx2, evt, { self }) => {
|
|
524
|
-
|
|
525
|
-
|
|
478
|
+
const options = {
|
|
479
|
+
...evt.toast,
|
|
526
480
|
pauseOnPageIdle: ctx2.pauseOnPageIdle,
|
|
527
481
|
pauseOnInteraction: ctx2.pauseOnInteraction,
|
|
528
482
|
dir: ctx2.dir,
|
|
529
|
-
|
|
530
|
-
}
|
|
483
|
+
getRootNode: ctx2.getRootNode
|
|
484
|
+
};
|
|
531
485
|
const toast = createToastMachine(options);
|
|
532
486
|
const actor = self.spawn(toast);
|
|
533
487
|
ctx2.toasts.push(actor);
|
|
@@ -578,6 +532,7 @@ function connect(state, send, normalize) {
|
|
|
578
532
|
return {
|
|
579
533
|
type: state.context.type,
|
|
580
534
|
title: state.context.title,
|
|
535
|
+
description: state.context.description,
|
|
581
536
|
placement,
|
|
582
537
|
isVisible,
|
|
583
538
|
isPaused,
|
|
@@ -650,6 +605,10 @@ function connect(state, send, normalize) {
|
|
|
650
605
|
"data-part": "title",
|
|
651
606
|
id: dom.getTitleId(state.context)
|
|
652
607
|
}),
|
|
608
|
+
descriptionProps: normalize.element({
|
|
609
|
+
"data-part": "description",
|
|
610
|
+
id: dom.getDescriptionId(state.context)
|
|
611
|
+
}),
|
|
653
612
|
closeButtonProps: normalize.button({
|
|
654
613
|
id: dom.getCloseButtonId(state.context),
|
|
655
614
|
"data-part": "close-button",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/toast",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20220730065001",
|
|
4
4
|
"description": "Core logic for the toast widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -29,20 +29,21 @@
|
|
|
29
29
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@zag-js/core": "0.
|
|
33
|
-
"@zag-js/types": "0.
|
|
32
|
+
"@zag-js/core": "0.1.9",
|
|
33
|
+
"@zag-js/types": "0.2.3"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@zag-js/dom-utils": "0.
|
|
37
|
-
"@zag-js/utils": "0.1.
|
|
36
|
+
"@zag-js/dom-utils": "0.1.8",
|
|
37
|
+
"@zag-js/utils": "0.1.3"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
|
-
"build
|
|
41
|
-
"start": "
|
|
42
|
-
"build": "
|
|
40
|
+
"build-fast": "tsup src/index.ts --format=esm,cjs",
|
|
41
|
+
"start": "pnpm build --watch",
|
|
42
|
+
"build": "tsup src/index.ts --format=esm,cjs --dts",
|
|
43
43
|
"test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
|
|
44
44
|
"lint": "eslint src --ext .ts,.tsx",
|
|
45
|
-
"test
|
|
46
|
-
"test
|
|
45
|
+
"test-ci": "pnpm test --ci --runInBand",
|
|
46
|
+
"test-watch": "pnpm test --watch -u",
|
|
47
|
+
"typecheck": "tsc --noEmit"
|
|
47
48
|
}
|
|
48
|
-
}
|
|
49
|
+
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { NormalizeProps, PropTypes } from "@zag-js/types";
|
|
2
|
-
import type { GroupMachineContext, GroupProps, GroupSend, GroupState, Placement, PromiseOptions, Toaster, Options } from "./toast.types";
|
|
3
|
-
export declare let toaster: Toaster;
|
|
4
|
-
export declare function groupConnect<T extends PropTypes>(state: GroupState, send: GroupSend, normalize: NormalizeProps<T>): {
|
|
5
|
-
count: number;
|
|
6
|
-
toasts: import("./toast.types").Service[];
|
|
7
|
-
toastsByPlacement: Partial<Record<Placement, import("./toast.types").Service[]>>;
|
|
8
|
-
isVisible(id: string): boolean;
|
|
9
|
-
create(options: Options): string;
|
|
10
|
-
upsert(options: Options): string;
|
|
11
|
-
dismiss(id?: string): void;
|
|
12
|
-
remove(id?: string): void;
|
|
13
|
-
dismissByPlacement(placement: Placement): void;
|
|
14
|
-
update(id: string, options: Options): string;
|
|
15
|
-
loading(options: Options): string;
|
|
16
|
-
success(options: Options): string;
|
|
17
|
-
error(options: Options): string;
|
|
18
|
-
promise<T_1>(promise: Promise<T_1>, options: PromiseOptions<T_1>, shared?: Options): Promise<T_1>;
|
|
19
|
-
pause(id?: string): void;
|
|
20
|
-
resume(id?: string): void;
|
|
21
|
-
getGroupProps(options: GroupProps): T["element"];
|
|
22
|
-
createPortal(): HTMLElement;
|
|
23
|
-
subscribe(fn: (toasts: GroupMachineContext["toasts"]) => void): () => void;
|
|
24
|
-
};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import type { GroupMachineContext, UserDefinedGroupContext } from "./toast.types";
|
|
2
|
-
export declare function groupMachine(ctx: UserDefinedGroupContext): import("@zag-js/core").Machine<GroupMachineContext, import("@zag-js/core").StateMachine.StateSchema, import("@zag-js/core").StateMachine.AnyEventObject>;
|
package/dist/toast.connect.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { NormalizeProps, PropTypes } from "@zag-js/types";
|
|
2
|
-
import type { Send, State } from "./toast.types";
|
|
3
|
-
export declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
|
|
4
|
-
type: import("./toast.types").Type;
|
|
5
|
-
title: string;
|
|
6
|
-
placement: import("./toast.types").Placement;
|
|
7
|
-
isVisible: boolean;
|
|
8
|
-
isPaused: boolean;
|
|
9
|
-
pause(): void;
|
|
10
|
-
resume(): void;
|
|
11
|
-
dismiss(): void;
|
|
12
|
-
rootProps: T["element"];
|
|
13
|
-
progressbarProps: T["element"];
|
|
14
|
-
titleProps: T["element"];
|
|
15
|
-
closeButtonProps: T["button"];
|
|
16
|
-
render(): any;
|
|
17
|
-
};
|
package/dist/toast.dom.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { GroupMachineContext as GroupCtx, MachineContext as Ctx, Placement } from "./toast.types";
|
|
2
|
-
export declare const dom: {
|
|
3
|
-
getRootNode: (ctx: {
|
|
4
|
-
getRootNode?: () => Node | Document | ShadowRoot;
|
|
5
|
-
}) => Document | ShadowRoot;
|
|
6
|
-
getDoc: (ctx: {
|
|
7
|
-
getRootNode?: () => Node | Document | ShadowRoot;
|
|
8
|
-
}) => Document;
|
|
9
|
-
getWin: (ctx: {
|
|
10
|
-
getRootNode?: () => Node | Document | ShadowRoot;
|
|
11
|
-
}) => Window & typeof globalThis;
|
|
12
|
-
getActiveElement: (ctx: {
|
|
13
|
-
getRootNode?: () => Node | Document | ShadowRoot;
|
|
14
|
-
}) => HTMLElement;
|
|
15
|
-
getById: (ctx: {
|
|
16
|
-
getRootNode?: () => Node | Document | ShadowRoot;
|
|
17
|
-
}, id: string) => HTMLElement;
|
|
18
|
-
} & {
|
|
19
|
-
getGroupId: (placement: Placement) => string;
|
|
20
|
-
getContainerId: (ctx: Ctx) => string;
|
|
21
|
-
getTitleId: (ctx: Ctx) => string;
|
|
22
|
-
getCloseButtonId: (ctx: Ctx) => string;
|
|
23
|
-
getPortalId: (ctx: GroupCtx) => string;
|
|
24
|
-
getPortalEl: (ctx: GroupCtx) => HTMLElement;
|
|
25
|
-
createPortalEl: (ctx: GroupCtx) => HTMLElement;
|
|
26
|
-
};
|
package/dist/toast.machine.d.ts
DELETED
package/dist/toast.types.d.ts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import type { Machine, StateMachine as S } from "@zag-js/core";
|
|
2
|
-
import type { CommonProperties, Context, Direction, DirectionProperty, RequiredBy, RootProperties } from "@zag-js/types";
|
|
3
|
-
export declare type Type = "success" | "error" | "loading" | "info" | "custom";
|
|
4
|
-
export declare type Placement = "top-start" | "top" | "top-end" | "bottom-start" | "bottom" | "bottom-end";
|
|
5
|
-
declare type SharedContext = {
|
|
6
|
-
/**
|
|
7
|
-
* Whether to pause toast when the user leaves the browser tab
|
|
8
|
-
*/
|
|
9
|
-
pauseOnPageIdle?: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Whether to pause the toast when interacted with
|
|
12
|
-
*/
|
|
13
|
-
pauseOnInteraction?: boolean;
|
|
14
|
-
};
|
|
15
|
-
export declare type ToastOptions = {
|
|
16
|
-
/**
|
|
17
|
-
* The unique id of the toast
|
|
18
|
-
*/
|
|
19
|
-
id: string;
|
|
20
|
-
/**
|
|
21
|
-
* The type of the toast
|
|
22
|
-
*/
|
|
23
|
-
type: Type;
|
|
24
|
-
/**
|
|
25
|
-
* The placement of the toast
|
|
26
|
-
*/
|
|
27
|
-
placement: Placement;
|
|
28
|
-
/**
|
|
29
|
-
* The message of the toast
|
|
30
|
-
*/
|
|
31
|
-
title?: string;
|
|
32
|
-
/**
|
|
33
|
-
* The description of the toast
|
|
34
|
-
*/
|
|
35
|
-
description?: string;
|
|
36
|
-
/**
|
|
37
|
-
* The duration the toast will be visible
|
|
38
|
-
*/
|
|
39
|
-
duration: number;
|
|
40
|
-
/**
|
|
41
|
-
* Custom function to render the toast element.
|
|
42
|
-
*/
|
|
43
|
-
render?: (options: RenderOptions) => any;
|
|
44
|
-
/**
|
|
45
|
-
* The duration for the toast to kept alive before it is removed.
|
|
46
|
-
* Useful for exit transitions.
|
|
47
|
-
*/
|
|
48
|
-
removeDelay?: number;
|
|
49
|
-
/**
|
|
50
|
-
* Function called when the toast has been closed and removed
|
|
51
|
-
*/
|
|
52
|
-
onClose?: VoidFunction;
|
|
53
|
-
/**
|
|
54
|
-
* Function called when the toast is leaving
|
|
55
|
-
*/
|
|
56
|
-
onClosing?: VoidFunction;
|
|
57
|
-
/**
|
|
58
|
-
* Function called when the toast is shown
|
|
59
|
-
*/
|
|
60
|
-
onOpen?: VoidFunction;
|
|
61
|
-
/**
|
|
62
|
-
* Function called when the toast is updated
|
|
63
|
-
*/
|
|
64
|
-
onUpdate?: VoidFunction;
|
|
65
|
-
};
|
|
66
|
-
export declare type Options = Partial<ToastOptions>;
|
|
67
|
-
export declare type RenderOptions = Omit<ToastOptions, "render"> & {
|
|
68
|
-
dismiss(): void;
|
|
69
|
-
};
|
|
70
|
-
export declare type MachineContext = SharedContext & RootProperties & CommonProperties & Omit<ToastOptions, "removeDelay"> & {
|
|
71
|
-
/**
|
|
72
|
-
* The duration for the toast to kept alive before it is removed.
|
|
73
|
-
* Useful for exit transitions.
|
|
74
|
-
*/
|
|
75
|
-
removeDelay: number;
|
|
76
|
-
/**
|
|
77
|
-
* The document's text/writing direction.
|
|
78
|
-
*/
|
|
79
|
-
dir?: Direction;
|
|
80
|
-
/**
|
|
81
|
-
* The time the toast was created
|
|
82
|
-
*/
|
|
83
|
-
createdAt: number;
|
|
84
|
-
/**
|
|
85
|
-
* The time left before the toast is removed
|
|
86
|
-
*/
|
|
87
|
-
remaining: number;
|
|
88
|
-
};
|
|
89
|
-
export declare type MachineState = {
|
|
90
|
-
value: "active" | "active:temp" | "dismissing" | "inactive" | "persist";
|
|
91
|
-
tags: "visible" | "paused" | "updating";
|
|
92
|
-
};
|
|
93
|
-
export declare type State = S.State<MachineContext, MachineState>;
|
|
94
|
-
export declare type Send = S.Send;
|
|
95
|
-
export declare type Service = Machine<MachineContext, MachineState>;
|
|
96
|
-
declare type GroupPublicContext = SharedContext & DirectionProperty & CommonProperties & {
|
|
97
|
-
/**
|
|
98
|
-
* The gutter or spacing between toasts
|
|
99
|
-
*/
|
|
100
|
-
gutter: string;
|
|
101
|
-
/**
|
|
102
|
-
* The z-index applied to each toast group
|
|
103
|
-
*/
|
|
104
|
-
zIndex: number;
|
|
105
|
-
/**
|
|
106
|
-
* The maximum number of toasts that can be shown at once
|
|
107
|
-
*/
|
|
108
|
-
max: number;
|
|
109
|
-
/**
|
|
110
|
-
* The offset from the safe environment edge of the viewport
|
|
111
|
-
*/
|
|
112
|
-
offsets: string | Record<"left" | "right" | "bottom" | "top", string>;
|
|
113
|
-
};
|
|
114
|
-
export declare type UserDefinedGroupContext = RequiredBy<GroupPublicContext, "id">;
|
|
115
|
-
declare type GroupComputedContext = Readonly<{
|
|
116
|
-
/**
|
|
117
|
-
* @computed
|
|
118
|
-
* The total number of toasts in the group
|
|
119
|
-
*/
|
|
120
|
-
readonly count: number;
|
|
121
|
-
}>;
|
|
122
|
-
declare type GroupPrivateContext = Context<{
|
|
123
|
-
/**
|
|
124
|
-
* @internal
|
|
125
|
-
* The child toast machines (spawned by the toast group)
|
|
126
|
-
*/
|
|
127
|
-
toasts: Service[];
|
|
128
|
-
}>;
|
|
129
|
-
export declare type GroupMachineContext = GroupPublicContext & GroupComputedContext & GroupPrivateContext;
|
|
130
|
-
export declare type GroupState = S.State<GroupMachineContext>;
|
|
131
|
-
export declare type GroupSend = (event: S.Event<S.AnyEventObject>) => void;
|
|
132
|
-
declare type MaybeFunction<Value, Args> = Value | ((arg: Args) => Value);
|
|
133
|
-
export declare type PromiseOptions<Value> = {
|
|
134
|
-
loading: ToastOptions;
|
|
135
|
-
success: MaybeFunction<ToastOptions, Value>;
|
|
136
|
-
error: MaybeFunction<ToastOptions, Error>;
|
|
137
|
-
};
|
|
138
|
-
export declare type GroupProps = {
|
|
139
|
-
placement: Placement;
|
|
140
|
-
label?: string;
|
|
141
|
-
};
|
|
142
|
-
export declare type Toaster = {
|
|
143
|
-
count: number;
|
|
144
|
-
isVisible(id: string): boolean;
|
|
145
|
-
upsert(options: ToastOptions): string | undefined;
|
|
146
|
-
create(options: ToastOptions): string | undefined;
|
|
147
|
-
success(options: ToastOptions): string | undefined;
|
|
148
|
-
error(options: ToastOptions): string | undefined;
|
|
149
|
-
loading(options: ToastOptions): string | undefined;
|
|
150
|
-
dismiss(id?: string | undefined): void;
|
|
151
|
-
remove(id?: string | undefined): void;
|
|
152
|
-
promise<T>(promise: Promise<T>, options: PromiseOptions<T>, shared?: ToastOptions): Promise<T>;
|
|
153
|
-
};
|
|
154
|
-
export {};
|
package/dist/toast.utils.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Style } from "@zag-js/types";
|
|
2
|
-
import type { GroupMachineContext, MachineContext, Placement, Service, Type } from "./toast.types";
|
|
3
|
-
export declare function getToastsByPlacement(toasts: Service[]): Partial<Record<Placement, Service[]>>;
|
|
4
|
-
export declare const defaultTimeouts: Record<Type, number>;
|
|
5
|
-
export declare function getToastDuration(duration: number | undefined, type: MachineContext["type"]): number;
|
|
6
|
-
export declare function getGroupPlacementStyle(ctx: GroupMachineContext, placement: Placement): Style;
|