@esri/calcite-components 5.1.0-next.7 → 5.1.0-next.9
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/dist/cdn/{3L54WMSL.js → 24BVOJIY.js} +1 -1
- package/dist/cdn/{VLKT7UVD.js → 34EJXQYF.js} +1 -1
- package/dist/cdn/{BCLXCJEM.js → 3GXLGKZV.js} +1 -1
- package/dist/cdn/{BYWKKEUK.js → 3IHT5FIP.js} +1 -1
- package/dist/cdn/{GS2OPY5B.js → 3O7NXGXJ.js} +1 -1
- package/dist/cdn/{S6HRAHQS.js → 43FMFYKZ.js} +1 -1
- package/dist/cdn/{3YNOEWLR.js → 43SP7K3P.js} +1 -1
- package/dist/cdn/{UFKZPJGX.js → 45Z5R6GR.js} +1 -1
- package/dist/cdn/{2YZJ5SK5.js → 47RTCYTX.js} +1 -1
- package/dist/cdn/{7MBOUDMI.js → 4AQ3DQDN.js} +1 -1
- package/dist/cdn/{J7B4VKUB.js → 4DJKUEBQ.js} +1 -1
- package/dist/cdn/4IBKGKIH.js +2 -0
- package/dist/cdn/{I6I5D5MI.js → 4JVVYRDW.js} +1 -1
- package/dist/cdn/{7BJTVAGJ.js → 4U633XVG.js} +1 -1
- package/dist/cdn/55GOZN42.js +2 -0
- package/dist/cdn/{IX7RXOMC.js → 575ZYV35.js} +1 -1
- package/dist/cdn/{LTPGJM6S.js → 5LUEFKD3.js} +1 -1
- package/dist/cdn/{RPXB3OIR.js → 5RDU2ZNH.js} +1 -1
- package/dist/cdn/{NRBJ3VOF.js → 5TJGOI64.js} +1 -1
- package/dist/cdn/{GC4LUWE2.js → 67QHQNZF.js} +1 -1
- package/dist/cdn/{SYSRTPLT.js → 6C76CPWO.js} +1 -1
- package/dist/cdn/{R72JHGCT.js → 6LA4PLL2.js} +1 -1
- package/dist/cdn/{AOSKB4O3.js → 6OKASMD7.js} +1 -1
- package/dist/cdn/{Q6OXR72I.js → 7ECYZZBW.js} +1 -1
- package/dist/cdn/{YVLGTYKI.js → 7JGWCRII.js} +1 -1
- package/dist/cdn/{3WREYYM5.js → 7XBTO6NQ.js} +1 -1
- package/dist/cdn/A6XPQQWN.js +2 -0
- package/dist/cdn/{K3YSAFRD.js → ANQRSTGE.js} +1 -1
- package/dist/cdn/{GFUL7D7M.js → AS2M2ZWD.js} +1 -1
- package/dist/cdn/{PFVIFFID.js → BAMCFG7H.js} +1 -1
- package/dist/cdn/{ZPR4DBFS.js → BDQCESE7.js} +1 -1
- package/dist/cdn/{5BL7R465.js → BG7CCT2Q.js} +1 -1
- package/dist/cdn/{3ARW44US.js → BMRN6G4T.js} +1 -1
- package/dist/cdn/{B6LFHYRQ.js → BPIG37CO.js} +1 -1
- package/dist/cdn/{RL55PUKO.js → BZGE52YU.js} +1 -1
- package/dist/cdn/{A5BBQLSY.js → C25ETLQX.js} +1 -1
- package/dist/cdn/{PZMLAOBO.js → CKMZY3H7.js} +1 -1
- package/dist/cdn/{WOUDT7QM.js → CMVTCAFL.js} +1 -1
- package/dist/cdn/{ETLJSBPM.js → CNR7IJIS.js} +1 -1
- package/dist/cdn/{PYIFXBJK.js → CSOE3CJR.js} +1 -1
- package/dist/cdn/{QKCQY33W.js → DRQCOAQ4.js} +1 -1
- package/dist/cdn/{GHLGH22R.js → DTUD5FAT.js} +1 -1
- package/dist/cdn/{BFOWFEX3.js → DYBHFMG7.js} +1 -1
- package/dist/cdn/{W7C3ZKLA.js → E6EGKXUX.js} +1 -1
- package/dist/cdn/{M2EEQG72.js → EB4M47KA.js} +1 -1
- package/dist/cdn/{Z5RVFQRM.js → EIXE62NK.js} +1 -1
- package/dist/cdn/{CFN4BIZL.js → EQZPTVS3.js} +1 -1
- package/dist/cdn/{HIOWL6WU.js → ESATITDD.js} +1 -1
- package/dist/cdn/ETIO6SPJ.js +2 -0
- package/dist/cdn/EY7FPNVS.js +2 -0
- package/dist/cdn/{TCCEQ7MN.js → FIEDEHAP.js} +1 -1
- package/dist/cdn/{J435BGYU.js → FZ6ZUHKQ.js} +1 -1
- package/dist/cdn/{77ZP6SXN.js → GGGN54CY.js} +1 -1
- package/dist/cdn/{WGALRMGQ.js → GH34TDLL.js} +1 -1
- package/dist/cdn/{7GGO2CZM.js → HG2EYXWI.js} +1 -1
- package/dist/cdn/{DRDD2NOI.js → HQDFIE2B.js} +1 -1
- package/dist/cdn/{6HLSG3XA.js → HZGU4N3I.js} +1 -1
- package/dist/cdn/{XU6Y5UJM.js → I5G3H4D4.js} +1 -1
- package/dist/cdn/{3OKBFBPD.js → I7BWPAOF.js} +1 -1
- package/dist/cdn/{PP3ZYBZZ.js → IBQYZCFQ.js} +1 -1
- package/dist/cdn/{GNJJTXA5.js → IJ7V345Q.js} +1 -1
- package/dist/cdn/{MCTFB7GO.js → IQ4VNR4Q.js} +1 -1
- package/dist/cdn/{MOO6RSVL.js → IWG7JAQJ.js} +1 -1
- package/dist/cdn/{CWAS32KR.js → IZLDBAPA.js} +1 -1
- package/dist/cdn/{ODAPCLKU.js → J2OGE3DI.js} +1 -1
- package/dist/cdn/{RGTWEZAQ.js → JPWQ44GC.js} +1 -1
- package/dist/cdn/{EZCA7WQG.js → JRF656V5.js} +1 -1
- package/dist/cdn/{RPTMX4W3.js → JRWW665Q.js} +1 -1
- package/dist/cdn/{4FGXGSCS.js → JVAE3MLA.js} +1 -1
- package/dist/cdn/{6PUUPFDX.js → K2H2TINH.js} +1 -1
- package/dist/cdn/{4YVKX7KL.js → KDZRPYFR.js} +1 -1
- package/dist/cdn/{2QXTLDZ6.js → KHIMNKVO.js} +1 -1
- package/dist/cdn/{B74N65HB.js → KMOFSKZF.js} +1 -1
- package/dist/cdn/{LWILKWNQ.js → KQNOWW4C.js} +1 -1
- package/dist/cdn/{KME7ZZCF.js → KYKC2CK2.js} +1 -1
- package/dist/cdn/{UHGCQVOL.js → L24DVRWE.js} +1 -1
- package/dist/cdn/{JSRHPQ52.js → L5LBH4FP.js} +1 -1
- package/dist/cdn/LKRLVAVK.js +2 -0
- package/dist/cdn/{7FWJSF56.js → LQD663MA.js} +1 -1
- package/dist/cdn/{PBYPABMK.js → M6MHKAA5.js} +1 -1
- package/dist/cdn/MMEADS6E.js +2 -0
- package/dist/cdn/{OOTSFWEM.js → MVA4NE6I.js} +1 -1
- package/dist/cdn/{3JNFU6KC.js → NGXAYCAR.js} +1 -1
- package/dist/cdn/{LD7LTIBH.js → NJRKH5Q7.js} +1 -1
- package/dist/cdn/{YELDC3QJ.js → NVHH3XZJ.js} +1 -1
- package/dist/cdn/{FS6JTDJK.js → NVSO6GLT.js} +1 -1
- package/dist/cdn/{IIZ3STBY.js → NY7A5LKZ.js} +1 -1
- package/dist/cdn/{MIHUMK4H.js → O7BFREIB.js} +1 -1
- package/dist/cdn/{B6HWVI4Y.js → OLYLT2L5.js} +1 -1
- package/dist/cdn/{BF5X3NKJ.js → OPHJLVOH.js} +1 -1
- package/dist/cdn/{YHMDHOC5.js → OQ2UCUQP.js} +1 -1
- package/dist/cdn/{HMXVJFQG.js → OXCJDMGQ.js} +1 -1
- package/dist/cdn/{PPZ47NEL.js → P4JFMLKY.js} +1 -1
- package/dist/cdn/{IJLVEBB7.js → PCTQTX5N.js} +1 -1
- package/dist/cdn/{55SG4TFB.js → PFKFYB45.js} +1 -1
- package/dist/cdn/{FZX5RPOG.js → PHGT3YNE.js} +1 -1
- package/dist/cdn/{TG2Q5JYE.js → PIU3YYLU.js} +1 -1
- package/dist/cdn/{JJVYITPX.js → QCDS2TXE.js} +1 -1
- package/dist/cdn/{QDHV7HSF.js → QR4JRFEP.js} +1 -1
- package/dist/cdn/QULVDSNJ.js +2 -0
- package/dist/cdn/{II65AX2Y.js → QWALXRY6.js} +1 -1
- package/dist/cdn/{T7KRQA2S.js → RCUNETDY.js} +1 -1
- package/dist/cdn/{PUI672KC.js → RPT5BJMD.js} +1 -1
- package/dist/cdn/{72UQHKZB.js → S7XHDLIF.js} +1 -1
- package/dist/cdn/{VLRV4R6U.js → SAQAAU52.js} +1 -1
- package/dist/cdn/{NEP2GKTJ.js → SG24GAXY.js} +1 -1
- package/dist/cdn/{5Q5XOD7Y.js → SHD6TE4R.js} +1 -1
- package/dist/cdn/{6EIEBFGZ.js → SIMNCT4V.js} +1 -1
- package/dist/cdn/{XGQPFD4F.js → SJSCENKK.js} +1 -1
- package/dist/cdn/{YCCYLLDK.js → SLVFP6JA.js} +1 -1
- package/dist/cdn/{WPVR4P6L.js → TKH5LW5O.js} +1 -1
- package/dist/cdn/{EUTZTNZS.js → TMOOTRK4.js} +1 -1
- package/dist/cdn/{4RM7IDEC.js → TTFCVVON.js} +1 -1
- package/dist/cdn/{CEKWE7MI.js → TXRFE5GH.js} +1 -1
- package/dist/cdn/{6PPA5ENT.js → TXYWJHYI.js} +1 -1
- package/dist/cdn/{JSPE4OG7.js → U4MTAQRM.js} +1 -1
- package/dist/cdn/UHQ454NG.js +2 -0
- package/dist/cdn/{NIOMLRZP.js → UKC7JB7P.js} +1 -1
- package/dist/cdn/{CJGFEG4P.js → UTQKB5CS.js} +1 -1
- package/dist/cdn/{MXIVUGX2.js → V2EVNXUV.js} +1 -1
- package/dist/cdn/{FZUCWEY4.js → VOTW2RMD.js} +1 -1
- package/dist/cdn/{KF4IOR4S.js → VQHTMUYJ.js} +1 -1
- package/dist/cdn/{LZ5FKMVP.js → WBJUAZ65.js} +1 -1
- package/dist/cdn/{QTH6ZO2M.js → WEAILY72.js} +1 -1
- package/dist/cdn/WITGQRKF.js +2 -0
- package/dist/cdn/WM4NZNNA.js +2 -0
- package/dist/cdn/{RABVM5D7.js → XJZLGVT6.js} +1 -1
- package/dist/cdn/{N3AYJLQ3.js → XUSE3II4.js} +1 -1
- package/dist/cdn/{PIAOVZIP.js → XW3UC4FN.js} +1 -1
- package/dist/cdn/{K3MWE3BD.js → YANXY6FO.js} +1 -1
- package/dist/cdn/{6ASYMYYE.js → YJHXVSEP.js} +1 -1
- package/dist/cdn/{S6Q2RWZQ.js → YM6QAFEQ.js} +1 -1
- package/dist/cdn/{BDV62ZVL.js → YMHR4PKM.js} +1 -1
- package/dist/cdn/{CWCZZTTC.js → YMSZKTCN.js} +1 -1
- package/dist/cdn/{MRGLBHY6.js → YYDYHAP7.js} +1 -1
- package/dist/cdn/{O6DG6EWV.js → ZEASFJJQ.js} +1 -1
- package/dist/cdn/{IOTVOWSQ.js → ZGCRVGEK.js} +1 -1
- package/dist/cdn/{V7UCCXSG.js → ZGJRTQBX.js} +1 -1
- package/dist/cdn/{V3YAFJPI.js → ZPZI63EH.js} +1 -1
- package/dist/cdn/{7JU6PR2F.js → ZTV4V5SF.js} +1 -1
- package/dist/cdn/index.js +1 -1
- package/dist/chunks/dom.js +5 -5
- package/dist/chunks/floating-ui.js +1 -4
- package/dist/chunks/input.js +2 -2
- package/dist/chunks/runtime.js +4 -4
- package/dist/chunks/useForm.js +165 -0
- package/dist/chunks/useReferenceElement.js +505 -0
- package/dist/components/calcite-block/customElement.js +1 -1
- package/dist/components/calcite-checkbox/customElement.d.ts +1 -1
- package/dist/components/calcite-checkbox/customElement.js +6 -7
- package/dist/components/calcite-combobox/customElement.d.ts +1 -1
- package/dist/components/calcite-combobox/customElement.js +11 -12
- package/dist/components/calcite-input/customElement.js +1 -1
- package/dist/components/calcite-input-date-picker/customElement.js +1 -1
- package/dist/components/calcite-input-number/customElement.js +1 -1
- package/dist/components/calcite-input-text/customElement.js +2 -161
- package/dist/components/calcite-input-time-picker/customElement.js +1 -1
- package/dist/components/calcite-list/customElement.js +25 -3
- package/dist/components/calcite-list-item-group/customElement.js +1 -1
- package/dist/components/calcite-meter/customElement.d.ts +7 -1
- package/dist/components/calcite-meter/customElement.js +0 -4
- package/dist/components/calcite-popover/customElement.js +11 -176
- package/dist/components/calcite-sheet/customElement.js +1 -1
- package/dist/components/calcite-tab-nav/customElement.js +1 -1
- package/dist/components/calcite-tabs/customElement.js +1 -1
- package/dist/components/calcite-text-area/customElement.js +1 -1
- package/dist/components/calcite-tooltip/customElement.js +11 -310
- package/dist/components/calcite-tree-item/customElement.js +1 -1
- package/dist/docs/api.json +1 -1
- package/dist/docs/docs.json +1 -1
- package/dist/docs/vscode.html-custom-data.json +1 -1
- package/dist/docs/web-types.json +1 -1
- package/dist/loader.js +2 -2
- package/package.json +2 -2
- package/dist/cdn/6AYITVWB.js +0 -2
- package/dist/cdn/CFGMG4DH.js +0 -2
- package/dist/cdn/DAUSY6FZ.js +0 -2
- package/dist/cdn/ECD3C5ZE.js +0 -2
- package/dist/cdn/GRA7E3RF.js +0 -2
- package/dist/cdn/K6ZO6PJL.js +0 -2
- package/dist/cdn/SHGMG2W2.js +0 -2
- package/dist/cdn/V5MTQXYJ.js +0 -2
- package/dist/cdn/WKUBLKRJ.js +0 -2
- package/dist/cdn/ZGL65NS5.js +0 -2
- package/dist/chunks/FloatingArrow.js +0 -24
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
|
+
import { makeGenericController } from "@arcgis/lumina/controllers";
|
|
3
|
+
import { uncapitalize, kebabToPascal } from "@arcgis/toolkit/string";
|
|
4
|
+
import { s as syncInputDelegate, i as isSupportedType } from "./input.js";
|
|
5
|
+
const componentsWithInputEvent = [
|
|
6
|
+
"calcite-input",
|
|
7
|
+
"calcite-input-number",
|
|
8
|
+
"calcite-input-text",
|
|
9
|
+
"calcite-text-area"
|
|
10
|
+
];
|
|
11
|
+
function getClearValidationEventName(componentTag) {
|
|
12
|
+
const componentTagCamelCase = uncapitalize(kebabToPascal(componentTag));
|
|
13
|
+
return `${componentTagCamelCase}${componentsWithInputEvent.includes(componentTag) ? "Input" : "Change"}`;
|
|
14
|
+
}
|
|
15
|
+
function displayValidationMessage(component, { status, message, icon }) {
|
|
16
|
+
if ("status" in component) {
|
|
17
|
+
component.status = status;
|
|
18
|
+
}
|
|
19
|
+
if ("validationIcon" in component && typeof component.validationIcon !== "string") {
|
|
20
|
+
component.validationIcon = icon;
|
|
21
|
+
}
|
|
22
|
+
if ("validationMessage" in component && !component.validationMessage) {
|
|
23
|
+
component.validationMessage = message;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function syncInternalInput(component, input) {
|
|
27
|
+
const { disabled, required } = component;
|
|
28
|
+
input.disabled = disabled;
|
|
29
|
+
input.required = !!required;
|
|
30
|
+
if (isCheckable(component)) {
|
|
31
|
+
input.checked = component.checked;
|
|
32
|
+
} else if (isInputComponent(component, input)) {
|
|
33
|
+
syncInputDelegate(input.type, component, input);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function isCheckable(component) {
|
|
37
|
+
return "checked" in component;
|
|
38
|
+
}
|
|
39
|
+
function isInputComponent(component, input) {
|
|
40
|
+
return component && isSupportedType(input.type);
|
|
41
|
+
}
|
|
42
|
+
const useForm = (options) => {
|
|
43
|
+
return makeGenericController((component, controller) => {
|
|
44
|
+
let defaultValueDirty = false;
|
|
45
|
+
let defaultCheckedDirty = false;
|
|
46
|
+
let inputDelegate;
|
|
47
|
+
let lastAssociatedForm = null;
|
|
48
|
+
if (options.inputType) {
|
|
49
|
+
inputDelegate = document.createElement("input");
|
|
50
|
+
inputDelegate.type = options.inputType;
|
|
51
|
+
}
|
|
52
|
+
function invalidFormHandler(event) {
|
|
53
|
+
event?.preventDefault();
|
|
54
|
+
}
|
|
55
|
+
function onFormReset() {
|
|
56
|
+
if ("status" in component) {
|
|
57
|
+
component.status = "idle";
|
|
58
|
+
}
|
|
59
|
+
if ("validationIcon" in component) {
|
|
60
|
+
component.validationIcon = false;
|
|
61
|
+
}
|
|
62
|
+
if ("validationMessage" in component) {
|
|
63
|
+
component.validationMessage = "";
|
|
64
|
+
}
|
|
65
|
+
if (isCheckable(component)) {
|
|
66
|
+
component.checked = defaultCheckedDirty ? component.defaultChecked : component.checked;
|
|
67
|
+
}
|
|
68
|
+
component.value = defaultValueDirty ? component.defaultValue : component.value;
|
|
69
|
+
defaultValueDirty = false;
|
|
70
|
+
defaultCheckedDirty = false;
|
|
71
|
+
}
|
|
72
|
+
component.listen("luminaFormResetCallback", () => {
|
|
73
|
+
onFormReset();
|
|
74
|
+
});
|
|
75
|
+
component.listen("luminaFormAssociatedCallback", ({ detail: [form] }) => {
|
|
76
|
+
if (form) {
|
|
77
|
+
form.addEventListener("invalid", invalidFormHandler, { capture: true });
|
|
78
|
+
} else {
|
|
79
|
+
lastAssociatedForm?.removeEventListener("invalid", invalidFormHandler, { capture: true });
|
|
80
|
+
}
|
|
81
|
+
lastAssociatedForm = form;
|
|
82
|
+
});
|
|
83
|
+
function handleInvalidInput() {
|
|
84
|
+
const validationMsg = inputDelegate?.validationMessage || "";
|
|
85
|
+
component.el.dispatchEvent(
|
|
86
|
+
// allows users to set custom validation messages
|
|
87
|
+
new CustomEvent("calciteInvalid", { bubbles: true, composed: true })
|
|
88
|
+
);
|
|
89
|
+
displayValidationMessage(component, {
|
|
90
|
+
message: validationMsg,
|
|
91
|
+
icon: true,
|
|
92
|
+
status: "invalid"
|
|
93
|
+
});
|
|
94
|
+
const clearValidationEvent = getClearValidationEventName(component.el.tagName.toLowerCase());
|
|
95
|
+
component.listen(
|
|
96
|
+
clearValidationEvent,
|
|
97
|
+
() => {
|
|
98
|
+
if ("status" in component) {
|
|
99
|
+
component.status = "idle";
|
|
100
|
+
}
|
|
101
|
+
if ("validationIcon" in component && (!component.validationIcon || component.validationIcon === true)) {
|
|
102
|
+
component.validationIcon = false;
|
|
103
|
+
}
|
|
104
|
+
if ("validationMessage" in component && component.validationMessage === validationMsg) {
|
|
105
|
+
component.validationMessage = "";
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
{ once: true }
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
controller.onConnected(() => {
|
|
112
|
+
component.el.addEventListener("invalid", handleInvalidInput);
|
|
113
|
+
});
|
|
114
|
+
controller.onDisconnected(() => {
|
|
115
|
+
component.el.removeEventListener("invalid", handleInvalidInput);
|
|
116
|
+
});
|
|
117
|
+
controller.onUpdate((changes) => {
|
|
118
|
+
if (changes.has("value") && !defaultValueDirty) {
|
|
119
|
+
defaultValueDirty = true;
|
|
120
|
+
component.defaultValue = component.value;
|
|
121
|
+
}
|
|
122
|
+
if (isCheckable(component) && changes.has("checked") && !defaultCheckedDirty) {
|
|
123
|
+
defaultCheckedDirty = true;
|
|
124
|
+
component.defaultChecked = component.checked;
|
|
125
|
+
}
|
|
126
|
+
if (changes.has("value") || isCheckable(component) && changes.has("checked")) {
|
|
127
|
+
component.elementInternals.setFormValue(getFormValue());
|
|
128
|
+
}
|
|
129
|
+
if (inputDelegate) {
|
|
130
|
+
inputDelegate.value = component.value;
|
|
131
|
+
syncInternalInput(component, inputDelegate);
|
|
132
|
+
inputDelegate.checkValidity();
|
|
133
|
+
component.elementInternals.setValidity(inputDelegate.validity, inputDelegate.validationMessage);
|
|
134
|
+
if ("validity" in component) {
|
|
135
|
+
component.validity = component.elementInternals.validity;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
function getFormValue() {
|
|
140
|
+
if (Array.isArray(component.value)) {
|
|
141
|
+
const formData = new FormData();
|
|
142
|
+
component.value.forEach((value) => formData.append(component.name, value));
|
|
143
|
+
return formData;
|
|
144
|
+
}
|
|
145
|
+
if (isCheckable(component)) {
|
|
146
|
+
if (component.checked) {
|
|
147
|
+
return component.defaultValue === void 0 && !defaultValueDirty && component.value === void 0 ? "on" : component.value;
|
|
148
|
+
}
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
return component.value;
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
get active() {
|
|
155
|
+
return !!component.elementInternals.form;
|
|
156
|
+
},
|
|
157
|
+
requestSubmit: () => {
|
|
158
|
+
component.elementInternals.form?.requestSubmit();
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
export {
|
|
164
|
+
useForm as u
|
|
165
|
+
};
|
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
|
+
import { ref } from "lit/directives/ref.js";
|
|
3
|
+
import { keyed } from "lit/directives/keyed.js";
|
|
4
|
+
import { nothing, svg, html } from "lit";
|
|
5
|
+
import { safeClassMap } from "@arcgis/lumina";
|
|
6
|
+
import { x as getShadowRootNode, j as isPrimaryPointerButton, y as isKeyboardTriggeredClick, q as queryElementRoots } from "./dom.js";
|
|
7
|
+
import { i as isActivationKey } from "./key.js";
|
|
8
|
+
import { t as toAriaBoolean } from "./aria.js";
|
|
9
|
+
import { makeGenericController } from "@arcgis/lumina/controllers";
|
|
10
|
+
const CSS = {
|
|
11
|
+
arrow: "calcite-floating-ui-arrow",
|
|
12
|
+
arrowStroke: "calcite-floating-ui-arrow__stroke"
|
|
13
|
+
};
|
|
14
|
+
const DEFAULTS = {
|
|
15
|
+
width: 12,
|
|
16
|
+
height: 6,
|
|
17
|
+
strokeWidth: 1
|
|
18
|
+
};
|
|
19
|
+
const FloatingArrow = ({ floatingLayout, key, ref: ref$1 }) => {
|
|
20
|
+
const { width, height, strokeWidth } = DEFAULTS;
|
|
21
|
+
const svgX = width / 2;
|
|
22
|
+
const isVertical = floatingLayout === "vertical";
|
|
23
|
+
const dValue = `M0,0 H${width} L${width - svgX},${height} Q${svgX},${height} ${svgX},${height} Z`;
|
|
24
|
+
return keyed(key, html`<svg aria-hidden=true class=${safeClassMap(CSS.arrow)} height=${width} viewBox=${`0 0 ${width} ${width + (!isVertical ? strokeWidth : 0)}`} width=${width + (isVertical ? strokeWidth : 0)} ${ref(ref$1)}>${svg`${svg`<path class=${safeClassMap(CSS.arrowStroke)} d=${dValue ?? nothing} fill=none stroke-width=${strokeWidth + 1} />` || ""}<path d=${dValue ?? nothing} stroke=none />`}</svg>`);
|
|
25
|
+
};
|
|
26
|
+
function haveSameComponents(components, activeComponents) {
|
|
27
|
+
if (components === activeComponents) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
if (components.length !== activeComponents.length) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
const s1 = new Set(components);
|
|
34
|
+
const s2 = new Set(activeComponents);
|
|
35
|
+
if (s1.size !== s2.size) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
for (const item of s1) {
|
|
39
|
+
if (!s2.has(item)) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
const clickTolerance = 5;
|
|
46
|
+
const HOVER_OPEN_DELAY_MS = 300;
|
|
47
|
+
const HOVER_QUICK_OPEN_DELAY_MS = HOVER_OPEN_DELAY_MS / 3;
|
|
48
|
+
const HOVER_CLOSE_DELAY_MS = HOVER_OPEN_DELAY_MS * 1.5;
|
|
49
|
+
function isDrag({
|
|
50
|
+
startX,
|
|
51
|
+
startY,
|
|
52
|
+
endX,
|
|
53
|
+
endY
|
|
54
|
+
}) {
|
|
55
|
+
const distance = Math.hypot(endX - startX, endY - startY);
|
|
56
|
+
return distance > clickTolerance;
|
|
57
|
+
}
|
|
58
|
+
const referenceElementManager = (options) => {
|
|
59
|
+
const registeredElements = /* @__PURE__ */ new Map();
|
|
60
|
+
const registeredShadowRootCounts = /* @__PURE__ */ new WeakMap();
|
|
61
|
+
let activeComponents = null;
|
|
62
|
+
let clickedComponents = null;
|
|
63
|
+
let hoverCloseTimeout = null;
|
|
64
|
+
let hoverOpenTimeout = null;
|
|
65
|
+
let hoveredComponents = null;
|
|
66
|
+
let pointerDownPosition = null;
|
|
67
|
+
let registeredComponentCount = 0;
|
|
68
|
+
const queryComponents = (composedPath, type) => {
|
|
69
|
+
const registeredElement = composedPath.find((pathEl) => registeredElements.has(pathEl));
|
|
70
|
+
if (!registeredElement) {
|
|
71
|
+
return void 0;
|
|
72
|
+
}
|
|
73
|
+
const components = registeredElements.get(registeredElement);
|
|
74
|
+
return components?.filter((component) => component.referenceElementType === type);
|
|
75
|
+
};
|
|
76
|
+
const toggleComponents = (event, type) => {
|
|
77
|
+
const composedPath = event.composedPath();
|
|
78
|
+
const components = queryComponents(composedPath, type);
|
|
79
|
+
components?.forEach((component) => {
|
|
80
|
+
if (component && !component.triggerDisabled) {
|
|
81
|
+
component.open = !component.open;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
Array.from(registeredElements.values()).flat().filter(
|
|
85
|
+
(component) => !components?.includes(component) && component.autoClose && component.open && !composedPath.includes(component.el)
|
|
86
|
+
).forEach((component) => component.open = false);
|
|
87
|
+
};
|
|
88
|
+
const clickHandler = (event) => {
|
|
89
|
+
if (isKeyboardTriggeredClick(event) || event.defaultPrevented || pointerDownPosition && isDrag({
|
|
90
|
+
endY: event.clientY,
|
|
91
|
+
endX: event.clientX,
|
|
92
|
+
startY: pointerDownPosition.y,
|
|
93
|
+
startX: pointerDownPosition.x
|
|
94
|
+
})) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
pointerDownPosition = null;
|
|
98
|
+
toggleComponents(event, "click");
|
|
99
|
+
};
|
|
100
|
+
const clearHoverOpenTimeout = () => {
|
|
101
|
+
if (hoverOpenTimeout != null) {
|
|
102
|
+
window.clearTimeout(hoverOpenTimeout);
|
|
103
|
+
}
|
|
104
|
+
hoverOpenTimeout = null;
|
|
105
|
+
};
|
|
106
|
+
const clearHoverCloseTimeout = () => {
|
|
107
|
+
if (hoverCloseTimeout != null) {
|
|
108
|
+
window.clearTimeout(hoverCloseTimeout);
|
|
109
|
+
}
|
|
110
|
+
hoverCloseTimeout = null;
|
|
111
|
+
};
|
|
112
|
+
const clearHoverTimeout = () => {
|
|
113
|
+
clearHoverOpenTimeout();
|
|
114
|
+
clearHoverCloseTimeout();
|
|
115
|
+
};
|
|
116
|
+
const pathHasOpenHoverComponent = (components, composedPath) => {
|
|
117
|
+
return activeComponents?.some((component) => component?.open && composedPath.includes(component.el)) || components?.some((component) => component?.open && composedPath.includes(component.el));
|
|
118
|
+
};
|
|
119
|
+
const toggleHoverComponents = (components, open) => {
|
|
120
|
+
components?.forEach((component) => component.open = open);
|
|
121
|
+
activeComponents = open ? components : null;
|
|
122
|
+
};
|
|
123
|
+
const closeActiveHoverComponents = () => {
|
|
124
|
+
toggleHoverComponents(activeComponents, false);
|
|
125
|
+
};
|
|
126
|
+
const hoverKeyDownHandler = (event) => {
|
|
127
|
+
if (event.key === "Escape" && !event.defaultPrevented) {
|
|
128
|
+
const openActiveHoverComponents = activeComponents?.filter((component) => component?.open);
|
|
129
|
+
if (openActiveHoverComponents?.length) {
|
|
130
|
+
clearHoverTimeout();
|
|
131
|
+
closeActiveHoverComponents();
|
|
132
|
+
const composedPath = event.composedPath();
|
|
133
|
+
if (openActiveHoverComponents.some(
|
|
134
|
+
(component) => component.referenceEl instanceof Element && composedPath.includes(component.referenceEl) || composedPath.includes(component.el)
|
|
135
|
+
)) {
|
|
136
|
+
event.preventDefault();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
const hoverClickHandler = (event) => {
|
|
142
|
+
if (event.defaultPrevented) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
clickedComponents = null;
|
|
146
|
+
const composedPath = event.composedPath();
|
|
147
|
+
const components = queryComponents(composedPath, "hover");
|
|
148
|
+
if (pathHasOpenHoverComponent(components, composedPath)) {
|
|
149
|
+
clearHoverTimeout();
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
closeActiveHoverComponents();
|
|
153
|
+
if (!components?.length) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
clearHoverTimeout();
|
|
157
|
+
const closeOnClickHoverComponents = components.filter((component) => component.closeOnClick);
|
|
158
|
+
const nonCloseOnClickHoverComponents = components.filter((component) => !component.closeOnClick);
|
|
159
|
+
if (closeOnClickHoverComponents?.length) {
|
|
160
|
+
clickedComponents = closeOnClickHoverComponents;
|
|
161
|
+
toggleHoverComponents(closeOnClickHoverComponents, false);
|
|
162
|
+
}
|
|
163
|
+
toggleHoverComponents(nonCloseOnClickHoverComponents, true);
|
|
164
|
+
};
|
|
165
|
+
const pointerDownHandler = (event) => {
|
|
166
|
+
if (event.defaultPrevented || !isPrimaryPointerButton(event)) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const { clientX, clientY } = event;
|
|
170
|
+
pointerDownPosition = { x: clientX, y: clientY };
|
|
171
|
+
};
|
|
172
|
+
const keyDownHandler = (event) => {
|
|
173
|
+
if (event.defaultPrevented) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (event.key === "Escape") {
|
|
177
|
+
closeAllComponents();
|
|
178
|
+
} else if (isActivationKey(event.key)) {
|
|
179
|
+
toggleComponents(event, "click");
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
const closeAllComponents = () => {
|
|
183
|
+
Array.from(registeredElements.values()).flat().forEach((component) => component.open = false);
|
|
184
|
+
};
|
|
185
|
+
const closeComponentsIfNotActive = (components) => {
|
|
186
|
+
if (!haveSameComponents(components ?? [], activeComponents ?? [])) {
|
|
187
|
+
closeActiveHoverComponents();
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
const openHoveredComponents = (components) => {
|
|
191
|
+
hoverOpenTimeout = window.setTimeout(
|
|
192
|
+
() => {
|
|
193
|
+
if (hoverOpenTimeout === null || !haveSameComponents(components ?? [], hoveredComponents ?? [])) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
clearHoverCloseTimeout();
|
|
197
|
+
closeComponentsIfNotActive(components);
|
|
198
|
+
toggleHoverComponents(components, true);
|
|
199
|
+
},
|
|
200
|
+
activeComponents?.some((component) => component.open) ? HOVER_QUICK_OPEN_DELAY_MS : HOVER_OPEN_DELAY_MS
|
|
201
|
+
);
|
|
202
|
+
};
|
|
203
|
+
const closeHoveredComponents = () => {
|
|
204
|
+
hoverCloseTimeout = window.setTimeout(() => {
|
|
205
|
+
if (hoverCloseTimeout === null) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
closeActiveHoverComponents();
|
|
209
|
+
}, HOVER_CLOSE_DELAY_MS);
|
|
210
|
+
};
|
|
211
|
+
const pointerMoveHandler = (event) => {
|
|
212
|
+
if (event.defaultPrevented) {
|
|
213
|
+
closeActiveHoverComponents();
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const composedPath = event.composedPath();
|
|
217
|
+
const components = queryComponents(composedPath, "hover");
|
|
218
|
+
if (pathHasOpenHoverComponent(components, composedPath)) {
|
|
219
|
+
clearHoverTimeout();
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (components?.some((component) => clickedComponents?.includes(component))) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (!components?.some((component) => hoveredComponents?.includes(component))) {
|
|
226
|
+
clearHoverOpenTimeout();
|
|
227
|
+
}
|
|
228
|
+
hoveredComponents = components;
|
|
229
|
+
if (components?.length) {
|
|
230
|
+
openHoveredComponents(components);
|
|
231
|
+
} else if (activeComponents?.some((component) => component?.open)) {
|
|
232
|
+
closeHoveredComponents();
|
|
233
|
+
}
|
|
234
|
+
clickedComponents = null;
|
|
235
|
+
};
|
|
236
|
+
const blurHandler = () => {
|
|
237
|
+
closeActiveHoverComponents();
|
|
238
|
+
};
|
|
239
|
+
const pointerLeaveHandler = (event) => {
|
|
240
|
+
if (event.defaultPrevented) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
clearHoverTimeout();
|
|
244
|
+
closeHoveredComponents();
|
|
245
|
+
};
|
|
246
|
+
const addListeners = () => {
|
|
247
|
+
if (options.click) {
|
|
248
|
+
window.addEventListener("click", clickHandler);
|
|
249
|
+
window.addEventListener("keydown", keyDownHandler);
|
|
250
|
+
window.addEventListener("pointerdown", pointerDownHandler);
|
|
251
|
+
}
|
|
252
|
+
if (options.hover) {
|
|
253
|
+
window.addEventListener("click", hoverClickHandler);
|
|
254
|
+
window.addEventListener("keydown", hoverKeyDownHandler);
|
|
255
|
+
window.addEventListener("pointermove", pointerMoveHandler);
|
|
256
|
+
window.addEventListener("focusin", focusInHandler);
|
|
257
|
+
window.addEventListener("blur", blurHandler);
|
|
258
|
+
document.addEventListener("pointerleave", pointerLeaveHandler);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
const removeListeners = () => {
|
|
262
|
+
if (options.click) {
|
|
263
|
+
window.removeEventListener("pointerdown", pointerDownHandler);
|
|
264
|
+
window.removeEventListener("click", clickHandler);
|
|
265
|
+
window.removeEventListener("keydown", keyDownHandler);
|
|
266
|
+
}
|
|
267
|
+
if (options.hover) {
|
|
268
|
+
window.removeEventListener("click", hoverClickHandler);
|
|
269
|
+
window.removeEventListener("keydown", hoverKeyDownHandler);
|
|
270
|
+
window.removeEventListener("pointermove", pointerMoveHandler);
|
|
271
|
+
window.removeEventListener("focusin", focusInHandler);
|
|
272
|
+
window.removeEventListener("blur", blurHandler);
|
|
273
|
+
document.removeEventListener("pointerleave", pointerLeaveHandler);
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
const toggleFocusedComponents = (components, open) => {
|
|
277
|
+
{
|
|
278
|
+
clearHoverTimeout();
|
|
279
|
+
}
|
|
280
|
+
toggleHoverComponents(components, open);
|
|
281
|
+
};
|
|
282
|
+
const getReferenceElShadowRootNode = (referenceEl) => {
|
|
283
|
+
return referenceEl instanceof Element ? getShadowRootNode(referenceEl) : null;
|
|
284
|
+
};
|
|
285
|
+
const focusInHandler = (event) => {
|
|
286
|
+
if (event.defaultPrevented) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
const composedPath = event.composedPath();
|
|
290
|
+
const components = queryComponents(composedPath, "hover");
|
|
291
|
+
if (pathHasOpenHoverComponent(components, composedPath)) {
|
|
292
|
+
clearHoverTimeout();
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
if (components?.some((component) => clickedComponents?.includes(component))) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
clickedComponents = null;
|
|
299
|
+
closeComponentsIfNotActive(components);
|
|
300
|
+
if (!components?.length) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
toggleFocusedComponents(components, true);
|
|
304
|
+
};
|
|
305
|
+
const updateElement = (component, referenceEl) => {
|
|
306
|
+
if (!referenceEl || !component.referenceElementType) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
if (options.click && "ariaExpanded" in referenceEl) {
|
|
310
|
+
const existingComponents = registeredElements.get(referenceEl) ?? [];
|
|
311
|
+
const existingComponentOpen = existingComponents?.some((component2) => component2.open) ?? false;
|
|
312
|
+
referenceEl.ariaExpanded = toAriaBoolean(component.open || existingComponentOpen);
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
const addShadowListeners = (shadowRoot) => {
|
|
316
|
+
shadowRoot.addEventListener("focusin", focusInHandler);
|
|
317
|
+
};
|
|
318
|
+
const removeShadowListeners = (shadowRoot) => {
|
|
319
|
+
shadowRoot.removeEventListener("focusin", focusInHandler);
|
|
320
|
+
};
|
|
321
|
+
const registerShadowRoot = (shadowRoot) => {
|
|
322
|
+
const count = registeredShadowRootCounts.get(shadowRoot);
|
|
323
|
+
const newCount = (typeof count === "number" ? count : 0) + 1;
|
|
324
|
+
if (newCount === 1) {
|
|
325
|
+
addShadowListeners(shadowRoot);
|
|
326
|
+
}
|
|
327
|
+
registeredShadowRootCounts.set(shadowRoot, newCount);
|
|
328
|
+
};
|
|
329
|
+
const unregisterShadowRoot = (shadowRoot) => {
|
|
330
|
+
const count = registeredShadowRootCounts.get(shadowRoot);
|
|
331
|
+
const currentCount = typeof count === "number" ? count : 0;
|
|
332
|
+
const newCount = Math.max(0, currentCount - 1);
|
|
333
|
+
if (currentCount > 0 && newCount === 0) {
|
|
334
|
+
removeShadowListeners(shadowRoot);
|
|
335
|
+
registeredShadowRootCounts.delete(shadowRoot);
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
if (newCount > 0) {
|
|
339
|
+
registeredShadowRootCounts.set(shadowRoot, newCount);
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
const registerElement = (component, referenceEl) => {
|
|
343
|
+
if (!referenceEl || !component.referenceElementType) {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
const existingComponents = registeredElements.get(referenceEl) ?? [];
|
|
347
|
+
if (existingComponents.includes(component)) {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
if (options.click && "ariaControlsElements" in referenceEl) {
|
|
351
|
+
const currentElements = referenceEl.ariaControlsElements ?? [];
|
|
352
|
+
if (!currentElements.includes(component)) {
|
|
353
|
+
const updatedElements = [...currentElements, component];
|
|
354
|
+
referenceEl.ariaControlsElements = updatedElements;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
if (options.hover && "ariaDescribedByElements" in referenceEl) {
|
|
358
|
+
const currentElements = referenceEl.ariaDescribedByElements ?? [];
|
|
359
|
+
if (!currentElements.includes(component)) {
|
|
360
|
+
const updatedElements = [...currentElements, component];
|
|
361
|
+
referenceEl.ariaDescribedByElements = updatedElements;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
registeredComponentCount++;
|
|
365
|
+
registeredElements.set(referenceEl, [...existingComponents, component]);
|
|
366
|
+
const shadowRoot = options.hover ? getReferenceElShadowRootNode(referenceEl) : null;
|
|
367
|
+
if (shadowRoot) {
|
|
368
|
+
registerShadowRoot(shadowRoot);
|
|
369
|
+
}
|
|
370
|
+
if (registeredComponentCount === 1) {
|
|
371
|
+
addListeners();
|
|
372
|
+
}
|
|
373
|
+
updateElement(component, referenceEl);
|
|
374
|
+
};
|
|
375
|
+
const decrementRegisteredElementCount = (shadowRoot) => {
|
|
376
|
+
registeredComponentCount--;
|
|
377
|
+
if (shadowRoot) {
|
|
378
|
+
unregisterShadowRoot(shadowRoot);
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
const unregisterElement = (component, referenceEl) => {
|
|
382
|
+
if (!referenceEl || !component.referenceElementType) {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
const shadowRoot = options.hover ? getReferenceElShadowRootNode(referenceEl) : null;
|
|
386
|
+
const existingComponents = registeredElements.get(referenceEl) ?? [];
|
|
387
|
+
const updatedComponents = existingComponents.filter((p) => p !== component);
|
|
388
|
+
if (updatedComponents.length > 0) {
|
|
389
|
+
registeredElements.set(referenceEl, updatedComponents);
|
|
390
|
+
if (updatedComponents.length !== existingComponents.length) {
|
|
391
|
+
decrementRegisteredElementCount(shadowRoot);
|
|
392
|
+
}
|
|
393
|
+
} else if (registeredElements.delete(referenceEl)) {
|
|
394
|
+
decrementRegisteredElementCount(shadowRoot);
|
|
395
|
+
}
|
|
396
|
+
if (registeredComponentCount === 0) {
|
|
397
|
+
removeListeners();
|
|
398
|
+
clearHoverTimeout();
|
|
399
|
+
}
|
|
400
|
+
if (options.click && "ariaControlsElements" in referenceEl) {
|
|
401
|
+
const newElements = referenceEl.ariaControlsElements?.filter((element) => element !== component);
|
|
402
|
+
referenceEl.ariaControlsElements = newElements?.length > 0 ? newElements : null;
|
|
403
|
+
}
|
|
404
|
+
if (options.click && "ariaExpanded" in referenceEl) {
|
|
405
|
+
const hasRegisteredComponents = (updatedComponents?.length ?? 0) > 0;
|
|
406
|
+
if (hasRegisteredComponents) {
|
|
407
|
+
const existingComponentOpen = updatedComponents?.some((component2) => component2.open) ?? false;
|
|
408
|
+
referenceEl.ariaExpanded = toAriaBoolean(existingComponentOpen);
|
|
409
|
+
} else {
|
|
410
|
+
referenceEl.ariaExpanded = null;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
if (options.hover && "ariaDescribedByElements" in referenceEl) {
|
|
414
|
+
const newElements = referenceEl.ariaDescribedByElements?.filter((element) => element !== component);
|
|
415
|
+
referenceEl.ariaDescribedByElements = newElements?.length > 0 ? newElements : null;
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
return {
|
|
419
|
+
registerElement,
|
|
420
|
+
unregisterElement,
|
|
421
|
+
updateElement
|
|
422
|
+
};
|
|
423
|
+
};
|
|
424
|
+
const useReferenceElement = (options) => {
|
|
425
|
+
const { manager } = options;
|
|
426
|
+
return makeGenericController((component, controller) => {
|
|
427
|
+
let animationFrameId = null;
|
|
428
|
+
let lastRegisteredReferenceEl = null;
|
|
429
|
+
const canManageReferenceElement = (referenceEl) => {
|
|
430
|
+
return Boolean(referenceEl && component.referenceElementType);
|
|
431
|
+
};
|
|
432
|
+
const registerReferenceElement = (referenceEl) => {
|
|
433
|
+
if (!canManageReferenceElement(referenceEl)) {
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
manager.registerElement(component, referenceEl);
|
|
437
|
+
lastRegisteredReferenceEl = referenceEl;
|
|
438
|
+
};
|
|
439
|
+
const unregisterReferenceElement = (referenceEl) => {
|
|
440
|
+
if (!canManageReferenceElement(referenceEl)) {
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
manager.unregisterElement(component, referenceEl);
|
|
444
|
+
if (lastRegisteredReferenceEl === referenceEl) {
|
|
445
|
+
lastRegisteredReferenceEl = null;
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
const getReferenceElement = (component2) => {
|
|
449
|
+
const { referenceElement, el } = component2;
|
|
450
|
+
return (typeof referenceElement === "string" ? queryElementRoots(el, { id: referenceElement }) : referenceElement) || null;
|
|
451
|
+
};
|
|
452
|
+
const setUpReferenceElement = (warn = true) => {
|
|
453
|
+
if (!component.referenceElementType) {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
component.referenceEl = getReferenceElement(component);
|
|
457
|
+
const { el, referenceElement, referenceEl } = component;
|
|
458
|
+
if (warn && referenceElement && !referenceEl) {
|
|
459
|
+
console.warn(`${el.tagName}: reference-element id "${referenceElement}" was not found.`, {
|
|
460
|
+
el
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
controller.onConnected(() => {
|
|
465
|
+
animationFrameId = requestAnimationFrame(() => {
|
|
466
|
+
if (!component.el.isConnected) {
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
setUpReferenceElement(component.manager.loadedCalled);
|
|
470
|
+
registerReferenceElement(component.referenceEl);
|
|
471
|
+
});
|
|
472
|
+
});
|
|
473
|
+
controller.onLoaded(() => {
|
|
474
|
+
if (component.referenceElement && !component.referenceEl) {
|
|
475
|
+
setUpReferenceElement();
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
controller.onUpdate((changes) => {
|
|
479
|
+
if (!component.hasUpdated) {
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
if (changes.has("referenceElement")) {
|
|
483
|
+
setUpReferenceElement();
|
|
484
|
+
}
|
|
485
|
+
if (changes.has("referenceEl")) {
|
|
486
|
+
unregisterReferenceElement(changes.get("referenceEl"));
|
|
487
|
+
registerReferenceElement(component.referenceEl);
|
|
488
|
+
} else if (changes.has("open")) {
|
|
489
|
+
manager.updateElement(component, component.referenceEl);
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
controller.onDisconnected(() => {
|
|
493
|
+
if (animationFrameId != null) {
|
|
494
|
+
cancelAnimationFrame(animationFrameId);
|
|
495
|
+
animationFrameId = null;
|
|
496
|
+
}
|
|
497
|
+
unregisterReferenceElement(lastRegisteredReferenceEl);
|
|
498
|
+
});
|
|
499
|
+
});
|
|
500
|
+
};
|
|
501
|
+
export {
|
|
502
|
+
FloatingArrow as F,
|
|
503
|
+
referenceElementManager as r,
|
|
504
|
+
useReferenceElement as u
|
|
505
|
+
};
|