Skip to content

Commit

Permalink
style: update code
Browse files Browse the repository at this point in the history
  • Loading branch information
yanglbme committed Aug 19, 2024
1 parent 1e55533 commit c0f1eb5
Show file tree
Hide file tree
Showing 20 changed files with 74 additions and 109 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/components/CodemirrorEditor/CssEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ function handleTabsEdit(targetName, action) {
return
}
if (store.cssContentConfig.active === targetName) {
const currentIndex = tabs.findIndex(tab => tab.name === targetName);
const nextTab = tabs[currentIndex + 1] || tabs[currentIndex - 1];
store.cssContentConfig.active = nextTab ? nextTab.name : '';
const currentIndex = tabs.findIndex(tab => tab.name === targetName)
const nextTab = tabs[currentIndex + 1] || tabs[currentIndex - 1]
store.cssContentConfig.active = nextTab ? nextTab.name : ``
}
store.cssContentConfig.tabs = tabs.filter(tab => tab.name !== targetName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
HoverCardTrigger,
} from '@/components/ui/hover-card'
import { codeBlockThemeOptions, colorOptions, fontFamilyOptions, fontSizeOptions, githubConfig, legendOptions, themeOptions } from '@/config'
import { codeBlockThemeOptions, colorOptions, fontFamilyOptions, fontSizeOptions, legendOptions, themeOptions } from '@/config'
import { useStore } from '@/stores'
const store = useStore()
Expand Down
8 changes: 1 addition & 7 deletions src/components/CodemirrorEditor/EditorHeader/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import { nextTick, ref } from 'vue'
import { nextTick } from 'vue'
import { storeToRefs } from 'pinia'
import { ElNotification } from 'element-plus'
import CodeMirror from 'codemirror'
Expand All @@ -19,12 +19,6 @@ import {
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu'
import {
HoverCard,
HoverCardContent,
HoverCardTrigger,
} from '@/components/ui/hover-card'
import { mergeCss, solveWeChatImage } from '@/utils'
import { useStore } from '@/stores'
Expand Down
4 changes: 1 addition & 3 deletions src/components/CodemirrorEditor/InsertFormDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createTable } from '@/utils'
const store = useStore()
const { formatContent, toggleShowInsertFormDialog } = store
const { toggleShowInsertFormDialog } = store
const rowNum = ref(3)
const colNum = ref(3)
Expand All @@ -27,9 +27,7 @@ function insertTable() {
store.editor.operation(() => {
store.editor.replaceSelection(`\n${table}\n`, `end`)
})
// store.editorRefresh()
resetVal()
// formatContent()
toggleShowInsertFormDialog()
}
</script>
Expand Down
6 changes: 3 additions & 3 deletions src/components/ui/dropdown-menu/DropdownMenuCheckboxItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { Check } from 'lucide-vue-next'
import { cn } from '@/lib/utils'
const props = defineProps<DropdownMenuCheckboxItemProps & { class?: HTMLAttributes['class'] }>()
const props = defineProps<DropdownMenuCheckboxItemProps & { class?: HTMLAttributes[`class`] }>()
const emits = defineEmits<DropdownMenuCheckboxItemEmits>()
const delegatedProps = computed(() => {
Expand All @@ -30,9 +30,9 @@ const forwarded = useForwardPropsEmits(delegatedProps, emits)
props.class,
)"
>
<span class="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
<span class="absolute left-2 h-3.5 w-3.5 flex items-center justify-center">
<DropdownMenuItemIndicator>
<Check class="w-4 h-4" />
<Check class="h-4 w-4" />
</DropdownMenuItemIndicator>
</span>
<slot />
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/dropdown-menu/DropdownMenuContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { cn } from '@/lib/utils'
const props = withDefaults(
defineProps<DropdownMenuContentProps & { class?: HTMLAttributes['class'] }>(),
defineProps<DropdownMenuContentProps & { class?: HTMLAttributes[`class`] }>(),
{
sideOffset: 4,
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/dropdown-menu/DropdownMenuItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type HTMLAttributes, computed } from 'vue'
import { DropdownMenuItem, type DropdownMenuItemProps, useForwardProps } from 'radix-vue'
import { cn } from '@/lib/utils'
const props = defineProps<DropdownMenuItemProps & { class?: HTMLAttributes['class'], inset?: boolean }>()
const props = defineProps<DropdownMenuItemProps & { class?: HTMLAttributes[`class`], inset?: boolean }>()
const delegatedProps = computed(() => {
const { class: _, ...delegated } = props
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/dropdown-menu/DropdownMenuLabel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type HTMLAttributes, computed } from 'vue'
import { DropdownMenuLabel, type DropdownMenuLabelProps, useForwardProps } from 'radix-vue'
import { cn } from '@/lib/utils'
const props = defineProps<DropdownMenuLabelProps & { class?: HTMLAttributes['class'], inset?: boolean }>()
const props = defineProps<DropdownMenuLabelProps & { class?: HTMLAttributes[`class`], inset?: boolean }>()
const delegatedProps = computed(() => {
const { class: _, ...delegated } = props
Expand Down
4 changes: 2 additions & 2 deletions src/components/ui/dropdown-menu/DropdownMenuRadioItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { Circle } from 'lucide-vue-next'
import { cn } from '@/lib/utils'
const props = defineProps<DropdownMenuRadioItemProps & { class?: HTMLAttributes['class'] }>()
const props = defineProps<DropdownMenuRadioItemProps & { class?: HTMLAttributes[`class`] }>()
const emits = defineEmits<DropdownMenuRadioItemEmits>()
Expand All @@ -31,7 +31,7 @@ const forwarded = useForwardPropsEmits(delegatedProps, emits)
props.class,
)"
>
<span class="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
<span class="absolute left-2 h-3.5 w-3.5 flex items-center justify-center">
<DropdownMenuItemIndicator>
<Circle class="h-2 w-2 fill-current" />
</DropdownMenuItemIndicator>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/dropdown-menu/DropdownMenuSeparator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { cn } from '@/lib/utils'
const props = defineProps<DropdownMenuSeparatorProps & {
class?: HTMLAttributes['class']
class?: HTMLAttributes[`class`]
}>()
const delegatedProps = computed(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/dropdown-menu/DropdownMenuShortcut.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { HTMLAttributes } from 'vue'
import { cn } from '@/lib/utils'
const props = defineProps<{
class?: HTMLAttributes['class']
class?: HTMLAttributes[`class`]
}>()
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/dropdown-menu/DropdownMenuSubContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from 'radix-vue'
import { cn } from '@/lib/utils'
const props = defineProps<DropdownMenuSubContentProps & { class?: HTMLAttributes['class'] }>()
const props = defineProps<DropdownMenuSubContentProps & { class?: HTMLAttributes[`class`] }>()
const emits = defineEmits<DropdownMenuSubContentEmits>()
const delegatedProps = computed(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/dropdown-menu/DropdownMenuSubTrigger.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { ChevronRight } from 'lucide-vue-next'
import { cn } from '@/lib/utils'
const props = defineProps<DropdownMenuSubTriggerProps & { class?: HTMLAttributes['class'] }>()
const props = defineProps<DropdownMenuSubTriggerProps & { class?: HTMLAttributes[`class`] }>()
const delegatedProps = computed(() => {
const { class: _, ...delegated } = props
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/hover-card/HoverCardContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { cn } from '@/lib/utils'
const props = withDefaults(
defineProps<HoverCardContentProps & { class?: HTMLAttributes['class'] }>(),
defineProps<HoverCardContentProps & { class?: HTMLAttributes[`class`] }>(),
{
sideOffset: 4,
},
Expand Down
26 changes: 0 additions & 26 deletions src/stores/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,32 +163,6 @@ export const useStore = defineStore(`store`, () => {
setCssEditorValue(content)
}

function startEditing(name) {
editingTab.value = name;
const tab = store.cssContentConfig.tabs.find(tab => tab.name === name);
if (tab) {
newTabName.value = tab.title;
}
}

function saveTabName(oldName) {
if (newTabName.value.trim() !== '' && newTabName.value !== oldName) {
if (store.cssContentConfig.tabs.some(tab => tab.title === newTabName.value)) {
ElMessage.error('不能与现有方案重名');
return;
}
const tab = store.cssContentConfig.tabs.find(tab => tab.name === oldName);
if (tab) {
tab.title = newTabName.value;
}
editingTab.value = null;
ElMessage.success('重命名成功~');
} else {
editingTab.value = null;
ElMessage.info('取消重命名');
}
}

const addCssContentTab = (name) => {
cssContentConfig.value.tabs.push({
name,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import prettier from 'prettier/standalone'
import prettierCss from 'prettier/parser-postcss'
import prettierMarkdown from 'prettier/parser-markdown'

import { defaultTheme, prefix } from '@/config'
import { prefix } from '@/config'

export function addPrefix(str) {
return `${prefix}__${str}`
Expand Down
9 changes: 4 additions & 5 deletions src/utils/tokenTools.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
export function utf16to8(str) {
let out, i, len, c
out = ``
len = str.length
for (i = 0; i < len; i++) {
c = str.charCodeAt(i)
let out = ``
const n = str.length
for (let i = 0; i < n; i++) {
const c = str.charCodeAt(i)
if (c >= 0x0001 && c <= 0x007F) {
out += str.charAt(i)
}
Expand Down
10 changes: 5 additions & 5 deletions src/utils/wx-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ class WxRenderer {
'font-size': this.opts.size,
})
for (const ele in themeTpl.inline) {
if (themeTpl.inline.hasOwnProperty(ele)) {
if (Object.prototype.hasOwnProperty.call(themeTpl.inline, ele)) {
const style = themeTpl.inline[ele]
mapping[ele] = merge(themeTpl.BASE, style)
}
}

const base_block = merge(base, {})
for (const ele in themeTpl.block) {
if (themeTpl.block.hasOwnProperty(ele)) {
if (Object.prototype.hasOwnProperty.call(themeTpl.inline, ele)) {
const style = themeTpl.block[ele]
mapping[ele] = merge(base_block, style)
}
Expand Down Expand Up @@ -151,12 +151,12 @@ class WxRenderer {
`code`,
)}>${text}</code></pre>`
}
renderer.codespan = (text, lang) =>
renderer.codespan = (text, _) =>
`<code ${getStyles(`codespan`)}>${text}</code>`
renderer.listitem = text =>
`<li ${getStyles(`listitem`)}><span><%s/></span>${text}</li>`

renderer.list = (text, ordered, start) => {
renderer.list = (text, ordered, _) => {
text = text.replace(/<\/*p .*?>/g, ``).replace(/<\/*p>/g, ``)
const segments = text.split(`<%s/>`)
if (!ordered) {
Expand Down Expand Up @@ -220,7 +220,7 @@ class WxRenderer {
`<section style="padding:0 8px;"><table class="preview-table"><thead ${getStyles(
`thead`,
)}>${header}</thead><tbody>${body}</tbody></table></section>`
renderer.tablecell = (text, flags) =>
renderer.tablecell = (text, _) =>
`<td ${getStyles(`td`)}>${text}</td>`
renderer.hr = () => `<hr ${getStyles(`hr`)}>`
return renderer
Expand Down
Loading

0 comments on commit c0f1eb5

Please sign in to comment.