UNPKG

angular2-json-schema-form

Version:
194 lines 8.78 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var core_1 = require("@angular/core"); var add_reference_component_1 = require("./add-reference.component"); var button_component_1 = require("./button.component"); var checkbox_component_1 = require("./checkbox.component"); var checkboxes_component_1 = require("./checkboxes.component"); var fieldset_component_1 = require("./fieldset.component"); var file_component_1 = require("./file.component"); var input_component_1 = require("./input.component"); var message_component_1 = require("./message.component"); var none_component_1 = require("./none.component"); var number_component_1 = require("./number.component"); var radios_component_1 = require("./radios.component"); var root_component_1 = require("./root.component"); var section_component_1 = require("./section.component"); var select_component_1 = require("./select.component"); var select_framework_component_1 = require("./select-framework.component"); var select_widget_component_1 = require("./select-widget.component"); var submit_component_1 = require("./submit.component"); var tabs_component_1 = require("./tabs.component"); var template_component_1 = require("./template.component"); var textarea_component_1 = require("./textarea.component"); var WidgetLibraryService = (function () { function WidgetLibraryService() { this.defaultWidget = 'none'; this.widgetLibrary = { 'none': none_component_1.NoneComponent, 'root': root_component_1.RootComponent, 'select-framework': select_framework_component_1.SelectFrameworkComponent, 'select-widget': select_widget_component_1.SelectWidgetComponent, '$ref': add_reference_component_1.AddReferenceComponent, 'email': 'text', 'integer': 'number', 'number': number_component_1.NumberComponent, 'password': 'text', 'search': 'text', 'tel': 'text', 'text': input_component_1.InputComponent, 'url': 'text', 'color': 'text', 'date': 'text', 'datetime': 'text', 'datetime-local': 'text', 'month': 'text', 'range': 'number', 'time': 'text', 'week': 'text', 'checkbox': checkbox_component_1.CheckboxComponent, 'file': file_component_1.FileComponent, 'hidden': 'text', 'image': 'text', 'radio': 'radios', 'reset': 'submit', 'submit': submit_component_1.SubmitComponent, 'button': button_component_1.ButtonComponent, 'select': select_component_1.SelectComponent, 'textarea': textarea_component_1.TextareaComponent, 'checkboxes': checkboxes_component_1.CheckboxesComponent, 'checkboxes-inline': 'checkboxes', 'checkboxbuttons': 'checkboxes', 'radios': radios_component_1.RadiosComponent, 'radios-inline': 'radios', 'radiobuttons': 'radios', 'fieldset': fieldset_component_1.FieldsetComponent, 'array': 'fieldset', 'tabarray': 'tabs', 'tab': 'fieldset', 'tabs': tabs_component_1.TabsComponent, 'help': message_component_1.MessageComponent, 'message': message_component_1.MessageComponent, 'msg': message_component_1.MessageComponent, 'html': message_component_1.MessageComponent, 'template': template_component_1.TemplateComponent, 'advancedfieldset': 'fieldset', 'authfieldset': 'fieldset', 'optionfieldset': 'fieldset', 'selectfieldset': 'fieldset', 'section': section_component_1.SectionComponent, 'conditional': 'section', 'actions': 'section', 'tagsinput': 'section', 'updown': 'number', 'date-time': 'text', 'alt-datetime': 'text', 'alt-date': 'text', 'wizard': 'section', }; this.registeredWidgets = {}; this.frameworkWidgets = {}; this.activeWidgets = {}; this.setActiveWidgets(); } WidgetLibraryService.prototype.setActiveWidgets = function () { this.activeWidgets = Object.assign({}, this.widgetLibrary, this.frameworkWidgets, this.registeredWidgets); for (var _i = 0, _a = Object.keys(this.activeWidgets); _i < _a.length; _i++) { var widgetName = _a[_i]; var widget = this.activeWidgets[widgetName]; if (typeof widget === 'string') { var usedAliases = []; while (typeof widget === 'string' && usedAliases.indexOf(widget) === -1) { usedAliases.push(widget); widget = this.activeWidgets[widget]; } if (typeof widget !== 'string') { this.activeWidgets[widgetName] = widget; } } } }; WidgetLibraryService.prototype.setDefaultWidget = function (type) { if (!this.hasWidget(type)) return false; this.defaultWidget = type; return true; }; WidgetLibraryService.prototype.hasWidget = function (type, widgetSet) { if (widgetSet === void 0) { widgetSet = 'activeWidgets'; } if (!type || typeof type !== 'string') return false; return this[widgetSet].hasOwnProperty(type); }; WidgetLibraryService.prototype.hasDefaultWidget = function (type) { return this.hasWidget(type, 'widgetLibrary'); }; WidgetLibraryService.prototype.registerWidget = function (type, widget) { if (!type || !widget || typeof type !== 'string') return false; this.registeredWidgets[type] = widget; this.setActiveWidgets(); return true; }; WidgetLibraryService.prototype.unRegisterWidget = function (type) { if (!type || typeof type !== 'string' || !this.registeredWidgets.hasOwnProperty(type)) return false; delete this.registeredWidgets[type]; this.setActiveWidgets(); return true; }; WidgetLibraryService.prototype.unRegisterAllWidgets = function (unRegisterFrameworkWidgets) { if (unRegisterFrameworkWidgets === void 0) { unRegisterFrameworkWidgets = true; } this.registeredWidgets = {}; if (unRegisterFrameworkWidgets) this.frameworkWidgets = {}; this.setActiveWidgets(); return true; }; WidgetLibraryService.prototype.registerFrameworkWidgets = function (widgets) { if (widgets === null || typeof widgets !== 'object') return false; this.frameworkWidgets = widgets; this.setActiveWidgets(); return true; }; WidgetLibraryService.prototype.unRegisterFrameworkWidgets = function () { if (Object.keys(this.frameworkWidgets).length) { this.frameworkWidgets = {}; this.setActiveWidgets(); } return true; }; WidgetLibraryService.prototype.getWidget = function (type, widgetSet) { if (widgetSet === void 0) { widgetSet = 'activeWidgets'; } if (this.hasWidget(type, widgetSet)) return this[widgetSet][type]; if (this.hasWidget(this.defaultWidget, widgetSet)) return this[widgetSet][this.defaultWidget]; return null; }; WidgetLibraryService.prototype.getAllWidgets = function () { return { widgetLibrary: this.widgetLibrary, registeredWidgets: this.registeredWidgets, frameworkWidgets: this.frameworkWidgets, activeWidgets: this.activeWidgets, }; }; return WidgetLibraryService; }()); WidgetLibraryService = __decorate([ core_1.Injectable(), __metadata("design:paramtypes", []) ], WidgetLibraryService); exports.WidgetLibraryService = WidgetLibraryService; //# sourceMappingURL=widget-library.service.js.map