@mpen/react-basic-inputs 0.3.1 → 0.3.2

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.
@@ -17,7 +17,6 @@ export declare type ActionButtonProps = RequiredKeys<ComponentPropsWithoutRef<'b
17
17
  export declare function DatetimeLocalInput({ value, defaultValue, min, max, onChange, ...props }: DatetimeLocalInputProps): JSX_2.Element;
18
18
 
19
19
  export declare type DatetimeLocalInputChangeEvent = {
20
- isoString: string | null;
21
20
  value: number | null;
22
21
  date: Date | null;
23
22
  };
@@ -37,16 +36,14 @@ export declare type DatetimeOffsetInputChangeEvent = {
37
36
  };
38
37
 
39
38
  export declare type DatetimeOffsetInputProps = {
40
- min?: DateValue_2;
41
- max?: DateValue_2;
42
- value?: DateValue_2 | null;
43
- defaultValue?: DateValue_2;
39
+ min?: DateValue;
40
+ max?: DateValue;
41
+ value?: DateValue | null;
42
+ defaultValue?: DateValue;
44
43
  onChange?: (ev: DatetimeOffsetInputChangeEvent) => void;
45
44
  };
46
45
 
47
- export declare type DateValue = number | string | Date;
48
-
49
- declare type DateValue_2 = number | string | Date;
46
+ declare type DateValue = number | string | Date;
50
47
 
51
48
  export declare const DebouncedInput: FC<DebouncedInputProps>;
52
49
 
@@ -72,51 +72,51 @@ class Y {
72
72
  return u;
73
73
  }
74
74
  }
75
- const le = (e) => ({
75
+ const ce = (e) => ({
76
76
  value: e,
77
77
  text: String(e),
78
78
  disabled: !0,
79
79
  key: ae
80
- }), ce = "3c9369b7-0a5e-46ea-93c2-e8b9fec67fdb", ae = "1a53f789-77f5-4ce6-a829-b00e563f1ee8";
81
- function ie({
80
+ }), le = "3c9369b7-0a5e-46ea-93c2-e8b9fec67fdb", ae = "1a53f789-77f5-4ce6-a829-b00e563f1ee8";
81
+ function fe({
82
82
  options: e,
83
83
  value: t,
84
- invalidValueOption: n = le,
84
+ invalidValueOption: n = ce,
85
85
  onChange: u,
86
86
  placeholder: r,
87
87
  ...s
88
88
  }) {
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)
89
+ const l = t == null, a = F(() => t != null && e.some((c) => c.value == t), [e, t]), o = F(() => t == null || !n ? null : n(t), [n, t]), f = F(() => {
90
+ if (a)
91
91
  return e;
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];
92
+ const c = [...e];
93
+ return l ? r != null && c.unshift({ text: r, hidden: !0, value: null, key: le }) : o && c.push(o), c;
94
+ }, [a, e, l, o, r]), d = te((c) => {
95
+ const g = c.target.selectedIndex, O = f[g];
96
96
  u == null || u({
97
- value: S.value,
97
+ value: O.value,
98
98
  // option: opt,
99
99
  // event: ev,
100
100
  index: g,
101
101
  type: "change",
102
- timeStamp: l.timeStamp,
103
- target: l.target
102
+ timeStamp: c.timeStamp,
103
+ target: c.target
104
104
  });
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();
105
+ }), i = h(null), m = T(() => {
106
+ i.current && (i.current.selectedIndex < 0 || f[i.current.selectedIndex].value != t) && (i.current.selectedIndex = f.findIndex((c) => c.value == t));
107
+ }, [f, t]), N = (c) => {
108
+ i.current = c, m();
109
109
  };
110
110
  R(() => {
111
111
  m();
112
112
  }, [m]);
113
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);
114
+ return /* @__PURE__ */ v("select", { ...s, onChange: d, ref: N, children: f.map((c, g) => {
115
+ const { value: O, text: b, uniqueKey: S, ...y } = c, V = x.fix(c, g);
116
+ return /* @__PURE__ */ W("option", { ...y, key: V, value: V }, c.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
122
  function oe(e) {
@@ -138,16 +138,16 @@ function me(e) {
138
138
  function I(e, t = 2) {
139
139
  return String(e).padStart(t, "0");
140
140
  }
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);
141
+ const z = k(function({ value: t = "", onPaste: n, onChange: u, onInput: r, onBlur: s, formatOnChange: l = ee, ...a }, o) {
142
+ const [f, d] = D(t), i = h(t), m = h(!1);
143
143
  R(() => {
144
- d(t), m.current = !1, f.current = t;
144
+ d(t), m.current = !1, i.current = t;
145
145
  }, [t]);
146
146
  const N = {
147
147
  type: "text",
148
- ...c,
148
+ ...a,
149
149
  ref: o,
150
- value: i,
150
+ value: f,
151
151
  onChange: (x) => {
152
152
  d(x.target.value);
153
153
  },
@@ -171,77 +171,77 @@ const z = k(function({ value: t = "", onPaste: n, onChange: u, onInput: r, onBlu
171
171
  m.current = !0, r == null || r(x);
172
172
  },
173
173
  onBlur: (x) => {
174
- const l = a(i);
175
- m.current && (l !== f.current && (u == null || u({
174
+ const c = l(f);
175
+ m.current && (c !== i.current && (u == null || u({
176
176
  type: "change",
177
- value: l,
177
+ value: c,
178
178
  timeStamp: x.timeStamp,
179
179
  target: x.target
180
- }), f.current = l), l !== x.target.value && d(l)), s == null || s(x);
180
+ }), i.current = c), c !== x.target.value && d(c)), s == null || s(x);
181
181
  }
182
182
  };
183
183
  return /* @__PURE__ */ v("input", { ...N });
184
184
  });
185
- function Se({ formatOnChange: e = fe, ...t }) {
185
+ function Oe({ formatOnChange: e = ie, ...t }) {
186
186
  return /* @__PURE__ */ v(z, { formatOnChange: e, ...t, type: "text" });
187
187
  }
188
- const Oe = k(function({
188
+ const Se = k(function({
189
189
  onInput: t,
190
190
  style: n,
191
191
  initialHeight: u = "auto",
192
192
  ...r
193
193
  }, s) {
194
- const a = h(null), [c, o] = D(u), i = T(() => {
195
- const f = a.current;
196
- if (!f)
194
+ const l = h(null), [a, o] = D(u), f = T(() => {
195
+ const i = l.current;
196
+ if (!i)
197
197
  return;
198
- f.style.height = u;
199
- const m = `${f.scrollHeight}px`;
200
- o(m), f.style.height = m;
198
+ i.style.height = u;
199
+ const m = `${i.scrollHeight}px`;
200
+ o(m), i.style.height = m;
201
201
  }, [u]);
202
202
  B(s, () => ({
203
- element: a.current,
204
- adjustHeight: i
205
- }), [i]);
206
- const d = _((f) => {
207
- i(), t == null || t(f);
203
+ element: l.current,
204
+ adjustHeight: f
205
+ }), [f]);
206
+ const d = _((i) => {
207
+ f(), t == null || t(i);
208
208
  });
209
209
  return J(() => {
210
- i();
211
- const f = a.current;
212
- if (!f)
210
+ f();
211
+ const i = l.current;
212
+ if (!i)
213
213
  return;
214
214
  const m = new ResizeObserver((N) => {
215
- i();
215
+ f();
216
216
  });
217
- return m.observe(f), () => {
218
- m.unobserve(f);
217
+ return m.observe(i), () => {
218
+ m.unobserve(i);
219
219
  };
220
- }, [i]), /* @__PURE__ */ v("textarea", { ...r, style: {
220
+ }, [f]), /* @__PURE__ */ v("textarea", { ...r, style: {
221
221
  overflow: "hidden",
222
222
  // these 2 styles aren't needed if the caller sets them in CSS.
223
223
  resize: "none",
224
224
  ...n,
225
- height: c
226
- }, onInput: d, ref: a });
225
+ height: a
226
+ }, onInput: d, ref: l });
227
227
  });
228
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,
229
+ const t = X(), n = e.name ?? t, u = e.valueEquals ?? Object.is, r = e.options ?? [], s = new Y(), l = _((a) => {
230
+ const o = Number(a.target.value), f = r[o];
231
+ f != null && e.onChange != null && e.onChange({
232
+ value: f.value,
233
233
  index: o,
234
234
  type: "change",
235
- timeStamp: c.timeStamp,
236
- target: c.target
235
+ timeStamp: a.timeStamp,
236
+ target: a.target
237
237
  });
238
238
  });
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);
239
+ return /* @__PURE__ */ v("ul", { className: e.className, children: r.map((a, o) => {
240
+ const { value: f, text: d, key: i, itemClassName: m, labelClassName: N, inputClassName: x, textClassName: c, ...g } = a, O = s.fix(a, o);
241
+ return e.value !== void 0 && (g.checked = u(f, 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: l, name: n, type: "radio" }),
243
+ /* @__PURE__ */ v("span", { className: c, children: d })
244
+ ] }) }, O);
245
245
  }) });
246
246
  }
247
247
  function U() {
@@ -260,13 +260,13 @@ const De = ({
260
260
  R(() => {
261
261
  A(s), r.current != null && (r.current.value = e);
262
262
  }, [e]);
263
- const a = () => {
263
+ const l = () => {
264
264
  r.current != null && r.current.value !== e && (t == null || t({ value: r.current.value }));
265
265
  };
266
266
  return /* @__PURE__ */ v("input", { ...u, ref: r, defaultValue: e, onInput: () => {
267
- A(s), s.current = setTimeout(a, n);
267
+ A(s), s.current = setTimeout(l, n);
268
268
  }, onBlur: () => {
269
- A(s), a();
269
+ A(s), l();
270
270
  } });
271
271
  };
272
272
  function _e({ onClick: e, ...t }) {
@@ -302,20 +302,20 @@ function M(e) {
302
302
  }
303
303
  const w = { offset: !1 };
304
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);
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 = (l) => {
306
+ if (l.currentTarget.value.length) {
307
+ const a = new Date(l.currentTarget.valueAsNumber);
308
308
  r({
309
309
  // TODO: undo this, "date time local" should in fact be local (no time zone)
310
- isoString: E(c, { offset: !0 }),
310
+ // isoString: toIsoDateString(date,{offset:true}),
311
311
  // isoString: date.toISOString(),
312
- value: c.valueOf(),
313
- date: c
312
+ value: a.valueOf(),
313
+ date: a
314
314
  });
315
315
  } else
316
316
  r({
317
317
  // isoStringWithOffset: null,
318
- isoString: null,
318
+ // isoString: null,
319
319
  value: null,
320
320
  date: null
321
321
  });
@@ -433,31 +433,31 @@ function we({
433
433
  onChange: r,
434
434
  ...s
435
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));
436
+ const [l, a] = D(() => $(e ?? t) !== null), [o, f] = D(() => $(e ?? t)), [d, i] = D(() => M(e ?? t)), m = be(e, () => {
437
+ a($(e) !== null), f($(e)), i(M(e));
438
438
  }), N = T((b) => {
439
439
  m(b), r == null || r({
440
440
  value: b
441
441
  });
442
442
  }, [r, m]);
443
443
  n != null && (s.min = M(n)), u != null && (s.max = M(u));
444
- const x = a ? o : K(d), l = T(
444
+ const x = l ? o : K(d), c = T(
445
445
  (b) => {
446
- const O = b.currentTarget.value;
447
- f(O), N(O + p(x));
446
+ const S = b.currentTarget.value;
447
+ i(S), N(S + p(x));
448
448
  },
449
449
  [N, x]
450
450
  ), g = T(
451
451
  (b) => {
452
- i(b.value), N(d + p(b.value));
452
+ f(b.value), N(d + p(b.value));
453
453
  },
454
454
  [N, d]
455
- ), S = T(
455
+ ), O = T(
456
456
  (b) => {
457
- const O = b.currentTarget.checked;
458
- c(O);
457
+ const S = b.currentTarget.checked;
458
+ a(S);
459
459
  let y;
460
- O ? d && o === null ? (y = K(d), i(y)) : y = o : y = K(d), N(d + p(y));
460
+ S ? d && o === null ? (y = K(d), f(y)) : y = o : y = K(d), N(d + p(y));
461
461
  },
462
462
  [o, d, N]
463
463
  );
@@ -468,42 +468,42 @@ function we({
468
468
  type: "datetime-local",
469
469
  ...s,
470
470
  value: d,
471
- onChange: l
471
+ onChange: c
472
472
  }
473
473
  ),
474
474
  /* @__PURE__ */ v(
475
475
  "input",
476
476
  {
477
477
  type: "checkbox",
478
- title: a ? "Use UTC offset from this device" : "Enable UTC offset selection",
479
- checked: a,
480
- onChange: S
478
+ title: l ? "Use UTC offset from this device" : "Enable UTC offset selection",
479
+ checked: l,
480
+ onChange: O
481
481
  }
482
482
  ),
483
483
  /* @__PURE__ */ v(
484
- ie,
484
+ fe,
485
485
  {
486
486
  value: x,
487
487
  onChange: g,
488
- disabled: !a,
488
+ disabled: !l,
489
489
  options: he
490
490
  }
491
491
  )
492
492
  ] });
493
493
  }
494
- const $e = k(function({ placeholder: t, formatOnChange: n = me, onChange: u, value: r, ...s }, a) {
495
- const c = {
494
+ const $e = k(function({ placeholder: t, formatOnChange: n = me, onChange: u, value: r, ...s }, l) {
495
+ const a = {
496
496
  inputMode: "decimal",
497
497
  ...s,
498
498
  formatOnChange: n,
499
499
  type: "number"
500
500
  };
501
- return r !== void 0 && (c.value = j(r)), t != null && (c.placeholder = String(t)), u != null && (c.onChange = (o) => {
501
+ return r !== void 0 && (a.value = j(r)), t != null && (a.placeholder = String(t)), u != null && (a.onChange = (o) => {
502
502
  u({
503
503
  ...o,
504
504
  value: de(o.value)
505
505
  });
506
- }), /* @__PURE__ */ v(z, { ...c, ref: a });
506
+ }), /* @__PURE__ */ v(z, { ...a, ref: l });
507
507
  });
508
508
  export {
509
509
  _e as ActionButton,
@@ -513,7 +513,7 @@ export {
513
513
  z as Input,
514
514
  $e as NumberInput,
515
515
  Ee as RadioMenu,
516
- ie as Select,
517
- Oe as TextArea,
518
- Se as TextInput
516
+ fe as Select,
517
+ Se as TextArea,
518
+ Oe as TextInput
519
519
  };
@@ -1 +1 @@
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"})});
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 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 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,S=o[g];u==null||u({value:S.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:S,text:h,uniqueKey:O,...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=E(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=E(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,S=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})]})},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 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 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 ae({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=a=>{if(a.currentTarget.value.length){const i=new Date(a.currentTarget.valueAsNumber);s({value:i.valueOf(),date:i})}else s({value:null,date:null})}),f.jsx("input",{type:"datetime-local",...l})}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 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 O=h.currentTarget.value;d(O),I(O+M(N))},[I,N]),g=r.useCallback(h=>{o(h.value),I(v+M(h.value))},[I,v]),S=r.useCallback(h=>{const O=h.currentTarget.checked;i(O);let T;O?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:S}),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=ae,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,9 +1,11 @@
1
1
  {
2
2
  "name": "@mpen/react-basic-inputs",
3
3
  "private": false,
4
- "version": "0.3.1",
4
+ "version": "0.3.2",
5
5
  "type": "module",
6
- "files": ["dist"],
6
+ "files": [
7
+ "dist"
8
+ ],
7
9
  "exports": {
8
10
  ".": {
9
11
  "import": "./dist/react-basic-inputs.js",
@@ -21,7 +23,8 @@
21
23
  "preview": "bun run --bun vite preview",
22
24
  "_prepublishOnly": "bun run --bun build",
23
25
  "_publish": "npm publish --access=public",
24
- "build:docs": "typedoc && hg addremove docs"
26
+ "build:docs": "typedoc && hg addremove docs",
27
+ "bump": "npm version patch && bun.exe run build && npm publish"
25
28
  },
26
29
  "peerDependencies": {
27
30
  "react": "^18.2.0"