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
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { FormArray, FormControl, FormGroup } from '@angular/forms';
|
|
2
|
+
|
|
3
|
+
export type LeafRuntimeType<T> = T extends 'string'
|
|
4
|
+
? string
|
|
5
|
+
: T extends 'number'
|
|
6
|
+
? number
|
|
7
|
+
: T extends 'boolean'
|
|
8
|
+
? boolean
|
|
9
|
+
: T extends 'enum'
|
|
10
|
+
? string | number
|
|
11
|
+
: never;
|
|
12
|
+
|
|
13
|
+
export type LeafBase = {
|
|
14
|
+
kind: 'leaf';
|
|
15
|
+
name: string;
|
|
16
|
+
required?: true | undefined;
|
|
17
|
+
label?: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type AnonLeaf = {
|
|
22
|
+
[K in Leaf['type']]: { type: K };
|
|
23
|
+
}[Leaf['type']];
|
|
24
|
+
|
|
25
|
+
export type LeafString = LeafBase & {
|
|
26
|
+
type: 'string';
|
|
27
|
+
default?: LeafRuntimeType<'string'>;
|
|
28
|
+
};
|
|
29
|
+
export type LeafNumber = LeafBase & {
|
|
30
|
+
type: 'number';
|
|
31
|
+
default?: LeafRuntimeType<'number'>;
|
|
32
|
+
};
|
|
33
|
+
export type LeafBoolean = LeafBase & {
|
|
34
|
+
type: 'boolean';
|
|
35
|
+
default?: LeafRuntimeType<'boolean'>;
|
|
36
|
+
};
|
|
37
|
+
export type LeafEnum = LeafBase & {
|
|
38
|
+
type: 'enum';
|
|
39
|
+
default?: LeafRuntimeType<'enum'>;
|
|
40
|
+
enumLabel?: string[];
|
|
41
|
+
enum: LeafRuntimeType<'enum'>[];
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type Appearance = {
|
|
45
|
+
flatten?: boolean;
|
|
46
|
+
noBorder?: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type Leaf = LeafString | LeafNumber | LeafBoolean | LeafEnum;
|
|
50
|
+
|
|
51
|
+
export type LeafList<TKind extends Leaf['type'] = Leaf['type']> = {
|
|
52
|
+
kind: 'leafList';
|
|
53
|
+
label?: string;
|
|
54
|
+
name: string;
|
|
55
|
+
description?: string;
|
|
56
|
+
default?: Exclude<Leaf['default'], undefined>[];
|
|
57
|
+
type: TKind;
|
|
58
|
+
minItems?: number;
|
|
59
|
+
maxItems?: number;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export type NodeGroupList = {
|
|
63
|
+
kind: 'nodeGroupList';
|
|
64
|
+
name: string;
|
|
65
|
+
label?: string;
|
|
66
|
+
description?: string;
|
|
67
|
+
type: NodeGroup;
|
|
68
|
+
minItems?: number;
|
|
69
|
+
maxItems?: number;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export type NodeGroup = {
|
|
73
|
+
kind: 'nodeGroup';
|
|
74
|
+
name: string;
|
|
75
|
+
subType?: string;
|
|
76
|
+
label?: string;
|
|
77
|
+
root?: boolean;
|
|
78
|
+
description?: string;
|
|
79
|
+
children: Record<string, NodeType>;
|
|
80
|
+
appearance?: Appearance;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export type NodeType = Leaf | LeafList | NodeGroup | NodeGroupList;
|
|
84
|
+
export type DFormControl<T extends NodeType> = T extends Leaf
|
|
85
|
+
? FormControl<LeafRuntimeType<T['type']>>
|
|
86
|
+
: T extends LeafList
|
|
87
|
+
? FormArray<FormControl<LeafRuntimeType<T['type']>>>
|
|
88
|
+
: T extends NodeGroup
|
|
89
|
+
? DFormGroup<T>
|
|
90
|
+
: T extends NodeGroupList
|
|
91
|
+
? FormArray<DFormGroup<T['type']>>
|
|
92
|
+
: never;
|
|
93
|
+
|
|
94
|
+
export type FormGroupType<T extends NodeGroup> = {
|
|
95
|
+
[TChild in keyof T['children']]: DFormControl<T['children'][TChild]>;
|
|
96
|
+
};
|
|
97
|
+
export type DFormGroup<T extends NodeGroup> = FormGroup<FormGroupType<T>>;
|