diff options
| author | かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com> | 2025-07-06 19:36:11 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-06 19:36:11 +0900 |
| commit | a8abb03d1785791ab40e57ab49c87640914532c9 (patch) | |
| tree | f80ea7a393a278e29f9642e86be8b341fcb4b95b /packages/frontend/src/widgets/widget.ts | |
| parent | Merge branch 'develop' of https://github.com/misskey-dev/misskey into develop (diff) | |
| download | misskey-a8abb03d1785791ab40e57ab49c87640914532c9.tar.gz misskey-a8abb03d1785791ab40e57ab49c87640914532c9.tar.bz2 misskey-a8abb03d1785791ab40e57ab49c87640914532c9.zip | |
refactor(frontend): Formまわりの型強化 (#16260)
* refactor(frontend): Formまわりの型強化
* fix
* avoid non-null assertion and add null check for safety
* refactor
* avoid non-null assertion and add null check for safety
* Update clip.vue
---------
Co-authored-by: syuilo <4439005+syuilo@users.noreply.github.com>
Diffstat (limited to 'packages/frontend/src/widgets/widget.ts')
| -rw-r--r-- | packages/frontend/src/widgets/widget.ts | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/packages/frontend/src/widgets/widget.ts b/packages/frontend/src/widgets/widget.ts index de4c369cbb..c5ca7ac26c 100644 --- a/packages/frontend/src/widgets/widget.ts +++ b/packages/frontend/src/widgets/widget.ts @@ -4,8 +4,9 @@ */ import { reactive, watch } from 'vue'; +import type { Reactive } from 'vue'; import { throttle } from 'throttle-debounce'; -import type { Form, GetFormResultType } from '@/utility/form.js'; +import type { FormWithDefault, GetFormResultType } from '@/utility/form.js'; import * as os from '@/os.js'; import { deepClone } from '@/utility/clone.js'; @@ -28,17 +29,17 @@ export type WidgetComponentExpose = { configure: () => void; }; -export const useWidgetPropsManager = <F extends Form & Record<string, { default: any; }>>( +export const useWidgetPropsManager = <F extends FormWithDefault>( name: string, propsDef: F, props: Readonly<WidgetComponentProps<GetFormResultType<F>>>, emit: WidgetComponentEmits<GetFormResultType<F>>, ): { - widgetProps: GetFormResultType<F>; + widgetProps: Reactive<GetFormResultType<F>>; save: () => void; configure: () => void; } => { - const widgetProps = reactive(props.widget ? deepClone(props.widget.data) : {}); + const widgetProps = reactive<GetFormResultType<F>>((props.widget ? deepClone(props.widget.data) : {}) as GetFormResultType<F>); const mergeProps = () => { for (const prop of Object.keys(propsDef)) { @@ -47,12 +48,13 @@ export const useWidgetPropsManager = <F extends Form & Record<string, { default: } } }; + watch(widgetProps, () => { mergeProps(); }, { deep: true, immediate: true }); const save = throttle(3000, () => { - emit('updateProps', widgetProps); + emit('updateProps', widgetProps as GetFormResultType<F>); }); const configure = async () => { |