@mpen/react-basic-inputs 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
File without changes
@@ -1,23 +1,22 @@
1
1
  import { ComponentPropsWithoutRef } from 'react';
2
- import { DetailedHTMLProps } from 'react';
2
+ import { ComponentPropsWithRef } from 'react';
3
3
  import { ElementType } from 'react';
4
4
  import { FC } from 'react';
5
- import { ForwardRefExoticComponent } from 'react';
6
- import { InputHTMLAttributes } from 'react';
7
- import { JSX as JSX_2 } from 'react/jsx-runtime';
5
+ import { JSX } from 'react/jsx-runtime';
8
6
  import { Key } from 'react';
9
7
  import { ReactNode } from 'react';
10
- import { RefAttributes } from 'react';
11
- import { TextareaHTMLAttributes } from 'react';
8
+ import { Ref } from 'react';
12
9
 
13
- export declare function ActionButton({ onClick, ...props }: ActionButtonProps): JSX_2.Element;
10
+ export declare function ActionButton({ onClick, ...props }: ActionButtonProps): JSX.Element;
14
11
 
15
12
  export declare type ActionButtonProps = RequiredKeys<ComponentPropsWithoutRef<'button'>, 'onClick'>;
16
13
 
17
- export declare function DatetimeLocalInput({ value, defaultValue, min, max, onChange, ...props }: DatetimeLocalInputProps): JSX_2.Element;
14
+ export declare function DatetimeLocalInput({ value, defaultValue, min, max, onChange, ...props }: DatetimeLocalInputProps): JSX.Element;
18
15
 
19
16
  export declare type DatetimeLocalInputChangeEvent = {
20
17
  value: string;
18
+ date: Date | null;
19
+ isoString: string;
21
20
  };
22
21
 
23
22
  export declare type DatetimeLocalInputProps = OverrideProps<'input', {
@@ -28,7 +27,7 @@ export declare type DatetimeLocalInputProps = OverrideProps<'input', {
28
27
  onChange?: (ev: DatetimeLocalInputChangeEvent) => void;
29
28
  }, 'type'>;
30
29
 
31
- export declare function DatetimeOffsetInput({ value, defaultValue, min, max, onChange, ...props }: DatetimeOffsetInputProps): JSX_2.Element;
30
+ export declare function DatetimeOffsetInput({ value, defaultValue, min, max, onChange, ...props }: DatetimeOffsetInputProps): JSX.Element;
32
31
 
33
32
  export declare type DatetimeOffsetInputChangeEvent = {
34
33
  value: string;
@@ -72,14 +71,7 @@ declare type HtmlSelectElement = HTMLElementTagNameMap['select'];
72
71
  /** Hack to de-conflict React's HTMLInputElement vs the standard dom lib */
73
72
  declare type HtmlTextAreaElement = HTMLElementTagNameMap['textarea'];
74
73
 
75
- export declare const Input: ForwardRefExoticComponent<Omit<Omit<DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref">, "value" | "onChange" | "formatOnChange"> & {
76
- onChange?: InputChangeEventHandler | undefined;
77
- value?: string | undefined;
78
- /**
79
- * Function used to format value on blur.
80
- */
81
- formatOnChange?: ((value: string) => string) | undefined;
82
- } & RefAttributes<HTMLInputElement>>;
74
+ export declare function Input({ value: initialValue, onPaste, onChange, onInput, onBlur, formatOnChange, ref, ...otherProps }: InputProps): JSX.Element;
83
75
 
84
76
  export declare type InputChangeEvent = {
85
77
  value: string;
@@ -93,6 +85,7 @@ export declare type InputChangeEventHandler = EventCallback<InputChangeEvent>;
93
85
  export declare type InputProps = OverrideProps<'input', {
94
86
  onChange?: InputChangeEventHandler;
95
87
  value?: string;
88
+ ref?: ComponentPropsWithRef<'input'>['ref'];
96
89
  /**
97
90
  * Function used to format value on blur.
98
91
  */
@@ -115,27 +108,20 @@ export declare type NumberChangeEvent = {
115
108
 
116
109
  export declare type NumberChangeEventHandler = EventCallback<NumberChangeEvent>;
117
110
 
118
- export declare const NumberInput: ForwardRefExoticComponent<Omit<Omit<Omit<Omit<DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref">, "value" | "onChange" | "formatOnChange"> & {
119
- onChange?: InputChangeEventHandler | undefined;
120
- value?: string | undefined;
121
- formatOnChange?: ((value: string) => string) | undefined;
122
- } & RefAttributes<HTMLInputElement>, "ref">, "value" | "onChange" | "placeholder" | "type"> & {
123
- value?: number | undefined;
124
- placeholder?: string | number | undefined;
125
- onChange?: NumberChangeEventHandler | undefined;
126
- } & RefAttributes<HTMLInputElement>>;
111
+ export declare function NumberInput({ placeholder, formatOnChange, onChange, value, ref, ...otherProps }: NumberInputProps): JSX.Element;
127
112
 
128
113
  export declare type NumberInputProps = OverrideProps<typeof Input, {
129
114
  value?: number;
130
115
  placeholder?: string | number;
131
116
  onChange?: NumberChangeEventHandler;
117
+ ref?: ComponentPropsWithRef<typeof Input>['ref'];
132
118
  }, 'type'>;
133
119
 
134
120
  declare type Override<Base, Extension, DeleteKeys extends PropertyKey = never> = Omit<Base, keyof Extension | DeleteKeys> & Extension;
135
121
 
136
122
  declare type OverrideProps<Base extends ElementType, Extension, DeleteKeys extends PropertyKey = never> = Override<ComponentPropsWithoutRef<Base>, Extension, DeleteKeys>;
137
123
 
138
- export declare function RadioMenu<T extends NonNil>(menu: RadioMenuProps<T>): JSX_2.Element;
124
+ export declare function RadioMenu<T extends NonNil>(menu: RadioMenuProps<T>): JSX.Element;
139
125
 
140
126
  export declare type RadioMenuChangeEvent<T> = {
141
127
  value: T;
@@ -173,7 +159,7 @@ declare type RequiredKeys<Type, Key extends keyof Type> = Omit<Type, Key> & Requ
173
159
 
174
160
  declare type Resolvable<TValue = unknown, TArgs extends ReadonlyArray<unknown> = []> = TValue extends any ? TValue | ((...args: TArgs) => TValue) : never;
175
161
 
176
- export declare function Select<T extends NonNil>({ options, value, invalidValueOption, onChange, placeholder, ...selectAttrs }: SelectProps<T>): JSX_2.Element;
162
+ export declare function Select<T extends NonNil>({ options, value, invalidValueOption, onChange, placeholder, ...selectAttrs }: SelectProps<T>): JSX.Element;
177
163
 
178
164
  export declare interface SelectChangeEvent<T> {
179
165
  value: T;
@@ -207,14 +193,12 @@ export declare type SelectProps<T extends NonNil> = OverrideProps<'select', {
207
193
  placeholder?: ReactNode;
208
194
  }, 'children' | 'defaultValue'>;
209
195
 
210
- export declare const TextArea: ForwardRefExoticComponent<Omit<Omit<DetailedHTMLProps<TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>, "ref">, "initialHeight"> & {
211
- /** Initial/minimum height. "0" or "auto" are good choices. Defaults to "auto" */
212
- initialHeight?: string | undefined;
213
- } & RefAttributes<TextAreaRef>>;
196
+ export declare function TextArea({ onInput, style, initialHeight, ref: fwdRef, ...rest }: TextAreaProps): JSX.Element;
214
197
 
215
198
  export declare type TextAreaProps = OverrideProps<'textarea', {
216
199
  /** Initial/minimum height. "0" or "auto" are good choices. Defaults to "auto" */
217
200
  initialHeight?: string;
201
+ ref?: Ref<TextAreaRef>;
218
202
  }>;
219
203
 
220
204
  export declare type TextAreaRef = {
@@ -222,7 +206,7 @@ export declare type TextAreaRef = {
222
206
  adjustHeight: VoidFn;
223
207
  };
224
208
 
225
- export declare function TextInput({ formatOnChange, ...otherProps }: TextInputProps): JSX_2.Element;
209
+ export declare function TextInput({ formatOnChange, ...otherProps }: TextInputProps): JSX.Element;
226
210
 
227
211
  export declare type TextInputProps = Omit<InputProps, 'text'>;
228
212
 
@@ -1,38 +1,38 @@
1
- var z = Object.defineProperty;
2
- var q = (e, t, n) => t in e ? z(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var P = (e, t, n) => (q(e, typeof t != "symbol" ? t + "" : t, n), n);
4
- import { jsx as v, jsxs as L } from "react/jsx-runtime";
5
- import { useDebugValue as G, useRef as h, useInsertionEffect as Z, useEffect as C, useMemo as F, useCallback as T, createElement as W, forwardRef as k, useState as D, useImperativeHandle as B, useLayoutEffect as J, useId as X } from "react";
6
- const Q = Object.freeze(() => {
1
+ var j = Object.defineProperty;
2
+ var z = (e, t, n) => t in e ? j(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var C = (e, t, n) => (z(e, typeof t != "symbol" ? t + "" : t, n), n);
4
+ import { jsx as v, jsxs as R } from "react/jsx-runtime";
5
+ import { useDebugValue as q, useRef as b, useInsertionEffect as G, useEffect as k, useMemo as P, useCallback as T, createElement as Z, useState as O, useImperativeHandle as W, useLayoutEffect as B, useId as J } from "react";
6
+ const X = Object.freeze(() => {
7
7
  });
8
- function ee(e) {
8
+ function Q(e) {
9
9
  return e;
10
10
  }
11
- let _;
12
- typeof window < "u" ? _ = (e) => {
13
- G(e);
14
- const t = h(ne);
15
- Z(() => {
11
+ let p;
12
+ typeof window < "u" ? p = (e) => {
13
+ q(e);
14
+ const t = b(te);
15
+ G(() => {
16
16
  t.current = e;
17
17
  }, [e]);
18
- const n = h(null);
18
+ const n = b(null);
19
19
  return n.current || (n.current = function() {
20
20
  return t.current.apply(this, arguments);
21
21
  }), n.current;
22
- } : _ = Q;
23
- function te(e) {
24
- return _(e);
22
+ } : p = X;
23
+ function ee(e) {
24
+ return p(e);
25
25
  }
26
- function ne() {
26
+ function te() {
27
27
  throw new Error("INVALID_USE_EVENT_INVOCATION: the callback from useEvent cannot be invoked before the component has mounted.");
28
28
  }
29
- function re() {
30
- var e = h(!0);
29
+ function ne() {
30
+ var e = b(!0);
31
31
  return e.current ? (e.current = !1, !0) : e.current;
32
32
  }
33
- var R = function(e, t) {
34
- var n = re();
35
- C(function() {
33
+ var U = function(e, t) {
34
+ var n = ne();
35
+ k(function() {
36
36
  if (!n)
37
37
  return e();
38
38
  }, t);
@@ -40,7 +40,7 @@ var R = function(e, t) {
40
40
  function ue(e, ...t) {
41
41
  return typeof e == "function" ? e(...t) : e;
42
42
  }
43
- function se(e, t) {
43
+ function re(e, t) {
44
44
  if (e.uniqueKey != null)
45
45
  return ue(e.uniqueKey, e, t);
46
46
  if (typeof e.value == "string")
@@ -55,101 +55,101 @@ function se(e, t) {
55
55
  }
56
56
  return String(t);
57
57
  }
58
- class H {
58
+ class L {
59
59
  constructor() {
60
- P(this, "_usedKeys", /* @__PURE__ */ new Map());
60
+ C(this, "_usedKeys", /* @__PURE__ */ new Map());
61
61
  }
62
62
  fix(t, n) {
63
- let r = se(t, n);
63
+ let u = re(t, n);
64
64
  for (; ; ) {
65
- let u = this._usedKeys.get(r);
66
- if (u === void 0) {
67
- this._usedKeys.set(r, 1);
65
+ let r = this._usedKeys.get(u);
66
+ if (r === void 0) {
67
+ this._usedKeys.set(u, 1);
68
68
  break;
69
69
  }
70
- this._usedKeys.set(r, ++u), r = `${r}(${u})`;
70
+ this._usedKeys.set(u, ++r), u = `${u}(${r})`;
71
71
  }
72
- return r;
72
+ return u;
73
73
  }
74
74
  }
75
- const ce = (e) => ({
75
+ const se = (e) => ({
76
76
  value: e,
77
77
  text: String(e),
78
78
  disabled: !0,
79
- key: ae
80
- }), le = "3c9369b7-0a5e-46ea-93c2-e8b9fec67fdb", ae = "1a53f789-77f5-4ce6-a829-b00e563f1ee8";
81
- function ie({
79
+ key: le
80
+ }), ce = "3c9369b7-0a5e-46ea-93c2-e8b9fec67fdb", le = "1a53f789-77f5-4ce6-a829-b00e563f1ee8";
81
+ function ae({
82
82
  options: e,
83
83
  value: t,
84
- invalidValueOption: n = ce,
85
- onChange: r,
86
- placeholder: u,
84
+ invalidValueOption: n = se,
85
+ onChange: u,
86
+ placeholder: r,
87
87
  ...s
88
88
  }) {
89
- const i = t == null, f = F(() => t != null && e.some((c) => c.value == t), [e, t]), o = F(() => t == null || !n ? null : n(t), [n, t]), l = F(() => {
89
+ const i = t == null, f = P(() => t != null && e.some((m) => m.value == t), [e, t]), c = P(() => t == null || !n ? null : n(t), [n, t]), o = P(() => {
90
90
  if (f)
91
91
  return e;
92
- const c = [...e];
93
- return i ? u != null && c.unshift({ text: u, hidden: !0, value: null, key: le }) : o && c.push(o), c;
94
- }, [f, e, i, o, u]), d = te((c) => {
95
- const g = c.target.selectedIndex, O = l[g];
96
- r == null || r({
97
- value: O.value,
92
+ const m = [...e];
93
+ return i ? r != null && m.unshift({ text: r, hidden: !0, value: null, key: ce }) : c && m.push(c), m;
94
+ }, [f, e, i, c, r]), l = ee((m) => {
95
+ const h = m.target.selectedIndex, S = o[h];
96
+ u == null || u({
97
+ value: S.value,
98
98
  // option: opt,
99
99
  // event: ev,
100
- index: g,
100
+ index: h,
101
101
  type: "change",
102
- timeStamp: c.timeStamp,
103
- target: c.target
102
+ timeStamp: m.timeStamp,
103
+ target: m.target
104
104
  });
105
- }), a = h(null), x = T(() => {
106
- a.current && (a.current.selectedIndex < 0 || l[a.current.selectedIndex].value != t) && (a.current.selectedIndex = l.findIndex((c) => c.value == t));
107
- }, [l, t]), N = (c) => {
108
- a.current = c, x();
105
+ }), d = b(null), x = T(() => {
106
+ d.current && (d.current.selectedIndex < 0 || o[d.current.selectedIndex].value != t) && (d.current.selectedIndex = o.findIndex((m) => m.value == t));
107
+ }, [o, t]), a = (m) => {
108
+ d.current = m, x();
109
109
  };
110
- R(() => {
110
+ U(() => {
111
111
  x();
112
112
  }, [x]);
113
- const m = new H();
114
- return /* @__PURE__ */ v("select", { ...s, onChange: d, ref: N, children: l.map((c, g) => {
115
- const { value: O, text: b, uniqueKey: S, ...y } = c, V = m.fix(c, g);
116
- return /* @__PURE__ */ W("option", { ...y, key: V, value: V }, c.text);
113
+ const N = new L();
114
+ return /* @__PURE__ */ v("select", { ...s, onChange: l, ref: a, children: o.map((m, h) => {
115
+ const { value: S, text: K, uniqueKey: A, ...g } = m, I = N.fix(m, h);
116
+ return /* @__PURE__ */ Z("option", { ...g, key: I, value: I }, m.text);
117
117
  }) });
118
118
  }
119
- function fe(e) {
119
+ function ie(e) {
120
120
  return e ? String(e).replace(/\s+/gu, " ").trim() : "";
121
121
  }
122
- function oe(e) {
122
+ function fe(e) {
123
123
  try {
124
124
  return e.toLocaleString("en-US", { useGrouping: !1, maximumFractionDigits: 20 });
125
125
  } catch {
126
126
  return e.toFixed(14).replace(/\.?0+$/, "");
127
127
  }
128
128
  }
129
- function de(e) {
129
+ function oe(e) {
130
130
  return e ? e === "∞" || e === "+∞" ? Number.POSITIVE_INFINITY : e === "-∞" ? Number.NEGATIVE_INFINITY : Number.parseFloat(e) : Number.NaN;
131
131
  }
132
- function Y(e) {
133
- return Number.isNaN(e) ? "" : e === Number.POSITIVE_INFINITY ? "∞" : e === Number.NEGATIVE_INFINITY ? "-∞" : oe(e);
132
+ function H(e) {
133
+ return Number.isNaN(e) ? "" : e === Number.POSITIVE_INFINITY ? "∞" : e === Number.NEGATIVE_INFINITY ? "-∞" : fe(e);
134
134
  }
135
- function xe(e) {
136
- return e ? Y(Number.parseFloat(e)) : "";
135
+ function de(e) {
136
+ return e ? H(Number.parseFloat(e)) : "";
137
137
  }
138
- function I(e, t = 2) {
138
+ function y(e, t = 2) {
139
139
  return String(e).padStart(t, "0");
140
140
  }
141
- const j = k(function({ value: t = "", onPaste: n, onChange: r, onInput: u, onBlur: s, formatOnChange: i = ee, ...f }, o) {
142
- const [l, d] = D(t), a = h(t), x = h(!1);
143
- R(() => {
144
- d(t), x.current = !1, a.current = t;
145
- }, [t]);
146
- const N = {
141
+ function Y({ value: e = "", onPaste: t, onChange: n, onInput: u, onBlur: r, formatOnChange: s = Q, ref: i, ...f }) {
142
+ const [c, o] = O(e), l = b(e), d = b(!1);
143
+ U(() => {
144
+ o(e), d.current = !1, l.current = e;
145
+ }, [e]);
146
+ const x = {
147
147
  type: "text",
148
148
  ...f,
149
- ref: o,
150
- value: l,
151
- onChange: (m) => {
152
- d(m.target.value);
149
+ ref: i,
150
+ value: c,
151
+ onChange: (a) => {
152
+ o(a.target.value);
153
153
  },
154
154
  // TODO: fire a change event onPaste ?
155
155
  // formatOnPaste?
@@ -167,157 +167,159 @@ const j = k(function({ value: t = "", onPaste: n, onChange: r, onInput: u, onBlu
167
167
  // // ev.preventDefault()
168
168
  // // setCurrentValue(formatOnChange(ev.clipboardData.getData('text/plain')))
169
169
  // },
170
- onInput: (m) => {
171
- x.current = !0, u == null || u(m);
170
+ onInput: (a) => {
171
+ d.current = !0, u == null || u(a);
172
172
  },
173
- onBlur: (m) => {
174
- const c = i(l);
175
- x.current && (c !== a.current && (r == null || r({
173
+ onBlur: (a) => {
174
+ const N = s(c);
175
+ d.current && (N !== l.current && (n == null || n({
176
176
  type: "change",
177
- value: c,
178
- timeStamp: m.timeStamp,
179
- target: m.target
180
- }), a.current = c), c !== m.target.value && d(c)), s == null || s(m);
177
+ value: N,
178
+ timeStamp: a.timeStamp,
179
+ target: a.target
180
+ }), l.current = N), N !== a.target.value && o(N)), r == null || r(a);
181
181
  }
182
182
  };
183
- return /* @__PURE__ */ v("input", { ...N });
184
- });
185
- function Oe({ formatOnChange: e = fe, ...t }) {
186
- return /* @__PURE__ */ v(j, { formatOnChange: e, ...t, type: "text" });
183
+ return /* @__PURE__ */ v("input", { ...x });
187
184
  }
188
- const Se = k(function({
189
- onInput: t,
190
- style: n,
191
- initialHeight: r = "auto",
192
- ...u
193
- }, s) {
194
- const i = h(null), [f, o] = D(r), l = T(() => {
195
- const a = i.current;
196
- if (!a)
185
+ function Oe({ formatOnChange: e = ie, ...t }) {
186
+ return /* @__PURE__ */ v(Y, { formatOnChange: e, ...t, type: "text" });
187
+ }
188
+ function Ee({
189
+ onInput: e,
190
+ style: t,
191
+ initialHeight: n = "auto",
192
+ ref: u,
193
+ ...r
194
+ }) {
195
+ const s = b(null), [i, f] = O(n), c = T(() => {
196
+ const l = s.current;
197
+ if (!l)
197
198
  return;
198
- a.style.height = r;
199
- const x = `${a.scrollHeight}px`;
200
- o(x), a.style.height = x;
201
- }, [r]);
202
- B(s, () => ({
203
- element: i.current,
204
- adjustHeight: l
205
- }), [l]);
206
- const d = _((a) => {
207
- l(), t == null || t(a);
199
+ l.style.height = n;
200
+ const d = `${l.scrollHeight}px`;
201
+ f(d), l.style.height = d;
202
+ }, [n]);
203
+ W(u, () => ({
204
+ element: s.current,
205
+ adjustHeight: c
206
+ }), [c]);
207
+ const o = p((l) => {
208
+ c(), e == null || e(l);
208
209
  });
209
- return J(() => {
210
- l();
211
- const a = i.current;
212
- if (!a)
210
+ return B(() => {
211
+ c();
212
+ const l = s.current;
213
+ if (!l)
213
214
  return;
214
- const x = new ResizeObserver((N) => {
215
- l();
215
+ const d = new ResizeObserver((x) => {
216
+ c();
216
217
  });
217
- return x.observe(a), () => {
218
- x.unobserve(a);
218
+ return d.observe(l), () => {
219
+ d.unobserve(l);
219
220
  };
220
- }, [l]), /* @__PURE__ */ v("textarea", { ...u, style: {
221
+ }, [c]), /* @__PURE__ */ v("textarea", { ...r, style: {
221
222
  overflow: "hidden",
222
223
  // these 2 styles aren't needed if the caller sets them in CSS.
223
224
  resize: "none",
224
- ...n,
225
- height: f
226
- }, onInput: d, ref: i });
227
- });
228
- function Ee(e) {
229
- const t = X(), n = e.name ?? t, r = e.valueEquals ?? Object.is, u = e.options ?? [], s = new H(), i = _((f) => {
230
- const o = Number(f.target.value), l = u[o];
231
- l != null && e.onChange != null && e.onChange({
232
- value: l.value,
233
- index: o,
225
+ ...t,
226
+ height: i
227
+ }, onInput: o, ref: s });
228
+ }
229
+ function De(e) {
230
+ const t = J(), n = e.name ?? t, u = e.valueEquals ?? Object.is, r = e.options ?? [], s = new L(), i = p((f) => {
231
+ const c = Number(f.target.value), o = r[c];
232
+ o != null && e.onChange != null && e.onChange({
233
+ value: o.value,
234
+ index: c,
234
235
  type: "change",
235
236
  timeStamp: f.timeStamp,
236
237
  target: f.target
237
238
  });
238
239
  });
239
- return /* @__PURE__ */ v("ul", { className: e.className, children: u.map((f, o) => {
240
- const { value: l, text: d, key: a, itemClassName: x, labelClassName: N, inputClassName: m, textClassName: c, ...g } = f, O = s.fix(f, o);
241
- return e.value !== void 0 && (g.checked = r(l, e.value)), /* @__PURE__ */ v("li", { className: x, "aria-disabled": g.disabled, children: /* @__PURE__ */ L("label", { className: N, children: [
242
- /* @__PURE__ */ v("input", { ...g, className: m, value: o, onChange: i, name: n, type: "radio" }),
243
- /* @__PURE__ */ v("span", { className: c, children: d })
244
- ] }) }, O);
240
+ return /* @__PURE__ */ v("ul", { className: e.className, children: r.map((f, c) => {
241
+ const { value: o, text: l, key: d, itemClassName: x, labelClassName: a, inputClassName: N, textClassName: m, ...h } = f, S = s.fix(f, c);
242
+ return e.value !== void 0 && (h.checked = u(o, e.value)), /* @__PURE__ */ v("li", { className: x, "aria-disabled": h.disabled, children: /* @__PURE__ */ R("label", { className: a, children: [
243
+ /* @__PURE__ */ v("input", { ...h, className: N, value: c, onChange: i, name: n, type: "radio" }),
244
+ /* @__PURE__ */ v("span", { className: m, children: l })
245
+ ] }) }, S);
245
246
  }) });
246
247
  }
247
- function U() {
248
- return h(null);
249
- }
250
- function K(e) {
248
+ function V(e) {
251
249
  e.current != null && (clearTimeout(e.current), e.current = null);
252
250
  }
253
- const De = ({
251
+ const pe = ({
254
252
  value: e,
255
253
  onChange: t,
256
254
  debounce: n = 500,
257
- ...r
255
+ ...u
258
256
  }) => {
259
- const u = U(), s = U();
260
- R(() => {
261
- K(s), u.current != null && (u.current.value = e);
257
+ const r = b(null), [s, i] = O(e);
258
+ k(() => {
259
+ V(r), i(e);
262
260
  }, [e]);
263
- const i = () => {
264
- u.current != null && u.current.value !== e && (t == null || t({ value: u.current.value }));
261
+ const f = () => {
262
+ s !== e && (t == null || t({ value: s }));
265
263
  };
266
- return /* @__PURE__ */ v("input", { ...r, ref: u, defaultValue: e, onInput: () => {
267
- K(s), s.current = setTimeout(i, n);
264
+ return /* @__PURE__ */ v("input", { ...u, value: s, onChange: (c) => {
265
+ i(c.currentTarget.value), V(r), r.current = setTimeout(f, n);
268
266
  }, onBlur: () => {
269
- K(s), i();
267
+ V(r), f();
270
268
  } });
271
269
  };
272
270
  function _e({ onClick: e, ...t }) {
273
- return t.onClick = (n) => {
274
- n.preventDefault(), e == null || e(n);
275
- }, /* @__PURE__ */ v("button", { type: "button", ...t });
271
+ return /* @__PURE__ */ v("button", { type: "button", ...t, onClick: (u) => {
272
+ u.preventDefault(), e == null || e(u);
273
+ } });
276
274
  }
277
- function E(e, t) {
275
+ function D(e, t) {
278
276
  const n = e instanceof Date ? e : new Date(e);
279
- let r = `${n.getFullYear()}-${I(n.getMonth() + 1)}-${I(n.getDate())}T${I(n.getHours())}:${I(n.getMinutes())}`;
280
- const u = (t == null ? void 0 : t.milliseconds) || (t == null ? void 0 : t.milliseconds) == null && n.getMilliseconds() !== 0;
281
- return ((t == null ? void 0 : t.seconds) || (t == null ? void 0 : t.seconds) == null && (n.getSeconds() !== 0 || u)) && (r += `:${I(n.getSeconds())}`, u && (r += `.${I(n.getMilliseconds(), 3)}`)), t != null && t.offset && (r += p(-n.getTimezoneOffset())), r;
277
+ let u = `${n.getFullYear()}-${y(n.getMonth() + 1)}-${y(n.getDate())}T${y(n.getHours())}:${y(n.getMinutes())}`;
278
+ const r = (t == null ? void 0 : t.milliseconds) || (t == null ? void 0 : t.milliseconds) == null && n.getMilliseconds() !== 0;
279
+ return ((t == null ? void 0 : t.seconds) || (t == null ? void 0 : t.seconds) == null && (n.getSeconds() !== 0 || r)) && (u += `:${y(n.getSeconds())}`, r && (u += `.${y(n.getMilliseconds(), 3)}`)), t != null && t.offset && (u += F(-n.getTimezoneOffset())), u;
282
280
  }
283
- function p(e) {
281
+ function F(e) {
284
282
  if (e == null)
285
283
  return "";
286
284
  if (e === 0)
287
285
  return "Z";
288
- const t = e > 0 ? "+" : "-", n = Math.floor(Math.abs(e) / 60), r = Math.abs(e) % 60;
289
- return `${t}${I(n)}:${I(r)}`;
286
+ const t = e > 0 ? "+" : "-", n = Math.floor(Math.abs(e) / 60), u = Math.abs(e) % 60;
287
+ return `${t}${y(n)}:${y(u)}`;
290
288
  }
291
- const me = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,3})?)?)(Z|[+-]\d{2}:\d{2})?$/, ve = { offset: !1, seconds: !1, milliseconds: !1 };
292
- function Ne(e) {
289
+ const me = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,3})?)?)(Z|[+-]\d{2}:\d{2})?$/, xe = { offset: !1, seconds: !1, milliseconds: !1 };
290
+ function ve(e) {
293
291
  return e == null || Number.isNaN(e) || e === "" || Number.isNaN(+new Date(e));
294
292
  }
295
- function M(e) {
293
+ function _(e) {
296
294
  if (typeof e == "string") {
297
295
  const t = e.match(me);
298
296
  if (t)
299
297
  return t[1];
300
298
  }
301
- return Ne(e) ? "" : E(e, ve);
299
+ return ve(e) ? "" : D(e, xe);
302
300
  }
303
- const w = { offset: !1 };
304
- function Me({ value: e, defaultValue: t, min: n, max: r, onChange: u, ...s }) {
305
- return e !== void 0 && (s.value = e === null ? "" : E(e, w)), t != null && (s.defaultValue = E(t, w)), n != null && (s.min = E(n, w)), r != null && (s.max = E(r, w)), u != null && (s.onChange = (i) => {
306
- u({
307
- value: i.currentTarget.value
301
+ const M = { offset: !1 };
302
+ function Me({ value: e, defaultValue: t, min: n, max: u, onChange: r, ...s }) {
303
+ const i = e !== void 0 ? e === null ? "" : D(e, M) : s.value, f = t != null ? D(t, M) : s.defaultValue, c = n != null ? D(n, M) : s.min, o = u != null ? D(u, M) : s.max, l = r == null ? s.onChange : (d) => {
304
+ const x = d.currentTarget.value, a = x === "" ? null : new Date(x);
305
+ r({
306
+ value: x,
307
+ date: a != null && !Number.isNaN(+a) ? a : null,
308
+ isoString: a != null && !Number.isNaN(+a) ? a.toISOString() : ""
308
309
  });
309
- }), /* @__PURE__ */ v("input", { type: "datetime-local", ...s });
310
+ };
311
+ return /* @__PURE__ */ v("input", { type: "datetime-local", ...s, value: i, defaultValue: f, min: c, max: o, onChange: l });
310
312
  }
311
- function ge(e) {
312
- const t = h(e);
313
+ function Ne(e) {
314
+ const t = b(e);
313
315
  return t.current = e, t;
314
316
  }
315
- function be(e, t) {
316
- const n = h(e), r = ge(t);
317
- return C(() => {
318
- Object.is(n.current, e) || (r.current(), n.current = e);
319
- }, [r, e]), T((u) => {
320
- n.current = u;
317
+ function ge(e, t) {
318
+ const n = b(e), u = Ne(t);
319
+ return k(() => {
320
+ Object.is(n.current, e) || (u.current(), n.current = e);
321
+ }, [u, e]), T((r) => {
322
+ n.current = r;
321
323
  }, []);
322
324
  }
323
325
  const he = [
@@ -398,7 +400,7 @@ const he = [
398
400
  // Kiribati
399
401
  { value: 14 * 60, text: "+14:00" }
400
402
  ];
401
- function $(e) {
403
+ function w(e) {
402
404
  if (typeof e != "string" || e === "")
403
405
  return null;
404
406
  const t = e.match(/([+-])(\d{2}):(\d{2})|Z$/);
@@ -406,56 +408,62 @@ function $(e) {
406
408
  return null;
407
409
  if (t[0] === "Z")
408
410
  return 0;
409
- const [, n, r, u] = t, s = Number(r) * 60 + Number(u);
411
+ const [, n, u, r] = t, s = Number(u) * 60 + Number(r);
410
412
  return n === "+" ? s : -s;
411
413
  }
412
- function A(e) {
414
+ function $(e) {
413
415
  return e === "" ? null : -new Date(e).getTimezoneOffset();
414
416
  }
417
+ function be(e, t, n) {
418
+ return e ? t : $(n);
419
+ }
420
+ function Ie(e, t, n) {
421
+ return F(be(e, t, n));
422
+ }
415
423
  function we({
416
424
  value: e,
417
425
  defaultValue: t,
418
426
  min: n,
419
- max: r,
420
- onChange: u,
427
+ max: u,
428
+ onChange: r,
421
429
  ...s
422
430
  }) {
423
- const [i, f] = D(() => $(e ?? t) !== null), [o, l] = D(() => $(e ?? t)), [d, a] = D(() => M(e ?? t)), x = be(e, () => {
424
- f($(e) !== null), l($(e)), a(M(e));
425
- }), N = T((b) => {
426
- x(b), u == null || u({
427
- value: b
431
+ const [i, f] = O(() => w(e ?? t) !== null), [c, o] = O(() => w(e ?? t)), [l, d] = O(() => _(e ?? t)), x = ge(e, () => {
432
+ f(w(e) !== null), o(w(e)), d(_(e));
433
+ }), a = T((g) => {
434
+ x(g), r == null || r({
435
+ value: g
428
436
  });
429
- }, [u, x]);
430
- n != null && (s.min = M(n)), r != null && (s.max = M(r));
431
- const m = i ? o : A(d), c = T(
432
- (b) => {
433
- const S = b.currentTarget.value;
434
- a(S), N(S + p(m));
437
+ }, [r, x]), N = n != null ? _(n) : s.min, m = u != null ? _(u) : s.max, h = i ? c : $(l), S = T(
438
+ (g) => {
439
+ const I = g.currentTarget.value;
440
+ d(I), a(I + Ie(i, c, I));
435
441
  },
436
- [N, m]
437
- ), g = T(
438
- (b) => {
439
- l(b.value), N(d + p(b.value));
442
+ [a, i, c]
443
+ ), K = T(
444
+ (g) => {
445
+ o(g.value), a(l + F(g.value));
440
446
  },
441
- [N, d]
442
- ), O = T(
443
- (b) => {
444
- const S = b.currentTarget.checked;
445
- f(S);
446
- let y;
447
- S ? d && o === null ? (y = A(d), l(y)) : y = o : y = A(d), N(d + p(y));
447
+ [a, l]
448
+ ), A = T(
449
+ (g) => {
450
+ const I = g.currentTarget.checked;
451
+ f(I);
452
+ let E;
453
+ I ? l && c === null ? (E = $(l), o(E)) : E = c : E = $(l), a(l + F(E));
448
454
  },
449
- [o, d, N]
455
+ [c, l, a]
450
456
  );
451
- return /* @__PURE__ */ L("span", { children: [
457
+ return /* @__PURE__ */ R("span", { children: [
452
458
  /* @__PURE__ */ v(
453
459
  "input",
454
460
  {
455
461
  type: "datetime-local",
456
462
  ...s,
457
- value: d,
458
- onChange: c
463
+ min: N,
464
+ max: m,
465
+ value: l,
466
+ onChange: S
459
467
  }
460
468
  ),
461
469
  /* @__PURE__ */ v(
@@ -464,43 +472,43 @@ function we({
464
472
  type: "checkbox",
465
473
  title: i ? "Use UTC offset from this device" : "Enable UTC offset selection",
466
474
  checked: i,
467
- onChange: O
475
+ onChange: A
468
476
  }
469
477
  ),
470
478
  /* @__PURE__ */ v(
471
- ie,
479
+ ae,
472
480
  {
473
- value: m,
474
- onChange: g,
481
+ value: h,
482
+ onChange: K,
475
483
  disabled: !i,
476
484
  options: he
477
485
  }
478
486
  )
479
487
  ] });
480
488
  }
481
- const $e = k(function({ placeholder: t, formatOnChange: n = xe, onChange: r, value: u, ...s }, i) {
482
- const f = {
489
+ function $e({ placeholder: e, formatOnChange: t = de, onChange: n, value: u, ref: r, ...s }) {
490
+ const i = {
483
491
  inputMode: "decimal",
484
492
  ...s,
485
- formatOnChange: n,
493
+ formatOnChange: t,
486
494
  type: "number"
487
495
  };
488
- return u !== void 0 && (f.value = Y(u)), t != null && (f.placeholder = String(t)), r != null && (f.onChange = (o) => {
489
- r({
490
- ...o,
491
- value: de(o.value)
496
+ return u !== void 0 && (i.value = H(u)), e != null && (i.placeholder = String(e)), n != null && (i.onChange = (f) => {
497
+ n({
498
+ ...f,
499
+ value: oe(f.value)
492
500
  });
493
- }), /* @__PURE__ */ v(j, { ...f, ref: i });
494
- });
501
+ }), /* @__PURE__ */ v(Y, { ...i, ref: r });
502
+ }
495
503
  export {
496
504
  _e as ActionButton,
497
505
  Me as DatetimeLocalInput,
498
506
  we as DatetimeOffsetInput,
499
- De as DebouncedInput,
500
- j as Input,
507
+ pe as DebouncedInput,
508
+ Y as Input,
501
509
  $e as NumberInput,
502
- Ee as RadioMenu,
503
- ie as Select,
504
- Se as TextArea,
510
+ De as RadioMenu,
511
+ ae as Select,
512
+ Ee as TextArea,
505
513
  Oe as TextInput
506
514
  };
@@ -1 +1 @@
1
- (function(o,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],f):(o=typeof globalThis<"u"?globalThis:o||self,f(o["@mpen/react-basic-inputs"]={},o.jsxRuntime,o.React))})(this,function(o,f,r){"use strict";var ve=Object.defineProperty;var be=(o,f,r)=>f in o?ve(o,f,{enumerable:!0,configurable:!0,writable:!0,value:r}):o[f]=r;var L=(o,f,r)=>(be(o,typeof f!="symbol"?f+"":f,r),r);const U=Object.freeze(()=>{});function q(e){return e}let E;typeof window<"u"?E=e=>{r.useDebugValue(e);const t=r.useRef(Y);r.useInsertionEffect(()=>{t.current=e},[e]);const n=r.useRef(null);return n.current||(n.current=function(){return t.current.apply(this,arguments)}),n.current}:E=U;function H(e){return E(e)}function Y(){throw new Error("INVALID_USE_EVENT_INVOCATION: the callback from useEvent cannot be invoked before the component has mounted.")}function z(){var e=r.useRef(!0);return e.current?(e.current=!1,!0):e.current}var p=function(e,t){var n=z();r.useEffect(function(){if(!n)return e()},t)};function G(e,...t){return typeof e=="function"?e(...t):e}function Z(e,t){if(e.uniqueKey!=null)return G(e.uniqueKey,e,t);if(typeof e.value=="string")return e.value;if(typeof e.value=="number")return String(e.value);try{const n=JSON.stringify(e.value);if(n!==void 0)return n}catch{}return String(t)}class K{constructor(){L(this,"_usedKeys",new Map)}fix(t,n){let u=Z(t,n);for(;;){let s=this._usedKeys.get(u);if(s===void 0){this._usedKeys.set(u,1);break}this._usedKeys.set(u,++s),u=`${u}(${s})`}return u}}const B=e=>({value:e,text:String(e),disabled:!0,key:J}),W="3c9369b7-0a5e-46ea-93c2-e8b9fec67fdb",J="1a53f789-77f5-4ce6-a829-b00e563f1ee8";function C({options:e,value:t,invalidValueOption:n=B,onChange:u,placeholder:s,...l}){const d=t==null,x=r.useMemo(()=>t!=null&&e.some(c=>c.value==t),[e,t]),m=r.useMemo(()=>t==null||!n?null:n(t),[n,t]),i=r.useMemo(()=>{if(x)return e;const c=[...e];return d?s!=null&&c.unshift({text:s,hidden:!0,value:null,key:W}):m&&c.push(m),c},[x,e,d,m,s]),v=H(c=>{const h=c.target.selectedIndex,S=i[h];u==null||u({value:S.value,index:h,type:"change",timeStamp:c.timeStamp,target:c.target})}),a=r.useRef(null),b=r.useCallback(()=>{a.current&&(a.current.selectedIndex<0||i[a.current.selectedIndex].value!=t)&&(a.current.selectedIndex=i.findIndex(c=>c.value==t))},[i,t]),I=c=>{a.current=c,b()};p(()=>{b()},[b]);const N=new K;return f.jsx("select",{...l,onChange:v,ref:I,children:i.map((c,h)=>{const{value:S,text:g,uniqueKey:O,...T}=c,P=N.fix(c,h);return r.createElement("option",{...T,key:P,value:P},c.text)})})}function X(e){return e?String(e).replace(/\s+/gu," ").trim():""}function Q(e){try{return e.toLocaleString("en-US",{useGrouping:!1,maximumFractionDigits:20})}catch{return e.toFixed(14).replace(/\.?0+$/,"")}}function R(e){return e?e==="∞"||e==="+∞"?Number.POSITIVE_INFINITY:e==="-∞"?Number.NEGATIVE_INFINITY:Number.parseFloat(e):Number.NaN}function V(e){return Number.isNaN(e)?"":e===Number.POSITIVE_INFINITY?"∞":e===Number.NEGATIVE_INFINITY?"-∞":Q(e)}function ee(e){return e?V(Number.parseFloat(e)):""}function y(e,t=2){return String(e).padStart(t,"0")}const $=r.forwardRef(function({value:t="",onPaste:n,onChange:u,onInput:s,onBlur:l,formatOnChange:d=q,...x},m){const[i,v]=r.useState(t),a=r.useRef(t),b=r.useRef(!1);p(()=>{v(t),b.current=!1,a.current=t},[t]);const I={type:"text",...x,ref:m,value:i,onChange:N=>{v(N.target.value)},onInput:N=>{b.current=!0,s==null||s(N)},onBlur:N=>{const c=d(i);b.current&&(c!==a.current&&(u==null||u({type:"change",value:c,timeStamp:N.timeStamp,target:N.target}),a.current=c),c!==N.target.value&&v(c)),l==null||l(N)}};return f.jsx("input",{...I})});function te({formatOnChange:e=X,...t}){return f.jsx($,{formatOnChange:e,...t,type:"text"})}const ne=r.forwardRef(function({onInput:t,style:n,initialHeight:u="auto",...s},l){const d=r.useRef(null),[x,m]=r.useState(u),i=r.useCallback(()=>{const a=d.current;if(!a)return;a.style.height=u;const b=`${a.scrollHeight}px`;m(b),a.style.height=b},[u]);r.useImperativeHandle(l,()=>({element:d.current,adjustHeight:i}),[i]);const v=E(a=>{i(),t==null||t(a)});return r.useLayoutEffect(()=>{i();const a=d.current;if(!a)return;const b=new ResizeObserver(I=>{i()});return b.observe(a),()=>{b.unobserve(a)}},[i]),f.jsx("textarea",{...s,style:{overflow:"hidden",resize:"none",...n,height:x},onInput:v,ref:d})});function ue(e){const t=r.useId(),n=e.name??t,u=e.valueEquals??Object.is,s=e.options??[],l=new K,d=E(x=>{const m=Number(x.target.value),i=s[m];i!=null&&e.onChange!=null&&e.onChange({value:i.value,index:m,type:"change",timeStamp:x.timeStamp,target:x.target})});return f.jsx("ul",{className:e.className,children:s.map((x,m)=>{const{value:i,text:v,key:a,itemClassName:b,labelClassName:I,inputClassName:N,textClassName:c,...h}=x,S=l.fix(x,m);return e.value!==void 0&&(h.checked=u(i,e.value)),f.jsx("li",{className:b,"aria-disabled":h.disabled,children:f.jsxs("label",{className:I,children:[f.jsx("input",{...h,className:N,value:m,onChange:d,name:n,type:"radio"}),f.jsx("span",{className:c,children:v})]})},S)})})}function j(){return r.useRef(null)}function A(e){e.current!=null&&(clearTimeout(e.current),e.current=null)}const re=({value:e,onChange:t,debounce:n=500,...u})=>{const s=j(),l=j();p(()=>{A(l),s.current!=null&&(s.current.value=e)},[e]);const d=()=>{s.current!=null&&s.current.value!==e&&(t==null||t({value:s.current.value}))};return f.jsx("input",{...u,ref:s,defaultValue:e,onInput:()=>{A(l),l.current=setTimeout(d,n)},onBlur:()=>{A(l),d()}})};function se({onClick:e,...t}){return t.onClick=n=>{n.preventDefault(),e==null||e(n)},f.jsx("button",{type:"button",...t})}function D(e,t){const n=e instanceof Date?e:new Date(e);let u=`${n.getFullYear()}-${y(n.getMonth()+1)}-${y(n.getDate())}T${y(n.getHours())}:${y(n.getMinutes())}`;const s=(t==null?void 0:t.milliseconds)||(t==null?void 0:t.milliseconds)==null&&n.getMilliseconds()!==0;return((t==null?void 0:t.seconds)||(t==null?void 0:t.seconds)==null&&(n.getSeconds()!==0||s))&&(u+=`:${y(n.getSeconds())}`,s&&(u+=`.${y(n.getMilliseconds(),3)}`)),t!=null&&t.offset&&(u+=M(-n.getTimezoneOffset())),u}function M(e){if(e==null)return"";if(e===0)return"Z";const t=e>0?"+":"-",n=Math.floor(Math.abs(e)/60),u=Math.abs(e)%60;return`${t}${y(n)}:${y(u)}`}const le=/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,3})?)?)(Z|[+-]\d{2}:\d{2})?$/,fe={offset:!1,seconds:!1,milliseconds:!1};function ce(e){return e==null||Number.isNaN(e)||e===""||Number.isNaN(+new Date(e))}function _(e){if(typeof e=="string"){const t=e.match(le);if(t)return t[1]}return ce(e)?"":D(e,fe)}const w={offset:!1};function ie({value:e,defaultValue:t,min:n,max:u,onChange:s,...l}){return e!==void 0&&(l.value=e===null?"":D(e,w)),t!=null&&(l.defaultValue=D(t,w)),n!=null&&(l.min=D(n,w)),u!=null&&(l.max=D(u,w)),s!=null&&(l.onChange=d=>{s({value:d.currentTarget.value})}),f.jsx("input",{type:"datetime-local",...l})}function ae(e){const t=r.useRef(e);return t.current=e,t}function oe(e,t){const n=r.useRef(e),u=ae(t);return r.useEffect(()=>{Object.is(n.current,e)||(u.current(),n.current=e)},[u,e]),r.useCallback(s=>{n.current=s},[])}const de=[{value:-12*60,text:"-12:00"},{value:-11*60,text:"-11:00"},{value:-10*60,text:"-10:00"},{value:-9.5*60,text:"-09:30"},{value:-9*60,text:"-09:00"},{value:-8*60,text:"-08:00"},{value:-7*60,text:"-07:00"},{value:-6*60,text:"-06:00"},{value:-5*60,text:"-05:00"},{value:-4*60,text:"-04:00"},{value:-3.5*60,text:"-03:30"},{value:-3*60,text:"-03:00"},{value:-2*60,text:"-02:00"},{value:-1*60,text:"-01:00"},{value:0,text:"±00:00"},{value:1*60,text:"+01:00"},{value:2*60,text:"+02:00"},{value:3*60,text:"+03:00"},{value:3.5*60,text:"+03:30"},{value:4*60,text:"+04:00"},{value:4.5*60,text:"+04:30"},{value:5*60,text:"+05:00"},{value:5.5*60,text:"+05:30"},{value:5.75*60,text:"+05:45"},{value:6*60,text:"+06:00"},{value:6.5*60,text:"+06:30"},{value:7*60,text:"+07:00"},{value:8*60,text:"+08:00"},{value:8.75*60,text:"+08:45"},{value:9*60,text:"+09:00"},{value:9.5*60,text:"+09:30"},{value:10*60,text:"+10:00"},{value:10.5*60,text:"+10:30"},{value:11*60,text:"+11:00"},{value:12*60,text:"+12:00"},{value:12.75*60,text:"+12:45"},{value:13*60,text:"+13:00"},{value:14*60,text:"+14:00"}];function k(e){if(typeof e!="string"||e==="")return null;const t=e.match(/([+-])(\d{2}):(\d{2})|Z$/);if(!t)return null;if(t[0]==="Z")return 0;const[,n,u,s]=t,l=Number(u)*60+Number(s);return n==="+"?l:-l}function F(e){return e===""?null:-new Date(e).getTimezoneOffset()}function xe({value:e,defaultValue:t,min:n,max:u,onChange:s,...l}){const[d,x]=r.useState(()=>k(e??t)!==null),[m,i]=r.useState(()=>k(e??t)),[v,a]=r.useState(()=>_(e??t)),b=oe(e,()=>{x(k(e)!==null),i(k(e)),a(_(e))}),I=r.useCallback(g=>{b(g),s==null||s({value:g})},[s,b]);n!=null&&(l.min=_(n)),u!=null&&(l.max=_(u));const N=d?m:F(v),c=r.useCallback(g=>{const O=g.currentTarget.value;a(O),I(O+M(N))},[I,N]),h=r.useCallback(g=>{i(g.value),I(v+M(g.value))},[I,v]),S=r.useCallback(g=>{const O=g.currentTarget.checked;x(O);let T;O?v&&m===null?(T=F(v),i(T)):T=m:T=F(v),I(v+M(T))},[m,v,I]);return f.jsxs("span",{children:[f.jsx("input",{type:"datetime-local",...l,value:v,onChange:c}),f.jsx("input",{type:"checkbox",title:d?"Use UTC offset from this device":"Enable UTC offset selection",checked:d,onChange:S}),f.jsx(C,{value:N,onChange:h,disabled:!d,options:de})]})}const me=r.forwardRef(function({placeholder:t,formatOnChange:n=ee,onChange:u,value:s,...l},d){const x={inputMode:"decimal",...l,formatOnChange:n,type:"number"};return s!==void 0&&(x.value=V(s)),t!=null&&(x.placeholder=String(t)),u!=null&&(x.onChange=m=>{u({...m,value:R(m.value)})}),f.jsx($,{...x,ref:d})});o.ActionButton=se,o.DatetimeLocalInput=ie,o.DatetimeOffsetInput=xe,o.DebouncedInput=re,o.Input=$,o.NumberInput=me,o.RadioMenu=ue,o.Select=C,o.TextArea=ne,o.TextInput=te,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
1
+ (function(m,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],f):(m=typeof globalThis<"u"?globalThis:m||self,f(m["@mpen/react-basic-inputs"]={},m.jsxRuntime,m.React))})(this,function(m,f,r){"use strict";var be=Object.defineProperty;var ge=(m,f,r)=>f in m?be(m,f,{enumerable:!0,configurable:!0,writable:!0,value:r}):m[f]=r;var L=(m,f,r)=>(ge(m,typeof f!="symbol"?f+"":f,r),r);const U=Object.freeze(()=>{});function q(e){return e}let O;typeof window<"u"?O=e=>{r.useDebugValue(e);const t=r.useRef(Y);r.useInsertionEffect(()=>{t.current=e},[e]);const n=r.useRef(null);return n.current||(n.current=function(){return t.current.apply(this,arguments)}),n.current}:O=U;function H(e){return O(e)}function Y(){throw new Error("INVALID_USE_EVENT_INVOCATION: the callback from useEvent cannot be invoked before the component has mounted.")}function z(){var e=r.useRef(!0);return e.current?(e.current=!1,!0):e.current}var P=function(e,t){var n=z();r.useEffect(function(){if(!n)return e()},t)};function G(e,...t){return typeof e=="function"?e(...t):e}function Z(e,t){if(e.uniqueKey!=null)return G(e.uniqueKey,e,t);if(typeof e.value=="string")return e.value;if(typeof e.value=="number")return String(e.value);try{const n=JSON.stringify(e.value);if(n!==void 0)return n}catch{}return String(t)}class F{constructor(){L(this,"_usedKeys",new Map)}fix(t,n){let u=Z(t,n);for(;;){let s=this._usedKeys.get(u);if(s===void 0){this._usedKeys.set(u,1);break}this._usedKeys.set(u,++s),u=`${u}(${s})`}return u}}const B=e=>({value:e,text:String(e),disabled:!0,key:J}),W="3c9369b7-0a5e-46ea-93c2-e8b9fec67fdb",J="1a53f789-77f5-4ce6-a829-b00e563f1ee8";function V({options:e,value:t,invalidValueOption:n=B,onChange:u,placeholder:s,...l}){const o=t==null,d=r.useMemo(()=>t!=null&&e.some(N=>N.value==t),[e,t]),c=r.useMemo(()=>t==null||!n?null:n(t),[n,t]),x=r.useMemo(()=>{if(d)return e;const N=[...e];return o?s!=null&&N.unshift({text:s,hidden:!0,value:null,key:W}):c&&N.push(c),N},[d,e,o,c,s]),a=H(N=>{const I=N.target.selectedIndex,T=x[I];u==null||u({value:T.value,index:I,type:"change",timeStamp:N.timeStamp,target:N.target})}),v=r.useRef(null),b=r.useCallback(()=>{v.current&&(v.current.selectedIndex<0||x[v.current.selectedIndex].value!=t)&&(v.current.selectedIndex=x.findIndex(N=>N.value==t))},[x,t]),i=N=>{v.current=N,b()};P(()=>{b()},[b]);const g=new F;return f.jsx("select",{...l,onChange:a,ref:i,children:x.map((N,I)=>{const{value:T,text:K,uniqueKey:j,...h}=N,S=g.fix(N,I);return r.createElement("option",{...h,key:S,value:S},N.text)})})}function X(e){return e?String(e).replace(/\s+/gu," ").trim():""}function Q(e){try{return e.toLocaleString("en-US",{useGrouping:!1,maximumFractionDigits:20})}catch{return e.toFixed(14).replace(/\.?0+$/,"")}}function R(e){return e?e==="∞"||e==="+∞"?Number.POSITIVE_INFINITY:e==="-∞"?Number.NEGATIVE_INFINITY:Number.parseFloat(e):Number.NaN}function A(e){return Number.isNaN(e)?"":e===Number.POSITIVE_INFINITY?"∞":e===Number.NEGATIVE_INFINITY?"-∞":Q(e)}function ee(e){return e?A(Number.parseFloat(e)):""}function y(e,t=2){return String(e).padStart(t,"0")}function C({value:e="",onPaste:t,onChange:n,onInput:u,onBlur:s,formatOnChange:l=q,ref:o,...d}){const[c,x]=r.useState(e),a=r.useRef(e),v=r.useRef(!1);P(()=>{x(e),v.current=!1,a.current=e},[e]);const b={type:"text",...d,ref:o,value:c,onChange:i=>{x(i.target.value)},onInput:i=>{v.current=!0,u==null||u(i)},onBlur:i=>{const g=l(c);v.current&&(g!==a.current&&(n==null||n({type:"change",value:g,timeStamp:i.timeStamp,target:i.target}),a.current=g),g!==i.target.value&&x(g)),s==null||s(i)}};return f.jsx("input",{...b})}function te({formatOnChange:e=X,...t}){return f.jsx(C,{formatOnChange:e,...t,type:"text"})}function ne({onInput:e,style:t,initialHeight:n="auto",ref:u,...s}){const l=r.useRef(null),[o,d]=r.useState(n),c=r.useCallback(()=>{const a=l.current;if(!a)return;a.style.height=n;const v=`${a.scrollHeight}px`;d(v),a.style.height=v},[n]);r.useImperativeHandle(u,()=>({element:l.current,adjustHeight:c}),[c]);const x=O(a=>{c(),e==null||e(a)});return r.useLayoutEffect(()=>{c();const a=l.current;if(!a)return;const v=new ResizeObserver(b=>{c()});return v.observe(a),()=>{v.unobserve(a)}},[c]),f.jsx("textarea",{...s,style:{overflow:"hidden",resize:"none",...t,height:o},onInput:x,ref:l})}function ue(e){const t=r.useId(),n=e.name??t,u=e.valueEquals??Object.is,s=e.options??[],l=new F,o=O(d=>{const c=Number(d.target.value),x=s[c];x!=null&&e.onChange!=null&&e.onChange({value:x.value,index:c,type:"change",timeStamp:d.timeStamp,target:d.target})});return f.jsx("ul",{className:e.className,children:s.map((d,c)=>{const{value:x,text:a,key:v,itemClassName:b,labelClassName:i,inputClassName:g,textClassName:N,...I}=d,T=l.fix(d,c);return e.value!==void 0&&(I.checked=u(x,e.value)),f.jsx("li",{className:b,"aria-disabled":I.disabled,children:f.jsxs("label",{className:i,children:[f.jsx("input",{...I,className:g,value:c,onChange:o,name:n,type:"radio"}),f.jsx("span",{className:N,children:a})]})},T)})})}function $(e){e.current!=null&&(clearTimeout(e.current),e.current=null)}const re=({value:e,onChange:t,debounce:n=500,...u})=>{const s=r.useRef(null),[l,o]=r.useState(e);r.useEffect(()=>{$(s),o(e)},[e]);const d=()=>{l!==e&&(t==null||t({value:l}))};return f.jsx("input",{...u,value:l,onChange:c=>{o(c.currentTarget.value),$(s),s.current=setTimeout(d,n)},onBlur:()=>{$(s),d()}})};function se({onClick:e,...t}){const n=u=>{u.preventDefault(),e==null||e(u)};return f.jsx("button",{type:"button",...t,onClick:n})}function E(e,t){const n=e instanceof Date?e:new Date(e);let u=`${n.getFullYear()}-${y(n.getMonth()+1)}-${y(n.getDate())}T${y(n.getHours())}:${y(n.getMinutes())}`;const s=(t==null?void 0:t.milliseconds)||(t==null?void 0:t.milliseconds)==null&&n.getMilliseconds()!==0;return((t==null?void 0:t.seconds)||(t==null?void 0:t.seconds)==null&&(n.getSeconds()!==0||s))&&(u+=`:${y(n.getSeconds())}`,s&&(u+=`.${y(n.getMilliseconds(),3)}`)),t!=null&&t.offset&&(u+=p(-n.getTimezoneOffset())),u}function p(e){if(e==null)return"";if(e===0)return"Z";const t=e>0?"+":"-",n=Math.floor(Math.abs(e)/60),u=Math.abs(e)%60;return`${t}${y(n)}:${y(u)}`}const le=/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,3})?)?)(Z|[+-]\d{2}:\d{2})?$/,ce={offset:!1,seconds:!1,milliseconds:!1};function ae(e){return e==null||Number.isNaN(e)||e===""||Number.isNaN(+new Date(e))}function M(e){if(typeof e=="string"){const t=e.match(le);if(t)return t[1]}return ae(e)?"":E(e,ce)}const _={offset:!1};function fe({value:e,defaultValue:t,min:n,max:u,onChange:s,...l}){const o=e!==void 0?e===null?"":E(e,_):l.value,d=t!=null?E(t,_):l.defaultValue,c=n!=null?E(n,_):l.min,x=u!=null?E(u,_):l.max,a=s==null?l.onChange:v=>{const b=v.currentTarget.value,i=b===""?null:new Date(b);s({value:b,date:i!=null&&!Number.isNaN(+i)?i:null,isoString:i!=null&&!Number.isNaN(+i)?i.toISOString():""})};return f.jsx("input",{type:"datetime-local",...l,value:o,defaultValue:d,min:c,max:x,onChange:a})}function ie(e){const t=r.useRef(e);return t.current=e,t}function oe(e,t){const n=r.useRef(e),u=ie(t);return r.useEffect(()=>{Object.is(n.current,e)||(u.current(),n.current=e)},[u,e]),r.useCallback(s=>{n.current=s},[])}const de=[{value:-12*60,text:"-12:00"},{value:-11*60,text:"-11:00"},{value:-10*60,text:"-10:00"},{value:-9.5*60,text:"-09:30"},{value:-9*60,text:"-09:00"},{value:-8*60,text:"-08:00"},{value:-7*60,text:"-07:00"},{value:-6*60,text:"-06:00"},{value:-5*60,text:"-05:00"},{value:-4*60,text:"-04:00"},{value:-3.5*60,text:"-03:30"},{value:-3*60,text:"-03:00"},{value:-2*60,text:"-02:00"},{value:-1*60,text:"-01:00"},{value:0,text:"±00:00"},{value:1*60,text:"+01:00"},{value:2*60,text:"+02:00"},{value:3*60,text:"+03:00"},{value:3.5*60,text:"+03:30"},{value:4*60,text:"+04:00"},{value:4.5*60,text:"+04:30"},{value:5*60,text:"+05:00"},{value:5.5*60,text:"+05:30"},{value:5.75*60,text:"+05:45"},{value:6*60,text:"+06:00"},{value:6.5*60,text:"+06:30"},{value:7*60,text:"+07:00"},{value:8*60,text:"+08:00"},{value:8.75*60,text:"+08:45"},{value:9*60,text:"+09:00"},{value:9.5*60,text:"+09:30"},{value:10*60,text:"+10:00"},{value:10.5*60,text:"+10:30"},{value:11*60,text:"+11:00"},{value:12*60,text:"+12:00"},{value:12.75*60,text:"+12:45"},{value:13*60,text:"+13:00"},{value:14*60,text:"+14:00"}];function k(e){if(typeof e!="string"||e==="")return null;const t=e.match(/([+-])(\d{2}):(\d{2})|Z$/);if(!t)return null;if(t[0]==="Z")return 0;const[,n,u,s]=t,l=Number(u)*60+Number(s);return n==="+"?l:-l}function w(e){return e===""?null:-new Date(e).getTimezoneOffset()}function me(e,t,n){return e?t:w(n)}function xe(e,t,n){return p(me(e,t,n))}function ve({value:e,defaultValue:t,min:n,max:u,onChange:s,...l}){const[o,d]=r.useState(()=>k(e??t)!==null),[c,x]=r.useState(()=>k(e??t)),[a,v]=r.useState(()=>M(e??t)),b=oe(e,()=>{d(k(e)!==null),x(k(e)),v(M(e))}),i=r.useCallback(h=>{b(h),s==null||s({value:h})},[s,b]),g=n!=null?M(n):l.min,N=u!=null?M(u):l.max,I=o?c:w(a),T=r.useCallback(h=>{const S=h.currentTarget.value;v(S),i(S+xe(o,c,S))},[i,o,c]),K=r.useCallback(h=>{x(h.value),i(a+p(h.value))},[i,a]),j=r.useCallback(h=>{const S=h.currentTarget.checked;d(S);let D;S?a&&c===null?(D=w(a),x(D)):D=c:D=w(a),i(a+p(D))},[c,a,i]);return f.jsxs("span",{children:[f.jsx("input",{type:"datetime-local",...l,min:g,max:N,value:a,onChange:T}),f.jsx("input",{type:"checkbox",title:o?"Use UTC offset from this device":"Enable UTC offset selection",checked:o,onChange:j}),f.jsx(V,{value:I,onChange:K,disabled:!o,options:de})]})}function Ne({placeholder:e,formatOnChange:t=ee,onChange:n,value:u,ref:s,...l}){const o={inputMode:"decimal",...l,formatOnChange:t,type:"number"};return u!==void 0&&(o.value=A(u)),e!=null&&(o.placeholder=String(e)),n!=null&&(o.onChange=d=>{n({...d,value:R(d.value)})}),f.jsx(C,{...o,ref:s})}m.ActionButton=se,m.DatetimeLocalInput=fe,m.DatetimeOffsetInput=ve,m.DebouncedInput=re,m.Input=C,m.NumberInput=Ne,m.RadioMenu=ue,m.Select=V,m.TextArea=ne,m.TextInput=te,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mpen/react-basic-inputs",
3
3
  "private": false,
4
- "version": "0.3.3",
4
+ "version": "0.4.0",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"
@@ -17,32 +17,34 @@
17
17
  "dev": "bun run --bun vite",
18
18
  "build": "run-p 'build:*'",
19
19
  "build:libs": "bun run --bun vite build",
20
+ "build:docs": "typedoc && hg addremove docs",
20
21
  "lint": "run-s 'lint:*'",
21
22
  "lint:ts": "bun run --bun tsc",
22
- "lint:es": "bun run --bun eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
23
+ "lint:es": "bun run --bun eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0 --fix",
23
24
  "preview": "bun run --bun vite preview",
24
25
  "_prepublishOnly": "bun run --bun build",
25
26
  "_publish": "npm publish --access=public",
26
- "build:docs": "typedoc && hg addremove docs",
27
- "bump": "npm version patch && bun.exe run build && npm publish"
27
+ "bump": "npm version patch && bun run build && npm publish"
28
28
  },
29
29
  "peerDependencies": {
30
- "react": "^18.2.0"
30
+ "react": ">=18"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@mpen/is-type": "^0.1.11",
34
34
  "@types/bun": "^1.1.2",
35
- "@types/react": "^18.2.66",
36
- "@types/react-dom": "^18.2.22",
35
+ "@types/react": "^19",
36
+ "@types/react-dom": "^19",
37
37
  "@typescript-eslint/eslint-plugin": "^7.2.0",
38
38
  "@typescript-eslint/parser": "^7.2.0",
39
39
  "@vitejs/plugin-react": "^4.2.1",
40
40
  "eslint": "^8.57.0",
41
+ "eslint-plugin-react-compiler": "^19.1.0-rc.2",
41
42
  "eslint-plugin-react-hooks": "^4.6.0",
42
43
  "eslint-plugin-react-refresh": "^0.4.6",
44
+ "eslint-plugin-unused-imports": "^4.3.0",
43
45
  "npm-run-all": "^4.1.5",
44
- "react": "^18.3.1",
45
- "react-dom": "^18.3.1",
46
+ "react": "^19",
47
+ "react-dom": "^19",
46
48
  "react-use": "^17.5.0",
47
49
  "sass": "^1.77.2",
48
50
  "typedoc": "^0.26.6",