@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.
Files changed (367) hide show
  1. package/README.md +579 -0
  2. package/dist/core/EmulatedEvent.d.ts +10 -0
  3. package/dist/core/EmulatedEvent.js +19 -0
  4. package/dist/core/Emulator.d.ts +74 -0
  5. package/dist/core/Emulator.js +153 -0
  6. package/dist/core/ShortcutManagerManager.d.ts +103 -0
  7. package/dist/core/ShortcutManagerManager.js +267 -0
  8. package/dist/core/addCommand.d.ts +7 -0
  9. package/dist/core/addCommand.js +7 -0
  10. package/dist/core/addKey.d.ts +7 -0
  11. package/dist/core/addKey.js +7 -0
  12. package/dist/core/addShortcut.d.ts +7 -0
  13. package/dist/core/addShortcut.js +7 -0
  14. package/dist/core/attach.d.ts +10 -0
  15. package/dist/core/attach.js +13 -0
  16. package/dist/core/createCommand.d.ts +4 -0
  17. package/dist/core/createCommand.js +11 -0
  18. package/dist/core/createCommands.d.ts +11 -0
  19. package/dist/core/createCommands.js +20 -0
  20. package/dist/core/createCondition.d.ts +7 -0
  21. package/dist/core/createCondition.js +11 -0
  22. package/dist/core/createContext.d.ts +2 -0
  23. package/dist/core/createContext.js +8 -0
  24. package/dist/core/createKey.d.ts +10 -0
  25. package/dist/core/createKey.js +35 -0
  26. package/dist/core/createKeys.d.ts +5 -0
  27. package/dist/core/createKeys.js +36 -0
  28. package/dist/core/createManager.d.ts +81 -0
  29. package/dist/core/createManager.js +83 -0
  30. package/dist/core/createManagerEventListeners.d.ts +4 -0
  31. package/dist/core/createManagerEventListeners.js +130 -0
  32. package/dist/core/createManagerOptions.d.ts +8 -0
  33. package/dist/core/createManagerOptions.js +17 -0
  34. package/dist/core/createShortcut.d.ts +8 -0
  35. package/dist/core/createShortcut.js +24 -0
  36. package/dist/core/createShortcuts.d.ts +13 -0
  37. package/dist/core/createShortcuts.js +20 -0
  38. package/dist/core/detach.d.ts +10 -0
  39. package/dist/core/detach.js +6 -0
  40. package/dist/core/index.d.ts +32 -0
  41. package/dist/core/index.js +32 -0
  42. package/dist/core/removeCommand.d.ts +7 -0
  43. package/dist/core/removeCommand.js +7 -0
  44. package/dist/core/removeKey.d.ts +7 -0
  45. package/dist/core/removeKey.js +7 -0
  46. package/dist/core/removeShortcut.d.ts +7 -0
  47. package/dist/core/removeShortcut.js +7 -0
  48. package/dist/core/setCommandProp.d.ts +17 -0
  49. package/dist/core/setCommandProp.js +96 -0
  50. package/dist/core/setCommandsProp.d.ts +15 -0
  51. package/dist/core/setCommandsProp.js +94 -0
  52. package/dist/core/setKeyProp.d.ts +16 -0
  53. package/dist/core/setKeyProp.js +47 -0
  54. package/dist/core/setKeysProp.d.ts +10 -0
  55. package/dist/core/setKeysProp.js +166 -0
  56. package/dist/core/setManagerProp.d.ts +34 -0
  57. package/dist/core/setManagerProp.js +54 -0
  58. package/dist/core/setShortcutProp.d.ts +9 -0
  59. package/dist/core/setShortcutProp.js +50 -0
  60. package/dist/core/setShortcutsProp.d.ts +12 -0
  61. package/dist/core/setShortcutsProp.js +93 -0
  62. package/dist/defaults/KeysSorter.d.ts +35 -0
  63. package/dist/defaults/KeysSorter.js +20 -0
  64. package/dist/defaults/Stringifier.d.ts +66 -0
  65. package/dist/defaults/Stringifier.js +119 -0
  66. package/dist/defaults/defaultConditionEquals.d.ts +19 -0
  67. package/dist/defaults/defaultConditionEquals.js +5 -0
  68. package/dist/defaults/defaultManagerCallback.d.ts +7 -0
  69. package/dist/defaults/defaultManagerCallback.js +5 -0
  70. package/dist/helpers/KnownError.d.ts +8 -0
  71. package/dist/helpers/KnownError.js +3 -0
  72. package/dist/helpers/calculateAndSetPositionAndWidth.d.ts +13 -0
  73. package/dist/helpers/calculateAndSetPositionAndWidth.js +18 -0
  74. package/dist/helpers/calculateLayoutSize.d.ts +9 -0
  75. package/dist/helpers/calculateLayoutSize.js +13 -0
  76. package/dist/helpers/doesShortcutConflict.d.ts +18 -0
  77. package/dist/helpers/doesShortcutConflict.js +42 -0
  78. package/dist/helpers/equalsCommand.d.ts +7 -0
  79. package/dist/helpers/equalsCommand.js +4 -0
  80. package/dist/helpers/equalsContext.d.ts +7 -0
  81. package/dist/helpers/equalsContext.js +19 -0
  82. package/dist/helpers/equalsShortcut.d.ts +9 -0
  83. package/dist/helpers/equalsShortcut.js +7 -0
  84. package/dist/helpers/forceClear.d.ts +12 -0
  85. package/dist/helpers/forceClear.js +16 -0
  86. package/dist/helpers/forceUpdateNativeKeysState.d.ts +5 -0
  87. package/dist/helpers/forceUpdateNativeKeysState.js +4 -0
  88. package/dist/helpers/generateKeyShortcutMap.d.ts +23 -0
  89. package/dist/helpers/generateKeyShortcutMap.js +64 -0
  90. package/dist/helpers/getKeyFromEventCode.d.ts +15 -0
  91. package/dist/helpers/getKeyFromEventCode.js +36 -0
  92. package/dist/helpers/getKeyFromIdOrVariant.d.ts +4 -0
  93. package/dist/helpers/getKeyFromIdOrVariant.js +26 -0
  94. package/dist/helpers/getKeyboardLayoutMap.d.ts +5 -0
  95. package/dist/helpers/getKeyboardLayoutMap.js +7 -0
  96. package/dist/helpers/getLabel.d.ts +9 -0
  97. package/dist/helpers/getLabel.js +6 -0
  98. package/dist/helpers/getTriggerableShortcut.d.ts +6 -0
  99. package/dist/helpers/getTriggerableShortcut.js +25 -0
  100. package/dist/helpers/index.d.ts +28 -0
  101. package/dist/helpers/index.js +28 -0
  102. package/dist/helpers/isValidManager.d.ts +3 -0
  103. package/dist/helpers/isValidManager.js +20 -0
  104. package/dist/helpers/isValidShortcut.d.ts +3 -0
  105. package/dist/helpers/isValidShortcut.js +10 -0
  106. package/dist/helpers/labelWithEvent.d.ts +13 -0
  107. package/dist/helpers/labelWithEvent.js +20 -0
  108. package/dist/helpers/labelWithKeyboardMap.d.ts +15 -0
  109. package/dist/helpers/labelWithKeyboardMap.js +17 -0
  110. package/dist/helpers/managerToStorableClone.d.ts +12 -0
  111. package/dist/helpers/managerToStorableClone.js +13 -0
  112. package/dist/helpers/onKeyboardLayoutChange.d.ts +10 -0
  113. package/dist/helpers/onKeyboardLayoutChange.js +7 -0
  114. package/dist/helpers/safeSetManagerChain.d.ts +20 -0
  115. package/dist/helpers/safeSetManagerChain.js +37 -0
  116. package/dist/helpers/shortcutCanExecuteIn.d.ts +4 -0
  117. package/dist/helpers/shortcutCanExecuteIn.js +9 -0
  118. package/dist/helpers/shortcutIsTriggerableBy.d.ts +2 -0
  119. package/dist/helpers/shortcutIsTriggerableBy.js +5 -0
  120. package/dist/helpers/shortcutSwapChords.d.ts +75 -0
  121. package/dist/helpers/shortcutSwapChords.js +118 -0
  122. package/dist/helpers/virtualPress.d.ts +13 -0
  123. package/dist/helpers/virtualPress.js +15 -0
  124. package/dist/helpers/virtualRelease.d.ts +5 -0
  125. package/dist/helpers/virtualRelease.js +15 -0
  126. package/dist/helpers/virtualToggle.d.ts +7 -0
  127. package/dist/helpers/virtualToggle.js +16 -0
  128. package/dist/internal/addToChain.d.ts +3 -0
  129. package/dist/internal/addToChain.js +27 -0
  130. package/dist/internal/areValidKeys.d.ts +7 -0
  131. package/dist/internal/areValidKeys.js +28 -0
  132. package/dist/internal/areValidVariants.d.ts +4 -0
  133. package/dist/internal/areValidVariants.js +45 -0
  134. package/dist/internal/checkTrigger.d.ts +2 -0
  135. package/dist/internal/checkTrigger.js +47 -0
  136. package/dist/internal/checkUntrigger.d.ts +2 -0
  137. package/dist/internal/checkUntrigger.js +18 -0
  138. package/dist/internal/cloneLastChord.d.ts +4 -0
  139. package/dist/internal/cloneLastChord.js +5 -0
  140. package/dist/internal/containsPossibleToggleChords.d.ts +13 -0
  141. package/dist/internal/containsPossibleToggleChords.js +65 -0
  142. package/dist/internal/errorTextAdd.d.ts +1 -0
  143. package/dist/internal/errorTextAdd.js +11 -0
  144. package/dist/internal/errorTextInUse.d.ts +1 -0
  145. package/dist/internal/errorTextInUse.js +8 -0
  146. package/dist/internal/errorTextRemove.d.ts +1 -0
  147. package/dist/internal/errorTextRemove.js +8 -0
  148. package/dist/internal/getModifierState.d.ts +2 -0
  149. package/dist/internal/getModifierState.js +7 -0
  150. package/dist/internal/getPressedKeys.d.ts +7 -0
  151. package/dist/internal/getPressedKeys.js +18 -0
  152. package/dist/internal/getPressedModifierKeys.d.ts +2 -0
  153. package/dist/internal/getPressedModifierKeys.js +10 -0
  154. package/dist/internal/getPressedNonModifierKeys.d.ts +7 -0
  155. package/dist/internal/getPressedNonModifierKeys.js +11 -0
  156. package/dist/internal/inChain.d.ts +5 -0
  157. package/dist/internal/inChain.js +14 -0
  158. package/dist/internal/isValidChain.d.ts +10 -0
  159. package/dist/internal/isValidChain.js +22 -0
  160. package/dist/internal/isValidChord.d.ts +11 -0
  161. package/dist/internal/isValidChord.js +59 -0
  162. package/dist/internal/isValidCommand.d.ts +12 -0
  163. package/dist/internal/isValidCommand.js +20 -0
  164. package/dist/internal/keyOrder.d.ts +6 -0
  165. package/dist/internal/keyOrder.js +14 -0
  166. package/dist/internal/removeFromChain.d.ts +3 -0
  167. package/dist/internal/removeFromChain.js +32 -0
  168. package/dist/internal/safeSetEmulatedToggleState.d.ts +4 -0
  169. package/dist/internal/safeSetEmulatedToggleState.js +13 -0
  170. package/dist/internal/setKeysState.d.ts +8 -0
  171. package/dist/internal/setKeysState.js +42 -0
  172. package/dist/internal/updateNativeKeysState.d.ts +14 -0
  173. package/dist/internal/updateNativeKeysState.js +58 -0
  174. package/dist/layouts/createLayout.d.ts +25 -0
  175. package/dist/layouts/createLayout.js +221 -0
  176. package/dist/module.d.mts +13 -0
  177. package/dist/module.json +9 -0
  178. package/dist/module.mjs +40 -0
  179. package/dist/runtime/composables/useLabeledByKeyboardLayoutMap.d.ts +9 -0
  180. package/dist/runtime/composables/useLabeledByKeyboardLayoutMap.js +19 -0
  181. package/dist/runtime/composables/usePointerCoords.d.ts +32 -0
  182. package/dist/runtime/composables/usePointerCoords.js +17 -0
  183. package/dist/runtime/composables/useShortcutManagerContextCount.d.ts +14 -0
  184. package/dist/runtime/composables/useShortcutManagerContextCount.js +61 -0
  185. package/dist/runtime/composables/useShortcutManagerKeysLayout.d.ts +18 -0
  186. package/dist/runtime/composables/useShortcutManagerKeysLayout.js +22 -0
  187. package/dist/runtime/composables/useShortcutManagerVirtualPress.d.ts +6 -0
  188. package/dist/runtime/composables/useShortcutManagerVirtualPress.js +24 -0
  189. package/dist/runtime/types.d.ts +10 -0
  190. package/dist/runtime/types.js +1 -0
  191. package/dist/runtime/utils/shortcutToId.d.ts +5 -0
  192. package/dist/runtime/utils/shortcutToId.js +6 -0
  193. package/dist/types/commands.d.ts +113 -0
  194. package/dist/types/commands.js +0 -0
  195. package/dist/types/condition.d.ts +29 -0
  196. package/dist/types/condition.js +0 -0
  197. package/dist/types/context.d.ts +18 -0
  198. package/dist/types/context.js +0 -0
  199. package/dist/types/enums.d.ts +186 -0
  200. package/dist/types/enums.js +70 -0
  201. package/dist/types/general.d.ts +92 -0
  202. package/dist/types/general.js +0 -0
  203. package/dist/types/index.d.ts +8 -0
  204. package/dist/types/index.js +8 -0
  205. package/dist/types/keys.d.ts +332 -0
  206. package/dist/types/keys.js +0 -0
  207. package/dist/types/manager.d.ts +249 -0
  208. package/dist/types/manager.js +0 -0
  209. package/dist/types/plugins.d.ts +1 -0
  210. package/dist/types/plugins.js +0 -0
  211. package/dist/types/shortcuts.d.ts +144 -0
  212. package/dist/types/shortcuts.js +0 -0
  213. package/dist/types/utils.d.ts +1 -0
  214. package/dist/types/utils.js +0 -0
  215. package/dist/types.d.mts +3 -0
  216. package/dist/utils/chainContainsSubset.d.ts +27 -0
  217. package/dist/utils/chainContainsSubset.js +45 -0
  218. package/dist/utils/cloneChain.d.ts +2 -0
  219. package/dist/utils/cloneChain.js +11 -0
  220. package/dist/utils/cloneKey.d.ts +3 -0
  221. package/dist/utils/cloneKey.js +26 -0
  222. package/dist/utils/containsKey.d.ts +7 -0
  223. package/dist/utils/containsKey.js +4 -0
  224. package/dist/utils/dedupeKeys.d.ts +9 -0
  225. package/dist/utils/dedupeKeys.js +9 -0
  226. package/dist/utils/equalsKey.d.ts +12 -0
  227. package/dist/utils/equalsKey.js +13 -0
  228. package/dist/utils/equalsKeys.d.ts +24 -0
  229. package/dist/utils/equalsKeys.js +15 -0
  230. package/dist/utils/index.d.ts +14 -0
  231. package/dist/utils/index.js +14 -0
  232. package/dist/utils/isAnyKey.d.ts +5 -0
  233. package/dist/utils/isAnyKey.js +5 -0
  234. package/dist/utils/isMouseKey.d.ts +5 -0
  235. package/dist/utils/isMouseKey.js +20 -0
  236. package/dist/utils/isNormalKey.d.ts +5 -0
  237. package/dist/utils/isNormalKey.js +5 -0
  238. package/dist/utils/isTriggerKey.d.ts +5 -0
  239. package/dist/utils/isTriggerKey.js +3 -0
  240. package/dist/utils/isWheelKey.d.ts +5 -0
  241. package/dist/utils/isWheelKey.js +11 -0
  242. package/dist/utils/mapKeys.d.ts +8 -0
  243. package/dist/utils/mapKeys.js +5 -0
  244. package/dist/utils/removeKeys.d.ts +7 -0
  245. package/dist/utils/removeKeys.js +4 -0
  246. package/package.json +156 -0
  247. package/src/core/EmulatedEvent.ts +29 -0
  248. package/src/core/Emulator.ts +185 -0
  249. package/src/core/ShortcutManagerManager.ts +380 -0
  250. package/src/core/addCommand.ts +24 -0
  251. package/src/core/addKey.ts +25 -0
  252. package/src/core/addShortcut.ts +24 -0
  253. package/src/core/attach.ts +27 -0
  254. package/src/core/createCommand.ts +24 -0
  255. package/src/core/createCommands.ts +45 -0
  256. package/src/core/createCondition.ts +21 -0
  257. package/src/core/createContext.ts +14 -0
  258. package/src/core/createKey.ts +59 -0
  259. package/src/core/createKeys.ts +68 -0
  260. package/src/core/createManager.ts +209 -0
  261. package/src/core/createManagerEventListeners.ts +139 -0
  262. package/src/core/createManagerOptions.ts +29 -0
  263. package/src/core/createShortcut.ts +49 -0
  264. package/src/core/createShortcuts.ts +51 -0
  265. package/src/core/detach.ts +21 -0
  266. package/src/core/index.ts +35 -0
  267. package/src/core/removeCommand.ts +25 -0
  268. package/src/core/removeKey.ts +25 -0
  269. package/src/core/removeShortcut.ts +24 -0
  270. package/src/core/setCommandProp.ts +140 -0
  271. package/src/core/setCommandsProp.ts +128 -0
  272. package/src/core/setKeyProp.ts +80 -0
  273. package/src/core/setKeysProp.ts +205 -0
  274. package/src/core/setManagerProp.ts +111 -0
  275. package/src/core/setShortcutProp.ts +89 -0
  276. package/src/core/setShortcutsProp.ts +124 -0
  277. package/src/defaults/KeysSorter.ts +55 -0
  278. package/src/defaults/Stringifier.ts +234 -0
  279. package/src/defaults/defaultConditionEquals.ts +29 -0
  280. package/src/defaults/defaultManagerCallback.ts +14 -0
  281. package/src/helpers/KnownError.ts +13 -0
  282. package/src/helpers/calculateAndSetPositionAndWidth.ts +30 -0
  283. package/src/helpers/calculateLayoutSize.ts +22 -0
  284. package/src/helpers/doesShortcutConflict.ts +72 -0
  285. package/src/helpers/equalsCommand.ts +18 -0
  286. package/src/helpers/equalsContext.ts +29 -0
  287. package/src/helpers/equalsShortcut.ts +34 -0
  288. package/src/helpers/forceClear.ts +31 -0
  289. package/src/helpers/forceUpdateNativeKeysState.ts +9 -0
  290. package/src/helpers/generateKeyShortcutMap.ts +113 -0
  291. package/src/helpers/getKeyFromEventCode.ts +67 -0
  292. package/src/helpers/getKeyFromIdOrVariant.ts +33 -0
  293. package/src/helpers/getKeyboardLayoutMap.ts +13 -0
  294. package/src/helpers/getLabel.ts +15 -0
  295. package/src/helpers/getTriggerableShortcut.ts +37 -0
  296. package/src/helpers/index.ts +30 -0
  297. package/src/helpers/isValidManager.ts +29 -0
  298. package/src/helpers/isValidShortcut.ts +20 -0
  299. package/src/helpers/labelWithEvent.ts +41 -0
  300. package/src/helpers/labelWithKeyboardMap.ts +37 -0
  301. package/src/helpers/managerToStorableClone.ts +26 -0
  302. package/src/helpers/onKeyboardLayoutChange.ts +17 -0
  303. package/src/helpers/safeSetManagerChain.ts +66 -0
  304. package/src/helpers/shortcutCanExecuteIn.ts +24 -0
  305. package/src/helpers/shortcutIsTriggerableBy.ts +15 -0
  306. package/src/helpers/shortcutSwapChords.ts +240 -0
  307. package/src/helpers/virtualPress.ts +34 -0
  308. package/src/helpers/virtualRelease.ts +25 -0
  309. package/src/helpers/virtualToggle.ts +28 -0
  310. package/src/internal/addToChain.ts +40 -0
  311. package/src/internal/areValidKeys.ts +40 -0
  312. package/src/internal/areValidVariants.ts +59 -0
  313. package/src/internal/checkTrigger.ts +55 -0
  314. package/src/internal/checkUntrigger.ts +26 -0
  315. package/src/internal/cloneLastChord.ts +10 -0
  316. package/src/internal/containsPossibleToggleChords.ts +91 -0
  317. package/src/internal/errorTextAdd.ts +18 -0
  318. package/src/internal/errorTextInUse.ts +10 -0
  319. package/src/internal/errorTextRemove.ts +10 -0
  320. package/src/internal/getModifierState.ts +15 -0
  321. package/src/internal/getPressedKeys.ts +26 -0
  322. package/src/internal/getPressedModifierKeys.ts +14 -0
  323. package/src/internal/getPressedNonModifierKeys.ts +19 -0
  324. package/src/internal/inChain.ts +25 -0
  325. package/src/internal/isValidChain.ts +42 -0
  326. package/src/internal/isValidChord.ts +87 -0
  327. package/src/internal/isValidCommand.ts +35 -0
  328. package/src/internal/keyOrder.ts +24 -0
  329. package/src/internal/removeFromChain.ts +46 -0
  330. package/src/internal/safeSetEmulatedToggleState.ts +23 -0
  331. package/src/internal/setKeysState.ts +71 -0
  332. package/src/internal/updateNativeKeysState.ts +84 -0
  333. package/src/layouts/createLayout.ts +328 -0
  334. package/src/module.ts +62 -0
  335. package/src/runtime/composables/useLabeledByKeyboardLayoutMap.ts +28 -0
  336. package/src/runtime/composables/usePointerCoords.ts +40 -0
  337. package/src/runtime/composables/useShortcutManagerContextCount.ts +81 -0
  338. package/src/runtime/composables/useShortcutManagerKeysLayout.ts +42 -0
  339. package/src/runtime/composables/useShortcutManagerVirtualPress.ts +30 -0
  340. package/src/runtime/types.ts +10 -0
  341. package/src/runtime/utils/shortcutToId.ts +14 -0
  342. package/src/types/commands.ts +148 -0
  343. package/src/types/condition.ts +35 -0
  344. package/src/types/context.ts +19 -0
  345. package/src/types/enums.ts +236 -0
  346. package/src/types/general.ts +117 -0
  347. package/src/types/index.ts +10 -0
  348. package/src/types/keys.ts +385 -0
  349. package/src/types/manager.ts +374 -0
  350. package/src/types/plugins.ts +32 -0
  351. package/src/types/shortcuts.ts +204 -0
  352. package/src/types/utils.ts +40 -0
  353. package/src/utils/chainContainsSubset.ts +97 -0
  354. package/src/utils/cloneChain.ts +13 -0
  355. package/src/utils/cloneKey.ts +33 -0
  356. package/src/utils/containsKey.ts +17 -0
  357. package/src/utils/dedupeKeys.ts +23 -0
  358. package/src/utils/equalsKey.ts +32 -0
  359. package/src/utils/equalsKeys.ts +50 -0
  360. package/src/utils/index.ts +16 -0
  361. package/src/utils/isAnyKey.ts +12 -0
  362. package/src/utils/isMouseKey.ts +27 -0
  363. package/src/utils/isNormalKey.ts +15 -0
  364. package/src/utils/isTriggerKey.ts +7 -0
  365. package/src/utils/isWheelKey.ts +18 -0
  366. package/src/utils/mapKeys.ts +21 -0
  367. package/src/utils/removeKeys.ts +16 -0
@@ -0,0 +1,374 @@
1
+ import type { AnyFunction } from "@alanscodelog/utils/types"
2
+
3
+ // eslint-disable-next-line no-restricted-imports
4
+ import type {
5
+ CanHookCommandProps,
6
+ CanHookCommandsProps,
7
+ CanHookKeyProps,
8
+ CanHookKeysProps,
9
+ CanHookShortcutProps,
10
+ CanHookShortcutsProps,
11
+ ChainError,
12
+ Command,
13
+ Commands,
14
+ CommandSetEntries,
15
+ CommandsSetEntries,
16
+ ConditionComparer,
17
+ ConditionEvaluator,
18
+ Context,
19
+ IKeysSorter,
20
+ IStringifier,
21
+ Key,
22
+ KeyboardLayoutMap,
23
+ Keys,
24
+ KeySetEntries,
25
+ KeysSetEntries,
26
+ MultipleErrors,
27
+ OnHookCommandProps,
28
+ OnHookCommandsProps,
29
+ OnHookKeyProps,
30
+ OnHookKeysProps,
31
+ OnHookShortcutProps,
32
+ OnHookShortcutsProps,
33
+ Shortcut,
34
+ SHORTCUT_ERROR,
35
+ Shortcuts,
36
+ ShortcutSetEntries,
37
+ ShortcutsSetEntries,
38
+ TriggerableShortcut
39
+ } from "./index.js"
40
+
41
+ import type { EmulatedEvent } from "../core/EmulatedEvent.js"
42
+ import type { KnownError } from "../helpers/index.js"
43
+
44
+
45
+ export type AnyInputEvent
46
+ = | KeyboardEvent
47
+ | MouseEvent
48
+ | WheelEvent
49
+ | EmulatedEvent
50
+ export type MinimalInputEvent
51
+ = (
52
+ | { button: number }
53
+ | { code?: string, key: string }
54
+ | { deltaY: number })
55
+ & Record<string, any>
56
+
57
+
58
+ export type ManagerReplaceValue = Partial<Pick<Manager, "shortcuts" | "keys" | "commands">>
59
+ export type ManagerReplaceErrors = KnownError<typeof SHORTCUT_ERROR.UNKNOWN_KEY | typeof SHORTCUT_ERROR.UNKNOWN_COMMAND>
60
+
61
+
62
+ export type ManagerListener = ({ event, keys, isKeydown, manager }: { event?: AnyInputEvent, keys: string[], isKeydown: boolean, manager: Manager }) => void
63
+
64
+ export type ExportedManager = {
65
+ shortcuts?: Shortcuts
66
+ keys?: Keys
67
+ commands?: Commands
68
+ }
69
+
70
+
71
+ export type OnHook<
72
+ TBase,
73
+ T extends Record<string, { val: any }>,
74
+ TKey extends keyof T = keyof T,
75
+ TVal extends T[TKey]["val"] = T[TKey]["val"]
76
+ >
77
+ = (obj: TBase, key: TKey, val: TVal) => void
78
+
79
+
80
+ export type CanHook<
81
+ TBase,
82
+ T extends Record<string, { val: any }>,
83
+ TKey extends keyof T = keyof T,
84
+ TVal extends T[TKey]["val"] = T[TKey]["val"],
85
+ TError extends Error = Error
86
+ >
87
+ = (obj: TBase, key: TKey, val: TVal) => TError | true
88
+
89
+ type GetManagerHooks<T extends OnHookManagerProps>
90
+ = T extends CanHookManagerProps
91
+ ? Partial<Pick<NonNullable<Manager["hooks"]>, "canSetManagerProp" | "onSetManagerProp">>
92
+ : Partial<Pick<NonNullable<Manager["hooks"]>, "onSetManagerProp">>
93
+
94
+ export type OnHookManagerProps = "state.chain" | "shortcuts" | "keys" | "commands" | `state.${keyof Manager["state"]}`
95
+ export type CanHookManagerProps = "state.chain" | "shortcuts" | "keys" | "commands" | `state.${keyof Pick<Manager["state"], "isRecording">}`
96
+ type ManagerStateHook<T extends keyof Manager["state"]> = {
97
+ val: Manager["state"][T]
98
+ manager: Manager
99
+ hooks: GetManagerHooks<`state.${T}`>
100
+ error: never
101
+ }
102
+ export type ManagerSetEntries = {
103
+ // eslint-disable-next-line @typescript-eslint/naming-convention
104
+ "state.chain": {
105
+ val: string[][]
106
+ manager: Manager
107
+ hooks: GetManagerHooks<"state.chain">
108
+ error: typeof SHORTCUT_ERROR.UNKNOWN_KEY
109
+ }
110
+ shortcuts: {
111
+ val: Shortcuts
112
+ manager: Manager
113
+ hooks: GetManagerHooks<"shortcuts">
114
+ error: typeof SHORTCUT_ERROR.UNKNOWN_COMMAND | ChainError
115
+ }
116
+ commands: {
117
+ val: Commands
118
+ manager: Manager
119
+ hooks: GetManagerHooks<"commands">
120
+ error: typeof SHORTCUT_ERROR.UNKNOWN_COMMAND
121
+ }
122
+ keys: {
123
+ val: Keys
124
+ manager: Manager
125
+ hooks: GetManagerHooks<"keys">
126
+ error: ChainError
127
+ }
128
+ // eslint-disable-next-line @typescript-eslint/naming-convention
129
+ "state.isRecording": ManagerStateHook<"isRecording">
130
+ // eslint-disable-next-line @typescript-eslint/naming-convention
131
+ "state.isAwaitingKeyup": ManagerStateHook<"isAwaitingKeyup">
132
+ // eslint-disable-next-line @typescript-eslint/naming-convention
133
+ "state.nextIsChord": ManagerStateHook<"nextIsChord">
134
+ // eslint-disable-next-line @typescript-eslint/naming-convention
135
+ "state.untrigger": ManagerStateHook<"untrigger">
136
+ }
137
+
138
+
139
+ export type CanHooks = {
140
+ canSetKeyProp?: CanHook<Key, Pick<KeySetEntries, CanHookKeyProps>>
141
+ canSetKeysProp?: CanHook<Keys, Pick<KeysSetEntries, CanHookKeysProps>>
142
+
143
+ canSetCommandProp?: CanHook<Command, Pick<CommandSetEntries, CanHookCommandProps>>
144
+ canSetCommandsProp?: CanHook<Commands, Pick<CommandsSetEntries, CanHookCommandsProps>>
145
+
146
+ canSetShortcutProp?: CanHook<Shortcut, Pick<ShortcutSetEntries, CanHookShortcutProps>>
147
+ canSetShortcutsProp?: CanHook<Shortcuts, Pick<ShortcutsSetEntries, CanHookShortcutsProps>>
148
+
149
+ canSetManagerProp?: CanHook<Manager, Pick<ManagerSetEntries, CanHookManagerProps>>
150
+ }
151
+ export type OnHooks = {
152
+ onSetKeyProp?: OnHook<Key, Pick<KeySetEntries, OnHookKeyProps>>
153
+ onSetKeysProp?: OnHook<Keys, Pick<KeysSetEntries, OnHookKeysProps>>
154
+
155
+ onSetCommandProp?: OnHook<Command, Pick<CommandSetEntries, OnHookCommandProps>>
156
+ onSetCommandsProp?: OnHook<Commands, Pick<CommandsSetEntries, OnHookCommandsProps>>
157
+
158
+ onSetShortcutProp?: OnHook<Shortcut, Pick<ShortcutSetEntries, OnHookShortcutProps>>
159
+ onSetShortcutsProp?: OnHook<Shortcuts, Pick<ShortcutsSetEntries, OnHookShortcutsProps>>
160
+
161
+ onSetManagerProp?: OnHook<Manager, Pick<ManagerSetEntries, OnHookManagerProps>>
162
+ }
163
+ export type Hooks = OnHooks & CanHooks
164
+
165
+ export type CanHookErrors<T extends CanHooks | any, TKey extends keyof T | string>
166
+ = T extends CanHooks
167
+ ? TKey extends keyof T
168
+ ? Extract<ReturnType<Extract<T[TKey], AnyFunction>>, Error>
169
+ : never
170
+ : never
171
+ export type Manager<
172
+
173
+ THooks extends Partial<Hooks> = Partial<Hooks>,
174
+ TKeys extends Keys = Keys,
175
+ TShortcuts extends Shortcuts = Shortcuts,
176
+ TCommands extends Commands = Commands,
177
+ TContext extends Context = Context,
178
+ TListener extends ManagerListener = ManagerListener
179
+ > = {
180
+ /** A name for the manager. */
181
+ name: string
182
+ type: "manager"
183
+ context: TContext
184
+ keys: TKeys
185
+ shortcuts: TShortcuts
186
+ commands: TCommands
187
+ /** Most options can be set directly, except any readonly options which must go through {@link setManagerProperties} to ensure state remains consistent. */
188
+ options: {
189
+ sorter: IKeysSorter
190
+ stringifier: IStringifier
191
+
192
+ /**
193
+ * The error callback for recoverable errors such as multiple shortcuts matching, no shortcut matching once a chord chain has been "started", or an unknown key event because no matching key was found (only for keyboard events).
194
+ *
195
+ * Usually you will want to clear the manager's chain when this happens and display the error to the user. The default callback logs the error and clears the chain.
196
+ *
197
+ * In the case of multiple valid shortcuts, if you trigger any of the shortcuts "manually" note that you will need to simulate both the keydown/keyup calls if you differentiate between them.
198
+ *
199
+ * Also the input event can be undefined if you set the manager chain directly since it will check if it should trigger shortcuts.
200
+ */
201
+
202
+ cb: (
203
+ manager: Manager,
204
+ error: MultipleErrors<
205
+ | typeof SHORTCUT_ERROR.MULTIPLE_MATCHING_SHORTCUTS
206
+ | typeof SHORTCUT_ERROR.NO_MATCHING_SHORTCUT
207
+ | typeof SHORTCUT_ERROR.UNKNOWN_KEY_EVENT
208
+ | typeof SHORTCUT_ERROR.UNKNOWN_KEY_ID
209
+ | typeof SHORTCUT_ERROR.UNKNOWN_KEY>,
210
+ e?: AnyInputEvent) => void
211
+
212
+ /**
213
+ * Determines if two conditions are equal.
214
+ *
215
+ * This is actually not a good idea to implement if you use boolean conditions. See {@link ConditionComparer} for why.
216
+ */
217
+ conditionEquals: ConditionComparer
218
+ /** Determines how conditions are evaluated. */
219
+ evaluateCondition: ConditionEvaluator<TContext>
220
+ /** Enable/disable triggering of shortcuts. The manager otherwise works as normal. */
221
+ enableShortcuts: boolean
222
+ /** Enable/disable listeners. Listeners will remain attached but do nothing. */
223
+ enableListeners: boolean
224
+ /**
225
+ * Whether to check the state of modifier or toggle keys using `event.getModifierState`.
226
+ *
227
+ * This is set to true by default when using `createManager` because it is usually what you want. It tracks the state with the most accuracy when, for example, the user focuses out, toggles a key, then focuses back.
228
+ *
229
+ * But, if you are allowing the user to change key states in some way (e.g. clicking on keys in the settings to visualize shortcuts), you will want to disable this temporarily so that they can click modifier keys. Otherwise they'd be immediately toggled off again (by the state check during the click) and nothing would happen.
230
+ *
231
+ * Keys also have their own individual {@link Key.updateStateOnAllEvents} in case you need more fine grained control.
232
+ *
233
+ * When this is set to false, the default mouseenter handler will ignore the event.
234
+ *
235
+ * If you will always have this set to false, you can forego the mouseenter event listener.
236
+ */
237
+ updateStateOnAllEvents: boolean
238
+
239
+ }
240
+ /**
241
+ * An event listener for all events the manager handles including {@link virtualPress}/{@link virtualRelease}.
242
+ *
243
+ * The listener is called right after keys are found so you can have access to the keys as the manager understood them, but before everything else (setting the state, labeling, adding/removing from the chain). Note that `isKeydown` is always true for wheel events since their keyup is emulated within the same event handler.
244
+ *
245
+ * This exists because not all events trigger shortcuts (which can access only the event that triggered them) but there are many times when you might still want access to the event to do things like `e.preventdefault()`:
246
+ *
247
+ * - When recording, we usually always need to do `e.preventDefault()` except in some rare cases:
248
+ * - For example say you have a div which records while focused, if the manager is attached to a parent element, you will have to allow clicks to the parent so losing focus stops the recording. You do not generally need to allow keys through as you can set all shortcut conditions to only trigger when not recording, temporily swap out the shortcuts while recording, or use the onSetKeyProp hook (note this would mean hardcoding keys, but might be acceptable for a case such as this).
249
+ * - We also need to `e.preventDefault()` for any chords that are also browser shortcuts (though note not all browser shortcuts can be overriden). If you really need to there is the [Keyboard API](https://developer.mozilla.org/en-US/docs/Web/API/Keyboard_API) which allows requesting some keyboard shortcuts be locked (see [Keyboard Locking](https://developer.mozilla.org/en-US/docs/Web/API/Keyboard_API#keyboard_locking)).
250
+ *
251
+ *
252
+ * The following should give you a good starting point:
253
+ *
254
+ * ```ts
255
+ * manager.listener = (({event, isKeydown, keys}) => {
256
+ * if (
257
+ * (manager.isRecording && !(event instanceof MouseEvent))
258
+ * // || TODO browser shortcuts filter
259
+ * ) {
260
+ * event.preventDefault()
261
+ * }
262
+ * })
263
+ * ```
264
+ */
265
+ listener?: TListener
266
+ /**
267
+ * Hooks provide a way to set further limits on what can be changed (can hooks), and provide listeners for when something *is* about to change (on* hooks).
268
+ *
269
+ * on* hooks allow hooking into changes for certain properties (such as key size/pos changed) to trigger recalculations (e.g. of layouts).
270
+ *
271
+ * They could also technically be used as an escape hatch for frameworks that don't support working mutable data, but I would advice against it. Instead I would recommend using a proxy based state management solution like valtio that allows for mutations and optimized rendering.
272
+ */
273
+ hooks: THooks
274
+
275
+ /**
276
+ * The manager requires some state to function and be a little bit more efficient. All properties are readonly because they should not be modified unless they are allowed to be by {@link setManagerProp}.
277
+ */
278
+ state: {
279
+ /**
280
+ * The current chain of chords.
281
+ *
282
+ * Note that the manager's chain is not neccesarily valid and should be checked before assigning to a shortcut.
283
+ *
284
+ * @RequiresSet @OnHookable @Managed
285
+ */
286
+ readonly chain: string[][]
287
+ /**
288
+ * Whether the manager is waiting for non-modifier keys to be release.
289
+ *
290
+ *@RequiresSet @OnHookable @Managed
291
+ */
292
+ readonly isAwaitingKeyup: boolean
293
+ /**
294
+ * Whether the manager is in recording mode.
295
+ *
296
+ * When enabling/disabling this property, you should clear the chain first with {@link safeSetSetManagerChain}.
297
+ *
298
+ * ```
299
+ * safeSetManagerChain(manager, [])
300
+ * setManagerProp(manager, "state.isRecording", true)
301
+ * //...
302
+ * safeSetManagerChain(manager, [])
303
+ * setManagerProp(manager, "state.isRecording", false)
304
+ * ```
305
+ *
306
+ * To allow users to record shortcuts, you can do something like have an input element that on focus starts recording and stops when focused is blurred (this has the advantage of working with keyboard navigation). In such a case, you can use the {@link Manager.listener} to `e.preventDefault()` all events except clicks outside the input. See it for more details.
307
+ *
308
+ * @RequiresSet @OnHookable @CanHookable
309
+ */
310
+ readonly isRecording: boolean
311
+ /**
312
+ * There are times, such as after a keydown event, that a shortcut command will trigger, but we also need to "untrigger" it later on key up. If there is a triggerable shortcut it is saved here. See {@link Manager.state.chain}.
313
+ *
314
+ * @RequiresSet @OnHookable @Managed
315
+ */
316
+ readonly untrigger: false | TriggerableShortcut
317
+ /**
318
+ * The manager keeps track of whether the next key press should start a new chord or not.
319
+ *
320
+ * @RequiresSet @OnHookable @Managed
321
+ */
322
+ readonly nextIsChord: boolean
323
+ }
324
+ }
325
+
326
+
327
+ export type LabelOptions = {
328
+ /**
329
+ * See {@link labelWithKeyboardMap}. This is required for label strategies that use the navigator. You can get the map using [navigator.keyboard.getLayoutMap()](https://developer.mozilla.org/en-US/docs/Web/API/Keyboard/getLayoutMap).
330
+ */
331
+ map: KeyboardLayoutMap
332
+
333
+ /**
334
+ * Filters the auto labeling.
335
+ *
336
+ * If the filter returns true, the key is not labeled.
337
+ *
338
+ * You can also use this to label the key yourself.
339
+ *
340
+ * Common filter actions:
341
+ * - Capitalize all single character keys to match what they look like on real keyboard.
342
+ * - Prevent keys with multi-line labels (e.g. `Num\nLock`, `Scroll\nLock` from getting changed).
343
+ *
344
+ * Note the event is not always a real event because if it's the navigator labeling the key or you're using the {@link Emulator} class, there isn't a real event.
345
+ */
346
+ labelFilter?: (
347
+ e: AnyInputEvent | MinimalInputEvent,
348
+ keyId: string,
349
+ label: string,
350
+ keys: Keys
351
+ ) => boolean
352
+
353
+ }
354
+
355
+ export type EventTypes = "keydown" | "keyup" | "wheel" | "mousedown" | "mouseup" | "mouseenter"
356
+
357
+ export type EventListenerTypes<T extends EventTypes = EventTypes> = {
358
+ [key in T]:
359
+ | ((
360
+ e: key extends "keydown" | "keyup"
361
+ ? KeyboardEvent
362
+ : key extends "wheel"
363
+ ? WheelEvent
364
+ : MouseEvent
365
+ ) => boolean)
366
+ | ((
367
+ e: key extends "keydown" | "keyup"
368
+ ? KeyboardEvent
369
+ : key extends "wheel"
370
+ ? WheelEvent
371
+ : MouseEvent
372
+ ) => void)
373
+ }
374
+
@@ -0,0 +1,32 @@
1
+ // /* Visualizer Plugin */
2
+ //
3
+ // export type VisualizerInfo = {
4
+ // /** List of classes to add to the key. */
5
+ // classes: /* string[] | */ VIS_KEYCLASSES[]
6
+ // /** List of classes to add to the label. */
7
+ // // eslint-disable-next-line @typescript-eslint/naming-convention
8
+ // label_classes: /* string[] | */ VIS_LABELCLASSES[] // todo
9
+ // }
10
+ //
11
+ // /* List of key classes the provided css recognizes. */
12
+ // // todo
13
+ // // eslint-disable-next-line @typescript-eslint/naming-convention
14
+ // export type VIS_KEYCLASSES =
15
+ // | "key"
16
+ // | "blank"
17
+ // | "small"
18
+ // | "medium"
19
+ // | "medium-small"
20
+ // | "medium-large"
21
+ // // TODO rename large?
22
+ // | "huge"
23
+ // | "vertical"
24
+ // | "space"
25
+ // | "flexspace"
26
+ // | "spacer"
27
+ //
28
+ // /* List of label classes the provided css recognizes. */
29
+ // // todo
30
+ // // eslint-disable-next-line @typescript-eslint/naming-convention
31
+ // export type VIS_LABELCLASSES =
32
+ // | "shrink"
@@ -0,0 +1,204 @@
1
+ import type { Command } from "./commands.js"
2
+ import type { Condition } from "./condition.js"
3
+ import type { ChainError, SHORTCUT_ERROR } from "./enums.js"
4
+ import type { PickManager } from "./general.js"
5
+ import type { Key } from "./keys.js"
6
+ import type { Manager } from "./manager.js"
7
+
8
+
9
+ /**
10
+ * Same as {@link Shortcut} except you're allowed to exclude all properties except the chain.
11
+ */
12
+ // see below for why so many generics
13
+ export interface RawShortcut<
14
+ TRawCommand extends Command["name"] | Command = Command["name"] | Command,
15
+ TCommand extends TRawCommand extends string ? Command<TRawCommand> : TRawCommand = TRawCommand extends string ? Command<TRawCommand> : TRawCommand,
16
+ TCondition extends Condition = Condition
17
+ > extends Omit<Partial<Shortcut<TCommand["name"], TCondition>>, "chain" | "command"> {
18
+ chain: (string | Key)[][]
19
+ command?: TRawCommand
20
+ }
21
+
22
+
23
+ // this has generics only so that if extending the interface,
24
+ // we can add additional properties depending on the name of the command
25
+ // and also possibly the condition, don't think others are needed
26
+ export interface Shortcut<
27
+ TCommand extends Command["name"] = Command["name"],
28
+ TCondition extends Condition = Condition
29
+ > {
30
+ type: "shortcut"
31
+ /**
32
+ * The {@link Command} to associate with the shortcut.
33
+ *
34
+ * @RequiresSet @OnHookable @CanHookable
35
+ */
36
+ readonly command?: TCommand
37
+ /**
38
+ * The {@link Condition} a shortcut is allowed to be triggered on. If both the command and the shortcut have a condition, both must be met.
39
+ *
40
+ * @RequiresSet @OnHookable @CanHookable
41
+ */
42
+ readonly condition: TCondition
43
+ /**
44
+ * Whether the shortcut is enabled. Defaults to true.
45
+ *
46
+ * @RequiresSet @OnHookable @CanHookable
47
+ */
48
+ readonly enabled: boolean
49
+ /**
50
+ * The chain of key chords that make up the shortcut. Note that this is NOT a unique identifier for shortcuts and cannot be used to compare them if you are making use of the when/context/active options.
51
+ *
52
+ * @RequiresSet @OnHookable @CanHookable
53
+ */
54
+ readonly chain: (Key["id"])[][]
55
+ /**
56
+ * It is sometimes useful for some shortcuts to not equal or conflict with eachother temporarily.
57
+ *
58
+ * Only methods that compare shortcut instances are affected.
59
+ *
60
+ * While the property is managed by the manager, it can be safely set then unset if not modifying anything.
61
+ *
62
+ * @RequiresSet @OnHookable @Managed
63
+ */
64
+ readonly forceUnequal: boolean
65
+ }
66
+
67
+ export type Shortcuts<
68
+ TEntries extends
69
+ Shortcut[] = Shortcut[]
70
+ > = {
71
+ /**
72
+ * The shortcut entries.
73
+ *
74
+ * To add/remove entries you should {@link addShortcut}/{@link removeShortcut} or {@link setShortcutsProp} with the synthetic `entries@add/remove` properties.
75
+ *
76
+ * The synthetic properties can be hooked into with {@link Manager.hooks}.
77
+ *
78
+ * @RequiresSet @OnHookable @Managed
79
+ */
80
+ readonly entries: TEntries
81
+ /**
82
+ * For {@link doesShortcutConflictWith}.
83
+ *
84
+ * @experimental
85
+ * If this is true, the manager's context will be used to check conditions agains.
86
+ *
87
+ * Given all other conditions are equal, the shortcuts can only be in conflict if they both match the context. Note this means if neither match the context they are not considered to conflict (even though they might in another context). This is meant to be used when they both match the context, but some behavior had to be chosen for when they don't.
88
+ */
89
+ useContextInConflictCheck?: boolean
90
+ /**
91
+ * For {@link doesShortcutConflictWith}.
92
+ *
93
+ * @experimental
94
+ * If this is true, modifier conflicts (e.g. `Ctrl` conflicts with `Ctrl+A`) will be ignored. You will need to figure out how to handle them manually.
95
+ */
96
+ ignoreModifierConflicts?: boolean
97
+ /**
98
+ * For {@link doesShortcutConflictWith}.
99
+ *
100
+ * @experimental
101
+ * If this is true, partial chain conflicts (e.g. `Space` conflicts with `Space+A`) will be ignored. You will need to figure out how to handle them manually.
102
+ */
103
+ ignoreChainConflicts?: boolean
104
+
105
+ }
106
+
107
+ export type RawShortcuts = Pick<Shortcuts, "entries"> & Partial<Shortcuts>
108
+
109
+ export type TriggerableShortcut = Shortcut & {
110
+ command: NonNullable<Command["name"]>
111
+ }
112
+
113
+
114
+ type GetShortcutHooks<T extends keyof ShortcutSetEntries | keyof ShortcutsSetEntries>
115
+ = T extends CanHookShortcutProps
116
+ ? Partial<Pick<NonNullable<Manager["hooks"]>, "canSetShortcutProp" | "onSetShortcutProp">>
117
+ : T extends OnHookShortcutProps
118
+ ? Partial<Pick<NonNullable<Manager["hooks"]>, "onSetShortcutProp">>
119
+ : T extends CanHookShortcutsProps
120
+ ? Partial<Pick<NonNullable<Manager["hooks"]>, "canSetShortcutsProp" | "onSetShortcutsProp">>
121
+ : Partial<Pick<NonNullable<Manager["hooks"]>, "onSetShortcutsProp">>
122
+
123
+
124
+ type BaseShortcutManager = Record<any, any>
125
+
126
+ export type ShortcutSetEntries = {
127
+ chain: {
128
+ val: Shortcut["chain"]
129
+ manager: BaseShortcutManager
130
+ & PickManager<"options", "stringifier" | "sorter">
131
+ & Pick<Manager, "shortcuts" | "commands" | "keys">
132
+ hooks: GetShortcutHooks<"chain">
133
+ error: ChainError | typeof SHORTCUT_ERROR.DUPLICATE_KEY | typeof SHORTCUT_ERROR.DUPLICATE_SHORTCUT
134
+ }
135
+ command: {
136
+ val: Shortcut["command"]
137
+ manager: BaseShortcutManager
138
+ & PickManager<"options", "stringifier">
139
+ & Pick<Manager, "commands">
140
+ & Partial<Pick<Manager, "keys">>
141
+
142
+ hooks: GetShortcutHooks<"command">
143
+ error: typeof SHORTCUT_ERROR.UNKNOWN_COMMAND
144
+ }
145
+ condition: {
146
+ val: Shortcut["condition"]
147
+ manager: never
148
+ hooks: GetShortcutHooks<"condition">
149
+ error: never
150
+ }
151
+ enabled: {
152
+ val: Shortcut["enabled"]
153
+ manager: never
154
+ hooks: GetShortcutHooks<"enabled">
155
+ error: never
156
+ }
157
+ forceUnequal: {
158
+ val: Shortcut["forceUnequal"]
159
+ manager: never
160
+ hooks: GetShortcutHooks<"forceUnequal">
161
+ error: never
162
+ }
163
+ }
164
+
165
+ export type OnHookShortcutProps
166
+ = | "chain"
167
+ | "command"
168
+ | "condition"
169
+ | "enabled"
170
+ | "forceUnequal"
171
+
172
+ export type CanHookShortcutProps = Exclude<OnHookShortcutProps, "forceUnequal">
173
+
174
+
175
+ export type SyntheticOnHookShortcutsProps = "entries@add" | "entries@remove"
176
+ export type CanHookShortcutsProps = SyntheticOnHookShortcutsProps
177
+ export type OnHookShortcutsProps = SyntheticOnHookShortcutsProps
178
+
179
+ type BaseShortcutsManager
180
+ = & Pick<Manager, "keys" | "commands" | "shortcuts">
181
+ & PickManager<"options", | "evaluateCondition" | "conditionEquals" | "stringifier">
182
+ & Record<any, any>
183
+
184
+ export type ShortcutsSetEntries = {
185
+ // eslint-disable-next-line @typescript-eslint/naming-convention
186
+ "entries@add": {
187
+ val: Shortcut
188
+ hooks: GetShortcutHooks<`entries@add`>
189
+ manager: BaseShortcutsManager
190
+ & PickManager<"options", "sorter">
191
+
192
+ error:
193
+ | typeof SHORTCUT_ERROR.DUPLICATE_SHORTCUT
194
+ | typeof SHORTCUT_ERROR.UNKNOWN_COMMAND
195
+ | ChainError
196
+ }
197
+ // eslint-disable-next-line @typescript-eslint/naming-convention
198
+ "entries@remove": {
199
+ val: Shortcut
200
+ hooks: GetShortcutHooks<`entries@remove`>
201
+ manager: BaseShortcutsManager
202
+ error: typeof SHORTCUT_ERROR.MISSING
203
+ }
204
+ }
@@ -0,0 +1,40 @@
1
+ // /* UTILITY TYPES */
2
+ // export type MakeOptional<T, TKey extends keyof T> = Omit<T, TKey> & Partial<Pick<T, TKey>>
3
+ // export type OnlyRequire<T, TKey extends keyof T> = Pick<T, TKey> & Partial<Omit<T, TKey>>
4
+ // /**
5
+ // * Converts a union/or type to an intersection/and.
6
+ // * TypeA | TypeB => TypeA & TypeB
7
+ // */
8
+ // export type OrToAnd<TUnion> = (TUnion extends any
9
+ // ? (k: TUnion) => void : never) extends ((k: infer I) => void)
10
+ // ? I : never
11
+ //
12
+ // export type DeepPartialArr<T> = {
13
+ // [P in keyof T]?: DeepPartialArr<T>[]
14
+ // }
15
+ //
16
+ // export type DeepPartialObj<T> = {
17
+ // [P in keyof T]?: DeepPartialObj<T[P]> | T[P];
18
+ // }
19
+ //
20
+ // export type Optional<T> = T | undefined
21
+ //
22
+ // /** Remove a type/s from a union. */
23
+ // export type Remove<T, TKey> = T extends TKey ? never : T
24
+ //
25
+ // /**
26
+ // * Creates record from Array (of objects) T, keyed by it's object's K property value, with values of type B.
27
+ // */
28
+ // export type RecordFromArray<
29
+ // T extends any[],
30
+ // TKey extends string & keyof T[number],
31
+ // TValue extends
32
+ // T[number] =
33
+ // T[number],
34
+ // > = Record<T[number][TKey], TValue>
35
+ //
36
+ // /**
37
+ // * Expand a record type. By default expands the record to accept any string key.
38
+ // * See any "collection" class's `add` method for example.
39
+ // */
40
+ // export type ExpandRecord<T, TKey extends string | number = keyof T & string, TValue = T[keyof T]> = T & {[ Key in TKey ]: TValue }