@internetarchive/ia-topnav 1.3.30 → 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.
Files changed (53) hide show
  1. package/.prettierignore +1 -1
  2. package/LICENSE +661 -661
  3. package/README.md +147 -147
  4. package/demo/index.html +28 -28
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.js.map +1 -1
  7. package/dist/src/data/menus.js.map +1 -1
  8. package/dist/src/dropdown-menu.js +26 -26
  9. package/dist/src/dropdown-menu.js.map +1 -1
  10. package/dist/src/ia-topnav.d.ts +4 -1
  11. package/dist/src/ia-topnav.js +96 -81
  12. package/dist/src/ia-topnav.js.map +1 -1
  13. package/dist/src/lib/keyboard-navigation.js.map +1 -1
  14. package/dist/src/login-button.js +17 -17
  15. package/dist/src/login-button.js.map +1 -1
  16. package/dist/src/media-menu.js +21 -21
  17. package/dist/src/media-menu.js.map +1 -1
  18. package/dist/src/models.d.ts +1 -0
  19. package/dist/src/models.js.map +1 -1
  20. package/dist/src/primary-nav.d.ts +3 -1
  21. package/dist/src/primary-nav.js +118 -95
  22. package/dist/src/primary-nav.js.map +1 -1
  23. package/dist/src/styles/login-button.js +87 -87
  24. package/dist/src/styles/login-button.js.map +1 -1
  25. package/dist/src/styles/primary-nav.js +343 -308
  26. package/dist/src/styles/primary-nav.js.map +1 -1
  27. package/dist/src/user-menu.js +13 -13
  28. package/dist/src/user-menu.js.map +1 -1
  29. package/dist/test/ia-topnav.test.js +39 -9
  30. package/dist/test/ia-topnav.test.js.map +1 -1
  31. package/dist/test/primary-nav.test.js +55 -7
  32. package/dist/test/primary-nav.test.js.map +1 -1
  33. package/eslint.config.mjs +53 -53
  34. package/index.ts +4 -3
  35. package/package.json +72 -72
  36. package/prettier.config.js +9 -9
  37. package/src/data/menus.ts +652 -652
  38. package/src/dropdown-menu.ts +132 -132
  39. package/src/ia-topnav.ts +383 -366
  40. package/src/lib/keyboard-navigation.ts +166 -166
  41. package/src/login-button.ts +78 -78
  42. package/src/media-menu.ts +143 -143
  43. package/src/models.ts +65 -63
  44. package/src/primary-nav.ts +324 -296
  45. package/src/styles/login-button.ts +90 -90
  46. package/src/styles/primary-nav.ts +346 -311
  47. package/src/user-menu.ts +32 -32
  48. package/ssl/server.key +28 -28
  49. package/test/ia-topnav.test.ts +381 -343
  50. package/test/primary-nav.test.ts +163 -94
  51. package/tsconfig.json +31 -31
  52. package/web-dev-server.config.mjs +32 -32
  53. package/web-test-runner.config.mjs +41 -41
@@ -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 { IATopNavConfig, IATopNavSecondIdentitySlotMode } from '../src/models';
11
- import { PrimaryNav } from '../src/primary-nav';
12
-
13
- const component = ({
14
- baseHost = 'archive.org',
15
- username = '',
16
- screenName = '',
17
- hideSearch = false,
18
- config = {},
19
- secondIdentitySlotMode = 'allow',
20
- }: {
21
- baseHost?: string;
22
- username?: string;
23
- screenName?: string;
24
- hideSearch?: boolean;
25
- config?: IATopNavConfig;
26
- secondIdentitySlotMode?: IATopNavSecondIdentitySlotMode;
27
- }) =>
28
- html` <primary-nav
29
- .baseHost=${baseHost}
30
- .username=${username}
31
- .screenName=${screenName}
32
- ?hideSearch=${hideSearch}
33
- .config=${config}
34
- .secondIdentitySlotMode=${secondIdentitySlotMode}
35
- ></primary-nav>`;
36
-
37
- afterEach(() => {
38
- fixtureCleanup();
39
- });
40
-
41
- describe('<primary-nav>', () => {
42
- it('renders the login link when no username present', async () => {
43
- const el = await fixture<PrimaryNav>(
44
- component({
45
- baseHost: 'archive.org',
46
- username: '',
47
- }),
48
- );
49
-
50
- expect(el.shadowRoot?.querySelector('login-button')).to.not.be.undefined;
51
- });
52
-
53
- it('does not render search menu toggle and search form if hideSearch true', async () => {
54
- const el = await fixture<PrimaryNav>(
55
- component({
56
- baseHost: 'archive.org',
57
- username: 'shaneriley',
58
- screenName: 'shaneriley',
59
- hideSearch: true,
60
- }),
61
- );
62
-
63
- expect(el.shadowRoot?.querySelector('.search-trigger')).to.equal(null);
64
- expect(el.shadowRoot?.querySelector('nav-search')).to.equal(null);
65
- });
66
-
67
- it('opens a slot with `secondIdentitySlotMode`', async () => {
68
- const el = await fixture<PrimaryNav>(
69
- component({
70
- baseHost: 'archive.org',
71
- username: 'boop',
72
- screenName: 'somesuperlongscreenname',
73
- secondIdentitySlotMode: 'allow',
74
- }),
75
- );
76
-
77
- const brandingBlock = el.shadowRoot?.querySelector('div.branding');
78
- expect(brandingBlock?.getAttribute('class')).to.contain(
79
- 'branding second-logo',
80
- );
81
-
82
- const slot = brandingBlock?.querySelector('slot');
83
- expect(slot).to.exist;
84
- expect(slot?.getAttribute('name')).to.equal('opt-sec-logo');
85
-
86
- el.secondIdentitySlotMode = '';
87
- await elementUpdated(el);
88
- const noSlotBrandingBlock = el.shadowRoot?.querySelector('div.branding');
89
- expect(noSlotBrandingBlock?.getAttribute('class')).to.contain('branding');
90
-
91
- const noSlot = noSlotBrandingBlock?.querySelector('slot');
92
- expect(noSlot).to.not.exist;
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
+ });