@zag-js/toast 2.0.0-next.2 → 2.0.0-next.4
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 +82 -103
- package/dist/toast-group.connect.mjs +77 -67
- package/dist/toast-group.machine.d.mts +2 -8
- package/dist/toast-group.machine.d.ts +2 -8
- package/dist/toast-group.machine.js +295 -290
- package/dist/toast-group.machine.mjs +290 -254
- 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 +176 -160
- package/dist/toast.connect.mjs +171 -124
- package/dist/toast.dom.d.mts +21 -14
- package/dist/toast.dom.d.ts +21 -14
- package/dist/toast.dom.js +50 -48
- package/dist/toast.dom.mjs +35 -17
- package/dist/toast.machine.d.mts +2 -8
- package/dist/toast.machine.d.ts +2 -8
- package/dist/toast.machine.js +404 -288
- package/dist/toast.machine.mjs +400 -253
- package/dist/toast.store.d.mts +2 -8
- package/dist/toast.store.d.ts +2 -8
- package/dist/toast.store.js +345 -263
- package/dist/toast.store.mjs +341 -238
- package/dist/toast.types.d.mts +460 -427
- package/dist/toast.types.d.ts +460 -427
- package/dist/toast.types.js +4 -18
- package/dist/toast.types.mjs +1 -0
- package/dist/toast.utils.d.mts +10 -13
- package/dist/toast.utils.d.ts +10 -13
- package/dist/toast.utils.js +185 -198
- package/dist/toast.utils.mjs +175 -168
- package/dist/utils/swipe.d.mts +16 -0
- package/dist/utils/swipe.d.ts +16 -0
- package/dist/utils/swipe.js +100 -0
- package/dist/utils/swipe.mjs +93 -0
- package/package.json +8 -8
package/dist/toast.anatomy.mjs
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
// src/toast.anatomy.ts
|
|
2
1
|
import { createAnatomy } from "@zag-js/anatomy";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"description",
|
|
8
|
-
"actionTrigger",
|
|
9
|
-
"closeTrigger"
|
|
10
|
-
);
|
|
11
|
-
var parts = anatomy.build();
|
|
12
|
-
export {
|
|
13
|
-
anatomy,
|
|
14
|
-
parts
|
|
15
|
-
};
|
|
2
|
+
// src/toast.anatomy.ts
|
|
3
|
+
const anatomy = createAnatomy("toast").parts("group", "root", "content", "title", "description", "actionTrigger", "closeTrigger");
|
|
4
|
+
const parts = anatomy.build();
|
|
5
|
+
export { anatomy, parts };
|
package/dist/toast.connect.d.mts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
declare function connect<T extends PropTypes, O>(service: Service<ToastSchema<O>>, normalize: NormalizeProps<T>): ToastApi<T, O>;
|
|
7
|
-
|
|
8
|
-
export { connect };
|
|
1
|
+
import { ToastApi, ToastSchema } from "./toast.types.mjs";
|
|
2
|
+
import { Service } from "@zag-js/core";
|
|
3
|
+
import { NormalizeProps, PropTypes } from "@zag-js/types";
|
|
4
|
+
export declare function connect<T extends PropTypes, O>(service: Service<ToastSchema<O>>, normalize: NormalizeProps<T>): ToastApi<T, O>;
|
package/dist/toast.connect.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
declare function connect<T extends PropTypes, O>(service: Service<ToastSchema<O>>, normalize: NormalizeProps<T>): ToastApi<T, O>;
|
|
7
|
-
|
|
8
|
-
export { connect };
|
|
1
|
+
import { ToastApi, ToastSchema } from "./toast.types.js";
|
|
2
|
+
import { NormalizeProps, PropTypes } from "@zag-js/types";
|
|
3
|
+
import { Service } from "@zag-js/core";
|
|
4
|
+
export declare function connect<T extends PropTypes, O>(service: Service<ToastSchema<O>>, normalize: NormalizeProps<T>): ToastApi<T, O>;
|
package/dist/toast.connect.js
CHANGED
|
@@ -1,163 +1,179 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/toast.connect.ts
|
|
31
|
-
var toast_connect_exports = {};
|
|
32
|
-
__export(toast_connect_exports, {
|
|
33
|
-
connect: () => connect
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
34
4
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
};
|
|
5
|
+
const require_toast_anatomy = require("./toast.anatomy.js");
|
|
6
|
+
const require_toast_dom = require("./toast.dom.js");
|
|
7
|
+
const require_toast_utils = require("./toast.utils.js");
|
|
8
|
+
let _zag_js_dom_query = require("@zag-js/dom-query");
|
|
9
|
+
let _zag_js_utils = require("@zag-js/utils");
|
|
10
|
+
// src/toast.connect.ts
|
|
11
|
+
const defaultTranslations = { closeTriggerLabel: "Dismiss notification" };
|
|
12
|
+
const SWIPE_IGNORE_SELECTOR = "button,a,input,textarea,select,[role=\"button\"],[data-swipe-ignore]";
|
|
44
13
|
function connect(service, normalize) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
14
|
+
const { state, send, prop, scope, context, computed } = service;
|
|
15
|
+
const translations = (0, _zag_js_utils.mergeWithDefault)(defaultTranslations, prop("translations"));
|
|
16
|
+
const visible = state.hasTag("visible");
|
|
17
|
+
const paused = state.hasTag("paused");
|
|
18
|
+
const mounted = context.get("mounted");
|
|
19
|
+
const rendered = context.get("rendered");
|
|
20
|
+
const frontmost = computed("frontmost");
|
|
21
|
+
const placement = prop("parent").computed("placement");
|
|
22
|
+
const type = prop("type");
|
|
23
|
+
const stacked = prop("parent").state.matches("stack");
|
|
24
|
+
const title = prop("title");
|
|
25
|
+
const description = prop("description");
|
|
26
|
+
const action = prop("action");
|
|
27
|
+
const [side, align = "center"] = placement.split("-");
|
|
28
|
+
const swiping = state.matches("visible:swiping");
|
|
29
|
+
const swipeDirection = context.get("swipeDirection");
|
|
30
|
+
function getRootState() {
|
|
31
|
+
return {
|
|
32
|
+
visible,
|
|
33
|
+
paused,
|
|
34
|
+
mounted,
|
|
35
|
+
frontmost,
|
|
36
|
+
stacked: !!stacked,
|
|
37
|
+
type,
|
|
38
|
+
placement,
|
|
39
|
+
side,
|
|
40
|
+
align,
|
|
41
|
+
swiping,
|
|
42
|
+
swipeDirection
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
type,
|
|
47
|
+
title,
|
|
48
|
+
description,
|
|
49
|
+
placement,
|
|
50
|
+
visible,
|
|
51
|
+
paused,
|
|
52
|
+
closable: !!prop("closable"),
|
|
53
|
+
pause() {
|
|
54
|
+
prop("parent").prop("store").pause(prop("id"));
|
|
55
|
+
},
|
|
56
|
+
resume() {
|
|
57
|
+
prop("parent").prop("store").resume(prop("id"));
|
|
58
|
+
},
|
|
59
|
+
dismiss() {
|
|
60
|
+
send({
|
|
61
|
+
type: "DISMISS",
|
|
62
|
+
src: "programmatic"
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
getRootState,
|
|
66
|
+
getRootProps() {
|
|
67
|
+
const rootState = getRootState();
|
|
68
|
+
return normalize.element({
|
|
69
|
+
...require_toast_anatomy.parts.root.attrs(scope.id),
|
|
70
|
+
dir: prop("dir"),
|
|
71
|
+
"data-state": rootState.visible ? "open" : "closed",
|
|
72
|
+
"data-type": rootState.type,
|
|
73
|
+
"data-placement": rootState.placement,
|
|
74
|
+
"data-align": rootState.align,
|
|
75
|
+
"data-side": rootState.side,
|
|
76
|
+
"data-mounted": (0, _zag_js_dom_query.dataAttr)(rootState.mounted),
|
|
77
|
+
"data-paused": (0, _zag_js_dom_query.dataAttr)(rootState.paused),
|
|
78
|
+
"data-first": (0, _zag_js_dom_query.dataAttr)(rootState.frontmost),
|
|
79
|
+
"data-sibling": (0, _zag_js_dom_query.dataAttr)(!rootState.frontmost),
|
|
80
|
+
"data-stack": (0, _zag_js_dom_query.dataAttr)(rootState.stacked),
|
|
81
|
+
"data-overlap": (0, _zag_js_dom_query.dataAttr)(!rootState.stacked),
|
|
82
|
+
"data-swiping": (0, _zag_js_dom_query.dataAttr)(rootState.swiping),
|
|
83
|
+
"data-swipe-direction": rootState.swipeDirection ?? void 0,
|
|
84
|
+
role: "status",
|
|
85
|
+
"aria-atomic": "true",
|
|
86
|
+
"aria-describedby": description && rendered.description ? require_toast_dom.getDescriptionId(scope) : void 0,
|
|
87
|
+
"aria-labelledby": title && rendered.title ? require_toast_dom.getTitleId(scope) : void 0,
|
|
88
|
+
tabIndex: 0,
|
|
89
|
+
style: require_toast_utils.getPlacementStyle(service, visible),
|
|
90
|
+
onKeyDown(event) {
|
|
91
|
+
if (event.defaultPrevented) return;
|
|
92
|
+
if (event.key == "Escape") {
|
|
93
|
+
send({
|
|
94
|
+
type: "DISMISS",
|
|
95
|
+
src: "keyboard"
|
|
96
|
+
});
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
onPointerDown(event) {
|
|
101
|
+
if (event.defaultPrevented || event.button !== 0) return;
|
|
102
|
+
if ((0, _zag_js_dom_query.getEventTarget)(event)?.closest(SWIPE_IGNORE_SELECTOR)) return;
|
|
103
|
+
send({
|
|
104
|
+
type: "SWIPE.START",
|
|
105
|
+
point: {
|
|
106
|
+
x: event.clientX,
|
|
107
|
+
y: event.clientY
|
|
108
|
+
},
|
|
109
|
+
pointerId: event.pointerId
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
getContentProps() {
|
|
115
|
+
const rootState = getRootState();
|
|
116
|
+
return normalize.element({
|
|
117
|
+
...require_toast_anatomy.parts.content.attrs(scope.id),
|
|
118
|
+
"data-state": rootState.visible ? "open" : "closed",
|
|
119
|
+
"data-first": (0, _zag_js_dom_query.dataAttr)(rootState.frontmost),
|
|
120
|
+
"data-sibling": (0, _zag_js_dom_query.dataAttr)(!rootState.frontmost),
|
|
121
|
+
"data-stack": (0, _zag_js_dom_query.dataAttr)(rootState.stacked),
|
|
122
|
+
"data-overlap": (0, _zag_js_dom_query.dataAttr)(!rootState.stacked)
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
getGhostBeforeProps() {
|
|
126
|
+
return normalize.element({
|
|
127
|
+
"data-ghost": "before",
|
|
128
|
+
style: require_toast_utils.getGhostBeforeStyle(service, visible)
|
|
129
|
+
});
|
|
130
|
+
},
|
|
131
|
+
getGhostAfterProps() {
|
|
132
|
+
return normalize.element({
|
|
133
|
+
"data-ghost": "after",
|
|
134
|
+
style: require_toast_utils.getGhostAfterStyle()
|
|
135
|
+
});
|
|
136
|
+
},
|
|
137
|
+
getTitleProps() {
|
|
138
|
+
return normalize.element({
|
|
139
|
+
...require_toast_anatomy.parts.title.attrs(scope.id),
|
|
140
|
+
id: require_toast_dom.getTitleId(scope)
|
|
141
|
+
});
|
|
142
|
+
},
|
|
143
|
+
getDescriptionProps() {
|
|
144
|
+
return normalize.element({
|
|
145
|
+
...require_toast_anatomy.parts.description.attrs(scope.id),
|
|
146
|
+
id: require_toast_dom.getDescriptionId(scope)
|
|
147
|
+
});
|
|
148
|
+
},
|
|
149
|
+
getActionTriggerProps() {
|
|
150
|
+
return normalize.button({
|
|
151
|
+
...require_toast_anatomy.parts.actionTrigger.attrs(scope.id),
|
|
152
|
+
type: "button",
|
|
153
|
+
onClick(event) {
|
|
154
|
+
if (event.defaultPrevented) return;
|
|
155
|
+
action?.onClick?.();
|
|
156
|
+
send({
|
|
157
|
+
type: "DISMISS",
|
|
158
|
+
src: "user"
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
},
|
|
163
|
+
getCloseTriggerProps() {
|
|
164
|
+
return normalize.button({
|
|
165
|
+
...require_toast_anatomy.parts.closeTrigger.attrs(scope.id),
|
|
166
|
+
type: "button",
|
|
167
|
+
"aria-label": translations?.closeTriggerLabel,
|
|
168
|
+
onClick(event) {
|
|
169
|
+
if (event.defaultPrevented) return;
|
|
170
|
+
send({
|
|
171
|
+
type: "DISMISS",
|
|
172
|
+
src: "user"
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
};
|
|
159
178
|
}
|
|
160
|
-
|
|
161
|
-
0 && (module.exports = {
|
|
162
|
-
connect
|
|
163
|
-
});
|
|
179
|
+
exports.connect = connect;
|