@react-foundry/anchor 0.1.9 → 0.2.0

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 CHANGED
@@ -1,28 +1,25 @@
1
- "use strict";
2
1
  'use client';
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.A = exports.Anchor = void 0;
5
- const jsx_runtime_1 = require("react/jsx-runtime");
6
- const react_1 = require("react");
7
- const client_component_helpers_1 = require("@react-foundry/client-component-helpers");
8
- const component_helpers_1 = require("@react-foundry/component-helpers");
9
- const router_1 = require("@react-foundry/router");
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 = (0, client_component_helpers_1.useIsMounted)();
18
- const active = (0, router_1.useIsActive)()(href || '');
19
- const current = (0, router_1.useLocation)();
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 = (0, component_helpers_1.classBuilder)('penultimate-anchor', classBlock, classModifiers, className);
25
- const url = uri_1.URI.parse(href || '');
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
- ? ((0, jsx_runtime_1.jsx)("a", { ...attrs, className: classes(), href: href, children: children }))
49
- : ((0, jsx_runtime_1.jsx)(router_1.Link, { ...attrs, "aria-current": active ? 'page' : undefined, className: classes(), to: location, children: children })));
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 = (0, component_helpers_1.classBuilder)('penultimate-anchor', classBlock, classModifiers, className);
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 = ((0, jsx_runtime_1.jsx)(AnchorInner, { ...props, children: children }));
62
- return (!router_1.needSuspense ? content : ((0, jsx_runtime_1.jsx)(react_1.Suspense, { fallback: (0, jsx_runtime_1.jsx)("a", { ...attrs, className: classes(), href: href, children: children }), children: content })));
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
- exports.Anchor = Anchor;
65
- exports.Anchor.displayName = 'A';
66
- exports.default = exports.Anchor;
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.9",
3
+ "version": "0.2.0",
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.mjs",
12
- "require": "./dist/Anchor.js",
13
- "default": "./dist/Anchor.mjs"
12
+ "import": "./dist/Anchor.js",
13
+ "default": "./dist/Anchor.js"
14
14
  }
15
15
  },
16
16
  "files": [
@@ -23,13 +23,13 @@
23
23
  "react-components"
24
24
  ],
25
25
  "dependencies": {
26
- "@react-foundry/client-component-helpers": "^0.1.9",
27
- "@react-foundry/component-helpers": "^0.1.9",
28
- "@react-foundry/router": "^0.1.9",
29
- "@react-foundry/uri": "^0.1.9"
26
+ "@react-foundry/client-component-helpers": "^0.2.0",
27
+ "@react-foundry/router": "^0.2.0",
28
+ "@react-foundry/component-helpers": "^0.2.0",
29
+ "@react-foundry/uri": "^0.2.0"
30
30
  },
31
31
  "peerDependencies": {
32
- "@react-foundry/docs-components": "^0.1.9",
32
+ "@react-foundry/docs-components": "^0.2.0",
33
33
  "@storybook/addon-docs": "^9.1.20",
34
34
  "react": "^19.2.4"
35
35
  },
@@ -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.9"
50
+ "@react-foundry/component-test-helpers": "0.2.0"
51
51
  },
52
52
  "scripts": {
53
53
  "test": "NODE_OPTIONS=--experimental-vm-modules jest",
54
- "build": "npm run build:esm && npm run build:cjs",
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.mjs",
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;