@internetarchive/collection-browser 3.4.1-alpha-webdev7761.0 → 3.4.1-alpha-webdev7761.2

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.
@@ -0,0 +1,83 @@
1
+ import { TemplateResult } from 'lit';
2
+
3
+ /**
4
+ * Represents a single predefined option in a combo box.
5
+ */
6
+ export interface IAComboBoxOption {
7
+ /**
8
+ * A unique ID representing this option.
9
+ *
10
+ * This value is used both as the DOM `id` for the option element, and as the
11
+ * identifier indicating which option(s) are selected.
12
+ */
13
+ id: string;
14
+
15
+ /**
16
+ * The text to use for filtering autocomplete entries in the options menu, and for
17
+ * displaying the option in the menu if no separate `content` value is provided.
18
+ */
19
+ text: string;
20
+
21
+ /**
22
+ * Optionally, the text or template to render for this option in the dropdown menu.
23
+ *
24
+ * If provided, it will be displayed in the options list instead of the option's
25
+ * `text` value (though `text` will still be used for filtering the list). For this
26
+ * reason, it is strongly encouraged to ensure that this content still prominently
27
+ * includes the `text` value both visually and in accessible labels to avoid confusion.
28
+ *
29
+ * If not provided, then `text` assumes both display and filtering roles by default.
30
+ */
31
+ content?: string | TemplateResult;
32
+
33
+ /**
34
+ * Optionally, a callback to invoke when this option is selected in the combo box menu.
35
+ */
36
+ onSelected?: (option: this) => unknown;
37
+ }
38
+
39
+ /**
40
+ * Type union of the possible preset options for combo box behavior (defining editability,
41
+ * autocomplete style, etc).
42
+ * @see {@linkcode IAComboBox.behavior}
43
+ */
44
+ export type IAComboBoxBehavior = 'select-only' | 'list' | 'freeform';
45
+
46
+ /**
47
+ * Type union of the possible preset options for filtering combo box entries.
48
+ * @see {@linkcode IAComboBox.filter}
49
+ */
50
+ export type IAComboBoxFilterPreset =
51
+ | 'all'
52
+ | 'prefix'
53
+ | 'suffix'
54
+ | 'substring'
55
+ | 'subsequence';
56
+
57
+ /**
58
+ * Required shape of functions used to filter combo box entries.
59
+ * @see {@linkcode IAComboBox.filter}
60
+ */
61
+ export type IAComboBoxFilterFunction = (
62
+ filterText: string,
63
+ optionText: string,
64
+ option: IAComboBoxOption,
65
+ ) => boolean;
66
+
67
+ /**
68
+ * The `filter` property of a combo box may be specified either as a string
69
+ * identifying a preset function, or directly as a custom filtering function.
70
+ * @see {@linkcode IAComboBox.filter}
71
+ */
72
+ export type IAComboBoxFilterOption =
73
+ | IAComboBoxFilterPreset
74
+ | IAComboBoxFilterFunction;
75
+
76
+ /**
77
+ * Helper function to check if a Map has any of a list of keys
78
+ * @param map The map to check
79
+ * @param keys The list of keys to check
80
+ */
81
+ export function hasAnyOf<T>(map: Map<T, unknown>, keys: T[]): boolean {
82
+ return keys.some((prop) => map.has(prop));
83
+ }