@genspectrum/dashboard-components 0.12.0 → 0.12.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.
@@ -1096,11 +1096,11 @@
1096
1096
  },
1097
1097
  {
1098
1098
  "kind": "variable",
1099
- "name": "FiresEvent",
1099
+ "name": "FiresEvents",
1100
1100
  "type": {
1101
1101
  "text": "StoryObj<Required<TextInputProps>>"
1102
1102
  },
1103
- "default": "{ ...Default, play: async ({ canvasElement, step }) => { const canvas = await withinShadowRoot(canvasElement, 'gs-text-input'); const inputField = () => canvas.getByPlaceholderText('Enter host name'); const listenerMock = fn(); await step('Setup event listener mock', async () => { canvasElement.addEventListener('gs-text-input-changed', listenerMock); }); await step('wait until data is loaded', async () => { await waitFor(() => { return expect(inputField()).toBeEnabled(); }); }); await step('Enters an invalid host name', async () => { await userEvent.type(inputField(), 'notInList'); await expect(listenerMock).not.toHaveBeenCalled(); }); await step('Empty input', async () => { await userEvent.type(inputField(), '{backspace>9/}'); await expect(listenerMock.mock.calls.at(-1)![0].detail).toStrictEqual({ host: undefined, }); }); await step('Enter a valid host name', async () => { await userEvent.type(inputField(), 'Homo'); await expect(listenerMock).toHaveBeenCalledWith( expect.objectContaining({ detail: { host: 'Homo', }, }), ); }); }, args: { ...Default.args, initialValue: '', }, }"
1103
+ "default": "{ ...Default, play: async ({ canvasElement, step }) => { const canvas = await withinShadowRoot(canvasElement, 'gs-text-input'); const inputField = () => canvas.getByPlaceholderText('Enter host name'); const listenerMock = fn(); await step('Setup event listener mock', async () => { canvasElement.addEventListener('gs-text-input-changed', listenerMock); }); await step('wait until data is loaded', async () => { await waitFor(() => { return expect(inputField()).toBeEnabled(); }); }); await step('Enters an invalid host name', async () => { await userEvent.type(inputField(), 'notInList'); await expect(listenerMock).not.toHaveBeenCalled(); }); await step('Empty input', async () => { await userEvent.type(inputField(), '{backspace>9/}'); }); await step('Enter a valid host name', async () => { await userEvent.type(inputField(), 'Homo s'); const dropdownOption = await canvas.findByText('Homo sapiens'); await userEvent.click(dropdownOption); }); await step('Verify event is fired with correct detail', async () => { await waitFor(() => { expect(listenerMock).toHaveBeenCalledWith( expect.objectContaining({ detail: { host: 'Homo sapiens', }, }), ); }); }); await step('Remove initial value', async () => { await fireEvent.click(canvas.getByRole('button', { name: 'clear selection' })); await expect(listenerMock).toHaveBeenCalledWith( expect.objectContaining({ detail: { host: undefined, }, }), ); }); await step('Empty input', async () => { inputField().blur(); await expect(listenerMock.mock.calls.at(-1)![0].detail).toStrictEqual({ host: undefined, }); }); }, args: { ...Default.args, initialValue: '', }, }"
1104
1104
  }
1105
1105
  ],
1106
1106
  "exports": [
@@ -1122,9 +1122,9 @@
1122
1122
  },
1123
1123
  {
1124
1124
  "kind": "js",
1125
- "name": "FiresEvent",
1125
+ "name": "FiresEvents",
1126
1126
  "declaration": {
1127
- "name": "FiresEvent",
1127
+ "name": "FiresEvents",
1128
1128
  "module": "src/web-components/input/gs-text-input.stories.ts"
1129
1129
  }
1130
1130
  }
@@ -1263,10 +1263,7 @@ declare global {
1263
1263
 
1264
1264
  declare global {
1265
1265
  interface HTMLElementTagNameMap {
1266
- 'gs-location-filter': LocationFilterComponent;
1267
- }
1268
- interface HTMLElementEventMap {
1269
- 'gs-location-changed': LocationChangedEvent;
1266
+ 'gs-mutation-comparison-component': MutationComparisonComponent;
1270
1267
  }
1271
1268
  }
1272
1269
 
@@ -1274,7 +1271,7 @@ declare global {
1274
1271
  declare global {
1275
1272
  namespace JSX {
1276
1273
  interface IntrinsicElements {
1277
- 'gs-location-filter': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1274
+ 'gs-mutation-comparison-component': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1278
1275
  }
1279
1276
  }
1280
1277
  }
@@ -1282,11 +1279,7 @@ declare global {
1282
1279
 
1283
1280
  declare global {
1284
1281
  interface HTMLElementTagNameMap {
1285
- 'gs-date-range-selector': DateRangeSelectorComponent;
1286
- }
1287
- interface HTMLElementEventMap {
1288
- 'gs-date-range-filter-changed': CustomEvent<Record<string, string>>;
1289
- 'gs-date-range-option-changed': DateRangeOptionChangedEvent;
1282
+ 'gs-mutations-component': MutationsComponent;
1290
1283
  }
1291
1284
  }
1292
1285
 
@@ -1294,7 +1287,7 @@ declare global {
1294
1287
  declare global {
1295
1288
  namespace JSX {
1296
1289
  interface IntrinsicElements {
1297
- 'gs-date-range-selector': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1290
+ 'gs-mutations-component': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1298
1291
  }
1299
1292
  }
1300
1293
  }
@@ -1302,10 +1295,7 @@ declare global {
1302
1295
 
1303
1296
  declare global {
1304
1297
  interface HTMLElementTagNameMap {
1305
- 'gs-text-input': TextInputComponent;
1306
- }
1307
- interface HTMLElementEventMap {
1308
- 'gs-text-input-changed': CustomEvent<Record<string, string>>;
1298
+ 'gs-prevalence-over-time': PrevalenceOverTimeComponent;
1309
1299
  }
1310
1300
  }
1311
1301
 
@@ -1313,7 +1303,7 @@ declare global {
1313
1303
  declare global {
1314
1304
  namespace JSX {
1315
1305
  interface IntrinsicElements {
1316
- 'gs-text-input': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1306
+ 'gs-prevalence-over-time': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1317
1307
  }
1318
1308
  }
1319
1309
  }
@@ -1321,10 +1311,7 @@ declare global {
1321
1311
 
1322
1312
  declare global {
1323
1313
  interface HTMLElementTagNameMap {
1324
- 'gs-mutation-filter': MutationFilterComponent;
1325
- }
1326
- interface HTMLElementEventMap {
1327
- 'gs-mutation-filter-changed': CustomEvent<MutationsFilter>;
1314
+ 'gs-relative-growth-advantage': RelativeGrowthAdvantageComponent;
1328
1315
  }
1329
1316
  }
1330
1317
 
@@ -1332,7 +1319,7 @@ declare global {
1332
1319
  declare global {
1333
1320
  namespace JSX {
1334
1321
  interface IntrinsicElements {
1335
- 'gs-mutation-filter': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1322
+ 'gs-relative-growth-advantage': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1336
1323
  }
1337
1324
  }
1338
1325
  }
@@ -1340,10 +1327,7 @@ declare global {
1340
1327
 
1341
1328
  declare global {
1342
1329
  interface HTMLElementTagNameMap {
1343
- 'gs-lineage-filter': LineageFilterComponent;
1344
- }
1345
- interface HTMLElementEventMap {
1346
- 'gs-lineage-filter-changed': CustomEvent<Record<string, string>>;
1330
+ 'gs-number-sequences-over-time': NumberSequencesOverTimeComponent;
1347
1331
  }
1348
1332
  }
1349
1333
 
@@ -1351,7 +1335,7 @@ declare global {
1351
1335
  declare global {
1352
1336
  namespace JSX {
1353
1337
  interface IntrinsicElements {
1354
- 'gs-lineage-filter': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1338
+ 'gs-number-sequences-over-time': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1355
1339
  }
1356
1340
  }
1357
1341
  }
@@ -1359,7 +1343,7 @@ declare global {
1359
1343
 
1360
1344
  declare global {
1361
1345
  interface HTMLElementTagNameMap {
1362
- 'gs-mutation-comparison-component': MutationComparisonComponent;
1346
+ 'gs-aggregate': AggregateComponent;
1363
1347
  }
1364
1348
  }
1365
1349
 
@@ -1367,7 +1351,7 @@ declare global {
1367
1351
  declare global {
1368
1352
  namespace JSX {
1369
1353
  interface IntrinsicElements {
1370
- 'gs-mutation-comparison-component': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1354
+ 'gs-aggregate': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1371
1355
  }
1372
1356
  }
1373
1357
  }
@@ -1375,7 +1359,7 @@ declare global {
1375
1359
 
1376
1360
  declare global {
1377
1361
  interface HTMLElementTagNameMap {
1378
- 'gs-mutations-component': MutationsComponent;
1362
+ 'gs-mutations-over-time': MutationsOverTimeComponent;
1379
1363
  }
1380
1364
  }
1381
1365
 
@@ -1383,7 +1367,7 @@ declare global {
1383
1367
  declare global {
1384
1368
  namespace JSX {
1385
1369
  interface IntrinsicElements {
1386
- 'gs-mutations-component': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1370
+ 'gs-mutations-over-time': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1387
1371
  }
1388
1372
  }
1389
1373
  }
@@ -1391,7 +1375,7 @@ declare global {
1391
1375
 
1392
1376
  declare global {
1393
1377
  interface HTMLElementTagNameMap {
1394
- 'gs-prevalence-over-time': PrevalenceOverTimeComponent;
1378
+ 'gs-sequences-by-location': SequencesByLocationComponent;
1395
1379
  }
1396
1380
  }
1397
1381
 
@@ -1399,7 +1383,7 @@ declare global {
1399
1383
  declare global {
1400
1384
  namespace JSX {
1401
1385
  interface IntrinsicElements {
1402
- 'gs-prevalence-over-time': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1386
+ 'gs-sequences-by-location': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1403
1387
  }
1404
1388
  }
1405
1389
  }
@@ -1407,7 +1391,7 @@ declare global {
1407
1391
 
1408
1392
  declare global {
1409
1393
  interface HTMLElementTagNameMap {
1410
- 'gs-relative-growth-advantage': RelativeGrowthAdvantageComponent;
1394
+ 'gs-statistics': StatisticsComponent;
1411
1395
  }
1412
1396
  }
1413
1397
 
@@ -1415,7 +1399,7 @@ declare global {
1415
1399
  declare global {
1416
1400
  namespace JSX {
1417
1401
  interface IntrinsicElements {
1418
- 'gs-relative-growth-advantage': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1402
+ 'gs-statistics': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1419
1403
  }
1420
1404
  }
1421
1405
  }
@@ -1423,7 +1407,11 @@ declare global {
1423
1407
 
1424
1408
  declare global {
1425
1409
  interface HTMLElementTagNameMap {
1426
- 'gs-aggregate': AggregateComponent;
1410
+ 'gs-date-range-selector': DateRangeSelectorComponent;
1411
+ }
1412
+ interface HTMLElementEventMap {
1413
+ 'gs-date-range-filter-changed': CustomEvent<Record<string, string>>;
1414
+ 'gs-date-range-option-changed': DateRangeOptionChangedEvent;
1427
1415
  }
1428
1416
  }
1429
1417
 
@@ -1431,7 +1419,7 @@ declare global {
1431
1419
  declare global {
1432
1420
  namespace JSX {
1433
1421
  interface IntrinsicElements {
1434
- 'gs-aggregate': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1422
+ 'gs-date-range-selector': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1435
1423
  }
1436
1424
  }
1437
1425
  }
@@ -1439,7 +1427,10 @@ declare global {
1439
1427
 
1440
1428
  declare global {
1441
1429
  interface HTMLElementTagNameMap {
1442
- 'gs-number-sequences-over-time': NumberSequencesOverTimeComponent;
1430
+ 'gs-location-filter': LocationFilterComponent;
1431
+ }
1432
+ interface HTMLElementEventMap {
1433
+ 'gs-location-changed': LocationChangedEvent;
1443
1434
  }
1444
1435
  }
1445
1436
 
@@ -1447,7 +1438,7 @@ declare global {
1447
1438
  declare global {
1448
1439
  namespace JSX {
1449
1440
  interface IntrinsicElements {
1450
- 'gs-number-sequences-over-time': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1441
+ 'gs-location-filter': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1451
1442
  }
1452
1443
  }
1453
1444
  }
@@ -1455,7 +1446,10 @@ declare global {
1455
1446
 
1456
1447
  declare global {
1457
1448
  interface HTMLElementTagNameMap {
1458
- 'gs-mutations-over-time': MutationsOverTimeComponent;
1449
+ 'gs-mutation-filter': MutationFilterComponent;
1450
+ }
1451
+ interface HTMLElementEventMap {
1452
+ 'gs-mutation-filter-changed': CustomEvent<MutationsFilter>;
1459
1453
  }
1460
1454
  }
1461
1455
 
@@ -1463,7 +1457,7 @@ declare global {
1463
1457
  declare global {
1464
1458
  namespace JSX {
1465
1459
  interface IntrinsicElements {
1466
- 'gs-mutations-over-time': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1460
+ 'gs-mutation-filter': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1467
1461
  }
1468
1462
  }
1469
1463
  }
@@ -1471,7 +1465,10 @@ declare global {
1471
1465
 
1472
1466
  declare global {
1473
1467
  interface HTMLElementTagNameMap {
1474
- 'gs-sequences-by-location': SequencesByLocationComponent;
1468
+ 'gs-lineage-filter': LineageFilterComponent;
1469
+ }
1470
+ interface HTMLElementEventMap {
1471
+ 'gs-lineage-filter-changed': CustomEvent<Record<string, string>>;
1475
1472
  }
1476
1473
  }
1477
1474
 
@@ -1479,7 +1476,7 @@ declare global {
1479
1476
  declare global {
1480
1477
  namespace JSX {
1481
1478
  interface IntrinsicElements {
1482
- 'gs-sequences-by-location': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1479
+ 'gs-lineage-filter': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1483
1480
  }
1484
1481
  }
1485
1482
  }
@@ -1487,7 +1484,10 @@ declare global {
1487
1484
 
1488
1485
  declare global {
1489
1486
  interface HTMLElementTagNameMap {
1490
- 'gs-statistics': StatisticsComponent;
1487
+ 'gs-text-input': TextInputComponent;
1488
+ }
1489
+ interface HTMLElementEventMap {
1490
+ 'gs-text-input-changed': CustomEvent<Record<string, string>>;
1491
1491
  }
1492
1492
  }
1493
1493
 
@@ -1495,7 +1495,7 @@ declare global {
1495
1495
  declare global {
1496
1496
  namespace JSX {
1497
1497
  interface IntrinsicElements {
1498
- 'gs-statistics': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1498
+ 'gs-text-input': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1499
1499
  }
1500
1500
  }
1501
1501
  }
@@ -10,7 +10,7 @@ import { v as views, n as namedLapisFilterSchema, s as sequenceTypeSchema, l as
10
10
  import { autoUpdate, computePosition, offset, shift, flip } from "@floating-ui/dom";
11
11
  import { ReactiveElement } from "@lit/reactive-element";
12
12
  import { BarWithErrorBarsController, BarWithErrorBar } from "chartjs-chart-error-bars";
13
- import Leaflet from "leaflet";
13
+ import { map, geoJson } from "leaflet";
14
14
  import * as topojson from "topojson-client";
15
15
  import flatpickr from "flatpickr";
16
16
  /**
@@ -8617,7 +8617,7 @@ function getDatasets$2(fields, maxNumberOfBars, data) {
8617
8617
  ]
8618
8618
  };
8619
8619
  }
8620
- const map = /* @__PURE__ */ new Map();
8620
+ const map2 = /* @__PURE__ */ new Map();
8621
8621
  const countsOfEachBar = /* @__PURE__ */ new Map();
8622
8622
  for (const row of sortedData) {
8623
8623
  const yValue = row[fields[0]];
@@ -8627,17 +8627,17 @@ function getDatasets$2(fields, maxNumberOfBars, data) {
8627
8627
  }
8628
8628
  const yAxisKey = String(yValue);
8629
8629
  const secondaryKey = String(secondaryValue);
8630
- if (!map.has(secondaryKey)) {
8631
- map.set(secondaryKey, []);
8630
+ if (!map2.has(secondaryKey)) {
8631
+ map2.set(secondaryKey, []);
8632
8632
  }
8633
- (_a = map.get(secondaryKey)) == null ? void 0 : _a.push({
8633
+ (_a = map2.get(secondaryKey)) == null ? void 0 : _a.push({
8634
8634
  y: yAxisKey,
8635
8635
  x: row.count,
8636
8636
  proportion: row.proportion
8637
8637
  });
8638
8638
  countsOfEachBar.set(yAxisKey, (countsOfEachBar.get(yAxisKey) ?? 0) + row.count);
8639
8639
  }
8640
- const datasets2 = Array.from(map.entries()).map(sortAndTruncateYAxisKeys(countsOfEachBar, maxNumberOfBars)).map(([key, value], index) => ({
8640
+ const datasets2 = Array.from(map2.entries()).map(sortAndTruncateYAxisKeys(countsOfEachBar, maxNumberOfBars)).map(([key, value], index) => ({
8641
8641
  borderWidth: 1,
8642
8642
  backgroundColor: singleGraphColorRGBAById(index, 0.3),
8643
8643
  borderColor: singleGraphColorRGBAById(index),
@@ -9259,13 +9259,13 @@ class Map2dBase {
9259
9259
  }
9260
9260
  }
9261
9261
  class Map2dView {
9262
- constructor(map) {
9263
- this.keysFirstAxis = new Map(map.keysFirstAxis);
9264
- this.keysSecondAxis = new Map(map.keysSecondAxis);
9265
- if (map instanceof Map2dView) {
9266
- this.baseMap = map.baseMap;
9262
+ constructor(map2) {
9263
+ this.keysFirstAxis = new Map(map2.keysFirstAxis);
9264
+ this.keysSecondAxis = new Map(map2.keysSecondAxis);
9265
+ if (map2 instanceof Map2dView) {
9266
+ this.baseMap = map2.baseMap;
9267
9267
  }
9268
- this.baseMap = map;
9268
+ this.baseMap = map2;
9269
9269
  }
9270
9270
  serializeFirstAxis(key) {
9271
9271
  return this.baseMap.serializeFirstAxis(key);
@@ -10489,7 +10489,7 @@ const SequencesByLocationMap = ({
10489
10489
  if (!ref.current) {
10490
10490
  return;
10491
10491
  }
10492
- const leafletMap = Leaflet.map(ref.current, {
10492
+ const leafletMap = map(ref.current, {
10493
10493
  scrollWheelZoom: enableMapNavigation,
10494
10494
  zoomControl: enableMapNavigation,
10495
10495
  keyboard: enableMapNavigation,
@@ -10498,7 +10498,7 @@ const SequencesByLocationMap = ({
10498
10498
  zoom,
10499
10499
  center: [offsetY, offsetX]
10500
10500
  });
10501
- Leaflet.geoJson(locations, {
10501
+ geoJson(locations, {
10502
10502
  style: (feature) => {
10503
10503
  var _a;
10504
10504
  return {
@@ -14561,7 +14561,16 @@ LocationFilterComponent = __decorateClass$3([
14561
14561
  async function fetchAutocompleteList(lapis, field, signal) {
14562
14562
  const fetchAggregatedOperator = new FetchAggregatedOperator({}, [field]);
14563
14563
  const data = (await fetchAggregatedOperator.evaluate(lapis, signal)).content;
14564
- return data.map((item) => item[field]);
14564
+ return data.map((item) => item[field]).sort();
14565
+ }
14566
+ class TextInputChangedEvent extends CustomEvent {
14567
+ constructor(detail) {
14568
+ super("gs-text-input-changed", {
14569
+ detail,
14570
+ bubbles: true,
14571
+ composed: true
14572
+ });
14573
+ }
14565
14574
  }
14566
14575
  const textInputInnerPropsSchema = z$2.object({
14567
14576
  lapisField: z$2.string().min(1),
@@ -14576,9 +14585,8 @@ const TextInput = (props) => {
14576
14585
  const size = { width, height: "3rem" };
14577
14586
  return /* @__PURE__ */ u$1(ErrorBoundary, { size, layout: "horizontal", componentProps: props, schema: textInputPropsSchema, children: /* @__PURE__ */ u$1(ResizeContainer, { size, children: /* @__PURE__ */ u$1(TextInputInner, { ...innerProps }) }) });
14578
14587
  };
14579
- const TextInputInner = ({ lapisField, placeholderText, initialValue }) => {
14588
+ const TextInputInner = ({ initialValue, lapisField, placeholderText }) => {
14580
14589
  const lapis = x$1(LapisUrlContext);
14581
- const inputRef = A$1(null);
14582
14590
  const { data, error, isLoading } = useQuery(() => fetchAutocompleteList(lapis, lapisField), [lapisField, lapis]);
14583
14591
  if (isLoading) {
14584
14592
  return /* @__PURE__ */ u$1(LoadingDisplay, {});
@@ -14589,39 +14597,143 @@ const TextInputInner = ({ lapisField, placeholderText, initialValue }) => {
14589
14597
  if (data === null) {
14590
14598
  return /* @__PURE__ */ u$1(NoDataDisplay, {});
14591
14599
  }
14592
- const onInput = () => {
14593
- var _a, _b, _c;
14594
- const value = ((_a = inputRef.current) == null ? void 0 : _a.value) === "" ? void 0 : (_b = inputRef.current) == null ? void 0 : _b.value;
14595
- if (isValidValue(value)) {
14596
- (_c = inputRef.current) == null ? void 0 : _c.dispatchEvent(
14597
- new CustomEvent("gs-text-input-changed", {
14598
- detail: { [lapisField]: value },
14599
- bubbles: true,
14600
- composed: true
14601
- })
14602
- );
14600
+ return /* @__PURE__ */ u$1(
14601
+ TextSelector,
14602
+ {
14603
+ lapisField,
14604
+ initialValue,
14605
+ placeholderText,
14606
+ data
14603
14607
  }
14604
- };
14605
- const isValidValue = (value) => {
14606
- if (value === void 0) {
14608
+ );
14609
+ };
14610
+ const TextSelector = ({
14611
+ lapisField,
14612
+ initialValue,
14613
+ placeholderText,
14614
+ data
14615
+ }) => {
14616
+ var _a;
14617
+ const [items, setItems] = h(data.filter((item) => filterByInputValue2(item, initialValue)));
14618
+ const divRef = A$1(null);
14619
+ const shadowRoot = ((_a = divRef.current) == null ? void 0 : _a.shadowRoot) ?? void 0;
14620
+ const environment = shadowRoot !== void 0 ? {
14621
+ addEventListener: window.addEventListener.bind(window),
14622
+ removeEventListener: window.removeEventListener.bind(window),
14623
+ document: shadowRoot.ownerDocument,
14624
+ Node: window.Node
14625
+ } : void 0;
14626
+ function filterByInputValue2(item, inputValue2) {
14627
+ if (inputValue2 === void 0 || inputValue2 === null || inputValue2 === "") {
14607
14628
  return true;
14608
14629
  }
14609
- return data.includes(value);
14630
+ return item == null ? void 0 : item.toLowerCase().includes((inputValue2 == null ? void 0 : inputValue2.toLowerCase()) || "");
14631
+ }
14632
+ const {
14633
+ isOpen,
14634
+ getToggleButtonProps,
14635
+ getMenuProps,
14636
+ getInputProps,
14637
+ highlightedIndex,
14638
+ getItemProps,
14639
+ selectedItem,
14640
+ inputValue,
14641
+ selectItem,
14642
+ setInputValue,
14643
+ closeMenu
14644
+ } = useCombobox({
14645
+ onInputValueChange({ inputValue: inputValue2 }) {
14646
+ setItems(data.filter((item) => filterByInputValue2(item, inputValue2)));
14647
+ },
14648
+ onSelectedItemChange({ selectedItem: selectedItem2 }) {
14649
+ var _a2;
14650
+ if (selectedItem2 !== null) {
14651
+ (_a2 = divRef.current) == null ? void 0 : _a2.dispatchEvent(new TextInputChangedEvent({ [lapisField]: selectedItem2 }));
14652
+ }
14653
+ },
14654
+ items,
14655
+ itemToString(item) {
14656
+ return item ?? "";
14657
+ },
14658
+ initialSelectedItem: initialValue,
14659
+ environment
14660
+ });
14661
+ const onInputBlur = () => {
14662
+ var _a2;
14663
+ if (inputValue === "") {
14664
+ (_a2 = divRef.current) == null ? void 0 : _a2.dispatchEvent(new TextInputChangedEvent({ [lapisField]: void 0 }));
14665
+ selectItem(null);
14666
+ } else if (inputValue !== selectedItem) {
14667
+ setInputValue(selectedItem ?? "");
14668
+ }
14610
14669
  };
14611
- return /* @__PURE__ */ u$1(Fragment, { children: [
14670
+ const clearInput = () => {
14671
+ var _a2;
14672
+ (_a2 = divRef.current) == null ? void 0 : _a2.dispatchEvent(new TextInputChangedEvent({ [lapisField]: void 0 }));
14673
+ selectItem(null);
14674
+ };
14675
+ const buttonRef = A$1(null);
14676
+ return /* @__PURE__ */ u$1("div", { ref: divRef, className: "relative w-full", children: [
14677
+ /* @__PURE__ */ u$1("div", { className: "w-full flex flex-col gap-1", children: /* @__PURE__ */ u$1(
14678
+ "div",
14679
+ {
14680
+ className: "flex gap-0.5 input input-bordered min-w-32",
14681
+ onBlur: (event) => {
14682
+ if (event.relatedTarget != buttonRef.current) {
14683
+ closeMenu();
14684
+ }
14685
+ },
14686
+ children: [
14687
+ /* @__PURE__ */ u$1(
14688
+ "input",
14689
+ {
14690
+ placeholder: placeholderText,
14691
+ className: "w-full p-1.5",
14692
+ ...getInputProps(),
14693
+ onBlur: onInputBlur
14694
+ }
14695
+ ),
14696
+ /* @__PURE__ */ u$1(
14697
+ "button",
14698
+ {
14699
+ "aria-label": "clear selection",
14700
+ className: `px-2 ${inputValue === "" && "hidden"}`,
14701
+ type: "button",
14702
+ onClick: clearInput,
14703
+ tabIndex: -1,
14704
+ children: "×"
14705
+ }
14706
+ ),
14707
+ /* @__PURE__ */ u$1(
14708
+ "button",
14709
+ {
14710
+ "aria-label": "toggle menu",
14711
+ className: "px-2",
14712
+ type: "button",
14713
+ ...getToggleButtonProps(),
14714
+ ref: buttonRef,
14715
+ children: isOpen ? /* @__PURE__ */ u$1(Fragment, { children: "↑" }) : /* @__PURE__ */ u$1(Fragment, { children: "↓" })
14716
+ }
14717
+ )
14718
+ ]
14719
+ }
14720
+ ) }),
14612
14721
  /* @__PURE__ */ u$1(
14613
- "input",
14722
+ "ul",
14614
14723
  {
14615
- type: "text",
14616
- class: "input input-bordered w-full",
14617
- placeholder: placeholderText ?? lapisField,
14618
- onInput,
14619
- ref: inputRef,
14620
- list: lapisField,
14621
- value: initialValue
14724
+ className: `absolute bg-white mt-1 shadow-md max-h-80 overflow-scroll z-10 w-full min-w-32 ${!(isOpen && items.length > 0) && "hidden"}`,
14725
+ ...getMenuProps(),
14726
+ children: isOpen && items.map((item, index) => /* @__PURE__ */ u$1(
14727
+ "li",
14728
+ {
14729
+ className: `${highlightedIndex === index && "bg-blue-300"} ${selectedItem !== null} py-2 px-3 shadow-sm flex flex-col`,
14730
+ ...getItemProps({ item, index }),
14731
+ children: /* @__PURE__ */ u$1("span", { children: item })
14732
+ },
14733
+ item
14734
+ ))
14622
14735
  }
14623
- ),
14624
- /* @__PURE__ */ u$1("datalist", { id: lapisField, children: data.map((item) => /* @__PURE__ */ u$1("option", { value: item }, item)) })
14736
+ )
14625
14737
  ] });
14626
14738
  };
14627
14739
  var __defProp$2 = Object.defineProperty;