Skip to content

Commit

Permalink
chore(shortcut): migrate to Svelte 5
Browse files Browse the repository at this point in the history
  • Loading branch information
vnphanquang committed Jul 9, 2024
1 parent 39dcfc9 commit 7af1455
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .changeset/rich-swans-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@svelte-put/shortcut': major
---

drop support for Svelte 4 and below. `on:shortcut` is now `onshortcut`
2 changes: 1 addition & 1 deletion packages/resize/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@internals/tsconfig": "workspace:*"
},
"peerDependencies": {
"svelte": "^5.0.0"
"svelte": "^5.0.0-next.1"
},
"volta": {
"extends": "../../package.json"
Expand Down
2 changes: 1 addition & 1 deletion packages/shortcut/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@internals/tsconfig": "workspace:*"
},
"peerDependencies": {
"svelte": "^3.55.0 || ^4.0.0 || ^5.0.0"
"svelte": "^5.0.0-next.1"
},
"volta": {
"extends": "../../package.json"
Expand Down
22 changes: 4 additions & 18 deletions packages/shortcut/src/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ActionReturn, Action } from 'svelte/action';
* whenever `svelte-put/shorcut` is imported.
*/
export interface ShortcutAttributes {
'on:shortcut'?: (event: CustomEvent<ShortcutEventDetail>) => void;
'onshortcut'?: (event: CustomEvent<ShortcutEventDetail>) => void;
}

/**
Expand All @@ -16,8 +16,6 @@ export interface ShortcutAttributes {
* {@link https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/ctrlKey | ctrlKey},
* {@link https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/shiftKey | shiftKey},
* {@link https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/metaKey | metaKey}.
*
*
*/
export type ShortcutModifier = 'alt' | 'ctrl' | 'meta' | 'shift';

Expand Down Expand Up @@ -104,21 +102,18 @@ export type ShortcutModifierDefinition =

/**
* A definition of a shortcut trigger
*
*/
export interface ShortcutTrigger {
/**
* whether to enable this triggered. Default to `true`
*
*
*
* `false` means trigger is disabled,
* but event listener is still placed on node
*/
enabled?: boolean;
/** modifier key to listen to in conjunction of `key` */
modifier?: ShortcutModifierDefinition;
/** id to distinguish this trigger from others, recommended when using `on:shortcut` */
/** id to distinguish this trigger from others, recommended when using `onshortcut` */
id?: string;
/** the {@link https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent | KeyboardEvent}.key to listen to */
key: string;
Expand All @@ -127,19 +122,14 @@ export interface ShortcutTrigger {
/**
* whether to call `event.preventDefault` before firing callback. Default to `false`
*
*
*
* This is called on the node the action is attached to, not the node that triggers the original `KeyboardEvent`.
* So for example, if `shortcut` is attached to `window`, by the time `preventDefault` is called, the event has already been
* bubbled up to `window`.
*/
preventDefault?: boolean;
}

/**
* svelte action parameter to config behavior of `shortcut`
*
*/
/** svelte action parameter to config behavior of `shortcut` */
export interface ShortcutParameter {
/** whether to activate the action. Default to `true` */
enabled?: boolean;
Expand Down Expand Up @@ -172,7 +162,7 @@ export interface ShortcutParameter {
* id: 'my-shortcut',
* },
* }}
* on:shortcut={onShortcut}
* onshortcut={onShortcut}
* />
* ```
*/
Expand All @@ -184,9 +174,5 @@ export interface ShortcutEventDetail {
/** the original `KeyboardEvent`. Helpful to access the event target, for example */
originalEvent: KeyboardEvent;
}

/** */
export type ShortcutAction = Action<HTMLElement, ShortcutParameter, ShortcutAttributes>;

/** */
export type ShortcutActionReturn = ActionReturn<ShortcutParameter, ShortcutAttributes>;
6 changes: 3 additions & 3 deletions packages/shortcut/src/shortcut.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
* },
* ],
* }}
* on:shortcut={onShortcut}
* onshortcut={onShortcut}
* />
* ```
*
Expand All @@ -80,11 +80,11 @@
*
* - pass multiple callbacks to their associated triggers, or
*
* - pass one single handler to the `on:shortcut` event, in which case you should
* - pass one single handler to the `onshortcut` event, in which case you should
* provide an ID to each trigger to be able to distinguish what trigger was activated
* in the event handler.
*
* Either way, only use `callback` or `on:shortcut` and not both to
* Either way, only use `callback` or `onshortcut` and not both to
* avoid handler duplication.
* @param {HTMLElement} node - HTMLElement to add event listener to
* @param {import('./public').ShortcutParameter} param - svelte action parameters
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7af1455

Please sign in to comment.