react-input-material 0.0.403 → 0.0.406
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/components/FileInput.js +1 -1
- package/components/FileInput.styles.css +2 -2
- package/components/GenericInput.js +1 -1
- package/components/GenericInput.module.css +1 -0
- package/components/GenericInput.styles.css +1 -1
- package/components/GenericInput.tsx +142 -143
- package/components/Inputs.js +1 -1
- package/components/Inputs.styles.css +1 -1
- package/components/Interval.js +1 -1
- package/components/Interval.styles.css +1 -1
- package/helper.d.ts +15 -29
- package/helper.js +1 -1
- package/index.js +1 -1
- package/index.styles.css +2 -2
- package/package.json +2 -2
- package/type.d.ts +19 -17
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
MouseEvent as ReactMouseEvent,
|
|
33
33
|
MutableRefObject,
|
|
34
34
|
ReactElement,
|
|
35
|
+
ReactNode,
|
|
35
36
|
Suspense,
|
|
36
37
|
useEffect,
|
|
37
38
|
useImperativeHandle,
|
|
@@ -123,6 +124,7 @@ import {
|
|
|
123
124
|
InputState as State,
|
|
124
125
|
InputModel as Model,
|
|
125
126
|
NativeInputType,
|
|
127
|
+
NormalizedSelection,
|
|
126
128
|
Renderable,
|
|
127
129
|
GenericInputComponent,
|
|
128
130
|
InputTablePosition as TablePosition,
|
|
@@ -782,7 +784,7 @@ export const GenericInputInner = function<Type = unknown>(
|
|
|
782
784
|
const keysSorted:Array<keyof typeof indicator> =
|
|
783
785
|
['start', 'end']
|
|
784
786
|
|
|
785
|
-
let value:string = properties.representation
|
|
787
|
+
let value:string = properties.representation as string
|
|
786
788
|
for (const type of keysSorted)
|
|
787
789
|
value = (
|
|
788
790
|
value.substring(0, cursor[type]) +
|
|
@@ -887,9 +889,13 @@ export const GenericInputInner = function<Type = unknown>(
|
|
|
887
889
|
(event as unknown as KeyboardEvent)?.key?.length === 1 ?
|
|
888
890
|
1 :
|
|
889
891
|
(event as unknown as KeyboardEvent)?.key === 'Backspace' &&
|
|
890
|
-
|
|
892
|
+
(
|
|
893
|
+
(properties.representation as string).length >
|
|
894
|
+
selectionStart
|
|
895
|
+
) ?
|
|
891
896
|
-1 :
|
|
892
897
|
0
|
|
898
|
+
|
|
893
899
|
setCursor({end: selectionEnd + add, start: selectionStart + add})
|
|
894
900
|
}
|
|
895
901
|
}
|
|
@@ -1102,7 +1108,7 @@ export const GenericInputInner = function<Type = unknown>(
|
|
|
1102
1108
|
|
|
1103
1109
|
if (!useSuggestions || properties.suggestSelection) {
|
|
1104
1110
|
const candidate:null|Type = getValueFromSelection<Type>(
|
|
1105
|
-
properties.representation, normalizedSelection
|
|
1111
|
+
properties.representation, normalizedSelection!
|
|
1106
1112
|
)
|
|
1107
1113
|
if (candidate === null) {
|
|
1108
1114
|
properties.value = parseValue<Type>(
|
|
@@ -1422,7 +1428,7 @@ export const GenericInputInner = function<Type = unknown>(
|
|
|
1422
1428
|
|
|
1423
1429
|
if (selectedIndex === -1) {
|
|
1424
1430
|
const result:null|Type = getValueFromSelection<Type>(
|
|
1425
|
-
properties.representation, normalizeSelection(results)
|
|
1431
|
+
properties.representation, normalizeSelection(results)!
|
|
1426
1432
|
)
|
|
1427
1433
|
|
|
1428
1434
|
if (result !== null || properties.searchSelection)
|
|
@@ -1447,7 +1453,7 @@ export const GenericInputInner = function<Type = unknown>(
|
|
|
1447
1453
|
) = properties.suggestionCreator({
|
|
1448
1454
|
abortController,
|
|
1449
1455
|
properties,
|
|
1450
|
-
query: properties.representation
|
|
1456
|
+
query: properties.representation as string
|
|
1451
1457
|
})
|
|
1452
1458
|
|
|
1453
1459
|
if ((result as Promise<Properties['selection']>)?.then) {
|
|
@@ -1489,7 +1495,7 @@ export const GenericInputInner = function<Type = unknown>(
|
|
|
1489
1495
|
consolidation.
|
|
1490
1496
|
*/
|
|
1491
1497
|
const result:null|Type = getValueFromSelection<Type>(
|
|
1492
|
-
properties.representation, normalizedSelection
|
|
1498
|
+
properties.representation, normalizedSelection!
|
|
1493
1499
|
)
|
|
1494
1500
|
|
|
1495
1501
|
if (result !== null || properties.searchSelection)
|
|
@@ -1721,11 +1727,10 @@ export const GenericInputInner = function<Type = unknown>(
|
|
|
1721
1727
|
selection =
|
|
1722
1728
|
givenProperties.selection || givenProperties.model?.selection
|
|
1723
1729
|
|
|
1724
|
-
const normalizedSelection:
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
normalizeSelection(selection, givenProperties.labels)
|
|
1730
|
+
const normalizedSelection:NormalizedSelection|undefined =
|
|
1731
|
+
selection instanceof AbortController ?
|
|
1732
|
+
[] :
|
|
1733
|
+
normalizeSelection(selection, givenProperties.labels)
|
|
1729
1734
|
const [suggestionLabels, suggestionValues] =
|
|
1730
1735
|
selection instanceof AbortController ?
|
|
1731
1736
|
[[], []] :
|
|
@@ -1924,7 +1929,7 @@ export const GenericInputInner = function<Type = unknown>(
|
|
|
1924
1929
|
)
|
|
1925
1930
|
|
|
1926
1931
|
const currentRenderableSuggestions:Array<ReactElement> = []
|
|
1927
|
-
const currentSuggestionLabels:Array<string> = []
|
|
1932
|
+
const currentSuggestionLabels:Array<ReactNode|string> = []
|
|
1928
1933
|
const currentSuggestionValues:Array<unknown> = []
|
|
1929
1934
|
const useSuggestions = Boolean(
|
|
1930
1935
|
properties.suggestionCreator ||
|
|
@@ -1940,9 +1945,9 @@ export const GenericInputInner = function<Type = unknown>(
|
|
|
1940
1945
|
if (Tools.isFunction(properties.children)) {
|
|
1941
1946
|
const result:null|ReactElement = properties.children({
|
|
1942
1947
|
index,
|
|
1943
|
-
normalizedSelection
|
|
1948
|
+
normalizedSelection: normalizedSelection!,
|
|
1944
1949
|
properties,
|
|
1945
|
-
query: properties.representation,
|
|
1950
|
+
query: properties.representation as string,
|
|
1946
1951
|
suggestion,
|
|
1947
1952
|
value: suggestionValues[index] as Type
|
|
1948
1953
|
})
|
|
@@ -1964,7 +1969,9 @@ export const GenericInputInner = function<Type = unknown>(
|
|
|
1964
1969
|
} else if (
|
|
1965
1970
|
!properties.representation ||
|
|
1966
1971
|
properties.suggestionCreator ||
|
|
1967
|
-
suggestionMatches(
|
|
1972
|
+
suggestionMatches(
|
|
1973
|
+
suggestion as string, properties.representation as string
|
|
1974
|
+
)
|
|
1968
1975
|
) {
|
|
1969
1976
|
currentRenderableSuggestions.push(
|
|
1970
1977
|
<MenuItem
|
|
@@ -1975,7 +1982,9 @@ export const GenericInputInner = function<Type = unknown>(
|
|
|
1975
1982
|
>
|
|
1976
1983
|
{(Tools.stringMark(
|
|
1977
1984
|
suggestion,
|
|
1978
|
-
|
|
1985
|
+
(
|
|
1986
|
+
properties.representation as string
|
|
1987
|
+
)?.split(' ') || '',
|
|
1979
1988
|
(value:unknown):string =>
|
|
1980
1989
|
`${value as string}`.toLowerCase(),
|
|
1981
1990
|
(foundWord:string):ReactElement =>
|
|
@@ -2004,6 +2013,47 @@ export const GenericInputInner = function<Type = unknown>(
|
|
|
2004
2013
|
(Boolean(normalizedSelection) || Boolean(properties.labels)) &&
|
|
2005
2014
|
!useSuggestions
|
|
2006
2015
|
/// endregion
|
|
2016
|
+
/// region determine type specific constraints
|
|
2017
|
+
const constraints:Mapping<unknown> = {}
|
|
2018
|
+
if (properties.type === 'number') {
|
|
2019
|
+
constraints.step = properties.step
|
|
2020
|
+
|
|
2021
|
+
if (properties.maximum !== Infinity)
|
|
2022
|
+
constraints.max = properties.maximum
|
|
2023
|
+
if (properties.minimum !== -Infinity)
|
|
2024
|
+
constraints.min = properties.minimum
|
|
2025
|
+
} else if (properties.type === 'string') {
|
|
2026
|
+
if (
|
|
2027
|
+
properties.maximumLength >= 0 &&
|
|
2028
|
+
properties.maximumLength !== Infinity
|
|
2029
|
+
)
|
|
2030
|
+
constraints.maxLength = properties.maximumLength
|
|
2031
|
+
if (properties.minimumLength > 0)
|
|
2032
|
+
constraints.minLength = properties.minimumLength
|
|
2033
|
+
|
|
2034
|
+
if (properties.editor !== 'plain')
|
|
2035
|
+
constraints.rows = properties.rows
|
|
2036
|
+
} else if (['date', 'datetime-local', 'time'].includes(properties.type)) {
|
|
2037
|
+
constraints.step = properties.step
|
|
2038
|
+
|
|
2039
|
+
if (properties.maximum !== Infinity)
|
|
2040
|
+
constraints.max = formatValue<Type>(
|
|
2041
|
+
properties,
|
|
2042
|
+
properties.maximum as
|
|
2043
|
+
unknown as
|
|
2044
|
+
Type,
|
|
2045
|
+
transformer
|
|
2046
|
+
)
|
|
2047
|
+
if (properties.minimum !== -Infinity)
|
|
2048
|
+
constraints.min = formatValue<Type>(
|
|
2049
|
+
properties,
|
|
2050
|
+
properties.minimum as
|
|
2051
|
+
unknown as
|
|
2052
|
+
Type,
|
|
2053
|
+
transformer
|
|
2054
|
+
)
|
|
2055
|
+
}
|
|
2056
|
+
/// endregion
|
|
2007
2057
|
/// region main markup
|
|
2008
2058
|
return <WrapConfigurations
|
|
2009
2059
|
strict={GenericInput.strict}
|
|
@@ -2131,7 +2181,10 @@ export const GenericInputInner = function<Type = unknown>(
|
|
|
2131
2181
|
useWorker: false
|
|
2132
2182
|
}}
|
|
2133
2183
|
theme="github"
|
|
2134
|
-
value={
|
|
2184
|
+
value={
|
|
2185
|
+
properties.representation as
|
|
2186
|
+
string
|
|
2187
|
+
}
|
|
2135
2188
|
{...properties.inputProperties as
|
|
2136
2189
|
CodeEditorProps
|
|
2137
2190
|
}
|
|
@@ -2160,12 +2213,16 @@ export const GenericInputInner = function<Type = unknown>(
|
|
|
2160
2213
|
ref={setRichTextEditorReference}
|
|
2161
2214
|
textareaName={properties.name}
|
|
2162
2215
|
tinymceScriptSrc={
|
|
2163
|
-
(
|
|
2164
|
-
|
|
2216
|
+
(
|
|
2217
|
+
TINYMCE_DEFAULT_OPTIONS
|
|
2218
|
+
.base_url as
|
|
2219
|
+
string
|
|
2165
2220
|
) +
|
|
2166
2221
|
'tinymce.min.js'
|
|
2167
2222
|
}
|
|
2168
|
-
value={
|
|
2223
|
+
value={
|
|
2224
|
+
properties.representation as string
|
|
2225
|
+
}
|
|
2169
2226
|
{...properties.inputProperties as
|
|
2170
2227
|
RichTextEditorProps
|
|
2171
2228
|
}
|
|
@@ -2268,47 +2325,7 @@ export const GenericInputInner = function<Type = unknown>(
|
|
|
2268
2325
|
<TextField
|
|
2269
2326
|
{...genericProperties as TextFieldProps}
|
|
2270
2327
|
{...materialProperties as TextFieldProps}
|
|
2271
|
-
{...
|
|
2272
|
-
{
|
|
2273
|
-
max: properties.maximum,
|
|
2274
|
-
min: properties.minimum,
|
|
2275
|
-
step: properties.step
|
|
2276
|
-
} :
|
|
2277
|
-
properties.type === 'string' ?
|
|
2278
|
-
{
|
|
2279
|
-
maxLength: properties.maximumLength >= 0 ?
|
|
2280
|
-
properties.maximumLength :
|
|
2281
|
-
Infinity,
|
|
2282
|
-
minLength: properties.minimumLength >= 0 ?
|
|
2283
|
-
properties.minimumLength :
|
|
2284
|
-
0,
|
|
2285
|
-
...(properties.editor === 'plain' ?
|
|
2286
|
-
{} :
|
|
2287
|
-
{rows: properties.rows}
|
|
2288
|
-
)
|
|
2289
|
-
} :
|
|
2290
|
-
['date', 'datetime-local', 'time'].includes(
|
|
2291
|
-
properties.type
|
|
2292
|
-
) ?
|
|
2293
|
-
{
|
|
2294
|
-
max: formatValue<Type>(
|
|
2295
|
-
properties,
|
|
2296
|
-
properties.maximum as
|
|
2297
|
-
unknown as
|
|
2298
|
-
Type,
|
|
2299
|
-
transformer
|
|
2300
|
-
),
|
|
2301
|
-
min: formatValue<Type>(
|
|
2302
|
-
properties,
|
|
2303
|
-
properties.minimum as
|
|
2304
|
-
unknown as
|
|
2305
|
-
Type,
|
|
2306
|
-
transformer
|
|
2307
|
-
),
|
|
2308
|
-
step: properties.step
|
|
2309
|
-
} :
|
|
2310
|
-
{}
|
|
2311
|
-
)}
|
|
2328
|
+
{...constraints}
|
|
2312
2329
|
align={properties.align}
|
|
2313
2330
|
characterCount={
|
|
2314
2331
|
typeof properties.maximumLength === 'number' &&
|
|
@@ -2338,7 +2355,7 @@ export const GenericInputInner = function<Type = unknown>(
|
|
|
2338
2355
|
properties.trailingIcon
|
|
2339
2356
|
))}
|
|
2340
2357
|
type={determineNativeType(properties)}
|
|
2341
|
-
value={properties.representation}
|
|
2358
|
+
value={properties.representation as string}
|
|
2342
2359
|
{...properties.inputProperties as TextFieldProps}
|
|
2343
2360
|
/>
|
|
2344
2361
|
</div>,
|
|
@@ -2454,34 +2471,21 @@ GenericInput.transformer = {
|
|
|
2454
2471
|
type: 'text'
|
|
2455
2472
|
},
|
|
2456
2473
|
date: {
|
|
2457
|
-
format: {
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
return ''
|
|
2474
|
+
format: {final: {transform: (value:number):string => {
|
|
2475
|
+
value = typeof value === 'number' ? value : parseFloat(value)
|
|
2476
|
+
|
|
2477
|
+
if (value === Infinity)
|
|
2478
|
+
return 'Infinitely far in the future'
|
|
2479
|
+
if (value === -Infinity)
|
|
2480
|
+
return 'Infinitely early in the past'
|
|
2481
|
+
if (!isFinite(value))
|
|
2482
|
+
return ''
|
|
2467
2483
|
|
|
2468
|
-
|
|
2469
|
-
|
|
2484
|
+
const formattedValue:string =
|
|
2485
|
+
(new Date(Math.round(value * 1000))).toISOString()
|
|
2470
2486
|
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
intermediate: {transform: (
|
|
2474
|
-
value:number,
|
|
2475
|
-
configuration:DefaultProperties<number>,
|
|
2476
|
-
transformer:InputDataTransformation
|
|
2477
|
-
):string =>
|
|
2478
|
-
transformer.date.format?.final.transform ?
|
|
2479
|
-
transformer.date.format.final.transform(
|
|
2480
|
-
value, configuration, transformer
|
|
2481
|
-
) :
|
|
2482
|
-
`${value}`
|
|
2483
|
-
}
|
|
2484
|
-
},
|
|
2487
|
+
return formattedValue.substring(0, formattedValue.indexOf('T'))
|
|
2488
|
+
}}},
|
|
2485
2489
|
parse: (value:Date|number|string):number =>
|
|
2486
2490
|
typeof value === 'number' ?
|
|
2487
2491
|
value :
|
|
@@ -2493,34 +2497,21 @@ GenericInput.transformer = {
|
|
|
2493
2497
|
},
|
|
2494
2498
|
// TODO respect local to utc conversion.
|
|
2495
2499
|
'datetime-local': {
|
|
2496
|
-
format: {
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
return ''
|
|
2500
|
+
format: {final: {transform: (value:number):string => {
|
|
2501
|
+
value = typeof value === 'number' ? value : parseFloat(value)
|
|
2502
|
+
|
|
2503
|
+
if (value === Infinity)
|
|
2504
|
+
return 'Infinitely far in the future'
|
|
2505
|
+
if (value === -Infinity)
|
|
2506
|
+
return 'Infinitely early in the past'
|
|
2507
|
+
if (!isFinite(value))
|
|
2508
|
+
return ''
|
|
2506
2509
|
|
|
2507
|
-
|
|
2508
|
-
|
|
2510
|
+
const formattedValue:string =
|
|
2511
|
+
(new Date(Math.round(value * 1000))).toISOString()
|
|
2509
2512
|
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
intermediate: {transform: (
|
|
2513
|
-
value:number,
|
|
2514
|
-
configuration:DefaultProperties<number>,
|
|
2515
|
-
transformer:InputDataTransformation
|
|
2516
|
-
):string =>
|
|
2517
|
-
transformer['datetime-local'].format?.final.transform ?
|
|
2518
|
-
transformer['datetime-local'].format.final.transform(
|
|
2519
|
-
value, configuration, transformer
|
|
2520
|
-
) :
|
|
2521
|
-
`${value}`
|
|
2522
|
-
}
|
|
2523
|
-
},
|
|
2513
|
+
return formattedValue.substring(0, formattedValue.length - 1)
|
|
2514
|
+
}}},
|
|
2524
2515
|
parse: (
|
|
2525
2516
|
value:number|string,
|
|
2526
2517
|
configuration:DefaultProperties<number>,
|
|
@@ -2531,49 +2522,57 @@ GenericInput.transformer = {
|
|
|
2531
2522
|
Date.parse(value as string) / 1000
|
|
2532
2523
|
},
|
|
2533
2524
|
time: {
|
|
2534
|
-
format: {
|
|
2535
|
-
|
|
2536
|
-
|
|
2525
|
+
format: {final: {transform: (
|
|
2526
|
+
value:number, configuration:DefaultProperties<number>
|
|
2527
|
+
):string => {
|
|
2528
|
+
value = typeof value === 'number' ? value : parseFloat(value)
|
|
2529
|
+
|
|
2530
|
+
if (value === Infinity)
|
|
2531
|
+
return 'Infinitely far in the future'
|
|
2532
|
+
if (value === -Infinity)
|
|
2533
|
+
return 'Infinitely early in the past'
|
|
2534
|
+
if (!isFinite(value))
|
|
2535
|
+
return ''
|
|
2537
2536
|
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
if (value === -Infinity)
|
|
2541
|
-
return 'infinitely early in the past'
|
|
2542
|
-
if (!isFinite(value))
|
|
2543
|
-
return ''
|
|
2537
|
+
let formattedValue:string =
|
|
2538
|
+
(new Date(Math.round(value * 1000))).toISOString()
|
|
2544
2539
|
|
|
2545
|
-
|
|
2546
|
-
|
|
2540
|
+
formattedValue = formattedValue.substring(
|
|
2541
|
+
formattedValue.indexOf('T') + 1, formattedValue.length - 1
|
|
2542
|
+
)
|
|
2547
2543
|
|
|
2544
|
+
if (
|
|
2545
|
+
configuration.step &&
|
|
2546
|
+
configuration.step >= 60 &&
|
|
2547
|
+
(configuration.step % 60) === 0
|
|
2548
|
+
)
|
|
2548
2549
|
return formattedValue.substring(
|
|
2549
|
-
formattedValue.
|
|
2550
|
+
0, formattedValue.lastIndexOf(':')
|
|
2550
2551
|
)
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
configuration:DefaultProperties<number>,
|
|
2555
|
-
transformer:InputDataTransformation
|
|
2556
|
-
):string =>
|
|
2557
|
-
transformer.time.format?.final.transform ?
|
|
2558
|
-
transformer.time.format.final.transform(
|
|
2559
|
-
value, configuration, transformer
|
|
2560
|
-
) :
|
|
2561
|
-
`${value}`
|
|
2562
|
-
}
|
|
2563
|
-
},
|
|
2552
|
+
|
|
2553
|
+
return formattedValue
|
|
2554
|
+
}}},
|
|
2564
2555
|
parse: (value:Date|number|string):number =>
|
|
2565
2556
|
typeof value === 'number' ?
|
|
2566
2557
|
value :
|
|
2567
2558
|
value instanceof Date ?
|
|
2568
2559
|
value.getTime() / 1000 :
|
|
2569
|
-
|
|
2570
|
-
/^([0-9]{2}):([0-9]{2})
|
|
2571
|
-
(
|
|
2560
|
+
parseFloat(value.replace(
|
|
2561
|
+
/^([0-9]{2}):([0-9]{2})(:([0-9]{2}(\.[0-9]+)?))?$/,
|
|
2562
|
+
(
|
|
2563
|
+
_match:string,
|
|
2564
|
+
hour:string,
|
|
2565
|
+
minute:string,
|
|
2566
|
+
secondsSuffix?:string,
|
|
2567
|
+
seconds?:string,
|
|
2568
|
+
_millisecondsSuffix?:string
|
|
2569
|
+
):string =>
|
|
2572
2570
|
String(
|
|
2573
2571
|
parseInt(hour) *
|
|
2574
2572
|
60 ** 2 +
|
|
2575
2573
|
parseInt(minute) *
|
|
2576
|
-
60
|
|
2574
|
+
60 +
|
|
2575
|
+
(secondsSuffix ? parseFloat(seconds!) : 0)
|
|
2577
2576
|
)
|
|
2578
2577
|
))
|
|
2579
2578
|
},
|