diff --git a/.changeset/alpine-hotkey-directive.md b/.changeset/alpine-hotkey-directive.md new file mode 100644 index 000000000..9ec869fe2 --- /dev/null +++ b/.changeset/alpine-hotkey-directive.md @@ -0,0 +1,5 @@ +--- +'@tanstack/alpine-hotkeys': minor +--- + +Add the `x-hotkey` directive, installed with `Alpine.plugin(hotkeyDirective)`. Name the hotkey with modifiers and give the callback as the expression: `x-hotkey.mod.s="save()"`, `x-hotkey.escape="close()"`, or `x-hotkey.g.h="goHome()"` for a sequence. The hotkey lives as long as the attribute, so a morph that changes or removes it, as Livewire does on every update, replaces or removes the hotkey. A changed `x-init="$hotkeys.createHotkey(...)"` stays registered until its element is removed. With Alpine's CSP build, name a component method: `x-hotkey.mod.s="save"`. A page that only uses `x-hotkey` doesn't ship the `$hotkeys` owners and readers. diff --git a/.changeset/ember-4-12-floor.md b/.changeset/ember-4-12-floor.md new file mode 100644 index 000000000..07c8740f2 --- /dev/null +++ b/.changeset/ember-4-12-floor.md @@ -0,0 +1,5 @@ +--- +'@tanstack/ember-hotkeys': minor +--- + +Support Ember 4.12 and newer, including the 4.12 and 5.12 LTS lines and ember-source 6.8.0 to 6.8.2, 6.9.0 and 6.10.0. The adapter tracked its state with `@ember/reactive/collections`, which only newer ember-source versions ship. It now uses `@glimmer/tracking`, which every supported version has. diff --git a/.changeset/ember-scope-defaults-order.md b/.changeset/ember-scope-defaults-order.md new file mode 100644 index 000000000..cedbbc965 --- /dev/null +++ b/.changeset/ember-scope-defaults-order.md @@ -0,0 +1,5 @@ +--- +'@tanstack/ember-hotkeys': minor +--- + +`createHotkeysScope` defaults no longer override an app hotkey's declared options. The helpers and modifiers from a scope put its defaults below the declaration, as the App Hotkeys guide says: scope defaults, then declared options, then call-site options. Before, a scope default such as `preventDefault: true` replaced `preventDefault: false` from `defineAppHotkeys`. diff --git a/.github/workflows/ember-compat.yml b/.github/workflows/ember-compat.yml new file mode 100644 index 000000000..a1df3b7e3 --- /dev/null +++ b/.github/workflows/ember-compat.yml @@ -0,0 +1,46 @@ +name: Ember Compatibility + +# The Ember adapter in classic ember-cli apps on the oldest Ember lines its peer +# range allows. The package's own tests run on a recent Ember only. +on: + pull_request: + paths: + - packages/hotkeys/src/** + - packages/hotkeys/package.json + - packages/ember-hotkeys/** + - e2e/ember-compat/** + - e2e/scripts/ember-compat.ts + - e2e/package.json + - .github/workflows/ember-compat.yml + push: + branches: [main] + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.number || github.ref }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + ember: + name: Ember ${{ matrix.ember }} + runs-on: ubuntu-latest + timeout-minutes: 20 + strategy: + fail-fast: false + matrix: + ember: ['4.12', '5.12'] + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Setup Tools + uses: TanStack/config/.github/setup@c1ef98305f122da0257951e5e2896e143bdf8173 # main + # Chrome comes with the runner image. + - name: Run Probe App + run: pnpm test:e2e:ember-compat "~${EMBER_VERSION}.0" + env: + EMBER_VERSION: ${{ matrix.ember }} diff --git a/.intent/review-state.json b/.intent/review-state.json index b28feeca3..5ea72c92b 100644 --- a/.intent/review-state.json +++ b/.intent/review-state.json @@ -3,11 +3,11 @@ "baseline": "ad56a4b0dbf3c34d8552eca2cc88c5c7000d520a", "items": { "skill:packages/alpine-hotkeys/skills/alpine-hotkeys/SKILL.md": { - "fingerprint": "ca9e3bb36fb667aa2f169fb0626252b647add734e6510a7aeddd7070149e833b", + "fingerprint": "19554ef6b5764ec9a5c186e1b25fe00a2e0b2742a8bf19f7cfac1bb55dc905d2", "snapshot": { "docs/framework/alpine/guides/app-hotkeys.md": "e0077fbe45936d6b81d61d778dc212b4a4e0cfa7df1bd99ecfd2470db1c842aa", - "docs/framework/alpine/quick-start.md": "08a69d1ed0415b4f2a85205b1de96565dcf97ef24d75cb5c6df991e531ba5cc0", - "packages/alpine-hotkeys/skills/alpine-hotkeys/SKILL.md": "6e1357a1219003b43fa74242cb5671ab0aaf5c3ffd24dcad00f571f1bd829004", + "docs/framework/alpine/quick-start.md": "822d70174d351fa7b2fe2e773b4fb3a2b558191386001025cdf2efac7b0c7854", + "packages/alpine-hotkeys/skills/alpine-hotkeys/SKILL.md": "e0403473c7a27af925d286e94c1c8e0bb0a780b03e47b816e5e96afa4da49fd5", "packages/alpine-hotkeys/skills/alpine-hotkeys/references/app-hotkeys.md": "0fb12f409b5aec0999df3799f86d116b24d4d4d00131041e63d59264a7af1c98", "packages/alpine-hotkeys/src/createAppHotkeys.ts": "4b3745b96bdbf7971347bd930b9525b740abfffbd72dfed556d36cc0cbfa6757", "packages/alpine-hotkeys/src/createHotkey.ts": "bd60563781632082d7a6be702d7761f0652e45afc36ac8aa1efae1106ae98556", @@ -17,9 +17,9 @@ "packages/alpine-hotkeys/src/hotkeysPlugin.ts": "35ffb8b772a178690d956f3b3a165b577c40d1723e186f5ffdef4a985f7be90b", "packages/alpine-hotkeys/src/scope.ts": "4521cc6c2abb1706bdd2b73e158e67b2eef7f5d325e22b1f50b65cf473b56905" }, - "head": "05be1291a103f39c2570697d44e8df5e039f4497", - "outcome": "no-change", - "reason": "The framework skill points to its guides and states no recorder output strings or macOS Command rules that changed.", + "head": "fa5664a5cecd519fc36453981e66c13049959fa4", + "outcome": "updated", + "reason": "Named the hotkeyDirective import next to the install call.", "evidence": ["packages/alpine-hotkeys/skills/alpine-hotkeys/SKILL.md"] }, "skill:packages/angular-hotkeys/skills/angular-hotkeys/SKILL.md": { @@ -43,13 +43,13 @@ ] }, "skill:packages/ember-hotkeys/skills/ember-hotkeys/SKILL.md": { - "fingerprint": "b9a8c8816fb7e610041ed1989459417b1d26537a20284a41ecc65734455521ec", + "fingerprint": "a0bae934e8fa3df1d8ba52835e06e401cdf8550a453e0d60807bd27ac1213f05", "snapshot": { "docs/framework/ember/guides/app-hotkeys.md": "0bb08f63eb9974ff3d8a0f408a3db321e16f8c6f285b1bbccd6e6b0a940ca4a7", "docs/framework/ember/quick-start.md": "2c8dc08cae925871408200ef4636adbac20cb23312d18773d726ca340c91f0e1", - "packages/ember-hotkeys/skills/ember-hotkeys/SKILL.md": "d315094e211499a2fb4d3bb83a1918a734458c150df9594416d1e412d88f7da6", + "packages/ember-hotkeys/skills/ember-hotkeys/SKILL.md": "96848b2a04a5bd52bd89107127d8c5799f0c06d2859cfb4fd6dbdda12fba4325", "packages/ember-hotkeys/skills/ember-hotkeys/references/app-hotkeys.md": "46d43786e0d2a5fca97c203f3e998bb6295ce45c16f181612973fd3788c1acc8", - "packages/ember-hotkeys/src/createHotkeysScope.ts": "850d665576c1f9f53e20d2654cb84a99a5e9fe7bfd190f9642133a6f1d3b41ee", + "packages/ember-hotkeys/src/createHotkeysScope.ts": "d7ff70b05c966c0cc62fa41254c8a0b40d4cb96cd081be5eb49878a3e148cbac", "packages/ember-hotkeys/src/onHotkey.ts": "0cd156d6a90b341d7f1006df47911b3033ba523a68758274c00df7c8cb9dfbff", "packages/ember-hotkeys/src/onHotkeys.ts": "a0ef3d3d1065ea4a28021827b363701a7efd2bb07606f9689fe58259080decc2", "packages/ember-hotkeys/src/useAppHotkeys.ts": "03a087b01789fb3297056d28a1452bafa1d07de44bc66a496d588436fcea6962", @@ -57,10 +57,13 @@ "packages/ember-hotkeys/src/useHotkeyRecorder.ts": "67e6ac60574e3d510f8d6199a5eb92303b6315051d1fb8a42decf75dcebc070b", "packages/ember-hotkeys/src/useHotkeys.ts": "963345b3720ddefec8677b9b9d9dfa2b6346e22b32f9f2034d406b43e5c5ccf8" }, - "head": "05be1291a103f39c2570697d44e8df5e039f4497", - "outcome": "no-change", - "reason": "The framework skill points to its guides and states no recorder output strings or macOS Command rules that changed.", - "evidence": ["packages/ember-hotkeys/skills/ember-hotkeys/SKILL.md"] + "head": "a0d13335f6d9976ac25ead467b4658185c741b51", + "outcome": "updated", + "reason": "The Ember version floor is now 4.12. The scope defaults order change matches what the skill and the App Hotkeys guide already say.", + "evidence": [ + "packages/ember-hotkeys/skills/ember-hotkeys/SKILL.md", + "docs/framework/ember/guides/app-hotkeys.md" + ] }, "skill:packages/hotkeys/skills/app-hotkeys/SKILL.md": { "fingerprint": "343a2d27fffcd7519a96ee497f9a4c8dcf2805157dbf564d3ead99060b77c0e8", @@ -264,13 +267,13 @@ ] }, "planning:_artifacts": { - "fingerprint": "9363e19207473b8ea4acb3cc257b5670b2730a17a7de958b100b42529ed07fae", + "fingerprint": "977bbb02f485e955e5de07bc22f25730c593026fd40239385752e100eef5f819", "snapshot": { "_artifacts/domain_map.yaml": "9020ca258eebcb3575acad17ed5fc62d53306d6e07d6dc6456c006fd8f05f94b", "_artifacts/skill_spec.md": "3dfe15cd5f88bff08bfe9492e7487f709fcec25af7576a7e81729433e6d1ebef", "_artifacts/skill_tree.yaml": "9bebee27767490316a1ef51cbb8fe40d20e22a57de71fae4c7c3b0b5131472c1", "docs/framework/alpine/guides/app-hotkeys.md": "e0077fbe45936d6b81d61d778dc212b4a4e0cfa7df1bd99ecfd2470db1c842aa", - "docs/framework/alpine/quick-start.md": "08a69d1ed0415b4f2a85205b1de96565dcf97ef24d75cb5c6df991e531ba5cc0", + "docs/framework/alpine/quick-start.md": "822d70174d351fa7b2fe2e773b4fb3a2b558191386001025cdf2efac7b0c7854", "docs/framework/angular/guides/provide-hotkeys-and-scopes.md": "3460ac6a9e5c544bfaa7c901aee1772e0b4122f4d942493998b132747929f97c", "docs/framework/angular/quick-start.md": "6853a3618a349160d18f61b97e8996c3ad4709930d4048192a724afa0b291690", "docs/framework/ember/guides/app-hotkeys.md": "0bb08f63eb9974ff3d8a0f408a3db321e16f8c6f285b1bbccd6e6b0a940ca4a7", @@ -295,7 +298,7 @@ "docs/framework/vue/guides/hotkeys-provider-and-scopes.md": "341b593efd34c0aa68c02dc95f186513d5c15139711d85c4827681ecab6af390", "docs/framework/vue/quick-start.md": "00e4e57173a5e03a8299398a1611e0a309738b0563f69e765bc10cda8fa95be1", "docs/guides/sensible-defaults.md": "96163627a03c50b44d62f49ee35eae4609445b3d7d928283391dacf79a250b6c", - "packages/alpine-hotkeys/skills/alpine-hotkeys/SKILL.md": "6e1357a1219003b43fa74242cb5671ab0aaf5c3ffd24dcad00f571f1bd829004", + "packages/alpine-hotkeys/skills/alpine-hotkeys/SKILL.md": "e0403473c7a27af925d286e94c1c8e0bb0a780b03e47b816e5e96afa4da49fd5", "packages/alpine-hotkeys/skills/alpine-hotkeys/references/app-hotkeys.md": "0fb12f409b5aec0999df3799f86d116b24d4d4d00131041e63d59264a7af1c98", "packages/alpine-hotkeys/src/createAppHotkeys.ts": "4b3745b96bdbf7971347bd930b9525b740abfffbd72dfed556d36cc0cbfa6757", "packages/alpine-hotkeys/src/createHotkey.ts": "bd60563781632082d7a6be702d7761f0652e45afc36ac8aa1efae1106ae98556", @@ -311,9 +314,9 @@ "packages/angular-hotkeys/src/injectHotkey.ts": "1e7974556713a47a9641a97466e2c5218ec4adb65efed4cec1b163756e2b9734", "packages/angular-hotkeys/src/injectHotkeyRecorder.ts": "8b4271888eee532d0674a6b6d034cdc76e06e6080988418fceb5e43756cdcaef", "packages/angular-hotkeys/src/injectHotkeys.ts": "c923eba82e55ee9f0357ea0c355eca05719c0aea806a9acbb2b4de55d2d20d42", - "packages/ember-hotkeys/skills/ember-hotkeys/SKILL.md": "d315094e211499a2fb4d3bb83a1918a734458c150df9594416d1e412d88f7da6", + "packages/ember-hotkeys/skills/ember-hotkeys/SKILL.md": "96848b2a04a5bd52bd89107127d8c5799f0c06d2859cfb4fd6dbdda12fba4325", "packages/ember-hotkeys/skills/ember-hotkeys/references/app-hotkeys.md": "46d43786e0d2a5fca97c203f3e998bb6295ce45c16f181612973fd3788c1acc8", - "packages/ember-hotkeys/src/createHotkeysScope.ts": "850d665576c1f9f53e20d2654cb84a99a5e9fe7bfd190f9642133a6f1d3b41ee", + "packages/ember-hotkeys/src/createHotkeysScope.ts": "d7ff70b05c966c0cc62fa41254c8a0b40d4cb96cd081be5eb49878a3e148cbac", "packages/ember-hotkeys/src/onHotkey.ts": "0cd156d6a90b341d7f1006df47911b3033ba523a68758274c00df7c8cb9dfbff", "packages/ember-hotkeys/src/onHotkeys.ts": "a0ef3d3d1065ea4a28021827b363701a7efd2bb07606f9689fe58259080decc2", "packages/ember-hotkeys/src/useAppHotkeys.ts": "03a087b01789fb3297056d28a1452bafa1d07de44bc66a496d588436fcea6962", @@ -395,10 +398,10 @@ "packages/vue-hotkeys/src/useHotkeyRecorder.ts": "f9090de677350d72ae3e1732eab11e5b89b5cf00021f2cc5e88d2fe3f2fb743d", "packages/vue-hotkeys/src/useHotkeys.ts": "a01bedb627cd6cad884cf59b2077c33b34289589e6a101fefb5ca1709dabb668" }, - "head": "b6df86ecbe091533369f326371ffc01b536bc37a", - "outcome": "no-change", - "reason": "Wording on how the recorder treats Windows AltGr; skills do not state it.", - "evidence": ["_artifacts"] + "head": "fa5664a5cecd519fc36453981e66c13049959fa4", + "outcome": "updated", + "reason": "Alpine skill names the directive import.", + "evidence": ["packages/alpine-hotkeys/skills/alpine-hotkeys/SKILL.md"] }, "source:.changeset/intent-skills.md": { "fingerprint": "a3f3a7466ee28fed505a518e9cd18cfda96a2282d207d73317b00d60b4430f62", @@ -1120,14 +1123,14 @@ ] }, "source:docs/framework/alpine/guides/hotkeys.md": { - "fingerprint": "dfa0f9f0f3d607cac55d227f9014132d0880b156422fce188488cda58ee94c5f", + "fingerprint": "a5aa978486678d25c698f8a31c14fcc36c3dc409c2e68c703c6f3e5d351ccad1", "snapshot": { - "docs/framework/alpine/guides/hotkeys.md": "6bc5ffd1d483ac2c9885f46977c1ccfc865b287184c9f8df2f03cb08e8ceb716" + "docs/framework/alpine/guides/hotkeys.md": "3c531778c995dd3bd60314067134188f2547e5dd3bf3cdc4af69e31c75019933" }, - "head": "1a7f595fd145e732f18293cbf39856b7f8f27017", - "outcome": "no-change", - "reason": "Dispatch and sequence fixes, replace removal, and guide updates; no skill guidance changes.", - "evidence": ["Core, adapter and e2e suites; battery 159/159"] + "head": "a0d13335f6d9976ac25ead467b4658185c741b51", + "outcome": "out-of-scope", + "reason": "Source, test, CI, or generated docs change; the skills that cover it were reviewed in their own items.", + "evidence": ["docs/framework/alpine/guides/hotkeys.md"] }, "source:docs/framework/angular/guides/hotkeys.md": { "fingerprint": "e03e407cde6dd6ae5a8d42bc8ae25df1cf109025b5c2bdcd8d2590450d082d8d", @@ -2621,16 +2624,14 @@ "evidence": ["packages/hotkeys/skills/hotkeys-core/SKILL.md"] }, "source:docs/config.json": { - "fingerprint": "23636769e54496747115ab5c2523987322da0ad0aad39a94684b0c695a7badd6", + "fingerprint": "f6d629e8af41c449a4f985ccffd9603d8a7703e94bdaab8f970a7f979289f9a2", "snapshot": { - "docs/config.json": "0ed70206117287e307db8337b3c280e22b337ba6e94ab02a4c8ee690138c7460" + "docs/config.json": "47426a418635a1d5950f8f317fd4d1e7eabedf6403c7bb5dea3f1744dc7f5a91" }, - "head": "bb8531891694fb630be3c91872f10a8377870d66", - "outcome": "no-change", - "reason": "Documentation reorganization and prose rewrite only; no public API, option, or runtime behavior changes, so skill guidance remains accurate.", - "evidence": [ - "Changed: docs/config.json at bb8531891694fb630be3c91872f10a8377870d66" - ] + "head": "a0d13335f6d9976ac25ead467b4658185c741b51", + "outcome": "out-of-scope", + "reason": "Source, test, CI, or generated docs change; the skills that cover it were reviewed in their own items.", + "evidence": ["docs/config.json"] }, "source:docs/devtools.md": { "fingerprint": "232bcf1c213622a4999fe9df77361090e77aa99e113bbb4ed747456499b52d08", @@ -2645,16 +2646,14 @@ ] }, "source:docs/installation.md": { - "fingerprint": "1dae2dfc5b0788601c2cfb1f1e6737a45f1fecfd420eafc958e85bf36b3c7b90", + "fingerprint": "33f00e0b358171abfa19d4307e29aeccf6c1e1bf1485cd472c2cec98d04fc4fa", "snapshot": { - "docs/installation.md": "32486ee11e8358922275a3bddc1fad77a6d72161bac22a845b8c4e16fabf9a21" + "docs/installation.md": "4a33dfac18204c2284d5d683d783405e522d98e62ae5e8ab4b9f8bf7cf86510e" }, - "head": "bb8531891694fb630be3c91872f10a8377870d66", - "outcome": "no-change", - "reason": "Reorganized and rewrote core and framework guides and extracted dedicated SSR and testing guides; no public API, option, or runtime behavior changes, so skill guidance remains accurate.", - "evidence": [ - "Changed: docs/installation.md at bb8531891694fb630be3c91872f10a8377870d66" - ] + "head": "a0d13335f6d9976ac25ead467b4658185c741b51", + "outcome": "out-of-scope", + "reason": "Source, test, CI, or generated docs change; the skills that cover it were reviewed in their own items.", + "evidence": ["docs/installation.md"] }, "source:nx.json": { "fingerprint": "e014971f835053ffc5ccbd92101c2526f8b5f2893ec5585cb893ea2283872953", @@ -4354,9 +4353,9 @@ "snapshot": { ".gitignore": "c38d3ddac82dce790729420c3e3cf6a9202cf8711c75677b8c997b8ec8e9458c" }, - "head": "40a7c282ad56fa8d1e118983258e52d30bd890e2", + "head": "a0d13335f6d9976ac25ead467b4658185c741b51", "outcome": "out-of-scope", - "reason": "Test timeout configuration only; no skill guidance involved.", + "reason": "Source, test, CI, or generated docs change; the skills that cover it were reviewed in their own items.", "evidence": [".gitignore"] }, "source:docs/framework/angular/guides/app-hotkeys.md": { @@ -5318,16 +5317,14 @@ ] }, "source:packages/ember-hotkeys/src/utils.ts": { - "fingerprint": "b2f3a6eae9a3500c775d5de248e0755d799499f73e1fbfc844f49850e3f98fbd", + "fingerprint": "e8b36d6adff3d41ed7788b4a442c0c210213402c7df738b9de8dc73e49a6bc46", "snapshot": { - "packages/ember-hotkeys/src/utils.ts": "dcb960b2ae9055e343b8b8a099d132a52b05c867ae1b915118a8984a1ec1e8d4" + "packages/ember-hotkeys/src/utils.ts": "1122f6dde9115e8f35e37681f6b03a499818a2748187e631e2a6974d1517f542" }, - "head": "1f0a2c627c4a18f005762600966a81e9b8daef3a", - "outcome": "no-change", - "reason": "Refactor to shared types and helpers, generated reference docs, and an example type fix; no guidance changes.", - "evidence": [ - "Behavior and public names are unchanged; reference docs are regenerated by pnpm generate-docs." - ] + "head": "a0d13335f6d9976ac25ead467b4658185c741b51", + "outcome": "out-of-scope", + "reason": "Source, test, CI, or generated docs change; the skills that cover it were reviewed in their own items.", + "evidence": ["packages/ember-hotkeys/src/utils.ts"] }, "source:packages/ember-hotkeys/tsconfig.docs.json": { "fingerprint": "5a0b923213eb2824c82df256d6984612e872d6f45f1df1166b5f9035067a6e5f", @@ -5822,28 +5819,24 @@ ] }, "source:docs/framework/ember/reference/classes/useHotkey.md": { - "fingerprint": "9f52c68f9d48ad5889e49faa5ee199109a997e3947638000527fc77350f81943", + "fingerprint": "a2f28a7e6ba804d3ba49e7bdfe4e7a237fb2cd0f57a448456aa55b44c88b5093", "snapshot": { - "docs/framework/ember/reference/classes/useHotkey.md": "1c6ab1b7c7f26f0a17fe4a8547b0f249b0fe1cb6b901b6b1b5f925193fae1b17" + "docs/framework/ember/reference/classes/useHotkey.md": "ae7ebc77c5eb66a53d8db0d8ac751c95283c1bb75b5758e755b12d4fc5247604" }, - "head": "ce272666d8aae7bebafc02b184b29fcd2e853125", - "outcome": "no-change", - "reason": "Combined test-coverage branch: tests, test setup, e2e suites, CI workflows and tooling config only. Regenerated reference pages only reorder a union type or change a node_modules path. No API or guidance change.", - "evidence": [ - "Changed: docs/framework/ember/reference/classes/useHotkey.md at ce272666d8aae7bebafc02b184b29fcd2e853125" - ] + "head": "a0d13335f6d9976ac25ead467b4658185c741b51", + "outcome": "out-of-scope", + "reason": "Source, test, CI, or generated docs change; the skills that cover it were reviewed in their own items.", + "evidence": ["docs/framework/ember/reference/classes/useHotkey.md"] }, "source:docs/framework/ember/reference/classes/useHotkeys.md": { - "fingerprint": "930d791aa75f2793c2d2f8ef3fc133aa44d3af5a7f0d53a32a791fbc52e57caf", + "fingerprint": "80b57856a54b6e58595872939a4837481aa8b0bcc342ef87e2cdef27b9dcb5ae", "snapshot": { - "docs/framework/ember/reference/classes/useHotkeys.md": "32d21321491f4453f375d8aa019829dd19440d4ce69dabcf7c7ed6564c1021cc" + "docs/framework/ember/reference/classes/useHotkeys.md": "7ec477e4076912b6dfd111e40daaf0766b3c6cd13a878ebc3c33e46aad8a7ee8" }, - "head": "ce272666d8aae7bebafc02b184b29fcd2e853125", - "outcome": "no-change", - "reason": "Combined test-coverage branch: tests, test setup, e2e suites, CI workflows and tooling config only. Regenerated reference pages only reorder a union type or change a node_modules path. No API or guidance change.", - "evidence": [ - "Changed: docs/framework/ember/reference/classes/useHotkeys.md at ce272666d8aae7bebafc02b184b29fcd2e853125" - ] + "head": "a0d13335f6d9976ac25ead467b4658185c741b51", + "outcome": "out-of-scope", + "reason": "Source, test, CI, or generated docs change; the skills that cover it were reviewed in their own items.", + "evidence": ["docs/framework/ember/reference/classes/useHotkeys.md"] }, "source:docs/reference/functions/assertValidHotkey.md": { "fingerprint": "6bba59302cab1aff80e5160f74a8a77765665dc0e51957e5647b5ed4ec1c7c6f", @@ -7094,16 +7087,14 @@ ] }, "source:packages/ember-hotkeys/src/bindings.ts": { - "fingerprint": "69616f637a63090b7b61a7e1533f572289631180fa767d898525d87b98f1c513", + "fingerprint": "70b8bd9c73c0069ae64c1a7d3fb1b6b616f678d849f01698e368e80e27f340bd", "snapshot": { - "packages/ember-hotkeys/src/bindings.ts": "155264a2ac80629fdcb2c55480caf16f5342cef95c15145852611ad3e56fffd0" + "packages/ember-hotkeys/src/bindings.ts": "97260de87f4cabe5c73b33d2aedc5f9aeaecd854b2b085ea042fcaecb60e56d1" }, - "head": "1f0a2c627c4a18f005762600966a81e9b8daef3a", - "outcome": "no-change", - "reason": "Refactor to shared types and helpers, generated reference docs, and an example type fix; no guidance changes.", - "evidence": [ - "Behavior and public names are unchanged; reference docs are regenerated by pnpm generate-docs." - ] + "head": "a0d13335f6d9976ac25ead467b4658185c741b51", + "outcome": "out-of-scope", + "reason": "Source, test, CI, or generated docs change; the skills that cover it were reviewed in their own items.", + "evidence": ["packages/ember-hotkeys/src/bindings.ts"] }, "source:packages/ember-hotkeys/tests/integration/unset-options.test.gts": { "fingerprint": "4beda11b9126af1148ee9786e807ee58e20445e2830582417b79bf16ce88139c", @@ -7362,16 +7353,14 @@ "evidence": ["pnpm generate-docs"] }, "source:docs/framework/alpine/reference/index.md": { - "fingerprint": "f6d515c74ab3cfdd84eb40560b335b86c54e9a85ca44bc3d3d2a39ab6280bd24", + "fingerprint": "b194d3230da948a9a61b8ec95978f0fa37399b99a9c111b0f8bfcb48a31bb4a7", "snapshot": { - "docs/framework/alpine/reference/index.md": "4ea3d1cdb584e0a5eaf0a38bd8ab0d6f9fcd5a7d4d101bdc9b4a3e98e05b18d1" + "docs/framework/alpine/reference/index.md": "9ff0228c3b2d39fc10b33676e848be30f7f02d487ce07eb2a8c846d4922a9696" }, - "head": "1f0a2c627c4a18f005762600966a81e9b8daef3a", - "outcome": "no-change", - "reason": "Refactor to shared types and helpers, generated reference docs, and an example type fix; no guidance changes.", - "evidence": [ - "Behavior and public names are unchanged; reference docs are regenerated by pnpm generate-docs." - ] + "head": "a0d13335f6d9976ac25ead467b4658185c741b51", + "outcome": "out-of-scope", + "reason": "Source, test, CI, or generated docs change; the skills that cover it were reviewed in their own items.", + "evidence": ["docs/framework/alpine/reference/index.md"] }, "source:docs/framework/angular/reference/functions/injectHeldKeyCodes.md": { "fingerprint": "1efff674856f6bc630b76ab066be37b9652a8e8880ede5d099a4d28c1759b707", @@ -7608,29 +7597,24 @@ "evidence": ["examples/*/*Recorder*"] }, "source:knip.json": { - "fingerprint": "a62250a7d92e10c7e1d1e2dec55fd8bd512bda34f117fb463fe113605d706651", + "fingerprint": "f5d8dcbdcd1b022476415d3bf758d58fef837874d937535825975775ece95c8f", "snapshot": { - "knip.json": "21632fa1e78cb846a87fb00fe37635a6ee7b2521e3543e3f5e7a6db008ab63ea" + "knip.json": "b03848efb8f121f2be27688292205d66cad414694635d089bfbf03fec0eb1b6c" }, - "head": "8fe6e81b5696979beb1c663ce4aac6c7d6696b77", - "outcome": "no-change", - "reason": "Shared adapter conformance suite: test-utils cases and per-adapter test harnesses only; no API or guidance change.", - "evidence": [ - "Changed: knip.json at 8fe6e81b5696979beb1c663ce4aac6c7d6696b77" - ] + "head": "a0d13335f6d9976ac25ead467b4658185c741b51", + "outcome": "out-of-scope", + "reason": "Source, test, CI, or generated docs change; the skills that cover it were reviewed in their own items.", + "evidence": ["knip.json"] }, "source:packages/alpine-hotkeys/src/index.ts": { - "fingerprint": "58c2365e8c460cb692e85c461090e292c52da2bbda31e27b6bab78bbdd2b47a9", + "fingerprint": "01dee7d5937b6f9f44e6b5ceeb1149f741438304d8ad0c32ea291e59bb6f22e6", "snapshot": { - "packages/alpine-hotkeys/src/index.ts": "ed1d39eff041713b9adce6e6bb447eb33893d8ce904d4093026a885d6401c2b8" + "packages/alpine-hotkeys/src/index.ts": "271395ed12723450a1247172aa7f4db0ba0cb57173944f4fee37a18f90757db4" }, - "head": "b627bb89ca8120dc83d9664c938ee06117579761", - "outcome": "updated", - "reason": "Source of the deprecated formatForDisplay export, a new label primitive, or JSDoc for them. The framework skill describes the label primitive and the deprecation.", - "evidence": [ - "packages/alpine-hotkeys/src/index.ts", - "git diff 7d9cccc3 -- packages/alpine-hotkeys/src/index.ts" - ] + "head": "a0d13335f6d9976ac25ead467b4658185c741b51", + "outcome": "out-of-scope", + "reason": "Source, test, CI, or generated docs change; the skills that cover it were reviewed in their own items.", + "evidence": ["packages/alpine-hotkeys/src/index.ts"] }, "source:packages/alpine-hotkeys/tests/effect-errors.test.ts": { "fingerprint": "87c77797e849ee672ca0662e839bdf35a31183c03b68b076bbaba1e946ef029e", @@ -8430,13 +8414,13 @@ "evidence": ["oxfmt.config.ts", "pnpm format:check passes"] }, "source:e2e/README.md": { - "fingerprint": "f7308362d4c2dcb06c96658008d21e9ba276ea6e04a5241e1bfe25b203cf72dc", + "fingerprint": "aea95f4a468218f55a0f29afc6592e3850bf4637e782ad4dbeba6805e59ebc18", "snapshot": { - "e2e/README.md": "ffad339ff541ed86742a1218d4e8e1c5babd34904a556224f92fe25fbb5ac4a4" + "e2e/README.md": "507d4b0c3a926df68f16b56ad7be649faba3bd17d03df61e5309fb16272d36ac" }, - "head": "2a213433c30909be875835beb9224c70d6da5eaa", + "head": "fa5664a5cecd519fc36453981e66c13049959fa4", "outcome": "out-of-scope", - "reason": "Test code and test documentation for development warnings; it carries no guidance for library users.", + "reason": "Directive key normalization, its test, and an e2e README note; the Alpine skill does not describe key normalization.", "evidence": ["e2e/README.md"] }, "source:e2e/playwright.ssr.config.ts": { @@ -18836,14 +18820,16 @@ "evidence": ["packages/hotkeys/tests/hotkey-recorder.test.ts"] }, "source:packages/hotkeys/tests/invariants/event-fuzz.test.ts": { - "fingerprint": "9bdf03502ed83aba3696306bb568db6b510e1ab2b8f3a569c520d4c3ddf48354", + "fingerprint": "30631b65172be55b9e20ee5715d647c2bfe6c78cdcce17c5e0615ee217548e1d", "snapshot": { - "packages/hotkeys/tests/invariants/event-fuzz.test.ts": "8fdfc986851cffee06827e60b7b03ea0d5b98a848da6c1bd63532b2a919599a8" + "packages/hotkeys/tests/invariants/event-fuzz.test.ts": "7dfdd7e33c74b37ec82d828a9ae023cf42ece446e7057e876a830137aae41e5c" }, - "head": "40a7c282ad56fa8d1e118983258e52d30bd890e2", - "outcome": "out-of-scope", - "reason": "Test timeout configuration only; no skill guidance involved.", - "evidence": ["packages/hotkeys/tests/invariants/event-fuzz.test.ts"] + "head": "5cbf2d91c1a15381ad5af38592181487cbd023d3", + "outcome": "updated", + "reason": "Merged test/coverage-overhaul: tests from #256 and guidance from #257-#259, reviewed in those PRs", + "evidence": [ + "Changed: packages/hotkeys/tests/invariants/event-fuzz.test.ts at 5cbf2d91c1a15381ad5af38592181487cbd023d3" + ] }, "source:packages/hotkeys/tests/invariants/fixtures.ts": { "fingerprint": "be15e0c5ef99ead69128bca52ffe28e7789431f487a0295fda72f5d6ad201641", @@ -18856,54 +18842,60 @@ "evidence": ["No skill references this file"] }, "source:packages/hotkeys/tests/invariants/matching.test.ts": { - "fingerprint": "3e9fb894f4d64a435b9d03bf62c968d14ce2bd200e10603d33ee73f5095bd43d", + "fingerprint": "060462d610627263728e7343ea9f23f8e4e4e9659729cc0ad5f8ebb0cc45e541", "snapshot": { - "packages/hotkeys/tests/invariants/matching.test.ts": "e73f80bb418a329c37ed4af49e28cf68ccd1e95fa79828e99e1bff6283207dd8" + "packages/hotkeys/tests/invariants/matching.test.ts": "0e3d36f982b69c8f79e741ac0085322c22a283980612979f0fba8f1242e1cc29" }, - "head": "40a7c282ad56fa8d1e118983258e52d30bd890e2", - "outcome": "out-of-scope", - "reason": "Test timeout configuration only; no skill guidance involved.", + "head": "263455eae65aaaae54818bf1150f6e32ffd967ec", + "outcome": "no-change", + "reason": "Test timeout only; no guidance changes.", "evidence": ["packages/hotkeys/tests/invariants/matching.test.ts"] }, "source:packages/hotkeys/tests/invariants/parse-fuzz.test.ts": { - "fingerprint": "8ad7b01d6722cbd2f1fe23fae0a7172afc42890885863b072a134718b23ac620", + "fingerprint": "717614d0339feabf4ff1e849854b2933e5ff5a45883ac69cfde0d59958fa86c0", "snapshot": { - "packages/hotkeys/tests/invariants/parse-fuzz.test.ts": "1111a66f9fa05f3a1166de480206565127b51c93c857badf5cd680d79b303ba3" + "packages/hotkeys/tests/invariants/parse-fuzz.test.ts": "23e1c950e9f9228ccb806836714478055121838ac1b579803450cfb2dc1c182a" }, - "head": "40a7c282ad56fa8d1e118983258e52d30bd890e2", - "outcome": "out-of-scope", - "reason": "Test timeout configuration only; no skill guidance involved.", - "evidence": ["packages/hotkeys/tests/invariants/parse-fuzz.test.ts"] + "head": "ce272666d8aae7bebafc02b184b29fcd2e853125", + "outcome": "no-change", + "reason": "Combined test-coverage branch: tests, test setup, e2e suites, CI workflows and tooling config only. Regenerated reference pages only reorder a union type or change a node_modules path. No API or guidance change.", + "evidence": [ + "Changed: packages/hotkeys/tests/invariants/parse-fuzz.test.ts at ce272666d8aae7bebafc02b184b29fcd2e853125" + ] }, "source:packages/hotkeys/tests/invariants/recorder-match.test.ts": { - "fingerprint": "51bcd6dc177042a767a872e4c7ec3af1f023631201767efef32975089947514e", + "fingerprint": "4ec141dbbc394567aeec6101e47e62fd4a02e5175954d013991cb1b77e8f2d41", "snapshot": { - "packages/hotkeys/tests/invariants/recorder-match.test.ts": "8d79acb7902c53d30c6be52b5762b0975227001c4efa4c57302a27d35261a862" + "packages/hotkeys/tests/invariants/recorder-match.test.ts": "c4e12a870251a42a8b5d3fad6f60e9567a9994de63f1acd5f85c310ab539aba9" }, - "head": "40a7c282ad56fa8d1e118983258e52d30bd890e2", + "head": "6305200d4b2fc98a6b0f9dd64da148a067a16163", "outcome": "out-of-scope", - "reason": "Test timeout configuration only; no skill guidance involved.", - "evidence": ["packages/hotkeys/tests/invariants/recorder-match.test.ts"] + "reason": "Test-only change: invariant tests count hotkey callbacks with a plain counter instead of vi.fn() and one sweep gets an explicit timeout. No public API, option, or runtime behavior changes.", + "evidence": [ + "Changed: packages/hotkeys/tests/invariants/recorder-match.test.ts at 6305200d4b2fc98a6b0f9dd64da148a067a16163" + ] }, "source:packages/hotkeys/tests/invariants/round-trip.test.ts": { - "fingerprint": "3251da0edd7950035074a33d6c46d87ebf1cb76dea7996cb9035e943adaa711a", + "fingerprint": "f80e36e694dd618f7fc4c34def7ed4afdb2b0c22dbef614801e5884832dced36", "snapshot": { - "packages/hotkeys/tests/invariants/round-trip.test.ts": "a9e49f76f649d3f8082c63d5ef0f014c61278897d5c8732e6238201d9e9d555a" + "packages/hotkeys/tests/invariants/round-trip.test.ts": "e93693c81fed98e32cf8b73f9f979f4ebac77fa41f2c0231e2952cfcee2f1dd7" }, - "head": "40a7c282ad56fa8d1e118983258e52d30bd890e2", - "outcome": "out-of-scope", - "reason": "Test timeout configuration only; no skill guidance involved.", - "evidence": ["packages/hotkeys/tests/invariants/round-trip.test.ts"] + "head": "ce272666d8aae7bebafc02b184b29fcd2e853125", + "outcome": "no-change", + "reason": "Combined test-coverage branch: tests, test setup, e2e suites, CI workflows and tooling config only. Regenerated reference pages only reorder a union type or change a node_modules path. No API or guidance change.", + "evidence": [ + "Changed: packages/hotkeys/tests/invariants/round-trip.test.ts at ce272666d8aae7bebafc02b184b29fcd2e853125" + ] }, "source:packages/hotkeys/tests/invariants/sequence-fuzz.test.ts": { - "fingerprint": "f9faf7cd4c81e06390e1283f5de9fe7192b5af188d8042be97daba616a9357de", + "fingerprint": "384a6ea1aa43c8df037f5b680396c867c55569c612c622537726afc7ef19febf", "snapshot": { - "packages/hotkeys/tests/invariants/sequence-fuzz.test.ts": "57a79fb2577dd7abed5d08d7046782176c34b7e2c5244ebcf4b213a6c1899bef" + "packages/hotkeys/tests/invariants/sequence-fuzz.test.ts": "e680d7614bc289a360319c8a82cf4af1cb33a59a2756b334ee0fa0556f6765b3" }, - "head": "40a7c282ad56fa8d1e118983258e52d30bd890e2", - "outcome": "out-of-scope", - "reason": "Test timeout configuration only; no skill guidance involved.", - "evidence": ["packages/hotkeys/tests/invariants/sequence-fuzz.test.ts"] + "head": "1a7f595fd145e732f18293cbf39856b7f8f27017", + "outcome": "no-change", + "reason": "Dispatch and sequence fixes, replace removal, and guide updates; no skill guidance changes.", + "evidence": ["Core, adapter and e2e suites; battery 159/159"] }, "source:packages/hotkeys/tests/recorder-options.test.ts": { "fingerprint": "4efa38b608766065daf3a9f4e5879f48e29b5238d8c9eac0ca32e87bd94b1391", @@ -19853,15 +19845,15 @@ ] }, "source:packages/ember-hotkeys/tests/integration/app-hotkeys.test.gts": { - "fingerprint": "c0a09eca64d87cbf7e135eda6018b41a81e9a9652e78db71d21e5c9c07fdcf94", + "fingerprint": "26c3c20b88507937a755d65144a668863018a35baafced5f0cc16d1174fd957c", "snapshot": { - "packages/ember-hotkeys/tests/integration/app-hotkeys.test.gts": "3e11f4d2d65879b4f4b35dd7b23119741de9cd1c9d0ad46c81bb30d08c696783" + "packages/ember-hotkeys/tests/integration/app-hotkeys.test.gts": "cc5771e08afecf8f6c110e0981633318ec03e8b0955d299459719d1b9679ce67" }, - "head": "1f0a2c627c4a18f005762600966a81e9b8daef3a", - "outcome": "no-change", - "reason": "Refactor to shared types and helpers, generated reference docs, and an example type fix; no guidance changes.", + "head": "d8b30e7a2de76168aa5adbbbf4f8b114baa30770", + "outcome": "out-of-scope", + "reason": "Test assertion made platform-independent; no skill guidance involved.", "evidence": [ - "Behavior and public names are unchanged; reference docs are regenerated by pnpm generate-docs." + "packages/ember-hotkeys/tests/integration/app-hotkeys.test.gts" ] }, "source:packages/hotkeys/tests/recorder-auto.test.ts": { @@ -20115,13 +20107,13 @@ ] }, "source:packages/ember-hotkeys/src/keyboardLayout.ts": { - "fingerprint": "7d148682f02173c2957c9d4c44e48170e9d20aec3c6a30071bf1df8d93e07bce", + "fingerprint": "f328f72ae18176cb3999cfa593f2d97b46a56ef1a3512eb29dd55e0951fc4adf", "snapshot": { - "packages/ember-hotkeys/src/keyboardLayout.ts": "0257d32102fe4b712a685d67aa4892990596d6494cb6df67434be9db354096ce" + "packages/ember-hotkeys/src/keyboardLayout.ts": "a4312e3226af8170301f5e9932569816440f1ed24a2c2cf2a4e2f7f691fba82f" }, - "head": "f993101815a9a769d0456da75313e68d89a19ff0", - "outcome": "no-change", - "reason": "Source for keyboard layout labels. The label primitive rows updated in this review cover the behavior.", + "head": "a0d13335f6d9976ac25ead467b4658185c741b51", + "outcome": "out-of-scope", + "reason": "Source, test, CI, or generated docs change; the skills that cover it were reviewed in their own items.", "evidence": ["packages/ember-hotkeys/src/keyboardLayout.ts"] }, "source:packages/ember-hotkeys/src/useKeyboardLayout.ts": { @@ -23075,14 +23067,16 @@ "evidence": ["No skill references this file"] }, "source:packages/hotkeys/tests/invariants/layouts.test.ts": { - "fingerprint": "51190fe1118b341f033f3c5d048782ae9209bf0d5beb48b9a1b08fdcd3408e89", + "fingerprint": "0baf324e9f8fc0b8771437a87082d185f5fc1908ee6e53f58efbc48528c8c9bb", "snapshot": { - "packages/hotkeys/tests/invariants/layouts.test.ts": "deb2b8d3461cd2a2a7a4ee87e7f2e73eb5d43029dee2b8675e7c39c0f57370a3" + "packages/hotkeys/tests/invariants/layouts.test.ts": "1477ec90c69a2637d73ab495fa673a72ef3dc4a51ff3c3a935be98fc48451bd9" }, - "head": "40a7c282ad56fa8d1e118983258e52d30bd890e2", + "head": "6305200d4b2fc98a6b0f9dd64da148a067a16163", "outcome": "out-of-scope", - "reason": "Test timeout configuration only; no skill guidance involved.", - "evidence": ["packages/hotkeys/tests/invariants/layouts.test.ts"] + "reason": "Test-only change: invariant tests count hotkey callbacks with a plain counter instead of vi.fn() and one sweep gets an explicit timeout. No public API, option, or runtime behavior changes.", + "evidence": [ + "Changed: packages/hotkeys/tests/invariants/layouts.test.ts at 6305200d4b2fc98a6b0f9dd64da148a067a16163" + ] }, "source:scripts/layout-table/dump-xkb.sh": { "fingerprint": "0425d7f60d1a07a1833701a3cff2a7ca45604e8a3b6e8c13999032a1dc537125", @@ -23797,14 +23791,146 @@ "evidence": ["hotkey-recorder.test.ts"] }, "source:packages/hotkeys/tests/invariants/recorder-layouts.test.ts": { - "fingerprint": "2c0722586f2b3d99f639c25d1c513d30dddb3bc71bcd8e4c3eb32898285fbb04", + "fingerprint": "26be851d8c52ebecbb39e7ef8617cb9c8fd6725682358f90dff02b825ab0ff54", "snapshot": { - "packages/hotkeys/tests/invariants/recorder-layouts.test.ts": "153c95723680c741ea1013132c38ae1dc36cd1c123ffd38474d6c574621e8958" + "packages/hotkeys/tests/invariants/recorder-layouts.test.ts": "ce747e03f0e069ae3e1fbd6b05049415ef26004be771f69f2de596e3171bec61" }, - "head": "40a7c282ad56fa8d1e118983258e52d30bd890e2", - "outcome": "out-of-scope", - "reason": "Test timeout configuration only; no skill guidance involved.", + "head": "05be1291a103f39c2570697d44e8df5e039f4497", + "outcome": "no-change", + "reason": "Covered by the app-hotkeys and hotkeys-core skill updates; generated reference, tests, e2e and guide edits need no other skill change.", "evidence": ["packages/hotkeys/tests/invariants/recorder-layouts.test.ts"] + }, + "source:.github/workflows/ember-compat.yml": { + "fingerprint": "3f32465e4aa29188af13c6fe90ed8eb2cc03d54f284433d483496a48001665eb", + "snapshot": { + ".github/workflows/ember-compat.yml": "491a0ec1fc145f6555d6f2e86c14b8a847ba2929670ffddd8111f9f2bf40ef62" + }, + "head": "a0d13335f6d9976ac25ead467b4658185c741b51", + "outcome": "out-of-scope", + "reason": "Source, test, CI, or generated docs change; the skills that cover it were reviewed in their own items.", + "evidence": [".github/workflows/ember-compat.yml"] + }, + "source:docs/framework/alpine/reference/functions/hotkeyDirective.md": { + "fingerprint": "5b0a44d19d2e7d38f5428372b4de094e537c678519786c1daf154239d24e89e6", + "snapshot": { + "docs/framework/alpine/reference/functions/hotkeyDirective.md": "51e55637d537e1155dbc21c451a95992bf47d87726a00f31dbcdb711642c8701" + }, + "head": "7604b394c7e089d1310768db2b04f7ff5701a2d4", + "outcome": "out-of-scope", + "reason": "Generated reference page; autofix updated the source line number.", + "evidence": [ + "docs/framework/alpine/reference/functions/hotkeyDirective.md" + ] + }, + "source:e2e/ember-compat/app/components/probe.hbs": { + "fingerprint": "d18ef94bdd3d54e6031f8d6729411dc7448409c6c6140a8ab0c6e5c887dc6761", + "snapshot": { + "e2e/ember-compat/app/components/probe.hbs": "e68d150880adc5b5c818d047039c552aaa01fa1c509f08d4c7ca93555ef7473a" + }, + "head": "a0d13335f6d9976ac25ead467b4658185c741b51", + "outcome": "out-of-scope", + "reason": "Source, test, CI, or generated docs change; the skills that cover it were reviewed in their own items.", + "evidence": ["e2e/ember-compat/app/components/probe.hbs"] + }, + "source:e2e/ember-compat/app/components/probe.js": { + "fingerprint": "5dcfb0475df6531747bf1af351edf17e86fbce41359378e8e8f9c7e8cc1a8105", + "snapshot": { + "e2e/ember-compat/app/components/probe.js": "34c8fd6fbfa2ed1842b4cdea011c86a6f4b98a2d8f1c52fbffb6740797717b71" + }, + "head": "a0d13335f6d9976ac25ead467b4658185c741b51", + "outcome": "out-of-scope", + "reason": "Source, test, CI, or generated docs change; the skills that cover it were reviewed in their own items.", + "evidence": ["e2e/ember-compat/app/components/probe.js"] + }, + "source:e2e/ember-compat/app/helpers/use-hotkey.js": { + "fingerprint": "a4f0ca6ad5bf4c91b0cad957c8b6e68d79df4978f225735c08579cb0d0bae91d", + "snapshot": { + "e2e/ember-compat/app/helpers/use-hotkey.js": "d883bd6fb80b624e7713d3f3623b8fb38feb0bb1d5cad0344e2938635636b4eb" + }, + "head": "a0d13335f6d9976ac25ead467b4658185c741b51", + "outcome": "out-of-scope", + "reason": "Source, test, CI, or generated docs change; the skills that cover it were reviewed in their own items.", + "evidence": ["e2e/ember-compat/app/helpers/use-hotkey.js"] + }, + "source:e2e/ember-compat/app/modifiers/on-hotkey.js": { + "fingerprint": "cd73f18f01f505cfae84482df10189768c6cbbcabed9b228883376ec5f927c84", + "snapshot": { + "e2e/ember-compat/app/modifiers/on-hotkey.js": "a535d2c814fdf5a3428dd54824076b4e1d4dde147cc83c7693e2f3b3ed6712b9" + }, + "head": "a0d13335f6d9976ac25ead467b4658185c741b51", + "outcome": "out-of-scope", + "reason": "Source, test, CI, or generated docs change; the skills that cover it were reviewed in their own items.", + "evidence": ["e2e/ember-compat/app/modifiers/on-hotkey.js"] + }, + "source:e2e/ember-compat/tests/integration/probe-test.js": { + "fingerprint": "2044c8544deba0ff0589652ce5a570466f140cc85ef2b89f519a30811d8cc88a", + "snapshot": { + "e2e/ember-compat/tests/integration/probe-test.js": "52dfa5e9f98c3f536e910711d810706ada218280398fd395221e9f7e7dea44d3" + }, + "head": "a0d13335f6d9976ac25ead467b4658185c741b51", + "outcome": "out-of-scope", + "reason": "Source, test, CI, or generated docs change; the skills that cover it were reviewed in their own items.", + "evidence": ["e2e/ember-compat/tests/integration/probe-test.js"] + }, + "source:e2e/scripts/ember-compat.ts": { + "fingerprint": "e3814d1f14c1d580c7212e15f239c2d796a3440e413e8378de9a1b6310ca2126", + "snapshot": { + "e2e/scripts/ember-compat.ts": "9b4bb5f4ad0089881491e6fa0ac3aa54afbac7aaf8801b542c5aacf6c7e4ff7a" + }, + "head": "a0d13335f6d9976ac25ead467b4658185c741b51", + "outcome": "out-of-scope", + "reason": "Source, test, CI, or generated docs change; the skills that cover it were reviewed in their own items.", + "evidence": ["e2e/scripts/ember-compat.ts"] + }, + "source:packages/alpine-hotkeys/src/hotkeyDirective.ts": { + "fingerprint": "8eb511d5f2b6d78481758dcb1651e57d60aaa0b3bad256480b4f5f980d4668c8", + "snapshot": { + "packages/alpine-hotkeys/src/hotkeyDirective.ts": "c05bfa110b0501ebffe36fc79cf09e35a3705a1fce76c64b74ba81209233868d" + }, + "head": "fa5664a5cecd519fc36453981e66c13049959fa4", + "outcome": "out-of-scope", + "reason": "Directive key normalization, its test, and an e2e README note; the Alpine skill does not describe key normalization.", + "evidence": ["packages/alpine-hotkeys/src/hotkeyDirective.ts"] + }, + "source:packages/alpine-hotkeys/tests/alpine-plugins.d.ts": { + "fingerprint": "ed56e74cbd1bc3196c9cca5b983edae6f65d3e89d6a265590b198c083ec8fd14", + "snapshot": { + "packages/alpine-hotkeys/tests/alpine-plugins.d.ts": "5372fda910724c874a7418a1de75178c7c21f3864ac41f3e482ff9704527c174" + }, + "head": "a0d13335f6d9976ac25ead467b4658185c741b51", + "outcome": "out-of-scope", + "reason": "Source, test, CI, or generated docs change; the skills that cover it were reviewed in their own items.", + "evidence": ["packages/alpine-hotkeys/tests/alpine-plugins.d.ts"] + }, + "source:packages/alpine-hotkeys/tests/csp-build.test.ts": { + "fingerprint": "557495d51ae66fa28f3480435186f08657f650ef9e430b47a0579070acb61aa3", + "snapshot": { + "packages/alpine-hotkeys/tests/csp-build.test.ts": "7abeeefbdc2a5e82ab6b1c8752cae35b90f0a688b136f8ebfd1d4ac67dc3417e" + }, + "head": "a0d13335f6d9976ac25ead467b4658185c741b51", + "outcome": "out-of-scope", + "reason": "Source, test, CI, or generated docs change; the skills that cover it were reviewed in their own items.", + "evidence": ["packages/alpine-hotkeys/tests/csp-build.test.ts"] + }, + "source:packages/alpine-hotkeys/tests/hotkey-directive.test.ts": { + "fingerprint": "368235348ffb851efdd6ea473e2f6d94509f97c4f61b338aaa6745e080a07183", + "snapshot": { + "packages/alpine-hotkeys/tests/hotkey-directive.test.ts": "0d6620ec6f956c84fb5571e23e1fe6b499ea64e4086a93aa09bf598169ece6bc" + }, + "head": "fa5664a5cecd519fc36453981e66c13049959fa4", + "outcome": "out-of-scope", + "reason": "Directive key normalization, its test, and an e2e README note; the Alpine skill does not describe key normalization.", + "evidence": ["packages/alpine-hotkeys/tests/hotkey-directive.test.ts"] + }, + "source:packages/ember-hotkeys/src/tracked.ts": { + "fingerprint": "36fd15298a16d6da406565c2de4bf1e051d9e0c64a42ecb4a64a28f5e9e79494", + "snapshot": { + "packages/ember-hotkeys/src/tracked.ts": "9c31e9e412ebf54901cd444118bdcc09663315164d42b36759e36eaeae52868e" + }, + "head": "a0d13335f6d9976ac25ead467b4658185c741b51", + "outcome": "out-of-scope", + "reason": "Source, test, CI, or generated docs change; the skills that cover it were reviewed in their own items.", + "evidence": ["packages/ember-hotkeys/src/tracked.ts"] } } } diff --git a/docs/config.json b/docs/config.json index ed107d5d3..67e6dc3ec 100644 --- a/docs/config.json +++ b/docs/config.json @@ -1623,6 +1623,10 @@ "label": "createHotkeysScope", "to": "framework/alpine/reference/functions/createHotkeysScope" }, + { + "label": "hotkeyDirective", + "to": "framework/alpine/reference/functions/hotkeyDirective" + }, { "label": "hotkeyRecorderPlugin", "to": "framework/alpine/reference/functions/hotkeyRecorderPlugin" diff --git a/docs/framework/alpine/guides/hotkeys.md b/docs/framework/alpine/guides/hotkeys.md index fe6285c3e..0ad6393af 100644 --- a/docs/framework/alpine/guides/hotkeys.md +++ b/docs/framework/alpine/guides/hotkeys.md @@ -90,7 +90,7 @@ To register hotkeys from markup, install `hotkeysPlugin` and call the same funct ``` -The plugin destroys `$hotkeys` with its element. The rest of this guide uses an owner from `createHotkeysScope`. +The plugin destroys `$hotkeys` with its element. For a fixed hotkey with the default options, the `x-hotkey` directive is shorter and follows morphs: `x-hotkey.mod.s="count++"`. See [Use the `x-hotkey` directive](../quick-start#use-the-x-hotkey-directive). The rest of this guide uses an owner from `createHotkeysScope`. ### Optional hotkeys diff --git a/docs/framework/alpine/quick-start.md b/docs/framework/alpine/quick-start.md index 3b1bdba60..0ea721f08 100644 --- a/docs/framework/alpine/quick-start.md +++ b/docs/framework/alpine/quick-start.md @@ -43,9 +43,33 @@ Destroying the owner unregisters every hotkey it created. The adapter runs in th That's all a hotkey needs. Shared defaults, scopes, and the other features later in this guide are optional, so add them as your app grows. +### Use the `x-hotkey` directive + +To register a hotkey in markup, install `hotkeyDirective` and name the hotkey with modifiers. The expression runs when the hotkey fires, with `$event` set to the keyboard event: + +```ts +import Alpine from 'alpinejs' +import { hotkeyDirective } from '@tanstack/alpine-hotkeys' + +Alpine.plugin(hotkeyDirective) +Alpine.start() +``` + +```html +
+ Saved times +
+``` + +HTML lowercases attribute names, so write each part in lowercase and multi-word keys with dashes: `x-hotkey.mod.shift.k`, `x-hotkey.escape`, `x-hotkey.arrow-up`, `x-hotkey.f2`. Write modifiers before their key. Each key ends a step, so `x-hotkey.g.h` is the sequence `['G', 'H']`, and `x-hotkey.s.mod`, with no key after `mod`, registers nothing. + +The hotkey uses the built-in defaults and lives as long as the attribute. Alpine removes it with its element, and when a morph changes or removes the attribute, as Livewire does on every update. For options, a hotkey that changes with state, or a key that can't be written in an attribute name, such as `?` or `[KeyW]`, use `$hotkeys` or an owner from `createHotkeysScope`. + +`hotkeyDirective` is a separate plugin from `hotkeysPlugin`. A page that only uses `x-hotkey` doesn't ship the owners and readers that `$hotkeys` holds. + ### Use the `$hotkeys` magic -The plugin also adds the `$hotkeys` magic, which registers hotkeys from markup: +`hotkeysPlugin` also adds the `$hotkeys` magic, which takes the same arguments as an owner from `createHotkeysScope`: ```html
@@ -57,6 +81,26 @@ The plugin also adds the `$hotkeys` magic, which registers hotkeys from markup: Call `$hotkeys.create*` in `x-init` or `init()`, and read `.value` anywhere. In a reactive expression such as `x-text`, each evaluation calls `create*` again and adds a new subscription. +Alpine runs `x-init` again when a morph changes it, but `$hotkeys` keeps its registrations until its element is removed. On pages that Livewire or `Alpine.morph` updates, a changed `x-init` hotkey stays registered next to the new one. Use `x-hotkey`, or an `Alpine.data` component that destroys its owner in `destroy()`, on those pages. + +### Alpine's CSP build + +The CSP build of Alpine, `@alpinejs/csp`, can't parse arrow functions, so `x-init="$hotkeys.createHotkey('Mod+S', () => save())"` registers nothing. Move the callback into an `Alpine.data` component, and name the method in `x-hotkey`: + +```ts +Alpine.data('editor', () => ({ + save() { + // ... + }, +})) +``` + +```html +
+``` + +A call such as `x-hotkey.mod.s="save()"` needs `@alpinejs/csp` 3.15 or newer, because older CSP builds only run a method by name. The `init()` pattern from [Register a hotkey](#register-a-hotkey) also works, because the callback lives in JavaScript, not in markup. + ## Register several hotkeys When a component has more than one hotkey, register them together with `createHotkeys`: diff --git a/docs/framework/alpine/reference/functions/hotkeyDirective.md b/docs/framework/alpine/reference/functions/hotkeyDirective.md new file mode 100644 index 000000000..bf721ec70 --- /dev/null +++ b/docs/framework/alpine/reference/functions/hotkeyDirective.md @@ -0,0 +1,27 @@ +--- +id: hotkeyDirective +title: hotkeyDirective +--- + + + +```ts +function hotkeyDirective(alpine): void; +``` + +Defined in: [hotkeyDirective.ts:46](https://github.com/TanStack/hotkeys/blob/main/packages/alpine-hotkeys/src/hotkeyDirective.ts#L46) + +Installs `x-hotkey`, which registers the hotkey named by its modifiers while +its element exists: `x-hotkey.mod.s="save()"`, `x-hotkey.escape="close()"`, +`x-hotkey.g.h="goHome()"`. The expression gets `$event`. Alpine removes the +hotkey with its element, and when a morph changes or removes the attribute. + +## Parameters + +### alpine + +`Alpine` + +## Returns + +`void` diff --git a/docs/framework/alpine/reference/index.md b/docs/framework/alpine/reference/index.md index 30e6db0f4..b49ded78e 100644 --- a/docs/framework/alpine/reference/index.md +++ b/docs/framework/alpine/reference/index.md @@ -31,5 +31,6 @@ title: "@tanstack/alpine-hotkeys" - [createHotkeyRecorder](functions/createHotkeyRecorder.md) - [createHotkeysScope](functions/createHotkeysScope.md) +- [hotkeyDirective](functions/hotkeyDirective.md) - [hotkeyRecorderPlugin](functions/hotkeyRecorderPlugin.md) - [hotkeysPlugin](functions/hotkeysPlugin.md) diff --git a/docs/framework/ember/reference/classes/useHotkey.md b/docs/framework/ember/reference/classes/useHotkey.md index efe41b5b5..8cc930874 100644 --- a/docs/framework/ember/reference/classes/useHotkey.md +++ b/docs/framework/ember/reference/classes/useHotkey.md @@ -1650,8 +1650,11 @@ coalesced manner. \| ((`properties`) => `void`) \| (() => `void`) \| `DirtyableTag` + \| ((...`args`) => `any`) \| ((...`args`) => `this`) \| (() => `this`) + \| (() => `void`) + \| (() => `string`) \| (\{ \<`K`\> (`key`): `UseHotkey`\[`K`\]; (`key`): `unknown`; @@ -1683,9 +1686,6 @@ coalesced manner. \| ((`keyName`, `decrement?`) => `number`) \| ((`keyName`) => `boolean`) \| (\<`K`\>(`key`) => `unknown`) - \| ((...`args`) => `any`) - \| (() => `void`) - \| (() => `string`) \| `undefined` ##### Parameters diff --git a/docs/framework/ember/reference/classes/useHotkeys.md b/docs/framework/ember/reference/classes/useHotkeys.md index b5e02a3a1..e5cd37205 100644 --- a/docs/framework/ember/reference/classes/useHotkeys.md +++ b/docs/framework/ember/reference/classes/useHotkeys.md @@ -1633,6 +1633,9 @@ coalesced manner. \| ((`positional`, `options`) => `void`) \| `Owner` \| `DirtyableTag` + \| ((...`args`) => `any`) + \| (() => `void`) + \| (() => `string`) \| ((`properties`) => `void`) \| (() => `void`) \| ((...`args`) => `this`) @@ -1668,9 +1671,6 @@ coalesced manner. \| ((`keyName`, `decrement?`) => `number`) \| ((`keyName`) => `boolean`) \| (\<`K`\>(`key`) => `unknown`) - \| ((...`args`) => `any`) - \| (() => `void`) - \| (() => `string`) \| `undefined` ##### Parameters diff --git a/docs/installation.md b/docs/installation.md index be370aefa..56f30dda8 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -78,7 +78,7 @@ Start with the [Alpine Quick Start](./framework/alpine/quick-start) and [Alpine # Ember -Requires Ember 6.8.3 or newer (excluding 6.9.0 and 6.10.0), and works with Vite (Embroider) or classic `ember-cli` with `ember-auto-import`. Register hotkeys in strict-mode `.gts` components and pass the component as owner to state readers and recorders. +Requires Ember 4.12 or newer, and works with Vite (Embroider) or classic `ember-cli` with `ember-auto-import` 2. Register hotkeys in strict-mode `.gts` components and pass the component as owner to state readers and recorders. Start with the [Ember Quick Start](./framework/ember/quick-start) and [Ember guides](./framework/ember/guides/hotkeys). Ember ships the hotkeys adapter only and has no dedicated devtools package. diff --git a/e2e/README.md b/e2e/README.md index 906b47582..2f51f9cce 100644 --- a/e2e/README.md +++ b/e2e/README.md @@ -2,13 +2,14 @@ Browser tests for `@tanstack/hotkeys`, run with Playwright against the library source. -| Suite | Command | Browsers | Keys | -| ------------------------------- | ------------------------------ | ------------------------------- | ----------------------------------------------- | -| Browser behavior (`browser/`) | `pnpm test:e2e` | Chromium, Firefox, WebKit | Playwright's simulated keyboard | -| Adapters (`adapters/`) | `pnpm test:e2e:adapters` | Chromium, Firefox, WebKit | Playwright's simulated keyboard | -| Keyboard layouts (`layouts/`) | `pnpm test:e2e:layouts:docker` | Chromium, Firefox | Real key presses through Linux keyboard layouts | -| Server rendering (`ssr/`) | `pnpm test:e2e:ssr` | Chromium | Playwright's simulated keyboard | -| Real input, nightly (`native/`) | `pnpm test:e2e:native` | Chromium, Edge, Chrome, Firefox | Real key presses on Windows, Wayland, and ibus | +| Suite | Command | Browsers | Keys | +| ------------------------------------- | -------------------------------------- | ------------------------------- | ----------------------------------------------- | +| Browser behavior (`browser/`) | `pnpm test:e2e` | Chromium, Firefox, WebKit | Playwright's simulated keyboard | +| Adapters (`adapters/`) | `pnpm test:e2e:adapters` | Chromium, Firefox, WebKit | Playwright's simulated keyboard | +| Keyboard layouts (`layouts/`) | `pnpm test:e2e:layouts:docker` | Chromium, Firefox | Real key presses through Linux keyboard layouts | +| Server rendering (`ssr/`) | `pnpm test:e2e:ssr` | Chromium | Playwright's simulated keyboard | +| Ember compatibility (`ember-compat/`) | `pnpm test:e2e:ember-compat ` | Chrome | Synthetic events in Ember's test runner | +| Real input, nightly (`native/`) | `pnpm test:e2e:native` | Chromium, Edge, Chrome, Firefox | Real key presses on Windows, Wayland, and ibus | Run the commands from the repository root or from `e2e/`. Install browsers once with `pnpm --filter @tanstack/hotkeys-e2e exec playwright install`. @@ -53,6 +54,14 @@ For each example and for a Mac and a Windows user agent, the tests check that: To add an example, add it to `ssr/examples.ts` with an unused port and the command that starts its production server. +## Ember compatibility + +The Ember adapter supports `ember-source` 4.12 and newer, but its own tests run on a recent Ember only. This check runs it in a classic ember-cli app on an older Ember. `scripts/ember-compat.ts` generates the app with the given ember-cli version, copies in the probe component and test from `ember-compat/`, installs the packed core and adapter, and runs `ember test`. The test registers a hotkey with the `useHotkey` helper and one with the `onHotkey` modifier, fires both, reads held keys, a key hold and a hint, and checks that teardown unregisters everything. + +Run `pnpm test:e2e:ember-compat "~4.12.0"` from the repository root: it builds the core and the adapter, then runs the check. Run `pnpm --filter @tanstack/hotkeys-e2e test:e2e:ember-compat "~4.12.0"` to skip the build. A second argument sets the `ember-source` version. The app is generated in a temporary folder and needs network access. The script runs on macOS and Linux. The check uses Chrome; set `TESTEM_BROWSER="Headless Edge"` where only Edge is installed. + +CI runs it on 4.12 and 5.12 for pull requests that change the core source or the Ember adapter, and after each merge to `main`. + ## Keyboard layouts These tests switch the X11 keyboard layout with `setxkbmap` and press physical keys with `xdotool`. The browser receives the same events a user's keyboard would produce on that layout. Cases cover AltGr, AZERTY, QWERTZ, Dvorak, Russian (alone and with a US group), dead keys, Turkish dotless i, the Czech digit row, the ISO and JIS extra keys (UK, Brazilian ABNT2, Japanese), and the numpad with NumLock on and off. diff --git a/e2e/ember-compat/app/components/probe.hbs b/e2e/ember-compat/app/components/probe.hbs new file mode 100644 index 000000000..e7f5a72f2 --- /dev/null +++ b/e2e/ember-compat/app/components/probe.hbs @@ -0,0 +1,7 @@ +{{use-hotkey 'Control+S' this.save}} +{{this.count}} +{{this.heldText}} +{{if this.hold.value 'held' 'up'}} +{{if this.hint.value 'on' 'off'}} +{{this.formatForDisplay 'Control+S'}} +
\ No newline at end of file diff --git a/e2e/ember-compat/app/components/probe.js b/e2e/ember-compat/app/components/probe.js new file mode 100644 index 000000000..bcd966eb0 --- /dev/null +++ b/e2e/ember-compat/app/components/probe.js @@ -0,0 +1,25 @@ +import { action } from '@ember/object' +import Component from '@glimmer/component' +import { tracked } from '@glimmer/tracking' +import { + useFormatForDisplay, + useHeldKeys, + useHotkeyHint, + useKeyHold, +} from '@tanstack/ember-hotkeys' + +export default class Probe extends Component { + @tracked count = 0 + held = useHeldKeys(this) + hold = useKeyHold(this, 'Control') + hint = useHotkeyHint(this, 'Control+S') + formatForDisplay = useFormatForDisplay() + + get heldText() { + return this.held.value.join(',') + } + + @action save() { + this.count++ + } +} diff --git a/e2e/ember-compat/app/helpers/use-hotkey.js b/e2e/ember-compat/app/helpers/use-hotkey.js new file mode 100644 index 000000000..3b5fc858c --- /dev/null +++ b/e2e/ember-compat/app/helpers/use-hotkey.js @@ -0,0 +1 @@ +export { useHotkey as default } from '@tanstack/ember-hotkeys' diff --git a/e2e/ember-compat/app/modifiers/on-hotkey.js b/e2e/ember-compat/app/modifiers/on-hotkey.js new file mode 100644 index 000000000..f1fa609a6 --- /dev/null +++ b/e2e/ember-compat/app/modifiers/on-hotkey.js @@ -0,0 +1 @@ +export { onHotkey as default } from '@tanstack/ember-hotkeys' diff --git a/e2e/ember-compat/tests/integration/probe-test.js b/e2e/ember-compat/tests/integration/probe-test.js new file mode 100644 index 000000000..dddb0d415 --- /dev/null +++ b/e2e/ember-compat/tests/integration/probe-test.js @@ -0,0 +1,60 @@ +import { render, settled, clearRender, focus } from '@ember/test-helpers' +import { VERSION } from '@ember/version' +import { getHotkeyManager } from '@tanstack/ember-hotkeys' +import { hbs } from 'ember-cli-htmlbars' +import { setupRenderingTest } from 'ember-qunit' +import { module, test } from 'qunit' + +function key(target, type, init) { + target.dispatchEvent( + new KeyboardEvent(type, { bubbles: true, cancelable: true, ...init }), + ) +} + +module('tanstack ember-hotkeys probe', function (hooks) { + setupRenderingTest(hooks) + + test('helper, modifier, readers and teardown', async function (assert) { + assert.ok(true, `ember-source ${VERSION}`) + await render(hbs``) + await settled() + assert.strictEqual( + getHotkeyManager().registrations.state.size, + 2, + 'helper and modifier registered', + ) + assert.dom('#hint').hasText('off') + assert.dom('#label').hasAnyText() + + key(document.body, 'keydown', { + key: 'Control', + code: 'ControlLeft', + ctrlKey: true, + }) + await settled() + assert.dom('#held').hasText('Control', 'held keys tracked') + assert.dom('#hold').hasText('held', 'key hold tracked') + assert.dom('#hint').hasText('on', 'hint tracked') + + key(document.body, 'keydown', { key: 's', code: 'KeyS', ctrlKey: true }) + await settled() + assert.dom('#count').hasText('1', 'helper hotkey fired') + key(document.body, 'keyup', { key: 's', code: 'KeyS', ctrlKey: true }) + key(document.body, 'keyup', { key: 'Control', code: 'ControlLeft' }) + await settled() + assert.dom('#held').hasText('', 'released') + assert.dom('#hint').hasText('off') + + await focus('#el') + key(document.querySelector('#el'), 'keydown', { key: 'k', code: 'KeyK' }) + await settled() + assert.dom('#count').hasText('2', 'modifier hotkey fired') + + await clearRender() + assert.strictEqual( + getHotkeyManager().registrations.state.size, + 0, + 'teardown', + ) + }) +}) diff --git a/e2e/package.json b/e2e/package.json index 5842e04de..eea8bdd21 100644 --- a/e2e/package.json +++ b/e2e/package.json @@ -5,6 +5,7 @@ "scripts": { "test:e2e": "playwright test", "test:e2e:adapters": "playwright test --config playwright.adapters.config.ts", + "test:e2e:ember-compat": "node scripts/ember-compat.ts", "test:e2e:layouts": "playwright test --config playwright.layouts.config.ts", "test:e2e:layouts:docker": "node scripts/layouts-docker.ts", "test:e2e:native": "playwright test --config playwright.native.config.ts", diff --git a/e2e/scripts/ember-compat.ts b/e2e/scripts/ember-compat.ts new file mode 100644 index 000000000..f485bf136 --- /dev/null +++ b/e2e/scripts/ember-compat.ts @@ -0,0 +1,107 @@ +// Runs the Ember adapter in a classic ember-cli app on an older Ember, to guard +// the `ember-source` peer range. The package's own tests need a recent Ember, +// so this generates an app with the given ember-cli version, copies in the +// probe from `e2e/ember-compat`, installs the packed core and adapter, and +// runs `ember test`. Build both packages first, or run the root script. +// +// Usage: node scripts/ember-compat.ts [ember-source version] +// The browser is Chrome, or `TESTEM_BROWSER`, such as `Headless Edge`. +import { execFileSync } from 'node:child_process' +import { + cpSync, + mkdtempSync, + readFileSync, + readdirSync, + writeFileSync, +} from 'node:fs' +import { tmpdir } from 'node:os' +import { join } from 'node:path' +import { fileURLToPath } from 'node:url' + +const [cliVersion, sourceVersion] = process.argv.slice(2) +if (!cliVersion) { + console.error( + 'Usage: node scripts/ember-compat.ts [ember-source version]', + ) + process.exit(1) +} + +const rootDir = fileURLToPath(new URL('../..', import.meta.url)) +const probeDir = fileURLToPath(new URL('../ember-compat', import.meta.url)) +const workDir = mkdtempSync(join(tmpdir(), 'hotkeys-ember-compat-')) +const packsDir = join(workDir, 'packs') +const appDir = join(workDir, 'probe') + +const run = (command: string, args: Array, cwd: string) => + execFileSync(command, args, { cwd, stdio: 'inherit' }) + +for (const pkg of ['hotkeys', 'ember-hotkeys']) { + run( + 'pnpm', + ['pack', '--pack-destination', packsDir], + join(rootDir, 'packages', pkg), + ) +} +const tarball = (prefix: string) => { + const name = readdirSync(packsDir).find((file) => + new RegExp(`^${prefix}-\\d`).test(file), + ) + if (!name) throw new Error(`No ${prefix} tarball in ${packsDir}`) + return `file:${join(packsDir, name)}` +} + +run( + 'npx', + [ + '--yes', + `ember-cli@${cliVersion}`, + 'new', + 'probe', + '--skip-git', + '--skip-npm', + '--lang', + 'en', + ], + workDir, +) +cpSync(join(probeDir, 'app'), join(appDir, 'app'), { recursive: true }) +cpSync(join(probeDir, 'tests'), join(appDir, 'tests'), { recursive: true }) + +const manifestPath = join(appDir, 'package.json') +const manifest = JSON.parse(readFileSync(manifestPath, 'utf8')) +manifest.devDependencies['@tanstack/ember-hotkeys'] = tarball( + 'tanstack-ember-hotkeys', +) +if (sourceVersion) manifest.devDependencies['ember-source'] = sourceVersion +// The adapter depends on the exact core version, which may not be published. +manifest.overrides = { '@tanstack/hotkeys': tarball('tanstack-hotkeys') } +writeFileSync(manifestPath, JSON.stringify(manifest, null, 2)) + +const browser = process.env.TESTEM_BROWSER ?? 'Chrome' +writeFileSync( + join(appDir, 'testem.js'), + `module.exports = ${JSON.stringify( + { + test_page: 'tests/index.html?hidepassed', + disable_watching: true, + launch_in_ci: [browser], + browser_start_timeout: 120, + browser_args: { + Chrome: { + ci: [ + '--headless', + '--no-sandbox', + '--disable-dev-shm-usage', + '--mute-audio', + '--remote-debugging-port=0', + ], + }, + }, + }, + null, + 2, + )}\n`, +) + +run('npm', ['install', '--no-audit', '--no-fund'], appDir) +run('npx', ['ember', 'test', '--test-port', '0'], appDir) diff --git a/knip.json b/knip.json index 189a21446..dbb1da3e0 100644 --- a/knip.json +++ b/knip.json @@ -17,10 +17,10 @@ "ignoreDependencies": [ "@ember/component", "@ember/destroyable", - "@ember/reactive", "@ember/runloop", "@ember/routing", "@embroider/shared-internals", + "@glimmer/tracking", "@glint/tsserver-plugin", "@tanstack/hotkeys-test-utils" ] @@ -29,7 +29,7 @@ "ignore": ["tests/custom-hooks/**"] }, "e2e": { - "ignore": ["adapters/shared/**"] + "ignore": ["adapters/shared/**", "ember-compat/**"] } } } diff --git a/package.json b/package.json index 17984a307..8540bca51 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "test:e2e:adapters": "nx run-many --skip-nx-cache --targets=build --projects='@tanstack/hotkeys-e2e-app-*' && pnpm --filter @tanstack/hotkeys-e2e test:e2e:adapters", "test:e2e:layouts": "pnpm --filter @tanstack/hotkeys-e2e test:e2e:layouts", "test:e2e:layouts:docker": "pnpm --filter @tanstack/hotkeys-e2e test:e2e:layouts:docker", + "test:e2e:ember-compat": "nx run @tanstack/ember-hotkeys:build && pnpm --filter @tanstack/hotkeys-e2e test:e2e:ember-compat", "test:e2e:ssr": "nx run-many --skip-nx-cache --targets=build --projects='@tanstack/hotkeys-example-*-format-for-display-*' && pnpm --filter @tanstack/hotkeys-e2e test:e2e:ssr", "test:eslint": "nx affected --target=test:eslint --exclude=examples/**", "test:oxlint": "nx affected --target=test:oxlint --exclude=examples/**", @@ -192,6 +193,15 @@ ], "limit": "12 KB" }, + { + "name": "Alpine hotkeyDirective", + "path": "packages/alpine-hotkeys/dist/index.js", + "import": "{ hotkeyDirective }", + "ignore": [ + "alpinejs" + ], + "limit": "10 KB" + }, { "name": "Ember useHotkey", "path": "packages/ember-hotkeys/dist/index.js", @@ -199,8 +209,8 @@ "ignore": [ "@ember/component/helper", "@ember/destroyable", - "@ember/reactive/collections", "@ember/runloop", + "@glimmer/tracking", "ember-modifier", "ember-source" ], diff --git a/packages/alpine-hotkeys/package.json b/packages/alpine-hotkeys/package.json index b23c6ab68..57f02ae5b 100644 --- a/packages/alpine-hotkeys/package.json +++ b/packages/alpine-hotkeys/package.json @@ -50,6 +50,8 @@ "@tanstack/hotkeys": "workspace:*" }, "devDependencies": { + "@alpinejs/csp": "3.17.5", + "@alpinejs/morph": "3.17.5", "@tanstack/hotkeys-test-utils": "workspace:*", "@types/alpinejs": "^3.17.0", "alpinejs": "^3.17.5" diff --git a/packages/alpine-hotkeys/skills/alpine-hotkeys/SKILL.md b/packages/alpine-hotkeys/skills/alpine-hotkeys/SKILL.md index e41b85e8a..48eb84439 100644 --- a/packages/alpine-hotkeys/skills/alpine-hotkeys/SKILL.md +++ b/packages/alpine-hotkeys/skills/alpine-hotkeys/SKILL.md @@ -62,6 +62,8 @@ Alpine.data('panel', () => ({ Install `Alpine.plugin(hotkeysPlugin)` before `Alpine.start()`. It gives the adapter the app's Alpine instance; without it, the adapter falls back to `window.Alpine` and throws when neither exists. The plugin also adds the `$hotkeys` magic for markup-only components, which is destroyed with its element: `x-init="$hotkeys.createHotkey('Mod+S', () => save())"`. +For a fixed hotkey in markup, import `hotkeyDirective` from `@tanstack/alpine-hotkeys`, install `Alpine.plugin(hotkeyDirective)`, and write `x-hotkey.mod.s="save()"`. Modifiers name the hotkey in lowercase, with dashes for multi-word keys (`x-hotkey.arrow-up`), and `x-hotkey.g.h` is a sequence. The expression gets `$event`. The directive uses the built-in options, and it lives as long as its attribute, so it follows Livewire and `Alpine.morph` updates. + ## API | API | What it's for | @@ -69,6 +71,7 @@ Install `Alpine.plugin(hotkeysPlugin)` before `Alpine.start()`. It gives the ada | `Alpine.plugin(hotkeysPlugin)` | Give the adapter the app's Alpine, and install the `$hotkeys` magic, an owner destroyed with its element. | | `createHotkeysScope(defaults?)` | Create an owner for one `Alpine.data` component, with optional default options. | | `createHotkeyRecorder(owner, options)` | Record a chord or sequence the user presses, for a settings screen. The owner destroys it and supplies its `hotkeyRecorder` defaults. | +| `Alpine.plugin(hotkeyDirective)` | Install `x-hotkey`, which registers the hotkey its modifiers name while the attribute exists. | | `Alpine.plugin(hotkeyRecorderPlugin)` | Install the `$hotkeyRecorder(options)` magic, which creates recorders destroyed with their element. | | `provideAppHotkeys(appHotkeys, options?)` | Declare app hotkeys and load the user's custom hotkeys once at startup, since Alpine has no provider. | | `getHotkeyManager().activateScope(scope, options?)` | Turn on a scope, such as an exclusive one for a dialog; it returns the function that turns the scope off. | @@ -99,6 +102,8 @@ The package also re-exports `@tanstack/hotkeys`, such as `matchesKeyboardEvent` - **`createHotkeysScope` isn't a hotkey scope.** It only owns registrations and sets defaults. For a dialog, activate a real scope in `init()` with `release = getHotkeyManager().activateScope(name, { exclusive: true })`, pass `{ scope: name }` to the dialog's hotkeys, and call `release()` in `destroy()`. Give each open dialog its own name. - **Pass options as a getter.** `{ enabled: this.dirty }` is read once. Use `() => ({ enabled: this.dirty })`. - **Use either `$hotkeys` or your own owner for a hotkey, not both.** Otherwise it registers twice. +- **Use `x-hotkey` on pages that Livewire or `Alpine.morph` updates.** A morph that changes `x-init` runs it again, but `$hotkeys` keeps the old registration until its element is removed, so both hotkeys fire. +- **Alpine's CSP build can't parse arrow functions in markup.** Put the callback in an `Alpine.data` method and name it: `x-hotkey.mod.s="save"`. A call such as `save()` needs `@alpinejs/csp` 3.15 or newer, or use the `init()` pattern. - **Call `create*` in `x-init` or `init()`, and read `.value` anywhere.** Calling `create*` inside a reactive expression such as `x-text="$hotkeys.createHeldKeys().value"` creates a new subscription on every evaluation. - **Owners have no `createHotkeyRecorder` method** since v0.10.0. Call `createHotkeyRecorder(this.hotkeys, options)`, so apps that don't record don't ship the recorder. - With server rendering, load the adapter only in the browser. diff --git a/packages/alpine-hotkeys/src/hotkeyDirective.ts b/packages/alpine-hotkeys/src/hotkeyDirective.ts new file mode 100644 index 000000000..e564c456e --- /dev/null +++ b/packages/alpine-hotkeys/src/hotkeyDirective.ts @@ -0,0 +1,61 @@ +import { + MODIFIER_ALIASES, + getHotkeyManager, + normalizeKeyName, +} from '@tanstack/hotkeys' +import type { Hotkey } from '@tanstack/hotkeys' +import type Alpine from 'alpinejs' + +/** + * Reads a hotkey from directive modifiers. HTML lowercases attribute names, so + * `arrow-up` names `ArrowUp`. Each key ends a step, so `['mod', 'k']` is + * `Mod+K` and `['g', 'h']` is the sequence `['G', 'H']`. + */ +export function hotkeyFromModifiers( + modifiers: ReadonlyArray, +): Hotkey | undefined { + const steps: Array = [] + let step = '' + for (const part of modifiers) { + if (Object.hasOwn(MODIFIER_ALIASES, part)) { + step += `${MODIFIER_ALIASES[part]}+` + } else { + // One character goes through core, which keeps `ı` and `ß` as written. + steps.push( + step + + ([...part].length === 1 + ? normalizeKeyName(part) + : part.replace(/(?:^|-)(.)/g, (_, char: string) => + char.toUpperCase(), + )), + ) + step = '' + } + } + // A modifier after the last key, as in `x-hotkey.s.mod`, names no key. + if (step) return undefined + return (steps.length > 1 ? steps : steps[0]) as Hotkey | undefined +} + +/** + * Installs `x-hotkey`, which registers the hotkey named by its modifiers while + * its element exists: `x-hotkey.mod.s="save()"`, `x-hotkey.escape="close()"`, + * `x-hotkey.g.h="goHome()"`. The expression gets `$event`. Alpine removes the + * hotkey with its element, and when a morph changes or removes the attribute. + */ +export function hotkeyDirective(alpine: typeof Alpine): void { + alpine.directive( + 'hotkey', + alpine.skipDuringClone( + (_element, { modifiers, expression }, { evaluateLater, cleanup }) => { + const hotkey = hotkeyFromModifiers(modifiers) + if (!hotkey) return + const run = evaluateLater(expression) + const handle = getHotkeyManager().register(hotkey, (event) => + run(() => {}, { scope: { $event: event }, params: [event] }), + ) + cleanup(() => handle.unregister()) + }, + ), + ) +} diff --git a/packages/alpine-hotkeys/src/index.ts b/packages/alpine-hotkeys/src/index.ts index 873ef7f53..443e880e0 100644 --- a/packages/alpine-hotkeys/src/index.ts +++ b/packages/alpine-hotkeys/src/index.ts @@ -4,6 +4,7 @@ export * from './createHotkeysScope' // Replaces the core export, to point components to the scope's function export { formatForDisplay } from './formatForDisplay' export * from './hotkeysPlugin' +export { hotkeyDirective } from './hotkeyDirective' export { createHotkeyRecorder } from './createHotkeyRecorder' export * from './hotkeyRecorderPlugin' diff --git a/packages/alpine-hotkeys/tests/alpine-plugins.d.ts b/packages/alpine-hotkeys/tests/alpine-plugins.d.ts new file mode 100644 index 000000000..f5e830394 --- /dev/null +++ b/packages/alpine-hotkeys/tests/alpine-plugins.d.ts @@ -0,0 +1,10 @@ +// The Alpine plugins the tests use ship no types. +declare module '@alpinejs/morph' { + const morph: import('alpinejs').PluginCallback + export default morph +} + +declare module '@alpinejs/csp' { + const Alpine: typeof import('alpinejs').default + export default Alpine +} diff --git a/packages/alpine-hotkeys/tests/csp-build.test.ts b/packages/alpine-hotkeys/tests/csp-build.test.ts new file mode 100644 index 000000000..b043c2227 --- /dev/null +++ b/packages/alpine-hotkeys/tests/csp-build.test.ts @@ -0,0 +1,57 @@ +// Alpine's CSP build parses expressions itself and rejects arrow functions, +// so the documented CSP pattern names a component method in `x-hotkey`. +import Alpine from '@alpinejs/csp' +import { afterEach, expect, it } from 'vitest' +import { + HotkeyManager, + getHotkeyManager, + hotkeyDirective, + hotkeysPlugin, +} from '../src' + +Alpine.plugin(hotkeysPlugin) +Alpine.plugin(hotkeyDirective) +Alpine.data('counter', () => ({ + count: 0, + increment() { + this.count++ + }, +})) +Alpine.start() + +async function pressIn(html: string) { + document.body.innerHTML = html + await Alpine.nextTick() + document.body.dispatchEvent( + new KeyboardEvent('keydown', { + key: 'k', + ctrlKey: true, + bubbles: true, + cancelable: true, + }), + ) + const element = document.body.firstElementChild as HTMLElement + return (Alpine.$data(element) as { count: number }).count +} + +afterEach(async () => { + document.body.replaceChildren() + await Alpine.nextTick() + expect(getHotkeyManager().registrations.state.size).toBe(0) + HotkeyManager.resetInstance() +}) + +it('runs a method name or call from x-hotkey', async () => { + expect( + await pressIn( + `
`, + ), + ).toBe(1) + document.body.replaceChildren() + await Alpine.nextTick() + expect( + await pressIn( + `
`, + ), + ).toBe(1) +}) diff --git a/packages/alpine-hotkeys/tests/hotkey-directive.test.ts b/packages/alpine-hotkeys/tests/hotkey-directive.test.ts new file mode 100644 index 000000000..d0ec6f83a --- /dev/null +++ b/packages/alpine-hotkeys/tests/hotkey-directive.test.ts @@ -0,0 +1,136 @@ +import morph from '@alpinejs/morph' +import Alpine from 'alpinejs' +import { afterEach, describe, expect, it } from 'vitest' +import { HotkeyManager, getHotkeyManager, hotkeyDirective } from '../src' +import { hotkeyFromModifiers } from '../src/hotkeyDirective' + +Alpine.plugin(morph) +Alpine.plugin(hotkeyDirective) +// Alpine sees attribute changes, such as a morph's, only once started. +Alpine.start() + +const morphTo = (from: Element, to: string) => + (Alpine as unknown as { morph: (from: Element, to: string) => void }).morph( + from, + to, + ) + +function key(key: string, options: KeyboardEventInit = {}) { + document.body.dispatchEvent( + new KeyboardEvent('keydown', { + key, + bubbles: true, + cancelable: true, + ...options, + }), + ) +} + +async function mount(html: string) { + document.body.innerHTML = html + // Alpine initializes added elements from its mutation observer. + await Alpine.nextTick() + return document.body.firstElementChild as HTMLElement +} + +function registered() { + return [...getHotkeyManager().registrations.state.values()].map( + (registration) => registration.hotkey, + ) +} + +afterEach(async () => { + document.body.replaceChildren() + await Alpine.nextTick() + HotkeyManager.resetInstance() +}) + +describe('hotkeyFromModifiers', () => { + it('reads chords, named keys, and sequences', () => { + expect(hotkeyFromModifiers(['mod', 's'])).toBe('Mod+S') + expect(hotkeyFromModifiers(['control', 'shift', 'k'])).toBe( + 'Control+Shift+K', + ) + expect(hotkeyFromModifiers(['escape'])).toBe('Escape') + expect(hotkeyFromModifiers(['arrow-up'])).toBe('ArrowUp') + expect(hotkeyFromModifiers(['shift', 'f10'])).toBe('Shift+F10') + expect(hotkeyFromModifiers(['g', 'h'])).toEqual(['G', 'H']) + expect(hotkeyFromModifiers(['mod', 'k', 'mod', 's'])).toEqual([ + 'Mod+K', + 'Mod+S', + ]) + expect(hotkeyFromModifiers([])).toBeUndefined() + }) + + it('keeps a letter that uppercases to another key', () => { + // `ı` uppercases to the ASCII `I` and `ß` to `SS`, as core keeps them. + expect(hotkeyFromModifiers(['mod', 'ı'])).toBe('Mod+ı') + expect(hotkeyFromModifiers(['ß'])).toBe('ß') + expect(hotkeyFromModifiers(['é'])).toBe('É') + }) + + it('reads nothing when a modifier comes after the last key', () => { + // `x-hotkey.s.mod` must not register a bare `S`. + expect(hotkeyFromModifiers(['s', 'mod'])).toBeUndefined() + expect(hotkeyFromModifiers(['g', 'h', 'shift'])).toBeUndefined() + }) +}) + +describe('x-hotkey', () => { + it('runs its expression with $event and unregisters with its element', async () => { + const element = await mount( + `
`, + ) + key('s', { ctrlKey: true }) + const data = Alpine.$data(element) as { count: number; key: string } + expect(data.count).toBe(1) + expect(data.key).toBe('s') + element.remove() + await Alpine.nextTick() + expect(getHotkeyManager().registrations.state.size).toBe(0) + }) + + it('registers sequences', async () => { + const element = await mount( + `
`, + ) + key('g') + key('h') + expect((Alpine.$data(element) as { count: number }).count).toBe(1) + }) + + it('follows a morph that changes the binding', async () => { + const element = await mount( + `
`, + ) + expect(registered()).toEqual(['Control+S']) + morphTo( + element, + `
`, + ) + await Alpine.nextTick() + expect(registered()).toEqual(['Control+P']) + key('s', { ctrlKey: true }) + key('p', { ctrlKey: true }) + expect((Alpine.$data(element) as { calls: Array }).calls).toEqual([ + 'P', + ]) + }) + + it('unregisters when a morph removes the attribute', async () => { + const element = await mount( + `
`, + ) + morphTo(element, `
`) + await Alpine.nextTick() + expect(getHotkeyManager().registrations.state.size).toBe(0) + }) + + it('keeps one registration through a morph that changes nothing', async () => { + const html = `
` + const element = await mount(html) + morphTo(element, html) + await Alpine.nextTick() + expect(registered()).toEqual(['Control+S']) + }) +}) diff --git a/packages/ember-hotkeys/package.json b/packages/ember-hotkeys/package.json index 3a2f27e73..750157023 100644 --- a/packages/ember-hotkeys/package.json +++ b/packages/ember-hotkeys/package.json @@ -80,7 +80,7 @@ "vite": "^8.3.7" }, "peerDependencies": { - "ember-source": ">=6.8.3 <6.9.0 || >=6.10.1" + "ember-source": ">=4.12.0" }, "ember-addon": { "version": 2, diff --git a/packages/ember-hotkeys/skills/ember-hotkeys/SKILL.md b/packages/ember-hotkeys/skills/ember-hotkeys/SKILL.md index 926c9e407..b3e269a8a 100644 --- a/packages/ember-hotkeys/skills/ember-hotkeys/SKILL.md +++ b/packages/ember-hotkeys/skills/ember-hotkeys/SKILL.md @@ -78,7 +78,7 @@ export default class Editor extends Component { The package also re-exports `@tanstack/hotkeys`, such as `matchesKeyboardEvent` and `defineAppHotkeys`. Its plain `formatForDisplay` export is deprecated: use `useFormatForDisplay()` in components. Outside a component, call the plain function and pass `platform`. -The helpers are template helpers, not JavaScript functions. State readers take the component as their owner, and their state is read through `.value`, or `.hotkeys` for registrations. Use Ember 6.8.3 or newer, except 6.9.0 and 6.10.0, and strict-mode `.gts` components. +The helpers are template helpers, not JavaScript functions. State readers take the component as their owner, and their state is read through `.value`, or `.hotkeys` for registrations. Use Ember 4.12 or newer and strict-mode `.gts` components. ## Pitfalls diff --git a/packages/ember-hotkeys/src/bindings.ts b/packages/ember-hotkeys/src/bindings.ts index 993be9eca..cb58ce532 100644 --- a/packages/ember-hotkeys/src/bindings.ts +++ b/packages/ember-hotkeys/src/bindings.ts @@ -24,6 +24,28 @@ function copyHotkey( return { ...hotkey } } +/** + * Hotkey defaults for the helper and modifier classes a `createHotkeysScope` + * scope creates. They are the lowest layer, below an app hotkey's declaration. + */ +export const classDefaults = new WeakMap< + object, + () => EmberHotkeyCommonOptions | undefined +>() + +/** The scope defaults for a helper or modifier, including a subclass of one. */ +function defaultsFor(owner: object): EmberHotkeyCommonOptions | undefined { + for ( + let helper: unknown = owner.constructor; + typeof helper === 'function'; + helper = Object.getPrototypeOf(helper) + ) { + const defaults = classDefaults.get(helper) + if (defaults) return defaults() + } + return undefined +} + /** * Registrations owned by a helper or modifier. `set` records the latest * definitions while Ember tracks the caller; registration changes publish @@ -34,15 +56,22 @@ export function createOwnedBindings(owner: object) { const state: { definitions: ReadonlyArray commonOptions: EmberHotkeyCommonOptions + defaults: EmberHotkeyCommonOptions | undefined element: HTMLElement | undefined - } = { definitions: [], commonOptions: {}, element: undefined } + } = { + definitions: [], + commonOptions: {}, + defaults: undefined, + element: undefined, + } function update(): void { if (isDestroying(owner) || isDestroyed(owner)) return - const { definitions, commonOptions, element } = state + const { definitions, commonOptions, defaults, element } = state bindings.update( prepareHotkeyDefinitions(definitions, { appHotkeysStore: getPublishedAppHotkeysStore(), + defaults, commonOptions: element ? { ...commonOptions, target: element } : commonOptions, @@ -75,6 +104,8 @@ export function createOwnedBindings(owner: object) { }) as EmberHotkeyDefinition, ) state.commonOptions = { ...commonOptions } + // Read while Ember tracks the caller, so reactive defaults re-run it. + state.defaults = defaultsFor(owner) state.element = element schedule() }, diff --git a/packages/ember-hotkeys/src/createHotkeysScope.ts b/packages/ember-hotkeys/src/createHotkeysScope.ts index 6d9b61ded..42298412a 100644 --- a/packages/ember-hotkeys/src/createHotkeysScope.ts +++ b/packages/ember-hotkeys/src/createHotkeysScope.ts @@ -1,8 +1,8 @@ import { - definedOptions, mergeHotkeysProviderDefaults, resolveMaybeGetter, } from '@tanstack/hotkeys/adapter' +import { classDefaults } from './bindings' import { OnHotkey } from './onHotkey' import { OnHotkeys } from './onHotkeys' import { UseHotkey } from './useHotkey' @@ -39,38 +39,14 @@ export function createHotkeysScope( undefined, ) const scope: EmberHotkeysScope = { - onHotkey: class extends OnHotkey { - override modify( - ...[element, args, options]: Parameters - ) { - super.modify(element, args, { - ...definedOptions(defaults().hotkey, options), - }) - } - }, - onHotkeys: class extends OnHotkeys { - override modify( - ...[element, args, options]: Parameters - ) { - super.modify(element, args, { - ...definedOptions(defaults().hotkey, options), - }) - } - }, - useHotkey: class extends UseHotkey { - override compute(...[args, options]: Parameters) { - super.compute(args, { - ...definedOptions(defaults().hotkey, options), - }) - } - }, - useHotkeys: class extends UseHotkeys { - override compute(...[args, options]: Parameters) { - super.compute(args, { - ...definedOptions(defaults().hotkey, options), - }) - } - }, + onHotkey: class extends OnHotkey {}, + onHotkeys: class extends OnHotkeys {}, + useHotkey: class extends UseHotkey {}, + useHotkeys: class extends UseHotkeys {}, + } + const hotkeyDefaults = () => defaults().hotkey + for (const helper of Object.values(scope)) { + classDefaults.set(helper, hotkeyDefaults) } scopeDefaults.set(scope, defaults) return scope diff --git a/packages/ember-hotkeys/src/keyboardLayout.ts b/packages/ember-hotkeys/src/keyboardLayout.ts index 2706ae8de..1baea4adc 100644 --- a/packages/ember-hotkeys/src/keyboardLayout.ts +++ b/packages/ember-hotkeys/src/keyboardLayout.ts @@ -1,6 +1,6 @@ -import { trackedObject } from '@ember/reactive/collections' import { schedule, scheduleOnce } from '@ember/runloop' import { getKeyboardLayoutStore, loadKeyboardLayout } from '@tanstack/hotkeys' +import { trackedVersion } from './tracked' import { scopeDefaults } from './utils' import type { KeyboardLayoutMap } from '@tanstack/hotkeys' import type { EmberHotkeysScope } from './createHotkeysScope' @@ -41,7 +41,7 @@ let changes: { version: number } | undefined export function trackedLayout(): KeyboardLayoutMap | null { const store = getKeyboardLayoutStore() if (!changes) { - const state = (changes = trackedObject({ version: 0 })) + const state = (changes = trackedVersion()) store.subscribe(() => { state.version++ }) @@ -60,7 +60,7 @@ export function untilRendered( onRendered?: () => void, ): () => KeyboardLayoutMap | null { let rendered = false - const state = trackedObject({ version: 0 }) + const state = trackedVersion() schedule('afterRender', () => { rendered = true onRendered?.() diff --git a/packages/ember-hotkeys/src/tracked.ts b/packages/ember-hotkeys/src/tracked.ts new file mode 100644 index 000000000..0ad4647a2 --- /dev/null +++ b/packages/ember-hotkeys/src/tracked.ts @@ -0,0 +1,28 @@ +import { tracked } from '@glimmer/tracking' + +class TrackedVersion { + declare version: number +} + +// Applies `@tracked version = 0` by hand, so the build needs no decorator +// transform. `@glimmer/tracking` works on every supported ember-source, where +// `@ember/reactive/collections` needs 6.8.3 or newer. +Object.defineProperty( + TrackedVersion.prototype, + 'version', + (tracked as unknown as (...args: Array) => PropertyDescriptor)( + TrackedVersion.prototype, + 'version', + { + configurable: true, + enumerable: true, + writable: true, + initializer: () => 0, + }, + ), +) + +/** A counter that invalidates its readers when it changes. */ +export function trackedVersion(): { version: number } { + return new TrackedVersion() +} diff --git a/packages/ember-hotkeys/src/utils.ts b/packages/ember-hotkeys/src/utils.ts index d1d3399fc..3065b62be 100644 --- a/packages/ember-hotkeys/src/utils.ts +++ b/packages/ember-hotkeys/src/utils.ts @@ -1,9 +1,9 @@ import { registerDestructor } from '@ember/destroyable' -import { trackedObject } from '@ember/reactive/collections' import { getPublishedAppHotkeysStore, subscribePublishedAppHotkeys, } from '@tanstack/hotkeys/adapter' +import { trackedVersion } from './tracked' import type { AppHotkeysStore } from '@tanstack/hotkeys' import type { Store } from '@tanstack/hotkeys/adapter' import type { DefaultHotkeysOptions } from './types' @@ -16,7 +16,7 @@ export function select( store: Pick, 'state' | 'subscribe'>, selector: (value: T) => TSelected, ) { - const state = trackedObject({ version: 0 }) + const state = trackedVersion() let last: TSelected | undefined // Invalidate consumers only when the selected value changes. The getter // still runs the selector while tracking, so getter inputs stay tracked. @@ -43,7 +43,7 @@ export function select( export function trackPublishedAppHotkeys( owner: object, ): () => AppHotkeysStore | null { - const state = trackedObject({ version: 0 }) + const state = trackedVersion() registerDestructor( owner, subscribePublishedAppHotkeys(() => { diff --git a/packages/ember-hotkeys/tests/integration/app-hotkeys.test.gts b/packages/ember-hotkeys/tests/integration/app-hotkeys.test.gts index 950b290d9..f262017c7 100644 --- a/packages/ember-hotkeys/tests/integration/app-hotkeys.test.gts +++ b/packages/ember-hotkeys/tests/integration/app-hotkeys.test.gts @@ -5,6 +5,7 @@ import Component from '@glimmer/component' import { tracked } from '@glimmer/tracking' import { HotkeyManager, + createHotkeysScope, defineAppHotkeys, getHotkeyManager, provideAppHotkeys, @@ -126,3 +127,89 @@ module('App hotkeys', (hooks) => { }) } }) + +const declaredHotkeys = defineAppHotkeys({ + 'doc.print': { + hotkey: 'Control+P', + options: { preventDefault: false, stopPropagation: false }, + }, +}) +const scoped = createHotkeysScope({ + hotkey: { preventDefault: true, stopPropagation: true }, +}) + +module('App hotkeys with scope defaults', (hooks) => { + setupRenderingTest(hooks) + + hooks.afterEach(() => { + HotkeyManager.resetInstance() + }) + + // Scope defaults are the lowest layer, below an app hotkey's declaration. + test('an app hotkey declaration wins over scope defaults', async (assert) => { + const { dispose } = provideAppHotkeys(declaredHotkeys) + const print = declaredHotkeys['doc.print'] + const noop = () => {} + await render( + , + ) + assert.deepEqual( + [...getHotkeyManager().registrations.state.values()].map((r) => ({ + preventDefault: r.options.preventDefault, + stopPropagation: r.options.stopPropagation, + })), + [ + { preventDefault: false, stopPropagation: false }, + { preventDefault: false, stopPropagation: false }, + ], + ) + await clearRender() + dispose() + }) +}) + +// Defaults that differ from the built-in ones, so a lost default shows. +const quiet = createHotkeysScope({ + hotkey: { preventDefault: false, stopPropagation: false }, +}) + +module('App hotkeys with scope defaults, by layer', (hooks) => { + setupRenderingTest(hooks) + + hooks.afterEach(() => { + HotkeyManager.resetInstance() + }) + + // Lists follow the same order, call-site options beat the declaration, and + // a subclass of a scope's helper keeps the scope defaults. + test('lists, call-site options and subclasses', async (assert) => { + const { dispose } = provideAppHotkeys(declaredHotkeys) + const noop = () => {} + const list: Array = [ + { hotkey: declaredHotkeys['doc.print'], callback: noop }, + ] + const SubHotkey = class extends quiet.useHotkey {} + await render( + , + ) + assert.deepEqual( + [...getHotkeyManager().registrations.state.values()] + .map( + (r) => + // The key alone: Linux and Windows write `Control` as `Mod`. + `${String(r.hotkey).slice(-1)} ${String(r.options.preventDefault)} ${String(r.options.stopPropagation)}`, + ) + .sort(), + ['K false false', 'P false false', 'P false true'], + ) + await clearRender() + dispose() + }) +}) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e63198312..52c088bd4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4625,6 +4625,12 @@ importers: specifier: workspace:* version: link:../hotkeys devDependencies: + '@alpinejs/csp': + specifier: 3.17.5 + version: 3.17.5 + '@alpinejs/morph': + specifier: 3.17.5 + version: 3.17.5 '@tanstack/hotkeys-test-utils': specifier: workspace:* version: link:../../test-utils @@ -5200,6 +5206,12 @@ packages: resolution: {integrity: sha512-CA+6MlgPkjSlGQpx+rLBSnHFy8pyYpGEjs7Yp0kVzOC6RM5jq99Z4KGOuplcNZBjQlM521t0nEvKLxFOv2NSZA==} engines: {node: '>= 14.0.0'} + '@alpinejs/csp@3.17.5': + resolution: {integrity: sha512-7e5lYgzJJL2eZ7esnx+E7wtxws+VDs9em9ztttZ+AQAYEng2bABHFp2SUga0wt84RyfL7hc6B+S/RGglXsPf6w==} + + '@alpinejs/morph@3.17.5': + resolution: {integrity: sha512-3/zvG152HGW/sIuvOKMojKc0sH+quIFjMArKuG8vT07x5I7R90iVmwCtCZgE+9+7BJoop9q00maNd7nvHIA5Fw==} + '@ampproject/remapping@2.3.0': resolution: {integrity: sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==} engines: {node: '>=6.0.0'} @@ -18787,6 +18799,12 @@ snapshots: dependencies: '@algolia/client-common': 5.61.0 + '@alpinejs/csp@3.17.5': + dependencies: + '@vue/reactivity': 3.5.45 + + '@alpinejs/morph@3.17.5': {} + '@ampproject/remapping@2.3.0': dependencies: '@jridgewell/gen-mapping': 0.3.13 @@ -31377,10 +31395,6 @@ snapshots: powershell-utils@0.2.1: {} - preact-render-to-string@6.8.2(preact@10.29.8): - dependencies: - preact: 10.29.8(preact-render-to-string@6.8.2) - preact-render-to-string@6.8.2(preact@11.2.0): dependencies: preact: 11.2.0(preact-render-to-string@6.8.2)