@dile/ui 2.21.2 → 2.21.4
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.
|
@@ -20,6 +20,9 @@ export class DileSelectAjax extends DileEmmitChange(LitElement) {
|
|
|
20
20
|
position: relative;
|
|
21
21
|
margin-bottom: 10px;
|
|
22
22
|
}
|
|
23
|
+
#result {
|
|
24
|
+
margin-bottom: 0.5rem;
|
|
25
|
+
}
|
|
23
26
|
label {
|
|
24
27
|
display: block;
|
|
25
28
|
margin-bottom: var(--dile-input-label-margin-bottom, 4px);
|
|
@@ -83,11 +86,11 @@ export class DileSelectAjax extends DileEmmitChange(LitElement) {
|
|
|
83
86
|
displayProperty: { type: String },
|
|
84
87
|
idProperty: { type: String },
|
|
85
88
|
delay: { type: Number },
|
|
86
|
-
opened: {
|
|
89
|
+
opened: {
|
|
87
90
|
type: Boolean,
|
|
88
91
|
state: true,
|
|
89
92
|
},
|
|
90
|
-
keyword: {
|
|
93
|
+
keyword: {
|
|
91
94
|
type: String,
|
|
92
95
|
state: true,
|
|
93
96
|
},
|
|
@@ -102,7 +105,7 @@ export class DileSelectAjax extends DileEmmitChange(LitElement) {
|
|
|
102
105
|
/* When static is true there is no posibility to search, then all the options are displayed on the select on initialization */
|
|
103
106
|
static: {
|
|
104
107
|
type: Boolean,
|
|
105
|
-
},
|
|
108
|
+
},
|
|
106
109
|
/** Message Displayed */
|
|
107
110
|
message: { type: String },
|
|
108
111
|
/** Hide errors on input */
|
|
@@ -166,9 +169,9 @@ export class DileSelectAjax extends DileEmmitChange(LitElement) {
|
|
|
166
169
|
.then(json => this.registerText(json))
|
|
167
170
|
.catch(error => this.registerError(error));
|
|
168
171
|
}
|
|
169
|
-
|
|
172
|
+
|
|
170
173
|
registerText(json) {
|
|
171
|
-
this.selectedText = json[this.resultDataProperty][this.displayProperty];
|
|
174
|
+
this.selectedText = json[this.resultDataProperty][this.displayProperty];
|
|
172
175
|
this.loading = false;
|
|
173
176
|
}
|
|
174
177
|
|
|
@@ -198,9 +201,9 @@ export class DileSelectAjax extends DileEmmitChange(LitElement) {
|
|
|
198
201
|
|
|
199
202
|
get selectedTemplate() {
|
|
200
203
|
return html`
|
|
201
|
-
<dile-input-search
|
|
204
|
+
<dile-input-search
|
|
202
205
|
id="result"
|
|
203
|
-
?errored=${this.errored}
|
|
206
|
+
?errored=${this.errored}
|
|
204
207
|
?disabled=${this.disabled}
|
|
205
208
|
value="${this.selectedText}"
|
|
206
209
|
readOnly
|
|
@@ -212,11 +215,11 @@ export class DileSelectAjax extends DileEmmitChange(LitElement) {
|
|
|
212
215
|
|
|
213
216
|
get searchTemplate() {
|
|
214
217
|
return html`
|
|
215
|
-
<dile-input-search
|
|
218
|
+
<dile-input-search
|
|
216
219
|
id="search"
|
|
217
|
-
placeholder="${this.placeholder}"
|
|
218
|
-
label="${this.label}"
|
|
219
|
-
?errored=${this.errored}
|
|
220
|
+
placeholder="${this.placeholder}"
|
|
221
|
+
label="${this.label}"
|
|
222
|
+
?errored=${this.errored}
|
|
220
223
|
?disabled=${this.disabled}
|
|
221
224
|
@focus=${this.onFocus}
|
|
222
225
|
@dile-input-search=${this.onTextInput}
|
|
@@ -267,8 +270,8 @@ export class DileSelectAjax extends DileEmmitChange(LitElement) {
|
|
|
267
270
|
|
|
268
271
|
get dataTemplate() {
|
|
269
272
|
return html`
|
|
270
|
-
<dile-select
|
|
271
|
-
id="elselect"
|
|
273
|
+
<dile-select
|
|
274
|
+
id="elselect"
|
|
272
275
|
@element-changed=${this.doSelected}
|
|
273
276
|
name="generated-select-field"
|
|
274
277
|
?errored=${this.errored}
|
|
@@ -279,13 +282,13 @@ export class DileSelectAjax extends DileEmmitChange(LitElement) {
|
|
|
279
282
|
<option value="${item[this.idProperty]}">${item[this.displayProperty]}</option>
|
|
280
283
|
`)}
|
|
281
284
|
</select>
|
|
282
|
-
</dile-select>
|
|
285
|
+
</dile-select>
|
|
283
286
|
`;
|
|
284
287
|
}
|
|
285
288
|
|
|
286
289
|
get messageTemplate() {
|
|
287
290
|
return html`
|
|
288
|
-
${this.message
|
|
291
|
+
${this.message
|
|
289
292
|
? html`<div class="message ${this.errored ? 'errored-msg' : ''}"><span>${this.message}</span></div>`
|
|
290
293
|
: ''
|
|
291
294
|
}
|
|
@@ -312,38 +315,38 @@ export class DileSelectAjax extends DileEmmitChange(LitElement) {
|
|
|
312
315
|
this.loading = true;
|
|
313
316
|
this.ajaxError = false;
|
|
314
317
|
const url = this.computeRequestURL();
|
|
315
|
-
|
|
318
|
+
|
|
316
319
|
fetch(url)
|
|
317
320
|
.then(response => response.json())
|
|
318
321
|
.then(json => this.registerData(json))
|
|
319
322
|
.catch(error => this.registerError(error));
|
|
320
323
|
}
|
|
321
|
-
|
|
324
|
+
|
|
322
325
|
computeRequestURL() {
|
|
323
326
|
const baseUrl = `${this.endpoint}?${this.queryStringVariable}=${this.keyword}`;
|
|
324
|
-
|
|
327
|
+
|
|
325
328
|
if (this.additionalQueryString && typeof this.additionalQueryString === 'object') {
|
|
326
329
|
const additionalParams = Object.entries(this.additionalQueryString)
|
|
327
330
|
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
|
|
328
331
|
.join('&');
|
|
329
|
-
|
|
332
|
+
|
|
330
333
|
return `${baseUrl}&${additionalParams}`;
|
|
331
334
|
}
|
|
332
|
-
|
|
335
|
+
|
|
333
336
|
return baseUrl;
|
|
334
337
|
}
|
|
335
|
-
|
|
338
|
+
|
|
336
339
|
|
|
337
340
|
registerError(err) {
|
|
338
341
|
this.ajaxError = true;
|
|
339
342
|
this.loading = false;
|
|
340
343
|
}
|
|
341
|
-
|
|
344
|
+
|
|
342
345
|
registerData(json) {
|
|
343
346
|
this.data = this.getResultData(json);
|
|
344
347
|
this.updateComplete.then( () => this.loading = false )
|
|
345
348
|
}
|
|
346
|
-
|
|
349
|
+
|
|
347
350
|
getResultData(json) {
|
|
348
351
|
if (this.resultDataProperty === undefined || this.resultDataProperty === '') {
|
|
349
352
|
return json;
|
|
@@ -401,12 +404,12 @@ export class DileSelectAjax extends DileEmmitChange(LitElement) {
|
|
|
401
404
|
}
|
|
402
405
|
|
|
403
406
|
dispatchSelectedTextChanged() {
|
|
404
|
-
this.dispatchEvent(new CustomEvent('dile-select-ajax-selected-text-changed',
|
|
405
|
-
{
|
|
407
|
+
this.dispatchEvent(new CustomEvent('dile-select-ajax-selected-text-changed',
|
|
408
|
+
{
|
|
406
409
|
bubbles: true,
|
|
407
410
|
composed: true,
|
|
408
411
|
detail: { selectedText: this.selectedText }
|
|
409
412
|
}
|
|
410
413
|
));
|
|
411
414
|
}
|
|
412
|
-
}
|
|
415
|
+
}
|
|
@@ -46,6 +46,14 @@ export const DileOverlay = function(superClass) {
|
|
|
46
46
|
this.horizontalAlign = 'under_left';
|
|
47
47
|
this.verticalAlign = 'bottom';
|
|
48
48
|
this.delayId = null;
|
|
49
|
+
this._rafId = null;
|
|
50
|
+
this._onScrollResize = () => {
|
|
51
|
+
if (this._rafId) return;
|
|
52
|
+
this._rafId = requestAnimationFrame(() => {
|
|
53
|
+
this._rafId = null;
|
|
54
|
+
if (this._overlayClass === 'opened') this.updatePosition();
|
|
55
|
+
});
|
|
56
|
+
};
|
|
49
57
|
}
|
|
50
58
|
|
|
51
59
|
firstUpdated() {
|
|
@@ -80,6 +88,7 @@ export const DileOverlay = function(superClass) {
|
|
|
80
88
|
}));
|
|
81
89
|
if(!this._opening && this._overlayClass=='opened') {
|
|
82
90
|
this._overlayClass = '';
|
|
91
|
+
this._removePositionListeners();
|
|
83
92
|
this.cancelDelay();
|
|
84
93
|
this.delayId = setTimeout(() => {
|
|
85
94
|
this.overlay.style.display = 'none'
|
|
@@ -106,64 +115,96 @@ export const DileOverlay = function(superClass) {
|
|
|
106
115
|
this._overlayClass = 'opened'
|
|
107
116
|
this._opening = false;
|
|
108
117
|
this.overlay.style.display = 'block';
|
|
118
|
+
this._addPositionListeners();
|
|
109
119
|
}, 50);
|
|
110
120
|
}
|
|
111
121
|
}
|
|
112
122
|
|
|
123
|
+
_addPositionListeners() {
|
|
124
|
+
window.addEventListener('scroll', this._onScrollResize, { passive: true, capture: true });
|
|
125
|
+
window.addEventListener('resize', this._onScrollResize, { passive: true });
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
_removePositionListeners() {
|
|
129
|
+
window.removeEventListener('scroll', this._onScrollResize, { capture: true });
|
|
130
|
+
window.removeEventListener('resize', this._onScrollResize);
|
|
131
|
+
if (this._rafId) {
|
|
132
|
+
cancelAnimationFrame(this._rafId);
|
|
133
|
+
this._rafId = null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
113
137
|
updatePosition() {
|
|
114
|
-
let triggerWidth = parseInt(this.trigger.offsetWidth);
|
|
115
|
-
let triggerHeight = parseInt(this.trigger.offsetHeight);
|
|
116
138
|
let moveTop = parseInt(this.moveTop);
|
|
117
139
|
let moveLeft = parseInt(this.moveLeft);
|
|
118
|
-
|
|
140
|
+
|
|
141
|
+
let triggerRect = this.trigger.getBoundingClientRect();
|
|
142
|
+
|
|
143
|
+
// Switch to fixed positioning so overflow:hidden ancestors don't clip the overlay
|
|
144
|
+
this.overlay.style.position = 'fixed';
|
|
119
145
|
let lastDisplay = this.overlay.style.display;
|
|
120
|
-
this.overlay.style.top =
|
|
146
|
+
this.overlay.style.top = '-10000px';
|
|
147
|
+
this.overlay.style.left = '-10000px';
|
|
121
148
|
this.overlay.style.display = 'block';
|
|
122
|
-
|
|
149
|
+
|
|
123
150
|
let overlayWidth = parseInt(this.overlay.offsetWidth);
|
|
124
151
|
let overlayHeight = parseInt(this.overlay.offsetHeight);
|
|
125
|
-
|
|
152
|
+
|
|
126
153
|
switch(this.verticalAlign) {
|
|
127
154
|
case 'top':
|
|
128
|
-
this.
|
|
155
|
+
this.setOverlayStyleTop(triggerRect.top - overlayHeight + moveTop, triggerRect, overlayHeight, 'top');
|
|
129
156
|
break;
|
|
130
157
|
case 'center':
|
|
131
|
-
this.
|
|
158
|
+
this.setOverlayStyleTop(triggerRect.top - ((overlayHeight - (triggerRect.height / 2)) / 2) - moveTop, triggerRect, overlayHeight, 'center');
|
|
132
159
|
break;
|
|
133
160
|
default:
|
|
134
|
-
this.
|
|
161
|
+
this.setOverlayStyleTop(triggerRect.bottom + 10 + moveTop, triggerRect, overlayHeight, 'bottom');
|
|
135
162
|
}
|
|
163
|
+
|
|
136
164
|
switch(this.horizontalAlign) {
|
|
137
165
|
case 'under_left':
|
|
138
|
-
this.setOverlayStyleLeft(
|
|
166
|
+
this.setOverlayStyleLeft(triggerRect.left);
|
|
167
|
+
break;
|
|
168
|
+
case 'under_right':
|
|
169
|
+
this.setOverlayStyleLeft(triggerRect.right - overlayWidth);
|
|
139
170
|
break;
|
|
140
|
-
case 'under_right':
|
|
141
|
-
this.setOverlayStyleLeft(`-${overlayWidth - triggerWidth}px`);
|
|
142
|
-
break;
|
|
143
171
|
case 'left':
|
|
144
|
-
this.setOverlayStyleLeft(
|
|
172
|
+
this.setOverlayStyleLeft(triggerRect.left - overlayWidth - moveLeft);
|
|
145
173
|
break;
|
|
146
174
|
case 'right':
|
|
147
|
-
|
|
175
|
+
this.setOverlayStyleLeft(triggerRect.right + moveLeft);
|
|
148
176
|
break;
|
|
149
177
|
default:
|
|
150
|
-
|
|
178
|
+
this.setOverlayStyleLeft(triggerRect.left - ((overlayWidth - triggerRect.width) / 2) - moveLeft);
|
|
151
179
|
}
|
|
180
|
+
|
|
152
181
|
this.overlay.style.display = lastDisplay;
|
|
153
182
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
183
|
+
|
|
184
|
+
setOverlayStyleTop(topValue, triggerRect, overlayHeight, direction) {
|
|
185
|
+
const viewportHeight = document.documentElement.clientHeight;
|
|
186
|
+
const margin = 10;
|
|
187
|
+
if (direction === 'bottom' && topValue + overlayHeight > viewportHeight - margin) {
|
|
188
|
+
const flipped = triggerRect.top - overlayHeight - margin;
|
|
189
|
+
topValue = flipped >= margin ? flipped : viewportHeight - overlayHeight - margin;
|
|
190
|
+
} else if (direction === 'top' && topValue < margin) {
|
|
191
|
+
const flipped = triggerRect.bottom + margin;
|
|
192
|
+
topValue = flipped + overlayHeight <= viewportHeight - margin ? flipped : margin;
|
|
161
193
|
}
|
|
162
|
-
|
|
163
|
-
if (
|
|
164
|
-
|
|
165
|
-
|
|
194
|
+
if (topValue < margin) topValue = margin;
|
|
195
|
+
if (topValue + overlayHeight > viewportHeight - margin) topValue = viewportHeight - overlayHeight - margin;
|
|
196
|
+
this.overlay.style.top = topValue + 'px';
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
setOverlayStyleLeft(posLeft) {
|
|
200
|
+
const pageWidth = document.querySelector('html').clientWidth;
|
|
201
|
+
const overlayWidth = this.overlay.offsetWidth;
|
|
202
|
+
if (posLeft < 10) {
|
|
203
|
+
posLeft = 10;
|
|
204
|
+
} else if (posLeft + overlayWidth > pageWidth - 15) {
|
|
205
|
+
posLeft = pageWidth - overlayWidth - 15;
|
|
166
206
|
}
|
|
207
|
+
this.overlay.style.left = posLeft + 'px';
|
|
167
208
|
}
|
|
168
209
|
}
|
|
169
210
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dile/ui",
|
|
3
|
-
"version": "2.21.
|
|
3
|
+
"version": "2.21.4",
|
|
4
4
|
"description": "UI Core components from dile-components.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"publishConfig": {
|
|
27
27
|
"access": "public"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "f3d7061476125162d6d9822928d40dc15e110c6c"
|
|
30
30
|
}
|