@teipublisher/pb-components 2.26.0-next-3.11 → 2.26.0-next-3.13
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.
- package/.github/workflows/main.yml +3 -3
- package/.github/workflows/node.js.yml +3 -3
- package/.github/workflows/release.js.yml +3 -3
- package/CHANGELOG.md +38 -0
- package/Dockerfile +78 -70
- package/css/components.css +5 -5
- package/dist/demo/components.css +2 -8
- package/dist/demo/pb-drawer2.html +1 -1
- package/dist/demo/pb-leaflet-map.html +1 -1
- package/dist/demo/pb-progress.html +2 -2
- package/dist/demo/pb-repeat.html +1 -3
- package/dist/demo/pb-view3.html +1 -1
- package/dist/{paper-icon-button-0fb125c4.js → paper-icon-button-72125e67.js} +1 -1
- package/dist/pb-code-editor.js +25 -20
- package/dist/pb-component-docs.js +58 -54
- package/dist/pb-components-bundle.js +1937 -1782
- package/dist/pb-edit-app.js +167 -107
- package/dist/pb-elements.json +45 -45
- package/dist/{pb-i18n-0611135a.js → pb-i18n-4cc00bfe.js} +1 -1
- package/dist/pb-leaflet-map.js +23 -23
- package/dist/pb-mei.js +56 -41
- package/dist/{pb-mixin-b1caa22e.js → pb-mixin-886ece32.js} +1 -1
- package/dist/pb-odd-editor.js +923 -756
- package/dist/pb-tify.js +2 -2
- package/dist/{vaadin-element-mixin-6633322b.js → vaadin-element-mixin-84fb7d82.js} +181 -143
- package/gh-pages.js +5 -3
- package/i18n/common/pl.json +2 -2
- package/lib/openseadragon.min.js +1 -1
- package/package.json +2 -2
- package/pb-elements.json +45 -45
- package/src/assets/components.css +5 -5
- package/src/authority/airtable.js +20 -21
- package/src/authority/anton.js +129 -129
- package/src/authority/custom.js +23 -21
- package/src/authority/geonames.js +38 -32
- package/src/authority/gnd.js +47 -42
- package/src/authority/kbga.js +137 -134
- package/src/authority/metagrid.js +44 -46
- package/src/authority/reconciliation.js +66 -67
- package/src/authority/registry.js +4 -4
- package/src/docs/pb-component-docs.js +2 -2
- package/src/docs/pb-component-view.js +5 -5
- package/src/docs/pb-components-list.js +2 -2
- package/src/docs/pb-demo-snippet.js +2 -2
- package/src/dts-client.js +299 -297
- package/src/dts-select-endpoint.js +90 -82
- package/src/parse-date-service.js +184 -135
- package/src/pb-ajax.js +150 -146
- package/src/pb-authority-lookup.js +183 -146
- package/src/pb-autocomplete.js +292 -280
- package/src/pb-blacklab-highlight.js +264 -259
- package/src/pb-blacklab-results.js +236 -221
- package/src/pb-browse-docs.js +540 -475
- package/src/pb-browse.js +68 -65
- package/src/pb-clipboard.js +79 -76
- package/src/pb-code-editor.js +110 -102
- package/src/pb-code-highlight.js +209 -204
- package/src/pb-codepen.js +79 -72
- package/src/pb-collapse.js +212 -207
- package/src/pb-combo-box.js +190 -190
- package/src/pb-components-bundle.js +1 -1
- package/src/pb-custom-form.js +151 -149
- package/src/pb-dialog.js +96 -60
- package/src/pb-document.js +89 -90
- package/src/pb-download.js +210 -198
- package/src/pb-drawer.js +145 -148
- package/src/pb-edit-app.js +301 -229
- package/src/pb-edit-xml.js +98 -96
- package/src/pb-events.js +114 -107
- package/src/pb-facs-link.js +104 -102
- package/src/pb-facsimile.js +411 -413
- package/src/pb-formula.js +151 -153
- package/src/pb-geolocation.js +129 -131
- package/src/pb-grid-action.js +53 -56
- package/src/pb-grid.js +231 -228
- package/src/pb-highlight.js +140 -140
- package/src/pb-hotkeys.js +40 -42
- package/src/pb-i18n.js +101 -104
- package/src/pb-image-strip.js +84 -78
- package/src/pb-lang.js +132 -128
- package/src/pb-leaflet-map.js +488 -485
- package/src/pb-link.js +126 -124
- package/src/pb-load.js +431 -426
- package/src/pb-login.js +291 -248
- package/src/pb-manage-odds.js +364 -318
- package/src/pb-map-icon.js +89 -89
- package/src/pb-map-layer.js +85 -85
- package/src/pb-markdown.js +90 -99
- package/src/pb-media-query.js +74 -72
- package/src/pb-mei.js +306 -295
- package/src/pb-message.js +144 -144
- package/src/pb-mixin.js +269 -264
- package/src/pb-navigation.js +80 -82
- package/src/pb-observable.js +38 -38
- package/src/pb-odd-editor.js +1053 -955
- package/src/pb-odd-elementspec-editor.js +348 -297
- package/src/pb-odd-model-editor.js +1061 -901
- package/src/pb-odd-parameter-editor.js +200 -178
- package/src/pb-odd-rendition-editor.js +136 -124
- package/src/pb-page.js +431 -421
- package/src/pb-paginate.js +202 -190
- package/src/pb-panel.js +191 -179
- package/src/pb-popover-themes.js +7 -5
- package/src/pb-popover.js +296 -287
- package/src/pb-print-preview.js +127 -127
- package/src/pb-progress.js +51 -51
- package/src/pb-repeat.js +105 -104
- package/src/pb-restricted.js +84 -77
- package/src/pb-search.js +252 -241
- package/src/pb-select-feature.js +127 -120
- package/src/pb-select-odd.js +132 -124
- package/src/pb-select-template.js +89 -78
- package/src/pb-select.js +251 -227
- package/src/pb-split-list.js +179 -174
- package/src/pb-svg.js +80 -79
- package/src/pb-table-column.js +54 -54
- package/src/pb-table-grid.js +221 -203
- package/src/pb-tabs.js +61 -63
- package/src/pb-tify.js +154 -154
- package/src/pb-timeline.js +271 -229
- package/src/pb-toggle-feature.js +182 -175
- package/src/pb-upload.js +184 -174
- package/src/pb-version.js +30 -30
- package/src/pb-view-annotate.js +132 -98
- package/src/pb-view.js +1289 -1270
- package/src/pb-zoom.js +75 -59
- package/src/polymer-hack.js +1 -1
- package/src/search-result-service.js +256 -223
- package/src/seed-element.js +13 -20
- package/src/settings.js +4 -4
- package/src/theming.js +96 -96
- package/src/urls.js +289 -289
- package/src/utils.js +53 -51
package/src/pb-autocomplete.js
CHANGED
|
@@ -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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const queryResult = [];
|
|
11
|
+
datasource.forEach(item => {
|
|
12
|
+
let objText;
|
|
13
|
+
let objValue;
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
124
|
+
connectedCallback() {
|
|
125
|
+
super.connectedCallback();
|
|
126
|
+
}
|
|
126
127
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
|
|
137
|
-
|
|
137
|
+
const autocomplete = this.shadowRoot.getElementById('autocomplete');
|
|
138
|
+
autocomplete.addEventListener('autocomplete-change', this._autocomplete.bind(this));
|
|
138
139
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
-
|
|
232
|
-
|
|
233
|
-
|
|
235
|
+
::slotted {
|
|
236
|
+
display: block;
|
|
237
|
+
margin-left: 10px;
|
|
238
|
+
}
|
|
239
|
+
`;
|
|
240
|
+
}
|
|
234
241
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
242
|
+
_autocomplete(ev) {
|
|
243
|
+
const search = this.shadowRoot.getElementById('search');
|
|
244
|
+
this._sendRequest(search.value);
|
|
245
|
+
}
|
|
239
246
|
|
|
240
|
-
|
|
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
|
-
|
|
245
|
-
|
|
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
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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
|
-
|
|
272
|
-
|
|
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.
|
|
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
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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
|
-
|
|
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
|
-
|
|
302
|
-
|
|
303
|
-
this.value = input.value;
|
|
312
|
+
this.emitTo('pb-autocomplete-selected', { text, value });
|
|
313
|
+
}
|
|
304
314
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
315
|
+
_setInput(ev) {
|
|
316
|
+
const input = this.shadowRoot.getElementById('search');
|
|
317
|
+
this.value = input.value;
|
|
308
318
|
|
|
309
|
-
|
|
310
|
-
|
|
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);
|