@salutejs/plasma-new-hope 0.340.0-canary.2314.18974837629.0 → 0.340.0-canary.2314.19038910206.0

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.
Files changed (141) hide show
  1. package/cjs/components/Combobox/ComboboxNew/Combobox.js +20 -4
  2. package/cjs/components/Combobox/ComboboxNew/Combobox.js.map +1 -1
  3. package/cjs/components/Combobox/ComboboxNew/hooks/useKeyboardNavigation.js +319 -1
  4. package/cjs/components/Combobox/ComboboxNew/hooks/useKeyboardNavigation.js.map +1 -1
  5. package/cjs/components/Combobox/ComboboxNew/reducers/focusedPathReducer.js +7 -0
  6. package/cjs/components/Combobox/ComboboxNew/reducers/focusedPathReducer.js.map +1 -1
  7. package/cjs/components/Combobox/ComboboxNew/reducers/treePathReducer.js +14 -2
  8. package/cjs/components/Combobox/ComboboxNew/reducers/treePathReducer.js.map +1 -1
  9. package/cjs/components/Combobox/ComboboxNew/ui/TreeList/TreeList.js +3 -3
  10. package/cjs/components/Combobox/ComboboxNew/ui/TreeList/TreeList.js.map +1 -1
  11. package/cjs/components/Combobox/ComboboxNew/ui/TreeList/ui/Item/Item.js +22 -5
  12. package/cjs/components/Combobox/ComboboxNew/ui/TreeList/ui/Item/Item.js.map +1 -1
  13. package/cjs/components/Select/Select.js +2 -1
  14. package/cjs/components/Select/Select.js.map +1 -1
  15. package/cjs/components/Select/hooks/useKeyboardNavigation.js +127 -38
  16. package/cjs/components/Select/hooks/useKeyboardNavigation.js.map +1 -1
  17. package/cjs/components/Select/reducers/focusedPathReducer.js +7 -0
  18. package/cjs/components/Select/reducers/focusedPathReducer.js.map +1 -1
  19. package/cjs/components/Select/reducers/treePathReducer.js +12 -0
  20. package/cjs/components/Select/reducers/treePathReducer.js.map +1 -1
  21. package/cjs/components/Select/ui/TreeList/TreeList.js +3 -3
  22. package/cjs/components/Select/ui/TreeList/TreeList.js.map +1 -1
  23. package/cjs/components/Select/ui/TreeList/ui/Item/Item.js +22 -5
  24. package/cjs/components/Select/ui/TreeList/ui/Item/Item.js.map +1 -1
  25. package/cjs/index.js +2 -0
  26. package/cjs/index.js.map +1 -1
  27. package/cjs/utils/index.js.map +1 -1
  28. package/cjs/utils/isArraysEqual.js +12 -0
  29. package/cjs/utils/isArraysEqual.js.map +1 -0
  30. package/emotion/cjs/components/Combobox/ComboboxNew/Combobox.js +16 -3
  31. package/emotion/cjs/components/Combobox/ComboboxNew/hooks/useKeyboardNavigation.js +312 -0
  32. package/emotion/cjs/components/Combobox/ComboboxNew/reducers/focusedPathReducer.js +7 -0
  33. package/emotion/cjs/components/Combobox/ComboboxNew/reducers/treePathReducer.js +14 -2
  34. package/emotion/cjs/components/Combobox/ComboboxNew/ui/TreeList/TreeList.js +7 -3
  35. package/emotion/cjs/components/Combobox/ComboboxNew/ui/TreeList/ui/Item/Item.js +49 -5
  36. package/emotion/cjs/components/Select/Select.js +2 -1
  37. package/emotion/cjs/components/Select/hooks/useKeyboardNavigation.js +156 -44
  38. package/emotion/cjs/components/Select/reducers/focusedPathReducer.js +7 -0
  39. package/emotion/cjs/components/Select/reducers/treePathReducer.js +12 -0
  40. package/emotion/cjs/components/Select/ui/TreeList/TreeList.js +7 -3
  41. package/emotion/cjs/components/Select/ui/TreeList/ui/Item/Item.js +49 -5
  42. package/emotion/cjs/examples/components/Combobox/Combobox.js +15 -0
  43. package/emotion/cjs/utils/index.js +4 -0
  44. package/emotion/cjs/utils/isArraysEqual.js +15 -0
  45. package/emotion/es/components/Combobox/ComboboxNew/Combobox.js +16 -3
  46. package/emotion/es/components/Combobox/ComboboxNew/hooks/useKeyboardNavigation.js +313 -0
  47. package/emotion/es/components/Combobox/ComboboxNew/reducers/focusedPathReducer.js +7 -0
  48. package/emotion/es/components/Combobox/ComboboxNew/reducers/treePathReducer.js +14 -2
  49. package/emotion/es/components/Combobox/ComboboxNew/ui/TreeList/TreeList.js +7 -3
  50. package/emotion/es/components/Combobox/ComboboxNew/ui/TreeList/ui/Item/Item.js +50 -6
  51. package/emotion/es/components/Select/Select.js +2 -1
  52. package/emotion/es/components/Select/hooks/useKeyboardNavigation.js +157 -44
  53. package/emotion/es/components/Select/reducers/focusedPathReducer.js +7 -0
  54. package/emotion/es/components/Select/reducers/treePathReducer.js +12 -0
  55. package/emotion/es/components/Select/ui/TreeList/TreeList.js +7 -3
  56. package/emotion/es/components/Select/ui/TreeList/ui/Item/Item.js +50 -6
  57. package/emotion/es/utils/index.js +1 -0
  58. package/emotion/es/utils/isArraysEqual.js +5 -0
  59. package/es/components/Combobox/ComboboxNew/Combobox.js +20 -4
  60. package/es/components/Combobox/ComboboxNew/Combobox.js.map +1 -1
  61. package/es/components/Combobox/ComboboxNew/hooks/useKeyboardNavigation.js +319 -1
  62. package/es/components/Combobox/ComboboxNew/hooks/useKeyboardNavigation.js.map +1 -1
  63. package/es/components/Combobox/ComboboxNew/reducers/focusedPathReducer.js +7 -0
  64. package/es/components/Combobox/ComboboxNew/reducers/focusedPathReducer.js.map +1 -1
  65. package/es/components/Combobox/ComboboxNew/reducers/treePathReducer.js +14 -2
  66. package/es/components/Combobox/ComboboxNew/reducers/treePathReducer.js.map +1 -1
  67. package/es/components/Combobox/ComboboxNew/ui/TreeList/TreeList.js +3 -3
  68. package/es/components/Combobox/ComboboxNew/ui/TreeList/TreeList.js.map +1 -1
  69. package/es/components/Combobox/ComboboxNew/ui/TreeList/ui/Item/Item.js +23 -6
  70. package/es/components/Combobox/ComboboxNew/ui/TreeList/ui/Item/Item.js.map +1 -1
  71. package/es/components/Select/Select.js +2 -1
  72. package/es/components/Select/Select.js.map +1 -1
  73. package/es/components/Select/hooks/useKeyboardNavigation.js +127 -38
  74. package/es/components/Select/hooks/useKeyboardNavigation.js.map +1 -1
  75. package/es/components/Select/reducers/focusedPathReducer.js +7 -0
  76. package/es/components/Select/reducers/focusedPathReducer.js.map +1 -1
  77. package/es/components/Select/reducers/treePathReducer.js +12 -0
  78. package/es/components/Select/reducers/treePathReducer.js.map +1 -1
  79. package/es/components/Select/ui/TreeList/TreeList.js +3 -3
  80. package/es/components/Select/ui/TreeList/TreeList.js.map +1 -1
  81. package/es/components/Select/ui/TreeList/ui/Item/Item.js +23 -6
  82. package/es/components/Select/ui/TreeList/ui/Item/Item.js.map +1 -1
  83. package/es/index.js +1 -0
  84. package/es/index.js.map +1 -1
  85. package/es/utils/index.js.map +1 -1
  86. package/es/utils/isArraysEqual.js +8 -0
  87. package/es/utils/isArraysEqual.js.map +1 -0
  88. package/package.json +2 -2
  89. package/styled-components/cjs/components/Combobox/ComboboxNew/Combobox.js +16 -3
  90. package/styled-components/cjs/components/Combobox/ComboboxNew/hooks/useKeyboardNavigation.js +312 -0
  91. package/styled-components/cjs/components/Combobox/ComboboxNew/reducers/focusedPathReducer.js +7 -0
  92. package/styled-components/cjs/components/Combobox/ComboboxNew/reducers/treePathReducer.js +14 -2
  93. package/styled-components/cjs/components/Combobox/ComboboxNew/ui/TreeList/TreeList.js +7 -3
  94. package/styled-components/cjs/components/Combobox/ComboboxNew/ui/TreeList/ui/Item/Item.js +49 -5
  95. package/styled-components/cjs/components/Select/Select.js +2 -1
  96. package/styled-components/cjs/components/Select/hooks/useKeyboardNavigation.js +156 -44
  97. package/styled-components/cjs/components/Select/reducers/focusedPathReducer.js +7 -0
  98. package/styled-components/cjs/components/Select/reducers/treePathReducer.js +12 -0
  99. package/styled-components/cjs/components/Select/ui/TreeList/TreeList.js +7 -3
  100. package/styled-components/cjs/components/Select/ui/TreeList/ui/Item/Item.js +49 -5
  101. package/styled-components/cjs/utils/index.js +4 -0
  102. package/styled-components/cjs/utils/isArraysEqual.js +15 -0
  103. package/styled-components/es/components/Combobox/ComboboxNew/Combobox.js +16 -3
  104. package/styled-components/es/components/Combobox/ComboboxNew/hooks/useKeyboardNavigation.js +313 -0
  105. package/styled-components/es/components/Combobox/ComboboxNew/reducers/focusedPathReducer.js +7 -0
  106. package/styled-components/es/components/Combobox/ComboboxNew/reducers/treePathReducer.js +14 -2
  107. package/styled-components/es/components/Combobox/ComboboxNew/ui/TreeList/TreeList.js +7 -3
  108. package/styled-components/es/components/Combobox/ComboboxNew/ui/TreeList/ui/Item/Item.js +50 -6
  109. package/styled-components/es/components/Select/Select.js +2 -1
  110. package/styled-components/es/components/Select/hooks/useKeyboardNavigation.js +157 -44
  111. package/styled-components/es/components/Select/reducers/focusedPathReducer.js +7 -0
  112. package/styled-components/es/components/Select/reducers/treePathReducer.js +12 -0
  113. package/styled-components/es/components/Select/ui/TreeList/TreeList.js +7 -3
  114. package/styled-components/es/components/Select/ui/TreeList/ui/Item/Item.js +50 -6
  115. package/styled-components/es/examples/components/Combobox/Combobox.js +0 -7
  116. package/styled-components/es/utils/index.js +1 -0
  117. package/styled-components/es/utils/isArraysEqual.js +5 -0
  118. package/types/components/Combobox/ComboboxNew/Combobox.d.ts.map +1 -1
  119. package/types/components/Combobox/ComboboxNew/hooks/useKeyboardNavigation.d.ts +7 -2
  120. package/types/components/Combobox/ComboboxNew/hooks/useKeyboardNavigation.d.ts.map +1 -1
  121. package/types/components/Combobox/ComboboxNew/reducers/focusedPathReducer.d.ts +3 -0
  122. package/types/components/Combobox/ComboboxNew/reducers/focusedPathReducer.d.ts.map +1 -1
  123. package/types/components/Combobox/ComboboxNew/reducers/treePathReducer.d.ts +6 -0
  124. package/types/components/Combobox/ComboboxNew/reducers/treePathReducer.d.ts.map +1 -1
  125. package/types/components/Combobox/ComboboxNew/ui/TreeList/ui/Item/Item.d.ts.map +1 -1
  126. package/types/components/Combobox/ComboboxNew/ui/TreeList/ui/Item/Item.types.d.ts +1 -1
  127. package/types/components/Combobox/ComboboxNew/ui/TreeList/ui/Item/Item.types.d.ts.map +1 -1
  128. package/types/components/Select/Select.d.ts.map +1 -1
  129. package/types/components/Select/hooks/useKeyboardNavigation.d.ts +2 -1
  130. package/types/components/Select/hooks/useKeyboardNavigation.d.ts.map +1 -1
  131. package/types/components/Select/reducers/focusedPathReducer.d.ts +3 -0
  132. package/types/components/Select/reducers/focusedPathReducer.d.ts.map +1 -1
  133. package/types/components/Select/reducers/treePathReducer.d.ts +6 -0
  134. package/types/components/Select/reducers/treePathReducer.d.ts.map +1 -1
  135. package/types/components/Select/ui/TreeList/ui/Item/Item.d.ts.map +1 -1
  136. package/types/components/Select/ui/TreeList/ui/Item/Item.types.d.ts +1 -1
  137. package/types/components/Select/ui/TreeList/ui/Item/Item.types.d.ts.map +1 -1
  138. package/types/utils/index.d.ts +1 -0
  139. package/types/utils/index.d.ts.map +1 -1
  140. package/types/utils/isArraysEqual.d.ts +2 -0
  141. package/types/utils/isArraysEqual.d.ts.map +1 -0
@@ -1,4 +1,30 @@
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _array_without_holes(arr) {
7
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
8
+ }
9
+ function _iterable_to_array(iter) {
10
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
11
+ }
12
+ function _non_iterable_spread() {
13
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
14
+ }
15
+ function _to_consumable_array(arr) {
16
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
17
+ }
18
+ function _unsupported_iterable_to_array(o, minLen) {
19
+ if (!o) return;
20
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
21
+ var n = Object.prototype.toString.call(o).slice(8, -1);
22
+ if (n === "Object" && o.constructor) n = o.constructor.name;
23
+ if (n === "Map" || n === "Set") return Array.from(n);
24
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
25
+ }
1
26
  import { isEmpty } from "../../../../utils";
27
+ import { keyExists } from "../../../Select/reducers";
2
28
  var JUMP_SIZE = 10;
3
29
  export var keys = {
4
30
  Enter: 'Enter',
@@ -21,7 +47,53 @@ export var getItemByFocused = function(focusedPath, focusedToValueMap) {
21
47
  }, '').replace(/^(\/)/, '');
22
48
  return focusedToValueMap.get(focusedPathAsString);
23
49
  };
50
+ // #TODO: подумать над идеей выноса логики фокуса непосредственно в focusedPathReducer.
24
51
  export var useKeyNavigation = function(param) {
52
+ var focusedPath = param.focusedPath, dispatchFocusedPath = param.dispatchFocusedPath, path = param.path, dispatchPath = param.dispatchPath, pathMap = param.pathMap, focusedToValueMap = param.focusedToValueMap, handleListToggle = param.handleListToggle, handlePressDown = param.handlePressDown, setTextValue = param.setTextValue, multiple = param.multiple, value = param.value, textValue = param.textValue, valueToItemMap = param.valueToItemMap, treePath = param.treePath, dispatchTreePath = param.dispatchTreePath, treeView = param.treeView, valueToPathMap = param.valueToPathMap, items = param.items;
53
+ if (treeView) {
54
+ return keyboardNavigationTree({
55
+ focusedPath: focusedPath,
56
+ dispatchFocusedPath: dispatchFocusedPath,
57
+ path: path,
58
+ dispatchPath: dispatchPath,
59
+ pathMap: pathMap,
60
+ focusedToValueMap: focusedToValueMap,
61
+ handleListToggle: handleListToggle,
62
+ handlePressDown: handlePressDown,
63
+ setTextValue: setTextValue,
64
+ multiple: multiple,
65
+ value: value,
66
+ textValue: textValue,
67
+ valueToItemMap: valueToItemMap,
68
+ treePath: treePath,
69
+ dispatchTreePath: dispatchTreePath,
70
+ treeView: treeView,
71
+ valueToPathMap: valueToPathMap,
72
+ items: items
73
+ });
74
+ }
75
+ return keyboardNavigationDefault({
76
+ focusedPath: focusedPath,
77
+ dispatchFocusedPath: dispatchFocusedPath,
78
+ path: path,
79
+ dispatchPath: dispatchPath,
80
+ pathMap: pathMap,
81
+ focusedToValueMap: focusedToValueMap,
82
+ handleListToggle: handleListToggle,
83
+ handlePressDown: handlePressDown,
84
+ setTextValue: setTextValue,
85
+ multiple: multiple,
86
+ value: value,
87
+ textValue: textValue,
88
+ valueToItemMap: valueToItemMap,
89
+ treePath: treePath,
90
+ dispatchTreePath: dispatchTreePath,
91
+ treeView: treeView,
92
+ valueToPathMap: valueToPathMap,
93
+ items: items
94
+ });
95
+ };
96
+ var keyboardNavigationDefault = function(param) {
25
97
  var focusedPath = param.focusedPath, dispatchFocusedPath = param.dispatchFocusedPath, path = param.path, dispatchPath = param.dispatchPath, pathMap = param.pathMap, focusedToValueMap = param.focusedToValueMap, handleListToggle = param.handleListToggle, handlePressDown = param.handlePressDown, setTextValue = param.setTextValue, multiple = param.multiple, value = param.value, textValue = param.textValue, valueToItemMap = param.valueToItemMap;
26
98
  var currentIndex = (focusedPath === null || focusedPath === void 0 ? void 0 : focusedPath[focusedPath.length - 1]) || 0;
27
99
  var currentLength = pathMap.get(path === null || path === void 0 ? void 0 : path[focusedPath.length - 1]) || 0;
@@ -280,3 +352,244 @@ export var useKeyNavigation = function(param) {
280
352
  onKeyDown: onKeyDown
281
353
  };
282
354
  };
355
+ var keyboardNavigationTree = function(param) {
356
+ var focusedPath = param.focusedPath, dispatchFocusedPath = param.dispatchFocusedPath, path = param.path, dispatchPath = param.dispatchPath, pathMap = param.pathMap, focusedToValueMap = param.focusedToValueMap, handleListToggle = param.handleListToggle, handlePressDown = param.handlePressDown, setTextValue = param.setTextValue, multiple = param.multiple, value = param.value, textValue = param.textValue, valueToItemMap = param.valueToItemMap, treePath = param.treePath, dispatchTreePath = param.dispatchTreePath, valueToPathMap = param.valueToPathMap, items = param.items;
357
+ var _currentItem_parent_items, _currentItem_parent;
358
+ var currentItem = getItemByFocused(focusedPath, focusedToValueMap);
359
+ var currentIndex = (focusedPath === null || focusedPath === void 0 ? void 0 : focusedPath[focusedPath.length - 1]) || 0;
360
+ var currentLength = (currentItem === null || currentItem === void 0 ? void 0 : (_currentItem_parent = currentItem.parent) === null || _currentItem_parent === void 0 ? void 0 : (_currentItem_parent_items = _currentItem_parent.items) === null || _currentItem_parent_items === void 0 ? void 0 : _currentItem_parent_items.length) || pathMap.get('root') || 0;
361
+ var isValidFocus = function(focusCandidate) {
362
+ if (!Array.isArray(items) || !Array.isArray(focusCandidate)) return false;
363
+ var currentLevel = items;
364
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
365
+ try {
366
+ for(var _iterator = focusCandidate[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
367
+ var index = _step.value;
368
+ if (!Array.isArray(currentLevel) || index >= currentLevel.length) {
369
+ return false;
370
+ }
371
+ var node = currentLevel[index];
372
+ currentLevel = node.items || [];
373
+ }
374
+ } catch (err) {
375
+ _didIteratorError = true;
376
+ _iteratorError = err;
377
+ } finally{
378
+ try {
379
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
380
+ _iterator.return();
381
+ }
382
+ } finally{
383
+ if (_didIteratorError) {
384
+ throw _iteratorError;
385
+ }
386
+ }
387
+ }
388
+ return true;
389
+ };
390
+ var onKeyDown = function(event) {
391
+ switch(event.code){
392
+ case keys.ArrowUp:
393
+ {
394
+ if (path[0]) {
395
+ event.stopPropagation();
396
+ event.preventDefault();
397
+ }
398
+ /**
399
+ * Если список открыт и фокус уже установлен на каком-либо элементе.
400
+ * */ if (focusedPath.length) {
401
+ /**
402
+ * Если это не первый элемент, то нужно вначале найти элемент для фокуса.
403
+ * Т.к. если верхний элемент раскрыт, то и перемещаться нужно не на него,
404
+ * а на его самый нижний дочерний элемент.
405
+ * */ if (currentIndex > 0) {
406
+ var nextFocus = _to_consumable_array(focusedPath.slice(0, -1)).concat([
407
+ currentIndex - 1
408
+ ]);
409
+ for(var i = 0; i <= focusedPath.length; i++){
410
+ var focusedPathAsString = nextFocus.reduce(function(acc, n) {
411
+ return "".concat(acc, "/").concat(n);
412
+ }, '').replace(/^(\/)/, '');
413
+ var item = focusedToValueMap.get(focusedPathAsString);
414
+ var isLevelOpened = keyExists(treePath, valueToPathMap.get(item === null || item === void 0 ? void 0 : item.value.toString()) || []);
415
+ if (isLevelOpened) {
416
+ var _item_items;
417
+ nextFocus = _to_consumable_array(nextFocus).concat([
418
+ ((item === null || item === void 0 ? void 0 : (_item_items = item.items) === null || _item_items === void 0 ? void 0 : _item_items.length) || 0) - 1
419
+ ]);
420
+ } else {
421
+ break;
422
+ }
423
+ }
424
+ dispatchFocusedPath({
425
+ type: 'set_focus',
426
+ value: nextFocus
427
+ });
428
+ } else {
429
+ /**
430
+ * Если элемент первый, то нужно лишь подняться к его родителю.
431
+ * */ dispatchFocusedPath({
432
+ type: 'return_prev_focus'
433
+ });
434
+ }
435
+ } else {
436
+ /**
437
+ * Если список закрыт, то нужно его открыть и установить фокус на первый элемент.
438
+ * */ dispatchPath({
439
+ type: 'opened_first_level'
440
+ });
441
+ dispatchFocusedPath({
442
+ type: 'set_initial_focus'
443
+ });
444
+ handleListToggle(true);
445
+ }
446
+ break;
447
+ }
448
+ case keys.ArrowDown:
449
+ {
450
+ if (path[0]) {
451
+ event.stopPropagation();
452
+ event.preventDefault();
453
+ }
454
+ /**
455
+ * Если список открыт и фокус уже установлен на каком-либо элементе.
456
+ * */ if (focusedPath.length) {
457
+ /**
458
+ * Заходим сюда если у элемента есть другие вложенные элементы.
459
+ * */ if ((currentItem === null || currentItem === void 0 ? void 0 : currentItem.items) && (currentItem === null || currentItem === void 0 ? void 0 : currentItem.items.length)) {
460
+ var isCurrentLevelOpened = keyExists(treePath, valueToPathMap.get(currentItem.value.toString()) || []);
461
+ /**
462
+ * Если у этого элемента открыт его дочерний список,
463
+ * то устанавливаем фокус на первый элемент из этого списка
464
+ * и сразу же выходим из обработчика события.
465
+ * */ if (isCurrentLevelOpened) {
466
+ dispatchFocusedPath({
467
+ type: 'add_focus',
468
+ value: 0
469
+ });
470
+ break;
471
+ }
472
+ }
473
+ /**
474
+ * Если мы еще не достигли конца списка, то движемся к следующему элементу.
475
+ * */ if (currentIndex + 1 < currentLength) {
476
+ dispatchFocusedPath({
477
+ type: 'change_last_focus',
478
+ value: currentIndex + 1
479
+ });
480
+ } else {
481
+ /**
482
+ * Если же достигли последнего элемента на текущем уровне, то нужно определить,
483
+ * на какой из элементов ниже мы перейдем.
484
+ * Переход фокуса отсюда может быть только на уровни выше, при чем сразу на несколько.
485
+ * */ var focusCandidate = _to_consumable_array(focusedPath);
486
+ var nextFocus1 = null;
487
+ while(focusCandidate.length > 1){
488
+ focusCandidate = _to_consumable_array(focusCandidate.slice(0, -2)).concat([
489
+ (focusCandidate.at(-2) || 0) + 1
490
+ ]);
491
+ if (isValidFocus(focusCandidate)) {
492
+ nextFocus1 = focusCandidate;
493
+ break;
494
+ }
495
+ }
496
+ if (nextFocus1) {
497
+ dispatchFocusedPath({
498
+ type: 'set_focus',
499
+ value: nextFocus1
500
+ });
501
+ } else {
502
+ break;
503
+ }
504
+ }
505
+ } else {
506
+ /**
507
+ * Если список закрыт, то нужно его открыть и установить фокус на первый элемент.
508
+ * */ dispatchPath({
509
+ type: 'opened_first_level'
510
+ });
511
+ dispatchFocusedPath({
512
+ type: 'set_initial_focus'
513
+ });
514
+ handleListToggle(true);
515
+ }
516
+ break;
517
+ }
518
+ case keys.ArrowLeft:
519
+ {
520
+ if (path[0]) {
521
+ event.stopPropagation();
522
+ event.preventDefault();
523
+ if (focusedPath.length) {
524
+ dispatchTreePath({
525
+ type: 'close_level',
526
+ value: valueToPathMap.get((currentItem === null || currentItem === void 0 ? void 0 : currentItem.value.toString()) || '') || []
527
+ });
528
+ }
529
+ }
530
+ break;
531
+ }
532
+ case keys.ArrowRight:
533
+ {
534
+ if (path[0]) {
535
+ event.stopPropagation();
536
+ event.preventDefault();
537
+ if (!focusedPath.length || (currentItem === null || currentItem === void 0 ? void 0 : currentItem.disabled) || !(currentItem === null || currentItem === void 0 ? void 0 : currentItem.items)) {
538
+ break;
539
+ }
540
+ dispatchTreePath({
541
+ type: 'open_level',
542
+ value: valueToPathMap.get(currentItem.value.toString()) || []
543
+ });
544
+ }
545
+ break;
546
+ }
547
+ case keys.Enter:
548
+ {
549
+ event.preventDefault();
550
+ if (!currentItem || (currentItem === null || currentItem === void 0 ? void 0 : currentItem.disabled)) {
551
+ break;
552
+ }
553
+ if (!path[0]) {
554
+ dispatchPath({
555
+ type: 'opened_first_level'
556
+ });
557
+ dispatchFocusedPath({
558
+ type: 'set_initial_focus'
559
+ });
560
+ break;
561
+ }
562
+ handlePressDown(currentItem);
563
+ break;
564
+ }
565
+ case keys.Tab:
566
+ case keys.Escape:
567
+ {
568
+ if (path[0]) {
569
+ handleListToggle(false);
570
+ }
571
+ if (multiple) {
572
+ setTextValue('');
573
+ } else if (textValue !== value) {
574
+ // Проверяем, отличается ли значение в инпуте от выбранного value после нажатия Tab/Enter.
575
+ // Если изменилось, то возвращаем label выбранного айтема.
576
+ // Если нет выбранного элемента, то стираем значение инпута.
577
+ if (isEmpty(value)) {
578
+ setTextValue('');
579
+ } else {
580
+ var _valueToItemMap_get;
581
+ setTextValue(((_valueToItemMap_get = valueToItemMap.get(value)) === null || _valueToItemMap_get === void 0 ? void 0 : _valueToItemMap_get.label) || '');
582
+ }
583
+ }
584
+ break;
585
+ }
586
+ default:
587
+ {
588
+ break;
589
+ }
590
+ }
591
+ };
592
+ return {
593
+ onKeyDown: onKeyDown
594
+ };
595
+ };
@@ -29,6 +29,10 @@ export function focusedPathReducer(state, action) {
29
29
  {
30
30
  return [];
31
31
  }
32
+ case 'set_focus':
33
+ {
34
+ return action.value;
35
+ }
32
36
  case 'set_initial_focus':
33
37
  {
34
38
  return [
@@ -49,6 +53,9 @@ export function focusedPathReducer(state, action) {
49
53
  }
50
54
  case 'return_prev_focus':
51
55
  {
56
+ if (state.length === 1) {
57
+ return state;
58
+ }
52
59
  return state.slice(0, -1);
53
60
  }
54
61
  default:
@@ -54,7 +54,7 @@ function removeObjectAtPath(obj, path) {
54
54
  }
55
55
  return obj;
56
56
  }
57
- // Утилита, которая получается на вход список отфильтрованных элементов
57
+ // Утилита, которая получает на вход список отфильтрованных элементов
58
58
  // и возвращает объект путей раскрытых элементов дерева.
59
59
  function generateNestedTreePathFromFilteredItems(items) {
60
60
  var result = {};
@@ -64,7 +64,7 @@ function generateNestedTreePathFromFilteredItems(items) {
64
64
  try {
65
65
  for(var _iterator = currentItems[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
66
66
  var item = _step.value;
67
- if (item === null || item === void 0 ? void 0 : item.value) {
67
+ if ((item === null || item === void 0 ? void 0 : item.value) && (item === null || item === void 0 ? void 0 : item.items)) {
68
68
  // Создаем новый уровень для текущего значения
69
69
  currentLevel[item === null || item === void 0 ? void 0 : item.value] = {};
70
70
  // Рекурсивно обрабатываем дочерние элементы
@@ -115,6 +115,18 @@ export function treePathReducer(state, action) {
115
115
  var filteredItem = action.value;
116
116
  return generateNestedTreePathFromFilteredItems(filteredItem);
117
117
  }
118
+ case 'open_level':
119
+ {
120
+ var stateCopy1 = deepCopy(state);
121
+ createObjectAtPath(stateCopy1, action.value);
122
+ return stateCopy1;
123
+ }
124
+ case 'close_level':
125
+ {
126
+ var stateCopy2 = deepCopy(state);
127
+ removeObjectAtPath(stateCopy2, action.value);
128
+ return stateCopy2;
129
+ }
118
130
  default:
119
131
  {
120
132
  return state;
@@ -20,8 +20,10 @@ export var TreeList = function(param) {
20
20
  }, beforeList, items === null || items === void 0 ? void 0 : items.map(function(item, index) {
21
21
  return /*#__PURE__*/ React.createElement(Item, {
22
22
  key: index,
23
- index: index,
24
- item: item
23
+ item: item,
24
+ pathToItem: [
25
+ index
26
+ ]
25
27
  });
26
28
  }), afterList));
27
29
  };
@@ -69,7 +71,9 @@ var VirtualTreeList = function(param) {
69
71
  ref: virtualizer.measureElement
70
72
  }, /*#__PURE__*/ React.createElement(Item, {
71
73
  item: items[virtualRow.index],
72
- index: virtualRow.index
74
+ pathToItem: [
75
+ virtualRow.index
76
+ ]
73
77
  }));
74
78
  })))), afterList);
75
79
  };
@@ -1,23 +1,53 @@
1
- import React, { useContext } from "react";
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _array_without_holes(arr) {
7
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
8
+ }
9
+ function _iterable_to_array(iter) {
10
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
11
+ }
12
+ function _non_iterable_spread() {
13
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
14
+ }
15
+ function _to_consumable_array(arr) {
16
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
17
+ }
18
+ function _unsupported_iterable_to_array(o, minLen) {
19
+ if (!o) return;
20
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
21
+ var n = Object.prototype.toString.call(o).slice(8, -1);
22
+ if (n === "Object" && o.constructor) n = o.constructor.name;
23
+ if (n === "Map" || n === "Set") return Array.from(n);
24
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
25
+ }
26
+ import React, { useContext, useRef } from "react";
2
27
  import { classes } from "../../../../../../Select/Select.tokens";
3
28
  import { sizeToIconSize } from "../../../../../../Select/utils";
29
+ import { useDidMountEffect } from "../../../../../../../hooks";
30
+ import { isArraysEqual, cx } from "../../../../../../../utils";
4
31
  import { keyExists } from "../../../../reducers/treePathReducer";
5
32
  import { Context } from "../../../../Combobox.context";
6
33
  import { ItemWrapper, ChildItems, Offset, IconWrapper, StyledCheckboxWrapper, StyledCheckbox, StyledIndicator, StyledIconDone, StyledText, StyledWrapper, StyledCell, DisclosureIconWrapper, StyledArrowRight, Wrapper, StyledArrowLeft } from "./Item.styles";
7
34
  export var Item = function(param) {
8
- var item = param.item, index = param.index;
35
+ var item = param.item, pathToItem = param.pathToItem;
9
36
  var _valueToPathMap_get, _item_items;
10
37
  var label = item.label, value = item.value, disabled = item.disabled, contentLeft = item.contentLeft, contentRight = item.contentRight;
11
38
  var isLeaf = !(item === null || item === void 0 ? void 0 : item.items);
12
39
  var _useContext = useContext(Context), checked = _useContext.checked, multiple = _useContext.multiple, size = _useContext.size, variant = _useContext.variant, renderItem = _useContext.renderItem, // eslint-disable-next-line @typescript-eslint/ban-ts-comment
13
40
  // @ts-ignore
14
41
  _checkboxAppearance = _useContext._checkboxAppearance, focusedPath = _useContext.focusedPath, treePath = _useContext.treePath, dispatchTreePath = _useContext.dispatchTreePath, arrowPlacement = _useContext.arrowPlacement, handleItemClick = _useContext.handleItemClick, handleCheckboxChange = _useContext.handleCheckboxChange, valueToPathMap = _useContext.valueToPathMap;
42
+ var ref = useRef(null);
15
43
  var itemDisabled = disabled;
44
+ var disabledClassName = itemDisabled ? classes.dropdownItemIsDisabled : undefined;
16
45
  var currentItemDepth = (((_valueToPathMap_get = valueToPathMap.get(item.value.toString())) === null || _valueToPathMap_get === void 0 ? void 0 : _valueToPathMap_get.length) || 0) - 1;
17
46
  var isCurrentLevelOpened = keyExists(treePath, valueToPathMap.get(value.toString()) || []);
18
47
  var withArrowInverse = isCurrentLevelOpened ? classes.arrowInverse : undefined;
19
- var focusedClass = currentItemDepth === focusedPath.length - 1 && index === (focusedPath === null || focusedPath === void 0 ? void 0 : focusedPath[currentItemDepth]) ? classes.dropdownItemIsFocused : undefined;
48
+ var focusedClass = isArraysEqual(pathToItem, focusedPath) ? classes.dropdownItemIsFocused : undefined;
20
49
  var handleClick = function(e) {
50
+ if (itemDisabled) return;
21
51
  if (!isLeaf) {
22
52
  dispatchTreePath({
23
53
  type: 'toggled_level',
@@ -33,8 +63,20 @@ export var Item = function(param) {
33
63
  e.stopPropagation();
34
64
  handleCheckboxChange(item);
35
65
  };
66
+ useDidMountEffect(function() {
67
+ if (focusedClass && (ref === null || ref === void 0 ? void 0 : ref.current)) {
68
+ ref.current.scrollIntoView({
69
+ behavior: 'smooth',
70
+ block: 'center',
71
+ inline: 'center'
72
+ });
73
+ }
74
+ }, [
75
+ focusedClass
76
+ ]);
36
77
  return /*#__PURE__*/ React.createElement(ItemWrapper, null, /*#__PURE__*/ React.createElement(Wrapper, {
37
- className: focusedClass,
78
+ ref: ref,
79
+ className: cx(focusedClass, disabledClassName),
38
80
  onClick: handleClick,
39
81
  variant: variant,
40
82
  role: "treeitem"
@@ -90,8 +132,10 @@ export var Item = function(param) {
90
132
  }))), !isLeaf && isCurrentLevelOpened && /*#__PURE__*/ React.createElement(ChildItems, null, (_item_items = item.items) === null || _item_items === void 0 ? void 0 : _item_items.map(function(item, index) {
91
133
  return /*#__PURE__*/ React.createElement(Item, {
92
134
  item: item,
93
- index: index,
94
- key: index
135
+ key: item.value,
136
+ pathToItem: _to_consumable_array(pathToItem).concat([
137
+ index
138
+ ])
95
139
  });
96
140
  })));
97
141
  };
@@ -414,7 +414,8 @@ import { Context } from "./Select.context";
414
414
  treePath: treePath,
415
415
  dispatchTreePath: dispatchTreePath,
416
416
  treeView: treeView,
417
- valueToPathMap: valueToPathMap
417
+ valueToPathMap: valueToPathMap,
418
+ items: transformedItems
418
419
  }).onKeyDown;
419
420
  // В данном эффекте мы следим за изменениями value снаружи и вносим коррективы в дерево чекбоксов.
420
421
  // Пример: когда юзер очистил value извне, тогда нужно пройтись по элементам и выключить все чекбоксы.