tyrell-components 1.0.0-RC14 → 1.0.0-RC16
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.
- package/README.md +53 -53
- package/css/tyrell-theme.css +32 -4
- package/css/tyrell.css +10 -15
- package/dist/tyrell-colors-static.css +1 -316
- package/dist/tyrell-theme.css +1 -1443
- package/dist/tyrell.css +1 -1390
- package/dist/tyrell.js +1 -1
- package/lib/base/ty-component.d.ts +14 -0
- package/lib/base/ty-component.d.ts.map +1 -0
- package/lib/base/ty-component.js +223 -196
- package/lib/base/ty-component.js.map +1 -0
- package/lib/components/button.d.ts +1 -1
- package/lib/components/button.d.ts.map +1 -0
- package/lib/components/button.js +267 -259
- package/lib/components/button.js.map +1 -0
- package/lib/components/calendar-month.d.ts +2 -2
- package/lib/components/calendar-month.d.ts.map +1 -0
- package/lib/components/calendar-month.js +440 -416
- package/lib/components/calendar-month.js.map +1 -0
- package/lib/components/calendar-navigation.d.ts +11 -0
- package/lib/components/calendar-navigation.d.ts.map +1 -0
- package/lib/components/calendar-navigation.js +272 -261
- package/lib/components/calendar-navigation.js.map +1 -0
- package/lib/components/calendar.d.ts +31 -3
- package/lib/components/calendar.d.ts.map +1 -0
- package/lib/components/calendar.js +785 -603
- package/lib/components/calendar.js.map +1 -0
- package/lib/components/checkbox.d.ts +1 -1
- package/lib/components/checkbox.d.ts.map +1 -0
- package/lib/components/checkbox.js +273 -272
- package/lib/components/checkbox.js.map +1 -0
- package/lib/components/copy.d.ts +1 -1
- package/lib/components/copy.d.ts.map +1 -0
- package/lib/components/copy.js +287 -278
- package/lib/components/copy.js.map +1 -0
- package/lib/components/date-picker.d.ts +16 -10
- package/lib/components/date-picker.d.ts.map +1 -0
- package/lib/components/date-picker.js +1068 -1122
- package/lib/components/date-picker.js.map +1 -0
- package/lib/components/dropdown.d.ts +403 -0
- package/lib/components/dropdown.d.ts.map +1 -0
- package/lib/components/dropdown.js +1315 -0
- package/lib/components/dropdown.js.map +1 -0
- package/lib/components/file-upload.d.ts +4 -0
- package/lib/components/file-upload.js +418 -404
- package/lib/components/icon.d.ts.map +1 -0
- package/lib/components/icon.js +141 -141
- package/lib/components/icon.js.map +1 -0
- package/lib/components/input.d.ts +1 -1
- package/lib/components/input.d.ts.map +1 -0
- package/lib/components/input.js +593 -596
- package/lib/components/input.js.map +1 -0
- package/lib/components/modal.d.ts +2 -8
- package/lib/components/modal.d.ts.map +1 -0
- package/lib/components/modal.js +309 -319
- package/lib/components/modal.js.map +1 -0
- package/lib/components/multiselect.d.ts +389 -0
- package/lib/components/multiselect.d.ts.map +1 -0
- package/lib/components/multiselect.js +1301 -0
- package/lib/components/multiselect.js.map +1 -0
- package/lib/components/option.d.ts.map +1 -0
- package/lib/components/option.js +167 -167
- package/lib/components/option.js.map +1 -0
- package/lib/components/popup.d.ts.map +1 -0
- package/lib/components/popup.js +236 -233
- package/lib/components/popup.js.map +1 -0
- package/lib/components/radio.d.ts +17 -2
- package/lib/components/radio.js +437 -406
- package/lib/components/resize-observer.d.ts.map +1 -0
- package/lib/components/resize-observer.js +67 -67
- package/lib/components/resize-observer.js.map +1 -0
- package/lib/components/scroll-container.d.ts +3 -2
- package/lib/components/scroll-container.d.ts.map +1 -0
- package/lib/components/scroll-container.js +289 -294
- package/lib/components/scroll-container.js.map +1 -0
- package/lib/components/select.d.ts +85 -18
- package/lib/components/select.js +1647 -1529
- package/lib/components/selected-tags.d.ts +1 -1
- package/lib/components/selected-tags.js +188 -182
- package/lib/components/step.d.ts.map +1 -0
- package/lib/components/step.js +62 -62
- package/lib/components/step.js.map +1 -0
- package/lib/components/switch.d.ts +1 -1
- package/lib/components/switch.js +214 -213
- package/lib/components/tab.d.ts +49 -1
- package/lib/components/tab.d.ts.map +1 -0
- package/lib/components/tab.js +203 -62
- package/lib/components/tab.js.map +1 -0
- package/lib/components/tabs.d.ts +15 -2
- package/lib/components/tabs.d.ts.map +1 -0
- package/lib/components/tabs.js +576 -496
- package/lib/components/tabs.js.map +1 -0
- package/lib/components/tag.d.ts +5 -8
- package/lib/components/tag.d.ts.map +1 -0
- package/lib/components/tag.js +235 -235
- package/lib/components/tag.js.map +1 -0
- package/lib/components/textarea.d.ts +5 -4
- package/lib/components/textarea.d.ts.map +1 -0
- package/lib/components/textarea.js +458 -456
- package/lib/components/textarea.js.map +1 -0
- package/lib/components/tooltip.d.ts +4 -3
- package/lib/components/tooltip.d.ts.map +1 -0
- package/lib/components/tooltip.js +293 -283
- package/lib/components/tooltip.js.map +1 -0
- package/lib/components/wizard.d.ts +5 -4
- package/lib/components/wizard.d.ts.map +1 -0
- package/lib/components/wizard.js +359 -395
- package/lib/components/wizard.js.map +1 -0
- package/lib/icons/fontawesome/brands.d.ts.map +1 -0
- package/lib/icons/fontawesome/brands.js.map +1 -0
- package/lib/icons/fontawesome/regular.d.ts.map +1 -0
- package/lib/icons/fontawesome/regular.js.map +1 -0
- package/lib/icons/fontawesome/solid.d.ts.map +1 -0
- package/lib/icons/fontawesome/solid.js.map +1 -0
- package/lib/icons/heroicons/micro.d.ts.map +1 -0
- package/lib/icons/heroicons/micro.js +392 -392
- package/lib/icons/heroicons/micro.js.map +1 -0
- package/lib/icons/heroicons/mini.d.ts.map +1 -0
- package/lib/icons/heroicons/mini.js +382 -382
- package/lib/icons/heroicons/mini.js.map +1 -0
- package/lib/icons/heroicons/outline.d.ts.map +1 -0
- package/lib/icons/heroicons/outline.js +337 -337
- package/lib/icons/heroicons/outline.js.map +1 -0
- package/lib/icons/heroicons/solid.d.ts.map +1 -0
- package/lib/icons/heroicons/solid.js +407 -407
- package/lib/icons/heroicons/solid.js.map +1 -0
- package/lib/icons/lucide.d.ts.map +1 -0
- package/lib/icons/lucide.js +22843 -22843
- package/lib/icons/lucide.js.map +1 -0
- package/lib/icons/material/filled.d.ts.map +1 -0
- package/lib/icons/material/filled.js +9653 -9653
- package/lib/icons/material/filled.js.map +1 -0
- package/lib/icons/material/outlined.d.ts.map +1 -0
- package/lib/icons/material/outlined.js +10271 -10271
- package/lib/icons/material/outlined.js.map +1 -0
- package/lib/icons/material/round.d.ts.map +1 -0
- package/lib/icons/material/round.js +10495 -10495
- package/lib/icons/material/round.js.map +1 -0
- package/lib/icons/material/sharp.d.ts.map +1 -0
- package/lib/icons/material/sharp.js +9905 -9905
- package/lib/icons/material/sharp.js.map +1 -0
- package/lib/icons/material/two-tone.d.ts.map +1 -0
- package/lib/icons/material/two-tone.js +12792 -12792
- package/lib/icons/material/two-tone.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +21 -21
- package/lib/index.js.map +1 -0
- package/lib/styles/button.d.ts.map +1 -0
- package/lib/styles/button.js +200 -302
- package/lib/styles/button.js.map +1 -0
- package/lib/styles/calendar-month.d.ts +3 -0
- package/lib/styles/calendar-month.d.ts.map +1 -0
- package/lib/styles/calendar-month.js +141 -185
- package/lib/styles/calendar-month.js.map +1 -0
- package/lib/styles/calendar-navigation.d.ts +1 -1
- package/lib/styles/calendar-navigation.d.ts.map +1 -0
- package/lib/styles/calendar-navigation.js +100 -86
- package/lib/styles/calendar-navigation.js.map +1 -0
- package/lib/styles/calendar.d.ts +3 -2
- package/lib/styles/calendar.d.ts.map +1 -0
- package/lib/styles/calendar.js +83 -9
- package/lib/styles/calendar.js.map +1 -0
- package/lib/styles/checkbox.js +62 -77
- package/lib/styles/copy.d.ts.map +1 -0
- package/lib/styles/copy.js +71 -91
- package/lib/styles/copy.js.map +1 -0
- package/lib/styles/custom-scrollbar.js +80 -100
- package/lib/styles/date-picker.d.ts.map +1 -0
- package/lib/styles/date-picker.js +295 -335
- package/lib/styles/date-picker.js.map +1 -0
- package/lib/styles/dropdown.d.ts +12 -0
- package/lib/styles/dropdown.d.ts.map +1 -0
- package/lib/styles/dropdown.js +725 -0
- package/lib/styles/dropdown.js.map +1 -0
- package/lib/styles/field-size.d.ts +6 -0
- package/lib/styles/field-size.js +91 -0
- package/lib/styles/file-upload.js +139 -169
- package/lib/styles/icon.d.ts.map +1 -0
- package/lib/styles/icon.js +92 -156
- package/lib/styles/icon.js.map +1 -0
- package/lib/styles/input.d.ts.map +1 -0
- package/lib/styles/input.js +125 -241
- package/lib/styles/input.js.map +1 -0
- package/lib/styles/modal.d.ts.map +1 -0
- package/lib/styles/modal.js +67 -102
- package/lib/styles/modal.js.map +1 -0
- package/lib/styles/multiselect.d.ts +6 -0
- package/lib/styles/multiselect.d.ts.map +1 -0
- package/lib/styles/multiselect.js +568 -0
- package/lib/styles/multiselect.js.map +1 -0
- package/lib/styles/option.d.ts +1 -1
- package/lib/styles/option.d.ts.map +1 -0
- package/lib/styles/option.js +47 -67
- package/lib/styles/option.js.map +1 -0
- package/lib/styles/popup.d.ts +1 -1
- package/lib/styles/popup.d.ts.map +1 -0
- package/lib/styles/popup.js +37 -65
- package/lib/styles/popup.js.map +1 -0
- package/lib/styles/radio.js +75 -96
- package/lib/styles/resize-observer.d.ts.map +1 -0
- package/lib/styles/resize-observer.js +2 -5
- package/lib/styles/resize-observer.js.map +1 -0
- package/lib/styles/scroll-container.d.ts +1 -1
- package/lib/styles/scroll-container.d.ts.map +1 -0
- package/lib/styles/scroll-container.js +101 -131
- package/lib/styles/scroll-container.js.map +1 -0
- package/lib/styles/select-base.js +596 -773
- package/lib/styles/select.d.ts +1 -1
- package/lib/styles/select.js +146 -228
- package/lib/styles/step.d.ts +1 -1
- package/lib/styles/step.d.ts.map +1 -0
- package/lib/styles/step.js +15 -30
- package/lib/styles/step.js.map +1 -0
- package/lib/styles/switch.js +37 -55
- package/lib/styles/tab.d.ts +1 -1
- package/lib/styles/tab.d.ts.map +1 -0
- package/lib/styles/tab.js +86 -29
- package/lib/styles/tab.js.map +1 -0
- package/lib/styles/tabs.d.ts +1 -1
- package/lib/styles/tabs.d.ts.map +1 -0
- package/lib/styles/tabs.js +190 -180
- package/lib/styles/tabs.js.map +1 -0
- package/lib/styles/tag.d.ts.map +1 -0
- package/lib/styles/tag.js +137 -191
- package/lib/styles/tag.js.map +1 -0
- package/lib/styles/textarea.d.ts +1 -1
- package/lib/styles/textarea.d.ts.map +1 -0
- package/lib/styles/textarea.js +205 -271
- package/lib/styles/textarea.js.map +1 -0
- package/lib/styles/tooltip.d.ts.map +1 -0
- package/lib/styles/tooltip.js +3 -3
- package/lib/styles/tooltip.js.map +1 -0
- package/lib/styles/wizard.d.ts +9 -5
- package/lib/styles/wizard.d.ts.map +1 -0
- package/lib/styles/wizard.js +301 -245
- package/lib/styles/wizard.js.map +1 -0
- package/lib/types/common.d.ts +4 -2
- package/lib/types/common.d.ts.map +1 -0
- package/lib/types/common.js +6 -5
- package/lib/types/common.js.map +1 -0
- package/lib/utils/calendar-utils.d.ts.map +1 -0
- package/lib/utils/calendar-utils.js +100 -100
- package/lib/utils/calendar-utils.js.map +1 -0
- package/lib/utils/custom-scrollbar.js +272 -272
- package/lib/utils/flavor-sheet.js +14 -14
- package/lib/utils/icon-registry.d.ts.map +1 -0
- package/lib/utils/icon-registry.js +127 -127
- package/lib/utils/icon-registry.js.map +1 -0
- package/lib/utils/loader-registry.js +3 -3
- package/lib/utils/locale.d.ts.map +1 -0
- package/lib/utils/locale.js +34 -34
- package/lib/utils/locale.js.map +1 -0
- package/lib/utils/mobile.js +1 -1
- package/lib/utils/number-format.d.ts.map +1 -0
- package/lib/utils/number-format.js +54 -54
- package/lib/utils/number-format.js.map +1 -0
- package/lib/utils/parse-boolean.d.ts +39 -0
- package/lib/utils/parse-boolean.d.ts.map +1 -0
- package/lib/utils/parse-boolean.js +23 -0
- package/lib/utils/parse-boolean.js.map +1 -0
- package/lib/utils/positioning.d.ts.map +1 -0
- package/lib/utils/positioning.js +212 -212
- package/lib/utils/positioning.js.map +1 -0
- package/lib/utils/property-capture.d.ts.map +1 -0
- package/lib/utils/property-capture.js +36 -36
- package/lib/utils/property-capture.js.map +1 -0
- package/lib/utils/property-manager.d.ts +1 -1
- package/lib/utils/property-manager.d.ts.map +1 -0
- package/lib/utils/property-manager.js +127 -125
- package/lib/utils/property-manager.js.map +1 -0
- package/lib/utils/resize-observer.d.ts.map +1 -0
- package/lib/utils/resize-observer.js +23 -23
- package/lib/utils/resize-observer.js.map +1 -0
- package/lib/utils/scroll-lock.d.ts.map +1 -0
- package/lib/utils/scroll-lock.js +57 -57
- package/lib/utils/scroll-lock.js.map +1 -0
- package/lib/utils/styles.d.ts.map +1 -0
- package/lib/utils/styles.js +17 -17
- package/lib/utils/styles.js.map +1 -0
- package/lib/utils/validity.d.ts +26 -0
- package/lib/utils/validity.js +53 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.d.ts.map +1 -0
- package/lib/version.js +1 -1
- package/lib/version.js.map +1 -0
- package/package.json +28 -7
package/lib/components/tabs.js
CHANGED
|
@@ -2,554 +2,634 @@ import { ensureStyles } from '../utils/styles.js';
|
|
|
2
2
|
import { tabsStyles } from '../styles/tabs.js';
|
|
3
3
|
const eventHandlers = new WeakMap();
|
|
4
4
|
const resizeObservers = new WeakMap();
|
|
5
|
+
const shownTabs = new WeakMap();
|
|
6
|
+
const instanceSheets = new WeakMap();
|
|
7
|
+
const pendingInitialSnap = new WeakMap();
|
|
8
|
+
let userInputs = 0;
|
|
9
|
+
const countInput = () => { userInputs++; };
|
|
10
|
+
addEventListener('pointerdown', countInput, { capture: true, passive: true });
|
|
11
|
+
addEventListener('keydown', countInput, { capture: true, passive: true });
|
|
12
|
+
const awaitedTabs = new WeakMap();
|
|
13
|
+
let snapCount = 0;
|
|
5
14
|
function getTabsAttributes(el) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
placement: (el.getAttribute('placement') || 'top'),
|
|
11
|
-
};
|
|
15
|
+
return {
|
|
16
|
+
placement: (el.getAttribute('placement') || 'top'),
|
|
17
|
+
fixed: el.hasAttribute('fixed'),
|
|
18
|
+
};
|
|
12
19
|
}
|
|
13
20
|
function getChildTabs(el) {
|
|
14
|
-
|
|
21
|
+
return Array.from(el.querySelectorAll(':scope > ty-tab'));
|
|
15
22
|
}
|
|
16
23
|
function getTabId(tab) {
|
|
17
|
-
|
|
24
|
+
return tab.getAttribute('id');
|
|
25
|
+
}
|
|
26
|
+
function getSlotLabel(tabsEl, tabId) {
|
|
27
|
+
return tabsEl.querySelector(`:scope > [slot='label-${tabId}']`);
|
|
18
28
|
}
|
|
19
29
|
function hasSlotLabel(tabsEl, tabId) {
|
|
20
|
-
|
|
30
|
+
return getSlotLabel(tabsEl, tabId) !== null;
|
|
21
31
|
}
|
|
22
32
|
function getTabLabelType(tabsEl, tab) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
33
|
+
const tabId = getTabId(tab);
|
|
34
|
+
if (tabId && hasSlotLabel(tabsEl, tabId)) {
|
|
35
|
+
return 'slot';
|
|
36
|
+
}
|
|
37
|
+
return 'text';
|
|
28
38
|
}
|
|
29
39
|
function isTabDisabled(tab) {
|
|
30
|
-
|
|
40
|
+
return tab.hasAttribute('disabled');
|
|
31
41
|
}
|
|
32
42
|
function hasCustomMarker(el) {
|
|
33
|
-
|
|
43
|
+
return el.querySelector(':scope > [slot="marker"]') !== null;
|
|
34
44
|
}
|
|
35
45
|
function findTabIndex(tabs, tabId) {
|
|
36
|
-
|
|
37
|
-
|
|
46
|
+
const index = tabs.findIndex(tab => getTabId(tab) === tabId);
|
|
47
|
+
return index >= 0 ? index : undefined;
|
|
48
|
+
}
|
|
49
|
+
function currentActive(el) {
|
|
50
|
+
return shownTabs.get(el) ?? null;
|
|
38
51
|
}
|
|
39
52
|
function getActiveTabId(el, tabs) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
function
|
|
50
|
-
|
|
53
|
+
const ids = tabs.map(getTabId).filter((id) => !!id);
|
|
54
|
+
const activeAttr = el.getAttribute('active');
|
|
55
|
+
if (activeAttr && ids.includes(activeAttr))
|
|
56
|
+
return activeAttr;
|
|
57
|
+
const shown = shownTabs.get(el);
|
|
58
|
+
if (shown && ids.includes(shown))
|
|
59
|
+
return shown;
|
|
60
|
+
return ids[0] ?? null;
|
|
61
|
+
}
|
|
62
|
+
function activateTab(el, tabId) {
|
|
63
|
+
el.setAttribute('active', tabId);
|
|
64
|
+
syncShownTab(el, true);
|
|
51
65
|
}
|
|
52
66
|
function dispatchTabChangeEvent(el, activeId, activeIndex, previousId, previousIndex) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
const event = new CustomEvent('ty-tab-change', {
|
|
68
|
+
detail: {
|
|
69
|
+
activeId,
|
|
70
|
+
activeIndex,
|
|
71
|
+
previousId,
|
|
72
|
+
previousIndex,
|
|
73
|
+
},
|
|
74
|
+
bubbles: true,
|
|
75
|
+
cancelable: false,
|
|
76
|
+
});
|
|
77
|
+
el.dispatchEvent(event);
|
|
64
78
|
}
|
|
65
79
|
function handleTabClick(el, tabId, event) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
80
|
+
event.preventDefault();
|
|
81
|
+
event.stopPropagation();
|
|
82
|
+
activateTab(el, tabId);
|
|
69
83
|
}
|
|
70
84
|
function cleanupEventListeners(el) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
85
|
+
const handlers = eventHandlers.get(el);
|
|
86
|
+
if (!handlers)
|
|
87
|
+
return;
|
|
88
|
+
const shadowRoot = el.shadowRoot;
|
|
89
|
+
if (!shadowRoot)
|
|
90
|
+
return;
|
|
91
|
+
handlers.tabClickHandlers.forEach((handler, tabId) => {
|
|
92
|
+
const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
|
|
93
|
+
if (button) {
|
|
94
|
+
button.removeEventListener('click', handler);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
handlers.tabKeydownHandlers.forEach((handler, tabId) => {
|
|
98
|
+
const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
|
|
99
|
+
if (button) {
|
|
100
|
+
button.removeEventListener('keydown', handler);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
handlers.tabClickHandlers.clear();
|
|
104
|
+
handlers.tabKeydownHandlers.clear();
|
|
105
|
+
}
|
|
106
|
+
function handleTabKeydown(el, shadowRoot, tabId, e) {
|
|
107
|
+
if (!['ArrowRight', 'ArrowLeft', 'Home', 'End'].includes(e.key))
|
|
108
|
+
return;
|
|
109
|
+
const ids = Array.from(shadowRoot.querySelectorAll('.tab-buttons [data-tab-id]:not([disabled])')).map((b) => b.getAttribute('data-tab-id'));
|
|
110
|
+
const i = ids.indexOf(tabId);
|
|
111
|
+
if (i < 0 || ids.length === 0)
|
|
112
|
+
return;
|
|
113
|
+
e.preventDefault();
|
|
114
|
+
const next = e.key === 'Home' ? ids[0]
|
|
115
|
+
: e.key === 'End' ? ids[ids.length - 1]
|
|
116
|
+
: e.key === 'ArrowRight' ? ids[(i + 1) % ids.length]
|
|
117
|
+
: ids[(i - 1 + ids.length) % ids.length];
|
|
118
|
+
if (next === tabId)
|
|
119
|
+
return;
|
|
120
|
+
handleTabClick(el, next, e);
|
|
121
|
+
requestAnimationFrame(() => {
|
|
122
|
+
shadowRoot.querySelector(`.tab-buttons [data-tab-id='${next}']`)?.focus();
|
|
123
|
+
});
|
|
91
124
|
}
|
|
92
125
|
function setupEventListeners(el, shadowRoot, tabs) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
126
|
+
cleanupEventListeners(el);
|
|
127
|
+
const handlers = {
|
|
128
|
+
tabClickHandlers: new Map(),
|
|
129
|
+
tabKeydownHandlers: new Map(),
|
|
130
|
+
};
|
|
131
|
+
tabs.forEach((tab) => {
|
|
132
|
+
const tabId = getTabId(tab);
|
|
133
|
+
if (!tabId)
|
|
134
|
+
return;
|
|
135
|
+
const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
|
|
136
|
+
if (button) {
|
|
137
|
+
const handler = (e) => handleTabClick(el, tabId, e);
|
|
138
|
+
const keydownHandler = (e) => handleTabKeydown(el, shadowRoot, tabId, e);
|
|
139
|
+
button.addEventListener('click', handler);
|
|
140
|
+
button.addEventListener('keydown', keydownHandler);
|
|
141
|
+
handlers.tabClickHandlers.set(tabId, handler);
|
|
142
|
+
handlers.tabKeydownHandlers.set(tabId, keydownHandler);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
eventHandlers.set(el, handlers);
|
|
146
|
+
}
|
|
147
|
+
function carouselTransform(activeIndex) {
|
|
148
|
+
return `translateX(${activeIndex * -100}%)`;
|
|
149
|
+
}
|
|
150
|
+
function snapNextChange(container) {
|
|
151
|
+
if (!container)
|
|
152
|
+
return;
|
|
153
|
+
const token = String(++snapCount);
|
|
154
|
+
container.setAttribute('data-snap', token);
|
|
155
|
+
requestAnimationFrame(() => requestAnimationFrame(() => {
|
|
156
|
+
if (container.getAttribute('data-snap') === token)
|
|
157
|
+
container.removeAttribute('data-snap');
|
|
158
|
+
}));
|
|
116
159
|
}
|
|
117
160
|
function updateTransform(el, activeIndex) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
161
|
+
const panelsWrapper = el.shadowRoot?.querySelector('.panels-wrapper');
|
|
162
|
+
if (panelsWrapper)
|
|
163
|
+
panelsWrapper.style.transform = carouselTransform(activeIndex);
|
|
164
|
+
}
|
|
165
|
+
function setAttr(node, name, value) {
|
|
166
|
+
if (node.getAttribute(name) !== value)
|
|
167
|
+
node.setAttribute(name, value);
|
|
168
|
+
}
|
|
169
|
+
function syncInstanceSheet(el, shownId) {
|
|
170
|
+
const shadowRoot = el.shadowRoot;
|
|
171
|
+
if (!shadowRoot)
|
|
172
|
+
return;
|
|
173
|
+
let sheet = instanceSheets.get(el);
|
|
174
|
+
if (!sheet) {
|
|
175
|
+
sheet = new CSSStyleSheet();
|
|
176
|
+
sheet.replaceSync(':host {} ::slotted(ty-tab) {}');
|
|
177
|
+
const hide = sheet.cssRules[1].style;
|
|
178
|
+
hide.setProperty('opacity', '0', 'important');
|
|
179
|
+
hide.setProperty('visibility', 'hidden', 'important');
|
|
180
|
+
hide.setProperty('pointer-events', 'none', 'important');
|
|
181
|
+
shadowRoot.adoptedStyleSheets = [...shadowRoot.adoptedStyleSheets, sheet];
|
|
182
|
+
instanceSheets.set(el, sheet);
|
|
183
|
+
}
|
|
184
|
+
const host = sheet.cssRules[0].style;
|
|
185
|
+
for (const prop of ['width', 'height']) {
|
|
186
|
+
const value = el.getAttribute(prop);
|
|
187
|
+
if (value)
|
|
188
|
+
host.setProperty(prop, value, 'important');
|
|
189
|
+
else
|
|
190
|
+
host.removeProperty(prop);
|
|
191
|
+
}
|
|
192
|
+
sheet.cssRules[1].selectorText = shownId
|
|
193
|
+
? `::slotted(ty-tab:not(#${CSS.escape(shownId)}))`
|
|
194
|
+
: '::slotted(ty-tab)';
|
|
127
195
|
}
|
|
128
196
|
function updateAriaAttributes(el, shadowRoot, activeId) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
197
|
+
const tabs = getChildTabs(el);
|
|
198
|
+
tabs.forEach((tab, idx) => {
|
|
199
|
+
const tabId = getTabId(tab);
|
|
200
|
+
if (!tabId)
|
|
201
|
+
return;
|
|
202
|
+
const button = shadowRoot.querySelector(`[data-tab-id='${tabId}']`);
|
|
203
|
+
const isActive = tabId === activeId;
|
|
204
|
+
if (button) {
|
|
205
|
+
button.setAttribute('aria-selected', String(isActive));
|
|
206
|
+
button.setAttribute('tabindex', isActive ? '0' : '-1');
|
|
207
|
+
button.setAttribute('data-active', String(isActive));
|
|
208
|
+
const slottedLabel = getSlotLabel(el, tabId);
|
|
209
|
+
if (slottedLabel) {
|
|
210
|
+
setAttr(slottedLabel, 'data-active', String(isActive));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
});
|
|
146
214
|
}
|
|
147
215
|
function updatePanelInteraction(el, activeId) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
tab.style.pointerEvents = 'auto';
|
|
157
|
-
tab.style.opacity = '1';
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
tab.style.pointerEvents = 'none';
|
|
161
|
-
tab.style.opacity = '0';
|
|
162
|
-
}
|
|
163
|
-
});
|
|
216
|
+
syncInstanceSheet(el, activeId);
|
|
217
|
+
getChildTabs(el).forEach((tab) => {
|
|
218
|
+
const tabId = getTabId(tab);
|
|
219
|
+
tab.setShown?.(!!tabId && tabId === activeId);
|
|
220
|
+
if (!tabId)
|
|
221
|
+
return;
|
|
222
|
+
setAttr(tab, 'data-active', String(tabId === activeId));
|
|
223
|
+
});
|
|
164
224
|
}
|
|
165
225
|
function calculateMarkerPosition(el, shadowRoot, activeId) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
226
|
+
const button = shadowRoot.querySelector(`[data-tab-id='${activeId}']`);
|
|
227
|
+
const buttonsContainer = shadowRoot.querySelector('.tab-buttons');
|
|
228
|
+
if (!button || !buttonsContainer)
|
|
229
|
+
return null;
|
|
230
|
+
const left = button.offsetLeft;
|
|
231
|
+
const top = button.offsetTop;
|
|
232
|
+
const width = button.offsetWidth;
|
|
233
|
+
const height = button.offsetHeight;
|
|
234
|
+
return { left, top, width, height };
|
|
235
|
+
}
|
|
236
|
+
function updateMarker(el, activeId, forceSnap = false) {
|
|
237
|
+
const shadowRoot = el.shadowRoot;
|
|
238
|
+
if (!shadowRoot)
|
|
239
|
+
return;
|
|
240
|
+
const marker = shadowRoot.querySelector('.marker-wrapper');
|
|
241
|
+
if (!marker)
|
|
242
|
+
return;
|
|
243
|
+
const position = calculateMarkerPosition(el, shadowRoot, activeId);
|
|
244
|
+
if (!position)
|
|
245
|
+
return;
|
|
246
|
+
const snap = forceSnap || !marker.style.left || marker.offsetWidth === 0;
|
|
247
|
+
if (snap)
|
|
248
|
+
marker.style.transition = 'none';
|
|
249
|
+
marker.style.left = `${position.left}px`;
|
|
250
|
+
marker.style.top = `${position.top}px`;
|
|
251
|
+
marker.style.width = `${position.width}px`;
|
|
252
|
+
marker.style.height = `${position.height}px`;
|
|
253
|
+
if (snap) {
|
|
254
|
+
marker.offsetWidth;
|
|
255
|
+
marker.style.transition = '';
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
function syncShownTab(el, user = false) {
|
|
259
|
+
const shadowRoot = el.shadowRoot;
|
|
260
|
+
if (!shadowRoot)
|
|
261
|
+
return;
|
|
262
|
+
const tabs = getChildTabs(el);
|
|
263
|
+
const previousId = shownTabs.get(el) ?? null;
|
|
264
|
+
const tabId = getActiveTabId(el, tabs);
|
|
265
|
+
const newIndex = (tabId ? findTabIndex(tabs, tabId) : undefined) ?? 0;
|
|
266
|
+
const container = shadowRoot.querySelector('.tabs-container');
|
|
267
|
+
if (tabId === previousId) {
|
|
268
|
+
const wrapper = shadowRoot.querySelector('.panels-wrapper');
|
|
269
|
+
if (wrapper && wrapper.style.transform !== carouselTransform(newIndex)) {
|
|
270
|
+
snapNextChange(container);
|
|
271
|
+
wrapper.style.transform = carouselTransform(newIndex);
|
|
272
|
+
}
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
shownTabs.set(el, tabId);
|
|
276
|
+
const initial = previousId === null;
|
|
277
|
+
const arrived = !user && tabId !== null && awaitedTabs.get(el) === tabId;
|
|
278
|
+
awaitedTabs.delete(el);
|
|
279
|
+
const requested = el.getAttribute('active');
|
|
280
|
+
if (initial && requested && requested !== tabId)
|
|
281
|
+
awaitedTabs.set(el, requested);
|
|
282
|
+
const snap = !user && (initial || arrived || pendingInitialSnap.get(el) === userInputs);
|
|
283
|
+
if (initial)
|
|
284
|
+
pendingInitialSnap.set(el, userInputs);
|
|
285
|
+
else if (!arrived)
|
|
286
|
+
pendingInitialSnap.delete(el);
|
|
287
|
+
if (snap)
|
|
288
|
+
snapNextChange(container);
|
|
289
|
+
updateTransform(el, newIndex);
|
|
290
|
+
updateAriaAttributes(el, shadowRoot, tabId || '');
|
|
291
|
+
updatePanelInteraction(el, tabId);
|
|
292
|
+
if (!tabId || initial)
|
|
293
|
+
return;
|
|
294
|
+
updateMarker(el, tabId, snap);
|
|
295
|
+
scrollActiveIntoView(el, tabId, !snap);
|
|
296
|
+
shadowRoot.querySelectorAll('.tab-overflow-item').forEach((item) => {
|
|
297
|
+
item.setAttribute('data-active', String(item.dataset.tabId === tabId));
|
|
298
|
+
});
|
|
299
|
+
tabs[newIndex]?.resetScroll?.();
|
|
300
|
+
if (arrived)
|
|
301
|
+
return;
|
|
302
|
+
const previousIndex = findTabIndex(tabs, previousId);
|
|
303
|
+
dispatchTabChangeEvent(el, tabId, newIndex, previousIndex === undefined ? null : previousId, previousIndex ?? null);
|
|
304
|
+
tabs[newIndex]?._requestLoad?.(newIndex);
|
|
221
305
|
}
|
|
222
306
|
function setupResizeObserver(el) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
updateTransform(el, activeIndex);
|
|
238
|
-
}
|
|
239
|
-
if (activeId) {
|
|
240
|
-
updateMarker(el, activeId);
|
|
241
|
-
}
|
|
242
|
-
updateOverflow(el);
|
|
243
|
-
});
|
|
244
|
-
observer.observe(el);
|
|
245
|
-
resizeObservers.set(el, observer);
|
|
307
|
+
const oldObserver = resizeObservers.get(el);
|
|
308
|
+
if (oldObserver) {
|
|
309
|
+
oldObserver.disconnect();
|
|
310
|
+
}
|
|
311
|
+
const observer = new ResizeObserver(() => {
|
|
312
|
+
const activeId = currentActive(el);
|
|
313
|
+
updateOverflow(el);
|
|
314
|
+
if (activeId) {
|
|
315
|
+
updateMarker(el, activeId);
|
|
316
|
+
scrollActiveIntoView(el, activeId, false);
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
observer.observe(el);
|
|
320
|
+
resizeObservers.set(el, observer);
|
|
246
321
|
}
|
|
247
322
|
function cleanupResizeObserver(el) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
323
|
+
const observer = resizeObservers.get(el);
|
|
324
|
+
if (observer) {
|
|
325
|
+
observer.disconnect();
|
|
326
|
+
resizeObservers.delete(el);
|
|
327
|
+
}
|
|
253
328
|
}
|
|
254
329
|
function renderTabButtons(tabsEl, tabs, activeId) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
330
|
+
const buttons = tabs.map((tab) => {
|
|
331
|
+
const tabId = getTabId(tab);
|
|
332
|
+
if (!tabId)
|
|
333
|
+
return '';
|
|
334
|
+
const labelType = getTabLabelType(tabsEl, tab);
|
|
335
|
+
const textLabel = labelType === 'text' ? (tab.getAttribute('label') || 'Tab') : '';
|
|
336
|
+
const disabled = isTabDisabled(tab);
|
|
337
|
+
const active = tabId === activeId;
|
|
338
|
+
return `<button
|
|
339
|
+
class="tab-button"
|
|
340
|
+
role="tab"
|
|
341
|
+
data-tab-id="${tabId}"
|
|
342
|
+
id="tab-${tabId}"
|
|
343
|
+
aria-selected="${active}"
|
|
344
|
+
tabindex="${active ? '0' : '-1'}"
|
|
345
|
+
data-active="${active}"
|
|
346
|
+
${disabled ? 'disabled aria-disabled="true"' : ''}
|
|
347
|
+
>
|
|
348
|
+
${labelType === 'slot' ? `<slot name="label-${tabId}"></slot>` : `<span class="tab-label">${textLabel}</span>`}
|
|
349
|
+
</button>`;
|
|
350
|
+
}).join('');
|
|
351
|
+
return `
|
|
352
|
+
<div class="tab-buttons" part="buttons-container">
|
|
353
|
+
<div class="tab-strip" role="tablist" part="strip">
|
|
354
|
+
<div class="marker-wrapper" part="marker-wrapper">
|
|
355
|
+
${!hasCustomMarker(tabsEl) ? '<div class="default-marker"></div>' : ''}
|
|
356
|
+
<slot name="marker"></slot>
|
|
357
|
+
</div>
|
|
358
|
+
${buttons}
|
|
359
|
+
</div>
|
|
360
|
+
</div>
|
|
361
|
+
`;
|
|
285
362
|
}
|
|
286
363
|
function renderButtonsOnly(tabsEl, tabs, activeId) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
const OVERFLOW_TRIGGER_WIDTH = 40;
|
|
364
|
+
return tabs.map((tab) => {
|
|
365
|
+
const tabId = getTabId(tab);
|
|
366
|
+
if (!tabId)
|
|
367
|
+
return '';
|
|
368
|
+
const labelType = getTabLabelType(tabsEl, tab);
|
|
369
|
+
const textLabel = labelType === 'text' ? (tab.getAttribute('label') || 'Tab') : '';
|
|
370
|
+
const disabled = isTabDisabled(tab);
|
|
371
|
+
const active = tabId === activeId;
|
|
372
|
+
return `<button
|
|
373
|
+
class="tab-button"
|
|
374
|
+
role="tab"
|
|
375
|
+
data-tab-id="${tabId}"
|
|
376
|
+
id="tab-${tabId}"
|
|
377
|
+
aria-selected="${active}"
|
|
378
|
+
tabindex="${active ? '0' : '-1'}"
|
|
379
|
+
data-active="${active}"
|
|
380
|
+
${disabled ? 'disabled aria-disabled="true"' : ''}
|
|
381
|
+
>
|
|
382
|
+
${labelType === 'slot' ? `<slot name="label-${tabId}"></slot>` : `<span class="tab-label">${textLabel}</span>`}
|
|
383
|
+
</button>`;
|
|
384
|
+
}).join('');
|
|
385
|
+
}
|
|
310
386
|
function getTabMenuLabel(tabsEl, tab) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
387
|
+
const tabId = getTabId(tab);
|
|
388
|
+
if (tabId && getTabLabelType(tabsEl, tab) === 'slot') {
|
|
389
|
+
const slotted = getSlotLabel(tabsEl, tabId);
|
|
390
|
+
return slotted?.textContent?.trim() || tabId;
|
|
391
|
+
}
|
|
392
|
+
return tab.getAttribute('label') || 'Tab';
|
|
317
393
|
}
|
|
318
394
|
function removeOverflowMenu(shadowRoot) {
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
function renderOverflowMenu(el, container,
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
container.appendChild(trigger);
|
|
395
|
+
shadowRoot.querySelector('.tab-overflow-trigger')?.remove();
|
|
396
|
+
}
|
|
397
|
+
function renderOverflowMenu(el, container, allTabs) {
|
|
398
|
+
const activeId = getActiveTabId(el, allTabs);
|
|
399
|
+
const trigger = document.createElement('button');
|
|
400
|
+
trigger.className = 'tab-overflow-trigger';
|
|
401
|
+
trigger.type = 'button';
|
|
402
|
+
trigger.setAttribute('aria-label', `${allTabs.length} tabs`);
|
|
403
|
+
trigger.textContent = '⋯';
|
|
404
|
+
const popup = document.createElement('ty-popup');
|
|
405
|
+
popup.setAttribute('placement', 'bottom');
|
|
406
|
+
const menu = document.createElement('div');
|
|
407
|
+
menu.className = 'tab-overflow-menu';
|
|
408
|
+
menu.setAttribute('role', 'menu');
|
|
409
|
+
allTabs.forEach((tab) => {
|
|
410
|
+
const tabId = getTabId(tab);
|
|
411
|
+
if (!tabId)
|
|
412
|
+
return;
|
|
413
|
+
const item = document.createElement('button');
|
|
414
|
+
item.type = 'button';
|
|
415
|
+
item.className = 'tab-overflow-item';
|
|
416
|
+
item.setAttribute('role', 'menuitem');
|
|
417
|
+
item.setAttribute('data-tab-id', tabId);
|
|
418
|
+
item.setAttribute('data-active', String(tabId === activeId));
|
|
419
|
+
item.textContent = getTabMenuLabel(el, tab);
|
|
420
|
+
if (isTabDisabled(tab)) {
|
|
421
|
+
item.disabled = true;
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
item.addEventListener('click', () => {
|
|
425
|
+
activateTab(el, tabId);
|
|
426
|
+
popup.closePopup?.();
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
menu.appendChild(item);
|
|
430
|
+
});
|
|
431
|
+
popup.appendChild(menu);
|
|
432
|
+
trigger.appendChild(popup);
|
|
433
|
+
container.appendChild(trigger);
|
|
359
434
|
}
|
|
360
435
|
function updateOverflow(el) {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
436
|
+
const shadowRoot = el.shadowRoot;
|
|
437
|
+
if (!shadowRoot)
|
|
438
|
+
return;
|
|
439
|
+
const container = shadowRoot.querySelector('.tab-buttons');
|
|
440
|
+
const strip = shadowRoot.querySelector('.tab-strip');
|
|
441
|
+
if (!container || !strip)
|
|
442
|
+
return;
|
|
443
|
+
if (getTabsAttributes(el).fixed) {
|
|
444
|
+
removeOverflowMenu(shadowRoot);
|
|
445
|
+
strip.classList.add('unclipped');
|
|
446
|
+
strip.style.removeProperty('--fade-left');
|
|
447
|
+
strip.style.removeProperty('--fade-right');
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
const savedScrollLeft = strip.scrollLeft;
|
|
451
|
+
removeOverflowMenu(shadowRoot);
|
|
452
|
+
if (strip.clientWidth <= 0)
|
|
453
|
+
return;
|
|
454
|
+
const buttons = strip.querySelectorAll('.tab-button');
|
|
455
|
+
const last = buttons[buttons.length - 1];
|
|
456
|
+
const contentWidth = last ? last.offsetLeft + last.offsetWidth : 0;
|
|
457
|
+
const stripWidth = strip.clientWidth;
|
|
458
|
+
const hidden = contentWidth - stripWidth;
|
|
459
|
+
strip.classList.toggle('unclipped', hidden <= 1);
|
|
460
|
+
if (hidden <= 1) {
|
|
461
|
+
strip.scrollLeft = savedScrollLeft;
|
|
462
|
+
updateEdgeFades(strip);
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
renderOverflowMenu(el, container, getChildTabs(el));
|
|
466
|
+
const triggerCost = container.clientWidth - strip.clientWidth;
|
|
467
|
+
if (hidden <= triggerCost) {
|
|
468
|
+
removeOverflowMenu(shadowRoot);
|
|
469
|
+
}
|
|
470
|
+
strip.scrollLeft = savedScrollLeft;
|
|
471
|
+
updateEdgeFades(strip);
|
|
472
|
+
}
|
|
473
|
+
function updateEdgeFades(strip) {
|
|
474
|
+
const maxScroll = strip.scrollWidth - strip.clientWidth;
|
|
475
|
+
const fade = (distance) => `${distance > 1 ? Math.min(28, distance) : 0}px`;
|
|
476
|
+
strip.style.setProperty('--fade-left', fade(strip.scrollLeft));
|
|
477
|
+
strip.style.setProperty('--fade-right', fade(maxScroll - strip.scrollLeft));
|
|
478
|
+
}
|
|
479
|
+
function scrollActiveIntoView(el, activeId, smooth) {
|
|
480
|
+
const shadowRoot = el.shadowRoot;
|
|
481
|
+
if (!shadowRoot)
|
|
482
|
+
return;
|
|
483
|
+
const strip = shadowRoot.querySelector('.tab-strip');
|
|
484
|
+
const button = shadowRoot.querySelector(`[data-tab-id='${activeId}']`);
|
|
485
|
+
if (!strip || !button || strip.clientWidth <= 0)
|
|
486
|
+
return;
|
|
487
|
+
const centered = button.offsetLeft + button.offsetWidth / 2 - strip.clientWidth / 2;
|
|
488
|
+
const target = Math.max(0, Math.min(centered, strip.scrollWidth - strip.clientWidth));
|
|
489
|
+
if (Math.round(target) !== Math.round(strip.scrollLeft)) {
|
|
490
|
+
const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
491
|
+
strip.scrollTo({ left: target, behavior: smooth && !reduce ? 'smooth' : 'auto' });
|
|
492
|
+
}
|
|
407
493
|
}
|
|
408
494
|
function render(el) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
updateOverflow(el);
|
|
487
|
-
});
|
|
488
|
-
setupEventListeners(el, shadowRoot, tabs);
|
|
489
|
-
updateAriaAttributes(el, shadowRoot, activeId || '');
|
|
490
|
-
setupResizeObserver(el);
|
|
491
|
-
if (activeId) {
|
|
492
|
-
updatePanelInteraction(el, activeId);
|
|
493
|
-
}
|
|
494
|
-
const markerSlot = shadowRoot.querySelector('slot[name="marker"]');
|
|
495
|
-
if (markerSlot) {
|
|
496
|
-
const updateDefaultMarkerVisibility = () => {
|
|
497
|
-
const defaultMarker = shadowRoot.querySelector('.default-marker');
|
|
498
|
-
if (defaultMarker) {
|
|
499
|
-
const hasCustom = markerSlot.assignedElements().length > 0;
|
|
500
|
-
defaultMarker.style.display = hasCustom ? 'none' : '';
|
|
501
|
-
}
|
|
502
|
-
};
|
|
503
|
-
markerSlot.addEventListener('slotchange', updateDefaultMarkerVisibility);
|
|
504
|
-
updateDefaultMarkerVisibility();
|
|
505
|
-
}
|
|
506
|
-
}
|
|
495
|
+
const shadowRoot = el.shadowRoot;
|
|
496
|
+
if (!shadowRoot)
|
|
497
|
+
return;
|
|
498
|
+
const { placement, fixed } = getTabsAttributes(el);
|
|
499
|
+
const tabs = getChildTabs(el);
|
|
500
|
+
const activeId = getActiveTabId(el, tabs);
|
|
501
|
+
const activeIndex = activeId ? (findTabIndex(tabs, activeId) ?? 0) : 0;
|
|
502
|
+
tabs.forEach((tab) => tab.setPanelLabel?.(getTabMenuLabel(el, tab)));
|
|
503
|
+
const existingContainer = shadowRoot.querySelector('.tabs-container');
|
|
504
|
+
const existingButtons = shadowRoot.querySelector('.tab-buttons');
|
|
505
|
+
const existingStrip = shadowRoot.querySelector('.tab-strip');
|
|
506
|
+
const existingViewport = shadowRoot.querySelector('.panels-viewport');
|
|
507
|
+
ensureStyles(shadowRoot, { css: tabsStyles, id: 'ty-tabs' });
|
|
508
|
+
if (existingContainer && existingButtons && existingStrip && existingViewport) {
|
|
509
|
+
existingContainer.setAttribute('data-placement', placement);
|
|
510
|
+
existingContainer.toggleAttribute('data-fixed', fixed);
|
|
511
|
+
const savedScrollLeft = existingStrip.scrollLeft;
|
|
512
|
+
existingButtons.querySelector('.tab-overflow-trigger')?.remove();
|
|
513
|
+
const allButtons = existingStrip.querySelectorAll('.tab-button');
|
|
514
|
+
allButtons.forEach(button => button.remove());
|
|
515
|
+
const buttonsHtml = renderButtonsOnly(el, tabs, activeId);
|
|
516
|
+
const tempDiv = document.createElement('div');
|
|
517
|
+
tempDiv.innerHTML = buttonsHtml;
|
|
518
|
+
Array.from(tempDiv.children).forEach(button => {
|
|
519
|
+
existingStrip.appendChild(button);
|
|
520
|
+
});
|
|
521
|
+
existingStrip.scrollLeft = savedScrollLeft;
|
|
522
|
+
setupEventListeners(el, shadowRoot, tabs);
|
|
523
|
+
updateAriaAttributes(el, shadowRoot, activeId || '');
|
|
524
|
+
const firstShow = !shownTabs.get(el);
|
|
525
|
+
requestAnimationFrame(() => {
|
|
526
|
+
const currentId = currentActive(el);
|
|
527
|
+
updateOverflow(el);
|
|
528
|
+
if (currentId) {
|
|
529
|
+
updateMarker(el, currentId, firstShow);
|
|
530
|
+
scrollActiveIntoView(el, currentId, !firstShow);
|
|
531
|
+
}
|
|
532
|
+
});
|
|
533
|
+
updatePanelInteraction(el, activeId);
|
|
534
|
+
}
|
|
535
|
+
else {
|
|
536
|
+
shadowRoot.innerHTML = `
|
|
537
|
+
<div class="tabs-container" data-placement="${placement}"${fixed ? ' data-fixed' : ''}>
|
|
538
|
+
${renderTabButtons(el, tabs, activeId)}
|
|
539
|
+
<div class="panels-viewport" part="panels-container">
|
|
540
|
+
<div class="panels-wrapper" style="transform: ${carouselTransform(activeIndex)}">
|
|
541
|
+
<slot></slot>
|
|
542
|
+
</div>
|
|
543
|
+
</div>
|
|
544
|
+
</div>
|
|
545
|
+
`;
|
|
546
|
+
requestAnimationFrame(() => {
|
|
547
|
+
const currentId = currentActive(el);
|
|
548
|
+
updateOverflow(el);
|
|
549
|
+
if (currentId) {
|
|
550
|
+
updateMarker(el, currentId);
|
|
551
|
+
scrollActiveIntoView(el, currentId, false);
|
|
552
|
+
}
|
|
553
|
+
});
|
|
554
|
+
setupEventListeners(el, shadowRoot, tabs);
|
|
555
|
+
updateAriaAttributes(el, shadowRoot, activeId || '');
|
|
556
|
+
const strip = shadowRoot.querySelector('.tab-strip');
|
|
557
|
+
strip?.addEventListener('scroll', () => updateEdgeFades(strip), { passive: true });
|
|
558
|
+
updatePanelInteraction(el, activeId);
|
|
559
|
+
const markerSlot = shadowRoot.querySelector('slot[name="marker"]');
|
|
560
|
+
if (markerSlot) {
|
|
561
|
+
const updateDefaultMarkerVisibility = () => {
|
|
562
|
+
const defaultMarker = shadowRoot.querySelector('.default-marker');
|
|
563
|
+
if (defaultMarker) {
|
|
564
|
+
const hasCustom = markerSlot.assignedElements().length > 0;
|
|
565
|
+
defaultMarker.style.display = hasCustom ? 'none' : '';
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
markerSlot.addEventListener('slotchange', updateDefaultMarkerVisibility);
|
|
569
|
+
updateDefaultMarkerVisibility();
|
|
570
|
+
}
|
|
571
|
+
}
|
|
507
572
|
}
|
|
508
573
|
function cleanup(el) {
|
|
509
|
-
|
|
510
|
-
|
|
574
|
+
cleanupEventListeners(el);
|
|
575
|
+
cleanupResizeObserver(el);
|
|
511
576
|
}
|
|
512
577
|
export class TyTabs extends HTMLElement {
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
578
|
+
static get observedAttributes() {
|
|
579
|
+
return ['width', 'height', 'active', 'placement', 'fixed'];
|
|
580
|
+
}
|
|
581
|
+
constructor() {
|
|
582
|
+
super();
|
|
583
|
+
this._childObserver = null;
|
|
584
|
+
this._updateQueued = false;
|
|
585
|
+
this._structureDirty = false;
|
|
586
|
+
this.attachShadow({ mode: 'open' });
|
|
587
|
+
}
|
|
588
|
+
get activeTab() {
|
|
589
|
+
return shownTabs.get(this) ?? null;
|
|
590
|
+
}
|
|
591
|
+
connectedCallback() {
|
|
592
|
+
render(this);
|
|
593
|
+
syncShownTab(this);
|
|
594
|
+
setupResizeObserver(this);
|
|
595
|
+
this._childObserver = new MutationObserver(() => this._queueUpdate(true));
|
|
596
|
+
this._childObserver.observe(this, { childList: true });
|
|
597
|
+
}
|
|
598
|
+
disconnectedCallback() {
|
|
599
|
+
this._childObserver?.disconnect();
|
|
600
|
+
this._childObserver = null;
|
|
601
|
+
cleanup(this);
|
|
602
|
+
}
|
|
603
|
+
_queueUpdate(structure) {
|
|
604
|
+
this._structureDirty || (this._structureDirty = structure);
|
|
605
|
+
if (this._updateQueued)
|
|
606
|
+
return;
|
|
607
|
+
this._updateQueued = true;
|
|
608
|
+
queueMicrotask(() => {
|
|
609
|
+
this._updateQueued = false;
|
|
610
|
+
if (!this.isConnected)
|
|
611
|
+
return;
|
|
612
|
+
if (this._childObserver?.takeRecords().length)
|
|
613
|
+
this._structureDirty = true;
|
|
614
|
+
if (this._structureDirty) {
|
|
615
|
+
this._structureDirty = false;
|
|
616
|
+
render(this);
|
|
617
|
+
}
|
|
618
|
+
syncShownTab(this);
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
622
|
+
if (!this.isConnected)
|
|
623
|
+
return;
|
|
624
|
+
if (name === 'active') {
|
|
625
|
+
if (oldValue !== newValue)
|
|
626
|
+
awaitedTabs.delete(this);
|
|
627
|
+
this._queueUpdate(false);
|
|
628
|
+
}
|
|
629
|
+
else
|
|
630
|
+
render(this);
|
|
631
|
+
}
|
|
552
632
|
}
|
|
553
633
|
if (!customElements.get('ty-tabs')) {
|
|
554
|
-
|
|
634
|
+
customElements.define('ty-tabs', TyTabs);
|
|
555
635
|
}
|