@json-editor/json-editor 2.5.4 → 2.6.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.
@@ -1136,5 +1136,212 @@
1136
1136
  "charlie": { "type": "string" }
1137
1137
  }
1138
1138
  ]
1139
+ },
1140
+ "nested_anyOf": {
1141
+ "schema": {
1142
+ "type": "object",
1143
+ "properties": {
1144
+ "prop": {
1145
+ "anyOf": [
1146
+ {
1147
+ "$ref": "#/definitions/A"
1148
+ },
1149
+ {
1150
+ "$ref": "#/definitions/B"
1151
+ }
1152
+ ]
1153
+ }
1154
+ },
1155
+ "definitions": {
1156
+ "A": {
1157
+ "title": "A",
1158
+ "type": "object",
1159
+ "properties": {
1160
+ "fooA": {
1161
+ "type": "string"
1162
+ },
1163
+ "barA": {
1164
+ "type": "string"
1165
+ },
1166
+ "common": {
1167
+ "type": "string"
1168
+ }
1169
+ },
1170
+ "required": [
1171
+ "fooA",
1172
+ "barA"
1173
+ ]
1174
+ },
1175
+ "B": {
1176
+ "title": "B",
1177
+ "anyOf": [
1178
+ {
1179
+ "$ref": "#/definitions/C"
1180
+ },
1181
+ {
1182
+ "$ref": "#/definitions/D"
1183
+ }
1184
+ ]
1185
+ },
1186
+ "C": {
1187
+ "title": "C",
1188
+ "type": "object",
1189
+ "properties": {
1190
+ "fooC": {
1191
+ "type": "string"
1192
+ },
1193
+ "barC": {
1194
+ "type": "string"
1195
+ },
1196
+ "common": {
1197
+ "type": "string"
1198
+ }
1199
+ },
1200
+ "required": [
1201
+ "fooC",
1202
+ "barC"
1203
+ ]
1204
+ },
1205
+ "D": {
1206
+ "title": "D",
1207
+ "type": "object",
1208
+ "properties": {
1209
+ "fooD": {
1210
+ "type": "string"
1211
+ },
1212
+ "barD": {
1213
+ "type": "string"
1214
+ }
1215
+ },
1216
+ "required": [
1217
+ "fooD",
1218
+ "barD"
1219
+ ]
1220
+ }
1221
+ }
1222
+ },
1223
+ "valid": [
1224
+ {
1225
+ "prop": {
1226
+ "fooC": "foo",
1227
+ "barC": "bar",
1228
+ "common": "common"
1229
+ }
1230
+ },
1231
+ {
1232
+ "prop": {
1233
+ "fooD": "foo",
1234
+ "barD": "bar",
1235
+ "common": "common"
1236
+ }
1237
+ },
1238
+ {
1239
+ "prop": {
1240
+ "fooA": "foo",
1241
+ "barA": "bar",
1242
+ "common": "common"
1243
+ }
1244
+ }
1245
+ ],
1246
+ "invalid": [
1247
+ {
1248
+ "prop": {
1249
+ "common": "common"
1250
+ }
1251
+ }
1252
+ ]
1253
+ },
1254
+ "anyOf_invalid_better_fit_test": {
1255
+ "schema": {
1256
+ "type": "object",
1257
+ "properties": {
1258
+ "foo": {
1259
+ "anyOf": [
1260
+ {
1261
+ "$ref": "#/definitions/A"
1262
+ },
1263
+ {
1264
+ "$ref": "#/definitions/B"
1265
+ }
1266
+ ]
1267
+ }
1268
+ },
1269
+ "definitions": {
1270
+ "A": {
1271
+ "type": "object",
1272
+ "properties": {
1273
+ "type": {
1274
+ "enum": [
1275
+ "A"
1276
+ ],
1277
+ "type": "string"
1278
+ },
1279
+ "referenced": {
1280
+ "$ref": "#/definitions/ReferencedObject"
1281
+ }
1282
+ },
1283
+ "required": [
1284
+ "type"
1285
+ ]
1286
+ },
1287
+ "B": {
1288
+ "type": "object",
1289
+ "properties": {
1290
+ "type": {
1291
+ "enum": [
1292
+ "B"
1293
+ ],
1294
+ "type": "string"
1295
+ },
1296
+ "referenced": {
1297
+ "properties": {
1298
+ "foo": {
1299
+ "type": "string"
1300
+ },
1301
+ "bar": {
1302
+ "type": "string"
1303
+ }
1304
+ },
1305
+ "type": "object"
1306
+ }
1307
+ },
1308
+ "required": [
1309
+ "type"
1310
+ ]
1311
+ },
1312
+ "ReferencedObject": {
1313
+ "properties": {
1314
+ "foo": {
1315
+ "type": "string"
1316
+ },
1317
+ "bar": {
1318
+ "type": "string"
1319
+ }
1320
+ },
1321
+ "type": "object"
1322
+ }
1323
+ }
1324
+ },
1325
+ "valid": [
1326
+ {
1327
+ "foo": {
1328
+ "type": "A",
1329
+ "referenced": {
1330
+ "foo": "",
1331
+ "bar": ""
1332
+ }
1333
+ }
1334
+ },
1335
+ {
1336
+ "foo": {
1337
+ "type": "B",
1338
+ "referenced": {
1339
+ "foo": "",
1340
+ "bar": ""
1341
+ }
1342
+ }
1343
+ }
1344
+ ],
1345
+ "invalid": []
1139
1346
  }
1140
1347
  }
@@ -75,7 +75,6 @@
75
75
  "enum":[
76
76
  "color",
77
77
  "date",
78
- "datetime",
79
78
  "datetime-local",
80
79
  "email",
81
80
  "month",
@@ -62,22 +62,33 @@
62
62
  "type": "string",
63
63
  "minLength": 5,
64
64
  "options": {
65
- "grid_columns": 4
65
+ "grid_columns": 3
66
66
  }
67
67
  },
68
68
  "number": {
69
69
  "title": "number",
70
70
  "type": "number",
71
71
  "options": {
72
- "grid_columns": 4
72
+ "grid_columns": 3
73
73
  }
74
74
  },
75
75
  "boolean": {
76
76
  "title": "boolean",
77
77
  "type": "boolean",
78
78
  "options": {
79
- "grid_columns": 4,
80
- "grid_break": true
79
+ "grid_columns": 3,
80
+ }
81
+ },
82
+ "radio": {
83
+ "type": "string",
84
+ "format": "radio",
85
+ "title": "Radio Buttons",
86
+ "enum": [
87
+ "Home",
88
+ "Work"
89
+ ],
90
+ "options": {
91
+ "grid_columns": 3
81
92
  }
82
93
  },
83
94
  "array": {
@@ -106,21 +117,33 @@
106
117
  "title": "string",
107
118
  "type": "string",
108
119
  "options": {
109
- "grid_columns": 4
120
+ "grid_columns": 3
110
121
  }
111
122
  },
112
123
  "number": {
113
124
  "title": "number",
114
125
  "type": "number",
115
126
  "options": {
116
- "grid_columns": 4
127
+ "grid_columns": 3
117
128
  }
118
129
  },
119
130
  "boolean": {
120
131
  "title": "boolean",
121
132
  "type": "boolean",
122
133
  "options": {
123
- "grid_columns": 4
134
+ "grid_columns": 3
135
+ }
136
+ },
137
+ "radio": {
138
+ "type": "string",
139
+ "format": "radio",
140
+ "title": "Radio Buttons",
141
+ "enum": [
142
+ "Home",
143
+ "Work"
144
+ ],
145
+ "options": {
146
+ "grid_columns": 3
124
147
  }
125
148
  },
126
149
  "array": {
@@ -0,0 +1,110 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Object Required Properties</title>
5
+ <meta charset="utf-8"/>
6
+ <script src="../../dist/jsoneditor.js"></script>
7
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
8
+ </head>
9
+ <body>
10
+
11
+ <div class="container">
12
+ <label for="show-opt-in">
13
+ <span>show_opt_in</span>
14
+ <input id="show-opt-in" type="checkbox">
15
+ </label>
16
+ <div id='json-editor-container'></div>
17
+ <label for="value"></label>
18
+ <textarea id="value" class="value" style="width: 100%; height: 300px;"></textarea>
19
+ <button id='get-value'>get value</button>
20
+ <button id='get-formatted-value'>get formatted value</button>
21
+ </div>
22
+
23
+ <script>
24
+ var container = document.querySelector('#json-editor-container')
25
+ var value = document.querySelector('#value')
26
+ var getValue = document.querySelector('#get-value')
27
+ var getFormattedValue = document.querySelector('#get-formatted-value')
28
+ var showOptIn = document.querySelector('#show-opt-in')
29
+ var schema = {
30
+ 'type': 'object',
31
+ 'title': 'option_show_opt_in_false',
32
+ 'options': {
33
+ 'show_opt_in': false
34
+ },
35
+ 'properties': {
36
+ 'option_show_opt_in_undefined': {
37
+ 'type': 'object',
38
+ 'title': 'option_show_opt_in_undefined',
39
+ 'properties': {
40
+ 'string': {
41
+ 'title': 'optional_string',
42
+ 'type': 'string'
43
+ }
44
+ }
45
+ },
46
+ 'option_show_opt_in_true': {
47
+ 'type': 'object',
48
+ 'title': 'option_show_opt_in_true',
49
+ 'options': {
50
+ 'show_opt_in': true
51
+ },
52
+ 'properties': {
53
+ 'string': {
54
+ 'title': 'optional_string',
55
+ 'type': 'string'
56
+ }
57
+ }
58
+ },
59
+ 'option_show_opt_in_false': {
60
+ 'type': 'object',
61
+ 'title': 'option_show_opt_in_false',
62
+ 'options': {
63
+ 'show_opt_in': false
64
+ },
65
+ 'properties': {
66
+ 'string': {
67
+ 'title': 'optional_string',
68
+ 'type': 'string'
69
+ }
70
+ }
71
+ }
72
+ }
73
+ }
74
+
75
+ window.addEventListener('DOMContentLoaded', function () {
76
+
77
+ var editor = null
78
+
79
+ var initJSONEditor = function (show_opt_in) {
80
+ if (editor) {
81
+ editor.destroy()
82
+ }
83
+
84
+ editor = new JSONEditor(container, {
85
+ schema: schema,
86
+ theme: 'bootstrap4',
87
+ disable_collapse: true,
88
+ disable_edit_json: true,
89
+ show_opt_in: show_opt_in || false
90
+ })
91
+ }
92
+
93
+ initJSONEditor(false)
94
+
95
+ showOptIn.addEventListener('click', function (event) {
96
+ initJSONEditor(event.target.checked)
97
+ })
98
+
99
+ getValue.addEventListener('click', function () {
100
+ value.value = JSON.stringify(editor.getValue())
101
+ })
102
+
103
+ getFormattedValue.addEventListener('click', function () {
104
+ value.value = JSON.stringify(editor.getValue(), null, 2)
105
+ })
106
+ })
107
+ </script>
108
+
109
+ </body>
110
+ </html>
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8"/>
5
+ <title>Stepper</title>
6
+ <link rel="stylesheet" id="theme-link" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
7
+ <link rel="stylesheet" id="iconlib-link" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css">
8
+ <script src="https://cdn.jsdelivr.net/npm/mathjs@5.3.1/dist/math.min.js" class="external_mathjs"></script>
9
+ <script src="../../dist/jsoneditor.js"></script>
10
+ </head>
11
+ <body>
12
+
13
+ <div class="container">
14
+ <textarea class="value form-control" rows="10"></textarea>
15
+ <button class='get-value'>Get Value</button>
16
+ <button class='set-value'>Set Value</button>
17
+ <div class='json-editor-container'></div>
18
+ </div>
19
+
20
+
21
+ <script>
22
+ var jsonEditorContainer = document.querySelector('.json-editor-container');
23
+ var value = document.querySelector('.value');
24
+
25
+ var schema = {
26
+ "type": "object",
27
+ "title": "range",
28
+ "properties": {
29
+ "stepper": {
30
+ 'type': 'integer',
31
+ 'format': 'stepper',
32
+ "default": ""
33
+ }
34
+ }
35
+ };
36
+
37
+ var editor = new JSONEditor(jsonEditorContainer, {
38
+ schema: schema,
39
+ theme: 'bootstrap4',
40
+ use_default_values: false,
41
+ required_by_default: true,
42
+ show_errors: 'always'
43
+ });
44
+
45
+ document.querySelector('.get-value').addEventListener('click', function () {
46
+ value.value = JSON.stringify(editor.getValue());
47
+ console.log(editor.getValue());
48
+ });
49
+
50
+ document.querySelector('.set-value').addEventListener('click', function () {
51
+ editor.setValue({number_range: 2})
52
+ });
53
+
54
+ </script>
55
+
56
+ </body>
57
+ </html>
@@ -8,6 +8,7 @@ import fixtureString from '../fixtures/string.json'
8
8
  import fixtureRecursive from '../fixtures/recursive.json'
9
9
  import * as math from 'mathjs'
10
10
  import { createFakeServer } from 'sinon'
11
+ import * as deepEqual from 'fast-deep-equal';
11
12
 
12
13
  describe('Validator', () => {
13
14
  it('mathjs test', () => {
@@ -79,6 +80,15 @@ describe('Validation Test', () => {
79
80
  done()
80
81
  })
81
82
  })
83
+
84
+ it(`does not change valid data ${i + 1}`, (done) => {
85
+ editor.on('ready', () => {
86
+ editor.setValue(v)
87
+ expect(deepEqual(editor.getValue(), v)).toBe(true)
88
+ done()
89
+ })
90
+ })
91
+
82
92
  })
83
93
  spec.invalid.forEach((v, i) => {
84
94
  it(`invalid data ${i + 1}`, (done) => {