ngx-render-material-forms 2.5.17 → 2.5.19
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.
- package/esm2022/lib/components/date/date.component.mjs +65 -47
- package/esm2022/lib/components/number/number.component.mjs +50 -1
- package/fesm2022/ngx-render-material-forms.js +113 -46
- package/fesm2022/ngx-render-material-forms.mjs.map +1 -1
- package/lib/components/date/date.component.d.ts +3 -0
- package/lib/components/number/number.component.d.ts +7 -0
- package/package.json +5 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { Injectable, Component, Input, ViewChild, ViewContainerRef, ViewChildren, EventEmitter, Output, forwardRef, Directive, Inject, NgModule } from '@angular/core';
|
|
2
|
+
import { Injectable, Component, Input, ViewChild, ViewContainerRef, ViewChildren, EventEmitter, Output, forwardRef, Directive, ElementRef, Inject, NgModule } from '@angular/core';
|
|
3
3
|
import * as i1$2 from '@angular/common/http';
|
|
4
4
|
import { HttpHeaders, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
|
|
5
5
|
import * as i1 from '@angular/common';
|
|
@@ -57,7 +57,7 @@ import NumberComponent from 'formiojs/components/number/Number.js';
|
|
|
57
57
|
import _, { get as get$1 } from 'lodash';
|
|
58
58
|
import CurrencyComponent from 'formiojs/components/currency/Currency.js';
|
|
59
59
|
import DayComponent from 'formiojs/components/day/Day.js';
|
|
60
|
-
import { momentDate } from 'formiojs/utils/utils.js';
|
|
60
|
+
import { momentDate, convertFormatToMoment } from 'formiojs/utils/utils.js';
|
|
61
61
|
import HiddenComponent from 'formiojs/components/hidden/Hidden.js';
|
|
62
62
|
import HtmlComponent from 'formiojs/components/html/HTML.js';
|
|
63
63
|
import { ENTER, COMMA } from '@angular/cdk/keycodes';
|
|
@@ -606,6 +606,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImpo
|
|
|
606
606
|
}] });
|
|
607
607
|
PhoneNumberComponent.MaterialComponent = MaterialPhoneNumberComponent;
|
|
608
608
|
|
|
609
|
+
// `beforeinput` types that add content to the field (typing, paste, drag & drop, autocomplete).
|
|
610
|
+
const INSERTING_INPUT_TYPES = [
|
|
611
|
+
'insertText',
|
|
612
|
+
'insertReplacementText',
|
|
613
|
+
'insertFromPaste',
|
|
614
|
+
'insertFromDrop',
|
|
615
|
+
'insertFromYank',
|
|
616
|
+
'insertCompositionText'
|
|
617
|
+
];
|
|
609
618
|
class MaterialNumberComponent extends MaterialTextfieldComponent {
|
|
610
619
|
constructor(element, ref, renderer) {
|
|
611
620
|
super(element, ref);
|
|
@@ -618,6 +627,9 @@ class MaterialNumberComponent extends MaterialTextfieldComponent {
|
|
|
618
627
|
super.ngAfterViewInit();
|
|
619
628
|
if (this.instance) {
|
|
620
629
|
const { instance } = this;
|
|
630
|
+
this.renderer.listen(this.input.nativeElement, 'beforeinput', (event) => {
|
|
631
|
+
this.blockNonNumericInput(event);
|
|
632
|
+
});
|
|
621
633
|
this.renderer.listen(this.input.nativeElement, 'blur', () => {
|
|
622
634
|
let value = instance.parseValue(this.control.value);
|
|
623
635
|
value = instance.formatValue(value);
|
|
@@ -626,6 +638,43 @@ class MaterialNumberComponent extends MaterialTextfieldComponent {
|
|
|
626
638
|
});
|
|
627
639
|
}
|
|
628
640
|
}
|
|
641
|
+
/**
|
|
642
|
+
* The input is rendered as type="text" so that the formio number/currency masks (delimiters,
|
|
643
|
+
* decimal separator, currency affixes) can be displayed. Typing, pasting or dropping characters
|
|
644
|
+
* that are not part of that numeric format is rejected before it reaches the control.
|
|
645
|
+
*/
|
|
646
|
+
blockNonNumericInput(event) {
|
|
647
|
+
if (!event || !event.cancelable || !INSERTING_INPUT_TYPES.includes(event.inputType)) {
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
const data = event.data !== undefined && event.data !== null
|
|
651
|
+
? event.data
|
|
652
|
+
: (event.dataTransfer ? event.dataTransfer.getData('text') : '');
|
|
653
|
+
if (!data || this.isAllowedNumericInput(data)) {
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
event.preventDefault();
|
|
657
|
+
}
|
|
658
|
+
isAllowedNumericInput(data) {
|
|
659
|
+
const instance = this.instance;
|
|
660
|
+
const allowed = new Set('0123456789'.split(''));
|
|
661
|
+
if (_.get(instance.component, 'allowNegative', true)) {
|
|
662
|
+
allowed.add('-');
|
|
663
|
+
}
|
|
664
|
+
if (!_.isFunction(instance.isDecimalAllowed) || instance.isDecimalAllowed()) {
|
|
665
|
+
allowed.add(instance.decimalSeparator || '.');
|
|
666
|
+
}
|
|
667
|
+
if (instance.delimiter) {
|
|
668
|
+
allowed.add(instance.delimiter);
|
|
669
|
+
}
|
|
670
|
+
// Currency renders its prefix/suffix (for example `$`) inside the input value.
|
|
671
|
+
[instance.currencyPrefix, instance.currencySuffix].forEach((affix) => {
|
|
672
|
+
if (_.isString(affix)) {
|
|
673
|
+
affix.split('').forEach((char) => allowed.add(char));
|
|
674
|
+
}
|
|
675
|
+
});
|
|
676
|
+
return data.split('').every((char) => allowed.has(char));
|
|
677
|
+
}
|
|
629
678
|
getValue() {
|
|
630
679
|
let value = this.control.value;
|
|
631
680
|
if (value && this.instance) {
|
|
@@ -1744,7 +1793,9 @@ class MaterialDateComponent extends MaterialComponent {
|
|
|
1744
1793
|
return this.instance && this.instance.component.enableTime === true;
|
|
1745
1794
|
}
|
|
1746
1795
|
setDisplayControlValue(value = null) {
|
|
1747
|
-
const format =
|
|
1796
|
+
const format = this.instance.component.format
|
|
1797
|
+
? convertFormatToMoment(this.instance.component.format)
|
|
1798
|
+
: `YYYY-MM-DD${this.enableTime ? 'THH:mm' : ''}`;
|
|
1748
1799
|
value = value || this.getDateTimeValue();
|
|
1749
1800
|
if (value) {
|
|
1750
1801
|
this.displayControl.setValue(momentDate(value).format(format));
|
|
@@ -1757,12 +1808,18 @@ class MaterialDateComponent extends MaterialComponent {
|
|
|
1757
1808
|
this.selectedDate = momentDate(event).utc().format();
|
|
1758
1809
|
this.control.setValue(this.selectedDate);
|
|
1759
1810
|
this.setDateTime();
|
|
1811
|
+
if (!this.enableTime) {
|
|
1812
|
+
this.isPickerOpened = false;
|
|
1813
|
+
}
|
|
1760
1814
|
}
|
|
1761
1815
|
onChangeTime(time) {
|
|
1762
1816
|
this.selectedTime = time;
|
|
1763
1817
|
if (this.selectedDate || (this.enableTime && !this.enableDate)) {
|
|
1764
1818
|
this.setDateTime();
|
|
1765
1819
|
}
|
|
1820
|
+
if ((this.enableDate && this.selectedDate) || (this.enableTime && !this.enableDate)) {
|
|
1821
|
+
this.isPickerOpened = false;
|
|
1822
|
+
}
|
|
1766
1823
|
}
|
|
1767
1824
|
onChangeInput() {
|
|
1768
1825
|
const value = this.dateFilter(this.displayControl.value) &&
|
|
@@ -1773,6 +1830,7 @@ class MaterialDateComponent extends MaterialComponent {
|
|
|
1773
1830
|
getDateTimeValue() {
|
|
1774
1831
|
let newDate = '';
|
|
1775
1832
|
let isSelectedTime = false;
|
|
1833
|
+
console.log(this.calendar);
|
|
1776
1834
|
if (this.calendar && this.calendar.selectedTime) {
|
|
1777
1835
|
const { selectedTime } = this.calendar;
|
|
1778
1836
|
isSelectedTime = true;
|
|
@@ -1881,20 +1939,19 @@ class MaterialDateComponent extends MaterialComponent {
|
|
|
1881
1939
|
return !formattedDates.includes(momentDate(d).format('YYYY-MM-DD'));
|
|
1882
1940
|
}
|
|
1883
1941
|
clickOutside(event) {
|
|
1884
|
-
if (this.isPickerOpened
|
|
1885
|
-
|
|
1942
|
+
if (!this.isPickerOpened) {
|
|
1943
|
+
return;
|
|
1886
1944
|
}
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1945
|
+
const target = event.target;
|
|
1946
|
+
const clickedInsideCalendar = this.calendarElRef && this.calendarElRef.nativeElement.contains(target);
|
|
1947
|
+
const clickedToggle = this.toggleElRef && this.toggleElRef.nativeElement.contains(target);
|
|
1948
|
+
// Any interaction within the calendar (day/month/year navigation, time picker, etc.)
|
|
1949
|
+
// must not close the picker. Closing on an actual selection is handled in
|
|
1950
|
+
// onChangeDate/onChangeTime once the value is complete.
|
|
1951
|
+
if (clickedInsideCalendar || clickedToggle) {
|
|
1952
|
+
return;
|
|
1894
1953
|
}
|
|
1895
|
-
|
|
1896
|
-
// this.toggleCalendar(event);
|
|
1897
|
-
// }
|
|
1954
|
+
this.isPickerOpened = false;
|
|
1898
1955
|
}
|
|
1899
1956
|
improveMinMaxDate(minDate, maxDate) {
|
|
1900
1957
|
if (minDate && minDate.length === 4) {
|
|
@@ -1906,7 +1963,7 @@ class MaterialDateComponent extends MaterialComponent {
|
|
|
1906
1963
|
return { minDate, maxDate };
|
|
1907
1964
|
}
|
|
1908
1965
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: MaterialDateComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
|
|
1909
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.14", type: MaterialDateComponent, selector: "mat-formio-date", host: { listeners: { "document:click": "clickOutside($event)" } }, viewQueries: [{ propertyName: "calendar", first: true, predicate: ["calendar"], descendants: true }], usesInheritance: true, ngImport: i0, template: `
|
|
1966
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.14", type: MaterialDateComponent, selector: "mat-formio-date", host: { listeners: { "document:click": "clickOutside($event)" } }, viewQueries: [{ propertyName: "calendar", first: true, predicate: ["calendar"], descendants: true }, { propertyName: "calendarElRef", first: true, predicate: ["calendar"], descendants: true, read: ElementRef }, { propertyName: "toggleElRef", first: true, predicate: ["toggleBtn"], descendants: true, read: ElementRef }], usesInheritance: true, ngImport: i0, template: `
|
|
1910
1967
|
<mat-formio-form-field [instance]="instance" [componentTemplate]="componentTemplate"></mat-formio-form-field>
|
|
1911
1968
|
<ng-template #componentTemplate let-hasLabel>
|
|
1912
1969
|
<mat-label *ngIf="hasLabel" fxFill>
|
|
@@ -1914,7 +1971,7 @@ class MaterialDateComponent extends MaterialComponent {
|
|
|
1914
1971
|
</mat-label>
|
|
1915
1972
|
|
|
1916
1973
|
<form class="example-form">
|
|
1917
|
-
<mat-datepicker-toggle [disabled]="isDisabled()" (click)="toggleCalendar($event)">
|
|
1974
|
+
<mat-datepicker-toggle #toggleBtn [disabled]="isDisabled()" (click)="toggleCalendar($event)">
|
|
1918
1975
|
<mat-icon matDatepickerToggleIcon *ngIf="enableTime && !enableDate">schedule</mat-icon>
|
|
1919
1976
|
</mat-datepicker-toggle>
|
|
1920
1977
|
<mat-form-field class="example-full-width">
|
|
@@ -1946,20 +2003,22 @@ class MaterialDateComponent extends MaterialComponent {
|
|
|
1946
2003
|
>
|
|
1947
2004
|
</mat-form-field>
|
|
1948
2005
|
|
|
1949
|
-
<
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
2006
|
+
<div (click)="$event.stopPropagation()">
|
|
2007
|
+
<mat-formio-calendar
|
|
2008
|
+
#calendar
|
|
2009
|
+
[minDate]="instance.component.datePicker.minDate || ''"
|
|
2010
|
+
[maxDate]="instance.component.datePicker.maxDate || ''"
|
|
2011
|
+
[dateFilter]="dateFilter"
|
|
2012
|
+
[hidden]="!isPickerOpened"
|
|
2013
|
+
(dateSelectEvent)="onChangeDate($event)"
|
|
2014
|
+
(timeSelectEvent)="onChangeTime($event)"
|
|
2015
|
+
[enableDate]="enableDate"
|
|
2016
|
+
[enableTime]="enableTime"
|
|
2017
|
+
[hourStep]="instance.component.timePicker.hourStep"
|
|
2018
|
+
[minuteStep]="instance.component.timePicker.minuteStep"
|
|
2019
|
+
[instance]="instance"
|
|
2020
|
+
></mat-formio-calendar>
|
|
2021
|
+
</div>
|
|
1963
2022
|
<mat-error *ngIf="instance.error">{{ instance.error.message }}</mat-error>
|
|
1964
2023
|
</form>
|
|
1965
2024
|
</ng-template>
|
|
@@ -1980,7 +2039,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImpo
|
|
|
1980
2039
|
</mat-label>
|
|
1981
2040
|
|
|
1982
2041
|
<form class="example-form">
|
|
1983
|
-
<mat-datepicker-toggle [disabled]="isDisabled()" (click)="toggleCalendar($event)">
|
|
2042
|
+
<mat-datepicker-toggle #toggleBtn [disabled]="isDisabled()" (click)="toggleCalendar($event)">
|
|
1984
2043
|
<mat-icon matDatepickerToggleIcon *ngIf="enableTime && !enableDate">schedule</mat-icon>
|
|
1985
2044
|
</mat-datepicker-toggle>
|
|
1986
2045
|
<mat-form-field class="example-full-width">
|
|
@@ -2012,20 +2071,22 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImpo
|
|
|
2012
2071
|
>
|
|
2013
2072
|
</mat-form-field>
|
|
2014
2073
|
|
|
2015
|
-
<
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2074
|
+
<div (click)="$event.stopPropagation()">
|
|
2075
|
+
<mat-formio-calendar
|
|
2076
|
+
#calendar
|
|
2077
|
+
[minDate]="instance.component.datePicker.minDate || ''"
|
|
2078
|
+
[maxDate]="instance.component.datePicker.maxDate || ''"
|
|
2079
|
+
[dateFilter]="dateFilter"
|
|
2080
|
+
[hidden]="!isPickerOpened"
|
|
2081
|
+
(dateSelectEvent)="onChangeDate($event)"
|
|
2082
|
+
(timeSelectEvent)="onChangeTime($event)"
|
|
2083
|
+
[enableDate]="enableDate"
|
|
2084
|
+
[enableTime]="enableTime"
|
|
2085
|
+
[hourStep]="instance.component.timePicker.hourStep"
|
|
2086
|
+
[minuteStep]="instance.component.timePicker.minuteStep"
|
|
2087
|
+
[instance]="instance"
|
|
2088
|
+
></mat-formio-calendar>
|
|
2089
|
+
</div>
|
|
2029
2090
|
<mat-error *ngIf="instance.error">{{ instance.error.message }}</mat-error>
|
|
2030
2091
|
</form>
|
|
2031
2092
|
</ng-template>
|
|
@@ -2034,6 +2095,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImpo
|
|
|
2034
2095
|
}], propDecorators: { calendar: [{
|
|
2035
2096
|
type: ViewChild,
|
|
2036
2097
|
args: ['calendar']
|
|
2098
|
+
}], calendarElRef: [{
|
|
2099
|
+
type: ViewChild,
|
|
2100
|
+
args: ['calendar', { read: ElementRef }]
|
|
2101
|
+
}], toggleElRef: [{
|
|
2102
|
+
type: ViewChild,
|
|
2103
|
+
args: ['toggleBtn', { read: ElementRef }]
|
|
2037
2104
|
}] } });
|
|
2038
2105
|
DateTimeComponent.MaterialComponent = MaterialDateComponent;
|
|
2039
2106
|
|