File size: 6,450 Bytes
c6535db | 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 170 171 | import {createApp} from 'vue'
import PrimeVue from "primevue/config";
import { app, $el } from '@/composable/comfyAPI.js'
import {ref} from "vue";
import {useChainCallback} from "@/composable/utils/useChainCallback.js";
import {useDomWidgetStore} from "@/stores/domWidgetStore.js";
import {ComponentWidgetImpl} from "@/composable/widgets/domWidget.js";
import promptAwaitBar from "@/components/graph/widgets/promptAwait.vue";
import multiSelectWidget from "@/components/graph/widgets/multiSelectWidget.vue";
import multiAngleWidget from '@/components/graph/widgets/multiAngleWidget.vue';
import tableEditorWidget from '@/components/graph/widgets/tableEditorWidget.vue';
import stylesSelector from '@/components/graph/widgets/stylesSelector.vue';
import {getSetting} from "@/composable/settings.js";
const vueApps = new Map()
const defaultStyle = {
width: '100%',
height: '100%',
display: 'flex',
flexDirection: 'column',
overflow: 'hidden'
}
const createVueWidget = (obj, components) => {
const container = document.createElement('div')
const node = obj.node
const options = obj.options || {getMinHeight: () => 100, hideOnZoom: true, serialize: true}
const styles = obj.styles || null
container.id = `easyuse-vue-widget-${node.id}`
Object.assign(container.style, defaultStyle, styles || {})
const widget = node.addDOMWidget(
obj.name || 'ustom_vue_component_basic',
'vue-basic',
container,
options,
)
if(obj.inputSpec) widget.inputSpec = obj.inputSpec
const vueApp = createApp(components, {
widget,
node
})
vueApp.use(PrimeVue)
vueApp.mount(container)
vueApps.set(node.id, vueApp)
widget.onRemove = () => {
const vueApp = vueApps.get(node.id)
if (vueApp) {
vueApp.unmount()
vueApps.delete(node.id)
}
}
return { widget }
}
app.registerExtension({
name: 'Comfy.EasyUse.CustomWidget',
getCustomWidgets: _ => ({
EASY_PROMPT_AWAIT_BAR: (node) => {
const widgetValue = ref(JSON.stringify({
select: 'now',
unlock: true,
last_seed:0,
seed:0,
}))
const isEasyUseTheme = ['obsidian','obsidian_dark','milk_white'].includes(getSetting('Comfy.ColorPalette')) ? true : false
const height = isEasyUseTheme ? 48 : 54
return createVueWidget({
name:'toolbar',
node,
options:{
getMinHeight: () => height,
getMaxHeight: () => height,
getValue: () => widgetValue.value,
setValue: (value) => {
try{
widgetValue.value = typeof(value) == 'object' ? JSON.stringify(value) : value
}catch(e){
console.error('EASY_MULTI_ANGLE setValue error:',e)
}
}
},
},promptAwaitBar)
},
EASY_PROMPT_STYLES: (node)=> {
const widgetValue = ref('')
return createVueWidget({
name:'select_styles',
node,
options:{
getMinHeight: () => 180,
getMaxHeight: () => node.size[1] - 75,
getValue: ()=> widgetValue.value,
setValue: (value) => {
widgetValue.value = Array.isArray(value) ? value.join(',') : value
}
},
styles:{'overflow':'visible'}
}, stylesSelector)
},
EASY_COMBO: (node, inputName, inputSpec) => {
const widgetValue = ref('')
const isEasyUseTheme = ['obsidian','obsidian_dark','milk_white'].includes(getSetting('Comfy.ColorPalette')) ? true : false
const height = isEasyUseTheme ? 22 : 26
return createVueWidget({
name:'mask_components',
node,
options:{
margin: 0,
getMinHeight: () => height,
getMaxHeight: () => height,
getValue: () => widgetValue.value,
setValue: (value) => {
widgetValue.value = Array.isArray(value) ? value.join(',') : value
}
},
inputSpec: inputSpec?.[1],
styles:{'overflow':'visible'}
}, multiSelectWidget)
},
EASY_MULTI_ANGLE: (node) => {
const widgetValue = ref(JSON.stringify([{
rotate:0,
vertical:0,
zoom:5,
add_angle_prompt:true
}]))
return createVueWidget({
name:'multi_angle',
node,
options:{
getMinHeight: () => 350,
getMaxHeight: () => node.size[1] - 80,
getValue: () => widgetValue.value,
setValue: (value) => {
try{
widgetValue.value = Array.isArray(value) ? JSON.stringify(value) : value
}catch(e){
console.error('EASY_MULTI_ANGLE setValue error:',e)
}
}
},
styles:{'overflow':'visible'}
},multiAngleWidget)
},
// 表格编辑器
EASY_TABLE_EDITOR: (node, inputName, inputData, app) => {
const widgetValue = ref(JSON.stringify({
mode: 'table',
headers: ['列1', '列2', '列3'],
rows: [['', '', ''], ['', '', '']],
markdown: '| 列1 | 列2 | 列3 |\n| --- | --- | --- |\n| | | |\n| | | |',
}))
return createVueWidget({
name: 'table_data',
node,
options: {
getMinHeight: () => 200,
getMaxHeight: () => node.size[1],
getValue: () => widgetValue.value,
setValue: (value) => {
widgetValue.value = typeof value === 'object' ? JSON.stringify(value) : value
}
},
styles: { overflow: 'hidden' }
}, tableEditorWidget)
}
})
}) |