@zanichelli/zanichelli-it-frontend-kit 1.3.0 → 1.4.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/loader.cjs.js +1 -1
- package/dist/cjs/zanichelli-it-frontend-kit.cjs.js +1 -1
- package/dist/cjs/zanit-back-to-top.zanit-menubar.zanit-mobile-menubar.zanit-search-form.entry.cjs.js.map +1 -1
- package/dist/cjs/zanit-back-to-top_4.cjs.entry.js +264 -22
- package/dist/cjs/zanit-back-to-top_4.cjs.entry.js.map +1 -1
- package/dist/collection/components/menubar/menubar.css +2 -0
- package/dist/collection/components/menubar/menubar.js +52 -2
- package/dist/collection/components/menubar/menubar.js.map +1 -1
- package/dist/collection/components/menubar/mobile-menubar/mobile-menubar.css +1 -0
- package/dist/collection/components/menubar/mobile-menubar/mobile-menubar.js +51 -1
- package/dist/collection/components/menubar/mobile-menubar/mobile-menubar.js.map +1 -1
- package/dist/collection/components/menubar/search-form/search-form.css +52 -0
- package/dist/collection/components/menubar/search-form/search-form.js +207 -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/p-WUj4Aaz8.js +375 -0
- package/dist/components/p-WUj4Aaz8.js.map +1 -0
- package/dist/components/{p-BJzEFXY7.js → p-_cX2Kfxg.js} +11 -5
- package/dist/components/p-_cX2Kfxg.js.map +1 -0
- package/dist/components/zanit-menubar.js +11 -5
- 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/loader.js +1 -1
- package/dist/esm/zanichelli-it-frontend-kit.js +1 -1
- package/dist/esm/zanit-back-to-top.zanit-menubar.zanit-mobile-menubar.zanit-search-form.entry.js.map +1 -1
- package/dist/esm/zanit-back-to-top_4.entry.js +264 -22
- package/dist/esm/zanit-back-to-top_4.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/dist/zanichelli-it-frontend-kit/p-457d6be5.entry.js +2 -0
- package/dist/zanichelli-it-frontend-kit/p-457d6be5.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-back-to-top.zanit-menubar.zanit-mobile-menubar.zanit-search-form.entry.esm.js.map +1 -1
- package/package.json +1 -1
- package/www/build/p-457d6be5.entry.js +2 -0
- package/www/build/p-457d6be5.entry.js.map +1 -0
- package/www/build/p-f274d1db.js +2 -0
- package/www/build/zanichelli-it-frontend-kit.esm.js +1 -1
- package/www/build/zanit-back-to-top.zanit-menubar.zanit-mobile-menubar.zanit-search-form.entry.esm.js.map +1 -1
- package/www/index.html +1 -1
- package/dist/components/p-BJzEFXY7.js.map +0 -1
- package/dist/components/p-Cfa-BVne.js +0 -133
- package/dist/components/p-Cfa-BVne.js.map +0 -1
- package/dist/zanichelli-it-frontend-kit/p-8349e91a.entry.js +0 -2
- package/dist/zanichelli-it-frontend-kit/p-8349e91a.entry.js.map +0 -1
- package/www/build/p-271550c5.js +0 -2
- package/www/build/p-8349e91a.entry.js +0 -2
- package/www/build/p-8349e91a.entry.js.map +0 -1
|
@@ -70,6 +70,14 @@ const moveFocus = (current, next) => {
|
|
|
70
70
|
next.tabIndex = 0;
|
|
71
71
|
next.focus({ preventScroll: true });
|
|
72
72
|
};
|
|
73
|
+
/** Check if event key is ArrowUp */
|
|
74
|
+
const isArrowUpKey = (event) => event.key === 'ArrowUp';
|
|
75
|
+
/** Check if event key is ArrowDown */
|
|
76
|
+
const isArrowDownKey = (event) => event.key === 'ArrowDown';
|
|
77
|
+
/** Check if event key is Tab */
|
|
78
|
+
const isTabKey = (event) => event.key === 'Tab';
|
|
79
|
+
/** Check if event key is Escape */
|
|
80
|
+
const isEscKey = (event) => event.key === 'Escape';
|
|
73
81
|
|
|
74
82
|
const DEFAULT_GROUP_KEY = 'default';
|
|
75
83
|
const DEFAULT_GROUP = {
|
|
@@ -111,7 +119,32 @@ const Menu = ({ controlledBy, items, currentPath = [], onItemKeyDown }) => {
|
|
|
111
119
|
}, href: item.href, role: "menuitem", tabIndex: -1, "aria-current": isActive(item) ? 'page' : 'false', onKeyDown: (event) => onItemKeyDown(event), target: item.target }, item.label))))))))))));
|
|
112
120
|
};
|
|
113
121
|
|
|
114
|
-
|
|
122
|
+
var SearchEnv;
|
|
123
|
+
(function (SearchEnv) {
|
|
124
|
+
SearchEnv["DEV"] = "dev";
|
|
125
|
+
SearchEnv["TEST"] = "test";
|
|
126
|
+
SearchEnv["PROD"] = "prod";
|
|
127
|
+
})(SearchEnv || (SearchEnv = {}));
|
|
128
|
+
const S3_SHOP_URL = {
|
|
129
|
+
dev: 'https://zanichelli-shop-dev.s3.eu-west-1.amazonaws.com',
|
|
130
|
+
test: 'https://zanichelli-shop-test.s3.eu-west-1.amazonaws.com',
|
|
131
|
+
prod: 'https://zanichelli-shop.s3.eu-west-1.amazonaws.com',
|
|
132
|
+
};
|
|
133
|
+
async function getSubjectsByArea(searchEnv) {
|
|
134
|
+
try {
|
|
135
|
+
const response = await fetch(`${S3_SHOP_URL[searchEnv]}/categories.json`);
|
|
136
|
+
if (!response.ok) {
|
|
137
|
+
throw new Error(`HTTP ${response.status}`);
|
|
138
|
+
}
|
|
139
|
+
return await response.json();
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
console.error('Error fetching subjects:', err);
|
|
143
|
+
return {};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
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{height:3rem;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}";
|
|
115
148
|
|
|
116
149
|
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}}";
|
|
117
150
|
|
|
@@ -136,6 +169,10 @@ const ZanitMenubar = class {
|
|
|
136
169
|
current = undefined;
|
|
137
170
|
/** Initial search query. */
|
|
138
171
|
searchQuery = undefined;
|
|
172
|
+
/** Environment for search suggestions */
|
|
173
|
+
searchEnv = SearchEnv.PROD;
|
|
174
|
+
/** Search area (e.g. "SCUOLA", "UNIVERSITÀ", "DIZIONARI"). */
|
|
175
|
+
searchArea;
|
|
139
176
|
timerId;
|
|
140
177
|
/** Setup the list of items. */
|
|
141
178
|
async parseData(data) {
|
|
@@ -487,13 +524,13 @@ const ZanitMenubar = class {
|
|
|
487
524
|
}
|
|
488
525
|
render() {
|
|
489
526
|
if (this.isMobile) {
|
|
490
|
-
return (index.h("zanit-mobile-menubar", { items: this.items, currentPath: this.currentPath, searchQuery: this.searchQuery, loading: this.loading }));
|
|
527
|
+
return (index.h("zanit-mobile-menubar", { items: this.items, currentPath: this.currentPath, searchQuery: this.searchQuery, loading: this.loading, searchArea: this.searchArea, searchEnv: this.searchEnv }));
|
|
491
528
|
}
|
|
492
529
|
return (index.h("nav", { "aria-label": "Zanichelli.it" }, index.h("div", { class: "shadow-wrapper" }, index.h("div", { class: "width-limiter" }, index.h("ul", { class: "menubar", role: "menubar", "aria-label": "Zanichelli.it" }, this.loading &&
|
|
493
530
|
[...new Array(4)].map((_, index$1) => (index.h(index.Fragment, null, index.h("li", { role: "none" }, index.h("div", { class: "menubar-item" }, index.h("z-ghost-loading", null))), index$1 < 3 && index.h("li", { role: "separator" })))), this.items?.map((item, index$1) => (index.h(index.Fragment, null, index.h("li", { role: "none" }, index.h("a", { class: {
|
|
494
531
|
'menubar-item': true,
|
|
495
532
|
'active': this.isActive(item),
|
|
496
|
-
}, 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 }, index.h("span", { "data-text": item.label }, item.label), item.menuItems?.length > 0 && (index.h("z-icon", { name: this.openMenu === item.id ? 'chevron-up' : 'chevron-down', width: "0.875rem", height: "0.875rem" })))), index$1 < this.items?.length - 1 && index.h("li", { role: "separator" }))))), index.h("zanit-search-form", { searchQuery: this.searchQuery, onResetSearch: () => (this.searchQuery = undefined) })), this.items.map((item) => this.openMenu === item.id && (index.h(Menu, { controlledBy: item.id, items: item.menuItems, currentPath: this.currentPath, onItemKeyDown: (event) => this.handleMenuKeydown(event) })))), this.items
|
|
533
|
+
}, 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 }, index.h("span", { "data-text": item.label }, item.label), item.menuItems?.length > 0 && (index.h("z-icon", { name: this.openMenu === item.id ? 'chevron-up' : 'chevron-down', width: "0.875rem", height: "0.875rem" })))), index$1 < this.items?.length - 1 && index.h("li", { role: "separator" }))))), index.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 && (index.h(Menu, { controlledBy: item.id, items: item.menuItems, currentPath: this.currentPath, onItemKeyDown: (event) => this.handleMenuKeydown(event) })))), this.items
|
|
497
534
|
?.filter((item) => this.isActive(item))
|
|
498
535
|
.map((item) => item.navbarItems?.length && (index.h("nav", { class: { 'sub-menubar': true, 'shadow-wrapper': true }, "aria-label": `Sezioni: ${item.label}` }, index.h("ul", { role: "menubar" }, item.navbarItems.map((subitem) => (index.h(index.Fragment, null, index.h("li", { role: "none" }, index.h("a", { class: {
|
|
499
536
|
'menubar-item': true,
|
|
@@ -509,7 +546,7 @@ const ZanitMenubar = class {
|
|
|
509
546
|
};
|
|
510
547
|
ZanitMenubar.style = menubarCss + menuCss$1;
|
|
511
548
|
|
|
512
|
-
const mobileMenubarCss = ":host{position:relative;z-index:2;display:block;width:100%;max-width:100%;background-color:#fff;color:var(--gray900);fill: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}nav{display:flex;width:100%;align-items:center;padding-left:var(--grid-margin);gap:8px}nav::after{position:absolute;top:0;right:0;width:100%;height:100%;background:transparent;box-shadow:var(--shadow-1);content:'';pointer-events:none}z-logo{margin:8px 0}.mobile-menu{position:absolute;top:100%;left:0;display:flex;overflow:auto;width:100%;max-height:calc(100vh - 48px - var(--zanit-menubar-top-offset, 0px));flex-direction:column;padding:16px var(--grid-margin) 32px;background-color:#fff;box-shadow:var(--shadow-2);gap:8px}.mobile-menu li{width:100%}.mobile-menu .items-container{display:flex;min-height:256px;flex-direction:column;gap:8px}.mobile-menu .items-container z-ghost-loading{width:40%;height:1.2rem}.mobile-menu .items-container .menubar-item{display:block;width:100%;padding:8px 0;font-size:1rem;text-align:left}.mobile-menu .items-container li:not(:last-child) .menubar-item{border-bottom:1px solid #000}[role='menuitem'].parent{display:flex;width:fit-content;align-items:center;padding:0;border:none;font-size:0.875rem;gap:8px}zanit-search-form{margin-left:auto}";
|
|
549
|
+
const mobileMenubarCss = ":host{position:relative;z-index:2;display:block;width:100%;max-width:100%;height:3rem;background-color:#fff;color:var(--gray900);fill: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}nav{display:flex;width:100%;align-items:center;padding-left:var(--grid-margin);gap:8px}nav::after{position:absolute;top:0;right:0;width:100%;height:100%;background:transparent;box-shadow:var(--shadow-1);content:'';pointer-events:none}z-logo{margin:8px 0}.mobile-menu{position:absolute;top:100%;left:0;display:flex;overflow:auto;width:100%;max-height:calc(100vh - 48px - var(--zanit-menubar-top-offset, 0px));flex-direction:column;padding:16px var(--grid-margin) 32px;background-color:#fff;box-shadow:var(--shadow-2);gap:8px}.mobile-menu li{width:100%}.mobile-menu .items-container{display:flex;min-height:256px;flex-direction:column;gap:8px}.mobile-menu .items-container z-ghost-loading{width:40%;height:1.2rem}.mobile-menu .items-container .menubar-item{display:block;width:100%;padding:8px 0;font-size:1rem;text-align:left}.mobile-menu .items-container li:not(:last-child) .menubar-item{border-bottom:1px solid #000}[role='menuitem'].parent{display:flex;width:fit-content;align-items:center;padding:0;border:none;font-size:0.875rem;gap:8px}zanit-search-form{margin-left:auto}";
|
|
513
550
|
|
|
514
551
|
const menuCss = ".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}}";
|
|
515
552
|
|
|
@@ -526,6 +563,10 @@ const ZanitMobileMenubar = class {
|
|
|
526
563
|
searchQuery = undefined;
|
|
527
564
|
/** Whether the menubar is loading the data. */
|
|
528
565
|
loading = false;
|
|
566
|
+
/** Environment for search suggestions */
|
|
567
|
+
searchEnv = SearchEnv.PROD;
|
|
568
|
+
/** Search area (e.g. "SCUOLA", "UNIVERSITÀ", "DIZIONARI"). */
|
|
569
|
+
searchArea;
|
|
529
570
|
/** Last active item ID. */
|
|
530
571
|
lastCurrent = undefined;
|
|
531
572
|
parentItem = undefined;
|
|
@@ -655,7 +696,7 @@ const ZanitMobileMenubar = class {
|
|
|
655
696
|
this.open = false;
|
|
656
697
|
}
|
|
657
698
|
render() {
|
|
658
|
-
return (index.h("nav", { key: '
|
|
699
|
+
return (index.h("nav", { key: '76079ce1e66f1b568f6e7eac1f67b91af0f2f48a', "aria-label": "Zanichelli.it" }, index.h("button", { key: '630b16be60aba3d7027fbe4b9e19e440cb454267', 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() }, index.h("z-icon", { key: '4c86d84d421ab93fb1c815c5a667dd55ce8254ac', name: this.open ? 'multiply' : 'burger-menu', width: "1.5rem", height: "1.5rem" })), index.h("z-logo", { key: '03c7b8613698098cf3a1ff4b1b8d649cb7d5b92a', imageAlt: "Logo Zanichelli", link: "/", height: 32, width: 126 }), index.h("zanit-search-form", { key: '5a1385991eebcf17ac8c275c8c69f6662f75e3b7', searchQuery: this.searchQuery, onResetSearch: () => (this.searchQuery = undefined), searchArea: this.searchArea, searchEnv: this.searchEnv }), this.open && (index.h("ul", { key: 'bc627e55f902beaac658f02d90ed78836fde193b', class: "mobile-menu", role: "menubar" }, !this.loading && this.currentPath && this.currentPath.length > 0 && (index.h("li", { key: '4708f9ee160d62a6cbf6333e11c1b9d02ae3d34c', role: "none" }, index.h("a", { key: '9fd59125f8cb87f6c86108eea7ba79a04bc4d68c', class: "parent", href: this.parentItem?.href ?? '/', id: this.parentItem?.id ?? undefined, role: "menuitem", tabIndex: -1, onKeyDown: (event) => this.handleItemKeydown(event), target: this.parentItem?.target }, index.h("z-icon", { key: '615bc59a1f058a745bdadd90c6f51f9abc757df1', name: "arrow-left", width: "0.5rem", height: "0.5rem" }), index.h("span", { key: '66a80691639e97b2d7d7d61cc45f8b47dcdabafe' }, this.parentItem?.label || 'Home')))), this.loading ? (index.h("div", { class: "items-container", role: "none" }, [...new Array(4)].map(() => (index.h("li", { role: "none" }, index.h("div", { class: "menubar-item", role: "none" }, index.h("z-ghost-loading", null))))))) : this.menuType === 'menu' ? (index.h(Menu, { items: this.menuItems, controlledBy: this.parentItem?.id, currentPath: this.currentPath, onItemKeyDown: (event) => this.handleItemKeydown(event) })) : (this.menuItems?.length > 0 && (index.h("div", { class: "items-container", role: "none" }, this.menuItems.map((item) => (index.h("li", { role: "none" }, index.h("a", { class: {
|
|
659
700
|
'menu-item': this.menuType === 'menu',
|
|
660
701
|
'menubar-item': this.menuType === 'menubar',
|
|
661
702
|
}, 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 }, index.h("span", { "data-text": item.label }, item.label))))))))))));
|
|
@@ -668,7 +709,91 @@ const ZanitMobileMenubar = class {
|
|
|
668
709
|
};
|
|
669
710
|
ZanitMobileMenubar.style = mobileMenubarCss + menuCss;
|
|
670
711
|
|
|
671
|
-
|
|
712
|
+
var AREA_LABELS;
|
|
713
|
+
(function (AREA_LABELS) {
|
|
714
|
+
AREA_LABELS["SCUOLA"] = "Scuola";
|
|
715
|
+
AREA_LABELS["UNIVERSIT\u00C0"] = "Universit\u00E0";
|
|
716
|
+
AREA_LABELS["GIURIDICO"] = "Giuridico";
|
|
717
|
+
AREA_LABELS["DIZIONARI"] = "Dizionari";
|
|
718
|
+
AREA_LABELS["SAGGISTICA"] = "Saggistica";
|
|
719
|
+
})(AREA_LABELS || (AREA_LABELS = {}));
|
|
720
|
+
const AREA_ORDER = Object.keys(AREA_LABELS);
|
|
721
|
+
function buildSuggestions(query, subjectsByArea, selectedArea) {
|
|
722
|
+
const matchingSubjectAreas = findSubjectAreas(query, subjectsByArea);
|
|
723
|
+
const hasSubject = matchingSubjectAreas.length > 0;
|
|
724
|
+
const subject = hasSubject ? query.toUpperCase() : undefined;
|
|
725
|
+
const suggestions = [];
|
|
726
|
+
if (selectedArea)
|
|
727
|
+
suggestions.push(buildWordSuggestion(query, selectedArea));
|
|
728
|
+
suggestions.push(buildWordSuggestion(query));
|
|
729
|
+
if (hasSubject) {
|
|
730
|
+
if (selectedArea) {
|
|
731
|
+
const orderedSubjectAreas = [
|
|
732
|
+
...matchingSubjectAreas.filter((area) => area === selectedArea),
|
|
733
|
+
...matchingSubjectAreas
|
|
734
|
+
.filter((area) => area !== selectedArea)
|
|
735
|
+
.sort((a, b) => getAreaOrder(a) - getAreaOrder(b)),
|
|
736
|
+
];
|
|
737
|
+
orderedSubjectAreas.forEach((area) => suggestions.push(buildSubjectSuggestion(query, area, subject)));
|
|
738
|
+
}
|
|
739
|
+
else {
|
|
740
|
+
matchingSubjectAreas
|
|
741
|
+
.sort((a, b) => getAreaOrder(a) - getAreaOrder(b))
|
|
742
|
+
.forEach((subjectArea) => suggestions.push(buildSubjectSuggestion(query, subjectArea, subject)));
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
return suggestions;
|
|
746
|
+
}
|
|
747
|
+
const buildWordSuggestion = (user_query, area) => {
|
|
748
|
+
return {
|
|
749
|
+
id: buildId(`word-${user_query}-${area}`),
|
|
750
|
+
label: buildLabel(user_query, area, false, false),
|
|
751
|
+
html_label: buildLabel(user_query, area, false, true),
|
|
752
|
+
url: buildUrl({ q: user_query, ...(area ? { area } : {}), user_query }),
|
|
753
|
+
...buildDetail(user_query, user_query, area),
|
|
754
|
+
};
|
|
755
|
+
};
|
|
756
|
+
const buildSubjectSuggestion = (user_query, area, subject) => {
|
|
757
|
+
return {
|
|
758
|
+
id: buildId(`subj-${user_query}-${area}-${subject}`),
|
|
759
|
+
label: buildLabel(user_query, area, true, false),
|
|
760
|
+
html_label: buildLabel(user_query, area, true, true),
|
|
761
|
+
url: buildUrl({ area, materia: subject, user_query }),
|
|
762
|
+
...buildDetail(user_query, undefined, area, subject),
|
|
763
|
+
};
|
|
764
|
+
};
|
|
765
|
+
const buildId = (string) => string
|
|
766
|
+
.split('')
|
|
767
|
+
.map((c) => c.charCodeAt(0).toString(16))
|
|
768
|
+
.join('');
|
|
769
|
+
const buildUrl = (params) => {
|
|
770
|
+
return `ricerca?${new URLSearchParams(params).toString()}`;
|
|
771
|
+
};
|
|
772
|
+
const buildDetail = (user_query, query, area, subject) => ({
|
|
773
|
+
user_query,
|
|
774
|
+
...(query ? { query } : {}),
|
|
775
|
+
...(area ? { area } : {}),
|
|
776
|
+
...(subject ? { subject } : {}),
|
|
777
|
+
});
|
|
778
|
+
const buildLabel = (user_query, area, isSubject = false, isHtml = false) => {
|
|
779
|
+
const openStrong = isHtml ? `<strong>` : ``;
|
|
780
|
+
const closeStrong = isHtml ? `</strong>` : ``;
|
|
781
|
+
return `Cerca la ${isSubject ? `materia` : `parola`} ${openStrong}${user_query}${closeStrong} ${area ? `nel catalogo ${openStrong}${AREA_LABELS[area] ?? area}${closeStrong}` : `in tutto il sito`}`;
|
|
782
|
+
};
|
|
783
|
+
function findSubjectAreas(query, subjectsByArea) {
|
|
784
|
+
const cleanedQuery = cleanSearch(query);
|
|
785
|
+
return Object.entries(subjectsByArea)
|
|
786
|
+
.filter(([, subjects]) => subjects.some((subject) => subject.toLowerCase() === cleanedQuery))
|
|
787
|
+
.map(([area]) => area);
|
|
788
|
+
}
|
|
789
|
+
/** Clear search string: lowercase, remove multiple spaces */
|
|
790
|
+
const cleanSearch = (s) => s.toLowerCase().replace(/\s+/g, ' ');
|
|
791
|
+
const getAreaOrder = (area) => {
|
|
792
|
+
const index = AREA_ORDER.indexOf(area);
|
|
793
|
+
return index >= 0 ? index : 100;
|
|
794
|
+
};
|
|
795
|
+
|
|
796
|
+
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);height:3rem;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;top:3rem;left:50%;width:100vw;border-top:1px solid var(--gray200);margin-left:-50vw;background:#fff;box-shadow:var(--shadow-1)}.suggestions-wrapper.hidden{display:none}.suggestions{display:flex;width:100%;flex-direction:column;align-items:stretch;padding:var(--space-unit);margin:0 auto}.suggestion{padding:calc(var(--space-unit) * 0.75) var(--space-unit);cursor:pointer;font-size:1rem;line-height:1.5rem}.suggestion strong{font-size:1.125rem}.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{max-width:1366px;padding:var(--space-unit) calc(var(--space-unit) * 3)}}";
|
|
672
797
|
|
|
673
798
|
const ZanitSearchForm = class {
|
|
674
799
|
constructor(hostRef) {
|
|
@@ -677,44 +802,77 @@ const ZanitSearchForm = class {
|
|
|
677
802
|
this.resetSearch = index.createEvent(this, "resetSearch");
|
|
678
803
|
}
|
|
679
804
|
formElement;
|
|
805
|
+
subjectsByArea = {};
|
|
806
|
+
timer;
|
|
680
807
|
get host() { return index.getElement(this); }
|
|
681
808
|
/** Indicates whether the searchbar is visible and usable. */
|
|
682
809
|
showSearchbar = false;
|
|
683
810
|
/** Search query to apply. */
|
|
684
811
|
_searchQuery = undefined;
|
|
812
|
+
/** Search suggestions to show in the autocomplete dropdown. */
|
|
813
|
+
suggestions = [];
|
|
814
|
+
/** Active suggestion - used for keyboard navigation */
|
|
815
|
+
activeSuggestion = '';
|
|
816
|
+
/** Show suggestions list */
|
|
817
|
+
showSuggestions = false;
|
|
685
818
|
/** Initial search query */
|
|
686
819
|
searchQuery = undefined;
|
|
820
|
+
/** Environment for search suggestions */
|
|
821
|
+
searchEnv = SearchEnv.PROD;
|
|
822
|
+
/** Search area (e.g. "SCUOLA", "UNIVERSITÀ", "DIZIONARI"). */
|
|
823
|
+
searchArea;
|
|
687
824
|
onSearchQueryChange() {
|
|
688
825
|
this._searchQuery = this.searchQuery;
|
|
689
826
|
if (this.searchQuery) {
|
|
690
827
|
this.openSearchbar();
|
|
691
828
|
}
|
|
829
|
+
this.resetSuggestions();
|
|
830
|
+
}
|
|
831
|
+
onSearchAreaChange() {
|
|
832
|
+
this.resetSuggestions();
|
|
833
|
+
}
|
|
834
|
+
onShowSearchbarChange() {
|
|
835
|
+
if (!this.showSearchbar) {
|
|
836
|
+
this.showSuggestions = false;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
onShowSuggestionsChange() {
|
|
840
|
+
this.activeSuggestion = '';
|
|
692
841
|
}
|
|
693
842
|
/** Emitted on search form submission. */
|
|
694
843
|
search;
|
|
695
844
|
resetSearch;
|
|
696
845
|
async connectedCallback() {
|
|
846
|
+
this.subjectsByArea = await getSubjectsByArea(this.searchEnv);
|
|
697
847
|
this.showSearchbar = !!this.searchQuery;
|
|
698
848
|
this._searchQuery = this.searchQuery;
|
|
699
849
|
}
|
|
700
850
|
/** Close open searchbar when clicking outside. */
|
|
701
851
|
handleOutsideClick(event) {
|
|
702
|
-
if (this.showSearchbar && this.
|
|
852
|
+
if (this.showSearchbar && this.host && !containsTarget(this.host, event)) {
|
|
703
853
|
this.showSearchbar = false;
|
|
704
854
|
}
|
|
705
855
|
}
|
|
706
|
-
/** Close the
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
856
|
+
/** Close the searchbar/suggestions when pressing Escape. */
|
|
857
|
+
handleEsc(event) {
|
|
858
|
+
if (!isEscKey(event)) {
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
if (this.showSuggestions) {
|
|
862
|
+
this.showSuggestions = false;
|
|
863
|
+
}
|
|
864
|
+
else {
|
|
865
|
+
this.showSearchbar = false;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
/** Close the searchbar/suggestions when pressing Tab. */
|
|
869
|
+
handleTab(event) {
|
|
870
|
+
if (!isTabKey(event)) {
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
873
|
+
this.showSuggestions = false;
|
|
874
|
+
if (!containsTarget(this.host, event)) {
|
|
875
|
+
this.showSearchbar = false;
|
|
718
876
|
}
|
|
719
877
|
}
|
|
720
878
|
openSearchbar() {
|
|
@@ -728,30 +886,114 @@ const ZanitSearchForm = class {
|
|
|
728
886
|
this.searchQuery = undefined;
|
|
729
887
|
this.resetSearch.emit();
|
|
730
888
|
}
|
|
889
|
+
resetSuggestions() {
|
|
890
|
+
this.suggestions = [];
|
|
891
|
+
this.showSuggestions = false;
|
|
892
|
+
}
|
|
731
893
|
handleInputChange(event) {
|
|
732
894
|
this._searchQuery = event.target.value;
|
|
733
895
|
if (!this._searchQuery) {
|
|
734
896
|
this.searchQuery = undefined;
|
|
735
897
|
}
|
|
898
|
+
this.updateSuggestions();
|
|
899
|
+
}
|
|
900
|
+
updateSuggestions() {
|
|
901
|
+
clearTimeout(this.timer);
|
|
902
|
+
const query = (this._searchQuery || '').trim();
|
|
903
|
+
if (query.length < 3) {
|
|
904
|
+
this.resetSuggestions();
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
this.timer = setTimeout(() => {
|
|
908
|
+
this.resetSuggestions();
|
|
909
|
+
this.suggestions = buildSuggestions(query, this.subjectsByArea, this.searchArea?.toUpperCase());
|
|
910
|
+
this.showSuggestions = true;
|
|
911
|
+
}, 300);
|
|
736
912
|
}
|
|
737
913
|
onSearchSubmit(event) {
|
|
738
914
|
event.preventDefault();
|
|
739
915
|
if (!this._searchQuery) {
|
|
740
916
|
return;
|
|
741
917
|
}
|
|
918
|
+
if (this.activeSuggestion) {
|
|
919
|
+
const suggestion = this.suggestions.find((s) => s.id === this.activeSuggestion);
|
|
920
|
+
if (suggestion) {
|
|
921
|
+
this.submitSuggestionSearch(suggestion);
|
|
922
|
+
this.showSuggestions = false;
|
|
923
|
+
return;
|
|
924
|
+
}
|
|
925
|
+
}
|
|
742
926
|
this.showSearchbar = false;
|
|
743
|
-
const searchEv = this.search.emit({ query: this._searchQuery });
|
|
927
|
+
const searchEv = this.search.emit({ query: this._searchQuery, area: this.searchArea });
|
|
744
928
|
// do not submit the form if the event default behavior was prevented
|
|
745
929
|
if (searchEv.defaultPrevented) {
|
|
746
930
|
return;
|
|
747
931
|
}
|
|
748
932
|
this.formElement.submit();
|
|
749
933
|
}
|
|
934
|
+
submitSuggestionSearch(suggestion) {
|
|
935
|
+
const ev = this.search.emit({
|
|
936
|
+
user_query: suggestion.user_query,
|
|
937
|
+
query: suggestion.query,
|
|
938
|
+
area: suggestion.area,
|
|
939
|
+
subject: suggestion.subject,
|
|
940
|
+
});
|
|
941
|
+
if (!ev.defaultPrevented) {
|
|
942
|
+
window.location.href = suggestion.url;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
handleSuggestionsNav(event) {
|
|
946
|
+
if (!isArrowDownKey(event) && !isArrowUpKey(event)) {
|
|
947
|
+
return;
|
|
948
|
+
}
|
|
949
|
+
if (!this.suggestions.length) {
|
|
950
|
+
return;
|
|
951
|
+
}
|
|
952
|
+
const options = this.suggestions.map((o) => o.id);
|
|
953
|
+
if (!options.length) {
|
|
954
|
+
return;
|
|
955
|
+
}
|
|
956
|
+
event.preventDefault();
|
|
957
|
+
event.stopPropagation();
|
|
958
|
+
if (!this.showSuggestions) {
|
|
959
|
+
this.showSuggestions = true;
|
|
960
|
+
}
|
|
961
|
+
let nextId = null;
|
|
962
|
+
const firstId = options[0];
|
|
963
|
+
const lastId = options[options.length - 1];
|
|
964
|
+
const currOption = options.indexOf(this.activeSuggestion);
|
|
965
|
+
if (currOption < 0) {
|
|
966
|
+
nextId = isArrowDownKey(event) ? firstId : lastId;
|
|
967
|
+
}
|
|
968
|
+
else {
|
|
969
|
+
if (isArrowDownKey(event)) {
|
|
970
|
+
nextId = options[currOption + 1] || lastId;
|
|
971
|
+
}
|
|
972
|
+
else {
|
|
973
|
+
nextId = options[currOption - 1] || firstId;
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
this.activeSuggestion = nextId;
|
|
977
|
+
}
|
|
978
|
+
renderSuggestions() {
|
|
979
|
+
return (index.h("div", { class: { 'suggestions-wrapper': true, 'hidden': !this.showSuggestions || !this.suggestions.length }, onPointerOver: (e) => e.preventDefault() }, index.h("div", { id: "search-suggestions", class: "suggestions", role: "listbox", "aria-label": "Seleziona tra i suggerimenti" }, this.suggestions.map((suggestion, k) => {
|
|
980
|
+
return (index.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) }));
|
|
981
|
+
}))));
|
|
982
|
+
}
|
|
750
983
|
render() {
|
|
751
|
-
return (index.h("form", { key: '
|
|
984
|
+
return (index.h(index.Host, { key: '5d4462489f2dd40636fd2bb025cb468bc4c5616e' }, index.h("form", { key: '21b2841bb46a3a839a4e4b4443635d48f70b4ae4', 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 && (index.h("input", { key: '67a60d9d8995e2e06ce1c27e3946158e55a142b0', type: "hidden", name: "area", value: this.searchArea })), index.h("div", { key: '09cecaba254019023f8206fa777bda6273cbeb15', class: "input-wrapper", role: "none" }, this.searchQuery && (index.h("button", { key: 'b50b141eba8ced81b4c97ffb9ed4547eada6494f', type: "reset", "aria-label": "Svuota campo di ricerca", disabled: !this.showSearchbar, "aria-hidden": !this.showSearchbar ? 'true' : undefined, tabIndex: !this.showSearchbar ? -1 : 0 }, index.h("z-icon", { key: 'b9a46579d4ae8e7850f38758b12eb0ec1aba731f', name: "multiply-circled" }))), index.h("input", { key: '3fbae3a688e7c775a5c96df4d1390f89da032f5b', 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.showSuggestions ? '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) => {
|
|
985
|
+
// INFO: prevent ESC from clearing input
|
|
986
|
+
if (isEscKey(e)) {
|
|
987
|
+
e.preventDefault();
|
|
988
|
+
}
|
|
989
|
+
this.handleSuggestionsNav(e);
|
|
990
|
+
} })), index.h("button", { key: '996e557aef2f19dedc0d4dc76df392336ce85af3', 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 : index.h("span", { class: "searchbar-button-label" }, "Cerca"), index.h("z-icon", { key: '85eac62f283fd347316f7bcdd45220e5f8c32040', name: "search" }))), this.renderSuggestions()));
|
|
752
991
|
}
|
|
753
992
|
static get watchers() { return {
|
|
754
|
-
"searchQuery": ["onSearchQueryChange"]
|
|
993
|
+
"searchQuery": ["onSearchQueryChange"],
|
|
994
|
+
"searchArea": ["onSearchAreaChange"],
|
|
995
|
+
"showSearchbar": ["onShowSearchbarChange"],
|
|
996
|
+
"showSuggestions": ["onShowSuggestionsChange"]
|
|
755
997
|
}; }
|
|
756
998
|
};
|
|
757
999
|
ZanitSearchForm.style = searchFormCss;
|