@headless-tree/core 0.0.0-20250506223720 → 0.0.0-20250506225032

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,10 +1,12 @@
1
1
  # @headless-tree/core
2
2
 
3
- ## 0.0.0-20250506223720
3
+ ## 0.0.0-20250506225032
4
4
 
5
5
  ### Patch Changes
6
6
 
7
+ - c9f9932: fixed tree.focusNextItem() and tree.focusPreviousItem() throwing if no item is currently focused
7
8
  - 6ed84b4: recursive item references are filtered out when rendering (#89)
9
+ - 4bef2f2: fixed a bug where hotkeys involving shift may not work properly depending on the order of shift and other key inputs (#98)
8
10
 
9
11
  ## 1.0.0
10
12
 
@@ -8,7 +8,7 @@ const specialKeys = {
8
8
  Space: /^ $/,
9
9
  };
10
10
  const testHotkeyMatch = (pressedKeys, tree, hotkey) => {
11
- const supposedKeys = hotkey.hotkey.split("+");
11
+ const supposedKeys = hotkey.hotkey.toLowerCase().split("+");
12
12
  const doKeysMatch = supposedKeys.every((key) => key in specialKeys
13
13
  ? [...pressedKeys].some((pressedKey) => specialKeys[key].test(pressedKey))
14
14
  : pressedKeys.has(key));
@@ -27,9 +27,10 @@ exports.hotkeysCoreFeature = {
27
27
  const keydown = (e) => {
28
28
  var _a, _b, _c, _d;
29
29
  var _e;
30
+ const key = e.key.toLowerCase();
30
31
  (_a = (_e = data.current).pressedKeys) !== null && _a !== void 0 ? _a : (_e.pressedKeys = new Set());
31
- const newMatch = !data.current.pressedKeys.has(e.key);
32
- data.current.pressedKeys.add(e.key);
32
+ const newMatch = !data.current.pressedKeys.has(key);
33
+ data.current.pressedKeys.add(key);
33
34
  const hotkeyName = findHotkeyMatch(data.current.pressedKeys, tree, tree.getHotkeyPresets(), tree.getConfig().hotkeys);
34
35
  if (!hotkeyName)
35
36
  return;
@@ -50,7 +51,7 @@ exports.hotkeysCoreFeature = {
50
51
  var _a;
51
52
  var _b;
52
53
  (_a = (_b = data.current).pressedKeys) !== null && _a !== void 0 ? _a : (_b.pressedKeys = new Set());
53
- data.current.pressedKeys.delete(e.key);
54
+ data.current.pressedKeys.delete(e.key.toLowerCase());
54
55
  };
55
56
  // keyup is registered on document, because some hotkeys shift
56
57
  // the focus away from the tree (i.e. search)
@@ -61,14 +61,18 @@ exports.treeFeature = {
61
61
  },
62
62
  focusNextItem: ({ tree }) => {
63
63
  var _a;
64
- const { index } = tree.getFocusedItem().getItemMeta();
65
- const nextIndex = Math.min(index + 1, tree.getItems().length - 1);
64
+ const focused = tree.getFocusedItem().getItemMeta();
65
+ if (!focused)
66
+ return;
67
+ const nextIndex = Math.min(focused.index + 1, tree.getItems().length - 1);
66
68
  (_a = tree.getItems()[nextIndex]) === null || _a === void 0 ? void 0 : _a.setFocused();
67
69
  },
68
70
  focusPreviousItem: ({ tree }) => {
69
71
  var _a;
70
- const { index } = tree.getFocusedItem().getItemMeta();
71
- const nextIndex = Math.max(index - 1, 0);
72
+ const focused = tree.getFocusedItem().getItemMeta();
73
+ if (!focused)
74
+ return;
75
+ const nextIndex = Math.max(focused.index - 1, 0);
72
76
  (_a = tree.getItems()[nextIndex]) === null || _a === void 0 ? void 0 : _a.setFocused();
73
77
  },
74
78
  updateDomFocus: ({ tree }) => {
@@ -5,7 +5,7 @@ const specialKeys = {
5
5
  Space: /^ $/,
6
6
  };
7
7
  const testHotkeyMatch = (pressedKeys, tree, hotkey) => {
8
- const supposedKeys = hotkey.hotkey.split("+");
8
+ const supposedKeys = hotkey.hotkey.toLowerCase().split("+");
9
9
  const doKeysMatch = supposedKeys.every((key) => key in specialKeys
10
10
  ? [...pressedKeys].some((pressedKey) => specialKeys[key].test(pressedKey))
11
11
  : pressedKeys.has(key));
@@ -24,9 +24,10 @@ export const hotkeysCoreFeature = {
24
24
  const keydown = (e) => {
25
25
  var _a, _b, _c, _d;
26
26
  var _e;
27
+ const key = e.key.toLowerCase();
27
28
  (_a = (_e = data.current).pressedKeys) !== null && _a !== void 0 ? _a : (_e.pressedKeys = new Set());
28
- const newMatch = !data.current.pressedKeys.has(e.key);
29
- data.current.pressedKeys.add(e.key);
29
+ const newMatch = !data.current.pressedKeys.has(key);
30
+ data.current.pressedKeys.add(key);
30
31
  const hotkeyName = findHotkeyMatch(data.current.pressedKeys, tree, tree.getHotkeyPresets(), tree.getConfig().hotkeys);
31
32
  if (!hotkeyName)
32
33
  return;
@@ -47,7 +48,7 @@ export const hotkeysCoreFeature = {
47
48
  var _a;
48
49
  var _b;
49
50
  (_a = (_b = data.current).pressedKeys) !== null && _a !== void 0 ? _a : (_b.pressedKeys = new Set());
50
- data.current.pressedKeys.delete(e.key);
51
+ data.current.pressedKeys.delete(e.key.toLowerCase());
51
52
  };
52
53
  // keyup is registered on document, because some hotkeys shift
53
54
  // the focus away from the tree (i.e. search)
@@ -58,14 +58,18 @@ export const treeFeature = {
58
58
  },
59
59
  focusNextItem: ({ tree }) => {
60
60
  var _a;
61
- const { index } = tree.getFocusedItem().getItemMeta();
62
- const nextIndex = Math.min(index + 1, tree.getItems().length - 1);
61
+ const focused = tree.getFocusedItem().getItemMeta();
62
+ if (!focused)
63
+ return;
64
+ const nextIndex = Math.min(focused.index + 1, tree.getItems().length - 1);
63
65
  (_a = tree.getItems()[nextIndex]) === null || _a === void 0 ? void 0 : _a.setFocused();
64
66
  },
65
67
  focusPreviousItem: ({ tree }) => {
66
68
  var _a;
67
- const { index } = tree.getFocusedItem().getItemMeta();
68
- const nextIndex = Math.max(index - 1, 0);
69
+ const focused = tree.getFocusedItem().getItemMeta();
70
+ if (!focused)
71
+ return;
72
+ const nextIndex = Math.max(focused.index - 1, 0);
69
73
  (_a = tree.getItems()[nextIndex]) === null || _a === void 0 ? void 0 : _a.setFocused();
70
74
  },
71
75
  updateDomFocus: ({ tree }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@headless-tree/core",
3
- "version": "0.0.0-20250506223720",
3
+ "version": "0.0.0-20250506225032",
4
4
  "type": "module",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/esm/index.js",
@@ -17,7 +17,7 @@ const testHotkeyMatch = (
17
17
  tree: TreeInstance<any>,
18
18
  hotkey: HotkeyConfig<any>,
19
19
  ) => {
20
- const supposedKeys = hotkey.hotkey.split("+");
20
+ const supposedKeys = hotkey.hotkey.toLowerCase().split("+");
21
21
  const doKeysMatch = supposedKeys.every((key) =>
22
22
  key in specialKeys
23
23
  ? [...pressedKeys].some((pressedKey) => specialKeys[key].test(pressedKey))
@@ -45,9 +45,10 @@ export const hotkeysCoreFeature: FeatureImplementation = {
45
45
  onTreeMount: (tree, element) => {
46
46
  const data = tree.getDataRef<HotkeysCoreDataRef>();
47
47
  const keydown = (e: KeyboardEvent) => {
48
+ const key = e.key.toLowerCase();
48
49
  data.current.pressedKeys ??= new Set();
49
- const newMatch = !data.current.pressedKeys.has(e.key);
50
- data.current.pressedKeys.add(e.key);
50
+ const newMatch = !data.current.pressedKeys.has(key);
51
+ data.current.pressedKeys.add(key);
51
52
 
52
53
  const hotkeyName = findHotkeyMatch(
53
54
  data.current.pressedKeys,
@@ -78,7 +79,7 @@ export const hotkeysCoreFeature: FeatureImplementation = {
78
79
 
79
80
  const keyup = (e: KeyboardEvent) => {
80
81
  data.current.pressedKeys ??= new Set();
81
- data.current.pressedKeys.delete(e.key);
82
+ data.current.pressedKeys.delete(e.key.toLowerCase());
82
83
  };
83
84
 
84
85
  // keyup is registered on document, because some hotkeys shift
@@ -83,14 +83,16 @@ export const treeFeature: FeatureImplementation<any> = {
83
83
  },
84
84
 
85
85
  focusNextItem: ({ tree }) => {
86
- const { index } = tree.getFocusedItem().getItemMeta();
87
- const nextIndex = Math.min(index + 1, tree.getItems().length - 1);
86
+ const focused = tree.getFocusedItem().getItemMeta();
87
+ if (!focused) return;
88
+ const nextIndex = Math.min(focused.index + 1, tree.getItems().length - 1);
88
89
  tree.getItems()[nextIndex]?.setFocused();
89
90
  },
90
91
 
91
92
  focusPreviousItem: ({ tree }) => {
92
- const { index } = tree.getFocusedItem().getItemMeta();
93
- const nextIndex = Math.max(index - 1, 0);
93
+ const focused = tree.getFocusedItem().getItemMeta();
94
+ if (!focused) return;
95
+ const nextIndex = Math.max(focused.index - 1, 0);
94
96
  tree.getItems()[nextIndex]?.setFocused();
95
97
  },
96
98