@ng-simplicity/forms-core 1.0.0 → 1.1.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/README.md +354 -23
- package/fesm2022/ng-simplicity-forms-core.mjs +118 -41
- package/fesm2022/ng-simplicity-forms-core.mjs.map +1 -1
- package/index.d.ts +42 -15
- package/package.json +1 -1
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Subject, takeUntil, BehaviorSubject, map, filter, of } from 'rxjs';
|
|
1
|
+
import { Subject, takeUntil, BehaviorSubject, map, filter, merge, of } from 'rxjs';
|
|
2
2
|
import * as i0 from '@angular/core';
|
|
3
|
-
import { Directive, InjectionToken, inject, Injectable, Injector, ViewContainerRef, Input, ChangeDetectionStrategy, Component, Sanitizer, SecurityContext, NgModule } from '@angular/core';
|
|
3
|
+
import { Directive, InjectionToken, inject, Injectable, ChangeDetectorRef, Injector, ViewContainerRef, Input, ChangeDetectionStrategy, Component, ElementRef, Sanitizer, SecurityContext, NgModule } from '@angular/core';
|
|
4
4
|
import { v4 } from 'uuid';
|
|
5
5
|
import { toSignal } from '@angular/core/rxjs-interop';
|
|
6
6
|
import { UntypedFormGroup, FormControl, UntypedFormArray, FormsModule, ReactiveFormsModule } from '@angular/forms';
|
|
7
|
-
import { defaults } from 'lodash';
|
|
8
7
|
import { CommonModule } from '@angular/common';
|
|
9
8
|
|
|
10
9
|
class NgsSubscriber {
|
|
@@ -42,6 +41,20 @@ const NgsFormsFormControlAddRemoveFunctions = {
|
|
|
42
41
|
}),
|
|
43
42
|
};
|
|
44
43
|
|
|
44
|
+
function ngsDefaults(target, ...sources) {
|
|
45
|
+
const result = target ? { ...target } : {};
|
|
46
|
+
for (const source of sources) {
|
|
47
|
+
if (!source)
|
|
48
|
+
continue;
|
|
49
|
+
for (const key of Object.keys(source)) {
|
|
50
|
+
if (result[key] === undefined) {
|
|
51
|
+
result[key] = source[key];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
|
|
45
58
|
class NgsFormsBaseClassFormComponent extends NgsSubscriber {
|
|
46
59
|
static key;
|
|
47
60
|
id = v4();
|
|
@@ -164,7 +177,7 @@ class NgsFormsInternalService {
|
|
|
164
177
|
}
|
|
165
178
|
mergeState(key, update) {
|
|
166
179
|
const obj = this.state.value[key] || {};
|
|
167
|
-
const updated =
|
|
180
|
+
const updated = ngsDefaults(update, obj);
|
|
168
181
|
this.state.value[key] = updated;
|
|
169
182
|
this.state.next(this.state.value);
|
|
170
183
|
}
|
|
@@ -174,9 +187,14 @@ class NgsFormsInternalService {
|
|
|
174
187
|
updateComponentState(componentKey, state) {
|
|
175
188
|
this.mergeState(componentKey, state);
|
|
176
189
|
}
|
|
177
|
-
subscribeToState(
|
|
190
|
+
subscribeToState(uuid, name) {
|
|
178
191
|
let last = '';
|
|
179
|
-
return this.state.pipe(map((allState) =>
|
|
192
|
+
return this.state.pipe(map((allState) => {
|
|
193
|
+
const stateByUuid = allState[uuid] || {};
|
|
194
|
+
const stateByName = name ? (allState[name] || {}) : {};
|
|
195
|
+
const globalState = allState['global'] || {};
|
|
196
|
+
return ngsDefaults(stateByUuid, ngsDefaults(stateByName, globalState));
|
|
197
|
+
}), filter((currentState) => {
|
|
180
198
|
const stringifiedState = JSON.stringify(currentState);
|
|
181
199
|
const isUpdated = stringifiedState !== last;
|
|
182
200
|
last = stringifiedState;
|
|
@@ -195,13 +213,40 @@ class NgsFormsFormItemWithVisibleAndValidatorsBase extends NgsFormsBaseClassForm
|
|
|
195
213
|
errorMessage = '';
|
|
196
214
|
formAddRemoveFns = inject(NGS_FORMS_CONTROL_ADD_REMOVE_FN);
|
|
197
215
|
privateService = inject(NgsFormsInternalService);
|
|
216
|
+
changeDetectorRef = inject(ChangeDetectorRef);
|
|
198
217
|
submitted = toSignal(this.privateService.isSubmitted$, { initialValue: false });
|
|
199
218
|
ngOnInit() {
|
|
200
|
-
this.control
|
|
219
|
+
if (!this.control) {
|
|
220
|
+
this.control = new FormControl(undefined, { validators: [] });
|
|
221
|
+
}
|
|
201
222
|
//this.bindVisible();
|
|
202
223
|
this.bindValidators();
|
|
203
224
|
//this.bindControlValidityChange();
|
|
204
225
|
this.formAddRemoveFns.add(this.control, this.config.name);
|
|
226
|
+
// Listen to changes and update error message dynamically
|
|
227
|
+
this.subscribe(merge(this.control.valueChanges, this.control.statusChanges, this.privateService.isSubmitted$), () => {
|
|
228
|
+
this.updateErrorMessage();
|
|
229
|
+
this.changeDetectorRef.markForCheck();
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
updateErrorMessage() {
|
|
233
|
+
if (!this.control) {
|
|
234
|
+
this.errorMessage = '';
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const showErrors = this.control.invalid && (this.control.touched || this.control.dirty || this.submitted());
|
|
238
|
+
if (!showErrors) {
|
|
239
|
+
this.errorMessage = '';
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
const errors = this.control.errors;
|
|
243
|
+
if (!errors) {
|
|
244
|
+
this.errorMessage = '';
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const firstErrorKey = Object.keys(errors)[0];
|
|
248
|
+
const map = this.config.errorMessageMap;
|
|
249
|
+
this.errorMessage = map?.[firstErrorKey] || `Field is invalid: ${firstErrorKey}`;
|
|
205
250
|
}
|
|
206
251
|
ngOnDestroy() {
|
|
207
252
|
super.ngOnDestroy();
|
|
@@ -229,7 +274,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImpo
|
|
|
229
274
|
class NgsFormsBaseClassFormInputComponent extends NgsFormsFormItemWithVisibleAndValidatorsBase {
|
|
230
275
|
myFormService = inject(NgsFormsService);
|
|
231
276
|
internalService = inject(NgsFormsInternalService);
|
|
232
|
-
commonState = toSignal(this.internalService.subscribeToState(this.config.name), { initialValue: {} });
|
|
277
|
+
commonState = toSignal(this.internalService.subscribeToState(this.itemData.uuid || '', this.config.name), { initialValue: {} });
|
|
233
278
|
toggleDisplayMode(setTo) {
|
|
234
279
|
}
|
|
235
280
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: NgsFormsBaseClassFormInputComponent, deps: null, target: i0.ɵɵFactoryTarget.Directive });
|
|
@@ -264,16 +309,18 @@ class NgsFormItemController extends NgsSubscriber {
|
|
|
264
309
|
itemData;
|
|
265
310
|
addRemoveControlFn;
|
|
266
311
|
index;
|
|
312
|
+
changeDetectorRef;
|
|
267
313
|
componentRef;
|
|
268
314
|
parentVisibility = new BehaviorSubject(false);
|
|
269
315
|
lastVisible;
|
|
270
|
-
constructor(injector, viewContainerRef, itemData, addRemoveControlFn, index) {
|
|
316
|
+
constructor(injector, viewContainerRef, itemData, addRemoveControlFn, index, changeDetectorRef) {
|
|
271
317
|
super();
|
|
272
318
|
this.injector = injector;
|
|
273
319
|
this.viewContainerRef = viewContainerRef;
|
|
274
320
|
this.itemData = itemData;
|
|
275
321
|
this.addRemoveControlFn = addRemoveControlFn;
|
|
276
322
|
this.index = index;
|
|
323
|
+
this.changeDetectorRef = changeDetectorRef;
|
|
277
324
|
this.bindVisibility();
|
|
278
325
|
}
|
|
279
326
|
destroy() {
|
|
@@ -281,16 +328,16 @@ class NgsFormItemController extends NgsSubscriber {
|
|
|
281
328
|
super.ngOnDestroy();
|
|
282
329
|
}
|
|
283
330
|
bindVisibility() {
|
|
284
|
-
if (!this.itemData.visible$) {
|
|
285
|
-
this.create();
|
|
331
|
+
if (!this.itemData.config.visible$) {
|
|
332
|
+
Promise.resolve().then(() => this.create());
|
|
286
333
|
return;
|
|
287
334
|
}
|
|
288
|
-
this.subscribe(this.itemData.visible$, (visible) => {
|
|
335
|
+
this.subscribe(this.itemData.config.visible$, (visible) => {
|
|
289
336
|
if (this.lastVisible === visible)
|
|
290
337
|
return;
|
|
291
338
|
this.lastVisible = visible;
|
|
292
339
|
if (visible) {
|
|
293
|
-
this.create();
|
|
340
|
+
Promise.resolve().then(() => this.create());
|
|
294
341
|
return;
|
|
295
342
|
}
|
|
296
343
|
this.detach();
|
|
@@ -314,11 +361,14 @@ class NgsFormItemController extends NgsSubscriber {
|
|
|
314
361
|
return;
|
|
315
362
|
}
|
|
316
363
|
this.componentRef = this.viewContainerRef.createComponent(componentType, { injector: myInjector });
|
|
364
|
+
this.componentRef.changeDetectorRef?.detectChanges();
|
|
365
|
+
this.changeDetectorRef?.markForCheck();
|
|
317
366
|
this.parentVisibility.next(true);
|
|
318
367
|
}
|
|
319
368
|
detach() {
|
|
320
369
|
this.parentVisibility.next(false);
|
|
321
370
|
this.componentRef?.destroy();
|
|
371
|
+
this.changeDetectorRef?.markForCheck();
|
|
322
372
|
}
|
|
323
373
|
}
|
|
324
374
|
|
|
@@ -330,6 +380,7 @@ class NgsFormsFormItemDirective {
|
|
|
330
380
|
controller;
|
|
331
381
|
viewContainerRef = inject(ViewContainerRef);
|
|
332
382
|
injector = inject(Injector);
|
|
383
|
+
changeDetectorRef = inject(ChangeDetectorRef);
|
|
333
384
|
formComponentRegistryService = inject(NgsFormsComponentRegistryService);
|
|
334
385
|
ngOnInit() {
|
|
335
386
|
if (!this.itemData) {
|
|
@@ -342,7 +393,7 @@ class NgsFormsFormItemDirective {
|
|
|
342
393
|
if (this.formGroup) {
|
|
343
394
|
addRemoveFn = NgsFormsFormControlAddRemoveFunctions.formGroup(this.formGroup);
|
|
344
395
|
}
|
|
345
|
-
this.controller = new NgsFormItemController(this.injector, this.viewContainerRef, this.itemData, addRemoveFn, this.index);
|
|
396
|
+
this.controller = new NgsFormItemController(this.injector, this.viewContainerRef, this.itemData, addRemoveFn, this.index, this.changeDetectorRef);
|
|
346
397
|
}
|
|
347
398
|
ngOnDestroy() {
|
|
348
399
|
this.controller?.destroy();
|
|
@@ -390,7 +441,7 @@ class NgsFormsColumnComponent extends NgsFormsBaseClassItemsContainerBase {
|
|
|
390
441
|
static key = 'column';
|
|
391
442
|
static create(config) {
|
|
392
443
|
return {
|
|
393
|
-
uuid: v4(),
|
|
444
|
+
uuid: config.uuid || v4(),
|
|
394
445
|
type: NgsFormsColumnComponent.key,
|
|
395
446
|
config,
|
|
396
447
|
};
|
|
@@ -421,7 +472,7 @@ class NgsFormsRowComponent extends NgsFormsBaseClassFormComponent {
|
|
|
421
472
|
}
|
|
422
473
|
static create(config) {
|
|
423
474
|
return {
|
|
424
|
-
uuid: v4(),
|
|
475
|
+
uuid: config.uuid || v4(),
|
|
425
476
|
type: NgsFormsRowComponent.key,
|
|
426
477
|
config: config,
|
|
427
478
|
};
|
|
@@ -436,12 +487,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImpo
|
|
|
436
487
|
|
|
437
488
|
class NgsFormsFormGroupComponent extends NgsFormsFormItemWithVisibleAndValidatorsBase {
|
|
438
489
|
static key = 'form-group';
|
|
439
|
-
static create(config
|
|
490
|
+
static create(config) {
|
|
440
491
|
return {
|
|
441
|
-
uuid: v4(),
|
|
492
|
+
uuid: config.uuid || v4(),
|
|
442
493
|
type: NgsFormsFormGroupComponent.key,
|
|
443
494
|
config,
|
|
444
|
-
items,
|
|
445
495
|
};
|
|
446
496
|
}
|
|
447
497
|
get formGroupControl() {
|
|
@@ -452,19 +502,18 @@ class NgsFormsFormGroupComponent extends NgsFormsFormItemWithVisibleAndValidator
|
|
|
452
502
|
this.control = new UntypedFormGroup({});
|
|
453
503
|
}
|
|
454
504
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: NgsFormsFormGroupComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
455
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.19", type: NgsFormsFormGroupComponent, isStandalone: true, selector: "ngs-forms-form-group", usesInheritance: true, ngImport: i0, template: "@if (
|
|
505
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.19", type: NgsFormsFormGroupComponent, isStandalone: true, selector: "ngs-forms-form-group", usesInheritance: true, ngImport: i0, template: "@if (config.items) {\n @for (item of config.items; track item.uuid) {\n <ng-container [ngs-form-item]=\"item\" [ngs-form-group]=\"formGroupControl\"></ng-container>\n }\n}\n", dependencies: [{ kind: "directive", type: NgsFormsFormItemDirective, selector: "[ngs-form-item]", inputs: ["ngs-form-item", "ngs-form-group", "ngs-form-array", "ngs-form-index"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
456
506
|
}
|
|
457
507
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: NgsFormsFormGroupComponent, decorators: [{
|
|
458
508
|
type: Component,
|
|
459
|
-
args: [{ selector: 'ngs-forms-form-group', imports: [NgsFormsFormItemDirective], changeDetection: ChangeDetectionStrategy.OnPush, template: "@if (
|
|
509
|
+
args: [{ selector: 'ngs-forms-form-group', imports: [NgsFormsFormItemDirective], changeDetection: ChangeDetectionStrategy.OnPush, template: "@if (config.items) {\n @for (item of config.items; track item.uuid) {\n <ng-container [ngs-form-item]=\"item\" [ngs-form-group]=\"formGroupControl\"></ng-container>\n }\n}\n" }]
|
|
460
510
|
}], ctorParameters: () => [] });
|
|
461
511
|
|
|
462
512
|
class NgsFormsFormArrayInternalService {
|
|
463
513
|
config = inject(NGS_FORMS_ITEM_DATA).config;
|
|
464
514
|
formArray = new UntypedFormArray([]);
|
|
465
|
-
|
|
515
|
+
itemsChanged = new Subject();
|
|
466
516
|
constructor() {
|
|
467
|
-
this.addRemoveFn.add(this.formArray, this.config.name);
|
|
468
517
|
if (this.config.initialItemCount) {
|
|
469
518
|
for (let i = 0; i < this.config.initialItemCount; i++) {
|
|
470
519
|
this.addItem();
|
|
@@ -472,7 +521,6 @@ class NgsFormsFormArrayInternalService {
|
|
|
472
521
|
}
|
|
473
522
|
}
|
|
474
523
|
ngOnDestroy() {
|
|
475
|
-
this.addRemoveFn.remove(this.formArray, this.config.name);
|
|
476
524
|
}
|
|
477
525
|
removeAt(index) {
|
|
478
526
|
if (this.config?.minItems && this.formArray.controls.length <= this.config.minItems) {
|
|
@@ -482,12 +530,14 @@ class NgsFormsFormArrayInternalService {
|
|
|
482
530
|
return;
|
|
483
531
|
}
|
|
484
532
|
this.formArray.removeAt(index);
|
|
533
|
+
this.itemsChanged.next();
|
|
485
534
|
}
|
|
486
535
|
addItem() {
|
|
487
536
|
if (this.config?.maxItems && this.formArray.controls.length >= this.config.maxItems) {
|
|
488
537
|
return;
|
|
489
538
|
}
|
|
490
|
-
this.formArray.
|
|
539
|
+
this.formArray.push(new UntypedFormGroup({}));
|
|
540
|
+
this.itemsChanged.next();
|
|
491
541
|
}
|
|
492
542
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: NgsFormsFormArrayInternalService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
493
543
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: NgsFormsFormArrayInternalService });
|
|
@@ -501,7 +551,7 @@ class NgsFormsFormArrayAddItemComponent extends NgsFormsBaseClassFormComponent {
|
|
|
501
551
|
internalArrayService = inject(NgsFormsFormArrayInternalService);
|
|
502
552
|
static create(config) {
|
|
503
553
|
return {
|
|
504
|
-
uuid: v4(),
|
|
554
|
+
uuid: config.uuid || v4(),
|
|
505
555
|
type: NgsFormsFormArrayAddItemComponent.key,
|
|
506
556
|
config: config,
|
|
507
557
|
};
|
|
@@ -510,37 +560,49 @@ class NgsFormsFormArrayAddItemComponent extends NgsFormsBaseClassFormComponent {
|
|
|
510
560
|
this.internalArrayService.addItem();
|
|
511
561
|
}
|
|
512
562
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: NgsFormsFormArrayAddItemComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
513
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.19", type: NgsFormsFormArrayAddItemComponent, isStandalone: true, selector: "ngs-forms-form-array-add-item", usesInheritance: true, ngImport: i0, template: "<button\n (click)=\"addItem()\"\n [class]=\"config.buttonClass || 'btn btn-outline-primary'\"\n type=\"button\">\n @if (config.buttonIcon) {\n <i [class]=\"config.buttonIcon\"></i>\n }\n {{ config.buttonText || 'Add Item' }}\n</button>\n", changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
563
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.19", type: NgsFormsFormArrayAddItemComponent, isStandalone: true, selector: "ngs-forms-form-array-add-item", usesInheritance: true, ngImport: i0, template: "<button\n (click)=\"addItem()\"\n [class]=\"config.buttonClass || 'btn btn-outline-primary'\"\n type=\"button\">\n @if (config.buttonIcon) {\n <i [class]=\"config.buttonIcon\" aria-hidden=\"true\"></i>\n }\n {{ config.buttonText || 'Add Item' }}\n</button>\n", changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
514
564
|
}
|
|
515
565
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: NgsFormsFormArrayAddItemComponent, decorators: [{
|
|
516
566
|
type: Component,
|
|
517
|
-
args: [{ selector: 'ngs-forms-form-array-add-item', changeDetection: ChangeDetectionStrategy.OnPush, template: "<button\n (click)=\"addItem()\"\n [class]=\"config.buttonClass || 'btn btn-outline-primary'\"\n type=\"button\">\n @if (config.buttonIcon) {\n <i [class]=\"config.buttonIcon\"></i>\n }\n {{ config.buttonText || 'Add Item' }}\n</button>\n" }]
|
|
567
|
+
args: [{ selector: 'ngs-forms-form-array-add-item', changeDetection: ChangeDetectionStrategy.OnPush, template: "<button\n (click)=\"addItem()\"\n [class]=\"config.buttonClass || 'btn btn-outline-primary'\"\n type=\"button\">\n @if (config.buttonIcon) {\n <i [class]=\"config.buttonIcon\" aria-hidden=\"true\"></i>\n }\n {{ config.buttonText || 'Add Item' }}\n</button>\n" }]
|
|
518
568
|
}] });
|
|
519
569
|
|
|
520
570
|
class NgsFormsFormArrayContainerComponent extends NgsFormsFormItemWithVisibleAndValidatorsBase {
|
|
571
|
+
formArrayService;
|
|
521
572
|
static key = 'form-array';
|
|
573
|
+
constructor(formArrayService) {
|
|
574
|
+
super();
|
|
575
|
+
this.formArrayService = formArrayService;
|
|
576
|
+
this.control = this.formArrayService.formArray;
|
|
577
|
+
}
|
|
522
578
|
static create(config) {
|
|
523
579
|
return {
|
|
524
|
-
uuid: v4(),
|
|
580
|
+
uuid: config.uuid || v4(),
|
|
525
581
|
type: NgsFormsFormArrayContainerComponent.key,
|
|
526
582
|
config: config,
|
|
527
583
|
};
|
|
528
584
|
}
|
|
529
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: NgsFormsFormArrayContainerComponent, deps:
|
|
585
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: NgsFormsFormArrayContainerComponent, deps: [{ token: NgsFormsFormArrayInternalService }], target: i0.ɵɵFactoryTarget.Component });
|
|
530
586
|
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.19", type: NgsFormsFormArrayContainerComponent, isStandalone: true, selector: "ngs-forms-form-array", providers: [NgsFormsFormArrayInternalService], usesInheritance: true, ngImport: i0, template: "<div [class]=\"config.containerClass || ''\">\n @for (item of config.items; track item.uuid) {\n <ng-container [ngs-form-item]=\"item\"></ng-container>\n }\n</div>\n", dependencies: [{ kind: "directive", type: NgsFormsFormItemDirective, selector: "[ngs-form-item]", inputs: ["ngs-form-item", "ngs-form-group", "ngs-form-array", "ngs-form-index"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
531
587
|
}
|
|
532
588
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: NgsFormsFormArrayContainerComponent, decorators: [{
|
|
533
589
|
type: Component,
|
|
534
590
|
args: [{ selector: 'ngs-forms-form-array', imports: [NgsFormsFormItemDirective], providers: [NgsFormsFormArrayInternalService], changeDetection: ChangeDetectionStrategy.OnPush, template: "<div [class]=\"config.containerClass || ''\">\n @for (item of config.items; track item.uuid) {\n <ng-container [ngs-form-item]=\"item\"></ng-container>\n }\n</div>\n" }]
|
|
535
|
-
}] });
|
|
591
|
+
}], ctorParameters: () => [{ type: NgsFormsFormArrayInternalService }] });
|
|
536
592
|
|
|
537
593
|
class NgsFormsFormArrayListComponent extends NgsFormsBaseClassFormComponent {
|
|
538
594
|
static key = 'form-array-list';
|
|
539
595
|
internalArrayService = inject(NgsFormsFormArrayInternalService);
|
|
540
596
|
myFormArray = this.internalArrayService.formArray;
|
|
597
|
+
changeDetectorRef = inject(ChangeDetectorRef);
|
|
598
|
+
ngOnInit() {
|
|
599
|
+
this.subscribe(this.internalArrayService.itemsChanged, () => {
|
|
600
|
+
this.changeDetectorRef.markForCheck();
|
|
601
|
+
});
|
|
602
|
+
}
|
|
541
603
|
static create(config) {
|
|
542
604
|
return {
|
|
543
|
-
uuid: v4(),
|
|
605
|
+
uuid: config.uuid || v4(),
|
|
544
606
|
type: NgsFormsFormArrayListComponent.key,
|
|
545
607
|
config: config,
|
|
546
608
|
};
|
|
@@ -559,13 +621,28 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImpo
|
|
|
559
621
|
class NgsFormsFormArrayRemoveItemComponent extends NgsFormsBaseClassFormComponent {
|
|
560
622
|
static key = 'form-array-remove-item';
|
|
561
623
|
internalArrayService = inject(NgsFormsFormArrayInternalService);
|
|
562
|
-
|
|
624
|
+
elementRef = inject(ElementRef);
|
|
625
|
+
indexFromDi = inject(NGS_FORMS_ITEM_INDEX, { optional: true });
|
|
626
|
+
get myIndex() {
|
|
627
|
+
if (this.indexFromDi !== null && this.indexFromDi !== undefined) {
|
|
628
|
+
return this.indexFromDi;
|
|
629
|
+
}
|
|
630
|
+
const el = this.elementRef.nativeElement;
|
|
631
|
+
const container = el.closest('[data-index]');
|
|
632
|
+
if (container) {
|
|
633
|
+
const idxAttr = container.getAttribute('data-index');
|
|
634
|
+
if (idxAttr !== null) {
|
|
635
|
+
return parseInt(idxAttr, 10);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
return 0;
|
|
639
|
+
}
|
|
563
640
|
constructor() {
|
|
564
641
|
super();
|
|
565
642
|
}
|
|
566
643
|
static create(config) {
|
|
567
644
|
return {
|
|
568
|
-
uuid: v4(),
|
|
645
|
+
uuid: config.uuid || v4(),
|
|
569
646
|
type: NgsFormsFormArrayRemoveItemComponent.key,
|
|
570
647
|
config,
|
|
571
648
|
};
|
|
@@ -574,18 +651,18 @@ class NgsFormsFormArrayRemoveItemComponent extends NgsFormsBaseClassFormComponen
|
|
|
574
651
|
this.internalArrayService.removeAt(this.myIndex);
|
|
575
652
|
}
|
|
576
653
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: NgsFormsFormArrayRemoveItemComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
577
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.19", type: NgsFormsFormArrayRemoveItemComponent, isStandalone: true, selector: "ngs-forms-form-array-remove-item", usesInheritance: true, ngImport: i0, template: "<button\n (click)=\"removeItem()\"\n [class]=\"config.buttonClass || 'btn btn-outline-danger btn-sm'\"\n type=\"button\">\n @if (config.buttonIcon) {\n <i [class]=\"config.buttonIcon\"></i>\n }\n {{ config.buttonText || 'Remove' }}\n index:{{ myIndex }}\n</button>\n", changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
654
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.19", type: NgsFormsFormArrayRemoveItemComponent, isStandalone: true, selector: "ngs-forms-form-array-remove-item", usesInheritance: true, ngImport: i0, template: "<button\n (click)=\"removeItem()\"\n [class]=\"config.buttonClass || 'btn btn-outline-danger btn-sm'\"\n type=\"button\">\n @if (config.buttonIcon) {\n <i [class]=\"config.buttonIcon\" aria-hidden=\"true\"></i>\n }\n {{ config.buttonText || 'Remove' }}\n index:{{ myIndex }}\n</button>\n", changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
578
655
|
}
|
|
579
656
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: NgsFormsFormArrayRemoveItemComponent, decorators: [{
|
|
580
657
|
type: Component,
|
|
581
|
-
args: [{ selector: 'ngs-forms-form-array-remove-item', changeDetection: ChangeDetectionStrategy.OnPush, template: "<button\n (click)=\"removeItem()\"\n [class]=\"config.buttonClass || 'btn btn-outline-danger btn-sm'\"\n type=\"button\">\n @if (config.buttonIcon) {\n <i [class]=\"config.buttonIcon\"></i>\n }\n {{ config.buttonText || 'Remove' }}\n index:{{ myIndex }}\n</button>\n" }]
|
|
658
|
+
args: [{ selector: 'ngs-forms-form-array-remove-item', changeDetection: ChangeDetectionStrategy.OnPush, template: "<button\n (click)=\"removeItem()\"\n [class]=\"config.buttonClass || 'btn btn-outline-danger btn-sm'\"\n type=\"button\">\n @if (config.buttonIcon) {\n <i [class]=\"config.buttonIcon\" aria-hidden=\"true\"></i>\n }\n {{ config.buttonText || 'Remove' }}\n index:{{ myIndex }}\n</button>\n" }]
|
|
582
659
|
}], ctorParameters: () => [] });
|
|
583
660
|
|
|
584
661
|
class NgsFormsTextDivComponent extends NgsFormsBaseClassFormComponent {
|
|
585
662
|
static key = 'text-div';
|
|
586
663
|
static create(config) {
|
|
587
664
|
return {
|
|
588
|
-
uuid: v4(),
|
|
665
|
+
uuid: config.uuid || v4(),
|
|
589
666
|
type: NgsFormsTextDivComponent.key,
|
|
590
667
|
config: config,
|
|
591
668
|
};
|
|
@@ -617,7 +694,7 @@ class NgsFormsHtmlContentComponent extends NgsFormsBaseClassFormComponent {
|
|
|
617
694
|
}
|
|
618
695
|
static create(config) {
|
|
619
696
|
return {
|
|
620
|
-
uuid: v4(),
|
|
697
|
+
uuid: config.uuid || v4(),
|
|
621
698
|
type: NgsFormsHtmlContentComponent.key,
|
|
622
699
|
config,
|
|
623
700
|
};
|
|
@@ -639,13 +716,13 @@ class NgsFormsFormSectionComponent extends NgsFormsBaseClassItemsContainerBase {
|
|
|
639
716
|
static key = 'section';
|
|
640
717
|
static create(config) {
|
|
641
718
|
return {
|
|
642
|
-
uuid: v4(),
|
|
719
|
+
uuid: config.uuid || v4(),
|
|
643
720
|
type: NgsFormsFormSectionComponent.key,
|
|
644
721
|
config: config,
|
|
645
722
|
};
|
|
646
723
|
}
|
|
647
724
|
ngOnInit() {
|
|
648
|
-
this.config =
|
|
725
|
+
this.config = ngsDefaults(this.config, sectionConfigDefaults);
|
|
649
726
|
}
|
|
650
727
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: NgsFormsFormSectionComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
651
728
|
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.19", type: NgsFormsFormSectionComponent, isStandalone: true, selector: "ngs-forms-form-section", usesInheritance: true, ngImport: i0, template: "<div class=\"form-section\">\n <div class=\"form-section-title {{config.titleClass}}\">{{ config.title }}</div>\n @if (config.subtitle) {\n <div class=\"form-section-subtitle {{config.subtitleClass}}\">{{ config.subtitle }}</div>\n }\n @if (config.items.length) {\n <div class=\"form-section-items\">\n @for (item of config.items; track item.uuid) {\n <ng-container [ngs-form-item]=\"item\"></ng-container>\n }\n </div>\n }\n</div>\n", dependencies: [{ kind: "directive", type: NgsFormsFormItemDirective, selector: "[ngs-form-item]", inputs: ["ngs-form-item", "ngs-form-group", "ngs-form-array", "ngs-form-index"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
@@ -683,5 +760,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImpo
|
|
|
683
760
|
* Generated bundle index. Do not edit.
|
|
684
761
|
*/
|
|
685
762
|
|
|
686
|
-
export { NGS_FORMS_CONTROL_ADD_REMOVE_FN, NGS_FORMS_ITEM_DATA, NGS_FORMS_ITEM_INDEX, NgsFormComponent, NgsFormsBaseClassFormComponent, NgsFormsBaseClassFormInputComponent, NgsFormsBaseClassFormItemInputWithOptionsComponent, NgsFormsBaseClassItemsContainerBase, NgsFormsColumnComponent, NgsFormsComponentRegistryService, NgsFormsCoreModule, NgsFormsFormArrayAddItemComponent, NgsFormsFormArrayContainerComponent, NgsFormsFormArrayInternalService, NgsFormsFormArrayListComponent, NgsFormsFormArrayRemoveItemComponent, NgsFormsFormControlAddRemoveFunctions, NgsFormsFormGroupComponent, NgsFormsFormItemDirective, NgsFormsFormItemWithVisibleAndValidatorsBase, NgsFormsFormSectionComponent, NgsFormsHtmlContentComponent, NgsFormsInternalService, NgsFormsRowComponent, NgsFormsService, NgsFormsTextDivComponent, NgsSubscriber };
|
|
763
|
+
export { NGS_FORMS_CONTROL_ADD_REMOVE_FN, NGS_FORMS_ITEM_DATA, NGS_FORMS_ITEM_INDEX, NgsFormComponent, NgsFormsBaseClassFormComponent, NgsFormsBaseClassFormInputComponent, NgsFormsBaseClassFormItemInputWithOptionsComponent, NgsFormsBaseClassItemsContainerBase, NgsFormsColumnComponent, NgsFormsComponentRegistryService, NgsFormsCoreModule, NgsFormsFormArrayAddItemComponent, NgsFormsFormArrayContainerComponent, NgsFormsFormArrayInternalService, NgsFormsFormArrayListComponent, NgsFormsFormArrayRemoveItemComponent, NgsFormsFormControlAddRemoveFunctions, NgsFormsFormGroupComponent, NgsFormsFormItemDirective, NgsFormsFormItemWithVisibleAndValidatorsBase, NgsFormsFormSectionComponent, NgsFormsHtmlContentComponent, NgsFormsInternalService, NgsFormsRowComponent, NgsFormsService, NgsFormsTextDivComponent, NgsSubscriber, ngsDefaults };
|
|
687
764
|
//# sourceMappingURL=ng-simplicity-forms-core.mjs.map
|