@stemy/ngx-utils 19.1.0 → 19.1.3

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.
@@ -4,7 +4,7 @@ import 'reflect-metadata';
4
4
  import * as i2 from '@angular/router';
5
5
  import { ActivatedRouteSnapshot, Scroll, NavigationEnd, DefaultUrlSerializer, UrlTree, UrlSegmentGroup, UrlSegment, UrlSerializer } from '@angular/router';
6
6
  import { BehaviorSubject, Observable, firstValueFrom, Subject, Subscription, from, TimeoutError, combineLatest } from 'rxjs';
7
- import { skipWhile, debounceTime, distinctUntilChanged, map, filter, first, mergeMap, timeout } from 'rxjs/operators';
7
+ import { skipWhile, debounceTime, distinctUntilChanged, map, filter, mergeMap, timeout } from 'rxjs/operators';
8
8
  import * as i1$3 from '@angular/common';
9
9
  import { isPlatformBrowser, isPlatformServer, DOCUMENT, APP_BASE_HREF, CommonModule } from '@angular/common';
10
10
  import * as i1 from 'ngx-device-detector';
@@ -1507,11 +1507,12 @@ class DateUtils {
1507
1507
  }
1508
1508
 
1509
1509
  class FileUtils {
1510
+ static { this.base64 = /^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$/g; }
1510
1511
  static getExtension(file) {
1511
- return file ? file.name.substr(file.name.lastIndexOf(".")).toLowerCase() : null;
1512
+ return file ? file.name.substring(file.name.lastIndexOf(".")).toLowerCase() : null;
1512
1513
  }
1513
1514
  static getName(file) {
1514
- return file ? file.name.substr(0, file.name.lastIndexOf(".")) : null;
1515
+ return file ? file.name.substring(0, file.name.lastIndexOf(".")) : null;
1515
1516
  }
1516
1517
  static toFile(blob, fileName) {
1517
1518
  const data = blob;
@@ -1556,31 +1557,37 @@ class FileUtils {
1556
1557
  // @dynamic
1557
1558
  reader => reader.readAsDataURL(file));
1558
1559
  }
1559
- static readDataFromUrl(http, url) {
1560
- return new Promise(
1561
- // @dynamic
1562
- (resolve, reject) => {
1563
- if (!url) {
1564
- reject({
1565
- message: "The url is not specified"
1566
- });
1567
- return;
1568
- }
1569
- if ((/^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$/g).test(url)) {
1570
- resolve(url);
1571
- return;
1572
- }
1573
- first()(http.get(url, {
1574
- responseType: "blob"
1575
- })).subscribe((blob) => {
1576
- FileUtils.readFileAsDataURL(blob).then(resolve, reject);
1577
- }, reason => {
1578
- if (reason.status > 0)
1579
- reject(reason);
1580
- else
1581
- resolve(url);
1582
- });
1583
- });
1560
+ static base64ToBlob(base64, mimeType = "application/octet-stream") {
1561
+ // Decode the Base64 string into a binary string
1562
+ const byteCharacters = atob(base64);
1563
+ // Convert the binary string into an array of bytes
1564
+ const byteNumbers = Array.from(byteCharacters, char => char.charCodeAt(0));
1565
+ const byteArray = new Uint8Array(byteNumbers);
1566
+ // Create a Blob with the byte array and the specified MIME type
1567
+ return new Blob([byteArray], { type: mimeType });
1568
+ }
1569
+ static async readBlobFromUrl(http, url) {
1570
+ if (!url) {
1571
+ throw new Error(`The URL is not specified for readBlobFromUrl`);
1572
+ }
1573
+ if (url.match(FileUtils.base64)) {
1574
+ return FileUtils.base64ToBlob(url);
1575
+ }
1576
+ return firstValueFrom(http.get(url, {
1577
+ responseType: "blob"
1578
+ }));
1579
+ }
1580
+ static async readDataFromUrl(http, url) {
1581
+ if (!url) {
1582
+ throw new Error(`The URL is not specified for readBlobFromUrl`);
1583
+ }
1584
+ if (url.match(FileUtils.base64)) {
1585
+ return url;
1586
+ }
1587
+ const blob = await firstValueFrom(http.get(url, {
1588
+ responseType: "blob"
1589
+ }));
1590
+ return FileUtils.readFileAsDataURL(blob);
1584
1591
  }
1585
1592
  static readFile(callback) {
1586
1593
  return new Promise(
@@ -5379,9 +5386,12 @@ class DropListComponent {
5379
5386
  this.idField = "id";
5380
5387
  this.labelField = "label";
5381
5388
  this.value = [];
5389
+ this.context = [];
5390
+ this.prepareItem = () => { };
5391
+ this.checkFn = () => false;
5382
5392
  this.valueMap = {};
5383
- this.remove = id => {
5384
- this.changeValue(this.value.filter(t => t !== id));
5393
+ this.remove = index => {
5394
+ this.changeValue(this.value.filter((_, i) => i !== index));
5385
5395
  };
5386
5396
  }
5387
5397
  onDragEnter(ev, elem, data) {
@@ -5421,6 +5431,8 @@ class DropListComponent {
5421
5431
  this.valueMap = this.context?.reduce((res, item) => {
5422
5432
  // In case this is a dynamic form option which stores real value under props
5423
5433
  item = Object.assign({}, item, item.props || {});
5434
+ // Prepare item
5435
+ this.prepareItem(item);
5424
5436
  const id = item[this.idField] || item.id;
5425
5437
  res[id] = item;
5426
5438
  return res;
@@ -5448,11 +5460,11 @@ class DropListComponent {
5448
5460
  this.onTouched?.();
5449
5461
  }
5450
5462
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: DropListComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); }
5451
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.0.3", type: DropListComponent, isStandalone: false, selector: "drop-list", inputs: { disabled: "disabled", unique: "unique", idField: "idField", labelField: "labelField", value: "value", context: "context", checkFn: "checkFn" }, providers: [{
5463
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.0.3", type: DropListComponent, isStandalone: false, selector: "drop-list", inputs: { disabled: "disabled", unique: "unique", idField: "idField", labelField: "labelField", value: "value", context: "context", prepareItem: "prepareItem", checkFn: "checkFn" }, providers: [{
5452
5464
  provide: NG_VALUE_ACCESSOR,
5453
5465
  useExisting: forwardRef(() => DropListComponent),
5454
5466
  multi: true,
5455
- }], queries: [{ propertyName: "itemTemplate", first: true, predicate: ["itemTemplate"], descendants: true }], usesOnChanges: true, ngImport: i0, template: "<ng-template #defaultTemplate let-item=\"item\">\n <div class=\"drop-list-item-label\">\n {{ item | getValue:labelField }}\n </div>\n</ng-template>\n<div class=\"drop-list\"\n #list\n (dragenter)=\"onDragEnter($event, list, this)\"\n (dragleave)=\"onDragLeave($event, list)\"\n (drop)=\"onDrop($event, list)\">\n <ng-container *ngFor=\"let id of value\">\n <div class=\"drop-list-item\">\n <ng-template #noItemTemplate>\n <div class=\"drop-list-item-label just-id\">\n {{ id }}\n </div>\n </ng-template>\n <ng-container [ngTemplateOutlet]=\"itemTemplate || defaultTemplate\"\n [ngTemplateOutletContext]=\"{item: valueMap[id], id: id, remove: remove}\"\n *ngIf=\"valueMap[id]; else noItemTemplate\"></ng-container>\n <div class=\"drop-list-item-delete\" (click)=\"remove(id)\">x</div>\n </div>\n </ng-container>\n</div>\n", styles: [".drop-list{min-height:100px;border:2px #bfbfbf dashed;border-radius:10px;padding:10px;display:flex;align-items:flex-start;justify-content:left;gap:10px;background-color:#0000000d;transition:.2s;flex-wrap:wrap}.drop-list.drop-allowed{background-color:#00000080;border-color:#a9a9a9}.drop-list .drop-list-item{position:relative;background:#0003;padding:7px 23px 7px 10px;border-radius:5px;-webkit-user-select:none;user-select:none}.drop-list .drop-list-item-label:not(.just-id){min-width:50px;text-align:center}.drop-list .drop-list-item-label.just-id{max-width:100px;overflow:hidden;text-overflow:ellipsis;color:gray}.drop-list .drop-list-item-delete{font-size:14px;line-height:14px;text-align:center;cursor:pointer;background:#fff;border-radius:2px;height:14px;width:15px;position:absolute;top:4px;right:4px}\n"], dependencies: [{ kind: "directive", type: i1$3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1$3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1$3.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "pipe", type: GetValuePipe, name: "getValue" }], encapsulation: i0.ViewEncapsulation.None }); }
5467
+ }], queries: [{ propertyName: "itemTemplate", first: true, predicate: ["itemTemplate"], descendants: true }], usesOnChanges: true, ngImport: i0, template: "<ng-template #defaultTemplate let-item=\"item\">\n <div class=\"drop-list-item-label\">\n {{ item | getValue:labelField }}\n </div>\n</ng-template>\n<div class=\"drop-list\"\n #list\n (dragenter)=\"onDragEnter($event, list, this)\"\n (dragleave)=\"onDragLeave($event, list)\"\n (drop)=\"onDrop($event, list)\">\n <ng-container *ngFor=\"let id of value; let ix = index\">\n <div class=\"drop-list-item\">\n <ng-template #noItemTemplate>\n <div class=\"drop-list-item-label just-id\">\n {{ id }}\n </div>\n </ng-template>\n <ng-container [ngTemplateOutlet]=\"itemTemplate || defaultTemplate\"\n [ngTemplateOutletContext]=\"{item: valueMap[id], id: id, remove: remove}\"\n *ngIf=\"valueMap[id]; else noItemTemplate\"></ng-container>\n <div class=\"drop-list-item-delete\" (click)=\"remove(ix)\">x</div>\n </div>\n </ng-container>\n</div>\n", styles: [".drop-list{min-height:100px;border:2px #bfbfbf dashed;border-radius:10px;padding:10px;display:flex;align-items:flex-start;justify-content:left;gap:10px;background-color:#0000000d;transition:.2s;flex-wrap:wrap}.drop-list.drop-allowed{background-color:#00000080;border-color:#a9a9a9}.drop-list .drop-list-item{position:relative;background:#0003;padding:7px 23px 7px 10px;border-radius:5px;-webkit-user-select:none;user-select:none}.drop-list .drop-list-item-label:not(.just-id){min-width:50px;text-align:center}.drop-list .drop-list-item-label.just-id{max-width:100px;overflow:hidden;text-overflow:ellipsis;color:gray}.drop-list .drop-list-item-delete{font-size:14px;line-height:14px;text-align:center;cursor:pointer;background:#fff;border-radius:2px;height:14px;width:15px;position:absolute;top:4px;right:4px}\n"], dependencies: [{ kind: "directive", type: i1$3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1$3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1$3.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "pipe", type: GetValuePipe, name: "getValue" }], encapsulation: i0.ViewEncapsulation.None }); }
5456
5468
  }
5457
5469
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: DropListComponent, decorators: [{
5458
5470
  type: Component,
@@ -5460,7 +5472,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImpor
5460
5472
  provide: NG_VALUE_ACCESSOR,
5461
5473
  useExisting: forwardRef(() => DropListComponent),
5462
5474
  multi: true,
5463
- }], template: "<ng-template #defaultTemplate let-item=\"item\">\n <div class=\"drop-list-item-label\">\n {{ item | getValue:labelField }}\n </div>\n</ng-template>\n<div class=\"drop-list\"\n #list\n (dragenter)=\"onDragEnter($event, list, this)\"\n (dragleave)=\"onDragLeave($event, list)\"\n (drop)=\"onDrop($event, list)\">\n <ng-container *ngFor=\"let id of value\">\n <div class=\"drop-list-item\">\n <ng-template #noItemTemplate>\n <div class=\"drop-list-item-label just-id\">\n {{ id }}\n </div>\n </ng-template>\n <ng-container [ngTemplateOutlet]=\"itemTemplate || defaultTemplate\"\n [ngTemplateOutletContext]=\"{item: valueMap[id], id: id, remove: remove}\"\n *ngIf=\"valueMap[id]; else noItemTemplate\"></ng-container>\n <div class=\"drop-list-item-delete\" (click)=\"remove(id)\">x</div>\n </div>\n </ng-container>\n</div>\n", styles: [".drop-list{min-height:100px;border:2px #bfbfbf dashed;border-radius:10px;padding:10px;display:flex;align-items:flex-start;justify-content:left;gap:10px;background-color:#0000000d;transition:.2s;flex-wrap:wrap}.drop-list.drop-allowed{background-color:#00000080;border-color:#a9a9a9}.drop-list .drop-list-item{position:relative;background:#0003;padding:7px 23px 7px 10px;border-radius:5px;-webkit-user-select:none;user-select:none}.drop-list .drop-list-item-label:not(.just-id){min-width:50px;text-align:center}.drop-list .drop-list-item-label.just-id{max-width:100px;overflow:hidden;text-overflow:ellipsis;color:gray}.drop-list .drop-list-item-delete{font-size:14px;line-height:14px;text-align:center;cursor:pointer;background:#fff;border-radius:2px;height:14px;width:15px;position:absolute;top:4px;right:4px}\n"] }]
5475
+ }], template: "<ng-template #defaultTemplate let-item=\"item\">\n <div class=\"drop-list-item-label\">\n {{ item | getValue:labelField }}\n </div>\n</ng-template>\n<div class=\"drop-list\"\n #list\n (dragenter)=\"onDragEnter($event, list, this)\"\n (dragleave)=\"onDragLeave($event, list)\"\n (drop)=\"onDrop($event, list)\">\n <ng-container *ngFor=\"let id of value; let ix = index\">\n <div class=\"drop-list-item\">\n <ng-template #noItemTemplate>\n <div class=\"drop-list-item-label just-id\">\n {{ id }}\n </div>\n </ng-template>\n <ng-container [ngTemplateOutlet]=\"itemTemplate || defaultTemplate\"\n [ngTemplateOutletContext]=\"{item: valueMap[id], id: id, remove: remove}\"\n *ngIf=\"valueMap[id]; else noItemTemplate\"></ng-container>\n <div class=\"drop-list-item-delete\" (click)=\"remove(ix)\">x</div>\n </div>\n </ng-container>\n</div>\n", styles: [".drop-list{min-height:100px;border:2px #bfbfbf dashed;border-radius:10px;padding:10px;display:flex;align-items:flex-start;justify-content:left;gap:10px;background-color:#0000000d;transition:.2s;flex-wrap:wrap}.drop-list.drop-allowed{background-color:#00000080;border-color:#a9a9a9}.drop-list .drop-list-item{position:relative;background:#0003;padding:7px 23px 7px 10px;border-radius:5px;-webkit-user-select:none;user-select:none}.drop-list .drop-list-item-label:not(.just-id){min-width:50px;text-align:center}.drop-list .drop-list-item-label.just-id{max-width:100px;overflow:hidden;text-overflow:ellipsis;color:gray}.drop-list .drop-list-item-delete{font-size:14px;line-height:14px;text-align:center;cursor:pointer;background:#fff;border-radius:2px;height:14px;width:15px;position:absolute;top:4px;right:4px}\n"] }]
5464
5476
  }], ctorParameters: () => [{ type: i0.ChangeDetectorRef }], propDecorators: { disabled: [{
5465
5477
  type: Input
5466
5478
  }], unique: [{
@@ -5473,6 +5485,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImpor
5473
5485
  type: Input
5474
5486
  }], context: [{
5475
5487
  type: Input
5488
+ }], prepareItem: [{
5489
+ type: Input
5476
5490
  }], checkFn: [{
5477
5491
  type: Input
5478
5492
  }], itemTemplate: [{