From f4e025170e43b29be5ce25e0d6de8da372c0a048 Mon Sep 17 00:00:00 2001
From: かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com>
Date: Sat, 4 Jan 2025 15:06:03 +0900
Subject: fix(frontend/AiScript): Ui:C:selectの値が切り替わらない問題を修正
 (#15184)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* fix(frontend/AiScript): Ui:C:selectの値が切り替わらない問題を修正

* Update Changelog
---
 packages/frontend/src/components/MkAsUi.vue | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

(limited to 'packages/frontend/src/components/MkAsUi.vue')

diff --git a/packages/frontend/src/components/MkAsUi.vue b/packages/frontend/src/components/MkAsUi.vue
index e52ab5ccad..365b767bd6 100644
--- a/packages/frontend/src/components/MkAsUi.vue
+++ b/packages/frontend/src/components/MkAsUi.vue
@@ -32,7 +32,7 @@ SPDX-License-Identifier: AGPL-3.0-only
 		<template v-if="c.label" #label>{{ c.label }}</template>
 		<template v-if="c.caption" #caption>{{ c.caption }}</template>
 	</MkInput>
-	<MkSelect v-else-if="c.type === 'select'" :small="size === 'small'" :modelValue="c.default ?? null" @update:modelValue="c.onChange">
+	<MkSelect v-else-if="c.type === 'select'" :small="size === 'small'" :modelValue="valueForSelect" @update:modelValue="onSelectUpdate">
 		<template v-if="c.label" #label>{{ c.label }}</template>
 		<template v-if="c.caption" #caption>{{ c.caption }}</template>
 		<option v-for="item in c.items" :key="item.value" :value="item.value">{{ item.text }}</option>
@@ -77,8 +77,8 @@ import MkPostForm from '@/components/MkPostForm.vue';
 const props = withDefaults(defineProps<{
 	component: AsUiComponent;
 	components: Ref<AsUiComponent>[];
-	size: 'small' | 'medium' | 'large';
-	align: 'left' | 'center' | 'right';
+	size?: 'small' | 'medium' | 'large';
+	align?: 'left' | 'center' | 'right';
 }>(), {
 	size: 'medium',
 	align: 'left',
@@ -86,7 +86,7 @@ const props = withDefaults(defineProps<{
 
 const c = props.component;
 
-function g(id) {
+function g(id: string) {
 	const v = props.components.find(x => x.value.id === id)?.value;
 	if (v) return v;
 
@@ -122,13 +122,22 @@ const containerStyle = computed(() => {
 
 const valueForSwitch = ref('default' in c && typeof c.default === 'boolean' ? c.default : false);
 
-function onSwitchUpdate(v) {
+function onSwitchUpdate(v: boolean) {
 	valueForSwitch.value = v;
 	if ('onChange' in c && c.onChange) {
 		c.onChange(v as never);
 	}
 }
 
+const valueForSelect = ref('default' in c && typeof c.default !== 'boolean' ? c.default ?? null : null);
+
+function onSelectUpdate(v) {
+	valueForSelect.value = v;
+	if ('onChange' in c && c.onChange) {
+		c.onChange(v as never);
+	}
+}
+
 function openPostForm() {
 	const form = (c as AsUiPostFormButton).form;
 	if (!form) return;
-- 
cgit v1.2.3-freya

