@eui/components 14.0.28 → 14.0.29

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.
@@ -17,7 +17,7 @@ import { TranslateModule } from '@ngx-translate/core';
17
17
  import * as i1$1 from '@angular/common/http';
18
18
  import { HttpEventType } from '@angular/common/http';
19
19
  import { tap, filter, map } from 'rxjs/operators';
20
- import { pipe } from 'rxjs';
20
+ import { pipe, zip, of, Observable } from 'rxjs';
21
21
 
22
22
  class EuiFileUploadProgressComponent {
23
23
  constructor() {
@@ -625,6 +625,323 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImpo
625
625
  }]
626
626
  }] });
627
627
 
628
+ const getMimeType = (header) => {
629
+ // convert Uint8Array to hex string
630
+ const hex = uint8ArrayToHexString(header);
631
+ // map hex string to mime type
632
+ if (hex.startsWith('89504e47')) {
633
+ return 'image/png';
634
+ }
635
+ if (hex.startsWith('464c4946')) {
636
+ return 'image/flif';
637
+ }
638
+ if (hex.startsWith('67696d7020786366')) {
639
+ return 'image/x-xcf';
640
+ }
641
+ if (hex.startsWith('49492a00')) {
642
+ return 'image/x-canon-cr2';
643
+ }
644
+ if (hex.startsWith('49492a00')) {
645
+ return 'image/x-canon-cr3';
646
+ }
647
+ if (hex.startsWith('49492a00')) {
648
+ return 'image/tiff';
649
+ }
650
+ if (hex.startsWith('424d')) {
651
+ return 'image/bmp';
652
+ }
653
+ if (hex.startsWith('69636e73')) {
654
+ return 'image/icns';
655
+ }
656
+ if (hex.startsWith('49491a0000004845415050')) {
657
+ return 'image/vnd.ms-photo';
658
+ }
659
+ if (hex.startsWith('38425053')) {
660
+ return 'image/vnd.adobe.photoshop';
661
+ }
662
+ if (hex.startsWith('06054b50')) {
663
+ return 'application/x-indesign';
664
+ }
665
+ if (hex.startsWith('504b0304')) {
666
+ return 'application/epub+zip';
667
+ }
668
+ if (hex.startsWith('504b0304')) {
669
+ return 'application/x-xpinstall';
670
+ }
671
+ if (hex.startsWith('504b0304')) {
672
+ return 'application/vnd.oasis.opendocument.text';
673
+ }
674
+ if (hex.startsWith('504b0304')) {
675
+ return 'application/vnd.oasis.opendocument.spreadsheet';
676
+ }
677
+ if (hex.startsWith('504b0304')) {
678
+ return 'application/vnd.oasis.opendocument.presentation';
679
+ }
680
+ if (hex.startsWith('504b0304')) {
681
+ return 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
682
+ }
683
+ if (hex.startsWith('504b0304')) {
684
+ return 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
685
+ }
686
+ if (hex.startsWith('504b0304')) {
687
+ return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
688
+ }
689
+ if (hex.startsWith('504b0304')) {
690
+ return 'application/zip';
691
+ }
692
+ if (hex.startsWith('7b2274797065223a226a736f6e227d')) {
693
+ return 'application/json';
694
+ }
695
+ if (hex.startsWith('7573746172')) {
696
+ return 'application/x-tar';
697
+ }
698
+ if (hex.startsWith('526172211a0700')) {
699
+ return 'application/x-rar-compressed';
700
+ }
701
+ if (hex.startsWith('1f8b08')) {
702
+ return 'application/gzip';
703
+ }
704
+ if (hex.startsWith('425a68')) {
705
+ return 'application/x-bzip2';
706
+ }
707
+ if (hex.startsWith('377abcaf271c')) {
708
+ return 'application/x-7z-compressed';
709
+ }
710
+ if (hex.startsWith('78da')) {
711
+ return 'application/x-apple-diskimage';
712
+ }
713
+ if (hex.startsWith('00000020667479706d70')) {
714
+ return 'video/mp4';
715
+ }
716
+ if (hex.startsWith('4d546864')) {
717
+ return 'audio/midi';
718
+ }
719
+ if (hex.startsWith('1a45dfa393428288')) {
720
+ return 'video/x-matroska';
721
+ }
722
+ if (hex.startsWith('1a45dfa3')) {
723
+ return 'video/webm';
724
+ }
725
+ if (hex.startsWith('00000014667479707174')) {
726
+ return 'video/quicktime';
727
+ }
728
+ if (hex.startsWith('52494646')) {
729
+ return 'video/vnd.avi';
730
+ }
731
+ if (hex.startsWith('52494646')) {
732
+ return 'audio/vnd.wave';
733
+ }
734
+ if (hex.startsWith('0a010301')) {
735
+ return 'audio/qcelp';
736
+ }
737
+ if (hex.startsWith('3026b2758e66cf11')) {
738
+ return 'audio/x-ms-asf';
739
+ }
740
+ if (hex.startsWith('3026b2758e66cf11')) {
741
+ return 'video/x-ms-asf';
742
+ }
743
+ if (hex.startsWith('3026b2758e66cf11')) {
744
+ return 'application/vnd.ms-asf';
745
+ }
746
+ if (hex.startsWith('000001ba')) {
747
+ return 'video/mpeg';
748
+ }
749
+ if (hex.startsWith('00000020667479703367')) {
750
+ return 'video/3gpp';
751
+ }
752
+ if (hex.startsWith('494433')) {
753
+ return 'audio/mpeg';
754
+ }
755
+ if (hex.startsWith('00000020667479704d344120')) {
756
+ return 'audio/mp4';
757
+ }
758
+ if (hex.startsWith('4f707573')) {
759
+ return 'audio/opus';
760
+ }
761
+ if (hex.startsWith('4f676753')) {
762
+ return 'video/ogg';
763
+ }
764
+ if (hex.startsWith('4f676753')) {
765
+ return 'audio/ogg';
766
+ }
767
+ if (hex.startsWith('4f676753')) {
768
+ return 'application/ogg';
769
+ }
770
+ if (hex.startsWith('664c6143')) {
771
+ return 'audio/x-flac';
772
+ }
773
+ if (hex.startsWith('4d414320')) {
774
+ return 'audio/ape';
775
+ }
776
+ if (hex.startsWith('7776706b')) {
777
+ return 'audio/wavpack';
778
+ }
779
+ if (hex.startsWith('2321414d520a')) {
780
+ return 'audio/amr';
781
+ }
782
+ if (hex.startsWith('255044462d312e')) {
783
+ return 'application/pdf';
784
+ }
785
+ if (hex.startsWith('7f454c46')) {
786
+ return 'application/x-elf';
787
+ }
788
+ if (hex.startsWith('4d5a')) {
789
+ return 'application/x-msdownload';
790
+ }
791
+ if (hex.startsWith('435753')) {
792
+ return 'application/x-shockwave-flash';
793
+ }
794
+ if (hex.startsWith('7b5c72746631')) {
795
+ return 'application/rtf';
796
+ }
797
+ if (hex.startsWith('0061736d')) {
798
+ return 'application/wasm';
799
+ }
800
+ if (hex.startsWith('774f4646')) {
801
+ return 'font/woff';
802
+ }
803
+ if (hex.startsWith('774f4632')) {
804
+ return 'font/woff2';
805
+ }
806
+ if (hex.startsWith('000100000008')) {
807
+ return 'application/vnd.ms-fontobject';
808
+ }
809
+ if (hex.startsWith('0001000000')) {
810
+ return 'font/ttf';
811
+ }
812
+ if (hex.startsWith('4f54544f00')) {
813
+ return 'font/otf';
814
+ }
815
+ if (hex.startsWith('000001000100')) {
816
+ return 'image/x-icon';
817
+ }
818
+ if (hex.startsWith('464c560105')) {
819
+ return 'video/x-flv';
820
+ }
821
+ if (hex.startsWith('25215053')) {
822
+ return 'application/postscript';
823
+ }
824
+ if (hex.startsWith('25215053')) {
825
+ return 'application/eps';
826
+ }
827
+ if (hex.startsWith('fd377a585a00')) {
828
+ return 'application/x-xz';
829
+ }
830
+ if (hex.startsWith('53514c69746520666f726d6174203300')) {
831
+ return 'application/x-sqlite3';
832
+ }
833
+ if (hex.startsWith('4e45531a00000001')) {
834
+ return 'application/x-nintendo-nes-rom';
835
+ }
836
+ if (hex.startsWith('504b0304')) {
837
+ return 'application/x-google-chrome-extension';
838
+ }
839
+ if (hex.startsWith('4d534346')) {
840
+ return 'application/vnd.ms-cab-compressed';
841
+ }
842
+ if (hex.startsWith('213c617263683e0a')) {
843
+ return 'application/x-deb';
844
+ }
845
+ if (hex.startsWith('1f8b08')) {
846
+ return 'application/x-unix-archive';
847
+ }
848
+ if (hex.startsWith('edabeedb')) {
849
+ return 'application/x-rpm';
850
+ }
851
+ if (hex.startsWith('1f9d90')) {
852
+ return 'application/x-compress';
853
+ }
854
+ if (hex.startsWith('4c5a4950')) {
855
+ return 'application/x-lzip';
856
+ }
857
+ if (hex.startsWith('d0cf11e0a1b11ae1')) {
858
+ return 'application/x-cfb';
859
+ }
860
+ if (hex.startsWith('4d49455f')) {
861
+ return 'application/x-mie';
862
+ }
863
+ if (hex.startsWith('4141523146')) {
864
+ return 'application/x-apache-arrow';
865
+ }
866
+ if (hex.startsWith('060e2b3402050101')) {
867
+ return 'application/mxf';
868
+ }
869
+ if (hex.startsWith('47')) {
870
+ return 'video/mp2t';
871
+ }
872
+ if (hex.startsWith('4250e4')) {
873
+ return 'application/x-blender';
874
+ }
875
+ if (hex.startsWith('425047fb')) {
876
+ return 'image/bpg';
877
+ }
878
+ if (hex.startsWith('ff4fff51')) {
879
+ return 'image/j2c';
880
+ }
881
+ if (hex.startsWith('0000000c6a5020200d0a')) {
882
+ return 'image/jp2';
883
+ }
884
+ if (hex.startsWith('6a5020200d0a870a')) {
885
+ return 'image/jpx';
886
+ }
887
+ if (hex.startsWith('6a5020200d0a870a')) {
888
+ return 'image/jpm';
889
+ }
890
+ if (hex.startsWith('0000000c6a5020200d0a')) {
891
+ return 'image/mj2';
892
+ }
893
+ if (hex.startsWith('464f524d')) {
894
+ return 'audio/aiff';
895
+ }
896
+ if (hex.startsWith('3c3f786d6c20')) {
897
+ return 'application/xml';
898
+ }
899
+ if (hex.startsWith('424f4f4b4d4f4249')) {
900
+ return 'application/x-mobipocket-ebook';
901
+ }
902
+ if (hex.startsWith('667479706174')) {
903
+ return 'image/heif';
904
+ }
905
+ if (hex.startsWith('667479706174')) {
906
+ return 'image/heif-sequence';
907
+ }
908
+ if (hex.startsWith('667479706174')) {
909
+ return 'image/heic';
910
+ }
911
+ if (hex.startsWith('667479706174')) {
912
+ return 'image/heic-sequence';
913
+ }
914
+ if (hex.startsWith('4b545820')) {
915
+ return 'image/ktx';
916
+ }
917
+ if (hex.startsWith('4449434d')) {
918
+ return 'application/dicom';
919
+ }
920
+ if (hex.startsWith('4d50434b')) {
921
+ return 'audio/x-musepack';
922
+ }
923
+ if (hex.startsWith('56656e64')) {
924
+ return 'text/calendar';
925
+ }
926
+ if (hex.startsWith('424547494e3a5643415244')) {
927
+ return 'text/vcard';
928
+ }
929
+ if (hex.startsWith('676c5458')) {
930
+ return 'model/gltf-binary';
931
+ }
932
+ if (hex.startsWith('d4c3b2a1')) {
933
+ return 'application/vnd.tcpdump.pcap';
934
+ }
935
+ if (hex.startsWith('464f524d')) {
936
+ return 'audio/x-voc';
937
+ }
938
+ if (hex.startsWith('64646f6c')) {
939
+ return 'audio/vnd.dolby.dd-raw';
940
+ }
941
+ return null;
942
+ };
943
+ const uint8ArrayToHexString = (uint8Array) => Array.prototype.map.call(uint8Array, (byte) => ('00' + byte.toString(16)).slice(-2)).join('');
944
+
628
945
  /**
629
946
  * @description
630
947
  * Validator that requires the maximum length of files that can be uploaded.
@@ -663,7 +980,7 @@ const maxSizeValidator = (maxSize) => (control) => {
663
980
  totalSize += file.size;
664
981
  });
665
982
  }
666
- return control.value && totalSize > (maxSize * 1.024) ? { maxSize } : null;
983
+ return control.value && totalSize > maxSize * 1.024 ? { maxSize } : null;
667
984
  };
668
985
  /**
669
986
  * @description
@@ -674,22 +991,42 @@ const maxSizeValidator = (maxSize) => (control) => {
674
991
  *
675
992
  * ```typescript
676
993
  * const fileUpload = new FormControl(null, mimeTypeExtensionValidator(['image/jpeg'])),
677
- * console.log(fileUpload.errors); // { invalidFileExtension: ['image/jpeg'] }
994
+ * console.log(fileUpload.errors); // { invalidMimeFileType: ['image/jpeg'] }
678
995
  * ```
679
996
  *
680
- * @returns A validator function that returns an error map with the
681
- * `invalidFileExtension` if the validation check fails, otherwise `null`.
997
+ * @returns An Async validator function that returns an error map with the
998
+ * `invalidMimeFileType` if the validation check fails, otherwise `null`.
682
999
  */
683
1000
  const mimeTypeExtensionValidator = (mimeTypes) => (control) => {
684
- const invalidFileExtension = [];
685
1001
  if (control.value) {
1002
+ const fileErrorObservables = [];
1003
+ // iterate over files
686
1004
  control.value.forEach((file) => {
687
- if (mimeTypes.indexOf(file.type) === -1) {
688
- invalidFileExtension.push(file.name);
689
- }
1005
+ // push observable which will check the mime validation type
1006
+ fileErrorObservables.push(validateFileMimeType(file, mimeTypes));
690
1007
  });
1008
+ return zip(...fileErrorObservables).pipe(map((fileErrors) => {
1009
+ const errors = fileErrors.filter((fileError) => fileError !== null);
1010
+ // Error should be { fileName: FileType }
1011
+ return { invalidMimeFileType: errors };
1012
+ }));
691
1013
  }
692
- return control.value && invalidFileExtension.length > 0 ? { invalidFileExtension } : null;
1014
+ return of(null);
1015
+ };
1016
+ const validateFileMimeType = (file, mimeTypes) => {
1017
+ return new Observable((subscriber) => {
1018
+ const reader = new FileReader();
1019
+ reader.onloadend = () => {
1020
+ const buffer = reader.result;
1021
+ const headerBytes = new Uint8Array(buffer).slice(0, 8);
1022
+ const mime = getMimeType(headerBytes);
1023
+ if (mimeTypes.indexOf(mime) === -1) {
1024
+ subscriber.next({ [file.name]: mime });
1025
+ }
1026
+ subscriber.complete();
1027
+ };
1028
+ reader.readAsArrayBuffer(file);
1029
+ });
693
1030
  };
694
1031
 
695
1032
  class EuiUploadedFile {