@mpen/react-basic-inputs 0.2.10 → 0.3.1

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,40 @@ 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 function DatetimeOffsetInput({ value, defaultValue, min, max, onChange, ...props }: DatetimeOffsetInputProps): JSX_2.Element;
34
+
35
+ export declare type DatetimeOffsetInputChangeEvent = {
36
+ value: string;
37
+ };
38
+
39
+ export declare type DatetimeOffsetInputProps = {
40
+ min?: DateValue_2;
41
+ max?: DateValue_2;
42
+ value?: DateValue_2 | null;
43
+ defaultValue?: DateValue_2;
44
+ onChange?: (ev: DatetimeOffsetInputChangeEvent) => void;
45
+ };
46
+
47
+ export declare type DateValue = number | string | Date;
48
+
49
+ declare type DateValue_2 = number | string | Date;
50
+
26
51
  export declare const DebouncedInput: FC<DebouncedInputProps>;
27
52
 
28
53
  export declare type DebouncedInputChangeEvent = {
@@ -1,160 +1,155 @@
1
- var $ = Object.defineProperty;
2
- var k = (e, t, r) => t in e ? $(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var F = (e, t, r) => (k(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 g, useInsertionEffect as H, useEffect as j, useMemo as S, useCallback as _, createElement as q, forwardRef as T, useState as w, useImperativeHandle as z, useLayoutEffect as G, useId as P } from "react";
6
- const U = Object.freeze(() => {
1
+ var C = Object.defineProperty;
2
+ var q = (e, t, n) => t in e ? C(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 H, 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(() => {
7
7
  });
8
- function W(e) {
8
+ function ee(e) {
9
9
  return e;
10
10
  }
11
- let p;
12
- typeof window < "u" ? p = (e) => {
13
- Y(e);
14
- const t = g(J);
15
- H(() => {
11
+ let _;
12
+ typeof window < "u" ? _ = (e) => {
13
+ G(e);
14
+ const t = h(ne);
15
+ Z(() => {
16
16
  t.current = e;
17
17
  }, [e]);
18
- const r = g(null);
19
- return r.current || (r.current = function() {
18
+ const n = h(null);
19
+ return n.current || (n.current = function() {
20
20
  return t.current.apply(this, arguments);
21
- }), r.current;
22
- } : p = U;
23
- function B(e) {
24
- return p(e);
21
+ }), n.current;
22
+ } : _ = Q;
23
+ function te(e) {
24
+ return _(e);
25
25
  }
26
- function J() {
26
+ function ne() {
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 C() {
30
- var e = g(!0);
29
+ function ue() {
30
+ var e = h(!0);
31
31
  return e.current ? (e.current = !1, !0) : e.current;
32
32
  }
33
- var O = function(e, t) {
34
- var r = C();
35
- j(function() {
36
- if (!r)
33
+ var R = function(e, t) {
34
+ var n = ue();
35
+ H(function() {
36
+ if (!n)
37
37
  return e();
38
38
  }, t);
39
39
  };
40
- function Q(e, ...t) {
40
+ function re(e, ...t) {
41
41
  return typeof e == "function" ? e(...t) : e;
42
42
  }
43
- function X(e, t) {
43
+ function se(e, t) {
44
44
  if (e.uniqueKey != null)
45
- return Q(e.uniqueKey, e, t);
45
+ return re(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 r = JSON.stringify(e.value);
52
- if (r !== void 0)
53
- return r;
51
+ const n = JSON.stringify(e.value);
52
+ if (n !== void 0)
53
+ return n;
54
54
  } catch {
55
55
  }
56
56
  return String(t);
57
57
  }
58
- class V {
58
+ class Y {
59
59
  constructor() {
60
- F(this, "usedKeys", /* @__PURE__ */ new Map());
60
+ P(this, "_usedKeys", /* @__PURE__ */ new Map());
61
61
  }
62
- fix(t, r) {
63
- let u = X(t, r);
62
+ fix(t, n) {
63
+ let u = se(t, n);
64
64
  for (; ; ) {
65
- let n = this.usedKeys.get(u);
66
- if (n === void 0) {
67
- this.usedKeys.set(u, 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(u, ++n), u = `${u}(${n})`;
70
+ this._usedKeys.set(u, ++r), u = `${u}(${r})`;
71
71
  }
72
72
  return u;
73
73
  }
74
74
  }
75
- const Z = (e) => ({
75
+ const le = (e) => ({
76
76
  value: e,
77
77
  text: String(e),
78
78
  disabled: !0,
79
- key: te
80
- }), ee = "3c9369b7-0a5e-46ea-93c2-e8b9fec67fdb", te = "1a53f789-77f5-4ce6-a829-b00e563f1ee8";
81
- function oe({
79
+ key: ae
80
+ }), ce = "3c9369b7-0a5e-46ea-93c2-e8b9fec67fdb", ae = "1a53f789-77f5-4ce6-a829-b00e563f1ee8";
81
+ function ie({
82
82
  options: e,
83
83
  value: t,
84
- invalidValueOption: r = Z,
84
+ invalidValueOption: n = le,
85
85
  onChange: u,
86
- placeholder: n,
87
- ...a
86
+ placeholder: r,
87
+ ...s
88
88
  }) {
89
- const f = t == null, l = S(() => t != null && e.some((s) => s.value == t), [e, t]), o = S(() => t == null || !r ? null : r(t), [r, t]), c = S(() => {
90
- if (l)
89
+ const a = t == null, c = F(() => t != null && e.some((l) => l.value == t), [e, t]), o = F(() => t == null || !n ? null : n(t), [n, t]), i = F(() => {
90
+ if (c)
91
91
  return e;
92
- const s = [...e];
93
- return f ? n != null && s.unshift({ text: n, hidden: !0, value: null, key: ee }) : o && s.push(o), s;
94
- }, [l, e, f, o, n]), x = B((s) => {
95
- const I = s.target.selectedIndex, v = c[I];
92
+ const l = [...e];
93
+ return a ? r != null && l.unshift({ text: r, hidden: !0, value: null, key: ce }) : o && l.push(o), l;
94
+ }, [c, e, a, o, r]), d = te((l) => {
95
+ const g = l.target.selectedIndex, S = i[g];
96
96
  u == null || u({
97
- value: v.value,
97
+ value: S.value,
98
98
  // option: opt,
99
99
  // event: ev,
100
- index: I,
100
+ index: g,
101
101
  type: "change",
102
- timeStamp: s.timeStamp,
103
- target: s.target
102
+ timeStamp: l.timeStamp,
103
+ target: l.target
104
104
  });
105
- }), i = g(null), d = _(() => {
106
- i.current && (i.current.selectedIndex < 0 || c[i.current.selectedIndex].value != t) && (i.current.selectedIndex = c.findIndex((s) => s.value == t));
107
- }, [c, t]), b = (s) => {
108
- i.current = s, d();
105
+ }), f = h(null), m = T(() => {
106
+ f.current && (f.current.selectedIndex < 0 || i[f.current.selectedIndex].value != t) && (f.current.selectedIndex = i.findIndex((l) => l.value == t));
107
+ }, [i, t]), N = (l) => {
108
+ f.current = l, m();
109
109
  };
110
- O(() => {
111
- d();
112
- }, [d]);
113
- const m = new V();
114
- return /* @__PURE__ */ N("select", { ...a, onChange: x, ref: b, children: c.map((s, I) => {
115
- const { value: v, text: ie, uniqueKey: ce, ...R } = s, K = m.fix(s, I);
116
- return /* @__PURE__ */ q("option", { ...R, key: K, value: K }, s.text);
110
+ R(() => {
111
+ m();
112
+ }, [m]);
113
+ const x = new Y();
114
+ return /* @__PURE__ */ v("select", { ...s, onChange: d, ref: N, children: i.map((l, g) => {
115
+ const { value: S, text: b, uniqueKey: O, ...y } = l, V = x.fix(l, g);
116
+ return /* @__PURE__ */ W("option", { ...y, key: V, value: V }, l.text);
117
117
  }) });
118
118
  }
119
- function re(e) {
119
+ function fe(e) {
120
120
  return e ? String(e).replace(/\s+/gu, " ").trim() : "";
121
121
  }
122
- function ne(e) {
122
+ function oe(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 ue(e) {
129
+ function de(e) {
130
130
  return e ? e === "∞" || e === "+∞" ? Number.POSITIVE_INFINITY : e === "-∞" ? Number.NEGATIVE_INFINITY : Number.parseFloat(e) : Number.NaN;
131
131
  }
132
- function D(e) {
133
- return Number.isNaN(e) ? "" : e === Number.POSITIVE_INFINITY ? "∞" : e === Number.NEGATIVE_INFINITY ? "-∞" : ne(e);
132
+ function j(e) {
133
+ return Number.isNaN(e) ? "" : e === Number.POSITIVE_INFINITY ? "∞" : e === Number.NEGATIVE_INFINITY ? "-∞" : oe(e);
134
134
  }
135
- function se(e) {
136
- return e ? D(Number.parseFloat(e)) : "";
135
+ function me(e) {
136
+ return e ? j(Number.parseFloat(e)) : "";
137
137
  }
138
- function y(e, t = 2) {
138
+ function I(e, t = 2) {
139
139
  return String(e).padStart(t, "0");
140
140
  }
141
- function h(e) {
142
- const t = new Date(e);
143
- let r = `${t.getFullYear()}-${y(t.getMonth() + 1)}-${y(t.getDate())}T${y(t.getHours())}:${y(t.getMinutes())}`;
144
- return (t.getSeconds() !== 0 || t.getMilliseconds() !== 0) && (r += ":" + y(t.getSeconds()), t.getMilliseconds() !== 0 && (r += "." + y(t.getMilliseconds(), 3))), r;
145
- }
146
- const A = T(function({ value: t = "", onPaste: r, onChange: u, onInput: n, onBlur: a, formatOnChange: f = W, ...l }, o) {
147
- const [c, x] = w(t), i = g(t), d = g(!1);
148
- O(() => {
149
- x(t), d.current = !1, i.current = t;
141
+ const z = k(function({ value: t = "", onPaste: n, onChange: u, onInput: r, onBlur: s, formatOnChange: a = ee, ...c }, o) {
142
+ const [i, d] = D(t), f = h(t), m = h(!1);
143
+ R(() => {
144
+ d(t), m.current = !1, f.current = t;
150
145
  }, [t]);
151
- const b = {
146
+ const N = {
152
147
  type: "text",
153
- ...l,
148
+ ...c,
154
149
  ref: o,
155
- value: c,
156
- onChange: (m) => {
157
- x(m.target.value);
150
+ value: i,
151
+ onChange: (x) => {
152
+ d(x.target.value);
158
153
  },
159
154
  // TODO: fire a change event onPaste ?
160
155
  // formatOnPaste?
@@ -172,138 +167,353 @@ const A = T(function({ value: t = "", onPaste: r, onChange: u, onInput: n, onBlu
172
167
  // // ev.preventDefault()
173
168
  // // setCurrentValue(formatOnChange(ev.clipboardData.getData('text/plain')))
174
169
  // },
175
- onInput: (m) => {
176
- d.current = !0, n == null || n(m);
170
+ onInput: (x) => {
171
+ m.current = !0, r == null || r(x);
177
172
  },
178
- onBlur: (m) => {
179
- const s = f(c);
180
- d.current && (s !== i.current && (u == null || u({
173
+ onBlur: (x) => {
174
+ const l = a(i);
175
+ m.current && (l !== f.current && (u == null || u({
181
176
  type: "change",
182
- value: s,
183
- timeStamp: m.timeStamp,
184
- target: m.target
185
- }), i.current = s), s !== m.target.value && x(s)), a == null || a(m);
177
+ value: l,
178
+ timeStamp: x.timeStamp,
179
+ target: x.target
180
+ }), f.current = l), l !== x.target.value && d(l)), s == null || s(x);
186
181
  }
187
182
  };
188
- return /* @__PURE__ */ N("input", { ...b });
183
+ return /* @__PURE__ */ v("input", { ...N });
189
184
  });
190
- function de({ formatOnChange: e = re, ...t }) {
191
- return /* @__PURE__ */ N(A, { formatOnChange: e, ...t, type: "text" });
185
+ function Se({ formatOnChange: e = fe, ...t }) {
186
+ return /* @__PURE__ */ v(z, { formatOnChange: e, ...t, type: "text" });
192
187
  }
193
- const me = T(function({
188
+ const Oe = k(function({
194
189
  onInput: t,
195
- style: r,
190
+ style: n,
196
191
  initialHeight: u = "auto",
197
- ...n
198
- }, a) {
199
- const f = g(null), [l, o] = w(u), c = _(() => {
200
- const i = f.current;
201
- if (!i)
192
+ ...r
193
+ }, s) {
194
+ const a = h(null), [c, o] = D(u), i = T(() => {
195
+ const f = a.current;
196
+ if (!f)
202
197
  return;
203
- i.style.height = u;
204
- const d = `${i.scrollHeight}px`;
205
- o(d), i.style.height = d;
198
+ f.style.height = u;
199
+ const m = `${f.scrollHeight}px`;
200
+ o(m), f.style.height = m;
206
201
  }, [u]);
207
- z(a, () => ({
208
- element: f.current,
209
- adjustHeight: c
210
- }), [c]);
211
- const x = p((i) => {
212
- c(), t == null || t(i);
202
+ B(s, () => ({
203
+ element: a.current,
204
+ adjustHeight: i
205
+ }), [i]);
206
+ const d = _((f) => {
207
+ i(), t == null || t(f);
213
208
  });
214
- return G(() => {
215
- c();
216
- const i = f.current;
217
- if (!i)
209
+ return J(() => {
210
+ i();
211
+ const f = a.current;
212
+ if (!f)
218
213
  return;
219
- const d = new ResizeObserver((b) => {
220
- c();
214
+ const m = new ResizeObserver((N) => {
215
+ i();
221
216
  });
222
- return d.observe(i), () => {
223
- d.unobserve(i);
217
+ return m.observe(f), () => {
218
+ m.unobserve(f);
224
219
  };
225
- }, [c]), /* @__PURE__ */ N("textarea", { ...n, style: {
220
+ }, [i]), /* @__PURE__ */ v("textarea", { ...r, style: {
226
221
  overflow: "hidden",
227
222
  // these 2 styles aren't needed if the caller sets them in CSS.
228
223
  resize: "none",
229
- ...r,
230
- height: l
231
- }, onInput: x, ref: f });
224
+ ...n,
225
+ height: c
226
+ }, onInput: d, ref: a });
232
227
  });
233
- function Ne(e) {
234
- const t = P(), r = e.name ?? t, u = e.valueEquals ?? Object.is, n = e.options ?? [], a = new V(), f = p((l) => {
235
- const o = Number(l.target.value), c = n[o];
236
- c != null && e.onChange != null && e.onChange({
237
- value: c.value,
228
+ function Ee(e) {
229
+ const t = X(), n = e.name ?? t, u = e.valueEquals ?? Object.is, r = e.options ?? [], s = new Y(), a = _((c) => {
230
+ const o = Number(c.target.value), i = r[o];
231
+ i != null && e.onChange != null && e.onChange({
232
+ value: i.value,
238
233
  index: o,
239
234
  type: "change",
240
- timeStamp: l.timeStamp,
241
- target: l.target
235
+ timeStamp: c.timeStamp,
236
+ target: c.target
242
237
  });
243
238
  });
244
- return /* @__PURE__ */ N("ul", { className: e.className, children: n.map((l, o) => {
245
- const { value: c, text: x, key: i, itemClassName: d, labelClassName: b, inputClassName: m, textClassName: s, ...I } = l, v = a.fix(l, o);
246
- return e.value !== void 0 && (I.checked = u(c, e.value)), /* @__PURE__ */ N("li", { className: d, "aria-disabled": I.disabled, children: /* @__PURE__ */ L("label", { className: b, children: [
247
- /* @__PURE__ */ N("input", { ...I, className: m, value: o, onChange: f, name: r, type: "radio" }),
248
- /* @__PURE__ */ N("span", { className: s, children: x })
249
- ] }) }, v);
239
+ return /* @__PURE__ */ v("ul", { className: e.className, children: r.map((c, o) => {
240
+ const { value: i, text: d, key: f, itemClassName: m, labelClassName: N, inputClassName: x, textClassName: l, ...g } = c, S = s.fix(c, o);
241
+ return e.value !== void 0 && (g.checked = u(i, e.value)), /* @__PURE__ */ v("li", { className: m, "aria-disabled": g.disabled, children: /* @__PURE__ */ L("label", { className: N, children: [
242
+ /* @__PURE__ */ v("input", { ...g, className: x, value: o, onChange: a, name: n, type: "radio" }),
243
+ /* @__PURE__ */ v("span", { className: l, children: d })
244
+ ] }) }, S);
250
245
  }) });
251
246
  }
252
- function M() {
253
- return g(null);
247
+ function U() {
248
+ return h(null);
254
249
  }
255
- function E(e) {
250
+ function A(e) {
256
251
  e.current != null && (clearTimeout(e.current), e.current = null);
257
252
  }
258
- const xe = ({
253
+ const De = ({
259
254
  value: e,
260
255
  onChange: t,
261
- debounce: r = 500,
256
+ debounce: n = 500,
262
257
  ...u
263
258
  }) => {
264
- const n = M(), a = M();
265
- O(() => {
266
- E(a), n.current != null && (n.current.value = e);
259
+ const r = U(), s = U();
260
+ R(() => {
261
+ A(s), r.current != null && (r.current.value = e);
267
262
  }, [e]);
268
- const f = () => {
269
- n.current != null && n.current.value !== e && (t == null || t({ value: n.current.value }));
263
+ const a = () => {
264
+ r.current != null && r.current.value !== e && (t == null || t({ value: r.current.value }));
270
265
  };
271
- return /* @__PURE__ */ N("input", { ...u, ref: n, defaultValue: e, onInput: () => {
272
- E(a), a.current = setTimeout(f, r);
266
+ return /* @__PURE__ */ v("input", { ...u, ref: r, defaultValue: e, onInput: () => {
267
+ A(s), s.current = setTimeout(a, n);
273
268
  }, onBlur: () => {
274
- E(a), f();
269
+ A(s), a();
275
270
  } });
276
271
  };
277
- function Ie({ onClick: e, ...t }) {
278
- return t.onClick = (r) => {
279
- r.preventDefault(), e == null || e(r);
280
- }, /* @__PURE__ */ N("button", { type: "button", ...t });
272
+ function _e({ onClick: e, ...t }) {
273
+ return t.onClick = (n) => {
274
+ n.preventDefault(), e == null || e(n);
275
+ }, /* @__PURE__ */ v("button", { type: "button", ...t });
276
+ }
277
+ function E(e, t) {
278
+ const n = e instanceof Date ? e : new Date(e);
279
+ let u = `${n.getFullYear()}-${I(n.getMonth() + 1)}-${I(n.getDate())}T${I(n.getHours())}:${I(n.getMinutes())}`;
280
+ const r = (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 || r)) && (u += `:${I(n.getSeconds())}`, r && (u += `.${I(n.getMilliseconds(), 3)}`)), t != null && t.offset && (u += p(-n.getTimezoneOffset())), u;
282
+ }
283
+ function p(e) {
284
+ if (e == null)
285
+ return "";
286
+ if (e === 0)
287
+ return "Z";
288
+ const t = e > 0 ? "+" : "-", n = Math.floor(Math.abs(e) / 60), u = Math.abs(e) % 60;
289
+ return `${t}${I(n)}:${I(u)}`;
290
+ }
291
+ const xe = /^(\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) {
293
+ return e == null || Number.isNaN(e) || e === "" || Number.isNaN(+new Date(e));
294
+ }
295
+ function M(e) {
296
+ if (typeof e == "string") {
297
+ const t = e.match(xe);
298
+ if (t)
299
+ return t[1];
300
+ }
301
+ return Ne(e) ? "" : E(e, ve);
302
+ }
303
+ const w = { offset: !1 };
304
+ function Me({ value: e, defaultValue: t, min: n, max: u, onChange: r, ...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)), u != null && (s.max = E(u, w)), r != null && (s.onChange = (a) => {
306
+ if (a.currentTarget.value.length) {
307
+ const c = new Date(a.currentTarget.valueAsNumber);
308
+ r({
309
+ // TODO: undo this, "date time local" should in fact be local (no time zone)
310
+ isoString: E(c, { offset: !0 }),
311
+ // isoString: date.toISOString(),
312
+ value: c.valueOf(),
313
+ date: c
314
+ });
315
+ } else
316
+ r({
317
+ // isoStringWithOffset: null,
318
+ isoString: null,
319
+ value: null,
320
+ date: null
321
+ });
322
+ }), /* @__PURE__ */ v("input", { type: "datetime-local", ...s });
281
323
  }
282
- function ge({ value: e, defaultValue: t, min: r, max: u, ...n }) {
283
- return e !== void 0 && (n.value = e === null ? "" : h(e)), t != null && (n.defaultValue = h(t)), r != null && (n.min = h(r)), u != null && (n.max = h(u)), /* @__PURE__ */ N("input", { type: "datetime-local", ...n });
324
+ function ge(e) {
325
+ const t = h(e);
326
+ return t.current = e, t;
327
+ }
328
+ function be(e, t) {
329
+ const n = h(e), u = ge(t);
330
+ return H(() => {
331
+ Object.is(n.current, e) || (u.current(), n.current = e);
332
+ }, [u, e]), T((r) => {
333
+ n.current = r;
334
+ }, []);
335
+ }
336
+ const he = [
337
+ // United States Minor Outlying Islands
338
+ { value: -12 * 60, text: "-12:00" },
339
+ // New Zealand, United States
340
+ { value: -11 * 60, text: "-11:00" },
341
+ // United States, French Polynesia, New Zealand
342
+ { value: -10 * 60, text: "-10:00" },
343
+ // France (Marquesas Islands)
344
+ { value: -9.5 * 60, text: "-09:30" },
345
+ // United States, Canada, Mexico
346
+ { value: -9 * 60, text: "-09:00" },
347
+ // United States, Canada, Mexico, UK (Pitcairn Islands)
348
+ { value: -8 * 60, text: "-08:00" },
349
+ // United States, Canada, Mexico
350
+ { value: -7 * 60, text: "-07:00" },
351
+ // United States, Canada, Mexico, Central America
352
+ { value: -6 * 60, text: "-06:00" },
353
+ // United States, Canada, Cuba, South America
354
+ { value: -5 * 60, text: "-05:00" },
355
+ // Canada, Caribbean, South America
356
+ { value: -4 * 60, text: "-04:00" },
357
+ // Canada (Newfoundland)
358
+ { value: -3.5 * 60, text: "-03:30" },
359
+ // Argentina, Brazil, Chile
360
+ { value: -3 * 60, text: "-03:00" },
361
+ // Brazil (Fernando de Noronha), South Georgia
362
+ { value: -2 * 60, text: "-02:00" },
363
+ // Cape Verde
364
+ { value: -1 * 60, text: "-01:00" },
365
+ // UK, Portugal, Iceland
366
+ { value: 0, text: "±00:00" },
367
+ // Central Europe
368
+ { value: 1 * 60, text: "+01:00" },
369
+ // Eastern Europe, Egypt
370
+ { value: 2 * 60, text: "+02:00" },
371
+ // East Africa, Middle East
372
+ { value: 3 * 60, text: "+03:00" },
373
+ // Iran
374
+ { value: 3.5 * 60, text: "+03:30" },
375
+ // UAE, Russia (Moscow)
376
+ { value: 4 * 60, text: "+04:00" },
377
+ // Afghanistan
378
+ { value: 4.5 * 60, text: "+04:30" },
379
+ // Pakistan
380
+ { value: 5 * 60, text: "+05:00" },
381
+ // India, Sri Lanka
382
+ { value: 5.5 * 60, text: "+05:30" },
383
+ // Nepal
384
+ { value: 5.75 * 60, text: "+05:45" },
385
+ // Bangladesh, Bhutan
386
+ { value: 6 * 60, text: "+06:00" },
387
+ // Myanmar
388
+ { value: 6.5 * 60, text: "+06:30" },
389
+ // Thailand, Vietnam
390
+ { value: 7 * 60, text: "+07:00" },
391
+ // China, Singapore
392
+ { value: 8 * 60, text: "+08:00" },
393
+ // Australia (Western)
394
+ { value: 8.75 * 60, text: "+08:45" },
395
+ // Japan, South Korea
396
+ { value: 9 * 60, text: "+09:00" },
397
+ // Australia (Central)
398
+ { value: 9.5 * 60, text: "+09:30" },
399
+ // Australia (Eastern)
400
+ { value: 10 * 60, text: "+10:00" },
401
+ // Australia (Lord Howe Island)
402
+ { value: 10.5 * 60, text: "+10:30" },
403
+ // Solomon Islands, Vanuatu
404
+ { value: 11 * 60, text: "+11:00" },
405
+ // Fiji, New Zealand
406
+ { value: 12 * 60, text: "+12:00" },
407
+ // New Zealand (Chatham Islands)
408
+ { value: 12.75 * 60, text: "+12:45" },
409
+ // Tonga, Samoa
410
+ { value: 13 * 60, text: "+13:00" },
411
+ // Kiribati
412
+ { value: 14 * 60, text: "+14:00" }
413
+ ];
414
+ function $(e) {
415
+ if (typeof e != "string" || e === "")
416
+ return null;
417
+ const t = e.match(/([+-])(\d{2}):(\d{2})|Z$/);
418
+ if (!t)
419
+ return null;
420
+ if (t[0] === "Z")
421
+ return 0;
422
+ const [, n, u, r] = t, s = Number(u) * 60 + Number(r);
423
+ return n === "+" ? s : -s;
424
+ }
425
+ function K(e) {
426
+ return e === "" ? null : -new Date(e).getTimezoneOffset();
427
+ }
428
+ function we({
429
+ value: e,
430
+ defaultValue: t,
431
+ min: n,
432
+ max: u,
433
+ onChange: r,
434
+ ...s
435
+ }) {
436
+ const [a, c] = D(() => $(e ?? t) !== null), [o, i] = D(() => $(e ?? t)), [d, f] = D(() => M(e ?? t)), m = be(e, () => {
437
+ c($(e) !== null), i($(e)), f(M(e));
438
+ }), N = T((b) => {
439
+ m(b), r == null || r({
440
+ value: b
441
+ });
442
+ }, [r, m]);
443
+ n != null && (s.min = M(n)), u != null && (s.max = M(u));
444
+ const x = a ? o : K(d), l = T(
445
+ (b) => {
446
+ const O = b.currentTarget.value;
447
+ f(O), N(O + p(x));
448
+ },
449
+ [N, x]
450
+ ), g = T(
451
+ (b) => {
452
+ i(b.value), N(d + p(b.value));
453
+ },
454
+ [N, d]
455
+ ), S = T(
456
+ (b) => {
457
+ const O = b.currentTarget.checked;
458
+ c(O);
459
+ let y;
460
+ O ? d && o === null ? (y = K(d), i(y)) : y = o : y = K(d), N(d + p(y));
461
+ },
462
+ [o, d, N]
463
+ );
464
+ return /* @__PURE__ */ L("span", { children: [
465
+ /* @__PURE__ */ v(
466
+ "input",
467
+ {
468
+ type: "datetime-local",
469
+ ...s,
470
+ value: d,
471
+ onChange: l
472
+ }
473
+ ),
474
+ /* @__PURE__ */ v(
475
+ "input",
476
+ {
477
+ type: "checkbox",
478
+ title: a ? "Use UTC offset from this device" : "Enable UTC offset selection",
479
+ checked: a,
480
+ onChange: S
481
+ }
482
+ ),
483
+ /* @__PURE__ */ v(
484
+ ie,
485
+ {
486
+ value: x,
487
+ onChange: g,
488
+ disabled: !a,
489
+ options: he
490
+ }
491
+ )
492
+ ] });
284
493
  }
285
- const be = T(function({ placeholder: t, formatOnChange: r = se, onChange: u, value: n, ...a }, f) {
286
- const l = {
494
+ const $e = k(function({ placeholder: t, formatOnChange: n = me, onChange: u, value: r, ...s }, a) {
495
+ const c = {
287
496
  inputMode: "decimal",
288
- ...a,
289
- formatOnChange: r,
497
+ ...s,
498
+ formatOnChange: n,
290
499
  type: "number"
291
500
  };
292
- return n !== void 0 && (l.value = D(n)), t != null && (l.placeholder = String(t)), u != null && (l.onChange = (o) => {
501
+ return r !== void 0 && (c.value = j(r)), t != null && (c.placeholder = String(t)), u != null && (c.onChange = (o) => {
293
502
  u({
294
503
  ...o,
295
- value: ue(o.value)
504
+ value: de(o.value)
296
505
  });
297
- }), /* @__PURE__ */ N(A, { ...l, ref: f });
506
+ }), /* @__PURE__ */ v(z, { ...c, ref: a });
298
507
  });
299
508
  export {
300
- Ie as ActionButton,
301
- ge as DatetimeLocalInput,
302
- xe as DebouncedInput,
303
- A as Input,
304
- be as NumberInput,
305
- Ne as RadioMenu,
306
- oe as Select,
307
- me as TextArea,
308
- de as TextInput
509
+ _e as ActionButton,
510
+ Me as DatetimeLocalInput,
511
+ we as DatetimeOffsetInput,
512
+ De as DebouncedInput,
513
+ z as Input,
514
+ $e as NumberInput,
515
+ Ee as RadioMenu,
516
+ ie as Select,
517
+ Oe as TextArea,
518
+ Se as TextInput
309
519
  };
@@ -1 +1 @@
1
- (function(f,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],i):(f=typeof globalThis<"u"?globalThis:f||self,i(f["@mpen/react-basic-inputs"]={},f.jsxRuntime,f.React))})(this,function(f,i,u){"use strict";var te=Object.defineProperty;var ne=(f,i,u)=>i in f?te(f,i,{enumerable:!0,configurable:!0,writable:!0,value:u}):f[i]=u;var F=(f,i,u)=>(ne(f,typeof i!="symbol"?i+"":i,u),u);const _=Object.freeze(()=>{});function A(e){return e}let h;typeof window<"u"?h=e=>{u.useDebugValue(e);const t=u.useRef(j);u.useInsertionEffect(()=>{t.current=e},[e]);const n=u.useRef(null);return n.current||(n.current=function(){return t.current.apply(this,arguments)}),n.current}:h=_;function V(e){return h(e)}function j(){throw new Error("INVALID_USE_EVENT_INVOCATION: the callback from useEvent cannot be invoked before the component has mounted.")}function $(){var e=u.useRef(!0);return e.current?(e.current=!1,!0):e.current}var T=function(e,t){var n=$();u.useEffect(function(){if(!n)return e()},t)};function k(e,...t){return typeof e=="function"?e(...t):e}function L(e,t){if(e.uniqueKey!=null)return k(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(){F(this,"usedKeys",new Map)}fix(t,n){let s=L(t,n);for(;;){let r=this.usedKeys.get(s);if(r===void 0){this.usedKeys.set(s,1);break}this.usedKeys.set(s,++r),s=`${s}(${r})`}return s}}const q=e=>({value:e,text:String(e),disabled:!0,key:H}),Y="3c9369b7-0a5e-46ea-93c2-e8b9fec67fdb",H="1a53f789-77f5-4ce6-a829-b00e563f1ee8";function z({options:e,value:t,invalidValueOption:n=q,onChange:s,placeholder:r,...d}){const m=t==null,a=u.useMemo(()=>t!=null&&e.some(c=>c.value==t),[e,t]),N=u.useMemo(()=>t==null||!n?null:n(t),[n,t]),o=u.useMemo(()=>{if(a)return e;const c=[...e];return m?r!=null&&c.unshift({text:r,hidden:!0,value:null,key:Y}):N&&c.push(N),c},[a,e,m,N,r]),y=V(c=>{const g=c.target.selectedIndex,v=o[g];s==null||s({value:v.value,index:g,type:"change",timeStamp:c.timeStamp,target:c.target})}),l=u.useRef(null),I=u.useCallback(()=>{l.current&&(l.current.selectedIndex<0||o[l.current.selectedIndex].value!=t)&&(l.current.selectedIndex=o.findIndex(c=>c.value==t))},[o,t]),x=c=>{l.current=c,I()};T(()=>{I()},[I]);const b=new M;return i.jsx("select",{...d,onChange:y,ref:x,children:o.map((c,g)=>{const{value:v,text:re,uniqueKey:ue,...ee}=c,D=b.fix(c,g);return u.createElement("option",{...ee,key:D,value:D},c.text)})})}function P(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 U(e){return e?e==="∞"||e==="+∞"?Number.POSITIVE_INFINITY:e==="-∞"?Number.NEGATIVE_INFINITY:Number.parseFloat(e):Number.NaN}function w(e){return Number.isNaN(e)?"":e===Number.POSITIVE_INFINITY?"∞":e===Number.NEGATIVE_INFINITY?"-∞":G(e)}function B(e){return e?w(Number.parseFloat(e)):""}function p(e,t=2){return String(e).padStart(t,"0")}function S(e){const t=new Date(e);let n=`${t.getFullYear()}-${p(t.getMonth()+1)}-${p(t.getDate())}T${p(t.getHours())}:${p(t.getMinutes())}`;return(t.getSeconds()!==0||t.getMilliseconds()!==0)&&(n+=":"+p(t.getSeconds()),t.getMilliseconds()!==0&&(n+="."+p(t.getMilliseconds(),3))),n}const E=u.forwardRef(function({value:t="",onPaste:n,onChange:s,onInput:r,onBlur:d,formatOnChange:m=A,...a},N){const[o,y]=u.useState(t),l=u.useRef(t),I=u.useRef(!1);T(()=>{y(t),I.current=!1,l.current=t},[t]);const x={type:"text",...a,ref:N,value:o,onChange:b=>{y(b.target.value)},onInput:b=>{I.current=!0,r==null||r(b)},onBlur:b=>{const c=m(o);I.current&&(c!==l.current&&(s==null||s({type:"change",value:c,timeStamp:b.timeStamp,target:b.target}),l.current=c),c!==b.target.value&&y(c)),d==null||d(b)}};return i.jsx("input",{...x})});function W({formatOnChange:e=P,...t}){return i.jsx(E,{formatOnChange:e,...t,type:"text"})}const C=u.forwardRef(function({onInput:t,style:n,initialHeight:s="auto",...r},d){const m=u.useRef(null),[a,N]=u.useState(s),o=u.useCallback(()=>{const l=m.current;if(!l)return;l.style.height=s;const I=`${l.scrollHeight}px`;N(I),l.style.height=I},[s]);u.useImperativeHandle(d,()=>({element:m.current,adjustHeight:o}),[o]);const y=h(l=>{o(),t==null||t(l)});return u.useLayoutEffect(()=>{o();const l=m.current;if(!l)return;const I=new ResizeObserver(x=>{o()});return I.observe(l),()=>{I.unobserve(l)}},[o]),i.jsx("textarea",{...r,style:{overflow:"hidden",resize:"none",...n,height:a},onInput:y,ref:m})});function J(e){const t=u.useId(),n=e.name??t,s=e.valueEquals??Object.is,r=e.options??[],d=new M,m=h(a=>{const N=Number(a.target.value),o=r[N];o!=null&&e.onChange!=null&&e.onChange({value:o.value,index:N,type:"change",timeStamp:a.timeStamp,target:a.target})});return i.jsx("ul",{className:e.className,children:r.map((a,N)=>{const{value:o,text:y,key:l,itemClassName:I,labelClassName:x,inputClassName:b,textClassName:c,...g}=a,v=d.fix(a,N);return e.value!==void 0&&(g.checked=s(o,e.value)),i.jsx("li",{className:I,"aria-disabled":g.disabled,children:i.jsxs("label",{className:x,children:[i.jsx("input",{...g,className:b,value:N,onChange:m,name:n,type:"radio"}),i.jsx("span",{className:c,children:y})]})},v)})})}function K(){return u.useRef(null)}function O(e){e.current!=null&&(clearTimeout(e.current),e.current=null)}const Q=({value:e,onChange:t,debounce:n=500,...s})=>{const r=K(),d=K();T(()=>{O(d),r.current!=null&&(r.current.value=e)},[e]);const m=()=>{r.current!=null&&r.current.value!==e&&(t==null||t({value:r.current.value}))};return i.jsx("input",{...s,ref:r,defaultValue:e,onInput:()=>{O(d),d.current=setTimeout(m,n)},onBlur:()=>{O(d),m()}})};function X({onClick:e,...t}){return t.onClick=n=>{n.preventDefault(),e==null||e(n)},i.jsx("button",{type:"button",...t})}function Z({value:e,defaultValue:t,min:n,max:s,...r}){return e!==void 0&&(r.value=e===null?"":S(e)),t!=null&&(r.defaultValue=S(t)),n!=null&&(r.min=S(n)),s!=null&&(r.max=S(s)),i.jsx("input",{type:"datetime-local",...r})}const R=u.forwardRef(function({placeholder:t,formatOnChange:n=B,onChange:s,value:r,...d},m){const a={inputMode:"decimal",...d,formatOnChange:n,type:"number"};return r!==void 0&&(a.value=w(r)),t!=null&&(a.placeholder=String(t)),s!=null&&(a.onChange=N=>{s({...N,value:U(N.value)})}),i.jsx(E,{...a,ref:m})});f.ActionButton=X,f.DatetimeLocalInput=Z,f.DebouncedInput=Q,f.Input=E,f.NumberInput=R,f.RadioMenu=J,f.Select=z,f.TextArea=C,f.TextInput=W,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
1
+ (function(x,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):(x=typeof globalThis<"u"?globalThis:x||self,f(x["@mpen/react-basic-inputs"]={},x.jsxRuntime,x.React))})(this,function(x,f,r){"use strict";var ve=Object.defineProperty;var be=(x,f,r)=>f in x?ve(x,f,{enumerable:!0,configurable:!0,writable:!0,value:r}):x[f]=r;var L=(x,f,r)=>(be(x,typeof f!="symbol"?f+"":f,r),r);const U=Object.freeze(()=>{});function q(e){return e}let D;typeof window<"u"?D=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}:D=U;function H(e){return D(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 a=t==null,i=r.useMemo(()=>t!=null&&e.some(c=>c.value==t),[e,t]),m=r.useMemo(()=>t==null||!n?null:n(t),[n,t]),o=r.useMemo(()=>{if(i)return e;const c=[...e];return a?s!=null&&c.unshift({text:s,hidden:!0,value:null,key:W}):m&&c.push(m),c},[i,e,a,m,s]),v=H(c=>{const g=c.target.selectedIndex,O=o[g];u==null||u({value:O.value,index:g,type:"change",timeStamp:c.timeStamp,target:c.target})}),d=r.useRef(null),b=r.useCallback(()=>{d.current&&(d.current.selectedIndex<0||o[d.current.selectedIndex].value!=t)&&(d.current.selectedIndex=o.findIndex(c=>c.value==t))},[o,t]),I=c=>{d.current=c,b()};p(()=>{b()},[b]);const N=new K;return f.jsx("select",{...l,onChange:v,ref:I,children:o.map((c,g)=>{const{value:O,text:h,uniqueKey:E,...T}=c,P=N.fix(c,g);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:a=q,...i},m){const[o,v]=r.useState(t),d=r.useRef(t),b=r.useRef(!1);p(()=>{v(t),b.current=!1,d.current=t},[t]);const I={type:"text",...i,ref:m,value:o,onChange:N=>{v(N.target.value)},onInput:N=>{b.current=!0,s==null||s(N)},onBlur:N=>{const c=a(o);b.current&&(c!==d.current&&(u==null||u({type:"change",value:c,timeStamp:N.timeStamp,target:N.target}),d.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 a=r.useRef(null),[i,m]=r.useState(u),o=r.useCallback(()=>{const d=a.current;if(!d)return;d.style.height=u;const b=`${d.scrollHeight}px`;m(b),d.style.height=b},[u]);r.useImperativeHandle(l,()=>({element:a.current,adjustHeight:o}),[o]);const v=D(d=>{o(),t==null||t(d)});return r.useLayoutEffect(()=>{o();const d=a.current;if(!d)return;const b=new ResizeObserver(I=>{o()});return b.observe(d),()=>{b.unobserve(d)}},[o]),f.jsx("textarea",{...s,style:{overflow:"hidden",resize:"none",...n,height:i},onInput:v,ref:a})});function ue(e){const t=r.useId(),n=e.name??t,u=e.valueEquals??Object.is,s=e.options??[],l=new K,a=D(i=>{const m=Number(i.target.value),o=s[m];o!=null&&e.onChange!=null&&e.onChange({value:o.value,index:m,type:"change",timeStamp:i.timeStamp,target:i.target})});return f.jsx("ul",{className:e.className,children:s.map((i,m)=>{const{value:o,text:v,key:d,itemClassName:b,labelClassName:I,inputClassName:N,textClassName:c,...g}=i,O=l.fix(i,m);return e.value!==void 0&&(g.checked=u(o,e.value)),f.jsx("li",{className:b,"aria-disabled":g.disabled,children:f.jsxs("label",{className:I,children:[f.jsx("input",{...g,className:N,value:m,onChange:a,name:n,type:"radio"}),f.jsx("span",{className:c,children:v})]})},O)})})}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 a=()=>{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(a,n)},onBlur:()=>{A(l),a()}})};function se({onClick:e,...t}){return t.onClick=n=>{n.preventDefault(),e==null||e(n)},f.jsx("button",{type:"button",...t})}function S(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)?"":S(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?"":S(e,w)),t!=null&&(l.defaultValue=S(t,w)),n!=null&&(l.min=S(n,w)),u!=null&&(l.max=S(u,w)),s!=null&&(l.onChange=a=>{if(a.currentTarget.value.length){const i=new Date(a.currentTarget.valueAsNumber);s({isoString:S(i,{offset:!0}),value:i.valueOf(),date:i})}else s({isoString:null,value:null,date:null})}),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[a,i]=r.useState(()=>k(e??t)!==null),[m,o]=r.useState(()=>k(e??t)),[v,d]=r.useState(()=>_(e??t)),b=oe(e,()=>{i(k(e)!==null),o(k(e)),d(_(e))}),I=r.useCallback(h=>{b(h),s==null||s({value:h})},[s,b]);n!=null&&(l.min=_(n)),u!=null&&(l.max=_(u));const N=a?m:F(v),c=r.useCallback(h=>{const E=h.currentTarget.value;d(E),I(E+M(N))},[I,N]),g=r.useCallback(h=>{o(h.value),I(v+M(h.value))},[I,v]),O=r.useCallback(h=>{const E=h.currentTarget.checked;i(E);let T;E?v&&m===null?(T=F(v),o(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:a?"Use UTC offset from this device":"Enable UTC offset selection",checked:a,onChange:O}),f.jsx(C,{value:N,onChange:g,disabled:!a,options:de})]})}const me=r.forwardRef(function({placeholder:t,formatOnChange:n=ee,onChange:u,value:s,...l},a){const i={inputMode:"decimal",...l,formatOnChange:n,type:"number"};return s!==void 0&&(i.value=V(s)),t!=null&&(i.placeholder=String(t)),u!=null&&(i.onChange=m=>{u({...m,value:R(m.value)})}),f.jsx($,{...i,ref:a})});x.ActionButton=se,x.DatetimeLocalInput=ie,x.DatetimeOffsetInput=xe,x.DebouncedInput=re,x.Input=$,x.NumberInput=me,x.RadioMenu=ue,x.Select=C,x.TextArea=ne,x.TextInput=te,Object.defineProperty(x,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.10",
4
+ "version": "0.3.1",
5
5
  "type": "module",
6
6
  "files": ["dist"],
7
7
  "exports": {