mirror of
https://github.com/fmhy/edit.git
synced 2026-01-10 18:36:17 +00:00
* feat: disable toggle starred to maintain consistency * fix: prevent Toggle Starred and Indexes from hiding TOC
54 lines
1.2 KiB
Vue
54 lines
1.2 KiB
Vue
<script setup lang="ts">
|
|
import { onBeforeUnmount, onMounted, ref } from 'vue'
|
|
import Switch from './Switch.vue'
|
|
|
|
const isDisabled = ref(false)
|
|
const isOn = ref(false)
|
|
|
|
const syncState = () => {
|
|
const root = document.documentElement
|
|
isDisabled.value = root.classList.contains('indexes-only')
|
|
isOn.value = root.classList.contains('starred-only')
|
|
}
|
|
|
|
let observer: MutationObserver | undefined
|
|
|
|
onMounted(() =>
|
|
(observer = new MutationObserver(syncState)).observe(document.documentElement, {
|
|
attributes: true,
|
|
attributeFilter: ['class']
|
|
})
|
|
)
|
|
|
|
onMounted(syncState)
|
|
|
|
onBeforeUnmount(() => observer?.disconnect())
|
|
|
|
const toggleStarred = (value: boolean) => {
|
|
if (isDisabled.value) {
|
|
isOn.value = document.documentElement.classList.contains('starred-only')
|
|
return
|
|
}
|
|
|
|
const root = document.documentElement
|
|
root.classList.toggle('starred-only', value)
|
|
root.dataset.starredWasOn = value ? 'true' : 'false'
|
|
isOn.value = value
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<Switch
|
|
v-model="isOn"
|
|
:disabled="isDisabled"
|
|
:class="{ disabled: isDisabled }"
|
|
@update:modelValue="toggleStarred"
|
|
/>
|
|
</template>
|
|
|
|
<style>
|
|
.starred-only .vp-doc li:not(.starred) {
|
|
display: none;
|
|
}
|
|
</style>
|