datasync-blob 1.0.2 → 1.1.1

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.
@@ -0,0 +1,38 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { Component, ChangeEvent } from 'react';
3
+
4
+ interface DsBlobProps {
5
+ width?: number;
6
+ height?: number;
7
+ maxWidth?: number;
8
+ maxHeight?: number;
9
+ reduceImage?: boolean;
10
+ jpegQuality?: number;
11
+ removebase64?: boolean;
12
+ uploadPicture: (data: {
13
+ data: string;
14
+ item_id: any;
15
+ }) => void;
16
+ item_id: any;
17
+ data?: string;
18
+ buttonStyle?: string;
19
+ Caption?: string;
20
+ pictureStyle?: string;
21
+ readOnly?: boolean;
22
+ }
23
+ interface DsBlobState {
24
+ hover_input: boolean;
25
+ hover_image: boolean;
26
+ }
27
+ declare class DsBlob extends Component<DsBlobProps, DsBlobState> {
28
+ private debugging;
29
+ constructor(props: DsBlobProps);
30
+ reduceImage: (e: Event) => void;
31
+ storeImageToImg: (e: ProgressEvent<FileReader>) => void;
32
+ readImage: (aPictureFile: File) => Promise<void>;
33
+ resetUpload: () => void;
34
+ onInputChange: (e: ChangeEvent<HTMLInputElement>) => void;
35
+ render(): react_jsx_runtime.JSX.Element;
36
+ }
37
+
38
+ export { DsBlob };
@@ -0,0 +1,38 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { Component, ChangeEvent } from 'react';
3
+
4
+ interface DsBlobProps {
5
+ width?: number;
6
+ height?: number;
7
+ maxWidth?: number;
8
+ maxHeight?: number;
9
+ reduceImage?: boolean;
10
+ jpegQuality?: number;
11
+ removebase64?: boolean;
12
+ uploadPicture: (data: {
13
+ data: string;
14
+ item_id: any;
15
+ }) => void;
16
+ item_id: any;
17
+ data?: string;
18
+ buttonStyle?: string;
19
+ Caption?: string;
20
+ pictureStyle?: string;
21
+ readOnly?: boolean;
22
+ }
23
+ interface DsBlobState {
24
+ hover_input: boolean;
25
+ hover_image: boolean;
26
+ }
27
+ declare class DsBlob extends Component<DsBlobProps, DsBlobState> {
28
+ private debugging;
29
+ constructor(props: DsBlobProps);
30
+ reduceImage: (e: Event) => void;
31
+ storeImageToImg: (e: ProgressEvent<FileReader>) => void;
32
+ readImage: (aPictureFile: File) => Promise<void>;
33
+ resetUpload: () => void;
34
+ onInputChange: (e: ChangeEvent<HTMLInputElement>) => void;
35
+ render(): react_jsx_runtime.JSX.Element;
36
+ }
37
+
38
+ export { DsBlob };
package/dist/index.js ADDED
@@ -0,0 +1,243 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var __async = (__this, __arguments, generator) => {
20
+ return new Promise((resolve, reject) => {
21
+ var fulfilled = (value) => {
22
+ try {
23
+ step(generator.next(value));
24
+ } catch (e) {
25
+ reject(e);
26
+ }
27
+ };
28
+ var rejected = (value) => {
29
+ try {
30
+ step(generator.throw(value));
31
+ } catch (e) {
32
+ reject(e);
33
+ }
34
+ };
35
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
36
+ step((generator = generator.apply(__this, __arguments)).next());
37
+ });
38
+ };
39
+
40
+ // src/index.ts
41
+ var index_exports = {};
42
+ __export(index_exports, {
43
+ DsBlob: () => DsBlob
44
+ });
45
+ module.exports = __toCommonJS(index_exports);
46
+
47
+ // src/components/DsBlob.tsx
48
+ var import_react = require("react");
49
+ var import_jsx_runtime = require("react/jsx-runtime");
50
+ var DsBlob = class extends import_react.Component {
51
+ constructor(props) {
52
+ super(props);
53
+ //-----------------------------------------------------------------------------------------------------------------------------------------
54
+ this.reduceImage = (e) => {
55
+ let imageSource = e.path && e.path[0] || e.srcElement;
56
+ if (this.debugging) console.log("imageSource = ", imageSource);
57
+ var canvas = document.createElement("canvas"), context, width = imageSource.width, height = imageSource.height;
58
+ if (this.props.width && this.props.height) {
59
+ if (width > this.props.width || height > this.props.height) {
60
+ alert("L'image est trop grande, le format requis est " + this.props.width + "x" + this.props.height);
61
+ return;
62
+ }
63
+ if (width < this.props.width || height < this.props.height) {
64
+ alert("L'image est trop petite, le format requis est " + this.props.width + "x" + this.props.height);
65
+ return;
66
+ }
67
+ }
68
+ if (this.props.maxWidth && this.props.maxHeight) {
69
+ if (width > height) {
70
+ if (!this.props.reduceImage) {
71
+ alert("L'image est trop large ! la largeur maximale est de " + this.props.maxWidth);
72
+ return;
73
+ }
74
+ if (width > this.props.maxWidth) {
75
+ height *= this.props.maxWidth / width;
76
+ width = this.props.maxWidth;
77
+ }
78
+ } else {
79
+ if (height > this.props.maxHeight) {
80
+ if (!this.props.reduceImage) {
81
+ alert("L'image est trop haute, la hauteur maximale est de " + this.props.maxHeight);
82
+ return;
83
+ }
84
+ width *= this.props.maxHeight / height;
85
+ height = this.props.maxHeight;
86
+ }
87
+ }
88
+ }
89
+ canvas.width = width;
90
+ canvas.height = height;
91
+ context = canvas.getContext("2d");
92
+ context.drawImage(imageSource, 0, 0, width, height);
93
+ let jpegCompressionRatio = this.props.jpegQuality && this.props.jpegQuality > 0 && this.props.jpegQuality < 1 ? this.props.jpegQuality : 1;
94
+ let canvasData = canvas.toDataURL("image/jpg", jpegCompressionRatio);
95
+ if (this.debugging)
96
+ console.log("jpegCompressionRatio->", jpegCompressionRatio, " canvasData.length = ", canvasData.length);
97
+ if (this.props.removebase64) {
98
+ this.props.uploadPicture({ data: canvasData ? canvasData.substring("data:image/png;base64".length) : "", item_id: this.props.item_id });
99
+ } else {
100
+ this.props.uploadPicture({ data: canvasData ? canvasData : "", item_id: this.props.item_id });
101
+ }
102
+ };
103
+ //-----------------------------------------------------------------------------------------------------------------------------------------
104
+ this.storeImageToImg = (e) => {
105
+ var image = document.createElement("img");
106
+ image.onload = this.reduceImage;
107
+ image.src = e.currentTarget.result;
108
+ };
109
+ //-----------------------------------------------------------------------------------------------------------------------------------------
110
+ this.readImage = (aPictureFile) => __async(this, null, function* () {
111
+ let _reader = new FileReader();
112
+ _reader.onload = this.storeImageToImg;
113
+ _reader.readAsDataURL(aPictureFile);
114
+ });
115
+ //-----------------------------------------------------------------------------------------------------------------------------------------
116
+ this.resetUpload = () => {
117
+ this.props.uploadPicture({ data: "", item_id: this.props.item_id });
118
+ };
119
+ //-----------------------------------------------------------------------------------------------------------------------------------------
120
+ this.onInputChange = (e) => {
121
+ const errs = [];
122
+ const files = Array.from(e.target.files || []);
123
+ const types = ["image/png", "image/jpeg", "image/gif"];
124
+ const _1Mo = 1024 * 1024;
125
+ const SizeLimit = 9;
126
+ e.target.value = "";
127
+ if (this.debugging)
128
+ console.log("onInputChange");
129
+ if (files.length > 1) {
130
+ const msg = "Pas plus d'une image \xE0 la fois";
131
+ alert(msg);
132
+ return;
133
+ }
134
+ files.forEach((file, i) => {
135
+ let errCount = errs.length;
136
+ if (types.every((type) => file.type !== type)) {
137
+ errs.push(`'${file.type}' : format non support\xE9`);
138
+ }
139
+ if (file.size > SizeLimit * _1Mo) {
140
+ errs.push(`'${file.name}' image trop volumineuse (max:${SizeLimit}M\xE9ga-octets)`);
141
+ }
142
+ if (this.debugging)
143
+ console.log(`errCount = ${errCount} vs errs.length = ${errs.length}`);
144
+ if (errCount == errs.length) {
145
+ if (this.debugging)
146
+ console.log("readImage::", file.name);
147
+ this.readImage(file);
148
+ }
149
+ });
150
+ if (errs.length) {
151
+ return errs.forEach((err) => alert(err));
152
+ }
153
+ };
154
+ this.state = { hover_input: false, hover_image: false };
155
+ this.debugging = false;
156
+ }
157
+ render() {
158
+ const upload_picture_label = {
159
+ cursor: "pointer"
160
+ };
161
+ const upload_picture_label_input = {
162
+ opacity: "0",
163
+ width: "0px",
164
+ height: "0px"
165
+ };
166
+ const div_show_image_hover = {
167
+ position: "relative",
168
+ margin: "0px",
169
+ opacity: "0.5"
170
+ };
171
+ const div_show_image = {
172
+ position: "relative",
173
+ margin: "0px"
174
+ };
175
+ const div_show_image_hover_input = {
176
+ display: "block",
177
+ top: "0px",
178
+ left: "0px",
179
+ position: "absolute"
180
+ };
181
+ const div_show_image_input = {
182
+ position: "absolute",
183
+ display: "none",
184
+ cursor: "pointer"
185
+ };
186
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
187
+ !this.props.data && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
188
+ "label",
189
+ {
190
+ id: "upload-picture-label",
191
+ className: this.props.buttonStyle,
192
+ style: upload_picture_label,
193
+ children: [
194
+ this.props.Caption,
195
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { style: upload_picture_label_input, id: "nested-input", type: "file", accept: "image/*", onChange: this.onInputChange, multiple: true })
196
+ ]
197
+ }
198
+ ),
199
+ this.props.data && this.props.data.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
200
+ "div",
201
+ {
202
+ className: "show-image",
203
+ style: div_show_image,
204
+ onMouseOver: () => {
205
+ this.setState({ hover_input: true, hover_image: true }, () => {
206
+ if (this.debugging) console.log("onMouseOver");
207
+ });
208
+ },
209
+ onMouseLeave: () => {
210
+ this.setState({ hover_input: false, hover_image: false }, () => {
211
+ if (this.debugging) console.log("onMouseLeave");
212
+ });
213
+ },
214
+ children: [
215
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
216
+ "img",
217
+ {
218
+ style: this.state.hover_image ? div_show_image_hover : div_show_image,
219
+ src: this.props.removebase64 ? "data:image/png;base64" : "" + this.props.data,
220
+ className: this.props.pictureStyle
221
+ }
222
+ ),
223
+ !this.props.readOnly && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
224
+ "input",
225
+ {
226
+ style: this.state.hover_input ? div_show_image_hover_input : div_show_image_input,
227
+ className: "btn btn-primary delete",
228
+ type: "button",
229
+ value: "Effacer",
230
+ onClick: this.resetUpload
231
+ }
232
+ )
233
+ ]
234
+ }
235
+ )
236
+ ] });
237
+ }
238
+ };
239
+ // Annotate the CommonJS export names for ESM import in node:
240
+ 0 && (module.exports = {
241
+ DsBlob
242
+ });
243
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/components/DsBlob.tsx"],"sourcesContent":["export {DsBlob} from './components/DsBlob';","\nimport React, { Component, ChangeEvent, MouseEvent } from \"react\";\n\ninterface DsBlobProps {\n width?: number;\n height?: number;\n maxWidth?: number;\n maxHeight?: number;\n reduceImage?: boolean;\n jpegQuality?: number;\n removebase64?: boolean;\n uploadPicture: (data: { data: string; item_id: any }) => void;\n item_id: any;\n data?: string;\n buttonStyle?: string;\n Caption?: string;\n pictureStyle?: string;\n readOnly?: boolean;\n}\n\ninterface DsBlobState {\n hover_input: boolean;\n hover_image: boolean;\n}\n\nexport class DsBlob extends Component<DsBlobProps, DsBlobState> {\n private debugging: boolean;\n\n constructor(props: DsBlobProps) {\n super(props);\n this.state = { hover_input: false, hover_image: false };\n this.debugging = false;\n }\n\n //-----------------------------------------------------------------------------------------------------------------------------------------\n reduceImage = (e: Event) => {\n let imageSource = ((e as any).path && (e as any).path[0]) || (e as any).srcElement as HTMLImageElement; //Safari compliancy\n\n if (this.debugging) console.log(\"imageSource = \", imageSource);\n var canvas = document.createElement('canvas'),\n context: CanvasRenderingContext2D | null,\n width = imageSource.width,\n height = imageSource.height;\n\n //Exact size props are set\n if (this.props.width && this.props.height) {\n //Check image size\n if (width > this.props.width || height > this.props.height) {\n alert(\"L'image est trop grande, le format requis est \" + this.props.width + \"x\" + this.props.height);\n return\n }\n\n //Check image size\n if (width < this.props.width || height < this.props.height) {\n alert(\"L'image est trop petite, le format requis est \" + this.props.width + \"x\" + this.props.height);\n return\n }\n }\n\n //Max size props are set\n if (this.props.maxWidth && this.props.maxHeight) {\n if (width > height) {\n //Check resize is enabled\n if (!this.props.reduceImage) {\n alert(\"L'image est trop large ! la largeur maximale est de \" + this.props.maxWidth);\n return\n }\n if (width > this.props.maxWidth) {\n height *= this.props.maxWidth / width;\n width = this.props.maxWidth;\n }\n } else {\n if (height > this.props.maxHeight) {\n //Check resize is enabled\n if (!this.props.reduceImage) {\n alert(\"L'image est trop haute, la hauteur maximale est de \" + this.props.maxHeight);\n return\n }\n\n width *= this.props.maxHeight / height;\n height = this.props.maxHeight;\n }\n }\n }\n\n //Build 2d picture\n canvas.width = width;\n canvas.height = height;\n context = canvas.getContext('2d');\n context!.drawImage(imageSource, 0, 0, width, height);\n\n\n //Jpeg conversion\n let jpegCompressionRatio = (this.props.jpegQuality && this.props.jpegQuality > 0 && this.props.jpegQuality < 1) ? this.props.jpegQuality : 1\n let canvasData = canvas.toDataURL('image/jpg', jpegCompressionRatio);//Jpeg conversion\n\n if (this.debugging)\n console.log(\"jpegCompressionRatio->\", jpegCompressionRatio, \" canvasData.length = \", canvasData.length);\n\n if (this.props.removebase64) {\n //remove base64 prefix if property is set\n this.props.uploadPicture({ data: canvasData ? canvasData.substring(\"data:image/png;base64\".length) : \"\", item_id: this.props.item_id });\n }\n else {\n //Keep base 64 prefix as it is\n this.props.uploadPicture({ data: canvasData ? canvasData : \"\", item_id: this.props.item_id });\n }\n }\n\n //-----------------------------------------------------------------------------------------------------------------------------------------\n storeImageToImg = (e: ProgressEvent<FileReader>) => {\n var image = document.createElement('img');\n image.onload = this.reduceImage;\n\n image.src = (e.currentTarget as FileReader).result as string;\n }\n\n //-----------------------------------------------------------------------------------------------------------------------------------------\n readImage = async (aPictureFile: File) => {\n let _reader = new FileReader();\n\n _reader.onload = this.storeImageToImg;\n _reader.readAsDataURL(aPictureFile);\n }\n\n //-----------------------------------------------------------------------------------------------------------------------------------------\n resetUpload = () => {\n this.props.uploadPicture({ data: \"\", item_id: this.props.item_id });\n }\n\n //-----------------------------------------------------------------------------------------------------------------------------------------\n onInputChange = (e: ChangeEvent<HTMLInputElement>) => {\n const errs: string[] = []\n const files = Array.from(e.target.files || [])\n const types = ['image/png', 'image/jpeg', 'image/gif']\n const _1Mo = 1024 * 1024\n const SizeLimit = 9\n\n //Reset input cache value - to assure trigger if user select the same file again\n e.target.value = \"\"\n\n if (this.debugging)\n console.log(\"onInputChange\")\n\n if (files.length > 1) {\n const msg = 'Pas plus d\\'une image à la fois'\n alert(msg);\n return;\n }\n\n files.forEach((file: File, i: number) => {\n let errCount = errs.length\n if (types.every(type => file.type !== type)) {\n errs.push(`'${file.type}' : format non supporté`)\n }\n\n if (file.size > (SizeLimit * _1Mo)) {\n errs.push(`'${file.name}' image trop volumineuse (max:${SizeLimit}Méga-octets)`)\n }\n\n if (this.debugging)\n console.log(`errCount = ${errCount} vs errs.length = ${errs.length}`)\n\n if (errCount == errs.length) { //None new error occurs\n if (this.debugging)\n console.log(\"readImage::\", file.name);\n this.readImage(file);\n }\n })\n\n if (errs.length) {\n return errs.forEach(err => alert(err))\n }\n }\n\n render() {\n\n const upload_picture_label: React.CSSProperties = {\n cursor: \"pointer\"\n }\n\n const upload_picture_label_input: React.CSSProperties = {\n opacity: \"0\",\n width: \"0px\",\n height: \"0px\"\n }\n\n const div_show_image_hover: React.CSSProperties = {\n position: \"relative\",\n margin: \"0px\",\n opacity: \"0.5\"\n }\n\n const div_show_image: React.CSSProperties = {\n position: \"relative\",\n margin: \"0px\"\n }\n\n const div_show_image_hover_input: React.CSSProperties = {\n display: \"block\",\n top: \"0px\",\n left: \"0px\",\n position: \"absolute\"\n }\n\n const div_show_image_input: React.CSSProperties = {\n position: \"absolute\",\n display: \"none\",\n cursor: \"pointer\"\n }\n\n return (\n <div>\n {(!this.props.data) &&\n <label\n id=\"upload-picture-label\"\n className={this.props.buttonStyle} style={upload_picture_label}>{this.props.Caption}\n <input style={upload_picture_label_input} id=\"nested-input\" type=\"file\" accept=\"image/*\" onChange={this.onInputChange} multiple />\n </label>}\n\n {(this.props.data && this.props.data.length > 0) &&\n <div className=\"show-image\"\n style={div_show_image}\n\n onMouseOver={() => { this.setState({ hover_input: true, hover_image: true }, () => { if (this.debugging) console.log(\"onMouseOver\") }) }}\n onMouseLeave={() => { this.setState({ hover_input: false, hover_image: false }, () => { if (this.debugging) console.log(\"onMouseLeave\") }) }}>\n\n <img\n style={this.state.hover_image ? div_show_image_hover : div_show_image}\n src={(this.props.removebase64) ? \"data:image/png;base64\" : \"\" + this.props.data}\n className={this.props.pictureStyle}\n />\n {!this.props.readOnly &&\n <input\n style={this.state.hover_input ? div_show_image_hover_input : div_show_image_input}\n className=\"btn btn-primary delete\" type=\"button\" value=\"Effacer\"\n onClick={this.resetUpload} />}\n </div>\n }\n </div>);\n }\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,mBAA0D;AAqNtC;AA7Lb,IAAM,SAAN,cAAqB,uBAAoC;AAAA,EAG5D,YAAY,OAAoB;AAC5B,UAAM,KAAK;AAMf;AAAA,uBAAc,CAAC,MAAa;AACxB,UAAI,cAAgB,EAAU,QAAS,EAAU,KAAK,CAAC,KAAO,EAAU;AAExE,UAAI,KAAK,UAAW,SAAQ,IAAI,kBAAkB,WAAW;AAC7D,UAAI,SAAS,SAAS,cAAc,QAAQ,GACxC,SACA,QAAQ,YAAY,OACpB,SAAS,YAAY;AAGzB,UAAI,KAAK,MAAM,SAAS,KAAK,MAAM,QAAQ;AAEvC,YAAI,QAAQ,KAAK,MAAM,SAAS,SAAS,KAAK,MAAM,QAAQ;AACxD,gBAA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UAEP,aAAa,MAAM;AAAE,iBAAK,SAAS,EAAE,aAAa,MAAM,aAAa,KAAK,GAAG,MAAM;AAAE,kBAAI,KAAK,UAAW,SAAQ,IAAI,aAAa;AAAA,YAAE,CAAC;AAAA,UAAE;AAAA,UACvI,cAAc,MAAM;AAAE,iBAAK,SAAS,EAAE,aAAa,OAAO,aAAa,MAAM,GAAG,MAAM;AAAE,kBAAI,KAAK,UAAW,SAAQ,IAAI,cAAc;AAAA,YAAE,CAAC;AAAA,UAAE;AAAA,UAE3I;AAAA;AAAA,cAAC;AAAA;AAAA,gBACG,OAAO,KAAK,MAAM,cAAc,uBAAuB;AAAA,gBACvD,KAAM,KAAK,MAAM,eAAgB,0BAA0B,KAAK,KAAK,MAAM;AAAA,gBAC3E,WAAW,KAAK,MAAM;AAAA;AAAA,YAC1B;AAAA,YACC,CAAC,KAAK,MAAM,YACT;AAAA,cAAC;AAAA;AAAA,gBACG,OAAO,KAAK,MAAM,cAAc,6BAA6B;AAAA,gBAC7D,WAAU;AAAA,gBAAyB,MAAK;AAAA,gBAAS,OAAM;AAAA,gBACvD,SAAS,KAAK;AAAA;AAAA,YAAa;AAAA;AAAA;AAAA,MACvC;AAAA,OAER;AAAA,EACR;AACJ;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,217 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+
22
+ // src/components/DsBlob.tsx
23
+ import { Component } from "react";
24
+ import { jsx, jsxs } from "react/jsx-runtime";
25
+ var DsBlob = class extends Component {
26
+ constructor(props) {
27
+ super(props);
28
+ //-----------------------------------------------------------------------------------------------------------------------------------------
29
+ this.reduceImage = (e) => {
30
+ let imageSource = e.path && e.path[0] || e.srcElement;
31
+ if (this.debugging) console.log("imageSource = ", imageSource);
32
+ var canvas = document.createElement("canvas"), context, width = imageSource.width, height = imageSource.height;
33
+ if (this.props.width && this.props.height) {
34
+ if (width > this.props.width || height > this.props.height) {
35
+ alert("L'image est trop grande, le format requis est " + this.props.width + "x" + this.props.height);
36
+ return;
37
+ }
38
+ if (width < this.props.width || height < this.props.height) {
39
+ alert("L'image est trop petite, le format requis est " + this.props.width + "x" + this.props.height);
40
+ return;
41
+ }
42
+ }
43
+ if (this.props.maxWidth && this.props.maxHeight) {
44
+ if (width > height) {
45
+ if (!this.props.reduceImage) {
46
+ alert("L'image est trop large ! la largeur maximale est de " + this.props.maxWidth);
47
+ return;
48
+ }
49
+ if (width > this.props.maxWidth) {
50
+ height *= this.props.maxWidth / width;
51
+ width = this.props.maxWidth;
52
+ }
53
+ } else {
54
+ if (height > this.props.maxHeight) {
55
+ if (!this.props.reduceImage) {
56
+ alert("L'image est trop haute, la hauteur maximale est de " + this.props.maxHeight);
57
+ return;
58
+ }
59
+ width *= this.props.maxHeight / height;
60
+ height = this.props.maxHeight;
61
+ }
62
+ }
63
+ }
64
+ canvas.width = width;
65
+ canvas.height = height;
66
+ context = canvas.getContext("2d");
67
+ context.drawImage(imageSource, 0, 0, width, height);
68
+ let jpegCompressionRatio = this.props.jpegQuality && this.props.jpegQuality > 0 && this.props.jpegQuality < 1 ? this.props.jpegQuality : 1;
69
+ let canvasData = canvas.toDataURL("image/jpg", jpegCompressionRatio);
70
+ if (this.debugging)
71
+ console.log("jpegCompressionRatio->", jpegCompressionRatio, " canvasData.length = ", canvasData.length);
72
+ if (this.props.removebase64) {
73
+ this.props.uploadPicture({ data: canvasData ? canvasData.substring("data:image/png;base64".length) : "", item_id: this.props.item_id });
74
+ } else {
75
+ this.props.uploadPicture({ data: canvasData ? canvasData : "", item_id: this.props.item_id });
76
+ }
77
+ };
78
+ //-----------------------------------------------------------------------------------------------------------------------------------------
79
+ this.storeImageToImg = (e) => {
80
+ var image = document.createElement("img");
81
+ image.onload = this.reduceImage;
82
+ image.src = e.currentTarget.result;
83
+ };
84
+ //-----------------------------------------------------------------------------------------------------------------------------------------
85
+ this.readImage = (aPictureFile) => __async(this, null, function* () {
86
+ let _reader = new FileReader();
87
+ _reader.onload = this.storeImageToImg;
88
+ _reader.readAsDataURL(aPictureFile);
89
+ });
90
+ //-----------------------------------------------------------------------------------------------------------------------------------------
91
+ this.resetUpload = () => {
92
+ this.props.uploadPicture({ data: "", item_id: this.props.item_id });
93
+ };
94
+ //-----------------------------------------------------------------------------------------------------------------------------------------
95
+ this.onInputChange = (e) => {
96
+ const errs = [];
97
+ const files = Array.from(e.target.files || []);
98
+ const types = ["image/png", "image/jpeg", "image/gif"];
99
+ const _1Mo = 1024 * 1024;
100
+ const SizeLimit = 9;
101
+ e.target.value = "";
102
+ if (this.debugging)
103
+ console.log("onInputChange");
104
+ if (files.length > 1) {
105
+ const msg = "Pas plus d'une image \xE0 la fois";
106
+ alert(msg);
107
+ return;
108
+ }
109
+ files.forEach((file, i) => {
110
+ let errCount = errs.length;
111
+ if (types.every((type) => file.type !== type)) {
112
+ errs.push(`'${file.type}' : format non support\xE9`);
113
+ }
114
+ if (file.size > SizeLimit * _1Mo) {
115
+ errs.push(`'${file.name}' image trop volumineuse (max:${SizeLimit}M\xE9ga-octets)`);
116
+ }
117
+ if (this.debugging)
118
+ console.log(`errCount = ${errCount} vs errs.length = ${errs.length}`);
119
+ if (errCount == errs.length) {
120
+ if (this.debugging)
121
+ console.log("readImage::", file.name);
122
+ this.readImage(file);
123
+ }
124
+ });
125
+ if (errs.length) {
126
+ return errs.forEach((err) => alert(err));
127
+ }
128
+ };
129
+ this.state = { hover_input: false, hover_image: false };
130
+ this.debugging = false;
131
+ }
132
+ render() {
133
+ const upload_picture_label = {
134
+ cursor: "pointer"
135
+ };
136
+ const upload_picture_label_input = {
137
+ opacity: "0",
138
+ width: "0px",
139
+ height: "0px"
140
+ };
141
+ const div_show_image_hover = {
142
+ position: "relative",
143
+ margin: "0px",
144
+ opacity: "0.5"
145
+ };
146
+ const div_show_image = {
147
+ position: "relative",
148
+ margin: "0px"
149
+ };
150
+ const div_show_image_hover_input = {
151
+ display: "block",
152
+ top: "0px",
153
+ left: "0px",
154
+ position: "absolute"
155
+ };
156
+ const div_show_image_input = {
157
+ position: "absolute",
158
+ display: "none",
159
+ cursor: "pointer"
160
+ };
161
+ return /* @__PURE__ */ jsxs("div", { children: [
162
+ !this.props.data && /* @__PURE__ */ jsxs(
163
+ "label",
164
+ {
165
+ id: "upload-picture-label",
166
+ className: this.props.buttonStyle,
167
+ style: upload_picture_label,
168
+ children: [
169
+ this.props.Caption,
170
+ /* @__PURE__ */ jsx("input", { style: upload_picture_label_input, id: "nested-input", type: "file", accept: "image/*", onChange: this.onInputChange, multiple: true })
171
+ ]
172
+ }
173
+ ),
174
+ this.props.data && this.props.data.length > 0 && /* @__PURE__ */ jsxs(
175
+ "div",
176
+ {
177
+ className: "show-image",
178
+ style: div_show_image,
179
+ onMouseOver: () => {
180
+ this.setState({ hover_input: true, hover_image: true }, () => {
181
+ if (this.debugging) console.log("onMouseOver");
182
+ });
183
+ },
184
+ onMouseLeave: () => {
185
+ this.setState({ hover_input: false, hover_image: false }, () => {
186
+ if (this.debugging) console.log("onMouseLeave");
187
+ });
188
+ },
189
+ children: [
190
+ /* @__PURE__ */ jsx(
191
+ "img",
192
+ {
193
+ style: this.state.hover_image ? div_show_image_hover : div_show_image,
194
+ src: this.props.removebase64 ? "data:image/png;base64" : "" + this.props.data,
195
+ className: this.props.pictureStyle
196
+ }
197
+ ),
198
+ !this.props.readOnly && /* @__PURE__ */ jsx(
199
+ "input",
200
+ {
201
+ style: this.state.hover_input ? div_show_image_hover_input : div_show_image_input,
202
+ className: "btn btn-primary delete",
203
+ type: "button",
204
+ value: "Effacer",
205
+ onClick: this.resetUpload
206
+ }
207
+ )
208
+ ]
209
+ }
210
+ )
211
+ ] });
212
+ }
213
+ };
214
+ export {
215
+ DsBlob
216
+ };
217
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/DsBlob.tsx"],"sourcesContent":["\nimport React, { Component, ChangeEvent, MouseEvent } from \"react\";\n\ninterface DsBlobProps {\n width?: number;\n height?: number;\n maxWidth?: number;\n maxHeight?: number;\n reduceImage?: boolean;\n jpegQuality?: number;\n removebase64?: boolean;\n uploadPicture: (data: { data: string; item_id: any }) => void;\n item_id: any;\n data?: string;\n buttonStyle?: string;\n Caption?: string;\n pictureStyle?: string;\n readOnly?: boolean;\n}\n\ninterface DsBlobState {\n hover_input: boolean;\n hover_image: boolean;\n}\n\nexport class DsBlob extends Component<DsBlobProps, DsBlobState> {\n private debugging: boolean;\n\n constructor(props: DsBlobProps) {\n super(props);\n this.state = { hover_input: false, hover_image: false };\n this.debugging = false;\n }\n\n //-----------------------------------------------------------------------------------------------------------------------------------------\n reduceImage = (e: Event) => {\n let imageSource = ((e as any).path && (e as any).path[0]) || (e as any).srcElement as HTMLImageElement; //Safari compliancy\n\n if (this.debugging) console.log(\"imageSource = \", imageSource);\n var canvas = document.createElement('canvas'),\n context: CanvasRenderingContext2D | null,\n width = imageSource.width,\n height = imageSource.height;\n\n //Exact size props are set\n if (this.props.width && this.props.height) {\n //Check image size\n if (width > this.props.width || height > this.props.height) {\n alert(\"L'image est trop grande, le format requis est \" + this.props.width + \"x\" + this.props.height);\n return\n }\n\n //Check image size\n if (width < this.props.width || height < this.props.height) {\n alert(\"L'image est trop petite, le format requis est \" + this.props.width + \"x\" + this.props.height);\n return\n }\n }\n\n //Max size props are set\n if (this.props.maxWidth && this.props.maxHeight) {\n if (width > height) {\n //Check resize is enabled\n if (!this.props.reduceImage) {\n alert(\"L'image est trop large ! la largeur maximale est de \" + this.props.maxWidth);\n return\n }\n if (width > this.props.maxWidth) {\n height *= this.props.maxWidth / width;\n width = this.props.maxWidth;\n }\n } else {\n if (height > this.props.maxHeight) {\n //Check resize is enabled\n if (!this.props.reduceImage) {\n alert(\"L'image est trop haute, la hauteur maximale est de \" + this.props.maxHeight);\n return\n }\n\n width *= this.props.maxHeight / height;\n height = this.props.maxHeight;\n }\n }\n }\n\n //Build 2d picture\n canvas.width = width;\n canvas.height = height;\n context = canvas.getContext('2d');\n context!.drawImage(imageSource, 0, 0, width, height);\n\n\n //Jpeg conversion\n let jpegCompressionRatio = (this.props.jpegQuality && this.props.jpegQuality > 0 && this.props.jpegQuality < 1) ? this.props.jpegQuality : 1\n let canvasData = canvas.toDataURL('image/jpg', jpegCompressionRatio);//Jpeg conversion\n\n if (this.debugging)\n console.log(\"jpegCompressionRatio->\", jpegCompressionRatio, \" canvasData.length = \", canvasData.length);\n\n if (this.props.removebase64) {\n //remove base64 prefix if property is set\n this.props.uploadPicture({ data: canvasData ? canvasData.substring(\"data:image/png;base64\".length) : \"\", item_id: this.props.item_id });\n }\n else {\n //Keep base 64 prefix as it is\n this.props.uploadPicture({ data: canvasData ? canvasData : \"\", item_id: this.props.item_id });\n }\n }\n\n //-----------------------------------------------------------------------------------------------------------------------------------------\n storeImageToImg = (e: ProgressEvent<FileReader>) => {\n var image = document.createElement('img');\n image.onload = this.reduceImage;\n\n image.src = (e.currentTarget as FileReader).result as string;\n }\n\n //-----------------------------------------------------------------------------------------------------------------------------------------\n readImage = async (aPictureFile: File) => {\n let _reader = new FileReader();\n\n _reader.onload = this.storeImageToImg;\n _reader.readAsDataURL(aPictureFile);\n }\n\n //-----------------------------------------------------------------------------------------------------------------------------------------\n resetUpload = () => {\n this.props.uploadPicture({ data: \"\", item_id: this.props.item_id });\n }\n\n //-----------------------------------------------------------------------------------------------------------------------------------------\n onInputChange = (e: ChangeEvent<HTMLInputElement>) => {\n const errs: string[] = []\n const files = Array.from(e.target.files || [])\n const types = ['image/png', 'image/jpeg', 'image/gif']\n const _1Mo = 1024 * 1024\n const SizeLimit = 9\n\n //Reset input cache value - to assure trigger if user select the same file again\n e.target.value = \"\"\n\n if (this.debugging)\n console.log(\"onInputChange\")\n\n if (files.length > 1) {\n const msg = 'Pas plus d\\'une image à la fois'\n alert(msg);\n return;\n }\n\n files.forEach((file: File, i: number) => {\n let errCount = errs.length\n if (types.every(type => file.type !== type)) {\n errs.push(`'${file.type}' : format non supporté`)\n }\n\n if (file.size > (SizeLimit * _1Mo)) {\n errs.push(`'${file.name}' image trop volumineuse (max:${SizeLimit}Méga-octets)`)\n }\n\n if (this.debugging)\n console.log(`errCount = ${errCount} vs errs.length = ${errs.length}`)\n\n if (errCount == errs.length) { //None new error occurs\n if (this.debugging)\n console.log(\"readImage::\", file.name);\n this.readImage(file);\n }\n })\n\n if (errs.length) {\n return errs.forEach(err => alert(err))\n }\n }\n\n render() {\n\n const upload_picture_label: React.CSSProperties = {\n cursor: \"pointer\"\n }\n\n const upload_picture_label_input: React.CSSProperties = {\n opacity: \"0\",\n width: \"0px\",\n height: \"0px\"\n }\n\n const div_show_image_hover: React.CSSProperties = {\n position: \"relative\",\n margin: \"0px\",\n opacity: \"0.5\"\n }\n\n const div_show_image: React.CSSProperties = {\n position: \"relative\",\n margin: \"0px\"\n }\n\n const div_show_image_hover_input: React.CSSProperties = {\n display: \"block\",\n top: \"0px\",\n left: \"0px\",\n position: \"absolute\"\n }\n\n const div_show_image_input: React.CSSProperties = {\n position: \"absolute\",\n display: \"none\",\n cursor: \"pointer\"\n }\n\n return (\n <div>\n {(!this.props.data) &&\n <label\n id=\"upload-picture-label\"\n className={this.props.buttonStyle} style={upload_picture_label}>{this.props.Caption}\n <input style={upload_picture_label_input} id=\"nested-input\" type=\"file\" accept=\"image/*\" onChange={this.onInputChange} multiple />\n </label>}\n\n {(this.props.data && this.props.data.length > 0) &&\n <div className=\"show-image\"\n style={div_show_image}\n\n onMouseOver={() => { this.setState({ hover_input: true, hover_image: true }, () => { if (this.debugging) console.log(\"onMouseOver\") }) }}\n onMouseLeave={() => { this.setState({ hover_input: false, hover_image: false }, () => { if (this.debugging) console.log(\"onMouseLeave\") }) }}>\n\n <img\n style={this.state.hover_image ? div_show_image_hover : div_show_image}\n src={(this.props.removebase64) ? \"data:image/png;base64\" : \"\" + this.props.data}\n className={this.props.pictureStyle}\n />\n {!this.props.readOnly &&\n <input\n style={this.state.hover_input ? div_show_image_hover_input : div_show_image_input}\n className=\"btn btn-primary delete\" type=\"button\" value=\"Effacer\"\n onClick={this.resetUpload} />}\n </div>\n }\n </div>);\n }\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AACA,SAAgB,iBAA0C;AAqNtC,SAGI,KAHJ;AA7Lb,IAAM,SAAN,cAAqB,UAAoC;AAAA,EAG5D,YAAY,OAAoB;AAC5B,UAAM,KAAK;AAMf;AAAA,uBAAc,CAAC,MAAa;AACxB,UAAI,cAAgB,EAAU,QAAS,EAAU,KAAK,CAAC,KAAO,EAAU;AAExE,UAAI,KAAK,UAAW,SAAQ,IAAI,kBAAkB,WAAW;AAC7D,UAAI,SAAS,SAAS,cAAc,QAAQ,GACxC,SACA,QAAQ,YAAY,OACpB,SAAS,YAAY;AAGzB,UAAI,KAAK,MAAM,SAAS,KAAK,MAAM,QAAQ;AAEvC,YAAI,QAAQ,KAAK,MAAM,SAAS,SAAS,KAAK,MAAM,QAAQ;AACxD,gBAAM,mDAAmD,KAAK,MAAM,QAAQ,MAAM,KAAK,MAAM,MAAM;AACnG;AAAA,QACJ;AAGA,YAAI,QAAQ,KAAK,MAAM,SAAS,SAAS,KAAK,MAAM,QAAQ;AACxD,gBAAM,mDAAmD,KAAK,MAAM,QAAQ,MAAM,KAAK,MAAM,MAAM;AACnG;AAAA,QACJ;AAAA,MACJ;AAGA,UAAI,KAAK,MAAM,YAAY,KAAK,MAAM,WAAW;AAC7C,YAAI,QAAQ,QAAQ;AAEhB,cAAI,CAAC,KAAK,MAAM,aAAa;AACzB,kBAAM,yDAAyD,KAA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,KAAK,MAAM,cAAc,uBAAuB;AAAA,gBACvD,KAAM,KAAK,MAAM,eAAgB,0BAA0B,KAAK,KAAK,MAAM;AAAA,gBAC3E,WAAW,KAAK,MAAM;AAAA;AAAA,YAC1B;AAAA,YACC,CAAC,KAAK,MAAM,YACT;AAAA,cAAC;AAAA;AAAA,gBACG,OAAO,KAAK,MAAM,cAAc,6BAA6B;AAAA,gBAC7D,WAAU;AAAA,gBAAyB,MAAK;AAAA,gBAAS,OAAM;AAAA,gBACvD,SAAS,KAAK;AAAA;AAAA,YAAa;AAAA;AAAA;AAAA,MACvC;AAAA,OAER;AAAA,EACR;AACJ;","names":[]}
package/package.json CHANGED
@@ -1,9 +1,14 @@
1
1
  {
2
2
  "name": "datasync-blob",
3
- "version": "1.0.2",
3
+ "version": "1.1.1",
4
4
  "description": "Datasync Blob component",
5
- "main": "./dist/components/DsBlob.js",
6
- "files": ["./dist"],
5
+ "main_OLD": "./dist/components/DsBlob.js",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.mjs",
8
+ "types": "./dist/index.d.ts",
9
+ "files": [
10
+ "./dist"
11
+ ],
7
12
  "repository": {
8
13
  "type": "git",
9
14
  "url": "https://github.com/pmabiala/datasync-blob.git"
@@ -18,17 +23,25 @@
18
23
  "@babel/preset-env": "^7.24.4",
19
24
  "@babel/preset-react": "^7.24.1",
20
25
  "@testing-library/react": "^14.2.2",
26
+ "javascript-obfuscator": "^4.1.1",
21
27
  "jest": "^29.7.0",
22
28
  "jest-environment-jsdom": "^29.7.0",
23
29
  "jest-transform-css": "^6.0.1",
24
30
  "react": "^18.2.0",
25
- "react-pdf": "^7.7.1"
31
+ "react-pdf": "^10.0.1",
32
+ "tsup": "^8.5.0",
33
+ "webpack": "^5.99.9",
34
+ "webpack-cli": "^6.0.1",
35
+ "webpack-node-externals": "^3.0.0",
36
+ "webpack-obfuscator": "^3.5.1"
26
37
  },
27
38
  "peerDependencies": {
28
39
  "react": "^ 18.2.0"
29
40
  },
30
41
  "scripts": {
31
- "build": "rm -r dist && babel src -d dist --ignore src/**/*.test.jsx && npm run copy-files",
42
+ "tsup": "tsup",
43
+ "build_old": "rm -r dist && babel src -d dist --ignore src/**/*.test.jsx && npm run copy-files",
44
+ "build": "rm -r dist && babel src -d dist --ignore src/**/*.test.jsx && npm run copy-files && webpack --config webpack.config.js",
32
45
  "copy-files": "cp ./src/*.css dist/",
33
46
  "test": "jest --config jest.config.json"
34
47
  },
package/dist/DsBlob.css DELETED
@@ -1,33 +0,0 @@
1
- #upload-picture-label{
2
- cursor: pointer;
3
- }
4
-
5
- #upload-picture-label input{
6
- opacity: 0;
7
- width: 0px;
8
- height: 0px;
9
- }
10
-
11
- div.show-image {
12
- position: relative;
13
- /*float:left;*/
14
- margin:5px;
15
- }
16
- div.show-image:hover img{
17
- opacity:0.5;
18
- }
19
- div.show-image:hover input {
20
- display: block;
21
- }
22
- div.show-image input {
23
- position:absolute;
24
- display:none;
25
- }
26
- div.show-image input.update {
27
- top:0;
28
- left:0;
29
- }
30
- div.show-image input.delete {
31
- top:0;
32
- left:0px;
33
- }
@@ -1,172 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.DsBlob = void 0;
7
- var _react = _interopRequireWildcard(require("react"));
8
- require("../DsBlob.css");
9
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
- class DsBlob extends _react.Component {
12
- constructor(props) {
13
- super(props);
14
- this.state = {};
15
- }
16
-
17
- //-----------------------------------------------------------------------------------------------------------------------------------------
18
- reduceImage = e => {
19
- let imageSource = e.path && e.path[0] || e.srcElement; //Safari compliancy
20
- //console.log("imageSource = ",imageSource);
21
- var canvas = document.createElement('canvas'),
22
- context,
23
- width = imageSource.width,
24
- height = imageSource.height;
25
-
26
- //Exact size props are set
27
- if (this.props.width && this.props.height) {
28
- //Check image size
29
- if (width > this.props.width || height > this.props.height) {
30
- alert("L'image est trop grande, le format requis est " + this.props.width + "x" + this.props.height);
31
- return;
32
- }
33
-
34
- //Check image size
35
- if (width < this.props.width || height < this.props.height) {
36
- alert("L'image est trop petite, le format requis est " + this.props.width + "x" + this.props.height);
37
- return;
38
- }
39
- }
40
-
41
- //Max size props are set
42
- if (this.props.maxWidth && this.props.maxHeight) {
43
- if (width > height) {
44
- //Check resize is enabled
45
- if (!this.props.reduceImage) {
46
- alert("L'image est trop large, la largeur maximale est de " + this.props.maxWidth);
47
- return;
48
- }
49
- if (width > this.props.maxWidth) {
50
- height *= this.props.maxWidth / width;
51
- width = this.props.maxWidth;
52
- }
53
- } else {
54
- if (height > this.props.maxHeight) {
55
- //Check resize is enabled
56
- if (!this.props.reduceImage) {
57
- alert("L'image est trop haute, la hauteur maximale est de " + this.props.maxHeight);
58
- return;
59
- }
60
- width *= this.props.maxHeight / height;
61
- height = this.props.maxHeight;
62
- }
63
- }
64
- }
65
-
66
- //Build 2d picture
67
- canvas.width = width;
68
- canvas.height = height;
69
- context = canvas.getContext('2d');
70
- context.drawImage(imageSource, 0, 0, width, height);
71
-
72
- //Jpeg conversion
73
- let jpegCompressionRatio = this.props.jpegQuality && this.props.jpegQuality > 0 && this.props.jpegQuality < 1 ? this.props.jpegQuality : 1;
74
- let canvasData = canvas.toDataURL('image/jpg', jpegCompressionRatio); //Jpeg conversion
75
-
76
- console.log("jpegCompressionRatio->", jpegCompressionRatio, " canvasData.length = ", canvasData.length);
77
- if (this.props.removebase64) {
78
- //remove base64 prefix if property is set
79
- this.props.uploadPicture({
80
- data: canvasData ? canvasData.substring("data:image/png;base64".length) : "",
81
- item_id: this.props.item_id
82
- });
83
- } else {
84
- //Keep base 64 prefix as it is
85
- this.props.uploadPicture({
86
- data: canvasData ? canvasData : "",
87
- item_id: this.props.item_id
88
- });
89
- }
90
- };
91
-
92
- //-----------------------------------------------------------------------------------------------------------------------------------------
93
- storeImageToImg = e => {
94
- var image = document.createElement('img');
95
- image.onload = this.reduceImage;
96
- image.src = e.currentTarget.result;
97
- };
98
-
99
- //-----------------------------------------------------------------------------------------------------------------------------------------
100
- readImage = async aPictureFile => {
101
- let _reader = new FileReader();
102
- _reader.onload = this.storeImageToImg;
103
- _reader.readAsDataURL(aPictureFile);
104
- };
105
-
106
- //-----------------------------------------------------------------------------------------------------------------------------------------
107
- resetUpload = () => {
108
- this.props.uploadPicture({
109
- data: "",
110
- item_id: this.props.item_id
111
- });
112
- };
113
-
114
- //-----------------------------------------------------------------------------------------------------------------------------------------
115
- onInputChange = e => {
116
- const errs = [];
117
- const files = Array.from(e.target.files);
118
- const types = ['image/png', 'image/jpeg', 'image/gif'];
119
- const _1Mo = 1024 * 1024;
120
- const SizeLimit = 9;
121
- console.clear();
122
- //Reset input cache value - to assure trigger if user select the same file again
123
- e.target.value = null;
124
- console.log("onInputChange");
125
- if (files.length > 1) {
126
- const msg = 'Pas plus d\'une image à la fois';
127
- alert(msg);
128
- return;
129
- }
130
- files.forEach((file, i) => {
131
- let errCount = errs.length;
132
- if (types.every(type => file.type !== type)) {
133
- errs.push(`'${file.type}' : format non supporté`);
134
- }
135
- if (file.size > SizeLimit * _1Mo) {
136
- errs.push(`'${file.name}' image trop volumineuse (max:${SizeLimit}Méga-octets)`);
137
- }
138
- console.log(`errCount = ${errCount} vs errs.length = ${errs.length}`);
139
- if (errCount == errs.length) {
140
- //None new error occurs
141
- console.log("readImage:", file.name);
142
- this.readImage(file);
143
- }
144
- });
145
- if (errs.length) {
146
- return errs.forEach(err => alert(err));
147
- }
148
- };
149
- render() {
150
- return /*#__PURE__*/_react.default.createElement("div", null, !this.props.data && /*#__PURE__*/_react.default.createElement("label", {
151
- id: "upload-picture-label",
152
- className: this.props.buttonStyle
153
- }, this.props.Caption, /*#__PURE__*/_react.default.createElement("input", {
154
- id: "nested-input",
155
- type: "file",
156
- accept: "image/*",
157
- onChange: this.onInputChange,
158
- multiple: true
159
- })), this.props.data && this.props.data.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
160
- class: "show-image"
161
- }, /*#__PURE__*/_react.default.createElement("img", {
162
- src: this.props.removebase64 ? "data:image/png;base64" : "" + this.props.data,
163
- className: this.props.pictureStyle
164
- }), !this.props.readOnly && /*#__PURE__*/_react.default.createElement("input", {
165
- className: "btn btn-primary delete",
166
- type: "button",
167
- value: "Effacer",
168
- onClick: this.resetUpload
169
- })));
170
- }
171
- }
172
- exports.DsBlob = DsBlob;