@homecode/ui 5.20.10 → 5.20.11

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.
@@ -5,7 +5,7 @@ import cn from 'classnames';
5
5
  import { Icon } from '../../Icon/Icon.js';
6
6
  import Context from '../context.js';
7
7
  import S from './Link.styl.js';
8
- import { isRootRelativeHref, isNativeDocumentHref } from './linkHref.js';
8
+ import { isExternalHref, isNativeDocumentHref } from './linkHref.js';
9
9
 
10
10
  const isStartFromDoubleSlash = href => /^\/\//.test(href);
11
11
  const isHttpHref = (href) => /^https?:\/\//i.test(href);
@@ -33,13 +33,7 @@ const Link = ({ className, exactClassName, children, href: hrefProp, isClear = f
33
33
  const isExternal = useMemo(() => {
34
34
  if (internalHref)
35
35
  return false;
36
- // A dot in `?filePath=a.pdf` is not a hostname. `http://` + `/api/…`
37
- // is parsed as host `api`.
38
- if (isRootRelativeHref(hrefProp))
39
- return false;
40
- if (isHttpHref(hrefProp))
41
- return true;
42
- return /\./.test(hrefProp);
36
+ return isExternalHref(hrefProp);
43
37
  }, [hrefProp, internalHref]);
44
38
  const nativeDocumentProp = isNativeDocumentHref(internalHref ?? hrefProp);
45
39
  const rootPath = useMemo(() => {
@@ -14,6 +14,18 @@ function isNativeDocumentHref(href) {
14
14
  if (path === '/api' || path.startsWith('/api/'))
15
15
  return true;
16
16
  return path.includes('.');
17
+ }
18
+ /**
19
+ * Opens in a new tab. A bare `example.com` is a host, but a dot only in the
20
+ * query (`//storage?file=a.mp4`) is not.
21
+ */
22
+ function isExternalHref(href) {
23
+ if (isRootRelativeHref(href))
24
+ return false;
25
+ if (/^https?:\/\//i.test(href))
26
+ return true;
27
+ const path = href.split(/[?#]/)[0] ?? '';
28
+ return path.includes('.');
17
29
  }
18
30
 
19
- export { isNativeDocumentHref, isRootRelativeHref };
31
+ export { isExternalHref, isNativeDocumentHref, isRootRelativeHref };
@@ -6,3 +6,8 @@ export declare function isRootRelativeHref(href: string): boolean;
6
6
  * an in-app route.
7
7
  */
8
8
  export declare function isNativeDocumentHref(href: string): boolean;
9
+ /**
10
+ * Opens in a new tab. A bare `example.com` is a host, but a dot only in the
11
+ * query (`//storage?file=a.mp4`) is not.
12
+ */
13
+ export declare function isExternalHref(href: string): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homecode/ui",
3
- "version": "5.20.10",
3
+ "version": "5.20.11",
4
4
  "description": "React UI components library",
5
5
  "scripts": {
6
6
  "tests": "jest",