@zag-js/toast 1.47.0 → 1.49.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 +10 -17
- package/dist/index.d.ts +10 -17
- package/dist/index.js +18 -45
- package/dist/index.mjs +5 -11
- package/dist/toast-group.connect.d.mts +4 -8
- package/dist/toast-group.connect.d.ts +4 -8
- package/dist/toast-group.connect.js +73 -97
- package/dist/toast-group.connect.mjs +67 -60
- package/dist/toast-group.machine.d.mts +2 -8
- package/dist/toast-group.machine.d.ts +2 -8
- package/dist/toast-group.machine.js +292 -346
- package/dist/toast-group.machine.mjs +286 -309
- package/dist/toast.anatomy.d.mts +2 -6
- package/dist/toast.anatomy.d.ts +2 -6
- package/dist/toast.anatomy.js +8 -40
- package/dist/toast.anatomy.mjs +4 -14
- package/dist/toast.connect.d.mts +4 -8
- package/dist/toast.connect.d.ts +4 -8
- package/dist/toast.connect.js +133 -158
- package/dist/toast.connect.mjs +126 -120
- package/dist/toast.dom.d.mts +19 -23
- package/dist/toast.dom.d.ts +19 -23
- package/dist/toast.dom.js +54 -83
- package/dist/toast.dom.mjs +39 -47
- package/dist/toast.machine.d.mts +2 -8
- package/dist/toast.machine.d.ts +2 -8
- package/dist/toast.machine.js +272 -300
- package/dist/toast.machine.mjs +265 -262
- package/dist/toast.store.d.mts +2 -8
- package/dist/toast.store.d.ts +2 -8
- package/dist/toast.store.js +344 -306
- package/dist/toast.store.mjs +340 -281
- package/dist/toast.types.d.mts +372 -374
- package/dist/toast.types.d.ts +372 -374
- package/dist/toast.types.js +4 -18
- package/dist/toast.types.mjs +1 -0
- package/dist/toast.utils.d.mts +10 -14
- package/dist/toast.utils.d.ts +10 -14
- package/dist/toast.utils.js +167 -217
- package/dist/toast.utils.mjs +157 -186
- package/package.json +9 -9
package/dist/toast.utils.mjs
CHANGED
|
@@ -1,200 +1,171 @@
|
|
|
1
|
-
// src/toast.utils.ts
|
|
2
1
|
import { MAX_Z_INDEX } from "@zag-js/dom-query";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
// src/toast.utils.ts
|
|
3
|
+
const defaultTimeouts = {
|
|
4
|
+
info: 5e3,
|
|
5
|
+
error: 5e3,
|
|
6
|
+
success: 2e3,
|
|
7
|
+
loading: 1e400,
|
|
8
|
+
warning: 5e3,
|
|
9
|
+
DEFAULT: 5e3
|
|
10
10
|
};
|
|
11
11
|
function getToastDuration(duration, type) {
|
|
12
|
-
|
|
12
|
+
return duration ?? defaultTimeouts[type] ?? defaultTimeouts.DEFAULT;
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
const getOffsets = (offsets) => typeof offsets === "string" ? {
|
|
15
|
+
left: offsets,
|
|
16
|
+
right: offsets,
|
|
17
|
+
bottom: offsets,
|
|
18
|
+
top: offsets
|
|
19
|
+
} : offsets;
|
|
15
20
|
function getGroupPlacementStyle(service, placement) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const offset = computedOffset.bottom;
|
|
47
|
-
styles.bottom = `max(env(safe-area-inset-bottom, 0px), ${offset})`;
|
|
48
|
-
}
|
|
49
|
-
if (!computedPlacement.includes("left")) {
|
|
50
|
-
const offset = computedOffset.right;
|
|
51
|
-
styles.insetInlineEnd = `calc(env(safe-area-inset-right, 0px) + ${offset})`;
|
|
52
|
-
}
|
|
53
|
-
if (!computedPlacement.includes("right")) {
|
|
54
|
-
const offset = computedOffset.left;
|
|
55
|
-
styles.insetInlineStart = `calc(env(safe-area-inset-left, 0px) + ${offset})`;
|
|
56
|
-
}
|
|
57
|
-
return styles;
|
|
21
|
+
const { prop, computed, context } = service;
|
|
22
|
+
const { offsets, gap } = prop("store").attrs;
|
|
23
|
+
const heights = context.get("heights");
|
|
24
|
+
const computedOffset = getOffsets(offsets);
|
|
25
|
+
const rtl = prop("dir") === "rtl";
|
|
26
|
+
const computedPlacement = placement.replace("-start", rtl ? "-right" : "-left").replace("-end", rtl ? "-left" : "-right");
|
|
27
|
+
const isRighty = computedPlacement.includes("right");
|
|
28
|
+
const isLefty = computedPlacement.includes("left");
|
|
29
|
+
const styles = {
|
|
30
|
+
position: "fixed",
|
|
31
|
+
pointerEvents: computed("count") > 0 ? void 0 : "none",
|
|
32
|
+
display: "flex",
|
|
33
|
+
flexDirection: "column",
|
|
34
|
+
"--gap": `${gap}px`,
|
|
35
|
+
"--first-height": `${heights[0]?.height || 0}px`,
|
|
36
|
+
"--viewport-offset-left": computedOffset.left,
|
|
37
|
+
"--viewport-offset-right": computedOffset.right,
|
|
38
|
+
"--viewport-offset-top": computedOffset.top,
|
|
39
|
+
"--viewport-offset-bottom": computedOffset.bottom,
|
|
40
|
+
zIndex: MAX_Z_INDEX
|
|
41
|
+
};
|
|
42
|
+
let alignItems = "center";
|
|
43
|
+
if (isRighty) alignItems = "flex-end";
|
|
44
|
+
if (isLefty) alignItems = "flex-start";
|
|
45
|
+
styles.alignItems = alignItems;
|
|
46
|
+
if (computedPlacement.includes("top")) styles.top = `max(env(safe-area-inset-top, 0px), ${computedOffset.top})`;
|
|
47
|
+
if (computedPlacement.includes("bottom")) styles.bottom = `max(env(safe-area-inset-bottom, 0px), ${computedOffset.bottom})`;
|
|
48
|
+
if (!computedPlacement.includes("left")) styles.insetInlineEnd = `calc(env(safe-area-inset-right, 0px) + ${computedOffset.right})`;
|
|
49
|
+
if (!computedPlacement.includes("right")) styles.insetInlineStart = `calc(env(safe-area-inset-left, 0px) + ${computedOffset.left})`;
|
|
50
|
+
return styles;
|
|
58
51
|
}
|
|
59
52
|
function getPlacementStyle(service, visible) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
"--scale": "calc(-1 * var(--base-scale))",
|
|
128
|
-
"--height": "var(--first-height)"
|
|
129
|
-
});
|
|
130
|
-
if (!visible) {
|
|
131
|
-
assign({
|
|
132
|
-
"--y": "calc(var(--sign) * 40%)"
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
if (sibling && stacked && !visible) {
|
|
137
|
-
assign({
|
|
138
|
-
"--y": "calc(var(--lift) * var(--offset) + var(--lift) * -100%)"
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
if (frontmost && !visible) {
|
|
142
|
-
assign({
|
|
143
|
-
"--y": "calc(var(--lift) * -100%)"
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
return styles;
|
|
53
|
+
const { prop, context, computed } = service;
|
|
54
|
+
const parent = prop("parent");
|
|
55
|
+
const placement = parent.computed("placement");
|
|
56
|
+
const { gap } = parent.prop("store").attrs;
|
|
57
|
+
const [side] = placement.split("-");
|
|
58
|
+
const mounted = context.get("mounted");
|
|
59
|
+
const remainingTime = context.get("remainingTime");
|
|
60
|
+
const height = computed("height");
|
|
61
|
+
const frontmost = computed("frontmost");
|
|
62
|
+
const sibling = !frontmost;
|
|
63
|
+
const stacked = prop("parent").state.matches("stack");
|
|
64
|
+
const overlap = !stacked;
|
|
65
|
+
const duration = prop("type") === "loading" ? Number.MAX_SAFE_INTEGER : remainingTime;
|
|
66
|
+
const offset = computed("heightIndex") * gap + computed("heightBefore");
|
|
67
|
+
const styles = {
|
|
68
|
+
position: "absolute",
|
|
69
|
+
pointerEvents: "auto",
|
|
70
|
+
"--opacity": "0",
|
|
71
|
+
"--remove-delay": `${prop("removeDelay")}ms`,
|
|
72
|
+
"--duration": `${duration}ms`,
|
|
73
|
+
"--initial-height": `${height}px`,
|
|
74
|
+
"--offset": `${offset}px`,
|
|
75
|
+
"--index": prop("index"),
|
|
76
|
+
"--z-index": computed("zIndex"),
|
|
77
|
+
"--lift-amount": "calc(var(--lift) * var(--gap))",
|
|
78
|
+
"--y": "100%",
|
|
79
|
+
"--x": "0"
|
|
80
|
+
};
|
|
81
|
+
const assign = (overrides) => Object.assign(styles, overrides);
|
|
82
|
+
if (side === "top") assign({
|
|
83
|
+
top: "0",
|
|
84
|
+
"--sign": "-1",
|
|
85
|
+
"--y": "-100%",
|
|
86
|
+
"--lift": "1"
|
|
87
|
+
});
|
|
88
|
+
else if (side === "bottom") assign({
|
|
89
|
+
bottom: "0",
|
|
90
|
+
"--sign": "1",
|
|
91
|
+
"--y": "100%",
|
|
92
|
+
"--lift": "-1"
|
|
93
|
+
});
|
|
94
|
+
if (mounted) {
|
|
95
|
+
assign({
|
|
96
|
+
"--y": "0",
|
|
97
|
+
"--opacity": "1"
|
|
98
|
+
});
|
|
99
|
+
if (stacked) assign({
|
|
100
|
+
"--y": "calc(var(--lift) * var(--offset))",
|
|
101
|
+
"--height": "var(--initial-height)"
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
if (!visible) assign({
|
|
105
|
+
"--opacity": "0",
|
|
106
|
+
pointerEvents: "none"
|
|
107
|
+
});
|
|
108
|
+
if (sibling && overlap) {
|
|
109
|
+
assign({
|
|
110
|
+
"--base-scale": "var(--index) * 0.05 + 1",
|
|
111
|
+
"--y": "calc(var(--lift-amount) * var(--index))",
|
|
112
|
+
"--scale": "calc(-1 * var(--base-scale))",
|
|
113
|
+
"--height": "var(--first-height)"
|
|
114
|
+
});
|
|
115
|
+
if (!visible) assign({ "--y": "calc(var(--sign) * 40%)" });
|
|
116
|
+
}
|
|
117
|
+
if (sibling && stacked && !visible) assign({ "--y": "calc(var(--lift) * var(--offset) + var(--lift) * -100%)" });
|
|
118
|
+
if (frontmost && !visible) assign({ "--y": "calc(var(--lift) * -100%)" });
|
|
119
|
+
return styles;
|
|
147
120
|
}
|
|
148
121
|
function getGhostBeforeStyle(service, visible) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
height: "calc(var(--initial-height) + 80%)"
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
return styles;
|
|
122
|
+
const { computed } = service;
|
|
123
|
+
const styles = {
|
|
124
|
+
position: "absolute",
|
|
125
|
+
inset: "0",
|
|
126
|
+
scale: "1 2",
|
|
127
|
+
pointerEvents: visible ? "none" : "auto"
|
|
128
|
+
};
|
|
129
|
+
const assign = (overrides) => Object.assign(styles, overrides);
|
|
130
|
+
if (computed("frontmost") && !visible) assign({ height: "calc(var(--initial-height) + 80%)" });
|
|
131
|
+
return styles;
|
|
163
132
|
}
|
|
164
133
|
function getGhostAfterStyle() {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
134
|
+
return {
|
|
135
|
+
position: "absolute",
|
|
136
|
+
left: "0",
|
|
137
|
+
height: "calc(var(--gap) + 2px)",
|
|
138
|
+
bottom: "100%",
|
|
139
|
+
width: "100%"
|
|
140
|
+
};
|
|
172
141
|
}
|
|
173
142
|
function setHeight(parent, item) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
143
|
+
const { id, height } = item;
|
|
144
|
+
parent.context.set("heights", (prev) => {
|
|
145
|
+
const existing = prev.find((i) => i.id === id);
|
|
146
|
+
if (existing) {
|
|
147
|
+
if (existing.height === height) return prev;
|
|
148
|
+
return prev.map((i) => i.id === id ? {
|
|
149
|
+
...i,
|
|
150
|
+
height
|
|
151
|
+
} : i);
|
|
152
|
+
}
|
|
153
|
+
const toasts = parent.context.get("toasts");
|
|
154
|
+
const rank = (id) => toasts.findIndex((t) => t.id === id);
|
|
155
|
+
const index = rank(id);
|
|
156
|
+
let insertAt = prev.findIndex((i) => {
|
|
157
|
+
const r = rank(i.id);
|
|
158
|
+
return r === -1 || r > index;
|
|
159
|
+
});
|
|
160
|
+
if (insertAt === -1) insertAt = prev.length;
|
|
161
|
+
return [
|
|
162
|
+
...prev.slice(0, insertAt),
|
|
163
|
+
{
|
|
164
|
+
id,
|
|
165
|
+
height
|
|
166
|
+
},
|
|
167
|
+
...prev.slice(insertAt)
|
|
168
|
+
];
|
|
169
|
+
});
|
|
191
170
|
}
|
|
192
|
-
export {
|
|
193
|
-
defaultTimeouts,
|
|
194
|
-
getGhostAfterStyle,
|
|
195
|
-
getGhostBeforeStyle,
|
|
196
|
-
getGroupPlacementStyle,
|
|
197
|
-
getPlacementStyle,
|
|
198
|
-
getToastDuration,
|
|
199
|
-
setHeight
|
|
200
|
-
};
|
|
171
|
+
export { defaultTimeouts, getGhostAfterStyle, getGhostBeforeStyle, getGroupPlacementStyle, getPlacementStyle, getToastDuration, setHeight };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/toast",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.49.0",
|
|
4
4
|
"description": "Core logic for the toast widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@zag-js/anatomy": "1.
|
|
33
|
-
"@zag-js/core": "1.
|
|
34
|
-
"@zag-js/dom-query": "1.
|
|
35
|
-
"@zag-js/dismissable": "1.
|
|
36
|
-
"@zag-js/utils": "1.
|
|
37
|
-
"@zag-js/types": "1.
|
|
32
|
+
"@zag-js/anatomy": "1.49.0",
|
|
33
|
+
"@zag-js/core": "1.49.0",
|
|
34
|
+
"@zag-js/dom-query": "1.49.0",
|
|
35
|
+
"@zag-js/dismissable": "1.49.0",
|
|
36
|
+
"@zag-js/utils": "1.49.0",
|
|
37
|
+
"@zag-js/types": "1.49.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"clean-package": "2.2.0"
|
|
@@ -67,8 +67,8 @@
|
|
|
67
67
|
"./package.json": "./package.json"
|
|
68
68
|
},
|
|
69
69
|
"scripts": {
|
|
70
|
-
"build": "
|
|
71
|
-
"lint": "
|
|
70
|
+
"build": "tsdown",
|
|
71
|
+
"lint": "oxlint src",
|
|
72
72
|
"typecheck": "tsc --noEmit"
|
|
73
73
|
}
|
|
74
74
|
}
|