@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.connect.mjs
CHANGED
|
@@ -1,128 +1,175 @@
|
|
|
1
|
-
// src/toast.connect.ts
|
|
2
|
-
import { dataAttr } from "@zag-js/dom-query";
|
|
3
|
-
import { mergeWithDefault } from "@zag-js/utils";
|
|
4
1
|
import { parts } from "./toast.anatomy.mjs";
|
|
5
|
-
import
|
|
2
|
+
import { getDescriptionId, getTitleId } from "./toast.dom.mjs";
|
|
6
3
|
import { getGhostAfterStyle, getGhostBeforeStyle, getPlacementStyle } from "./toast.utils.mjs";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
import { dataAttr, getEventTarget } from "@zag-js/dom-query";
|
|
5
|
+
import { mergeWithDefault } from "@zag-js/utils";
|
|
6
|
+
// src/toast.connect.ts
|
|
7
|
+
const defaultTranslations = { closeTriggerLabel: "Dismiss notification" };
|
|
8
|
+
const SWIPE_IGNORE_SELECTOR = "button,a,input,textarea,select,[role=\"button\"],[data-swipe-ignore]";
|
|
10
9
|
function connect(service, normalize) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
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
|
-
|
|
10
|
+
const { state, send, prop, scope, context, computed } = service;
|
|
11
|
+
const translations = mergeWithDefault(defaultTranslations, prop("translations"));
|
|
12
|
+
const visible = state.hasTag("visible");
|
|
13
|
+
const paused = state.hasTag("paused");
|
|
14
|
+
const mounted = context.get("mounted");
|
|
15
|
+
const rendered = context.get("rendered");
|
|
16
|
+
const frontmost = computed("frontmost");
|
|
17
|
+
const placement = prop("parent").computed("placement");
|
|
18
|
+
const type = prop("type");
|
|
19
|
+
const stacked = prop("parent").state.matches("stack");
|
|
20
|
+
const title = prop("title");
|
|
21
|
+
const description = prop("description");
|
|
22
|
+
const action = prop("action");
|
|
23
|
+
const [side, align = "center"] = placement.split("-");
|
|
24
|
+
const swiping = state.matches("visible:swiping");
|
|
25
|
+
const swipeDirection = context.get("swipeDirection");
|
|
26
|
+
function getRootState() {
|
|
27
|
+
return {
|
|
28
|
+
visible,
|
|
29
|
+
paused,
|
|
30
|
+
mounted,
|
|
31
|
+
frontmost,
|
|
32
|
+
stacked: !!stacked,
|
|
33
|
+
type,
|
|
34
|
+
placement,
|
|
35
|
+
side,
|
|
36
|
+
align,
|
|
37
|
+
swiping,
|
|
38
|
+
swipeDirection
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
type,
|
|
43
|
+
title,
|
|
44
|
+
description,
|
|
45
|
+
placement,
|
|
46
|
+
visible,
|
|
47
|
+
paused,
|
|
48
|
+
closable: !!prop("closable"),
|
|
49
|
+
pause() {
|
|
50
|
+
prop("parent").prop("store").pause(prop("id"));
|
|
51
|
+
},
|
|
52
|
+
resume() {
|
|
53
|
+
prop("parent").prop("store").resume(prop("id"));
|
|
54
|
+
},
|
|
55
|
+
dismiss() {
|
|
56
|
+
send({
|
|
57
|
+
type: "DISMISS",
|
|
58
|
+
src: "programmatic"
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
getRootState,
|
|
62
|
+
getRootProps() {
|
|
63
|
+
const rootState = getRootState();
|
|
64
|
+
return normalize.element({
|
|
65
|
+
...parts.root.attrs(scope.id),
|
|
66
|
+
dir: prop("dir"),
|
|
67
|
+
"data-state": rootState.visible ? "open" : "closed",
|
|
68
|
+
"data-type": rootState.type,
|
|
69
|
+
"data-placement": rootState.placement,
|
|
70
|
+
"data-align": rootState.align,
|
|
71
|
+
"data-side": rootState.side,
|
|
72
|
+
"data-mounted": dataAttr(rootState.mounted),
|
|
73
|
+
"data-paused": dataAttr(rootState.paused),
|
|
74
|
+
"data-first": dataAttr(rootState.frontmost),
|
|
75
|
+
"data-sibling": dataAttr(!rootState.frontmost),
|
|
76
|
+
"data-stack": dataAttr(rootState.stacked),
|
|
77
|
+
"data-overlap": dataAttr(!rootState.stacked),
|
|
78
|
+
"data-swiping": dataAttr(rootState.swiping),
|
|
79
|
+
"data-swipe-direction": rootState.swipeDirection ?? void 0,
|
|
80
|
+
role: "status",
|
|
81
|
+
"aria-atomic": "true",
|
|
82
|
+
"aria-describedby": description && rendered.description ? getDescriptionId(scope) : void 0,
|
|
83
|
+
"aria-labelledby": title && rendered.title ? getTitleId(scope) : void 0,
|
|
84
|
+
tabIndex: 0,
|
|
85
|
+
style: getPlacementStyle(service, visible),
|
|
86
|
+
onKeyDown(event) {
|
|
87
|
+
if (event.defaultPrevented) return;
|
|
88
|
+
if (event.key == "Escape") {
|
|
89
|
+
send({
|
|
90
|
+
type: "DISMISS",
|
|
91
|
+
src: "keyboard"
|
|
92
|
+
});
|
|
93
|
+
event.preventDefault();
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
onPointerDown(event) {
|
|
97
|
+
if (event.defaultPrevented || event.button !== 0) return;
|
|
98
|
+
if (getEventTarget(event)?.closest(SWIPE_IGNORE_SELECTOR)) return;
|
|
99
|
+
send({
|
|
100
|
+
type: "SWIPE.START",
|
|
101
|
+
point: {
|
|
102
|
+
x: event.clientX,
|
|
103
|
+
y: event.clientY
|
|
104
|
+
},
|
|
105
|
+
pointerId: event.pointerId
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
getContentProps() {
|
|
111
|
+
const rootState = getRootState();
|
|
112
|
+
return normalize.element({
|
|
113
|
+
...parts.content.attrs(scope.id),
|
|
114
|
+
"data-state": rootState.visible ? "open" : "closed",
|
|
115
|
+
"data-first": dataAttr(rootState.frontmost),
|
|
116
|
+
"data-sibling": dataAttr(!rootState.frontmost),
|
|
117
|
+
"data-stack": dataAttr(rootState.stacked),
|
|
118
|
+
"data-overlap": dataAttr(!rootState.stacked)
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
getGhostBeforeProps() {
|
|
122
|
+
return normalize.element({
|
|
123
|
+
"data-ghost": "before",
|
|
124
|
+
style: getGhostBeforeStyle(service, visible)
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
getGhostAfterProps() {
|
|
128
|
+
return normalize.element({
|
|
129
|
+
"data-ghost": "after",
|
|
130
|
+
style: getGhostAfterStyle()
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
getTitleProps() {
|
|
134
|
+
return normalize.element({
|
|
135
|
+
...parts.title.attrs(scope.id),
|
|
136
|
+
id: getTitleId(scope)
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
getDescriptionProps() {
|
|
140
|
+
return normalize.element({
|
|
141
|
+
...parts.description.attrs(scope.id),
|
|
142
|
+
id: getDescriptionId(scope)
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
getActionTriggerProps() {
|
|
146
|
+
return normalize.button({
|
|
147
|
+
...parts.actionTrigger.attrs(scope.id),
|
|
148
|
+
type: "button",
|
|
149
|
+
onClick(event) {
|
|
150
|
+
if (event.defaultPrevented) return;
|
|
151
|
+
action?.onClick?.();
|
|
152
|
+
send({
|
|
153
|
+
type: "DISMISS",
|
|
154
|
+
src: "user"
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
},
|
|
159
|
+
getCloseTriggerProps() {
|
|
160
|
+
return normalize.button({
|
|
161
|
+
...parts.closeTrigger.attrs(scope.id),
|
|
162
|
+
type: "button",
|
|
163
|
+
"aria-label": translations?.closeTriggerLabel,
|
|
164
|
+
onClick(event) {
|
|
165
|
+
if (event.defaultPrevented) return;
|
|
166
|
+
send({
|
|
167
|
+
type: "DISMISS",
|
|
168
|
+
src: "user"
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
};
|
|
125
174
|
}
|
|
126
|
-
export {
|
|
127
|
-
connect
|
|
128
|
-
};
|
|
175
|
+
export { connect };
|
package/dist/toast.dom.d.mts
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
declare const
|
|
7
|
-
declare const
|
|
8
|
-
declare const
|
|
9
|
-
declare const
|
|
10
|
-
declare const
|
|
11
|
-
declare const
|
|
12
|
-
declare const
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { Placement } from "./toast.types.mjs";
|
|
2
|
+
import { Scope } from "@zag-js/core";
|
|
3
|
+
export declare const getRegionId: (placement: Placement) => string;
|
|
4
|
+
export declare const getRootId: (ctx: Scope) => string;
|
|
5
|
+
export declare const getTitleId: (ctx: Scope) => string;
|
|
6
|
+
export declare const getDescriptionId: (ctx: Scope) => string;
|
|
7
|
+
export declare const getCloseTriggerId: (ctx: Scope) => string;
|
|
8
|
+
export declare const getRegionEl: (ctx: Scope, placement: Placement) => HTMLElement | null;
|
|
9
|
+
export declare const getToastEls: (ctx: Scope, placement: Placement) => HTMLElement[];
|
|
10
|
+
export declare const getRootEl: (ctx: Scope) => HTMLElement | null;
|
|
11
|
+
export declare const getContentEl: (ctx: Scope) => HTMLElement | null;
|
|
12
|
+
export declare const getTitleEl: (ctx: Scope) => HTMLElement | null;
|
|
13
|
+
export declare const getDescriptionEl: (ctx: Scope) => HTMLElement | null;
|
|
14
|
+
interface ObserveContentOptions {
|
|
15
|
+
/** Called when the content's size may have changed */
|
|
16
|
+
onChange: VoidFunction;
|
|
17
|
+
/** Called when the content's DOM changes */
|
|
18
|
+
onMutate?: VoidFunction | undefined;
|
|
19
|
+
}
|
|
20
|
+
export declare function observeContent(contentEl: HTMLElement, options: ObserveContentOptions): () => void;
|
|
21
|
+
export {};
|
package/dist/toast.dom.d.ts
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
declare const
|
|
7
|
-
declare const
|
|
8
|
-
declare const
|
|
9
|
-
declare const
|
|
10
|
-
declare const
|
|
11
|
-
declare const
|
|
12
|
-
declare const
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { Placement } from "./toast.types.js";
|
|
2
|
+
import { Scope } from "@zag-js/core";
|
|
3
|
+
export declare const getRegionId: (placement: Placement) => string;
|
|
4
|
+
export declare const getRootId: (ctx: Scope) => string;
|
|
5
|
+
export declare const getTitleId: (ctx: Scope) => string;
|
|
6
|
+
export declare const getDescriptionId: (ctx: Scope) => string;
|
|
7
|
+
export declare const getCloseTriggerId: (ctx: Scope) => string;
|
|
8
|
+
export declare const getRegionEl: (ctx: Scope, placement: Placement) => HTMLElement | null;
|
|
9
|
+
export declare const getToastEls: (ctx: Scope, placement: Placement) => HTMLElement[];
|
|
10
|
+
export declare const getRootEl: (ctx: Scope) => HTMLElement | null;
|
|
11
|
+
export declare const getContentEl: (ctx: Scope) => HTMLElement | null;
|
|
12
|
+
export declare const getTitleEl: (ctx: Scope) => HTMLElement | null;
|
|
13
|
+
export declare const getDescriptionEl: (ctx: Scope) => HTMLElement | null;
|
|
14
|
+
interface ObserveContentOptions {
|
|
15
|
+
/** Called when the content's size may have changed */
|
|
16
|
+
onChange: VoidFunction;
|
|
17
|
+
/** Called when the content's DOM changes */
|
|
18
|
+
onMutate?: VoidFunction | undefined;
|
|
19
|
+
}
|
|
20
|
+
export declare function observeContent(contentEl: HTMLElement, options: ObserveContentOptions): () => void;
|
|
21
|
+
export {};
|
package/dist/toast.dom.js
CHANGED
|
@@ -1,49 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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.dom.ts
|
|
21
|
-
var toast_dom_exports = {};
|
|
22
|
-
__export(toast_dom_exports, {
|
|
23
|
-
getCloseTriggerId: () => getCloseTriggerId,
|
|
24
|
-
getDescriptionId: () => getDescriptionId,
|
|
25
|
-
getRegionEl: () => getRegionEl,
|
|
26
|
-
getRegionId: () => getRegionId,
|
|
27
|
-
getRootEl: () => getRootEl,
|
|
28
|
-
getRootId: () => getRootId,
|
|
29
|
-
getTitleId: () => getTitleId
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(toast_dom_exports);
|
|
32
|
-
var import_toast = require("./toast.anatomy.js");
|
|
33
|
-
var getRegionId = (placement) => `toast-group-${placement}`;
|
|
34
|
-
var getRootId = (ctx) => `${ctx.id}`;
|
|
35
|
-
var getTitleId = (ctx) => `${ctx.id}:title`;
|
|
36
|
-
var getDescriptionId = (ctx) => `${ctx.id}:description`;
|
|
37
|
-
var getCloseTriggerId = (ctx) => `${ctx.id}:close`;
|
|
38
|
-
var getRegionEl = (ctx, placement) => ctx.getById(`toast-group-${placement}`);
|
|
39
|
-
var getRootEl = (ctx) => ctx.query(ctx.selector(import_toast.parts.root));
|
|
40
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
-
0 && (module.exports = {
|
|
42
|
-
getCloseTriggerId,
|
|
43
|
-
getDescriptionId,
|
|
44
|
-
getRegionEl,
|
|
45
|
-
getRegionId,
|
|
46
|
-
getRootEl,
|
|
47
|
-
getRootId,
|
|
48
|
-
getTitleId
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
49
4
|
});
|
|
5
|
+
const require_toast_anatomy = require("./toast.anatomy.js");
|
|
6
|
+
let _zag_js_dom_query = require("@zag-js/dom-query");
|
|
7
|
+
// src/toast.dom.ts
|
|
8
|
+
const getRegionId = (placement) => `toast-group-${placement}`;
|
|
9
|
+
const getRootId = (ctx) => `${ctx.id}`;
|
|
10
|
+
const getTitleId = (ctx) => `${ctx.id}:title`;
|
|
11
|
+
const getDescriptionId = (ctx) => `${ctx.id}:description`;
|
|
12
|
+
const getCloseTriggerId = (ctx) => `${ctx.id}:close`;
|
|
13
|
+
const getRegionEl = (ctx, placement) => ctx.getById(`toast-group-${placement}`);
|
|
14
|
+
const getToastEls = (ctx, placement) => (0, _zag_js_dom_query.queryAll)(getRegionEl(ctx, placement), `[${require_toast_anatomy.parts.root.attr}]`);
|
|
15
|
+
const getRootEl = (ctx) => ctx.query(ctx.selector(require_toast_anatomy.parts.root));
|
|
16
|
+
const getContentEl = (ctx) => ctx.query(ctx.selector(require_toast_anatomy.parts.content));
|
|
17
|
+
const getTitleEl = (ctx) => ctx.query(ctx.selector(require_toast_anatomy.parts.title));
|
|
18
|
+
const getDescriptionEl = (ctx) => ctx.query(ctx.selector(require_toast_anatomy.parts.description));
|
|
19
|
+
function observeContent(contentEl, options) {
|
|
20
|
+
const { onChange, onMutate } = options;
|
|
21
|
+
const win = (0, _zag_js_dom_query.getWindow)(contentEl);
|
|
22
|
+
const frame = _zag_js_dom_query.AnimationFrame.create();
|
|
23
|
+
const stopResizeObserver = _zag_js_dom_query.resizeObserverBorderBox.observe(contentEl, () => frame.request(onChange));
|
|
24
|
+
const mutationObserver = new win.MutationObserver(() => {
|
|
25
|
+
frame.cancel();
|
|
26
|
+
onChange();
|
|
27
|
+
onMutate?.();
|
|
28
|
+
});
|
|
29
|
+
mutationObserver.observe(contentEl, {
|
|
30
|
+
childList: true,
|
|
31
|
+
subtree: true,
|
|
32
|
+
characterData: true
|
|
33
|
+
});
|
|
34
|
+
return () => {
|
|
35
|
+
mutationObserver.disconnect();
|
|
36
|
+
stopResizeObserver();
|
|
37
|
+
frame.cancel();
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
exports.getCloseTriggerId = getCloseTriggerId;
|
|
41
|
+
exports.getContentEl = getContentEl;
|
|
42
|
+
exports.getDescriptionEl = getDescriptionEl;
|
|
43
|
+
exports.getDescriptionId = getDescriptionId;
|
|
44
|
+
exports.getRegionEl = getRegionEl;
|
|
45
|
+
exports.getRegionId = getRegionId;
|
|
46
|
+
exports.getRootEl = getRootEl;
|
|
47
|
+
exports.getRootId = getRootId;
|
|
48
|
+
exports.getTitleEl = getTitleEl;
|
|
49
|
+
exports.getTitleId = getTitleId;
|
|
50
|
+
exports.getToastEls = getToastEls;
|
|
51
|
+
exports.observeContent = observeContent;
|
package/dist/toast.dom.mjs
CHANGED
|
@@ -1,18 +1,36 @@
|
|
|
1
|
-
// src/toast.dom.ts
|
|
2
1
|
import { parts } from "./toast.anatomy.mjs";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
2
|
+
import { AnimationFrame, getWindow, queryAll, resizeObserverBorderBox } from "@zag-js/dom-query";
|
|
3
|
+
// src/toast.dom.ts
|
|
4
|
+
const getRegionId = (placement) => `toast-group-${placement}`;
|
|
5
|
+
const getRootId = (ctx) => `${ctx.id}`;
|
|
6
|
+
const getTitleId = (ctx) => `${ctx.id}:title`;
|
|
7
|
+
const getDescriptionId = (ctx) => `${ctx.id}:description`;
|
|
8
|
+
const getCloseTriggerId = (ctx) => `${ctx.id}:close`;
|
|
9
|
+
const getRegionEl = (ctx, placement) => ctx.getById(`toast-group-${placement}`);
|
|
10
|
+
const getToastEls = (ctx, placement) => queryAll(getRegionEl(ctx, placement), `[${parts.root.attr}]`);
|
|
11
|
+
const getRootEl = (ctx) => ctx.query(ctx.selector(parts.root));
|
|
12
|
+
const getContentEl = (ctx) => ctx.query(ctx.selector(parts.content));
|
|
13
|
+
const getTitleEl = (ctx) => ctx.query(ctx.selector(parts.title));
|
|
14
|
+
const getDescriptionEl = (ctx) => ctx.query(ctx.selector(parts.description));
|
|
15
|
+
function observeContent(contentEl, options) {
|
|
16
|
+
const { onChange, onMutate } = options;
|
|
17
|
+
const win = getWindow(contentEl);
|
|
18
|
+
const frame = AnimationFrame.create();
|
|
19
|
+
const stopResizeObserver = resizeObserverBorderBox.observe(contentEl, () => frame.request(onChange));
|
|
20
|
+
const mutationObserver = new win.MutationObserver(() => {
|
|
21
|
+
frame.cancel();
|
|
22
|
+
onChange();
|
|
23
|
+
onMutate?.();
|
|
24
|
+
});
|
|
25
|
+
mutationObserver.observe(contentEl, {
|
|
26
|
+
childList: true,
|
|
27
|
+
subtree: true,
|
|
28
|
+
characterData: true
|
|
29
|
+
});
|
|
30
|
+
return () => {
|
|
31
|
+
mutationObserver.disconnect();
|
|
32
|
+
stopResizeObserver();
|
|
33
|
+
frame.cancel();
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export { getCloseTriggerId, getContentEl, getDescriptionEl, getDescriptionId, getRegionEl, getRegionId, getRootEl, getRootId, getTitleEl, getTitleId, getToastEls, observeContent };
|
package/dist/toast.machine.d.mts
CHANGED
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import '@zag-js/types';
|
|
4
|
-
import '@zag-js/dom-query';
|
|
5
|
-
|
|
6
|
-
declare const machine: _zag_js_core.Machine<ToastSchema>;
|
|
7
|
-
|
|
8
|
-
export { machine };
|
|
1
|
+
import { ToastSchema } from "./toast.types.mjs";
|
|
2
|
+
export declare const machine: import("@zag-js/core").Machine<ToastSchema>;
|
package/dist/toast.machine.d.ts
CHANGED
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import '@zag-js/types';
|
|
4
|
-
import '@zag-js/dom-query';
|
|
5
|
-
|
|
6
|
-
declare const machine: _zag_js_core.Machine<ToastSchema>;
|
|
7
|
-
|
|
8
|
-
export { machine };
|
|
1
|
+
import { ToastSchema } from "./toast.types.js";
|
|
2
|
+
export declare const machine: import("@zag-js/core").Machine<ToastSchema>;
|