@likable-hair/svelte 4.2.5 → 4.3.0
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/components/composed/buttons/ActivableButton.svelte +25 -7
- package/dist/components/composed/common/HeadersDrawer.svelte +66 -28
- package/dist/components/composed/common/HeadersDrawer.svelte.d.ts +22 -12
- package/dist/components/composed/common/MenuOrDrawer.svelte +40 -12
- package/dist/components/composed/common/MenuOrDrawerOptions.svelte +51 -27
- package/dist/components/composed/common/MenuOrDrawerOptions.svelte.d.ts +15 -10
- package/dist/components/composed/common/QuickActions.svelte +59 -23
- package/dist/components/composed/common/ToolTip.svelte +51 -32
- package/dist/components/composed/dashboard/DashboardShaper.svelte +280 -147
- package/dist/components/composed/dashboard/DashboardShaper.svelte.d.ts +54 -45
- package/dist/components/composed/forms/AsyncAutocomplete.svelte +81 -30
- package/dist/components/composed/forms/AsyncAutocomplete.svelte.d.ts +12 -5
- package/dist/components/composed/forms/AvatarDropdown.svelte +146 -70
- package/dist/components/composed/forms/AvatarDropdown.svelte.d.ts +27 -22
- package/dist/components/composed/forms/ConfirmOrCancelButtons.svelte +65 -19
- package/dist/components/composed/forms/CountriesAutocomplete.svelte +33 -4
- package/dist/components/composed/forms/DatePickerTextField.svelte +266 -161
- package/dist/components/composed/forms/Dropdown.svelte +88 -21
- package/dist/components/composed/forms/Dropdown.svelte.d.ts +18 -13
- package/dist/components/composed/forms/IconsDropdown.svelte +85 -40
- package/dist/components/composed/forms/IconsDropdown.svelte.d.ts +15 -8
- package/dist/components/composed/forms/LabelAndSelect.svelte +46 -5
- package/dist/components/composed/forms/LabelAndTextField.svelte +56 -3
- package/dist/components/composed/forms/PeriodPicker.svelte +38 -18
- package/dist/components/composed/forms/PeriodPicker.svelte.d.ts +32 -7
- package/dist/components/composed/forms/PeriodSelector.svelte +427 -312
- package/dist/components/composed/forms/PeriodSelector.svelte.d.ts +20 -13
- package/dist/components/composed/forms/ToggleList.svelte +71 -37
- package/dist/components/composed/forms/ToggleList.svelte.d.ts +14 -7
- package/dist/components/composed/forms/YearPickerTextField.svelte +154 -82
- package/dist/components/composed/list/DynamicTable.svelte +1372 -809
- package/dist/components/composed/list/DynamicTable.svelte.d.ts +85 -70
- package/dist/components/composed/list/EnhancedPaginatedTable.svelte +75 -32
- package/dist/components/composed/list/EnhancedPaginatedTable.svelte.d.ts +16 -6
- package/dist/components/composed/list/PaginatedTable.svelte +324 -116
- package/dist/components/composed/list/PaginatedTable.svelte.d.ts +26 -22
- package/dist/components/composed/progress/HorizontalStackedProgress.svelte +67 -29
- package/dist/components/composed/search/DynamicFilters.svelte +126 -91
- package/dist/components/composed/search/FilterEditor.svelte +169 -109
- package/dist/components/composed/search/Filters.svelte +385 -275
- package/dist/components/composed/search/GlobalSearchTextField.svelte +102 -42
- package/dist/components/composed/search/GlobalSearchTextField.svelte.d.ts +23 -20
- package/dist/components/composed/search/MobileFilterEditor.svelte +174 -120
- package/dist/components/composed/search/QuickFilters.svelte +124 -75
- package/dist/components/composed/search/SearchBar.svelte +42 -3
- package/dist/components/composed/search/SearchResults.svelte +48 -5
- package/dist/components/composed/search/SearchResults.svelte.d.ts +17 -17
- package/dist/components/layouts/CollapsibleSideBarLayout.svelte +100 -24
- package/dist/components/layouts/StableDividedSideBarLayout.svelte +74 -24
- package/dist/components/layouts/UnstableDividedSideBarLayout.svelte +140 -57
- package/dist/components/simple/buttons/Button.svelte +86 -36
- package/dist/components/simple/buttons/LinkButton.svelte +81 -25
- package/dist/components/simple/charts/BarChart.svelte +137 -105
- package/dist/components/simple/charts/LineChart.svelte +124 -92
- package/dist/components/simple/charts/PieChart.svelte +51 -23
- package/dist/components/simple/common/CollapsibleDivider.svelte +58 -26
- package/dist/components/simple/common/Divider.svelte +2 -1
- package/dist/components/simple/common/InfiniteScroll.svelte +60 -34
- package/dist/components/simple/common/MediaQuery.svelte +28 -3
- package/dist/components/simple/common/Menu.svelte +516 -371
- package/dist/components/simple/common/NoData.svelte +18 -4
- package/dist/components/simple/common/VerticalDraggableList.svelte +52 -26
- package/dist/components/simple/common/VerticalDraggableList.svelte.d.ts +20 -9
- package/dist/components/simple/dashboards/DashboardGridShaper.svelte +28 -22
- package/dist/components/simple/dates/Calendar.svelte +142 -72
- package/dist/components/simple/dates/DatePicker.svelte +138 -71
- package/dist/components/simple/dates/MonthSelector.svelte +49 -13
- package/dist/components/simple/dates/YearSelector.svelte +73 -30
- package/dist/components/simple/dialogs/Dialog.svelte +109 -59
- package/dist/components/simple/forms/Autocomplete.svelte +341 -164
- package/dist/components/simple/forms/Autocomplete.svelte.d.ts +27 -20
- package/dist/components/simple/forms/Checkbox.svelte +57 -29
- package/dist/components/simple/forms/FileInput.svelte +103 -58
- package/dist/components/simple/forms/FileInputList.svelte +115 -51
- package/dist/components/simple/forms/RadioButton.svelte +36 -3
- package/dist/components/simple/forms/Select.svelte +30 -3
- package/dist/components/simple/forms/SimpleTextField.svelte +94 -4
- package/dist/components/simple/forms/Switch.svelte +33 -11
- package/dist/components/simple/forms/Textarea.svelte +22 -5
- package/dist/components/simple/forms/VerticalSwitch.svelte +19 -2
- package/dist/components/simple/forms/VerticalTextSwitch.svelte +35 -3
- package/dist/components/simple/lists/BoxList.svelte +42 -11
- package/dist/components/simple/lists/ColorInvertedSelector.svelte +83 -25
- package/dist/components/simple/lists/HierarchyMenu.svelte +55 -20
- package/dist/components/simple/lists/Paginator.svelte +53 -34
- package/dist/components/simple/lists/SelectableMenuList.svelte +52 -16
- package/dist/components/simple/lists/SelectableVerticalList.svelte +169 -85
- package/dist/components/simple/lists/SelectableVerticalList.svelte.d.ts +21 -14
- package/dist/components/simple/lists/SidebarMenuList.svelte +127 -79
- package/dist/components/simple/lists/SimpleTable.svelte +442 -245
- package/dist/components/simple/lists/SimpleTable.svelte.d.ts +31 -22
- package/dist/components/simple/loaders/CircularLoader.css +1 -1
- package/dist/components/simple/loaders/CircularLoader.svelte +11 -3
- package/dist/components/simple/loaders/Skeleton.svelte +3 -2
- package/dist/components/simple/media/Avatar.svelte +35 -15
- package/dist/components/simple/media/DescriptiveAvatar.svelte +30 -4
- package/dist/components/simple/media/FlagIcon.svelte +13 -3
- package/dist/components/simple/media/Icon.svelte +21 -6
- package/dist/components/simple/navigation/Breadcrumb.svelte +41 -9
- package/dist/components/simple/navigation/Chip.svelte +65 -29
- package/dist/components/simple/navigation/Drawer.svelte +132 -71
- package/dist/components/simple/navigation/HeaderMenu.svelte +69 -25
- package/dist/components/simple/navigation/Navigator.svelte +45 -11
- package/dist/components/simple/navigation/TabSwitcher.svelte +60 -19
- package/dist/components/simple/notifiers/AlertBanner.svelte +59 -11
- package/dist/components/simple/progress/ProgressBar.svelte +26 -10
- package/dist/components/simple/timeline/SimpleTimeLine.svelte +52 -5
- package/dist/components/simple/timeline/SimpleTimeLine.svelte.d.ts +16 -9
- package/dist/components/simple/typography/Code.svelte +41 -12
- package/dist/stores/layouts/unstableSidebarOpened.d.ts +1 -1
- package/dist/stores/layouts/unstableSidebarOpened.js +1 -1
- package/dist/stores/theme.js +2 -2
- package/dist/utils/filters/builder.d.ts +2 -2
- package/dist/utils/filters/builder.js +7 -7
- package/dist/utils/filters/modifiers/where.d.ts +1 -1
- package/dist/utils/teleporter.js +4 -4
- package/package.json +39 -33
|
@@ -1,401 +1,546 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { createId } from '@paralleldrive/cuid2';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
fly,
|
|
6
|
+
type FadeParams,
|
|
7
|
+
type FlyParams,
|
|
8
|
+
type SlideParams,
|
|
9
|
+
type TransitionConfig,
|
|
10
|
+
} from "svelte/transition";
|
|
11
|
+
|
|
12
|
+
import { sidebarOpened } from '../../../stores/layouts/unstableSidebarOpened';
|
|
13
|
+
import type { Snippet } from 'svelte';
|
|
14
|
+
|
|
15
|
+
interface Props {
|
|
16
|
+
_top?: number;
|
|
17
|
+
_left?: number;
|
|
18
|
+
_offsetTop?: number;
|
|
19
|
+
_offsetLeft?: number;
|
|
20
|
+
_width?: string;
|
|
21
|
+
_height?: string;
|
|
22
|
+
_maxHeight?: string;
|
|
23
|
+
_minWidth?: string;
|
|
24
|
+
_overflow?: string;
|
|
25
|
+
_boxShadow?: string;
|
|
26
|
+
_borderRadius?: string;
|
|
27
|
+
_activatorGap?: number;
|
|
28
|
+
|
|
29
|
+
open?: boolean;
|
|
30
|
+
refreshPosition?: boolean;
|
|
31
|
+
activator?: HTMLElement;
|
|
32
|
+
anchor?: "bottom" | "bottom-center" | "right-center" | "left-center" | "up" | "left" | "right" | "up-center";
|
|
33
|
+
closeOnClickOutside?: boolean;
|
|
34
|
+
inAnimation?: (
|
|
35
|
+
node: Element,
|
|
36
|
+
params?: SlideParams | FlyParams | FadeParams
|
|
37
|
+
) => TransitionConfig;
|
|
38
|
+
inAnimationConfig?: SlideParams | FlyParams | FadeParams;
|
|
39
|
+
outAnimation?: (
|
|
40
|
+
node: Element,
|
|
41
|
+
params?: SlideParams | FlyParams | FadeParams
|
|
42
|
+
) => TransitionConfig;
|
|
43
|
+
outAnimationConfig?: SlideParams | FlyParams | FadeParams;
|
|
44
|
+
menuElement?: HTMLElement;
|
|
45
|
+
flipOnOverflow?: boolean;
|
|
46
|
+
stayInViewport?: boolean;
|
|
47
|
+
openingId?: string;
|
|
48
|
+
onkeydown?: () => void;
|
|
49
|
+
children?: Snippet<[]>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let {
|
|
53
|
+
_activatorGap = 5,
|
|
54
|
+
_height = 'auto',
|
|
55
|
+
_overflow = 'auto',
|
|
56
|
+
_width = 'auto',
|
|
57
|
+
anchor = 'bottom',
|
|
58
|
+
closeOnClickOutside = false,
|
|
59
|
+
flipOnOverflow = $bindable(false),
|
|
60
|
+
inAnimation = fly,
|
|
61
|
+
inAnimationConfig = {
|
|
62
|
+
duration: 100,
|
|
63
|
+
y: 10,
|
|
64
|
+
},
|
|
65
|
+
open = $bindable(),
|
|
66
|
+
outAnimation = fly,
|
|
67
|
+
outAnimationConfig = {
|
|
68
|
+
duration: 100,
|
|
69
|
+
y: 10,
|
|
70
|
+
},
|
|
71
|
+
refreshPosition = $bindable(false),
|
|
72
|
+
stayInViewport = $bindable(false),
|
|
73
|
+
_borderRadius = undefined,
|
|
74
|
+
_boxShadow = undefined,
|
|
75
|
+
_left = undefined,
|
|
76
|
+
_maxHeight = undefined,
|
|
77
|
+
_minWidth = undefined,
|
|
78
|
+
_top = undefined,
|
|
79
|
+
_offsetTop = 0,
|
|
80
|
+
_offsetLeft = 0,
|
|
81
|
+
activator = $bindable(),
|
|
82
|
+
menuElement = $bindable(),
|
|
83
|
+
openingId = $bindable(),
|
|
84
|
+
onkeydown,
|
|
85
|
+
children,
|
|
86
|
+
}: Props = $props()
|
|
87
|
+
|
|
88
|
+
let zIndex = $state(50),
|
|
89
|
+
currentUid: string = createId(),
|
|
90
|
+
closeController: HTMLElement;
|
|
91
|
+
|
|
92
|
+
let calculatedTop = $state<number | undefined>(undefined);
|
|
93
|
+
let calculatedLeft = $state<number | undefined>(undefined);
|
|
94
|
+
|
|
95
|
+
let finalTop = $derived(_top !== undefined ? _top : (calculatedTop !== undefined ? calculatedTop + _offsetTop : undefined));
|
|
96
|
+
let finalLeft = $derived(_left !== undefined ? _left : (calculatedLeft !== undefined ? calculatedLeft + _offsetLeft : undefined));
|
|
97
|
+
|
|
98
|
+
function calculateMenuPosition(params: {
|
|
99
|
+
activator: HTMLElement;
|
|
100
|
+
menuElement: HTMLElement;
|
|
101
|
+
}) {
|
|
102
|
+
if (_top !== undefined && _left !== undefined) return;
|
|
103
|
+
|
|
104
|
+
let tempTop: number = 0;
|
|
105
|
+
let tempLeft: number = 0;
|
|
106
|
+
|
|
21
107
|
if (params.menuElement) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
tempLeft = tempLeft - (menuWidth - activatorWidth) / 2;
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
tempLeft = tempLeft + (activatorWidth - menuWidth) / 2;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
108
|
+
if (params.activator) {
|
|
109
|
+
if (anchor == "bottom") {
|
|
110
|
+
let { left: activatorLeft, top: activatorTop } =
|
|
111
|
+
params.activator.getBoundingClientRect();
|
|
112
|
+
let activatorHeight = params.activator.offsetHeight;
|
|
113
|
+
tempTop = activatorTop + activatorHeight + _activatorGap;
|
|
114
|
+
tempLeft = activatorLeft;
|
|
115
|
+
|
|
116
|
+
let { top: fixedParentTop, left: fixedParentLeft, fixedParent, validStickyParent } = getParentInstanceFromViewport(activator?.parentElement);
|
|
117
|
+
if(!!fixedParent) {
|
|
118
|
+
tempTop = tempTop - fixedParentTop
|
|
119
|
+
tempLeft = tempLeft - fixedParentLeft
|
|
120
|
+
} else if(!validStickyParent && !fixedParent) {
|
|
121
|
+
tempTop = tempTop + window.scrollY
|
|
122
|
+
tempLeft = tempLeft + window.scrollX
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
} else if (anchor == "bottom-center") {
|
|
126
|
+
let { left: activatorLeft, top: activatorTop } =
|
|
127
|
+
params.activator.getBoundingClientRect();
|
|
128
|
+
let activatorHeight = params.activator.offsetHeight;
|
|
129
|
+
let activatorWidth = params.activator.offsetWidth;
|
|
130
|
+
let menuWidth = params.menuElement.offsetWidth;
|
|
131
|
+
tempTop = activatorTop + activatorHeight + _activatorGap;
|
|
132
|
+
tempLeft = activatorLeft;
|
|
133
|
+
|
|
134
|
+
let { top: fixedParentTop, left: fixedParentLeft, fixedParent, validStickyParent } = getParentInstanceFromViewport(activator?.parentElement);
|
|
135
|
+
if(!!fixedParent) {
|
|
136
|
+
tempTop = tempTop - fixedParentTop
|
|
137
|
+
tempLeft = tempLeft - fixedParentLeft
|
|
138
|
+
} else if(!validStickyParent && !fixedParent) {
|
|
139
|
+
tempTop = tempTop + window.scrollY
|
|
140
|
+
tempLeft = tempLeft + window.scrollX
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (menuWidth > activatorWidth) {
|
|
144
|
+
tempLeft = tempLeft - (menuWidth - activatorWidth) / 2;
|
|
145
|
+
} else {
|
|
146
|
+
tempLeft = tempLeft + (activatorWidth - menuWidth) / 2;
|
|
147
|
+
}
|
|
148
|
+
} else if (anchor == 'right-center') {
|
|
149
|
+
let { left: activatorLeft, top: activatorTop } = params.activator.getBoundingClientRect();
|
|
150
|
+
let activatorHeight = params.activator.offsetHeight;
|
|
151
|
+
let activatorWidth = params.activator.offsetWidth;
|
|
152
|
+
let menuHeight = params.menuElement.offsetHeight;
|
|
153
|
+
let { top: fixedParentTop, left: fixedParentLeft } = getParentInstanceFromViewport(activator?.parentElement);
|
|
154
|
+
|
|
155
|
+
tempTop = activatorTop + window.scrollY + (activatorHeight / 2) - (menuHeight / 2) - fixedParentTop;
|
|
156
|
+
tempLeft = activatorLeft + window.scrollX + activatorWidth + _activatorGap - fixedParentLeft;
|
|
157
|
+
} else if (anchor == 'left-center') {
|
|
158
|
+
let { left: activatorLeft, top: activatorTop } = params.activator.getBoundingClientRect();
|
|
159
|
+
let activatorHeight = params.activator.offsetHeight;
|
|
160
|
+
let menuHeight = params.menuElement.offsetHeight;
|
|
161
|
+
let menuWidth = params.menuElement.offsetWidth;
|
|
162
|
+
let { top: fixedParentTop, left: fixedParentLeft, fixedParent, validStickyParent } = getParentInstanceFromViewport(activator?.parentElement);
|
|
163
|
+
|
|
164
|
+
tempTop = activatorTop + (activatorHeight / 2) - (menuHeight / 2);
|
|
165
|
+
tempLeft = activatorLeft - menuWidth - _activatorGap;
|
|
166
|
+
|
|
167
|
+
if(!!fixedParent) {
|
|
168
|
+
tempTop = tempTop - fixedParentTop
|
|
169
|
+
tempLeft = tempLeft - fixedParentLeft
|
|
170
|
+
} else if(!validStickyParent && !fixedParent) {
|
|
171
|
+
tempTop = tempTop + window.scrollY
|
|
172
|
+
tempLeft = tempLeft + window.scrollX
|
|
173
|
+
}
|
|
174
|
+
} else if (anchor == 'left') {
|
|
175
|
+
let { left: activatorLeft, top: activatorTop } = params.activator.getBoundingClientRect();
|
|
176
|
+
let menuWidth = params.menuElement.offsetWidth;
|
|
177
|
+
tempTop = activatorTop;
|
|
178
|
+
tempLeft = activatorLeft - menuWidth - _activatorGap;
|
|
179
|
+
let { top: fixedParentTop, left: fixedParentLeft, fixedParent, validStickyParent } = getParentInstanceFromViewport(activator?.parentElement);
|
|
180
|
+
if(!!fixedParent) {
|
|
181
|
+
tempTop = tempTop - fixedParentTop
|
|
182
|
+
tempLeft = tempLeft - fixedParentLeft
|
|
183
|
+
} else if(!validStickyParent && !fixedParent) {
|
|
184
|
+
tempTop = tempTop + window.scrollY
|
|
185
|
+
tempLeft = tempLeft + window.scrollX
|
|
186
|
+
}
|
|
187
|
+
} else if (anchor == 'right') {
|
|
188
|
+
let { left: activatorLeft, top: activatorTop } = params.activator.getBoundingClientRect();
|
|
189
|
+
let activatorWidth = params.activator.offsetWidth;
|
|
190
|
+
tempTop = activatorTop;
|
|
191
|
+
tempLeft = activatorLeft + activatorWidth + _activatorGap;
|
|
192
|
+
|
|
193
|
+
let { top: fixedParentTop, left: fixedParentLeft, fixedParent, validStickyParent } = getParentInstanceFromViewport(activator?.parentElement);
|
|
194
|
+
if(!!fixedParent) {
|
|
195
|
+
tempTop = tempTop - fixedParentTop
|
|
196
|
+
tempLeft = tempLeft - fixedParentLeft
|
|
197
|
+
} else if(!validStickyParent && !fixedParent) {
|
|
198
|
+
tempTop = tempTop + window.scrollY
|
|
199
|
+
tempLeft = tempLeft + window.scrollX
|
|
200
|
+
}
|
|
201
|
+
} else if (anchor == 'up') {
|
|
202
|
+
let { left: activatorLeft, top: activatorTop } = params.activator.getBoundingClientRect();
|
|
203
|
+
let menuHeight = params.menuElement.offsetHeight;
|
|
204
|
+
tempTop = activatorTop - menuHeight - _activatorGap;
|
|
205
|
+
tempLeft = activatorLeft;
|
|
206
|
+
|
|
207
|
+
let { top: fixedParentTop, left: fixedParentLeft, fixedParent, validStickyParent } = getParentInstanceFromViewport(activator?.parentElement);
|
|
208
|
+
if(!!fixedParent) {
|
|
209
|
+
tempTop = tempTop - fixedParentTop
|
|
210
|
+
tempLeft = tempLeft - fixedParentLeft
|
|
211
|
+
} else if(!validStickyParent && !fixedParent) {
|
|
212
|
+
tempTop = tempTop + window.scrollY
|
|
213
|
+
tempLeft = tempLeft + window.scrollX
|
|
214
|
+
}
|
|
215
|
+
} else if (anchor == 'up-center') {
|
|
216
|
+
let { left: activatorLeft, top: activatorTop } = params.activator.getBoundingClientRect();
|
|
217
|
+
let activatorWidth = params.activator.offsetWidth;
|
|
218
|
+
let menuHeight = params.menuElement.offsetHeight;
|
|
219
|
+
let menuWidth = params.menuElement.offsetWidth;
|
|
220
|
+
tempTop = activatorTop - menuHeight - _activatorGap;
|
|
221
|
+
tempLeft = activatorLeft;
|
|
222
|
+
let { top: fixedParentTop, left: fixedParentLeft, fixedParent, validStickyParent } = getParentInstanceFromViewport(activator?.parentElement);
|
|
223
|
+
if(!!fixedParent) {
|
|
224
|
+
tempTop = tempTop - fixedParentTop
|
|
225
|
+
tempLeft = tempLeft - fixedParentLeft
|
|
226
|
+
} else if(!validStickyParent && !fixedParent) {
|
|
227
|
+
tempTop = tempTop + window.scrollY
|
|
228
|
+
tempLeft = tempLeft + window.scrollX
|
|
229
|
+
}
|
|
230
|
+
if (menuWidth > activatorWidth) {
|
|
231
|
+
tempLeft = tempLeft - (menuWidth - activatorWidth) / 2;
|
|
232
|
+
} else {
|
|
233
|
+
tempLeft = tempLeft + (activatorWidth - menuWidth) / 2;
|
|
234
|
+
}
|
|
155
235
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
let { left: activatorLeft } = params.activator.getBoundingClientRect();
|
|
167
|
-
tempLeft = activatorLeft + window.scrollX - _activatorGap - (menuElement?.offsetWidth || 0);
|
|
168
|
-
}
|
|
169
|
-
if (anchor == 'left-center' &&
|
|
170
|
-
tempLeft < 0) {
|
|
171
|
-
let { left: activatorLeft } = params.activator.getBoundingClientRect();
|
|
172
|
-
let activatorWidth = params.activator.offsetWidth;
|
|
173
|
-
tempLeft = activatorLeft + window.scrollX + activatorWidth + _activatorGap;
|
|
174
|
-
}
|
|
175
|
-
if (anchor == 'left' &&
|
|
176
|
-
tempLeft < 0) {
|
|
177
|
-
let { left: activatorLeft } = params.activator.getBoundingClientRect();
|
|
178
|
-
let activatorWidth = params.activator.offsetWidth;
|
|
179
|
-
tempLeft = activatorLeft + window.scrollX + activatorWidth + _activatorGap;
|
|
180
|
-
}
|
|
181
|
-
if (anchor == 'right' &&
|
|
182
|
-
window.innerWidth + window.scrollX <
|
|
183
|
-
tempLeft + (menuElement?.offsetWidth || 0)) {
|
|
184
|
-
let { left: activatorLeft } = params.activator.getBoundingClientRect();
|
|
185
|
-
let menuWidth = params.menuElement.offsetWidth;
|
|
186
|
-
tempLeft = activatorLeft + window.scrollX - menuWidth - _activatorGap;
|
|
187
|
-
}
|
|
188
|
-
if (anchor == 'up' &&
|
|
189
|
-
tempTop < window.scrollY) {
|
|
190
|
-
let { top: activatorTop } = params.activator.getBoundingClientRect();
|
|
191
|
-
let activatorHeight = params.activator.offsetHeight;
|
|
192
|
-
tempTop = activatorTop + window.scrollY + activatorHeight + _activatorGap;
|
|
193
|
-
}
|
|
194
|
-
if (anchor == 'up-center' &&
|
|
195
|
-
tempTop < window.scrollY) {
|
|
196
|
-
let { top: activatorTop } = params.activator.getBoundingClientRect();
|
|
197
|
-
let activatorHeight = params.activator.offsetHeight;
|
|
198
|
-
tempTop = activatorTop + window.scrollY + activatorHeight + _activatorGap;
|
|
199
|
-
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if(flipOnOverflow && !!params.activator) {
|
|
239
|
+
if (
|
|
240
|
+
(anchor == 'bottom' || anchor == 'bottom-center') &&
|
|
241
|
+
tempTop + (menuElement?.offsetHeight || 0) > window.scrollY + window.innerHeight
|
|
242
|
+
) {
|
|
243
|
+
let { top: activatorTop } = params.activator.getBoundingClientRect();
|
|
244
|
+
let menuHeight = params.menuElement.offsetHeight;
|
|
245
|
+
tempTop = activatorTop + window.scrollY - menuHeight - _activatorGap;
|
|
200
246
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
247
|
+
|
|
248
|
+
if (
|
|
249
|
+
anchor == 'right-center' &&
|
|
250
|
+
window.innerWidth + window.scrollX <
|
|
251
|
+
tempLeft + (menuElement?.offsetWidth || 0)
|
|
252
|
+
) {
|
|
253
|
+
let { left: activatorLeft } = params.activator.getBoundingClientRect();
|
|
254
|
+
tempLeft = activatorLeft + window.scrollX - _activatorGap - (menuElement?.offsetWidth || 0)
|
|
209
255
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
tempTop = tempTop + window.scrollY;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
256
|
+
|
|
257
|
+
if (
|
|
258
|
+
anchor == 'left-center' &&
|
|
259
|
+
tempLeft < 0
|
|
260
|
+
) {
|
|
261
|
+
let { left: activatorLeft } = params.activator.getBoundingClientRect();
|
|
262
|
+
let activatorWidth = params.activator.offsetWidth;
|
|
263
|
+
tempLeft = activatorLeft + window.scrollX + activatorWidth + _activatorGap
|
|
221
264
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
const controllers = document.querySelectorAll(`[data-operation="close"][data-opening-id="${openingId}"]`);
|
|
231
|
-
for (let k = 0; k < controllers.length; k += 1) {
|
|
232
|
-
if (controllers[k] !== closeController) {
|
|
233
|
-
const clickEvent = new MouseEvent('click', {
|
|
234
|
-
bubbles: true,
|
|
235
|
-
cancelable: true,
|
|
236
|
-
view: window
|
|
237
|
-
});
|
|
238
|
-
controllers[k].dispatchEvent(clickEvent);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
265
|
+
|
|
266
|
+
if (
|
|
267
|
+
anchor == 'left' &&
|
|
268
|
+
tempLeft < 0
|
|
269
|
+
) {
|
|
270
|
+
let { left: activatorLeft } = params.activator.getBoundingClientRect();
|
|
271
|
+
let activatorWidth = params.activator.offsetWidth;
|
|
272
|
+
tempLeft = activatorLeft + window.scrollX + activatorWidth + _activatorGap
|
|
241
273
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
274
|
+
|
|
275
|
+
if (
|
|
276
|
+
anchor == 'right' &&
|
|
277
|
+
window.innerWidth + window.scrollX <
|
|
278
|
+
tempLeft + (menuElement?.offsetWidth || 0)
|
|
279
|
+
) {
|
|
280
|
+
let { left: activatorLeft } = params.activator.getBoundingClientRect();
|
|
281
|
+
let menuWidth = params.menuElement.offsetWidth;
|
|
282
|
+
tempLeft = activatorLeft + window.scrollX - menuWidth - _activatorGap
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (
|
|
286
|
+
anchor == 'up' &&
|
|
287
|
+
tempTop < window.scrollY
|
|
288
|
+
) {
|
|
289
|
+
let { top: activatorTop } = params.activator.getBoundingClientRect();
|
|
290
|
+
let activatorHeight = params.activator.offsetHeight;
|
|
291
|
+
tempTop = activatorTop + window.scrollY + activatorHeight + _activatorGap
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (
|
|
295
|
+
anchor == 'up-center' &&
|
|
296
|
+
tempTop < window.scrollY
|
|
297
|
+
) {
|
|
298
|
+
let { top: activatorTop } = params.activator.getBoundingClientRect();
|
|
299
|
+
let activatorHeight = params.activator.offsetHeight;
|
|
300
|
+
tempTop = activatorTop + window.scrollY + activatorHeight + _activatorGap
|
|
255
301
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
if (
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if(stayInViewport) {
|
|
305
|
+
if (
|
|
306
|
+
window.innerWidth + window.scrollX <
|
|
307
|
+
tempLeft + (menuElement?.offsetWidth || 0)
|
|
308
|
+
) {
|
|
309
|
+
tempLeft = Math.max(
|
|
310
|
+
window.innerWidth + window.scrollX - (menuElement?.offsetWidth || 0),
|
|
311
|
+
0
|
|
312
|
+
);
|
|
264
313
|
}
|
|
265
|
-
if (
|
|
266
|
-
|
|
267
|
-
if (!maxZIndex || maxZIndex < Number(menu.style.zIndex))
|
|
268
|
-
maxZIndex = Number(menu.style.zIndex);
|
|
269
|
-
});
|
|
314
|
+
if (tempLeft < window.scrollX) {
|
|
315
|
+
tempLeft = window.scrollX;
|
|
270
316
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if(!!positionedAncestor) {
|
|
320
|
+
let { left: positionedAncestorLeft, top: positionedAncestorTop } = positionedAncestor.getBoundingClientRect();
|
|
321
|
+
|
|
322
|
+
tempLeft = tempLeft - (positionedAncestorLeft + window.scrollX - positionedAncestor.scrollLeft)
|
|
323
|
+
tempTop = tempTop - (positionedAncestorTop + window.scrollY - positionedAncestor.scrollTop)
|
|
324
|
+
|
|
325
|
+
if(!!activator) {
|
|
326
|
+
let { validStickyParent, fixedParent } = getParentInstanceFromViewport(activator?.parentElement)
|
|
327
|
+
if(!!validStickyParent || !!fixedParent) {
|
|
328
|
+
tempLeft = tempLeft + window.scrollX
|
|
329
|
+
tempTop = tempTop + window.scrollY
|
|
330
|
+
}
|
|
279
331
|
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
calculatedTop = tempTop;
|
|
335
|
+
calculatedLeft = tempLeft;
|
|
280
336
|
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
let positionedAncestor: HTMLElement | undefined = undefined
|
|
340
|
+
|
|
341
|
+
$effect(() => {
|
|
342
|
+
if (open) {
|
|
343
|
+
if(!!openingId) {
|
|
344
|
+
const _openingId = openingId
|
|
345
|
+
const _currentUid = currentUid
|
|
284
346
|
setTimeout(() => {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
347
|
+
const controllers = document.querySelectorAll(`[data-operation="close"][data-opening-id="${_openingId}"]`)
|
|
348
|
+
for(let k = 0; k < controllers.length; k += 1) {
|
|
349
|
+
if(controllers[k].getAttribute('data-uid') !== _currentUid) {
|
|
350
|
+
const clickEvent = new MouseEvent('click', {
|
|
351
|
+
bubbles: true,
|
|
352
|
+
cancelable: true,
|
|
353
|
+
view: window
|
|
354
|
+
})
|
|
355
|
+
controllers[k].dispatchEvent(clickEvent)
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}, 0)
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
if (!menuElement || !activator) return;
|
|
362
|
+
if (_top !== undefined && _left !== undefined) return;
|
|
363
|
+
|
|
364
|
+
if(!!activator) {
|
|
365
|
+
let parent = activator.parentElement
|
|
366
|
+
while(!!parent) {
|
|
367
|
+
let parentPosition = getComputedStyle(parent).position
|
|
368
|
+
parent.addEventListener('scroll', refreshMenuPosition)
|
|
369
|
+
if(parentPosition == 'absolute' || parentPosition == 'fixed' || parentPosition === 'relative') break
|
|
370
|
+
parent = parent.parentElement
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
let otherMenus: NodeListOf<HTMLElement> =
|
|
375
|
+
document.querySelectorAll("[data-menu]");
|
|
376
|
+
let otherDialogs: NodeListOf<HTMLElement> =
|
|
377
|
+
document.querySelectorAll("[data-dialog]");
|
|
378
|
+
|
|
379
|
+
let maxZIndex: number | undefined = undefined;
|
|
380
|
+
if (otherDialogs.length > 0) {
|
|
381
|
+
otherDialogs.forEach((dialog) => {
|
|
382
|
+
if (!maxZIndex || maxZIndex < Number(dialog.style.zIndex))
|
|
383
|
+
maxZIndex = Number(dialog.style.zIndex);
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (otherMenus.length > 0) {
|
|
388
|
+
otherMenus.forEach((menu) => {
|
|
389
|
+
if (!maxZIndex || maxZIndex < Number(menu.style.zIndex))
|
|
390
|
+
maxZIndex = Number(menu.style.zIndex);
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
if (!!activator && !!menuElement)
|
|
395
|
+
calculateMenuPosition({ activator, menuElement });
|
|
396
|
+
|
|
397
|
+
if (maxZIndex) zIndex = maxZIndex + 2;
|
|
398
|
+
|
|
399
|
+
if(!!menuElement && !!activator) {
|
|
400
|
+
let elem = getPositionedAncestor(menuElement.parentElement)
|
|
401
|
+
positionedAncestor = elem == null ? undefined : elem
|
|
402
|
+
calculateMenuPosition({menuElement, activator})
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
})
|
|
406
|
+
$effect(() => {
|
|
407
|
+
if (!!_width && !!activator && !!menuElement) {
|
|
408
|
+
setTimeout(() => {
|
|
409
|
+
if(!!activator && !!menuElement)
|
|
410
|
+
calculateMenuPosition({ activator, menuElement });
|
|
411
|
+
}, 1)
|
|
288
412
|
}
|
|
289
|
-
})
|
|
290
|
-
$effect(() => {
|
|
413
|
+
})
|
|
414
|
+
$effect(() => {
|
|
291
415
|
if (refreshPosition && !!activator && !!menuElement) {
|
|
292
|
-
|
|
293
|
-
|
|
416
|
+
calculateMenuPosition({ activator, menuElement });
|
|
417
|
+
refreshPosition = false;
|
|
294
418
|
}
|
|
295
|
-
})
|
|
296
|
-
function handleOutsideClick(node, params) {
|
|
419
|
+
})
|
|
420
|
+
function handleOutsideClick(node: HTMLElement, params: { enabled: boolean; activator?: HTMLElement }) {
|
|
297
421
|
const handleWindowClick = () => {
|
|
298
|
-
|
|
422
|
+
open = false;
|
|
299
423
|
};
|
|
300
|
-
|
|
301
|
-
|
|
424
|
+
|
|
425
|
+
const handleStopPropagation = (event: Event) => {
|
|
426
|
+
event.stopPropagation();
|
|
302
427
|
};
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
428
|
+
|
|
429
|
+
function updateListeners(currentParams: { enabled: boolean; activator?: HTMLElement }) {
|
|
430
|
+
window.removeEventListener("mousedown", handleWindowClick);
|
|
431
|
+
window.removeEventListener("touchstart", handleWindowClick);
|
|
432
|
+
node.removeEventListener("mousedown", handleStopPropagation);
|
|
433
|
+
node.removeEventListener("touchstart", handleStopPropagation);
|
|
434
|
+
|
|
435
|
+
if (currentParams.activator) {
|
|
436
|
+
currentParams.activator.removeEventListener("mousedown", handleStopPropagation);
|
|
437
|
+
currentParams.activator.removeEventListener("touchstart", handleStopPropagation);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
if (currentParams.enabled) {
|
|
441
|
+
window.addEventListener("mousedown", handleWindowClick);
|
|
442
|
+
window.addEventListener("touchstart", handleWindowClick);
|
|
443
|
+
|
|
444
|
+
node.addEventListener("mousedown", handleStopPropagation);
|
|
445
|
+
node.addEventListener("touchstart", handleStopPropagation);
|
|
446
|
+
|
|
308
447
|
if (currentParams.activator) {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
}
|
|
312
|
-
if (currentParams.enabled) {
|
|
313
|
-
window.addEventListener("mousedown", handleWindowClick);
|
|
314
|
-
window.addEventListener("touchstart", handleWindowClick);
|
|
315
|
-
node.addEventListener("mousedown", handleStopPropagation);
|
|
316
|
-
node.addEventListener("touchstart", handleStopPropagation);
|
|
317
|
-
if (currentParams.activator) {
|
|
318
|
-
currentParams.activator.addEventListener("mousedown", handleStopPropagation);
|
|
319
|
-
currentParams.activator.addEventListener("touchstart", handleStopPropagation);
|
|
320
|
-
}
|
|
448
|
+
currentParams.activator.addEventListener("mousedown", handleStopPropagation);
|
|
449
|
+
currentParams.activator.addEventListener("touchstart", handleStopPropagation);
|
|
321
450
|
}
|
|
451
|
+
}
|
|
322
452
|
}
|
|
453
|
+
|
|
323
454
|
updateListeners(params);
|
|
455
|
+
|
|
324
456
|
return {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
457
|
+
update(newParams: { enabled: boolean; activator?: HTMLElement }) {
|
|
458
|
+
updateListeners(newParams);
|
|
459
|
+
},
|
|
460
|
+
destroy() {
|
|
461
|
+
updateListeners({ enabled: false, activator: params.activator });
|
|
462
|
+
}
|
|
331
463
|
};
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
if (positions.includes(getComputedStyle(elem).position))
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
function handleCloseControllerClick(event) {
|
|
341
|
-
event.stopPropagation()
|
|
342
|
-
open = false
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
function getPositionedAncestor(elem: HTMLElement | null, positions: string[] = ['fixed', 'absolute', 'sticky', 'relative']): HTMLElement | null {
|
|
467
|
+
if (!elem) return null
|
|
468
|
+
if (positions.includes(getComputedStyle(elem).position)) return elem
|
|
469
|
+
return getPositionedAncestor(elem.parentElement)
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
function handleCloseControllerClick(event: MouseEvent) {
|
|
473
|
+
event.stopPropagation()
|
|
474
|
+
open = false
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
function getParentInstanceFromViewport(activatorParent: HTMLElement | undefined | null): {
|
|
478
|
+
top: number
|
|
479
|
+
left: number
|
|
480
|
+
fixedParent?: HTMLElement,
|
|
481
|
+
validStickyParent?: HTMLElement
|
|
482
|
+
} {
|
|
483
|
+
let top = 0
|
|
484
|
+
let left = 0
|
|
485
|
+
let fixedParent: HTMLElement | undefined = undefined
|
|
486
|
+
let stickyParent: HTMLElement | undefined = !!activatorParent && getComputedStyle(activatorParent).position === 'sticky' ? activatorParent : undefined
|
|
487
|
+
let isStickyValid: boolean = false
|
|
488
|
+
|
|
489
|
+
while(!!activatorParent && activatorParent.nodeName.toLowerCase() !== 'html' && activatorParent.nodeName.toLowerCase() !== 'body') {
|
|
490
|
+
const currentParent = activatorParent.parentElement
|
|
491
|
+
if(!currentParent) break
|
|
492
|
+
|
|
493
|
+
const computedStyle = getComputedStyle(currentParent)
|
|
494
|
+
const position = computedStyle.position;
|
|
495
|
+
const display = computedStyle.display;
|
|
496
|
+
|
|
497
|
+
if((position === 'fixed' || position === 'absolute' || position === 'relative') && display === "flex") {
|
|
498
|
+
const boundingClientRect = currentParent.getBoundingClientRect();
|
|
499
|
+
top = top + boundingClientRect.top
|
|
500
|
+
left = left + boundingClientRect.left
|
|
501
|
+
fixedParent = currentParent
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
if(position === 'sticky') {
|
|
505
|
+
stickyParent = activatorParent
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
if(position === 'relative' && !!stickyParent) {
|
|
509
|
+
isStickyValid = true
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
activatorParent = activatorParent.parentElement
|
|
513
|
+
|
|
370
514
|
}
|
|
371
|
-
return { top, left, fixedParent, validStickyParent: isStickyValid ? stickyParent : undefined }
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
|
|
515
|
+
return { top, left, fixedParent, validStickyParent: isStickyValid ? stickyParent : undefined }
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
function refreshMenuPosition() {
|
|
519
|
+
if(open && !!menuElement && !!activator) calculateMenuPosition({ menuElement, activator })
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
function handleMenuClick(e: MouseEvent, zIndex: number) {
|
|
523
|
+
let otherMenus: NodeListOf<HTMLElement> = document.querySelectorAll(`[data-menu]`)
|
|
379
524
|
otherMenus.forEach(m => {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
}
|
|
525
|
+
let uid = m.getAttribute('data-uid')
|
|
526
|
+
if(uid !== currentUid && Number(m.style.zIndex) > zIndex) {
|
|
527
|
+
let controller = document.querySelector(`[data-operation="close"][data-uid="${uid}"]`)
|
|
528
|
+
if(!!controller) {
|
|
529
|
+
const clickEvent = new MouseEvent('click', {
|
|
530
|
+
bubbles: true,
|
|
531
|
+
cancelable: true,
|
|
532
|
+
view: window
|
|
533
|
+
})
|
|
534
|
+
controller.dispatchEvent(clickEvent)
|
|
391
535
|
}
|
|
392
|
-
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
536
|
+
}
|
|
537
|
+
})
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
// TODO find a better way to update menu positions with animations
|
|
541
|
+
$effect(() => {
|
|
542
|
+
if($sidebarOpened !== undefined) setTimeout(refreshMenuPosition, 300)
|
|
543
|
+
})
|
|
399
544
|
</script>
|
|
400
545
|
|
|
401
546
|
<svelte:window onscroll={refreshMenuPosition} onresize={refreshMenuPosition} ></svelte:window>
|