playbook_ui 14.8.0.pre.alpha.play1648heightglobalprops4606 → 14.8.0.pre.alpha.revert3916revert3893PBNTR667railstypeaheadformintegration4565

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/_playbook.scss +0 -1
  3. data/app/pb_kits/playbook/pb_checkbox/checkbox.html.erb +2 -2
  4. data/app/pb_kits/playbook/pb_checkbox/checkbox.rb +4 -0
  5. data/app/pb_kits/playbook/pb_checkbox/docs/_checkbox_indeterminate.html.erb +7 -84
  6. data/app/pb_kits/playbook/pb_dropdown/_dropdown.scss +0 -1
  7. data/app/pb_kits/playbook/pb_dropdown/dropdown_container.html.erb +1 -0
  8. data/app/pb_kits/playbook/pb_dropdown/dropdown_container.rb +4 -0
  9. data/app/pb_kits/playbook/pb_form/docs/_form_form_with.html.erb +2 -2
  10. data/app/pb_kits/playbook/pb_form/docs/_form_form_with_loading.html.erb +1 -1
  11. data/app/pb_kits/playbook/pb_form/docs/_form_form_with_validate.html.erb +63 -12
  12. data/app/pb_kits/playbook/pb_selectable_card/docs/_selectable_card_default.html.erb +1 -2
  13. data/app/pb_kits/playbook/pb_typeahead/_typeahead.scss +0 -3
  14. data/app/pb_kits/playbook/pb_typeahead/index.ts +291 -2
  15. data/app/pb_kits/playbook/pb_typeahead/typeahead.html.erb +5 -2
  16. data/app/pb_kits/playbook/pb_typeahead/typeahead.rb +4 -0
  17. data/app/pb_kits/playbook/utilities/_max_width.scss +0 -4
  18. data/app/pb_kits/playbook/utilities/_min_width.scss +1 -1
  19. data/app/pb_kits/playbook/utilities/globalPropNames.mjs +1 -0
  20. data/app/pb_kits/playbook/utilities/globalProps.ts +0 -24
  21. data/dist/chunks/{_typeahead-dal1XERd.js → _typeahead-IoHUnHeF.js} +2 -2
  22. data/dist/chunks/{_weekday_stacked-KjwZgsC3.js → _weekday_stacked-BuaqHM9z.js} +1 -1
  23. data/dist/chunks/{lib-BC6ESsxG.js → lib-SyD3buPZ.js} +1 -1
  24. data/dist/chunks/{pb_form_validation-B_Z9rEbg.js → pb_form_validation-Dt8UJgrJ.js} +1 -1
  25. data/dist/chunks/vendor.js +1 -1
  26. data/dist/playbook-doc.js +1 -1
  27. data/dist/playbook-rails-react-bindings.js +1 -1
  28. data/dist/playbook-rails.js +1 -1
  29. data/dist/playbook.css +1 -1
  30. data/lib/playbook/classnames.rb +0 -3
  31. data/lib/playbook/forms/builder/typeahead_field.rb +13 -0
  32. data/lib/playbook/kit_base.rb +1 -16
  33. data/lib/playbook/version.rb +1 -1
  34. metadata +6 -12
  35. data/app/pb_kits/playbook/tokens/_height.scss +0 -19
  36. data/app/pb_kits/playbook/tokens/exports/_height.module.scss +0 -37
  37. data/app/pb_kits/playbook/utilities/_height.scss +0 -33
  38. data/lib/playbook/height.rb +0 -29
  39. data/lib/playbook/max_height.rb +0 -29
  40. data/lib/playbook/min_height.rb +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c400478957c7ac7d0b7f5d9dd4313416455cd60e7e405758d7929235a2458f5e
4
- data.tar.gz: 820c87cf0e999947f6e1c4eabc30a719c51b2fbf71f5429f01fdc3287948df3d
3
+ metadata.gz: fbcc7537aa0ece4caf4a922f2b49f40be79668e3cb793727a882184285669f05
4
+ data.tar.gz: 15d4b8d7216b62376bddd4da158f9bbb74b4eb9abbb88b88f7e425af6d0ad8df
5
5
  SHA512:
6
- metadata.gz: bd355b592a328ec6485ec24347f37926631f5fee5e31f8e2d87413cd1be9c5764dacc6e0532688cc720073bcb7fcb430afc45f34da0a0bb60a0ca742fe16a7b5
7
- data.tar.gz: e47e0ce844150818eb47998e80628fd8b6a16e1db4c2c5effe065e5c96a075051204046b566cefa96fd9e4a81cccd2b43ba9237b9380f9746082a762614ea4ec
6
+ metadata.gz: 03e07711563ef5c12a4785ad6f01d1168d9360f9a4881ea8c86bd1a878991c611c9cf4e2a27b14c8355469e18c6516fe2fe0fa6426ed8960ee7e7600631648e5
7
+ data.tar.gz: ab58d3db94e12e61aac2e00804a200681452b909cbfb4ac17d57a62a56f6003ea23909551e7ebf5739f6840ded08bcb6f08180a8395536aad982eb2683cd0988
@@ -126,4 +126,3 @@
126
126
  @import 'utilities/overflow';
127
127
  @import 'utilities/truncate';
128
128
  @import 'utilities/vertical_align';
129
- @import 'utilities/height';
@@ -6,12 +6,12 @@
6
6
  ) do %>
7
7
  <%= content.presence || object.input %>
8
8
  <% if object.indeterminate %>
9
- <span data-pb-checkbox-icon-span="true" class="pb_checkbox_indeterminate">
9
+ <span class="pb_checkbox_indeterminate">
10
10
  <%= pb_rails("icon", props: { icon: "minus", classname: "indeterminate_icon", fixed_width: true}) %>
11
11
  <%= pb_rails("icon", props: { icon: "check", classname: "check_icon hidden", fixed_width: true}) %>
12
12
  </span>
13
13
  <% else %>
14
- <span data-pb-checkbox-icon-span="true" class="pb_checkbox_checkmark">
14
+ <span class="pb_checkbox_checkmark">
15
15
  <%= pb_rails("icon", props: { icon: "check", classname: "check_icon", fixed_width: true}) %>
16
16
  <%= pb_rails("icon", props: { icon: "minus", classname: "indeterminate_icon hidden", fixed_width: true}) %>
17
17
  </span>
@@ -18,6 +18,10 @@ module Playbook
18
18
  prop :form_spacing, type: Playbook::Props::Boolean,
19
19
  default: false
20
20
 
21
+ def checked_html
22
+ checked ? "checked='true'" : nil
23
+ end
24
+
21
25
  def classname
22
26
  generate_classname("pb_checkbox_kit", checked_class) + indeterminate_class + error_class
23
27
  end
@@ -1,84 +1,7 @@
1
- <% checkboxes = [
2
- { name: 'Coffee', id: 'coffee', checked: false },
3
- { name: 'Ice Cream', id: 'ice-cream', checked: false },
4
- { name: 'Chocolate', id: 'chocolate', checked: true }
5
- ] %>
6
-
7
- <%= pb_rails("table", props: { container: false, size: "md" }) do %>
8
- <thead>
9
- <tr>
10
- <th>
11
- <%= pb_rails("checkbox", props: {
12
- checked: true,
13
- text: "Uncheck All",
14
- value: "checkbox-value",
15
- name: "main-checkbox",
16
- indeterminate: true,
17
- id: "indeterminate-checkbox"
18
- }) %>
19
- </th>
20
- </tr>
21
- </thead>
22
-
23
- <tbody>
24
- <% checkboxes.each do |checkbox| %>
25
- <tr>
26
- <td>
27
- <%= pb_rails("checkbox", props: {
28
- checked: checkbox[:checked],
29
- text: checkbox[:name],
30
- value: checkbox[:id],
31
- name: "#{checkbox[:id]}-indeterminate-checkbox",
32
- id: "#{checkbox[:id]}-indeterminate-checkbox",
33
- }) %>
34
- </td>
35
- </tr>
36
- <% end %>
37
- </tbody>
38
- <% end %>
39
-
40
- <script>
41
- document.addEventListener('DOMContentLoaded', function() {
42
- const mainCheckboxWrapper = document.getElementById('indeterminate-checkbox');
43
- const mainCheckbox = document.getElementsByName("main-checkbox")[0];
44
- const childCheckboxes = document.querySelectorAll('input[type="checkbox"][id$="indeterminate-checkbox"]');
45
-
46
- const updateMainCheckbox = () => {
47
- // Count the number of checked child checkboxes
48
- const checkedCount = Array.from(childCheckboxes).filter(cb => cb.checked).length;
49
- // Determine if the main checkbox should be in an indeterminate state
50
- const indeterminate = checkedCount > 0 && checkedCount < childCheckboxes.length;
51
-
52
- // Set the main checkbox states
53
- mainCheckbox.indeterminate = indeterminate;
54
- mainCheckbox.checked = checkedCount > 0;
55
-
56
- // Determine the main checkbox label based on the number of checked checkboxes
57
- const text = checkedCount === 0 ? 'Check All' : 'Uncheck All';
58
-
59
- // Determine the icon class to add and remove based on the number of checked checkboxes
60
- const iconClassToAdd = checkedCount === 0 ? 'pb_checkbox_checkmark' : 'pb_checkbox_indeterminate';
61
- const iconClassToRemove = checkedCount === 0 ? 'pb_checkbox_indeterminate' : 'pb_checkbox_checkmark';
62
-
63
- // Update main checkbox label
64
- mainCheckboxWrapper.getElementsByClassName('pb_body_kit')[0].textContent = text;
65
-
66
- // Add and remove the icon class to the main checkbox wrapper
67
- mainCheckboxWrapper.querySelector('[data-pb-checkbox-icon-span]').classList.add(iconClassToAdd);
68
- mainCheckboxWrapper.querySelector('[data-pb-checkbox-icon-span]').classList.remove(iconClassToRemove);
69
-
70
- // Toggle the visibility of the checkbox icon based on the indeterminate state
71
- mainCheckboxWrapper.getElementsByClassName("indeterminate_icon")[0].classList.toggle('hidden', !indeterminate);
72
- mainCheckboxWrapper.getElementsByClassName("check_icon")[0].classList.toggle('hidden', indeterminate);
73
- };
74
-
75
- mainCheckbox.addEventListener('change', function() {
76
- childCheckboxes.forEach(cb => cb.checked = this.checked);
77
- updateMainCheckbox();
78
- });
79
-
80
- childCheckboxes.forEach(cb => {
81
- cb.addEventListener('change', updateMainCheckbox);
82
- });
83
- });
84
- </script>
1
+ <%= pb_rails("checkbox" , props: {
2
+ text: "Select ",
3
+ value: "checkbox-value",
4
+ name: "main",
5
+ indeterminate: true,
6
+ id: "test-indeterminate-js"
7
+ }) %>
@@ -53,7 +53,6 @@
53
53
  }
54
54
 
55
55
  .pb_dropdown_container {
56
- position: absolute;
57
56
  background-color: $white;
58
57
  overflow: hidden;
59
58
  box-shadow: $shadow_deep;
@@ -3,6 +3,7 @@
3
3
  class: object.classname,
4
4
  data: object.data,
5
5
  id: object.id,
6
+ style: object.container_style,
6
7
  **combined_html_options) do %>
7
8
  <%= pb_rails("list", props: {ordered: false, borderless: false}) do %>
8
9
  <% if content.present? %>
@@ -7,6 +7,10 @@ module Playbook
7
7
  generate_classname("pb_dropdown_container", "close", separator: " ")
8
8
  end
9
9
 
10
+ def container_style
11
+ "position: absolute"
12
+ end
13
+
10
14
  def data
11
15
  Hash(prop(:data)).merge(dropdown_container: true)
12
16
  end
@@ -23,7 +23,7 @@
23
23
  %>
24
24
 
25
25
  <%= pb_form_with(scope: :example, url: "", method: :get) do |form| %>
26
- <%= form.typeahead :example_user, props: { data: { typeahead_example1: true, user: {} }, placeholder: "Search for a user" } %>
26
+ <%= form.typeahead :example_typeahead, props: { data: { typeahead_example1: true, user: {} }, label: true, placeholder: "Search for a user" } %>
27
27
  <%= form.text_field :example_text_field, props: { label: true } %>
28
28
  <%= form.phone_number_field :example_phone_number_field, props: { label: "Example phone field" } %>
29
29
  <%= form.email_field :example_email_field, props: { label: true } %>
@@ -92,7 +92,7 @@
92
92
  const selectedUserData = JSON.parse(selectedUserJSON)
93
93
 
94
94
  // set the input field's value
95
- event.target.querySelector('input[name=example_user]').value = selectedUserData.login
95
+ event.target.querySelector('input[name=example_typeahead]').value = selectedUserData.login
96
96
 
97
97
  // log the selected option's dataset
98
98
  console.log('The selected user data:')
@@ -1,5 +1,5 @@
1
1
  <%= pb_form_with(scope: :example, url: "", method: :get, loading: true) do |form| %>
2
- <%= form.text_field :example_text_field, props: { label: true } %>
2
+ <%= form.text_field :example_text_field_loading, props: { label: true } %>
3
3
 
4
4
  <%= form.actions do |action| %>
5
5
  <%= action.submit %>
@@ -22,23 +22,74 @@
22
22
  %>
23
23
 
24
24
  <%= pb_form_with(scope: :example, method: :get, url: "", validate: true) do |form| %>
25
- <%= form.text_field :example_text_field, props: { label: true, required: true } %>
26
- <%= form.phone_number_field :example_phone_number_field, props: { label: "Example phone field" } %>
27
- <%= form.email_field :example_email_field, props: { label: true, required: true } %>
28
- <%= form.number_field :example_number_field, props: { label: true, required: true } %>
29
- <%= form.search_field :example_project_number, props: { label: true, required: true, validation: { pattern: "[0-9]{2}-[0-9]{5}", message: "Please enter a valid project number (example: 33-12345)." } } %>
30
- <%= form.password_field :example_password_field, props: { label: true, required: true } %>
31
- <%= form.url_field :example_url_field, props: { label: true, required: true } %>
32
- <%= form.text_area :example_text_area, props: { label: true, required: true } %>
33
- <%= form.dropdown_field :example_dropdown, props: { label: true, options: example_dropdown_options, required: true } %>
34
- <%= form.select :example_select, [ ["Yes", 1], ["No", 2] ], props: { label: true, blank_selection: "Select One...", required: true } %>
35
- <%= form.collection_select :example_collection_select, example_collection, :value, :name, props: { label: true, blank_selection: "Select One...", required: true } %>
25
+ <%= form.typeahead :example_typeahead_validation, props: { data: { typeahead_example2: true, user: {} }, label: true, placeholder: "Search for a user", required: true, validation: { message: "Please select a user." } } %>
26
+ <%= form.text_field :example_text_field_validation, props: { label: true, required: true } %>
27
+ <%= form.phone_number_field :example_phone_number_field_validation, props: { label: "Example phone field" } %>
28
+ <%= form.email_field :example_email_field_validation, props: { label: true, required: true } %>
29
+ <%= form.number_field :example_number_field_validation, props: { label: true, required: true } %>
30
+ <%= form.search_field :example_project_number_validation, props: { label: true, required: true, validation: { pattern: "[0-9]{2}-[0-9]{5}", message: "Please enter a valid project number (example: 33-12345)." } } %>
31
+ <%= form.password_field :example_password_field_validation, props: { label: true, required: true } %>
32
+ <%= form.url_field :example_url_field_validation, props: { label: true, required: true } %>
33
+ <%= form.text_area :example_text_area_validation, props: { label: true, required: true } %>
34
+ <%= form.dropdown_field :example_dropdown_validation, props: { label: true, options: example_dropdown_options, required: true } %>
35
+ <%= form.select :example_select_validation, [ ["Yes", 1], ["No", 2] ], props: { label: true, blank_selection: "Select One...", required: true } %>
36
+ <%= form.collection_select :example_collection_select_validation, example_collection, :value, :name, props: { label: true, blank_selection: "Select One...", required: true } %>
36
37
  <%= form.check_box :example_checkbox, props: { text: "Example Checkbox", label: true, required: true } %>
37
38
  <%= form.date_picker :example_date_picker_2, props: { label: true, required: true } %>
38
- <%= form.star_rating_field :example_star_rating, props: { variant: "interactive", label: true, required: true } %>
39
+ <%= form.star_rating_field :example_star_rating_validation, props: { variant: "interactive", label: true, required: true } %>
39
40
 
40
41
  <%= form.actions do |action| %>
41
42
  <%= action.submit %>
42
43
  <%= action.button props: { type: "reset", text: "Cancel", variant: "secondary" } %>
43
44
  <% end %>
44
45
  <% end %>
46
+
47
+ <!-- form.typeahead user results example template -->
48
+ <template data-typeahead-example-result-option>
49
+ <%= pb_rails("user", props: {
50
+ name: tag(:slot, name: "name"),
51
+ orientation: "horizontal",
52
+ align: "left",
53
+ avatar_url: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGP6zwAAAgcBApocMXEAAAAASUVORK5CYII=",
54
+ avatar: true
55
+ }) %>
56
+ </template>
57
+
58
+ <!-- form.typeahead JS example implementation -->
59
+ <%= javascript_tag defer: "defer" do %>
60
+ document.addEventListener("pb-typeahead-kit-search", function(event) {
61
+ if (!event.target.dataset || !event.target.dataset.typeaheadExample2) return
62
+
63
+ fetch(`https://api.github.com/search/users?q=${encodeURIComponent(event.detail.searchingFor)}`)
64
+ .then(response => response.json())
65
+ .then((result) => {
66
+ const resultOptionTemplate = document.querySelector("[data-typeahead-example-result-option]")
67
+
68
+ event.detail.setResults((result.items || []).map((user) => {
69
+ const wrapper = resultOptionTemplate.content.cloneNode(true)
70
+ wrapper.children[0].dataset.user = JSON.stringify(user)
71
+ wrapper.querySelector('slot[name="name"]').replaceWith(user.login)
72
+ wrapper.querySelector('img').dataset.src = user.avatar_url
73
+ return wrapper
74
+ }))
75
+ })
76
+ })
77
+
78
+
79
+ document.addEventListener("pb-typeahead-kit-result-option-selected", function(event) {
80
+ if (!event.target.dataset.typeaheadExample2) return
81
+
82
+ const selectedUserJSON = event.detail.selected.firstElementChild.dataset.user
83
+ const selectedUserData = JSON.parse(selectedUserJSON)
84
+
85
+ // set the input field's value
86
+ event.target.querySelector('input[name=example_typeahead_validation]').value = selectedUserData.login
87
+
88
+ // log the selected option's dataset
89
+ console.log('The selected user data:')
90
+ console.dir(selectedUserData)
91
+
92
+ // do even more with the data later - TBD
93
+ event.target.dataset.user = selectedUserJSON
94
+ })
95
+ <% end %>
@@ -6,7 +6,6 @@
6
6
  value: "selected_with_icon",
7
7
  checked: true,
8
8
  icon: true,
9
-
10
9
  }) do %>
11
10
  Selected, with icon
12
11
  <% end %>
@@ -37,4 +36,4 @@
37
36
  Disabled
38
37
  <% end %>
39
38
 
40
- </div>
39
+ </div>
@@ -2,7 +2,6 @@
2
2
  @import "../tokens/border_radius";
3
3
  @import "../tokens/spacing";
4
4
  @import "../tokens/shadows";
5
- @import "../tokens/positioning";
6
5
 
7
6
  [class^=pb_typeahead_kit] {
8
7
  .typeahead-kit-select__option {
@@ -100,7 +99,6 @@
100
99
  .typeahead-kit-select__menu {
101
100
  background-color: $bg_dark;
102
101
  color: $white;
103
- z-index: $z_1;
104
102
  }
105
103
  .typeahead-kit-select__option:hover {
106
104
  background-color: $active_dark;
@@ -184,7 +182,6 @@
184
182
  }
185
183
 
186
184
  .typeahead-kit-select__menu {
187
- z-index: $z_1;
188
185
  .typeahead-kit-select__menu-list {
189
186
  padding: 0;
190
187
  }
@@ -4,11 +4,12 @@ import { debounce } from 'lodash'
4
4
  export default class PbTypeahead extends PbEnhancedElement {
5
5
  _searchInput: HTMLInputElement
6
6
  _resultsElement: HTMLElement
7
- _debouncedSearch: Function
7
+ _debouncedSearch: () => void // changed - diff
8
8
  _resultsLoadingIndicator: HTMLElement
9
9
  _resultOptionTemplate: HTMLElement
10
10
  _resultsOptionCache: Map<string, Array<DocumentFragment>>
11
11
  _searchContext: string
12
+ _validSelection: boolean // changed - new
12
13
 
13
14
  static get selector() {
14
15
  return '[data-pb-typeahead-kit]'
@@ -19,6 +20,7 @@ export default class PbTypeahead extends PbEnhancedElement {
19
20
  this.searchInput.addEventListener('focus', () => this.debouncedSearch())
20
21
  this.searchInput.addEventListener('input', () => this.debouncedSearch())
21
22
  this.resultsElement.addEventListener('click', (event: MouseEvent) => this.optionSelected(event))
23
+ // this.element.closest('form')?.addEventListener('submit', (event) => this.handleFormSubmission(event)) // changed - new
22
24
  }
23
25
 
24
26
  handleKeydown(event: KeyboardEvent) {
@@ -86,12 +88,44 @@ export default class PbTypeahead extends PbEnhancedElement {
86
88
  const resultOption = (event.target as Element).closest('[data-result-option-item]')
87
89
  if (!resultOption) return
88
90
 
91
+ this._validSelection = true // changed - new
92
+ this.removeValidationError() // changed - new
93
+
89
94
  this.resultsCacheClear()
90
95
  this.searchInputClear()
91
96
  this.clearResults()
92
97
 
93
98
  this.element.dispatchEvent(new CustomEvent('pb-typeahead-kit-result-option-selected', { bubbles: true, detail: { selected: resultOption, typeahead: this } }))
94
99
  }
100
+ // changed - new
101
+ removeValidationError() {
102
+ const inputWrapper = this.searchInput.closest('.text_input_wrapper')
103
+ if (inputWrapper) {
104
+ const errorMessage = inputWrapper.querySelector('.pb_body_kit_negative') as HTMLElement
105
+ if (errorMessage) {
106
+ errorMessage.style.display = 'none'
107
+ }
108
+ this.searchInput.classList.remove('error')
109
+ }
110
+ }
111
+ // changed - new
112
+ showValidationError() {
113
+ const inputWrapper = this.searchInput.closest('.text_input_wrapper')
114
+ if (inputWrapper) {
115
+ const errorMessage = inputWrapper.querySelector('.pb_body_kit_negative') as HTMLElement
116
+ if (errorMessage) {
117
+ errorMessage.style.display = 'block'
118
+ }
119
+ this.searchInput.classList.add('error')
120
+ }
121
+ }
122
+ // changed - new
123
+ // handleFormSubmission(event: Event) {
124
+ // if (!this._validSelection) {
125
+ // this.showValidationError()
126
+ // event.preventDefault()
127
+ // }
128
+ // }
95
129
 
96
130
  clearResults() {
97
131
  this.resultsElement.innerHTML = ''
@@ -201,8 +235,263 @@ export default class PbTypeahead extends PbEnhancedElement {
201
235
  }
202
236
 
203
237
  toggleResultsLoadingIndicator(visible: boolean) {
204
- var visibilityProperty = '0'
238
+ let visibilityProperty = '0' // changed - diff
205
239
  if (visible) visibilityProperty = '1'
206
240
  this.resultsLoadingIndicator.style.opacity = visibilityProperty
207
241
  }
208
242
  }
243
+
244
+ // import PbEnhancedElement from '../pb_enhanced_element';
245
+ // import { debounce } from 'lodash';
246
+
247
+ // export default class PbTypeahead extends PbEnhancedElement {
248
+ // _searchInput: HTMLInputElement;
249
+ // _resultsElement: HTMLElement;
250
+ // _debouncedSearch: () => void;
251
+ // _resultsLoadingIndicator: HTMLElement;
252
+ // _resultOptionTemplate: HTMLElement;
253
+ // _resultsOptionCache: Map<string, Array<DocumentFragment>>;
254
+ // _searchContext: string;
255
+ // _validSelection: boolean;
256
+
257
+ // static get selector() {
258
+ // return '[data-pb-typeahead-kit]';
259
+ // }
260
+
261
+ // connect() {
262
+ // this.element.addEventListener('keydown', (event: KeyboardEvent) => this.handleKeydown(event));
263
+ // this.searchInput.addEventListener('focus', () => this.debouncedSearch());
264
+ // this.searchInput.addEventListener('input', () => this.debouncedSearch());
265
+ // this.resultsElement.addEventListener('click', (event: MouseEvent) => this.optionSelected(event));
266
+ // // this.attachFormSubmissionHandler();
267
+ // }
268
+
269
+ // // attachFormSubmissionHandler() {
270
+ // // const formElement = this.element.closest('form');
271
+ // // if (formElement) {
272
+ // // formElement.addEventListener('submit', (event: Event) => {
273
+ // // if (!this._validSelection) {
274
+ // // this.showValidationError();
275
+ // // event.preventDefault();
276
+ // // }
277
+ // // });
278
+ // // }
279
+ // // }
280
+
281
+ // handleKeydown(event: KeyboardEvent) {
282
+ // if (event.key === 'ArrowUp') {
283
+ // event.preventDefault();
284
+ // this.focusPreviousOption();
285
+ // } else if (event.key === 'ArrowDown') {
286
+ // event.preventDefault();
287
+ // this.focusNextOption();
288
+ // }
289
+ // }
290
+
291
+ // search() {
292
+ // if (this.searchTerm.length < parseInt(this.searchTermMinimumLength)) {
293
+ // return this.clearResults();
294
+ // }
295
+
296
+ // this.toggleResultsLoadingIndicator(true);
297
+ // this.showResults();
298
+
299
+ // const searchTerm = this.searchTerm;
300
+ // const searchContext = this.searchContext;
301
+ // const search = {
302
+ // searchingFor: searchTerm,
303
+ // searchingContext: searchContext,
304
+ // setResults: (results: Array<DocumentFragment>) => {
305
+ // this.resultsCacheUpdate(searchTerm, searchContext, results);
306
+ // },
307
+ // };
308
+ // this.element.dispatchEvent(new CustomEvent('pb-typeahead-kit-search', { bubbles: true, detail: search }));
309
+ // }
310
+
311
+ // resultsCacheUpdate(searchTerm: string, searchContext: string, results: Array<DocumentFragment>) {
312
+ // const searchTermAndContext = this.cacheKeyFor(searchTerm, searchContext);
313
+ // if (this.resultsOptionCache.has(searchTermAndContext)) {
314
+ // this.resultsOptionCache.delete(searchTermAndContext);
315
+ // }
316
+ // if (this.resultsOptionCache.size > 32) {
317
+ // this.resultsOptionCache.delete(this.resultsOptionCache.keys().next().value);
318
+ // }
319
+
320
+ // this.resultsOptionCache.set(searchTermAndContext, results);
321
+ // this.showResults();
322
+ // }
323
+
324
+ // resultsCacheClear() {
325
+ // this.resultsOptionCache.clear();
326
+ // }
327
+
328
+ // get debouncedSearch() {
329
+ // return this._debouncedSearch = (
330
+ // this._debouncedSearch ||
331
+ // debounce(this.search, parseInt(this.searchDebounceTimeout)).bind(this)
332
+ // );
333
+ // }
334
+
335
+ // showResults() {
336
+ // if (!this.resultsOptionCache.has(this.searchTermAndContext)) return;
337
+
338
+ // this.toggleResultsLoadingIndicator(false);
339
+ // this.clearResults();
340
+ // for (const result of this.resultsOptionCache.get(this.searchTermAndContext)) {
341
+ // this.resultsElement.appendChild(this.newResultOption(result.cloneNode(true)));
342
+ // }
343
+ // for (const result of this.resultsElement.querySelectorAll('[data-result-option-item]')) {
344
+ // result.addEventListener('mousedown', (event: MouseEvent) => this.optionSelected(event));
345
+ // }
346
+ // }
347
+
348
+ // optionSelected(event: MouseEvent) {
349
+ // const resultOption = (event.target as Element).closest('[data-result-option-item]');
350
+ // if (!resultOption) return;
351
+
352
+ // this._validSelection = true;
353
+ // this.removeValidationError();
354
+
355
+ // this.resultsCacheClear();
356
+ // this.searchInputClear();
357
+ // this.clearResults();
358
+
359
+ // this.element.dispatchEvent(new CustomEvent('pb-typeahead-kit-result-option-selected', {
360
+ // bubbles: true,
361
+ // detail: { selected: resultOption, typeahead: this },
362
+ // }));
363
+ // }
364
+
365
+ // removeValidationError() {
366
+ // const inputWrapper = this.searchInput.closest('.text_input_wrapper');
367
+ // if (inputWrapper) {
368
+ // const errorMessage = inputWrapper.querySelector('.pb_body_kit_negative') as HTMLElement;
369
+ // if (errorMessage) {
370
+ // errorMessage.style.display = 'none';
371
+ // }
372
+ // this.searchInput.classList.remove('error');
373
+ // }
374
+ // }
375
+
376
+ // showValidationError() {
377
+ // const inputWrapper = this.searchInput.closest('.text_input_wrapper');
378
+ // if (inputWrapper) {
379
+ // const errorMessage = inputWrapper.querySelector('.pb_body_kit_negative') as HTMLElement;
380
+ // if (errorMessage) {
381
+ // errorMessage.style.display = 'block';
382
+ // }
383
+ // this.searchInput.classList.add('error');
384
+ // }
385
+ // }
386
+
387
+ // clearResults() {
388
+ // this.resultsElement.innerHTML = '';
389
+ // }
390
+
391
+ // newResultOption(content: DocumentFragment) {
392
+ // const resultOption = (this.resultOptionTemplate as HTMLTemplateElement).content.cloneNode(true) as Element;
393
+ // resultOption.querySelector('slot[name="content"]').replaceWith(content);
394
+ // return resultOption;
395
+ // }
396
+
397
+ // focusPreviousOption() {
398
+ // const currentIndex = this.resultOptionItems.indexOf(this.currentSelectedResultOptionItem);
399
+ // const previousIndex = currentIndex - 1;
400
+ // const previousOptionItem = (
401
+ // this.resultOptionItems[previousIndex] ||
402
+ // this.resultOptionItems[this.resultOptionItems.length - 1]
403
+ // );
404
+ // (previousOptionItem as HTMLElement).focus();
405
+ // }
406
+
407
+ // focusNextOption() {
408
+ // const currentIndex = this.resultOptionItems.indexOf(this.currentSelectedResultOptionItem);
409
+ // const nextIndex = currentIndex + 1;
410
+ // const nextOptionItem = (
411
+ // this.resultOptionItems[nextIndex] ||
412
+ // this.resultOptionItems[0]
413
+ // );
414
+ // (nextOptionItem as HTMLElement).focus();
415
+ // }
416
+
417
+ // get resultOptionItems() {
418
+ // return Array.from(this.resultsElement.querySelectorAll('[data-result-option-item]'));
419
+ // }
420
+
421
+ // get currentSelectedResultOptionItem() {
422
+ // return document.activeElement.closest('[data-result-option-item]');
423
+ // }
424
+
425
+ // get searchInput() {
426
+ // return this._searchInput = (this._searchInput || this.element.querySelector('input[type="search"]'));
427
+ // }
428
+
429
+ // get searchTerm() {
430
+ // return this.searchInput.value;
431
+ // }
432
+
433
+ // get searchContext() {
434
+ // if (this._searchContext) return this._searchContext;
435
+
436
+ // const selector = (this.element as HTMLElement).dataset.searchContextValueSelector;
437
+ // if (selector) return ((
438
+ // this.element.parentNode.querySelector(selector) ||
439
+ // this.element.closest(selector)
440
+ // ) as HTMLInputElement).value;
441
+
442
+ // return null;
443
+ // }
444
+
445
+ // set searchContext(value) {
446
+ // this._searchContext = value;
447
+ // }
448
+
449
+ // get searchTermAndContext() {
450
+ // return this.cacheKeyFor(this.searchTerm, this.searchContext);
451
+ // }
452
+
453
+ // cacheKeyFor(searchTerm: string, searchContext: string) {
454
+ // return [searchTerm, JSON.stringify(searchContext)].join();
455
+ // }
456
+
457
+ // searchInputClear() {
458
+ // this.searchInput.value = '';
459
+ // }
460
+
461
+ // get searchTermMinimumLength() {
462
+ // return (this.element as HTMLElement).dataset.pbTypeaheadKitSearchTermMinimumLength;
463
+ // }
464
+
465
+ // get searchDebounceTimeout() {
466
+ // return (this.element as HTMLElement).dataset.pbTypeaheadKitSearchDebounceTimeout;
467
+ // }
468
+
469
+ // get resultsElement() {
470
+ // return this._resultsElement = (this._resultsElement || this.element.querySelector('[data-pb-typeahead-kit-results]'));
471
+ // }
472
+
473
+ // get resultOptionTemplate() {
474
+ // return this._resultOptionTemplate = (
475
+ // this._resultOptionTemplate ||
476
+ // this.element.querySelector('template[data-pb-typeahead-kit-result-option]')
477
+ // );
478
+ // }
479
+
480
+ // get resultsOptionCache() {
481
+ // return this._resultsOptionCache = (
482
+ // this._resultsOptionCache ||
483
+ // new Map
484
+ // );
485
+ // }
486
+
487
+ // get resultsLoadingIndicator() {
488
+ // return this._resultsLoadingIndicator = (
489
+ // this._resultsLoadingIndicator ||
490
+ // this.element.querySelector('[data-pb-typeahead-kit-loading-indicator]')
491
+ // );
492
+ // }
493
+
494
+ // toggleResultsLoadingIndicator(visible: boolean) {
495
+ // this.resultsLoadingIndicator.style.opacity = visible ? '1' : '0';
496
+ // }
497
+ // }