monobill-mintui 0.6.713 → 0.6.714
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/components/search/Search.d.ts +1 -18
- package/dist/components/search/Search.d.ts.map +1 -1
- package/dist/components/search/browser.js +13 -59
- package/dist/components/search/index.cjs +1 -1
- package/dist/components/search/index.js +13 -59
- package/dist/index.cjs +1 -1
- package/dist/index.css +1 -1
- package/dist/index.js +13 -59
- package/dist/search.css +1 -1
- package/package.json +1 -1
|
@@ -25,8 +25,6 @@ declare class MintSearch extends HTMLElement {
|
|
|
25
25
|
private _filtersMoreOpen;
|
|
26
26
|
private _filterOverflowObserver;
|
|
27
27
|
private _filterOverflowZeroWidthRetries;
|
|
28
|
-
private _desktopFilterWrap;
|
|
29
|
-
private _mobileFilterWrap;
|
|
30
28
|
private _resultsWrap;
|
|
31
29
|
private _stateWrap;
|
|
32
30
|
private _customResultsWrap;
|
|
@@ -34,7 +32,6 @@ declare class MintSearch extends HTMLElement {
|
|
|
34
32
|
private _searchOpen;
|
|
35
33
|
/** Active filters in click order; backspace removes the most recently added last. */
|
|
36
34
|
private _selectedFilters;
|
|
37
|
-
private _selectedFilterBackspaceArmed;
|
|
38
35
|
private _debounceId;
|
|
39
36
|
private _abortController;
|
|
40
37
|
private _docPointerDownHandler;
|
|
@@ -64,15 +61,6 @@ declare class MintSearch extends HTMLElement {
|
|
|
64
61
|
private _getFilterChipOverflowReservePx;
|
|
65
62
|
/** Comma-separated for URL params and legacy `filter` event field. */
|
|
66
63
|
private _getFilterParamValue;
|
|
67
|
-
/** Comma + space for the prepend chip label. */
|
|
68
|
-
private _getFilterChipLabelText;
|
|
69
|
-
/**
|
|
70
|
-
* Keep the prepend chip to a single readable line:
|
|
71
|
-
* - 1 filter: "Beauty"
|
|
72
|
-
* - many filters: "Beauty, and 2 more"
|
|
73
|
-
* - if still too long: truncate with "..."
|
|
74
|
-
*/
|
|
75
|
-
private _getCondensedFilterChipLabel;
|
|
76
64
|
private _isMobileViewport;
|
|
77
65
|
/**
|
|
78
66
|
* When true (attribute present), viewports under 1100px hide the inline field and use the
|
|
@@ -120,9 +108,7 @@ declare class MintSearch extends HTMLElement {
|
|
|
120
108
|
private _getNativeInputValue;
|
|
121
109
|
private _getCurrentInputValue;
|
|
122
110
|
private _applyFilterSelectionChange;
|
|
123
|
-
/**
|
|
124
|
-
private _clearAllSelectedFilters;
|
|
125
|
-
/** Second backspace when armed: remove the last-added filter only (LIFO). */
|
|
111
|
+
/** Remove the most recently selected filter (LIFO). */
|
|
126
112
|
private _popLastSelectedFilter;
|
|
127
113
|
private _focusActiveInput;
|
|
128
114
|
/** Focus the native control inside `mint-button` (Show all / Hide filters). */
|
|
@@ -143,9 +129,6 @@ declare class MintSearch extends HTMLElement {
|
|
|
143
129
|
private _getSearchFocusableElements;
|
|
144
130
|
private _focusFirstChipOrResult;
|
|
145
131
|
private _moveFocusInResults;
|
|
146
|
-
private _renderSelectedFilter;
|
|
147
|
-
/** Keep typed text after the selected-filter chip instead of letting the two overlap. */
|
|
148
|
-
private _syncSelectedFilterInputOffset;
|
|
149
132
|
private _bindInputHandlers;
|
|
150
133
|
openSearch(focusInput?: boolean): void;
|
|
151
134
|
closeSearch(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Search.d.ts","sourceRoot":"","sources":["../../../src/components/search/Search.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,CAAA;AACtB,OAAO,sBAAsB,CAAA;AAC7B,OAAO,qBAAqB,CAAA;AAC5B,OAAO,eAAe,CAAA;AACtB,OAAO,gBAAgB,CAAA;AACvB,OAAO,iBAAiB,CAAA;AAaxB,cAAM,UAAW,SAAQ,WAAW;IAClC,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAI;IACtC,+GAA+G;IAC/G,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,wBAAwB,CAC2C;IAE3F,MAAM,KAAK,kBAAkB,IAAI,MAAM,EAAE,CAYxC;IAED,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,aAAa,CAAgC;IACrD,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,WAAW,CAAgC;IACnD,OAAO,CAAC,iBAAiB,CAA2B;IACpD,OAAO,CAAC,oBAAoB,CAA2B;IACvD,OAAO,CAAC,kBAAkB,CAA2B;IACrD,4EAA4E;IAC5E,OAAO,CAAC,wBAAwB,CAA2B;IAC3D,OAAO,CAAC,uBAAuB,CAA2B;IAC1D,OAAO,CAAC,sBAAsB,CAA2B;IACzD,OAAO,CAAC,gBAAgB,CAAQ;IAChC,OAAO,CAAC,uBAAuB,CAA8B;IAC7D,OAAO,CAAC,+BAA+B,CAAI;IAC3C,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"Search.d.ts","sourceRoot":"","sources":["../../../src/components/search/Search.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,CAAA;AACtB,OAAO,sBAAsB,CAAA;AAC7B,OAAO,qBAAqB,CAAA;AAC5B,OAAO,eAAe,CAAA;AACtB,OAAO,gBAAgB,CAAA;AACvB,OAAO,iBAAiB,CAAA;AAaxB,cAAM,UAAW,SAAQ,WAAW;IAClC,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAI;IACtC,+GAA+G;IAC/G,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,wBAAwB,CAC2C;IAE3F,MAAM,KAAK,kBAAkB,IAAI,MAAM,EAAE,CAYxC;IAED,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,aAAa,CAAgC;IACrD,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,WAAW,CAAgC;IACnD,OAAO,CAAC,iBAAiB,CAA2B;IACpD,OAAO,CAAC,oBAAoB,CAA2B;IACvD,OAAO,CAAC,kBAAkB,CAA2B;IACrD,4EAA4E;IAC5E,OAAO,CAAC,wBAAwB,CAA2B;IAC3D,OAAO,CAAC,uBAAuB,CAA2B;IAC1D,OAAO,CAAC,sBAAsB,CAA2B;IACzD,OAAO,CAAC,gBAAgB,CAAQ;IAChC,OAAO,CAAC,uBAAuB,CAA8B;IAC7D,OAAO,CAAC,+BAA+B,CAAI;IAC3C,OAAO,CAAC,YAAY,CAA2B;IAC/C,OAAO,CAAC,UAAU,CAA2B;IAC7C,OAAO,CAAC,kBAAkB,CAA2B;IACrD,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,WAAW,CAAQ;IAC3B,qFAAqF;IACrF,OAAO,CAAC,gBAAgB,CAAe;IACvC,OAAO,CAAC,WAAW,CAAsB;IACzC,OAAO,CAAC,gBAAgB,CAA+B;IACvD,OAAO,CAAC,sBAAsB,CAA2C;IACzE,OAAO,CAAC,qBAAqB,CAA4C;IACzE,OAAO,CAAC,gBAAgB,CAAyC;IACjE,OAAO,CAAC,cAAc,CAA4B;IAClD,OAAO,CAAC,cAAc,CAA4B;IAClD,OAAO,CAAC,oBAAoB,CAA+B;IAC3D,OAAO,CAAC,eAAe,CAA2B;IAClD,OAAO,CAAC,gBAAgB,CAAgC;IACxD,OAAO,CAAC,YAAY,CAAsB;IAE1C,iBAAiB,IAAI,IAAI;IASzB,oBAAoB,IAAI,IAAI;IAsC5B,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAI9F,OAAO,CAAC,eAAe;IAQvB,OAAO,CAAC,wBAAwB;IAchC,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,iBAAiB;IAQzB,OAAO,CAAC,mBAAmB;IAI3B;;;OAGG;IACH,OAAO,CAAC,+BAA+B;IAOvC,sEAAsE;IACtE,OAAO,CAAC,oBAAoB;IAI5B,OAAO,CAAC,iBAAiB;IAIzB;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;IAQzB,sFAAsF;IACtF,OAAO,CAAC,mBAAmB;IAK3B,OAAO,CAAC,gBAAgB;IAKxB;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IA8C1B,OAAO,CAAC,2BAA2B;IAMnC,OAAO,CAAC,oBAAoB;IAmB5B,6EAA6E;IAC7E,OAAO,CAAC,wBAAwB;IAgChC,OAAO,CAAC,qBAAqB;IAiE7B,OAAO,CAAC,oBAAoB;IAgB5B,OAAO,CAAC,sBAAsB;IAgB9B,OAAO,CAAC,qBAAqB;IAY7B,OAAO,CAAC,WAAW;IAWnB,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,oBAAoB;IAoB5B;;;;OAIG;IACH,OAAO,CAAC,qBAAqB;IAQ7B,OAAO,CAAC,cAAc;IAuCtB,OAAO,CAAC,SAAS;IAQjB,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,YAAY;IAOpB,OAAO,CAAC,iBAAiB;IA8BzB,OAAO,CAAC,kBAAkB;IAiB1B,OAAO,CAAC,iBAAiB;IAezB,OAAO,CAAC,YAAY;IAepB,OAAO,CAAC,cAAc;IAoEtB,OAAO,CAAC,mBAAmB;IAyC3B,OAAO,CAAC,eAAe;IAMvB,OAAO,CAAC,oBAAoB;IAO5B,OAAO,CAAC,qBAAqB;IAc7B,OAAO,CAAC,2BAA2B;IAenC,uDAAuD;IACvD,OAAO,CAAC,sBAAsB;IAM9B,OAAO,CAAC,iBAAiB;IAQzB,+EAA+E;IAC/E,OAAO,CAAC,wBAAwB;IAOhC,OAAO,CAAC,sBAAsB;IAK9B,OAAO,CAAC,wBAAwB;IAiDhC;;;;OAIG;IACH,OAAO,CAAC,4BAA4B;IA2BpC,OAAO,CAAC,2BAA2B;IAMnC,OAAO,CAAC,uBAAuB;IAY/B,OAAO,CAAC,mBAAmB;IAyB3B,OAAO,CAAC,2BAA2B;IAUnC,+FAA+F;IAC/F,OAAO,CAAC,2BAA2B;IAanC,OAAO,CAAC,uBAAuB;IAY/B,OAAO,CAAC,mBAAmB;IAsB3B,OAAO,CAAC,kBAAkB;IAkC1B,UAAU,CAAC,UAAU,UAAO,GAAG,IAAI;IAInC,WAAW,IAAI,IAAI;IAInB,YAAY,CAAC,UAAU,UAAO,GAAG,IAAI;IAQrC,YAAY,IAAI,OAAO;IAIvB,MAAM,IAAI,IAAI;IAwQd,OAAO,CAAC,qBAAqB;CAU9B;AAMD,eAAe,UAAU,CAAA"}
|
|
@@ -28,7 +28,7 @@ import "../chunks/search-BwjKBnv9.js";
|
|
|
28
28
|
//#region src/components/search/Search.ts
|
|
29
29
|
var t = class e extends HTMLElement {
|
|
30
30
|
constructor(...e) {
|
|
31
|
-
super(...e), this._shell = null, this._desktopInput = null, this._panel = null, this._panelInner = null, this._resultsId = "", this._panelInput = null, this._panelFiltersWrap = null, this._panelFiltersMainRow = null, this._panelFiltersChips = null, this._panelFiltersShowAllWrap = null, this._panelFiltersShowAllBtn = null, this._panelFiltersMorePanel = null, this._filtersMoreOpen = !1, this._filterOverflowObserver = null, this._filterOverflowZeroWidthRetries = 0, this.
|
|
31
|
+
super(...e), this._shell = null, this._desktopInput = null, this._panel = null, this._panelInner = null, this._resultsId = "", this._panelInput = null, this._panelFiltersWrap = null, this._panelFiltersMainRow = null, this._panelFiltersChips = null, this._panelFiltersShowAllWrap = null, this._panelFiltersShowAllBtn = null, this._panelFiltersMorePanel = null, this._filtersMoreOpen = !1, this._filterOverflowObserver = null, this._filterOverflowZeroWidthRetries = 0, this._resultsWrap = null, this._stateWrap = null, this._customResultsWrap = null, this._query = "", this._searchOpen = !1, this._selectedFilters = [], this._debounceId = null, this._abortController = null, this._docPointerDownHandler = null, this._globalKeydownHandler = null, this._focusOutHandler = null, this._resizeHandler = null, this._scrollHandler = null, this._desktopShortcutHint = null, this._panelSearchBar = null, this._contentObserver = null, this._renderFrame = null;
|
|
32
32
|
}
|
|
33
33
|
static {
|
|
34
34
|
this._filterMorePanelSeq = 0;
|
|
@@ -97,16 +97,6 @@ var t = class e extends HTMLElement {
|
|
|
97
97
|
_getFilterParamValue() {
|
|
98
98
|
return this._selectedFilters.join(",");
|
|
99
99
|
}
|
|
100
|
-
_getFilterChipLabelText() {
|
|
101
|
-
return this._selectedFilters.join(", ");
|
|
102
|
-
}
|
|
103
|
-
_getCondensedFilterChipLabel(e = 22) {
|
|
104
|
-
if (!this._hasSelectedFilters()) return "";
|
|
105
|
-
let [t = ""] = this._selectedFilters, n = this._selectedFilters.length - 1, r = Math.max(8, e - 2), i = t;
|
|
106
|
-
if (n <= 0) return i.length <= r ? i : `${i.slice(0, Math.max(1, r - 3))}...`;
|
|
107
|
-
let a = `${t}, and ${n} more`;
|
|
108
|
-
return a.length <= r ? a : `${a.slice(0, Math.max(1, r - 3))}...`;
|
|
109
|
-
}
|
|
110
100
|
_isMobileViewport() {
|
|
111
101
|
return window.matchMedia("(max-width: 1099.98px)").matches;
|
|
112
102
|
}
|
|
@@ -253,12 +243,11 @@ var t = class e extends HTMLElement {
|
|
|
253
243
|
}
|
|
254
244
|
let e = this._shell?.getBoundingClientRect();
|
|
255
245
|
if (!e) return;
|
|
256
|
-
let t = window.innerHeight, n = Math.max(0, Math.min(416, t - 16)), r = Math.max(0, t - e.bottom - 4), i = Math.max(0, e.top - 4), a = r < n && i > r, o = Math.min(n, a ? i : r);
|
|
257
|
-
this._panel.classList.toggle("is-open-above", a), this._panelInner && (this._panelInner.style.maxHeight = `${o}px`), this._panel.style.left = `${e.left}px`, this._panel.style.width = `${e.width}px`, this._panel.style.right = "auto", a ? (this._panel.style.top = "auto", this._panel.style.bottom = `${Math.max(0, t - e.top
|
|
246
|
+
let t = window.innerHeight, n = Math.max(0, Math.min(416, t - 16)), r = Math.max(0, t - e.bottom - 8 - 4), i = Math.max(0, e.top - 8 - 4), a = r < n && i > r, o = Math.min(n, a ? i : r);
|
|
247
|
+
this._panel.classList.toggle("is-open-above", a), this._panelInner && (this._panelInner.style.maxHeight = `${o}px`), this._panel.style.left = `${e.left}px`, this._panel.style.width = `${e.width}px`, this._panel.style.right = "auto", a ? (this._panel.style.top = "auto", this._panel.style.bottom = `${Math.max(0, t - e.top + 4)}px`) : (this._panel.style.top = `${e.bottom + 4}px`, this._panel.style.bottom = "auto");
|
|
258
248
|
}
|
|
259
249
|
_setQuery(e) {
|
|
260
|
-
|
|
261
|
-
this._query = e, e !== t && (this._selectedFilterBackspaceArmed = !1), this._desktopInput && (this._desktopInput.value = e), this._panelInput && (this._panelInput.value = e);
|
|
250
|
+
this._query = e, this._desktopInput && (this._desktopInput.value = e), this._panelInput && (this._panelInput.value = e);
|
|
262
251
|
}
|
|
263
252
|
_cancelDebounce() {
|
|
264
253
|
this._debounceId !== null && (window.clearTimeout(this._debounceId), this._debounceId = null);
|
|
@@ -416,11 +405,8 @@ var t = class e extends HTMLElement {
|
|
|
416
405
|
}
|
|
417
406
|
this._cancelDebounce(), this._abortSearch(), this._emitResultsChange([]), this._renderState("Start typing to search");
|
|
418
407
|
}
|
|
419
|
-
_clearAllSelectedFilters() {
|
|
420
|
-
this._selectedFilters = [], this._selectedFilterBackspaceArmed = !1, this._applyFilterSelectionChange();
|
|
421
|
-
}
|
|
422
408
|
_popLastSelectedFilter() {
|
|
423
|
-
this._selectedFilters.length !== 0 && (this._selectedFilters.pop(), this.
|
|
409
|
+
this._selectedFilters.length !== 0 && (this._selectedFilters.pop(), this._applyFilterSelectionChange());
|
|
424
410
|
}
|
|
425
411
|
_focusActiveInput() {
|
|
426
412
|
let e = this._primarySearchInput();
|
|
@@ -516,32 +502,6 @@ var t = class e extends HTMLElement {
|
|
|
516
502
|
t ? t.focus() : this._focusActiveInput();
|
|
517
503
|
}
|
|
518
504
|
}
|
|
519
|
-
_renderSelectedFilter() {
|
|
520
|
-
let e = (e) => {
|
|
521
|
-
if (!e || (e.innerHTML = "", !this._hasSelectedFilters())) return;
|
|
522
|
-
let t = document.createElement("mint-chip");
|
|
523
|
-
t.setAttribute("dismissable", ""), t.title = this._getFilterChipLabelText();
|
|
524
|
-
let n = this._getCondensedFilterChipLabel();
|
|
525
|
-
t.classList.add("mint-search-selected-filter"), this._selectedFilterBackspaceArmed && t.classList.add("is-backspace-armed"), t.textContent = n, t.addEventListener("dismiss", (e) => {
|
|
526
|
-
e.stopPropagation(), this._clearAllSelectedFilters();
|
|
527
|
-
}), e.appendChild(t);
|
|
528
|
-
};
|
|
529
|
-
e(this._desktopFilterWrap), e(this._mobileFilterWrap);
|
|
530
|
-
let t = this._hasSelectedFilters();
|
|
531
|
-
this._desktopInput?.classList.toggle("has-selected-filter", t), this._panelInput?.classList.toggle("has-selected-filter", t), this._syncSelectedFilterInputOffset(this._desktopInput, this._desktopFilterWrap), this._syncSelectedFilterInputOffset(this._panelInput, this._mobileFilterWrap);
|
|
532
|
-
}
|
|
533
|
-
_syncSelectedFilterInputOffset(e, t) {
|
|
534
|
-
if (!e || !t) return;
|
|
535
|
-
let n = t.querySelector("mint-chip");
|
|
536
|
-
if (!n) {
|
|
537
|
-
e.style.removeProperty("--mint-search-filter-chip-width");
|
|
538
|
-
return;
|
|
539
|
-
}
|
|
540
|
-
let r = () => {
|
|
541
|
-
n.isConnected && e.style.setProperty("--mint-search-filter-chip-width", `${n.getBoundingClientRect().width}px`);
|
|
542
|
-
};
|
|
543
|
-
r(), requestAnimationFrame(r);
|
|
544
|
-
}
|
|
545
505
|
_bindInputHandlers(e) {
|
|
546
506
|
let t = () => {
|
|
547
507
|
this._scheduleSearch(this._getNativeInputValue(e));
|
|
@@ -557,13 +517,7 @@ var t = class e extends HTMLElement {
|
|
|
557
517
|
}
|
|
558
518
|
if (t.key !== "Backspace") return;
|
|
559
519
|
let n = this._getNativeInputValue(e);
|
|
560
|
-
|
|
561
|
-
if (!this._selectedFilterBackspaceArmed) {
|
|
562
|
-
t.preventDefault(), this._selectedFilterBackspaceArmed = !0, this._renderSelectedFilter();
|
|
563
|
-
return;
|
|
564
|
-
}
|
|
565
|
-
t.preventDefault(), this._popLastSelectedFilter();
|
|
566
|
-
}
|
|
520
|
+
n !== this._query && this._setQuery(n), !(n.length > 0) && this._hasSelectedFilters() && (t.preventDefault(), this._popLastSelectedFilter());
|
|
567
521
|
});
|
|
568
522
|
}
|
|
569
523
|
openSearch(e = !0) {
|
|
@@ -589,19 +543,19 @@ var t = class e extends HTMLElement {
|
|
|
589
543
|
return;
|
|
590
544
|
}
|
|
591
545
|
if (!this._shell) {
|
|
592
|
-
this._shell = document.createElement("div"), this._shell.className = "mint-search-shell", this.
|
|
546
|
+
this._shell = document.createElement("div"), this._shell.className = "mint-search-shell", this._desktopInput = document.createElement("mint-input"), this._desktopInput.setAttribute("type", "search"), this._desktopInput.setAttribute("icon", "search"), this._desktopInput.setAttribute("aria-label", this.getAttribute("placeholder") || "Search"), this._desktopInput.className = "mint-search-input";
|
|
593
547
|
let e = document.createElement("span");
|
|
594
|
-
e.className = "mint-search-shortcut-hint", e.setAttribute("
|
|
548
|
+
e.className = "mint-search-shortcut-hint", e.setAttribute("aria-hidden", "true"), this._desktopShortcutHint = e, this._bindInputHandlers(this._desktopInput), this._shell.appendChild(this._desktopInput), this._shell.appendChild(e), this.appendChild(this._shell);
|
|
595
549
|
}
|
|
596
550
|
if (!this._panel) {
|
|
597
551
|
this._panel = document.createElement("div"), this._panel.className = "mint-search-panel is-hidden";
|
|
598
552
|
let e = document.createElement("div");
|
|
599
553
|
e.className = "mint-search-panel-inner", this._panelInner = e;
|
|
600
554
|
let t = document.createElement("div");
|
|
601
|
-
this._panelSearchBar = t, t.className = "mint-search-panel-searchbar is-hidden", this.
|
|
555
|
+
this._panelSearchBar = t, t.className = "mint-search-panel-searchbar is-hidden", this._panelInput = document.createElement("mint-input"), this._panelInput.setAttribute("type", "search"), this._panelInput.setAttribute("icon", "search"), this._panelInput.setAttribute("aria-label", this.getAttribute("placeholder") || "Search"), this._panelInput.className = "mint-search-input", this._bindInputHandlers(this._panelInput), t.appendChild(this._panelInput), this._customResultsWrap = document.createElement("div"), this._customResultsWrap.className = "mint-search-custom-results is-hidden", this._stateWrap = document.createElement("div"), this._stateWrap.className = "mint-search-state", this._stateWrap.textContent = "Start typing to search", this._stateWrap.setAttribute("role", "status"), this._stateWrap.setAttribute("aria-live", "polite"), this._resultsWrap = document.createElement("div"), this._resultsWrap.className = "mint-search-results", this._resultsId = `mint-search-results-${Math.random().toString(36).slice(2, 10)}`, this._resultsWrap.id = this._resultsId, this._resultsWrap.setAttribute("role", "listbox"), this._resultsWrap.setAttribute("aria-label", "Search results"), this._customResultsWrap.setAttribute("role", "region"), this._customResultsWrap.setAttribute("aria-label", "Search results"), e.appendChild(t), this._panelFiltersWrap = document.createElement("div"), e.appendChild(this._panelFiltersWrap), this._ensurePanelFiltersShell(), e.appendChild(this._customResultsWrap), e.appendChild(this._stateWrap), e.appendChild(this._resultsWrap), this._panel.appendChild(e);
|
|
602
556
|
}
|
|
603
557
|
this._panel.parentElement !== document.body && document.body.appendChild(this._panel);
|
|
604
|
-
let t = this.
|
|
558
|
+
let t = this._getPlaceholder();
|
|
605
559
|
if (this._desktopInput && this._desktopInput.setAttribute("placeholder", t), this._panelInput && this._panelInput.setAttribute("placeholder", t), this._desktopInput && this._desktopInput.setAttribute("aria-label", this.getAttribute("aria-label") || this._getPlaceholder()), this._panelInput && this._panelInput.setAttribute("aria-label", this.getAttribute("aria-label") || this._getPlaceholder()), this._desktopShortcutHint) {
|
|
606
560
|
let e = this._getOpenShortcutHintText();
|
|
607
561
|
this._desktopShortcutHint.textContent = e, this._desktopShortcutHint.classList.toggle("is-hidden", !e);
|
|
@@ -628,9 +582,9 @@ var t = class e extends HTMLElement {
|
|
|
628
582
|
let a = (n) => {
|
|
629
583
|
n && n.stopPropagation();
|
|
630
584
|
let r = this._filtersMoreOpen, i = this._selectedFilters.indexOf(t);
|
|
631
|
-
i >= 0 ? this._selectedFilters.splice(i, 1) : this._selectedFilters.push(t)
|
|
585
|
+
i >= 0 ? this._selectedFilters.splice(i, 1) : this._selectedFilters.push(t);
|
|
632
586
|
let a = e.length > 0 && this._selectedFilters.length === e.length, o = this._selectedFilters.length === 0;
|
|
633
|
-
r && (a || o) && (this._filtersMoreOpen = !1), this._emitFilterChange(), this.
|
|
587
|
+
r && (a || o) && (this._filtersMoreOpen = !1), this._emitFilterChange(), this.render(), this._query.trim() && this._scheduleSearch(this._query), r ? a || o ? this._focusActiveInput() : requestAnimationFrame(() => {
|
|
634
588
|
this._getFilterChipElements().find((e) => e.dataset.mintSearchFilter === t)?.focus();
|
|
635
589
|
}) : this._focusActiveInput();
|
|
636
590
|
};
|
|
@@ -669,7 +623,7 @@ var t = class e extends HTMLElement {
|
|
|
669
623
|
let e = this._customResultsWrap.childElementCount > 0;
|
|
670
624
|
this._customResultsWrap.classList.toggle("is-hidden", !e), e ? (this._stateWrap?.classList.add("is-hidden"), this._resultsWrap?.classList.add("is-hidden")) : this._resultsWrap?.classList.remove("is-hidden");
|
|
671
625
|
}
|
|
672
|
-
this.
|
|
626
|
+
this._syncResponsiveChrome(), this._syncPanelVisibility();
|
|
673
627
|
}
|
|
674
628
|
_syncResponsiveChrome() {
|
|
675
629
|
let e = this._collapseOnMobile();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../chunks/icon-CWOP4Com.js`);const e=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/icon-D6C1XGp2.js`),require(`../chunks/close-DSrpkGHJ.js`),require(`../chunks/button-B_yN18B-.js`),require(`../chunks/chip-BUaS7ks-.js`),require(`../chunks/input-BI4nrOaG.js`),require(`../chunks/search-q3dkl4-X.js`);var t=class e extends HTMLElement{constructor(...e){super(...e),this._shell=null,this._desktopInput=null,this._panel=null,this._panelInner=null,this._resultsId=``,this._panelInput=null,this._panelFiltersWrap=null,this._panelFiltersMainRow=null,this._panelFiltersChips=null,this._panelFiltersShowAllWrap=null,this._panelFiltersShowAllBtn=null,this._panelFiltersMorePanel=null,this._filtersMoreOpen=!1,this._filterOverflowObserver=null,this._filterOverflowZeroWidthRetries=0,this._desktopFilterWrap=null,this._mobileFilterWrap=null,this._resultsWrap=null,this._stateWrap=null,this._customResultsWrap=null,this._query=``,this._searchOpen=!1,this._selectedFilters=[],this._selectedFilterBackspaceArmed=!1,this._debounceId=null,this._abortController=null,this._docPointerDownHandler=null,this._globalKeydownHandler=null,this._focusOutHandler=null,this._resizeHandler=null,this._scrollHandler=null,this._desktopShortcutHint=null,this._panelSearchBar=null,this._contentObserver=null,this._renderFrame=null}static{this._filterMorePanelSeq=0}static{this._filterChipsOverflowMask=`linear-gradient(to right, #000 0%, #000 max(0%, calc(100% - 3.5rem)), transparent 100%)`}static get observedAttributes(){return[`endpoint`,`search-param`,`placeholder`,`filters`,`filter-param`,`open-shortcut`,`open-shortcut-hint`,`collapse-on-mobile`,`results-limit`]}connectedCallback(){this.classList.add(`mint-search-host`),this._attachGlobalHandlers(),this._attachFocusOutHandler(),this._attachResizeHandler(),this.render(),this._observeContentMutations()}disconnectedCallback(){this._panel?.remove(),this._docPointerDownHandler&&=(document.removeEventListener(`pointerdown`,this._docPointerDownHandler,!0),null),this._globalKeydownHandler&&=(document.removeEventListener(`keydown`,this._globalKeydownHandler),null),this._resizeHandler&&=(window.removeEventListener(`resize`,this._resizeHandler),null),this._scrollHandler&&=(document.removeEventListener(`scroll`,this._scrollHandler,!0),null),this._focusOutHandler&&=(this.removeEventListener(`focusout`,this._focusOutHandler,!0),null),this._cancelDebounce(),this._abortSearch(),this._filterOverflowObserver&&=(this._filterOverflowObserver.disconnect(),null),this._contentObserver&&=(this._contentObserver.disconnect(),null),this._renderFrame!==null&&(cancelAnimationFrame(this._renderFrame),this._renderFrame=null)}attributeChangedCallback(e,t,n){t!==n&&this.render()}_scheduleRender(){this._renderFrame===null&&(this._renderFrame=requestAnimationFrame(()=>{this._renderFrame=null,this.render()}))}_observeContentMutations(){this._contentObserver||=new MutationObserver(()=>{this._scheduleRender()}),this._contentObserver.disconnect(),this._contentObserver.observe(this,{childList:!0,attributes:!0,attributeFilter:[`slot`]})}_getEndpoint(){return(this.getAttribute(`endpoint`)||``).trim()}_getSearchParam(){return(this.getAttribute(`search-param`)||`q`).trim()||`q`}_getPlaceholder(){return this.getAttribute(`placeholder`)||`Search`}_getFilterParam(){return(this.getAttribute(`filter-param`)||``).trim()}_getFilterOptions(){return(this.getAttribute(`filters`)||``).split(`,`).map(e=>e.trim()).filter(Boolean)}_hasSelectedFilters(){return this._selectedFilters.length>0}_getFilterChipOverflowReservePx(){let e=Math.max(1,this._getFilterOptions().length),t=this._hasSelectedFilters()?28:56;return Math.min(200,t+e*34)}_getFilterParamValue(){return this._selectedFilters.join(`,`)}_getFilterChipLabelText(){return this._selectedFilters.join(`, `)}_getCondensedFilterChipLabel(e=22){if(!this._hasSelectedFilters())return``;let[t=``]=this._selectedFilters,n=this._selectedFilters.length-1,r=Math.max(8,e-2),i=t;if(n<=0)return i.length<=r?i:`${i.slice(0,Math.max(1,r-3))}...`;let a=`${t}, and ${n} more`;return a.length<=r?a:`${a.slice(0,Math.max(1,r-3))}...`}_isMobileViewport(){return window.matchMedia(`(max-width: 1099.98px)`).matches}_collapseOnMobile(){let e=this.getAttribute(`collapse-on-mobile`);if(e===null)return!1;let t=e.trim().toLowerCase();return!(t===`false`||t===`0`||t===`off`||t===`none`)}_primarySearchInput(){return this._isMobileViewport()&&this._collapseOnMobile()?this._panelInput:this._desktopInput}_isApplePlatform(){return typeof navigator>`u`?!1:/Mac|iPhone|iPad|iPod/i.test(navigator.platform)||/Mac OS/i.test(navigator.userAgent)}_parseOpenShortcut(){let e=(this.getAttribute(`open-shortcut`)??`mod+k`).trim().toLowerCase();if(!e||e===`none`||e===`false`||e===`off`)return{disabled:!0,wantMod:!1,wantMeta:!1,wantCtrl:!1,wantAlt:!1,wantShift:!1,key:``};let t=e.split(`+`).map(e=>e.trim()).filter(Boolean);if(t.length===0)return{disabled:!0,wantMod:!1,wantMeta:!1,wantCtrl:!1,wantAlt:!1,wantShift:!1,key:``};let n=t[t.length-1],r=new Set(t.slice(0,-1).map(e=>e.toLowerCase()));return{disabled:!1,wantMod:r.has(`mod`),wantMeta:r.has(`meta`)||r.has(`cmd`)||r.has(`super`),wantCtrl:r.has(`ctrl`)||r.has(`control`),wantAlt:r.has(`alt`),wantShift:r.has(`shift`),key:n.toLowerCase()}}_eventKeyMatchesShortcutKey(e,t){let n=t.toLowerCase();return(e.key.length,e.key.toLowerCase())===n}_openShortcutMatches(e){let t=this._parseOpenShortcut();return t.disabled||!t.key||e.repeat||!this._eventKeyMatchesShortcutKey(e,t.key)||t.wantShift!==e.shiftKey||t.wantAlt!==e.altKey?!1:t.wantMod||t.wantMeta||t.wantCtrl?!(t.wantMod&&!(e.metaKey||e.ctrlKey)||t.wantMeta&&!e.metaKey||t.wantCtrl&&!e.ctrlKey):!!t.wantAlt}_getOpenShortcutHintText(){let e=this.getAttribute(`open-shortcut-hint`);if(e===`none`||e===`false`)return``;if(e!==null&&e.trim()!==``)return e.trim();let t=this._parseOpenShortcut();if(t.disabled)return``;let n=this._isApplePlatform(),r=[];t.wantMod&&r.push(n?`⌘`:`Ctrl`),t.wantMeta&&!t.wantMod&&r.push(n?`⌘`:`Meta`),t.wantCtrl&&!t.wantMod&&r.push(`Ctrl`),t.wantAlt&&r.push(`Alt`),t.wantShift&&r.push(`Shift`);let i=t.key.length===1?t.key.toUpperCase():t.key;return i?t.wantMod&&!t.wantMeta&&!t.wantCtrl&&!t.wantAlt&&!t.wantShift&&t.key.length===1?`${n?`⌘`:`Ctrl+`}${i}`:[...r,i].join(`+`):``}_attachGlobalHandlers(){this._globalKeydownHandler||(this._globalKeydownHandler=e=>{if(this._openShortcutMatches(e)){e.preventDefault(),this._openSearch(!0);return}if(e.key===`Tab`&&this._searchOpen){let t=e.composedPath();if(this._shell&&t.includes(this._shell)||this._panelInner&&t.includes(this._panelInner)){let t=this._getSearchFocusableElements();if(t.length){let n=document.activeElement,r=n?t.indexOf(n):-1,i=e.shiftKey?-1:1,a=r<0?e.shiftKey?t.length-1:0:(r+i+t.length)%t.length;e.preventDefault(),t[a]?.focus()}}return}if(e.key.toLowerCase()===`escape`&&this._searchOpen){if(this._filtersMoreOpen){this._filtersMoreOpen=!1,this.render(),requestAnimationFrame(()=>this._focusActiveInput());return}this._closeSearch()}},document.addEventListener(`keydown`,this._globalKeydownHandler)),this._docPointerDownHandler||(this._docPointerDownHandler=e=>{if(!this._searchOpen)return;let t=e.composedPath();this._filtersMoreOpen&&this._panelFiltersWrap&&!t.includes(this._panelFiltersWrap)&&(this._filtersMoreOpen=!1,this.render(),requestAnimationFrame(()=>this._focusActiveInput())),!(this._shell&&t.includes(this._shell)||this._panelInner&&t.includes(this._panelInner))&&this._closeSearch()},document.addEventListener(`pointerdown`,this._docPointerDownHandler,!0))}_attachResizeHandler(){this._resizeHandler||(this._resizeHandler=()=>{this._syncPanelVisibility(),this._syncFilterOverflow()},window.addEventListener(`resize`,this._resizeHandler,{passive:!0})),this._scrollHandler||(this._scrollHandler=()=>{this._searchOpen&&this._positionPanel()},document.addEventListener(`scroll`,this._scrollHandler,!0))}_attachFocusOutHandler(){this._focusOutHandler||(this._focusOutHandler=e=>{if(!this._searchOpen)return;let t=e.relatedTarget;t&&(this._shell&&this._shell.contains(t)||this._panelInner&&this._panelInner.contains(t)||this._closeSearch())},this.addEventListener(`focusout`,this._focusOutHandler,!0))}_emitSearchOpenChange(){this.dispatchEvent(new CustomEvent(`search-open-change`,{detail:{open:this._searchOpen},bubbles:!0,composed:!0}))}_openSearch(e=!1){this._getEndpoint()&&(this._searchOpen||(this._searchOpen=!0,this._syncPanelVisibility(),this._emitSearchOpenChange(),e&&this._primarySearchInput()?.focus()))}_closeSearch(){this._searchOpen&&(this._searchOpen=!1,this._filtersMoreOpen=!1,this._syncPanelVisibility(),this._emitSearchOpenChange())}_syncPanelVisibility(){if(this._panel){this._syncPanelLayoutClass(),this._panel.classList.toggle(`is-hidden`,!this._searchOpen),this._panel.classList.toggle(`is-open`,this._searchOpen),this._shell&&this._shell.classList.toggle(`is-open`,this._searchOpen);for(let e of[this._desktopInput,this._panelInput]){let t=e?.querySelector(`input`);t&&(t.setAttribute(`aria-expanded`,String(this._searchOpen)),this._resultsId&&t.setAttribute(`aria-controls`,this._resultsId))}this._positionPanel(),this._searchOpen&&this._scheduleFilterOverflowSync()}}_syncPanelLayoutClass(){if(!this._panel)return;let e=!this._isMobileViewport()||!this._collapseOnMobile();this._panel.classList.toggle(`mint-search-panel-anchored`,e),this._panel.classList.toggle(`mint-search-panel-mobile`,!e),this._panel.classList.toggle(`mint-search-panel-global`,this.classList.contains(`global-search-control`))}_positionPanel(){if(!this._panel)return;if(!(!this._isMobileViewport()||!this._collapseOnMobile())){this._panel.style.left=``,this._panel.style.right=``,this._panel.style.top=``,this._panel.style.bottom=``,this._panel.style.width=``,this._panel.classList.remove(`is-open-above`),this._panelInner&&(this._panelInner.style.maxHeight=``);return}let e=this._shell?.getBoundingClientRect();if(!e)return;let t=window.innerHeight,n=Math.max(0,Math.min(416,t-16)),r=Math.max(0,t-e.bottom-4),i=Math.max(0,e.top-4),a=r<n&&i>r,o=Math.min(n,a?i:r);this._panel.classList.toggle(`is-open-above`,a),this._panelInner&&(this._panelInner.style.maxHeight=`${o}px`),this._panel.style.left=`${e.left}px`,this._panel.style.width=`${e.width}px`,this._panel.style.right=`auto`,a?(this._panel.style.top=`auto`,this._panel.style.bottom=`${Math.max(0,t-e.top-4)}px`):(this._panel.style.top=`${e.bottom-4}px`,this._panel.style.bottom=`auto`)}_setQuery(e){let t=this._query;this._query=e,e!==t&&(this._selectedFilterBackspaceArmed=!1),this._desktopInput&&(this._desktopInput.value=e),this._panelInput&&(this._panelInput.value=e)}_cancelDebounce(){this._debounceId!==null&&(window.clearTimeout(this._debounceId),this._debounceId=null)}_abortSearch(){this._abortController&&=(this._abortController.abort(),null)}_normalizeResults(e){let t=Number.parseInt(this.getAttribute(`results-limit`)||``,10),n=Number.isFinite(t)&&t>0?Math.min(t,1e3):8;return(e=>{if(Array.isArray(e))return e;if(!e||typeof e!=`object`)return[];let t=e;for(let e of[`results`,`items`,`data`,`products`]){let n=t[e];if(Array.isArray(n))return n}return[]})(e).map(e=>{let t=e||{};return{title:String(t.title||t.name||t.label||t.email||t.id||``).trim()||`Untitled`,subtitle:String(t.description||t.category||t.username||``).trim(),parent:String(t.parent||t.type||t.entity||t.kind||t.category||``).trim()||void 0}}).slice(0,n)}_emitResultsChange(e,t){let n=this._hasSelectedFilters()?this._getFilterParamValue():null;this.dispatchEvent(new CustomEvent(`search-results-change`,{detail:{query:this._query,filter:n,filters:[...this._selectedFilters],results:e,raw:t??null},bubbles:!0,composed:!0}))}_emitFilterChange(){let e=this._hasSelectedFilters()?this._getFilterParamValue():null;this.dispatchEvent(new CustomEvent(`search-filter-change`,{detail:{query:this._query,filter:e,filters:[...this._selectedFilters]},bubbles:!0,composed:!0}))}_renderState(e){if(this._customResultsWrap&&this._customResultsWrap.childElementCount>0){this._stateWrap&&this._stateWrap.classList.add(`is-hidden`),this._resultsWrap&&this._resultsWrap.classList.add(`is-hidden`);return}this._stateWrap&&(this._stateWrap.textContent=e,this._stateWrap.classList.remove(`is-hidden`),this._resultsWrap&&(this._resultsWrap.classList.remove(`is-hidden`),this._resultsWrap.innerHTML=``))}_renderResults(e){if(this._customResultsWrap&&this._customResultsWrap.childElementCount>0){this._stateWrap&&this._stateWrap.classList.add(`is-hidden`),this._resultsWrap&&this._resultsWrap.classList.add(`is-hidden`);return}if(!(!this._resultsWrap||!this._stateWrap)){if(this._resultsWrap.innerHTML=``,e.length===0){this._renderState(`No results found`);return}this._stateWrap.classList.add(`is-hidden`);for(let t of e){let e=document.createElement(`button`);e.type=`button`,e.className=`mint-search-result`,e.setAttribute(`role`,`option`),e.setAttribute(`aria-selected`,`false`);let n=document.createElement(`mint-icon`);n.setAttribute(`name`,`search`),n.className=`mint-search-result-icon`;let r=document.createElement(`div`);r.className=`mint-search-result-copy`;let i=document.createElement(`div`);if(i.className=`mint-search-result-title`,i.textContent=t.title,r.appendChild(i),t.subtitle){let e=document.createElement(`div`);e.className=`mint-search-result-subtitle`,e.textContent=t.subtitle,r.appendChild(e)}e.appendChild(n),e.appendChild(r),e.addEventListener(`keydown`,t=>{if(t.key===`ArrowDown`){t.preventDefault(),this._moveFocusInResults(e,1);return}if(t.key===`ArrowUp`){t.preventDefault(),this._moveFocusInResults(e,-1);return}}),e.addEventListener(`click`,()=>{let e=this._hasSelectedFilters()?this._getFilterParamValue():null;this.dispatchEvent(new CustomEvent(`search-select`,{detail:{query:this._query,filter:e,filters:[...this._selectedFilters],result:t},bubbles:!0,composed:!0})),this._closeSearch()}),this._resultsWrap.appendChild(e)}}}_fetchSearchResults(e){let t=this._getEndpoint();if(!t)return;let n=e.trim();if(!n){this._emitResultsChange([]),this._renderState(`Start typing to search`);return}this._abortSearch(),this._abortController=new AbortController,this._renderState(`Searching...`);let r=new URLSearchParams;r.set(this._getSearchParam(),n);let i=this._getFilterParam();i&&this._hasSelectedFilters()&&r.set(i,this._getFilterParamValue());let a=t.includes(`{query}`)?t.replace(`{query}`,encodeURIComponent(n)):`${t}${t.includes(`?`)?`&`:`?`}${r.toString()}`;fetch(a,{signal:this._abortController.signal}).then(e=>{if(!e.ok)throw Error(`Request failed: ${e.status}`);return e.json()}).then(e=>{let t=this._normalizeResults(e);this._emitResultsChange(t,e),this._renderResults(t)}).catch(e=>{e?.name!==`AbortError`&&(this._emitResultsChange([]),this._renderState(`Unable to load results`))})}_scheduleSearch(e){this._setQuery(e),this._cancelDebounce(),this._debounceId=window.setTimeout(()=>this._fetchSearchResults(e),220)}_getNativeInputValue(e){if(!e)return``;let t=e.querySelector(`input, textarea`);return t?t.value||``:e.value||``}_getCurrentInputValue(){let e=document.activeElement;return e&&this._desktopInput&&this._desktopInput.contains(e)?this._getNativeInputValue(this._desktopInput):e&&this._panelInput&&this._panelInput.contains(e)?this._getNativeInputValue(this._panelInput):this._getNativeInputValue(this._primarySearchInput())}_applyFilterSelectionChange(){let e=this._getCurrentInputValue();if(this._setQuery(e),this._emitFilterChange(),this.render(),e.trim()){this._scheduleSearch(e);return}this._cancelDebounce(),this._abortSearch(),this._emitResultsChange([]),this._renderState(`Start typing to search`)}_clearAllSelectedFilters(){this._selectedFilters=[],this._selectedFilterBackspaceArmed=!1,this._applyFilterSelectionChange()}_popLastSelectedFilter(){this._selectedFilters.length!==0&&(this._selectedFilters.pop(),this._selectedFilterBackspaceArmed=!1,this._applyFilterSelectionChange())}_focusActiveInput(){let e=this._primarySearchInput();e&&requestAnimationFrame(()=>{e.focus()})}_focusHideFiltersControl(){let e=this._panelFiltersShowAllBtn;e&&(e.querySelector(`button`)??e).focus()}_getFilterChipElements(){return this._panelFiltersWrap?Array.from(this._panelFiltersWrap.querySelectorAll(`mint-chip`)):[]}_ensurePanelFiltersShell(){!this._panelFiltersWrap||this._panelFiltersMainRow||(this._panelFiltersWrap.replaceChildren(),this._panelFiltersWrap.className=`mint-search-filters`,this._panelFiltersMainRow=document.createElement(`div`),this._panelFiltersMainRow.className=`mint-search-filter-row`,this._panelFiltersChips=document.createElement(`div`),this._panelFiltersChips.className=`mint-search-filter-chips`,this._panelFiltersMorePanel=document.createElement(`div`),this._panelFiltersMorePanel.id=`mint-search-filter-more-${e._filterMorePanelSeq++}`,this._panelFiltersMorePanel.className=`mint-search-filter-more is-hidden`,this._panelFiltersShowAllWrap=document.createElement(`div`),this._panelFiltersShowAllWrap.className=`mint-search-filter-more-trigger is-hidden`,this._panelFiltersShowAllBtn=document.createElement(`mint-button`),this._panelFiltersShowAllBtn.setAttribute(`type`,`button`),this._panelFiltersShowAllBtn.setAttribute(`variant`,`ghost`),this._panelFiltersShowAllBtn.setAttribute(`tone`,`neutral`),this._panelFiltersShowAllBtn.setAttribute(`size`,`small`),this._panelFiltersShowAllBtn.classList.add(`mint-search-filter-more-button`),this._panelFiltersShowAllBtn.setAttribute(`aria-expanded`,`false`),this._panelFiltersShowAllBtn.setAttribute(`aria-controls`,this._panelFiltersMorePanel.id),this._panelFiltersShowAllBtn.addEventListener(`click`,e=>{e.stopPropagation();let t=this._filtersMoreOpen;this._filtersMoreOpen=!this._filtersMoreOpen,this.render(),t&&requestAnimationFrame(()=>this._focusActiveInput())}),this._panelFiltersShowAllWrap.append(this._panelFiltersShowAllBtn),this._panelFiltersMainRow.append(this._panelFiltersChips,this._panelFiltersShowAllWrap),this._setPanelFiltersShowAllLabel(`Show all`),this._panelFiltersWrap.append(this._panelFiltersMainRow,this._panelFiltersMorePanel),typeof ResizeObserver<`u`&&!this._filterOverflowObserver&&(this._filterOverflowObserver=new ResizeObserver(()=>this._syncFilterOverflow()),this._filterOverflowObserver.observe(this._panelFiltersChips),this._filterOverflowObserver.observe(this._panelFiltersMainRow)))}_setPanelFiltersShowAllLabel(e){let t=this._panelFiltersShowAllBtn;if(!t)return;for(let e of Array.from(t.childNodes))e.nodeType===Node.TEXT_NODE&&e.remove();let n=t.querySelector(`button .mint-button-content`)||t.querySelector(`.mint-button-content`);if(n){n.textContent=e;return}let r=t.querySelector(`:scope > button`);if(r){r.replaceChildren(document.createTextNode(e)),t.render?.();return}t.firstElementChild||t.appendChild(document.createTextNode(e))}_scheduleFilterOverflowSync(){requestAnimationFrame(()=>{requestAnimationFrame(()=>this._syncFilterOverflow())})}_setFilterChipsEdgeFade(t){let n=this._panelFiltersChips;n&&(t?(n.style.maskImage=e._filterChipsOverflowMask,n.style.webkitMaskImage=e._filterChipsOverflowMask):(n.style.maskImage=``,n.style.webkitMaskImage=``))}_syncFilterOverflow(){if(!this._panelFiltersChips||!this._panelFiltersShowAllWrap||!this._panelFiltersShowAllBtn)return;if(this._filtersMoreOpen){this._panelFiltersShowAllWrap.classList.remove(`is-hidden`),this._filterOverflowZeroWidthRetries=0,this._setFilterChipsEdgeFade(!1);return}let e=this._panelFiltersChips.clientWidth;if(e===0&&this._searchOpen){this._filterOverflowZeroWidthRetries<10&&(this._filterOverflowZeroWidthRetries+=1,this._scheduleFilterOverflowSync()),this._setFilterChipsEdgeFade(!1);return}this._filterOverflowZeroWidthRetries=0;let t=this._panelFiltersChips.scrollWidth+this._getFilterChipOverflowReservePx()>e;this._panelFiltersShowAllWrap.classList.toggle(`is-hidden`,!t),this._setFilterChipsEdgeFade(t)}_getResultFocusableElements(){let e=this._customResultsWrap&&!this._customResultsWrap.classList.contains(`is-hidden`)?this._customResultsWrap:this._resultsWrap;return e?Array.from(e.querySelectorAll(`button:not([disabled]), [href], [tabindex]:not([tabindex="-1"]), input:not([disabled]), select:not([disabled]), textarea:not([disabled])`)):[]}_getSearchFocusableElements(){return[this._shell,this._panelInner].filter(e=>!!e).flatMap(e=>Array.from(e.querySelectorAll(`button:not([disabled]), [href], [tabindex]:not([tabindex="-1"]), input:not([disabled]), select:not([disabled]), textarea:not([disabled])`))).filter(e=>{if(e.closest(`.is-hidden`)||e.closest(`[aria-hidden="true"]`))return!1;let t=window.getComputedStyle(e);return t.display!==`none`&&t.visibility!==`hidden`})}_focusFirstChipOrResult(e=!1){let t=this._getFilterChipElements(),n=this._getResultFocusableElements();if(!e){(t[0]||n[0])?.focus();return}(n[n.length-1]||t[t.length-1])?.focus()}_moveFocusInResults(e,t){let n=this._getResultFocusableElements();if(n.length===0)return;let r=n.indexOf(e);if(r===-1)return;let i=n[r+t];if(i){i.focus();return}if(t===-1){let e=this._getFilterChipElements(),t=e[e.length-1];t?t.focus():this._focusActiveInput()}}_renderSelectedFilter(){let e=e=>{if(!e||(e.innerHTML=``,!this._hasSelectedFilters()))return;let t=document.createElement(`mint-chip`);t.setAttribute(`dismissable`,``),t.title=this._getFilterChipLabelText();let n=this._getCondensedFilterChipLabel();t.classList.add(`mint-search-selected-filter`),this._selectedFilterBackspaceArmed&&t.classList.add(`is-backspace-armed`),t.textContent=n,t.addEventListener(`dismiss`,e=>{e.stopPropagation(),this._clearAllSelectedFilters()}),e.appendChild(t)};e(this._desktopFilterWrap),e(this._mobileFilterWrap);let t=this._hasSelectedFilters();this._desktopInput?.classList.toggle(`has-selected-filter`,t),this._panelInput?.classList.toggle(`has-selected-filter`,t),this._syncSelectedFilterInputOffset(this._desktopInput,this._desktopFilterWrap),this._syncSelectedFilterInputOffset(this._panelInput,this._mobileFilterWrap)}_syncSelectedFilterInputOffset(e,t){if(!e||!t)return;let n=t.querySelector(`mint-chip`);if(!n){e.style.removeProperty(`--mint-search-filter-chip-width`);return}let r=()=>{n.isConnected&&e.style.setProperty(`--mint-search-filter-chip-width`,`${n.getBoundingClientRect().width}px`)};r(),requestAnimationFrame(r)}_bindInputHandlers(e){let t=()=>{this._scheduleSearch(this._getNativeInputValue(e))};e.addEventListener(`focusin`,()=>this._openSearch(!1)),e.addEventListener(`input`,t),e.addEventListener(`search`,t),e.addEventListener(`change`,t),e.addEventListener(`keydown`,t=>{if(t.key===`ArrowDown`){this._searchOpen||this._openSearch(!1),t.preventDefault(),this._focusFirstChipOrResult(!1);return}if(t.key===`ArrowUp`){this._searchOpen||this._openSearch(!1),t.preventDefault(),this._focusFirstChipOrResult(!0);return}if(t.key!==`Backspace`)return;let n=this._getNativeInputValue(e);if(n!==this._query&&this._setQuery(n),!(n.length>0)&&this._hasSelectedFilters()){if(!this._selectedFilterBackspaceArmed){t.preventDefault(),this._selectedFilterBackspaceArmed=!0,this._renderSelectedFilter();return}t.preventDefault(),this._popLastSelectedFilter()}})}openSearch(e=!0){this._openSearch(e)}closeSearch(){this._closeSearch()}toggleSearch(e=!0){if(this._searchOpen){this._closeSearch();return}this._openSearch(e)}isSearchOpen(){return this._searchOpen}render(){let e=this._getEndpoint();if(this.classList.toggle(`is-hidden`,!e),!e){this._searchOpen=!1,this._panel?.classList.add(`is-hidden`);return}if(!this._shell){this._shell=document.createElement(`div`),this._shell.className=`mint-search-shell`,this._desktopFilterWrap=document.createElement(`div`),this._desktopFilterWrap.className=`mint-search-filter-slot`,this._desktopFilterWrap.setAttribute(`slot`,`prepend`),this._desktopInput=document.createElement(`mint-input`),this._desktopInput.setAttribute(`type`,`search`),this._desktopInput.setAttribute(`icon`,`search`),this._desktopInput.setAttribute(`aria-label`,this.getAttribute(`placeholder`)||`Search`),this._desktopInput.className=`mint-search-input`;let e=document.createElement(`span`);e.className=`mint-search-shortcut-hint`,e.setAttribute(`slot`,`append`),this._desktopShortcutHint=e,this._bindInputHandlers(this._desktopInput),this._desktopInput.appendChild(this._desktopFilterWrap),this._desktopInput.appendChild(e),this._shell.appendChild(this._desktopInput),this.appendChild(this._shell)}if(!this._panel){this._panel=document.createElement(`div`),this._panel.className=`mint-search-panel is-hidden`;let e=document.createElement(`div`);e.className=`mint-search-panel-inner`,this._panelInner=e;let t=document.createElement(`div`);this._panelSearchBar=t,t.className=`mint-search-panel-searchbar is-hidden`,this._mobileFilterWrap=document.createElement(`div`),this._mobileFilterWrap.className=`mint-search-filter-slot`,this._mobileFilterWrap.setAttribute(`slot`,`prepend`),this._panelInput=document.createElement(`mint-input`),this._panelInput.setAttribute(`type`,`search`),this._panelInput.setAttribute(`icon`,`search`),this._panelInput.setAttribute(`aria-label`,this.getAttribute(`placeholder`)||`Search`),this._panelInput.className=`mint-search-input`,this._bindInputHandlers(this._panelInput),this._panelInput.appendChild(this._mobileFilterWrap),t.appendChild(this._panelInput),this._customResultsWrap=document.createElement(`div`),this._customResultsWrap.className=`mint-search-custom-results is-hidden`,this._stateWrap=document.createElement(`div`),this._stateWrap.className=`mint-search-state`,this._stateWrap.textContent=`Start typing to search`,this._stateWrap.setAttribute(`role`,`status`),this._stateWrap.setAttribute(`aria-live`,`polite`),this._resultsWrap=document.createElement(`div`),this._resultsWrap.className=`mint-search-results`,this._resultsId=`mint-search-results-${Math.random().toString(36).slice(2,10)}`,this._resultsWrap.id=this._resultsId,this._resultsWrap.setAttribute(`role`,`listbox`),this._resultsWrap.setAttribute(`aria-label`,`Search results`),this._customResultsWrap.setAttribute(`role`,`region`),this._customResultsWrap.setAttribute(`aria-label`,`Search results`),e.appendChild(t),this._panelFiltersWrap=document.createElement(`div`),e.appendChild(this._panelFiltersWrap),this._ensurePanelFiltersShell(),e.appendChild(this._customResultsWrap),e.appendChild(this._stateWrap),e.appendChild(this._resultsWrap),this._panel.appendChild(e)}this._panel.parentElement!==document.body&&document.body.appendChild(this._panel);let t=this._hasSelectedFilters()?``:this._getPlaceholder();if(this._desktopInput&&this._desktopInput.setAttribute(`placeholder`,t),this._panelInput&&this._panelInput.setAttribute(`placeholder`,t),this._desktopInput&&this._desktopInput.setAttribute(`aria-label`,this.getAttribute(`aria-label`)||this._getPlaceholder()),this._panelInput&&this._panelInput.setAttribute(`aria-label`,this.getAttribute(`aria-label`)||this._getPlaceholder()),this._desktopShortcutHint){let e=this._getOpenShortcutHintText();this._desktopShortcutHint.textContent=e,this._desktopShortcutHint.classList.toggle(`is-hidden`,!e)}if(this._panelFiltersWrap){this._ensurePanelFiltersShell();let e=this._getFilterOptions();this._selectedFilters=this._selectedFilters.filter(t=>e.includes(t));let t=e.length>0;t||(this._filtersMoreOpen=!1),this._panelFiltersWrap.classList.toggle(`is-hidden`,!t),this._panelInner?.classList.toggle(`has-no-filters`,!t),this._panelFiltersChips&&this._panelFiltersChips.replaceChildren(),this._panelFiltersMorePanel&&this._panelFiltersMorePanel.replaceChildren();let n=this._filtersMoreOpen&&this._panelFiltersMorePanel?this._panelFiltersMorePanel:this._panelFiltersChips;for(let t of e){if(!n)break;let r=document.createElement(`mint-chip`),i=this._selectedFilters.includes(t);if(i&&r.classList.add(`is-selected`),r.classList.add(`mint-search-filter-chip`),i){let e=document.createElement(`span`);e.textContent=t;let n=document.createElement(`mint-icon`);n.setAttribute(`name`,`close`),n.className=`mint-search-filter-chip-close`,n.setAttribute(`aria-hidden`,`true`),r.append(e,n)}else r.textContent=t;r.tabIndex=0,r.setAttribute(`role`,`button`),r.setAttribute(`aria-label`,i?`Remove filter ${t}`:`Filter by ${t}`),r.dataset.mintSearchFilter=t,r.addEventListener(`pointerdown`,e=>{e.preventDefault()});let a=n=>{n&&n.stopPropagation();let r=this._filtersMoreOpen,i=this._selectedFilters.indexOf(t);i>=0?this._selectedFilters.splice(i,1):this._selectedFilters.push(t),this._selectedFilterBackspaceArmed=!1;let a=e.length>0&&this._selectedFilters.length===e.length,o=this._selectedFilters.length===0;r&&(a||o)&&(this._filtersMoreOpen=!1),this._emitFilterChange(),this._renderSelectedFilter(),this.render(),this._query.trim()&&this._scheduleSearch(this._query),r?a||o?this._focusActiveInput():requestAnimationFrame(()=>{this._getFilterChipElements().find(e=>e.dataset.mintSearchFilter===t)?.focus()}):this._focusActiveInput()};r.addEventListener(`click`,e=>a(e)),r.addEventListener(`keydown`,e=>{let t=this._getFilterChipElements(),n=t.indexOf(r);if(e.key===`Enter`||e.key===` `){e.preventDefault(),a(e);return}if(e.key===`ArrowRight`){e.preventDefault();let r=t[n+1];r&&r.focus();return}if(e.key===`ArrowLeft`){e.preventDefault();let r=t[n-1];r?r.focus():this._filtersMoreOpen?this._focusHideFiltersControl():this._focusActiveInput();return}if(e.key===`ArrowDown`){e.preventDefault(),this._getResultFocusableElements()[0]?.focus();return}if(e.key===`ArrowUp`){e.preventDefault(),this._filtersMoreOpen?this._focusHideFiltersControl():this._focusActiveInput();return}}),n.appendChild(r)}this._panelFiltersChips&&this._panelFiltersChips.classList.toggle(`is-hidden`,this._filtersMoreOpen),this._panelFiltersMorePanel&&this._panelFiltersMorePanel.classList.toggle(`is-hidden`,!this._filtersMoreOpen),this._panelFiltersShowAllBtn&&(this._setPanelFiltersShowAllLabel(this._filtersMoreOpen?`Hide filters`:`Show all`),this._panelFiltersShowAllBtn.setAttribute(`aria-expanded`,this._filtersMoreOpen?`true`:`false`)),this._panelInner&&(this._filtersMoreOpen&&t?this._panelInner.classList.add(`is-overflow-visible`):this._panelInner.classList.remove(`is-overflow-visible`)),this._scheduleFilterOverflowSync()}if(this._customResultsWrap){Array.from(this.children).filter(e=>e===this._shell||e===this._panel?!1:e.getAttribute(`slot`)===`results`).forEach(e=>this._customResultsWrap.appendChild(e));let e=this._customResultsWrap.childElementCount>0;this._customResultsWrap.classList.toggle(`is-hidden`,!e),e?(this._stateWrap?.classList.add(`is-hidden`),this._resultsWrap?.classList.add(`is-hidden`)):this._resultsWrap?.classList.remove(`is-hidden`)}this._renderSelectedFilter(),this._syncResponsiveChrome(),this._syncPanelVisibility()}_syncResponsiveChrome(){let e=this._collapseOnMobile();this._shell&&this._shell.classList.toggle(`is-collapsed`,e),this._panelSearchBar&&(this._panelSearchBar.classList.toggle(`is-hidden`,!e),this._panelSearchBar.classList.toggle(`is-collapsed`,e))}};customElements.get(`mint-search`)||e.t(`mint-search`,t),module.exports=t;
|
|
1
|
+
require(`../chunks/icon-CWOP4Com.js`);const e=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/icon-D6C1XGp2.js`),require(`../chunks/close-DSrpkGHJ.js`),require(`../chunks/button-B_yN18B-.js`),require(`../chunks/chip-BUaS7ks-.js`),require(`../chunks/input-BI4nrOaG.js`),require(`../chunks/search-q3dkl4-X.js`);var t=class e extends HTMLElement{constructor(...e){super(...e),this._shell=null,this._desktopInput=null,this._panel=null,this._panelInner=null,this._resultsId=``,this._panelInput=null,this._panelFiltersWrap=null,this._panelFiltersMainRow=null,this._panelFiltersChips=null,this._panelFiltersShowAllWrap=null,this._panelFiltersShowAllBtn=null,this._panelFiltersMorePanel=null,this._filtersMoreOpen=!1,this._filterOverflowObserver=null,this._filterOverflowZeroWidthRetries=0,this._resultsWrap=null,this._stateWrap=null,this._customResultsWrap=null,this._query=``,this._searchOpen=!1,this._selectedFilters=[],this._debounceId=null,this._abortController=null,this._docPointerDownHandler=null,this._globalKeydownHandler=null,this._focusOutHandler=null,this._resizeHandler=null,this._scrollHandler=null,this._desktopShortcutHint=null,this._panelSearchBar=null,this._contentObserver=null,this._renderFrame=null}static{this._filterMorePanelSeq=0}static{this._filterChipsOverflowMask=`linear-gradient(to right, #000 0%, #000 max(0%, calc(100% - 3.5rem)), transparent 100%)`}static get observedAttributes(){return[`endpoint`,`search-param`,`placeholder`,`filters`,`filter-param`,`open-shortcut`,`open-shortcut-hint`,`collapse-on-mobile`,`results-limit`]}connectedCallback(){this.classList.add(`mint-search-host`),this._attachGlobalHandlers(),this._attachFocusOutHandler(),this._attachResizeHandler(),this.render(),this._observeContentMutations()}disconnectedCallback(){this._panel?.remove(),this._docPointerDownHandler&&=(document.removeEventListener(`pointerdown`,this._docPointerDownHandler,!0),null),this._globalKeydownHandler&&=(document.removeEventListener(`keydown`,this._globalKeydownHandler),null),this._resizeHandler&&=(window.removeEventListener(`resize`,this._resizeHandler),null),this._scrollHandler&&=(document.removeEventListener(`scroll`,this._scrollHandler,!0),null),this._focusOutHandler&&=(this.removeEventListener(`focusout`,this._focusOutHandler,!0),null),this._cancelDebounce(),this._abortSearch(),this._filterOverflowObserver&&=(this._filterOverflowObserver.disconnect(),null),this._contentObserver&&=(this._contentObserver.disconnect(),null),this._renderFrame!==null&&(cancelAnimationFrame(this._renderFrame),this._renderFrame=null)}attributeChangedCallback(e,t,n){t!==n&&this.render()}_scheduleRender(){this._renderFrame===null&&(this._renderFrame=requestAnimationFrame(()=>{this._renderFrame=null,this.render()}))}_observeContentMutations(){this._contentObserver||=new MutationObserver(()=>{this._scheduleRender()}),this._contentObserver.disconnect(),this._contentObserver.observe(this,{childList:!0,attributes:!0,attributeFilter:[`slot`]})}_getEndpoint(){return(this.getAttribute(`endpoint`)||``).trim()}_getSearchParam(){return(this.getAttribute(`search-param`)||`q`).trim()||`q`}_getPlaceholder(){return this.getAttribute(`placeholder`)||`Search`}_getFilterParam(){return(this.getAttribute(`filter-param`)||``).trim()}_getFilterOptions(){return(this.getAttribute(`filters`)||``).split(`,`).map(e=>e.trim()).filter(Boolean)}_hasSelectedFilters(){return this._selectedFilters.length>0}_getFilterChipOverflowReservePx(){let e=Math.max(1,this._getFilterOptions().length),t=this._hasSelectedFilters()?28:56;return Math.min(200,t+e*34)}_getFilterParamValue(){return this._selectedFilters.join(`,`)}_isMobileViewport(){return window.matchMedia(`(max-width: 1099.98px)`).matches}_collapseOnMobile(){let e=this.getAttribute(`collapse-on-mobile`);if(e===null)return!1;let t=e.trim().toLowerCase();return!(t===`false`||t===`0`||t===`off`||t===`none`)}_primarySearchInput(){return this._isMobileViewport()&&this._collapseOnMobile()?this._panelInput:this._desktopInput}_isApplePlatform(){return typeof navigator>`u`?!1:/Mac|iPhone|iPad|iPod/i.test(navigator.platform)||/Mac OS/i.test(navigator.userAgent)}_parseOpenShortcut(){let e=(this.getAttribute(`open-shortcut`)??`mod+k`).trim().toLowerCase();if(!e||e===`none`||e===`false`||e===`off`)return{disabled:!0,wantMod:!1,wantMeta:!1,wantCtrl:!1,wantAlt:!1,wantShift:!1,key:``};let t=e.split(`+`).map(e=>e.trim()).filter(Boolean);if(t.length===0)return{disabled:!0,wantMod:!1,wantMeta:!1,wantCtrl:!1,wantAlt:!1,wantShift:!1,key:``};let n=t[t.length-1],r=new Set(t.slice(0,-1).map(e=>e.toLowerCase()));return{disabled:!1,wantMod:r.has(`mod`),wantMeta:r.has(`meta`)||r.has(`cmd`)||r.has(`super`),wantCtrl:r.has(`ctrl`)||r.has(`control`),wantAlt:r.has(`alt`),wantShift:r.has(`shift`),key:n.toLowerCase()}}_eventKeyMatchesShortcutKey(e,t){let n=t.toLowerCase();return(e.key.length,e.key.toLowerCase())===n}_openShortcutMatches(e){let t=this._parseOpenShortcut();return t.disabled||!t.key||e.repeat||!this._eventKeyMatchesShortcutKey(e,t.key)||t.wantShift!==e.shiftKey||t.wantAlt!==e.altKey?!1:t.wantMod||t.wantMeta||t.wantCtrl?!(t.wantMod&&!(e.metaKey||e.ctrlKey)||t.wantMeta&&!e.metaKey||t.wantCtrl&&!e.ctrlKey):!!t.wantAlt}_getOpenShortcutHintText(){let e=this.getAttribute(`open-shortcut-hint`);if(e===`none`||e===`false`)return``;if(e!==null&&e.trim()!==``)return e.trim();let t=this._parseOpenShortcut();if(t.disabled)return``;let n=this._isApplePlatform(),r=[];t.wantMod&&r.push(n?`⌘`:`Ctrl`),t.wantMeta&&!t.wantMod&&r.push(n?`⌘`:`Meta`),t.wantCtrl&&!t.wantMod&&r.push(`Ctrl`),t.wantAlt&&r.push(`Alt`),t.wantShift&&r.push(`Shift`);let i=t.key.length===1?t.key.toUpperCase():t.key;return i?t.wantMod&&!t.wantMeta&&!t.wantCtrl&&!t.wantAlt&&!t.wantShift&&t.key.length===1?`${n?`⌘`:`Ctrl+`}${i}`:[...r,i].join(`+`):``}_attachGlobalHandlers(){this._globalKeydownHandler||(this._globalKeydownHandler=e=>{if(this._openShortcutMatches(e)){e.preventDefault(),this._openSearch(!0);return}if(e.key===`Tab`&&this._searchOpen){let t=e.composedPath();if(this._shell&&t.includes(this._shell)||this._panelInner&&t.includes(this._panelInner)){let t=this._getSearchFocusableElements();if(t.length){let n=document.activeElement,r=n?t.indexOf(n):-1,i=e.shiftKey?-1:1,a=r<0?e.shiftKey?t.length-1:0:(r+i+t.length)%t.length;e.preventDefault(),t[a]?.focus()}}return}if(e.key.toLowerCase()===`escape`&&this._searchOpen){if(this._filtersMoreOpen){this._filtersMoreOpen=!1,this.render(),requestAnimationFrame(()=>this._focusActiveInput());return}this._closeSearch()}},document.addEventListener(`keydown`,this._globalKeydownHandler)),this._docPointerDownHandler||(this._docPointerDownHandler=e=>{if(!this._searchOpen)return;let t=e.composedPath();this._filtersMoreOpen&&this._panelFiltersWrap&&!t.includes(this._panelFiltersWrap)&&(this._filtersMoreOpen=!1,this.render(),requestAnimationFrame(()=>this._focusActiveInput())),!(this._shell&&t.includes(this._shell)||this._panelInner&&t.includes(this._panelInner))&&this._closeSearch()},document.addEventListener(`pointerdown`,this._docPointerDownHandler,!0))}_attachResizeHandler(){this._resizeHandler||(this._resizeHandler=()=>{this._syncPanelVisibility(),this._syncFilterOverflow()},window.addEventListener(`resize`,this._resizeHandler,{passive:!0})),this._scrollHandler||(this._scrollHandler=()=>{this._searchOpen&&this._positionPanel()},document.addEventListener(`scroll`,this._scrollHandler,!0))}_attachFocusOutHandler(){this._focusOutHandler||(this._focusOutHandler=e=>{if(!this._searchOpen)return;let t=e.relatedTarget;t&&(this._shell&&this._shell.contains(t)||this._panelInner&&this._panelInner.contains(t)||this._closeSearch())},this.addEventListener(`focusout`,this._focusOutHandler,!0))}_emitSearchOpenChange(){this.dispatchEvent(new CustomEvent(`search-open-change`,{detail:{open:this._searchOpen},bubbles:!0,composed:!0}))}_openSearch(e=!1){this._getEndpoint()&&(this._searchOpen||(this._searchOpen=!0,this._syncPanelVisibility(),this._emitSearchOpenChange(),e&&this._primarySearchInput()?.focus()))}_closeSearch(){this._searchOpen&&(this._searchOpen=!1,this._filtersMoreOpen=!1,this._syncPanelVisibility(),this._emitSearchOpenChange())}_syncPanelVisibility(){if(this._panel){this._syncPanelLayoutClass(),this._panel.classList.toggle(`is-hidden`,!this._searchOpen),this._panel.classList.toggle(`is-open`,this._searchOpen),this._shell&&this._shell.classList.toggle(`is-open`,this._searchOpen);for(let e of[this._desktopInput,this._panelInput]){let t=e?.querySelector(`input`);t&&(t.setAttribute(`aria-expanded`,String(this._searchOpen)),this._resultsId&&t.setAttribute(`aria-controls`,this._resultsId))}this._positionPanel(),this._searchOpen&&this._scheduleFilterOverflowSync()}}_syncPanelLayoutClass(){if(!this._panel)return;let e=!this._isMobileViewport()||!this._collapseOnMobile();this._panel.classList.toggle(`mint-search-panel-anchored`,e),this._panel.classList.toggle(`mint-search-panel-mobile`,!e),this._panel.classList.toggle(`mint-search-panel-global`,this.classList.contains(`global-search-control`))}_positionPanel(){if(!this._panel)return;if(!(!this._isMobileViewport()||!this._collapseOnMobile())){this._panel.style.left=``,this._panel.style.right=``,this._panel.style.top=``,this._panel.style.bottom=``,this._panel.style.width=``,this._panel.classList.remove(`is-open-above`),this._panelInner&&(this._panelInner.style.maxHeight=``);return}let e=this._shell?.getBoundingClientRect();if(!e)return;let t=window.innerHeight,n=Math.max(0,Math.min(416,t-16)),r=Math.max(0,t-e.bottom-8-4),i=Math.max(0,e.top-8-4),a=r<n&&i>r,o=Math.min(n,a?i:r);this._panel.classList.toggle(`is-open-above`,a),this._panelInner&&(this._panelInner.style.maxHeight=`${o}px`),this._panel.style.left=`${e.left}px`,this._panel.style.width=`${e.width}px`,this._panel.style.right=`auto`,a?(this._panel.style.top=`auto`,this._panel.style.bottom=`${Math.max(0,t-e.top+4)}px`):(this._panel.style.top=`${e.bottom+4}px`,this._panel.style.bottom=`auto`)}_setQuery(e){this._query=e,this._desktopInput&&(this._desktopInput.value=e),this._panelInput&&(this._panelInput.value=e)}_cancelDebounce(){this._debounceId!==null&&(window.clearTimeout(this._debounceId),this._debounceId=null)}_abortSearch(){this._abortController&&=(this._abortController.abort(),null)}_normalizeResults(e){let t=Number.parseInt(this.getAttribute(`results-limit`)||``,10),n=Number.isFinite(t)&&t>0?Math.min(t,1e3):8;return(e=>{if(Array.isArray(e))return e;if(!e||typeof e!=`object`)return[];let t=e;for(let e of[`results`,`items`,`data`,`products`]){let n=t[e];if(Array.isArray(n))return n}return[]})(e).map(e=>{let t=e||{};return{title:String(t.title||t.name||t.label||t.email||t.id||``).trim()||`Untitled`,subtitle:String(t.description||t.category||t.username||``).trim(),parent:String(t.parent||t.type||t.entity||t.kind||t.category||``).trim()||void 0}}).slice(0,n)}_emitResultsChange(e,t){let n=this._hasSelectedFilters()?this._getFilterParamValue():null;this.dispatchEvent(new CustomEvent(`search-results-change`,{detail:{query:this._query,filter:n,filters:[...this._selectedFilters],results:e,raw:t??null},bubbles:!0,composed:!0}))}_emitFilterChange(){let e=this._hasSelectedFilters()?this._getFilterParamValue():null;this.dispatchEvent(new CustomEvent(`search-filter-change`,{detail:{query:this._query,filter:e,filters:[...this._selectedFilters]},bubbles:!0,composed:!0}))}_renderState(e){if(this._customResultsWrap&&this._customResultsWrap.childElementCount>0){this._stateWrap&&this._stateWrap.classList.add(`is-hidden`),this._resultsWrap&&this._resultsWrap.classList.add(`is-hidden`);return}this._stateWrap&&(this._stateWrap.textContent=e,this._stateWrap.classList.remove(`is-hidden`),this._resultsWrap&&(this._resultsWrap.classList.remove(`is-hidden`),this._resultsWrap.innerHTML=``))}_renderResults(e){if(this._customResultsWrap&&this._customResultsWrap.childElementCount>0){this._stateWrap&&this._stateWrap.classList.add(`is-hidden`),this._resultsWrap&&this._resultsWrap.classList.add(`is-hidden`);return}if(!(!this._resultsWrap||!this._stateWrap)){if(this._resultsWrap.innerHTML=``,e.length===0){this._renderState(`No results found`);return}this._stateWrap.classList.add(`is-hidden`);for(let t of e){let e=document.createElement(`button`);e.type=`button`,e.className=`mint-search-result`,e.setAttribute(`role`,`option`),e.setAttribute(`aria-selected`,`false`);let n=document.createElement(`mint-icon`);n.setAttribute(`name`,`search`),n.className=`mint-search-result-icon`;let r=document.createElement(`div`);r.className=`mint-search-result-copy`;let i=document.createElement(`div`);if(i.className=`mint-search-result-title`,i.textContent=t.title,r.appendChild(i),t.subtitle){let e=document.createElement(`div`);e.className=`mint-search-result-subtitle`,e.textContent=t.subtitle,r.appendChild(e)}e.appendChild(n),e.appendChild(r),e.addEventListener(`keydown`,t=>{if(t.key===`ArrowDown`){t.preventDefault(),this._moveFocusInResults(e,1);return}if(t.key===`ArrowUp`){t.preventDefault(),this._moveFocusInResults(e,-1);return}}),e.addEventListener(`click`,()=>{let e=this._hasSelectedFilters()?this._getFilterParamValue():null;this.dispatchEvent(new CustomEvent(`search-select`,{detail:{query:this._query,filter:e,filters:[...this._selectedFilters],result:t},bubbles:!0,composed:!0})),this._closeSearch()}),this._resultsWrap.appendChild(e)}}}_fetchSearchResults(e){let t=this._getEndpoint();if(!t)return;let n=e.trim();if(!n){this._emitResultsChange([]),this._renderState(`Start typing to search`);return}this._abortSearch(),this._abortController=new AbortController,this._renderState(`Searching...`);let r=new URLSearchParams;r.set(this._getSearchParam(),n);let i=this._getFilterParam();i&&this._hasSelectedFilters()&&r.set(i,this._getFilterParamValue());let a=t.includes(`{query}`)?t.replace(`{query}`,encodeURIComponent(n)):`${t}${t.includes(`?`)?`&`:`?`}${r.toString()}`;fetch(a,{signal:this._abortController.signal}).then(e=>{if(!e.ok)throw Error(`Request failed: ${e.status}`);return e.json()}).then(e=>{let t=this._normalizeResults(e);this._emitResultsChange(t,e),this._renderResults(t)}).catch(e=>{e?.name!==`AbortError`&&(this._emitResultsChange([]),this._renderState(`Unable to load results`))})}_scheduleSearch(e){this._setQuery(e),this._cancelDebounce(),this._debounceId=window.setTimeout(()=>this._fetchSearchResults(e),220)}_getNativeInputValue(e){if(!e)return``;let t=e.querySelector(`input, textarea`);return t?t.value||``:e.value||``}_getCurrentInputValue(){let e=document.activeElement;return e&&this._desktopInput&&this._desktopInput.contains(e)?this._getNativeInputValue(this._desktopInput):e&&this._panelInput&&this._panelInput.contains(e)?this._getNativeInputValue(this._panelInput):this._getNativeInputValue(this._primarySearchInput())}_applyFilterSelectionChange(){let e=this._getCurrentInputValue();if(this._setQuery(e),this._emitFilterChange(),this.render(),e.trim()){this._scheduleSearch(e);return}this._cancelDebounce(),this._abortSearch(),this._emitResultsChange([]),this._renderState(`Start typing to search`)}_popLastSelectedFilter(){this._selectedFilters.length!==0&&(this._selectedFilters.pop(),this._applyFilterSelectionChange())}_focusActiveInput(){let e=this._primarySearchInput();e&&requestAnimationFrame(()=>{e.focus()})}_focusHideFiltersControl(){let e=this._panelFiltersShowAllBtn;e&&(e.querySelector(`button`)??e).focus()}_getFilterChipElements(){return this._panelFiltersWrap?Array.from(this._panelFiltersWrap.querySelectorAll(`mint-chip`)):[]}_ensurePanelFiltersShell(){!this._panelFiltersWrap||this._panelFiltersMainRow||(this._panelFiltersWrap.replaceChildren(),this._panelFiltersWrap.className=`mint-search-filters`,this._panelFiltersMainRow=document.createElement(`div`),this._panelFiltersMainRow.className=`mint-search-filter-row`,this._panelFiltersChips=document.createElement(`div`),this._panelFiltersChips.className=`mint-search-filter-chips`,this._panelFiltersMorePanel=document.createElement(`div`),this._panelFiltersMorePanel.id=`mint-search-filter-more-${e._filterMorePanelSeq++}`,this._panelFiltersMorePanel.className=`mint-search-filter-more is-hidden`,this._panelFiltersShowAllWrap=document.createElement(`div`),this._panelFiltersShowAllWrap.className=`mint-search-filter-more-trigger is-hidden`,this._panelFiltersShowAllBtn=document.createElement(`mint-button`),this._panelFiltersShowAllBtn.setAttribute(`type`,`button`),this._panelFiltersShowAllBtn.setAttribute(`variant`,`ghost`),this._panelFiltersShowAllBtn.setAttribute(`tone`,`neutral`),this._panelFiltersShowAllBtn.setAttribute(`size`,`small`),this._panelFiltersShowAllBtn.classList.add(`mint-search-filter-more-button`),this._panelFiltersShowAllBtn.setAttribute(`aria-expanded`,`false`),this._panelFiltersShowAllBtn.setAttribute(`aria-controls`,this._panelFiltersMorePanel.id),this._panelFiltersShowAllBtn.addEventListener(`click`,e=>{e.stopPropagation();let t=this._filtersMoreOpen;this._filtersMoreOpen=!this._filtersMoreOpen,this.render(),t&&requestAnimationFrame(()=>this._focusActiveInput())}),this._panelFiltersShowAllWrap.append(this._panelFiltersShowAllBtn),this._panelFiltersMainRow.append(this._panelFiltersChips,this._panelFiltersShowAllWrap),this._setPanelFiltersShowAllLabel(`Show all`),this._panelFiltersWrap.append(this._panelFiltersMainRow,this._panelFiltersMorePanel),typeof ResizeObserver<`u`&&!this._filterOverflowObserver&&(this._filterOverflowObserver=new ResizeObserver(()=>this._syncFilterOverflow()),this._filterOverflowObserver.observe(this._panelFiltersChips),this._filterOverflowObserver.observe(this._panelFiltersMainRow)))}_setPanelFiltersShowAllLabel(e){let t=this._panelFiltersShowAllBtn;if(!t)return;for(let e of Array.from(t.childNodes))e.nodeType===Node.TEXT_NODE&&e.remove();let n=t.querySelector(`button .mint-button-content`)||t.querySelector(`.mint-button-content`);if(n){n.textContent=e;return}let r=t.querySelector(`:scope > button`);if(r){r.replaceChildren(document.createTextNode(e)),t.render?.();return}t.firstElementChild||t.appendChild(document.createTextNode(e))}_scheduleFilterOverflowSync(){requestAnimationFrame(()=>{requestAnimationFrame(()=>this._syncFilterOverflow())})}_setFilterChipsEdgeFade(t){let n=this._panelFiltersChips;n&&(t?(n.style.maskImage=e._filterChipsOverflowMask,n.style.webkitMaskImage=e._filterChipsOverflowMask):(n.style.maskImage=``,n.style.webkitMaskImage=``))}_syncFilterOverflow(){if(!this._panelFiltersChips||!this._panelFiltersShowAllWrap||!this._panelFiltersShowAllBtn)return;if(this._filtersMoreOpen){this._panelFiltersShowAllWrap.classList.remove(`is-hidden`),this._filterOverflowZeroWidthRetries=0,this._setFilterChipsEdgeFade(!1);return}let e=this._panelFiltersChips.clientWidth;if(e===0&&this._searchOpen){this._filterOverflowZeroWidthRetries<10&&(this._filterOverflowZeroWidthRetries+=1,this._scheduleFilterOverflowSync()),this._setFilterChipsEdgeFade(!1);return}this._filterOverflowZeroWidthRetries=0;let t=this._panelFiltersChips.scrollWidth+this._getFilterChipOverflowReservePx()>e;this._panelFiltersShowAllWrap.classList.toggle(`is-hidden`,!t),this._setFilterChipsEdgeFade(t)}_getResultFocusableElements(){let e=this._customResultsWrap&&!this._customResultsWrap.classList.contains(`is-hidden`)?this._customResultsWrap:this._resultsWrap;return e?Array.from(e.querySelectorAll(`button:not([disabled]), [href], [tabindex]:not([tabindex="-1"]), input:not([disabled]), select:not([disabled]), textarea:not([disabled])`)):[]}_getSearchFocusableElements(){return[this._shell,this._panelInner].filter(e=>!!e).flatMap(e=>Array.from(e.querySelectorAll(`button:not([disabled]), [href], [tabindex]:not([tabindex="-1"]), input:not([disabled]), select:not([disabled]), textarea:not([disabled])`))).filter(e=>{if(e.closest(`.is-hidden`)||e.closest(`[aria-hidden="true"]`))return!1;let t=window.getComputedStyle(e);return t.display!==`none`&&t.visibility!==`hidden`})}_focusFirstChipOrResult(e=!1){let t=this._getFilterChipElements(),n=this._getResultFocusableElements();if(!e){(t[0]||n[0])?.focus();return}(n[n.length-1]||t[t.length-1])?.focus()}_moveFocusInResults(e,t){let n=this._getResultFocusableElements();if(n.length===0)return;let r=n.indexOf(e);if(r===-1)return;let i=n[r+t];if(i){i.focus();return}if(t===-1){let e=this._getFilterChipElements(),t=e[e.length-1];t?t.focus():this._focusActiveInput()}}_bindInputHandlers(e){let t=()=>{this._scheduleSearch(this._getNativeInputValue(e))};e.addEventListener(`focusin`,()=>this._openSearch(!1)),e.addEventListener(`input`,t),e.addEventListener(`search`,t),e.addEventListener(`change`,t),e.addEventListener(`keydown`,t=>{if(t.key===`ArrowDown`){this._searchOpen||this._openSearch(!1),t.preventDefault(),this._focusFirstChipOrResult(!1);return}if(t.key===`ArrowUp`){this._searchOpen||this._openSearch(!1),t.preventDefault(),this._focusFirstChipOrResult(!0);return}if(t.key!==`Backspace`)return;let n=this._getNativeInputValue(e);n!==this._query&&this._setQuery(n),!(n.length>0)&&this._hasSelectedFilters()&&(t.preventDefault(),this._popLastSelectedFilter())})}openSearch(e=!0){this._openSearch(e)}closeSearch(){this._closeSearch()}toggleSearch(e=!0){if(this._searchOpen){this._closeSearch();return}this._openSearch(e)}isSearchOpen(){return this._searchOpen}render(){let e=this._getEndpoint();if(this.classList.toggle(`is-hidden`,!e),!e){this._searchOpen=!1,this._panel?.classList.add(`is-hidden`);return}if(!this._shell){this._shell=document.createElement(`div`),this._shell.className=`mint-search-shell`,this._desktopInput=document.createElement(`mint-input`),this._desktopInput.setAttribute(`type`,`search`),this._desktopInput.setAttribute(`icon`,`search`),this._desktopInput.setAttribute(`aria-label`,this.getAttribute(`placeholder`)||`Search`),this._desktopInput.className=`mint-search-input`;let e=document.createElement(`span`);e.className=`mint-search-shortcut-hint`,e.setAttribute(`aria-hidden`,`true`),this._desktopShortcutHint=e,this._bindInputHandlers(this._desktopInput),this._shell.appendChild(this._desktopInput),this._shell.appendChild(e),this.appendChild(this._shell)}if(!this._panel){this._panel=document.createElement(`div`),this._panel.className=`mint-search-panel is-hidden`;let e=document.createElement(`div`);e.className=`mint-search-panel-inner`,this._panelInner=e;let t=document.createElement(`div`);this._panelSearchBar=t,t.className=`mint-search-panel-searchbar is-hidden`,this._panelInput=document.createElement(`mint-input`),this._panelInput.setAttribute(`type`,`search`),this._panelInput.setAttribute(`icon`,`search`),this._panelInput.setAttribute(`aria-label`,this.getAttribute(`placeholder`)||`Search`),this._panelInput.className=`mint-search-input`,this._bindInputHandlers(this._panelInput),t.appendChild(this._panelInput),this._customResultsWrap=document.createElement(`div`),this._customResultsWrap.className=`mint-search-custom-results is-hidden`,this._stateWrap=document.createElement(`div`),this._stateWrap.className=`mint-search-state`,this._stateWrap.textContent=`Start typing to search`,this._stateWrap.setAttribute(`role`,`status`),this._stateWrap.setAttribute(`aria-live`,`polite`),this._resultsWrap=document.createElement(`div`),this._resultsWrap.className=`mint-search-results`,this._resultsId=`mint-search-results-${Math.random().toString(36).slice(2,10)}`,this._resultsWrap.id=this._resultsId,this._resultsWrap.setAttribute(`role`,`listbox`),this._resultsWrap.setAttribute(`aria-label`,`Search results`),this._customResultsWrap.setAttribute(`role`,`region`),this._customResultsWrap.setAttribute(`aria-label`,`Search results`),e.appendChild(t),this._panelFiltersWrap=document.createElement(`div`),e.appendChild(this._panelFiltersWrap),this._ensurePanelFiltersShell(),e.appendChild(this._customResultsWrap),e.appendChild(this._stateWrap),e.appendChild(this._resultsWrap),this._panel.appendChild(e)}this._panel.parentElement!==document.body&&document.body.appendChild(this._panel);let t=this._getPlaceholder();if(this._desktopInput&&this._desktopInput.setAttribute(`placeholder`,t),this._panelInput&&this._panelInput.setAttribute(`placeholder`,t),this._desktopInput&&this._desktopInput.setAttribute(`aria-label`,this.getAttribute(`aria-label`)||this._getPlaceholder()),this._panelInput&&this._panelInput.setAttribute(`aria-label`,this.getAttribute(`aria-label`)||this._getPlaceholder()),this._desktopShortcutHint){let e=this._getOpenShortcutHintText();this._desktopShortcutHint.textContent=e,this._desktopShortcutHint.classList.toggle(`is-hidden`,!e)}if(this._panelFiltersWrap){this._ensurePanelFiltersShell();let e=this._getFilterOptions();this._selectedFilters=this._selectedFilters.filter(t=>e.includes(t));let t=e.length>0;t||(this._filtersMoreOpen=!1),this._panelFiltersWrap.classList.toggle(`is-hidden`,!t),this._panelInner?.classList.toggle(`has-no-filters`,!t),this._panelFiltersChips&&this._panelFiltersChips.replaceChildren(),this._panelFiltersMorePanel&&this._panelFiltersMorePanel.replaceChildren();let n=this._filtersMoreOpen&&this._panelFiltersMorePanel?this._panelFiltersMorePanel:this._panelFiltersChips;for(let t of e){if(!n)break;let r=document.createElement(`mint-chip`),i=this._selectedFilters.includes(t);if(i&&r.classList.add(`is-selected`),r.classList.add(`mint-search-filter-chip`),i){let e=document.createElement(`span`);e.textContent=t;let n=document.createElement(`mint-icon`);n.setAttribute(`name`,`close`),n.className=`mint-search-filter-chip-close`,n.setAttribute(`aria-hidden`,`true`),r.append(e,n)}else r.textContent=t;r.tabIndex=0,r.setAttribute(`role`,`button`),r.setAttribute(`aria-label`,i?`Remove filter ${t}`:`Filter by ${t}`),r.dataset.mintSearchFilter=t,r.addEventListener(`pointerdown`,e=>{e.preventDefault()});let a=n=>{n&&n.stopPropagation();let r=this._filtersMoreOpen,i=this._selectedFilters.indexOf(t);i>=0?this._selectedFilters.splice(i,1):this._selectedFilters.push(t);let a=e.length>0&&this._selectedFilters.length===e.length,o=this._selectedFilters.length===0;r&&(a||o)&&(this._filtersMoreOpen=!1),this._emitFilterChange(),this.render(),this._query.trim()&&this._scheduleSearch(this._query),r?a||o?this._focusActiveInput():requestAnimationFrame(()=>{this._getFilterChipElements().find(e=>e.dataset.mintSearchFilter===t)?.focus()}):this._focusActiveInput()};r.addEventListener(`click`,e=>a(e)),r.addEventListener(`keydown`,e=>{let t=this._getFilterChipElements(),n=t.indexOf(r);if(e.key===`Enter`||e.key===` `){e.preventDefault(),a(e);return}if(e.key===`ArrowRight`){e.preventDefault();let r=t[n+1];r&&r.focus();return}if(e.key===`ArrowLeft`){e.preventDefault();let r=t[n-1];r?r.focus():this._filtersMoreOpen?this._focusHideFiltersControl():this._focusActiveInput();return}if(e.key===`ArrowDown`){e.preventDefault(),this._getResultFocusableElements()[0]?.focus();return}if(e.key===`ArrowUp`){e.preventDefault(),this._filtersMoreOpen?this._focusHideFiltersControl():this._focusActiveInput();return}}),n.appendChild(r)}this._panelFiltersChips&&this._panelFiltersChips.classList.toggle(`is-hidden`,this._filtersMoreOpen),this._panelFiltersMorePanel&&this._panelFiltersMorePanel.classList.toggle(`is-hidden`,!this._filtersMoreOpen),this._panelFiltersShowAllBtn&&(this._setPanelFiltersShowAllLabel(this._filtersMoreOpen?`Hide filters`:`Show all`),this._panelFiltersShowAllBtn.setAttribute(`aria-expanded`,this._filtersMoreOpen?`true`:`false`)),this._panelInner&&(this._filtersMoreOpen&&t?this._panelInner.classList.add(`is-overflow-visible`):this._panelInner.classList.remove(`is-overflow-visible`)),this._scheduleFilterOverflowSync()}if(this._customResultsWrap){Array.from(this.children).filter(e=>e===this._shell||e===this._panel?!1:e.getAttribute(`slot`)===`results`).forEach(e=>this._customResultsWrap.appendChild(e));let e=this._customResultsWrap.childElementCount>0;this._customResultsWrap.classList.toggle(`is-hidden`,!e),e?(this._stateWrap?.classList.add(`is-hidden`),this._resultsWrap?.classList.add(`is-hidden`)):this._resultsWrap?.classList.remove(`is-hidden`)}this._syncResponsiveChrome(),this._syncPanelVisibility()}_syncResponsiveChrome(){let e=this._collapseOnMobile();this._shell&&this._shell.classList.toggle(`is-collapsed`,e),this._panelSearchBar&&(this._panelSearchBar.classList.toggle(`is-hidden`,!e),this._panelSearchBar.classList.toggle(`is-collapsed`,e))}};customElements.get(`mint-search`)||e.t(`mint-search`,t),module.exports=t;
|
|
@@ -16,7 +16,7 @@ import "../chunks/search-BwjKBnv9.js";
|
|
|
16
16
|
//#region src/components/search/Search.ts
|
|
17
17
|
var t = class e extends HTMLElement {
|
|
18
18
|
constructor(...e) {
|
|
19
|
-
super(...e), this._shell = null, this._desktopInput = null, this._panel = null, this._panelInner = null, this._resultsId = "", this._panelInput = null, this._panelFiltersWrap = null, this._panelFiltersMainRow = null, this._panelFiltersChips = null, this._panelFiltersShowAllWrap = null, this._panelFiltersShowAllBtn = null, this._panelFiltersMorePanel = null, this._filtersMoreOpen = !1, this._filterOverflowObserver = null, this._filterOverflowZeroWidthRetries = 0, this.
|
|
19
|
+
super(...e), this._shell = null, this._desktopInput = null, this._panel = null, this._panelInner = null, this._resultsId = "", this._panelInput = null, this._panelFiltersWrap = null, this._panelFiltersMainRow = null, this._panelFiltersChips = null, this._panelFiltersShowAllWrap = null, this._panelFiltersShowAllBtn = null, this._panelFiltersMorePanel = null, this._filtersMoreOpen = !1, this._filterOverflowObserver = null, this._filterOverflowZeroWidthRetries = 0, this._resultsWrap = null, this._stateWrap = null, this._customResultsWrap = null, this._query = "", this._searchOpen = !1, this._selectedFilters = [], this._debounceId = null, this._abortController = null, this._docPointerDownHandler = null, this._globalKeydownHandler = null, this._focusOutHandler = null, this._resizeHandler = null, this._scrollHandler = null, this._desktopShortcutHint = null, this._panelSearchBar = null, this._contentObserver = null, this._renderFrame = null;
|
|
20
20
|
}
|
|
21
21
|
static {
|
|
22
22
|
this._filterMorePanelSeq = 0;
|
|
@@ -85,16 +85,6 @@ var t = class e extends HTMLElement {
|
|
|
85
85
|
_getFilterParamValue() {
|
|
86
86
|
return this._selectedFilters.join(",");
|
|
87
87
|
}
|
|
88
|
-
_getFilterChipLabelText() {
|
|
89
|
-
return this._selectedFilters.join(", ");
|
|
90
|
-
}
|
|
91
|
-
_getCondensedFilterChipLabel(e = 22) {
|
|
92
|
-
if (!this._hasSelectedFilters()) return "";
|
|
93
|
-
let [t = ""] = this._selectedFilters, n = this._selectedFilters.length - 1, r = Math.max(8, e - 2), i = t;
|
|
94
|
-
if (n <= 0) return i.length <= r ? i : `${i.slice(0, Math.max(1, r - 3))}...`;
|
|
95
|
-
let a = `${t}, and ${n} more`;
|
|
96
|
-
return a.length <= r ? a : `${a.slice(0, Math.max(1, r - 3))}...`;
|
|
97
|
-
}
|
|
98
88
|
_isMobileViewport() {
|
|
99
89
|
return window.matchMedia("(max-width: 1099.98px)").matches;
|
|
100
90
|
}
|
|
@@ -241,12 +231,11 @@ var t = class e extends HTMLElement {
|
|
|
241
231
|
}
|
|
242
232
|
let e = this._shell?.getBoundingClientRect();
|
|
243
233
|
if (!e) return;
|
|
244
|
-
let t = window.innerHeight, n = Math.max(0, Math.min(416, t - 16)), r = Math.max(0, t - e.bottom - 4), i = Math.max(0, e.top - 4), a = r < n && i > r, o = Math.min(n, a ? i : r);
|
|
245
|
-
this._panel.classList.toggle("is-open-above", a), this._panelInner && (this._panelInner.style.maxHeight = `${o}px`), this._panel.style.left = `${e.left}px`, this._panel.style.width = `${e.width}px`, this._panel.style.right = "auto", a ? (this._panel.style.top = "auto", this._panel.style.bottom = `${Math.max(0, t - e.top
|
|
234
|
+
let t = window.innerHeight, n = Math.max(0, Math.min(416, t - 16)), r = Math.max(0, t - e.bottom - 8 - 4), i = Math.max(0, e.top - 8 - 4), a = r < n && i > r, o = Math.min(n, a ? i : r);
|
|
235
|
+
this._panel.classList.toggle("is-open-above", a), this._panelInner && (this._panelInner.style.maxHeight = `${o}px`), this._panel.style.left = `${e.left}px`, this._panel.style.width = `${e.width}px`, this._panel.style.right = "auto", a ? (this._panel.style.top = "auto", this._panel.style.bottom = `${Math.max(0, t - e.top + 4)}px`) : (this._panel.style.top = `${e.bottom + 4}px`, this._panel.style.bottom = "auto");
|
|
246
236
|
}
|
|
247
237
|
_setQuery(e) {
|
|
248
|
-
|
|
249
|
-
this._query = e, e !== t && (this._selectedFilterBackspaceArmed = !1), this._desktopInput && (this._desktopInput.value = e), this._panelInput && (this._panelInput.value = e);
|
|
238
|
+
this._query = e, this._desktopInput && (this._desktopInput.value = e), this._panelInput && (this._panelInput.value = e);
|
|
250
239
|
}
|
|
251
240
|
_cancelDebounce() {
|
|
252
241
|
this._debounceId !== null && (window.clearTimeout(this._debounceId), this._debounceId = null);
|
|
@@ -404,11 +393,8 @@ var t = class e extends HTMLElement {
|
|
|
404
393
|
}
|
|
405
394
|
this._cancelDebounce(), this._abortSearch(), this._emitResultsChange([]), this._renderState("Start typing to search");
|
|
406
395
|
}
|
|
407
|
-
_clearAllSelectedFilters() {
|
|
408
|
-
this._selectedFilters = [], this._selectedFilterBackspaceArmed = !1, this._applyFilterSelectionChange();
|
|
409
|
-
}
|
|
410
396
|
_popLastSelectedFilter() {
|
|
411
|
-
this._selectedFilters.length !== 0 && (this._selectedFilters.pop(), this.
|
|
397
|
+
this._selectedFilters.length !== 0 && (this._selectedFilters.pop(), this._applyFilterSelectionChange());
|
|
412
398
|
}
|
|
413
399
|
_focusActiveInput() {
|
|
414
400
|
let e = this._primarySearchInput();
|
|
@@ -504,32 +490,6 @@ var t = class e extends HTMLElement {
|
|
|
504
490
|
t ? t.focus() : this._focusActiveInput();
|
|
505
491
|
}
|
|
506
492
|
}
|
|
507
|
-
_renderSelectedFilter() {
|
|
508
|
-
let e = (e) => {
|
|
509
|
-
if (!e || (e.innerHTML = "", !this._hasSelectedFilters())) return;
|
|
510
|
-
let t = document.createElement("mint-chip");
|
|
511
|
-
t.setAttribute("dismissable", ""), t.title = this._getFilterChipLabelText();
|
|
512
|
-
let n = this._getCondensedFilterChipLabel();
|
|
513
|
-
t.classList.add("mint-search-selected-filter"), this._selectedFilterBackspaceArmed && t.classList.add("is-backspace-armed"), t.textContent = n, t.addEventListener("dismiss", (e) => {
|
|
514
|
-
e.stopPropagation(), this._clearAllSelectedFilters();
|
|
515
|
-
}), e.appendChild(t);
|
|
516
|
-
};
|
|
517
|
-
e(this._desktopFilterWrap), e(this._mobileFilterWrap);
|
|
518
|
-
let t = this._hasSelectedFilters();
|
|
519
|
-
this._desktopInput?.classList.toggle("has-selected-filter", t), this._panelInput?.classList.toggle("has-selected-filter", t), this._syncSelectedFilterInputOffset(this._desktopInput, this._desktopFilterWrap), this._syncSelectedFilterInputOffset(this._panelInput, this._mobileFilterWrap);
|
|
520
|
-
}
|
|
521
|
-
_syncSelectedFilterInputOffset(e, t) {
|
|
522
|
-
if (!e || !t) return;
|
|
523
|
-
let n = t.querySelector("mint-chip");
|
|
524
|
-
if (!n) {
|
|
525
|
-
e.style.removeProperty("--mint-search-filter-chip-width");
|
|
526
|
-
return;
|
|
527
|
-
}
|
|
528
|
-
let r = () => {
|
|
529
|
-
n.isConnected && e.style.setProperty("--mint-search-filter-chip-width", `${n.getBoundingClientRect().width}px`);
|
|
530
|
-
};
|
|
531
|
-
r(), requestAnimationFrame(r);
|
|
532
|
-
}
|
|
533
493
|
_bindInputHandlers(e) {
|
|
534
494
|
let t = () => {
|
|
535
495
|
this._scheduleSearch(this._getNativeInputValue(e));
|
|
@@ -545,13 +505,7 @@ var t = class e extends HTMLElement {
|
|
|
545
505
|
}
|
|
546
506
|
if (t.key !== "Backspace") return;
|
|
547
507
|
let n = this._getNativeInputValue(e);
|
|
548
|
-
|
|
549
|
-
if (!this._selectedFilterBackspaceArmed) {
|
|
550
|
-
t.preventDefault(), this._selectedFilterBackspaceArmed = !0, this._renderSelectedFilter();
|
|
551
|
-
return;
|
|
552
|
-
}
|
|
553
|
-
t.preventDefault(), this._popLastSelectedFilter();
|
|
554
|
-
}
|
|
508
|
+
n !== this._query && this._setQuery(n), !(n.length > 0) && this._hasSelectedFilters() && (t.preventDefault(), this._popLastSelectedFilter());
|
|
555
509
|
});
|
|
556
510
|
}
|
|
557
511
|
openSearch(e = !0) {
|
|
@@ -577,19 +531,19 @@ var t = class e extends HTMLElement {
|
|
|
577
531
|
return;
|
|
578
532
|
}
|
|
579
533
|
if (!this._shell) {
|
|
580
|
-
this._shell = document.createElement("div"), this._shell.className = "mint-search-shell", this.
|
|
534
|
+
this._shell = document.createElement("div"), this._shell.className = "mint-search-shell", this._desktopInput = document.createElement("mint-input"), this._desktopInput.setAttribute("type", "search"), this._desktopInput.setAttribute("icon", "search"), this._desktopInput.setAttribute("aria-label", this.getAttribute("placeholder") || "Search"), this._desktopInput.className = "mint-search-input";
|
|
581
535
|
let e = document.createElement("span");
|
|
582
|
-
e.className = "mint-search-shortcut-hint", e.setAttribute("
|
|
536
|
+
e.className = "mint-search-shortcut-hint", e.setAttribute("aria-hidden", "true"), this._desktopShortcutHint = e, this._bindInputHandlers(this._desktopInput), this._shell.appendChild(this._desktopInput), this._shell.appendChild(e), this.appendChild(this._shell);
|
|
583
537
|
}
|
|
584
538
|
if (!this._panel) {
|
|
585
539
|
this._panel = document.createElement("div"), this._panel.className = "mint-search-panel is-hidden";
|
|
586
540
|
let e = document.createElement("div");
|
|
587
541
|
e.className = "mint-search-panel-inner", this._panelInner = e;
|
|
588
542
|
let t = document.createElement("div");
|
|
589
|
-
this._panelSearchBar = t, t.className = "mint-search-panel-searchbar is-hidden", this.
|
|
543
|
+
this._panelSearchBar = t, t.className = "mint-search-panel-searchbar is-hidden", this._panelInput = document.createElement("mint-input"), this._panelInput.setAttribute("type", "search"), this._panelInput.setAttribute("icon", "search"), this._panelInput.setAttribute("aria-label", this.getAttribute("placeholder") || "Search"), this._panelInput.className = "mint-search-input", this._bindInputHandlers(this._panelInput), t.appendChild(this._panelInput), this._customResultsWrap = document.createElement("div"), this._customResultsWrap.className = "mint-search-custom-results is-hidden", this._stateWrap = document.createElement("div"), this._stateWrap.className = "mint-search-state", this._stateWrap.textContent = "Start typing to search", this._stateWrap.setAttribute("role", "status"), this._stateWrap.setAttribute("aria-live", "polite"), this._resultsWrap = document.createElement("div"), this._resultsWrap.className = "mint-search-results", this._resultsId = `mint-search-results-${Math.random().toString(36).slice(2, 10)}`, this._resultsWrap.id = this._resultsId, this._resultsWrap.setAttribute("role", "listbox"), this._resultsWrap.setAttribute("aria-label", "Search results"), this._customResultsWrap.setAttribute("role", "region"), this._customResultsWrap.setAttribute("aria-label", "Search results"), e.appendChild(t), this._panelFiltersWrap = document.createElement("div"), e.appendChild(this._panelFiltersWrap), this._ensurePanelFiltersShell(), e.appendChild(this._customResultsWrap), e.appendChild(this._stateWrap), e.appendChild(this._resultsWrap), this._panel.appendChild(e);
|
|
590
544
|
}
|
|
591
545
|
this._panel.parentElement !== document.body && document.body.appendChild(this._panel);
|
|
592
|
-
let t = this.
|
|
546
|
+
let t = this._getPlaceholder();
|
|
593
547
|
if (this._desktopInput && this._desktopInput.setAttribute("placeholder", t), this._panelInput && this._panelInput.setAttribute("placeholder", t), this._desktopInput && this._desktopInput.setAttribute("aria-label", this.getAttribute("aria-label") || this._getPlaceholder()), this._panelInput && this._panelInput.setAttribute("aria-label", this.getAttribute("aria-label") || this._getPlaceholder()), this._desktopShortcutHint) {
|
|
594
548
|
let e = this._getOpenShortcutHintText();
|
|
595
549
|
this._desktopShortcutHint.textContent = e, this._desktopShortcutHint.classList.toggle("is-hidden", !e);
|
|
@@ -616,9 +570,9 @@ var t = class e extends HTMLElement {
|
|
|
616
570
|
let a = (n) => {
|
|
617
571
|
n && n.stopPropagation();
|
|
618
572
|
let r = this._filtersMoreOpen, i = this._selectedFilters.indexOf(t);
|
|
619
|
-
i >= 0 ? this._selectedFilters.splice(i, 1) : this._selectedFilters.push(t)
|
|
573
|
+
i >= 0 ? this._selectedFilters.splice(i, 1) : this._selectedFilters.push(t);
|
|
620
574
|
let a = e.length > 0 && this._selectedFilters.length === e.length, o = this._selectedFilters.length === 0;
|
|
621
|
-
r && (a || o) && (this._filtersMoreOpen = !1), this._emitFilterChange(), this.
|
|
575
|
+
r && (a || o) && (this._filtersMoreOpen = !1), this._emitFilterChange(), this.render(), this._query.trim() && this._scheduleSearch(this._query), r ? a || o ? this._focusActiveInput() : requestAnimationFrame(() => {
|
|
622
576
|
this._getFilterChipElements().find((e) => e.dataset.mintSearchFilter === t)?.focus();
|
|
623
577
|
}) : this._focusActiveInput();
|
|
624
578
|
};
|
|
@@ -657,7 +611,7 @@ var t = class e extends HTMLElement {
|
|
|
657
611
|
let e = this._customResultsWrap.childElementCount > 0;
|
|
658
612
|
this._customResultsWrap.classList.toggle("is-hidden", !e), e ? (this._stateWrap?.classList.add("is-hidden"), this._resultsWrap?.classList.add("is-hidden")) : this._resultsWrap?.classList.remove("is-hidden");
|
|
659
613
|
}
|
|
660
|
-
this.
|
|
614
|
+
this._syncResponsiveChrome(), this._syncPanelVisibility();
|
|
661
615
|
}
|
|
662
616
|
_syncResponsiveChrome() {
|
|
663
617
|
let e = this._collapseOnMobile();
|