@italia/tooltip 1.0.0-alpha.10
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/AUTHORS +3 -0
- package/LICENSE +18 -0
- package/README.md +67 -0
- package/custom-elements.json +497 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +5 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/it-tooltip.d.ts +46 -0
- package/dist/src/it-tooltip.d.ts.map +1 -0
- package/dist/src/it-tooltip.js +3146 -0
- package/dist/src/it-tooltip.js.map +1 -0
- package/dist/src/types.d.ts +4 -0
- package/dist/src/types.d.ts.map +1 -0
- package/package.json +73 -0
- package/styles/globals.scss +6 -0
|
@@ -0,0 +1,3146 @@
|
|
|
1
|
+
import { directive, Directive } from 'lit/directive.js';
|
|
2
|
+
import { LitElement, css, html } from 'lit';
|
|
3
|
+
import { state, query, property, customElement } from 'lit/decorators.js';
|
|
4
|
+
|
|
5
|
+
/******************************************************************************
|
|
6
|
+
Copyright (c) Microsoft Corporation.
|
|
7
|
+
|
|
8
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
9
|
+
purpose with or without fee is hereby granted.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
12
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
13
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
14
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
15
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
16
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
18
|
+
***************************************************************************** */
|
|
19
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
function __decorate(decorators, target, key, desc) {
|
|
23
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
24
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
25
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
26
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function __metadata(metadataKey, metadataValue) {
|
|
30
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
34
|
+
var e = new Error(message);
|
|
35
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
class SetAttributesDirective extends Directive {
|
|
39
|
+
update(part, [attributes]) {
|
|
40
|
+
const el = part.element;
|
|
41
|
+
for (const [name, value] of Object.entries(attributes)) {
|
|
42
|
+
if (value != null)
|
|
43
|
+
el.setAttribute(name, value);
|
|
44
|
+
else
|
|
45
|
+
el.removeAttribute(name);
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
50
|
+
render(_attributes) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/* How to use:
|
|
55
|
+
|
|
56
|
+
<textarea ${setAttributes(this._ariaAttributes)} ... />
|
|
57
|
+
*/
|
|
58
|
+
directive(SetAttributesDirective);
|
|
59
|
+
|
|
60
|
+
function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}
|
|
61
|
+
|
|
62
|
+
const connectedElements = new Set();
|
|
63
|
+
if (window && !window.translations) {
|
|
64
|
+
window.translations = new Map();
|
|
65
|
+
}
|
|
66
|
+
const { translations } = window;
|
|
67
|
+
let fallback;
|
|
68
|
+
// TODO: We need some way for users to be able to set these on the server.
|
|
69
|
+
let documentDirection = 'ltr';
|
|
70
|
+
// Fallback for server.
|
|
71
|
+
let documentLanguage = 'en';
|
|
72
|
+
const isClient = typeof MutationObserver !== 'undefined' &&
|
|
73
|
+
typeof document !== 'undefined' &&
|
|
74
|
+
typeof document.documentElement !== 'undefined';
|
|
75
|
+
/** Updates all localized elements that are currently connected */
|
|
76
|
+
function update() {
|
|
77
|
+
if (isClient) {
|
|
78
|
+
documentDirection = document.documentElement.dir || 'ltr';
|
|
79
|
+
documentLanguage = document.documentElement.lang || navigator.language;
|
|
80
|
+
}
|
|
81
|
+
[...connectedElements.keys()].forEach((el) => {
|
|
82
|
+
const litEl = el;
|
|
83
|
+
if (typeof litEl.requestUpdate === 'function') {
|
|
84
|
+
litEl.requestUpdate();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if (isClient) {
|
|
89
|
+
const documentElementObserver = new MutationObserver(update);
|
|
90
|
+
documentDirection = document.documentElement.dir || 'ltr';
|
|
91
|
+
documentLanguage = document.documentElement.lang || navigator.language;
|
|
92
|
+
// Watch for changes on <html lang>
|
|
93
|
+
documentElementObserver.observe(document.documentElement, {
|
|
94
|
+
attributes: true,
|
|
95
|
+
attributeFilter: ['dir', 'lang'],
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/** Registers one or more translations */
|
|
99
|
+
function registerTranslation(...translation) {
|
|
100
|
+
translation.forEach((t) => {
|
|
101
|
+
const code = t.$code.toLowerCase();
|
|
102
|
+
if (translations.has(code)) {
|
|
103
|
+
// Merge translations that share the same language code
|
|
104
|
+
translations.set(code, { ...translations.get(code), ...t });
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
translations.set(code, t);
|
|
108
|
+
}
|
|
109
|
+
// The first translation that's registered is the fallback
|
|
110
|
+
if (!fallback) {
|
|
111
|
+
fallback = t;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
update();
|
|
115
|
+
}
|
|
116
|
+
if (typeof window !== 'undefined') {
|
|
117
|
+
window.registerTranslation = registerTranslation;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Localize Reactive Controller for components built with Lit
|
|
121
|
+
*
|
|
122
|
+
* To use this controller, import the class and instantiate it in a custom element constructor:
|
|
123
|
+
*
|
|
124
|
+
* private localize = new LocalizeController(this);
|
|
125
|
+
*
|
|
126
|
+
* This will add the element to the set and make it respond to changes to <html dir|lang> automatically. To make it
|
|
127
|
+
* respond to changes to its own dir|lang properties, make it a property:
|
|
128
|
+
*
|
|
129
|
+
* @property() dir: string;
|
|
130
|
+
* @property() lang: string;
|
|
131
|
+
*
|
|
132
|
+
* To use a translation method, call it like this:
|
|
133
|
+
*
|
|
134
|
+
* ${this.localize.term('term_key_here')}
|
|
135
|
+
* ${this.localize.date('2021-12-03')}
|
|
136
|
+
* ${this.localize.number(1000000)}
|
|
137
|
+
*/
|
|
138
|
+
class LocalizeController {
|
|
139
|
+
constructor(host) {
|
|
140
|
+
this.host = host;
|
|
141
|
+
this.host.addController(this);
|
|
142
|
+
}
|
|
143
|
+
hostConnected() {
|
|
144
|
+
connectedElements.add(this.host);
|
|
145
|
+
}
|
|
146
|
+
hostDisconnected() {
|
|
147
|
+
connectedElements.delete(this.host);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Gets the host element's directionality as determined by the `dir` attribute. The return value is transformed to
|
|
151
|
+
* lowercase.
|
|
152
|
+
*/
|
|
153
|
+
dir() {
|
|
154
|
+
return `${this.host.dir || documentDirection}`.toLowerCase();
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Gets the host element's language as determined by the `lang` attribute. The return value is transformed to
|
|
158
|
+
* lowercase.
|
|
159
|
+
*/
|
|
160
|
+
lang() {
|
|
161
|
+
return `${this.host.lang || documentLanguage}`.toLowerCase();
|
|
162
|
+
}
|
|
163
|
+
// eslint-disable-next-line class-methods-use-this
|
|
164
|
+
getTranslationData(lang) {
|
|
165
|
+
// Convert "en_US" to "en-US". Note that both underscores and dashes are allowed per spec, but underscores result in
|
|
166
|
+
// a RangeError by the call to `new Intl.Locale()`. See: https://unicode.org/reports/tr35/#unicode-locale-identifier
|
|
167
|
+
const locale = new Intl.Locale(lang.replace(/_/g, '-'));
|
|
168
|
+
const language = locale?.language.toLowerCase();
|
|
169
|
+
const region = locale?.region?.toLowerCase() ?? '';
|
|
170
|
+
const primary = translations.get(`${language}-${region}`);
|
|
171
|
+
const secondary = translations.get(language);
|
|
172
|
+
return { locale, language, region, primary, secondary };
|
|
173
|
+
}
|
|
174
|
+
/** Determines if the specified term exists, optionally checking the fallback translation. */
|
|
175
|
+
exists(key, options) {
|
|
176
|
+
const { primary, secondary } = this.getTranslationData(options.lang ?? this.lang());
|
|
177
|
+
const mergedOptions = {
|
|
178
|
+
includeFallback: false,
|
|
179
|
+
...options,
|
|
180
|
+
};
|
|
181
|
+
if ((primary && primary[key]) ||
|
|
182
|
+
(secondary && secondary[key]) ||
|
|
183
|
+
(mergedOptions.includeFallback && fallback && fallback[key])) {
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
/** Outputs a translated term. */
|
|
189
|
+
term(key, ...args) {
|
|
190
|
+
const { primary, secondary } = this.getTranslationData(this.lang());
|
|
191
|
+
let term;
|
|
192
|
+
// Look for a matching term using regionCode, code, then the fallback
|
|
193
|
+
if (primary && primary[key]) {
|
|
194
|
+
term = primary[key];
|
|
195
|
+
}
|
|
196
|
+
else if (secondary && secondary[key]) {
|
|
197
|
+
term = secondary[key];
|
|
198
|
+
}
|
|
199
|
+
else if (fallback && fallback[key]) {
|
|
200
|
+
term = fallback[key];
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
// eslint-disable-next-line no-console
|
|
204
|
+
console.error(`No translation found for: ${String(key)}`);
|
|
205
|
+
return String(key);
|
|
206
|
+
}
|
|
207
|
+
if (typeof term === 'function') {
|
|
208
|
+
return term(...args);
|
|
209
|
+
}
|
|
210
|
+
return term;
|
|
211
|
+
}
|
|
212
|
+
/** Outputs a localized date in the specified format. */
|
|
213
|
+
date(dateToFormat, options) {
|
|
214
|
+
const date = new Date(dateToFormat);
|
|
215
|
+
return new Intl.DateTimeFormat(this.lang(), options).format(date);
|
|
216
|
+
}
|
|
217
|
+
/** Outputs a localized number in the specified format. */
|
|
218
|
+
number(numberToFormat, options) {
|
|
219
|
+
const num = Number(numberToFormat);
|
|
220
|
+
return Number.isNaN(num) ? '' : new Intl.NumberFormat(this.lang(), options).format(num);
|
|
221
|
+
}
|
|
222
|
+
/** Outputs a localized time in relative format. */
|
|
223
|
+
relativeTime(value, unit, options) {
|
|
224
|
+
return new Intl.RelativeTimeFormat(this.lang(), options).format(value, unit);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* @param Base The base class.
|
|
230
|
+
* @returns A mix-in implementing `localizations` method.
|
|
231
|
+
*
|
|
232
|
+
*@example
|
|
233
|
+
* <!-- Terms -->
|
|
234
|
+
${this.$localize.term('hello')}
|
|
235
|
+
or
|
|
236
|
+
${this.$t('hello')}
|
|
237
|
+
|
|
238
|
+
<!-- Dates -->
|
|
239
|
+
${this.$localize.date('2021-09-15 14:00:00 ET', { month: 'long', day: 'numeric', year: 'numeric' })}
|
|
240
|
+
or
|
|
241
|
+
${this.$d('2021-09-15 14:00:00 ET', { month: 'long', day: 'numeric', year: 'numeric' })}
|
|
242
|
+
|
|
243
|
+
<!-- Numbers/currency -->
|
|
244
|
+
${this.$localize.number(1000, { style: 'currency', currency: 'USD'})}
|
|
245
|
+
or
|
|
246
|
+
${this.$n(1000,{ style: 'currency', currency: 'USD'})}
|
|
247
|
+
|
|
248
|
+
<!-- Determining language -->
|
|
249
|
+
${this.$localize.lang()}
|
|
250
|
+
|
|
251
|
+
<!-- Determining directionality, e.g. 'ltr' or 'rtl' -->
|
|
252
|
+
${this.$localize.dir()}
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
*** HOW TO DEFINE TRANSLATIONS: ***
|
|
256
|
+
// Simple terms
|
|
257
|
+
upload: 'Upload',
|
|
258
|
+
|
|
259
|
+
// Terms with placeholders
|
|
260
|
+
greetUser: (name: string) => `Hello, ${name}!`,
|
|
261
|
+
|
|
262
|
+
// Plurals
|
|
263
|
+
numFilesSelected: (count: number) => {
|
|
264
|
+
if (count === 0) return 'No files selected';
|
|
265
|
+
if (count === 1) return '1 file selected';
|
|
266
|
+
return `${count} files selected`;
|
|
267
|
+
}
|
|
268
|
+
*/
|
|
269
|
+
const LocalizeMixin = (Base) => class extends Base {
|
|
270
|
+
constructor() {
|
|
271
|
+
super(...arguments);
|
|
272
|
+
this.localize = new LocalizeController(this);
|
|
273
|
+
}
|
|
274
|
+
// Provide default values to avoid definite assignment errors and avoid decorators
|
|
275
|
+
// commentati perchè danno problemi su React.js. Sono attributi nativi, e assegnare un valore di default a react da fastidio
|
|
276
|
+
// dir: string = '';
|
|
277
|
+
// lang: string = '';
|
|
278
|
+
/**
|
|
279
|
+
* Restituisce tutta l'utility di traduzione
|
|
280
|
+
*
|
|
281
|
+
|
|
282
|
+
*
|
|
283
|
+
* @returns tutta l'utility di traduzione
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* this.$localize.lang() -> ritorna la lingua corrente
|
|
287
|
+
* this.$localize.dir() -> ritorna la direzione della lingua corrente
|
|
288
|
+
*/
|
|
289
|
+
get $localize() {
|
|
290
|
+
return this.localize;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Restituisce una stringa localizzata a partire da una chiave di termine.
|
|
294
|
+
*
|
|
295
|
+
* Utilizza il `LocalizeController` per accedere al dizionario corrente e
|
|
296
|
+
* tradurre la chiave fornita secondo la lingua attiva.
|
|
297
|
+
*
|
|
298
|
+
* @param t - La chiave del termine da localizzare (es. 'hello', 'submit', ecc.).
|
|
299
|
+
* @returns La stringa tradotta in base alla lingua attiva. Se la chiave non è trovata, restituisce la chiave stessa.
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* this.$t('hello'); // → "Ciao" (in locale it-IT)
|
|
303
|
+
*/
|
|
304
|
+
$t(t) {
|
|
305
|
+
// format term
|
|
306
|
+
return this.localize.term(t);
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Formatta una data in base alla localizzazione attiva.
|
|
310
|
+
*
|
|
311
|
+
* Utilizza il `LocalizeController` per restituire una stringa localizzata
|
|
312
|
+
* secondo le opzioni fornite (es. mese esteso, anno, ecc.).
|
|
313
|
+
*
|
|
314
|
+
* @param n - La data da formattare come stringa compatibile (es. ISO o con timezone, es. '2021-09-15 14:00:00 ET').
|
|
315
|
+
* @param p - Le opzioni di formattazione per `Intl.DateTimeFormat` (es. { year: 'numeric', month: 'long', day: 'numeric' }).
|
|
316
|
+
* @returns Una stringa rappresentante la data formattata secondo la localizzazione attiva.
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* this.$d('2021-09-15 14:00:00 ET', { year: 'numeric', month: 'long', day: 'numeric' });
|
|
320
|
+
* // → "15 settembre 2021" (in locale it-IT)
|
|
321
|
+
*/
|
|
322
|
+
$d(d, p) {
|
|
323
|
+
// format date
|
|
324
|
+
return this.localize.date(d, p);
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Formatta un numero secondo le impostazioni locali dell'utente corrente.
|
|
328
|
+
*
|
|
329
|
+
* Utilizza il `LocalizeController` per applicare formattazione numerica,
|
|
330
|
+
* incluse opzioni come separatori, decimali, valute, ecc.
|
|
331
|
+
*
|
|
332
|
+
* @param d - Il numero da formattare.
|
|
333
|
+
* @param p - Le opzioni di formattazione (es. { style: 'currency', currency: 'EUR' }).
|
|
334
|
+
* @returns Una stringa rappresentante il numero formattato secondo la localizzazione attiva.
|
|
335
|
+
*
|
|
336
|
+
* @example
|
|
337
|
+
* this.$n(1234.56, { style: 'currency', currency: 'USD' }); // → "$1,234.56" (in locale en-US)
|
|
338
|
+
*/
|
|
339
|
+
$n(d, p) {
|
|
340
|
+
return this.localize.number(d, p);
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
/* eslint-disable no-console */
|
|
345
|
+
class Logger {
|
|
346
|
+
constructor(tag) {
|
|
347
|
+
this.tag = tag;
|
|
348
|
+
}
|
|
349
|
+
format(level, msg) {
|
|
350
|
+
return [`[${this.tag}] ${msg}`];
|
|
351
|
+
}
|
|
352
|
+
warn(msg) {
|
|
353
|
+
console.warn(...this.format('warn', msg));
|
|
354
|
+
}
|
|
355
|
+
error(msg) {
|
|
356
|
+
console.error(...this.format('error', msg));
|
|
357
|
+
}
|
|
358
|
+
info(msg) {
|
|
359
|
+
console.info(...this.format('info', msg));
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Factory function per creare una base class estendibile
|
|
365
|
+
* con stili personalizzati.
|
|
366
|
+
*/
|
|
367
|
+
class BaseComponent extends LitElement {
|
|
368
|
+
constructor() {
|
|
369
|
+
super();
|
|
370
|
+
this.composeClass = clsx;
|
|
371
|
+
this.logger = new Logger(this.tagName.toLowerCase());
|
|
372
|
+
}
|
|
373
|
+
get _ariaAttributes() {
|
|
374
|
+
const attributes = {};
|
|
375
|
+
for (const attr of this.getAttributeNames()) {
|
|
376
|
+
if (attr === 'it-role') {
|
|
377
|
+
attributes.role = this.getAttribute(attr);
|
|
378
|
+
}
|
|
379
|
+
else if (attr.startsWith('it-aria-')) {
|
|
380
|
+
attributes[attr.replace(/^it-/, '')] = this.getAttribute(attr);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return attributes;
|
|
384
|
+
}
|
|
385
|
+
// eslint-disable-next-line class-methods-use-this
|
|
386
|
+
generateId(prefix) {
|
|
387
|
+
return `${prefix}-${Math.random().toString(36).slice(2)}`;
|
|
388
|
+
}
|
|
389
|
+
// eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
|
|
390
|
+
addFocus(element) {
|
|
391
|
+
// new TrackFocus(element); // per il momento è stato disattivato perchè ci sono le pseudo classi ::focus-visible per fare quello che fa TrackFocus. Si possono aggiungere regole css in bsi-italia 3 dato che stiamo facendo una breaking release di bsi.
|
|
392
|
+
}
|
|
393
|
+
// eslint-disable-next-line class-methods-use-this
|
|
394
|
+
getActiveElement() {
|
|
395
|
+
let active = document.activeElement;
|
|
396
|
+
while (active && active.shadowRoot && active.shadowRoot.activeElement) {
|
|
397
|
+
active = active.shadowRoot.activeElement;
|
|
398
|
+
}
|
|
399
|
+
return active;
|
|
400
|
+
}
|
|
401
|
+
get focusElement() {
|
|
402
|
+
return this;
|
|
403
|
+
}
|
|
404
|
+
// eslint-disable-next-line class-methods-use-this
|
|
405
|
+
get prefersReducedMotion() {
|
|
406
|
+
return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
407
|
+
}
|
|
408
|
+
connectedCallback() {
|
|
409
|
+
super.connectedCallback();
|
|
410
|
+
// generate internal _id
|
|
411
|
+
const prefix = this.id?.length > 0 ? this.id : this.tagName.toLowerCase();
|
|
412
|
+
this._id = this.generateId(prefix);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
const BaseLocalizedComponent = LocalizeMixin(BaseComponent);
|
|
416
|
+
|
|
417
|
+
//
|
|
418
|
+
// We store a WeakMap of forms + controls so we can keep references to all FormControl within a given form. As
|
|
419
|
+
// elements connect and disconnect to/from the DOM, their containing form is used as the key and the form control is
|
|
420
|
+
// added and removed from the form's set, respectively.
|
|
421
|
+
//
|
|
422
|
+
const formCollections = new WeakMap();
|
|
423
|
+
//
|
|
424
|
+
// We store a WeakMap of reportValidity() overloads so we can override it when form controls connect to the DOM and
|
|
425
|
+
// restore the original behavior when they disconnect.
|
|
426
|
+
//
|
|
427
|
+
const reportValidityOverloads = new WeakMap();
|
|
428
|
+
const checkValidityOverloads = new WeakMap();
|
|
429
|
+
//
|
|
430
|
+
// We store a Set of controls that users have interacted with. This allows us to determine the interaction state
|
|
431
|
+
// without littering the DOM with additional data attributes.
|
|
432
|
+
//
|
|
433
|
+
const userInteractedControls = new WeakSet();
|
|
434
|
+
//
|
|
435
|
+
// We store a WeakMap of interactions for each form control so we can track when all conditions are met for validation.
|
|
436
|
+
//
|
|
437
|
+
const interactions = new WeakMap();
|
|
438
|
+
/** A reactive controller to allow form controls to participate in form submission, validation, etc. */
|
|
439
|
+
class FormControlController {
|
|
440
|
+
constructor(host, options) {
|
|
441
|
+
this.submittedOnce = false;
|
|
442
|
+
this.handleFormData = (event) => {
|
|
443
|
+
// console.log('handleFormData');
|
|
444
|
+
const disabled = this.options.disabled(this.host);
|
|
445
|
+
const name = this.options.name(this.host);
|
|
446
|
+
const value = this.options.value(this.host);
|
|
447
|
+
const tagName = this.host.tagName.toLowerCase();
|
|
448
|
+
// For buttons, we only submit the value if they were the submitter. This is currently done in doAction() by
|
|
449
|
+
// injecting the name/value on a temporary button, so we can just skip them here.
|
|
450
|
+
const isButton = tagName === 'it-button';
|
|
451
|
+
if (this.host.isConnected &&
|
|
452
|
+
!disabled &&
|
|
453
|
+
!isButton &&
|
|
454
|
+
typeof name === 'string' &&
|
|
455
|
+
name.length > 0 &&
|
|
456
|
+
typeof value !== 'undefined') {
|
|
457
|
+
switch (tagName) {
|
|
458
|
+
case 'it-radio':
|
|
459
|
+
if (this.host.checked) {
|
|
460
|
+
event.formData.append(name, value);
|
|
461
|
+
}
|
|
462
|
+
break;
|
|
463
|
+
case 'it-checkbox':
|
|
464
|
+
case 'it-toggle':
|
|
465
|
+
if (this.host.checked) {
|
|
466
|
+
if (event.formData.getAll(name).indexOf(value) < 0) {
|
|
467
|
+
// handle group checkbox
|
|
468
|
+
event.formData.append(name, value);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
break;
|
|
472
|
+
case 'it-checkbox-group':
|
|
473
|
+
case 'it-toggle-group':
|
|
474
|
+
// non settare valori in formData, perchè ogni singola checkbox setta il suo valore
|
|
475
|
+
break;
|
|
476
|
+
case 'it-upload':
|
|
477
|
+
// value is File[] — append each File object directly (not as string)
|
|
478
|
+
if (Array.isArray(value)) {
|
|
479
|
+
value.forEach((file) => {
|
|
480
|
+
event.formData.append(name, file);
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
break;
|
|
484
|
+
default:
|
|
485
|
+
if (Array.isArray(value)) {
|
|
486
|
+
value.forEach((val) => {
|
|
487
|
+
event.formData.append(name, val.toString());
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
else {
|
|
491
|
+
event.formData.append(name, value.toString());
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
this.handleFormSubmit = (event) => {
|
|
497
|
+
const disabled = this.options.disabled(this.host);
|
|
498
|
+
const reportValidity = this.options.reportValidity;
|
|
499
|
+
// Update the interacted state for all controls when the form is submitted
|
|
500
|
+
if (this.form && !this.form.noValidate) {
|
|
501
|
+
formCollections.get(this.form)?.forEach((control) => {
|
|
502
|
+
this.setUserInteracted(control, true);
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
const resReportValidity = reportValidity(this.host);
|
|
506
|
+
if (this.form && !this.form.noValidate && !disabled && !resReportValidity) {
|
|
507
|
+
event.preventDefault();
|
|
508
|
+
// event.stopImmediatePropagation(); // se lo attiviamo, valida un campo alla volta
|
|
509
|
+
// Scroll al primo controllo non valido
|
|
510
|
+
const formControls = formCollections.get(this.form);
|
|
511
|
+
if (formControls) {
|
|
512
|
+
for (const control of formControls) {
|
|
513
|
+
if (!control.validity?.valid) {
|
|
514
|
+
// Scroll smooth verso il controllo non valido
|
|
515
|
+
control.scrollIntoView({
|
|
516
|
+
behavior: 'smooth',
|
|
517
|
+
block: 'center',
|
|
518
|
+
});
|
|
519
|
+
break;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
this.submittedOnce = true;
|
|
525
|
+
};
|
|
526
|
+
this.handleFormReset = () => {
|
|
527
|
+
this.options.setValue(this.host, '');
|
|
528
|
+
this.submittedOnce = false;
|
|
529
|
+
this.setUserInteracted(this.host, false);
|
|
530
|
+
interactions.set(this.host, []);
|
|
531
|
+
};
|
|
532
|
+
this.handleInteraction = (event) => {
|
|
533
|
+
const emittedEvents = interactions.get(this.host);
|
|
534
|
+
if (!emittedEvents.includes(event.type)) {
|
|
535
|
+
emittedEvents.push(event.type);
|
|
536
|
+
}
|
|
537
|
+
// Mark it as user-interacted as soon as all associated events have been emitted
|
|
538
|
+
if (emittedEvents.length === this.options.assumeInteractionOn.length) {
|
|
539
|
+
this.setUserInteracted(this.host, true);
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
this.checkFormValidity = () => {
|
|
543
|
+
// console.log('checkFormValidity');
|
|
544
|
+
//
|
|
545
|
+
// This is very similar to the `reportFormValidity` function, but it does not trigger native constraint validation
|
|
546
|
+
// Allow the user to simply check if the form is valid and handling validity in their own way.
|
|
547
|
+
//
|
|
548
|
+
// We preserve the original method in a WeakMap, but we don't call it from the overload because that would trigger
|
|
549
|
+
// validations in an unexpected order. When the element disconnects, we revert to the original behavior. This won't
|
|
550
|
+
// be necessary once we can use ElementInternals.
|
|
551
|
+
//
|
|
552
|
+
// Note that we're also honoring the form's novalidate attribute.
|
|
553
|
+
//
|
|
554
|
+
if (this.form && !this.form.noValidate) {
|
|
555
|
+
// This seems sloppy, but checking all elements will cover native inputs, Shoelace inputs, and other custom
|
|
556
|
+
// elements that support the constraint validation API.
|
|
557
|
+
const elements = this.form.querySelectorAll('*');
|
|
558
|
+
for (const element of elements) {
|
|
559
|
+
if (typeof element.checkValidity === 'function') {
|
|
560
|
+
if (!element.checkValidity()) {
|
|
561
|
+
return false;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
return true;
|
|
567
|
+
};
|
|
568
|
+
this.reportFormValidity = () => {
|
|
569
|
+
// console.log('reportFormValidity');
|
|
570
|
+
//
|
|
571
|
+
// FormControl work hard to act like regular form controls. They support the Constraint Validation API
|
|
572
|
+
// and its associated methods such as setCustomValidity() and reportValidity(). However, the HTMLFormElement also
|
|
573
|
+
// has a reportValidity() method that will trigger validation on all child controls. Since we're not yet using
|
|
574
|
+
// ElementInternals, we need to overload this method so it looks for any element with the reportValidity() method.
|
|
575
|
+
//
|
|
576
|
+
// We preserve the original method in a WeakMap, but we don't call it from the overload because that would trigger
|
|
577
|
+
// validations in an unexpected order. When the element disconnects, we revert to the original behavior. This won't
|
|
578
|
+
// be necessary once we can use ElementInternals.
|
|
579
|
+
//
|
|
580
|
+
// Note that we're also honoring the form's novalidate attribute.
|
|
581
|
+
//
|
|
582
|
+
if (this.form && !this.form.noValidate) {
|
|
583
|
+
// This seems sloppy, but checking all elements will cover native inputs, Shoelace inputs, and other custom
|
|
584
|
+
// elements that support the constraint validation API.
|
|
585
|
+
const elements = this.form.querySelectorAll('*');
|
|
586
|
+
for (const element of elements) {
|
|
587
|
+
if (typeof element.reportValidity === 'function') {
|
|
588
|
+
if (!element.reportValidity()) {
|
|
589
|
+
return false;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
return true;
|
|
595
|
+
};
|
|
596
|
+
(this.host = host).addController(this);
|
|
597
|
+
this.options = {
|
|
598
|
+
form: (input) => {
|
|
599
|
+
// If there's a form attribute, use it to find the target form by id
|
|
600
|
+
// Controls may not always reflect the 'form' property. For example, `<it-button>` doesn't reflect.
|
|
601
|
+
const formId = input.form;
|
|
602
|
+
if (formId) {
|
|
603
|
+
const root = input.getRootNode();
|
|
604
|
+
const form = root.querySelector(`#${formId}`);
|
|
605
|
+
if (form) {
|
|
606
|
+
return form;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
return input.closest('form');
|
|
610
|
+
},
|
|
611
|
+
name: (input) => input.name,
|
|
612
|
+
value: (input) => input.value,
|
|
613
|
+
disabled: (input) => input.disabled ?? false,
|
|
614
|
+
reportValidity: (input) => typeof input.reportValidity === 'function' ? input.reportValidity() : true,
|
|
615
|
+
checkValidity: (input) => (typeof input.checkValidity === 'function' ? input.checkValidity() : true),
|
|
616
|
+
setValue: (input, value) => {
|
|
617
|
+
// eslint-disable-next-line no-param-reassign
|
|
618
|
+
input.value = value;
|
|
619
|
+
},
|
|
620
|
+
assumeInteractionOn: ['it-input'],
|
|
621
|
+
...options,
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
hostConnected() {
|
|
625
|
+
const form = this.options.form(this.host);
|
|
626
|
+
if (form) {
|
|
627
|
+
this.attachForm(form);
|
|
628
|
+
}
|
|
629
|
+
// Listen for interactions
|
|
630
|
+
interactions.set(this.host, []);
|
|
631
|
+
this.options.assumeInteractionOn.forEach((event) => {
|
|
632
|
+
this.host.addEventListener(event, this.handleInteraction);
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
hostDisconnected() {
|
|
636
|
+
this.detachForm();
|
|
637
|
+
// Clean up interactions
|
|
638
|
+
interactions.delete(this.host);
|
|
639
|
+
this.options.assumeInteractionOn.forEach((event) => {
|
|
640
|
+
this.host.removeEventListener(event, this.handleInteraction);
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
hostUpdated() {
|
|
644
|
+
const form = this.options.form(this.host);
|
|
645
|
+
// Detach if the form no longer exists
|
|
646
|
+
if (!form) {
|
|
647
|
+
this.detachForm();
|
|
648
|
+
}
|
|
649
|
+
// If the form has changed, reattach it
|
|
650
|
+
if (form && this.form !== form) {
|
|
651
|
+
this.detachForm();
|
|
652
|
+
this.attachForm(form);
|
|
653
|
+
}
|
|
654
|
+
if (this.host.hasUpdated) {
|
|
655
|
+
this.setValidity(this.host.validity.valid);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
attachForm(form) {
|
|
659
|
+
if (form) {
|
|
660
|
+
this.form = form;
|
|
661
|
+
// Add this element to the form's collection
|
|
662
|
+
if (formCollections.has(this.form)) {
|
|
663
|
+
formCollections.get(this.form).add(this.host);
|
|
664
|
+
}
|
|
665
|
+
else {
|
|
666
|
+
formCollections.set(this.form, new Set([this.host]));
|
|
667
|
+
}
|
|
668
|
+
this.form.addEventListener('formdata', this.handleFormData);
|
|
669
|
+
this.form.addEventListener('submit', this.handleFormSubmit);
|
|
670
|
+
this.form.addEventListener('reset', this.handleFormReset);
|
|
671
|
+
// Overload the form's reportValidity() method so it looks at FormControl
|
|
672
|
+
if (!reportValidityOverloads.has(this.form)) {
|
|
673
|
+
reportValidityOverloads.set(this.form, this.form.reportValidity);
|
|
674
|
+
this.form.reportValidity = () => this.reportFormValidity();
|
|
675
|
+
}
|
|
676
|
+
// Overload the form's checkValidity() method so it looks at FormControl
|
|
677
|
+
if (!checkValidityOverloads.has(this.form)) {
|
|
678
|
+
checkValidityOverloads.set(this.form, this.form.checkValidity);
|
|
679
|
+
this.form.checkValidity = () => this.checkFormValidity();
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
else {
|
|
683
|
+
this.form = undefined;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
detachForm() {
|
|
687
|
+
if (!this.form)
|
|
688
|
+
return;
|
|
689
|
+
const formCollection = formCollections.get(this.form);
|
|
690
|
+
if (!formCollection) {
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
this.submittedOnce = false;
|
|
694
|
+
// Remove this host from the form's collection
|
|
695
|
+
formCollection.delete(this.host);
|
|
696
|
+
// Check to make sure there's no other form controls in the collection. If we do this
|
|
697
|
+
// without checking if any other controls are still in the collection, then we will wipe out the
|
|
698
|
+
// validity checks for all other elements.
|
|
699
|
+
// see: https://github.com/shoelace-style/shoelace/issues/1703
|
|
700
|
+
if (formCollection.size <= 0) {
|
|
701
|
+
this.form.removeEventListener('formdata', this.handleFormData);
|
|
702
|
+
this.form.removeEventListener('submit', this.handleFormSubmit);
|
|
703
|
+
this.form.removeEventListener('reset', this.handleFormReset);
|
|
704
|
+
// Remove the overload and restore the original method
|
|
705
|
+
if (reportValidityOverloads.has(this.form)) {
|
|
706
|
+
this.form.reportValidity = reportValidityOverloads.get(this.form);
|
|
707
|
+
reportValidityOverloads.delete(this.form);
|
|
708
|
+
}
|
|
709
|
+
if (checkValidityOverloads.has(this.form)) {
|
|
710
|
+
this.form.checkValidity = checkValidityOverloads.get(this.form);
|
|
711
|
+
checkValidityOverloads.delete(this.form);
|
|
712
|
+
}
|
|
713
|
+
// So it looks weird here to not always set the form to undefined. But I _think_ if we unattach this.form here,
|
|
714
|
+
// we end up in this fun spot where future validity checks don't have a reference to the form validity handler.
|
|
715
|
+
// First form element in sets the validity handler. So we can't clean up `this.form` until there are no other form elements in the form.
|
|
716
|
+
this.form = undefined;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
// eslint-disable-next-line class-methods-use-this
|
|
720
|
+
setUserInteracted(el, hasInteracted) {
|
|
721
|
+
if (hasInteracted) {
|
|
722
|
+
userInteractedControls.add(el);
|
|
723
|
+
}
|
|
724
|
+
else {
|
|
725
|
+
userInteractedControls.delete(el);
|
|
726
|
+
}
|
|
727
|
+
el.requestUpdate();
|
|
728
|
+
}
|
|
729
|
+
doAction(type, submitter) {
|
|
730
|
+
// console.log('doaction', type);
|
|
731
|
+
if (this.form) {
|
|
732
|
+
const button = document.createElement('button');
|
|
733
|
+
button.type = type;
|
|
734
|
+
button.style.position = 'absolute';
|
|
735
|
+
button.style.width = '0';
|
|
736
|
+
button.style.height = '0';
|
|
737
|
+
button.style.clipPath = 'inset(50%)';
|
|
738
|
+
button.style.overflow = 'hidden';
|
|
739
|
+
button.style.whiteSpace = 'nowrap';
|
|
740
|
+
// Pass name, value, and form attributes through to the temporary button
|
|
741
|
+
if (submitter) {
|
|
742
|
+
button.name = submitter.name;
|
|
743
|
+
button.value = submitter.value;
|
|
744
|
+
['formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget'].forEach((attr) => {
|
|
745
|
+
if (submitter.hasAttribute(attr)) {
|
|
746
|
+
button.setAttribute(attr, submitter.getAttribute(attr));
|
|
747
|
+
}
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
this.form.append(button);
|
|
751
|
+
button.click();
|
|
752
|
+
button.remove();
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
/** Returns the associated `<form>` element, if one exists. */
|
|
756
|
+
getForm() {
|
|
757
|
+
return this.form ?? null;
|
|
758
|
+
}
|
|
759
|
+
/** Resets the form, restoring all the control to their default value */
|
|
760
|
+
reset(submitter) {
|
|
761
|
+
this.doAction('reset', submitter);
|
|
762
|
+
}
|
|
763
|
+
/** Submits the form, triggering validation and form data injection. */
|
|
764
|
+
submit(submitter) {
|
|
765
|
+
// Calling form.submit() bypasses the submit event and constraint validation. To prevent this, we can inject a
|
|
766
|
+
// native submit button into the form, "click" it, then remove it to simulate a standard form submission.
|
|
767
|
+
this.doAction('submit', submitter);
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Synchronously sets the form control's validity. Call this when you know the future validity but need to update
|
|
771
|
+
* the host element immediately, i.e. before Lit updates the component in the next update.
|
|
772
|
+
*/
|
|
773
|
+
setValidity(isValid) {
|
|
774
|
+
const host = this.host;
|
|
775
|
+
const hasInteracted = Boolean(userInteractedControls.has(host));
|
|
776
|
+
const required = Boolean(host.required);
|
|
777
|
+
//
|
|
778
|
+
// We're mapping the following "states" to data attributes. In the future, we can use ElementInternals.states to
|
|
779
|
+
// create a similar mapping, but instead of [data-invalid] it will look like :--invalid.
|
|
780
|
+
//
|
|
781
|
+
// See this RFC for more details: https://github.com/shoelace-style/shoelace/issues/1011
|
|
782
|
+
//
|
|
783
|
+
host.toggleAttribute('data-required', required);
|
|
784
|
+
host.toggleAttribute('data-optional', !required);
|
|
785
|
+
host.toggleAttribute('data-invalid', !isValid);
|
|
786
|
+
host.toggleAttribute('data-valid', isValid);
|
|
787
|
+
host.toggleAttribute('data-user-invalid', !isValid && hasInteracted);
|
|
788
|
+
host.toggleAttribute('data-user-valid', isValid && hasInteracted);
|
|
789
|
+
}
|
|
790
|
+
userInteracted() {
|
|
791
|
+
const hasInteracted = Boolean(userInteractedControls.has(this.host));
|
|
792
|
+
return hasInteracted;
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* Updates the form control's validity based on the current value of `host.validity.valid`. Call this when anything
|
|
796
|
+
* that affects constraint validation changes so the component receives the correct validity states.
|
|
797
|
+
*/
|
|
798
|
+
updateValidity() {
|
|
799
|
+
const host = this.host;
|
|
800
|
+
this.setValidity(host.validity.valid);
|
|
801
|
+
}
|
|
802
|
+
/**
|
|
803
|
+
* Dispatches a non-bubbling, cancelable custom event of type `it-invalid`.
|
|
804
|
+
* If the `it-invalid` event will be cancelled then the original `invalid`
|
|
805
|
+
* event (which may have been passed as argument) will also be cancelled.
|
|
806
|
+
* If no original `invalid` event has been passed then the `it-invalid`
|
|
807
|
+
* event will be cancelled before being dispatched.
|
|
808
|
+
*/
|
|
809
|
+
emitInvalidEvent(originalInvalidEvent) {
|
|
810
|
+
const itInvalidEvent = new CustomEvent('it-invalid', {
|
|
811
|
+
bubbles: false,
|
|
812
|
+
composed: false,
|
|
813
|
+
cancelable: true,
|
|
814
|
+
detail: {},
|
|
815
|
+
});
|
|
816
|
+
if (!originalInvalidEvent) {
|
|
817
|
+
itInvalidEvent.preventDefault();
|
|
818
|
+
}
|
|
819
|
+
if (!this.host.dispatchEvent(itInvalidEvent)) {
|
|
820
|
+
originalInvalidEvent?.preventDefault();
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
const translation = {
|
|
826
|
+
$code: 'it',
|
|
827
|
+
$name: 'Italiano',
|
|
828
|
+
$dir: 'ltr',
|
|
829
|
+
validityRequired: 'Questo campo è obbligatorio.',
|
|
830
|
+
validityGroupRequired: "Scegli almeno un'opzione",
|
|
831
|
+
validityPattern: 'Il valore non corrisponde al formato richiesto.',
|
|
832
|
+
validityMinlength: 'Il valore deve essere lungo almeno {minlength} caratteri.',
|
|
833
|
+
validityMaxlength: 'Il valore deve essere lungo al massimo {maxlength} caratteri.',
|
|
834
|
+
};
|
|
835
|
+
|
|
836
|
+
registerTranslation(translation);
|
|
837
|
+
class FormControl extends BaseLocalizedComponent {
|
|
838
|
+
constructor() {
|
|
839
|
+
super(...arguments);
|
|
840
|
+
this.formControlController = new FormControlController(this, {
|
|
841
|
+
assumeInteractionOn: ['it-input', 'it-blur', 'it-change'],
|
|
842
|
+
});
|
|
843
|
+
// TODO: verificare se serve davvero con il fatto che usiamo form-controller
|
|
844
|
+
// static formAssociated = true;
|
|
845
|
+
// @property()
|
|
846
|
+
// internals = this.attachInternals();
|
|
847
|
+
this._touched = false;
|
|
848
|
+
/** The name of the input, submitted as a name/value pair with form data. */
|
|
849
|
+
this.name = '';
|
|
850
|
+
/** The current value of the input, submitted as a name/value pair with form data. */
|
|
851
|
+
this.value = '';
|
|
852
|
+
/** If the input is disabled. */
|
|
853
|
+
this.disabled = false;
|
|
854
|
+
/**
|
|
855
|
+
* By default, form controls are associated with the nearest containing `<form>` element. This attribute allows you
|
|
856
|
+
* to place the form control outside of a form and associate it with the form that has this `id`. The form must be in
|
|
857
|
+
* the same document or shadow root for this to work.
|
|
858
|
+
*/
|
|
859
|
+
this.form = '';
|
|
860
|
+
/** If you implement your custom validation and you won't to trigger default validation */
|
|
861
|
+
this.customValidation = false;
|
|
862
|
+
/** If your input is invalid from your custom validition, set this attribute with message validation */
|
|
863
|
+
this.validationText = '';
|
|
864
|
+
/**
|
|
865
|
+
* Specifies the granularity that the value must adhere to, or the special value `any` which means no stepping is
|
|
866
|
+
* implied, allowing any numeric value. Only applies to date and number input types.
|
|
867
|
+
*/
|
|
868
|
+
this.step = 'any';
|
|
869
|
+
/** The input's minimum length. */
|
|
870
|
+
this.minlength = -1;
|
|
871
|
+
/** The input's maximum length. */
|
|
872
|
+
this.maxlength = -1;
|
|
873
|
+
/** If the input is required. */
|
|
874
|
+
this.required = false;
|
|
875
|
+
/* For grouped input, like checkbox-group */
|
|
876
|
+
this.isInGroup = false;
|
|
877
|
+
this.validationMessage = '';
|
|
878
|
+
}
|
|
879
|
+
/** Gets the validity state object */
|
|
880
|
+
get validity() {
|
|
881
|
+
return this.inputElement?.validity;
|
|
882
|
+
}
|
|
883
|
+
/** Gets the associated form, if one exists. */
|
|
884
|
+
getForm() {
|
|
885
|
+
return this.formControlController.getForm();
|
|
886
|
+
}
|
|
887
|
+
// Form validation methods
|
|
888
|
+
checkValidity() {
|
|
889
|
+
const inputValid = this.inputElement?.checkValidity() ?? true; // this.inputElement.checkValidity() è la validazione del browser
|
|
890
|
+
return inputValid;
|
|
891
|
+
}
|
|
892
|
+
/** Checks for validity and shows the browser's validation message if the control is invalid. */
|
|
893
|
+
reportValidity() {
|
|
894
|
+
// const ret = this.inputElement.checkValidity();
|
|
895
|
+
const ret = this.checkValidity(); // chiama la checkValidity, che se è stata overridata chiama quella
|
|
896
|
+
this.handleValidationMessages();
|
|
897
|
+
return ret; // this.inputElement.reportValidity();
|
|
898
|
+
}
|
|
899
|
+
/** Sets a custom validation message. Pass an empty string to restore validity. */
|
|
900
|
+
setCustomValidity(message) {
|
|
901
|
+
this.inputElement.setCustomValidity(message);
|
|
902
|
+
this.validationMessage = this.inputElement.validationMessage;
|
|
903
|
+
this.formControlController.updateValidity();
|
|
904
|
+
}
|
|
905
|
+
// Handlers
|
|
906
|
+
_handleReady() {
|
|
907
|
+
requestAnimationFrame(() => {
|
|
908
|
+
this.dispatchEvent(new CustomEvent('it-input-ready', { bubbles: true, detail: { el: this.inputElement } }));
|
|
909
|
+
});
|
|
910
|
+
}
|
|
911
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
912
|
+
_handleInput(e) {
|
|
913
|
+
this.handleValidationMessages();
|
|
914
|
+
this.dispatchEvent(new CustomEvent('it-input', {
|
|
915
|
+
detail: { value: this.inputElement.value, el: this.inputElement },
|
|
916
|
+
bubbles: true,
|
|
917
|
+
composed: true,
|
|
918
|
+
}));
|
|
919
|
+
}
|
|
920
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
921
|
+
_handleBlur(e) {
|
|
922
|
+
this._touched = true;
|
|
923
|
+
this.handleValidationMessages();
|
|
924
|
+
this.dispatchEvent(new FocusEvent('it-blur', { bubbles: true, composed: true }));
|
|
925
|
+
}
|
|
926
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
927
|
+
_handleFocus(e) {
|
|
928
|
+
this.dispatchEvent(new FocusEvent('it-focus', { bubbles: true, composed: true }));
|
|
929
|
+
}
|
|
930
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
931
|
+
_handleClick(e) {
|
|
932
|
+
this.dispatchEvent(new MouseEvent('it-click', { bubbles: true, composed: true }));
|
|
933
|
+
}
|
|
934
|
+
/*
|
|
935
|
+
Override default browser validation messages
|
|
936
|
+
*/
|
|
937
|
+
handleValidationMessages() {
|
|
938
|
+
if (!this.customValidation) {
|
|
939
|
+
const _v = this.inputElement.validity;
|
|
940
|
+
const isRequiredHandledByGroup = this.isInGroup === true;
|
|
941
|
+
if (_v.valueMissing && !isRequiredHandledByGroup) {
|
|
942
|
+
this.setCustomValidity(this.$t('validityRequired'));
|
|
943
|
+
}
|
|
944
|
+
else if (_v.patternMismatch) {
|
|
945
|
+
this.setCustomValidity(this.$t('validityPattern'));
|
|
946
|
+
}
|
|
947
|
+
else if (_v.tooShort) {
|
|
948
|
+
this.setCustomValidity(this.$t('validityMinlength').replace('{minlength}', this.minlength.toString()));
|
|
949
|
+
}
|
|
950
|
+
else if (_v.tooLong) {
|
|
951
|
+
this.setCustomValidity(this.$t('validityMaxlength').replace('{maxlength}', this.maxlength.toString()));
|
|
952
|
+
}
|
|
953
|
+
else {
|
|
954
|
+
/* nothing. Usa il messaggio di errore della validazione
|
|
955
|
+
di default del browser per altri errori di validità come:
|
|
956
|
+
- typeMismatch
|
|
957
|
+
- rangeUnderflow
|
|
958
|
+
- rangeOverflow
|
|
959
|
+
- stepMismatch
|
|
960
|
+
- badInput */
|
|
961
|
+
const otherConstraintErrors = _v.typeMismatch || _v.rangeUnderflow || _v.rangeOverflow || _v.stepMismatch || _v.badInput;
|
|
962
|
+
if (!otherConstraintErrors) {
|
|
963
|
+
this.setCustomValidity('');
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
this.validationMessage = this.inputElement.validationMessage;
|
|
968
|
+
}
|
|
969
|
+
_handleInvalid(event) {
|
|
970
|
+
this.formControlController.setValidity(false);
|
|
971
|
+
this.formControlController.emitInvalidEvent(event);
|
|
972
|
+
}
|
|
973
|
+
_handleChange(e) {
|
|
974
|
+
const target = e.target;
|
|
975
|
+
let value;
|
|
976
|
+
if (target instanceof HTMLInputElement) {
|
|
977
|
+
switch (target.type) {
|
|
978
|
+
case 'checkbox':
|
|
979
|
+
case 'radio':
|
|
980
|
+
value = target.checked;
|
|
981
|
+
break;
|
|
982
|
+
case 'file':
|
|
983
|
+
value = target.files; // FileList
|
|
984
|
+
break;
|
|
985
|
+
default:
|
|
986
|
+
value = target.value;
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
else if (target instanceof HTMLSelectElement) {
|
|
990
|
+
if (target.multiple) {
|
|
991
|
+
value = Array.from(target.selectedOptions).map((o) => o.value);
|
|
992
|
+
}
|
|
993
|
+
else {
|
|
994
|
+
value = target.value;
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
else {
|
|
998
|
+
// textarea o altri input con value
|
|
999
|
+
value = target.value;
|
|
1000
|
+
}
|
|
1001
|
+
this.dispatchEvent(new CustomEvent('it-change', {
|
|
1002
|
+
detail: { value, el: target },
|
|
1003
|
+
bubbles: true,
|
|
1004
|
+
composed: true,
|
|
1005
|
+
}));
|
|
1006
|
+
}
|
|
1007
|
+
updated(changedProperties) {
|
|
1008
|
+
super.updated?.(changedProperties);
|
|
1009
|
+
if (this.customValidation) {
|
|
1010
|
+
this.setCustomValidity(this.validationText ?? '');
|
|
1011
|
+
}
|
|
1012
|
+
else if (this.formControlController.userInteracted()) {
|
|
1013
|
+
this.formControlController.updateValidity();
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
__decorate([
|
|
1018
|
+
state(),
|
|
1019
|
+
__metadata("design:type", Object)
|
|
1020
|
+
], FormControl.prototype, "_touched", void 0);
|
|
1021
|
+
__decorate([
|
|
1022
|
+
query('.it-form__control'),
|
|
1023
|
+
__metadata("design:type", HTMLInputElement)
|
|
1024
|
+
], FormControl.prototype, "inputElement", void 0);
|
|
1025
|
+
__decorate([
|
|
1026
|
+
property({ type: String, reflect: true }) // from FormControl
|
|
1027
|
+
,
|
|
1028
|
+
__metadata("design:type", Object)
|
|
1029
|
+
], FormControl.prototype, "name", void 0);
|
|
1030
|
+
__decorate([
|
|
1031
|
+
property({ reflect: true }),
|
|
1032
|
+
__metadata("design:type", Object)
|
|
1033
|
+
], FormControl.prototype, "value", void 0);
|
|
1034
|
+
__decorate([
|
|
1035
|
+
property({ type: Boolean, reflect: true }) // from FormControl
|
|
1036
|
+
,
|
|
1037
|
+
__metadata("design:type", Object)
|
|
1038
|
+
], FormControl.prototype, "disabled", void 0);
|
|
1039
|
+
__decorate([
|
|
1040
|
+
property({ reflect: true, type: String }),
|
|
1041
|
+
__metadata("design:type", Object)
|
|
1042
|
+
], FormControl.prototype, "form", void 0);
|
|
1043
|
+
__decorate([
|
|
1044
|
+
property({ type: Boolean, reflect: true, attribute: 'custom-validation' }),
|
|
1045
|
+
__metadata("design:type", Object)
|
|
1046
|
+
], FormControl.prototype, "customValidation", void 0);
|
|
1047
|
+
__decorate([
|
|
1048
|
+
property({ attribute: 'validity-message', reflect: true }),
|
|
1049
|
+
__metadata("design:type", String)
|
|
1050
|
+
], FormControl.prototype, "validationText", void 0);
|
|
1051
|
+
__decorate([
|
|
1052
|
+
property(),
|
|
1053
|
+
__metadata("design:type", String)
|
|
1054
|
+
], FormControl.prototype, "pattern", void 0);
|
|
1055
|
+
__decorate([
|
|
1056
|
+
property(),
|
|
1057
|
+
__metadata("design:type", Object)
|
|
1058
|
+
], FormControl.prototype, "min", void 0);
|
|
1059
|
+
__decorate([
|
|
1060
|
+
property(),
|
|
1061
|
+
__metadata("design:type", Object)
|
|
1062
|
+
], FormControl.prototype, "max", void 0);
|
|
1063
|
+
__decorate([
|
|
1064
|
+
property(),
|
|
1065
|
+
__metadata("design:type", Object)
|
|
1066
|
+
], FormControl.prototype, "step", void 0);
|
|
1067
|
+
__decorate([
|
|
1068
|
+
property({ type: Number }),
|
|
1069
|
+
__metadata("design:type", Object)
|
|
1070
|
+
], FormControl.prototype, "minlength", void 0);
|
|
1071
|
+
__decorate([
|
|
1072
|
+
property({ type: Number }),
|
|
1073
|
+
__metadata("design:type", Object)
|
|
1074
|
+
], FormControl.prototype, "maxlength", void 0);
|
|
1075
|
+
__decorate([
|
|
1076
|
+
property({ type: Boolean, reflect: true }) // from FormControl
|
|
1077
|
+
,
|
|
1078
|
+
__metadata("design:type", Object)
|
|
1079
|
+
], FormControl.prototype, "required", void 0);
|
|
1080
|
+
__decorate([
|
|
1081
|
+
property({ type: Boolean }),
|
|
1082
|
+
__metadata("design:type", Object)
|
|
1083
|
+
], FormControl.prototype, "isInGroup", void 0);
|
|
1084
|
+
__decorate([
|
|
1085
|
+
state(),
|
|
1086
|
+
__metadata("design:type", Object)
|
|
1087
|
+
], FormControl.prototype, "validationMessage", void 0);
|
|
1088
|
+
|
|
1089
|
+
if (typeof window !== 'undefined') {
|
|
1090
|
+
window._itAnalytics = window._itAnalytics || {};
|
|
1091
|
+
window._itAnalytics = {
|
|
1092
|
+
...window._itAnalytics,
|
|
1093
|
+
version: '1.0.0-alpha.10',
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
/**
|
|
1098
|
+
* Custom positioning reference element.
|
|
1099
|
+
* @see https://floating-ui.com/docs/virtual-elements
|
|
1100
|
+
*/
|
|
1101
|
+
|
|
1102
|
+
const min = Math.min;
|
|
1103
|
+
const max = Math.max;
|
|
1104
|
+
const round = Math.round;
|
|
1105
|
+
const floor = Math.floor;
|
|
1106
|
+
const createCoords = v => ({
|
|
1107
|
+
x: v,
|
|
1108
|
+
y: v
|
|
1109
|
+
});
|
|
1110
|
+
const oppositeSideMap = {
|
|
1111
|
+
left: 'right',
|
|
1112
|
+
right: 'left',
|
|
1113
|
+
bottom: 'top',
|
|
1114
|
+
top: 'bottom'
|
|
1115
|
+
};
|
|
1116
|
+
const oppositeAlignmentMap = {
|
|
1117
|
+
start: 'end',
|
|
1118
|
+
end: 'start'
|
|
1119
|
+
};
|
|
1120
|
+
function clamp(start, value, end) {
|
|
1121
|
+
return max(start, min(value, end));
|
|
1122
|
+
}
|
|
1123
|
+
function evaluate(value, param) {
|
|
1124
|
+
return typeof value === 'function' ? value(param) : value;
|
|
1125
|
+
}
|
|
1126
|
+
function getSide(placement) {
|
|
1127
|
+
return placement.split('-')[0];
|
|
1128
|
+
}
|
|
1129
|
+
function getAlignment(placement) {
|
|
1130
|
+
return placement.split('-')[1];
|
|
1131
|
+
}
|
|
1132
|
+
function getOppositeAxis(axis) {
|
|
1133
|
+
return axis === 'x' ? 'y' : 'x';
|
|
1134
|
+
}
|
|
1135
|
+
function getAxisLength(axis) {
|
|
1136
|
+
return axis === 'y' ? 'height' : 'width';
|
|
1137
|
+
}
|
|
1138
|
+
const yAxisSides = /*#__PURE__*/new Set(['top', 'bottom']);
|
|
1139
|
+
function getSideAxis(placement) {
|
|
1140
|
+
return yAxisSides.has(getSide(placement)) ? 'y' : 'x';
|
|
1141
|
+
}
|
|
1142
|
+
function getAlignmentAxis(placement) {
|
|
1143
|
+
return getOppositeAxis(getSideAxis(placement));
|
|
1144
|
+
}
|
|
1145
|
+
function getAlignmentSides(placement, rects, rtl) {
|
|
1146
|
+
if (rtl === void 0) {
|
|
1147
|
+
rtl = false;
|
|
1148
|
+
}
|
|
1149
|
+
const alignment = getAlignment(placement);
|
|
1150
|
+
const alignmentAxis = getAlignmentAxis(placement);
|
|
1151
|
+
const length = getAxisLength(alignmentAxis);
|
|
1152
|
+
let mainAlignmentSide = alignmentAxis === 'x' ? alignment === (rtl ? 'end' : 'start') ? 'right' : 'left' : alignment === 'start' ? 'bottom' : 'top';
|
|
1153
|
+
if (rects.reference[length] > rects.floating[length]) {
|
|
1154
|
+
mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
|
|
1155
|
+
}
|
|
1156
|
+
return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
|
|
1157
|
+
}
|
|
1158
|
+
function getExpandedPlacements(placement) {
|
|
1159
|
+
const oppositePlacement = getOppositePlacement(placement);
|
|
1160
|
+
return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
|
|
1161
|
+
}
|
|
1162
|
+
function getOppositeAlignmentPlacement(placement) {
|
|
1163
|
+
return placement.replace(/start|end/g, alignment => oppositeAlignmentMap[alignment]);
|
|
1164
|
+
}
|
|
1165
|
+
const lrPlacement = ['left', 'right'];
|
|
1166
|
+
const rlPlacement = ['right', 'left'];
|
|
1167
|
+
const tbPlacement = ['top', 'bottom'];
|
|
1168
|
+
const btPlacement = ['bottom', 'top'];
|
|
1169
|
+
function getSideList(side, isStart, rtl) {
|
|
1170
|
+
switch (side) {
|
|
1171
|
+
case 'top':
|
|
1172
|
+
case 'bottom':
|
|
1173
|
+
if (rtl) return isStart ? rlPlacement : lrPlacement;
|
|
1174
|
+
return isStart ? lrPlacement : rlPlacement;
|
|
1175
|
+
case 'left':
|
|
1176
|
+
case 'right':
|
|
1177
|
+
return isStart ? tbPlacement : btPlacement;
|
|
1178
|
+
default:
|
|
1179
|
+
return [];
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
|
|
1183
|
+
const alignment = getAlignment(placement);
|
|
1184
|
+
let list = getSideList(getSide(placement), direction === 'start', rtl);
|
|
1185
|
+
if (alignment) {
|
|
1186
|
+
list = list.map(side => side + "-" + alignment);
|
|
1187
|
+
if (flipAlignment) {
|
|
1188
|
+
list = list.concat(list.map(getOppositeAlignmentPlacement));
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
return list;
|
|
1192
|
+
}
|
|
1193
|
+
function getOppositePlacement(placement) {
|
|
1194
|
+
return placement.replace(/left|right|bottom|top/g, side => oppositeSideMap[side]);
|
|
1195
|
+
}
|
|
1196
|
+
function expandPaddingObject(padding) {
|
|
1197
|
+
return {
|
|
1198
|
+
top: 0,
|
|
1199
|
+
right: 0,
|
|
1200
|
+
bottom: 0,
|
|
1201
|
+
left: 0,
|
|
1202
|
+
...padding
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
function getPaddingObject(padding) {
|
|
1206
|
+
return typeof padding !== 'number' ? expandPaddingObject(padding) : {
|
|
1207
|
+
top: padding,
|
|
1208
|
+
right: padding,
|
|
1209
|
+
bottom: padding,
|
|
1210
|
+
left: padding
|
|
1211
|
+
};
|
|
1212
|
+
}
|
|
1213
|
+
function rectToClientRect(rect) {
|
|
1214
|
+
const {
|
|
1215
|
+
x,
|
|
1216
|
+
y,
|
|
1217
|
+
width,
|
|
1218
|
+
height
|
|
1219
|
+
} = rect;
|
|
1220
|
+
return {
|
|
1221
|
+
width,
|
|
1222
|
+
height,
|
|
1223
|
+
top: y,
|
|
1224
|
+
left: x,
|
|
1225
|
+
right: x + width,
|
|
1226
|
+
bottom: y + height,
|
|
1227
|
+
x,
|
|
1228
|
+
y
|
|
1229
|
+
};
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
function computeCoordsFromPlacement(_ref, placement, rtl) {
|
|
1233
|
+
let {
|
|
1234
|
+
reference,
|
|
1235
|
+
floating
|
|
1236
|
+
} = _ref;
|
|
1237
|
+
const sideAxis = getSideAxis(placement);
|
|
1238
|
+
const alignmentAxis = getAlignmentAxis(placement);
|
|
1239
|
+
const alignLength = getAxisLength(alignmentAxis);
|
|
1240
|
+
const side = getSide(placement);
|
|
1241
|
+
const isVertical = sideAxis === 'y';
|
|
1242
|
+
const commonX = reference.x + reference.width / 2 - floating.width / 2;
|
|
1243
|
+
const commonY = reference.y + reference.height / 2 - floating.height / 2;
|
|
1244
|
+
const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
|
|
1245
|
+
let coords;
|
|
1246
|
+
switch (side) {
|
|
1247
|
+
case 'top':
|
|
1248
|
+
coords = {
|
|
1249
|
+
x: commonX,
|
|
1250
|
+
y: reference.y - floating.height
|
|
1251
|
+
};
|
|
1252
|
+
break;
|
|
1253
|
+
case 'bottom':
|
|
1254
|
+
coords = {
|
|
1255
|
+
x: commonX,
|
|
1256
|
+
y: reference.y + reference.height
|
|
1257
|
+
};
|
|
1258
|
+
break;
|
|
1259
|
+
case 'right':
|
|
1260
|
+
coords = {
|
|
1261
|
+
x: reference.x + reference.width,
|
|
1262
|
+
y: commonY
|
|
1263
|
+
};
|
|
1264
|
+
break;
|
|
1265
|
+
case 'left':
|
|
1266
|
+
coords = {
|
|
1267
|
+
x: reference.x - floating.width,
|
|
1268
|
+
y: commonY
|
|
1269
|
+
};
|
|
1270
|
+
break;
|
|
1271
|
+
default:
|
|
1272
|
+
coords = {
|
|
1273
|
+
x: reference.x,
|
|
1274
|
+
y: reference.y
|
|
1275
|
+
};
|
|
1276
|
+
}
|
|
1277
|
+
switch (getAlignment(placement)) {
|
|
1278
|
+
case 'start':
|
|
1279
|
+
coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
|
|
1280
|
+
break;
|
|
1281
|
+
case 'end':
|
|
1282
|
+
coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
|
|
1283
|
+
break;
|
|
1284
|
+
}
|
|
1285
|
+
return coords;
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
/**
|
|
1289
|
+
* Resolves with an object of overflow side offsets that determine how much the
|
|
1290
|
+
* element is overflowing a given clipping boundary on each side.
|
|
1291
|
+
* - positive = overflowing the boundary by that number of pixels
|
|
1292
|
+
* - negative = how many pixels left before it will overflow
|
|
1293
|
+
* - 0 = lies flush with the boundary
|
|
1294
|
+
* @see https://floating-ui.com/docs/detectOverflow
|
|
1295
|
+
*/
|
|
1296
|
+
async function detectOverflow(state, options) {
|
|
1297
|
+
var _await$platform$isEle;
|
|
1298
|
+
if (options === void 0) {
|
|
1299
|
+
options = {};
|
|
1300
|
+
}
|
|
1301
|
+
const {
|
|
1302
|
+
x,
|
|
1303
|
+
y,
|
|
1304
|
+
platform,
|
|
1305
|
+
rects,
|
|
1306
|
+
elements,
|
|
1307
|
+
strategy
|
|
1308
|
+
} = state;
|
|
1309
|
+
const {
|
|
1310
|
+
boundary = 'clippingAncestors',
|
|
1311
|
+
rootBoundary = 'viewport',
|
|
1312
|
+
elementContext = 'floating',
|
|
1313
|
+
altBoundary = false,
|
|
1314
|
+
padding = 0
|
|
1315
|
+
} = evaluate(options, state);
|
|
1316
|
+
const paddingObject = getPaddingObject(padding);
|
|
1317
|
+
const altContext = elementContext === 'floating' ? 'reference' : 'floating';
|
|
1318
|
+
const element = elements[altBoundary ? altContext : elementContext];
|
|
1319
|
+
const clippingClientRect = rectToClientRect(await platform.getClippingRect({
|
|
1320
|
+
element: ((_await$platform$isEle = await (platform.isElement == null ? void 0 : platform.isElement(element))) != null ? _await$platform$isEle : true) ? element : element.contextElement || (await (platform.getDocumentElement == null ? void 0 : platform.getDocumentElement(elements.floating))),
|
|
1321
|
+
boundary,
|
|
1322
|
+
rootBoundary,
|
|
1323
|
+
strategy
|
|
1324
|
+
}));
|
|
1325
|
+
const rect = elementContext === 'floating' ? {
|
|
1326
|
+
x,
|
|
1327
|
+
y,
|
|
1328
|
+
width: rects.floating.width,
|
|
1329
|
+
height: rects.floating.height
|
|
1330
|
+
} : rects.reference;
|
|
1331
|
+
const offsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating));
|
|
1332
|
+
const offsetScale = (await (platform.isElement == null ? void 0 : platform.isElement(offsetParent))) ? (await (platform.getScale == null ? void 0 : platform.getScale(offsetParent))) || {
|
|
1333
|
+
x: 1,
|
|
1334
|
+
y: 1
|
|
1335
|
+
} : {
|
|
1336
|
+
x: 1,
|
|
1337
|
+
y: 1
|
|
1338
|
+
};
|
|
1339
|
+
const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
|
|
1340
|
+
elements,
|
|
1341
|
+
rect,
|
|
1342
|
+
offsetParent,
|
|
1343
|
+
strategy
|
|
1344
|
+
}) : rect);
|
|
1345
|
+
return {
|
|
1346
|
+
top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
|
|
1347
|
+
bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
|
|
1348
|
+
left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
|
|
1349
|
+
right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
|
|
1350
|
+
};
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
/**
|
|
1354
|
+
* Computes the `x` and `y` coordinates that will place the floating element
|
|
1355
|
+
* next to a given reference element.
|
|
1356
|
+
*
|
|
1357
|
+
* This export does not have any `platform` interface logic. You will need to
|
|
1358
|
+
* write one for the platform you are using Floating UI with.
|
|
1359
|
+
*/
|
|
1360
|
+
const computePosition$1 = async (reference, floating, config) => {
|
|
1361
|
+
const {
|
|
1362
|
+
placement = 'bottom',
|
|
1363
|
+
strategy = 'absolute',
|
|
1364
|
+
middleware = [],
|
|
1365
|
+
platform
|
|
1366
|
+
} = config;
|
|
1367
|
+
const validMiddleware = middleware.filter(Boolean);
|
|
1368
|
+
const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(floating));
|
|
1369
|
+
let rects = await platform.getElementRects({
|
|
1370
|
+
reference,
|
|
1371
|
+
floating,
|
|
1372
|
+
strategy
|
|
1373
|
+
});
|
|
1374
|
+
let {
|
|
1375
|
+
x,
|
|
1376
|
+
y
|
|
1377
|
+
} = computeCoordsFromPlacement(rects, placement, rtl);
|
|
1378
|
+
let statefulPlacement = placement;
|
|
1379
|
+
let middlewareData = {};
|
|
1380
|
+
let resetCount = 0;
|
|
1381
|
+
for (let i = 0; i < validMiddleware.length; i++) {
|
|
1382
|
+
var _platform$detectOverf;
|
|
1383
|
+
const {
|
|
1384
|
+
name,
|
|
1385
|
+
fn
|
|
1386
|
+
} = validMiddleware[i];
|
|
1387
|
+
const {
|
|
1388
|
+
x: nextX,
|
|
1389
|
+
y: nextY,
|
|
1390
|
+
data,
|
|
1391
|
+
reset
|
|
1392
|
+
} = await fn({
|
|
1393
|
+
x,
|
|
1394
|
+
y,
|
|
1395
|
+
initialPlacement: placement,
|
|
1396
|
+
placement: statefulPlacement,
|
|
1397
|
+
strategy,
|
|
1398
|
+
middlewareData,
|
|
1399
|
+
rects,
|
|
1400
|
+
platform: {
|
|
1401
|
+
...platform,
|
|
1402
|
+
detectOverflow: (_platform$detectOverf = platform.detectOverflow) != null ? _platform$detectOverf : detectOverflow
|
|
1403
|
+
},
|
|
1404
|
+
elements: {
|
|
1405
|
+
reference,
|
|
1406
|
+
floating
|
|
1407
|
+
}
|
|
1408
|
+
});
|
|
1409
|
+
x = nextX != null ? nextX : x;
|
|
1410
|
+
y = nextY != null ? nextY : y;
|
|
1411
|
+
middlewareData = {
|
|
1412
|
+
...middlewareData,
|
|
1413
|
+
[name]: {
|
|
1414
|
+
...middlewareData[name],
|
|
1415
|
+
...data
|
|
1416
|
+
}
|
|
1417
|
+
};
|
|
1418
|
+
if (reset && resetCount <= 50) {
|
|
1419
|
+
resetCount++;
|
|
1420
|
+
if (typeof reset === 'object') {
|
|
1421
|
+
if (reset.placement) {
|
|
1422
|
+
statefulPlacement = reset.placement;
|
|
1423
|
+
}
|
|
1424
|
+
if (reset.rects) {
|
|
1425
|
+
rects = reset.rects === true ? await platform.getElementRects({
|
|
1426
|
+
reference,
|
|
1427
|
+
floating,
|
|
1428
|
+
strategy
|
|
1429
|
+
}) : reset.rects;
|
|
1430
|
+
}
|
|
1431
|
+
({
|
|
1432
|
+
x,
|
|
1433
|
+
y
|
|
1434
|
+
} = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
|
|
1435
|
+
}
|
|
1436
|
+
i = -1;
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
return {
|
|
1440
|
+
x,
|
|
1441
|
+
y,
|
|
1442
|
+
placement: statefulPlacement,
|
|
1443
|
+
strategy,
|
|
1444
|
+
middlewareData
|
|
1445
|
+
};
|
|
1446
|
+
};
|
|
1447
|
+
|
|
1448
|
+
/**
|
|
1449
|
+
* Provides data to position an inner element of the floating element so that it
|
|
1450
|
+
* appears centered to the reference element.
|
|
1451
|
+
* @see https://floating-ui.com/docs/arrow
|
|
1452
|
+
*/
|
|
1453
|
+
const arrow$1 = options => ({
|
|
1454
|
+
name: 'arrow',
|
|
1455
|
+
options,
|
|
1456
|
+
async fn(state) {
|
|
1457
|
+
const {
|
|
1458
|
+
x,
|
|
1459
|
+
y,
|
|
1460
|
+
placement,
|
|
1461
|
+
rects,
|
|
1462
|
+
platform,
|
|
1463
|
+
elements,
|
|
1464
|
+
middlewareData
|
|
1465
|
+
} = state;
|
|
1466
|
+
// Since `element` is required, we don't Partial<> the type.
|
|
1467
|
+
const {
|
|
1468
|
+
element,
|
|
1469
|
+
padding = 0
|
|
1470
|
+
} = evaluate(options, state) || {};
|
|
1471
|
+
if (element == null) {
|
|
1472
|
+
return {};
|
|
1473
|
+
}
|
|
1474
|
+
const paddingObject = getPaddingObject(padding);
|
|
1475
|
+
const coords = {
|
|
1476
|
+
x,
|
|
1477
|
+
y
|
|
1478
|
+
};
|
|
1479
|
+
const axis = getAlignmentAxis(placement);
|
|
1480
|
+
const length = getAxisLength(axis);
|
|
1481
|
+
const arrowDimensions = await platform.getDimensions(element);
|
|
1482
|
+
const isYAxis = axis === 'y';
|
|
1483
|
+
const minProp = isYAxis ? 'top' : 'left';
|
|
1484
|
+
const maxProp = isYAxis ? 'bottom' : 'right';
|
|
1485
|
+
const clientProp = isYAxis ? 'clientHeight' : 'clientWidth';
|
|
1486
|
+
const endDiff = rects.reference[length] + rects.reference[axis] - coords[axis] - rects.floating[length];
|
|
1487
|
+
const startDiff = coords[axis] - rects.reference[axis];
|
|
1488
|
+
const arrowOffsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(element));
|
|
1489
|
+
let clientSize = arrowOffsetParent ? arrowOffsetParent[clientProp] : 0;
|
|
1490
|
+
|
|
1491
|
+
// DOM platform can return `window` as the `offsetParent`.
|
|
1492
|
+
if (!clientSize || !(await (platform.isElement == null ? void 0 : platform.isElement(arrowOffsetParent)))) {
|
|
1493
|
+
clientSize = elements.floating[clientProp] || rects.floating[length];
|
|
1494
|
+
}
|
|
1495
|
+
const centerToReference = endDiff / 2 - startDiff / 2;
|
|
1496
|
+
|
|
1497
|
+
// If the padding is large enough that it causes the arrow to no longer be
|
|
1498
|
+
// centered, modify the padding so that it is centered.
|
|
1499
|
+
const largestPossiblePadding = clientSize / 2 - arrowDimensions[length] / 2 - 1;
|
|
1500
|
+
const minPadding = min(paddingObject[minProp], largestPossiblePadding);
|
|
1501
|
+
const maxPadding = min(paddingObject[maxProp], largestPossiblePadding);
|
|
1502
|
+
|
|
1503
|
+
// Make sure the arrow doesn't overflow the floating element if the center
|
|
1504
|
+
// point is outside the floating element's bounds.
|
|
1505
|
+
const min$1 = minPadding;
|
|
1506
|
+
const max = clientSize - arrowDimensions[length] - maxPadding;
|
|
1507
|
+
const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
|
|
1508
|
+
const offset = clamp(min$1, center, max);
|
|
1509
|
+
|
|
1510
|
+
// If the reference is small enough that the arrow's padding causes it to
|
|
1511
|
+
// to point to nothing for an aligned placement, adjust the offset of the
|
|
1512
|
+
// floating element itself. To ensure `shift()` continues to take action,
|
|
1513
|
+
// a single reset is performed when this is true.
|
|
1514
|
+
const shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center !== offset && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;
|
|
1515
|
+
const alignmentOffset = shouldAddOffset ? center < min$1 ? center - min$1 : center - max : 0;
|
|
1516
|
+
return {
|
|
1517
|
+
[axis]: coords[axis] + alignmentOffset,
|
|
1518
|
+
data: {
|
|
1519
|
+
[axis]: offset,
|
|
1520
|
+
centerOffset: center - offset - alignmentOffset,
|
|
1521
|
+
...(shouldAddOffset && {
|
|
1522
|
+
alignmentOffset
|
|
1523
|
+
})
|
|
1524
|
+
},
|
|
1525
|
+
reset: shouldAddOffset
|
|
1526
|
+
};
|
|
1527
|
+
}
|
|
1528
|
+
});
|
|
1529
|
+
|
|
1530
|
+
/**
|
|
1531
|
+
* Optimizes the visibility of the floating element by flipping the `placement`
|
|
1532
|
+
* in order to keep it in view when the preferred placement(s) will overflow the
|
|
1533
|
+
* clipping boundary. Alternative to `autoPlacement`.
|
|
1534
|
+
* @see https://floating-ui.com/docs/flip
|
|
1535
|
+
*/
|
|
1536
|
+
const flip$1 = function (options) {
|
|
1537
|
+
if (options === void 0) {
|
|
1538
|
+
options = {};
|
|
1539
|
+
}
|
|
1540
|
+
return {
|
|
1541
|
+
name: 'flip',
|
|
1542
|
+
options,
|
|
1543
|
+
async fn(state) {
|
|
1544
|
+
var _middlewareData$arrow, _middlewareData$flip;
|
|
1545
|
+
const {
|
|
1546
|
+
placement,
|
|
1547
|
+
middlewareData,
|
|
1548
|
+
rects,
|
|
1549
|
+
initialPlacement,
|
|
1550
|
+
platform,
|
|
1551
|
+
elements
|
|
1552
|
+
} = state;
|
|
1553
|
+
const {
|
|
1554
|
+
mainAxis: checkMainAxis = true,
|
|
1555
|
+
crossAxis: checkCrossAxis = true,
|
|
1556
|
+
fallbackPlacements: specifiedFallbackPlacements,
|
|
1557
|
+
fallbackStrategy = 'bestFit',
|
|
1558
|
+
fallbackAxisSideDirection = 'none',
|
|
1559
|
+
flipAlignment = true,
|
|
1560
|
+
...detectOverflowOptions
|
|
1561
|
+
} = evaluate(options, state);
|
|
1562
|
+
|
|
1563
|
+
// If a reset by the arrow was caused due to an alignment offset being
|
|
1564
|
+
// added, we should skip any logic now since `flip()` has already done its
|
|
1565
|
+
// work.
|
|
1566
|
+
// https://github.com/floating-ui/floating-ui/issues/2549#issuecomment-1719601643
|
|
1567
|
+
if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
|
|
1568
|
+
return {};
|
|
1569
|
+
}
|
|
1570
|
+
const side = getSide(placement);
|
|
1571
|
+
const initialSideAxis = getSideAxis(initialPlacement);
|
|
1572
|
+
const isBasePlacement = getSide(initialPlacement) === initialPlacement;
|
|
1573
|
+
const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
|
|
1574
|
+
const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
|
|
1575
|
+
const hasFallbackAxisSideDirection = fallbackAxisSideDirection !== 'none';
|
|
1576
|
+
if (!specifiedFallbackPlacements && hasFallbackAxisSideDirection) {
|
|
1577
|
+
fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
|
|
1578
|
+
}
|
|
1579
|
+
const placements = [initialPlacement, ...fallbackPlacements];
|
|
1580
|
+
const overflow = await platform.detectOverflow(state, detectOverflowOptions);
|
|
1581
|
+
const overflows = [];
|
|
1582
|
+
let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
|
|
1583
|
+
if (checkMainAxis) {
|
|
1584
|
+
overflows.push(overflow[side]);
|
|
1585
|
+
}
|
|
1586
|
+
if (checkCrossAxis) {
|
|
1587
|
+
const sides = getAlignmentSides(placement, rects, rtl);
|
|
1588
|
+
overflows.push(overflow[sides[0]], overflow[sides[1]]);
|
|
1589
|
+
}
|
|
1590
|
+
overflowsData = [...overflowsData, {
|
|
1591
|
+
placement,
|
|
1592
|
+
overflows
|
|
1593
|
+
}];
|
|
1594
|
+
|
|
1595
|
+
// One or more sides is overflowing.
|
|
1596
|
+
if (!overflows.every(side => side <= 0)) {
|
|
1597
|
+
var _middlewareData$flip2, _overflowsData$filter;
|
|
1598
|
+
const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
|
|
1599
|
+
const nextPlacement = placements[nextIndex];
|
|
1600
|
+
if (nextPlacement) {
|
|
1601
|
+
const ignoreCrossAxisOverflow = checkCrossAxis === 'alignment' ? initialSideAxis !== getSideAxis(nextPlacement) : false;
|
|
1602
|
+
if (!ignoreCrossAxisOverflow ||
|
|
1603
|
+
// We leave the current main axis only if every placement on that axis
|
|
1604
|
+
// overflows the main axis.
|
|
1605
|
+
overflowsData.every(d => getSideAxis(d.placement) === initialSideAxis ? d.overflows[0] > 0 : true)) {
|
|
1606
|
+
// Try next placement and re-run the lifecycle.
|
|
1607
|
+
return {
|
|
1608
|
+
data: {
|
|
1609
|
+
index: nextIndex,
|
|
1610
|
+
overflows: overflowsData
|
|
1611
|
+
},
|
|
1612
|
+
reset: {
|
|
1613
|
+
placement: nextPlacement
|
|
1614
|
+
}
|
|
1615
|
+
};
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1619
|
+
// First, find the candidates that fit on the mainAxis side of overflow,
|
|
1620
|
+
// then find the placement that fits the best on the main crossAxis side.
|
|
1621
|
+
let resetPlacement = (_overflowsData$filter = overflowsData.filter(d => d.overflows[0] <= 0).sort((a, b) => a.overflows[1] - b.overflows[1])[0]) == null ? void 0 : _overflowsData$filter.placement;
|
|
1622
|
+
|
|
1623
|
+
// Otherwise fallback.
|
|
1624
|
+
if (!resetPlacement) {
|
|
1625
|
+
switch (fallbackStrategy) {
|
|
1626
|
+
case 'bestFit':
|
|
1627
|
+
{
|
|
1628
|
+
var _overflowsData$filter2;
|
|
1629
|
+
const placement = (_overflowsData$filter2 = overflowsData.filter(d => {
|
|
1630
|
+
if (hasFallbackAxisSideDirection) {
|
|
1631
|
+
const currentSideAxis = getSideAxis(d.placement);
|
|
1632
|
+
return currentSideAxis === initialSideAxis ||
|
|
1633
|
+
// Create a bias to the `y` side axis due to horizontal
|
|
1634
|
+
// reading directions favoring greater width.
|
|
1635
|
+
currentSideAxis === 'y';
|
|
1636
|
+
}
|
|
1637
|
+
return true;
|
|
1638
|
+
}).map(d => [d.placement, d.overflows.filter(overflow => overflow > 0).reduce((acc, overflow) => acc + overflow, 0)]).sort((a, b) => a[1] - b[1])[0]) == null ? void 0 : _overflowsData$filter2[0];
|
|
1639
|
+
if (placement) {
|
|
1640
|
+
resetPlacement = placement;
|
|
1641
|
+
}
|
|
1642
|
+
break;
|
|
1643
|
+
}
|
|
1644
|
+
case 'initialPlacement':
|
|
1645
|
+
resetPlacement = initialPlacement;
|
|
1646
|
+
break;
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
if (placement !== resetPlacement) {
|
|
1650
|
+
return {
|
|
1651
|
+
reset: {
|
|
1652
|
+
placement: resetPlacement
|
|
1653
|
+
}
|
|
1654
|
+
};
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
return {};
|
|
1658
|
+
}
|
|
1659
|
+
};
|
|
1660
|
+
};
|
|
1661
|
+
|
|
1662
|
+
const originSides = /*#__PURE__*/new Set(['left', 'top']);
|
|
1663
|
+
|
|
1664
|
+
// For type backwards-compatibility, the `OffsetOptions` type was also
|
|
1665
|
+
// Derivable.
|
|
1666
|
+
|
|
1667
|
+
async function convertValueToCoords(state, options) {
|
|
1668
|
+
const {
|
|
1669
|
+
placement,
|
|
1670
|
+
platform,
|
|
1671
|
+
elements
|
|
1672
|
+
} = state;
|
|
1673
|
+
const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
|
|
1674
|
+
const side = getSide(placement);
|
|
1675
|
+
const alignment = getAlignment(placement);
|
|
1676
|
+
const isVertical = getSideAxis(placement) === 'y';
|
|
1677
|
+
const mainAxisMulti = originSides.has(side) ? -1 : 1;
|
|
1678
|
+
const crossAxisMulti = rtl && isVertical ? -1 : 1;
|
|
1679
|
+
const rawValue = evaluate(options, state);
|
|
1680
|
+
|
|
1681
|
+
// eslint-disable-next-line prefer-const
|
|
1682
|
+
let {
|
|
1683
|
+
mainAxis,
|
|
1684
|
+
crossAxis,
|
|
1685
|
+
alignmentAxis
|
|
1686
|
+
} = typeof rawValue === 'number' ? {
|
|
1687
|
+
mainAxis: rawValue,
|
|
1688
|
+
crossAxis: 0,
|
|
1689
|
+
alignmentAxis: null
|
|
1690
|
+
} : {
|
|
1691
|
+
mainAxis: rawValue.mainAxis || 0,
|
|
1692
|
+
crossAxis: rawValue.crossAxis || 0,
|
|
1693
|
+
alignmentAxis: rawValue.alignmentAxis
|
|
1694
|
+
};
|
|
1695
|
+
if (alignment && typeof alignmentAxis === 'number') {
|
|
1696
|
+
crossAxis = alignment === 'end' ? alignmentAxis * -1 : alignmentAxis;
|
|
1697
|
+
}
|
|
1698
|
+
return isVertical ? {
|
|
1699
|
+
x: crossAxis * crossAxisMulti,
|
|
1700
|
+
y: mainAxis * mainAxisMulti
|
|
1701
|
+
} : {
|
|
1702
|
+
x: mainAxis * mainAxisMulti,
|
|
1703
|
+
y: crossAxis * crossAxisMulti
|
|
1704
|
+
};
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
/**
|
|
1708
|
+
* Modifies the placement by translating the floating element along the
|
|
1709
|
+
* specified axes.
|
|
1710
|
+
* A number (shorthand for `mainAxis` or distance), or an axes configuration
|
|
1711
|
+
* object may be passed.
|
|
1712
|
+
* @see https://floating-ui.com/docs/offset
|
|
1713
|
+
*/
|
|
1714
|
+
const offset$1 = function (options) {
|
|
1715
|
+
if (options === void 0) {
|
|
1716
|
+
options = 0;
|
|
1717
|
+
}
|
|
1718
|
+
return {
|
|
1719
|
+
name: 'offset',
|
|
1720
|
+
options,
|
|
1721
|
+
async fn(state) {
|
|
1722
|
+
var _middlewareData$offse, _middlewareData$arrow;
|
|
1723
|
+
const {
|
|
1724
|
+
x,
|
|
1725
|
+
y,
|
|
1726
|
+
placement,
|
|
1727
|
+
middlewareData
|
|
1728
|
+
} = state;
|
|
1729
|
+
const diffCoords = await convertValueToCoords(state, options);
|
|
1730
|
+
|
|
1731
|
+
// If the placement is the same and the arrow caused an alignment offset
|
|
1732
|
+
// then we don't need to change the positioning coordinates.
|
|
1733
|
+
if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
|
|
1734
|
+
return {};
|
|
1735
|
+
}
|
|
1736
|
+
return {
|
|
1737
|
+
x: x + diffCoords.x,
|
|
1738
|
+
y: y + diffCoords.y,
|
|
1739
|
+
data: {
|
|
1740
|
+
...diffCoords,
|
|
1741
|
+
placement
|
|
1742
|
+
}
|
|
1743
|
+
};
|
|
1744
|
+
}
|
|
1745
|
+
};
|
|
1746
|
+
};
|
|
1747
|
+
|
|
1748
|
+
/**
|
|
1749
|
+
* Optimizes the visibility of the floating element by shifting it in order to
|
|
1750
|
+
* keep it in view when it will overflow the clipping boundary.
|
|
1751
|
+
* @see https://floating-ui.com/docs/shift
|
|
1752
|
+
*/
|
|
1753
|
+
const shift$1 = function (options) {
|
|
1754
|
+
if (options === void 0) {
|
|
1755
|
+
options = {};
|
|
1756
|
+
}
|
|
1757
|
+
return {
|
|
1758
|
+
name: 'shift',
|
|
1759
|
+
options,
|
|
1760
|
+
async fn(state) {
|
|
1761
|
+
const {
|
|
1762
|
+
x,
|
|
1763
|
+
y,
|
|
1764
|
+
placement,
|
|
1765
|
+
platform
|
|
1766
|
+
} = state;
|
|
1767
|
+
const {
|
|
1768
|
+
mainAxis: checkMainAxis = true,
|
|
1769
|
+
crossAxis: checkCrossAxis = false,
|
|
1770
|
+
limiter = {
|
|
1771
|
+
fn: _ref => {
|
|
1772
|
+
let {
|
|
1773
|
+
x,
|
|
1774
|
+
y
|
|
1775
|
+
} = _ref;
|
|
1776
|
+
return {
|
|
1777
|
+
x,
|
|
1778
|
+
y
|
|
1779
|
+
};
|
|
1780
|
+
}
|
|
1781
|
+
},
|
|
1782
|
+
...detectOverflowOptions
|
|
1783
|
+
} = evaluate(options, state);
|
|
1784
|
+
const coords = {
|
|
1785
|
+
x,
|
|
1786
|
+
y
|
|
1787
|
+
};
|
|
1788
|
+
const overflow = await platform.detectOverflow(state, detectOverflowOptions);
|
|
1789
|
+
const crossAxis = getSideAxis(getSide(placement));
|
|
1790
|
+
const mainAxis = getOppositeAxis(crossAxis);
|
|
1791
|
+
let mainAxisCoord = coords[mainAxis];
|
|
1792
|
+
let crossAxisCoord = coords[crossAxis];
|
|
1793
|
+
if (checkMainAxis) {
|
|
1794
|
+
const minSide = mainAxis === 'y' ? 'top' : 'left';
|
|
1795
|
+
const maxSide = mainAxis === 'y' ? 'bottom' : 'right';
|
|
1796
|
+
const min = mainAxisCoord + overflow[minSide];
|
|
1797
|
+
const max = mainAxisCoord - overflow[maxSide];
|
|
1798
|
+
mainAxisCoord = clamp(min, mainAxisCoord, max);
|
|
1799
|
+
}
|
|
1800
|
+
if (checkCrossAxis) {
|
|
1801
|
+
const minSide = crossAxis === 'y' ? 'top' : 'left';
|
|
1802
|
+
const maxSide = crossAxis === 'y' ? 'bottom' : 'right';
|
|
1803
|
+
const min = crossAxisCoord + overflow[minSide];
|
|
1804
|
+
const max = crossAxisCoord - overflow[maxSide];
|
|
1805
|
+
crossAxisCoord = clamp(min, crossAxisCoord, max);
|
|
1806
|
+
}
|
|
1807
|
+
const limitedCoords = limiter.fn({
|
|
1808
|
+
...state,
|
|
1809
|
+
[mainAxis]: mainAxisCoord,
|
|
1810
|
+
[crossAxis]: crossAxisCoord
|
|
1811
|
+
});
|
|
1812
|
+
return {
|
|
1813
|
+
...limitedCoords,
|
|
1814
|
+
data: {
|
|
1815
|
+
x: limitedCoords.x - x,
|
|
1816
|
+
y: limitedCoords.y - y,
|
|
1817
|
+
enabled: {
|
|
1818
|
+
[mainAxis]: checkMainAxis,
|
|
1819
|
+
[crossAxis]: checkCrossAxis
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
};
|
|
1823
|
+
}
|
|
1824
|
+
};
|
|
1825
|
+
};
|
|
1826
|
+
|
|
1827
|
+
function hasWindow() {
|
|
1828
|
+
return typeof window !== 'undefined';
|
|
1829
|
+
}
|
|
1830
|
+
function getNodeName(node) {
|
|
1831
|
+
if (isNode(node)) {
|
|
1832
|
+
return (node.nodeName || '').toLowerCase();
|
|
1833
|
+
}
|
|
1834
|
+
// Mocked nodes in testing environments may not be instances of Node. By
|
|
1835
|
+
// returning `#document` an infinite loop won't occur.
|
|
1836
|
+
// https://github.com/floating-ui/floating-ui/issues/2317
|
|
1837
|
+
return '#document';
|
|
1838
|
+
}
|
|
1839
|
+
function getWindow(node) {
|
|
1840
|
+
var _node$ownerDocument;
|
|
1841
|
+
return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
|
|
1842
|
+
}
|
|
1843
|
+
function getDocumentElement(node) {
|
|
1844
|
+
var _ref;
|
|
1845
|
+
return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
|
|
1846
|
+
}
|
|
1847
|
+
function isNode(value) {
|
|
1848
|
+
if (!hasWindow()) {
|
|
1849
|
+
return false;
|
|
1850
|
+
}
|
|
1851
|
+
return value instanceof Node || value instanceof getWindow(value).Node;
|
|
1852
|
+
}
|
|
1853
|
+
function isElement(value) {
|
|
1854
|
+
if (!hasWindow()) {
|
|
1855
|
+
return false;
|
|
1856
|
+
}
|
|
1857
|
+
return value instanceof Element || value instanceof getWindow(value).Element;
|
|
1858
|
+
}
|
|
1859
|
+
function isHTMLElement(value) {
|
|
1860
|
+
if (!hasWindow()) {
|
|
1861
|
+
return false;
|
|
1862
|
+
}
|
|
1863
|
+
return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
|
|
1864
|
+
}
|
|
1865
|
+
function isShadowRoot(value) {
|
|
1866
|
+
if (!hasWindow() || typeof ShadowRoot === 'undefined') {
|
|
1867
|
+
return false;
|
|
1868
|
+
}
|
|
1869
|
+
return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
|
|
1870
|
+
}
|
|
1871
|
+
const invalidOverflowDisplayValues = /*#__PURE__*/new Set(['inline', 'contents']);
|
|
1872
|
+
function isOverflowElement(element) {
|
|
1873
|
+
const {
|
|
1874
|
+
overflow,
|
|
1875
|
+
overflowX,
|
|
1876
|
+
overflowY,
|
|
1877
|
+
display
|
|
1878
|
+
} = getComputedStyle$1(element);
|
|
1879
|
+
return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !invalidOverflowDisplayValues.has(display);
|
|
1880
|
+
}
|
|
1881
|
+
const tableElements = /*#__PURE__*/new Set(['table', 'td', 'th']);
|
|
1882
|
+
function isTableElement(element) {
|
|
1883
|
+
return tableElements.has(getNodeName(element));
|
|
1884
|
+
}
|
|
1885
|
+
const topLayerSelectors = [':popover-open', ':modal'];
|
|
1886
|
+
function isTopLayer(element) {
|
|
1887
|
+
return topLayerSelectors.some(selector => {
|
|
1888
|
+
try {
|
|
1889
|
+
return element.matches(selector);
|
|
1890
|
+
} catch (_e) {
|
|
1891
|
+
return false;
|
|
1892
|
+
}
|
|
1893
|
+
});
|
|
1894
|
+
}
|
|
1895
|
+
const transformProperties = ['transform', 'translate', 'scale', 'rotate', 'perspective'];
|
|
1896
|
+
const willChangeValues = ['transform', 'translate', 'scale', 'rotate', 'perspective', 'filter'];
|
|
1897
|
+
const containValues = ['paint', 'layout', 'strict', 'content'];
|
|
1898
|
+
function isContainingBlock(elementOrCss) {
|
|
1899
|
+
const webkit = isWebKit();
|
|
1900
|
+
const css = isElement(elementOrCss) ? getComputedStyle$1(elementOrCss) : elementOrCss;
|
|
1901
|
+
|
|
1902
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
|
|
1903
|
+
// https://drafts.csswg.org/css-transforms-2/#individual-transforms
|
|
1904
|
+
return transformProperties.some(value => css[value] ? css[value] !== 'none' : false) || (css.containerType ? css.containerType !== 'normal' : false) || !webkit && (css.backdropFilter ? css.backdropFilter !== 'none' : false) || !webkit && (css.filter ? css.filter !== 'none' : false) || willChangeValues.some(value => (css.willChange || '').includes(value)) || containValues.some(value => (css.contain || '').includes(value));
|
|
1905
|
+
}
|
|
1906
|
+
function getContainingBlock(element) {
|
|
1907
|
+
let currentNode = getParentNode(element);
|
|
1908
|
+
while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
|
|
1909
|
+
if (isContainingBlock(currentNode)) {
|
|
1910
|
+
return currentNode;
|
|
1911
|
+
} else if (isTopLayer(currentNode)) {
|
|
1912
|
+
return null;
|
|
1913
|
+
}
|
|
1914
|
+
currentNode = getParentNode(currentNode);
|
|
1915
|
+
}
|
|
1916
|
+
return null;
|
|
1917
|
+
}
|
|
1918
|
+
function isWebKit() {
|
|
1919
|
+
if (typeof CSS === 'undefined' || !CSS.supports) return false;
|
|
1920
|
+
return CSS.supports('-webkit-backdrop-filter', 'none');
|
|
1921
|
+
}
|
|
1922
|
+
const lastTraversableNodeNames = /*#__PURE__*/new Set(['html', 'body', '#document']);
|
|
1923
|
+
function isLastTraversableNode(node) {
|
|
1924
|
+
return lastTraversableNodeNames.has(getNodeName(node));
|
|
1925
|
+
}
|
|
1926
|
+
function getComputedStyle$1(element) {
|
|
1927
|
+
return getWindow(element).getComputedStyle(element);
|
|
1928
|
+
}
|
|
1929
|
+
function getNodeScroll(element) {
|
|
1930
|
+
if (isElement(element)) {
|
|
1931
|
+
return {
|
|
1932
|
+
scrollLeft: element.scrollLeft,
|
|
1933
|
+
scrollTop: element.scrollTop
|
|
1934
|
+
};
|
|
1935
|
+
}
|
|
1936
|
+
return {
|
|
1937
|
+
scrollLeft: element.scrollX,
|
|
1938
|
+
scrollTop: element.scrollY
|
|
1939
|
+
};
|
|
1940
|
+
}
|
|
1941
|
+
function getParentNode(node) {
|
|
1942
|
+
if (getNodeName(node) === 'html') {
|
|
1943
|
+
return node;
|
|
1944
|
+
}
|
|
1945
|
+
const result =
|
|
1946
|
+
// Step into the shadow DOM of the parent of a slotted node.
|
|
1947
|
+
node.assignedSlot ||
|
|
1948
|
+
// DOM Element detected.
|
|
1949
|
+
node.parentNode ||
|
|
1950
|
+
// ShadowRoot detected.
|
|
1951
|
+
isShadowRoot(node) && node.host ||
|
|
1952
|
+
// Fallback.
|
|
1953
|
+
getDocumentElement(node);
|
|
1954
|
+
return isShadowRoot(result) ? result.host : result;
|
|
1955
|
+
}
|
|
1956
|
+
function getNearestOverflowAncestor(node) {
|
|
1957
|
+
const parentNode = getParentNode(node);
|
|
1958
|
+
if (isLastTraversableNode(parentNode)) {
|
|
1959
|
+
return node.ownerDocument ? node.ownerDocument.body : node.body;
|
|
1960
|
+
}
|
|
1961
|
+
if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
|
|
1962
|
+
return parentNode;
|
|
1963
|
+
}
|
|
1964
|
+
return getNearestOverflowAncestor(parentNode);
|
|
1965
|
+
}
|
|
1966
|
+
function getOverflowAncestors(node, list, traverseIframes) {
|
|
1967
|
+
var _node$ownerDocument2;
|
|
1968
|
+
if (list === void 0) {
|
|
1969
|
+
list = [];
|
|
1970
|
+
}
|
|
1971
|
+
if (traverseIframes === void 0) {
|
|
1972
|
+
traverseIframes = true;
|
|
1973
|
+
}
|
|
1974
|
+
const scrollableAncestor = getNearestOverflowAncestor(node);
|
|
1975
|
+
const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
|
|
1976
|
+
const win = getWindow(scrollableAncestor);
|
|
1977
|
+
if (isBody) {
|
|
1978
|
+
const frameElement = getFrameElement(win);
|
|
1979
|
+
return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], frameElement && traverseIframes ? getOverflowAncestors(frameElement) : []);
|
|
1980
|
+
}
|
|
1981
|
+
return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));
|
|
1982
|
+
}
|
|
1983
|
+
function getFrameElement(win) {
|
|
1984
|
+
return win.parent && Object.getPrototypeOf(win.parent) ? win.frameElement : null;
|
|
1985
|
+
}
|
|
1986
|
+
|
|
1987
|
+
function getCssDimensions(element) {
|
|
1988
|
+
const css = getComputedStyle$1(element);
|
|
1989
|
+
// In testing environments, the `width` and `height` properties are empty
|
|
1990
|
+
// strings for SVG elements, returning NaN. Fallback to `0` in this case.
|
|
1991
|
+
let width = parseFloat(css.width) || 0;
|
|
1992
|
+
let height = parseFloat(css.height) || 0;
|
|
1993
|
+
const hasOffset = isHTMLElement(element);
|
|
1994
|
+
const offsetWidth = hasOffset ? element.offsetWidth : width;
|
|
1995
|
+
const offsetHeight = hasOffset ? element.offsetHeight : height;
|
|
1996
|
+
const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
|
|
1997
|
+
if (shouldFallback) {
|
|
1998
|
+
width = offsetWidth;
|
|
1999
|
+
height = offsetHeight;
|
|
2000
|
+
}
|
|
2001
|
+
return {
|
|
2002
|
+
width,
|
|
2003
|
+
height,
|
|
2004
|
+
$: shouldFallback
|
|
2005
|
+
};
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
function unwrapElement(element) {
|
|
2009
|
+
return !isElement(element) ? element.contextElement : element;
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
function getScale(element) {
|
|
2013
|
+
const domElement = unwrapElement(element);
|
|
2014
|
+
if (!isHTMLElement(domElement)) {
|
|
2015
|
+
return createCoords(1);
|
|
2016
|
+
}
|
|
2017
|
+
const rect = domElement.getBoundingClientRect();
|
|
2018
|
+
const {
|
|
2019
|
+
width,
|
|
2020
|
+
height,
|
|
2021
|
+
$
|
|
2022
|
+
} = getCssDimensions(domElement);
|
|
2023
|
+
let x = ($ ? round(rect.width) : rect.width) / width;
|
|
2024
|
+
let y = ($ ? round(rect.height) : rect.height) / height;
|
|
2025
|
+
|
|
2026
|
+
// 0, NaN, or Infinity should always fallback to 1.
|
|
2027
|
+
|
|
2028
|
+
if (!x || !Number.isFinite(x)) {
|
|
2029
|
+
x = 1;
|
|
2030
|
+
}
|
|
2031
|
+
if (!y || !Number.isFinite(y)) {
|
|
2032
|
+
y = 1;
|
|
2033
|
+
}
|
|
2034
|
+
return {
|
|
2035
|
+
x,
|
|
2036
|
+
y
|
|
2037
|
+
};
|
|
2038
|
+
}
|
|
2039
|
+
|
|
2040
|
+
const noOffsets = /*#__PURE__*/createCoords(0);
|
|
2041
|
+
function getVisualOffsets(element) {
|
|
2042
|
+
const win = getWindow(element);
|
|
2043
|
+
if (!isWebKit() || !win.visualViewport) {
|
|
2044
|
+
return noOffsets;
|
|
2045
|
+
}
|
|
2046
|
+
return {
|
|
2047
|
+
x: win.visualViewport.offsetLeft,
|
|
2048
|
+
y: win.visualViewport.offsetTop
|
|
2049
|
+
};
|
|
2050
|
+
}
|
|
2051
|
+
function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
|
|
2052
|
+
if (isFixed === void 0) {
|
|
2053
|
+
isFixed = false;
|
|
2054
|
+
}
|
|
2055
|
+
if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
|
|
2056
|
+
return false;
|
|
2057
|
+
}
|
|
2058
|
+
return isFixed;
|
|
2059
|
+
}
|
|
2060
|
+
|
|
2061
|
+
function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
|
|
2062
|
+
if (includeScale === void 0) {
|
|
2063
|
+
includeScale = false;
|
|
2064
|
+
}
|
|
2065
|
+
if (isFixedStrategy === void 0) {
|
|
2066
|
+
isFixedStrategy = false;
|
|
2067
|
+
}
|
|
2068
|
+
const clientRect = element.getBoundingClientRect();
|
|
2069
|
+
const domElement = unwrapElement(element);
|
|
2070
|
+
let scale = createCoords(1);
|
|
2071
|
+
if (includeScale) {
|
|
2072
|
+
if (offsetParent) {
|
|
2073
|
+
if (isElement(offsetParent)) {
|
|
2074
|
+
scale = getScale(offsetParent);
|
|
2075
|
+
}
|
|
2076
|
+
} else {
|
|
2077
|
+
scale = getScale(element);
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
|
|
2081
|
+
let x = (clientRect.left + visualOffsets.x) / scale.x;
|
|
2082
|
+
let y = (clientRect.top + visualOffsets.y) / scale.y;
|
|
2083
|
+
let width = clientRect.width / scale.x;
|
|
2084
|
+
let height = clientRect.height / scale.y;
|
|
2085
|
+
if (domElement) {
|
|
2086
|
+
const win = getWindow(domElement);
|
|
2087
|
+
const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
|
|
2088
|
+
let currentWin = win;
|
|
2089
|
+
let currentIFrame = getFrameElement(currentWin);
|
|
2090
|
+
while (currentIFrame && offsetParent && offsetWin !== currentWin) {
|
|
2091
|
+
const iframeScale = getScale(currentIFrame);
|
|
2092
|
+
const iframeRect = currentIFrame.getBoundingClientRect();
|
|
2093
|
+
const css = getComputedStyle$1(currentIFrame);
|
|
2094
|
+
const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
|
|
2095
|
+
const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
|
|
2096
|
+
x *= iframeScale.x;
|
|
2097
|
+
y *= iframeScale.y;
|
|
2098
|
+
width *= iframeScale.x;
|
|
2099
|
+
height *= iframeScale.y;
|
|
2100
|
+
x += left;
|
|
2101
|
+
y += top;
|
|
2102
|
+
currentWin = getWindow(currentIFrame);
|
|
2103
|
+
currentIFrame = getFrameElement(currentWin);
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
return rectToClientRect({
|
|
2107
|
+
width,
|
|
2108
|
+
height,
|
|
2109
|
+
x,
|
|
2110
|
+
y
|
|
2111
|
+
});
|
|
2112
|
+
}
|
|
2113
|
+
|
|
2114
|
+
// If <html> has a CSS width greater than the viewport, then this will be
|
|
2115
|
+
// incorrect for RTL.
|
|
2116
|
+
function getWindowScrollBarX(element, rect) {
|
|
2117
|
+
const leftScroll = getNodeScroll(element).scrollLeft;
|
|
2118
|
+
if (!rect) {
|
|
2119
|
+
return getBoundingClientRect(getDocumentElement(element)).left + leftScroll;
|
|
2120
|
+
}
|
|
2121
|
+
return rect.left + leftScroll;
|
|
2122
|
+
}
|
|
2123
|
+
|
|
2124
|
+
function getHTMLOffset(documentElement, scroll) {
|
|
2125
|
+
const htmlRect = documentElement.getBoundingClientRect();
|
|
2126
|
+
const x = htmlRect.left + scroll.scrollLeft - getWindowScrollBarX(documentElement, htmlRect);
|
|
2127
|
+
const y = htmlRect.top + scroll.scrollTop;
|
|
2128
|
+
return {
|
|
2129
|
+
x,
|
|
2130
|
+
y
|
|
2131
|
+
};
|
|
2132
|
+
}
|
|
2133
|
+
|
|
2134
|
+
function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
|
|
2135
|
+
let {
|
|
2136
|
+
elements,
|
|
2137
|
+
rect,
|
|
2138
|
+
offsetParent,
|
|
2139
|
+
strategy
|
|
2140
|
+
} = _ref;
|
|
2141
|
+
const isFixed = strategy === 'fixed';
|
|
2142
|
+
const documentElement = getDocumentElement(offsetParent);
|
|
2143
|
+
const topLayer = elements ? isTopLayer(elements.floating) : false;
|
|
2144
|
+
if (offsetParent === documentElement || topLayer && isFixed) {
|
|
2145
|
+
return rect;
|
|
2146
|
+
}
|
|
2147
|
+
let scroll = {
|
|
2148
|
+
scrollLeft: 0,
|
|
2149
|
+
scrollTop: 0
|
|
2150
|
+
};
|
|
2151
|
+
let scale = createCoords(1);
|
|
2152
|
+
const offsets = createCoords(0);
|
|
2153
|
+
const isOffsetParentAnElement = isHTMLElement(offsetParent);
|
|
2154
|
+
if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
|
|
2155
|
+
if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
|
|
2156
|
+
scroll = getNodeScroll(offsetParent);
|
|
2157
|
+
}
|
|
2158
|
+
if (isHTMLElement(offsetParent)) {
|
|
2159
|
+
const offsetRect = getBoundingClientRect(offsetParent);
|
|
2160
|
+
scale = getScale(offsetParent);
|
|
2161
|
+
offsets.x = offsetRect.x + offsetParent.clientLeft;
|
|
2162
|
+
offsets.y = offsetRect.y + offsetParent.clientTop;
|
|
2163
|
+
}
|
|
2164
|
+
}
|
|
2165
|
+
const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
|
|
2166
|
+
return {
|
|
2167
|
+
width: rect.width * scale.x,
|
|
2168
|
+
height: rect.height * scale.y,
|
|
2169
|
+
x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x + htmlOffset.x,
|
|
2170
|
+
y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y + htmlOffset.y
|
|
2171
|
+
};
|
|
2172
|
+
}
|
|
2173
|
+
|
|
2174
|
+
function getClientRects(element) {
|
|
2175
|
+
return Array.from(element.getClientRects());
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2178
|
+
// Gets the entire size of the scrollable document area, even extending outside
|
|
2179
|
+
// of the `<html>` and `<body>` rect bounds if horizontally scrollable.
|
|
2180
|
+
function getDocumentRect(element) {
|
|
2181
|
+
const html = getDocumentElement(element);
|
|
2182
|
+
const scroll = getNodeScroll(element);
|
|
2183
|
+
const body = element.ownerDocument.body;
|
|
2184
|
+
const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
|
|
2185
|
+
const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
|
|
2186
|
+
let x = -scroll.scrollLeft + getWindowScrollBarX(element);
|
|
2187
|
+
const y = -scroll.scrollTop;
|
|
2188
|
+
if (getComputedStyle$1(body).direction === 'rtl') {
|
|
2189
|
+
x += max(html.clientWidth, body.clientWidth) - width;
|
|
2190
|
+
}
|
|
2191
|
+
return {
|
|
2192
|
+
width,
|
|
2193
|
+
height,
|
|
2194
|
+
x,
|
|
2195
|
+
y
|
|
2196
|
+
};
|
|
2197
|
+
}
|
|
2198
|
+
|
|
2199
|
+
// Safety check: ensure the scrollbar space is reasonable in case this
|
|
2200
|
+
// calculation is affected by unusual styles.
|
|
2201
|
+
// Most scrollbars leave 15-18px of space.
|
|
2202
|
+
const SCROLLBAR_MAX = 25;
|
|
2203
|
+
function getViewportRect(element, strategy) {
|
|
2204
|
+
const win = getWindow(element);
|
|
2205
|
+
const html = getDocumentElement(element);
|
|
2206
|
+
const visualViewport = win.visualViewport;
|
|
2207
|
+
let width = html.clientWidth;
|
|
2208
|
+
let height = html.clientHeight;
|
|
2209
|
+
let x = 0;
|
|
2210
|
+
let y = 0;
|
|
2211
|
+
if (visualViewport) {
|
|
2212
|
+
width = visualViewport.width;
|
|
2213
|
+
height = visualViewport.height;
|
|
2214
|
+
const visualViewportBased = isWebKit();
|
|
2215
|
+
if (!visualViewportBased || visualViewportBased && strategy === 'fixed') {
|
|
2216
|
+
x = visualViewport.offsetLeft;
|
|
2217
|
+
y = visualViewport.offsetTop;
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
const windowScrollbarX = getWindowScrollBarX(html);
|
|
2221
|
+
// <html> `overflow: hidden` + `scrollbar-gutter: stable` reduces the
|
|
2222
|
+
// visual width of the <html> but this is not considered in the size
|
|
2223
|
+
// of `html.clientWidth`.
|
|
2224
|
+
if (windowScrollbarX <= 0) {
|
|
2225
|
+
const doc = html.ownerDocument;
|
|
2226
|
+
const body = doc.body;
|
|
2227
|
+
const bodyStyles = getComputedStyle(body);
|
|
2228
|
+
const bodyMarginInline = doc.compatMode === 'CSS1Compat' ? parseFloat(bodyStyles.marginLeft) + parseFloat(bodyStyles.marginRight) || 0 : 0;
|
|
2229
|
+
const clippingStableScrollbarWidth = Math.abs(html.clientWidth - body.clientWidth - bodyMarginInline);
|
|
2230
|
+
if (clippingStableScrollbarWidth <= SCROLLBAR_MAX) {
|
|
2231
|
+
width -= clippingStableScrollbarWidth;
|
|
2232
|
+
}
|
|
2233
|
+
} else if (windowScrollbarX <= SCROLLBAR_MAX) {
|
|
2234
|
+
// If the <body> scrollbar is on the left, the width needs to be extended
|
|
2235
|
+
// by the scrollbar amount so there isn't extra space on the right.
|
|
2236
|
+
width += windowScrollbarX;
|
|
2237
|
+
}
|
|
2238
|
+
return {
|
|
2239
|
+
width,
|
|
2240
|
+
height,
|
|
2241
|
+
x,
|
|
2242
|
+
y
|
|
2243
|
+
};
|
|
2244
|
+
}
|
|
2245
|
+
|
|
2246
|
+
const absoluteOrFixed = /*#__PURE__*/new Set(['absolute', 'fixed']);
|
|
2247
|
+
// Returns the inner client rect, subtracting scrollbars if present.
|
|
2248
|
+
function getInnerBoundingClientRect(element, strategy) {
|
|
2249
|
+
const clientRect = getBoundingClientRect(element, true, strategy === 'fixed');
|
|
2250
|
+
const top = clientRect.top + element.clientTop;
|
|
2251
|
+
const left = clientRect.left + element.clientLeft;
|
|
2252
|
+
const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
|
|
2253
|
+
const width = element.clientWidth * scale.x;
|
|
2254
|
+
const height = element.clientHeight * scale.y;
|
|
2255
|
+
const x = left * scale.x;
|
|
2256
|
+
const y = top * scale.y;
|
|
2257
|
+
return {
|
|
2258
|
+
width,
|
|
2259
|
+
height,
|
|
2260
|
+
x,
|
|
2261
|
+
y
|
|
2262
|
+
};
|
|
2263
|
+
}
|
|
2264
|
+
function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
|
|
2265
|
+
let rect;
|
|
2266
|
+
if (clippingAncestor === 'viewport') {
|
|
2267
|
+
rect = getViewportRect(element, strategy);
|
|
2268
|
+
} else if (clippingAncestor === 'document') {
|
|
2269
|
+
rect = getDocumentRect(getDocumentElement(element));
|
|
2270
|
+
} else if (isElement(clippingAncestor)) {
|
|
2271
|
+
rect = getInnerBoundingClientRect(clippingAncestor, strategy);
|
|
2272
|
+
} else {
|
|
2273
|
+
const visualOffsets = getVisualOffsets(element);
|
|
2274
|
+
rect = {
|
|
2275
|
+
x: clippingAncestor.x - visualOffsets.x,
|
|
2276
|
+
y: clippingAncestor.y - visualOffsets.y,
|
|
2277
|
+
width: clippingAncestor.width,
|
|
2278
|
+
height: clippingAncestor.height
|
|
2279
|
+
};
|
|
2280
|
+
}
|
|
2281
|
+
return rectToClientRect(rect);
|
|
2282
|
+
}
|
|
2283
|
+
function hasFixedPositionAncestor(element, stopNode) {
|
|
2284
|
+
const parentNode = getParentNode(element);
|
|
2285
|
+
if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
|
|
2286
|
+
return false;
|
|
2287
|
+
}
|
|
2288
|
+
return getComputedStyle$1(parentNode).position === 'fixed' || hasFixedPositionAncestor(parentNode, stopNode);
|
|
2289
|
+
}
|
|
2290
|
+
|
|
2291
|
+
// A "clipping ancestor" is an `overflow` element with the characteristic of
|
|
2292
|
+
// clipping (or hiding) child elements. This returns all clipping ancestors
|
|
2293
|
+
// of the given element up the tree.
|
|
2294
|
+
function getClippingElementAncestors(element, cache) {
|
|
2295
|
+
const cachedResult = cache.get(element);
|
|
2296
|
+
if (cachedResult) {
|
|
2297
|
+
return cachedResult;
|
|
2298
|
+
}
|
|
2299
|
+
let result = getOverflowAncestors(element, [], false).filter(el => isElement(el) && getNodeName(el) !== 'body');
|
|
2300
|
+
let currentContainingBlockComputedStyle = null;
|
|
2301
|
+
const elementIsFixed = getComputedStyle$1(element).position === 'fixed';
|
|
2302
|
+
let currentNode = elementIsFixed ? getParentNode(element) : element;
|
|
2303
|
+
|
|
2304
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
|
|
2305
|
+
while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
|
|
2306
|
+
const computedStyle = getComputedStyle$1(currentNode);
|
|
2307
|
+
const currentNodeIsContaining = isContainingBlock(currentNode);
|
|
2308
|
+
if (!currentNodeIsContaining && computedStyle.position === 'fixed') {
|
|
2309
|
+
currentContainingBlockComputedStyle = null;
|
|
2310
|
+
}
|
|
2311
|
+
const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === 'static' && !!currentContainingBlockComputedStyle && absoluteOrFixed.has(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
|
|
2312
|
+
if (shouldDropCurrentNode) {
|
|
2313
|
+
// Drop non-containing blocks.
|
|
2314
|
+
result = result.filter(ancestor => ancestor !== currentNode);
|
|
2315
|
+
} else {
|
|
2316
|
+
// Record last containing block for next iteration.
|
|
2317
|
+
currentContainingBlockComputedStyle = computedStyle;
|
|
2318
|
+
}
|
|
2319
|
+
currentNode = getParentNode(currentNode);
|
|
2320
|
+
}
|
|
2321
|
+
cache.set(element, result);
|
|
2322
|
+
return result;
|
|
2323
|
+
}
|
|
2324
|
+
|
|
2325
|
+
// Gets the maximum area that the element is visible in due to any number of
|
|
2326
|
+
// clipping ancestors.
|
|
2327
|
+
function getClippingRect(_ref) {
|
|
2328
|
+
let {
|
|
2329
|
+
element,
|
|
2330
|
+
boundary,
|
|
2331
|
+
rootBoundary,
|
|
2332
|
+
strategy
|
|
2333
|
+
} = _ref;
|
|
2334
|
+
const elementClippingAncestors = boundary === 'clippingAncestors' ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary);
|
|
2335
|
+
const clippingAncestors = [...elementClippingAncestors, rootBoundary];
|
|
2336
|
+
const firstClippingAncestor = clippingAncestors[0];
|
|
2337
|
+
const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
|
|
2338
|
+
const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
|
|
2339
|
+
accRect.top = max(rect.top, accRect.top);
|
|
2340
|
+
accRect.right = min(rect.right, accRect.right);
|
|
2341
|
+
accRect.bottom = min(rect.bottom, accRect.bottom);
|
|
2342
|
+
accRect.left = max(rect.left, accRect.left);
|
|
2343
|
+
return accRect;
|
|
2344
|
+
}, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
|
|
2345
|
+
return {
|
|
2346
|
+
width: clippingRect.right - clippingRect.left,
|
|
2347
|
+
height: clippingRect.bottom - clippingRect.top,
|
|
2348
|
+
x: clippingRect.left,
|
|
2349
|
+
y: clippingRect.top
|
|
2350
|
+
};
|
|
2351
|
+
}
|
|
2352
|
+
|
|
2353
|
+
function getDimensions(element) {
|
|
2354
|
+
const {
|
|
2355
|
+
width,
|
|
2356
|
+
height
|
|
2357
|
+
} = getCssDimensions(element);
|
|
2358
|
+
return {
|
|
2359
|
+
width,
|
|
2360
|
+
height
|
|
2361
|
+
};
|
|
2362
|
+
}
|
|
2363
|
+
|
|
2364
|
+
function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
|
|
2365
|
+
const isOffsetParentAnElement = isHTMLElement(offsetParent);
|
|
2366
|
+
const documentElement = getDocumentElement(offsetParent);
|
|
2367
|
+
const isFixed = strategy === 'fixed';
|
|
2368
|
+
const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
|
|
2369
|
+
let scroll = {
|
|
2370
|
+
scrollLeft: 0,
|
|
2371
|
+
scrollTop: 0
|
|
2372
|
+
};
|
|
2373
|
+
const offsets = createCoords(0);
|
|
2374
|
+
|
|
2375
|
+
// If the <body> scrollbar appears on the left (e.g. RTL systems). Use
|
|
2376
|
+
// Firefox with layout.scrollbar.side = 3 in about:config to test this.
|
|
2377
|
+
function setLeftRTLScrollbarOffset() {
|
|
2378
|
+
offsets.x = getWindowScrollBarX(documentElement);
|
|
2379
|
+
}
|
|
2380
|
+
if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
|
|
2381
|
+
if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
|
|
2382
|
+
scroll = getNodeScroll(offsetParent);
|
|
2383
|
+
}
|
|
2384
|
+
if (isOffsetParentAnElement) {
|
|
2385
|
+
const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
|
|
2386
|
+
offsets.x = offsetRect.x + offsetParent.clientLeft;
|
|
2387
|
+
offsets.y = offsetRect.y + offsetParent.clientTop;
|
|
2388
|
+
} else if (documentElement) {
|
|
2389
|
+
setLeftRTLScrollbarOffset();
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2392
|
+
if (isFixed && !isOffsetParentAnElement && documentElement) {
|
|
2393
|
+
setLeftRTLScrollbarOffset();
|
|
2394
|
+
}
|
|
2395
|
+
const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
|
|
2396
|
+
const x = rect.left + scroll.scrollLeft - offsets.x - htmlOffset.x;
|
|
2397
|
+
const y = rect.top + scroll.scrollTop - offsets.y - htmlOffset.y;
|
|
2398
|
+
return {
|
|
2399
|
+
x,
|
|
2400
|
+
y,
|
|
2401
|
+
width: rect.width,
|
|
2402
|
+
height: rect.height
|
|
2403
|
+
};
|
|
2404
|
+
}
|
|
2405
|
+
|
|
2406
|
+
function isStaticPositioned(element) {
|
|
2407
|
+
return getComputedStyle$1(element).position === 'static';
|
|
2408
|
+
}
|
|
2409
|
+
|
|
2410
|
+
function getTrueOffsetParent(element, polyfill) {
|
|
2411
|
+
if (!isHTMLElement(element) || getComputedStyle$1(element).position === 'fixed') {
|
|
2412
|
+
return null;
|
|
2413
|
+
}
|
|
2414
|
+
if (polyfill) {
|
|
2415
|
+
return polyfill(element);
|
|
2416
|
+
}
|
|
2417
|
+
let rawOffsetParent = element.offsetParent;
|
|
2418
|
+
|
|
2419
|
+
// Firefox returns the <html> element as the offsetParent if it's non-static,
|
|
2420
|
+
// while Chrome and Safari return the <body> element. The <body> element must
|
|
2421
|
+
// be used to perform the correct calculations even if the <html> element is
|
|
2422
|
+
// non-static.
|
|
2423
|
+
if (getDocumentElement(element) === rawOffsetParent) {
|
|
2424
|
+
rawOffsetParent = rawOffsetParent.ownerDocument.body;
|
|
2425
|
+
}
|
|
2426
|
+
return rawOffsetParent;
|
|
2427
|
+
}
|
|
2428
|
+
|
|
2429
|
+
// Gets the closest ancestor positioned element. Handles some edge cases,
|
|
2430
|
+
// such as table ancestors and cross browser bugs.
|
|
2431
|
+
function getOffsetParent(element, polyfill) {
|
|
2432
|
+
const win = getWindow(element);
|
|
2433
|
+
if (isTopLayer(element)) {
|
|
2434
|
+
return win;
|
|
2435
|
+
}
|
|
2436
|
+
if (!isHTMLElement(element)) {
|
|
2437
|
+
let svgOffsetParent = getParentNode(element);
|
|
2438
|
+
while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) {
|
|
2439
|
+
if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) {
|
|
2440
|
+
return svgOffsetParent;
|
|
2441
|
+
}
|
|
2442
|
+
svgOffsetParent = getParentNode(svgOffsetParent);
|
|
2443
|
+
}
|
|
2444
|
+
return win;
|
|
2445
|
+
}
|
|
2446
|
+
let offsetParent = getTrueOffsetParent(element, polyfill);
|
|
2447
|
+
while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) {
|
|
2448
|
+
offsetParent = getTrueOffsetParent(offsetParent, polyfill);
|
|
2449
|
+
}
|
|
2450
|
+
if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) {
|
|
2451
|
+
return win;
|
|
2452
|
+
}
|
|
2453
|
+
return offsetParent || getContainingBlock(element) || win;
|
|
2454
|
+
}
|
|
2455
|
+
|
|
2456
|
+
const getElementRects = async function (data) {
|
|
2457
|
+
const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
|
|
2458
|
+
const getDimensionsFn = this.getDimensions;
|
|
2459
|
+
const floatingDimensions = await getDimensionsFn(data.floating);
|
|
2460
|
+
return {
|
|
2461
|
+
reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy),
|
|
2462
|
+
floating: {
|
|
2463
|
+
x: 0,
|
|
2464
|
+
y: 0,
|
|
2465
|
+
width: floatingDimensions.width,
|
|
2466
|
+
height: floatingDimensions.height
|
|
2467
|
+
}
|
|
2468
|
+
};
|
|
2469
|
+
};
|
|
2470
|
+
|
|
2471
|
+
function isRTL(element) {
|
|
2472
|
+
return getComputedStyle$1(element).direction === 'rtl';
|
|
2473
|
+
}
|
|
2474
|
+
|
|
2475
|
+
const platform = {
|
|
2476
|
+
convertOffsetParentRelativeRectToViewportRelativeRect,
|
|
2477
|
+
getDocumentElement,
|
|
2478
|
+
getClippingRect,
|
|
2479
|
+
getOffsetParent,
|
|
2480
|
+
getElementRects,
|
|
2481
|
+
getClientRects,
|
|
2482
|
+
getDimensions,
|
|
2483
|
+
getScale,
|
|
2484
|
+
isElement,
|
|
2485
|
+
isRTL
|
|
2486
|
+
};
|
|
2487
|
+
|
|
2488
|
+
function rectsAreEqual(a, b) {
|
|
2489
|
+
return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
|
|
2490
|
+
}
|
|
2491
|
+
|
|
2492
|
+
// https://samthor.au/2021/observing-dom/
|
|
2493
|
+
function observeMove(element, onMove) {
|
|
2494
|
+
let io = null;
|
|
2495
|
+
let timeoutId;
|
|
2496
|
+
const root = getDocumentElement(element);
|
|
2497
|
+
function cleanup() {
|
|
2498
|
+
var _io;
|
|
2499
|
+
clearTimeout(timeoutId);
|
|
2500
|
+
(_io = io) == null || _io.disconnect();
|
|
2501
|
+
io = null;
|
|
2502
|
+
}
|
|
2503
|
+
function refresh(skip, threshold) {
|
|
2504
|
+
if (skip === void 0) {
|
|
2505
|
+
skip = false;
|
|
2506
|
+
}
|
|
2507
|
+
if (threshold === void 0) {
|
|
2508
|
+
threshold = 1;
|
|
2509
|
+
}
|
|
2510
|
+
cleanup();
|
|
2511
|
+
const elementRectForRootMargin = element.getBoundingClientRect();
|
|
2512
|
+
const {
|
|
2513
|
+
left,
|
|
2514
|
+
top,
|
|
2515
|
+
width,
|
|
2516
|
+
height
|
|
2517
|
+
} = elementRectForRootMargin;
|
|
2518
|
+
if (!skip) {
|
|
2519
|
+
onMove();
|
|
2520
|
+
}
|
|
2521
|
+
if (!width || !height) {
|
|
2522
|
+
return;
|
|
2523
|
+
}
|
|
2524
|
+
const insetTop = floor(top);
|
|
2525
|
+
const insetRight = floor(root.clientWidth - (left + width));
|
|
2526
|
+
const insetBottom = floor(root.clientHeight - (top + height));
|
|
2527
|
+
const insetLeft = floor(left);
|
|
2528
|
+
const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
|
|
2529
|
+
const options = {
|
|
2530
|
+
rootMargin,
|
|
2531
|
+
threshold: max(0, min(1, threshold)) || 1
|
|
2532
|
+
};
|
|
2533
|
+
let isFirstUpdate = true;
|
|
2534
|
+
function handleObserve(entries) {
|
|
2535
|
+
const ratio = entries[0].intersectionRatio;
|
|
2536
|
+
if (ratio !== threshold) {
|
|
2537
|
+
if (!isFirstUpdate) {
|
|
2538
|
+
return refresh();
|
|
2539
|
+
}
|
|
2540
|
+
if (!ratio) {
|
|
2541
|
+
// If the reference is clipped, the ratio is 0. Throttle the refresh
|
|
2542
|
+
// to prevent an infinite loop of updates.
|
|
2543
|
+
timeoutId = setTimeout(() => {
|
|
2544
|
+
refresh(false, 1e-7);
|
|
2545
|
+
}, 1000);
|
|
2546
|
+
} else {
|
|
2547
|
+
refresh(false, ratio);
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
if (ratio === 1 && !rectsAreEqual(elementRectForRootMargin, element.getBoundingClientRect())) {
|
|
2551
|
+
// It's possible that even though the ratio is reported as 1, the
|
|
2552
|
+
// element is not actually fully within the IntersectionObserver's root
|
|
2553
|
+
// area anymore. This can happen under performance constraints. This may
|
|
2554
|
+
// be a bug in the browser's IntersectionObserver implementation. To
|
|
2555
|
+
// work around this, we compare the element's bounding rect now with
|
|
2556
|
+
// what it was at the time we created the IntersectionObserver. If they
|
|
2557
|
+
// are not equal then the element moved, so we refresh.
|
|
2558
|
+
refresh();
|
|
2559
|
+
}
|
|
2560
|
+
isFirstUpdate = false;
|
|
2561
|
+
}
|
|
2562
|
+
|
|
2563
|
+
// Older browsers don't support a `document` as the root and will throw an
|
|
2564
|
+
// error.
|
|
2565
|
+
try {
|
|
2566
|
+
io = new IntersectionObserver(handleObserve, {
|
|
2567
|
+
...options,
|
|
2568
|
+
// Handle <iframe>s
|
|
2569
|
+
root: root.ownerDocument
|
|
2570
|
+
});
|
|
2571
|
+
} catch (_e) {
|
|
2572
|
+
io = new IntersectionObserver(handleObserve, options);
|
|
2573
|
+
}
|
|
2574
|
+
io.observe(element);
|
|
2575
|
+
}
|
|
2576
|
+
refresh(true);
|
|
2577
|
+
return cleanup;
|
|
2578
|
+
}
|
|
2579
|
+
|
|
2580
|
+
/**
|
|
2581
|
+
* Automatically updates the position of the floating element when necessary.
|
|
2582
|
+
* Should only be called when the floating element is mounted on the DOM or
|
|
2583
|
+
* visible on the screen.
|
|
2584
|
+
* @returns cleanup function that should be invoked when the floating element is
|
|
2585
|
+
* removed from the DOM or hidden from the screen.
|
|
2586
|
+
* @see https://floating-ui.com/docs/autoUpdate
|
|
2587
|
+
*/
|
|
2588
|
+
function autoUpdate(reference, floating, update, options) {
|
|
2589
|
+
if (options === void 0) {
|
|
2590
|
+
options = {};
|
|
2591
|
+
}
|
|
2592
|
+
const {
|
|
2593
|
+
ancestorScroll = true,
|
|
2594
|
+
ancestorResize = true,
|
|
2595
|
+
elementResize = typeof ResizeObserver === 'function',
|
|
2596
|
+
layoutShift = typeof IntersectionObserver === 'function',
|
|
2597
|
+
animationFrame = false
|
|
2598
|
+
} = options;
|
|
2599
|
+
const referenceEl = unwrapElement(reference);
|
|
2600
|
+
const ancestors = ancestorScroll || ancestorResize ? [...(referenceEl ? getOverflowAncestors(referenceEl) : []), ...getOverflowAncestors(floating)] : [];
|
|
2601
|
+
ancestors.forEach(ancestor => {
|
|
2602
|
+
ancestorScroll && ancestor.addEventListener('scroll', update, {
|
|
2603
|
+
passive: true
|
|
2604
|
+
});
|
|
2605
|
+
ancestorResize && ancestor.addEventListener('resize', update);
|
|
2606
|
+
});
|
|
2607
|
+
const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update) : null;
|
|
2608
|
+
let reobserveFrame = -1;
|
|
2609
|
+
let resizeObserver = null;
|
|
2610
|
+
if (elementResize) {
|
|
2611
|
+
resizeObserver = new ResizeObserver(_ref => {
|
|
2612
|
+
let [firstEntry] = _ref;
|
|
2613
|
+
if (firstEntry && firstEntry.target === referenceEl && resizeObserver) {
|
|
2614
|
+
// Prevent update loops when using the `size` middleware.
|
|
2615
|
+
// https://github.com/floating-ui/floating-ui/issues/1740
|
|
2616
|
+
resizeObserver.unobserve(floating);
|
|
2617
|
+
cancelAnimationFrame(reobserveFrame);
|
|
2618
|
+
reobserveFrame = requestAnimationFrame(() => {
|
|
2619
|
+
var _resizeObserver;
|
|
2620
|
+
(_resizeObserver = resizeObserver) == null || _resizeObserver.observe(floating);
|
|
2621
|
+
});
|
|
2622
|
+
}
|
|
2623
|
+
update();
|
|
2624
|
+
});
|
|
2625
|
+
if (referenceEl && !animationFrame) {
|
|
2626
|
+
resizeObserver.observe(referenceEl);
|
|
2627
|
+
}
|
|
2628
|
+
resizeObserver.observe(floating);
|
|
2629
|
+
}
|
|
2630
|
+
let frameId;
|
|
2631
|
+
let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
|
|
2632
|
+
if (animationFrame) {
|
|
2633
|
+
frameLoop();
|
|
2634
|
+
}
|
|
2635
|
+
function frameLoop() {
|
|
2636
|
+
const nextRefRect = getBoundingClientRect(reference);
|
|
2637
|
+
if (prevRefRect && !rectsAreEqual(prevRefRect, nextRefRect)) {
|
|
2638
|
+
update();
|
|
2639
|
+
}
|
|
2640
|
+
prevRefRect = nextRefRect;
|
|
2641
|
+
frameId = requestAnimationFrame(frameLoop);
|
|
2642
|
+
}
|
|
2643
|
+
update();
|
|
2644
|
+
return () => {
|
|
2645
|
+
var _resizeObserver2;
|
|
2646
|
+
ancestors.forEach(ancestor => {
|
|
2647
|
+
ancestorScroll && ancestor.removeEventListener('scroll', update);
|
|
2648
|
+
ancestorResize && ancestor.removeEventListener('resize', update);
|
|
2649
|
+
});
|
|
2650
|
+
cleanupIo == null || cleanupIo();
|
|
2651
|
+
(_resizeObserver2 = resizeObserver) == null || _resizeObserver2.disconnect();
|
|
2652
|
+
resizeObserver = null;
|
|
2653
|
+
if (animationFrame) {
|
|
2654
|
+
cancelAnimationFrame(frameId);
|
|
2655
|
+
}
|
|
2656
|
+
};
|
|
2657
|
+
}
|
|
2658
|
+
|
|
2659
|
+
/**
|
|
2660
|
+
* Modifies the placement by translating the floating element along the
|
|
2661
|
+
* specified axes.
|
|
2662
|
+
* A number (shorthand for `mainAxis` or distance), or an axes configuration
|
|
2663
|
+
* object may be passed.
|
|
2664
|
+
* @see https://floating-ui.com/docs/offset
|
|
2665
|
+
*/
|
|
2666
|
+
const offset = offset$1;
|
|
2667
|
+
|
|
2668
|
+
/**
|
|
2669
|
+
* Optimizes the visibility of the floating element by shifting it in order to
|
|
2670
|
+
* keep it in view when it will overflow the clipping boundary.
|
|
2671
|
+
* @see https://floating-ui.com/docs/shift
|
|
2672
|
+
*/
|
|
2673
|
+
const shift = shift$1;
|
|
2674
|
+
|
|
2675
|
+
/**
|
|
2676
|
+
* Optimizes the visibility of the floating element by flipping the `placement`
|
|
2677
|
+
* in order to keep it in view when the preferred placement(s) will overflow the
|
|
2678
|
+
* clipping boundary. Alternative to `autoPlacement`.
|
|
2679
|
+
* @see https://floating-ui.com/docs/flip
|
|
2680
|
+
*/
|
|
2681
|
+
const flip = flip$1;
|
|
2682
|
+
|
|
2683
|
+
/**
|
|
2684
|
+
* Provides data to position an inner element of the floating element so that it
|
|
2685
|
+
* appears centered to the reference element.
|
|
2686
|
+
* @see https://floating-ui.com/docs/arrow
|
|
2687
|
+
*/
|
|
2688
|
+
const arrow = arrow$1;
|
|
2689
|
+
|
|
2690
|
+
/**
|
|
2691
|
+
* Computes the `x` and `y` coordinates that will place the floating element
|
|
2692
|
+
* next to a given reference element.
|
|
2693
|
+
*/
|
|
2694
|
+
const computePosition = (reference, floating, options) => {
|
|
2695
|
+
// This caches the expensive `getClippingElementAncestors` function so that
|
|
2696
|
+
// multiple lifecycle resets re-use the same result. It only lives for a
|
|
2697
|
+
// single call. If other functions become expensive, we can add them as well.
|
|
2698
|
+
const cache = new Map();
|
|
2699
|
+
const mergedOptions = {
|
|
2700
|
+
platform,
|
|
2701
|
+
...options
|
|
2702
|
+
};
|
|
2703
|
+
const platformWithCache = {
|
|
2704
|
+
...mergedOptions.platform,
|
|
2705
|
+
_c: cache
|
|
2706
|
+
};
|
|
2707
|
+
return computePosition$1(reference, floating, {
|
|
2708
|
+
...mergedOptions,
|
|
2709
|
+
platform: platformWithCache
|
|
2710
|
+
});
|
|
2711
|
+
};
|
|
2712
|
+
|
|
2713
|
+
var styles = css`/***************************** 1 ****************************************/
|
|
2714
|
+
/***************************** 2 ****************************************/
|
|
2715
|
+
/***************************** 1 ****************************************/
|
|
2716
|
+
/***************************** 2 ****************************************/
|
|
2717
|
+
/***************************** 1 ****************************************/
|
|
2718
|
+
/***************************** 2 ****************************************/
|
|
2719
|
+
/***************************** 3 ****************************************/
|
|
2720
|
+
/***************************** 1 ****************************************/
|
|
2721
|
+
/***************************** 2 ****************************************/
|
|
2722
|
+
/***************************** 3 ****************************************/
|
|
2723
|
+
/***************************** NEUTRAL 1 ****************************************/
|
|
2724
|
+
/***************************** NEUTRAL 2 ****************************************/
|
|
2725
|
+
/***************************** NEUTRAL 2 / 3 ****************************************/
|
|
2726
|
+
.fade {
|
|
2727
|
+
transition: opacity 0.15s linear;
|
|
2728
|
+
}
|
|
2729
|
+
@media (prefers-reduced-motion: reduce) {
|
|
2730
|
+
.fade {
|
|
2731
|
+
transition: none;
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2734
|
+
.fade:not(.show) {
|
|
2735
|
+
opacity: 0;
|
|
2736
|
+
}
|
|
2737
|
+
|
|
2738
|
+
.collapse:not(.show) {
|
|
2739
|
+
display: none;
|
|
2740
|
+
}
|
|
2741
|
+
|
|
2742
|
+
.collapsing {
|
|
2743
|
+
height: 0;
|
|
2744
|
+
overflow: hidden;
|
|
2745
|
+
transition: height 0.35s ease;
|
|
2746
|
+
}
|
|
2747
|
+
@media (prefers-reduced-motion: reduce) {
|
|
2748
|
+
.collapsing {
|
|
2749
|
+
transition: none;
|
|
2750
|
+
}
|
|
2751
|
+
}
|
|
2752
|
+
.collapsing.collapse-horizontal {
|
|
2753
|
+
width: 0;
|
|
2754
|
+
height: auto;
|
|
2755
|
+
transition: width 0.35s ease;
|
|
2756
|
+
}
|
|
2757
|
+
@media (prefers-reduced-motion: reduce) {
|
|
2758
|
+
.collapsing.collapse-horizontal {
|
|
2759
|
+
transition: none;
|
|
2760
|
+
}
|
|
2761
|
+
}
|
|
2762
|
+
|
|
2763
|
+
.tooltip {
|
|
2764
|
+
--bsi-tooltip-arrow-height: 0.4rem;
|
|
2765
|
+
--bsi-tooltip-arrow-width: 0.8rem;
|
|
2766
|
+
--bsi-tooltip-bg: var(--bsi-color-background-emphasis);
|
|
2767
|
+
--bsi-tooltip-border-radius: var(--bsi-radius-smooth);
|
|
2768
|
+
--bsi-tooltip-color: var(--bsi-color-text-inverse);
|
|
2769
|
+
--bsi-tooltip-font-size: var(--bsi-label-font-size-s);
|
|
2770
|
+
--bsi-tooltip-margin: 0;
|
|
2771
|
+
--bsi-tooltip-max-width: 32em;
|
|
2772
|
+
--bsi-tooltip-opacity: 1;
|
|
2773
|
+
--bsi-tooltip-padding-x: var(--bsi-spacing-3xs);
|
|
2774
|
+
--bsi-tooltip-padding-y: var(--bsi-spacing-xxs);
|
|
2775
|
+
--bsi-tooltip-zindex: 10;
|
|
2776
|
+
}
|
|
2777
|
+
|
|
2778
|
+
/* stylelint-disable-next-line no-duplicate-selectors */
|
|
2779
|
+
.tooltip {
|
|
2780
|
+
z-index: var(--bsi-tooltip-zindex);
|
|
2781
|
+
display: block;
|
|
2782
|
+
margin: var(--bsi-tooltip-margin);
|
|
2783
|
+
padding: var(--bsi-tooltip-arrow-height);
|
|
2784
|
+
border-radius: var(--bsi-tooltip-border-radius);
|
|
2785
|
+
opacity: 0;
|
|
2786
|
+
font-size: var(--bsi-tooltip-font-size);
|
|
2787
|
+
word-wrap: break-word;
|
|
2788
|
+
font-family: var(--bsi-font-sans-serif);
|
|
2789
|
+
font-style: normal;
|
|
2790
|
+
font-weight: 400;
|
|
2791
|
+
line-height: 1.5;
|
|
2792
|
+
text-align: left;
|
|
2793
|
+
text-align: start;
|
|
2794
|
+
text-decoration: none;
|
|
2795
|
+
text-shadow: none;
|
|
2796
|
+
text-transform: none;
|
|
2797
|
+
letter-spacing: normal;
|
|
2798
|
+
word-break: normal;
|
|
2799
|
+
white-space: normal;
|
|
2800
|
+
word-spacing: normal;
|
|
2801
|
+
line-break: auto;
|
|
2802
|
+
font-size: var(--bsi-tooltip-font-size);
|
|
2803
|
+
}
|
|
2804
|
+
.tooltip.show {
|
|
2805
|
+
opacity: var(--bsi-tooltip-opacity);
|
|
2806
|
+
}
|
|
2807
|
+
.tooltip .tooltip-arrow {
|
|
2808
|
+
display: none;
|
|
2809
|
+
}
|
|
2810
|
+
.tooltip .tooltip-inner {
|
|
2811
|
+
padding: var(--bsi-tooltip-padding-y) calc(var(--bsi-tooltip-padding-x) * 2);
|
|
2812
|
+
background-color: var(--bsi-tooltip-bg);
|
|
2813
|
+
}
|
|
2814
|
+
@media (min-width: 768px) {
|
|
2815
|
+
.tooltip .tooltip-inner .tooltip-inner {
|
|
2816
|
+
padding: calc(var(--bsi-tooltip-padding-x) * 0.5) var(--bsi-tooltip-padding-x);
|
|
2817
|
+
}
|
|
2818
|
+
}
|
|
2819
|
+
.tooltip .tooltip-inner a {
|
|
2820
|
+
color: var(--bsi-tooltip-color);
|
|
2821
|
+
text-decoration: underline;
|
|
2822
|
+
}
|
|
2823
|
+
.tooltip.bs-tooltip-top, .tooltip.bs-tooltip-auto[data-popper-placement^=top], .tooltip.bs-tooltip-bottom, .tooltip.bs-tooltip-auto[data-popper-placement^=bottom] {
|
|
2824
|
+
padding: var(--bsi-tooltip-padding-x) 0;
|
|
2825
|
+
}
|
|
2826
|
+
.tooltip.bs-tooltip-left, .tooltip.bs-tooltip-right {
|
|
2827
|
+
padding: 0 var(--bsi-tooltip-padding-x);
|
|
2828
|
+
}
|
|
2829
|
+
|
|
2830
|
+
.bs-tooltip-top .tooltip-arrow, .bs-tooltip-auto[data-popper-placement^=top] .tooltip-arrow {
|
|
2831
|
+
bottom: 0;
|
|
2832
|
+
}
|
|
2833
|
+
.bs-tooltip-top .tooltip-arrow::before, .bs-tooltip-auto[data-popper-placement^=top] .tooltip-arrow::before {
|
|
2834
|
+
top: -1px;
|
|
2835
|
+
border-width: var(--bsi-tooltip-arrow-height) calc(var(--bsi-tooltip-arrow-width) * 0.5) 0;
|
|
2836
|
+
border-top-color: var(--bsi-tooltip-bg);
|
|
2837
|
+
}
|
|
2838
|
+
|
|
2839
|
+
/* rtl:begin:ignore */
|
|
2840
|
+
.bs-tooltip-end .tooltip-arrow, .bs-tooltip-auto[data-popper-placement^=right] .tooltip-arrow {
|
|
2841
|
+
left: 0;
|
|
2842
|
+
width: var(--bsi-tooltip-arrow-height);
|
|
2843
|
+
height: var(--bsi-tooltip-arrow-width);
|
|
2844
|
+
}
|
|
2845
|
+
.bs-tooltip-end .tooltip-arrow::before, .bs-tooltip-auto[data-popper-placement^=right] .tooltip-arrow::before {
|
|
2846
|
+
right: -1px;
|
|
2847
|
+
border-width: calc(var(--bsi-tooltip-arrow-width) * 0.5) var(--bsi-tooltip-arrow-height) calc(var(--bsi-tooltip-arrow-width) * 0.5) 0;
|
|
2848
|
+
border-right-color: var(--bsi-tooltip-bg);
|
|
2849
|
+
}
|
|
2850
|
+
|
|
2851
|
+
/* rtl:end:ignore */
|
|
2852
|
+
.bs-tooltip-bottom .tooltip-arrow, .bs-tooltip-auto[data-popper-placement^=bottom] .tooltip-arrow {
|
|
2853
|
+
top: 0;
|
|
2854
|
+
}
|
|
2855
|
+
.bs-tooltip-bottom .tooltip-arrow::before, .bs-tooltip-auto[data-popper-placement^=bottom] .tooltip-arrow::before {
|
|
2856
|
+
bottom: -1px;
|
|
2857
|
+
border-width: 0 calc(var(--bsi-tooltip-arrow-width) * 0.5) var(--bsi-tooltip-arrow-height);
|
|
2858
|
+
border-bottom-color: var(--bsi-tooltip-bg);
|
|
2859
|
+
}
|
|
2860
|
+
|
|
2861
|
+
/* rtl:begin:ignore */
|
|
2862
|
+
.bs-tooltip-start .tooltip-arrow, .bs-tooltip-auto[data-popper-placement^=left] .tooltip-arrow {
|
|
2863
|
+
right: 0;
|
|
2864
|
+
width: var(--bsi-tooltip-arrow-height);
|
|
2865
|
+
height: var(--bsi-tooltip-arrow-width);
|
|
2866
|
+
}
|
|
2867
|
+
.bs-tooltip-start .tooltip-arrow::before, .bs-tooltip-auto[data-popper-placement^=left] .tooltip-arrow::before {
|
|
2868
|
+
left: -1px;
|
|
2869
|
+
border-width: calc(var(--bsi-tooltip-arrow-width) * 0.5) 0 calc(var(--bsi-tooltip-arrow-width) * 0.5) var(--bsi-tooltip-arrow-height);
|
|
2870
|
+
border-left-color: var(--bsi-tooltip-bg);
|
|
2871
|
+
}
|
|
2872
|
+
|
|
2873
|
+
/* rtl:end:ignore */
|
|
2874
|
+
.tooltip-inner {
|
|
2875
|
+
max-width: var(--bsi-tooltip-max-width);
|
|
2876
|
+
padding: var(--bsi-tooltip-padding-y) var(--bsi-tooltip-padding-x);
|
|
2877
|
+
background-color: var(--bsi-tooltip-bg);
|
|
2878
|
+
color: var(--bsi-tooltip-color);
|
|
2879
|
+
text-align: center;
|
|
2880
|
+
border-radius: var(--bsi-tooltip-border-radius);
|
|
2881
|
+
}
|
|
2882
|
+
|
|
2883
|
+
.tooltip {
|
|
2884
|
+
position: absolute;
|
|
2885
|
+
visibility: hidden;
|
|
2886
|
+
}`;
|
|
2887
|
+
|
|
2888
|
+
var ItTooltip_1;
|
|
2889
|
+
const BSI_PLACEMENT_CLASSES = {
|
|
2890
|
+
top: 'bs-tooltip-top',
|
|
2891
|
+
right: 'bs-tooltip-end',
|
|
2892
|
+
bottom: 'bs-tooltip-bottom',
|
|
2893
|
+
left: 'bs-tooltip-start',
|
|
2894
|
+
};
|
|
2895
|
+
let ItTooltip = ItTooltip_1 = class ItTooltip extends BaseComponent {
|
|
2896
|
+
constructor() {
|
|
2897
|
+
super(...arguments);
|
|
2898
|
+
this.open = false;
|
|
2899
|
+
this.controlled = false;
|
|
2900
|
+
this.placement = 'top';
|
|
2901
|
+
this.noFlip = false;
|
|
2902
|
+
this.isTransitioning = false;
|
|
2903
|
+
this._contentElement = null;
|
|
2904
|
+
this._lastTrigger = null;
|
|
2905
|
+
this._onMouseEnter = () => {
|
|
2906
|
+
if (!this.controlled)
|
|
2907
|
+
this.showTooltip();
|
|
2908
|
+
};
|
|
2909
|
+
this._onMouseLeave = (e) => {
|
|
2910
|
+
if (!this.controlled) {
|
|
2911
|
+
const rt = e.relatedTarget;
|
|
2912
|
+
// When mouse moves to the tooltip (shadow DOM), relatedTarget is retargeted to the host
|
|
2913
|
+
if (rt === this || this._tooltipElement?.contains(rt))
|
|
2914
|
+
return;
|
|
2915
|
+
this.hideTooltip();
|
|
2916
|
+
}
|
|
2917
|
+
};
|
|
2918
|
+
this._onTooltipMouseLeave = (e) => {
|
|
2919
|
+
if (!this.controlled) {
|
|
2920
|
+
const rt = e.relatedTarget;
|
|
2921
|
+
// When mouse moves back to trigger (light DOM), relatedTarget is retargeted to the host
|
|
2922
|
+
if (rt === this || rt === this._triggerElement || this._triggerElement?.contains(rt))
|
|
2923
|
+
return;
|
|
2924
|
+
this.hideTooltip();
|
|
2925
|
+
}
|
|
2926
|
+
};
|
|
2927
|
+
this._onFocusIn = () => {
|
|
2928
|
+
if (!this.controlled)
|
|
2929
|
+
this.showTooltip();
|
|
2930
|
+
};
|
|
2931
|
+
this._onFocusOut = () => {
|
|
2932
|
+
if (!this.controlled)
|
|
2933
|
+
this.hideTooltip();
|
|
2934
|
+
};
|
|
2935
|
+
this._onKeyDown = (e) => {
|
|
2936
|
+
if (e.key === 'Escape' && this.open && !this.controlled)
|
|
2937
|
+
this.hideTooltip();
|
|
2938
|
+
};
|
|
2939
|
+
}
|
|
2940
|
+
get _triggerElement() {
|
|
2941
|
+
return this._triggerSlot?.assignedElements({ flatten: true })[0] ?? null;
|
|
2942
|
+
}
|
|
2943
|
+
disconnectedCallback() {
|
|
2944
|
+
super.disconnectedCallback?.();
|
|
2945
|
+
this._removeListeners();
|
|
2946
|
+
this._cleanup?.();
|
|
2947
|
+
this._contentElement?.removeAttribute('role');
|
|
2948
|
+
this._contentElement?.removeAttribute('id');
|
|
2949
|
+
this._contentElement?.removeAttribute('aria-hidden');
|
|
2950
|
+
this._cleanupDescribedBy();
|
|
2951
|
+
}
|
|
2952
|
+
_cleanupDescribedBy() {
|
|
2953
|
+
if (!this._lastTrigger)
|
|
2954
|
+
return;
|
|
2955
|
+
if ('setDescribedBy' in this._lastTrigger && typeof this._lastTrigger.setDescribedBy === 'function') {
|
|
2956
|
+
this._lastTrigger.setDescribedBy(null);
|
|
2957
|
+
}
|
|
2958
|
+
else {
|
|
2959
|
+
this._lastTrigger.removeAttribute('aria-describedby');
|
|
2960
|
+
}
|
|
2961
|
+
}
|
|
2962
|
+
firstUpdated(_changedProperties) {
|
|
2963
|
+
super.firstUpdated(_changedProperties);
|
|
2964
|
+
this._setupAria();
|
|
2965
|
+
if (!this.controlled)
|
|
2966
|
+
this._setupStandardEvents();
|
|
2967
|
+
}
|
|
2968
|
+
updated(changedProps) {
|
|
2969
|
+
if (changedProps.has('open')) {
|
|
2970
|
+
if (this.open) {
|
|
2971
|
+
this._contentElement?.removeAttribute('aria-hidden');
|
|
2972
|
+
this._show();
|
|
2973
|
+
this.dispatchEvent(new CustomEvent('it-tooltip-open', { bubbles: true, composed: true }));
|
|
2974
|
+
}
|
|
2975
|
+
else {
|
|
2976
|
+
this._contentElement?.setAttribute('aria-hidden', 'true');
|
|
2977
|
+
this._hide();
|
|
2978
|
+
this.dispatchEvent(new CustomEvent('it-tooltip-close', { bubbles: true, composed: true }));
|
|
2979
|
+
}
|
|
2980
|
+
}
|
|
2981
|
+
}
|
|
2982
|
+
_setupAria() {
|
|
2983
|
+
this._contentElement?.removeAttribute('role');
|
|
2984
|
+
this._contentElement?.removeAttribute('id');
|
|
2985
|
+
this._cleanupDescribedBy();
|
|
2986
|
+
const trigger = this._triggerElement;
|
|
2987
|
+
const content = this._contentSlot?.assignedElements({ flatten: true })[0];
|
|
2988
|
+
if (!trigger || !content || !this._id)
|
|
2989
|
+
return;
|
|
2990
|
+
this._contentElement = content;
|
|
2991
|
+
this._lastTrigger = trigger;
|
|
2992
|
+
if (!content.id)
|
|
2993
|
+
content.id = this._id;
|
|
2994
|
+
content.setAttribute('role', 'tooltip');
|
|
2995
|
+
if (this.open) {
|
|
2996
|
+
content.removeAttribute('aria-hidden');
|
|
2997
|
+
}
|
|
2998
|
+
else {
|
|
2999
|
+
content.setAttribute('aria-hidden', 'true');
|
|
3000
|
+
}
|
|
3001
|
+
if ('setDescribedBy' in trigger && typeof trigger.setDescribedBy === 'function') {
|
|
3002
|
+
trigger.setDescribedBy(content);
|
|
3003
|
+
}
|
|
3004
|
+
else {
|
|
3005
|
+
trigger.setAttribute('aria-describedby', content.id);
|
|
3006
|
+
}
|
|
3007
|
+
}
|
|
3008
|
+
_setupStandardEvents() {
|
|
3009
|
+
this._removeListeners();
|
|
3010
|
+
const trigger = this._triggerElement;
|
|
3011
|
+
if (!trigger)
|
|
3012
|
+
return;
|
|
3013
|
+
trigger.addEventListener('mouseenter', this._onMouseEnter);
|
|
3014
|
+
trigger.addEventListener('mouseleave', this._onMouseLeave);
|
|
3015
|
+
trigger.addEventListener('focusin', this._onFocusIn);
|
|
3016
|
+
trigger.addEventListener('focusout', this._onFocusOut);
|
|
3017
|
+
trigger.addEventListener('keydown', this._onKeyDown);
|
|
3018
|
+
}
|
|
3019
|
+
_removeListeners() {
|
|
3020
|
+
const trigger = this._triggerElement;
|
|
3021
|
+
if (!trigger)
|
|
3022
|
+
return;
|
|
3023
|
+
trigger.removeEventListener('mouseenter', this._onMouseEnter);
|
|
3024
|
+
trigger.removeEventListener('mouseleave', this._onMouseLeave);
|
|
3025
|
+
trigger.removeEventListener('focusin', this._onFocusIn);
|
|
3026
|
+
trigger.removeEventListener('focusout', this._onFocusOut);
|
|
3027
|
+
trigger.removeEventListener('keydown', this._onKeyDown);
|
|
3028
|
+
}
|
|
3029
|
+
_show() {
|
|
3030
|
+
if (this.isTransitioning) {
|
|
3031
|
+
return;
|
|
3032
|
+
}
|
|
3033
|
+
const trigger = this._triggerElement;
|
|
3034
|
+
if (!trigger || !this._tooltipElement)
|
|
3035
|
+
return;
|
|
3036
|
+
this._cleanup = autoUpdate(trigger, this._tooltipElement, () => {
|
|
3037
|
+
computePosition(trigger, this._tooltipElement, {
|
|
3038
|
+
placement: this.placement,
|
|
3039
|
+
middleware: [
|
|
3040
|
+
offset(ItTooltip_1.OFFSET),
|
|
3041
|
+
flip({ mainAxis: !this.noFlip, crossAxis: !this.noFlip }),
|
|
3042
|
+
shift({ padding: 8 }),
|
|
3043
|
+
arrow({ element: this._arrowElement }),
|
|
3044
|
+
],
|
|
3045
|
+
}).then(({ x, y, placement: finalPlacement, middlewareData }) => {
|
|
3046
|
+
Object.assign(this._tooltipElement.style, {
|
|
3047
|
+
visibility: 'visible',
|
|
3048
|
+
left: `${x}px`,
|
|
3049
|
+
top: `${y}px`,
|
|
3050
|
+
});
|
|
3051
|
+
const side = finalPlacement.split('-')[0];
|
|
3052
|
+
Object.values(BSI_PLACEMENT_CLASSES).forEach((c) => this._tooltipElement.classList.remove(c));
|
|
3053
|
+
this._tooltipElement.classList.add(BSI_PLACEMENT_CLASSES[side]);
|
|
3054
|
+
const { x: arrowX, y: arrowY } = middlewareData.arrow ?? {};
|
|
3055
|
+
const staticSide = { top: 'bottom', right: 'left', bottom: 'top', left: 'right' }[side];
|
|
3056
|
+
Object.assign(this._arrowElement.style, {
|
|
3057
|
+
left: arrowX != null ? `${arrowX}px` : '',
|
|
3058
|
+
top: arrowY != null ? `${arrowY}px` : '',
|
|
3059
|
+
right: '',
|
|
3060
|
+
bottom: '',
|
|
3061
|
+
[staticSide]: '-4px',
|
|
3062
|
+
position: 'absolute',
|
|
3063
|
+
});
|
|
3064
|
+
});
|
|
3065
|
+
});
|
|
3066
|
+
}
|
|
3067
|
+
_hide() {
|
|
3068
|
+
this.isTransitioning = true;
|
|
3069
|
+
setTimeout(() => {
|
|
3070
|
+
this._cleanup?.();
|
|
3071
|
+
this._tooltipElement.style.visibility = 'hidden';
|
|
3072
|
+
Object.values(BSI_PLACEMENT_CLASSES).forEach((c) => this._tooltipElement.classList.remove(c));
|
|
3073
|
+
this.isTransitioning = false;
|
|
3074
|
+
}, ItTooltip_1.TRANSITION_DURATION);
|
|
3075
|
+
}
|
|
3076
|
+
showTooltip() {
|
|
3077
|
+
this.open = true;
|
|
3078
|
+
}
|
|
3079
|
+
hideTooltip() {
|
|
3080
|
+
this.open = false;
|
|
3081
|
+
}
|
|
3082
|
+
toggle() {
|
|
3083
|
+
this.open = !this.open;
|
|
3084
|
+
}
|
|
3085
|
+
render() {
|
|
3086
|
+
const classes = this.composeClass('tooltip fade', {
|
|
3087
|
+
show: this.open,
|
|
3088
|
+
});
|
|
3089
|
+
return html `
|
|
3090
|
+
<slot
|
|
3091
|
+
name="trigger"
|
|
3092
|
+
part="trigger"
|
|
3093
|
+
@slotchange=${() => {
|
|
3094
|
+
this._setupAria();
|
|
3095
|
+
if (!this.controlled)
|
|
3096
|
+
this._setupStandardEvents();
|
|
3097
|
+
}}
|
|
3098
|
+
></slot>
|
|
3099
|
+
<div class=${classes} @mouseleave=${this._onTooltipMouseLeave}>
|
|
3100
|
+
<div class="tooltip-arrow"></div>
|
|
3101
|
+
<div class="tooltip-inner"><slot name="content" @slotchange=${() => this._setupAria()}></slot></div>
|
|
3102
|
+
</div>
|
|
3103
|
+
`;
|
|
3104
|
+
}
|
|
3105
|
+
};
|
|
3106
|
+
ItTooltip.styles = styles;
|
|
3107
|
+
ItTooltip.OFFSET = 0;
|
|
3108
|
+
ItTooltip.TRANSITION_DURATION = 150;
|
|
3109
|
+
__decorate([
|
|
3110
|
+
property({ type: Boolean, reflect: true }),
|
|
3111
|
+
__metadata("design:type", Object)
|
|
3112
|
+
], ItTooltip.prototype, "open", void 0);
|
|
3113
|
+
__decorate([
|
|
3114
|
+
property({ type: Boolean }),
|
|
3115
|
+
__metadata("design:type", Object)
|
|
3116
|
+
], ItTooltip.prototype, "controlled", void 0);
|
|
3117
|
+
__decorate([
|
|
3118
|
+
property({ type: String }),
|
|
3119
|
+
__metadata("design:type", String)
|
|
3120
|
+
], ItTooltip.prototype, "placement", void 0);
|
|
3121
|
+
__decorate([
|
|
3122
|
+
property({ type: Boolean, attribute: 'no-flip' }),
|
|
3123
|
+
__metadata("design:type", Boolean)
|
|
3124
|
+
], ItTooltip.prototype, "noFlip", void 0);
|
|
3125
|
+
__decorate([
|
|
3126
|
+
query('slot[name="trigger"]'),
|
|
3127
|
+
__metadata("design:type", HTMLSlotElement)
|
|
3128
|
+
], ItTooltip.prototype, "_triggerSlot", void 0);
|
|
3129
|
+
__decorate([
|
|
3130
|
+
query('slot[name="content"]'),
|
|
3131
|
+
__metadata("design:type", HTMLSlotElement)
|
|
3132
|
+
], ItTooltip.prototype, "_contentSlot", void 0);
|
|
3133
|
+
__decorate([
|
|
3134
|
+
query('.tooltip'),
|
|
3135
|
+
__metadata("design:type", HTMLElement)
|
|
3136
|
+
], ItTooltip.prototype, "_tooltipElement", void 0);
|
|
3137
|
+
__decorate([
|
|
3138
|
+
query('.tooltip-arrow'),
|
|
3139
|
+
__metadata("design:type", HTMLElement)
|
|
3140
|
+
], ItTooltip.prototype, "_arrowElement", void 0);
|
|
3141
|
+
ItTooltip = ItTooltip_1 = __decorate([
|
|
3142
|
+
customElement('it-tooltip')
|
|
3143
|
+
], ItTooltip);
|
|
3144
|
+
|
|
3145
|
+
export { ItTooltip };
|
|
3146
|
+
//# sourceMappingURL=it-tooltip.js.map
|