mirror of
https://github.com/linsa-io/linsa.git
synced 2026-04-20 07:21:34 +02:00
feat(shortcut): Keyboard Navigation (#168)
* chore: remove sliding menu * feat(ui): sheet * feat: shortcut component * chore: register new shortcut component to layout * fix: react attr naming * fix: set default to false for shortcut * feat(store): keydown-manager * feat(hooks): keyboard manager * chore: use util from base for la-editor * chore: use util from base for minimal-tiptap-editor * chore(utils): keyboard * chore: use new keyboard manager * fix: uniqueness of certain component * feat: global key handler * chore: implement new key handler
This commit is contained in:
@@ -8,7 +8,5 @@ export function getOutput(editor: Editor, output: LAEditorProps["output"]) {
|
||||
return ""
|
||||
}
|
||||
|
||||
export * from "./keyboard"
|
||||
export * from "./platform"
|
||||
export * from "./isCustomNodeSelected"
|
||||
export * from "./isTextSelected"
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
import { isMacOS } from "./platform"
|
||||
|
||||
export const getShortcutKey = (key: string) => {
|
||||
const lowercaseKey = key.toLowerCase()
|
||||
const macOS = isMacOS()
|
||||
|
||||
switch (lowercaseKey) {
|
||||
case "mod":
|
||||
return macOS ? "⌘" : "Ctrl"
|
||||
case "alt":
|
||||
return macOS ? "⌥" : "Alt"
|
||||
case "shift":
|
||||
return macOS ? "⇧" : "Shift"
|
||||
default:
|
||||
return key
|
||||
}
|
||||
}
|
||||
|
||||
export const getShortcutKeys = (keys: string | string[], separator: string = "") => {
|
||||
const keyArray = Array.isArray(keys) ? keys : keys.split(/\s+/)
|
||||
const shortcutKeys = keyArray.map(getShortcutKey)
|
||||
return shortcutKeys.join(separator)
|
||||
}
|
||||
|
||||
export default { getShortcutKey, getShortcutKeys }
|
||||
@@ -1,46 +0,0 @@
|
||||
export interface NavigatorWithUserAgentData extends Navigator {
|
||||
userAgentData?: {
|
||||
brands: { brand: string; version: string }[]
|
||||
mobile: boolean
|
||||
platform: string
|
||||
getHighEntropyValues: (hints: string[]) => Promise<{
|
||||
platform: string
|
||||
platformVersion: string
|
||||
uaFullVersion: string
|
||||
}>
|
||||
}
|
||||
}
|
||||
|
||||
let isMac: boolean | undefined
|
||||
|
||||
const getPlatform = () => {
|
||||
const nav = navigator as NavigatorWithUserAgentData
|
||||
if (nav.userAgentData) {
|
||||
if (nav.userAgentData.platform) {
|
||||
return nav.userAgentData.platform
|
||||
}
|
||||
|
||||
nav.userAgentData
|
||||
.getHighEntropyValues(["platform"])
|
||||
.then(highEntropyValues => {
|
||||
if (highEntropyValues.platform) {
|
||||
return highEntropyValues.platform
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
return navigator.platform || ""
|
||||
})
|
||||
}
|
||||
|
||||
return navigator.platform || ""
|
||||
}
|
||||
|
||||
export const isMacOS = () => {
|
||||
if (isMac === undefined) {
|
||||
isMac = getPlatform().toLowerCase().includes("mac")
|
||||
}
|
||||
|
||||
return isMac
|
||||
}
|
||||
|
||||
export default isMacOS
|
||||
Reference in New Issue
Block a user