@dimakorotkov/ngx-json-editor
Version:
Angular library for json-editor
1 lines • 6.24 kB
Source Map (JSON)
{"version":3,"file":"dimakorotkov-ngx-json-editor.mjs","sources":["../../../projects/ngx-json-editor/src/lib/ngx-json-editor.service.ts","../../../projects/ngx-json-editor/src/lib/ngx-json-editor.component.ts","../../../projects/ngx-json-editor/src/lib/ngx-json-editor.module.ts","../../../projects/ngx-json-editor/src/public-api.ts","../../../projects/ngx-json-editor/src/dimakorotkov-ngx-json-editor.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class NgxJsonEditorService {\n\n constructor() { }\n}\n","import { Component, ElementRef, forwardRef, Input, OnDestroy, OnInit, ViewChild } from '@angular/core';\nimport { AbstractControl, ControlValueAccessor, NG_VALIDATORS, NG_VALUE_ACCESSOR, ValidationErrors, Validator } from '@angular/forms';\n\n@Component({\n selector: 'dimakorotkov-ngx-json-editor',\n template: `\n <div #container></div>\n `,\n styles: [\n ],\n providers: [\n {\n provide: NG_VALUE_ACCESSOR,\n useExisting: forwardRef(() => NgxJsonEditorComponent),\n multi: true\n },\n {\n provide: NG_VALIDATORS,\n useExisting: NgxJsonEditorComponent, //forwardRef(() => NgxJsonEditorComponent),\n multi: true,\n }\n ],\n})\nexport class NgxJsonEditorComponent implements OnInit, ControlValueAccessor, OnDestroy, Validator {\n\n @Input() options!: JSONEditorOptions<any>;\n\n @ViewChild('container', { static: true }) container!: ElementRef;\n\n private editor?: JSONEditor<any>;\n private onChange?: any;\n private onTouched?: any;\n\n ngOnDestroy(): void {\n if (this.editor) {\n this.editor.destroy();\n delete this.editor;\n }\n }\n\n writeValue(obj: any): void {\n if (this.editor) {\n this.editor.setValue(obj);\n } else {\n throw new Error('Editor was not initalized.');\n }\n }\n\n registerOnChange(fn: any): void {\n this.onChange = fn;\n }\n\n registerOnTouched(fn: any): void {\n this.onTouched = fn;\n }\n\n ngOnInit(): void {\n if (this.container.nativeElement) {\n if (this.options) {\n this.editor = new JSONEditor(this.container.nativeElement, this.options);\n this.editor.on('change', () => {\n if (this.editor && this.onChange) {\n this.onChange(this.editor.getValue());\n }\n });\n } else {\n throw new Error(`Set the options parameter for json-editor.`); \n }\n } else {\n throw new Error(`Can't find the ElementRef reference for json-editor.`);\n }\n }\n\n setDisabledState?(isDisabled: boolean): void {\n if (this.editor) {\n if (isDisabled) {\n this.editor.disable();\n } else {\n this.editor.enable();\n }\n }\n }\n\n validate(control: AbstractControl): ValidationErrors | null {\n let result: ValidationErrors | null = null;\n if (this.editor) {\n const errors = this.editor.validate(control.value);\n if (errors.length) {\n result = {};\n for (let i = 0; i < errors.length; i++) {\n result[i] = errors[i];\n }\n }\n }\n return result;\n }\n\n}\n","import { NgModule } from '@angular/core';\nimport { NgxJsonEditorComponent } from './ngx-json-editor.component';\n\n\n\n@NgModule({\n declarations: [\n NgxJsonEditorComponent\n ],\n imports: [\n ],\n exports: [\n NgxJsonEditorComponent\n ]\n})\nexport class NgxJsonEditorModule { }\n","/*\n * Public API Surface of ngx-json-editor\n */\n\nexport * from './lib/ngx-json-editor.service';\nexport * from './lib/ngx-json-editor.component';\nexport * from './lib/ngx-json-editor.module';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;MAKa,oBAAoB;IAE/B,iBAAiB;;iHAFN,oBAAoB;qHAApB,oBAAoB,cAFnB,MAAM;2FAEP,oBAAoB;kBAHhC,UAAU;mBAAC;oBACV,UAAU,EAAE,MAAM;iBACnB;;;MCmBY,sBAAsB;IAUjC,WAAW;QACT,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC,MAAM,CAAC;SACpB;KACF;IAED,UAAU,CAAC,GAAQ;QACjB,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;SAC3B;aAAM;YAC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