2
2
3
3
A configurable editor for ngx-formly forms.
4
4
5
+ This project uses standalone components.
6
+
5
7
Demo: https://formly-editor.sesan.dev
6
8
7
9
![ Demo Screenshot] ( docs/img/screenshot.png ' Demo Screenshot ')
@@ -12,8 +14,6 @@ Demo: https://formly-editor.sesan.dev
12
14
- Install dependencies: ` npm i `
13
15
- Start app: ` npm start `
14
16
15
- The editor is also published as an [ NPM library] ( https://www.npmjs.com/package/@sesan07/ngx-formly-editor ) . It can be installed with ` npm i @sesan07/ngx-formly-editor `
16
-
17
17
## Setup
18
18
19
19
### Create a config
@@ -57,12 +57,16 @@ const cardWrapperConfig: FieldWrapperOption = {
57
57
};
58
58
59
59
// Configure validator options that can be set
60
- export const validatorOptions: ValidatorOption [] = [{
61
- name: ' Ip' ,
62
- key: ' ip' ,
63
- }];
60
+ export const validatorOptions: ValidatorOption [] = [
61
+ {
62
+ name: ' Ip' ,
63
+ key: ' ip' ,
64
+ }
65
+ ...
66
+ ];
64
67
65
68
export const editorConfig: EditorConfig = {
69
+ id: ' editor' ,
66
70
fieldOptions: [ // Configs for fields or field categories
67
71
{ // A field category
68
72
displayName: ' Input' ,
@@ -74,6 +78,11 @@ export const editorConfig: EditorConfig = {
74
78
],
75
79
wrapperOptions: [cardWrapperConfig ], // configs for wrappers
76
80
validatorOptions: validatorOptions ,
81
+ defaultForm: {
82
+ name: ' Form Zero' ,
83
+ fields: [... ], // Formly field configs
84
+ model: {... }
85
+ },
77
86
};
78
87
```
79
88
@@ -85,60 +94,70 @@ These helper functions can be used to create properties
85
94
- ` createSelectProperty({...}) `
86
95
- ` createTextProperty({...}) `
87
96
88
- ### Import the EditorModule
97
+ ### Provide the Editor config
89
98
90
99
``` typescript
91
- import { NgModule } from ' @angular/core' ;
100
+ import { ApplicationConfig , importProvidersFrom } from ' @angular/core' ;
92
101
import { FormlyModule } from ' @ngx-formly/core' ;
93
- import { FormlyMaterialModule } from ' @ngx-formly/material' ;
94
- import { EditorModule } from ' @sesan07/ngx-formly-editor' ;
95
- import { editorConfig } from ' ./editor.config' ;
96
102
97
- @NgModule ({
98
- ...
99
- imports : [
103
+ import { provideEditor , provideEditorConfig , withConfig } from ' @sesan07/ngx-formly-editor' ;
104
+
105
+ import { editorConfig1 , editorConfig2 } from ' ./editor.config' ;
106
+
107
+ // Single route setup
108
+ export const appConfig: ApplicationConfig = {
109
+ providers: [
110
+ ...
111
+ // Provide the editor and config
112
+ provideEditor (withConfig (editorConfig1 )),
113
+ // Ngx-formly configuration
114
+ importProvidersFrom ([
115
+ FormlyModule .forRoot ({ ... }),
116
+ ]),
100
117
...
101
- FormlyMaterialModule , // Can be replaced with other formly UI modules
102
- FormlyModule .forRoot ({ // Configure formly
103
- ...
104
- validators : [{ name: ' ip' , validation: ipValidator }],
105
- validationMessages: [{ name: ' required' , message: ' This field is required' }],
106
- }),
107
- EditorModule .forRoot (editorConfig ), // Configure the editor
108
118
],
109
- })
110
- export class MyModule {}
119
+ };
120
+
121
+ // Multi route setup
122
+ export const appConfig: ApplicationConfig = {
123
+ providers: [
124
+ ...
125
+ // Provide the editor
126
+ provideEditor (),
127
+ provideRouter ([
128
+ {
129
+ path: ' path1' ,
130
+ // Provide editorConfig1 for path1
131
+ providers: [provideEditorConfig (editorConfig1 )],
132
+ },
133
+ {
134
+ path: ' path2' ,
135
+ // Provide editorConfig2 for path2
136
+ providers: [provideEditorConfig (editorConfig2 )],
137
+ },
138
+ ])
139
+ // Ngx-formly configuration
140
+ importProvidersFrom ([
141
+ FormlyModule .forRoot ({ ... }),
142
+ ]),
143
+ ...
144
+ ],
145
+ };
111
146
```
112
147
113
148
### Use the Editor Component
114
149
115
150
``` typescript
116
151
import { Component } from ' @angular/core' ;
117
- import { IDefaultForm , IStylesConfig , tailwindConfig } from ' @sesan07/ngx-formly-editor' ;
152
+ import { EditorComponent } from ' @sesan07/ngx-formly-editor' ;
118
153
119
154
@Component ({
120
155
selector: ' app-example' ,
121
- template: `
122
- <!-- All inputs are optional -->
123
- <editor-main
124
- [autosaveStorageKey]="'editor-local-storage-key'"
125
- [autosaveDelay]="2000"
126
- [defaultForm]="defaultForm"
127
- [stylesConfig]="tailwindConfig"
128
- >
129
- </editor-main>
130
- ` ,
156
+ template: ` <editor-main></editor-main> ` ,
157
+ standalone: true ,
158
+ imports: [EditorComponent ],
131
159
})
132
- export class ExampleComponent {
133
- // Configuration for the editor's styling system (styling tab on UI) (defaults to tailwindConfig)
134
- // A `bootstrapConfig` is also available, or you can create yours.
135
- tailwindConfig: IStylesConfig = tailwindConfig ;
136
- defaultForm: IDefaultForm = {
137
- name: ' Form Zero' ,
138
- fields: [... ], // Formly field configs
139
- model: {... }
140
- }
141
- }
160
+ export class ExampleComponent {}
142
161
```
143
162
144
163
### Import the editor's styles into your app
0 commit comments