mobx-route 0.0.87 → 0.0.88
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/package.json
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { AnchorHTMLAttributes, ReactNode } from 'react';
|
|
2
2
|
import { AllPropertiesOptional } from 'yummies/utils/types';
|
|
3
|
-
import { AbstractPathRouteEntity,
|
|
4
|
-
|
|
3
|
+
import { AbstractPathRouteEntity, ExtractPathParams, RouteNavigateParams } from '../../core/index.js';
|
|
4
|
+
interface LinkAnchorProps extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> {
|
|
5
5
|
asChild?: boolean;
|
|
6
|
-
}
|
|
6
|
+
}
|
|
7
|
+
type LinkPathRouteProps<TRoute extends AbstractPathRouteEntity> = {
|
|
7
8
|
to: TRoute;
|
|
8
9
|
} & (AllPropertiesOptional<ExtractPathParams<TRoute['path']>> extends true ? {
|
|
9
10
|
params?: ExtractPathParams<TRoute['path']> | null | undefined;
|
|
10
11
|
} : {
|
|
11
12
|
params: ExtractPathParams<TRoute['path']>;
|
|
12
|
-
})
|
|
13
|
+
});
|
|
14
|
+
type LinkSimpleRouteProps = {
|
|
13
15
|
to: string;
|
|
14
16
|
} | {
|
|
15
17
|
href: string;
|
|
16
|
-
}
|
|
17
|
-
type
|
|
18
|
+
};
|
|
19
|
+
export type LinkProps<TRoute extends AbstractPathRouteEntity> = LinkAnchorProps & RouteNavigateParams & (LinkPathRouteProps<TRoute> | LinkSimpleRouteProps);
|
|
20
|
+
type LinkComponentType = <TRoute extends AbstractPathRouteEntity>(props: LinkProps<TRoute>) => ReactNode;
|
|
18
21
|
export declare const Link: LinkComponentType;
|
|
19
22
|
export {};
|
|
20
23
|
//# sourceMappingURL=link.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../../src/react/components/link.tsx"],"names":[],"mappings":"AAEA,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K,EAAE,SAAS,CAAC,MAAM,CAAC,KACrB,SAAS,CAAC;AAEf,eAAO,MAAM,IAAI,EA6DD,iBAAiB,CAAC"}
|
package/react/components/link.js
CHANGED
|
@@ -2,7 +2,9 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
3
3
|
import { observer } from 'mobx-react-lite';
|
|
4
4
|
import { cloneElement, forwardRef, isValidElement, } from 'react';
|
|
5
|
-
export const Link = observer(forwardRef(({ to, href: outerHref, asChild,
|
|
5
|
+
export const Link = observer(forwardRef(({ to, href: outerHref, asChild, children, params,
|
|
6
|
+
// route navigate params
|
|
7
|
+
query, replace, state, ...outerAnchorProps }, ref) => {
|
|
6
8
|
const href = outerHref ??
|
|
7
9
|
(typeof to === 'string'
|
|
8
10
|
? to
|
|
@@ -14,15 +16,21 @@ export const Link = observer(forwardRef(({ to, href: outerHref, asChild, query,
|
|
|
14
16
|
event.shiftKey ||
|
|
15
17
|
event.button !== 0)
|
|
16
18
|
return;
|
|
17
|
-
|
|
19
|
+
outerAnchorProps.onClick?.(event);
|
|
18
20
|
if (!event.defaultPrevented && typeof to !== 'string') {
|
|
19
21
|
event.preventDefault();
|
|
20
|
-
to.open(href, { replace, query });
|
|
22
|
+
to.open(href, { replace, query, state });
|
|
21
23
|
}
|
|
22
24
|
};
|
|
25
|
+
const anchorProps = {
|
|
26
|
+
...outerAnchorProps,
|
|
27
|
+
href,
|
|
28
|
+
onClick: handleClick,
|
|
29
|
+
rel: outerAnchorProps.target === '_blank' && !outerAnchorProps.rel
|
|
30
|
+
? 'noopener noreferrer'
|
|
31
|
+
: outerAnchorProps.rel,
|
|
32
|
+
};
|
|
23
33
|
return asChild && isValidElement(children) ? (
|
|
24
34
|
// @ts-ignore
|
|
25
|
-
cloneElement(children,
|
|
26
|
-
? 'noopener noreferrer'
|
|
27
|
-
: anchorProps.rel, children: children }));
|
|
35
|
+
cloneElement(children, anchorProps)) : (_jsx("a", { ...anchorProps, ref: ref, children: children }));
|
|
28
36
|
}));
|