ees-jsoneditor 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +183 -0
  3. package/angular.json +169 -0
  4. package/e2e/app.e2e-spec.ts +17 -0
  5. package/e2e/app.po.ts +11 -0
  6. package/e2e/tsconfig.e2e.json +12 -0
  7. package/package.json +79 -0
  8. package/projects/ees-jsoneditor/.eslintrc.json +37 -0
  9. package/projects/ees-jsoneditor/README.md +200 -0
  10. package/projects/ees-jsoneditor/ng-package.json +7 -0
  11. package/projects/ees-jsoneditor/package.json +27 -0
  12. package/projects/ees-jsoneditor/src/lib/jsoneditor.component.spec.ts +25 -0
  13. package/projects/ees-jsoneditor/src/lib/jsoneditor.component.ts +269 -0
  14. package/projects/ees-jsoneditor/src/lib/jsoneditoroptions.ts +166 -0
  15. package/projects/ees-jsoneditor/src/public-api.ts +6 -0
  16. package/projects/ees-jsoneditor/tsconfig.lib.json +14 -0
  17. package/projects/ees-jsoneditor/tsconfig.lib.prod.json +10 -0
  18. package/projects/ees-jsoneditor/tsconfig.spec.json +14 -0
  19. package/renovate.json +38 -0
  20. package/src/app/app.component.css +0 -0
  21. package/src/app/app.component.html +6 -0
  22. package/src/app/app.component.spec.ts +27 -0
  23. package/src/app/app.component.ts +13 -0
  24. package/src/app/app.config.ts +8 -0
  25. package/src/app/app.routes.ts +7 -0
  26. package/src/app/demo/demo.component.css +1 -0
  27. package/src/app/demo/demo.component.html +65 -0
  28. package/src/app/demo/demo.component.spec.ts +31 -0
  29. package/src/app/demo/demo.component.ts +211 -0
  30. package/src/app/demo/schema.value.ts +111 -0
  31. package/src/app/demo/show.component.ts +15 -0
  32. package/src/assets/.gitkeep +0 -0
  33. package/src/assets/printDemo.png +0 -0
  34. package/src/environments/environment.prod.ts +3 -0
  35. package/src/environments/environment.ts +8 -0
  36. package/src/favicon.ico +0 -0
  37. package/src/index.html +14 -0
  38. package/src/main.ts +6 -0
  39. package/src/styles.scss +2 -0
  40. package/tsconfig.app.json +14 -0
  41. package/tsconfig.json +39 -0
  42. package/tsconfig.spec.json +14 -0
@@ -0,0 +1,14 @@
1
+ /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
+ {
3
+ "extends": "../../tsconfig.json",
4
+ "compilerOptions": {
5
+ "outDir": "../../out-tsc/lib",
6
+ "declaration": true,
7
+ "declarationMap": true,
8
+ "inlineSources": true,
9
+ "types": []
10
+ },
11
+ "exclude": [
12
+ "**/*.spec.ts"
13
+ ]
14
+ }
@@ -0,0 +1,10 @@
1
+ /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
+ {
3
+ "extends": "./tsconfig.lib.json",
4
+ "compilerOptions": {
5
+ "declarationMap": false
6
+ },
7
+ "angularCompilerOptions": {
8
+ "compilationMode": "partial"
9
+ }
10
+ }
@@ -0,0 +1,14 @@
1
+ /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
+ {
3
+ "extends": "../../tsconfig.json",
4
+ "compilerOptions": {
5
+ "outDir": "../../out-tsc/spec",
6
+ "types": [
7
+ "jasmine"
8
+ ]
9
+ },
10
+ "include": [
11
+ "**/*.spec.ts",
12
+ "**/*.d.ts"
13
+ ]
14
+ }
package/renovate.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "pinVersions": false,
3
+ "ignoreUnstable": false,
4
+ "semanticCommits": true,
5
+ "semanticPrefix": "build:",
6
+ "commitMessage": "{{semanticPrefix}}update {{depName}} to version {{newVersion}}",
7
+ "packageFiles": [
8
+ "package.json",
9
+ "ees-jsoneditor/package.json"
10
+ ],
11
+ "packages": [
12
+ {
13
+ "packagePattern": "^@angular\/.*",
14
+ "groupName": "angular",
15
+ "pinVersions": false
16
+ },
17
+ {
18
+ "packagePattern": "^@types\/.*",
19
+ "groupName": "type definitions",
20
+ "pinVersions": false
21
+ },
22
+ {
23
+ "packagePattern": "^jasmine.*",
24
+ "groupName": "jasmine",
25
+ "pinVersions": false
26
+ },
27
+ {
28
+ "packagePattern": "^karma.*",
29
+ "groupName": "karma",
30
+ "pinVersions": false
31
+ },
32
+ {
33
+ "packagePattern": "^protractor.*",
34
+ "groupName": "protractor",
35
+ "pinVersions": false
36
+ }
37
+ ]
38
+ }
File without changes
@@ -0,0 +1,6 @@
1
+ <div style="text-align:center">
2
+ <h1>
3
+ Welcome to Angular Json Editor
4
+ </h1>
5
+ </div>
6
+ <router-outlet></router-outlet>
@@ -0,0 +1,27 @@
1
+ import { TestBed, waitForAsync } from '@angular/core/testing';
2
+ import {
3
+ RouterTestingModule
4
+ } from '@angular/router/testing';
5
+ import { AppComponent } from './app.component';
6
+ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
7
+ import { routes } from './app.routes';
8
+
9
+ describe('AppComponent', () => {
10
+ beforeEach(waitForAsync(() => {
11
+ TestBed.configureTestingModule({
12
+ imports: [
13
+ RouterTestingModule.withRoutes(routes),
14
+ FormsModule,
15
+ ReactiveFormsModule,
16
+ AppComponent
17
+ ]
18
+ }).compileComponents();
19
+ }));
20
+
21
+ it('should create the app', waitForAsync(() => {
22
+ const fixture = TestBed.createComponent(AppComponent);
23
+ const app = fixture.debugElement.componentInstance;
24
+ expect(app).toBeTruthy();
25
+ }));
26
+
27
+ });
@@ -0,0 +1,13 @@
1
+ import { Component } from '@angular/core';
2
+ import { RouterOutlet } from '@angular/router';
3
+
4
+ @Component({
5
+ standalone: true,
6
+ imports: [RouterOutlet],
7
+ selector: 'app-root',
8
+ templateUrl: './app.component.html',
9
+ styleUrls: ['./app.component.css']
10
+ })
11
+ export class AppComponent {
12
+ title = 'app';
13
+ }
@@ -0,0 +1,8 @@
1
+ import { ApplicationConfig } from '@angular/core';
2
+ import { provideRouter } from '@angular/router';
3
+
4
+ import { routes } from './app.routes';
5
+
6
+ export const appConfig: ApplicationConfig = {
7
+ providers: [provideRouter(routes)]
8
+ };
@@ -0,0 +1,7 @@
1
+ import { Routes } from '@angular/router';
2
+ import { DemoComponent } from './demo/demo.component';
3
+
4
+ export const routes: Routes = [
5
+ { path: '', redirectTo: '/demo', pathMatch: 'full' },
6
+ { path: 'demo', component: DemoComponent }
7
+ ];
@@ -0,0 +1 @@
1
+ json-editor>div {height: 100%;}
@@ -0,0 +1,65 @@
1
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.6/ace.js"></script>
2
+
3
+ <h2>Options</h2>
4
+
5
+ <h3>Language</h3>
6
+ <button (click)="setLanguage('en')">Language EN</button>
7
+ <button (click)="setLanguage('pt-BR')">Language PT</button>
8
+ <button (click)="customLanguage()">Language Custom</button>
9
+ <hr />
10
+
11
+ <h3>Live Reload</h3>
12
+ <button (click)="changeData()">New Data</button>
13
+ <!-- <button (click)="changeObject()">Change Data</button> -->
14
+ Random Number: {{data.randomNumber}}
15
+
16
+ <h3>Custom Options</h3>
17
+ <button (click)="setAce()">Customize Ace</button>
18
+ <button (click)="toggleNav()">Navigation Bar</button>
19
+ <button (click)="toggleStatus()">Status Bar</button>
20
+
21
+
22
+ <hr />
23
+
24
+ <h3 *ngIf="editorOptions.language">Force Language to {{editorOptions.language}}</h3>
25
+
26
+ <h3>Example with (change)</h3>
27
+ <div style="height:600px;">
28
+ <json-editor [options]="editorOptions" (change)="changeLog($event)" [data]="data" #editor></json-editor>
29
+ <app-show [data]="showData"></app-show>
30
+ </div>
31
+
32
+
33
+
34
+ <h3>Using options and data variable </h3>
35
+
36
+ <div style="height:300px;">
37
+ <form [formGroup]="form" (submit)="submit()">
38
+ <json-editor [options]="editorOptions2" formControlName="myinput" #editorTwo></json-editor>
39
+ <div *ngIf="formData">
40
+ <h4>Form submitted</h4>
41
+ {{ formData }}
42
+ </div>
43
+ <button>Submit</button>
44
+ </form>
45
+ </div>
46
+
47
+
48
+ <h2>Multi json in a loop</h2>
49
+ <button (click)="show=!show">Show/Hide Json Editors</button>
50
+ <div *ngIf="show === true">
51
+ <div *ngFor="let prd of dataMulti.products" class="w-100-p p-24">
52
+ <json-editor [options]="makeOptions()" [data]="prd" (change)="showJson($event)" ></json-editor>
53
+ </div>
54
+ </div>
55
+
56
+
57
+ <table>
58
+ <tr>
59
+ <td>Last edit data</td>
60
+ </tr>
61
+ <tr>
62
+ <td>{{editedData}}</td>
63
+ </tr>
64
+ </table>
65
+ <hr>
@@ -0,0 +1,31 @@
1
+ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
2
+ import { InfinityJsonEditorComponent } from 'ees-jsoneditor';
3
+ import { DemoComponent } from './demo.component';
4
+ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
5
+
6
+ describe('DemoComponent', () => {
7
+ let component: DemoComponent;
8
+ let fixture: ComponentFixture<DemoComponent>;
9
+
10
+ beforeEach(waitForAsync(() => {
11
+ TestBed.configureTestingModule({
12
+ imports: [
13
+ InfinityJsonEditorComponent,
14
+ FormsModule,
15
+ ReactiveFormsModule,
16
+ DemoComponent
17
+ ],
18
+ })
19
+ .compileComponents();
20
+ }));
21
+
22
+ beforeEach(() => {
23
+ fixture = TestBed.createComponent(DemoComponent);
24
+ component = fixture.componentInstance;
25
+ fixture.detectChanges();
26
+ });
27
+
28
+ it('should be created', () => {
29
+ expect(component).toBeTruthy();
30
+ });
31
+ });
@@ -0,0 +1,211 @@
1
+ import { Component, OnInit, ViewChild } from '@angular/core';
2
+ import { InfinityJsonEditorComponent, JsonEditorOptions } from '../../../projects/ees-jsoneditor/src/public-api';
3
+ import { ReactiveFormsModule, UntypedFormBuilder } from '@angular/forms';
4
+ import { schema } from './schema.value';
5
+ import { ShowComponent } from './show.component';
6
+ import { CommonModule } from '@angular/common';
7
+
8
+ @Component({
9
+ standalone: true,
10
+ imports: [CommonModule, ReactiveFormsModule, InfinityJsonEditorComponent, ShowComponent],
11
+ selector: 'app-demo',
12
+ templateUrl: './demo.component.html',
13
+ styleUrls: ['./demo.component.css']
14
+ })
15
+ export class DemoComponent implements OnInit {
16
+
17
+ @ViewChild('editor', { static: false }) editor: InfinityJsonEditorComponent;
18
+ @ViewChild('editorTwo', { static: false }) editorTwo: InfinityJsonEditorComponent;
19
+
20
+ public editorOptions: JsonEditorOptions;
21
+ public data: any;
22
+
23
+ public editorOptions2: JsonEditorOptions;
24
+ public data2: any;
25
+
26
+ public showData;
27
+ public editedData;
28
+ public show = false;
29
+ public form;
30
+ public formData;
31
+
32
+ dataMulti: any = {
33
+ products: [{
34
+ name: 'car',
35
+ product: [{
36
+ name: 'honda',
37
+ model: [
38
+ { id: 'civic', name: 'civic' },
39
+ { id: 'accord', name: 'accord' },
40
+ { id: 'crv', name: 'crv' },
41
+ { id: 'pilot', name: 'pilot' },
42
+ { id: 'odyssey', name: 'odyssey' }
43
+ ]
44
+ }]
45
+ },
46
+ {
47
+ name: 'book',
48
+ product: [{
49
+ name: 'dostoyevski',
50
+ model: [
51
+ { id: 'Axe', name: 'Axe' },
52
+ { id: 'accord', name: 'accord' },
53
+ { id: 'crv', name: 'crv' },
54
+ { id: 'pilot', name: 'pilot' },
55
+ { id: 'odyssey', name: 'odyssey' }
56
+ ]
57
+ }]
58
+ }
59
+ ]
60
+ };
61
+
62
+ constructor(public fb: UntypedFormBuilder) {
63
+ this.editorOptions = new JsonEditorOptions();
64
+ this.editorOptions.schema = schema;
65
+
66
+ this.initEditorOptions(this.editorOptions);
67
+
68
+ // code, text, tree, form and view
69
+ this.editorOptions.mode = 'view'
70
+
71
+ this.editorOptions2 = new JsonEditorOptions();
72
+ this.initEditorOptions(this.editorOptions2)
73
+ }
74
+
75
+ ngOnInit() {
76
+ this.showData = this.data = {
77
+ randomNumber: 2,
78
+ products: [
79
+ {
80
+ name: 'car',
81
+ product:
82
+ [
83
+ {
84
+ name: 'honda',
85
+ model: [
86
+ { id: 'civic', name: 'civic' },
87
+ { id: 'accord', name: 'accord' }, { id: 'crv', name: 'crv' },
88
+ { id: 'pilot', name: 'pilot' }, { id: 'odyssey', name: 'odyssey' }
89
+ ]
90
+ }
91
+ ]
92
+ }
93
+ ]
94
+ };
95
+
96
+ this.data2 = {
97
+ nedata: 'test'
98
+ };
99
+
100
+ this.form = this.fb.group({
101
+ myinput: [this.data2]
102
+ });
103
+
104
+ // this.editorOptions.onChange = this.changeLog.bind(this);
105
+ }
106
+
107
+ changeLog(event = null) {
108
+ console.log(event);
109
+ console.log('change:', this.editor);
110
+ console.log('change2:', this.editorTwo);
111
+
112
+ /**
113
+ * Manual validation based on the schema
114
+ * if the change does not meet the JSON Schema, it will use the last data
115
+ * and will revert the user change.
116
+ */
117
+ const editorJson = this.editor.getEditor()
118
+ editorJson.validate()
119
+ const errors = editorJson.validateSchema.errors
120
+ if (errors && errors.length > 0) {
121
+ console.log('Errors found', errors)
122
+ editorJson.set(this.showData);
123
+ } else {
124
+ this.showData = this.editor.get();
125
+ }
126
+ }
127
+
128
+ changeEvent(event) {
129
+ console.log(event);
130
+ }
131
+
132
+ initEditorOptions(editorOptions) {
133
+ // this.editorOptions.mode = 'code'; // set only one mode
134
+ editorOptions.modes = ['code', 'text', 'tree', 'view']; // set all allowed modes
135
+ editorOptions.onCreateMenu = (items: Array<any>, node: object) => {
136
+ console.log(items, node, 'onCreateMenu');
137
+ return items;
138
+ };
139
+ // this.editorOptions.ace = (<any>window).ace.edit('editor');
140
+ }
141
+
142
+ setLanguage(lang) {
143
+ this.editorOptions.language = lang; // force a specific language, ie. pt-BR
144
+ this.editor.setOptions(this.editorOptions);
145
+ }
146
+
147
+ setAce() {
148
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
149
+ const aceEditor = (<any>window).ace.edit(document.querySelector('#a' + this.editor.id + '>div'));
150
+ // custom your ace here
151
+ aceEditor.setReadOnly(true);
152
+ aceEditor.setFontSize('110pt');
153
+ this.editorOptions.ace = aceEditor;
154
+ this.editor.setOptions(this.editorOptions);
155
+ }
156
+
157
+ toggleNav() {
158
+ this.editorOptions.navigationBar = !this.editorOptions.navigationBar;
159
+ this.editor.setOptions(this.editorOptions);
160
+ }
161
+
162
+ toggleStatus() {
163
+ this.editorOptions.statusBar = !this.editorOptions.statusBar;
164
+ this.editor.setOptions(this.editorOptions);
165
+ }
166
+
167
+ customLanguage() {
168
+ this.editorOptions.languages = {
169
+ // eslint-disable-next-line @typescript-eslint/naming-convention
170
+ 'pt-BR': {
171
+ auto: 'Automático testing'
172
+ },
173
+ en: {
174
+ auto: 'Auto testing'
175
+ }
176
+ };
177
+ this.editor.setOptions(this.editorOptions);
178
+ }
179
+
180
+ changeObject() {
181
+ this.data.randomNumber = Math.floor(Math.random() * 8);
182
+ }
183
+
184
+ changeData() {
185
+ this.data = Object.assign({}, this.data,
186
+ { randomNumber: Math.floor(Math.random() * 8) });
187
+ }
188
+
189
+ /**
190
+ * Example on how get the json changed from the jsoneditor
191
+ */
192
+ getData() {
193
+ const changedJson = this.editor.get();
194
+ console.log(changedJson);
195
+ }
196
+
197
+ print(v) {
198
+ return JSON.stringify(v, null, 2);
199
+ }
200
+ submit() {
201
+ this.formData = JSON.stringify(this.form.value, null, 2);
202
+ console.log(this.form.value);
203
+ }
204
+
205
+ showJson(d) {
206
+ console.log(d)
207
+ this.editedData = JSON.stringify(d, null, 2);
208
+ }
209
+
210
+ makeOptions = () => new JsonEditorOptions()
211
+ }
@@ -0,0 +1,111 @@
1
+ export const schema = {
2
+ definitions: {},
3
+ $schema: 'http://json-schema.org/draft-07/schema#',
4
+ $id: 'http://example.com/root.json',
5
+ type: 'object',
6
+ title: 'The Root Schema',
7
+ required: [
8
+ 'randomNumber',
9
+ 'products'
10
+ ],
11
+ properties: {
12
+ randomNumber: {
13
+ $id: '#/properties/randomNumber',
14
+ type: 'integer',
15
+ title: 'The Randomnumber Schema',
16
+ default: 0,
17
+ examples: [
18
+ 10
19
+ ],
20
+ enum: [1, 2, 3, 4, 5, 6, 7, 8]
21
+ },
22
+ products: {
23
+ $id: '#/properties/products',
24
+ type: 'array',
25
+ title: 'The Products Schema',
26
+ items: {
27
+ $id: '#/properties/products/items',
28
+ type: 'object',
29
+ title: 'The Items Schema',
30
+ required: [
31
+ 'name',
32
+ 'product'
33
+ ],
34
+ properties: {
35
+ name: {
36
+ $id: '#/properties/products/items/properties/name',
37
+ type: 'string',
38
+ title: 'The Name Schema',
39
+ default: '',
40
+ examples: [
41
+ 'car'
42
+ ],
43
+ pattern: '^(.*)$'
44
+ },
45
+ product: {
46
+ $id: '#/properties/products/items/properties/product',
47
+ type: 'array',
48
+ title: 'The Product Schema',
49
+ items: {
50
+ $id: '#/properties/products/items/properties/product/items',
51
+ type: 'object',
52
+ title: 'The Items Schema',
53
+ required: [
54
+ 'name',
55
+ 'model'
56
+ ],
57
+ properties: {
58
+ name: {
59
+ $id: '#/properties/products/items/properties/product/items/properties/name',
60
+ type: 'string',
61
+ title: 'The Name Schema',
62
+ default: '',
63
+ examples: [
64
+ 'honda'
65
+ ],
66
+ pattern: '^(.*)$'
67
+ },
68
+ model: {
69
+ $id: '#/properties/products/items/properties/product/items/properties/model',
70
+ type: 'array',
71
+ title: 'The Model Schema',
72
+ items: {
73
+ $id: '#/properties/products/items/properties/product/items/properties/model/items',
74
+ type: 'object',
75
+ title: 'The Items Schema',
76
+ required: [
77
+ 'id',
78
+ 'name'
79
+ ],
80
+ properties: {
81
+ id: {
82
+ $id: '#/properties/products/items/properties/product/items/properties/model/items/properties/id',
83
+ type: 'string',
84
+ title: 'The Id Schema',
85
+ default: '',
86
+ examples: [
87
+ 'civic'
88
+ ],
89
+ pattern: '^(.*)$'
90
+ },
91
+ name: {
92
+ $id: '#/properties/products/items/properties/product/items/properties/model/items/properties/name',
93
+ type: 'string',
94
+ title: 'The Name Schema',
95
+ default: '',
96
+ examples: [
97
+ 'civic'
98
+ ],
99
+ pattern: '^(.*)$'
100
+ }
101
+ }
102
+ }
103
+ }
104
+ }
105
+ }
106
+ }
107
+ }
108
+ }
109
+ }
110
+ }
111
+ }
@@ -0,0 +1,15 @@
1
+ import { JsonPipe } from "@angular/common";
2
+ import { Component, Input } from "@angular/core";
3
+
4
+ @Component ({
5
+ standalone: true,
6
+ imports: [JsonPipe],
7
+ selector: "app-show",
8
+ template: "<div>{{data | json}}</div>"
9
+ })
10
+ export class ShowComponent {
11
+
12
+ @Input ()
13
+ public data;
14
+
15
+ }
File without changes
Binary file
@@ -0,0 +1,3 @@
1
+ export const environment = {
2
+ production: true
3
+ };
@@ -0,0 +1,8 @@
1
+ // The file contents for the current environment will overwrite these during build.
2
+ // The build system defaults to the dev environment which uses `environment.ts`, but if you do
3
+ // `ng build --env=prod` then `environment.prod.ts` will be used instead.
4
+ // The list of which env maps to which file can be found in `.angular-cli.json`.
5
+
6
+ export const environment = {
7
+ production: false
8
+ };
Binary file
package/src/index.html ADDED
@@ -0,0 +1,14 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>ees-jsoneditor</title>
6
+ <base href="/">
7
+
8
+ <meta name="viewport" content="width=device-width, initial-scale=1">
9
+ <link rel="icon" type="image/x-icon" href="favicon.ico">
10
+ </head>
11
+ <body>
12
+ <app-root>Loading...</app-root>
13
+ </body>
14
+ </html>
package/src/main.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { bootstrapApplication } from '@angular/platform-browser';
2
+ import { appConfig } from './app/app.config';
3
+ import { AppComponent } from './app/app.component';
4
+
5
+ bootstrapApplication(AppComponent, appConfig)
6
+ .catch((err) => console.error(err));
@@ -0,0 +1,2 @@
1
+ /* You can add global styles to this file, and also import other style files */
2
+ @import "../node_modules/jsoneditor/dist/jsoneditor.min.css";
@@ -0,0 +1,14 @@
1
+ /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
+ {
3
+ "extends": "./tsconfig.json",
4
+ "compilerOptions": {
5
+ "outDir": "./out-tsc/app",
6
+ "types": []
7
+ },
8
+ "files": [
9
+ "src/main.ts"
10
+ ],
11
+ "include": [
12
+ "src/**/*.d.ts"
13
+ ]
14
+ }