@vscode-elements/elements 2.0.0-pre.1 → 2.0.0-pre.2

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 (247) hide show
  1. package/README.md +5 -1
  2. package/custom-elements.json +4505 -2986
  3. package/dist/bundled.js +1157 -934
  4. package/dist/includes/VscElement.d.ts +9 -1
  5. package/dist/includes/VscElement.d.ts.map +1 -1
  6. package/dist/includes/VscElement.js +38 -5
  7. package/dist/includes/VscElement.js.map +1 -1
  8. package/dist/includes/form-button-widget/LabelledCheckboxOrRadio.d.ts.map +1 -1
  9. package/dist/includes/form-button-widget/base.styles.js +8 -8
  10. package/dist/includes/form-button-widget/base.styles.js.map +1 -1
  11. package/dist/includes/uniqueId.d.ts.map +1 -1
  12. package/dist/includes/vscode-select/OptionListController.d.ts +61 -0
  13. package/dist/includes/vscode-select/OptionListController.d.ts.map +1 -0
  14. package/dist/includes/vscode-select/OptionListController.js +373 -0
  15. package/dist/includes/vscode-select/OptionListController.js.map +1 -0
  16. package/dist/includes/vscode-select/helpers.d.ts +4 -2
  17. package/dist/includes/vscode-select/helpers.d.ts.map +1 -1
  18. package/dist/includes/vscode-select/helpers.js +26 -0
  19. package/dist/includes/vscode-select/helpers.js.map +1 -1
  20. package/dist/includes/vscode-select/styles.d.ts.map +1 -1
  21. package/dist/includes/vscode-select/styles.js +137 -86
  22. package/dist/includes/vscode-select/styles.js.map +1 -1
  23. package/dist/includes/vscode-select/template-elements.d.ts +1 -0
  24. package/dist/includes/vscode-select/template-elements.d.ts.map +1 -1
  25. package/dist/includes/vscode-select/template-elements.js +14 -1
  26. package/dist/includes/vscode-select/template-elements.js.map +1 -1
  27. package/dist/includes/vscode-select/types.d.ts +11 -7
  28. package/dist/includes/vscode-select/types.d.ts.map +1 -1
  29. package/dist/includes/vscode-select/types.js.map +1 -1
  30. package/dist/includes/vscode-select/vscode-select-base.d.ts +42 -31
  31. package/dist/includes/vscode-select/vscode-select-base.d.ts.map +1 -1
  32. package/dist/includes/vscode-select/vscode-select-base.js +379 -245
  33. package/dist/includes/vscode-select/vscode-select-base.js.map +1 -1
  34. package/dist/main.d.ts +4 -0
  35. package/dist/main.d.ts.map +1 -1
  36. package/dist/main.js +4 -0
  37. package/dist/main.js.map +1 -1
  38. package/dist/vscode-badge/vscode-badge.d.ts.map +1 -1
  39. package/dist/vscode-badge/vscode-badge.js +2 -2
  40. package/dist/vscode-badge/vscode-badge.js.map +1 -1
  41. package/dist/vscode-button/vscode-button.d.ts +1 -0
  42. package/dist/vscode-button/vscode-button.d.ts.map +1 -1
  43. package/dist/vscode-button/vscode-button.js +8 -2
  44. package/dist/vscode-button/vscode-button.js.map +1 -1
  45. package/dist/vscode-button/vscode-button.styles.d.ts.map +1 -1
  46. package/dist/vscode-button/vscode-button.styles.js +60 -11
  47. package/dist/vscode-button/vscode-button.styles.js.map +1 -1
  48. package/dist/vscode-button-group/index.d.ts +2 -0
  49. package/dist/vscode-button-group/index.d.ts.map +1 -0
  50. package/dist/vscode-button-group/index.js +2 -0
  51. package/dist/vscode-button-group/index.js.map +1 -0
  52. package/dist/vscode-button-group/vscode-button-group.d.ts +29 -0
  53. package/dist/vscode-button-group/vscode-button-group.d.ts.map +1 -0
  54. package/dist/vscode-button-group/vscode-button-group.js +38 -0
  55. package/dist/vscode-button-group/vscode-button-group.js.map +1 -0
  56. package/dist/vscode-button-group/vscode-button-group.styles.d.ts +4 -0
  57. package/dist/vscode-button-group/vscode-button-group.styles.d.ts.map +1 -0
  58. package/dist/vscode-button-group/vscode-button-group.styles.js +35 -0
  59. package/dist/vscode-button-group/vscode-button-group.styles.js.map +1 -0
  60. package/dist/vscode-checkbox/vscode-checkbox.d.ts +10 -10
  61. package/dist/vscode-checkbox/vscode-checkbox.d.ts.map +1 -1
  62. package/dist/vscode-checkbox/vscode-checkbox.js +12 -14
  63. package/dist/vscode-checkbox/vscode-checkbox.js.map +1 -1
  64. package/dist/vscode-checkbox/vscode-checkbox.styles.js +2 -2
  65. package/dist/vscode-checkbox/vscode-checkbox.styles.js.map +1 -1
  66. package/dist/vscode-checkbox-group/vscode-checkbox-group.d.ts.map +1 -1
  67. package/dist/vscode-checkbox-group/vscode-checkbox-group.js +2 -2
  68. package/dist/vscode-checkbox-group/vscode-checkbox-group.js.map +1 -1
  69. package/dist/vscode-collapsible/vscode-collapsible.d.ts +6 -6
  70. package/dist/vscode-collapsible/vscode-collapsible.d.ts.map +1 -1
  71. package/dist/vscode-collapsible/vscode-collapsible.js +8 -8
  72. package/dist/vscode-collapsible/vscode-collapsible.js.map +1 -1
  73. package/dist/vscode-collapsible/vscode-collapsible.styles.js +6 -6
  74. package/dist/vscode-collapsible/vscode-collapsible.styles.js.map +1 -1
  75. package/dist/vscode-context-menu/vscode-context-menu.d.ts +8 -8
  76. package/dist/vscode-context-menu/vscode-context-menu.d.ts.map +1 -1
  77. package/dist/vscode-context-menu/vscode-context-menu.js +9 -9
  78. package/dist/vscode-context-menu/vscode-context-menu.js.map +1 -1
  79. package/dist/vscode-context-menu/vscode-context-menu.styles.js +7 -7
  80. package/dist/vscode-context-menu/vscode-context-menu.styles.js.map +1 -1
  81. package/dist/vscode-context-menu-item/vscode-context-menu-item.d.ts +9 -9
  82. package/dist/vscode-context-menu-item/vscode-context-menu-item.d.ts.map +1 -1
  83. package/dist/vscode-context-menu-item/vscode-context-menu-item.js +11 -11
  84. package/dist/vscode-context-menu-item/vscode-context-menu-item.js.map +1 -1
  85. package/dist/vscode-context-menu-item/vscode-context-menu-item.styles.d.ts.map +1 -1
  86. package/dist/vscode-context-menu-item/vscode-context-menu-item.styles.js +10 -13
  87. package/dist/vscode-context-menu-item/vscode-context-menu-item.styles.js.map +1 -1
  88. package/dist/vscode-divider/vscode-divider.d.ts +2 -0
  89. package/dist/vscode-divider/vscode-divider.d.ts.map +1 -1
  90. package/dist/vscode-divider/vscode-divider.js +4 -2
  91. package/dist/vscode-divider/vscode-divider.js.map +1 -1
  92. package/dist/vscode-divider/vscode-divider.styles.js +1 -1
  93. package/dist/vscode-divider/vscode-divider.styles.js.map +1 -1
  94. package/dist/vscode-form-container/vscode-form-container.d.ts.map +1 -1
  95. package/dist/vscode-form-container/vscode-form-container.js +2 -2
  96. package/dist/vscode-form-container/vscode-form-container.js.map +1 -1
  97. package/dist/vscode-form-group/vscode-form-group.d.ts.map +1 -1
  98. package/dist/vscode-form-group/vscode-form-group.js +2 -2
  99. package/dist/vscode-form-group/vscode-form-group.js.map +1 -1
  100. package/dist/vscode-form-helper/vscode-form-helper.d.ts.map +1 -1
  101. package/dist/vscode-form-helper/vscode-form-helper.js +1 -2
  102. package/dist/vscode-form-helper/vscode-form-helper.js.map +1 -1
  103. package/dist/vscode-icon/vscode-icon.d.ts +4 -4
  104. package/dist/vscode-icon/vscode-icon.d.ts.map +1 -1
  105. package/dist/vscode-icon/vscode-icon.js +7 -6
  106. package/dist/vscode-icon/vscode-icon.js.map +1 -1
  107. package/dist/vscode-icon/vscode-icon.styles.d.ts.map +1 -1
  108. package/dist/vscode-icon/vscode-icon.styles.js +10 -4
  109. package/dist/vscode-icon/vscode-icon.styles.js.map +1 -1
  110. package/dist/vscode-label/vscode-label.d.ts +3 -3
  111. package/dist/vscode-label/vscode-label.d.ts.map +1 -1
  112. package/dist/vscode-label/vscode-label.js +14 -12
  113. package/dist/vscode-label/vscode-label.js.map +1 -1
  114. package/dist/vscode-label/vscode-label.styles.js +4 -4
  115. package/dist/vscode-label/vscode-label.styles.js.map +1 -1
  116. package/dist/vscode-multi-select/vscode-multi-select.d.ts +39 -26
  117. package/dist/vscode-multi-select/vscode-multi-select.d.ts.map +1 -1
  118. package/dist/vscode-multi-select/vscode-multi-select.js +184 -161
  119. package/dist/vscode-multi-select/vscode-multi-select.js.map +1 -1
  120. package/dist/vscode-option/vscode-option.d.ts.map +1 -1
  121. package/dist/vscode-option/vscode-option.js +2 -2
  122. package/dist/vscode-option/vscode-option.js.map +1 -1
  123. package/dist/vscode-progress-ring/vscode-progress-ring.d.ts +2 -0
  124. package/dist/vscode-progress-ring/vscode-progress-ring.d.ts.map +1 -1
  125. package/dist/vscode-progress-ring/vscode-progress-ring.js +4 -2
  126. package/dist/vscode-progress-ring/vscode-progress-ring.js.map +1 -1
  127. package/dist/vscode-progress-ring/vscode-progress-ring.styles.js +1 -1
  128. package/dist/vscode-progress-ring/vscode-progress-ring.styles.js.map +1 -1
  129. package/dist/vscode-radio/vscode-radio.d.ts +9 -8
  130. package/dist/vscode-radio/vscode-radio.d.ts.map +1 -1
  131. package/dist/vscode-radio/vscode-radio.js +11 -9
  132. package/dist/vscode-radio/vscode-radio.js.map +1 -1
  133. package/dist/vscode-radio/vscode-radio.styles.js +2 -2
  134. package/dist/vscode-radio/vscode-radio.styles.js.map +1 -1
  135. package/dist/vscode-radio-group/vscode-radio-group.d.ts.map +1 -1
  136. package/dist/vscode-radio-group/vscode-radio-group.js +2 -2
  137. package/dist/vscode-radio-group/vscode-radio-group.js.map +1 -1
  138. package/dist/vscode-scrollable/vscode-scrollable.d.ts +61 -17
  139. package/dist/vscode-scrollable/vscode-scrollable.d.ts.map +1 -1
  140. package/dist/vscode-scrollable/vscode-scrollable.js +193 -88
  141. package/dist/vscode-scrollable/vscode-scrollable.js.map +1 -1
  142. package/dist/vscode-scrollable/vscode-scrollable.styles.d.ts.map +1 -1
  143. package/dist/vscode-scrollable/vscode-scrollable.styles.js +17 -5
  144. package/dist/vscode-scrollable/vscode-scrollable.styles.js.map +1 -1
  145. package/dist/vscode-single-select/vscode-single-select.d.ts +39 -28
  146. package/dist/vscode-single-select/vscode-single-select.d.ts.map +1 -1
  147. package/dist/vscode-single-select/vscode-single-select.js +180 -125
  148. package/dist/vscode-single-select/vscode-single-select.js.map +1 -1
  149. package/dist/vscode-split-layout/vscode-split-layout.d.ts +3 -1
  150. package/dist/vscode-split-layout/vscode-split-layout.d.ts.map +1 -1
  151. package/dist/vscode-split-layout/vscode-split-layout.js +8 -3
  152. package/dist/vscode-split-layout/vscode-split-layout.js.map +1 -1
  153. package/dist/vscode-split-layout/vscode-split-layout.styles.js +3 -3
  154. package/dist/vscode-split-layout/vscode-split-layout.styles.js.map +1 -1
  155. package/dist/vscode-tab-header/vscode-tab-header.d.ts.map +1 -1
  156. package/dist/vscode-tab-header/vscode-tab-header.js +2 -2
  157. package/dist/vscode-tab-header/vscode-tab-header.js.map +1 -1
  158. package/dist/vscode-tab-panel/vscode-tab-panel.d.ts.map +1 -1
  159. package/dist/vscode-tab-panel/vscode-tab-panel.js +2 -2
  160. package/dist/vscode-tab-panel/vscode-tab-panel.js.map +1 -1
  161. package/dist/vscode-table/helpers.d.ts.map +1 -1
  162. package/dist/vscode-table/vscode-table.d.ts +1 -0
  163. package/dist/vscode-table/vscode-table.d.ts.map +1 -1
  164. package/dist/vscode-table/vscode-table.js +20 -16
  165. package/dist/vscode-table/vscode-table.js.map +1 -1
  166. package/dist/vscode-table-body/vscode-table-body.d.ts.map +1 -1
  167. package/dist/vscode-table-body/vscode-table-body.js +2 -2
  168. package/dist/vscode-table-body/vscode-table-body.js.map +1 -1
  169. package/dist/vscode-table-cell/vscode-table-cell.d.ts.map +1 -1
  170. package/dist/vscode-table-cell/vscode-table-cell.js +2 -2
  171. package/dist/vscode-table-cell/vscode-table-cell.js.map +1 -1
  172. package/dist/vscode-table-header/vscode-table-header.d.ts.map +1 -1
  173. package/dist/vscode-table-header/vscode-table-header.js +2 -2
  174. package/dist/vscode-table-header/vscode-table-header.js.map +1 -1
  175. package/dist/vscode-table-header-cell/vscode-table-header-cell.d.ts.map +1 -1
  176. package/dist/vscode-table-header-cell/vscode-table-header-cell.js +2 -2
  177. package/dist/vscode-table-header-cell/vscode-table-header-cell.js.map +1 -1
  178. package/dist/vscode-table-row/vscode-table-row.d.ts.map +1 -1
  179. package/dist/vscode-table-row/vscode-table-row.js +2 -2
  180. package/dist/vscode-table-row/vscode-table-row.js.map +1 -1
  181. package/dist/vscode-tabs/vscode-tabs.d.ts.map +1 -1
  182. package/dist/vscode-tabs/vscode-tabs.js +2 -2
  183. package/dist/vscode-tabs/vscode-tabs.js.map +1 -1
  184. package/dist/vscode-textarea/vscode-textarea.d.ts +18 -18
  185. package/dist/vscode-textarea/vscode-textarea.d.ts.map +1 -1
  186. package/dist/vscode-textarea/vscode-textarea.js +20 -20
  187. package/dist/vscode-textarea/vscode-textarea.js.map +1 -1
  188. package/dist/vscode-textarea/vscode-textarea.styles.d.ts.map +1 -1
  189. package/dist/vscode-textarea/vscode-textarea.styles.js +31 -22
  190. package/dist/vscode-textarea/vscode-textarea.styles.js.map +1 -1
  191. package/dist/vscode-textfield/vscode-textfield.d.ts.map +1 -1
  192. package/dist/vscode-textfield/vscode-textfield.js +2 -2
  193. package/dist/vscode-textfield/vscode-textfield.js.map +1 -1
  194. package/dist/vscode-toolbar-button/index.d.ts +2 -0
  195. package/dist/vscode-toolbar-button/index.d.ts.map +1 -0
  196. package/dist/vscode-toolbar-button/index.js +2 -0
  197. package/dist/vscode-toolbar-button/index.js.map +1 -0
  198. package/dist/vscode-toolbar-button/vscode-toolbar-button.d.ts +26 -0
  199. package/dist/vscode-toolbar-button/vscode-toolbar-button.d.ts.map +1 -0
  200. package/dist/vscode-toolbar-button/vscode-toolbar-button.js +83 -0
  201. package/dist/vscode-toolbar-button/vscode-toolbar-button.js.map +1 -0
  202. package/dist/vscode-toolbar-button/vscode-toolbar-button.styles.d.ts +4 -0
  203. package/dist/vscode-toolbar-button/vscode-toolbar-button.styles.d.ts.map +1 -0
  204. package/dist/vscode-toolbar-button/vscode-toolbar-button.styles.js +77 -0
  205. package/dist/vscode-toolbar-button/vscode-toolbar-button.styles.js.map +1 -0
  206. package/dist/vscode-toolbar-container/index.d.ts +2 -0
  207. package/dist/vscode-toolbar-container/index.d.ts.map +1 -0
  208. package/dist/vscode-toolbar-container/index.js +2 -0
  209. package/dist/vscode-toolbar-container/index.js.map +1 -0
  210. package/dist/vscode-toolbar-container/vscode-toolbar-container.d.ts +17 -0
  211. package/dist/vscode-toolbar-container/vscode-toolbar-container.d.ts.map +1 -0
  212. package/dist/vscode-toolbar-container/vscode-toolbar-container.js +25 -0
  213. package/dist/vscode-toolbar-container/vscode-toolbar-container.js.map +1 -0
  214. package/dist/vscode-toolbar-container/vscode-toolbar-container.styles.d.ts +4 -0
  215. package/dist/vscode-toolbar-container/vscode-toolbar-container.styles.d.ts.map +1 -0
  216. package/dist/vscode-toolbar-container/vscode-toolbar-container.styles.js +14 -0
  217. package/dist/vscode-toolbar-container/vscode-toolbar-container.styles.js.map +1 -0
  218. package/dist/vscode-tree/helpers.d.ts +11 -0
  219. package/dist/vscode-tree/helpers.d.ts.map +1 -0
  220. package/dist/vscode-tree/helpers.js +139 -0
  221. package/dist/vscode-tree/helpers.js.map +1 -0
  222. package/dist/vscode-tree/tree-context.d.ts +33 -0
  223. package/dist/vscode-tree/tree-context.d.ts.map +1 -0
  224. package/dist/vscode-tree/tree-context.js +4 -0
  225. package/dist/vscode-tree/tree-context.js.map +1 -0
  226. package/dist/vscode-tree/vscode-tree.d.ts +35 -150
  227. package/dist/vscode-tree/vscode-tree.d.ts.map +1 -1
  228. package/dist/vscode-tree/vscode-tree.js +263 -627
  229. package/dist/vscode-tree/vscode-tree.js.map +1 -1
  230. package/dist/vscode-tree/vscode-tree.styles.d.ts.map +1 -1
  231. package/dist/vscode-tree/vscode-tree.styles.js +4 -240
  232. package/dist/vscode-tree/vscode-tree.styles.js.map +1 -1
  233. package/dist/vscode-tree-item/index.d.ts +2 -0
  234. package/dist/vscode-tree-item/index.d.ts.map +1 -0
  235. package/dist/vscode-tree-item/index.js +2 -0
  236. package/dist/vscode-tree-item/index.js.map +1 -0
  237. package/dist/vscode-tree-item/vscode-tree-item.d.ts +45 -0
  238. package/dist/vscode-tree-item/vscode-tree-item.d.ts.map +1 -0
  239. package/dist/vscode-tree-item/vscode-tree-item.js +377 -0
  240. package/dist/vscode-tree-item/vscode-tree-item.js.map +1 -0
  241. package/dist/vscode-tree-item/vscode-tree-item.styles.d.ts +4 -0
  242. package/dist/vscode-tree-item/vscode-tree-item.styles.d.ts.map +1 -0
  243. package/dist/vscode-tree-item/vscode-tree-item.styles.js +165 -0
  244. package/dist/vscode-tree-item/vscode-tree-item.styles.js.map +1 -0
  245. package/package.json +38 -38
  246. package/vscode.css-custom-data.json +47 -58
  247. package/vscode.html-custom-data.json +166 -81
@@ -4,713 +4,349 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { html, nothing } from 'lit';
8
- import { customElement, property, state } from 'lit/decorators.js';
9
- import { classMap } from 'lit/directives/class-map.js';
10
- import { ifDefined } from 'lit/directives/if-defined.js';
11
- import { VscElement } from '../includes/VscElement.js';
12
- import { stylePropertyMap } from '../includes/style-property-map.js';
13
- import '../vscode-badge/index.js';
14
- import '../vscode-icon/index.js';
15
- import styles from './vscode-tree.styles.js';
16
- const ARROW_OUTER_WIDTH = 30;
17
- const ARROW_ICON_WIDTH = 16;
18
- const CONTENT_PADDING = 3;
19
- const addPath = (tree, prevPath = []) => {
20
- const nextTree = [];
21
- tree.forEach((item, index) => {
22
- const path = [...prevPath, index];
23
- const nextItem = {
24
- ...item,
25
- path,
26
- };
27
- if (item.subItems) {
28
- nextItem.subItems = addPath(item.subItems, path);
29
- }
30
- nextTree.push(nextItem);
31
- });
32
- return nextTree;
7
+ import { html } from 'lit';
8
+ import { provide } from '@lit/context';
9
+ import { customElement, property, queryAssignedElements, } from 'lit/decorators.js';
10
+ import { VscElement } from '../includes/VscElement';
11
+ import styles from './vscode-tree.styles';
12
+ import { configContext, treeContext, } from './tree-context';
13
+ import { findNextItem, findPrevItem, getParentItem, initPathTrackerProps, } from './helpers.js';
14
+ export const EXPAND_MODE = {
15
+ SINGLE_CLICK: 'singleClick',
16
+ DOUBLE_CLICK: 'doubleClick',
33
17
  };
34
- const isBranch = (item) => {
35
- if (item.subItems &&
36
- Array.isArray(item.subItems) &&
37
- item?.subItems?.length > 0) {
38
- return true;
39
- }
40
- return false;
41
- };
42
- /**
43
- * @tag vscode-tree
44
- *
45
- * @fires vsc-select Dispatched when an item is selected.
46
- * @fires {VscTreeSelectEvent} vsc-tree-select Dispatched when an item is selected.
47
- * @fires vsc-run-action Dispatched when an action icon is clicked.
48
- * @fires {VscTreeActionEvent} vsc-tree-action Dispatched when an action icon is clicked.
49
- *
50
- * @cssprop --vscode-focusBorder
51
- * @cssprop --vscode-font-family
52
- * @cssprop --vscode-font-size
53
- * @cssprop --vscode-font-weight
54
- * @cssprop --vscode-list-hoverForeground
55
- * @cssprop --vscode-list-hoverBackground
56
- * @cssprop --vscode-list-inactiveSelectionBackground
57
- * @cssprop --vscode-list-inactiveSelectionForeground
58
- * @cssprop --vscode-list-activeSelectionBackground
59
- * @cssprop --vscode-list-activeSelectionForeground
60
- * @cssprop --vscode-list-inactiveSelectionIconForeground
61
- * @cssprop --vscode-list-inactiveFocusBackground
62
- * @cssprop --vscode-list-inactiveFocusOutline
63
- * @cssprop --vscode-list-focusOutline
64
- * @cssprop --vscode-tree-inactiveIndentGuidesStroke
65
- * @cssprop --vscode-tree-indentGuidesStroke
66
- *
67
- * @csspart text-content
68
- * @csspart description
69
- * @csspart counter-badge-decoration
70
- * @csspart filled-circle-decoration
71
- * @csspart caption-decoration
72
- * @csspart decorations Container of decorations
73
- */
18
+ const listenedKeys = [
19
+ ' ',
20
+ 'ArrowDown',
21
+ 'ArrowUp',
22
+ 'ArrowLeft',
23
+ 'ArrowRight',
24
+ 'Enter',
25
+ 'Escape',
26
+ 'Shift',
27
+ ];
28
+ const DEFAULT_ARROWS = false;
29
+ const DEFAULT_INDENT = 8;
30
+ const DEFAULT_INDENT_GUIDES = false;
31
+ const DEFAULT_MULTI_SELECT = false;
32
+ const DEFAULT_EXPAND_MODE = EXPAND_MODE.SINGLE_CLICK;
74
33
  let VscodeTree = class VscodeTree extends VscElement {
34
+ //#region lifecycle methods
75
35
  constructor() {
76
- super(...arguments);
77
- this.indent = 8;
78
- this.arrows = false;
79
- this.multiline = false;
80
- this.tabindex = 0;
81
- this.indentGuides = false;
82
- this._data = [];
83
- this._selectedItem = null;
84
- this._focusedItem = null;
85
- this._selectedBranch = null;
86
- this._focusedBranch = null;
87
- this._handleComponentKeyDownBound = this._handleComponentKeyDown.bind(this);
88
- }
89
- set data(val) {
90
- const oldVal = this._data;
91
- this._data = addPath(val);
92
- this.requestUpdate('data', oldVal);
93
- }
94
- get data() {
95
- return this._data;
96
- }
97
- /**
98
- * Closes all opened tree items recursively.
99
- */
100
- closeAll() {
101
- this._closeSubTreeRecursively(this.data);
102
- this.requestUpdate();
103
- }
104
- /**
105
- * Deselects all selected items.
106
- */
107
- deselectAll() {
108
- this._deselectItemsRecursively(this.data);
109
- this.requestUpdate();
110
- }
111
- /**
112
- * Returns a reference to a TreeItem object by path.
113
- * @param path
114
- * @returns
115
- */
116
- getItemByPath(path) {
117
- return this._getItemByPath(path);
118
- }
119
- connectedCallback() {
120
- super.connectedCallback();
121
- this.addEventListener('keydown', this._handleComponentKeyDownBound);
122
- }
123
- disconnectedCallback() {
124
- super.disconnectedCallback();
125
- this.removeEventListener('keydown', this._handleComponentKeyDownBound);
126
- }
127
- _getItemByPath(path) {
128
- let current = this._data;
129
- let item = null;
130
- path.forEach((el, i) => {
131
- if (i === path.length - 1) {
132
- item = current[el];
133
- }
134
- else {
135
- current = current[el].subItems;
136
- }
137
- });
138
- return item;
139
- }
140
- _handleActionClick(ev) {
141
- ev.stopPropagation();
142
- const el = ev.target;
143
- const itemPath = el.dataset.itemPath;
144
- const actionIndex = el.dataset.index;
145
- let item = null;
146
- let actionId = '';
147
- let value = '';
148
- if (itemPath) {
149
- const path = itemPath.split('/').map((p) => Number(p));
150
- item = this._getItemByPath(path);
151
- if (item?.actions) {
152
- const index = Number(actionIndex);
153
- if (item.actions[index]) {
154
- actionId = item.actions[index].actionId;
155
- }
156
- }
157
- if (item?.value) {
158
- value = item.value;
159
- }
160
- }
161
- /** @deprecated Renamed to `vsc-tree-action` */
162
- this.dispatchEvent(new CustomEvent('vsc-run-action', {
163
- detail: {
164
- actionId,
165
- item,
166
- value,
36
+ super();
37
+ //#region properties
38
+ this.arrows = DEFAULT_ARROWS;
39
+ this.expandMode = DEFAULT_EXPAND_MODE;
40
+ this.indent = DEFAULT_INDENT;
41
+ this.indentGuides = DEFAULT_INDENT_GUIDES;
42
+ this.multiSelect = DEFAULT_MULTI_SELECT;
43
+ //#endregion
44
+ //#region private variables
45
+ this._treeContextState = {
46
+ isShiftPressed: false,
47
+ activeItem: null,
48
+ selectedItems: new Set(),
49
+ allItems: null,
50
+ itemListUpToDate: false,
51
+ focusedItem: null,
52
+ prevFocusedItem: null,
53
+ hasBranchItem: false,
54
+ rootElement: this,
55
+ highlightedItems: [],
56
+ highlightGuides: () => {
57
+ this._highlightGuides();
167
58
  },
168
- }));
169
- /**
170
- * Dispatched when an action icon is clicked.
171
- */
172
- this.dispatchEvent(new CustomEvent('vsc-tree-action', {
173
- detail: {
174
- actionId,
175
- item,
176
- value,
177
- },
178
- }));
179
- }
180
- _renderIconVariant(variant) {
181
- const { type, value } = variant;
182
- if (type === 'themeicon') {
183
- return html `<vscode-icon name=${value} class="theme-icon"></vscode-icon>`;
184
- }
185
- else {
186
- return html `<span
187
- class="image-icon"
188
- .style=${stylePropertyMap({ backgroundImage: `url(${value})` })}
189
- ></span>`;
190
- }
191
- }
192
- _renderIcon(item) {
193
- const iconVariants = {
194
- branch: {
195
- value: 'folder',
196
- type: 'themeicon',
197
- },
198
- open: {
199
- value: 'folder-opened',
200
- type: 'themeicon',
201
- },
202
- leaf: {
203
- value: 'file',
204
- type: 'themeicon',
59
+ emitSelectEvent: () => {
60
+ this._emitSelectEvent();
205
61
  },
206
62
  };
207
- if (item.iconUrls) {
208
- if (item.iconUrls.branch) {
209
- iconVariants.branch = {
210
- value: item.iconUrls.branch,
211
- type: 'image',
212
- };
213
- }
214
- if (item.iconUrls.leaf) {
215
- iconVariants.leaf = {
216
- value: item.iconUrls.leaf,
217
- type: 'image',
218
- };
219
- }
220
- if (item.iconUrls.open) {
221
- iconVariants.open = {
222
- value: item.iconUrls.open,
223
- type: 'image',
224
- };
225
- }
226
- }
227
- else if (typeof item.icons === 'object') {
228
- if (item.icons.branch) {
229
- iconVariants.branch = {
230
- value: item.icons.branch,
231
- type: 'themeicon',
232
- };
233
- }
234
- if (item.icons.leaf) {
235
- iconVariants.leaf = {
236
- value: item.icons.leaf,
237
- type: 'themeicon',
238
- };
239
- }
240
- if (item.icons.open) {
241
- iconVariants.open = {
242
- value: item.icons.open,
243
- type: 'themeicon',
244
- };
63
+ this._configContext = {
64
+ arrows: DEFAULT_ARROWS,
65
+ expandMode: DEFAULT_EXPAND_MODE,
66
+ indent: DEFAULT_INDENT,
67
+ indentGuides: DEFAULT_INDENT_GUIDES,
68
+ multiSelect: DEFAULT_MULTI_SELECT,
69
+ };
70
+ this._handleComponentKeyDown = (ev) => {
71
+ const key = ev.key;
72
+ if (listenedKeys.includes(key)) {
73
+ ev.stopPropagation();
74
+ ev.preventDefault();
245
75
  }
246
- }
247
- else if (!item.icons) {
248
- return html `${nothing}`;
249
- }
250
- if (isBranch(item)) {
251
- if (item.open) {
252
- return this._renderIconVariant(iconVariants.open);
76
+ switch (key) {
77
+ case ' ':
78
+ case 'Enter':
79
+ this._handleEnterPress();
80
+ break;
81
+ case 'ArrowDown':
82
+ this._handleArrowDownPress();
83
+ break;
84
+ case 'ArrowLeft':
85
+ this._handleArrowLeftPress(ev);
86
+ break;
87
+ case 'ArrowRight':
88
+ this._handleArrowRightPress();
89
+ break;
90
+ case 'ArrowUp':
91
+ this._handleArrowUpPress();
92
+ break;
93
+ case 'Shift':
94
+ this._handleShiftPress();
95
+ break;
96
+ default:
253
97
  }
254
- else {
255
- return this._renderIconVariant(iconVariants.branch);
98
+ };
99
+ this._handleComponentKeyUp = (ev) => {
100
+ if (ev.key === 'Shift') {
101
+ this._treeContextState.isShiftPressed = false;
256
102
  }
257
- }
258
- else {
259
- return this._renderIconVariant(iconVariants.leaf);
260
- }
261
- }
262
- _renderArrow(item) {
263
- if (!this.arrows || !isBranch(item)) {
264
- return html `${nothing}`;
265
- }
266
- const { open = false } = item;
267
- const arrowIconName = open ? 'chevron-down' : 'chevron-right';
268
- return html `
269
- <div class="arrow-container">
270
- <vscode-icon name=${arrowIconName} class="icon-arrow"></vscode-icon>
271
- </div>
272
- `;
273
- }
274
- _renderActions(item) {
275
- const actionButtons = [];
276
- if (item.actions && Array.isArray(item.actions)) {
277
- item.actions.forEach((action, index) => {
278
- if (action.icon) {
279
- const icon = html `<vscode-icon
280
- name=${action.icon}
281
- action-icon
282
- title=${ifDefined(action.tooltip)}
283
- data-item-path=${ifDefined(item.path?.join('/'))}
284
- data-index=${index}
285
- class="action-icon"
286
- @click=${this._handleActionClick}
287
- ></vscode-icon>`;
288
- actionButtons.push(icon);
103
+ };
104
+ this._handleSlotChange = () => {
105
+ this._treeContextState.itemListUpToDate = false;
106
+ initPathTrackerProps(this, this._assignedTreeItems);
107
+ this.updateComplete.then(() => {
108
+ if (this._treeContextState.activeItem === null) {
109
+ const firstChild = this.querySelector(':scope > vscode-tree-item');
110
+ if (firstChild) {
111
+ firstChild.active = true;
112
+ }
289
113
  }
114
+ this._highlightGuides();
290
115
  });
291
- }
292
- if (actionButtons.length > 0) {
293
- return html `<div class="actions">${actionButtons}</div>`;
294
- }
295
- else {
296
- return html `${nothing}`;
297
- }
116
+ };
117
+ this.addEventListener('keyup', this._handleComponentKeyUp);
118
+ this.addEventListener('keydown', this._handleComponentKeyDown);
298
119
  }
299
- _renderDecorations(item) {
300
- const decorations = [];
301
- if (item.decorations && Array.isArray(item.decorations)) {
302
- item.decorations.forEach((decoration) => {
303
- const { appearance = 'text', visibleWhen = 'always', content = '', color = '', focusedColor = '', hoverColor = '', selectedColor = '', } = decoration;
304
- const visibleWhenClass = `visible-when-${visibleWhen}`;
305
- const inlineStyles = {};
306
- if (color) {
307
- inlineStyles['--color'] = color;
308
- }
309
- if (focusedColor) {
310
- inlineStyles['--focused-color'] = focusedColor;
311
- }
312
- if (hoverColor) {
313
- inlineStyles['--hover-color'] = hoverColor;
314
- }
315
- if (selectedColor) {
316
- inlineStyles['--selected-color'] = selectedColor;
317
- }
318
- switch (appearance) {
319
- case 'counter-badge':
320
- decorations.push(html `<vscode-badge
321
- variant="counter"
322
- class=${['counter-badge', visibleWhenClass].join(' ')}
323
- part="counter-badge-decoration"
324
- >${content}</vscode-badge
325
- >`);
326
- break;
327
- case 'filled-circle':
328
- decorations.push(html `<vscode-icon
329
- name="circle-filled"
330
- size="14"
331
- class=${['filled-circle', visibleWhenClass].join(' ')}
332
- part="filled-circle-decoration"
333
- .style=${stylePropertyMap(inlineStyles)}
334
- ></vscode-icon>`);
335
- break;
336
- case 'text':
337
- decorations.push(html `<div
338
- class=${['decoration-text', visibleWhenClass].join(' ')}
339
- part="caption-decoration"
340
- .style=${stylePropertyMap(inlineStyles)}
341
- >
342
- ${content}
343
- </div>`);
344
- break;
345
- default:
346
- }
347
- });
348
- }
349
- if (decorations.length > 0) {
350
- return html `<div class="decorations" part="decorations">
351
- ${decorations}
352
- </div>`;
353
- }
354
- else {
355
- return html `${nothing}`;
356
- }
120
+ connectedCallback() {
121
+ super.connectedCallback();
122
+ this.role = 'tree';
357
123
  }
358
- _renderTreeItem(item, additionalOptions) {
359
- const { open = false, label, description = '', tooltip, selected = false, focused = false, subItems = [], } = item;
360
- const { path, itemType, hasFocusedItem = false, hasSelectedItem = false, } = additionalOptions;
361
- const indentLevel = path.length - 1;
362
- const contentsClasses = ['contents'];
363
- const liClasses = open ? ['open'] : [];
364
- const indentSize = indentLevel * this.indent;
365
- const padLeft = this.arrows && itemType === 'leaf'
366
- ? ARROW_OUTER_WIDTH + indentSize
367
- : indentSize;
368
- const arrowMarkup = this._renderArrow(item);
369
- const iconMarkup = this._renderIcon(item);
370
- const indentGuidePos = this.arrows
371
- ? indentSize + ARROW_ICON_WIDTH
372
- : indentSize + CONTENT_PADDING;
373
- const subTreeMarkup = open && itemType === 'branch'
374
- ? html `<ul
375
- .style=${stylePropertyMap({
376
- '--indent-guide-pos': `${indentGuidePos}px`,
377
- })}
378
- class=${classMap({
379
- 'has-active-item': hasFocusedItem || hasSelectedItem,
380
- })}
381
- >
382
- ${this._renderTree(subItems, path)}
383
- </ul>`
384
- : nothing;
385
- const descriptionMarkup = description
386
- ? html `<span class="description" part="description">${description}</span>`
387
- : nothing;
388
- const actionsMarkup = this._renderActions(item);
389
- const decorationsMarkup = this._renderDecorations(item);
390
- liClasses.push(itemType);
391
- if (selected) {
392
- contentsClasses.push('selected');
124
+ willUpdate(changedProperties) {
125
+ this._updateConfigContext(changedProperties);
126
+ if (changedProperties.has('multiSelect')) {
127
+ this.ariaMultiSelectable = this.multiSelect ? 'true' : 'false';
393
128
  }
394
- if (focused) {
395
- contentsClasses.push('focused');
396
- }
397
- return html `
398
- <li data-path=${path.join('/')} class=${liClasses.join(' ')}>
399
- <div
400
- class=${contentsClasses.join(' ')}
401
- .style=${stylePropertyMap({
402
- paddingLeft: `${padLeft + CONTENT_PADDING}px`,
403
- })}
404
- >
405
- ${arrowMarkup}${iconMarkup}<span
406
- class="text-content"
407
- part="text-content"
408
- title=${ifDefined(tooltip)}
409
- >${label}${descriptionMarkup}</span
410
- >
411
- ${actionsMarkup} ${decorationsMarkup}
412
- </div>
413
- ${subTreeMarkup}
414
- </li>
415
- `;
416
129
  }
417
- _renderTree(tree, oldPath = []) {
418
- const ret = [];
419
- if (!tree) {
420
- return nothing;
421
- }
422
- tree.forEach((item, index) => {
423
- const path = [...oldPath, index];
424
- const itemType = isBranch(item) ? 'branch' : 'leaf';
425
- const { selected = false, focused = false, hasFocusedItem = false, hasSelectedItem = false, } = item;
426
- if (selected) {
427
- this._selectedItem = item;
130
+ //#endregion
131
+ //#region public methods
132
+ expandAll() {
133
+ const children = this.querySelectorAll('vscode-tree-item');
134
+ children.forEach((item) => {
135
+ if (item.branch) {
136
+ item.open = true;
428
137
  }
429
- if (focused) {
430
- this._focusedItem = item;
138
+ });
139
+ }
140
+ collapseAll() {
141
+ const children = this.querySelectorAll('vscode-tree-item');
142
+ children.forEach((item) => {
143
+ if (item.branch) {
144
+ item.open = false;
431
145
  }
432
- ret.push(this._renderTreeItem(item, {
433
- path,
434
- itemType,
435
- hasFocusedItem,
436
- hasSelectedItem,
437
- }));
438
146
  });
439
- return ret;
440
147
  }
441
- _selectItem(item) {
442
- if (this._selectedItem) {
443
- this._selectedItem.selected = false;
444
- }
445
- if (this._focusedItem) {
446
- this._focusedItem.focused = false;
447
- }
448
- this._selectedItem = item;
449
- item.selected = true;
450
- this._focusedItem = item;
451
- item.focused = true;
452
- if (this._selectedBranch) {
453
- this._selectedBranch.hasSelectedItem = false;
454
- }
455
- let parentBranch = null;
456
- if (item.path?.length && item.path.length > 1) {
457
- parentBranch = this._getItemByPath(item.path.slice(0, -1));
458
- }
459
- if (isBranch(item)) {
460
- this._selectedBranch = item;
461
- item.hasSelectedItem = true;
462
- item.open = !item.open;
463
- if (!item.open) {
464
- if (parentBranch) {
465
- this._selectedBranch = parentBranch;
466
- parentBranch.hasSelectedItem = true;
467
- }
148
+ /**
149
+ * @internal
150
+ * Updates `hasBranchItem` property in the context state in order to removing
151
+ * extra padding before the leaf elements, if it is required.
152
+ */
153
+ updateHasBranchItemFlag() {
154
+ const hasBranchItem = this._assignedTreeItems.some((li) => li.branch);
155
+ this._treeContextState = { ...this._treeContextState, hasBranchItem };
156
+ }
157
+ //#endregion
158
+ //#region private methods
159
+ _emitSelectEvent() {
160
+ const ev = new CustomEvent('vsc-tree-select', {
161
+ detail: Array.from(this._treeContextState.selectedItems),
162
+ });
163
+ this.dispatchEvent(ev);
164
+ }
165
+ _highlightGuides() {
166
+ const { activeItem, highlightedItems, selectedItems } = this._treeContextState;
167
+ highlightedItems.forEach((i) => (i.highlightedGuides = false));
168
+ if (activeItem) {
169
+ this._treeContextState.highlightedItems = [];
170
+ if (activeItem.branch && activeItem.open) {
171
+ activeItem.highlightedGuides = true;
172
+ this._treeContextState.highlightedItems.push(activeItem);
468
173
  }
469
174
  else {
470
- this._selectedBranch = item;
471
- item.hasSelectedItem = true;
175
+ const parent = getParentItem(activeItem);
176
+ if (parent && parent.branch) {
177
+ parent.highlightedGuides = true;
178
+ this._treeContextState.highlightedItems.push(parent);
179
+ }
472
180
  }
473
181
  }
474
- else {
475
- if (item.path?.length && item.path.length > 1) {
476
- const parentBranch = this._getItemByPath(item.path.slice(0, -1));
477
- if (parentBranch) {
478
- this._selectedBranch = parentBranch;
479
- parentBranch.hasSelectedItem = true;
182
+ if (selectedItems) {
183
+ selectedItems.forEach((item) => {
184
+ if (item.branch && item.open) {
185
+ item.highlightedGuides = true;
186
+ this._treeContextState.highlightedItems.push(item);
480
187
  }
481
- }
482
- else {
483
- this._selectedBranch = item;
484
- item.hasSelectedItem = true;
485
- }
188
+ else {
189
+ const parent = getParentItem(item);
190
+ if (parent && parent.branch) {
191
+ parent.highlightedGuides = true;
192
+ this._treeContextState.highlightedItems.push(item);
193
+ }
194
+ }
195
+ });
486
196
  }
487
- this._emitSelectEvent(this._selectedItem, this._selectedItem.path.join('/'));
488
- this.requestUpdate();
489
197
  }
490
- _focusItem(item) {
491
- if (this._focusedItem) {
492
- this._focusedItem.focused = false;
198
+ _updateConfigContext(changedProperties) {
199
+ const { arrows, expandMode, indent, indentGuides, multiSelect } = this;
200
+ if (changedProperties.has('arrows')) {
201
+ this._configContext = { ...this._configContext, arrows };
493
202
  }
494
- this._focusedItem = item;
495
- item.focused = true;
496
- const isBranch = !!item?.subItems?.length;
497
- if (this._focusedBranch) {
498
- this._focusedBranch.hasFocusedItem = false;
203
+ if (changedProperties.has('expandMode')) {
204
+ this._configContext = { ...this._configContext, expandMode };
499
205
  }
500
- let parentBranch = null;
501
- if (item.path?.length && item.path.length > 1) {
502
- parentBranch = this._getItemByPath(item.path.slice(0, -1));
206
+ if (changedProperties.has('indent')) {
207
+ this._configContext = { ...this._configContext, indent };
503
208
  }
504
- if (!isBranch) {
505
- if (parentBranch) {
506
- this._focusedBranch = parentBranch;
507
- parentBranch.hasFocusedItem = true;
508
- }
209
+ if (changedProperties.has('indentGuides')) {
210
+ this._configContext = { ...this._configContext, indentGuides };
509
211
  }
510
- else {
511
- if (item.open) {
512
- this._focusedBranch = item;
513
- item.hasFocusedItem = true;
514
- }
515
- else if (!item.open && parentBranch) {
516
- this._focusedBranch = parentBranch;
517
- parentBranch.hasFocusedItem = true;
518
- }
212
+ if (changedProperties.has('multiSelect')) {
213
+ this._configContext = { ...this._configContext, multiSelect };
519
214
  }
520
215
  }
521
- _closeSubTreeRecursively(tree) {
522
- tree.forEach((item) => {
523
- item.open = false;
524
- if (item.subItems && item.subItems.length > 0) {
525
- this._closeSubTreeRecursively(item.subItems);
526
- }
216
+ _focusItem(item) {
217
+ item.active = true;
218
+ item.updateComplete.then(() => {
219
+ item.focus();
527
220
  });
528
221
  }
529
- _deselectItemsRecursively(tree) {
530
- tree.forEach((item) => {
531
- if (item.selected) {
532
- item.selected = false;
533
- }
534
- if (item.subItems && item.subItems.length > 0) {
535
- this._deselectItemsRecursively(item.subItems);
222
+ _focusPrevItem() {
223
+ if (this._treeContextState.focusedItem) {
224
+ const item = findPrevItem(this._treeContextState.focusedItem);
225
+ if (item) {
226
+ this._focusItem(item);
227
+ if (this._treeContextState.isShiftPressed && this.multiSelect) {
228
+ item.selected = !item.selected;
229
+ this._emitSelectEvent();
230
+ }
536
231
  }
537
- });
232
+ }
538
233
  }
539
- _emitSelectEvent(item, path) {
540
- const { icons, label, open, value } = item;
541
- const detail = {
542
- icons,
543
- itemType: isBranch(item) ? 'branch' : 'leaf',
544
- label,
545
- open: open || false,
546
- value: value || label,
547
- path,
548
- };
549
- /** @deprecated Renamed to `vsc-tree-select` */
550
- this.dispatchEvent(new CustomEvent('vsc-select', {
551
- bubbles: true,
552
- composed: true,
553
- detail,
554
- }));
555
- this.dispatchEvent(new CustomEvent('vsc-tree-select', {
556
- detail,
557
- }));
234
+ _focusNextItem() {
235
+ if (this._treeContextState.focusedItem) {
236
+ const item = findNextItem(this._treeContextState.focusedItem);
237
+ if (item) {
238
+ this._focusItem(item);
239
+ if (this._treeContextState.isShiftPressed && this.multiSelect) {
240
+ item.selected = !item.selected;
241
+ this._emitSelectEvent();
242
+ }
243
+ }
244
+ }
558
245
  }
559
- _focusPrevItem() {
560
- if (!this._focusedItem) {
561
- this._focusItem(this._data[0]);
246
+ //#endregion
247
+ //#region event handlers
248
+ _handleArrowRightPress() {
249
+ if (!this._treeContextState.focusedItem) {
562
250
  return;
563
251
  }
564
- const { path } = this._focusedItem;
565
- if (path && path?.length > 0) {
566
- const currentItemIndex = path[path.length - 1];
567
- const hasParent = path.length > 1;
568
- if (currentItemIndex > 0) {
569
- const newPath = [...path];
570
- newPath[newPath.length - 1] = currentItemIndex - 1;
571
- const prevSibling = this._getItemByPath(newPath);
572
- let newFocusedItem = prevSibling;
573
- if (prevSibling?.open && prevSibling.subItems?.length) {
574
- const { subItems } = prevSibling;
575
- newFocusedItem = subItems[subItems.length - 1];
576
- }
577
- this._focusItem(newFocusedItem);
252
+ const { focusedItem } = this._treeContextState;
253
+ if (focusedItem.branch) {
254
+ if (focusedItem.open) {
255
+ this._focusNextItem();
578
256
  }
579
257
  else {
580
- if (hasParent) {
581
- const newPath = [...path];
582
- newPath.pop();
583
- this._focusItem(this._getItemByPath(newPath));
584
- }
258
+ focusedItem.open = true;
585
259
  }
586
260
  }
587
- else {
588
- this._focusItem(this._data[0]);
589
- }
590
261
  }
591
- _focusNextItem() {
592
- if (!this._focusedItem) {
593
- this._focusItem(this._data[0]);
262
+ _handleArrowLeftPress(ev) {
263
+ if (ev.ctrlKey) {
264
+ this.collapseAll();
594
265
  return;
595
266
  }
596
- const { path, open } = this._focusedItem;
597
- if (open &&
598
- Array.isArray(this._focusedItem.subItems) &&
599
- this._focusedItem.subItems.length > 0) {
600
- this._focusItem(this._focusedItem.subItems[0]);
267
+ if (!this._treeContextState.focusedItem) {
601
268
  return;
602
269
  }
603
- const nextPath = [...path];
604
- nextPath[nextPath.length - 1] += 1;
605
- let nextFocusedItem = this._getItemByPath(nextPath);
606
- if (nextFocusedItem) {
607
- this._focusItem(nextFocusedItem);
270
+ const { focusedItem } = this._treeContextState;
271
+ const parent = getParentItem(focusedItem);
272
+ if (!focusedItem.branch) {
273
+ if (parent && parent.branch) {
274
+ this._focusItem(parent);
275
+ }
608
276
  }
609
277
  else {
610
- nextPath.pop();
611
- if (nextPath.length > 0) {
612
- nextPath[nextPath.length - 1] += 1;
613
- nextFocusedItem = this._getItemByPath(nextPath);
614
- if (nextFocusedItem) {
615
- this._focusItem(nextFocusedItem);
278
+ if (focusedItem.open) {
279
+ focusedItem.open = false;
280
+ }
281
+ else {
282
+ if (parent && parent.branch) {
283
+ this._focusItem(parent);
616
284
  }
617
285
  }
618
286
  }
619
287
  }
620
- _handleClick(event) {
621
- const composedPath = event.composedPath();
622
- const targetElement = composedPath.find((el) => el.tagName &&
623
- el.tagName.toUpperCase() === 'LI');
624
- if (targetElement) {
625
- const pathStr = targetElement.dataset.path || '';
626
- const path = pathStr.split('/').map((el) => Number(el));
627
- const item = this._getItemByPath(path);
628
- this._selectItem(item);
288
+ _handleArrowDownPress() {
289
+ if (this._treeContextState.focusedItem) {
290
+ this._focusNextItem();
629
291
  }
630
292
  else {
631
- if (this._focusedItem) {
632
- this._focusedItem.focused = false;
633
- }
634
- this._focusedItem = null;
293
+ this._focusItem(this._assignedTreeItems[0]);
635
294
  }
636
295
  }
637
- _handleComponentKeyDown(ev) {
638
- const keys = [
639
- ' ',
640
- 'ArrowDown',
641
- 'ArrowUp',
642
- 'Enter',
643
- 'Escape',
644
- ];
645
- const key = ev.key;
646
- if (keys.includes(ev.key)) {
647
- ev.stopPropagation();
648
- ev.preventDefault();
649
- }
650
- if (key === 'Escape') {
651
- this._focusedItem = null;
652
- }
653
- if (key === 'ArrowUp') {
296
+ _handleArrowUpPress() {
297
+ if (this._treeContextState.focusedItem) {
654
298
  this._focusPrevItem();
655
299
  }
656
- if (key === 'ArrowDown') {
657
- this._focusNextItem();
300
+ else {
301
+ this._focusItem(this._assignedTreeItems[0]);
658
302
  }
659
- if (key === 'Enter' || key === ' ') {
660
- if (this._focusedItem) {
661
- this._selectItem(this._focusedItem);
303
+ }
304
+ _handleEnterPress() {
305
+ const { focusedItem } = this._treeContextState;
306
+ if (focusedItem) {
307
+ this._treeContextState.selectedItems.forEach((li) => (li.selected = false));
308
+ focusedItem.selected = true;
309
+ this._emitSelectEvent();
310
+ if (focusedItem.branch) {
311
+ focusedItem.open = !focusedItem.open;
662
312
  }
663
313
  }
664
314
  }
315
+ _handleShiftPress() {
316
+ this._treeContextState.isShiftPressed = true;
317
+ }
318
+ //#endregion
665
319
  render() {
666
- const classes = classMap({
667
- multi: this.multiline,
668
- single: !this.multiline,
669
- wrapper: true,
670
- 'has-not-focused-item': !this._focusedItem,
671
- 'selection-none': !this._selectedItem,
672
- 'selection-single': this._selectedItem !== null,
673
- });
674
- return html `
675
- <div @click=${this._handleClick} class=${classes}>
676
- <ul>
677
- ${this._renderTree(this._data)}
678
- </ul>
679
- </div>
680
- `;
320
+ return html `<div>
321
+ <slot @slotchange=${this._handleSlotChange}></slot>
322
+ </div>`;
681
323
  }
682
324
  };
683
325
  VscodeTree.styles = styles;
684
- __decorate([
685
- property({ type: Array, reflect: false })
686
- ], VscodeTree.prototype, "data", null);
687
- __decorate([
688
- property({ type: Number })
689
- ], VscodeTree.prototype, "indent", void 0);
690
326
  __decorate([
691
327
  property({ type: Boolean, reflect: true })
692
328
  ], VscodeTree.prototype, "arrows", void 0);
693
329
  __decorate([
694
- property({ type: Boolean, reflect: true })
695
- ], VscodeTree.prototype, "multiline", void 0);
330
+ property({ type: String, attribute: 'expand-mode' })
331
+ ], VscodeTree.prototype, "expandMode", void 0);
696
332
  __decorate([
697
333
  property({ type: Number, reflect: true })
698
- ], VscodeTree.prototype, "tabindex", void 0);
334
+ ], VscodeTree.prototype, "indent", void 0);
699
335
  __decorate([
700
- property({ type: Boolean, reflect: true, attribute: 'indent-guides' })
336
+ property({ type: Boolean, attribute: 'indent-guides', reflect: true })
701
337
  ], VscodeTree.prototype, "indentGuides", void 0);
702
338
  __decorate([
703
- state()
704
- ], VscodeTree.prototype, "_selectedItem", void 0);
339
+ property({ type: Boolean, reflect: true, attribute: 'multi-select' })
340
+ ], VscodeTree.prototype, "multiSelect", void 0);
705
341
  __decorate([
706
- state()
707
- ], VscodeTree.prototype, "_focusedItem", void 0);
342
+ provide({ context: treeContext })
343
+ ], VscodeTree.prototype, "_treeContextState", void 0);
708
344
  __decorate([
709
- state()
710
- ], VscodeTree.prototype, "_selectedBranch", void 0);
345
+ provide({ context: configContext })
346
+ ], VscodeTree.prototype, "_configContext", void 0);
711
347
  __decorate([
712
- state()
713
- ], VscodeTree.prototype, "_focusedBranch", void 0);
348
+ queryAssignedElements({ selector: 'vscode-tree-item' })
349
+ ], VscodeTree.prototype, "_assignedTreeItems", void 0);
714
350
  VscodeTree = __decorate([
715
351
  customElement('vscode-tree')
716
352
  ], VscodeTree);