Skip to content

Commit dfda340

Browse files
committed
fix: prevent popping command palette when an input is focused
Closes tempestphp/tempest-framework#1591
1 parent 7d10b0b commit dfda340

File tree

7 files changed

+66
-64
lines changed

7 files changed

+66
-64
lines changed

bun.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"workspaces": {
44
"": {
55
"dependencies": {
6+
"@vueuse/math": "^13.9.0",
67
"highlight.js": "^11.11.1",
78
"puppeteer": "^24.11.2",
89
},
@@ -230,6 +231,8 @@
230231

231232
"@vueuse/core": ["@vueuse/[email protected]", "", { "dependencies": { "@types/web-bluetooth": "^0.0.21", "@vueuse/metadata": "13.6.0", "@vueuse/shared": "13.6.0" }, "peerDependencies": { "vue": "^3.5.0" } }, "sha512-DJbD5fV86muVmBgS9QQPddVX7d9hWYswzlf4bIyUD2dj8GC46R1uNClZhVAmsdVts4xb2jwp1PbpuiA50Qee1A=="],
232233

234+
"@vueuse/math": ["@vueuse/[email protected]", "", { "dependencies": { "@vueuse/shared": "13.9.0" }, "peerDependencies": { "vue": "^3.5.0" } }, "sha512-Qk2jqlaEGKwwe2/MBGtUd8nPpzoQPSQTfm2d30NPywjpYdpbI+WqOAE99MuSq9kIRoU7Xq3IYBtxMaLTy6lpsA=="],
235+
233236
"@vueuse/metadata": ["@vueuse/[email protected]", "", {}, "sha512-rnIH7JvU7NjrpexTsl2Iwv0V0yAx9cw7+clymjKuLSXG0QMcLD0LDgdNmXic+qL0SGvgSVPEpM9IDO/wqo1vkQ=="],
234237

235238
"@vueuse/shared": ["@vueuse/[email protected]", "", { "peerDependencies": { "vue": "^3.5.0" } }, "sha512-pDykCSoS2T3fsQrYqf9SyF0QXWHmcGPQ+qiOVjlYSzlWd9dgppB2bFSM1GgKKkt7uzn0BBMV3IbJsUfHG2+BCg=="],
@@ -542,6 +545,8 @@
542545

543546
"@tailwindcss/oxide-wasm32-wasi/tslib": ["[email protected]", "", { "bundled": true }, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="],
544547

548+
"@vueuse/math/@vueuse/shared": ["@vueuse/[email protected]", "", { "peerDependencies": { "vue": "^3.5.0" } }, "sha512-e89uuTLMh0U5cZ9iDpEI2senqPGfbPRTHM/0AaQkcxnpqjkZqDYP8rpfm7edOz8s+pOCOROEy1PIveSW8+fL5g=="],
549+
545550
"reka-ui/@vueuse/core": ["@vueuse/[email protected]", "", { "dependencies": { "@types/web-bluetooth": "^0.0.21", "@vueuse/metadata": "12.8.2", "@vueuse/shared": "12.8.2", "vue": "^3.5.13" } }, "sha512-HbvCmZdzAu3VGi/pWYm5Ut+Kd9mn1ZHnn4L5G8kOQTPs/IwIAmJoBrmYk2ckLArgMXZj0AW3n5CAejLUO+PhdQ=="],
546551

547552
"reka-ui/@vueuse/shared": ["@vueuse/[email protected]", "", { "dependencies": { "vue": "^3.5.13" } }, "sha512-dznP38YzxZoNloI0qpEfpkms8knDtaoQ6Y/sfS0L7Yki4zh40LFHEhur0odJC6xTHG5dxWVPiUWBXn+wCG2s5w=="],

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
"type": "project",
44
"description": "Documentation website for the Tempest framework",
55
"require": {
6-
"tempest/framework": "^2.2.0",
7-
"league/commonmark": "^2.7.0",
8-
"symfony/yaml": "^7.3.1",
6+
"tempest/framework": "^2.2.1",
7+
"league/commonmark": "^2.7.1",
8+
"symfony/yaml": "^7.3.3",
99
"spatie/yaml-front-matter": "^2.1",
1010
"spatie/browsershot": "^4.4",
1111
"assertchris/ellison": "^1.0.2"
1212
},
1313
"require-dev": {
14-
"phpunit/phpunit": "^12.2.5",
15-
"symfony/var-dumper": "^7.3.1",
14+
"phpunit/phpunit": "^12.4.0",
15+
"symfony/var-dumper": "^7.3.4",
1616
"carthage-software/mago": "^0.26.1",
17-
"rector/rector": "^2.1"
17+
"rector/rector": "^2.1.7"
1818
},
1919
"autoload": {
2020
"psr-4": {

composer.lock

Lines changed: 18 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@tailwindcss/vite": "^4.1.11",
1717
"@vitejs/plugin-vue": "^6.0.0",
1818
"@vueuse/core": "^13.5.0",
19+
"@vueuse/math": "^13.9.0",
1920
"fuse.js": "^7.1.0",
2021
"reka-ui": "^2.3.2",
2122
"tailwindcss": "^4.1.11",

src/Web/Code/code.view.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,25 @@
1717
</style>
1818
</x-slot>
1919

20-
<div class="hero-bg h-full flex justify-center">
21-
<div class="w-full">
22-
<x-form :action="uri([CodeController::class, 'submit'])">
23-
<x-csrf-token/>
24-
<div class="grid gap-4 max-full max-w-[66%] mx-auto">
20+
<div class="flex justify-center h-full hero-bg">
21+
<div class="flex items-center w-full grow">
22+
<form :action="uri([CodeController::class, 'submit'])" method="POST" class="w-full">
23+
<x-csrf-token />
24+
<input type="hidden" name="_method" value="POST">
25+
<div class="gap-4 grid mx-auto max-w-[66%] max-full">
2526
<input type="hidden" name="lang" :value="$language"/>
2627
<label for="code" class="text-xl">Paste your code</label>
27-
<textarea name="code" id="code" class="border-2 border-[--primary] w-full p-4 rounded bg-[var(--code-background)] text-[var(--foreground)]" rows="20" autofocus>{{ $code }}</textarea>
28+
<p class="text-(--ui-text-muted) text-sm mb-4">
29+
30+
</p>
31+
<textarea name="code" id="code" class="font-mono bg-(--code-background) p-4 border-(--ui-border-muted) border-2 rounded focus:outline-none w-full text-(--foreground)" rows="20" autofocus>{{ $code }}</textarea>
2832
<div class="flex justify-end">
29-
<input type="submit" class="no-primary rounded-md font-medium inline-flex items-center focus:outline-hidden disabled:cursor-not-allowed aria-disabled:cursor-not-allowed disabled:opacity-75 aria-disabled:opacity-75 transition-colors px-4 py-2 gap-2 ring ring-inset ring-(--ui-border-accented) text-(--ui-text) bg-(--ui-bg) hover:bg-(--ui-bg-elevated) disabled:bg-(--ui-bg) aria-disabled:bg-(--ui-bg) focus-visible:ring-2 focus-visible:ring-(--ui-border-inverted)"/>
33+
<button type="submit" class="no-primary cursor-pointer rounded-md font-medium inline-flex items-center focus:outline-hidden disabled:cursor-not-allowed aria-disabled:cursor-not-allowed disabled:opacity-75 aria-disabled:opacity-75 transition-colors px-4 py-2 gap-2 ring ring-inset ring-(--ui-border-accented) text-(--ui-text) bg-(--ui-bg) hover:bg-(--ui-bg-elevated) disabled:bg-(--ui-bg) aria-disabled:bg-(--ui-bg) focus-visible:ring-2 focus-visible:ring-(--ui-border-inverted)">
34+
Submit
35+
</button>
3036
</div>
3137
</div>
32-
</x-form>
38+
</form>
3339
</div>
3440
</div>
3541
</x-base>

src/Web/Code/code_preview.view.php

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,24 @@
11
<x-base-code>
2-
<div class="bg-red p-4 fixed z-[99] right-0 top-0 flex gap-2" :if="!$clean">
2+
<div class="top-0 right-0 z-[99] fixed flex gap-2 bg-red p-4" :if="!$clean">
33
<a
44
:href="$cleanUrl"
5-
class="
6-
cursor-pointer
7-
bg-white
8-
p-2
9-
rounded-full
10-
shadow-xl
11-
border-2 border-transparent
12-
hover:bg-tempest-blue-500
13-
hover:border-white
14-
">
5+
class="bg-white hover:bg-tempest-blue-500 shadow-xl p-2 border-2 hover:border-white border-transparent rounded-full cursor-pointer">
156
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
167
<path stroke-linecap="round" stroke-linejoin="round" d="M9 17.25v1.007a3 3 0 0 1-.879 2.122L7.5 21h9l-.621-.621A3 3 0 0 1 15 18.257V17.25m6-12V15a2.25 2.25 0 0 1-2.25 2.25H5.25A2.25 2.25 0 0 1 3 15V5.25m18 0A2.25 2.25 0 0 0 18.75 3H5.25A2.25 2.25 0 0 0 3 5.25m18 0V12a2.25 2.25 0 0 1-2.25 2.25H5.25A2.25 2.25 0 0 1 3 12V5.25" />
178
</svg>
189
</a>
1910
<a
2011
:href="$editUrl"
21-
class="
22-
cursor-pointer
23-
bg-white
24-
p-2
25-
rounded-full
26-
shadow-xl
27-
border-2 border-transparent
28-
hover:bg-tempest-blue-500
29-
hover:border-white
30-
">
12+
class="bg-white hover:bg-tempest-blue-500 shadow-xl p-2 border-2 hover:border-white border-transparent rounded-full cursor-pointer">
3113
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
3214
<path stroke-linecap="round" stroke-linejoin="round" d="m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L10.582 16.07a4.5 4.5 0 0 1-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 0 1 1.13-1.897l8.932-8.931Zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0 1 15.75 21H5.25A2.25 2.25 0 0 1 3 18.75V8.25A2.25 2.25 0 0 1 5.25 6H10"/>
3315
</svg>
3416
</a>
3517
</div>
3618

37-
<div class="flex items-center justify-center h-full absolute top-0 left-0 w-full">
19+
<div class="top-0 left-0 absolute flex justify-center items-center w-full h-full">
3820
<div
39-
class="bg-(--ui-bg) border-(--ui-border) rounded-md p-8 max-h-[75%] overflow-scroll"
21+
class="bg-(--ui-bg) border-(--ui-border) rounded-md p-8 max-h-[75%] overflow-auto"
4022
:class="implode([
4123
$center ? 'text-center' : '',
4224
$clean ?: 'border'

src/Web/CommandPalette/register-palette.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { useMagicKeys, whenever } from '@vueuse/core'
2-
import type { Ref } from 'vue'
1+
import { useActiveElement, useMagicKeys, whenever } from '@vueuse/core'
2+
import { logicAnd } from '@vueuse/math'
3+
import { computed, type Ref, watchEffect } from 'vue'
34

45
interface Options {
56
value: Ref<boolean>
@@ -13,9 +14,14 @@ export function registerPalette(options: Options) {
1314
target: document.body,
1415
passive: false,
1516
onEventFired(e) {
17+
if (['INPUT', 'TEXTAREA'].includes((e.target as Element).tagName ?? '')) {
18+
return
19+
}
20+
1621
if (e.key === '/' && e.type === 'keydown') {
1722
e.preventDefault()
1823
}
24+
1925
if (e.key === 'k' && e.type === 'keydown' && e.metaKey) {
2026
e.preventDefault()
2127
}
@@ -33,6 +39,13 @@ export function registerPalette(options: Options) {
3339
element.addEventListener('click', toggleCommandPalette)
3440
})
3541

36-
whenever(Meta_K, () => options.value.value = !options.value.value)
37-
whenever(Slash, () => options.value.value = true)
42+
const activeElement = useActiveElement()
43+
const notUsingInput = computed(() => !['INPUT', 'TEXTAREA'].includes(activeElement.value?.tagName ?? ''))
44+
45+
watchEffect(() => {
46+
console.log({ Meta_K, Slash, notUsingInput })
47+
})
48+
49+
whenever(logicAnd(Meta_K, notUsingInput), () => options.value.value = !options.value.value)
50+
whenever(logicAnd(Slash, notUsingInput), () => options.value.value = true)
3851
}

0 commit comments

Comments
 (0)