@vonage/vivid 3.40.0 → 3.42.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 (161) hide show
  1. package/accordion/index.js +2 -2
  2. package/accordion-item/index.js +2 -2
  3. package/alert/index.js +6 -5
  4. package/audio-player/index.js +33 -0
  5. package/avatar/index.js +2 -2
  6. package/badge/index.js +2 -2
  7. package/banner/index.js +8 -5
  8. package/breadcrumb/index.js +1 -1
  9. package/breadcrumb-item/index.js +3 -3
  10. package/button/index.js +4 -4
  11. package/calendar/index.js +1 -1
  12. package/calendar-event/index.js +1 -1
  13. package/card/index.js +4 -3
  14. package/checkbox/index.js +3 -3
  15. package/combobox/index.js +8 -8
  16. package/custom-elements.json +438 -41
  17. package/data-grid/index.js +2 -2
  18. package/date-picker/index.js +9 -9
  19. package/date-range-picker/index.js +8 -8
  20. package/dialog/index.js +6 -6
  21. package/divider/index.js +1 -1
  22. package/elevation/index.js +1 -1
  23. package/empty-state/index.js +2 -2
  24. package/fab/index.js +3 -3
  25. package/file-picker/index.js +5 -5
  26. package/focus/index.js +1 -1
  27. package/header/index.js +2 -2
  28. package/icon/index.js +1 -1
  29. package/index.js +57 -56
  30. package/layout/index.js +1 -1
  31. package/lib/alert/alert.d.ts +3 -1
  32. package/lib/alert/locale.d.ts +3 -0
  33. package/lib/audio-player/audio-player.d.ts +17 -0
  34. package/lib/audio-player/audio-player.template.d.ts +4 -0
  35. package/lib/audio-player/definition.d.ts +4 -0
  36. package/lib/audio-player/locale.d.ts +5 -0
  37. package/lib/banner/banner.d.ts +3 -1
  38. package/lib/banner/locale.d.ts +3 -0
  39. package/lib/card/card.d.ts +3 -0
  40. package/lib/card/card.template.d.ts +1 -1
  41. package/lib/card/definition.d.ts +1 -0
  42. package/lib/checkbox/checkbox.d.ts +1 -0
  43. package/lib/components.d.ts +1 -0
  44. package/lib/enums.d.ts +2 -1
  45. package/lib/selectable-box/selectable-box.d.ts +2 -2
  46. package/lib/split-button/locale.d.ts +3 -0
  47. package/lib/split-button/split-button.d.ts +4 -2
  48. package/listbox/index.js +4 -4
  49. package/locales/en-GB.js +14 -0
  50. package/locales/en-US.js +14 -0
  51. package/locales/ja-JP.js +14 -0
  52. package/locales/zh-CN.js +14 -0
  53. package/menu/index.js +8 -8
  54. package/menu-item/index.js +3 -3
  55. package/nav/index.js +1 -1
  56. package/nav-disclosure/index.js +3 -3
  57. package/nav-item/index.js +3 -3
  58. package/note/index.js +2 -2
  59. package/number-field/index.js +6 -6
  60. package/option/index.js +3 -3
  61. package/package.json +1 -1
  62. package/pagination/index.js +5 -5
  63. package/popup/index.js +6 -6
  64. package/progress/index.js +1 -1
  65. package/progress-ring/index.js +1 -1
  66. package/radio/index.js +2 -2
  67. package/radio-group/index.js +2 -2
  68. package/select/index.js +8 -8
  69. package/selectable-box/index.js +5 -5
  70. package/shared/definition.js +3 -3
  71. package/shared/definition10.js +90 -159
  72. package/shared/definition11.js +151 -29
  73. package/shared/definition12.js +37 -766
  74. package/shared/definition13.js +747 -106
  75. package/shared/definition14.js +121 -198
  76. package/shared/definition15.js +167 -664
  77. package/shared/definition16.js +576 -1137
  78. package/shared/definition17.js +1278 -143
  79. package/shared/definition18.js +68 -306
  80. package/shared/definition19.js +359 -217
  81. package/shared/definition2.js +1 -1
  82. package/shared/definition20.js +259 -67
  83. package/shared/definition21.js +66 -58
  84. package/shared/definition22.js +43 -84
  85. package/shared/definition23.js +76 -2353
  86. package/shared/definition24.js +2362 -45
  87. package/shared/definition25.js +63 -27
  88. package/shared/definition26.js +24 -51
  89. package/shared/definition27.js +36 -822
  90. package/shared/definition28.js +837 -49
  91. package/shared/definition29.js +52 -89
  92. package/shared/definition3.js +1 -1
  93. package/shared/definition30.js +88 -24
  94. package/shared/definition31.js +25 -12
  95. package/shared/definition32.js +12 -52
  96. package/shared/definition33.js +28 -502
  97. package/shared/definition34.js +442 -197
  98. package/shared/definition35.js +260 -186
  99. package/shared/definition36.js +186 -75
  100. package/shared/definition37.js +70 -54
  101. package/shared/definition38.js +65 -421
  102. package/shared/definition39.js +437 -38
  103. package/shared/definition4.js +43 -16
  104. package/shared/definition40.js +32 -680
  105. package/shared/definition41.js +654 -105
  106. package/shared/definition42.js +117 -78
  107. package/shared/definition43.js +74 -567
  108. package/shared/definition44.js +567 -98
  109. package/shared/definition45.js +110 -135
  110. package/shared/definition46.js +153 -17
  111. package/shared/definition47.js +16 -79
  112. package/shared/definition48.js +53 -475
  113. package/shared/definition49.js +502 -25
  114. package/shared/definition5.js +160 -44
  115. package/shared/definition50.js +22 -121
  116. package/shared/definition51.js +113 -271
  117. package/shared/definition52.js +249 -243
  118. package/shared/definition53.js +270 -109
  119. package/shared/definition54.js +84 -74
  120. package/shared/definition55.js +114 -69
  121. package/shared/definition56.js +81 -292
  122. package/shared/definition57.js +302 -13
  123. package/shared/definition58.js +11 -41
  124. package/shared/definition59.js +20 -154
  125. package/shared/definition6.js +43 -33
  126. package/shared/definition60.js +181 -0
  127. package/shared/definition7.js +39 -106
  128. package/shared/definition8.js +122 -38
  129. package/shared/definition9.js +56 -89
  130. package/shared/enums.js +1 -0
  131. package/shared/icon.js +2 -2
  132. package/shared/index.js +1 -1
  133. package/shared/index2.js +1 -1
  134. package/shared/listbox.js +1 -1
  135. package/shared/localization/Locale.d.ts +8 -0
  136. package/shared/patterns/form-elements/form-elements.d.ts +6 -6
  137. package/shared/presentationDate.js +10 -8
  138. package/shared/text-field.js +1 -1
  139. package/side-drawer/index.js +1 -1
  140. package/slider/index.js +3 -3
  141. package/split-button/index.js +6 -3
  142. package/style.css +329 -242
  143. package/styles/core/all.css +31 -25
  144. package/styles/core/theme.css +1 -1
  145. package/styles/core/typography.css +31 -25
  146. package/styles/tokens/theme-dark.css +4 -4
  147. package/styles/tokens/theme-light.css +4 -4
  148. package/styles/tokens/vivid-2-compat.css +1 -1
  149. package/switch/index.js +3 -3
  150. package/tab/index.js +3 -3
  151. package/tab-panel/index.js +1 -1
  152. package/tabs/index.js +5 -5
  153. package/tag/index.js +3 -3
  154. package/tag-group/index.js +1 -1
  155. package/text-area/index.js +3 -3
  156. package/text-field/index.js +3 -3
  157. package/toggletip/index.js +7 -7
  158. package/tooltip/index.js +7 -7
  159. package/tree-item/index.js +3 -3
  160. package/tree-view/index.js +1 -1
  161. package/vivid.api.json +270 -1
@@ -1,18 +1,8 @@
1
- import { a as attr, h as html, r as registerFactory } from './index.js';
2
- import { a as iconRegistries } from './definition25.js';
3
- import { f as focusRegistries } from './definition57.js';
4
- import { A as AffixIcon, a as affixIconTemplateFactory, I as IconWrapper } from './affix.js';
5
- import { T as TreeItem$1 } from './tree-item.js';
6
- import { a as applyMixins } from './apply-mixins.js';
7
- import { I as Icon } from './icon.js';
8
- import { f as focusTemplateFactory } from './focus2.js';
9
- import { e as elements, s as slotted } from './slotted.js';
10
- import { c as children } from './children.js';
11
- import { w as when } from './when.js';
1
+ import { a as attr, F as FoundationElement, h as html, r as registerFactory } from './index.js';
2
+ import { P as Popup, p as popupRegistries } from './definition60.js';
12
3
  import { c as classNames } from './class-names.js';
13
- import { r as ref } from './ref.js';
14
4
 
15
- const styles = "/**\n * Do not edit directly\n * Generated on Wed, 01 Nov 2023 12:16:28 GMT\n */\n@supports selector(:focus-visible) {\n :host(:focus-visible) {\n outline: none;\n }\n}\n:host([disabled]) {\n cursor: not-allowed;\n}\n\n.control {\n position: relative;\n display: inline-flex;\n box-sizing: border-box;\n align-items: center;\n background-color: var(--_appearance-color-fill);\n border-radius: 6px;\n box-shadow: inset 0 0 0 1px var(--_appearance-color-outline);\n color: var(--_appearance-color-text);\n font: var(--vvd-typography-base);\n gap: 12px;\n hyphens: auto;\n inline-size: 100%;\n min-block-size: calc(1px * (40 + 4 * clamp(-1, var(--vvd-size-density, 0), 2)));\n padding-inline: 16px;\n text-decoration: none;\n vertical-align: middle;\n word-break: break-word;\n}\n.control {\n --_appearance-color-text: var(--_connotation-color-primary);\n --_appearance-color-fill: transparent;\n --_appearance-color-outline: transparent;\n}\n.control:where(:disabled, .disabled) {\n --_appearance-color-text: var(--vvd-color-neutral-300);\n --_appearance-color-fill: transparent;\n --_appearance-color-outline: transparent;\n}\n.control:where(:hover, .hover):where(:not(:disabled, .disabled, .readonly)) {\n --_appearance-color-text: var(--_connotation-color-primary);\n --_appearance-color-fill: var(--_connotation-color-faint);\n --_appearance-color-outline: transparent;\n}\n.control:where(:active, .active):where(:not(:disabled, .disabled)) {\n --_appearance-color-text: var(--_connotation-color-primary);\n --_appearance-color-fill: var(--_connotation-color-soft);\n --_appearance-color-outline: transparent;\n}\n.control:where(.selected, [aria-current]):where(:not(:disabled, .disabled, :hover, .hover)) {\n --_appearance-color-text: var(--_connotation-color-primary-text);\n --_appearance-color-fill: var(--_connotation-color-primary);\n --_appearance-color-outline: transparent;\n}\n.control:where(.selected, [aria-current]):where(:hover, .hover) {\n --_appearance-color-text: var(--_connotation-color-primary-text);\n --_appearance-color-fill: var(--_connotation-color-primary-increment);\n --_appearance-color-outline: transparent;\n}\n.control {\n /* @cssprop [--vvd-tree-item-accent-primary=var(--vvd-color-canvas-text)] */\n --_connotation-color-primary: var(--vvd-tree-item-accent-primary, var(--vvd-color-canvas-text));\n /* @cssprop [--vvd-tree-item-accent-primary-text=var(--vvd-color-canvas)] */\n --_connotation-color-primary-text: var(--vvd-tree-item-accent-primary-text, var(--vvd-color-canvas));\n /* @cssprop [--vvd-tree-item-accent-primary-increment=var(--vvd-color-neutral-800)] */\n --_connotation-color-primary-increment: var(--vvd-tree-item-accent-primary-increment, var(--vvd-color-neutral-800));\n /* @cssprop [--vvd-tree-item-accent-faint=var(--vvd-color-neutral-50)] */\n --_connotation-color-faint: var(--vvd-tree-item-accent-faint, var(--vvd-color-neutral-50));\n /* @cssprop [--vvd-tree-item-accent-soft=var(--vvd-color-neutral-100)] */\n --_connotation-color-soft: var(--vvd-tree-item-accent-soft, var(--vvd-color-neutral-100));\n}\n@supports selector(:focus-visible) {\n .control:focus-visible {\n outline: none;\n }\n}\n@supports (user-select: none) {\n .control {\n user-select: none;\n }\n}\n.control:not(.disabled) {\n cursor: pointer;\n}\n.control.disabled {\n pointer-events: none;\n}\n.control .text {\n font: var(--vvd-typography-base);\n}\n\n.expandCollapseButton {\n display: flex;\n align-items: center;\n border-radius: 6px;\n font-size: 20px;\n}\n.expandCollapseButton .expandCollapseIcon {\n margin: 4px;\n}\n.expandCollapseButton:hover {\n background-color: var(--vvd-color-neutral-100);\n}\n.selected .expandCollapseButton:hover {\n background-color: var(--vvd-color-neutral-700);\n}\n\n.items {\n display: flex;\n flex-direction: column;\n gap: 4px;\n margin-block: 4px;\n padding-inline-start: 48px;\n}\n\n:host(:not(:focus-visible)) .focus-indicator {\n display: none;\n}\n\nslot[name=icon] {\n font-size: 20px;\n line-height: 1;\n}\n.control:not(.disabled, .selected) slot[name=icon] {\n color: var(--vvd-color-neutral-600);\n}";
5
+ const styles = "/**\n * Do not edit directly\n * Generated on Thu, 30 Nov 2023 11:42:28 GMT\n */\n.control {\n pointer-events: none;\n}\n\n.tooltip {\n width: var(--tooltip-inline-size, auto);\n}\n.tooltip-text {\n padding: 8px 12px;\n color: var(--vvd-color-canvas-text);\n font: var(--vvd-typography-base-bold);\n}";
16
6
 
17
7
  var __defProp = Object.defineProperty;
18
8
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -25,71 +15,126 @@ var __decorateClass = (decorators, target, key, kind) => {
25
15
  __defProp(target, key, result);
26
16
  return result;
27
17
  };
28
- class TreeItem extends TreeItem$1 {
18
+ class Tooltip extends FoundationElement {
19
+ constructor() {
20
+ super(...arguments);
21
+ this.#anchorEl = null;
22
+ this.open = false;
23
+ this.#observeMissingAnchor = (anchorId) => {
24
+ this.#observer = new MutationObserver(() => {
25
+ const anchor = document.getElementById(anchorId);
26
+ if (anchor) {
27
+ this.#anchorEl = anchor;
28
+ this.#anchorUpdated();
29
+ this.#observer.disconnect();
30
+ this.#observer = void 0;
31
+ }
32
+ });
33
+ this.#observer.observe(document.body, { childList: true, subtree: true });
34
+ };
35
+ this.#show = () => {
36
+ this.open = true;
37
+ };
38
+ this.#hide = () => {
39
+ this.open = false;
40
+ };
41
+ this.#closeOnEscape = (e) => {
42
+ if (e.key === "Escape")
43
+ this.#hide();
44
+ };
45
+ }
46
+ #anchorEl;
47
+ #observer;
48
+ anchorChanged(_, newValue) {
49
+ if (this.#anchorEl)
50
+ this.#removeEventListener();
51
+ this.#observer?.disconnect();
52
+ this.#anchorEl = newValue instanceof HTMLElement ? newValue : document.getElementById(newValue);
53
+ if (this.#anchorEl) {
54
+ this.#anchorUpdated();
55
+ } else {
56
+ this.#observeMissingAnchor(newValue);
57
+ }
58
+ }
59
+ #observeMissingAnchor;
60
+ disconnectedCallback() {
61
+ super.disconnectedCallback();
62
+ this.#removeEventListener();
63
+ this.#observer?.disconnect();
64
+ document.removeEventListener("keydown", this.#closeOnEscape);
65
+ }
66
+ #anchorUpdated() {
67
+ this.#removeEventListener();
68
+ this.#addEventListener();
69
+ }
70
+ #addEventListener() {
71
+ if (this.#anchorEl) {
72
+ this.#anchorEl.addEventListener("mouseover", this.#show);
73
+ this.#anchorEl.addEventListener("mouseout", this.#hide);
74
+ this.#anchorEl.addEventListener("focusin", this.#show);
75
+ this.#anchorEl.addEventListener("focusout", this.#hide);
76
+ }
77
+ }
78
+ #removeEventListener() {
79
+ this.#anchorEl?.removeEventListener("mouseover", this.#show);
80
+ this.#anchorEl?.removeEventListener("mouseout", this.#hide);
81
+ this.#anchorEl?.removeEventListener("focusin", this.#show);
82
+ this.#anchorEl?.removeEventListener("focusout", this.#hide);
83
+ }
84
+ #show;
85
+ #hide;
86
+ #closeOnEscape;
87
+ openChanged(_, newValue) {
88
+ if (_ === void 0)
89
+ return;
90
+ if (newValue) {
91
+ document.addEventListener("keydown", this.#closeOnEscape);
92
+ } else {
93
+ document.removeEventListener("keydown", this.#closeOnEscape);
94
+ }
95
+ }
29
96
  }
30
97
  __decorateClass([
31
98
  attr
32
- ], TreeItem.prototype, "text", 2);
33
- applyMixins(TreeItem, AffixIcon);
99
+ ], Tooltip.prototype, "text", 2);
100
+ __decorateClass([
101
+ attr({ mode: "fromView" })
102
+ ], Tooltip.prototype, "placement", 2);
103
+ __decorateClass([
104
+ attr({ mode: "boolean" })
105
+ ], Tooltip.prototype, "open", 2);
106
+ __decorateClass([
107
+ attr({ mode: "fromView" })
108
+ ], Tooltip.prototype, "anchor", 2);
34
109
 
35
110
  const getClasses = ({
36
- disabled,
37
- selected
111
+ open
38
112
  }) => classNames(
39
113
  "control",
40
- ["disabled", disabled],
41
- ["selected", Boolean(selected)]
114
+ ["open", Boolean(open)]
42
115
  );
43
- const expandCollapseButton = (context) => {
44
- const iconTag = context.tagFor(Icon);
116
+ const TooltipTemplate = (context) => {
117
+ const popupTag = context.tagFor(Popup);
45
118
  return html`
46
- <div aria-hidden="true"
47
- class="expandCollapseButton"
48
- @click="${(x, c) => x.handleExpandCollapseButtonClick(c.event)}"
49
- ${ref("expandCollapseButton")}
50
- >
51
- <${iconTag} class="expandCollapseIcon" name="${(x) => x.expanded ? "chevron-down-line" : "chevron-right-line"}"></${iconTag}>
52
- </div>`;
53
- };
54
- const TreeItemTemplate = (context) => {
55
- const affixIconTemplate = affixIconTemplateFactory(context);
56
- const focusTemplate = focusTemplateFactory(context);
57
- return html`
58
- <template
59
- role="treeitem"
60
- slot="${(x) => x.isNestedItem() ? "item" : void 0}"
61
- tabindex="-1"
62
- aria-expanded="${(x) => x.childItems && x.childItems.length > 0 ? x.expanded : void 0}"
63
- aria-selected="${(x) => x.selected}"
64
- aria-disabled="${(x) => x.disabled}"
65
- @focusin="${(x, c) => x.handleFocus(c.event)}"
66
- @focusout="${(x, c) => x.handleBlur(c.event)}"
67
- ${children({ property: "childItems", filter: elements(context.tagFor(TreeItem)) })}
68
- >
69
- <div class="${getClasses}">
70
- ${() => focusTemplate}
71
- ${when((x) => x.childItems && x.childItems.length > 0, expandCollapseButton(context))}
72
- ${(x) => affixIconTemplate(x.icon, IconWrapper.Slot)}
73
- ${(x) => x.text}
74
- </div>
75
- ${when(
76
- (x) => x.childItems && x.childItems.length > 0 && x.expanded,
77
- html`
78
- <div role="group" class="items">
79
- <slot name="item" ${slotted("items")}></slot>
80
- </div>`
81
- )}
82
- </template>`;
119
+ <${popupTag} class="${getClasses}" arrow alternate
120
+ :placement=${(x) => x.placement}
121
+ :anchor="${(x) => x.anchor}"
122
+ :open=${(x) => x.open}
123
+ exportparts="vvd-theme-alternate">
124
+ <div class="tooltip" role="tooltip">
125
+ <header part="vvd-theme-alternate" class="tooltip-header">
126
+ <div class="tooltip-text">${(x) => x.text}</div>
127
+ </header>
128
+ </div>
129
+ </${popupTag}>`;
83
130
  };
84
131
 
85
- const treeItemDefinition = TreeItem.compose(
86
- {
87
- baseName: "tree-item",
88
- template: TreeItemTemplate,
89
- styles
90
- }
91
- );
92
- const treeItemRegistries = [treeItemDefinition(), ...iconRegistries, ...focusRegistries];
93
- const registerTreeItem = registerFactory(treeItemRegistries);
132
+ const tooltipDefinition = Tooltip.compose({
133
+ baseName: "tooltip",
134
+ template: TooltipTemplate,
135
+ styles
136
+ });
137
+ const tooltipRegistries = [tooltipDefinition(), ...popupRegistries];
138
+ const registerTooltip = registerFactory(tooltipRegistries);
94
139
 
95
- export { treeItemRegistries as a, registerTreeItem as r, treeItemDefinition as t };
140
+ export { tooltipRegistries as a, registerTooltip as r, tooltipDefinition as t };
@@ -1,306 +1,95 @@
1
- import { F as FoundationElement, D as DOM, _ as __decorate, a as attr, o as observable, h as html, r as registerFactory } from './index.js';
2
- import { T as TreeItem$1, i as isTreeItemElement } from './tree-item.js';
3
- import { i as isHTMLElement, g as getDisplayedNodes } from './dom.js';
4
- import { k as keyEnter, e as keyArrowUp, f as keyArrowDown, h as keyArrowRight, i as keyArrowLeft, d as keyEnd, g as keyHome } from './key-codes.js';
5
- import { r as ref } from './ref.js';
6
- import { s as slotted } from './slotted.js';
1
+ import { a as attr, h as html, r as registerFactory } from './index.js';
2
+ import { a as iconRegistries } from './definition26.js';
3
+ import { f as focusRegistries } from './definition58.js';
4
+ import { A as AffixIcon, a as affixIconTemplateFactory, I as IconWrapper } from './affix.js';
5
+ import { T as TreeItem$1 } from './tree-item.js';
6
+ import { a as applyMixins } from './apply-mixins.js';
7
+ import { I as Icon } from './icon.js';
8
+ import { f as focusTemplateFactory } from './focus2.js';
9
+ import { e as elements, s as slotted } from './slotted.js';
10
+ import { c as children } from './children.js';
11
+ import { w as when } from './when.js';
7
12
  import { c as classNames } from './class-names.js';
13
+ import { r as ref } from './ref.js';
8
14
 
9
- /**
10
- * A Tree view Custom HTML Element.
11
- * Implements the {@link https://w3c.github.io/aria-practices/#TreeView | ARIA TreeView }.
12
- *
13
- * @slot - The default slot for tree items
14
- *
15
- * @public
16
- */
17
- let TreeView$1 = class TreeView extends FoundationElement {
18
- constructor() {
19
- super(...arguments);
20
- /**
21
- * The tree item that is designated to be in the tab queue.
22
- *
23
- * @internal
24
- */
25
- this.currentFocused = null;
26
- /**
27
- * Handle focus events
28
- *
29
- * @internal
30
- */
31
- this.handleFocus = (e) => {
32
- if (this.slottedTreeItems.length < 1) {
33
- // no child items, nothing to do
34
- return;
35
- }
36
- if (e.target === this) {
37
- if (this.currentFocused === null) {
38
- this.currentFocused = this.getValidFocusableItem();
39
- }
40
- if (this.currentFocused !== null) {
41
- TreeItem$1.focusItem(this.currentFocused);
42
- }
43
- return;
44
- }
45
- if (this.contains(e.target)) {
46
- this.setAttribute("tabindex", "-1");
47
- this.currentFocused = e.target;
48
- }
49
- };
50
- /**
51
- * Handle blur events
52
- *
53
- * @internal
54
- */
55
- this.handleBlur = (e) => {
56
- if (e.target instanceof HTMLElement &&
57
- (e.relatedTarget === null || !this.contains(e.relatedTarget))) {
58
- this.setAttribute("tabindex", "0");
59
- }
60
- };
61
- /**
62
- * KeyDown handler
63
- *
64
- * @internal
65
- */
66
- this.handleKeyDown = (e) => {
67
- if (e.defaultPrevented) {
68
- return;
69
- }
70
- if (this.slottedTreeItems.length < 1) {
71
- return true;
72
- }
73
- const treeItems = this.getVisibleNodes();
74
- switch (e.key) {
75
- case keyHome:
76
- if (treeItems.length) {
77
- TreeItem$1.focusItem(treeItems[0]);
78
- }
79
- return;
80
- case keyEnd:
81
- if (treeItems.length) {
82
- TreeItem$1.focusItem(treeItems[treeItems.length - 1]);
83
- }
84
- return;
85
- case keyArrowLeft:
86
- if (e.target && this.isFocusableElement(e.target)) {
87
- const item = e.target;
88
- if (item instanceof TreeItem$1 &&
89
- item.childItemLength() > 0 &&
90
- item.expanded) {
91
- item.expanded = false;
92
- }
93
- else if (item instanceof TreeItem$1 &&
94
- item.parentElement instanceof TreeItem$1) {
95
- TreeItem$1.focusItem(item.parentElement);
96
- }
97
- }
98
- return false;
99
- case keyArrowRight:
100
- if (e.target && this.isFocusableElement(e.target)) {
101
- const item = e.target;
102
- if (item instanceof TreeItem$1 &&
103
- item.childItemLength() > 0 &&
104
- !item.expanded) {
105
- item.expanded = true;
106
- }
107
- else if (item instanceof TreeItem$1 && item.childItemLength() > 0) {
108
- this.focusNextNode(1, e.target);
109
- }
110
- }
111
- return;
112
- case keyArrowDown:
113
- if (e.target && this.isFocusableElement(e.target)) {
114
- this.focusNextNode(1, e.target);
115
- }
116
- return;
117
- case keyArrowUp:
118
- if (e.target && this.isFocusableElement(e.target)) {
119
- this.focusNextNode(-1, e.target);
120
- }
121
- return;
122
- case keyEnter:
123
- // In single-select trees where selection does not follow focus (see note below),
124
- // the default action is typically to select the focused node.
125
- this.handleClick(e);
126
- return;
127
- }
128
- // don't prevent default if we took no action
129
- return true;
130
- };
131
- /**
132
- * Handles the selected-changed events bubbling up
133
- * from child tree items
134
- *
135
- * @internal
136
- */
137
- this.handleSelectedChange = (e) => {
138
- if (e.defaultPrevented) {
139
- return;
140
- }
141
- if (!(e.target instanceof Element) || !isTreeItemElement(e.target)) {
142
- return true;
143
- }
144
- const item = e.target;
145
- if (item.selected) {
146
- if (this.currentSelected && this.currentSelected !== item) {
147
- this.currentSelected.selected = false;
148
- }
149
- // new selected item
150
- this.currentSelected = item;
151
- }
152
- else if (!item.selected && this.currentSelected === item) {
153
- // selected item deselected
154
- this.currentSelected = null;
155
- }
156
- return;
157
- };
158
- /**
159
- * Updates the tree view when slottedTreeItems changes
160
- */
161
- this.setItems = () => {
162
- // force single selection
163
- // defaults to first one found
164
- const selectedItem = this.treeView.querySelector("[aria-selected='true']");
165
- this.currentSelected = selectedItem;
166
- // invalidate the current focused item if it is no longer valid
167
- if (this.currentFocused === null || !this.contains(this.currentFocused)) {
168
- this.currentFocused = this.getValidFocusableItem();
169
- }
170
- // toggle properties on child elements
171
- this.nested = this.checkForNestedItems();
172
- const treeItems = this.getVisibleNodes();
173
- treeItems.forEach(node => {
174
- if (isTreeItemElement(node)) {
175
- node.nested = this.nested;
176
- }
177
- });
178
- };
179
- /**
180
- * check if the item is focusable
181
- */
182
- this.isFocusableElement = (el) => {
183
- return isTreeItemElement(el);
184
- };
185
- this.isSelectedElement = (el) => {
186
- return el.selected;
187
- };
188
- }
189
- slottedTreeItemsChanged() {
190
- if (this.$fastController.isConnected) {
191
- // update for slotted children change
192
- this.setItems();
193
- }
194
- }
195
- connectedCallback() {
196
- super.connectedCallback();
197
- this.setAttribute("tabindex", "0");
198
- DOM.queueUpdate(() => {
199
- this.setItems();
200
- });
201
- }
202
- /**
203
- * Handles click events bubbling up
204
- *
205
- * @internal
206
- */
207
- handleClick(e) {
208
- if (e.defaultPrevented) {
209
- // handled, do nothing
210
- return;
211
- }
212
- if (!(e.target instanceof Element) || !isTreeItemElement(e.target)) {
213
- // not a tree item, ignore
214
- return true;
215
- }
216
- const item = e.target;
217
- if (!item.disabled) {
218
- item.selected = !item.selected;
219
- }
220
- return;
221
- }
222
- /**
223
- * Move focus to a tree item based on its offset from the provided item
224
- */
225
- focusNextNode(delta, item) {
226
- const visibleNodes = this.getVisibleNodes();
227
- if (!visibleNodes) {
228
- return;
229
- }
230
- const focusItem = visibleNodes[visibleNodes.indexOf(item) + delta];
231
- if (isHTMLElement(focusItem)) {
232
- TreeItem$1.focusItem(focusItem);
233
- }
234
- }
235
- /**
236
- * checks if there are any nested tree items
237
- */
238
- getValidFocusableItem() {
239
- const treeItems = this.getVisibleNodes();
240
- // default to selected element if there is one
241
- let focusIndex = treeItems.findIndex(this.isSelectedElement);
242
- if (focusIndex === -1) {
243
- // otherwise first focusable tree item
244
- focusIndex = treeItems.findIndex(this.isFocusableElement);
245
- }
246
- if (focusIndex !== -1) {
247
- return treeItems[focusIndex];
248
- }
249
- return null;
250
- }
251
- /**
252
- * checks if there are any nested tree items
253
- */
254
- checkForNestedItems() {
255
- return this.slottedTreeItems.some((node) => {
256
- return isTreeItemElement(node) && node.querySelector("[role='treeitem']");
257
- });
258
- }
259
- getVisibleNodes() {
260
- return getDisplayedNodes(this, "[role='treeitem']") || [];
261
- }
262
- };
263
- __decorate([
264
- attr({ attribute: "render-collapsed-nodes" })
265
- ], TreeView$1.prototype, "renderCollapsedNodes", void 0);
266
- __decorate([
267
- observable
268
- ], TreeView$1.prototype, "currentSelected", void 0);
269
- __decorate([
270
- observable
271
- ], TreeView$1.prototype, "slottedTreeItems", void 0);
272
-
273
- const styles = ".control {\n position: relative;\n display: flex;\n flex-direction: column;\n gap: 4px;\n}";
15
+ const styles = "/**\n * Do not edit directly\n * Generated on Thu, 30 Nov 2023 11:42:28 GMT\n */\n@supports selector(:focus-visible) {\n :host(:focus-visible) {\n outline: none;\n }\n}\n:host([disabled]) {\n cursor: not-allowed;\n}\n\n.control {\n position: relative;\n display: inline-flex;\n box-sizing: border-box;\n align-items: center;\n background-color: var(--_appearance-color-fill);\n border-radius: 6px;\n box-shadow: inset 0 0 0 1px var(--_appearance-color-outline);\n color: var(--_appearance-color-text);\n font: var(--vvd-typography-base);\n gap: 12px;\n hyphens: auto;\n inline-size: 100%;\n min-block-size: calc(1px * (40 + 4 * clamp(-1, var(--vvd-size-density, 0), 2)));\n padding-inline: 16px;\n text-decoration: none;\n vertical-align: middle;\n word-break: break-word;\n}\n.control {\n --_appearance-color-text: var(--_connotation-color-primary);\n --_appearance-color-fill: transparent;\n --_appearance-color-outline: transparent;\n}\n.control:where(:disabled, .disabled) {\n --_appearance-color-text: var(--vvd-color-neutral-300);\n --_appearance-color-fill: transparent;\n --_appearance-color-outline: transparent;\n}\n.control:where(:hover, .hover):where(:not(:disabled, .disabled, .readonly)) {\n --_appearance-color-text: var(--_connotation-color-primary);\n --_appearance-color-fill: var(--_connotation-color-faint);\n --_appearance-color-outline: transparent;\n}\n.control:where(:active, .active):where(:not(:disabled, .disabled)) {\n --_appearance-color-text: var(--_connotation-color-primary);\n --_appearance-color-fill: var(--_connotation-color-soft);\n --_appearance-color-outline: transparent;\n}\n.control:where(.selected, [aria-current]):where(:not(:disabled, .disabled)) {\n --_appearance-color-text: var(--_connotation-color-primary-text);\n --_appearance-color-fill: var(--_connotation-color-primary);\n --_appearance-color-outline: transparent;\n}\n.control:where(.selected, [aria-current]):where(:hover, .hover):where(:not(:disabled, .disabled, .readonly)) {\n --_appearance-color-text: var(--_connotation-color-primary-text);\n --_appearance-color-fill: var(--_connotation-color-primary-increment);\n --_appearance-color-outline: transparent;\n}\n.control {\n /* @cssprop [--vvd-tree-item-accent-primary=var(--vvd-color-canvas-text)] */\n --_connotation-color-primary: var(--vvd-tree-item-accent-primary, var(--vvd-color-canvas-text));\n /* @cssprop [--vvd-tree-item-accent-primary-text=var(--vvd-color-canvas)] */\n --_connotation-color-primary-text: var(--vvd-tree-item-accent-primary-text, var(--vvd-color-canvas));\n /* @cssprop [--vvd-tree-item-accent-primary-increment=var(--vvd-color-neutral-800)] */\n --_connotation-color-primary-increment: var(--vvd-tree-item-accent-primary-increment, var(--vvd-color-neutral-800));\n /* @cssprop [--vvd-tree-item-accent-faint=var(--vvd-color-neutral-50)] */\n --_connotation-color-faint: var(--vvd-tree-item-accent-faint, var(--vvd-color-neutral-50));\n /* @cssprop [--vvd-tree-item-accent-soft=var(--vvd-color-neutral-100)] */\n --_connotation-color-soft: var(--vvd-tree-item-accent-soft, var(--vvd-color-neutral-100));\n}\n@supports selector(:focus-visible) {\n .control:focus-visible {\n outline: none;\n }\n}\n@supports (user-select: none) {\n .control {\n user-select: none;\n }\n}\n.control:not(.disabled) {\n cursor: pointer;\n}\n.control.disabled {\n pointer-events: none;\n}\n.control .text {\n font: var(--vvd-typography-base);\n}\n\n.expandCollapseButton {\n display: flex;\n align-items: center;\n border-radius: 6px;\n font-size: 20px;\n}\n.expandCollapseButton .expandCollapseIcon {\n margin: 4px;\n}\n.expandCollapseButton:hover {\n background-color: var(--vvd-color-neutral-100);\n}\n.selected .expandCollapseButton:hover {\n background-color: var(--vvd-color-neutral-700);\n}\n\n.items {\n display: flex;\n flex-direction: column;\n gap: 4px;\n margin-block: 4px;\n padding-inline-start: 48px;\n}\n\n:host(:not(:focus-visible)) .focus-indicator {\n display: none;\n}\n\nslot[name=icon] {\n font-size: 20px;\n line-height: 1;\n}\n.control:not(.disabled, .selected) slot[name=icon] {\n color: var(--vvd-color-neutral-600);\n}";
274
16
 
275
- class TreeView extends TreeView$1 {
17
+ var __defProp = Object.defineProperty;
18
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
19
+ var __decorateClass = (decorators, target, key, kind) => {
20
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
21
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
22
+ if (decorator = decorators[i])
23
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
24
+ if (kind && result)
25
+ __defProp(target, key, result);
26
+ return result;
27
+ };
28
+ class TreeItem extends TreeItem$1 {
276
29
  }
30
+ __decorateClass([
31
+ attr
32
+ ], TreeItem.prototype, "text", 2);
33
+ applyMixins(TreeItem, AffixIcon);
277
34
 
278
- const getClasses = (_) => classNames("control");
279
- const TreeViewTemplate = () => {
35
+ const getClasses = ({
36
+ disabled,
37
+ selected
38
+ }) => classNames(
39
+ "control",
40
+ ["disabled", disabled],
41
+ ["selected", Boolean(selected)]
42
+ );
43
+ const expandCollapseButton = (context) => {
44
+ const iconTag = context.tagFor(Icon);
45
+ return html`
46
+ <div aria-hidden="true"
47
+ class="expandCollapseButton"
48
+ @click="${(x, c) => x.handleExpandCollapseButtonClick(c.event)}"
49
+ ${ref("expandCollapseButton")}
50
+ >
51
+ <${iconTag} class="expandCollapseIcon" name="${(x) => x.expanded ? "chevron-down-line" : "chevron-right-line"}"></${iconTag}>
52
+ </div>`;
53
+ };
54
+ const TreeItemTemplate = (context) => {
55
+ const affixIconTemplate = affixIconTemplateFactory(context);
56
+ const focusTemplate = focusTemplateFactory(context);
280
57
  return html`
281
58
  <template
282
- role="tree"
283
- ${ref("treeView")}
284
- @keydown="${(x, c) => x.handleKeyDown(c.event)}"
285
- @focusin="${(x, c) => x.handleFocus(c.event)}"
286
- @focusout="${(x, c) => x.handleBlur(c.event)}"
287
- @click="${(x, c) => x.handleClick(c.event)}"
288
- @selected-change="${(x, c) => x.handleSelectedChange(c.event)}"
289
- >
290
- <div class="${getClasses}">
291
- <slot ${slotted("slottedTreeItems")}></slot>
292
- </div>
293
- </template>`;
59
+ role="treeitem"
60
+ slot="${(x) => x.isNestedItem() ? "item" : void 0}"
61
+ tabindex="-1"
62
+ aria-expanded="${(x) => x.childItems && x.childItems.length > 0 ? x.expanded : void 0}"
63
+ aria-selected="${(x) => x.selected}"
64
+ aria-disabled="${(x) => x.disabled}"
65
+ @focusin="${(x, c) => x.handleFocus(c.event)}"
66
+ @focusout="${(x, c) => x.handleBlur(c.event)}"
67
+ ${children({ property: "childItems", filter: elements(context.tagFor(TreeItem)) })}
68
+ >
69
+ <div class="${getClasses}">
70
+ ${() => focusTemplate}
71
+ ${when((x) => x.childItems && x.childItems.length > 0, expandCollapseButton(context))}
72
+ ${(x) => affixIconTemplate(x.icon, IconWrapper.Slot)}
73
+ ${(x) => x.text}
74
+ </div>
75
+ ${when(
76
+ (x) => x.childItems && x.childItems.length > 0 && x.expanded,
77
+ html`
78
+ <div role="group" class="items">
79
+ <slot name="item" ${slotted("items")}></slot>
80
+ </div>`
81
+ )}
82
+ </template>`;
294
83
  };
295
84
 
296
- const treeViewDefinition = TreeView.compose(
85
+ const treeItemDefinition = TreeItem.compose(
297
86
  {
298
- baseName: "tree-view",
299
- template: TreeViewTemplate,
87
+ baseName: "tree-item",
88
+ template: TreeItemTemplate,
300
89
  styles
301
90
  }
302
91
  );
303
- const treeViewRegistries = [treeViewDefinition()];
304
- const registerTreeView = registerFactory(treeViewRegistries);
92
+ const treeItemRegistries = [treeItemDefinition(), ...iconRegistries, ...focusRegistries];
93
+ const registerTreeItem = registerFactory(treeItemRegistries);
305
94
 
306
- export { treeViewRegistries as a, registerTreeView as r, treeViewDefinition as t };
95
+ export { treeItemRegistries as a, registerTreeItem as r, treeItemDefinition as t };