All files / src/components/u-toc.vue item.vue

28.84% Statements 15/52
4.16% Branches 2/48
9.09% Functions 1/11
30% Lines 15/50

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169      7x   7x     7x                                                                     7x                                                                                                                                                                                                                                   7x       7x 7x            
<template>
<div :class="$style.root">
    <a
        :class="$style.link"
        :selected="selected"
        :readonly="parentVM.readonly"
        :disabled="disabled || parentVM.disabled"
        :href="!disabled && anchorJumped"
        :target="target"
        v-on="listeners"
        v-ellipsis-title
        :value="value"
        @click.stop="handleClick($event)"
    >
        <span vusion-slot-name="label">
            <s-empty v-if="(!$slots.label) && $env.VUE_APP_DESIGNER "></s-empty>
            <slot name="label">{{ label }}</slot>
        </span>
    </a>
    <div :class="$style.sub">
        <slot></slot>
    </div>
</div>
</template>
 
<script>
import { MSinglexItem } from '../m-singlex.vue';
import SEmpty from '../s-empty.vue';
 
export const UTocItem = {
    name: 'u-toc-item',
    parentName: 'u-toc',
    extends: MSinglexItem,
    components: {
        SEmpty,
    },
    props: {
        value: null,
        label: { type: String, default: '' },
        anchorLinked: { type: String, default: '' },
        hrefAndTo: { type: String, default: '' },
        target: { type: String, default: '' },
        disabled: { type: Boolean, default: false },
    },
    computed: {
        listeners() {
            const listeners = Object.assign({}, this.$listeners);
            delete listeners.click;
            return listeners;
        },
        selected() {
            if (this.isSelected && !this.active) {
                return this.isSelected;
            } else if (!this.isSelected && this.active) {
                return false;
            }
            return this.parentVM && this.parentVM.router ? this.active : this.isSelected;
        },
        anchorJumped() {
            if (this.anchorLinked) {
                return `${this.hrefAndTo}#${this.anchorLinked}`;
            } else if (this.hrefAndTo) {
                return this.hrefAndTo;
            }
            return this.currentHref;
        },
    },
    watch: {
        active(active) {
            this.watchActive(active);
        },
    },
    mounted() {
        this.watchActive(this.active);
    },
    methods: {
        watchActive(active) {
            // active && this.groupVM && this.groupVM.toggle(true);
            if (active && this.parentVM) {
                this.parentVM.setActive(this);
                this.parentVM.stopScrollSpy(this);
            }
        },
        async handleClick(e) {
            if (this.disabled || this.readonly || this.parentVM.disabled || this.parentVM.readonly)
                return;
            this.parentVM.select(this);
            const actualValue = this.value || this.label;
            const oldValue = this.value;
            const oldVM = this.selectedVM;
            this.$emit('click', {
                value: actualValue,
                node: this.node,
                oldNode: oldVM && oldVM.node,
                nodeVM: this,
                oldVM,
            }, this);
            if (this.link) {
                const res = await this.$linkpao(this.link, this.target);
                if (res) {
                    e.preventDefault();
                }
            }
        },
    },
};
 
export default UTocItem;
</script>
 
<style module>
.root {
    position: relative;
    display: block;
    cursor: var(--cursor-pointer);
}

.root::before {
    content: '';
    display: block;
    position: absolute;
    width: var(--toc-item-circle-size);
    height: var(--toc-item-circle-size);
    left: -13px;
    top: 9px;
    border-radius: 100px;
    background: var(--toc-border-color);
}
 
.root .root::before {
    display: none;
}

.link {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
 
.link:hover {
    color: var(--brand-primary);
}

.link[readonly] {
    cursor: default;
    background: none;
}
 
.link[selected] {
    color: var(--brand-primary);
}
 
.link[disabled] {
    /* @Private */
    cursor: var(--cursor-not-allowed);
    background: none;
    color: var(--color-light);
}
 
.link[selected][disabled] {
    background: var(--gray-lighter);
}

.sub {
    padding-left: 1em;
}
</style>