UNPKG

angular2-json-schema-form

Version:
191 lines 10.3 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 widget_library_service_1 = require("../widgets/widget-library.service"); var no_framework_component_1 = require("./no-framework.component"); var material_design_component_1 = require("./material-design/material-design.component"); var material_add_reference_component_1 = require("./material-design/material-add-reference.component"); var material_button_component_1 = require("./material-design/material-button.component"); var material_card_component_1 = require("./material-design/material-card.component"); var material_checkbox_component_1 = require("./material-design/material-checkbox.component"); var material_checkboxes_component_1 = require("./material-design/material-checkboxes.component"); var material_file_component_1 = require("./material-design/material-file.component"); var material_input_component_1 = require("./material-design/material-input.component"); var material_number_component_1 = require("./material-design/material-number.component"); var material_radios_component_1 = require("./material-design/material-radios.component"); var material_select_component_1 = require("./material-design/material-select.component"); var material_tabs_component_1 = require("./material-design/material-tabs.component"); var material_textarea_component_1 = require("./material-design/material-textarea.component"); var bootstrap_3_component_1 = require("./bootstrap-3.component"); var bootstrap_4_component_1 = require("./bootstrap-4.component"); var foundation_6_component_1 = require("./foundation-6.component"); var semantic_ui_component_1 = require("./semantic-ui.component"); var FrameworkLibraryService = (function () { function FrameworkLibraryService(widgetLibrary) { this.widgetLibrary = widgetLibrary; this.activeFramework = null; this.loadExternalAssets = false; this.defaultFramework = 'bootstrap-3'; this.frameworkLibrary = { 'no-framework': { framework: no_framework_component_1.NoFrameworkComponent }, 'material-design': { framework: material_design_component_1.MaterialDesignComponent, widgets: { '$ref': material_add_reference_component_1.MaterialAddReferenceComponent, 'number': material_number_component_1.MaterialNumberComponent, 'text': material_input_component_1.MaterialInputComponent, 'file': material_file_component_1.MaterialFileComponent, 'checkbox': material_checkbox_component_1.MaterialCheckboxComponent, 'submit': 'button', 'button': material_button_component_1.MaterialButtonComponent, 'select': material_select_component_1.MaterialSelectComponent, 'textarea': material_textarea_component_1.MaterialTextareaComponent, 'checkboxes': material_checkboxes_component_1.MaterialCheckboxesComponent, 'radios': material_radios_component_1.MaterialRadiosComponent, 'card': material_card_component_1.MaterialCardComponent, 'tabs': material_tabs_component_1.MaterialTabsComponent, }, stylesheets: [ '//fonts.googleapis.com/icon?family=Material+Icons', '//fonts.googleapis.com/css?family=Roboto:300,400,500,700', '//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css', './node_modules/@angular/material/core/theming/prebuilt/indigo-pink.css', ], }, 'bootstrap-3': { framework: bootstrap_3_component_1.Bootstrap3Component, stylesheets: [ '//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css', ], scripts: [ '//ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js', '//ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', ], }, 'bootstrap-4': { framework: bootstrap_4_component_1.Bootstrap4Component, }, 'foundation-6': { framework: foundation_6_component_1.Foundation6Component, }, 'smantic-ui': { framework: semantic_ui_component_1.SemanticUIComponent, }, }; } FrameworkLibraryService.prototype.registerFrameworkWidgets = function (framework) { if (framework.hasOwnProperty('widgets')) { this.widgetLibrary.registerFrameworkWidgets(framework.widgets); return true; } this.widgetLibrary.unRegisterFrameworkWidgets(); return false; }; FrameworkLibraryService.prototype.unloadFrameworkExternalAssets = function () { for (var _i = 0, _a = (this.scripts || []).concat((this.stylesheets || [])); _i < _a.length; _i++) { var node = _a[_i]; node.parentNode.removeChild(node); } this.scripts = []; this.stylesheets = []; }; FrameworkLibraryService.prototype.loadFrameworkExternalAssets = function (framework) { this.unloadFrameworkExternalAssets(); if (framework.hasOwnProperty('scripts')) { for (var _i = 0, _a = framework.scripts; _i < _a.length; _i++) { var script = _a[_i]; var newScript = document.createElement('script'); if (script.slice(0, 1) === '/' || script.slice(0, 2) === './' || script.slice(0, 4) === 'http') { newScript.src = script; } else { newScript.innerHTML = script; } this.scripts.push(newScript); document.head.appendChild(newScript); } } if (framework.hasOwnProperty('stylesheets')) { for (var _b = 0, _c = framework.stylesheets; _b < _c.length; _b++) { var stylesheet = _c[_b]; var newStylesheet = void 0; if (stylesheet.slice(0, 1) === '/' || stylesheet.slice(0, 2) === './' || stylesheet.slice(0, 4) === 'http') { newStylesheet = document.createElement('link'); newStylesheet.rel = 'stylesheet'; newStylesheet.href = stylesheet; } else { newStylesheet = document.createElement('style'); newStylesheet.innerHTML = stylesheet; } this.stylesheets.push(newStylesheet); document.head.appendChild(newStylesheet); } } return !!(framework.stylesheets || framework.scripts); }; FrameworkLibraryService.prototype.setLoadExternalAssets = function (loadExternalAssets) { if (loadExternalAssets === void 0) { loadExternalAssets = true; } this.loadExternalAssets = !!loadExternalAssets; }; FrameworkLibraryService.prototype.setFramework = function (framework, loadExternalAssets) { if (loadExternalAssets === void 0) { loadExternalAssets = this.loadExternalAssets; } if (!framework) return false; var validNewFramework = false; if (!framework || framework === 'default') { this.activeFramework = this.frameworkLibrary[this.defaultFramework]; validNewFramework = true; } else if (typeof framework === 'string' && this.hasFramework(framework)) { this.activeFramework = this.frameworkLibrary[framework]; validNewFramework = true; } else if (typeof framework === 'object' && framework.hasOwnProperty('framework')) { this.activeFramework = framework; validNewFramework = true; } if (validNewFramework) { this.registerFrameworkWidgets(this.activeFramework); if (loadExternalAssets) { this.loadFrameworkExternalAssets(this.activeFramework); } else { this.unloadFrameworkExternalAssets(); } } return validNewFramework; }; FrameworkLibraryService.prototype.hasFramework = function (type) { if (!type || typeof type !== 'string') return false; return this.frameworkLibrary.hasOwnProperty(type); }; FrameworkLibraryService.prototype.getFramework = function () { if (!this.activeFramework) this.setFramework('default', true); return this.activeFramework.framework; }; FrameworkLibraryService.prototype.getFrameworkWidgets = function () { return this.activeFramework.widgets || {}; }; FrameworkLibraryService.prototype.getFrameworkStylesheets = function () { return this.activeFramework.stylesheets || []; }; FrameworkLibraryService.prototype.getFrameworkScritps = function () { return this.activeFramework.scripts || []; }; return FrameworkLibraryService; }()); FrameworkLibraryService = __decorate([ core_1.Injectable(), __metadata("design:paramtypes", [widget_library_service_1.WidgetLibraryService]) ], FrameworkLibraryService); exports.FrameworkLibraryService = FrameworkLibraryService; //# sourceMappingURL=framework-library.service.js.map