UNPKG

@formio/angular

Version:

This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 10.1.4.

242 lines (235 loc) 10.1 kB
import { FormioCore, FormBuilder } from '@formio/js'; export { FormioCore as Formio } from '@formio/js'; import * as i0 from '@angular/core'; import { EventEmitter, ViewChild, Output, Input, Component, InjectionToken, Inject, Injectable, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; class FormioComponent { src; form; submission; url; options = {}; ready = new EventEmitter(); submit = new EventEmitter(); error = new EventEmitter(); change = new EventEmitter(); element; instance; ngAfterViewInit() { FormioCore.createForm(this.element.nativeElement, this.src || this.form, this.options).then((form) => { this.instance = form; if (this.url) { form.url = this.url; } if (this.submission) { form.submission = this.submission; } this.ready.emit(form); form.on('submit', (submission) => this.submit.emit(submission)); form.on('error', (err) => this.error.emit(err)); form.on('change', (event) => this.change.emit(event)); }).catch((err) => this.error.emit(err)); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: FormioComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.14", type: FormioComponent, isStandalone: false, selector: "formio", inputs: { src: "src", form: "form", submission: "submission", url: "url", options: "options" }, outputs: { ready: "ready", submit: "submit", error: "error", change: "change" }, viewQueries: [{ propertyName: "element", first: true, predicate: ["formio"], descendants: true }], ngImport: i0, template: '<div #formio></div>', isInline: true }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: FormioComponent, decorators: [{ type: Component, args: [{ selector: 'formio', template: '<div #formio></div>', standalone: false }] }], propDecorators: { src: [{ type: Input }], form: [{ type: Input }], submission: [{ type: Input }], url: [{ type: Input }], options: [{ type: Input }], ready: [{ type: Output }], submit: [{ type: Output }], error: [{ type: Output }], change: [{ type: Output }], element: [{ type: ViewChild, args: ['formio'] }] } }); class FormioBuilder { element; form; options = {}; change = new EventEmitter(); ready = new EventEmitter(); error = new EventEmitter(); builder; componentAdding = false; get instance() { return this.builder.instance; } ngAfterViewInit() { this.builder = new FormBuilder(this.element.nativeElement, this.form, this.options); this.builder.ready.then(() => { this.instance.on('addComponent', (component, parent, path, index, isNew) => { if (isNew) { this.componentAdding = true; } else { this.change.emit({ type: 'addComponent', builder: this.instance, form: this.instance.schema, component: component, parent: parent, path: path, index: index }); this.componentAdding = false; } }); this.instance.on('saveComponent', (component, original, parent, path, index, isNew) => { this.change.emit({ type: this.componentAdding ? 'addComponent' : 'saveComponent', builder: this.instance, form: this.instance.schema, component: component, originalComponent: original, parent: parent, path: path, index: index, isNew: isNew || false }); this.componentAdding = false; }); this.instance.on('removeComponent', (component, parent, path, index) => { this.change.emit({ type: 'deleteComponent', builder: this.instance, form: this.instance.schema, component: component, parent: parent, path: path, index: index }); }); this.ready.emit(this.instance); }).catch((err) => this.error.emit(err)); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: FormioBuilder, deps: [], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.14", type: FormioBuilder, isStandalone: false, selector: "formio-builder", inputs: { form: "form", options: "options" }, outputs: { change: "change", ready: "ready", error: "error" }, viewQueries: [{ propertyName: "element", first: true, predicate: ["formio"], descendants: true }], ngImport: i0, template: '<div #formio></div>', isInline: true }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: FormioBuilder, decorators: [{ type: Component, args: [{ selector: 'formio-builder', template: '<div #formio></div>', standalone: false }] }], propDecorators: { element: [{ type: ViewChild, args: ['formio'] }], form: [{ type: Input }], options: [{ type: Input }], change: [{ type: Output }], ready: [{ type: Output }], error: [{ type: Output }] } }); const FormioAppConfig = new InjectionToken('formio-config'); class FormioAppService { baseUrl; apiUrl; projectUrl; appUrl; icons; formio; user; onUser = new EventEmitter(); constructor(config = {}) { this.baseUrl = this.apiUrl = config.apiUrl || config.baseUrl; this.projectUrl = this.appUrl = config.appUrl || config.projectUrl; if (this.baseUrl) { FormioCore.setBaseUrl(this.baseUrl); FormioCore.setProjectUrl(this.projectUrl); if (config.icons) { FormioCore.icons = config.icons; } if (config.config) { for (let key in config.config) { FormioCore.config[key] = config.config[key]; } } FormioCore.events.on('formio.user', (user) => this.setUser(user)); this.formio = new FormioCore(this.projectUrl); this.authenticate(); } } setUser(user) { this.user = user; this.onUser.emit(user); } logout() { return FormioCore.logout().then(() => { this.setUser(null); FormioCore.clearCache(); }).catch(() => { this.setUser(null); FormioCore.clearCache(); }); } authenticate() { return this.formio.currentUser().then((user) => this.setUser(user)).catch(() => this.setUser(null)); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: FormioAppService, deps: [{ token: FormioAppConfig }], target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: FormioAppService }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: FormioAppService, decorators: [{ type: Injectable }], ctorParameters: () => [{ type: undefined, decorators: [{ type: Inject, args: [FormioAppConfig] }] }] }); class FormioEmbedModule { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: FormioEmbedModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.14", ngImport: i0, type: FormioEmbedModule, declarations: [FormioComponent, FormioBuilder], imports: [CommonModule], exports: [FormioComponent, FormioBuilder] }); static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: FormioEmbedModule, providers: [ FormioAppService ], imports: [CommonModule] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: FormioEmbedModule, decorators: [{ type: NgModule, args: [{ imports: [ CommonModule ], declarations: [ FormioComponent, FormioBuilder ], exports: [ FormioComponent, FormioBuilder ], providers: [ FormioAppService ] }] }] }); /** * Generated bundle index. Do not edit. */ export { FormioAppConfig, FormioAppService, FormioBuilder, FormioComponent, FormioEmbedModule }; //# sourceMappingURL=formio-angular-embed.mjs.map