@klippa/ngx-enhancy-forms 7.2.0 → 7.4.0
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/bundles/klippa-ngx-enhancy-forms.umd.js +289 -158
- package/bundles/klippa-ngx-enhancy-forms.umd.js.map +1 -1
- package/bundles/klippa-ngx-enhancy-forms.umd.min.js +2 -2
- package/bundles/klippa-ngx-enhancy-forms.umd.min.js.map +1 -1
- package/esm2015/klippa-ngx-enhancy-forms.js +1 -2
- package/esm2015/lib/elements/date-time-picker/date-time-picker.component.js +5 -4
- package/esm2015/lib/elements/file-input/file-input.component.js +3 -2
- package/esm2015/lib/elements/sortable-grouped-items/sortable-grouped-items.component.js +49 -0
- package/esm2015/lib/elements/value-accessor-base/value-accessor-base.component.js +33 -4
- package/esm2015/lib/ngx-enhancy-forms.module.js +4 -1
- package/esm2015/lib/util/arrays.js +45 -0
- package/esm2015/lib/util/values.js +1 -10
- package/esm2015/public-api.js +3 -1
- package/fesm2015/klippa-ngx-enhancy-forms.js +124 -15
- package/fesm2015/klippa-ngx-enhancy-forms.js.map +1 -1
- package/klippa-ngx-enhancy-forms.d.ts +0 -1
- package/klippa-ngx-enhancy-forms.metadata.json +1 -1
- package/lib/elements/sortable-grouped-items/sortable-grouped-items.component.d.ts +7 -0
- package/lib/elements/value-accessor-base/value-accessor-base.component.d.ts +4 -1
- package/lib/util/arrays.d.ts +6 -0
- package/lib/util/values.d.ts +0 -2
- package/package.json +1 -1
- package/public-api.d.ts +2 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Directive, Input, Component, SkipSelf, Optional, InjectionToken, Host, Inject, ViewChild, EventEmitter, Output, HostBinding, ContentChild, TemplateRef, ChangeDetectorRef, NgModule } from '@angular/core';
|
|
2
2
|
import { CommonModule } from '@angular/common';
|
|
3
3
|
import { FormArray, FormGroup, FormControl, ControlContainer, NG_VALUE_ACCESSOR, FormsModule } from '@angular/forms';
|
|
4
|
-
import { isString } from 'lodash';
|
|
4
|
+
import { isString, isArray } from 'lodash';
|
|
5
5
|
import { SortablejsModule } from 'ngx-sortablejs';
|
|
6
6
|
import { NgSelectModule } from '@ng-select/ng-select';
|
|
7
7
|
import { parse, format, isSameDay, startOfMonth, endOfMonth } from 'date-fns';
|
|
@@ -23,12 +23,6 @@ function numberIsSet(value) {
|
|
|
23
23
|
function isValueSet(value) {
|
|
24
24
|
return value !== null && value !== undefined;
|
|
25
25
|
}
|
|
26
|
-
function removeDuplicatesFromArray(array) {
|
|
27
|
-
return array.filter((c, i) => {
|
|
28
|
-
const firstOccurrenceIndex = array.findIndex((c2) => c2 === c);
|
|
29
|
-
return i === firstOccurrenceIndex;
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
26
|
function stringOrArrayIsSetAndEmpty(value) {
|
|
33
27
|
return value !== null && value !== undefined && value.length === 0;
|
|
34
28
|
}
|
|
@@ -38,9 +32,6 @@ function truncateString(s, length) {
|
|
|
38
32
|
}
|
|
39
33
|
return s.substring(0, length) + '...';
|
|
40
34
|
}
|
|
41
|
-
function arrayIsSetAndFilled(arr) {
|
|
42
|
-
return Array.isArray(arr) && arr !== null && arr !== undefined && arr.length > 0;
|
|
43
|
-
}
|
|
44
35
|
|
|
45
36
|
const invalidFieldsSymbol = Symbol('Not all fields are valid');
|
|
46
37
|
class SubFormDirective {
|
|
@@ -321,6 +312,49 @@ FormElementComponent.propDecorators = {
|
|
|
321
312
|
internalComponentRef: [{ type: ViewChild, args: ['internalComponentRef',] }]
|
|
322
313
|
};
|
|
323
314
|
|
|
315
|
+
function removeDuplicatesFromArraysWithComparator(comparator, ...arrays) {
|
|
316
|
+
let combined = [];
|
|
317
|
+
for (const array of arrays) {
|
|
318
|
+
combined = combined.concat(array);
|
|
319
|
+
}
|
|
320
|
+
return combined.filter((c, i) => {
|
|
321
|
+
const firstOccurrenceIndex = combined.findIndex((c2) => comparator(c, c2));
|
|
322
|
+
return i === firstOccurrenceIndex;
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
function removeDuplicatesFromArray(array) {
|
|
326
|
+
return array.filter((c, i) => {
|
|
327
|
+
const firstOccurrenceIndex = array.findIndex((c2) => c2 === c);
|
|
328
|
+
return i === firstOccurrenceIndex;
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
function insertAtIndex(arr, index, item) {
|
|
332
|
+
arr.splice(index, 0, item);
|
|
333
|
+
}
|
|
334
|
+
function arrayIsSetAndFilled(arr) {
|
|
335
|
+
return isArray(arr) && arr !== null && arr !== undefined && arr.length > 0;
|
|
336
|
+
}
|
|
337
|
+
function asArray(value) {
|
|
338
|
+
if (isValueSet(value)) {
|
|
339
|
+
if (Array.isArray(value)) {
|
|
340
|
+
return value;
|
|
341
|
+
}
|
|
342
|
+
return [value];
|
|
343
|
+
}
|
|
344
|
+
return [];
|
|
345
|
+
}
|
|
346
|
+
function splitArrayByCondition(value, condition) {
|
|
347
|
+
return value.reduce((acc, cur) => {
|
|
348
|
+
if (condition(cur)) {
|
|
349
|
+
acc.push([]);
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
acc[acc.length - 1].push(cur);
|
|
353
|
+
}
|
|
354
|
+
return acc;
|
|
355
|
+
}, [[]]);
|
|
356
|
+
}
|
|
357
|
+
|
|
324
358
|
/**
|
|
325
359
|
* This component is a base in order to create a component that supports ngModel.
|
|
326
360
|
* Some important things to know about it:
|
|
@@ -336,6 +370,7 @@ class ValueAccessorBase {
|
|
|
336
370
|
this.controlContainer = controlContainer;
|
|
337
371
|
this.changed = new Array();
|
|
338
372
|
this.touched = new Array();
|
|
373
|
+
this.prevValue = null;
|
|
339
374
|
this.disabled = false;
|
|
340
375
|
// we support both providing just the formControlName and the full formControl
|
|
341
376
|
this.formControlName = null;
|
|
@@ -385,6 +420,7 @@ class ValueAccessorBase {
|
|
|
385
420
|
}
|
|
386
421
|
writeValue(value) {
|
|
387
422
|
this.innerValue = value;
|
|
423
|
+
this.prevValue = value;
|
|
388
424
|
}
|
|
389
425
|
registerOnChange(fn) {
|
|
390
426
|
this.changed.push(fn);
|
|
@@ -393,8 +429,33 @@ class ValueAccessorBase {
|
|
|
393
429
|
this.touched.push(fn);
|
|
394
430
|
}
|
|
395
431
|
setInnerValueAndNotify(value) {
|
|
396
|
-
|
|
397
|
-
|
|
432
|
+
const actuallySetValue = (valueToSet) => {
|
|
433
|
+
this.innerValue = valueToSet;
|
|
434
|
+
this.prevValue = valueToSet;
|
|
435
|
+
this.changed.forEach((fn) => fn(valueToSet));
|
|
436
|
+
};
|
|
437
|
+
if (isValueSet(this.innerValueChangeInterceptor)) {
|
|
438
|
+
this.latestInnerValueChangedInterceptorPromise = this.innerValueChangeInterceptor();
|
|
439
|
+
const myPromise = this.latestInnerValueChangedInterceptorPromise;
|
|
440
|
+
this.latestInnerValueChangedInterceptorPromise.then(() => {
|
|
441
|
+
if (this.latestInnerValueChangedInterceptorPromise === myPromise) {
|
|
442
|
+
actuallySetValue(value);
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
// ignore outdated promises
|
|
446
|
+
}
|
|
447
|
+
}).catch(() => {
|
|
448
|
+
if (this.latestInnerValueChangedInterceptorPromise === myPromise) {
|
|
449
|
+
actuallySetValue(this.prevValue);
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
// ignore outdated promises
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
else {
|
|
457
|
+
actuallySetValue(value);
|
|
458
|
+
}
|
|
398
459
|
}
|
|
399
460
|
resetToNull() {
|
|
400
461
|
this.setInnerValueAndNotify(null);
|
|
@@ -418,6 +479,7 @@ ValueAccessorBase.ctorParameters = () => [
|
|
|
418
479
|
];
|
|
419
480
|
ValueAccessorBase.propDecorators = {
|
|
420
481
|
disabled: [{ type: Input }],
|
|
482
|
+
innerValueChangeInterceptor: [{ type: Input }],
|
|
421
483
|
formControlName: [{ type: Input }],
|
|
422
484
|
formControl: [{ type: Input }],
|
|
423
485
|
onTouch: [{ type: Output }]
|
|
@@ -1096,8 +1158,8 @@ class DateTimePickerComponent extends MultipleValueAccessorBase {
|
|
|
1096
1158
|
if (this.multiple) {
|
|
1097
1159
|
this.datePickerRef.close = () => {
|
|
1098
1160
|
};
|
|
1099
|
-
if (this.selectedDates.some((e) => e
|
|
1100
|
-
this.selectedDates = this.selectedDates.filter((e) => e
|
|
1161
|
+
if (this.selectedDates.some((e) => isSameDay(e, date))) {
|
|
1162
|
+
this.selectedDates = this.selectedDates.filter((e) => !isSameDay(e, date));
|
|
1101
1163
|
}
|
|
1102
1164
|
else {
|
|
1103
1165
|
this.selectedDates = [...this.selectedDates, date];
|
|
@@ -1380,6 +1442,51 @@ FileInputComponent.propDecorators = {
|
|
|
1380
1442
|
clearable: [{ type: Input }]
|
|
1381
1443
|
};
|
|
1382
1444
|
|
|
1445
|
+
class SortableGroupedItemsComponent extends ValueAccessorBase {
|
|
1446
|
+
constructor() {
|
|
1447
|
+
super(...arguments);
|
|
1448
|
+
this.reloader = true; // sortable items doesnt correctly update, so we have this boolean that flips to rerender the sortable items comp
|
|
1449
|
+
}
|
|
1450
|
+
writeValue(value) {
|
|
1451
|
+
super.writeValue(value);
|
|
1452
|
+
this.reloader = false;
|
|
1453
|
+
setTimeout(() => {
|
|
1454
|
+
if (arrayIsSetAndFilled(value)) {
|
|
1455
|
+
this.items = value.flatMap(e => [...e, '']);
|
|
1456
|
+
}
|
|
1457
|
+
else {
|
|
1458
|
+
this.items = [];
|
|
1459
|
+
}
|
|
1460
|
+
this.reloader = true;
|
|
1461
|
+
});
|
|
1462
|
+
}
|
|
1463
|
+
onItemsRearranged(value) {
|
|
1464
|
+
const result = splitArrayByCondition(value, e => e === '').filter(arrayIsSetAndFilled);
|
|
1465
|
+
this.setInnerValueAndNotify(result);
|
|
1466
|
+
this.reloader = false;
|
|
1467
|
+
setTimeout(() => {
|
|
1468
|
+
this.items = [...this.items, ''].filter((e, i) => {
|
|
1469
|
+
if (i === 0 && e === '') {
|
|
1470
|
+
return false;
|
|
1471
|
+
}
|
|
1472
|
+
if (e === '' && this.items[i - 1] === '') {
|
|
1473
|
+
return false;
|
|
1474
|
+
}
|
|
1475
|
+
return true;
|
|
1476
|
+
});
|
|
1477
|
+
this.reloader = true;
|
|
1478
|
+
});
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
SortableGroupedItemsComponent.decorators = [
|
|
1482
|
+
{ type: Component, args: [{
|
|
1483
|
+
selector: 'klp-form-sortable-grouped-items',
|
|
1484
|
+
template: "<ng-container *ngIf=\"reloader\">\n\t<klp-form-sortable-items\n\t\t[(ngModel)]=\"items\"\n\t\t(ngModelChange)=\"onItemsRearranged($event)\"\n\t>\n\t\t<ng-template let-item=\"item\">\n\t\t\t<div>{{item}}</div>\n\t\t</ng-template>\n\t</klp-form-sortable-items>\n</ng-container>\n",
|
|
1485
|
+
providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: SortableGroupedItemsComponent, multi: true }],
|
|
1486
|
+
styles: [":host{display:block}"]
|
|
1487
|
+
},] }
|
|
1488
|
+
];
|
|
1489
|
+
|
|
1383
1490
|
class NgxEnhancyFormsModule {
|
|
1384
1491
|
}
|
|
1385
1492
|
NgxEnhancyFormsModule.decorators = [
|
|
@@ -1405,6 +1512,7 @@ NgxEnhancyFormsModule.decorators = [
|
|
|
1405
1512
|
SelectComponent,
|
|
1406
1513
|
SelectFooterComponent,
|
|
1407
1514
|
SortableItemsComponent,
|
|
1515
|
+
SortableGroupedItemsComponent,
|
|
1408
1516
|
TextInputComponent,
|
|
1409
1517
|
ToggleComponent,
|
|
1410
1518
|
FileInputComponent,
|
|
@@ -1429,6 +1537,7 @@ NgxEnhancyFormsModule.decorators = [
|
|
|
1429
1537
|
SelectComponent,
|
|
1430
1538
|
SelectFooterComponent,
|
|
1431
1539
|
SortableItemsComponent,
|
|
1540
|
+
SortableGroupedItemsComponent,
|
|
1432
1541
|
TextInputComponent,
|
|
1433
1542
|
ToggleComponent,
|
|
1434
1543
|
FileInputComponent,
|
|
@@ -1450,5 +1559,5 @@ NgxEnhancyFormsModule.decorators = [
|
|
|
1450
1559
|
* Generated bundle index. Do not edit.
|
|
1451
1560
|
*/
|
|
1452
1561
|
|
|
1453
|
-
export { ButtonComponent, CheckboxComponent, DATE_PICKER_LOCALE, DATE_PICKER_TRANSLATIONS, DATE_TIME_PICKER_TRANSLATIONS, DEFAULT_ERROR_MESSAGES, DatePickerComponent, DateTimePickerComponent, EmailInputComponent, FORM_ERROR_MESSAGES, FormCaptionComponent, FormComponent, FormElementComponent, FormErrorComponent, FormSubmitButtonComponent, KLP_DATE_FORMATS, LoadingIndicatorComponent, MultipleValueAccessorBase, NgxEnhancyFormsModule, NumberInputComponent, PasswordFieldComponent, SELECT_TRANSLATIONS, SelectComponent, SelectFooterComponent, SortableItemsComponent, SubFormDirective, TextInputComponent, ToggleComponent, ValueAccessorBase, dateValidator, invalidDateKey, invalidFieldsSymbol, matDateFormatsFactory, MaterialModule as ɵa
|
|
1562
|
+
export { ButtonComponent, CheckboxComponent, DATE_PICKER_LOCALE, DATE_PICKER_TRANSLATIONS, DATE_TIME_PICKER_TRANSLATIONS, DEFAULT_ERROR_MESSAGES, DatePickerComponent, DateTimePickerComponent, EmailInputComponent, FORM_ERROR_MESSAGES, FileInputComponent, FormCaptionComponent, FormComponent, FormElementComponent, FormErrorComponent, FormSubmitButtonComponent, KLP_DATE_FORMATS, LoadingIndicatorComponent, MultipleValueAccessorBase, NgxEnhancyFormsModule, NumberInputComponent, PasswordFieldComponent, SELECT_TRANSLATIONS, SelectComponent, SelectFooterComponent, SortableGroupedItemsComponent, SortableItemsComponent, SubFormDirective, TextInputComponent, ToggleComponent, ValueAccessorBase, dateValidator, invalidDateKey, invalidFieldsSymbol, matDateFormatsFactory, MaterialModule as ɵa };
|
|
1454
1563
|
//# sourceMappingURL=klippa-ngx-enhancy-forms.js.map
|