@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.
Files changed (45) 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 +82 -103
  8. package/dist/toast-group.connect.mjs +77 -67
  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 +295 -290
  12. package/dist/toast-group.machine.mjs +290 -254
  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 +176 -160
  20. package/dist/toast.connect.mjs +171 -124
  21. package/dist/toast.dom.d.mts +21 -14
  22. package/dist/toast.dom.d.ts +21 -14
  23. package/dist/toast.dom.js +50 -48
  24. package/dist/toast.dom.mjs +35 -17
  25. package/dist/toast.machine.d.mts +2 -8
  26. package/dist/toast.machine.d.ts +2 -8
  27. package/dist/toast.machine.js +404 -288
  28. package/dist/toast.machine.mjs +400 -253
  29. package/dist/toast.store.d.mts +2 -8
  30. package/dist/toast.store.d.ts +2 -8
  31. package/dist/toast.store.js +345 -263
  32. package/dist/toast.store.mjs +341 -238
  33. package/dist/toast.types.d.mts +460 -427
  34. package/dist/toast.types.d.ts +460 -427
  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 +185 -198
  40. package/dist/toast.utils.mjs +175 -168
  41. package/dist/utils/swipe.d.mts +16 -0
  42. package/dist/utils/swipe.d.ts +16 -0
  43. package/dist/utils/swipe.js +100 -0
  44. package/dist/utils/swipe.mjs +93 -0
  45. package/package.json +8 -8
@@ -1,15 +1,5 @@
1
- // src/toast.anatomy.ts
2
1
  import { createAnatomy } from "@zag-js/anatomy";
3
- var anatomy = createAnatomy("toast").parts(
4
- "group",
5
- "root",
6
- "title",
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 };
@@ -1,8 +1,4 @@
1
- import { Service } from '@zag-js/core';
2
- import { PropTypes, NormalizeProps } from '@zag-js/types';
3
- import { ToastSchema, ToastApi } from './toast.types.mjs';
4
- import '@zag-js/dom-query';
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>;
@@ -1,8 +1,4 @@
1
- import { Service } from '@zag-js/core';
2
- import { PropTypes, NormalizeProps } from '@zag-js/types';
3
- import { ToastSchema, ToastApi } from './toast.types.js';
4
- import '@zag-js/dom-query';
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>;
@@ -1,163 +1,179 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
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
- module.exports = __toCommonJS(toast_connect_exports);
36
- var import_dom_query = require("@zag-js/dom-query");
37
- var import_utils = require("@zag-js/utils");
38
- var import_toast = require("./toast.anatomy.js");
39
- var dom = __toESM(require("./toast.dom.js"));
40
- var import_toast2 = require("./toast.utils.js");
41
- var defaultTranslations = {
42
- closeTriggerLabel: "Dismiss notification"
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
- const { state, send, prop, scope, context, computed } = service;
46
- const translations = (0, import_utils.mergeWithDefault)(defaultTranslations, prop("translations"));
47
- const visible = state.hasTag("visible");
48
- const paused = state.hasTag("paused");
49
- const mounted = context.get("mounted");
50
- const frontmost = computed("frontmost");
51
- const placement = prop("parent").computed("placement");
52
- const type = prop("type");
53
- const stacked = prop("stacked");
54
- const title = prop("title");
55
- const description = prop("description");
56
- const action = prop("action");
57
- const [side, align = "center"] = placement.split("-");
58
- function getRootState() {
59
- return { visible, paused, mounted, frontmost, stacked: !!stacked, type, placement, side, align };
60
- }
61
- return {
62
- type,
63
- title,
64
- description,
65
- placement,
66
- visible,
67
- paused,
68
- closable: !!prop("closable"),
69
- pause() {
70
- send({ type: "PAUSE" });
71
- },
72
- resume() {
73
- send({ type: "RESUME" });
74
- },
75
- dismiss() {
76
- send({ type: "DISMISS", src: "programmatic" });
77
- },
78
- getRootState,
79
- getRootProps() {
80
- const rootState = getRootState();
81
- return normalize.element({
82
- ...import_toast.parts.root.attrs(scope.id),
83
- dir: prop("dir"),
84
- "data-state": rootState.visible ? "open" : "closed",
85
- "data-type": rootState.type,
86
- "data-placement": rootState.placement,
87
- "data-align": rootState.align,
88
- "data-side": rootState.side,
89
- "data-mounted": (0, import_dom_query.dataAttr)(rootState.mounted),
90
- "data-paused": (0, import_dom_query.dataAttr)(rootState.paused),
91
- "data-first": (0, import_dom_query.dataAttr)(rootState.frontmost),
92
- "data-sibling": (0, import_dom_query.dataAttr)(!rootState.frontmost),
93
- "data-stack": (0, import_dom_query.dataAttr)(rootState.stacked),
94
- "data-overlap": (0, import_dom_query.dataAttr)(!rootState.stacked),
95
- role: "status",
96
- "aria-atomic": "true",
97
- "aria-describedby": description ? dom.getDescriptionId(scope) : void 0,
98
- "aria-labelledby": title ? dom.getTitleId(scope) : void 0,
99
- tabIndex: 0,
100
- style: (0, import_toast2.getPlacementStyle)(service, visible),
101
- onKeyDown(event) {
102
- if (event.defaultPrevented) return;
103
- if (event.key == "Escape") {
104
- send({ type: "DISMISS", src: "keyboard" });
105
- event.preventDefault();
106
- }
107
- }
108
- });
109
- },
110
- /* Leave a ghost div to avoid setting hover to false when transitioning out */
111
- getGhostBeforeProps() {
112
- return normalize.element({
113
- "data-ghost": "before",
114
- style: (0, import_toast2.getGhostBeforeStyle)(service, visible)
115
- });
116
- },
117
- /* Needed to avoid setting hover to false when in between toasts */
118
- getGhostAfterProps() {
119
- return normalize.element({
120
- "data-ghost": "after",
121
- style: (0, import_toast2.getGhostAfterStyle)()
122
- });
123
- },
124
- getTitleProps() {
125
- return normalize.element({
126
- ...import_toast.parts.title.attrs(scope.id),
127
- id: dom.getTitleId(scope)
128
- });
129
- },
130
- getDescriptionProps() {
131
- return normalize.element({
132
- ...import_toast.parts.description.attrs(scope.id),
133
- id: dom.getDescriptionId(scope)
134
- });
135
- },
136
- getActionTriggerProps() {
137
- return normalize.button({
138
- ...import_toast.parts.actionTrigger.attrs(scope.id),
139
- type: "button",
140
- onClick(event) {
141
- if (event.defaultPrevented) return;
142
- action?.onClick?.();
143
- send({ type: "DISMISS", src: "user" });
144
- }
145
- });
146
- },
147
- getCloseTriggerProps() {
148
- return normalize.button({
149
- ...import_toast.parts.closeTrigger.attrs(scope.id),
150
- type: "button",
151
- "aria-label": translations?.closeTriggerLabel,
152
- onClick(event) {
153
- if (event.defaultPrevented) return;
154
- send({ type: "DISMISS", src: "user" });
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
- // Annotate the CommonJS export names for ESM import in node:
161
- 0 && (module.exports = {
162
- connect
163
- });
179
+ exports.connect = connect;