@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.
Files changed (289) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/components/accordion/accordion.d.ts +1 -1
  3. package/dist/components/accordion/accordion.js +83 -102
  4. package/dist/components/accordion/index.d.ts +1 -1
  5. package/dist/components/accordion/index.js +1 -0
  6. package/dist/components/accordion/model.d.ts +2 -2
  7. package/dist/components/accordion/model.js +2 -4
  8. package/dist/components/accordion-item/accordion-item.d.ts +2 -2
  9. package/dist/components/accordion-item/accordion-item.js +56 -89
  10. package/dist/components/accordion-item/index.d.ts +1 -1
  11. package/dist/components/accordion-item/index.js +1 -0
  12. package/dist/components/accordion-item/model.d.ts +1 -1
  13. package/dist/components/accordion-item/model.js +1 -0
  14. package/dist/components/badge/badge.d.ts +1 -1
  15. package/dist/components/badge/badge.js +28 -72
  16. package/dist/components/badge/index.d.ts +1 -1
  17. package/dist/components/badge/index.js +1 -0
  18. package/dist/components/badge/model.d.ts +1 -1
  19. package/dist/components/badge/model.js +1 -12
  20. package/dist/components/brand/brand.d.ts +1 -1
  21. package/dist/components/brand/brand.js +10 -60
  22. package/dist/components/brand/index.d.ts +1 -1
  23. package/dist/components/brand/index.js +1 -0
  24. package/dist/components/brand/model.d.ts +1 -1
  25. package/dist/components/brand/model.js +1 -0
  26. package/dist/components/button/button.d.ts +1 -1
  27. package/dist/components/button/button.js +19 -75
  28. package/dist/components/button/index.d.ts +1 -1
  29. package/dist/components/button/index.js +1 -0
  30. package/dist/components/button/model.d.ts +1 -1
  31. package/dist/components/button/model.js +2 -13
  32. package/dist/components/card/card.d.ts +1 -1
  33. package/dist/components/card/card.js +14 -65
  34. package/dist/components/card/index.d.ts +1 -1
  35. package/dist/components/card/index.js +1 -0
  36. package/dist/components/card/model.d.ts +1 -1
  37. package/dist/components/card/model.js +2 -8
  38. package/dist/components/checkbox/checkbox.d.ts +1 -1
  39. package/dist/components/checkbox/checkbox.js +143 -163
  40. package/dist/components/checkbox/index.d.ts +1 -1
  41. package/dist/components/checkbox/index.js +1 -0
  42. package/dist/components/checkbox/model.d.ts +1 -1
  43. package/dist/components/checkbox/model.js +1 -0
  44. package/dist/components/custom-button/custom-button.d.ts +1 -1
  45. package/dist/components/custom-button/custom-button.js +10 -65
  46. package/dist/components/custom-button/index.d.ts +1 -1
  47. package/dist/components/custom-button/index.js +1 -0
  48. package/dist/components/custom-button/model.d.ts +2 -2
  49. package/dist/components/custom-button/model.js +1 -0
  50. package/dist/components/custom-select/custom-select.d.ts +1 -1
  51. package/dist/components/custom-select/custom-select.js +688 -509
  52. package/dist/components/custom-select/index.d.ts +1 -1
  53. package/dist/components/custom-select/index.js +1 -0
  54. package/dist/components/custom-select/model.d.ts +4 -4
  55. package/dist/components/custom-select/model.js +1 -8
  56. package/dist/components/custom-select-dropdown/custom-select-dropdown.d.ts +1 -1
  57. package/dist/components/custom-select-dropdown/custom-select-dropdown.js +10 -62
  58. package/dist/components/custom-select-dropdown/index.d.ts +1 -1
  59. package/dist/components/custom-select-dropdown/index.js +1 -0
  60. package/dist/components/custom-select-dropdown/model.d.ts +1 -1
  61. package/dist/components/custom-select-dropdown/model.js +1 -8
  62. package/dist/components/custom-select-form-field/custom-select-form-field.d.ts +1 -1
  63. package/dist/components/custom-select-form-field/custom-select-form-field.js +9 -57
  64. package/dist/components/custom-select-form-field/index.d.ts +1 -1
  65. package/dist/components/custom-select-form-field/index.js +1 -0
  66. package/dist/components/custom-select-form-field/model.d.ts +1 -1
  67. package/dist/components/custom-select-form-field/model.js +1 -0
  68. package/dist/components/custom-select-list/custom-select-list.d.ts +1 -1
  69. package/dist/components/custom-select-list/custom-select-list.js +9 -60
  70. package/dist/components/custom-select-list/index.d.ts +1 -1
  71. package/dist/components/custom-select-list/index.js +1 -0
  72. package/dist/components/custom-select-list/model.d.ts +1 -1
  73. package/dist/components/custom-select-list/model.js +1 -0
  74. package/dist/components/custom-select-list-item/custom-select-list-item.d.ts +2 -2
  75. package/dist/components/custom-select-list-item/custom-select-list-item.js +28 -89
  76. package/dist/components/custom-select-list-item/index.d.ts +1 -1
  77. package/dist/components/custom-select-list-item/index.js +1 -0
  78. package/dist/components/custom-select-list-item/model.d.ts +1 -1
  79. package/dist/components/custom-select-list-item/model.js +1 -4
  80. package/dist/components/divider/divider.d.ts +1 -1
  81. package/dist/components/divider/divider.js +9 -60
  82. package/dist/components/divider/index.d.ts +1 -1
  83. package/dist/components/divider/index.js +1 -0
  84. package/dist/components/divider/model.d.ts +1 -1
  85. package/dist/components/divider/model.js +2 -4
  86. package/dist/components/drawer/drawer.d.ts +2 -2
  87. package/dist/components/drawer/drawer.js +109 -118
  88. package/dist/components/drawer/index.d.ts +1 -1
  89. package/dist/components/drawer/index.js +1 -0
  90. package/dist/components/drawer/model.d.ts +4 -1
  91. package/dist/components/drawer/model.js +4 -14
  92. package/dist/components/header/header.d.ts +1 -1
  93. package/dist/components/header/header.js +43 -143
  94. package/dist/components/header/index.d.ts +1 -1
  95. package/dist/components/header/index.js +1 -0
  96. package/dist/components/header/model.d.ts +1 -1
  97. package/dist/components/header/model.js +1 -0
  98. package/dist/components/icon/icon.d.ts +1 -1
  99. package/dist/components/icon/icon.js +9 -61
  100. package/dist/components/icon/index.d.ts +1 -1
  101. package/dist/components/icon/index.js +1 -0
  102. package/dist/components/icon/model.d.ts +1 -1
  103. package/dist/components/icon/model.js +1 -11
  104. package/dist/components/infotext/index.d.ts +1 -1
  105. package/dist/components/infotext/index.js +1 -0
  106. package/dist/components/infotext/infotext.d.ts +1 -1
  107. package/dist/components/infotext/infotext.js +9 -62
  108. package/dist/components/infotext/model.d.ts +1 -1
  109. package/dist/components/infotext/model.js +1 -0
  110. package/dist/components/input/index.d.ts +1 -1
  111. package/dist/components/input/index.js +1 -0
  112. package/dist/components/input/input.d.ts +1 -1
  113. package/dist/components/input/input.js +154 -198
  114. package/dist/components/input/model.d.ts +1 -1
  115. package/dist/components/input/model.js +5 -21
  116. package/dist/components/link/index.d.ts +1 -1
  117. package/dist/components/link/index.js +1 -0
  118. package/dist/components/link/link.d.ts +1 -1
  119. package/dist/components/link/link.js +9 -70
  120. package/dist/components/link/model.d.ts +1 -1
  121. package/dist/components/link/model.js +3 -8
  122. package/dist/components/navigation/index.d.ts +1 -1
  123. package/dist/components/navigation/index.js +1 -0
  124. package/dist/components/navigation/model.d.ts +1 -1
  125. package/dist/components/navigation/model.js +1 -0
  126. package/dist/components/navigation/navigation.d.ts +1 -1
  127. package/dist/components/navigation/navigation.js +9 -57
  128. package/dist/components/navigation-item/index.d.ts +1 -1
  129. package/dist/components/navigation-item/index.js +1 -0
  130. package/dist/components/navigation-item/model.d.ts +2 -2
  131. package/dist/components/navigation-item/model.js +1 -0
  132. package/dist/components/navigation-item/navigation-item.d.ts +1 -1
  133. package/dist/components/navigation-item/navigation-item.js +71 -117
  134. package/dist/components/notification/index.d.ts +1 -1
  135. package/dist/components/notification/index.js +1 -0
  136. package/dist/components/notification/model.d.ts +1 -1
  137. package/dist/components/notification/model.js +3 -12
  138. package/dist/components/notification/notification.d.ts +2 -2
  139. package/dist/components/notification/notification.js +23 -100
  140. package/dist/components/page/index.d.ts +1 -1
  141. package/dist/components/page/index.js +1 -0
  142. package/dist/components/page/model.d.ts +1 -1
  143. package/dist/components/page/model.js +2 -4
  144. package/dist/components/page/page.d.ts +1 -1
  145. package/dist/components/page/page.js +42 -74
  146. package/dist/components/popover/index.d.ts +1 -1
  147. package/dist/components/popover/index.js +1 -0
  148. package/dist/components/popover/model.d.ts +1 -1
  149. package/dist/components/popover/model.js +1 -0
  150. package/dist/components/popover/popover.d.ts +1 -1
  151. package/dist/components/popover/popover.js +119 -126
  152. package/dist/components/radio/index.d.ts +1 -1
  153. package/dist/components/radio/index.js +1 -0
  154. package/dist/components/radio/model.d.ts +1 -1
  155. package/dist/components/radio/model.js +1 -0
  156. package/dist/components/radio/radio.d.ts +1 -1
  157. package/dist/components/radio/radio.js +86 -124
  158. package/dist/components/section/index.d.ts +1 -1
  159. package/dist/components/section/index.js +1 -0
  160. package/dist/components/section/model.d.ts +1 -1
  161. package/dist/components/section/model.js +1 -0
  162. package/dist/components/section/section.d.ts +1 -1
  163. package/dist/components/section/section.js +9 -59
  164. package/dist/components/select/index.d.ts +1 -1
  165. package/dist/components/select/index.js +1 -0
  166. package/dist/components/select/model.d.ts +1 -1
  167. package/dist/components/select/model.js +1 -0
  168. package/dist/components/select/select.d.ts +1 -1
  169. package/dist/components/select/select.js +172 -188
  170. package/dist/components/stack/index.d.ts +1 -1
  171. package/dist/components/stack/index.js +1 -0
  172. package/dist/components/stack/model.d.ts +1 -1
  173. package/dist/components/stack/model.js +4 -14
  174. package/dist/components/stack/stack.d.ts +1 -1
  175. package/dist/components/stack/stack.js +9 -63
  176. package/dist/components/switch/index.d.ts +1 -1
  177. package/dist/components/switch/index.js +1 -0
  178. package/dist/components/switch/model.d.ts +1 -1
  179. package/dist/components/switch/model.js +1 -0
  180. package/dist/components/switch/switch.d.ts +1 -1
  181. package/dist/components/switch/switch.js +135 -182
  182. package/dist/components/tab-item/index.d.ts +1 -1
  183. package/dist/components/tab-item/index.js +1 -0
  184. package/dist/components/tab-item/model.d.ts +1 -1
  185. package/dist/components/tab-item/model.js +1 -0
  186. package/dist/components/tab-item/tab-item.d.ts +1 -1
  187. package/dist/components/tab-item/tab-item.js +72 -105
  188. package/dist/components/tab-list/index.d.ts +1 -1
  189. package/dist/components/tab-list/index.js +1 -0
  190. package/dist/components/tab-list/model.d.ts +1 -1
  191. package/dist/components/tab-list/model.js +1 -0
  192. package/dist/components/tab-list/tab-list.d.ts +1 -1
  193. package/dist/components/tab-list/tab-list.js +9 -60
  194. package/dist/components/tab-panel/index.d.ts +1 -1
  195. package/dist/components/tab-panel/index.js +1 -0
  196. package/dist/components/tab-panel/model.d.ts +1 -1
  197. package/dist/components/tab-panel/model.js +1 -0
  198. package/dist/components/tab-panel/tab-panel.d.ts +1 -1
  199. package/dist/components/tab-panel/tab-panel.js +10 -59
  200. package/dist/components/table/examples/data.d.ts +1 -1
  201. package/dist/components/table/examples/data.js +258 -0
  202. package/dist/components/table/index.d.ts +1 -1
  203. package/dist/components/table/index.js +1 -0
  204. package/dist/components/table/model.d.ts +2 -2
  205. package/dist/components/table/model.js +6 -28
  206. package/dist/components/table/table.d.ts +1 -1
  207. package/dist/components/table/table.js +77 -111
  208. package/dist/components/table-body/index.d.ts +1 -1
  209. package/dist/components/table-body/index.js +1 -0
  210. package/dist/components/table-body/model.d.ts +2 -2
  211. package/dist/components/table-body/model.js +1 -0
  212. package/dist/components/table-body/table-body.d.ts +1 -1
  213. package/dist/components/table-body/table-body.js +12 -64
  214. package/dist/components/table-caption/index.d.ts +1 -1
  215. package/dist/components/table-caption/index.js +1 -0
  216. package/dist/components/table-caption/model.d.ts +1 -1
  217. package/dist/components/table-caption/model.js +1 -0
  218. package/dist/components/table-caption/table-caption.d.ts +1 -1
  219. package/dist/components/table-caption/table-caption.js +9 -57
  220. package/dist/components/table-data-cell/index.d.ts +1 -1
  221. package/dist/components/table-data-cell/index.js +1 -0
  222. package/dist/components/table-data-cell/model.d.ts +1 -1
  223. package/dist/components/table-data-cell/model.js +1 -0
  224. package/dist/components/table-data-cell/table-data-cell.d.ts +1 -1
  225. package/dist/components/table-data-cell/table-data-cell.js +9 -62
  226. package/dist/components/table-footer/index.d.ts +1 -1
  227. package/dist/components/table-footer/index.js +1 -0
  228. package/dist/components/table-footer/model.d.ts +2 -2
  229. package/dist/components/table-footer/model.js +1 -0
  230. package/dist/components/table-footer/table-footer.d.ts +1 -1
  231. package/dist/components/table-footer/table-footer.js +12 -64
  232. package/dist/components/table-head/index.d.ts +1 -1
  233. package/dist/components/table-head/index.js +1 -0
  234. package/dist/components/table-head/model.d.ts +2 -2
  235. package/dist/components/table-head/model.js +1 -0
  236. package/dist/components/table-head/table-head.d.ts +1 -1
  237. package/dist/components/table-head/table-head.js +18 -71
  238. package/dist/components/table-header-cell/index.d.ts +1 -1
  239. package/dist/components/table-header-cell/index.js +1 -0
  240. package/dist/components/table-header-cell/model.d.ts +1 -1
  241. package/dist/components/table-header-cell/model.js +1 -9
  242. package/dist/components/table-header-cell/table-header-cell.d.ts +1 -1
  243. package/dist/components/table-header-cell/table-header-cell.js +9 -65
  244. package/dist/components/table-row/index.d.ts +1 -1
  245. package/dist/components/table-row/index.js +1 -0
  246. package/dist/components/table-row/model.d.ts +4 -4
  247. package/dist/components/table-row/model.js +1 -8
  248. package/dist/components/table-row/table-row.d.ts +1 -1
  249. package/dist/components/table-row/table-row.js +20 -127
  250. package/dist/components/tabs/index.d.ts +1 -1
  251. package/dist/components/tabs/index.js +1 -0
  252. package/dist/components/tabs/model.d.ts +3 -3
  253. package/dist/components/tabs/model.js +2 -4
  254. package/dist/components/tabs/tabs.d.ts +1 -1
  255. package/dist/components/tabs/tabs.js +170 -191
  256. package/dist/components/tag/index.d.ts +1 -1
  257. package/dist/components/tag/index.js +1 -0
  258. package/dist/components/tag/model.d.ts +1 -1
  259. package/dist/components/tag/model.js +1 -4
  260. package/dist/components/tag/tag.d.ts +1 -1
  261. package/dist/components/tag/tag.js +26 -91
  262. package/dist/components/textarea/index.d.ts +1 -1
  263. package/dist/components/textarea/index.js +1 -0
  264. package/dist/components/textarea/model.d.ts +1 -1
  265. package/dist/components/textarea/model.js +2 -13
  266. package/dist/components/textarea/textarea.d.ts +1 -1
  267. package/dist/components/textarea/textarea.js +139 -165
  268. package/dist/components/tooltip/index.d.ts +1 -1
  269. package/dist/components/tooltip/index.js +1 -0
  270. package/dist/components/tooltip/model.d.ts +1 -1
  271. package/dist/components/tooltip/model.js +1 -4
  272. package/dist/components/tooltip/tooltip.d.ts +1 -1
  273. package/dist/components/tooltip/tooltip.js +197 -160
  274. package/dist/index.d.ts +97 -97
  275. package/dist/index.js +97 -75
  276. package/dist/shared/constants.js +100 -32
  277. package/dist/shared/examples/index.js +4 -0
  278. package/dist/shared/figma.js +1 -0
  279. package/dist/shared/model.js +22 -77
  280. package/dist/shared/showcase/show-code-link.js +51 -0
  281. package/dist/utils/document-click-listener.js +29 -26
  282. package/dist/utils/document-scroll-listener.js +38 -30
  283. package/dist/utils/floating-components.js +404 -107
  284. package/dist/utils/form-components.js +71 -34
  285. package/dist/utils/index.d.ts +1 -1
  286. package/dist/utils/index.js +170 -49
  287. package/dist/utils/navigation.js +134 -68
  288. package/dist/utils/react.js +21 -10
  289. package/package.json +6 -9
@@ -1,30 +1,38 @@
1
- import { uuid as e } from "./index.js";
2
- //#region src/utils/document-scroll-listener.ts
3
- var t = class t {
4
- static {
5
- this.callbacks = {};
6
- }
7
- static {
8
- this._instance = null;
9
- }
10
- static runCallbacks(e) {
11
- for (let n of Object.values(t.callbacks)) typeof n == "function" && n(e);
12
- }
13
- constructor() {
14
- if (this.ticking = !1, t._instance) return t._instance;
15
- t._instance = this, self.document && self.document.addEventListener("scroll", (e) => {
16
- this.ticking ||= (window.requestAnimationFrame(() => {
17
- t.runCallbacks(e), this.ticking = !1;
18
- }), !0);
19
- }, !0);
20
- }
21
- addCallback(n) {
22
- let r = e();
23
- return t.callbacks[r] = n, r;
24
- }
25
- removeCallback(e) {
26
- delete t.callbacks[e];
27
- }
28
- };
29
- //#endregion
30
- export { t as DocumentScrollListener };
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
- //#region src/utils/floating-components.ts
2
- var e = (e) => {
3
- let { top: t, bottom: n, left: r, right: i } = e.getBoundingClientRect(), { innerHeight: a, innerWidth: o } = window, s = t < 0, c = n > a, l = r < 0, u = i > o, d = e.dataset.outsideVy, f = e.dataset.outsideVx, p = e?.parentElement?.getBoundingClientRect();
4
- return p && (d && (e.dataset.outsideVy === "top" ? s = p.top - (n - p.bottom) < 0 : c = p.bottom + (p.top - t) > a), f && (e.dataset.outsideVx === "left" ? l = p.left - (i - p.right) < 0 : u = p.right + (p.left - r) > o)), {
5
- outTop: s,
6
- outBottom: c,
7
- outLeft: l,
8
- outRight: u
9
- };
10
- }, t = (t) => {
11
- let { outTop: n, outBottom: r, outLeft: i, outRight: a } = e(t), o = {};
12
- return n || r ? (o = { vy: n ? "top" : "bottom" }, t.dataset.outsideVy = o.vy) : delete t.dataset.outsideVy, i || a ? (o = {
13
- ...o,
14
- vx: a ? "right" : "left"
15
- }, t.dataset.outsideVx = o.vx) : delete t.dataset.outsideVx, o;
16
- }, n = (e, t, n) => {
17
- if (!e || !t || getComputedStyle(e).zIndex === "9999") return;
18
- let { top: i, bottom: a, childHeight: o, childWidth: s, width: c, right: l, left: u, correctedPlacement: d } = r(e, t, n);
19
- e.dataset.width === "full" && (e.style.inlineSize = `${c}px`), d === "top" || d === "bottom" || d === "top-start" || d === "bottom-start" ? e.style.insetInlineStart = `${u}px` : (d === "top-end" || d === "bottom-end") && (e.style.insetInlineStart = `${l - s}px`), d?.startsWith("top") ? e.style.insetBlockStart = `${i - o}px` : d?.startsWith("bottom") && (e.style.insetBlockStart = `${a}px`), e.style.position = "fixed";
20
- }, r = (e, t, n) => {
21
- if (!e || !t) return {
22
- top: 0,
23
- bottom: 0,
24
- right: 0,
25
- height: 0,
26
- width: 0,
27
- left: 0,
28
- childHeight: 0,
29
- childWidth: 0,
30
- correctedPlacement: n,
31
- innerWidth: window.innerWidth,
32
- innerHeight: window.innerHeight
33
- };
34
- let r = e.getBoundingClientRect(), { top: i, height: a, bottom: o, right: s, left: c, width: l } = t.getBoundingClientRect(), { innerHeight: u, innerWidth: d } = window, f = r.height, p = r.width;
35
- (n === "bottom" || n === "top") && (p /= 2), (n === "left" || n === "right") && (f /= 2);
36
- let m = o + f > u, h = i - f < 0, g = c - p < 0, _ = s + p > d, v = n;
37
- return n.startsWith("bottom") ? m ? (v = n?.replace("bottom", "top"), g && _ ? v = "top" : g ? v = "top-start" : _ && (v = "top-end")) : g && _ ? v = "bottom" : g ? v = "bottom-start" : _ && (v = "bottom-end") : n.startsWith("top") ? h ? (v = n?.replace("top", "bottom"), g && _ ? v = "bottom" : g ? v = "bottom-start" : _ && (v = "bottom-end")) : g && _ ? v = "top" : g ? v = "top-start" : _ && (v = "top-end") : n.startsWith("left") ? g ? (v = n?.replace("left", "right"), m && h ? v = "right" : m ? v = "right-end" : h && (v = "right-start")) : m && h ? v = "left" : m ? v = "left-end" : h && (v = "left-start") : v.startsWith("right") && (_ ? (v = n?.replace("right", "left"), m && h ? v = "left" : m ? v = "left-end" : h && (v = "left-start")) : m && h ? v = "right" : m ? v = "right-end" : h && (v = "right-start")), {
38
- top: i,
39
- bottom: o,
40
- right: s,
41
- height: a,
42
- width: l,
43
- left: c,
44
- childHeight: r.height,
45
- childWidth: r.width,
46
- correctedPlacement: v,
47
- innerWidth: d,
48
- innerHeight: u
49
- };
50
- }, i = 10, a = /* @__PURE__ */ new WeakMap(), o = (e) => {
51
- if (a.has(e)) return a.get(e);
52
- let t = e.parentElement, n = 0;
53
- for (; t && n < i;) {
54
- if (t.dataset.correctedPlacement) return a.set(e, t), t;
55
- t = t.parentElement, n += 1;
56
- }
57
- return a.set(e, null), null;
58
- }, s = (e, t, n) => {
59
- if (!e || !t) return;
60
- let i = getComputedStyle(t), a = ["absolute", "fixed"].includes(i.position), s = o(e), c = !s && !a, l = getComputedStyle(e)?.getPropertyValue("--db-popover-distance") ?? "0px", { top: u, height: d, width: f, childHeight: p, childWidth: m, right: h, left: g, bottom: _, correctedPlacement: v, innerWidth: y, innerHeight: b } = r(e, t, n);
61
- if (s) {
62
- let e = s.getBoundingClientRect();
63
- g = Math.abs(g - e.left), h = (f + Math.abs(h - e.right)) * 1.5, u = Math.abs(u - e.top), _ = (d + Math.abs(_ - e.bottom)) * 1.5;
64
- }
65
- if (a && (g = 0, h = f, u = 0, _ = d, [
66
- "auto",
67
- "inherit",
68
- "0"
69
- ].includes(i.zIndex) && (t.style.zIndex = "1")), m > f && (v.startsWith("bottom") || v.startsWith("top"))) {
70
- let t = f / 2 / m * 100;
71
- v.endsWith("start") ? e.style.setProperty("--db-tooltip-arrow-inline-start", `${t}%`) : v.endsWith("end") ? e.style.setProperty("--db-tooltip-arrow-inline-start", `${100 - t}%`) : e.style.setProperty("--db-tooltip-arrow-inline-start", "50%");
72
- }
73
- if (p > d && (v.startsWith("left") || v.startsWith("bottom"))) {
74
- let t = d / 2 / p * 100;
75
- v.endsWith("start") ? e.style.setProperty("--db-tooltip-arrow-block-start", `${t}%`) : v.endsWith("end") ? e.style.setProperty("--db-tooltip-arrow-block-start", `${100 - t}%`) : e.style.setProperty("--db-tooltip-arrow-block-start", "50%");
76
- }
77
- if (v === "right" || v === "left") e.style.insetBlockStart = `${u + d / 2}px`;
78
- else if (v === "right-start" || v === "left-start") {
79
- let t = u + p;
80
- e.style.insetBlockStart = `${u}px`, e.style.insetBlockEnd = `${!a && t > b ? b : t}px`;
81
- } else if (v === "right-end" || v === "left-end") {
82
- let t = _ - p;
83
- e.style.insetBlockStart = `${!a && t < 0 ? 0 : t}px`, e.style.insetBlockEnd = `${_}px`;
84
- } else if (v === "top" || v === "bottom") e.style.insetInlineStart = `${g + f / 2}px`;
85
- else if (v === "top-start" || v === "bottom-start") {
86
- let t = g + m;
87
- e.style.insetInlineStart = `${g}px`, e.style.insetInlineEnd = `${!a && t > y ? y : t}px`;
88
- } else if (v === "top-end" || v === "bottom-end") {
89
- let t = h - m;
90
- e.style.insetInlineStart = `${!a && t < 0 ? 0 : t}px`, e.style.insetInlineEnd = `${h}px`;
91
- }
92
- if (v?.startsWith("right")) {
93
- let t = h + m;
94
- e.style.insetInlineStart = `calc(${h}px + ${l})`, e.style.insetInlineEnd = `calc(${c && t > y ? y : t}px + ${l})`;
95
- } else if (v?.startsWith("left")) {
96
- let t = g - m;
97
- e.style.insetInlineStart = `calc(${c && t < 0 ? 0 : t}px - ${l})`, e.style.insetInlineEnd = `calc(${h}px - ${l})`;
98
- } else if (v?.startsWith("top")) {
99
- let t = u - p;
100
- e.style.insetBlockStart = `calc(${c && t < 0 ? 0 : t}px - ${l})`, e.style.insetBlockEnd = `calc(${a ? t : _}px - ${l})`;
101
- } else if (v?.startsWith("bottom")) {
102
- let t = _ + p;
103
- e.style.insetBlockStart = `calc(${a ? t : _}px + ${l})`, e.style.insetBlockEnd = `calc(${c && t > b ? b : t}px + ${l})`;
104
- }
105
- e.style.position = "fixed", e.dataset.correctedPlacement = v;
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 };