2024-08-23 19:17:07 +08:00
|
|
|
import { classNames } from "@ember-decorators/component";
|
2024-08-23 07:28:28 +08:00
|
|
|
import { PLATFORM_KEY_MODIFIER } from "discourse/lib/keyboard-shortcuts";
|
|
|
|
import { translateModKey } from "discourse/lib/utilities";
|
2024-11-20 04:45:18 +08:00
|
|
|
import { i18n } from "discourse-i18n";
|
2023-10-11 02:38:59 +08:00
|
|
|
import DropdownSelectBoxComponent from "select-kit/components/dropdown-select-box";
|
2024-08-23 19:17:07 +08:00
|
|
|
import {
|
|
|
|
pluginApiIdentifiers,
|
|
|
|
selectKitOptions,
|
|
|
|
} from "select-kit/components/select-kit";
|
2020-02-03 21:22:14 +08:00
|
|
|
|
2024-08-23 19:17:07 +08:00
|
|
|
@classNames("toolbar-popup-menu-options")
|
|
|
|
@selectKitOptions({
|
|
|
|
showFullTitle: false,
|
|
|
|
filterable: false,
|
|
|
|
autoFilterable: false,
|
|
|
|
preventHeaderFocus: true,
|
|
|
|
customStyle: true,
|
|
|
|
})
|
|
|
|
@pluginApiIdentifiers("toolbar-popup-menu-options")
|
|
|
|
export default class ToolbarPopupMenuOptions extends DropdownSelectBoxComponent {
|
2020-02-03 21:22:14 +08:00
|
|
|
modifyContent(contents) {
|
|
|
|
return contents
|
|
|
|
.map((content) => {
|
|
|
|
if (content.condition) {
|
2024-08-23 07:28:28 +08:00
|
|
|
let label;
|
|
|
|
if (content.label) {
|
2024-11-20 04:45:18 +08:00
|
|
|
label = i18n(content.label);
|
2024-08-23 07:28:28 +08:00
|
|
|
if (content.shortcut) {
|
|
|
|
label += ` <kbd class="shortcut">${translateModKey(
|
2024-08-27 02:58:23 +08:00
|
|
|
PLATFORM_KEY_MODIFIER + "+" + content.shortcut
|
|
|
|
)}</kbd>`;
|
2024-08-23 07:28:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let title;
|
|
|
|
if (content.title) {
|
2024-11-20 04:45:18 +08:00
|
|
|
title = i18n(content.title);
|
2024-08-23 07:28:28 +08:00
|
|
|
if (content.shortcut) {
|
|
|
|
title += ` (${translateModKey(
|
2024-08-27 02:58:23 +08:00
|
|
|
PLATFORM_KEY_MODIFIER + "+" + content.shortcut
|
|
|
|
)})`;
|
2024-08-23 07:28:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let name = content.name;
|
|
|
|
if (!name && content.label) {
|
2024-11-20 04:45:18 +08:00
|
|
|
name = i18n(content.label);
|
2024-08-23 07:28:28 +08:00
|
|
|
}
|
|
|
|
|
2017-12-13 17:49:32 +08:00
|
|
|
return {
|
2020-02-03 21:22:14 +08:00
|
|
|
icon: content.icon,
|
2024-08-23 07:28:28 +08:00
|
|
|
label,
|
|
|
|
title,
|
|
|
|
name,
|
2024-04-05 21:35:25 +08:00
|
|
|
id: { name: content.name, action: content.action },
|
2017-12-13 17:49:32 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
})
|
2020-02-03 21:22:14 +08:00
|
|
|
.filter(Boolean);
|
2024-08-23 19:17:07 +08:00
|
|
|
}
|
|
|
|
}
|