Skip to content

Commit

Permalink
2.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Houfeng committed Aug 6, 2022
1 parent ca7327b commit bea6b86
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 18 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,20 @@ function Demo(){
```jsx
import { FingerProxy, FingerProxyContainer } from "react-finger";

const FingeredDiv = Finger("div");

function Demo(){
return (
<YourBoundaryWrapper>
<FingerProxy
onShortcut = { event => {
event.when(['control','shift','a'], ()=>{
// Something...
});
event.when(['control','shift','b'], ()=>{
// Something...
});
}}
/>
</YourBoundaryWrapper>
<FingeredDiv
onShortcut = { event => {
event.when(['control','shift','a'], ()=>{
// Something...
});
event.when(['control','shift','b'], ()=>{
// Something...
});
}}
/>
);
}
```
7 changes: 5 additions & 2 deletions examples/develop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ const boxStyle: CSSProperties = {
const onShortcut = (event: FingerShortcutEvent) => {
event.when(["f", "a"], () => {
console.log('FingerProxy onShortcut', event);
});
});
event.when(["f1", "f2"], () => {
console.log('FingerProxy onShortcut', event.key);
});
};

export function App() {

return (
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-finger",
"version": "2.0.1",
"version": "2.0.2",
"description": "React Finger is a library of gesture events for React that allows developers to use a single set of events for both desktop and mobile devices.",
"keywords": [
"Gesture",
Expand Down
5 changes: 5 additions & 0 deletions src/core/FingerEventWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ const POINTER_EVENT_KEYS = [
"composedPath",
"preventDefault",
"eventPhase",
"isDefaultPrevented",
"isPropagationStopped",
"isTrusted",
"defaultPrevented",
"getModifierState",
"location",
"path",
"view",
Expand Down
1 change: 1 addition & 0 deletions src/core/FingerKeyboardEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type FingerShortcutEvent<T extends Element = Element> =
FingerKeyboardEvent<
T,
{
keys: string[];
when: (keys: string[], handler: () => void) => void;
}
>;
Expand Down
8 changes: 7 additions & 1 deletion src/events/FingerShortcutProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ import {
import { FingerProvider } from "../core/FingerProviders";

const KEY_SET = Symbol();
const LAST_ACTION = Symbol();

export const FingerShortcutProvider: FingerProvider = {
name: "Shortcut",
events: ["onShortcut"],

handleKeyDown: ({ events, context, event }) => {
const { flags } = context;
if (!event.repeat) flags.set(LAST_ACTION, "down");
if (flags.get(LAST_ACTION) === "up") return;
const set = flags.has(KEY_SET)
? (flags.get(KEY_SET) as Set<string>)
: new Set<string>();
Expand All @@ -28,13 +31,16 @@ export const FingerShortcutProvider: FingerProvider = {
handler();
}
};
const shortcutEvent = FingerKeyboardEvent("onShortcut", event, { when });
const keys = Array.from(set);
const detail = { when, keys };
const shortcutEvent = FingerKeyboardEvent("onShortcut", event, detail);
events.onShortcut?.(shortcutEvent);
},

handleKeyUp: ({ context, event }) => {
const { flags } = context;
if (!flags.has(KEY_SET)) return;
flags.set(LAST_ACTION, "up");
(flags.get(KEY_SET) as Set<string>).delete(event.key.toLowerCase());
},
};

0 comments on commit bea6b86

Please sign in to comment.