blob: d7b6331b2e08961f0fb540b068bf459aa85eaa3e [file] [log] [blame]
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/common"),require("@angular/material/tooltip"),require("@angular/material/icon"),require("@angular/core"),require("@angular/cdk/bidi"),require("@covalent/core/common")):"function"==typeof define&&define.amd?define("@covalent/core/json-formatter",["exports","@angular/common","@angular/material/tooltip","@angular/material/icon","@angular/core","@angular/cdk/bidi","@covalent/core/common"],t):t((e.covalent=e.covalent||{},e.covalent.core=e.covalent.core||{},e.covalent.core["json-formatter"]={}),e.ng.common,e.ng.material.tooltip,e.ng.material.icon,e.ng.core,e.ng.cdk.bidi,e.covalent.core.common)}(this,function(e,t,r,n,o,a,i){"use strict";var d=(Object.defineProperty(s.prototype,"levelsOpen",{get:function(){return this._levelsOpen},set:function(e){if(!Number.isInteger(e))throw new Error("[levelsOpen] needs to be an integer.");this._levelsOpen=e,this._open=0<e},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"open",{get:function(){return this._open},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"key",{get:function(){var e=this._key&&this._key.length>s.KEY_MAX_LENGTH?"…":"";return this._key?this._key.substring(0,s.KEY_MAX_LENGTH)+e:this._key},set:function(e){this._key=e},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"data",{get:function(){return this._data},set:function(e){this._data=e,this.parseChildren()},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"children",{get:function(){return this._children},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"isRTL",{get:function(){return!!this._dir&&"rtl"===this._dir.dir},enumerable:!0,configurable:!0}),s.prototype.refresh=function(){this._changeDetectorRef.markForCheck()},s.prototype.toggle=function(){this._open=!this._open},s.prototype.isObject=function(){return"object"===this.getType(this._data)},s.prototype.isArray=function(){return Array.isArray(this._data)},s.prototype.hasChildren=function(){return this._children&&0<this._children.length},s.prototype.getValue=function(e){var t=this.getType(e);if("undefined"===t||"null"===t)return t;if("date"===t)e=new Date(e).toString();else if("string"===t)e='"'+e+'"';else{if("function"===t)return e.toString().replace(/[\r\n]/g,"").replace(/\{.*\}/,"")+"{…}";if(Array.isArray(e))return this.getObjectName()+" ["+e.length+"]"}return e},s.prototype.getType=function(e){if("object"==typeof e){if(!e)return"null";if(Array.isArray(e))return"object";var t=new Date(e);if("[object Date]"===Object.prototype.toString.call(t)&&!Number.isNaN(t.getTime()))return"date"}return typeof e},s.prototype.getObjectName=function(){var e=this._data;if(this.isObject()&&!e.constructor)return"Object";var t=/function (.{1,})\(/.exec(e.constructor.toString());return t&&1<t.length?t[1]:""},s.prototype.getPreview=function(){var e,t=this,r="{ ",n=" }";this.isArray()?(e=this._data.slice(0,s.PREVIEW_LIMIT).map(function(e){return t.getValue(e)}),r="[",n="]"):e=this._children.slice(0,s.PREVIEW_LIMIT).map(function(e){return e+": "+t.getValue(t._data[e])});var o=e.join(", "),a=e.length>=s.PREVIEW_LIMIT||o.length>s.PREVIEW_STRING_MAX_LENGTH?"…":"";return r+o.substring(0,s.PREVIEW_STRING_MAX_LENGTH)+a+n},s.prototype.parseChildren=function(){if(this.isObject())for(var e in this._children=[],this._data)this._children.push(e)},s.KEY_MAX_LENGTH=30,s.PREVIEW_STRING_MAX_LENGTH=80,s.PREVIEW_LIMIT=5,s.decorators=[{type:o.Component,args:[{changeDetection:o.ChangeDetectionStrategy.OnPush,selector:"td-json-formatter",template:'<div class="td-json-formatter-wrapper">\n <a class="td-key"\n [class.td-key-node]="hasChildren()"\n [class.td-key-leaf]="!hasChildren()"\n [tabIndex]="isObject()? 0 : -1"\n (keydown.enter)="toggle()"\n (click)="toggle()">\n <mat-icon class="td-node-icon" *ngIf="hasChildren()">{{open? \'keyboard_arrow_down\' : (isRTL ? \'keyboard_arrow_left\' : \'keyboard_arrow_right\')}}</mat-icon>\n <span *ngIf="key" class="key">{{key}}:</span>\n <span class="value">\n <span [class.td-empty]="!hasChildren()" *ngIf="isObject()" [matTooltip]="getPreview()" matTooltipPosition="after">\n <span class="td-object-name">{{getObjectName()}}</span>\n <span class="td-array-length" *ngIf="isArray()">[{{data.length}}]</span>\n </span>\n <span *ngIf="!isObject()" [class]="getType(data)">{{getValue(data)}}</span>\n </span>\n </a>\n <div class="td-object-children" [@tdCollapse]="!(hasChildren() && open)">\n <ng-template let-key ngFor [ngForOf]="children">\n <td-json-formatter [key]="key" [data]="data[key]" [levelsOpen]="levelsOpen - 1"></td-json-formatter>\n </ng-template>\n </div>\n</div>',animations:[i.tdCollapseAnimation],styles:[":host{display:block}.td-json-formatter-wrapper{padding-top:2px;padding-bottom:2px}.td-json-formatter-wrapper .td-key{-webkit-box-sizing:border-box;box-sizing:border-box;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-orient:horizontal;-webkit-box-direction:normal;-ms-flex-direction:row;flex-direction:row;-webkit-box-align:start;-ms-flex-align:start;align-items:flex-start;-ms-flex-line-pack:center;align-content:center;max-width:100%;-webkit-box-pack:start;-ms-flex-pack:start;justify-content:flex-start}.td-json-formatter-wrapper .td-key.td-key-node:hover{cursor:pointer}.td-json-formatter-wrapper .td-object-children.ng-animating{overflow:hidden}.td-json-formatter-wrapper .td-object-children .td-key,.td-json-formatter-wrapper .td-object-children .td-object-children{padding-left:24px}::ng-deep [dir=rtl] .td-json-formatter-wrapper .td-object-children .td-key,::ng-deep [dir=rtl] .td-json-formatter-wrapper .td-object-children .td-object-children{padding-right:24px;padding-left:0}.td-json-formatter-wrapper .td-object-children .td-key.td-key-leaf,.td-json-formatter-wrapper .td-object-children .td-object-children.td-key-leaf{padding-left:48px}::ng-deep [dir=rtl] .td-json-formatter-wrapper .td-object-children .td-key.td-key-leaf,::ng-deep [dir=rtl] .td-json-formatter-wrapper .td-object-children .td-object-children.td-key-leaf{padding-right:48px;padding-left:0}.td-json-formatter-wrapper .value{margin-left:5px}::ng-deep [dir=rtl] .td-json-formatter-wrapper .value{padding-right:5px;padding-left:0}.td-json-formatter-wrapper .value .td-empty{opacity:.5;text-decoration:line-through}.td-json-formatter-wrapper .value .date,.td-json-formatter-wrapper .value .string{word-break:break-word}"]}]}],s.ctorParameters=function(){return[{type:o.ChangeDetectorRef},{type:a.Dir,decorators:[{type:o.Optional}]}]},s.propDecorators={levelsOpen:[{type:o.Input,args:["levelsOpen"]}],key:[{type:o.Input,args:["key"]}],data:[{type:o.Input,args:["data"]}]},s);function s(e,t){this._changeDetectorRef=e,this._dir=t,this._open=!1,this._levelsOpen=0}var l=(p.decorators=[{type:o.NgModule,args:[{imports:[t.CommonModule,r.MatTooltipModule,n.MatIconModule],declarations:[d],exports:[d]}]}],p);function p(){}e.CovalentJsonFormatterModule=l,e.TdJsonFormatterComponent=d,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=covalent-core-json-formatter.umd.min.js.map