@zag-js/toast 1.46.0 → 1.48.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.
Files changed (41) hide show
  1. package/dist/index.d.mts +10 -17
  2. package/dist/index.d.ts +10 -17
  3. package/dist/index.js +18 -45
  4. package/dist/index.mjs +5 -11
  5. package/dist/toast-group.connect.d.mts +4 -8
  6. package/dist/toast-group.connect.d.ts +4 -8
  7. package/dist/toast-group.connect.js +73 -97
  8. package/dist/toast-group.connect.mjs +68 -61
  9. package/dist/toast-group.machine.d.mts +2 -8
  10. package/dist/toast-group.machine.d.ts +2 -8
  11. package/dist/toast-group.machine.js +294 -302
  12. package/dist/toast-group.machine.mjs +289 -266
  13. package/dist/toast.anatomy.d.mts +2 -6
  14. package/dist/toast.anatomy.d.ts +2 -6
  15. package/dist/toast.anatomy.js +8 -40
  16. package/dist/toast.anatomy.mjs +4 -14
  17. package/dist/toast.connect.d.mts +4 -8
  18. package/dist/toast.connect.d.ts +4 -8
  19. package/dist/toast.connect.js +133 -158
  20. package/dist/toast.connect.mjs +128 -122
  21. package/dist/toast.dom.d.mts +21 -16
  22. package/dist/toast.dom.d.ts +21 -16
  23. package/dist/toast.dom.js +56 -53
  24. package/dist/toast.dom.mjs +42 -20
  25. package/dist/toast.machine.d.mts +2 -8
  26. package/dist/toast.machine.d.ts +2 -8
  27. package/dist/toast.machine.js +272 -311
  28. package/dist/toast.machine.mjs +268 -276
  29. package/dist/toast.store.d.mts +2 -8
  30. package/dist/toast.store.d.ts +2 -8
  31. package/dist/toast.store.js +344 -299
  32. package/dist/toast.store.mjs +340 -274
  33. package/dist/toast.types.d.mts +372 -374
  34. package/dist/toast.types.d.ts +372 -374
  35. package/dist/toast.types.js +4 -18
  36. package/dist/toast.types.mjs +1 -0
  37. package/dist/toast.utils.d.mts +10 -13
  38. package/dist/toast.utils.d.ts +10 -13
  39. package/dist/toast.utils.js +169 -198
  40. package/dist/toast.utils.mjs +159 -168
  41. package/package.json +9 -9
@@ -1,18 +1,4 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
-
16
- // src/toast.types.ts
17
- var toast_types_exports = {};
18
- module.exports = __toCommonJS(toast_types_exports);
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -1,13 +1,10 @@
1
- import { Service } from '@zag-js/core';
2
- import { Style } from '@zag-js/types';
3
- import { Type, ToastSchema, ToastGroupService, Placement } from './toast.types.mjs';
4
- import '@zag-js/dom-query';
5
-
6
- declare const defaultTimeouts: Record<Type, number>;
7
- declare function getToastDuration(duration: number | undefined, type: Type): number;
8
- declare function getGroupPlacementStyle(service: ToastGroupService, placement: Placement): Style;
9
- declare function getPlacementStyle(service: Service<ToastSchema>, visible: boolean): Style;
10
- declare function getGhostBeforeStyle(service: Service<ToastSchema>, visible: boolean): Style;
11
- declare function getGhostAfterStyle(): Style;
12
-
13
- export { defaultTimeouts, getGhostAfterStyle, getGhostBeforeStyle, getGroupPlacementStyle, getPlacementStyle, getToastDuration };
1
+ import { Placement, ToastGroupSchema, ToastGroupService, ToastHeight, ToastSchema, Type } from "./toast.types.mjs";
2
+ import { Service } from "@zag-js/core";
3
+ import { Style } from "@zag-js/types";
4
+ export declare const defaultTimeouts: Record<Type, number>;
5
+ export declare function getToastDuration(duration: number | undefined, type: Type): number;
6
+ export declare function getGroupPlacementStyle(service: ToastGroupService, placement: Placement): Style;
7
+ export declare function getPlacementStyle(service: Service<ToastSchema>, visible: boolean): Style;
8
+ export declare function getGhostBeforeStyle(service: Service<ToastSchema>, visible: boolean): Style;
9
+ export declare function getGhostAfterStyle(): Style;
10
+ export declare function setHeight(parent: Service<ToastGroupSchema>, item: ToastHeight): void;
@@ -1,13 +1,10 @@
1
- import { Service } from '@zag-js/core';
2
- import { Style } from '@zag-js/types';
3
- import { Type, ToastSchema, ToastGroupService, Placement } from './toast.types.js';
4
- import '@zag-js/dom-query';
5
-
6
- declare const defaultTimeouts: Record<Type, number>;
7
- declare function getToastDuration(duration: number | undefined, type: Type): number;
8
- declare function getGroupPlacementStyle(service: ToastGroupService, placement: Placement): Style;
9
- declare function getPlacementStyle(service: Service<ToastSchema>, visible: boolean): Style;
10
- declare function getGhostBeforeStyle(service: Service<ToastSchema>, visible: boolean): Style;
11
- declare function getGhostAfterStyle(): Style;
12
-
13
- export { defaultTimeouts, getGhostAfterStyle, getGhostBeforeStyle, getGroupPlacementStyle, getPlacementStyle, getToastDuration };
1
+ import { Placement, ToastGroupSchema, ToastGroupService, ToastHeight, ToastSchema, Type } from "./toast.types.js";
2
+ import { Style } from "@zag-js/types";
3
+ import { Service } from "@zag-js/core";
4
+ export declare const defaultTimeouts: Record<Type, number>;
5
+ export declare function getToastDuration(duration: number | undefined, type: Type): number;
6
+ export declare function getGroupPlacementStyle(service: ToastGroupService, placement: Placement): Style;
7
+ export declare function getPlacementStyle(service: Service<ToastSchema>, visible: boolean): Style;
8
+ export declare function getGhostBeforeStyle(service: Service<ToastSchema>, visible: boolean): Style;
9
+ export declare function getGhostAfterStyle(): Style;
10
+ export declare function setHeight(parent: Service<ToastGroupSchema>, item: ToastHeight): void;
@@ -1,210 +1,181 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/toast.utils.ts
21
- var toast_utils_exports = {};
22
- __export(toast_utils_exports, {
23
- defaultTimeouts: () => defaultTimeouts,
24
- getGhostAfterStyle: () => getGhostAfterStyle,
25
- getGhostBeforeStyle: () => getGhostBeforeStyle,
26
- getGroupPlacementStyle: () => getGroupPlacementStyle,
27
- getPlacementStyle: () => getPlacementStyle,
28
- getToastDuration: () => getToastDuration
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
29
4
  });
30
- module.exports = __toCommonJS(toast_utils_exports);
31
- var import_dom_query = require("@zag-js/dom-query");
32
- var defaultTimeouts = {
33
- info: 5e3,
34
- error: 5e3,
35
- success: 2e3,
36
- loading: Infinity,
37
- warning: 5e3,
38
- DEFAULT: 5e3
5
+ let _zag_js_dom_query = require("@zag-js/dom-query");
6
+ // src/toast.utils.ts
7
+ const defaultTimeouts = {
8
+ info: 5e3,
9
+ error: 5e3,
10
+ success: 2e3,
11
+ loading: 1e400,
12
+ warning: 5e3,
13
+ DEFAULT: 5e3
39
14
  };
40
15
  function getToastDuration(duration, type) {
41
- return duration ?? defaultTimeouts[type] ?? defaultTimeouts.DEFAULT;
16
+ return duration ?? defaultTimeouts[type] ?? defaultTimeouts.DEFAULT;
42
17
  }
43
- var getOffsets = (offsets) => typeof offsets === "string" ? { left: offsets, right: offsets, bottom: offsets, top: offsets } : offsets;
18
+ const getOffsets = (offsets) => typeof offsets === "string" ? {
19
+ left: offsets,
20
+ right: offsets,
21
+ bottom: offsets,
22
+ top: offsets
23
+ } : offsets;
44
24
  function getGroupPlacementStyle(service, placement) {
45
- const { prop, computed, context } = service;
46
- const { offsets, gap } = prop("store").attrs;
47
- const heights = context.get("heights");
48
- const computedOffset = getOffsets(offsets);
49
- const rtl = prop("dir") === "rtl";
50
- const computedPlacement = placement.replace("-start", rtl ? "-right" : "-left").replace("-end", rtl ? "-left" : "-right");
51
- const isRighty = computedPlacement.includes("right");
52
- const isLefty = computedPlacement.includes("left");
53
- const styles = {
54
- position: "fixed",
55
- pointerEvents: computed("count") > 0 ? void 0 : "none",
56
- display: "flex",
57
- flexDirection: "column",
58
- "--gap": `${gap}px`,
59
- "--first-height": `${heights[0]?.height || 0}px`,
60
- "--viewport-offset-left": computedOffset.left,
61
- "--viewport-offset-right": computedOffset.right,
62
- "--viewport-offset-top": computedOffset.top,
63
- "--viewport-offset-bottom": computedOffset.bottom,
64
- zIndex: import_dom_query.MAX_Z_INDEX
65
- };
66
- let alignItems = "center";
67
- if (isRighty) alignItems = "flex-end";
68
- if (isLefty) alignItems = "flex-start";
69
- styles.alignItems = alignItems;
70
- if (computedPlacement.includes("top")) {
71
- const offset = computedOffset.top;
72
- styles.top = `max(env(safe-area-inset-top, 0px), ${offset})`;
73
- }
74
- if (computedPlacement.includes("bottom")) {
75
- const offset = computedOffset.bottom;
76
- styles.bottom = `max(env(safe-area-inset-bottom, 0px), ${offset})`;
77
- }
78
- if (!computedPlacement.includes("left")) {
79
- const offset = computedOffset.right;
80
- styles.insetInlineEnd = `calc(env(safe-area-inset-right, 0px) + ${offset})`;
81
- }
82
- if (!computedPlacement.includes("right")) {
83
- const offset = computedOffset.left;
84
- styles.insetInlineStart = `calc(env(safe-area-inset-left, 0px) + ${offset})`;
85
- }
86
- return styles;
25
+ const { prop, computed, context } = service;
26
+ const { offsets, gap } = prop("store").attrs;
27
+ const heights = context.get("heights");
28
+ const computedOffset = getOffsets(offsets);
29
+ const rtl = prop("dir") === "rtl";
30
+ const computedPlacement = placement.replace("-start", rtl ? "-right" : "-left").replace("-end", rtl ? "-left" : "-right");
31
+ const isRighty = computedPlacement.includes("right");
32
+ const isLefty = computedPlacement.includes("left");
33
+ const styles = {
34
+ position: "fixed",
35
+ pointerEvents: computed("count") > 0 ? void 0 : "none",
36
+ display: "flex",
37
+ flexDirection: "column",
38
+ "--gap": `${gap}px`,
39
+ "--first-height": `${heights[0]?.height || 0}px`,
40
+ "--viewport-offset-left": computedOffset.left,
41
+ "--viewport-offset-right": computedOffset.right,
42
+ "--viewport-offset-top": computedOffset.top,
43
+ "--viewport-offset-bottom": computedOffset.bottom,
44
+ zIndex: _zag_js_dom_query.MAX_Z_INDEX
45
+ };
46
+ let alignItems = "center";
47
+ if (isRighty) alignItems = "flex-end";
48
+ if (isLefty) alignItems = "flex-start";
49
+ styles.alignItems = alignItems;
50
+ if (computedPlacement.includes("top")) styles.top = `max(env(safe-area-inset-top, 0px), ${computedOffset.top})`;
51
+ if (computedPlacement.includes("bottom")) styles.bottom = `max(env(safe-area-inset-bottom, 0px), ${computedOffset.bottom})`;
52
+ if (!computedPlacement.includes("left")) styles.insetInlineEnd = `calc(env(safe-area-inset-right, 0px) + ${computedOffset.right})`;
53
+ if (!computedPlacement.includes("right")) styles.insetInlineStart = `calc(env(safe-area-inset-left, 0px) + ${computedOffset.left})`;
54
+ return styles;
87
55
  }
88
56
  function getPlacementStyle(service, visible) {
89
- const { prop, context, computed } = service;
90
- const parent = prop("parent");
91
- const placement = parent.computed("placement");
92
- const { gap } = parent.prop("store").attrs;
93
- const [side] = placement.split("-");
94
- const mounted = context.get("mounted");
95
- const remainingTime = context.get("remainingTime");
96
- const height = computed("height");
97
- const frontmost = computed("frontmost");
98
- const sibling = !frontmost;
99
- const overlap = !prop("stacked");
100
- const stacked = prop("stacked");
101
- const type = prop("type");
102
- const duration = type === "loading" ? Number.MAX_SAFE_INTEGER : remainingTime;
103
- const offset = computed("heightIndex") * gap + computed("heightBefore");
104
- const styles = {
105
- position: "absolute",
106
- pointerEvents: "auto",
107
- "--opacity": "0",
108
- "--remove-delay": `${prop("removeDelay")}ms`,
109
- "--duration": `${duration}ms`,
110
- "--initial-height": `${height}px`,
111
- "--offset": `${offset}px`,
112
- "--index": prop("index"),
113
- "--z-index": computed("zIndex"),
114
- "--lift-amount": "calc(var(--lift) * var(--gap))",
115
- "--y": "100%",
116
- "--x": "0"
117
- };
118
- const assign = (overrides) => Object.assign(styles, overrides);
119
- if (side === "top") {
120
- assign({
121
- top: "0",
122
- "--sign": "-1",
123
- "--y": "-100%",
124
- "--lift": "1"
125
- });
126
- } else if (side === "bottom") {
127
- assign({
128
- bottom: "0",
129
- "--sign": "1",
130
- "--y": "100%",
131
- "--lift": "-1"
132
- });
133
- }
134
- if (mounted) {
135
- assign({
136
- "--y": "0",
137
- "--opacity": "1"
138
- });
139
- if (stacked) {
140
- assign({
141
- "--y": "calc(var(--lift) * var(--offset))",
142
- "--height": "var(--initial-height)"
143
- });
144
- }
145
- }
146
- if (!visible) {
147
- assign({
148
- "--opacity": "0",
149
- pointerEvents: "none"
150
- });
151
- }
152
- if (sibling && overlap) {
153
- assign({
154
- "--base-scale": "var(--index) * 0.05 + 1",
155
- "--y": "calc(var(--lift-amount) * var(--index))",
156
- "--scale": "calc(-1 * var(--base-scale))",
157
- "--height": "var(--first-height)"
158
- });
159
- if (!visible) {
160
- assign({
161
- "--y": "calc(var(--sign) * 40%)"
162
- });
163
- }
164
- }
165
- if (sibling && stacked && !visible) {
166
- assign({
167
- "--y": "calc(var(--lift) * var(--offset) + var(--lift) * -100%)"
168
- });
169
- }
170
- if (frontmost && !visible) {
171
- assign({
172
- "--y": "calc(var(--lift) * -100%)"
173
- });
174
- }
175
- return styles;
57
+ const { prop, context, computed } = service;
58
+ const parent = prop("parent");
59
+ const placement = parent.computed("placement");
60
+ const { gap } = parent.prop("store").attrs;
61
+ const [side] = placement.split("-");
62
+ const mounted = context.get("mounted");
63
+ const remainingTime = context.get("remainingTime");
64
+ const height = computed("height");
65
+ const frontmost = computed("frontmost");
66
+ const sibling = !frontmost;
67
+ const stacked = prop("parent").state.matches("stack");
68
+ const overlap = !stacked;
69
+ const duration = prop("type") === "loading" ? Number.MAX_SAFE_INTEGER : remainingTime;
70
+ const offset = computed("heightIndex") * gap + computed("heightBefore");
71
+ const styles = {
72
+ position: "absolute",
73
+ pointerEvents: "auto",
74
+ "--opacity": "0",
75
+ "--remove-delay": `${prop("removeDelay")}ms`,
76
+ "--duration": `${duration}ms`,
77
+ "--initial-height": `${height}px`,
78
+ "--offset": `${offset}px`,
79
+ "--index": prop("index"),
80
+ "--z-index": computed("zIndex"),
81
+ "--lift-amount": "calc(var(--lift) * var(--gap))",
82
+ "--y": "100%",
83
+ "--x": "0"
84
+ };
85
+ const assign = (overrides) => Object.assign(styles, overrides);
86
+ if (side === "top") assign({
87
+ top: "0",
88
+ "--sign": "-1",
89
+ "--y": "-100%",
90
+ "--lift": "1"
91
+ });
92
+ else if (side === "bottom") assign({
93
+ bottom: "0",
94
+ "--sign": "1",
95
+ "--y": "100%",
96
+ "--lift": "-1"
97
+ });
98
+ if (mounted) {
99
+ assign({
100
+ "--y": "0",
101
+ "--opacity": "1"
102
+ });
103
+ if (stacked) assign({
104
+ "--y": "calc(var(--lift) * var(--offset))",
105
+ "--height": "var(--initial-height)"
106
+ });
107
+ }
108
+ if (!visible) assign({
109
+ "--opacity": "0",
110
+ pointerEvents: "none"
111
+ });
112
+ if (sibling && overlap) {
113
+ assign({
114
+ "--base-scale": "var(--index) * 0.05 + 1",
115
+ "--y": "calc(var(--lift-amount) * var(--index))",
116
+ "--scale": "calc(-1 * var(--base-scale))",
117
+ "--height": "var(--first-height)"
118
+ });
119
+ if (!visible) assign({ "--y": "calc(var(--sign) * 40%)" });
120
+ }
121
+ if (sibling && stacked && !visible) assign({ "--y": "calc(var(--lift) * var(--offset) + var(--lift) * -100%)" });
122
+ if (frontmost && !visible) assign({ "--y": "calc(var(--lift) * -100%)" });
123
+ return styles;
176
124
  }
177
125
  function getGhostBeforeStyle(service, visible) {
178
- const { computed } = service;
179
- const styles = {
180
- position: "absolute",
181
- inset: "0",
182
- scale: "1 2",
183
- pointerEvents: visible ? "none" : "auto"
184
- };
185
- const assign = (overrides) => Object.assign(styles, overrides);
186
- if (computed("frontmost") && !visible) {
187
- assign({
188
- height: "calc(var(--initial-height) + 80%)"
189
- });
190
- }
191
- return styles;
126
+ const { computed } = service;
127
+ const styles = {
128
+ position: "absolute",
129
+ inset: "0",
130
+ scale: "1 2",
131
+ pointerEvents: visible ? "none" : "auto"
132
+ };
133
+ const assign = (overrides) => Object.assign(styles, overrides);
134
+ if (computed("frontmost") && !visible) assign({ height: "calc(var(--initial-height) + 80%)" });
135
+ return styles;
192
136
  }
193
137
  function getGhostAfterStyle() {
194
- return {
195
- position: "absolute",
196
- left: "0",
197
- height: "calc(var(--gap) + 2px)",
198
- bottom: "100%",
199
- width: "100%"
200
- };
138
+ return {
139
+ position: "absolute",
140
+ left: "0",
141
+ height: "calc(var(--gap) + 2px)",
142
+ bottom: "100%",
143
+ width: "100%"
144
+ };
201
145
  }
202
- // Annotate the CommonJS export names for ESM import in node:
203
- 0 && (module.exports = {
204
- defaultTimeouts,
205
- getGhostAfterStyle,
206
- getGhostBeforeStyle,
207
- getGroupPlacementStyle,
208
- getPlacementStyle,
209
- getToastDuration
210
- });
146
+ function setHeight(parent, item) {
147
+ const { id, height } = item;
148
+ parent.context.set("heights", (prev) => {
149
+ const existing = prev.find((i) => i.id === id);
150
+ if (existing) {
151
+ if (existing.height === height) return prev;
152
+ return prev.map((i) => i.id === id ? {
153
+ ...i,
154
+ height
155
+ } : i);
156
+ }
157
+ const toasts = parent.context.get("toasts");
158
+ const rank = (id) => toasts.findIndex((t) => t.id === id);
159
+ const index = rank(id);
160
+ let insertAt = prev.findIndex((i) => {
161
+ const r = rank(i.id);
162
+ return r === -1 || r > index;
163
+ });
164
+ if (insertAt === -1) insertAt = prev.length;
165
+ return [
166
+ ...prev.slice(0, insertAt),
167
+ {
168
+ id,
169
+ height
170
+ },
171
+ ...prev.slice(insertAt)
172
+ ];
173
+ });
174
+ }
175
+ exports.defaultTimeouts = defaultTimeouts;
176
+ exports.getGhostAfterStyle = getGhostAfterStyle;
177
+ exports.getGhostBeforeStyle = getGhostBeforeStyle;
178
+ exports.getGroupPlacementStyle = getGroupPlacementStyle;
179
+ exports.getPlacementStyle = getPlacementStyle;
180
+ exports.getToastDuration = getToastDuration;
181
+ exports.setHeight = setHeight;