@salesforcedevs/arch-components 1.20.17-alpha2 → 1.20.17-alpha4
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/package.json +1 -1
- package/src/modules/common/context/context.ts +14 -14
- package/src/modules/common/effectAdapter/__tests__/effectAdapter.test.ts +4 -4
- package/src/modules/common/effectAdapter/effectAdapter.ts +13 -7
- package/src/modules/common/reflectedElement/__tests__/reflectedElement.test.ts +5 -5
- package/src/modules/common/reflectedElement/reflectedElement.ts +1 -1
- package/src/modules/common/slot/__tests__/slot.test.ts +12 -12
- package/src/modules/common/slot/slot.ts +4 -3
- package/src/modules/sa/coverage/coverage.ts +14 -18
- package/src/modules/sa/coverage/types.d.ts +12 -12
- package/src/modules/sa/explorer/explorer.ts +25 -25
- package/src/modules/sa/gallery/gallery.ts +11 -11
- package/src/modules/shared/a11y/a11y.ts +5 -5
- package/src/modules/shared/color/color.ts +13 -13
- package/src/modules/shared/fetch/fetch.ts +6 -6
- package/src/modules/shared/helpers/helpers.ts +6 -6
- package/src/modules/shared/i18n/i18n.ts +1 -1
- package/src/modules/shared/labels/__tests__/helpers.test.ts +3 -3
- package/src/modules/shared/labels/__tests__/pointHelpers.test.ts +3 -3
- package/src/modules/shared/labels/__tests__/timeHelpers.test.ts +8 -8
- package/src/modules/shared/labels/helpers.ts +4 -4
- package/src/modules/shared/labels/pointHelpers.ts +2 -2
- package/src/modules/shared/labels/timeHelpers.ts +3 -3
- package/src/modules/shared/menu/menu.ts +22 -22
- package/src/modules/shared/polling-request.ts +2 -2
- package/src/modules/shared/testutils.ts +4 -4
- package/src/modules/shared/useEffectAttr.ts +5 -5
- package/src/modules/tds/appLauncher/__tests__/appLauncher.test.ts +8 -8
- package/src/modules/tds/appLauncher/appLauncher.ts +6 -6
- package/src/modules/tds/avatar/__tests__/avatar.test.ts +1 -1
- package/src/modules/tds/button/__tests__/button.test.ts +5 -5
- package/src/modules/tds/buttonIcon/__tests__/buttonIcon.test.ts +1 -1
- package/src/modules/tds/buttonLink/__tests__/buttonLink.test.ts +1 -1
- package/src/modules/tds/childSummary/childSummary.ts +2 -2
- package/src/modules/tds/contentChildListItem/__tests__/contentChildListItem.test.ts +2 -2
- package/src/modules/tds/contentIcon/contentIcon.ts +1 -1
- package/src/modules/tds/footerLinks/__tests__/footerLinks.test.ts +2 -2
- package/src/modules/tds/headerAvatar/__tests__/headerAvatar.test.ts +4 -4
- package/src/modules/tds/headerAvatar/headerAvatar.ts +5 -5
- package/src/modules/tds/headerHelpButton/__tests__/headerHelpButton.test.ts +2 -2
- package/src/modules/tds/heading/__tests__/heading.test.ts +7 -7
- package/src/modules/tds/icon/icon.ts +11 -11
- package/src/modules/tds/radio/__tests__/radio.test.ts +1 -1
- package/src/modules/tds/search/__tests__/search.test.ts +17 -17
- package/src/modules/tds/search/lib/__tests__/listbox.test.ts +16 -16
- package/src/modules/tds/search/lib/listbox.ts +16 -16
- package/src/modules/tds/search/search.ts +10 -10
- package/src/modules/tds/select/__tests__/select.test.ts +1 -1
- package/src/modules/tds/summary/__tests__/summary.test.ts +16 -16
- package/src/modules/tds/summary/summary.ts +2 -2
- package/src/modules/tds/themeProvider/themeProvider.ts +4 -4
- package/src/modules/th/favoriteButton/__tests__/favoriteButton.test.ts +1 -1
- package/src/modules/th/favoriteButton/mocks/index.ts +2 -2
- package/src/modules/th/search/__tests__/search.test.ts +2 -2
- package/src/modules/th/search/mocks/index.ts +1 -1
- package/src/modules/th/search/search.ts +21 -21
- package/src/modules/tm/card/card.ts +15 -15
- package/src/modules/tm/content/content.ts +11 -11
- package/src/modules/tm/endCapA/__tests__/endCapA.test.ts +2 -2
- package/src/modules/tm/eventsA/eventsA.ts +1 -1
- package/src/modules/tm/faqA/faqA.ts +4 -4
- package/src/modules/tm/featureGridA/__tests__/featureGridA.test.ts +2 -2
- package/src/modules/tm/footnote/footnote.ts +1 -1
- package/src/modules/tm/heroA/__tests__/heroA.test.ts +2 -2
- package/src/modules/tm/heroA/heroA.ts +3 -3
- package/src/modules/tm/promoA/__tests__/promoA.test.ts +3 -3
- package/src/modules/tm/promoA/promoA.ts +4 -4
- package/src/modules/tm/sectionA/sectionA.ts +1 -1
- package/src/modules/tm/utils/utils.ts +5 -5
- package/src/modules/tm/youtube/youtube.ts +2 -2
- package/src/modules/ui/focusTrap/focusTrap.ts +7 -7
- package/src/modules/ui/focusVisible/focusVisible.ts +7 -7
- package/src/modules/th/tbid/__tests__/__snapshots__/tbid.test.ts.snap +0 -3
- package/src/modules/th/tbid/__tests__/tbid.test.ts +0 -242
- package/src/modules/th/tbid/tbid.html +0 -1
- package/src/modules/th/tbid/tbid.stories.mdx +0 -25
- package/src/modules/th/tbid/tbid.ts +0 -215
|
@@ -2,11 +2,11 @@ export function hexToRGB(h: string) {
|
|
|
2
2
|
let r = 0;
|
|
3
3
|
let g = 0;
|
|
4
4
|
let b = 0;
|
|
5
|
-
if (h.length
|
|
5
|
+
if (h.length === 4) {
|
|
6
6
|
r = +('0x' + h[1] + h[1]);
|
|
7
7
|
g = +('0x' + h[2] + h[2]);
|
|
8
8
|
b = +('0x' + h[3] + h[3]);
|
|
9
|
-
} else if (h.length
|
|
9
|
+
} else if (h.length === 7) {
|
|
10
10
|
r = +('0x' + h[1] + h[2]);
|
|
11
11
|
g = +('0x' + h[3] + h[4]);
|
|
12
12
|
b = +('0x' + h[5] + h[6]);
|
|
@@ -18,20 +18,20 @@ export function RGBToHSL(r: number, g: number, b: number) {
|
|
|
18
18
|
r /= 255;
|
|
19
19
|
g /= 255;
|
|
20
20
|
b /= 255;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
const cmin = Math.min(r, g, b);
|
|
22
|
+
const cmax = Math.max(r, g, b);
|
|
23
|
+
const delta = cmax - cmin;
|
|
24
24
|
let h = 0;
|
|
25
25
|
let s = 0;
|
|
26
26
|
let l = 0;
|
|
27
|
-
if (delta === 0) h = 0;
|
|
28
|
-
else if (cmax === r) h = ((g - b) / delta) % 6;
|
|
29
|
-
else if (cmax === g) h = (b - r) / delta + 2;
|
|
30
|
-
else h = (r - g) / delta + 4;
|
|
27
|
+
if (delta === 0) {h = 0;}
|
|
28
|
+
else if (cmax === r) {h = ((g - b) / delta) % 6;}
|
|
29
|
+
else if (cmax === g) {h = (b - r) / delta + 2;}
|
|
30
|
+
else {h = (r - g) / delta + 4;}
|
|
31
31
|
h = Math.round(h * 60);
|
|
32
|
-
if (h < 0) h += 360;
|
|
32
|
+
if (h < 0) {h += 360;}
|
|
33
33
|
l = (cmax + cmin) / 2;
|
|
34
|
-
s = delta
|
|
34
|
+
s = delta === 0 ? 0 : delta / (1 - Math.abs(2 * l - 1));
|
|
35
35
|
s = +s.toFixed(1);
|
|
36
36
|
l = +l.toFixed(1);
|
|
37
37
|
return [h, s, l];
|
|
@@ -46,7 +46,7 @@ export function hsl(h: number, s: number, l: number) {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export function lightenHex(hex: string, by: number) {
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
const [r, g, b] = hexToRGB(hex);
|
|
50
|
+
const [h, s, l] = RGBToHSL(r, g, b);
|
|
51
51
|
return hsl(h, s, l + by);
|
|
52
52
|
}
|
|
@@ -4,7 +4,7 @@ export function csrfHeader(token: string = '') {
|
|
|
4
4
|
};
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
export function fetch(url: string, { ...options }: RequestInit = {}) {
|
|
7
|
+
export function fetch(url: string, { ...options }: globalThis.RequestInit = {}) {
|
|
8
8
|
return window.fetch(url, {
|
|
9
9
|
...options,
|
|
10
10
|
credentials: 'same-origin'
|
|
@@ -13,7 +13,7 @@ export function fetch(url: string, { ...options }: RequestInit = {}) {
|
|
|
13
13
|
|
|
14
14
|
export function fetchJSON<T>(
|
|
15
15
|
url: string,
|
|
16
|
-
{ headers, ...options }: RequestInit = {}
|
|
16
|
+
{ headers, ...options }: globalThis.RequestInit = {}
|
|
17
17
|
) {
|
|
18
18
|
return fetch(url, {
|
|
19
19
|
...options,
|
|
@@ -22,11 +22,11 @@ export function fetchJSON<T>(
|
|
|
22
22
|
Accept: 'application/json; charset=utf-8'
|
|
23
23
|
}
|
|
24
24
|
}).then(async (response) => {
|
|
25
|
-
if (response.ok) return response.json() as Promise<T>;
|
|
25
|
+
if (response.ok) {return response.json() as Promise<T>;}
|
|
26
26
|
if (/json/.test(String(response.headers.get('Content-Type'))))
|
|
27
|
-
return response
|
|
27
|
+
{return response
|
|
28
28
|
.json()
|
|
29
|
-
.then((errorJSON) => Promise.reject(errorJSON));
|
|
29
|
+
.then((errorJSON) => Promise.reject(errorJSON));}
|
|
30
30
|
throw new Error(
|
|
31
31
|
`Application error code ${response.status} for "${url}"`
|
|
32
32
|
);
|
|
@@ -38,7 +38,7 @@ export { fetchJSON as getJSON };
|
|
|
38
38
|
export function postJSON<T>(
|
|
39
39
|
url: string,
|
|
40
40
|
body?: object,
|
|
41
|
-
{ headers, method = 'POST', ...options }: RequestInit = {}
|
|
41
|
+
{ headers, method = 'POST', ...options }: globalThis.RequestInit = {}
|
|
42
42
|
) {
|
|
43
43
|
return fetchJSON<T>(url, {
|
|
44
44
|
...options,
|
|
@@ -9,13 +9,13 @@ export function attrToBool(attr: any) {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export function hash(value: string) {
|
|
12
|
-
let
|
|
12
|
+
let hashValue = 0;
|
|
13
13
|
for (let i = 0; i < value.length; i++) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const char = value.charCodeAt(i);
|
|
15
|
+
hashValue = (hashValue << 5) - hashValue + char;
|
|
16
|
+
hashValue |= 0;
|
|
17
17
|
}
|
|
18
|
-
return
|
|
18
|
+
return hashValue;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export function createImageUrl(image: string, hash: string) {
|
|
@@ -50,7 +50,7 @@ export function sendInteractionEvent(name: string, type: string, event: any, tar
|
|
|
50
50
|
let text: string = '';
|
|
51
51
|
let eventValue: string = '';
|
|
52
52
|
let channelAction: string = '';
|
|
53
|
-
|
|
53
|
+
const channelActionStatus: string = channelActionsStatus.SUCCESS;
|
|
54
54
|
const pageUrl = new URL(document.location.href);
|
|
55
55
|
const searchTitle = pageUrl.searchParams.get('keywords') || '';
|
|
56
56
|
if (
|
|
@@ -20,7 +20,7 @@ const dict: LabelsDict = {
|
|
|
20
20
|
|
|
21
21
|
describe('label', () => {
|
|
22
22
|
describe('default language', () => {
|
|
23
|
-
|
|
23
|
+
const lang = 'en';
|
|
24
24
|
|
|
25
25
|
describe('known keys', () => {
|
|
26
26
|
it('finds key and returns the value', () => {
|
|
@@ -52,7 +52,7 @@ describe('label', () => {
|
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
describe('language with region', () => {
|
|
55
|
-
|
|
55
|
+
const lang = 'es-MX';
|
|
56
56
|
|
|
57
57
|
describe('known keys', () => {
|
|
58
58
|
it('finds key and returns the value', () => {
|
|
@@ -86,7 +86,7 @@ describe('label', () => {
|
|
|
86
86
|
});
|
|
87
87
|
|
|
88
88
|
describe('language not found', () => {
|
|
89
|
-
|
|
89
|
+
const lang = 'de';
|
|
90
90
|
|
|
91
91
|
describe('fallbacks', () => {
|
|
92
92
|
it('fails to find key and falls back to english', () => {
|
|
@@ -2,7 +2,7 @@ import { pointLabel } from '../pointHelpers';
|
|
|
2
2
|
|
|
3
3
|
describe('pointLabel', () => {
|
|
4
4
|
describe('en', () => {
|
|
5
|
-
|
|
5
|
+
const lang = 'en';
|
|
6
6
|
|
|
7
7
|
it('returns correct values', () => {
|
|
8
8
|
expect(pointLabel(lang, 0)).toEqual('0 Points');
|
|
@@ -12,7 +12,7 @@ describe('pointLabel', () => {
|
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
describe('es-MX', () => {
|
|
15
|
-
|
|
15
|
+
const lang = 'es-MX';
|
|
16
16
|
|
|
17
17
|
it('returns correct values', () => {
|
|
18
18
|
expect(pointLabel(lang, 0)).toEqual('0 puntos');
|
|
@@ -22,7 +22,7 @@ describe('pointLabel', () => {
|
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
describe('fj', () => {
|
|
25
|
-
|
|
25
|
+
const lang = 'fj';
|
|
26
26
|
|
|
27
27
|
it('returns correct values', () => {
|
|
28
28
|
expect(pointLabel(lang, 0)).toEqual('0 Points');
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { hoursMinutesLabel, hoursMinutesLeftLabel } from '../timeHelpers';
|
|
2
2
|
|
|
3
3
|
describe('hoursMinutesLabel', () => {
|
|
4
|
-
|
|
4
|
+
const subject = hoursMinutesLabel;
|
|
5
5
|
|
|
6
6
|
describe('en', () => {
|
|
7
|
-
|
|
7
|
+
const lang = 'en';
|
|
8
8
|
|
|
9
9
|
it('returns correct values', () => {
|
|
10
10
|
expect(subject(lang, 0)).toEqual('');
|
|
@@ -20,7 +20,7 @@ describe('hoursMinutesLabel', () => {
|
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
describe('es-MX', () => {
|
|
23
|
-
|
|
23
|
+
const lang = 'es-MX';
|
|
24
24
|
|
|
25
25
|
it('falls back to es', () => {
|
|
26
26
|
expect(subject(lang, 0)).toEqual('');
|
|
@@ -36,7 +36,7 @@ describe('hoursMinutesLabel', () => {
|
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
describe('fj', () => {
|
|
39
|
-
|
|
39
|
+
const lang = 'fj';
|
|
40
40
|
|
|
41
41
|
it('falls back to en', () => {
|
|
42
42
|
expect(subject(lang, 1)).toEqual('~1 min');
|
|
@@ -45,10 +45,10 @@ describe('hoursMinutesLabel', () => {
|
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
describe('hoursMinutesLeftLabel', () => {
|
|
48
|
-
|
|
48
|
+
const subject = hoursMinutesLeftLabel;
|
|
49
49
|
|
|
50
50
|
describe('en', () => {
|
|
51
|
-
|
|
51
|
+
const lang = 'en';
|
|
52
52
|
|
|
53
53
|
it('returns correct values', () => {
|
|
54
54
|
expect(subject(lang, 0)).toEqual('');
|
|
@@ -64,7 +64,7 @@ describe('hoursMinutesLeftLabel', () => {
|
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
describe('es-MX', () => {
|
|
67
|
-
|
|
67
|
+
const lang = 'es-MX';
|
|
68
68
|
|
|
69
69
|
it('falls back to es', () => {
|
|
70
70
|
expect(subject(lang, 0)).toEqual('');
|
|
@@ -80,7 +80,7 @@ describe('hoursMinutesLeftLabel', () => {
|
|
|
80
80
|
});
|
|
81
81
|
|
|
82
82
|
describe('fj', () => {
|
|
83
|
-
|
|
83
|
+
const lang = 'fj';
|
|
84
84
|
|
|
85
85
|
it('falls back to en', () => {
|
|
86
86
|
expect(subject(lang, 1)).toEqual('~1 min left');
|
|
@@ -8,15 +8,15 @@ export function label(
|
|
|
8
8
|
labelKey: string,
|
|
9
9
|
values: (string | number)[] = []
|
|
10
10
|
): string {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const [langBase] = lang.split('-');
|
|
12
|
+
const labels = {
|
|
13
13
|
...dict[DEFAULT_LANGUAGE],
|
|
14
14
|
...dict[langBase],
|
|
15
15
|
...dict[lang]
|
|
16
16
|
};
|
|
17
17
|
let str = labels[labelKey];
|
|
18
|
-
if (str === undefined) return labelKey;
|
|
19
|
-
for (
|
|
18
|
+
if (str === undefined) {return labelKey;}
|
|
19
|
+
for (const val of values) {
|
|
20
20
|
str = str.replace('%{n}', val.toString());
|
|
21
21
|
}
|
|
22
22
|
return str;
|
|
@@ -40,8 +40,8 @@ export function pointLabel(lang: string, points: number | undefined) {
|
|
|
40
40
|
return label(lang, labels, 'zero', [points]);
|
|
41
41
|
} else if (points === 1) {
|
|
42
42
|
return label(lang, labels, 'one', [points]);
|
|
43
|
-
}
|
|
43
|
+
}
|
|
44
44
|
return label(lang, labels, 'many', [points]);
|
|
45
|
-
|
|
45
|
+
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -123,7 +123,7 @@ function hoursMinutesLabelArgs(timeInMinutes: number) {
|
|
|
123
123
|
const mins = timeInMinutes % 60;
|
|
124
124
|
|
|
125
125
|
let key = '';
|
|
126
|
-
|
|
126
|
+
const values = [];
|
|
127
127
|
|
|
128
128
|
if (hrs > 0) {
|
|
129
129
|
values.push(hrs);
|
|
@@ -166,7 +166,7 @@ function hoursMinutesLabelArgs(timeInMinutes: number) {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
export function hoursMinutesLabel(lang: string, timeInMinutes: number) {
|
|
169
|
-
|
|
169
|
+
const labelInfo = hoursMinutesLabelArgs(timeInMinutes);
|
|
170
170
|
|
|
171
171
|
return timeInMinutes
|
|
172
172
|
? label(lang, labels, `${labelInfo.key}`, labelInfo.values)
|
|
@@ -174,7 +174,7 @@ export function hoursMinutesLabel(lang: string, timeInMinutes: number) {
|
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
export function hoursMinutesLeftLabel(lang: string, timeInMinutes: number) {
|
|
177
|
-
|
|
177
|
+
const labelInfo = hoursMinutesLabelArgs(timeInMinutes);
|
|
178
178
|
|
|
179
179
|
return timeInMinutes
|
|
180
180
|
? label(lang, labels, `${labelInfo.key}Left`, labelInfo.values)
|
|
@@ -49,7 +49,7 @@ export class Menu {
|
|
|
49
49
|
| Partial<MenuState>
|
|
50
50
|
| ((state: MenuState) => Partial<MenuState>)
|
|
51
51
|
) {
|
|
52
|
-
|
|
52
|
+
const { state } = this;
|
|
53
53
|
this.state = {
|
|
54
54
|
...state,
|
|
55
55
|
...(typeof nextState === 'function' ? nextState(state) : nextState)
|
|
@@ -58,8 +58,8 @@ export class Menu {
|
|
|
58
58
|
|
|
59
59
|
renderedCallback() {
|
|
60
60
|
if (!this.state.setup) {
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
const $trigger = this.getElement(SELECTOR_TRIGGER)!;
|
|
62
|
+
const $menu = this.getElement(SELECTOR_MENU)!;
|
|
63
63
|
$trigger.addEventListener('click', this.onTriggerClick as EventListener);
|
|
64
64
|
$trigger.addEventListener('keydown', this.onTriggerKeyDown as EventListener);
|
|
65
65
|
$menu.addEventListener('blur', this.onMenuBlur as EventListener);
|
|
@@ -78,8 +78,8 @@ export class Menu {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
disconnectedCallback() {
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
const $trigger = this.getElement(SELECTOR_TRIGGER)!;
|
|
82
|
+
const $menu = this.getElement(SELECTOR_MENU)!;
|
|
83
83
|
$trigger.removeEventListener('click', this.onTriggerClick as EventListener);
|
|
84
84
|
$trigger.removeEventListener('keydown', this.onTriggerKeyDown as EventListener);
|
|
85
85
|
$menu.removeEventListener('blur', this.onMenuBlur as EventListener);
|
|
@@ -106,8 +106,8 @@ export class Menu {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
private onTriggerClick = (e: MouseEvent) => {
|
|
109
|
-
if (this.state.open) this.close();
|
|
110
|
-
else this.open();
|
|
109
|
+
if (this.state.open) {this.close();}
|
|
110
|
+
else {this.open();}
|
|
111
111
|
};
|
|
112
112
|
|
|
113
113
|
private onTriggerKeyDown = (e: KeyboardEvent) => {
|
|
@@ -124,9 +124,9 @@ export class Menu {
|
|
|
124
124
|
|
|
125
125
|
private onMenuBlur = (e: FocusEvent) => {
|
|
126
126
|
setTimeout(() => {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if ($menu === $active || $menu.contains($active)) return;
|
|
127
|
+
const $active = this.input.shadowRoot.activeElement;
|
|
128
|
+
const $menu = this.getElement(SELECTOR_MENU)!;
|
|
129
|
+
if ($menu === $active || $menu.contains($active)) {return;}
|
|
130
130
|
this.setState({ open: false });
|
|
131
131
|
});
|
|
132
132
|
};
|
|
@@ -137,7 +137,7 @@ export class Menu {
|
|
|
137
137
|
this.setState((state) => {
|
|
138
138
|
let { selectedIndex } = state;
|
|
139
139
|
selectedIndex--;
|
|
140
|
-
if (selectedIndex < 0) selectedIndex = state.count - 1;
|
|
140
|
+
if (selectedIndex < 0) {selectedIndex = state.count - 1;}
|
|
141
141
|
return { selectedIndex };
|
|
142
142
|
});
|
|
143
143
|
break;
|
|
@@ -145,12 +145,12 @@ export class Menu {
|
|
|
145
145
|
this.setState((state) => {
|
|
146
146
|
let { selectedIndex } = state;
|
|
147
147
|
selectedIndex++;
|
|
148
|
-
if (selectedIndex === state.count) selectedIndex = 0;
|
|
148
|
+
if (selectedIndex === state.count) {selectedIndex = 0;}
|
|
149
149
|
return { selectedIndex };
|
|
150
150
|
});
|
|
151
151
|
break;
|
|
152
152
|
case 'Enter':
|
|
153
|
-
if (!this.state.open) break;
|
|
153
|
+
if (!this.state.open) {break;}
|
|
154
154
|
this.close();
|
|
155
155
|
this.select();
|
|
156
156
|
break;
|
|
@@ -167,18 +167,18 @@ export class Menu {
|
|
|
167
167
|
};
|
|
168
168
|
|
|
169
169
|
private select() {
|
|
170
|
-
|
|
170
|
+
const element = this.input.shadowRoot.querySelectorAll(
|
|
171
171
|
getSelector(SELECTOR_ITEM)
|
|
172
172
|
)[this.state.selectedIndex] as HTMLElement | undefined;
|
|
173
|
-
if (element) element.click();
|
|
173
|
+
if (element) {element.click();}
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
private setTriggerAttributes() {
|
|
177
177
|
if (!this.state.setup) {
|
|
178
178
|
return;
|
|
179
179
|
}
|
|
180
|
-
|
|
181
|
-
|
|
180
|
+
const $trigger = this.getElement(SELECTOR_TRIGGER)!;
|
|
181
|
+
const $menu = this.getElement(SELECTOR_MENU)!;
|
|
182
182
|
$trigger.setAttribute('aria-controls', $menu.getAttribute('id') || '');
|
|
183
183
|
$trigger.setAttribute('aria-expanded', String(this.state.open));
|
|
184
184
|
$trigger.setAttribute('aria-haspopup', 'true');
|
|
@@ -190,8 +190,8 @@ export class Menu {
|
|
|
190
190
|
return;
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
-
|
|
194
|
-
|
|
193
|
+
const $menu = this.getElement(SELECTOR_MENU)!;
|
|
194
|
+
const $activeDecendant = this.input.shadowRoot.querySelectorAll(
|
|
195
195
|
getSelector(SELECTOR_ITEM)
|
|
196
196
|
)[this.state.selectedIndex] as HTMLElement | undefined;
|
|
197
197
|
$menu.setAttribute(
|
|
@@ -207,13 +207,13 @@ export class Menu {
|
|
|
207
207
|
$menu.removeAttribute('tabindex');
|
|
208
208
|
}
|
|
209
209
|
this.input.shadowRoot.querySelectorAll('ui,li').forEach((node) => {
|
|
210
|
-
|
|
210
|
+
const element = node as HTMLElement;
|
|
211
211
|
element.setAttribute('role', 'presentation');
|
|
212
212
|
});
|
|
213
213
|
this.input.shadowRoot
|
|
214
214
|
.querySelectorAll(getSelector(SELECTOR_ITEM))
|
|
215
215
|
.forEach((node) => {
|
|
216
|
-
|
|
216
|
+
const element = node as HTMLElement;
|
|
217
217
|
element.setAttribute('tabindex', '-1');
|
|
218
218
|
});
|
|
219
219
|
}
|
|
@@ -222,7 +222,7 @@ export class Menu {
|
|
|
222
222
|
this.input.shadowRoot
|
|
223
223
|
.querySelectorAll(getSelector(SELECTOR_ITEM))
|
|
224
224
|
.forEach((node, i) => {
|
|
225
|
-
|
|
225
|
+
const element = node as HTMLElement;
|
|
226
226
|
element.setAttribute(
|
|
227
227
|
'data-active',
|
|
228
228
|
String(i === this.state.selectedIndex)
|
|
@@ -74,7 +74,7 @@ export class PollingRequest<T> {
|
|
|
74
74
|
const res = await this.request();
|
|
75
75
|
|
|
76
76
|
// If polling was stopped before the request could complete
|
|
77
|
-
if (currentAttempt !== this.attempt) return;
|
|
77
|
+
if (currentAttempt !== this.attempt) {return;}
|
|
78
78
|
|
|
79
79
|
if (this.done(res)) {
|
|
80
80
|
this.stop();
|
|
@@ -88,7 +88,7 @@ export class PollingRequest<T> {
|
|
|
88
88
|
}
|
|
89
89
|
} catch (err) {
|
|
90
90
|
// If polling was stopped before the request could complete
|
|
91
|
-
if (currentAttempt !== this.attempt) return;
|
|
91
|
+
if (currentAttempt !== this.attempt) {return;}
|
|
92
92
|
|
|
93
93
|
this.stop();
|
|
94
94
|
this.reject(err);
|
|
@@ -20,7 +20,7 @@ export function $testid(value: string, element: HTMLElement) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export function renderIntoBody(template: TemplateResult) {
|
|
23
|
-
|
|
23
|
+
const element = document.createElement('div');
|
|
24
24
|
document.body.append(element);
|
|
25
25
|
render(template, element);
|
|
26
26
|
return element.children[0] as HTMLElement;
|
|
@@ -35,10 +35,10 @@ export async function renderIntoBodyAndWait(
|
|
|
35
35
|
}) => boolean)
|
|
36
36
|
| string
|
|
37
37
|
) {
|
|
38
|
-
|
|
38
|
+
const element = renderIntoBody(template);
|
|
39
39
|
await new Promise((resolve) => {
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
const check = () => {
|
|
41
|
+
const isReady =
|
|
42
42
|
typeof ready === 'string'
|
|
43
43
|
? querySelector(ready, element) !== null
|
|
44
44
|
: ready({ querySelector, querySelectorAll });
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
export function useEffectAttr(fn: Function, deps: Array<string>, context: any) {
|
|
2
|
-
|
|
2
|
+
const prevValues = new Map<string, any>();
|
|
3
3
|
return () => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
for (
|
|
4
|
+
const prev = deps.map((key) => prevValues.get(key));
|
|
5
|
+
const next = deps.map((key) => context[key]);
|
|
6
|
+
for (const i in prev) {
|
|
7
7
|
if (next[i] !== prev[i]) {
|
|
8
8
|
fn.call(context);
|
|
9
9
|
break;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
for (
|
|
12
|
+
for (const k of deps) {
|
|
13
13
|
prevValues.set(k, context[k]);
|
|
14
14
|
}
|
|
15
15
|
};
|
|
@@ -41,7 +41,7 @@ describe('tds-app-launcher', () => {
|
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
it('opens the menu when the container is clicked', async () => {
|
|
44
|
-
|
|
44
|
+
const clickEvent = new MouseEvent('click', {
|
|
45
45
|
bubbles: false,
|
|
46
46
|
cancelable: true
|
|
47
47
|
});
|
|
@@ -60,7 +60,7 @@ describe('tds-app-launcher', () => {
|
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
it('render the label', () => {
|
|
63
|
-
|
|
63
|
+
const $button = querySelector(
|
|
64
64
|
'tds-button-icon button',
|
|
65
65
|
renderElement({ label: 'Fancy Apps' })
|
|
66
66
|
)!;
|
|
@@ -68,8 +68,8 @@ describe('tds-app-launcher', () => {
|
|
|
68
68
|
});
|
|
69
69
|
|
|
70
70
|
it('renders each app', async () => {
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
const apps = [...mockApps];
|
|
72
|
+
const $items = shadow.querySelectorAll('.menu__item')!;
|
|
73
73
|
apps.forEach((app, index) => {
|
|
74
74
|
expect($items[index].getAttribute('href')).toBe(app.link.href);
|
|
75
75
|
expect($items[index].textContent).toBe(app.label);
|
|
@@ -81,11 +81,11 @@ describe('tds-app-launcher', () => {
|
|
|
81
81
|
|
|
82
82
|
describe('tracking', () => {
|
|
83
83
|
it('app_launcher_clicked', async () => {
|
|
84
|
-
|
|
84
|
+
const clickEvent = new MouseEvent('click', {
|
|
85
85
|
bubbles: false,
|
|
86
86
|
cancelable: true
|
|
87
87
|
});
|
|
88
|
-
|
|
88
|
+
const handler = jest.fn();
|
|
89
89
|
document.addEventListener('trailhead_track', handler);
|
|
90
90
|
shadow
|
|
91
91
|
.querySelector('[data-menu="trigger"]')!
|
|
@@ -98,11 +98,11 @@ describe('tds-app-launcher', () => {
|
|
|
98
98
|
);
|
|
99
99
|
});
|
|
100
100
|
it('app_launcher_link_clicked', async () => {
|
|
101
|
-
|
|
101
|
+
const clickEvent = new MouseEvent('click', {
|
|
102
102
|
bubbles: false,
|
|
103
103
|
cancelable: true
|
|
104
104
|
});
|
|
105
|
-
|
|
105
|
+
const handler = jest.fn();
|
|
106
106
|
document.addEventListener('trailhead_track', handler);
|
|
107
107
|
shadow
|
|
108
108
|
.querySelector('[data-menu="item"]')!
|
|
@@ -52,7 +52,7 @@ export default class extends LightningElement {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
private onOptionClick(e: MouseEvent) {
|
|
55
|
-
|
|
55
|
+
const target = e.currentTarget as HTMLElement;
|
|
56
56
|
track(this.template.host, 'app_launcher_link_clicked', {
|
|
57
57
|
label: this.menuOptions.find((o) => o.key === target.dataset.key)!
|
|
58
58
|
.label
|
|
@@ -60,16 +60,16 @@ export default class extends LightningElement {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
private resizeMenu() {
|
|
63
|
-
|
|
64
|
-
if (!$menu) return;
|
|
63
|
+
const $menu = this.template.querySelector('.menu') as HTMLElement;
|
|
64
|
+
if (!$menu) {return;}
|
|
65
65
|
$menu.style.transform = '';
|
|
66
66
|
$menu.style.width = '';
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
const rect = $menu.getBoundingClientRect();
|
|
68
|
+
const shouldResize = this.menuState.open && rect.x < 0;
|
|
69
69
|
$menu.style.width = shouldResize
|
|
70
70
|
? 'calc(100vw - var(--tds-spacing-2) * 2)'
|
|
71
71
|
: '';
|
|
72
|
-
|
|
72
|
+
const rectResized = $menu.getBoundingClientRect();
|
|
73
73
|
$menu.style.transform = shouldResize
|
|
74
74
|
? `translate(calc(${Math.abs(
|
|
75
75
|
rectResized.x
|
|
@@ -6,6 +6,6 @@ customElements.define('tds-avatar', Avatar.CustomElementConstructor);
|
|
|
6
6
|
|
|
7
7
|
describe('tds-avatar', () => {
|
|
8
8
|
it('works', () => {
|
|
9
|
-
|
|
9
|
+
const element = renderIntoBody(html` <tds-avatar></tds-avatar> `);
|
|
10
10
|
});
|
|
11
11
|
});
|
|
@@ -6,7 +6,7 @@ customElements.define('tds-button', Button.CustomElementConstructor);
|
|
|
6
6
|
|
|
7
7
|
describe('tds-button', () => {
|
|
8
8
|
it('reflects attributes', async () => {
|
|
9
|
-
|
|
9
|
+
const element = renderIntoBody(
|
|
10
10
|
html` <tds-button aria-label="Hello"></tds-button> `
|
|
11
11
|
);
|
|
12
12
|
expect(element.shadowRoot!.querySelector('button')).toHaveAttribute(
|
|
@@ -16,7 +16,7 @@ describe('tds-button', () => {
|
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
it('can show a spinner', () => {
|
|
19
|
-
|
|
19
|
+
const element = renderIntoBody(
|
|
20
20
|
html` <tds-button spinner>Creating...</tds-button> `
|
|
21
21
|
);
|
|
22
22
|
|
|
@@ -24,7 +24,7 @@ describe('tds-button', () => {
|
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
it('applies size small class', async () => {
|
|
27
|
-
|
|
27
|
+
const element = renderIntoBody(
|
|
28
28
|
html` <tds-button size="small"></tds-button> `
|
|
29
29
|
);
|
|
30
30
|
expect(
|
|
@@ -33,7 +33,7 @@ describe('tds-button', () => {
|
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
it('applies size large class', async () => {
|
|
36
|
-
|
|
36
|
+
const element = renderIntoBody(
|
|
37
37
|
html` <tds-button size="large"></tds-button> `
|
|
38
38
|
);
|
|
39
39
|
expect(
|
|
@@ -42,7 +42,7 @@ describe('tds-button', () => {
|
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
it('does not apply invalid size class', async () => {
|
|
45
|
-
|
|
45
|
+
const element = renderIntoBody(
|
|
46
46
|
html` <tds-button size="floogle"></tds-button> `
|
|
47
47
|
);
|
|
48
48
|
expect(
|
|
@@ -6,7 +6,7 @@ customElements.define('tds-button-icon', ButtonIcon.CustomElementConstructor);
|
|
|
6
6
|
|
|
7
7
|
describe('tds-button-icon', () => {
|
|
8
8
|
it('reflects attributes', async () => {
|
|
9
|
-
|
|
9
|
+
const element = renderIntoBody(
|
|
10
10
|
html` <tds-button-icon aria-label="Hello"></tds-button-icon> `
|
|
11
11
|
);
|
|
12
12
|
expect(element.shadowRoot!.querySelector('button')).toHaveAttribute(
|