@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,28 @@
1
+
2
+ import { htmlTheme } from './html.js'
3
+ // import { bootstrap2Theme } from './bootstrap2'
4
+ import { bootstrap3Theme } from './bootstrap3.js'
5
+ import { bootstrap4Theme } from './bootstrap4.js'
6
+ // import { foundationTheme, foundation3Theme, foundation4Theme, foundation5Theme, foundation6Theme } from './foundation.js'
7
+ import { jqueryuiTheme } from './jqueryui.js'
8
+ import { barebonesTheme } from './barebones.js'
9
+ // import { materializeTheme } from './materialize'
10
+ import { spectreTheme } from './spectre.js'
11
+ import { tailwindTheme } from './tailwind.js'
12
+
13
+ export const themes = {
14
+ html: htmlTheme,
15
+ // bootstrap2: bootstrap2Theme,
16
+ bootstrap3: bootstrap3Theme,
17
+ bootstrap4: bootstrap4Theme,
18
+ // foundation: foundationTheme,
19
+ // foundation3: foundation3Theme,
20
+ // foundation4: foundation4Theme,
21
+ // foundation5: foundation5Theme,
22
+ // foundation6: foundation6Theme,
23
+ jqueryui: jqueryuiTheme,
24
+ barebones: barebonesTheme,
25
+ // materialize: materializeTheme,
26
+ spectre: spectreTheme,
27
+ tailwind: tailwindTheme
28
+ }
@@ -0,0 +1,198 @@
1
+ import { AbstractTheme } from '../theme.js'
2
+
3
+ export class jqueryuiTheme extends AbstractTheme {
4
+ getTable () {
5
+ const el = super.getTable()
6
+ el.setAttribute('cellpadding', 5)
7
+ el.setAttribute('cellspacing', 0)
8
+ return el
9
+ }
10
+
11
+ getTableHeaderCell (text) {
12
+ const el = super.getTableHeaderCell(text)
13
+ el.classList.add('ui-state-active')
14
+ el.style.fontWeight = 'bold'
15
+ return el
16
+ }
17
+
18
+ getTableCell () {
19
+ const el = super.getTableCell()
20
+ el.classList.add('ui-widget-content')
21
+ return el
22
+ }
23
+
24
+ getHeaderButtonHolder () {
25
+ const el = this.getButtonHolder()
26
+ el.style.marginLeft = '10px'
27
+ el.style.fontSize = '.6em'
28
+ el.style.display = 'inline-block'
29
+ return el
30
+ }
31
+
32
+ getFormInputDescription (text) {
33
+ const el = this.getDescription(text)
34
+ el.style.marginLeft = '10px'
35
+ el.style.display = 'inline-block'
36
+ return el
37
+ }
38
+
39
+ getFormControl (label, input, description, infoText) {
40
+ const el = super.getFormControl(label, input, description, infoText)
41
+ if (input.type === 'checkbox') {
42
+ el.style.lineHeight = '25px'
43
+
44
+ el.style.padding = '3px 0'
45
+ } else {
46
+ el.style.padding = '4px 0 8px 0'
47
+ }
48
+ return el
49
+ }
50
+
51
+ getDescription (text) {
52
+ const el = document.createElement('span')
53
+ el.style.fontSize = '.8em'
54
+ el.style.fontStyle = 'italic'
55
+ if (window.DOMPurify) el.innerHTML = window.DOMPurify.sanitize(text)
56
+ else el.textContent = this.cleanText(text)
57
+ return el
58
+ }
59
+
60
+ getButtonHolder () {
61
+ const el = document.createElement('div')
62
+ el.classList.add('ui-buttonset')
63
+ el.style.fontSize = '.7em'
64
+ return el
65
+ }
66
+
67
+ getFormInputLabel (text, req) {
68
+ const el = document.createElement('label')
69
+ el.style.fontWeight = 'bold'
70
+ el.style.display = 'block'
71
+ el.textContent = text
72
+ if (req) el.classList.add('required')
73
+ return el
74
+ }
75
+
76
+ getButton (text, icon, title) {
77
+ const button = document.createElement('button')
78
+ button.classList.add('ui-button', 'ui-widget', 'ui-state-default', 'ui-corner-all')
79
+
80
+ /* Icon only */
81
+ if (icon && !text) {
82
+ button.classList.add('ui-button-icon-only')
83
+ icon.classList.add('ui-button-icon-primary', 'ui-icon-primary')
84
+ button.appendChild(icon)
85
+ /* Icon and Text */
86
+ } else if (icon) {
87
+ button.classList.add('ui-button-text-icon-primary')
88
+ icon.classList.add('ui-button-icon-primary', 'ui-icon-primary')
89
+ button.appendChild(icon)
90
+ /* Text only */
91
+ } else {
92
+ button.classList.add('ui-button-text-only')
93
+ }
94
+
95
+ const el = document.createElement('span')
96
+ el.classList.add('ui-button-text')
97
+ el.textContent = text || title || '.'
98
+ button.appendChild(el)
99
+
100
+ button.setAttribute('title', title)
101
+
102
+ return button
103
+ }
104
+
105
+ setButtonText (button, text, icon, title) {
106
+ button.innerHTML = ''
107
+ button.classList.add('ui-button', 'ui-widget', 'ui-state-default', 'ui-corner-all')
108
+
109
+ /* Icon only */
110
+ if (icon && !text) {
111
+ button.classList.add('ui-button-icon-only')
112
+ icon.classList.add('ui-button-icon-primary', 'ui-icon-primary')
113
+ button.appendChild(icon)
114
+ /* Icon and Text */
115
+ } else if (icon) {
116
+ button.classList.add('ui-button-text-icon-primary')
117
+ icon.classList.add('ui-button-icon-primary', 'ui-icon-primary')
118
+ button.appendChild(icon)
119
+ /* Text only */
120
+ } else {
121
+ button.classList.add('ui-button-text-only')
122
+ }
123
+
124
+ const el = document.createElement('span')
125
+ el.classList.add('ui-button-text')
126
+ el.textContent = text || title || '.'
127
+ button.appendChild(el)
128
+
129
+ button.setAttribute('title', title)
130
+ }
131
+
132
+ getIndentedPanel () {
133
+ const el = document.createElement('div')
134
+ el.classList.add('ui-widget-content', 'ui-corner-all')
135
+ el.style.padding = '1em 1.4em'
136
+ el.style.marginBottom = '20px'
137
+ return el
138
+ }
139
+
140
+ afterInputReady (input) {
141
+ if (input.controls) return
142
+ input.controls = this.closest(input, '.form-control')
143
+ if (this.queuedInputErrorText) {
144
+ const text = this.queuedInputErrorText
145
+ delete this.queuedInputErrorText
146
+ this.addInputError(input, text)
147
+ }
148
+ }
149
+
150
+ addInputError (input, text) {
151
+ if (!input.controls) {
152
+ this.queuedInputErrorText = text
153
+ return
154
+ }
155
+ if (!input.errmsg) {
156
+ input.errmsg = document.createElement('div')
157
+ input.errmsg.classList.add('ui-state-error')
158
+ input.controls.appendChild(input.errmsg)
159
+ } else {
160
+ input.errmsg.style.display = ''
161
+ }
162
+
163
+ input.errmsg.textContent = text
164
+ }
165
+
166
+ removeInputError (input) {
167
+ if (!input.controls) {
168
+ delete this.queuedInputErrorText
169
+ }
170
+ if (!input.errmsg) return
171
+ input.errmsg.style.display = 'none'
172
+ }
173
+
174
+ markTabActive (row) {
175
+ row.tab.classList.remove('ui-widget-header')
176
+ row.tab.classList.add('ui-state-active')
177
+
178
+ if (typeof row.rowPane !== 'undefined') {
179
+ row.rowPane.style.display = ''
180
+ } else {
181
+ row.container.style.display = ''
182
+ }
183
+ }
184
+
185
+ markTabInactive (row) {
186
+ row.tab.classList.add('ui-widget-header')
187
+ row.tab.classList.remove('ui-state-active')
188
+
189
+ if (typeof row.rowPane !== 'undefined') {
190
+ row.rowPane.style.display = 'none'
191
+ } else {
192
+ row.container.style.display = 'none'
193
+ }
194
+ }
195
+ }
196
+
197
+ /* Custom stylesheet rules. format: "selector" : "CSS rules" */
198
+ jqueryuiTheme.rules = { 'div[data-schemaid="root"]:after': 'position:relative;color:red;margin:10px 0;font-weight:600;display:block;width:100%;text-align:center;content:"This is an old JSON-Editor 1.x Theme and might not display elements correctly when used with the 2.x version"' }
@@ -0,0 +1,426 @@
1
+ import { AbstractTheme } from '../theme.js'
2
+
3
+ export class materializeTheme extends AbstractTheme {
4
+ /**
5
+ * Applies grid size to specified element.
6
+ *
7
+ * @param {HTMLElement} el The DOM element to have specified size applied.
8
+ * @param {Integer} size The grid column size.
9
+ * @see http://materializecss.com/grid.html
10
+ */
11
+ setGridColumnSize (el, size) {
12
+ el.classList.add('col')
13
+ el.classList.add(`s${size}`)
14
+ }
15
+
16
+ /**
17
+ * Gets a wrapped button element for a header.
18
+ *
19
+ * @returns {HTMLElement} The wrapped button element.
20
+ */
21
+ getHeaderButtonHolder () {
22
+ return this.getButtonHolder()
23
+ }
24
+
25
+ /**
26
+ * Gets a wrapped button element.
27
+ *
28
+ * @returns {HTMLElement} The wrapped button element.
29
+ */
30
+ getButtonHolder () {
31
+ return document.createElement('span')
32
+ }
33
+
34
+ /**
35
+ * Gets a single button element.
36
+ *
37
+ * @param {string} text The button text.
38
+ * @param {HTMLElement} icon The icon object.
39
+ * @param {string} title The button title.
40
+ * @returns {HTMLElement} The button object.
41
+ * @see http://materializecss.com/buttons.html
42
+ */
43
+ getButton (text, icon, title) {
44
+ /* Prepare icon. */
45
+ if (icon) {
46
+ icon.classList.add('left')
47
+ icon.style.marginRight = '5px'
48
+ }
49
+
50
+ /* Create and return button. */
51
+ const el = super.getButton(text, icon, title)
52
+ el.classList.add('waves-effect', 'waves-light', 'btn')
53
+ el.style.fontSize = '0.75rem'
54
+ el.style.height = '24px'
55
+ el.style.lineHeight = '24px'
56
+ el.style.marginLeft = '5px'
57
+ el.style.padding = '0 0.5rem'
58
+ return el
59
+ }
60
+
61
+ afterInputReady (input) {
62
+ let label = input.previousSibling
63
+
64
+ if (input.type && input.type === 'range') {
65
+ label = input.parentElement.previousSibling
66
+ }
67
+
68
+ if (input.value || (input.dataset && input.dataset.containerFor && input.dataset.containerFor === 'radio')) {
69
+ if (label && label.localName === 'label') {
70
+ label.classList.add('active')
71
+ }
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Gets a form control object consisiting of several sub objects.
77
+ *
78
+ * @param {HTMLElement} label The label element.
79
+ * @param {HTMLElement} input The input element.
80
+ * @param {string} description The element description.
81
+ * @param {string} infoText The element information text.
82
+ * @returns {HTMLElement} The assembled DOM element.
83
+ * @see http://materializecss.com/forms.html
84
+ */
85
+ getFormControl (label, input, description, infoText) {
86
+ let ctrl
87
+ const { type } = input
88
+
89
+ /* Checkboxes get wrapped in p elements. */
90
+ if (type && (type === 'checkbox' || type === 'radio')) {
91
+ ctrl = document.createElement('p')
92
+ if (label) {
93
+ const span = document.createElement('span')
94
+ span.innerHTML = label.innerHTML
95
+ label.innerHTML = ''
96
+ label.setAttribute('for', input.id)
97
+ ctrl.appendChild(label)
98
+ label.appendChild(input)
99
+ label.appendChild(span)
100
+ } else {
101
+ ctrl.appendChild(input)
102
+ }
103
+
104
+ return ctrl
105
+ }
106
+
107
+ /* Anything else gets wrapped in divs. */
108
+ ctrl = super.getFormControl(label, input, description, infoText)
109
+
110
+ /* Color needs special attention. */
111
+ if (type && type === 'color') {
112
+ input.style.height = '3rem'
113
+ input.style.width = '100%'
114
+ input.style.margin = '5px 0 20px 0'
115
+ input.style.padding = '3px'
116
+
117
+ if (label) {
118
+ label.style.transform = 'translateY(-14px) scale(0.8)'
119
+ label.style['-webkit-transform'] = 'translateY(-14px) scale(0.8)'
120
+ label.style['-webkit-transform-origin'] = '0 0'
121
+ label.style['transform-origin'] = '0 0'
122
+ }
123
+ }
124
+
125
+ return ctrl
126
+ }
127
+
128
+ getDescription (text) {
129
+ const el = document.createElement('div')
130
+ el.classList.add('grey-text')
131
+ /* el.style.marginTop = '-15px' */
132
+ if (window.DOMPurify) el.innerHTML = window.DOMPurify.sanitize(text)
133
+ else el.textContent = this.cleanText(text)
134
+ return el
135
+ }
136
+
137
+ /**
138
+ * Gets a header element.
139
+ *
140
+ * @param {string|HTMLElement} text The header text or element.
141
+ * @returns {HTMLElement} The header element.
142
+ */
143
+ getHeader (text, pathDepth) {
144
+ const el = document.createElement('h5')
145
+
146
+ if (typeof text === 'string') {
147
+ el.textContent = text
148
+ } else {
149
+ el.appendChild(text)
150
+ }
151
+
152
+ return el
153
+ }
154
+
155
+ getChildEditorHolder () {
156
+ const el = document.createElement('div')
157
+ el.marginBottom = '10px'
158
+ return el
159
+ }
160
+
161
+ getIndentedPanel () {
162
+ const el = document.createElement('div')
163
+ el.classList.add('card-panel')
164
+ return el
165
+ }
166
+
167
+ getTable () {
168
+ const el = document.createElement('table')
169
+ el.classList.add('striped', 'bordered')
170
+ el.style.marginBottom = '10px'
171
+ return el
172
+ }
173
+
174
+ getTableRow () {
175
+ return document.createElement('tr')
176
+ }
177
+
178
+ getTableHead () {
179
+ return document.createElement('thead')
180
+ }
181
+
182
+ getTableBody () {
183
+ return document.createElement('tbody')
184
+ }
185
+
186
+ getTableHeaderCell (text) {
187
+ const el = document.createElement('th')
188
+ el.textContent = text
189
+ return el
190
+ }
191
+
192
+ getTableCell () {
193
+ const el = document.createElement('td')
194
+ return el
195
+ }
196
+
197
+ /**
198
+ * Gets the tab holder element.
199
+ *
200
+ * @returns {HTMLElement} The tab holder component.
201
+ * @see https://github.com/Dogfalo/materialize/issues/2542#issuecomment-233458602
202
+ */
203
+ getTabHolder () {
204
+ const html = [
205
+ '<div class="col s2">',
206
+ ' <ul class="tabs" style="height: auto; margin-top: 0.82rem; -ms-flex-direction: column; -webkit-flex-direction: column; flex-direction: column; display: -webkit-flex; display: flex;">',
207
+ ' </ul>',
208
+ '</div>',
209
+ '<div class="col s10">',
210
+ '<div>'
211
+ ].join('\n')
212
+
213
+ const el = document.createElement('div')
214
+ el.classList.add('row', 'card-panel')
215
+ el.innerHTML = html
216
+ return el
217
+ }
218
+
219
+ /**
220
+ * Add specified tab to specified holder element.
221
+ *
222
+ * @param {HTMLElement} holder The tab holder element.
223
+ * @param {HTMLElement} tab The tab to add.
224
+ */
225
+ addTab (holder, tab) {
226
+ holder.children[0].children[0].appendChild(tab)
227
+ }
228
+
229
+ /**
230
+ * Gets a single tab element.
231
+ *
232
+ * @param {HTMLElement} span The tab's content.
233
+ * @returns {HTMLElement} The tab element.
234
+ * @see https://github.com/Dogfalo/materialize/issues/2542#issuecomment-233458602
235
+ */
236
+ getTab (span) {
237
+ const el = document.createElement('li')
238
+ el.classList.add('tab')
239
+ el.style = el.style || {}
240
+ this.applyStyles(el,
241
+ {
242
+ width: '100%',
243
+ textAlign: 'left',
244
+ lineHeight: '24px',
245
+ height: '24px',
246
+ fontSize: '14px',
247
+ cursor: 'pointer'
248
+ }
249
+ )
250
+ el.appendChild(span)
251
+ return el
252
+ }
253
+
254
+ /**
255
+ * Marks specified tab as active.
256
+ *
257
+ * @returns {HTMLElement} The tab element.
258
+ * @see https://github.com/Dogfalo/materialize/issues/2542#issuecomment-233458602
259
+ */
260
+ markTabActive (tab) {
261
+ tab.style = tab.style || {}
262
+ this.applyStyles(tab,
263
+ {
264
+ width: '100%',
265
+ textAlign: 'left',
266
+ lineHeight: '24px',
267
+ height: '24px',
268
+ fontSize: '14px',
269
+ cursor: 'pointer',
270
+ color: 'rgba(238,110,115,1)',
271
+ transition: 'border-color .5s ease',
272
+ borderRight: '3px solid #424242'
273
+ }
274
+ )
275
+ }
276
+
277
+ /**
278
+ * Marks specified tab as inactive.
279
+ *
280
+ * @returns {HTMLElement} The tab element.
281
+ * @see https://github.com/Dogfalo/materialize/issues/2542#issuecomment-233458602
282
+ */
283
+ markTabInactive (tab) {
284
+ tab.style = tab.style || {}
285
+ this.applyStyles(tab,
286
+ {
287
+ width: '100%',
288
+ textAlign: 'left',
289
+ lineHeight: '24px',
290
+ height: '24px',
291
+ fontSize: '14px',
292
+ cursor: 'pointer',
293
+ color: 'rgba(238,110,115,0.7)'
294
+ }
295
+ )
296
+ }
297
+
298
+ /**
299
+ * Returns the element that holds the tab contents.
300
+ *
301
+ * @param {HTMLElement} tabHolder The full tab holder element.
302
+ * @returns {HTMLElement} The content element inside specified tab holder.
303
+ */
304
+ getTabContentHolder (tabHolder) {
305
+ return tabHolder.children[1]
306
+ }
307
+
308
+ /**
309
+ * Creates and returns a tab content element.
310
+ *
311
+ * @returns {HTMLElement} The new tab content element.
312
+ */
313
+ getTabContent () {
314
+ return document.createElement('div')
315
+ }
316
+
317
+ /**
318
+ * Adds an error message to the specified input element.
319
+ *
320
+ * @param {HTMLElement} input The input element that caused the error.
321
+ * @param {string} text The error message.
322
+ */
323
+ addInputError (input, text) {
324
+ /* Get the parent element. Should most likely be a <div class="input-field" ... />. */
325
+ const parent = input.parentNode
326
+
327
+ if (!parent) return
328
+
329
+ /* Remove any previous error. */
330
+ this.removeInputError(input)
331
+
332
+ /* Append an error message div. */
333
+ const el = document.createElement('div')
334
+ el.classList.add('error-text', 'red-text')
335
+ el.textContent = text
336
+ parent.appendChild(el)
337
+ }
338
+
339
+ /**
340
+ * Removes any error message from the specified input element.
341
+ *
342
+ * @param {HTMLElement} input The input element that previously caused the error.
343
+ */
344
+ removeInputError (input) {
345
+ /* Get the parent element. Should most likely be a <div class="input-field" ... />. */
346
+ const parent = input.parentElement
347
+
348
+ if (!parent) return
349
+
350
+ /* Remove all elements having class .error-text. */
351
+ const els = parent.getElementsByClassName('error-text')
352
+ for (let i = 0; i < els.length; i++) { parent.removeChild(els[i]) }
353
+ }
354
+
355
+ addTableRowError (row) {
356
+ }
357
+
358
+ removeTableRowError (row) {
359
+ }
360
+
361
+ /**
362
+ * Gets a select DOM element.
363
+ *
364
+ * @param {object} options The option values.
365
+ * @return {HTMLElement} The DOM element.
366
+ * @see http://materializecss.com/forms.html#select
367
+ */
368
+ getSelectInput (options, multiple) {
369
+ const select = super.getSelectInput(options)
370
+ select.classList.add('browser-default')
371
+ return select
372
+ }
373
+
374
+ /**
375
+ * Gets a textarea DOM element.
376
+ *
377
+ * @returns {HTMLElement} The DOM element.
378
+ * @see http://materializecss.com/forms.html#textarea
379
+ */
380
+ getTextareaInput () {
381
+ const el = document.createElement('textarea')
382
+ el.style.marginBottom = '5px'
383
+ el.style.fontSize = '1rem'
384
+ el.style.fontFamily = 'monospace'
385
+ return el
386
+ }
387
+
388
+ getCheckbox () {
389
+ const el = this.getFormInputField('checkbox')
390
+ el.id = this.createUuid()
391
+ return el
392
+ }
393
+
394
+ /**
395
+ * Gets the modal element for displaying Edit JSON and Properties dialogs.
396
+ *
397
+ * @returns {HTMLElement} The modal DOM element.
398
+ * @see http://materializecss.com/cards.html
399
+ */
400
+ getModal () {
401
+ const el = document.createElement('div')
402
+ el.classList.add('card-panel', 'z-depth-3')
403
+ el.style.padding = '5px'
404
+ el.style.position = 'absolute'
405
+ el.style.zIndex = '10'
406
+ el.style.display = 'none'
407
+ return el
408
+ }
409
+
410
+ /**
411
+ * Creates and returns a RFC4122 version 4 compliant unique id.
412
+ *
413
+ * @returns {string} A GUID.
414
+ * @see https://stackoverflow.com/a/2117523
415
+ */
416
+ createUuid () {
417
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
418
+ const r = Math.random() * 16 | 0; const v = c === 'x' ? r : (r & 0x3 | 0x8)
419
+ return v.toString(16)
420
+ }
421
+ )
422
+ }
423
+ }
424
+
425
+ /* Custom stylesheet rules. format: "selector" : "CSS rules" */
426
+ materializeTheme.rules = { 'div[data-schemaid="root"]:after': 'position:relative;color:red;margin:10px 0;font-weight:600;display:block;width:100%;text-align:center;content:"This is an old JSON-Editor 1.x Theme and might not display elements correctly when used with the 2.x version"' }