@aquera/nile-elements 2.0.26 → 2.0.27
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/README.md +7 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.js +441 -418
- package/dist/nile-calendar/nile-calendar.cjs.js +1 -1
- package/dist/nile-calendar/nile-calendar.cjs.js.map +1 -1
- package/dist/nile-calendar/nile-calendar.esm.js +1 -1
- package/dist/nile-code-editor/nile-code-editor.cjs.js +2 -2
- package/dist/nile-code-editor/nile-code-editor.cjs.js.map +1 -1
- package/dist/nile-code-editor/nile-code-editor.esm.js +5 -5
- package/dist/nile-combobox/nile-combobox.cjs.js +1 -1
- package/dist/nile-combobox/nile-combobox.cjs.js.map +1 -1
- package/dist/nile-combobox/nile-combobox.css.cjs.js +1 -1
- package/dist/nile-combobox/nile-combobox.css.cjs.js.map +1 -1
- package/dist/nile-combobox/nile-combobox.css.esm.js +2 -0
- package/dist/nile-combobox/nile-combobox.esm.js +1 -1
- package/dist/nile-detail/nile-detail.cjs.js +1 -1
- package/dist/nile-detail/nile-detail.cjs.js.map +1 -1
- package/dist/nile-detail/nile-detail.esm.js +6 -5
- package/dist/nile-select/index.cjs.js +1 -1
- package/dist/nile-select/index.esm.js +1 -1
- package/dist/nile-select/nile-select.cjs.js +1 -1
- package/dist/nile-select/nile-select.cjs.js.map +1 -1
- package/dist/nile-select/nile-select.esm.js +1 -1
- package/dist/nile-virtual-select/index.cjs.js +1 -1
- package/dist/nile-virtual-select/index.esm.js +1 -1
- package/dist/nile-virtual-select/nile-virtual-select.cjs.js +4 -4
- package/dist/nile-virtual-select/nile-virtual-select.cjs.js.map +1 -1
- package/dist/nile-virtual-select/nile-virtual-select.css.cjs.js +1 -1
- package/dist/nile-virtual-select/nile-virtual-select.css.cjs.js.map +1 -1
- package/dist/nile-virtual-select/nile-virtual-select.css.esm.js +19 -5
- package/dist/nile-virtual-select/nile-virtual-select.esm.js +5 -5
- package/dist/nile-virtual-select/renderer.cjs.js +1 -1
- package/dist/nile-virtual-select/renderer.cjs.js.map +1 -1
- package/dist/nile-virtual-select/renderer.esm.js +23 -22
- package/dist/src/nile-calendar/nile-calendar.d.ts +4 -0
- package/dist/src/nile-calendar/nile-calendar.js +18 -2
- package/dist/src/nile-calendar/nile-calendar.js.map +1 -1
- package/dist/src/nile-calendar/nile-calendar.test.js +50 -0
- package/dist/src/nile-calendar/nile-calendar.test.js.map +1 -1
- package/dist/src/nile-code-editor/nile-code-editor.d.ts +12 -0
- package/dist/src/nile-code-editor/nile-code-editor.js +92 -0
- package/dist/src/nile-code-editor/nile-code-editor.js.map +1 -1
- package/dist/src/nile-combobox/nile-combobox.css.js +2 -0
- package/dist/src/nile-combobox/nile-combobox.css.js.map +1 -1
- package/dist/src/nile-combobox/nile-combobox.d.ts +1 -0
- package/dist/src/nile-combobox/nile-combobox.js +12 -1
- package/dist/src/nile-combobox/nile-combobox.js.map +1 -1
- package/dist/src/nile-combobox/nile-combobox.test.js +375 -0
- package/dist/src/nile-combobox/nile-combobox.test.js.map +1 -1
- package/dist/src/nile-detail/nile-detail.d.ts +4 -0
- package/dist/src/nile-detail/nile-detail.js +35 -3
- package/dist/src/nile-detail/nile-detail.js.map +1 -1
- package/dist/src/nile-virtual-select/nile-virtual-select.css.js +19 -5
- package/dist/src/nile-virtual-select/nile-virtual-select.css.js.map +1 -1
- package/dist/src/nile-virtual-select/nile-virtual-select.d.ts +29 -0
- package/dist/src/nile-virtual-select/nile-virtual-select.js +120 -13
- package/dist/src/nile-virtual-select/nile-virtual-select.js.map +1 -1
- package/dist/src/nile-virtual-select/nile-virtual-select.test.js +187 -2
- package/dist/src/nile-virtual-select/nile-virtual-select.test.js.map +1 -1
- package/dist/src/nile-virtual-select/renderer.d.ts +1 -1
- package/dist/src/nile-virtual-select/renderer.js +11 -4
- package/dist/src/nile-virtual-select/renderer.js.map +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/nile-calendar/nile-calendar.test.ts +54 -0
- package/src/nile-calendar/nile-calendar.ts +17 -3
- package/src/nile-code-editor/nile-code-editor.ts +82 -0
- package/src/nile-combobox/nile-combobox.css.ts +2 -0
- package/src/nile-combobox/nile-combobox.test.ts +416 -0
- package/src/nile-combobox/nile-combobox.ts +11 -1
- package/src/nile-detail/nile-detail.ts +34 -3
- package/src/nile-virtual-select/nile-virtual-select.css.ts +19 -5
- package/src/nile-virtual-select/nile-virtual-select.test.ts +230 -2
- package/src/nile-virtual-select/nile-virtual-select.ts +117 -11
- package/src/nile-virtual-select/renderer.ts +12 -5
- package/vscode-html-custom-data.json +14 -4
|
@@ -959,14 +959,242 @@ describe('NileVirtualSelect external value while Selected is open', () => {
|
|
|
959
959
|
expect(el.data.length).to.equal(200);
|
|
960
960
|
});
|
|
961
961
|
|
|
962
|
-
it('E4. showtooltip: a
|
|
962
|
+
it('E4. showtooltip: a direct uncheck in the Selected view removes that item (GI-3101)', async () => {
|
|
963
963
|
const el = await mount(true);
|
|
964
964
|
await toggleSelected(el);
|
|
965
965
|
|
|
966
966
|
await pick(el, 'option-2');
|
|
967
967
|
|
|
968
968
|
expect(el.value).to.deep.equal(['option-1']);
|
|
969
|
-
expect(
|
|
969
|
+
expect(el.showSelected).to.be.true;
|
|
970
|
+
expect(values(el)).to.deep.equal(['option-1']);
|
|
971
|
+
});
|
|
972
|
+
|
|
973
|
+
describe('GI-3101: Show Selected stays in sync after a user unselect', () => {
|
|
974
|
+
it('F1. unselecting one of A,B,C leaves exactly A,C and Show Selected on', async () => {
|
|
975
|
+
const el = await mount(false, ['option-1', 'option-2', 'option-3']);
|
|
976
|
+
await toggleSelected(el);
|
|
977
|
+
expect(values(el)).to.deep.equal(['option-1', 'option-2', 'option-3']);
|
|
978
|
+
|
|
979
|
+
await pick(el, 'option-2');
|
|
980
|
+
|
|
981
|
+
expect(el.showSelected).to.be.true;
|
|
982
|
+
expect(values(el)).to.deep.equal(['option-1', 'option-3']);
|
|
983
|
+
});
|
|
984
|
+
|
|
985
|
+
it('F2. unselected options never reappear, even after the consumer reassigns data', async () => {
|
|
986
|
+
const el = await mount(false, ['option-1', 'option-2', 'option-3']);
|
|
987
|
+
await toggleSelected(el);
|
|
988
|
+
await pick(el, 'option-2');
|
|
989
|
+
|
|
990
|
+
el.data = [...OPTIONS]; // lookup refresh / paging hands back the full list
|
|
991
|
+
await el.updateComplete;
|
|
992
|
+
await aTimeout(30);
|
|
993
|
+
|
|
994
|
+
expect(el.showSelected).to.be.true;
|
|
995
|
+
expect(values(el)).to.deep.equal(['option-1', 'option-3']);
|
|
996
|
+
});
|
|
997
|
+
|
|
998
|
+
it('F3. removing several selected items one after another keeps working', async () => {
|
|
999
|
+
const el = await mount(false, ['option-1', 'option-2', 'option-3', 'option-4']);
|
|
1000
|
+
await toggleSelected(el);
|
|
1001
|
+
|
|
1002
|
+
await pick(el, 'option-1');
|
|
1003
|
+
expect(values(el)).to.deep.equal(['option-2', 'option-3', 'option-4']);
|
|
1004
|
+
await pick(el, 'option-3');
|
|
1005
|
+
expect(values(el)).to.deep.equal(['option-2', 'option-4']);
|
|
1006
|
+
await pick(el, 'option-4');
|
|
1007
|
+
expect(values(el)).to.deep.equal(['option-2']);
|
|
1008
|
+
});
|
|
1009
|
+
|
|
1010
|
+
it('F4. rapid unselects without awaiting between them end in the right list', async () => {
|
|
1011
|
+
const el = await mount(false, ['option-1', 'option-2', 'option-3', 'option-4']);
|
|
1012
|
+
await toggleSelected(el);
|
|
1013
|
+
|
|
1014
|
+
el.handleOptionSelection({ value: 'option-1' });
|
|
1015
|
+
el.handleOptionSelection({ value: 'option-2' });
|
|
1016
|
+
await el.updateComplete;
|
|
1017
|
+
await aTimeout(30);
|
|
1018
|
+
|
|
1019
|
+
expect(el.value).to.deep.equal(['option-3', 'option-4']);
|
|
1020
|
+
expect(values(el)).to.deep.equal(['option-3', 'option-4']);
|
|
1021
|
+
});
|
|
1022
|
+
|
|
1023
|
+
it('F5. unselecting the last item leaves the Selected view with the full list', async () => {
|
|
1024
|
+
const el = await mount(false, ['option-1']);
|
|
1025
|
+
await toggleSelected(el);
|
|
1026
|
+
|
|
1027
|
+
await pick(el, 'option-1');
|
|
1028
|
+
|
|
1029
|
+
expect(el.showSelected).to.be.false;
|
|
1030
|
+
expect(el.data.length).to.equal(200);
|
|
1031
|
+
});
|
|
1032
|
+
|
|
1033
|
+
it('F6. toggling Show Selected off after an unselect restores the full list', async () => {
|
|
1034
|
+
const el = await mount(false, ['option-1', 'option-2', 'option-3']);
|
|
1035
|
+
await toggleSelected(el);
|
|
1036
|
+
await pick(el, 'option-2');
|
|
1037
|
+
|
|
1038
|
+
await toggleSelected(el);
|
|
1039
|
+
|
|
1040
|
+
expect(el.showSelected).to.be.false;
|
|
1041
|
+
expect(el.data.length).to.equal(200);
|
|
1042
|
+
});
|
|
1043
|
+
|
|
1044
|
+
it('F7. a selected item deep in the list survives an unselect of another', async () => {
|
|
1045
|
+
const el = await mount(false, ['option-3', 'option-150', 'option-199']);
|
|
1046
|
+
await toggleSelected(el);
|
|
1047
|
+
|
|
1048
|
+
await pick(el, 'option-3');
|
|
1049
|
+
|
|
1050
|
+
expect(values(el)).to.deep.equal(['option-150', 'option-199']);
|
|
1051
|
+
});
|
|
1052
|
+
|
|
1053
|
+
it('F8. an unselect does not reset scroll or trigger a full repaint', async () => {
|
|
1054
|
+
const el = await mount(false, ['option-1', 'option-2', 'option-3']);
|
|
1055
|
+
await toggleSelected(el);
|
|
1056
|
+
let resets = 0;
|
|
1057
|
+
el.resetScrollPosition = async () => { resets++; };
|
|
1058
|
+
el.repaintOptionsContainer = () => { resets++; };
|
|
1059
|
+
|
|
1060
|
+
await pick(el, 'option-2');
|
|
1061
|
+
|
|
1062
|
+
expect(resets).to.equal(0);
|
|
1063
|
+
});
|
|
1064
|
+
|
|
1065
|
+
it('F9. a refresh that yields the same list does not reassign data', async () => {
|
|
1066
|
+
const el = await mount(false, ['option-1', 'option-2', 'option-3']);
|
|
1067
|
+
await toggleSelected(el);
|
|
1068
|
+
const before = el.data;
|
|
1069
|
+
|
|
1070
|
+
el.refreshSelectedList();
|
|
1071
|
+
el.refreshSelectedList();
|
|
1072
|
+
|
|
1073
|
+
expect(el.data).to.equal(before);
|
|
1074
|
+
});
|
|
1075
|
+
|
|
1076
|
+
it('F10. no-scroll follows real overflow, not just the item count', async () => {
|
|
1077
|
+
const el = await mount(false, ['option-1', 'option-2', 'option-3', 'option-4', 'option-5', 'option-6', 'option-7']);
|
|
1078
|
+
await toggleSelected(el);
|
|
1079
|
+
// The list element is recreated when it drops below the virtualizer threshold (5), so look it up fresh.
|
|
1080
|
+
await pick(el, 'option-7');
|
|
1081
|
+
await pick(el, 'option-6');
|
|
1082
|
+
await pick(el, 'option-5'); // 4 left: now below the threshold
|
|
1083
|
+
await aTimeout(50);
|
|
1084
|
+
const virtualized = el.shadowRoot.querySelector('.virtualized') as HTMLElement | null;
|
|
1085
|
+
if (!virtualized) throw new Error('.virtualized not rendered');
|
|
1086
|
+
const size = (scrollHeight: number, clientHeight: number) => {
|
|
1087
|
+
Object.defineProperty(virtualized, 'scrollHeight', { configurable: true, get: () => scrollHeight });
|
|
1088
|
+
Object.defineProperty(virtualized, 'clientHeight', { configurable: true, get: () => clientHeight });
|
|
1089
|
+
};
|
|
1090
|
+
|
|
1091
|
+
size(400, 150); // tall rows in a short popup: overflows, so it must stay scrollable
|
|
1092
|
+
await pick(el, 'option-4');
|
|
1093
|
+
await aTimeout(50);
|
|
1094
|
+
expect(el.data.length).to.equal(3);
|
|
1095
|
+
expect(virtualized.classList.contains('no-scroll')).to.be.false;
|
|
1096
|
+
|
|
1097
|
+
size(150, 150); // the same rows now fit: the scrollbar can be hidden
|
|
1098
|
+
await pick(el, 'option-3');
|
|
1099
|
+
await aTimeout(50);
|
|
1100
|
+
expect(el.data.length).to.equal(2);
|
|
1101
|
+
expect(virtualized.classList.contains('no-scroll')).to.be.true;
|
|
1102
|
+
});
|
|
1103
|
+
|
|
1104
|
+
it('F11. shrinking below the virtualizer threshold drops its leftover min-height', async () => {
|
|
1105
|
+
const el = await mount(false, ['option-1', 'option-2', 'option-3']);
|
|
1106
|
+
const virtualized = () => el.shadowRoot.querySelector('.virtualized') as HTMLElement;
|
|
1107
|
+
// While the list is long the renderer sets min-height: 0 itself; the virtualizer only fills in its 150px default
|
|
1108
|
+
// when none is set, so the list can shrink in a short popup (flex-basis keeps 150px as the preferred height).
|
|
1109
|
+
expect(virtualized().style.minHeight).to.equal('0px');
|
|
1110
|
+
|
|
1111
|
+
await toggleSelected(el);
|
|
1112
|
+
await aTimeout(50);
|
|
1113
|
+
|
|
1114
|
+
expect(el.data.length).to.equal(3);
|
|
1115
|
+
expect(virtualized().style.minHeight).to.equal('');
|
|
1116
|
+
});
|
|
1117
|
+
|
|
1118
|
+
// The virtualizer measures rows during the popup's open animation (scaled to 0.9) and then keeps them too close
|
|
1119
|
+
// together, so they overlap and the gap disappears. Once open, the component nudges the list's width by 1px so the
|
|
1120
|
+
// virtualizer re-measures. Row rects are faked here, since the real overlap depends on animation timing.
|
|
1121
|
+
const forceRowRects = (el: any, pitch: number) => {
|
|
1122
|
+
const rows = [...el.shadowRoot.querySelectorAll('.virtualized nile-option')] as HTMLElement[];
|
|
1123
|
+
rows.forEach((row, i) => {
|
|
1124
|
+
row.getBoundingClientRect = () => ({ top: i * pitch, bottom: i * pitch + 42, height: 42, left: 0, right: 100, width: 100, x: 0, y: i * pitch, toJSON() {} }) as DOMRect;
|
|
1125
|
+
});
|
|
1126
|
+
};
|
|
1127
|
+
const watchWidth = (el: any) => {
|
|
1128
|
+
const virtualized = el.shadowRoot.querySelector('.virtualized') as HTMLElement;
|
|
1129
|
+
const widths: string[] = [];
|
|
1130
|
+
const observer = new MutationObserver(() => widths.push(virtualized.style.width));
|
|
1131
|
+
observer.observe(virtualized, { attributes: true, attributeFilter: ['style'] });
|
|
1132
|
+
return { widths, stop: () => observer.disconnect(), virtualized };
|
|
1133
|
+
};
|
|
1134
|
+
|
|
1135
|
+
it('F12. rows that overlap after open make the list nudge its width once so the virtualizer re-measures', async () => {
|
|
1136
|
+
const el = await mount(false, ['option-1', 'option-2', 'option-3']);
|
|
1137
|
+
const before = el.shadowRoot.querySelector('.virtualized');
|
|
1138
|
+
forceRowRects(el, 38); // 42px rows positioned 38px apart: overlapping
|
|
1139
|
+
const watch = watchWidth(el);
|
|
1140
|
+
|
|
1141
|
+
await el.healOverlappingRows();
|
|
1142
|
+
await aTimeout(0);
|
|
1143
|
+
watch.stop();
|
|
1144
|
+
|
|
1145
|
+
expect(watch.widths).to.include('calc(100% - 1px)');
|
|
1146
|
+
expect(watch.virtualized.style.width).to.equal(''); // restored
|
|
1147
|
+
expect(el.shadowRoot.querySelector('.virtualized')).to.equal(before); // nothing re-created
|
|
1148
|
+
});
|
|
1149
|
+
|
|
1150
|
+
it('F14. opening waits for the virtualizer to lay rows out, and never blocks forever', async () => {
|
|
1151
|
+
const el = await mount(false, ['option-1', 'option-2', 'option-3']);
|
|
1152
|
+
const rows = [...el.shadowRoot.querySelectorAll('.virtualized nile-option')] as HTMLElement[];
|
|
1153
|
+
let reads = 0;
|
|
1154
|
+
// The virtualizer's estimate (rows 100px apart) for the first few reads, then the real 42px pitch.
|
|
1155
|
+
const fake = (pitch: number) => (row: HTMLElement, i: number) => {
|
|
1156
|
+
row.getBoundingClientRect = () => {
|
|
1157
|
+
reads += 1;
|
|
1158
|
+
const p = reads <= 8 ? 100 : pitch;
|
|
1159
|
+
return { top: i * p, bottom: i * p + 42, height: 42, left: 0, right: 100, width: 100, x: 0, y: i * p, toJSON() {} } as DOMRect;
|
|
1160
|
+
};
|
|
1161
|
+
};
|
|
1162
|
+
rows.forEach(fake(42));
|
|
1163
|
+
await el.waitForRowLayout();
|
|
1164
|
+
expect(reads).to.be.greaterThan(8); // it kept waiting while the estimate was in place
|
|
1165
|
+
|
|
1166
|
+
reads = -1e9; // always the estimate: must give up after the frame cap instead of hanging
|
|
1167
|
+
const started = performance.now();
|
|
1168
|
+
await el.waitForRowLayout(5);
|
|
1169
|
+
expect(performance.now() - started).to.be.lessThan(1000);
|
|
1170
|
+
});
|
|
1171
|
+
|
|
1172
|
+
it('F15. re-measuring the chips does not hide chips that all fitted (no blink when the dropdown opens)', async () => {
|
|
1173
|
+
const el = await mount(false, ['option-1', 'option-2']);
|
|
1174
|
+
const hidden = () => [...el.shadowRoot.querySelectorAll('nile-tag')].filter((tag: Element) => tag.classList.contains('select__invisible')).length;
|
|
1175
|
+
|
|
1176
|
+
el.oldMaxOptionsVisible = 0; // the last fit showed every chip
|
|
1177
|
+
el.setFittedMaxOptionsVisible(Infinity); // a re-measure starts
|
|
1178
|
+
await el.updateComplete;
|
|
1179
|
+
expect(hidden()).to.equal(0);
|
|
1180
|
+
|
|
1181
|
+
el.oldMaxOptionsVisible = 1; // the last fit clipped everything after the first chip
|
|
1182
|
+
el.setFittedMaxOptionsVisible(Infinity);
|
|
1183
|
+
await el.updateComplete;
|
|
1184
|
+
expect(hidden()).to.equal(1); // unchanged behaviour: only the previously clipped chip is hidden while measuring
|
|
1185
|
+
});
|
|
1186
|
+
|
|
1187
|
+
it('F13. correctly spaced rows are left alone', async () => {
|
|
1188
|
+
const el = await mount(false, ['option-1', 'option-2', 'option-3']);
|
|
1189
|
+
forceRowRects(el, 44); // 2px gap
|
|
1190
|
+
const watch = watchWidth(el);
|
|
1191
|
+
|
|
1192
|
+
await el.healOverlappingRows();
|
|
1193
|
+
await aTimeout(0);
|
|
1194
|
+
watch.stop();
|
|
1195
|
+
|
|
1196
|
+
expect(watch.widths).to.deep.equal([]);
|
|
1197
|
+
});
|
|
970
1198
|
});
|
|
971
1199
|
|
|
972
1200
|
it('E5. without showtooltip an external value leaves the Selected list as it was (pre-2.0.9)', async () => {
|
|
@@ -138,6 +138,8 @@ export class NileVirtualSelect extends NileElement implements NileFormControl {
|
|
|
138
138
|
@property({ type: Array }) data: any = [];
|
|
139
139
|
|
|
140
140
|
private lastSeenValue: string | string[] | undefined;
|
|
141
|
+
/** Set by direct user selection changes so the value watcher can tell them from external ones. */
|
|
142
|
+
private userSelectionChange = false;
|
|
141
143
|
|
|
142
144
|
/** Original unfiltered option items for search functionality */
|
|
143
145
|
@state() private originalOptionItems: any = [];
|
|
@@ -668,6 +670,95 @@ export class NileVirtualSelect extends NileElement implements NileFormControl {
|
|
|
668
670
|
});
|
|
669
671
|
}
|
|
670
672
|
|
|
673
|
+
private isValueSelected(item: any): boolean {
|
|
674
|
+
const selectedValues = Array.isArray(this.value) ? this.value : [this.value];
|
|
675
|
+
const itemValue = this.getItemValue(item);
|
|
676
|
+
return selectedValues.some(val => String(val) === String(itemValue));
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* Keeps the "Selected" view in sync with the current selection without a full repaint:
|
|
681
|
+
* `data` is only reassigned when the filtered list actually differs (no needless watcher runs or
|
|
682
|
+
* virtualization rebuilds), and scroll position is left alone. The `no-scroll` class is only touched
|
|
683
|
+
* when the item count crosses the threshold.
|
|
684
|
+
*/
|
|
685
|
+
private refreshSelectedList(): void {
|
|
686
|
+
if (!this.showSelected) return;
|
|
687
|
+
const next = this.originalOptionItems.filter((item: any) => this.isValueSelected(item));
|
|
688
|
+
const prev = this.data || [];
|
|
689
|
+
if (next.length === prev.length && next.every((item: any, i: number) => item === prev[i])) {
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
this.data = next;
|
|
693
|
+
if (prev.length < 5 || next.length < 5) {
|
|
694
|
+
this.updateNoScroll();
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* Hides the scrollbar only for short lists that genuinely fit. A short list can still overflow
|
|
700
|
+
* (tall rows, small popup), and then it must stay scrollable.
|
|
701
|
+
*/
|
|
702
|
+
private updateNoScroll(): void {
|
|
703
|
+
this.updateComplete.then(() => requestAnimationFrame(() => {
|
|
704
|
+
const virtualized = this.shadowRoot?.querySelector('.virtualized') as HTMLElement | null;
|
|
705
|
+
if (!virtualized) return;
|
|
706
|
+
virtualized.classList.remove('no-scroll');
|
|
707
|
+
if (this.data.length < 5 && virtualized.scrollHeight <= virtualized.clientHeight + 1) {
|
|
708
|
+
virtualized.classList.add('no-scroll');
|
|
709
|
+
}
|
|
710
|
+
}));
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* Until the virtualizer has measured its rows it positions them by an estimated size (100px), so for a frame or two
|
|
715
|
+
* they sit far apart. The popup is hidden while it positions itself, but that is not always long enough; keep it
|
|
716
|
+
* hidden until the first two rows are spaced by their own height. Capped, so it can never block opening.
|
|
717
|
+
*/
|
|
718
|
+
private async waitForRowLayout(maxFrames = 30): Promise<void> {
|
|
719
|
+
const settled = (): boolean => {
|
|
720
|
+
if (!VirtualSelectRenderer.shouldUseVirtualizer(this.data ?? [])) return true; // plain list: nothing is estimated
|
|
721
|
+
const virtualized = this.shadowRoot?.querySelector('.virtualized--scroller');
|
|
722
|
+
if (!virtualized) return false; // not rendered yet
|
|
723
|
+
const rows = [...virtualized.querySelectorAll('nile-option')]
|
|
724
|
+
.map(row => row.getBoundingClientRect())
|
|
725
|
+
.sort((a, b) => a.top - b.top);
|
|
726
|
+
return rows.length >= 2 && Math.abs(rows[1].top - rows[0].top - rows[0].height) <= 1;
|
|
727
|
+
};
|
|
728
|
+
for (let frame = 0; frame < maxFrames && !settled(); frame += 1) {
|
|
729
|
+
await new Promise(resolve => requestAnimationFrame(resolve));
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* Safety net for a stale row measurement. The virtualizer measures rows with getBoundingClientRect, so anything
|
|
735
|
+
* that scales the popup while it measures (a custom open animation, a transformed ancestor) records rows too small
|
|
736
|
+
* and positions them too close together: they overlap and the gap between them disappears until something
|
|
737
|
+
* re-measures. Once the popup is open, detect that and nudge the list's width by 1px: the virtualizer re-measures
|
|
738
|
+
* all rows when its host resizes, without re-creating anything.
|
|
739
|
+
*/
|
|
740
|
+
private async healOverlappingRows(): Promise<void> {
|
|
741
|
+
const frames = () => new Promise<void>(resolve => requestAnimationFrame(() => requestAnimationFrame(() => resolve())));
|
|
742
|
+
const virtualized = this.shadowRoot?.querySelector('.virtualized--scroller') as HTMLElement | null;
|
|
743
|
+
if (!virtualized) return;
|
|
744
|
+
const overlapping = (): boolean => {
|
|
745
|
+
const rows = [...virtualized.querySelectorAll('nile-option')]
|
|
746
|
+
.map(row => row.getBoundingClientRect())
|
|
747
|
+
.sort((a, b) => a.top - b.top);
|
|
748
|
+
return rows.length >= 2 && rows[1].top - rows[0].top < rows[0].height - 0.5;
|
|
749
|
+
};
|
|
750
|
+
try {
|
|
751
|
+
await (document.fonts?.ready ?? Promise.resolve());
|
|
752
|
+
if (!this.open || !overlapping()) return;
|
|
753
|
+
virtualized.style.width = 'calc(100% - 1px)';
|
|
754
|
+
await frames();
|
|
755
|
+
virtualized.style.width = '';
|
|
756
|
+
await frames();
|
|
757
|
+
} catch {
|
|
758
|
+
virtualized.style.width = '';
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
|
|
671
762
|
private toggleShowSelected(event: Event): void {
|
|
672
763
|
event.stopPropagation();
|
|
673
764
|
event.preventDefault();
|
|
@@ -827,6 +918,7 @@ export class NileVirtualSelect extends NileElement implements NileFormControl {
|
|
|
827
918
|
|
|
828
919
|
private toggleOptionSelection(optionValue: string): void {
|
|
829
920
|
const currentValues = Array.isArray(this.value) ? this.value : [];
|
|
921
|
+
this.userSelectionChange = this.showSelected;
|
|
830
922
|
|
|
831
923
|
if (currentValues.includes(optionValue)) {
|
|
832
924
|
this.value = currentValues.filter(v => v !== optionValue);
|
|
@@ -852,6 +944,7 @@ export class NileVirtualSelect extends NileElement implements NileFormControl {
|
|
|
852
944
|
currentValue = currentValue ? [currentValue] : [];
|
|
853
945
|
}
|
|
854
946
|
const newValue = currentValue.filter((v: string) => v !== option.value);
|
|
947
|
+
this.userSelectionChange = this.showSelected;
|
|
855
948
|
this.value = newValue;
|
|
856
949
|
this.selectionChanged();
|
|
857
950
|
}
|
|
@@ -931,16 +1024,7 @@ export class NileVirtualSelect extends NileElement implements NileFormControl {
|
|
|
931
1024
|
|
|
932
1025
|
repaintOptionsContainer() {
|
|
933
1026
|
this.resetScrollPosition();
|
|
934
|
-
this.
|
|
935
|
-
const virtualized = this.shadowRoot?.querySelector('.virtualized') as HTMLElement;
|
|
936
|
-
if (virtualized) {
|
|
937
|
-
if (this.data.length < 5) {
|
|
938
|
-
virtualized.classList.add('no-scroll');
|
|
939
|
-
} else {
|
|
940
|
-
virtualized.classList.remove('no-scroll');
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
});
|
|
1027
|
+
this.updateNoScroll();
|
|
944
1028
|
}
|
|
945
1029
|
|
|
946
1030
|
handleScroll(e: Event): void {
|
|
@@ -1029,7 +1113,11 @@ export class NileVirtualSelect extends NileElement implements NileFormControl {
|
|
|
1029
1113
|
this.selectionChanged();
|
|
1030
1114
|
if (externalValueChange && this.showTooltip && this.showSelected) {
|
|
1031
1115
|
this.applySelectedFilter();
|
|
1116
|
+
} else if (this.userSelectionChange) {
|
|
1117
|
+
// A direct user unselect while "Show Selected" is on drops that item from the list.
|
|
1118
|
+
this.refreshSelectedList();
|
|
1032
1119
|
}
|
|
1120
|
+
this.userSelectionChange = false;
|
|
1033
1121
|
this.requestUpdate();
|
|
1034
1122
|
|
|
1035
1123
|
// Update body append content if it's active
|
|
@@ -1043,6 +1131,12 @@ export class NileVirtualSelect extends NileElement implements NileFormControl {
|
|
|
1043
1131
|
if (this.data.length > 0 && this.open && !this.showSelected && !this.searchValue) {
|
|
1044
1132
|
this.originalOptionItems = [...this.data];
|
|
1045
1133
|
}
|
|
1134
|
+
if (this.showSelected && this.data.length > 0 && !this.data.every((item: any) => this.isValueSelected(item))) {
|
|
1135
|
+
// The consumer replaced `data` with unfiltered items while "Show Selected" is on:
|
|
1136
|
+
// adopt them as the source list and narrow back to the selection.
|
|
1137
|
+
this.originalOptionItems = [...this.data];
|
|
1138
|
+
this.refreshSelectedList();
|
|
1139
|
+
}
|
|
1046
1140
|
this.selectionChanged();
|
|
1047
1141
|
// Show no results message when data is empty and not loading
|
|
1048
1142
|
if (!this.optionsLoading && !this.loading && this.data.length === 0) {
|
|
@@ -1136,6 +1230,9 @@ export class NileVirtualSelect extends NileElement implements NileFormControl {
|
|
|
1136
1230
|
// Wait for next frame to allow Floating UI to calculate position
|
|
1137
1231
|
await new Promise(resolve => requestAnimationFrame(resolve));
|
|
1138
1232
|
|
|
1233
|
+
// Keep the popup hidden until the virtualizer has laid its rows out, so its 100px starting estimate is never seen.
|
|
1234
|
+
await this.waitForRowLayout();
|
|
1235
|
+
|
|
1139
1236
|
// Show popup after positioning is calculated
|
|
1140
1237
|
if (this.popup?.popup) {
|
|
1141
1238
|
this.popup.popup.style.visibility = '';
|
|
@@ -1144,7 +1241,12 @@ export class NileVirtualSelect extends NileElement implements NileFormControl {
|
|
|
1144
1241
|
const { keyframes, options } = getAnimation(this, 'select.show', {
|
|
1145
1242
|
dir: 'ltr',
|
|
1146
1243
|
});
|
|
1147
|
-
|
|
1244
|
+
// Drop the `scale` property (the default animation is opacity + scale 0.9 -> 1). The virtualizer measures rows with
|
|
1245
|
+
// getBoundingClientRect, so rows measured while the popup is scaled come out too small and are then snapped apart.
|
|
1246
|
+
// Only `scale` is removed: other properties, including a consumer's `transform`, are left as they set them.
|
|
1247
|
+
const withoutScale = keyframes.map(({ scale, ...rest }) => rest);
|
|
1248
|
+
await animateTo(this.popup.popup, withoutScale, options);
|
|
1249
|
+
await this.healOverlappingRows();
|
|
1148
1250
|
|
|
1149
1251
|
if (this.wasShowSelectedCheckedOnClose) {
|
|
1150
1252
|
this.showSelected = false;
|
|
@@ -1497,7 +1599,11 @@ export class NileVirtualSelect extends NileElement implements NileFormControl {
|
|
|
1497
1599
|
|
|
1498
1600
|
private renderLegacyTag(option: VirtualOption, index: number): TemplateResult {
|
|
1499
1601
|
const classes = {
|
|
1602
|
+
// While the fit is re-measured (maxOptionsVisible = Infinity), hide only the chips that were previously clipped.
|
|
1603
|
+
// A previous limit of 0 means every chip fitted (see `maxOptionsVisible <= 0` in renderTags), so none are hidden;
|
|
1604
|
+
// treating 0 as "none visible" blinked the whole chip row on every re-fit, e.g. each time the dropdown opened.
|
|
1500
1605
|
select__invisible:
|
|
1606
|
+
this.oldMaxOptionsVisible > 0 &&
|
|
1501
1607
|
index + 1 > this.oldMaxOptionsVisible &&
|
|
1502
1608
|
this.maxOptionsVisible === Infinity,
|
|
1503
1609
|
};
|
|
@@ -9,6 +9,8 @@ import { html, type TemplateResult } from 'lit';
|
|
|
9
9
|
import { virtualize } from '@lit-labs/virtualizer/virtualize.js';
|
|
10
10
|
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
|
|
11
11
|
import { classMap } from 'lit/directives/class-map.js';
|
|
12
|
+
import { keyed } from 'lit/directives/keyed.js';
|
|
13
|
+
import { styleMap } from 'lit/directives/style-map.js';
|
|
12
14
|
|
|
13
15
|
export class VirtualSelectRenderer {
|
|
14
16
|
static getVirtualizedContent(
|
|
@@ -31,6 +33,10 @@ export class VirtualSelectRenderer {
|
|
|
31
33
|
tickOnSelect?: boolean,
|
|
32
34
|
legacy?: boolean
|
|
33
35
|
): TemplateResult {
|
|
36
|
+
// The list element is keyed on the virtualizer threshold: crossing it recreates the element. Reusing one
|
|
37
|
+
// element would leave the virtualizer attached with its inline min-height/contain, which shows as blank
|
|
38
|
+
// space once a short list renders as plain options.
|
|
39
|
+
const useVirtualizer = VirtualSelectRenderer.shouldUseVirtualizer(data);
|
|
34
40
|
return html`
|
|
35
41
|
<div part="select-options" class="select__options ${
|
|
36
42
|
searchEnabled ? 'select__options__search-enabled' : ``
|
|
@@ -42,12 +48,13 @@ export class VirtualSelectRenderer {
|
|
|
42
48
|
</div>
|
|
43
49
|
`
|
|
44
50
|
: html`
|
|
45
|
-
|
|
46
|
-
class="virtualized"
|
|
51
|
+
${keyed(useVirtualizer, html`<div
|
|
52
|
+
class="virtualized ${useVirtualizer ? 'virtualized--scroller' : ''}"
|
|
47
53
|
part="virtualized"
|
|
54
|
+
style=${styleMap(useVirtualizer ? { minHeight: '0' } : {})}
|
|
48
55
|
@scroll=${onScroll}
|
|
49
56
|
>
|
|
50
|
-
${
|
|
57
|
+
${useVirtualizer
|
|
51
58
|
? html`
|
|
52
59
|
${virtualize({
|
|
53
60
|
items: data,
|
|
@@ -61,7 +68,7 @@ export class VirtualSelectRenderer {
|
|
|
61
68
|
VirtualSelectRenderer.getItemRenderFunction(item, renderItemFunction, value, multiple, getDisplayText, getItemValue, getItemDescription, getItemPrefix, getItemSuffix, allowHtmlLabel, enableDescription, tickOnSelect, legacy)
|
|
62
69
|
)}
|
|
63
70
|
`}
|
|
64
|
-
</div
|
|
71
|
+
</div>`)}
|
|
65
72
|
`}
|
|
66
73
|
</div>`;
|
|
67
74
|
}
|
|
@@ -129,7 +136,7 @@ export class VirtualSelectRenderer {
|
|
|
129
136
|
* Determines whether to use virtualizer based on dataset size
|
|
130
137
|
* For small datasets (less than 5 items), use regular rendering for better sizing
|
|
131
138
|
*/
|
|
132
|
-
|
|
139
|
+
static shouldUseVirtualizer(data: any[]): boolean {
|
|
133
140
|
return data.length >= 5;
|
|
134
141
|
}
|
|
135
142
|
}
|