refactor(log): trim

This commit is contained in:
07akioni 2021-11-27 22:58:15 +08:00
parent 0255fd6838
commit 090889ea33
2 changed files with 9 additions and 18 deletions

View File

@ -35,14 +35,8 @@ export const logInjectionKey: InjectionKey<LogInjection> = Symbol('log')
const logProps = {
...(useTheme.props as ThemeProps<LogTheme>),
loading: {
type: Boolean,
default: false
},
trim: {
type: Boolean,
default: false
},
loading: Boolean,
trim: Boolean,
log: String,
fontSize: {
type: Number,
@ -69,10 +63,7 @@ const logProps = {
type: Number,
default: 0
},
hljs: {
type: Object,
default: undefined
},
hljs: Object,
onReachTop: Function as PropType<() => void>,
onReachBottom: Function as PropType<() => void>,
onRequireMore: Function as PropType<(from: 'top' | 'bottom') => void>

View File

@ -22,14 +22,14 @@ export default defineComponent({
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
inject(logInjectionKey)!
const selfRef = ref<HTMLElement | null>(null)
const mergedLineTrimRef = computed(() => {
return trimRef.value ? (props.line || '').trim() : props.line
const maybeTrimmedLinesRef = computed(() => {
return trimRef.value ? props.line.trim() : props.line
})
function setInnerHTML (): void {
if (selfRef.value) {
selfRef.value.innerHTML = generateCodeHTML(
languageRef.value,
mergedLineTrimRef.value
maybeTrimmedLinesRef.value
)
}
}
@ -58,11 +58,11 @@ export default defineComponent({
return {
highlight: highlightRef,
selfRef,
mergedLineTrim: mergedLineTrimRef
maybeTrimmedLines: maybeTrimmedLinesRef
}
},
render () {
const { highlight, mergedLineTrim } = this
return <pre ref="selfRef">{highlight ? null : mergedLineTrim}</pre>
const { highlight, maybeTrimmedLines } = this
return <pre ref="selfRef">{highlight ? null : maybeTrimmedLines}</pre>
}
})