Line data Source code
1 : <template>
2 4791 : <FormItem
3 : :id="setting.id"
4 : :item="formItem"
5 : :form-value="settingValue"
6 : @update:form-value="updateSettingValue"
7 : >
8 : <template #name-prefix>
9 : <Badge v-if="setting.id === 'Comfy.Locale'" severity="primary">
10 : <i class="icon-[lucide--languages]" />
11 : </Badge>
12 : <Tooltip v-if="setting.experimental">
13 : <TooltipTrigger as-child>
14 : <Badge severity="primary">
15 : <template #icon>
16 : <i-material-symbols:experiment-outline />
17 : </template>
18 : </Badge>
19 : </TooltipTrigger>
20 : <TooltipContent>{{ $t('g.experimental') }}</TooltipContent>
21 : </Tooltip>
22 : </template>
23 : </FormItem>
24 : </template>
25 :
26 : <script setup lang="ts">
27 : import { computed } from 'vue'
28 : import { useI18n } from 'vue-i18n'
29 :
30 : import FormItem from '@/components/common/FormItem.vue'
31 : import Badge from '@comfyorg/design-system/badge/Badge'
32 : import Tooltip from '@comfyorg/design-system/tooltip/Tooltip'
33 : import TooltipContent from '@comfyorg/design-system/tooltip/TooltipContent'
34 : import TooltipTrigger from '@comfyorg/design-system/tooltip/TooltipTrigger'
35 : import { st } from '@/i18n'
36 : import { useSettingStore } from '@/platform/settings/settingStore'
37 : import type {
38 : SettingOption,
39 : SettingParams,
40 : Settings
41 : } from '@comfyorg/settings-core/types'
42 : import { normalizeI18nKey } from '@/utils/formatUtil'
43 :
44 4724 : const props = defineProps<{
45 : setting: SettingParams
46 : }>()
47 :
48 4724 : const { t } = useI18n()
49 :
50 899 : function translateOptions(
51 : options:
52 : | (SettingOption | string)[]
53 : | ((value: unknown) => (SettingOption | string)[])
54 : ) {
55 899 : if (typeof options === 'function') {
56 0 : return translateOptions(options(settingValue.value))
57 : }
58 :
59 899 : return options.map((option) => {
60 3525 : const optionLabel = typeof option === 'string' ? option : option.text
61 3525 : const optionValue = typeof option === 'string' ? option : option.value
62 :
63 3525 : return {
64 : text: t(
65 : `settings.${normalizeI18nKey(props.setting.id)}.options.${normalizeI18nKey(optionLabel)}`,
66 : optionLabel
67 : ),
68 : value: optionValue
69 : }
70 : })
71 : }
72 :
73 4724 : const formItem = computed(() => {
74 4767 : const normalizedId = normalizeI18nKey(props.setting.id)
75 4767 : return {
76 : ...props.setting,
77 : name: t(`settings.${normalizedId}.name`, props.setting.name),
78 : tooltip: props.setting.tooltip
79 : ? st(`settings.${normalizedId}.tooltip`, props.setting.tooltip)
80 : : undefined,
81 : options: props.setting.options
82 : ? translateOptions(props.setting.options)
83 : : undefined
84 : }
85 : })
86 :
87 4724 : const settingStore = useSettingStore()
88 4724 : const settingValue = computed(() => settingStore.get(props.setting.id))
89 22 : async function updateSettingValue(newValue: unknown) {
90 22 : await settingStore.set(
91 : props.setting.id,
92 : newValue as Settings[typeof props.setting.id]
93 : )
94 : }
95 : </script>
|