@json-editor/json-editor 1.4.0-beta.0 → 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 (435) 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 +62 -16
  8. package/CHANGELOG.md +483 -113
  9. package/CONTRIBUTING.md +43 -4
  10. package/Makefile +26 -0
  11. package/README.md +632 -121
  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 -11550
  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 +42 -35
  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 +600 -582
  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 +9 -17
  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 +381 -327
  61. package/src/editor.js +733 -544
  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 +107 -130
  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 +141 -125
  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 +1190 -1068
  93. package/src/editors/radio.js +117 -101
  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 -433
  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 -265
  141. package/src/themes/bootstrap3.css +53 -0
  142. package/src/themes/bootstrap3.css.js +3 -0
  143. package/src/themes/bootstrap3.js +355 -262
  144. package/src/themes/bootstrap4.css +89 -0
  145. package/src/themes/bootstrap4.css.js +3 -0
  146. package/src/themes/bootstrap4.js +743 -237
  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 +535 -472
  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 -167
  156. package/src/themes/materialize.js +263 -292
  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 +909 -565
  165. package/src/validators/ip-validator.js +51 -0
  166. package/tests/Dockerfile +3 -0
  167. package/tests/README.md +25 -5
  168. package/tests/codeceptjs/codecept.json +9 -2
  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 -63
  174. package/tests/codeceptjs/editors/advanced_test.js +12 -9
  175. package/tests/codeceptjs/editors/array_any_of_test.js +50 -0
  176. package/tests/codeceptjs/editors/array_test.js +923 -657
  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 -6
  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 -64
  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 -7
  187. package/tests/codeceptjs/editors/number_test.js +75 -60
  188. package/tests/codeceptjs/editors/object_test.js +322 -80
  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 -10
  195. package/tests/codeceptjs/editors/select_test.js +47 -18
  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 +107 -91
  199. package/tests/codeceptjs/editors/table-confirm-delete_test.js +60 -54
  200. package/tests/codeceptjs/editors/tabs_test.js +15 -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 +11 -19
  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 +10 -8
  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 +10 -13
  301. package/tests/pages/grid.html +4 -7
  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 +56 -20
  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 -228
  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/src/class.js +0 -68
  430. package/src/editors/rating.js +0 -152
  431. package/src/ie9.js +0 -51
  432. package/src/intro.js +0 -23
  433. package/src/jquery.js +0 -64
  434. package/src/outro.js +0 -2
  435. package/src/themes/jsoneditor.barebones-theme.js +0 -60
@@ -1,804 +1,921 @@
1
- JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
2
- askConfirmation: function() {
1
+ import { AbstractEditor } from '../editor.js'
2
+ import { extend, generateUUID, trigger } from '../utilities.js'
3
+ import rules from './array.css.js'
4
+
5
+ export class ArrayEditor extends AbstractEditor {
6
+ askConfirmation () {
3
7
  if (this.jsoneditor.options.prompt_before_delete === true) {
4
- if (confirm("Are you sure you want to remove this node?") === false) {
5
- return false;
8
+ if (window.confirm(this.translate('button_delete_node_warning')) === false) {
9
+ return false
6
10
  }
7
11
  }
8
- return true;
9
- },
10
- getDefault: function() {
11
- return this.schema["default"] || [];
12
- },
13
- register: function() {
14
- this._super();
15
- if(this.rows) {
16
- for(var i=0; i<this.rows.length; i++) {
17
- this.rows[i].register();
18
- }
12
+ return true
13
+ }
14
+
15
+ register () {
16
+ super.register()
17
+ if (this.rows) {
18
+ this.rows.forEach(row => row.register())
19
19
  }
20
- },
21
- unregister: function() {
22
- this._super();
23
- if(this.rows) {
24
- for(var i=0; i<this.rows.length; i++) {
25
- this.rows[i].unregister();
26
- }
20
+ }
21
+
22
+ unregister () {
23
+ super.unregister()
24
+ if (this.rows) {
25
+ this.rows.forEach(row => row.unregister())
27
26
  }
28
- },
29
- getNumColumns: function() {
30
- var info = this.getItemInfo(0);
31
- // Tabs require extra horizontal space
32
- if(this.tabs_holder && this.schema.format !== 'tabs-top') {
33
- return Math.max(Math.min(12,info.width+2),4);
34
- }
35
- else {
36
- return info.width;
37
- }
38
- },
39
- enable: function() {
40
- if(!this.always_disabled) {
41
- if(this.add_row_button) this.add_row_button.disabled = false;
42
- if(this.remove_all_rows_button) this.remove_all_rows_button.disabled = false;
43
- if(this.delete_last_row_button) this.delete_last_row_button.disabled = false;
44
-
45
- if(this.rows) {
46
- for(var i=0; i<this.rows.length; i++) {
47
- this.rows[i].enable();
48
-
49
- if(this.rows[i].moveup_button) this.rows[i].moveup_button.disabled = false;
50
- if(this.rows[i].movedown_button) this.rows[i].movedown_button.disabled = false;
51
- if(this.rows[i].delete_button) this.rows[i].delete_button.disabled = false;
52
- }
53
- }
54
- this._super();
55
- }
56
- },
57
- disable: function(always_disabled) {
58
- if(always_disabled) this.always_disabled = true;
59
- if(this.add_row_button) this.add_row_button.disabled = true;
60
- if(this.remove_all_rows_button) this.remove_all_rows_button.disabled = true;
61
- if(this.delete_last_row_button) this.delete_last_row_button.disabled = true;
62
-
63
- if(this.rows) {
64
- for(var i=0; i<this.rows.length; i++) {
65
- this.rows[i].disable(always_disabled);
66
-
67
- if(this.rows[i].moveup_button) this.rows[i].moveup_button.disabled = true;
68
- if(this.rows[i].movedown_button) this.rows[i].movedown_button.disabled = true;
69
- if(this.rows[i].delete_button) this.rows[i].delete_button.disabled = true;
70
- }
27
+ }
28
+
29
+ getNumColumns () {
30
+ const info = this.getItemInfo(0)
31
+ /* Tabs require extra horizontal space */
32
+ if (this.tabs_holder && this.schema.format !== 'tabs-top') {
33
+ return Math.max(Math.min(12, info.width + 2), 4)
71
34
  }
72
- this._super();
73
- },
74
- preBuild: function() {
75
- this._super();
76
-
77
- this.rows = [];
78
- this.row_cache = [];
79
-
80
- this.hide_delete_buttons = this.options.disable_array_delete || this.jsoneditor.options.disable_array_delete;
81
- this.hide_delete_all_rows_buttons = this.hide_delete_buttons || this.options.disable_array_delete_all_rows || this.jsoneditor.options.disable_array_delete_all_rows;
82
- this.hide_delete_last_row_buttons = this.hide_delete_buttons || this.options.disable_array_delete_last_row || this.jsoneditor.options.disable_array_delete_last_row;
83
- this.hide_move_buttons = this.options.disable_array_reorder || this.jsoneditor.options.disable_array_reorder;
84
- this.hide_add_button = this.options.disable_array_add || this.jsoneditor.options.disable_array_add;
85
- this.show_copy_button = this.options.enable_array_copy || this.jsoneditor.options.enable_array_copy;
86
- this.array_controls_top = this.options.array_controls_top || this.jsoneditor.options.array_controls_top;
87
- },
88
- build: function() {
89
- var self = this;
90
-
91
- if(!this.options.compact) {
92
- this.header = document.createElement('label');
93
- this.header.textContent = this.getTitle();
94
- this.title = this.theme.getHeader(this.header);
95
- this.container.appendChild(this.title);
96
- this.title_controls = this.theme.getHeaderButtonHolder();
97
- this.title.appendChild(this.title_controls);
98
- if(this.schema.description) {
99
- this.description = this.theme.getDescription(this.schema.description);
100
- this.container.appendChild(this.description);
101
- }
102
- this.error_holder = document.createElement('div');
103
- this.container.appendChild(this.error_holder);
35
+ return info.width
36
+ }
104
37
 
105
- if(this.schema.format === 'tabs-top') {
106
- this.controls = this.theme.getHeaderButtonHolder();
107
- this.title.appendChild(this.controls);
108
- this.tabs_holder = this.theme.getTopTabHolder(this.getValidId(this.getItemTitle()));
109
- this.container.appendChild(this.tabs_holder);
110
- this.row_holder = this.theme.getTopTabContentHolder(this.tabs_holder);
38
+ enable () {
39
+ if (!this.always_disabled) {
40
+ this.setAvailability(this, false)
111
41
 
112
- this.active_tab = null;
42
+ if (this.rows) {
43
+ this.rows.forEach(row => {
44
+ row.enable()
45
+ this.setAvailability(row, false)
46
+ })
113
47
  }
114
- else if(this.schema.format === 'tabs') {
115
- this.controls = this.theme.getHeaderButtonHolder();
116
- this.title.appendChild(this.controls);
117
- this.tabs_holder = this.theme.getTabHolder(this.getValidId(this.getItemTitle()));
118
- this.container.appendChild(this.tabs_holder);
119
- this.row_holder = this.theme.getTabContentHolder(this.tabs_holder);
120
-
121
- this.active_tab = null;
122
- }
123
- else {
124
- this.panel = this.theme.getIndentedPanel();
125
- this.container.appendChild(this.panel);
126
- this.row_holder = document.createElement('div');
127
- this.panel.appendChild(this.row_holder);
128
- this.controls = this.theme.getButtonHolder();
48
+ super.enable()
49
+ }
50
+ }
51
+
52
+ disable (alwaysDisabled) {
53
+ if (alwaysDisabled) this.always_disabled = true
54
+ this.setAvailability(this, true)
55
+
56
+ if (this.rows) {
57
+ this.rows.forEach(row => {
58
+ row.disable(alwaysDisabled)
59
+ this.setAvailability(row, true)
60
+ })
61
+ }
62
+ super.disable()
63
+ }
64
+
65
+ setAvailability (element, val) {
66
+ if (element.add_row_button) element.add_row_button.disabled = val
67
+ if (element.remove_all_rows_button) element.remove_all_rows_button.disabled = val
68
+ if (element.delete_last_row_button) element.delete_last_row_button.disabled = val
69
+ if (element.copy_button) element.copy_button.disabled = val
70
+ if (element.delete_button) element.delete_button.disabled = val
71
+ if (element.moveup_button) element.moveup_button.disabled = val
72
+ if (element.movedown_button) element.movedown_button.disabled = val
73
+ }
74
+
75
+ preBuild () {
76
+ super.preBuild()
77
+
78
+ this.rows = []
79
+ this.row_cache = []
80
+
81
+ this.hide_delete_buttons = this.options.disable_array_delete || this.jsoneditor.options.disable_array_delete
82
+ this.hide_delete_all_rows_buttons = this.hide_delete_buttons || this.options.disable_array_delete_all_rows || this.jsoneditor.options.disable_array_delete_all_rows
83
+ this.hide_delete_last_row_buttons = this.hide_delete_buttons || this.options.disable_array_delete_last_row || this.jsoneditor.options.disable_array_delete_last_row
84
+ this.hide_move_buttons = this.options.disable_array_reorder || this.jsoneditor.options.disable_array_reorder
85
+ this.hide_add_button = this.options.disable_array_add || this.jsoneditor.options.disable_array_add
86
+ this.show_copy_button = this.options.enable_array_copy || this.jsoneditor.options.enable_array_copy
87
+ this.array_controls_top = this.options.array_controls_top || this.jsoneditor.options.array_controls_top
88
+ }
89
+
90
+ build () {
91
+ if (!this.options.compact) {
92
+ this.header = document.createElement('span')
93
+ this.header.textContent = this.getTitle()
94
+ this.title = this.theme.getHeader(this.header, this.getPathDepth())
95
+ this.container.appendChild(this.title)
96
+ if (this.options.infoText) {
97
+ this.infoButton = this.theme.getInfoButton(this.translateProperty(this.options.infoText))
98
+ this.container.appendChild(this.infoButton)
99
+ }
100
+ this.title_controls = this.theme.getHeaderButtonHolder()
101
+ this.title.appendChild(this.title_controls)
102
+ if (this.schema.description) {
103
+ this.description = this.theme.getDescription(this.translateProperty(this.schema.description))
104
+ this.container.appendChild(this.description)
105
+ }
106
+ this.error_holder = document.createElement('div')
107
+ this.container.appendChild(this.error_holder)
108
+
109
+ if (this.schema.format === 'tabs-top') {
110
+ this.controls = this.theme.getHeaderButtonHolder()
111
+ this.title.appendChild(this.controls)
112
+ this.tabs_holder = this.theme.getTopTabHolder(this.getValidId(this.getItemTitle()))
113
+ this.container.appendChild(this.tabs_holder)
114
+ this.row_holder = this.theme.getTopTabContentHolder(this.tabs_holder)
115
+
116
+ this.active_tab = null
117
+ } else if (this.schema.format === 'tabs') {
118
+ this.controls = this.theme.getHeaderButtonHolder()
119
+ this.title.appendChild(this.controls)
120
+ this.tabs_holder = this.theme.getTabHolder(this.getValidId(this.getItemTitle()))
121
+ this.container.appendChild(this.tabs_holder)
122
+ this.row_holder = this.theme.getTabContentHolder(this.tabs_holder)
123
+
124
+ this.active_tab = null
125
+ } else {
126
+ this.panel = this.theme.getIndentedPanel()
127
+ this.container.appendChild(this.panel)
128
+ this.row_holder = document.createElement('div')
129
+ this.panel.appendChild(this.row_holder)
130
+ this.controls = this.theme.getButtonHolder()
129
131
  if (this.array_controls_top) {
130
- this.title.appendChild(this.controls);
131
- }
132
- else {
133
- this.panel.appendChild(this.controls);
132
+ this.title.appendChild(this.controls)
133
+ } else {
134
+ this.panel.appendChild(this.controls)
134
135
  }
135
136
  }
137
+ } else {
138
+ /* compact mode */
139
+ this.title = this.theme.getHeader('', this.getPathDepth())
140
+ this.container.appendChild(this.title)
141
+ this.panel = this.theme.getIndentedPanel()
142
+ this.container.appendChild(this.panel)
143
+ this.title_controls = this.theme.getHeaderButtonHolder()
144
+ this.title.appendChild(this.title_controls)
145
+ this.controls = this.theme.getHeaderButtonHolder()
146
+ this.title.appendChild(this.controls)
147
+ this.row_holder = document.createElement('div')
148
+ this.panel.appendChild(this.row_holder)
149
+ }
150
+
151
+ /* Add controls */
152
+ this.addControls()
153
+ }
154
+
155
+ postBuild () {
156
+ super.postBuild()
157
+
158
+ if (this.schema.readOnly || this.schema.readonly) {
159
+ this.disable()
136
160
  }
137
- else {
138
- this.panel = this.theme.getIndentedPanel();
139
- this.container.appendChild(this.panel);
140
- this.title_controls = this.theme.getHeaderButtonHolder();
141
- this.panel.appendChild(this.title_controls);
142
- this.controls = this.theme.getButtonHolder();
143
- this.panel.appendChild(this.controls);
144
- this.row_holder = document.createElement('div');
145
- this.panel.appendChild(this.row_holder);
146
- }
147
-
148
- // Add controls
149
- this.addControls();
150
- },
151
- onChildEditorChange: function(editor) {
152
- this.refreshValue();
153
- this.refreshTabs(true);
154
- this._super(editor);
155
- },
156
- getItemTitle: function() {
157
- if(!this.item_title) {
158
- if(this.schema.items && !Array.isArray(this.schema.items)) {
159
- var tmp = this.jsoneditor.expandRefs(this.schema.items);
160
- this.item_title = tmp.title || 'item';
161
- }
162
- else {
163
- this.item_title = 'item';
161
+ }
162
+
163
+ onChildEditorChange (editor, eventData) {
164
+ this.refreshValue()
165
+ this.refreshTabs(true)
166
+ this.is_dirty = true
167
+ super.onChildEditorChange(editor, eventData)
168
+ }
169
+
170
+ getItemTitle () {
171
+ if (!this.item_title) {
172
+ if (this.schema.items && !Array.isArray(this.schema.items)) {
173
+ const tmp = this.jsoneditor.expandRefs(this.schema.items)
174
+ this.item_title = this.translateProperty(tmp.title) || this.translate('default_array_item_title')
175
+ } else {
176
+ this.item_title = this.translate('default_array_item_title')
164
177
  }
165
178
  }
166
- return this.cleanText(this.item_title);
167
- },
168
- getItemSchema: function(i) {
169
- if(Array.isArray(this.schema.items)) {
170
- if(i >= this.schema.items.length) {
171
- if(this.schema.additionalItems===true) {
172
- return {};
173
- }
174
- else if(this.schema.additionalItems) {
175
- return $extend({},this.schema.additionalItems);
179
+ return this.cleanText(this.item_title)
180
+ }
181
+
182
+ getItemSchema (i) {
183
+ if (Array.isArray(this.schema.items)) {
184
+ if (i >= this.schema.items.length) {
185
+ if (this.schema.additionalItems === true) {
186
+ return {}
187
+ } else if (this.schema.additionalItems) {
188
+ return extend({}, this.schema.additionalItems)
176
189
  }
190
+ } else {
191
+ return extend({}, this.schema.items[i])
177
192
  }
178
- else {
179
- return $extend({},this.schema.items[i]);
180
- }
181
- }
182
- else if(this.schema.items) {
183
- return $extend({},this.schema.items);
193
+ } else if (this.schema.items) {
194
+ return extend({}, this.schema.items)
195
+ } else {
196
+ return {}
184
197
  }
185
- else {
186
- return {};
187
- }
188
- },
189
- getItemInfo: function(i) {
190
- var schema = this.getItemSchema(i);
198
+ }
191
199
 
192
- // Check if it's cached
193
- this.item_info = this.item_info || {};
194
- var stringified = JSON.stringify(schema);
195
- if(typeof this.item_info[stringified] !== "undefined") return this.item_info[stringified];
200
+ getItemInfo (i) {
201
+ let schema = this.getItemSchema(i)
196
202
 
197
- // Get the schema for this item
198
- schema = this.jsoneditor.expandRefs(schema);
203
+ /* Check if it's cached */
204
+ this.item_info = this.item_info || {}
205
+ const stringified = JSON.stringify(schema)
206
+ if (typeof this.item_info[stringified] !== 'undefined') return this.item_info[stringified]
207
+
208
+ /* Get the schema for this item */
209
+ schema = this.jsoneditor.expandRefs(schema)
199
210
 
200
211
  this.item_info[stringified] = {
201
- title: schema.title || "item",
202
- 'default': schema["default"],
212
+ title: this.translateProperty(schema.title) || this.translate('default_array_item_title'),
213
+ default: schema.default,
203
214
  width: 12,
204
215
  child_editors: schema.properties || schema.items
205
- };
206
-
207
- return this.item_info[stringified];
208
- },
209
- getElementEditor: function(i) {
210
- var item_info = this.getItemInfo(i);
211
- var schema = this.getItemSchema(i);
212
- schema = this.jsoneditor.expandRefs(schema);
213
- schema.title = item_info.title+' '+(i+1);
214
-
215
- var editor = this.jsoneditor.getEditorClass(schema);
216
-
217
- var holder;
218
- if(this.tabs_holder) {
219
- if(this.schema.format === 'tabs-top') {
220
- holder = this.theme.getTopTabContent();
221
- }
222
- else {
223
- holder = this.theme.getTabContent();
224
- }
225
- holder.id = this.path+'.'+i;
226
216
  }
227
- else if(item_info.child_editors) {
228
- holder = this.theme.getChildEditorHolder();
229
- }
230
- else {
231
- holder = this.theme.getIndentedPanel();
217
+
218
+ return this.item_info[stringified]
219
+ }
220
+
221
+ getElementEditor (i) {
222
+ const itemInfo = this.getItemInfo(i)
223
+ let schema = this.getItemSchema(i)
224
+ schema = this.jsoneditor.expandRefs(schema)
225
+ schema.title = `${itemInfo.title} ${i + 1}`
226
+
227
+ const editor = this.jsoneditor.getEditorClass(schema)
228
+
229
+ let holder
230
+ if (this.tabs_holder) {
231
+ if (this.schema.format === 'tabs-top') {
232
+ holder = this.theme.getTopTabContent()
233
+ } else {
234
+ holder = this.theme.getTabContent()
235
+ }
236
+ holder.id = `${this.path}.${i}`
237
+ } else if (itemInfo.child_editors) {
238
+ holder = this.theme.getChildEditorHolder()
239
+ } else {
240
+ holder = this.theme.getIndentedPanel()
232
241
  }
233
242
 
234
- this.row_holder.appendChild(holder);
243
+ this.row_holder.appendChild(holder)
235
244
 
236
- var ret = this.jsoneditor.createEditor(editor,{
245
+ const ret = this.jsoneditor.createEditor(editor, {
237
246
  jsoneditor: this.jsoneditor,
238
- schema: schema,
247
+ schema,
239
248
  container: holder,
240
- path: this.path+'.'+i,
249
+ path: `${this.path}.${i}`,
241
250
  parent: this,
242
251
  required: true
243
- });
244
- ret.preBuild();
245
- ret.build();
246
- ret.postBuild();
247
-
248
- if(!ret.title_controls) {
249
- ret.array_controls = this.theme.getButtonHolder();
250
- holder.appendChild(ret.array_controls);
251
- }
252
-
253
- return ret;
254
- },
255
- destroy: function() {
256
- this.empty(true);
257
- if(this.title && this.title.parentNode) this.title.parentNode.removeChild(this.title);
258
- if(this.description && this.description.parentNode) this.description.parentNode.removeChild(this.description);
259
- if(this.row_holder && this.row_holder.parentNode) this.row_holder.parentNode.removeChild(this.row_holder);
260
- if(this.controls && this.controls.parentNode) this.controls.parentNode.removeChild(this.controls);
261
- if(this.panel && this.panel.parentNode) this.panel.parentNode.removeChild(this.panel);
262
-
263
- this.rows = this.row_cache = this.title = this.description = this.row_holder = this.panel = this.controls = null;
264
-
265
- this._super();
266
- },
267
- empty: function(hard) {
268
- if(!this.rows) return;
269
- var self = this;
270
- $each(this.rows,function(i,row) {
271
- if(hard) {
272
- if(row.tab && row.tab.parentNode) row.tab.parentNode.removeChild(row.tab);
273
- self.destroyRow(row,true);
274
- self.row_cache[i] = null;
275
- }
276
- self.rows[i] = null;
277
- });
278
- self.rows = [];
279
- if(hard) self.row_cache = [];
280
- },
281
- destroyRow: function(row,hard) {
282
- var holder = row.container;
283
- if(hard) {
284
- row.destroy();
285
- if(holder.parentNode) holder.parentNode.removeChild(holder);
286
- if(row.tab && row.tab.parentNode) row.tab.parentNode.removeChild(row.tab);
287
- }
288
- else {
289
- if(row.tab) row.tab.style.display = 'none';
290
- holder.style.display = 'none';
291
- row.unregister();
292
- }
293
- },
294
- getMax: function() {
295
- if((Array.isArray(this.schema.items)) && this.schema.additionalItems === false) {
296
- return Math.min(this.schema.items.length,this.schema.maxItems || Infinity);
297
- }
298
- else {
299
- return this.schema.maxItems || Infinity;
300
- }
301
- },
302
- refreshTabs: function(refresh_headers) {
303
- var self = this;
304
- $each(this.rows, function(i,row) {
305
- if(!row.tab) return;
306
-
307
- if(refresh_headers) {
308
- row.tab_text.textContent = row.getHeaderText();
252
+ })
253
+ ret.preBuild()
254
+ ret.build()
255
+ ret.postBuild()
256
+
257
+ if (!ret.title_controls) {
258
+ ret.array_controls = this.theme.getButtonHolder()
259
+ holder.appendChild(ret.array_controls)
260
+ }
261
+
262
+ return ret
263
+ }
264
+
265
+ checkParent (elem) {
266
+ return elem && elem.parentNode
267
+ }
268
+
269
+ destroy () {
270
+ this.empty(true)
271
+ if (this.checkParent(this.title)) this.title.parentNode.removeChild(this.title)
272
+ if (this.checkParent(this.description)) this.description.parentNode.removeChild(this.description)
273
+ if (this.checkParent(this.row_holder)) this.row_holder.parentNode.removeChild(this.row_holder)
274
+ if (this.checkParent(this.controls)) this.controls.parentNode.removeChild(this.controls)
275
+ if (this.checkParent(this.panel)) this.panel.parentNode.removeChild(this.panel)
276
+
277
+ this.rows = this.row_cache = this.title = this.description = this.row_holder = this.panel = this.controls = null
278
+
279
+ super.destroy()
280
+ }
281
+
282
+ empty (hard) {
283
+ if (this.rows === null) return
284
+
285
+ this.rows.forEach((row, i) => {
286
+ if (hard) {
287
+ if (this.checkParent(row.tab)) row.tab.parentNode.removeChild(row.tab)
288
+ this.destroyRow(row, true)
289
+ this.row_cache[i] = null
309
290
  }
310
- else {
311
- if(row.tab === self.active_tab) {
312
- self.theme.markTabActive(row);
313
- }
314
- else {
315
- self.theme.markTabInactive(row);
316
- }
291
+ this.rows[i] = null
292
+ })
293
+ if (hard) {
294
+ for (let j = this.rows.length; j < this.row_cache.length; j++) {
295
+ this.destroyRow(this.row_cache[j], true)
296
+ this.row_cache[j] = null
317
297
  }
318
- });
319
- },
320
- setValue: function(value, initial) {
321
- // Update the array's value, adding/removing rows when necessary
322
- value = value || [];
298
+ }
299
+ this.rows = []
300
+ if (hard) this.row_cache = []
301
+ }
323
302
 
324
- if(!(Array.isArray(value))) value = [value];
303
+ destroyRow (row, hard) {
304
+ const holder = row.container
305
+ if (hard) {
306
+ row.destroy()
307
+ if (holder.parentNode) holder.parentNode.removeChild(holder)
308
+ if (this.checkParent(row.tab)) row.tab.parentNode.removeChild(row.tab)
309
+ } else {
310
+ if (row.tab) row.tab.style.display = 'none'
311
+ holder.style.display = 'none'
312
+ row.unregister()
313
+ }
314
+ }
325
315
 
326
- var serialized = JSON.stringify(value);
327
- if(serialized === this.serialized) return;
316
+ getMax () {
317
+ if ((Array.isArray(this.schema.items)) && this.schema.additionalItems === false) {
318
+ return Math.min(this.schema.items.length, this.schema.maxItems || Infinity)
319
+ }
320
+ return this.schema.maxItems || Infinity
321
+ }
328
322
 
329
- // Make sure value has between minItems and maxItems items in it
330
- if(this.schema.minItems) {
331
- while(value.length < this.schema.minItems) {
332
- value.push(this.getItemInfo(value.length)["default"]);
323
+ refreshTabs (refreshHeaders) {
324
+ this.rows.forEach(row => {
325
+ if (!row.tab) return
326
+
327
+ if (refreshHeaders) {
328
+ row.tab_text.textContent = row.getHeaderText()
329
+ } else if (row.tab === this.active_tab) {
330
+ this.theme.markTabActive(row)
331
+ } else {
332
+ this.theme.markTabInactive(row)
333
+ }
334
+ })
335
+ }
336
+
337
+ ensureArraySize (value) {
338
+ if (!(Array.isArray(value))) value = [value]
339
+
340
+ if (this.schema.minItems) {
341
+ while (value.length < this.schema.minItems) {
342
+ value.push(this.getItemInfo(value.length).default)
333
343
  }
334
344
  }
335
- if(this.getMax() && value.length > this.getMax()) {
336
- value = value.slice(0,this.getMax());
345
+ if (this.getMax() && value.length > this.getMax()) {
346
+ value = value.slice(0, this.getMax())
337
347
  }
348
+ return value
349
+ }
338
350
 
339
- var self = this;
340
- $each(value,function(i,val) {
341
- if(self.rows[i]) {
342
- // TODO: don't set the row's value if it hasn't changed
343
- self.rows[i].setValue(val,initial);
344
- }
345
- else if(self.row_cache[i]) {
346
- self.rows[i] = self.row_cache[i];
347
- self.rows[i].setValue(val,initial);
348
- self.rows[i].container.style.display = '';
349
- if(self.rows[i].tab) self.rows[i].tab.style.display = '';
350
- self.rows[i].register();
351
+ setValue (value = [], initial) {
352
+ value = this.applyConstFilter(value)
353
+ /* Make sure value has between minItems and maxItems items in it */
354
+ value = this.ensureArraySize(value)
355
+
356
+ const serialized = JSON.stringify(value)
357
+ if (serialized === this.serialized) {
358
+ if (initial) {
359
+ this.refreshValue(initial)
351
360
  }
352
- else {
353
- self.addRow(val,initial);
361
+ return
362
+ }
363
+
364
+ value.forEach((val, i) => {
365
+ if (this.rows[i]) {
366
+ /* TODO: don't set the row's value if it hasn't changed */
367
+ this.rows[i].setValue(val, initial)
368
+ } else if (this.row_cache[i]) {
369
+ this.rows[i] = this.row_cache[i]
370
+ this.rows[i].setValue(val, initial)
371
+ this.rows[i].container.style.display = ''
372
+ if (this.rows[i].tab) this.rows[i].tab.style.display = ''
373
+ this.rows[i].register()
374
+ this.jsoneditor.trigger('addRow', this.rows[i])
375
+ } else {
376
+ const editor = this.addRow(val, initial)
377
+ this.jsoneditor.trigger('addRow', editor)
354
378
  }
355
- });
379
+ })
356
380
 
357
- for(var j=value.length; j<self.rows.length; j++) {
358
- self.destroyRow(self.rows[j]);
359
- self.rows[j] = null;
381
+ for (let j = value.length; j < this.rows.length; j++) {
382
+ this.destroyRow(this.rows[j])
383
+ this.rows[j] = null
360
384
  }
361
- self.rows = self.rows.slice(0,value.length);
385
+ this.rows = this.rows.slice(0, value.length)
362
386
 
363
- // Set the active tab
364
- var new_active_tab = null;
365
- $each(self.rows, function(i,row) {
366
- if(row.tab === self.active_tab) {
367
- new_active_tab = row.tab;
368
- return false;
369
- }
370
- });
371
- if(!new_active_tab && self.rows.length) new_active_tab = self.rows[0].tab;
372
-
373
- self.active_tab = new_active_tab;
374
-
375
- self.refreshValue(initial);
376
- self.refreshTabs(true);
377
- self.refreshTabs();
378
-
379
- self.onChange();
380
-
381
- // TODO: sortable
382
- },
383
- refreshValue: function(force) {
384
- var self = this;
385
- var oldi = this.value? this.value.length : 0;
386
- this.value = [];
387
-
388
- $each(this.rows,function(i,editor) {
389
- // Get the value for this editor
390
- self.value[i] = editor.getValue();
391
- });
392
-
393
- if(oldi !== this.value.length || force) {
394
- // If we currently have minItems items in the array
395
- var minItems = this.schema.minItems && this.schema.minItems >= this.rows.length;
396
-
397
- $each(this.rows,function(i,editor) {
398
- // Hide the move down button for the last row
399
- if(editor.movedown_button) {
400
- if(i === self.rows.length - 1) {
401
- editor.movedown_button.style.display = 'none';
402
- }
403
- else {
404
- editor.movedown_button.style.display = '';
405
- }
406
- }
387
+ /* Set the active tab */
388
+ const row = this.rows.find(row => row.tab === this.active_tab)
389
+ let newActiveTab = typeof row !== 'undefined' ? row.tab : null
390
+ if (!newActiveTab && this.rows.length) newActiveTab = this.rows[0].tab
407
391
 
408
- // Hide the delete button if we have minItems items
409
- if(editor.delete_button) {
410
- if(minItems) {
411
- editor.delete_button.style.display = 'none';
412
- }
413
- else {
414
- editor.delete_button.style.display = '';
415
- }
416
- }
392
+ this.active_tab = newActiveTab
417
393
 
418
- // Get the value for this editor
419
- self.value[i] = editor.getValue();
420
- });
394
+ this.refreshValue(initial)
395
+ this.refreshTabs(true)
396
+ this.refreshTabs()
421
397
 
422
- var controls_needed = false;
398
+ this.onChange()
423
399
 
424
- if(!this.value.length) {
425
- this.delete_last_row_button.style.display = 'none';
426
- this.remove_all_rows_button.style.display = 'none';
427
- }
428
- else if(this.value.length === 1) {
429
- this.remove_all_rows_button.style.display = 'none';
400
+ /* TODO: sortable */
401
+ }
430
402
 
431
- // If there are minItems items in the array, or configured to hide the delete_last_row button, hide the delete button beneath the rows
432
- if(minItems || this.hide_delete_last_row_buttons) {
433
- this.delete_last_row_button.style.display = 'none';
434
- }
435
- else {
436
- this.delete_last_row_button.style.display = '';
437
- controls_needed = true;
438
- }
439
- }
440
- else {
441
- if(minItems || this.hide_delete_last_row_buttons) {
442
- this.delete_last_row_button.style.display = 'none';
443
- }
444
- else {
445
- this.delete_last_row_button.style.display = '';
446
- controls_needed = true;
447
- }
403
+ setButtonState (element, display) {
404
+ const buttonStateMode = this.options.button_state_mode || this.jsoneditor.options.button_state_mode
405
+
406
+ switch (buttonStateMode) {
407
+ case 1:
408
+ element.style.display = display ? '' : 'none'
409
+ break
410
+ case 2:
411
+ element.disabled = !display
412
+ break
413
+ default:
414
+ element.style.display = display ? '' : 'none'
415
+ }
416
+ }
417
+
418
+ setupButtons (minItems) {
419
+ const controlsNeeded = []
420
+
421
+ if (!this.value.length) {
422
+ this.setButtonState(this.delete_last_row_button, false)
423
+ this.setButtonState(this.remove_all_rows_button, false)
424
+ } else if (this.value.length === 1) {
425
+ this.setButtonState(this.remove_all_rows_button, false)
426
+
427
+ /* If there are minItems items in the array, or configured to hide the delete_last_row button, hide the delete button beneath the rows */
428
+ const display = !(minItems || this.hide_delete_last_row_buttons)
429
+ this.setButtonState(this.delete_last_row_button, display)
430
+ controlsNeeded.push(display)
431
+ } else {
432
+ const display1 = !(minItems || this.hide_delete_last_row_buttons)
433
+ this.setButtonState(this.delete_last_row_button, display1)
434
+ controlsNeeded.push(display1)
435
+
436
+ const display2 = !(minItems || this.hide_delete_all_rows_buttons)
437
+ this.setButtonState(this.remove_all_rows_button, display2)
438
+ controlsNeeded.push(display2)
439
+ }
440
+
441
+ /* If there are maxItems in the array, hide the add button beneath the rows */
442
+ const display = !((this.getMax() && this.getMax() <= this.rows.length) || this.hide_add_button)
443
+ this.setButtonState(this.add_row_button, display)
444
+ controlsNeeded.push(display)
445
+
446
+ return controlsNeeded.some(e => e)
447
+ }
448
+
449
+ refreshValue (force) {
450
+ const oldi = this.value ? this.value.length : 0
451
+ /* Get the value for this editor */
452
+ this.value = this.rows.map(editor => editor.getValue())
453
+
454
+ if (oldi !== this.value.length || force) {
455
+ /* If we currently have minItems items in the array */
456
+ const minItems = this.schema.minItems && this.schema.minItems >= this.rows.length
448
457
 
449
- if(minItems || this.hide_delete_all_rows_buttons) {
450
- this.remove_all_rows_button.style.display = 'none';
458
+ this.rows.forEach((editor, i) => {
459
+ /* Hide the move down button for the last row */
460
+ if (editor.movedown_button) {
461
+ const display = (i !== this.rows.length - 1)
462
+ this.setButtonState(editor.movedown_button, display)
451
463
  }
452
- else {
453
- this.remove_all_rows_button.style.display = '';
454
- controls_needed = true;
464
+
465
+ /* Hide the delete button if we have minItems items */
466
+ if (editor.delete_button) {
467
+ this.setButtonState(editor.delete_button, !minItems)
455
468
  }
456
- }
457
469
 
458
- // If there are maxItems in the array, hide the add button beneath the rows
459
- if((this.getMax() && this.getMax() <= this.rows.length) || this.hide_add_button){
460
- this.add_row_button.style.display = 'none';
461
- }
462
- else {
463
- this.add_row_button.style.display = '';
464
- controls_needed = true;
465
- }
470
+ /* Get the value for this editor */
471
+ this.value[i] = editor.getValue()
472
+ })
466
473
 
467
- if(!this.collapsed && controls_needed) {
468
- this.controls.style.display = 'inline-block';
469
- }
470
- else {
471
- this.controls.style.display = 'none';
474
+ if (this.setupButtons(minItems) && !this.collapsed) {
475
+ this.controls.style.display = 'inline-block'
476
+ } else {
477
+ this.controls.style.display = 'none'
472
478
  }
473
479
  }
474
- },
475
- addRow: function(value, initial) {
476
- var self = this;
477
- var i = this.rows.length;
480
+ this.serialized = JSON.stringify(this.value)
481
+ }
478
482
 
479
- self.rows[i] = this.getElementEditor(i);
480
- self.row_cache[i] = self.rows[i];
483
+ addRow (value, initial) {
484
+ const i = this.rows.length
481
485
 
482
- if(self.tabs_holder) {
483
- self.rows[i].tab_text = document.createElement('span');
484
- self.rows[i].tab_text.textContent = self.rows[i].getHeaderText();
485
- if(self.schema.format === 'tabs-top'){
486
- self.rows[i].tab = self.theme.getTopTab(self.rows[i].tab_text,this.getValidId(self.rows[i].path));
487
- self.theme.addTopTab(self.tabs_holder, self.rows[i].tab);
488
- }
489
- else {
490
- self.rows[i].tab = self.theme.getTab(self.rows[i].tab_text,this.getValidId(self.rows[i].path));
491
- self.theme.addTab(self.tabs_holder, self.rows[i].tab);
486
+ this.rows[i] = this.getElementEditor(i)
487
+ this.row_cache[i] = this.rows[i]
488
+
489
+ if (this.tabs_holder) {
490
+ this.rows[i].tab_text = document.createElement('span')
491
+ this.rows[i].tab_text.textContent = this.rows[i].getHeaderText()
492
+ if (this.schema.format === 'tabs-top') {
493
+ this.rows[i].tab = this.theme.getTopTab(this.rows[i].tab_text, this.getValidId(this.rows[i].path))
494
+ this.theme.addTopTab(this.tabs_holder, this.rows[i].tab)
495
+ } else {
496
+ this.rows[i].tab = this.theme.getTab(this.rows[i].tab_text, this.getValidId(this.rows[i].path))
497
+ this.theme.addTab(this.tabs_holder, this.rows[i].tab)
492
498
  }
493
- self.rows[i].tab.addEventListener('click', function(e) {
494
- self.active_tab = self.rows[i].tab;
495
- self.refreshTabs();
496
- e.preventDefault();
497
- e.stopPropagation();
498
- });
499
+ this.rows[i].tab.addEventListener('click', (e) => {
500
+ this.active_tab = this.rows[i].tab
501
+ this.refreshTabs()
502
+ e.preventDefault()
503
+ e.stopPropagation()
504
+ })
505
+ this._supportDragDrop(this.rows[i].tab)
506
+ } else {
507
+ this._supportDragDrop(this.rows[i].container, true)
508
+ }
509
+
510
+ const controlsHolder = this.rows[i].title_controls || this.rows[i].array_controls
499
511
 
512
+ /* Buttons to delete row, move row up, and move row down */
513
+ if (!this.hide_delete_buttons) {
514
+ this.rows[i].delete_button = this._createDeleteButton(i, controlsHolder)
500
515
  }
501
516
 
502
- var controls_holder = self.rows[i].title_controls || self.rows[i].array_controls;
517
+ /* Button to copy an array element and add it as last element */
518
+ if (this.show_copy_button) {
519
+ this.rows[i].copy_button = this._createCopyButton(i, controlsHolder)
520
+ }
503
521
 
504
- // Buttons to delete row, move row up, and move row down
505
- if(!self.hide_delete_buttons) {
506
- self.rows[i].delete_button = this.getButton(self.getItemTitle(),'delete',this.translate('button_delete_row_title',[self.getItemTitle()]));
507
- self.rows[i].delete_button.classList.add('delete', 'json-editor-btntype-delete');
508
- self.rows[i].delete_button.setAttribute('data-i',i);
509
- self.rows[i].delete_button.addEventListener('click',function(e) {
510
- e.preventDefault();
511
- e.stopPropagation();
522
+ if (i && !this.hide_move_buttons) {
523
+ this.rows[i].moveup_button = this._createMoveUpButton(i, controlsHolder)
524
+ }
512
525
 
513
- if (!self.askConfirmation()) {
514
- return false;
515
- }
526
+ if (!this.hide_move_buttons) {
527
+ this.rows[i].movedown_button = this._createMoveDownButton(i, controlsHolder)
528
+ }
516
529
 
517
- var i = this.getAttribute('data-i')*1;
518
- var value = self.getValue();
519
- var newval = [];
520
- var new_active_tab = null;
530
+ if (typeof value !== 'undefined') this.rows[i].setValue(value, initial)
531
+ this.refreshTabs()
521
532
 
522
- $each(value,function(j,row) {
523
- if(j !== i) {
524
- newval.push(row);
525
- }
526
- });
533
+ return this.rows[i]
534
+ }
527
535
 
528
- self.empty(true);
529
- self.setValue(newval);
536
+ _createDeleteButton (i, holder) {
537
+ const button = this.getButton(this.getItemTitle(), 'delete', 'button_delete_row_title', [this.getItemTitle()])
538
+ button.classList.add('delete', 'json-editor-btntype-delete')
539
+ button.setAttribute('data-i', i)
540
+ button.addEventListener('click', e => {
541
+ e.preventDefault()
542
+ e.stopPropagation()
530
543
 
531
- if (self.rows[i]) {
532
- new_active_tab = self.rows[i].tab;
533
- } else if (self.rows[i-1]) {
534
- new_active_tab = self.rows[i-1].tab;
535
- }
544
+ if (!this.askConfirmation()) {
545
+ return false
546
+ }
536
547
 
537
- if(new_active_tab) {
538
- self.active_tab = new_active_tab;
539
- self.refreshTabs();
540
- }
548
+ const i = e.currentTarget.getAttribute('data-i') * 1
549
+ const newval = this.getValue().filter((row, j) => j !== i)
550
+ let newActiveTab = null
541
551
 
542
- self.onChange(true);
543
- self.jsoneditor.trigger('deleteRow');
544
- });
552
+ const editor = this.rows[i]
553
+ const editorValue = editor.getValue()
545
554
 
546
- if(controls_holder) {
547
- controls_holder.appendChild(self.rows[i].delete_button);
555
+ this.setValue(newval)
556
+
557
+ if (this.rows[i]) {
558
+ newActiveTab = this.rows[i].tab
559
+ } else if (this.rows[i - 1]) {
560
+ newActiveTab = this.rows[i - 1].tab
561
+ }
562
+
563
+ if (newActiveTab) {
564
+ this.active_tab = newActiveTab
565
+ this.refreshTabs()
548
566
  }
567
+
568
+ this.onChange(true)
569
+ this.jsoneditor.trigger('deleteRow', editorValue)
570
+ })
571
+
572
+ if (holder) {
573
+ holder.appendChild(button)
549
574
  }
575
+ return button
576
+ }
550
577
 
551
- //Button to copy an array element and add it as last element
552
- if(self.show_copy_button){
553
- self.rows[i].copy_button = this.getButton(self.getItemTitle(),'copy','Copy '+self.getItemTitle());
554
- self.rows[i].copy_button.classList.add('copy', 'json-editor-btntype-copy');
555
- self.rows[i].copy_button.setAttribute('data-i',i);
556
- self.rows[i].copy_button.addEventListener('click',function(e) {
557
- var value = self.getValue();
558
- e.preventDefault();
559
- e.stopPropagation();
560
- var i = this.getAttribute('data-i')*1;
561
-
562
- $each(value,function(j,row) {
563
- if(j===i) {
564
- value.push(row);
578
+ _createCopyButton (i, holder) {
579
+ const button = this.getButton(this.getItemTitle(), 'copy', 'button_copy_row_title', [this.getItemTitle()])
580
+ const schema = this.schema
581
+ button.classList.add('copy', 'json-editor-btntype-copy')
582
+ button.setAttribute('data-i', i)
583
+ button.addEventListener('click', e => {
584
+ const value = this.getValue()
585
+ e.preventDefault()
586
+ e.stopPropagation()
587
+ const i = e.currentTarget.getAttribute('data-i') * 1
588
+
589
+ value.forEach((row, j) => {
590
+ if (j === i) {
591
+ let duplicatedRow = (typeof row === 'object' && row !== null) ? { ...row } : row
592
+ /* Force generation of new UUID if the item has been cloned. */
593
+ if (schema.items.type === 'string' && schema.items.format === 'uuid') {
594
+ duplicatedRow = generateUUID()
595
+ } else if (schema.items.type === 'object' && schema.items.properties) {
596
+ for (const key of Object.keys(duplicatedRow)) {
597
+ if (schema.items.properties && schema.items.properties[key] && schema.items.properties[key].format === 'uuid') {
598
+ duplicatedRow[key] = generateUUID()
565
599
  }
566
- });
600
+ }
601
+ }
602
+ value.push(duplicatedRow)
603
+ }
604
+ })
605
+
606
+ this.setValue(value)
607
+ this.refreshValue(true)
608
+ this.onChange(true)
609
+ this.jsoneditor.trigger('copyRow', this.rows[i - 1])
610
+ })
611
+
612
+ holder.appendChild(button)
613
+ return button
614
+ }
567
615
 
568
- self.setValue(value);
569
- self.refreshValue(true);
570
- self.onChange(true);
616
+ _createMoveUpButton (i, holder) {
617
+ const button = this.getButton('', (this.schema.format === 'tabs-top' ? 'moveleft' : 'moveup'), 'button_move_up_title')
618
+ button.classList.add('moveup', 'json-editor-btntype-move')
619
+ button.setAttribute('data-i', i)
620
+ button.addEventListener('click', e => {
621
+ e.preventDefault()
622
+ e.stopPropagation()
623
+ const i = e.currentTarget.getAttribute('data-i') * 1
571
624
 
572
- });
625
+ if (i <= 0) return
626
+ const rows = this.getValue()
627
+ const tmp = rows[i - 1]
628
+ rows[i - 1] = rows[i]
629
+ rows[i] = tmp
573
630
 
574
- controls_holder.appendChild(self.rows[i].copy_button);
631
+ this.setValue(rows)
632
+ this.active_tab = this.rows[i - 1].tab
633
+ this.refreshTabs()
634
+
635
+ this.onChange(true)
636
+
637
+ this.jsoneditor.trigger('moveRow', this.rows[i - 1])
638
+ })
639
+
640
+ if (holder) {
641
+ holder.appendChild(button)
575
642
  }
643
+ return button
644
+ }
576
645
 
646
+ _createMoveDownButton (i, holder) {
647
+ const button = this.getButton('', (this.schema.format === 'tabs-top' ? 'moveright' : 'movedown'), 'button_move_down_title')
648
+ button.classList.add('movedown', 'json-editor-btntype-move')
649
+ button.setAttribute('data-i', i)
650
+ button.addEventListener('click', e => {
651
+ e.preventDefault()
652
+ e.stopPropagation()
653
+ const i = e.currentTarget.getAttribute('data-i') * 1
654
+
655
+ const rows = this.getValue()
656
+ if (i >= rows.length - 1) return
657
+ const tmp = rows[i + 1]
658
+ rows[i + 1] = rows[i]
659
+ rows[i] = tmp
660
+
661
+ this.setValue(rows)
662
+ this.active_tab = this.rows[i + 1].tab
663
+ this.refreshTabs()
664
+ this.onChange(true)
665
+
666
+ this.jsoneditor.trigger('moveRow', this.rows[i + 1])
667
+ })
668
+
669
+ if (holder) {
670
+ holder.appendChild(button)
671
+ }
672
+ return button
673
+ }
577
674
 
578
- if(i && !self.hide_move_buttons) {
579
- self.rows[i].moveup_button = this.getButton('','moveup',this.translate('button_move_up_title'));
580
- self.rows[i].moveup_button.classList.add('moveup', 'json-editor-btntype-move');
581
- self.rows[i].moveup_button.setAttribute('data-i',i);
582
- self.rows[i].moveup_button.addEventListener('click',function(e) {
583
- e.preventDefault();
584
- e.stopPropagation();
585
- var i = this.getAttribute('data-i')*1;
675
+ _supportDragDrop (tab, useTrigger) {
676
+ supportDragDrop(tab, (i, j) => {
677
+ const rows = this.getValue()
678
+ const tmp = rows[i]
679
+ rows.splice(i, 1)
680
+ rows.splice(j, 0, tmp)
586
681
 
587
- if(i<=0) return;
588
- var rows = self.getValue();
589
- var tmp = rows[i-1];
590
- rows[i-1] = rows[i];
591
- rows[i] = tmp;
682
+ this.setValue(rows)
683
+ this.active_tab = this.rows[j].tab
684
+ this.refreshTabs()
592
685
 
593
- self.setValue(rows);
594
- self.active_tab = self.rows[i-1].tab;
595
- self.refreshTabs();
686
+ this.onChange(true)
596
687
 
597
- self.onChange(true);
688
+ this.jsoneditor.trigger('moveRow', this.rows[j])
689
+ }, { useTrigger })
690
+ }
598
691
 
599
- self.jsoneditor.trigger('moveRow');
600
- });
692
+ addControls () {
693
+ this.collapsed = false
694
+ this.toggle_button = this._createToggleButton()
601
695
 
602
- if(controls_holder) {
603
- controls_holder.appendChild(self.rows[i].moveup_button);
604
- }
696
+ /* If it should start collapsed */
697
+ if (this.options.collapsed) {
698
+ trigger(this.toggle_button, 'click')
605
699
  }
606
700
 
607
- if(!self.hide_move_buttons) {
608
- self.rows[i].movedown_button = this.getButton('','movedown',this.translate('button_move_down_title'));
609
- self.rows[i].movedown_button.classList.add('movedown', 'json-editor-btntype-move');
610
- self.rows[i].movedown_button.setAttribute('data-i',i);
611
- self.rows[i].movedown_button.addEventListener('click',function(e) {
612
- e.preventDefault();
613
- e.stopPropagation();
614
- var i = this.getAttribute('data-i')*1;
701
+ /* Collapse button disabled */
702
+ if (this.schema.options && typeof this.schema.options.disable_collapse !== 'undefined') {
703
+ if (this.schema.options.disable_collapse) this.toggle_button.style.display = 'none'
704
+ } else if (this.jsoneditor.options.disable_collapse) {
705
+ this.toggle_button.style.display = 'none'
706
+ }
615
707
 
616
- var rows = self.getValue();
617
- if(i>=rows.length-1) return;
618
- var tmp = rows[i+1];
619
- rows[i+1] = rows[i];
620
- rows[i] = tmp;
708
+ /* Add "new row" and "delete last" buttons below editor */
709
+ this.add_row_button = this._createAddRowButton()
710
+ this.delete_last_row_button = this._createDeleteLastRowButton()
711
+ this.remove_all_rows_button = this._createRemoveAllRowsButton()
621
712
 
622
- self.setValue(rows);
623
- self.active_tab = self.rows[i+1].tab;
624
- self.refreshTabs();
625
- self.onChange(true);
713
+ if (this.tabs) {
714
+ this.add_row_button.classList.add('je-array-control-btn')
715
+ this.delete_last_row_button.classList.add('je-array-control-btn')
716
+ this.remove_all_rows_button.classList.add('je-array-control-btn')
717
+ }
718
+ }
626
719
 
627
- self.jsoneditor.trigger('moveRow');
628
- });
720
+ _createToggleButton () {
721
+ const button = this.getButton('', 'collapse', 'button_collapse')
722
+ button.classList.add('json-editor-btntype-toggle')
723
+ this.title.insertBefore(button, this.title.childNodes[0])
724
+
725
+ const rowHolderDisplay = this.row_holder.style.display
726
+ const controlsDisplay = this.controls.style.display
727
+ button.addEventListener('click', e => {
728
+ e.preventDefault()
729
+ e.stopPropagation()
730
+ if (this.panel) this.setButtonState(this.panel, this.collapsed)
731
+ if (this.tabs_holder) this.setButtonState(this.tabs_holder, this.collapsed)
732
+ if (this.collapsed) {
733
+ this.collapsed = false
734
+ this.row_holder.style.display = rowHolderDisplay
735
+ this.controls.style.display = controlsDisplay
736
+ this.setButtonText(e.currentTarget, '', 'collapse', 'button_collapse')
737
+ } else {
738
+ this.collapsed = true
739
+ this.row_holder.style.display = 'none'
740
+ this.controls.style.display = 'none'
741
+ this.setButtonText(e.currentTarget, '', 'expand', 'button_expand')
742
+ }
743
+ })
744
+ return button
745
+ }
629
746
 
630
- if(controls_holder) {
631
- controls_holder.appendChild(self.rows[i].movedown_button);
632
- }
633
- }
747
+ _createAddRowButton () {
748
+ const button = this.getButton(this.getItemTitle(), 'add', 'button_add_row_title', [this.getItemTitle()])
749
+ button.classList.add('json-editor-btntype-add')
750
+ button.addEventListener('click', (e) => {
751
+ e.preventDefault()
752
+ e.stopPropagation()
753
+ const i = this.rows.length
754
+ let editor
755
+ if (this.row_cache[i]) {
756
+ editor = this.rows[i] = this.row_cache[i]
757
+ this.rows[i].setValue(this.rows[i].getDefault(), true)
758
+ // override cached value, so optional properties are not checked.
759
+ if (typeof this.rows[i].deactivateNonRequiredProperties === 'function') {
760
+ this.rows[i].deactivateNonRequiredProperties(true)
761
+ }
762
+ this.rows[i].container.style.display = ''
763
+ if (this.rows[i].tab) this.rows[i].tab.style.display = ''
764
+ this.rows[i].register()
765
+ } else {
766
+ editor = this.addRow()
767
+ }
768
+ this.active_tab = this.rows[i].tab
769
+ this.refreshTabs()
770
+ this.refreshValue()
771
+ this.onChange(true)
772
+ this.jsoneditor.trigger('addRow', editor)
773
+ })
774
+ this.controls.appendChild(button)
775
+ return button
776
+ }
634
777
 
635
- if(value) self.rows[i].setValue(value, initial);
636
- self.refreshTabs();
637
- },
638
- addControls: function() {
639
- var self = this;
640
-
641
- this.collapsed = false;
642
- this.toggle_button = this.getButton('','collapse',this.translate('button_collapse'));
643
- this.toggle_button.classList.add('json-editor-btntype-toggle');
644
- this.title_controls.appendChild(this.toggle_button);
645
- var row_holder_display = self.row_holder.style.display;
646
- var controls_display = self.controls.style.display;
647
- this.toggle_button.addEventListener('click',function(e) {
648
- e.preventDefault();
649
- e.stopPropagation();
650
- if(self.collapsed) {
651
- self.collapsed = false;
652
- if(self.panel) self.panel.style.display = '';
653
- self.row_holder.style.display = row_holder_display;
654
- if(self.tabs_holder) self.tabs_holder.style.display = '';
655
- self.controls.style.display = controls_display;
656
- self.setButtonText(this,'','collapse',self.translate('button_collapse'));
657
- }
658
- else {
659
- self.collapsed = true;
660
- self.row_holder.style.display = 'none';
661
- if(self.tabs_holder) self.tabs_holder.style.display = 'none';
662
- self.controls.style.display = 'none';
663
- if(self.panel) self.panel.style.display = 'none';
664
- self.setButtonText(this,'','expand',self.translate('button_expand'));
665
- }
666
- });
667
-
668
- // If it should start collapsed
669
- if(this.options.collapsed) {
670
- $trigger(this.toggle_button,'click');
671
- }
672
-
673
- // Collapse button disabled
674
- if(this.schema.options && typeof this.schema.options.disable_collapse !== "undefined") {
675
- if(this.schema.options.disable_collapse) this.toggle_button.style.display = 'none';
676
- }
677
- else if(this.jsoneditor.options.disable_collapse) {
678
- this.toggle_button.style.display = 'none';
679
- }
680
-
681
- // Add "new row" and "delete last" buttons below editor
682
- this.add_row_button = this.getButton(this.getItemTitle(),'add',this.translate('button_add_row_title',[this.getItemTitle()]));
683
- this.add_row_button.classList.add('json-editor-btntype-add');
684
- this.add_row_button.addEventListener('click',function(e) {
685
- e.preventDefault();
686
- e.stopPropagation();
687
- var i = self.rows.length;
688
- if(self.row_cache[i]) {
689
- self.rows[i] = self.row_cache[i];
690
- self.rows[i].setValue(self.rows[i].getDefault(), true);
691
- self.rows[i].container.style.display = '';
692
- if(self.rows[i].tab) self.rows[i].tab.style.display = '';
693
- self.rows[i].register();
694
- }
695
- else {
696
- self.addRow();
697
- }
698
- self.active_tab = self.rows[i].tab;
699
- self.refreshTabs();
700
- self.refreshValue();
701
- self.onChange(true);
702
- self.jsoneditor.trigger('addRow');
703
- });
704
- self.controls.appendChild(this.add_row_button);
705
-
706
- this.delete_last_row_button = this.getButton(this.translate('button_delete_last',[this.getItemTitle()]),'delete',this.translate('button_delete_last_title',[this.getItemTitle()]));
707
- this.delete_last_row_button.classList.add('json-editor-btntype-deletelast');
708
- this.delete_last_row_button.addEventListener('click',function(e) {
709
- e.preventDefault();
710
- e.stopPropagation();
711
-
712
- if (!self.askConfirmation()) {
713
- return false;
778
+ _createDeleteLastRowButton () {
779
+ const button = this.getButton('button_delete_last', 'subtract', 'button_delete_last_title', [this.getItemTitle()])
780
+ button.classList.add('json-editor-btntype-deletelast')
781
+ button.addEventListener('click', (e) => {
782
+ e.preventDefault()
783
+ e.stopPropagation()
784
+
785
+ if (!this.askConfirmation()) {
786
+ return false
714
787
  }
715
788
 
716
- var rows = self.getValue();
717
- var new_active_tab = null;
789
+ const rows = this.getValue()
790
+ let newActiveTab = null
718
791
 
719
- rows.pop();
720
- self.empty(true);
721
- self.setValue(rows);
792
+ const editorValue = rows.pop()
722
793
 
723
- if (self.rows[self.rows.length-1]) {
724
- new_active_tab = self.rows[self.rows.length-1].tab;
794
+ this.setValue(rows)
795
+
796
+ if (this.rows[this.rows.length - 1]) {
797
+ newActiveTab = this.rows[this.rows.length - 1].tab
725
798
  }
726
799
 
727
- if(new_active_tab) {
728
- self.active_tab = new_active_tab;
729
- self.refreshTabs();
800
+ if (newActiveTab) {
801
+ this.active_tab = newActiveTab
802
+ this.refreshTabs()
730
803
  }
731
804
 
732
- self.onChange(true);
733
- self.jsoneditor.trigger('deleteRow');
734
- });
735
- self.controls.appendChild(this.delete_last_row_button);
805
+ this.onChange(true)
806
+ this.jsoneditor.trigger('deleteRow', editorValue)
807
+ })
808
+ this.controls.appendChild(button)
809
+ return button
810
+ }
736
811
 
737
- this.remove_all_rows_button = this.getButton(this.translate('button_delete_all'),'delete',this.translate('button_delete_all_title'));
738
- this.remove_all_rows_button.classList.add('json-editor-btntype-deleteall');
739
- this.remove_all_rows_button.addEventListener('click',function(e) {
740
- e.preventDefault();
741
- e.stopPropagation();
812
+ _createRemoveAllRowsButton () {
813
+ const button = this.getButton('button_delete_all', 'delete', 'button_delete_all_title')
814
+ button.classList.add('json-editor-btntype-deleteall')
815
+ button.addEventListener('click', (e) => {
816
+ e.preventDefault()
817
+ e.stopPropagation()
742
818
 
743
- if (!self.askConfirmation()) {
744
- return false;
819
+ if (!this.askConfirmation()) {
820
+ return false
745
821
  }
746
822
 
747
- self.empty(true);
748
- self.setValue([]);
749
- self.onChange(true);
750
- self.jsoneditor.trigger('deleteAllRows');
751
- });
752
- self.controls.appendChild(this.remove_all_rows_button);
753
-
754
- if(self.tabs) {
755
- this.add_row_button.style.width = '100%';
756
- this.add_row_button.style.textAlign = 'left';
757
- this.add_row_button.style.marginBottom = '3px';
758
-
759
- this.delete_last_row_button.style.width = '100%';
760
- this.delete_last_row_button.style.textAlign = 'left';
761
- this.delete_last_row_button.style.marginBottom = '3px';
762
-
763
- this.remove_all_rows_button.style.width = '100%';
764
- this.remove_all_rows_button.style.textAlign = 'left';
765
- this.remove_all_rows_button.style.marginBottom = '3px';
766
- }
767
- },
768
- showValidationErrors: function(errors) {
769
- var self = this;
770
-
771
- // Get all the errors that pertain to this editor
772
- var my_errors = [];
773
- var other_errors = [];
774
- $each(errors, function(i,error) {
775
- if(error.path === self.path) {
776
- my_errors.push(error);
777
- }
778
- else {
779
- other_errors.push(error);
780
- }
781
- });
782
-
783
- // Show errors for this editor
784
- if(this.error_holder) {
785
- if(my_errors.length) {
786
- var message = [];
787
- this.error_holder.innerHTML = '';
788
- this.error_holder.style.display = '';
789
- $each(my_errors, function(i,error) {
790
- self.error_holder.appendChild(self.theme.getErrorMessage(error.message));
791
- });
792
- }
793
- // Hide error area
794
- else {
795
- this.error_holder.style.display = 'none';
796
- }
797
- }
823
+ const values = this.getValue()
798
824
 
799
- // Show errors for child editors
800
- $each(this.rows, function(i,row) {
801
- row.showValidationErrors(other_errors);
802
- });
825
+ this.empty(true)
826
+ this.setValue([])
827
+ this.onChange(true)
828
+ this.jsoneditor.trigger('deleteAllRows', values)
829
+ })
830
+ this.controls.appendChild(button)
831
+ return button
832
+ }
833
+
834
+ showValidationErrors (errors) {
835
+ /* Get all the errors that pertain to this editor */
836
+ const myErrors = []
837
+ const otherErrors = []
838
+ errors.forEach(error => {
839
+ if (error.path === this.path) {
840
+ myErrors.push(error)
841
+ } else {
842
+ otherErrors.push(error)
843
+ }
844
+ })
845
+
846
+ /* Show errors for this editor */
847
+ if (this.error_holder) {
848
+ if (myErrors.length) {
849
+ this.error_holder.innerHTML = ''
850
+ this.error_holder.style.display = ''
851
+ myErrors.forEach(error => {
852
+ this.error_holder.appendChild(this.theme.getErrorMessage(error.message))
853
+ })
854
+ /* Hide error area */
855
+ } else {
856
+ this.error_holder.style.display = 'none'
857
+ }
858
+ }
859
+
860
+ /* Show errors for child editors */
861
+ this.rows.forEach(row =>
862
+ row.showValidationErrors(otherErrors)
863
+ )
864
+ }
865
+ }
866
+ ArrayEditor.rules = rules
867
+
868
+ // drag/drop array item to adjust order
869
+ // handler(fromIdx, toIdx, fromDom, toDom), opt={useTrigger}
870
+ // useTrigger=true: pressing ctrl to enable drag
871
+ export function supportDragDrop (tab, handler, opt = {}) {
872
+ if (opt.useTrigger) {
873
+ tab.addEventListener('mousedown', e => {
874
+ if (e.ctrlKey) {
875
+ // window.console.log('enable drag')
876
+ tab.draggable = true
877
+ const fn = e => {
878
+ tab.draggable = false
879
+ // window.console.log('disable drag')
880
+ document.removeEventListener('dragend', fn)
881
+ document.removeEventListener('mouseup', fn)
882
+ }
883
+ document.addEventListener('dragend', fn)
884
+ document.addEventListener('mouseup', fn)
885
+ }
886
+ })
887
+ } else {
888
+ tab.draggable = true
803
889
  }
804
- });
890
+ tab.addEventListener('dragstart', e => {
891
+ window.curDrag = tab
892
+ })
893
+ tab.addEventListener('dragover', e => {
894
+ if (window.curDrag === null || window.curDrag === tab || window.curDrag.parentElement !== tab.parentElement) {
895
+ e.dataTransfer.dropEffect = 'none'
896
+ } else {
897
+ e.dataTransfer.dropEffect = 'move'
898
+ }
899
+ e.preventDefault()
900
+ })
901
+ tab.addEventListener('drop', e => {
902
+ e.preventDefault()
903
+ e.stopPropagation()
904
+ if (window.curDrag === null || window.curDrag === tab || window.curDrag.parentElement !== tab.parentElement) {
905
+ return
906
+ }
907
+ const getPos = item => {
908
+ let i = 0
909
+ let a = item.parentElement.firstElementChild
910
+ while (a !== item && a !== null) {
911
+ a = a.nextSibling
912
+ ++i
913
+ }
914
+ return i
915
+ }
916
+ const i = getPos(window.curDrag)
917
+ const j = getPos(tab)
918
+ handler(i, j, window.curDrag, tab)
919
+ window.curDrag = null
920
+ })
921
+ }