@teipublisher/pb-components 2.26.1-next.3 → 3.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 (154) hide show
  1. package/.github/workflows/main.yml +3 -3
  2. package/.github/workflows/node.js.yml +3 -3
  3. package/.github/workflows/release.js.yml +4 -4
  4. package/.releaserc.json +2 -2
  5. package/CHANGELOG.md +262 -11
  6. package/Dockerfile +78 -70
  7. package/css/components.css +5 -5
  8. package/css/leaflet/images/layers.png +0 -0
  9. package/dist/demo/components.css +46 -1
  10. package/dist/demo/pb-browse-docs2.html +1 -1
  11. package/dist/demo/pb-dialog.html +3 -5
  12. package/dist/demo/pb-drawer2.html +1 -1
  13. package/dist/demo/pb-facsimile.html +2 -2
  14. package/dist/demo/pb-grid.html +19 -6
  15. package/dist/demo/pb-leaflet-map.html +1 -1
  16. package/dist/demo/pb-login.html +0 -2
  17. package/dist/demo/pb-message.html +1 -2
  18. package/dist/demo/pb-progress.html +2 -2
  19. package/dist/demo/pb-repeat.html +1 -3
  20. package/dist/demo/pb-search.html +7 -4
  21. package/dist/demo/pb-search3.html +1 -1
  22. package/dist/demo/pb-search4.html +2 -2
  23. package/dist/demo/pb-view3.html +1 -1
  24. package/dist/{iron-form-3b8dcaa7.js → iron-form-dfb3e3b1.js} +95 -95
  25. package/dist/paper-checkbox-645e1077.js +200 -0
  26. package/dist/{paper-icon-button-b1d31571.js → paper-icon-button-984162bd.js} +1 -1
  27. package/dist/{paper-checkbox-515a5284.js → paper-inky-focus-behavior-fa16796b.js} +58 -247
  28. package/dist/{paper-listbox-a3b7175c.js → paper-listbox-5f5d1cec.js} +152 -162
  29. package/dist/pb-code-editor.js +25 -20
  30. package/dist/pb-component-docs.js +68 -64
  31. package/dist/pb-components-bundle.js +1983 -2293
  32. package/dist/pb-edit-app.js +167 -107
  33. package/dist/pb-elements.json +176 -120
  34. package/dist/{pb-i18n-0611135a.js → pb-i18n-4cc00bfe.js} +1 -1
  35. package/dist/pb-leaflet-map.js +23 -23
  36. package/dist/pb-mei.js +56 -41
  37. package/dist/{pb-mixin-b1caa22e.js → pb-mixin-886ece32.js} +1 -1
  38. package/dist/pb-odd-editor.js +1023 -782
  39. package/dist/pb-tify.js +2 -2
  40. package/dist/vaadin-element-mixin-beb74ffd.js +545 -0
  41. package/gh-pages.js +5 -3
  42. package/i18n/common/en.json +6 -0
  43. package/i18n/common/pl.json +2 -2
  44. package/lib/openseadragon.min.js +6 -6
  45. package/package.json +3 -3
  46. package/pb-elements.json +176 -120
  47. package/src/assets/components.css +5 -5
  48. package/src/authority/airtable.js +20 -21
  49. package/src/authority/anton.js +129 -129
  50. package/src/authority/custom.js +23 -21
  51. package/src/authority/geonames.js +38 -32
  52. package/src/authority/gnd.js +50 -42
  53. package/src/authority/kbga.js +137 -134
  54. package/src/authority/metagrid.js +44 -46
  55. package/src/authority/reconciliation.js +66 -67
  56. package/src/authority/registry.js +4 -4
  57. package/src/docs/pb-component-docs.js +2 -2
  58. package/src/docs/pb-component-view.js +5 -5
  59. package/src/docs/pb-components-list.js +2 -2
  60. package/src/docs/pb-demo-snippet.js +2 -2
  61. package/src/dts-client.js +299 -297
  62. package/src/dts-select-endpoint.js +90 -82
  63. package/src/parse-date-service.js +184 -135
  64. package/src/pb-ajax.js +158 -171
  65. package/src/pb-authority-lookup.js +191 -156
  66. package/src/pb-autocomplete.js +292 -280
  67. package/src/pb-blacklab-highlight.js +264 -259
  68. package/src/pb-blacklab-results.js +236 -221
  69. package/src/pb-browse-docs.js +540 -475
  70. package/src/pb-browse.js +68 -65
  71. package/src/pb-clipboard.js +79 -76
  72. package/src/pb-code-editor.js +110 -102
  73. package/src/pb-code-highlight.js +209 -204
  74. package/src/pb-codepen.js +79 -72
  75. package/src/pb-collapse.js +211 -151
  76. package/src/pb-combo-box.js +190 -190
  77. package/src/pb-components-bundle.js +1 -1
  78. package/src/pb-components.js +1 -0
  79. package/src/pb-custom-form.js +173 -153
  80. package/src/pb-dialog.js +98 -62
  81. package/src/pb-document.js +89 -90
  82. package/src/pb-download.js +212 -196
  83. package/src/pb-drawer.js +145 -148
  84. package/src/pb-edit-app.js +301 -229
  85. package/src/pb-edit-xml.js +100 -97
  86. package/src/pb-events.js +114 -107
  87. package/src/pb-facs-link.js +104 -102
  88. package/src/pb-facsimile.js +474 -410
  89. package/src/pb-formula.js +151 -153
  90. package/src/pb-geolocation.js +129 -131
  91. package/src/pb-grid-action.js +53 -56
  92. package/src/pb-grid.js +231 -228
  93. package/src/pb-highlight.js +140 -140
  94. package/src/pb-hotkeys.js +40 -42
  95. package/src/pb-i18n.js +101 -104
  96. package/src/pb-image-strip.js +84 -78
  97. package/src/pb-lang.js +142 -57
  98. package/src/pb-leaflet-map.js +488 -485
  99. package/src/pb-link.js +126 -124
  100. package/src/pb-load.js +431 -429
  101. package/src/pb-login.js +299 -244
  102. package/src/pb-manage-odds.js +352 -336
  103. package/src/pb-map-icon.js +89 -89
  104. package/src/pb-map-layer.js +85 -85
  105. package/src/pb-markdown.js +90 -99
  106. package/src/pb-media-query.js +74 -72
  107. package/src/pb-mei.js +306 -295
  108. package/src/pb-message.js +139 -97
  109. package/src/pb-mixin.js +269 -264
  110. package/src/pb-navigation.js +80 -95
  111. package/src/pb-observable.js +38 -38
  112. package/src/pb-odd-editor.js +1054 -958
  113. package/src/pb-odd-elementspec-editor.js +349 -298
  114. package/src/pb-odd-model-editor.js +1075 -909
  115. package/src/pb-odd-parameter-editor.js +200 -178
  116. package/src/pb-odd-rendition-editor.js +136 -124
  117. package/src/pb-page.js +431 -422
  118. package/src/pb-paginate.js +228 -179
  119. package/src/pb-panel.js +198 -182
  120. package/src/pb-popover-themes.js +15 -8
  121. package/src/pb-popover.js +296 -287
  122. package/src/pb-print-preview.js +127 -127
  123. package/src/pb-progress.js +51 -51
  124. package/src/pb-repeat.js +105 -104
  125. package/src/pb-restricted.js +84 -77
  126. package/src/pb-search.js +256 -228
  127. package/src/pb-select-feature.js +127 -120
  128. package/src/pb-select-odd.js +132 -124
  129. package/src/pb-select-template.js +89 -78
  130. package/src/pb-select.js +251 -227
  131. package/src/pb-split-list.js +179 -174
  132. package/src/pb-svg.js +80 -79
  133. package/src/pb-table-column.js +54 -54
  134. package/src/pb-table-grid.js +221 -203
  135. package/src/pb-tabs.js +61 -63
  136. package/src/pb-tify.js +154 -154
  137. package/src/pb-timeline.js +382 -249
  138. package/src/pb-toggle-feature.js +195 -187
  139. package/src/pb-upload.js +184 -174
  140. package/src/pb-version.js +30 -30
  141. package/src/pb-view-annotate.js +135 -98
  142. package/src/pb-view.js +1282 -1270
  143. package/src/pb-zoom.js +127 -45
  144. package/src/polymer-hack.js +1 -1
  145. package/src/search-result-service.js +256 -223
  146. package/src/seed-element.js +13 -20
  147. package/src/settings.js +4 -4
  148. package/src/theming.js +98 -91
  149. package/src/urls.js +289 -289
  150. package/src/utils.js +53 -51
  151. package/css/pb-styles.css +0 -51
  152. package/dist/vaadin-element-mixin-fe4a4883.js +0 -527
  153. package/src/assets/pb-styles.css +0 -51
  154. package/src/pb-light-dom.js +0 -41
@@ -7,34 +7,35 @@ import '@polymer/iron-icon';
7
7
  import '@cwmr/paper-autocomplete/paper-autocomplete-suggestions.js';
8
8
 
9
9
  function _query(datasource, query) {
10
- const queryResult = [];
11
- datasource.forEach((item) => {
12
- let objText, objValue;
10
+ const queryResult = [];
11
+ datasource.forEach(item => {
12
+ let objText;
13
+ let objValue;
13
14
 
14
- if (typeof item === 'object') {
15
- objText = item.text;
16
- objValue = item.value;
17
- } else {
18
- objText = item.toString();
19
- objValue = objText;
20
- }
15
+ if (typeof item === 'object') {
16
+ objText = item.text;
17
+ objValue = item.value;
18
+ } else {
19
+ objText = item.toString();
20
+ objValue = objText;
21
+ }
21
22
 
22
- if (objText.toLowerCase().indexOf(query) > -1) {
23
- // NOTE: the structure of the result object matches with the current template. For custom templates, you
24
- // might need to return more data
25
- const resultItem = {};
26
- resultItem.text = objText;
27
- resultItem.value = objValue;
28
- queryResult.push(resultItem);
29
- }
30
- });
31
- return queryResult;
23
+ if (objText.toLowerCase().indexOf(query) > -1) {
24
+ // NOTE: the structure of the result object matches with the current template. For custom templates, you
25
+ // might need to return more data
26
+ const resultItem = {};
27
+ resultItem.text = objText;
28
+ resultItem.value = objValue;
29
+ queryResult.push(resultItem);
30
+ }
31
+ });
32
+ return queryResult;
32
33
  }
33
34
 
34
35
  /**
35
36
  * Provides an input with attached autocomplete. The autocomplete suggestions can be read
36
37
  * either from a static list or a remote endpoint to which the current user input is sent.
37
- *
38
+ *
38
39
  * @cssprop --pb-search-label-color - Color of the label and underline
39
40
  * @cssprop --pb-search-input-color - Text color for input field
40
41
  * @cssprop --pb-search-focus-color - Color for label and underline if input has focus
@@ -43,293 +44,304 @@ function _query(datasource, query) {
43
44
  * @slot - default unnamed slot
44
45
  */
45
46
  export class PbAutocomplete extends pbMixin(LitElement) {
46
- static get properties() {
47
- return {
48
- ...super.properties,
49
- /**
50
- * Name of the form field which will be submitted
51
- */
52
- name: {
53
- type: String
54
- },
55
- /**
56
- * Value of the form field which will be submitted
57
- */
58
- value: {
59
- type: String
60
- },
61
- /**
62
- * Placeholder to display if field is empty
63
- */
64
- placeholder: {
65
- type: String,
66
- attribute: 'placeholder'
67
- },
68
- /**
69
- * Optional URL to query for suggestions. If relative, it is interpreted
70
- * relative to the endpoint defined on a surrounding `pb-page`.
71
- *
72
- * Upon autocomplete, the current input by the user will be sent with a query parameter
73
- * `query`. The name/values of form controls nested within `pb-autocomplete` will also be
74
- * appended to the request as parameters. This allows the server side code to distinguish
75
- * different states.
76
- */
77
- source: {
78
- type: String
79
- },
80
- /**
81
- * If set, the entire list of possible suggestions will be preloaded upon initialization of the
82
- * component.
83
- */
84
- preload: {
85
- type: Boolean
86
- },
87
- /**
88
- * A static list of suggestions. Use instead of `source`. May either be a flat array of strings,
89
- * or an array containing objects of the form `{"text": "", "value": ""}, in which case "value" denotes
90
- * the value to be used when the enclosing form is submitted, and "text" is the label to be displayed.
91
- */
92
- suggestions: {
93
- type: Array
94
- },
95
- /**
96
- * By default suggestions are filtered by prefix, i.e. only suggestions starting with the prefix
97
- * typed by the user are shown. Set this property to true to search for the user-provided string
98
- * anywhere within the suggestion text.
99
- */
100
- substring: {
101
- type: Boolean
102
- },
103
- /**
104
- * An icon to display next to the input.
105
- */
106
- icon: {
107
- type: String
108
- }
109
- };
110
- }
47
+ static get properties() {
48
+ return {
49
+ ...super.properties,
50
+ /**
51
+ * Name of the form field which will be submitted
52
+ */
53
+ name: {
54
+ type: String,
55
+ },
56
+ /**
57
+ * Value of the form field which will be submitted
58
+ */
59
+ value: {
60
+ type: String,
61
+ },
62
+ /**
63
+ * Placeholder to display if field is empty
64
+ */
65
+ placeholder: {
66
+ type: String,
67
+ attribute: 'placeholder',
68
+ },
69
+ /**
70
+ * Optional URL to query for suggestions. If relative, it is interpreted
71
+ * relative to the endpoint defined on a surrounding `pb-page`.
72
+ *
73
+ * Upon autocomplete, the current input by the user will be sent with a query parameter
74
+ * `query`. The name/values of form controls nested within `pb-autocomplete` will also be
75
+ * appended to the request as parameters. This allows the server side code to distinguish
76
+ * different states.
77
+ */
78
+ source: {
79
+ type: String,
80
+ },
81
+ /**
82
+ * If set, the entire list of possible suggestions will be preloaded upon initialization of the
83
+ * component.
84
+ */
85
+ preload: {
86
+ type: Boolean,
87
+ },
88
+ /**
89
+ * A static list of suggestions. Use instead of `source`. May either be a flat array of strings,
90
+ * or an array containing objects of the form `{"text": "", "value": ""}, in which case "value" denotes
91
+ * the value to be used when the enclosing form is submitted, and "text" is the label to be displayed.
92
+ */
93
+ suggestions: {
94
+ type: Array,
95
+ },
96
+ /**
97
+ * By default suggestions are filtered by prefix, i.e. only suggestions starting with the prefix
98
+ * typed by the user are shown. Set this property to true to search for the user-provided string
99
+ * anywhere within the suggestion text.
100
+ */
101
+ substring: {
102
+ type: Boolean,
103
+ },
104
+ /**
105
+ * An icon to display next to the input.
106
+ */
107
+ icon: {
108
+ type: String,
109
+ },
110
+ };
111
+ }
111
112
 
112
- constructor() {
113
- super();
114
- this.placeholder = 'search.placeholder';
115
- this.suggestions = [];
116
- this.lastSelected = null;
117
- this.preload = false;
118
- this.substring = false;
119
- this._hiddenInput = null;
120
- this._initialized = false;
121
- }
113
+ constructor() {
114
+ super();
115
+ this.placeholder = 'search.placeholder';
116
+ this.suggestions = [];
117
+ this.lastSelected = null;
118
+ this.preload = false;
119
+ this.substring = false;
120
+ this._hiddenInput = null;
121
+ this._initialized = false;
122
+ }
122
123
 
123
- connectedCallback() {
124
- super.connectedCallback();
125
- }
124
+ connectedCallback() {
125
+ super.connectedCallback();
126
+ }
126
127
 
127
- firstUpdated() {
128
- const inIronForm = this.closest('iron-form,pb-search,pb-custom-form');
129
- if (!inIronForm) {
130
- this._hiddenInput = document.createElement('input');
131
- this._hiddenInput.type = 'hidden';
132
- this._hiddenInput.name = this.name;
133
- this.appendChild(this._hiddenInput);
134
- }
128
+ firstUpdated() {
129
+ const inIronForm = this.closest('iron-form,pb-search,pb-custom-form');
130
+ if (!inIronForm) {
131
+ this._hiddenInput = document.createElement('input');
132
+ this._hiddenInput.type = 'hidden';
133
+ this._hiddenInput.name = this.name;
134
+ this.appendChild(this._hiddenInput);
135
+ }
135
136
 
136
- const autocomplete = this.shadowRoot.getElementById('autocomplete');
137
- autocomplete.addEventListener('autocomplete-change', this._autocomplete.bind(this));
137
+ const autocomplete = this.shadowRoot.getElementById('autocomplete');
138
+ autocomplete.addEventListener('autocomplete-change', this._autocomplete.bind(this));
138
139
 
139
- if (this.preload && this.source) {
140
- if (this.substring) {
141
- autocomplete.queryFn = _query;
142
- }
143
- waitOnce('pb-page-ready', () => {
144
- this._sendRequest();
145
- });
146
- } else if (this.value) {
147
- if (this.source) {
148
- waitOnce('pb-page-ready', () => {
149
- //console.log('send autocomplete request for remote source %s on value %s', this.source, this.value);
150
- this._sendRequest(this.value);
151
- });
152
- } else {
153
- const input = this.shadowRoot.getElementById('search');
154
- const value = this.suggestions.find((suggestion) => {
155
- if (suggestion.text) {
156
- return suggestion.value === this.value;
157
- }
158
- return suggestion === this.value;
159
- });
160
- if (value) {
161
- input.value = value.text || value;
162
- if (this._hiddenInput) {
163
- this._hiddenInput.value = value.value || value;
164
- }
165
- }
166
- if (this._hiddenInput) {
167
- this._hiddenInput.value = this.value;
168
- }
169
- }
140
+ if (this.preload && this.source) {
141
+ if (this.substring) {
142
+ autocomplete.queryFn = _query;
143
+ }
144
+ waitOnce('pb-page-ready', () => {
145
+ this._sendRequest();
146
+ });
147
+ } else if (this.value) {
148
+ if (this.source) {
149
+ waitOnce('pb-page-ready', () => {
150
+ // console.log('send autocomplete request for remote source %s on value %s', this.source, this.value);
151
+ this._sendRequest(this.value);
152
+ });
153
+ } else {
154
+ const input = this.shadowRoot.getElementById('search');
155
+ const value = this.suggestions.find(suggestion => {
156
+ if (suggestion.text) {
157
+ return suggestion.value === this.value;
158
+ }
159
+ return suggestion === this.value;
160
+ });
161
+ if (value) {
162
+ input.value = value.text || value;
163
+ if (this._hiddenInput) {
164
+ this._hiddenInput.value = value.value || value;
165
+ }
166
+ }
167
+ if (this._hiddenInput) {
168
+ this._hiddenInput.value = this.value;
170
169
  }
170
+ }
171
171
  }
172
+ }
172
173
 
173
- render() {
174
- return html`
175
- <custom-style>
176
- <style>
177
- :host {
178
- --suggestions-item: {
179
- color: var(--pb-search-suggestions-color, black);
180
- };
181
- --suggestions-wrapper: {
182
- background: var(--pb-search-suggestions-background, white);
183
- };
184
- }
185
- </style>
186
- </custom-style>
187
- <slot></slot>
188
- <paper-input id="search" type="search" name="query" @keyup="${this._setInput}" label="${translate(this.placeholder)}"
189
- always-float-label>
190
- ${this.icon ? html`<iron-icon icon="${this.icon}" slot="prefix"></iron-icon>` : null}
191
- </paper-input>
192
- <paper-autocomplete-suggestions id="autocomplete" for="search" .source="${this.suggestions}" ?remote-source="${!this.preload && this.source}"
193
- @autocomplete-selected="${this._autocompleteSelected}"></paper-autocomplete-suggestions>
194
-
195
- <iron-ajax
196
- id="autocompleteLoader"
197
- verbose
198
- handle-as="json"
199
- method="get"
200
- with-credentials
201
- @response="${this._updateSuggestions}"></iron-ajax>
174
+ render() {
175
+ return html`
176
+ <custom-style>
177
+ <style>
178
+ :host {
179
+ --suggestions-item: {
180
+ color: var(--pb-search-suggestions-color, black);
181
+ }
182
+ --suggestions-wrapper: {
183
+ background: var(--pb-search-suggestions-background, white);
184
+ }
185
+ }
186
+ </style>
187
+ </custom-style>
188
+ <slot></slot>
189
+ <paper-input
190
+ id="search"
191
+ type="search"
192
+ name="query"
193
+ @keyup="${this._setInput}"
194
+ label="${translate(this.placeholder)}"
195
+ always-float-label
196
+ >
197
+ ${this.icon ? html`<iron-icon icon="${this.icon}" slot="prefix"></iron-icon>` : null}
198
+ </paper-input>
199
+ <paper-autocomplete-suggestions
200
+ id="autocomplete"
201
+ for="search"
202
+ .source="${this.suggestions}"
203
+ ?remote-source="${!this.preload && this.source}"
204
+ @autocomplete-selected="${this._autocompleteSelected}"
205
+ ></paper-autocomplete-suggestions>
202
206
 
203
-
207
+ <iron-ajax
208
+ id="autocompleteLoader"
209
+ verbose
210
+ handle-as="json"
211
+ method="get"
212
+ with-credentials
213
+ @response="${this._updateSuggestions}"
214
+ ></iron-ajax>
204
215
  `;
216
+ }
205
217
 
206
- }
207
-
208
- static get styles() {
209
- return css`
210
- :host {
211
- --paper-input-container-color: var(--pb-search-label-color, var(--paper-grey-500, #303030));
212
- --paper-input-container-input-color: var(--pb-search-input-color, var(--pb-color-primary, #000000));
213
- --paper-input-container-focus-color: var(--pb-search-focus-color, var(--paper-grey-500, #303030));
214
-
215
- display: flex;
216
- align-items: center;
217
- }
218
+ static get styles() {
219
+ return css`
220
+ :host {
221
+ --paper-input-container-color: var(--pb-search-label-color, var(--paper-grey-500, #303030));
222
+ --paper-input-container-input-color: var(
223
+ --pb-search-input-color,
224
+ var(--pb-color-primary, #000000)
225
+ );
226
+ --paper-input-container-focus-color: var(
227
+ --pb-search-focus-color,
228
+ var(--paper-grey-500, #303030)
229
+ );
218
230
 
219
- ::slotted {
220
- display: block;
221
- margin-left: 10px;
222
- }
223
- `;
224
- }
225
-
226
- _autocomplete(ev) {
227
- const search = this.shadowRoot.getElementById('search');
228
- this._sendRequest(search.value);
229
- }
231
+ display: flex;
232
+ align-items: center;
233
+ }
230
234
 
231
- _sendRequest(query) {
232
- const loader = this.shadowRoot.getElementById('autocompleteLoader');
233
- loader.url = this.toAbsoluteURL(this.source);
235
+ ::slotted {
236
+ display: block;
237
+ margin-left: 10px;
238
+ }
239
+ `;
240
+ }
234
241
 
235
- const params = this._getParameters();
236
- params.query = query;
237
- loader.params = params;
238
- //console.log('send request for %s with %o', loaderId, params);
242
+ _autocomplete(ev) {
243
+ const search = this.shadowRoot.getElementById('search');
244
+ this._sendRequest(search.value);
245
+ }
239
246
 
240
- loader.generateRequest();
241
- }
247
+ _sendRequest(query) {
248
+ const loader = this.shadowRoot.getElementById('autocompleteLoader');
249
+ loader.url = this.toAbsoluteURL(this.source);
242
250
 
251
+ const params = this._getParameters();
252
+ params.query = query;
253
+ loader.params = params;
254
+ // console.log('send request for %s with %o', loaderId, params);
243
255
 
244
- _updateSuggestions() {
245
- const loader = this.shadowRoot.getElementById('autocompleteLoader');
246
- if (this._initialized) {
247
- const autocomplete = this.shadowRoot.getElementById('autocomplete');
248
- if (loader.lastResponse) {
249
- this.suggestions = loader.lastResponse;
250
- autocomplete.suggestions(this.suggestions);
251
- }
252
- } else if (loader.lastResponse) {
253
- const suggestions = loader.lastResponse;
256
+ loader.generateRequest();
257
+ }
254
258
 
255
- const input = this.shadowRoot.getElementById('search');
256
- const value = suggestions.find((suggestion) => {
257
- if (suggestion.text) {
258
- return suggestion.value === this.value;
259
- }
260
- return suggestion === this.value;
261
- });
262
- if (value) {
263
- input.value = value.text || value;
264
- if (this._hiddenInput) {
265
- this._hiddenInput.value = value.value || value;
266
- }
267
- } else if (this._hiddenInput) {
268
- this._hiddenInput.value = this.value;
269
- }
259
+ _updateSuggestions() {
260
+ const loader = this.shadowRoot.getElementById('autocompleteLoader');
261
+ if (this._initialized) {
262
+ const autocomplete = this.shadowRoot.getElementById('autocomplete');
263
+ if (loader.lastResponse) {
264
+ this.suggestions = loader.lastResponse;
265
+ autocomplete.suggestions(this.suggestions);
266
+ }
267
+ } else if (loader.lastResponse) {
268
+ const suggestions = loader.lastResponse;
270
269
 
271
- if (this.preload) {
272
- this.suggestions = suggestions;
273
- }
270
+ const input = this.shadowRoot.getElementById('search');
271
+ const value = suggestions.find(suggestion => {
272
+ if (suggestion.text) {
273
+ return suggestion.value === this.value;
274
274
  }
275
- this._initialized = true;
276
-
277
- }
275
+ return suggestion === this.value;
276
+ });
277
+ if (value) {
278
+ input.value = value.text || value;
279
+ if (this._hiddenInput) {
280
+ this._hiddenInput.value = value.value || value;
281
+ }
282
+ } else if (this._hiddenInput) {
283
+ this._hiddenInput.value = this.value;
284
+ }
278
285
 
279
- _getParameters() {
280
- const params = {};
281
- const inputs = this.querySelectorAll('[name]');
282
- inputs.forEach((input) => {
283
- params[input.name] = input.value;
284
- });
285
- return params;
286
+ if (this.preload) {
287
+ this.suggestions = suggestions;
288
+ }
286
289
  }
290
+ this._initialized = true;
291
+ }
287
292
 
288
- _autocompleteSelected(ev) {
289
- const { text, value } = ev.detail;
290
- this.lastSelected = text;
291
- const input = this.shadowRoot.getElementById('search');
292
- input.value = text;
293
- this.value = value;
294
- if (this._hiddenInput) {
295
- this._hiddenInput.value = this.value;
296
- }
293
+ _getParameters() {
294
+ const params = {};
295
+ const inputs = this.querySelectorAll('[name]');
296
+ inputs.forEach(input => {
297
+ params[input.name] = input.value;
298
+ });
299
+ return params;
300
+ }
297
301
 
298
- this.emitTo('pb-autocomplete-selected', { text, value });
302
+ _autocompleteSelected(ev) {
303
+ const { text, value } = ev.detail;
304
+ this.lastSelected = text;
305
+ const input = this.shadowRoot.getElementById('search');
306
+ input.value = text;
307
+ this.value = value;
308
+ if (this._hiddenInput) {
309
+ this._hiddenInput.value = this.value;
299
310
  }
300
311
 
301
- _setInput(ev) {
302
- const input = this.shadowRoot.getElementById('search');
303
- this.value = input.value;
312
+ this.emitTo('pb-autocomplete-selected', { text, value });
313
+ }
304
314
 
305
- if (this._hiddenInput) {
306
- this._hiddenInput.value = this.value;
307
- }
315
+ _setInput(ev) {
316
+ const input = this.shadowRoot.getElementById('search');
317
+ this.value = input.value;
308
318
 
309
- if (ev.keyCode === 13) {
310
- const entry = this.suggestions.find((suggestion) => {
311
- if (suggestion.text) {
312
- return suggestion.value === this.value;
313
- }
314
- return suggestion === this.value;
315
- });
316
- if (!entry) {
317
- return;
318
- }
319
- if (entry.value) {
320
- this.emitTo('pb-autocomplete-selected', {
321
- text: entry.text,
322
- value: entry.value
323
- });
324
- } else {
325
- this.emitTo('pb-autocomplete-selected', {
326
- text: entry,
327
- value: entry
328
- });
329
- }
330
- }
319
+ if (this._hiddenInput) {
320
+ this._hiddenInput.value = this.value;
331
321
  }
332
322
 
333
-
323
+ if (ev.keyCode === 13) {
324
+ const entry = this.suggestions.find(suggestion => {
325
+ if (suggestion.text) {
326
+ return suggestion.value === this.value;
327
+ }
328
+ return suggestion === this.value;
329
+ });
330
+ if (!entry) {
331
+ return;
332
+ }
333
+ if (entry.value) {
334
+ this.emitTo('pb-autocomplete-selected', {
335
+ text: entry.text,
336
+ value: entry.value,
337
+ });
338
+ } else {
339
+ this.emitTo('pb-autocomplete-selected', {
340
+ text: entry,
341
+ value: entry,
342
+ });
343
+ }
344
+ }
345
+ }
334
346
  }
335
- customElements.define('pb-autocomplete', PbAutocomplete);
347
+ customElements.define('pb-autocomplete', PbAutocomplete);