@db-ux/react-core-components 4.11.1 → 4.12.1
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/CHANGELOG.md +23 -0
- package/dist/components/accordion/accordion.d.ts +1 -1
- package/dist/components/accordion/accordion.js +83 -102
- package/dist/components/accordion/index.d.ts +1 -1
- package/dist/components/accordion/index.js +1 -0
- package/dist/components/accordion/model.d.ts +2 -2
- package/dist/components/accordion/model.js +2 -4
- package/dist/components/accordion-item/accordion-item.d.ts +2 -2
- package/dist/components/accordion-item/accordion-item.js +56 -89
- package/dist/components/accordion-item/index.d.ts +1 -1
- package/dist/components/accordion-item/index.js +1 -0
- package/dist/components/accordion-item/model.d.ts +1 -1
- package/dist/components/accordion-item/model.js +1 -0
- package/dist/components/badge/badge.d.ts +1 -1
- package/dist/components/badge/badge.js +28 -72
- package/dist/components/badge/index.d.ts +1 -1
- package/dist/components/badge/index.js +1 -0
- package/dist/components/badge/model.d.ts +1 -1
- package/dist/components/badge/model.js +1 -12
- package/dist/components/brand/brand.d.ts +1 -1
- package/dist/components/brand/brand.js +10 -60
- package/dist/components/brand/index.d.ts +1 -1
- package/dist/components/brand/index.js +1 -0
- package/dist/components/brand/model.d.ts +1 -1
- package/dist/components/brand/model.js +1 -0
- package/dist/components/button/button.d.ts +1 -1
- package/dist/components/button/button.js +19 -75
- package/dist/components/button/index.d.ts +1 -1
- package/dist/components/button/index.js +1 -0
- package/dist/components/button/model.d.ts +1 -1
- package/dist/components/button/model.js +2 -13
- package/dist/components/card/card.d.ts +1 -1
- package/dist/components/card/card.js +14 -65
- package/dist/components/card/index.d.ts +1 -1
- package/dist/components/card/index.js +1 -0
- package/dist/components/card/model.d.ts +1 -1
- package/dist/components/card/model.js +2 -8
- package/dist/components/checkbox/checkbox.d.ts +1 -1
- package/dist/components/checkbox/checkbox.js +143 -163
- package/dist/components/checkbox/index.d.ts +1 -1
- package/dist/components/checkbox/index.js +1 -0
- package/dist/components/checkbox/model.d.ts +1 -1
- package/dist/components/checkbox/model.js +1 -0
- package/dist/components/custom-button/custom-button.d.ts +1 -1
- package/dist/components/custom-button/custom-button.js +10 -65
- package/dist/components/custom-button/index.d.ts +1 -1
- package/dist/components/custom-button/index.js +1 -0
- package/dist/components/custom-button/model.d.ts +2 -2
- package/dist/components/custom-button/model.js +1 -0
- package/dist/components/custom-select/custom-select.d.ts +1 -1
- package/dist/components/custom-select/custom-select.js +688 -509
- package/dist/components/custom-select/index.d.ts +1 -1
- package/dist/components/custom-select/index.js +1 -0
- package/dist/components/custom-select/model.d.ts +4 -4
- package/dist/components/custom-select/model.js +1 -8
- package/dist/components/custom-select-dropdown/custom-select-dropdown.d.ts +1 -1
- package/dist/components/custom-select-dropdown/custom-select-dropdown.js +10 -62
- package/dist/components/custom-select-dropdown/index.d.ts +1 -1
- package/dist/components/custom-select-dropdown/index.js +1 -0
- package/dist/components/custom-select-dropdown/model.d.ts +1 -1
- package/dist/components/custom-select-dropdown/model.js +1 -8
- package/dist/components/custom-select-form-field/custom-select-form-field.d.ts +1 -1
- package/dist/components/custom-select-form-field/custom-select-form-field.js +9 -57
- package/dist/components/custom-select-form-field/index.d.ts +1 -1
- package/dist/components/custom-select-form-field/index.js +1 -0
- package/dist/components/custom-select-form-field/model.d.ts +1 -1
- package/dist/components/custom-select-form-field/model.js +1 -0
- package/dist/components/custom-select-list/custom-select-list.d.ts +1 -1
- package/dist/components/custom-select-list/custom-select-list.js +9 -60
- package/dist/components/custom-select-list/index.d.ts +1 -1
- package/dist/components/custom-select-list/index.js +1 -0
- package/dist/components/custom-select-list/model.d.ts +1 -1
- package/dist/components/custom-select-list/model.js +1 -0
- package/dist/components/custom-select-list-item/custom-select-list-item.d.ts +2 -2
- package/dist/components/custom-select-list-item/custom-select-list-item.js +28 -89
- package/dist/components/custom-select-list-item/index.d.ts +1 -1
- package/dist/components/custom-select-list-item/index.js +1 -0
- package/dist/components/custom-select-list-item/model.d.ts +1 -1
- package/dist/components/custom-select-list-item/model.js +1 -4
- package/dist/components/divider/divider.d.ts +1 -1
- package/dist/components/divider/divider.js +9 -60
- package/dist/components/divider/index.d.ts +1 -1
- package/dist/components/divider/index.js +1 -0
- package/dist/components/divider/model.d.ts +1 -1
- package/dist/components/divider/model.js +2 -4
- package/dist/components/drawer/drawer.d.ts +2 -2
- package/dist/components/drawer/drawer.js +109 -118
- package/dist/components/drawer/index.d.ts +1 -1
- package/dist/components/drawer/index.js +1 -0
- package/dist/components/drawer/model.d.ts +4 -1
- package/dist/components/drawer/model.js +4 -14
- package/dist/components/header/header.d.ts +1 -1
- package/dist/components/header/header.js +43 -143
- package/dist/components/header/index.d.ts +1 -1
- package/dist/components/header/index.js +1 -0
- package/dist/components/header/model.d.ts +1 -1
- package/dist/components/header/model.js +1 -0
- package/dist/components/icon/icon.d.ts +1 -1
- package/dist/components/icon/icon.js +9 -61
- package/dist/components/icon/index.d.ts +1 -1
- package/dist/components/icon/index.js +1 -0
- package/dist/components/icon/model.d.ts +1 -1
- package/dist/components/icon/model.js +1 -11
- package/dist/components/infotext/index.d.ts +1 -1
- package/dist/components/infotext/index.js +1 -0
- package/dist/components/infotext/infotext.d.ts +1 -1
- package/dist/components/infotext/infotext.js +9 -62
- package/dist/components/infotext/model.d.ts +1 -1
- package/dist/components/infotext/model.js +1 -0
- package/dist/components/input/index.d.ts +1 -1
- package/dist/components/input/index.js +1 -0
- package/dist/components/input/input.d.ts +1 -1
- package/dist/components/input/input.js +154 -198
- package/dist/components/input/model.d.ts +1 -1
- package/dist/components/input/model.js +5 -21
- package/dist/components/link/index.d.ts +1 -1
- package/dist/components/link/index.js +1 -0
- package/dist/components/link/link.d.ts +1 -1
- package/dist/components/link/link.js +9 -70
- package/dist/components/link/model.d.ts +1 -1
- package/dist/components/link/model.js +3 -8
- package/dist/components/navigation/index.d.ts +1 -1
- package/dist/components/navigation/index.js +1 -0
- package/dist/components/navigation/model.d.ts +1 -1
- package/dist/components/navigation/model.js +1 -0
- package/dist/components/navigation/navigation.d.ts +1 -1
- package/dist/components/navigation/navigation.js +9 -57
- package/dist/components/navigation-item/index.d.ts +1 -1
- package/dist/components/navigation-item/index.js +1 -0
- package/dist/components/navigation-item/model.d.ts +2 -2
- package/dist/components/navigation-item/model.js +1 -0
- package/dist/components/navigation-item/navigation-item.d.ts +1 -1
- package/dist/components/navigation-item/navigation-item.js +71 -117
- package/dist/components/notification/index.d.ts +1 -1
- package/dist/components/notification/index.js +1 -0
- package/dist/components/notification/model.d.ts +1 -1
- package/dist/components/notification/model.js +3 -12
- package/dist/components/notification/notification.d.ts +2 -2
- package/dist/components/notification/notification.js +23 -100
- package/dist/components/page/index.d.ts +1 -1
- package/dist/components/page/index.js +1 -0
- package/dist/components/page/model.d.ts +1 -1
- package/dist/components/page/model.js +2 -4
- package/dist/components/page/page.d.ts +1 -1
- package/dist/components/page/page.js +42 -74
- package/dist/components/popover/index.d.ts +1 -1
- package/dist/components/popover/index.js +1 -0
- package/dist/components/popover/model.d.ts +1 -1
- package/dist/components/popover/model.js +1 -0
- package/dist/components/popover/popover.d.ts +1 -1
- package/dist/components/popover/popover.js +119 -126
- package/dist/components/radio/index.d.ts +1 -1
- package/dist/components/radio/index.js +1 -0
- package/dist/components/radio/model.d.ts +1 -1
- package/dist/components/radio/model.js +1 -0
- package/dist/components/radio/radio.d.ts +1 -1
- package/dist/components/radio/radio.js +86 -124
- package/dist/components/section/index.d.ts +1 -1
- package/dist/components/section/index.js +1 -0
- package/dist/components/section/model.d.ts +1 -1
- package/dist/components/section/model.js +1 -0
- package/dist/components/section/section.d.ts +1 -1
- package/dist/components/section/section.js +9 -59
- package/dist/components/select/index.d.ts +1 -1
- package/dist/components/select/index.js +1 -0
- package/dist/components/select/model.d.ts +1 -1
- package/dist/components/select/model.js +1 -0
- package/dist/components/select/select.d.ts +1 -1
- package/dist/components/select/select.js +172 -188
- package/dist/components/stack/index.d.ts +1 -1
- package/dist/components/stack/index.js +1 -0
- package/dist/components/stack/model.d.ts +1 -1
- package/dist/components/stack/model.js +4 -14
- package/dist/components/stack/stack.d.ts +1 -1
- package/dist/components/stack/stack.js +9 -63
- package/dist/components/switch/index.d.ts +1 -1
- package/dist/components/switch/index.js +1 -0
- package/dist/components/switch/model.d.ts +1 -1
- package/dist/components/switch/model.js +1 -0
- package/dist/components/switch/switch.d.ts +1 -1
- package/dist/components/switch/switch.js +135 -182
- package/dist/components/tab-item/index.d.ts +1 -1
- package/dist/components/tab-item/index.js +1 -0
- package/dist/components/tab-item/model.d.ts +1 -1
- package/dist/components/tab-item/model.js +1 -0
- package/dist/components/tab-item/tab-item.d.ts +1 -1
- package/dist/components/tab-item/tab-item.js +72 -105
- package/dist/components/tab-list/index.d.ts +1 -1
- package/dist/components/tab-list/index.js +1 -0
- package/dist/components/tab-list/model.d.ts +1 -1
- package/dist/components/tab-list/model.js +1 -0
- package/dist/components/tab-list/tab-list.d.ts +1 -1
- package/dist/components/tab-list/tab-list.js +9 -60
- package/dist/components/tab-panel/index.d.ts +1 -1
- package/dist/components/tab-panel/index.js +1 -0
- package/dist/components/tab-panel/model.d.ts +1 -1
- package/dist/components/tab-panel/model.js +1 -0
- package/dist/components/tab-panel/tab-panel.d.ts +1 -1
- package/dist/components/tab-panel/tab-panel.js +10 -59
- package/dist/components/table/examples/data.d.ts +1 -1
- package/dist/components/table/examples/data.js +258 -0
- package/dist/components/table/index.d.ts +1 -1
- package/dist/components/table/index.js +1 -0
- package/dist/components/table/model.d.ts +2 -2
- package/dist/components/table/model.js +6 -28
- package/dist/components/table/table.d.ts +1 -1
- package/dist/components/table/table.js +77 -111
- package/dist/components/table-body/index.d.ts +1 -1
- package/dist/components/table-body/index.js +1 -0
- package/dist/components/table-body/model.d.ts +2 -2
- package/dist/components/table-body/model.js +1 -0
- package/dist/components/table-body/table-body.d.ts +1 -1
- package/dist/components/table-body/table-body.js +12 -64
- package/dist/components/table-caption/index.d.ts +1 -1
- package/dist/components/table-caption/index.js +1 -0
- package/dist/components/table-caption/model.d.ts +1 -1
- package/dist/components/table-caption/model.js +1 -0
- package/dist/components/table-caption/table-caption.d.ts +1 -1
- package/dist/components/table-caption/table-caption.js +9 -57
- package/dist/components/table-data-cell/index.d.ts +1 -1
- package/dist/components/table-data-cell/index.js +1 -0
- package/dist/components/table-data-cell/model.d.ts +1 -1
- package/dist/components/table-data-cell/model.js +1 -0
- package/dist/components/table-data-cell/table-data-cell.d.ts +1 -1
- package/dist/components/table-data-cell/table-data-cell.js +9 -62
- package/dist/components/table-footer/index.d.ts +1 -1
- package/dist/components/table-footer/index.js +1 -0
- package/dist/components/table-footer/model.d.ts +2 -2
- package/dist/components/table-footer/model.js +1 -0
- package/dist/components/table-footer/table-footer.d.ts +1 -1
- package/dist/components/table-footer/table-footer.js +12 -64
- package/dist/components/table-head/index.d.ts +1 -1
- package/dist/components/table-head/index.js +1 -0
- package/dist/components/table-head/model.d.ts +2 -2
- package/dist/components/table-head/model.js +1 -0
- package/dist/components/table-head/table-head.d.ts +1 -1
- package/dist/components/table-head/table-head.js +18 -71
- package/dist/components/table-header-cell/index.d.ts +1 -1
- package/dist/components/table-header-cell/index.js +1 -0
- package/dist/components/table-header-cell/model.d.ts +1 -1
- package/dist/components/table-header-cell/model.js +1 -9
- package/dist/components/table-header-cell/table-header-cell.d.ts +1 -1
- package/dist/components/table-header-cell/table-header-cell.js +9 -65
- package/dist/components/table-row/index.d.ts +1 -1
- package/dist/components/table-row/index.js +1 -0
- package/dist/components/table-row/model.d.ts +4 -4
- package/dist/components/table-row/model.js +1 -8
- package/dist/components/table-row/table-row.d.ts +1 -1
- package/dist/components/table-row/table-row.js +20 -127
- package/dist/components/tabs/index.d.ts +1 -1
- package/dist/components/tabs/index.js +1 -0
- package/dist/components/tabs/model.d.ts +3 -3
- package/dist/components/tabs/model.js +2 -4
- package/dist/components/tabs/tabs.d.ts +1 -1
- package/dist/components/tabs/tabs.js +170 -191
- package/dist/components/tag/index.d.ts +1 -1
- package/dist/components/tag/index.js +1 -0
- package/dist/components/tag/model.d.ts +1 -1
- package/dist/components/tag/model.js +1 -4
- package/dist/components/tag/tag.d.ts +1 -1
- package/dist/components/tag/tag.js +26 -91
- package/dist/components/textarea/index.d.ts +1 -1
- package/dist/components/textarea/index.js +1 -0
- package/dist/components/textarea/model.d.ts +1 -1
- package/dist/components/textarea/model.js +2 -13
- package/dist/components/textarea/textarea.d.ts +1 -1
- package/dist/components/textarea/textarea.js +139 -165
- package/dist/components/tooltip/index.d.ts +1 -1
- package/dist/components/tooltip/index.js +1 -0
- package/dist/components/tooltip/model.d.ts +1 -1
- package/dist/components/tooltip/model.js +1 -4
- package/dist/components/tooltip/tooltip.d.ts +1 -1
- package/dist/components/tooltip/tooltip.js +197 -160
- package/dist/index.d.ts +97 -97
- package/dist/index.js +97 -75
- package/dist/shared/constants.js +100 -32
- package/dist/shared/examples/index.js +4 -0
- package/dist/shared/figma.js +1 -0
- package/dist/shared/model.js +22 -77
- package/dist/shared/showcase/show-code-link.js +51 -0
- package/dist/utils/document-click-listener.js +29 -26
- package/dist/utils/document-scroll-listener.js +38 -30
- package/dist/utils/floating-components.js +404 -107
- package/dist/utils/form-components.js +71 -34
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +170 -49
- package/dist/utils/navigation.js +134 -68
- package/dist/utils/react.js +21 -10
- package/package.json +6 -9
|
@@ -1,30 +1,38 @@
|
|
|
1
|
-
import { uuid
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
1
|
+
import { uuid } from './index.js';
|
|
2
|
+
export class DocumentScrollListener {
|
|
3
|
+
static callbacks = {};
|
|
4
|
+
static _instance = null;
|
|
5
|
+
static runCallbacks(event) {
|
|
6
|
+
for (const callback of Object.values(DocumentScrollListener.callbacks)) {
|
|
7
|
+
if (typeof callback === 'function') {
|
|
8
|
+
callback(event);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
ticking = false;
|
|
13
|
+
constructor() {
|
|
14
|
+
if (DocumentScrollListener._instance) {
|
|
15
|
+
return DocumentScrollListener._instance;
|
|
16
|
+
}
|
|
17
|
+
DocumentScrollListener._instance = this;
|
|
18
|
+
if (self.document) {
|
|
19
|
+
self.document.addEventListener('scroll', event => {
|
|
20
|
+
if (!this.ticking) {
|
|
21
|
+
window.requestAnimationFrame(() => {
|
|
22
|
+
DocumentScrollListener.runCallbacks(event);
|
|
23
|
+
this.ticking = false;
|
|
24
|
+
});
|
|
25
|
+
this.ticking = true;
|
|
26
|
+
}
|
|
27
|
+
}, true);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
addCallback(callback) {
|
|
31
|
+
const callbackID = uuid();
|
|
32
|
+
DocumentScrollListener.callbacks[callbackID] = callback;
|
|
33
|
+
return callbackID;
|
|
34
|
+
}
|
|
35
|
+
removeCallback(id) {
|
|
36
|
+
delete DocumentScrollListener.callbacks[id];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -1,108 +1,405 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
1
|
+
// TODO: We should reevaluate this as soon as CSS Anchor Positioning is supported in all relevant browsers
|
|
2
|
+
const isInView = (el) => {
|
|
3
|
+
const { top, bottom, left, right } = el.getBoundingClientRect();
|
|
4
|
+
const { innerHeight, innerWidth } = window;
|
|
5
|
+
let outTop = top < 0;
|
|
6
|
+
let outBottom = bottom > innerHeight;
|
|
7
|
+
let outLeft = left < 0;
|
|
8
|
+
let outRight = right > innerWidth;
|
|
9
|
+
// We need to check if it was already outside
|
|
10
|
+
const outsideY = el.dataset['outsideVy'];
|
|
11
|
+
const outsideX = el.dataset['outsideVx'];
|
|
12
|
+
const parentRect = el?.parentElement?.getBoundingClientRect();
|
|
13
|
+
if (parentRect) {
|
|
14
|
+
if (outsideY) {
|
|
15
|
+
const position = el.dataset['outsideVy'];
|
|
16
|
+
if (position === 'top') {
|
|
17
|
+
outTop = parentRect.top - (bottom - parentRect.bottom) < 0;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
outBottom = parentRect.bottom + (parentRect.top - top) > innerHeight;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (outsideX) {
|
|
24
|
+
const position = el.dataset['outsideVx'];
|
|
25
|
+
if (position === 'left') {
|
|
26
|
+
outLeft = parentRect.left - (right - parentRect.right) < 0;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
outRight = parentRect.right + (parentRect.left - left) > innerWidth;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
outTop,
|
|
35
|
+
outBottom,
|
|
36
|
+
outLeft,
|
|
37
|
+
outRight
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export const handleDataOutside = (el) => {
|
|
41
|
+
const { outTop, outBottom, outLeft, outRight } = isInView(el);
|
|
42
|
+
let dataOutsidePair = {};
|
|
43
|
+
if (outTop || outBottom) {
|
|
44
|
+
dataOutsidePair = {
|
|
45
|
+
vy: outTop ? 'top' : 'bottom'
|
|
46
|
+
};
|
|
47
|
+
el.dataset['outsideVy'] = dataOutsidePair.vy;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
delete el.dataset['outsideVy'];
|
|
51
|
+
}
|
|
52
|
+
if (outLeft || outRight) {
|
|
53
|
+
dataOutsidePair = {
|
|
54
|
+
...dataOutsidePair,
|
|
55
|
+
vx: outRight ? 'right' : 'left'
|
|
56
|
+
};
|
|
57
|
+
el.dataset['outsideVx'] = dataOutsidePair.vx;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
delete el.dataset['outsideVx'];
|
|
61
|
+
}
|
|
62
|
+
return dataOutsidePair;
|
|
63
|
+
};
|
|
64
|
+
export const handleFixedDropdown = (element, parent, placement) => {
|
|
65
|
+
if (!element || !parent)
|
|
66
|
+
return;
|
|
67
|
+
const fullWidth = element.dataset['width'] === 'full';
|
|
68
|
+
const autoWidth = element.dataset['width'] === 'auto';
|
|
69
|
+
// Reset width-specific inline styles first so a previous mode (e.g. "auto")
|
|
70
|
+
// doesn't leave a stale minInlineSize/inlineSize behind when the dropdown
|
|
71
|
+
// width changes at runtime. This must happen before getFloatingProps
|
|
72
|
+
// measures the element, otherwise the dropdown would be measured with a
|
|
73
|
+
// width it no longer has and positioned incorrectly. It also has to run
|
|
74
|
+
// before the mobile bailout below: otherwise a desktop minInlineSize would
|
|
75
|
+
// survive into the mobile sheet, where CSS min-inline-size beats the
|
|
76
|
+
// mobile max-inline-size guard and overflows the viewport.
|
|
77
|
+
element.style.inlineSize = '';
|
|
78
|
+
element.style.minInlineSize = '';
|
|
79
|
+
// We skip the rest if we are in mobile, it's already fixed via CSS.
|
|
80
|
+
if (getComputedStyle(element).zIndex === '9999')
|
|
81
|
+
return;
|
|
82
|
+
const { top, bottom, childHeight, childWidth, width, right, left, correctedPlacement, innerWidth } = getFloatingProps(element, parent, placement);
|
|
83
|
+
// For auto width the dropdown is forced to be at least as wide as the trigger,
|
|
84
|
+
// but clamped to its own max-inline-size: CSS lets a min-inline-size override
|
|
85
|
+
// the max when the minimum is larger, so a trigger wider than the viewport
|
|
86
|
+
// limit would otherwise drop the side margins or overflow horizontally.
|
|
87
|
+
let autoMinWidth = width;
|
|
88
|
+
if (autoWidth) {
|
|
89
|
+
const maxInlineSize = parseFloat(getComputedStyle(element).maxInlineSize);
|
|
90
|
+
if (!isNaN(maxInlineSize) && maxInlineSize > 0) {
|
|
91
|
+
autoMinWidth = Math.min(width, maxInlineSize);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (fullWidth) {
|
|
95
|
+
element.style.inlineSize = `${width}px`;
|
|
96
|
+
}
|
|
97
|
+
else if (autoWidth) {
|
|
98
|
+
element.style.minInlineSize = `${autoMinWidth}px`;
|
|
99
|
+
}
|
|
100
|
+
// getFloatingProps measured childWidth before the inline styles were
|
|
101
|
+
// (re)applied, so use the width the dropdown will actually have:
|
|
102
|
+
// - auto: the clamped minimum, so end-aligned dropdowns don't extend past
|
|
103
|
+
// the trigger's right edge.
|
|
104
|
+
// - full: the trigger width (the reset above drops it to content width).
|
|
105
|
+
let effectiveChildWidth = childWidth;
|
|
106
|
+
if (autoWidth) {
|
|
107
|
+
effectiveChildWidth = Math.max(childWidth, autoMinWidth);
|
|
108
|
+
}
|
|
109
|
+
else if (fullWidth) {
|
|
110
|
+
effectiveChildWidth = width;
|
|
111
|
+
}
|
|
112
|
+
// getFloatingProps detects horizontal overflow assuming a centered element
|
|
113
|
+
// (it halves childWidth). The dropdown is actually start-aligned (inset =
|
|
114
|
+
// left), so for the wider auto dropdown re-check overflow against its full
|
|
115
|
+
// width and flip to end-alignment when it would extend past the viewport.
|
|
116
|
+
let dropdownPlacement = correctedPlacement;
|
|
117
|
+
if (autoWidth && (dropdownPlacement === 'top' || dropdownPlacement === 'bottom' || dropdownPlacement === 'top-start' || dropdownPlacement === 'bottom-start') && left + effectiveChildWidth > innerWidth) {
|
|
118
|
+
dropdownPlacement = dropdownPlacement.startsWith('top') ? 'top-end' : 'bottom-end';
|
|
119
|
+
}
|
|
120
|
+
if (dropdownPlacement === 'top' || dropdownPlacement === 'bottom' || dropdownPlacement === 'top-start' || dropdownPlacement === 'bottom-start') {
|
|
121
|
+
element.style.insetInlineStart = `${left}px`;
|
|
122
|
+
}
|
|
123
|
+
else if (dropdownPlacement === 'top-end' || dropdownPlacement === 'bottom-end') {
|
|
124
|
+
element.style.insetInlineStart = `${Math.max(right - effectiveChildWidth, 0)}px`;
|
|
125
|
+
}
|
|
126
|
+
if (dropdownPlacement?.startsWith('top')) {
|
|
127
|
+
element.style.insetBlockStart = `${top - childHeight}px`;
|
|
128
|
+
}
|
|
129
|
+
else if (dropdownPlacement?.startsWith('bottom')) {
|
|
130
|
+
element.style.insetBlockStart = `${bottom}px`;
|
|
131
|
+
}
|
|
132
|
+
element.style.position = 'fixed';
|
|
133
|
+
};
|
|
134
|
+
export const getFloatingProps = (element, parent, placement) => {
|
|
135
|
+
if (!element || !parent) {
|
|
136
|
+
return {
|
|
137
|
+
top: 0,
|
|
138
|
+
bottom: 0,
|
|
139
|
+
right: 0,
|
|
140
|
+
height: 0,
|
|
141
|
+
width: 0,
|
|
142
|
+
left: 0,
|
|
143
|
+
childHeight: 0,
|
|
144
|
+
childWidth: 0,
|
|
145
|
+
correctedPlacement: placement,
|
|
146
|
+
innerWidth: window.innerWidth,
|
|
147
|
+
innerHeight: window.innerHeight
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
const childRect = element.getBoundingClientRect();
|
|
151
|
+
const { top, height, bottom, right, left, width } = parent.getBoundingClientRect();
|
|
152
|
+
const { innerHeight, innerWidth } = window;
|
|
153
|
+
let childHeight = childRect.height;
|
|
154
|
+
let childWidth = childRect.width;
|
|
155
|
+
if (placement === 'bottom' || placement === 'top') {
|
|
156
|
+
childWidth = childWidth / 2;
|
|
157
|
+
}
|
|
158
|
+
if (placement === 'left' || placement === 'right') {
|
|
159
|
+
childHeight = childHeight / 2;
|
|
160
|
+
}
|
|
161
|
+
const outsideBottom = bottom + childHeight > innerHeight;
|
|
162
|
+
const outsideTop = top - childHeight < 0;
|
|
163
|
+
const outsideLeft = left - childWidth < 0;
|
|
164
|
+
const outsideRight = right + childWidth > innerWidth;
|
|
165
|
+
let correctedPlacement = placement;
|
|
166
|
+
if (placement.startsWith('bottom')) {
|
|
167
|
+
if (outsideBottom) {
|
|
168
|
+
correctedPlacement = placement?.replace('bottom', 'top');
|
|
169
|
+
if (outsideLeft && outsideRight) {
|
|
170
|
+
correctedPlacement = 'top';
|
|
171
|
+
}
|
|
172
|
+
else if (outsideLeft) {
|
|
173
|
+
correctedPlacement = 'top-start';
|
|
174
|
+
}
|
|
175
|
+
else if (outsideRight) {
|
|
176
|
+
correctedPlacement = 'top-end';
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
if (outsideLeft && outsideRight) {
|
|
181
|
+
correctedPlacement = 'bottom';
|
|
182
|
+
}
|
|
183
|
+
else if (outsideLeft) {
|
|
184
|
+
correctedPlacement = 'bottom-start';
|
|
185
|
+
}
|
|
186
|
+
else if (outsideRight) {
|
|
187
|
+
correctedPlacement = 'bottom-end';
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
else if (placement.startsWith('top')) {
|
|
192
|
+
if (outsideTop) {
|
|
193
|
+
correctedPlacement = placement?.replace('top', 'bottom');
|
|
194
|
+
if (outsideLeft && outsideRight) {
|
|
195
|
+
correctedPlacement = 'bottom';
|
|
196
|
+
}
|
|
197
|
+
else if (outsideLeft) {
|
|
198
|
+
correctedPlacement = 'bottom-start';
|
|
199
|
+
}
|
|
200
|
+
else if (outsideRight) {
|
|
201
|
+
correctedPlacement = 'bottom-end';
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
if (outsideLeft && outsideRight) {
|
|
206
|
+
correctedPlacement = 'top';
|
|
207
|
+
}
|
|
208
|
+
else if (outsideLeft) {
|
|
209
|
+
correctedPlacement = 'top-start';
|
|
210
|
+
}
|
|
211
|
+
else if (outsideRight) {
|
|
212
|
+
correctedPlacement = 'top-end';
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
else if (placement.startsWith('left')) {
|
|
217
|
+
if (outsideLeft) {
|
|
218
|
+
correctedPlacement = placement?.replace('left', 'right');
|
|
219
|
+
if (outsideBottom && outsideTop) {
|
|
220
|
+
correctedPlacement = 'right';
|
|
221
|
+
}
|
|
222
|
+
else if (outsideBottom) {
|
|
223
|
+
correctedPlacement = 'right-end';
|
|
224
|
+
}
|
|
225
|
+
else if (outsideTop) {
|
|
226
|
+
correctedPlacement = 'right-start';
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
if (outsideBottom && outsideTop) {
|
|
231
|
+
correctedPlacement = 'left';
|
|
232
|
+
}
|
|
233
|
+
else if (outsideBottom) {
|
|
234
|
+
correctedPlacement = 'left-end';
|
|
235
|
+
}
|
|
236
|
+
else if (outsideTop) {
|
|
237
|
+
correctedPlacement = 'left-start';
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
else if (correctedPlacement.startsWith('right')) {
|
|
242
|
+
if (outsideRight) {
|
|
243
|
+
correctedPlacement = placement?.replace('right', 'left');
|
|
244
|
+
if (outsideBottom && outsideTop) {
|
|
245
|
+
correctedPlacement = 'left';
|
|
246
|
+
}
|
|
247
|
+
else if (outsideBottom) {
|
|
248
|
+
correctedPlacement = 'left-end';
|
|
249
|
+
}
|
|
250
|
+
else if (outsideTop) {
|
|
251
|
+
correctedPlacement = 'left-start';
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
if (outsideBottom && outsideTop) {
|
|
256
|
+
correctedPlacement = 'right';
|
|
257
|
+
}
|
|
258
|
+
else if (outsideBottom) {
|
|
259
|
+
correctedPlacement = 'right-end';
|
|
260
|
+
}
|
|
261
|
+
else if (outsideTop) {
|
|
262
|
+
correctedPlacement = 'right-start';
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
top,
|
|
268
|
+
bottom,
|
|
269
|
+
right,
|
|
270
|
+
height,
|
|
271
|
+
width,
|
|
272
|
+
left,
|
|
273
|
+
childHeight: childRect.height,
|
|
274
|
+
childWidth: childRect.width,
|
|
275
|
+
correctedPlacement,
|
|
276
|
+
innerWidth,
|
|
277
|
+
innerHeight
|
|
278
|
+
};
|
|
279
|
+
};
|
|
280
|
+
const MAX_ANCESTOR_DEPTH = 10;
|
|
281
|
+
const ancestorCache = new WeakMap();
|
|
282
|
+
const getAncestorHasCorrectedPlacement = (element) => {
|
|
283
|
+
if (ancestorCache.has(element)) {
|
|
284
|
+
return ancestorCache.get(element);
|
|
285
|
+
}
|
|
286
|
+
let current = element.parentElement;
|
|
287
|
+
let anchor = 0;
|
|
288
|
+
while (current && anchor < MAX_ANCESTOR_DEPTH) {
|
|
289
|
+
if (current.dataset['correctedPlacement']) {
|
|
290
|
+
ancestorCache.set(element, current);
|
|
291
|
+
return current;
|
|
292
|
+
}
|
|
293
|
+
current = current.parentElement;
|
|
294
|
+
anchor += 1;
|
|
295
|
+
}
|
|
296
|
+
ancestorCache.set(element, null);
|
|
297
|
+
return null;
|
|
298
|
+
};
|
|
299
|
+
export const handleFixedPopover = (element, parent, placement) => {
|
|
300
|
+
if (!element || !parent)
|
|
301
|
+
return;
|
|
302
|
+
const parentComputedStyles = getComputedStyle(parent);
|
|
303
|
+
const parentHasFloatingPosition = ['absolute', 'fixed'].includes(parentComputedStyles.position);
|
|
304
|
+
const ancestorWithCorrectedPlacement = getAncestorHasCorrectedPlacement(element);
|
|
305
|
+
const noFloatingAncestor = !ancestorWithCorrectedPlacement && !parentHasFloatingPosition;
|
|
306
|
+
const distance = getComputedStyle(element)?.getPropertyValue('--db-popover-distance') ?? '0px';
|
|
307
|
+
let { top, height, width, childHeight, childWidth, right, left, bottom, correctedPlacement, innerWidth, innerHeight } = getFloatingProps(element, parent, placement);
|
|
308
|
+
if (ancestorWithCorrectedPlacement) {
|
|
309
|
+
const ancestorRect = ancestorWithCorrectedPlacement.getBoundingClientRect();
|
|
310
|
+
left = Math.abs(left - ancestorRect.left);
|
|
311
|
+
right = (width + Math.abs(right - ancestorRect.right)) * 1.5; // We add a transform -50% later
|
|
312
|
+
top = Math.abs(top - ancestorRect.top);
|
|
313
|
+
bottom = (height + Math.abs(bottom - ancestorRect.bottom)) * 1.5; // We add a transform -50% later
|
|
314
|
+
}
|
|
315
|
+
if (parentHasFloatingPosition) {
|
|
316
|
+
/*
|
|
317
|
+
* If we have a floating element inside an element with position:absolute/fixed
|
|
318
|
+
* we need to calculate with relative values
|
|
319
|
+
* */
|
|
320
|
+
left = 0;
|
|
321
|
+
right = width;
|
|
322
|
+
top = 0;
|
|
323
|
+
bottom = height;
|
|
324
|
+
if (['auto', 'inherit', '0'].includes(parentComputedStyles.zIndex)) {
|
|
325
|
+
// We need the default zIndex for floating elements on the parent
|
|
326
|
+
parent.style.zIndex = '1';
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
// Tooltip arrow position
|
|
330
|
+
if (childWidth > width && (correctedPlacement.startsWith('bottom') || correctedPlacement.startsWith('top'))) {
|
|
331
|
+
const diff = width / 2 / childWidth * 100;
|
|
332
|
+
if (correctedPlacement.endsWith('start')) {
|
|
333
|
+
element.style.setProperty('--db-tooltip-arrow-inline-start', `${diff}%`);
|
|
334
|
+
}
|
|
335
|
+
else if (correctedPlacement.endsWith('end')) {
|
|
336
|
+
element.style.setProperty('--db-tooltip-arrow-inline-start', `${100 - diff}%`);
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
element.style.setProperty('--db-tooltip-arrow-inline-start', `50%`);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
if (childHeight > height && (correctedPlacement.startsWith('left') || correctedPlacement.startsWith('bottom'))) {
|
|
343
|
+
const diff = height / 2 / childHeight * 100;
|
|
344
|
+
if (correctedPlacement.endsWith('start')) {
|
|
345
|
+
element.style.setProperty('--db-tooltip-arrow-block-start', `${diff}%`);
|
|
346
|
+
}
|
|
347
|
+
else if (correctedPlacement.endsWith('end')) {
|
|
348
|
+
element.style.setProperty('--db-tooltip-arrow-block-start', `${100 - diff}%`);
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
element.style.setProperty('--db-tooltip-arrow-block-start', `50%`);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
// Popover position
|
|
355
|
+
if (correctedPlacement === 'right' || correctedPlacement === 'left') {
|
|
356
|
+
// center horizontally
|
|
357
|
+
element.style.insetBlockStart = `${top + height / 2}px`;
|
|
358
|
+
}
|
|
359
|
+
else if (correctedPlacement === 'right-start' || correctedPlacement === 'left-start') {
|
|
360
|
+
const end = top + childHeight;
|
|
361
|
+
element.style.insetBlockStart = `${top}px`;
|
|
362
|
+
element.style.insetBlockEnd = `${!parentHasFloatingPosition && end > innerHeight ? innerHeight : end}px`;
|
|
363
|
+
}
|
|
364
|
+
else if (correctedPlacement === 'right-end' || correctedPlacement === 'left-end') {
|
|
365
|
+
const start = bottom - childHeight;
|
|
366
|
+
element.style.insetBlockStart = `${!parentHasFloatingPosition && start < 0 ? 0 : start}px`;
|
|
367
|
+
element.style.insetBlockEnd = `${bottom}px`;
|
|
368
|
+
}
|
|
369
|
+
else if (correctedPlacement === 'top' || correctedPlacement === 'bottom') {
|
|
370
|
+
// center vertically
|
|
371
|
+
element.style.insetInlineStart = `${left + width / 2}px`;
|
|
372
|
+
}
|
|
373
|
+
else if (correctedPlacement === 'top-start' || correctedPlacement === 'bottom-start') {
|
|
374
|
+
const end = left + childWidth;
|
|
375
|
+
element.style.insetInlineStart = `${left}px`;
|
|
376
|
+
element.style.insetInlineEnd = `${!parentHasFloatingPosition && end > innerWidth ? innerWidth : end}px`;
|
|
377
|
+
}
|
|
378
|
+
else if (correctedPlacement === 'top-end' || correctedPlacement === 'bottom-end') {
|
|
379
|
+
const start = right - childWidth;
|
|
380
|
+
element.style.insetInlineStart = `${!parentHasFloatingPosition && start < 0 ? 0 : start}px`;
|
|
381
|
+
element.style.insetInlineEnd = `${right}px`;
|
|
382
|
+
}
|
|
383
|
+
if (correctedPlacement?.startsWith('right')) {
|
|
384
|
+
const end = right + childWidth;
|
|
385
|
+
element.style.insetInlineStart = `calc(${right}px + ${distance})`;
|
|
386
|
+
element.style.insetInlineEnd = `calc(${noFloatingAncestor && end > innerWidth ? innerWidth : end}px + ${distance})`;
|
|
387
|
+
}
|
|
388
|
+
else if (correctedPlacement?.startsWith('left')) {
|
|
389
|
+
const start = left - childWidth;
|
|
390
|
+
element.style.insetInlineStart = `calc(${noFloatingAncestor && start < 0 ? 0 : start}px - ${distance})`;
|
|
391
|
+
element.style.insetInlineEnd = `calc(${right}px - ${distance})`;
|
|
392
|
+
}
|
|
393
|
+
else if (correctedPlacement?.startsWith('top')) {
|
|
394
|
+
const start = top - childHeight;
|
|
395
|
+
element.style.insetBlockStart = `calc(${noFloatingAncestor && start < 0 ? 0 : start}px - ${distance})`;
|
|
396
|
+
element.style.insetBlockEnd = `calc(${parentHasFloatingPosition ? start : bottom}px - ${distance})`;
|
|
397
|
+
}
|
|
398
|
+
else if (correctedPlacement?.startsWith('bottom')) {
|
|
399
|
+
const end = bottom + childHeight;
|
|
400
|
+
element.style.insetBlockStart = `calc(${parentHasFloatingPosition ? end : bottom}px + ${distance})`;
|
|
401
|
+
element.style.insetBlockEnd = `calc(${noFloatingAncestor && end > innerHeight ? innerHeight : end}px + ${distance})`;
|
|
402
|
+
}
|
|
403
|
+
element.style.position = 'fixed';
|
|
404
|
+
element.dataset['correctedPlacement'] = correctedPlacement;
|
|
106
405
|
};
|
|
107
|
-
//#endregion
|
|
108
|
-
export { r as getFloatingProps, t as handleDataOutside, n as handleFixedDropdown, s as handleFixedPopover };
|