datasync-blob 1.1.23 → 1.1.24

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.
@@ -5,13 +5,17 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.DsBlob = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
+ var _propTypes = _interopRequireDefault(require("prop-types"));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
8
10
  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); }
9
11
  class DsBlob extends _react.Component {
10
12
  constructor(props) {
11
13
  super(props);
12
14
  this.state = {
13
15
  hover_input: false,
14
- hover_image: false
16
+ hover_image: false,
17
+ data: props.data || "",
18
+ binaryData: props.binaryData || null
15
19
  };
16
20
  this.debugging = false;
17
21
  }
@@ -78,17 +82,17 @@ class DsBlob extends _react.Component {
78
82
  let canvasData = canvas.toDataURL('image/jpg', jpegCompressionRatio); //Jpeg conversion
79
83
 
80
84
  if (this.debugging) console.log("jpegCompressionRatio->", jpegCompressionRatio, " canvasData.length = ", canvasData.length);
85
+ const processedData = this.props.removebase64 ? canvasData ? canvasData.substring("data:image/png;base64".length) : "" : canvasData ? canvasData : "";
86
+ this.setData(processedData);
81
87
  if (this.props.removebase64) {
82
88
  //remove base64 prefix if property is set
83
89
  this.props.uploadPicture({
84
- data: canvasData ? canvasData.substring("data:image/png;base64".length) : "",
85
- item_id: this.props.item_id
90
+ data: processedData
86
91
  });
87
92
  } else {
88
93
  //Keep base 64 prefix as it is
89
94
  this.props.uploadPicture({
90
- data: canvasData ? canvasData : "",
91
- item_id: this.props.item_id
95
+ data: processedData
92
96
  });
93
97
  }
94
98
  };
@@ -166,12 +170,14 @@ class DsBlob extends _react.Component {
166
170
  console.log("Fallback: Using binary data, size:", binaryData.byteLength);
167
171
 
168
172
  // Store both display URL and binary data
173
+ this.setData(blobUrl, binaryData);
169
174
  this.props.uploadPicture({
170
175
  data: blobUrl,
171
176
  // For display in img tag
172
177
  binaryData: binaryData,
173
178
  // Genuine JPEG binary stream
174
- item_id: this.props.item_id,
179
+ cloud_url_prefix: this.props.cloud_url_prefix,
180
+ // Pass cloud URL prefix if needed for parent component
175
181
  isBlobUrl: true // Flag to track blob URLs for cleanup
176
182
  });
177
183
  };
@@ -241,21 +247,43 @@ class DsBlob extends _react.Component {
241
247
  resetUpload = () => {
242
248
  // Clean up any blob URLs before resetting
243
249
  this.cleanupBlobUrl();
250
+ this.setData("", null);
244
251
  this.props.uploadPicture({
245
252
  data: "",
246
- item_id: this.props.item_id
253
+ cloud_url_prefix: this.props.cloud_url_prefix,
254
+ isBlobUrl: false
247
255
  });
256
+ //this.props.uploadPicture({data:"",cloud_url_prefix:this.props.cloud_url_prefix, isBlobUrl:true});
248
257
  };
249
258
 
250
259
  //-----------------------------------------------------------------------------------------------------------------------------------------
251
260
  cleanupBlobUrl = () => {
261
+ // Only show alert if not in test environment
262
+ if (typeof jest === 'undefined') {
263
+ alert("cleanupBlobUrl !");
264
+ }
252
265
  // Revoke blob URL if it exists to prevent memory leaks
253
- if (this.props.data && this.props.data.startsWith && this.props.data.startsWith('blob:')) {
254
- URL.revokeObjectURL(this.props.data);
255
- console.log("Blob URL cleaned up:", this.props.data);
266
+ if (this.state.data && this.state.data.startsWith('blob:')) {
267
+ URL.revokeObjectURL(this.state.data);
268
+ console.log("Blob URL cleaned up:", this.state.data);
256
269
  }
257
270
  };
258
271
 
272
+ //-----------------------------------------------------------------------------------------------------------------------------------------
273
+ componentDidUpdate(prevProps) {
274
+ // Sync state with prop changes from parent
275
+ if (prevProps.data !== this.props.data) {
276
+ this.setState({
277
+ data: this.props.data || ""
278
+ });
279
+ }
280
+ if (prevProps.binaryData !== this.props.binaryData) {
281
+ this.setState({
282
+ binaryData: this.props.binaryData || null
283
+ });
284
+ }
285
+ }
286
+
259
287
  //-----------------------------------------------------------------------------------------------------------------------------------------
260
288
  componentWillUnmount() {
261
289
  // Cleanup blob URLs when component unmounts
@@ -304,28 +332,41 @@ class DsBlob extends _react.Component {
304
332
 
305
333
  //-----------------------------------------------------------------------------------------------------------------------------------------
306
334
  getImageSrc = () => {
307
- if (!this.props.data) return "";
335
+ if (!this.state.data) return "";
308
336
 
309
337
  // Check if it's already a complete URL (cloud storage URL or blob URL)
310
- if (this.props.data.startsWith('http://') || this.props.data.startsWith('https://') || this.props.data.startsWith('blob:')) {
311
- return this.props.data;
338
+ if (this.state.data.startsWith('http://') || this.state.data.startsWith('https://') || this.state.data.startsWith('blob:')) {
339
+ return this.state.data;
312
340
  }
313
341
 
314
342
  // Check if it's already a data URL (base64)
315
- if (this.props.data.startsWith('data:')) {
316
- return this.props.data;
343
+ if (this.state.data.startsWith('data:')) {
344
+ return this.state.data;
317
345
  }
318
346
 
319
347
  // Otherwise, treat as base64 and add appropriate prefix
320
348
  const prefix = this.props.removebase64 ? "data:image/png;base64," : "";
321
- return prefix + this.props.data;
349
+ return prefix + this.state.data;
322
350
  };
323
351
 
324
352
  //-----------------------------------------------------------------------------------------------------------------------------------------
325
353
  getBinaryData = () => {
326
354
  // Return the genuine JPEG binary stream (ArrayBuffer)
327
355
  // This can be used by parent components for uploading or processing
328
- return this.props.binaryData || null;
356
+ return this.state.binaryData || this.props.binaryData || null;
357
+ };
358
+
359
+ //-----------------------------------------------------------------------------------------------------------------------------------------
360
+ //-----------------------------------------------------------------------------------------------------------------------------------------
361
+ // Data getter and setter methods for read-write access
362
+ getData = () => {
363
+ return this.state.data;
364
+ };
365
+ setData = (data, binaryData = null) => {
366
+ this.setState({
367
+ data: data || "",
368
+ binaryData: binaryData
369
+ });
329
370
  };
330
371
 
331
372
  //-----------------------------------------------------------------------------------------------------------------------------------------
@@ -333,7 +374,7 @@ class DsBlob extends _react.Component {
333
374
  // Return the type of image data being used
334
375
  if (this.props.isCloudUrl) return 'cloud';
335
376
  if (this.props.isBlobUrl) return 'blob';
336
- if (this.props.data && this.props.data.startsWith('data:')) return 'base64';
377
+ if (this.state.data && this.state.data.startsWith('data:')) return 'base64';
337
378
  return 'unknown';
338
379
  };
339
380
  render() {
@@ -365,7 +406,7 @@ class DsBlob extends _react.Component {
365
406
  display: "none",
366
407
  cursor: "pointer"
367
408
  };
368
- return /*#__PURE__*/_react.default.createElement("div", null, !this.props.data && /*#__PURE__*/_react.default.createElement("label", {
409
+ return /*#__PURE__*/_react.default.createElement("div", null, !this.state.data && /*#__PURE__*/_react.default.createElement("label", {
369
410
  id: "upload-picture-label",
370
411
  className: this.props.buttonStyle,
371
412
  style: upload_picture_label
@@ -376,7 +417,7 @@ class DsBlob extends _react.Component {
376
417
  accept: "image/*",
377
418
  onChange: this.onInputChange,
378
419
  multiple: true
379
- })), this.props.data && this.props.data.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
420
+ })), this.state.data && this.state.data.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
380
421
  class: "show-image",
381
422
  style: div_show_image,
382
423
  onMouseOver: () => {
@@ -408,4 +449,31 @@ class DsBlob extends _react.Component {
408
449
  })));
409
450
  }
410
451
  }
411
- exports.DsBlob = DsBlob;
452
+ exports.DsBlob = DsBlob;
453
+ DsBlob.propTypes = {
454
+ // Image handling props (note: data and binaryData are managed as read-write state internally)
455
+ data: _propTypes.default.string,
456
+ binaryData: _propTypes.default.object,
457
+ // Upload callback
458
+ uploadPicture: _propTypes.default.func.isRequired,
459
+ // Image size constraints
460
+ width: _propTypes.default.number,
461
+ height: _propTypes.default.number,
462
+ maxWidth: _propTypes.default.number,
463
+ maxHeight: _propTypes.default.number,
464
+ // Image processing options
465
+ reduceImage: _propTypes.default.bool,
466
+ jpegQuality: _propTypes.default.number,
467
+ removebase64: _propTypes.default.bool,
468
+ // Cloud storage options
469
+ cloud_storage: _propTypes.default.bool,
470
+ cloud_url_prefix: _propTypes.default.string,
471
+ // UI props
472
+ Caption: _propTypes.default.string,
473
+ buttonStyle: _propTypes.default.string,
474
+ pictureStyle: _propTypes.default.string,
475
+ readOnly: _propTypes.default.bool,
476
+ // Status flags
477
+ isCloudUrl: _propTypes.default.bool,
478
+ isBlobUrl: _propTypes.default.bool
479
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datasync-blob",
3
- "version": "1.1.23",
3
+ "version": "1.1.24",
4
4
  "description": "Datasync Blob component",
5
5
  "main": "./dist/components/DsBlob.js",
6
6
  "files": [