@forge/react 11.16.2-next.1-experimental-49a346a → 11.16.2-next.1-experimental-ad10820
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/CHANGELOG.md +2 -2
- package/out/router/components/Route.d.ts +13 -0
- package/out/router/components/Route.d.ts.map +1 -1
- package/out/router/components/Route.js +5 -0
- package/out/router/components/Router.d.ts +13 -1
- package/out/router/components/Router.d.ts.map +1 -1
- package/out/router/components/Router.js +18 -3
- package/out/router/components/__test__/Router.test.js +7 -0
- package/out/router/hooks/useLocation.d.ts +6 -0
- package/out/router/hooks/useLocation.d.ts.map +1 -1
- package/out/router/hooks/useLocation.js +6 -0
- package/out/router/hooks/useNavigate.d.ts +5 -0
- package/out/router/hooks/useNavigate.d.ts.map +1 -1
- package/out/router/hooks/useNavigate.js +5 -0
- package/out/router/hooks/useParams.d.ts +6 -0
- package/out/router/hooks/useParams.d.ts.map +1 -1
- package/out/router/hooks/useParams.js +6 -0
- package/package.json +2 -2
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @forge/react
|
|
2
2
|
|
|
3
|
-
## 11.16.2-next.1-experimental-
|
|
3
|
+
## 11.16.2-next.1-experimental-ad10820
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
- Updated dependencies [f7f06c8]
|
|
21
21
|
- Updated dependencies [dba5074]
|
|
22
22
|
- Updated dependencies [fc55c83]
|
|
23
|
-
- @forge/bridge@5.17.0-next.6-experimental-
|
|
23
|
+
- @forge/bridge@5.17.0-next.6-experimental-ad10820
|
|
24
24
|
|
|
25
25
|
## 11.16.2-next.1
|
|
26
26
|
|
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
import { ForgeChildren } from '../../types';
|
|
2
2
|
export interface RouteProps {
|
|
3
|
+
/**
|
|
4
|
+
* The URL path pattern to match against the current location. Supports static segments, dynamic parameters (e.g. :id), and a catch-all wildcard (*).
|
|
5
|
+
* @type string
|
|
6
|
+
*/
|
|
3
7
|
path: string;
|
|
8
|
+
/**
|
|
9
|
+
* The content to render when the path matches the current location.
|
|
10
|
+
* @type ForgeElement
|
|
11
|
+
*/
|
|
4
12
|
children: ForgeChildren;
|
|
5
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Route conditionally renders its children when the current URL path matches its path prop. It must be used within a Router component.
|
|
16
|
+
*
|
|
17
|
+
* @see [Route](https://developer.atlassian.com/platform/forge/ui-kit/components/router/#route) in UI Kit documentation for more information
|
|
18
|
+
*/
|
|
6
19
|
export declare const Route: ({ path, children }: RouteProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
7
20
|
//# sourceMappingURL=Route.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Route.d.ts","sourceRoot":"","sources":["../../../src/router/components/Route.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,aAAa,CAAC;CACzB;AAED,eAAO,MAAM,KAAK,uBAAwB,UAAU,mDAoBnD,CAAC"}
|
|
1
|
+
{"version":3,"file":"Route.d.ts","sourceRoot":"","sources":["../../../src/router/components/Route.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,WAAW,UAAU;IACzB;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,QAAQ,EAAE,aAAa,CAAC;CACzB;AAED;;;;GAIG;AACH,eAAO,MAAM,KAAK,uBAAwB,UAAU,mDAoBnD,CAAC"}
|
|
@@ -6,6 +6,11 @@ const react_1 = require("react");
|
|
|
6
6
|
const RouterContext_1 = require("./RouterContext");
|
|
7
7
|
const ParamsContext_1 = require("./ParamsContext");
|
|
8
8
|
const matchPath_1 = require("../utils/matchPath");
|
|
9
|
+
/**
|
|
10
|
+
* Route conditionally renders its children when the current URL path matches its path prop. It must be used within a Router component.
|
|
11
|
+
*
|
|
12
|
+
* @see [Route](https://developer.atlassian.com/platform/forge/ui-kit/components/router/#route) in UI Kit documentation for more information
|
|
13
|
+
*/
|
|
9
14
|
const Route = ({ path, children }) => {
|
|
10
15
|
const context = (0, react_1.useContext)(RouterContext_1.RouterContext);
|
|
11
16
|
if (!context) {
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import { ForgeChildren, ForgeNode } from '../../types';
|
|
2
2
|
export interface RouterProps {
|
|
3
|
+
/**
|
|
4
|
+
* @type Route
|
|
5
|
+
* The child elements to render within the router. Typically contains one or more Route components.
|
|
6
|
+
*/
|
|
3
7
|
children: ForgeChildren;
|
|
4
|
-
|
|
8
|
+
/**
|
|
9
|
+
* A fallback value to render when no Route child has a path matching the current path.
|
|
10
|
+
*/
|
|
11
|
+
fallback?: ForgeNode | null;
|
|
5
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Router provides client-side routing by allowing content to be rendered based on the current URL path.
|
|
15
|
+
*
|
|
16
|
+
* @see [Router](https://developer.atlassian.com/platform/forge/ui-kit/components/router/) in UI Kit documentation for more information
|
|
17
|
+
*/
|
|
6
18
|
export declare const Router: ({ children, fallback }: RouterProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
19
|
//# sourceMappingURL=Router.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../../src/router/components/Router.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../../src/router/components/Router.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAevD,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,QAAQ,EAAE,aAAa,CAAC;IACxB;;OAEG;IACH,QAAQ,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;CAC7B;AAED;;;;GAIG;AACH,eAAO,MAAM,MAAM,2BAAmC,WAAW,4CAiEhE,CAAC"}
|
|
@@ -5,6 +5,18 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const bridge_1 = require("@forge/bridge");
|
|
7
7
|
const RouterContext_1 = require("./RouterContext");
|
|
8
|
+
const components_1 = require("../../components");
|
|
9
|
+
const Fallback = ({ hasMatchedRouteRef, fallback }) => {
|
|
10
|
+
if (hasMatchedRouteRef.current) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: fallback });
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Router provides client-side routing by allowing content to be rendered based on the current URL path.
|
|
17
|
+
*
|
|
18
|
+
* @see [Router](https://developer.atlassian.com/platform/forge/ui-kit/components/router/) in UI Kit documentation for more information
|
|
19
|
+
*/
|
|
8
20
|
const Router = ({ children, fallback = null }) => {
|
|
9
21
|
const [history, setHistory] = (0, react_1.useState)(null);
|
|
10
22
|
const [location, setLocation] = (0, react_1.useState)(null);
|
|
@@ -35,9 +47,12 @@ const Router = ({ children, fallback = null }) => {
|
|
|
35
47
|
}
|
|
36
48
|
return { history, location, hasMatchedRouteRef };
|
|
37
49
|
}, [history, location]);
|
|
38
|
-
if (error
|
|
39
|
-
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.
|
|
50
|
+
if (error) {
|
|
51
|
+
return ((0, jsx_runtime_1.jsx)(components_1.SectionMessage, { appearance: "error", children: (0, jsx_runtime_1.jsx)(components_1.Text, { children: error.message }) }));
|
|
52
|
+
}
|
|
53
|
+
if (!routerContext) {
|
|
54
|
+
return ((0, jsx_runtime_1.jsx)(components_1.SectionMessage, { appearance: "error", children: (0, jsx_runtime_1.jsxs)(components_1.Text, { children: ["History is not defined. Check the list of", ' ', (0, jsx_runtime_1.jsx)(components_1.Link, { href: "https://developer.atlassian.com/platform/forge/ui-kit/components/router/#supported-modules", children: "supported modules" }), ' ', "for Router"] }) }));
|
|
40
55
|
}
|
|
41
|
-
return (0, jsx_runtime_1.
|
|
56
|
+
return ((0, jsx_runtime_1.jsxs)(RouterContext_1.RouterContext.Provider, { value: routerContext, children: [children, (0, jsx_runtime_1.jsx)(Fallback, { hasMatchedRouteRef: hasMatchedRouteRef, fallback: fallback })] }));
|
|
42
57
|
};
|
|
43
58
|
exports.Router = Router;
|
|
@@ -59,6 +59,13 @@ describe('Router', () => {
|
|
|
59
59
|
expect(forgeDoc).toHaveProperty('children[0].children[0].props.text', 'First');
|
|
60
60
|
expect(forgeDoc?.children).toHaveLength(1);
|
|
61
61
|
});
|
|
62
|
+
it('renders fallback when no Route matches', async () => {
|
|
63
|
+
mockCreateHistory.mockImplementation(async () => (0, test_utils_1.createMockHistory)('/unknown'));
|
|
64
|
+
await reconcilerTestRenderer_1.default.create((0, jsx_runtime_1.jsxs)(Router_1.Router, { fallback: (0, jsx_runtime_1.jsx)(__1.Text, { children: "No match" }), children: [(0, jsx_runtime_1.jsx)(Route_1.Route, { path: "/", children: (0, jsx_runtime_1.jsx)(__1.Text, { children: "Home" }) }), (0, jsx_runtime_1.jsx)(Route_1.Route, { path: "/settings", children: (0, jsx_runtime_1.jsx)(__1.Text, { children: "Settings" }) })] }));
|
|
65
|
+
const forgeDoc = (0, testUtils_1.getLastBridgeCallForgeDoc)(bridgeCalls);
|
|
66
|
+
expect(forgeDoc).toHaveProperty('children[0].type', 'Text');
|
|
67
|
+
expect(forgeDoc).toHaveProperty('children[0].children[0].props.text', 'No match');
|
|
68
|
+
});
|
|
62
69
|
it('renders the catchall Route when no other route matches', async () => {
|
|
63
70
|
mockCreateHistory.mockImplementation(async () => (0, test_utils_1.createMockHistory)('/unknown'));
|
|
64
71
|
await reconcilerTestRenderer_1.default.create((0, jsx_runtime_1.jsxs)(Router_1.Router, { children: [(0, jsx_runtime_1.jsx)(Route_1.Route, { path: "/", children: (0, jsx_runtime_1.jsx)(__1.Text, { children: "Home" }) }), (0, jsx_runtime_1.jsx)(Route_1.Route, { path: "*", children: (0, jsx_runtime_1.jsx)(__1.Text, { children: "Not Found" }) })] }));
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import type { Location } from 'history';
|
|
2
|
+
/**
|
|
3
|
+
* This hook returns the current location object, which contains information about the current URL. It updates automatically when the user navigates to a different route.
|
|
4
|
+
* It must be used within a Router component.
|
|
5
|
+
*
|
|
6
|
+
* @see [useLocation](https://developer.atlassian.com/platform/forge/ui-kit/hooks/use-location/) in UI Kit documentation for more information
|
|
7
|
+
*/
|
|
2
8
|
export declare const useLocation: () => Location;
|
|
3
9
|
//# sourceMappingURL=useLocation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocation.d.ts","sourceRoot":"","sources":["../../../src/router/hooks/useLocation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGxC,eAAO,MAAM,WAAW,QAAO,QAQ9B,CAAC"}
|
|
1
|
+
{"version":3,"file":"useLocation.d.ts","sourceRoot":"","sources":["../../../src/router/hooks/useLocation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGxC;;;;;GAKG;AACH,eAAO,MAAM,WAAW,QAAO,QAQ9B,CAAC"}
|
|
@@ -3,6 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useLocation = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const RouterContext_1 = require("../components/RouterContext");
|
|
6
|
+
/**
|
|
7
|
+
* This hook returns the current location object, which contains information about the current URL. It updates automatically when the user navigates to a different route.
|
|
8
|
+
* It must be used within a Router component.
|
|
9
|
+
*
|
|
10
|
+
* @see [useLocation](https://developer.atlassian.com/platform/forge/ui-kit/hooks/use-location/) in UI Kit documentation for more information
|
|
11
|
+
*/
|
|
6
12
|
const useLocation = () => {
|
|
7
13
|
const context = (0, react_1.useContext)(RouterContext_1.RouterContext);
|
|
8
14
|
if (!context) {
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
interface NavigateOptions {
|
|
2
2
|
replace?: boolean;
|
|
3
3
|
}
|
|
4
|
+
/**
|
|
5
|
+
* This hook returns a function that lets you programmatically navigate to different routes in your app. It must be used within a Router component.
|
|
6
|
+
*
|
|
7
|
+
* @see [useNavigate](https://developer.atlassian.com/platform/forge/ui-kit/hooks/use-navigate/) in UI Kit documentation for more information
|
|
8
|
+
*/
|
|
4
9
|
export declare const useNavigate: () => (to: string | number, options?: NavigateOptions) => void;
|
|
5
10
|
export {};
|
|
6
11
|
//# sourceMappingURL=useNavigate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNavigate.d.ts","sourceRoot":"","sources":["../../../src/router/hooks/useNavigate.ts"],"names":[],"mappings":"AAGA,UAAU,eAAe;
|
|
1
|
+
{"version":3,"file":"useNavigate.d.ts","sourceRoot":"","sources":["../../../src/router/hooks/useNavigate.ts"],"names":[],"mappings":"AAGA,UAAU,eAAe;IAIvB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAwBD;;;;GAIG;AACH,eAAO,MAAM,WAAW,aAUf,MAAM,GAAG,MAAM,YAAY,eAAe,SAkBlD,CAAC"}
|
|
@@ -21,6 +21,11 @@ const resolvePath = (currentPathname, to) => {
|
|
|
21
21
|
}
|
|
22
22
|
return '/' + resolved.join('/');
|
|
23
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* This hook returns a function that lets you programmatically navigate to different routes in your app. It must be used within a Router component.
|
|
26
|
+
*
|
|
27
|
+
* @see [useNavigate](https://developer.atlassian.com/platform/forge/ui-kit/hooks/use-navigate/) in UI Kit documentation for more information
|
|
28
|
+
*/
|
|
24
29
|
const useNavigate = () => {
|
|
25
30
|
const context = (0, react_1.useContext)(RouterContext_1.RouterContext);
|
|
26
31
|
if (!context) {
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This hook returns an object containing the dynamic parameters extracted from the current URL, as defined by the matching Route component's path prop.
|
|
3
|
+
* It must be used within a Route component.
|
|
4
|
+
*
|
|
5
|
+
* @see [useParams](https://developer.atlassian.com/platform/forge/ui-kit/hooks/use-params/) in UI Kit documentation for more information
|
|
6
|
+
*/
|
|
1
7
|
export declare const useParams: () => Record<string, string>;
|
|
2
8
|
//# sourceMappingURL=useParams.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useParams.d.ts","sourceRoot":"","sources":["../../../src/router/hooks/useParams.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS,QAAO,OAAO,MAAM,EAAE,MAAM,CAMjD,CAAC"}
|
|
1
|
+
{"version":3,"file":"useParams.d.ts","sourceRoot":"","sources":["../../../src/router/hooks/useParams.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,eAAO,MAAM,SAAS,QAAO,OAAO,MAAM,EAAE,MAAM,CAMjD,CAAC"}
|
|
@@ -3,6 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useParams = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const ParamsContext_1 = require("../components/ParamsContext");
|
|
6
|
+
/**
|
|
7
|
+
* This hook returns an object containing the dynamic parameters extracted from the current URL, as defined by the matching Route component's path prop.
|
|
8
|
+
* It must be used within a Route component.
|
|
9
|
+
*
|
|
10
|
+
* @see [useParams](https://developer.atlassian.com/platform/forge/ui-kit/hooks/use-params/) in UI Kit documentation for more information
|
|
11
|
+
*/
|
|
6
12
|
const useParams = () => {
|
|
7
13
|
const context = (0, react_1.useContext)(ParamsContext_1.ParamsContext);
|
|
8
14
|
if (context === null) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forge/react",
|
|
3
|
-
"version": "11.16.2-next.1-experimental-
|
|
3
|
+
"version": "11.16.2-next.1-experimental-ad10820",
|
|
4
4
|
"description": "Forge React reconciler",
|
|
5
5
|
"author": "Atlassian",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@atlaskit/adf-schema": "^48.0.0",
|
|
37
37
|
"@atlaskit/adf-utils": "^19.19.0",
|
|
38
38
|
"@atlaskit/forge-react-types": "^1.3.0",
|
|
39
|
-
"@forge/bridge": "^5.17.0-next.6-experimental-
|
|
39
|
+
"@forge/bridge": "^5.17.0-next.6-experimental-ad10820",
|
|
40
40
|
"@forge/egress": "^2.3.2",
|
|
41
41
|
"@forge/i18n": "0.0.7",
|
|
42
42
|
"@types/react": "^18.2.64",
|