@fto-consult/expo-ui 5.7.0 → 5.7.2

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.
@@ -1,131 +0,0 @@
1
- import TextField from "./TextField";
2
- import PropTypes from "prop-types";
3
- import {isNonNullString,defaultStr} from "$cutils";
4
- import { UPPER_CASE } from "$src/lib/validator";
5
- //import {isDocUpdate} from "$database/utils";
6
-
7
- /*** le composant IdField reprend exactement les même propriétés
8
- * que le composant textField, elle doit cependant avoir obligatoirement un champ
9
- * name, un champ dbName, le nom de la bd ou vérifier l'unicité du champ
10
- */
11
- export default class IdField extends TextField {
12
- constructor(props){
13
- super(props)
14
- this.isDocUpdate = false;
15
- }
16
- getValidValue(data){
17
- let _id = super.getValidValue(data);
18
- if(this.props._id === false){
19
- return defaultStr(_id);
20
- }
21
- let prefix = defaultStr(this.props.table,this.props.tableName).toUpperCase().trim();
22
- if(this.props.prefix_on_id == false){
23
- prefix = "";
24
- } else ///les id des champs uniques sont définis de la forme : tableName/code
25
- if(isNonNullString(prefix)){
26
- prefix =prefix.rtrim("/")+"/";
27
- _id = defaultStr(_id).ltrim("/");
28
- }
29
- if(!isDocUpdate(data)){
30
- data._id = (prefix+_id).trim();
31
- }
32
- return defaultStr(_id).trim();
33
- }
34
- isValidRuleDynamic(){
35
- return true;
36
- }
37
- _render(props,setRef){
38
- let {dbName,_id,tableName,table,validType,validRule,fieldName,...p} = props;
39
- fieldName = defaultStr(fieldName,this.name,p.name);
40
- this.fieldName = fieldName;
41
- if(isNonNullString(fieldName) && isObj(props.data)){
42
- this.isDocUpdate = isDocUpdate(p.data) && isNonNullString(props.data[fieldName]);
43
- }
44
- tableName = defaultStr(tableName,table).toUpperCase();
45
- this.maxLength = undefined;
46
- validType = defaultStr(validType,validRule);
47
- if(this.isDocUpdate){
48
- p.disabled = true;
49
- p.validType = validType = UPPER_CASE;
50
- } else {
51
- //p.disabled = false;
52
- let maxLength = 15;
53
- if(isNumber(p.maxLength) && maxLength > 0){
54
- maxLength = p.maxLength;
55
- }
56
- if(!isNonNullString(dbName)) dbName = '';
57
- let prefix = tableName;
58
- if(this.props.prefix_on_id == false){
59
- prefix = "";
60
- }
61
- if(isNonNullString(prefix)){
62
- prefix = prefix.toUpperCase().trim()+"/";
63
- //les champs d'id unique pour la table sont définis de la forme : tableName/id
64
- //tableName = '';
65
- }
66
- if(isNonNullString(fieldName)){
67
- prefix = "";
68
- } else fieldName = "";
69
- let uniqV = 'uniqueid['+dbName+','+tableName+','+(p.label||p.text)+','+fieldName+','+prefix+']';
70
- let validType1 = 'maxLength['+maxLength+']';
71
-
72
- if(!validType.contains("maxLength")){
73
- validType = validType1.rtrim("|")+"|"+validType.trim().ltrim('|');
74
- }
75
- if(!validType.contains("required")){
76
- validType = "required|"+validType.ltrim("|");
77
- }
78
- if(!validType.contains(uniqV)){
79
- validType = validType.trim().rtrim('|')+"|"+uniqV;
80
- }
81
- if(!validType.contains(UPPER_CASE)){
82
- validType += "|"+UPPER_CASE
83
- }
84
- p.validType = validType;
85
- this.INITIAL_STATE.validRule = this.INITIAL_STATE.validType = validType;
86
- p.maxLength = maxLength;
87
- if(typeof p.minLength !=='number'){
88
- p.minLength = 2;
89
- }
90
- this.maxLength = maxLength;
91
- }
92
- if(p.disabled || p.readOnly || p.editable === false){
93
- p.contentContainerProps = Object.assign({},p.contentContainerProps)
94
- p.contentContainerProps.pointerEvents = defaultStr(p.contentContainerProps.pointerEvents,"auto");
95
- p.enableCopy = p.defaultValue ? true : false;
96
- }
97
- this.setValidRule(validType);
98
- p.upper = true;
99
- return super._render(p,setRef);
100
- }
101
- isTextField(){
102
- return false;
103
- }
104
- }
105
-
106
- IdField.propTypes = {
107
- /**** si le champ sera habileté de définir la valeur de l'id
108
- * Au fait lorsque dans une même table, il existe au moins deux champ de type pieceId, il est possible que le champ sélectionné pour générer
109
- * la valeur de l'id de la table ne soit pas le bon. pour éviter celà, il suffit de passer la props
110
- * _id à la valeur false dans tous les champs qui seront ignorés pour le calcul de l'id; ainsi, en cas de validation du champ, la valeur de l'_id de la table ne sera pas calculée
111
- */
112
- _id : PropTypes.bool,
113
- /*** le nom du champ qu'on valide
114
- * si fieldName est définie, alors, il est utilisé pour la validation du champ.
115
- * lorsque la valeur est mise à jour, on recherche en base toutes les objets ayant pour valeur ladite valeur
116
- * Si est trouvé, alors une erreur est retournée.
117
- * Dans le cas où fieldName est définie, alors, l'id n'est pas utilisé pour la validation
118
- *
119
- */
120
- fieldName : PropTypes.string,
121
- ///si les id de la table seront préfixés
122
- prefix_on_id : PropTypes.bool,
123
- ...TextField.propTypes,
124
- /*** le nom de la table dans laquelle l'idField est enreigistré */
125
- table : PropTypes.string,
126
- tableName : PropTypes.string, //idem à table
127
- /*** le nom de la bd où l'id field est enregistré */
128
- dbName : PropTypes.string,
129
- //la longueur maximale du champ
130
- maxLength:PropTypes.number
131
- }
@@ -1,136 +0,0 @@
1
- import TextField from "./TextField";
2
- import PropTypes from "prop-types";
3
- import { UPPER_CASE } from "$src/lib/validator";
4
- import {isNonNullString,defaultStr,isPromise} from "$cutils";
5
- import React from "$react";
6
- import { ActivityIndicator } from "react-native-paper";
7
-
8
- export default class FormPieceField extends TextField {
9
- constructor(props){
10
- super(props)
11
- this.autobind();
12
- }
13
- UNSAFE_componentWillReceiveProps(nextProps){
14
- this.newFieldPieceId = undefined;
15
- return super.UNSAFE_componentWillReceiveProps(nextProps);
16
- }
17
- componentDidMount(){
18
- super.componentDidMount();
19
- this.fetchNewId(false);
20
- }
21
- handleCheckIdError(msg,errorCb){
22
- this.canCheckAgain = false;
23
- this.hasError = true;
24
- if(isNonNullString(msg)) this.onNoValidate(msg,undefined,this,null,null);
25
- if(isFunction(errorCb)){
26
- errorCb(e);
27
- }
28
- }
29
-
30
- /*** met à jour la données du numéro de piece */
31
- fetchNewId(focus){
32
- const data = defaultObj(this.props.data);
33
- if(!isNonNullString(this.piece) && isNonNullString(this.name)) return undefined;
34
- if(isNonNullString(data[this.name])){
35
- this.newFieldPieceId = data[this.name];
36
- return this.newFieldPieceId;
37
- }
38
- setTimeout(()=>{
39
- const tableName = this.tableName = defaultStr(data.table,this.tableName,this.props.tableName,this.props.table);
40
- const fId = typeof this.props.fetchNewId =='function'? this.props.fetchNewId({...this.props,tableName,table:tableName}) : null;
41
- const cb = (value)=>{
42
- if(isNonNullString(value)){
43
- this.newFieldPieceId = value;
44
- this.validate({value});
45
- if(focus) this.focus();
46
- }
47
- }
48
-
49
- },0);
50
- }
51
- /*** retourne la valeur validée */
52
- getValidValue(data){
53
- const validValue = super.getValidValue(data);
54
- data.piece = defaultStr(data.piece,this.piece);
55
- data._id = defaultStr(data._id,validValue,this.newFieldPieceId);
56
- return validValue;
57
- }
58
- getUniqidArgs (){
59
- return {context:this,table:this.tableName,dbName:this.dbName,piece:this.piece}
60
- }
61
- isValidRuleDynamic(){
62
- return true;
63
- }
64
- isTextField(){
65
- return false;
66
- }
67
- componentDidUpdate(){
68
- if(!isNonNullString(this.newFieldPieceId) && this.piece){
69
- this.fetchNewId();
70
- }
71
- }
72
- _render(props,setRef){
73
- let {check,checkFields,dbName,tableName,table,piece,...p} = (props);
74
- check = defaultVal(check,checkFields);
75
- this.check = check;
76
- this.tableName = defaultStr(tableName,table).toUpperCase();
77
- this.dbName = defaultVal(dbName,'');
78
- this.piece = defaultVal(this.piece,piece);
79
- if(isFunction(piece)){
80
- this.piece = defaultStr(piece(this.getUniqidArgs()),this.piece);
81
- }
82
- p.readOnly = true;
83
- delete p.validType;
84
- if(isNonNullString(p.name) && isObj(p.data) && isNonNullString(p.data[p.name])){
85
- p.disabled = true;
86
- p.validType = UPPER_CASE;
87
- p.defaultValue = p.data[p.name];
88
- } else {
89
- p.validType = 'required|'+UPPER_CASE;
90
- }
91
- if(typeof p.minLength !=='number'){
92
- p.minLength = 2;
93
- }
94
- p.validRule = p.validType;
95
- if(p.disabled || p.readOnly || p.editable === false){
96
- const {right} = p;
97
- p.contentContainerProps = Object.assign({},p.contentContainerProps)
98
- p.contentContainerProps.pointerEvents = defaultStr(p.contentContainerProps.pointerEvents,"auto");
99
- ///p.enableCopy = p.defaultValue || this.newFieldPieceId ? true : false;
100
- p.right = (props)=>{
101
- const r = typeof right =='function'? right (props) : React.isValidElement(right)? right : null;
102
- if(!p.defaultValue){
103
- return <>{r}<ActivityIndicator
104
- {...props}
105
- style = {[props.style,{marginRight:10}]}
106
- /></>
107
- }
108
- return r;
109
- }
110
- }
111
- this.setValidRule(p.validType);
112
- return super._render(p,setRef);
113
- }
114
- }
115
-
116
- /*** le principe est de générer une id et vérifier l'existance deans la bd, jusqu'à retourner un
117
- * qui n'existe pas en bd
118
- */
119
- FormPieceField.propTypes = {
120
- ...TextField.propTypes,
121
- tableName : PropTypes.string.isRequired, //le nom de la table dans la bd où dans la liste des tables de pieces : CONSTANTS.PIECES
122
- //le type de données dont on veut déterminer le numéro de piece doit être obligatoire
123
- //ce type doit exister dans la table des piece : PIECE[table][type] doit retourner le prochain index
124
- ///si c'est une fonction elle doit être utilisée pour générer le préfix de la piece
125
- piece : PropTypes.oneOfType([
126
- PropTypes.string.isRequired,
127
- PropTypes.func.isRequired
128
- ]),
129
- /*** le nom de la table dans laquelle l'idField est enreigistré */
130
- /*** le nom de la bd où l'id field est enregistré */
131
- dbName : PropTypes.string,
132
- }
133
-
134
- FormPieceField.defaultProps = {
135
- name : '_id'
136
- }