@zanichelli/zanichelli-it-frontend-kit 1.0.0 → 1.0.2

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 (102) hide show
  1. package/dist/cjs/index-xkrZykI_.js +1532 -0
  2. package/dist/cjs/index-xkrZykI_.js.map +1 -0
  3. package/dist/cjs/index.cjs.js +5 -0
  4. package/dist/cjs/index.cjs.js.map +1 -0
  5. package/dist/cjs/loader.cjs.js +15 -0
  6. package/dist/cjs/loader.cjs.js.map +1 -0
  7. package/dist/cjs/zanichelli-it-frontend-kit.cjs.js +27 -0
  8. package/dist/cjs/zanichelli-it-frontend-kit.cjs.js.map +1 -0
  9. package/dist/cjs/zanit-menubar.zanit-mobile-menubar.zanit-search-form.entry.cjs.js.map +1 -0
  10. package/dist/cjs/zanit-menubar_3.cjs.entry.js +676 -0
  11. package/dist/cjs/zanit-menubar_3.cjs.entry.js.map +1 -0
  12. package/dist/collection/collection-manifest.json +14 -0
  13. package/dist/collection/components/menubar/menu/menu.css +98 -0
  14. package/dist/collection/components/menubar/menu/menu.js +38 -0
  15. package/dist/collection/components/menubar/menu/menu.js.map +1 -0
  16. package/dist/collection/components/menubar/menubar.css +167 -0
  17. package/{www/build/zanit-menubar.entry.js → dist/collection/components/menubar/menubar.js} +157 -25
  18. package/dist/collection/components/menubar/menubar.js.map +1 -0
  19. package/dist/collection/components/menubar/mobile-menubar/mobile-menubar.css +114 -0
  20. package/{www/build/zanit-mobile-menubar.entry.js → dist/collection/components/menubar/mobile-menubar/mobile-menubar.js} +149 -25
  21. package/dist/collection/components/menubar/mobile-menubar/mobile-menubar.js.map +1 -0
  22. package/dist/collection/components/menubar/search-form/search-form.css +147 -0
  23. package/{www/build/zanit-search-form.entry.js → dist/collection/components/menubar/search-form/search-form.js} +98 -22
  24. package/dist/collection/components/menubar/search-form/search-form.js.map +1 -0
  25. package/dist/collection/index.js +11 -0
  26. package/dist/collection/index.js.map +1 -0
  27. package/dist/collection/utils/types.js +2 -0
  28. package/dist/collection/utils/types.js.map +1 -0
  29. package/dist/{zanichelli-it-frontend-kit/utils-CaxAWyZI.js → collection/utils/utils.js} +3 -7
  30. package/dist/collection/utils/utils.js.map +1 -0
  31. package/dist/components/index.js +1290 -0
  32. package/dist/components/index.js.map +1 -0
  33. package/dist/{zanichelli-it-frontend-kit/zanit-mobile-menubar.entry.js → components/p-CQEWv_Pv.js} +87 -14
  34. package/dist/components/p-CQEWv_Pv.js.map +1 -0
  35. package/dist/{zanichelli-it-frontend-kit/zanit-search-form.entry.js → components/p-CiHl-h3q.js} +52 -13
  36. package/dist/components/p-CiHl-h3q.js.map +1 -0
  37. package/dist/{zanichelli-it-frontend-kit/zanit-menubar.entry.js → components/zanit-menubar.js} +56 -13
  38. package/dist/components/zanit-menubar.js.map +1 -0
  39. package/dist/components/zanit-mobile-menubar.js +9 -0
  40. package/dist/components/zanit-mobile-menubar.js.map +1 -0
  41. package/dist/components/zanit-search-form.js +9 -0
  42. package/dist/components/zanit-search-form.js.map +1 -0
  43. package/dist/esm/index-BWVQ0LD4.js +1504 -0
  44. package/dist/esm/index-BWVQ0LD4.js.map +1 -0
  45. package/dist/esm/index.js +4 -0
  46. package/dist/esm/index.js.map +1 -0
  47. package/dist/esm/loader.js +13 -0
  48. package/dist/esm/loader.js.map +1 -0
  49. package/dist/esm/zanichelli-it-frontend-kit.js +23 -0
  50. package/dist/esm/zanichelli-it-frontend-kit.js.map +1 -0
  51. package/dist/esm/zanit-menubar.zanit-mobile-menubar.zanit-search-form.entry.js.map +1 -0
  52. package/dist/esm/zanit-menubar_3.entry.js +672 -0
  53. package/dist/esm/zanit-menubar_3.entry.js.map +1 -0
  54. package/dist/index.cjs.js +1 -0
  55. package/dist/index.js +1 -0
  56. package/dist/zanichelli-it-frontend-kit/index.esm.js +0 -10
  57. package/dist/zanichelli-it-frontend-kit/index.esm.js.map +1 -1
  58. package/dist/zanichelli-it-frontend-kit/p-BWVQ0LD4.js +3 -0
  59. package/dist/zanichelli-it-frontend-kit/p-BWVQ0LD4.js.map +1 -0
  60. package/dist/zanichelli-it-frontend-kit/p-b6c74a1e.entry.js +2 -0
  61. package/dist/zanichelli-it-frontend-kit/p-b6c74a1e.entry.js.map +1 -0
  62. package/dist/zanichelli-it-frontend-kit/zanichelli-it-frontend-kit.css +1 -993
  63. package/dist/zanichelli-it-frontend-kit/zanichelli-it-frontend-kit.esm.js +1 -49
  64. package/dist/zanichelli-it-frontend-kit/zanichelli-it-frontend-kit.esm.js.map +1 -1
  65. package/dist/zanichelli-it-frontend-kit/zanit-menubar.zanit-mobile-menubar.zanit-search-form.entry.esm.js.map +1 -0
  66. package/package.json +1 -1
  67. package/www/build/index.esm.js +0 -10
  68. package/www/build/index.esm.js.map +1 -1
  69. package/www/build/p-984b8fa6.css +1 -0
  70. package/www/build/p-BWVQ0LD4.js +3 -0
  71. package/www/build/p-BWVQ0LD4.js.map +1 -0
  72. package/www/build/p-b6c74a1e.entry.js +2 -0
  73. package/www/build/p-b6c74a1e.entry.js.map +1 -0
  74. package/www/build/p-d36eb550.js +2 -0
  75. package/www/build/zanichelli-it-frontend-kit.css +1 -993
  76. package/www/build/zanichelli-it-frontend-kit.esm.js +1 -49
  77. package/www/build/zanichelli-it-frontend-kit.esm.js.map +1 -1
  78. package/www/build/zanit-menubar.zanit-mobile-menubar.zanit-search-form.entry.esm.js.map +1 -0
  79. package/www/index.html +2 -11
  80. package/dist/zanichelli-it-frontend-kit/index-Cn3aX5eK.js +0 -4170
  81. package/dist/zanichelli-it-frontend-kit/index-Cn3aX5eK.js.map +0 -1
  82. package/dist/zanichelli-it-frontend-kit/menu-DZlhu_pe.js +0 -46
  83. package/dist/zanichelli-it-frontend-kit/menu-DZlhu_pe.js.map +0 -1
  84. package/dist/zanichelli-it-frontend-kit/utils-CaxAWyZI.js.map +0 -1
  85. package/dist/zanichelli-it-frontend-kit/zanit-menubar.entry.esm.js.map +0 -1
  86. package/dist/zanichelli-it-frontend-kit/zanit-menubar.entry.js.map +0 -1
  87. package/dist/zanichelli-it-frontend-kit/zanit-mobile-menubar.entry.esm.js.map +0 -1
  88. package/dist/zanichelli-it-frontend-kit/zanit-mobile-menubar.entry.js.map +0 -1
  89. package/dist/zanichelli-it-frontend-kit/zanit-search-form.entry.esm.js.map +0 -1
  90. package/dist/zanichelli-it-frontend-kit/zanit-search-form.entry.js.map +0 -1
  91. package/www/build/index-Cn3aX5eK.js +0 -4170
  92. package/www/build/index-Cn3aX5eK.js.map +0 -1
  93. package/www/build/menu-DZlhu_pe.js +0 -46
  94. package/www/build/menu-DZlhu_pe.js.map +0 -1
  95. package/www/build/utils-CaxAWyZI.js +0 -21
  96. package/www/build/utils-CaxAWyZI.js.map +0 -1
  97. package/www/build/zanit-menubar.entry.esm.js.map +0 -1
  98. package/www/build/zanit-menubar.entry.js.map +0 -1
  99. package/www/build/zanit-mobile-menubar.entry.esm.js.map +0 -1
  100. package/www/build/zanit-mobile-menubar.entry.js.map +0 -1
  101. package/www/build/zanit-search-form.entry.esm.js.map +0 -1
  102. package/www/build/zanit-search-form.entry.js.map +0 -1
@@ -0,0 +1,676 @@
1
+ 'use strict';
2
+
3
+ var index = require('./index-xkrZykI_.js');
4
+
5
+ /**
6
+ * Check if an element contains an event target by checking its composedPath.
7
+ * Useful when an event target may come from a component's shadow DOM.
8
+ */
9
+ const containsTarget = (ancestor, event) => {
10
+ return event
11
+ .composedPath()
12
+ .filter((el) => el !== document && el !== window.window)
13
+ .some((el) => ancestor.contains(el));
14
+ };
15
+ /** Move the focus to `next` element, set tabindex to 0 for `next` and -1 to `current`. */
16
+ const moveFocus = (current, next) => {
17
+ current.tabIndex = -1;
18
+ next.tabIndex = 0;
19
+ next.focus();
20
+ };
21
+
22
+ const DEFAULT_GROUP_KEY = 'default';
23
+ const DEFAULT_GROUP = {
24
+ id: DEFAULT_GROUP_KEY,
25
+ label: DEFAULT_GROUP_KEY,
26
+ };
27
+ /** Get the items grouped by their group. */
28
+ const getGroupedItems = (items) => {
29
+ const groups = items.reduce((grouped, item) => {
30
+ const itemGroup = grouped.find(({ group }) => group.id === (item.group?.id || DEFAULT_GROUP.id));
31
+ if (!itemGroup) {
32
+ grouped.push({ group: item.group ?? DEFAULT_GROUP, items: [item] });
33
+ }
34
+ else {
35
+ itemGroup.items.push(item);
36
+ }
37
+ return grouped;
38
+ }, []);
39
+ // Sort to keep default group at the end
40
+ return groups.sort((a, b) => (a.group.id === DEFAULT_GROUP_KEY ? 1 : b.group.id === DEFAULT_GROUP_KEY ? -1 : 0));
41
+ };
42
+ /**
43
+ * Floating menu component. It shows a list of items that can be grouped.
44
+ */
45
+ const Menu = ({ controlledBy, items, currentPath = [], onItemKeyDown }) => {
46
+ if (!items?.length) {
47
+ return null;
48
+ }
49
+ const groups = getGroupedItems(items);
50
+ const isActive = (item) => currentPath.includes(controlledBy) && currentPath.includes(item.id);
51
+ return (index.h("div", { class: "menu-wrapper", role: "none" },
52
+ index.h("div", { class: "menu", "aria-labelledby": controlledBy ?? undefined, role: "menu" }, groups.map(({ group, items }) => (index.h("div", { class: { group: true, highlight: items.some((item) => item.highlight) } },
53
+ group.id !== DEFAULT_GROUP_KEY ? (index.h("div", { class: "group-name", id: group.id }, group.label)) : groups.length > 1 ? (
54
+ // empty div to keep the same height as the other groups
55
+ index.h("div", { class: "group-name" })) : null,
56
+ index.h("ul", { class: "menu-list", role: "group", "aria-labelledby": group.id !== DEFAULT_GROUP_KEY ? group.id : undefined }, items.map((item) => (index.h("li", { role: "none" }, item.href && (index.h("a", { class: {
57
+ 'menu-item': true,
58
+ 'active': isActive(item),
59
+ }, href: item.href, role: "menuitem", tabIndex: -1, "aria-current": isActive(item) ? 'page' : 'false', onKeyDown: (event) => onItemKeyDown(event), target: item.target }, item.label))))))))))));
60
+ };
61
+
62
+ 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;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}";
63
+
64
+ 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-rg)}.menu .group .menu-list{display:flex;flex-direction:column;gap:8px}.menu .group .menu-list .menu-item{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}.menu .group.highlight .menu-list{gap:16px}}";
65
+
66
+ const ZanitMenubar = class {
67
+ constructor(hostRef) {
68
+ index.registerInstance(this, hostRef);
69
+ }
70
+ get host() { return index.getElement(this); }
71
+ /** Menubar items extracted from `data`. */
72
+ items = [];
73
+ /** ID of the currently open menu. */
74
+ openMenu = undefined;
75
+ /** ID of the item to show the subitems navbar for. */
76
+ openNavbar = undefined;
77
+ /** IDs of the current prop */
78
+ currentPath = [];
79
+ isMobile = false;
80
+ loading = false;
81
+ /** The data to build the menu (as an array of `MenubarItem` or a JSON array) or the url to fetch to retrieve it. */
82
+ data;
83
+ /** Path of the current item. */
84
+ current = undefined;
85
+ /** Initial search query. */
86
+ searchQuery = undefined;
87
+ timerId;
88
+ /** Setup the list of items. */
89
+ async parseData(data) {
90
+ if (!data) {
91
+ return;
92
+ }
93
+ if (data instanceof URL) {
94
+ this.items = await this.fetchData(data);
95
+ }
96
+ else if (data instanceof Promise) {
97
+ this.loading = true;
98
+ this.items = await data;
99
+ this.loading = false;
100
+ }
101
+ else if (typeof data === 'string') {
102
+ try {
103
+ this.items = JSON.parse(data);
104
+ if (!Array.isArray(this.items) || !this.items?.every((item) => item)) {
105
+ throw new Error('Expected an array of MenubarItem objects.');
106
+ }
107
+ }
108
+ catch {
109
+ let url;
110
+ try {
111
+ url = new URL(data);
112
+ }
113
+ catch {
114
+ throw new Error('Invalid string provided for `data` property: not a valid url or JSON.');
115
+ }
116
+ this.items = await this.fetchData(url);
117
+ }
118
+ }
119
+ else if (Array.isArray(data) && data.every((item) => item)) {
120
+ this.items = data;
121
+ }
122
+ else {
123
+ throw new Error('Invalid `data` property value. Expected an url, a JSON or an array/promise of MenubarItem objects.');
124
+ }
125
+ }
126
+ onItemsChange() {
127
+ this.initTabindex();
128
+ }
129
+ onCurrentChange() {
130
+ this.currentPath = this.current?.split('/').filter(Boolean) || [];
131
+ }
132
+ async connectedCallback() {
133
+ const mobileMediaQuery = window.matchMedia('(width < 768px)');
134
+ this.isMobile = mobileMediaQuery.matches;
135
+ mobileMediaQuery.onchange = (mql) => {
136
+ this.isMobile = mql.matches;
137
+ this.initTabindex();
138
+ this.openMenu = undefined;
139
+ };
140
+ await this.parseData(this.data);
141
+ this.onCurrentChange();
142
+ this.initTabindex();
143
+ }
144
+ /** Close any open menu when clicking outside. */
145
+ handleOutsideClick(event) {
146
+ if (!this.openMenu || containsTarget(this.host, event)) {
147
+ return;
148
+ }
149
+ this.openMenu = undefined;
150
+ }
151
+ /** Close any open menu when pressing Escape or Tab. */
152
+ handleKeydown(event) {
153
+ switch (event.key) {
154
+ case 'Escape':
155
+ case 'Tab':
156
+ this.openMenu = undefined;
157
+ break;
158
+ }
159
+ }
160
+ handleMouseover() {
161
+ clearTimeout(this.timerId);
162
+ }
163
+ /**
164
+ * Automatically close any open menu on mouseout after with a little delay.
165
+ * The delay is useful to avoid immediate closing when the pointer briefly leaves the component.
166
+ */
167
+ handleMouseout(event) {
168
+ this.timerId = window.setTimeout(() => {
169
+ if (!this.openMenu || containsTarget(this.host, event)) {
170
+ return;
171
+ }
172
+ this.openMenu = undefined;
173
+ }, 500);
174
+ }
175
+ /** Close the menu when it loses focus. */
176
+ handleFocusout(event) {
177
+ const relatedTarget = event.relatedTarget;
178
+ if (!this.openMenu || this.host.shadowRoot.querySelector('.menu')?.contains(relatedTarget)) {
179
+ return;
180
+ }
181
+ this.openMenu = undefined;
182
+ }
183
+ /** Fetch data from passed URL. */
184
+ async fetchData(url) {
185
+ try {
186
+ this.loading = true;
187
+ const data = await (await fetch(url)).json();
188
+ this.loading = false;
189
+ if (!Array.isArray(data) || !data.every((item) => item)) {
190
+ throw new Error('Invalid data structure. Expected an array of MenuItem objects.');
191
+ }
192
+ return data;
193
+ }
194
+ catch (error) {
195
+ this.loading = false;
196
+ console.error('Error fetching menubar data:', error);
197
+ throw new Error('Failed to fetch menubar data from the provided URL.', { cause: error });
198
+ }
199
+ }
200
+ /** Initialize tabindex on menuitems of menubars, setting -1 to all but the first one. */
201
+ initTabindex() {
202
+ setTimeout(() => {
203
+ this.host.shadowRoot.querySelectorAll('[role="menubar"]')?.forEach((menubar) => {
204
+ menubar
205
+ .querySelectorAll('[role="menuitem"]')
206
+ ?.forEach((item, index) => item.setAttribute('tabindex', index === 0 ? '0' : '-1'));
207
+ });
208
+ }, 100);
209
+ }
210
+ /** Indicates whether the element has to be highlighted by checking whether it is set as current or one of its descendants is. */
211
+ isActive(item) {
212
+ if (this.currentPath.length === 0) {
213
+ return false;
214
+ }
215
+ if (this.currentPath.includes(item.id)) {
216
+ return true;
217
+ }
218
+ if (item.menuItems?.length) {
219
+ return item.menuItems.some((menuItem) => menuItem.id === this.current);
220
+ }
221
+ if (item.navbarItems?.length) {
222
+ const isActive = item.navbarItems.some((navbarItem) => this.isActive(navbarItem));
223
+ if (isActive) {
224
+ return true;
225
+ }
226
+ }
227
+ return false;
228
+ }
229
+ /** Opens the menu associated with the menubar `item`, if any. */
230
+ showMenu(item) {
231
+ this.openMenu = undefined; // close any open menu first
232
+ if (!item.menuItems?.length) {
233
+ return;
234
+ }
235
+ this.openMenu = item.id;
236
+ }
237
+ /** Get all elements with `menuitem` role inside parent's `menubar`. * */
238
+ getParentMenubarElements(itemEl) {
239
+ return Array.from(itemEl?.closest('[role="menubar"]')?.querySelectorAll(':scope > li a[role="menuitem"]') ?? []);
240
+ }
241
+ /** Move the focus to the previous menubar item, or the last one. Then open its menu if any other menu was open. */
242
+ focusPreviousItem(itemEl) {
243
+ this.openMenu = undefined; // close any open menu first
244
+ const menubarElements = this.getParentMenubarElements(itemEl);
245
+ itemEl.tabIndex = -1;
246
+ const currentIndex = menubarElements.indexOf(itemEl);
247
+ const prevItem = menubarElements[(currentIndex - 1 + menubarElements.length) % menubarElements.length]; // get previous item or last one
248
+ prevItem.tabIndex = 0;
249
+ prevItem.focus();
250
+ // open the item's menu if any other menu was open
251
+ if (prevItem.ariaHasPopup === 'true' && this.openMenu) {
252
+ this.openMenu = prevItem.id;
253
+ }
254
+ }
255
+ /** Move the focus to the next menubar item, or the first one. Then open its menu if any other menu was open. */
256
+ focusNextItem(itemEl) {
257
+ this.openMenu = undefined; // close any open menu first
258
+ const menubarElements = this.getParentMenubarElements(itemEl);
259
+ itemEl.tabIndex = -1;
260
+ const currentIndex = menubarElements.indexOf(itemEl);
261
+ const nextItem = menubarElements[(currentIndex + 1) % menubarElements.length]; // get next item or first one
262
+ nextItem.tabIndex = 0;
263
+ nextItem.focus();
264
+ // open the item's menu if any other menu was open
265
+ if (nextItem.ariaHasPopup === 'true' && this.openMenu) {
266
+ this.openMenu = nextItem.id;
267
+ }
268
+ }
269
+ /** Handles keyboard navigation on menubar items. */
270
+ handleItemKeydown(event, item) {
271
+ const target = event.target;
272
+ switch (event.key) {
273
+ case 'Home': {
274
+ event.preventDefault();
275
+ event.stopPropagation();
276
+ const firstItem = this.getParentMenubarElements(target)[0];
277
+ moveFocus(target, firstItem);
278
+ break;
279
+ }
280
+ case 'End': {
281
+ event.preventDefault();
282
+ event.stopPropagation();
283
+ const lastItem = this.getParentMenubarElements(target).pop();
284
+ moveFocus(target, lastItem);
285
+ break;
286
+ }
287
+ case 'ArrowUp': {
288
+ if (!item.menuItems?.length) {
289
+ break;
290
+ }
291
+ event.preventDefault();
292
+ event.stopPropagation();
293
+ this.openMenu = item.id;
294
+ // focus last item of the menu
295
+ setTimeout(() => {
296
+ const menuItems = Array.from(this.host.shadowRoot.querySelectorAll(`[aria-labelledby=${item.id}] [role="menuitem"]`));
297
+ moveFocus(target, menuItems[menuItems.length - 1]);
298
+ }, 100);
299
+ break;
300
+ }
301
+ case 'ArrowRight': {
302
+ event.preventDefault();
303
+ event.stopPropagation();
304
+ this.focusNextItem(target);
305
+ break;
306
+ }
307
+ case 'ArrowDown': {
308
+ if (!item.menuItems?.length) {
309
+ break;
310
+ }
311
+ this.openMenu = item.id;
312
+ setTimeout(() => {
313
+ // focus first item of the menu
314
+ const firsMenuItem = this.host.shadowRoot.querySelector(`[aria-labelledby=${item.id}] [role="menuitem"]`);
315
+ firsMenuItem.tabIndex = 0;
316
+ firsMenuItem.focus();
317
+ }, 100);
318
+ break;
319
+ }
320
+ case 'ArrowLeft': {
321
+ event.preventDefault();
322
+ event.stopPropagation();
323
+ this.focusPreviousItem(target);
324
+ break;
325
+ }
326
+ }
327
+ }
328
+ /** Get the previous element with `role=group`. */
329
+ getPreviousGroup(groupContainer) {
330
+ const groups = Array.from(groupContainer?.closest('[role="menu"]')?.querySelectorAll('[role="group"]') ?? []);
331
+ const currentIndex = groups.indexOf(groupContainer);
332
+ return groups[currentIndex - 1];
333
+ }
334
+ /** Get the next element with `role=group`. */
335
+ getNextGroup(groupContainer) {
336
+ const groups = Array.from(groupContainer?.closest('[role="menu"]')?.querySelectorAll('[role="group"]') ?? []);
337
+ const currentIndex = groups.indexOf(groupContainer);
338
+ return groups[currentIndex + 1];
339
+ }
340
+ /** Handles keyboard navigation events from `Menu` component. */
341
+ handleMenuKeydown(event) {
342
+ const itemElement = event.target;
343
+ const items = Array.from(itemElement.closest('[role="menu"]')?.querySelectorAll('[role="menuitem"]') ?? []);
344
+ const currentIndex = items.indexOf(itemElement);
345
+ switch (event.key) {
346
+ case 'ArrowUp': {
347
+ event.preventDefault();
348
+ event.stopPropagation();
349
+ const prevItem = items[currentIndex - 1] || items[items.length - 1];
350
+ moveFocus(itemElement, prevItem);
351
+ break;
352
+ }
353
+ // Move the focus to the first item of the next group if any, otherwise move it to the next menubar item
354
+ case 'ArrowRight': {
355
+ event.preventDefault();
356
+ event.stopPropagation();
357
+ const currentGroup = itemElement.closest('[role=group]');
358
+ const nextGroup = this.getNextGroup(currentGroup);
359
+ if (!nextGroup) {
360
+ itemElement.tabIndex = -1;
361
+ const menuTriggerId = itemElement.closest('[role="menu"][aria-labelledby]').getAttribute('aria-labelledby');
362
+ const focusedItem = this.host.shadowRoot.getElementById(menuTriggerId);
363
+ this.focusNextItem(focusedItem);
364
+ break;
365
+ }
366
+ const nextGroupItems = (nextGroup.querySelectorAll('[role="menuitem"]') ?? []);
367
+ moveFocus(itemElement, nextGroupItems[0]);
368
+ break;
369
+ }
370
+ case 'ArrowDown': {
371
+ event.preventDefault();
372
+ event.stopPropagation();
373
+ const nextItem = items[currentIndex + 1] || items[0];
374
+ moveFocus(itemElement, nextItem);
375
+ break;
376
+ }
377
+ // Move the focus to the first item of the previous group if any, otherwise move it to the previous menubar item
378
+ case 'ArrowLeft': {
379
+ event.preventDefault();
380
+ event.stopPropagation();
381
+ const currentGroup = itemElement.closest('[role=group]');
382
+ const prevGroup = this.getPreviousGroup(currentGroup);
383
+ if (!prevGroup) {
384
+ itemElement.tabIndex = -1;
385
+ const menuTriggerId = itemElement.closest('[role="menu"][aria-labelledby]').getAttribute('aria-labelledby');
386
+ const focusedItem = this.host.shadowRoot.getElementById(menuTriggerId);
387
+ this.focusPreviousItem(focusedItem);
388
+ break;
389
+ }
390
+ const prevGroupItems = (prevGroup.querySelectorAll('[role="menuitem"]') ?? []);
391
+ moveFocus(itemElement, prevGroupItems[0]);
392
+ break;
393
+ }
394
+ case 'Home':
395
+ // Move to the first menu item
396
+ event.preventDefault();
397
+ event.stopPropagation();
398
+ moveFocus(itemElement, items[0]);
399
+ break;
400
+ case 'End':
401
+ // Move to the last menu item
402
+ event.preventDefault();
403
+ event.stopPropagation();
404
+ moveFocus(itemElement, items[items.length - 1]);
405
+ break;
406
+ }
407
+ }
408
+ render() {
409
+ if (this.isMobile) {
410
+ return (index.h("zanit-mobile-menubar", { items: this.items, currentPath: this.currentPath, searchQuery: this.searchQuery, loading: this.loading }));
411
+ }
412
+ 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 &&
413
+ [...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: {
414
+ 'menubar-item': true,
415
+ 'active': this.isActive(item),
416
+ }, 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
417
+ ?.filter((item) => this.isActive(item))
418
+ .map((item) => item.navbarItems?.length && (index.h("nav", { class: { 'sub-menubar': true, 'shadow-wrapper': true } }, index.h("ul", { role: "menubar" }, item.navbarItems.map((subitem) => (index.h(index.Fragment, null, index.h("li", { role: "none" }, index.h("a", { class: {
419
+ 'menubar-item': true,
420
+ 'active': this.isActive(subitem),
421
+ }, 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 }, index.h("span", null, subitem.label), subitem.menuItems?.length > 0 && (index.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 && (index.h(Menu, { controlledBy: subitem.id, items: subitem.menuItems, currentPath: this.currentPath, onItemKeyDown: (event) => this.handleMenuKeydown(event) }))))))));
422
+ }
423
+ static get watchers() { return {
424
+ "data": ["parseData"],
425
+ "items": ["onItemsChange"],
426
+ "current": ["onCurrentChange"]
427
+ }; }
428
+ };
429
+ ZanitMenubar.style = menubarCss + menuCss$1;
430
+
431
+ 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:8px var(--grid-margin)}nav::after{position:absolute;top:0;right:0;width:100%;height:100%;background:transparent;box-shadow:var(--shadow-1);content:'';pointer-events:none}.burger-button{margin-left:auto}.mobile-menu{position:absolute;top:100%;left:0;display:flex;width:100%;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}";
432
+
433
+ 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-rg)}.menu .group .menu-list{display:flex;flex-direction:column;gap:8px}.menu .group .menu-list .menu-item{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}.menu .group.highlight .menu-list{gap:16px}}";
434
+
435
+ const ZanitMobileMenubar = class {
436
+ constructor(hostRef) {
437
+ index.registerInstance(this, hostRef);
438
+ }
439
+ get host() { return index.getElement(this); }
440
+ /** IDs path of the current item. */
441
+ currentPath = [];
442
+ /** Menubar items. */
443
+ items = [];
444
+ /** Initial search query. */
445
+ searchQuery = undefined;
446
+ /** Whether the menubar is loading the data. */
447
+ loading = false;
448
+ /** Last active item ID. */
449
+ lastCurrent = undefined;
450
+ parentItem = undefined;
451
+ menuItems = undefined;
452
+ /** Whether the items to render come from a menubar or a menu. */
453
+ menuType = undefined;
454
+ open;
455
+ onItemsChange() {
456
+ this.lastCurrent = this.currentPath?.length ? this.currentPath[this.currentPath.length - 1] : undefined;
457
+ this.setupData(this.items);
458
+ }
459
+ /**
460
+ * Find the current item and take its parent, `menuItems` or the `navbarItems`.
461
+ */
462
+ setupData(items, parent) {
463
+ // If no current item is defined, we show all items
464
+ if (this.lastCurrent === undefined) {
465
+ this.parentItem = undefined;
466
+ this.menuType = 'menubar';
467
+ this.menuItems = items;
468
+ return;
469
+ }
470
+ for (const item of items) {
471
+ if (item.id === this.lastCurrent) {
472
+ this.parentItem = parent;
473
+ this.menuType = item.menuItems?.length ? 'menu' : 'menubar';
474
+ this.menuItems = item.menuItems || item.navbarItems;
475
+ return;
476
+ }
477
+ if (this.currentPath.length > 1 &&
478
+ item.id === this.currentPath[this.currentPath.length - 2] &&
479
+ item.menuItems?.some(({ id }) => id === this.lastCurrent)) {
480
+ this.parentItem = item;
481
+ this.menuType = item.menuItems?.length ? 'menu' : 'menubar';
482
+ this.menuItems = item.menuItems || item.navbarItems;
483
+ return;
484
+ }
485
+ if (item.navbarItems?.length) {
486
+ this.setupData(item.navbarItems, item);
487
+ }
488
+ }
489
+ }
490
+ get menuItemsElement() {
491
+ return Array.from(this.host.shadowRoot.querySelectorAll('[role="menuitem"]'));
492
+ }
493
+ /** Initialize tabindex on menuitems, setting -1 to all but the first one. */
494
+ initTabindex() {
495
+ this.menuItemsElement.forEach((item, index) => item.setAttribute('tabindex', index === 0 ? '0' : '-1'));
496
+ }
497
+ toggleMenu() {
498
+ if (this.open) {
499
+ this.open = false;
500
+ }
501
+ else {
502
+ this.open = true;
503
+ setTimeout(() => {
504
+ this.initTabindex();
505
+ this.menuItemsElement[0]?.focus();
506
+ }, 200);
507
+ }
508
+ }
509
+ /** Handles keyboard navigation on mobile menu. */
510
+ handleItemKeydown(event) {
511
+ switch (event.key) {
512
+ case 'ArrowUp': {
513
+ event.preventDefault();
514
+ event.stopPropagation();
515
+ const items = this.menuItemsElement;
516
+ const currentIndex = items.indexOf(event.target);
517
+ const prevItem = items[(currentIndex - 1 + items.length) % items.length];
518
+ moveFocus(items[currentIndex], prevItem);
519
+ break;
520
+ }
521
+ case 'ArrowDown': {
522
+ event.preventDefault();
523
+ event.stopPropagation();
524
+ const items = this.menuItemsElement;
525
+ const currentIndex = items.indexOf(event.target);
526
+ const nextItem = items[(currentIndex + 1) % items.length];
527
+ moveFocus(items[currentIndex], nextItem);
528
+ break;
529
+ }
530
+ case 'Home': {
531
+ event.preventDefault();
532
+ event.stopPropagation();
533
+ moveFocus(event.target, this.menuItemsElement[0]);
534
+ break;
535
+ }
536
+ case 'End': {
537
+ event.preventDefault();
538
+ event.stopPropagation();
539
+ moveFocus(event.target, this.menuItemsElement.pop());
540
+ break;
541
+ }
542
+ }
543
+ }
544
+ connectedCallback() {
545
+ this.lastCurrent = this.currentPath?.length ? this.currentPath[this.currentPath.length - 1] : undefined;
546
+ this.setupData(this.items);
547
+ }
548
+ /** Close the menu when clicking outside. */
549
+ handleOutsideClick(event) {
550
+ if (containsTarget(this.host, event)) {
551
+ return;
552
+ }
553
+ this.open = false;
554
+ }
555
+ /** Close the menu when pressing Escape or Tab. */
556
+ handleKeydown(event) {
557
+ switch (event.key) {
558
+ case 'Escape':
559
+ this.open = false;
560
+ break;
561
+ case 'Tab':
562
+ if (containsTarget(this.host, event)) {
563
+ break;
564
+ }
565
+ this.open = false;
566
+ break;
567
+ }
568
+ }
569
+ /** Close the menu when the focus goes out. */
570
+ handleFocusout(event) {
571
+ if (containsTarget(this.host, event)) {
572
+ return;
573
+ }
574
+ this.open = false;
575
+ }
576
+ render() {
577
+ return (index.h("nav", { key: '8670451f03909d3008f6e21d02ee5c7412d86bac', "aria-label": "Zanichelli.it" }, index.h("z-logo", { key: '8f8704851b84185e6c01bc6cd5e2a3b3cda53a61', imageAlt: "Logo Zanichelli", link: "/", height: 32, width: 126 }), index.h("button", { key: '02271df658a071f9ae0d91f8140b9e8e15064ccc', 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: 'fcbff94368d67da8a237190518452048276882a0', name: this.open ? 'multiply' : 'burger-menu', width: "1.5rem", height: "1.5rem" })), this.open && (index.h("ul", { key: '94fae1693d0ebd41d86cfe55450a40cbff88b7dd', class: "mobile-menu", role: "menubar" }, index.h("li", { key: '5e09e8484e6450646d4da570a0791da92e477fc7', role: "none" }, index.h("zanit-search-form", { key: '564813af11cc4b6c62db80ee2acdbeb54cec935f', searchQuery: this.searchQuery, onResetSearch: () => (this.searchQuery = undefined) })), !this.loading && this.currentPath && this.currentPath.length > 0 && (index.h("li", { key: '7b501d3a1c7dcf705bd1bfd8d03a29573c27f891', role: "none" }, index.h("a", { key: '949db4a79629f0d0ab44cc94d11f717abc87cb4d', 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: '2537588429f0185c67f87702d040fdc8ad7fbe06', name: "arrow-left", width: "0.5rem", height: "0.5rem" }), index.h("span", { key: '732de0ec2a09d41ecacd62d7fa8e5c799e67e533' }, 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: {
578
+ 'menu-item': this.menuType === 'menu',
579
+ 'menubar-item': this.menuType === 'menubar',
580
+ }, 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))))))))))));
581
+ }
582
+ static get watchers() { return {
583
+ "items": ["onItemsChange"],
584
+ "currentPath": ["onItemsChange"]
585
+ }; }
586
+ };
587
+ ZanitMobileMenubar.style = mobileMenubarCss + menuCss;
588
+
589
+ 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}@media (width < 768px){.searchbar{display:flex;align-items:center;border:1px solid #000;border-radius:4px}.searchbar>*:first-child{border-bottom-left-radius:3px;border-top-left-radius:3px}.searchbar button[type='reset']{display:flex;padding:0 0 0 8px;cursor:pointer}.searchbar input{width:100%;height:100%;padding:4px 8px;border:none;background-color:#fff;font-family:var(--font-family-sans);font-size:1rem}.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{padding:4px 8px;border-left:1px solid #000;background:var(--zanit-accent-color);border-bottom-right-radius:3px;border-top-right-radius:3px}.searchbar input:focus:focus-visible,.searchbar .searchbar-button:focus:focus-visible{z-index:1}}@media (width >= 768px){.searchbar{display:flex;font-size:1.5rem}.searchbar.searchbar-open{position:absolute;width:100%;height:100%;inset:0}.searchbar .input-wrapper{display:none;width:100%;align-items:center;padding:0 0 0 var(--grid-margin);background-color:#fff;gap:6px;}.searchbar .input-wrapper:not(.hide){display:flex}.searchbar button[type='reset']{display:flex;align-items:center;border-radius:4px;cursor:pointer}.searchbar input{z-index:1;width:100%;height:100%;padding:8px;border:none;background-color:#fff;font-family:var(--font-family-sans);font-size:inherit}.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;padding:8px 16px;border-right:1px solid #000;border-left:1px solid #000;background:var(--zanit-accent-color);font-family:inherit;font-size:inherit;gap:64px;line-height:1}.searchbar input:focus:focus-visible,.searchbar .searchbar-button:focus:focus-visible{z-index:1}}@media (width >= 768px) and (width < 1152px){.searchbar .searchbar-button>.searchbar-button-label{display:none}}";
590
+
591
+ const ZanitSearchForm = class {
592
+ constructor(hostRef) {
593
+ index.registerInstance(this, hostRef);
594
+ this.search = index.createEvent(this, "search");
595
+ this.resetSearch = index.createEvent(this, "resetSearch");
596
+ }
597
+ formElement;
598
+ get host() { return index.getElement(this); }
599
+ isMobile = false;
600
+ /** Indicates whether the searchbar is visible and usable. */
601
+ showSearchbar = false;
602
+ /** Search query to apply. */
603
+ _searchQuery = undefined;
604
+ /** Initial search query */
605
+ searchQuery = undefined;
606
+ onSearchQueryChange() {
607
+ this._searchQuery = this.searchQuery;
608
+ if (this.searchQuery) {
609
+ this.openSearchbar();
610
+ }
611
+ }
612
+ /** Emitted on search form submission. */
613
+ search;
614
+ resetSearch;
615
+ async connectedCallback() {
616
+ this.showSearchbar = !!this.searchQuery;
617
+ const mobileMediaQuery = window.matchMedia('(width < 768px)');
618
+ this.isMobile = mobileMediaQuery.matches;
619
+ mobileMediaQuery.onchange = (mql) => {
620
+ this.isMobile = mql.matches;
621
+ };
622
+ }
623
+ /** Close open searchbar when clicking outside. */
624
+ handleOutsideClick(event) {
625
+ if (this.showSearchbar && this.formElement && !containsTarget(this.formElement, event)) {
626
+ this.showSearchbar = false;
627
+ }
628
+ }
629
+ openSearchbar() {
630
+ this.showSearchbar = true;
631
+ setTimeout(() => {
632
+ const searchbarInput = this.host.shadowRoot.querySelector('#searchbar-input');
633
+ searchbarInput.focus();
634
+ }, 100);
635
+ }
636
+ resetSearchQuery() {
637
+ this.searchQuery = undefined;
638
+ this.resetSearch.emit();
639
+ }
640
+ handleInputChange(event) {
641
+ this._searchQuery = event.target.value;
642
+ if (!this._searchQuery) {
643
+ this.searchQuery = undefined;
644
+ }
645
+ }
646
+ onSearchSubmit(event) {
647
+ event.preventDefault();
648
+ if (!this._searchQuery) {
649
+ return;
650
+ }
651
+ this.showSearchbar = false;
652
+ const searchEv = this.search.emit({ query: this._searchQuery });
653
+ // do not submit the form if the event default behavior was prevented
654
+ if (searchEv.defaultPrevented) {
655
+ return;
656
+ }
657
+ this.formElement.submit();
658
+ }
659
+ render() {
660
+ if (this.isMobile) {
661
+ return (index.h("form", { class: "searchbar", ref: (el) => (this.formElement = el), role: "search", "aria-label": "Cerca", method: "get", action: "/ricerca", onSubmit: (event) => this.onSearchSubmit(event), onReset: () => this.resetSearchQuery() }, this.searchQuery && (index.h("button", { type: "reset", "aria-label": "Svuota campo di ricerca" }, index.h("z-icon", { name: "multiply-circled", width: "1rem", height: "1rem" }))), index.h("input", { id: "searchbar-input", name: "q", type: "search", placeholder: "Cerca per parola chiave o ISBN", onInput: (event) => this.handleInputChange(event), value: this.searchQuery, required: true }), index.h("button", { class: "searchbar-button", "aria-controls": "searchbar-input", "aria-label": "Cerca", type: "submit" }, index.h("z-icon", { name: "search", width: "1.25rem", height: "1.25rem" }))));
662
+ }
663
+ return (index.h("form", { class: { 'searchbar': true, 'searchbar-open': this.showSearchbar }, ref: (el) => (this.formElement = el), role: "search", "aria-label": "Cerca", method: "get", action: "/ricerca", onSubmit: (event) => this.onSearchSubmit(event), onReset: () => this.resetSearchQuery() }, index.h("div", { class: { 'hide': !this.showSearchbar, 'input-wrapper': true }, role: "none" }, this.searchQuery && (index.h("button", { type: "reset", "aria-label": "Svuota campo di ricerca" }, index.h("z-icon", { name: "multiply-circled", width: "1.5rem", height: "1.5rem" }))), index.h("input", { id: "searchbar-input", name: "q", type: "search", placeholder: "Cerca per parola chiave o ISBN", onInput: (event) => this.handleInputChange(event), value: this.searchQuery, required: true })), index.h("button", { class: "searchbar-button", "aria-label": "Cerca", "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", { name: "search", width: "2rem", height: "2rem" }))));
664
+ }
665
+ static get watchers() { return {
666
+ "searchQuery": ["onSearchQueryChange"]
667
+ }; }
668
+ };
669
+ ZanitSearchForm.style = searchFormCss;
670
+
671
+ exports.zanit_menubar = ZanitMenubar;
672
+ exports.zanit_mobile_menubar = ZanitMobileMenubar;
673
+ exports.zanit_search_form = ZanitSearchForm;
674
+ //# sourceMappingURL=zanit-menubar.zanit-mobile-menubar.zanit-search-form.entry.cjs.js.map
675
+
676
+ //# sourceMappingURL=zanit-menubar_3.cjs.entry.js.map