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