@zag-js/toast 0.10.5 → 0.11.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/dist/index.d.mts +288 -0
- package/dist/index.d.ts +285 -10
- package/dist/index.js +661 -21
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +630 -11
- package/dist/index.mjs.map +1 -0
- package/package.json +8 -8
- package/dist/toast-group.connect.d.ts +0 -75
- package/dist/toast-group.connect.js +0 -176
- package/dist/toast-group.connect.mjs +0 -171
- package/dist/toast-group.machine.d.ts +0 -3
- package/dist/toast-group.machine.js +0 -99
- package/dist/toast-group.machine.mjs +0 -95
- package/dist/toast.anatomy.d.ts +0 -3
- package/dist/toast.anatomy.js +0 -11
- package/dist/toast.anatomy.mjs +0 -6
- package/dist/toast.connect.d.ts +0 -52
- package/dist/toast.connect.js +0 -141
- package/dist/toast.connect.mjs +0 -137
- package/dist/toast.dom.d.ts +0 -28
- package/dist/toast.dom.js +0 -16
- package/dist/toast.dom.mjs +0 -12
- package/dist/toast.machine.d.ts +0 -3
- package/dist/toast.machine.js +0 -149
- package/dist/toast.machine.mjs +0 -145
- package/dist/toast.types.d.ts +0 -148
- package/dist/toast.utils.d.ts +0 -6
- package/dist/toast.utils.js +0 -67
- package/dist/toast.utils.mjs +0 -60
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { createMachine } from '@zag-js/core';
|
|
2
|
-
import { MAX_Z_INDEX } from '@zag-js/dom-query';
|
|
3
|
-
import { compact } from '@zag-js/utils';
|
|
4
|
-
import { createToastMachine } from './toast.machine.mjs';
|
|
5
|
-
|
|
6
|
-
function groupMachine(userContext) {
|
|
7
|
-
const ctx = compact(userContext);
|
|
8
|
-
return createMachine({
|
|
9
|
-
id: "toaster",
|
|
10
|
-
initial: "active",
|
|
11
|
-
context: {
|
|
12
|
-
dir: "ltr",
|
|
13
|
-
max: Number.MAX_SAFE_INTEGER,
|
|
14
|
-
toasts: [],
|
|
15
|
-
gutter: "1rem",
|
|
16
|
-
zIndex: MAX_Z_INDEX,
|
|
17
|
-
pauseOnPageIdle: false,
|
|
18
|
-
pauseOnInteraction: true,
|
|
19
|
-
offsets: { left: "0px", right: "0px", top: "0px", bottom: "0px" },
|
|
20
|
-
...ctx
|
|
21
|
-
},
|
|
22
|
-
computed: {
|
|
23
|
-
count: (ctx2) => ctx2.toasts.length
|
|
24
|
-
},
|
|
25
|
-
on: {
|
|
26
|
-
SETUP: {},
|
|
27
|
-
PAUSE_TOAST: {
|
|
28
|
-
actions: (_ctx, evt, { self }) => {
|
|
29
|
-
self.sendChild("PAUSE", evt.id);
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
PAUSE_ALL: {
|
|
33
|
-
actions: (ctx2) => {
|
|
34
|
-
ctx2.toasts.forEach((toast) => toast.send("PAUSE"));
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
RESUME_TOAST: {
|
|
38
|
-
actions: (_ctx, evt, { self }) => {
|
|
39
|
-
self.sendChild("RESUME", evt.id);
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
RESUME_ALL: {
|
|
43
|
-
actions: (ctx2) => {
|
|
44
|
-
ctx2.toasts.forEach((toast) => toast.send("RESUME"));
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
ADD_TOAST: {
|
|
48
|
-
guard: (ctx2) => ctx2.toasts.length < ctx2.max,
|
|
49
|
-
actions: (ctx2, evt, { self }) => {
|
|
50
|
-
const options = {
|
|
51
|
-
...evt.toast,
|
|
52
|
-
pauseOnPageIdle: ctx2.pauseOnPageIdle,
|
|
53
|
-
pauseOnInteraction: ctx2.pauseOnInteraction,
|
|
54
|
-
dir: ctx2.dir,
|
|
55
|
-
getRootNode: ctx2.getRootNode
|
|
56
|
-
};
|
|
57
|
-
const toast = createToastMachine(options);
|
|
58
|
-
const actor = self.spawn(toast);
|
|
59
|
-
ctx2.toasts.push(actor);
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
UPDATE_TOAST: {
|
|
63
|
-
actions: (_ctx, evt, { self }) => {
|
|
64
|
-
self.sendChild({ type: "UPDATE", toast: evt.toast }, evt.id);
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
DISMISS_TOAST: {
|
|
68
|
-
actions: (_ctx, evt, { self }) => {
|
|
69
|
-
self.sendChild("DISMISS", evt.id);
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
DISMISS_ALL: {
|
|
73
|
-
actions: (ctx2) => {
|
|
74
|
-
ctx2.toasts.forEach((toast) => toast.send("DISMISS"));
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
REMOVE_TOAST: {
|
|
78
|
-
actions: (ctx2, evt, { self }) => {
|
|
79
|
-
self.stopChild(evt.id);
|
|
80
|
-
const index = ctx2.toasts.findIndex((toast) => toast.id === evt.id);
|
|
81
|
-
ctx2.toasts.splice(index, 1);
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
REMOVE_ALL: {
|
|
85
|
-
actions: (ctx2, _evt, { self }) => {
|
|
86
|
-
ctx2.toasts.forEach((toast) => self.stopChild(toast.id));
|
|
87
|
-
while (ctx2.toasts.length)
|
|
88
|
-
ctx2.toasts.pop();
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export { groupMachine };
|
package/dist/toast.anatomy.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { AnatomyInstance, AnatomyPart } from '@zag-js/anatomy';
|
|
2
|
-
export declare const anatomy: AnatomyInstance<"group" | "title" | "description" | "root" | "closeTrigger">;
|
|
3
|
-
export declare const parts: Record<"group" | "title" | "description" | "root" | "closeTrigger", AnatomyPart>;
|
package/dist/toast.anatomy.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const anatomy$1 = require('@zag-js/anatomy');
|
|
6
|
-
|
|
7
|
-
const anatomy = anatomy$1.createAnatomy("toast").parts("group", "root", "title", "description", "closeTrigger");
|
|
8
|
-
const parts = anatomy.build();
|
|
9
|
-
|
|
10
|
-
exports.anatomy = anatomy;
|
|
11
|
-
exports.parts = parts;
|
package/dist/toast.anatomy.mjs
DELETED
package/dist/toast.connect.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import type { NormalizeProps, PropTypes } from "@zag-js/types";
|
|
2
|
-
import type { Type, Placement, Send, State } from './toast.types';
|
|
3
|
-
export declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
|
|
4
|
-
/**
|
|
5
|
-
* The type of the toast.
|
|
6
|
-
*/
|
|
7
|
-
type: Type;
|
|
8
|
-
/**
|
|
9
|
-
* The title of the toast.
|
|
10
|
-
*/
|
|
11
|
-
title: string | undefined;
|
|
12
|
-
/**
|
|
13
|
-
* The description of the toast.
|
|
14
|
-
*/
|
|
15
|
-
description: string | undefined;
|
|
16
|
-
/**
|
|
17
|
-
* The current placement of the toast.
|
|
18
|
-
*/
|
|
19
|
-
placement: Placement;
|
|
20
|
-
/**
|
|
21
|
-
* Whether the toast is visible.
|
|
22
|
-
*/
|
|
23
|
-
isVisible: boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Whether the toast is paused.
|
|
26
|
-
*/
|
|
27
|
-
isPaused: boolean;
|
|
28
|
-
/**
|
|
29
|
-
* Whether the toast is in RTL mode.
|
|
30
|
-
*/
|
|
31
|
-
isRtl: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Function to pause the toast (keeping it visible).
|
|
34
|
-
*/
|
|
35
|
-
pause(): void;
|
|
36
|
-
/**
|
|
37
|
-
* Function to resume the toast dismissing.
|
|
38
|
-
*/
|
|
39
|
-
resume(): void;
|
|
40
|
-
/**
|
|
41
|
-
* Function to instantly dismiss the toast.
|
|
42
|
-
*/
|
|
43
|
-
dismiss(): void;
|
|
44
|
-
/**
|
|
45
|
-
* Function render the toast in the DOM (based on the defined `render` property)
|
|
46
|
-
*/
|
|
47
|
-
render(): any;
|
|
48
|
-
rootProps: T["element"];
|
|
49
|
-
titleProps: T["element"];
|
|
50
|
-
descriptionProps: T["element"];
|
|
51
|
-
closeTriggerProps: T["button"];
|
|
52
|
-
};
|
package/dist/toast.connect.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const domQuery = require('@zag-js/dom-query');
|
|
6
|
-
const toast_anatomy = require('./toast.anatomy.js');
|
|
7
|
-
const toast_dom = require('./toast.dom.js');
|
|
8
|
-
|
|
9
|
-
function connect(state, send, normalize) {
|
|
10
|
-
const isVisible = state.hasTag("visible");
|
|
11
|
-
const isPaused = state.hasTag("paused");
|
|
12
|
-
const pauseOnInteraction = state.context.pauseOnInteraction;
|
|
13
|
-
const placement = state.context.placement;
|
|
14
|
-
return {
|
|
15
|
-
/**
|
|
16
|
-
* The type of the toast.
|
|
17
|
-
*/
|
|
18
|
-
type: state.context.type,
|
|
19
|
-
/**
|
|
20
|
-
* The title of the toast.
|
|
21
|
-
*/
|
|
22
|
-
title: state.context.title,
|
|
23
|
-
/**
|
|
24
|
-
* The description of the toast.
|
|
25
|
-
*/
|
|
26
|
-
description: state.context.description,
|
|
27
|
-
/**
|
|
28
|
-
* The current placement of the toast.
|
|
29
|
-
*/
|
|
30
|
-
placement,
|
|
31
|
-
/**
|
|
32
|
-
* Whether the toast is visible.
|
|
33
|
-
*/
|
|
34
|
-
isVisible,
|
|
35
|
-
/**
|
|
36
|
-
* Whether the toast is paused.
|
|
37
|
-
*/
|
|
38
|
-
isPaused,
|
|
39
|
-
/**
|
|
40
|
-
* Whether the toast is in RTL mode.
|
|
41
|
-
*/
|
|
42
|
-
isRtl: state.context.dir === "rtl",
|
|
43
|
-
/**
|
|
44
|
-
* Function to pause the toast (keeping it visible).
|
|
45
|
-
*/
|
|
46
|
-
pause() {
|
|
47
|
-
send("PAUSE");
|
|
48
|
-
},
|
|
49
|
-
/**
|
|
50
|
-
* Function to resume the toast dismissing.
|
|
51
|
-
*/
|
|
52
|
-
resume() {
|
|
53
|
-
send("RESUME");
|
|
54
|
-
},
|
|
55
|
-
/**
|
|
56
|
-
* Function to instantly dismiss the toast.
|
|
57
|
-
*/
|
|
58
|
-
dismiss() {
|
|
59
|
-
send("DISMISS");
|
|
60
|
-
},
|
|
61
|
-
/**
|
|
62
|
-
* Function render the toast in the DOM (based on the defined `render` property)
|
|
63
|
-
*/
|
|
64
|
-
render() {
|
|
65
|
-
return state.context.render?.({
|
|
66
|
-
id: state.context.id,
|
|
67
|
-
type: state.context.type,
|
|
68
|
-
duration: state.context.duration,
|
|
69
|
-
title: state.context.title,
|
|
70
|
-
placement: state.context.placement,
|
|
71
|
-
description: state.context.description,
|
|
72
|
-
dismiss() {
|
|
73
|
-
send("DISMISS");
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
},
|
|
77
|
-
rootProps: normalize.element({
|
|
78
|
-
...toast_anatomy.parts.root.attrs,
|
|
79
|
-
dir: state.context.dir,
|
|
80
|
-
id: toast_dom.dom.getRootId(state.context),
|
|
81
|
-
"data-open": domQuery.dataAttr(isVisible),
|
|
82
|
-
"data-type": state.context.type,
|
|
83
|
-
"data-placement": placement,
|
|
84
|
-
role: "status",
|
|
85
|
-
"aria-atomic": "true",
|
|
86
|
-
tabIndex: 0,
|
|
87
|
-
style: {
|
|
88
|
-
position: "relative",
|
|
89
|
-
pointerEvents: "auto",
|
|
90
|
-
margin: "calc(var(--toast-gutter) / 2)",
|
|
91
|
-
"--remove-delay": `${state.context.removeDelay}ms`,
|
|
92
|
-
"--duration": `${state.context.duration}ms`
|
|
93
|
-
},
|
|
94
|
-
onKeyDown(event) {
|
|
95
|
-
if (event.key == "Escape") {
|
|
96
|
-
send("DISMISS");
|
|
97
|
-
event.preventDefault();
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
onFocus() {
|
|
101
|
-
if (pauseOnInteraction) {
|
|
102
|
-
send("PAUSE");
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
onBlur() {
|
|
106
|
-
if (pauseOnInteraction) {
|
|
107
|
-
send("RESUME");
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
onPointerEnter() {
|
|
111
|
-
if (pauseOnInteraction) {
|
|
112
|
-
send("PAUSE");
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
onPointerLeave() {
|
|
116
|
-
if (pauseOnInteraction) {
|
|
117
|
-
send("RESUME");
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}),
|
|
121
|
-
titleProps: normalize.element({
|
|
122
|
-
...toast_anatomy.parts.title.attrs,
|
|
123
|
-
id: toast_dom.dom.getTitleId(state.context)
|
|
124
|
-
}),
|
|
125
|
-
descriptionProps: normalize.element({
|
|
126
|
-
...toast_anatomy.parts.description.attrs,
|
|
127
|
-
id: toast_dom.dom.getDescriptionId(state.context)
|
|
128
|
-
}),
|
|
129
|
-
closeTriggerProps: normalize.button({
|
|
130
|
-
id: toast_dom.dom.getCloseTriggerId(state.context),
|
|
131
|
-
...toast_anatomy.parts.closeTrigger.attrs,
|
|
132
|
-
type: "button",
|
|
133
|
-
"aria-label": "Dismiss notification",
|
|
134
|
-
onClick() {
|
|
135
|
-
send("DISMISS");
|
|
136
|
-
}
|
|
137
|
-
})
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
exports.connect = connect;
|
package/dist/toast.connect.mjs
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { dataAttr } from '@zag-js/dom-query';
|
|
2
|
-
import { parts } from './toast.anatomy.mjs';
|
|
3
|
-
import { dom } from './toast.dom.mjs';
|
|
4
|
-
|
|
5
|
-
function connect(state, send, normalize) {
|
|
6
|
-
const isVisible = state.hasTag("visible");
|
|
7
|
-
const isPaused = state.hasTag("paused");
|
|
8
|
-
const pauseOnInteraction = state.context.pauseOnInteraction;
|
|
9
|
-
const placement = state.context.placement;
|
|
10
|
-
return {
|
|
11
|
-
/**
|
|
12
|
-
* The type of the toast.
|
|
13
|
-
*/
|
|
14
|
-
type: state.context.type,
|
|
15
|
-
/**
|
|
16
|
-
* The title of the toast.
|
|
17
|
-
*/
|
|
18
|
-
title: state.context.title,
|
|
19
|
-
/**
|
|
20
|
-
* The description of the toast.
|
|
21
|
-
*/
|
|
22
|
-
description: state.context.description,
|
|
23
|
-
/**
|
|
24
|
-
* The current placement of the toast.
|
|
25
|
-
*/
|
|
26
|
-
placement,
|
|
27
|
-
/**
|
|
28
|
-
* Whether the toast is visible.
|
|
29
|
-
*/
|
|
30
|
-
isVisible,
|
|
31
|
-
/**
|
|
32
|
-
* Whether the toast is paused.
|
|
33
|
-
*/
|
|
34
|
-
isPaused,
|
|
35
|
-
/**
|
|
36
|
-
* Whether the toast is in RTL mode.
|
|
37
|
-
*/
|
|
38
|
-
isRtl: state.context.dir === "rtl",
|
|
39
|
-
/**
|
|
40
|
-
* Function to pause the toast (keeping it visible).
|
|
41
|
-
*/
|
|
42
|
-
pause() {
|
|
43
|
-
send("PAUSE");
|
|
44
|
-
},
|
|
45
|
-
/**
|
|
46
|
-
* Function to resume the toast dismissing.
|
|
47
|
-
*/
|
|
48
|
-
resume() {
|
|
49
|
-
send("RESUME");
|
|
50
|
-
},
|
|
51
|
-
/**
|
|
52
|
-
* Function to instantly dismiss the toast.
|
|
53
|
-
*/
|
|
54
|
-
dismiss() {
|
|
55
|
-
send("DISMISS");
|
|
56
|
-
},
|
|
57
|
-
/**
|
|
58
|
-
* Function render the toast in the DOM (based on the defined `render` property)
|
|
59
|
-
*/
|
|
60
|
-
render() {
|
|
61
|
-
return state.context.render?.({
|
|
62
|
-
id: state.context.id,
|
|
63
|
-
type: state.context.type,
|
|
64
|
-
duration: state.context.duration,
|
|
65
|
-
title: state.context.title,
|
|
66
|
-
placement: state.context.placement,
|
|
67
|
-
description: state.context.description,
|
|
68
|
-
dismiss() {
|
|
69
|
-
send("DISMISS");
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
},
|
|
73
|
-
rootProps: normalize.element({
|
|
74
|
-
...parts.root.attrs,
|
|
75
|
-
dir: state.context.dir,
|
|
76
|
-
id: dom.getRootId(state.context),
|
|
77
|
-
"data-open": dataAttr(isVisible),
|
|
78
|
-
"data-type": state.context.type,
|
|
79
|
-
"data-placement": placement,
|
|
80
|
-
role: "status",
|
|
81
|
-
"aria-atomic": "true",
|
|
82
|
-
tabIndex: 0,
|
|
83
|
-
style: {
|
|
84
|
-
position: "relative",
|
|
85
|
-
pointerEvents: "auto",
|
|
86
|
-
margin: "calc(var(--toast-gutter) / 2)",
|
|
87
|
-
"--remove-delay": `${state.context.removeDelay}ms`,
|
|
88
|
-
"--duration": `${state.context.duration}ms`
|
|
89
|
-
},
|
|
90
|
-
onKeyDown(event) {
|
|
91
|
-
if (event.key == "Escape") {
|
|
92
|
-
send("DISMISS");
|
|
93
|
-
event.preventDefault();
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
onFocus() {
|
|
97
|
-
if (pauseOnInteraction) {
|
|
98
|
-
send("PAUSE");
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
onBlur() {
|
|
102
|
-
if (pauseOnInteraction) {
|
|
103
|
-
send("RESUME");
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
onPointerEnter() {
|
|
107
|
-
if (pauseOnInteraction) {
|
|
108
|
-
send("PAUSE");
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
onPointerLeave() {
|
|
112
|
-
if (pauseOnInteraction) {
|
|
113
|
-
send("RESUME");
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}),
|
|
117
|
-
titleProps: normalize.element({
|
|
118
|
-
...parts.title.attrs,
|
|
119
|
-
id: dom.getTitleId(state.context)
|
|
120
|
-
}),
|
|
121
|
-
descriptionProps: normalize.element({
|
|
122
|
-
...parts.description.attrs,
|
|
123
|
-
id: dom.getDescriptionId(state.context)
|
|
124
|
-
}),
|
|
125
|
-
closeTriggerProps: normalize.button({
|
|
126
|
-
id: dom.getCloseTriggerId(state.context),
|
|
127
|
-
...parts.closeTrigger.attrs,
|
|
128
|
-
type: "button",
|
|
129
|
-
"aria-label": "Dismiss notification",
|
|
130
|
-
onClick() {
|
|
131
|
-
send("DISMISS");
|
|
132
|
-
}
|
|
133
|
-
})
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export { connect };
|
package/dist/toast.dom.d.ts
DELETED
|
@@ -1,28 +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 | ShadowRoot | Document) | undefined;
|
|
5
|
-
}) => ShadowRoot | Document;
|
|
6
|
-
getDoc: (ctx: {
|
|
7
|
-
getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
|
|
8
|
-
}) => Document;
|
|
9
|
-
getWin: (ctx: {
|
|
10
|
-
getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
|
|
11
|
-
}) => Window & typeof globalThis;
|
|
12
|
-
getActiveElement: (ctx: {
|
|
13
|
-
getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
|
|
14
|
-
}) => HTMLElement | null;
|
|
15
|
-
getById: <T extends HTMLElement = HTMLElement>(ctx: {
|
|
16
|
-
getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
|
|
17
|
-
}, id: string) => T | null;
|
|
18
|
-
queryById: <T_1 extends HTMLElement = HTMLElement>(ctx: {
|
|
19
|
-
getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
|
|
20
|
-
}, id: string) => T_1;
|
|
21
|
-
} & {
|
|
22
|
-
getGroupId: (placement: Placement) => string;
|
|
23
|
-
getRootId: (ctx: Ctx) => string;
|
|
24
|
-
getTitleId: (ctx: Ctx) => string;
|
|
25
|
-
getDescriptionId: (ctx: Ctx) => string;
|
|
26
|
-
getCloseTriggerId: (ctx: Ctx) => string;
|
|
27
|
-
getPortalId: (ctx: GroupCtx) => string;
|
|
28
|
-
};
|
package/dist/toast.dom.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const domQuery = require('@zag-js/dom-query');
|
|
6
|
-
|
|
7
|
-
const dom = domQuery.createScope({
|
|
8
|
-
getGroupId: (placement) => `toast-group:${placement}`,
|
|
9
|
-
getRootId: (ctx) => `toast:${ctx.id}`,
|
|
10
|
-
getTitleId: (ctx) => `toast:${ctx.id}:title`,
|
|
11
|
-
getDescriptionId: (ctx) => `toast:${ctx.id}:description`,
|
|
12
|
-
getCloseTriggerId: (ctx) => `toast${ctx.id}:close`,
|
|
13
|
-
getPortalId: (ctx) => `toast-portal:${ctx.id}`
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
exports.dom = dom;
|
package/dist/toast.dom.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { createScope } from '@zag-js/dom-query';
|
|
2
|
-
|
|
3
|
-
const dom = createScope({
|
|
4
|
-
getGroupId: (placement) => `toast-group:${placement}`,
|
|
5
|
-
getRootId: (ctx) => `toast:${ctx.id}`,
|
|
6
|
-
getTitleId: (ctx) => `toast:${ctx.id}:title`,
|
|
7
|
-
getDescriptionId: (ctx) => `toast:${ctx.id}:description`,
|
|
8
|
-
getCloseTriggerId: (ctx) => `toast${ctx.id}:close`,
|
|
9
|
-
getPortalId: (ctx) => `toast-portal:${ctx.id}`
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
export { dom };
|
package/dist/toast.machine.d.ts
DELETED
package/dist/toast.machine.js
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const core = require('@zag-js/core');
|
|
6
|
-
const domEvent = require('@zag-js/dom-event');
|
|
7
|
-
const utils = require('@zag-js/utils');
|
|
8
|
-
const toast_dom = require('./toast.dom.js');
|
|
9
|
-
const toast_utils = require('./toast.utils.js');
|
|
10
|
-
|
|
11
|
-
const { not, and, or } = core.guards;
|
|
12
|
-
function createToastMachine(options = {}) {
|
|
13
|
-
const { type = "info", duration, id = "toast", placement = "bottom", removeDelay = 0, ...restProps } = options;
|
|
14
|
-
const ctx = utils.compact(restProps);
|
|
15
|
-
const computedDuration = toast_utils.getToastDuration(duration, type);
|
|
16
|
-
return core.createMachine(
|
|
17
|
-
{
|
|
18
|
-
id,
|
|
19
|
-
entry: "invokeOnOpen",
|
|
20
|
-
initial: type === "loading" ? "persist" : "active",
|
|
21
|
-
context: {
|
|
22
|
-
id,
|
|
23
|
-
type,
|
|
24
|
-
remaining: computedDuration,
|
|
25
|
-
duration: computedDuration,
|
|
26
|
-
removeDelay,
|
|
27
|
-
createdAt: Date.now(),
|
|
28
|
-
placement,
|
|
29
|
-
...ctx
|
|
30
|
-
},
|
|
31
|
-
on: {
|
|
32
|
-
UPDATE: [
|
|
33
|
-
{
|
|
34
|
-
guard: and("hasTypeChanged", "isChangingToLoading"),
|
|
35
|
-
target: "persist",
|
|
36
|
-
actions: ["setContext", "invokeOnUpdate"]
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
guard: or("hasDurationChanged", "hasTypeChanged"),
|
|
40
|
-
target: "active:temp",
|
|
41
|
-
actions: ["setContext", "invokeOnUpdate"]
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
actions: ["setContext", "invokeOnUpdate"]
|
|
45
|
-
}
|
|
46
|
-
]
|
|
47
|
-
},
|
|
48
|
-
states: {
|
|
49
|
-
"active:temp": {
|
|
50
|
-
tags: ["visible", "updating"],
|
|
51
|
-
after: {
|
|
52
|
-
0: "active"
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
persist: {
|
|
56
|
-
tags: ["visible", "paused"],
|
|
57
|
-
activities: "trackDocumentVisibility",
|
|
58
|
-
on: {
|
|
59
|
-
RESUME: {
|
|
60
|
-
guard: not("isLoadingType"),
|
|
61
|
-
target: "active",
|
|
62
|
-
actions: ["setCreatedAt"]
|
|
63
|
-
},
|
|
64
|
-
DISMISS: "dismissing"
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
active: {
|
|
68
|
-
tags: ["visible"],
|
|
69
|
-
activities: "trackDocumentVisibility",
|
|
70
|
-
after: {
|
|
71
|
-
VISIBLE_DURATION: "dismissing"
|
|
72
|
-
},
|
|
73
|
-
on: {
|
|
74
|
-
DISMISS: "dismissing",
|
|
75
|
-
PAUSE: {
|
|
76
|
-
target: "persist",
|
|
77
|
-
actions: "setRemainingDuration"
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
dismissing: {
|
|
82
|
-
entry: "invokeOnClosing",
|
|
83
|
-
after: {
|
|
84
|
-
REMOVE_DELAY: {
|
|
85
|
-
target: "inactive",
|
|
86
|
-
actions: "notifyParentToRemove"
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
inactive: {
|
|
91
|
-
entry: "invokeOnClose",
|
|
92
|
-
type: "final"
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
activities: {
|
|
98
|
-
trackDocumentVisibility(ctx2, _evt, { send }) {
|
|
99
|
-
if (!ctx2.pauseOnPageIdle)
|
|
100
|
-
return;
|
|
101
|
-
const doc = toast_dom.dom.getDoc(ctx2);
|
|
102
|
-
return domEvent.addDomEvent(doc, "visibilitychange", () => {
|
|
103
|
-
send(doc.visibilityState === "hidden" ? "PAUSE" : "RESUME");
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
guards: {
|
|
108
|
-
isChangingToLoading: (_, evt) => evt.toast?.type === "loading",
|
|
109
|
-
isLoadingType: (ctx2) => ctx2.type === "loading",
|
|
110
|
-
hasTypeChanged: (ctx2, evt) => evt.toast?.type !== ctx2.type,
|
|
111
|
-
hasDurationChanged: (ctx2, evt) => evt.toast?.duration !== ctx2.duration
|
|
112
|
-
},
|
|
113
|
-
delays: {
|
|
114
|
-
VISIBLE_DURATION: (ctx2) => ctx2.remaining,
|
|
115
|
-
REMOVE_DELAY: (ctx2) => ctx2.removeDelay
|
|
116
|
-
},
|
|
117
|
-
actions: {
|
|
118
|
-
setRemainingDuration(ctx2) {
|
|
119
|
-
ctx2.remaining -= Date.now() - ctx2.createdAt;
|
|
120
|
-
},
|
|
121
|
-
setCreatedAt(ctx2) {
|
|
122
|
-
ctx2.createdAt = Date.now();
|
|
123
|
-
},
|
|
124
|
-
notifyParentToRemove(_ctx, _evt, { self }) {
|
|
125
|
-
self.sendParent({ type: "REMOVE_TOAST", id: self.id });
|
|
126
|
-
},
|
|
127
|
-
invokeOnClosing(ctx2) {
|
|
128
|
-
ctx2.onClosing?.();
|
|
129
|
-
},
|
|
130
|
-
invokeOnClose(ctx2) {
|
|
131
|
-
ctx2.onClose?.();
|
|
132
|
-
},
|
|
133
|
-
invokeOnOpen(ctx2) {
|
|
134
|
-
ctx2.onOpen?.();
|
|
135
|
-
},
|
|
136
|
-
invokeOnUpdate(ctx2) {
|
|
137
|
-
ctx2.onUpdate?.();
|
|
138
|
-
},
|
|
139
|
-
setContext(ctx2, evt) {
|
|
140
|
-
const { duration: duration2, type: type2 } = evt.toast;
|
|
141
|
-
const time = toast_utils.getToastDuration(duration2, type2);
|
|
142
|
-
Object.assign(ctx2, { ...evt.toast, duration: time, remaining: time });
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
exports.createToastMachine = createToastMachine;
|