@tinkoff/router 0.2.4 → 0.2.6

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/README.md CHANGED
@@ -273,29 +273,6 @@ export const Cmp = () => {
273
273
  };
274
274
  ```
275
275
 
276
- #### Link
277
-
278
- A wrapper for a react component that makes it clickable
279
-
280
- > If the react component is passed to the Link as children, then this passed component will be rendered and the `href`, `onClick` props will be passed as props to that component and they should be used to make the navigation. Otherwise, the `<a>` tag will be rendered with children as a child.
281
-
282
- ```ts
283
- import { Link } from '@tinkoff/router';
284
- import CustomLink from '@custom-scope/link';
285
-
286
- export const Component = () => {
287
- return (
288
- <Link url="/test/">
289
- <CustomLink />
290
- </Link>
291
- );
292
- };
293
-
294
- export const WrapLink = () => {
295
- return <Link url="/test/">Click me</Link>;
296
- };
297
- ```
298
-
299
276
  ## How to
300
277
 
301
278
  ### Load route config from external api
@@ -3,4 +3,3 @@ export { useRouter } from './useRouter';
3
3
  export { useRoute } from './useRoute';
4
4
  export { useUrl } from './useUrl';
5
5
  export { useNavigate } from './useNavigate';
6
- export { Link } from './link';
@@ -1,6 +1,6 @@
1
1
  import type { Navigation, HistoryOptions, NavigationType } from '../types';
2
2
  import type { RouteTree } from '../tree/tree';
3
- export declare type Listener = (arg: {
3
+ export type Listener = (arg: {
4
4
  url: string;
5
5
  type?: NavigationType;
6
6
  navigateState?: any;
@@ -9,7 +9,7 @@ import find from '@tinkoff/utils/array/find';
9
9
  import findIndex from '@tinkoff/utils/array/findIndex';
10
10
  import { jsx } from 'react/jsx-runtime';
11
11
  import { useSyncExternalStore } from 'use-sync-external-store/shim';
12
- import { createContext, useContext, useCallback, isValidElement, cloneElement } from 'react';
12
+ import { createContext, useContext, useCallback } from 'react';
13
13
  import { useShallowEqual } from '@tinkoff/react-hooks';
14
14
 
15
15
  const PARAMETER_DELIMITER = ':';
@@ -1166,32 +1166,4 @@ const useNavigate = (rootOptions) => {
1166
1166
  }, [rootOpts, router]);
1167
1167
  };
1168
1168
 
1169
- function Link(props) {
1170
- const { children, onClick, url, query, replace, target, navigateOptions, ...otherProps } = props;
1171
- const navigate = useNavigate({ url, query, replace, ...navigateOptions });
1172
- const handleClick = useCallback((event) => {
1173
- // ignores the navigation when clicked using right mouse button or
1174
- // by holding a special modifier key: ctrl, command, win, alt, shift
1175
- if (target ||
1176
- event.ctrlKey ||
1177
- event.metaKey ||
1178
- event.altKey ||
1179
- event.shiftKey ||
1180
- event.button !== 0) {
1181
- return;
1182
- }
1183
- event.preventDefault();
1184
- navigate();
1185
- onClick && onClick(event);
1186
- }, [navigate, target, onClick]);
1187
- const extraProps = { href: url, onClick: handleClick, target };
1188
- if (isValidElement(children)) {
1189
- return cloneElement(children, extraProps);
1190
- }
1191
- return (
1192
- // eslint-disable-next-line react/jsx-props-no-spreading
1193
- jsx("a", { ...otherProps, ...extraProps, children: children }));
1194
- }
1195
- Link.displayName = 'Link';
1196
-
1197
- export { AbstractRouter, History, Link, NoSpaRouter, Provider, RouteTree, Router, getParts, isHistoryFallback, isParameterized, isWildcard, logger, makePath, parse, setLogger, useNavigate, useRoute, useRouter, useUrl };
1169
+ export { AbstractRouter, History, NoSpaRouter, Provider, RouteTree, Router, getParts, isHistoryFallback, isParameterized, isWildcard, logger, makePath, parse, setLogger, useNavigate, useRoute, useRouter, useUrl };
package/lib/index.es.js CHANGED
@@ -9,7 +9,7 @@ import find from '@tinkoff/utils/array/find';
9
9
  import findIndex from '@tinkoff/utils/array/findIndex';
10
10
  import { jsx } from 'react/jsx-runtime';
11
11
  import { useSyncExternalStore } from 'use-sync-external-store/shim';
12
- import { createContext, useContext, useCallback, isValidElement, cloneElement } from 'react';
12
+ import { createContext, useContext, useCallback } from 'react';
13
13
  import { useShallowEqual } from '@tinkoff/react-hooks';
14
14
 
15
15
  const PARAMETER_DELIMITER = ':';
@@ -1094,32 +1094,4 @@ const useNavigate = (rootOptions) => {
1094
1094
  }, [rootOpts, router]);
1095
1095
  };
1096
1096
 
1097
- function Link(props) {
1098
- const { children, onClick, url, query, replace, target, navigateOptions, ...otherProps } = props;
1099
- const navigate = useNavigate({ url, query, replace, ...navigateOptions });
1100
- const handleClick = useCallback((event) => {
1101
- // ignores the navigation when clicked using right mouse button or
1102
- // by holding a special modifier key: ctrl, command, win, alt, shift
1103
- if (target ||
1104
- event.ctrlKey ||
1105
- event.metaKey ||
1106
- event.altKey ||
1107
- event.shiftKey ||
1108
- event.button !== 0) {
1109
- return;
1110
- }
1111
- event.preventDefault();
1112
- navigate();
1113
- onClick && onClick(event);
1114
- }, [navigate, target, onClick]);
1115
- const extraProps = { href: url, onClick: handleClick, target };
1116
- if (isValidElement(children)) {
1117
- return cloneElement(children, extraProps);
1118
- }
1119
- return (
1120
- // eslint-disable-next-line react/jsx-props-no-spreading
1121
- jsx("a", { ...otherProps, ...extraProps, children: children }));
1122
- }
1123
- Link.displayName = 'Link';
1124
-
1125
- export { AbstractRouter, History, Link, NoSpaRouter, Provider, RouteTree, Router, getParts, isHistoryFallback, isParameterized, isWildcard, logger, makePath, parse, setLogger, useNavigate, useRoute, useRouter, useUrl };
1097
+ export { AbstractRouter, History, NoSpaRouter, Provider, RouteTree, Router, getParts, isHistoryFallback, isParameterized, isWildcard, logger, makePath, parse, setLogger, useNavigate, useRoute, useRouter, useUrl };
package/lib/index.js CHANGED
@@ -1109,37 +1109,8 @@ const useNavigate = (rootOptions) => {
1109
1109
  }, [rootOpts, router]);
1110
1110
  };
1111
1111
 
1112
- function Link(props) {
1113
- const { children, onClick, url, query, replace, target, navigateOptions, ...otherProps } = props;
1114
- const navigate = useNavigate({ url, query, replace, ...navigateOptions });
1115
- const handleClick = react.useCallback((event) => {
1116
- // ignores the navigation when clicked using right mouse button or
1117
- // by holding a special modifier key: ctrl, command, win, alt, shift
1118
- if (target ||
1119
- event.ctrlKey ||
1120
- event.metaKey ||
1121
- event.altKey ||
1122
- event.shiftKey ||
1123
- event.button !== 0) {
1124
- return;
1125
- }
1126
- event.preventDefault();
1127
- navigate();
1128
- onClick && onClick(event);
1129
- }, [navigate, target, onClick]);
1130
- const extraProps = { href: url, onClick: handleClick, target };
1131
- if (react.isValidElement(children)) {
1132
- return react.cloneElement(children, extraProps);
1133
- }
1134
- return (
1135
- // eslint-disable-next-line react/jsx-props-no-spreading
1136
- jsxRuntime.jsx("a", { ...otherProps, ...extraProps, children: children }));
1137
- }
1138
- Link.displayName = 'Link';
1139
-
1140
1112
  exports.AbstractRouter = AbstractRouter;
1141
1113
  exports.History = History;
1142
- exports.Link = Link;
1143
1114
  exports.NoSpaRouter = NoSpaRouter;
1144
1115
  exports.Provider = Provider;
1145
1116
  exports.RouteTree = RouteTree;
package/lib/logger.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare type LogFn = (data: {
1
+ export type LogFn = (data: {
2
2
  event: string;
3
3
  [key: string]: any;
4
4
  }) => void;
@@ -10,7 +10,7 @@ export interface Parameter {
10
10
  regexp?: RegExp;
11
11
  optional?: boolean;
12
12
  }
13
- export declare type ParsedPath = {
13
+ export type ParsedPath = {
14
14
  type: PartType.literal;
15
15
  value: string;
16
16
  } | {
package/lib/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Url, Query } from '@tinkoff/url';
2
- export declare type Params = Record<string, string>;
2
+ export type Params = Record<string, string>;
3
3
  export interface Route {
4
4
  name: string;
5
5
  path: string;
@@ -24,11 +24,11 @@ export interface BaseNavigateOptions {
24
24
  export interface NavigateOptions extends BaseNavigateOptions {
25
25
  url?: string;
26
26
  }
27
- export declare type UpdateCurrentRouteOptions = BaseNavigateOptions;
27
+ export type UpdateCurrentRouteOptions = BaseNavigateOptions;
28
28
  export interface HistoryOptions {
29
29
  historyFallback: string;
30
30
  }
31
- export declare type NavigationType = 'navigate' | 'updateCurrentRoute';
31
+ export type NavigationType = 'navigate' | 'updateCurrentRoute';
32
32
  export interface Navigation {
33
33
  type: NavigationType;
34
34
  from?: NavigationRoute;
@@ -43,8 +43,8 @@ export interface Navigation {
43
43
  redirect?: boolean;
44
44
  redirectFrom?: NavigationRoute;
45
45
  }
46
- export declare type NavigationGuard = (navigation: Navigation) => Promise<void | NavigateOptions | string | boolean>;
47
- export declare type NavigationHook = (navigation: Navigation) => Promise<void>;
48
- export declare type NavigationSyncHook = (navigation: Navigation) => void;
49
- export declare type HookName = 'beforeResolve' | 'beforeNavigate' | 'afterNavigate' | 'beforeUpdateCurrent' | 'afterUpdateCurrent';
50
- export declare type SyncHookName = 'change';
46
+ export type NavigationGuard = (navigation: Navigation) => Promise<void | NavigateOptions | string | boolean>;
47
+ export type NavigationHook = (navigation: Navigation) => Promise<void>;
48
+ export type NavigationSyncHook = (navigation: Navigation) => void;
49
+ export type HookName = 'beforeResolve' | 'beforeNavigate' | 'afterNavigate' | 'beforeUpdateCurrent' | 'afterUpdateCurrent';
50
+ export type SyncHookName = 'change';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinkoff/router",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "router",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -1,14 +0,0 @@
1
- interface Props {
2
- children?: any;
3
- url: string;
4
- query?: Record<string, string>;
5
- replace?: boolean;
6
- target?: string;
7
- onClick?: Function;
8
- navigateOptions?: Record<string, any>;
9
- }
10
- declare function Link(props: Props): JSX.Element;
11
- declare namespace Link {
12
- var displayName: string;
13
- }
14
- export { Link };