@react-foundry/anchor 0.1.9 → 0.2.1
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/dist/Anchor.js +21 -25
- package/package.json +13 -15
- package/dist/Anchor.mjs +0 -63
package/dist/Anchor.js
CHANGED
|
@@ -1,28 +1,25 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
'use client';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const uri_1 = require("@react-foundry/uri");
|
|
11
|
-
require("../assets/Anchor.scss");
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Suspense } from 'react';
|
|
4
|
+
import { useIsMounted } from '@react-foundry/client-component-helpers';
|
|
5
|
+
import { classBuilder } from '@react-foundry/component-helpers';
|
|
6
|
+
import { Link, needSuspense, useLocation, useIsActive } from '@react-foundry/router';
|
|
7
|
+
import { URI } from '@react-foundry/uri';
|
|
8
|
+
import '../assets/Anchor.scss';
|
|
12
9
|
const supportedProtocols = [
|
|
13
10
|
'http:',
|
|
14
11
|
'https:'
|
|
15
12
|
];
|
|
16
13
|
const AnchorInner = ({ children, classBlock, classModifiers: _classModifiers = [], className, forceExternal = false, href, ...attrs }) => {
|
|
17
|
-
const isMounted =
|
|
18
|
-
const active =
|
|
19
|
-
const current =
|
|
14
|
+
const isMounted = useIsMounted();
|
|
15
|
+
const active = useIsActive()(href || '');
|
|
16
|
+
const current = useLocation();
|
|
20
17
|
const classModifiers = [
|
|
21
18
|
active ? 'active' : '',
|
|
22
19
|
...(Array.isArray(_classModifiers) ? _classModifiers : [_classModifiers])
|
|
23
20
|
];
|
|
24
|
-
const classes =
|
|
25
|
-
const url =
|
|
21
|
+
const classes = classBuilder('penultimate-anchor', classBlock, classModifiers, className);
|
|
22
|
+
const url = URI.parse(href || '');
|
|
26
23
|
const unsupported = url.protocol !== '' && !supportedProtocols.includes(url.protocol || '');
|
|
27
24
|
const noPath = url.pathname === '';
|
|
28
25
|
const noSearch = url.search === '';
|
|
@@ -45,11 +42,11 @@ const AnchorInner = ({ children, classBlock, classModifiers: _classModifiers = [
|
|
|
45
42
|
!isMounted && hashLink ||
|
|
46
43
|
hashLink && noHash);
|
|
47
44
|
return (basicAnchor
|
|
48
|
-
? ((
|
|
49
|
-
: ((
|
|
45
|
+
? (_jsx("a", { ...attrs, className: classes(), href: href, children: children }))
|
|
46
|
+
: (_jsx(Link, { ...attrs, "aria-current": active ? 'page' : undefined, className: classes(), to: location, children: children })));
|
|
50
47
|
};
|
|
51
|
-
const Anchor = ({ children, classBlock, classModifiers, className, forceExternal, href, ...attrs }) => {
|
|
52
|
-
const classes =
|
|
48
|
+
export const Anchor = ({ children, classBlock, classModifiers, className, forceExternal, href, ...attrs }) => {
|
|
49
|
+
const classes = classBuilder('penultimate-anchor', classBlock, classModifiers, className);
|
|
53
50
|
const props = {
|
|
54
51
|
...attrs,
|
|
55
52
|
classBlock,
|
|
@@ -58,10 +55,9 @@ const Anchor = ({ children, classBlock, classModifiers, className, forceExternal
|
|
|
58
55
|
forceExternal,
|
|
59
56
|
href
|
|
60
57
|
};
|
|
61
|
-
const content = ((
|
|
62
|
-
return (!
|
|
58
|
+
const content = (_jsx(AnchorInner, { ...props, children: children }));
|
|
59
|
+
return (!needSuspense ? content : (_jsx(Suspense, { fallback: _jsx("a", { ...attrs, className: classes(), href: href, children: children }), children: content })));
|
|
63
60
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
exports.A = exports.Anchor;
|
|
61
|
+
Anchor.displayName = 'A';
|
|
62
|
+
export default Anchor;
|
|
63
|
+
export const A = Anchor;
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-foundry/anchor",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "A drop-in replacement for the 'a' element.",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "dist/Anchor.js",
|
|
6
7
|
"sass": "assets/Anchor.scss",
|
|
7
8
|
"exports": {
|
|
8
9
|
".": {
|
|
9
10
|
"sass": "./assets/Anchor.scss",
|
|
10
11
|
"types": "./dist/Anchor.d.ts",
|
|
11
|
-
"import": "./dist/Anchor.
|
|
12
|
-
"
|
|
13
|
-
"default": "./dist/Anchor.mjs"
|
|
12
|
+
"import": "./dist/Anchor.js",
|
|
13
|
+
"default": "./dist/Anchor.js"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
@@ -23,15 +23,15 @@
|
|
|
23
23
|
"react-components"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@react-foundry/client-component-helpers": "^0.1
|
|
27
|
-
"@react-foundry/
|
|
28
|
-
"@react-foundry/
|
|
29
|
-
"@react-foundry/
|
|
26
|
+
"@react-foundry/client-component-helpers": "^0.2.1",
|
|
27
|
+
"@react-foundry/router": "^0.2.1",
|
|
28
|
+
"@react-foundry/uri": "^0.2.1",
|
|
29
|
+
"@react-foundry/component-helpers": "^0.2.1"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@react-foundry/docs-components": "^0.1
|
|
32
|
+
"@react-foundry/docs-components": "^0.2.1",
|
|
33
33
|
"@storybook/addon-docs": "^9.1.20",
|
|
34
|
-
"react": "^19.2.
|
|
34
|
+
"react": "^19.2.5"
|
|
35
35
|
},
|
|
36
36
|
"peerDependenciesMeta": {
|
|
37
37
|
"@react-foundry/docs-components": {
|
|
@@ -47,15 +47,13 @@
|
|
|
47
47
|
"jest-environment-jsdom": "30.3.0",
|
|
48
48
|
"ts-jest": "29.4.9",
|
|
49
49
|
"typescript": "5.9.3",
|
|
50
|
-
"@react-foundry/component-test-helpers": "0.1
|
|
50
|
+
"@react-foundry/component-test-helpers": "0.2.1"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
54
|
-
"build": "
|
|
55
|
-
"build:esm": "tsc -m es2022 && find dist -name '*.js' -exec sh -c 'mv \"$0\" \"${0%.js}.mjs\"' {} \\;",
|
|
56
|
-
"build:cjs": "tsc",
|
|
54
|
+
"build": "tsc",
|
|
57
55
|
"clean": "rm -rf dist tsconfig.tsbuildinfo"
|
|
58
56
|
},
|
|
59
|
-
"module": "dist/Anchor.
|
|
57
|
+
"module": "dist/Anchor.js",
|
|
60
58
|
"typings": "dist/Anchor.d.ts"
|
|
61
59
|
}
|
package/dist/Anchor.mjs
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { Suspense } from 'react';
|
|
4
|
-
import { useIsMounted } from '@react-foundry/client-component-helpers';
|
|
5
|
-
import { classBuilder } from '@react-foundry/component-helpers';
|
|
6
|
-
import { Link, needSuspense, useLocation, useIsActive } from '@react-foundry/router';
|
|
7
|
-
import { URI } from '@react-foundry/uri';
|
|
8
|
-
import '../assets/Anchor.scss';
|
|
9
|
-
const supportedProtocols = [
|
|
10
|
-
'http:',
|
|
11
|
-
'https:'
|
|
12
|
-
];
|
|
13
|
-
const AnchorInner = ({ children, classBlock, classModifiers: _classModifiers = [], className, forceExternal = false, href, ...attrs }) => {
|
|
14
|
-
const isMounted = useIsMounted();
|
|
15
|
-
const active = useIsActive()(href || '');
|
|
16
|
-
const current = useLocation();
|
|
17
|
-
const classModifiers = [
|
|
18
|
-
active ? 'active' : '',
|
|
19
|
-
...(Array.isArray(_classModifiers) ? _classModifiers : [_classModifiers])
|
|
20
|
-
];
|
|
21
|
-
const classes = classBuilder('penultimate-anchor', classBlock, classModifiers, className);
|
|
22
|
-
const url = URI.parse(href || '');
|
|
23
|
-
const unsupported = url.protocol !== '' && !supportedProtocols.includes(url.protocol || '');
|
|
24
|
-
const noPath = url.pathname === '';
|
|
25
|
-
const noSearch = url.search === '';
|
|
26
|
-
const noHash = url.hash === '';
|
|
27
|
-
const hashLink = noPath && noSearch;
|
|
28
|
-
const location = {
|
|
29
|
-
pathname: (noPath
|
|
30
|
-
? current.pathname
|
|
31
|
-
: url?.pathname),
|
|
32
|
-
search: (hashLink
|
|
33
|
-
? current.search
|
|
34
|
-
: url?.search),
|
|
35
|
-
hash: (noHash
|
|
36
|
-
? '#'
|
|
37
|
-
: url?.hash)
|
|
38
|
-
};
|
|
39
|
-
const basicAnchor = (forceExternal ||
|
|
40
|
-
unsupported ||
|
|
41
|
-
url.hostname ||
|
|
42
|
-
!isMounted && hashLink ||
|
|
43
|
-
hashLink && noHash);
|
|
44
|
-
return (basicAnchor
|
|
45
|
-
? (_jsx("a", { ...attrs, className: classes(), href: href, children: children }))
|
|
46
|
-
: (_jsx(Link, { ...attrs, "aria-current": active ? 'page' : undefined, className: classes(), to: location, children: children })));
|
|
47
|
-
};
|
|
48
|
-
export const Anchor = ({ children, classBlock, classModifiers, className, forceExternal, href, ...attrs }) => {
|
|
49
|
-
const classes = classBuilder('penultimate-anchor', classBlock, classModifiers, className);
|
|
50
|
-
const props = {
|
|
51
|
-
...attrs,
|
|
52
|
-
classBlock,
|
|
53
|
-
classModifiers,
|
|
54
|
-
className,
|
|
55
|
-
forceExternal,
|
|
56
|
-
href
|
|
57
|
-
};
|
|
58
|
-
const content = (_jsx(AnchorInner, { ...props, children: children }));
|
|
59
|
-
return (!needSuspense ? content : (_jsx(Suspense, { fallback: _jsx("a", { ...attrs, className: classes(), href: href, children: children }), children: content })));
|
|
60
|
-
};
|
|
61
|
-
Anchor.displayName = 'A';
|
|
62
|
-
export default Anchor;
|
|
63
|
-
export const A = Anchor;
|