adwaveui
Version:
Interactive Web Components inspired by the Gtk Adwaita theme.
747 lines (745 loc) • 30.8 kB
JavaScript
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
// src/components/selector/selector.tsx
import { jsx as _jsx, jsxs as _jsxs } from "jsxte/jsx-runtime";
import { Selector } from "adwavecss";
import { Attribute, CustomElement, ElementLifecycleEvent, Slotted, State, WcSlot } from "jsxte-wc";
import { BaseElement } from "../../base-elements.mjs";
import "../../index.style.mjs";
import { cls } from "../../utils/cls.mjs";
import { CustomKeyboardEvent, CustomMouseEvent } from "../../utils/events.mjs";
import { getUid } from "../../utils/get-uid.mjs";
import { stopEvent } from "../../utils/prevent-default.mjs";
import "./selector.style.mjs";
var __esDecorate = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
function accept(f) {
if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected");
return f;
}
__name(accept, "accept");
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
var _, done = false;
for (var i = decorators.length - 1; i >= 0; i--) {
var context = {};
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
context.addInitializer = function(f) {
if (done) throw new TypeError("Cannot add initializers after decoration has completed");
extraInitializers.push(accept(f || null));
};
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
if (kind === "accessor") {
if (result === void 0) continue;
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
if (_ = accept(result.get)) descriptor.get = _;
if (_ = accept(result.set)) descriptor.set = _;
if (_ = accept(result.init)) initializers.unshift(_);
} else if (_ = accept(result)) {
if (kind === "field") initializers.unshift(_);
else descriptor[key] = _;
}
}
if (target) Object.defineProperty(target, contextIn.name, descriptor);
done = true;
};
var __runInitializers = function(thisArg, initializers, value) {
var useValue = arguments.length > 2;
for (var i = 0; i < initializers.length; i++) {
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
}
return useValue ? value : void 0;
};
var IS_MOBILE = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
var SEARCHABLE_CHARS = `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+=-[]\\{}|;':",./<>?`.split("");
var FOCUS_CHANGE_EVENT_THROTTLE = 60;
var SelectorChangeEvent = class extends CustomEvent {
static {
__name(this, "SelectorChangeEvent");
}
constructor(value) {
super("change", {
detail: {
value
}
});
}
};
var ADWaveSelector = (() => {
let _classDecorators = [CustomElement("adw-selector")];
let _classDescriptor;
let _classExtraInitializers = [];
let _classThis;
let _classSuper = BaseElement;
let _placeholder_decorators;
let _placeholder_initializers = [];
let _placeholder_extraInitializers = [];
let _disabled_decorators;
let _disabled_initializers = [];
let _disabled_extraInitializers = [];
let _name_decorators;
let _name_initializers = [];
let _name_extraInitializers = [];
let _form_decorators;
let _form_initializers = [];
let _form_extraInitializers = [];
let _orientation_decorators;
let _orientation_initializers = [];
let _orientation_extraInitializers = [];
let _reverseorder_decorators;
let _reverseorder_initializers = [];
let _reverseorder_extraInitializers = [];
let _value_decorators;
let _value_initializers = [];
let _value_extraInitializers = [];
let _isOpen_decorators;
let _isOpen_initializers = [];
let _isOpen_extraInitializers = [];
let _options_decorators;
let _options_initializers = [];
let _options_extraInitializers = [];
var ADWaveSelector2 = class extends _classSuper {
static {
__name(this, "ADWaveSelector");
}
static {
_classThis = this;
}
static {
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
_placeholder_decorators = [Attribute({ nullable: true })];
_disabled_decorators = [Attribute({ type: "boolean", nullable: false, default: false })];
_name_decorators = [Attribute({ nullable: true })];
_form_decorators = [Attribute({ nullable: true })];
_orientation_decorators = [Attribute({ nullable: false, default: "down" })];
_reverseorder_decorators = [Attribute({ type: "boolean", nullable: false, default: false })];
_value_decorators = [Attribute({ nullable: true })];
_isOpen_decorators = [State()];
_options_decorators = [Slotted({ filter: "adw-option" })];
__esDecorate(this, null, _placeholder_decorators, { kind: "accessor", name: "placeholder", static: false, private: false, access: { has: /* @__PURE__ */ __name((obj) => "placeholder" in obj, "has"), get: /* @__PURE__ */ __name((obj) => obj.placeholder, "get"), set: /* @__PURE__ */ __name((obj, value) => {
obj.placeholder = value;
}, "set") }, metadata: _metadata }, _placeholder_initializers, _placeholder_extraInitializers);
__esDecorate(this, null, _disabled_decorators, { kind: "accessor", name: "disabled", static: false, private: false, access: { has: /* @__PURE__ */ __name((obj) => "disabled" in obj, "has"), get: /* @__PURE__ */ __name((obj) => obj.disabled, "get"), set: /* @__PURE__ */ __name((obj, value) => {
obj.disabled = value;
}, "set") }, metadata: _metadata }, _disabled_initializers, _disabled_extraInitializers);
__esDecorate(this, null, _name_decorators, { kind: "accessor", name: "name", static: false, private: false, access: { has: /* @__PURE__ */ __name((obj) => "name" in obj, "has"), get: /* @__PURE__ */ __name((obj) => obj.name, "get"), set: /* @__PURE__ */ __name((obj, value) => {
obj.name = value;
}, "set") }, metadata: _metadata }, _name_initializers, _name_extraInitializers);
__esDecorate(this, null, _form_decorators, { kind: "accessor", name: "form", static: false, private: false, access: { has: /* @__PURE__ */ __name((obj) => "form" in obj, "has"), get: /* @__PURE__ */ __name((obj) => obj.form, "get"), set: /* @__PURE__ */ __name((obj, value) => {
obj.form = value;
}, "set") }, metadata: _metadata }, _form_initializers, _form_extraInitializers);
__esDecorate(this, null, _orientation_decorators, { kind: "accessor", name: "orientation", static: false, private: false, access: { has: /* @__PURE__ */ __name((obj) => "orientation" in obj, "has"), get: /* @__PURE__ */ __name((obj) => obj.orientation, "get"), set: /* @__PURE__ */ __name((obj, value) => {
obj.orientation = value;
}, "set") }, metadata: _metadata }, _orientation_initializers, _orientation_extraInitializers);
__esDecorate(this, null, _reverseorder_decorators, { kind: "accessor", name: "reverseorder", static: false, private: false, access: { has: /* @__PURE__ */ __name((obj) => "reverseorder" in obj, "has"), get: /* @__PURE__ */ __name((obj) => obj.reverseorder, "get"), set: /* @__PURE__ */ __name((obj, value) => {
obj.reverseorder = value;
}, "set") }, metadata: _metadata }, _reverseorder_initializers, _reverseorder_extraInitializers);
__esDecorate(this, null, _value_decorators, { kind: "accessor", name: "value", static: false, private: false, access: { has: /* @__PURE__ */ __name((obj) => "value" in obj, "has"), get: /* @__PURE__ */ __name((obj) => obj.value, "get"), set: /* @__PURE__ */ __name((obj, value) => {
obj.value = value;
}, "set") }, metadata: _metadata }, _value_initializers, _value_extraInitializers);
__esDecorate(this, null, _isOpen_decorators, { kind: "accessor", name: "isOpen", static: false, private: false, access: { has: /* @__PURE__ */ __name((obj) => "isOpen" in obj, "has"), get: /* @__PURE__ */ __name((obj) => obj.isOpen, "get"), set: /* @__PURE__ */ __name((obj, value) => {
obj.isOpen = value;
}, "set") }, metadata: _metadata }, _isOpen_initializers, _isOpen_extraInitializers);
__esDecorate(this, null, _options_decorators, { kind: "accessor", name: "options", static: false, private: false, access: { has: /* @__PURE__ */ __name((obj) => "options" in obj, "has"), get: /* @__PURE__ */ __name((obj) => obj.options, "get"), set: /* @__PURE__ */ __name((obj, value) => {
obj.options = value;
}, "set") }, metadata: _metadata }, _options_initializers, _options_extraInitializers);
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
ADWaveSelector2 = _classThis = _classDescriptor.value;
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
__runInitializers(_classThis, _classExtraInitializers);
}
#placeholder_accessor_storage;
get placeholder() {
return this.#placeholder_accessor_storage;
}
set placeholder(value) {
this.#placeholder_accessor_storage = value;
}
#disabled_accessor_storage;
get disabled() {
return this.#disabled_accessor_storage;
}
set disabled(value) {
this.#disabled_accessor_storage = value;
}
#name_accessor_storage;
get name() {
return this.#name_accessor_storage;
}
set name(value) {
this.#name_accessor_storage = value;
}
#form_accessor_storage;
get form() {
return this.#form_accessor_storage;
}
set form(value) {
this.#form_accessor_storage = value;
}
#orientation_accessor_storage;
get orientation() {
return this.#orientation_accessor_storage;
}
set orientation(value) {
this.#orientation_accessor_storage = value;
}
#reverseorder_accessor_storage;
get reverseorder() {
return this.#reverseorder_accessor_storage;
}
set reverseorder(value) {
this.#reverseorder_accessor_storage = value;
}
#value_accessor_storage;
get value() {
return this.#value_accessor_storage;
}
set value(value) {
this.#value_accessor_storage = value;
}
#isOpen_accessor_storage;
get isOpen() {
return this.#isOpen_accessor_storage;
}
set isOpen(value) {
this.#isOpen_accessor_storage = value;
}
#options_accessor_storage;
get options() {
return this.#options_accessor_storage;
}
set options(value) {
this.#options_accessor_storage = value;
}
constructor() {
super();
this.#placeholder_accessor_storage = __runInitializers(this, _placeholder_initializers, null);
this.#disabled_accessor_storage = (__runInitializers(this, _placeholder_extraInitializers), __runInitializers(this, _disabled_initializers, false));
this.#name_accessor_storage = (__runInitializers(this, _disabled_extraInitializers), __runInitializers(this, _name_initializers, null));
this.#form_accessor_storage = (__runInitializers(this, _name_extraInitializers), __runInitializers(this, _form_initializers, null));
this.#orientation_accessor_storage = (__runInitializers(this, _form_extraInitializers), __runInitializers(this, _orientation_initializers, "down"));
this.#reverseorder_accessor_storage = (__runInitializers(this, _orientation_extraInitializers), __runInitializers(this, _reverseorder_initializers, false));
this.#value_accessor_storage = (__runInitializers(this, _reverseorder_extraInitializers), __runInitializers(this, _value_initializers, null));
this.#isOpen_accessor_storage = (__runInitializers(this, _value_extraInitializers), __runInitializers(this, _isOpen_initializers, false));
this.#options_accessor_storage = (__runInitializers(this, _isOpen_extraInitializers), __runInitializers(this, _options_initializers, []));
this.selectableOptions = (__runInitializers(this, _options_extraInitializers), []);
this.uid = getUid();
this.dialogElem = { current: null };
this.optionsListElem = { current: null };
this.searchInputMemory = "";
this.handleClick = (e) => {
e.preventDefault();
e.stopPropagation();
const shouldContinue = this.dispatchEvent(new CustomMouseEvent("click", {
type: "selector"
}, e));
if (!shouldContinue || this.disabled) {
return;
}
this.toggleOpen();
};
this.handleDialogClick = (e) => {
e.preventDefault();
e.stopPropagation();
const dialog = this.dialogElem.current;
const shouldContinue = this.dispatchEvent(new CustomMouseEvent("click", {
type: "dialog"
}, e));
if (this.isOpen && dialog && shouldContinue) {
if (!this.optionsListElem.current?.contains(e.target)) {
dialog.close();
this.isOpen = false;
}
}
};
this.handleOptionClick = (e) => {
e.preventDefault();
e.stopPropagation();
const btn = e.target;
const { option: optValue } = btn?.dataset ?? {};
const shouldContinue = this.dispatchEvent(new CustomMouseEvent("click", {
type: "option",
option: optValue
}, e));
if (!shouldContinue || this.disabled || optValue == null) {
return;
}
const success = this.select(optValue);
if (success) {
const dialog = this.dialogElem.current;
dialog?.close();
this.isOpen = false;
this.focusSelf();
}
};
this.handleModalCancel = (e) => {
this.isOpen = false;
};
this._lastFocusChange = 0;
this.handleKeyDown = (ev) => {
if (this.disabled) {
return;
}
switch (ev.key) {
case " ":
case "Enter": {
ev.preventDefault();
this.withCustomKeyEvent(ev, () => {
if (!this.isOpen) {
this.dialogElem.current?.showModal();
this.isOpen = true;
} else {
const target = ev.target;
if (target.tagName === "BUTTON") {
if (ev.key === "Enter")
target.click();
} else {
this.dialogElem.current?.close();
this.isOpen = false;
}
}
});
break;
}
case "ArrowUp": {
ev.preventDefault();
this.withFocusChangeEvent(() => {
this.withCustomKeyEvent(ev, () => {
this.focusOption(-1);
});
});
break;
}
case "ArrowDown": {
ev.preventDefault();
this.withFocusChangeEvent(() => {
this.withCustomKeyEvent(ev, () => {
this.focusOption(1);
});
});
break;
}
case "PageUp": {
ev.preventDefault();
this.withFocusChangeEvent(() => {
this.withCustomKeyEvent(ev, () => {
this.focusOption(-10);
});
});
break;
}
case "PageDown": {
ev.preventDefault();
this.withFocusChangeEvent(() => {
this.withCustomKeyEvent(ev, () => {
this.focusOption(10);
});
});
break;
}
case "Home": {
ev.preventDefault();
this.withFocusChangeEvent(() => {
this.withCustomKeyEvent(ev, () => {
this.focusOption(-this.selectableOptions.length);
});
});
break;
}
case "End": {
ev.preventDefault();
this.withFocusChangeEvent(() => {
this.withCustomKeyEvent(ev, () => {
this.focusOption(+this.selectableOptions.length);
});
});
break;
}
case "Escape": {
ev.preventDefault();
this.withCustomKeyEvent(ev, () => {
if (this.isOpen) {
this.isOpen = false;
this.focusSelf();
}
});
break;
}
default:
if (SEARCHABLE_CHARS.includes(ev.key)) {
this.searchInputMemory += ev.key;
window.clearTimeout(this.clearSearchInputMemoryTimeout);
this.clearSearchInputMemoryTimeout = window.setTimeout(() => {
this.searchInputMemory = "";
}, 1e3);
this.tryInputSearch();
}
break;
}
};
this.Option = (props) => {
const isSelected = props.option.isEqualTo(this.value);
const isInert = props.option.inert;
if (isInert) {
return _jsxs("button", { class: cls([{
[Selector.option]: true,
inert: true
}, props.option.className]), role: "presentation", onclick: stopEvent, children: [_jsx("span", {}), _jsx("span", { class: "opt-label", children: props.option.getLabel() }), _jsx("span", {})] });
}
return _jsx("button", { class: cls([{
[Selector.option]: true,
selected: isSelected
}, props.option.className]), onclick: this.handleOptionClick, "data-option": props.option.getValue(), role: "option", "aria-selected": isSelected, children: props.option.getLabel() });
};
this.OptionsListMobile = () => {
let options = this.options;
if (this.reverseorder) {
options = options.slice().reverse();
}
return _jsx("dialog", { ref: this.dialogElem, onclick: this.handleDialogClick, oncancel: this.handleModalCancel, children: _jsx("div", { id: this.uid, class: cls([Selector.optionsList, Selector.noPosition]), ref: this.optionsListElem, role: "listbox", children: options.map((option) => _jsx(this.Option, { option })) }) });
};
this.OptionsListDesktop = () => {
let options = this.options;
if (this.reverseorder) {
options = options.slice().reverse();
}
return _jsx("div", { id: this.uid, class: cls({
[Selector.optionsList]: true,
[Selector.top]: this.orientation === "up"
}), ref: this.optionsListElem, children: options.map((option) => _jsx(this.Option, { option })) });
};
this.HiddenSelect = () => {
return _jsx("select", { class: "_adw_hidden", name: this.name ?? void 0, form: this.form ?? void 0, disabled: this.disabled ?? void 0, "aria-hidden": "true", onchange: stopEvent, children: this.selectableOptions.map((option, index) => {
return _jsx("option", { value: option.getValue(), selected: option.isEqualTo(this.value) });
}) });
};
this.immediateEffect(() => {
this.updateSelectableOptions();
}, (s) => [s.options]);
this.effect(() => {
if (this.isOpen) {
const optionsList = this.optionsListElem.current;
if (optionsList) {
const reverse = this.orientation === "up";
if (this.value != null) {
this.scrollToOption(this.value);
} else {
optionsList.scrollTo({
top: reverse ? optionsList.scrollHeight : 0,
behavior: "instant"
});
}
}
if (!IS_MOBILE) {
const eventHandler = /* @__PURE__ */ __name((event) => {
if (!this.contains(event.target)) {
this.isOpen = false;
this.dialogElem.current?.close();
}
}, "eventHandler");
document.addEventListener("click", eventHandler);
return () => {
document.removeEventListener("click", eventHandler);
};
}
}
}, (s) => [s.isOpen]);
this.effect(() => {
const firstSelected = this.selectableOptions.find((opt) => opt.isSelected());
if (firstSelected) {
this.value = firstSelected.getValue();
for (let j = 0; j < this.selectableOptions.length; j++) {
const slot = this.selectableOptions[j];
if (slot !== firstSelected) {
slot.setSelected(false);
}
}
}
}, () => []);
this.lifecycle.on(ElementLifecycleEvent.SlotDidChange, (c) => {
if (c.detail.slotName === "options") {
let hasChanged = false;
const addedSlots = c.detail.changes.added;
const removedSlots = c.detail.changes.removed;
const changedSlots = c.detail.changes.attributeChanged;
for (let i = 0; i < removedSlots.length; i++) {
const slot = removedSlots[i];
if (slot.isSelected()) {
hasChanged = true;
this.value = null;
}
}
for (let i = 0; i < changedSlots.length; i++) {
const slot = changedSlots[i];
if (slot.isSelected()) {
const newValue = slot.getValue();
hasChanged = this.value !== newValue;
this.value = newValue;
for (let j = 0; j < this.selectableOptions.length; j++) {
const otherSlot = this.selectableOptions[j];
if (otherSlot !== slot) {
otherSlot.setSelected(false);
}
}
break;
}
}
for (let i = 0; i < addedSlots.length; i++) {
const slot = addedSlots[i];
if (slot.isSelected()) {
const newValue = slot.getValue();
hasChanged = this.value !== newValue;
this.value = newValue;
for (let j = 0; j < this.options.length; j++) {
const otherSlot = this.options[j];
if (otherSlot !== slot) {
otherSlot.setSelected(false);
}
}
break;
}
}
this.updateSelectableOptions();
if (hasChanged) {
this.dispatchEvent(new SelectorChangeEvent(this.value));
}
}
});
}
toggleOpen() {
if (!this.isOpen) {
this.dialogElem.current?.showModal();
this.isOpen = true;
} else {
this.dialogElem.current?.close();
this.isOpen = false;
}
}
updateSelectableOptions() {
const selectedBefore = this.selectableOptions.find((o) => o.isSelected());
this.selectableOptions = [];
for (let i = 0; i < this.options.length; i++) {
const option = this.options[i];
if (!option.inert) {
this.selectableOptions.push(option);
}
}
if (selectedBefore) {
const selectedAfter = this.selectableOptions.find((o) => o.isEqualTo(selectedBefore.getValue()));
if (selectedAfter) {
selectedBefore.setSelected(true);
} else {
this.value = null;
}
}
}
tryInputSearch() {
if (this.searchInputMemory.length === 0)
return;
const searchTerm = this.searchInputMemory.toLowerCase();
let foundOpt = this.selectableOptions.find((opt) => {
const label = opt.getLabel().toLowerCase();
return label.startsWith(searchTerm);
});
if (!foundOpt) {
this.selectableOptions.find((opt) => {
const label = opt.getLabel().toLowerCase();
return label.includes(searchTerm);
});
}
if (foundOpt) {
this.scrollToOption(foundOpt?.getValue(), "smooth");
}
}
scrollToOption(value, behavior = "instant") {
const optionsList = this.optionsListElem.current;
if (!optionsList) {
return;
}
const allOptElems = Array.from(optionsList.querySelectorAll("button.option"));
const activeOptionElem = allOptElems.find((btn) => btn.dataset.option === value);
if (activeOptionElem) {
const optionsList2 = this.optionsListElem.current;
optionsList2?.scrollTo({
top: activeOptionElem.offsetTop - optionsList2.clientHeight / 2,
behavior
});
activeOptionElem.focus();
}
}
focusSelf() {
this.querySelector(`.${Selector.selector}`)?.focus();
}
/**
* Selects the option that is offset from the currently focused
* option. (e.g. focusOption(1) should select the option following
* the currently focused one whereas focusOption(-2) should select
* the second option that's behind the focused option)
*/
focusOption(offset) {
const options = this.optionsListElem.current;
if (!options) {
return;
}
let currentOption = options.querySelector(`.${Selector.option}:focus`);
if (!currentOption) {
currentOption = options.querySelector(`.${Selector.option}.selected`);
}
if (!currentOption) {
const reverse = this.orientation === "up";
const firstOption = options.querySelector(reverse ? `.${Selector.option}:nth-last-child(1 of :not(.inert))` : `.${Selector.option}:nth-child(1 of :not(.inert))`);
firstOption?.focus();
return;
}
let target = currentOption;
const direction = offset > 0 ? "nextElementSibling" : "previousElementSibling";
mainloop: for (let i = 0; i < Math.abs(offset); i++) {
let next = target[direction];
if (!next) {
break;
}
while (next.classList.contains("inert")) {
next = next[direction];
if (!next) {
break mainloop;
}
}
target = next;
}
if (target) {
target.focus();
}
}
select(optionValue) {
if (optionValue == null) {
return false;
}
let success = false;
for (let i = 0; i < this.selectableOptions.length; i++) {
const option = this.selectableOptions[i];
const isSelected = option.isEqualTo(optionValue);
if (isSelected) {
option.setSelected(true);
success = true;
}
}
return success;
}
withCustomKeyEvent(ev, cb, onCancel) {
ev.stopPropagation();
const shouldContinue = this.dispatchEvent(new CustomKeyboardEvent("keydown", {}, ev));
if (shouldContinue) {
cb();
} else if (onCancel) {
onCancel();
}
}
withFocusChangeEvent(handler) {
const now = Date.now();
if (now - this._lastFocusChange > FOCUS_CHANGE_EVENT_THROTTLE) {
this._lastFocusChange = now;
handler();
}
}
getSelectedOption() {
return this.selectableOptions.find((option) => option.isEqualTo(this.value));
}
render() {
const label = this.getSelectedOption()?.getLabel();
return _jsxs("div", { class: cls({
[Selector.selector]: true,
[Selector.opened]: this.isOpen,
[Selector.noPosition]: IS_MOBILE,
[Selector.disabled]: this.disabled
}), onclick: this.handleClick, onkeydown: this.handleKeyDown, tabindex: "0", role: "combobox", "aria-haspopup": "listbox", "aria-expanded": this.isOpen, "aria-controls": this.uid, "aria-placeholder": this.placeholder, children: [_jsx("span", { class: cls({
[Selector.selectedOption]: true,
"with-placeholder": !label
}), children: label ? label : this.placeholder }), _jsx("span", { class: Selector.downButton }), IS_MOBILE ? _jsx(this.OptionsListMobile, {}) : _jsx(this.OptionsListDesktop, {}), _jsx(this.HiddenSelect, {})] });
}
};
return ADWaveSelector2 = _classThis;
})();
var ADWaveSelectorOption = (() => {
let _classDecorators = [CustomElement("adw-option")];
let _classDescriptor;
let _classExtraInitializers = [];
let _classThis;
let _classSuper = WcSlot;
var ADWaveSelectorOption2 = class extends _classSuper {
static {
__name(this, "ADWaveSelectorOption");
}
static {
_classThis = this;
}
static {
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
ADWaveSelectorOption2 = _classThis = _classDescriptor.value;
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
__runInitializers(_classThis, _classExtraInitializers);
}
get selected() {
return this.isSelected();
}
set selected(selected) {
this.setSelected(selected);
}
get value() {
return this.getValue();
}
set value(value) {
this.setAttribute("value", value);
}
get inert() {
return this.hasAttribute("inert");
}
set inert(inert) {
this.toggleAttribute("inert", inert);
}
constructor() {
super();
}
isEqualTo(value) {
return this.hasValue() && this.getValue() === value;
}
hasValue() {
return this.hasAttribute("value");
}
getValue() {
return this.getAttribute("value") ?? "";
}
getLabel() {
return this.innerText;
}
setSelected(selected) {
this.setAttribute("selected", selected.toString());
}
isSelected() {
return this.getAttribute("selected") === "true";
}
shouldEmitAttributeChangeEvent(mutations) {
for (let i = 0; i < mutations.length; i++) {
const mutation = mutations[i];
switch (mutation.attributeName) {
case "inert":
case "value":
case "class":
return true;
case "selected":
if (mutation.oldValue !== this.getAttribute("selected")) {
return true;
}
break;
}
}
return false;
}
};
return ADWaveSelectorOption2 = _classThis;
})();
export {
ADWaveSelector,
ADWaveSelectorOption
};