@internetarchive/ia-topnav 1.4.0 → 1.4.1-alpha-webdev8259.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.
- package/.prettierignore +1 -1
- package/LICENSE +661 -661
- package/README.md +147 -147
- package/demo/index.html +28 -28
- package/dist/index.d.ts +1 -0
- package/dist/index.js.map +1 -1
- package/dist/src/data/menus.js.map +1 -1
- package/dist/src/dropdown-menu.js +26 -26
- package/dist/src/dropdown-menu.js.map +1 -1
- package/dist/src/ia-topnav.d.ts +4 -1
- package/dist/src/ia-topnav.js +96 -81
- package/dist/src/ia-topnav.js.map +1 -1
- package/dist/src/lib/keyboard-navigation.js.map +1 -1
- package/dist/src/login-button.js +17 -17
- package/dist/src/login-button.js.map +1 -1
- package/dist/src/media-menu.js +21 -21
- package/dist/src/media-menu.js.map +1 -1
- package/dist/src/models.d.ts +1 -0
- package/dist/src/models.js.map +1 -1
- package/dist/src/primary-nav.d.ts +3 -1
- package/dist/src/primary-nav.js +118 -95
- package/dist/src/primary-nav.js.map +1 -1
- package/dist/src/styles/login-button.js +87 -87
- package/dist/src/styles/login-button.js.map +1 -1
- package/dist/src/styles/primary-nav.js +343 -308
- package/dist/src/styles/primary-nav.js.map +1 -1
- package/dist/src/user-menu.js +13 -13
- package/dist/src/user-menu.js.map +1 -1
- package/dist/test/ia-topnav.test.js +39 -9
- package/dist/test/ia-topnav.test.js.map +1 -1
- package/dist/test/primary-nav.test.js +55 -7
- package/dist/test/primary-nav.test.js.map +1 -1
- package/eslint.config.mjs +53 -53
- package/index.ts +4 -3
- package/package.json +72 -72
- package/prettier.config.js +9 -9
- package/src/data/menus.ts +652 -652
- package/src/dropdown-menu.ts +132 -132
- package/src/ia-topnav.ts +383 -366
- package/src/lib/keyboard-navigation.ts +166 -166
- package/src/login-button.ts +78 -78
- package/src/media-menu.ts +143 -143
- package/src/models.ts +65 -63
- package/src/primary-nav.ts +324 -296
- package/src/styles/login-button.ts +90 -90
- package/src/styles/primary-nav.ts +346 -311
- package/src/user-menu.ts +32 -32
- package/ssl/server.key +28 -28
- package/test/ia-topnav.test.ts +381 -343
- package/test/primary-nav.test.ts +163 -94
- package/tsconfig.json +31 -31
- package/web-dev-server.config.mjs +32 -32
- package/web-test-runner.config.mjs +41 -41
package/test/primary-nav.test.ts
CHANGED
|
@@ -1,94 +1,163 @@
|
|
|
1
|
-
import {
|
|
2
|
-
html,
|
|
3
|
-
fixture,
|
|
4
|
-
expect,
|
|
5
|
-
fixtureCleanup,
|
|
6
|
-
elementUpdated,
|
|
7
|
-
} from '@open-wc/testing';
|
|
8
|
-
|
|
9
|
-
import '../src/primary-nav';
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
expect(
|
|
84
|
-
expect(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
1
|
+
import {
|
|
2
|
+
html,
|
|
3
|
+
fixture,
|
|
4
|
+
expect,
|
|
5
|
+
fixtureCleanup,
|
|
6
|
+
elementUpdated,
|
|
7
|
+
} from '@open-wc/testing';
|
|
8
|
+
|
|
9
|
+
import '../src/primary-nav';
|
|
10
|
+
import {
|
|
11
|
+
IATopNavConfig,
|
|
12
|
+
IATopNavSearchSlotMode,
|
|
13
|
+
IATopNavSecondIdentitySlotMode,
|
|
14
|
+
} from '../src/models';
|
|
15
|
+
import { PrimaryNav } from '../src/primary-nav';
|
|
16
|
+
|
|
17
|
+
const component = ({
|
|
18
|
+
baseHost = 'archive.org',
|
|
19
|
+
username = '',
|
|
20
|
+
screenName = '',
|
|
21
|
+
hideSearch = false,
|
|
22
|
+
config = {},
|
|
23
|
+
searchSlotMode = '',
|
|
24
|
+
secondIdentitySlotMode = 'allow',
|
|
25
|
+
}: {
|
|
26
|
+
baseHost?: string;
|
|
27
|
+
username?: string;
|
|
28
|
+
screenName?: string;
|
|
29
|
+
hideSearch?: boolean;
|
|
30
|
+
config?: IATopNavConfig;
|
|
31
|
+
searchSlotMode?: IATopNavSearchSlotMode;
|
|
32
|
+
secondIdentitySlotMode?: IATopNavSecondIdentitySlotMode;
|
|
33
|
+
}) =>
|
|
34
|
+
html` <primary-nav
|
|
35
|
+
.baseHost=${baseHost}
|
|
36
|
+
.username=${username}
|
|
37
|
+
.screenName=${screenName}
|
|
38
|
+
?hideSearch=${hideSearch}
|
|
39
|
+
.config=${config}
|
|
40
|
+
.searchSlotMode=${searchSlotMode}
|
|
41
|
+
.secondIdentitySlotMode=${secondIdentitySlotMode}
|
|
42
|
+
></primary-nav>`;
|
|
43
|
+
|
|
44
|
+
afterEach(() => {
|
|
45
|
+
fixtureCleanup();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('<primary-nav>', () => {
|
|
49
|
+
it('renders the login link when no username present', async () => {
|
|
50
|
+
const el = await fixture<PrimaryNav>(
|
|
51
|
+
component({
|
|
52
|
+
baseHost: 'archive.org',
|
|
53
|
+
username: '',
|
|
54
|
+
}),
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
expect(el.shadowRoot?.querySelector('login-button')).to.not.be.undefined;
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('does not render search menu toggle and search form if hideSearch true', async () => {
|
|
61
|
+
const el = await fixture<PrimaryNav>(
|
|
62
|
+
component({
|
|
63
|
+
baseHost: 'archive.org',
|
|
64
|
+
username: 'shaneriley',
|
|
65
|
+
screenName: 'shaneriley',
|
|
66
|
+
hideSearch: true,
|
|
67
|
+
}),
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
expect(el.shadowRoot?.querySelector('.search-trigger')).to.equal(null);
|
|
71
|
+
expect(el.shadowRoot?.querySelector('nav-search')).to.equal(null);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('renders nav-search by default', async () => {
|
|
75
|
+
const el = await fixture<PrimaryNav>(
|
|
76
|
+
component({
|
|
77
|
+
baseHost: 'archive.org',
|
|
78
|
+
username: 'testuser',
|
|
79
|
+
screenName: 'testuser',
|
|
80
|
+
}),
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
expect(el.shadowRoot?.querySelector('nav-search')).to.exist;
|
|
84
|
+
expect(el.shadowRoot?.querySelector('.custom-search-container')).to.not
|
|
85
|
+
.exist;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('renders custom-search slot when searchSlotMode is "custom"', async () => {
|
|
89
|
+
const el = await fixture<PrimaryNav>(
|
|
90
|
+
component({
|
|
91
|
+
baseHost: 'archive.org',
|
|
92
|
+
username: 'testuser',
|
|
93
|
+
screenName: 'testuser',
|
|
94
|
+
searchSlotMode: 'custom',
|
|
95
|
+
}),
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
expect(el.shadowRoot?.querySelector('nav-search')).to.not.exist;
|
|
99
|
+
expect(el.shadowRoot?.querySelector('.custom-search-container')).to.exist;
|
|
100
|
+
|
|
101
|
+
const slot = el.shadowRoot?.querySelector<HTMLSlotElement>(
|
|
102
|
+
'slot[name="custom-search"]',
|
|
103
|
+
);
|
|
104
|
+
expect(slot).to.exist;
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('keeps search trigger button when searchSlotMode is "custom"', async () => {
|
|
108
|
+
const el = await fixture<PrimaryNav>(
|
|
109
|
+
component({
|
|
110
|
+
baseHost: 'archive.org',
|
|
111
|
+
username: 'testuser',
|
|
112
|
+
screenName: 'testuser',
|
|
113
|
+
searchSlotMode: 'custom',
|
|
114
|
+
}),
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
expect(el.shadowRoot?.querySelector('.search-trigger')).to.exist;
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('hides custom search when hideSearch is true', async () => {
|
|
121
|
+
const el = await fixture<PrimaryNav>(
|
|
122
|
+
component({
|
|
123
|
+
baseHost: 'archive.org',
|
|
124
|
+
username: 'testuser',
|
|
125
|
+
screenName: 'testuser',
|
|
126
|
+
searchSlotMode: 'custom',
|
|
127
|
+
hideSearch: true,
|
|
128
|
+
}),
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
expect(el.shadowRoot?.querySelector('.custom-search-container')).to.not
|
|
132
|
+
.exist;
|
|
133
|
+
expect(el.shadowRoot?.querySelector('.search-trigger')).to.not.exist;
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('opens a slot with `secondIdentitySlotMode`', async () => {
|
|
137
|
+
const el = await fixture<PrimaryNav>(
|
|
138
|
+
component({
|
|
139
|
+
baseHost: 'archive.org',
|
|
140
|
+
username: 'boop',
|
|
141
|
+
screenName: 'somesuperlongscreenname',
|
|
142
|
+
secondIdentitySlotMode: 'allow',
|
|
143
|
+
}),
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
const brandingBlock = el.shadowRoot?.querySelector('div.branding');
|
|
147
|
+
expect(brandingBlock?.getAttribute('class')).to.contain(
|
|
148
|
+
'branding second-logo',
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const slot = brandingBlock?.querySelector('slot');
|
|
152
|
+
expect(slot).to.exist;
|
|
153
|
+
expect(slot?.getAttribute('name')).to.equal('opt-sec-logo');
|
|
154
|
+
|
|
155
|
+
el.secondIdentitySlotMode = '';
|
|
156
|
+
await elementUpdated(el);
|
|
157
|
+
const noSlotBrandingBlock = el.shadowRoot?.querySelector('div.branding');
|
|
158
|
+
expect(noSlotBrandingBlock?.getAttribute('class')).to.contain('branding');
|
|
159
|
+
|
|
160
|
+
const noSlot = noSlotBrandingBlock?.querySelector('slot');
|
|
161
|
+
expect(noSlot).to.not.exist;
|
|
162
|
+
});
|
|
163
|
+
});
|
package/tsconfig.json
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es2018",
|
|
4
|
-
"module": "esnext",
|
|
5
|
-
"moduleResolution": "node",
|
|
6
|
-
"noEmitOnError": true,
|
|
7
|
-
"lib": ["es2017", "dom"],
|
|
8
|
-
"strict": true,
|
|
9
|
-
"esModuleInterop": false,
|
|
10
|
-
"allowSyntheticDefaultImports": true,
|
|
11
|
-
"experimentalDecorators": true,
|
|
12
|
-
"importHelpers": true,
|
|
13
|
-
"outDir": "dist",
|
|
14
|
-
"sourceMap": true,
|
|
15
|
-
"inlineSources": true,
|
|
16
|
-
"rootDir": "./",
|
|
17
|
-
"declaration": true,
|
|
18
|
-
"plugins": [
|
|
19
|
-
{
|
|
20
|
-
"name": "ts-lit-plugin"
|
|
21
|
-
}
|
|
22
|
-
],
|
|
23
|
-
"paths": {
|
|
24
|
-
// workaround for: https://github.com/vitest-dev/vitest/issues/4567
|
|
25
|
-
"rollup/parseAst": [
|
|
26
|
-
"./node_modules/rollup/dist/parseAst"
|
|
27
|
-
]
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
"include": ["**/*.ts"]
|
|
31
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2018",
|
|
4
|
+
"module": "esnext",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"noEmitOnError": true,
|
|
7
|
+
"lib": ["es2017", "dom"],
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": false,
|
|
10
|
+
"allowSyntheticDefaultImports": true,
|
|
11
|
+
"experimentalDecorators": true,
|
|
12
|
+
"importHelpers": true,
|
|
13
|
+
"outDir": "dist",
|
|
14
|
+
"sourceMap": true,
|
|
15
|
+
"inlineSources": true,
|
|
16
|
+
"rootDir": "./",
|
|
17
|
+
"declaration": true,
|
|
18
|
+
"plugins": [
|
|
19
|
+
{
|
|
20
|
+
"name": "ts-lit-plugin"
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"paths": {
|
|
24
|
+
// workaround for: https://github.com/vitest-dev/vitest/issues/4567
|
|
25
|
+
"rollup/parseAst": [
|
|
26
|
+
"./node_modules/rollup/dist/parseAst"
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"include": ["**/*.ts"]
|
|
31
|
+
}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
// import { hmrPlugin, presets } from '@open-wc/dev-server-hmr';
|
|
2
|
-
|
|
3
|
-
/** Use Hot Module replacement by adding --hmr to the start command */
|
|
4
|
-
const hmr = process.argv.includes('--hmr');
|
|
5
|
-
|
|
6
|
-
export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
|
|
7
|
-
nodeResolve: true,
|
|
8
|
-
open: '/demo',
|
|
9
|
-
watch: !hmr,
|
|
10
|
-
sslCert: './ssl/server.crt',
|
|
11
|
-
sslKey: './ssl/server.key',
|
|
12
|
-
hostname: 'local.archive.org',
|
|
13
|
-
http2: true,
|
|
14
|
-
|
|
15
|
-
/** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
|
|
16
|
-
// esbuildTarget: 'auto'
|
|
17
|
-
|
|
18
|
-
/** Set appIndex to enable SPA routing */
|
|
19
|
-
// appIndex: 'demo/index.html',
|
|
20
|
-
|
|
21
|
-
/** Configure bare import resolve plugin */
|
|
22
|
-
// nodeResolve: {
|
|
23
|
-
// exportConditions: ['browser', 'development']
|
|
24
|
-
// },
|
|
25
|
-
|
|
26
|
-
plugins: [
|
|
27
|
-
/** Use Hot Module Replacement by uncommenting. Requires @open-wc/dev-server-hmr plugin */
|
|
28
|
-
// hmr && hmrPlugin({ exclude: ['**/*/node_modules/**/*'], presets: [presets.litElement] }),
|
|
29
|
-
],
|
|
30
|
-
|
|
31
|
-
// See documentation for all available options
|
|
32
|
-
});
|
|
1
|
+
// import { hmrPlugin, presets } from '@open-wc/dev-server-hmr';
|
|
2
|
+
|
|
3
|
+
/** Use Hot Module replacement by adding --hmr to the start command */
|
|
4
|
+
const hmr = process.argv.includes('--hmr');
|
|
5
|
+
|
|
6
|
+
export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
|
|
7
|
+
nodeResolve: true,
|
|
8
|
+
open: '/demo',
|
|
9
|
+
watch: !hmr,
|
|
10
|
+
sslCert: './ssl/server.crt',
|
|
11
|
+
sslKey: './ssl/server.key',
|
|
12
|
+
hostname: 'local.archive.org',
|
|
13
|
+
http2: true,
|
|
14
|
+
|
|
15
|
+
/** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
|
|
16
|
+
// esbuildTarget: 'auto'
|
|
17
|
+
|
|
18
|
+
/** Set appIndex to enable SPA routing */
|
|
19
|
+
// appIndex: 'demo/index.html',
|
|
20
|
+
|
|
21
|
+
/** Configure bare import resolve plugin */
|
|
22
|
+
// nodeResolve: {
|
|
23
|
+
// exportConditions: ['browser', 'development']
|
|
24
|
+
// },
|
|
25
|
+
|
|
26
|
+
plugins: [
|
|
27
|
+
/** Use Hot Module Replacement by uncommenting. Requires @open-wc/dev-server-hmr plugin */
|
|
28
|
+
// hmr && hmrPlugin({ exclude: ['**/*/node_modules/**/*'], presets: [presets.litElement] }),
|
|
29
|
+
],
|
|
30
|
+
|
|
31
|
+
// See documentation for all available options
|
|
32
|
+
});
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
// import { playwrightLauncher } from '@web/test-runner-playwright';
|
|
2
|
-
|
|
3
|
-
const filteredLogs = ['Running in dev mode', 'lit-html is in dev mode'];
|
|
4
|
-
|
|
5
|
-
export default /** @type {import("@web/test-runner").TestRunnerConfig} */ ({
|
|
6
|
-
/** Test files to run */
|
|
7
|
-
files: 'dist/test/**/*.test.js',
|
|
8
|
-
|
|
9
|
-
/** Resolve bare module imports */
|
|
10
|
-
nodeResolve: {
|
|
11
|
-
exportConditions: ['browser', 'development'],
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
/** Filter out lit dev mode logs */
|
|
15
|
-
filterBrowserLogs(log) {
|
|
16
|
-
for (const arg of log.args) {
|
|
17
|
-
if (typeof arg === 'string' && filteredLogs.some(l => arg.includes(l))) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return true;
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
/** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
|
|
25
|
-
// esbuildTarget: 'auto',
|
|
26
|
-
|
|
27
|
-
/** Amount of browsers to run concurrently */
|
|
28
|
-
// concurrentBrowsers: 2,
|
|
29
|
-
|
|
30
|
-
/** Amount of test files per browser to test concurrently */
|
|
31
|
-
// concurrency: 1,
|
|
32
|
-
|
|
33
|
-
/** Browsers to run tests on */
|
|
34
|
-
// browsers: [
|
|
35
|
-
// playwrightLauncher({ product: 'chromium' }),
|
|
36
|
-
// playwrightLauncher({ product: 'firefox' }),
|
|
37
|
-
// playwrightLauncher({ product: 'webkit' }),
|
|
38
|
-
// ],
|
|
39
|
-
|
|
40
|
-
// See documentation for all available options
|
|
41
|
-
});
|
|
1
|
+
// import { playwrightLauncher } from '@web/test-runner-playwright';
|
|
2
|
+
|
|
3
|
+
const filteredLogs = ['Running in dev mode', 'lit-html is in dev mode'];
|
|
4
|
+
|
|
5
|
+
export default /** @type {import("@web/test-runner").TestRunnerConfig} */ ({
|
|
6
|
+
/** Test files to run */
|
|
7
|
+
files: 'dist/test/**/*.test.js',
|
|
8
|
+
|
|
9
|
+
/** Resolve bare module imports */
|
|
10
|
+
nodeResolve: {
|
|
11
|
+
exportConditions: ['browser', 'development'],
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
/** Filter out lit dev mode logs */
|
|
15
|
+
filterBrowserLogs(log) {
|
|
16
|
+
for (const arg of log.args) {
|
|
17
|
+
if (typeof arg === 'string' && filteredLogs.some(l => arg.includes(l))) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
/** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
|
|
25
|
+
// esbuildTarget: 'auto',
|
|
26
|
+
|
|
27
|
+
/** Amount of browsers to run concurrently */
|
|
28
|
+
// concurrentBrowsers: 2,
|
|
29
|
+
|
|
30
|
+
/** Amount of test files per browser to test concurrently */
|
|
31
|
+
// concurrency: 1,
|
|
32
|
+
|
|
33
|
+
/** Browsers to run tests on */
|
|
34
|
+
// browsers: [
|
|
35
|
+
// playwrightLauncher({ product: 'chromium' }),
|
|
36
|
+
// playwrightLauncher({ product: 'firefox' }),
|
|
37
|
+
// playwrightLauncher({ product: 'webkit' }),
|
|
38
|
+
// ],
|
|
39
|
+
|
|
40
|
+
// See documentation for all available options
|
|
41
|
+
});
|