1// @ts-ignore 2function _assert_this_initialized(self) { 3 if (self === void 0) { 4 throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); 5 } 6 return self; 7} 8function _class_call_check(instance, Constructor) { 9 if (!(instance instanceof Constructor)) { 10 throw new TypeError("Cannot call a class as a function"); 11 } 12} 13function _defineProperties(target, props) { 14 for(var i = 0; i < props.length; i++){ 15 var descriptor = props[i]; 16 descriptor.enumerable = descriptor.enumerable || false; 17 descriptor.configurable = true; 18 if ("value" in descriptor) descriptor.writable = true; 19 Object.defineProperty(target, descriptor.key, descriptor); 20 } 21} 22function _create_class(Constructor, protoProps, staticProps) { 23 if (protoProps) _defineProperties(Constructor.prototype, protoProps); 24 if (staticProps) _defineProperties(Constructor, staticProps); 25 return Constructor; 26} 27function _define_property(obj, key, value) { 28 if (key in obj) { 29 Object.defineProperty(obj, key, { 30 value: value, 31 enumerable: true, 32 configurable: true, 33 writable: true 34 }); 35 } else { 36 obj[key] = value; 37 } 38 return obj; 39} 40function _get_prototype_of(o) { 41 _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) { 42 return o.__proto__ || Object.getPrototypeOf(o); 43 }; 44 return _get_prototype_of(o); 45} 46function _inherits(subClass, superClass) { 47 if (typeof superClass !== "function" && superClass !== null) { 48 throw new TypeError("Super expression must either be null or a function"); 49 } 50 subClass.prototype = Object.create(superClass && superClass.prototype, { 51 constructor: { 52 value: subClass, 53 writable: true, 54 configurable: true 55 } 56 }); 57 if (superClass) _set_prototype_of(subClass, superClass); 58} 59function _possible_constructor_return(self, call) { 60 if (call && (_type_of(call) === "object" || typeof call === "function")) { 61 return call; 62 } 63 return _assert_this_initialized(self); 64} 65function _set_prototype_of(o, p) { 66 _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) { 67 o.__proto__ = p; 68 return o; 69 }; 70 return _set_prototype_of(o, p); 71} 72function _type_of(obj) { 73 "@swc/helpers - typeof"; 74 return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; 75} 76function _is_native_reflect_construct() { 77 if (typeof Reflect === "undefined" || !Reflect.construct) return false; 78 if (Reflect.construct.sham) return false; 79 if (typeof Proxy === "function") return true; 80 try { 81 Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {})); 82 return true; 83 } catch (e) { 84 return false; 85 } 86} 87function _create_super(Derived) { 88 var hasNativeReflectConstruct = _is_native_reflect_construct(); 89 return function _createSuperInternal() { 90 var Super = _get_prototype_of(Derived), result; 91 if (hasNativeReflectConstruct) { 92 var NewTarget = _get_prototype_of(this).constructor; 93 result = Reflect.construct(Super, arguments, NewTarget); 94 } else { 95 result = Super.apply(this, arguments); 96 } 97 return _possible_constructor_return(this, result); 98 }; 99} 100import { Controller } from "@hotwired/stimulus"; 101// @ts-ignore 102import { useClickOutside } from "stimulus-use"; 103// @ts-ignore 104import { setsEqual } from "./utils.js"; 105var _class = /*#__PURE__*/ function(Controller) { 106 "use strict"; 107 _inherits(_class, Controller); 108 var _super = _create_super(_class); 109 function _class() { 110 _class_call_check(this, _class); 111 var _this; 112 _this = _super.apply(this, arguments); 113 _define_property(_assert_this_initialized(_this), "opened", false); 114 _define_property(_assert_this_initialized(_this), "anchor", null); 115 _define_property(_assert_this_initialized(_this), "draft", new Set()); 116 _define_property(_assert_this_initialized(_this), "initial", new Set()); 117 _define_property(_assert_this_initialized(_this), "modalName", void 0); 118 _define_property(_assert_this_initialized(_this), "onKeydown", function(event) { 119 if (!_this.opened) return; 120 if (event.key !== "Escape") return; 121 event.preventDefault(); 122 _this.close(); 123 }); 124 return _this; 125 } 126 _create_class(_class, [ 127 { 128 key: "isOpen", 129 value: function isOpen() { 130 return this.opened; 131 } 132 }, 133 { 134 key: "open", 135 value: function open(anchor) { 136 if (this.opened) return; 137 this.doOpen(anchor); 138 } 139 }, 140 { 141 key: "close", 142 value: function close() { 143 if (!this.opened) return; 144 this.doClose(); 145 } 146 }, 147 { 148 key: "connect", 149 value: function connect() { 150 this.modalName = this.nameValue; 151 useClickOutside(this, { 152 element: this.element, 153 dispatchEvent: false 154 }); 155 document.addEventListener("keydown", this.onKeydown); 156 this.element.hidden = true; 157 } 158 }, 159 { 160 key: "disconnect", 161 value: function disconnect() { 162 document.removeEventListener("keydown", this.onKeydown); 163 } 164 }, 165 { 166 key: "doOpen", 167 value: function doOpen(anchor) { 168 var _this = this; 169 this.anchor = anchor; 170 var selected = this.getGroupInputs().filter(function(i) { 171 return i.checked; 172 }).map(function(i) { 173 return i.id; 174 }); 175 this.initial = new Set(selected); 176 this.draft = new Set(selected); 177 this.element.hidden = false;
178 this.opened = true; 179 this.element.dataset.ignoreOutside = "1"; 180 requestAnimationFrame(function() { 181 var _this_searchInputTarget_focus, _this_searchInputTarget; 182 delete _this.element.dataset.ignoreOutside; 183 (_this_searchInputTarget = _this.searchInputTarget) === null || _this_searchInputTarget === void 0 ? void 0 : (_this_searchInputTarget_focus = _this_searchInputTarget.focus) === null || _this_searchInputTarget_focus === void 0 ? void 0 : _this_searchInputTarget_focus.call(_this_searchInputTarget, { 184 preventScroll: true 185 }); 186 }); 187 this.syncLabelsFromDraft(); 188 this.resetSearch(); 189 this.updateFooter(); 190 if (this.hasMainPageOutlet && this.mainPageOutlet.notifyFiltersModalOpen) { 191 this.mainPageOutlet.notifyFiltersModalOpen(this.modalName); 192 } 193 } 194 }, 195 { 196 key: "doClose", 197 value: function doClose() { 198 this.element.hidden = true; 199 this.opened = false; 200 this.anchor = null; 201 if (this.hasMainPageOutlet && this.mainPageOutlet.notifyFiltersModalClose) { 202 this.mainPageOutlet.notifyFiltersModalClose(); 203 } 204 } 205 }, 206 { 207 key: "closeWithoutApply", 208 value: function closeWithoutApply(event) { 209 event.preventDefault(); 210 event.stopPropagation(); 211 this.close(); 212 } 213 }, 214 { 215 key: "clickOutside", 216 value: function clickOutside(event) { 217 var _this_anchor; 218 if (!this.opened) return; 219 if (this.element.dataset.ignoreOutside === "1") return; 220 var _event_target; 221 var target = (_event_target = event === null || event === void 0 ? void 0 : event.target) !== null && _event_target !== void 0 ? _event_target : null; 222 if (!target) return; 223 if ((_this_anchor = this.anchor) === null || _this_anchor === void 0 ? void 0 : _this_anchor.contains(target)) return; 224 this.close(); 225 } 226 }, 227 { 228 key: "onLabelClick", 229 value: function onLabelClick(event) { 230 event.preventDefault(); 231 var label = event.currentTarget; 232 var inputId = label.htmlFor; 233 if (!inputId) return; 234 if (this.draft.has(inputId)) this.draft.delete(inputId); 235 else this.draft.add(inputId); 236 label.classList.toggle("is-checked", this.draft.has(inputId)); 237 this.updateFooter(); 238 } 239 }, 240 { 241 key: "clear", 242 value: function clear() { 243 this.draft.clear(); 244 this.syncLabelsFromDraft(); 245 this.updateFooter(); 246 } 247 }, 248 { 249 key: "apply", 250 value: function apply() { 251 var _this_mainFiltersOutlet_applyModalSelection, _this_mainFiltersOutlet; 252 (_this_mainFiltersOutlet = this.mainFiltersOutlet) === null || _this_mainFiltersOutlet === void 0 ? void 0 : (_this_mainFiltersOutlet_applyModalSelection = _this_mainFiltersOutlet.applyModalSelection) === null || _this_mainFiltersOutlet_applyModalSelection === void 0 ? void 0 : _this_mainFiltersOutlet_applyModalSelection.call(_this_mainFiltersOutlet, this.modalName, Array.from(this.draft)); 253 this.close(); 254 } 255 }, 256 { 257 key: "onSearch", 258 value: function onSearch() { 259 var q = this.searchInputTarget.value.trim().toLowerCase(); 260 this.element.classList.toggle("filters-modal--searching", q.length > 0); 261 var visibleLetters = new Set(); 262 this.itemTargets.forEach(function(itemEl) { 263 var el = itemEl; 264 var _el_dataset_label; 265 var label = ((_el_dataset_label = el.dataset.label) !== null && _el_dataset_label !== void 0 ? _el_dataset_label : "").toLowerCase(); 266 var isVisible = q ? label.includes(q) : true; 267 el.hidden = !isVisible; 268 var letter = el.dataset.letter; 269 if (letter && isVisible) visibleLetters.add(letter); 270 });
271 this.groupTargets.forEach(function(groupEl0) { 272 var groupEl = groupEl0; 273 var letter = groupEl.dataset.letter; 274 groupEl.hidden = !letter || !visibleLetters.has(letter); 275 }); 276 } 277 }, 278 { 279 key: "resetSearch", 280 value: function resetSearch() { 281 this.searchInputTarget.value = ""; 282 this.element.classList.remove("filters-modal--searching"); 283 this.itemTargets.forEach(function(itemEl) { 284 var el = itemEl; 285 el.hidden = false; 286 }); 287 this.groupTargets.forEach(function(groupEl0) { 288 var groupEl = groupEl0; 289 groupEl.hidden = false; 290 }); 291 } 292 }, 293 { 294 key: "updateFooter", 295 value: function updateFooter() { 296 var count = this.draft.size; 297 var dirty = !setsEqual(this.draft, this.initial); 298 var showFooter = this.initial.size > 0 || dirty; 299 this.footerTarget.hidden = !showFooter; 300 var labelEl = this.applyBtnTarget.querySelector(".filters-modal__apply-label"); 301 var countEl = this.applyBtnTarget.querySelector(".filters-modal__apply-count"); 302 if (!labelEl || !countEl) { 303 this.applyBtnTarget.textContent = ""; 304 labelEl = document.createElement("span"); 305 labelEl.className = "filters-modal__apply-label"; 306 countEl = document.createElement("span"); 307 countEl.className = "filters-modal__apply-count"; 308 this.applyBtnTarget.append(labelEl, countEl); 309 } 310 labelEl.textContent = this.applyLabelValue; 311 countEl.textContent = count > 0 ? String(count) : ""; 312 countEl.hidden = count === 0; 313 this.clearBtnTarget.disabled = count === 0; 314 } 315 }, 316 { 317 key: "syncLabelsFromDraft", 318 value: function syncLabelsFromDraft() { 319 var set = this.draft; 320 this.element.querySelectorAll("label[for]").forEach(function(lbl) { 321 var id = lbl.htmlFor; 322 if (!id) return; 323 lbl.classList.toggle("is-checked", set.has(id)); 324 }); 325 } 326 }, 327 { 328 key: "getGroupInputs", 329 value: function getGroupInputs() { 330 if (!this.hasMainFiltersOutlet) return []; 331 return Array.from(this.mainFiltersOutlet.formTarget.querySelectorAll('input[type="checkbox"][data-group="'.concat(this.modalName, '"]'))); 332 } 333 } 334 ]); 335 return _class; 336}(Controller); 337_define_property(_class, "targets", [ 338 "searchInput", 339 "item", 340 "group", 341 "footer", 342 "applyBtn", 343 "clearBtn" 344]); 345_define_property(_class, "values", { 346 name: String, 347 applyLabel: String 348}); 349_define_property(_class, "outlets", [ 350 "main-filters", 351 "main-page" 352]); 353/* stimulusFetch: 'lazy' */ export { _class as default };
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.