DEV: Update keyboard shortcuts to glimmer and new modal api (#22422)
This commit is contained in:
parent
1e26a521c2
commit
d458ca154c
|
@ -0,0 +1,27 @@
|
||||||
|
<DModal
|
||||||
|
@title={{i18n "keyboard_shortcuts_help.title"}}
|
||||||
|
@closeModal={{@closeModal}}
|
||||||
|
class="keyboard-shortcuts-modal"
|
||||||
|
>
|
||||||
|
<:body>
|
||||||
|
<div id="keyboard-shortcuts-help">
|
||||||
|
<div class="keyboard-shortcuts-help__container">
|
||||||
|
{{#each-in this.shortcuts as |category shortcutCategory|}}
|
||||||
|
<section
|
||||||
|
class="shortcut-category span-{{shortcutCategory.count}}
|
||||||
|
shortcut-category-{{category}}"
|
||||||
|
>
|
||||||
|
<h4>{{i18n
|
||||||
|
(concat "keyboard_shortcuts_help." category ".title")
|
||||||
|
}}</h4>
|
||||||
|
<ul>
|
||||||
|
{{#each-in shortcutCategory.shortcuts as |name shortcut|}}
|
||||||
|
<li>{{html-safe shortcut}}</li>
|
||||||
|
{{/each-in}}
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
{{/each-in}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</:body>
|
||||||
|
</DModal>
|
|
@ -1,8 +1,8 @@
|
||||||
import Controller from "@ember/controller";
|
import Component from "@glimmer/component";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import { translateModKey } from "discourse/lib/utilities";
|
import { translateModKey } from "discourse/lib/utilities";
|
||||||
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
|
||||||
import { extraKeyboardShortcutsHelp } from "discourse/lib/keyboard-shortcuts";
|
import { extraKeyboardShortcutsHelp } from "discourse/lib/keyboard-shortcuts";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
const KEY = "keyboard_shortcuts_help";
|
const KEY = "keyboard_shortcuts_help";
|
||||||
const SHIFT = I18n.t("shortcut_modifier_key.shift");
|
const SHIFT = I18n.t("shortcut_modifier_key.shift");
|
||||||
|
@ -59,17 +59,10 @@ function buildShortcut(
|
||||||
return I18n.t(`${KEY}.${key}`, context);
|
return I18n.t(`${KEY}.${key}`, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Controller.extend(ModalFunctionality, {
|
export default class KeyboardShortcutsHelp extends Component {
|
||||||
onShow() {
|
@service currentUser;
|
||||||
this.set("modal.modalClass", "keyboard-shortcuts-modal");
|
|
||||||
this._defineShortcuts();
|
|
||||||
},
|
|
||||||
|
|
||||||
onClose() {
|
get shortcuts() {
|
||||||
this.set("shortcuts", null);
|
|
||||||
},
|
|
||||||
|
|
||||||
_defineShortcuts() {
|
|
||||||
let shortcuts = {
|
let shortcuts = {
|
||||||
jump_to: { shortcuts: this._buildJumpToSection() },
|
jump_to: { shortcuts: this._buildJumpToSection() },
|
||||||
application: {
|
application: {
|
||||||
|
@ -248,8 +241,8 @@ export default Controller.extend(ModalFunctionality, {
|
||||||
};
|
};
|
||||||
this._buildExtraShortcuts(shortcuts);
|
this._buildExtraShortcuts(shortcuts);
|
||||||
this._addCountsToShortcutCategories(shortcuts);
|
this._addCountsToShortcutCategories(shortcuts);
|
||||||
this.set("shortcuts", shortcuts);
|
return shortcuts;
|
||||||
},
|
}
|
||||||
|
|
||||||
_buildExtraShortcuts(shortcuts) {
|
_buildExtraShortcuts(shortcuts) {
|
||||||
for (const [category, helps] of Object.entries(
|
for (const [category, helps] of Object.entries(
|
||||||
|
@ -270,7 +263,7 @@ export default Controller.extend(ModalFunctionality, {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
_addCountsToShortcutCategories(shortcuts) {
|
_addCountsToShortcutCategories(shortcuts) {
|
||||||
for (const [category, shortcutCategory] of Object.entries(shortcuts)) {
|
for (const [category, shortcutCategory] of Object.entries(shortcuts)) {
|
||||||
|
@ -278,7 +271,7 @@ export default Controller.extend(ModalFunctionality, {
|
||||||
shortcutCategory.shortcuts
|
shortcutCategory.shortcuts
|
||||||
).length;
|
).length;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
_transformExtraDefinition(definition) {
|
_transformExtraDefinition(definition) {
|
||||||
if (definition.keys1) {
|
if (definition.keys1) {
|
||||||
|
@ -300,7 +293,7 @@ export default Controller.extend(ModalFunctionality, {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return definition;
|
return definition;
|
||||||
},
|
}
|
||||||
|
|
||||||
_translateKeys(string) {
|
_translateKeys(string) {
|
||||||
for (const [matcher, replacement] of Object.entries(
|
for (const [matcher, replacement] of Object.entries(
|
||||||
|
@ -309,7 +302,7 @@ export default Controller.extend(ModalFunctionality, {
|
||||||
string = string.replace(matcher, replacement);
|
string = string.replace(matcher, replacement);
|
||||||
}
|
}
|
||||||
return string;
|
return string;
|
||||||
},
|
}
|
||||||
|
|
||||||
_buildJumpToSection() {
|
_buildJumpToSection() {
|
||||||
const shortcuts = {
|
const shortcuts = {
|
||||||
|
@ -333,5 +326,5 @@ export default Controller.extend(ModalFunctionality, {
|
||||||
previous: buildShortcut("jump_to.previous", { keys1: ["g", "k"] }),
|
previous: buildShortcut("jump_to.previous", { keys1: ["g", "k"] }),
|
||||||
});
|
});
|
||||||
return shortcuts;
|
return shortcuts;
|
||||||
},
|
}
|
||||||
});
|
}
|
|
@ -13,6 +13,7 @@ import mobile from "discourse/lib/mobile";
|
||||||
import { inject as service } from "@ember/service";
|
import { inject as service } from "@ember/service";
|
||||||
import { setting } from "discourse/lib/computed";
|
import { setting } from "discourse/lib/computed";
|
||||||
import showModal from "discourse/lib/show-modal";
|
import showModal from "discourse/lib/show-modal";
|
||||||
|
import KeyboardShortcutsHelp from "discourse/components/modal/keyboard-shortcuts-help";
|
||||||
|
|
||||||
function unlessReadOnly(method, message) {
|
function unlessReadOnly(method, message) {
|
||||||
return function () {
|
return function () {
|
||||||
|
@ -146,9 +147,7 @@ const ApplicationRoute = DiscourseRoute.extend(OpenComposer, {
|
||||||
},
|
},
|
||||||
|
|
||||||
showKeyboardShortcutsHelp() {
|
showKeyboardShortcutsHelp() {
|
||||||
showModal("keyboard-shortcuts-help", {
|
this.modal.show(KeyboardShortcutsHelp);
|
||||||
title: "keyboard_shortcuts_help.title",
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Close the current modal, and destroy its state.
|
// Close the current modal, and destroy its state.
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
<DModalBody @id="keyboard-shortcuts-help">
|
|
||||||
<div class="keyboard-shortcuts-help__container">
|
|
||||||
{{#each-in this.shortcuts as |category shortcutCategory|}}
|
|
||||||
<section
|
|
||||||
class="shortcut-category span-{{shortcutCategory.count}}
|
|
||||||
shortcut-category-{{category}}"
|
|
||||||
>
|
|
||||||
<h4>{{i18n (concat "keyboard_shortcuts_help." category ".title")}}</h4>
|
|
||||||
<ul>
|
|
||||||
{{#each-in shortcutCategory.shortcuts as |name shortcut|}}
|
|
||||||
<li>{{html-safe shortcut}}</li>
|
|
||||||
{{/each-in}}
|
|
||||||
</ul>
|
|
||||||
</section>
|
|
||||||
{{/each-in}}
|
|
||||||
</div>
|
|
||||||
</DModalBody>
|
|
Loading…
Reference in New Issue