piral-core 1.10.2-beta.bcfd89f → 1.10.2-beta.c944cfd

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.
@@ -1,11 +1,27 @@
1
1
  import * as React from 'react';
2
2
  //@ts-ignore
3
- import { Routes, Route } from 'react-router-dom';
3
+ import { Routes, Route, useParams, useLocation, useNavigate } from 'react-router-dom';
4
+ function getHistory(navigate) {
5
+ return {
6
+ push(path, state) {
7
+ navigate(path, { replace: false, state });
8
+ },
9
+ replace(path, state) {
10
+ navigate(path, { replace: true, state });
11
+ },
12
+ };
13
+ }
14
+ const RouteContentWrapper = ({ Component }) => {
15
+ const navigate = useNavigate();
16
+ const params = useParams();
17
+ const loc = useLocation();
18
+ return (React.createElement(Component, { history: getHistory(navigate), location: loc, match: { params, isExact: true, path: loc.pathname, url: location.href } }));
19
+ };
4
20
  export const DefaultRouteSwitch = ({ paths, NotFound, ...props }) => {
5
21
  return (React.createElement(Routes, { ...props },
6
22
  paths.map(({ path, Component }) => (
7
23
  //@ts-ignore
8
- React.createElement(Route, { key: path, path: path, element: React.createElement(Component, null) }))),
24
+ React.createElement(Route, { key: path, path: path, element: React.createElement(RouteContentWrapper, { Component: Component }) }))),
9
25
  //@ts-ignore
10
26
  React.createElement(Route, { path: "*", element: React.createElement(NotFound, null) })));
11
27
  };
@@ -1 +1 @@
1
- {"version":3,"file":"DefaultRouteSwitch_v6.js","sourceRoot":"","sources":["../../src/defaults/DefaultRouteSwitch_v6.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,YAAY;AACZ,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAGjD,MAAM,CAAC,MAAM,kBAAkB,GAA+B,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,EAAE;IAC9F,OAAO,CACL,oBAAC,MAAM,OAAK,KAAK;QACd,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AU,CAAC,QAAQ,CAAC,EAC7B,QAAQ,EAAE,GAAG,EACb,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,QAAQ,EAAE,GAAG,EAAE,QAAQ,CAAC,IAAI,EAAE,GACxE,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAA+B,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,EAAE;IAC9F,OAAO,CACL,oBAAC,MAAM,OAAK,KAAK;QACd,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;QAClC,YAAY;QACZ,oBAAC,KAAK,IAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,oBAAC,mBAAmB,IAAC,SAAS,EAAE,SAAS,GAAI,GAAI,CACzF,CAAC;QAEA,YAAY;QACZ,oBAAC,KAAK,IAAC,IAAI,EAAC,GAAG,EAAC,OAAO,EAAE,oBAAC,QAAQ,OAAG,GAAI,CAEpC,CACV,CAAC;AACJ,CAAC,CAAC;AACF,kBAAkB,CAAC,WAAW,GAAG,oBAAoB,CAAC"}
@@ -1,11 +1,27 @@
1
1
  import * as React from 'react';
2
2
  //@ts-ignore
3
- import { Routes, Route } from 'react-router';
3
+ import { Routes, Route, useParams, useLocation, useNavigate } from 'react-router';
4
+ function getHistory(navigate) {
5
+ return {
6
+ push(path, state) {
7
+ navigate(path, { replace: false, state });
8
+ },
9
+ replace(path, state) {
10
+ navigate(path, { replace: true, state });
11
+ },
12
+ };
13
+ }
14
+ const RouteContentWrapper = ({ Component }) => {
15
+ const navigate = useNavigate();
16
+ const params = useParams();
17
+ const loc = useLocation();
18
+ return (React.createElement(Component, { history: getHistory(navigate), location: loc, match: { params, isExact: true, path: loc.pathname, url: location.href } }));
19
+ };
4
20
  export const DefaultRouteSwitch = ({ paths, NotFound, ...props }) => {
5
21
  return (React.createElement(Routes, { ...props },
6
22
  paths.map(({ path, Component }) => (
7
23
  //@ts-ignore
8
- React.createElement(Route, { key: path, path: path, element: React.createElement(Component, null) }))),
24
+ React.createElement(Route, { key: path, path: path, element: React.createElement(RouteContentWrapper, { Component: Component }) }))),
9
25
  //@ts-ignore
10
26
  React.createElement(Route, { path: "*", element: React.createElement(NotFound, null) })));
11
27
  };
@@ -1 +1 @@
1
- {"version":3,"file":"DefaultRouteSwitch_v7.js","sourceRoot":"","sources":["../../src/defaults/DefaultRouteSwitch_v7.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,YAAY;AACZ,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAG7C,MAAM,CAAC,MAAM,kBAAkB,GAA+B,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,EAAE;IAC9F,OAAO,CACL,oBAAC,MAAM,OAAK,KAAK;QACd,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;QAClC,YAAY;QACZ,oBAAC,KAAK,IAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,oBAAC,SAAS,OAAG,GAAI,CACzD,CAAC;QAEA,YAAY;QACZ,oBAAC,KAAK,IAAC,IAAI,EAAC,GAAG,EAAC,OAAO,EAAE,oBAAC,QAAQ,OAAG,GAAI,CAEpC,CACV,CAAC;AACJ,CAAC,CAAC;AACF,kBAAkB,CAAC,WAAW,GAAG,oBAAoB,CAAC"}
1
+ {"version":3,"file":"DefaultRouteSwitch_v7.js","sourceRoot":"","sources":["../../src/defaults/DefaultRouteSwitch_v7.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,YAAY;AACZ,OAAO,EAAE,MA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AAC;AAMD,MAAM,mBAAmB,GAAuC,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE;IAChF,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,WAAW,EAAE,CAAC;IAE3C,OAAO,CACL,oBAAC,SAAS,IACR,OAAO,EAAE,UAAU,CAAC,QAAQ,CAAC,EAC7B,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,EACtF,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,CAAC,IAAI,EAAE,GACpE,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAA+B,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,EAAE;IAC9F,OAAO,CACL,oBAAC,MAAM,OAAK,KAAK;QACd,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAClC,oBAAC,KAAK,IAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;YAC1B,oBAAC,mBAAmB,IAAC,SAAS,EAAE,SAAS,GAAI,CACvC,CACT,CAAC;QACF,oBAAC,KAAK;YACJ,oBAAC,mBAAmB,IAAC,SAAS,EAAE,QAAQ,GAAI,CACtC,CACD,CACV,CAAC;AACJ,CAAC,CAAC;AACF,kBAAkB,CAAC,WAAW,GAAG,oBAAoB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { ReactElement, ReactNode } from 'react';
2
- import type { RouteComponentProps } from 'react-router';
2
+ import type { History, Location } from 'history';
3
3
  import type { PiletApi, Pilet, PiletEntry, PiletEntries, PiletMetadata, EventEmitter, PiletLoader, PiletLoadingStrategy } from 'piral-base';
4
4
  import type { PiletCustomApi } from './custom';
5
5
  import type { AnyComponent, PiralPageMeta } from './components';
@@ -38,12 +38,47 @@ export interface ExtensionComponentProps<T> extends BaseComponentProps {
38
38
  */
39
39
  children?: ReactNode;
40
40
  }
41
+ /**
42
+ * The match object determining what exactly has been matched for the current navigation.
43
+ */
44
+ export interface RouteMatch<Params extends {
45
+ [K in keyof Params]?: string;
46
+ } = {}> {
47
+ /**
48
+ * The parameters extracted from the current navigation.
49
+ */
50
+ params: Params;
51
+ /**
52
+ * Indicates if the parameters have been matched exactly.
53
+ */
54
+ isExact: boolean;
55
+ /**
56
+ * The relative path.
57
+ */
58
+ path: string;
59
+ /**
60
+ * The fully qualified URL.
61
+ */
62
+ url: string;
63
+ }
41
64
  /**
42
65
  * The props that every registered page component obtains.
43
66
  */
44
67
  export interface RouteBaseProps<UrlParams extends {
45
68
  [K in keyof UrlParams]?: string;
46
- } = {}, UrlState = any> extends RouteComponentProps<UrlParams, {}, UrlState>, BaseComponentProps {
69
+ } = {}, UrlState = any> extends BaseComponentProps {
70
+ /**
71
+ * The history API to navigate.
72
+ */
73
+ history: History<UrlState>;
74
+ /**
75
+ * Information about the current location.
76
+ */
77
+ location: Location<UrlState>;
78
+ /**
79
+ * Information about the matching of the current route.
80
+ */
81
+ match: RouteMatch<UrlParams>;
47
82
  }
48
83
  /**
49
84
  * The props used by a page component.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-core",
3
- "version": "1.10.2-beta.bcfd89f",
3
+ "version": "1.10.2-beta.c944cfd",
4
4
  "description": "The core library for creating a Piral instance.",
5
5
  "keywords": [
6
6
  "portal",
@@ -63,8 +63,8 @@
63
63
  "test": "echo \"Error: run tests from root\" && exit 1"
64
64
  },
65
65
  "dependencies": {
66
- "piral-base": "1.10.2-beta.bcfd89f",
67
- "piral-debug-utils": "1.10.2-beta.bcfd89f",
66
+ "piral-base": "1.10.2-beta.c944cfd",
67
+ "piral-debug-utils": "1.10.2-beta.c944cfd",
68
68
  "zustand": "^3.0.0"
69
69
  },
70
70
  "devDependencies": {
@@ -84,5 +84,5 @@
84
84
  "react-router-dom",
85
85
  "tslib"
86
86
  ],
87
- "gitHead": "bcfd89f9f012d80d58769664e72415bdcee27a3d"
87
+ "gitHead": "c944cfdddc642d5bf44c3494b3b8632bb5d45431"
88
88
  }
@@ -1,14 +1,43 @@
1
1
  import * as React from 'react';
2
2
  //@ts-ignore
3
- import { Routes, Route } from 'react-router-dom';
3
+ import { Routes, Route, useParams, useLocation, useNavigate } from 'react-router-dom';
4
4
  import { RouteSwitchProps } from '../types';
5
5
 
6
+ function getHistory(navigate: any): any {
7
+ return {
8
+ push(path: string, state: any) {
9
+ navigate(path, { replace: false, state });
10
+ },
11
+ replace(path: string, state: any) {
12
+ navigate(path, { replace: true, state });
13
+ },
14
+ };
15
+ }
16
+
17
+ interface RouteContentWrapperProps {
18
+ Component: RouteSwitchProps['paths'][0]['Component'];
19
+ }
20
+
21
+ const RouteContentWrapper: React.FC<RouteContentWrapperProps> = ({ Component }) => {
22
+ const navigate = useNavigate();
23
+ const params = useParams();
24
+ const loc = useLocation();
25
+
26
+ return (
27
+ <Component
28
+ history={getHistory(navigate)}
29
+ location={loc}
30
+ match={{ params, isExact: true, path: loc.pathname, url: location.href }}
31
+ />
32
+ );
33
+ };
34
+
6
35
  export const DefaultRouteSwitch: React.FC<RouteSwitchProps> = ({ paths, NotFound, ...props }) => {
7
36
  return (
8
37
  <Routes {...props}>
9
38
  {paths.map(({ path, Component }) => (
10
39
  //@ts-ignore
11
- <Route key={path} path={path} element={<Component />} />
40
+ <Route key={path} path={path} element={<RouteContentWrapper Component={Component} />} />
12
41
  ))}
13
42
  {
14
43
  //@ts-ignore
@@ -1,14 +1,43 @@
1
1
  import * as React from 'react';
2
2
  //@ts-ignore
3
- import { Routes, Route } from 'react-router';
3
+ import { Routes, Route, useParams, useLocation, useNavigate } from 'react-router';
4
4
  import { RouteSwitchProps } from '../types';
5
5
 
6
+ function getHistory(navigate: any): any {
7
+ return {
8
+ push(path: string, state: any) {
9
+ navigate(path, { replace: false, state });
10
+ },
11
+ replace(path: string, state: any) {
12
+ navigate(path, { replace: true, state });
13
+ },
14
+ };
15
+ }
16
+
17
+ interface RouteContentWrapperProps {
18
+ Component: RouteSwitchProps['paths'][0]['Component'];
19
+ }
20
+
21
+ const RouteContentWrapper: React.FC<RouteContentWrapperProps> = ({ Component }) => {
22
+ const navigate = useNavigate();
23
+ const params = useParams();
24
+ const loc = useLocation();
25
+
26
+ return (
27
+ <Component
28
+ history={getHistory(navigate)}
29
+ location={loc}
30
+ match={{ params, isExact: true, path: loc.pathname, url: location.href }}
31
+ />
32
+ );
33
+ };
34
+
6
35
  export const DefaultRouteSwitch: React.FC<RouteSwitchProps> = ({ paths, NotFound, ...props }) => {
7
36
  return (
8
37
  <Routes {...props}>
9
38
  {paths.map(({ path, Component }) => (
10
39
  //@ts-ignore
11
- <Route key={path} path={path} element={<Component />} />
40
+ <Route key={path} path={path} element={<RouteContentWrapper Component={Component} />} />
12
41
  ))}
13
42
  {
14
43
  //@ts-ignore
@@ -21,6 +21,7 @@ interface RouteContentWrapperProps {
21
21
  const RouteContentWrapper: React.FC<RouteContentWrapperProps> = ({ Component }) => {
22
22
  const params = useParams();
23
23
  const [pathname, navigate] = useLocation();
24
+
24
25
  return (
25
26
  <Component
26
27
  history={getHistory(navigate)}
package/src/types/api.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ReactElement, ReactNode } from 'react';
2
- import type { RouteComponentProps } from 'react-router';
2
+ import type { History, Location } from 'history';
3
3
  import type {
4
4
  PiletApi,
5
5
  Pilet,
@@ -53,12 +53,46 @@ export interface ExtensionComponentProps<T> extends BaseComponentProps {
53
53
  children?: ReactNode;
54
54
  }
55
55
 
56
+ /**
57
+ * The match object determining what exactly has been matched for the current navigation.
58
+ */
59
+ export interface RouteMatch<Params extends { [K in keyof Params]?: string } = {}> {
60
+ /**
61
+ * The parameters extracted from the current navigation.
62
+ */
63
+ params: Params;
64
+ /**
65
+ * Indicates if the parameters have been matched exactly.
66
+ */
67
+ isExact: boolean;
68
+ /**
69
+ * The relative path.
70
+ */
71
+ path: string;
72
+ /**
73
+ * The fully qualified URL.
74
+ */
75
+ url: string;
76
+ }
77
+
56
78
  /**
57
79
  * The props that every registered page component obtains.
58
80
  */
59
81
  export interface RouteBaseProps<UrlParams extends { [K in keyof UrlParams]?: string } = {}, UrlState = any>
60
- extends RouteComponentProps<UrlParams, {}, UrlState>,
61
- BaseComponentProps {}
82
+ extends BaseComponentProps {
83
+ /**
84
+ * The history API to navigate.
85
+ */
86
+ history: History<UrlState>;
87
+ /**
88
+ * Information about the current location.
89
+ */
90
+ location: Location<UrlState>;
91
+ /**
92
+ * Information about the matching of the current route.
93
+ */
94
+ match: RouteMatch<UrlParams>;
95
+ }
62
96
 
63
97
  /**
64
98
  * The props used by a page component.
@@ -80,8 +114,8 @@ export interface PageComponentProps<T extends { [K in keyof T]?: string } = {},
80
114
  export type AnyExtensionComponent<TName> = TName extends keyof PiralExtensionSlotMap
81
115
  ? AnyComponent<ExtensionComponentProps<TName>>
82
116
  : TName extends string
83
- ? AnyComponent<ExtensionComponentProps<any>>
84
- : AnyComponent<ExtensionComponentProps<TName>>;
117
+ ? AnyComponent<ExtensionComponentProps<any>>
118
+ : AnyComponent<ExtensionComponentProps<TName>>;
85
119
 
86
120
  /**
87
121
  * Defines the Pilet API from piral-core.