@lemonadejs/dropdown 3.2.1 → 3.5.0
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/index.js +55 -30
- package/dist/react.d.ts +4 -1
- package/dist/style.css +3 -5
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -242,7 +242,7 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
-
const Dropdown = function () {
|
|
245
|
+
const Dropdown = function (html) {
|
|
246
246
|
let self = this;
|
|
247
247
|
// Internal value controllers
|
|
248
248
|
let value = [];
|
|
@@ -256,6 +256,29 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
256
256
|
}
|
|
257
257
|
// Lazy loading global instance
|
|
258
258
|
let lazyloading = null;
|
|
259
|
+
|
|
260
|
+
// Data
|
|
261
|
+
if (! Array.isArray(self.data)) {
|
|
262
|
+
self.data = [];
|
|
263
|
+
}
|
|
264
|
+
let data = JSON.parse(JSON.stringify(self.data));
|
|
265
|
+
|
|
266
|
+
if (html) {
|
|
267
|
+
let select = document.createElement('select');
|
|
268
|
+
select.innerHTML = html.trim();
|
|
269
|
+
for (let i = 0; i < select.children.length; i++) {
|
|
270
|
+
let option = select.children[i];
|
|
271
|
+
if (option.tagName === 'OPTION') {
|
|
272
|
+
let text = option.textContent;
|
|
273
|
+
let value = option.getAttribute('value');
|
|
274
|
+
if (value === null) {
|
|
275
|
+
value = text;
|
|
276
|
+
}
|
|
277
|
+
self.data.push({ text: text, value: value });
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
259
282
|
// Custom events defined by the user
|
|
260
283
|
let onload = self.onload;
|
|
261
284
|
let onchange = self.onchange;
|
|
@@ -332,9 +355,11 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
332
355
|
const setData = function () {
|
|
333
356
|
// Estimate width
|
|
334
357
|
let width = self.width;
|
|
358
|
+
// Data
|
|
359
|
+
data = JSON.parse(JSON.stringify(self.data));
|
|
335
360
|
// Re-order to make sure groups are in sequence
|
|
336
|
-
if (
|
|
337
|
-
|
|
361
|
+
if (data && data.length) {
|
|
362
|
+
data.sort((a, b) => {
|
|
338
363
|
// Compare groups
|
|
339
364
|
if (a.group && b.group) {
|
|
340
365
|
return a.group.localeCompare(b.group);
|
|
@@ -343,7 +368,7 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
343
368
|
});
|
|
344
369
|
let group = '';
|
|
345
370
|
// Define group headers
|
|
346
|
-
|
|
371
|
+
data.map((v) => {
|
|
347
372
|
// Compare groups
|
|
348
373
|
if (v && v.group && v.group !== group) {
|
|
349
374
|
v.header = true;
|
|
@@ -351,7 +376,7 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
351
376
|
}
|
|
352
377
|
});
|
|
353
378
|
// Width && values
|
|
354
|
-
|
|
379
|
+
data.map(function (s) {
|
|
355
380
|
// Estimated width of the element
|
|
356
381
|
if (s.text) {
|
|
357
382
|
width = Math.max(width, s.text.length * 8);
|
|
@@ -375,7 +400,7 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
375
400
|
self.animation = true;
|
|
376
401
|
}
|
|
377
402
|
// Data to be listed
|
|
378
|
-
self.rows =
|
|
403
|
+
self.rows = data;
|
|
379
404
|
}
|
|
380
405
|
|
|
381
406
|
const updateLabel = function () {
|
|
@@ -386,7 +411,7 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
386
411
|
}
|
|
387
412
|
}
|
|
388
413
|
|
|
389
|
-
const setValue = function (v) {
|
|
414
|
+
const setValue = function (v, ignoreEvent) {
|
|
390
415
|
// Values
|
|
391
416
|
let newValue;
|
|
392
417
|
if (!Array.isArray(v)) {
|
|
@@ -402,8 +427,8 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
402
427
|
// Width && values
|
|
403
428
|
value = [];
|
|
404
429
|
|
|
405
|
-
if (Array.isArray(
|
|
406
|
-
|
|
430
|
+
if (Array.isArray(data)) {
|
|
431
|
+
data.map(function (s) {
|
|
407
432
|
// Select values
|
|
408
433
|
if (newValue.indexOf(s.value) !== -1) {
|
|
409
434
|
s.selected = true;
|
|
@@ -418,7 +443,7 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
418
443
|
updateLabel();
|
|
419
444
|
|
|
420
445
|
// Component onchange
|
|
421
|
-
if (typeof
|
|
446
|
+
if (! ignoreEvent && typeof(onchange) === 'function') {
|
|
422
447
|
onchange.call(self, self, getValue());
|
|
423
448
|
}
|
|
424
449
|
}
|
|
@@ -444,7 +469,7 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
444
469
|
// Reset search
|
|
445
470
|
if (self.autocomplete) {
|
|
446
471
|
// Go to begin of the data
|
|
447
|
-
self.rows =
|
|
472
|
+
self.rows = data;
|
|
448
473
|
// Remove editable attribute
|
|
449
474
|
self.input.removeAttribute('contenteditable');
|
|
450
475
|
// Clear input
|
|
@@ -498,7 +523,6 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
498
523
|
}
|
|
499
524
|
}
|
|
500
525
|
|
|
501
|
-
|
|
502
526
|
self.add = async function (e) {
|
|
503
527
|
if (!self.input.textContent) {
|
|
504
528
|
return false;
|
|
@@ -526,7 +550,7 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
526
550
|
}
|
|
527
551
|
|
|
528
552
|
// Process the data
|
|
529
|
-
|
|
553
|
+
data.push(s);
|
|
530
554
|
// Select the new item
|
|
531
555
|
self.select(e, s);
|
|
532
556
|
// Close dropdown
|
|
@@ -541,11 +565,11 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
541
565
|
self.search = function (e) {
|
|
542
566
|
if (self.state && self.autocomplete) {
|
|
543
567
|
// Filter options
|
|
544
|
-
let
|
|
545
|
-
if (!self.input.textContent) {
|
|
546
|
-
|
|
568
|
+
let temp;
|
|
569
|
+
if (! self.input.textContent) {
|
|
570
|
+
temp = self.data;
|
|
547
571
|
} else {
|
|
548
|
-
|
|
572
|
+
temp = self.data.filter(item => {
|
|
549
573
|
return item.selected === true ||
|
|
550
574
|
(item.text.toLowerCase().includes(self.input.textContent.toLowerCase())) ||
|
|
551
575
|
(item.group && item.group.toLowerCase().includes(self.input.textContent.toLowerCase()));
|
|
@@ -554,7 +578,7 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
554
578
|
// Cursor
|
|
555
579
|
removeCursor(true);
|
|
556
580
|
// Update the data from the dropdown
|
|
557
|
-
self.rows =
|
|
581
|
+
self.rows = temp;
|
|
558
582
|
}
|
|
559
583
|
}
|
|
560
584
|
|
|
@@ -661,17 +685,13 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
661
685
|
self.input.remove();
|
|
662
686
|
}
|
|
663
687
|
|
|
664
|
-
if (
|
|
665
|
-
self.data = [];
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
if (self.url && self.data.length === 0) {
|
|
688
|
+
if (self.url && data.length === 0) {
|
|
669
689
|
const xhr = new XMLHttpRequest();
|
|
670
690
|
|
|
671
691
|
xhr.onreadystatechange = function () {
|
|
672
692
|
if (xhr.readyState === 4) {
|
|
673
693
|
if (xhr.status === 200) {
|
|
674
|
-
|
|
694
|
+
data = JSON.parse(xhr.responseText);
|
|
675
695
|
} else {
|
|
676
696
|
console.error('Failed to fetch data. Status code: ' + xhr.status);
|
|
677
697
|
}
|
|
@@ -689,21 +709,21 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
689
709
|
setData();
|
|
690
710
|
// Set value
|
|
691
711
|
if (typeof (self.value) !== 'undefined') {
|
|
692
|
-
setValue(self.value);
|
|
712
|
+
setValue(self.value, true);
|
|
693
713
|
}
|
|
694
714
|
// Focus out of the component
|
|
695
715
|
self.el.addEventListener('focusout', function (e) {
|
|
696
716
|
if (self.modal) {
|
|
697
717
|
if (!(e.relatedTarget && self.el.contains(e.relatedTarget)) && !self.el.contains(e.relatedTarget)) {
|
|
698
718
|
if (!self.modal.closed) {
|
|
699
|
-
|
|
719
|
+
self.modal.closed = true;
|
|
700
720
|
}
|
|
701
721
|
}
|
|
702
722
|
}
|
|
703
|
-
})
|
|
723
|
+
});
|
|
704
724
|
// Key events
|
|
705
725
|
self.el.addEventListener('keydown', function (e) {
|
|
706
|
-
if (!self.modal.closed) {
|
|
726
|
+
if (! self.modal.closed) {
|
|
707
727
|
let prevent = false;
|
|
708
728
|
if (e.key === 'ArrowUp') {
|
|
709
729
|
moveCursor(-1);
|
|
@@ -724,6 +744,9 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
724
744
|
} else if (e.key === 'Enter') {
|
|
725
745
|
self.select(e, self.rows[cursor]);
|
|
726
746
|
prevent = true;
|
|
747
|
+
} else if (e.key === 'Escape') {
|
|
748
|
+
self.modal.closed = true;
|
|
749
|
+
prevent = true;
|
|
727
750
|
} else {
|
|
728
751
|
if (e.keyCode === 32 && !self.autocomplete) {
|
|
729
752
|
self.select(e, self.rows[cursor]);
|
|
@@ -735,7 +758,7 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
735
758
|
e.stopImmediatePropagation();
|
|
736
759
|
}
|
|
737
760
|
} else {
|
|
738
|
-
if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
|
|
761
|
+
if (e.key === 'ArrowUp' || e.key === 'ArrowDown' || e.key === 'Enter') {
|
|
739
762
|
self.modal.closed = false;
|
|
740
763
|
}
|
|
741
764
|
}
|
|
@@ -777,7 +800,7 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
777
800
|
|
|
778
801
|
return `<div class="lm-dropdown" data-insert="{{self.insert}}" data-type="{{self.type}}" data-state="{{self.state}}" :value="self.value" :data="self.data">
|
|
779
802
|
<div class="lm-dropdown-header">
|
|
780
|
-
<div class="lm-dropdown-input" onpaste="self.onpaste" oninput="self.search"
|
|
803
|
+
<div class="lm-dropdown-input" onpaste="self.onpaste" oninput="self.search" onmousedown="self.click" placeholder="{{self.placeholder}}" :ref="self.input" tabindex="0"></div>
|
|
781
804
|
<div class="lm-dropdown-add" onmousedown="self.add"></div>
|
|
782
805
|
<div class="lm-dropdown-header-controls">
|
|
783
806
|
<button onclick="self.close" class="lm-dropdown-done">Done</button>
|
|
@@ -797,6 +820,8 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
797
820
|
|
|
798
821
|
lemonade.setComponents({ Dropdown: Dropdown });
|
|
799
822
|
|
|
823
|
+
lemonade.createWebComponent('dropdown', Dropdown);
|
|
824
|
+
|
|
800
825
|
return function (root, options) {
|
|
801
826
|
if (typeof (root) === 'object') {
|
|
802
827
|
lemonade.render(Dropdown, root, options)
|
package/dist/react.d.ts
CHANGED
|
@@ -6,10 +6,13 @@
|
|
|
6
6
|
import Component from './index';
|
|
7
7
|
|
|
8
8
|
interface Dropdown {
|
|
9
|
+
ref?: MutableRefObject<undefined>;
|
|
9
10
|
(): any
|
|
10
11
|
[key: string]: any
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
type Props = IntrinsicAttributes & Component.Options & Dropdown;
|
|
15
|
+
|
|
16
|
+
declare function Dropdown<Dropdown>(props: Props): any;
|
|
14
17
|
|
|
15
18
|
export default Dropdown;
|
package/dist/style.css
CHANGED
|
@@ -40,12 +40,8 @@
|
|
|
40
40
|
border-radius: 0;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
.lm-dropdown .lm-lazy {
|
|
44
|
-
max-height: 300px;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
43
|
.lm-dropdown-input {
|
|
48
|
-
padding:
|
|
44
|
+
padding: var(--lm-input-padding, 6px) 24px var(--lm-input-padding, 6px) 10px;
|
|
49
45
|
white-space: nowrap;
|
|
50
46
|
overflow: hidden;
|
|
51
47
|
text-overflow: ellipsis;
|
|
@@ -311,7 +307,9 @@
|
|
|
311
307
|
}
|
|
312
308
|
|
|
313
309
|
.lm-dropdown .lm-lazy {
|
|
310
|
+
max-height: 300px;
|
|
314
311
|
scrollbar-width: thin;
|
|
312
|
+
padding-bottom: 5px;
|
|
315
313
|
}
|
|
316
314
|
|
|
317
315
|
.lm-dropdown .lm-lazy::-webkit-scrollbar {
|
package/package.json
CHANGED
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
"javascript plugins"
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"lemonadejs": "^4.
|
|
18
|
-
"@lemonadejs/modal": "^2.
|
|
17
|
+
"lemonadejs": "^4.3.3",
|
|
18
|
+
"@lemonadejs/modal": "^3.2.0"
|
|
19
19
|
},
|
|
20
20
|
"main": "dist/index.js",
|
|
21
21
|
"types": "dist/index.d.ts",
|
|
22
|
-
"version": "3.
|
|
22
|
+
"version": "3.5.0"
|
|
23
23
|
}
|