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

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 +3512 -1943
  3. package/dist/bundled.js +1179 -947
  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 +9 -0
  219. package/dist/vscode-tree/helpers.d.ts.map +1 -0
  220. package/dist/vscode-tree/helpers.js +116 -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 +96 -144
  227. package/dist/vscode-tree/vscode-tree.d.ts.map +1 -1
  228. package/dist/vscode-tree/vscode-tree.js +324 -622
  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 +31 -231
  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 +50 -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 +418 -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 +140 -0
  244. package/dist/vscode-tree-item/vscode-tree-item.styles.js.map +1 -0
  245. package/package.json +40 -40
  246. package/vscode.css-custom-data.json +44 -55
  247. package/vscode.html-custom-data.json +154 -45
@@ -4,713 +4,415 @@ 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, findParentItem, initPathTrackerProps, } from './helpers.js';
14
+ export const ExpandMode = {
15
+ singleClick: 'singleClick',
16
+ doubleClick: '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;
18
+ export const IndentGuides = {
19
+ none: 'none',
20
+ onHover: 'onHover',
21
+ always: 'always',
41
22
  };
23
+ const listenedKeys = [
24
+ ' ',
25
+ 'ArrowDown',
26
+ 'ArrowUp',
27
+ 'ArrowLeft',
28
+ 'ArrowRight',
29
+ 'Enter',
30
+ 'Escape',
31
+ 'Shift',
32
+ ];
33
+ const DEFAULT_HIDE_ARROWS = false;
34
+ const DEFAULT_INDENT = 8;
35
+ const DEFAULT_MULTI_SELECT = false;
36
+ const DEFAULT_EXPAND_MODE = ExpandMode.singleClick;
37
+ const DEFAULT_INDENT_GUIDE_DISPLAY = IndentGuides.onHover;
42
38
  /**
43
39
  * @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
40
  */
74
41
  let VscodeTree = class VscodeTree extends VscElement {
42
+ //#endregion
43
+ //#region lifecycle methods
75
44
  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);
45
+ super();
46
+ //#region properties
47
+ /**
48
+ * Although arrows are always visible in the Tree component by default in VSCode, some icon sets
49
+ * (e.g., Material Icon Theme) allow disabling them in the file explorer view. This flag makes it
50
+ * possible to mimic that behavior.
51
+ *
52
+ * @type {boolean}
53
+ * @default false
54
+ */
55
+ this.hideArrows = DEFAULT_HIDE_ARROWS;
56
+ /**
57
+ * Controls how tree folders are expanded when clicked. This property is designed to use
58
+ * the `workbench.tree.expandMode` setting.
59
+ *
60
+ * Valid options are available as constants.
61
+ *
62
+ * ```javascript
63
+ * import {ExpandMode} from '@vscode-elements/elements/dist/vscode-tree/vscode-tree.js';
64
+ *
65
+ * document.querySelector('vscode-tree').expandMode = ExpandMode.singleClick;
66
+ * ```
67
+ *
68
+ * @type {'singleClick' | 'doubleClick'}
69
+ * @default 'singleClick'
70
+ */
71
+ this.expandMode = DEFAULT_EXPAND_MODE;
72
+ /**
73
+ * Controls the indentation in pixels. This property is designed to use the
74
+ * `workbench.tree.indent` setting.
75
+ *
76
+ * @type {number}
77
+ * @default 8
78
+ */
79
+ this.indent = DEFAULT_INDENT;
80
+ /**
81
+ * Controls whether the tree should render indent guides. This property is
82
+ * designed to use the `workbench.tree.renderIndentGuides` setting.
83
+ *
84
+ * Valid options are available as constants.
85
+ *
86
+ * ```javascript
87
+ * import {IndentGuides} from '@vscode-elements/elements/dist/vscode-tree/vscode-tree.js';
88
+ *
89
+ * document.querySelector('vscode-tree').expandMode = IndentGuides.onHover;
90
+ * ```
91
+ *
92
+ * @type {'none' | 'onHover' | 'always'}
93
+ * @default 'onHover'
94
+ */
95
+ this.indentGuides = DEFAULT_INDENT_GUIDE_DISPLAY;
96
+ /**
97
+ * Allows selecting multiple items.
98
+ *
99
+ * @type {boolean}
100
+ * @default false
101
+ */
102
+ this.multiSelect = DEFAULT_MULTI_SELECT;
103
+ //#endregion
104
+ //#region private variables
105
+ this._treeContextState = {
106
+ isShiftPressed: false,
107
+ activeItem: null,
108
+ selectedItems: new Set(),
109
+ allItems: null,
110
+ itemListUpToDate: false,
111
+ focusedItem: null,
112
+ prevFocusedItem: null,
113
+ hasBranchItem: false,
114
+ rootElement: this,
115
+ highlightedItems: new Set(),
116
+ highlightIndentGuides: () => {
117
+ this._highlightIndentGuides();
118
+ },
119
+ emitSelectEvent: () => {
120
+ this._emitSelectEvent();
121
+ },
122
+ };
123
+ this._configContext = {
124
+ hideArrows: DEFAULT_HIDE_ARROWS,
125
+ expandMode: DEFAULT_EXPAND_MODE,
126
+ indent: DEFAULT_INDENT,
127
+ indentGuides: DEFAULT_INDENT_GUIDE_DISPLAY,
128
+ multiSelect: DEFAULT_MULTI_SELECT,
129
+ };
130
+ this._handleComponentKeyDown = (ev) => {
131
+ const key = ev.key;
132
+ if (listenedKeys.includes(key)) {
133
+ ev.stopPropagation();
134
+ ev.preventDefault();
135
+ }
136
+ switch (key) {
137
+ case ' ':
138
+ case 'Enter':
139
+ this._handleEnterPress();
140
+ break;
141
+ case 'ArrowDown':
142
+ this._handleArrowDownPress();
143
+ break;
144
+ case 'ArrowLeft':
145
+ this._handleArrowLeftPress(ev);
146
+ break;
147
+ case 'ArrowRight':
148
+ this._handleArrowRightPress();
149
+ break;
150
+ case 'ArrowUp':
151
+ this._handleArrowUpPress();
152
+ break;
153
+ case 'Shift':
154
+ this._handleShiftPress();
155
+ break;
156
+ default:
157
+ }
158
+ };
159
+ this._handleComponentKeyUp = (ev) => {
160
+ if (ev.key === 'Shift') {
161
+ this._treeContextState.isShiftPressed = false;
162
+ }
163
+ };
164
+ this._handleSlotChange = () => {
165
+ this._treeContextState.itemListUpToDate = false;
166
+ initPathTrackerProps(this, this._assignedTreeItems);
167
+ this.updateComplete.then(() => {
168
+ if (this._treeContextState.activeItem === null) {
169
+ const firstChild = this.querySelector(':scope > vscode-tree-item');
170
+ if (firstChild) {
171
+ firstChild.active = true;
172
+ }
173
+ }
174
+ });
175
+ };
176
+ this.addEventListener('keyup', this._handleComponentKeyUp);
177
+ this.addEventListener('keydown', this._handleComponentKeyDown);
88
178
  }
89
- set data(val) {
90
- const oldVal = this._data;
91
- this._data = addPath(val);
92
- this.requestUpdate('data', oldVal);
179
+ connectedCallback() {
180
+ super.connectedCallback();
181
+ this.role = 'tree';
93
182
  }
94
- get data() {
95
- return this._data;
183
+ willUpdate(changedProperties) {
184
+ this._updateConfigContext(changedProperties);
185
+ if (changedProperties.has('multiSelect')) {
186
+ this.ariaMultiSelectable = this.multiSelect ? 'true' : 'false';
187
+ }
96
188
  }
189
+ //#endregion
190
+ //#region public methods
97
191
  /**
98
- * Closes all opened tree items recursively.
192
+ * Expands all folders.
99
193
  */
100
- closeAll() {
101
- this._closeSubTreeRecursively(this.data);
102
- this.requestUpdate();
194
+ expandAll() {
195
+ const children = this.querySelectorAll('vscode-tree-item');
196
+ children.forEach((item) => {
197
+ if (item.branch) {
198
+ item.open = true;
199
+ }
200
+ });
103
201
  }
104
202
  /**
105
- * Deselects all selected items.
203
+ * Collapses all folders.
106
204
  */
107
- deselectAll() {
108
- this._deselectItemsRecursively(this.data);
109
- this.requestUpdate();
205
+ collapseAll() {
206
+ const children = this.querySelectorAll('vscode-tree-item');
207
+ children.forEach((item) => {
208
+ if (item.branch) {
209
+ item.open = false;
210
+ }
211
+ });
110
212
  }
111
213
  /**
112
- * Returns a reference to a TreeItem object by path.
113
- * @param path
114
- * @returns
214
+ * @internal
215
+ * Updates `hasBranchItem` property in the context state in order to removing
216
+ * extra padding before the leaf elements, if it is required.
115
217
  */
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);
218
+ updateHasBranchItemFlag() {
219
+ const hasBranchItem = this._assignedTreeItems.some((li) => li.branch);
220
+ this._treeContextState = { ...this._treeContextState, hasBranchItem };
126
221
  }
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
- }
222
+ //#endregion
223
+ //#region private methods
224
+ _emitSelectEvent() {
225
+ const ev = new CustomEvent('vsc-tree-select', {
226
+ detail: Array.from(this._treeContextState.selectedItems),
137
227
  });
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,
167
- },
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
- }));
228
+ this.dispatchEvent(ev);
179
229
  }
180
- _renderIconVariant(variant) {
181
- const { type, value } = variant;
182
- if (type === 'themeicon') {
183
- return html `<vscode-icon name=${value} class="theme-icon"></vscode-icon>`;
230
+ _highlightIndentGuideOfItem(item) {
231
+ if (item.branch && item.open) {
232
+ item.highlightedGuides = true;
233
+ this._treeContextState.highlightedItems?.add(item);
184
234
  }
185
235
  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',
205
- },
206
- };
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
- };
236
+ const parent = findParentItem(item);
237
+ if (parent) {
238
+ parent.highlightedGuides = true;
239
+ this._treeContextState.highlightedItems?.add(parent);
225
240
  }
226
241
  }
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
- };
245
- }
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);
253
- }
254
- else {
255
- return this._renderIconVariant(iconVariants.branch);
256
- }
257
- }
258
- else {
259
- return this._renderIconVariant(iconVariants.leaf);
260
- }
261
242
  }
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);
289
- }
290
- });
291
- }
292
- if (actionButtons.length > 0) {
293
- return html `<div class="actions">${actionButtons}</div>`;
243
+ _highlightIndentGuides() {
244
+ if (this.indentGuides === IndentGuides.none) {
245
+ return;
294
246
  }
295
- else {
296
- return html `${nothing}`;
247
+ this._treeContextState.highlightedItems?.forEach((i) => (i.highlightedGuides = false));
248
+ this._treeContextState.highlightedItems?.clear();
249
+ if (this._treeContextState.activeItem) {
250
+ this._highlightIndentGuideOfItem(this._treeContextState.activeItem);
297
251
  }
252
+ this._treeContextState.selectedItems.forEach((item) => {
253
+ this._highlightIndentGuideOfItem(item);
254
+ });
298
255
  }
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
- });
256
+ _updateConfigContext(changedProperties) {
257
+ const { hideArrows, expandMode, indent, indentGuides, multiSelect } = this;
258
+ if (changedProperties.has('hideArrows')) {
259
+ this._configContext = { ...this._configContext, hideArrows };
348
260
  }
349
- if (decorations.length > 0) {
350
- return html `<div class="decorations" part="decorations">
351
- ${decorations}
352
- </div>`;
261
+ if (changedProperties.has('expandMode')) {
262
+ this._configContext = { ...this._configContext, expandMode };
353
263
  }
354
- else {
355
- return html `${nothing}`;
264
+ if (changedProperties.has('indent')) {
265
+ this._configContext = { ...this._configContext, indent };
356
266
  }
357
- }
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');
267
+ if (changedProperties.has('indentGuides')) {
268
+ this._configContext = { ...this._configContext, indentGuides };
393
269
  }
394
- if (focused) {
395
- contentsClasses.push('focused');
270
+ if (changedProperties.has('multiSelect')) {
271
+ this._configContext = { ...this._configContext, multiSelect };
396
272
  }
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
273
  }
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;
428
- }
429
- if (focused) {
430
- this._focusedItem = item;
431
- }
432
- ret.push(this._renderTreeItem(item, {
433
- path,
434
- itemType,
435
- hasFocusedItem,
436
- hasSelectedItem,
437
- }));
274
+ _focusItem(item) {
275
+ item.active = true;
276
+ item.updateComplete.then(() => {
277
+ item.focus();
278
+ this._highlightIndentGuides();
438
279
  });
439
- return ret;
440
280
  }
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;
281
+ _focusPrevItem() {
282
+ if (this._treeContextState.focusedItem) {
283
+ const item = findPrevItem(this._treeContextState.focusedItem);
284
+ if (item) {
285
+ this._focusItem(item);
286
+ if (this._treeContextState.isShiftPressed && this.multiSelect) {
287
+ item.selected = !item.selected;
288
+ this._emitSelectEvent();
467
289
  }
468
290
  }
469
- else {
470
- this._selectedBranch = item;
471
- item.hasSelectedItem = true;
472
- }
473
291
  }
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;
480
- }
481
- }
482
- else {
483
- this._selectedBranch = item;
484
- item.hasSelectedItem = true;
485
- }
486
- }
487
- this._emitSelectEvent(this._selectedItem, this._selectedItem.path.join('/'));
488
- this.requestUpdate();
489
292
  }
490
- _focusItem(item) {
491
- if (this._focusedItem) {
492
- this._focusedItem.focused = false;
493
- }
494
- this._focusedItem = item;
495
- item.focused = true;
496
- const isBranch = !!item?.subItems?.length;
497
- if (this._focusedBranch) {
498
- this._focusedBranch.hasFocusedItem = false;
499
- }
500
- let parentBranch = null;
501
- if (item.path?.length && item.path.length > 1) {
502
- parentBranch = this._getItemByPath(item.path.slice(0, -1));
503
- }
504
- if (!isBranch) {
505
- if (parentBranch) {
506
- this._focusedBranch = parentBranch;
507
- parentBranch.hasFocusedItem = true;
508
- }
509
- }
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;
293
+ _focusNextItem() {
294
+ if (this._treeContextState.focusedItem) {
295
+ const item = findNextItem(this._treeContextState.focusedItem);
296
+ if (item) {
297
+ this._focusItem(item);
298
+ if (this._treeContextState.isShiftPressed && this.multiSelect) {
299
+ item.selected = !item.selected;
300
+ this._emitSelectEvent();
301
+ }
518
302
  }
519
303
  }
520
304
  }
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
- }
527
- });
528
- }
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);
536
- }
537
- });
538
- }
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
- }));
558
- }
559
- _focusPrevItem() {
560
- if (!this._focusedItem) {
561
- this._focusItem(this._data[0]);
305
+ //#endregion
306
+ //#region event handlers
307
+ _handleArrowRightPress() {
308
+ if (!this._treeContextState.focusedItem) {
562
309
  return;
563
310
  }
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);
311
+ const { focusedItem } = this._treeContextState;
312
+ if (focusedItem.branch) {
313
+ if (focusedItem.open) {
314
+ this._focusNextItem();
578
315
  }
579
316
  else {
580
- if (hasParent) {
581
- const newPath = [...path];
582
- newPath.pop();
583
- this._focusItem(this._getItemByPath(newPath));
584
- }
317
+ focusedItem.open = true;
585
318
  }
586
319
  }
587
- else {
588
- this._focusItem(this._data[0]);
589
- }
590
320
  }
591
- _focusNextItem() {
592
- if (!this._focusedItem) {
593
- this._focusItem(this._data[0]);
321
+ _handleArrowLeftPress(ev) {
322
+ if (ev.ctrlKey) {
323
+ this.collapseAll();
594
324
  return;
595
325
  }
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]);
326
+ if (!this._treeContextState.focusedItem) {
601
327
  return;
602
328
  }
603
- const nextPath = [...path];
604
- nextPath[nextPath.length - 1] += 1;
605
- let nextFocusedItem = this._getItemByPath(nextPath);
606
- if (nextFocusedItem) {
607
- this._focusItem(nextFocusedItem);
329
+ const { focusedItem } = this._treeContextState;
330
+ const parent = findParentItem(focusedItem);
331
+ if (!focusedItem.branch) {
332
+ if (parent && parent.branch) {
333
+ this._focusItem(parent);
334
+ }
608
335
  }
609
336
  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);
337
+ if (focusedItem.open) {
338
+ focusedItem.open = false;
339
+ }
340
+ else {
341
+ if (parent && parent.branch) {
342
+ this._focusItem(parent);
616
343
  }
617
344
  }
618
345
  }
619
346
  }
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);
347
+ _handleArrowDownPress() {
348
+ if (this._treeContextState.focusedItem) {
349
+ this._focusNextItem();
629
350
  }
630
351
  else {
631
- if (this._focusedItem) {
632
- this._focusedItem.focused = false;
633
- }
634
- this._focusedItem = null;
352
+ this._focusItem(this._assignedTreeItems[0]);
635
353
  }
636
354
  }
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') {
355
+ _handleArrowUpPress() {
356
+ if (this._treeContextState.focusedItem) {
654
357
  this._focusPrevItem();
655
358
  }
656
- if (key === 'ArrowDown') {
657
- this._focusNextItem();
359
+ else {
360
+ this._focusItem(this._assignedTreeItems[0]);
658
361
  }
659
- if (key === 'Enter' || key === ' ') {
660
- if (this._focusedItem) {
661
- this._selectItem(this._focusedItem);
362
+ }
363
+ _handleEnterPress() {
364
+ const { focusedItem } = this._treeContextState;
365
+ if (focusedItem) {
366
+ this._treeContextState.selectedItems.forEach((li) => (li.selected = false));
367
+ this._treeContextState.selectedItems.clear();
368
+ this._highlightIndentGuides();
369
+ focusedItem.selected = true;
370
+ this._emitSelectEvent();
371
+ if (focusedItem.branch) {
372
+ focusedItem.open = !focusedItem.open;
662
373
  }
663
374
  }
664
375
  }
376
+ _handleShiftPress() {
377
+ this._treeContextState.isShiftPressed = true;
378
+ }
379
+ //#endregion
665
380
  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
- `;
381
+ return html `<div>
382
+ <slot @slotchange=${this._handleSlotChange}></slot>
383
+ </div>`;
681
384
  }
682
385
  };
683
386
  VscodeTree.styles = styles;
684
387
  __decorate([
685
- property({ type: Array, reflect: false })
686
- ], VscodeTree.prototype, "data", null);
388
+ property({ type: Boolean, reflect: true, attribute: 'hide-arrows' })
389
+ ], VscodeTree.prototype, "hideArrows", void 0);
687
390
  __decorate([
688
- property({ type: Number })
689
- ], VscodeTree.prototype, "indent", void 0);
690
- __decorate([
691
- property({ type: Boolean, reflect: true })
692
- ], VscodeTree.prototype, "arrows", void 0);
693
- __decorate([
694
- property({ type: Boolean, reflect: true })
695
- ], VscodeTree.prototype, "multiline", void 0);
391
+ property({ type: String, attribute: 'expand-mode' })
392
+ ], VscodeTree.prototype, "expandMode", void 0);
696
393
  __decorate([
697
394
  property({ type: Number, reflect: true })
698
- ], VscodeTree.prototype, "tabindex", void 0);
395
+ ], VscodeTree.prototype, "indent", void 0);
699
396
  __decorate([
700
- property({ type: Boolean, reflect: true, attribute: 'indent-guides' })
397
+ property({
398
+ type: String,
399
+ attribute: 'indent-guides',
400
+ useDefault: true,
401
+ reflect: true,
402
+ })
701
403
  ], VscodeTree.prototype, "indentGuides", void 0);
702
404
  __decorate([
703
- state()
704
- ], VscodeTree.prototype, "_selectedItem", void 0);
405
+ property({ type: Boolean, reflect: true, attribute: 'multi-select' })
406
+ ], VscodeTree.prototype, "multiSelect", void 0);
705
407
  __decorate([
706
- state()
707
- ], VscodeTree.prototype, "_focusedItem", void 0);
408
+ provide({ context: treeContext })
409
+ ], VscodeTree.prototype, "_treeContextState", void 0);
708
410
  __decorate([
709
- state()
710
- ], VscodeTree.prototype, "_selectedBranch", void 0);
411
+ provide({ context: configContext })
412
+ ], VscodeTree.prototype, "_configContext", void 0);
711
413
  __decorate([
712
- state()
713
- ], VscodeTree.prototype, "_focusedBranch", void 0);
414
+ queryAssignedElements({ selector: 'vscode-tree-item' })
415
+ ], VscodeTree.prototype, "_assignedTreeItems", void 0);
714
416
  VscodeTree = __decorate([
715
417
  customElement('vscode-tree')
716
418
  ], VscodeTree);