asterui 0.12.1 → 0.12.3
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/components/Checkbox.d.ts +10 -0
- package/dist/components/Dock.d.ts +38 -0
- package/dist/components/Mask.d.ts +14 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +173 -169
- package/dist/index.js.map +1 -1
- package/dist/index10.js +85 -59
- package/dist/index10.js.map +1 -1
- package/dist/index100.js +12 -7
- package/dist/index100.js.map +1 -1
- package/dist/index101.js +13 -11
- package/dist/index101.js.map +1 -1
- package/dist/index102.js +7 -30
- package/dist/index102.js.map +1 -1
- package/dist/index103.js +11 -16
- package/dist/index103.js.map +1 -1
- package/dist/index104.js +30 -10792
- package/dist/index104.js.map +1 -1
- package/dist/index105.js +18 -5
- package/dist/index105.js.map +1 -1
- package/dist/index15.js +3 -3
- package/dist/index21.js +1 -1
- package/dist/index24.js +43 -32
- package/dist/index24.js.map +1 -1
- package/dist/index25.js +32 -41
- package/dist/index25.js.map +1 -1
- package/dist/index26.js +41 -12
- package/dist/index26.js.map +1 -1
- package/dist/index27.js +12 -33
- package/dist/index27.js.map +1 -1
- package/dist/index28.js +33 -63
- package/dist/index28.js.map +1 -1
- package/dist/index29.js +60 -77
- package/dist/index29.js.map +1 -1
- package/dist/index30.js +80 -18
- package/dist/index30.js.map +1 -1
- package/dist/index31.js +15 -217
- package/dist/index31.js.map +1 -1
- package/dist/index32.js +216 -1078
- package/dist/index32.js.map +1 -1
- package/dist/index33.js +1081 -17
- package/dist/index33.js.map +1 -1
- package/dist/index34.js +17 -121
- package/dist/index34.js.map +1 -1
- package/dist/index35.js +119 -37
- package/dist/index35.js.map +1 -1
- package/dist/index36.js +31 -182
- package/dist/index36.js.map +1 -1
- package/dist/index37.js +191 -97
- package/dist/index37.js.map +1 -1
- package/dist/index38.js +93 -158
- package/dist/index38.js.map +1 -1
- package/dist/index39.js +155 -139
- package/dist/index39.js.map +1 -1
- package/dist/index40.js +146 -15
- package/dist/index40.js.map +1 -1
- package/dist/index41.js +14 -17
- package/dist/index41.js.map +1 -1
- package/dist/index42.js +18 -21
- package/dist/index42.js.map +1 -1
- package/dist/index43.js +18 -116
- package/dist/index43.js.map +1 -1
- package/dist/index44.js +116 -10
- package/dist/index44.js.map +1 -1
- package/dist/index45.js +13 -35
- package/dist/index45.js.map +1 -1
- package/dist/index46.js +33 -114
- package/dist/index46.js.map +1 -1
- package/dist/index47.js +10 -176
- package/dist/index47.js.map +1 -1
- package/dist/index48.js +114 -145
- package/dist/index48.js.map +1 -1
- package/dist/index49.js +176 -12
- package/dist/index49.js.map +1 -1
- package/dist/index50.js +146 -21
- package/dist/index50.js.map +1 -1
- package/dist/index51.js +12 -14
- package/dist/index51.js.map +1 -1
- package/dist/index52.js +20 -5
- package/dist/index52.js.map +1 -1
- package/dist/index53.js +14 -266
- package/dist/index53.js.map +1 -1
- package/dist/index54.js +7 -17
- package/dist/index54.js.map +1 -1
- package/dist/index55.js +257 -113
- package/dist/index55.js.map +1 -1
- package/dist/index56.js +17 -110
- package/dist/index56.js.map +1 -1
- package/dist/index57.js +121 -169
- package/dist/index57.js.map +1 -1
- package/dist/index58.js +110 -32
- package/dist/index58.js.map +1 -1
- package/dist/index59.js +163 -115
- package/dist/index59.js.map +1 -1
- package/dist/index60.js +30 -84
- package/dist/index60.js.map +1 -1
- package/dist/index61.js +121 -19
- package/dist/index61.js.map +1 -1
- package/dist/index62.js +81 -69
- package/dist/index62.js.map +1 -1
- package/dist/index63.js +19 -56
- package/dist/index63.js.map +1 -1
- package/dist/index64.js +72 -43
- package/dist/index64.js.map +1 -1
- package/dist/index65.js +54 -49
- package/dist/index65.js.map +1 -1
- package/dist/index66.js +41 -58
- package/dist/index66.js.map +1 -1
- package/dist/index67.js +50 -105
- package/dist/index67.js.map +1 -1
- package/dist/index68.js +62 -41
- package/dist/index68.js.map +1 -1
- package/dist/index69.js +99 -60
- package/dist/index69.js.map +1 -1
- package/dist/index70.js +41 -21
- package/dist/index70.js.map +1 -1
- package/dist/index71.js +66 -44
- package/dist/index71.js.map +1 -1
- package/dist/index72.js +19 -132
- package/dist/index72.js.map +1 -1
- package/dist/index73.js +40 -46
- package/dist/index73.js.map +1 -1
- package/dist/index74.js +134 -22
- package/dist/index74.js.map +1 -1
- package/dist/index75.js +50 -29
- package/dist/index75.js.map +1 -1
- package/dist/index76.js +19 -19
- package/dist/index76.js.map +1 -1
- package/dist/index77.js +31 -329
- package/dist/index77.js.map +1 -1
- package/dist/index78.js +19 -53
- package/dist/index78.js.map +1 -1
- package/dist/index79.js +328 -39
- package/dist/index79.js.map +1 -1
- package/dist/index80.js +56 -23
- package/dist/index80.js.map +1 -1
- package/dist/index81.js +40 -95
- package/dist/index81.js.map +1 -1
- package/dist/index82.js +22 -129
- package/dist/index82.js.map +1 -1
- package/dist/index83.js +86 -152
- package/dist/index83.js.map +1 -1
- package/dist/index84.js +125 -60
- package/dist/index84.js.map +1 -1
- package/dist/index85.js +160 -34
- package/dist/index85.js.map +1 -1
- package/dist/index86.js +65 -234
- package/dist/index86.js.map +1 -1
- package/dist/index87.js +35 -34
- package/dist/index87.js.map +1 -1
- package/dist/index88.js +222 -198
- package/dist/index88.js.map +1 -1
- package/dist/index89.js +34 -213
- package/dist/index89.js.map +1 -1
- package/dist/index90.js +190 -275
- package/dist/index90.js.map +1 -1
- package/dist/index91.js +202 -167
- package/dist/index91.js.map +1 -1
- package/dist/index92.js +263 -226
- package/dist/index92.js.map +1 -1
- package/dist/index93.js +176 -12
- package/dist/index93.js.map +1 -1
- package/dist/index94.js +257 -32
- package/dist/index94.js.map +1 -1
- package/dist/index95.js +13 -5
- package/dist/index95.js.map +1 -1
- package/dist/index96.js +31 -12
- package/dist/index96.js.map +1 -1
- package/dist/index97.js +5 -45
- package/dist/index97.js.map +1 -1
- package/dist/index98.js +13 -12
- package/dist/index98.js.map +1 -1
- package/dist/index99.js +44 -13
- package/dist/index99.js.map +1 -1
- package/package.json +11 -4
- package/dist/index106.js +0 -45
- package/dist/index106.js.map +0 -1
- package/dist/index107.js +0 -5
- package/dist/index107.js.map +0 -1
- package/dist/index108.js +0 -10
- package/dist/index108.js.map +0 -1
- package/dist/index109.js +0 -155
- package/dist/index109.js.map +0 -1
- package/dist/index110.js +0 -33
- package/dist/index110.js.map +0 -1
- package/dist/index111.js +0 -33
- package/dist/index111.js.map +0 -1
- package/dist/index112.js +0 -5
- package/dist/index112.js.map +0 -1
- package/dist/index113.js +0 -75
- package/dist/index113.js.map +0 -1
- package/dist/index114.js +0 -42
- package/dist/index114.js.map +0 -1
- package/dist/index115.js +0 -29
- package/dist/index115.js.map +0 -1
- package/dist/index116.js +0 -24
- package/dist/index116.js.map +0 -1
- package/dist/index117.js +0 -27
- package/dist/index117.js.map +0 -1
- package/dist/index118.js +0 -23
- package/dist/index118.js.map +0 -1
- package/dist/index119.js +0 -103
- package/dist/index119.js.map +0 -1
- package/dist/index120.js +0 -363
- package/dist/index120.js.map +0 -1
- package/dist/index121.js +0 -28
- package/dist/index121.js.map +0 -1
- package/dist/index122.js +0 -76
- package/dist/index122.js.map +0 -1
- package/dist/index123.js +0 -19
- package/dist/index123.js.map +0 -1
- package/dist/index124.js +0 -69
- package/dist/index124.js.map +0 -1
- package/dist/index125.js +0 -147
- package/dist/index125.js.map +0 -1
- package/dist/index126.js +0 -5
- package/dist/index126.js.map +0 -1
- package/dist/index127.js +0 -59
- package/dist/index127.js.map +0 -1
- package/dist/index128.js +0 -5
- package/dist/index128.js.map +0 -1
- package/dist/index129.js +0 -5
- package/dist/index129.js.map +0 -1
- package/dist/index130.js +0 -5
- package/dist/index130.js.map +0 -1
- package/dist/index131.js +0 -5
- package/dist/index131.js.map +0 -1
- package/dist/index132.js +0 -5
- package/dist/index132.js.map +0 -1
- package/dist/index133.js +0 -5
- package/dist/index133.js.map +0 -1
- package/dist/index134.js +0 -5
- package/dist/index134.js.map +0 -1
- package/dist/index135.js +0 -5
- package/dist/index135.js.map +0 -1
- package/dist/index136.js +0 -35
- package/dist/index136.js.map +0 -1
- package/dist/index137.js +0 -5
- package/dist/index137.js.map +0 -1
- package/dist/index138.js +0 -11
- package/dist/index138.js.map +0 -1
- package/dist/index139.js +0 -5
- package/dist/index139.js.map +0 -1
- package/dist/index140.js +0 -5
- package/dist/index140.js.map +0 -1
- package/dist/index141.js +0 -24
- package/dist/index141.js.map +0 -1
- package/dist/index142.js +0 -5
- package/dist/index142.js.map +0 -1
- package/dist/index143.js +0 -27
- package/dist/index143.js.map +0 -1
- package/dist/index144.js +0 -74
- package/dist/index144.js.map +0 -1
- package/dist/index145.js +0 -24
- package/dist/index145.js.map +0 -1
- package/dist/index146.js +0 -37
- package/dist/index146.js.map +0 -1
- package/dist/index147.js +0 -73
- package/dist/index147.js.map +0 -1
- package/dist/index148.js +0 -5
- package/dist/index148.js.map +0 -1
- package/dist/index149.js +0 -25
- package/dist/index149.js.map +0 -1
- package/dist/index150.js +0 -5
- package/dist/index150.js.map +0 -1
- package/dist/index151.js +0 -5
- package/dist/index151.js.map +0 -1
- package/dist/index152.js +0 -5
- package/dist/index152.js.map +0 -1
- package/dist/index153.js +0 -5
- package/dist/index153.js.map +0 -1
- package/dist/index154.js +0 -7
- package/dist/index154.js.map +0 -1
package/dist/index54.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index54.js","sources":["../src/components/
|
|
1
|
+
{"version":3,"file":"index54.js","sources":["../src/components/Window.tsx"],"sourcesContent":["import React from 'react'\n\nexport interface WindowProps {\n children: React.ReactNode\n className?: string\n contentClassName?: string\n}\n\nexport const Window: React.FC<WindowProps> = ({\n children,\n className = '',\n contentClassName = '',\n}) => {\n return (\n <div className={`mockup-window border border-base-300 ${className}`}>\n <div className={`border-t border-base-300 ${contentClassName}`}>\n {children}\n </div>\n </div>\n )\n}\n"],"names":["Window","children","className","contentClassName","jsx"],"mappings":";AAQO,MAAMA,IAAgC,CAAC;AAAA,EAC5C,UAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,kBAAAC,IAAmB;AACrB,MAEI,gBAAAC,EAAC,OAAA,EAAI,WAAW,wCAAwCF,CAAS,IAC/D,UAAA,gBAAAE,EAAC,OAAA,EAAI,WAAW,4BAA4BD,CAAgB,IACzD,UAAAF,GACH,GACF;"}
|
package/dist/index55.js
CHANGED
|
@@ -1,125 +1,269 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { jsxs as i, jsx as t, Fragment as F } from "react/jsx-runtime";
|
|
2
|
+
import x, { useRef as T, useId as j, useEffect as B } from "react";
|
|
3
|
+
import { createRoot as K } from "react-dom/client";
|
|
4
|
+
function u({
|
|
5
|
+
children: e,
|
|
6
|
+
title: r,
|
|
7
|
+
footer: o,
|
|
8
|
+
open: a = !1,
|
|
9
|
+
onOk: l,
|
|
10
|
+
onCancel: s,
|
|
11
|
+
okText: v = "OK",
|
|
12
|
+
cancelText: c = "Cancel",
|
|
13
|
+
maskClosable: h = !0,
|
|
14
|
+
closable: m = !0,
|
|
15
|
+
position: d,
|
|
16
|
+
align: p,
|
|
17
|
+
className: f = "",
|
|
18
|
+
...b
|
|
19
|
+
}) {
|
|
20
|
+
const k = T(null), C = T(null), [N, y] = x.useState(!1), L = j(), g = j();
|
|
21
|
+
B(() => {
|
|
22
|
+
const n = k.current;
|
|
23
|
+
n && (a ? n.open || (C.current = document.activeElement, n.showModal()) : n.open && (n.close(), C.current?.focus()));
|
|
24
|
+
}, [a]), B(() => {
|
|
25
|
+
const n = k.current;
|
|
26
|
+
if (!n) return;
|
|
27
|
+
const M = () => {
|
|
28
|
+
s?.();
|
|
13
29
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return this.notifications;
|
|
17
|
-
}
|
|
18
|
-
emit() {
|
|
19
|
-
this.listeners.forEach((t) => t());
|
|
20
|
-
}
|
|
21
|
-
ensureContainer() {
|
|
22
|
-
this.container || (this.container = document.createElement("div"), document.body.appendChild(this.container), this.root = d.createRoot(this.container), this.root.render(/* @__PURE__ */ i(f, { manager: this })));
|
|
23
|
-
}
|
|
24
|
-
open(t) {
|
|
25
|
-
this.ensureContainer();
|
|
26
|
-
const o = `notification-${++this.idCounter}`, s = {
|
|
27
|
-
...t,
|
|
28
|
-
id: o,
|
|
29
|
-
createdAt: Date.now(),
|
|
30
|
-
duration: t.duration ?? 4.5,
|
|
31
|
-
placement: t.placement ?? "topRight",
|
|
32
|
-
closable: t.closable ?? !0,
|
|
33
|
-
type: t.type ?? "info"
|
|
30
|
+
return n.addEventListener("close", M), () => {
|
|
31
|
+
n.removeEventListener("close", M);
|
|
34
32
|
};
|
|
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
|
-
t({});
|
|
63
|
-
}), [e]);
|
|
64
|
-
const o = e.getNotifications(), s = {
|
|
65
|
-
topLeft: [],
|
|
66
|
-
topRight: [],
|
|
67
|
-
bottomLeft: [],
|
|
68
|
-
bottomRight: []
|
|
69
|
-
};
|
|
70
|
-
o.forEach((n) => {
|
|
71
|
-
s[n.placement].push(n);
|
|
72
|
-
});
|
|
73
|
-
const r = {
|
|
74
|
-
topRight: "toast toast-top toast-end",
|
|
75
|
-
topLeft: "toast toast-top toast-start",
|
|
76
|
-
bottomRight: "toast toast-bottom toast-end",
|
|
77
|
-
bottomLeft: "toast toast-bottom toast-start"
|
|
78
|
-
};
|
|
79
|
-
return /* @__PURE__ */ i(h, { children: Object.entries(s).map(([n, c]) => c.length === 0 ? null : /* @__PURE__ */ i("div", { className: r[n], children: c.map((a) => /* @__PURE__ */ i(
|
|
80
|
-
b,
|
|
81
|
-
{
|
|
82
|
-
notification: a,
|
|
83
|
-
onClose: () => e.close(a.id)
|
|
84
|
-
},
|
|
85
|
-
a.id
|
|
86
|
-
)) }, n)) });
|
|
87
|
-
}
|
|
88
|
-
function b({ notification: e, onClose: t }) {
|
|
89
|
-
const o = {
|
|
90
|
-
success: "alert-success",
|
|
91
|
-
error: "alert-error",
|
|
92
|
-
info: "alert-info",
|
|
93
|
-
warning: "alert-warning"
|
|
94
|
-
}, s = () => {
|
|
95
|
-
e.onClick && e.onClick();
|
|
96
|
-
};
|
|
97
|
-
return /* @__PURE__ */ l(
|
|
98
|
-
"div",
|
|
33
|
+
}, [s]);
|
|
34
|
+
const E = {
|
|
35
|
+
top: "modal-top",
|
|
36
|
+
middle: "modal-middle",
|
|
37
|
+
bottom: "modal-bottom"
|
|
38
|
+
}, O = {
|
|
39
|
+
start: "modal-start",
|
|
40
|
+
end: "modal-end"
|
|
41
|
+
}, R = [
|
|
42
|
+
"modal",
|
|
43
|
+
d && E[d],
|
|
44
|
+
p && O[p],
|
|
45
|
+
f
|
|
46
|
+
].filter(Boolean).join(" "), $ = async () => {
|
|
47
|
+
if (l) {
|
|
48
|
+
y(!0);
|
|
49
|
+
try {
|
|
50
|
+
await l(), y(!1);
|
|
51
|
+
} catch (n) {
|
|
52
|
+
throw y(!1), n;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}, z = () => {
|
|
56
|
+
h && s && s();
|
|
57
|
+
}, I = !o && (l || s), W = o != null;
|
|
58
|
+
return /* @__PURE__ */ i(
|
|
59
|
+
"dialog",
|
|
99
60
|
{
|
|
100
|
-
|
|
101
|
-
|
|
61
|
+
ref: k,
|
|
62
|
+
className: R,
|
|
63
|
+
"data-state": a ? "open" : "closed",
|
|
64
|
+
"aria-labelledby": r ? L : void 0,
|
|
65
|
+
"aria-describedby": g,
|
|
66
|
+
...b,
|
|
102
67
|
children: [
|
|
103
|
-
/* @__PURE__ */
|
|
104
|
-
|
|
105
|
-
|
|
68
|
+
/* @__PURE__ */ i("div", { className: "modal-box", children: [
|
|
69
|
+
r && /* @__PURE__ */ t("h3", { id: L, className: "text-lg font-bold mb-4", children: r }),
|
|
70
|
+
/* @__PURE__ */ t("div", { id: g, className: "py-4", children: e }),
|
|
71
|
+
I && /* @__PURE__ */ i("div", { className: "modal-action", children: [
|
|
72
|
+
s && /* @__PURE__ */ t("button", { className: "btn", onClick: s, children: c }),
|
|
73
|
+
l && /* @__PURE__ */ t(
|
|
74
|
+
"button",
|
|
75
|
+
{
|
|
76
|
+
className: `btn btn-primary ${N ? "loading" : ""}`,
|
|
77
|
+
onClick: $,
|
|
78
|
+
disabled: N,
|
|
79
|
+
children: v
|
|
80
|
+
}
|
|
81
|
+
)
|
|
82
|
+
] }),
|
|
83
|
+
W && /* @__PURE__ */ t("div", { className: "modal-action", children: o })
|
|
106
84
|
] }),
|
|
107
|
-
|
|
108
|
-
"button",
|
|
109
|
-
{
|
|
110
|
-
className: "btn btn-sm btn-ghost btn-circle",
|
|
111
|
-
onClick: (r) => {
|
|
112
|
-
r.stopPropagation(), t();
|
|
113
|
-
},
|
|
114
|
-
children: "✕"
|
|
115
|
-
}
|
|
116
|
-
)
|
|
85
|
+
m && h && /* @__PURE__ */ t("form", { method: "dialog", className: "modal-backdrop", children: /* @__PURE__ */ t("button", { onClick: z, children: "close" }) })
|
|
117
86
|
]
|
|
118
87
|
}
|
|
119
88
|
);
|
|
120
89
|
}
|
|
121
|
-
|
|
90
|
+
function w(e) {
|
|
91
|
+
const r = document.createElement("div");
|
|
92
|
+
document.body.appendChild(r);
|
|
93
|
+
const o = K(r), a = () => {
|
|
94
|
+
o.unmount(), r.parentNode && r.parentNode.removeChild(r);
|
|
95
|
+
}, l = () => {
|
|
96
|
+
const [s, v] = x.useState(!0), [c, h] = x.useState(!1), m = () => {
|
|
97
|
+
v(!1), setTimeout(a, 300);
|
|
98
|
+
}, d = async () => {
|
|
99
|
+
if (e.onOk) {
|
|
100
|
+
h(!0);
|
|
101
|
+
try {
|
|
102
|
+
await e.onOk(), m();
|
|
103
|
+
} catch {
|
|
104
|
+
h(!1);
|
|
105
|
+
}
|
|
106
|
+
} else
|
|
107
|
+
m();
|
|
108
|
+
}, p = () => {
|
|
109
|
+
e.onCancel?.(), m();
|
|
110
|
+
}, f = () => {
|
|
111
|
+
switch (e.type) {
|
|
112
|
+
case "success":
|
|
113
|
+
return "alert-success";
|
|
114
|
+
case "warning":
|
|
115
|
+
return "alert-warning";
|
|
116
|
+
case "error":
|
|
117
|
+
return "alert-error";
|
|
118
|
+
case "info":
|
|
119
|
+
default:
|
|
120
|
+
return "alert-info";
|
|
121
|
+
}
|
|
122
|
+
}, b = () => {
|
|
123
|
+
switch (e.type) {
|
|
124
|
+
case "success":
|
|
125
|
+
return /* @__PURE__ */ t(
|
|
126
|
+
"svg",
|
|
127
|
+
{
|
|
128
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
129
|
+
className: "stroke-current shrink-0 h-6 w-6",
|
|
130
|
+
fill: "none",
|
|
131
|
+
viewBox: "0 0 24 24",
|
|
132
|
+
children: /* @__PURE__ */ t(
|
|
133
|
+
"path",
|
|
134
|
+
{
|
|
135
|
+
strokeLinecap: "round",
|
|
136
|
+
strokeLinejoin: "round",
|
|
137
|
+
strokeWidth: "2",
|
|
138
|
+
d: "M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"
|
|
139
|
+
}
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
);
|
|
143
|
+
case "warning":
|
|
144
|
+
return /* @__PURE__ */ t(
|
|
145
|
+
"svg",
|
|
146
|
+
{
|
|
147
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
148
|
+
className: "stroke-current shrink-0 h-6 w-6",
|
|
149
|
+
fill: "none",
|
|
150
|
+
viewBox: "0 0 24 24",
|
|
151
|
+
children: /* @__PURE__ */ t(
|
|
152
|
+
"path",
|
|
153
|
+
{
|
|
154
|
+
strokeLinecap: "round",
|
|
155
|
+
strokeLinejoin: "round",
|
|
156
|
+
strokeWidth: "2",
|
|
157
|
+
d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
|
|
158
|
+
}
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
);
|
|
162
|
+
case "error":
|
|
163
|
+
return /* @__PURE__ */ t(
|
|
164
|
+
"svg",
|
|
165
|
+
{
|
|
166
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
167
|
+
className: "stroke-current shrink-0 h-6 w-6",
|
|
168
|
+
fill: "none",
|
|
169
|
+
viewBox: "0 0 24 24",
|
|
170
|
+
children: /* @__PURE__ */ t(
|
|
171
|
+
"path",
|
|
172
|
+
{
|
|
173
|
+
strokeLinecap: "round",
|
|
174
|
+
strokeLinejoin: "round",
|
|
175
|
+
strokeWidth: "2",
|
|
176
|
+
d: "M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"
|
|
177
|
+
}
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
);
|
|
181
|
+
case "info":
|
|
182
|
+
default:
|
|
183
|
+
return /* @__PURE__ */ t(
|
|
184
|
+
"svg",
|
|
185
|
+
{
|
|
186
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
187
|
+
fill: "none",
|
|
188
|
+
viewBox: "0 0 24 24",
|
|
189
|
+
className: "stroke-current shrink-0 w-6 h-6",
|
|
190
|
+
children: /* @__PURE__ */ t(
|
|
191
|
+
"path",
|
|
192
|
+
{
|
|
193
|
+
strokeLinecap: "round",
|
|
194
|
+
strokeLinejoin: "round",
|
|
195
|
+
strokeWidth: "2",
|
|
196
|
+
d: "M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
|
|
197
|
+
}
|
|
198
|
+
)
|
|
199
|
+
}
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
return /* @__PURE__ */ i(
|
|
204
|
+
u,
|
|
205
|
+
{
|
|
206
|
+
open: s,
|
|
207
|
+
onOk: e.showCancel ? void 0 : d,
|
|
208
|
+
onCancel: p,
|
|
209
|
+
title: e.type ? /* @__PURE__ */ i("div", { className: `alert ${f()}`, children: [
|
|
210
|
+
b(),
|
|
211
|
+
/* @__PURE__ */ t("div", { children: e.title && /* @__PURE__ */ t("h3", { className: "font-bold", children: e.title }) })
|
|
212
|
+
] }) : e.title,
|
|
213
|
+
okText: e.okText,
|
|
214
|
+
cancelText: e.cancelText,
|
|
215
|
+
footer: e.showCancel ? /* @__PURE__ */ i(F, { children: [
|
|
216
|
+
/* @__PURE__ */ t("button", { className: "btn", onClick: p, children: e.cancelText || "Cancel" }),
|
|
217
|
+
/* @__PURE__ */ t(
|
|
218
|
+
"button",
|
|
219
|
+
{
|
|
220
|
+
className: `btn ${e.type === "error" ? "btn-error" : "btn-primary"} ${c ? "loading" : ""}`,
|
|
221
|
+
onClick: d,
|
|
222
|
+
disabled: c,
|
|
223
|
+
children: e.okText || "OK"
|
|
224
|
+
}
|
|
225
|
+
)
|
|
226
|
+
] }) : /* @__PURE__ */ t(
|
|
227
|
+
"button",
|
|
228
|
+
{
|
|
229
|
+
className: `btn ${e.type === "error" ? "btn-error" : "btn-primary"} ${c ? "loading" : ""}`,
|
|
230
|
+
onClick: d,
|
|
231
|
+
disabled: c,
|
|
232
|
+
children: e.okText || "OK"
|
|
233
|
+
}
|
|
234
|
+
),
|
|
235
|
+
children: [
|
|
236
|
+
e.type && e.content && /* @__PURE__ */ t("div", { className: "text-sm", children: e.content }),
|
|
237
|
+
!e.type && e.content
|
|
238
|
+
]
|
|
239
|
+
}
|
|
240
|
+
);
|
|
241
|
+
};
|
|
242
|
+
return o.render(/* @__PURE__ */ t(l, {})), {
|
|
243
|
+
destroy: a
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
function S(e) {
|
|
247
|
+
return w({ ...e, showCancel: !0 });
|
|
248
|
+
}
|
|
249
|
+
function A(e) {
|
|
250
|
+
return w({ ...e, type: "info", showCancel: !1 });
|
|
251
|
+
}
|
|
252
|
+
function D(e) {
|
|
253
|
+
return w({ ...e, type: "success", showCancel: !1 });
|
|
254
|
+
}
|
|
255
|
+
function q(e) {
|
|
256
|
+
return w({ ...e, type: "warning", showCancel: !1 });
|
|
257
|
+
}
|
|
258
|
+
function G(e) {
|
|
259
|
+
return w({ ...e, type: "error", showCancel: !1 });
|
|
260
|
+
}
|
|
261
|
+
u.confirm = S;
|
|
262
|
+
u.info = A;
|
|
263
|
+
u.success = D;
|
|
264
|
+
u.warning = q;
|
|
265
|
+
u.error = G;
|
|
122
266
|
export {
|
|
123
|
-
|
|
267
|
+
u as Modal
|
|
124
268
|
};
|
|
125
269
|
//# sourceMappingURL=index55.js.map
|
package/dist/index55.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index55.js","sources":["../src/components/Notification.tsx"],"sourcesContent":["import React, { useEffect, useState } from 'react'\nimport ReactDOM from 'react-dom/client'\n\nexport type NotificationType = 'success' | 'info' | 'warning' | 'error'\nexport type NotificationPlacement = 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight'\n\nexport interface NotificationConfig {\n message: React.ReactNode\n description?: React.ReactNode\n type?: NotificationType\n duration?: number // in seconds, 0 = no auto close\n placement?: NotificationPlacement\n closable?: boolean\n onClick?: () => void\n onClose?: () => void\n}\n\ninterface NotificationItem extends NotificationConfig {\n id: string\n createdAt: number\n}\n\ntype Listener = () => void\n\nclass NotificationManager {\n private notifications: NotificationItem[] = []\n private listeners: Listener[] = []\n private container: HTMLDivElement | null = null\n private root: ReactDOM.Root | null = null\n private idCounter = 0\n\n subscribe(listener: Listener) {\n this.listeners.push(listener)\n return () => {\n this.listeners = this.listeners.filter((l) => l !== listener)\n }\n }\n\n getNotifications() {\n return this.notifications\n }\n\n private emit() {\n this.listeners.forEach((listener) => listener())\n }\n\n private ensureContainer() {\n if (!this.container) {\n this.container = document.createElement('div')\n document.body.appendChild(this.container)\n this.root = ReactDOM.createRoot(this.container)\n this.root.render(<NotificationContainer manager={this} />)\n }\n }\n\n open(config: NotificationConfig) {\n this.ensureContainer()\n\n const id = `notification-${++this.idCounter}`\n const notification: NotificationItem = {\n ...config,\n id,\n createdAt: Date.now(),\n duration: config.duration ?? 4.5,\n placement: config.placement ?? 'topRight',\n closable: config.closable ?? true,\n type: config.type ?? 'info',\n }\n\n this.notifications.push(notification)\n this.emit()\n\n // Auto-dismiss\n if (notification.duration && notification.duration > 0) {\n setTimeout(() => {\n this.close(id)\n }, notification.duration * 1000)\n }\n\n return id\n }\n\n close(id: string) {\n const notification = this.notifications.find((n) => n.id === id)\n this.notifications = this.notifications.filter((n) => n.id !== id)\n this.emit()\n\n if (notification?.onClose) {\n notification.onClose()\n }\n }\n\n success(config: Omit<NotificationConfig, 'type'>) {\n return this.open({ ...config, type: 'success' })\n }\n\n error(config: Omit<NotificationConfig, 'type'>) {\n return this.open({ ...config, type: 'error' })\n }\n\n info(config: Omit<NotificationConfig, 'type'>) {\n return this.open({ ...config, type: 'info' })\n }\n\n warning(config: Omit<NotificationConfig, 'type'>) {\n return this.open({ ...config, type: 'warning' })\n }\n\n destroy() {\n this.notifications = []\n this.emit()\n }\n}\n\ninterface NotificationContainerProps {\n manager: NotificationManager\n}\n\nfunction NotificationContainer({ manager }: NotificationContainerProps) {\n const [, forceUpdate] = useState({})\n\n useEffect(() => {\n const unsubscribe = manager.subscribe(() => {\n forceUpdate({})\n })\n return unsubscribe\n }, [manager])\n\n const notifications = manager.getNotifications()\n\n // Group by placement\n const grouped: Record<NotificationPlacement, NotificationItem[]> = {\n topLeft: [],\n topRight: [],\n bottomLeft: [],\n bottomRight: [],\n }\n\n notifications.forEach((notification) => {\n grouped[notification.placement!].push(notification)\n })\n\n const placementClasses: Record<NotificationPlacement, string> = {\n topRight: 'toast toast-top toast-end',\n topLeft: 'toast toast-top toast-start',\n bottomRight: 'toast toast-bottom toast-end',\n bottomLeft: 'toast toast-bottom toast-start',\n }\n\n return (\n <>\n {Object.entries(grouped).map(([placement, items]) => {\n if (items.length === 0) return null\n\n return (\n <div key={placement} className={placementClasses[placement as NotificationPlacement]}>\n {items.map((notification) => (\n <NotificationItem\n key={notification.id}\n notification={notification}\n onClose={() => manager.close(notification.id)}\n />\n ))}\n </div>\n )\n })}\n </>\n )\n}\n\ninterface NotificationItemProps {\n notification: NotificationItem\n onClose: () => void\n}\n\nfunction NotificationItem({ notification, onClose }: NotificationItemProps) {\n const alertTypeClasses: Record<NotificationType, string> = {\n success: 'alert-success',\n error: 'alert-error',\n info: 'alert-info',\n warning: 'alert-warning',\n }\n\n const handleClick = () => {\n if (notification.onClick) {\n notification.onClick()\n }\n }\n\n return (\n <div\n className={`alert ${alertTypeClasses[notification.type!]} shadow-lg cursor-pointer min-w-[300px] max-w-[400px]`}\n onClick={handleClick}\n >\n <div className=\"flex-1\">\n {notification.message && <div className=\"font-bold\">{notification.message}</div>}\n {notification.description && <div className=\"text-sm\">{notification.description}</div>}\n </div>\n {notification.closable && (\n <button\n className=\"btn btn-sm btn-ghost btn-circle\"\n onClick={(e) => {\n e.stopPropagation()\n onClose()\n }}\n >\n ✕\n </button>\n )}\n </div>\n )\n}\n\nexport const notification = new NotificationManager()\n"],"names":["NotificationManager","listener","l","ReactDOM","jsx","NotificationContainer","config","id","notification","n","manager","forceUpdate","useState","useEffect","notifications","grouped","placementClasses","Fragment","placement","items","NotificationItem","onClose","alertTypeClasses","handleClick","jsxs","e"],"mappings":";;;AAwBA,MAAMA,EAAoB;AAAA,EAChB,gBAAoC,CAAA;AAAA,EACpC,YAAw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"],"sourcesContent":["import React, { useEffect, useRef, useId } from 'react'\nimport { createRoot } from 'react-dom/client'\n\nexport interface ModalProps extends Omit<React.HTMLAttributes<HTMLDialogElement>, 'title'> {\n children: React.ReactNode\n title?: React.ReactNode\n footer?: React.ReactNode\n open?: boolean\n onOk?: () => void | Promise<void>\n onCancel?: () => void\n okText?: string\n cancelText?: string\n maskClosable?: boolean\n closable?: boolean\n position?: 'top' | 'middle' | 'bottom'\n align?: 'start' | 'end'\n}\n\nexport interface ModalFuncProps {\n title?: React.ReactNode\n content?: React.ReactNode\n onOk?: () => void | Promise<void>\n onCancel?: () => void\n okText?: string\n cancelText?: string\n type?: 'info' | 'success' | 'warning' | 'error'\n}\n\nexport function Modal({\n children,\n title,\n footer,\n open = false,\n onOk,\n onCancel,\n okText = 'OK',\n cancelText = 'Cancel',\n maskClosable = true,\n closable = true,\n position,\n align,\n className = '',\n ...rest\n}: ModalProps) {\n const dialogRef = useRef<HTMLDialogElement>(null)\n const previousActiveElement = useRef<HTMLElement | null>(null)\n const [loading, setLoading] = React.useState(false)\n const titleId = useId()\n const contentId = useId()\n\n useEffect(() => {\n const dialog = dialogRef.current\n if (!dialog) return\n\n if (open) {\n if (!dialog.open) {\n // Save currently focused element for restoration\n previousActiveElement.current = document.activeElement as HTMLElement\n dialog.showModal()\n }\n } else {\n if (dialog.open) {\n dialog.close()\n // Restore focus to previously focused element\n previousActiveElement.current?.focus()\n }\n }\n }, [open])\n\n useEffect(() => {\n const dialog = dialogRef.current\n if (!dialog) return\n\n const handleClose = () => {\n onCancel?.()\n }\n\n dialog.addEventListener('close', handleClose)\n return () => {\n dialog.removeEventListener('close', handleClose)\n }\n }, [onCancel])\n\n const positionClasses = {\n top: 'modal-top',\n middle: 'modal-middle',\n bottom: 'modal-bottom',\n }\n\n const alignClasses = {\n start: 'modal-start',\n end: 'modal-end',\n }\n\n const classes = [\n 'modal',\n position && positionClasses[position],\n align && alignClasses[align],\n className,\n ]\n .filter(Boolean)\n .join(' ')\n\n const handleOk = async () => {\n if (onOk) {\n setLoading(true)\n try {\n await onOk()\n setLoading(false)\n } catch (error) {\n setLoading(false)\n throw error\n }\n }\n }\n\n const handleBackdropClick = () => {\n if (maskClosable && onCancel) {\n onCancel()\n }\n }\n\n // Render default footer if no custom footer provided and either onOk or onCancel exists\n const shouldRenderDefaultFooter = !footer && (onOk || onCancel)\n const shouldRenderCustomFooter = footer !== null && footer !== undefined\n\n return (\n <dialog\n ref={dialogRef}\n className={classes}\n data-state={open ? 'open' : 'closed'}\n aria-labelledby={title ? titleId : undefined}\n aria-describedby={contentId}\n {...rest}\n >\n <div className=\"modal-box\">\n {title && (\n <h3 id={titleId} className=\"text-lg font-bold mb-4\">\n {title}\n </h3>\n )}\n <div id={contentId} className=\"py-4\">\n {children}\n </div>\n {shouldRenderDefaultFooter && (\n <div className=\"modal-action\">\n {onCancel && (\n <button className=\"btn\" onClick={onCancel}>\n {cancelText}\n </button>\n )}\n {onOk && (\n <button\n className={`btn btn-primary ${loading ? 'loading' : ''}`}\n onClick={handleOk}\n disabled={loading}\n >\n {okText}\n </button>\n )}\n </div>\n )}\n {shouldRenderCustomFooter && <div className=\"modal-action\">{footer}</div>}\n </div>\n {closable && maskClosable && (\n <form method=\"dialog\" className=\"modal-backdrop\">\n <button onClick={handleBackdropClick}>close</button>\n </form>\n )}\n </dialog>\n )\n}\n\nfunction createModal(config: ModalFuncProps & { showCancel?: boolean }) {\n const div = document.createElement('div')\n document.body.appendChild(div)\n const root = createRoot(div)\n\n const destroy = () => {\n root.unmount()\n if (div.parentNode) {\n div.parentNode.removeChild(div)\n }\n }\n\n const ModalContent = () => {\n const [open, setOpen] = React.useState(true)\n const [loading, setLoading] = React.useState(false)\n\n const handleClose = () => {\n setOpen(false)\n setTimeout(destroy, 300) // Wait for animation\n }\n\n const handleOk = async () => {\n if (config.onOk) {\n setLoading(true)\n try {\n await config.onOk()\n handleClose()\n } catch (error) {\n setLoading(false)\n }\n } else {\n handleClose()\n }\n }\n\n const handleCancel = () => {\n config.onCancel?.()\n handleClose()\n }\n\n const getAlertClass = () => {\n switch (config.type) {\n case 'success':\n return 'alert-success'\n case 'warning':\n return 'alert-warning'\n case 'error':\n return 'alert-error'\n case 'info':\n default:\n return 'alert-info'\n }\n }\n\n const getIcon = () => {\n switch (config.type) {\n case 'success':\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n className=\"stroke-current shrink-0 h-6 w-6\"\n fill=\"none\"\n viewBox=\"0 0 24 24\"\n >\n <path\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth=\"2\"\n d=\"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z\"\n />\n </svg>\n )\n case 'warning':\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n className=\"stroke-current shrink-0 h-6 w-6\"\n fill=\"none\"\n viewBox=\"0 0 24 24\"\n >\n <path\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth=\"2\"\n d=\"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z\"\n />\n </svg>\n )\n case 'error':\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n className=\"stroke-current shrink-0 h-6 w-6\"\n fill=\"none\"\n viewBox=\"0 0 24 24\"\n >\n <path\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth=\"2\"\n d=\"M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z\"\n />\n </svg>\n )\n case 'info':\n default:\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n fill=\"none\"\n viewBox=\"0 0 24 24\"\n className=\"stroke-current shrink-0 w-6 h-6\"\n >\n <path\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth=\"2\"\n d=\"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z\"\n ></path>\n </svg>\n )\n }\n }\n\n return (\n <Modal\n open={open}\n onOk={config.showCancel ? undefined : handleOk}\n onCancel={handleCancel}\n title={\n config.type ? (\n <div className={`alert ${getAlertClass()}`}>\n {getIcon()}\n <div>\n {config.title && <h3 className=\"font-bold\">{config.title}</h3>}\n </div>\n </div>\n ) : (\n config.title\n )\n }\n okText={config.okText}\n cancelText={config.cancelText}\n footer={\n config.showCancel ? (\n <>\n <button className=\"btn\" onClick={handleCancel}>\n {config.cancelText || 'Cancel'}\n </button>\n <button\n className={`btn ${config.type === 'error' ? 'btn-error' : 'btn-primary'} ${loading ? 'loading' : ''}`}\n onClick={handleOk}\n disabled={loading}\n >\n {config.okText || 'OK'}\n </button>\n </>\n ) : (\n <button\n className={`btn ${config.type === 'error' ? 'btn-error' : 'btn-primary'} ${loading ? 'loading' : ''}`}\n onClick={handleOk}\n disabled={loading}\n >\n {config.okText || 'OK'}\n </button>\n )\n }\n >\n {config.type && config.content && <div className=\"text-sm\">{config.content}</div>}\n {!config.type && config.content}\n </Modal>\n )\n }\n\n root.render(<ModalContent />)\n\n return {\n destroy,\n }\n}\n\nfunction confirm(config: ModalFuncProps) {\n return createModal({ ...config, showCancel: true })\n}\n\nfunction info(config: ModalFuncProps) {\n return createModal({ ...config, type: 'info', showCancel: false })\n}\n\nfunction success(config: ModalFuncProps) {\n return createModal({ ...config, type: 'success', showCancel: false })\n}\n\nfunction warning(config: ModalFuncProps) {\n return createModal({ ...config, type: 'warning', showCancel: false })\n}\n\nfunction error(config: ModalFuncProps) {\n return createModal({ ...config, type: 'error', showCancel: false })\n}\n\nModal.confirm = confirm\nModal.info = info\nModal.success = success\nModal.warning = warning\nModal.error = error\n"],"names":["Modal","children","title","footer","open","onOk","onCancel","okText","cancelText","maskClosable","closable","position","align","className","rest","dialogRef","useRef","previousActiveElement","loading","setLoading","React","titleId","useId","contentId","useEffect","dialog","handleClose","positionClasses","alignClasses","classes","handleOk","error","handleBackdropClick","shouldRenderDefaultFooter","shouldRenderCustomFooter","jsxs","jsx","createModal","config","div","root","createRoot","destroy","ModalContent","setOpen","handleCancel","getAlertClass","getIcon","Fragment","confirm","info","success","warning"],"mappings":";;;AA4BO,SAASA,EAAM;AAAA,EACpB,UAAAC;AAAA,EACA,OAAAC;AAAA,EACA,QAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,MAAAC;AAAA,EACA,UAAAC;AAAA,EACA,QAAAC,IAAS;AAAA,EACT,YAAAC,IAAa;AAAA,EACb,cAAAC,IAAe;AAAA,EACf,UAAAC,IAAW;AAAA,EACX,UAAAC;AAAA,EACA,OAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,GAAGC;AACL,GAAe;AACb,QAAMC,IAAYC,EAA0B,IAAI,GAC1CC,IAAwBD,EAA2B,IAAI,GACvD,CAACE,GAASC,CAAU,IAAIC,EAAM,SAAS,EAAK,GAC5CC,IAAUC,EAAA,GACVC,IAAYD,EAAA;AAElB,EAAAE,EAAU,MAAM;AACd,UAAMC,IAASV,EAAU;AACzB,IAAKU,MAEDrB,IACGqB,EAAO,SAEVR,EAAsB,UAAU,SAAS,eACzCQ,EAAO,UAAA,KAGLA,EAAO,SACTA,EAAO,MAAA,GAEPR,EAAsB,SAAS,MAAA;AAAA,EAGrC,GAAG,CAACb,CAAI,CAAC,GAEToB,EAAU,MAAM;AACd,UAAMC,IAASV,EAAU;AACzB,QAAI,CAACU,EAAQ;AAEb,UAAMC,IAAc,MAAM;AACxB,MAAApB,IAAA;AAAA,IACF;AAEA,WAAAmB,EAAO,iBAAiB,SAASC,CAAW,GACrC,MAAM;AACX,MAAAD,EAAO,oBAAoB,SAASC,CAAW;AAAA,IACjD;AAAA,EACF,GAAG,CAACpB,CAAQ,CAAC;AAEb,QAAMqB,IAAkB;AAAA,IACtB,KAAK;AAAA,IACL,QAAQ;AAAA,IACR,QAAQ;AAAA,EAAA,GAGJC,IAAe;A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UAC1E,CAACE,EAAO,QAAQA,EAAO;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAG9B;AAEA,SAAAE,EAAK,OAAO,gBAAAJ,EAACO,GAAA,CAAA,CAAa,CAAE,GAErB;AAAA,IACL,SAAAD;AAAA,EAAA;AAEJ;AAEA,SAASO,EAAQX,GAAwB;AACvC,SAAOD,EAAY,EAAE,GAAGC,GAAQ,YAAY,IAAM;AACpD;AAEA,SAASY,EAAKZ,GAAwB;AACpC,SAAOD,EAAY,EAAE,GAAGC,GAAQ,MAAM,QAAQ,YAAY,IAAO;AACnE;AAEA,SAASa,EAAQb,GAAwB;AACvC,SAAOD,EAAY,EAAE,GAAGC,GAAQ,MAAM,WAAW,YAAY,IAAO;AACtE;AAEA,SAASc,EAAQd,GAAwB;AACvC,SAAOD,EAAY,EAAE,GAAGC,GAAQ,MAAM,WAAW,YAAY,IAAO;AACtE;AAEA,SAASP,EAAMO,GAAwB;AACrC,SAAOD,EAAY,EAAE,GAAGC,GAAQ,MAAM,SAAS,YAAY,IAAO;AACpE;AAEAtC,EAAM,UAAUiD;AAChBjD,EAAM,OAAOkD;AACblD,EAAM,UAAUmD;AAChBnD,EAAM,UAAUoD;AAChBpD,EAAM,QAAQ+B;"}
|
package/dist/index56.js
CHANGED
|
@@ -1,113 +1,20 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}, R) => {
|
|
18
|
-
const [a, o] = M(() => {
|
|
19
|
-
const t = p.split("").slice(0, s);
|
|
20
|
-
return [...t, ...Array(s - t.length).fill("")];
|
|
21
|
-
}), u = V([]), x = {
|
|
22
|
-
xs: "input-xs w-8 h-8 text-sm",
|
|
23
|
-
sm: "input-sm w-10 h-10 text-base",
|
|
24
|
-
md: "w-12 h-12 text-lg",
|
|
25
|
-
lg: "input-lg w-14 h-14 text-xl",
|
|
26
|
-
xl: "w-16 h-16 text-2xl"
|
|
27
|
-
};
|
|
28
|
-
Z(R, () => ({
|
|
29
|
-
focus: () => {
|
|
30
|
-
u.current[0]?.focus();
|
|
31
|
-
},
|
|
32
|
-
clear: () => {
|
|
33
|
-
o(Array(s).fill("")), u.current[0]?.focus();
|
|
34
|
-
}
|
|
35
|
-
})), j(() => {
|
|
36
|
-
A && u.current[0]?.focus();
|
|
37
|
-
}, [A]), j(() => {
|
|
38
|
-
const t = p.split("").slice(0, s);
|
|
39
|
-
o([...t, ...Array(s - t.length).fill("")]);
|
|
40
|
-
}, [p, s]);
|
|
41
|
-
const w = i(
|
|
42
|
-
(t, e) => {
|
|
43
|
-
if (c || f === "number" && !/^\d*$/.test(e) || f === "text" && !/^[a-zA-Z0-9]*$/.test(e)) return;
|
|
44
|
-
const r = [...a];
|
|
45
|
-
if (e.length > 1) {
|
|
46
|
-
const O = e.slice(0, s - t).split("");
|
|
47
|
-
O.forEach((K, $) => {
|
|
48
|
-
t + $ < s && (r[t + $] = K);
|
|
49
|
-
}), o(r);
|
|
50
|
-
const D = r.join("");
|
|
51
|
-
n?.(D);
|
|
52
|
-
const E = Math.min(t + O.length, s - 1);
|
|
53
|
-
u.current[E]?.focus(), D.length === s && m?.(D);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
r[t] = e, o(r);
|
|
57
|
-
const l = r.join("");
|
|
58
|
-
n?.(l), e && t < s - 1 && u.current[t + 1]?.focus(), l.length === s && !l.includes("") && m?.(l);
|
|
59
|
-
},
|
|
60
|
-
[a, s, f, c, n, m]
|
|
61
|
-
), z = i(
|
|
62
|
-
(t, e) => {
|
|
63
|
-
if (!c)
|
|
64
|
-
if (e.key === "Backspace") {
|
|
65
|
-
e.preventDefault();
|
|
66
|
-
const r = [...a];
|
|
67
|
-
a[t] ? (r[t] = "", o(r), n?.(r.join(""))) : t > 0 && (r[t - 1] = "", o(r), n?.(r.join("")), u.current[t - 1]?.focus());
|
|
68
|
-
} else e.key === "ArrowLeft" && t > 0 ? (e.preventDefault(), u.current[t - 1]?.focus()) : e.key === "ArrowRight" && t < s - 1 && (e.preventDefault(), u.current[t + 1]?.focus());
|
|
69
|
-
},
|
|
70
|
-
[a, s, c, n]
|
|
71
|
-
), N = i(
|
|
72
|
-
(t) => {
|
|
73
|
-
if (t.preventDefault(), c) return;
|
|
74
|
-
const e = t.clipboardData.getData("text"), r = f === "number" ? e.replace(/\D/g, "") : e.replace(/[^a-zA-Z0-9]/g, "");
|
|
75
|
-
r && w(0, r);
|
|
76
|
-
},
|
|
77
|
-
[f, c, w]
|
|
78
|
-
), T = i((t) => {
|
|
79
|
-
t.target.select();
|
|
80
|
-
}, []);
|
|
81
|
-
return /* @__PURE__ */ v("div", { className: `flex gap-2 ${I}`, children: a.map((t, e) => /* @__PURE__ */ v(
|
|
82
|
-
"input",
|
|
83
|
-
{
|
|
84
|
-
ref: (r) => {
|
|
85
|
-
u.current[e] = r;
|
|
86
|
-
},
|
|
87
|
-
type: y ? "password" : f === "number" ? "tel" : "text",
|
|
88
|
-
inputMode: f === "number" ? "numeric" : "text",
|
|
89
|
-
maxLength: 1,
|
|
90
|
-
value: t,
|
|
91
|
-
placeholder: b,
|
|
92
|
-
disabled: c,
|
|
93
|
-
onChange: (r) => w(e, r.target.value),
|
|
94
|
-
onKeyDown: (r) => z(e, r),
|
|
95
|
-
onPaste: N,
|
|
96
|
-
onFocus: T,
|
|
97
|
-
className: `
|
|
98
|
-
input input-bordered text-center font-mono
|
|
99
|
-
${x[k]}
|
|
100
|
-
${P ? "input-error" : ""}
|
|
101
|
-
${c ? "input-disabled opacity-50" : ""}
|
|
102
|
-
`,
|
|
103
|
-
"aria-label": `OTP digit ${e + 1}`
|
|
104
|
-
},
|
|
105
|
-
e
|
|
106
|
-
)) });
|
|
107
|
-
}
|
|
108
|
-
);
|
|
109
|
-
g.displayName = "OTPInput";
|
|
1
|
+
import { jsx as a, jsxs as c } from "react/jsx-runtime";
|
|
2
|
+
const d = ({
|
|
3
|
+
children: s,
|
|
4
|
+
start: r,
|
|
5
|
+
center: e,
|
|
6
|
+
end: n,
|
|
7
|
+
className: v = "",
|
|
8
|
+
...i
|
|
9
|
+
}) => {
|
|
10
|
+
const l = ["navbar bg-base-100", v].filter(Boolean).join(" ");
|
|
11
|
+
return s ? /* @__PURE__ */ a("div", { className: l, ...i, children: s }) : /* @__PURE__ */ c("div", { className: l, ...i, children: [
|
|
12
|
+
r && /* @__PURE__ */ a("div", { className: "navbar-start", children: r }),
|
|
13
|
+
e && /* @__PURE__ */ a("div", { className: "navbar-center", children: e }),
|
|
14
|
+
n && /* @__PURE__ */ a("div", { className: "navbar-end", children: n })
|
|
15
|
+
] });
|
|
16
|
+
};
|
|
110
17
|
export {
|
|
111
|
-
|
|
18
|
+
d as Navbar
|
|
112
19
|
};
|
|
113
20
|
//# sourceMappingURL=index56.js.map
|
package/dist/index56.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index56.js","sources":["../src/components/OTPInput.tsx"],"sourcesContent":["import React, { useRef, useState, useEffect, useCallback, forwardRef, useImperativeHandle } from 'react'\n\nexport interface OTPInputProps {\n /** Number of input fields */\n length?: number\n /** Current value */\n value?: string\n /** Callback when value changes */\n onChange?: (value: string) => void\n /** Callback when all fields are filled */\n onComplete?: (value: string) => void\n /** Input size */\n size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl'\n /** Input type - number only or alphanumeric */\n type?: 'number' | 'text'\n /** Mask input (show dots instead of characters) */\n mask?: boolean\n /** Disabled state */\n disabled?: boolean\n /** Error state */\n error?: boolean\n /** Auto focus first input on mount */\n autoFocus?: boolean\n /** Placeholder character */\n placeholder?: string\n /** Additional CSS classes */\n className?: string\n}\n\nexport interface OTPInputRef {\n focus: () => void\n clear: () => void\n}\n\nexport const OTPInput = forwardRef<OTPInputRef, OTPInputProps>(\n (\n {\n length = 6,\n value = '',\n onChange,\n onComplete,\n size = 'md',\n type = 'number',\n mask = false,\n disabled = false,\n error = false,\n autoFocus = false,\n placeholder = '',\n className = '',\n },\n ref\n ) => {\n const [otp, setOtp] = useState<string[]>(() => {\n const initial = value.split('').slice(0, length)\n return [...initial, ...Array(length - initial.length).fill('')]\n })\n\n const inputRefs = useRef<(HTMLInputElement | null)[]>([])\n\n const sizeClasses = {\n xs: 'input-xs w-8 h-8 text-sm',\n sm: 'input-sm w-10 h-10 text-base',\n md: 'w-12 h-12 text-lg',\n lg: 'input-lg w-14 h-14 text-xl',\n xl: 'w-16 h-16 text-2xl',\n }\n\n useImperativeHandle(ref, () => ({\n focus: () => {\n inputRefs.current[0]?.focus()\n },\n clear: () => {\n setOtp(Array(length).fill(''))\n inputRefs.current[0]?.focus()\n },\n }))\n\n useEffect(() => {\n if (autoFocus) {\n inputRefs.current[0]?.focus()\n }\n }, [autoFocus])\n\n useEffect(() => {\n const newOtp = value.split('').slice(0, length)\n setOtp([...newOtp, ...Array(length - newOtp.length).fill('')])\n }, [value, length])\n\n const handleChange = useCallback(\n (index: number, char: string) => {\n if (disabled) return\n\n // Validate input\n if (type === 'number' && !/^\\d*$/.test(char)) return\n if (type === 'text' && !/^[a-zA-Z0-9]*$/.test(char)) return\n\n const newOtp = [...otp]\n\n // Handle paste of multiple characters\n if (char.length > 1) {\n const chars = char.slice(0, length - index).split('')\n chars.forEach((c, i) => {\n if (index + i < length) {\n newOtp[index + i] = c\n }\n })\n setOtp(newOtp)\n\n const newValue = newOtp.join('')\n onChange?.(newValue)\n\n // Focus appropriate field\n const nextIndex = Math.min(index + chars.length, length - 1)\n inputRefs.current[nextIndex]?.focus()\n\n if (newValue.length === length) {\n onComplete?.(newValue)\n }\n return\n }\n\n // Single character\n newOtp[index] = char\n setOtp(newOtp)\n\n const newValue = newOtp.join('')\n onChange?.(newValue)\n\n // Move to next input\n if (char && index < length - 1) {\n inputRefs.current[index + 1]?.focus()\n }\n\n if (newValue.length === length && !newValue.includes('')) {\n onComplete?.(newValue)\n }\n },\n [otp, length, type, disabled, onChange, onComplete]\n )\n\n const handleKeyDown = useCallback(\n (index: number, e: React.KeyboardEvent<HTMLInputElement>) => {\n if (disabled) return\n\n if (e.key === 'Backspace') {\n e.preventDefault()\n const newOtp = [...otp]\n\n if (otp[index]) {\n // Clear current field\n newOtp[index] = ''\n setOtp(newOtp)\n onChange?.(newOtp.join(''))\n } else if (index > 0) {\n // Move to previous field and clear it\n newOtp[index - 1] = ''\n setOtp(newOtp)\n onChange?.(newOtp.join(''))\n inputRefs.current[index - 1]?.focus()\n }\n } else if (e.key === 'ArrowLeft' && index > 0) {\n e.preventDefault()\n inputRefs.current[index - 1]?.focus()\n } else if (e.key === 'ArrowRight' && index < length - 1) {\n e.preventDefault()\n inputRefs.current[index + 1]?.focus()\n }\n },\n [otp, length, disabled, onChange]\n )\n\n const handlePaste = useCallback(\n (e: React.ClipboardEvent) => {\n e.preventDefault()\n if (disabled) return\n\n const pastedData = e.clipboardData.getData('text')\n const filteredData =\n type === 'number'\n ? pastedData.replace(/\\D/g, '')\n : pastedData.replace(/[^a-zA-Z0-9]/g, '')\n\n if (filteredData) {\n handleChange(0, filteredData)\n }\n },\n [type, disabled, handleChange]\n )\n\n const handleFocus = useCallback((e: React.FocusEvent<HTMLInputElement>) => {\n e.target.select()\n }, [])\n\n return (\n <div className={`flex gap-2 ${className}`}>\n {otp.map((digit, index) => (\n <input\n key={index}\n ref={(el) => {\n inputRefs.current[index] = el\n }}\n type={mask ? 'password' : type === 'number' ? 'tel' : 'text'}\n inputMode={type === 'number' ? 'numeric' : 'text'}\n maxLength={1}\n value={digit}\n placeholder={placeholder}\n disabled={disabled}\n onChange={(e) => handleChange(index, e.target.value)}\n onKeyDown={(e) => handleKeyDown(index, e)}\n onPaste={handlePaste}\n onFocus={handleFocus}\n className={`\n input input-bordered text-center font-mono\n ${sizeClasses[size]}\n ${error ? 'input-error' : ''}\n ${disabled ? 'input-disabled opacity-50' : ''}\n `}\n aria-label={`OTP digit ${index + 1}`}\n />\n ))}\n </div>\n )\n }\n)\n\nOTPInput.displayName = 'OTPInput'\n"],"names":["OTPInput","forwardRef","length","value","onChange","onComplete","size","type","mask","disabled","error","autoFocus","placeholder","className","ref","otp","setOtp","useState","initial","inputRefs","useRef","sizeClasses","useImperativeHandle","useEffect","newOtp","handleChange","useCallback","index","char","chars","c","i","newValue","nextIndex","handleKeyDown","handlePaste","e","pastedData","filteredData","handleFocus","jsx","digit","el"],"mappings":";;AAkCO,MAAMA,IAAWC;AAAA,EACtB,CACE;AAAA,IACE,QAAAC,IAAS;AAAA,IACT,OAAAC,IAAQ;AAAA,IACR,UAAAC;AAAA,IACA,YAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,MAAAC,IAAO;AAAA,IACP,MAAAC,IAAO;AAAA,IACP,UAAAC,IAAW;AAAA,IACX,OAAAC,IAAQ;AAAA,IACR,WAAAC,IAAY;AAAA,IACZ,aAAAC,IAAc;AAAA,IACd,WAAAC,IAAY;AAAA,EAAA,GAEdC,MACG;AACH,UAAM,CAACC,GAAKC,CAAM,IAAIC,EAAmB,MAAM;AAC7C,YAAMC,IAAUf,EAAM,MAAM,EAAE,EAAE,MAAM,GAAGD,CAAM;AAC/C,aAAO,CAAC,GAAGgB,GAAS,GAAG,MAAMhB,IAASgB,EAAQ,MAAM,EAAE,KAAK,EAAE,CAAC;AAAA,IAChE,CAAC,GAEKC,IAAYC,EAAoC,EAAE,GAElDC,IAAc;AAAA,MAClB,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,IAAA;AAGN,IAAAC,EAAoBR,GAAK,OAAO;AAAA,MAC9B,OAAO,MAAM;AACX,QAAAK,EAAU,QAAQ,CAAC,GAAG,MAAA;AAAA,MACxB;AAAA,MACA,OAAO,MAAM;AACX,QAAAH,EAAO,MAAMd,CAAM,EAA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E;AAE5C,QAAIC,KACFb,EAAa,GAAGa,CAAY;AAAA,MAEhC;AAAA,MACA,CAAC/B,GAAME,GAAUgB,CAAY;AAAA,IAAA,GAGzBc,IAAcb,EAAY,CAACU,MAA0C;AACzE,MAAAA,EAAE,OAAO,OAAA;AAAA,IACX,GAAG,CAAA,CAAE;AAEL,WACE,gBAAAI,EAAC,OAAA,EAAI,WAAW,cAAc3B,CAAS,IACpC,UAAAE,EAAI,IAAI,CAAC0B,GAAOd,MACf,gBAAAa;AAAA,MAAC;AAAA,MAAA;AAAA,QAEC,KAAK,CAACE,MAAO;AACX,UAAAvB,EAAU,QAAQQ,CAAK,IAAIe;AAAA,QAC7B;AAAA,QACA,MAAMlC,IAAO,aAAaD,MAAS,WAAW,QAAQ;AAAA,QACtD,WAAWA,MAAS,WAAW,YAAY;AAAA,QAC3C,WAAW;AAAA,QACX,OAAOkC;AAAA,QACP,aAAA7B;AAAA,QACA,UAAAH;AAAA,QACA,UAAU,CAAC2B,MAAMX,EAAaE,GAAOS,EAAE,OAAO,KAAK;AAAA,QACnD,WAAW,CAACA,MAAMF,EAAcP,GAAOS,CAAC;AAAA,QACxC,SAASD;AAAA,QACT,SAASI;AAAA,QACT,WAAW;AAAA;AAAA,gBAEPlB,EAAYf,CAAI,CAAC;AAAA,gBACjBI,IAAQ,gBAAgB,EAAE;AAAA,gBAC1BD,IAAW,8BAA8B,EAAE;AAAA;AAAA,QAE/C,cAAY,aAAakB,IAAQ,CAAC;AAAA,MAAA;AAAA,MApB7BA;AAAA,IAAA,CAsBR,GACH;AAAA,EAEJ;AACF;AAEA3B,EAAS,cAAc;"}
|
|
1
|
+
{"version":3,"file":"index56.js","sources":["../src/components/Navbar.tsx"],"sourcesContent":["import React from 'react'\n\nexport interface NavbarProps extends React.HTMLAttributes<HTMLDivElement> {\n children?: React.ReactNode\n start?: React.ReactNode\n center?: React.ReactNode\n end?: React.ReactNode\n}\n\nexport const Navbar: React.FC<NavbarProps> = ({\n children,\n start,\n center,\n end,\n className = '',\n ...rest\n}) => {\n const navbarClasses = ['navbar bg-base-100', className]\n .filter(Boolean)\n .join(' ')\n\n if (children) {\n return <div className={navbarClasses} {...rest}>{children}</div>\n }\n\n return (\n <div className={navbarClasses} {...rest}>\n {start && <div className=\"navbar-start\">{start}</div>}\n {center && <div className=\"navbar-center\">{center}</div>}\n {end && <div className=\"navbar-end\">{end}</div>}\n </div>\n )\n}\n"],"names":["Navbar","children","start","center","end","className","rest","navbarClasses","jsxs","jsx"],"mappings":";AASO,MAAMA,IAAgC,CAAC;AAAA,EAC5C,UAAAC;AAAA,EACA,OAAAC;AAAA,EACA,QAAAC;AAAA,EACA,KAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,GAAGC;AACL,MAAM;AACJ,QAAMC,IAAgB,CAAC,sBAAsBF,CAAS,EACnD,OAAO,OAAO,EACd,KAAK,GAAG;AAEX,SAAIJ,sBACM,OAAA,EAAI,WAAWM,GAAgB,GAAGD,GAAO,UAAAL,GAAS,IAI1D,gBAAAO,EAAC,OAAA,EAAI,WAAWD,GAAgB,GAAGD,GAChC,UAAA;AAAA,IAAAJ,KAAS,gBAAAO,EAAC,OAAA,EAAI,WAAU,gBAAgB,UAAAP,GAAM;AAAA,IAC9CC,KAAU,gBAAAM,EAAC,OAAA,EAAI,WAAU,iBAAiB,UAAAN,GAAO;AAAA,IACjDC,KAAO,gBAAAK,EAAC,OAAA,EAAI,WAAU,cAAc,UAAAL,EAAA,CAAI;AAAA,EAAA,GAC3C;AAEJ;"}
|