@wirenboard/json-editor 2.5.3-wb13

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 (283) hide show
  1. package/.env-dist +2 -0
  2. package/.eslintrc +7 -0
  3. package/.gitattributes +1 -0
  4. package/.github/PULL_REQUEST_TEMPLATE.md +9 -0
  5. package/.github/issue_template +25 -0
  6. package/.github/workflows/build.yml +58 -0
  7. package/.travis.yml +70 -0
  8. package/CHANGELOG.md +915 -0
  9. package/CONTRIBUTING.md +92 -0
  10. package/LICENSE +20 -0
  11. package/Makefile +26 -0
  12. package/README.md +1646 -0
  13. package/README_ADDON.md +573 -0
  14. package/UPGRADING.md +46 -0
  15. package/build/CssToJson.js +55 -0
  16. package/codecept.conf.js +35 -0
  17. package/config/.eslintrc +7 -0
  18. package/config/codeceptjs_helpers.js +139 -0
  19. package/config/helpers.js +10 -0
  20. package/config/karma.conf.js +93 -0
  21. package/config/readme.md +31 -0
  22. package/config/webpack.common.js +75 -0
  23. package/config/webpack.dev.js +15 -0
  24. package/config/webpack.nonmin.js +19 -0
  25. package/config/webpack.prod.js +25 -0
  26. package/dist/jsoneditor.js +14 -0
  27. package/dist/nonmin/jsoneditor.js +29097 -0
  28. package/dist/nonmin/jsoneditor.js.map +1 -0
  29. package/docs/ace_editor.html +56 -0
  30. package/docs/advanced.html +136 -0
  31. package/docs/basic.html +63 -0
  32. package/docs/basic_person.json +26 -0
  33. package/docs/choices.html +86 -0
  34. package/docs/cleave.html +132 -0
  35. package/docs/colorpicker.html +194 -0
  36. package/docs/css_integration.html +135 -0
  37. package/docs/datetime.html +305 -0
  38. package/docs/describedby.html +161 -0
  39. package/docs/enumsource.html +67 -0
  40. package/docs/images/categoriesDemo.png +0 -0
  41. package/docs/images/inheritance_tree.png +0 -0
  42. package/docs/images/jsoneditor.png +0 -0
  43. package/docs/imask.html +192 -0
  44. package/docs/index.html +579 -0
  45. package/docs/materialize_css.html +164 -0
  46. package/docs/meta_schema.json +705 -0
  47. package/docs/multiple_upload_base64.html +65 -0
  48. package/docs/person.json +73 -0
  49. package/docs/polyfills/assign.js +29 -0
  50. package/docs/radio.html +156 -0
  51. package/docs/recursive.html +170 -0
  52. package/docs/select2.html +99 -0
  53. package/docs/selectize.html +100 -0
  54. package/docs/signature.html +42 -0
  55. package/docs/starrating.html +137 -0
  56. package/docs/upload.html +131 -0
  57. package/docs/uuid.html +70 -0
  58. package/docs/wysiwyg.html +56 -0
  59. package/jasmine.json +11 -0
  60. package/json-editor-json-editor-2.5.3-wb13.tgz +0 -0
  61. package/package.json +100 -0
  62. package/release-notes.md +88 -0
  63. package/src/core.js +412 -0
  64. package/src/defaults.js +402 -0
  65. package/src/editor.js +707 -0
  66. package/src/editors/ace.js +89 -0
  67. package/src/editors/array/choices.js +103 -0
  68. package/src/editors/array/select2.js +110 -0
  69. package/src/editors/array/selectize.js +103 -0
  70. package/src/editors/array.css +9 -0
  71. package/src/editors/array.css.js +3 -0
  72. package/src/editors/array.js +818 -0
  73. package/src/editors/autocomplete.js +58 -0
  74. package/src/editors/base64.js +157 -0
  75. package/src/editors/button.js +97 -0
  76. package/src/editors/checkbox.js +95 -0
  77. package/src/editors/choices.css +3 -0
  78. package/src/editors/choices.css.js +3 -0
  79. package/src/editors/choices.js +69 -0
  80. package/src/editors/colorpicker.js +103 -0
  81. package/src/editors/datetime.js +141 -0
  82. package/src/editors/describedby.js +188 -0
  83. package/src/editors/enum.js +136 -0
  84. package/src/editors/hidden.js +127 -0
  85. package/src/editors/index.js +81 -0
  86. package/src/editors/info.js +20 -0
  87. package/src/editors/integer.js +19 -0
  88. package/src/editors/ip.js +36 -0
  89. package/src/editors/jodit.js +64 -0
  90. package/src/editors/multiple.js +409 -0
  91. package/src/editors/multiselect.js +218 -0
  92. package/src/editors/null.js +18 -0
  93. package/src/editors/number.js +51 -0
  94. package/src/editors/object.css +41 -0
  95. package/src/editors/object.css.js +3 -0
  96. package/src/editors/object.js +1290 -0
  97. package/src/editors/radio.js +111 -0
  98. package/src/editors/sceditor.js +72 -0
  99. package/src/editors/select.js +370 -0
  100. package/src/editors/select2.js +110 -0
  101. package/src/editors/selectize.js +112 -0
  102. package/src/editors/signature.js +113 -0
  103. package/src/editors/simplemde.js +100 -0
  104. package/src/editors/starrating.css +52 -0
  105. package/src/editors/starrating.css.js +3 -0
  106. package/src/editors/starrating.js +135 -0
  107. package/src/editors/stepper.js +27 -0
  108. package/src/editors/string.js +372 -0
  109. package/src/editors/table.js +516 -0
  110. package/src/editors/upload.js +321 -0
  111. package/src/editors/uuid.js +56 -0
  112. package/src/iconlib.js +24 -0
  113. package/src/iconlibs/bootstrap2.js +28 -0
  114. package/src/iconlibs/bootstrap3.js +28 -0
  115. package/src/iconlibs/fontawesome3.js +28 -0
  116. package/src/iconlibs/fontawesome4.js +28 -0
  117. package/src/iconlibs/fontawesome5.js +28 -0
  118. package/src/iconlibs/foundation2.js +24 -0
  119. package/src/iconlibs/foundation3.js +28 -0
  120. package/src/iconlibs/index.js +25 -0
  121. package/src/iconlibs/jqueryui.js +28 -0
  122. package/src/iconlibs/materialicons.js +49 -0
  123. package/src/iconlibs/openiconic.js +28 -0
  124. package/src/iconlibs/spectre.js +28 -0
  125. package/src/resolvers.js +128 -0
  126. package/src/schemaloader.js +408 -0
  127. package/src/style.css +150 -0
  128. package/src/style.css.js +3 -0
  129. package/src/templates/default.js +52 -0
  130. package/src/templates/ejs.js +13 -0
  131. package/src/templates/handlebars.js +1 -0
  132. package/src/templates/hogan.js +10 -0
  133. package/src/templates/index.js +21 -0
  134. package/src/templates/lodash.js +9 -0
  135. package/src/templates/markup.js +9 -0
  136. package/src/templates/mustache.js +9 -0
  137. package/src/templates/swig.js +1 -0
  138. package/src/templates/underscore.js +9 -0
  139. package/src/theme.js +659 -0
  140. package/src/themes/barebones.css +35 -0
  141. package/src/themes/barebones.css.js +3 -0
  142. package/src/themes/barebones.js +28 -0
  143. package/src/themes/bootstrap2.js +319 -0
  144. package/src/themes/bootstrap3.css +0 -0
  145. package/src/themes/bootstrap3.css.js +3 -0
  146. package/src/themes/bootstrap3.js +315 -0
  147. package/src/themes/bootstrap4.css +89 -0
  148. package/src/themes/bootstrap4.css.js +3 -0
  149. package/src/themes/bootstrap4.js +690 -0
  150. package/src/themes/bootstrap5.css.js +3 -0
  151. package/src/themes/foundation.js +569 -0
  152. package/src/themes/html.css +60 -0
  153. package/src/themes/html.css.js +3 -0
  154. package/src/themes/html.js +71 -0
  155. package/src/themes/index.js +28 -0
  156. package/src/themes/jqueryui.js +198 -0
  157. package/src/themes/materialize.js +426 -0
  158. package/src/themes/spectre.css +208 -0
  159. package/src/themes/spectre.css.js +3 -0
  160. package/src/themes/spectre.js +406 -0
  161. package/src/themes/tailwind.css +249 -0
  162. package/src/themes/tailwind.css.js +3 -0
  163. package/src/themes/tailwind.js +443 -0
  164. package/src/utilities.js +138 -0
  165. package/src/validator.js +877 -0
  166. package/src/validators/ip-validator.js +51 -0
  167. package/tests/Dockerfile +3 -0
  168. package/tests/README.md +48 -0
  169. package/tests/codeceptjs/codecept.json +42 -0
  170. package/tests/codeceptjs/constrains/if-then-else_test.js +143 -0
  171. package/tests/codeceptjs/core_test.js +217 -0
  172. package/tests/codeceptjs/editors/advanced_test.js +13 -0
  173. package/tests/codeceptjs/editors/array_any_of_test.js +50 -0
  174. package/tests/codeceptjs/editors/array_test.js +900 -0
  175. package/tests/codeceptjs/editors/button_test.js +35 -0
  176. package/tests/codeceptjs/editors/checkbox_test.js +21 -0
  177. package/tests/codeceptjs/editors/colorpicker_test.js +27 -0
  178. package/tests/codeceptjs/editors/datetime_test.js +33 -0
  179. package/tests/codeceptjs/editors/inheritance_test.js +11 -0
  180. package/tests/codeceptjs/editors/integer_test.js +84 -0
  181. package/tests/codeceptjs/editors/issues/issue-gh-812_test.js +32 -0
  182. package/tests/codeceptjs/editors/jodit_test.js +24 -0
  183. package/tests/codeceptjs/editors/multiselect_test.js +8 -0
  184. package/tests/codeceptjs/editors/number_test.js +82 -0
  185. package/tests/codeceptjs/editors/object_test.js +204 -0
  186. package/tests/codeceptjs/editors/option-no_default_values_test.js +42 -0
  187. package/tests/codeceptjs/editors/programmatic-changes_test.js +20 -0
  188. package/tests/codeceptjs/editors/radio_test.js +10 -0
  189. package/tests/codeceptjs/editors/rating_test.js +13 -0
  190. package/tests/codeceptjs/editors/select_test.js +22 -0
  191. package/tests/codeceptjs/editors/stepper_test.js +27 -0
  192. package/tests/codeceptjs/editors/string_test.js +118 -0
  193. package/tests/codeceptjs/editors/table-confirm-delete_test.js +67 -0
  194. package/tests/codeceptjs/editors/tabs_test.js +14 -0
  195. package/tests/codeceptjs/editors/uuid_test.js +21 -0
  196. package/tests/codeceptjs/editors/validation_test.js +14 -0
  197. package/tests/codeceptjs/meta-schema_test.js +17 -0
  198. package/tests/codeceptjs/schemaloader_test.js +13 -0
  199. package/tests/codeceptjs/steps.d.ts +13 -0
  200. package/tests/codeceptjs/steps_file.js +12 -0
  201. package/tests/codeceptjs/themes_test.js +519 -0
  202. package/tests/docker-compose.yml +34 -0
  203. package/tests/fixtures/basic_person.json +26 -0
  204. package/tests/fixtures/nested_object.json +26 -0
  205. package/tests/fixtures/person.json +55 -0
  206. package/tests/fixtures/recursive.json +8 -0
  207. package/tests/fixtures/some_types.json +32 -0
  208. package/tests/fixtures/string.json +3 -0
  209. package/tests/fixtures/validation.json +1140 -0
  210. package/tests/pages/_demo.html +475 -0
  211. package/tests/pages/advanced.html +137 -0
  212. package/tests/pages/anyof.html +80 -0
  213. package/tests/pages/array-anyof.html +142 -0
  214. package/tests/pages/array-checkboxes.html +41 -0
  215. package/tests/pages/array-choices.html +45 -0
  216. package/tests/pages/array-integers.html +37 -0
  217. package/tests/pages/array-move-events.html +61 -0
  218. package/tests/pages/array-multiselects.html +42 -0
  219. package/tests/pages/array-nested-arrays.html +40 -0
  220. package/tests/pages/array-numbers.html +37 -0
  221. package/tests/pages/array-objects.html +42 -0
  222. package/tests/pages/array-ratings.html +40 -0
  223. package/tests/pages/array-selectize.html +51 -0
  224. package/tests/pages/array-selects.html +36 -0
  225. package/tests/pages/array-strings.html +36 -0
  226. package/tests/pages/array.html +42 -0
  227. package/tests/pages/assets/pages.css +130 -0
  228. package/tests/pages/button-callbacks.html +77 -0
  229. package/tests/pages/checkbox-labels.html +114 -0
  230. package/tests/pages/colorpicker-no-3rd-party.html +43 -0
  231. package/tests/pages/colorpicker-use-vanilla-picker.html +50 -0
  232. package/tests/pages/core.html +118 -0
  233. package/tests/pages/datetime.html +76 -0
  234. package/tests/pages/form-name.html +108 -0
  235. package/tests/pages/grid-strict.html +311 -0
  236. package/tests/pages/grid.html +284 -0
  237. package/tests/pages/if-then-else-allOf.html +117 -0
  238. package/tests/pages/inheritance.html +76 -0
  239. package/tests/pages/integer.html +68 -0
  240. package/tests/pages/issues/_template.html +50 -0
  241. package/tests/pages/issues/issue-gh-812.html +110 -0
  242. package/tests/pages/issues/issue-gh-823-meta-schema.html +35 -0
  243. package/tests/pages/issues/issue-gh-848.html +81 -0
  244. package/tests/pages/meta_schema.json +705 -0
  245. package/tests/pages/number.html +89 -0
  246. package/tests/pages/object-no-additional-properties.html +65 -0
  247. package/tests/pages/object-no-duplicated-id.html +68 -0
  248. package/tests/pages/object-required-properties.html +236 -0
  249. package/tests/pages/object-with-dependencies-array.html +46 -0
  250. package/tests/pages/object-with-dependencies.html +60 -0
  251. package/tests/pages/object.html +79 -0
  252. package/tests/pages/oneof.html +103 -0
  253. package/tests/pages/option-no_default_values.html +58 -0
  254. package/tests/pages/programmatic-changes.html +120 -0
  255. package/tests/pages/read-only.html +105 -0
  256. package/tests/pages/select.html +41 -0
  257. package/tests/pages/stepper.html +59 -0
  258. package/tests/pages/string-ace-editor.html +52 -0
  259. package/tests/pages/string-cleave.html +46 -0
  260. package/tests/pages/string-custom-attributes.html +62 -0
  261. package/tests/pages/string-formats.html +52 -0
  262. package/tests/pages/string-formats2.html +57 -0
  263. package/tests/pages/string-jodit-editor.html +49 -0
  264. package/tests/pages/string-sceditor.html +62 -0
  265. package/tests/pages/table-move-events.html +56 -0
  266. package/tests/pages/table.html +46 -0
  267. package/tests/pages/tabs.html +131 -0
  268. package/tests/pages/themes.html +527 -0
  269. package/tests/pages/translate-property.html +247 -0
  270. package/tests/pages/urn.html +93 -0
  271. package/tests/pages/uuid.html +72 -0
  272. package/tests/pages/validation.html +99 -0
  273. package/tests/unit/.eslintrc +8 -0
  274. package/tests/unit/core.spec.js +309 -0
  275. package/tests/unit/defaults.spec.js +40 -0
  276. package/tests/unit/editor.spec.js +160 -0
  277. package/tests/unit/editors/array.spec.js +86 -0
  278. package/tests/unit/editors/object.spec.js +79 -0
  279. package/tests/unit/editors/table.spec.js +91 -0
  280. package/tests/unit/readme.md +35 -0
  281. package/tests/unit/schemaloader.spec.js +498 -0
  282. package/tests/unit/validator.spec.js +94 -0
  283. package/tests/unit/validators/ip-validator.spec.js +62 -0
@@ -0,0 +1,818 @@
1
+ import { AbstractEditor } from '../editor.js'
2
+ import { extend, trigger } from '../utilities.js'
3
+ import rules from './array.css.js'
4
+
5
+ export class ArrayEditor extends AbstractEditor {
6
+ askConfirmation () {
7
+ if (this.jsoneditor.options.prompt_before_delete === true) {
8
+ if (window.confirm(this.translate('button_delete_node_warning')) === false) {
9
+ return false
10
+ }
11
+ }
12
+ return true
13
+ }
14
+
15
+ getDefault () {
16
+ return this.schema.default || []
17
+ }
18
+
19
+ register () {
20
+ super.register()
21
+ if (this.rows) {
22
+ this.rows.forEach(row => row.register())
23
+ }
24
+ }
25
+
26
+ unregister () {
27
+ super.unregister()
28
+ if (this.rows) {
29
+ this.rows.forEach(row => row.unregister())
30
+ }
31
+ }
32
+
33
+ getNumColumns () {
34
+ const info = this.getItemInfo(0)
35
+ /* Tabs require extra horizontal space */
36
+ if (this.tabs_holder && this.schema.format !== 'tabs-top') {
37
+ return Math.max(Math.min(12, info.width + 2), 4)
38
+ }
39
+ return info.width
40
+ }
41
+
42
+ enable () {
43
+ if (!this.always_disabled) {
44
+ this.setAvailability(this, false)
45
+
46
+ if (this.rows) {
47
+ this.rows.forEach(row => {
48
+ row.enable()
49
+ this.setAvailability(row, false)
50
+ })
51
+ }
52
+ super.enable()
53
+ }
54
+ }
55
+
56
+ disable (alwaysDisabled) {
57
+ if (alwaysDisabled) this.always_disabled = true
58
+ this.setAvailability(this, true)
59
+
60
+ if (this.rows) {
61
+ this.rows.forEach(row => {
62
+ row.disable(alwaysDisabled)
63
+ this.setAvailability(row, true)
64
+ })
65
+ }
66
+ super.disable()
67
+ }
68
+
69
+ setAvailability (element, val) {
70
+ if (element.add_row_button) element.add_row_button.disabled = val
71
+ if (element.remove_all_rows_button) element.remove_all_rows_button.disabled = val
72
+ if (element.delete_last_row_button) element.delete_last_row_button.disabled = val
73
+ if (element.copy_button) element.copy_button.disabled = val
74
+ if (element.delete_button) element.delete_button.disabled = val
75
+ if (element.moveup_button) element.moveup_button.disabled = val
76
+ if (element.movedown_button) element.movedown_button.disabled = val
77
+ }
78
+
79
+ preBuild () {
80
+ super.preBuild()
81
+
82
+ this.rows = []
83
+ this.row_cache = []
84
+
85
+ this.hide_delete_buttons = this.options.disable_array_delete || this.jsoneditor.options.disable_array_delete
86
+ 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
87
+ 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
88
+ this.hide_move_buttons = this.options.disable_array_reorder || this.jsoneditor.options.disable_array_reorder
89
+ this.hide_add_button = this.options.disable_array_add || this.jsoneditor.options.disable_array_add
90
+ this.show_copy_button = this.options.enable_array_copy || this.jsoneditor.options.enable_array_copy
91
+ this.array_controls_top = this.options.array_controls_top || this.jsoneditor.options.array_controls_top
92
+ }
93
+
94
+ build () {
95
+ if (!this.options.compact) {
96
+ this.header = document.createElement('label')
97
+ this.header.textContent = this.getTitle()
98
+ this.title = this.theme.getHeader(this.header, this.getPathDepth())
99
+ this.title_controls = this.theme.getHeaderButtonHolder()
100
+ if (!this.options.wb || !this.options.wb.disable_title) {
101
+ this.container.appendChild(this.title)
102
+ this.title.appendChild(this.title_controls)
103
+ }
104
+ if (this.options.infoText) {
105
+ this.infoButton = this.theme.getInfoButton(this.translateProperty(this.options.infoText))
106
+ this.container.appendChild(this.infoButton)
107
+ }
108
+ if (this.schema.description) {
109
+ this.description = this.theme.getDescription(this.translateProperty(this.schema.description))
110
+ this.container.appendChild(this.description)
111
+ }
112
+ this.error_holder = document.createElement('div')
113
+ this.container.appendChild(this.error_holder)
114
+
115
+ if (this.schema.format === 'tabs-top') {
116
+ this.controls = this.theme.getHeaderButtonHolder()
117
+ this.title.appendChild(this.controls)
118
+ this.tabs_holder = this.theme.getTopTabHolder(this.getValidId(this.getItemTitle()))
119
+ this.container.appendChild(this.tabs_holder)
120
+ this.row_holder = this.theme.getTopTabContentHolder(this.tabs_holder)
121
+
122
+ this.active_tab = null
123
+ } else if (this.schema.format === 'tabs') {
124
+ this.controls = this.theme.getHeaderButtonHolder()
125
+ this.title.appendChild(this.controls)
126
+ this.tabs_holder = this.theme.getTabHolder(this.getValidId(this.getItemTitle()))
127
+ this.container.appendChild(this.tabs_holder)
128
+ this.row_holder = this.theme.getTabContentHolder(this.tabs_holder)
129
+
130
+ this.active_tab = null
131
+ } else {
132
+ if (!this.options.wb || !this.options.wb.disable_panel) {
133
+ this.panel = this.theme.getIndentedPanel()
134
+ } else {
135
+ this.panel = document.createElement('div')
136
+ }
137
+ this.container.appendChild(this.panel)
138
+ this.row_holder = document.createElement('div')
139
+ this.panel.appendChild(this.row_holder)
140
+ this.controls = this.theme.getButtonHolder()
141
+ if (this.array_controls_top) {
142
+ this.title.appendChild(this.controls)
143
+ } else {
144
+ this.panel.appendChild(this.controls)
145
+ }
146
+ }
147
+ } else {
148
+ /* compact mode */
149
+ this.title = this.theme.getHeader('', this.getPathDepth())
150
+ this.panel = document.createElement('div')
151
+ this.container.appendChild(this.panel)
152
+ this.title_controls = this.theme.getHeaderButtonHolder()
153
+ this.controls = this.theme.getHeaderButtonHolder()
154
+ this.row_holder = document.createElement('div')
155
+ this.panel.appendChild(this.row_holder)
156
+ }
157
+
158
+ /* Add controls */
159
+ this.addControls()
160
+ }
161
+
162
+ onChildEditorChange (editor) {
163
+ this.refreshValue()
164
+ this.refreshTabs(true)
165
+ super.onChildEditorChange(editor)
166
+ }
167
+
168
+ getItemTitle () {
169
+ if (!this.item_title) {
170
+ if (this.schema.items && !Array.isArray(this.schema.items)) {
171
+ const tmp = this.jsoneditor.expandRefs(this.schema.items)
172
+ this.item_title = this.translateProperty(tmp.title) || this.translate('default_array_item_title')
173
+ } else {
174
+ this.item_title = this.translate('default_array_item_title')
175
+ }
176
+ }
177
+ return this.cleanText(this.item_title)
178
+ }
179
+
180
+ getItemSchema (i) {
181
+ if (Array.isArray(this.schema.items)) {
182
+ if (i >= this.schema.items.length) {
183
+ if (this.schema.additionalItems === true) {
184
+ return {}
185
+ } else if (this.schema.additionalItems) {
186
+ return extend({}, this.schema.additionalItems)
187
+ }
188
+ } else {
189
+ return extend({}, this.schema.items[i])
190
+ }
191
+ } else if (this.schema.items) {
192
+ if (!this.cachedItems) {
193
+ var items = extend({}, this.schema.items)
194
+ this.cachedItems = this.jsoneditor.expandRefs(items)
195
+ this.singleItemSchema = true
196
+ }
197
+ return extend({}, this.cachedItems)
198
+ } else {
199
+ return {}
200
+ }
201
+ }
202
+
203
+ getItemInfo (i, schema) {
204
+ if (!schema) {
205
+ schema = this.getItemSchema(i)
206
+ }
207
+
208
+ /* Check if it's cached */
209
+ this.item_info = this.item_info || {}
210
+ const stringified = JSON.stringify(schema)
211
+ if (typeof this.item_info[stringified] !== 'undefined') return this.item_info[stringified]
212
+
213
+ this.item_info[stringified] = {
214
+ title: this.translateProperty(schema.title) || this.translate('default_array_item_title'),
215
+ default: schema.default,
216
+ width: 12,
217
+ child_editors: schema.properties || schema.items
218
+ }
219
+
220
+ return this.item_info[stringified]
221
+ }
222
+
223
+ getElementEditor (i) {
224
+ const schema = this.getItemSchema(i)
225
+ const itemInfo = this.getItemInfo(i, schema)
226
+ schema.title = `${itemInfo.title} ${i + 1}`
227
+
228
+ var editor
229
+ if (this.singleItemSchema) {
230
+ if (!this.cachedEditorClass) {
231
+ this.cachedEditorClass = this.jsoneditor.getEditorClass(schema)
232
+ }
233
+ editor = this.cachedEditorClass
234
+ } else {
235
+ editor = this.jsoneditor.getEditorClass(schema)
236
+ }
237
+
238
+ let holder
239
+ if (this.tabs_holder) {
240
+ if (this.schema.format === 'tabs-top') {
241
+ holder = this.theme.getTopTabContent()
242
+ } else {
243
+ holder = this.theme.getTabContent()
244
+ }
245
+ holder.id = `${this.path}.${i}`
246
+ } else if (itemInfo.child_editors) {
247
+ holder = this.theme.getChildEditorHolder()
248
+ } else {
249
+ if (!this.options.wb || !this.options.wb.disable_array_item_panel) {
250
+ holder = this.theme.getIndentedPanel()
251
+ } else {
252
+ holder = document.createElement('div')
253
+ }
254
+ }
255
+
256
+ this.row_holder.appendChild(holder)
257
+
258
+ const ret = this.jsoneditor.createEditor(editor, {
259
+ jsoneditor: this.jsoneditor,
260
+ schema,
261
+ container: holder,
262
+ path: `${this.path}.${i}`,
263
+ parent: this,
264
+ required: true
265
+ })
266
+ ret.preBuild()
267
+ ret.build()
268
+ ret.postBuild()
269
+
270
+ if (!ret.title_controls) {
271
+ ret.array_controls = this.theme.getButtonHolder()
272
+ if (!this.hide_delete_buttons || this.show_copy_button || !this.hide_move_buttons) {
273
+ holder.appendChild(ret.array_controls)
274
+ }
275
+ }
276
+
277
+ return ret
278
+ }
279
+
280
+ checkParent (elem) {
281
+ return elem && elem.parentNode
282
+ }
283
+
284
+ destroy () {
285
+ this.empty(true)
286
+ if (this.checkParent(this.title)) this.title.parentNode.removeChild(this.title)
287
+ if (this.checkParent(this.description)) this.description.parentNode.removeChild(this.description)
288
+ if (this.checkParent(this.row_holder)) this.row_holder.parentNode.removeChild(this.row_holder)
289
+ if (this.checkParent(this.controls)) this.controls.parentNode.removeChild(this.controls)
290
+ if (this.checkParent(this.panel)) this.panel.parentNode.removeChild(this.panel)
291
+
292
+ this.rows = this.row_cache = this.title = this.description = this.row_holder = this.panel = this.controls = null
293
+
294
+ super.destroy()
295
+ }
296
+
297
+ empty (hard) {
298
+ if (!this.rows) return
299
+
300
+ this.rows.forEach((row, i) => {
301
+ if (hard) {
302
+ if (this.checkParent(row.tab)) row.tab.parentNode.removeChild(row.tab)
303
+ this.destroyRow(row, true)
304
+ this.row_cache[i] = null
305
+ }
306
+ this.rows[i] = null
307
+ })
308
+ this.rows = []
309
+ if (hard) this.row_cache = []
310
+ }
311
+
312
+ destroyRow (row, hard) {
313
+ const holder = row.container
314
+ if (hard) {
315
+ row.destroy()
316
+ if (holder.parentNode) holder.parentNode.removeChild(holder)
317
+ if (this.checkParent(row.tab)) row.tab.parentNode.removeChild(row.tab)
318
+ } else {
319
+ if (row.tab) row.tab.style.display = 'none'
320
+ holder.style.display = 'none'
321
+ row.unregister()
322
+ }
323
+ }
324
+
325
+ getMax () {
326
+ if ((Array.isArray(this.schema.items)) && this.schema.additionalItems === false) {
327
+ return Math.min(this.schema.items.length, this.schema.maxItems || Infinity)
328
+ }
329
+ return this.schema.maxItems || Infinity
330
+ }
331
+
332
+ refreshTabs (refreshHeaders) {
333
+ this.rows.forEach(row => {
334
+ if (!row.tab) return
335
+
336
+ if (refreshHeaders) {
337
+ row.tab_text.textContent = row.getHeaderText()
338
+ } else if (row.tab === this.active_tab) {
339
+ this.theme.markTabActive(row)
340
+ } else {
341
+ this.theme.markTabInactive(row)
342
+ }
343
+ })
344
+ }
345
+
346
+ ensureArraySize (value) {
347
+ if (!(Array.isArray(value))) value = [value]
348
+
349
+ if (this.schema.minItems) {
350
+ while (value.length < this.schema.minItems) {
351
+ value.push(this.getItemInfo(value.length).default)
352
+ }
353
+ }
354
+ if (this.getMax() && value.length > this.getMax()) {
355
+ value = value.slice(0, this.getMax())
356
+ }
357
+ return value
358
+ }
359
+
360
+ setValue (value = [], initial) {
361
+ /* Make sure value has between minItems and maxItems items in it */
362
+ value = this.ensureArraySize(value)
363
+
364
+ const serialized = JSON.stringify(value)
365
+ if (serialized === this.serialized) return
366
+
367
+ value.forEach((val, i) => {
368
+ if (this.rows[i]) {
369
+ /* TODO: don't set the row's value if it hasn't changed */
370
+ this.rows[i].setValue(val, initial)
371
+ } else if (this.row_cache[i]) {
372
+ this.rows[i] = this.row_cache[i]
373
+ this.rows[i].setValue(val, initial)
374
+ this.rows[i].container.style.display = ''
375
+ if (this.rows[i].tab) this.rows[i].tab.style.display = ''
376
+ this.rows[i].register()
377
+ this.jsoneditor.trigger('addRow', this.rows[i])
378
+ } else {
379
+ const editor = this.addRow(val, initial)
380
+ this.jsoneditor.trigger('addRow', editor)
381
+ }
382
+ })
383
+
384
+ for (let j = value.length; j < this.rows.length; j++) {
385
+ this.destroyRow(this.rows[j])
386
+ this.rows[j] = null
387
+ }
388
+ this.rows = this.rows.slice(0, value.length)
389
+
390
+ /* Set the active tab */
391
+ const row = this.rows.find(row => row.tab === this.active_tab)
392
+ let newActiveTab = typeof row !== 'undefined' ? row.tab : null
393
+ if (!newActiveTab && this.rows.length) newActiveTab = this.rows[0].tab
394
+
395
+ this.active_tab = newActiveTab
396
+
397
+ this.refreshValue(initial)
398
+ this.refreshTabs(true)
399
+ this.refreshTabs()
400
+
401
+ this.onChange()
402
+
403
+ /* TODO: sortable */
404
+ }
405
+
406
+ setVisibility (element, display) {
407
+ element.style.display = display ? '' : 'none'
408
+ }
409
+
410
+ setupButtons (minItems) {
411
+ const controlsNeeded = []
412
+
413
+ if (!this.value.length) {
414
+ this.delete_last_row_button.style.display = 'none'
415
+ this.remove_all_rows_button.style.display = 'none'
416
+ } else if (this.value.length === 1) {
417
+ this.remove_all_rows_button.style.display = 'none'
418
+
419
+ /* If there are minItems items in the array, or configured to hide the delete_last_row button, hide the delete button beneath the rows */
420
+ const display = !(minItems || this.hide_delete_last_row_buttons)
421
+ this.setVisibility(this.delete_last_row_button, display)
422
+ controlsNeeded.push(display)
423
+ } else {
424
+ const display1 = !(minItems || this.hide_delete_last_row_buttons)
425
+ this.setVisibility(this.delete_last_row_button, display1)
426
+ controlsNeeded.push(display1)
427
+
428
+ const display2 = !(minItems || this.hide_delete_all_rows_buttons)
429
+ this.setVisibility(this.remove_all_rows_button, display2)
430
+ controlsNeeded.push(display2)
431
+ }
432
+
433
+ /* If there are maxItems in the array, hide the add button beneath the rows */
434
+ const display = !((this.getMax() && this.getMax() <= this.rows.length) || this.hide_add_button)
435
+ this.setVisibility(this.add_row_button, display)
436
+ controlsNeeded.push(display)
437
+
438
+ return controlsNeeded.some(e => e)
439
+ }
440
+
441
+ refreshValue (force) {
442
+ const oldi = this.value ? this.value.length : 0
443
+ /* Get the value for this editor */
444
+ this.value = this.rows.map(editor => editor.getValue())
445
+
446
+ if (oldi !== this.value.length || force) {
447
+ /* If we currently have minItems items in the array */
448
+ const minItems = this.schema.minItems && this.schema.minItems >= this.rows.length
449
+
450
+ this.rows.forEach((editor, i) => {
451
+ /* Hide the move down button for the last row */
452
+ if (editor.movedown_button) {
453
+ const display = (i !== this.rows.length - 1)
454
+ this.setVisibility(editor.movedown_button, display)
455
+ }
456
+
457
+ /* Hide the delete button if we have minItems items */
458
+ if (editor.delete_button) {
459
+ this.setVisibility(editor.delete_button, !minItems)
460
+ }
461
+
462
+ /* Get the value for this editor */
463
+ this.value[i] = editor.getValue()
464
+ })
465
+
466
+ if (!this.collapsed && this.setupButtons(minItems)) {
467
+ this.controls.style.display = 'inline-block'
468
+ } else {
469
+ this.controls.style.display = 'none'
470
+ }
471
+ }
472
+ this.serialized = JSON.stringify(this.value)
473
+ }
474
+
475
+ addRow (value, initial) {
476
+ const i = this.rows.length
477
+
478
+ this.rows[i] = this.getElementEditor(i)
479
+ this.row_cache[i] = this.rows[i]
480
+
481
+ if (this.tabs_holder) {
482
+ this.rows[i].tab_text = document.createElement('span')
483
+ this.rows[i].tab_text.textContent = this.rows[i].getHeaderText()
484
+ if (this.schema.format === 'tabs-top') {
485
+ this.rows[i].tab = this.theme.getTopTab(this.rows[i].tab_text, this.getValidId(this.rows[i].path))
486
+ this.theme.addTopTab(this.tabs_holder, this.rows[i].tab)
487
+ } else {
488
+ this.rows[i].tab = this.theme.getTab(this.rows[i].tab_text, this.getValidId(this.rows[i].path))
489
+ this.theme.addTab(this.tabs_holder, this.rows[i].tab)
490
+ }
491
+ this.rows[i].tab.addEventListener('click', (e) => {
492
+ this.active_tab = this.rows[i].tab
493
+ this.refreshTabs()
494
+ e.preventDefault()
495
+ e.stopPropagation()
496
+ })
497
+ }
498
+
499
+ const controlsHolder = this.rows[i].title_controls || this.rows[i].array_controls
500
+
501
+ /* Buttons to delete row, move row up, and move row down */
502
+ if (!this.hide_delete_buttons) {
503
+ this.rows[i].delete_button = this._createDeleteButton(i, controlsHolder)
504
+ }
505
+
506
+ /* Button to copy an array element and add it as last element */
507
+ if (this.show_copy_button) {
508
+ this.rows[i].copy_button = this._createCopyButton(i, controlsHolder)
509
+ }
510
+
511
+ if (i && !this.hide_move_buttons) {
512
+ this.rows[i].moveup_button = this._createMoveUpButton(i, controlsHolder)
513
+ }
514
+
515
+ if (!this.hide_move_buttons) {
516
+ this.rows[i].movedown_button = this._createMoveDownButton(i, controlsHolder)
517
+ }
518
+
519
+ if (typeof value !== 'undefined') this.rows[i].setValue(value, initial)
520
+ this.refreshTabs()
521
+
522
+ return this.rows[i]
523
+ }
524
+
525
+ _createDeleteButton (i, holder) {
526
+ const button = this.getButton(this.getItemTitle(), 'delete', 'button_delete_row_title', [this.getItemTitle()])
527
+ button.classList.add('delete', 'json-editor-btntype-delete')
528
+ button.setAttribute('data-i', i)
529
+ button.addEventListener('click', e => {
530
+ e.preventDefault()
531
+ e.stopPropagation()
532
+
533
+ if (!this.askConfirmation()) {
534
+ return false
535
+ }
536
+
537
+ const i = e.currentTarget.getAttribute('data-i') * 1
538
+ const newval = this.getValue().filter((row, j) => j !== i)
539
+ let newActiveTab = null
540
+
541
+ const editor = this.rows[i]
542
+
543
+ this.setValue(newval)
544
+
545
+ if (this.rows[i]) {
546
+ newActiveTab = this.rows[i].tab
547
+ } else if (this.rows[i - 1]) {
548
+ newActiveTab = this.rows[i - 1].tab
549
+ }
550
+
551
+ if (newActiveTab) {
552
+ this.active_tab = newActiveTab
553
+ this.refreshTabs()
554
+ }
555
+
556
+ this.onChange(true)
557
+ this.jsoneditor.trigger('deleteRow', editor)
558
+ })
559
+
560
+ if (holder) {
561
+ holder.appendChild(button)
562
+ }
563
+ return button
564
+ }
565
+
566
+ _createCopyButton (i, holder) {
567
+ const button = this.getButton(this.getItemTitle(), 'copy', 'button_copy_row_title', [this.getItemTitle()])
568
+ button.classList.add('copy', 'json-editor-btntype-copy')
569
+ button.setAttribute('data-i', i)
570
+ button.addEventListener('click', e => {
571
+ const value = this.getValue()
572
+ e.preventDefault()
573
+ e.stopPropagation()
574
+ const i = e.currentTarget.getAttribute('data-i') * 1
575
+
576
+ value.forEach((row, j) => {
577
+ if (j === i) {
578
+ value.push(row)
579
+ }
580
+ })
581
+
582
+ this.setValue(value)
583
+ this.refreshValue(true)
584
+ this.onChange(true)
585
+ })
586
+
587
+ holder.appendChild(button)
588
+ return button
589
+ }
590
+
591
+ _createMoveUpButton (i, holder) {
592
+ const button = this.getButton('', (this.schema.format === 'tabs-top' ? 'moveleft' : 'moveup'), 'button_move_up_title')
593
+ button.classList.add('moveup', 'json-editor-btntype-move')
594
+ button.setAttribute('data-i', i)
595
+ button.addEventListener('click', e => {
596
+ e.preventDefault()
597
+ e.stopPropagation()
598
+ const i = e.currentTarget.getAttribute('data-i') * 1
599
+
600
+ if (i <= 0) return
601
+ const rows = this.getValue()
602
+ const tmp = rows[i - 1]
603
+ rows[i - 1] = rows[i]
604
+ rows[i] = tmp
605
+
606
+ this.setValue(rows)
607
+ this.active_tab = this.rows[i - 1].tab
608
+ this.refreshTabs()
609
+
610
+ this.onChange(true)
611
+
612
+ this.jsoneditor.trigger('moveRow', this.rows[i - 1])
613
+ })
614
+
615
+ if (holder) {
616
+ holder.appendChild(button)
617
+ }
618
+ return button
619
+ }
620
+
621
+ _createMoveDownButton (i, holder) {
622
+ const button = this.getButton('', (this.schema.format === 'tabs-top' ? 'moveright' : 'movedown'), 'button_move_down_title')
623
+ button.classList.add('movedown', 'json-editor-btntype-move')
624
+ button.setAttribute('data-i', i)
625
+ button.addEventListener('click', e => {
626
+ e.preventDefault()
627
+ e.stopPropagation()
628
+ const i = e.currentTarget.getAttribute('data-i') * 1
629
+
630
+ const rows = this.getValue()
631
+ if (i >= rows.length - 1) return
632
+ const tmp = rows[i + 1]
633
+ rows[i + 1] = rows[i]
634
+ rows[i] = tmp
635
+
636
+ this.setValue(rows)
637
+ this.active_tab = this.rows[i + 1].tab
638
+ this.refreshTabs()
639
+ this.onChange(true)
640
+
641
+ this.jsoneditor.trigger('moveRow', this.rows[i + 1])
642
+ })
643
+
644
+ if (holder) {
645
+ holder.appendChild(button)
646
+ }
647
+ return button
648
+ }
649
+
650
+ addControls () {
651
+ this.collapsed = false
652
+ this.toggle_button = this._createToggleButton()
653
+
654
+ /* If it should start collapsed */
655
+ if (this.options.collapsed) {
656
+ trigger(this.toggle_button, 'click')
657
+ }
658
+
659
+ /* Collapse button disabled */
660
+ if (this.schema.options && typeof this.schema.options.disable_collapse !== 'undefined') {
661
+ if (this.schema.options.disable_collapse) this.toggle_button.style.display = 'none'
662
+ } else if (this.jsoneditor.options.disable_collapse) {
663
+ this.toggle_button.style.display = 'none'
664
+ }
665
+
666
+ /* Add "new row" and "delete last" buttons below editor */
667
+ this.add_row_button = this._createAddRowButton()
668
+ this.delete_last_row_button = this._createDeleteLastRowButton()
669
+ this.remove_all_rows_button = this._createRemoveAllRowsButton()
670
+
671
+ if (this.tabs) {
672
+ this.add_row_button.classList.add('je-array-control-btn')
673
+ this.delete_last_row_button.classList.add('je-array-control-btn')
674
+ this.remove_all_rows_button.classList.add('je-array-control-btn')
675
+ }
676
+ }
677
+
678
+ _createToggleButton () {
679
+ const button = this.getButton('', 'collapse', 'button_collapse')
680
+ button.classList.add('json-editor-btntype-toggle')
681
+ this.title.insertBefore(button, this.title.childNodes[0])
682
+
683
+ const rowHolderDisplay = this.row_holder.style.display
684
+ const controlsDisplay = this.controls.style.display
685
+ button.addEventListener('click', e => {
686
+ e.preventDefault()
687
+ e.stopPropagation()
688
+ if (this.panel) this.setVisibility(this.panel, this.collapsed)
689
+ if (this.tabs_holder) this.setVisibility(this.tabs_holder, this.collapsed)
690
+ if (this.collapsed) {
691
+ this.collapsed = false
692
+ this.row_holder.style.display = rowHolderDisplay
693
+ this.controls.style.display = controlsDisplay
694
+ this.setButtonText(e.currentTarget, '', 'collapse', 'button_collapse')
695
+ } else {
696
+ this.collapsed = true
697
+ this.row_holder.style.display = 'none'
698
+ this.controls.style.display = 'none'
699
+ this.setButtonText(e.currentTarget, '', 'expand', 'button_expand')
700
+ }
701
+ })
702
+ return button
703
+ }
704
+
705
+ _createAddRowButton () {
706
+ const button = this.getButton(this.getItemTitle(), 'add', 'button_add_row_title', [this.getItemTitle()])
707
+ button.classList.add('json-editor-btntype-add')
708
+ button.addEventListener('click', (e) => {
709
+ e.preventDefault()
710
+ e.stopPropagation()
711
+ const i = this.rows.length
712
+ let editor
713
+ if (this.row_cache[i]) {
714
+ editor = this.rows[i] = this.row_cache[i]
715
+ this.rows[i].setValue(this.rows[i].getDefault(), true)
716
+ this.rows[i].container.style.display = ''
717
+ if (this.rows[i].tab) this.rows[i].tab.style.display = ''
718
+ this.rows[i].register()
719
+ } else {
720
+ editor = this.addRow()
721
+ }
722
+ this.active_tab = this.rows[i].tab
723
+ this.refreshTabs()
724
+ this.refreshValue()
725
+ this.onChange(true)
726
+ this.jsoneditor.trigger('addRow', editor)
727
+ })
728
+ this.controls.appendChild(button)
729
+ return button
730
+ }
731
+
732
+ _createDeleteLastRowButton () {
733
+ const button = this.getButton('button_delete_last', 'subtract', 'button_delete_last_title', [this.getItemTitle()])
734
+ button.classList.add('json-editor-btntype-deletelast')
735
+ button.addEventListener('click', (e) => {
736
+ e.preventDefault()
737
+ e.stopPropagation()
738
+
739
+ if (!this.askConfirmation()) {
740
+ return false
741
+ }
742
+
743
+ const rows = this.getValue()
744
+ let newActiveTab = null
745
+
746
+ const editor = rows.pop()
747
+
748
+ this.setValue(rows)
749
+
750
+ if (this.rows[this.rows.length - 1]) {
751
+ newActiveTab = this.rows[this.rows.length - 1].tab
752
+ }
753
+
754
+ if (newActiveTab) {
755
+ this.active_tab = newActiveTab
756
+ this.refreshTabs()
757
+ }
758
+
759
+ this.onChange(true)
760
+ this.jsoneditor.trigger('deleteRow', editor)
761
+ })
762
+ this.controls.appendChild(button)
763
+ return button
764
+ }
765
+
766
+ _createRemoveAllRowsButton () {
767
+ const button = this.getButton('button_delete_all', 'delete', 'button_delete_all_title')
768
+ button.classList.add('json-editor-btntype-deleteall')
769
+ button.addEventListener('click', (e) => {
770
+ e.preventDefault()
771
+ e.stopPropagation()
772
+
773
+ if (!this.askConfirmation()) {
774
+ return false
775
+ }
776
+
777
+ this.empty(true)
778
+ this.setValue([])
779
+ this.onChange(true)
780
+ this.jsoneditor.trigger('deleteAllRows')
781
+ })
782
+ this.controls.appendChild(button)
783
+ return button
784
+ }
785
+
786
+ showValidationErrors (errors) {
787
+ /* Get all the errors that pertain to this editor */
788
+ const myErrors = []
789
+ const otherErrors = []
790
+ errors.forEach(error => {
791
+ if (error.path === this.path) {
792
+ myErrors.push(error)
793
+ } else {
794
+ otherErrors.push(error)
795
+ }
796
+ })
797
+
798
+ /* Show errors for this editor */
799
+ if (this.error_holder) {
800
+ if (myErrors.length) {
801
+ this.error_holder.innerHTML = ''
802
+ this.error_holder.style.display = ''
803
+ myErrors.forEach(error => {
804
+ this.error_holder.appendChild(this.theme.getErrorMessage(error.message))
805
+ })
806
+ /* Hide error area */
807
+ } else {
808
+ this.error_holder.style.display = 'none'
809
+ }
810
+ }
811
+
812
+ /* Show errors for child editors */
813
+ this.rows.forEach(row =>
814
+ row.showValidationErrors(otherErrors)
815
+ )
816
+ }
817
+ }
818
+ ArrayEditor.rules = rules