UNPKG

angular-xml-editor

Version:
157 lines (156 loc) 14.7 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ import { Component, Input } from '@angular/core'; import { XmlEditRuleCheckAttributes } from '../../code/xml-rules-check/xmlEditRuleCheckAttributes.class'; import { RuleAttributeTypes } from '../../code/xml-rules-check/xmlRuleAttribut.class'; import { AngularXmlEditorService } from '../../angular-xml-editor.service'; import { Xml2htmlAttributeWorker } from '../../code/xml-html-converter/xml2htmlAttributeWorker.class'; import { Xml2html } from '../../code/xml-html-converter/xml2html.class'; var XmlEditorAttributeEditorComponent = /** @class */ (function () { function XmlEditorAttributeEditorComponent(editorService) { this.editorService = editorService; this.attribTypes = RuleAttributeTypes; this.attributes = []; } Object.defineProperty(XmlEditorAttributeEditorComponent.prototype, "editorContextId", { set: /** * @param {?} value * @return {?} */ function (value) { var _this = this; if (!value) { return; } this.editorContext = this.editorService.getEditorContext(value); this.actualCursorPosChangedSubscription = this.editorContext.actualCursorChanged.subscribe(function (pos) { _this.attributes = _this.GetAttributesForCursorPos(pos.StartPos); _this.elementName = _this.GetElementNameForCursorPos(pos.StartPos); }); }, enumerable: true, configurable: true }); /** * @return {?} */ XmlEditorAttributeEditorComponent.prototype.ngOnInit = /** * @return {?} */ function () { }; /** * @return {?} */ XmlEditorAttributeEditorComponent.prototype.ngOnDestroy = /** * @return {?} */ function () { this.actualCursorPosChangedSubscription.unsubscribe(); }; /** * @param {?} key * @param {?} value * @return {?} */ XmlEditorAttributeEditorComponent.prototype.attributeValueChanged = /** * @param {?} key * @param {?} value * @return {?} */ function (key, value) { if (this.actualElement) { /** @type {?} */ var attribWorker = new Xml2htmlAttributeWorker(this.editorContext.config.rules); attribWorker.writeAttributeToHtml(this.actualElement, key, value); } }; /** * @param {?} pos * @return {?} */ XmlEditorAttributeEditorComponent.prototype.GetElementNameForCursorPos = /** * @param {?} pos * @return {?} */ function (pos) { /** @type {?} */ var rulesCheck = new XmlEditRuleCheckAttributes(this.editorContext.config.xmlSchema); /** @type {?} */ var parentNode = /** @type {?} */ (rulesCheck.getRelevantParentNodeForCursorPos(pos)); if (parentNode) { return Xml2html.getTagNameFromNode(parentNode); } return undefined; }; /** * @param {?} pos * @return {?} */ XmlEditorAttributeEditorComponent.prototype.GetAttributesForCursorPos = /** * @param {?} pos * @return {?} */ function (pos) { /** @type {?} */ var attribWorker = new Xml2htmlAttributeWorker(this.editorContext.config.rules); /** @type {?} */ var rulesCheck = new XmlEditRuleCheckAttributes(this.editorContext.config.xmlSchema); /** @type {?} */ var parentNode = /** @type {?} */ (rulesCheck.getRelevantParentNodeForCursorPos(pos)); this.actualElement = parentNode; if (parentNode) { /** @type {?} */ var allowedAttributes = rulesCheck.AttributesAllowedAtThisCursorPos(pos); return allowedAttributes.map(function (a) { return /** @type {?} */ ({ rules: a, value: attribWorker.getAttributeValueFromHtml(parentNode, a.attribName) }); }); } return []; }; XmlEditorAttributeEditorComponent.decorators = [ { type: Component, args: [{ selector: 'axed-attribute-editor', template: "<div class=\"sws-attribute-editor-toolbar\" *ngIf=\"elementName\">\r\n\r\n <h3>Attributes</h3>\r\n\r\n <div *ngIf=\"attributes.length > 0; else noAttributes\">\r\n <p>Attributes for <b>{{elementName}}</b> element</p>\r\n <div *ngFor=\"let attrib of attributes\">\r\n <span>{{attrib.rules.attribName}}</span>:<br />\r\n\r\n <input type=\"text\" *ngIf=\"attrib.rules.typ === attribTypes.String\" value=\"{{attrib.value}}\"\r\n (input)=\"attributeValueChanged(attrib.rules.attribName, $event.target.value);\">\r\n\r\n <select *ngIf=\"attrib.rules.typ === attribTypes.Enum\" value=\"{{attrib.value}}\"\r\n (input)=\"attributeValueChanged(attrib.rules.attribName, $event.target.value);\">\r\n <option *ngIf=\"attrib.rules.required === false\"></option>\r\n <option *ngFor=\"let value of attrib.rules.fixedValues\">{{value}}</option>\r\n </select>\r\n\r\n </div>\r\n </div>\r\n\r\n <ng-template #noAttributes>\r\n No attributes to edit for element <b>{{elementName}}</b>\r\n </ng-template>\r\n\r\n</div>\r\n", styles: [".sws-attribute-editor-toolbar input,.sws-attribute-editor-toolbar select{width:100%;border-radius:5px;background-color:transparent;padding:.6em 0 .4em;margin-bottom:.3em;border:.5px solid #eee}"] }] } ]; /** @nocollapse */ XmlEditorAttributeEditorComponent.ctorParameters = function () { return [ { type: AngularXmlEditorService } ]; }; XmlEditorAttributeEditorComponent.propDecorators = { editorContextId: [{ type: Input, args: ['editorContextId',] }] }; return XmlEditorAttributeEditorComponent; }()); export { XmlEditorAttributeEditorComponent }; if (false) { /** @type {?} */ XmlEditorAttributeEditorComponent.prototype.editorContext; /** @type {?} */ XmlEditorAttributeEditorComponent.prototype.actualCursorPosChangedSubscription; /** @type {?} */ XmlEditorAttributeEditorComponent.prototype.attribTypes; /** @type {?} */ XmlEditorAttributeEditorComponent.prototype.attributes; /** @type {?} */ XmlEditorAttributeEditorComponent.prototype.elementName; /** @type {?} */ XmlEditorAttributeEditorComponent.prototype.actualElement; /** @type {?} */ XmlEditorAttributeEditorComponent.prototype.editorService; } /** * @record */ export function ToolbarAttributData() { } /** @type {?} */ ToolbarAttributData.prototype.rules; /** @type {?} */ ToolbarAttributData.prototype.value; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoieG1sLWVkaXRvci1hdHRyaWJ1dGUtZWRpdG9yLmNvbXBvbmVudC5qcyIsInNvdXJjZVJvb3QiOiJuZzovL2FuZ3VsYXIteG1sLWVkaXRvci8iLCJzb3VyY2VzIjpbImxpYi9jb21wb25lbnRzL3htbC1lZGl0b3ItYXR0cmlidXRlLWVkaXRvci94bWwtZWRpdG9yLWF0dHJpYnV0ZS1lZGl0b3IuY29tcG9uZW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7QUFBQSxPQUFPLEVBQUUsU0FBUyxFQUFVLEtBQUssRUFBYSxNQUFNLGVBQWUsQ0FBQztBQUVwRSxPQUFPLEVBQUUsMEJBQTBCLEV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