feat: Add support for keyboard shortcuts (#870)
* Add support for keyboard shortcuts.
This change introduces a Shortcut component for defining global
keyboard shortcuts from whichever component makes more sense.
This change also adds an initial set of navigation shortcuts:
- Backspace to leave a modal dialog or to go back
- g t to go to the federated timeline
- g f to go to the favorite page
- g h to go to the home page
- g n to go to the notification page
- g c to go to the community page
- s to go to the search page
These shortcuts are loaded asynchronously from _layout.html
In modal dialogs, shortcuts are also modal, to avoid strange or
overly complex behavior. This is implemented by grouping
shortcuts into scopes, and activating a separate 'modal' scope
when entering a modal dialog, so a separate set of shortcuts can
be enabled in modal dialog. Modal dialogs can be exited by
pressing 'Backspace'.
* Navigate up/down lists using keyboard shortcuts.
This change introduces keyboard shortcuts for navigating in lists and
virtual lists. j or arrow up selects the next element, k or arrow down,
the previous element. Selecting an element scrolls the list up and down,
as necessary.
This change also allows directing keyboard shortcuts to the active
element and defines the following shortcuts, for the active status:
- f to favorite or unfavorite it
- b to boost or unboost it
- r to reply to it
- o to open its thread
- x to toggle the display of a CW
- y to toggle the display of sensitive medias
This works by defining a keyboard shortcut scope for each list element.
A new component, ScrollListShortcuts, keeps track of the active element,
based on list or virtual list elements and redirects shortcuts to the
active element's scope. ScrollListShortcuts keeps the active element in
the current realm of the store, so the active element is restored when
going back to the list.
* Typing h or ? displays the list of available keyboard shortcuts.
This change introduces a new modal dialog that documents the list of
available shortcuts.
2019-01-13 18:03:29 +00:00
|
|
|
<nav id="main-nav" class="main-nav">
|
2018-03-27 16:34:29 +00:00
|
|
|
<ul class="main-nav-ul">
|
2018-05-04 04:24:10 +00:00
|
|
|
{#each $navPages as navPage (navPage.href)}
|
2018-04-11 05:51:42 +00:00
|
|
|
<li class="main-nav-li">
|
2018-05-03 04:32:43 +00:00
|
|
|
<NavItem
|
|
|
|
{page}
|
|
|
|
name={navPage.name}
|
|
|
|
href={navPage.href}
|
|
|
|
svg={navPage.svg}
|
|
|
|
label={navPage.label}
|
|
|
|
/>
|
2018-02-08 06:49:50 +00:00
|
|
|
</li>
|
2018-05-03 04:32:43 +00:00
|
|
|
{/each}
|
2018-01-06 23:51:25 +00:00
|
|
|
</ul>
|
|
|
|
</nav>
|
2019-09-21 01:53:04 +00:00
|
|
|
{#if navShortcuts}
|
|
|
|
<svelte:component this={navShortcuts}/>
|
|
|
|
{/if}
|
2018-01-06 23:51:25 +00:00
|
|
|
|
|
|
|
<style>
|
2018-01-20 20:35:38 +00:00
|
|
|
.main-nav {
|
2018-01-12 17:01:46 +00:00
|
|
|
border-bottom: 1px solid var(--nav-border);
|
|
|
|
background: var(--nav-bg);
|
2018-01-11 06:17:15 +00:00
|
|
|
position: fixed;
|
|
|
|
left: 0;
|
|
|
|
right: 0;
|
|
|
|
top: 0;
|
2019-02-07 06:24:03 +00:00
|
|
|
z-index: 100;
|
2018-11-16 08:37:28 +00:00
|
|
|
contain: content; /* see https://www.w3.org/TR/2018/CR-css-contain-1-20181108/#valdef-contain-content */
|
2018-01-06 23:51:25 +00:00
|
|
|
}
|
|
|
|
|
2018-03-27 16:34:29 +00:00
|
|
|
.main-nav-ul {
|
2018-01-06 23:51:25 +00:00
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
2018-01-07 05:05:49 +00:00
|
|
|
list-style: none;
|
|
|
|
display: flex;
|
2018-03-27 16:34:29 +00:00
|
|
|
align-items: stretch;
|
2018-01-06 23:51:25 +00:00
|
|
|
}
|
|
|
|
|
2018-03-27 16:34:29 +00:00
|
|
|
.main-nav-li {
|
|
|
|
display: flex;
|
|
|
|
}
|
|
|
|
|
2018-02-09 02:01:00 +00:00
|
|
|
@media (max-width: 991px) {
|
2018-03-27 16:34:29 +00:00
|
|
|
.main-nav-li {
|
2018-01-28 23:53:49 +00:00
|
|
|
flex: 1;
|
2018-01-07 05:05:49 +00:00
|
|
|
}
|
2018-01-28 23:53:49 +00:00
|
|
|
}
|
2018-01-07 04:44:47 +00:00
|
|
|
|
2018-01-13 07:24:05 +00:00
|
|
|
</style>
|
|
|
|
<script>
|
|
|
|
import NavItem from './NavItem'
|
feat: Add support for keyboard shortcuts (#870)
* Add support for keyboard shortcuts.
This change introduces a Shortcut component for defining global
keyboard shortcuts from whichever component makes more sense.
This change also adds an initial set of navigation shortcuts:
- Backspace to leave a modal dialog or to go back
- g t to go to the federated timeline
- g f to go to the favorite page
- g h to go to the home page
- g n to go to the notification page
- g c to go to the community page
- s to go to the search page
These shortcuts are loaded asynchronously from _layout.html
In modal dialogs, shortcuts are also modal, to avoid strange or
overly complex behavior. This is implemented by grouping
shortcuts into scopes, and activating a separate 'modal' scope
when entering a modal dialog, so a separate set of shortcuts can
be enabled in modal dialog. Modal dialogs can be exited by
pressing 'Backspace'.
* Navigate up/down lists using keyboard shortcuts.
This change introduces keyboard shortcuts for navigating in lists and
virtual lists. j or arrow up selects the next element, k or arrow down,
the previous element. Selecting an element scrolls the list up and down,
as necessary.
This change also allows directing keyboard shortcuts to the active
element and defines the following shortcuts, for the active status:
- f to favorite or unfavorite it
- b to boost or unboost it
- r to reply to it
- o to open its thread
- x to toggle the display of a CW
- y to toggle the display of sensitive medias
This works by defining a keyboard shortcut scope for each list element.
A new component, ScrollListShortcuts, keeps track of the active element,
based on list or virtual list elements and redirects shortcuts to the
active element's scope. ScrollListShortcuts keeps the active element in
the current realm of the store, so the active element is restored when
going back to the list.
* Typing h or ? displays the list of available keyboard shortcuts.
This change introduces a new modal dialog that documents the list of
available shortcuts.
2019-01-13 18:03:29 +00:00
|
|
|
import { importNavShortcuts } from '../_utils/asyncModules'
|
2018-02-08 06:49:50 +00:00
|
|
|
import { store } from '../_store/store'
|
|
|
|
|
2018-01-13 07:24:05 +00:00
|
|
|
export default {
|
2019-09-21 01:53:04 +00:00
|
|
|
async oncreate () {
|
|
|
|
const navShortcuts = await importNavShortcuts()
|
|
|
|
this.set({ navShortcuts })
|
|
|
|
},
|
2018-02-08 06:49:50 +00:00
|
|
|
store: () => store,
|
2018-01-13 07:24:05 +00:00
|
|
|
components: {
|
|
|
|
NavItem
|
feat: Add support for keyboard shortcuts (#870)
* Add support for keyboard shortcuts.
This change introduces a Shortcut component for defining global
keyboard shortcuts from whichever component makes more sense.
This change also adds an initial set of navigation shortcuts:
- Backspace to leave a modal dialog or to go back
- g t to go to the federated timeline
- g f to go to the favorite page
- g h to go to the home page
- g n to go to the notification page
- g c to go to the community page
- s to go to the search page
These shortcuts are loaded asynchronously from _layout.html
In modal dialogs, shortcuts are also modal, to avoid strange or
overly complex behavior. This is implemented by grouping
shortcuts into scopes, and activating a separate 'modal' scope
when entering a modal dialog, so a separate set of shortcuts can
be enabled in modal dialog. Modal dialogs can be exited by
pressing 'Backspace'.
* Navigate up/down lists using keyboard shortcuts.
This change introduces keyboard shortcuts for navigating in lists and
virtual lists. j or arrow up selects the next element, k or arrow down,
the previous element. Selecting an element scrolls the list up and down,
as necessary.
This change also allows directing keyboard shortcuts to the active
element and defines the following shortcuts, for the active status:
- f to favorite or unfavorite it
- b to boost or unboost it
- r to reply to it
- o to open its thread
- x to toggle the display of a CW
- y to toggle the display of sensitive medias
This works by defining a keyboard shortcut scope for each list element.
A new component, ScrollListShortcuts, keeps track of the active element,
based on list or virtual list elements and redirects shortcuts to the
active element's scope. ScrollListShortcuts keeps the active element in
the current realm of the store, so the active element is restored when
going back to the list.
* Typing h or ? displays the list of available keyboard shortcuts.
This change introduces a new modal dialog that documents the list of
available shortcuts.
2019-01-13 18:03:29 +00:00
|
|
|
},
|
|
|
|
data: () => ({
|
2019-09-21 01:53:04 +00:00
|
|
|
navShortcuts: undefined
|
feat: Add support for keyboard shortcuts (#870)
* Add support for keyboard shortcuts.
This change introduces a Shortcut component for defining global
keyboard shortcuts from whichever component makes more sense.
This change also adds an initial set of navigation shortcuts:
- Backspace to leave a modal dialog or to go back
- g t to go to the federated timeline
- g f to go to the favorite page
- g h to go to the home page
- g n to go to the notification page
- g c to go to the community page
- s to go to the search page
These shortcuts are loaded asynchronously from _layout.html
In modal dialogs, shortcuts are also modal, to avoid strange or
overly complex behavior. This is implemented by grouping
shortcuts into scopes, and activating a separate 'modal' scope
when entering a modal dialog, so a separate set of shortcuts can
be enabled in modal dialog. Modal dialogs can be exited by
pressing 'Backspace'.
* Navigate up/down lists using keyboard shortcuts.
This change introduces keyboard shortcuts for navigating in lists and
virtual lists. j or arrow up selects the next element, k or arrow down,
the previous element. Selecting an element scrolls the list up and down,
as necessary.
This change also allows directing keyboard shortcuts to the active
element and defines the following shortcuts, for the active status:
- f to favorite or unfavorite it
- b to boost or unboost it
- r to reply to it
- o to open its thread
- x to toggle the display of a CW
- y to toggle the display of sensitive medias
This works by defining a keyboard shortcut scope for each list element.
A new component, ScrollListShortcuts, keeps track of the active element,
based on list or virtual list elements and redirects shortcuts to the
active element's scope. ScrollListShortcuts keeps the active element in
the current realm of the store, so the active element is restored when
going back to the list.
* Typing h or ? displays the list of available keyboard shortcuts.
This change introduces a new modal dialog that documents the list of
available shortcuts.
2019-01-13 18:03:29 +00:00
|
|
|
})
|
2018-01-13 07:24:05 +00:00
|
|
|
}
|
feat: Add support for keyboard shortcuts (#870)
* Add support for keyboard shortcuts.
This change introduces a Shortcut component for defining global
keyboard shortcuts from whichever component makes more sense.
This change also adds an initial set of navigation shortcuts:
- Backspace to leave a modal dialog or to go back
- g t to go to the federated timeline
- g f to go to the favorite page
- g h to go to the home page
- g n to go to the notification page
- g c to go to the community page
- s to go to the search page
These shortcuts are loaded asynchronously from _layout.html
In modal dialogs, shortcuts are also modal, to avoid strange or
overly complex behavior. This is implemented by grouping
shortcuts into scopes, and activating a separate 'modal' scope
when entering a modal dialog, so a separate set of shortcuts can
be enabled in modal dialog. Modal dialogs can be exited by
pressing 'Backspace'.
* Navigate up/down lists using keyboard shortcuts.
This change introduces keyboard shortcuts for navigating in lists and
virtual lists. j or arrow up selects the next element, k or arrow down,
the previous element. Selecting an element scrolls the list up and down,
as necessary.
This change also allows directing keyboard shortcuts to the active
element and defines the following shortcuts, for the active status:
- f to favorite or unfavorite it
- b to boost or unboost it
- r to reply to it
- o to open its thread
- x to toggle the display of a CW
- y to toggle the display of sensitive medias
This works by defining a keyboard shortcut scope for each list element.
A new component, ScrollListShortcuts, keeps track of the active element,
based on list or virtual list elements and redirects shortcuts to the
active element's scope. ScrollListShortcuts keeps the active element in
the current realm of the store, so the active element is restored when
going back to the list.
* Typing h or ? displays the list of available keyboard shortcuts.
This change introduces a new modal dialog that documents the list of
available shortcuts.
2019-01-13 18:03:29 +00:00
|
|
|
</script>
|