@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,112 @@
1
+ import { SelectEditor } from './select.js'
2
+ import { extend } from '../utilities.js'
3
+
4
+ export class SelectizeEditor extends SelectEditor {
5
+ setValue (value, initial) {
6
+ if (this.selectize_instance) {
7
+ if (initial) this.is_dirty = false
8
+ else if (this.jsoneditor.options.show_errors === 'change') this.is_dirty = true
9
+
10
+ const sanitized = this.updateValue(value) /* Sets this.value to sanitized value */
11
+
12
+ this.input.value = sanitized
13
+
14
+ this.selectize_instance.clear(true)
15
+ this.selectize_instance.setValue(sanitized)
16
+
17
+ this.onChange(true)
18
+ } else super.setValue(value, initial)
19
+ }
20
+
21
+ afterInputReady () {
22
+ if (window.jQuery && window.jQuery.fn && window.jQuery.fn.selectize && !this.selectize_instance) {
23
+ /* Get options, either global options from "this.defaults.options.selectize" or */
24
+ /* single property options from schema "options.selectize" */
25
+ const options = this.expandCallbacks('selectize', extend({}, this.defaults.options.selectize || {}, this.options.selectize || {}))
26
+
27
+ /* New items are allowed if option "create" is true and type is "string" */
28
+ this.newEnumAllowed = options.create = !!options.create && this.schema.type === 'string'
29
+
30
+ this.selectize_instance = (window.jQuery(this.input).selectize(options))[0].selectize
31
+
32
+ /* Remove change handler set in parent class (src/multiselect.js) */
33
+ this.control.removeEventListener('change', this.multiselectChangeHandler)
34
+
35
+ /* Create a new change handler */
36
+ this.multiselectChangeHandler = (value) => {
37
+ /* var value = this.selectize_instance.getValue(true); */
38
+ /* this.value = value; */
39
+ this.updateValue(value)
40
+ this.onChange(true)
41
+ }
42
+
43
+ /* Add new event handler. */
44
+ /* Note: Must use the "on()" method and not addEventListener() */
45
+ this.selectize_instance.on('change', this.multiselectChangeHandler)
46
+ }
47
+ super.afterInputReady()
48
+ }
49
+
50
+ updateValue (value) {
51
+ let sanitized = this.enum_values[0]
52
+ value = this.typecast(value || '')
53
+ if (!this.enum_values.includes(value)) {
54
+ if (this.newEnumAllowed) {
55
+ sanitized = this.addNewOption(value) ? value : sanitized
56
+ }
57
+ } else sanitized = value
58
+ this.value = sanitized
59
+ return sanitized
60
+ }
61
+
62
+ addNewOption (value) {
63
+ const sanitized = this.typecast(value); let res = false
64
+
65
+ if (!this.enum_values.includes(sanitized) && sanitized !== '') {
66
+ /* Add to list of valid enum values */
67
+ this.enum_options.push(`${sanitized}`)
68
+ this.enum_display.push(`${sanitized}`)
69
+ this.enum_values.push(sanitized)
70
+ /* Update Schema enum to prevent triggering error */
71
+ /* "Value must be one of the enumerated values" */
72
+ this.schema.enum.push(sanitized)
73
+
74
+ /* Add selectize item */
75
+ this.selectize_instance.addItem(sanitized)
76
+ this.selectize_instance.refreshOptions(false)
77
+
78
+ res = true
79
+ }
80
+ return res
81
+ }
82
+
83
+ onWatchedFieldChange () {
84
+ super.onWatchedFieldChange()
85
+ if (this.selectize_instance) {
86
+ this.selectize_instance.clear(true) /* Clear selection */
87
+ this.selectize_instance.clearOptions(true) /* Remove all options */
88
+ this.enum_options.forEach((value, i) => {
89
+ this.selectize_instance.addOption({ value, text: this.enum_display[i] })
90
+ })
91
+ this.selectize_instance.addItem(`${this.value}`, true) /* Set new selection */
92
+ }
93
+ }
94
+
95
+ enable () {
96
+ if (!this.always_disabled && this.selectize_instance) this.selectize_instance.unlock()
97
+ super.enable()
98
+ }
99
+
100
+ disable (alwaysDisabled) {
101
+ if (this.selectize_instance) this.selectize_instance.lock()
102
+ super.disable(alwaysDisabled)
103
+ }
104
+
105
+ destroy () {
106
+ if (this.selectize_instance) {
107
+ this.selectize_instance.destroy()
108
+ this.selectize_instance = null
109
+ }
110
+ super.destroy()
111
+ }
112
+ }
@@ -0,0 +1,113 @@
1
+ /* This editor is using the signature pad editor from https://github.com/szimek/signature_pad */
2
+ /* Credits for the pad itself go to https://github.com/szimek */
3
+
4
+ import { StringEditor } from './string.js'
5
+
6
+ export class SignatureEditor extends StringEditor {
7
+ build () {
8
+ if (!this.options.compact) this.header = this.label = this.theme.getFormInputLabel(this.getTitle(), this.isRequired())
9
+ if (this.schema.description) this.description = this.theme.getFormInputDescription(this.translateProperty(this.schema.description))
10
+ const formname = this.formname.replace(/\W/g, '')
11
+
12
+ if (typeof SignaturePad === 'function') {
13
+ /* Dynamically add the required CSS the first time this editor is used */
14
+ this.input = this.theme.getFormInputField('hidden')
15
+ this.container.appendChild(this.input)
16
+
17
+ /* Required to keep height */
18
+ const signatureContainer = document.createElement('div')
19
+ signatureContainer.classList.add('signature-container')
20
+
21
+ /* Create canvas for signature pad */
22
+ const canvas = document.createElement('canvas')
23
+ canvas.setAttribute('name', formname)
24
+ canvas.classList.add('signature')
25
+ signatureContainer.appendChild(canvas)
26
+
27
+ this.signaturePad = new window.SignaturePad(canvas, {
28
+ onEnd () {
29
+ /* check if the signature is not empty before setting a value */
30
+ if (!this.signaturePad.isEmpty()) {
31
+ this.input.value = this.signaturePad.toDataURL()
32
+ } else {
33
+ this.input.value = ''
34
+ }
35
+
36
+ this.is_dirty = true
37
+ this.refreshValue()
38
+ this.watch_listener()
39
+ this.jsoneditor.notifyWatchers(this.path)
40
+ if (this.parent) this.parent.onChildEditorChange(this)
41
+ else this.jsoneditor.onChange()
42
+ }
43
+ })
44
+
45
+ /* create button containers and add clear signature button */
46
+ const buttons = document.createElement('div')
47
+ const clearButton = document.createElement('button')
48
+ clearButton.classList.add('tiny', 'button')
49
+ clearButton.innerHTML = 'Clear signature'
50
+ buttons.appendChild(clearButton)
51
+ signatureContainer.appendChild(buttons)
52
+
53
+ if (this.options.compact) this.container.setAttribute('class', `${this.container.getAttribute('class')} compact`)
54
+
55
+ if (this.schema.readOnly || this.schema.readonly) {
56
+ this.disable(true)
57
+
58
+ Array.from(this.inputs).forEach(input => {
59
+ canvas.setAttribute('readOnly', 'readOnly')
60
+ input.disabled = true
61
+ })
62
+ }
63
+ /* add listener to the clear button. when clicked, trigger a canvas change after emptying the canvas */
64
+ clearButton.addEventListener('click', (e) => {
65
+ e.preventDefault()
66
+ e.stopPropagation()
67
+ this.signaturePad.clear()
68
+ /* trigger stroke end to let signaturePad update the dataURL */
69
+ this.signaturePad.strokeEnd()
70
+ })
71
+
72
+ this.control = this.theme.getFormControl(this.label, signatureContainer, this.description)
73
+ this.container.appendChild(this.control)
74
+ this.refreshValue()
75
+
76
+ /* signature canvas will stretch to signatureContainer width */
77
+ canvas.width = signatureContainer.offsetWidth
78
+ if (this.options && this.options.canvas_height) {
79
+ canvas.height = this.options.canvas_height
80
+ } else {
81
+ canvas.height = '300' /* Set to default height of 300px; */
82
+ }
83
+ } else {
84
+ const message = document.createElement('p')
85
+ message.innerHTML = 'Signature pad is not available, please include SignaturePad from https://github.com/szimek/signature_pad'
86
+ this.container.appendChild(message)
87
+ }
88
+ }
89
+
90
+ setValue (val) {
91
+ if (typeof SignaturePad === 'function') {
92
+ const sanitized = this.sanitize(val)
93
+ if (this.value === sanitized) {
94
+ return
95
+ }
96
+ this.value = sanitized
97
+ this.input.value = this.value
98
+ this.signaturePad.clear()
99
+ /* only set contents if value != '' */
100
+ if (val && val !== '') {
101
+ this.signaturePad.fromDataURL(val)
102
+ }
103
+ this.watch_listener()
104
+ this.jsoneditor.notifyWatchers(this.path)
105
+ return false
106
+ }
107
+ }
108
+
109
+ destroy () {
110
+ this.signaturePad.off()
111
+ delete this.signaturePad
112
+ }
113
+ }
@@ -0,0 +1,100 @@
1
+ import { StringEditor } from './string.js'
2
+ import { extend } from '../utilities.js'
3
+
4
+ export class SimplemdeEditor extends StringEditor {
5
+ setValue (value, initial, fromTemplate) {
6
+ const res = super.setValue(value, initial, fromTemplate)
7
+ if (res !== undefined && res.changed && this.simplemde_instance) this.simplemde_instance.value(res.value)
8
+ }
9
+
10
+ build () {
11
+ this.options.format = 'textarea' /* Force format into "textarea" */
12
+ super.build()
13
+ this.input_type = this.schema.format /* Restore original format */
14
+ this.input.setAttribute('data-schemaformat', this.input_type)
15
+ }
16
+
17
+ afterInputReady () {
18
+ let options
19
+
20
+ if (window.SimpleMDE) {
21
+ /* Get options, either global options from "this.defaults.options.simplemde" or */
22
+ /* single property options from schema "options.simplemde" */
23
+ options = this.expandCallbacks('simplemde', extend({}, {
24
+ height: 300
25
+ }, this.defaults.options.simplemde || {}, this.options.simplemde || {}, {
26
+ element: this.input
27
+ }))
28
+
29
+ this.simplemde_instance = new window.SimpleMDE(options)
30
+
31
+ if (this.schema.readOnly || this.schema.readonly || this.schema.template) {
32
+ this.simplemde_instance.codemirror.options.readOnly = true
33
+ }
34
+
35
+ /* Listen for changes */
36
+ this.simplemde_instance.codemirror.on('change', () => {
37
+ this.value = this.simplemde_instance.value()
38
+ this.is_dirty = true
39
+ this.onChange(true)
40
+ })
41
+
42
+ /* This will prevent SimpleMDE content from being hidden until focus in Chrome */
43
+ /* if SimpleMDE is not visible (Like when placed inside Tabs) */
44
+ if (options.autorefresh) {
45
+ this.startListening(this.simplemde_instance.codemirror, this.simplemde_instance.codemirror.state.autoRefresh = { delay: 250 })
46
+ }
47
+
48
+ this.theme.afterInputReady(this.input)
49
+ } else super.afterInputReady() /* Library not loaded, so just treat this as a string */
50
+ }
51
+
52
+ getNumColumns () {
53
+ return 6
54
+ }
55
+
56
+ enable () {
57
+ if (!this.always_disabled && this.simplemde_instance) this.simplemde_instance.codemirror.options.readOnly = false
58
+ super.enable()
59
+ }
60
+
61
+ disable (alwaysDisabled) {
62
+ if (this.simplemde_instance) this.simplemde_instance.codemirror.options.readOnly = true
63
+ super.disable(alwaysDisabled)
64
+ }
65
+
66
+ destroy () {
67
+ if (this.simplemde_instance) {
68
+ this.simplemde_instance.toTextArea()
69
+ this.simplemde_instance = null
70
+ }
71
+ super.destroy()
72
+ }
73
+
74
+ /* Ported from https://codemirror.net/addon/display/autorefresh.js */
75
+ startListening (cm, state) {
76
+ function check () {
77
+ if (cm.display.wrapper.offsetHeight) {
78
+ this.stopListening(cm, state)
79
+ if (cm.display.lastWrapHeight !== cm.display.wrapper.clientHeight) {
80
+ cm.refresh()
81
+ }
82
+ } else {
83
+ state.timeout = window.setTimeout(check, state.delay)
84
+ }
85
+ }
86
+ state.timeout = window.setTimeout(check, state.delay)
87
+ state.hurry = () => {
88
+ window.clearTimeout(state.timeout)
89
+ state.timeout = window.setTimeout(check, 50)
90
+ }
91
+ cm.on(window, 'mouseup', state.hurry)
92
+ cm.on(window, 'keyup', state.hurry)
93
+ }
94
+
95
+ stopListening (cm, state) {
96
+ window.clearTimeout(state.timeout)
97
+ cm.off(window, 'mouseup', state.hurry)
98
+ cm.off(window, 'keyup', state.hurry)
99
+ }
100
+ }
@@ -0,0 +1,52 @@
1
+ .starrating {
2
+ direction: rtl;
3
+ display: inline-block;
4
+ white-space:nowrap;
5
+ }
6
+
7
+ .starrating > input {
8
+ display: none;
9
+ }
10
+
11
+ /* Remove radio buttons */
12
+
13
+ .starrating > label:before {
14
+ content: '\2606'; /* Empty Star */
15
+ margin: 1px;
16
+ font-size: 18px;
17
+ font-style:normal;
18
+ font-weight:400;
19
+ line-height:1;
20
+ font-family: 'Arial';
21
+ display: inline-block;
22
+ }
23
+
24
+ .starrating > label {
25
+ color: #888; /* Start color when not clicked */
26
+ cursor: pointer;
27
+ margin: 0;
28
+ margin: 8px 0 2px 0;
29
+ }
30
+
31
+ .starrating > label.starrating-display-enabled {
32
+ margin: 1px 0 0 0;
33
+ }
34
+
35
+ .starrating > input:checked ~ label,
36
+ .starrating:not(.readonly) > input:hover ~ label {
37
+ color: #ffca08; /* Set yellow color when star checked/hover */
38
+ }
39
+
40
+ .starrating > input:checked ~ label:before,
41
+ .starrating:not(.readonly) > input:hover ~ label:before {
42
+ content: '\2605'; /* Filled Star when star checked/hover */
43
+ text-shadow: 0 0 1px rgba(0,20,20,1);
44
+ }
45
+
46
+ .starrating .starrating-display {
47
+ position: relative;
48
+ direction: rtl;
49
+ text-align: center;
50
+ font-size: 10px;
51
+ line-height: 0px;
52
+ }
@@ -0,0 +1,3 @@
1
+ /* eslint-disable */
2
+ export default {".starrating":"direction:rtl;display:inline-block;white-space:nowrap",".starrating > input":"display:none",".starrating > label:before":"content:'%5C2606';margin:1px;font-size:18px;font-style:normal;font-weight:400;line-height:1;font-family:'Arial';display:inline-block",".starrating > label":"color:%23888;cursor:pointer;margin:8px%200%202px%200",".starrating > label.starrating-display-enabled":"margin:1px%200%200%200",".starrating > input:checked ~ label":"color:%23ffca08",".starrating:not(.readonly) > input:hover ~ label":"color:%23ffca08",".starrating > input:checked ~ label:before":"content:'%5C2605';text-shadow:0%200%201px%20rgba(0%2C20%2C20%2C1)",".starrating:not(.readonly) > input:hover ~ label:before":"content:'%5C2605';text-shadow:0%200%201px%20rgba(0%2C20%2C20%2C1)",".starrating .starrating-display":"position:relative;direction:rtl;text-align:center;font-size:10px;line-height:0px"}
3
+ /* eslint-enable */
@@ -0,0 +1,135 @@
1
+ import { StringEditor } from './string.js'
2
+ import rules from './starrating.css.js'
3
+
4
+ export class StarratingEditor extends StringEditor {
5
+ build () {
6
+ if (!this.options.compact) this.header = this.label = this.theme.getFormInputLabel(this.getTitle(), this.isRequired())
7
+ if (this.schema.description) this.description = this.theme.getFormInputDescription(this.translateProperty(this.schema.description))
8
+ if (this.options.infoText) this.infoButton = this.theme.getInfoButton(this.translateProperty(this.options.infoText))
9
+ if (this.options.compact) this.container.classList.add('compact')
10
+
11
+ this.ratingContainer = document.createElement('div')
12
+ this.ratingContainer.classList.add('starrating')
13
+
14
+ /* Emulate the old "rating" editor parameters */
15
+ if (this.schema.enum === undefined) {
16
+ let max = this.schema.maximum ? this.schema.maximum : 5
17
+ if (this.schema.exclusiveMaximum) max--
18
+ this.enum_values = []
19
+ for (let k = 0; k < max; k++) this.enum_values.push(k + 1)
20
+ } else this.enum_values = this.schema.enum
21
+
22
+ this.radioGroup = []
23
+
24
+ const radioInputEventhandler = e => {
25
+ e.preventDefault()
26
+ e.stopPropagation()
27
+ this.setValue(e.currentTarget.value)
28
+ this.onChange(true)
29
+ }
30
+
31
+ for (let i = this.enum_values.length - 1; i > -1; i--) {
32
+ const id = this.formname + (i + 1)
33
+
34
+ /* form radio elements */
35
+ const radioInput = this.theme.getFormInputField('radio')
36
+ radioInput.name = `${this.formname}[starrating]`
37
+ radioInput.value = this.enum_values[i]
38
+ radioInput.id = id
39
+ radioInput.addEventListener('change', radioInputEventhandler, false)
40
+ this.radioGroup.push(radioInput)
41
+
42
+ /* form-label for radio elements */
43
+ const radioLabel = document.createElement('label')
44
+ radioLabel.htmlFor = id
45
+ radioLabel.title = this.enum_values[i]
46
+ if (this.options.displayValue) {
47
+ radioLabel.classList.add('starrating-display-enabled')
48
+ }
49
+
50
+ this.ratingContainer.appendChild(radioInput)
51
+ this.ratingContainer.appendChild(radioLabel)
52
+ }
53
+
54
+ if (this.options.displayValue) {
55
+ this.displayRating = document.createElement('div')
56
+ this.displayRating.classList.add('starrating-display')
57
+ this.displayRating.innerText = this.enum_values[0]
58
+ this.ratingContainer.appendChild(this.displayRating)
59
+ }
60
+
61
+ if (this.schema.readOnly || this.schema.readonly) {
62
+ this.disable(true)
63
+ for (let j = 0; j < this.radioGroup.length; j++) {
64
+ this.radioGroup[j].disabled = true
65
+ }
66
+ this.ratingContainer.classList.add('readonly')
67
+ }
68
+
69
+ const ratingsContainerWrapper = this.theme.getContainer()
70
+ ratingsContainerWrapper.appendChild(this.ratingContainer)
71
+
72
+ this.input = ratingsContainerWrapper
73
+
74
+ this.control = this.theme.getFormControl(this.label, ratingsContainerWrapper, this.description, this.infoButton)
75
+ this.container.appendChild(this.control)
76
+
77
+ this.refreshValue()
78
+ }
79
+
80
+ enable () {
81
+ if (!this.always_disabled) {
82
+ for (let i = 0; i < this.radioGroup.length; i++) {
83
+ this.radioGroup[i].disabled = false
84
+ }
85
+ this.ratingContainer.classList.remove('readonly')
86
+ this.disabled = false
87
+ }
88
+ }
89
+
90
+ disable (alwaysDisabled) {
91
+ if (alwaysDisabled) this.always_disabled = true
92
+ for (let i = 0; i < this.radioGroup.length; i++) {
93
+ this.radioGroup[i].disabled = true
94
+ }
95
+ this.ratingContainer.classList.add('readonly')
96
+ this.disabled = true
97
+ }
98
+
99
+ destroy () {
100
+ if (this.ratingContainer.parentNode && this.ratingContainer.parentNode.parentNode) this.ratingContainer.parentNode.parentNode.removeChild(this.ratingContainer.parentNode)
101
+ if (this.label && this.label.parentNode) this.label.parentNode.removeChild(this.label)
102
+ if (this.description && this.description.parentNode) this.description.parentNode.removeChild(this.description)
103
+ super.destroy()
104
+ }
105
+
106
+ getNumColumns () {
107
+ return 2
108
+ }
109
+
110
+ getValue () {
111
+ if (!this.dependenciesFulfilled) {
112
+ return undefined
113
+ }
114
+ if (this.schema.type === 'integer') {
115
+ return this.value === '' ? undefined : this.value * 1
116
+ }
117
+ return this.value
118
+ }
119
+
120
+ setValue (value) {
121
+ for (let i = 0; i < this.radioGroup.length; i++) {
122
+ if (this.radioGroup[i].value === `${value}`) {
123
+ this.radioGroup[i].checked = true
124
+ this.value = value
125
+
126
+ if (this.options.displayValue) this.displayRating.innerHTML = this.value
127
+
128
+ this.onChange(true)
129
+ break
130
+ }
131
+ }
132
+ }
133
+ }
134
+
135
+ StarratingEditor.rules = rules
@@ -0,0 +1,27 @@
1
+ import { IntegerEditor } from './integer.js'
2
+
3
+ export class StepperEditor extends IntegerEditor {
4
+ build () {
5
+ super.build()
6
+ this.input.setAttribute('type', 'number')
7
+ if (!this.input.getAttribute('step')) {
8
+ this.input.setAttribute('step', '1')
9
+ }
10
+ const stepperButtons = this.theme.getStepperButtons(this.input)
11
+ this.control.appendChild(stepperButtons)
12
+ this.stepperDown = this.control.querySelector('.stepper-down')
13
+ this.stepperUp = this.control.querySelector('.stepper-up')
14
+ }
15
+
16
+ enable () {
17
+ super.enable()
18
+ this.stepperDown.removeAttribute('disabled')
19
+ this.stepperUp.removeAttribute('disabled')
20
+ }
21
+
22
+ disable () {
23
+ super.disable()
24
+ this.stepperDown.setAttribute('disabled', true)
25
+ this.stepperUp.setAttribute('disabled', true)
26
+ }
27
+ }