datasync-blob 1.0.2 → 1.1.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/dist/components/DsBlob.js +65 -13
- package/package.json +12 -4
- package/dist/DsBlob.css +0 -33
|
@@ -5,19 +5,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.DsBlob = void 0;
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
-
|
|
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; }
|
|
8
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
11
9
|
class DsBlob extends _react.Component {
|
|
12
10
|
constructor(props) {
|
|
13
11
|
super(props);
|
|
14
|
-
this.state = {
|
|
12
|
+
this.state = {
|
|
13
|
+
hover_input: false,
|
|
14
|
+
hover_image: false
|
|
15
|
+
};
|
|
16
|
+
this.debugging = false;
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
//-----------------------------------------------------------------------------------------------------------------------------------------
|
|
18
20
|
reduceImage = e => {
|
|
19
21
|
let imageSource = e.path && e.path[0] || e.srcElement; //Safari compliancy
|
|
20
|
-
|
|
22
|
+
|
|
23
|
+
if (this.debugging) console.log("imageSource = ", imageSource);
|
|
21
24
|
var canvas = document.createElement('canvas'),
|
|
22
25
|
context,
|
|
23
26
|
width = imageSource.width,
|
|
@@ -43,7 +46,7 @@ class DsBlob extends _react.Component {
|
|
|
43
46
|
if (width > height) {
|
|
44
47
|
//Check resize is enabled
|
|
45
48
|
if (!this.props.reduceImage) {
|
|
46
|
-
alert("L'image est trop large
|
|
49
|
+
alert("L'image est trop large ! la largeur maximale est de " + this.props.maxWidth);
|
|
47
50
|
return;
|
|
48
51
|
}
|
|
49
52
|
if (width > this.props.maxWidth) {
|
|
@@ -73,7 +76,7 @@ class DsBlob extends _react.Component {
|
|
|
73
76
|
let jpegCompressionRatio = this.props.jpegQuality && this.props.jpegQuality > 0 && this.props.jpegQuality < 1 ? this.props.jpegQuality : 1;
|
|
74
77
|
let canvasData = canvas.toDataURL('image/jpg', jpegCompressionRatio); //Jpeg conversion
|
|
75
78
|
|
|
76
|
-
console.log("jpegCompressionRatio->", jpegCompressionRatio, " canvasData.length = ", canvasData.length);
|
|
79
|
+
if (this.debugging) console.log("jpegCompressionRatio->", jpegCompressionRatio, " canvasData.length = ", canvasData.length);
|
|
77
80
|
if (this.props.removebase64) {
|
|
78
81
|
//remove base64 prefix if property is set
|
|
79
82
|
this.props.uploadPicture({
|
|
@@ -118,10 +121,10 @@ class DsBlob extends _react.Component {
|
|
|
118
121
|
const types = ['image/png', 'image/jpeg', 'image/gif'];
|
|
119
122
|
const _1Mo = 1024 * 1024;
|
|
120
123
|
const SizeLimit = 9;
|
|
121
|
-
|
|
124
|
+
|
|
122
125
|
//Reset input cache value - to assure trigger if user select the same file again
|
|
123
126
|
e.target.value = null;
|
|
124
|
-
console.log("onInputChange");
|
|
127
|
+
if (this.debugging) console.log("onInputChange");
|
|
125
128
|
if (files.length > 1) {
|
|
126
129
|
const msg = 'Pas plus d\'une image à la fois';
|
|
127
130
|
alert(msg);
|
|
@@ -135,10 +138,10 @@ class DsBlob extends _react.Component {
|
|
|
135
138
|
if (file.size > SizeLimit * _1Mo) {
|
|
136
139
|
errs.push(`'${file.name}' image trop volumineuse (max:${SizeLimit}Méga-octets)`);
|
|
137
140
|
}
|
|
138
|
-
console.log(`errCount = ${errCount} vs errs.length = ${errs.length}`);
|
|
141
|
+
if (this.debugging) console.log(`errCount = ${errCount} vs errs.length = ${errs.length}`);
|
|
139
142
|
if (errCount == errs.length) {
|
|
140
143
|
//None new error occurs
|
|
141
|
-
console.log("readImage
|
|
144
|
+
if (this.debugging) console.log("readImage::", file.name);
|
|
142
145
|
this.readImage(file);
|
|
143
146
|
}
|
|
144
147
|
});
|
|
@@ -147,21 +150,70 @@ class DsBlob extends _react.Component {
|
|
|
147
150
|
}
|
|
148
151
|
};
|
|
149
152
|
render() {
|
|
153
|
+
const upload_picture_label = {
|
|
154
|
+
cursor: "pointer"
|
|
155
|
+
};
|
|
156
|
+
const upload_picture_label_input = {
|
|
157
|
+
opacity: "0",
|
|
158
|
+
width: "0px",
|
|
159
|
+
height: "0px"
|
|
160
|
+
};
|
|
161
|
+
const div_show_image_hover = {
|
|
162
|
+
position: "relative",
|
|
163
|
+
margin: "0px",
|
|
164
|
+
opacity: "0.5"
|
|
165
|
+
};
|
|
166
|
+
const div_show_image = {
|
|
167
|
+
position: "relative",
|
|
168
|
+
margin: "0px"
|
|
169
|
+
};
|
|
170
|
+
const div_show_image_hover_input = {
|
|
171
|
+
display: "block",
|
|
172
|
+
top: "0px",
|
|
173
|
+
left: "0px",
|
|
174
|
+
position: "absolute"
|
|
175
|
+
};
|
|
176
|
+
const div_show_image_input = {
|
|
177
|
+
position: "absolute",
|
|
178
|
+
display: "none",
|
|
179
|
+
cursor: "pointer"
|
|
180
|
+
};
|
|
150
181
|
return /*#__PURE__*/_react.default.createElement("div", null, !this.props.data && /*#__PURE__*/_react.default.createElement("label", {
|
|
151
182
|
id: "upload-picture-label",
|
|
152
|
-
className: this.props.buttonStyle
|
|
183
|
+
className: this.props.buttonStyle,
|
|
184
|
+
style: upload_picture_label
|
|
153
185
|
}, this.props.Caption, /*#__PURE__*/_react.default.createElement("input", {
|
|
186
|
+
style: upload_picture_label_input,
|
|
154
187
|
id: "nested-input",
|
|
155
188
|
type: "file",
|
|
156
189
|
accept: "image/*",
|
|
157
190
|
onChange: this.onInputChange,
|
|
158
191
|
multiple: true
|
|
159
192
|
})), this.props.data && this.props.data.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
|
|
160
|
-
class: "show-image"
|
|
193
|
+
class: "show-image",
|
|
194
|
+
style: div_show_image,
|
|
195
|
+
onMouseOver: () => {
|
|
196
|
+
this.setState({
|
|
197
|
+
hover_input: true,
|
|
198
|
+
hover_image: true
|
|
199
|
+
}, () => {
|
|
200
|
+
if (this.debugging) console.log("onMouseOver");
|
|
201
|
+
});
|
|
202
|
+
},
|
|
203
|
+
onMouseLeave: () => {
|
|
204
|
+
this.setState({
|
|
205
|
+
hover_input: false,
|
|
206
|
+
hover_image: false
|
|
207
|
+
}, () => {
|
|
208
|
+
if (this.debugging) console.log("onMouseLeave");
|
|
209
|
+
});
|
|
210
|
+
}
|
|
161
211
|
}, /*#__PURE__*/_react.default.createElement("img", {
|
|
212
|
+
style: this.state.hover_image ? div_show_image_hover : div_show_image,
|
|
162
213
|
src: this.props.removebase64 ? "data:image/png;base64" : "" + this.props.data,
|
|
163
214
|
className: this.props.pictureStyle
|
|
164
215
|
}), !this.props.readOnly && /*#__PURE__*/_react.default.createElement("input", {
|
|
216
|
+
style: this.state.hover_input ? div_show_image_hover_input : div_show_image_input,
|
|
165
217
|
className: "btn btn-primary delete",
|
|
166
218
|
type: "button",
|
|
167
219
|
value: "Effacer",
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "datasync-blob",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Datasync Blob component",
|
|
5
5
|
"main": "./dist/components/DsBlob.js",
|
|
6
|
-
"files": [
|
|
6
|
+
"files": [
|
|
7
|
+
"./dist"
|
|
8
|
+
],
|
|
7
9
|
"repository": {
|
|
8
10
|
"type": "git",
|
|
9
11
|
"url": "https://github.com/pmabiala/datasync-blob.git"
|
|
@@ -18,17 +20,23 @@
|
|
|
18
20
|
"@babel/preset-env": "^7.24.4",
|
|
19
21
|
"@babel/preset-react": "^7.24.1",
|
|
20
22
|
"@testing-library/react": "^14.2.2",
|
|
23
|
+
"javascript-obfuscator": "^4.1.1",
|
|
21
24
|
"jest": "^29.7.0",
|
|
22
25
|
"jest-environment-jsdom": "^29.7.0",
|
|
23
26
|
"jest-transform-css": "^6.0.1",
|
|
24
27
|
"react": "^18.2.0",
|
|
25
|
-
"react-pdf": "^7.7.1"
|
|
28
|
+
"react-pdf": "^7.7.1",
|
|
29
|
+
"webpack": "^5.99.9",
|
|
30
|
+
"webpack-cli": "^6.0.1",
|
|
31
|
+
"webpack-node-externals": "^3.0.0",
|
|
32
|
+
"webpack-obfuscator": "^3.5.1"
|
|
26
33
|
},
|
|
27
34
|
"peerDependencies": {
|
|
28
35
|
"react": "^ 18.2.0"
|
|
29
36
|
},
|
|
30
37
|
"scripts": {
|
|
31
|
-
"
|
|
38
|
+
"build_old": "rm -r dist && babel src -d dist --ignore src/**/*.test.jsx && npm run copy-files",
|
|
39
|
+
"build": "rm -r dist && babel src -d dist --ignore src/**/*.test.jsx && npm run copy-files && webpack --config webpack.config.js",
|
|
32
40
|
"copy-files": "cp ./src/*.css dist/",
|
|
33
41
|
"test": "jest --config jest.config.json"
|
|
34
42
|
},
|
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
|
-
}
|