@json-editor/json-editor 2.5.4 → 2.7.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 (91) hide show
  1. package/.github/workflows/build.yml +12 -3
  2. package/CHANGELOG.md +51 -14
  3. package/README.md +159 -20
  4. package/dist/jsoneditor.js +2 -2
  5. package/dist/nonmin/jsoneditor.js +5483 -3610
  6. package/dist/nonmin/jsoneditor.js.map +1 -1
  7. package/docs/cleave.html +1 -1
  8. package/docs/datetime.html +1 -1
  9. package/docs/describedby.html +1 -1
  10. package/docs/form-submission.html +76 -0
  11. package/docs/index.html +2 -2
  12. package/docs/materialize_css.html +1 -1
  13. package/docs/meta_schema.json +0 -1
  14. package/docs/radio.html +1 -1
  15. package/docs/select2.html +1 -1
  16. package/docs/selectize.html +1 -1
  17. package/docs/starrating.html +1 -1
  18. package/docs/wysiwyg.html +1 -1
  19. package/package.json +28 -26
  20. package/release-notes.md +5 -3
  21. package/src/core.js +36 -37
  22. package/src/defaults.js +9 -2
  23. package/src/editor.js +6 -2
  24. package/src/editors/array.js +12 -1
  25. package/src/editors/autocomplete.js +4 -3
  26. package/src/editors/button.js +1 -1
  27. package/src/editors/multiple.js +2 -0
  28. package/src/editors/multiselect.js +14 -5
  29. package/src/editors/object.js +10 -6
  30. package/src/editors/radio.js +6 -1
  31. package/src/editors/string.js +7 -1
  32. package/src/editors/table.js +21 -2
  33. package/src/editors/upload.js +1 -1
  34. package/src/editors/uuid.js +2 -12
  35. package/src/iconlib.js +1 -1
  36. package/src/schemaloader.js +232 -109
  37. package/src/style.css +3 -0
  38. package/src/style.css.js +1 -1
  39. package/src/theme.js +5 -4
  40. package/src/themes/bootstrap3.js +3 -2
  41. package/src/themes/bootstrap4.js +7 -0
  42. package/src/themes/spectre.js +2 -1
  43. package/src/utilities.js +18 -0
  44. package/src/validator.js +65 -47
  45. package/tests/codeceptjs/codecept.json +1 -1
  46. package/tests/codeceptjs/core_test.js +98 -0
  47. package/tests/codeceptjs/editors/advanced_test.js +1 -1
  48. package/tests/codeceptjs/editors/array_test.js +74 -0
  49. package/tests/codeceptjs/editors/autocomplete_test.js +16 -0
  50. package/tests/codeceptjs/editors/button_test.js +11 -4
  51. package/tests/codeceptjs/editors/integer_test.js +7 -2
  52. package/tests/codeceptjs/editors/jodit_test.js +3 -3
  53. package/tests/codeceptjs/editors/object_test.js +84 -13
  54. package/tests/codeceptjs/editors/range_test.js +12 -0
  55. package/tests/codeceptjs/editors/stepper_test.js +12 -0
  56. package/tests/codeceptjs/editors/uuid_test.js +31 -4
  57. package/tests/codeceptjs/editors/validation_test.js +1 -1
  58. package/tests/docker-compose.yml +1 -1
  59. package/tests/fixtures/definitions.json +22 -0
  60. package/tests/fixtures/properties.json +20 -0
  61. package/tests/fixtures/validation.json +207 -0
  62. package/tests/pages/array-checkboxes-infotext.html +52 -0
  63. package/tests/pages/array-move-events.html +4 -2
  64. package/tests/pages/array-unique-items-sort.html +78 -0
  65. package/tests/pages/autocomplete.html +69 -0
  66. package/tests/pages/button-icons.html +38 -0
  67. package/tests/pages/core.html +4 -2
  68. package/tests/pages/error-messages.html +47 -0
  69. package/tests/pages/grid-strict.html +6 -10
  70. package/tests/pages/grid.html +0 -4
  71. package/tests/pages/issues/issue-gh-812.html +4 -2
  72. package/tests/pages/meta_schema.json +14 -1
  73. package/tests/pages/object-required-properties.html +37 -14
  74. package/tests/pages/object-show-opt-in.html +110 -0
  75. package/tests/pages/object-with-dependencies-array.html +29 -19
  76. package/tests/pages/range.html +60 -0
  77. package/tests/pages/ready.html +43 -0
  78. package/tests/pages/references.html +162 -0
  79. package/tests/pages/stepper-manual.html +57 -0
  80. package/tests/pages/string-simplemde-editor.html +81 -0
  81. package/tests/pages/table-move-events.html +4 -1
  82. package/tests/pages/urn.html +11 -8
  83. package/tests/pages/uuid.html +89 -50
  84. package/tests/pages/validation-messages.json +705 -0
  85. package/tests/unit/core.spec.js +79 -66
  86. package/tests/unit/editor.spec.js +20 -8
  87. package/tests/unit/editors/array.spec.js +3 -2
  88. package/tests/unit/editors/object.spec.js +3 -1
  89. package/tests/unit/editors/table.spec.js +4 -2
  90. package/tests/unit/schemaloader.spec.js +77 -105
  91. package/tests/unit/validator.spec.js +10 -0
@@ -0,0 +1,52 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8"/>
5
+ <script src="../../dist/jsoneditor.js"></script>
6
+ </head>
7
+ <body>
8
+
9
+ <textarea class="debug" cols="30" rows="10"></textarea>
10
+ <button class='get-value'>Get Value</button>
11
+ <div class='container'></div>
12
+
13
+ <script>
14
+ var container = document.querySelector('.container')
15
+ var debug = document.querySelector('.debug')
16
+ var schema = {
17
+ 'title': 'Checkbox with Infotext',
18
+ 'type': 'array',
19
+ 'uniqueItems': true,
20
+ 'items': {
21
+ 'type': 'string',
22
+ 'enum': ['1', '2', '3', '4', '5'],
23
+ 'options': {
24
+ 'enum_titles': ['old a', 'old b'],
25
+ 'enum': [
26
+ {},
27
+ {
28
+ 'title': 'b',
29
+ },
30
+ {},
31
+ { 'infoText': 'dd' },
32
+ {
33
+ 'title': 'e',
34
+ 'infoText': 'ee'
35
+ }
36
+ ]
37
+ }
38
+ }
39
+ }
40
+
41
+ var editor = new JSONEditor(container, {
42
+ schema: schema
43
+ })
44
+
45
+ document.querySelector('.get-value').addEventListener('click', function () {
46
+ debug.value = JSON.stringify(editor.getValue())
47
+ })
48
+
49
+ </script>
50
+
51
+ </body>
52
+ </html>
@@ -27,8 +27,8 @@
27
27
  var editor = new JSONEditor(container, {
28
28
  schema: schema
29
29
  });
30
-
31
- document.querySelector('.get-value').addEventListener('click', function () {
30
+ editor.promise.then(() => {
31
+ document.querySelector('.get-value').addEventListener('click', function () {
32
32
  debug.value = JSON.stringify(editor.getValue());
33
33
  });
34
34
 
@@ -53,6 +53,8 @@
53
53
  action.value = 'deleteAllRows'
54
54
  console.log('deleteAllRows')
55
55
  });
56
+ })
57
+
56
58
 
57
59
 
58
60
  </script>
@@ -0,0 +1,78 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8"/>
5
+ <script src="../../dist/jsoneditor.js"></script>
6
+ </head>
7
+ <body>
8
+
9
+ <textarea class="debug" cols="30" rows="10"></textarea>
10
+ <button class='get-value'>Get Value</button>
11
+ <div class='container'></div>
12
+
13
+ <script>
14
+ var container = document.querySelector('.container');
15
+ var debug = document.querySelector('.debug');
16
+ var schema = {
17
+ "properties": {
18
+ "items": {
19
+ "title": "items",
20
+ "name": "ageband",
21
+ "type": "array",
22
+ "uniqueItems": true,
23
+ "format": "checkbox",
24
+ "items": {
25
+ "type": "string",
26
+ "enum": [
27
+ "01",
28
+ "02",
29
+ "03",
30
+ "04",
31
+ "05",
32
+ "06",
33
+ "07",
34
+ "08",
35
+ "09",
36
+ "10",
37
+ "11",
38
+ "12",
39
+ "13",
40
+ "14",
41
+ "15"
42
+ ],
43
+ "options": {
44
+ "enum_titles": [
45
+ "01",
46
+ "02",
47
+ "03",
48
+ "04",
49
+ "05",
50
+ "06",
51
+ "07",
52
+ "08",
53
+ "09",
54
+ "10",
55
+ "11",
56
+ "12",
57
+ "13",
58
+ "14",
59
+ "15"
60
+ ]
61
+ }
62
+ }
63
+ }
64
+ }
65
+ }
66
+
67
+ var editor = new JSONEditor(container, {
68
+ schema: schema
69
+ });
70
+
71
+ document.querySelector('.get-value').addEventListener('click', function () {
72
+ debug.value = JSON.stringify(editor.getValue());
73
+ });
74
+
75
+ </script>
76
+
77
+ </body>
78
+ </html>
@@ -0,0 +1,69 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8"/>
5
+ <title>Autocomplete</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://unpkg.com/@trevoreyre/autocomplete-js"></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
+ <div class='json-editor-container'></div>
16
+ </div>
17
+
18
+
19
+ <script>
20
+ window.addEventListener('load', function () {
21
+ var jsonEditorContainer = document.querySelector('.json-editor-container')
22
+ var value = document.querySelector('.value')
23
+
24
+ JSONEditor.defaults.callbacks = {
25
+ 'autocomplete': {
26
+ 'search': function (editor, input) {
27
+ var countries = [
28
+ 'germany',
29
+ 'iran',
30
+ 'iraq',
31
+ 'spain'
32
+ ]
33
+
34
+ if (input.length < 1) { return [] }
35
+
36
+ return countries.filter(country => {
37
+ return country.toLowerCase().startsWith(input.toLowerCase())
38
+ })
39
+ }
40
+ }
41
+ }
42
+
43
+ var schema = {
44
+ 'title': 'Test',
45
+ 'type': 'string',
46
+ 'format': 'autocomplete',
47
+ 'options': {
48
+ 'autocomplete': {
49
+ 'search': 'search',
50
+ 'autoSelect': true
51
+ }
52
+ }
53
+ }
54
+
55
+ var editor = new JSONEditor(jsonEditorContainer, {
56
+ schema: schema,
57
+ theme: 'bootstrap4',
58
+ required_by_default: true,
59
+ show_errors: 'always'
60
+ })
61
+
62
+ editor.on('change', function () {
63
+ value.value = JSON.stringify(editor.getValue())
64
+ })
65
+ })
66
+ </script>
67
+
68
+ </body>
69
+ </html>
@@ -0,0 +1,38 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8"/>
5
+ <title>Button Callbacks</title>
6
+ <script src="../../dist/jsoneditor.js"></script>
7
+ <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css">
8
+ </head>
9
+ <body>
10
+
11
+ <div class='container'></div>
12
+
13
+ <script>
14
+ var container = document.querySelector('.container');
15
+ var schema = {
16
+ 'type': 'object',
17
+ 'title': 'test',
18
+ 'properties': {
19
+ 'search': {
20
+ 'type': 'button',
21
+ 'title': 'Search',
22
+ 'options': {
23
+ 'button': {
24
+ 'icon': 'search'
25
+ }
26
+ }
27
+ }
28
+ }
29
+ }
30
+
31
+ var editor = new JSONEditor(container, {
32
+ iconlib: 'fontawesome5',
33
+ schema: schema,
34
+ });
35
+ </script>
36
+
37
+ </body>
38
+ </html>
@@ -58,8 +58,8 @@
58
58
  var editor = new JSONEditor(container, {
59
59
  schema: schema
60
60
  });
61
-
62
- var changeCallback = function () {
61
+ editor.promise.then(() => {
62
+ var changeCallback = function () {
63
63
  if (this.getCount()>1) formChanged.style.display = 'block'
64
64
  }.bind({
65
65
  count:0,
@@ -111,6 +111,8 @@
111
111
  destroy.addEventListener('click', function () {
112
112
  editor.destroy();
113
113
  });
114
+ })
115
+
114
116
 
115
117
  </script>
116
118
 
@@ -0,0 +1,47 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8"/>
5
+ <title>JSONEditor with forms</title>
6
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
7
+ </head>
8
+ <body>
9
+ <div class="container">
10
+ <button id="switch-es">Switch to ES</button>
11
+ <div id='editor-container'></div>
12
+ </div>
13
+ <script src="../../dist/jsoneditor.js"></script>
14
+ <script>
15
+ JSONEditor.defaults.languages.es = {}
16
+
17
+ var switchEs = document.querySelector('#switch-es')
18
+ var editor = null
19
+
20
+ var initEditor = function () {
21
+ if (editor) {
22
+ editor.destroy()
23
+ }
24
+
25
+ editor = new JSONEditor(document.querySelector('#editor-container'), {
26
+ theme: 'bootstrap4',
27
+ disable_edit_json: true,
28
+ disable_properties: true,
29
+ disable_collapse: true,
30
+ ajax: true,
31
+ show_errors: 'always',
32
+ schema: {
33
+ $ref: './validation-messages.json',
34
+ }
35
+ })
36
+ }
37
+
38
+ switchEs.addEventListener('click', function () {
39
+ JSONEditor.defaults.language = 'es'
40
+ initEditor()
41
+ })
42
+
43
+ initEditor()
44
+
45
+ </script>
46
+ </body>
47
+ </html>
@@ -34,7 +34,6 @@
34
34
  <script>
35
35
  var container = document.querySelector('.json-editor-container');
36
36
  var editor = document.querySelector('.value');
37
-
38
37
  var schema = {
39
38
  "type": "object",
40
39
  "title": "range",
@@ -291,19 +290,16 @@
291
290
  schema: schema,
292
291
  theme: theme
293
292
  });
293
+ document.getElementById('theme_switcher').addEventListener('change',function() {
294
+ setTheme(this.value);
295
+ });
296
+
297
+
294
298
  };
295
-
296
- document.getElementById('theme_switcher').addEventListener('change',function() {
297
- setTheme(this.value);
298
- });
299
-
300
299
  window.addEventListener('load',function() {
301
- editor = new JSONEditor(container, {
302
- schema: schema,
303
- theme: 'bootstrap4'
304
- });
305
300
  setTheme(this.value);
306
301
  });
302
+
307
303
 
308
304
  </script>
309
305
 
@@ -268,10 +268,6 @@
268
268
  });
269
269
 
270
270
  window.addEventListener('load',function() {
271
- editor = new JSONEditor(container, {
272
- schema: schema,
273
- theme: 'bootstrap4'
274
- });
275
271
  setTheme(this.value);
276
272
  });
277
273
 
@@ -59,8 +59,8 @@
59
59
  }
60
60
  },
61
61
  });
62
-
63
- // Hook up the submit button to log to the console
62
+ editor.promise.then(() => {
63
+ // Hook up the submit button to log to the console
64
64
  document.getElementById('submit').addEventListener('click',function() {
65
65
  // Get the value from the editor
66
66
  console.log(editor.getValue());
@@ -105,6 +105,8 @@
105
105
  }
106
106
  ]
107
107
  });
108
+ })
109
+
108
110
  </script>
109
111
  </body>
110
112
  </html>
@@ -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",
@@ -626,6 +625,20 @@
626
625
  "tilte":"title"
627
626
  }
628
627
  },
628
+ "enum": {
629
+ "type": "array",
630
+ "items": {
631
+ "type": "object",
632
+ "properties": {
633
+ "title": {
634
+ "type": "string"
635
+ },
636
+ "infoText":{
637
+ "type": "string"
638
+ }
639
+ }
640
+ }
641
+ },
629
642
  "grid_columns":{
630
643
  "type":"integer",
631
644
  "default": 1,
@@ -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": {
@@ -139,7 +162,7 @@
139
162
  }
140
163
  };
141
164
 
142
- var setTheme = function(theme) {
165
+ var setTheme = async function(theme) {
143
166
  theme = theme || '';
144
167
 
145
168
  var mapping = {
@@ -187,30 +210,30 @@
187
210
  document.getElementById('theme_stylesheet').href = mapping[theme];
188
211
  document.getElementById('theme_switcher').value = JSONEditor.defaults.options.theme;
189
212
 
190
-
213
+ console.log(editor)
191
214
  if (editor) {
192
215
  editor.destroy();
193
216
  }
194
217
 
195
- initJsonEditor();
218
+ await initJsonEditor();
196
219
 
197
220
  };
198
221
 
199
- initJsonEditor = function () {
222
+ initJsonEditor = async function () {
200
223
  editor = new JSONEditor(container, {
201
224
  schema: schema,
202
225
  theme: 'bootstrap4',
203
226
  show_opt_in: true
204
227
  });
228
+ await editor.promise;
205
229
  }
206
230
 
207
231
  document.getElementById('theme_switcher').addEventListener('change',function() {
208
232
  setTheme(this.value);
209
233
  });
210
234
 
211
- window.addEventListener('load',function() {
212
-
213
- initJsonEditor();
235
+ window.addEventListener('load', async function() {
236
+ await initJsonEditor();
214
237
 
215
238
  getValue.addEventListener('click', function () {
216
239
  value.value = JSON.stringify(editor.getValue());
@@ -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>