Skip to content

Commit 6176cca

Browse files
fix(frontend): MenuRadioの指定方法変更 (#17345)
* fix(frontend): MenuRadioの指定方法変更 * fix indent --------- Co-authored-by: syuilo <[email protected]>
1 parent 9569310 commit 6176cca

4 files changed

Lines changed: 73 additions & 51 deletions

File tree

packages/frontend/src/components/MkMediaAudio.vue

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,28 @@ function showMenu(ev: MouseEvent) {
182182
text: i18n.ts._mediaControls.playbackRate,
183183
icon: 'ti ti-clock-play',
184184
ref: speed,
185-
options: {
186-
'0.25x': 0.25,
187-
'0.5x': 0.5,
188-
'0.75x': 0.75,
189-
'1.0x': 1,
190-
'1.25x': 1.25,
191-
'1.5x': 1.5,
192-
'2.0x': 2,
193-
},
185+
options: [{
186+
label: '0.25x',
187+
value: 0.25,
188+
}, {
189+
label: '0.5x',
190+
value: 0.5,
191+
}, {
192+
label: '0.75x',
193+
value: 0.75,
194+
}, {
195+
label: '1.0x',
196+
value: 1,
197+
}, {
198+
label: '1.25x',
199+
value: 1.25,
200+
}, {
201+
label: '1.5x',
202+
value: 1.5,
203+
}, {
204+
label: '2.0x',
205+
value: 2,
206+
}],
194207
},
195208
{
196209
type: 'divider',

packages/frontend/src/components/MkMediaVideo.vue

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,28 @@ function showMenu(ev: PointerEvent) {
204204
text: i18n.ts._mediaControls.playbackRate,
205205
icon: 'ti ti-clock-play',
206206
ref: speed,
207-
options: {
208-
'0.25x': 0.25,
209-
'0.5x': 0.5,
210-
'0.75x': 0.75,
211-
'1.0x': 1,
212-
'1.25x': 1.25,
213-
'1.5x': 1.5,
214-
'2.0x': 2,
215-
},
207+
options: [{
208+
label: '0.25x',
209+
value: 0.25,
210+
}, {
211+
label: '0.5x',
212+
value: 0.5,
213+
}, {
214+
label: '0.75x',
215+
value: 0.75,
216+
}, {
217+
label: '1.0x',
218+
value: 1,
219+
}, {
220+
label: '1.25x',
221+
value: 1.25,
222+
}, {
223+
label: '1.5x',
224+
value: 1.5,
225+
}, {
226+
label: '2.0x',
227+
value: 2,
228+
}],
216229
},
217230
...(window.document.pictureInPictureEnabled ? [{
218231
text: i18n.ts._mediaControls.pip,

packages/frontend/src/components/MkMenu.vue

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -339,24 +339,23 @@ function onItemMouseLeave() {
339339
}
340340
341341
async function showRadioOptions(item: MenuRadio, ev: MouseEvent | PointerEvent | KeyboardEvent) {
342-
const children: MenuItem[] = Object.keys(item.options).map<MenuRadioOption>(key => {
343-
const value = item.options[key];
342+
const children: MenuItem[] = item.options.map<MenuRadioOption>(def => {
344343
return {
345344
type: 'radioOption',
346-
text: key,
345+
text: def.label,
347346
action: () => {
348347
if (isRef(item.ref)) {
349-
item.ref.value = value;
348+
item.ref.value = def.value;
350349
} else {
351350
// @ts-expect-error リアクティビティは保たれる
352-
item.ref = value;
351+
item.ref = def.value;
353352
}
354353
},
355354
active: computed(() => {
356355
if (isRef(item.ref)) {
357-
return item.ref.value === value;
356+
return item.ref.value === def.value;
358357
} else {
359-
return item.ref === value;
358+
return item.ref === def.value;
360359
}
361360
}),
362361
};
@@ -421,9 +420,14 @@ function close(actioned = false) {
421420
});
422421
}
423422
424-
function switchItem(item: MenuSwitch & { ref: any }) {
423+
function switchItem(item: MenuSwitch) {
425424
if (item.disabled !== undefined && (typeof item.disabled === 'boolean' ? item.disabled : item.disabled.value)) return;
426-
item.ref = !item.ref;
425+
if (isRef(item.ref)) {
426+
item.ref.value = !item.ref.value;
427+
} else {
428+
// @ts-expect-error リアクティビティは保たれる
429+
item.ref = !item.ref;
430+
}
427431
}
428432
429433
function focusUp() {

packages/frontend/src/types/menu.ts

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import type { OptionValue } from '@/types/option-value.js';
1010

1111
type ComponentProps<T extends Component> = { [K in keyof CP<T>]: MaybeRef<CP<T>[K]> };
1212

13-
type MenuRadioOptionsDef = Record<string, OptionValue>;
14-
1513
type Text = string | ComputedRef<string>;
1614

1715
export type MenuAction = (ev: PointerEvent) => void;
@@ -32,6 +30,12 @@ interface MenuBase {
3230
type: string;
3331
}
3432

33+
interface TextMenuBase extends MenuBase {
34+
text: Text;
35+
caption?: Text | null | undefined | ComputedRef<null | undefined>;
36+
icon?: string;
37+
}
38+
3539
export interface MenuDivider extends MenuBase {
3640
type: 'divider';
3741
}
@@ -42,24 +46,18 @@ export interface MenuLabel extends MenuBase {
4246
caption?: Text | null | undefined | ComputedRef<null | undefined>;
4347
}
4448

45-
export interface MenuLink extends MenuBase {
49+
export interface MenuLink extends TextMenuBase {
4650
type: 'link';
4751
to: string;
48-
text: Text;
49-
caption?: Text | null | undefined | ComputedRef<null | undefined>;
50-
icon?: string;
5152
indicate?: boolean;
5253
avatar?: Misskey.entities.User;
5354
}
5455

55-
export interface MenuA extends MenuBase {
56+
export interface MenuA extends TextMenuBase {
5657
type: 'a';
5758
href: string;
5859
target?: string;
5960
download?: string;
60-
text: Text;
61-
caption?: Text | null | undefined | ComputedRef<null | undefined>;
62-
icon?: string;
6361
indicate?: boolean;
6462
}
6563

@@ -71,22 +69,19 @@ export interface MenuUser extends MenuBase {
7169
action: MenuAction;
7270
}
7371

74-
export interface MenuSwitch extends MenuBase {
72+
export interface MenuSwitch extends TextMenuBase {
7573
type: 'switch';
7674
ref: Ref<boolean>;
77-
text: Text;
78-
caption?: Text | null | undefined | ComputedRef<null | undefined>;
79-
icon?: string;
8075
disabled?: boolean | Ref<boolean>;
8176
}
8277

83-
export interface MenuRadio extends MenuBase {
78+
export interface MenuRadio extends TextMenuBase {
8479
type: 'radio';
85-
text: Text;
86-
caption?: Text | null | undefined | ComputedRef<null | undefined>;
87-
icon?: string;
88-
ref: Ref<MenuRadioOptionsDef[keyof MenuRadioOptionsDef]>;
89-
options: MenuRadioOptionsDef;
80+
ref: Ref<OptionValue>;
81+
options: {
82+
label: string;
83+
value: OptionValue;
84+
}[];
9085
disabled?: boolean | Ref<boolean>;
9186
}
9287

@@ -104,11 +99,8 @@ export interface MenuComponent<T extends Component = any> extends MenuBase {
10499
props?: ComponentProps<T>;
105100
}
106101

107-
export interface MenuParent extends MenuBase {
102+
export interface MenuParent extends TextMenuBase {
108103
type: 'parent';
109-
text: Text;
110-
caption?: Text | null | undefined | ComputedRef<null | undefined>;
111-
icon?: string;
112104
children: MenuItem[] | (() => Promise<MenuItem[]> | MenuItem[]);
113105
}
114106

0 commit comments

Comments
 (0)