@antadesign/anta 0.3.13 → 0.3.14

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.
@@ -0,0 +1,100 @@
1
+ const TOAST_PLACEMENTS = [
2
+ "top-left",
3
+ "top-center",
4
+ "top-right",
5
+ "bottom-left",
6
+ "bottom-center",
7
+ "bottom-right"
8
+ ];
9
+ const DEFAULT_PLACEMENT = "bottom-right";
10
+ const EMPTY = Object.freeze([]);
11
+ let uid = 0;
12
+ function createToaster() {
13
+ let snapshot = EMPTY;
14
+ const listeners = /* @__PURE__ */ new Set();
15
+ const emit = () => listeners.forEach((fn) => fn());
16
+ function add(render, opts = {}) {
17
+ const id = opts.id ?? `t${++uid}`;
18
+ const i = snapshot.findIndex((e) => e.id === id);
19
+ const prev = i === -1 ? void 0 : snapshot[i];
20
+ const next = {
21
+ id,
22
+ render,
23
+ // On an upsert (existing id), keep the live toast's placement / duration /
24
+ // politeness when the caller omits them — so replacing the content doesn't
25
+ // silently reset a sticky toast to auto-dismiss or move it to another
26
+ // corner. Pass the option explicitly (incl. `undefined`) to change it.
27
+ placement: opts.placement ?? prev?.placement ?? DEFAULT_PLACEMENT,
28
+ duration: "duration" in opts ? opts.duration : prev?.duration,
29
+ politeness: opts.politeness ?? prev?.politeness,
30
+ leaving: false,
31
+ rev: prev ? prev.rev + 1 : 0
32
+ };
33
+ snapshot = prev ? snapshot.map((e, j) => j === i ? next : e) : [...snapshot, next];
34
+ emit();
35
+ return id;
36
+ }
37
+ function dismiss(id) {
38
+ let changed = false;
39
+ snapshot = snapshot.map((e) => {
40
+ if (e.id === id && !e.leaving) {
41
+ changed = true;
42
+ return { ...e, leaving: true };
43
+ }
44
+ return e;
45
+ });
46
+ if (changed) emit();
47
+ }
48
+ function update(id, render) {
49
+ let changed = false;
50
+ snapshot = snapshot.map((e) => {
51
+ if (e.id === id && !e.leaving) {
52
+ changed = true;
53
+ return { ...e, render, rev: e.rev + 1 };
54
+ }
55
+ return e;
56
+ });
57
+ if (changed) emit();
58
+ }
59
+ function remove(id) {
60
+ const next = snapshot.filter((e) => e.id !== id);
61
+ if (next.length !== snapshot.length) {
62
+ snapshot = next;
63
+ emit();
64
+ }
65
+ }
66
+ function clear() {
67
+ let changed = false;
68
+ snapshot = snapshot.map((e) => {
69
+ if (!e.leaving) {
70
+ changed = true;
71
+ return { ...e, leaving: true };
72
+ }
73
+ return e;
74
+ });
75
+ if (changed) emit();
76
+ }
77
+ return {
78
+ add,
79
+ dismiss,
80
+ update,
81
+ remove,
82
+ clear,
83
+ subscribe(onChange) {
84
+ listeners.add(onChange);
85
+ return () => {
86
+ listeners.delete(onChange);
87
+ };
88
+ },
89
+ getSnapshot() {
90
+ return snapshot;
91
+ },
92
+ getServerSnapshot() {
93
+ return EMPTY;
94
+ }
95
+ };
96
+ }
97
+ export {
98
+ TOAST_PLACEMENTS,
99
+ createToaster
100
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antadesign/anta",
3
- "version": "0.3.13",
3
+ "version": "0.3.14",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",