@movalib/movalib-commons 1.0.41 → 1.0.43
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.
|
@@ -7,6 +7,7 @@ var jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
7
7
|
var material_1 = require("@mui/material");
|
|
8
8
|
var react_1 = require("react");
|
|
9
9
|
var VehicleTire_1 = __importDefault(require("./models/VehicleTire"));
|
|
10
|
+
var Tools_1 = require("./helpers/Tools");
|
|
10
11
|
// Regex pour une taille de pneumatique Française
|
|
11
12
|
var regex = /^\d{9}[A-Za-z]$/;
|
|
12
13
|
var MovaVehicleTireField = function (_a) {
|
|
@@ -16,7 +17,8 @@ var MovaVehicleTireField = function (_a) {
|
|
|
16
17
|
var _d = (0, react_1.useState)(false), error = _d[0], setError = _d[1];
|
|
17
18
|
var _e = (0, react_1.useState)(0), lastLength = _e[0], setLastLength = _e[1]; // Ajout d'un état pour stocker la longueur précédente
|
|
18
19
|
(0, react_1.useEffect)(function () {
|
|
19
|
-
|
|
20
|
+
console.log(vehicleTire);
|
|
21
|
+
setTireInfo((0, Tools_1.formatVehicleTire)(vehicleTire));
|
|
20
22
|
}, [vehicleTire]);
|
|
21
23
|
(0, react_1.useEffect)(function () {
|
|
22
24
|
// Cette expression régulière supprimera tous les caractères qui ne sont pas des chiffres ou des lettres alphabétiques, à l'exception de "R" et "r".
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import VehicleTire from "../models/VehicleTire";
|
|
1
2
|
import { MovaFormField } from "./Types";
|
|
3
|
+
export declare function formatVehicleTire(vehicleTire: VehicleTire): string;
|
|
4
|
+
export declare function formatVehicleTireStr(input: string): string;
|
|
2
5
|
/**
|
|
3
6
|
* Valide un champ de formulaire en utilisant une fonction de validation personnalisée.
|
|
4
7
|
*
|
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateField = void 0;
|
|
3
|
+
exports.validateField = exports.formatVehicleTireStr = exports.formatVehicleTire = void 0;
|
|
4
|
+
function formatVehicleTire(vehicleTire) {
|
|
5
|
+
if (vehicleTire) {
|
|
6
|
+
var concatened = "".concat(vehicleTire.width).concat(vehicleTire.height).concat(vehicleTire.diameter).concat(vehicleTire.speedIndex);
|
|
7
|
+
return formatVehicleTireStr(concatened);
|
|
8
|
+
}
|
|
9
|
+
return '';
|
|
10
|
+
}
|
|
11
|
+
exports.formatVehicleTire = formatVehicleTire;
|
|
12
|
+
function formatVehicleTireStr(input) {
|
|
13
|
+
var formatted = input.toUpperCase().replace(/[^0-9A-QS-Za-qs-z]/g, '').slice(0, 10);
|
|
14
|
+
if (formatted.length >= 3) {
|
|
15
|
+
formatted = "".concat(formatted.substring(0, 3), " / ").concat(formatted.substring(3));
|
|
16
|
+
}
|
|
17
|
+
var indexOfR = formatted.indexOf(" R");
|
|
18
|
+
if (formatted.length >= 8 && indexOfR === -1) {
|
|
19
|
+
formatted = "".concat(formatted.substring(0, 8), " R").concat(formatted.substring(8));
|
|
20
|
+
if (formatted.length >= 12 && indexOfR === -1)
|
|
21
|
+
formatted = "".concat(formatted.substring(0, 12), " ").concat(formatted.substring(12));
|
|
22
|
+
}
|
|
23
|
+
else if (indexOfR !== -1 && formatted.length > indexOfR + 2) {
|
|
24
|
+
formatted = "".concat(formatted.substring(0, indexOfR + 2), " ").concat(formatted.substring(indexOfR + 2));
|
|
25
|
+
}
|
|
26
|
+
console.log(formatted);
|
|
27
|
+
return formatted;
|
|
28
|
+
}
|
|
29
|
+
exports.formatVehicleTireStr = formatVehicleTireStr;
|
|
30
|
+
;
|
|
4
31
|
/**
|
|
5
32
|
* Valide un champ de formulaire en utilisant une fonction de validation personnalisée.
|
|
6
33
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TextField } from '@mui/material';
|
|
2
2
|
import { useState, type FC, useEffect } from 'react';
|
|
3
3
|
import VehicleTire from './models/VehicleTire';
|
|
4
|
+
import { formatVehicleTire } from './helpers/Tools';
|
|
4
5
|
|
|
5
6
|
interface MovaVehicleTireFieldProps {
|
|
6
7
|
vehicleTire: VehicleTire,
|
|
@@ -18,8 +19,9 @@ const MovaVehicleTireField: FC<MovaVehicleTireFieldProps> = ({ vehicleTire, onCh
|
|
|
18
19
|
const [lastLength, setLastLength] = useState<number>(0); // Ajout d'un état pour stocker la longueur précédente
|
|
19
20
|
|
|
20
21
|
useEffect(() => {
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
console.log(vehicleTire);
|
|
23
|
+
setTireInfo(formatVehicleTire(vehicleTire));
|
|
24
|
+
}, [vehicleTire]);
|
|
23
25
|
|
|
24
26
|
useEffect(() => {
|
|
25
27
|
|
|
@@ -101,4 +103,4 @@ const MovaVehicleTireField: FC<MovaVehicleTireFieldProps> = ({ vehicleTire, onCh
|
|
|
101
103
|
);
|
|
102
104
|
}
|
|
103
105
|
|
|
104
|
-
export default MovaVehicleTireField;
|
|
106
|
+
export default MovaVehicleTireField;
|
package/src/helpers/Tools.ts
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
|
+
import VehicleTire from "../models/VehicleTire";
|
|
1
2
|
import { MovaFormField } from "./Types";
|
|
2
3
|
|
|
4
|
+
export function formatVehicleTire(vehicleTire: VehicleTire){
|
|
5
|
+
if(vehicleTire){
|
|
6
|
+
let concatened = `${vehicleTire.width}${vehicleTire.height}${vehicleTire.diameter}${vehicleTire.speedIndex}`;
|
|
7
|
+
return formatVehicleTireStr(concatened);
|
|
8
|
+
}
|
|
9
|
+
return '';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function formatVehicleTireStr(input: string){
|
|
13
|
+
|
|
14
|
+
let formatted = input.toUpperCase().replace(/[^0-9A-QS-Za-qs-z]/g, '').slice(0, 10);
|
|
15
|
+
|
|
16
|
+
if (formatted.length >= 3) {
|
|
17
|
+
formatted = `${formatted.substring(0, 3)} / ${formatted.substring(3)}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const indexOfR = formatted.indexOf(" R");
|
|
21
|
+
|
|
22
|
+
if (formatted.length >= 8 && indexOfR === -1) {
|
|
23
|
+
formatted = `${formatted.substring(0, 8)} R${formatted.substring(8)}`;
|
|
24
|
+
|
|
25
|
+
if (formatted.length >= 12 && indexOfR === -1)
|
|
26
|
+
formatted = `${formatted.substring(0, 12)} ${formatted.substring(12)}`;
|
|
27
|
+
|
|
28
|
+
} else if (indexOfR !== -1 && formatted.length > indexOfR + 2) {
|
|
29
|
+
formatted = `${formatted.substring(0, indexOfR + 2)} ${formatted.substring(indexOfR + 2)}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
console.log(formatted);
|
|
33
|
+
return formatted;
|
|
34
|
+
};
|
|
35
|
+
|
|
3
36
|
/**
|
|
4
37
|
* Valide un champ de formulaire en utilisant une fonction de validation personnalisée.
|
|
5
38
|
*
|