timvir 0.2.48 → 0.2.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/core/index.js +44 -10
- package/package.json +2 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# timvir
|
|
2
2
|
|
|
3
|
+
## 0.2.49
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- **Remove dependency on react-hotkeys-hook** ([#3660](https://github.com/timvir/timvir/pull/3660)) - Timvir has only relied on a small part of the full capability of react-hotkeys-hook. It was easy enough to re-implement the necessary functionality and drop the dependency.
|
|
8
|
+
|
|
3
9
|
## 0.2.48
|
|
4
10
|
|
|
5
11
|
## 0.2.47
|
package/core/index.js
CHANGED
|
@@ -5,7 +5,6 @@ export { useContext } from 'timvir/context';
|
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import * as builtins from 'timvir/builtins';
|
|
7
7
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
8
|
-
import { useHotkeys } from 'react-hotkeys-hook';
|
|
9
8
|
import { makeBus } from 'timvir/bus';
|
|
10
9
|
import * as ReactDOM from 'react-dom';
|
|
11
10
|
import { defaultSearch } from 'timvir/search';
|
|
@@ -824,27 +823,31 @@ function Page(props$1, ref) {
|
|
|
824
823
|
blocks,
|
|
825
824
|
toc
|
|
826
825
|
}), [bus, mdxComponents, location, Link, blocks, toc]);
|
|
827
|
-
useHotkeys(
|
|
826
|
+
useHotkeys({
|
|
827
|
+
modifiers: ["meta"],
|
|
828
|
+
key: "p"
|
|
829
|
+
}, ev => {
|
|
828
830
|
ev.preventDefault();
|
|
829
831
|
setState({
|
|
830
832
|
search: {
|
|
831
833
|
open: !state.search.open
|
|
832
834
|
}
|
|
833
835
|
});
|
|
834
|
-
}, {
|
|
835
|
-
enableOnFormTags: true
|
|
836
836
|
});
|
|
837
|
-
useHotkeys(
|
|
837
|
+
useHotkeys({
|
|
838
|
+
modifiers: ["meta"],
|
|
839
|
+
key: "k"
|
|
840
|
+
}, ev => {
|
|
838
841
|
ev.preventDefault();
|
|
839
842
|
setState({
|
|
840
843
|
search: {
|
|
841
844
|
open: !state.search.open
|
|
842
845
|
}
|
|
843
846
|
});
|
|
844
|
-
}, {
|
|
845
|
-
enableOnFormTags: ["INPUT"]
|
|
846
847
|
});
|
|
847
|
-
useHotkeys(
|
|
848
|
+
useHotkeys({
|
|
849
|
+
key: "escape"
|
|
850
|
+
}, ev => {
|
|
848
851
|
if (state.search.open) {
|
|
849
852
|
ev.preventDefault();
|
|
850
853
|
setState({
|
|
@@ -853,8 +856,6 @@ function Page(props$1, ref) {
|
|
|
853
856
|
}
|
|
854
857
|
});
|
|
855
858
|
}
|
|
856
|
-
}, {
|
|
857
|
-
enableOnFormTags: true
|
|
858
859
|
});
|
|
859
860
|
return /*#__PURE__*/jsxs(Provider, {
|
|
860
861
|
value: context,
|
|
@@ -958,6 +959,39 @@ const styles = {
|
|
|
958
959
|
$$css: true
|
|
959
960
|
}
|
|
960
961
|
};
|
|
962
|
+
function useHotkeys(trigger, callback) {
|
|
963
|
+
const ref = React.useRef({
|
|
964
|
+
trigger,
|
|
965
|
+
callback
|
|
966
|
+
});
|
|
967
|
+
React.useLayoutEffect(() => {
|
|
968
|
+
ref.current = {
|
|
969
|
+
trigger,
|
|
970
|
+
callback
|
|
971
|
+
};
|
|
972
|
+
});
|
|
973
|
+
React.useEffect(() => {
|
|
974
|
+
const handleKeyDown = event => {
|
|
975
|
+
if (ref.current.trigger.key.toLowerCase() !== event.key.toLowerCase()) {
|
|
976
|
+
return;
|
|
977
|
+
}
|
|
978
|
+
{
|
|
979
|
+
const allModifiers = ["alt", "ctrl", "meta", "shift"];
|
|
980
|
+
const expectedModifiers = ref.current.trigger.modifiers ?? [];
|
|
981
|
+
for (const modifier of allModifiers) {
|
|
982
|
+
if (event[`${modifier}Key`] !== expectedModifiers.includes(modifier)) {
|
|
983
|
+
return;
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
ref.current.callback(event);
|
|
988
|
+
};
|
|
989
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
990
|
+
return () => {
|
|
991
|
+
window.removeEventListener("keydown", handleKeyDown);
|
|
992
|
+
};
|
|
993
|
+
}, []);
|
|
994
|
+
}
|
|
961
995
|
|
|
962
996
|
/**
|
|
963
997
|
* A mailbox is a wonka source which receives messages for one specific block (identified by its id).
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "timvir",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.49",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"exports": {
|
|
@@ -22,8 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"react": "^17 || ^18 || ^19",
|
|
25
|
-
"react-dom": "^17 || ^18 || ^19"
|
|
26
|
-
"react-hotkeys-hook": "^4 || ^5"
|
|
25
|
+
"react-dom": "^17 || ^18 || ^19"
|
|
27
26
|
},
|
|
28
27
|
"repository": {
|
|
29
28
|
"type": "git",
|