Skip to content

Commit d88884e

Browse files
Merge pull request #342 from VKCOM/pavelnikitin/fix/add-platform-check/MA-16191
Pavelnikitin/fix/add-platform-check/MA-16191
2 parents b814050 + e2cd26c commit d88884e

32 files changed

+1309
-846
lines changed

.eslintrc.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const path = require('path');
22

33
module.exports = {
44
root: true,
5-
extends: ['@vkontakte/eslint-config/typescript', 'prettier'],
5+
extends: ['plugin:@vkontakte/eslint-plugin/typescript', "plugin:import/recommended", 'prettier'],
66
overrides: [
77
{
88
files: '**/*.{ts,tsx}',
@@ -11,9 +11,18 @@ module.exports = {
1111
},
1212
},
1313
],
14+
settings: {
15+
"import/resolver": {
16+
"node": {
17+
"extensions": [".js", ".jsx", ".ts", ".tsx"]
18+
}
19+
}
20+
},
1421
rules: {
22+
'import/named': 'off',
1523
'no-shadow': 'off',
1624
'guard-for-in': 'off',
25+
'import/no-unresolved': ['error', { ignore: ['^[a-z@]'] }],
1726
'@typescript-eslint/ban-types': 'off',
1827
'@typescript-eslint/array-type': 'off',
1928
'@typescript-eslint/prefer-readonly': 'off',

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env sh
22
. "$(dirname -- "$0")/_/husky.sh"
33

4-
yarn lint-staged
4+
yarn lint-staged

.lintstagedrc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"*.ts": "eslint",
3-
"*.tsx": "eslint"
2+
"*.ts": ["eslint", "prettier --check"],
3+
"*.tsx": ["eslint", "prettier --check"]
44
}

.prettierignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Исключаем по умолчанию все файлы
2+
/**/*.*
3+
4+
# Включаем проверку только в src на расширения(ts, tsx, html)
5+
!src/**/*.ts
6+
!src/**/*.tsx
7+
!src/**/*.html
8+
9+
# Исключаем файлы в директориях node_modules, dist, build
10+
**/node_modules/*.*
11+
**/dist/*.*
12+
**/build/*.*
13+
**/page-types/*.*

examples/vk-mini-apps-router-example/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
"@testing-library/user-event": "^14.4.3",
99
"@types/jest": "^29.5.3",
1010
"@types/node": "^20.9.0",
11-
"@types/react": "^18.2.20",
11+
"@types/react": "^18.2.48",
1212
"@types/react-dom": "^18.2.7",
1313
"@vkontakte/icons": "^2.77.0",
1414
"@vkontakte/vk-bridge": "latest",
15-
"@vkontakte/vk-mini-apps-router": "latest",
15+
"@vkontakte/vk-mini-apps-router": "1.4.2",
1616
"@vkontakte/vkui": "^6.0.0",
1717
"react": "^18.2.0",
1818
"react-dom": "^18.2.0",

examples/vk-mini-apps-router-example/yarn.lock

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,7 +2253,7 @@
22532253
dependencies:
22542254
"@types/react" "*"
22552255

2256-
"@types/react@*", "@types/react@^18.2.20":
2256+
"@types/react@*":
22572257
version "18.2.20"
22582258
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.2.20.tgz#1605557a83df5c8a2cc4eeb743b3dfc0eb6aaeb2"
22592259
integrity sha512-WKNtmsLWJM/3D5mG4U84cysVY31ivmyw85dE84fOCk5Hx78wezB/XEjVPWl2JTZ5FkEeaTJf+VgUAUn3PE7Isw==
@@ -2262,6 +2262,15 @@
22622262
"@types/scheduler" "*"
22632263
csstype "^3.0.2"
22642264

2265+
"@types/react@^18.2.48":
2266+
version "18.2.48"
2267+
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.2.48.tgz#11df5664642d0bd879c1f58bc1d37205b064e8f1"
2268+
integrity sha512-qboRCl6Ie70DQQG9hhNREz81jqC1cs9EVNcjQ1AU+jH6NFfSAhVVbrrY/+nSF+Bsk4AOwm9Qa61InvMCyV+H3w==
2269+
dependencies:
2270+
"@types/prop-types" "*"
2271+
"@types/scheduler" "*"
2272+
csstype "^3.0.2"
2273+
22652274
22662275
version "1.17.1"
22672276
resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.17.1.tgz#3afd6ad8967c77e4376c598a82ddd58f46ec45d6"
@@ -2467,10 +2476,10 @@
24672476
resolved "https://registry.yarnpkg.com/@vkontakte/vk-bridge/-/vk-bridge-2.9.0.tgz#24aed0217f0c508f4c62ed44fe52ce3fe7f47e53"
24682477
integrity sha512-fyOdtZq+68Jnp8FNmas3fnJ4b1bjc1fmAovl2afV14VeJ1KG1OwoAaE7zpVL4U4VVZJGhhdANxEsc4tBYUSkxA==
24692478

2470-
"@vkontakte/vk-mini-apps-router@latest":
2471-
version "1.3.2"
2472-
resolved "https://registry.yarnpkg.com/@vkontakte/vk-mini-apps-router/-/vk-mini-apps-router-1.3.2.tgz#ce3d1dfe0dfb95c02b8449988ee049573d57a521"
2473-
integrity sha512-X9gDgt9z1ffE2u1tUtCr2cSgB44ld3qave78gDXTBitTpkTZncP/ZyU+6IWWbSxhHwp8qSsUMES+JI2kj83E8A==
2479+
"@vkontakte/vk-mini-apps-router@1.4.2":
2480+
version "1.4.2"
2481+
resolved "https://registry.yarnpkg.com/@vkontakte/vk-mini-apps-router/-/vk-mini-apps-router-1.4.2.tgz#804c8a3906249bc6e9c0d2d597a0409a12fdd88b"
2482+
integrity sha512-yQnCoWDy5rnX+RHhi7iSELu+lJi7O+1KToNwWA+pGblZmPWOQnOnwRNc6R0DO+uvDaMqh6k9NQa2AJvHZNcq3Q==
24742483
dependencies:
24752484
"@remix-run/router" "^1.13.0"
24762485

package.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
},
2121
"scripts": {
2222
"build": "tsc",
23-
"lint:js": "eslint src/ --ext ts,tsx --fix",
23+
"eslint:check": "eslint src/ --ext ts,tsx",
24+
"eslint:fix": "eslint src/ --ext ts,tsx",
25+
"prettier:check": "prettier --check .",
26+
"prettier:fix": "prettier --write .",
2427
"prepare": "husky install",
2528
"prepublishOnly": "yarn build"
2629
},
@@ -33,15 +36,18 @@
3336
},
3437
"devDependencies": {
3538
"@types/react": "^18.0.28",
36-
"@typescript-eslint/eslint-plugin": "^4.33.0",
37-
"@vkontakte/eslint-config": "^3.1.0",
39+
"@typescript-eslint/eslint-plugin": "^5.50.0",
40+
"@typescript-eslint/parser": "^5.0.0",
41+
"@vkontakte/eslint-plugin": "^1.2.0",
3842
"@vkontakte/prettier-config": "^0.1.0",
39-
"eslint": "^7.32.0",
43+
"eslint": "^8.33.0",
4044
"eslint-config-prettier": "^9.0.0",
45+
"eslint-plugin-import": "^2.29.1",
4146
"eslint-plugin-react": "^7.32.2",
42-
"eslint-plugin-react-hooks": "^2.5.1",
47+
"eslint-plugin-react-hooks": "^4.6.0",
4348
"husky": "^8.0.3",
44-
"lint-staged": "^14.0.0",
49+
"lint-staged": "^15.2.0",
50+
"prettier": "^2.7.1",
4551
"typescript": "^5.1.6"
4652
},
4753
"files": [

src/components/DefaultNotFound.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ export type DefaultNotFoundProps = {
1717

1818
export function DefaultNotFound({ routeNavigator }: DefaultNotFoundProps): ReactElement {
1919
return (
20-
<div onClick={() => routeNavigator.replace('/')} className="default-not-found" style={DivStyles}>
21-
</div>
20+
<div
21+
onClick={() => void routeNavigator.replace('/')}
22+
className="default-not-found"
23+
style={DivStyles}
24+
></div>
2225
);
23-
}
26+
}

src/components/RouterLink.tsx

Lines changed: 48 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @ts-expect-error
21
import { Link } from '@vkontakte/vkui';
32
import { useHref } from '../hooks/useHref';
43
import { RelativeRoutingType, To } from '@remix-run/router';
@@ -11,33 +10,19 @@ import {
1110
} from 'react';
1211
import { useLinkClickHandler } from '../hooks/useLinkClickHandler';
1312

14-
export interface LinkProps
15-
extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> {
13+
export interface LinkProps extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> {
1614
reloadDocument?: boolean;
1715
replace?: boolean;
1816
relative?: RelativeRoutingType;
1917
to: To;
2018
}
2119

22-
export interface RouterLinkProps
23-
extends Omit<LinkProps, 'className' | 'style' | 'children'> {
24-
children?:
25-
| ReactNode
26-
| ((props: { isActive: boolean; isPending: boolean }) => ReactNode);
20+
export interface RouterLinkProps extends Omit<LinkProps, 'className' | 'style' | 'children'> {
21+
children?: ReactNode;
2722
caseSensitive?: boolean;
28-
className?:
29-
| string
30-
| ((props: {
31-
isActive: boolean;
32-
isPending: boolean;
33-
}) => string | undefined);
23+
className?: string;
3424
end?: boolean;
35-
style?:
36-
| CSSProperties
37-
| ((props: {
38-
isActive: boolean;
39-
isPending: boolean;
40-
}) => CSSProperties | undefined);
25+
style?: CSSProperties;
4126
}
4227

4328
const ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
@@ -47,69 +32,55 @@ const isBrowser =
4732
typeof window.document !== 'undefined' &&
4833
typeof window.document.createElement !== 'undefined';
4934

50-
export const RouterLink = forwardRef<HTMLAnchorElement, RouterLinkProps>(
51-
function(
52-
{
53-
to,
54-
relative,
55-
replace,
56-
target,
57-
reloadDocument,
58-
onClick,
59-
...rest
60-
}: RouterLinkProps,
61-
ref,
62-
) {
63-
// Rendered into <a href> for absolute URLs
64-
let absoluteHref;
65-
let isExternal = false;
35+
export const RouterLink = forwardRef<HTMLAnchorElement, RouterLinkProps>(function (
36+
{ to, relative, replace, target, reloadDocument, onClick, ...rest }: RouterLinkProps,
37+
ref,
38+
) {
39+
// Rendered into <a href> for absolute URLs
40+
let absoluteHref;
41+
let isExternal = false;
6642

67-
if (typeof to === 'string' && ABSOLUTE_URL_REGEX.test(to)) {
68-
// Render the absolute href server- and client-side
69-
absoluteHref = to;
43+
if (typeof to === 'string' && ABSOLUTE_URL_REGEX.test(to)) {
44+
// Render the absolute href server- and client-side
45+
absoluteHref = to;
7046

71-
// Only check for external origins client-side
72-
if (isBrowser) {
73-
const currentUrl = new URL(window.location.href);
74-
const targetUrl = to.startsWith('//')
75-
? new URL(currentUrl.protocol + to)
76-
: new URL(to);
77-
const path = targetUrl.pathname;
47+
// Only check for external origins client-side
48+
if (isBrowser) {
49+
const currentUrl = new URL(window.location.href);
50+
const targetUrl = to.startsWith('//') ? new URL(currentUrl.protocol + to) : new URL(to);
51+
const path = targetUrl.pathname;
7852

79-
if (targetUrl.origin === currentUrl.origin) {
80-
// Strip the protocol/origin/basename for same-origin absolute URLs
81-
to = path + targetUrl.search + targetUrl.hash;
82-
} else {
83-
isExternal = true;
84-
}
53+
if (targetUrl.origin === currentUrl.origin) {
54+
// Strip the protocol/origin/basename for same-origin absolute URLs
55+
to = path + targetUrl.search + targetUrl.hash;
56+
} else {
57+
isExternal = true;
8558
}
8659
}
87-
88-
const href = useHref(to, { relative });
60+
}
8961

90-
const internalOnClick = useLinkClickHandler(to, {
91-
replace,
92-
target,
93-
relative,
94-
});
62+
const href = useHref(to, { relative });
9563

96-
function handleClick(
97-
event: ReactMouseEvent<HTMLAnchorElement, MouseEvent>
98-
) {
99-
if (onClick) onClick(event);
100-
if (!event.defaultPrevented) {
101-
internalOnClick(event);
102-
}
103-
}
64+
const internalOnClick = useLinkClickHandler(to, {
65+
replace,
66+
target,
67+
relative,
68+
});
10469

105-
return (
106-
<Link
107-
{...rest}
108-
href={absoluteHref || href}
109-
onClick={isExternal || reloadDocument ? onClick : handleClick}
110-
ref={ref}
111-
target={target}
112-
></Link>
113-
);
70+
function handleClick(event: ReactMouseEvent<HTMLAnchorElement>) {
71+
if (onClick) onClick(event);
72+
if (!event.defaultPrevented) {
73+
internalOnClick(event);
74+
}
11475
}
115-
);
76+
77+
return (
78+
<Link
79+
{...rest}
80+
href={absoluteHref || href}
81+
onClick={isExternal || reloadDocument ? onClick : handleClick}
82+
getRootRef={ref}
83+
target={target}
84+
></Link>
85+
);
86+
});

src/contexts.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@ export interface ThrottledContextObject {
3232
interval: number;
3333
}
3434

35-
export const ThrottledContext = createContext<ThrottledContextObject>({ enabled: false, firstActionDelay: 0, interval: 0 });
35+
export const ThrottledContext = createContext<ThrottledContextObject>({
36+
enabled: false,
37+
firstActionDelay: 0,
38+
interval: 0,
39+
});

0 commit comments

Comments
 (0)