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
@@ -12,44 +12,43 @@
12
12
  </div>
13
13
  </template>
14
14
 
15
- <script>
16
- import mixin from './mixin.js'
17
- import mixin_h from '../highlight/mixin.js'
18
-
19
- export default {
20
- name: "highlight-script",
21
- props: {
22
- modelValue: String,
23
- },
24
- mixins: [mixin, mixin_h],
25
- data() {
26
- return {
27
- d: this.modelValue,
28
- code: "",
29
- };
30
- },
31
- async created() {
32
- if (this.modelValue) {
33
- await this.build_code()
34
- }
35
- },
36
- watch: {
37
- modelValue: function () {
38
- this.d = this.modelValue;
39
- },
40
- d: async function () {
41
- await this.build_code()
42
- this.$emit("update:modelValue", this.d);
43
- },
44
- },
45
- methods: {
46
- async build_code() {
47
- this.code = await this.highlight(this.d, "js", true)
48
- }
15
+ <script setup>
16
+ import {ref, watch, onMounted} from 'vue'
17
+ import {useHighlight} from '../highlight/useHighlight.js'
18
+ import {useCodeFormatter} from './useCodeFormatter.js'
19
+
20
+ const props = defineProps({
21
+ modelValue: String
22
+ })
23
+
24
+ const emit = defineEmits(['update:modelValue'])
25
+
26
+ const {highlight} = useHighlight()
27
+ const {setTab} = useCodeFormatter()
28
+
29
+ const d = ref(props.modelValue || '')
30
+ const code = ref('')
31
+
32
+ const build_code = async () => {
33
+ if (d.value) {
34
+ code.value = await highlight(d.value, "js", true)
35
+ } else {
36
+ code.value = ''
49
37
  }
50
- };
51
- </script>
38
+ }
39
+
40
+ watch(() => props.modelValue, (newValue) => {
41
+ d.value = newValue
42
+ })
52
43
 
53
- <style lang="scss">
44
+ watch(d, async (newValue) => {
45
+ await build_code()
46
+ emit('update:modelValue', newValue)
47
+ }, {immediate: true})
54
48
 
55
- </style>
49
+ onMounted(async () => {
50
+ if (props.modelValue) {
51
+ await build_code()
52
+ }
53
+ })
54
+ </script>
@@ -32,6 +32,7 @@
32
32
  :css="sty"
33
33
  :script="scr"
34
34
  :template="temp"
35
+ :scriptSetup="scriptSetup"
35
36
  ></r-code-editor-run>
36
37
  </div>
37
38
  <div v-show="show !== 'run'" ref="codeView" class="code-wrapper">
@@ -42,10 +43,11 @@
42
43
  </div>
43
44
  <div>
44
45
  <span v-show="scriptShow" class="highlight-syn-class"
45
- >&lt;script&gt;<br/>export default {</span
46
+ >&lt;script <span class="highlight-syn-str" v-if="scriptSetup">setup</span>&gt;<br/>
47
+ <template v-if="!scriptSetup">export default {</template></span
46
48
  >
47
49
  <highlight-script ref="h-js" v-model="scr"></highlight-script>
48
- <span v-show="scriptShow" class="highlight-syn-class">}<br/>&lt;/script&gt;</span>
50
+ <span v-show="scriptShow" class="highlight-syn-class"><template v-if="!scriptSetup">}</template><br/>&lt;/script&gt;</span>
49
51
  </div>
50
52
  <div>
51
53
  <span v-show="cssShow" class="highlight-syn-class"
@@ -58,87 +60,135 @@
58
60
  </div>
59
61
  </template>
60
62
 
61
- <script>
62
- import {defineAsyncComponent} from 'vue'
63
-
64
- export default {
65
- name: "r-code-editor",
66
- components: {
67
- HighlightCss: defineAsyncComponent(() =>
68
- import("./highlightCss.vue")
69
- ), HighlightScript: defineAsyncComponent(() =>
70
- import("./highlightJs.vue")
71
- ), highlightHtml: defineAsyncComponent(() =>
72
- import("./highlightHtml.vue")
73
- ), RCodeEditorRun: defineAsyncComponent(() =>
74
- import("./run.vue")
75
- )
76
- },
77
- props: {
78
- runnable: Boolean,
79
- templateShow: {type: Boolean, default: true},
80
- scriptShow: {type: Boolean, default: true},
81
- cssShow: {type: Boolean, default: true},
82
- template: String,
83
- script: String,
84
- css: String,
85
- },
86
- emits: ["update:template", "update:script", "update:css"],
87
- data() {
88
- return {
89
- show: "code",
90
- code: "",
91
- edited: false,
92
- temp: this.template,
93
- scr: this.script,
94
- sty: this.css,
95
- id: this.$helper.uniqueId(),
96
- };
97
- },
98
- created() {
99
- if (!this.$r.icons.play) {
100
- this.$r.icons.play =
101
- '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><path fill="currentColor" d="M8 5.14v14l11-7l-11-7Z"/></svg>';
102
- }
103
- if (!this.$r.icons.code_tags) {
104
- this.$r.icons.code_tags =
105
- '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><path fill="currentColor" d="m14.6 16.6l4.6-4.6l-4.6-4.6L16 6l6 6l-6 6l-1.4-1.4m-5.2 0L4.8 12l4.6-4.6L8 6l-6 6l6 6l1.4-1.4Z"/></svg>';
106
- }
107
- },
108
- watch: {
109
- template: function (n) {
110
- this.temp = n
111
- },
112
- script: function (n) {
113
- this.scr = n
114
- },
115
- css: function (n) {
116
- this.sty = n
117
- },
118
- temp: function () {
119
- this.$emit("update:template", this.temp);
120
- },
121
- scr: function () {
122
- this.$emit("update:script", this.scr);
123
- },
124
- sty: function () {
125
- this.$emit("update:css", this.sty);
126
- },
127
- },
128
- methods: {
129
- pretty() {
130
- this.temp = this.$refs["h-html"].pretty_html(this.temp)
131
- this.scr = this.$refs["h-js"].pretty_js(this.scr)
132
- this.sty = this.$refs["h-css"].pretty_js(this.sty)
133
- }
134
- },
135
- };
63
+ <script setup>
64
+ import {ref, watch, defineAsyncComponent, inject} from 'vue'
65
+ import {useCodeFormatter} from "./useCodeFormatter"
66
+
67
+ const {pretty_html, pretty_js} = useCodeFormatter()
68
+ const HighlightCss = defineAsyncComponent(() => import("./highlightCss.vue"))
69
+ const HighlightScript = defineAsyncComponent(() => import("./highlightJs.vue"))
70
+ const HighlightHtml = defineAsyncComponent(() => import("./highlightHtml.vue"))
71
+ const RCodeEditorRun = defineAsyncComponent(() => import("./run.vue"))
72
+
73
+ const props = defineProps({
74
+ /**
75
+ * Enables run functionality for the code editor
76
+ * @type {Boolean}
77
+ */
78
+ runnable: Boolean,
79
+
80
+ /**
81
+ * Shows/hides the template section
82
+ * @type {Boolean}
83
+ * @default true
84
+ */
85
+ templateShow: {type: Boolean, default: true},
86
+
87
+ /**
88
+ * Shows/hides the script section
89
+ * @type {Boolean}
90
+ * @default true
91
+ */
92
+ scriptShow: {type: Boolean, default: true},
93
+
94
+ /**
95
+ * Shows/hides the CSS section
96
+ * @type {Boolean}
97
+ * @default true
98
+ */
99
+ cssShow: {type: Boolean, default: true},
100
+
101
+ /**
102
+ * Template code content
103
+ * @type {String}
104
+ */
105
+ template: String,
106
+
107
+ /**
108
+ * Script code content
109
+ * @type {String}
110
+ */
111
+ script: String,
112
+
113
+ /**
114
+ * CSS code content
115
+ * @type {String}
116
+ */
117
+ css: String,
118
+ /**
119
+ * Script code content is setup.
120
+ */
121
+ scriptSetup: Boolean
122
+ })
123
+
124
+ const emit = defineEmits([
125
+ /**
126
+ * Emitted when template content changes
127
+ * @param {String} template - Updated template code
128
+ */
129
+ "update:template",
130
+
131
+ /**
132
+ * Emitted when script content changes
133
+ * @param {String} script - Updated script code
134
+ */
135
+ "update:script",
136
+
137
+ /**
138
+ * Emitted when CSS content changes
139
+ * @param {String} css - Updated CSS code
140
+ */
141
+ "update:css"
142
+ ])
143
+
144
+ const renusify = inject('renusify')
145
+ const $r = renusify.$r
146
+ const $helper = renusify.$helper
147
+
148
+ const show = ref("code")
149
+ const temp = ref(props.template || "")
150
+ const scr = ref(props.script || "")
151
+ const sty = ref(props.css || "")
152
+ const id = ref($helper?.uniqueId() || Math.random().toString(36).substr(2, 9))
153
+
154
+ watch(() => props.template, (newValue) => {
155
+ temp.value = newValue
156
+ })
157
+
158
+ watch(() => props.script, (newValue) => {
159
+ scr.value = newValue
160
+ })
161
+
162
+ watch(() => props.css, (newValue) => {
163
+ sty.value = newValue
164
+ })
165
+
166
+ watch(temp, (newValue) => {
167
+ emit("update:template", newValue)
168
+ })
169
+
170
+ watch(scr, (newValue) => {
171
+ emit("update:script", newValue)
172
+ })
173
+
174
+ watch(sty, (newValue) => {
175
+ emit("update:css", newValue)
176
+ })
177
+
178
+ /**
179
+ * Formats all code sections (template, script, CSS) to make them prettier
180
+ */
181
+ const pretty = () => {
182
+ temp.value = pretty_html(temp.value)
183
+ scr.value = pretty_js(scr.value)
184
+ sty.value = pretty_js(sty.value)
185
+ }
136
186
  </script>
137
187
 
138
188
  <style lang="scss">
139
- @use "../../style/variables/base";
189
+ @use "../../style" as *;
140
190
 
141
- .#{base.$prefix}code-editor {
191
+ .#{$prefix}code-editor {
142
192
  position: relative;
143
193
  white-space: break-spaces;
144
194
  caret-color: #f8f8f2;
@@ -1,46 +1,232 @@
1
1
  <template>
2
2
  <component :is="page"></component>
3
3
  </template>
4
- <script>
5
- import {defineAsyncComponent} from "vue/dist/vue.esm-bundler.js";
6
-
7
- export default {
8
- name: "r-code-editor-run",
9
- props: {
10
- template: String,
11
- script: String,
12
- css: String,
13
- id: String,
14
- },
15
- computed: {
16
- page() {
17
- if (this.css) {
18
- let children = document.querySelectorAll(`[f='${this.id}']`);
19
- if (children) {
20
- let childArray = Array.prototype.slice.call(children);
21
-
22
- childArray.forEach(function (child) {
23
- child.parentNode.removeChild(child);
24
- });
4
+ <script setup>
5
+ import {
6
+ computed,
7
+ inject,
8
+ onMounted,
9
+ onUnmounted,
10
+ onUpdated,
11
+ provide,
12
+ reactive,
13
+ ref,
14
+ toRef,
15
+ toRefs,
16
+ watch,
17
+ watchEffect
18
+ } from 'vue'
19
+
20
+ import {defineAsyncComponent, defineComponent} from 'vue/dist/vue.esm-bundler.js'
21
+
22
+ const props = defineProps({
23
+ template: String,
24
+ script: String,
25
+ css: String,
26
+ id: String,
27
+ scriptSetup: Boolean,
28
+ })
29
+ const addStyleToHead = () => {
30
+ if (props.css && props.id) {
31
+ const existingStyles = document.querySelectorAll(`[f='${props.id}']`)
32
+ existingStyles.forEach(style => style.remove())
33
+
34
+ const style = document.createElement("style")
35
+ style.textContent = props.css
36
+ style.setAttribute("f", props.id)
37
+ style.setAttribute("type", "text/css")
38
+ document.head.appendChild(style)
39
+ }
40
+ }
41
+
42
+ const removeStyleFromHead = () => {
43
+ if (props.id) {
44
+ const existingStyles = document.querySelectorAll(`[f='${props.id}']`)
45
+ existingStyles.forEach(style => style.remove())
46
+ }
47
+ }
48
+
49
+ const page = computed(() => {
50
+ addStyleToHead()
51
+
52
+ const temp = props.template || ""
53
+ const scr = props.script || ''
54
+
55
+ return defineAsyncComponent(() =>
56
+ new Promise((resolve) => {
57
+ try {
58
+ if (props.scriptSetup) {
59
+ // Create the component with script setup
60
+ const componentObj = defineComponent({
61
+ template: temp,
62
+ setup() {
63
+ // Create a context object with all Vue APIs
64
+ const vueContext = {
65
+ // Reactivity
66
+ ref,
67
+ reactive,
68
+ computed,
69
+ watch,
70
+ watchEffect,
71
+
72
+ // Lifecycle
73
+ onMounted,
74
+ onUnmounted,
75
+ onUpdated,
76
+
77
+ // Dependency Injection
78
+ inject,
79
+ provide,
80
+
81
+ // Refs
82
+ toRefs,
83
+ toRef
84
+ }
85
+
86
+ try {
87
+ // Process the script to remove imports and handle setup
88
+ const processedScript = processScriptForSetup(scr)
89
+
90
+ // Create the setup function with all Vue APIs available
91
+ const setupCode = `
92
+ // Make Vue APIs available
93
+ ${Object.entries(vueContext).map(([key, value]) =>
94
+ `const ${key} = arguments[0]['${key}'];`
95
+ ).join('\n')}
96
+
97
+ // User's script
98
+ ${processedScript}
99
+
100
+ // Collect and return declared variables
101
+ const result = {};
102
+ const declaredVars = ${JSON.stringify(extractDeclaredVariables(processedScript))};
103
+ declaredVars.forEach(varName => {
104
+ try {
105
+ if (typeof eval(varName) !== 'undefined') {
106
+ result[varName] = eval(varName);
107
+ }
108
+ } catch(e) {}
109
+ });
110
+ return result;
111
+ `
112
+
113
+ const setupFunction = new Function(setupCode)
114
+ return setupFunction(vueContext)
115
+
116
+ } catch (error) {
117
+ console.error('Error executing user script:', error)
118
+ return {
119
+ __error: ref(`Script execution error: ${error.message}`)
120
+ }
121
+ }
122
+ }
123
+ })
124
+
125
+ resolve(componentObj)
126
+
127
+ } else {
128
+ // For Options API
129
+ const scriptObj = eval(`(function() {
130
+ return { ${scr} }
131
+ })()`)
132
+
133
+ const componentObj = defineComponent({
134
+ template: temp,
135
+ ...scriptObj
136
+ })
137
+
138
+ resolve(componentObj)
139
+ }
140
+ } catch (error) {
141
+ console.error('Error creating component:', error)
142
+ resolve(createErrorComponent(error))
25
143
  }
26
- let s = document.createElement("style");
27
- s.innerText = this.css;
28
- s.setAttribute("f", this.id);
29
- s.setAttribute("type", "text/css");
30
- window.document.head.append(s);
144
+ })
145
+ )
146
+ })
147
+
148
+ // Process script to remove imports and prepare for setup
149
+ function processScriptForSetup(script) {
150
+ let processed = script
151
+
152
+ // Remove Vue imports since we provide them
153
+ processed = processed.replace(/import\s*{[^}]*}\s*from\s*['"]vue['"][\s;]*/g, '')
154
+
155
+ // Remove other imports (for now, could handle them differently)
156
+ processed = processed.replace(/import\s+.*?\s+from\s+['"][^'"]+['"][\s;]*/g, '// [import removed]')
157
+
158
+ // Handle defineProps and defineEmits
159
+ processed = processed.replace(/defineProps\s*\(/g, 'const props = defineProps(')
160
+ processed = processed.replace(/defineEmits\s*\(/g, 'const emit = defineEmits(')
161
+
162
+ return processed.trim()
163
+ }
164
+
165
+ // Extract variable names that should be returned
166
+ function extractDeclaredVariables(script) {
167
+ const variables = []
168
+
169
+ // Match variable declarations
170
+ const varPatterns = [
171
+ /(?:const|let|var)\s+(\w+)\s*=/g,
172
+ /function\s+(\w+)\s*\(/g,
173
+ /(\w+)\s*:\s*\(\)\s*=>/g // Arrow functions
174
+ ]
175
+
176
+ varPatterns.forEach(pattern => {
177
+ let match
178
+ while ((match = pattern.exec(script)) !== null) {
179
+ if (match[1] && !match[1].startsWith('_')) {
180
+ variables.push(match[1])
31
181
  }
32
- let temp = this.template || "";
33
- let scr = this.script || 'name:"test"';
34
- return defineAsyncComponent(
35
- () =>
36
- new Promise((resolve) => {
37
- resolve({
38
- template: temp,
39
- ...eval("Object({" + scr + "})"),
40
- });
41
- })
42
- );
182
+ }
183
+ })
184
+
185
+ // Also look for ref, reactive, computed declarations
186
+ const reactivePatterns = [
187
+ /(\w+)\s*=\s*ref\(/,
188
+ /(\w+)\s*=\s*reactive\(/,
189
+ /(\w+)\s*=\s*computed\(/
190
+ ]
191
+
192
+ script.split('\n').forEach(line => {
193
+ reactivePatterns.forEach(pattern => {
194
+ const match = line.match(pattern)
195
+ if (match && match[1]) {
196
+ variables.push(match[1])
197
+ }
198
+ })
199
+ })
200
+
201
+ return [...new Set(variables)] // Remove duplicates
202
+ }
203
+
204
+ function createErrorComponent(error) {
205
+ return defineComponent({
206
+ name: 'ErrorComponent',
207
+ setup() {
208
+ const errorMsg = ref(error.message)
209
+ return {errorMsg}
43
210
  },
44
- },
45
- };
211
+ template: `
212
+ <div style="color: #f44336; padding: 20px; background: #ffebee; border-radius: 4px; font-family: 'Courier New', monospace;">
213
+ <div style="font-weight: bold; margin-bottom: 8px;">Script Error:</div>
214
+ <div>{{ errorMsg }}</div>
215
+ </div>
216
+ `
217
+ })
218
+ }
219
+
220
+ onMounted(() => {
221
+ addStyleToHead()
222
+ })
223
+
224
+ onUnmounted(() => {
225
+ removeStyleFromHead()
226
+ })
227
+
228
+ watch(() => props.css, () => {
229
+ addStyleToHead()
230
+ })
46
231
  </script>
232
+