@yoobic/yobi 8.4.9 → 8.4.10

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.
@@ -1,14 +1,14 @@
1
1
  import { MediaType, PictureSourceType } from '@awesome-cordova-plugins/camera';
2
2
  import { MediaCapture } from '@awesome-cordova-plugins/media-capture';
3
3
  import { StatusBar } from '@capacitor/status-bar';
4
- import { addFilePrefix, asyncWaterfall, audios, changeExtension, downloadFile, getAsyncExtraData, getFormCapturedFileSize, getMimeType, getSession, hasLargeFile, images, isAndroid, isAudio, isCloudinaryLink, isFile, isGif, isImage, isImageUrl, isIOS, isIphoneX, isLenovo, isNativeFilePath, isNativeMobile, isNullOrUndefined, isOffline, isPhotoEdited, isSafari, isUnsplashUrl, isVideo, isWeb, moveToImageDirectory, pipes, read, showActionSheet, showAlert, showContextMenu, showModal, showToast, translate, translateMulti, updatePathSessionId, videos } from '@shared/utils';
4
+ import { addFilePrefix, asyncWaterfall, audios, changeExtension, downloadFile, getAsyncExtraData, getFormCapturedFileSize, getMimeType, getSession, hasLargeFile, images, isAndroid, isAudio, isCloudinaryLink, isFile, isGif, isImage, isImageUrl, isIOS, isIphoneX, isLenovo, isNativeFilePath, isNativeMobile, isNullOrUndefined, isOffline, isPhotoEdited, isSafari, isUnsplashUrl, isVideo, isWeb, pipes, read, showActionSheet, showAlert, showContextMenu, showModal, showToast, translate, translateMulti, updatePathSessionId, videos } from '@shared/utils';
5
5
  import { Build, Component, Element, Event, h, Host, Method, Prop, State, Watch } from '@stencil/core';
6
6
  import { assign, assignInWith, clone, compact, intersection, isArray, isNumber, isUndefined, keys } from 'lodash-es';
7
7
  import { getPicture, getVideo, getVideoDevices, importMultipleFromLibrary, showAudioRecorder } from '../../../utils/helpers/camera-helpers';
8
8
  import { getAppContext, querySelectorAllDeep, querySelectorDeep, showImageCropper, showPhotoEditor, showSlidesMedia } from '../../../utils/helpers/common-helpers';
9
9
  import { initArrayValue } from '../../../utils/helpers/form-helpers';
10
10
  import { setValidator, setValueAndValidateInput } from '../../../utils/helpers/form-input-helpers';
11
- import { shouldUseLowPerformanceCamera } from './form-capture-helper';
11
+ import { processMediaPath, shouldUseLowPerformanceCamera } from './form-capture-helper';
12
12
  export class YooFormCaptureComponent {
13
13
  constructor() {
14
14
  this.extraData = {};
@@ -37,9 +37,15 @@ export class YooFormCaptureComponent {
37
37
  this.updateExtraData(extraData);
38
38
  }
39
39
  /** If there is index, the field is a multiphoto */
40
- async setFieldValue(data) {
41
- this.multiple ? this.value.push(data) : this.value = data;
42
- setValueAndValidateInput(this.value, this);
40
+ async setFieldValue(index, data) {
41
+ if (index === undefined) {
42
+ setValueAndValidateInput(data, this);
43
+ }
44
+ else {
45
+ const newValue = this.value ? [...this.value] : [];
46
+ newValue[index] = data;
47
+ setValueAndValidateInput(newValue, this);
48
+ }
43
49
  }
44
50
  async stopImageRecognitionProcess(isCancelled = false) {
45
51
  this.imageRecoCancelled = isCancelled;
@@ -231,7 +237,7 @@ export class YooFormCaptureComponent {
231
237
  }
232
238
  allowCrop(file) {
233
239
  var _a;
234
- return (((_a = this.cropperOptions) === null || _a === void 0 ? void 0 : _a.cropRatio) > 0 || this.showCropper) && isImage(file) && !isGif(file) && (!(typeof file === 'string' && isUnsplashUrl(file)) || isWeb(this.host));
240
+ return isWeb(this.host) && (((_a = this.cropperOptions) === null || _a === void 0 ? void 0 : _a.cropRatio) > 0 || this.showCropper) && isImage(file) && !isGif(file) && (!(typeof file === 'string' && isUnsplashUrl(file)) || isWeb(this.host));
235
241
  }
236
242
  removeAllCapture() {
237
243
  this.value = [];
@@ -259,7 +265,7 @@ export class YooFormCaptureComponent {
259
265
  }
260
266
  /** for webcam, choose which device to take photo/video */
261
267
  capture(device, index) {
262
- var _a, _b;
268
+ var _a, _b, _c;
263
269
  let newIndex = index;
264
270
  if (index < 0) {
265
271
  newIndex = (_b = (_a = this.value) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
@@ -267,7 +273,7 @@ export class YooFormCaptureComponent {
267
273
  if (isNativeMobile()) {
268
274
  let newIndex = index;
269
275
  if (index < 0) {
270
- if (this.value && this.value.length) {
276
+ if ((_c = this.value) === null || _c === void 0 ? void 0 : _c.length) {
271
277
  newIndex = this.value.length;
272
278
  }
273
279
  else {
@@ -291,33 +297,19 @@ export class YooFormCaptureComponent {
291
297
  }
292
298
  }
293
299
  async processMediaData(mediaData, index) {
294
- if (mediaData === null || mediaData === void 0 ? void 0 : mediaData.includes('?')) {
295
- mediaData = mediaData.substring(0, mediaData.indexOf('?'));
296
- }
297
- else if (mediaData && !isImageUrl(mediaData)) {
298
- mediaData = addFilePrefix(mediaData);
299
- if (!isAndroid() && ['cache', 'tmp'].includes(mediaData)) {
300
- try {
301
- mediaData = await moveToImageDirectory(mediaData, getSession().user ? getSession().user.disablePhotoOrientationAutoFix : false);
302
- }
303
- catch (err) {
304
- throw new Error(err);
305
- }
306
- }
307
- }
308
300
  try {
301
+ !isImageUrl(mediaData) && (mediaData = await processMediaPath(mediaData));
309
302
  if (this.shouldTagImage()) {
310
303
  const tag = await this.showPhotoTagDialog(mediaData);
311
304
  (tag === null || tag === void 0 ? void 0 : tag.data) && this.updateTagData(tag, index);
312
305
  }
313
- await this.setFieldValue(mediaData);
306
+ await this.setFieldValue(index, mediaData);
314
307
  this.clearPhotoEdit(index);
315
308
  this.saveGeoloc && this.captureGeoloc(index);
316
309
  }
317
310
  catch (err) {
318
311
  throw new Error(err);
319
312
  }
320
- return mediaData;
321
313
  }
322
314
  showPhotoTagDialog(imageSrc, value) {
323
315
  const imageTag = document.createElement('yoo-form-capture-tag-dialog');
@@ -325,7 +317,8 @@ export class YooFormCaptureComponent {
325
317
  imageTag.imageSrc = imageSrc;
326
318
  imageTag.value = value;
327
319
  imageTag.addEventListener('fetchData', (ev) => {
328
- this.onFetchGridData(ev);
320
+ ev.stopPropagation();
321
+ this.fetchData.emit(ev.detail);
329
322
  });
330
323
  return showModal(imageTag, null, '', 'slideYEnterAnimation', 'slideYLeaveAnimation');
331
324
  }
@@ -379,7 +372,7 @@ export class YooFormCaptureComponent {
379
372
  });
380
373
  }
381
374
  async capturePhoto(useLibrary, index) {
382
- var _a, _b, _c;
375
+ var _a, _b, _c, _d, _e;
383
376
  const quality = this.isImageRecognition ? 100 : 70;
384
377
  const sourceType = useLibrary ? PictureSourceType.PHOTOLIBRARY : PictureSourceType.CAMERA;
385
378
  const mediaType = this.type === 'video' ? MediaType.VIDEO : MediaType.PICTURE;
@@ -449,26 +442,22 @@ export class YooFormCaptureComponent {
449
442
  if (!res && this.showImageLoader) {
450
443
  this.showImageLoader = false;
451
444
  }
445
+ const newIndex = index < 0 ? ((_e = (_d = this.value) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0) : index;
452
446
  const imagesData = Array.isArray(res) ? res : [res];
453
447
  const hasUnsplash = imagesData.some(d => isUnsplashUrl(d));
454
- const processImage = async (imageData, index) => {
455
- var _a;
448
+ const processImage = async (imageData, i) => {
456
449
  try {
457
- let extractedData = (imageData === null || imageData === void 0 ? void 0 : imageData['data']) || (imageData === null || imageData === void 0 ? void 0 : imageData['path']) || (imageData === null || imageData === void 0 ? void 0 : imageData['fullPath']) || imageData;
458
- if (!this.shouldTagImage()) {
459
- const shouldOpenCropper = !hasUnsplash && imagesData.length === 1 && this.allowCrop(imageData);
460
- const newIndex = Array.isArray(this.value) ? (_a = this.value) === null || _a === void 0 ? void 0 : _a.length : index;
461
- if (shouldOpenCropper) {
462
- extractedData = await this.onOpenCropper(imageData);
463
- }
464
- await this.processMediaData(extractedData, newIndex);
465
- }
450
+ let extractedData = await processMediaPath((imageData === null || imageData === void 0 ? void 0 : imageData['data']) || (imageData === null || imageData === void 0 ? void 0 : imageData['path']) || (imageData === null || imageData === void 0 ? void 0 : imageData['fullPath']) || imageData);
451
+ const shouldOpenCropper = !hasUnsplash && imagesData.length === 1 && this.allowCrop(extractedData);
452
+ shouldOpenCropper && (extractedData = await this.onOpenCropper(imageData));
453
+ const updatingIndex = this.multiple ? newIndex + i : undefined;
454
+ await this.processMediaData(extractedData, updatingIndex);
466
455
  }
467
456
  catch (err) {
468
457
  this.showImageLoader = false;
469
458
  }
470
459
  };
471
- await Promise.all(imagesData.map((data, index) => processImage(data, index)));
460
+ await asyncWaterfall(imagesData.map((data, i) => processImage(data, i)));
472
461
  this.showImageLoader = false;
473
462
  }
474
463
  catch (err) {
@@ -476,36 +465,29 @@ export class YooFormCaptureComponent {
476
465
  throw new Error(err);
477
466
  }
478
467
  }
479
- captureVideo(index) {
480
- const options = { limit: 1, duration: this.duration || 60, saveToPhotoAlbum: true };
481
- return getVideo(options).then((files) => {
482
- this.processMediaData(this.fixPathAndGetValue(files), index);
483
- });
468
+ async captureVideo(index) {
469
+ const files = await getVideo({ limit: 1, duration: this.duration || 60, saveToPhotoAlbum: true });
470
+ await Promise.all(files === null || files === void 0 ? void 0 : files.map(file => this.processMediaData(this.fixPathAndGetValue(file), index)));
484
471
  }
485
472
  async captureAudio(index) {
486
- if (isAndroid()) {
487
- const ret = await showAudioRecorder(this.host);
488
- if (ret && ret.data) {
489
- return this.processMediaData(ret.data, index);
473
+ try {
474
+ if (isAndroid()) {
475
+ const { data } = await showAudioRecorder(this.host);
476
+ this.processMediaData(data, index);
477
+ }
478
+ else {
479
+ const files = await MediaCapture.captureAudio({ limit: 1, duration: this.duration || 60 });
480
+ await Promise.all(files === null || files === void 0 ? void 0 : files.map(file => this.processMediaData(this.fixPathAndGetValue(file), index)));
490
481
  }
491
482
  }
492
- else {
493
- const options = { limit: 1, duration: this.duration || 60 };
494
- return MediaCapture.captureAudio(options)
495
- .then((files) => {
496
- this.processMediaData(this.fixPathAndGetValue(files), index);
497
- })
498
- .catch((err) => {
499
- if (err.code !== 3) {
500
- this.noAudio();
501
- }
502
- });
483
+ catch (err) {
484
+ if (err.code !== 3) {
485
+ showAlert(translate('AUDIO'), [translate('YOOBICOK')], translate('NOAUDIO'));
486
+ }
487
+ throw new Error(err);
503
488
  }
504
489
  }
505
- noAudio() {
506
- showAlert(translate('AUDIO'), [translate('YOOBICOK')], translate('NOAUDIO'));
507
- }
508
- fixSessionIdPath() {
490
+ async fixSessionIdPath() {
509
491
  if (isIOS() && isNativeMobile() && this.value && typeof this.value !== 'undefined') {
510
492
  if (Array.isArray(this.value)) {
511
493
  const newValue = [];
@@ -527,11 +509,8 @@ export class YooFormCaptureComponent {
527
509
  }
528
510
  }
529
511
  }
530
- fixPathAndGetValue(files) {
531
- if ((files === null || files === void 0 ? void 0 : files.length) > 0) {
532
- return addFilePrefix(files[0].fullPath);
533
- }
534
- return '';
512
+ fixPathAndGetValue(file) {
513
+ return addFilePrefix(file === null || file === void 0 ? void 0 : file.fullPath) || '';
535
514
  }
536
515
  captureFromWebcam(device, index) {
537
516
  let webcam = document.createElement('yoo-form-capture-webcam-dialog');
@@ -542,7 +521,7 @@ export class YooFormCaptureComponent {
542
521
  this.showPhotoTagDialog(ret.data).then((tag) => {
543
522
  if (!isNullOrUndefined(tag === null || tag === void 0 ? void 0 : tag.data)) {
544
523
  this.updateTagData(tag, index);
545
- this.setFieldValue(ret.data);
524
+ this.setFieldValue(index, ret.data);
546
525
  this.clearPhotoEdit(index);
547
526
  if (this.saveGeoloc) {
548
527
  this.captureGeoloc();
@@ -551,7 +530,7 @@ export class YooFormCaptureComponent {
551
530
  });
552
531
  }
553
532
  else {
554
- this.setFieldValue(ret.data);
533
+ this.setFieldValue(index, ret.data);
555
534
  this.clearPhotoEdit(index);
556
535
  if (this.saveGeoloc) {
557
536
  this.captureGeoloc();
@@ -651,7 +630,7 @@ export class YooFormCaptureComponent {
651
630
  }
652
631
  else {
653
632
  if (this.multiple && (newImages === null || newImages === void 0 ? void 0 : newImages.length) > 0) {
654
- this.setFieldValue(newImages);
633
+ this.setFieldValue(index, newImages);
655
634
  }
656
635
  else if (newImages === null || newImages === void 0 ? void 0 : newImages.length) {
657
636
  this.value = newImages[0];
@@ -662,9 +641,10 @@ export class YooFormCaptureComponent {
662
641
  });
663
642
  }
664
643
  captureGeoloc(index) {
644
+ var _a;
665
645
  let newIndex = index;
666
646
  if (this.saveGeoloc) {
667
- if (isNullOrUndefined(newIndex) && this.multiple && this.value && this.value.length - 1 > -1) {
647
+ if (isNullOrUndefined(newIndex) && this.multiple && ((_a = this.value) === null || _a === void 0 ? void 0 : _a.length) - 1 > -1) {
668
648
  newIndex = this.value.length - 1;
669
649
  }
670
650
  this.getGeoloc.emit(newIndex);
@@ -690,10 +670,6 @@ export class YooFormCaptureComponent {
690
670
  this.captureFromDisk(index);
691
671
  }
692
672
  }
693
- onFetchGridData(ev) {
694
- ev.stopPropagation();
695
- this.fetchData.emit(ev.detail);
696
- }
697
673
  getTargetElement(index) {
698
674
  return index !== undefined ? Array.from(this.fileInputs).find((_, ind) => ind === index) : this.fileInputs;
699
675
  }
@@ -714,17 +690,17 @@ export class YooFormCaptureComponent {
714
690
  const tag = await this.showPhotoTagDialog(data);
715
691
  if (!isNullOrUndefined(tag === null || tag === void 0 ? void 0 : tag.data)) {
716
692
  this.updateTagData(tag, index);
717
- this.setFieldValue(data);
693
+ this.setFieldValue(index, data);
718
694
  this.clearPhotoEdit(index);
719
695
  }
720
696
  }
721
697
  else {
722
- this.setFieldValue(data);
698
+ this.setFieldValue(index, data);
723
699
  this.clearPhotoEdit(index);
724
700
  }
725
701
  }
726
702
  else {
727
- this.setFieldValue(f);
703
+ this.setFieldValue(index, f);
728
704
  this.clearPhotoEdit(index);
729
705
  }
730
706
  targetElement.value = null;
@@ -1605,7 +1581,8 @@ export class YooFormCaptureComponent {
1605
1581
  }
1606
1582
  }
1607
1583
  shouldTagImage() {
1608
- return this.tags && this.tags.length > 0;
1584
+ var _a;
1585
+ return ((_a = this.tags) === null || _a === void 0 ? void 0 : _a.length) > 0;
1609
1586
  }
1610
1587
  onCancelImageReco() {
1611
1588
  showAlert('', [translate('YOOBICNO'), translate('YOOBICYES')], translate('STOPIMAGERECO')).then((res) => {
@@ -2779,10 +2756,13 @@ export class YooFormCaptureComponent {
2779
2756
  },
2780
2757
  "setFieldValue": {
2781
2758
  "complexType": {
2782
- "signature": "(data: any) => Promise<void>",
2759
+ "signature": "(index: number, data: any) => Promise<void>",
2783
2760
  "parameters": [{
2784
2761
  "tags": [],
2785
2762
  "text": ""
2763
+ }, {
2764
+ "tags": [],
2765
+ "text": ""
2786
2766
  }],
2787
2767
  "references": {
2788
2768
  "Promise": {
@@ -295,7 +295,7 @@ export class YooFormDynamicComponent {
295
295
  const videoValue = fieldData.value;
296
296
  const videoElement = el;
297
297
  if (videoValue) {
298
- videoElement.setFieldValue(videoValue);
298
+ videoElement.setFieldValue(undefined, videoValue);
299
299
  }
300
300
  break;
301
301
  }