@bravobit/bb-foundation 0.53.1 → 0.53.2

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.
@@ -46,9 +46,6 @@ export declare class BbFilePicker implements ControlValueAccessor {
46
46
  };
47
47
  saveFile(files: File[]): void;
48
48
  private getFilesFromEvent;
49
- private isValidFileType;
50
- private isValidFileSize;
51
- private isFileLike;
52
49
  static ɵfac: i0.ɵɵFactoryDeclaration<BbFilePicker, never>;
53
50
  static ɵcmp: i0.ɵɵComponentDeclaration<BbFilePicker, "bb-file-picker", never, { "label": { "alias": "label"; "required": false; }; "hint": { "alias": "hint"; "required": false; }; "accept": { "alias": "accept"; "required": false; }; "maxFileSize": { "alias": "maxFileSize"; "required": false; }; "showImages": { "alias": "showImages"; "required": false; }; "grouped": { "alias": "grouped"; "required": false; }; "required": { "alias": "required"; "required": false; }; "disabled": { "alias": "disabled"; "required": false; }; "hideErrors": { "alias": "hideErrors"; "required": false; }; "value": { "alias": "value"; "required": false; }; }, { "valueChange": "valueChange"; }, ["extraTemplate"], never, true, never>;
54
51
  static ngAcceptInputType_maxFileSize: unknown;
@@ -61,9 +61,6 @@ export declare class BbMultiFileControl implements ControlValueAccessor {
61
61
  maxFileSize?: undefined;
62
62
  };
63
63
  addFiles(files: File[]): void;
64
- private isValidFileSize;
65
- private isValidFileType;
66
- private isFileLike;
67
64
  static ɵfac: i0.ɵɵFactoryDeclaration<BbMultiFileControl, never>;
68
65
  static ɵcmp: i0.ɵɵComponentDeclaration<BbMultiFileControl, "bb-multi-file-control", never, { "label": { "alias": "label"; "required": false; }; "hint": { "alias": "hint"; "required": false; }; "accept": { "alias": "accept"; "required": false; }; "maxFileSize": { "alias": "maxFileSize"; "required": false; }; "maxTotalFileSize": { "alias": "maxTotalFileSize"; "required": false; }; "grouped": { "alias": "grouped"; "required": false; }; "required": { "alias": "required"; "required": false; }; "disabled": { "alias": "disabled"; "required": false; }; "hideErrors": { "alias": "hideErrors"; "required": false; }; "items": { "alias": "items"; "required": false; }; }, { "delete": "delete"; }, never, never, true, never>;
69
66
  static ngAcceptInputType_maxFileSize: unknown;
@@ -12,7 +12,7 @@ import { BbTemplate } from '@bravobit/bb-foundation/utils';
12
12
  import * as i1$1 from '@angular/cdk/platform';
13
13
  import { Platform } from '@angular/cdk/platform';
14
14
  import * as i2 from '@bravobit/bb-foundation';
15
- import { Files, clamp, hsvToHex, hexToHsv, formatFileSize, Exif, FileLoader, parseDate } from '@bravobit/bb-foundation';
15
+ import { Files, clamp, hsvToHex, hexToHsv, formatFileSize, Exif, FileLoader, parseDate, isValidFileType, isValidFileSize, isFileLike } from '@bravobit/bb-foundation';
16
16
  import { Overlay } from '@angular/cdk/overlay';
17
17
  import { ComponentPortal } from '@angular/cdk/portal';
18
18
  import * as i3 from '@angular/platform-browser';
@@ -1768,7 +1768,7 @@ class BbMultiFileControl {
1768
1768
  validate(control) {
1769
1769
  const value = control?.value ?? [];
1770
1770
  const errors = value.reduce((previous, current, index) => {
1771
- if (this.isValidFileType(current)) {
1771
+ if (isValidFileType(current, this.accept)) {
1772
1772
  return previous;
1773
1773
  }
1774
1774
  return { ...previous, [index]: true };
@@ -1777,7 +1777,7 @@ class BbMultiFileControl {
1777
1777
  return { invalidFiles: errors };
1778
1778
  }
1779
1779
  for (const file of value) {
1780
- if (!this.isValidFileSize(file)) {
1780
+ if (!isValidFileSize(file, this.maxFileSize)) {
1781
1781
  return { maxFileSize: { maxSize: formatFileSize(this.maxFileSize) } };
1782
1782
  }
1783
1783
  }
@@ -1785,7 +1785,7 @@ class BbMultiFileControl {
1785
1785
  if (totalSize > this.maxTotalFileSize) {
1786
1786
  return {
1787
1787
  maxTotalFileSize: {
1788
- max: formatFileSize(this.maxFileSize),
1788
+ max: formatFileSize(this.maxTotalFileSize),
1789
1789
  current: formatFileSize(totalSize)
1790
1790
  }
1791
1791
  };
@@ -1798,36 +1798,13 @@ class BbMultiFileControl {
1798
1798
  }
1799
1799
  for (let index = 0; index < files?.length; index++) {
1800
1800
  const file = files?.[index] ?? null;
1801
- if (!this.isFileLike(file)) {
1801
+ if (!isFileLike(file)) {
1802
1802
  continue;
1803
1803
  }
1804
1804
  this.value.push(file);
1805
1805
  }
1806
1806
  this.onChangeCallback?.(this.value);
1807
1807
  }
1808
- isValidFileSize(file) {
1809
- if (!this.isFileLike(file)) {
1810
- return false;
1811
- }
1812
- return file?.size <= this.maxFileSize;
1813
- }
1814
- isValidFileType(file) {
1815
- if (!this.isFileLike(file)) {
1816
- return false;
1817
- }
1818
- if (this.accept === null || this.accept === undefined) {
1819
- return true;
1820
- }
1821
- const regexString = this.accept
1822
- .replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&')
1823
- .replace(/,/g, '|');
1824
- const mimeTypeRegex = new RegExp(regexString);
1825
- return mimeTypeRegex.test(file?.type);
1826
- }
1827
- isFileLike(input) {
1828
- return 'File' in window && input instanceof File
1829
- || 'Blob' in window && input instanceof Blob;
1830
- }
1831
1808
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.6", ngImport: i0, type: BbMultiFileControl, deps: [], target: i0.ɵɵFactoryTarget.Component });
1832
1809
  static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.1.6", type: BbMultiFileControl, isStandalone: true, selector: "bb-multi-file-control", inputs: { label: "label", hint: "hint", accept: "accept", maxFileSize: ["maxFileSize", "maxFileSize", numberAttribute], maxTotalFileSize: ["maxTotalFileSize", "maxTotalFileSize", numberAttribute], grouped: ["grouped", "grouped", booleanAttribute], required: ["required", "required", booleanAttribute], disabled: ["disabled", "disabled", booleanAttribute], hideErrors: ["hideErrors", "hideErrors", booleanAttribute], items: "items" }, outputs: { delete: "delete" }, host: { properties: { "class.required": "required", "class.disabled": "disabled", "class.grouped": "grouped", "class.error": "error" }, classAttribute: "bb-multi-file-control" }, providers: [
1833
1810
  { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => BbMultiFileControl), multi: true },
@@ -1956,10 +1933,10 @@ class BbFilePicker {
1956
1933
  if (value === null || value === undefined) {
1957
1934
  return null;
1958
1935
  }
1959
- if (!this.isValidFileType(value)) {
1936
+ if (!isValidFileType(value, this.accept)) {
1960
1937
  return { invalidFileType: true };
1961
1938
  }
1962
- if (!this.isValidFileSize(value)) {
1939
+ if (!isValidFileSize(value, this.maxFileSize)) {
1963
1940
  return { maxFileSize: { maxSize: formatFileSize(this.maxFileSize) } };
1964
1941
  }
1965
1942
  return null;
@@ -1979,29 +1956,6 @@ class BbFilePicker {
1979
1956
  }
1980
1957
  return Array.from(element.files);
1981
1958
  }
1982
- isValidFileType(file) {
1983
- if (!this.isFileLike(file)) {
1984
- return false;
1985
- }
1986
- if (this.accept === null || this.accept === undefined) {
1987
- return true;
1988
- }
1989
- const regexString = this.accept
1990
- .replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&')
1991
- .replace(/,/g, '|');
1992
- const mimeTypeRegex = new RegExp(regexString);
1993
- return mimeTypeRegex.test(file?.type);
1994
- }
1995
- isValidFileSize(file) {
1996
- if (!this.isFileLike(file)) {
1997
- return false;
1998
- }
1999
- return file?.size <= this.maxFileSize;
2000
- }
2001
- isFileLike(input) {
2002
- return 'File' in window && input instanceof File
2003
- || 'Blob' in window && input instanceof Blob;
2004
- }
2005
1959
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.6", ngImport: i0, type: BbFilePicker, deps: [], target: i0.ɵɵFactoryTarget.Component });
2006
1960
  static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.1.6", type: BbFilePicker, isStandalone: true, selector: "bb-file-picker", inputs: { label: "label", hint: "hint", accept: "accept", maxFileSize: ["maxFileSize", "maxFileSize", numberAttribute], showImages: ["showImages", "showImages", booleanAttribute], grouped: ["grouped", "grouped", booleanAttribute], required: ["required", "required", booleanAttribute], disabled: ["disabled", "disabled", booleanAttribute], hideErrors: ["hideErrors", "hideErrors", booleanAttribute], value: "value" }, outputs: { valueChange: "valueChange" }, host: { properties: { "class.required": "required", "class.disabled": "disabled", "class.grouped": "grouped", "class.error": "error" }, classAttribute: "bb-file-picker" }, providers: [
2007
1961
  {