@json-editor/json-editor 1.3.5 → 1.17.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 (436) hide show
  1. package/.claude/settings.local.json +8 -0
  2. package/.env +2 -0
  3. package/.env-dist +2 -0
  4. package/.eslintrc +10 -0
  5. package/.github/PULL_REQUEST_TEMPLATE.md +9 -0
  6. package/.github/workflows/build.yml +70 -0
  7. package/.travis.yml +63 -9
  8. package/CHANGELOG.md +1152 -0
  9. package/CONTRIBUTING.md +44 -5
  10. package/Makefile +26 -0
  11. package/README.md +765 -138
  12. package/README_ADDON.md +577 -0
  13. package/UPGRADING.md +46 -0
  14. package/build/CssToJson.js +55 -0
  15. package/codecept.conf.js +35 -0
  16. package/config/.eslintrc +7 -0
  17. package/config/codeceptjs_helpers.js +146 -0
  18. package/config/helpers.js +10 -0
  19. package/config/karma.conf.js +89 -0
  20. package/config/readme.md +31 -0
  21. package/config/webpack.common.js +71 -0
  22. package/config/webpack.dev.js +15 -0
  23. package/config/webpack.nonmin.js +19 -0
  24. package/config/webpack.prod.js +24 -0
  25. package/dist/jsoneditor.js +2 -11013
  26. package/dist/jsoneditor.js.LICENSE.txt +15 -0
  27. package/dist/nonmin/jsoneditor.js +31392 -0
  28. package/dist/nonmin/jsoneditor.js.map +1 -0
  29. package/docs/basic.html +2 -2
  30. package/docs/basic_person.json +2 -1
  31. package/docs/choices.html +86 -0
  32. package/docs/cleave.html +11 -19
  33. package/docs/colorpicker.html +194 -0
  34. package/docs/css_integration.html +56 -54
  35. package/docs/custom-editor.html +92 -0
  36. package/docs/datetime.html +48 -21
  37. package/docs/describedby.html +161 -0
  38. package/docs/enumsource.html +67 -0
  39. package/docs/form-submission.html +162 -0
  40. package/docs/imask.html +192 -0
  41. package/docs/index.html +606 -423
  42. package/docs/materialize_css.html +1 -1
  43. package/docs/meta-schema.html +793 -0
  44. package/docs/meta_schema.json +446 -400
  45. package/docs/polyfills/assign.js +29 -0
  46. package/docs/radio.html +156 -0
  47. package/docs/recursive.html +15 -17
  48. package/docs/scripts/ajv-validator.js +8695 -0
  49. package/docs/select2.html +15 -9
  50. package/docs/selectize.html +11 -9
  51. package/docs/signature.html +12 -11
  52. package/docs/starrating.html +5 -17
  53. package/docs/upload.html +33 -23
  54. package/docs/uuid.html +70 -0
  55. package/docs/wysiwyg.html +14 -7
  56. package/jasmine.json +11 -0
  57. package/package.json +74 -25
  58. package/release-notes.md +90 -0
  59. package/src/core.js +411 -611
  60. package/src/defaults.js +385 -306
  61. package/src/editor.js +761 -520
  62. package/src/editors/ace.js +90 -0
  63. package/src/editors/array/choices.js +104 -0
  64. package/src/editors/array/select2.js +112 -0
  65. package/src/editors/array/selectize.js +108 -86
  66. package/src/editors/array.css +9 -0
  67. package/src/editors/array.css.js +3 -0
  68. package/src/editors/array.js +812 -695
  69. package/src/editors/autocomplete.js +59 -0
  70. package/src/editors/base64.js +148 -129
  71. package/src/editors/button.js +104 -0
  72. package/src/editors/checkbox.js +111 -76
  73. package/src/editors/choices.css +3 -0
  74. package/src/editors/choices.css.js +3 -0
  75. package/src/editors/choices.js +71 -0
  76. package/src/editors/colorpicker.js +105 -0
  77. package/src/editors/datetime.js +93 -79
  78. package/src/editors/describedby.js +190 -0
  79. package/src/editors/enum.js +131 -116
  80. package/src/editors/hidden.js +100 -86
  81. package/src/editors/index.js +81 -0
  82. package/src/editors/info.js +28 -0
  83. package/src/editors/integer.js +21 -8
  84. package/src/editors/ip.js +36 -0
  85. package/src/editors/jodit.js +66 -0
  86. package/src/editors/multiple.js +380 -241
  87. package/src/editors/multiselect.js +207 -207
  88. package/src/editors/null.js +15 -11
  89. package/src/editors/number.js +39 -30
  90. package/src/editors/object.css +41 -0
  91. package/src/editors/object.css.js +3 -0
  92. package/src/editors/object.js +1209 -1007
  93. package/src/editors/radio.js +128 -0
  94. package/src/editors/sceditor.js +74 -0
  95. package/src/editors/select.js +318 -342
  96. package/src/editors/select2.js +112 -0
  97. package/src/editors/selectize.js +89 -338
  98. package/src/editors/signature.js +100 -104
  99. package/src/editors/simplemde.js +103 -0
  100. package/src/{styles → editors}/starrating.css +11 -2
  101. package/src/editors/starrating.css.js +3 -0
  102. package/src/editors/starrating.js +126 -95
  103. package/src/editors/stepper.js +27 -0
  104. package/src/editors/string.js +352 -426
  105. package/src/editors/table.js +486 -410
  106. package/src/editors/upload.js +297 -131
  107. package/src/editors/uuid.js +49 -0
  108. package/src/iconlib.js +22 -27
  109. package/src/iconlibs/bootstrap.js +28 -0
  110. package/src/iconlibs/bootstrap2.js +28 -17
  111. package/src/iconlibs/bootstrap3.js +28 -17
  112. package/src/iconlibs/fontawesome3.js +28 -17
  113. package/src/iconlibs/fontawesome4.js +28 -18
  114. package/src/iconlibs/fontawesome5.js +28 -18
  115. package/src/iconlibs/foundation2.js +24 -17
  116. package/src/iconlibs/foundation3.js +28 -17
  117. package/src/iconlibs/index.js +27 -0
  118. package/src/iconlibs/jqueryui.js +28 -17
  119. package/src/iconlibs/materialicons.js +49 -44
  120. package/src/iconlibs/openiconic.js +28 -0
  121. package/src/iconlibs/spectre.js +28 -0
  122. package/src/resolvers.js +135 -0
  123. package/src/schemaloader.js +639 -0
  124. package/src/style.css +157 -0
  125. package/src/style.css.js +3 -0
  126. package/src/templates/default.js +46 -51
  127. package/src/templates/ejs.js +8 -10
  128. package/src/templates/handlebars.js +1 -3
  129. package/src/templates/hogan.js +7 -9
  130. package/src/templates/index.js +21 -0
  131. package/src/templates/lodash.js +6 -8
  132. package/src/templates/markup.js +6 -8
  133. package/src/templates/mustache.js +6 -8
  134. package/src/templates/swig.js +1 -3
  135. package/src/templates/underscore.js +6 -8
  136. package/src/theme.js +717 -426
  137. package/src/themes/barebones.css +35 -0
  138. package/src/themes/barebones.css.js +3 -0
  139. package/src/themes/barebones.js +31 -0
  140. package/src/themes/bootstrap2.js +302 -264
  141. package/src/themes/bootstrap3.css +53 -0
  142. package/src/themes/bootstrap3.css.js +3 -0
  143. package/src/themes/bootstrap3.js +356 -259
  144. package/src/themes/bootstrap4.css +89 -0
  145. package/src/themes/bootstrap4.css.js +3 -0
  146. package/src/themes/bootstrap4.js +744 -234
  147. package/src/themes/bootstrap5.css +97 -0
  148. package/src/themes/bootstrap5.css.js +3 -0
  149. package/src/themes/bootstrap5.js +687 -0
  150. package/src/themes/foundation.js +539 -465
  151. package/src/themes/html.css +60 -0
  152. package/src/themes/html.css.js +3 -0
  153. package/src/themes/html.js +69 -82
  154. package/src/themes/index.js +29 -0
  155. package/src/themes/jqueryui.js +181 -166
  156. package/src/themes/materialize.js +263 -291
  157. package/src/themes/spectre.css +208 -0
  158. package/src/themes/spectre.css.js +3 -0
  159. package/src/themes/spectre.js +443 -0
  160. package/src/themes/tailwind.css +303 -0
  161. package/src/themes/tailwind.css.js +3 -0
  162. package/src/themes/tailwind.js +469 -0
  163. package/src/utilities.js +127 -68
  164. package/src/validator.js +914 -551
  165. package/src/validators/ip-validator.js +51 -0
  166. package/tests/Dockerfile +3 -0
  167. package/tests/README.md +27 -6
  168. package/tests/codeceptjs/codecept.json +29 -5
  169. package/tests/codeceptjs/constrains/contains_test.js +37 -0
  170. package/tests/codeceptjs/constrains/dependentRequired_test.js +33 -0
  171. package/tests/codeceptjs/constrains/dependentSchemas_test.js +16 -0
  172. package/tests/codeceptjs/constrains/if-then-else_test.js +186 -0
  173. package/tests/codeceptjs/core_test.js +534 -68
  174. package/tests/codeceptjs/editors/advanced_test.js +12 -10
  175. package/tests/codeceptjs/editors/array_any_of_test.js +50 -0
  176. package/tests/codeceptjs/editors/array_test.js +935 -677
  177. package/tests/codeceptjs/editors/autocomplete_test.js +15 -0
  178. package/tests/codeceptjs/editors/button_test.js +50 -0
  179. package/tests/codeceptjs/editors/checkbox_test.js +21 -8
  180. package/tests/codeceptjs/editors/colorpicker_test.js +29 -0
  181. package/tests/codeceptjs/editors/datetime_test.js +33 -0
  182. package/tests/codeceptjs/editors/inheritance_test.js +10 -0
  183. package/tests/codeceptjs/editors/integer_test.js +82 -71
  184. package/tests/codeceptjs/editors/jodit_test.js +23 -0
  185. package/tests/codeceptjs/editors/multiple_test.js +27 -0
  186. package/tests/codeceptjs/editors/multiselect_test.js +6 -9
  187. package/tests/codeceptjs/editors/number_test.js +75 -67
  188. package/tests/codeceptjs/editors/object_test.js +337 -28
  189. package/tests/codeceptjs/editors/option-no_default_values_test.js +42 -0
  190. package/tests/codeceptjs/editors/programmatic-changes_test.js +20 -0
  191. package/tests/codeceptjs/editors/purify_test.js +26 -0
  192. package/tests/codeceptjs/editors/radio_test.js +9 -0
  193. package/tests/codeceptjs/editors/range_test.js +10 -0
  194. package/tests/codeceptjs/editors/rating_test.js +10 -16
  195. package/tests/codeceptjs/editors/select_test.js +46 -23
  196. package/tests/codeceptjs/editors/starrating_test.js +15 -0
  197. package/tests/codeceptjs/editors/stepper_test.js +37 -0
  198. package/tests/codeceptjs/editors/string_test.js +108 -101
  199. package/tests/codeceptjs/editors/table-confirm-delete_test.js +60 -55
  200. package/tests/codeceptjs/editors/tabs_test.js +14 -11
  201. package/tests/codeceptjs/editors/uuid_test.js +48 -0
  202. package/tests/codeceptjs/editors/validation_test.js +13 -9
  203. package/tests/codeceptjs/issues/issue-gh-1133_test.js +9 -0
  204. package/tests/codeceptjs/issues/issue-gh-1158-2_test.js +10 -0
  205. package/tests/codeceptjs/issues/issue-gh-1158_test.js +8 -0
  206. package/tests/codeceptjs/issues/issue-gh-1164_test.js +9 -0
  207. package/tests/codeceptjs/issues/issue-gh-1171_test.js +11 -0
  208. package/tests/codeceptjs/issues/issue-gh-1211_test.js +17 -0
  209. package/tests/codeceptjs/issues/issue-gh-1257_test.js +11 -0
  210. package/tests/codeceptjs/issues/issue-gh-1272_test.js +21 -0
  211. package/tests/codeceptjs/issues/issue-gh-1330_test.js +8 -0
  212. package/tests/codeceptjs/issues/issue-gh-1338_test.js +18 -0
  213. package/tests/codeceptjs/issues/issue-gh-1347_test.js +8 -0
  214. package/tests/codeceptjs/issues/issue-gh-1364_test.js +13 -0
  215. package/tests/codeceptjs/issues/issue-gh-1367_test.js +11 -0
  216. package/tests/codeceptjs/issues/issue-gh-1383_test.js +9 -0
  217. package/tests/codeceptjs/issues/issue-gh-1384_test.js +9 -0
  218. package/tests/codeceptjs/issues/issue-gh-1410_test.js +13 -0
  219. package/tests/codeceptjs/issues/issue-gh-1422_test.js +9 -0
  220. package/tests/codeceptjs/issues/issue-gh-1431_test.js +12 -0
  221. package/tests/codeceptjs/issues/issue-gh-1439_test.js +12 -0
  222. package/tests/codeceptjs/issues/issue-gh-1452_test.js +10 -0
  223. package/tests/codeceptjs/issues/issue-gh-1453_test.js +18 -0
  224. package/tests/codeceptjs/issues/issue-gh-1461_test.js +14 -0
  225. package/tests/codeceptjs/issues/issue-gh-1463_test.js +9 -0
  226. package/tests/codeceptjs/issues/issue-gh-1471_test.js +17 -0
  227. package/tests/codeceptjs/issues/issue-gh-1485_test.js +13 -0
  228. package/tests/codeceptjs/issues/issue-gh-1491_test.js +9 -0
  229. package/tests/codeceptjs/issues/issue-gh-1525_test.js +9 -0
  230. package/tests/codeceptjs/issues/issue-gh-1536_test.js +12 -0
  231. package/tests/codeceptjs/issues/issue-gh-1538_test.js +10 -0
  232. package/tests/codeceptjs/issues/issue-gh-1541_test.js +8 -0
  233. package/tests/codeceptjs/issues/issue-gh-1559_test.js +15 -0
  234. package/tests/codeceptjs/issues/issue-gh-1562_test.js +12 -0
  235. package/tests/codeceptjs/issues/issue-gh-1586_test.js +15 -0
  236. package/tests/codeceptjs/issues/issue-gh-1636_test.js +9 -0
  237. package/tests/codeceptjs/issues/issue-gh-795_test.js +13 -0
  238. package/tests/codeceptjs/issues/issue-gh-810_test.js +52 -0
  239. package/tests/codeceptjs/issues/issue-gh-812_test.js +25 -0
  240. package/tests/codeceptjs/meta-schema_test.js +85 -0
  241. package/tests/codeceptjs/schemaloader_test.js +14 -0
  242. package/tests/codeceptjs/steps.d.ts +13 -0
  243. package/tests/codeceptjs/steps_file.js +4 -4
  244. package/tests/codeceptjs/test-config.js +3 -0
  245. package/tests/codeceptjs/themes_test.js +564 -0
  246. package/tests/docker-compose-local.yml +5 -0
  247. package/tests/docker-compose.yml +23 -17
  248. package/tests/fixtures/basic_person.json +2 -1
  249. package/tests/fixtures/definitions.json +22 -0
  250. package/tests/fixtures/nested_object.json +26 -0
  251. package/tests/fixtures/properties.json +20 -0
  252. package/tests/fixtures/some_types.json +32 -0
  253. package/tests/fixtures/validation.json +1347 -0
  254. package/tests/pages/_demo.html +475 -0
  255. package/tests/pages/advanced.html +1 -1
  256. package/tests/pages/anyof-2.html +91 -0
  257. package/tests/pages/anyof.html +82 -0
  258. package/tests/pages/array-anyof.html +145 -0
  259. package/tests/pages/array-checkboxes-infotext.html +55 -0
  260. package/tests/pages/array-checkboxes.html +5 -2
  261. package/tests/pages/array-choices.html +48 -0
  262. package/tests/pages/array-events-table.html +70 -0
  263. package/tests/pages/array-events.html +75 -0
  264. package/tests/pages/array-header-template.html +60 -0
  265. package/tests/pages/array-integers.html +5 -2
  266. package/tests/pages/array-multiselects.html +5 -2
  267. package/tests/pages/array-nested-arrays.html +5 -2
  268. package/tests/pages/array-numbers.html +5 -2
  269. package/tests/pages/array-objects.html +5 -2
  270. package/tests/pages/array-ratings.html +5 -2
  271. package/tests/pages/array-selectize-create.html +63 -0
  272. package/tests/pages/array-selectize.html +54 -0
  273. package/tests/pages/array-selects.html +5 -2
  274. package/tests/pages/array-strings.html +5 -2
  275. package/tests/pages/array-table-responsive.html +66 -0
  276. package/tests/pages/array-unique-items-sort.html +81 -0
  277. package/tests/pages/array.html +5 -2
  278. package/tests/pages/assets/autocomplete.css +1 -0
  279. package/tests/pages/assets/autocomplete.min.js +1 -0
  280. package/tests/pages/assets/pages.css +130 -0
  281. package/tests/pages/autocomplete.html +72 -0
  282. package/tests/pages/button-callbacks.html +79 -0
  283. package/tests/pages/button-icons.html +39 -0
  284. package/tests/pages/button_state_mode_1.html +35 -0
  285. package/tests/pages/button_state_mode_2.html +36 -0
  286. package/tests/pages/checkbox-labels.html +116 -0
  287. package/tests/pages/colorpicker-no-3rd-party.html +45 -0
  288. package/tests/pages/colorpicker-use-vanilla-picker.html +52 -0
  289. package/tests/pages/container-attributes.html +51 -0
  290. package/tests/pages/contains.html +39 -0
  291. package/tests/pages/core.html +14 -7
  292. package/tests/pages/datetime.html +78 -0
  293. package/tests/pages/dependentRequired.html +72 -0
  294. package/tests/pages/dependentSchemas.html +53 -0
  295. package/tests/pages/disable-button-in-object-editors.html +57 -0
  296. package/tests/pages/editor-show-validation-errors.html +54 -0
  297. package/tests/pages/enforce-const.html +168 -0
  298. package/tests/pages/error-messages.html +48 -0
  299. package/tests/pages/form-name.html +111 -0
  300. package/tests/pages/grid-strict.html +308 -0
  301. package/tests/pages/grid.html +281 -0
  302. package/tests/pages/if-else.html +58 -0
  303. package/tests/pages/if-then-else-allOf.html +118 -0
  304. package/tests/pages/if-then-else-disable-fields.html +70 -0
  305. package/tests/pages/if-then-else.html +65 -0
  306. package/tests/pages/if-then.html +58 -0
  307. package/tests/pages/inheritance.html +80 -0
  308. package/tests/pages/integer.html +17 -10
  309. package/tests/pages/issues/_template.html +50 -0
  310. package/tests/pages/issues/issue-gh-1133.html +64 -0
  311. package/tests/pages/issues/issue-gh-1158-2.html +189 -0
  312. package/tests/pages/issues/issue-gh-1158.html +50 -0
  313. package/tests/pages/issues/issue-gh-1164.html +71 -0
  314. package/tests/pages/issues/issue-gh-1165.html +63 -0
  315. package/tests/pages/issues/issue-gh-1165.json +8 -0
  316. package/tests/pages/issues/issue-gh-1171.html +39 -0
  317. package/tests/pages/issues/issue-gh-1211.html +1022 -0
  318. package/tests/pages/issues/issue-gh-1233-failing.html +46 -0
  319. package/tests/pages/issues/issue-gh-1233-passing.html +49 -0
  320. package/tests/pages/issues/issue-gh-1257.html +77 -0
  321. package/tests/pages/issues/issue-gh-1272.html +167 -0
  322. package/tests/pages/issues/issue-gh-1330.html +52 -0
  323. package/tests/pages/issues/issue-gh-1338.html +74 -0
  324. package/tests/pages/issues/issue-gh-1347.html +142 -0
  325. package/tests/pages/issues/issue-gh-1364.html +64 -0
  326. package/tests/pages/issues/issue-gh-1367.html +49 -0
  327. package/tests/pages/issues/issue-gh-1383.html +31 -0
  328. package/tests/pages/issues/issue-gh-1383.json +14 -0
  329. package/tests/pages/issues/issue-gh-1384.html +31 -0
  330. package/tests/pages/issues/issue-gh-1384.json +36 -0
  331. package/tests/pages/issues/issue-gh-1410.html +57 -0
  332. package/tests/pages/issues/issue-gh-1422.html +68 -0
  333. package/tests/pages/issues/issue-gh-1431.html +49 -0
  334. package/tests/pages/issues/issue-gh-1439.html +69 -0
  335. package/tests/pages/issues/issue-gh-1452.html +98 -0
  336. package/tests/pages/issues/issue-gh-1453.html +45 -0
  337. package/tests/pages/issues/issue-gh-1461.html +55 -0
  338. package/tests/pages/issues/issue-gh-1463.html +41 -0
  339. package/tests/pages/issues/issue-gh-1466.html +63 -0
  340. package/tests/pages/issues/issue-gh-1471.html +49 -0
  341. package/tests/pages/issues/issue-gh-1485.html +59 -0
  342. package/tests/pages/issues/issue-gh-1491.html +59 -0
  343. package/tests/pages/issues/issue-gh-1525.html +62 -0
  344. package/tests/pages/issues/issue-gh-1536.html +55 -0
  345. package/tests/pages/issues/issue-gh-1538.html +56 -0
  346. package/tests/pages/issues/issue-gh-1541.html +51 -0
  347. package/tests/pages/issues/issue-gh-1541.json +9 -0
  348. package/tests/pages/issues/issue-gh-1559.html +68 -0
  349. package/tests/pages/issues/issue-gh-1562.html +170 -0
  350. package/tests/pages/issues/issue-gh-1586.html +48 -0
  351. package/tests/pages/issues/issue-gh-1636.html +52 -0
  352. package/tests/pages/issues/issue-gh-795.html +58 -0
  353. package/tests/pages/issues/issue-gh-810.html +149 -0
  354. package/tests/pages/issues/issue-gh-812.html +113 -0
  355. package/tests/pages/issues/issue-gh-823-meta-schema.html +35 -0
  356. package/tests/pages/issues/issue-gh-848.html +81 -0
  357. package/tests/pages/keep_only_existing_values.html +81 -0
  358. package/tests/pages/load-events.html +61 -0
  359. package/tests/pages/maxContains.html +40 -0
  360. package/tests/pages/meta-schema.html +793 -0
  361. package/tests/pages/meta_schema.json +740 -0
  362. package/tests/pages/minContains.html +40 -0
  363. package/tests/pages/number.html +53 -6
  364. package/tests/pages/object-case-sensitive-property-search-false.html +42 -0
  365. package/tests/pages/object-case-sensitive-property-search-true.html +42 -0
  366. package/tests/pages/object-no-additional-properties.html +68 -0
  367. package/tests/pages/object-no-duplicated-id.html +70 -0
  368. package/tests/pages/object-required-properties.html +261 -0
  369. package/tests/pages/object-show-opt-in.html +111 -0
  370. package/tests/pages/object-with-dependencies-array.html +58 -0
  371. package/tests/pages/object-with-dependencies.html +62 -0
  372. package/tests/pages/object.html +5 -3
  373. package/tests/pages/oneof-2.html +91 -0
  374. package/tests/pages/oneof.html +105 -0
  375. package/tests/pages/opt-in-widget.html +134 -0
  376. package/tests/pages/option-dependencies.html +107 -0
  377. package/tests/pages/option-no_default_values.html +60 -0
  378. package/tests/pages/per-editor-options.html +44 -0
  379. package/tests/pages/placeholder-options.html +57 -0
  380. package/tests/pages/programmatic-changes.html +121 -0
  381. package/tests/pages/prompt-paste-max-length-reached.html +51 -0
  382. package/tests/pages/purify.html +66 -0
  383. package/tests/pages/range.html +62 -0
  384. package/tests/pages/read-only.html +60 -8
  385. package/tests/pages/ready.html +44 -0
  386. package/tests/pages/references.html +168 -0
  387. package/tests/pages/remove-false-properties.html +85 -0
  388. package/tests/pages/select-values.html +91 -0
  389. package/tests/pages/select.html +4 -3
  390. package/tests/pages/show-validation-errors.html +73 -0
  391. package/tests/pages/starrating.html +86 -0
  392. package/tests/pages/stepper-manual.html +59 -0
  393. package/tests/pages/stepper.html +61 -0
  394. package/tests/pages/string-ace-editor.html +7 -3
  395. package/tests/pages/string-cleave.html +48 -0
  396. package/tests/pages/string-custom-attributes.html +9 -6
  397. package/tests/pages/string-formats.html +54 -0
  398. package/tests/pages/string-formats2.html +59 -0
  399. package/tests/pages/{array-move-events.html → string-jodit-editor.html} +21 -29
  400. package/tests/pages/string-sceditor.html +9 -7
  401. package/tests/pages/string-simplemde-editor.html +83 -0
  402. package/tests/pages/switcher-option.html +69 -0
  403. package/tests/pages/table.html +4 -2
  404. package/tests/pages/tabs.html +1 -1
  405. package/tests/pages/themes.html +517 -0
  406. package/tests/pages/title-hidden.html +75 -0
  407. package/tests/pages/translate-property.html +248 -0
  408. package/tests/pages/urn.html +98 -0
  409. package/tests/pages/use-name-attributes.html +207 -0
  410. package/tests/pages/uuid.html +113 -0
  411. package/tests/pages/validation-messages.json +705 -0
  412. package/tests/pages/validation.html +20 -730
  413. package/tests/unit/.eslintrc +8 -0
  414. package/tests/unit/core.spec.js +320 -0
  415. package/tests/unit/defaults.spec.js +40 -0
  416. package/tests/unit/editor.spec.js +172 -0
  417. package/tests/unit/editors/array.spec.js +87 -0
  418. package/tests/unit/editors/object.spec.js +81 -0
  419. package/tests/unit/editors/table.spec.js +93 -0
  420. package/tests/unit/readme.md +35 -0
  421. package/tests/unit/schemaloader.spec.js +576 -0
  422. package/tests/unit/validator.spec.js +104 -0
  423. package/tests/unit/validators/ip-validator.spec.js +62 -0
  424. package/Gruntfile.js +0 -226
  425. package/dist/css/jsoneditor.min.css +0 -1
  426. package/dist/jsoneditor.js.map +0 -1
  427. package/dist/jsoneditor.min.js +0 -19
  428. package/dist/jsoneditor.min.js.map +0 -1
  429. package/docs/demo.html +0 -646
  430. package/src/class.js +0 -68
  431. package/src/editors/rating.js +0 -152
  432. package/src/ie9.js +0 -51
  433. package/src/intro.js +0 -23
  434. package/src/jquery.js +0 -64
  435. package/src/outro.js +0 -2
  436. package/src/themes/jsoneditor.barebones-theme.js +0 -60
package/docs/index.html CHANGED
@@ -1,481 +1,664 @@
1
1
  <!DOCTYPE html>
2
- <html>
2
+ <html lang="en">
3
3
  <head>
4
- <meta charset="utf-8" />
5
- <title>JSON Editor Example</title>
6
-
7
- <!-- placeholders for the theme switcher -->
8
- <link rel='stylesheet' id='theme_stylesheet'>
9
- <link rel='stylesheet' id='icon_stylesheet'>
10
- <style>[class*="foundicon-"] {font-family: GeneralFoundicons;font-style: normal;}</style>
11
-
12
- <script src="https://cdn.jsdelivr.net/npm/@json-editor/json-editor@latest/dist/jsoneditor.min.js"></script>
13
-
14
- <script>
15
- /**
16
- * LZString compression library
17
- * Used to create direct links to the demo.
18
- * NOT REQUIRED for JSON Editor.
19
- * https://github.com/pieroxy/lz-string
20
- */
21
- var LZString={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",_f:String.fromCharCode,compressToBase64:function(e){if(e==null)return"";var t="";var n,r,i,s,o,u,a;var f=0;e=LZString.compress(e);while(f<e.length*2){if(f%2==0){n=e.charCodeAt(f/2)>>8;r=e.charCodeAt(f/2)&255;if(f/2+1<e.length)i=e.charCodeAt(f/2+1)>>8;else i=NaN}else{n=e.charCodeAt((f-1)/2)&255;if((f+1)/2<e.length){r=e.charCodeAt((f+1)/2)>>8;i=e.charCodeAt((f+1)/2)&255}else r=i=NaN}f+=3;s=n>>2;o=(n&3)<<4|r>>4;u=(r&15)<<2|i>>6;a=i&63;if(isNaN(r)){u=a=64}else if(isNaN(i)){a=64}t=t+LZString._keyStr.charAt(s)+LZString._keyStr.charAt(o)+LZString._keyStr.charAt(u)+LZString._keyStr.charAt(a)}return t},decompressFromBase64:function(e){if(e==null)return"";var t="",n=0,r,i,s,o,u,a,f,l,c=0,h=LZString._f;e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(c<e.length){u=LZString._keyStr.indexOf(e.charAt(c++));a=LZString._keyStr.indexOf(e.charAt(c++));f=LZString._keyStr.indexOf(e.charAt(c++));l=LZString._keyStr.indexOf(e.charAt(c++));i=u<<2|a>>4;s=(a&15)<<4|f>>2;o=(f&3)<<6|l;if(n%2==0){r=i<<8;if(f!=64){t+=h(r|s)}if(l!=64){r=o<<8}}else{t=t+h(r|i);if(f!=64){r=s<<8}if(l!=64){t+=h(r|o)}}n+=3}return LZString.decompress(t)},compressToUTF16:function(e){if(e==null)return"";var t="",n,r,i,s=0,o=LZString._f;e=LZString.compress(e);for(n=0;n<e.length;n++){r=e.charCodeAt(n);switch(s++){case 0:t+=o((r>>1)+32);i=(r&1)<<14;break;case 1:t+=o(i+(r>>2)+32);i=(r&3)<<13;break;case 2:t+=o(i+(r>>3)+32);i=(r&7)<<12;break;case 3:t+=o(i+(r>>4)+32);i=(r&15)<<11;break;case 4:t+=o(i+(r>>5)+32);i=(r&31)<<10;break;case 5:t+=o(i+(r>>6)+32);i=(r&63)<<9;break;case 6:t+=o(i+(r>>7)+32);i=(r&127)<<8;break;case 7:t+=o(i+(r>>8)+32);i=(r&255)<<7;break;case 8:t+=o(i+(r>>9)+32);i=(r&511)<<6;break;case 9:t+=o(i+(r>>10)+32);i=(r&1023)<<5;break;case 10:t+=o(i+(r>>11)+32);i=(r&2047)<<4;break;case 11:t+=o(i+(r>>12)+32);i=(r&4095)<<3;break;case 12:t+=o(i+(r>>13)+32);i=(r&8191)<<2;break;case 13:t+=o(i+(r>>14)+32);i=(r&16383)<<1;break;case 14:t+=o(i+(r>>15)+32,(r&32767)+32);s=0;break}}return t+o(i+32)},decompressFromUTF16:function(e){if(e==null)return"";var t="",n,r,i=0,s=0,o=LZString._f;while(s<e.length){r=e.charCodeAt(s)-32;switch(i++){case 0:n=r<<1;break;case 1:t+=o(n|r>>14);n=(r&16383)<<2;break;case 2:t+=o(n|r>>13);n=(r&8191)<<3;break;case 3:t+=o(n|r>>12);n=(r&4095)<<4;break;case 4:t+=o(n|r>>11);n=(r&2047)<<5;break;case 5:t+=o(n|r>>10);n=(r&1023)<<6;break;case 6:t+=o(n|r>>9);n=(r&511)<<7;break;case 7:t+=o(n|r>>8);n=(r&255)<<8;break;case 8:t+=o(n|r>>7);n=(r&127)<<9;break;case 9:t+=o(n|r>>6);n=(r&63)<<10;break;case 10:t+=o(n|r>>5);n=(r&31)<<11;break;case 11:t+=o(n|r>>4);n=(r&15)<<12;break;case 12:t+=o(n|r>>3);n=(r&7)<<13;break;case 13:t+=o(n|r>>2);n=(r&3)<<14;break;case 14:t+=o(n|r>>1);n=(r&1)<<15;break;case 15:t+=o(n|r);i=0;break}s++}return LZString.decompress(t)},compressToUint8Array:function(e){var t=LZString.compress(e);var n=new Uint8Array(t.length*2);for(var r=0,i=t.length;r<i;r++){var s=t.charCodeAt(r);n[r*2]=s>>>8;n[r*2+1]=s%256}return n},decompressFromUint8Array:function(e){if(e===null||e===undefined){return LZString.decompress(e)}else{var t=new Array(e.length/2);for(var n=0,r=t.length;n<r;n++){t[n]=e[n*2]*256+e[n*2+1]}return LZString.decompress(String.fromCharCode.apply(null,t))}},compressToEncodedURIComponent:function(e){return LZString.compressToBase64(e).replace(/=/g,"$").replace(/\//g,"-")},decompressFromEncodedURIComponent:function(e){if(e)e=e.replace(/$/g,"=").replace(/-/g,"/");return LZString.decompressFromBase64(e)},compress:function(e){if(e==null)return"";var t,n,r={},i={},s="",o="",u="",a=2,f=3,l=2,c="",h=0,p=0,d,v=LZString._f;for(d=0;d<e.length;d+=1){s=e.charAt(d);if(!Object.prototype.hasOwnProperty.call(r,s)){r[s]=f++;i[s]=true}o=u+s;if(Object.prototype.hasOwnProperty.call(r,o)){u=o}else{if(Object.prototype.hasOwnProperty.call(i,u)){if(u.charCodeAt(0)<256){for(t=0;t<l;t++){h=h<<1;if(p==15){p=0;c+=v(h);h=0}else{p++}}n=u.charCodeAt(0);for(t=0;t<8;t++){h=h<<1|n&1;if(p==15){p=0;c+=v(h);h=0}else{p++}n=n>>1}}else{n=1;for(t=0;t<l;t++){h=h<<1|n;if(p==15){p=0;c+=v(h);h=0}else{p++}n=0}n=u.charCodeAt(0);for(t=0;t<16;t++){h=h<<1|n&1;if(p==15){p=0;c+=v(h);h=0}else{p++}n=n>>1}}a--;if(a==0){a=Math.pow(2,l);l++}delete i[u]}else{n=r[u];for(t=0;t<l;t++){h=h<<1|n&1;if(p==15){p=0;c+=v(h);h=0}else{p++}n=n>>1}}a--;if(a==0){a=Math.pow(2,l);l++}r[o]=f++;u=String(s)}}if(u!==""){if(Object.prototype.hasOwnProperty.call(i,u)){if(u.charCodeAt(0)<256){for(t=0;t<l;t++){h=h<<1;if(p==15){p=0;c+=v(h);h=0}else{p++}}n=u.charCodeAt(0);for(t=0;t<8;t++){h=h<<1|n&1;if(p==15){p=0;c+=v(h);h=0}else{p++}n=n>>1}}else{n=1;for(t=0;t<l;t++){h=h<<1|n;if(p==15){p=0;c+=v(h);h=0}else{p++}n=0}n=u.charCodeAt(0);for(t=0;t<16;t++){h=h<<1|n&1;if(p==15){p=0;c+=v(h);h=0}else{p++}n=n>>1}}a--;if(a==0){a=Math.pow(2,l);l++}delete i[u]}else{n=r[u];for(t=0;t<l;t++){h=h<<1|n&1;if(p==15){p=0;c+=v(h);h=0}else{p++}n=n>>1}}a--;if(a==0){a=Math.pow(2,l);l++}}n=2;for(t=0;t<l;t++){h=h<<1|n&1;if(p==15){p=0;c+=v(h);h=0}else{p++}n=n>>1}while(true){h=h<<1;if(p==15){c+=v(h);break}else p++}return c},decompress:function(e){if(e==null)return"";if(e=="")return null;var t=[],n,r=4,i=4,s=3,o="",u="",a,f,l,c,h,p,d,v=LZString._f,m={string:e,val:e.charCodeAt(0),position:32768,index:1};for(a=0;a<3;a+=1){t[a]=a}l=0;h=Math.pow(2,2);p=1;while(p!=h){c=m.val&m.position;m.position>>=1;if(m.position==0){m.position=32768;m.val=m.string.charCodeAt(m.index++)}l|=(c>0?1:0)*p;p<<=1}switch(n=l){case 0:l=0;h=Math.pow(2,8);p=1;while(p!=h){c=m.val&m.position;m.position>>=1;if(m.position==0){m.position=32768;m.val=m.string.charCodeAt(m.index++)}l|=(c>0?1:0)*p;p<<=1}d=v(l);break;case 1:l=0;h=Math.pow(2,16);p=1;while(p!=h){c=m.val&m.position;m.position>>=1;if(m.position==0){m.position=32768;m.val=m.string.charCodeAt(m.index++)}l|=(c>0?1:0)*p;p<<=1}d=v(l);break;case 2:return""}t[3]=d;f=u=d;while(true){if(m.index>m.string.length){return""}l=0;h=Math.pow(2,s);p=1;while(p!=h){c=m.val&m.position;m.position>>=1;if(m.position==0){m.position=32768;m.val=m.string.charCodeAt(m.index++)}l|=(c>0?1:0)*p;p<<=1}switch(d=l){case 0:l=0;h=Math.pow(2,8);p=1;while(p!=h){c=m.val&m.position;m.position>>=1;if(m.position==0){m.position=32768;m.val=m.string.charCodeAt(m.index++)}l|=(c>0?1:0)*p;p<<=1}t[i++]=v(l);d=i-1;r--;break;case 1:l=0;h=Math.pow(2,16);p=1;while(p!=h){c=m.val&m.position;m.position>>=1;if(m.position==0){m.position=32768;m.val=m.string.charCodeAt(m.index++)}l|=(c>0?1:0)*p;p<<=1}t[i++]=v(l);d=i-1;r--;break;case 2:return u}if(r==0){r=Math.pow(2,s);s++}if(t[d]){o=t[d]}else{if(d===i){o=f+f.charAt(0)}else{return null}}u+=o;t[i++]=f+o.charAt(0);r--;f=o;if(r==0){r=Math.pow(2,s);s++}}}};if(typeof module!=="undefined"&&module!=null){module.exports=LZString}
22
- </script>
4
+ <meta charset="utf-8"/>
5
+ <title>JSON Editor Interactive Example</title>
6
+ <script src="https://cdn.jsdelivr.net/npm/@json-editor/json-editor@latest/dist/jsoneditor.min.js"></script>
7
+ <script src="https://cdn.jsdelivr.net/npm/ace-builds@1.14.0/src-noconflict/ace.js"></script>
8
+ <script src="./polyfills/assign.js"></script>
9
+ <script src="https://cdn.jsdelivr.net/npm/lz-string@1.4.4/libs/lz-string.min.js"></script>
10
+ <script src="./scripts/ajv-validator.js"></script>
11
+ <link rel='stylesheet' id='theme-link'>
12
+ <link rel='stylesheet' id='iconlib-link'>
13
+ <style>
14
+ .maintenance-notice {
15
+ background-color: #fff3cd;
16
+ border: 1px solid #ffeaa7;
17
+ border-radius: 4px;
18
+ padding: 12px 16px;
19
+ margin-bottom: 20px;
20
+ color: #856404;
21
+ }
22
+ .maintenance-notice a {
23
+ color: #533102;
24
+ text-decoration: underline;
25
+ }
26
+ </style>
23
27
  </head>
24
-
25
28
  <body>
26
- <div class='container'>
27
- <div class='row'>
28
- <div class='span8 col-md-8 columns eight large-8 col s8'>
29
- <h2>Editor</h2>
29
+ <div class="container grid-xl" style="padding-top: 15px; padding-bottom: 30px;">
30
+ <div class="maintenance-notice">
31
+ <strong>Maintenance Mode:</strong> This library is in maintenance mode.
32
+ For active development, consider <a href="https://github.com/germanbisurgi/jedison" target="_blank">Jedison</a>.
33
+ </div>
34
+ <div class="row columns md:flex">
35
+ <div class='col-7 col-md-7 w-7/12'>
36
+ <h1>Editor</h1>
30
37
  <p>Below is the editor generated from the JSON Schema.</p>
31
-
32
- <div id='editor'></div>
38
+ <div id="json-editor-form"></div>
33
39
  </div>
34
- <div class='span4 col-md-4 columns four large-4 col s4'>
40
+ <div class='col-5 col-md-5 w-5/12'>
35
41
  <div>
36
- <a href='#' id='direct_link'>Direct Link</a> (preserves schema, value, and options)
42
+ <a class="btn btn-primary" id="direct-link" title="preserves schema, value, and options">Direct Link</a>
43
+ <a class="btn btn-secondary" href="?" title="reload editor with default example settings">Reset</a>
44
+ <a class="btn btn-secondary" href="https://github.com/json-editor/json-editor" title="github" target="_blank">GitHub</a>
37
45
  </div>
38
-
39
46
  <h2>JSON Output</h2>
40
- <p>You can also make changes to the JSON here and set the value in the editor by clicking <button class='btn btn-primary' id='setvalue'>Update Form</button></p>
41
- <textarea id='output' style='width: 100%; height: 300px; font-family: monospace;' class='form-control'></textarea>
42
-
47
+ <p>You can also make changes to the JSON here and set the value in the editor by clicking "Update Form"</p>
48
+ <label for="output-textarea"></label>
49
+ <button class='btn btn-primary btn-block' id='setvalue'>Update Form</button>
50
+ <textarea id='output-textarea' rows="15" style="width: 100%; font-family: monospace;"
51
+ class='form-control'></textarea>
52
+ <h2>Validation</h2>
53
+ <label for="validate-textarea">This will update whenever the form changes to show validation errors if there
54
+ are any.</label><br>
55
+ <textarea id='validate-textarea' readonly disabled class='form-control'></textarea>
43
56
  <h2>Options</h2>
44
- <div id='options_holder'>
45
- <div>
46
- <label>CSS Framework</label>
47
- <select id='theme_switcher' class='form-control browser-default'>
48
- <option value='barebones'>Barebones</option>
49
- <option value='html'>HTML</option>
50
- <option value='jqueryui'>jQuery UI</option>
51
- <option value='bootstrap2'>Bootstrap 2</option>
52
- <option value='bootstrap3'>Bootstrap 3</option>
53
- <option value='bootstrap4'>Bootstrap 4</option>
54
- <option value='foundation3'>Foundation 3</option>
55
- <option value='foundation4'>Foundation 4</option>
56
- <option value='foundation5'>Foundation 5</option>
57
- <option value='foundation6'>Foundation 6</option>
58
- <option value='materialize'>Materialize</option>
59
- </select>
60
- </div>
61
- <div>
62
- <label>Icon Library</label>
63
- <select id='icon_switcher' class='form-control browser-default'>
64
- <option value=''>None</option>
65
- <option value='jqueryui'>jQuery UI</option>
66
- <option value='bootstrap2'>Bootstrap 2 Glyphicons</option>
67
- <option value='bootstrap3'>Bootstrap 3 Glyphicons</option>
68
- <option value='foundation2'>Foundicons 2</option>
69
- <option value='foundation3'>Foundicons 3</option>
70
- <option value='fontawesome3'>FontAwesome 3</option>
71
- <option value='fontawesome4'>FontAwesome 4</option>
72
- <option value='fontawesome5'>FontAwesome 5</option>
73
- <option value='materialicons'>Material Icons</option>
74
- </select>
75
- </div>
76
- <div>
77
- <label>Object Layout</label>
78
- <select id='object_layout' class='form-control browser-default'>
79
- <option value='normal'>normal</option>
80
- <option value='grid'>grid</option>
81
- </select>
82
- </div>
83
- <div>
84
- <label>Show Errors</label>
85
- <select id='show_errors' class='form-control browser-default'>
86
- <option value='interaction'>On Interaction</option>
87
- <option value='change'>On Field Change</option>
88
- <option value='always'>Always</option>
89
- <option value='never'>Never</option>
90
- </select>
91
- </div>
92
- <div>
93
- <label>Boolean options</label>
94
- <select multiple size="9" id="boolean_options" style="width: 100%; height: inherit;" class="form-control browser-default">
95
- <option value='required_by_default'>Object properties required by default</option>
96
- <option value='display_required_only'>Only show required properties by default</option>
97
- <option value='no_additional_properties'>No additional object properties</option>
98
- <option value='ajax'>Allow loading schemas via Ajax</option>
99
- <option value='disable_edit_json'>Disable "Edit JSON" buttons</option>
100
- <option value='disable_collapse'>Disable collapse buttons</option>
101
- <option value='disable_properties'>Disable properties buttons</option>
102
- <option value='disable_array_add'>Disable array add buttons</option>
103
- <option value='disable_array_reorder'>Disable array move buttons</option>
104
- <option value='disable_array_delete'>Disable array delete buttons</option>
105
- <option value='disable_array_delete_all_rows'>Disable array delete all rows buttons</option>
106
- <option value='disable_array_delete_last_row'>Disable array delete last row buttons</option>
107
- </select>
108
- </div>
57
+ <div>
58
+ <label for="boolean-options-select">Boolean options</label><br>
59
+ <select multiple size="15" id="boolean-options-select" class="form-control browser-default">
60
+ <option value='use_default_values'>Default values based on the "type"</option>
61
+ <option value='use_name_attributes'>Use name attributes</option>
62
+ <option value='prompt_before_delete'>Prompt before delete</option>
63
+ <option value='case_sensitive_property_search'>Case sensitive property search</option>
64
+ <option value='required_by_default'>Object properties required by default</option>
65
+ <option value='display_required_only'>Only show required properties by default</option>
66
+ <option value='show_opt_in'>Show optional properties (with checkbox)</option>
67
+ <option value='no_additional_properties'>No additional object properties</option>
68
+ <option value='ajax'>Allow loading schemas via Ajax</option>
69
+ <option value='disable_edit_json'>Disable "Edit JSON" buttons</option>
70
+ <option value='disable_collapse'>Disable collapse buttons</option>
71
+ <option value='disable_properties'>Disable properties buttons</option>
72
+ <option value='disable_array_add'>Disable array add buttons</option>
73
+ <option value='disable_array_reorder'>Disable array move buttons</option>
74
+ <option value='disable_array_delete'>Disable array delete buttons</option>
75
+ <option value='enable_array_copy'>Add copy buttons to arrays</option>
76
+ <option value='array_controls_top'>Array controls will be displayed at top of list</option>
77
+ <option value='disable_array_delete_all_rows'>Disable array delete all rows buttons</option>
78
+ <option value='disable_array_delete_last_row'>Disable array delete last row buttons</option>
79
+ </select>
80
+ </div>
81
+ <div>
82
+ <label for="theme-select">theme</label><br>
83
+ <select id='theme-select' name="theme" class='form-control browser-default'>
84
+ <option value='barebones'>Barebones</option>
85
+ <option value='bootstrap3'>Bootstrap 3</option>
86
+ <option value='bootstrap4'>Bootstrap 4</option>
87
+ <option value='bootstrap5'>Bootstrap 5</option>
88
+ <option value='html'>HTML</option>
89
+ <option value='spectre'>Spectre</option>
90
+ <option value='tailwind'>Tailwind</option>
91
+ </select>
92
+ </div>
93
+ <div>
94
+ <label for="iconlib-select">iconlib</label><br>
95
+ <select id='iconlib-select' name="iconlib" class='form-control browser-default'>
96
+ <option value='fontawesome3'>fontawesome 3</option>
97
+ <option value='fontawesome4'>fontawesome 4</option>
98
+ <option value='fontawesome5'>fontawesome 5</option>
99
+ <option value='jqueryui'>jQuery UI</option>
100
+ <option value='openiconic'>Open Iconic</option>
101
+ <option value='spectre'>Spectre</option>
102
+ <option value='spectre'>Spectre</option>
103
+ <option value='bootstrap'>Bootstrap</option>
104
+ </select>
105
+ </div>
106
+ <div>
107
+ <label for="object-layout-select">Object Layout</label><br>
108
+ <select id='object-layout-select' class='form-control browser-default'>
109
+ <option value='normal'>normal</option>
110
+ <option value='grid'>grid</option>
111
+ </select>
112
+ </div>
113
+ <div>
114
+ <label for="show-errors-select">Show Errors</label><br>
115
+ <select id='show-errors-select' class='form-control browser-default'>
116
+ <option value='interaction'>On Interaction</option>
117
+ <option value='change'>On Field Change</option>
118
+ <option value='always'>Always</option>
119
+ <option value='never'>Never</option>
120
+ </select>
121
+ </div>
122
+ <div>
123
+ <label for="lib-select"
124
+ title="It's recommended that you click the Direct Link after changing these options">Include
125
+ External Library</label><br>
126
+ <select multiple size="10" id='lib-select' class='form-control browser-default'
127
+ title="It's reccomended that you click the Direct Link after changing these options">
128
+ <option value='ace_editor'>Ace Editor</option>
129
+ <option value='choices'>Choices</option>
130
+ <option value='sceditor'>SCEditor</option>
131
+ <option value='simplemde'>SimpleMDE</option>
132
+ <option value='select2'>Select2</option>
133
+ <option value='selectize'>Selectize</option>
134
+ <option value='flatpickr'>Flatpickr</option>
135
+ <option value='signature_pad'>Signature Pad</option>
136
+ <option value='mathjs'>Math.js</option>
137
+ <option value='cleavejs'>Cleave.js</option>
138
+ </select>
109
139
  </div>
110
-
111
- <h2>Validation</h2>
112
- <p>This will update whenever the form changes to show validation errors if there are any.</p>
113
- <textarea id='validate' style='width: 100%; height: 100px; font-family: monospace;' readonly disabled class='form-control'></textarea>
114
140
  </div>
115
141
  </div>
116
- <div class='row'>
117
- <div class='row'>
118
- <div class='span12 col-md-12 columns twelve large-12 col s12'>
119
- <h2>Schema</h2>
120
- <p>You can change the schema and see how the generated form looks. After you make changes, click <button class='btn btn-primary' id='setschema'>Update Schema</button></p>
121
142
 
122
- <textarea id='schema' style='width: 100%; height: 450px; font-family: monospace;' class='form-control'></textarea>
123
- </div>
143
+ <h2>Schema</h2>
144
+
145
+ <div class="row columns md:flex">
146
+ <div class='col-7 col-md-7 w-7/12'>
147
+ <label for="schema-textarea">You can change the schema and see how the generated form looks. After you make changes, click "Update Schema"</label>
148
+ <button class='btn btn-primary btn-block' id='setschema'>Update Schema</button>
149
+ <textarea id='schema-textarea' style="height: 100vh;"></textarea>
124
150
  </div>
125
- <div class='row'>
126
- <div class='span12 col-md-12 columns twelve large-12 col s12'>
127
- <h2>Code</h2>
128
- <pre><code>// Set default options
129
- JSONEditor.defaults.options.theme = 'bootstrap2';
130
-
131
- // Initialize the editor
132
- var editor = new JSONEditor(document.getElementById("editor_holder"),{
133
- schema: {
134
- type: "object",
135
- properties: {
136
- name: { "type": "string" }
137
- }
138
- }
139
- });
140
-
141
- // Set the value
142
- editor.setValue({
143
- name: "John Smith"
144
- });
145
-
146
- // Get the value
147
- var data = editor.getValue();
148
- console.log(data.name); // "John Smith"
149
-
150
- // Validate
151
- var errors = editor.validate();
152
- if(errors.length) {
153
- // Not valid
154
- }
155
-
156
- // Listen for changes
157
- editor.on("change", function() {
158
- // Do something...
159
- });</code></pre>
160
- </div>
151
+
152
+ <div class='col-5 col-md-5 w-5/12'>
153
+ <label for="je-errors-textarea">
154
+ <span>AJV (JE meta-schema): </span>
155
+ <code id="je-errors-count"></code>
156
+ </label>
157
+ <textarea id='je-errors-textarea'></textarea>
158
+
159
+ <br>
160
+
161
+ <label for="ajv-errors-textarea">
162
+ <span>AJV (meta-schema-2020-12): </span>
163
+ <code id="ajv-errors-count"></code>
164
+ </label>
165
+ <textarea id='ajv-errors-textarea'></textarea>
161
166
  </div>
162
167
  </div>
163
168
  </div>
164
169
  <script>
165
- (function() {
166
- var schema;
167
- if(window.location.href.match('[?&]schema=([^&]+)')) {
168
- try {
169
- schema = JSON.parse(LZString.decompressFromBase64(window.location.href.match('[?&]schema=([^&]+)')[1]));
170
- }
171
- catch(e) {
172
- console.log('invalid starting schema');
170
+ var defaultSchema = {
171
+ 'title': 'Person',
172
+ 'type': 'object',
173
+ 'required': [
174
+ 'name',
175
+ 'age',
176
+ 'date',
177
+ 'favorite_color',
178
+ 'gender',
179
+ 'location',
180
+ 'pets'
181
+ ],
182
+ 'properties': {
183
+ 'name': {
184
+ 'type': 'string',
185
+ 'description': 'First and Last name',
186
+ 'minLength': 4,
187
+ 'default': 'Jeremy Dorn'
188
+ },
189
+ 'age': {
190
+ 'type': 'integer',
191
+ 'default': 25,
192
+ 'minimum': 18,
193
+ 'maximum': 99
194
+ },
195
+ 'favorite_color': {
196
+ 'type': 'string',
197
+ 'format': 'color',
198
+ 'title': 'favorite color',
199
+ 'default': '#ffa500'
200
+ },
201
+ 'gender': {
202
+ 'type': 'string',
203
+ 'enum': [
204
+ 'male',
205
+ 'female',
206
+ 'other'
207
+ ]
208
+ },
209
+ 'date': {
210
+ 'type': 'string',
211
+ 'format': 'date',
212
+ 'options': {
213
+ 'flatpickr': {}
173
214
  }
174
- }
175
-
176
- // Default starting schema
177
- if(!schema) {
178
- schema = {
179
- title: "Person",
180
- type: "object",
181
- "required": [
182
- 'name',
183
- 'age',
184
- 'favorite_color',
185
- 'gender',
186
- 'location',
187
- 'pets'
188
- ],
189
- properties: {
190
- name: {
191
- type: "string",
192
- description: "First and Last name",
193
- minLength: 4,
194
- default: "Jeremy Dorn"
195
- },
196
- age: {
197
- type: "integer",
198
- default: 25,
199
- minimum: 18,
200
- maximum: 99
201
- },
202
- favorite_color: {
203
- type: "string",
204
- format: "color",
205
- title: "favorite color",
206
- default: "#ffa500"
207
- },
208
- gender: {
209
- type: "string",
210
- enum: ["male", "female"]
211
- },
212
- location: {
213
- type: "object",
214
- title: "Location",
215
- properties: {
216
- city: {
217
- type: "string",
218
- default: "San Francisco"
219
- },
220
- state: {
221
- type: "string",
222
- default: "CA"
223
- },
224
- citystate: {
225
- type: "string",
226
- description: "This is generated automatically from the previous two fields",
227
- template: "{{city}}, {{state}}",
228
- watch: {
229
- city: 'location.city',
230
- state: 'location.state'
231
- }
232
- }
233
- }
234
- },
235
- pets: {
236
- type: "array",
237
- format: "table",
238
- title: "Pets",
239
- uniqueItems: true,
240
- items: {
241
- type: "object",
242
- title: "Pet",
243
- properties: {
244
- type: {
245
- type: "string",
246
- enum: ["cat","dog","bird","reptile","other"],
247
- default: "dog"
248
- },
249
- name: {
250
- type: "string"
251
- }
252
- }
253
- },
254
- default: [
255
- {
256
- type: "dog",
257
- name: "Walter"
258
- }
259
- ]
260
- }
215
+ },
216
+ 'location': {
217
+ 'type': 'object',
218
+ 'title': 'Location',
219
+ 'properties': {
220
+ 'city': {
221
+ 'type': 'string',
222
+ 'default': 'San Francisco'
223
+ },
224
+ 'state': {
225
+ 'type': 'string',
226
+ 'default': 'CA'
227
+ },
228
+ 'citystate': {
229
+ 'type': 'string',
230
+ 'description': 'This is generated automatically from the previous two fields',
231
+ 'template': '{{city}}, {{state}}',
232
+ 'watch': {
233
+ 'city': 'location.city',
234
+ 'state': 'location.state'
261
235
  }
236
+ }
262
237
  }
238
+ },
239
+ 'pets': {
240
+ 'type': 'array',
241
+ 'format': 'table',
242
+ 'title': 'Pets',
243
+ 'uniqueItems': true,
244
+ 'items': {
245
+ 'type': 'object',
246
+ 'title': 'Pet',
247
+ 'properties': {
248
+ 'type': {
249
+ 'type': 'string',
250
+ 'enum': [
251
+ 'cat',
252
+ 'dog',
253
+ 'bird',
254
+ 'reptile',
255
+ 'other'
256
+ ],
257
+ 'default': 'dog'
258
+ },
259
+ 'name': {
260
+ 'type': 'string'
261
+ }
262
+ }
263
+ },
264
+ 'default': [
265
+ {
266
+ 'type': 'dog',
267
+ 'name': 'Walter'
268
+ }
269
+ ]
270
+ }
263
271
  }
272
+ }
264
273
 
265
- // Divs/textareas on the page
266
- var $schema = document.getElementById('schema');
267
- var $output = document.getElementById('output');
268
- var $editor = document.getElementById('editor');
269
- var $validate = document.getElementById('validate');
270
-
271
- // Buttons
272
- var $set_schema_button = document.getElementById('setschema');
273
- var $set_value_button = document.getElementById('setvalue');
274
-
275
- var jsoneditor;
276
-
277
- var updateDirectLink = function() {
278
- var url = window.location.href.replace(/\?.*/,'');
274
+ // parse url -> merge options -> refreshUI() -> initJsoneditor() -> direct link
275
+
276
+ /* ------------------------------------------------------------------- data */
277
+
278
+ var data = {}
279
+
280
+ var defaultOptions = Object.assign({}, JSONEditor.defaults.options, {
281
+ iconlib: 'fontawesome5',
282
+ object_layout: 'normal',
283
+ schema: defaultSchema,
284
+ show_errors: 'interaction',
285
+ theme: 'bootstrap4',
286
+ })
287
+
288
+ var jsoneditor = null
289
+ var directLink = document.querySelector('#direct-link')
290
+
291
+ var booleanOptionsSelect = document.querySelector('#boolean-options-select')
292
+ var head = document.getElementsByTagName('head')[0]
293
+ var iconlibSelect = document.querySelector('#iconlib-select')
294
+ var iconlibLink = document.querySelector('#iconlib-link')
295
+ var libSelect = document.querySelector('#lib-select')
296
+ var jsonEditorForm = document.querySelector('#json-editor-form')
297
+ var objectLayoutSelect = document.querySelector('#object-layout-select')
298
+ var setSchema = document.querySelector('#setschema')
299
+ var setValue = document.querySelector('#setvalue')
300
+ var showErrorsSelect = document.querySelector('#show-errors-select')
301
+ var themeSelect = document.querySelector('#theme-select')
302
+ var themeLink = document.querySelector('#theme-link')
303
+ var validateTextarea = document.querySelector('#validate-textarea')
304
+
305
+ var aceConfig = {
306
+ mode: 'ace/mode/json',
307
+ maxLines: Infinity,
308
+ minLines: 5,
309
+ showFoldWidgets: false,
310
+ showPrintMargin: false
311
+ }
279
312
 
280
- url += '?schema='+LZString.compressToBase64(JSON.stringify(schema));
281
- url += '&value='+LZString.compressToBase64(JSON.stringify(jsoneditor.getValue()));
313
+ var outputTextarea = ace.edit('output-textarea', aceConfig)
314
+ var schemaTextarea = ace.edit('schema-textarea', aceConfig)
315
+ var ajvErrorsTextarea = ace.edit('ajv-errors-textarea', aceConfig)
316
+ var jeErrorsTextarea = ace.edit('je-errors-textarea', aceConfig)
317
+ var ajvErrorsCount = document.querySelector('#ajv-errors-count')
318
+ var jeErrorsCount = document.querySelector('#je-errors-count')
319
+ var ajv = new AjvValidator()
320
+
321
+ const validateSchema = () => {
322
+ const dataToValidate = JSON.parse(schemaTextarea.getValue())
323
+ let errors
324
+
325
+ // AJV validation
326
+ ajvErrorsCount.textContent = '0'
327
+ errors = ajv.validate202012(dataToValidate)
328
+ ajvErrorsTextarea.setValue(JSON.stringify(errors, null, 2))
329
+ ajvErrorsCount.textContent = JSON.stringify(errors.length)
330
+ schemaTextarea.clearSelection(1)
331
+ ajvErrorsTextarea.clearSelection(1)
332
+
333
+ // JE validation with AJV
334
+ jeErrorsCount.textContent = '0'
335
+ errors = ajv.validateJeMetaSchema(dataToValidate)
336
+ jeErrorsTextarea.setValue(JSON.stringify(errors, null, 2))
337
+ jeErrorsCount.textContent = JSON.stringify(errors.length)
338
+ schemaTextarea.clearSelection(1)
339
+ jeErrorsTextarea.clearSelection(1)
340
+ }
282
341
 
283
- for(var i in JSONEditor.defaults.options) {
284
- if(!JSONEditor.defaults.options.hasOwnProperty(i)) continue;
285
- if(JSONEditor.defaults.options[i]===false) continue;
286
- else if(JSONEditor.defaults.options[i]===true) {
287
- url += '&'+i;
288
- }
289
- else {
290
- url += '&'+i+'='+JSONEditor.defaults.options[i];
291
- }
342
+ /* -------------------------------------------------------------- parse url */
343
+
344
+ var parseUrl = function () {
345
+ var url = window.location.search
346
+ var queryParamsString = url.substring(1, url.length)
347
+ var queryParams = queryParamsString.split('&')
348
+
349
+ if (queryParamsString.length) {
350
+ queryParams.forEach(function (queryParam) {
351
+ var splittedParam = queryParam.split('=')
352
+ var param = splittedParam[0]
353
+ var value = splittedParam[1]
354
+
355
+ // data query param
356
+ if (param === 'data') {
357
+ // compress schema and value
358
+ try {
359
+ data = JSON.parse(LZString.decompressFromBase64(value))
360
+ } catch (reason) {
361
+ }
292
362
  }
363
+ })
364
+ }
293
365
 
294
- document.getElementById('direct_link').href = url;
295
- };
296
-
297
- var reload = function(keep_value) {
298
- var startval = (jsoneditor && keep_value)? jsoneditor.getValue() : window.startval;
299
- window.startval = undefined;
300
-
301
- if(jsoneditor) jsoneditor.destroy();
302
- jsoneditor = new JSONEditor($editor,{
303
- schema: schema,
304
- startval: startval
305
- });
306
- window.jsoneditor = jsoneditor;
366
+ mergeOptions()
367
+ }
307
368
 
308
- // When the value of the editor changes, update the JSON output and validation message
309
- jsoneditor.on('change',function() {
310
- var json = jsoneditor.getValue();
369
+ /* ----------------------------------------------------------- mergeOptions */
311
370
 
312
- $output.value = JSON.stringify(json,null,2);
371
+ var mergeOptions = function () {
372
+ data.options = Object.assign(defaultOptions, data.options)
373
+ refreshUI()
374
+ }
313
375
 
314
- var validation_errors = jsoneditor.validate();
315
- // Show validation errors if there are any
316
- if(validation_errors.length) {
317
- $validate.value = JSON.stringify(validation_errors,null,2);
318
- }
319
- else {
320
- $validate.value = 'valid';
321
- }
376
+ /* -------------------------------------------------------------- refreshUI */
377
+
378
+ var refreshUI = function () {
379
+ // schema
380
+ schemaTextarea.setValue(JSON.stringify(data.options.schema, null, 2))
381
+ schemaTextarea.clearSelection(1)
382
+ validateSchema()
383
+
384
+ // theme
385
+ var themeMap = {
386
+ barebones: '',
387
+ bootstrap3: 'https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css',
388
+ bootstrap4: 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css',
389
+ bootstrap5: 'https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css',
390
+ html: '',
391
+ spectre: 'https://unpkg.com/spectre.css/dist/spectre.min.css',
392
+ tailwind: 'https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css'
393
+ }
394
+ themeLink.href = themeMap[data.options.theme]
395
+ themeSelect.value = data.options.theme
396
+
397
+ // iconlLib
398
+ var iconLibMap = {
399
+ fontawesome3: 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/3.2.1/css/font-awesome.css',
400
+ fontawesome4: 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.css',
401
+ fontawesome5: 'https://use.fontawesome.com/releases/v5.6.1/css/all.css',
402
+ jqueryui: 'https://code.jquery.com/ui/1.10.3/themes/south-street/jquery-ui.css',
403
+ openiconic: 'https://cdnjs.cloudflare.com/ajax/libs/open-iconic/1.1.1/font/css/open-iconic.min.css',
404
+ spectre: 'https://unpkg.com/spectre.css/dist/spectre-icons.min.css',
405
+ bootstrap: 'https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css'
406
+ }
407
+ iconlibLink.href = iconLibMap[data.options.iconlib]
408
+ iconlibSelect.value = data.options.iconlib
322
409
 
323
- updateDirectLink();
410
+ // object_layout
411
+ objectLayoutSelect.value = data.options.object_layout
324
412
 
325
- // Materialize extra.
326
- if (window.Materialize) window.Materialize.updateTextFields();
413
+ // show_errors
414
+ showErrorsSelect.value = data.options.show_errors
327
415
 
328
- });
329
- };
416
+ // boolean values
417
+ var booleanOptions = booleanOptionsSelect.children
418
+ for (var i = 0; i < booleanOptions.length; i++) {
419
+ var booleanValue = booleanOptions[i]
420
+ if (data.options[booleanValue.value]) {
421
+ booleanValue.selected = true
422
+ }
423
+ }
330
424
 
331
- // Start the schema and output textareas with initial values
332
- $schema.value = JSON.stringify(schema,null,2);
333
- $output.value = '';
425
+ // libs
426
+ var libMapping = {
427
+ ace_editor: {
428
+ js: [
429
+ 'https://cdn.jsdelivr.net/npm/ace-editor-builds@1.2.4/src-min-noconflict/ace.js'
430
+ ],
431
+ css: []
432
+ },
433
+ choices: {
434
+ js: [
435
+ 'https://cdn.jsdelivr.net/npm/choices.js/public/assets/scripts/choices.min.js'
436
+ ],
437
+ css: [
438
+ 'https://cdn.jsdelivr.net/npm/choices.js/public/assets/styles/choices.min.css'
439
+ ]
440
+ },
441
+ cleavejs: {
442
+ js: [
443
+ 'https://cdn.jsdelivr.net/npm/cleave.js@1.4.7/dist/cleave.min.js'
444
+ ],
445
+ css: []
446
+ },
447
+ sceditor: {
448
+ js: [
449
+ 'https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js',
450
+ 'https://cdn.jsdelivr.net/npm/sceditor@2.1.3/minified/sceditor.min.js',
451
+ 'https://cdn.jsdelivr.net/npm/sceditor@2.1.3/minified/formats/bbcode.js',
452
+ 'https://cdn.jsdelivr.net/npm/sceditor@2.1.3/minified/formats/xhtml.js'
453
+ ],
454
+ css: [
455
+ 'https://cdn.jsdelivr.net/npm/sceditor@2.1.3/minified/themes/default.min.css'
456
+ ]
457
+ },
458
+ simplemde: {
459
+ js: [
460
+ 'https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js'
461
+ ],
462
+ css: [
463
+ 'https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css'
464
+ ]
465
+ },
466
+ select2: {
467
+ js: [
468
+ 'https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js',
469
+ 'https://cdn.jsdelivr.net/npm/select2@4.0.6-rc.1/dist/js/select2.min.js'
470
+ ],
471
+ css: [
472
+ 'https://cdn.jsdelivr.net/npm/select2@4.0.6-rc.1/dist/css/select2.min.css'
473
+ ]
474
+ },
475
+ selectize: {
476
+ js: [
477
+ 'https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js',
478
+ 'https://cdn.jsdelivr.net/npm/selectize@0.12.6/dist/js/standalone/selectize.min.js'
479
+ ],
480
+ css: [
481
+ 'https://cdn.jsdelivr.net/npm/selectize@0.12.6/dist/css/selectize.min.css',
482
+ 'https://cdn.jsdelivr.net/npm/selectize@0.12.6/dist/css/selectize.default.min.css'
483
+ ]
484
+ },
485
+ flatpickr: {
486
+ js: [
487
+ 'https://cdn.jsdelivr.net/npm/flatpickr'
488
+ ],
489
+ css: [
490
+ 'https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css'
491
+ ]
492
+ },
493
+ signature_pad: {
494
+ js: [
495
+ 'https://cdn.jsdelivr.net/npm/signature_pad@2.3.2/dist/signature_pad.min.js'
496
+ ],
497
+ css: []
498
+ },
499
+ mathjs: {
500
+ js: [
501
+ 'https://cdn.jsdelivr.net/npm/mathjs@5.3.1/dist/math.min.js'
502
+ ],
503
+ css: []
504
+ },
505
+ }
334
506
 
335
- // When the 'update form' button is clicked, set the editor's value
336
- $set_value_button.addEventListener('click',function() {
337
- jsoneditor.setValue(JSON.parse($output.value));
338
- });
507
+ if (data.selectedLibs || data.unselectedLibs) {
339
508
 
340
- // Update the schema when the button is clicked
341
- $set_schema_button.addEventListener('click',function() {
342
- try {
343
- schema = JSON.parse($schema.value);
344
- }
345
- catch(e) {
346
- alert('Invalid Schema: '+e.message);
347
- return;
509
+ var booleanOptions = booleanOptionsSelect.children
510
+ for (var i = 0; i < booleanOptions.length; i++) {
511
+ var booleanValue = booleanOptions[i]
512
+ if (data.options[booleanValue.value]) {
513
+ booleanValue.selected = true
348
514
  }
515
+ }
349
516
 
350
- reload();
351
- });
352
-
353
- // Set the theme by loading the right stylesheets
354
- var setTheme = function(theme,no_reload) {
355
- theme = theme || '';
356
-
357
- var mapping = {
358
- barebones: '',
359
- html: '',
360
- bootstrap2: '//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css',
361
- bootstrap3: '//netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css',
362
- bootstrap4: '//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css',
363
- foundation3: '//cdnjs.cloudflare.com/ajax/libs/foundation/3.2.5/stylesheets/foundation.css',
364
- foundation4: '//cdnjs.cloudflare.com/ajax/libs/foundation/4.3.2/css/foundation.min.css',
365
- foundation5: '//cdnjs.cloudflare.com/ajax/libs/foundation/5.5.3/css/foundation.min.css',
366
- foundation6: '//cdnjs.cloudflare.com/ajax/libs/foundation/6.2.4/foundation.min.css',
367
- jqueryui: '//code.jquery.com/ui/1.10.3/themes/south-street/jquery-ui.css',
368
- materialize: '//cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css'
369
- };
370
-
371
- if(typeof mapping[theme] === 'undefined') {
372
- theme = 'bootstrap3';
373
- document.getElementById('theme_switcher').value = theme;
374
- }
517
+ var libSelectChildren = libSelect.children
518
+ for (var i = 0; i < libSelectChildren.length; i++) {
519
+ var child = libSelectChildren[i]
520
+ child.selected = data.selectedLibs.includes(child.value)
521
+ }
375
522
 
376
- var scriptMapping = {
377
- materialize: [
378
- 'https://code.jquery.com/jquery-3.2.1.min.js',
379
- 'https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js'
380
- ]
381
- }
523
+ // remove libraries
524
+ data.unselectedLibs.forEach(function (selectedLib) {
525
+ var concat = libMapping[selectedLib].js.concat(libMapping[selectedLib].css)
526
+ concat.forEach(function () {
527
+ var className = '.external_' + selectedLib
528
+ var toRemove = head.querySelector(className)
529
+ if (toRemove) {
530
+ toRemove.parentNode.removeChild(toRemove)
531
+ }
532
+ })
533
+ })
534
+
535
+ // add libraries
536
+ data.selectedLibs.forEach(function (selectedLib) {
537
+ // add js
538
+ libMapping[selectedLib].js.forEach(function (js) {
539
+ var scriptElement = document.createElement('script')
540
+ scriptElement.type = 'text/javascript'
541
+ scriptElement.src = js
542
+ scriptElement.async = false
543
+ scriptElement.classList.add('external_' + selectedLib)
544
+ head.appendChild(scriptElement)
545
+ })
546
+ // add css
547
+ libMapping[selectedLib].css.forEach(function (css) {
548
+ var linkElement = document.createElement('link')
549
+ linkElement.setAttribute('rel', 'stylesheet')
550
+ linkElement.setAttribute('type', 'text/css')
551
+ linkElement.setAttribute('href', css)
552
+ linkElement.classList.add('external_' + selectedLib)
553
+ head.appendChild(linkElement)
554
+ })
555
+ })
556
+ }
382
557
 
383
- var themeScripts = scriptMapping[theme],
384
- head = document.getElementsByTagName('head')[0],
385
- script;
386
-
387
- if (typeof themeScripts == 'string') { themeScripts = [themeScripts]; }
388
- if (Array.isArray(themeScripts)) {
389
- for (var i = 0; i < themeScripts.length; i++) {
390
- script = document.createElement('script');
391
- script.type = 'text/javascript';
392
- script.src = themeScripts[i];
393
- head.appendChild(script);
394
- }
395
- }
558
+ initJsoneditor()
559
+ }
396
560
 
397
- JSONEditor.defaults.options.theme = theme;
561
+ /* --------------------------------------------------------- initJsoneditor */
398
562
 
399
- document.getElementById('theme_stylesheet').href = mapping[theme];
400
- document.getElementById('theme_switcher').value = JSONEditor.defaults.options.theme;
563
+ var initJsoneditor = function () {
564
+ // destroy old JSONEditor instance if exists
565
+ if (jsoneditor) {
566
+ jsoneditor.destroy()
567
+ }
401
568
 
402
- if(!no_reload) reload(true);
403
- };
569
+ // new instance of JSONEditor
570
+ jsoneditor = new window.JSONEditor(jsonEditorForm, data.options)
571
+
572
+ // listen for changes
573
+ jsoneditor.on('change', function () {
574
+ // output
575
+ var json = jsoneditor.getValue()
576
+ outputTextarea.setValue(JSON.stringify(json, null, 2))
577
+ outputTextarea.clearSelection(1)
578
+
579
+ // validate
580
+ var validationErrors = jsoneditor.validate()
581
+ if (validationErrors.length) {
582
+ validateTextarea.value = JSON.stringify(validationErrors, null, 2)
583
+ } else {
584
+ validateTextarea.value = 'valid'
585
+ }
586
+ })
587
+ updateDirectLink()
588
+ }
404
589
 
405
- // Set the icontheme
406
- // Set the theme by loading the right stylesheets
407
- var setIconlib = function(iconlib,no_reload) {
408
- iconlib = iconlib || '';
409
- var mapping = {
410
- foundation2: '//cdnjs.cloudflare.com/ajax/libs/foundicons/2.0/stylesheets/general_foundicons.css',
411
- foundation3: '//cdnjs.cloudflare.com/ajax/libs/foundicons/3.0.0/foundation-icons.css',
412
- fontawesome3: '//cdnjs.cloudflare.com/ajax/libs/font-awesome/3.2.1/css/font-awesome.css',
413
- fontawesome4: '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.css',
414
- fontawesome5: 'https://use.fontawesome.com/releases/v5.6.1/css/all.css',
415
- materialicons: 'https://fonts.googleapis.com/icon?family=Material+Icons'
416
- };
590
+ /* ------------------------------------------------------- updateDirectLink */
417
591
 
418
- JSONEditor.defaults.options.iconlib = iconlib;
592
+ var updateDirectLink = function () {
593
+ var url = window.location.href.replace(/\?.*/, '')
594
+ url += '?data='
595
+ url += LZString.compressToBase64(JSON.stringify(data))
596
+ directLink.href = url
597
+ }
419
598
 
420
- document.getElementById('icon_stylesheet').href = mapping[iconlib] || '';
421
- document.getElementById('icon_switcher').value = JSONEditor.defaults.options.iconlib;
599
+ /* -------------------------------------------------------- event listeners */
422
600
 
423
- if(!no_reload) reload(true);
424
- };
601
+ setValue.addEventListener('click', function () {
602
+ jsoneditor.setValue(JSON.parse(outputTextarea.getValue()))
603
+ })
425
604
 
426
- var refreshBooleanOptions = function(no_reload) {
427
- var boolean_options = document.getElementById('boolean_options').children;
428
- for(var i=0; i<boolean_options.length; i++) {
429
- JSONEditor.defaults.options[boolean_options[i].value] = boolean_options[i].selected;
430
- }
431
- if(!no_reload) reload(true);
432
- };
433
-
434
- // Change listeners for options
435
- document.getElementById('theme_switcher').addEventListener('change',function() {
436
- setTheme(this.value);
437
- });
438
- document.getElementById('icon_switcher').addEventListener('change',function() {
439
- setIconlib(this.value);
440
- });
441
- document.getElementById('object_layout').addEventListener('change',function() {
442
- JSONEditor.defaults.options.object_layout = this.value;
443
- reload(true);
444
- });
445
- document.getElementById('show_errors').addEventListener('change',function() {
446
- JSONEditor.defaults.options.show_errors = this.value;
447
- reload(true);
448
- });
449
- document.getElementById('boolean_options').addEventListener('change',function() {
450
- refreshBooleanOptions();
451
- });
452
-
453
- // Get starting value from url
454
- if(window.location.href.match('[?&]value=([^&]+)')) {
455
- window.startval = JSON.parse(LZString.decompressFromBase64(window.location.href.match('[?&]value=([^&]+)')[1]));
605
+ setSchema.addEventListener('click', function () {
606
+ try {
607
+ data.options.schema = JSON.parse(schemaTextarea.getValue())
608
+ validateSchema()
609
+ } catch (e) {
610
+ alert('Invalid Schema: ' + e.message)
611
+ return
456
612
  }
613
+ refreshUI()
614
+ })
615
+
616
+ themeSelect.addEventListener('change', function () {
617
+ data.options.theme = this.value || ''
618
+ refreshUI()
619
+ })
620
+
621
+ iconlibSelect.addEventListener('change', function () {
622
+ data.options.iconlib = this.value || ''
623
+ refreshUI()
624
+ })
625
+
626
+ objectLayoutSelect.addEventListener('change', function () {
627
+ data.options.object_layout = this.value || ''
628
+ refreshUI()
629
+ })
630
+
631
+ showErrorsSelect.addEventListener('change', function () {
632
+ data.options.show_errors = this.value || ''
633
+ refreshUI()
634
+ })
635
+
636
+ booleanOptionsSelect.addEventListener('change', function () {
637
+ var booleanOptions = this.children
638
+ for (var i = 0; i < booleanOptions.length; i++) {
639
+ data.options[booleanOptions[i].value] = booleanOptions[i].selected
640
+ }
641
+ refreshUI()
642
+ })
457
643
 
458
- // Set options from direct link
459
- setTheme((window.location.href.match(/[?&]theme=([^&]+)/)||[])[1] || 'bootstrap2', true);
460
-
461
- setIconlib((window.location.href.match(/[?&]iconlib=([^&]*)/)||[null,'fontawesome4'])[1], true);
462
-
463
- document.getElementById('object_layout').value = (window.location.href.match(/[?&]object_layout=([^&]+)/)||[])[1] || 'normal';
464
- JSONEditor.defaults.options.object_layout = document.getElementById('object_layout').value;
644
+ libSelect.addEventListener('change', function () {
645
+ data.selectedLibs = []
646
+ data.unselectedLibs = []
465
647
 
466
- document.getElementById('show_errors').value = (window.location.href.match(/[?&]show_errors=([^&]+)/)||[])[1] || 'interaction';
467
- JSONEditor.defaults.options.show_errors = document.getElementById('show_errors').value;
648
+ var libs = this.children
468
649
 
469
- var boolean_options = document.getElementById('boolean_options').children;
470
- for(var i=0; i<boolean_options.length; i++) {
471
- if(window.location.href.match(new RegExp('[?&]'+boolean_options[i].getAttribute('value')+'([&=]|$)'))) {
472
- boolean_options[i].selected = true;
473
- }
650
+ for (var i = 0; i < libs.length; i++) {
651
+ if (libs[i].selected) {
652
+ data.selectedLibs.push(libs[i].value)
653
+ } else {
654
+ data.unselectedLibs.push(libs[i].value)
655
+ }
474
656
  }
475
- refreshBooleanOptions(true);
657
+ refreshUI()
658
+ })
659
+
660
+ parseUrl()
476
661
 
477
- reload();
478
- })();
479
662
  </script>
480
663
  </body>
481
664
  </html>