@dereekb/dbx-form 9.16.2 → 9.16.4

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.
@@ -26,7 +26,7 @@ import * as i1$2 from '@angular/material/button';
26
26
  import { MatButtonModule } from '@angular/material/button';
27
27
  import * as i3$3 from '@angular/flex-layout/flex';
28
28
  import { FlexLayoutModule } from '@angular/flex-layout';
29
- import { objectIsEmpty, mergeObjectsFunction, filterFromPOJOFunction, mergeObjects, filterFromPOJO, asArray, objectHasNoKeys, addPlusPrefixToNumber, convertMaybeToArray, makeValuesGroupMap, findUnique, searchStringFilterFunction, caseInsensitiveFilterByIndexOfDecisionFactory, mergeIntoArray, lastValue, separateValues, arrayToMap, getValueFromGetter, filterMaybeValues, dateFromLogicalDate, WEBSITE_DOMAIN_NAME_REGEX, KeyValueTypleValueFilter, valuesFromPOJO, allObjectsAreEqual, isNumberDivisibleBy, nearestDivisibleValues, transformNumberFunction, concatArrays, transformStringFunction, US_STATE_CODE_STRING_REGEX, ZIP_CODE_STRING_REGEX, LAT_LNG_PATTERN, capitalizeFirstLetter, BooleanStringKeyArrayUtilityInstance } from '@dereekb/util';
29
+ import { objectIsEmpty, mergeObjectsFunction, filterFromPOJOFunction, mergeObjects, filterFromPOJO, asArray, objectHasNoKeys, addPlusPrefixToNumber, convertMaybeToArray, makeValuesGroupMap, findUnique, searchStringFilterFunction, caseInsensitiveFilterByIndexOfDecisionFactory, mergeIntoArray, lastValue, separateValues, arrayToMap, cachedGetter, makeGetter, asDecisionFunction, getValueFromGetter, filterMaybeValues, dateFromLogicalDate, WEBSITE_DOMAIN_NAME_REGEX, KeyValueTypleValueFilter, valuesFromPOJO, allObjectsAreEqual, isNumberDivisibleBy, nearestDivisibleValues, transformNumberFunction, concatArrays, transformStringFunction, US_STATE_CODE_STRING_REGEX, ZIP_CODE_STRING_REGEX, LAT_LNG_PATTERN, capitalizeFirstLetter, BooleanStringKeyArrayUtilityInstance } from '@dereekb/util';
30
30
  import * as i2$1 from '@angular/material/slide-toggle';
31
31
  import { MatSlideToggleModule } from '@angular/material/slide-toggle';
32
32
  import * as i2$2 from '@angular/flex-layout/extended';
@@ -2686,12 +2686,30 @@ function textEditorField(config) {
2686
2686
  }
2687
2687
 
2688
2688
  class DbxFormRepeatArrayTypeComponent extends FieldArrayType {
2689
+ constructor() {
2690
+ super(...arguments);
2691
+ this._labelForField = cachedGetter(() => {
2692
+ const input = this.repeatArrayField.labelForField;
2693
+ if (typeof input === 'function') {
2694
+ return input;
2695
+ }
2696
+ else {
2697
+ return makeGetter(input ?? '');
2698
+ }
2699
+ });
2700
+ this._allowRemove = cachedGetter(() => {
2701
+ return asDecisionFunction(this.field.props.allowRemove, true);
2702
+ });
2703
+ }
2689
2704
  get repeatArrayField() {
2690
2705
  return this.field.props;
2691
2706
  }
2692
2707
  get label() {
2693
2708
  return this.field.props.label ?? this.field.key;
2694
2709
  }
2710
+ get description() {
2711
+ return this.field.props.description;
2712
+ }
2695
2713
  get addText() {
2696
2714
  return this.repeatArrayField.addText ?? 'Add';
2697
2715
  }
@@ -2704,7 +2722,24 @@ class DbxFormRepeatArrayTypeComponent extends FieldArrayType {
2704
2722
  get count() {
2705
2723
  return this.field.fieldGroup?.length ?? 0;
2706
2724
  }
2707
- get canAdd() {
2725
+ get disableRearrange() {
2726
+ return Boolean(this.field.props.disableRearrange);
2727
+ }
2728
+ get allowAdd() {
2729
+ return this.field.props.allowAdd ?? true;
2730
+ }
2731
+ allowRemove(i) {
2732
+ const array = this.model;
2733
+ const value = array[i];
2734
+ return this._allowRemove()({
2735
+ i,
2736
+ value
2737
+ });
2738
+ }
2739
+ get addItemDisabled() {
2740
+ return !this.canAddItem;
2741
+ }
2742
+ get canAddItem() {
2708
2743
  const max = this.max;
2709
2744
  if (max == null) {
2710
2745
  return true;
@@ -2740,64 +2775,70 @@ class DbxFormRepeatArrayTypeComponent extends FieldArrayType {
2740
2775
  drop(event) {
2741
2776
  this.swapIndexes(event.previousIndex, event.currentIndex);
2742
2777
  }
2743
- labelForItem(field) {
2744
- return getValueFromGetter(this.repeatArrayField.labelForField ?? '', field);
2778
+ labelForItem(fieldConfig, i) {
2779
+ const array = this.model;
2780
+ const value = array[i];
2781
+ return getValueFromGetter(this._labelForField(), {
2782
+ i,
2783
+ value,
2784
+ fieldConfig
2785
+ });
2745
2786
  }
2746
2787
  }
2747
2788
  DbxFormRepeatArrayTypeComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.2", ngImport: i0, type: DbxFormRepeatArrayTypeComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
2748
2789
  DbxFormRepeatArrayTypeComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.1.2", type: DbxFormRepeatArrayTypeComponent, selector: "ng-component", usesInheritance: true, ngImport: i0, template: `
2749
2790
  <div class="dbx-form-repeat-array">
2750
- <dbx-subsection [header]="label">
2791
+ <dbx-subsection [header]="label" [hint]="description">
2751
2792
  <!-- Fields -->
2752
- <div class="dbx-form-repeat-array-fields" cdkDropList (cdkDropListDropped)="drop($event)">
2793
+ <div class="dbx-form-repeat-array-fields" cdkDropList [cdkDropListDisabled]="disableRearrange" (cdkDropListDropped)="drop($event)">
2753
2794
  <div class="dbx-form-repeat-array-field" cdkDrag cdkDragLockAxis="y" *ngFor="let field of field.fieldGroup; let i = index; let last = last">
2754
- <div class="example-custom-placeholder" *cdkDragPlaceholder></div>
2755
- <dbx-bar>
2756
- <button cdkDragHandle mat-flat-button><mat-icon>drag_handle</mat-icon></button>
2795
+ <div class="dbx-form-repeat-array-drag-placeholder" *cdkDragPlaceholder></div>
2796
+ <dbx-bar class="dbx-bar-fixed-height">
2797
+ <button *ngIf="!disableRearrange" cdkDragHandle mat-flat-button><mat-icon>drag_handle</mat-icon></button>
2757
2798
  <dbx-button-spacer></dbx-button-spacer>
2758
2799
  <h4>
2759
2800
  <span class="repeat-array-number">{{ i + 1 }}</span>
2760
- <span>{{ labelForItem(field) }}</span>
2801
+ <span>{{ labelForItem(field, i) }}</span>
2761
2802
  </h4>
2762
2803
  <span class="dbx-spacer"></span>
2763
- <button mat-flat-button color="warn" (click)="remove(i)">{{ removeText }}</button>
2804
+ <dbx-button *ngIf="allowRemove(i)" color="warn" [text]="removeText" (buttonClick)="remove(i)"></dbx-button>
2764
2805
  </dbx-bar>
2765
2806
  <formly-field class="dbx-form-repeat-array-field-content" [field]="field"></formly-field>
2766
2807
  </div>
2767
2808
  </div>
2768
2809
  <!-- Add Button -->
2769
2810
  <div class="dbx-form-repeat-array-footer">
2770
- <button *ngIf="canAdd" mat-raised-button (click)="add()">{{ addText }}</button>
2811
+ <dbx-button *ngIf="allowAdd" [raised]="true" [disabled]="addItemDisabled" [text]="addText" (buttonClick)="add()"></dbx-button>
2771
2812
  </div>
2772
2813
  </dbx-subsection>
2773
2814
  </div>
2774
- `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i1$2.MatButton, selector: "button[mat-button], button[mat-raised-button], button[mat-icon-button], button[mat-fab], button[mat-mini-fab], button[mat-stroked-button], button[mat-flat-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }, { kind: "component", type: i5.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "directive", type: i4$5.CdkDropList, selector: "[cdkDropList], cdk-drop-list", inputs: ["cdkDropListConnectedTo", "cdkDropListData", "cdkDropListOrientation", "id", "cdkDropListLockAxis", "cdkDropListDisabled", "cdkDropListSortingDisabled", "cdkDropListEnterPredicate", "cdkDropListSortPredicate", "cdkDropListAutoScrollDisabled", "cdkDropListAutoScrollStep"], outputs: ["cdkDropListDropped", "cdkDropListEntered", "cdkDropListExited", "cdkDropListSorted"], exportAs: ["cdkDropList"] }, { kind: "directive", type: i4$5.CdkDrag, selector: "[cdkDrag]", inputs: ["cdkDragData", "cdkDragLockAxis", "cdkDragRootElement", "cdkDragBoundary", "cdkDragStartDelay", "cdkDragFreeDragPosition", "cdkDragDisabled", "cdkDragConstrainPosition", "cdkDragPreviewClass", "cdkDragPreviewContainer"], outputs: ["cdkDragStarted", "cdkDragReleased", "cdkDragEnded", "cdkDragEntered", "cdkDragExited", "cdkDragDropped", "cdkDragMoved"], exportAs: ["cdkDrag"] }, { kind: "directive", type: i4$5.CdkDragHandle, selector: "[cdkDragHandle]", inputs: ["cdkDragHandleDisabled"] }, { kind: "directive", type: i4$5.CdkDragPlaceholder, selector: "ng-template[cdkDragPlaceholder]", inputs: ["data"] }, { kind: "component", type: i1$1.DbxSubSectionComponent, selector: "dbx-subsection" }, { kind: "directive", type: i1$1.DbxBarDirective, selector: "dbx-bar,[dbxBar]", inputs: ["color"] }, { kind: "directive", type: i1$1.DbxButtonSpacerDirective, selector: "dbx-button-spacer,[dbxButtonSpacer]" }, { kind: "component", type: i1$3.FormlyField, selector: "formly-field", inputs: ["field"] }] });
2815
+ `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i1$2.MatButton, selector: "button[mat-button], button[mat-raised-button], button[mat-icon-button], button[mat-fab], button[mat-mini-fab], button[mat-stroked-button], button[mat-flat-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }, { kind: "component", type: i5.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "directive", type: i4$5.CdkDropList, selector: "[cdkDropList], cdk-drop-list", inputs: ["cdkDropListConnectedTo", "cdkDropListData", "cdkDropListOrientation", "id", "cdkDropListLockAxis", "cdkDropListDisabled", "cdkDropListSortingDisabled", "cdkDropListEnterPredicate", "cdkDropListSortPredicate", "cdkDropListAutoScrollDisabled", "cdkDropListAutoScrollStep"], outputs: ["cdkDropListDropped", "cdkDropListEntered", "cdkDropListExited", "cdkDropListSorted"], exportAs: ["cdkDropList"] }, { kind: "directive", type: i4$5.CdkDrag, selector: "[cdkDrag]", inputs: ["cdkDragData", "cdkDragLockAxis", "cdkDragRootElement", "cdkDragBoundary", "cdkDragStartDelay", "cdkDragFreeDragPosition", "cdkDragDisabled", "cdkDragConstrainPosition", "cdkDragPreviewClass", "cdkDragPreviewContainer"], outputs: ["cdkDragStarted", "cdkDragReleased", "cdkDragEnded", "cdkDragEntered", "cdkDragExited", "cdkDragDropped", "cdkDragMoved"], exportAs: ["cdkDrag"] }, { kind: "directive", type: i4$5.CdkDragHandle, selector: "[cdkDragHandle]", inputs: ["cdkDragHandleDisabled"] }, { kind: "directive", type: i4$5.CdkDragPlaceholder, selector: "ng-template[cdkDragPlaceholder]", inputs: ["data"] }, { kind: "component", type: i1$1.DbxSubSectionComponent, selector: "dbx-subsection" }, { kind: "directive", type: i1$1.DbxBarDirective, selector: "dbx-bar,[dbxBar]", inputs: ["color"] }, { kind: "component", type: i1$1.DbxButtonComponent, selector: "dbx-button", inputs: ["type", "raised", "stroked", "flat", "color", "customButtonColor", "customTextColor", "customSpinnerColor"] }, { kind: "directive", type: i1$1.DbxButtonSpacerDirective, selector: "dbx-button-spacer,[dbxButtonSpacer]" }, { kind: "component", type: i1$3.FormlyField, selector: "formly-field", inputs: ["field"] }] });
2775
2816
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.2", ngImport: i0, type: DbxFormRepeatArrayTypeComponent, decorators: [{
2776
2817
  type: Component,
2777
2818
  args: [{
2778
2819
  template: `
2779
2820
  <div class="dbx-form-repeat-array">
2780
- <dbx-subsection [header]="label">
2821
+ <dbx-subsection [header]="label" [hint]="description">
2781
2822
  <!-- Fields -->
2782
- <div class="dbx-form-repeat-array-fields" cdkDropList (cdkDropListDropped)="drop($event)">
2823
+ <div class="dbx-form-repeat-array-fields" cdkDropList [cdkDropListDisabled]="disableRearrange" (cdkDropListDropped)="drop($event)">
2783
2824
  <div class="dbx-form-repeat-array-field" cdkDrag cdkDragLockAxis="y" *ngFor="let field of field.fieldGroup; let i = index; let last = last">
2784
- <div class="example-custom-placeholder" *cdkDragPlaceholder></div>
2785
- <dbx-bar>
2786
- <button cdkDragHandle mat-flat-button><mat-icon>drag_handle</mat-icon></button>
2825
+ <div class="dbx-form-repeat-array-drag-placeholder" *cdkDragPlaceholder></div>
2826
+ <dbx-bar class="dbx-bar-fixed-height">
2827
+ <button *ngIf="!disableRearrange" cdkDragHandle mat-flat-button><mat-icon>drag_handle</mat-icon></button>
2787
2828
  <dbx-button-spacer></dbx-button-spacer>
2788
2829
  <h4>
2789
2830
  <span class="repeat-array-number">{{ i + 1 }}</span>
2790
- <span>{{ labelForItem(field) }}</span>
2831
+ <span>{{ labelForItem(field, i) }}</span>
2791
2832
  </h4>
2792
2833
  <span class="dbx-spacer"></span>
2793
- <button mat-flat-button color="warn" (click)="remove(i)">{{ removeText }}</button>
2834
+ <dbx-button *ngIf="allowRemove(i)" color="warn" [text]="removeText" (buttonClick)="remove(i)"></dbx-button>
2794
2835
  </dbx-bar>
2795
2836
  <formly-field class="dbx-form-repeat-array-field-content" [field]="field"></formly-field>
2796
2837
  </div>
2797
2838
  </div>
2798
2839
  <!-- Add Button -->
2799
2840
  <div class="dbx-form-repeat-array-footer">
2800
- <button *ngIf="canAdd" mat-raised-button (click)="add()">{{ addText }}</button>
2841
+ <dbx-button *ngIf="allowAdd" [raised]="true" [disabled]="addItemDisabled" [text]="addText" (buttonClick)="add()"></dbx-button>
2801
2842
  </div>
2802
2843
  </dbx-subsection>
2803
2844
  </div>
@@ -2855,15 +2896,20 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.2", ngImpor
2855
2896
  }] });
2856
2897
 
2857
2898
  function repeatArrayField(config) {
2858
- const { key, repeatFieldGroup, maxLength, addText, removeText, labelForField } = config;
2899
+ const { key, label, description, repeatFieldGroup, maxLength, addText, removeText, labelForField, disableRearrange, allowAdd, allowRemove } = config;
2859
2900
  return formlyField({
2860
2901
  key,
2861
2902
  type: 'repeatarray',
2862
2903
  ...propsAndConfigForFieldConfig(config, {
2904
+ label,
2905
+ description,
2863
2906
  maxLength,
2864
2907
  labelForField,
2865
2908
  addText,
2866
- removeText
2909
+ removeText,
2910
+ disableRearrange,
2911
+ allowAdd,
2912
+ allowRemove
2867
2913
  }),
2868
2914
  fieldArray: {
2869
2915
  fieldGroup: asArray(repeatFieldGroup)