@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,16 +1,21 @@
1
- import { Scope } from '@zag-js/core';
2
- import { Placement } from './toast.types.js';
3
- import '@zag-js/types';
4
- import '@zag-js/dom-query';
5
-
6
- declare const getRegionId: (placement: Placement) => string;
7
- declare const getRegionEl: (ctx: Scope, placement: Placement) => HTMLElement | null;
8
- declare const getRootId: (ctx: Scope) => string;
9
- declare const getRootEl: (ctx: Scope) => HTMLElement | null;
10
- declare const getTitleId: (ctx: Scope) => string;
11
- declare const getDescriptionId: (ctx: Scope) => string;
12
- declare const getTitleEl: (ctx: Scope) => HTMLElement | null;
13
- declare const getDescriptionEl: (ctx: Scope) => HTMLElement | null;
14
- declare const getCloseTriggerId: (ctx: Scope) => string;
15
-
16
- export { getCloseTriggerId, getDescriptionEl, getDescriptionId, getRegionEl, getRegionId, getRootEl, getRootId, getTitleEl, getTitleId };
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 getRegionEl: (ctx: Scope, placement: Placement) => HTMLElement | null;
5
+ export declare const getToastEls: (ctx: Scope, placement: Placement) => HTMLElement[];
6
+ export declare const getRootId: (ctx: Scope) => string;
7
+ export declare const getRootEl: (ctx: Scope) => HTMLElement | null;
8
+ export declare const getTitleId: (ctx: Scope) => string;
9
+ export declare const getDescriptionId: (ctx: Scope) => string;
10
+ export declare const getTitleEl: (ctx: Scope) => HTMLElement | null;
11
+ export declare const getDescriptionEl: (ctx: Scope) => HTMLElement | null;
12
+ export declare const getCloseTriggerId: (ctx: Scope) => string;
13
+ interface ObserveContentOptions {
14
+ filter?: ((el: Element) => boolean) | undefined;
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(rootEl: HTMLElement, options: ObserveContentOptions): () => void;
21
+ export {};
package/dist/toast.dom.js CHANGED
@@ -1,54 +1,57 @@
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.dom.ts
21
- var toast_dom_exports = {};
22
- __export(toast_dom_exports, {
23
- getCloseTriggerId: () => getCloseTriggerId,
24
- getDescriptionEl: () => getDescriptionEl,
25
- getDescriptionId: () => getDescriptionId,
26
- getRegionEl: () => getRegionEl,
27
- getRegionId: () => getRegionId,
28
- getRootEl: () => getRootEl,
29
- getRootId: () => getRootId,
30
- getTitleEl: () => getTitleEl,
31
- getTitleId: () => getTitleId
32
- });
33
- module.exports = __toCommonJS(toast_dom_exports);
34
- var getRegionId = (placement) => `toast-group:${placement}`;
35
- var getRegionEl = (ctx, placement) => ctx.getById(`toast-group:${placement}`);
36
- var getRootId = (ctx) => `toast:${ctx.id}`;
37
- var getRootEl = (ctx) => ctx.getById(getRootId(ctx));
38
- var getTitleId = (ctx) => `toast:${ctx.id}:title`;
39
- var getDescriptionId = (ctx) => `toast:${ctx.id}:description`;
40
- var getTitleEl = (ctx) => ctx.getById(getTitleId(ctx));
41
- var getDescriptionEl = (ctx) => ctx.getById(getDescriptionId(ctx));
42
- var getCloseTriggerId = (ctx) => `toast${ctx.id}:close`;
43
- // Annotate the CommonJS export names for ESM import in node:
44
- 0 && (module.exports = {
45
- getCloseTriggerId,
46
- getDescriptionEl,
47
- getDescriptionId,
48
- getRegionEl,
49
- getRegionId,
50
- getRootEl,
51
- getRootId,
52
- getTitleEl,
53
- getTitleId
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
54
4
  });
5
+ let _zag_js_dom_query = require("@zag-js/dom-query");
6
+ let _zag_js_utils = require("@zag-js/utils");
7
+ // src/toast.dom.ts
8
+ const getRegionId = (placement) => `toast-group:${placement}`;
9
+ const getRegionEl = (ctx, placement) => ctx.getById(`toast-group:${placement}`);
10
+ const getToastEls = (ctx, placement) => (0, _zag_js_dom_query.queryAll)(getRegionEl(ctx, placement), "[data-scope=toast][data-part=root]");
11
+ const getRootId = (ctx) => `toast:${ctx.id}`;
12
+ const getRootEl = (ctx) => ctx.getById(getRootId(ctx));
13
+ const getTitleId = (ctx) => `toast:${ctx.id}:title`;
14
+ const getDescriptionId = (ctx) => `toast:${ctx.id}:description`;
15
+ const getTitleEl = (ctx) => ctx.getById(getTitleId(ctx));
16
+ const getDescriptionEl = (ctx) => ctx.getById(getDescriptionId(ctx));
17
+ const getCloseTriggerId = (ctx) => `toast${ctx.id}:close`;
18
+ function observeContent(rootEl, options) {
19
+ const { filter = () => true, onChange, onMutate } = options;
20
+ const win = (0, _zag_js_dom_query.getWindow)(rootEl);
21
+ const frame = _zag_js_dom_query.AnimationFrame.create();
22
+ const notify = () => frame.request(onChange);
23
+ let stopObservingChildren;
24
+ const observeChildren = () => {
25
+ stopObservingChildren?.();
26
+ const children = Array.from(rootEl.children).filter(filter);
27
+ stopObservingChildren = (0, _zag_js_utils.callAll)(...children.map((child) => _zag_js_dom_query.resizeObserverBorderBox.observe(child, notify)));
28
+ };
29
+ observeChildren();
30
+ const mutationObserver = new win.MutationObserver(() => {
31
+ frame.cancel();
32
+ onChange();
33
+ onMutate?.();
34
+ observeChildren();
35
+ });
36
+ mutationObserver.observe(rootEl, {
37
+ childList: true,
38
+ subtree: true,
39
+ characterData: true
40
+ });
41
+ return () => {
42
+ mutationObserver.disconnect();
43
+ stopObservingChildren?.();
44
+ frame.cancel();
45
+ };
46
+ }
47
+ exports.getCloseTriggerId = getCloseTriggerId;
48
+ exports.getDescriptionEl = getDescriptionEl;
49
+ exports.getDescriptionId = getDescriptionId;
50
+ exports.getRegionEl = getRegionEl;
51
+ exports.getRegionId = getRegionId;
52
+ exports.getRootEl = getRootEl;
53
+ exports.getRootId = getRootId;
54
+ exports.getTitleEl = getTitleEl;
55
+ exports.getTitleId = getTitleId;
56
+ exports.getToastEls = getToastEls;
57
+ exports.observeContent = observeContent;
@@ -1,21 +1,43 @@
1
+ import { AnimationFrame, getWindow, queryAll, resizeObserverBorderBox } from "@zag-js/dom-query";
2
+ import { callAll } from "@zag-js/utils";
1
3
  // src/toast.dom.ts
2
- var getRegionId = (placement) => `toast-group:${placement}`;
3
- var getRegionEl = (ctx, placement) => ctx.getById(`toast-group:${placement}`);
4
- var getRootId = (ctx) => `toast:${ctx.id}`;
5
- var getRootEl = (ctx) => ctx.getById(getRootId(ctx));
6
- var getTitleId = (ctx) => `toast:${ctx.id}:title`;
7
- var getDescriptionId = (ctx) => `toast:${ctx.id}:description`;
8
- var getTitleEl = (ctx) => ctx.getById(getTitleId(ctx));
9
- var getDescriptionEl = (ctx) => ctx.getById(getDescriptionId(ctx));
10
- var getCloseTriggerId = (ctx) => `toast${ctx.id}:close`;
11
- export {
12
- getCloseTriggerId,
13
- getDescriptionEl,
14
- getDescriptionId,
15
- getRegionEl,
16
- getRegionId,
17
- getRootEl,
18
- getRootId,
19
- getTitleEl,
20
- getTitleId
21
- };
4
+ const getRegionId = (placement) => `toast-group:${placement}`;
5
+ const getRegionEl = (ctx, placement) => ctx.getById(`toast-group:${placement}`);
6
+ const getToastEls = (ctx, placement) => queryAll(getRegionEl(ctx, placement), "[data-scope=toast][data-part=root]");
7
+ const getRootId = (ctx) => `toast:${ctx.id}`;
8
+ const getRootEl = (ctx) => ctx.getById(getRootId(ctx));
9
+ const getTitleId = (ctx) => `toast:${ctx.id}:title`;
10
+ const getDescriptionId = (ctx) => `toast:${ctx.id}:description`;
11
+ const getTitleEl = (ctx) => ctx.getById(getTitleId(ctx));
12
+ const getDescriptionEl = (ctx) => ctx.getById(getDescriptionId(ctx));
13
+ const getCloseTriggerId = (ctx) => `toast${ctx.id}:close`;
14
+ function observeContent(rootEl, options) {
15
+ const { filter = () => true, onChange, onMutate } = options;
16
+ const win = getWindow(rootEl);
17
+ const frame = AnimationFrame.create();
18
+ const notify = () => frame.request(onChange);
19
+ let stopObservingChildren;
20
+ const observeChildren = () => {
21
+ stopObservingChildren?.();
22
+ const children = Array.from(rootEl.children).filter(filter);
23
+ stopObservingChildren = callAll(...children.map((child) => resizeObserverBorderBox.observe(child, notify)));
24
+ };
25
+ observeChildren();
26
+ const mutationObserver = new win.MutationObserver(() => {
27
+ frame.cancel();
28
+ onChange();
29
+ onMutate?.();
30
+ observeChildren();
31
+ });
32
+ mutationObserver.observe(rootEl, {
33
+ childList: true,
34
+ subtree: true,
35
+ characterData: true
36
+ });
37
+ return () => {
38
+ mutationObserver.disconnect();
39
+ stopObservingChildren?.();
40
+ frame.cancel();
41
+ };
42
+ }
43
+ export { getCloseTriggerId, getDescriptionEl, getDescriptionId, getRegionEl, getRegionId, getRootEl, getRootId, getTitleEl, getTitleId, getToastEls, observeContent };
@@ -1,8 +1,2 @@
1
- import * as _zag_js_core from '@zag-js/core';
2
- import { ToastSchema } from './toast.types.mjs';
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>;
@@ -1,8 +1,2 @@
1
- import * as _zag_js_core from '@zag-js/core';
2
- import { ToastSchema } from './toast.types.js';
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>;