Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zag-js/toast

Package Overview
Dependencies
Maintainers
1
Versions
1019
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zag-js/toast - npm Package Compare versions

Comparing version 0.0.0-dev-20220413175519 to 0.0.0-dev-20220415160434

823

dist/index.js

@@ -58,10 +58,3 @@ var __defProp = Object.defineProperty;

// ../../utilities/core/src/array.ts
function clear(v) {
while (v.length > 0)
v.pop();
return v;
}
// ../../utilities/core/src/functions.ts
// ../../utilities/core/dist/index.mjs
var runIfFn = (v, ...a) => {

@@ -71,22 +64,3 @@ const res = typeof v === "function" ? v(...a) : v;

};
var cast = (v) => v;
var noop = () => {
};
var uuid = /* @__PURE__ */ (() => {
let id = 0;
return () => {
id++;
return id.toString(36);
};
})();
// ../../utilities/core/src/guard.ts
var isDom = () => !!(typeof window !== "undefined");
var isArray = (v) => Array.isArray(v);
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
var isNumber = (v) => typeof v === "number" && !Number.isNaN(v);
var isString = (v) => typeof v === "string";
var isFunction = (v) => typeof v === "function";
// ../../utilities/core/src/warning.ts
function warn(...a) {

@@ -99,717 +73,7 @@ const m = a.length === 1 ? a[0] : a[1];

}
function invariant(...a) {
const m = a.length === 1 ? a[0] : a[1];
const c = a.length === 2 ? a[0] : true;
if (c && void 0 !== "production") {
throw new Error(m);
}
}
// ../../../node_modules/@zag-js/core/src/index.ts
var import_vanilla3 = require("valtio/vanilla");
// src/toast-group.connect.ts
var import_core = require("@zag-js/core");
// ../../core/src/action-utils.ts
function isGuardHelper(value) {
return isObject(value) && value.predicate != null;
}
function determineActionsFn(values, guardMap) {
return (context, event) => {
if (isGuardHelper(values))
return values.predicate(guardMap != null ? guardMap : {})(context, event);
return values;
};
}
// ../../core/src/guard-utils.ts
function or(...conditions) {
return {
predicate: (guards2) => (ctx, event) => conditions.map((condition) => {
var _a;
if (isString(condition)) {
return !!((_a = guards2[condition]) == null ? void 0 : _a.call(guards2, ctx, event));
}
if (isFunction(condition)) {
return condition(ctx, event);
}
return condition.predicate(guards2)(ctx, event);
}).some(Boolean)
};
}
function and(...conditions) {
return {
predicate: (guards2) => (ctx, event) => conditions.map((condition) => {
var _a;
if (isString(condition)) {
return !!((_a = guards2[condition]) == null ? void 0 : _a.call(guards2, ctx, event));
}
if (isFunction(condition)) {
return condition(ctx, event);
}
return condition.predicate(guards2)(ctx, event);
}).every(Boolean)
};
}
function not(condition) {
return {
predicate: (guardMap) => (ctx, event) => {
var _a;
if (isString(condition)) {
return !((_a = guardMap[condition]) == null ? void 0 : _a.call(guardMap, ctx, event));
}
if (isFunction(condition)) {
return !condition(ctx, event);
}
return !condition.predicate(guardMap)(ctx, event);
}
};
}
var guards = { or, and, not };
function isGuardHelper2(value) {
return isObject(value) && value.predicate != null;
}
var TruthyGuard = () => true;
function determineGuardFn(guard, guardMap) {
guard = guard != null ? guard : TruthyGuard;
return (context, event) => {
if (isString(guard)) {
const value = guardMap == null ? void 0 : guardMap[guard];
return isFunction(value) ? value(context, event) : value;
}
if (isGuardHelper2(guard)) {
return guard.predicate(guardMap != null ? guardMap : {})(context, event);
}
return guard == null ? void 0 : guard(context, event);
};
}
// ../../../node_modules/klona/json/index.mjs
function klona(val) {
var k, out, tmp;
if (Array.isArray(val)) {
out = Array(k = val.length);
while (k--)
out[k] = (tmp = val[k]) && typeof tmp === "object" ? klona(tmp) : tmp;
return out;
}
if (Object.prototype.toString.call(val) === "[object Object]") {
out = {};
for (k in val) {
if (k === "__proto__") {
Object.defineProperty(out, k, {
value: klona(val[k]),
configurable: true,
enumerable: true,
writable: true
});
} else {
out[k] = (tmp = val[k]) && typeof tmp === "object" ? klona(tmp) : tmp;
}
}
return out;
}
return val;
}
// ../../core/src/machine.ts
var import_utils9 = require("valtio/utils");
var import_vanilla2 = require("valtio/vanilla");
// ../../core/src/create-proxy.ts
var import_vanilla = require("valtio/vanilla");
function createProxy(config) {
var _a;
const state = (0, import_vanilla.proxy)({
value: "",
previousValue: "",
event: cast({}),
context: (_a = config.context) != null ? _a : cast({}),
done: false,
tags: [],
hasTag(tag) {
return this.tags.includes(tag);
},
matches(...value) {
return value.includes(this.value);
},
can(event) {
return cast(this).nextEvents.includes(event);
},
get nextEvents() {
var _a2, _b, _c, _d;
const stateEvents = (_c = (_b = (_a2 = config.states) == null ? void 0 : _a2[this.value]) == null ? void 0 : _b["on"]) != null ? _c : {};
const globalEvents = (_d = config == null ? void 0 : config.on) != null ? _d : {};
return Object.keys(__spreadValues(__spreadValues({}, stateEvents), globalEvents));
},
get changed() {
if (this.event.value === "machine.init" /* Init */ || !this.previousValue)
return false;
return this.value !== this.previousValue;
}
});
return cast(state);
}
// ../../core/src/delay-utils.ts
function determineDelayFn(delay, delaysMap) {
return (context, event) => {
if (isNumber(delay))
return delay;
if (isFunction(delay)) {
return delay(context, event);
}
if (isString(delay)) {
const value = Number.parseFloat(delay);
if (!Number.isNaN(value)) {
return value;
}
if (delaysMap) {
const valueOrFn = delaysMap == null ? void 0 : delaysMap[delay];
if (valueOrFn == null) {
const msg = `[machine] Cannot determine delay for ${delay}. It doesn't exist in options.delays`;
throw new Error(msg);
}
return isFunction(valueOrFn) ? valueOrFn(context, event) : valueOrFn;
}
}
};
}
// ../../core/src/utils.ts
function toEvent(event) {
const obj = isString(event) ? { type: event } : event;
return obj;
}
function toArray(value) {
if (!value)
return [];
return isArray(value) ? value : [value];
}
// ../../core/src/transition-utils.ts
function toTarget(target) {
return isString(target) ? { target } : target;
}
function determineTransitionFn(transitions, guardMap) {
return (context, event) => {
return toArray(transitions).map(toTarget).find((transition) => {
var _a;
const determineGuard = determineGuardFn(transition.guard, guardMap);
const guard = determineGuard(context, event);
return (_a = guard != null ? guard : transition.target) != null ? _a : transition.actions;
});
};
}
function toTransition(transition, current) {
const _transition = isString(transition) ? toTarget(transition) : transition;
const fn = (t2) => {
const isTargetless = t2.actions && !t2.target;
if (isTargetless && current)
t2.target = current;
return t2;
};
if (isArray(_transition)) {
return _transition.map(fn);
}
if (isObject(_transition)) {
return fn(cast(_transition));
}
}
// ../../core/src/machine.ts
var Machine = class {
constructor(config, options) {
this.config = config;
this.status = "Not Started" /* NotStarted */;
this.type = "machine" /* Machine */;
this.activityEvents = /* @__PURE__ */ new Map();
this.delayedEvents = /* @__PURE__ */ new Map();
this.stateListeners = /* @__PURE__ */ new Set();
this.eventListeners = /* @__PURE__ */ new Set();
this.doneListeners = /* @__PURE__ */ new Set();
this.contextWatchers = /* @__PURE__ */ new Set();
this.removeStateListener = noop;
this.removeEventListener = noop;
this.children = /* @__PURE__ */ new Map();
this.start = (init) => {
if (this.status === "Running" /* Running */) {
return this;
}
this.status = "Running" /* Running */;
const event = toEvent("machine.init" /* Init */);
if (init) {
const resolved = isObject(init) ? init : { context: this.config.context, value: init };
this.setState(resolved.value);
this.setContext(resolved.context);
}
const transition = {
target: !!init ? void 0 : this.config.initial
};
const info = this.getNextStateInfo(transition, event);
info.target = cast(info.target || transition.target);
this.initialState = info;
this.performStateChangeEffects(info.target, info, event);
this.removeStateListener = (0, import_vanilla2.subscribe)(this.state, () => {
this.stateListeners.forEach((listener) => {
listener(this.stateSnapshot);
});
}, this.sync);
this.removeEventListener = (0, import_utils9.subscribeKey)(this.state, "event", (value) => {
if (this.config.onEvent) {
this.executeActions(this.config.onEvent, value);
}
for (const listener of this.eventListeners) {
listener(value);
}
});
this.setupContextWatchers();
this.executeActivities(toEvent("machine.start" /* Start */), toArray(this.config.activities), "machine.start" /* Start */);
this.executeActions(this.config.entry, toEvent("machine.start" /* Start */));
return this;
};
this.setupContextWatchers = () => {
var _a;
for (const [key, fn] of Object.entries((_a = this.config.watch) != null ? _a : {})) {
this.contextWatchers.add((0, import_utils9.subscribeKey)(this.state.context, key, () => {
this.executeActions(fn, this.state.event);
}));
}
};
this.setupComputed = () => {
var _a;
const computed = cast((_a = this.config.computed) != null ? _a : {});
const deriveFns = Object.fromEntries(Object.entries(computed).map(([key, fn]) => [key, (get) => fn(get(this.state.context))]));
(0, import_utils9.derive)(deriveFns, { proxy: this.state.context });
};
this.detachComputed = () => {
(0, import_utils9.underive)(this.state.context, { delete: true });
};
this.stop = () => {
if (this.status === "Stopped" /* Stopped */)
return;
this.setState(null);
this.setEvent("machine.stop" /* Stop */);
if (this.config.context) {
this.setContext(this.config.context);
}
this.stopStateListeners();
this.stopChildren();
this.stopActivities();
this.stopDelayedEvents();
this.stopContextWatchers();
this.stopEventListeners();
this.detachComputed();
this.status = "Stopped" /* Stopped */;
this.executeActions(this.config.exit, toEvent("machine.stop" /* Stop */));
return this;
};
this.stopEventListeners = () => {
this.eventListeners.clear();
this.removeEventListener();
};
this.stopStateListeners = () => {
this.removeStateListener();
this.stateListeners.clear();
};
this.stopContextWatchers = () => {
this.contextWatchers.forEach((fn) => fn());
this.contextWatchers.clear();
};
this.stopDelayedEvents = () => {
this.delayedEvents.forEach((state) => {
state.forEach((stop) => stop());
});
this.delayedEvents.clear();
};
this.stopActivities = (state) => {
var _a, _b;
if (state) {
(_a = this.activityEvents.get(state)) == null ? void 0 : _a.forEach((stop) => stop());
(_b = this.activityEvents.get(state)) == null ? void 0 : _b.clear();
this.activityEvents.delete(state);
} else {
this.activityEvents.forEach((state2) => {
state2.forEach((stop) => stop());
state2.clear();
});
this.activityEvents.clear();
}
};
this.sendChild = (evt, to) => {
const event = toEvent(evt);
const id = runIfFn(to, this.contextSnapshot);
const child = this.children.get(id);
if (!child) {
invariant(`[machine/send-child] Cannot send '${event.type}' event to unknown child`);
}
child.send(event);
};
this.stopChild = (id) => {
if (!this.children.has(id)) {
invariant("[machine/stop-child] Cannot stop unknown child");
}
this.children.get(id).stop();
this.children.delete(id);
};
this.removeChild = (id) => {
this.children.delete(id);
};
this.stopChildren = () => {
this.children.forEach((child) => child.stop());
this.children.clear();
};
this.setParent = (parent) => {
this.parent = parent;
};
this.spawn = (src, id) => {
const actor = runIfFn(src);
if (id)
actor.id = id;
actor.type = "machine.actor" /* Actor */;
actor.setParent(this);
this.children.set(actor.id, cast(actor));
actor.onDone(() => {
this.removeChild(actor.id);
}).start();
return cast((0, import_vanilla2.ref)(actor));
};
this.addActivityCleanup = (state, cleanup) => {
var _a;
if (!state)
return;
if (!this.activityEvents.has(state)) {
this.activityEvents.set(state, /* @__PURE__ */ new Set([cleanup]));
} else {
(_a = this.activityEvents.get(state)) == null ? void 0 : _a.add(cleanup);
}
};
this.setState = (target) => {
this.state.previousValue = this.state.value;
this.state.value = target;
const stateNode = this.getStateNode(target);
if (target == null) {
clear(this.state.tags);
} else {
this.state.tags = toArray(stateNode == null ? void 0 : stateNode.tags);
}
};
this.setContext = (context) => {
for (const key in context) {
this.state.context[key] = context[key];
}
};
this.withContext = (context) => {
this.detachComputed();
const newContext = __spreadValues(__spreadValues({}, this.config.context), context);
return new Machine(__spreadProps(__spreadValues({}, this.config), { context: newContext }), this.options);
};
this.withOptions = (options) => {
this.detachComputed();
return new Machine(this.config, __spreadValues(__spreadValues({}, this.options), options));
};
this.setActions = (actions) => {
this.actionMap = __spreadValues(__spreadValues({}, this.actionMap), actions);
};
this.clone = () => {
this.detachComputed();
return new Machine(this.config, this.options);
};
this.getStateNode = (state) => {
var _a;
if (!state)
return;
return (_a = this.config.states) == null ? void 0 : _a[state];
};
this.getNextStateInfo = (transitions, event) => {
var _a;
const transition = this.determineTransition(transitions, event);
const target = (_a = transition == null ? void 0 : transition.target) != null ? _a : this.state.value;
const stateNode = this.getStateNode(target);
return {
transition,
stateNode,
target
};
};
this.getActionFromDelayedTransition = (transition) => {
const event = toEvent("machine.after" /* After */);
const determineDelay = determineDelayFn(transition.delay, this.delayMap);
const delay = determineDelay(this.contextSnapshot, event);
let id;
return {
entry: () => {
id = globalThis.setTimeout(() => {
const current = this.state.value;
const next = this.getNextStateInfo(transition, event);
this.performStateChangeEffects(current, next, event);
}, delay);
},
exit: () => {
globalThis.clearTimeout(id);
}
};
};
this.getDelayedEventActions = (state) => {
const stateNode = this.getStateNode(state);
const event = toEvent("machine.after" /* After */);
if (!stateNode || !stateNode.after)
return;
const entries = [];
const exits = [];
if (isArray(stateNode.after)) {
const transition = this.determineTransition(stateNode.after, event);
if (!transition)
return;
const actions = this.getActionFromDelayedTransition(transition);
entries.push(actions.entry);
exits.push(actions.exit);
} else if (isObject(stateNode.after)) {
for (const delay in stateNode.after) {
const transition = stateNode.after[delay];
let resolvedTransition = {};
if (isArray(transition)) {
const picked = this.determineTransition(transition, event);
if (picked)
resolvedTransition = picked;
} else if (isString(transition)) {
resolvedTransition = { target: transition, delay };
} else {
resolvedTransition = __spreadProps(__spreadValues({}, transition), { delay });
}
const actions = this.getActionFromDelayedTransition(resolvedTransition);
entries.push(actions.entry);
exits.push(actions.exit);
}
}
return { entries, exits };
};
this.executeActions = (actions, event) => {
var _a;
const _actions = determineActionsFn(actions, this.guardMap)(this.contextSnapshot, event);
for (const action of toArray(_actions)) {
const fn = isString(action) ? (_a = this.actionMap) == null ? void 0 : _a[action] : action;
warn(isString(action) && !fn, `[machine/exec-action] No implementation found for action: \`${action}\``);
fn == null ? void 0 : fn(this.state.context, event, this.meta);
}
};
this.executeActivities = (event, activities, state) => {
var _a;
for (const activity of activities) {
const fn = isString(activity) ? (_a = this.activityMap) == null ? void 0 : _a[activity] : activity;
if (!fn) {
warn(`[machine/exec-activity] No implementation found for activity: \`${activity}\``);
continue;
}
const cleanup = fn(this.state.context, event, this.meta);
if (cleanup) {
this.addActivityCleanup(state != null ? state : this.state.value, cleanup);
}
}
};
this.createEveryActivities = (every, callbackfn) => {
if (!every)
return;
const event = toEvent("machine.every" /* Every */);
if (isArray(every)) {
const picked = toArray(every).find((t2) => {
const determineDelay2 = determineDelayFn(t2.delay, this.delayMap);
t2.delay = determineDelay2(this.contextSnapshot, event);
const determineGuard = determineGuardFn(t2.guard, this.guardMap);
const guard = determineGuard(this.contextSnapshot, event);
return guard != null ? guard : t2.delay;
});
if (!picked)
return;
const determineDelay = determineDelayFn(picked.delay, this.delayMap);
const delay = determineDelay(this.contextSnapshot, event);
const activity = () => {
const id = globalThis.setInterval(() => {
this.executeActions(picked.actions, event);
}, delay);
return () => {
globalThis.clearInterval(id);
};
};
callbackfn(activity);
} else {
for (const interval in every) {
const actions = every == null ? void 0 : every[interval];
const determineDelay = determineDelayFn(interval, this.delayMap);
const delay = determineDelay(this.contextSnapshot, event);
const activity = () => {
const id = globalThis.setInterval(() => {
this.executeActions(actions, event);
}, delay);
return () => {
globalThis.clearInterval(id);
};
};
callbackfn(activity);
}
}
};
this.setEvent = (event) => {
this.state.event = (0, import_vanilla2.ref)(toEvent(event));
};
this.performExitEffects = (current, event) => {
const currentState = this.state.value;
const stateNode = current ? this.getStateNode(current) : void 0;
this.stopActivities(currentState);
const _exit = determineActionsFn(stateNode == null ? void 0 : stateNode.exit, this.guardMap)(this.contextSnapshot, event);
const exitActions = toArray(_exit);
const afterExitActions = this.delayedEvents.get(currentState);
if (afterExitActions) {
exitActions.push(...afterExitActions);
}
this.executeActions(exitActions, event);
this.eventListeners.clear();
};
this.performEntryEffects = (next, event) => {
const stateNode = this.getStateNode(next);
const activities = toArray(stateNode == null ? void 0 : stateNode.activities);
this.createEveryActivities(stateNode == null ? void 0 : stateNode.every, (activity) => {
activities.unshift(activity);
});
if (activities.length > 0) {
this.executeActivities(event, activities);
}
const _entry = determineActionsFn(stateNode == null ? void 0 : stateNode.entry, this.guardMap)(this.contextSnapshot, event);
const entryActions = toArray(_entry);
const afterActions = this.getDelayedEventActions(next);
if ((stateNode == null ? void 0 : stateNode.after) && afterActions) {
this.delayedEvents.set(next, afterActions == null ? void 0 : afterActions.exits);
entryActions.push(...afterActions.entries);
}
this.executeActions(entryActions, event);
if ((stateNode == null ? void 0 : stateNode.type) === "final") {
this.state.done = true;
this.doneListeners.forEach((listener) => {
listener(this.stateSnapshot);
});
this.stop();
}
};
this.performTransitionEffects = (transition, event) => {
const t2 = this.determineTransition(transition, event);
this.executeActions(t2 == null ? void 0 : t2.actions, event);
};
this.performStateChangeEffects = (current, next, event) => {
var _a, _b;
this.setEvent(event);
next.target = (_b = (_a = next.target) != null ? _a : this.state.value) != null ? _b : void 0;
const ok = next.target && next.target !== this.state.value;
if (ok) {
this.performExitEffects(current, event);
}
this.performTransitionEffects(next == null ? void 0 : next.transition, event);
this.setState(next.target);
if (ok) {
this.performEntryEffects(next.target, event);
}
};
this.determineTransition = (transition, event) => {
const fn = determineTransitionFn(transition, this.guardMap);
return fn == null ? void 0 : fn(this.contextSnapshot, event);
};
this.sendParent = (evt) => {
var _a;
if (!this.parent) {
invariant("[machine/send-parent] Cannot send event to an unknown parent");
}
const event = toEvent(evt);
(_a = this.parent) == null ? void 0 : _a.send(event);
};
this.send = (evt) => {
const event = toEvent(evt);
this.transition(this.state.value, event);
};
this.transition = (state, evt) => {
var _a, _b, _c;
const stateNode = isString(state) ? this.getStateNode(state) : state == null ? void 0 : state.stateNode;
const event = toEvent(evt);
if (!stateNode && !this.config.on) {
const msg = this.status === "Stopped" /* Stopped */ ? "[machine/transition] Cannot transition a stopped machine" : "[machine/transition] State does not have a definition";
warn(msg);
return;
}
const transitionConfig = (_c = (_a = stateNode == null ? void 0 : stateNode.on) == null ? void 0 : _a[event.type]) != null ? _c : (_b = this.config.on) == null ? void 0 : _b[event.type];
const transition = toTransition(transitionConfig, this.state.value);
if (!transition)
return;
const info = this.getNextStateInfo(transition, event);
this.performStateChangeEffects(this.state.value, info, event);
return info.stateNode;
};
this.subscribe = (listener) => {
this.stateListeners.add(listener);
if (this.status === "Running" /* Running */) {
listener(this.stateSnapshot);
}
return () => {
this.stateListeners.delete(listener);
};
};
this.onDone = (listener) => {
this.doneListeners.add(listener);
return this;
};
this.onTransition = (listener) => {
this.stateListeners.add(listener);
if (this.status === "Running" /* Running */) {
listener(this.stateSnapshot);
}
return this;
};
this.onEvent = (listener) => {
listener(this.state.event);
this.eventListeners.add(listener);
return this;
};
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
this.options = klona(options);
this.id = (_a = config.id) != null ? _a : `machine-${uuid()}`;
this.guardMap = (_c = (_b = this.options) == null ? void 0 : _b.guards) != null ? _c : {};
this.actionMap = (_e = (_d = this.options) == null ? void 0 : _d.actions) != null ? _e : {};
this.delayMap = (_g = (_f = this.options) == null ? void 0 : _f.delays) != null ? _g : {};
this.activityMap = (_i = (_h = this.options) == null ? void 0 : _h.activities) != null ? _i : {};
this.sync = (_k = (_j = this.options) == null ? void 0 : _j.sync) != null ? _k : false;
this.state = createProxy(klona(config));
this.setupComputed();
const event = toEvent("machine.created" /* Created */);
this.executeActions(config == null ? void 0 : config.created, event);
}
get stateSnapshot() {
return cast((0, import_vanilla2.snapshot)(this.state));
}
get contextSnapshot() {
return this.stateSnapshot.context;
}
get self() {
const _self = this;
return {
id: this.id,
send: this.send.bind(this),
sendParent: this.sendParent.bind(this),
sendChild: this.sendChild.bind(this),
stop: this.stop.bind(this),
stopChild: this.stopChild.bind(this),
spawn: this.spawn.bind(this),
get state() {
return _self.stateSnapshot;
}
};
}
get meta() {
return {
state: this.stateSnapshot,
guards: this.guardMap,
send: this.send.bind(this),
listen: this.onEvent.bind(this),
self: this.self,
getState: () => this.stateSnapshot
};
}
};
var createMachine = (config, options) => new Machine(config, options);
// ../../types/src/prop-types.ts
// ../../types/dist/index.mjs
function createNormalizer(fn) {

@@ -969,10 +233,10 @@ return { button: fn, label: fn, input: fn, output: fn, element: fn };

},
promise(promise, msgs, opts = {}) {
const id = group2.loading(__spreadProps(__spreadValues(__spreadValues({}, opts), opts == null ? void 0 : opts.loading), { type: "loading", title: msgs.loading }));
promise(promise, options, shared = {}) {
const id = group2.loading(__spreadValues(__spreadValues({}, shared), options.loading));
promise.then((response) => {
const message = runIfFn(msgs.loading, response);
group2.success(__spreadProps(__spreadValues(__spreadValues({}, opts), opts == null ? void 0 : opts.success), { id, title: message }));
const successOptions = runIfFn(options.success, response);
group2.success(__spreadProps(__spreadValues(__spreadValues({}, shared), successOptions), { id }));
}).catch((error) => {
const message = runIfFn(msgs.error, error);
group2.error(__spreadProps(__spreadValues(__spreadValues({}, opts), opts == null ? void 0 : opts.error), { id, title: message }));
const errorOptions = runIfFn(options.error, error);
group2.error(__spreadProps(__spreadValues(__spreadValues({}, shared), errorOptions), { id }));
});

@@ -1017,3 +281,3 @@ return promise;

subscribe(fn) {
return (0, import_vanilla3.subscribe)(state.context.toasts, () => fn(state.context.toasts));
return (0, import_core.subscribe)(state.context.toasts, () => fn(state.context.toasts));
}

@@ -1027,10 +291,22 @@ };

// ../../utilities/dom/src/attrs.ts
// src/toast-group.machine.ts
var import_core3 = require("@zag-js/core");
// ../../utilities/dom/dist/index.mjs
var dataAttr = (guard) => {
return guard ? "" : void 0;
};
// ../../utilities/dom/src/event-bus.ts
var listenerElements = /* @__PURE__ */ new Map();
var listenerCache = /* @__PURE__ */ new Map();
var cast = (v) => v;
var noop = () => {
};
function getListenerElements() {
;
globalThis.__listenerElements__ = globalThis.__listenerElements__ || /* @__PURE__ */ new Map();
return globalThis.__listenerElements__;
}
function getListenerCache() {
;
globalThis.__listenerCache__ = globalThis.__listenerCache__ || /* @__PURE__ */ new Map();
return globalThis.__listenerCache__;
}
function globalEventBus(node, type, handler, options) {

@@ -1041,6 +317,8 @@ var _a;

const hash = JSON.stringify({ type, options });
const listenerElements = getListenerElements();
const listenerCache = getListenerCache();
const group2 = listenerElements.get(node);
if (!listenerElements.has(node)) {
const group3 = /* @__PURE__ */ new Map([[hash, /* @__PURE__ */ new Set([handler])]]);
listenerElements.set(node, group3);
const group22 = /* @__PURE__ */ new Map([[hash, /* @__PURE__ */ new Set([handler])]]);
listenerElements.set(node, group22);
} else if (group2 == null ? void 0 : group2.has(hash)) {

@@ -1055,4 +333,4 @@ (_a = group2 == null ? void 0 : group2.get(hash)) == null ? void 0 : _a.add(handler);

var _a3;
const group3 = listenerElements.get(node2);
(_a3 = group3 == null ? void 0 : group3.get(hash)) == null ? void 0 : _a3.forEach((fn) => fn(event));
const group22 = listenerElements.get(node2);
(_a3 = group22 == null ? void 0 : group22.get(hash)) == null ? void 0 : _a3.forEach((fn) => fn(event));
}

@@ -1074,10 +352,10 @@ if (!(listenerCache == null ? void 0 : listenerCache.has(node2))) {

return;
const group3 = listenerElements.get(node);
(_a2 = group3 == null ? void 0 : group3.get(hash)) == null ? void 0 : _a2.delete(handler);
if (((_b = group3 == null ? void 0 : group3.get(hash)) == null ? void 0 : _b.size) === 0) {
const group22 = listenerElements.get(node);
(_a2 = group22 == null ? void 0 : group22.get(hash)) == null ? void 0 : _a2.delete(handler);
if (((_b = group22 == null ? void 0 : group22.get(hash)) == null ? void 0 : _b.size) === 0) {
const listener = (_c = listenerCache.get(node)) == null ? void 0 : _c.get(hash);
node.removeEventListener(type, listener, options);
group3 == null ? void 0 : group3.delete(hash);
group22 == null ? void 0 : group22.delete(hash);
(_d = listenerCache.get(node)) == null ? void 0 : _d.delete(hash);
if ((group3 == null ? void 0 : group3.size) === 0) {
if ((group22 == null ? void 0 : group22.size) === 0) {
listenerElements.delete(node);

@@ -1089,4 +367,2 @@ listenerCache.delete(node);

}
// ../../utilities/dom/src/listener.ts
var t = (v) => Object.prototype.toString.call(v).slice(8, -1);

@@ -1099,7 +375,3 @@ var isRef = (v) => t(v) === "Object" && "current" in v;

}
// ../../utilities/dom/src/constants.ts
var MAX_Z_INDEX = 2147483647;
// ../../utilities/dom/src/visibility-event.ts
function trackDocumentVisibility(_doc, callback) {

@@ -1114,7 +386,8 @@ const doc = cast(_doc);

// src/toast.machine.ts
var { not: not2, and: and2, or: or2 } = guards;
var import_core2 = require("@zag-js/core");
var { not, and, or } = import_core2.guards;
function createToastMachine(options = {}) {
const _a = options, { type = "info", duration, id = "toast", placement = "bottom", removeDelay = 500 } = _a, rest = __objRest(_a, ["type", "duration", "id", "placement", "removeDelay"]);
const __duration = getToastDuration(duration, type);
return createMachine({
return (0, import_core2.createMachine)({
id,

@@ -1135,3 +408,3 @@ entry: "invokeOnOpen",

{
guard: and2("hasTypeChanged", "isChangingToLoading"),
guard: and("hasTypeChanged", "isChangingToLoading"),
target: "persist",

@@ -1141,3 +414,3 @@ actions: ["setContext", "invokeOnUpdate"]

{
guard: or2("hasDurationChanged", "hasTypeChanged"),
guard: or("hasDurationChanged", "hasTypeChanged"),
target: "active:temp",

@@ -1163,3 +436,3 @@ actions: ["setContext", "invokeOnUpdate"]

RESUME: {
guard: not2("isLoadingType"),
guard: not("isLoadingType"),
target: "active",

@@ -1264,3 +537,3 @@ actions: ["setCreatedAt"]

// src/toast-group.machine.ts
var groupMachine = createMachine({
var groupMachine = (0, import_core3.createMachine)({
id: "toaster",

@@ -1287,3 +560,3 @@ initial: "active",

if (evt.doc)
ctx.doc = (0, import_vanilla3.ref)(evt.doc);
ctx.doc = (0, import_core3.ref)(evt.doc);
}

@@ -1319,3 +592,3 @@ },

dir: ctx.dir,
doc: (0, import_vanilla3.ref)((_a = ctx.doc) != null ? _a : document)
doc: (0, import_core3.ref)((_a = ctx.doc) != null ? _a : document)
});

@@ -1322,0 +595,0 @@ const toast = createToastMachine(options);

4

dist/toast-group.connect.d.ts
import { StateMachine as S } from "@zag-js/core";
import { PropTypes, ReactPropTypes } from "@zag-js/types";
import { Toaster, GroupProps, GroupMachineContext, Options, Placement, PromiseMessages, PromiseOptions } from "./toast.types";
import { Toaster, GroupProps, GroupMachineContext, Options, Placement, PromiseOptions } from "./toast.types";
export declare let toaster: Toaster;

@@ -19,3 +19,3 @@ export declare function groupConnect<T extends PropTypes = ReactPropTypes>(state: S.State<GroupMachineContext>, send: (event: S.Event<S.AnyEventObject>) => void, normalize?: import("@zag-js/types").NormalizeProps): {

error(options: Options): string;
promise<T_1>(promise: Promise<T_1>, msgs: PromiseMessages, opts?: PromiseOptions): Promise<T_1>;
promise<T_1>(promise: Promise<T_1>, options: PromiseOptions<T_1>, shared?: Options): Promise<T_1>;
pause(id?: string): void;

@@ -22,0 +22,0 @@ resume(id?: string): void;

@@ -124,10 +124,7 @@ import { Machine } from "@zag-js/core";

declare type MaybeFunction<Value, Args> = Value | ((arg: Args) => Value);
export declare type PromiseMessages<Value = any> = {
loading: Value;
success: MaybeFunction<Value, Options>;
error: MaybeFunction<Value, Options>;
export declare type PromiseOptions<Value> = {
loading: Options;
success: MaybeFunction<Options, Value>;
error: MaybeFunction<Options, any>;
};
export declare type PromiseOptions = Options & {
[key in "success" | "loading" | "error"]?: Options;
};
export declare type GroupProps = {

@@ -147,5 +144,5 @@ placement: Placement;

remove(id?: string | undefined): void;
promise<T>(promise: Promise<T>, msgs: PromiseMessages, opts?: PromiseOptions): Promise<T>;
promise<T>(promise: Promise<T>, options: PromiseOptions<T>, shared?: Options): Promise<T>;
};
export {};
//# sourceMappingURL=toast.types.d.ts.map
{
"name": "@zag-js/toast",
"version": "0.0.0-dev-20220413175519",
"version": "0.0.0-dev-20220415160434",
"description": "Core logic for the toast widget implemented as a state machine",

@@ -32,6 +32,6 @@ "keywords": [

"dependencies": {
"@zag-js/core": "^0.0.0-dev-20220413175519",
"@zag-js/dom-utils": "^0.0.0-dev-20220413175519",
"@zag-js/types": "^0.0.0-dev-20220413175519",
"@zag-js/utils": "^0.0.0-dev-20220413175519"
"@zag-js/core": "^0.0.0-dev-20220415160434",
"@zag-js/dom-utils": "^0.0.0-dev-20220415160434",
"@zag-js/types": "^0.0.0-dev-20220415160434",
"@zag-js/utils": "^0.0.0-dev-20220415160434"
},

@@ -38,0 +38,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc