@lukso/web-components 1.141.0 → 1.141.1
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/index.cjs +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/lukso-search/index.cjs +11 -668
- package/dist/components/lukso-search/index.js +7 -673
- package/dist/index-9fZwHYlC.js +680 -0
- package/dist/index-BV3Zii44.cjs +683 -0
- package/dist/index.cjs +3 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,680 @@
|
|
|
1
|
+
import { m as makeBlockie } from './index-C2gvsCnK.js';
|
|
2
|
+
import { T as TailwindStyledElement, x, E } from './index-Ctu_Y4Qk.js';
|
|
3
|
+
import { n, t } from './property-B5uoP6xb.js';
|
|
4
|
+
import { r } from './state-THRbrpGV.js';
|
|
5
|
+
import { c as ce } from './index-B9iart53.js';
|
|
6
|
+
import './components/lukso-dropdown/index.js';
|
|
7
|
+
import './components/lukso-dropdown-option/index.js';
|
|
8
|
+
import './components/lukso-icon/index.js';
|
|
9
|
+
import './components/lukso-input/index.js';
|
|
10
|
+
import './components/lukso-tag/index.js';
|
|
11
|
+
import { s as sliceAddress } from './index-omLmsjy0.js';
|
|
12
|
+
import './tailwind-config.js';
|
|
13
|
+
import './cn-Cu9aP49j.js';
|
|
14
|
+
|
|
15
|
+
const style = ":host {\n\n display: inline-flex\n}\n\n:host([is-full-width]) {\n\n display: flex;\n\n width: 100%\n}";
|
|
16
|
+
|
|
17
|
+
var STANDARDS = /* @__PURE__ */ ((STANDARDS2) => {
|
|
18
|
+
STANDARDS2["EOA"] = "EOA";
|
|
19
|
+
STANDARDS2["LSP3"] = "LSP0ERC725Account";
|
|
20
|
+
STANDARDS2["LSP7"] = "LSP7DigitalAsset";
|
|
21
|
+
STANDARDS2["LSP8"] = "LSP8IdentifiableDigitalAsset";
|
|
22
|
+
STANDARDS2["UNKNOWN"] = "UnknownContract";
|
|
23
|
+
return STANDARDS2;
|
|
24
|
+
})(STANDARDS || {});
|
|
25
|
+
var SEARCH_RESULT_TYPES = /* @__PURE__ */ ((SEARCH_RESULT_TYPES2) => {
|
|
26
|
+
SEARCH_RESULT_TYPES2["STRING"] = "string";
|
|
27
|
+
SEARCH_RESULT_TYPES2["PROFILE"] = "profile";
|
|
28
|
+
SEARCH_RESULT_TYPES2["ASSET"] = "asset";
|
|
29
|
+
SEARCH_RESULT_TYPES2["APP"] = "app";
|
|
30
|
+
SEARCH_RESULT_TYPES2["UNIVERSAL_NAME"] = "universal-name";
|
|
31
|
+
return SEARCH_RESULT_TYPES2;
|
|
32
|
+
})(SEARCH_RESULT_TYPES || {});
|
|
33
|
+
|
|
34
|
+
var __defProp = Object.defineProperty;
|
|
35
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
36
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
37
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
38
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
39
|
+
if (decorator = decorators[i])
|
|
40
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
41
|
+
if (kind && result) __defProp(target, key, result);
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
let LuksoSearch = class extends TailwindStyledElement(style) {
|
|
45
|
+
constructor() {
|
|
46
|
+
super(...arguments);
|
|
47
|
+
this.value = "";
|
|
48
|
+
this.name = "";
|
|
49
|
+
this.placeholder = "";
|
|
50
|
+
this.label = "";
|
|
51
|
+
this.groupLabels = JSON.stringify({
|
|
52
|
+
[SEARCH_RESULT_TYPES.UNIVERSAL_NAME]: "Universal Names",
|
|
53
|
+
[SEARCH_RESULT_TYPES.PROFILE]: "Profiles",
|
|
54
|
+
[SEARCH_RESULT_TYPES.ASSET]: "Assets",
|
|
55
|
+
[SEARCH_RESULT_TYPES.APP]: "Apps",
|
|
56
|
+
[SEARCH_RESULT_TYPES.STRING]: "Other"
|
|
57
|
+
});
|
|
58
|
+
this.availableText = "Available";
|
|
59
|
+
this.unavailableText = "Registered";
|
|
60
|
+
this.autocomplete = "off";
|
|
61
|
+
this.id = "";
|
|
62
|
+
this.description = "";
|
|
63
|
+
this.error = "";
|
|
64
|
+
this.customClass = "";
|
|
65
|
+
this.isFullWidth = false;
|
|
66
|
+
this.isReadonly = false;
|
|
67
|
+
this.isDisabled = false;
|
|
68
|
+
this.autofocus = false;
|
|
69
|
+
this.borderless = false;
|
|
70
|
+
this.results = "";
|
|
71
|
+
this.rightIcon = "search";
|
|
72
|
+
this.debounce = 700;
|
|
73
|
+
this.isSearching = false;
|
|
74
|
+
this.noResultsText = "";
|
|
75
|
+
this.showNoResults = false;
|
|
76
|
+
this.hideLoading = false;
|
|
77
|
+
this.hasReset = false;
|
|
78
|
+
this.keepValueOnEscapeHit = false;
|
|
79
|
+
this.selected = void 0;
|
|
80
|
+
this.size = "large";
|
|
81
|
+
this.maxHeight = void 0;
|
|
82
|
+
this.isDebouncing = false;
|
|
83
|
+
this.resultsParsed = [];
|
|
84
|
+
this.styles = ce({
|
|
85
|
+
slots: {
|
|
86
|
+
loading: "bg-neutral-95 w-full animate-pulse animation-delay-none"
|
|
87
|
+
},
|
|
88
|
+
variants: {
|
|
89
|
+
size: {
|
|
90
|
+
small: {
|
|
91
|
+
loading: "h-7 rounded-4"
|
|
92
|
+
},
|
|
93
|
+
medium: {
|
|
94
|
+
loading: "h-10 rounded-8"
|
|
95
|
+
},
|
|
96
|
+
large: {
|
|
97
|
+
loading: "h-10 rounded-8"
|
|
98
|
+
},
|
|
99
|
+
"x-large": {
|
|
100
|
+
loading: "h-12 rounded-8"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
this.dropdownSize = {
|
|
106
|
+
small: "small",
|
|
107
|
+
medium: "medium",
|
|
108
|
+
large: "medium",
|
|
109
|
+
"x-large": "medium"
|
|
110
|
+
};
|
|
111
|
+
this.profileSize = {
|
|
112
|
+
small: "2x-small",
|
|
113
|
+
medium: "x-small",
|
|
114
|
+
large: "x-small",
|
|
115
|
+
"x-large": "small"
|
|
116
|
+
};
|
|
117
|
+
this.usernameSize = {
|
|
118
|
+
small: "small",
|
|
119
|
+
medium: "medium",
|
|
120
|
+
large: "large",
|
|
121
|
+
"x-large": "x-large"
|
|
122
|
+
};
|
|
123
|
+
this.textSize = {
|
|
124
|
+
small: "text-12",
|
|
125
|
+
medium: "text-14",
|
|
126
|
+
large: "text-16",
|
|
127
|
+
"x-large": "text-16"
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
connectedCallback() {
|
|
131
|
+
super.connectedCallback();
|
|
132
|
+
window.addEventListener("click", this.handleOutsideDropdownClick.bind(this));
|
|
133
|
+
window.addEventListener("keydown", this.handleDropdownKeydown.bind(this));
|
|
134
|
+
}
|
|
135
|
+
disconnectedCallback() {
|
|
136
|
+
super.disconnectedCallback();
|
|
137
|
+
window.removeEventListener("click", this.handleOutsideDropdownClick);
|
|
138
|
+
window.removeEventListener("keydown", this.handleDropdownKeydown);
|
|
139
|
+
}
|
|
140
|
+
willUpdate(changedProperties) {
|
|
141
|
+
if (changedProperties.has("selected")) {
|
|
142
|
+
const selectedOption = this.shadowRoot?.querySelector(
|
|
143
|
+
`[data-index="${changedProperties.get("selected")}"`
|
|
144
|
+
);
|
|
145
|
+
if (selectedOption) {
|
|
146
|
+
if ("scrollIntoViewIfNeeded" in selectedOption && typeof selectedOption.scrollIntoViewIfNeeded === "function") {
|
|
147
|
+
selectedOption.scrollIntoViewIfNeeded();
|
|
148
|
+
} else {
|
|
149
|
+
selectedOption.scrollIntoView({
|
|
150
|
+
behavior: "smooth",
|
|
151
|
+
block: "center"
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
resultsTemplate() {
|
|
158
|
+
const resultTemplates = [];
|
|
159
|
+
this.resultsParsed = JSON.parse(this.results);
|
|
160
|
+
const groupLabelsParsed = JSON.parse(this.groupLabels);
|
|
161
|
+
const types = this.resultsParsed.map((r) => r.type);
|
|
162
|
+
const isMixedTypes = new Set(types).size > 1;
|
|
163
|
+
for (const result of Object.entries(this.resultsParsed)) {
|
|
164
|
+
const index = Number(result[0]);
|
|
165
|
+
if (isMixedTypes) {
|
|
166
|
+
const currentType = result[1].type;
|
|
167
|
+
const prevType = index > 0 ? this.resultsParsed[index - 1].type : null;
|
|
168
|
+
if (index === 0 || currentType !== prevType) {
|
|
169
|
+
let headerText = "";
|
|
170
|
+
switch (currentType) {
|
|
171
|
+
case SEARCH_RESULT_TYPES.UNIVERSAL_NAME:
|
|
172
|
+
headerText = groupLabelsParsed[SEARCH_RESULT_TYPES.UNIVERSAL_NAME];
|
|
173
|
+
break;
|
|
174
|
+
case SEARCH_RESULT_TYPES.PROFILE:
|
|
175
|
+
headerText = groupLabelsParsed[SEARCH_RESULT_TYPES.PROFILE];
|
|
176
|
+
break;
|
|
177
|
+
case SEARCH_RESULT_TYPES.ASSET:
|
|
178
|
+
headerText = groupLabelsParsed[SEARCH_RESULT_TYPES.ASSET];
|
|
179
|
+
break;
|
|
180
|
+
case SEARCH_RESULT_TYPES.APP:
|
|
181
|
+
headerText = groupLabelsParsed[SEARCH_RESULT_TYPES.APP];
|
|
182
|
+
break;
|
|
183
|
+
default:
|
|
184
|
+
headerText = groupLabelsParsed[SEARCH_RESULT_TYPES.STRING];
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
resultTemplates.push(
|
|
188
|
+
x`<div
|
|
189
|
+
class="py-1 my-1 text-neutral-35 paragraph-inter-12-medium tracking-wider border-b border-b-neutral-95"
|
|
190
|
+
>
|
|
191
|
+
${headerText}
|
|
192
|
+
</div>`
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
switch (result[1].type) {
|
|
197
|
+
// UniversalName result
|
|
198
|
+
case SEARCH_RESULT_TYPES.UNIVERSAL_NAME:
|
|
199
|
+
resultTemplates.push(
|
|
200
|
+
this.resultUniversalNameTemplate(result[1], index)
|
|
201
|
+
);
|
|
202
|
+
break;
|
|
203
|
+
// Profile result
|
|
204
|
+
case SEARCH_RESULT_TYPES.PROFILE:
|
|
205
|
+
resultTemplates.push(this.resultProfileTemplate(result[1], index));
|
|
206
|
+
break;
|
|
207
|
+
// Asset result
|
|
208
|
+
case SEARCH_RESULT_TYPES.ASSET:
|
|
209
|
+
resultTemplates.push(this.resultAssetTemplate(result[1], index));
|
|
210
|
+
break;
|
|
211
|
+
// App result
|
|
212
|
+
case SEARCH_RESULT_TYPES.APP:
|
|
213
|
+
resultTemplates.push(this.resultAppTemplate(result[1], index));
|
|
214
|
+
break;
|
|
215
|
+
// Default string result
|
|
216
|
+
default:
|
|
217
|
+
resultTemplates.push(this.resultStringTemplate(result[1], index));
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return x`<lukso-dropdown
|
|
222
|
+
size=${this.dropdownSize[this.size]}
|
|
223
|
+
is-open
|
|
224
|
+
is-open-on-outside-click
|
|
225
|
+
is-full-width
|
|
226
|
+
max-height=${this.maxHeight || E}
|
|
227
|
+
>${resultTemplates}</lukso-dropdown
|
|
228
|
+
>`;
|
|
229
|
+
}
|
|
230
|
+
noResultsTemplate() {
|
|
231
|
+
return x`<lukso-dropdown
|
|
232
|
+
size=${this.dropdownSize[this.size]}
|
|
233
|
+
is-open
|
|
234
|
+
is-open-on-outside-click
|
|
235
|
+
is-full-width
|
|
236
|
+
>${x`<div class="paragraph-inter-14-semi-bold text-neutral-20 pl-1">
|
|
237
|
+
${this.noResultsText}
|
|
238
|
+
</div>`}</lukso-dropdown
|
|
239
|
+
>`;
|
|
240
|
+
}
|
|
241
|
+
loadingTemplate() {
|
|
242
|
+
const { loading } = this.styles({
|
|
243
|
+
size: this.size
|
|
244
|
+
});
|
|
245
|
+
if (this.showNoResults) {
|
|
246
|
+
return x`<lukso-dropdown
|
|
247
|
+
size=${this.dropdownSize[this.size]}
|
|
248
|
+
is-open
|
|
249
|
+
is-open-on-outside-click
|
|
250
|
+
is-full-width
|
|
251
|
+
>${x`
|
|
252
|
+
<div role="status" class="flex flex-col gap-1">
|
|
253
|
+
<div class=${loading()}></div>
|
|
254
|
+
</div>
|
|
255
|
+
`}</lukso-dropdown
|
|
256
|
+
>`;
|
|
257
|
+
}
|
|
258
|
+
if (this.resultsParsed.length === 0 || this.resultsParsed.length > 5) {
|
|
259
|
+
return x`<lukso-dropdown
|
|
260
|
+
size=${this.dropdownSize[this.size]}
|
|
261
|
+
is-open
|
|
262
|
+
is-open-on-outside-click
|
|
263
|
+
is-full-width
|
|
264
|
+
>${x`
|
|
265
|
+
<div role="status" class="flex flex-col gap-1">
|
|
266
|
+
${[...Array(5)].map(() => x`<div class=${loading()}></div>`)}
|
|
267
|
+
</div>
|
|
268
|
+
`}</lukso-dropdown
|
|
269
|
+
>`;
|
|
270
|
+
}
|
|
271
|
+
return x`<lukso-dropdown
|
|
272
|
+
size=${this.dropdownSize[this.size]}
|
|
273
|
+
is-open
|
|
274
|
+
is-open-on-outside-click
|
|
275
|
+
is-full-width
|
|
276
|
+
>${x`
|
|
277
|
+
<div role="status" class="flex flex-col gap-1">
|
|
278
|
+
${this.resultsParsed.map(() => x`<div class=${loading()}></div>`)}
|
|
279
|
+
</div>
|
|
280
|
+
`}</lukso-dropdown
|
|
281
|
+
>`;
|
|
282
|
+
}
|
|
283
|
+
resultStringTemplate(result, index) {
|
|
284
|
+
const dropdownSize = this.size === "large" || this.size === "x-large" ? "medium" : this.size;
|
|
285
|
+
return x`<lukso-dropdown-option
|
|
286
|
+
data-id="${result.id}"
|
|
287
|
+
data-index="${index + 1}"
|
|
288
|
+
?is-selected=${this.selected === index + 1}
|
|
289
|
+
size=${dropdownSize}
|
|
290
|
+
@click=${() => this.handleSelect(result)}
|
|
291
|
+
>
|
|
292
|
+
${result.value}
|
|
293
|
+
</lukso-dropdown-option>`;
|
|
294
|
+
}
|
|
295
|
+
resultUniversalNameTemplate(result, index) {
|
|
296
|
+
const tag = x`<lukso-tag
|
|
297
|
+
is-rounded
|
|
298
|
+
background-color="${result.status ? "green-95" : "neutral-95"}"
|
|
299
|
+
text-color="${result.status ? "green-45" : "neutral-60"}"
|
|
300
|
+
>${!!result.status ? this.availableText : this.unavailableText}</lukso-tag
|
|
301
|
+
>`;
|
|
302
|
+
return x`<lukso-dropdown-option
|
|
303
|
+
data-id="${result.id}"
|
|
304
|
+
data-index="${index + 1}"
|
|
305
|
+
?is-selected=${this.selected === index + 1}
|
|
306
|
+
size=${this.dropdownSize[this.size]}
|
|
307
|
+
@click=${() => this.handleSelect(result)}
|
|
308
|
+
>
|
|
309
|
+
<div class="flex flex-row items-center justify-between w-full">
|
|
310
|
+
<div class="paragraph-inter-14-semi-bold">${result.value}</div>
|
|
311
|
+
${tag}
|
|
312
|
+
</div>
|
|
313
|
+
</lukso-dropdown-option>`;
|
|
314
|
+
}
|
|
315
|
+
resultProfileTemplate(result, index) {
|
|
316
|
+
const eoaProfilePicture = x`<lukso-profile
|
|
317
|
+
profile-address="${result.address}"
|
|
318
|
+
profile-url="${result.address ? makeBlockie(result.address) : ""}"
|
|
319
|
+
size=${this.profileSize[this.size]}
|
|
320
|
+
></lukso-profile>`;
|
|
321
|
+
const lsp3ProfilePicture = x`<lukso-profile
|
|
322
|
+
profile-address="${result.address}"
|
|
323
|
+
profile-url="${result.image}"
|
|
324
|
+
size=${this.profileSize[this.size]}
|
|
325
|
+
has-identicon
|
|
326
|
+
></lukso-profile>`;
|
|
327
|
+
const standard = result.standard || STANDARDS.LSP3;
|
|
328
|
+
const profilePicture = standard !== STANDARDS.LSP3 ? eoaProfilePicture : lsp3ProfilePicture;
|
|
329
|
+
const upProfileUsername = x`<lukso-username
|
|
330
|
+
name="${result.name?.toLowerCase() || "anonymous-profile"}"
|
|
331
|
+
address="${result.address}"
|
|
332
|
+
name-color="neutral-20"
|
|
333
|
+
max-width="300"
|
|
334
|
+
size=${this.usernameSize[this.size]}
|
|
335
|
+
?hide-prefix="${!result.name}"
|
|
336
|
+
class="ml-1"
|
|
337
|
+
></lukso-username> `;
|
|
338
|
+
const eoaUsername = x`<lukso-username
|
|
339
|
+
name="${sliceAddress(result.address, 8)}"
|
|
340
|
+
address="__EOA"
|
|
341
|
+
name-color="neutral-20"
|
|
342
|
+
max-width="300"
|
|
343
|
+
size=${this.usernameSize[this.size]}
|
|
344
|
+
hide-prefix
|
|
345
|
+
class="ml-1"
|
|
346
|
+
></lukso-username>`;
|
|
347
|
+
const scUsername = x`<lukso-username
|
|
348
|
+
name=""
|
|
349
|
+
address="${sliceAddress(result.address, 8)}"
|
|
350
|
+
name-color="neutral-20"
|
|
351
|
+
max-width="300"
|
|
352
|
+
size=${this.usernameSize[this.size]}
|
|
353
|
+
hide-prefix
|
|
354
|
+
class="ml-1"
|
|
355
|
+
></lukso-username>`;
|
|
356
|
+
let profileName = scUsername;
|
|
357
|
+
if (standard === STANDARDS.EOA) {
|
|
358
|
+
profileName = eoaUsername;
|
|
359
|
+
} else if (standard === STANDARDS.LSP3) {
|
|
360
|
+
profileName = upProfileUsername;
|
|
361
|
+
}
|
|
362
|
+
return x`<lukso-dropdown-option
|
|
363
|
+
data-id="${result.address}"
|
|
364
|
+
data-index="${index + 1}"
|
|
365
|
+
?is-selected=${this.selected === index + 1}
|
|
366
|
+
size=${this.dropdownSize[this.size]}
|
|
367
|
+
@click=${() => this.handleSelect(result)}
|
|
368
|
+
>
|
|
369
|
+
${profilePicture} ${profileName}
|
|
370
|
+
</lukso-dropdown-option>`;
|
|
371
|
+
}
|
|
372
|
+
resultAssetTemplate(result, index) {
|
|
373
|
+
return x`<lukso-dropdown-option
|
|
374
|
+
data-id="${result.address}"
|
|
375
|
+
data-index="${index + 1}"
|
|
376
|
+
?is-selected=${this.selected === index + 1}
|
|
377
|
+
size=${this.dropdownSize[this.size]}
|
|
378
|
+
@click=${() => this.handleSelect(result)}
|
|
379
|
+
>
|
|
380
|
+
<lukso-profile
|
|
381
|
+
profile-address="${result.address}"
|
|
382
|
+
profile-url="${result.image}"
|
|
383
|
+
placeholder="/assets/images/token-default.svg"
|
|
384
|
+
size=${this.profileSize[this.size]}
|
|
385
|
+
></lukso-profile>
|
|
386
|
+
<span class="paragraph-inter-14-semi-bold ${this.textSize[this.size]}"
|
|
387
|
+
>${result.name}
|
|
388
|
+
<span
|
|
389
|
+
class="text-neutral-60 paragraph-inter-14-regular ${this.textSize[this.size]}"
|
|
390
|
+
>${result.symbol}</span
|
|
391
|
+
></span
|
|
392
|
+
>
|
|
393
|
+
</lukso-dropdown-option>`;
|
|
394
|
+
}
|
|
395
|
+
resultAppTemplate(result, index) {
|
|
396
|
+
return x`<lukso-dropdown-option
|
|
397
|
+
data-id="${result.address}"
|
|
398
|
+
data-index="${index + 1}"
|
|
399
|
+
?is-selected=${this.selected === index + 1}
|
|
400
|
+
size=${this.dropdownSize[this.size]}
|
|
401
|
+
@click=${() => this.handleSelect(result)}
|
|
402
|
+
>
|
|
403
|
+
<lukso-profile
|
|
404
|
+
profile-address="${result.address}"
|
|
405
|
+
profile-url="${result.image}"
|
|
406
|
+
size=${this.profileSize[this.size]}
|
|
407
|
+
></lukso-profile>
|
|
408
|
+
<span class="paragraph-inter-14-semi-bold ${this.textSize[this.size]}"
|
|
409
|
+
>${result.name}
|
|
410
|
+
</span>
|
|
411
|
+
</lukso-dropdown-option>`;
|
|
412
|
+
}
|
|
413
|
+
async handleOutsideDropdownClick(event) {
|
|
414
|
+
const element = event.target;
|
|
415
|
+
if (element?.dataset?.component === "lukso-search") {
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
this.results = "";
|
|
419
|
+
}
|
|
420
|
+
async handleDropdownKeydown(event) {
|
|
421
|
+
if (event.key === "ArrowUp" && this.selected && this.selected > 1 && this.resultsParsed?.length) {
|
|
422
|
+
event.preventDefault();
|
|
423
|
+
this.selected = this.selected - 1;
|
|
424
|
+
}
|
|
425
|
+
if (event.key === "ArrowDown" && this.resultsParsed?.length) {
|
|
426
|
+
event.preventDefault();
|
|
427
|
+
if (!this.selected) {
|
|
428
|
+
this.selected = 1;
|
|
429
|
+
} else if (this.selected < this.resultsParsed.length) {
|
|
430
|
+
this.selected = this.selected + 1;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
if (event.key === "Enter" && this.resultsParsed?.length) {
|
|
434
|
+
if (this.selected) {
|
|
435
|
+
const selectedResult = this.resultsParsed[this.selected - 1];
|
|
436
|
+
await this.handleSelect(selectedResult);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
if (event.key === "Escape") {
|
|
440
|
+
this.results = "";
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
async handleSelect(result) {
|
|
444
|
+
await this.updateComplete;
|
|
445
|
+
const selectEvent = new CustomEvent("on-select", {
|
|
446
|
+
detail: {
|
|
447
|
+
value: result
|
|
448
|
+
},
|
|
449
|
+
bubbles: false,
|
|
450
|
+
composed: true
|
|
451
|
+
});
|
|
452
|
+
this.dispatchEvent(selectEvent);
|
|
453
|
+
}
|
|
454
|
+
async handleBlur(event) {
|
|
455
|
+
event.stopPropagation();
|
|
456
|
+
await this.updateComplete;
|
|
457
|
+
const target = event.target;
|
|
458
|
+
const blurEvent = new CustomEvent("on-blur", {
|
|
459
|
+
detail: {
|
|
460
|
+
value: target.value,
|
|
461
|
+
event
|
|
462
|
+
},
|
|
463
|
+
bubbles: false,
|
|
464
|
+
composed: true
|
|
465
|
+
});
|
|
466
|
+
this.dispatchEvent(blurEvent);
|
|
467
|
+
}
|
|
468
|
+
async handleInputClick(event) {
|
|
469
|
+
event.stopPropagation();
|
|
470
|
+
await this.updateComplete;
|
|
471
|
+
const target = event.target;
|
|
472
|
+
const clickEvent = new CustomEvent("on-input-click", {
|
|
473
|
+
detail: {
|
|
474
|
+
value: target.value,
|
|
475
|
+
event
|
|
476
|
+
},
|
|
477
|
+
bubbles: false,
|
|
478
|
+
composed: true
|
|
479
|
+
});
|
|
480
|
+
this.dispatchEvent(clickEvent);
|
|
481
|
+
}
|
|
482
|
+
async handleKeyUp(event) {
|
|
483
|
+
event.stopPropagation();
|
|
484
|
+
await this.updateComplete;
|
|
485
|
+
const value = event?.detail?.value;
|
|
486
|
+
if (!this.keepValueOnEscapeHit && event?.detail?.event?.key === "Escape") {
|
|
487
|
+
this.value = "";
|
|
488
|
+
event.detail.value = "";
|
|
489
|
+
this.handleSearch(event);
|
|
490
|
+
}
|
|
491
|
+
const keyEvent = new CustomEvent("on-key-up", {
|
|
492
|
+
detail: {
|
|
493
|
+
value,
|
|
494
|
+
event
|
|
495
|
+
},
|
|
496
|
+
bubbles: true,
|
|
497
|
+
composed: true
|
|
498
|
+
});
|
|
499
|
+
this.dispatchEvent(keyEvent);
|
|
500
|
+
}
|
|
501
|
+
async handleReset(event) {
|
|
502
|
+
if (!this.hasReset) {
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
await this.updateComplete;
|
|
506
|
+
this.value = "";
|
|
507
|
+
const target = event.target;
|
|
508
|
+
const clickEvent = new CustomEvent("on-reset", {
|
|
509
|
+
detail: {
|
|
510
|
+
value: target.value,
|
|
511
|
+
event
|
|
512
|
+
},
|
|
513
|
+
bubbles: false,
|
|
514
|
+
composed: true
|
|
515
|
+
});
|
|
516
|
+
this.dispatchEvent(clickEvent);
|
|
517
|
+
}
|
|
518
|
+
async searchDebounce(searchTerm) {
|
|
519
|
+
await this.updateComplete;
|
|
520
|
+
this.value = searchTerm;
|
|
521
|
+
this.debounceTimer = setTimeout(() => {
|
|
522
|
+
const changeEvent = new CustomEvent("on-search", {
|
|
523
|
+
detail: {
|
|
524
|
+
value: searchTerm
|
|
525
|
+
},
|
|
526
|
+
bubbles: false,
|
|
527
|
+
composed: true
|
|
528
|
+
});
|
|
529
|
+
this.dispatchEvent(changeEvent);
|
|
530
|
+
this.isDebouncing = false;
|
|
531
|
+
}, this.debounce);
|
|
532
|
+
}
|
|
533
|
+
handleSearch(event) {
|
|
534
|
+
if (this.isDebouncing) {
|
|
535
|
+
clearTimeout(this.debounceTimer);
|
|
536
|
+
}
|
|
537
|
+
this.isDebouncing = true;
|
|
538
|
+
const target = event.target;
|
|
539
|
+
this.searchDebounce(target.value);
|
|
540
|
+
}
|
|
541
|
+
render() {
|
|
542
|
+
return x`
|
|
543
|
+
<div class="relative w-full">
|
|
544
|
+
<lukso-input
|
|
545
|
+
name=${this.name}
|
|
546
|
+
type="text"
|
|
547
|
+
.value=${this.value}
|
|
548
|
+
placeholder=${this.placeholder}
|
|
549
|
+
autocomplete=${this.autocomplete}
|
|
550
|
+
label=${this.label}
|
|
551
|
+
description=${this.description}
|
|
552
|
+
error=${this.error}
|
|
553
|
+
custom-class=${this.customClass}
|
|
554
|
+
id=${this.id}
|
|
555
|
+
size=${this.size}
|
|
556
|
+
data-component="lukso-search"
|
|
557
|
+
right-icon="${this.hasReset && this.value ? "close-sm" : this.rightIcon}"
|
|
558
|
+
?is-right-icon-clickable=${this.hasReset && this.value}
|
|
559
|
+
?autofocus=${this.autofocus}
|
|
560
|
+
?is-readonly=${this.isReadonly}
|
|
561
|
+
?is-disabled=${this.isDisabled}
|
|
562
|
+
?is-full-width=${this.isFullWidth}
|
|
563
|
+
keep-focus-on-escape
|
|
564
|
+
@on-input=${this.handleSearch}
|
|
565
|
+
@on-blur=${this.handleBlur}
|
|
566
|
+
@on-input-click=${this.handleInputClick}
|
|
567
|
+
@on-right-icon-click=${this.handleReset}
|
|
568
|
+
@on-key-up=${this.handleKeyUp}
|
|
569
|
+
></lukso-input>
|
|
570
|
+
<!-- results dropdown -->
|
|
571
|
+
${this.results && !(this.isSearching || this.isDebouncing) ? this.resultsTemplate() : E}
|
|
572
|
+
<!-- no results dropdown -->
|
|
573
|
+
${this.showNoResults && !(this.isSearching || this.isDebouncing) ? this.noResultsTemplate() : E}
|
|
574
|
+
<!-- loading dropdown -->
|
|
575
|
+
${!this.hideLoading && this.value && (this.isSearching || this.isDebouncing) ? this.loadingTemplate() : E}
|
|
576
|
+
</div>
|
|
577
|
+
`;
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
__decorateClass([
|
|
581
|
+
n({ type: String })
|
|
582
|
+
], LuksoSearch.prototype, "value", 2);
|
|
583
|
+
__decorateClass([
|
|
584
|
+
n({ type: String })
|
|
585
|
+
], LuksoSearch.prototype, "name", 2);
|
|
586
|
+
__decorateClass([
|
|
587
|
+
n({ type: String })
|
|
588
|
+
], LuksoSearch.prototype, "placeholder", 2);
|
|
589
|
+
__decorateClass([
|
|
590
|
+
n({ type: String })
|
|
591
|
+
], LuksoSearch.prototype, "label", 2);
|
|
592
|
+
__decorateClass([
|
|
593
|
+
n({ type: String, attribute: "group-labels" })
|
|
594
|
+
], LuksoSearch.prototype, "groupLabels", 2);
|
|
595
|
+
__decorateClass([
|
|
596
|
+
n({ type: String, attribute: "available-text" })
|
|
597
|
+
], LuksoSearch.prototype, "availableText", 2);
|
|
598
|
+
__decorateClass([
|
|
599
|
+
n({ type: String, attribute: "unavailable-text" })
|
|
600
|
+
], LuksoSearch.prototype, "unavailableText", 2);
|
|
601
|
+
__decorateClass([
|
|
602
|
+
n({ type: String })
|
|
603
|
+
], LuksoSearch.prototype, "autocomplete", 2);
|
|
604
|
+
__decorateClass([
|
|
605
|
+
n({ type: String })
|
|
606
|
+
], LuksoSearch.prototype, "id", 2);
|
|
607
|
+
__decorateClass([
|
|
608
|
+
n({ type: String })
|
|
609
|
+
], LuksoSearch.prototype, "description", 2);
|
|
610
|
+
__decorateClass([
|
|
611
|
+
n({ type: String })
|
|
612
|
+
], LuksoSearch.prototype, "error", 2);
|
|
613
|
+
__decorateClass([
|
|
614
|
+
n({ type: String, attribute: "custom-class" })
|
|
615
|
+
], LuksoSearch.prototype, "customClass", 2);
|
|
616
|
+
__decorateClass([
|
|
617
|
+
n({ type: Boolean, attribute: "is-full-width" })
|
|
618
|
+
], LuksoSearch.prototype, "isFullWidth", 2);
|
|
619
|
+
__decorateClass([
|
|
620
|
+
n({ type: Boolean, attribute: "is-readonly" })
|
|
621
|
+
], LuksoSearch.prototype, "isReadonly", 2);
|
|
622
|
+
__decorateClass([
|
|
623
|
+
n({ type: Boolean, attribute: "is-disabled" })
|
|
624
|
+
], LuksoSearch.prototype, "isDisabled", 2);
|
|
625
|
+
__decorateClass([
|
|
626
|
+
n({ type: Boolean })
|
|
627
|
+
], LuksoSearch.prototype, "autofocus", 2);
|
|
628
|
+
__decorateClass([
|
|
629
|
+
n({ type: Boolean })
|
|
630
|
+
], LuksoSearch.prototype, "borderless", 2);
|
|
631
|
+
__decorateClass([
|
|
632
|
+
n({ type: String })
|
|
633
|
+
], LuksoSearch.prototype, "results", 2);
|
|
634
|
+
__decorateClass([
|
|
635
|
+
n({ type: String, attribute: "right-icon" })
|
|
636
|
+
], LuksoSearch.prototype, "rightIcon", 2);
|
|
637
|
+
__decorateClass([
|
|
638
|
+
n({ type: Number })
|
|
639
|
+
], LuksoSearch.prototype, "debounce", 2);
|
|
640
|
+
__decorateClass([
|
|
641
|
+
n({ type: Boolean, attribute: "is-searching" })
|
|
642
|
+
], LuksoSearch.prototype, "isSearching", 2);
|
|
643
|
+
__decorateClass([
|
|
644
|
+
n({ type: String, attribute: "no-results-text" })
|
|
645
|
+
], LuksoSearch.prototype, "noResultsText", 2);
|
|
646
|
+
__decorateClass([
|
|
647
|
+
n({ type: Boolean, attribute: "show-no-results" })
|
|
648
|
+
], LuksoSearch.prototype, "showNoResults", 2);
|
|
649
|
+
__decorateClass([
|
|
650
|
+
n({ type: Boolean, attribute: "hide-loading" })
|
|
651
|
+
], LuksoSearch.prototype, "hideLoading", 2);
|
|
652
|
+
__decorateClass([
|
|
653
|
+
n({ type: Boolean, attribute: "has-reset" })
|
|
654
|
+
], LuksoSearch.prototype, "hasReset", 2);
|
|
655
|
+
__decorateClass([
|
|
656
|
+
n({ type: Boolean, attribute: "keep-value-on-escape-hit" })
|
|
657
|
+
], LuksoSearch.prototype, "keepValueOnEscapeHit", 2);
|
|
658
|
+
__decorateClass([
|
|
659
|
+
n({ type: Number })
|
|
660
|
+
], LuksoSearch.prototype, "selected", 2);
|
|
661
|
+
__decorateClass([
|
|
662
|
+
n({ type: String })
|
|
663
|
+
], LuksoSearch.prototype, "size", 2);
|
|
664
|
+
__decorateClass([
|
|
665
|
+
n({ type: Number, attribute: "max-height" })
|
|
666
|
+
], LuksoSearch.prototype, "maxHeight", 2);
|
|
667
|
+
__decorateClass([
|
|
668
|
+
r()
|
|
669
|
+
], LuksoSearch.prototype, "isDebouncing", 2);
|
|
670
|
+
__decorateClass([
|
|
671
|
+
r()
|
|
672
|
+
], LuksoSearch.prototype, "debounceTimer", 2);
|
|
673
|
+
__decorateClass([
|
|
674
|
+
r()
|
|
675
|
+
], LuksoSearch.prototype, "resultsParsed", 2);
|
|
676
|
+
LuksoSearch = __decorateClass([
|
|
677
|
+
t("lukso-search")
|
|
678
|
+
], LuksoSearch);
|
|
679
|
+
|
|
680
|
+
export { LuksoSearch as L, STANDARDS as S, SEARCH_RESULT_TYPES as a };
|