-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dirty initial model metadata load & preview
based on node preview code
- Loading branch information
1 parent
d9bae3b
commit d2cd56c
Showing
3 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
72
src/components/sidebar/tabs/modelLibrary/ModelTreeLeaf.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |