wj-elements 0.1.184 → 0.1.186
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/form-associated-element-CaIxmEod.js +242 -0
- package/dist/form-associated-element-CaIxmEod.js.map +1 -0
- package/dist/light.css +3 -3
- package/dist/packages/internals/form-associated-element.d.ts +138 -0
- package/dist/packages/wje-checkbox/checkbox.element.d.ts +17 -90
- package/dist/packages/wje-infinite-scroll/infinite-scroll.element.d.ts +1 -1
- package/dist/packages/wje-input/input.element.d.ts +3 -106
- package/dist/packages/wje-options/options.element.d.ts +23 -19
- package/dist/packages/wje-popup/popup.element.d.ts +10 -0
- package/dist/packages/wje-radio/radio.element.d.ts +12 -1
- package/dist/packages/wje-radio-group/radio-group.element.d.ts +8 -90
- package/dist/packages/wje-select/select.d.ts +1 -1
- package/dist/packages/wje-select/select.element.d.ts +56 -194
- package/dist/packages/wje-textarea/textarea.element.d.ts +3 -110
- package/dist/{popup.element-Di4nHYij.js → popup.element-CVbbnTWI.js} +53 -24
- package/dist/{popup.element-Di4nHYij.js.map → popup.element-CVbbnTWI.js.map} +1 -1
- package/dist/wje-checkbox.js +59 -403
- package/dist/wje-checkbox.js.map +1 -1
- package/dist/wje-dropdown.js +1 -1
- package/dist/wje-icon-picker.js +1 -1
- package/dist/wje-infinite-scroll.js +7 -2
- package/dist/wje-infinite-scroll.js.map +1 -1
- package/dist/wje-input.js +10 -213
- package/dist/wje-input.js.map +1 -1
- package/dist/wje-master.js +1 -1
- package/dist/wje-option.js.map +1 -1
- package/dist/wje-options.js +56 -45
- package/dist/wje-options.js.map +1 -1
- package/dist/wje-popup.js +1 -1
- package/dist/wje-radio-group.js +82 -148
- package/dist/wje-radio-group.js.map +1 -1
- package/dist/wje-radio.js +36 -8
- package/dist/wje-radio.js.map +1 -1
- package/dist/wje-select.js +186 -303
- package/dist/wje-select.js.map +1 -1
- package/dist/wje-textarea.js +16 -210
- package/dist/wje-textarea.js.map +1 -1
- package/dist/wje-tooltip.js +1 -1
- package/package.json +2 -2
package/dist/wje-select.js
CHANGED
|
@@ -9,8 +9,9 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
|
|
|
9
9
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
10
10
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
11
11
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
12
|
-
var _addedOptions, _htmlOptions, _Select_instances, htmlSelectedItem_fn;
|
|
13
|
-
import
|
|
12
|
+
var _addedOptions, _htmlOptions, _Select_instances, htmlSelectedItem_fn, getSelected_fn, getSelectedOptions_fn, _applySearchFilter;
|
|
13
|
+
import { F as FormAssociatedElement } from "./form-associated-element-CaIxmEod.js";
|
|
14
|
+
import { event } from "./event.js";
|
|
14
15
|
import Button from "./wje-button.js";
|
|
15
16
|
import "./wje-popup.js";
|
|
16
17
|
import { I as Icon } from "./icon-DY5AZ6xM.js";
|
|
@@ -20,20 +21,9 @@ import Input from "./wje-input.js";
|
|
|
20
21
|
import Option from "./wje-option.js";
|
|
21
22
|
import Options from "./wje-options.js";
|
|
22
23
|
import Checkbox from "./wje-checkbox.js";
|
|
23
|
-
import { P as Popup } from "./popup.element-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class Select extends WJElement {
|
|
27
|
-
/**
|
|
28
|
-
* Constructor for the Select class.
|
|
29
|
-
* @class
|
|
30
|
-
* @description Initializes the Select component.
|
|
31
|
-
* This constructor sets up the initial state of the component, including selected items, counter element, and internal element API.
|
|
32
|
-
* It also tracks whether the select element was previously opened.
|
|
33
|
-
* @class
|
|
34
|
-
* @augments {WJElement}
|
|
35
|
-
* @memberof Select
|
|
36
|
-
*/
|
|
24
|
+
import { P as Popup } from "./popup.element-CVbbnTWI.js";
|
|
25
|
+
const styles = "/*\n[ WJ Select ]\n*/\n\n:host {\n margin-bottom: var(--wje-select-margin-bottom);\n width: 100%;\n display: block;\n [slot='arrow'] {\n transform: rotate(0deg);\n transition: all 0.2s ease-in;\n }\n}\n\n.native-select {\n position: relative;\n &.default {\n .wrapper {\n display: block;\n background-color: var(--wje-select-background);\n border-width: var(--wje-select-border-width);\n border-style: var(--wje-select-border-style);\n border-color: var(--wje-select-border-color);\n border-radius: var(--wje-select-border-radius);\n padding-inline: 0.5rem;\n padding-top: 0.125rem;\n padding-bottom: 0.125rem;\n }\n .input-wrapper {\n padding: 0;\n min-height: 28px;\n margin-top: -4px;\n }\n &.focused {\n wje-label {\n opacity: 0.67;\n font-size: 12px;\n letter-spacing: normal;\n }\n }\n wje-label {\n margin: 0;\n display: block;\n opacity: 1;\n cursor: text;\n transition: opacity 0.2s ease 0s;\n line-height: var(--wje-select-line-height);\n &.fade {\n opacity: 0.5;\n font-size: 12px;\n letter-spacing: normal;\n }\n }\n }\n &.standard {\n .wrapper {\n background-color: var(--wje-select-background);\n border-width: var(--wje-select-border-width);\n border-style: var(--wje-select-border-style);\n border-color: var(--wje-select-border-color);\n border-radius: var(--wje-select-border-radius);\n }\n .input-wrapper {\n background: transparent;\n width: 100%;\n }\n slot[name='error'] {\n position: static;\n\n background: transparent;\n padding: 0.25rem 0;\n left: auto;\n transform: none;\n color: var(--wje-input-color-invalid);\n font-size: 12px;\n line-height: normal;\n }\n }\n}\n\n.wrapper {\n display: flex;\n width: 100%;\n}\n\n.input-wrapper {\n display: grid;\n grid-template-columns: auto 1fr auto auto auto;\n align-items: center;\n background-color: var(--wje-select-background);\n min-height: 28px;\n color: var(--wje-select-color);\n line-height: var(--wje-select-line-height);\n appearance: none;\n padding: 2px 0.5rem;\n font-size: 14px !important;\n font-weight: normal;\n vertical-align: middle;\n input[readonly] {\n pointer-events: none;\n caret-color: transparent;\n }\n}\n\ninput {\n color: var(--wje-select-color);\n line-height: var(--wje-select-line-height);\n font-size: 14px !important;\n font-weight: 400;\n letter-spacing: 0.01em;\n border: medium;\n height: 25px;\n min-height: 25px;\n padding: 0;\n background: none;\n box-shadow: none;\n width: 100%;\n outline: 0;\n font-size: 14px !important;\n}\n\n::placeholder {\n opacity: 1;\n}\n\n:host [active] {\n .wrapper {\n border-radius: var(--wje-select-border-radius);\n }\n [slot='arrow'] {\n transform: rotate(180deg);\n transition: all 0.2s ease-in;\n }\n}\n\n.options-wrapper {\n border-width: var(--wje-select-options-border-width);\n border-style: var(--wje-select-options-border-style);\n border-color: var(--wje-select-options-border-color);\n border-radius: var(--wje-select-options-border-radius);\n margin-top: calc(0px - var(--wje-select-border-width));\n background: var(--wje-select-background);\n overflow: hidden;\n}\n\n.find {\n margin-block: var(--wje-select-find-margin-block);\n margin-inline: var(--wje-select-find-margin-inline);\n width: var(--wje-select-find-width);\n}\n\n.list {\n overflow: auto;\n height: 100%;\n}\n\n.options-wrapper:has(.find) .list {\n height: calc(100% - 32px - 2 * var(--wje-select-find-margin-block));\n}\n\n:host([multiple]) input {\n position: absolute;\n z-index: -1;\n top: 0;\n left: 0;\n width: 0;\n height: 0;\n opacity: 0;\n}\n\n:host([multiple]) .chips {\n display: flex;\n flex: 1;\n align-items: center;\n flex-wrap: wrap;\n gap: var(--wje-spacing-3x-small);\n}\n\n:host([disabled]) .input-wrapper {\n opacity: 0.5;\n pointer-events: none;\n cursor: not-allowed;\n}\n\n.counter {\n padding-inline: 0.5rem;\n}\n\nwje-chip {\n --wje-chip-margin: 0 0.25rem 0 0;\n}\n\nwje-button {\n --wje-padding-top: 0.25rem;\n --wje-padding-start: 0.25rem;\n --wje-padding-end: 0.25rem;\n --wje-padding-bottom: 0.25rem;\n --wje-button-margin-inline: 0 0.25rem;\n}\n\n.slot-start,\n.slot-end {\n &:not(:empty) {\n margin-right: 0.5rem;\n }\n}\n\nslot[name='error'] {\n display: none;\n}\n\n:host([invalid]) slot[name='error'] {\n display: block;\n}\n\nslot[name='error'] {\n display: none;\n position: absolute;\n max-width: 100%;\n min-width: auto;\n border-radius: 50px;\n background: black;\n padding: 0.25rem 0.5rem;\n top: 0;\n left: 50%;\n transform: translate(-50%, -50%);\n color: white;\n font-size: var(--wje-font-size-small);\n width: max-content;\n line-height: normal;\n}\n\n.input-hidden{\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n padding: 0;\n margin: 0;\n opacity: 0;\n z-index: -1;\n}";
|
|
26
|
+
class Select extends FormAssociatedElement {
|
|
37
27
|
constructor() {
|
|
38
28
|
super();
|
|
39
29
|
__privateAdd(this, _Select_instances);
|
|
@@ -51,7 +41,6 @@ class Select extends WJElement {
|
|
|
51
41
|
* @property {Function} 'wje-chip' Represents the Chip component class.
|
|
52
42
|
* @property {Function} 'wje-input' Represents the Input component class.
|
|
53
43
|
* @property {Function} 'wje-option' Represents the Option component class.
|
|
54
|
-
* @property {Function} 'wje-options' Represents the Options component class.
|
|
55
44
|
* @property {Function} 'wje-checkbox' Represents the Checkbox component class.
|
|
56
45
|
*/
|
|
57
46
|
__publicField(this, "dependencies", {
|
|
@@ -88,7 +77,7 @@ class Select extends WJElement {
|
|
|
88
77
|
this.processClickedOption(e.target, true);
|
|
89
78
|
}
|
|
90
79
|
this.selections();
|
|
91
|
-
this.
|
|
80
|
+
this.validate(this.selectedOptions);
|
|
92
81
|
this.pristine = false;
|
|
93
82
|
this.propagateValidation();
|
|
94
83
|
});
|
|
@@ -129,9 +118,22 @@ class Select extends WJElement {
|
|
|
129
118
|
this.processClickedOption(e.target.option, true);
|
|
130
119
|
this.selections();
|
|
131
120
|
});
|
|
132
|
-
this
|
|
121
|
+
__privateAdd(this, _applySearchFilter, (e) => {
|
|
122
|
+
const optionsElement = this.querySelector("wje-options");
|
|
123
|
+
if (optionsElement && optionsElement.hasAttribute("lazy")) {
|
|
124
|
+
optionsElement.setAttribute("search", e.target.value);
|
|
125
|
+
} else {
|
|
126
|
+
let value = e.target.value.trim().toLowerCase();
|
|
127
|
+
this.getAllOptions().forEach((option) => {
|
|
128
|
+
if (option.textContent.trim().toLowerCase().includes(value)) {
|
|
129
|
+
option.style.display = "block";
|
|
130
|
+
} else {
|
|
131
|
+
option.style.display = "none";
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
});
|
|
133
136
|
this.counterEl = null;
|
|
134
|
-
this.internals = this.attachInternals();
|
|
135
137
|
this._wasOppened = false;
|
|
136
138
|
this.native = null;
|
|
137
139
|
this.popup = null;
|
|
@@ -143,19 +145,32 @@ class Select extends WJElement {
|
|
|
143
145
|
this.chips = null;
|
|
144
146
|
this.clear = null;
|
|
145
147
|
this.list = null;
|
|
146
|
-
this.
|
|
148
|
+
this._value = [];
|
|
149
|
+
this._selected = [];
|
|
150
|
+
this._selectedOptions = [];
|
|
147
151
|
}
|
|
148
152
|
/**
|
|
149
|
-
*
|
|
150
|
-
*
|
|
153
|
+
* Sets the value of the form element. Handles multiple values when
|
|
154
|
+
* the element has the 'multiple' attribute by storing them in a FormData object.
|
|
155
|
+
* @param {string | Array} value The value to be set. Can be a single value or an array of values
|
|
156
|
+
* when 'multiple' attribute is present.
|
|
151
157
|
*/
|
|
152
158
|
set value(value) {
|
|
153
|
-
if (
|
|
159
|
+
if (value) {
|
|
160
|
+
let data = value;
|
|
161
|
+
if (!Array.isArray(data)) {
|
|
162
|
+
data = data.split(" ");
|
|
163
|
+
}
|
|
154
164
|
const formData = new FormData();
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
165
|
+
data.forEach((v) => {
|
|
166
|
+
formData.append(this.name, v);
|
|
167
|
+
});
|
|
168
|
+
value = formData;
|
|
169
|
+
this._value = data;
|
|
170
|
+
this.selected = data;
|
|
158
171
|
this.internals.setFormValue(value);
|
|
172
|
+
} else {
|
|
173
|
+
this._value = [];
|
|
159
174
|
}
|
|
160
175
|
}
|
|
161
176
|
/**
|
|
@@ -163,25 +178,19 @@ class Select extends WJElement {
|
|
|
163
178
|
* @returns {object} The value of the attribute.
|
|
164
179
|
*/
|
|
165
180
|
get value() {
|
|
166
|
-
return this.
|
|
181
|
+
return this._value;
|
|
167
182
|
}
|
|
168
|
-
|
|
183
|
+
/**
|
|
184
|
+
* Sets the `validate-on-change` attribute on the element. When the attribute is present, it typically indicates that validation should occur when the value of the input changes.
|
|
185
|
+
* @param {boolean} value A boolean indicating whether to enable or disable the `validate-on-change` attribute.
|
|
186
|
+
*/
|
|
187
|
+
set validateOnChange(value) {
|
|
169
188
|
if (value) {
|
|
170
|
-
this.setAttribute("
|
|
189
|
+
this.setAttribute("validate-on-change", "");
|
|
171
190
|
} else {
|
|
172
|
-
this.removeAttribute("
|
|
191
|
+
this.removeAttribute("validate-on-change");
|
|
173
192
|
}
|
|
174
193
|
}
|
|
175
|
-
get required() {
|
|
176
|
-
return this.hasAttribute("required");
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Getter for the customErrorDisplay attribute.
|
|
180
|
-
* @returns {boolean} Whether the attribute is present.
|
|
181
|
-
*/
|
|
182
|
-
get customErrorDisplay() {
|
|
183
|
-
return this.hasAttribute("custom-error-display");
|
|
184
|
-
}
|
|
185
194
|
/**
|
|
186
195
|
* Getter for the validateOnChange attribute.
|
|
187
196
|
* @returns {boolean} Whether the attribute is present.
|
|
@@ -189,30 +198,9 @@ class Select extends WJElement {
|
|
|
189
198
|
get validateOnChange() {
|
|
190
199
|
return this.hasAttribute("validate-on-change");
|
|
191
200
|
}
|
|
192
|
-
/**
|
|
193
|
-
* Retrieves the value of the 'invalid' attribute.
|
|
194
|
-
* This method checks if the 'invalid' attribute is present on the element.
|
|
195
|
-
* @returns {boolean} Returns true if the 'invalid' attribute is present, otherwise false.
|
|
196
|
-
*/
|
|
197
|
-
get invalid() {
|
|
198
|
-
return this.hasAttribute("invalid");
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Sets the 'invalid' property of the element.
|
|
202
|
-
* When set to a truthy value, the 'invalid' attribute is added to the element.
|
|
203
|
-
* When set to a falsy value, the 'invalid' attribute is removed from the element.
|
|
204
|
-
* @param {boolean} value A boolean indicating whether the element is invalid.
|
|
205
|
-
*/
|
|
206
|
-
set invalid(value) {
|
|
207
|
-
if (value) {
|
|
208
|
-
this.setAttribute("invalid", "");
|
|
209
|
-
} else {
|
|
210
|
-
this.removeAttribute("invalid");
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
201
|
/**
|
|
214
202
|
* Sets the maximum number of options allowed.
|
|
215
|
-
* @param {
|
|
203
|
+
* @param { number | object} value The value to set as the maximum number of options.
|
|
216
204
|
* If null, the 'max-options' attribute will be removed.
|
|
217
205
|
*/
|
|
218
206
|
set maxOptions(value) {
|
|
@@ -232,65 +220,52 @@ class Select extends WJElement {
|
|
|
232
220
|
return +this.getAttribute("max-options") || 1;
|
|
233
221
|
}
|
|
234
222
|
/**
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
return this.internals.form;
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Getter for the name attribute.
|
|
243
|
-
* @returns {string} The name of the input.
|
|
244
|
-
*/
|
|
245
|
-
get name() {
|
|
246
|
-
return this.getAttribute("name");
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Getter for the type attribute.
|
|
250
|
-
* @returns {string} The type of the input.
|
|
223
|
+
* @summary Setter for the defaultValue attribute.
|
|
224
|
+
* This method sets the 'value' attribute of the custom input element to the provided value.
|
|
225
|
+
* The 'value' attribute represents the default value of the input element.
|
|
226
|
+
* @param {string} value The value to set as the default value.
|
|
251
227
|
*/
|
|
252
|
-
|
|
253
|
-
|
|
228
|
+
set defaultValue(value) {
|
|
229
|
+
this.setAttribute("value", value);
|
|
254
230
|
}
|
|
255
231
|
/**
|
|
256
|
-
* Getter for the
|
|
257
|
-
*
|
|
232
|
+
* @summary Getter for the defaultValue attribute.
|
|
233
|
+
* This method retrieves the 'value' attribute of the custom input element.
|
|
234
|
+
* The 'value' attribute represents the default value of the input element.
|
|
235
|
+
* If the 'value' attribute is not set, it returns an empty string.
|
|
236
|
+
* @returns {string} The default value of the input element.
|
|
258
237
|
*/
|
|
259
|
-
get
|
|
260
|
-
return this.
|
|
238
|
+
get defaultValue() {
|
|
239
|
+
return this.getAttribute("value") ?? "";
|
|
261
240
|
}
|
|
262
241
|
/**
|
|
263
|
-
*
|
|
264
|
-
* @
|
|
242
|
+
* Sets the trigger value.
|
|
243
|
+
* @param {string} value The trigger value to set.
|
|
265
244
|
*/
|
|
266
|
-
|
|
267
|
-
|
|
245
|
+
set trigger(value) {
|
|
246
|
+
this.setAttribute("trigger", value);
|
|
268
247
|
}
|
|
269
248
|
/**
|
|
270
|
-
*
|
|
271
|
-
* @returns {
|
|
249
|
+
* Returns the trigger value.
|
|
250
|
+
* @returns {string} The trigger value.
|
|
272
251
|
*/
|
|
273
|
-
get
|
|
274
|
-
return this.
|
|
252
|
+
get trigger() {
|
|
253
|
+
return this.getAttribute("trigger") || "click";
|
|
275
254
|
}
|
|
276
255
|
/**
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
* The 'value' attribute represents the default value of the input element.
|
|
280
|
-
* If the 'value' attribute is not set, it returns an empty string.
|
|
281
|
-
* @returns {string} The default value of the input element.
|
|
256
|
+
* Sets the offset attribute for the element.
|
|
257
|
+
* @param {string} value The value to assign to the offset attribute.
|
|
282
258
|
*/
|
|
283
|
-
|
|
284
|
-
|
|
259
|
+
set offset(value) {
|
|
260
|
+
this.setAttribute("offset", value);
|
|
285
261
|
}
|
|
286
262
|
/**
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
* The
|
|
290
|
-
* @param {string} value The value to set as the default value.
|
|
263
|
+
* Gets the value of the offset attribute of the current element.
|
|
264
|
+
* If the offset attribute is not present, returns a default value of '0'.
|
|
265
|
+
* @returns {string} The value of the offset attribute or the default value '0'.
|
|
291
266
|
*/
|
|
292
|
-
|
|
293
|
-
this.
|
|
267
|
+
get offset() {
|
|
268
|
+
return this.getAttribute("offset") || "5";
|
|
294
269
|
}
|
|
295
270
|
/**
|
|
296
271
|
* Sets the label value.
|
|
@@ -304,7 +279,38 @@ class Select extends WJElement {
|
|
|
304
279
|
* @returns {Array} The selected value.
|
|
305
280
|
*/
|
|
306
281
|
get selected() {
|
|
307
|
-
return this.
|
|
282
|
+
return this._selected;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Sets the selected options for the object.
|
|
286
|
+
* @param {Array|object} value The new value for the selected options. It can be an array or object containing the selected options.
|
|
287
|
+
*/
|
|
288
|
+
set selectedOptions(value) {
|
|
289
|
+
this._selectedOptions = value;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Retrieves the selected options.
|
|
293
|
+
* @returns {Array} An array containing the currently selected options. If no options are selected, an empty array is returned.
|
|
294
|
+
*/
|
|
295
|
+
get selectedOptions() {
|
|
296
|
+
return this._selectedOptions || [];
|
|
297
|
+
}
|
|
298
|
+
set lazy(value) {
|
|
299
|
+
if (value) {
|
|
300
|
+
this.setAttribute("lazy", "");
|
|
301
|
+
} else {
|
|
302
|
+
this.removeAttribute("lazy");
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
get lazy() {
|
|
306
|
+
return this.hasAttribute("lazy");
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Getter for the customErrorDisplay attribute.
|
|
310
|
+
* @returns {boolean} Whether the attribute is present.
|
|
311
|
+
*/
|
|
312
|
+
get customErrorDisplay() {
|
|
313
|
+
return this.hasAttribute("custom-error-display");
|
|
308
314
|
}
|
|
309
315
|
/**
|
|
310
316
|
* Retrieves the complete list of options available for the component.
|
|
@@ -324,26 +330,6 @@ class Select extends WJElement {
|
|
|
324
330
|
).reverse();
|
|
325
331
|
}
|
|
326
332
|
}
|
|
327
|
-
/**
|
|
328
|
-
* Sets the trigger value.
|
|
329
|
-
* @param {string} value The trigger value to set.
|
|
330
|
-
*/
|
|
331
|
-
set trigger(value) {
|
|
332
|
-
this.setAttribute("trigger", value);
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* Returns the trigger value.
|
|
336
|
-
* @returns {string} The trigger value.
|
|
337
|
-
*/
|
|
338
|
-
get trigger() {
|
|
339
|
-
return this.getAttribute("trigger") || "click";
|
|
340
|
-
}
|
|
341
|
-
set offset(value) {
|
|
342
|
-
this.setAttribute("offset", value);
|
|
343
|
-
}
|
|
344
|
-
get offset() {
|
|
345
|
-
return this.getAttribute("offset") || "0";
|
|
346
|
-
}
|
|
347
333
|
/**
|
|
348
334
|
* Returns the CSS styles for the component.
|
|
349
335
|
* @static
|
|
@@ -389,12 +375,22 @@ class Select extends WJElement {
|
|
|
389
375
|
slotStart.classList.add("slot-start");
|
|
390
376
|
let input = document.createElement("input");
|
|
391
377
|
input.setAttribute("type", "text");
|
|
392
|
-
input.
|
|
393
|
-
input.
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
378
|
+
input.value = this.value.join(" ").trim();
|
|
379
|
+
input.classList.add("input-hidden");
|
|
380
|
+
let display = document.createElement("input");
|
|
381
|
+
display.setAttribute("type", "text");
|
|
382
|
+
display.setAttribute("part", "input");
|
|
383
|
+
display.setAttribute("autocomplete", "off");
|
|
384
|
+
display.setAttribute("readonly", "");
|
|
385
|
+
display.setAttribute("placeholder", this.placeholder || "");
|
|
386
|
+
if (this.required) {
|
|
397
387
|
input.setAttribute("required", "");
|
|
388
|
+
display.setAttribute("required", "");
|
|
389
|
+
}
|
|
390
|
+
if (this.disabled) {
|
|
391
|
+
input.setAttribute("disabled", "");
|
|
392
|
+
display.setAttribute("disabled", "");
|
|
393
|
+
}
|
|
398
394
|
let slotEnd = document.createElement("div");
|
|
399
395
|
slotEnd.classList.add("slot-end");
|
|
400
396
|
let arrow = document.createElement("wje-icon");
|
|
@@ -422,17 +418,20 @@ class Select extends WJElement {
|
|
|
422
418
|
errorSlot.setAttribute("name", "error");
|
|
423
419
|
let popup = document.createElement("wje-popup");
|
|
424
420
|
popup.setAttribute("placement", "bottom-start");
|
|
425
|
-
popup.setAttribute("manual", "");
|
|
426
421
|
popup.setAttribute("size", "");
|
|
427
422
|
popup.setAttribute("part", "popup");
|
|
428
423
|
popup.setAttribute("offset", this.offset);
|
|
429
|
-
if (this.
|
|
424
|
+
if (this.lazy || this.querySelector("wje-options")) {
|
|
425
|
+
popup.setAttribute("loader", "");
|
|
426
|
+
}
|
|
427
|
+
if (this.disabled) popup.setAttribute("disabled", "");
|
|
430
428
|
if (this.variant === "standard") {
|
|
431
429
|
if (this.hasAttribute("label")) native.appendChild(label);
|
|
432
430
|
} else {
|
|
433
431
|
wrapper.appendChild(label);
|
|
434
432
|
}
|
|
435
433
|
inputWrapper.append(slotStart);
|
|
434
|
+
inputWrapper.append(display);
|
|
436
435
|
inputWrapper.append(input);
|
|
437
436
|
clear.append(clearIcon);
|
|
438
437
|
if (this.hasAttribute("multiple")) inputWrapper.append(chips);
|
|
@@ -450,18 +449,6 @@ class Select extends WJElement {
|
|
|
450
449
|
optionsWrapper.appendChild(find);
|
|
451
450
|
this.findEl = find;
|
|
452
451
|
}
|
|
453
|
-
if (this.hasAttribute("lazy")) {
|
|
454
|
-
event.addListener(popup, "wje-popup:show", null, (e) => {
|
|
455
|
-
if (this._wasOppened) return;
|
|
456
|
-
this._wasOppened = true;
|
|
457
|
-
const optionsElement = this.querySelector("wje-options");
|
|
458
|
-
optionsElement.setAttribute("lazy", "");
|
|
459
|
-
optionsElement.setAttribute("attached", "");
|
|
460
|
-
});
|
|
461
|
-
} else {
|
|
462
|
-
const optionsElement = this.querySelector("wje-options");
|
|
463
|
-
optionsElement == null ? void 0 : optionsElement.setAttribute("attached", "");
|
|
464
|
-
}
|
|
465
452
|
optionsWrapper.append(list);
|
|
466
453
|
wrapper.append(inputWrapper);
|
|
467
454
|
popup.append(wrapper);
|
|
@@ -470,17 +457,18 @@ class Select extends WJElement {
|
|
|
470
457
|
this.append(error);
|
|
471
458
|
native.append(popup);
|
|
472
459
|
native.append(errorSlot);
|
|
460
|
+
fragment.appendChild(native);
|
|
473
461
|
this.native = native;
|
|
474
462
|
this.popup = popup;
|
|
475
463
|
this.labelElement = label;
|
|
476
464
|
this.slotStart = slotStart;
|
|
477
465
|
this.slotEnd = slotEnd;
|
|
478
466
|
this.input = input;
|
|
467
|
+
this.display = display;
|
|
479
468
|
this.optionsWrapper = optionsWrapper;
|
|
480
469
|
this.chips = chips;
|
|
481
470
|
this.clear = clear;
|
|
482
471
|
this.list = list;
|
|
483
|
-
fragment.appendChild(native);
|
|
484
472
|
return fragment;
|
|
485
473
|
}
|
|
486
474
|
/**
|
|
@@ -491,13 +479,22 @@ class Select extends WJElement {
|
|
|
491
479
|
*/
|
|
492
480
|
afterDraw() {
|
|
493
481
|
var _a, _b;
|
|
494
|
-
this.
|
|
482
|
+
this.validate(this.selectedOptions);
|
|
495
483
|
if (this.hasAttribute("invalid")) {
|
|
496
484
|
this.showInvalidMessage();
|
|
497
485
|
}
|
|
498
486
|
(_a = this.getAllOptions()) == null ? void 0 : _a.forEach((option) => {
|
|
499
487
|
this.optionCheckSlot(option);
|
|
500
488
|
});
|
|
489
|
+
if (this.lazy) {
|
|
490
|
+
event.addListener(this.popup, "wje-popup:show", null, (e) => {
|
|
491
|
+
if (this._wasOppened) return;
|
|
492
|
+
this._wasOppened = true;
|
|
493
|
+
const optionsElement = this.querySelector("wje-options");
|
|
494
|
+
optionsElement.setAttribute("lazy", "");
|
|
495
|
+
optionsElement.setAttribute("attached", "");
|
|
496
|
+
});
|
|
497
|
+
}
|
|
501
498
|
__privateSet(this, _htmlOptions, Array.from(this.querySelectorAll(":scope > wje-option")).map((option) => {
|
|
502
499
|
return {
|
|
503
500
|
value: option.value,
|
|
@@ -529,6 +526,7 @@ class Select extends WJElement {
|
|
|
529
526
|
(_b = this.clear) == null ? void 0 : _b.addEventListener("wje-button:click", (e) => {
|
|
530
527
|
e.preventDefault();
|
|
531
528
|
e.stopPropagation();
|
|
529
|
+
this.selected = [];
|
|
532
530
|
this.selectedOptions = [];
|
|
533
531
|
this.getAllOptions().forEach((option) => {
|
|
534
532
|
option.selected = false;
|
|
@@ -536,7 +534,9 @@ class Select extends WJElement {
|
|
|
536
534
|
this.selections();
|
|
537
535
|
e.stopPropagation();
|
|
538
536
|
});
|
|
539
|
-
this.
|
|
537
|
+
this.selectOptions(this.value);
|
|
538
|
+
this.selected = __privateMethod(this, _Select_instances, getSelected_fn).call(this);
|
|
539
|
+
this.selectedOptions = __privateMethod(this, _Select_instances, getSelectedOptions_fn).call(this);
|
|
540
540
|
this.selections(true);
|
|
541
541
|
this.list.addEventListener("wje-options:load", (e) => {
|
|
542
542
|
this.selectedOptions.forEach((option) => {
|
|
@@ -547,20 +547,11 @@ class Select extends WJElement {
|
|
|
547
547
|
});
|
|
548
548
|
});
|
|
549
549
|
this.list.scrollTo(0, 0);
|
|
550
|
+
event.dispatchCustomEvent(this.popup, "wje-popup:content-ready");
|
|
550
551
|
});
|
|
551
552
|
if (this.hasAttribute("find") && this.findEl instanceof HTMLElement) {
|
|
552
|
-
event.addListener(this.findEl, "keyup", "", (
|
|
553
|
-
|
|
554
|
-
if (optionsElement && optionsElement.hasAttribute("lazy")) {
|
|
555
|
-
optionsElement.setAttribute("search", e.target.value);
|
|
556
|
-
} else {
|
|
557
|
-
let value = e.target.value.trim().toLowerCase();
|
|
558
|
-
this.getAllOptions().forEach((option) => {
|
|
559
|
-
if (option.textContent.trim().toLowerCase().includes(value)) option.style.display = "block";
|
|
560
|
-
else option.style.display = "none";
|
|
561
|
-
});
|
|
562
|
-
}
|
|
563
|
-
});
|
|
553
|
+
event.addListener(this.findEl, "keyup", "", __privateGet(this, _applySearchFilter));
|
|
554
|
+
event.addListener(this.findEl, "wje-input:clear", "", __privateGet(this, _applySearchFilter));
|
|
564
555
|
}
|
|
565
556
|
}
|
|
566
557
|
/**
|
|
@@ -570,38 +561,19 @@ class Select extends WJElement {
|
|
|
570
561
|
getAllOptions() {
|
|
571
562
|
return this.querySelectorAll("wje-option");
|
|
572
563
|
}
|
|
573
|
-
/**
|
|
574
|
-
* Returns the selected options as HTML.
|
|
575
|
-
* @returns {NodeList} The selected options as HTML.
|
|
576
|
-
*/
|
|
577
|
-
getSelectedOptions() {
|
|
578
|
-
return Array.from(this.querySelectorAll("wje-option[selected]"));
|
|
579
|
-
}
|
|
580
|
-
/**
|
|
581
|
-
* Returns the selected options.
|
|
582
|
-
* @returns {Array} The selected options.
|
|
583
|
-
*/
|
|
584
|
-
getSelected() {
|
|
585
|
-
return this.selectedOptions.map((option) => {
|
|
586
|
-
return {
|
|
587
|
-
value: option.value,
|
|
588
|
-
text: __privateMethod(this, _Select_instances, htmlSelectedItem_fn).call(this, option.value)
|
|
589
|
-
// option.textContent.trim(),
|
|
590
|
-
};
|
|
591
|
-
});
|
|
592
|
-
}
|
|
593
564
|
/**
|
|
594
565
|
* Handles the selection change.
|
|
595
566
|
* @param {Element[]} options The option that changed.
|
|
596
567
|
* @param {number} length The length of the selected options.
|
|
597
568
|
*/
|
|
598
569
|
selectionChanged(options = null, length = 0) {
|
|
599
|
-
var _a, _b;
|
|
570
|
+
var _a, _b, _c, _d, _e;
|
|
571
|
+
this.selected = __privateMethod(this, _Select_instances, getSelected_fn).call(this);
|
|
600
572
|
if (this.hasAttribute("multiple")) {
|
|
601
573
|
this.value = this.selectedOptions.map((el) => el.value).reverse();
|
|
574
|
+
this.input.value = this.selected.map((a) => a.value).join(" ").trim();
|
|
602
575
|
if (this.placeholder && length === 0) {
|
|
603
576
|
this.chips.innerHTML = this.placeholder;
|
|
604
|
-
this.input.value = "";
|
|
605
577
|
} else {
|
|
606
578
|
if (options !== null) Array.from(options).slice(0, +this.maxOptions).forEach((option) => this.chips.appendChild(this.getChip(option)));
|
|
607
579
|
if (this.counterEl instanceof HTMLElement || !this.maxOptions || length > +this.maxOptions) {
|
|
@@ -609,10 +581,10 @@ class Select extends WJElement {
|
|
|
609
581
|
}
|
|
610
582
|
}
|
|
611
583
|
} else {
|
|
612
|
-
|
|
613
|
-
let value = (option && __privateMethod(this, _Select_instances, htmlSelectedItem_fn).call(this, option.value)) ?? "";
|
|
584
|
+
const option = options == null ? void 0 : options.at(0);
|
|
614
585
|
this.value = (_b = (_a = this.selectedOptions) == null ? void 0 : _a.map((el) => el.value)) == null ? void 0 : _b.at(0);
|
|
615
|
-
this.input.value = value;
|
|
586
|
+
this.input.value = ((_c = this.selected[0]) == null ? void 0 : _c.value) || "";
|
|
587
|
+
this.display.value = ((_e = (_d = this.selectedOptions[0]) == null ? void 0 : _d.textContent) == null ? void 0 : _e.trim()) || "";
|
|
616
588
|
if (option && option instanceof HTMLElement) {
|
|
617
589
|
this.slotStart.innerHTML = "";
|
|
618
590
|
let optionSlotStart = option == null ? void 0 : option.querySelector("wje-option > [slot=start]");
|
|
@@ -654,7 +626,7 @@ class Select extends WJElement {
|
|
|
654
626
|
if (this.selectedOptions.length > 0) {
|
|
655
627
|
this.selectionChanged(this.selectedOptions, this.selectedOptions.length);
|
|
656
628
|
} else {
|
|
657
|
-
this.selectionChanged();
|
|
629
|
+
this.selectionChanged(this.selectedOptions);
|
|
658
630
|
}
|
|
659
631
|
if (silence) return;
|
|
660
632
|
event.dispatchCustomEvent(this, "wje-select:change");
|
|
@@ -715,6 +687,14 @@ class Select extends WJElement {
|
|
|
715
687
|
__privateGet(this, _addedOptions).push({ [map.value]: item[map.value], [map.text]: item[map.text] });
|
|
716
688
|
return option;
|
|
717
689
|
}
|
|
690
|
+
/**
|
|
691
|
+
* Returns the provided item.
|
|
692
|
+
* @param {any} item The item to be returned.
|
|
693
|
+
* @returns {any} The same item that was passed as input.
|
|
694
|
+
*/
|
|
695
|
+
htmlSelectedItem(item) {
|
|
696
|
+
return item;
|
|
697
|
+
}
|
|
718
698
|
/**
|
|
719
699
|
* Adds an option to the select element.
|
|
720
700
|
* @param {any} optionData The data for the option to be added.
|
|
@@ -741,11 +721,6 @@ class Select extends WJElement {
|
|
|
741
721
|
if (!Array.isArray(optionsData)) {
|
|
742
722
|
this.addOption(optionsData, silent, map);
|
|
743
723
|
} else {
|
|
744
|
-
const optionsElement = this.querySelector("wje-options");
|
|
745
|
-
if (optionsElement) {
|
|
746
|
-
optionsElement.addOptions(optionsData, silent, map);
|
|
747
|
-
return;
|
|
748
|
-
}
|
|
749
724
|
optionsData.forEach((item) => {
|
|
750
725
|
this.addOption(item, silent, map);
|
|
751
726
|
});
|
|
@@ -778,14 +753,6 @@ class Select extends WJElement {
|
|
|
778
753
|
});
|
|
779
754
|
}
|
|
780
755
|
}
|
|
781
|
-
/**
|
|
782
|
-
* Returns the provided item.
|
|
783
|
-
* @param {any} item The item to be returned.
|
|
784
|
-
* @returns {any} The same item that was passed as input.
|
|
785
|
-
*/
|
|
786
|
-
htmlSelectedItem(item) {
|
|
787
|
-
return item;
|
|
788
|
-
}
|
|
789
756
|
/**
|
|
790
757
|
* Clones and appends an icon from a template with slot "check" to the given option element.
|
|
791
758
|
* @param {HTMLElement} option The target option element where the "check" icon will be added.
|
|
@@ -801,106 +768,6 @@ class Select extends WJElement {
|
|
|
801
768
|
let iconClone = icon.cloneNode(true);
|
|
802
769
|
option.append(iconClone);
|
|
803
770
|
}
|
|
804
|
-
/**
|
|
805
|
-
* Validates the selection of options in the select element.
|
|
806
|
-
* Checks if the element is required and no option is selected,
|
|
807
|
-
* in which case it sets a validation error with a custom message.
|
|
808
|
-
* If the element passes validation, it clears any existing validation errors.
|
|
809
|
-
*
|
|
810
|
-
* @return {void} Does not return a value.
|
|
811
|
-
*/
|
|
812
|
-
validateSelect() {
|
|
813
|
-
if (this.required && this.selectedOptions.length === 0) {
|
|
814
|
-
const msg = this.getAttribute("message-required") || "Zvoľte možnosť";
|
|
815
|
-
this.internals.setValidity({ valueMissing: true }, msg);
|
|
816
|
-
} else {
|
|
817
|
-
this.internals.setValidity({});
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
/**
|
|
821
|
-
* Checks and updates the validation state of the component based on its current properties.
|
|
822
|
-
* If the component is invalid and a custom error display is enabled, it dispatches an 'invalid' event.
|
|
823
|
-
* @returns {void} This method does not return a value.
|
|
824
|
-
*/
|
|
825
|
-
propagateValidation() {
|
|
826
|
-
this.invalid = !this.pristine && !this.validity.valid;
|
|
827
|
-
if (this.invalid) {
|
|
828
|
-
event.dispatchCustomEvent(this, "wje-select:invalid");
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
showInvalidMessage() {
|
|
832
|
-
{
|
|
833
|
-
const slot = this.querySelector("[slot='error']");
|
|
834
|
-
let errorMessageEL = slot.querySelector("[error-message]");
|
|
835
|
-
if (!errorMessageEL) {
|
|
836
|
-
const error = document.createElement("div");
|
|
837
|
-
error.setAttribute("error-message", "");
|
|
838
|
-
slot.append(error);
|
|
839
|
-
errorMessageEL = error;
|
|
840
|
-
}
|
|
841
|
-
errorMessageEL.textContent = this.internals.validationMessage;
|
|
842
|
-
}
|
|
843
|
-
console.log(`Invalid input: ${this.internals.validationMessage}`);
|
|
844
|
-
}
|
|
845
|
-
/**
|
|
846
|
-
* Lifecycle callback invoked when the custom element becomes associated with a form element.
|
|
847
|
-
* @param {HTMLFormElement} form The form element the custom element is associated with.
|
|
848
|
-
* @returns {void}
|
|
849
|
-
*/
|
|
850
|
-
formAssociatedCallback(form) {
|
|
851
|
-
if (form) {
|
|
852
|
-
form.addEventListener("submit", () => {
|
|
853
|
-
this.validateSelect();
|
|
854
|
-
this.propagateValidation();
|
|
855
|
-
});
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
/**
|
|
859
|
-
* The formResetCallback method is a built-in lifecycle callback that gets called when a form gets reset.
|
|
860
|
-
* This method is responsible for resetting the value of the custom input element to its default value.
|
|
861
|
-
* It also resets the form value and validity state in the form internals.
|
|
862
|
-
* @function
|
|
863
|
-
*/
|
|
864
|
-
formResetCallback() {
|
|
865
|
-
this.value = this.defaultValue;
|
|
866
|
-
this.internals.setFormValue(this.defaultValue);
|
|
867
|
-
this.internals.setValidity({});
|
|
868
|
-
}
|
|
869
|
-
/**
|
|
870
|
-
* The formStateRestoreCallback method is a built-in lifecycle callback that gets called when the state of a form-associated custom element is restored.
|
|
871
|
-
* This method is responsible for restoring the value of the custom input element to its saved state.
|
|
872
|
-
* It also restores the form value and validity state in the form internals to their saved states.
|
|
873
|
-
* @param {object} state The saved state of the custom input element.
|
|
874
|
-
* @function
|
|
875
|
-
*/
|
|
876
|
-
formStateRestoreCallback(state) {
|
|
877
|
-
this.value = state.value;
|
|
878
|
-
this.internals.setFormValue(state.value);
|
|
879
|
-
this.internals.setValidity({});
|
|
880
|
-
}
|
|
881
|
-
/**
|
|
882
|
-
* The formStateSaveCallback method is a built-in lifecycle callback that gets called when the state of a form-associated custom element is saved.
|
|
883
|
-
* This method is responsible for saving the value of the custom input element.
|
|
884
|
-
* @returns {object} The saved state of the custom input element.
|
|
885
|
-
* @function
|
|
886
|
-
*/
|
|
887
|
-
formStateSaveCallback() {
|
|
888
|
-
return {
|
|
889
|
-
value: this.value
|
|
890
|
-
};
|
|
891
|
-
}
|
|
892
|
-
/**
|
|
893
|
-
* The formDisabledCallback method is a built-in lifecycle callback that gets called when the disabled state of a form-associated custom element changes.
|
|
894
|
-
* This method is not implemented yet.
|
|
895
|
-
* @param {boolean} disabled The new disabled state of the custom input element.
|
|
896
|
-
* @function
|
|
897
|
-
*/
|
|
898
|
-
formDisabledCallback(disabled) {
|
|
899
|
-
var _a;
|
|
900
|
-
console.warn("formDisabledCallback not implemented yet");
|
|
901
|
-
(_a = this.native) == null ? void 0 : _a.classList.toggle("disabled", disabled);
|
|
902
|
-
this.toggleAttribute("disabled", disabled);
|
|
903
|
-
}
|
|
904
771
|
/**
|
|
905
772
|
* Checks if all elements in the `elements` array are present in the `options` array based on their `option` property.
|
|
906
773
|
* @param {Array} elements The array of elements to check. Each element should have an `option` property.
|
|
@@ -932,10 +799,26 @@ htmlSelectedItem_fn = function(item) {
|
|
|
932
799
|
return this.htmlSelectedItem(value);
|
|
933
800
|
};
|
|
934
801
|
/**
|
|
935
|
-
*
|
|
936
|
-
* @
|
|
802
|
+
* Returns the selected options.
|
|
803
|
+
* @returns {Array} The selected options.
|
|
937
804
|
*/
|
|
938
|
-
|
|
805
|
+
getSelected_fn = function() {
|
|
806
|
+
return this.selectedOptions.map((option) => {
|
|
807
|
+
return {
|
|
808
|
+
value: option.value,
|
|
809
|
+
text: __privateMethod(this, _Select_instances, htmlSelectedItem_fn).call(this, option.value)
|
|
810
|
+
// option.textContent.trim(),
|
|
811
|
+
};
|
|
812
|
+
});
|
|
813
|
+
};
|
|
814
|
+
/**
|
|
815
|
+
* Returns the selected options as HTML.
|
|
816
|
+
* @returns {NodeList} The selected options as HTML.
|
|
817
|
+
*/
|
|
818
|
+
getSelectedOptions_fn = function() {
|
|
819
|
+
return Array.from(this.querySelectorAll("wje-option[selected]"));
|
|
820
|
+
};
|
|
821
|
+
_applySearchFilter = new WeakMap();
|
|
939
822
|
Select.define("wje-select", Select);
|
|
940
823
|
export {
|
|
941
824
|
Select as default
|