react-input-material 0.0.406 → 0.0.409
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/GenericInput.js +1 -1
- package/components/GenericInput.tsx +160 -64
- package/components/Inputs.js +1 -1
- package/components/Interval.js +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/type.d.ts +4 -4
|
@@ -1006,6 +1006,7 @@ export const GenericInputInner = function<Type = unknown>(
|
|
|
1006
1006
|
transformer,
|
|
1007
1007
|
/*
|
|
1008
1008
|
NOTE: Handle two cases:
|
|
1009
|
+
|
|
1009
1010
|
1. Representation has to be determine initially
|
|
1010
1011
|
(-> usually no focus).
|
|
1011
1012
|
2. Representation was set from the outside
|
|
@@ -2470,9 +2471,28 @@ GenericInput.transformer = {
|
|
|
2470
2471
|
NaN,
|
|
2471
2472
|
type: 'text'
|
|
2472
2473
|
},
|
|
2474
|
+
|
|
2473
2475
|
date: {
|
|
2474
|
-
format: {final: {transform: (
|
|
2475
|
-
value
|
|
2476
|
+
format: {final: {transform: (
|
|
2477
|
+
value:Date|number|string,
|
|
2478
|
+
configuration:DefaultProperties<number>,
|
|
2479
|
+
transformer:InputDataTransformation
|
|
2480
|
+
):string => {
|
|
2481
|
+
if (typeof value !== 'number')
|
|
2482
|
+
if (transformer.date.parse)
|
|
2483
|
+
value = transformer.date.parse(
|
|
2484
|
+
value, configuration, transformer
|
|
2485
|
+
)
|
|
2486
|
+
else {
|
|
2487
|
+
const parsedDate:number = value instanceof Date ?
|
|
2488
|
+
value.getTime() / 1000 :
|
|
2489
|
+
Date.parse(value)
|
|
2490
|
+
if (isNaN(parsedDate)) {
|
|
2491
|
+
const parsedFloat:number = parseFloat(value as string)
|
|
2492
|
+
value = isNaN(parsedFloat) ? 0 : parsedFloat
|
|
2493
|
+
} else
|
|
2494
|
+
value = parsedDate / 1000
|
|
2495
|
+
}
|
|
2476
2496
|
|
|
2477
2497
|
if (value === Infinity)
|
|
2478
2498
|
return 'Infinitely far in the future'
|
|
@@ -2486,19 +2506,47 @@ GenericInput.transformer = {
|
|
|
2486
2506
|
|
|
2487
2507
|
return formattedValue.substring(0, formattedValue.indexOf('T'))
|
|
2488
2508
|
}}},
|
|
2489
|
-
parse: (value:Date|number|string):number =>
|
|
2490
|
-
typeof value === 'number'
|
|
2491
|
-
value
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2509
|
+
parse: (value:Date|number|string):number => {
|
|
2510
|
+
if (typeof value === 'number')
|
|
2511
|
+
return value
|
|
2512
|
+
|
|
2513
|
+
if (value instanceof Date)
|
|
2514
|
+
return value.getTime() / 1000
|
|
2515
|
+
|
|
2516
|
+
const parsedDate:number = Date.parse(value)
|
|
2517
|
+
if (isNaN(parsedDate)) {
|
|
2518
|
+
const parsedFloat:number = parseFloat(value)
|
|
2519
|
+
if (isNaN(parsedFloat))
|
|
2520
|
+
return 0
|
|
2521
|
+
|
|
2522
|
+
return parsedFloat
|
|
2523
|
+
}
|
|
2524
|
+
|
|
2525
|
+
return parsedDate / 1000
|
|
2526
|
+
}
|
|
2497
2527
|
},
|
|
2498
2528
|
// TODO respect local to utc conversion.
|
|
2499
2529
|
'datetime-local': {
|
|
2500
|
-
format: {final: {transform: (
|
|
2501
|
-
value
|
|
2530
|
+
format: {final: {transform: (
|
|
2531
|
+
value:Date|number|string,
|
|
2532
|
+
configuration:DefaultProperties<number>,
|
|
2533
|
+
transformer:InputDataTransformation
|
|
2534
|
+
):string => {
|
|
2535
|
+
if (typeof value !== 'number')
|
|
2536
|
+
if (transformer['datetime-local'].parse)
|
|
2537
|
+
value = transformer['datetime-local'].parse(
|
|
2538
|
+
value, configuration, transformer
|
|
2539
|
+
)
|
|
2540
|
+
else {
|
|
2541
|
+
const parsedDate:number = value instanceof Date ?
|
|
2542
|
+
value.getTime() / 1000 :
|
|
2543
|
+
Date.parse(value)
|
|
2544
|
+
if (isNaN(parsedDate)) {
|
|
2545
|
+
const parsedFloat:number = parseFloat(value as string)
|
|
2546
|
+
value = isNaN(parsedFloat) ? 0 : parsedFloat
|
|
2547
|
+
} else
|
|
2548
|
+
value = parsedDate / 1000
|
|
2549
|
+
}
|
|
2502
2550
|
|
|
2503
2551
|
if (value === Infinity)
|
|
2504
2552
|
return 'Infinitely far in the future'
|
|
@@ -2513,68 +2561,116 @@ GenericInput.transformer = {
|
|
|
2513
2561
|
return formattedValue.substring(0, formattedValue.length - 1)
|
|
2514
2562
|
}}},
|
|
2515
2563
|
parse: (
|
|
2516
|
-
value:number|string,
|
|
2564
|
+
value:Date|number|string,
|
|
2517
2565
|
configuration:DefaultProperties<number>,
|
|
2518
2566
|
transformer:InputDataTransformation
|
|
2519
|
-
):number =>
|
|
2520
|
-
transformer.date.parse
|
|
2521
|
-
transformer.date.parse(
|
|
2522
|
-
|
|
2567
|
+
):number => {
|
|
2568
|
+
if (transformer.date.parse)
|
|
2569
|
+
return transformer.date.parse(
|
|
2570
|
+
value, configuration, transformer
|
|
2571
|
+
)
|
|
2572
|
+
|
|
2573
|
+
if (value instanceof Date)
|
|
2574
|
+
return value.getTime() / 1000
|
|
2575
|
+
|
|
2576
|
+
const parsedDate:number = Date.parse(value as string)
|
|
2577
|
+
if (isNaN(parsedDate)) {
|
|
2578
|
+
const parsedFloat:number = parseFloat(value as string)
|
|
2579
|
+
if (isNaN(parsedFloat))
|
|
2580
|
+
return 0
|
|
2581
|
+
|
|
2582
|
+
return parsedFloat
|
|
2583
|
+
}
|
|
2584
|
+
|
|
2585
|
+
return parsedDate / 1000
|
|
2586
|
+
}
|
|
2523
2587
|
},
|
|
2524
2588
|
time: {
|
|
2525
|
-
format: {
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2589
|
+
format: {
|
|
2590
|
+
final: {transform: (
|
|
2591
|
+
value:Date|number|string,
|
|
2592
|
+
configuration:DefaultProperties<number>,
|
|
2593
|
+
transformer:InputDataTransformation
|
|
2594
|
+
):string => {
|
|
2595
|
+
if (typeof value !== 'number')
|
|
2596
|
+
if (transformer.time.parse)
|
|
2597
|
+
value = transformer.time.parse(
|
|
2598
|
+
value, configuration, transformer
|
|
2599
|
+
)
|
|
2600
|
+
else {
|
|
2601
|
+
const parsedDate:number = value instanceof Date ?
|
|
2602
|
+
value.getTime() / 1000 :
|
|
2603
|
+
Date.parse(value)
|
|
2604
|
+
if (isNaN(parsedDate)) {
|
|
2605
|
+
const parsedFloat:number =
|
|
2606
|
+
parseFloat(value as string)
|
|
2607
|
+
value = isNaN(parsedFloat) ? 0 : parsedFloat
|
|
2608
|
+
} else
|
|
2609
|
+
value = parsedDate / 1000
|
|
2610
|
+
}
|
|
2529
2611
|
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2612
|
+
if (value === Infinity)
|
|
2613
|
+
return 'Infinitely far in the future'
|
|
2614
|
+
if (value === -Infinity)
|
|
2615
|
+
return 'Infinitely early in the past'
|
|
2616
|
+
if (!isFinite(value))
|
|
2617
|
+
return ''
|
|
2536
2618
|
|
|
2537
|
-
|
|
2538
|
-
|
|
2619
|
+
let formattedValue:string =
|
|
2620
|
+
(new Date(Math.round(value * 1000))).toISOString()
|
|
2539
2621
|
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2622
|
+
formattedValue = formattedValue.substring(
|
|
2623
|
+
formattedValue.indexOf('T') + 1, formattedValue.length - 1
|
|
2624
|
+
)
|
|
2543
2625
|
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
)
|
|
2549
|
-
return formattedValue.substring(
|
|
2550
|
-
0, formattedValue.lastIndexOf(':')
|
|
2626
|
+
if (
|
|
2627
|
+
configuration.step &&
|
|
2628
|
+
configuration.step >= 60 &&
|
|
2629
|
+
(configuration.step % 60) === 0
|
|
2551
2630
|
)
|
|
2631
|
+
return formattedValue.substring(
|
|
2632
|
+
0, formattedValue.lastIndexOf(':')
|
|
2633
|
+
)
|
|
2552
2634
|
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
value
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
)
|
|
2577
|
-
|
|
2635
|
+
return formattedValue
|
|
2636
|
+
}}
|
|
2637
|
+
},
|
|
2638
|
+
parse: (value:Date|number|string):number => {
|
|
2639
|
+
if (typeof value === 'number')
|
|
2640
|
+
return value
|
|
2641
|
+
|
|
2642
|
+
if (value instanceof Date)
|
|
2643
|
+
return value.getTime() / 1000
|
|
2644
|
+
|
|
2645
|
+
const parsedDate:number = Date.parse(value)
|
|
2646
|
+
if (isNaN(parsedDate)) {
|
|
2647
|
+
const parsedFloat:number = parseFloat(value.replace(
|
|
2648
|
+
/^([0-9]{2}):([0-9]{2})(:([0-9]{2}(\.[0-9]+)?))?$/,
|
|
2649
|
+
(
|
|
2650
|
+
_match:string,
|
|
2651
|
+
hour:string,
|
|
2652
|
+
minute:string,
|
|
2653
|
+
secondsSuffix?:string,
|
|
2654
|
+
seconds?:string,
|
|
2655
|
+
_millisecondsSuffix?:string
|
|
2656
|
+
):string =>
|
|
2657
|
+
String(
|
|
2658
|
+
parseInt(hour) *
|
|
2659
|
+
60 ** 2 +
|
|
2660
|
+
parseInt(minute) *
|
|
2661
|
+
60 +
|
|
2662
|
+
(secondsSuffix ? parseFloat(seconds!) : 0)
|
|
2663
|
+
)
|
|
2664
|
+
))
|
|
2665
|
+
|
|
2666
|
+
if (isNaN(parsedFloat))
|
|
2667
|
+
return 0
|
|
2668
|
+
|
|
2669
|
+
return parsedFloat
|
|
2670
|
+
}
|
|
2671
|
+
|
|
2672
|
+
return parsedDate / 1000
|
|
2673
|
+
}
|
|
2578
2674
|
},
|
|
2579
2675
|
|
|
2580
2676
|
float: {
|