@headless-tree/react 1.2.0 → 1.2.1

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,11 @@
1
1
  # @headless-tree/react
2
2
 
3
+ ## 1.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - d925607: fixed `<AssistiveTreeDescription />` component throwing an error if the dnd feature is not included (#126)
8
+
3
9
  ## 1.2.0
4
10
 
5
11
  ### Minor Changes
@@ -27,15 +27,17 @@ const styles = {
27
27
  clip: "rect(0 0 0 0)",
28
28
  };
29
29
  const getDefaultLabel = (dnd, assistiveState, hotkeys) => {
30
- var _a, _b;
30
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
31
+ if (!hotkeys.startDrag)
32
+ return ""; // No hotkey feature configured
31
33
  const itemNames = (_b = (_a = dnd === null || dnd === void 0 ? void 0 : dnd.draggedItems) === null || _a === void 0 ? void 0 : _a.map((item) => item.getItemName()).join(", ")) !== null && _b !== void 0 ? _b : "";
32
34
  const position = !(dnd === null || dnd === void 0 ? void 0 : dnd.dragTarget)
33
35
  ? "None"
34
36
  : "childIndex" in dnd.dragTarget
35
37
  ? `${dnd.dragTarget.childIndex} of ${dnd.dragTarget.item.getChildren().length} in ${dnd.dragTarget.item.getItemName()}`
36
38
  : `in ${dnd.dragTarget.item.getItemName()}`;
37
- const navGuide = `Press ${hotkeys.dragUp.hotkey} and ${hotkeys.dragDown.hotkey} to move up or down, ` +
38
- `${hotkeys.completeDrag.hotkey} to drop, ${hotkeys.cancelDrag.hotkey} to abort.`;
39
+ const navGuide = `Press ${(_c = hotkeys.dragUp) === null || _c === void 0 ? void 0 : _c.hotkey} and ${(_d = hotkeys.dragDown) === null || _d === void 0 ? void 0 : _d.hotkey} to move up or down, ` +
40
+ `${(_e = hotkeys.completeDrag) === null || _e === void 0 ? void 0 : _e.hotkey} to drop, ${(_f = hotkeys.cancelDrag) === null || _f === void 0 ? void 0 : _f.hotkey} to abort.`;
39
41
  switch (assistiveState) {
40
42
  case core_1.AssistiveDndState.Started:
41
43
  return itemNames
@@ -44,12 +46,12 @@ const getDefaultLabel = (dnd, assistiveState, hotkeys) => {
44
46
  case core_1.AssistiveDndState.Dragging:
45
47
  return itemNames ? `${itemNames}, ${position}` : position;
46
48
  case core_1.AssistiveDndState.Completed:
47
- return `Drag completed. Press ${hotkeys.startDrag.hotkey} to move selected items`;
49
+ return `Drag completed. Press ${(_g = hotkeys.startDrag) === null || _g === void 0 ? void 0 : _g.hotkey} to move selected items`;
48
50
  case core_1.AssistiveDndState.Aborted:
49
- return `Drag cancelled. Press ${hotkeys.startDrag.hotkey} to move selected items`;
51
+ return `Drag cancelled. Press ${(_h = hotkeys.startDrag) === null || _h === void 0 ? void 0 : _h.hotkey} to move selected items`;
50
52
  case core_1.AssistiveDndState.None:
51
53
  default:
52
- return `Press ${hotkeys.startDrag.hotkey} to move selected items`;
54
+ return `Press ${(_j = hotkeys.startDrag) === null || _j === void 0 ? void 0 : _j.hotkey} to move selected items`;
53
55
  }
54
56
  };
55
57
  const AssistiveTreeDescription = (_a) => {
@@ -21,15 +21,17 @@ const styles = {
21
21
  clip: "rect(0 0 0 0)",
22
22
  };
23
23
  const getDefaultLabel = (dnd, assistiveState, hotkeys) => {
24
- var _a, _b;
24
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
25
+ if (!hotkeys.startDrag)
26
+ return ""; // No hotkey feature configured
25
27
  const itemNames = (_b = (_a = dnd === null || dnd === void 0 ? void 0 : dnd.draggedItems) === null || _a === void 0 ? void 0 : _a.map((item) => item.getItemName()).join(", ")) !== null && _b !== void 0 ? _b : "";
26
28
  const position = !(dnd === null || dnd === void 0 ? void 0 : dnd.dragTarget)
27
29
  ? "None"
28
30
  : "childIndex" in dnd.dragTarget
29
31
  ? `${dnd.dragTarget.childIndex} of ${dnd.dragTarget.item.getChildren().length} in ${dnd.dragTarget.item.getItemName()}`
30
32
  : `in ${dnd.dragTarget.item.getItemName()}`;
31
- const navGuide = `Press ${hotkeys.dragUp.hotkey} and ${hotkeys.dragDown.hotkey} to move up or down, ` +
32
- `${hotkeys.completeDrag.hotkey} to drop, ${hotkeys.cancelDrag.hotkey} to abort.`;
33
+ const navGuide = `Press ${(_c = hotkeys.dragUp) === null || _c === void 0 ? void 0 : _c.hotkey} and ${(_d = hotkeys.dragDown) === null || _d === void 0 ? void 0 : _d.hotkey} to move up or down, ` +
34
+ `${(_e = hotkeys.completeDrag) === null || _e === void 0 ? void 0 : _e.hotkey} to drop, ${(_f = hotkeys.cancelDrag) === null || _f === void 0 ? void 0 : _f.hotkey} to abort.`;
33
35
  switch (assistiveState) {
34
36
  case AssistiveDndState.Started:
35
37
  return itemNames
@@ -38,12 +40,12 @@ const getDefaultLabel = (dnd, assistiveState, hotkeys) => {
38
40
  case AssistiveDndState.Dragging:
39
41
  return itemNames ? `${itemNames}, ${position}` : position;
40
42
  case AssistiveDndState.Completed:
41
- return `Drag completed. Press ${hotkeys.startDrag.hotkey} to move selected items`;
43
+ return `Drag completed. Press ${(_g = hotkeys.startDrag) === null || _g === void 0 ? void 0 : _g.hotkey} to move selected items`;
42
44
  case AssistiveDndState.Aborted:
43
- return `Drag cancelled. Press ${hotkeys.startDrag.hotkey} to move selected items`;
45
+ return `Drag cancelled. Press ${(_h = hotkeys.startDrag) === null || _h === void 0 ? void 0 : _h.hotkey} to move selected items`;
44
46
  case AssistiveDndState.None:
45
47
  default:
46
- return `Press ${hotkeys.startDrag.hotkey} to move selected items`;
48
+ return `Press ${(_j = hotkeys.startDrag) === null || _j === void 0 ? void 0 : _j.hotkey} to move selected items`;
47
49
  }
48
50
  };
49
51
  export const AssistiveTreeDescription = (_a) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@headless-tree/react",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "main": "lib/cjs/index.js",
5
5
  "module": "lib/esm/index.js",
6
6
  "types": "lib/esm/index.d.ts",
@@ -22,6 +22,7 @@ const getDefaultLabel = <T,>(
22
22
  assistiveState: AssistiveDndState,
23
23
  hotkeys: HotkeysConfig<T>,
24
24
  ) => {
25
+ if (!hotkeys.startDrag) return ""; // No hotkey feature configured
25
26
  const itemNames =
26
27
  dnd?.draggedItems?.map((item) => item.getItemName()).join(", ") ?? "";
27
28
  const position = !dnd?.dragTarget
@@ -30,8 +31,8 @@ const getDefaultLabel = <T,>(
30
31
  ? `${dnd.dragTarget.childIndex} of ${dnd.dragTarget.item.getChildren().length} in ${dnd.dragTarget.item.getItemName()}`
31
32
  : `in ${dnd.dragTarget.item.getItemName()}`;
32
33
  const navGuide =
33
- `Press ${hotkeys.dragUp.hotkey} and ${hotkeys.dragDown.hotkey} to move up or down, ` +
34
- `${hotkeys.completeDrag.hotkey} to drop, ${hotkeys.cancelDrag.hotkey} to abort.`;
34
+ `Press ${hotkeys.dragUp?.hotkey} and ${hotkeys.dragDown?.hotkey} to move up or down, ` +
35
+ `${hotkeys.completeDrag?.hotkey} to drop, ${hotkeys.cancelDrag?.hotkey} to abort.`;
35
36
  switch (assistiveState) {
36
37
  case AssistiveDndState.Started:
37
38
  return itemNames
@@ -40,12 +41,12 @@ const getDefaultLabel = <T,>(
40
41
  case AssistiveDndState.Dragging:
41
42
  return itemNames ? `${itemNames}, ${position}` : position;
42
43
  case AssistiveDndState.Completed:
43
- return `Drag completed. Press ${hotkeys.startDrag.hotkey} to move selected items`;
44
+ return `Drag completed. Press ${hotkeys.startDrag?.hotkey} to move selected items`;
44
45
  case AssistiveDndState.Aborted:
45
- return `Drag cancelled. Press ${hotkeys.startDrag.hotkey} to move selected items`;
46
+ return `Drag cancelled. Press ${hotkeys.startDrag?.hotkey} to move selected items`;
46
47
  case AssistiveDndState.None:
47
48
  default:
48
- return `Press ${hotkeys.startDrag.hotkey} to move selected items`;
49
+ return `Press ${hotkeys.startDrag?.hotkey} to move selected items`;
49
50
  }
50
51
  };
51
52