@unvired/turboforms-embed-sdk 2.0.63 → 2.0.65

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
 
@@ -30189,24 +30215,47 @@ class SmartFileComponent extends FieldComponent {
30189
30215
  logger.info("[TF_SDK:84] ✅ event.detail.controlId =" + event.detail.controlId)
30190
30216
  if (that.component.id == event.detail.controlId) {
30191
30217
  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;
30218
+ const isBase64 = typeof event.detail.imageData === 'string' && event.detail.imageData.startsWith('data:');
30219
+ if (isBase64 || typeof window.resolveLocalFileSystemURL !== 'function') {
30220
+ const base64ToFile = (base64, filename, contentType = 'image/jpeg') => {
30221
+ const arr = base64.split(',');
30222
+ const mime = arr[0].match(/:(.*?);/)[1];
30223
+ const bstr = atob(arr[1]);
30224
+ let n = bstr.length;
30225
+ const u8arr = new Uint8Array(n);
30226
+ while (n--) {
30227
+ u8arr[n] = bstr.charCodeAt(n);
30228
+ }
30229
+ return new File([u8arr], filename, { type: contentType });
30230
+ };
30231
+ const file = base64ToFile(
30232
+ event.detail.imageData,
30233
+ event.detail.fileName || `photo-${Date.now()}.jpg`
30234
+ );
30235
+ isfileBrowse = false;
30236
+ replace = false;
30237
+ that.compressFile([file]);
30238
+ window.isListenerSet = true;
30239
+ } else {
30240
+ window.resolveLocalFileSystemURL(event.detail.imageData, (fileEntry) => {
30241
+ fileEntry.file((file) => {
30242
+ logger.info("[TF_SDK:85] ✅ fileEntry =" + file)
30243
+ const reader = new FileReader();
30244
+ reader.onloadend = (evt) => {
30245
+ logger.info("[TF_SDK:86] ✅ onloadend =" + evt)
30246
+ const blob = new Blob([new Uint8Array(evt.target.result)], {
30247
+ type: file.type
30248
+ });
30249
+ blob.name = file.name;
30250
+ logger.info("[TF_SDK:87] ✅ file.name =" + file.name);
30251
+ logger.info("[TF_SDK:88] ✅ blob instanceOf Blob =" + blob)
30252
+ that.compressFile([blob])
30253
+ };
30254
+ reader.readAsArrayBuffer(file);
30255
+ });
30256
+ })
30257
+ window.isListenerSet = true;
30258
+ }
30210
30259
  }
30211
30260
  }
30212
30261
  }, false);
@@ -30786,8 +30835,16 @@ class SmartFileComponent extends FieldComponent {
30786
30835
  : this.t('Preparing file to remove'),
30787
30836
  });
30788
30837
 
30789
- const index = this.dataValue.findIndex((file) => file.name === fileInfo.name);
30790
- this.splice(index);
30838
+ const index = this.dataValue.findIndex((file) =>
30839
+ file === fileInfo ||
30840
+ (file.id && file.id === fileInfo.id) ||
30841
+ (file.name && file.name === fileInfo.name)
30842
+ );
30843
+ if (index !== -1) {
30844
+ this.splice(index);
30845
+ } else {
30846
+ logger.warn(`[TF_SDK:102b] ⚠️ Could not find file to delete in dataValue:`, fileInfo);
30847
+ }
30791
30848
  this.redraw();
30792
30849
  }
30793
30850
 
@@ -40556,17 +40613,30 @@ function processFilePreviewsAndErrors(comp) {
40556
40613
  e.preventDefault();
40557
40614
  e.stopPropagation();
40558
40615
 
40616
+ // Resolve current image src dynamically at click time
40617
+ let currentImgSrc = "";
40618
+ const previewImg = row.querySelector('.file-preview-img, [ref="fileImage"]');
40619
+ if (previewImg && previewImg.src) {
40620
+ currentImgSrc = previewImg.src;
40621
+ } else {
40622
+ const link = row.querySelector('a');
40623
+ const imageExtensionPattern = /\.(jpg|jpeg|png|gif|webp|svg)$/i;
40624
+ if (link && link.href && (imageExtensionPattern.test(link.href) || link.href.startsWith('data:image'))) {
40625
+ currentImgSrc = link.href;
40626
+ }
40627
+ }
40628
+
40559
40629
  // 🖼️ Custom Preview Integration
40560
- if (iconCfg.title === 'Preview' && imgSrc && typeof window.openImagePreviewModal === 'function') {
40630
+ if (iconCfg.title === 'Preview' && currentImgSrc && typeof window.openImagePreviewModal === 'function') {
40561
40631
  const fileName = row.querySelector('a')?.textContent?.trim() || 'File Preview';
40562
- window.openImagePreviewModal(imgSrc, fileName);
40632
+ window.openImagePreviewModal(currentImgSrc, fileName);
40563
40633
  return;
40564
40634
  }
40565
40635
 
40566
40636
  // ✂️ Custom Crop Integration
40567
- if (iconCfg.title === 'Edit' && imgSrc && typeof cropro !== 'undefined') {
40637
+ if (iconCfg.title === 'Edit' && currentImgSrc && typeof cropro !== 'undefined') {
40568
40638
  const tempImg = new Image();
40569
- tempImg.src = imgSrc;
40639
+ tempImg.src = currentImgSrc;
40570
40640
  tempImg.style.position = 'fixed';
40571
40641
  tempImg.style.visibility = 'hidden';
40572
40642
  tempImg.style.pointerEvents = 'none';
@@ -40578,7 +40648,6 @@ function processFilePreviewsAndErrors(comp) {
40578
40648
  cropArea.renderAtNaturalSize = true;
40579
40649
  cropArea.popupMargin = 60; // Increase margin to reduce modal size
40580
40650
 
40581
- // Apply Custom Theme Colors to Crop Area
40582
40651
  // Apply Custom Theme Colors to Crop Area
40583
40652
  if (cropArea.styles && cropArea.styles.settings && comp.closest('.tf-embed-sdk')) {
40584
40653
  const computedStyle = getComputedStyle(comp);
@@ -40636,7 +40705,7 @@ function processFilePreviewsAndErrors(comp) {
40636
40705
  // Default: Dispatch custom event for app-level integration
40637
40706
 
40638
40707
  const customEvent = new CustomEvent(`formio-file-action`, {
40639
- detail: { element: comp, icon: iconCfg, row: row, imgSrc: imgSrc },
40708
+ detail: { element: comp, icon: iconCfg, row: row, imgSrc: currentImgSrc },
40640
40709
  bubbles: true
40641
40710
  });
40642
40711
  actionBtn.dispatchEvent(customEvent);
@@ -41642,7 +41711,7 @@ initThemeHook();
41642
41711
  </div>
41643
41712
 
41644
41713
  <div id="sticky-footer">
41645
- <div class="build-version">SDK v2.0.63</div>
41714
+ <div class="build-version">SDK v2.0.65</div>
41646
41715
 
41647
41716
  <button class="footer-btn footer-btn-secondary" id="prevBtn" style="display:none" onclick="FormOnPrevious()">
41648
41717
  <i class="bi bi-chevron-left"></i> Previous
@@ -42130,6 +42199,15 @@ initThemeHook();
42130
42199
 
42131
42200
  if (showLoader && sdkLoader) {
42132
42201
  sdkLoader.classList.remove('hidden');
42202
+ // Handle loader back button visibility
42203
+ const loaderBackBtn = sdkLoader.querySelector('.sdk-loader-back-btn');
42204
+ if (loaderBackBtn) {
42205
+ if (payloadData.showBackButton === false || payloadData.showBackButton === 'false') {
42206
+ loaderBackBtn.style.setProperty('display', 'none', 'important');
42207
+ } else {
42208
+ loaderBackBtn.style.setProperty('display', 'inline-block', 'important');
42209
+ }
42210
+ }
42133
42211
  } else {
42134
42212
  if (sdkLoader) sdkLoader.classList.add('hidden');
42135
42213
  document.querySelectorAll('.tf-form-loading').forEach(el => el.classList.remove('tf-form-loading'));