@klippa/ngx-enhancy-forms 7.3.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 +286 -184
- 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/lib/elements/date-time-picker/date-time-picker.component.js +3 -2
- 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 +3 -2
- 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 +2 -1
- package/fesm2015/klippa-ngx-enhancy-forms.js +92 -11
- package/fesm2015/klippa-ngx-enhancy-forms.js.map +1 -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/util/arrays.d.ts +6 -0
- package/lib/util/values.d.ts +0 -2
- package/package.json +1 -1
- package/public-api.d.ts +1 -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:
|
|
@@ -1408,6 +1442,51 @@ FileInputComponent.propDecorators = {
|
|
|
1408
1442
|
clearable: [{ type: Input }]
|
|
1409
1443
|
};
|
|
1410
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
|
+
|
|
1411
1490
|
class NgxEnhancyFormsModule {
|
|
1412
1491
|
}
|
|
1413
1492
|
NgxEnhancyFormsModule.decorators = [
|
|
@@ -1433,6 +1512,7 @@ NgxEnhancyFormsModule.decorators = [
|
|
|
1433
1512
|
SelectComponent,
|
|
1434
1513
|
SelectFooterComponent,
|
|
1435
1514
|
SortableItemsComponent,
|
|
1515
|
+
SortableGroupedItemsComponent,
|
|
1436
1516
|
TextInputComponent,
|
|
1437
1517
|
ToggleComponent,
|
|
1438
1518
|
FileInputComponent,
|
|
@@ -1457,6 +1537,7 @@ NgxEnhancyFormsModule.decorators = [
|
|
|
1457
1537
|
SelectComponent,
|
|
1458
1538
|
SelectFooterComponent,
|
|
1459
1539
|
SortableItemsComponent,
|
|
1540
|
+
SortableGroupedItemsComponent,
|
|
1460
1541
|
TextInputComponent,
|
|
1461
1542
|
ToggleComponent,
|
|
1462
1543
|
FileInputComponent,
|
|
@@ -1478,5 +1559,5 @@ NgxEnhancyFormsModule.decorators = [
|
|
|
1478
1559
|
* Generated bundle index. Do not edit.
|
|
1479
1560
|
*/
|
|
1480
1561
|
|
|
1481
|
-
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, 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 };
|
|
1482
1563
|
//# sourceMappingURL=klippa-ngx-enhancy-forms.js.map
|