@vonage/vivid 4.16.2 → 4.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (292) hide show
  1. package/custom-elements.json +3426 -506
  2. package/elevation/index.cjs +1 -1
  3. package/elevation/index.js +1 -1
  4. package/index.cjs +147 -39
  5. package/index.js +64 -59
  6. package/lib/accordion/definition.d.ts +2 -0
  7. package/lib/accordion-item/definition.d.ts +2 -0
  8. package/lib/action-group/definition.d.ts +2 -0
  9. package/lib/alert/definition.d.ts +2 -0
  10. package/lib/audio-player/definition.d.ts +2 -0
  11. package/lib/avatar/definition.d.ts +2 -0
  12. package/lib/badge/definition.d.ts +2 -0
  13. package/lib/banner/definition.d.ts +2 -0
  14. package/lib/breadcrumb/definition.d.ts +2 -0
  15. package/lib/breadcrumb-item/definition.d.ts +2 -0
  16. package/lib/button/definition.d.ts +2 -0
  17. package/lib/calendar/calendar.d.ts +2 -0
  18. package/lib/calendar/definition.d.ts +2 -0
  19. package/lib/calendar-event/definition.d.ts +2 -0
  20. package/lib/card/definition.d.ts +2 -0
  21. package/lib/checkbox/definition.d.ts +2 -0
  22. package/lib/combobox/definition.d.ts +2 -0
  23. package/lib/components.d.ts +1 -0
  24. package/lib/data-grid/definition.d.ts +4 -0
  25. package/lib/date-picker/definition.d.ts +2 -0
  26. package/lib/date-range-picker/definition.d.ts +2 -0
  27. package/lib/dial-pad/definition.d.ts +2 -0
  28. package/lib/dialog/definition.d.ts +2 -0
  29. package/lib/divider/definition.d.ts +2 -0
  30. package/lib/empty-state/definition.d.ts +2 -0
  31. package/lib/enums.d.ts +6 -0
  32. package/lib/fab/definition.d.ts +2 -0
  33. package/lib/file-picker/definition.d.ts +2 -0
  34. package/lib/header/definition.d.ts +2 -0
  35. package/lib/icon/definition.d.ts +2 -0
  36. package/lib/layout/definition.d.ts +2 -0
  37. package/lib/menu/definition.d.ts +2 -0
  38. package/lib/menu/menu.d.ts +454 -4
  39. package/lib/menu-item/definition.d.ts +2 -0
  40. package/lib/nav/definition.d.ts +2 -0
  41. package/lib/nav-disclosure/definition.d.ts +2 -0
  42. package/lib/nav-item/definition.d.ts +2 -0
  43. package/lib/note/definition.d.ts +2 -0
  44. package/lib/number-field/definition.d.ts +2 -0
  45. package/lib/option/definition.d.ts +2 -0
  46. package/lib/pagination/definition.d.ts +2 -0
  47. package/lib/popup/definition.d.ts +0 -1
  48. package/lib/popup/popup.d.ts +25 -0
  49. package/lib/progress/definition.d.ts +2 -0
  50. package/lib/progress-ring/definition.d.ts +2 -0
  51. package/lib/radio/definition.d.ts +2 -0
  52. package/lib/radio-group/definition.d.ts +2 -0
  53. package/lib/range-slider/definition.d.ts +2 -0
  54. package/lib/rich-text-editor/definition.d.ts +2 -0
  55. package/lib/rich-text-editor/facades/prose-mirror-vivid.schema.d.ts +2 -0
  56. package/lib/rich-text-editor/facades/vivid-prose-mirror.facade.d.ts +7 -0
  57. package/lib/rich-text-editor/rich-text-editor.d.ts +13 -0
  58. package/lib/rich-text-editor/rich-text-editor.template.d.ts +4 -0
  59. package/lib/searchable-select/definition.d.ts +2 -0
  60. package/lib/select/definition.d.ts +2 -0
  61. package/lib/selectable-box/definition.d.ts +2 -0
  62. package/lib/side-drawer/definition.d.ts +2 -0
  63. package/lib/slider/definition.d.ts +2 -0
  64. package/lib/split-button/definition.d.ts +2 -0
  65. package/lib/switch/definition.d.ts +2 -0
  66. package/lib/tab/definition.d.ts +2 -0
  67. package/lib/tab-panel/definition.d.ts +2 -0
  68. package/lib/tabs/definition.d.ts +2 -0
  69. package/lib/tag/definition.d.ts +2 -0
  70. package/lib/tag-group/definition.d.ts +2 -0
  71. package/lib/text-area/definition.d.ts +2 -0
  72. package/lib/text-field/definition.d.ts +2 -0
  73. package/lib/time-picker/definition.d.ts +2 -0
  74. package/lib/time-picker/inline-time-picker/columns.d.ts +13 -0
  75. package/lib/time-picker/inline-time-picker/definition.d.ts +1 -0
  76. package/lib/time-picker/inline-time-picker/inline-time-picker.d.ts +15 -0
  77. package/lib/time-picker/inline-time-picker/inline-time-picker.template.d.ts +5 -0
  78. package/lib/time-picker/time-picker.template.d.ts +1 -2
  79. package/lib/toggletip/definition.d.ts +2 -0
  80. package/lib/toggletip/toggletip.d.ts +454 -4
  81. package/lib/tooltip/definition.d.ts +2 -0
  82. package/lib/tooltip/tooltip.d.ts +454 -4
  83. package/lib/tree-item/definition.d.ts +2 -0
  84. package/lib/tree-view/definition.d.ts +2 -0
  85. package/lib/video-player/definition.d.ts +2 -0
  86. package/menu/index.js +1 -1
  87. package/package.json +7 -2
  88. package/popup/index.cjs +1 -1
  89. package/popup/index.js +1 -1
  90. package/rich-text-editor/index.cjs +5 -0
  91. package/rich-text-editor/index.js +3 -0
  92. package/searchable-select/index.cjs +1 -1
  93. package/searchable-select/index.js +1 -1
  94. package/select/index.cjs +1 -1
  95. package/select/index.js +1 -1
  96. package/selectable-box/index.cjs +1 -1
  97. package/selectable-box/index.js +1 -1
  98. package/shared/affix.cjs +1 -3
  99. package/shared/affix.js +2 -4
  100. package/shared/anchored.cjs +12 -9
  101. package/shared/anchored.js +13 -10
  102. package/shared/definition.js +1 -1
  103. package/shared/definition10.cjs +1 -0
  104. package/shared/definition10.js +2 -2
  105. package/shared/definition11.cjs +1 -1
  106. package/shared/definition11.js +2 -2
  107. package/shared/definition12.cjs +1 -1
  108. package/shared/definition12.js +2 -2
  109. package/shared/definition13.cjs +15 -2
  110. package/shared/definition13.js +16 -4
  111. package/shared/definition14.cjs +3 -2
  112. package/shared/definition14.js +4 -4
  113. package/shared/definition15.cjs +1 -1
  114. package/shared/definition15.js +2 -2
  115. package/shared/definition16.cjs +18 -18
  116. package/shared/definition16.js +6 -6
  117. package/shared/definition17.cjs +3 -0
  118. package/shared/definition17.js +2 -2
  119. package/shared/definition18.cjs +7 -7
  120. package/shared/definition18.js +4 -4
  121. package/shared/definition19.cjs +15 -15
  122. package/shared/definition19.js +4 -4
  123. package/shared/definition2.cjs +1 -0
  124. package/shared/definition2.js +2 -2
  125. package/shared/definition20.cjs +5 -4
  126. package/shared/definition20.js +6 -6
  127. package/shared/definition21.cjs +3 -2
  128. package/shared/definition21.js +4 -4
  129. package/shared/definition22.js +1 -1
  130. package/shared/definition23.cjs +2 -1
  131. package/shared/definition23.js +3 -3
  132. package/shared/definition24.cjs +2 -1
  133. package/shared/definition24.js +3 -3
  134. package/shared/definition25.cjs +14 -14
  135. package/shared/definition25.js +3 -3
  136. package/shared/definition26.cjs +2 -1
  137. package/shared/definition26.js +3 -3
  138. package/shared/definition27.cjs +1 -1
  139. package/shared/definition27.js +2 -2
  140. package/shared/definition28.cjs +1 -0
  141. package/shared/definition28.js +2 -2
  142. package/shared/definition29.cjs +53 -61
  143. package/shared/definition29.js +54 -63
  144. package/shared/definition3.cjs +1 -0
  145. package/shared/definition3.js +2 -2
  146. package/shared/definition30.cjs +1 -0
  147. package/shared/definition30.js +2 -2
  148. package/shared/definition31.cjs +1 -0
  149. package/shared/definition31.js +2 -2
  150. package/shared/definition32.cjs +1 -0
  151. package/shared/definition32.js +2 -2
  152. package/shared/definition33.cjs +2 -1
  153. package/shared/definition33.js +3 -3
  154. package/shared/definition34.cjs +25 -25
  155. package/shared/definition34.js +5 -5
  156. package/shared/definition35.cjs +1 -1
  157. package/shared/definition35.js +2 -2
  158. package/shared/definition36.cjs +2 -1
  159. package/shared/definition36.js +3 -3
  160. package/shared/definition37.cjs +1 -1
  161. package/shared/definition37.js +2 -2
  162. package/shared/definition38.cjs +2 -1
  163. package/shared/definition38.js +3 -3
  164. package/shared/definition39.cjs +1 -0
  165. package/shared/definition39.js +2 -2
  166. package/shared/definition4.cjs +3 -2
  167. package/shared/definition4.js +4 -4
  168. package/shared/definition40.cjs +1 -1
  169. package/shared/definition40.js +2 -2
  170. package/shared/definition41.cjs +30 -30
  171. package/shared/definition41.js +5 -5
  172. package/shared/definition42.cjs +12538 -1052
  173. package/shared/definition42.js +12538 -1053
  174. package/shared/definition43.cjs +927 -701
  175. package/shared/definition43.js +929 -702
  176. package/shared/definition44.cjs +874 -104
  177. package/shared/definition44.js +874 -104
  178. package/shared/definition45.cjs +114 -90
  179. package/shared/definition45.js +113 -90
  180. package/shared/definition46.cjs +88 -464
  181. package/shared/definition46.js +87 -463
  182. package/shared/definition47.cjs +463 -109
  183. package/shared/definition47.js +462 -109
  184. package/shared/definition48.cjs +108 -106
  185. package/shared/definition48.js +107 -106
  186. package/shared/definition49.cjs +139 -13
  187. package/shared/definition49.js +138 -13
  188. package/shared/definition5.cjs +3 -2
  189. package/shared/definition5.js +5 -5
  190. package/shared/definition50.cjs +16 -114
  191. package/shared/definition50.js +15 -114
  192. package/shared/definition51.cjs +79 -485
  193. package/shared/definition51.js +78 -485
  194. package/shared/definition52.cjs +503 -23
  195. package/shared/definition52.js +502 -23
  196. package/shared/definition53.cjs +25 -123
  197. package/shared/definition53.js +24 -123
  198. package/shared/definition54.cjs +96 -254
  199. package/shared/definition54.js +96 -255
  200. package/shared/definition55.cjs +261 -59
  201. package/shared/definition55.js +262 -60
  202. package/shared/definition56.cjs +72 -861
  203. package/shared/definition56.js +72 -861
  204. package/shared/definition57.cjs +880 -107
  205. package/shared/definition57.js +880 -107
  206. package/shared/definition58.cjs +104 -88
  207. package/shared/definition58.js +104 -89
  208. package/shared/definition59.cjs +80 -165
  209. package/shared/definition59.js +79 -163
  210. package/shared/definition6.cjs +2 -1
  211. package/shared/definition6.js +3 -3
  212. package/shared/definition60.cjs +142 -228
  213. package/shared/definition60.js +141 -229
  214. package/shared/definition61.cjs +233 -70146
  215. package/shared/definition61.js +232 -70146
  216. package/shared/definition62.cjs +69381 -28
  217. package/shared/definition62.js +69380 -27
  218. package/shared/definition63.cjs +28 -2163
  219. package/shared/definition63.js +27 -2161
  220. package/shared/definition64.cjs +2195 -0
  221. package/shared/definition64.js +2190 -0
  222. package/shared/definition7.cjs +2 -1
  223. package/shared/definition7.js +3 -3
  224. package/shared/definition8.cjs +2 -1
  225. package/shared/definition8.js +3 -3
  226. package/shared/definition9.cjs +1 -1
  227. package/shared/definition9.js +2 -2
  228. package/shared/enums.cjs +8 -0
  229. package/shared/enums.js +8 -1
  230. package/shared/form-associated.js +1 -1
  231. package/shared/form-elements.cjs +7 -7
  232. package/shared/form-elements.js +8 -8
  233. package/shared/foundation/vivid-element/vivid-element.d.ts +1 -0
  234. package/shared/patterns/anchored.d.ts +891 -10
  235. package/shared/patterns/trapped-focus.d.ts +2 -0
  236. package/shared/presentationDate.cjs +5 -7
  237. package/shared/presentationDate.js +5 -7
  238. package/shared/slider.template.cjs +4 -4
  239. package/shared/slider.template.js +4 -4
  240. package/shared/text-anchor.template.cjs +2 -2
  241. package/shared/text-anchor.template.js +2 -2
  242. package/shared/text-field.cjs +555 -2
  243. package/shared/text-field.js +554 -2
  244. package/shared/text-field2.cjs +2 -572
  245. package/shared/text-field2.js +2 -571
  246. package/shared/trapped-focus.cjs +7 -1
  247. package/shared/trapped-focus.js +7 -1
  248. package/shared/utils/mixins.d.ts +3 -0
  249. package/shared/vivid-element.cjs +3 -0
  250. package/shared/vivid-element.js +4 -1
  251. package/side-drawer/index.cjs +1 -1
  252. package/side-drawer/index.js +1 -1
  253. package/slider/index.cjs +1 -1
  254. package/slider/index.js +1 -1
  255. package/split-button/index.cjs +1 -1
  256. package/split-button/index.js +1 -1
  257. package/styles/core/all.css +1 -1
  258. package/styles/core/theme.css +1 -1
  259. package/styles/core/typography.css +1 -1
  260. package/styles/tokens/theme-dark.css +4 -4
  261. package/styles/tokens/theme-light.css +4 -4
  262. package/styles/tokens/vivid-2-compat.css +1 -1
  263. package/switch/index.cjs +1 -1
  264. package/switch/index.js +1 -1
  265. package/tab/index.cjs +1 -1
  266. package/tab/index.js +1 -1
  267. package/tab-panel/index.cjs +1 -1
  268. package/tab-panel/index.js +1 -1
  269. package/tabs/index.cjs +1 -1
  270. package/tabs/index.js +1 -1
  271. package/tag/index.cjs +1 -1
  272. package/tag/index.js +1 -1
  273. package/tag-group/index.cjs +1 -1
  274. package/tag-group/index.js +1 -1
  275. package/text-anchor/index.js +1 -1
  276. package/text-area/index.cjs +1 -1
  277. package/text-area/index.js +1 -1
  278. package/text-field/index.cjs +1 -1
  279. package/text-field/index.js +1 -1
  280. package/time-picker/index.cjs +1 -1
  281. package/time-picker/index.js +1 -1
  282. package/toggletip/index.cjs +1 -1
  283. package/toggletip/index.js +1 -1
  284. package/tooltip/index.cjs +1 -1
  285. package/tooltip/index.js +1 -1
  286. package/tree-item/index.cjs +1 -1
  287. package/tree-item/index.js +1 -1
  288. package/tree-view/index.cjs +1 -1
  289. package/tree-view/index.js +1 -1
  290. package/video-player/index.cjs +1 -1
  291. package/video-player/index.js +1 -1
  292. package/vivid.api.json +22795 -1
@@ -1,12 +1,15 @@
1
- import { V as VividElement, D as DOM, a as attr, o as observable, h as html, d as defineVividComponent, f as createRegisterFunction } from './vivid-element.js';
2
- import { T as TreeItem, i as isTreeItemElement, t as treeItemDefinition } from './definition59.js';
3
- import { k as keyEnter, e as keyArrowUp, f as keyArrowDown, i as keyArrowRight, h as keyArrowLeft, d as keyEnd, g as keyHome } from './key-codes.js';
1
+ import { I as Icon, i as iconDefinition } from './definition27.js';
2
+ import { V as VividElement, a as attr, o as observable, h as html, d as createRegisterFunction, f as defineVividComponent } from './vivid-element.js';
3
+ import { a as applyMixins } from './apply-mixins.js';
4
+ import { b as AffixIcon, a as affixIconTemplateFactory, I as IconWrapper } from './affix.js';
4
5
  import { i as isHTMLElement } from './dom.js';
5
- import { r as ref } from './ref.js';
6
- import { s as slotted } from './slotted.js';
6
+ import { e as elements, s as slotted } from './slotted.js';
7
+ import { c as children } from './children.js';
7
8
  import { c as classNames } from './class-names.js';
9
+ import { w as when } from './when.js';
10
+ import { r as ref } from './ref.js';
8
11
 
9
- const styles = ".control{position:relative;display:flex;flex-direction:column;gap:4px}";
12
+ const styles = ":host(:focus-visible){outline:none}:host([disabled]){cursor:not-allowed}.control{--_appearance-color-text: var(--_connotation-color-firm);--_appearance-color-fill: transparent;--_appearance-color-outline: transparent}.control:where(.disabled,:disabled){--_appearance-color-text: var(--vvd-color-neutral-300);--_appearance-color-fill: transparent;--_appearance-color-outline: transparent}.control:where(.hover,:hover):where(:not(.disabled,:disabled,.readonly)){--_appearance-color-text: var(--_connotation-color-firm);--_appearance-color-fill: var(--_connotation-color-faint);--_appearance-color-outline: transparent}.control:where(.active,:active):where(:not(.disabled,:disabled)){--_appearance-color-text: var(--_connotation-color-firm);--_appearance-color-fill: var(--_connotation-color-soft);--_appearance-color-outline: transparent}.control:where(.selected):where(:not(.disabled,:disabled)){--_appearance-color-text: var(--_connotation-color-primary-text);--_appearance-color-fill: var(--_connotation-color-primary);--_appearance-color-outline: transparent}.control:where(.selected):where(.hover,:hover):where(:not(.disabled,:disabled,.readonly)){--_appearance-color-text: var(--_connotation-color-primary-text);--_appearance-color-fill: var(--_connotation-color-primary-increment);--_appearance-color-outline: transparent}.control{--_connotation-color-primary: var(--vvd-tree-item-accent-primary, var(--vvd-color-canvas-text));--_connotation-color-primary-text: var(--vvd-tree-item-accent-primary-text, var(--vvd-color-canvas));--_connotation-color-primary-increment: var(--vvd-tree-item-accent-primary-increment, var(--vvd-color-neutral-800));--_connotation-color-faint: var(--vvd-tree-item-accent-faint, var(--vvd-color-neutral-50));--_connotation-color-soft: var(--vvd-tree-item-accent-soft, var(--vvd-color-neutral-100));--_connotation-color-firm: var(--vvd-tree-item-accent-firm, var(--vvd-color-canvas-text))}.control{position:relative;display:inline-flex;box-sizing:border-box;align-items:center;border-radius:8px;background-color:var(--_appearance-color-fill);box-shadow:inset 0 0 0 1px var(--_appearance-color-outline);color:var(--_appearance-color-text);font:var(--vvd-typography-base);gap:12px;hyphens:auto;inline-size:100%;min-block-size:calc(1px*(40 + 4*clamp(-1,var(--vvd-size-density, 0),2)));padding-inline:16px;text-decoration:none;vertical-align:middle;word-break:break-word}@supports (user-select: none){.control{user-select:none}}.control:not(.disabled){cursor:pointer}.control.disabled{pointer-events:none}:host(:focus-visible) .control{box-shadow:inset 0 0 0 3px var(--focus-stroke-gap-color, currentColor);outline:2px solid var(--focus-stroke-color, var(--vvd-color-canvas-text));outline-offset:calc(-2px - var(--focus-inset, 0px))}:host(:focus-visible) .control:not(.selected){--focus-stroke-gap-color: transparent}.control .text{font:var(--vvd-typography-base)}.expandCollapseButton{display:flex;align-items:center;border-radius:8px;font-size:20px}.expandCollapseButton .expandCollapseIcon{margin:4px}.expandCollapseButton:hover{background-color:var(--vvd-color-neutral-100)}.selected .expandCollapseButton:hover{background-color:var(--vvd-color-neutral-700)}.items{display:flex;flex-direction:column;gap:4px;margin-block-start:4px;padding-inline-start:48px}slot[name=icon]{font-size:20px;line-height:1}.control:not(.disabled,.selected) slot[name=icon]{color:var(--vvd-color-neutral-600)}";
10
13
 
11
14
  var __defProp = Object.defineProperty;
12
15
  var __decorateClass = (decorators, target, key, kind) => {
@@ -17,277 +20,186 @@ var __decorateClass = (decorators, target, key, kind) => {
17
20
  if (result) __defProp(target, key, result);
18
21
  return result;
19
22
  };
20
- function getDisplayedNodes(rootNode, selector) {
21
- if (isHTMLElement(rootNode)) {
22
- const nodes = Array.from(
23
- rootNode.querySelectorAll(selector)
24
- );
25
- const visibleNodes = nodes.filter((node) => {
26
- if (node.parentElement instanceof TreeItem) {
27
- if (node.parentElement.getAttribute("aria-expanded") === "true")
28
- return true;
29
- } else {
30
- return true;
31
- }
32
- return false;
33
- });
34
- return visibleNodes;
35
- }
36
- return [];
23
+ function isTreeItemElement(el) {
24
+ return isHTMLElement(el) && el.getAttribute("role") === "treeitem";
37
25
  }
38
- class TreeView extends VividElement {
26
+ class TreeItem extends VividElement {
39
27
  constructor() {
40
28
  super(...arguments);
29
+ this.expanded = false;
30
+ this.selected = false;
31
+ this.disabled = false;
32
+ this.focusable = false;
41
33
  /**
42
- * The tree item that is designated to be in the tab queue.
34
+ * Whether the tree is nested
43
35
  *
44
- * @internal
36
+ * @public
45
37
  */
46
- this.currentFocused = null;
38
+ this.isNestedItem = () => {
39
+ return isTreeItemElement(this.parentElement);
40
+ };
47
41
  /**
48
- * Handle focus events
42
+ * Handle expand button click
49
43
  *
50
44
  * @internal
51
45
  */
52
- this.handleFocus = (e) => {
53
- if (this.slottedTreeItems.length > 0) {
54
- if (e.target === this) {
55
- if (this.currentFocused !== null) {
56
- TreeItem.focusItem(this.currentFocused);
57
- }
58
- return;
59
- }
60
- if (this.contains(e.target)) {
61
- this.setAttribute("tabindex", "-1");
62
- this.currentFocused = e.target;
63
- }
46
+ this.handleExpandCollapseButtonClick = (e) => {
47
+ if (!this.disabled && !e.defaultPrevented) {
48
+ this.expanded = !this.expanded;
64
49
  }
65
50
  };
66
51
  /**
67
- * Handle blur events
52
+ * Handle focus events
68
53
  *
69
54
  * @internal
70
55
  */
71
- this.handleBlur = (e) => {
72
- if (e.target instanceof HTMLElement && (e.relatedTarget === null || !this.contains(e.relatedTarget))) {
73
- this.setAttribute("tabindex", "0");
74
- }
56
+ this.handleFocus = (_e) => {
57
+ this.setAttribute("tabindex", "0");
75
58
  };
76
59
  /**
77
- * KeyDown handler
78
- *
79
- * @internal
80
- */
81
- this.handleKeyDown = (e) => {
82
- if (this.slottedTreeItems.length < 1) {
83
- return true;
84
- }
85
- if (!e.defaultPrevented) {
86
- const treeItems = this.getVisibleNodes();
87
- switch (e.key) {
88
- case keyHome:
89
- if (treeItems.length) {
90
- TreeItem.focusItem(treeItems[0]);
91
- }
92
- return;
93
- case keyEnd:
94
- if (treeItems.length) {
95
- TreeItem.focusItem(treeItems[treeItems.length - 1]);
96
- }
97
- return;
98
- case keyArrowLeft:
99
- if (e.target && this.isFocusableElement(e.target)) {
100
- const item = e.target;
101
- if (item instanceof TreeItem && item.childItemLength() > 0 && item.expanded) {
102
- item.expanded = false;
103
- } else if (item instanceof TreeItem && item.parentElement instanceof TreeItem) {
104
- TreeItem.focusItem(item.parentElement);
105
- }
106
- }
107
- return false;
108
- case keyArrowRight:
109
- if (e.target && this.isFocusableElement(e.target)) {
110
- const item = e.target;
111
- if (item instanceof TreeItem && item.childItemLength() > 0 && !item.expanded) {
112
- item.expanded = true;
113
- } else if (item instanceof TreeItem && item.childItemLength() > 0) {
114
- this.focusNextNode(1, e.target);
115
- }
116
- }
117
- return;
118
- case keyArrowDown:
119
- if (e.target && this.isFocusableElement(e.target)) {
120
- this.focusNextNode(1, e.target);
121
- }
122
- return;
123
- case keyArrowUp:
124
- if (e.target && this.isFocusableElement(e.target)) {
125
- this.focusNextNode(-1, e.target);
126
- }
127
- return;
128
- case keyEnter:
129
- this.handleClick(e);
130
- return;
131
- }
132
- }
133
- return true;
134
- };
135
- /**
136
- * Handles the selected-changed events bubbling up
137
- * from child tree items
60
+ * Handle blur events
138
61
  *
139
- * @internal
140
- */
141
- this.handleSelectedChange = (e) => {
142
- if (!e.defaultPrevented) {
143
- if (!(e.target instanceof Element) || !isTreeItemElement(e.target)) {
144
- return true;
145
- }
146
- const item = e.target;
147
- if (item.selected) {
148
- if (this.currentSelected && this.currentSelected !== item) {
149
- this.currentSelected.selected = false;
150
- }
151
- this.currentSelected = item;
152
- } else if (!item.selected && this.currentSelected === item) {
153
- this.currentSelected = null;
154
- }
155
- return;
156
- }
157
- };
158
- /**
159
- * Updates the tree view when slottedTreeItems changes
160
- */
161
- this.setItems = () => {
162
- const selectedItem = this.treeView.querySelector(
163
- "[aria-selected='true']"
164
- );
165
- this.currentSelected = selectedItem;
166
- if (this.currentFocused === null || !this.contains(this.currentFocused)) {
167
- this.currentFocused = this.getValidFocusableItem();
168
- }
169
- this.nested = this.checkForNestedItems();
170
- const treeItems = this.getVisibleNodes();
171
- treeItems.forEach((node) => {
172
- if (isTreeItemElement(node)) {
173
- node.nested = this.nested;
174
- }
175
- });
176
- };
177
- /**
178
- * check if the item is focusable
62
+ * @internal
179
63
  */
180
- this.isFocusableElement = (el) => {
181
- return isTreeItemElement(el);
182
- };
183
- this.isSelectedElement = (el) => {
184
- return el.selected;
64
+ this.handleBlur = (_e) => {
65
+ this.setAttribute("tabindex", "-1");
185
66
  };
186
67
  }
187
- slottedTreeItemsChanged() {
68
+ expandedChanged() {
188
69
  if (this.$fastController.isConnected) {
189
- this.setItems();
70
+ this.$emit("expanded-change", this);
190
71
  }
191
72
  }
192
- connectedCallback() {
193
- super.connectedCallback();
194
- this.setAttribute("tabindex", "0");
195
- DOM.queueUpdate(() => {
196
- this.setItems();
197
- });
198
- }
199
- /**
200
- * Handles click events bubbling up
201
- *
202
- * @internal
203
- */
204
- handleClick(e) {
205
- if (!e.defaultPrevented) {
206
- if (!(e.target instanceof Element) || !isTreeItemElement(e.target)) {
207
- return true;
208
- }
209
- const item = e.target;
210
- if (!item.disabled) {
211
- item.selected = !item.selected;
212
- }
213
- return;
73
+ selectedChanged() {
74
+ if (this.$fastController.isConnected) {
75
+ this.$emit("selected-change", this);
214
76
  }
215
77
  }
216
- /**
217
- * Move focus to a tree item based on its offset from the provided item
218
- */
219
- focusNextNode(delta, item) {
220
- const visibleNodes = this.getVisibleNodes();
221
- if (visibleNodes) {
222
- const focusItem = visibleNodes[visibleNodes.indexOf(item) + delta];
223
- if (isHTMLElement(focusItem)) {
224
- TreeItem.focusItem(focusItem);
225
- }
78
+ itemsChanged() {
79
+ if (this.$fastController.isConnected) {
80
+ this.items.forEach((node) => {
81
+ if (isTreeItemElement(node)) {
82
+ node.nested = true;
83
+ }
84
+ });
226
85
  }
227
86
  }
228
87
  /**
229
- * checks if there are any nested tree items
88
+ * Places document focus on a tree item
89
+ *
90
+ * @public
91
+ * @param el - the element to focus
230
92
  */
231
- getValidFocusableItem() {
232
- const treeItems = this.getVisibleNodes();
233
- let focusIndex = treeItems.findIndex(this.isSelectedElement);
234
- if (focusIndex === -1) {
235
- focusIndex = treeItems.findIndex(this.isFocusableElement);
236
- }
237
- if (focusIndex !== -1) {
238
- return treeItems[focusIndex];
239
- }
240
- return null;
93
+ static focusItem(el) {
94
+ el.focusable = true;
95
+ el.focus();
241
96
  }
242
97
  /**
243
- * checks if there are any nested tree items
98
+ * Gets number of children
99
+ *
100
+ * @internal
244
101
  */
245
- checkForNestedItems() {
246
- return this.slottedTreeItems.some((node) => {
247
- return isTreeItemElement(node) && node.querySelector("[role='treeitem']");
248
- });
249
- }
250
- getVisibleNodes() {
251
- return getDisplayedNodes(this, "[role='treeitem']");
102
+ childItemLength() {
103
+ const treeChildren = this.childItems.filter(
104
+ (item) => {
105
+ return isTreeItemElement(item);
106
+ }
107
+ );
108
+ return treeChildren.length;
252
109
  }
253
110
  }
111
+ __decorateClass([
112
+ attr
113
+ ], TreeItem.prototype, "text");
114
+ __decorateClass([
115
+ attr({ mode: "boolean" })
116
+ ], TreeItem.prototype, "expanded");
117
+ __decorateClass([
118
+ attr({
119
+ mode: "boolean"
120
+ })
121
+ ], TreeItem.prototype, "selected");
122
+ __decorateClass([
123
+ attr({ mode: "boolean" })
124
+ ], TreeItem.prototype, "disabled");
125
+ __decorateClass([
126
+ observable
127
+ ], TreeItem.prototype, "focusable");
254
128
  // @ts-expect-error Type is incorrectly non-optional
255
129
  __decorateClass([
256
- attr({ attribute: "render-collapsed-nodes" })
257
- ], TreeView.prototype, "renderCollapsedNodes");
130
+ observable
131
+ ], TreeItem.prototype, "childItems");
132
+ __decorateClass([
133
+ observable
134
+ ], TreeItem.prototype, "items");
258
135
  // @ts-expect-error Type is incorrectly non-optional
259
136
  __decorateClass([
260
137
  observable
261
- ], TreeView.prototype, "currentSelected");
138
+ ], TreeItem.prototype, "nested");
262
139
  // @ts-expect-error Type is incorrectly non-optional
263
140
  __decorateClass([
264
141
  observable
265
- ], TreeView.prototype, "slottedTreeItems");
142
+ ], TreeItem.prototype, "renderCollapsedChildren");
143
+ applyMixins(TreeItem, AffixIcon);
266
144
 
267
- const getClasses = (_) => classNames("control");
268
- const TreeViewTemplate = html` <template
269
- role="tree"
270
- ${ref("treeView")}
271
- @keydown="${(x, c) => x.handleKeyDown(c.event)}"
272
- @focusin="${(x, c) => x.handleFocus(c.event)}"
273
- @focusout="${(x, c) => x.handleBlur(c.event)}"
274
- @click="${(x, c) => x.handleClick(c.event)}"
275
- @selected-change="${(x, c) => x.handleSelectedChange(c.event)}"
276
- >
277
- <div class="${getClasses}">
278
- <slot ${slotted("slottedTreeItems")}></slot>
279
- </div>
280
- </template>`;
145
+ const getClasses = ({ disabled, selected }) => classNames(
146
+ "control",
147
+ ["disabled", disabled],
148
+ ["selected", Boolean(selected)]
149
+ );
150
+ const expandCollapseButton = (context) => {
151
+ const iconTag = context.tagFor(Icon);
152
+ return html`
153
+ <div aria-hidden="true"
154
+ class="expandCollapseButton"
155
+ @click="${(x, c) => x.handleExpandCollapseButtonClick(c.event)}"
156
+ ${ref("expandCollapseButton")}
157
+ >
158
+ <${iconTag} class="expandCollapseIcon" name="${(x) => x.expanded ? "chevron-down-line" : "chevron-right-line"}"></${iconTag}>
159
+ </div>`;
160
+ };
161
+ const TreeItemTemplate = (context) => {
162
+ const affixIconTemplate = affixIconTemplateFactory(context);
163
+ return html` <template
164
+ role="treeitem"
165
+ slot="${(x) => x.isNestedItem() ? "item" : void 0}"
166
+ tabindex="-1"
167
+ aria-expanded="${(x) => x.childItems && x.childItems.length > 0 ? x.expanded : void 0}"
168
+ aria-selected="${(x) => x.selected}"
169
+ aria-disabled="${(x) => x.disabled}"
170
+ @focusin="${(x, c) => x.handleFocus(c.event)}"
171
+ @focusout="${(x, c) => x.handleBlur(c.event)}"
172
+ ${children({
173
+ property: "childItems",
174
+ filter: elements(context.tagFor(TreeItem))
175
+ })}
176
+ >
177
+ <div class="${getClasses}">
178
+ ${when(
179
+ (x) => x.childItems && x.childItems.length > 0,
180
+ expandCollapseButton(context)
181
+ )}
182
+ ${(x) => affixIconTemplate(x.icon, IconWrapper.Slot)}
183
+ ${(x) => x.text}
184
+ </div>
185
+ ${when(
186
+ (x) => x.childItems && x.childItems.length > 0 && x.expanded,
187
+ html` <div role="group" class="items">
188
+ <slot name="item" ${slotted("items")}></slot>
189
+ </div>`
190
+ )}
191
+ </template>`;
192
+ };
281
193
 
282
- const treeViewDefinition = defineVividComponent(
283
- "tree-view",
284
- TreeView,
285
- TreeViewTemplate,
286
- [treeItemDefinition],
194
+ const treeItemDefinition = defineVividComponent(
195
+ "tree-item",
196
+ TreeItem,
197
+ TreeItemTemplate,
198
+ [iconDefinition],
287
199
  {
288
200
  styles
289
201
  }
290
202
  );
291
- const registerTreeView = createRegisterFunction(treeViewDefinition);
203
+ const registerTreeItem = createRegisterFunction(treeItemDefinition);
292
204
 
293
- export { registerTreeView as r, treeViewDefinition as t };
205
+ export { TreeItem as T, isTreeItemElement as i, registerTreeItem as r, treeItemDefinition as t };