Skip to content

Commit 5d93240

Browse files
committed
fix: demo components and add nth.vue
- Removed unused stylelint directive from demo2.vue. - Simplified the structure of demo3.vue by removing el-popover and retaining only the add-node-popover-body. - Cleaned up script sections in demo2.vue and demo3.vue. - Introduced a new nth.vue component with basic styling and structure. - Added a test case for nth.vue to ensure proper transformation. - Updated transformSvelte.test.ts to enhance button styling consistency.
1 parent 3baadb2 commit 5d93240

File tree

10 files changed

+481
-600
lines changed

10 files changed

+481
-600
lines changed

playground/src/App.vue

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import 'vivid-typing/dist/index.css'
1616
1717
const { t, locale } = useI18n()
1818
const input = ref('')
19-
let pre: any
20-
= '<template>\n <button>button</button>\n</template>\n\n<style scoped>\n button {\n height: 32px;\n display: flex;\n justify-content: center;\n align-items: center;\n font-size: 14px;\n cursor: pointer;\n user-select: none;\n padding: 8px 15px;\n border-radius: 4px;\n border: none;\n box-sizing: border-box;\n color: #fff;\n background-color: #409eff;\n margin: auto;\n }\n button:hover{\n background-color: #67c23a ;\n }\n</style>\n'
19+
let pre: any =
20+
'<template>\n <button>button</button>\n</template>\n\n<style scoped>\n button {\n height: 32px;\n display: flex;\n justify-content: center;\n align-items: center;\n font-size: 14px;\n cursor: pointer;\n user-select: none;\n padding: 8px 15px;\n border-radius: 4px;\n border: none;\n box-sizing: border-box;\n color: #fff;\n background-color: #409eff;\n margin: auto;\n }\n button:hover{\n background-color: #67c23a ;\n }\n</style>\n'
2121
2222
let editorComponent: any = null
2323
let outputComponent: any = null
@@ -30,8 +30,7 @@ const isChecked = ref(false)
3030
const transform = computed(() => {
3131
try {
3232
return toUnocss(input.value, isChecked.value)
33-
}
34-
catch (err) {
33+
} catch (err) {
3534
return ''
3635
}
3736
})
@@ -90,7 +89,7 @@ const cssCompletionProvider = {
9089
}
9190
9291
return {
93-
suggestions: cssSuggestions.map(prop => ({
92+
suggestions: cssSuggestions.map((prop) => ({
9493
label: prop,
9594
kind: monaco.languages.CompletionItemKind.Property,
9695
insertText: prop,
@@ -100,7 +99,7 @@ const cssCompletionProvider = {
10099
},
101100
}
102101
monaco.languages.registerCompletionItemProvider('html', {
103-
triggerCharacters: ['<', ' ', ':', '"', '\'', '.'],
102+
triggerCharacters: ['<', ' ', ':', '"', "'", '.'],
104103
provideCompletionItems(model, position) {
105104
const textUntilPosition = model.getValueInRange({
106105
startLineNumber: 1,
@@ -110,9 +109,9 @@ monaco.languages.registerCompletionItemProvider('html', {
110109
})
111110
112111
// Check if we're in a style section
113-
const isInStyleSection
114-
= /<style\b/.test(textUntilPosition)
115-
&& !/<\/style>/.test(textUntilPosition.split(/<style\b/)[1] || '')
112+
const isInStyleSection =
113+
/<style\b/.test(textUntilPosition) &&
114+
!/<\/style>/.test(textUntilPosition.split(/<style\b/)[1] || '')
116115
117116
// Check if we're in a style attribute
118117
const isInStyleAttribute = /style\s*=\s*["'][^"']*$/.test(textUntilPosition)
@@ -180,7 +179,7 @@ monaco.languages.registerCompletionItemProvider('html', {
180179
]
181180
182181
return {
183-
suggestions: htmlTags.map(tag => ({
182+
suggestions: htmlTags.map((tag) => ({
184183
label: tag,
185184
kind: monaco.languages.CompletionItemKind.Keyword,
186185
insertText: `${tag}$0></${tag}>`,
@@ -271,8 +270,7 @@ onMounted(() => {
271270
document.addEventListener('keydown', (e) => {
272271
if ((e.metaKey || e.ctrlKey) && e.key === 'c') {
273272
const selection = document.getSelection()
274-
if (!selection || !selection.toString())
275-
return
273+
if (!selection || !selection.toString()) return
276274
const text = selection.toString()
277275
window.parent.postMessage({ eventType: 'copy', text }, '*')
278276
}
@@ -293,7 +291,7 @@ onMounted(() => {
293291
})
294292
outputComponent = monaco.editor.create(editorResult.value!, {
295293
value: `<template>
296-
<button h-32px flex justify-center items-center text-14px cursor-pointer select-none px-15px py-8px border-rd-4px border-none box-border text-#fff bg-#409eff m-auto hover="bg-#67c23a">button</button>
294+
<button class="h-32px flex justify-center items-center text-14px cursor-pointer select-none px-15px py-8px border-rd-4px border-none box-border text-[#fff] bg-[#409eff] m-auto hover-bg-[#67c23a]">button</button>
297295
</template>
298296
<style scoped></style>
299297
`,
@@ -315,10 +313,8 @@ onMounted(() => {
315313
const stop = useRaf(
316314
async () => {
317315
const newInput = editorComponent?.getValue()
318-
if (!newInput)
319-
return
320-
if (!editorResult.value)
321-
return
316+
if (!newInput) return
317+
if (!editorResult.value) return
322318
let code
323319
if ((!pre && newInput) || pre !== newInput) {
324320
pre = newInput
@@ -327,9 +323,8 @@ const stop = useRaf(
327323
code = await fetch('https://localhost/.netlify/functions/server', {
328324
method: 'POST',
329325
body: newInput,
330-
}).then(res => res.text())
331-
}
332-
catch (error) {
326+
}).then((res) => res.text())
327+
} catch (error) {
333328
code = await transformVue(newInput, {
334329
isRem: isChecked.value,
335330
})
@@ -400,17 +395,18 @@ function codeToHtml(code: string) {
400395
classReg,
401396
(_: any, match: any) => `[data-v-display]${match} {`,
402397
),
403-
))
398+
),
399+
)
404400
.replace('<template>', '')
405401
.replace('<\/template>', '')
406402
}
407-
const options = ref(cssSuggestions.map(i => ({ value: i })))
403+
const options = ref(cssSuggestions.map((i) => ({ value: i })))
408404
function onSearch(searchText: string) {
409405
options.value = !searchText
410-
? cssSuggestions.map(i => ({ value: i }))
406+
? cssSuggestions.map((i) => ({ value: i }))
411407
: cssSuggestions
412-
.map(i => ({ value: i }))
413-
.filter(i => i.value.includes(searchText))
408+
.map((i) => ({ value: i }))
409+
.filter((i) => i.value.includes(searchText))
414410
.sort(
415411
(a, b) => a.value.indexOf(searchText) - b.value.indexOf(searchText),
416412
)
@@ -429,8 +425,7 @@ function copyStyle() {
429425
}
430426
431427
function changelanguage() {
432-
if (locale.value === 'en')
433-
locale.value = 'zh'
428+
if (locale.value === 'en') locale.value = 'zh'
434429
else locale.value = 'en'
435430
}
436431
@@ -440,8 +435,7 @@ onUnmounted(() => {
440435
document.removeEventListener('keydown', (e) => {
441436
if ((e.metaKey || e.ctrlKey) && e.key === 'c') {
442437
const selection = document.getSelection()
443-
if (!selection || !selection.toString())
444-
return
438+
if (!selection || !selection.toString()) return
445439
const text = selection.toString()
446440
window.parent.postMessage({ eventType: 'copy', text }, '*')
447441
}
@@ -514,7 +508,7 @@ function onSelect(value: any) {
514508
@select="onSelect"
515509
/>
516510
<div flex items-center my3>
517-
<input v-model="isChecked" type="checkbox" w4 h4 mr1> isRem
511+
<input v-model="isChecked" type="checkbox" w4 h4 mr1 /> isRem
518512
</div>
519513
<div min-h-20 flex items-center justify-center>
520514
<div v-if="transform" flex="~ gap-4" items-center>

src/transformCode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface Options {
1414
}
1515

1616
export async function transfromCode(code: string, options: Options) {
17-
const { filepath, isRem, type, isJsx = false, globalCss } = options || {}
17+
const { filepath, isRem, type, isJsx = true, globalCss } = options || {}
1818
// 删除代码中的注释部分
1919
// code = code.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, '')
2020
if (type === 'tsx')

0 commit comments

Comments
 (0)