|
|
@@ -1,6 +1,7 @@
|
|
|
<template>
|
|
|
<div class="l-flex__none l-flex--col c-tree-node">
|
|
|
<div
|
|
|
+ v-if="isInView"
|
|
|
class="l-flex--row c-tree-node__content u-pointer"
|
|
|
:class="{ selected }"
|
|
|
@click="onToggle"
|
|
|
@@ -21,11 +22,8 @@
|
|
|
/>
|
|
|
<span class="l-flex__fill c-sibling-item near u-ellipsis">{{ node.name }}</span>
|
|
|
</div>
|
|
|
- <template v-if="!isLeaf">
|
|
|
- <div
|
|
|
- v-show="expand"
|
|
|
- class="l-flex--col c-tree-node__sub"
|
|
|
- >
|
|
|
+ <template v-if="!isLeaf && expand">
|
|
|
+ <div class="l-flex--col c-tree-node__sub">
|
|
|
<div
|
|
|
v-if="nodeCount === 0"
|
|
|
class="c-tree-node__empty u-color--info dark"
|
|
|
@@ -55,7 +53,8 @@ export default {
|
|
|
},
|
|
|
data () {
|
|
|
return {
|
|
|
- expand: !!this.tree?.defaultExpand,
|
|
|
+ isInView: false,
|
|
|
+ expand: this.node.children ? !!this.tree?.expandOnInit : false,
|
|
|
selected: false
|
|
|
}
|
|
|
},
|
|
|
@@ -82,7 +81,37 @@ export default {
|
|
|
return false
|
|
|
}
|
|
|
},
|
|
|
+ watch: {
|
|
|
+ 'tree.expandOnInit' (val) {
|
|
|
+ if (!this.isLeaf && val) {
|
|
|
+ this.expand = val
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ mounted () {
|
|
|
+ this.observe(this.$el)
|
|
|
+ },
|
|
|
+ beforeDestroy () {
|
|
|
+ this.$observer?.disconnect()
|
|
|
+ this.$observer = null
|
|
|
+ },
|
|
|
methods: {
|
|
|
+ observe () {
|
|
|
+ if (!this.$observer) {
|
|
|
+ this.$observer = new IntersectionObserver(entries => {
|
|
|
+ entries.forEach(entry => {
|
|
|
+ if (entry.isIntersecting) {
|
|
|
+ this.isInView = true
|
|
|
+ } else {
|
|
|
+ this.isInView = false
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }, {
|
|
|
+ threshold: [0.25]
|
|
|
+ })
|
|
|
+ }
|
|
|
+ this.$observer.observe(this.$el)
|
|
|
+ },
|
|
|
onToggle () {
|
|
|
if (this.isLeaf) {
|
|
|
this.tree.clickNode(this.node, this)
|
|
|
@@ -105,6 +134,7 @@ export default {
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
.c-tree-node {
|
|
|
+ min-height: $padding--xs * 2 + $font-size--sm;
|
|
|
line-height: 1;
|
|
|
|
|
|
&__content {
|