Skip to content

Commit 7af1455

Browse files
committed
chore(shortcut): migrate to Svelte 5
1 parent 39dcfc9 commit 7af1455

6 files changed

Lines changed: 18 additions & 27 deletions

File tree

.changeset/rich-swans-grow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@svelte-put/shortcut': major
3+
---
4+
5+
drop support for Svelte 4 and below. `on:shortcut` is now `onshortcut`

packages/resize/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"@internals/tsconfig": "workspace:*"
5252
},
5353
"peerDependencies": {
54-
"svelte": "^5.0.0"
54+
"svelte": "^5.0.0-next.1"
5555
},
5656
"volta": {
5757
"extends": "../../package.json"

packages/shortcut/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"@internals/tsconfig": "workspace:*"
5353
},
5454
"peerDependencies": {
55-
"svelte": "^3.55.0 || ^4.0.0 || ^5.0.0"
55+
"svelte": "^5.0.0-next.1"
5656
},
5757
"volta": {
5858
"extends": "../../package.json"

packages/shortcut/src/public.d.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ActionReturn, Action } from 'svelte/action';
77
* whenever `svelte-put/shorcut` is imported.
88
*/
99
export interface ShortcutAttributes {
10-
'on:shortcut'?: (event: CustomEvent<ShortcutEventDetail>) => void;
10+
'onshortcut'?: (event: CustomEvent<ShortcutEventDetail>) => void;
1111
}
1212

1313
/**
@@ -16,8 +16,6 @@ export interface ShortcutAttributes {
1616
* {@link https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/ctrlKey | ctrlKey},
1717
* {@link https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/shiftKey | shiftKey},
1818
* {@link https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/metaKey | metaKey}.
19-
*
20-
*
2119
*/
2220
export type ShortcutModifier = 'alt' | 'ctrl' | 'meta' | 'shift';
2321

@@ -104,21 +102,18 @@ export type ShortcutModifierDefinition =
104102

105103
/**
106104
* A definition of a shortcut trigger
107-
*
108105
*/
109106
export interface ShortcutTrigger {
110107
/**
111108
* whether to enable this triggered. Default to `true`
112109
*
113-
*
114-
*
115110
* `false` means trigger is disabled,
116111
* but event listener is still placed on node
117112
*/
118113
enabled?: boolean;
119114
/** modifier key to listen to in conjunction of `key` */
120115
modifier?: ShortcutModifierDefinition;
121-
/** id to distinguish this trigger from others, recommended when using `on:shortcut` */
116+
/** id to distinguish this trigger from others, recommended when using `onshortcut` */
122117
id?: string;
123118
/** the {@link https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent | KeyboardEvent}.key to listen to */
124119
key: string;
@@ -127,19 +122,14 @@ export interface ShortcutTrigger {
127122
/**
128123
* whether to call `event.preventDefault` before firing callback. Default to `false`
129124
*
130-
*
131-
*
132125
* This is called on the node the action is attached to, not the node that triggers the original `KeyboardEvent`.
133126
* So for example, if `shortcut` is attached to `window`, by the time `preventDefault` is called, the event has already been
134127
* bubbled up to `window`.
135128
*/
136129
preventDefault?: boolean;
137130
}
138131

139-
/**
140-
* svelte action parameter to config behavior of `shortcut`
141-
*
142-
*/
132+
/** svelte action parameter to config behavior of `shortcut` */
143133
export interface ShortcutParameter {
144134
/** whether to activate the action. Default to `true` */
145135
enabled?: boolean;
@@ -172,7 +162,7 @@ export interface ShortcutParameter {
172162
* id: 'my-shortcut',
173163
* },
174164
* }}
175-
* on:shortcut={onShortcut}
165+
* onshortcut={onShortcut}
176166
* />
177167
* ```
178168
*/
@@ -184,9 +174,5 @@ export interface ShortcutEventDetail {
184174
/** the original `KeyboardEvent`. Helpful to access the event target, for example */
185175
originalEvent: KeyboardEvent;
186176
}
187-
188-
/** */
189177
export type ShortcutAction = Action<HTMLElement, ShortcutParameter, ShortcutAttributes>;
190-
191-
/** */
192178
export type ShortcutActionReturn = ActionReturn<ShortcutParameter, ShortcutAttributes>;

packages/shortcut/src/shortcut.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
* },
6161
* ],
6262
* }}
63-
* on:shortcut={onShortcut}
63+
* onshortcut={onShortcut}
6464
* />
6565
* ```
6666
*
@@ -80,11 +80,11 @@
8080
*
8181
* - pass multiple callbacks to their associated triggers, or
8282
*
83-
* - pass one single handler to the `on:shortcut` event, in which case you should
83+
* - pass one single handler to the `onshortcut` event, in which case you should
8484
* provide an ID to each trigger to be able to distinguish what trigger was activated
8585
* in the event handler.
8686
*
87-
* Either way, only use `callback` or `on:shortcut` and not both to
87+
* Either way, only use `callback` or `onshortcut` and not both to
8888
* avoid handler duplication.
8989
* @param {HTMLElement} node - HTMLElement to add event listener to
9090
* @param {import('./public').ShortcutParameter} param - svelte action parameters

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)