@json-editor/json-editor 2.6.1 → 2.9.0-beta.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 (74) hide show
  1. package/.github/workflows/build.yml +12 -3
  2. package/CHANGELOG.md +32 -0
  3. package/README.md +148 -18
  4. package/dist/jsoneditor.js +2 -2
  5. package/dist/nonmin/jsoneditor.js +2920 -643
  6. package/dist/nonmin/jsoneditor.js.map +1 -1
  7. package/docs/form-submission.html +162 -0
  8. package/package.json +4 -3
  9. package/release-notes.md +2 -0
  10. package/src/core.js +36 -37
  11. package/src/defaults.js +10 -2
  12. package/src/editors/array.js +12 -1
  13. package/src/editors/autocomplete.js +4 -3
  14. package/src/editors/button.js +1 -1
  15. package/src/editors/checkbox.js +3 -1
  16. package/src/editors/hidden.js +3 -1
  17. package/src/editors/multiselect.js +17 -6
  18. package/src/editors/radio.js +8 -3
  19. package/src/editors/select.js +3 -1
  20. package/src/editors/signature.js +3 -1
  21. package/src/editors/string.js +7 -1
  22. package/src/editors/table.js +20 -2
  23. package/src/editors/upload.js +1 -1
  24. package/src/editors/uuid.js +2 -12
  25. package/src/iconlib.js +1 -1
  26. package/src/schemaloader.js +319 -103
  27. package/src/style.css +3 -0
  28. package/src/style.css.js +1 -1
  29. package/src/theme.js +0 -2
  30. package/src/themes/bootstrap3.js +1 -0
  31. package/src/themes/spectre.js +2 -1
  32. package/src/utilities.js +18 -0
  33. package/src/validator.js +36 -34
  34. package/tests/codeceptjs/codecept.json +1 -1
  35. package/tests/codeceptjs/core_test.js +125 -0
  36. package/tests/codeceptjs/editors/advanced_test.js +1 -1
  37. package/tests/codeceptjs/editors/array_test.js +74 -0
  38. package/tests/codeceptjs/editors/autocomplete_test.js +16 -0
  39. package/tests/codeceptjs/editors/button_test.js +10 -3
  40. package/tests/codeceptjs/editors/integer_test.js +7 -2
  41. package/tests/codeceptjs/editors/jodit_test.js +3 -3
  42. package/tests/codeceptjs/editors/range_test.js +12 -0
  43. package/tests/codeceptjs/editors/uuid_test.js +31 -4
  44. package/tests/docker-compose.yml +1 -1
  45. package/tests/fixtures/definitions.json +22 -0
  46. package/tests/fixtures/properties.json +20 -0
  47. package/tests/pages/array-checkboxes-infotext.html +52 -0
  48. package/tests/pages/array-move-events.html +4 -2
  49. package/tests/pages/array-unique-items-sort.html +78 -0
  50. package/tests/pages/autocomplete.html +69 -0
  51. package/tests/pages/button-icons.html +38 -0
  52. package/tests/pages/core.html +4 -2
  53. package/tests/pages/error-messages.html +47 -0
  54. package/tests/pages/grid-strict.html +6 -10
  55. package/tests/pages/grid.html +0 -4
  56. package/tests/pages/issues/issue-gh-812.html +4 -2
  57. package/tests/pages/meta_schema.json +14 -0
  58. package/tests/pages/object-required-properties.html +7 -7
  59. package/tests/pages/range.html +60 -0
  60. package/tests/pages/ready.html +43 -0
  61. package/tests/pages/references.html +168 -0
  62. package/tests/pages/string-simplemde-editor.html +81 -0
  63. package/tests/pages/table-move-events.html +4 -1
  64. package/tests/pages/urn.html +11 -8
  65. package/tests/pages/use-name-attributes.html +206 -0
  66. package/tests/pages/uuid.html +89 -50
  67. package/tests/pages/validation-messages.json +705 -0
  68. package/tests/unit/core.spec.js +79 -66
  69. package/tests/unit/editor.spec.js +20 -8
  70. package/tests/unit/editors/array.spec.js +3 -2
  71. package/tests/unit/editors/object.spec.js +3 -1
  72. package/tests/unit/editors/table.spec.js +4 -2
  73. package/tests/unit/schemaloader.spec.js +181 -103
  74. package/tests/unit/validator.spec.js +2 -2
@@ -0,0 +1,168 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>References JSON Editor Example</title>
6
+
7
+ <script src="../../dist/jsoneditor.js"></script>
8
+ </head>
9
+ <body>
10
+ <h1>References JSON Editor Example</h1>
11
+
12
+ <p>This example demonstrates the following:</p>
13
+ <ul>
14
+ <li>Loading external schemas via ajax</li>
15
+ <li>Referencing internal schema definitions</li>
16
+ <li>Referencing external schema definitions</li>
17
+ <li>Referencing external schema properties</li>
18
+ </ul>
19
+
20
+ <button id='submit'>Submit (console.log)</button>
21
+ <button id='restore'>Restore to Default</button>
22
+ <button id='enable_disable'>Disable/Enable Form</button>
23
+ <span id='valid_indicator'></span>
24
+
25
+ <div id='editor_holder'></div>
26
+
27
+ <script>
28
+ // This is the starting value for the editor
29
+ // We will use this to seed the initial editor
30
+ // and to provide a "Restore to Default" button.
31
+ var starting_value = [
32
+ {
33
+ name: "John Smith",
34
+ age: 35,
35
+ gender: "male",
36
+ location: {
37
+ city: "San Francisco",
38
+ state: "California",
39
+ citystate: ""
40
+ },
41
+ pets: [
42
+ {
43
+ name: "Spot",
44
+ type: "dog",
45
+ fixed: true
46
+ },
47
+ {
48
+ name: "Whiskers",
49
+ type: "cat",
50
+ fixed: false
51
+ }
52
+ ]
53
+ }
54
+ ];
55
+
56
+ // Initialize the editor
57
+ var editor = new JSONEditor(document.getElementById('editor_holder'),{
58
+ // Enable fetching schemas via ajax
59
+ ajax: true,
60
+
61
+ // Enable caching schemas from via ajax
62
+ ajax_cache_responses: true,
63
+
64
+ // The cache-buster for cached caches
65
+ ajax_cache_buster: 'abc123',
66
+
67
+ // The schema for the editor
68
+ schema: {
69
+ $schema: "https://json-schema.org/draft-04/schema",
70
+ title: "Example Organization",
71
+ type: "object",
72
+ definitions: {
73
+ taxid: {
74
+ type: "string",
75
+ title: "Tax ID"
76
+ },
77
+ external: {
78
+ $ref: "../fixtures/string.json"
79
+ }
80
+ },
81
+ properties: {
82
+ external: {
83
+ $ref: "#/definitions/external"
84
+ },
85
+ orgid: { $ref: "#/definitions/taxid" },
86
+ address: {
87
+ $ref: "../fixtures/definitions.json#/definitions/address"
88
+ },
89
+ people: {
90
+ type: "array",
91
+ title: "People",
92
+ format: "tabs",
93
+ items: {
94
+ title: "Person",
95
+ headerTemplate: "{{i}} - {{self.name}}",
96
+ oneOf: [
97
+ {
98
+ $ref: "../fixtures/basic_person.json",
99
+ title: "Basic Person"
100
+ },
101
+ {
102
+ $ref: "../fixtures/person.json",
103
+ title: "Complex Person"
104
+ }
105
+ ]
106
+ }
107
+ },
108
+ link: {
109
+ $ref: '../fixtures/definitions.json#/properties/address'
110
+ }
111
+ }
112
+ },
113
+
114
+ // Seed the form with a starting value
115
+ startval: starting_value,
116
+
117
+ // Disable additional properties
118
+ no_additional_properties: true,
119
+
120
+ // Require all properties by default
121
+ required_by_default: true
122
+ });
123
+
124
+ // Hook up the submit button to log to the console
125
+ document.getElementById('submit').addEventListener('click',function() {
126
+ // Get the value from the editor
127
+ console.log(editor.getValue());
128
+ });
129
+
130
+ // Hook up the Restore to Default button
131
+ document.getElementById('restore').addEventListener('click',function() {
132
+ editor.setValue(starting_value);
133
+ });
134
+
135
+ // Hook up the enable/disable button
136
+ document.getElementById('enable_disable').addEventListener('click',function() {
137
+ // Enable form
138
+ if(!editor.isEnabled()) {
139
+ editor.enable();
140
+ }
141
+ // Disable form
142
+ else {
143
+ editor.disable();
144
+ }
145
+ });
146
+
147
+ // Hook up the validation indicator to update its
148
+ // status whenever the editor changes
149
+ editor.on('change',function() {
150
+ // Get an array of errors from the validator
151
+ var errors = editor.validate();
152
+
153
+ var indicator = document.getElementById('valid_indicator');
154
+
155
+ // Not valid
156
+ if(errors.length) {
157
+ indicator.style.color = 'red';
158
+ indicator.textContent = "not valid";
159
+ }
160
+ // Valid
161
+ else {
162
+ indicator.style.color = 'green';
163
+ indicator.textContent = "valid";
164
+ }
165
+ });
166
+ </script>
167
+ </body>
168
+ </html>
@@ -0,0 +1,81 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>string-simple-mde-editor</title>
6
+
7
+ <!-- json editor -->
8
+ <script src="../../dist/jsoneditor.js"></script>
9
+
10
+ <!-- simpleMDE-editor -->
11
+ <script src="./../../node_modules/simplemde/dist/simplemde.min.js"></script>
12
+ <link
13
+ rel="stylesheet"
14
+ href="./../../node_modules/simplemde/dist/simplemde.min.css"
15
+ />
16
+ </head>
17
+ <body>
18
+ <textarea class="debug" cols="30" rows="10"></textarea>
19
+ <button class="get-value">Get Value</button>
20
+ <div class="container"></div>
21
+
22
+ <script>
23
+ const container = document.querySelector(".container");
24
+ const debug = document.querySelector(".debug");
25
+
26
+ const schema = {
27
+ type: "array",
28
+ title: "string-simplemde-editor",
29
+ items: {
30
+ $schema: "http://json-schema.org/draft-07/schema#",
31
+ title: "Example",
32
+ type: "object",
33
+ format: "categories",
34
+ basicCategoryTitle: "Main Editor",
35
+ required: ["title"],
36
+ properties: {
37
+ title: {
38
+ type: "string",
39
+ format: "markdown",
40
+ default: "Lorem",
41
+ options: {
42
+ simplemde: {
43
+ spellChecker: false,
44
+ autorefresh: true,
45
+ },
46
+ },
47
+ },
48
+ content: {
49
+ type: "object",
50
+ title: "Tabbed Editor",
51
+ properties: {
52
+ description: {
53
+ title: "Test",
54
+ type: "string",
55
+ format: "markdown",
56
+ default: "Lorem ipsum.",
57
+ options: {
58
+ simplemde: {
59
+ spellChecker: false,
60
+ autorefresh: true,
61
+ },
62
+ },
63
+ },
64
+ },
65
+ },
66
+ },
67
+ },
68
+ };
69
+
70
+ var editor = new JSONEditor(container, {
71
+ schema: schema,
72
+ });
73
+
74
+ document
75
+ .querySelector(".get-value")
76
+ .addEventListener("click", function () {
77
+ debug.value = JSON.stringify(editor.getValue());
78
+ });
79
+ </script>
80
+ </body>
81
+ </html>
@@ -26,7 +26,8 @@
26
26
  schema: schema,
27
27
  enable_array_copy: true
28
28
  });
29
- document.querySelector('.get-value').addEventListener('click', function () {
29
+ editor.promise.then(() => {
30
+ document.querySelector('.get-value').addEventListener('click', function () {
30
31
  debug.value = JSON.stringify(editor.getValue());
31
32
  });
32
33
  editor.setValue(["A","B","C","D","E"]);
@@ -50,6 +51,8 @@
50
51
  alert('deleteAllRows');
51
52
  console.log('deleteAllRows');
52
53
  });
54
+ })
55
+
53
56
  </script>
54
57
 
55
58
  </body>
@@ -28,7 +28,7 @@
28
28
  theme: 'bootstrap4',
29
29
  use_default_values: false,
30
30
  show_errors: 'always',
31
- urn_resolver: (urn, callback) => {
31
+ urn_resolver: async (urn, callback) => {
32
32
  console.log('resolving ' + urn)
33
33
  let schema
34
34
 
@@ -68,13 +68,16 @@
68
68
  break
69
69
  default: return false
70
70
  }
71
-
72
- // simulate async
73
- window.setTimeout(() => {
74
- callback(JSON.stringify(schema))
75
- }, 500)
76
-
77
- return true
71
+ return new Promise((resolve) => {
72
+ // simulate async
73
+ window.setTimeout(() => {
74
+ console.log(schema)
75
+ resolve(JSON.stringify(schema))
76
+ }, 50);
77
+ })
78
+
79
+
80
+ //return true
78
81
  }
79
82
  })
80
83
 
@@ -0,0 +1,206 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8"/>
5
+ <title>Use name attributes</title>
6
+ <script src="../../dist/jsoneditor.js"></script>
7
+ </head>
8
+ <body>
9
+ <div class='container'></div>
10
+ <script>
11
+ var schema = {
12
+ "type": "object",
13
+ "title": "root",
14
+ "properties": {
15
+ "booleans": {
16
+ "type": "object",
17
+ "title": "booleans",
18
+ "properties": {
19
+ "boolean": {
20
+ "type": "boolean",
21
+ "title": "default"
22
+ },
23
+ "boolean-enum": {
24
+ "type": "boolean",
25
+ "title": "boolean enum select",
26
+ "format": "select",
27
+ "options": {
28
+ "enum_titles": [
29
+ "No",
30
+ "Yes"
31
+ ]
32
+ }
33
+ },
34
+ "boolean-enum-radio": {
35
+ "type": "boolean",
36
+ "title": "boolean enum radio",
37
+ "format": "radio",
38
+ "options": {
39
+ "enum_titles": [
40
+ "No",
41
+ "Yes"
42
+ ]
43
+ }
44
+ }
45
+ }
46
+ },
47
+ "strings": {
48
+ "type": "object",
49
+ "title": "strings",
50
+ "properties": {
51
+ "string": {
52
+ "type": "string",
53
+ "title": "default"
54
+ },
55
+ "string-enum": {
56
+ "type": "string",
57
+ "title": "string enum select",
58
+ "enum": [
59
+ "albert",
60
+ "betti",
61
+ "carl"
62
+ ],
63
+ "options": {
64
+ "enum_titles": [
65
+ "Albert",
66
+ "Betti",
67
+ "Carl"
68
+ ]
69
+ }
70
+ },
71
+ "string-radio": {
72
+ "type": "string",
73
+ "title": "string enum radio",
74
+ "format": "radio",
75
+ "enum": [
76
+ "albert",
77
+ "betti",
78
+ "carl"
79
+ ],
80
+ "options": {
81
+ "enum_titles": [
82
+ "Albert",
83
+ "Betti",
84
+ "Carl"
85
+ ]
86
+ }
87
+ }
88
+ }
89
+ },
90
+ "numbers": {
91
+ "type": "object",
92
+ "title": "numbers",
93
+ "properties": {
94
+ "number": {
95
+ "type": "number",
96
+ "title": "number"
97
+ },
98
+ "number-enum": {
99
+ "type": "number",
100
+ "title": "number enum select",
101
+ "enum": [
102
+ 1.5,
103
+ 2.5,
104
+ 3.5
105
+ ],
106
+ "options": {
107
+ "enum_titles": [
108
+ "small (1.5)",
109
+ "medium (2.5)",
110
+ "big (3.5)"
111
+ ]
112
+ }
113
+ },
114
+ "number-enum-radio": {
115
+ "type": "number",
116
+ "title": "number enum radio",
117
+ "format": "radio",
118
+ "enum": [
119
+ 1.5,
120
+ 2.5,
121
+ 3.5
122
+ ],
123
+ "options": {
124
+ "enum_titles": [
125
+ "small (1.5)",
126
+ "medium (2.5)",
127
+ "big (3.5)"
128
+ ]
129
+ }
130
+ }
131
+ }
132
+ },
133
+ "integers": {
134
+ "type": "object",
135
+ "title": "integers",
136
+ "properties": {
137
+ "integer": {
138
+ "type": "integer",
139
+ "title": "integer"
140
+ },
141
+ "integer-enum": {
142
+ "type": "integer",
143
+ "title": "integer enum select",
144
+ "enum": [
145
+ 1,
146
+ 2,
147
+ 3
148
+ ],
149
+ "options": {
150
+ "enum_titles": [
151
+ "small (1)",
152
+ "medium (2)",
153
+ "big (3)"
154
+ ]
155
+ }
156
+ },
157
+ "integer-enum-radio": {
158
+ "type": "number",
159
+ "title": "integer enum radio",
160
+ "format": "radio",
161
+ "enum": [
162
+ 1,
163
+ 2,
164
+ 3
165
+ ],
166
+ "options": {
167
+ "enum_titles": [
168
+ "small (1.5)",
169
+ "medium (2.5)",
170
+ "big (3.5)"
171
+ ]
172
+ }
173
+ }
174
+ }
175
+ },
176
+ "arrays": {
177
+ "type": "object",
178
+ "title": "arrays",
179
+ "properties": {
180
+ "string-array": {
181
+ "type": "array",
182
+ "title": "strings color",
183
+ "default": [
184
+ "#6d80dd",
185
+ "#b80f0f",
186
+ "#280606"
187
+ ],
188
+ "items": {
189
+ "type": "string",
190
+ "title": "color",
191
+ "format": "color"
192
+ }
193
+ }
194
+ }
195
+ }
196
+ }
197
+ }
198
+
199
+
200
+ var editor = new JSONEditor(document.querySelector('.container'), {
201
+ use_name_attributes: false,
202
+ schema: schema
203
+ })
204
+ </script>
205
+ </body>
206
+ </html>
@@ -1,72 +1,111 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
+
3
4
  <head>
4
- <meta charset="utf-8"/>
5
+ <meta charset="utf-8" />
5
6
  <script src="../../dist/jsoneditor.js"></script>
6
7
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
7
8
  <title>object-no-duplicated-id</title>
8
9
  </head>
10
+
9
11
  <body>
10
12
 
11
- <div class="container">
12
- <div class="form-group">
13
- <textarea id="value" class="form-control" rows="10"></textarea>
13
+ <div class="container">
14
+ <div class="form-group">
15
+ <textarea id="value" class="form-control" rows="10"></textarea>
16
+ </div>
17
+ <button id="get-value" class='btn btn-secondary'>get value</button>
18
+ <hr>
19
+ <div id='form-container'></div>
14
20
  </div>
15
- <button id="get-value" class='btn btn-secondary'>get value</button>
16
- <hr>
17
- <div id='form-container'></div>
18
- </div>
19
21
 
20
- <script>
21
- var formContainer = document.querySelector('#form-container')
22
- var value = document.querySelector('#value')
23
- var getValue = document.querySelector('#get-value')
22
+ <script>
23
+ var formContainer = document.querySelector('#form-container')
24
+ var value = document.querySelector('#value')
25
+ var getValue = document.querySelector('#get-value')
24
26
 
25
- var today = (offset) => {
26
- var t = new Date()
27
- t.setDate(t.getDate() + (offset || 0))
28
- return t.toISOString().split('T')[0]
29
- }
27
+ var today = (offset) => {
28
+ var t = new Date()
29
+ t.setDate(t.getDate() + (offset || 0))
30
+ return t.toISOString().split('T')[0]
31
+ }
30
32
 
31
- var schema = {
32
- 'type': 'object',
33
- 'properties': {
34
- 'uuid': {
35
- 'type': 'string',
36
- 'format': 'uuid',
37
- 'title': 'single uuid',
38
- 'required': true,
39
- 'default': 'banana'
40
- },
41
- 'uuidArray': {
42
- 'type': 'array',
43
- 'title': 'uuid array',
44
- 'required': true,
45
- 'items': {
46
- 'type': 'object',
47
- 'properties': {
48
- 'uuid': {
49
- 'type': 'string',
50
- 'format': 'uuid'
33
+ var schema = {
34
+ 'type': 'object',
35
+ 'properties': {
36
+ 'uuid': {
37
+ 'type': 'string',
38
+ 'format': 'uuid',
39
+ 'title': 'single uuid',
40
+ 'required': true,
41
+ 'default': 'banana'
42
+ },
43
+ 'uuidStringArray': {
44
+ 'type': 'array',
45
+ 'required': true,
46
+ 'title': 'array of uuids',
47
+ 'items': {
48
+ 'type': 'string',
49
+ 'format': 'uuid',
50
+ 'title': 'uuid string array item'
51
+ }
52
+ },
53
+ 'uuidObjectArray': {
54
+ 'type': 'array',
55
+ 'title': 'array of objects with uuid property',
56
+ 'required': true,
57
+ 'items': {
58
+ 'title': 'uuid object array item',
59
+ 'type': 'object',
60
+ 'properties': {
61
+ 'uuid': {
62
+ 'type': 'string',
63
+ 'format': 'uuid'
64
+ }
65
+ }
66
+ }
67
+ },
68
+ 'uuidStringTable': {
69
+ 'type': 'array',
70
+ 'required': true,
71
+ 'format': 'table',
72
+ 'title': 'array of uuids (table)',
73
+ 'items': {
74
+ 'title': 'uuid string table item',
75
+ 'type': 'string',
76
+ 'format': 'uuid'
77
+ }
78
+ },
79
+ 'uuidObjectTable': {
80
+ "type": "array",
81
+ "format": "table",
82
+ "title": "Array of objects (Table) with uuid property",
83
+ "items": {
84
+ 'title': 'uuid object table item',
85
+ "type": "object",
86
+ "properties": {
87
+ "uuid": {
88
+ "type": "string",
89
+ "format": "uuid",
90
+ }
51
91
  }
52
92
  }
53
93
  }
54
94
  }
55
95
  }
56
- }
57
-
58
- var editor = new JSONEditor(formContainer, {
59
- schema: schema,
60
- theme: 'bootstrap4',
61
- show_errors: 'always'
62
- })
63
96
 
64
- getValue.addEventListener('click', function () {
65
- value.value = JSON.stringify(editor.getValue())
66
- console.log(editor.getValue())
67
- })
97
+ var editor = new JSONEditor(formContainer, {
98
+ schema: schema,
99
+ theme: 'bootstrap4',
100
+ show_errors: 'always',
101
+ enable_array_copy: true,
102
+ })
68
103
 
69
- </script>
104
+ getValue.addEventListener('click', function () {
105
+ value.value = JSON.stringify(editor.getValue())
106
+ console.log(editor.getValue())
107
+ })
70
108
 
109
+ </script>
71
110
  </body>
72
- </html>
111
+ </html>