Skip to content

Commit

Permalink
dirty initial model metadata load & preview
Browse files Browse the repository at this point in the history
based on node preview code
  • Loading branch information
mcmonkey4eva committed Sep 17, 2024
1 parent d9bae3b commit d2cd56c
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/components/sidebar/tabs/ModelLibrarySidebarTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
</div>
</template>
</SidebarTabTemplate>
<div id="model-library-model-preview-container" />
</template>

<script setup lang="ts">
Expand Down
40 changes: 40 additions & 0 deletions src/components/sidebar/tabs/modelLibrary/ModelPreview.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<template>
<div class="model_preview">
<div class="model_preview_title">
{{ modelDef.title }}
</div>
<div class="model_preview_descript">
{{ modelDef.description }}
</div>
</div>
</template>

<script setup lang="ts">
import { ComfyModelDef } from '@/stores/modelStore'
const props = defineProps({
modelDef: {
type: ComfyModelDef,
required: true
}
})
const modelDef = props.modelDef
</script>
<style scoped>
.model_preview {
background-color: var(--comfy-menu-bg);
font-family: 'Open Sans', sans-serif;
font-size: small;
color: var(--descrip-text);
border: 1px solid var(--descrip-text);
min-width: 300px;
width: min-content;
height: fit-content;
z-index: 9999;
border-radius: 12px;
overflow: hidden;
font-size: 12px;
padding-bottom: 10px;
}
</style>
72 changes: 72 additions & 0 deletions src/components/sidebar/tabs/modelLibrary/ModelTreeLeaf.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,87 @@
<template>
<div ref="container" class="model-lib-node-container h-full w-full">
<TreeExplorerTreeNode :node="node"> </TreeExplorerTreeNode>

<teleport v-if="isHovered" to="#model-library-model-preview-container">
<div class="model-lib-model-preview" :style="modelPreviewStyle">
<ModelPreview ref="previewRef" :modelDef="modelDef"></ModelPreview>
</div>
</teleport>
</div>
</template>

<script setup lang="ts">
import TreeExplorerTreeNode from '@/components/common/TreeExplorerTreeNode.vue'
import ModelPreview from './ModelPreview.vue'
import { ComfyModelDef } from '@/stores/modelStore'
import { RenderedTreeExplorerNode } from '@/types/treeExplorerTypes'
import {
computed,
CSSProperties,
nextTick,
onMounted,
onUnmounted,
ref
} from 'vue'
import { useSettingStore } from '@/stores/settingStore'
const props = defineProps<{
node: RenderedTreeExplorerNode<ComfyModelDef>
}>()
const modelDef = computed(() => props.node.data)
const previewRef = ref<InstanceType<typeof ModelPreview> | null>(null)
const modelPreviewStyle = ref<CSSProperties>({
position: 'absolute',
top: '0px',
left: '0px'
})
const settingStore = useSettingStore()
const sidebarLocation = computed<'left' | 'right'>(() =>
settingStore.get('Comfy.Sidebar.Location')
)
const handleModelHover = async () => {
const hoverTarget = modelContentElement.value
const targetRect = hoverTarget.getBoundingClientRect()
const previewHeight = previewRef.value?.$el.offsetHeight || 0
const availableSpaceBelow = window.innerHeight - targetRect.bottom
modelPreviewStyle.value.top =
previewHeight > availableSpaceBelow
? `${Math.max(0, targetRect.top - (previewHeight - availableSpaceBelow) - 20)}px`
: `${targetRect.top - 40}px`
if (sidebarLocation.value === 'left') {
modelPreviewStyle.value.left = `${targetRect.right}px`
} else {
modelPreviewStyle.value.left = `${targetRect.left - 400}px`
}
modelDef.value.load()
}
const container = ref<HTMLElement | null>(null)
const modelContentElement = ref<HTMLElement | null>(null)
const isHovered = ref(false)
const handleMouseEnter = async () => {
isHovered.value = true
await nextTick()
handleModelHover()
}
const handleMouseLeave = () => {
isHovered.value = false
}
onMounted(() => {
modelContentElement.value = container.value?.closest('.p-tree-node-content')
modelContentElement.value?.addEventListener('mouseenter', handleMouseEnter)
modelContentElement.value?.addEventListener('mouseleave', handleMouseLeave)
})
onUnmounted(() => {
modelContentElement.value?.removeEventListener('mouseenter', handleMouseEnter)
modelContentElement.value?.removeEventListener('mouseleave', handleMouseLeave)
})
</script>

0 comments on commit d2cd56c

Please sign in to comment.