Skip to content

Commit bee3c82

Browse files
committed
Merge pull request #1105 from formio/expand-embed-lib
Expanding the components to allow for more functionality.
1 parent 56233da commit bee3c82

File tree

7 files changed

+3683
-3880
lines changed

7 files changed

+3683
-3880
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [Unreleased: 8.1.0-rc.1]
6+
- Expanding the components to allow for more functionality
7+
58
## 8.0.0
69
### Changed
710
- Official Release

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"docs:build": "compodoc -p tsconfig.json -n angular-formio -d docs --hideGenerator",
1111
"docs:serve": "npm run docs:build -- -s",
1212
"docs:watch": "npm run docs:build -- -s -w",
13-
"publish": "npm run build:prod && npm publish ./dist/angular-formio --tag=8x",
13+
"publish": "npm run build:prod && npm publish ./dist/angular-formio --tag=rc",
1414
"publish:latest": "npm run build:prod && npm publish ./dist/angular-formio",
1515
"test": "ng test",
1616
"lint": "ng lint",
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Component, ElementRef, Input, ViewChild, Output, EventEmitter, AfterViewInit } from '@angular/core';
2-
import { FormioCore as Formio } from '@formio/js';
2+
import { FormBuilder } from '@formio/js';
3+
import WebformBuilder from '@formio/js/lib/cjs/WebformBuilder';
34

45
@Component({
56
selector: 'formio-builder',
@@ -9,11 +10,59 @@ export class FormioBuilder implements AfterViewInit {
910
@ViewChild('formio') element: ElementRef;
1011
@Input() form?: Object | null;
1112
@Input() options?: Object = {};
12-
@Output() ready = new EventEmitter<Formio>();
13+
@Output() change = new EventEmitter<any>();
14+
@Output() ready = new EventEmitter<any>();
1315
@Output() error = new EventEmitter<any>();
16+
public builder: FormBuilder;
17+
public componentAdding = false;
18+
get instance(): WebformBuilder {
19+
return this.builder.instance;
20+
}
1421
ngAfterViewInit(): void {
15-
Formio.builder(this.element.nativeElement, this.form, this.options).then((builder) => {
16-
this.ready.emit(builder);
22+
this.builder = new FormBuilder(this.element.nativeElement, this.form, this.options);
23+
this.builder.ready.then(() => {
24+
this.instance.on('addComponent', (component, parent, path, index, isNew) => {
25+
if (isNew) {
26+
this.componentAdding = true;
27+
} else {
28+
this.change.emit({
29+
type: 'addComponent',
30+
builder: this.instance,
31+
form: this.instance.schema,
32+
component: component,
33+
parent: parent,
34+
path: path,
35+
index: index
36+
});
37+
this.componentAdding = false;
38+
}
39+
});
40+
this.instance.on('saveComponent', (component, original, parent, path, index, isNew) => {
41+
this.change.emit({
42+
type: this.componentAdding ? 'addComponent' : 'saveComponent',
43+
builder: this.instance,
44+
form: this.instance.schema,
45+
component: component,
46+
originalComponent: original,
47+
parent: parent,
48+
path: path,
49+
index: index,
50+
isNew: isNew || false
51+
});
52+
this.componentAdding = false;
53+
});
54+
this.instance.on('removeComponent', (component, parent, path, index) => {
55+
this.change.emit({
56+
type: 'deleteComponent',
57+
builder: this.instance,
58+
form: this.instance.schema,
59+
component: component,
60+
parent: parent,
61+
path: path,
62+
index: index
63+
});
64+
});
65+
this.ready.emit(this.instance);
1766
}).catch((err) => this.error.emit(err));
1867
}
1968
}
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
11
import { Component, ViewChild, ElementRef, Input, Output, EventEmitter, OnChanges, AfterViewInit } from '@angular/core';
2-
import { FormioCore as Formio } from '@formio/js';
2+
import { FormioCore as Formio, Webform } from '@formio/js';
3+
import { Form, Submission } from '@formio/core/types'
34

45
@Component({
56
selector: 'formio',
67
template: '<div #formio></div>'
78
})
89
export class FormioComponent implements AfterViewInit {
910
@Input() src?: string;
10-
@Input() form?: Object | null;
11-
@Input() submission?: Object | null;
12-
@Input() options?: Object = {};
13-
@Output() ready = new EventEmitter<Formio>();
11+
@Input() form?: Form | null;
12+
@Input() submission?: Submission | null;
13+
@Input() url?: string;
14+
@Input() options?: Webform["options"] = {};
15+
@Output() ready = new EventEmitter<Webform>();
1416
@Output() submit = new EventEmitter<object>();
1517
@Output() error = new EventEmitter<any>();
18+
@Output() change = new EventEmitter<any>();
1619
@ViewChild('formio') element: ElementRef;
20+
public instance: Webform;
1721
ngAfterViewInit(): void {
18-
Formio.createForm(this.element.nativeElement, this.src || this.form, this.options).then((form) => {
22+
Formio.createForm(this.element.nativeElement, this.src || this.form, this.options).then((form: Webform) => {
23+
this.instance = form;
24+
if (this.url) {
25+
form.url = this.url;
26+
}
1927
if (this.submission) {
2028
form.submission = this.submission;
2129
}
2230
this.ready.emit(form);
2331
form.on('submit', (submission) => this.submit.emit(submission));
2432
form.on('error', (err) => this.error.emit(err));
33+
form.on('change', (event) => this.change.emit(event));
2534
}).catch((err) => this.error.emit(err));
2635
}
2736
}

projects/angular-formio/src/formio.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class FormioAppConfig {
1414
apiUrl?: string,
1515
baseUrl?: string,
1616
appUrl?: string,
17-
projectUrl?: string
17+
projectUrl?: string
1818
} = {}) {
1919
this.apiUrl = config.apiUrl || config.baseUrl;
2020
this.appUrl = config.appUrl || config.projectUrl;

projects/angular-formio/src/formio.utils.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RouterModule } from '@angular/router';
2-
import { find, trim, each, intersection } from 'lodash';
2+
import { each } from 'lodash';
33

44
export function extendRouter(Class: any, config: any, ClassRoutes: any) {
55
each(Class.decorators, decorator => {
@@ -11,7 +11,9 @@ export function extendRouter(Class: any, config: any, ClassRoutes: any) {
1111
each(arg.imports, (_import, index) => {
1212
if (
1313
(_import.ngModule && (_import.ngModule.name === 'RouterModule')) ||
14-
(_import.name === 'RouterModule')
14+
(_import.ngModule && (_import.ngModule.name === '_RouterModule')) ||
15+
(_import.name === 'RouterModule') ||
16+
(_import.name === '_RouterModule')
1517
) {
1618
arg.imports[index] = RouterModule.forChild(ClassRoutes(config));
1719
}

0 commit comments

Comments
 (0)