react-input-material 0.0.404 → 0.0.407
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 +100 -102
- 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 +1 -1
- 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 =>
|
|
@@ -2172,7 +2181,10 @@ export const GenericInputInner = function<Type = unknown>(
|
|
|
2172
2181
|
useWorker: false
|
|
2173
2182
|
}}
|
|
2174
2183
|
theme="github"
|
|
2175
|
-
value={
|
|
2184
|
+
value={
|
|
2185
|
+
properties.representation as
|
|
2186
|
+
string
|
|
2187
|
+
}
|
|
2176
2188
|
{...properties.inputProperties as
|
|
2177
2189
|
CodeEditorProps
|
|
2178
2190
|
}
|
|
@@ -2201,12 +2213,16 @@ export const GenericInputInner = function<Type = unknown>(
|
|
|
2201
2213
|
ref={setRichTextEditorReference}
|
|
2202
2214
|
textareaName={properties.name}
|
|
2203
2215
|
tinymceScriptSrc={
|
|
2204
|
-
(
|
|
2205
|
-
|
|
2216
|
+
(
|
|
2217
|
+
TINYMCE_DEFAULT_OPTIONS
|
|
2218
|
+
.base_url as
|
|
2219
|
+
string
|
|
2206
2220
|
) +
|
|
2207
2221
|
'tinymce.min.js'
|
|
2208
2222
|
}
|
|
2209
|
-
value={
|
|
2223
|
+
value={
|
|
2224
|
+
properties.representation as string
|
|
2225
|
+
}
|
|
2210
2226
|
{...properties.inputProperties as
|
|
2211
2227
|
RichTextEditorProps
|
|
2212
2228
|
}
|
|
@@ -2339,7 +2355,7 @@ export const GenericInputInner = function<Type = unknown>(
|
|
|
2339
2355
|
properties.trailingIcon
|
|
2340
2356
|
))}
|
|
2341
2357
|
type={determineNativeType(properties)}
|
|
2342
|
-
value={properties.representation}
|
|
2358
|
+
value={properties.representation as string}
|
|
2343
2359
|
{...properties.inputProperties as TextFieldProps}
|
|
2344
2360
|
/>
|
|
2345
2361
|
</div>,
|
|
@@ -2455,34 +2471,21 @@ GenericInput.transformer = {
|
|
|
2455
2471
|
type: 'text'
|
|
2456
2472
|
},
|
|
2457
2473
|
date: {
|
|
2458
|
-
format: {
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
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 ''
|
|
2468
2483
|
|
|
2469
|
-
|
|
2470
|
-
|
|
2484
|
+
const formattedValue:string =
|
|
2485
|
+
(new Date(Math.round(value * 1000))).toISOString()
|
|
2471
2486
|
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
intermediate: {transform: (
|
|
2475
|
-
value:number,
|
|
2476
|
-
configuration:DefaultProperties<number>,
|
|
2477
|
-
transformer:InputDataTransformation
|
|
2478
|
-
):string =>
|
|
2479
|
-
transformer.date.format?.final.transform ?
|
|
2480
|
-
transformer.date.format.final.transform(
|
|
2481
|
-
value, configuration, transformer
|
|
2482
|
-
) :
|
|
2483
|
-
`${value}`
|
|
2484
|
-
}
|
|
2485
|
-
},
|
|
2487
|
+
return formattedValue.substring(0, formattedValue.indexOf('T'))
|
|
2488
|
+
}}},
|
|
2486
2489
|
parse: (value:Date|number|string):number =>
|
|
2487
2490
|
typeof value === 'number' ?
|
|
2488
2491
|
value :
|
|
@@ -2494,34 +2497,21 @@ GenericInput.transformer = {
|
|
|
2494
2497
|
},
|
|
2495
2498
|
// TODO respect local to utc conversion.
|
|
2496
2499
|
'datetime-local': {
|
|
2497
|
-
format: {
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
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 ''
|
|
2507
2509
|
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
+
const formattedValue:string =
|
|
2511
|
+
(new Date(Math.round(value * 1000))).toISOString()
|
|
2510
2512
|
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
intermediate: {transform: (
|
|
2514
|
-
value:number,
|
|
2515
|
-
configuration:DefaultProperties<number>,
|
|
2516
|
-
transformer:InputDataTransformation
|
|
2517
|
-
):string =>
|
|
2518
|
-
transformer['datetime-local'].format?.final.transform ?
|
|
2519
|
-
transformer['datetime-local'].format.final.transform(
|
|
2520
|
-
value, configuration, transformer
|
|
2521
|
-
) :
|
|
2522
|
-
`${value}`
|
|
2523
|
-
}
|
|
2524
|
-
},
|
|
2513
|
+
return formattedValue.substring(0, formattedValue.length - 1)
|
|
2514
|
+
}}},
|
|
2525
2515
|
parse: (
|
|
2526
2516
|
value:number|string,
|
|
2527
2517
|
configuration:DefaultProperties<number>,
|
|
@@ -2532,49 +2522,57 @@ GenericInput.transformer = {
|
|
|
2532
2522
|
Date.parse(value as string) / 1000
|
|
2533
2523
|
},
|
|
2534
2524
|
time: {
|
|
2535
|
-
format: {
|
|
2536
|
-
|
|
2537
|
-
|
|
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 ''
|
|
2538
2536
|
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
if (value === -Infinity)
|
|
2542
|
-
return 'infinitely early in the past'
|
|
2543
|
-
if (!isFinite(value))
|
|
2544
|
-
return ''
|
|
2537
|
+
let formattedValue:string =
|
|
2538
|
+
(new Date(Math.round(value * 1000))).toISOString()
|
|
2545
2539
|
|
|
2546
|
-
|
|
2547
|
-
|
|
2540
|
+
formattedValue = formattedValue.substring(
|
|
2541
|
+
formattedValue.indexOf('T') + 1, formattedValue.length - 1
|
|
2542
|
+
)
|
|
2548
2543
|
|
|
2544
|
+
if (
|
|
2545
|
+
configuration.step &&
|
|
2546
|
+
configuration.step >= 60 &&
|
|
2547
|
+
(configuration.step % 60) === 0
|
|
2548
|
+
)
|
|
2549
2549
|
return formattedValue.substring(
|
|
2550
|
-
formattedValue.
|
|
2550
|
+
0, formattedValue.lastIndexOf(':')
|
|
2551
2551
|
)
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
configuration:DefaultProperties<number>,
|
|
2556
|
-
transformer:InputDataTransformation
|
|
2557
|
-
):string =>
|
|
2558
|
-
transformer.time.format?.final.transform ?
|
|
2559
|
-
transformer.time.format.final.transform(
|
|
2560
|
-
value, configuration, transformer
|
|
2561
|
-
) :
|
|
2562
|
-
`${value}`
|
|
2563
|
-
}
|
|
2564
|
-
},
|
|
2552
|
+
|
|
2553
|
+
return formattedValue
|
|
2554
|
+
}}},
|
|
2565
2555
|
parse: (value:Date|number|string):number =>
|
|
2566
2556
|
typeof value === 'number' ?
|
|
2567
2557
|
value :
|
|
2568
2558
|
value instanceof Date ?
|
|
2569
2559
|
value.getTime() / 1000 :
|
|
2570
|
-
|
|
2571
|
-
/^([0-9]{2}):([0-9]{2})
|
|
2572
|
-
(
|
|
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 =>
|
|
2573
2570
|
String(
|
|
2574
2571
|
parseInt(hour) *
|
|
2575
2572
|
60 ** 2 +
|
|
2576
2573
|
parseInt(minute) *
|
|
2577
|
-
60
|
|
2574
|
+
60 +
|
|
2575
|
+
(secondsSuffix ? parseFloat(seconds!) : 0)
|
|
2578
2576
|
)
|
|
2579
2577
|
))
|
|
2580
2578
|
},
|