govuk_publishing_components 58.1.1 → 59.0.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.
Files changed (165) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/select-with-search/cross-icon.svg +6 -0
  3. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-search-tracker.js +4 -0
  4. data/app/assets/javascripts/govuk_publishing_components/components/select-with-search.js +57 -0
  5. data/app/assets/stylesheets/govuk_publishing_components/_all_components.scss +2 -0
  6. data/app/assets/stylesheets/govuk_publishing_components/components/_action-link.scss +14 -136
  7. data/app/assets/stylesheets/govuk_publishing_components/components/_heading.scss +0 -5
  8. data/app/assets/stylesheets/govuk_publishing_components/components/_layout-header.scss +6 -48
  9. data/app/assets/stylesheets/govuk_publishing_components/components/_select-with-search.scss +168 -0
  10. data/app/assets/stylesheets/govuk_publishing_components/components/_select.scss +6 -0
  11. data/app/assets/stylesheets/govuk_publishing_components/components/_tag.scss +14 -0
  12. data/app/assets/stylesheets/govuk_publishing_components/components/helpers/_markdown-typography.scss +1 -1
  13. data/app/views/govuk_publishing_components/components/_action_link.html.erb +4 -37
  14. data/app/views/govuk_publishing_components/components/_layout_header.html.erb +0 -2
  15. data/app/views/govuk_publishing_components/components/_select.html.erb +22 -23
  16. data/app/views/govuk_publishing_components/components/_select_with_search.html.erb +14 -0
  17. data/app/views/govuk_publishing_components/components/_share_links.html.erb +17 -9
  18. data/app/views/govuk_publishing_components/components/_tag.html.erb +20 -0
  19. data/app/views/govuk_publishing_components/components/docs/action_link.yml +0 -62
  20. data/app/views/govuk_publishing_components/components/docs/layout_header.yml +13 -0
  21. data/app/views/govuk_publishing_components/components/docs/select.yml +11 -0
  22. data/app/views/govuk_publishing_components/components/docs/select_with_search.yml +196 -0
  23. data/app/views/govuk_publishing_components/components/docs/share_links.yml +10 -0
  24. data/app/views/govuk_publishing_components/components/docs/signup_link.yml +0 -7
  25. data/app/views/govuk_publishing_components/components/docs/single_page_notification_button.yml +1 -7
  26. data/app/views/govuk_publishing_components/components/docs/subscription_links.yml +1 -7
  27. data/app/views/govuk_publishing_components/components/docs/tag.yml +57 -0
  28. data/app/views/govuk_publishing_components/components/layout_header/_header_logo.html.erb +16 -5
  29. data/lib/govuk_publishing_components/presenters/heading_helper.rb +1 -2
  30. data/lib/govuk_publishing_components/presenters/select_helper.rb +8 -5
  31. data/lib/govuk_publishing_components/presenters/select_with_search_helper.rb +92 -0
  32. data/lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb +1 -1
  33. data/lib/govuk_publishing_components/version.rb +1 -1
  34. data/lib/govuk_publishing_components.rb +1 -0
  35. data/node_modules/choices.js/LICENSE +21 -0
  36. data/node_modules/choices.js/README.md +1360 -0
  37. data/node_modules/choices.js/package.json +173 -0
  38. data/node_modules/choices.js/public/assets/scripts/choices.js +5230 -0
  39. data/node_modules/choices.js/public/assets/scripts/choices.min.js +2 -0
  40. data/node_modules/choices.js/public/assets/scripts/choices.mjs +5222 -0
  41. data/node_modules/choices.js/public/assets/scripts/choices.search-basic.js +4748 -0
  42. data/node_modules/choices.js/public/assets/scripts/choices.search-basic.min.js +2 -0
  43. data/node_modules/choices.js/public/assets/scripts/choices.search-basic.mjs +4740 -0
  44. data/node_modules/choices.js/public/assets/scripts/choices.search-kmp.js +3631 -0
  45. data/node_modules/choices.js/public/assets/scripts/choices.search-kmp.min.js +2 -0
  46. data/node_modules/choices.js/public/assets/scripts/choices.search-kmp.mjs +3623 -0
  47. data/node_modules/choices.js/public/assets/scripts/choices.search-prefix.js +3590 -0
  48. data/node_modules/choices.js/public/assets/scripts/choices.search-prefix.min.js +2 -0
  49. data/node_modules/choices.js/public/assets/scripts/choices.search-prefix.mjs +3582 -0
  50. data/node_modules/choices.js/public/assets/styles/base.css +180 -0
  51. data/node_modules/choices.js/public/assets/styles/base.css.map +1 -0
  52. data/node_modules/choices.js/public/assets/styles/base.min.css +1 -0
  53. data/node_modules/choices.js/public/assets/styles/choices.css +338 -0
  54. data/node_modules/choices.js/public/assets/styles/choices.css.map +1 -0
  55. data/node_modules/choices.js/public/assets/styles/choices.min.css +1 -0
  56. data/node_modules/choices.js/public/types/src/index.d.ts +6 -0
  57. data/node_modules/choices.js/public/types/src/scripts/actions/choices.d.ts +30 -0
  58. data/node_modules/choices.js/public/types/src/scripts/actions/groups.d.ts +8 -0
  59. data/node_modules/choices.js/public/types/src/scripts/actions/items.d.ts +17 -0
  60. data/node_modules/choices.js/public/types/src/scripts/choices.d.ts +210 -0
  61. data/node_modules/choices.js/public/types/src/scripts/components/container.d.ts +36 -0
  62. data/node_modules/choices.js/public/types/src/scripts/components/dropdown.d.ts +21 -0
  63. data/node_modules/choices.js/public/types/src/scripts/components/index.d.ts +7 -0
  64. data/node_modules/choices.js/public/types/src/scripts/components/input.d.ts +37 -0
  65. data/node_modules/choices.js/public/types/src/scripts/components/list.d.ts +14 -0
  66. data/node_modules/choices.js/public/types/src/scripts/components/wrapped-element.d.ts +21 -0
  67. data/node_modules/choices.js/public/types/src/scripts/components/wrapped-input.d.ts +3 -0
  68. data/node_modules/choices.js/public/types/src/scripts/components/wrapped-select.d.ts +20 -0
  69. data/node_modules/choices.js/public/types/src/scripts/constants.d.ts +1 -0
  70. data/node_modules/choices.js/public/types/src/scripts/defaults.d.ts +4 -0
  71. data/node_modules/choices.js/public/types/src/scripts/interfaces/action-type.d.ts +13 -0
  72. data/node_modules/choices.js/public/types/src/scripts/interfaces/build-flags.d.ts +11 -0
  73. data/node_modules/choices.js/public/types/src/scripts/interfaces/choice-full.d.ts +23 -0
  74. data/node_modules/choices.js/public/types/src/scripts/interfaces/class-names.d.ts +61 -0
  75. data/node_modules/choices.js/public/types/src/scripts/interfaces/event-choice.d.ts +7 -0
  76. data/node_modules/choices.js/public/types/src/scripts/interfaces/event-type.d.ts +14 -0
  77. data/node_modules/choices.js/public/types/src/scripts/interfaces/group-full.d.ts +10 -0
  78. data/node_modules/choices.js/public/types/src/scripts/interfaces/index.d.ts +14 -0
  79. data/node_modules/choices.js/public/types/src/scripts/interfaces/input-choice.d.ts +15 -0
  80. data/node_modules/choices.js/public/types/src/scripts/interfaces/input-group.d.ts +10 -0
  81. data/node_modules/choices.js/public/types/src/scripts/interfaces/item.d.ts +17 -0
  82. data/node_modules/choices.js/public/types/src/scripts/interfaces/keycode-map.d.ts +13 -0
  83. data/node_modules/choices.js/public/types/src/scripts/interfaces/options.d.ts +566 -0
  84. data/node_modules/choices.js/public/types/src/scripts/interfaces/passed-element-type.d.ts +7 -0
  85. data/node_modules/choices.js/public/types/src/scripts/interfaces/passed-element.d.ts +95 -0
  86. data/node_modules/choices.js/public/types/src/scripts/interfaces/position-options-type.d.ts +1 -0
  87. data/node_modules/choices.js/public/types/src/scripts/interfaces/search.d.ts +11 -0
  88. data/node_modules/choices.js/public/types/src/scripts/interfaces/state.d.ts +10 -0
  89. data/node_modules/choices.js/public/types/src/scripts/interfaces/store.d.ts +64 -0
  90. data/node_modules/choices.js/public/types/src/scripts/interfaces/string-pre-escaped.d.ts +3 -0
  91. data/node_modules/choices.js/public/types/src/scripts/interfaces/string-untrusted.d.ts +4 -0
  92. data/node_modules/choices.js/public/types/src/scripts/interfaces/templates.d.ts +29 -0
  93. data/node_modules/choices.js/public/types/src/scripts/interfaces/types.d.ts +18 -0
  94. data/node_modules/choices.js/public/types/src/scripts/lib/choice-input.d.ts +9 -0
  95. data/node_modules/choices.js/public/types/src/scripts/lib/html-guard-statements.d.ts +4 -0
  96. data/node_modules/choices.js/public/types/src/scripts/lib/utils.d.ts +31 -0
  97. data/node_modules/choices.js/public/types/src/scripts/reducers/choices.d.ts +8 -0
  98. data/node_modules/choices.js/public/types/src/scripts/reducers/groups.d.ts +8 -0
  99. data/node_modules/choices.js/public/types/src/scripts/reducers/items.d.ts +9 -0
  100. data/node_modules/choices.js/public/types/src/scripts/search/fuse.d.ts +14 -0
  101. data/node_modules/choices.js/public/types/src/scripts/search/index.d.ts +3 -0
  102. data/node_modules/choices.js/public/types/src/scripts/search/kmp.d.ts +11 -0
  103. data/node_modules/choices.js/public/types/src/scripts/search/prefix-filter.d.ts +11 -0
  104. data/node_modules/choices.js/public/types/src/scripts/store/store.d.ts +59 -0
  105. data/node_modules/choices.js/public/types/src/scripts/templates.d.ts +8 -0
  106. data/node_modules/choices.js/src/entry.js +3 -0
  107. data/node_modules/choices.js/src/icons/cross-inverse.svg +1 -0
  108. data/node_modules/choices.js/src/icons/cross.svg +1 -0
  109. data/node_modules/choices.js/src/index.ts +8 -0
  110. data/node_modules/choices.js/src/scripts/actions/choices.ts +59 -0
  111. data/node_modules/choices.js/src/scripts/actions/groups.ts +14 -0
  112. data/node_modules/choices.js/src/scripts/actions/items.ts +34 -0
  113. data/node_modules/choices.js/src/scripts/choices.ts +2364 -0
  114. data/node_modules/choices.js/src/scripts/components/container.ts +157 -0
  115. data/node_modules/choices.js/src/scripts/components/dropdown.ts +50 -0
  116. data/node_modules/choices.js/src/scripts/components/index.ts +8 -0
  117. data/node_modules/choices.js/src/scripts/components/input.ts +146 -0
  118. data/node_modules/choices.js/src/scripts/components/list.ts +89 -0
  119. data/node_modules/choices.js/src/scripts/components/wrapped-element.ts +89 -0
  120. data/node_modules/choices.js/src/scripts/components/wrapped-input.ts +3 -0
  121. data/node_modules/choices.js/src/scripts/components/wrapped-select.ts +115 -0
  122. data/node_modules/choices.js/src/scripts/constants.ts +1 -0
  123. data/node_modules/choices.js/src/scripts/defaults.ts +93 -0
  124. data/node_modules/choices.js/src/scripts/interfaces/action-type.ts +15 -0
  125. data/node_modules/choices.js/src/scripts/interfaces/build-flags.ts +17 -0
  126. data/node_modules/choices.js/src/scripts/interfaces/choice-full.ts +30 -0
  127. data/node_modules/choices.js/src/scripts/interfaces/class-names.ts +61 -0
  128. data/node_modules/choices.js/src/scripts/interfaces/event-choice.ts +9 -0
  129. data/node_modules/choices.js/src/scripts/interfaces/event-type.ts +16 -0
  130. data/node_modules/choices.js/src/scripts/interfaces/group-full.ts +12 -0
  131. data/node_modules/choices.js/src/scripts/interfaces/index.ts +14 -0
  132. data/node_modules/choices.js/src/scripts/interfaces/input-choice.ts +17 -0
  133. data/node_modules/choices.js/src/scripts/interfaces/input-group.ts +11 -0
  134. data/node_modules/choices.js/src/scripts/interfaces/item.ts +17 -0
  135. data/node_modules/choices.js/src/scripts/interfaces/keycode-map.ts +13 -0
  136. data/node_modules/choices.js/src/scripts/interfaces/options.ts +619 -0
  137. data/node_modules/choices.js/src/scripts/interfaces/passed-element-type.ts +9 -0
  138. data/node_modules/choices.js/src/scripts/interfaces/passed-element.ts +96 -0
  139. data/node_modules/choices.js/src/scripts/interfaces/position-options-type.ts +1 -0
  140. data/node_modules/choices.js/src/scripts/interfaces/search.ts +12 -0
  141. data/node_modules/choices.js/src/scripts/interfaces/state.ts +12 -0
  142. data/node_modules/choices.js/src/scripts/interfaces/store.ts +84 -0
  143. data/node_modules/choices.js/src/scripts/interfaces/string-pre-escaped.ts +3 -0
  144. data/node_modules/choices.js/src/scripts/interfaces/string-untrusted.ts +5 -0
  145. data/node_modules/choices.js/src/scripts/interfaces/templates.ts +66 -0
  146. data/node_modules/choices.js/src/scripts/interfaces/types.ts +21 -0
  147. data/node_modules/choices.js/src/scripts/lib/choice-input.ts +88 -0
  148. data/node_modules/choices.js/src/scripts/lib/html-guard-statements.ts +7 -0
  149. data/node_modules/choices.js/src/scripts/lib/utils.ts +230 -0
  150. data/node_modules/choices.js/src/scripts/reducers/choices.ts +86 -0
  151. data/node_modules/choices.js/src/scripts/reducers/groups.ts +32 -0
  152. data/node_modules/choices.js/src/scripts/reducers/items.ts +86 -0
  153. data/node_modules/choices.js/src/scripts/search/fuse.ts +59 -0
  154. data/node_modules/choices.js/src/scripts/search/index.ts +17 -0
  155. data/node_modules/choices.js/src/scripts/search/kmp.ts +87 -0
  156. data/node_modules/choices.js/src/scripts/search/prefix-filter.ts +42 -0
  157. data/node_modules/choices.js/src/scripts/store/store.ts +184 -0
  158. data/node_modules/choices.js/src/scripts/templates.ts +409 -0
  159. data/node_modules/choices.js/src/styles/base.scss +189 -0
  160. data/node_modules/choices.js/src/styles/choices.scss +414 -0
  161. data/node_modules/choices.js/src/tsconfig.json +22 -0
  162. metadata +137 -4
  163. data/app/assets/images/govuk_publishing_components/action-link-arrow--dark.svg +0 -5
  164. data/app/assets/images/govuk_publishing_components/action-link-arrow--simple-light.svg +0 -4
  165. data/app/assets/images/govuk_publishing_components/action-link-arrow.svg +0 -5
@@ -0,0 +1,210 @@
1
+ import { Container, Dropdown, Input, List, WrappedInput, WrappedSelect } from './components';
2
+ import { InputChoice } from './interfaces/input-choice';
3
+ import { InputGroup } from './interfaces/input-group';
4
+ import { Options } from './interfaces/options';
5
+ import { StateChangeSet } from './interfaces/state';
6
+ import Store from './store/store';
7
+ import { ChoiceFull } from './interfaces/choice-full';
8
+ import { GroupFull } from './interfaces/group-full';
9
+ import { EventChoiceValueType, PassedElementType } from './interfaces';
10
+ import { EventChoice } from './interfaces/event-choice';
11
+ import { NoticeType, Templates } from './interfaces/templates';
12
+ import { Searcher } from './interfaces/search';
13
+ /**
14
+ * Choices
15
+ * @author Josh Johnson<josh@joshuajohnson.co.uk>
16
+ */
17
+ declare class Choices {
18
+ static version: string;
19
+ static get defaults(): {
20
+ options: Partial<Options>;
21
+ allOptions: Options;
22
+ templates: Templates;
23
+ };
24
+ initialised: boolean;
25
+ initialisedOK?: boolean;
26
+ config: Options;
27
+ passedElement: WrappedInput | WrappedSelect;
28
+ containerOuter: Container;
29
+ containerInner: Container;
30
+ choiceList: List;
31
+ itemList: List;
32
+ input: Input;
33
+ dropdown: Dropdown;
34
+ _elementType: PassedElementType;
35
+ _isTextElement: boolean;
36
+ _isSelectOneElement: boolean;
37
+ _isSelectMultipleElement: boolean;
38
+ _isSelectElement: boolean;
39
+ _hasNonChoicePlaceholder: boolean;
40
+ _canAddUserChoices: boolean;
41
+ _store: Store<Options>;
42
+ _templates: Templates;
43
+ _lastAddedChoiceId: number;
44
+ _lastAddedGroupId: number;
45
+ _currentValue: string;
46
+ _canSearch: boolean;
47
+ _isScrollingOnIe: boolean;
48
+ _highlightPosition: number;
49
+ _wasTap: boolean;
50
+ _isSearching: boolean;
51
+ _placeholderValue: string | null;
52
+ _baseId: string;
53
+ _direction: HTMLElement['dir'];
54
+ _idNames: {
55
+ itemChoice: string;
56
+ };
57
+ _presetChoices: (ChoiceFull | GroupFull)[];
58
+ _initialItems: string[];
59
+ _searcher: Searcher<ChoiceFull>;
60
+ _notice?: {
61
+ type: NoticeType;
62
+ text: string;
63
+ };
64
+ _docRoot: ShadowRoot | HTMLElement;
65
+ constructor(element?: string | Element | HTMLInputElement | HTMLSelectElement, userConfig?: Partial<Options>);
66
+ init(): void;
67
+ destroy(): void;
68
+ enable(): this;
69
+ disable(): this;
70
+ highlightItem(item: InputChoice, runEvent?: boolean): this;
71
+ unhighlightItem(item: InputChoice, runEvent?: boolean): this;
72
+ highlightAll(): this;
73
+ unhighlightAll(): this;
74
+ removeActiveItemsByValue(value: string): this;
75
+ removeActiveItems(excludedId?: number): this;
76
+ removeHighlightedItems(runEvent?: boolean): this;
77
+ showDropdown(preventInputFocus?: boolean): this;
78
+ hideDropdown(preventInputBlur?: boolean): this;
79
+ getValue<B extends boolean = false>(valueOnly?: B): EventChoiceValueType<B> | EventChoiceValueType<B>[];
80
+ setValue(items: string[] | InputChoice[]): this;
81
+ setChoiceByValue(value: string | string[]): this;
82
+ /**
83
+ * Set choices of select input via an array of objects (or function that returns array of object or promise of it),
84
+ * a value field name and a label field name.
85
+ * This behaves the same as passing items via the choices option but can be called after initialising Choices.
86
+ * This can also be used to add groups of choices (see example 2); Optionally pass a true `replaceChoices` value to remove any existing choices.
87
+ * Optionally pass a `customProperties` object to add additional data to your choices (useful when searching/filtering etc).
88
+ *
89
+ * **Input types affected:** select-one, select-multiple
90
+ *
91
+ * @example
92
+ * ```js
93
+ * const example = new Choices(element);
94
+ *
95
+ * example.setChoices([
96
+ * {value: 'One', label: 'Label One', disabled: true},
97
+ * {value: 'Two', label: 'Label Two', selected: true},
98
+ * {value: 'Three', label: 'Label Three'},
99
+ * ], 'value', 'label', false);
100
+ * ```
101
+ *
102
+ * @example
103
+ * ```js
104
+ * const example = new Choices(element);
105
+ *
106
+ * example.setChoices(async () => {
107
+ * try {
108
+ * const items = await fetch('/items');
109
+ * return items.json()
110
+ * } catch(err) {
111
+ * console.error(err)
112
+ * }
113
+ * });
114
+ * ```
115
+ *
116
+ * @example
117
+ * ```js
118
+ * const example = new Choices(element);
119
+ *
120
+ * example.setChoices([{
121
+ * label: 'Group one',
122
+ * id: 1,
123
+ * disabled: false,
124
+ * choices: [
125
+ * {value: 'Child One', label: 'Child One', selected: true},
126
+ * {value: 'Child Two', label: 'Child Two', disabled: true},
127
+ * {value: 'Child Three', label: 'Child Three'},
128
+ * ]
129
+ * },
130
+ * {
131
+ * label: 'Group two',
132
+ * id: 2,
133
+ * disabled: false,
134
+ * choices: [
135
+ * {value: 'Child Four', label: 'Child Four', disabled: true},
136
+ * {value: 'Child Five', label: 'Child Five'},
137
+ * {value: 'Child Six', label: 'Child Six', customProperties: {
138
+ * description: 'Custom description about child six',
139
+ * random: 'Another random custom property'
140
+ * }},
141
+ * ]
142
+ * }], 'value', 'label', false);
143
+ * ```
144
+ */
145
+ setChoices(choicesArrayOrFetcher?: (InputChoice | InputGroup)[] | ((instance: Choices) => (InputChoice | InputGroup)[] | Promise<(InputChoice | InputGroup)[]>), value?: string | null, label?: string, replaceChoices?: boolean, clearSearchFlag?: boolean, replaceItems?: boolean): this | Promise<this>;
146
+ refresh(withEvents?: boolean, selectFirstOption?: boolean, deselectAll?: boolean): this;
147
+ removeChoice(value: string): this;
148
+ clearChoices(clearOptions?: boolean, clearItems?: boolean): this;
149
+ clearStore(clearOptions?: boolean): this;
150
+ clearInput(): this;
151
+ _validateConfig(): void;
152
+ _render(changes?: StateChangeSet): void;
153
+ _renderChoices(): void;
154
+ _renderItems(): void;
155
+ _displayNotice(text: string, type: NoticeType, openDropdown?: boolean): void;
156
+ _clearNotice(): void;
157
+ _renderNotice(fragment?: DocumentFragment): void;
158
+ _getChoiceForOutput(choice: ChoiceFull, keyCode?: number): EventChoice;
159
+ _triggerChange(value: any): void;
160
+ _handleButtonAction(element: HTMLElement): void;
161
+ _handleItemAction(element: HTMLElement, hasShiftKey?: boolean): void;
162
+ _handleChoiceAction(element: HTMLElement): boolean;
163
+ _handleBackspace(items: ChoiceFull[]): void;
164
+ _loadChoices(): void;
165
+ _handleLoadingState(setLoading?: boolean): void;
166
+ _handleSearch(value?: string): void;
167
+ _canAddItems(): boolean;
168
+ _canCreateItem(value: string): boolean;
169
+ _searchChoices(value: string): number | null;
170
+ _stopSearch(): void;
171
+ _addEventListeners(): void;
172
+ _removeEventListeners(): void;
173
+ _onKeyDown(event: KeyboardEvent): void;
174
+ _onKeyUp(): void;
175
+ _onInput(): void;
176
+ _onSelectKey(event: KeyboardEvent, hasItems: boolean): void;
177
+ _onEnterKey(event: KeyboardEvent, hasActiveDropdown: boolean): void;
178
+ _onEscapeKey(event: KeyboardEvent, hasActiveDropdown: boolean): void;
179
+ _onDirectionKey(event: KeyboardEvent, hasActiveDropdown: boolean): void;
180
+ _onDeleteKey(event: KeyboardEvent, items: ChoiceFull[], hasFocusedInput: boolean): void;
181
+ _onTouchMove(): void;
182
+ _onTouchEnd(event: TouchEvent): void;
183
+ /**
184
+ * Handles mousedown event in capture mode for containetOuter.element
185
+ */
186
+ _onMouseDown(event: MouseEvent): void;
187
+ /**
188
+ * Handles mouseover event over this.dropdown
189
+ * @param {MouseEvent} event
190
+ */
191
+ _onMouseOver({ target }: Pick<MouseEvent, 'target'>): void;
192
+ _onClick({ target }: Pick<MouseEvent, 'target'>): void;
193
+ _onFocus({ target }: Pick<FocusEvent, 'target'>): void;
194
+ _onBlur({ target }: Pick<FocusEvent, 'target'>): void;
195
+ _onFormReset(): void;
196
+ _highlightChoice(el?: HTMLElement | null): void;
197
+ _addItem(item: ChoiceFull, withEvents?: boolean, userTriggered?: boolean): void;
198
+ _removeItem(item: ChoiceFull): void;
199
+ _addChoice(choice: ChoiceFull, withEvents?: boolean, userTriggered?: boolean): void;
200
+ _addGroup(group: GroupFull, withEvents?: boolean): void;
201
+ _createTemplates(): void;
202
+ _createElements(): void;
203
+ _createStructure(): void;
204
+ _initStore(): void;
205
+ _addPredefinedChoices(choices: (ChoiceFull | GroupFull)[], selectFirstOption?: boolean, withEvents?: boolean): void;
206
+ _findAndSelectChoiceByValue(value: string, userTriggered?: boolean): boolean;
207
+ _generatePlaceholderValue(): string | null;
208
+ _warnChoicesInitFailed(caller: string): void;
209
+ }
210
+ export default Choices;
@@ -0,0 +1,36 @@
1
+ import { ClassNames } from '../interfaces/class-names';
2
+ import { PositionOptionsType } from '../interfaces/position-options-type';
3
+ import { PassedElementType } from '../interfaces/passed-element-type';
4
+ export default class Container {
5
+ element: HTMLElement;
6
+ type: PassedElementType;
7
+ classNames: ClassNames;
8
+ position: PositionOptionsType;
9
+ isOpen: boolean;
10
+ isFlipped: boolean;
11
+ isDisabled: boolean;
12
+ isLoading: boolean;
13
+ constructor({ element, type, classNames, position, }: {
14
+ element: HTMLElement;
15
+ type: PassedElementType;
16
+ classNames: ClassNames;
17
+ position: PositionOptionsType;
18
+ });
19
+ /**
20
+ * Determine whether container should be flipped based on passed
21
+ * dropdown position
22
+ */
23
+ shouldFlip(dropdownPos: number, dropdownHeight: number): boolean;
24
+ setActiveDescendant(activeDescendantID: string): void;
25
+ removeActiveDescendant(): void;
26
+ open(dropdownPos: number, dropdownHeight: number): void;
27
+ close(): void;
28
+ addFocusState(): void;
29
+ removeFocusState(): void;
30
+ enable(): void;
31
+ disable(): void;
32
+ wrap(element: HTMLElement): void;
33
+ unwrap(element: HTMLElement): void;
34
+ addLoadingState(): void;
35
+ removeLoadingState(): void;
36
+ }
@@ -0,0 +1,21 @@
1
+ import { ClassNames } from '../interfaces/class-names';
2
+ import { PassedElementType } from '../interfaces/passed-element-type';
3
+ export default class Dropdown {
4
+ element: HTMLElement;
5
+ type: PassedElementType;
6
+ classNames: ClassNames;
7
+ isActive: boolean;
8
+ constructor({ element, type, classNames, }: {
9
+ element: HTMLElement;
10
+ type: PassedElementType;
11
+ classNames: ClassNames;
12
+ });
13
+ /**
14
+ * Show dropdown to user by adding active state class
15
+ */
16
+ show(): this;
17
+ /**
18
+ * Hide dropdown from user
19
+ */
20
+ hide(): this;
21
+ }
@@ -0,0 +1,7 @@
1
+ import Dropdown from './dropdown';
2
+ import Container from './container';
3
+ import Input from './input';
4
+ import List from './list';
5
+ import WrappedInput from './wrapped-input';
6
+ import WrappedSelect from './wrapped-select';
7
+ export { Dropdown, Container, Input, List, WrappedInput, WrappedSelect };
@@ -0,0 +1,37 @@
1
+ import { ClassNames } from '../interfaces/class-names';
2
+ import { PassedElementType } from '../interfaces/passed-element-type';
3
+ export default class Input {
4
+ element: HTMLInputElement;
5
+ type: PassedElementType;
6
+ classNames: ClassNames;
7
+ preventPaste: boolean;
8
+ isFocussed: boolean;
9
+ isDisabled: boolean;
10
+ constructor({ element, type, classNames, preventPaste, }: {
11
+ element: HTMLInputElement;
12
+ type: PassedElementType;
13
+ classNames: ClassNames;
14
+ preventPaste: boolean;
15
+ });
16
+ set placeholder(placeholder: string);
17
+ get value(): string;
18
+ set value(value: string);
19
+ addEventListeners(): void;
20
+ removeEventListeners(): void;
21
+ enable(): void;
22
+ disable(): void;
23
+ focus(): void;
24
+ blur(): void;
25
+ clear(setWidth?: boolean): this;
26
+ /**
27
+ * Set the correct input width based on placeholder
28
+ * value or input value
29
+ */
30
+ setWidth(): void;
31
+ setActiveDescendant(activeDescendantID: string): void;
32
+ removeActiveDescendant(): void;
33
+ _onInput(): void;
34
+ _onPaste(event: ClipboardEvent): void;
35
+ _onFocus(): void;
36
+ _onBlur(): void;
37
+ }
@@ -0,0 +1,14 @@
1
+ export default class List {
2
+ element: HTMLElement;
3
+ scrollPos: number;
4
+ height: number;
5
+ constructor({ element }: {
6
+ element: HTMLElement;
7
+ });
8
+ prepend(node: Element | DocumentFragment): void;
9
+ scrollToTop(): void;
10
+ scrollToChildElement(element: HTMLElement, direction: 1 | -1): void;
11
+ _scrollDown(scrollPos: number, strength: number, destination: number): void;
12
+ _scrollUp(scrollPos: number, strength: number, destination: number): void;
13
+ _animateScroll(destination: number, direction: number): void;
14
+ }
@@ -0,0 +1,21 @@
1
+ import { ClassNames } from '../interfaces/class-names';
2
+ import { EventTypes } from '../interfaces/event-type';
3
+ import { EventMap } from '../interfaces';
4
+ export default class WrappedElement<T extends HTMLInputElement | HTMLSelectElement> {
5
+ element: T;
6
+ classNames: ClassNames;
7
+ isDisabled: boolean;
8
+ constructor({ element, classNames }: {
9
+ element: any;
10
+ classNames: any;
11
+ });
12
+ get isActive(): boolean;
13
+ get dir(): string;
14
+ get value(): string;
15
+ set value(value: string);
16
+ conceal(): void;
17
+ reveal(): void;
18
+ enable(): void;
19
+ disable(): void;
20
+ triggerEvent<K extends EventTypes>(eventType: EventTypes, data?: EventMap[K]['detail']): void;
21
+ }
@@ -0,0 +1,3 @@
1
+ import WrappedElement from './wrapped-element';
2
+ export default class WrappedInput extends WrappedElement<HTMLInputElement> {
3
+ }
@@ -0,0 +1,20 @@
1
+ import { ClassNames } from '../interfaces/class-names';
2
+ import WrappedElement from './wrapped-element';
3
+ import { GroupFull } from '../interfaces/group-full';
4
+ import { ChoiceFull } from '../interfaces/choice-full';
5
+ export default class WrappedSelect extends WrappedElement<HTMLSelectElement> {
6
+ classNames: ClassNames;
7
+ template: (data: object) => HTMLOptionElement;
8
+ extractPlaceholder: boolean;
9
+ constructor({ element, classNames, template, extractPlaceholder, }: {
10
+ element: HTMLSelectElement;
11
+ classNames: ClassNames;
12
+ template: (data: object) => HTMLOptionElement;
13
+ extractPlaceholder: boolean;
14
+ });
15
+ get placeholderOption(): HTMLOptionElement | null;
16
+ addOptions(choices: ChoiceFull[]): void;
17
+ optionsAsChoices(): (ChoiceFull | GroupFull)[];
18
+ _optionToChoice(option: HTMLOptionElement): ChoiceFull;
19
+ _optgroupToChoice(optgroup: HTMLOptGroupElement): GroupFull;
20
+ }
@@ -0,0 +1 @@
1
+ export declare const SCROLLING_SPEED: number;
@@ -0,0 +1,4 @@
1
+ import { ClassNames } from './interfaces/class-names';
2
+ import { Options } from './interfaces/options';
3
+ export declare const DEFAULT_CLASSNAMES: ClassNames;
4
+ export declare const DEFAULT_CONFIG: Options;
@@ -0,0 +1,13 @@
1
+ import { Types } from './types';
2
+ export declare const ActionType: {
3
+ readonly ADD_CHOICE: "ADD_CHOICE";
4
+ readonly REMOVE_CHOICE: "REMOVE_CHOICE";
5
+ readonly FILTER_CHOICES: "FILTER_CHOICES";
6
+ readonly ACTIVATE_CHOICES: "ACTIVATE_CHOICES";
7
+ readonly CLEAR_CHOICES: "CLEAR_CHOICES";
8
+ readonly ADD_GROUP: "ADD_GROUP";
9
+ readonly ADD_ITEM: "ADD_ITEM";
10
+ readonly REMOVE_ITEM: "REMOVE_ITEM";
11
+ readonly HIGHLIGHT_ITEM: "HIGHLIGHT_ITEM";
12
+ };
13
+ export type ActionTypes = Types.ValueOf<typeof ActionType>;
@@ -0,0 +1,11 @@
1
+ export declare const canUseDom: boolean;
2
+ export declare const searchFuse: string | undefined;
3
+ export declare const searchKMP: boolean;
4
+ /**
5
+ * These are not directly used, as an exported object (even as const) will prevent tree-shake away code paths
6
+ */
7
+ export declare const BuildFlags: {
8
+ readonly searchFuse: string | undefined;
9
+ readonly searchKMP: boolean;
10
+ readonly canUseDom: boolean;
11
+ };
@@ -0,0 +1,23 @@
1
+ import { StringUntrusted } from './string-untrusted';
2
+ import { Types } from './types';
3
+ import { GroupFull } from './group-full';
4
+ export interface ChoiceFull {
5
+ id: number;
6
+ highlighted: boolean;
7
+ element?: HTMLOptionElement | HTMLOptGroupElement;
8
+ itemEl?: HTMLElement;
9
+ choiceEl?: HTMLElement;
10
+ labelClass?: Array<string>;
11
+ labelDescription?: string;
12
+ customProperties?: Types.CustomProperties;
13
+ disabled: boolean;
14
+ active: boolean;
15
+ elementId?: string;
16
+ group: GroupFull | null;
17
+ label: StringUntrusted | string;
18
+ placeholder: boolean;
19
+ selected: boolean;
20
+ value: string;
21
+ score: number;
22
+ rank: number;
23
+ }
@@ -0,0 +1,61 @@
1
+ /** Classes added to HTML generated by By default classnames follow the BEM notation. */
2
+ export interface ClassNames {
3
+ /** @default ['choices'] */
4
+ containerOuter: string | Array<string>;
5
+ /** @default ['choices__inner'] */
6
+ containerInner: string | Array<string>;
7
+ /** @default ['choices__input'] */
8
+ input: string | Array<string>;
9
+ /** @default ['choices__input--cloned'] */
10
+ inputCloned: string | Array<string>;
11
+ /** @default ['choices__list'] */
12
+ list: string | Array<string>;
13
+ /** @default ['choices__list--multiple'] */
14
+ listItems: string | Array<string>;
15
+ /** @default ['choices__list--single'] */
16
+ listSingle: string | Array<string>;
17
+ /** @default ['choices__list--dropdown'] */
18
+ listDropdown: string | Array<string>;
19
+ /** @default ['choices__item'] */
20
+ item: string | Array<string>;
21
+ /** @default ['choices__item--selectable'] */
22
+ itemSelectable: string | Array<string>;
23
+ /** @default ['choices__item--disabled'] */
24
+ itemDisabled: string | Array<string>;
25
+ /** @default ['choices__item--choice'] */
26
+ itemChoice: string | Array<string>;
27
+ /** @default ['choices__description'] */
28
+ description: string | Array<string>;
29
+ /** @default ['choices__placeholder'] */
30
+ placeholder: string | Array<string>;
31
+ /** @default ['choices__group'] */
32
+ group: string | Array<string>;
33
+ /** @default ['choices__heading'] */
34
+ groupHeading: string | Array<string>;
35
+ /** @default ['choices__button'] */
36
+ button: string | Array<string>;
37
+ /** @default ['is-active'] */
38
+ activeState: string | Array<string>;
39
+ /** @default ['is-focused'] */
40
+ focusState: string | Array<string>;
41
+ /** @default ['is-open'] */
42
+ openState: string | Array<string>;
43
+ /** @default ['is-disabled'] */
44
+ disabledState: string | Array<string>;
45
+ /** @default ['is-highlighted'] */
46
+ highlightedState: string | Array<string>;
47
+ /** @default ['is-selected'] */
48
+ selectedState: string | Array<string>;
49
+ /** @default ['is-flipped'] */
50
+ flippedState: string | Array<string>;
51
+ /** @default ['is-loading'] */
52
+ loadingState: string | Array<string>;
53
+ /** @default ['choices__notice'] */
54
+ notice: string | Array<string>;
55
+ /** @default ['choices__item--selectable', 'add-choice'] */
56
+ addChoice: string | Array<string>;
57
+ /** @default ['has-no-results'] */
58
+ noResults: string | Array<string>;
59
+ /** @default ['has-no-choices'] */
60
+ noChoices: string | Array<string>;
61
+ }
@@ -0,0 +1,7 @@
1
+ import { InputChoice } from './input-choice';
2
+ export type EventChoiceValueType<B extends boolean> = B extends true ? string : EventChoice;
3
+ export interface EventChoice extends InputChoice {
4
+ element?: HTMLOptionElement | HTMLOptGroupElement;
5
+ groupValue?: string;
6
+ keyCode?: number;
7
+ }
@@ -0,0 +1,14 @@
1
+ import { Types } from './types';
2
+ export declare const EventType: {
3
+ readonly showDropdown: "showDropdown";
4
+ readonly hideDropdown: "hideDropdown";
5
+ readonly change: "change";
6
+ readonly choice: "choice";
7
+ readonly search: "search";
8
+ readonly addItem: "addItem";
9
+ readonly removeItem: "removeItem";
10
+ readonly highlightItem: "highlightItem";
11
+ readonly highlightChoice: "highlightChoice";
12
+ readonly unhighlightItem: "unhighlightItem";
13
+ };
14
+ export type EventTypes = Types.ValueOf<typeof EventType>;
@@ -0,0 +1,10 @@
1
+ import { ChoiceFull } from './choice-full';
2
+ export interface GroupFull {
3
+ id: number;
4
+ active: boolean;
5
+ disabled: boolean;
6
+ label?: string;
7
+ element?: HTMLOptGroupElement;
8
+ groupEl?: HTMLElement;
9
+ choices: ChoiceFull[];
10
+ }
@@ -0,0 +1,14 @@
1
+ export * from './action-type';
2
+ export * from './input-choice';
3
+ export * from './input-group';
4
+ export * from './event-choice';
5
+ export * from './class-names';
6
+ export * from './event-type';
7
+ export * from './item';
8
+ export * from './keycode-map';
9
+ export * from './options';
10
+ export * from './passed-element';
11
+ export * from './passed-element-type';
12
+ export * from './position-options-type';
13
+ export * from './state';
14
+ export * from './types';
@@ -0,0 +1,15 @@
1
+ import { StringUntrusted } from './string-untrusted';
2
+ import { Types } from './types';
3
+ export interface InputChoice {
4
+ id?: number;
5
+ highlighted?: boolean;
6
+ labelClass?: string | Array<string>;
7
+ labelDescription?: string;
8
+ customProperties?: Types.CustomProperties;
9
+ disabled?: boolean;
10
+ active?: boolean;
11
+ label: StringUntrusted | string;
12
+ placeholder?: boolean;
13
+ selected?: boolean;
14
+ value: any;
15
+ }
@@ -0,0 +1,10 @@
1
+ import { InputChoice } from './input-choice';
2
+ import { StringUntrusted } from './string-untrusted';
3
+ export interface InputGroup {
4
+ id?: number;
5
+ active?: boolean;
6
+ disabled?: boolean;
7
+ label?: StringUntrusted | string;
8
+ value: string;
9
+ choices: InputChoice[];
10
+ }
@@ -0,0 +1,17 @@
1
+ import { InputChoice } from './input-choice';
2
+ import { InputGroup } from './input-group';
3
+ /**
4
+ * @deprecated Use InputChoice instead
5
+ */
6
+ export interface Item extends InputChoice {
7
+ }
8
+ /**
9
+ * @deprecated Use InputChoice instead
10
+ */
11
+ export interface Choice extends InputChoice {
12
+ }
13
+ /**
14
+ * @deprecated Use InputGroup instead
15
+ */
16
+ export interface Group extends InputGroup {
17
+ }
@@ -0,0 +1,13 @@
1
+ export declare const KeyCodeMap: {
2
+ readonly TAB_KEY: 9;
3
+ readonly SHIFT_KEY: 16;
4
+ readonly BACK_KEY: 46;
5
+ readonly DELETE_KEY: 8;
6
+ readonly ENTER_KEY: 13;
7
+ readonly A_KEY: 65;
8
+ readonly ESC_KEY: 27;
9
+ readonly UP_KEY: 38;
10
+ readonly DOWN_KEY: 40;
11
+ readonly PAGE_UP_KEY: 33;
12
+ readonly PAGE_DOWN_KEY: 34;
13
+ };