@witchcraft/spellcraft 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +579 -0
- package/dist/core/EmulatedEvent.d.ts +10 -0
- package/dist/core/EmulatedEvent.js +19 -0
- package/dist/core/Emulator.d.ts +74 -0
- package/dist/core/Emulator.js +153 -0
- package/dist/core/ShortcutManagerManager.d.ts +103 -0
- package/dist/core/ShortcutManagerManager.js +267 -0
- package/dist/core/addCommand.d.ts +7 -0
- package/dist/core/addCommand.js +7 -0
- package/dist/core/addKey.d.ts +7 -0
- package/dist/core/addKey.js +7 -0
- package/dist/core/addShortcut.d.ts +7 -0
- package/dist/core/addShortcut.js +7 -0
- package/dist/core/attach.d.ts +10 -0
- package/dist/core/attach.js +13 -0
- package/dist/core/createCommand.d.ts +4 -0
- package/dist/core/createCommand.js +11 -0
- package/dist/core/createCommands.d.ts +11 -0
- package/dist/core/createCommands.js +20 -0
- package/dist/core/createCondition.d.ts +7 -0
- package/dist/core/createCondition.js +11 -0
- package/dist/core/createContext.d.ts +2 -0
- package/dist/core/createContext.js +8 -0
- package/dist/core/createKey.d.ts +10 -0
- package/dist/core/createKey.js +35 -0
- package/dist/core/createKeys.d.ts +5 -0
- package/dist/core/createKeys.js +36 -0
- package/dist/core/createManager.d.ts +81 -0
- package/dist/core/createManager.js +83 -0
- package/dist/core/createManagerEventListeners.d.ts +4 -0
- package/dist/core/createManagerEventListeners.js +130 -0
- package/dist/core/createManagerOptions.d.ts +8 -0
- package/dist/core/createManagerOptions.js +17 -0
- package/dist/core/createShortcut.d.ts +8 -0
- package/dist/core/createShortcut.js +24 -0
- package/dist/core/createShortcuts.d.ts +13 -0
- package/dist/core/createShortcuts.js +20 -0
- package/dist/core/detach.d.ts +10 -0
- package/dist/core/detach.js +6 -0
- package/dist/core/index.d.ts +32 -0
- package/dist/core/index.js +32 -0
- package/dist/core/removeCommand.d.ts +7 -0
- package/dist/core/removeCommand.js +7 -0
- package/dist/core/removeKey.d.ts +7 -0
- package/dist/core/removeKey.js +7 -0
- package/dist/core/removeShortcut.d.ts +7 -0
- package/dist/core/removeShortcut.js +7 -0
- package/dist/core/setCommandProp.d.ts +17 -0
- package/dist/core/setCommandProp.js +96 -0
- package/dist/core/setCommandsProp.d.ts +15 -0
- package/dist/core/setCommandsProp.js +94 -0
- package/dist/core/setKeyProp.d.ts +16 -0
- package/dist/core/setKeyProp.js +47 -0
- package/dist/core/setKeysProp.d.ts +10 -0
- package/dist/core/setKeysProp.js +166 -0
- package/dist/core/setManagerProp.d.ts +34 -0
- package/dist/core/setManagerProp.js +54 -0
- package/dist/core/setShortcutProp.d.ts +9 -0
- package/dist/core/setShortcutProp.js +50 -0
- package/dist/core/setShortcutsProp.d.ts +12 -0
- package/dist/core/setShortcutsProp.js +93 -0
- package/dist/defaults/KeysSorter.d.ts +35 -0
- package/dist/defaults/KeysSorter.js +20 -0
- package/dist/defaults/Stringifier.d.ts +66 -0
- package/dist/defaults/Stringifier.js +119 -0
- package/dist/defaults/defaultConditionEquals.d.ts +19 -0
- package/dist/defaults/defaultConditionEquals.js +5 -0
- package/dist/defaults/defaultManagerCallback.d.ts +7 -0
- package/dist/defaults/defaultManagerCallback.js +5 -0
- package/dist/helpers/KnownError.d.ts +8 -0
- package/dist/helpers/KnownError.js +3 -0
- package/dist/helpers/calculateAndSetPositionAndWidth.d.ts +13 -0
- package/dist/helpers/calculateAndSetPositionAndWidth.js +18 -0
- package/dist/helpers/calculateLayoutSize.d.ts +9 -0
- package/dist/helpers/calculateLayoutSize.js +13 -0
- package/dist/helpers/doesShortcutConflict.d.ts +18 -0
- package/dist/helpers/doesShortcutConflict.js +42 -0
- package/dist/helpers/equalsCommand.d.ts +7 -0
- package/dist/helpers/equalsCommand.js +4 -0
- package/dist/helpers/equalsContext.d.ts +7 -0
- package/dist/helpers/equalsContext.js +19 -0
- package/dist/helpers/equalsShortcut.d.ts +9 -0
- package/dist/helpers/equalsShortcut.js +7 -0
- package/dist/helpers/forceClear.d.ts +12 -0
- package/dist/helpers/forceClear.js +16 -0
- package/dist/helpers/forceUpdateNativeKeysState.d.ts +5 -0
- package/dist/helpers/forceUpdateNativeKeysState.js +4 -0
- package/dist/helpers/generateKeyShortcutMap.d.ts +23 -0
- package/dist/helpers/generateKeyShortcutMap.js +64 -0
- package/dist/helpers/getKeyFromEventCode.d.ts +15 -0
- package/dist/helpers/getKeyFromEventCode.js +36 -0
- package/dist/helpers/getKeyFromIdOrVariant.d.ts +4 -0
- package/dist/helpers/getKeyFromIdOrVariant.js +26 -0
- package/dist/helpers/getKeyboardLayoutMap.d.ts +5 -0
- package/dist/helpers/getKeyboardLayoutMap.js +7 -0
- package/dist/helpers/getLabel.d.ts +9 -0
- package/dist/helpers/getLabel.js +6 -0
- package/dist/helpers/getTriggerableShortcut.d.ts +6 -0
- package/dist/helpers/getTriggerableShortcut.js +25 -0
- package/dist/helpers/index.d.ts +28 -0
- package/dist/helpers/index.js +28 -0
- package/dist/helpers/isValidManager.d.ts +3 -0
- package/dist/helpers/isValidManager.js +20 -0
- package/dist/helpers/isValidShortcut.d.ts +3 -0
- package/dist/helpers/isValidShortcut.js +10 -0
- package/dist/helpers/labelWithEvent.d.ts +13 -0
- package/dist/helpers/labelWithEvent.js +20 -0
- package/dist/helpers/labelWithKeyboardMap.d.ts +15 -0
- package/dist/helpers/labelWithKeyboardMap.js +17 -0
- package/dist/helpers/managerToStorableClone.d.ts +12 -0
- package/dist/helpers/managerToStorableClone.js +13 -0
- package/dist/helpers/onKeyboardLayoutChange.d.ts +10 -0
- package/dist/helpers/onKeyboardLayoutChange.js +7 -0
- package/dist/helpers/safeSetManagerChain.d.ts +20 -0
- package/dist/helpers/safeSetManagerChain.js +37 -0
- package/dist/helpers/shortcutCanExecuteIn.d.ts +4 -0
- package/dist/helpers/shortcutCanExecuteIn.js +9 -0
- package/dist/helpers/shortcutIsTriggerableBy.d.ts +2 -0
- package/dist/helpers/shortcutIsTriggerableBy.js +5 -0
- package/dist/helpers/shortcutSwapChords.d.ts +75 -0
- package/dist/helpers/shortcutSwapChords.js +118 -0
- package/dist/helpers/virtualPress.d.ts +13 -0
- package/dist/helpers/virtualPress.js +15 -0
- package/dist/helpers/virtualRelease.d.ts +5 -0
- package/dist/helpers/virtualRelease.js +15 -0
- package/dist/helpers/virtualToggle.d.ts +7 -0
- package/dist/helpers/virtualToggle.js +16 -0
- package/dist/internal/addToChain.d.ts +3 -0
- package/dist/internal/addToChain.js +27 -0
- package/dist/internal/areValidKeys.d.ts +7 -0
- package/dist/internal/areValidKeys.js +28 -0
- package/dist/internal/areValidVariants.d.ts +4 -0
- package/dist/internal/areValidVariants.js +45 -0
- package/dist/internal/checkTrigger.d.ts +2 -0
- package/dist/internal/checkTrigger.js +47 -0
- package/dist/internal/checkUntrigger.d.ts +2 -0
- package/dist/internal/checkUntrigger.js +18 -0
- package/dist/internal/cloneLastChord.d.ts +4 -0
- package/dist/internal/cloneLastChord.js +5 -0
- package/dist/internal/containsPossibleToggleChords.d.ts +13 -0
- package/dist/internal/containsPossibleToggleChords.js +65 -0
- package/dist/internal/errorTextAdd.d.ts +1 -0
- package/dist/internal/errorTextAdd.js +11 -0
- package/dist/internal/errorTextInUse.d.ts +1 -0
- package/dist/internal/errorTextInUse.js +8 -0
- package/dist/internal/errorTextRemove.d.ts +1 -0
- package/dist/internal/errorTextRemove.js +8 -0
- package/dist/internal/getModifierState.d.ts +2 -0
- package/dist/internal/getModifierState.js +7 -0
- package/dist/internal/getPressedKeys.d.ts +7 -0
- package/dist/internal/getPressedKeys.js +18 -0
- package/dist/internal/getPressedModifierKeys.d.ts +2 -0
- package/dist/internal/getPressedModifierKeys.js +10 -0
- package/dist/internal/getPressedNonModifierKeys.d.ts +7 -0
- package/dist/internal/getPressedNonModifierKeys.js +11 -0
- package/dist/internal/inChain.d.ts +5 -0
- package/dist/internal/inChain.js +14 -0
- package/dist/internal/isValidChain.d.ts +10 -0
- package/dist/internal/isValidChain.js +22 -0
- package/dist/internal/isValidChord.d.ts +11 -0
- package/dist/internal/isValidChord.js +59 -0
- package/dist/internal/isValidCommand.d.ts +12 -0
- package/dist/internal/isValidCommand.js +20 -0
- package/dist/internal/keyOrder.d.ts +6 -0
- package/dist/internal/keyOrder.js +14 -0
- package/dist/internal/removeFromChain.d.ts +3 -0
- package/dist/internal/removeFromChain.js +32 -0
- package/dist/internal/safeSetEmulatedToggleState.d.ts +4 -0
- package/dist/internal/safeSetEmulatedToggleState.js +13 -0
- package/dist/internal/setKeysState.d.ts +8 -0
- package/dist/internal/setKeysState.js +42 -0
- package/dist/internal/updateNativeKeysState.d.ts +14 -0
- package/dist/internal/updateNativeKeysState.js +58 -0
- package/dist/layouts/createLayout.d.ts +25 -0
- package/dist/layouts/createLayout.js +221 -0
- package/dist/module.d.mts +13 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +40 -0
- package/dist/runtime/composables/useLabeledByKeyboardLayoutMap.d.ts +9 -0
- package/dist/runtime/composables/useLabeledByKeyboardLayoutMap.js +19 -0
- package/dist/runtime/composables/usePointerCoords.d.ts +32 -0
- package/dist/runtime/composables/usePointerCoords.js +17 -0
- package/dist/runtime/composables/useShortcutManagerContextCount.d.ts +14 -0
- package/dist/runtime/composables/useShortcutManagerContextCount.js +61 -0
- package/dist/runtime/composables/useShortcutManagerKeysLayout.d.ts +18 -0
- package/dist/runtime/composables/useShortcutManagerKeysLayout.js +22 -0
- package/dist/runtime/composables/useShortcutManagerVirtualPress.d.ts +6 -0
- package/dist/runtime/composables/useShortcutManagerVirtualPress.js +24 -0
- package/dist/runtime/types.d.ts +10 -0
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/utils/shortcutToId.d.ts +5 -0
- package/dist/runtime/utils/shortcutToId.js +6 -0
- package/dist/types/commands.d.ts +113 -0
- package/dist/types/commands.js +0 -0
- package/dist/types/condition.d.ts +29 -0
- package/dist/types/condition.js +0 -0
- package/dist/types/context.d.ts +18 -0
- package/dist/types/context.js +0 -0
- package/dist/types/enums.d.ts +186 -0
- package/dist/types/enums.js +70 -0
- package/dist/types/general.d.ts +92 -0
- package/dist/types/general.js +0 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.js +8 -0
- package/dist/types/keys.d.ts +332 -0
- package/dist/types/keys.js +0 -0
- package/dist/types/manager.d.ts +249 -0
- package/dist/types/manager.js +0 -0
- package/dist/types/plugins.d.ts +1 -0
- package/dist/types/plugins.js +0 -0
- package/dist/types/shortcuts.d.ts +144 -0
- package/dist/types/shortcuts.js +0 -0
- package/dist/types/utils.d.ts +1 -0
- package/dist/types/utils.js +0 -0
- package/dist/types.d.mts +3 -0
- package/dist/utils/chainContainsSubset.d.ts +27 -0
- package/dist/utils/chainContainsSubset.js +45 -0
- package/dist/utils/cloneChain.d.ts +2 -0
- package/dist/utils/cloneChain.js +11 -0
- package/dist/utils/cloneKey.d.ts +3 -0
- package/dist/utils/cloneKey.js +26 -0
- package/dist/utils/containsKey.d.ts +7 -0
- package/dist/utils/containsKey.js +4 -0
- package/dist/utils/dedupeKeys.d.ts +9 -0
- package/dist/utils/dedupeKeys.js +9 -0
- package/dist/utils/equalsKey.d.ts +12 -0
- package/dist/utils/equalsKey.js +13 -0
- package/dist/utils/equalsKeys.d.ts +24 -0
- package/dist/utils/equalsKeys.js +15 -0
- package/dist/utils/index.d.ts +14 -0
- package/dist/utils/index.js +14 -0
- package/dist/utils/isAnyKey.d.ts +5 -0
- package/dist/utils/isAnyKey.js +5 -0
- package/dist/utils/isMouseKey.d.ts +5 -0
- package/dist/utils/isMouseKey.js +20 -0
- package/dist/utils/isNormalKey.d.ts +5 -0
- package/dist/utils/isNormalKey.js +5 -0
- package/dist/utils/isTriggerKey.d.ts +5 -0
- package/dist/utils/isTriggerKey.js +3 -0
- package/dist/utils/isWheelKey.d.ts +5 -0
- package/dist/utils/isWheelKey.js +11 -0
- package/dist/utils/mapKeys.d.ts +8 -0
- package/dist/utils/mapKeys.js +5 -0
- package/dist/utils/removeKeys.d.ts +7 -0
- package/dist/utils/removeKeys.js +4 -0
- package/package.json +156 -0
- package/src/core/EmulatedEvent.ts +29 -0
- package/src/core/Emulator.ts +185 -0
- package/src/core/ShortcutManagerManager.ts +380 -0
- package/src/core/addCommand.ts +24 -0
- package/src/core/addKey.ts +25 -0
- package/src/core/addShortcut.ts +24 -0
- package/src/core/attach.ts +27 -0
- package/src/core/createCommand.ts +24 -0
- package/src/core/createCommands.ts +45 -0
- package/src/core/createCondition.ts +21 -0
- package/src/core/createContext.ts +14 -0
- package/src/core/createKey.ts +59 -0
- package/src/core/createKeys.ts +68 -0
- package/src/core/createManager.ts +209 -0
- package/src/core/createManagerEventListeners.ts +139 -0
- package/src/core/createManagerOptions.ts +29 -0
- package/src/core/createShortcut.ts +49 -0
- package/src/core/createShortcuts.ts +51 -0
- package/src/core/detach.ts +21 -0
- package/src/core/index.ts +35 -0
- package/src/core/removeCommand.ts +25 -0
- package/src/core/removeKey.ts +25 -0
- package/src/core/removeShortcut.ts +24 -0
- package/src/core/setCommandProp.ts +140 -0
- package/src/core/setCommandsProp.ts +128 -0
- package/src/core/setKeyProp.ts +80 -0
- package/src/core/setKeysProp.ts +205 -0
- package/src/core/setManagerProp.ts +111 -0
- package/src/core/setShortcutProp.ts +89 -0
- package/src/core/setShortcutsProp.ts +124 -0
- package/src/defaults/KeysSorter.ts +55 -0
- package/src/defaults/Stringifier.ts +234 -0
- package/src/defaults/defaultConditionEquals.ts +29 -0
- package/src/defaults/defaultManagerCallback.ts +14 -0
- package/src/helpers/KnownError.ts +13 -0
- package/src/helpers/calculateAndSetPositionAndWidth.ts +30 -0
- package/src/helpers/calculateLayoutSize.ts +22 -0
- package/src/helpers/doesShortcutConflict.ts +72 -0
- package/src/helpers/equalsCommand.ts +18 -0
- package/src/helpers/equalsContext.ts +29 -0
- package/src/helpers/equalsShortcut.ts +34 -0
- package/src/helpers/forceClear.ts +31 -0
- package/src/helpers/forceUpdateNativeKeysState.ts +9 -0
- package/src/helpers/generateKeyShortcutMap.ts +113 -0
- package/src/helpers/getKeyFromEventCode.ts +67 -0
- package/src/helpers/getKeyFromIdOrVariant.ts +33 -0
- package/src/helpers/getKeyboardLayoutMap.ts +13 -0
- package/src/helpers/getLabel.ts +15 -0
- package/src/helpers/getTriggerableShortcut.ts +37 -0
- package/src/helpers/index.ts +30 -0
- package/src/helpers/isValidManager.ts +29 -0
- package/src/helpers/isValidShortcut.ts +20 -0
- package/src/helpers/labelWithEvent.ts +41 -0
- package/src/helpers/labelWithKeyboardMap.ts +37 -0
- package/src/helpers/managerToStorableClone.ts +26 -0
- package/src/helpers/onKeyboardLayoutChange.ts +17 -0
- package/src/helpers/safeSetManagerChain.ts +66 -0
- package/src/helpers/shortcutCanExecuteIn.ts +24 -0
- package/src/helpers/shortcutIsTriggerableBy.ts +15 -0
- package/src/helpers/shortcutSwapChords.ts +240 -0
- package/src/helpers/virtualPress.ts +34 -0
- package/src/helpers/virtualRelease.ts +25 -0
- package/src/helpers/virtualToggle.ts +28 -0
- package/src/internal/addToChain.ts +40 -0
- package/src/internal/areValidKeys.ts +40 -0
- package/src/internal/areValidVariants.ts +59 -0
- package/src/internal/checkTrigger.ts +55 -0
- package/src/internal/checkUntrigger.ts +26 -0
- package/src/internal/cloneLastChord.ts +10 -0
- package/src/internal/containsPossibleToggleChords.ts +91 -0
- package/src/internal/errorTextAdd.ts +18 -0
- package/src/internal/errorTextInUse.ts +10 -0
- package/src/internal/errorTextRemove.ts +10 -0
- package/src/internal/getModifierState.ts +15 -0
- package/src/internal/getPressedKeys.ts +26 -0
- package/src/internal/getPressedModifierKeys.ts +14 -0
- package/src/internal/getPressedNonModifierKeys.ts +19 -0
- package/src/internal/inChain.ts +25 -0
- package/src/internal/isValidChain.ts +42 -0
- package/src/internal/isValidChord.ts +87 -0
- package/src/internal/isValidCommand.ts +35 -0
- package/src/internal/keyOrder.ts +24 -0
- package/src/internal/removeFromChain.ts +46 -0
- package/src/internal/safeSetEmulatedToggleState.ts +23 -0
- package/src/internal/setKeysState.ts +71 -0
- package/src/internal/updateNativeKeysState.ts +84 -0
- package/src/layouts/createLayout.ts +328 -0
- package/src/module.ts +62 -0
- package/src/runtime/composables/useLabeledByKeyboardLayoutMap.ts +28 -0
- package/src/runtime/composables/usePointerCoords.ts +40 -0
- package/src/runtime/composables/useShortcutManagerContextCount.ts +81 -0
- package/src/runtime/composables/useShortcutManagerKeysLayout.ts +42 -0
- package/src/runtime/composables/useShortcutManagerVirtualPress.ts +30 -0
- package/src/runtime/types.ts +10 -0
- package/src/runtime/utils/shortcutToId.ts +14 -0
- package/src/types/commands.ts +148 -0
- package/src/types/condition.ts +35 -0
- package/src/types/context.ts +19 -0
- package/src/types/enums.ts +236 -0
- package/src/types/general.ts +117 -0
- package/src/types/index.ts +10 -0
- package/src/types/keys.ts +385 -0
- package/src/types/manager.ts +374 -0
- package/src/types/plugins.ts +32 -0
- package/src/types/shortcuts.ts +204 -0
- package/src/types/utils.ts +40 -0
- package/src/utils/chainContainsSubset.ts +97 -0
- package/src/utils/cloneChain.ts +13 -0
- package/src/utils/cloneKey.ts +33 -0
- package/src/utils/containsKey.ts +17 -0
- package/src/utils/dedupeKeys.ts +23 -0
- package/src/utils/equalsKey.ts +32 -0
- package/src/utils/equalsKeys.ts +50 -0
- package/src/utils/index.ts +16 -0
- package/src/utils/isAnyKey.ts +12 -0
- package/src/utils/isMouseKey.ts +27 -0
- package/src/utils/isNormalKey.ts +15 -0
- package/src/utils/isTriggerKey.ts +7 -0
- package/src/utils/isWheelKey.ts +18 -0
- package/src/utils/mapKeys.ts +21 -0
- package/src/utils/removeKeys.ts +16 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Ref, ref } from "vue"
|
|
2
|
+
|
|
3
|
+
import type { ManagerListener } from "../../types/index.js"
|
|
4
|
+
|
|
5
|
+
export function useShortcutManagerVirtualPress(): {
|
|
6
|
+
virtuallyPressedKeys: Ref<Record<string, boolean>>
|
|
7
|
+
updateVirtuallyPressed: ManagerListener
|
|
8
|
+
} {
|
|
9
|
+
const virtuallyPressedKeys = ref<Record<string, boolean>>({})
|
|
10
|
+
function updateVirtuallyPressed(arg: Parameters<ManagerListener>[0]): void {
|
|
11
|
+
const { event, keys, isKeydown } = arg
|
|
12
|
+
if (!event) {
|
|
13
|
+
for (const key of keys) {
|
|
14
|
+
if (isKeydown) {
|
|
15
|
+
virtuallyPressedKeys.value[key] = true
|
|
16
|
+
} else {
|
|
17
|
+
delete virtuallyPressedKeys.value[key]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
} else {
|
|
21
|
+
for (const key of keys) {
|
|
22
|
+
delete virtuallyPressedKeys.value[key]
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
virtuallyPressedKeys,
|
|
28
|
+
updateVirtuallyPressed
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface Register { }
|
|
2
|
+
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
4
|
+
type ExtendedContextInfo = Register extends { ExtendedContextInfo: infer T } ? T : unknown
|
|
5
|
+
|
|
6
|
+
export type ContextInfo = ExtendedContextInfo & {
|
|
7
|
+
count: Record<string, number>
|
|
8
|
+
isActive: Record<string, boolean>
|
|
9
|
+
}
|
|
10
|
+
export {}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PickManager } from "../../types/general.js"
|
|
2
|
+
import type { Manager } from "../../types/manager.js"
|
|
3
|
+
import type { Shortcut } from "../../types/shortcuts.js"
|
|
4
|
+
|
|
5
|
+
/** Turns a shortcut into an id to use in a v-for loop. */
|
|
6
|
+
export const shortcutToId = (
|
|
7
|
+
shortcut: Shortcut,
|
|
8
|
+
manager: PickManager<"options", "stringifier"> & Pick<Manager, "keys">
|
|
9
|
+
): string => [
|
|
10
|
+
shortcut.enabled,
|
|
11
|
+
manager.options.stringifier.stringify(shortcut.chain, manager),
|
|
12
|
+
shortcut.command ?? "",
|
|
13
|
+
shortcut.condition.text
|
|
14
|
+
].join("--")
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import type { Condition } from "./condition.js"
|
|
2
|
+
import type { Context } from "./context.js"
|
|
3
|
+
import type { SHORTCUT_ERROR } from "./enums.js"
|
|
4
|
+
import type { PickManager } from "./general.js"
|
|
5
|
+
import type { AnyInputEvent, Manager, MinimalInputEvent } from "./manager.js"
|
|
6
|
+
import type { Shortcut } from "./shortcuts.js"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export type RawCommand<TName extends string = string> = Pick<Command<TName>, "name"> & Partial<Command<TName>>
|
|
10
|
+
|
|
11
|
+
export type CommandExecute<TName extends string = string> = <
|
|
12
|
+
|
|
13
|
+
T extends AnyInputEvent | MinimalInputEvent = AnyInputEvent | MinimalInputEvent
|
|
14
|
+
>(args: {
|
|
15
|
+
isKeydown: boolean
|
|
16
|
+
command: Command<TName>
|
|
17
|
+
shortcut?: Shortcut<TName> | undefined
|
|
18
|
+
/**
|
|
19
|
+
* The event that triggered the command. It might be undefined if a virtual event triggered the key. It's typed as {@link AnyInputEvent} because you might also receive Emulated events from the {@link Emulator} if you use it. If you don't you can safely ignore the {@link EmulatedEvent} type or type the execute function as `CommandExecute<AnyInputEvent>`
|
|
20
|
+
*/
|
|
21
|
+
event?: T
|
|
22
|
+
/**
|
|
23
|
+
* The manager might be undefined. This is to allow calling the command manually without it.
|
|
24
|
+
*/
|
|
25
|
+
manager?: Manager
|
|
26
|
+
context: Context
|
|
27
|
+
}) => void
|
|
28
|
+
|
|
29
|
+
export interface Command<
|
|
30
|
+
TName extends
|
|
31
|
+
string = string,
|
|
32
|
+
TExec extends CommandExecute<string> = CommandExecute<string>,
|
|
33
|
+
TCondition extends
|
|
34
|
+
Condition = Condition
|
|
35
|
+
> {
|
|
36
|
+
readonly type: "command"
|
|
37
|
+
/**
|
|
38
|
+
* Unique string to identify the command by.
|
|
39
|
+
*
|
|
40
|
+
* Note that when changing a command's name, it is not an error for the old command to not exist in the manager. This is to allow for easier checking if a command can be added. If you need it to be an error, you can add a canSetCommand hook.
|
|
41
|
+
*
|
|
42
|
+
* @RequiresSet @OnHookable @CanHookable
|
|
43
|
+
*/
|
|
44
|
+
readonly name: TName
|
|
45
|
+
/**
|
|
46
|
+
* The function to execute when a shortcut triggers it's command. It is executed both on keydown and keyup (of the first released key) so be sure to check the isKeydown parameter so you don't trigger commands twice.
|
|
47
|
+
*
|
|
48
|
+
* The command itself is passed to it, and if it is managed by a manager it is also passed the shortcut, the manager itself, and the event of the last key that triggered it. Note the event might not exist when the manager needs to emulate a key release. See {@link Manager.autoReleaseDelay}.
|
|
49
|
+
*
|
|
50
|
+
* You should do `e.preventDefault` if you need it or haven't done so from {@link Manager.eventFilter}.
|
|
51
|
+
*
|
|
52
|
+
* You should also do {@link safeSetManagerChain} on keyup for most regular shortcuts. See it for details.
|
|
53
|
+
*
|
|
54
|
+
* See {@link Manager}.
|
|
55
|
+
*
|
|
56
|
+
* @RequiresSet @OnHookable @CanHookable
|
|
57
|
+
*/
|
|
58
|
+
readonly execute?: TExec
|
|
59
|
+
/**
|
|
60
|
+
* Commands may have an additional condition that must be met, apart from the shortcut's that triggered it.
|
|
61
|
+
*
|
|
62
|
+
* If the command is created without a condition, it is assigned a blank condition. If you are using a custom condition class, you should probably always pass a blank condition.
|
|
63
|
+
*
|
|
64
|
+
* @RequiresSet @OnHookable @CanHookable
|
|
65
|
+
*/
|
|
66
|
+
readonly condition: TCondition
|
|
67
|
+
/**
|
|
68
|
+
* A description of what the command does.
|
|
69
|
+
*
|
|
70
|
+
* @RequiresSet @OnHookable @CanHookable
|
|
71
|
+
*/
|
|
72
|
+
readonly description: string
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export type Commands<
|
|
76
|
+
TEntries extends Record<string, Command> = Record<string, Command>
|
|
77
|
+
> = {
|
|
78
|
+
type: "commands"
|
|
79
|
+
/**
|
|
80
|
+
* The command entries.
|
|
81
|
+
*
|
|
82
|
+
* To add/remove entries you should {@link addCommand}/{@link removeCommand} or {@link setCommandsProp} with the synthetic `entries@add/remove` properties.
|
|
83
|
+
*
|
|
84
|
+
* The synthetic properties can be hooked into with {@link Manager.hooks}.
|
|
85
|
+
*
|
|
86
|
+
* @RequiresSet @OnHookable @Managed
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
entries: TEntries
|
|
90
|
+
}
|
|
91
|
+
export type RawCommands = Pick<Commands, "entries"> & Partial<Commands>
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
type GetCommandHooks<T extends keyof CommandSetEntries | keyof CommandsSetEntries>
|
|
95
|
+
= T extends CanHookCommandProps
|
|
96
|
+
? Partial<Pick<NonNullable<Manager["hooks"]>, "canSetCommandProp" | "onSetCommandProp">>
|
|
97
|
+
: T extends OnHookCommandProps
|
|
98
|
+
? Partial<Pick<NonNullable<Manager["hooks"]>, "onSetCommandProp">>
|
|
99
|
+
: T extends CanHookCommandsProps
|
|
100
|
+
? Partial<Pick<NonNullable<Manager["hooks"]>, "canSetCommandsProp" | "onSetCommandsProp">>
|
|
101
|
+
: Partial<Pick<NonNullable<Manager["hooks"]>, "onSetCommandsProp">>
|
|
102
|
+
|
|
103
|
+
type Unmanaged<T extends keyof Command & keyof CommandSetEntries> = {
|
|
104
|
+
val: Command[T]
|
|
105
|
+
manager: never
|
|
106
|
+
hooks: GetCommandHooks<T>
|
|
107
|
+
error: never
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export type CommandSetEntries = {
|
|
111
|
+
condition: Unmanaged<"condition">
|
|
112
|
+
execute: Unmanaged<"execute">
|
|
113
|
+
description: Unmanaged<"description">
|
|
114
|
+
name: {
|
|
115
|
+
val: string
|
|
116
|
+
manager: Pick<Manager, "commands" | "shortcuts" | "keys"> & PickManager<"options", "stringifier">
|
|
117
|
+
hooks: GetCommandHooks<"name">
|
|
118
|
+
// see name above, missing should NOT be an error
|
|
119
|
+
error: typeof SHORTCUT_ERROR.COMMAND_IN_USE | typeof SHORTCUT_ERROR.DUPLICATE_COMMAND | typeof SHORTCUT_ERROR.MULTIPLE_ERRORS
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
export type OnHookCommandProps = "condition" | "execute" | "description"
|
|
123
|
+
export type CanHookCommandProps = OnHookCommandProps
|
|
124
|
+
|
|
125
|
+
type BaseCommandsManager = PickManager<"options", "stringifier"> & Record<any, any>
|
|
126
|
+
& Pick<Manager, "commands">
|
|
127
|
+
|
|
128
|
+
export type CommandsSetEntries = {
|
|
129
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
130
|
+
"entries@add": {
|
|
131
|
+
val: Command
|
|
132
|
+
hooks: GetCommandHooks<`entries@add`>
|
|
133
|
+
manager: BaseCommandsManager
|
|
134
|
+
error: typeof SHORTCUT_ERROR.DUPLICATE_COMMAND
|
|
135
|
+
}
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
137
|
+
"entries@remove": {
|
|
138
|
+
val: Command
|
|
139
|
+
hooks: GetCommandHooks<`entries@remove`>
|
|
140
|
+
manager: BaseCommandsManager & Pick<Manager, "shortcuts" | "keys">
|
|
141
|
+
error: typeof SHORTCUT_ERROR.COMMAND_IN_USE | typeof SHORTCUT_ERROR.MISSING
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export type SyntheticOnHookCommandsProps = "entries@add" | "entries@remove"
|
|
146
|
+
export type CanHookCommandsProps = SyntheticOnHookCommandsProps
|
|
147
|
+
export type OnHookCommandsProps = SyntheticOnHookCommandsProps
|
|
148
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Context } from "./context.js"
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export type RawCondition = string
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This just describes a condition. No logic to parse/evaluate them is provided and a third party library should be used. The {@link ConditionEvaluator} can then be used to specify how to evaluate them.
|
|
8
|
+
*/
|
|
9
|
+
export interface Condition {
|
|
10
|
+
type: "condition"
|
|
11
|
+
/**
|
|
12
|
+
* The main text representation of the condition. Note that this is NOT a unique identifier for conditions and cannot be used to compare them if you are using boolean expressions for your conditions. See {@link Condition.constructor} for an explanation.
|
|
13
|
+
*/
|
|
14
|
+
text: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Returns whether the condition passed is equal to this one.
|
|
19
|
+
*
|
|
20
|
+
* The default method does a simplistic check of the `text` property for equality. If you override the method you will likely want it to just always return false.
|
|
21
|
+
*
|
|
22
|
+
* Why? Because unless you're using simple single variable conditions that you can presort to make them uniquely identifiable (i.e. not boolean expressions, but something like `!a b !c`), this will return A LOT of false negatives.
|
|
23
|
+
*
|
|
24
|
+
* Why the false negatives? Because two conditions might be functionally equal but have differing representations (e.g: `a && b`, `b && a`). You might think, lets normalize them all, but normalizing boolean expressions (converting them to CNF) can be dangerous with very long expressions because it can take exponential time.
|
|
25
|
+
*
|
|
26
|
+
* Now the main reason for checking the equality of two conditions is to check if two shortcuts might conflict. If we're using boolean expressions it just can't be done safely.
|
|
27
|
+
*
|
|
28
|
+
* This is a personal preference, but if we have a method that gives false negatives it can be confusing that some shortcuts immediately error when added because their conditions are simple, while others don't until triggered. The simpler, more consistent alternative is to only have them error on triggering. Aditionally conflicting conditions can be shown on the keyboard layout when then user picks contexts to check against.
|
|
29
|
+
*
|
|
30
|
+
* Why use the default implementation at all then? Well, shortcuts aren't the only ones that have conditions, commands can too, but unlike shortcuts, usually it's developers who are in charge of assigning a command's condition, and since they are usually simple, it's more possible to make sure the conditions are unique (e.g. tests could enforce they're unique by converting them all to CNF and pre-checking them for equality).
|
|
31
|
+
*/
|
|
32
|
+
export type ConditionComparer = (conditionA?: Condition, conditionB?: Condition) => boolean
|
|
33
|
+
|
|
34
|
+
export type ConditionEvaluator<TContext extends Context<any>> = (condition: Condition, context: TContext) => boolean
|
|
35
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface RecursiveRecord {
|
|
2
|
+
[key: string]: any | RecursiveRecord
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* # Context
|
|
6
|
+
*
|
|
7
|
+
* Like {@link Condition}, provides a way to describe contexts. How contexts look and work is up to you.
|
|
8
|
+
*
|
|
9
|
+
* Contexts describe the relevant application state. They are what {@link Condition}s are evaluated against.
|
|
10
|
+
*
|
|
11
|
+
* @template TValue **@internal** Captures the type of the context value.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export type Context<TValue extends object = any> = {
|
|
15
|
+
type: "context"
|
|
16
|
+
/** Where the context object is stored. */
|
|
17
|
+
value: TValue
|
|
18
|
+
}
|
|
19
|
+
export type RawContext = Pick<Context, "value"> & Partial<Context>
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import type { EnumLike } from "@alanscodelog/utils"
|
|
2
|
+
import { enumFromArray } from "@alanscodelog/utils/enumFromArray"
|
|
3
|
+
|
|
4
|
+
import type { Command, Commands } from "./commands.js"
|
|
5
|
+
import type { Key, Keys } from "./keys.js"
|
|
6
|
+
import type { AnyInputEvent } from "./manager.js"
|
|
7
|
+
import type { Shortcut, Shortcuts } from "./shortcuts.js"
|
|
8
|
+
|
|
9
|
+
import type { KnownError } from "../helpers/index.js"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* All possible errors.
|
|
13
|
+
*/
|
|
14
|
+
export const SHORTCUT_ERROR = enumFromArray([
|
|
15
|
+
// === shortcut init related problems
|
|
16
|
+
"CHORD_W_ONLY_MODIFIERS",
|
|
17
|
+
"CHORD_W_MULTIPLE_TRIGGER_KEYS",
|
|
18
|
+
"CHORD_W_MULTIPLE_WHEEL_KEYS",
|
|
19
|
+
"CHORD_W_DUPLICATE_KEY",
|
|
20
|
+
"IMPOSSIBLE_TOGGLE_SEQUENCE",
|
|
21
|
+
"MISSING", // removing
|
|
22
|
+
"INVALID_VARIANT",
|
|
23
|
+
"INVALID_VARIANT_PAIR",
|
|
24
|
+
|
|
25
|
+
// === duplicate "bases"
|
|
26
|
+
"DUPLICATE_KEY",
|
|
27
|
+
"DUPLICATE_COMMAND",
|
|
28
|
+
"DUPLICATE_SHORTCUT",
|
|
29
|
+
|
|
30
|
+
// === other
|
|
31
|
+
"INVALID_SWAP_CHORDS",
|
|
32
|
+
"CANNOT_SET_WHILE_DISABLED",
|
|
33
|
+
|
|
34
|
+
// === manager
|
|
35
|
+
"MULTIPLE_MATCHING_SHORTCUTS",
|
|
36
|
+
"INCORRECT_TOGGLE_STATE",
|
|
37
|
+
"NO_MATCHING_SHORTCUT",
|
|
38
|
+
"UNKNOWN_KEY",
|
|
39
|
+
"UNKNOWN_KEY_ID",
|
|
40
|
+
"UNKNOWN_COMMAND",
|
|
41
|
+
"KEY_IN_USE",
|
|
42
|
+
"COMMAND_IN_USE",
|
|
43
|
+
"UNKNOWN_KEY_EVENT",
|
|
44
|
+
"MULTIPLE_ERRORS",
|
|
45
|
+
"INVALID_MANAGER"
|
|
46
|
+
])
|
|
47
|
+
export type ShortcutError = EnumLike<typeof SHORTCUT_ERROR>
|
|
48
|
+
|
|
49
|
+
export type ChainError
|
|
50
|
+
= | typeof SHORTCUT_ERROR.UNKNOWN_KEY
|
|
51
|
+
| typeof SHORTCUT_ERROR.CHORD_W_DUPLICATE_KEY
|
|
52
|
+
| typeof SHORTCUT_ERROR.CHORD_W_ONLY_MODIFIERS
|
|
53
|
+
| typeof SHORTCUT_ERROR.CHORD_W_MULTIPLE_TRIGGER_KEYS
|
|
54
|
+
| typeof SHORTCUT_ERROR.CHORD_W_MULTIPLE_WHEEL_KEYS
|
|
55
|
+
| typeof SHORTCUT_ERROR.IMPOSSIBLE_TOGGLE_SEQUENCE
|
|
56
|
+
|
|
57
|
+
/** Errors that will throw since they should be caught at production. */
|
|
58
|
+
|
|
59
|
+
export const TYPE_ERROR = enumFromArray([
|
|
60
|
+
"ILLEGAL_OPERATION",
|
|
61
|
+
"HOOK_OR_LISTENER_DOES_NOT_EXIST",
|
|
62
|
+
"FILTER_DOES_NOT_EXIST"
|
|
63
|
+
])
|
|
64
|
+
export type TypeError = EnumLike<typeof TYPE_ERROR>
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Defines the properties attached to each error.
|
|
68
|
+
*
|
|
69
|
+
* Makes it easy to define the properties attached to each error by just allowing passing the error (regardless of error type) as T in [[KnownError]] and [[InternalError]].
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
export type ErrorInfo<T extends ShortcutError | TypeError>
|
|
73
|
+
= T extends ShortcutError
|
|
74
|
+
? ERROR_Info[T]
|
|
75
|
+
: never
|
|
76
|
+
|
|
77
|
+
/** Type multiple {@link KnownError} errors to work like a discriminated union. */
|
|
78
|
+
export type MultipleErrors<T extends ShortcutError | TypeError> = {
|
|
79
|
+
[k in T]: KnownError<k>
|
|
80
|
+
}[T]
|
|
81
|
+
|
|
82
|
+
// note all these error types could be kept in the same type, but then we'd have to make all the keys unique and we can't because internal errors should use the same key
|
|
83
|
+
|
|
84
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
85
|
+
type ERROR_Info = {
|
|
86
|
+
// === shortcut init related problems
|
|
87
|
+
[SHORTCUT_ERROR.CHORD_W_ONLY_MODIFIERS]: {
|
|
88
|
+
chord: string[]
|
|
89
|
+
i: number
|
|
90
|
+
keys: string[]
|
|
91
|
+
}
|
|
92
|
+
[SHORTCUT_ERROR.CHORD_W_MULTIPLE_TRIGGER_KEYS]: {
|
|
93
|
+
chord: string[]
|
|
94
|
+
i: number
|
|
95
|
+
keys: string[]
|
|
96
|
+
}
|
|
97
|
+
[SHORTCUT_ERROR.CHORD_W_MULTIPLE_WHEEL_KEYS]: {
|
|
98
|
+
chord: string[]
|
|
99
|
+
i: number
|
|
100
|
+
keys: string[]
|
|
101
|
+
}
|
|
102
|
+
[SHORTCUT_ERROR.CHORD_W_DUPLICATE_KEY]: {
|
|
103
|
+
chord: string[]
|
|
104
|
+
i: number
|
|
105
|
+
keys: string[]
|
|
106
|
+
}
|
|
107
|
+
[SHORTCUT_ERROR.IMPOSSIBLE_TOGGLE_SEQUENCE]: {
|
|
108
|
+
chain: string[][]
|
|
109
|
+
i: number
|
|
110
|
+
key: Key
|
|
111
|
+
}
|
|
112
|
+
[SHORTCUT_ERROR.MISSING]: {
|
|
113
|
+
entry: Key | Shortcut | Command | string
|
|
114
|
+
self: Keys | Shortcuts | Commands
|
|
115
|
+
}
|
|
116
|
+
[SHORTCUT_ERROR.INVALID_VARIANT]: {
|
|
117
|
+
variants: string[]
|
|
118
|
+
id: string
|
|
119
|
+
}
|
|
120
|
+
[SHORTCUT_ERROR.INVALID_VARIANT_PAIR]: {
|
|
121
|
+
variants: Key[]
|
|
122
|
+
key: Key
|
|
123
|
+
otherKey: Key
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
[SHORTCUT_ERROR.DUPLICATE_KEY]: {
|
|
127
|
+
existing: Key
|
|
128
|
+
self: Keys
|
|
129
|
+
}
|
|
130
|
+
[SHORTCUT_ERROR.DUPLICATE_SHORTCUT]: {
|
|
131
|
+
existing: Shortcut
|
|
132
|
+
self: Shortcuts
|
|
133
|
+
/** If the error is caused by a change, key and value will contain the new key and value. */
|
|
134
|
+
key?: string
|
|
135
|
+
value?: any
|
|
136
|
+
}
|
|
137
|
+
[SHORTCUT_ERROR.DUPLICATE_COMMAND]: {
|
|
138
|
+
existing: Command
|
|
139
|
+
self: Commands
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
// === other
|
|
144
|
+
[SHORTCUT_ERROR.INVALID_SWAP_CHORDS]:
|
|
145
|
+
{
|
|
146
|
+
chord: string[][]
|
|
147
|
+
}
|
|
148
|
+
| {
|
|
149
|
+
chordsA: string[][]
|
|
150
|
+
chordsB: string[][]
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
[SHORTCUT_ERROR.CANNOT_SET_WHILE_DISABLED]:
|
|
154
|
+
{
|
|
155
|
+
key: Key
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// === manager
|
|
159
|
+
[SHORTCUT_ERROR.MULTIPLE_MATCHING_SHORTCUTS]: {
|
|
160
|
+
shortcuts: Shortcut[]
|
|
161
|
+
}
|
|
162
|
+
[SHORTCUT_ERROR.INCORRECT_TOGGLE_STATE]: {
|
|
163
|
+
key: Key
|
|
164
|
+
}
|
|
165
|
+
[SHORTCUT_ERROR.NO_MATCHING_SHORTCUT]: {
|
|
166
|
+
chain: string[][]
|
|
167
|
+
}
|
|
168
|
+
[SHORTCUT_ERROR.UNKNOWN_KEY]: {
|
|
169
|
+
shortcut?: Pick<Shortcut, "chain">
|
|
170
|
+
keys: string[] | Keys
|
|
171
|
+
}
|
|
172
|
+
[SHORTCUT_ERROR.UNKNOWN_COMMAND]: {
|
|
173
|
+
shortcut?: Pick<Shortcut, "chain" | "command">
|
|
174
|
+
command: string
|
|
175
|
+
commands: string[] | Commands
|
|
176
|
+
}
|
|
177
|
+
[SHORTCUT_ERROR.MULTIPLE_ERRORS]: {
|
|
178
|
+
errors: Error[]
|
|
179
|
+
}
|
|
180
|
+
[SHORTCUT_ERROR.KEY_IN_USE]: {
|
|
181
|
+
inUseShortcuts: Shortcut[]
|
|
182
|
+
}
|
|
183
|
+
[SHORTCUT_ERROR.COMMAND_IN_USE]: {
|
|
184
|
+
inUseShortcuts: Shortcut[]
|
|
185
|
+
}
|
|
186
|
+
[SHORTCUT_ERROR.UNKNOWN_KEY_EVENT]: {
|
|
187
|
+
e: AnyInputEvent
|
|
188
|
+
button?: string
|
|
189
|
+
code?: string
|
|
190
|
+
key?: string
|
|
191
|
+
deltaY?: number | string
|
|
192
|
+
}
|
|
193
|
+
[SHORTCUT_ERROR.UNKNOWN_KEY_ID]: {
|
|
194
|
+
id: string
|
|
195
|
+
}
|
|
196
|
+
[SHORTCUT_ERROR.INVALID_MANAGER]: {
|
|
197
|
+
keys: string[]
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
export const MOUSE = enumFromArray([
|
|
203
|
+
"R",
|
|
204
|
+
"M",
|
|
205
|
+
"L",
|
|
206
|
+
"BACK",
|
|
207
|
+
"FORWARD"
|
|
208
|
+
])
|
|
209
|
+
export type Mouse = EnumLike<typeof MOUSE>
|
|
210
|
+
|
|
211
|
+
export const WHEEL = enumFromArray([
|
|
212
|
+
"down",
|
|
213
|
+
"up"
|
|
214
|
+
])
|
|
215
|
+
export type Wheel = EnumLike<typeof WHEEL>
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
// These do not need to be initialized, we want the order they're declared in.
|
|
219
|
+
export const KEY_SORT_POS = {
|
|
220
|
+
mod: 0,
|
|
221
|
+
modmouse: 1,
|
|
222
|
+
// modmousewheel = error
|
|
223
|
+
modwheel: 2, // weird...
|
|
224
|
+
modtoggle: 3, // weird...
|
|
225
|
+
modtogglemouse: 4, // weird...
|
|
226
|
+
modtogglewheel: 5, // weird...
|
|
227
|
+
// modtogglemousewheel = error
|
|
228
|
+
normal: 6,
|
|
229
|
+
mouse: 7,
|
|
230
|
+
wheel: 8,
|
|
231
|
+
toggle: 9,
|
|
232
|
+
togglemouse: 10,
|
|
233
|
+
togglewheel: 11 // weird...
|
|
234
|
+
// modtogglemousewheel = error
|
|
235
|
+
}
|
|
236
|
+
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { Command } from "./commands.js"
|
|
2
|
+
import type { Condition } from "./condition.js"
|
|
3
|
+
import type { Key } from "./keys.js"
|
|
4
|
+
import type { Manager } from "./manager.js"
|
|
5
|
+
import type { Shortcut } from "./shortcuts.js"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
9
|
+
export type NavigatorWKeyboard = {
|
|
10
|
+
keyboard?: {
|
|
11
|
+
/**
|
|
12
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/Keyboard/getLayoutMap getLayoutMap}
|
|
13
|
+
*/
|
|
14
|
+
getLayoutMap(): Promise<KeyboardLayoutMap>
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export type KeyCode = string
|
|
18
|
+
export type KeyLabel = string
|
|
19
|
+
export type KeyboardLayoutMap = Map<KeyCode, KeyLabel>
|
|
20
|
+
export type AttachTarget = {
|
|
21
|
+
addEventListener: HTMLElement["addEventListener"]
|
|
22
|
+
removeEventListener: HTMLElement["removeEventListener"]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type DefaultStringifierOptions = {
|
|
26
|
+
/**
|
|
27
|
+
* The key parameter will be undefined for unknown keys.
|
|
28
|
+
* Also careful with toggle keys, you will need to check which toggle it is by checking against the toggle ids.
|
|
29
|
+
*/
|
|
30
|
+
key?: (id: string, key?: Key) => string
|
|
31
|
+
chord?: (key: readonly string[]) => string
|
|
32
|
+
chain?: (key: readonly string[]) => string
|
|
33
|
+
shortcut?: (shortcut: Shortcut) => string
|
|
34
|
+
command?: (command?: Command) => string
|
|
35
|
+
condition?: (condition?: Condition) => string
|
|
36
|
+
propertyValue?: (propertyValue?: any) => string
|
|
37
|
+
list?: (items: string[], type: "keys" | "commands" | "shortcuts") => string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type StringifyCommandList = { type: "command", list: string[] }
|
|
41
|
+
export type StringifyKeyList = { type: "key", list: string[] }
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
43
|
+
export type IStringifier = {
|
|
44
|
+
stringify(
|
|
45
|
+
entry: Shortcut,
|
|
46
|
+
manager: Pick<Manager, "keys" | "commands">
|
|
47
|
+
): string
|
|
48
|
+
/**
|
|
49
|
+
* Stringifies single keys in string or {@link Key} from, as well as chords, chains, full shortcuts, and commands.
|
|
50
|
+
*
|
|
51
|
+
* In the case of string key ids and Shortcuts, some additional information is required to be able to convert the keys and commands back into the full commands and consistently stringify them.
|
|
52
|
+
*
|
|
53
|
+
*/
|
|
54
|
+
stringify(
|
|
55
|
+
entry: string | string[] | string[][],
|
|
56
|
+
manager: Pick<Manager, "keys">
|
|
57
|
+
): string
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
stringify(
|
|
61
|
+
entry: Key | Key[] | Command | Condition,
|
|
62
|
+
): string
|
|
63
|
+
|
|
64
|
+
stringify(
|
|
65
|
+
entry: string | string[] | string[][] | Key | Key[] | Shortcut | Command | Condition,
|
|
66
|
+
manager: Pick<Manager, "keys" | "commands"> | Pick<Manager, "keys"> | never
|
|
67
|
+
|
|
68
|
+
): string
|
|
69
|
+
/** Stringifies the property values of items when there is an error (e.g. "You cannot change prop x from a to b because of y." a and b here being the property values). */
|
|
70
|
+
stringifyPropertyValue(entry: any): string
|
|
71
|
+
/**
|
|
72
|
+
* Stringifies lists of keys, shortcuts, or commands.
|
|
73
|
+
*
|
|
74
|
+
* The type must be specified because we can't magically tell what type something is for string lists and/or empty lists.
|
|
75
|
+
*/
|
|
76
|
+
stringifyList(type: "keys", entries: Key[]): string
|
|
77
|
+
stringifyList(type: "commands", entries: Command[]): string
|
|
78
|
+
stringifyList(type: "keys", entries: string[], manager: Pick<Manager, "keys">): string
|
|
79
|
+
stringifyList(type: "commands", entries: string[], manager: Pick<Manager, "commands">): string
|
|
80
|
+
stringifyList(type: "shortcuts", entries: Shortcut[], manager: Pick<Manager, "keys" | "commands">): string
|
|
81
|
+
/**
|
|
82
|
+
* Stringifies commands by name (`stringify` interprets single strings as key ids.).
|
|
83
|
+
*/
|
|
84
|
+
stringifyCommand(name: string | undefined, manager: Pick<Manager, "commands">): string
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
export type PickManager<
|
|
89
|
+
TType extends "options" | "state" | "hooks",
|
|
90
|
+
TKeys extends keyof TManager[TType],
|
|
91
|
+
TManager extends Manager = Manager
|
|
92
|
+
>
|
|
93
|
+
= Record<TType, Pick<TManager[TType], TKeys>>
|
|
94
|
+
|
|
95
|
+
export type PickManagerHooks<T extends Manager["hooks"]> = {
|
|
96
|
+
hooks?: T
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export type ShortcutInfo = {
|
|
100
|
+
shortcut: Shortcut
|
|
101
|
+
isPressableChain: boolean
|
|
102
|
+
isPressable: boolean
|
|
103
|
+
isPressed: boolean
|
|
104
|
+
/** If a shortcut contains unpressed modifiers, it will not be considered pressable or a pressable chain, but you will likely want to show a hint on the modifier anyways. */
|
|
105
|
+
hasUnpressedModifiers: boolean
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export type KeyInfo = {
|
|
109
|
+
/** All shortcuts that contain this key and are either pressable, pressable chains, or pressed. */
|
|
110
|
+
pressableEntries: ShortcutInfo[]
|
|
111
|
+
/** All shortcuts that contain this key and are not pressable but have unpressed modifiers (see {@link ShortcutInfo.hasUnpressedModifiers}). */
|
|
112
|
+
modifierEntries: ShortcutInfo[]
|
|
113
|
+
/** Depending on the shortcut's list passed, or how conditions and contexts are implemented, it's possible for their to be conflicting shortcuts in certain contexts. */
|
|
114
|
+
containsConflicting: boolean
|
|
115
|
+
/** Indicates there are shortcuts in the modifierEntries, i.e. there are shortcuts that have unpressedModifiers (see {@link ShortcutInfo.hasUnpressedModifiers}). You will usually want to have some visual hint the modifier key can be pressed to show more shortcuts. */
|
|
116
|
+
isModifierHint: boolean
|
|
117
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* Autogenerated Index [types] */
|
|
2
|
+
|
|
3
|
+
export * from "./manager.js"
|
|
4
|
+
export * from "./enums.js"
|
|
5
|
+
export * from "./general.js"
|
|
6
|
+
export * from "./commands.js"
|
|
7
|
+
export * from "./condition.js"
|
|
8
|
+
export * from "./keys.js"
|
|
9
|
+
export * from "./shortcuts.js"
|
|
10
|
+
export * from "./context.js"
|