renusify 2.5.2 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/components/app/index.vue +74 -22
  2. package/components/app/toast/index.vue +76 -71
  3. package/components/app/toast/toast.vue +62 -44
  4. package/components/avatar/index.vue +208 -84
  5. package/components/button/buttonConfirm.vue +53 -26
  6. package/components/button/buttonGroup.js +0 -2
  7. package/components/button/buttonGroup.vue +310 -62
  8. package/components/button/index.vue +584 -100
  9. package/components/calendar/index.js +0 -2
  10. package/components/calendar/index.vue +326 -262
  11. package/components/calendar/month.vue +64 -55
  12. package/components/calendar/year.vue +30 -25
  13. package/components/card/index.vue +139 -59
  14. package/components/codeEditor/highlightCss.vue +38 -39
  15. package/components/codeEditor/highlightHtml.vue +64 -64
  16. package/components/codeEditor/highlightJs.vue +37 -38
  17. package/components/codeEditor/index.vue +129 -79
  18. package/components/codeEditor/run.vue +225 -39
  19. package/components/codeEditor/useCodeFormatter.js +150 -0
  20. package/components/confirm/index.vue +139 -80
  21. package/components/container/col.vue +5 -4
  22. package/components/container/divider.vue +28 -19
  23. package/components/container/index.vue +34 -15
  24. package/components/container/row.vue +26 -9
  25. package/components/container/spacer.vue +2 -4
  26. package/components/container/style.scss +3 -0
  27. package/components/content/index.vue +49 -32
  28. package/components/cropper/index.vue +401 -244
  29. package/components/float/index.vue +542 -415
  30. package/components/form/addressInput/index.vue +184 -109
  31. package/components/form/camInput/index.vue +370 -244
  32. package/components/form/checkInput/index.vue +138 -71
  33. package/components/form/checkboxInput/index.vue +87 -47
  34. package/components/form/colorInput/Alpha.vue +81 -83
  35. package/components/form/colorInput/Hue.vue +91 -68
  36. package/components/form/colorInput/Preview.vue +43 -47
  37. package/components/form/colorInput/Saturation.vue +101 -86
  38. package/components/form/colorInput/index.vue +71 -39
  39. package/components/form/colorInput/picker.vue +111 -106
  40. package/components/form/colorInput/useColor.js +153 -0
  41. package/components/form/dateInput/index.vue +691 -356
  42. package/components/form/dateInput/month.vue +63 -54
  43. package/components/form/dateInput/year.vue +35 -25
  44. package/components/form/fileInput/index.js +0 -1
  45. package/components/form/fileInput/index.vue +263 -106
  46. package/components/form/fileInput/single.vue +323 -164
  47. package/components/form/groupInput/index.vue +199 -101
  48. package/components/form/index.vue +189 -83
  49. package/components/form/input/index.vue +416 -377
  50. package/components/form/jsonInput/JsonView.vue +54 -56
  51. package/components/form/jsonInput/index.vue +247 -165
  52. package/components/form/maskInput/index.vue +252 -132
  53. package/components/form/numberInput/index.js +0 -1
  54. package/components/form/numberInput/index.vue +226 -117
  55. package/components/form/passwordInput/index.js +2 -1
  56. package/components/form/passwordInput/index.vue +269 -102
  57. package/components/form/radioInput/index.vue +143 -72
  58. package/components/form/rangeInput/index.vue +280 -167
  59. package/components/form/ratingInput/index.vue +57 -57
  60. package/components/form/selectInput/index.js +1 -3
  61. package/components/form/selectInput/index.vue +584 -296
  62. package/components/form/switchInput/index.vue +73 -59
  63. package/components/form/telInput/index.js +0 -1
  64. package/components/form/telInput/index.vue +238 -135
  65. package/components/form/textArea/index.vue +72 -35
  66. package/components/form/textEditor/index.vue +739 -0
  67. package/components/form/{text-editor → textEditor}/style.scss +8 -16
  68. package/components/form/textInput/index.vue +54 -32
  69. package/components/form/timeInput/index.vue +82 -55
  70. package/components/form/timeInput/range.vue +115 -94
  71. package/components/form/timeInput/timepicker.vue +382 -449
  72. package/components/form/uniqueInput/index.vue +105 -48
  73. package/components/form/unitInput/index.vue +139 -84
  74. package/components/formCreator/index.js +0 -1
  75. package/components/formCreator/index.vue +314 -148
  76. package/components/highlight/index.vue +41 -25
  77. package/components/highlight/style.scss +2 -2
  78. package/components/highlight/{mixin.js → useHighlight.js} +181 -160
  79. package/components/icon/index.vue +79 -33
  80. package/components/img/index.vue +249 -147
  81. package/components/img/preview.vue +180 -198
  82. package/components/img/svgImg.vue +42 -39
  83. package/components/index.js +5 -20
  84. package/components/infinite/index.js +1 -2
  85. package/components/infinite/index.vue +248 -66
  86. package/components/map/index.vue +428 -261
  87. package/components/map/route.vue +794 -487
  88. package/components/map/select.vue +118 -58
  89. package/components/menu/index.vue +201 -91
  90. package/components/meta/meta.js +26 -3
  91. package/components/modal/index.vue +382 -156
  92. package/components/notify/index.vue +204 -86
  93. package/components/notify/notification.vue +38 -55
  94. package/components/progress/circle.vue +189 -70
  95. package/components/progress/line.vue +266 -46
  96. package/components/searchBox/index.js +1 -3
  97. package/components/searchBox/index.vue +194 -101
  98. package/components/skeleton/index.vue +45 -20
  99. package/components/slider/index.vue +318 -156
  100. package/components/swiper/index.vue +254 -106
  101. package/components/table/crud/footer.vue +77 -53
  102. package/components/table/crud/header.vue +71 -72
  103. package/components/table/crud/index.vue +629 -399
  104. package/components/table/index.vue +721 -278
  105. package/components/timeAgo/index.vue +145 -96
  106. package/components/tour/index.vue +338 -235
  107. package/components/tree/index.vue +235 -89
  108. package/components/tree/tree-element.vue +106 -106
  109. package/directive/animate/index.js +77 -0
  110. package/directive/clickOutSide/index.js +98 -0
  111. package/directive/drag/index.js +153 -0
  112. package/directive/index.js +11 -13
  113. package/directive/intersect/index.js +263 -0
  114. package/directive/mask/index.js +67 -0
  115. package/directive/parallax/index.js +78 -0
  116. package/directive/ripple/index.js +14 -0
  117. package/directive/scroll/index.js +244 -0
  118. package/directive/sortable/index.js +274 -0
  119. package/directive/title/index.js +75 -0
  120. package/directive/touch/index.js +268 -0
  121. package/index.js +10 -8
  122. package/package.json +5 -2
  123. package/plugins/validation/Validate.js +88 -79
  124. package/scripts/generate-docs.mjs +226 -0
  125. package/scripts/menu.mjs +240 -0
  126. package/scripts/parser.mjs +1086 -0
  127. package/style/_index.scss +7 -0
  128. package/style/app.scss +13 -65
  129. package/style/colors.scss +5 -22
  130. package/style/functions/index.scss +8 -0
  131. package/style/mixins/index.scss +17 -5
  132. package/style/variables/base.scss +154 -175
  133. package/style/variables/color.scss +0 -12
  134. package/style/variables/utilities.scss +0 -180
  135. package/tools/helper.js +0 -8
  136. package/tools/icons.js +6 -1
  137. package/tools/root.js +71 -0
  138. package/components/app/style.scss +0 -41
  139. package/components/app/toast/style.scss +0 -20
  140. package/components/avatar/style.scss +0 -32
  141. package/components/bar/bottomNav.js +0 -1
  142. package/components/bar/bottomNav.vue +0 -28
  143. package/components/bar/bottomNavigationCircle.js +0 -2
  144. package/components/bar/bottomNavigationCircle.vue +0 -99
  145. package/components/bar/scss/bottomNav.scss +0 -67
  146. package/components/bar/scss/toolbar.scss +0 -174
  147. package/components/bar/toolbar/index.js +0 -8
  148. package/components/bar/toolbar/index.vue +0 -35
  149. package/components/bar/toolbar/laptop.vue +0 -33
  150. package/components/bar/toolbar/menuChilds.vue +0 -41
  151. package/components/bar/toolbar/menuLaptop.vue +0 -41
  152. package/components/bar/toolbar/menuMob.vue +0 -39
  153. package/components/bar/toolbar/mixin.js +0 -43
  154. package/components/bar/toolbar/mobile.vue +0 -34
  155. package/components/breadcrumb/bredcrumbItem.vue +0 -39
  156. package/components/breadcrumb/index.js +0 -3
  157. package/components/breadcrumb/index.vue +0 -71
  158. package/components/breadcrumb/style.scss +0 -51
  159. package/components/button/style.scss +0 -411
  160. package/components/card/style.scss +0 -86
  161. package/components/chart/chart.js +0 -1
  162. package/components/chart/chart.vue +0 -69
  163. package/components/chart/worldMap.js +0 -2
  164. package/components/chart/worldMap.vue +0 -1112
  165. package/components/chat/MessageList.vue +0 -163
  166. package/components/chat/chatInput.vue +0 -150
  167. package/components/chat/chatMsg.vue +0 -276
  168. package/components/chat/index.js +0 -11
  169. package/components/chat/index.vue +0 -113
  170. package/components/chip/index.js +0 -3
  171. package/components/chip/index.vue +0 -77
  172. package/components/chip/style.scss +0 -199
  173. package/components/codeEditor/mixin.js +0 -145
  174. package/components/countdown/index.js +0 -1
  175. package/components/countdown/index.vue +0 -105
  176. package/components/form/colorInput/mixin.js +0 -132
  177. package/components/form/fileInput/file.js +0 -148
  178. package/components/form/telInput/assets/flags.png +0 -0
  179. package/components/form/telInput/assets/flags@2x.png +0 -0
  180. package/components/form/text-editor/index.vue +0 -705
  181. package/components/icon/style.scss +0 -17
  182. package/components/infinite/div.js +0 -6
  183. package/components/infinite/div.vue +0 -193
  184. package/components/infinite/page.js +0 -3
  185. package/components/infinite/page.vue +0 -105
  186. package/components/list/index.js +0 -3
  187. package/components/list/index.vue +0 -122
  188. package/components/list/style.scss +0 -66
  189. package/components/message/index.js +0 -4
  190. package/components/message/index.vue +0 -40
  191. package/components/modal/style.scss +0 -146
  192. package/components/nestable/NestableItem.vue +0 -307
  193. package/components/nestable/editable.js +0 -44
  194. package/components/nestable/index.js +0 -1
  195. package/components/nestable/index.vue +0 -226
  196. package/components/nestable/methods.js +0 -416
  197. package/components/progress/style.scss +0 -229
  198. package/components/table/style.scss +0 -338
  199. package/components/tabs/index.js +0 -3
  200. package/components/tabs/index.vue +0 -151
  201. package/components/timeline/index.js +0 -6
  202. package/components/timeline/index.vue +0 -76
  203. package/directive/resize/index.js +0 -30
  204. package/directive/skeleton/index.js +0 -27
  205. package/directive/skeleton/style.scss +0 -37
  206. package/plugins/request/Request.js +0 -68
  207. package/style/animation.scss +0 -94
  208. package/style/style.scss +0 -8
  209. package/tools/rootable.js +0 -75
  210. /package/components/form/{text-editor → textEditor}/index.js +0 -0
  211. /package/components/form/{text-editor → textEditor}/preview.js +0 -0
  212. /package/components/form/{text-editor → textEditor}/preview.vue +0 -0
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div :class="`${$r.prefix}json-view d-flex v-end flex-wrap`"
2
+ <div :class="`${$r.prefix}json-view d-flex v-start flex-wrap`"
3
3
  v-for="(value,key) in modelValue"
4
4
  :key="key">
5
5
  <div class="d-flex v-center me-1">
@@ -11,7 +11,7 @@
11
11
  <div v-if="typeof value==='object'" class="flex-grow-1 w-full ps-10">
12
12
  <r-json-input :tile="tile"
13
13
  :model-value="value"
14
- @update:model-value="emit(key,$event)"
14
+ @update:model-value="emitValue(key,$event)"
15
15
  :disableAdd="disableAdd||template!==undefined"
16
16
  :disableDel="disableDel||template!==undefined"
17
17
  :translate="translate"
@@ -22,76 +22,74 @@
22
22
  <r-text-input v-if="typeof value==='string'"
23
23
  :tile="tile"
24
24
  :label="!is_array?t(key):''"
25
- :model-value="value" @update:model-value="emit(key,$event)"></r-text-input>
25
+ :model-value="value" @update:model-value="emitValue(key,$event)"></r-text-input>
26
26
  <r-number-input v-else-if="typeof value==='number'"
27
27
  :tile="tile"
28
28
  :label="!is_array?t(key):''"
29
- :model-value="value" @update:model-value="emit(key,$event)"></r-number-input>
29
+ :model-value="value" @update:model-value="emitValue(key,$event)"></r-number-input>
30
30
  <r-switch-input v-else-if="typeof value==='boolean'"
31
31
  :tile="tile"
32
32
  :label="!is_array?t(key):''"
33
- :model-value="value" @update:model-value="emit(key,$event)"></r-switch-input>
33
+ :model-value="value" @update:model-value="emitValue(key,$event)"></r-switch-input>
34
34
 
35
35
  </div>
36
36
 
37
37
  </div>
38
38
  </template>
39
- <script>
40
- export default {
41
- name: 'jsonView',
42
- props: {
43
- modelValue: Object,
44
- template: Object,
45
- disableAdd: Boolean,
46
- disableDel: Boolean,
47
- tile: Boolean,
48
- translate: Boolean
49
- },
50
- emits: ['update:modelValue'],
51
- data() {
52
- return {
53
- time_id: null
54
- }
55
- },
56
- computed: {
57
- is_array() {
58
- return Array.isArray(this.modelValue)
59
- }
39
+ <script setup>
40
+ import {computed, inject} from 'vue'
41
+
42
+ const props = defineProps({
43
+ modelValue: {
44
+ type: Object,
45
+ default: () => ({})
60
46
  },
61
- methods: {
62
- t(key) {
63
- if (this.translate) {
64
- return this.$t(key)
65
- }
66
- return key
67
- },
68
- del(key) {
69
- let o = this.modelValue
70
- if (this.is_array) {
71
- o.splice(key, 1)
72
- } else {
73
- delete o[key]
74
- }
75
- this.$emit('update:modelValue', o)
76
- },
77
- emit(k, v) {
78
- let d = this.modelValue
79
- d[k] = v
80
- this.$emit('update:modelValue', d)
81
- }
47
+ template: Object,
48
+ disableAdd: Boolean,
49
+ disableDel: Boolean,
50
+ tile: Boolean,
51
+ translate: Boolean
52
+ })
53
+
54
+ const emit = defineEmits(['update:modelValue'])
55
+
56
+ const {$t} = inject('renusify')
57
+
58
+
59
+ const is_array = computed(() => Array.isArray(props.modelValue))
60
+
61
+ const t = (key) => {
62
+ if (props.translate && $t) {
63
+ return $t(key)
64
+ }
65
+ return key
66
+ }
67
+
68
+ const del = (key) => {
69
+ const newValue = JSON.parse(JSON.stringify(props.modelValue))
70
+
71
+ if (is_array.value) {
72
+ newValue.splice(key, 1)
73
+ } else {
74
+ delete newValue[key]
82
75
  }
76
+
77
+ emit('update:modelValue', newValue)
78
+ }
79
+
80
+ const emitValue = (key, value) => {
81
+ const newValue = JSON.parse(JSON.stringify(props.modelValue))
82
+
83
+ newValue[key] = value
84
+
85
+ emit('update:modelValue', newValue)
83
86
  }
87
+
84
88
  </script>
85
89
  <style lang="scss">
86
- @use "../../../style/variables/base";
87
- @use "../../../style/mixins";
90
+ @use "../../../style" as *;
88
91
 
89
- .#{base.$prefix}json-view {
90
- @include mixins.rtl() {
91
- border-right: 1px solid var(--color-sheet-low);
92
- }
93
- @include mixins.ltr() {
94
- border-left: 1px solid var(--color-sheet-low);
95
- }
92
+ .#{$prefix}json-view {
93
+ background-color: var(--color-sheet-container);
96
94
  }
97
95
  </style>
@@ -1,38 +1,37 @@
1
1
  <template>
2
- <div :class="[`${$r.prefix}json-input`,{'input-tile':c_tile}]">
2
+ <r-input :class="[`${$r.prefix}json-input`]"
3
+ :model-value="modelValue"
4
+ label-active>
3
5
  <div class="d-flex v-center">
4
- <r-btn v-if="!disableEditKey" class="me-1 mb-1" icon @click.prevent="modeForm=!modeForm">{}</r-btn>
5
- <div v-if="label">{{ label }}</div>
6
+ <r-btn v-if="!disableEditKey" class="my-1" icon size="sm" @click.prevent="modeForm=!modeForm">{ }</r-btn>
6
7
  </div>
7
8
  <div v-if="modeForm">
8
9
  <json-view :model-value="modelValue"
9
- @update:model-value="emit"
10
+ @update:model-value="emitValue"
10
11
  :template="template"
11
12
  :disableAdd="disableAdd"
12
13
  :disableDel="disableDel"
13
14
  :translate="translate"
14
- :tile="tile"
15
15
  ></json-view>
16
16
  <r-btn
17
17
  v-if="!show &&!disableAdd"
18
18
  class="my-3 ms-1"
19
19
  icon
20
- size="small"
20
+ size="sm"
21
21
  @click.prevent="open">
22
22
  <r-icon v-html="$r.icons.plus"></r-icon>
23
23
  </r-btn>
24
24
  <div v-else-if="show" class="d-flex v-baseline flex-wrap">
25
+ <!-- Custom slot for add form with add function and info object -->
25
26
  <slot :add="add" :info="info">
26
27
  <r-text-input
27
28
  v-if="!is_array"
28
29
  v-model="info.key"
29
- :label="keyLabel||$t('key','renusify')"
30
- :tile="tile"
30
+ :placeholder="keyLabel||$t('key','renusify')"
31
31
  class="w-30 pe-1"></r-text-input>
32
32
  <div v-if="!valueType" class="w-20">
33
33
  <r-select-input v-model="info.type"
34
34
  :items="['text','number','boolean','json','array']"
35
- :tile="tile"
36
35
  :translate="translate"
37
36
  class="me-1"
38
37
  disableSearch
@@ -42,15 +41,15 @@
42
41
  </div>
43
42
  <r-text-input v-if="info.type==='text'"
44
43
  v-model="info.value"
45
- :label="valueLabel||$t('value','renusify')"
46
- :tile="tile"></r-text-input>
44
+ :placeholder="valueLabel||$t('value','renusify')"
45
+ ></r-text-input>
47
46
  <r-number-input v-else-if="info.type==='number'"
48
47
  v-model="info.value"
49
- :label="valueLabel||$t('value','renusify')" :tile="tile"></r-number-input>
48
+ :placeholder="valueLabel||$t('value','renusify')"></r-number-input>
50
49
  <r-switch-input v-else-if="info.type==='boolean'"
51
50
  v-model="info.value"
52
- :label="valueLabel||$t('value','renusify')" :tile="tile"></r-switch-input>
53
- <r-btn :rounded="!c_tile" class="ms-1 color-success" @click.prevent="add">{{ $t('add', 'renusify') }}</r-btn>
51
+ :label="valueLabel||$t('value','renusify')"></r-switch-input>
52
+ <r-btn class="ms-1 color-success" size="sm" @click.prevent="add">{{ $t('add', 'renusify') }}</r-btn>
54
53
  </slot>
55
54
  </div>
56
55
  </div>
@@ -63,178 +62,261 @@
63
62
  class="ltr w-full"
64
63
  spellcheck="false"
65
64
  :rows="modelValue?Object.keys(modelValue).length+5:5"
66
- @keydown="setTab"
67
65
  ></textarea>
68
66
  <div class="text-preview" v-html="code"></div>
69
67
  </div>
70
- </div>
68
+ </r-input>
71
69
  </template>
72
- <script>
73
- import {defineAsyncComponent} from 'vue'
74
- import mixin from '../../highlight/mixin.js'
75
-
76
- export default {
77
- name: 'r-json',
78
- components: {JsonView: defineAsyncComponent(() => import('./JsonView.vue'))},
79
- mixins: [mixin],
80
- props: {
81
- label: String,
82
- keyLabel: {type: String, default: 'key'},
83
- valueLabel: {type: String, default: 'value'},
84
- modelValue: {
85
- type: Object, Array
86
- },
87
- valueType: {
88
- type: String,
89
- validator: function (value) {
90
- return ['text', 'number', 'boolean'].indexOf(value) !== -1
91
- }
92
- },
93
- template: Object,
94
- baseArray: Boolean,
95
- disableAdd: Boolean,
96
- tile: {type: Boolean, default: undefined},
97
- disableEditKey: Boolean,
98
- disableDel: Boolean,
99
- translate: Boolean
70
+
71
+ <script setup>
72
+ import {computed, inject, onMounted, ref, watch} from 'vue'
73
+ import {useHighlight} from '../../highlight/useHighlight.js'
74
+ import JsonView from "./JsonView.vue"
75
+
76
+ const props = defineProps({
77
+ /**
78
+ * Label text for the key input field
79
+ * @type {String}
80
+ * @default 'key'
81
+ */
82
+ keyLabel: {
83
+ type: String,
84
+ default: 'key'
100
85
  },
101
- emits: ['update:modelValue'],
102
- data() {
103
- return {
104
- lazyValue: '',
105
- modeForm: true,
106
- error: false,
107
- show: false,
108
- code: "",
109
- info: {}
110
- }
86
+ /**
87
+ * Label text for the value input field
88
+ * @type {String}
89
+ * @default 'value'
90
+ */
91
+ valueLabel: {
92
+ type: String,
93
+ default: 'value'
111
94
  },
112
- async created() {
113
- if (this.modelValue) {
114
- await this.build_code()
115
- }
95
+ /**
96
+ * The JSON data model value (object or array)
97
+ * @type {Object|Array}
98
+ */
99
+ modelValue: [Object, Array],
100
+ /**
101
+ * Fixed value type for all items when specified
102
+ * @type {String}
103
+ * @validator ['text', 'number', 'boolean']
104
+ */
105
+ valueType: {
106
+ type: String,
107
+ validator: (value) => ['text', 'number', 'boolean'].includes(value)
116
108
  },
117
- watch: {
118
- modeForm: function () {
119
- this.lazyValue = JSON.stringify(this.modelValue || {}, null, 4)
120
- },
121
- modelValue: function () {
122
- try {
123
- this.error = false
124
- if (JSON.stringify(JSON.parse(this.lazyValue)) !== JSON.stringify(this.modelValue)) {
125
- this.lazyValue = JSON.stringify(this.modelValue || {}, null, 4)
126
- }
127
- } catch (er) {
128
- this.error = true
129
- }
109
+ /**
110
+ * Template object for new items when adding
111
+ * @type {Object}
112
+ */
113
+ template: Object,
114
+ /**
115
+ * Treat the model value as an array base
116
+ * @type {Boolean}
117
+ */
118
+ baseArray: Boolean,
119
+ /**
120
+ * Disable the ability to add new items
121
+ * @type {Boolean}
122
+ */
123
+ disableAdd: Boolean,
124
+ /**
125
+ * Disable the edit key toggle button
126
+ * @type {Boolean}
127
+ */
128
+ disableEditKey: Boolean,
129
+ /**
130
+ * Disable the ability to delete items
131
+ * @type {Boolean}
132
+ */
133
+ disableDel: Boolean,
134
+ /**
135
+ * Enable translation for UI texts
136
+ * @type {Boolean}
137
+ */
138
+ translate: Boolean
139
+ })
130
140
 
131
- },
132
- lazyValue: async function () {
133
- try {
134
- this.error = false
135
- await this.build_code()
136
- this.$emit('update:modelValue', JSON.parse(this.lazyValue))
137
- } catch (er) {
138
- this.error = true
139
- }
140
- },
141
- },
142
- computed: {
143
- c_tile() {
144
- if (this.tile === undefined && this.$r.inputs.tile) {
145
- return this.$r.inputs.tile
146
- }
147
- return this.tile
148
- },
149
- is_array() {
150
- if (this.baseArray) {
151
- return true
152
- }
153
- return Array.isArray(this.modelValue)
141
+ const emit = defineEmits([
142
+ /**
143
+ * Emitted when the JSON data changes
144
+ * @param {Object|Array} value - The updated JSON data
145
+ */
146
+ 'update:modelValue'
147
+ ])
148
+
149
+ const {highlight} = useHighlight()
150
+
151
+ const $t = inject('renusify').$t
152
+
153
+ // Reactive data
154
+ const lazyValue = ref('')
155
+ const modeForm = ref(true)
156
+ const error = ref(false)
157
+ const show = ref(false)
158
+ const code = ref('')
159
+ const info = ref({})
160
+
161
+ // Computed properties
162
+ /**
163
+ * Determines if the model value is an array
164
+ * @returns {Boolean} True if model is an array
165
+ */
166
+ const is_array = computed(() => {
167
+ if (props.baseArray) {
168
+ return true
169
+ }
170
+ return Array.isArray(props.modelValue)
171
+ })
172
+
173
+ // Methods
174
+ /**
175
+ * Builds syntax-highlighted code from JSON
176
+ */
177
+ const build_code = async () => {
178
+ try {
179
+ code.value = await highlight(lazyValue.value, 'json', true)
180
+ } catch (err) {
181
+ console.error('Error highlighting code:', err)
182
+ }
183
+ }
184
+
185
+ /**
186
+ * Opens the add form or applies template
187
+ */
188
+ const open = () => {
189
+ if (props.template) {
190
+ let newValue = props.modelValue
191
+
192
+ if (!newValue) {
193
+ newValue = props.baseArray ? [] : {}
154
194
  }
155
- },
156
- methods: {
157
- async build_code() {
158
- this.code = await this.highlight(this.lazyValue, "json", true)
159
- },
160
- open() {
161
- if (this.template) {
162
- let d = this.modelValue
163
- if (!d) {
164
- d = []
165
- }
166
- d.push(Object.assign({}, {}, this.template))
167
- this.$emit('update:modelValue', d)
168
- } else {
169
- if (this.valueType) {
170
- this.info.type = this.valueType
171
- }
172
- this.show = true
173
- }
174
- },
175
-
176
- emit(e) {
177
- this.$emit('update:modelValue', e)
178
- },
179
- add() {
180
- let d = this.modelValue
181
- if (!d) {
182
- if (this.baseArray) {
183
- d = []
184
- } else {
185
- d = {}
186
- }
187
- }
188
- if (this.info.type === 'json') {
189
- if (this.is_array) {
190
- d.push({})
191
- } else {
192
- d[this.info.key] = {}
193
- }
194
- } else if (this.info.type === 'array') {
195
- if (this.is_array) {
196
- d.push([])
197
- } else {
198
- d[this.info.key] = []
199
- }
200
- } else {
201
- if (this.is_array) {
202
- d.push(this.info.value)
203
- } else {
204
- d[this.info.key] = this.info.value
205
- }
206
- }
207
- this.show = false
208
- this.info = {}
209
- this.$emit('update:modelValue', d)
195
+
196
+ if (props.baseArray) {
197
+ const templateCopy = JSON.parse(JSON.stringify(props.template))
198
+ newValue.push(templateCopy)
199
+ } else {
200
+ newValue = JSON.parse(JSON.stringify(props.template))
210
201
  }
202
+
203
+ emit('update:modelValue', newValue)
204
+ } else {
205
+ if (props.valueType) {
206
+ info.value.type = props.valueType
207
+ }
208
+ show.value = true
211
209
  }
212
210
  }
213
- </script>
214
- <style lang="scss">
215
- @use "sass:map";
216
- @use "../../../style/variables/base";
217
211
 
212
+ /**
213
+ * Emits updated value from JsonView component
214
+ * @param {Object|Array} value - The updated JSON value
215
+ */
216
+ const emitValue = (value) => {
217
+ emit('update:modelValue', value)
218
+ }
218
219
 
219
- .#{base.$prefix}json-input {
220
- background: var(--color-sheet-container);
221
- padding: 5px;
220
+ /**
221
+ * Adds a new item to the JSON data
222
+ */
223
+ const add = () => {
224
+ let newValue = props.modelValue
222
225
 
223
- &.input-tile {
224
- border-radius: map.get(base.$borders, 'sm');
226
+ if (!newValue) {
227
+ newValue = props.baseArray ? [] : {}
225
228
  }
226
229
 
227
- &:not(.input-tile) {
228
- border-radius: map.get(base.$borders, 'xl');
230
+ newValue = JSON.parse(JSON.stringify(newValue))
231
+
232
+ if (info.value.type === 'json') {
233
+ if (is_array.value) {
234
+ newValue.push({})
235
+ } else {
236
+ newValue[info.value.key] = {}
237
+ }
238
+ } else if (info.value.type === 'array') {
239
+ if (is_array.value) {
240
+ newValue.push([])
241
+ } else {
242
+ newValue[info.value.key] = []
243
+ }
244
+ } else {
245
+ if (is_array.value) {
246
+ newValue.push(info.value.value)
247
+ } else {
248
+ newValue[info.value.key] = info.value.value
249
+ }
229
250
  }
230
251
 
231
- .input-control {
232
- background: var(--color-sheet-container-low);
252
+ show.value = false
253
+ info.value = {}
254
+ emit('update:modelValue', newValue)
255
+ }
256
+
257
+ // Watchers
258
+ watch(modeForm, () => {
259
+ lazyValue.value = JSON.stringify(props.modelValue || {}, null, 4)
260
+ })
261
+
262
+ watch(() => props.modelValue, (newValue) => {
263
+ try {
264
+ error.value = false
265
+
266
+ if (lazyValue.value) {
267
+ const currentParsed = JSON.parse(lazyValue.value)
268
+ if (JSON.stringify(currentParsed) !== JSON.stringify(newValue)) {
269
+ lazyValue.value = JSON.stringify(newValue || {}, null, 4)
270
+ }
271
+ } else {
272
+ lazyValue.value = JSON.stringify(newValue || {}, null, 4)
273
+ }
274
+ } catch (er) {
275
+ error.value = true
276
+ console.error('Error parsing JSON:', er)
233
277
  }
278
+ }, {deep: true})
234
279
 
235
- textarea {
236
- outline: none;
237
- border: 1px solid var(--color-sheet-low);
280
+ watch(lazyValue, async (newValue) => {
281
+ try {
282
+ error.value = false
283
+ await build_code()
284
+ const parsed = JSON.parse(newValue)
285
+ emit('update:modelValue', parsed)
286
+ } catch (er) {
287
+ error.value = true
288
+ console.error('Error in lazyValue watch:', er)
289
+ }
290
+ })
291
+
292
+ // Lifecycle hooks
293
+ onMounted(async () => {
294
+ if (props.modelValue) {
295
+ try {
296
+ lazyValue.value = JSON.stringify(props.modelValue, null, 4)
297
+ await build_code()
298
+ } catch (err) {
299
+ console.error('Error initializing component:', err)
300
+ }
301
+ }
302
+ })
303
+ </script>
304
+
305
+ <style lang="scss">
306
+ @use "sass:map";
307
+ @use "../../../style/variables/base";
308
+
309
+
310
+ .#{base.$prefix}json-input {
311
+ > .input-control {
312
+ height: auto;
313
+ padding: 8px;
314
+ }
315
+
316
+ .input-holder {
317
+ .input-control {
318
+ background-color: var(--color-sheet-container-low);
319
+ }
238
320
  }
239
321
 
240
322
  .state-error {