Skip to content

Commit

Permalink
chore: reduced redundancy
Browse files Browse the repository at this point in the history
Signed-off-by: Karthik Ayangar <karthik.ayangar7118@gmail.com>
  • Loading branch information
kituuu committed Mar 8, 2024
1 parent f557f09 commit becc9dd
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 82 deletions.
51 changes: 25 additions & 26 deletions client/scss/components/_keyboard-shortcuts.scss
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
.keyboard_shortcut {
.w-keyboard-shortcuts {
width: 100%;
}

&__category {
font-size: 20px;
display: flex;
flex-direction: row;
font-weight: 400;
margin-bottom: 0.75rem;
margin-top: 1.2rem;
}
.w-keyboard-shortcuts__category {
font-size: theme('fontSize.22'); // there is no 20
display: flex;
flex-direction: row;
font-weight: theme('fontWeight.bold');
margin-bottom: theme('spacing.3');
margin-top: theme('spacing.5');
}

&__key {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
border-top: 1px solid rgb(134, 134, 134);
.w-keyboard_shortcuts__key {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
border-top: 1px solid theme('colors.grey.200');
}

th {
font-size: 16px;
font-weight: 400;
padding: 0.5rem 0;
display: flex;
flex-direction: row;
}
.w-keyboard_shortcuts__label {
font-size: theme('fontSize.16');
padding: theme('spacing.2') 0;
display: flex;
flex-direction: row;
}

td {
padding: 0.5rem 0;
}
}
.w-keyboard_shortcuts__symbol {
padding: theme('spacing.2') 0;
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
{% load wagtailadmin_tags %}
{% load wagtailadmin_tags i18n %}
{% dialog icon_name='regex' id='keyboard-shortcuts-dialog' title=_("Keyboard shortcuts") %}
{% if shortcuts%}
<table class="keyboard_shortcut">
<table class="w-keyboard-shortcuts">
<caption class="w-sr-only">
All keyboard shortcuts
{% trans "All keyboard shortcuts" %}
</caption>
<thead class="w-sr-only">
<tr>
<th scope="col">Section</th>
<th scope="col">Keyboard shortcut</th>
<th scope="col">Keyboard shortcut</th>
<th scope="col">{% trans "Section" %}</th>
<th scope="col">{% trans "Keyboard shortcut" %}</th>
</tr>
</thead>

{% for category, shortcuts in shortcuts.items %}
<tbody class="w-w-full">
<tbody class="w-w-full" id="keyboard-shortut-group-{{ category.0 }}">
<tr colspan="2">
<th class="keyboard_shortcut__category" scope="rowgroup">{{ category }}</th>
<th class="w-keyboard-shortcuts__category" scope="rowgroup">{{ category.1 }}</th>
</tr>
{% for shortcut in shortcuts %}
<tr class="keyboard_shortcut__key">
<th scope="row">{{ shortcut.Label }}</th>
<td><kbd>{{ shortcut.Shortcut }}</kbd></td>
<tr class="w-keyboard_shortcuts__key ">
<th class="w-keyboard_shortcuts__label" scope="row">{{ shortcut.label }}</th>
<td class="w-keyboard_shortcuts__symbol"><kbd>{{ shortcut.shortcut }}</kbd></td>
</tr>
{% endfor %}
</tbody>
{% endfor %}
</table>
{% endif%}
{% enddialog %}
{% enddialog %}
55 changes: 28 additions & 27 deletions wagtail/admin/templatetags/wagtailadmin_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -1308,46 +1308,47 @@ def workflow_status_with_date(workflow_state):
def keyboard_shortcuts_dialog(context):
user_agent = context["request"].headers.get("User-Agent", "")
is_mac = re.search(r"Mac|iPod|iPhone|iPad", user_agent)
shortcuts_category = {
"Actions": [
{"Label": "Save", "Shortcut": ("⌘" if is_mac else "Ctrl") + " + s"},
{"Label": "Preview", "Shortcut": ("⌘" if is_mac else "Ctrl") + " + p"},
],
"Common actions": [
{"Label": "Copy", "Shortcut": ("⌘" if is_mac else "Ctrl") + " + c"},
{"Label": "Cut", "Shortcut": ("⌘" if is_mac else "Ctrl") + " + x"},
{"Label": "Paste", "Shortcut": ("⌘" if is_mac else "Ctrl") + " + v"},
modifier = "⌘" if is_mac else "Ctrl"
shortcuts = {
("common-actions", _("Common Actions")): [
{"label": _("Copy"), "shortcut": f"{modifier} + c"},
{"label": _("Cut"), "shortcut": f"{modifier} + x"},
{"label": _("Paste"), "shortcut": f"{modifier} + v"},
{
"Label": "Paste without formatting",
"Shortcut": ("⌘" if is_mac else "Ctrl") + " + shift + v",
"label": _("Paste without formatting"),
"shortcut": f"{modifier} + shift + v",
},
{"Label": "Undo", "Shortcut": ("⌘" if is_mac else "Ctrl") + " + z"},
{"Label": "Redo", "Shortcut": ("⌘" if is_mac else "Ctrl") + " + y"},
{"label": _("Undo"), "shortcut": f"{modifier} + z"},
{"label": _("Redo"), "shortcut": f"{modifier} + y"},
],
("page-editing-actions", _("Page editing actions")): [
{"label": _("Save"), "shortcut": f"{modifier} + s"},
{"label": _("Preview"), "shortcut": f"{modifier} + p"},
],
"Text formatting": [
{"Label": "Bold", "Shortcut": ("⌘" if is_mac else "Ctrl") + " + b"},
{"Label": "Italic", "Shortcut": ("⌘" if is_mac else "Ctrl") + " + i"},
{"Label": "Underline", "Shortcut": ("⌘" if is_mac else "Ctrl") + " + u"},
("text-formatting", _("Text Formatting")): [
{"label": _("Bold"), "shortcut": f"{modifier} + b"},
{"label": _("Italic"), "shortcut": f"{modifier} + i"},
{"label": _("Underline"), "shortcut": f"{modifier} + u"},
{
"Label": "Monospace (code)",
"Shortcut": ("⌘" if is_mac else "Ctrl") + " + j",
"label": _("Monospace (code)"),
"shortcut": f"{modifier} + j",
},
{
"Label": "Strike-through",
"Shortcut": ("⌘" if is_mac else "Ctrl") + " + x",
"label": _("Strike-through"),
"shortcut": f"{modifier} + x",
},
{"Label": "Superscript", "Shortcut": ("⌘" if is_mac else "Ctrl") + " + ."},
{"Label": "Subscript", "Shortcut": ("⌘" if is_mac else "Ctrl") + " + ,"},
{"label": _("Superscript"), "shortcut": f"{modifier} + ."},
{"label": _("Subscript"), "shortcut": f"{modifier} + ,"},
],
"Text content": [
("text-content", _("Text Content")): [
{
"Label": "Insert or edit a link",
"Shortcut": ("⌘" if is_mac else "Ctrl") + "+ k",
"label": _("Insert or edit a link"),
"shortcut": f"{modifier} + k",
}
],
}
return {
"shortcuts": shortcuts_category,
"shortcuts": shortcuts,
}


Expand Down
34 changes: 17 additions & 17 deletions wagtail/admin/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,6 @@ def render_component(self, request):
return super().render_component(request)


@hooks.register("register_help_menu_item")
def register_keyboard_shortcuts_menu_item():
return MenuItem(
_("Shortcuts"),
icon_name="regex",
order=1200,
attrs={
"role": "button",
"data-a11y-dialog-show": "keyboard-shortcuts-dialog",
"data-action": "w-action#noop:prevent:stop",
"data-controller": "w-action",
},
name="keyboard-shortcuts-trigger",
url="#",
)


@hooks.register("register_admin_menu_item")
def register_explorer_menu_item():
return ExplorerMenuItem(
Expand Down Expand Up @@ -1015,6 +998,23 @@ def register_editors_guide_menu_item():
)


@hooks.register("register_help_menu_item")
def register_keyboard_shortcuts_menu_item():
return MenuItem(
_("Shortcuts"),
icon_name="regex",
order=1200,
attrs={
"role": "button",
"data-a11y-dialog-show": "keyboard-shortcuts-dialog",
"data-action": "w-action#noop:prevent:stop",
"data-controller": "w-action",
},
name="keyboard-shortcuts-trigger",
url="#",
)


@hooks.register("register_admin_menu_item")
def register_help_menu():
return DismissibleSubmenuMenuItem(
Expand Down

0 comments on commit becc9dd

Please sign in to comment.