@fto-consult/expo-ui 8.11.0 → 8.12.0
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/package.json +2 -2
- package/src/components/Barcode/Designer/index.js +0 -3
- package/src/components/Barcode/Generator/Generator.js +3 -5
- package/src/components/Barcode/Generator/index.js +15 -49
- package/src/components/Barcode/Generator/utils.js +64 -1
- package/src/components/Barcode/utils.js +20 -6
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fto-consult/expo-ui",
|
3
|
-
"version": "8.
|
3
|
+
"version": "8.12.0",
|
4
4
|
"description": "Bibliothèque de composants UI Expo,react-native",
|
5
5
|
"scripts": {
|
6
6
|
"clear-npx-cache": "npx clear-npx-cache",
|
@@ -70,7 +70,7 @@
|
|
70
70
|
"dependencies": {
|
71
71
|
"@emotion/react": "^11.11.1",
|
72
72
|
"@faker-js/faker": "^8.0.2",
|
73
|
-
"@fto-consult/common": "^4.13.
|
73
|
+
"@fto-consult/common": "^4.13.9",
|
74
74
|
"@fto-consult/node-utils": "^1.4.7",
|
75
75
|
"apexcharts": "^3.45.2",
|
76
76
|
"commander": "^11.1.0",
|
@@ -253,9 +253,6 @@ const BarcodeDesigner = forwardRef(({
|
|
253
253
|
{...state}
|
254
254
|
displayValue = {!!state.displayValue}
|
255
255
|
autoConvertToDataURL = {false}
|
256
|
-
onConvertToDataURL = {(dataURL)=>{
|
257
|
-
console.log(dataURL,"converting to dataurl");
|
258
|
-
}}
|
259
256
|
ref = {useMergeRefs(ref,innerRef)}
|
260
257
|
/>
|
261
258
|
{React.isValidElement(rightContent) ?rightContent : null}
|
@@ -5,10 +5,9 @@ import {jsbarcodePropTypes } from "./utils";
|
|
5
5
|
import View from "$ecomponents/View";
|
6
6
|
|
7
7
|
///@see : https://lindell.me/JsBarcode/
|
8
|
-
const BarcodeGeneratorComponent = forwardRef(({value,format,id,errorText,testID,onReady,text,flat,width,height,displayValue,fontOptions,font,textAlign,textPosition,textMargin,fontSize,background,lineColor,margin,marginTop,marginBottom,marginLeft,marginRight,valid},ref)=>{
|
8
|
+
const BarcodeGeneratorComponent = forwardRef(({value,as:asTag,format,id,errorText,testID,onReady,text,flat,width,height,displayValue,fontOptions,font,textAlign,textPosition,textMargin,fontSize,background,lineColor,margin,marginTop,marginBottom,marginLeft,marginRight,valid},ref)=>{
|
9
9
|
testID = defaultStr(testID,"RN_GeneratorWebSVG");
|
10
10
|
const idRef = useRef(defaultStr(id,uniqid("bar-code-generator-web")));
|
11
|
-
const innerRef = useRef(null);
|
12
11
|
const error = React.isValidElement(errorText)? errorText : null;
|
13
12
|
if(error){
|
14
13
|
displayValue = false;
|
@@ -27,9 +26,8 @@ const BarcodeGeneratorComponent = forwardRef(({value,format,id,errorText,testID,
|
|
27
26
|
}
|
28
27
|
},[value,error,format,width,height,displayValue,flat,text,fontOptions,font,textAlign,textPosition,textMargin,fontSize,background,lineColor,margin,marginTop,marginBottom,marginLeft,marginRight])
|
29
28
|
if(error) return error;
|
30
|
-
|
31
|
-
|
32
|
-
</View>
|
29
|
+
const Tag = asTag || "img";
|
30
|
+
return <Tag id={`${idRef.current}`} ref={ref} data-test-id={`${testID}`} className="bar-code-generator-svg"/>
|
33
31
|
});
|
34
32
|
|
35
33
|
BarcodeGeneratorComponent.displayName = "BarcodeGeneratorComponent";
|
@@ -5,15 +5,14 @@ import theme,{StyleProp} from "$theme";
|
|
5
5
|
import {defaultStr,defaultObj,isNonNullString,extendObj,uniqid,isDataURL} from "$cutils";
|
6
6
|
import Generator from "./Generator";
|
7
7
|
import {isMobileNative} from "$cplatform";
|
8
|
-
import { defaultBarcodeFormat,barcodeFormats,jsbarcodePropTypes,encode } from './utils';
|
9
|
-
import { captureRef } from '$expo-ui/view-shot';
|
10
|
-
import Base64 from "$base64";
|
8
|
+
import { defaultBarcodeFormat,barcodeFormats,toDataURL,jsbarcodePropTypes,encode } from './utils';
|
11
9
|
import Label from "$ecomponents/Label";
|
12
10
|
|
13
11
|
export * from "./utils";
|
14
12
|
|
15
13
|
const BarcodeGenerator = forwardRef(({
|
16
14
|
value = '',
|
15
|
+
as,
|
17
16
|
width = 2,
|
18
17
|
height = 100,
|
19
18
|
format,
|
@@ -119,57 +118,27 @@ const BarcodeGenerator = forwardRef(({
|
|
119
118
|
};
|
120
119
|
}
|
121
120
|
}, [value, width, height, format, lineColor, maxWidth]);
|
121
|
+
const _toDataURL = ()=>{
|
122
|
+
return toDataURL(innerRef.current,{
|
123
|
+
onConvertToDataURL,dataURLOptions,
|
124
|
+
});
|
125
|
+
}
|
122
126
|
useEffect(()=>{
|
123
|
-
if(
|
124
|
-
|
127
|
+
if(autoConvertToDataURL === true){
|
128
|
+
_toDataURL();
|
125
129
|
}
|
126
130
|
},[format,value,width,height,lineColor])
|
127
|
-
|
128
|
-
return new Promise((resolve,reject)=>{
|
129
|
-
const cb2 = (x, y, width, height) => {
|
130
|
-
return captureRef(innerRef.current,extendObj({},{
|
131
|
-
quality: 1,
|
132
|
-
format: 'png',
|
133
|
-
result : "data-uri",
|
134
|
-
width,
|
135
|
-
height,
|
136
|
-
},dataURLOptions)).then((r)=>{
|
137
|
-
if(isDataURL(r) && typeof onConvertToDataURL =="function"){
|
138
|
-
onConvertToDataURL({dataURL:r});
|
139
|
-
}
|
140
|
-
resolve({dataURL:r,width,height});
|
141
|
-
}).catch((e)=>{
|
142
|
-
console.log(e," is capturing data url");
|
143
|
-
reject(e);
|
144
|
-
});
|
145
|
-
};
|
146
|
-
if(!isMobileNative() && typeof document !=="undefined" && typeof document?.querySelector =='function'){
|
147
|
-
const canvas = document.querySelector(`#${idRef.current}`);
|
148
|
-
if(canvas){
|
149
|
-
if(typeof canvas?.toDataURL =='function'){
|
150
|
-
return resolve(canvas.toDataURL());
|
151
|
-
}
|
152
|
-
} else {
|
153
|
-
try {
|
154
|
-
const {width,height} = canvas?.getBoundingClientRect();
|
155
|
-
return cb2(undefined,undefined,width,height);
|
156
|
-
} catch(e){
|
157
|
-
reject(e);
|
158
|
-
}
|
159
|
-
}
|
160
|
-
}
|
161
|
-
return innerRef.current?.measureInWindow(cb2);
|
162
|
-
});
|
163
|
-
}
|
131
|
+
|
164
132
|
return (<Generator
|
165
133
|
{...rest}
|
134
|
+
as={as}
|
166
135
|
errorText = {error ? <Label style={{textAlign:'center'}} error fontSize={15} textBold>
|
167
136
|
{error?.toString()}
|
168
137
|
</Label>: null}
|
169
138
|
id = {idRef.current}
|
170
139
|
onReady = {()=>{
|
171
140
|
if(typeof onReady =="function"){
|
172
|
-
return onReady({toDataURL});
|
141
|
+
return onReady({toDataURL:_toDataURL});
|
173
142
|
}
|
174
143
|
}}
|
175
144
|
value = {value}
|
@@ -181,12 +150,9 @@ const BarcodeGenerator = forwardRef(({
|
|
181
150
|
width = {isMobileNative()?barCodeWidth:width}
|
182
151
|
height = {height}
|
183
152
|
lineColor = {lineColor}
|
184
|
-
ref = {(
|
185
|
-
|
186
|
-
|
187
|
-
}
|
188
|
-
innerRef.current = el;
|
189
|
-
React.setRef(ref,el);
|
153
|
+
ref = {(element)=>{
|
154
|
+
innerRef.current = element;
|
155
|
+
React.setRef(ref,{element,toDataURL});
|
190
156
|
}}
|
191
157
|
/>);
|
192
158
|
});
|
@@ -1,6 +1,9 @@
|
|
1
1
|
import barcodes from 'jsbarcode/src/barcodes';
|
2
2
|
import PropTypes from "prop-types";
|
3
|
-
import {defaultObj} from "$cutils";
|
3
|
+
import {defaultObj,defaultNumber} from "$cutils";
|
4
|
+
import { captureRef } from '$expo-ui/view-shot';
|
5
|
+
import {isDataURL} from "$cutils";
|
6
|
+
import {isMobileNative} from "$cplatform";
|
4
7
|
|
5
8
|
export const barcodeFormats = Object.keys(barcodes);
|
6
9
|
|
@@ -101,3 +104,63 @@ export const encode = (options,format)=>{
|
|
101
104
|
return null;
|
102
105
|
}
|
103
106
|
}
|
107
|
+
|
108
|
+
|
109
|
+
/*** exporte au format dataURL
|
110
|
+
@param {domElement|nativeElement} element, l'élement dom ou l'élément react native
|
111
|
+
@param {object} options, les options supplémentaires
|
112
|
+
*/
|
113
|
+
export const toDataURL = (element,options)=>{
|
114
|
+
if(!element){
|
115
|
+
return Promise.reject({message:`Impossible de convertir le code barre en dataURL, rassurer vous que le premier argument de la fonction toDataURL soit un élément dom ou un élement react natif`,options})
|
116
|
+
}
|
117
|
+
options = defaultObj(options);
|
118
|
+
const {onConvertToDataURL,...dataURLOptions} = options;
|
119
|
+
return new Promise((resolve,reject)=>{
|
120
|
+
const final = (dataURL,rest)=>{
|
121
|
+
dataURL = isDataURL(dataURL)? dataURL : undefined;
|
122
|
+
const result = {...defaultObj(rest),dataURL};
|
123
|
+
if(dataURL){
|
124
|
+
if(typeof onConvertToDataURL =="function"){
|
125
|
+
onConvertToDataURL(result);
|
126
|
+
}
|
127
|
+
return resolve(result);
|
128
|
+
}
|
129
|
+
reject({...result,message:`Image non valide!! le fichier dataURL généré est non valide`,status:false})
|
130
|
+
}
|
131
|
+
const cb2 = (x, y, width, height) => {
|
132
|
+
return captureRef(element,extendObj({},{
|
133
|
+
quality: 1,
|
134
|
+
format: 'png',
|
135
|
+
result : "data-uri",
|
136
|
+
width,
|
137
|
+
height,
|
138
|
+
},dataURLOptions)).then(final).catch((e)=>{
|
139
|
+
console.log(e," is capturing data url");
|
140
|
+
reject(e);
|
141
|
+
});
|
142
|
+
};
|
143
|
+
if(!isMobileNative() && typeof document !=="undefined" && typeof document?.querySelector =='function'){
|
144
|
+
if(typeof element?.toDataURL =='function'){
|
145
|
+
const {width,height} = typeof element.getBoundingClientRect =="function"? element.getBoundingClientRect() : {};
|
146
|
+
return final(element.toDataURL(),{width,height});
|
147
|
+
}
|
148
|
+
const src = typeof element?.getAttribute =='function' && element?.getAttribute("src");
|
149
|
+
if(isDataURL(src)){
|
150
|
+
const width = defaultNumber(element.width,element.naturalWidth,element.clientWidth);
|
151
|
+
const height = defaultNumber(element.height,element.naturalHeight,element.clientHeight);
|
152
|
+
return final(src,{width,height});
|
153
|
+
}
|
154
|
+
try {
|
155
|
+
const ob = element?.getBoundingClientRect();
|
156
|
+
if(isObj(ob)){
|
157
|
+
const {width,height} = ob;
|
158
|
+
return cb2(undefined,undefined,width,height);
|
159
|
+
}
|
160
|
+
} catch(e){
|
161
|
+
reject(e);
|
162
|
+
}
|
163
|
+
}
|
164
|
+
return element?.measureInWindow(cb2);
|
165
|
+
});
|
166
|
+
}
|
@@ -2,6 +2,7 @@
|
|
2
2
|
import {defaultNumber,isNonNullString} from "$cutils";
|
3
3
|
import Preloader from "$preloader";
|
4
4
|
import JsBarcode from "jsbarcode";
|
5
|
+
import { toDataURL } from "./Generator/utils";
|
5
6
|
|
6
7
|
/*** permet de generer une liste des codes barres à partir des props passés en paramètre
|
7
8
|
*/
|
@@ -25,18 +26,31 @@ export function generate ({startSequence,onFinish,barcodeTemplate,barcodeOptions
|
|
25
26
|
setTimeout(()=>{
|
26
27
|
for(let sequence=startSequence;sequence<=endSequence;sequence++){
|
27
28
|
promises.push(new Promise((resolve)=>{
|
28
|
-
const
|
29
|
+
const hasSerializer = typeof window?.XMLSerializer !=="undefined" && window?.XMLSerializer;
|
30
|
+
const canvas = document.createElement(hasSerializer ? 'svg':'img');
|
29
31
|
const b = generate({sequence,template:barcodeTemplate,barcodeTemplate});
|
30
32
|
const barcode = isNonNullString(b)? b : defaultStr(barcodeTemplate);//.replaceAll("{sequence}",sequence)
|
31
33
|
if(barcode){
|
32
34
|
Preloader.open(`${prefix} [${barcode}]...`)
|
33
35
|
try {
|
34
36
|
JsBarcode(canvas,barcode,barcodeOptions);
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
if(hasSerializer){
|
38
|
+
const serializer = new XMLSerializer();
|
39
|
+
const svg = serializer.serializeToString(canvas);
|
40
|
+
const ret = {svg,barcode};
|
41
|
+
data.push(ret)
|
42
|
+
return resolve(ret);
|
43
|
+
}
|
44
|
+
return toDataURL(canvas).then((ret)=>{
|
45
|
+
ret = {...ret,barcode};
|
46
|
+
data.push(ret)
|
47
|
+
resolve(ret)
|
48
|
+
}).catch((e)=>{
|
49
|
+
console.log(e," converting ",barcode," to data url")
|
50
|
+
resolve({message:`Unable to convert barcode ${barcode} to dataURL`,status:false})
|
51
|
+
})
|
39
52
|
} catch(e){
|
53
|
+
console.log(e," occurred on generating barcode ",barcode," for sequence ",sequence);
|
40
54
|
resolve({error:e})
|
41
55
|
}
|
42
56
|
} else {
|
@@ -44,7 +58,7 @@ export function generate ({startSequence,onFinish,barcodeTemplate,barcodeOptions
|
|
44
58
|
}
|
45
59
|
}));
|
46
60
|
}
|
47
|
-
return Promise.all(promises).then(()=>{
|
61
|
+
return Promise.all(promises).then((allD)=>{
|
48
62
|
resolve(data);
|
49
63
|
}).catch((e)=>{
|
50
64
|
console.log(e," generation barcode");
|