Skip to content
This repository was archived by the owner on Jan 9, 2022. It is now read-only.

Commit 16bb4e1

Browse files
committed
feat: convert js files to ts
1 parent e877c1b commit 16bb4e1

File tree

8 files changed

+79
-84
lines changed

8 files changed

+79
-84
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"vue": "^3.0.5"
2424
},
2525
"devDependencies": {
26+
"@types/body-scroll-lock": "^2.6.2",
2627
"@types/node": "^16.3.1",
2728
"@vitejs/plugin-vue": "^1.2.4",
2829
"@vue/compiler-sfc": "^3.0.5",

src/gitart-vue-dialog/composable/stackable.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ export const useStackable: (param: IUseStackableParams) => {activeZIndex: Comput
3535
const index = isActive.value ? getMaxZIndex() + 2 : getZIndex(content.value);
3636

3737
if (index === null) {
38-
// return null;
3938
return 0
4039
}
4140

42-
return parseInt(index);
41+
return index;
4342
});
4443

4544
return {

src/gitart-vue-dialog/composable/useScrollbar.js

Whitespace-only changes.

src/gitart-vue-dialog/helper/index.js

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/gitart-vue-dialog/helper/index.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
*
3+
* @param {string | number | null | undefined} str
4+
* @param {string} unit
5+
* @returns {string | undefined}
6+
*/
7+
export const convertToUnit = (str: string | number | null | undefined, unit = 'px') => {
8+
if (str == null || str === '') {
9+
return undefined;
10+
} else if (isNaN(+str)) {
11+
return String(str);
12+
} else {
13+
return `${Number(str)}${unit}`;
14+
}
15+
};
16+
17+
export const getZIndex = (el?: Element): number => {
18+
if (!el || el.nodeType !== Node.ELEMENT_NODE) return 0;
19+
20+
const index = parseInt(window.getComputedStyle(el).getPropertyValue('z-index'));
21+
22+
if (!index) return getZIndex(el.parentNode as HTMLElement);
23+
24+
return index;
25+
};
26+
27+
export default {
28+
convertToUnit,
29+
getZIndex,
30+
};

src/gitart-vue-dialog/helper/scroll.helper.js

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { enableBodyScroll, disableBodyScroll } from 'body-scroll-lock';
2+
3+
export const getScrollbarWidth = () => {
4+
const container = document.createElement('div');
5+
container.style.visibility = 'hidden';
6+
container.style.overflow = 'scroll';
7+
const inner = document.createElement('div');
8+
9+
container.appendChild(inner);
10+
document.body.appendChild(container);
11+
const scrollbarWidth = container.offsetWidth - inner.offsetWidth;
12+
document.body.removeChild(container);
13+
14+
return scrollbarWidth;
15+
};
16+
17+
/**
18+
*
19+
* @param {boolean} hideScroll
20+
*/
21+
const disableScroll = (hideScroll = false) => {
22+
if (hideScroll) {
23+
const scrollWidth = getScrollbarWidth();
24+
disableBodyScroll(document.body);
25+
if (scrollWidth > 0) {
26+
document.body.style.paddingRight = scrollWidth + 'px';
27+
}
28+
} else {
29+
disableBodyScroll(document.body);
30+
}
31+
};
32+
33+
const enableScroll = () => {
34+
enableBodyScroll(document.body);
35+
document.body.style.paddingRight = '0';
36+
};
37+
38+
export default {
39+
getScrollbarWidth,
40+
disableScroll,
41+
enableScroll,
42+
};

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
"@babel/helper-validator-identifier" "^7.14.5"
2121
to-fast-properties "^2.0.0"
2222

23+
"@types/body-scroll-lock@^2.6.2":
24+
version "2.6.2"
25+
resolved "https://registry.yarnpkg.com/@types/body-scroll-lock/-/body-scroll-lock-2.6.2.tgz#ce56d17e1bf8383c08a074733c4e9e536a59ae61"
26+
integrity sha512-PhoQPbwPYspXqf7lkwtF7aJzAwL88t+9E/e0b2X84tlHpU8ZuS9UNnLtkT0XhyZJYHpET5qRfIdZ0HBIxuc7HQ==
27+
2328
"@types/estree@^0.0.48":
2429
version "0.0.48"
2530
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.48.tgz#18dc8091b285df90db2f25aa7d906cfc394b7f74"

0 commit comments

Comments
 (0)