@json-editor/json-editor 2.5.2 → 2.6.1

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 (99) hide show
  1. package/.eslintrc +5 -2
  2. package/.github/PULL_REQUEST_TEMPLATE.md +6 -6
  3. package/.github/workflows/build.yml +58 -0
  4. package/CHANGELOG.md +41 -1
  5. package/CONTRIBUTING.md +1 -1
  6. package/README.md +39 -4
  7. package/README_ADDON.md +65 -0
  8. package/config/codeceptjs_helpers.js +4 -0
  9. package/dist/jsoneditor.js +2 -2
  10. package/dist/nonmin/jsoneditor.js +3711 -3324
  11. package/dist/nonmin/jsoneditor.js.map +1 -1
  12. package/docs/cleave.html +1 -1
  13. package/docs/datetime.html +1 -1
  14. package/docs/describedby.html +1 -1
  15. package/docs/index.html +4 -2
  16. package/docs/materialize_css.html +1 -1
  17. package/docs/meta_schema.json +0 -1
  18. package/docs/radio.html +1 -1
  19. package/docs/select2.html +1 -1
  20. package/docs/selectize.html +1 -1
  21. package/docs/starrating.html +1 -1
  22. package/docs/wysiwyg.html +1 -1
  23. package/package.json +27 -26
  24. package/release-notes.md +9 -9
  25. package/src/core.js +1 -0
  26. package/src/defaults.js +182 -94
  27. package/src/editor.js +28 -9
  28. package/src/editors/array.js +20 -16
  29. package/src/editors/autocomplete.js +1 -0
  30. package/src/editors/base64.js +5 -4
  31. package/src/editors/button.js +2 -2
  32. package/src/editors/checkbox.js +3 -3
  33. package/src/editors/datetime.js +2 -2
  34. package/src/editors/info.js +1 -1
  35. package/src/editors/multiple.js +8 -2
  36. package/src/editors/multiselect.js +5 -3
  37. package/src/editors/object.js +35 -21
  38. package/src/editors/radio.js +9 -4
  39. package/src/editors/select.js +6 -6
  40. package/src/editors/signature.js +3 -2
  41. package/src/editors/starrating.js +5 -5
  42. package/src/editors/string.js +6 -4
  43. package/src/editors/table.js +24 -14
  44. package/src/editors/upload.js +4 -3
  45. package/src/editors/uuid.js +1 -1
  46. package/src/iconlibs/index.js +2 -0
  47. package/src/iconlibs/openiconic.js +28 -0
  48. package/src/schemaloader.js +112 -28
  49. package/src/theme.js +6 -3
  50. package/src/themes/bootstrap3.js +4 -4
  51. package/src/themes/bootstrap4.js +11 -3
  52. package/src/themes/html.js +1 -2
  53. package/src/themes/materialize.js +1 -1
  54. package/src/themes/spectre.js +11 -8
  55. package/src/themes/tailwind.js +1 -1
  56. package/src/validator.js +128 -16
  57. package/tests/codeceptjs/core_test.js +125 -1
  58. package/tests/codeceptjs/editors/array_test.js +13 -11
  59. package/tests/codeceptjs/editors/button_test.js +6 -1
  60. package/tests/codeceptjs/editors/issues/issue-gh-812_test.js +32 -0
  61. package/tests/codeceptjs/editors/number_test.js +1 -1
  62. package/tests/codeceptjs/editors/object_test.js +216 -100
  63. package/tests/codeceptjs/editors/programmatic-changes_test.js +3 -1
  64. package/tests/codeceptjs/editors/radio_test.js +10 -0
  65. package/tests/codeceptjs/editors/rating_test.js +10 -11
  66. package/tests/codeceptjs/editors/select_test.js +17 -15
  67. package/tests/codeceptjs/editors/stepper_test.js +13 -1
  68. package/tests/codeceptjs/editors/string_test.js +81 -80
  69. package/tests/codeceptjs/editors/table-confirm-delete_test.js +58 -56
  70. package/tests/codeceptjs/editors/tabs_test.js +12 -10
  71. package/tests/codeceptjs/editors/validation_test.js +10 -8
  72. package/tests/codeceptjs/meta-schema_test.js +13 -14
  73. package/tests/codeceptjs/schemaloader_test.js +13 -0
  74. package/tests/codeceptjs/steps_file.js +4 -3
  75. package/tests/codeceptjs/themes_test.js +31 -0
  76. package/tests/docker-compose.yml +4 -3
  77. package/tests/fixtures/validation.json +382 -1
  78. package/tests/pages/_demo.html +2 -0
  79. package/tests/pages/anyof.html +80 -0
  80. package/tests/pages/issues/issue-gh-812.html +110 -0
  81. package/tests/pages/issues/issue-gh-848.html +81 -0
  82. package/tests/pages/meta_schema.json +0 -1
  83. package/tests/pages/object-no-additional-properties.html +27 -12
  84. package/tests/pages/object-required-properties.html +43 -9
  85. package/tests/pages/object-show-opt-in.html +110 -0
  86. package/tests/pages/object-with-dependencies-array.html +56 -0
  87. package/tests/pages/oneof.html +103 -0
  88. package/tests/pages/read-only.html +19 -4
  89. package/tests/pages/stepper-manual.html +57 -0
  90. package/tests/pages/themes.html +2 -0
  91. package/tests/pages/translate-property.html +247 -0
  92. package/tests/pages/urn.html +93 -0
  93. package/tests/unit/core.spec.js +2 -0
  94. package/tests/unit/defaults.spec.js +4 -2
  95. package/tests/unit/editor.spec.js +2 -0
  96. package/tests/unit/editors/array.spec.js +86 -0
  97. package/tests/unit/editors/table.spec.js +91 -0
  98. package/tests/unit/schemaloader.spec.js +362 -3
  99. package/tests/unit/validator.spec.js +14 -2
@@ -0,0 +1,247 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8"/>
5
+ <title>translate property</title>
6
+ <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
7
+ <script src="https://cdn.jsdelivr.net/npm/signature_pad@2.3.2/dist/signature_pad.min.js"></script>
8
+ <script src="../../dist/jsoneditor.js"></script>
9
+ </head>
10
+ <body>
11
+
12
+ <div class="container">
13
+ <div class='json-editor-container'></div>
14
+ </div>
15
+
16
+
17
+ <script>
18
+ var jsonEditorContainer = document.querySelector('.json-editor-container');
19
+ var value = document.querySelector('.value');
20
+
21
+ var schema = {
22
+ "type": "object",
23
+ "title": "objectTitle",
24
+ "description": "objectDescription",
25
+ "properties": {
26
+ "boolean": {
27
+ "type": "boolean",
28
+ "title": "booleanTitle",
29
+ "description": "booleanDescription",
30
+ "options": {
31
+ "infoText": "booleanInfoText"
32
+ }
33
+ },
34
+ "booleanCheckbox": {
35
+ "format": "checkbox",
36
+ "type": "boolean",
37
+ "title": "booleanTitle",
38
+ "description": "booleanDescription",
39
+ "options": {
40
+ "infoText": "booleanInfoText"
41
+ }
42
+ },
43
+ "string": {
44
+ "type": "string",
45
+ "title": "stringTitle",
46
+ "description": "stringDescription",
47
+ "options": {
48
+ "infoText": "stringInfoText"
49
+ }
50
+ },
51
+ "stringRadio": {
52
+ "format": "radio",
53
+ "type": "string",
54
+ "title": "stringRadioTitle",
55
+ "description": "stringRadioDescription",
56
+ "options": {
57
+ "infoText": "stringRadioInfoText"
58
+ },
59
+ "enum": ["Home", "Work"]
60
+ },
61
+ "integer": {
62
+ "type": "integer",
63
+ "title": "integerTitle",
64
+ "description": "integerDescription",
65
+ "options": {
66
+ "infoText": "integerInfoText"
67
+ }
68
+ },
69
+ "number": {
70
+ "type": "number",
71
+ "title": "numberTitle",
72
+ "description": "numberDescription",
73
+ "options": {
74
+ "infoText": "numberInfoText"
75
+ }
76
+ },
77
+ "array": {
78
+ "type": "array",
79
+ "title": "arrayTitle",
80
+ "description": "arrayDescription",
81
+ "options": {
82
+ "infoText": "arrayInfoText"
83
+ },
84
+ "items": {
85
+ "type": "string",
86
+ "title": "stringTitle",
87
+ "description": "stringDescription",
88
+ "options": {
89
+ "infoText": "stringInfoText"
90
+ }
91
+ }
92
+ },
93
+ "arrayTabs": {
94
+ "format": "tabs",
95
+ "type": "array",
96
+ "title": "arrayTabsTitle",
97
+ "description": "arrayTabsDescription",
98
+ "options": {
99
+ "infoText": "arrayTabsInfoText"
100
+ },
101
+ "items": {
102
+ "type": "string",
103
+ "title": "stringTitle",
104
+ "description": "stringDescription",
105
+ "options": {
106
+ "infoText": "stringInfoText"
107
+ }
108
+ }
109
+ },
110
+ "arrayTable": {
111
+ "format": "table",
112
+ "type": "array",
113
+ "title": "arrayTableTitle",
114
+ "description": "arrayTableDescription",
115
+ "options": {
116
+ "infoText": "arrayTableInfoText"
117
+ },
118
+ "items": {
119
+ "type": "string",
120
+ "title": "stringTitle",
121
+ "description": "stringDescription",
122
+ "options": {
123
+ "infoText": "stringInfoText"
124
+ }
125
+ }
126
+ },
127
+ "signature": {
128
+ "type": "signature",
129
+ "title": "signatureTitle",
130
+ "description": "signatureDescription",
131
+ "options": {
132
+ "infoText": "signatureInfoText",
133
+ "canvas_height": 200
134
+ }
135
+ },
136
+ "rating": {
137
+ "title": "ratingTitle",
138
+ "description": "ratingDescription",
139
+ "type": "integer",
140
+ "format": "rating",
141
+ "maximum": "5",
142
+ "exclusiveMaximum": false,
143
+ "options": {
144
+ "infoText": "ratingInfoText"
145
+ }
146
+ }
147
+ }
148
+ }
149
+
150
+ var dictionary = {
151
+ en: {
152
+ 'objectTitle': 'Object Title',
153
+ 'objectDescription': 'Object Description',
154
+ 'booleanTitle': 'Boolean Title',
155
+ 'booleanDescription': 'Boolean Description',
156
+ 'booleanInfoText': 'Boolean Info Text',
157
+ 'stringTitle': 'String Title',
158
+ 'stringDescription': 'String Description',
159
+ 'stringInfoText': 'String Info Text',
160
+ 'stringRadioTitle': 'String Radio Title',
161
+ 'stringRadioDescription': 'String Radio Description',
162
+ 'stringRadioInfoText': 'String Radio Info Text',
163
+ 'integerTitle': 'Integer Title',
164
+ 'integerDescription': 'Integer Description',
165
+ 'integerInfoText': 'Integer Info Text',
166
+ 'numberTitle': 'Number Title',
167
+ 'numberDescription': 'Number Description',
168
+ 'numberInfoText': 'Number Info Text',
169
+ 'arrayTitle': 'Array Title',
170
+ 'arrayDescription': 'Array Description',
171
+ 'arrayInfoText': 'Array Info Text',
172
+ 'arrayTabsTitle': 'Array Tabs Title',
173
+ 'arrayTabsDescription': 'Array Tabs Description',
174
+ 'arrayTabsInfoText': 'Array Tabs Info Text',
175
+ 'arrayTableTitle': 'Array Table Title',
176
+ 'arrayTableDescription': 'Array Table Description',
177
+ 'arrayTableInfoText': 'Array Table Info Text',
178
+ 'signatureTitle': 'Signature Title',
179
+ 'signatureDescription': 'Signature Description',
180
+ 'signatureInfoText': 'Signature Info Text',
181
+ 'ratingTitle': 'Rating Title',
182
+ 'ratingDescription': 'Rating Description',
183
+ 'ratingInfoText': 'Rating Info Text'
184
+ },
185
+ de: {
186
+ 'objectTitle': 'Object Title (but in german)',
187
+ 'objectDescription': 'Object Description (but in german)',
188
+ 'booleanTitle': 'Boolean Title (but in german)',
189
+ 'booleanDescription': 'Boolean Description (but in german)',
190
+ 'booleanInfoText': 'Boolean Info Text (but in german)',
191
+ 'stringTitle': 'String Title (but in german)',
192
+ 'stringDescription': 'String Description (but in german)',
193
+ 'stringInfoText': 'String Info Text (but in german)',
194
+ 'stringRadioTitle': 'String Radio Title (but in german)',
195
+ 'stringRadioDescription': 'String Radio Description (but in german)',
196
+ 'stringRadioInfoText': 'String Radio Info Text (but in german)',
197
+ 'integerTitle': 'Integer Title (but in german)',
198
+ 'integerDescription': 'Integer Description (but in german)',
199
+ 'integerInfoText': 'Integer Info Text (but in german)',
200
+ 'numberTitle': 'Number Title (but in german)',
201
+ 'numberDescription': 'Number Description (but in german)',
202
+ 'numberInfoText': 'Number Info Text (but in german)',
203
+ 'arrayTitle': 'Array Title (but in german)',
204
+ 'arrayDescription': 'Array Description (but in german)',
205
+ 'arrayInfoText': 'Array Info Text (but in german)',
206
+ 'arrayTabsTitle': 'Array Tabs Title (but in german)',
207
+ 'arrayTabsDescription': 'Array Tabs Description (but in german)',
208
+ 'arrayTabsInfoText': 'Array Tabs Info Text (but in german)',
209
+ 'arrayTableTitle': 'Array Table Title (but in german)',
210
+ 'arrayTableDescription': 'Array Table Description (but in german)',
211
+ 'arrayTableInfoText': 'Array Table Info Text (but in german)',
212
+ 'signatureTitle': 'Signature Title (but in german)',
213
+ 'signatureDescription': 'Signature Description (but in german)',
214
+ 'signatureInfoText': 'Signature Info Text (but in german)',
215
+ 'ratingTitle': 'Rating Title (but in german)',
216
+ 'ratingDescription': 'Rating Description (but in german)',
217
+ 'ratingInfoText': 'Rating Info Text (but in german)'
218
+ }
219
+ }
220
+
221
+ const urlParams = new URLSearchParams(window.location.search);
222
+ const lang = urlParams.get('lang') || 'en'
223
+
224
+ console.log('lang', lang)
225
+
226
+ JSONEditor.defaults.translateProperty = function (key) {
227
+ var text;
228
+
229
+ if (key !== null) {
230
+ text = dictionary[lang][key] ? dictionary[lang][key] : key
231
+ }
232
+
233
+ console.log('translateProperty', key, '=>', text)
234
+
235
+ return text;
236
+ };
237
+
238
+ var editor = new JSONEditor(jsonEditorContainer, {
239
+ schema: schema,
240
+ theme: 'bootstrap3',
241
+ use_default_values: false,
242
+ required_by_default: true
243
+ });
244
+ </script>
245
+
246
+ </body>
247
+ </html>
@@ -0,0 +1,93 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8"/>
5
+ <title>URN</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
+ <textarea class="value" cols="30" rows="10"></textarea>
14
+ <button class='get-value'>Get Value</button>
15
+ <button class='set-value'>Set Value</button>
16
+ <div class='json-editor-container'></div>
17
+
18
+ <script>
19
+ var jsonEditorContainer = document.querySelector('.json-editor-container');
20
+ var value = document.querySelector('.value');
21
+
22
+ var schema = {
23
+ $ref: 'urn:com:github:json-editor:name'
24
+ };
25
+
26
+ var editor = new JSONEditor(jsonEditorContainer, {
27
+ schema: schema,
28
+ theme: 'bootstrap4',
29
+ use_default_values: false,
30
+ show_errors: 'always',
31
+ urn_resolver: (urn, callback) => {
32
+ console.log('resolving ' + urn)
33
+ let schema
34
+
35
+ switch (urn) {
36
+ case 'urn:com:github:json-editor:name':
37
+ schema = {
38
+ type: 'object',
39
+ properties: {
40
+ fname: {
41
+ $ref: 'urn:com:github:json-editor:fname'
42
+ },
43
+ lname: {
44
+ $ref: 'urn:com:github:json-editor:lname#/definitions/lname'
45
+ }
46
+ }
47
+ }
48
+ break
49
+ case 'urn:com:github:json-editor:fname':
50
+ schema = {
51
+ id: 'urn:com:github:json-editor:fname',
52
+ type: 'string',
53
+ default: 'John',
54
+ minLength: 4
55
+ }
56
+ break
57
+ case 'urn:com:github:json-editor:lname':
58
+ schema = {
59
+ definitions: {
60
+ lname: {
61
+ id: 'urn:com:github:json-editor:lname',
62
+ type: 'string',
63
+ default: 'Doe',
64
+ minLength: 3
65
+ }
66
+ }
67
+ }
68
+ break
69
+ default: return false
70
+ }
71
+
72
+ // simulate async
73
+ window.setTimeout(() => {
74
+ callback(JSON.stringify(schema))
75
+ }, 500)
76
+
77
+ return true
78
+ }
79
+ })
80
+
81
+ document.querySelector('.get-value').addEventListener('click', function () {
82
+ value.value = JSON.stringify(editor.getValue())
83
+ console.log(editor.getValue())
84
+ })
85
+
86
+ document.querySelector('.set-value').addEventListener('click', function () {
87
+ editor.setValue({number_range: 2})
88
+ })
89
+
90
+ </script>
91
+
92
+ </body>
93
+ </html>
@@ -1,3 +1,5 @@
1
+ /* global describe beforeEach afterEach it expect Event */
2
+
1
3
  /*
2
4
  Stub test file
3
5
  TODO: Write unit tests for all interfaces
@@ -1,3 +1,5 @@
1
+ /* global describe beforeEach it expect */
2
+
1
3
  import { defaults } from '../../src/defaults'
2
4
 
3
5
  describe('defaults', () => {
@@ -32,7 +34,7 @@ describe('languages test', () => {
32
34
  expect(defaults.translate('error_notempty')).toBe('Value required')
33
35
  })
34
36
 
35
- it('throw error to unknown translate string', () => {
36
- expect(() => defaults.translate('unknown_message')).toThrow()
37
+ it('should return translation key for unknown translation string', () => {
38
+ expect(defaults.translate('unknown_message')).toBe('unknown_message')
37
39
  })
38
40
  })
@@ -1,3 +1,5 @@
1
+ /* global describe beforeEach afterEach it expect */
2
+
1
3
  import { JSONEditor } from '../../src/core'
2
4
 
3
5
  describe('Editor', () => {
@@ -0,0 +1,86 @@
1
+ import { JSONEditor } from '../../../src/core'
2
+
3
+ const fixture = [
4
+ {
5
+ title: 'Array Editor Test',
6
+ schema: {
7
+ type: 'array',
8
+ items: {
9
+ type: ['boolean', 'string', 'null', 'number']
10
+ }
11
+ },
12
+ value: [false]
13
+ },
14
+ {
15
+ title: 'Array Editor Test',
16
+ schema: {
17
+ type: 'array',
18
+ items: {
19
+ type: ['boolean', 'string', 'null', 'number']
20
+ }
21
+ },
22
+ value: ['']
23
+ },
24
+ {
25
+ title: 'Array Editor Test',
26
+ schema: {
27
+ type: 'array',
28
+ items: {
29
+ type: ['boolean', 'string', 'null', 'number']
30
+ }
31
+ },
32
+ value: [0]
33
+ },
34
+ {
35
+ title: 'Array Editor Test',
36
+ schema: {
37
+ type: 'array',
38
+ items: {
39
+ type: 'string'
40
+ }
41
+ },
42
+ options: {
43
+ use_default_values: false
44
+ },
45
+ value: ['']
46
+ },
47
+ {
48
+ title: 'Array Editor Test',
49
+ schema: {
50
+ type: 'array',
51
+ items: {
52
+ type: 'number'
53
+ }
54
+ },
55
+ options: {
56
+ use_default_values: false
57
+ },
58
+ value: [0]
59
+ }
60
+ ]
61
+
62
+ describe('Array Editor', () => {
63
+ let element
64
+ let editor
65
+
66
+ beforeEach(() => {
67
+ document.body.insertAdjacentHTML(
68
+ 'afterbegin',
69
+ '<div id="fixture"></div>')
70
+ element = document.getElementById('fixture')
71
+ })
72
+
73
+ afterEach(() => {
74
+ editor.destroy()
75
+ })
76
+
77
+ fixture.forEach(spec => {
78
+ it(spec.title, () => {
79
+ editor = new JSONEditor(element, {
80
+ schema: spec.schema
81
+ })
82
+ editor.setValue(spec.value);
83
+ expect(editor.getValue()).toEqual(spec.value)
84
+ })
85
+ })
86
+ })
@@ -0,0 +1,91 @@
1
+ import { JSONEditor } from '../../../src/core'
2
+
3
+ const fixture = [
4
+ {
5
+ title: 'Table Editor Test',
6
+ schema: {
7
+ type: 'array',
8
+ format: 'table',
9
+ items: {
10
+ type: ['boolean', 'string', 'null', 'number']
11
+ }
12
+ },
13
+ value: [false]
14
+ },
15
+ {
16
+ title: 'Table Editor Test',
17
+ schema: {
18
+ type: 'array',
19
+ format: 'table',
20
+ items: {
21
+ type: ['boolean', 'string', 'null', 'number']
22
+ }
23
+ },
24
+ value: ['']
25
+ },
26
+ {
27
+ title: 'Table Editor Test',
28
+ schema: {
29
+ type: 'array',
30
+ format: 'table',
31
+ items: {
32
+ type: ['boolean', 'string', 'null', 'number']
33
+ }
34
+ },
35
+ value: [0]
36
+ },
37
+ {
38
+ title: 'Table Editor Test',
39
+ schema: {
40
+ type: 'array',
41
+ format: 'table',
42
+ items: {
43
+ type: 'string'
44
+ }
45
+ },
46
+ options: {
47
+ use_default_values: false
48
+ },
49
+ value: ['']
50
+ },
51
+ {
52
+ title: 'Table Editor Test',
53
+ schema: {
54
+ type: 'array',
55
+ format: 'table',
56
+ items: {
57
+ type: 'number'
58
+ }
59
+ },
60
+ options: {
61
+ use_default_values: false
62
+ },
63
+ value: [0]
64
+ }
65
+ ]
66
+
67
+ describe('Table Editor', () => {
68
+ let element
69
+ let editor
70
+
71
+ beforeEach(() => {
72
+ document.body.insertAdjacentHTML(
73
+ 'afterbegin',
74
+ '<div id="fixture"></div>')
75
+ element = document.getElementById('fixture')
76
+ })
77
+
78
+ afterEach(() => {
79
+ editor.destroy()
80
+ })
81
+
82
+ fixture.forEach(spec => {
83
+ it(spec.title, () => {
84
+ editor = new JSONEditor(element, {
85
+ schema: spec.schema
86
+ })
87
+ editor.setValue(spec.value);
88
+ expect(editor.getValue()).toEqual(spec.value)
89
+ })
90
+ })
91
+ })