asterui 0.12.16 → 0.12.18

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 (144) hide show
  1. package/dist/components/Card.d.ts +14 -2
  2. package/dist/components/Checkbox.d.ts +3 -1
  3. package/dist/components/Form.d.ts +7 -1
  4. package/dist/components/Input.d.ts +10 -2
  5. package/dist/components/Select.d.ts +8 -0
  6. package/dist/index.d.ts +0 -2
  7. package/dist/index.js +134 -136
  8. package/dist/index.js.map +1 -1
  9. package/dist/index10.js +70 -65
  10. package/dist/index10.js.map +1 -1
  11. package/dist/index100.js +43 -11
  12. package/dist/index100.js.map +1 -1
  13. package/dist/index101.js +11 -44
  14. package/dist/index101.js.map +1 -1
  15. package/dist/index102.js +12 -10
  16. package/dist/index102.js.map +1 -1
  17. package/dist/index103.js +7 -14
  18. package/dist/index103.js.map +1 -1
  19. package/dist/index104.js +12 -7
  20. package/dist/index104.js.map +1 -1
  21. package/dist/index105.js +29 -11
  22. package/dist/index105.js.map +1 -1
  23. package/dist/index106.js +16 -29
  24. package/dist/index106.js.map +1 -1
  25. package/dist/index13.js +86 -68
  26. package/dist/index13.js.map +1 -1
  27. package/dist/index34.js +198 -158
  28. package/dist/index34.js.map +1 -1
  29. package/dist/index42.js +185 -148
  30. package/dist/index42.js.map +1 -1
  31. package/dist/index43.js +19 -19
  32. package/dist/index43.js.map +1 -1
  33. package/dist/index46.js +134 -18
  34. package/dist/index46.js.map +1 -1
  35. package/dist/index47.js +10 -134
  36. package/dist/index47.js.map +1 -1
  37. package/dist/index48.js +35 -13
  38. package/dist/index48.js.map +1 -1
  39. package/dist/index49.js +34 -35
  40. package/dist/index49.js.map +1 -1
  41. package/dist/index50.js +81 -34
  42. package/dist/index50.js.map +1 -1
  43. package/dist/index51.js +166 -71
  44. package/dist/index51.js.map +1 -1
  45. package/dist/index52.js +144 -167
  46. package/dist/index52.js.map +1 -1
  47. package/dist/index53.js +11 -152
  48. package/dist/index53.js.map +1 -1
  49. package/dist/index54.js +20 -10
  50. package/dist/index54.js.map +1 -1
  51. package/dist/index55.js +14 -22
  52. package/dist/index55.js.map +1 -1
  53. package/dist/index56.js +7 -14
  54. package/dist/index56.js.map +1 -1
  55. package/dist/index57.js +333 -6
  56. package/dist/index57.js.map +1 -1
  57. package/dist/index58.js +47 -334
  58. package/dist/index58.js.map +1 -1
  59. package/dist/index59.js +122 -47
  60. package/dist/index59.js.map +1 -1
  61. package/dist/index60.js +108 -120
  62. package/dist/index60.js.map +1 -1
  63. package/dist/index61.js +167 -107
  64. package/dist/index61.js.map +1 -1
  65. package/dist/index62.js +29 -167
  66. package/dist/index62.js.map +1 -1
  67. package/dist/index63.js +120 -30
  68. package/dist/index63.js.map +1 -1
  69. package/dist/index64.js +80 -116
  70. package/dist/index64.js.map +1 -1
  71. package/dist/index65.js +19 -85
  72. package/dist/index65.js.map +1 -1
  73. package/dist/index66.js +73 -19
  74. package/dist/index66.js.map +1 -1
  75. package/dist/index67.js +54 -71
  76. package/dist/index67.js.map +1 -1
  77. package/dist/index68.js +44 -56
  78. package/dist/index68.js.map +1 -1
  79. package/dist/index69.js +49 -42
  80. package/dist/index69.js.map +1 -1
  81. package/dist/index70.js +121 -50
  82. package/dist/index70.js.map +1 -1
  83. package/dist/index71.js +102 -118
  84. package/dist/index71.js.map +1 -1
  85. package/dist/index72.js +72 -105
  86. package/dist/index72.js.map +1 -1
  87. package/dist/index73.js +68 -41
  88. package/dist/index73.js.map +1 -1
  89. package/dist/index74.js +19 -66
  90. package/dist/index74.js.map +1 -1
  91. package/dist/index75.js +55 -18
  92. package/dist/index75.js.map +1 -1
  93. package/dist/index76.js +251 -55
  94. package/dist/index76.js.map +1 -1
  95. package/dist/index77.js +22 -254
  96. package/dist/index77.js.map +1 -1
  97. package/dist/index78.js +31 -22
  98. package/dist/index78.js.map +1 -1
  99. package/dist/index79.js +93 -30
  100. package/dist/index79.js.map +1 -1
  101. package/dist/index80.js +324 -89
  102. package/dist/index80.js.map +1 -1
  103. package/dist/index81.js +73 -322
  104. package/dist/index81.js.map +1 -1
  105. package/dist/index82.js +39 -79
  106. package/dist/index82.js.map +1 -1
  107. package/dist/index83.js +23 -40
  108. package/dist/index83.js.map +1 -1
  109. package/dist/index84.js +93 -21
  110. package/dist/index84.js.map +1 -1
  111. package/dist/index85.js +148 -87
  112. package/dist/index85.js.map +1 -1
  113. package/dist/index86.js +152 -147
  114. package/dist/index86.js.map +1 -1
  115. package/dist/index87.js +63 -159
  116. package/dist/index87.js.map +1 -1
  117. package/dist/index88.js +35 -65
  118. package/dist/index88.js.map +1 -1
  119. package/dist/index89.js +234 -35
  120. package/dist/index89.js.map +1 -1
  121. package/dist/index90.js +31 -231
  122. package/dist/index90.js.map +1 -1
  123. package/dist/index91.js +210 -34
  124. package/dist/index91.js.map +1 -1
  125. package/dist/index92.js +198 -195
  126. package/dist/index92.js.map +1 -1
  127. package/dist/index93.js +241 -159
  128. package/dist/index93.js.map +1 -1
  129. package/dist/index94.js +166 -283
  130. package/dist/index94.js.map +1 -1
  131. package/dist/index95.js +253 -173
  132. package/dist/index95.js.map +1 -1
  133. package/dist/index96.js +14 -258
  134. package/dist/index96.js.map +1 -1
  135. package/dist/index97.js +31 -12
  136. package/dist/index97.js.map +1 -1
  137. package/dist/index98.js +5 -32
  138. package/dist/index98.js.map +1 -1
  139. package/dist/index99.js +13 -5
  140. package/dist/index99.js.map +1 -1
  141. package/package.json +1 -1
  142. package/dist/components/Label.d.ts +0 -15
  143. package/dist/index107.js +0 -21
  144. package/dist/index107.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index59.js","sources":["../src/components/Navbar.tsx"],"sourcesContent":["import React from 'react'\n\nexport type NavbarColor = 'base' | 'neutral' | 'primary' | 'secondary' | 'accent'\nexport type NavbarShadow = 'none' | 'sm' | 'md' | 'lg' | 'xl'\nexport type NavbarRounded = 'none' | 'sm' | 'md' | 'lg' | 'xl' | 'full'\n\nexport interface NavbarProps extends Omit<React.HTMLAttributes<HTMLElement>, 'color'> {\n children?: React.ReactNode\n /** Content for the start section of the navbar (typically logo/brand) */\n start?: React.ReactNode\n /** Content for the center section of the navbar */\n center?: React.ReactNode\n /** Content for the end section of the navbar (typically actions/menu) */\n end?: React.ReactNode\n /** Background color variant */\n color?: NavbarColor\n /** Make navbar sticky at the top */\n sticky?: boolean\n /** Shadow depth */\n shadow?: NavbarShadow\n /** Border radius */\n rounded?: NavbarRounded\n}\n\nconst colorClasses: Record<NavbarColor, string> = {\n base: 'bg-base-100',\n neutral: 'bg-neutral text-neutral-content',\n primary: 'bg-primary text-primary-content',\n secondary: 'bg-secondary text-secondary-content',\n accent: 'bg-accent text-accent-content',\n}\n\nconst shadowClasses: Record<NavbarShadow, string> = {\n none: '',\n sm: 'shadow-sm',\n md: 'shadow-md',\n lg: 'shadow-lg',\n xl: 'shadow-xl',\n}\n\nconst roundedClasses: Record<NavbarRounded, string> = {\n none: '',\n sm: 'rounded-sm',\n md: 'rounded-md',\n lg: 'rounded-lg',\n xl: 'rounded-xl',\n full: 'rounded-full',\n}\n\nexport const Navbar: React.FC<NavbarProps> = ({\n children,\n start,\n center,\n end,\n color = 'base',\n sticky = false,\n shadow = 'none',\n rounded = 'none',\n className = '',\n ...rest\n}) => {\n const navbarClasses = [\n 'navbar',\n colorClasses[color],\n sticky && 'sticky top-0 z-50',\n shadowClasses[shadow],\n roundedClasses[rounded],\n className,\n ]\n .filter(Boolean)\n .join(' ')\n\n if (children) {\n return <nav className={navbarClasses} {...rest}>{children}</nav>\n }\n\n return (\n <nav 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 </nav>\n )\n}\n"],"names":["colorClasses","shadowClasses","roundedClasses","Navbar","children","start","center","end","color","sticky","shadow","rounded","className","rest","navbarClasses","jsxs","jsx"],"mappings":";AAwBA,MAAMA,IAA4C;AAAA,EAChD,MAAM;AAAA,EACN,SAAS;AAAA,EACT,SAAS;AAAA,EACT,WAAW;AAAA,EACX,QAAQ;AACV,GAEMC,IAA8C;AAAA,EAClD,MAAM;AAAA,EACN,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN,GAEMC,IAAgD;AAAA,EACpD,MAAM;AAAA,EACN,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,MAAM;AACR,GAEaC,IAAgC,CAAC;AAAA,EAC5C,UAAAC;AAAA,EACA,OAAAC;AAAA,EACA,QAAAC;AAAA,EACA,KAAAC;AAAA,EACA,OAAAC,IAAQ;AAAA,EACR,QAAAC,IAAS;AAAA,EACT,QAAAC,IAAS;AAAA,EACT,SAAAC,IAAU;AAAA,EACV,WAAAC,IAAY;AAAA,EACZ,GAAGC;AACL,MAAM;AACJ,QAAMC,IAAgB;AAAA,IACpB;AAAA,IACAd,EAAaQ,CAAK;AAAA,IAClBC,KAAU;AAAA,IACVR,EAAcS,CAAM;AAAA,IACpBR,EAAeS,CAAO;AAAA,IACtBC;AAAA,EAAA,EAEC,OAAO,OAAO,EACd,KAAK,GAAG;AAEX,SAAIR,sBACM,OAAA,EAAI,WAAWU,GAAgB,GAAGD,GAAO,UAAAT,GAAS,IAI1D,gBAAAW,EAAC,OAAA,EAAI,WAAWD,GAAgB,GAAGD,GAChC,UAAA;AAAA,IAAAR,KAAS,gBAAAW,EAAC,OAAA,EAAI,WAAU,gBAAgB,UAAAX,GAAM;AAAA,IAC9CC,KAAU,gBAAAU,EAAC,OAAA,EAAI,WAAU,iBAAiB,UAAAV,GAAO;AAAA,IACjDC,KAAO,gBAAAS,EAAC,OAAA,EAAI,WAAU,cAAc,UAAAT,EAAA,CAAI;AAAA,EAAA,GAC3C;AAEJ;"}
1
+ {"version":3,"file":"index59.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,YAAwB,CAAA;AAAA,EACxB,YAAmC;AAAA,EACnC,OAA6B;AAAA,EAC7B,YAAY;AAAA,EAEpB,UAAUC,GAAoB;AAC5B,gBAAK,UAAU,KAAKA,CAAQ,GACrB,MAAM;AACX,WAAK,YAAY,KAAK,UAAU,OAAO,CAACC,MAAMA,MAAMD,CAAQ;AAAA,IAC9D;AAAA,EACF;AAAA,EAEA,mBAAmB;AACjB,WAAO,KAAK;AAAA,EACd;AAAA,EAEQ,OAAO;AACb,SAAK,UAAU,QAAQ,CAACA,MAAaA,GAAU;AAAA,EACjD;AAAA,EAEQ,kBAAkB;AACxB,IAAK,KAAK,cACR,KAAK,YAAY,SAAS,cAAc,KAAK,GAC7C,SAAS,KAAK,YAAY,KAAK,SAAS,GACxC,KAAK,OAAOE,EAAS,WAAW,KAAK,SAAS,GAC9C,KAAK,KAAK,OAAO,gBAAAC,EAACC,GAAA,EAAsB,SAAS,MAAM,CAAE;AAAA,EAE7D;AAAA,EAEA,KAAKC,GAA4B;AAC/B,SAAK,gBAAA;AAEL,UAAMC,IAAK,gBAAgB,EAAE,KAAK,SAAS,IACrCC,IAAiC;AAAA,MACrC,GAAGF;AAAA,MACH,IAAAC;AAAA,MACA,WAAW,KAAK,IAAA;AAAA,MAChB,UAAUD,EAAO,YAAY;AAAA,MAC7B,WAAWA,EAAO,aAAa;AAAA,MAC/B,UAAUA,EAAO,YAAY;AA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AAW,UAAAI,EAAa,YAAA,CAAY;AAAA,QAAA,GAClF;AAAA,QACCA,EAAa,YACZ,gBAAAJ;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,WAAU;AAAA,YACV,SAAS,CAACqB,MAAM;AACd,cAAAA,EAAE,gBAAA,GACFJ,EAAA;AAAA,YACF;AAAA,YACD,UAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MAED;AAAA,IAAA;AAAA,EAAA;AAIR;AAEO,MAAMb,IAAe,IAAIR,EAAA;"}
package/dist/index60.js CHANGED
@@ -1,125 +1,113 @@
1
- import { jsx as i, Fragment as h, jsxs as l } from "react/jsx-runtime";
2
- import { useState as u, useEffect as p } from "react";
3
- import d from "react-dom/client";
4
- class m {
5
- notifications = [];
6
- listeners = [];
7
- container = null;
8
- root = null;
9
- idCounter = 0;
10
- subscribe(t) {
11
- return this.listeners.push(t), () => {
12
- this.listeners = this.listeners.filter((o) => o !== t);
1
+ import { jsx as v } from "react/jsx-runtime";
2
+ import { forwardRef as L, useState as M, useRef as V, useImperativeHandle as Z, useEffect as j, useCallback as i } from "react";
3
+ const g = L(
4
+ ({
5
+ length: s = 6,
6
+ value: p = "",
7
+ onChange: n,
8
+ onComplete: m,
9
+ size: k = "md",
10
+ type: f = "number",
11
+ mask: y = !1,
12
+ disabled: c = !1,
13
+ error: P = !1,
14
+ autoFocus: A = !1,
15
+ placeholder: b = "",
16
+ className: I = ""
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"
13
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
+ )) });
14
107
  }
15
- getNotifications() {
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"
34
- };
35
- return this.notifications.push(s), this.emit(), s.duration && s.duration > 0 && setTimeout(() => {
36
- this.close(o);
37
- }, s.duration * 1e3), o;
38
- }
39
- close(t) {
40
- const o = this.notifications.find((s) => s.id === t);
41
- this.notifications = this.notifications.filter((s) => s.id !== t), this.emit(), o?.onClose && o.onClose();
42
- }
43
- success(t) {
44
- return this.open({ ...t, type: "success" });
45
- }
46
- error(t) {
47
- return this.open({ ...t, type: "error" });
48
- }
49
- info(t) {
50
- return this.open({ ...t, type: "info" });
51
- }
52
- warning(t) {
53
- return this.open({ ...t, type: "warning" });
54
- }
55
- destroy() {
56
- this.notifications = [], this.emit();
57
- }
58
- }
59
- function f({ manager: e }) {
60
- const [, t] = u({});
61
- p(() => e.subscribe(() => {
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",
99
- {
100
- className: `alert ${o[e.type]} shadow-lg cursor-pointer min-w-[300px] max-w-[400px]`,
101
- onClick: s,
102
- children: [
103
- /* @__PURE__ */ l("div", { className: "flex-1", children: [
104
- e.message && /* @__PURE__ */ i("div", { className: "font-bold", children: e.message }),
105
- e.description && /* @__PURE__ */ i("div", { className: "text-sm", children: e.description })
106
- ] }),
107
- e.closable && /* @__PURE__ */ i(
108
- "button",
109
- {
110
- className: "btn btn-sm btn-ghost btn-circle",
111
- onClick: (r) => {
112
- r.stopPropagation(), t();
113
- },
114
- children: "✕"
115
- }
116
- )
117
- ]
118
- }
119
- );
120
- }
121
- const y = new m();
108
+ );
109
+ g.displayName = "OTPInput";
122
110
  export {
123
- y as notification
111
+ g as OTPInput
124
112
  };
125
113
  //# sourceMappingURL=index60.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index60.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,YAAwB,CAAA;AAAA,EACxB,YAAmC;AAAA,EACnC,OAA6B;AAAA,EAC7B,YAAY;AAAA,EAEpB,UAAUC,GAAoB;AAC5B,gBAAK,UAAU,KAAKA,CAAQ,GACrB,MAAM;AACX,WAAK,YAAY,KAAK,UAAU,OAAO,CAACC,MAAMA,MAAMD,CAAQ;AAAA,IAC9D;AAAA,EACF;AAAA,EAEA,mBAAmB;AACjB,WAAO,KAAK;AAAA,EACd;AAAA,EAEQ,OAAO;AACb,SAAK,UAAU,QAAQ,CAACA,MAAaA,GAAU;AAAA,EACjD;AAAA,EAEQ,kBAAkB;AACxB,IAAK,KAAK,cACR,KAAK,YAAY,SAAS,cAAc,KAAK,GAC7C,SAAS,KAAK,YAAY,KAAK,SAAS,GACxC,KAAK,OAAOE,EAAS,WAAW,KAAK,SAAS,GAC9C,KAAK,KAAK,OAAO,gBAAAC,EAACC,GAAA,EAAsB,SAAS,MAAM,CAAE;AAAA,EAE7D;AAAA,EAEA,KAAKC,GAA4B;AAC/B,SAAK,gBAAA;AAEL,UAAMC,IAAK,gBAAgB,EAAE,KAAK,SAAS,IACrCC,IAAiC;AAAA,MACrC,GAAGF;AAAA,MACH,IAAAC;AAAA,MACA,WAAW,KAAK,IAAA;AAAA,MAChB,UAAUD,EAAO,YAAY;AAAA,MAC7B,WAAWA,EAAO,aAAa;AAAA,MA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,EAAC,OAAA,EAAI,WAAU,WAAW,UAAAI,EAAa,YAAA,CAAY;AAAA,QAAA,GAClF;AAAA,QACCA,EAAa,YACZ,gBAAAJ;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,WAAU;AAAA,YACV,SAAS,CAACqB,MAAM;AACd,cAAAA,EAAE,gBAAA,GACFJ,EAAA;AAAA,YACF;AAAA,YACD,UAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MAED;AAAA,IAAA;AAAA,EAAA;AAIR;AAEO,MAAMb,IAAe,IAAIR,EAAA;"}
1
+ {"version":3,"file":"index60.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"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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;"}
package/dist/index61.js CHANGED
@@ -1,113 +1,173 @@
1
- import { jsx as v } from "react/jsx-runtime";
2
- import { forwardRef as L, useState as M, useRef as V, useImperativeHandle as Z, useEffect as j, useCallback as i } from "react";
3
- const g = L(
4
- ({
5
- length: s = 6,
6
- value: p = "",
7
- onChange: n,
8
- onComplete: m,
9
- size: k = "md",
10
- type: f = "number",
11
- mask: y = !1,
12
- disabled: c = !1,
13
- error: P = !1,
14
- autoFocus: A = !1,
15
- placeholder: b = "",
16
- className: I = ""
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();
1
+ import { jsxs as o, jsx as i } from "react/jsx-runtime";
2
+ import f from "react";
3
+ const q = ({
4
+ current: p,
5
+ defaultCurrent: P = 1,
6
+ total: m,
7
+ pageSize: h,
8
+ defaultPageSize: C = 10,
9
+ pageSizeOptions: j = [10, 20, 50, 100],
10
+ onChange: g,
11
+ onShowSizeChange: k,
12
+ showSizeChanger: y = !1,
13
+ showQuickJumper: S = !1,
14
+ showTotal: d = !1,
15
+ simple: I = !1,
16
+ size: M = "md",
17
+ disabled: a = !1,
18
+ className: b = "",
19
+ ...N
20
+ }) => {
21
+ const [w, v] = f.useState(P), [J, D] = f.useState(C), [x, $] = f.useState(""), t = p !== void 0 ? p : w, u = h !== void 0 ? h : J, n = Math.ceil(m / u), r = (e) => {
22
+ e < 1 || e > n || a || (p === void 0 && v(e), g?.(e, u));
23
+ }, E = (e) => {
24
+ const c = Math.ceil(m / e), s = t > c ? c : t;
25
+ h === void 0 && D(e), p === void 0 && s !== t && v(s), k?.(s, e), g?.(s, e);
26
+ }, F = (e) => {
27
+ if (e.key === "Enter") {
28
+ const c = parseInt(x);
29
+ !isNaN(c) && c >= 1 && c <= n && (r(c), $(""));
30
+ }
31
+ }, G = () => {
32
+ const e = [];
33
+ if (n <= 7)
34
+ for (let s = 1; s <= n; s++)
35
+ e.push(s);
36
+ else if (t <= 3) {
37
+ for (let s = 1; s <= 5; s++)
38
+ e.push(s);
39
+ e.push("ellipsis"), e.push(n);
40
+ } else if (t >= n - 2) {
41
+ e.push(1), e.push("ellipsis");
42
+ for (let s = n - 4; s <= n; s++)
43
+ e.push(s);
44
+ } else {
45
+ e.push(1), e.push("ellipsis");
46
+ for (let s = t - 1; s <= t + 1; s++)
47
+ e.push(s);
48
+ e.push("ellipsis"), e.push(n);
49
+ }
50
+ return e;
51
+ }, l = {
52
+ xs: "btn-xs",
53
+ sm: "btn-sm",
54
+ md: "",
55
+ lg: "btn-lg"
56
+ }[M], K = [
57
+ (t - 1) * u + 1,
58
+ Math.min(t * u, m)
59
+ ];
60
+ return I ? /* @__PURE__ */ o("div", { className: `flex items-center gap-2 ${b}`, ...N, children: [
61
+ /* @__PURE__ */ i(
62
+ "button",
63
+ {
64
+ className: `btn btn-ghost ${l}`,
65
+ onClick: () => r(t - 1),
66
+ disabled: a || t === 1,
67
+ children: "‹"
34
68
  }
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",
69
+ ),
70
+ /* @__PURE__ */ o("span", { className: "text-sm", children: [
71
+ t,
72
+ " / ",
73
+ n
74
+ ] }),
75
+ /* @__PURE__ */ i(
76
+ "button",
77
+ {
78
+ className: `btn btn-ghost ${l}`,
79
+ onClick: () => r(t + 1),
80
+ disabled: a || t === n,
81
+ children: "›"
82
+ }
83
+ )
84
+ ] }) : /* @__PURE__ */ o("div", { className: `flex flex-wrap items-center gap-4 ${b}`, ...N, children: [
85
+ d && /* @__PURE__ */ i("div", { className: "text-sm text-base-content/70", children: typeof d == "function" ? d(m, K) : `Total ${m} items` }),
86
+ y && /* @__PURE__ */ i(
87
+ "select",
83
88
  {
84
- ref: (r) => {
85
- u.current[e] = r;
89
+ className: `select select-bordered ${l}`,
90
+ value: u,
91
+ onChange: (e) => E(Number(e.target.value)),
92
+ disabled: a,
93
+ children: j.map((e) => /* @__PURE__ */ o("option", { value: e, children: [
94
+ e,
95
+ " / page"
96
+ ] }, e))
97
+ }
98
+ ),
99
+ /* @__PURE__ */ o("div", { className: "join", children: [
100
+ /* @__PURE__ */ i(
101
+ "button",
102
+ {
103
+ className: `join-item btn ${l}`,
104
+ onClick: () => r(1),
105
+ disabled: a || t === 1,
106
+ title: "First page",
107
+ children: "«"
108
+ }
109
+ ),
110
+ /* @__PURE__ */ i(
111
+ "button",
112
+ {
113
+ className: `join-item btn ${l}`,
114
+ onClick: () => r(t - 1),
115
+ disabled: a || t === 1,
116
+ title: "Previous page",
117
+ children: "‹"
118
+ }
119
+ ),
120
+ G().map((e, c) => e === "ellipsis" ? /* @__PURE__ */ i("button", { className: `join-item btn btn-disabled ${l}`, children: "..." }, `ellipsis-${c}`) : /* @__PURE__ */ i(
121
+ "button",
122
+ {
123
+ className: `join-item btn ${l} ${t === e ? "btn-active" : ""}`,
124
+ onClick: () => r(e),
125
+ disabled: a,
126
+ children: e
86
127
  },
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";
128
+ e
129
+ )),
130
+ /* @__PURE__ */ i(
131
+ "button",
132
+ {
133
+ className: `join-item btn ${l}`,
134
+ onClick: () => r(t + 1),
135
+ disabled: a || t === n,
136
+ title: "Next page",
137
+ children: "›"
138
+ }
139
+ ),
140
+ /* @__PURE__ */ i(
141
+ "button",
142
+ {
143
+ className: `join-item btn ${l}`,
144
+ onClick: () => r(n),
145
+ disabled: a || t === n,
146
+ title: "Last page",
147
+ children: "»"
148
+ }
149
+ )
150
+ ] }),
151
+ S && /* @__PURE__ */ o("div", { className: "flex items-center gap-2", children: [
152
+ /* @__PURE__ */ i("span", { className: "text-sm", children: "Go to" }),
153
+ /* @__PURE__ */ i(
154
+ "input",
155
+ {
156
+ type: "number",
157
+ className: `input input-bordered w-16 ${l}`,
158
+ min: 1,
159
+ max: n,
160
+ value: x,
161
+ onChange: (e) => $(e.target.value),
162
+ onKeyDown: F,
163
+ disabled: a,
164
+ placeholder: String(t)
165
+ }
166
+ )
167
+ ] })
168
+ ] });
169
+ };
110
170
  export {
111
- g as OTPInput
171
+ q as Pagination
112
172
  };
113
173
  //# sourceMappingURL=index61.js.map