@etsoo/react 1.5.41 → 1.5.44

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/lib/mu/RLink.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Link } from '@mui/material';
2
2
  import React from 'react';
3
3
  import { globalApp } from '../app/ReactApp';
4
+ import { useDelayedExecutor } from '../uses/useDelayedExecutor';
4
5
  /**
5
6
  * Router Link
6
7
  * @param props Props
@@ -8,19 +9,27 @@ import { globalApp } from '../app/ReactApp';
8
9
  */
9
10
  export const RLink = React.forwardRef((props, ref) => {
10
11
  // Destruct
11
- const { href, onClick, ...rest } = props;
12
+ const { href, target, onClick, ...rest } = props;
13
+ const delayed = useDelayedExecutor((href) => {
14
+ // Router push
15
+ globalApp.history.push(href);
16
+ }, 100);
12
17
  // Click handler
13
18
  const onClickLocl = (event) => {
14
19
  if (onClick)
15
20
  onClick(event);
16
- if (!event.isDefaultPrevented && href && globalApp) {
17
- // Router push
18
- globalApp.history.push(href);
19
- // Cancel further processing
21
+ if (!event.isDefaultPrevented() &&
22
+ href &&
23
+ (!target || target === '_self') && // Let browser handle "target=_blank" etc
24
+ globalApp) {
25
+ // Prevent href action
20
26
  event.preventDefault();
21
- event.stopPropagation();
27
+ delayed.call(undefined, href);
22
28
  }
23
29
  };
30
+ React.useEffect(() => {
31
+ return () => delayed.clear();
32
+ }, [delayed]);
24
33
  // Component
25
- return React.createElement(Link, { ...rest, onClick: onClickLocl, href: href, ref: ref });
34
+ return (React.createElement(Link, { ...rest, onClick: onClickLocl, href: href, target: target, ref: ref }));
26
35
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.5.41",
3
+ "version": "1.5.44",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
package/src/mu/RLink.tsx CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Link, LinkProps } from '@mui/material';
2
2
  import React from 'react';
3
3
  import { globalApp } from '../app/ReactApp';
4
+ import { useDelayedExecutor } from '../uses/useDelayedExecutor';
4
5
 
5
6
  /**
6
7
  * Router Link
@@ -10,7 +11,12 @@ import { globalApp } from '../app/ReactApp';
10
11
  export const RLink = React.forwardRef<HTMLAnchorElement, LinkProps>(
11
12
  (props, ref) => {
12
13
  // Destruct
13
- const { href, onClick, ...rest } = props;
14
+ const { href, target, onClick, ...rest } = props;
15
+
16
+ const delayed = useDelayedExecutor((href: string) => {
17
+ // Router push
18
+ globalApp.history.push(href);
19
+ }, 100);
14
20
 
15
21
  // Click handler
16
22
  const onClickLocl = (
@@ -18,17 +24,31 @@ export const RLink = React.forwardRef<HTMLAnchorElement, LinkProps>(
18
24
  ) => {
19
25
  if (onClick) onClick(event);
20
26
 
21
- if (!event.isDefaultPrevented && href && globalApp) {
22
- // Router push
23
- globalApp.history.push(href);
24
-
25
- // Cancel further processing
27
+ if (
28
+ !event.isDefaultPrevented() &&
29
+ href &&
30
+ (!target || target === '_self') && // Let browser handle "target=_blank" etc
31
+ globalApp
32
+ ) {
33
+ // Prevent href action
26
34
  event.preventDefault();
27
- event.stopPropagation();
35
+ delayed.call(undefined, href);
28
36
  }
29
37
  };
30
38
 
39
+ React.useEffect(() => {
40
+ return () => delayed.clear();
41
+ }, [delayed]);
42
+
31
43
  // Component
32
- return <Link {...rest} onClick={onClickLocl} href={href} ref={ref} />;
44
+ return (
45
+ <Link
46
+ {...rest}
47
+ onClick={onClickLocl}
48
+ href={href}
49
+ target={target}
50
+ ref={ref}
51
+ />
52
+ );
33
53
  }
34
54
  );