timvir 0.2.47 → 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 CHANGED
@@ -1,5 +1,13 @@
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
+
9
+ ## 0.2.48
10
+
3
11
  ## 0.2.47
4
12
 
5
13
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import { Code, Grid } from "timvir/blocks";
1
+ import { Grid } from "timvir/blocks";
2
2
 
3
3
  # Exhibit
4
4
 
@@ -21,9 +21,11 @@ Think of the `<Exhibit>` block as a `<figure>` + `<figcaption>` for React compon
21
21
 
22
22
  Import `Exhibit` from the `timvir/blocks` module, then use in a Timvir mdx page like so:
23
23
 
24
- <Code language="jsx">
25
- <Sample variant="usage" as="source/markup" />
26
- </Code>
24
+ ```jsx
25
+ <Exhibit caption="Here goes your caption">
26
+ <YourReactComponent />
27
+ </Exhibit>
28
+ ```
27
29
 
28
30
  ## Bleed
29
31
 
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("meta+p", ev => {
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("meta+k", ev => {
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("escape", ev => {
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.47",
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",
@@ -1 +0,0 @@
1
- export default function Sample(): import("react/jsx-runtime").JSX.Element;