11<script setup lang="ts">
2- import type { Config } from ' fcitx5-js'
32import { NLayout , NLayoutFooter , NLayoutSider , NMenu } from ' naive-ui'
4- import { ref } from ' vue'
3+ import { computed , ref } from ' vue'
54import BasicConfig from ' ./BasicConfig.vue'
65import FooterButtons from ' ./FooterButtons.vue'
7- import { extractValue } from ' ./util '
6+ import { ConfigManager } from ' ./manager '
87
98const props = defineProps <{
109 uri: string
1110 onClose: () => void
1211}>()
1312
14- const index = ref (0 )
15- const config = {
16- Children: [],
17- ... window .fcitx .getConfig (props .uri ),
18- }
19- const options = config .Children .map ((child , i ) => ({
13+ const options = { Children: [], ... window .fcitx .getConfig (props .uri ) }.Children .map ((child , i ) => ({
2014 key: i ,
2115 label: child .Description ,
2216}))
2317
24- const collapsed = ref (false )
25-
26- function childToConfig(child : typeof config .Children [0 ]): Config {
27- return { Children: child .Children || [] }
28- }
29-
30- const form = ref (extractValue (config , false ))
31-
32- function reset() {
33- form .value [config .Children [index .value ].Option ] = extractValue (childToConfig (config .Children [index .value ]), true )
34- }
18+ const index = ref (0 )
19+ const manager = computed (() => new ConfigManager (props .uri , index .value ))
3520
36- function apply() {
37- window .fcitx .setConfig (props .uri , form .value )
38- }
21+ const collapsed = ref (false )
3922 </script >
4023
4124<template >
@@ -62,18 +45,17 @@ function apply() {
6245 style =" bottom : 50px "
6346 >
6447 <BasicConfig
65- :path =" config.Children[index] .Option"
66- :config =" childToConfig(config.Children[index]) "
67- :value =" form[config.Children[index].Option] "
48+ :path =" { Option: '', ...manager.config } .Option"
49+ :config =" manager.config "
50+ :value =" manager. form.value "
6851 style =" margin : 16px "
69- @update =" v => form[config.Children[index].Option] = v "
52+ @update =" (v) => manager.set(v) "
7053 />
7154 </NLayout >
7255 <NLayoutFooter position =" absolute" >
7356 <FooterButtons
74- :reset =" reset"
75- :apply =" apply"
76- :close =" onClose"
57+ :manager =" manager"
58+ @close =" onClose"
7759 />
7860 </NLayoutFooter >
7961 </NLayout >
0 commit comments