@invopop/popui 0.0.15 → 0.0.17

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.
@@ -2,6 +2,7 @@
2
2
  import BaseTableActions from "./BaseTableActions.svelte";
3
3
  import BaseTableCell from "./BaseTableCell.svelte";
4
4
  import InputCheckbox from "./InputCheckbox.svelte";
5
+ import { scrollIntoTableView } from "./helpers.js";
5
6
  const dispatch = createEventDispatcher();
6
7
  let actionsDropdown;
7
8
  let checkboxButton;
@@ -27,24 +28,7 @@ $:
27
28
  scrollIntoView();
28
29
  }
29
30
  function scrollIntoView() {
30
- const offset = 40;
31
- const elementRect = checkboxButton.getBoundingClientRect();
32
- const elementTop = elementRect.top + offset;
33
- const elementBottom = elementRect.bottom + offset;
34
- const viewportHeight = window.innerHeight;
35
- const isAboveView = elementRect.top - offset < 0;
36
- const isBelowView = elementRect.bottom + offset > viewportHeight;
37
- if (isAboveView) {
38
- window.scrollTo({
39
- top: elementTop - offset,
40
- behavior: "smooth"
41
- });
42
- } else if (isBelowView) {
43
- window.scrollTo({
44
- top: elementBottom - viewportHeight + offset,
45
- behavior: "smooth"
46
- });
47
- }
31
+ scrollIntoTableView(checkboxButton);
48
32
  }
49
33
  </script>
50
34
 
package/dist/helpers.d.ts CHANGED
@@ -4,3 +4,5 @@ export declare function toPascalCase(text: string): string;
4
4
  export declare function resolveIcon(icon?: IconSource | string | undefined): Promise<IconSource | undefined>;
5
5
  export declare function getCountryName(code: string): string | undefined;
6
6
  export declare function getStatusType(status: string): FeedItemStatus;
7
+ export declare function getScrollableContainer(element: HTMLElement): HTMLElement | undefined;
8
+ export declare function scrollIntoTableView(element: HTMLElement): void;
package/dist/helpers.js CHANGED
@@ -33,3 +33,42 @@ export function getStatusType(status) {
33
33
  };
34
34
  return statuses[status];
35
35
  }
36
+ export function getScrollableContainer(element) {
37
+ if (!element) {
38
+ return undefined;
39
+ }
40
+ let parent = element.parentElement;
41
+ while (parent) {
42
+ const { overflow } = window.getComputedStyle(parent);
43
+ if (overflow.split(' ').every((o) => o === 'auto' || o === 'scroll')) {
44
+ return parent;
45
+ }
46
+ parent = parent.parentElement;
47
+ }
48
+ return document.documentElement;
49
+ }
50
+ export function scrollIntoTableView(element) {
51
+ const offset = 80;
52
+ const offsetTop = offset + 40;
53
+ const container = getScrollableContainer(element);
54
+ if (!container)
55
+ return;
56
+ const containerRect = container.getBoundingClientRect();
57
+ const elementRect = element.getBoundingClientRect();
58
+ const elementTop = elementRect.top - containerRect.top + container.scrollTop;
59
+ const elementBottom = elementRect.bottom - containerRect.top + container.scrollTop;
60
+ const isAboveView = elementTop - offsetTop < container.scrollTop;
61
+ const isBelowView = elementBottom + offset > container.scrollTop + container.clientHeight;
62
+ if (isAboveView) {
63
+ container.scrollTo({
64
+ top: elementTop - offsetTop,
65
+ behavior: 'smooth'
66
+ });
67
+ }
68
+ else if (isBelowView) {
69
+ container.scrollTo({
70
+ top: elementBottom - container.clientHeight + offset,
71
+ behavior: 'smooth'
72
+ });
73
+ }
74
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@invopop/popui",
3
3
  "license": "MIT",
4
- "version": "0.0.15",
4
+ "version": "0.0.17",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
7
7
  "build": "vite build && npm run package",