@italia/popover 0.1.0-alpha.2 → 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/README.md +57 -9
- package/custom-elements.json +189 -0
- package/dist/src/it-popover.d.ts +6 -1
- package/dist/src/it-popover.d.ts.map +1 -1
- package/dist/src/it-popover.js +210 -184
- package/dist/src/it-popover.js.map +1 -1
- package/package.json +8 -4
- package/styles/globals.scss +19 -0
package/dist/src/it-popover.js
CHANGED
|
@@ -113,7 +113,9 @@ function registerTranslation(...translation) {
|
|
|
113
113
|
});
|
|
114
114
|
update();
|
|
115
115
|
}
|
|
116
|
-
window
|
|
116
|
+
if (typeof window !== 'undefined') {
|
|
117
|
+
window.registerTranslation = registerTranslation;
|
|
118
|
+
}
|
|
117
119
|
/**
|
|
118
120
|
* Localize Reactive Controller for components built with Lit
|
|
119
121
|
*
|
|
@@ -436,6 +438,7 @@ const interactions = new WeakMap();
|
|
|
436
438
|
/** A reactive controller to allow form controls to participate in form submission, validation, etc. */
|
|
437
439
|
class FormControlController {
|
|
438
440
|
constructor(host, options) {
|
|
441
|
+
this.submittedOnce = false;
|
|
439
442
|
this.handleFormData = (event) => {
|
|
440
443
|
// console.log('handleFormData');
|
|
441
444
|
const disabled = this.options.disabled(this.host);
|
|
@@ -457,6 +460,27 @@ class FormControlController {
|
|
|
457
460
|
event.formData.append(name, value);
|
|
458
461
|
}
|
|
459
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;
|
|
460
484
|
default:
|
|
461
485
|
if (Array.isArray(value)) {
|
|
462
486
|
value.forEach((val) => {
|
|
@@ -478,13 +502,30 @@ class FormControlController {
|
|
|
478
502
|
this.setUserInteracted(control, true);
|
|
479
503
|
});
|
|
480
504
|
}
|
|
481
|
-
|
|
505
|
+
const resReportValidity = reportValidity(this.host);
|
|
506
|
+
if (this.form && !this.form.noValidate && !disabled && !resReportValidity) {
|
|
482
507
|
event.preventDefault();
|
|
483
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
|
+
}
|
|
484
523
|
}
|
|
524
|
+
this.submittedOnce = true;
|
|
485
525
|
};
|
|
486
526
|
this.handleFormReset = () => {
|
|
487
527
|
this.options.setValue(this.host, '');
|
|
528
|
+
this.submittedOnce = false;
|
|
488
529
|
this.setUserInteracted(this.host, false);
|
|
489
530
|
interactions.set(this.host, []);
|
|
490
531
|
};
|
|
@@ -649,6 +690,7 @@ class FormControlController {
|
|
|
649
690
|
if (!formCollection) {
|
|
650
691
|
return;
|
|
651
692
|
}
|
|
693
|
+
this.submittedOnce = false;
|
|
652
694
|
// Remove this host from the form's collection
|
|
653
695
|
formCollection.delete(this.host);
|
|
654
696
|
// Check to make sure there's no other form controls in the collection. If we do this
|
|
@@ -745,6 +787,10 @@ class FormControlController {
|
|
|
745
787
|
host.toggleAttribute('data-user-invalid', !isValid && hasInteracted);
|
|
746
788
|
host.toggleAttribute('data-user-valid', isValid && hasInteracted);
|
|
747
789
|
}
|
|
790
|
+
userInteracted() {
|
|
791
|
+
const hasInteracted = Boolean(userInteractedControls.has(this.host));
|
|
792
|
+
return hasInteracted;
|
|
793
|
+
}
|
|
748
794
|
/**
|
|
749
795
|
* Updates the form control's validity based on the current value of `host.validity.valid`. Call this when anything
|
|
750
796
|
* that affects constraint validation changes so the component receives the correct validity states.
|
|
@@ -781,6 +827,7 @@ const translation = {
|
|
|
781
827
|
$name: 'Italiano',
|
|
782
828
|
$dir: 'ltr',
|
|
783
829
|
validityRequired: 'Questo campo è obbligatorio.',
|
|
830
|
+
validityGroupRequired: "Scegli almeno un'opzione",
|
|
784
831
|
validityPattern: 'Il valore non corrisponde al formato richiesto.',
|
|
785
832
|
validityMinlength: 'Il valore deve essere lungo almeno {minlength} caratteri.',
|
|
786
833
|
validityMaxlength: 'Il valore deve essere lungo al massimo {maxlength} caratteri.',
|
|
@@ -825,24 +872,27 @@ class FormControl extends BaseLocalizedComponent {
|
|
|
825
872
|
this.maxlength = -1;
|
|
826
873
|
/** If the input is required. */
|
|
827
874
|
this.required = false;
|
|
875
|
+
/* For grouped input, like checkbox-group */
|
|
876
|
+
this.isInGroup = false;
|
|
828
877
|
this.validationMessage = '';
|
|
829
878
|
}
|
|
830
879
|
/** Gets the validity state object */
|
|
831
880
|
get validity() {
|
|
832
881
|
return this.inputElement?.validity;
|
|
833
882
|
}
|
|
883
|
+
/** Gets the associated form, if one exists. */
|
|
884
|
+
getForm() {
|
|
885
|
+
return this.formControlController.getForm();
|
|
886
|
+
}
|
|
834
887
|
// Form validation methods
|
|
835
888
|
checkValidity() {
|
|
836
889
|
const inputValid = this.inputElement?.checkValidity() ?? true; // this.inputElement.checkValidity() è la validazione del browser
|
|
837
890
|
return inputValid;
|
|
838
891
|
}
|
|
839
|
-
/** Gets the associated form, if one exists. */
|
|
840
|
-
getForm() {
|
|
841
|
-
return this.formControlController.getForm();
|
|
842
|
-
}
|
|
843
892
|
/** Checks for validity and shows the browser's validation message if the control is invalid. */
|
|
844
893
|
reportValidity() {
|
|
845
|
-
const ret = this.inputElement.checkValidity();
|
|
894
|
+
// const ret = this.inputElement.checkValidity();
|
|
895
|
+
const ret = this.checkValidity(); // chiama la checkValidity, che se è stata overridata chiama quella
|
|
846
896
|
this.handleValidationMessages();
|
|
847
897
|
return ret; // this.inputElement.reportValidity();
|
|
848
898
|
}
|
|
@@ -887,7 +937,8 @@ class FormControl extends BaseLocalizedComponent {
|
|
|
887
937
|
handleValidationMessages() {
|
|
888
938
|
if (!this.customValidation) {
|
|
889
939
|
const _v = this.inputElement.validity;
|
|
890
|
-
|
|
940
|
+
const isRequiredHandledByGroup = this.isInGroup === true;
|
|
941
|
+
if (_v.valueMissing && !isRequiredHandledByGroup) {
|
|
891
942
|
this.setCustomValidity(this.$t('validityRequired'));
|
|
892
943
|
}
|
|
893
944
|
else if (_v.patternMismatch) {
|
|
@@ -958,7 +1009,7 @@ class FormControl extends BaseLocalizedComponent {
|
|
|
958
1009
|
if (this.customValidation) {
|
|
959
1010
|
this.setCustomValidity(this.validationText ?? '');
|
|
960
1011
|
}
|
|
961
|
-
else {
|
|
1012
|
+
else if (this.formControlController.userInteracted()) {
|
|
962
1013
|
this.formControlController.updateValidity();
|
|
963
1014
|
}
|
|
964
1015
|
}
|
|
@@ -1026,11 +1077,23 @@ __decorate([
|
|
|
1026
1077
|
,
|
|
1027
1078
|
__metadata("design:type", Object)
|
|
1028
1079
|
], FormControl.prototype, "required", void 0);
|
|
1080
|
+
__decorate([
|
|
1081
|
+
property({ type: Boolean }),
|
|
1082
|
+
__metadata("design:type", Object)
|
|
1083
|
+
], FormControl.prototype, "isInGroup", void 0);
|
|
1029
1084
|
__decorate([
|
|
1030
1085
|
state(),
|
|
1031
1086
|
__metadata("design:type", Object)
|
|
1032
1087
|
], FormControl.prototype, "validationMessage", void 0);
|
|
1033
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
|
+
|
|
1034
1097
|
/**
|
|
1035
1098
|
* Custom positioning reference element.
|
|
1036
1099
|
* @see https://floating-ui.com/docs/virtual-elements
|
|
@@ -1222,6 +1285,71 @@ function computeCoordsFromPlacement(_ref, placement, rtl) {
|
|
|
1222
1285
|
return coords;
|
|
1223
1286
|
}
|
|
1224
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
|
+
|
|
1225
1353
|
/**
|
|
1226
1354
|
* Computes the `x` and `y` coordinates that will place the floating element
|
|
1227
1355
|
* next to a given reference element.
|
|
@@ -1251,6 +1379,7 @@ const computePosition$1 = async (reference, floating, config) => {
|
|
|
1251
1379
|
let middlewareData = {};
|
|
1252
1380
|
let resetCount = 0;
|
|
1253
1381
|
for (let i = 0; i < validMiddleware.length; i++) {
|
|
1382
|
+
var _platform$detectOverf;
|
|
1254
1383
|
const {
|
|
1255
1384
|
name,
|
|
1256
1385
|
fn
|
|
@@ -1268,7 +1397,10 @@ const computePosition$1 = async (reference, floating, config) => {
|
|
|
1268
1397
|
strategy,
|
|
1269
1398
|
middlewareData,
|
|
1270
1399
|
rects,
|
|
1271
|
-
platform
|
|
1400
|
+
platform: {
|
|
1401
|
+
...platform,
|
|
1402
|
+
detectOverflow: (_platform$detectOverf = platform.detectOverflow) != null ? _platform$detectOverf : detectOverflow
|
|
1403
|
+
},
|
|
1272
1404
|
elements: {
|
|
1273
1405
|
reference,
|
|
1274
1406
|
floating
|
|
@@ -1313,71 +1445,6 @@ const computePosition$1 = async (reference, floating, config) => {
|
|
|
1313
1445
|
};
|
|
1314
1446
|
};
|
|
1315
1447
|
|
|
1316
|
-
/**
|
|
1317
|
-
* Resolves with an object of overflow side offsets that determine how much the
|
|
1318
|
-
* element is overflowing a given clipping boundary on each side.
|
|
1319
|
-
* - positive = overflowing the boundary by that number of pixels
|
|
1320
|
-
* - negative = how many pixels left before it will overflow
|
|
1321
|
-
* - 0 = lies flush with the boundary
|
|
1322
|
-
* @see https://floating-ui.com/docs/detectOverflow
|
|
1323
|
-
*/
|
|
1324
|
-
async function detectOverflow(state, options) {
|
|
1325
|
-
var _await$platform$isEle;
|
|
1326
|
-
if (options === void 0) {
|
|
1327
|
-
options = {};
|
|
1328
|
-
}
|
|
1329
|
-
const {
|
|
1330
|
-
x,
|
|
1331
|
-
y,
|
|
1332
|
-
platform,
|
|
1333
|
-
rects,
|
|
1334
|
-
elements,
|
|
1335
|
-
strategy
|
|
1336
|
-
} = state;
|
|
1337
|
-
const {
|
|
1338
|
-
boundary = 'clippingAncestors',
|
|
1339
|
-
rootBoundary = 'viewport',
|
|
1340
|
-
elementContext = 'floating',
|
|
1341
|
-
altBoundary = false,
|
|
1342
|
-
padding = 0
|
|
1343
|
-
} = evaluate(options, state);
|
|
1344
|
-
const paddingObject = getPaddingObject(padding);
|
|
1345
|
-
const altContext = elementContext === 'floating' ? 'reference' : 'floating';
|
|
1346
|
-
const element = elements[altBoundary ? altContext : elementContext];
|
|
1347
|
-
const clippingClientRect = rectToClientRect(await platform.getClippingRect({
|
|
1348
|
-
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))),
|
|
1349
|
-
boundary,
|
|
1350
|
-
rootBoundary,
|
|
1351
|
-
strategy
|
|
1352
|
-
}));
|
|
1353
|
-
const rect = elementContext === 'floating' ? {
|
|
1354
|
-
x,
|
|
1355
|
-
y,
|
|
1356
|
-
width: rects.floating.width,
|
|
1357
|
-
height: rects.floating.height
|
|
1358
|
-
} : rects.reference;
|
|
1359
|
-
const offsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating));
|
|
1360
|
-
const offsetScale = (await (platform.isElement == null ? void 0 : platform.isElement(offsetParent))) ? (await (platform.getScale == null ? void 0 : platform.getScale(offsetParent))) || {
|
|
1361
|
-
x: 1,
|
|
1362
|
-
y: 1
|
|
1363
|
-
} : {
|
|
1364
|
-
x: 1,
|
|
1365
|
-
y: 1
|
|
1366
|
-
};
|
|
1367
|
-
const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
|
|
1368
|
-
elements,
|
|
1369
|
-
rect,
|
|
1370
|
-
offsetParent,
|
|
1371
|
-
strategy
|
|
1372
|
-
}) : rect);
|
|
1373
|
-
return {
|
|
1374
|
-
top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
|
|
1375
|
-
bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
|
|
1376
|
-
left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
|
|
1377
|
-
right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
|
|
1378
|
-
};
|
|
1379
|
-
}
|
|
1380
|
-
|
|
1381
1448
|
/**
|
|
1382
1449
|
* Provides data to position an inner element of the floating element so that it
|
|
1383
1450
|
* appears centered to the reference element.
|
|
@@ -1510,7 +1577,7 @@ const flip$1 = function (options) {
|
|
|
1510
1577
|
fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
|
|
1511
1578
|
}
|
|
1512
1579
|
const placements = [initialPlacement, ...fallbackPlacements];
|
|
1513
|
-
const overflow = await detectOverflow(state, detectOverflowOptions);
|
|
1580
|
+
const overflow = await platform.detectOverflow(state, detectOverflowOptions);
|
|
1514
1581
|
const overflows = [];
|
|
1515
1582
|
let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
|
|
1516
1583
|
if (checkMainAxis) {
|
|
@@ -1694,7 +1761,8 @@ const shift$1 = function (options) {
|
|
|
1694
1761
|
const {
|
|
1695
1762
|
x,
|
|
1696
1763
|
y,
|
|
1697
|
-
placement
|
|
1764
|
+
placement,
|
|
1765
|
+
platform
|
|
1698
1766
|
} = state;
|
|
1699
1767
|
const {
|
|
1700
1768
|
mainAxis: checkMainAxis = true,
|
|
@@ -1717,7 +1785,7 @@ const shift$1 = function (options) {
|
|
|
1717
1785
|
x,
|
|
1718
1786
|
y
|
|
1719
1787
|
};
|
|
1720
|
-
const overflow = await detectOverflow(state, detectOverflowOptions);
|
|
1788
|
+
const overflow = await platform.detectOverflow(state, detectOverflowOptions);
|
|
1721
1789
|
const crossAxis = getSideAxis(getSide(placement));
|
|
1722
1790
|
const mainAxis = getOppositeAxis(crossAxis);
|
|
1723
1791
|
let mainAxisCoord = coords[mainAxis];
|
|
@@ -1756,90 +1824,6 @@ const shift$1 = function (options) {
|
|
|
1756
1824
|
};
|
|
1757
1825
|
};
|
|
1758
1826
|
|
|
1759
|
-
/**
|
|
1760
|
-
* Provides data that allows you to change the size of the floating element —
|
|
1761
|
-
* for instance, prevent it from overflowing the clipping boundary or match the
|
|
1762
|
-
* width of the reference element.
|
|
1763
|
-
* @see https://floating-ui.com/docs/size
|
|
1764
|
-
*/
|
|
1765
|
-
const size$1 = function (options) {
|
|
1766
|
-
if (options === void 0) {
|
|
1767
|
-
options = {};
|
|
1768
|
-
}
|
|
1769
|
-
return {
|
|
1770
|
-
name: 'size',
|
|
1771
|
-
options,
|
|
1772
|
-
async fn(state) {
|
|
1773
|
-
var _state$middlewareData, _state$middlewareData2;
|
|
1774
|
-
const {
|
|
1775
|
-
placement,
|
|
1776
|
-
rects,
|
|
1777
|
-
platform,
|
|
1778
|
-
elements
|
|
1779
|
-
} = state;
|
|
1780
|
-
const {
|
|
1781
|
-
apply = () => {},
|
|
1782
|
-
...detectOverflowOptions
|
|
1783
|
-
} = evaluate(options, state);
|
|
1784
|
-
const overflow = await detectOverflow(state, detectOverflowOptions);
|
|
1785
|
-
const side = getSide(placement);
|
|
1786
|
-
const alignment = getAlignment(placement);
|
|
1787
|
-
const isYAxis = getSideAxis(placement) === 'y';
|
|
1788
|
-
const {
|
|
1789
|
-
width,
|
|
1790
|
-
height
|
|
1791
|
-
} = rects.floating;
|
|
1792
|
-
let heightSide;
|
|
1793
|
-
let widthSide;
|
|
1794
|
-
if (side === 'top' || side === 'bottom') {
|
|
1795
|
-
heightSide = side;
|
|
1796
|
-
widthSide = alignment === ((await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating))) ? 'start' : 'end') ? 'left' : 'right';
|
|
1797
|
-
} else {
|
|
1798
|
-
widthSide = side;
|
|
1799
|
-
heightSide = alignment === 'end' ? 'top' : 'bottom';
|
|
1800
|
-
}
|
|
1801
|
-
const maximumClippingHeight = height - overflow.top - overflow.bottom;
|
|
1802
|
-
const maximumClippingWidth = width - overflow.left - overflow.right;
|
|
1803
|
-
const overflowAvailableHeight = min(height - overflow[heightSide], maximumClippingHeight);
|
|
1804
|
-
const overflowAvailableWidth = min(width - overflow[widthSide], maximumClippingWidth);
|
|
1805
|
-
const noShift = !state.middlewareData.shift;
|
|
1806
|
-
let availableHeight = overflowAvailableHeight;
|
|
1807
|
-
let availableWidth = overflowAvailableWidth;
|
|
1808
|
-
if ((_state$middlewareData = state.middlewareData.shift) != null && _state$middlewareData.enabled.x) {
|
|
1809
|
-
availableWidth = maximumClippingWidth;
|
|
1810
|
-
}
|
|
1811
|
-
if ((_state$middlewareData2 = state.middlewareData.shift) != null && _state$middlewareData2.enabled.y) {
|
|
1812
|
-
availableHeight = maximumClippingHeight;
|
|
1813
|
-
}
|
|
1814
|
-
if (noShift && !alignment) {
|
|
1815
|
-
const xMin = max(overflow.left, 0);
|
|
1816
|
-
const xMax = max(overflow.right, 0);
|
|
1817
|
-
const yMin = max(overflow.top, 0);
|
|
1818
|
-
const yMax = max(overflow.bottom, 0);
|
|
1819
|
-
if (isYAxis) {
|
|
1820
|
-
availableWidth = width - 2 * (xMin !== 0 || xMax !== 0 ? xMin + xMax : max(overflow.left, overflow.right));
|
|
1821
|
-
} else {
|
|
1822
|
-
availableHeight = height - 2 * (yMin !== 0 || yMax !== 0 ? yMin + yMax : max(overflow.top, overflow.bottom));
|
|
1823
|
-
}
|
|
1824
|
-
}
|
|
1825
|
-
await apply({
|
|
1826
|
-
...state,
|
|
1827
|
-
availableWidth,
|
|
1828
|
-
availableHeight
|
|
1829
|
-
});
|
|
1830
|
-
const nextDimensions = await platform.getDimensions(elements.floating);
|
|
1831
|
-
if (width !== nextDimensions.width || height !== nextDimensions.height) {
|
|
1832
|
-
return {
|
|
1833
|
-
reset: {
|
|
1834
|
-
rects: true
|
|
1835
|
-
}
|
|
1836
|
-
};
|
|
1837
|
-
}
|
|
1838
|
-
return {};
|
|
1839
|
-
}
|
|
1840
|
-
};
|
|
1841
|
-
};
|
|
1842
|
-
|
|
1843
1827
|
function hasWindow() {
|
|
1844
1828
|
return typeof window !== 'undefined';
|
|
1845
1829
|
}
|
|
@@ -2696,14 +2680,6 @@ const shift = shift$1;
|
|
|
2696
2680
|
*/
|
|
2697
2681
|
const flip = flip$1;
|
|
2698
2682
|
|
|
2699
|
-
/**
|
|
2700
|
-
* Provides data that allows you to change the size of the floating element —
|
|
2701
|
-
* for instance, prevent it from overflowing the clipping boundary or match the
|
|
2702
|
-
* width of the reference element.
|
|
2703
|
-
* @see https://floating-ui.com/docs/size
|
|
2704
|
-
*/
|
|
2705
|
-
const size = size$1;
|
|
2706
|
-
|
|
2707
2683
|
/**
|
|
2708
2684
|
* Provides data to position an inner element of the floating element so that it
|
|
2709
2685
|
* appears centered to the reference element.
|
|
@@ -2748,14 +2724,17 @@ var styles = css`/***************************** 1 ******************************
|
|
|
2748
2724
|
/***************************** NEUTRAL 2 ****************************************/
|
|
2749
2725
|
/***************************** NEUTRAL 2 / 3 ****************************************/
|
|
2750
2726
|
:host {
|
|
2751
|
-
--
|
|
2727
|
+
--bsi-dropdown-background: var(--bsi-color-background-inverse);
|
|
2752
2728
|
}`;
|
|
2753
2729
|
|
|
2754
2730
|
let ItPopover = class ItPopover extends BaseComponent {
|
|
2755
2731
|
constructor() {
|
|
2756
2732
|
super(...arguments);
|
|
2757
2733
|
this.open = false;
|
|
2734
|
+
this.controlled = false;
|
|
2758
2735
|
this.placement = 'bottom-start';
|
|
2736
|
+
this.offset = 12;
|
|
2737
|
+
this.noFlip = false;
|
|
2759
2738
|
this._onDocumentClick = (event) => {
|
|
2760
2739
|
if (!this.open)
|
|
2761
2740
|
return;
|
|
@@ -2773,27 +2752,57 @@ let ItPopover = class ItPopover extends BaseComponent {
|
|
|
2773
2752
|
}
|
|
2774
2753
|
_setChildrenProperties() {
|
|
2775
2754
|
if (this._triggerElement && this._triggerElement.tagName === 'IT-BUTTON') {
|
|
2755
|
+
if (this._triggerElement.disabled) {
|
|
2756
|
+
this._triggerElement.removeAttribute('it-aria-haspopup');
|
|
2757
|
+
this._triggerElement.expanded = undefined;
|
|
2758
|
+
return;
|
|
2759
|
+
}
|
|
2776
2760
|
if (!this._triggerElement.hasAttribute('it-aria-haspopup')) {
|
|
2777
2761
|
this._triggerElement?.setAttribute('it-aria-haspopup', 'true');
|
|
2778
2762
|
}
|
|
2779
2763
|
this._triggerElement.expanded = this.open;
|
|
2780
2764
|
}
|
|
2781
2765
|
else {
|
|
2766
|
+
if (this._triggerElement?.hasAttribute('disabled')) {
|
|
2767
|
+
this._triggerElement.removeAttribute('aria-haspopup');
|
|
2768
|
+
this._triggerElement.removeAttribute('aria-expanded');
|
|
2769
|
+
return;
|
|
2770
|
+
}
|
|
2782
2771
|
if (!this._triggerElement?.hasAttribute('aria-haspopup')) {
|
|
2783
2772
|
this._triggerElement?.setAttribute('aria-haspopup', 'true');
|
|
2784
2773
|
}
|
|
2785
2774
|
this._triggerElement?.setAttribute('aria-expanded', String(this.open));
|
|
2786
2775
|
}
|
|
2787
2776
|
}
|
|
2788
|
-
|
|
2789
|
-
super.connectedCallback?.();
|
|
2777
|
+
setupStandardEvents() {
|
|
2790
2778
|
document.addEventListener('click', this._onDocumentClick);
|
|
2779
|
+
this._triggerElement?.addEventListener('click', (e) => {
|
|
2780
|
+
e.preventDefault();
|
|
2781
|
+
this.toggle();
|
|
2782
|
+
});
|
|
2783
|
+
this._triggerElement?.addEventListener('keydown', (e) => {
|
|
2784
|
+
if (e.key === 'Escape' && this.open) {
|
|
2785
|
+
this.closePopover();
|
|
2786
|
+
this._triggerElement?.focus();
|
|
2787
|
+
}
|
|
2788
|
+
});
|
|
2789
|
+
this._contentElement?.addEventListener('keydown', (e) => {
|
|
2790
|
+
if (e.key === 'Escape' && this.open) {
|
|
2791
|
+
this.closePopover();
|
|
2792
|
+
this._triggerElement?.focus();
|
|
2793
|
+
}
|
|
2794
|
+
});
|
|
2791
2795
|
}
|
|
2792
2796
|
disconnectedCallback() {
|
|
2793
2797
|
super.disconnectedCallback?.();
|
|
2794
2798
|
document.removeEventListener('click', this._onDocumentClick);
|
|
2795
2799
|
this._cleanup?.();
|
|
2796
2800
|
}
|
|
2801
|
+
firstUpdated(_changedProperties) {
|
|
2802
|
+
super.firstUpdated(_changedProperties);
|
|
2803
|
+
if (!this.controlled)
|
|
2804
|
+
this.setupStandardEvents();
|
|
2805
|
+
}
|
|
2797
2806
|
updated(changedProps) {
|
|
2798
2807
|
this._setChildrenProperties();
|
|
2799
2808
|
if (changedProps.has('open')) {
|
|
@@ -2826,16 +2835,17 @@ let ItPopover = class ItPopover extends BaseComponent {
|
|
|
2826
2835
|
computePosition(this._triggerElement, this._contentElement, {
|
|
2827
2836
|
placement: this.placement,
|
|
2828
2837
|
middleware: [
|
|
2829
|
-
offset(
|
|
2830
|
-
flip(),
|
|
2838
|
+
offset(this.offset),
|
|
2839
|
+
flip({ mainAxis: !this.noFlip, crossAxis: !this.noFlip }),
|
|
2831
2840
|
shift({ padding: 8 }),
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
}
|
|
2841
|
+
// Commentato perchè nella toolbar con dropdown che ha position absolute, vogliamo il min-width impostato da css con var(--bsi-dropdown-min-width)
|
|
2842
|
+
// size({
|
|
2843
|
+
// apply({ rects, elements }) {
|
|
2844
|
+
// Object.assign(elements.floating.style, {
|
|
2845
|
+
// minWidth: `${rects.reference.width}px`,
|
|
2846
|
+
// });
|
|
2847
|
+
// },
|
|
2848
|
+
// }),
|
|
2839
2849
|
arrow({ element: this._arrowElement }),
|
|
2840
2850
|
],
|
|
2841
2851
|
}).then(({ x, y, placement, middlewareData }) => {
|
|
@@ -2851,8 +2861,12 @@ let ItPopover = class ItPopover extends BaseComponent {
|
|
|
2851
2861
|
bottom: 'top',
|
|
2852
2862
|
left: 'right',
|
|
2853
2863
|
}[placement.split('-')[0]];
|
|
2864
|
+
const triggerRect = this._triggerElement.getBoundingClientRect();
|
|
2865
|
+
const contentRect = this._contentElement.getBoundingClientRect();
|
|
2866
|
+
const triggerCenter = triggerRect.left + triggerRect.width / 2;
|
|
2867
|
+
const arrowLeft = triggerCenter - contentRect.left - this._triggerElement.offsetWidth / 2 + 20;
|
|
2854
2868
|
Object.assign(this._arrowElement.style, {
|
|
2855
|
-
left: arrowX != null ?
|
|
2869
|
+
left: arrowX != null ? `${arrowLeft}px` : '',
|
|
2856
2870
|
top: arrowY != null ? `${arrowY}px` : '',
|
|
2857
2871
|
right: '',
|
|
2858
2872
|
bottom: '',
|
|
@@ -2884,7 +2898,7 @@ let ItPopover = class ItPopover extends BaseComponent {
|
|
|
2884
2898
|
render() {
|
|
2885
2899
|
return html `
|
|
2886
2900
|
<slot name="trigger" part="trigger" @slotchange=${this._setChildrenProperties}></slot>
|
|
2887
|
-
<slot name="content"></slot>
|
|
2901
|
+
<slot name="content" part="popover-content"></slot>
|
|
2888
2902
|
`;
|
|
2889
2903
|
}
|
|
2890
2904
|
};
|
|
@@ -2893,10 +2907,22 @@ __decorate([
|
|
|
2893
2907
|
property({ type: Boolean, reflect: true }),
|
|
2894
2908
|
__metadata("design:type", Object)
|
|
2895
2909
|
], ItPopover.prototype, "open", void 0);
|
|
2910
|
+
__decorate([
|
|
2911
|
+
property({ type: Boolean }),
|
|
2912
|
+
__metadata("design:type", Object)
|
|
2913
|
+
], ItPopover.prototype, "controlled", void 0);
|
|
2896
2914
|
__decorate([
|
|
2897
2915
|
property({ type: String }),
|
|
2898
2916
|
__metadata("design:type", String)
|
|
2899
2917
|
], ItPopover.prototype, "placement", void 0);
|
|
2918
|
+
__decorate([
|
|
2919
|
+
property({ type: Number }),
|
|
2920
|
+
__metadata("design:type", Number)
|
|
2921
|
+
], ItPopover.prototype, "offset", void 0);
|
|
2922
|
+
__decorate([
|
|
2923
|
+
property({ type: Boolean, attribute: 'no-flip' }),
|
|
2924
|
+
__metadata("design:type", Boolean)
|
|
2925
|
+
], ItPopover.prototype, "noFlip", void 0);
|
|
2900
2926
|
__decorate([
|
|
2901
2927
|
query('slot[name="trigger"]'),
|
|
2902
2928
|
__metadata("design:type", HTMLSlotElement)
|