@likable-hair/svelte 3.0.69 → 3.0.71
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.
|
@@ -19,11 +19,11 @@ function calculateMenuPosition(params) {
|
|
|
19
19
|
let activatorHeight = params.activator.offsetHeight;
|
|
20
20
|
_top = activatorTop + activatorHeight + _activatorGap;
|
|
21
21
|
_left = activatorLeft;
|
|
22
|
-
let { top: fixedParentTop, left: fixedParentLeft,
|
|
23
|
-
if (!!
|
|
22
|
+
let { top: fixedParentTop, left: fixedParentLeft, fixedParent, validStickyParent } = getParentInstanceFromViewport(activator?.parentElement);
|
|
23
|
+
if (!!fixedParent) {
|
|
24
24
|
_top = _top - fixedParentTop;
|
|
25
25
|
_left = _left - fixedParentLeft;
|
|
26
|
-
} else {
|
|
26
|
+
} else if (!validStickyParent) {
|
|
27
27
|
_top = _top + window.scrollY;
|
|
28
28
|
_left = _left + window.scrollX;
|
|
29
29
|
}
|
|
@@ -34,11 +34,11 @@ function calculateMenuPosition(params) {
|
|
|
34
34
|
let menuWidth = params.menuElement.offsetWidth;
|
|
35
35
|
_top = activatorTop + activatorHeight + _activatorGap;
|
|
36
36
|
_left = activatorLeft;
|
|
37
|
-
let { top: fixedParentTop, left: fixedParentLeft,
|
|
38
|
-
if (!!
|
|
37
|
+
let { top: fixedParentTop, left: fixedParentLeft, fixedParent, validStickyParent } = getParentInstanceFromViewport(activator?.parentElement);
|
|
38
|
+
if (!!fixedParent) {
|
|
39
39
|
_top = _top - fixedParentTop;
|
|
40
40
|
_left = _left - fixedParentLeft;
|
|
41
|
-
} else {
|
|
41
|
+
} else if (!validStickyParent) {
|
|
42
42
|
_top = _top + window.scrollY;
|
|
43
43
|
_left = _left + window.scrollX;
|
|
44
44
|
}
|
|
@@ -81,8 +81,15 @@ function calculateMenuPosition(params) {
|
|
|
81
81
|
_left = 0;
|
|
82
82
|
if (!_top)
|
|
83
83
|
_top = 0;
|
|
84
|
-
_left = _left - positionedAncestorLeft;
|
|
85
|
-
_top = _top - positionedAncestorTop;
|
|
84
|
+
_left = _left - (positionedAncestorLeft + window.scrollX);
|
|
85
|
+
_top = _top - (positionedAncestorTop + window.scrollY);
|
|
86
|
+
if (!!activator) {
|
|
87
|
+
let { validStickyParent } = getParentInstanceFromViewport(activator?.parentElement);
|
|
88
|
+
if (!!validStickyParent) {
|
|
89
|
+
_left = _left + window.scrollX;
|
|
90
|
+
_top = _top + window.scrollY;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
86
93
|
}
|
|
87
94
|
}
|
|
88
95
|
}
|
|
@@ -173,7 +180,9 @@ function handleCloseControllerClick() {
|
|
|
173
180
|
function getParentInstanceFromViewport(activatorParent) {
|
|
174
181
|
let top = 0;
|
|
175
182
|
let left = 0;
|
|
176
|
-
let
|
|
183
|
+
let fixedParent = void 0;
|
|
184
|
+
let stickyParent = !!activatorParent && getComputedStyle(activatorParent).position === "sticky" ? activatorParent : void 0;
|
|
185
|
+
let isStickyValid = false;
|
|
177
186
|
while (!!activatorParent && activatorParent.nodeName.toLowerCase() !== "html" && activatorParent.nodeName.toLowerCase() !== "body") {
|
|
178
187
|
const currentParent = activatorParent.parentElement;
|
|
179
188
|
if (!currentParent)
|
|
@@ -185,19 +194,21 @@ function getParentInstanceFromViewport(activatorParent) {
|
|
|
185
194
|
const boundingClientRect = activatorParent.getBoundingClientRect();
|
|
186
195
|
top = top + boundingClientRect.top;
|
|
187
196
|
left = left + boundingClientRect.left;
|
|
188
|
-
|
|
197
|
+
fixedParent = activatorParent;
|
|
198
|
+
}
|
|
199
|
+
if (position === "sticky") {
|
|
200
|
+
stickyParent = activatorParent;
|
|
201
|
+
}
|
|
202
|
+
if (position === "relative" && !!stickyParent) {
|
|
203
|
+
isStickyValid = true;
|
|
189
204
|
}
|
|
190
205
|
activatorParent = activatorParent.parentElement;
|
|
191
206
|
}
|
|
192
|
-
return { top, left,
|
|
207
|
+
return { top, left, fixedParent, validStickyParent: isStickyValid ? stickyParent : void 0 };
|
|
193
208
|
}
|
|
194
209
|
function handleWindowScrollOrResize() {
|
|
195
|
-
if (open && !!menuElement && !!activator)
|
|
196
|
-
let elem = getPositionedAncestor(menuElement.parentElement);
|
|
197
|
-
if (!!elem && getComputedStyle(elem).position == "sticky")
|
|
198
|
-
return;
|
|
210
|
+
if (open && !!menuElement && !!activator)
|
|
199
211
|
calculateMenuPosition({ menuElement, activator });
|
|
200
|
-
}
|
|
201
212
|
}
|
|
202
213
|
function handleMenuClick(e, zIndex2) {
|
|
203
214
|
let otherMenus = document.querySelectorAll(`[data-menu]`);
|
|
@@ -235,7 +246,7 @@ function handleMenuClick(e, zIndex2) {
|
|
|
235
246
|
data-menu
|
|
236
247
|
data-uid={currentUid}
|
|
237
248
|
style:z-index={zIndex}
|
|
238
|
-
style:position=
|
|
249
|
+
style:position="absolute"
|
|
239
250
|
style:top={_top + "px"}
|
|
240
251
|
style:box-shadow={_boxShadow}
|
|
241
252
|
style:border-radius={_borderRadius}
|