@unvired/turboforms-embed-sdk 2.0.64 → 2.0.66

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.
@@ -30095,33 +30095,59 @@ class SmartFileComponent extends FieldComponent {
30095
30095
  });
30096
30096
  }
30097
30097
 
30098
- if (this.refs.cameraButton && webViewCamera) {
30098
+ if (this.refs.cameraButton) {
30099
30099
  this.addEventListener(this.refs.cameraButton, 'click', (event) => {
30100
30100
  event.preventDefault();
30101
- webViewCamera.getPicture((success) => {
30102
- window.resolveLocalFileSystemURL(success, (fileEntry) => {
30103
- fileEntry.file((file) => {
30104
- const reader = new FileReader();
30105
- reader.onloadend = (evt) => {
30106
- const blob = new Blob([new Uint8Array(evt.target.result)], {
30107
- type: file.type
30108
- });
30109
- blob.name = file.name;
30110
- replace = false;
30111
- this.processAndUpload([blob]);
30112
- };
30113
- reader.readAsArrayBuffer(file);
30101
+ if (webViewCamera) {
30102
+ webViewCamera.getPicture((success) => {
30103
+ window.resolveLocalFileSystemURL(success, (fileEntry) => {
30104
+ fileEntry.file((file) => {
30105
+ const reader = new FileReader();
30106
+ reader.onloadend = (evt) => {
30107
+ const blob = new Blob([new Uint8Array(evt.target.result)], {
30108
+ type: file.type
30109
+ });
30110
+ blob.name = file.name;
30111
+ replace = false;
30112
+ this.processAndUpload([blob]);
30113
+ };
30114
+ reader.readAsArrayBuffer(file);
30115
+ });
30114
30116
  });
30117
+ }, (err) => {
30118
+ logger.error(err);
30119
+ }, {
30120
+ sourceType: webViewCamera.PictureSourceType.CAMERA,
30121
+ encodingType: webViewCamera.EncodingType.PNG,
30122
+ mediaType: webViewCamera.MediaType.PICTURE,
30123
+ saveToPhotoAlbum: true,
30124
+ correctOrientation: false,
30115
30125
  });
30116
- }, (err) => {
30117
- logger.error(err);
30118
- }, {
30119
- sourceType: webViewCamera.PictureSourceType.CAMERA,
30120
- encodingType: webViewCamera.EncodingType.PNG,
30121
- mediaType: webViewCamera.MediaType.PICTURE,
30122
- saveToPhotoAlbum: true,
30123
- correctOrientation: false,
30124
- });
30126
+ } else {
30127
+ let id = this.component.id;
30128
+ isfileBrowse = false;
30129
+ window.isListenerSet = false;
30130
+ let eventCustom = new CustomEvent("openCamera", {
30131
+ detail: {
30132
+ controlId: id,
30133
+ },
30134
+ });
30135
+
30136
+ if (window.parent && window.parent !== window) {
30137
+ window.parent.postMessage(
30138
+ {
30139
+ type: "OPEN_CAMERA",
30140
+ data: { controlId: id },
30141
+ status: "sucess",
30142
+ message: "camera triggerd",
30143
+ },
30144
+ "*"
30145
+ );
30146
+ }
30147
+
30148
+ logger.info("[TF_SDK] ✅ Dispatching openCamera event for controlId:", id);
30149
+ document.dispatchEvent(eventCustom);
30150
+ }
30125
30151
  });
30126
30152
  }
30127
30153
 
@@ -30131,14 +30157,32 @@ class SmartFileComponent extends FieldComponent {
30131
30157
  this.takePicture();
30132
30158
  });
30133
30159
  }
30134
- let currentObj = this;
30135
30160
  if (this.refs.toggleCameraMode) {
30136
30161
  this.addEventListener(this.refs.toggleCameraMode, 'click', (event) => {
30137
30162
  event.preventDefault();
30138
- let id = currentObj.id
30163
+ let id = this.component.id;
30139
30164
  isfileBrowse = false;
30140
- this.cameraMode = !this.cameraMode;
30141
- this.redraw();
30165
+ window.isListenerSet = false;
30166
+ let eventCustom = new CustomEvent("openCamera", {
30167
+ detail: {
30168
+ controlId: id,
30169
+ },
30170
+ });
30171
+
30172
+ if (window.parent && window.parent !== window) {
30173
+ window.parent.postMessage(
30174
+ {
30175
+ type: "OPEN_CAMERA",
30176
+ data: { controlId: id },
30177
+ status: "sucess",
30178
+ message: "camera triggerd",
30179
+ },
30180
+ "*"
30181
+ );
30182
+ }
30183
+
30184
+ logger.info("[TF_SDK:84b] ✅ Dispatching openCamera event from toggleCameraMode for controlId:", id);
30185
+ document.dispatchEvent(eventCustom);
30142
30186
  });
30143
30187
  }
30144
30188
 
@@ -30189,24 +30233,47 @@ class SmartFileComponent extends FieldComponent {
30189
30233
  logger.info("[TF_SDK:84] ✅ event.detail.controlId =" + event.detail.controlId)
30190
30234
  if (that.component.id == event.detail.controlId) {
30191
30235
  if (!window.isListenerSet) {
30192
- window.resolveLocalFileSystemURL(event.detail.imageData, (fileEntry) => {
30193
- fileEntry.file((file) => {
30194
- logger.info("[TF_SDK:85] fileEntry =" + file)
30195
- const reader = new FileReader();
30196
- reader.onloadend = (evt) => {
30197
- logger.info("[TF_SDK:86] onloadend =" + evt)
30198
- const blob = new Blob([new Uint8Array(evt.target.result)], {
30199
- type: file.type
30200
- });
30201
- blob.name = file.name;
30202
- logger.info("[TF_SDK:87] ✅ file.name =" + file.name);
30203
- logger.info("[TF_SDK:88] blob instanceOf Blob =" + blob)
30204
- that.compressFile([blob])
30205
- };
30206
- reader.readAsArrayBuffer(file);
30207
- });
30208
- })
30209
- window.isListenerSet = true;
30236
+ const isBase64 = typeof event.detail.imageData === 'string' && event.detail.imageData.startsWith('data:');
30237
+ if (isBase64 || typeof window.resolveLocalFileSystemURL !== 'function') {
30238
+ const base64ToFile = (base64, filename, contentType = 'image/jpeg') => {
30239
+ const arr = base64.split(',');
30240
+ const mime = arr[0].match(/:(.*?);/)[1];
30241
+ const bstr = atob(arr[1]);
30242
+ let n = bstr.length;
30243
+ const u8arr = new Uint8Array(n);
30244
+ while (n--) {
30245
+ u8arr[n] = bstr.charCodeAt(n);
30246
+ }
30247
+ return new File([u8arr], filename, { type: contentType });
30248
+ };
30249
+ const file = base64ToFile(
30250
+ event.detail.imageData,
30251
+ event.detail.fileName || `photo-${Date.now()}.jpg`
30252
+ );
30253
+ isfileBrowse = false;
30254
+ replace = false;
30255
+ that.compressFile([file]);
30256
+ window.isListenerSet = true;
30257
+ } else {
30258
+ window.resolveLocalFileSystemURL(event.detail.imageData, (fileEntry) => {
30259
+ fileEntry.file((file) => {
30260
+ logger.info("[TF_SDK:85] ✅ fileEntry =" + file)
30261
+ const reader = new FileReader();
30262
+ reader.onloadend = (evt) => {
30263
+ logger.info("[TF_SDK:86] ✅ onloadend =" + evt)
30264
+ const blob = new Blob([new Uint8Array(evt.target.result)], {
30265
+ type: file.type
30266
+ });
30267
+ blob.name = file.name;
30268
+ logger.info("[TF_SDK:87] ✅ file.name =" + file.name);
30269
+ logger.info("[TF_SDK:88] ✅ blob instanceOf Blob =" + blob)
30270
+ that.compressFile([blob])
30271
+ };
30272
+ reader.readAsArrayBuffer(file);
30273
+ });
30274
+ })
30275
+ window.isListenerSet = true;
30276
+ }
30210
30277
  }
30211
30278
  }
30212
30279
  }, false);
@@ -41662,7 +41729,7 @@ initThemeHook();
41662
41729
  </div>
41663
41730
 
41664
41731
  <div id="sticky-footer">
41665
- <div class="build-version">SDK v2.0.64</div>
41732
+ <div class="build-version">SDK v2.0.66</div>
41666
41733
 
41667
41734
  <button class="footer-btn footer-btn-secondary" id="prevBtn" style="display:none" onclick="FormOnPrevious()">
41668
41735
  <i class="bi bi-chevron-left"></i> Previous
@@ -42150,6 +42217,15 @@ initThemeHook();
42150
42217
 
42151
42218
  if (showLoader && sdkLoader) {
42152
42219
  sdkLoader.classList.remove('hidden');
42220
+ // Handle loader back button visibility
42221
+ const loaderBackBtn = sdkLoader.querySelector('.sdk-loader-back-btn');
42222
+ if (loaderBackBtn) {
42223
+ if (payloadData.showBackButton === false || payloadData.showBackButton === 'false') {
42224
+ loaderBackBtn.style.setProperty('display', 'none', 'important');
42225
+ } else {
42226
+ loaderBackBtn.style.setProperty('display', 'inline-block', 'important');
42227
+ }
42228
+ }
42153
42229
  } else {
42154
42230
  if (sdkLoader) sdkLoader.classList.add('hidden');
42155
42231
  document.querySelectorAll('.tf-form-loading').forEach(el => el.classList.remove('tf-form-loading'));