@zanichelli/zanichelli-it-frontend-kit 1.2.0 → 1.3.0-RC1
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/dist/cjs/{index-q1XSBSqA.js → index-CRwLFnL1.js} +7 -3
- package/dist/cjs/index-CRwLFnL1.js.map +1 -0
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/zanichelli-it-frontend-kit.cjs.js +2 -2
- package/dist/cjs/zanit-menubar.zanit-mobile-menubar.zanit-search-form.entry.cjs.js.map +1 -1
- package/dist/cjs/zanit-menubar_3.cjs.entry.js +267 -22
- package/dist/cjs/zanit-menubar_3.cjs.entry.js.map +1 -1
- package/dist/collection/components/menubar/menubar.css +1 -0
- package/dist/collection/components/menubar/menubar.js +53 -2
- package/dist/collection/components/menubar/menubar.js.map +1 -1
- package/dist/collection/components/menubar/mobile-menubar/mobile-menubar.js +52 -1
- package/dist/collection/components/menubar/mobile-menubar/mobile-menubar.js.map +1 -1
- package/dist/collection/components/menubar/search-form/search-form.css +45 -0
- package/dist/collection/components/menubar/search-form/search-form.js +208 -22
- package/dist/collection/components/menubar/search-form/search-form.js.map +1 -1
- package/dist/collection/components/menubar/search-form/suggestions.js +84 -0
- package/dist/collection/components/menubar/search-form/suggestions.js.map +1 -0
- package/dist/collection/utils/subjects.api.js +25 -0
- package/dist/collection/utils/subjects.api.js.map +1 -0
- package/dist/collection/utils/utils.js +8 -0
- package/dist/collection/utils/utils.js.map +1 -1
- package/dist/components/index.js +5 -2
- package/dist/components/index.js.map +1 -1
- package/dist/components/{p-DCsoOA4v.js → p-CuXV3NdC.js} +12 -5
- package/dist/components/p-CuXV3NdC.js.map +1 -0
- package/dist/components/p-DRtCn2AS.js +376 -0
- package/dist/components/p-DRtCn2AS.js.map +1 -0
- package/dist/components/zanit-menubar.js +13 -6
- package/dist/components/zanit-menubar.js.map +1 -1
- package/dist/components/zanit-mobile-menubar.js +1 -1
- package/dist/components/zanit-search-form.js +1 -1
- package/dist/esm/{index-CaWL2omE.js → index-B82IapZZ.js} +7 -4
- package/dist/esm/index-B82IapZZ.js.map +1 -0
- package/dist/esm/loader.js +3 -3
- package/dist/esm/zanichelli-it-frontend-kit.js +3 -3
- package/dist/esm/zanit-menubar.zanit-mobile-menubar.zanit-search-form.entry.js.map +1 -1
- package/dist/esm/zanit-menubar_3.entry.js +267 -22
- package/dist/esm/zanit-menubar_3.entry.js.map +1 -1
- package/dist/types/components/menubar/menubar.d.ts +5 -0
- package/dist/types/components/menubar/mobile-menubar/mobile-menubar.d.ts +5 -0
- package/dist/types/components/menubar/search-form/search-form.d.ts +28 -5
- package/dist/types/components/menubar/search-form/suggestions.d.ts +11 -0
- package/dist/types/components.d.ts +60 -4
- package/dist/types/utils/subjects.api.d.ts +6 -0
- package/dist/types/utils/types.d.ts +7 -0
- package/dist/types/utils/utils.d.ts +8 -0
- package/{www/build/p-CaWL2omE.js → dist/zanichelli-it-frontend-kit/p-B82IapZZ.js} +2 -2
- package/dist/zanichelli-it-frontend-kit/p-B82IapZZ.js.map +1 -0
- package/dist/zanichelli-it-frontend-kit/p-d7e08556.entry.js +2 -0
- package/dist/zanichelli-it-frontend-kit/p-d7e08556.entry.js.map +1 -0
- package/dist/zanichelli-it-frontend-kit/zanichelli-it-frontend-kit.esm.js +1 -1
- package/dist/zanichelli-it-frontend-kit/zanit-menubar.zanit-mobile-menubar.zanit-search-form.entry.esm.js.map +1 -1
- package/package.json +11 -12
- package/www/build/p-3c83769f.js +2 -0
- package/{dist/zanichelli-it-frontend-kit/p-CaWL2omE.js → www/build/p-B82IapZZ.js} +2 -2
- package/www/build/p-B82IapZZ.js.map +1 -0
- package/www/build/p-d7e08556.entry.js +2 -0
- package/www/build/p-d7e08556.entry.js.map +1 -0
- package/www/build/zanichelli-it-frontend-kit.esm.js +1 -1
- package/www/build/zanit-menubar.zanit-mobile-menubar.zanit-search-form.entry.esm.js.map +1 -1
- package/www/index.html +1 -1
- package/dist/cjs/index-q1XSBSqA.js.map +0 -1
- package/dist/components/p-C_SXGfG9.js +0 -133
- package/dist/components/p-C_SXGfG9.js.map +0 -1
- package/dist/components/p-DCsoOA4v.js.map +0 -1
- package/dist/esm/index-CaWL2omE.js.map +0 -1
- package/dist/zanichelli-it-frontend-kit/p-217f87ff.entry.js +0 -2
- package/dist/zanichelli-it-frontend-kit/p-217f87ff.entry.js.map +0 -1
- package/dist/zanichelli-it-frontend-kit/p-CaWL2omE.js.map +0 -1
- package/www/build/p-1d74b708.js +0 -2
- package/www/build/p-217f87ff.entry.js +0 -2
- package/www/build/p-217f87ff.entry.js.map +0 -1
- package/www/build/p-CaWL2omE.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { h, r as registerInstance, a as getElement, F as Fragment, c as createEvent } from './index-
|
|
1
|
+
import { h, r as registerInstance, a as getElement, F as Fragment, c as createEvent, H as Host } from './index-B82IapZZ.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Check if an element contains an event target by checking its composedPath.
|
|
@@ -16,6 +16,14 @@ const moveFocus = (current, next) => {
|
|
|
16
16
|
next.tabIndex = 0;
|
|
17
17
|
next.focus({ preventScroll: true });
|
|
18
18
|
};
|
|
19
|
+
/** Check if event key is ArrowUp */
|
|
20
|
+
const isArrowUpKey = (event) => event.key === 'ArrowUp';
|
|
21
|
+
/** Check if event key is ArrowDown */
|
|
22
|
+
const isArrowDownKey = (event) => event.key === 'ArrowDown';
|
|
23
|
+
/** Check if event key is Tab */
|
|
24
|
+
const isTabKey = (event) => event.key === 'Tab';
|
|
25
|
+
/** Check if event key is Escape */
|
|
26
|
+
const isEscKey = (event) => event.key === 'Escape';
|
|
19
27
|
|
|
20
28
|
const DEFAULT_GROUP_KEY = 'default';
|
|
21
29
|
const DEFAULT_GROUP = {
|
|
@@ -57,7 +65,32 @@ const Menu = ({ controlledBy, items, currentPath = [], onItemKeyDown }) => {
|
|
|
57
65
|
}, href: item.href, role: "menuitem", tabIndex: -1, "aria-current": isActive(item) ? 'page' : 'false', onKeyDown: (event) => onItemKeyDown(event), target: item.target }, item.label))))))))))));
|
|
58
66
|
};
|
|
59
67
|
|
|
60
|
-
|
|
68
|
+
var SearchEnv;
|
|
69
|
+
(function (SearchEnv) {
|
|
70
|
+
SearchEnv["DEV"] = "dev";
|
|
71
|
+
SearchEnv["TEST"] = "test";
|
|
72
|
+
SearchEnv["PROD"] = "prod";
|
|
73
|
+
})(SearchEnv || (SearchEnv = {}));
|
|
74
|
+
const S3_SHOP_URL = {
|
|
75
|
+
dev: 'https://zanichelli-shop-dev.s3.eu-west-1.amazonaws.com',
|
|
76
|
+
test: 'https://zanichelli-shop-test.s3.eu-west-1.amazonaws.com',
|
|
77
|
+
prod: 'https://zanichelli-shop.s3.eu-west-1.amazonaws.com',
|
|
78
|
+
};
|
|
79
|
+
async function getSubjectsByArea(searchEnv) {
|
|
80
|
+
try {
|
|
81
|
+
const response = await fetch(`${S3_SHOP_URL[searchEnv]}/categories.json`);
|
|
82
|
+
if (!response.ok) {
|
|
83
|
+
throw new Error(`HTTP ${response.status}`);
|
|
84
|
+
}
|
|
85
|
+
return await response.json();
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
console.error('Error fetching subjects:', err);
|
|
89
|
+
return {};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const menubarCss = ":host{position:relative;z-index:2;display:flex;width:100%;background-color:#fff;color:var(--gray900);font-family:var(--font-family-sans)}:host,*,::before,::after{box-sizing:border-box}*:focus:focus-visible{box-shadow:var(--shadow-focus-primary);outline:none}ul{padding:0;margin:0;list-style:none}a{color:var(--gray900);cursor:pointer;text-decoration:none}button{all:unset;cursor:pointer}:host nav{width:100%}.shadow-wrapper{position:relative;z-index:1;display:flex;width:100%}.shadow-wrapper::after{position:absolute;top:0;right:0;width:100%;height:100%;background:transparent;box-shadow:var(--shadow-1);content:'';pointer-events:none}.width-limiter{position:relative;display:flex;width:100%;max-width:var(--zanit-menubar-max-width, 1366px);margin:0 auto}.shadow-wrapper+.shadow-wrapper{z-index:0}.sub-menubar>ul{gap:28px}.width-limiter>ul,.sub-menubar>ul{position:relative;z-index:3;display:flex;width:100%;align-items:center;padding:0 var(--grid-margin);margin-right:auto;margin-left:auto;gap:20px}.shadow-wrapper>.width-limiter,.shadow-wrapper>ul{width:100%;max-width:var(--zanit-menubar-max-width, 1366px)}ul.menubar{padding-right:0}.menubar z-ghost-loading{display:block;width:120px;height:1.25rem}.menubar>li[role='separator']{width:1px;height:1.25rem;background-color:#000}.menubar-item{position:relative;display:flex;align-items:center;padding:14px 0;font-size:1rem;gap:8px;line-height:1.25rem}.menubar .menubar-item{text-transform:uppercase}.menubar-item [data-text]{display:flex;flex-direction:column}.menubar-item.active>[data-text],.menubar-item:hover>[data-text],.menubar-item:focus:focus-visible>[data-text]{font-weight:var(--font-bd)}.menubar-item>[data-text]::after{height:0;content:attr(data-text) / '';font-weight:var(--font-bd);letter-spacing:normal;pointer-events:none;user-select:none;visibility:hidden}.sub-menubar .menubar-item.active::after{position:absolute;z-index:-1;bottom:0;left:-4px;width:calc(100% + 8px);height:4px;background-color:var(--red500);content:''}zanit-search-form{margin-left:auto}";
|
|
61
94
|
|
|
62
95
|
const menuCss$1 = ".menu-wrapper{width:100%;background-color:#fff}.menu{position:relative;display:flex;width:100%;flex-direction:column;gap:32px 0}.menu .group{display:flex;flex-direction:column}.menu .group .group-name{border-bottom:1px solid currentcolor;margin-bottom:4px;color:var(--red500);font-size:0.875rem;font-weight:var(--font-md)}.menu .group .menu-list{display:flex;flex-direction:column;gap:8px}.menu .group .menu-list .menu-item{display:block;border-bottom:2px solid transparent;font-size:0.875rem;font-weight:var(--font-md)}.menu .menu-list .menu-item.active,.menu .menu-list .menu-item:hover{border-bottom-color:var(--red500)}.menu .group.highlight .menu-list .menu-item{font-size:1rem}@media (width >= 768px){.menu-wrapper{position:absolute;top:100%;left:0;display:flex;justify-content:center;box-shadow:var(--shadow-1)}.menu{display:grid;width:100%;max-width:var(--zanit-menubar-max-width, 1366px);padding:16px var(--grid-margin);gap:0 24px;grid-auto-columns:minmax(0, max-content);grid-auto-flow:column;grid-template-rows:minmax(0, max-content) max-content}.menu .group{display:grid;grid-row:1 / -1;grid-template-columns:1fr;grid-template-rows:subgrid}@supports not (grid-template-rows: subgrid){.menu .group{grid-template-rows:repeat(auto-fit, minmax(0, max-content))}}.menu .group .group-name{border:none;margin-bottom:16px}.menu .group .menu-list .menu-item{font-size:1rem}.menu .group.highlight .menu-list .menu-item{font-size:1.5rem}}";
|
|
63
96
|
|
|
@@ -82,6 +115,10 @@ const ZanitMenubar = class {
|
|
|
82
115
|
current = undefined;
|
|
83
116
|
/** Initial search query. */
|
|
84
117
|
searchQuery = undefined;
|
|
118
|
+
/** Environment for search suggestions */
|
|
119
|
+
searchEnv = SearchEnv.PROD;
|
|
120
|
+
/** Search area (e.g. "SCUOLA", "UNIVERSITÀ", "DIZIONARI"). */
|
|
121
|
+
searchArea;
|
|
85
122
|
timerId;
|
|
86
123
|
/** Setup the list of items. */
|
|
87
124
|
async parseData(data) {
|
|
@@ -433,19 +470,20 @@ const ZanitMenubar = class {
|
|
|
433
470
|
}
|
|
434
471
|
render() {
|
|
435
472
|
if (this.isMobile) {
|
|
436
|
-
return (h("zanit-mobile-menubar", { items: this.items, currentPath: this.currentPath, searchQuery: this.searchQuery, loading: this.loading }));
|
|
473
|
+
return (h("zanit-mobile-menubar", { items: this.items, currentPath: this.currentPath, searchQuery: this.searchQuery, loading: this.loading, searchArea: this.searchArea, searchEnv: this.searchEnv }));
|
|
437
474
|
}
|
|
438
475
|
return (h("nav", { "aria-label": "Zanichelli.it" }, h("div", { class: "shadow-wrapper" }, h("div", { class: "width-limiter" }, h("ul", { class: "menubar", role: "menubar", "aria-label": "Zanichelli.it" }, this.loading &&
|
|
439
476
|
[...new Array(4)].map((_, index) => (h(Fragment, null, h("li", { role: "none" }, h("div", { class: "menubar-item" }, h("z-ghost-loading", null))), index < 3 && h("li", { role: "separator" })))), this.items?.map((item, index) => (h(Fragment, null, h("li", { role: "none" }, h("a", { class: {
|
|
440
477
|
'menubar-item': true,
|
|
441
478
|
'active': this.isActive(item),
|
|
442
|
-
}, href: item.href, id: item.id, role: "menuitem", tabIndex: -1, "aria-expanded": item.menuItems?.length ? (this.openMenu === item.id ? 'true' : 'false') : undefined, "aria-haspopup": item.menuItems?.length ? 'true' : 'false', "aria-current": this.current.includes(item.id) ? 'page' : 'false', onPointerOver: () => this.showMenu(item), onKeyDown: (event) => this.handleItemKeydown(event, item), target: item.target }, h("span", { "data-text": item.label }, item.label), item.menuItems?.length > 0 && (h("z-icon", { name: this.openMenu === item.id ? 'chevron-up' : 'chevron-down', width: "0.875rem", height: "0.875rem" })))), index < this.items?.length - 1 && h("li", { role: "separator" }))))), h("zanit-search-form", { searchQuery: this.searchQuery, onResetSearch: () => (this.searchQuery = undefined) })), this.items.map((item) => this.openMenu === item.id && (h(Menu, { controlledBy: item.id, items: item.menuItems, currentPath: this.currentPath, onItemKeyDown: (event) => this.handleMenuKeydown(event) })))), this.items
|
|
479
|
+
}, href: item.href, id: item.id, role: "menuitem", tabIndex: -1, "aria-expanded": item.menuItems?.length ? (this.openMenu === item.id ? 'true' : 'false') : undefined, "aria-haspopup": item.menuItems?.length ? 'true' : 'false', "aria-current": this.current.includes(item.id) ? 'page' : 'false', onPointerOver: () => this.showMenu(item), onKeyDown: (event) => this.handleItemKeydown(event, item), target: item.target }, h("span", { "data-text": item.label }, item.label), item.menuItems?.length > 0 && (h("z-icon", { name: this.openMenu === item.id ? 'chevron-up' : 'chevron-down', width: "0.875rem", height: "0.875rem" })))), index < this.items?.length - 1 && h("li", { role: "separator" }))))), h("zanit-search-form", { searchQuery: this.searchQuery, searchArea: this.searchArea, searchEnv: this.searchEnv, onResetSearch: () => (this.searchQuery = undefined) })), this.items.map((item) => this.openMenu === item.id && (h(Menu, { controlledBy: item.id, items: item.menuItems, currentPath: this.currentPath, onItemKeyDown: (event) => this.handleMenuKeydown(event) })))), this.items
|
|
443
480
|
?.filter((item) => this.isActive(item))
|
|
444
481
|
.map((item) => item.navbarItems?.length && (h("nav", { class: { 'sub-menubar': true, 'shadow-wrapper': true }, "aria-label": `Sezioni: ${item.label}` }, h("ul", { role: "menubar" }, item.navbarItems.map((subitem) => (h(Fragment, null, h("li", { role: "none" }, h("a", { class: {
|
|
445
482
|
'menubar-item': true,
|
|
446
483
|
'active': this.isActive(subitem),
|
|
447
484
|
}, href: subitem.href, id: subitem.id, role: "menuitem", tabIndex: -1, "aria-haspopup": subitem.menuItems?.length ? 'true' : 'false', "aria-expanded": subitem.menuItems?.length ? (this.openMenu === subitem.id ? 'true' : 'false') : undefined, "aria-current": this.current.includes(subitem.id) ? 'page' : 'false', onPointerOver: () => this.showMenu(subitem), onKeyDown: (event) => this.handleItemKeydown(event, subitem), target: item.target }, h("span", null, subitem.label), subitem.menuItems?.length > 0 && (h("z-icon", { name: this.openMenu === subitem.id ? 'chevron-up' : 'chevron-down', width: "0.75rem", height: "0.75rem" })))))))), item.navbarItems.map((subitem) => this.openMenu === subitem.id && (h(Menu, { controlledBy: subitem.id, items: subitem.menuItems, currentPath: this.currentPath, onItemKeyDown: (event) => this.handleMenuKeydown(event) }))))))));
|
|
448
485
|
}
|
|
486
|
+
static get delegatesFocus() { return true; }
|
|
449
487
|
static get watchers() { return {
|
|
450
488
|
"data": ["parseData"],
|
|
451
489
|
"items": ["onItemsChange"],
|
|
@@ -471,6 +509,10 @@ const ZanitMobileMenubar = class {
|
|
|
471
509
|
searchQuery = undefined;
|
|
472
510
|
/** Whether the menubar is loading the data. */
|
|
473
511
|
loading = false;
|
|
512
|
+
/** Environment for search suggestions */
|
|
513
|
+
searchEnv = SearchEnv.PROD;
|
|
514
|
+
/** Search area (e.g. "SCUOLA", "UNIVERSITÀ", "DIZIONARI"). */
|
|
515
|
+
searchArea;
|
|
474
516
|
/** Last active item ID. */
|
|
475
517
|
lastCurrent = undefined;
|
|
476
518
|
parentItem = undefined;
|
|
@@ -600,11 +642,12 @@ const ZanitMobileMenubar = class {
|
|
|
600
642
|
this.open = false;
|
|
601
643
|
}
|
|
602
644
|
render() {
|
|
603
|
-
return (h("nav", { key: '
|
|
645
|
+
return (h("nav", { key: 'f21d484bf0c81aa8e4583f71bf8a8523c57b791f', "aria-label": "Zanichelli.it" }, h("button", { key: '5331948d9f25ebf2812b9538ba2654ccd98a376a', class: "burger-button", type: "button", "aria-expanded": this.open ? 'true' : 'false', "aria-controls": "mobile-menu", "aria-label": this.open ? 'Chiudi menù' : 'Apri menù', onClick: () => this.toggleMenu() }, h("z-icon", { key: '14b6264bd1aa3383a90d0f38924cc73b407af7fb', name: this.open ? 'multiply' : 'burger-menu', width: "1.5rem", height: "1.5rem" })), h("z-logo", { key: 'ad25511bb218bdfae227a6f84c2f84790da5495a', imageAlt: "Logo Zanichelli", link: "/", height: 32, width: 126 }), h("zanit-search-form", { key: 'a76767d008e17c8c22baef76eb5ef6237764a665', searchQuery: this.searchQuery, onResetSearch: () => (this.searchQuery = undefined), searchArea: this.searchArea, searchEnv: this.searchEnv }), this.open && (h("ul", { key: 'dc7159a8a0342825a7828323204dd10e32ea30ee', class: "mobile-menu", role: "menubar" }, !this.loading && this.currentPath && this.currentPath.length > 0 && (h("li", { key: '60f03b21375d3cdc89242a67b89c42a6d2aad5ca', role: "none" }, h("a", { key: '143c13385480d4860d95cc073af0d53aa8f622f2', class: "parent", href: this.parentItem?.href ?? '/', id: this.parentItem?.id ?? undefined, role: "menuitem", tabIndex: -1, onKeyDown: (event) => this.handleItemKeydown(event), target: this.parentItem?.target }, h("z-icon", { key: 'a433613bd001bcbd44ba98305291d8d585349f21', name: "arrow-left", width: "0.5rem", height: "0.5rem" }), h("span", { key: '237cc68a00c57e71ef564444ab872a4d47bf7071' }, this.parentItem?.label || 'Home')))), this.loading ? (h("div", { class: "items-container", role: "none" }, [...new Array(4)].map(() => (h("li", { role: "none" }, h("div", { class: "menubar-item", role: "none" }, h("z-ghost-loading", null))))))) : this.menuType === 'menu' ? (h(Menu, { items: this.menuItems, controlledBy: this.parentItem?.id, currentPath: this.currentPath, onItemKeyDown: (event) => this.handleItemKeydown(event) })) : (this.menuItems?.length > 0 && (h("div", { class: "items-container", role: "none" }, this.menuItems.map((item) => (h("li", { role: "none" }, h("a", { class: {
|
|
604
646
|
'menu-item': this.menuType === 'menu',
|
|
605
647
|
'menubar-item': this.menuType === 'menubar',
|
|
606
648
|
}, href: item.href, id: item.id, role: "menuitem", "aria-current": this.lastCurrent === item.id ? 'page' : 'false', tabIndex: -1, onKeyDown: (event) => this.handleItemKeydown(event), target: item.target }, h("span", { "data-text": item.label }, item.label))))))))))));
|
|
607
649
|
}
|
|
650
|
+
static get delegatesFocus() { return true; }
|
|
608
651
|
static get watchers() { return {
|
|
609
652
|
"items": ["onItemsChange"],
|
|
610
653
|
"currentPath": ["onItemsChange"]
|
|
@@ -612,7 +655,91 @@ const ZanitMobileMenubar = class {
|
|
|
612
655
|
};
|
|
613
656
|
ZanitMobileMenubar.style = mobileMenubarCss + menuCss;
|
|
614
657
|
|
|
615
|
-
|
|
658
|
+
var AREA_LABELS;
|
|
659
|
+
(function (AREA_LABELS) {
|
|
660
|
+
AREA_LABELS["SCUOLA"] = "Scuola";
|
|
661
|
+
AREA_LABELS["UNIVERSIT\u00C0"] = "Universit\u00E0";
|
|
662
|
+
AREA_LABELS["GIURIDICO"] = "Giuridico";
|
|
663
|
+
AREA_LABELS["DIZIONARI"] = "Dizionari";
|
|
664
|
+
AREA_LABELS["SAGGISTICA"] = "Saggistica";
|
|
665
|
+
})(AREA_LABELS || (AREA_LABELS = {}));
|
|
666
|
+
const AREA_ORDER = Object.keys(AREA_LABELS);
|
|
667
|
+
function buildSuggestions(query, subjectsByArea, selectedArea) {
|
|
668
|
+
const matchingSubjectAreas = findSubjectAreas(query, subjectsByArea);
|
|
669
|
+
const hasSubject = matchingSubjectAreas.length > 0;
|
|
670
|
+
const subject = hasSubject ? query.toUpperCase() : undefined;
|
|
671
|
+
const suggestions = [];
|
|
672
|
+
if (selectedArea)
|
|
673
|
+
suggestions.push(buildWordSuggestion(query, selectedArea));
|
|
674
|
+
suggestions.push(buildWordSuggestion(query));
|
|
675
|
+
if (hasSubject) {
|
|
676
|
+
if (selectedArea) {
|
|
677
|
+
const orderedSubjectAreas = [
|
|
678
|
+
...matchingSubjectAreas.filter((area) => area === selectedArea),
|
|
679
|
+
...matchingSubjectAreas
|
|
680
|
+
.filter((area) => area !== selectedArea)
|
|
681
|
+
.sort((a, b) => getAreaOrder(a) - getAreaOrder(b)),
|
|
682
|
+
];
|
|
683
|
+
orderedSubjectAreas.forEach((area) => suggestions.push(buildSubjectSuggestion(query, area, subject)));
|
|
684
|
+
}
|
|
685
|
+
else {
|
|
686
|
+
matchingSubjectAreas
|
|
687
|
+
.sort((a, b) => getAreaOrder(a) - getAreaOrder(b))
|
|
688
|
+
.forEach((subjectArea) => suggestions.push(buildSubjectSuggestion(query, subjectArea, subject)));
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
return suggestions;
|
|
692
|
+
}
|
|
693
|
+
const buildWordSuggestion = (user_query, area) => {
|
|
694
|
+
return {
|
|
695
|
+
id: buildId(`word-${user_query}-${area}`),
|
|
696
|
+
label: buildLabel(user_query, area, false, false),
|
|
697
|
+
html_label: buildLabel(user_query, area, false, true),
|
|
698
|
+
url: buildUrl({ q: user_query, ...(area ? { area } : {}), user_query }),
|
|
699
|
+
...buildDetail(user_query, user_query, area),
|
|
700
|
+
};
|
|
701
|
+
};
|
|
702
|
+
const buildSubjectSuggestion = (user_query, area, subject) => {
|
|
703
|
+
return {
|
|
704
|
+
id: buildId(`subj-${user_query}-${area}-${subject}`),
|
|
705
|
+
label: buildLabel(user_query, area, true, false),
|
|
706
|
+
html_label: buildLabel(user_query, area, true, true),
|
|
707
|
+
url: buildUrl({ area, materia: subject, user_query }),
|
|
708
|
+
...buildDetail(user_query, undefined, area, subject),
|
|
709
|
+
};
|
|
710
|
+
};
|
|
711
|
+
const buildId = (string) => string
|
|
712
|
+
.split('')
|
|
713
|
+
.map((c) => c.charCodeAt(0).toString(16))
|
|
714
|
+
.join('');
|
|
715
|
+
const buildUrl = (params) => {
|
|
716
|
+
return `ricerca?${new URLSearchParams(params).toString()}`;
|
|
717
|
+
};
|
|
718
|
+
const buildDetail = (user_query, query, area, subject) => ({
|
|
719
|
+
user_query,
|
|
720
|
+
...(query ? { query } : {}),
|
|
721
|
+
...(area ? { area } : {}),
|
|
722
|
+
...(subject ? { subject } : {}),
|
|
723
|
+
});
|
|
724
|
+
const buildLabel = (user_query, area, isSubject = false, isHtml = false) => {
|
|
725
|
+
const openStrong = isHtml ? `<strong>` : ``;
|
|
726
|
+
const closeStrong = isHtml ? `</strong>` : ``;
|
|
727
|
+
return `Cerca la ${isSubject ? `materia` : `parola`} ${openStrong}${user_query}${closeStrong} ${area ? `nel catalogo ${openStrong}${AREA_LABELS[area] ?? area}` : `in tutto il sito`}${closeStrong}`;
|
|
728
|
+
};
|
|
729
|
+
function findSubjectAreas(query, subjectsByArea) {
|
|
730
|
+
const cleanedQuery = cleanSearch(query);
|
|
731
|
+
return Object.entries(subjectsByArea)
|
|
732
|
+
.filter(([, subjects]) => subjects.some((subject) => subject.toLowerCase() === cleanedQuery))
|
|
733
|
+
.map(([area]) => area);
|
|
734
|
+
}
|
|
735
|
+
/** Clear search string: lowercase, remove multiple spaces */
|
|
736
|
+
const cleanSearch = (s) => s.toLowerCase().replace(/\s+/g, ' ');
|
|
737
|
+
const getAreaOrder = (area) => {
|
|
738
|
+
const index = AREA_ORDER.indexOf(area);
|
|
739
|
+
return index >= 0 ? index : 100;
|
|
740
|
+
};
|
|
741
|
+
|
|
742
|
+
const searchFormCss = ":host,*,::before,::after{box-sizing:border-box}*:focus:focus-visible{box-shadow:var(--shadow-focus-primary);outline:none}button{all:unset;cursor:pointer}.searchbar{--searchbar-button-x-padding:14px;--searchbar-button-icon-width:1.75rem;--closed-searchbar-width:calc((var(--searchbar-button-x-padding) * 2) + var(--searchbar-button-icon-width) + 1px);position:absolute;z-index:5;top:0;right:0;display:flex;width:var(--closed-searchbar-width);justify-content:flex-end;transition:width 0.4s ease-in-out}.searchbar.searchbar-open{width:100%}.searchbar .input-wrapper{display:flex;overflow:hidden;width:100%;align-items:center;padding:8px;padding-left:var(--grid-margin);background-color:#fff;gap:8px;transition-duration:0.4s;transition-property:padding-right, padding-left, width;transition-timing-function:ease-in-out}.searchbar:not(.searchbar-open) .input-wrapper{overflow:hidden;width:0;padding:0}.searchbar button[type='reset']{--z-icon-width:1rem;--z-icon-height:1rem;display:flex;align-items:center;cursor:pointer}.searchbar input{z-index:1;width:100%;height:100%;padding:0;border:none;background-color:#fff;font-family:var(--font-family-sans);font-size:1rem}.searchbar.searchbar-open input:first-child{padding-left:4px;margin-left:-4px;}.searchbar input[type='search']::-webkit-search-cancel-button,.searchbar input[type='search']::-webkit-search-decoration{appearance:none}.searchbar input::placeholder{color:var(--gray500)}.searchbar .searchbar-button{display:flex;align-items:center;justify-content:center;padding:10px var(--searchbar-button-x-padding);border-left:1px solid #000;background:var(--zanit-accent-color);font-family:inherit;font-size:inherit;gap:64px;line-height:1}.searchbar .searchbar-button:focus-visible{z-index:1}.searchbar-button z-icon{--z-icon-width:var(--searchbar-button-icon-width);--z-icon-height:var(--searchbar-button-icon-width)}.suggestions-wrapper{position:absolute;z-index:4;width:100vw;margin-left:-50vw;left:50%;top:48px;background:#fff;box-shadow:var(--shadow-1);border-top:1px solid var(--gray200)}.suggestions-wrapper.hidden{display:none}.suggestions{display:flex;padding:var(--space-unit);flex-direction:column;align-items:stretch;width:100%;margin:0 auto}.suggestion{cursor:pointer;padding:calc(var(--space-unit) * 0.75) var(--space-unit)}.suggestion:hover,.suggestion[aria-selected='true']{background:var(--gray100)}@media (width < 1152px){.searchbar .searchbar-button>.searchbar-button-label{display:none}}@media (width >= 768px){.searchbar{--searchbar-button-x-padding:16px;--searchbar-button-icon-width:2rem}.searchbar .input-wrapper{gap:14px}.searchbar button[type='reset']{--z-icon-width:1.5rem;--z-icon-height:1.5rem}.searchbar input,.searchbar .searchbar-button{font-size:1.5rem}.searchbar .searchbar-button{padding:8px var(--searchbar-button-x-padding)}.suggestions{padding:var(--space-unit) calc(var(--space-unit) * 2)}}@media (width >= 1152px){.searchbar{--closed-searchbar-width:190px}}@media (width >= 1366px){.searchbar .searchbar-button{border-right:1px solid #000}.suggestions{padding:var(--space-unit) calc(var(--space-unit) * 3);max-width:1366px}}";
|
|
616
743
|
|
|
617
744
|
const ZanitSearchForm = class {
|
|
618
745
|
constructor(hostRef) {
|
|
@@ -621,44 +748,77 @@ const ZanitSearchForm = class {
|
|
|
621
748
|
this.resetSearch = createEvent(this, "resetSearch");
|
|
622
749
|
}
|
|
623
750
|
formElement;
|
|
751
|
+
subjectsByArea = {};
|
|
752
|
+
timer;
|
|
624
753
|
get host() { return getElement(this); }
|
|
625
754
|
/** Indicates whether the searchbar is visible and usable. */
|
|
626
755
|
showSearchbar = false;
|
|
627
756
|
/** Search query to apply. */
|
|
628
757
|
_searchQuery = undefined;
|
|
758
|
+
/** Search suggestions to show in the autocomplete dropdown. */
|
|
759
|
+
suggestions = [];
|
|
760
|
+
/** Active suggestion - used for keyboard navigation */
|
|
761
|
+
activeSuggestion = '';
|
|
762
|
+
/** Show suggestions list */
|
|
763
|
+
showSuggestions = false;
|
|
629
764
|
/** Initial search query */
|
|
630
765
|
searchQuery = undefined;
|
|
766
|
+
/** Environment for search suggestions */
|
|
767
|
+
searchEnv = SearchEnv.PROD;
|
|
768
|
+
/** Search area (e.g. "SCUOLA", "UNIVERSITÀ", "DIZIONARI"). */
|
|
769
|
+
searchArea;
|
|
631
770
|
onSearchQueryChange() {
|
|
632
771
|
this._searchQuery = this.searchQuery;
|
|
633
772
|
if (this.searchQuery) {
|
|
634
773
|
this.openSearchbar();
|
|
635
774
|
}
|
|
775
|
+
this.resetSuggestions();
|
|
776
|
+
}
|
|
777
|
+
onSearchAreaChange() {
|
|
778
|
+
this.resetSuggestions();
|
|
779
|
+
}
|
|
780
|
+
onShowSearchbarChange() {
|
|
781
|
+
if (!this.showSearchbar) {
|
|
782
|
+
this.showSuggestions = false;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
onShowSuggestionsChange() {
|
|
786
|
+
this.activeSuggestion = '';
|
|
636
787
|
}
|
|
637
788
|
/** Emitted on search form submission. */
|
|
638
789
|
search;
|
|
639
790
|
resetSearch;
|
|
640
791
|
async connectedCallback() {
|
|
792
|
+
this.subjectsByArea = await getSubjectsByArea(this.searchEnv);
|
|
641
793
|
this.showSearchbar = !!this.searchQuery;
|
|
642
794
|
this._searchQuery = this.searchQuery;
|
|
643
795
|
}
|
|
644
796
|
/** Close open searchbar when clicking outside. */
|
|
645
797
|
handleOutsideClick(event) {
|
|
646
|
-
if (this.showSearchbar && this.
|
|
798
|
+
if (this.showSearchbar && this.host && !containsTarget(this.host, event)) {
|
|
647
799
|
this.showSearchbar = false;
|
|
648
800
|
}
|
|
649
801
|
}
|
|
650
|
-
/** Close the
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
802
|
+
/** Close the searchbar/suggestions when pressing Escape. */
|
|
803
|
+
handleEsc(event) {
|
|
804
|
+
if (!isEscKey(event)) {
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
if (this.showSuggestions) {
|
|
808
|
+
this.showSuggestions = false;
|
|
809
|
+
}
|
|
810
|
+
else {
|
|
811
|
+
this.showSearchbar = false;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
/** Close the searchbar/suggestions when pressing Tab. */
|
|
815
|
+
handleTab(event) {
|
|
816
|
+
if (!isTabKey(event)) {
|
|
817
|
+
return;
|
|
818
|
+
}
|
|
819
|
+
this.showSuggestions = false;
|
|
820
|
+
if (!containsTarget(this.host, event)) {
|
|
821
|
+
this.showSearchbar = false;
|
|
662
822
|
}
|
|
663
823
|
}
|
|
664
824
|
openSearchbar() {
|
|
@@ -672,30 +832,115 @@ const ZanitSearchForm = class {
|
|
|
672
832
|
this.searchQuery = undefined;
|
|
673
833
|
this.resetSearch.emit();
|
|
674
834
|
}
|
|
835
|
+
resetSuggestions() {
|
|
836
|
+
this.suggestions = [];
|
|
837
|
+
this.showSuggestions = false;
|
|
838
|
+
}
|
|
675
839
|
handleInputChange(event) {
|
|
676
840
|
this._searchQuery = event.target.value;
|
|
677
841
|
if (!this._searchQuery) {
|
|
678
842
|
this.searchQuery = undefined;
|
|
679
843
|
}
|
|
844
|
+
this.updateSuggestions();
|
|
845
|
+
}
|
|
846
|
+
updateSuggestions() {
|
|
847
|
+
clearTimeout(this.timer);
|
|
848
|
+
const query = (this._searchQuery || '').trim();
|
|
849
|
+
if (query.length < 3) {
|
|
850
|
+
this.resetSuggestions();
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
this.timer = setTimeout(() => {
|
|
854
|
+
this.resetSuggestions();
|
|
855
|
+
this.suggestions = buildSuggestions(query, this.subjectsByArea, this.searchArea?.toUpperCase());
|
|
856
|
+
this.showSuggestions = true;
|
|
857
|
+
}, 300);
|
|
680
858
|
}
|
|
681
859
|
onSearchSubmit(event) {
|
|
682
860
|
event.preventDefault();
|
|
683
861
|
if (!this._searchQuery) {
|
|
684
862
|
return;
|
|
685
863
|
}
|
|
864
|
+
if (this.activeSuggestion) {
|
|
865
|
+
const suggestion = this.suggestions.find((s) => s.id === this.activeSuggestion);
|
|
866
|
+
if (suggestion) {
|
|
867
|
+
this.submitSuggestionSearch(suggestion);
|
|
868
|
+
this.showSuggestions = false;
|
|
869
|
+
return;
|
|
870
|
+
}
|
|
871
|
+
}
|
|
686
872
|
this.showSearchbar = false;
|
|
687
|
-
|
|
873
|
+
this.showSuggestions = false;
|
|
874
|
+
const searchEv = this.search.emit({ query: this._searchQuery, area: this.searchArea });
|
|
688
875
|
// do not submit the form if the event default behavior was prevented
|
|
689
876
|
if (searchEv.defaultPrevented) {
|
|
690
877
|
return;
|
|
691
878
|
}
|
|
692
879
|
this.formElement.submit();
|
|
693
880
|
}
|
|
881
|
+
submitSuggestionSearch(suggestion) {
|
|
882
|
+
const ev = this.search.emit({
|
|
883
|
+
user_query: suggestion.user_query,
|
|
884
|
+
query: suggestion.query,
|
|
885
|
+
area: suggestion.area,
|
|
886
|
+
subject: suggestion.subject,
|
|
887
|
+
});
|
|
888
|
+
if (!ev.defaultPrevented) {
|
|
889
|
+
window.location.href = suggestion.url;
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
handleSuggestionsNav(event) {
|
|
893
|
+
if (!isArrowDownKey(event) && !isArrowUpKey(event)) {
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
896
|
+
if (!this.suggestions.length) {
|
|
897
|
+
return;
|
|
898
|
+
}
|
|
899
|
+
const options = Array.from(this.host.shadowRoot.querySelectorAll("[role='option']")).map((o) => o.id);
|
|
900
|
+
if (!options.length) {
|
|
901
|
+
return;
|
|
902
|
+
}
|
|
903
|
+
event.preventDefault();
|
|
904
|
+
event.stopPropagation();
|
|
905
|
+
if (!this.showSuggestions) {
|
|
906
|
+
this.showSuggestions = true;
|
|
907
|
+
}
|
|
908
|
+
let nextId = null;
|
|
909
|
+
const firstId = options[0];
|
|
910
|
+
const lastId = options[options.length - 1];
|
|
911
|
+
const currOption = options.indexOf(this.activeSuggestion);
|
|
912
|
+
if (currOption < 0) {
|
|
913
|
+
nextId = isArrowDownKey(event) ? firstId : lastId;
|
|
914
|
+
}
|
|
915
|
+
else {
|
|
916
|
+
if (isArrowDownKey(event)) {
|
|
917
|
+
nextId = options[currOption + 1] || lastId;
|
|
918
|
+
}
|
|
919
|
+
else {
|
|
920
|
+
nextId = options[currOption - 1] || firstId;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
this.activeSuggestion = nextId;
|
|
924
|
+
}
|
|
925
|
+
renderSuggestions() {
|
|
926
|
+
return (h("div", { class: { 'suggestions-wrapper': true, 'hidden': !this.showSuggestions || !this.suggestions.length }, onPointerOver: (e) => e.preventDefault() }, h("div", { id: "search-suggestions", class: "suggestions", role: "listbox", "aria-label": "Seleziona tra i suggerimenti" }, this.suggestions.map((suggestion, k) => {
|
|
927
|
+
return (h("span", { key: k, innerHTML: suggestion.html_label, id: suggestion.id, class: "suggestion", role: "option", "aria-label": suggestion.label, "aria-selected": this.activeSuggestion === suggestion.id ? 'true' : undefined, onClick: () => this.submitSuggestionSearch(suggestion) }));
|
|
928
|
+
}))));
|
|
929
|
+
}
|
|
694
930
|
render() {
|
|
695
|
-
return (h("form", { key: '
|
|
931
|
+
return (h(Host, { key: 'd7316fa36a078c2dd1c5888ba35bf004e4c08e6c' }, h("form", { key: '36180991431f49981a4bddd58e4caf0253f326ef', class: { 'searchbar': true, 'searchbar-open': this.showSearchbar }, ref: (el) => (this.formElement = el), role: "search", "aria-label": "Cerca nel sito", method: "get", action: "/ricerca", onSubmit: (event) => this.onSearchSubmit(event), onReset: () => this.resetSearchQuery() }, !!this.searchArea && (h("input", { key: '98862f739245597cd1c22b76c15e2e728a429f17', type: "hidden", name: "area", value: this.searchArea })), h("div", { key: '919e102ea248a41caea96fc3c7289b106d54195d', class: "input-wrapper", role: "none" }, this.searchQuery && (h("button", { key: 'd53357c9b63e6bae5b28809499265a7c332b5f2d', type: "reset", "aria-label": "Svuota campo di ricerca", disabled: !this.showSearchbar, "aria-hidden": !this.showSearchbar ? 'true' : undefined, tabIndex: !this.showSearchbar ? -1 : 0 }, h("z-icon", { key: '2ff06d5550f8701e6256f178b925153cac565be8', name: "multiply-circled" }))), h("input", { key: '879339821611ce65bd2777726ebabd0c44384b72', id: "searchbar-input", name: "q", type: "search", disabled: !this.showSearchbar, placeholder: "Cerca per parola chiave o ISBN", value: this.searchQuery, required: true, autocomplete: "off", role: "combobox", "aria-autocomplete": "list", "aria-expanded": this.suggestions.length ? 'true' : 'false', "aria-controls": "search-suggestions", "aria-activedescendant": this.activeSuggestion, "aria-label": "Cerca per parola chiave o ISBN", "aria-hidden": !this.showSearchbar ? 'true' : undefined, tabIndex: !this.showSearchbar ? -1 : 0, onInput: (event) => this.handleInputChange(event), onKeyDown: (e) => {
|
|
932
|
+
// INFO: prevent ESC from clearing input
|
|
933
|
+
if (isEscKey(e)) {
|
|
934
|
+
e.preventDefault();
|
|
935
|
+
}
|
|
936
|
+
this.handleSuggestionsNav(e);
|
|
937
|
+
} })), h("button", { key: '7101e9eedd9385bfeb5ee41a80d7e6842e75f493', class: "searchbar-button", "aria-label": this.showSearchbar ? 'Esegui ricerca' : 'Apri il campo di ricerca', "aria-controls": "searchbar-input", type: this.showSearchbar ? 'submit' : 'button', onClick: () => this.openSearchbar() }, this.showSearchbar ? null : h("span", { class: "searchbar-button-label" }, "Cerca"), h("z-icon", { key: '6e8d065e91e94fba49c64e856129d72155e88b84', name: "search" }))), this.renderSuggestions()));
|
|
696
938
|
}
|
|
697
939
|
static get watchers() { return {
|
|
698
|
-
"searchQuery": ["onSearchQueryChange"]
|
|
940
|
+
"searchQuery": ["onSearchQueryChange"],
|
|
941
|
+
"searchArea": ["onSearchAreaChange"],
|
|
942
|
+
"showSearchbar": ["onShowSearchbarChange"],
|
|
943
|
+
"showSuggestions": ["onShowSuggestionsChange"]
|
|
699
944
|
}; }
|
|
700
945
|
};
|
|
701
946
|
ZanitSearchForm.style = searchFormCss;
|