@mpen/react-basic-inputs 0.2.9 → 0.3.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.
@@ -14,15 +14,24 @@ export declare function ActionButton({ onClick, ...props }: ActionButtonProps):
14
14
 
15
15
  export declare type ActionButtonProps = RequiredKeys<ComponentPropsWithoutRef<'button'>, 'onClick'>;
16
16
 
17
- export declare function DatetimeLocalInput({ value, defaultValue, min, max, ...props }: DatetimeLocalInputProps): JSX_2.Element;
17
+ export declare function DatetimeLocalInput({ value, defaultValue, min, max, onChange, ...props }: DatetimeLocalInputProps): JSX_2.Element;
18
+
19
+ export declare type DatetimeLocalInputChangeEvent = {
20
+ isoString: string | null;
21
+ value: number | null;
22
+ date: Date | null;
23
+ };
18
24
 
19
25
  export declare type DatetimeLocalInputProps = OverrideProps<'input', {
20
- min?: number | string | Date;
21
- max?: number | string | Date;
22
- value?: number | string | Date | null;
23
- defaultValue?: number | string | Date;
26
+ min?: DateValue;
27
+ max?: DateValue;
28
+ value?: DateValue | null;
29
+ defaultValue?: DateValue;
30
+ onChange?: (ev: DatetimeLocalInputChangeEvent) => void;
24
31
  }, 'type'>;
25
32
 
33
+ export declare type DateValue = number | string | Date;
34
+
26
35
  export declare const DebouncedInput: FC<DebouncedInputProps>;
27
36
 
28
37
  export declare type DebouncedInputChangeEvent = {
@@ -85,6 +94,31 @@ export declare type InvalidValueToOption<T> = (value: T) => SelectOption<T>;
85
94
  */
86
95
  declare type NonNil = {};
87
96
 
97
+ export declare type NumberChangeEvent = {
98
+ value: number;
99
+ type: 'change';
100
+ timeStamp: number;
101
+ target: HtmlInputElement;
102
+ };
103
+
104
+ export declare type NumberChangeEventHandler = EventCallback<NumberChangeEvent>;
105
+
106
+ export declare const NumberInput: ForwardRefExoticComponent<Omit<Omit<Omit<Omit<DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref">, "value" | "onChange" | "formatOnChange"> & {
107
+ onChange?: InputChangeEventHandler | undefined;
108
+ value?: string | undefined;
109
+ formatOnChange?: ((value: string) => string) | undefined;
110
+ } & RefAttributes<HTMLInputElement>, "ref">, "value" | "onChange" | "placeholder" | "type"> & {
111
+ value?: number | undefined;
112
+ placeholder?: string | number | undefined;
113
+ onChange?: NumberChangeEventHandler | undefined;
114
+ } & RefAttributes<HTMLInputElement>>;
115
+
116
+ export declare type NumberInputProps = OverrideProps<typeof Input, {
117
+ value?: number;
118
+ placeholder?: string | number;
119
+ onChange?: NumberChangeEventHandler;
120
+ }, 'type'>;
121
+
88
122
  declare type Override<Base, Extension, DeleteKeys extends PropertyKey = never> = Omit<Base, keyof Extension | DeleteKeys> & Extension;
89
123
 
90
124
  declare type OverrideProps<Base extends ElementType, Extension, DeleteKeys extends PropertyKey = never> = Override<ComponentPropsWithoutRef<Base>, Extension, DeleteKeys>;
@@ -1,144 +1,155 @@
1
- var V = Object.defineProperty;
2
- var $ = (e, t, n) => t in e ? V(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var w = (e, t, n) => ($(e, typeof t != "symbol" ? t + "" : t, n), n);
4
- import { jsx as x, jsxs as k } from "react/jsx-runtime";
5
- import { useDebugValue as H, useRef as h, useInsertionEffect as L, useEffect as j, useMemo as S, useCallback as D, createElement as q, forwardRef as R, useState as T, useImperativeHandle as F, useLayoutEffect as z, useId as Y } from "react";
6
- const U = Object.freeze(() => {
1
+ var k = Object.defineProperty;
2
+ var H = (e, t, r) => t in e ? k(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
+ var K = (e, t, r) => (H(e, typeof t != "symbol" ? t + "" : t, r), r);
4
+ import { jsx as N, jsxs as L } from "react/jsx-runtime";
5
+ import { useDebugValue as Y, useRef as x, useInsertionEffect as j, useEffect as q, useMemo as E, useCallback as D, createElement as z, forwardRef as M, useState as F, useImperativeHandle as P, useLayoutEffect as U, useId as G } from "react";
6
+ const W = Object.freeze(() => {
7
7
  });
8
8
  function B(e) {
9
9
  return e;
10
10
  }
11
- let b;
12
- typeof window < "u" ? b = (e) => {
13
- H(e);
14
- const t = h(P);
15
- L(() => {
11
+ let v;
12
+ typeof window < "u" ? v = (e) => {
13
+ Y(e);
14
+ const t = x(Q);
15
+ j(() => {
16
16
  t.current = e;
17
17
  }, [e]);
18
- const n = h(null);
19
- return n.current || (n.current = function() {
18
+ const r = x(null);
19
+ return r.current || (r.current = function() {
20
20
  return t.current.apply(this, arguments);
21
- }), n.current;
22
- } : b = U;
21
+ }), r.current;
22
+ } : v = W;
23
23
  function J(e) {
24
- return b(e);
24
+ return v(e);
25
25
  }
26
- function P() {
26
+ function Q() {
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 W() {
30
- var e = h(!0);
29
+ function X() {
30
+ var e = x(!0);
31
31
  return e.current ? (e.current = !1, !0) : e.current;
32
32
  }
33
- var O = function(e, t) {
34
- var n = W();
35
- j(function() {
36
- if (!n)
33
+ var w = function(e, t) {
34
+ var r = X();
35
+ q(function() {
36
+ if (!r)
37
37
  return e();
38
38
  }, t);
39
39
  };
40
- function C(e, ...t) {
40
+ function Z(e, ...t) {
41
41
  return typeof e == "function" ? e(...t) : e;
42
42
  }
43
- function G(e, t) {
43
+ function C(e, t) {
44
44
  if (e.uniqueKey != null)
45
- return C(e.uniqueKey, e, t);
45
+ return Z(e.uniqueKey, e, t);
46
46
  if (typeof e.value == "string")
47
47
  return e.value;
48
48
  if (typeof e.value == "number")
49
49
  return String(e.value);
50
50
  try {
51
- const n = JSON.stringify(e.value);
52
- if (n !== void 0)
53
- return n;
51
+ const r = JSON.stringify(e.value);
52
+ if (r !== void 0)
53
+ return r;
54
54
  } catch {
55
55
  }
56
56
  return String(t);
57
57
  }
58
- class _ {
58
+ class A {
59
59
  constructor() {
60
- w(this, "usedKeys", /* @__PURE__ */ new Map());
60
+ K(this, "usedKeys", /* @__PURE__ */ new Map());
61
61
  }
62
- fix(t, n) {
63
- let u = G(t, n);
62
+ fix(t, r) {
63
+ let n = C(t, r);
64
64
  for (; ; ) {
65
- let r = this.usedKeys.get(u);
66
- if (r === void 0) {
67
- this.usedKeys.set(u, 1);
65
+ let u = this.usedKeys.get(n);
66
+ if (u === void 0) {
67
+ this.usedKeys.set(n, 1);
68
68
  break;
69
69
  }
70
- this.usedKeys.set(u, ++r), u = `${u}(${r})`;
70
+ this.usedKeys.set(n, ++u), n = `${n}(${u})`;
71
71
  }
72
- return u;
72
+ return n;
73
73
  }
74
74
  }
75
- const Q = (e) => ({
75
+ const ee = (e) => ({
76
76
  value: e,
77
77
  text: String(e),
78
78
  disabled: !0,
79
- key: Z
80
- }), X = "3c9369b7-0a5e-46ea-93c2-e8b9fec67fdb", Z = "1a53f789-77f5-4ce6-a829-b00e563f1ee8";
81
- function ie({
79
+ key: re
80
+ }), te = "3c9369b7-0a5e-46ea-93c2-e8b9fec67fdb", re = "1a53f789-77f5-4ce6-a829-b00e563f1ee8";
81
+ function de({
82
82
  options: e,
83
83
  value: t,
84
- invalidValueOption: n = Q,
85
- onChange: u,
86
- placeholder: r,
87
- ...a
84
+ invalidValueOption: r = ee,
85
+ onChange: n,
86
+ placeholder: u,
87
+ ...c
88
88
  }) {
89
- const f = t == null, o = S(() => t != null && e.some((s) => s.value == t), [e, t]), d = S(() => t == null || !n ? null : n(t), [n, t]), i = S(() => {
90
- if (o)
89
+ const i = t == null, l = E(() => t != null && e.some((s) => s.value == t), [e, t]), o = E(() => t == null || !r ? null : r(t), [r, t]), a = E(() => {
90
+ if (l)
91
91
  return e;
92
92
  const s = [...e];
93
- return f ? r != null && s.unshift({ text: r, hidden: !0, value: null, key: X }) : d && s.push(d), s;
94
- }, [o, e, f, d, r]), y = J((s) => {
95
- const g = s.target.selectedIndex, N = i[g];
96
- u == null || u({
97
- value: N.value,
93
+ return i ? u != null && s.unshift({ text: u, hidden: !0, value: null, key: te }) : o && s.push(o), s;
94
+ }, [l, e, i, o, u]), g = J((s) => {
95
+ const I = s.target.selectedIndex, S = a[I];
96
+ n == null || n({
97
+ value: S.value,
98
98
  // option: opt,
99
99
  // event: ev,
100
- index: g,
100
+ index: I,
101
101
  type: "change",
102
102
  timeStamp: s.timeStamp,
103
103
  target: s.target
104
104
  });
105
- }), c = h(null), l = D(() => {
106
- c.current && (c.current.selectedIndex < 0 || i[c.current.selectedIndex].value != t) && (c.current.selectedIndex = i.findIndex((s) => s.value == t));
107
- }, [i, t]), v = (s) => {
108
- c.current = s, l();
105
+ }), f = x(null), d = D(() => {
106
+ f.current && (f.current.selectedIndex < 0 || a[f.current.selectedIndex].value != t) && (f.current.selectedIndex = a.findIndex((s) => s.value == t));
107
+ }, [a, t]), y = (s) => {
108
+ f.current = s, d();
109
109
  };
110
- O(() => {
111
- l();
112
- }, [l]);
113
- const m = new _();
114
- return /* @__PURE__ */ x("select", { ...a, onChange: y, ref: v, children: i.map((s, g) => {
115
- const { value: N, text: ne, uniqueKey: re, ...A } = s, K = m.fix(s, g);
116
- return /* @__PURE__ */ q("option", { ...A, key: K, value: K }, s.text);
110
+ w(() => {
111
+ d();
112
+ }, [d]);
113
+ const m = new A();
114
+ return /* @__PURE__ */ N("select", { ...c, onChange: g, ref: y, children: a.map((s, I) => {
115
+ const { value: S, text: le, uniqueKey: ie, ...R } = s, _ = m.fix(s, I);
116
+ return /* @__PURE__ */ z("option", { ...R, key: _, value: _ }, s.text);
117
117
  }) });
118
118
  }
119
- function ee(e) {
119
+ function ne(e) {
120
120
  return e ? String(e).replace(/\s+/gu, " ").trim() : "";
121
121
  }
122
- function p(e, t = 2) {
123
- return String(e).padStart(t, "0");
122
+ function ue(e) {
123
+ try {
124
+ return e.toLocaleString("en-US", { useGrouping: !1, maximumFractionDigits: 20 });
125
+ } catch {
126
+ return e.toFixed(14).replace(/\.?0+$/, "");
127
+ }
124
128
  }
125
- function I(e) {
126
- const t = new Date(e);
127
- let n = `${t.getFullYear()}-${p(t.getMonth() + 1)}-${p(t.getDate())}T${p(t.getHours())}:${p(t.getMinutes())}`;
128
- return (t.getSeconds() !== 0 || t.getMilliseconds() !== 0) && (n += ":" + p(t.getSeconds()), t.getMilliseconds() !== 0 && (n += "." + p(t.getMilliseconds(), 3))), n;
129
+ function se(e) {
130
+ return e ? e === "∞" || e === "+∞" ? Number.POSITIVE_INFINITY : e === "-∞" ? Number.NEGATIVE_INFINITY : Number.parseFloat(e) : Number.NaN;
131
+ }
132
+ function V(e) {
133
+ return Number.isNaN(e) ? "" : e === Number.POSITIVE_INFINITY ? "∞" : e === Number.NEGATIVE_INFINITY ? "-∞" : ue(e);
134
+ }
135
+ function ce(e) {
136
+ return e ? V(Number.parseFloat(e)) : "";
137
+ }
138
+ function b(e, t = 2) {
139
+ return String(e).padStart(t, "0");
129
140
  }
130
- const te = R(function({ value: t = "", onPaste: n, onChange: u, onInput: r, onBlur: a, formatOnChange: f = B, ...o }, d) {
131
- const [i, y] = T(t), c = h(t), l = h(!1);
132
- O(() => {
133
- y(t), l.current = !1, c.current = t;
141
+ const p = M(function({ value: t = "", onPaste: r, onChange: n, onInput: u, onBlur: c, formatOnChange: i = B, ...l }, o) {
142
+ const [a, g] = F(t), f = x(t), d = x(!1);
143
+ w(() => {
144
+ g(t), d.current = !1, f.current = t;
134
145
  }, [t]);
135
- const v = {
146
+ const y = {
136
147
  type: "text",
137
- ...o,
138
- ref: d,
139
- value: i,
148
+ ...l,
149
+ ref: o,
150
+ value: a,
140
151
  onChange: (m) => {
141
- y(m.target.value);
152
+ g(m.target.value);
142
153
  },
143
154
  // TODO: fire a change event onPaste ?
144
155
  // formatOnPaste?
@@ -157,122 +168,164 @@ const te = R(function({ value: t = "", onPaste: n, onChange: u, onInput: r, onBl
157
168
  // // setCurrentValue(formatOnChange(ev.clipboardData.getData('text/plain')))
158
169
  // },
159
170
  onInput: (m) => {
160
- l.current = !0, r == null || r(m);
171
+ d.current = !0, u == null || u(m);
161
172
  },
162
173
  onBlur: (m) => {
163
- const s = f(i);
164
- l.current && (s !== c.current && (u == null || u({
174
+ const s = i(a);
175
+ d.current && (s !== f.current && (n == null || n({
165
176
  type: "change",
166
177
  value: s,
167
178
  timeStamp: m.timeStamp,
168
179
  target: m.target
169
- }), c.current = s), s !== m.target.value && y(s)), a == null || a(m);
180
+ }), f.current = s), s !== m.target.value && g(s)), c == null || c(m);
170
181
  }
171
182
  };
172
- return /* @__PURE__ */ x("input", { ...v });
183
+ return /* @__PURE__ */ N("input", { ...y });
173
184
  });
174
- function le({ formatOnChange: e = ee, ...t }) {
175
- return /* @__PURE__ */ x(te, { formatOnChange: e, ...t, type: "text" });
185
+ function me({ formatOnChange: e = ne, ...t }) {
186
+ return /* @__PURE__ */ N(p, { formatOnChange: e, ...t, type: "text" });
176
187
  }
177
- const ae = R(function({
188
+ const Ne = M(function({
178
189
  onInput: t,
179
- style: n,
180
- initialHeight: u = "auto",
181
- ...r
182
- }, a) {
183
- const f = h(null), [o, d] = T(u), i = D(() => {
184
- const c = f.current;
185
- if (!c)
190
+ style: r,
191
+ initialHeight: n = "auto",
192
+ ...u
193
+ }, c) {
194
+ const i = x(null), [l, o] = F(n), a = D(() => {
195
+ const f = i.current;
196
+ if (!f)
186
197
  return;
187
- c.style.height = u;
188
- const l = `${c.scrollHeight}px`;
189
- d(l), c.style.height = l;
190
- }, [u]);
191
- F(a, () => ({
192
- element: f.current,
193
- adjustHeight: i
194
- }), [i]);
195
- const y = b((c) => {
196
- i(), t == null || t(c);
198
+ f.style.height = n;
199
+ const d = `${f.scrollHeight}px`;
200
+ o(d), f.style.height = d;
201
+ }, [n]);
202
+ P(c, () => ({
203
+ element: i.current,
204
+ adjustHeight: a
205
+ }), [a]);
206
+ const g = v((f) => {
207
+ a(), t == null || t(f);
197
208
  });
198
- return z(() => {
199
- i();
200
- const c = f.current;
201
- if (!c)
209
+ return U(() => {
210
+ a();
211
+ const f = i.current;
212
+ if (!f)
202
213
  return;
203
- const l = new ResizeObserver((v) => {
204
- i();
214
+ const d = new ResizeObserver((y) => {
215
+ a();
205
216
  });
206
- return l.observe(c), () => {
207
- l.unobserve(c);
217
+ return d.observe(f), () => {
218
+ d.unobserve(f);
208
219
  };
209
- }, [i]), /* @__PURE__ */ x("textarea", { ...r, style: {
220
+ }, [a]), /* @__PURE__ */ N("textarea", { ...u, style: {
210
221
  overflow: "hidden",
211
222
  // these 2 styles aren't needed if the caller sets them in CSS.
212
223
  resize: "none",
213
- ...n,
214
- height: o
215
- }, onInput: y, ref: f });
224
+ ...r,
225
+ height: l
226
+ }, onInput: g, ref: i });
216
227
  });
217
- function fe(e) {
218
- const t = Y(), n = e.name ?? t, u = e.valueEquals ?? Object.is, r = e.options ?? [], a = new _(), f = b((o) => {
219
- const d = Number(o.target.value), i = r[d];
220
- i != null && e.onChange != null && e.onChange({
221
- value: i.value,
222
- index: d,
228
+ function ge(e) {
229
+ const t = G(), r = e.name ?? t, n = e.valueEquals ?? Object.is, u = e.options ?? [], c = new A(), i = v((l) => {
230
+ const o = Number(l.target.value), a = u[o];
231
+ a != null && e.onChange != null && e.onChange({
232
+ value: a.value,
233
+ index: o,
223
234
  type: "change",
224
- timeStamp: o.timeStamp,
225
- target: o.target
235
+ timeStamp: l.timeStamp,
236
+ target: l.target
226
237
  });
227
238
  });
228
- return /* @__PURE__ */ x("ul", { className: e.className, children: r.map((o, d) => {
229
- const { value: i, text: y, key: c, itemClassName: l, labelClassName: v, inputClassName: m, textClassName: s, ...g } = o, N = a.fix(o, d);
230
- return e.value !== void 0 && (g.checked = u(i, e.value)), /* @__PURE__ */ x("li", { className: l, "aria-disabled": g.disabled, children: /* @__PURE__ */ k("label", { className: v, children: [
231
- /* @__PURE__ */ x("input", { ...g, className: m, value: d, onChange: f, name: n, type: "radio" }),
232
- /* @__PURE__ */ x("span", { className: s, children: y })
233
- ] }) }, N);
239
+ return /* @__PURE__ */ N("ul", { className: e.className, children: u.map((l, o) => {
240
+ const { value: a, text: g, key: f, itemClassName: d, labelClassName: y, inputClassName: m, textClassName: s, ...I } = l, S = c.fix(l, o);
241
+ return e.value !== void 0 && (I.checked = n(a, e.value)), /* @__PURE__ */ N("li", { className: d, "aria-disabled": I.disabled, children: /* @__PURE__ */ L("label", { className: y, children: [
242
+ /* @__PURE__ */ N("input", { ...I, className: m, value: o, onChange: i, name: r, type: "radio" }),
243
+ /* @__PURE__ */ N("span", { className: s, children: g })
244
+ ] }) }, S);
234
245
  }) });
235
246
  }
236
- function M() {
237
- return h(null);
247
+ function $() {
248
+ return x(null);
238
249
  }
239
- function E(e) {
250
+ function O(e) {
240
251
  e.current != null && (clearTimeout(e.current), e.current = null);
241
252
  }
242
- const oe = ({
253
+ const Ie = ({
243
254
  value: e,
244
255
  onChange: t,
245
- debounce: n = 500,
246
- ...u
256
+ debounce: r = 500,
257
+ ...n
247
258
  }) => {
248
- const r = M(), a = M();
249
- O(() => {
250
- E(a), r.current != null && (r.current.value = e);
259
+ const u = $(), c = $();
260
+ w(() => {
261
+ O(c), u.current != null && (u.current.value = e);
251
262
  }, [e]);
252
- const f = () => {
253
- r.current != null && r.current.value !== e && (t == null || t({ value: r.current.value }));
263
+ const i = () => {
264
+ u.current != null && u.current.value !== e && (t == null || t({ value: u.current.value }));
254
265
  };
255
- return /* @__PURE__ */ x("input", { ...u, ref: r, defaultValue: e, onInput: () => {
256
- E(a), a.current = setTimeout(f, n);
266
+ return /* @__PURE__ */ N("input", { ...n, ref: u, defaultValue: e, onInput: () => {
267
+ O(c), c.current = setTimeout(i, r);
257
268
  }, onBlur: () => {
258
- E(a), f();
269
+ O(c), i();
259
270
  } });
260
271
  };
261
- function de({ onClick: e, ...t }) {
262
- return t.onClick = (n) => {
263
- n.preventDefault(), e == null || e(n);
264
- }, /* @__PURE__ */ x("button", { type: "button", ...t });
272
+ function be({ onClick: e, ...t }) {
273
+ return t.onClick = (r) => {
274
+ r.preventDefault(), e == null || e(r);
275
+ }, /* @__PURE__ */ N("button", { type: "button", ...t });
276
+ }
277
+ function h(e, t) {
278
+ const r = new Date(e);
279
+ let n = `${r.getFullYear()}-${b(r.getMonth() + 1)}-${b(r.getDate())}T${b(r.getHours())}:${b(r.getMinutes())}`;
280
+ const u = (t == null ? void 0 : t.milliseconds) || (t == null ? void 0 : t.milliseconds) == null && r.getMilliseconds() !== 0;
281
+ if (((t == null ? void 0 : t.seconds) || (t == null ? void 0 : t.seconds) == null && (r.getSeconds() !== 0 || u)) && (n += `:${b(r.getSeconds())}`, u && (n += `.${b(r.getMilliseconds(), 3)}`)), t != null && t.offset) {
282
+ const i = -r.getTimezoneOffset(), l = i >= 0 ? "+" : "-", o = Math.floor(Math.abs(i) / 60), a = Math.abs(i) % 60;
283
+ n += `${l}${b(o)}:${b(a)}`;
284
+ }
285
+ return n;
265
286
  }
266
- function me({ value: e, defaultValue: t, min: n, max: u, ...r }) {
267
- return e !== void 0 && (r.value = e === null ? "" : I(e)), t != null && (r.defaultValue = I(t)), n != null && (r.min = I(n)), u != null && (r.max = I(u)), /* @__PURE__ */ x("input", { type: "datetime-local", ...r });
287
+ const T = { offset: !1 };
288
+ function xe({ value: e, defaultValue: t, min: r, max: n, onChange: u, ...c }) {
289
+ return e !== void 0 && (c.value = e === null ? "" : h(e, T)), t != null && (c.defaultValue = h(t, T)), r != null && (c.min = h(r, T)), n != null && (c.max = h(n, T)), u != null && (c.onChange = (i) => {
290
+ if (i.currentTarget.value.length) {
291
+ const l = new Date(i.currentTarget.valueAsNumber);
292
+ u({
293
+ isoString: h(l, { offset: !0 }),
294
+ // isoString: date.toISOString(),
295
+ value: l.valueOf(),
296
+ date: l
297
+ });
298
+ } else
299
+ u({
300
+ // isoStringWithOffset: null,
301
+ isoString: null,
302
+ value: null,
303
+ date: null
304
+ });
305
+ }), /* @__PURE__ */ N("input", { type: "datetime-local", ...c });
268
306
  }
307
+ const ye = M(function({ placeholder: t, formatOnChange: r = ce, onChange: n, value: u, ...c }, i) {
308
+ const l = {
309
+ inputMode: "decimal",
310
+ ...c,
311
+ formatOnChange: r,
312
+ type: "number"
313
+ };
314
+ return u !== void 0 && (l.value = V(u)), t != null && (l.placeholder = String(t)), n != null && (l.onChange = (o) => {
315
+ n({
316
+ ...o,
317
+ value: se(o.value)
318
+ });
319
+ }), /* @__PURE__ */ N(p, { ...l, ref: i });
320
+ });
269
321
  export {
270
- de as ActionButton,
271
- me as DatetimeLocalInput,
272
- oe as DebouncedInput,
273
- te as Input,
274
- fe as RadioMenu,
275
- ie as Select,
276
- ae as TextArea,
277
- le as TextInput
322
+ be as ActionButton,
323
+ xe as DatetimeLocalInput,
324
+ Ie as DebouncedInput,
325
+ p as Input,
326
+ ye as NumberInput,
327
+ ge as RadioMenu,
328
+ de as Select,
329
+ Ne as TextArea,
330
+ me as TextInput
278
331
  };
@@ -1 +1 @@
1
- (function(f,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],c):(f=typeof globalThis<"u"?globalThis:f||self,c(f["@mpen/react-basic-inputs"]={},f.jsxRuntime,f.React))})(this,function(f,c,r){"use strict";var Q=Object.defineProperty;var X=(f,c,r)=>c in f?Q(f,c,{enumerable:!0,configurable:!0,writable:!0,value:r}):f[c]=r;var D=(f,c,r)=>(X(f,typeof c!="symbol"?c+"":c,r),r);const A=Object.freeze(()=>{});function j(e){return e}let I;typeof window<"u"?I=e=>{r.useDebugValue(e);const t=r.useRef(k);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}:I=A;function _(e){return I(e)}function k(){throw new Error("INVALID_USE_EVENT_INVOCATION: the callback from useEvent cannot be invoked before the component has mounted.")}function V(){var e=r.useRef(!0);return e.current?(e.current=!1,!0):e.current}var E=function(e,t){var n=V();r.useEffect(function(){if(!n)return e()},t)};function $(e,...t){return typeof e=="function"?e(...t):e}function q(e,t){if(e.uniqueKey!=null)return $(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 M{constructor(){D(this,"usedKeys",new Map)}fix(t,n){let s=q(t,n);for(;;){let u=this.usedKeys.get(s);if(u===void 0){this.usedKeys.set(s,1);break}this.usedKeys.set(s,++u),s=`${s}(${u})`}return s}}const L=e=>({value:e,text:String(e),disabled:!0,key:F}),H="3c9369b7-0a5e-46ea-93c2-e8b9fec67fdb",F="1a53f789-77f5-4ce6-a829-b00e563f1ee8";function z({options:e,value:t,invalidValueOption:n=L,onChange:s,placeholder:u,...d}){const y=t==null,m=r.useMemo(()=>t!=null&&e.some(i=>i.value==t),[e,t]),x=r.useMemo(()=>t==null||!n?null:n(t),[n,t]),a=r.useMemo(()=>{if(m)return e;const i=[...e];return y?u!=null&&i.unshift({text:u,hidden:!0,value:null,key:H}):x&&i.push(x),i},[m,e,y,x,u]),h=_(i=>{const p=i.target.selectedIndex,N=a[p];s==null||s({value:N.value,index:p,type:"change",timeStamp:i.timeStamp,target:i.target})}),l=r.useRef(null),o=r.useCallback(()=>{l.current&&(l.current.selectedIndex<0||a[l.current.selectedIndex].value!=t)&&(l.current.selectedIndex=a.findIndex(i=>i.value==t))},[a,t]),v=i=>{l.current=i,o()};E(()=>{o()},[o]);const g=new M;return c.jsx("select",{...d,onChange:h,ref:v,children:a.map((i,p)=>{const{value:N,text:Z,uniqueKey:R,...G}=i,w=g.fix(i,p);return r.createElement("option",{...G,key:w,value:w},i.text)})})}function Y(e){return e?String(e).replace(/\s+/gu," ").trim():""}function b(e,t=2){return String(e).padStart(t,"0")}function S(e){const t=new Date(e);let n=`${t.getFullYear()}-${b(t.getMonth()+1)}-${b(t.getDate())}T${b(t.getHours())}:${b(t.getMinutes())}`;return(t.getSeconds()!==0||t.getMilliseconds()!==0)&&(n+=":"+b(t.getSeconds()),t.getMilliseconds()!==0&&(n+="."+b(t.getMilliseconds(),3))),n}const T=r.forwardRef(function({value:t="",onPaste:n,onChange:s,onInput:u,onBlur:d,formatOnChange:y=j,...m},x){const[a,h]=r.useState(t),l=r.useRef(t),o=r.useRef(!1);E(()=>{h(t),o.current=!1,l.current=t},[t]);const v={type:"text",...m,ref:x,value:a,onChange:g=>{h(g.target.value)},onInput:g=>{o.current=!0,u==null||u(g)},onBlur:g=>{const i=y(a);o.current&&(i!==l.current&&(s==null||s({type:"change",value:i,timeStamp:g.timeStamp,target:g.target}),l.current=i),i!==g.target.value&&h(i)),d==null||d(g)}};return c.jsx("input",{...v})});function B({formatOnChange:e=Y,...t}){return c.jsx(T,{formatOnChange:e,...t,type:"text"})}const P=r.forwardRef(function({onInput:t,style:n,initialHeight:s="auto",...u},d){const y=r.useRef(null),[m,x]=r.useState(s),a=r.useCallback(()=>{const l=y.current;if(!l)return;l.style.height=s;const o=`${l.scrollHeight}px`;x(o),l.style.height=o},[s]);r.useImperativeHandle(d,()=>({element:y.current,adjustHeight:a}),[a]);const h=I(l=>{a(),t==null||t(l)});return r.useLayoutEffect(()=>{a();const l=y.current;if(!l)return;const o=new ResizeObserver(v=>{a()});return o.observe(l),()=>{o.unobserve(l)}},[a]),c.jsx("textarea",{...u,style:{overflow:"hidden",resize:"none",...n,height:m},onInput:h,ref:y})});function U(e){const t=r.useId(),n=e.name??t,s=e.valueEquals??Object.is,u=e.options??[],d=new M,y=I(m=>{const x=Number(m.target.value),a=u[x];a!=null&&e.onChange!=null&&e.onChange({value:a.value,index:x,type:"change",timeStamp:m.timeStamp,target:m.target})});return c.jsx("ul",{className:e.className,children:u.map((m,x)=>{const{value:a,text:h,key:l,itemClassName:o,labelClassName:v,inputClassName:g,textClassName:i,...p}=m,N=d.fix(m,x);return e.value!==void 0&&(p.checked=s(a,e.value)),c.jsx("li",{className:o,"aria-disabled":p.disabled,children:c.jsxs("label",{className:v,children:[c.jsx("input",{...p,className:g,value:x,onChange:y,name:n,type:"radio"}),c.jsx("span",{className:i,children:h})]})},N)})})}function K(){return r.useRef(null)}function O(e){e.current!=null&&(clearTimeout(e.current),e.current=null)}const C=({value:e,onChange:t,debounce:n=500,...s})=>{const u=K(),d=K();E(()=>{O(d),u.current!=null&&(u.current.value=e)},[e]);const y=()=>{u.current!=null&&u.current.value!==e&&(t==null||t({value:u.current.value}))};return c.jsx("input",{...s,ref:u,defaultValue:e,onInput:()=>{O(d),d.current=setTimeout(y,n)},onBlur:()=>{O(d),y()}})};function J({onClick:e,...t}){return t.onClick=n=>{n.preventDefault(),e==null||e(n)},c.jsx("button",{type:"button",...t})}function W({value:e,defaultValue:t,min:n,max:s,...u}){return e!==void 0&&(u.value=e===null?"":S(e)),t!=null&&(u.defaultValue=S(t)),n!=null&&(u.min=S(n)),s!=null&&(u.max=S(s)),c.jsx("input",{type:"datetime-local",...u})}f.ActionButton=J,f.DatetimeLocalInput=W,f.DebouncedInput=C,f.Input=T,f.RadioMenu=U,f.Select=z,f.TextArea=P,f.TextInput=B,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
1
+ (function(o,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],c):(o=typeof globalThis<"u"?globalThis:o||self,c(o["@mpen/react-basic-inputs"]={},o.jsxRuntime,o.React))})(this,function(o,c,s){"use strict";var re=Object.defineProperty;var ne=(o,c,s)=>c in o?re(o,c,{enumerable:!0,configurable:!0,writable:!0,value:s}):o[c]=s;var $=(o,c,s)=>(ne(o,typeof c!="symbol"?c+"":c,s),s);const p=Object.freeze(()=>{});function F(e){return e}let S;typeof window<"u"?S=e=>{s.useDebugValue(e);const t=s.useRef(j);s.useInsertionEffect(()=>{t.current=e},[e]);const r=s.useRef(null);return r.current||(r.current=function(){return t.current.apply(this,arguments)}),r.current}:S=p;function V(e){return S(e)}function j(){throw new Error("INVALID_USE_EVENT_INVOCATION: the callback from useEvent cannot be invoked before the component has mounted.")}function k(){var e=s.useRef(!0);return e.current?(e.current=!1,!0):e.current}var O=function(e,t){var r=k();s.useEffect(function(){if(!r)return e()},t)};function L(e,...t){return typeof e=="function"?e(...t):e}function q(e,t){if(e.uniqueKey!=null)return L(e.uniqueKey,e,t);if(typeof e.value=="string")return e.value;if(typeof e.value=="number")return String(e.value);try{const r=JSON.stringify(e.value);if(r!==void 0)return r}catch{}return String(t)}class D{constructor(){$(this,"usedKeys",new Map)}fix(t,r){let n=q(t,r);for(;;){let u=this.usedKeys.get(n);if(u===void 0){this.usedKeys.set(n,1);break}this.usedKeys.set(n,++u),n=`${n}(${u})`}return n}}const H=e=>({value:e,text:String(e),disabled:!0,key:P}),Y="3c9369b7-0a5e-46ea-93c2-e8b9fec67fdb",P="1a53f789-77f5-4ce6-a829-b00e563f1ee8";function z({options:e,value:t,invalidValueOption:r=H,onChange:n,placeholder:u,...l}){const a=t==null,i=s.useMemo(()=>t!=null&&e.some(f=>f.value==t),[e,t]),N=s.useMemo(()=>t==null||!r?null:r(t),[r,t]),d=s.useMemo(()=>{if(i)return e;const f=[...e];return a?u!=null&&f.unshift({text:u,hidden:!0,value:null,key:Y}):N&&f.push(N),f},[i,e,a,N,u]),g=V(f=>{const x=f.target.selectedIndex,E=d[x];n==null||n({value:E.value,index:x,type:"change",timeStamp:f.timeStamp,target:f.target})}),m=s.useRef(null),I=s.useCallback(()=>{m.current&&(m.current.selectedIndex<0||d[m.current.selectedIndex].value!=t)&&(m.current.selectedIndex=d.findIndex(f=>f.value==t))},[d,t]),h=f=>{m.current=f,I()};O(()=>{I()},[I]);const b=new D;return c.jsx("select",{...l,onChange:g,ref:h,children:d.map((f,x)=>{const{value:E,text:ue,uniqueKey:se,...te}=f,K=b.fix(f,x);return s.createElement("option",{...te,key:K,value:K},f.text)})})}function U(e){return e?String(e).replace(/\s+/gu," ").trim():""}function G(e){try{return e.toLocaleString("en-US",{useGrouping:!1,maximumFractionDigits:20})}catch{return e.toFixed(14).replace(/\.?0+$/,"")}}function B(e){return e?e==="∞"||e==="+∞"?Number.POSITIVE_INFINITY:e==="-∞"?Number.NEGATIVE_INFINITY:Number.parseFloat(e):Number.NaN}function _(e){return Number.isNaN(e)?"":e===Number.POSITIVE_INFINITY?"∞":e===Number.NEGATIVE_INFINITY?"-∞":G(e)}function W(e){return e?_(Number.parseFloat(e)):""}function y(e,t=2){return String(e).padStart(t,"0")}const M=s.forwardRef(function({value:t="",onPaste:r,onChange:n,onInput:u,onBlur:l,formatOnChange:a=F,...i},N){const[d,g]=s.useState(t),m=s.useRef(t),I=s.useRef(!1);O(()=>{g(t),I.current=!1,m.current=t},[t]);const h={type:"text",...i,ref:N,value:d,onChange:b=>{g(b.target.value)},onInput:b=>{I.current=!0,u==null||u(b)},onBlur:b=>{const f=a(d);I.current&&(f!==m.current&&(n==null||n({type:"change",value:f,timeStamp:b.timeStamp,target:b.target}),m.current=f),f!==b.target.value&&g(f)),l==null||l(b)}};return c.jsx("input",{...h})});function J({formatOnChange:e=U,...t}){return c.jsx(M,{formatOnChange:e,...t,type:"text"})}const C=s.forwardRef(function({onInput:t,style:r,initialHeight:n="auto",...u},l){const a=s.useRef(null),[i,N]=s.useState(n),d=s.useCallback(()=>{const m=a.current;if(!m)return;m.style.height=n;const I=`${m.scrollHeight}px`;N(I),m.style.height=I},[n]);s.useImperativeHandle(l,()=>({element:a.current,adjustHeight:d}),[d]);const g=S(m=>{d(),t==null||t(m)});return s.useLayoutEffect(()=>{d();const m=a.current;if(!m)return;const I=new ResizeObserver(h=>{d()});return I.observe(m),()=>{I.unobserve(m)}},[d]),c.jsx("textarea",{...u,style:{overflow:"hidden",resize:"none",...r,height:i},onInput:g,ref:a})});function Q(e){const t=s.useId(),r=e.name??t,n=e.valueEquals??Object.is,u=e.options??[],l=new D,a=S(i=>{const N=Number(i.target.value),d=u[N];d!=null&&e.onChange!=null&&e.onChange({value:d.value,index:N,type:"change",timeStamp:i.timeStamp,target:i.target})});return c.jsx("ul",{className:e.className,children:u.map((i,N)=>{const{value:d,text:g,key:m,itemClassName:I,labelClassName:h,inputClassName:b,textClassName:f,...x}=i,E=l.fix(i,N);return e.value!==void 0&&(x.checked=n(d,e.value)),c.jsx("li",{className:I,"aria-disabled":x.disabled,children:c.jsxs("label",{className:h,children:[c.jsx("input",{...x,className:b,value:N,onChange:a,name:r,type:"radio"}),c.jsx("span",{className:f,children:g})]})},E)})})}function A(){return s.useRef(null)}function w(e){e.current!=null&&(clearTimeout(e.current),e.current=null)}const X=({value:e,onChange:t,debounce:r=500,...n})=>{const u=A(),l=A();O(()=>{w(l),u.current!=null&&(u.current.value=e)},[e]);const a=()=>{u.current!=null&&u.current.value!==e&&(t==null||t({value:u.current.value}))};return c.jsx("input",{...n,ref:u,defaultValue:e,onInput:()=>{w(l),l.current=setTimeout(a,r)},onBlur:()=>{w(l),a()}})};function Z({onClick:e,...t}){return t.onClick=r=>{r.preventDefault(),e==null||e(r)},c.jsx("button",{type:"button",...t})}function v(e,t){const r=new Date(e);let n=`${r.getFullYear()}-${y(r.getMonth()+1)}-${y(r.getDate())}T${y(r.getHours())}:${y(r.getMinutes())}`;const u=(t==null?void 0:t.milliseconds)||(t==null?void 0:t.milliseconds)==null&&r.getMilliseconds()!==0;if(((t==null?void 0:t.seconds)||(t==null?void 0:t.seconds)==null&&(r.getSeconds()!==0||u))&&(n+=`:${y(r.getSeconds())}`,u&&(n+=`.${y(r.getMilliseconds(),3)}`)),t!=null&&t.offset){const a=-r.getTimezoneOffset(),i=a>=0?"+":"-",N=Math.floor(Math.abs(a)/60),d=Math.abs(a)%60;n+=`${i}${y(N)}:${y(d)}`}return n}const T={offset:!1};function R({value:e,defaultValue:t,min:r,max:n,onChange:u,...l}){return e!==void 0&&(l.value=e===null?"":v(e,T)),t!=null&&(l.defaultValue=v(t,T)),r!=null&&(l.min=v(r,T)),n!=null&&(l.max=v(n,T)),u!=null&&(l.onChange=a=>{if(a.currentTarget.value.length){const i=new Date(a.currentTarget.valueAsNumber);u({isoString:v(i,{offset:!0}),value:i.valueOf(),date:i})}else u({isoString:null,value:null,date:null})}),c.jsx("input",{type:"datetime-local",...l})}const ee=s.forwardRef(function({placeholder:t,formatOnChange:r=W,onChange:n,value:u,...l},a){const i={inputMode:"decimal",...l,formatOnChange:r,type:"number"};return u!==void 0&&(i.value=_(u)),t!=null&&(i.placeholder=String(t)),n!=null&&(i.onChange=N=>{n({...N,value:B(N.value)})}),c.jsx(M,{...i,ref:a})});o.ActionButton=Z,o.DatetimeLocalInput=R,o.DebouncedInput=X,o.Input=M,o.NumberInput=ee,o.RadioMenu=Q,o.Select=z,o.TextArea=C,o.TextInput=J,Object.defineProperty(o,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.2.9",
4
+ "version": "0.3.0",
5
5
  "type": "module",
6
6
  "files": ["dist"],
7
7
  "exports": {