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