(
fn: T & { _withKeys?: { [k: string]: T } },
modifiers: string[],
)
| 89 | * @private |
| 90 | */ |
| 91 | export const withKeys = <T extends (event: KeyboardEvent) => any>( |
| 92 | fn: T & { _withKeys?: { [k: string]: T } }, |
| 93 | modifiers: string[], |
| 94 | ): T => { |
| 95 | let globalKeyCodes: LegacyConfig['keyCodes'] |
| 96 | let instance: ComponentInternalInstance | null = null |
| 97 | if (__COMPAT__) { |
| 98 | instance = getCurrentInstance() |
| 99 | if ( |
| 100 | compatUtils.isCompatEnabled(DeprecationTypes.CONFIG_KEY_CODES, instance) |
| 101 | ) { |
| 102 | if (instance) { |
| 103 | globalKeyCodes = (instance.appContext.config as LegacyConfig).keyCodes |
| 104 | } |
| 105 | } |
| 106 | if (__DEV__ && modifiers.some(m => /^\d+$/.test(m))) { |
| 107 | compatUtils.warnDeprecation( |
| 108 | DeprecationTypes.V_ON_KEYCODE_MODIFIER, |
| 109 | instance, |
| 110 | ) |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | const cache: { [k: string]: T } = fn._withKeys || (fn._withKeys = {}) |
| 115 | const cacheKey = modifiers.join('.') |
| 116 | |
| 117 | return ( |
| 118 | cache[cacheKey] || |
| 119 | (cache[cacheKey] = (event => { |
| 120 | if (!('key' in event)) { |
| 121 | return |
| 122 | } |
| 123 | |
| 124 | const eventKey = hyphenate(event.key) |
| 125 | if ( |
| 126 | modifiers.some( |
| 127 | k => |
| 128 | k === eventKey || |
| 129 | keyNames[k as unknown as CompatModifiers] === eventKey, |
| 130 | ) |
| 131 | ) { |
| 132 | return fn(event) |
| 133 | } |
| 134 | |
| 135 | if (__COMPAT__) { |
| 136 | const keyCode = String(event.keyCode) |
| 137 | if ( |
| 138 | compatUtils.isCompatEnabled( |
| 139 | DeprecationTypes.V_ON_KEYCODE_MODIFIER, |
| 140 | instance, |
| 141 | ) && |
| 142 | modifiers.some(mod => mod == keyCode) |
| 143 | ) { |
| 144 | return fn(event) |
| 145 | } |
| 146 | if (globalKeyCodes) { |
| 147 | for (const mod of modifiers) { |
| 148 | const codes = globalKeyCodes[mod] |
no test coverage detected