@itcenteratunihelsinki/huds-lib 0.6.6 → 0.6.7

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 (35) hide show
  1. package/dist/cjs/huds-lib.cjs.js +1 -1
  2. package/dist/cjs/{hy-accordion-container_89.cjs.entry.js → hy-accordion-container_83.cjs.entry.js} +606 -1314
  3. package/dist/cjs/loader.cjs.js +1 -1
  4. package/dist/collection/collection-manifest.json +0 -12
  5. package/dist/collection/components/navigation/hy-menu-main-group/hy-menu-main-group.js +20 -1
  6. package/dist/collection/components/site-header/site-header.css +16 -1
  7. package/dist/collection/components/site-header/site-header.js +15 -37
  8. package/dist/esm/huds-lib.js +1 -1
  9. package/dist/esm/{hy-accordion-container_89.entry.js → hy-accordion-container_83.entry.js} +608 -1310
  10. package/dist/esm/loader.js +1 -1
  11. package/dist/huds-lib/huds-lib.esm.js +1 -1
  12. package/dist/huds-lib/p-f86741ed.entry.js +86 -0
  13. package/dist/types/components/navigation/hy-menu-main-group/hy-menu-main-group.d.ts +1 -0
  14. package/dist/types/components/site-header/site-header.d.ts +0 -1
  15. package/dist/types/components.d.ts +3 -212
  16. package/package.json +1 -1
  17. package/dist/collection/components/navigation/menu/menu.css +0 -262
  18. package/dist/collection/components/navigation/menu/menu.js +0 -431
  19. package/dist/collection/components/navigation/menu-item/menu-item.css +0 -348
  20. package/dist/collection/components/navigation/menu-item/menu-item.js +0 -557
  21. package/dist/collection/components/navigation/menu-level-container/menu-level-container.css +0 -129
  22. package/dist/collection/components/navigation/menu-level-container/menu-level-container.js +0 -300
  23. package/dist/collection/components/navigation/menu-mobile-breadcrumb/menu-mobile-breadcrumb.css +0 -90
  24. package/dist/collection/components/navigation/menu-mobile-breadcrumb/menu-mobile-breadcrumb.js +0 -151
  25. package/dist/collection/components/navigation/mobile-menu-shortcuts/mobile-menu-shortcuts.css +0 -140
  26. package/dist/collection/components/navigation/mobile-menu-shortcuts/mobile-menu-shortcuts.js +0 -68
  27. package/dist/collection/components/site-header/hy-desktop-menu-links/hy-desktop-menu-links.css +0 -469
  28. package/dist/collection/components/site-header/hy-desktop-menu-links/hy-desktop-menu-links.js +0 -482
  29. package/dist/huds-lib/p-f28263c0.entry.js +0 -86
  30. package/dist/types/components/navigation/menu/menu.d.ts +0 -30
  31. package/dist/types/components/navigation/menu-item/menu-item.d.ts +0 -31
  32. package/dist/types/components/navigation/menu-level-container/menu-level-container.d.ts +0 -27
  33. package/dist/types/components/navigation/menu-mobile-breadcrumb/menu-mobile-breadcrumb.d.ts +0 -12
  34. package/dist/types/components/navigation/mobile-menu-shortcuts/mobile-menu-shortcuts.d.ts +0 -13
  35. package/dist/types/components/site-header/hy-desktop-menu-links/hy-desktop-menu-links.d.ts +0 -60
@@ -1,482 +0,0 @@
1
- import { Component, h, Element, Prop, State, Event, Listen } from '@stencil/core';
2
- import { jsonParserWorker } from '../../../global/globalScript';
3
- import ResizeObserver from 'resize-observer-polyfill';
4
- let scrollTimer = null;
5
- let resizeTimer = null;
6
- let keys = {
7
- enter: 'Enter',
8
- tab: 'Tab',
9
- space: 'Space',
10
- };
11
- let scrollTimeout = null;
12
- let resizeTimeout = null;
13
- export class HyDesktopMenuLinks {
14
- constructor() {
15
- /*
16
- First level menu links to be displayed on Desktop screens.
17
- * */
18
- this.isGroup = false;
19
- this.isDropdown = false;
20
- this.firstLevelLinksList = [];
21
- this.menuLinkItems = [];
22
- this.hasToolbar = false;
23
- this.isDesktopMenuOpen = false;
24
- this.currenOpenMenuId = 0;
25
- this.isNewMenuIdOnHover = false;
26
- // private _submenuLeftMargin: number = 32;
27
- this._headerBorderOffset = 0;
28
- this._hoverTimer = null;
29
- this._fadeOutTimer = null;
30
- this._mouseEnter = null;
31
- this._mouseLeave = null;
32
- }
33
- async componentWillLoad() {
34
- this._dataDesktopLinks = await jsonParserWorker(this.dataDesktopLinks);
35
- }
36
- disconnectedCallback() {
37
- clearTimeout(scrollTimer);
38
- clearTimeout(resizeTimer);
39
- }
40
- removeBackdropShadow(size) {
41
- // Close backdrop shadow if the screen is < 1200px
42
- if (size < 1200) {
43
- this.showBackdropShadow();
44
- }
45
- }
46
- showBackdropShadow(state = 'close', top = 0) {
47
- let hyHeader = this.el.closest('.hy-site-header');
48
- if (!hyHeader)
49
- return;
50
- let hyBackdropDiv = hyHeader.children[0];
51
- if (hyBackdropDiv && !this.isDropdown) {
52
- if (state === 'open') {
53
- const windowHeight = window.outerHeight;
54
- hyBackdropDiv.style.height = `${windowHeight}px`;
55
- hyBackdropDiv.style.top = `${top}px`;
56
- hyBackdropDiv.style.position = 'absolute';
57
- hyBackdropDiv.classList.add('is-active');
58
- }
59
- else {
60
- hyBackdropDiv.removeAttribute('style');
61
- hyBackdropDiv.classList.remove('is-active');
62
- }
63
- }
64
- }
65
- showPanel(id) {
66
- // Close menu lang menu if it's open
67
- this.menuDesktopToggled.emit();
68
- clearTimeout(this._hoverTimer);
69
- clearTimeout(this._fadeOutTimer);
70
- // Open desktop menu panel
71
- this.isDesktopMenuOpen = true;
72
- const menuItems = this.el.shadowRoot.querySelectorAll(`.hy-desktop-menu__button`);
73
- const menuPanelItems = this.el.shadowRoot.querySelectorAll('.hy-desktop-menu__panel'); // all panels
74
- const activeMenuItem = this.el.shadowRoot.querySelector(`.hy-desktop-menu__button[link-id="${id}"]`);
75
- const activeMenuItemSibling = activeMenuItem.nextElementSibling; // current panel
76
- // Reset elements by removing the active classes.
77
- menuItems.forEach((item) => {
78
- item.setAttribute('aria-expanded', 'false');
79
- });
80
- menuPanelItems.forEach((item) => {
81
- item.setAttribute('aria-hidden', 'true');
82
- item.style.transition = 'none';
83
- item.style.opacity = '0';
84
- });
85
- // Set active attributes to currently active panel.
86
- activeMenuItem.setAttribute('aria-expanded', 'true');
87
- activeMenuItemSibling.style.opacity = '1';
88
- if (this.hasToolbar) {
89
- activeMenuItemSibling.classList.add('has-toolbar');
90
- }
91
- activeMenuItemSibling.setAttribute('aria-hidden', 'false');
92
- // Add panels top value automatically with the correct header height
93
- let topOffset = window.pageYOffset;
94
- const bodyElementClasses = document.body.classList;
95
- const headerElement = document.querySelector('hy-site-header');
96
- const headerShadowRootElement = headerElement.shadowRoot.querySelector('header');
97
- let headerElementHeight = headerShadowRootElement.offsetHeight + this._headerBorderOffset;
98
- let headerElementOffset = headerShadowRootElement.offsetTop;
99
- let panelElementOffset = headerElementHeight + headerElementOffset;
100
- // Add shadow backdrop
101
- let rect = activeMenuItemSibling.getBoundingClientRect();
102
- let backdropOffset = headerElementHeight + headerElementOffset + rect.height;
103
- let backdropToolbarOffset = backdropOffset - 79;
104
- if (!this.isDropdown) {
105
- window.addEventListener('scroll', () => {
106
- clearTimeout(scrollTimeout);
107
- scrollTimeout = setTimeout(() => {
108
- topOffset = window.pageYOffset;
109
- if (topOffset === 0) {
110
- activeMenuItemSibling.style.top = `${panelElementOffset}px`;
111
- }
112
- if (headerShadowRootElement.classList.contains('hy-site-header--sticky-active') && topOffset > 0) {
113
- if (bodyElementClasses.contains('toolbar-horizontal')) {
114
- activeMenuItemSibling.style.top = `${headerElementHeight}px`;
115
- if (this.isDesktopMenuOpen) {
116
- this.showBackdropShadow('open', backdropToolbarOffset);
117
- }
118
- }
119
- }
120
- }, 250);
121
- });
122
- }
123
- if (!this.isDropdown) {
124
- if (headerShadowRootElement.classList.contains('hy-site-header--sticky-active') && topOffset > 0) {
125
- if (bodyElementClasses.contains('toolbar-horizontal')) {
126
- activeMenuItemSibling.style.top = `${headerElementHeight}px`;
127
- if (this.isDesktopMenuOpen) {
128
- this.showBackdropShadow('open', backdropToolbarOffset);
129
- }
130
- }
131
- else {
132
- activeMenuItemSibling.style.top = `${panelElementOffset}px`;
133
- this.showBackdropShadow('open', backdropOffset);
134
- }
135
- }
136
- else {
137
- activeMenuItemSibling.style.top = `${panelElementOffset}px`;
138
- this.showBackdropShadow('open', backdropOffset);
139
- }
140
- }
141
- if (this.isDropdown) {
142
- let windowWidth = window.outerWidth;
143
- const desktopMenuPanelWidth = activeMenuItemSibling.offsetWidth;
144
- if (windowWidth - activeMenuItem.getBoundingClientRect().left < desktopMenuPanelWidth) {
145
- activeMenuItemSibling.style.left = `auto`;
146
- activeMenuItemSibling.style.right = `-17px`;
147
- }
148
- window.addEventListener('resize', () => {
149
- clearTimeout(resizeTimeout);
150
- resizeTimeout = setTimeout(() => {
151
- windowWidth = window.outerWidth;
152
- if (windowWidth - activeMenuItem.getBoundingClientRect().left < desktopMenuPanelWidth) {
153
- activeMenuItemSibling.style.left = `auto`;
154
- activeMenuItemSibling.style.right = `-17px`;
155
- }
156
- else {
157
- activeMenuItemSibling.style.left = `-17px`;
158
- activeMenuItemSibling.style.right = `auto`;
159
- }
160
- }, 250);
161
- });
162
- }
163
- }
164
- closePanel(fadeOut = false) {
165
- this.isDesktopMenuOpen = false;
166
- this.isNewMenuIdOnHover = false;
167
- this.currenOpenMenuId = 0;
168
- this.showBackdropShadow();
169
- this.clearPanelItemsStatus(fadeOut);
170
- clearTimeout(this._hoverTimer);
171
- }
172
- clearPanelItemsStatus(fadeOut = false) {
173
- const menuItems = this.el.shadowRoot.querySelectorAll(`.hy-desktop-menu__button`);
174
- const menuPanelItems = this.el.shadowRoot.querySelectorAll('.hy-desktop-menu__panel');
175
- // Reset elements by removing the active classes.
176
- menuItems.forEach((item) => {
177
- // item.classList.remove('desktop-menu-link--is-active');
178
- item.setAttribute('aria-expanded', 'false');
179
- });
180
- if (fadeOut) {
181
- menuPanelItems.forEach((item) => {
182
- item.style.opacity = '0';
183
- item.style.transition = 'opacity 1s';
184
- });
185
- this._fadeOutTimer = window.requestAnimationFrame(() => {
186
- menuPanelItems.forEach((item) => {
187
- // item.classList.remove('hy-desktop-menu-panel--is-active');
188
- item.setAttribute('aria-hidden', 'true');
189
- });
190
- });
191
- }
192
- else {
193
- menuPanelItems.forEach((item) => {
194
- // item.classList.remove('hy-desktop-menu-panel--is-active');
195
- item.setAttribute('aria-hidden', 'true');
196
- item.style.opacity = '0';
197
- item.style.transition = 'none';
198
- });
199
- }
200
- }
201
- handleDesktopMenuClose(event) {
202
- let fadeOut = true;
203
- this.closePanel(fadeOut);
204
- event.stopPropagation();
205
- }
206
- // CLose the desktop menu panel if user opens the language menu.
207
- menuLanguageToggled() {
208
- let fadeOut = true;
209
- this.closePanel(fadeOut);
210
- }
211
- // Close the desktop menu panel if user opens University main menu
212
- universityMainMenuPanelToggled() {
213
- let fadeOut = true;
214
- this.closePanel(fadeOut);
215
- }
216
- // Close the desktop menu panel if user opens search panel
217
- searchPanelToggled() {
218
- let fadeOut = true;
219
- this.closePanel(fadeOut);
220
- }
221
- // CLose the desktop menu panel if user scrolls Sticky Header till the very top.
222
- headerScrollUp() {
223
- let fadeOut = false;
224
- this.closePanel(fadeOut);
225
- }
226
- handleDesktopMenuEnter(event, id) {
227
- if (this.isDesktopMenuOpen && this._mouseEnter == null) {
228
- clearTimeout(this._mouseLeave);
229
- this._mouseLeave = null;
230
- this._mouseEnter = setTimeout(() => {
231
- this.isNewMenuIdOnHover = true;
232
- clearTimeout(this._fadeOutTimer);
233
- const activeMenuItem = this.el.shadowRoot.querySelector(`.hy-desktop-menu__button[link-id="${id}"]`);
234
- // Set focus to the button.
235
- if (activeMenuItem !== null)
236
- activeMenuItem.focus();
237
- this.currenOpenMenuId = id;
238
- this.showPanel(id);
239
- event.stopPropagation();
240
- }, 500);
241
- }
242
- }
243
- handleDesktopMenuLeave() {
244
- clearTimeout(this._mouseEnter);
245
- this._mouseEnter = null;
246
- }
247
- handleWindowClick(event) {
248
- // Check if event is being fired during pressing a key (event.detail==0 in this case)
249
- if (event.detail == 0)
250
- return;
251
- if (this.isDesktopMenuOpen) {
252
- this.handleDesktopMenuClose(event);
253
- event.stopPropagation();
254
- }
255
- }
256
- handleDesktopMenuClick(event, id) {
257
- // Check if event is being fired during pressing a key (event.detail==0 in this case)
258
- if (event.detail == 0)
259
- return;
260
- event.stopPropagation();
261
- if (!this.isDesktopMenuOpen) {
262
- this.currenOpenMenuId = id;
263
- this.showPanel(id);
264
- }
265
- else if (this.isDesktopMenuOpen) {
266
- this.handleDesktopMenuClose(event);
267
- }
268
- if (this.isNewMenuIdOnHover) {
269
- this.isNewMenuIdOnHover = false;
270
- }
271
- }
272
- handleKeyDown(event, id) {
273
- event.stopPropagation();
274
- const key = event.code;
275
- if ([keys.enter, keys.space].includes(key)) {
276
- if (!this.isDesktopMenuOpen) {
277
- this.currenOpenMenuId = id;
278
- this.showPanel(id);
279
- }
280
- else {
281
- this.handleDesktopMenuClose(event);
282
- }
283
- }
284
- }
285
- componentDidLoad() {
286
- // Set the browser resize observer to gather information about browser width.
287
- this.ro = new ResizeObserver((entries) => {
288
- for (const entry of entries) {
289
- this.removeBackdropShadow(entry.contentRect.width);
290
- }
291
- });
292
- this.ro.observe(document.body);
293
- let hyToolbar = document.querySelectorAll('#toolbar-administration')[0];
294
- if (hyToolbar) {
295
- this.hasToolbar = true;
296
- }
297
- const links = this._dataDesktopLinks;
298
- let menuLinkItems = [];
299
- if (links) {
300
- links.map(({ menuLinkId: id, shortcuts, items, url, description, toggleOff, label, labelExtra, isExternal, isActive, shortcutsTitle, closeButtonTitle, }) => {
301
- let target = isExternal ? '_blank' : '_self';
302
- const isLabelLong = label.split(' ').length >= 3 ? true : false;
303
- let customizedLabel = [];
304
- if (isLabelLong && !this.isGroup) {
305
- customizedLabel = label.split(' ');
306
- customizedLabel.splice(2, 0, '</br>');
307
- }
308
- if (toggleOff) {
309
- menuLinkItems.push(h("li", { onMouseEnter: (e) => this.handleDesktopMenuClose(e), class: `hy-desktop-menu__item ${isActive === 'true' ? 'is-active-trail' : ''}` },
310
- h("a", { "aria-current": label, href: url, target: target, class: `hy-desktop-menu__button ${isLabelLong && !this.isGroup ? 'is-long' : ''}`, "menu-link-id": id }, labelExtra ? h("span", { class: "label" }, labelExtra) : h("span", { class: "label" }, label))));
311
- }
312
- else {
313
- menuLinkItems.push(h("li", { class: "hy-desktop-menu__item" },
314
- h("button", { tabindex: "0", type: "button", class: `hy-desktop-menu__button ${isActive === 'true' ? 'is-active-trail' : ''} ${isLabelLong && !this.isGroup ? 'is-long' : ''}`, "link-id": id, onClick: (e) => this.handleDesktopMenuClick(e, id), onKeyDown: (e) => this.handleKeyDown(e, id), onMouseEnter: (e) => this.handleDesktopMenuEnter(e, id), onMouseLeave: () => this.handleDesktopMenuLeave(), "aria-expanded": "false" },
315
- h("span", { innerHTML: isLabelLong && !this.isGroup ? customizedLabel.join(' ') : label }),
316
- h("hy-icon", { icon: 'hy-icon-caret-down', size: 32 })),
317
- h("section", { class: `hy-desktop-menu__panel ${this.isDropdown ? 'is-dropdown' : ''}`, "aria-hidden": "true" },
318
- h("div", { class: "hy-desktop-menu__panel-container" },
319
- h("div", { class: "hy-desktop-menu__panel-menu" },
320
- h("div", { class: "hy-desktop-menu__panel-header" },
321
- h("hy-icon", { icon: 'hy-icon-arrow-right', size: 24 }),
322
- h("a", { "aria-current": label, href: url, target: target, "menu-link-id": id }, labelExtra || label),
323
- description && !this.isDropdown && h("p", null, description)),
324
- h("div", { class: `hy-desktop-menu__panel-content ${shortcuts.length > 0 ? 'has-shortcuts' : ''}` },
325
- h("ul", { class: 'hy-desktop-menu__panel-links hy-desktop-menu__panel-links--menu', "menu-link-id": id }, items.map(({ label, url, isExternal }) => {
326
- let subitemTarget = isExternal ? '_blank' : '_self';
327
- return (h("li", { class: "hy-desktop-menu__panel-links-item" },
328
- h("a", { class: "hy-desktop-menu__panel-link", href: url, target: subitemTarget },
329
- h("hy-icon", { icon: 'hy-icon-caret-right', size: 10 }),
330
- h("span", null,
331
- label,
332
- isExternal && h("hy-icon", { icon: 'hy-icon-arrow-right', size: 12 })))));
333
- })),
334
- shortcuts.length > 0 && (h("div", { class: "hy-desktop-menu__panel-shortcuts" },
335
- h("h2", null, shortcutsTitle),
336
- h("ul", { class: "hy-desktop-menu__panel-links hy-desktop-menu__panel-links--shortcuts" }, shortcuts.map(({ shortcut_title, shortcut_url, shortcut_is_external, shortcut_aria_label }) => {
337
- let target = shortcut_is_external ? '_blank' : '_self';
338
- return (h("li", { class: "hy-desktop-menu__panel-links-item" },
339
- h("a", { "aria-current": shortcut_aria_label, href: shortcut_url, class: "hy-desktop-menu__panel-link", target: target, "aria-label": shortcut_aria_label },
340
- h("hy-icon", { icon: 'hy-icon-caret-right', size: 10 }),
341
- h("span", null,
342
- shortcut_title,
343
- shortcut_is_external && h("hy-icon", { icon: 'hy-icon-arrow-right', size: 12 })))));
344
- })))))),
345
- !this.isDropdown && (h("button", { onClick: (e) => this.handleDesktopMenuClose(e), class: {
346
- 'hy-desktop-menu__panel-close-button': true,
347
- }, "aria-label": "Close menu" },
348
- h("span", null, closeButtonTitle),
349
- h("hy-icon", { icon: 'hy-icon-remove', size: 16 })))))));
350
- }
351
- });
352
- }
353
- this.menuLinkItems = menuLinkItems;
354
- }
355
- render() {
356
- return (h("nav", { role: 'navigation', class: `hy-site-header__menu-desktop ${this.isGroup ? 'is-group' : ''} ${this.isDropdown ? 'is-dropdown' : ''}` },
357
- h("ul", { class: `hy-desktop-menu ${this.isDesktopMenuOpen ? 'is-panel-open' : ''}` }, this.menuLinkItems)));
358
- }
359
- static get is() { return "hy-desktop-menu-links"; }
360
- static get encapsulation() { return "shadow"; }
361
- static get originalStyleUrls() { return {
362
- "$": ["hy-desktop-menu-links.scss"]
363
- }; }
364
- static get styleUrls() { return {
365
- "$": ["hy-desktop-menu-links.css"]
366
- }; }
367
- static get properties() { return {
368
- "isGroup": {
369
- "type": "boolean",
370
- "mutable": false,
371
- "complexType": {
372
- "original": "boolean",
373
- "resolved": "boolean",
374
- "references": {}
375
- },
376
- "required": false,
377
- "optional": true,
378
- "docs": {
379
- "tags": [],
380
- "text": ""
381
- },
382
- "attribute": "is-group",
383
- "reflect": false,
384
- "defaultValue": "false"
385
- },
386
- "isDropdown": {
387
- "type": "boolean",
388
- "mutable": false,
389
- "complexType": {
390
- "original": "boolean",
391
- "resolved": "boolean",
392
- "references": {}
393
- },
394
- "required": false,
395
- "optional": true,
396
- "docs": {
397
- "tags": [],
398
- "text": ""
399
- },
400
- "attribute": "is-dropdown",
401
- "reflect": false,
402
- "defaultValue": "false"
403
- },
404
- "dataDesktopLinks": {
405
- "type": "string",
406
- "mutable": false,
407
- "complexType": {
408
- "original": "DesktopLinks[] | string",
409
- "resolved": "DesktopLinks[] | string",
410
- "references": {
411
- "DesktopLinks": {
412
- "location": "local"
413
- }
414
- }
415
- },
416
- "required": false,
417
- "optional": false,
418
- "docs": {
419
- "tags": [],
420
- "text": ""
421
- },
422
- "attribute": "data-desktop-links",
423
- "reflect": false
424
- }
425
- }; }
426
- static get states() { return {
427
- "firstLevelLinksList": {},
428
- "menuLinkItems": {},
429
- "hasToolbar": {},
430
- "isDesktopMenuOpen": {},
431
- "currenOpenMenuId": {},
432
- "isNewMenuIdOnHover": {}
433
- }; }
434
- static get events() { return [{
435
- "method": "menuDesktopToggled",
436
- "name": "menuDesktopToggled",
437
- "bubbles": true,
438
- "cancelable": true,
439
- "composed": true,
440
- "docs": {
441
- "tags": [],
442
- "text": ""
443
- },
444
- "complexType": {
445
- "original": "any",
446
- "resolved": "any",
447
- "references": {}
448
- }
449
- }]; }
450
- static get elementRef() { return "el"; }
451
- static get listeners() { return [{
452
- "name": "menuLanguageToggled",
453
- "method": "menuLanguageToggled",
454
- "target": "document",
455
- "capture": false,
456
- "passive": false
457
- }, {
458
- "name": "universityMainMenuToggled",
459
- "method": "universityMainMenuPanelToggled",
460
- "target": "document",
461
- "capture": false,
462
- "passive": false
463
- }, {
464
- "name": "searchPanelToggled",
465
- "method": "searchPanelToggled",
466
- "target": "document",
467
- "capture": false,
468
- "passive": false
469
- }, {
470
- "name": "headerScrollUp",
471
- "method": "headerScrollUp",
472
- "target": "document",
473
- "capture": false,
474
- "passive": false
475
- }, {
476
- "name": "click",
477
- "method": "handleWindowClick",
478
- "target": "window",
479
- "capture": false,
480
- "passive": false
481
- }]; }
482
- }