@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
@@ -22,7 +22,7 @@ jobs:
22
22
  include:
23
23
  - selenium-browser: "chrome"
24
24
  build-env: "build.prod"
25
- - build-nonmin: "chrome"
25
+ - selenium-browser: "chrome"
26
26
  build-env: "build.nonmin.travis"
27
27
  - selenium-browser: "firefox"
28
28
  build-env: "build.prod"
@@ -50,9 +50,18 @@ jobs:
50
50
  - name: Build
51
51
  run: docker-compose run -T --rm node npm run ${BUILD_ENV}
52
52
  - name: Test
53
- run: docker-compose exec -T node codeceptjs -c /repo/tests/codeceptjs/codecept.json run-multiple basic:${SELENIUM_BROWSER} --invert --grep '@optional'
53
+ run: |
54
+ docker-compose exec -T node codeceptjs -c /repo/tests/codeceptjs/codecept.json run-multiple basic:${SELENIUM_BROWSER} --invert --grep '@optional'
55
+ pwd
56
+ ls -la codeceptjs/output
57
+ - name: Test Artifacts
58
+ if: always()
59
+ uses: actions/upload-artifact@v3
60
+ with:
61
+ name: codeceptjs-output
62
+ path: tests/codeceptjs/output
63
+ retention-days: 30
54
64
  - name: Test (optional)
55
65
  continue-on-error: true
56
66
  run: docker-compose exec -T node codeceptjs -c /repo/tests/codeceptjs/codecept.json run-multiple basic:${SELENIUM_BROWSER} --grep '@optional'
57
67
 
58
-
package/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  ### Unreleased
2
2
 
3
+ ### dev
4
+
5
+ - Enh #1162 Added cache system for schema loader (chhill-redhat)
6
+
7
+ ### 2.8.0
8
+
9
+ - Added feature: use_name_attributes option
10
+
11
+ ### 2.7.0
12
+
13
+ - Fixed array uniqueItems sorting bug
14
+ - Configurable icons for type button editors
15
+ - Fixed autocomplete options rendering
16
+ - Editor gets .je-ready class when ready
17
+ - Regenerate unique UUID when copying arrays
18
+ - Added infoText for checkbox on "Spectre" and "Bootstrap 3" Themes
19
+ - Added configurable error messages at editor schema level feature
20
+ - Added form submission case study and linked it in the readme
21
+ - Fixed range output value rendering
22
+ - Added automated test for references
23
+ - Added SimpleMDE test page
24
+ - JSON pointers support for definitions
25
+ - Added infoText for multiselect enum
26
+ - Updated packages and fixed npm audits
27
+ - Using latest jquery in docs to resolve vulnerabilities
28
+ - fixed bug in upload editor
29
+ - Updated release-motes.md
30
+ - Added feature: override error messages in schema options
31
+ - fixed arbitrary JSON pointers not returning the schema at the pointer path
32
+ - Add infoText for enums with format `checkbox` (default)
33
+ - updated `jodit` devDependency (jodit markup changes)
34
+
3
35
  ### 2.6.1
4
36
 
5
37
  - Fix for #900 to close the properties modal when we click outside modal
package/README.md CHANGED
@@ -11,6 +11,7 @@ Some pull requests added from the original repo.
11
11
  JSON Editor takes a JSON Schema and uses it to generate an HTML form.
12
12
  It has full support for JSON Schema version 3 and 4 and can integrate with several popular CSS frameworks (bootstrap, spectre, tailwind).
13
13
 
14
+ Take a look at this [example](https://json-editor.github.io/json-editor/form-submission.html) for a simple form submission case study.
14
15
  ### Online Demo
15
16
 
16
17
  Check out an interactive demo: https://json-editor.github.io/json-editor/
@@ -138,6 +139,16 @@ Here are all the available options:
138
139
  <td>If <code>true</code>, JSON Editor will make ajax call with [credentials](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials).</td>
139
140
  <td><code>false</code></td>
140
141
  </tr>
142
+ <tr>
143
+ <td>ajax_cache_responses</td>
144
+ <td>If <code>true</code>, JSON Editor will cache external URLs' schemas in <code>localStorage</code> to avoid subsequent ajax calls.</td>
145
+ <td><code>false</code></td>
146
+ </tr>
147
+ <tr>
148
+ <td>ajax_cache_buster</td>
149
+ <td>If <code>ajax_cache_responses</code> is enabled, use this string to invalidate stale caches. E.g., this value should be changed when schemas are updated.</td>
150
+ <td>Current date in simplied ISO-8601 format (e.g., "2011-10-05" for October 5, 2011).</td>
151
+ </tr>
141
152
  <tr>
142
153
  <td>compact</td>
143
154
  <td>If <code>true</code>, the label will not be displayed/added.</td>
@@ -294,6 +305,11 @@ Here are all the available options:
294
305
  <td>A callback function to resolve an undefined Uniform Resource Name (URN) for <code>$ref</code>. The function receives a URN and callback to pass back a serialized JSON response. The function should return a boolean (true if the URN can be resolved; false otherwise).</td>
295
306
  <td><code>false</code></td>
296
307
  </tr>
308
+ <tr>
309
+ <td>use_name_attributes</td>
310
+ <td>If <code>true</code>, control inputs <code>name</code> attributes will be set.</td>
311
+ <td><code>true</code></td>
312
+ </tr>
297
313
  </tbody>
298
314
  </table>
299
315
 
@@ -521,7 +537,7 @@ Some of The [hyper-schema][hyper] specification is supported as well.
521
537
 
522
538
  ### $ref and definitions
523
539
 
524
- JSON Editor supports schema references to external URLs and local definitions. Here's an example showing both:
540
+ JSON Editor supports schema references to external URLs and local definitions as well as JSON Pointers. Here's an example:
525
541
 
526
542
  ```json
527
543
  {
@@ -533,6 +549,9 @@ JSON Editor supports schema references to external URLs and local definitions.
533
549
  },
534
550
  "location": {
535
551
  "$ref": "http://mydomain.com/geo.json"
552
+ },
553
+ "birthday": {
554
+ "$ref": "http://mydomain.com/person.json#/definitions/birthdate"
536
555
  }
537
556
  },
538
557
  "definitions": {
@@ -867,6 +886,57 @@ You can enable [Ace editor options](https://github.com/ajaxorg/ace/wiki/Configur
867
886
  }
868
887
  ```
869
888
 
889
+ ### Special editors
890
+
891
+ JSONEditor features specialized types of editors.
892
+
893
+ #### Button editor
894
+
895
+ Creates a button whose click callback can be defined in `JSONEditor.defaults.callbacks`. Options:
896
+
897
+ - `icon`: Renders an icon into the button. Must be supported by the iconLib used.
898
+ - `validated`: With `true` the button is disabled until the whole editor is valid.
899
+ - `action`: the name of the callback that will be invoked when the button is clicked.
900
+
901
+ > **Warning**
902
+ > For the form to render properly all callbacks used in `action`s must also be defined in `JSONEditor.defaults.callbacks`.
903
+
904
+ ```js
905
+ JSONEditor.defaults.callbacks = {
906
+ "button" : {
907
+ "myAction" : function (jseditor, e) {
908
+ alert('Button action')
909
+ }
910
+ }
911
+ }
912
+ ```
913
+
914
+ ```json
915
+ {
916
+ "type": "button",
917
+ "title": "Search",
918
+ "options": {
919
+ "button": {
920
+ "icon": "search",
921
+ "action": "myAction",
922
+ "validated": true
923
+ }
924
+ }
925
+ }
926
+ ```
927
+
928
+ #### Info editor
929
+
930
+ Displays a label and a description text.
931
+
932
+ ```json
933
+ {
934
+ "type": "info",
935
+ "title": "Important:",
936
+ "description": "Lorem ipsum dolor"
937
+ }
938
+ ```
939
+
870
940
  #### Booleans
871
941
 
872
942
  The default boolean editor is a select box with options "true" and "false". To use a checkbox instead, set the format to `checkbox`.
@@ -1035,23 +1105,24 @@ Editor Options
1035
1105
 
1036
1106
  Editors can accept options which alter the behavior in some way.
1037
1107
 
1038
- * `collapsed` - If set to true, the editor will start collapsed (works for objects and arrays)
1039
- * `disable_array_add` - If set to true, the "add row" button will be hidden (works for arrays)
1040
- * `disable_array_delete` - If set to true, all of the "delete" buttons will be hidden (works for arrays)
1041
- * `disable_array_delete_all_rows` - If set to true, just the "delete all rows" button will be hidden (works for arrays)
1042
- * `disable_array_delete_last_row` - If set to true, just the "delete last row" buttons will be hidden (works for arrays)
1043
- * `disable_array_reorder` - If set to true, the "move up/down" buttons will be hidden (works for arrays)
1044
- * `disable_collapse` - If set to true, the collapse button will be hidden (works for objects and arrays)
1045
- * `disable_edit_json` - If set to true, the Edit JSON button will be hidden (works for objects)
1046
- * `disable_properties` - If set to true, the Edit Properties button will be hidden (works for objects)
1047
- * `array_controls_top` - If set to true, array controls (add, delete etc) will be displayed at top of list (works for arrays)
1048
- * `enum_titles` - An array of display values to use for select box options in the same order as defined with the `enum` keyword. Works with schema using enum values.
1049
- * `expand_height` - If set to true, the input will auto expand/contract to fit the content. Works best with textareas.
1050
- * `grid_columns` - Explicitly set the number of grid columns (1-12) for the editor if it's within an object using a grid layout.
1051
- * `hidden` - If set to true, the editor will not appear in the UI (works for all types)
1052
- * `input_height` - Explicitly set the height of the input element. Should be a valid CSS width string (e.g. "100px"). Works best with textareas.
1053
- * `input_width` - Explicitly set the width of the input element. Should be a valid CSS width string (e.g. "100px"). Works for string, number, and integer data types.
1054
- * `remove_empty_properties` - If set to true for an object, empty object properties (i.e. those with falsy values) will not be returned by getValue().
1108
+ * `collapsed` - If set to true, the editor will start collapsed (works for objects and arrays)
1109
+ * `disable_array_add` - If set to true, the "add row" button will be hidden (works for arrays)
1110
+ * `disable_array_delete` - If set to true, all of the "delete" buttons will be hidden (works for arrays)
1111
+ * `disable_array_delete_all_rows` - If set to true, just the "delete all rows" button will be hidden (works for arrays)
1112
+ * `disable_array_delete_last_row` - If set to true, just the "delete last row" buttons will be hidden (works for arrays)
1113
+ * `disable_array_reorder` - If set to true, the "move up/down" buttons will be hidden (works for arrays)
1114
+ * `disable_collapse` - If set to true, the collapse button will be hidden (works for objects and arrays)
1115
+ * `disable_edit_json` - If set to true, the Edit JSON button will be hidden (works for objects)
1116
+ * `disable_properties` - If set to true, the Edit Properties button will be hidden (works for objects)
1117
+ * `array_controls_top` - If set to true, array controls (add, delete etc) will be displayed at top of list (works for arrays)
1118
+ * `enum` - See [Enum options](#enum-options)
1119
+ * `enum_titles` - An array of display values to use for select box options in the same order as defined with the `enum` keyword. Works with schema using enum values.
1120
+ * `expand_height` - If set to true, the input will auto expand/contract to fit the content. Works best with textareas.
1121
+ * `grid_columns` - Explicitly set the number of grid columns (1-12) for the editor if it's within an object using a grid layout.
1122
+ * `hidden` - If set to true, the editor will not appear in the UI (works for all types)
1123
+ * `input_height` - Explicitly set the height of the input element. Should be a valid CSS width string (e.g. "100px"). Works best with textareas.
1124
+ * `input_width` - Explicitly set the width of the input element. Should be a valid CSS width string (e.g. "100px"). Works for string, number, and integer data types.
1125
+ * `remove_empty_properties` - If set to true for an object, empty object properties (i.e. those with falsy values) will not be returned by getValue().
1055
1126
 
1056
1127
  ```json
1057
1128
  {
@@ -1086,6 +1157,43 @@ Using the option `infoText`, will create a info button, displaying the text you
1086
1157
  }
1087
1158
  ```
1088
1159
 
1160
+ Enum options
1161
+ ------------------
1162
+
1163
+ Using the option `enum`, it is possible to modify how enums with format `checkbox` (default) are displayed in the editor.
1164
+ It is an array of objects (described below), which must be in the same order as defined with the `enum` keyword.
1165
+
1166
+ Currently, the following is supported:
1167
+
1168
+ * `title`: *Optional* Display value shown instead of the enum value
1169
+ * `infoText`: *Optional* Creates an info button next to the title, displaying the text you set, on hovering.
1170
+
1171
+ It is possible also to set these options only for some enum values, to skip one enum value, define an empty object (`{}`).
1172
+
1173
+ ```json
1174
+ {
1175
+ "type": "array",
1176
+ "items": {
1177
+ "type": "string",
1178
+ "enum": ["1", "2", "3", "4"],
1179
+ "options": {
1180
+ "enum": [
1181
+ {},
1182
+ {
1183
+ "title": "Title 2"
1184
+ },
1185
+ { "infoText": "InfoText 3" },
1186
+ {
1187
+ "title": "Title 4",
1188
+ "infoText": "InfoText 4"
1189
+ }
1190
+ ]
1191
+ }
1192
+ }
1193
+ }
1194
+ ```
1195
+
1196
+ If both options `enum_titles[x]` and `enum[x].title` are set for the enum value `x`, than the title set under `enum[x].title` will be used.
1089
1197
 
1090
1198
  Dependencies
1091
1199
  ------------------
@@ -1542,6 +1650,28 @@ By default, all instances of JSON Editor will use the `en` language. To overrid
1542
1650
  JSONEditor.defaults.language = "es";
1543
1651
  ```
1544
1652
 
1653
+ You can also override translations per editor in the it's schema options.
1654
+
1655
+ ````json
1656
+ "error_const": {
1657
+ "type": "string",
1658
+ "title": "error_const",
1659
+ "const": "test",
1660
+ "default": "something else",
1661
+ "options": {
1662
+ "error_messages": {
1663
+ "en": {
1664
+ "error_const": "CUSTOM EN: Value must be the constant value"
1665
+ },
1666
+ "es": {
1667
+ "error_const": "CUSTOM ES: Value must be the constant value"
1668
+ }
1669
+ }
1670
+ }
1671
+ }
1672
+ ````
1673
+
1674
+
1545
1675
  Button Customization
1546
1676
  -----------------
1547
1677