ng-form-foundry 0.0.1
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 +63 -0
- package/ng-package.json +7 -0
- package/package.json +12 -0
- package/src/lib/core/dynamic-recursive-forms-builder.ts +129 -0
- package/src/lib/core/utils.ts +33 -0
- package/src/lib/dynamic-recursive-form/anon-leaf-renderer/anon-leaf-renderer.component.html +31 -0
- package/src/lib/dynamic-recursive-form/anon-leaf-renderer/anon-leaf-renderer.component.scss +11 -0
- package/src/lib/dynamic-recursive-form/anon-leaf-renderer/anon-leaf-renderer.component.spec.ts +22 -0
- package/src/lib/dynamic-recursive-form/anon-leaf-renderer/anon-leaf-renderer.component.ts +39 -0
- package/src/lib/dynamic-recursive-form/dynamic-recursive-form.component.html +168 -0
- package/src/lib/dynamic-recursive-form/dynamic-recursive-form.component.scss +128 -0
- package/src/lib/dynamic-recursive-form/dynamic-recursive-form.component.spec.ts +23 -0
- package/src/lib/dynamic-recursive-form/dynamic-recursive-form.component.ts +71 -0
- package/src/lib/dynamic-recursive-form/dynamic-recursive-form.stories.ts +36 -0
- package/src/lib/dynamic-recursive-form/leaf-enum-renderer/leaf-enum-renderer.component.html +8 -0
- package/src/lib/dynamic-recursive-form/leaf-enum-renderer/leaf-enum-renderer.component.scss +9 -0
- package/src/lib/dynamic-recursive-form/leaf-enum-renderer/leaf-enum-renderer.component.spec.ts +22 -0
- package/src/lib/dynamic-recursive-form/leaf-enum-renderer/leaf-enum-renderer.component.ts +21 -0
- package/src/lib/dynamic-recursive-form/leaf-list-renderer/leaf-list-renderer.component.html +31 -0
- package/src/lib/dynamic-recursive-form/leaf-list-renderer/leaf-list-renderer.component.scss +57 -0
- package/src/lib/dynamic-recursive-form/leaf-list-renderer/leaf-list-renderer.component.spec.ts +23 -0
- package/src/lib/dynamic-recursive-form/leaf-list-renderer/leaf-list-renderer.component.ts +52 -0
- package/src/lib/dynamic-recursive-form/leaf-renderer/leaf-renderer.component.html +17 -0
- package/src/lib/dynamic-recursive-form/leaf-renderer/leaf-renderer.component.scss +11 -0
- package/src/lib/dynamic-recursive-form/leaf-renderer/leaf-renderer.component.spec.ts +22 -0
- package/src/lib/dynamic-recursive-form/leaf-renderer/leaf-renderer.component.ts +41 -0
- package/src/lib/dynamic-recursive-form/node-group-list-renderer/node-group-list-renderer.component.html +24 -0
- package/src/lib/dynamic-recursive-form/node-group-list-renderer/node-group-list-renderer.component.scss +48 -0
- package/src/lib/dynamic-recursive-form/node-group-list-renderer/node-group-list-renderer.component.spec.ts +22 -0
- package/src/lib/dynamic-recursive-form/node-group-list-renderer/node-group-list-renderer.component.ts +101 -0
- package/src/lib/types/dynamic-recursive.types.ts +97 -0
- package/src/lib/types/examples/complex-oai.ts +938 -0
- package/src/public-api.ts +12 -0
- package/tsconfig.lib.json +18 -0
- package/tsconfig.lib.prod.json +11 -0
- package/tsconfig.spec.json +14 -0
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# NgFormFoundry
|
|
2
|
+
|
|
3
|
+
This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 20.3.0.
|
|
4
|
+
|
|
5
|
+
## Code scaffolding
|
|
6
|
+
|
|
7
|
+
Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
ng generate component component-name
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
ng generate --help
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Building
|
|
20
|
+
|
|
21
|
+
To build the library, run:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
ng build ng-form-foundry
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
This command will compile your project, and the build artifacts will be placed in the `dist/` directory.
|
|
28
|
+
|
|
29
|
+
### Publishing the Library
|
|
30
|
+
|
|
31
|
+
Once the project is built, you can publish your library by following these steps:
|
|
32
|
+
|
|
33
|
+
1. Navigate to the `dist` directory:
|
|
34
|
+
```bash
|
|
35
|
+
cd dist/ng-form-foundry
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
2. Run the `npm publish` command to publish your library to the npm registry:
|
|
39
|
+
```bash
|
|
40
|
+
npm publish
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Running unit tests
|
|
44
|
+
|
|
45
|
+
To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
ng test
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Running end-to-end tests
|
|
52
|
+
|
|
53
|
+
For end-to-end (e2e) testing, run:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
ng e2e
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
|
|
60
|
+
|
|
61
|
+
## Additional Resources
|
|
62
|
+
|
|
63
|
+
For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
|
package/ng-package.json
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FormArray,
|
|
3
|
+
FormControl,
|
|
4
|
+
FormGroup,
|
|
5
|
+
ValidatorFn,
|
|
6
|
+
Validators,
|
|
7
|
+
} from '@angular/forms';
|
|
8
|
+
import {
|
|
9
|
+
DFormControl,
|
|
10
|
+
DFormGroup,
|
|
11
|
+
FormGroupType,
|
|
12
|
+
Leaf,
|
|
13
|
+
LeafEnum,
|
|
14
|
+
LeafList,
|
|
15
|
+
LeafRuntimeType,
|
|
16
|
+
NodeGroup,
|
|
17
|
+
NodeGroupList,
|
|
18
|
+
NodeType,
|
|
19
|
+
} from '../types/dynamic-recursive.types';
|
|
20
|
+
|
|
21
|
+
// --- type guards
|
|
22
|
+
function isLeaf(node: NodeType): node is Leaf {
|
|
23
|
+
return node.kind === 'leaf';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function isLeafList(node: NodeType): node is LeafList {
|
|
27
|
+
return node.kind === 'leafList';
|
|
28
|
+
}
|
|
29
|
+
function isNodeGroup(node: NodeType): node is NodeGroup {
|
|
30
|
+
return node.kind === 'nodeGroup';
|
|
31
|
+
}
|
|
32
|
+
function isNodeGroupList(node: NodeType): node is NodeGroupList {
|
|
33
|
+
return node.kind === 'nodeGroupList';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function enumValidator(choices: readonly (string | number)[]): ValidatorFn {
|
|
37
|
+
const set = new Set(choices);
|
|
38
|
+
return (ctrl) =>
|
|
39
|
+
ctrl.value == null || set.has(ctrl.value) ? null : { enum: true };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function buildLeafControl<L extends Leaf>(
|
|
43
|
+
leaf: L,
|
|
44
|
+
initial?: unknown,
|
|
45
|
+
): FormControl<LeafRuntimeType<L['type']>> {
|
|
46
|
+
const validators: ValidatorFn[] = [];
|
|
47
|
+
if ('required' in leaf && leaf.required) validators.push(Validators.required);
|
|
48
|
+
if ('type' in leaf && leaf.type === 'enum') {
|
|
49
|
+
const choices = (leaf as LeafEnum).enum as (string | number)[];
|
|
50
|
+
validators.push(enumValidator(choices));
|
|
51
|
+
}
|
|
52
|
+
const defaultValue =
|
|
53
|
+
initial ?? ('default' in leaf ? (leaf as any).default : undefined) ?? null;
|
|
54
|
+
return new FormControl<LeafRuntimeType<L['type']>>(defaultValue, {
|
|
55
|
+
nonNullable: true,
|
|
56
|
+
validators,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function buildLeafListControl<L extends LeafList>(
|
|
61
|
+
list: L,
|
|
62
|
+
initial: LeafRuntimeType<L['type']>[] | null,
|
|
63
|
+
): FormArray<FormControl<LeafRuntimeType<LeafList['type']> | null>> {
|
|
64
|
+
const values = (Array.isArray(initial) ? initial : undefined) ??
|
|
65
|
+
list.default ?? [null];
|
|
66
|
+
return new FormArray(values.map((v) => new FormControl(v)));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function buildNodeGroupControl<G extends NodeGroup>(
|
|
70
|
+
group: G,
|
|
71
|
+
initial?: Record<string, unknown> | null,
|
|
72
|
+
): DFormGroup<G> {
|
|
73
|
+
const controls: any = {} as Partial<FormGroupType<G>>;
|
|
74
|
+
for (const key in group.children) {
|
|
75
|
+
const child = group.children[key];
|
|
76
|
+
controls[key] = buildControl(
|
|
77
|
+
child,
|
|
78
|
+
initial,
|
|
79
|
+
) as FormGroupType<G>[typeof key];
|
|
80
|
+
}
|
|
81
|
+
return new FormGroup(controls as FormGroupType<G>) as DFormGroup<G>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function buildNodeGroupListControl<GL extends NodeGroupList>(
|
|
85
|
+
list: GL,
|
|
86
|
+
initial: GL[] | null = null,
|
|
87
|
+
): FormArray<DFormGroup<GL['type']>> {
|
|
88
|
+
const values = Array.isArray(initial) ? initial : [null];
|
|
89
|
+
return new FormArray(
|
|
90
|
+
values.map((v) => buildNodeGroupControl(list.type, v as any)),
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function buildControl<T extends NodeType>(
|
|
95
|
+
node: T,
|
|
96
|
+
initial?: unknown | null,
|
|
97
|
+
): DFormControl<T> | FormControl<LeafRuntimeType<any>> | FormArray<any> {
|
|
98
|
+
if (isLeaf(node)) {
|
|
99
|
+
return buildLeafControl(node, initial);
|
|
100
|
+
}
|
|
101
|
+
if (isLeafList(node)) {
|
|
102
|
+
return buildLeafListControl(
|
|
103
|
+
node,
|
|
104
|
+
initial !== null
|
|
105
|
+
? (initial as LeafRuntimeType<(T & LeafList)['type']>[])
|
|
106
|
+
: initial,
|
|
107
|
+
) as DFormControl<T>;
|
|
108
|
+
}
|
|
109
|
+
if (isNodeGroup(node)) {
|
|
110
|
+
return buildNodeGroupControl(
|
|
111
|
+
node,
|
|
112
|
+
initial ? (initial as Record<string, unknown>) : null,
|
|
113
|
+
) as DFormControl<T>;
|
|
114
|
+
}
|
|
115
|
+
if (isNodeGroupList(node)) {
|
|
116
|
+
return buildNodeGroupListControl(
|
|
117
|
+
node,
|
|
118
|
+
initial ? (initial as NodeGroupList[]) : null,
|
|
119
|
+
) as DFormControl<T>;
|
|
120
|
+
}
|
|
121
|
+
return new FormControl(initial ?? '') as DFormControl<T>;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function buildFormFromSchema<S extends NodeGroup>(
|
|
125
|
+
schema: S,
|
|
126
|
+
initial: Record<string, unknown> | null = null,
|
|
127
|
+
): DFormGroup<S> {
|
|
128
|
+
return buildNodeGroupControl<S>(schema, initial);
|
|
129
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { FormArray, FormControl, FormGroup } from '@angular/forms';
|
|
2
|
+
import { Leaf, NodeGroup, NodeGroupList, NodeType } from '../types/dynamic-recursive.types';
|
|
3
|
+
|
|
4
|
+
export function nodeGroupChildrenList(schema: NodeGroup): Array<{ key: string; value: NodeType }> {
|
|
5
|
+
const children = schema.children ?? {};
|
|
6
|
+
return Object.entries(children).map(([key, value]) => ({
|
|
7
|
+
key,
|
|
8
|
+
value: value as NodeType,
|
|
9
|
+
}));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function nodeGroupChildrenLeafs(schema: NodeGroup): Array<{ key: string; value: Leaf }> {
|
|
13
|
+
const children = schema.children ?? {};
|
|
14
|
+
return Object.entries(children).reduce((acc, [key, value]) => {
|
|
15
|
+
if (value.kind === 'leaf') {
|
|
16
|
+
acc.push({ key, value: value as Leaf });
|
|
17
|
+
}
|
|
18
|
+
return acc;
|
|
19
|
+
}, [] as Array<{ key: string; value: Leaf }>);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function asFormControl(control: any) {
|
|
23
|
+
return control as FormControl;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function asFormArray(control: any) {
|
|
27
|
+
return control as FormArray;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function asFormGroup(control: any) {
|
|
31
|
+
return control as FormGroup;
|
|
32
|
+
}
|
|
33
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<div class="anon-leaf-container">
|
|
2
|
+
@if (AnonLeaf.type === 'string') {
|
|
3
|
+
<mat-form-field [appearance]="editable ? 'fill' : 'outline'">
|
|
4
|
+
<mat-label>{{ label }} #{{ index + 1}}</mat-label>
|
|
5
|
+
<input [readonly]="!editable"
|
|
6
|
+
[formControl]="control"
|
|
7
|
+
matInput type="text" >
|
|
8
|
+
@if (removable) {
|
|
9
|
+
}
|
|
10
|
+
</mat-form-field>
|
|
11
|
+
} @else if (AnonLeaf.type === 'number') {
|
|
12
|
+
<mat-form-field [appearance]="editable ? 'fill' : 'outline'">
|
|
13
|
+
<mat-label>{{ label }} #{{ index + 1}}</mat-label>
|
|
14
|
+
<input [readonly]="!editable"
|
|
15
|
+
[formControl]="control"
|
|
16
|
+
matInput type="number">
|
|
17
|
+
</mat-form-field>
|
|
18
|
+
} @else if (AnonLeaf.type === 'boolean') {
|
|
19
|
+
<mat-checkbox [disabled]="!editable" [formControl]="control">value</mat-checkbox>
|
|
20
|
+
}
|
|
21
|
+
@else if (AnonLeaf.type === 'enum' && 'enum' in AnonLeaf) {
|
|
22
|
+
<mat-form-field>
|
|
23
|
+
<mat-label>{{ label }} #{{ index + 1}}</mat-label>
|
|
24
|
+
<mat-select [formControl]="control">
|
|
25
|
+
@for (option of (AnonLeaf.type === 'enum' ? AnonLeaf.enum : []); track $index) {
|
|
26
|
+
<mat-option [value]="option">{{ option }}</mat-option>
|
|
27
|
+
}
|
|
28
|
+
</mat-select>
|
|
29
|
+
</mat-form-field>
|
|
30
|
+
}
|
|
31
|
+
</div>
|
package/src/lib/dynamic-recursive-form/anon-leaf-renderer/anon-leaf-renderer.component.spec.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { AnonLeafRendererComponent } from './anon-leaf-renderer.component';
|
|
4
|
+
|
|
5
|
+
describe('DrfAnonLeafRendererComponent', () => {
|
|
6
|
+
let component: AnonLeafRendererComponent;
|
|
7
|
+
let fixture: ComponentFixture<AnonLeafRendererComponent>;
|
|
8
|
+
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
await TestBed.configureTestingModule({
|
|
11
|
+
imports: [AnonLeafRendererComponent],
|
|
12
|
+
}).compileComponents();
|
|
13
|
+
|
|
14
|
+
fixture = TestBed.createComponent(AnonLeafRendererComponent);
|
|
15
|
+
component = fixture.componentInstance;
|
|
16
|
+
fixture.detectChanges();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should create', () => {
|
|
20
|
+
expect(component).toBeTruthy();
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
|
2
|
+
import { AnonLeaf } from '../../types/dynamic-recursive.types';
|
|
3
|
+
import { FormControl, ReactiveFormsModule } from '@angular/forms';
|
|
4
|
+
import { MatSelectModule } from '@angular/material/select';
|
|
5
|
+
import { MatFormFieldModule } from '@angular/material/form-field';
|
|
6
|
+
import { MatIconModule } from '@angular/material/icon';
|
|
7
|
+
import { MatCheckboxModule } from '@angular/material/checkbox';
|
|
8
|
+
import { MatInputModule } from '@angular/material/input';
|
|
9
|
+
import { MatButtonModule } from '@angular/material/button';
|
|
10
|
+
|
|
11
|
+
@Component({
|
|
12
|
+
selector: 'nff-anon-leaf-renderer',
|
|
13
|
+
standalone: true,
|
|
14
|
+
imports: [
|
|
15
|
+
ReactiveFormsModule,
|
|
16
|
+
MatFormFieldModule,
|
|
17
|
+
MatSelectModule,
|
|
18
|
+
MatIconModule,
|
|
19
|
+
MatCheckboxModule,
|
|
20
|
+
MatInputModule,
|
|
21
|
+
MatButtonModule,
|
|
22
|
+
],
|
|
23
|
+
templateUrl: './anon-leaf-renderer.component.html',
|
|
24
|
+
styleUrl: './anon-leaf-renderer.component.scss',
|
|
25
|
+
})
|
|
26
|
+
export class AnonLeafRendererComponent {
|
|
27
|
+
@Input() AnonLeaf!: AnonLeaf;
|
|
28
|
+
@Input() initialValue!: string;
|
|
29
|
+
@Input() control = new FormControl();
|
|
30
|
+
@Input() removable: boolean = false;
|
|
31
|
+
@Input() editable: boolean = true;
|
|
32
|
+
@Input() index!: number;
|
|
33
|
+
@Output() remove = new EventEmitter();
|
|
34
|
+
@Input() label!: string;
|
|
35
|
+
|
|
36
|
+
emitRemoveEvent() {
|
|
37
|
+
this.remove.emit();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
@if (!root) {
|
|
2
|
+
<ng-template #formRender>
|
|
3
|
+
<div class="form-content" [formGroup]="formGroup">
|
|
4
|
+
<div class="leafs-container">
|
|
5
|
+
<div class="fields">
|
|
6
|
+
@for (childItem of nodeGroupChildrenList; track $index) {
|
|
7
|
+
@let child = childItem.value;
|
|
8
|
+
@if (child.kind == 'leaf') {
|
|
9
|
+
<nff-leaf-renderer
|
|
10
|
+
[leaf_]=child
|
|
11
|
+
[control]=asFormControl(formGroup.get(child.name))
|
|
12
|
+
[removable]=false
|
|
13
|
+
[editable]=editable
|
|
14
|
+
[initialValue]="formGroup.get(child.name)?.value"
|
|
15
|
+
/>
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
@for (childItem of nodeGroupChildrenList; track $index) {
|
|
19
|
+
@let child = childItem.value;
|
|
20
|
+
@if (child.kind == 'leafList') {
|
|
21
|
+
<nff-leaf-list-renderer
|
|
22
|
+
[leaf_]="child"
|
|
23
|
+
[editable]=editable
|
|
24
|
+
[formArray]="asFormArray(formGroup.get(child.name))"
|
|
25
|
+
[initialValue]="formGroup.get(child.name)?.value"
|
|
26
|
+
/>
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
@for (childItem of nodeGroupChildrenList; track $index) {
|
|
32
|
+
@let child = childItem.value;
|
|
33
|
+
@if (child.kind == 'nodeGroup' && child.appearance?.flatten) {
|
|
34
|
+
<nff-dynamic-recursive-form
|
|
35
|
+
[schema]="child"
|
|
36
|
+
[formGroup]="asFormGroup(formGroup.get(child.name))"
|
|
37
|
+
[initialValue]="formGroup.get(child.name)?.value"
|
|
38
|
+
[editable]="editable"
|
|
39
|
+
/>
|
|
40
|
+
}
|
|
41
|
+
@else if (child.kind == 'nodeGroup'){
|
|
42
|
+
<nff-dynamic-recursive-form
|
|
43
|
+
[schema]="child"
|
|
44
|
+
[formGroup]="asFormGroup(formGroup.get(child.name))"
|
|
45
|
+
[initialValue]="formGroup.get(child.name)?.value"
|
|
46
|
+
[editable]="editable"
|
|
47
|
+
/>
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@for (childItem of nodeGroupChildrenList; track $index) {
|
|
52
|
+
@let child = childItem.value;
|
|
53
|
+
@if (child.kind == 'nodeGroupList') {
|
|
54
|
+
<nff-node-group-list-renderer
|
|
55
|
+
[nodeGroupList]="child"
|
|
56
|
+
[formArray]="asFormArray(formGroup.get(child.name))"
|
|
57
|
+
[initialValue]="formGroup.get(child.name)?.value"
|
|
58
|
+
[editable]="editable"
|
|
59
|
+
/>
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
</div>
|
|
63
|
+
</ng-template>
|
|
64
|
+
@if (schema.appearance?.flatten) {
|
|
65
|
+
<div class="flattened-form">
|
|
66
|
+
<ng-container *ngTemplateOutlet="formRender"></ng-container>
|
|
67
|
+
@if (editable && removable) {
|
|
68
|
+
<button matIconButton class="small-icon-button edit-icon" [class]="{ 'edit-icon': !editable}" (click)="emitRemoveEvent(); $event.stopPropagation()">
|
|
69
|
+
<mat-icon>delete</mat-icon>
|
|
70
|
+
</button>
|
|
71
|
+
}
|
|
72
|
+
</div>
|
|
73
|
+
}
|
|
74
|
+
@else {
|
|
75
|
+
<mat-card appearance="outlined" [class]="{ 'mat-card-no-broder': schema.appearance?.noBorder }">
|
|
76
|
+
<mat-card-header>
|
|
77
|
+
<div>
|
|
78
|
+
<button matIconButton class="small-icon-button" [class]="{ 'edit-icon': !editable}" (click)="editable = !editable">
|
|
79
|
+
<mat-icon>edit</mat-icon>
|
|
80
|
+
</button>
|
|
81
|
+
@if (editable && removable) {
|
|
82
|
+
<button matIconButton class="small-icon-button edit-icon" [class]="{ 'edit-icon': !editable}" (click)="emitRemoveEvent(); $event.stopPropagation()">
|
|
83
|
+
<mat-icon>delete</mat-icon>
|
|
84
|
+
</button>
|
|
85
|
+
}
|
|
86
|
+
</div>
|
|
87
|
+
<mat-card-title class="config-form-subsection-card">
|
|
88
|
+
{{ title ?? schema.label ?? schema.name }}
|
|
89
|
+
</mat-card-title>
|
|
90
|
+
</mat-card-header>
|
|
91
|
+
<mat-card-content>
|
|
92
|
+
<ng-container *ngTemplateOutlet="formRender"></ng-container>
|
|
93
|
+
</mat-card-content>
|
|
94
|
+
</mat-card>
|
|
95
|
+
}
|
|
96
|
+
} @else {
|
|
97
|
+
<div class="form-content" [formGroup]="formGroup">
|
|
98
|
+
<div class="leafs-container">
|
|
99
|
+
<div class="fields">
|
|
100
|
+
<button matIconButton class="small-icon-button" [class]="{ 'edit-icon': !editable }" (click)="editable = !editable">
|
|
101
|
+
<mat-icon>edit</mat-icon>
|
|
102
|
+
</button>
|
|
103
|
+
@for (childItem of nodeGroupChildrenList; track $index) {
|
|
104
|
+
@let child = childItem.value;
|
|
105
|
+
@if (child.kind == 'leaf') {
|
|
106
|
+
<nff-leaf-renderer
|
|
107
|
+
[leaf_]=child
|
|
108
|
+
[control]=asFormControl(formGroup.get(child.name))
|
|
109
|
+
[removable]=false
|
|
110
|
+
[editable]=editable
|
|
111
|
+
[initialValue]="formGroup.get(child.name)?.value"
|
|
112
|
+
/>
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
@for (childItem of nodeGroupChildrenList; track $index) {
|
|
116
|
+
@let child = childItem.value;
|
|
117
|
+
@if (child.kind == 'leafList') {
|
|
118
|
+
<nff-leaf-list-renderer
|
|
119
|
+
[leaf_]="child"
|
|
120
|
+
[editable]=editable
|
|
121
|
+
[formArray]="asFormArray(formGroup.get(child.name))"
|
|
122
|
+
[initialValue]="formGroup.get(child.name)?.value"
|
|
123
|
+
/>
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
128
|
+
<mat-accordion multi>
|
|
129
|
+
@for (childItem of nodeGroupChildrenList; track $index) {
|
|
130
|
+
@let child = childItem.value;
|
|
131
|
+
@if (child.kind == 'nodeGroupList') {
|
|
132
|
+
<mat-expansion-panel togglePosition="before">
|
|
133
|
+
<mat-expansion-panel-header>
|
|
134
|
+
<mat-panel-title>
|
|
135
|
+
{{ title ?? child.label ?? child.name }}
|
|
136
|
+
</mat-panel-title>
|
|
137
|
+
</mat-expansion-panel-header>
|
|
138
|
+
<nff-node-group-list-renderer
|
|
139
|
+
[nodeGroupList]="child"
|
|
140
|
+
[formArray]="asFormArray(formGroup.get(child.name))"
|
|
141
|
+
[initialValue]="formGroup.get(child.name)?.value"
|
|
142
|
+
[editable]="editable"
|
|
143
|
+
/>
|
|
144
|
+
</mat-expansion-panel>
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
@for (childItem of nodeGroupChildrenList; track $index) {
|
|
148
|
+
@let child = childItem.value;
|
|
149
|
+
@if (child.kind == 'nodeGroup') {
|
|
150
|
+
<mat-expansion-panel togglePosition="before" expanded="true">
|
|
151
|
+
<mat-expansion-panel-header >
|
|
152
|
+
<mat-panel-title>
|
|
153
|
+
{{ title ?? child.label ?? child.name }}
|
|
154
|
+
</mat-panel-title>
|
|
155
|
+
</mat-expansion-panel-header>
|
|
156
|
+
<nff-dynamic-recursive-form
|
|
157
|
+
[schema]="child"
|
|
158
|
+
[formGroup]="asFormGroup(formGroup.get(child.name))"
|
|
159
|
+
[initialValue]="formGroup.get(child.name)?.value"
|
|
160
|
+
[title]="child.name ?? 'General Settings'"
|
|
161
|
+
[editable]="editable"
|
|
162
|
+
/>
|
|
163
|
+
</mat-expansion-panel>
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
</mat-accordion>
|
|
167
|
+
</div>
|
|
168
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
@use '@angular/material' as mat;
|
|
2
|
+
|
|
3
|
+
:host {
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
flex-wrap: wrap;
|
|
7
|
+
@include mat.expansion-overrides((
|
|
8
|
+
));
|
|
9
|
+
width: 100%;
|
|
10
|
+
margin: 8px 0;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.fields {
|
|
14
|
+
display: flex;
|
|
15
|
+
flex-direction: row;
|
|
16
|
+
gap: 8px;
|
|
17
|
+
flex-wrap: wrap;
|
|
18
|
+
flex: 1 1 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.mat-expansion-panel-content {
|
|
22
|
+
display: flex;
|
|
23
|
+
flex-direction: row;
|
|
24
|
+
gap: 16px;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
.mat-expansion-panel-content:hover {
|
|
29
|
+
display: flex;
|
|
30
|
+
flex-direction: row;
|
|
31
|
+
gap: 16px;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
.form-content {
|
|
36
|
+
display: flex;
|
|
37
|
+
flex-direction: column;
|
|
38
|
+
flex-wrap: wrap;
|
|
39
|
+
width: 100%;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.leafs-container {
|
|
43
|
+
display: flex;
|
|
44
|
+
flex-direction: column;
|
|
45
|
+
gap: 8px;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
mat-panel-description {
|
|
49
|
+
display: flex;
|
|
50
|
+
flex-direction: row;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.node-groups-container {
|
|
54
|
+
display: flex;
|
|
55
|
+
flex-direction: column;
|
|
56
|
+
flex-basis: 100%;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.section-actions {
|
|
60
|
+
display: flex;
|
|
61
|
+
flex-direction: row;
|
|
62
|
+
gap: 8px;
|
|
63
|
+
justify-content: flex-end;
|
|
64
|
+
width: 100%;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
mat-card {
|
|
68
|
+
padding: 0;
|
|
69
|
+
width: 100%;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.mat-card-no-broder {
|
|
73
|
+
border: 0;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
mat-card-content {
|
|
77
|
+
box-sizing: border-box;
|
|
78
|
+
padding: 16px;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
mat-card-header {
|
|
82
|
+
display: flex;
|
|
83
|
+
flex-direction: row;
|
|
84
|
+
align-items: flex-start;
|
|
85
|
+
padding: 16px 16px;
|
|
86
|
+
gap: 16px;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.edit-icon {
|
|
90
|
+
opacity: 0.2;
|
|
91
|
+
animation: icon-released 0.5s;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.edit-icon:hover {
|
|
95
|
+
opacity: 1;
|
|
96
|
+
animation: icon-transition 0.5s;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.flattened-form {
|
|
100
|
+
display: flex;
|
|
101
|
+
flex-direction: row;
|
|
102
|
+
width: 100%;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.flattened-style-actions {
|
|
106
|
+
display: flex;
|
|
107
|
+
flex-direction: row;
|
|
108
|
+
gap: 8px;
|
|
109
|
+
justify-content: flex-end;
|
|
110
|
+
align-items: flex-start;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
@keyframes icon-hovered {
|
|
114
|
+
0% {
|
|
115
|
+
opacity: 0.4;
|
|
116
|
+
}
|
|
117
|
+
100% {}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@keyframes icon-released {
|
|
121
|
+
0% {
|
|
122
|
+
opacity: 1;
|
|
123
|
+
}
|
|
124
|
+
100% {
|
|
125
|
+
opacity: 0.4;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { DynamicRecursiveFormComponent } from './dynamic-recursive-form.component';
|
|
4
|
+
|
|
5
|
+
describe('DynamicRecursiveFormComponent', () => {
|
|
6
|
+
let component: DynamicRecursiveFormComponent;
|
|
7
|
+
let fixture: ComponentFixture<DynamicRecursiveFormComponent>;
|
|
8
|
+
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
await TestBed.configureTestingModule({
|
|
11
|
+
imports: [DynamicRecursiveFormComponent]
|
|
12
|
+
})
|
|
13
|
+
.compileComponents();
|
|
14
|
+
|
|
15
|
+
fixture = TestBed.createComponent(DynamicRecursiveFormComponent);
|
|
16
|
+
component = fixture.componentInstance;
|
|
17
|
+
fixture.detectChanges();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should create', () => {
|
|
21
|
+
expect(component).toBeTruthy();
|
|
22
|
+
});
|
|
23
|
+
});
|