piral-core 1.3.0-beta.6050 → 1.3.0-beta.6059
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/esm/components/PiralRoutes.js +15 -4
- package/esm/components/PiralRoutes.js.map +1 -1
- package/esm/types/api.d.ts +2 -12
- package/esm/types/components.d.ts +14 -1
- package/esm/types/state.d.ts +2 -2
- package/esm/utils/index.d.ts +1 -0
- package/esm/utils/index.js +1 -0
- package/esm/utils/index.js.map +1 -1
- package/esm/utils/routes.d.ts +1 -0
- package/esm/utils/routes.js +7 -0
- package/esm/utils/routes.js.map +1 -0
- package/lib/components/PiralRoutes.js +15 -4
- package/lib/components/PiralRoutes.js.map +1 -1
- package/lib/types/api.d.ts +2 -12
- package/lib/types/components.d.ts +14 -1
- package/lib/types/state.d.ts +2 -2
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +1 -0
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/routes.d.ts +1 -0
- package/lib/utils/routes.js +11 -0
- package/lib/utils/routes.js.map +1 -0
- package/package.json +5 -4
- package/src/components/PiralRoutes.tsx +16 -6
- package/src/types/api.ts +1 -11
- package/src/types/components.ts +14 -1
- package/src/types/state.ts +1 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/routes.test.ts +48 -0
- package/src/utils/routes.ts +7 -0
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { useGlobalState } from '../hooks';
|
|
4
|
+
import { createRouteMatcher } from '../utils';
|
|
4
5
|
import { useRouteFilter } from '../../app.codegen';
|
|
5
6
|
function useRoutes() {
|
|
6
7
|
const routes = useGlobalState((s) => s.routes);
|
|
7
8
|
const pages = useGlobalState((s) => s.registry.pages);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
return useRouteFilter([
|
|
10
|
+
...Object.entries(routes).map(([path, Component]) => ({
|
|
11
|
+
path,
|
|
12
|
+
Component,
|
|
13
|
+
meta: {},
|
|
14
|
+
matcher: createRouteMatcher(path),
|
|
15
|
+
})),
|
|
16
|
+
...Object.entries(pages).map(([path, entry]) => ({
|
|
17
|
+
path,
|
|
18
|
+
Component: entry.component,
|
|
19
|
+
meta: entry.meta,
|
|
20
|
+
matcher: createRouteMatcher(path),
|
|
21
|
+
})),
|
|
22
|
+
]);
|
|
12
23
|
}
|
|
13
24
|
/**
|
|
14
25
|
* The component for defining the exclusive routes to be used.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PiralRoutes.js","sourceRoot":"","sources":["../../src/components/PiralRoutes.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"PiralRoutes.js","sourceRoot":"","sources":["../../src/components/PiralRoutes.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAE9C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,SAAS,SAAS;IAChB,MAAM,MAAM,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC/C,MAAM,KAAK,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAEtD,OAAO,cAAc,CAAC;QACpB,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC;YACpD,IAAI;YACJ,SAAS;YACT,IAAI,EAAE,EAAE;YACR,OAAO,EAAE,kBAAkB,CAAC,IAAI,CAAC;SAClC,CAAC,CAAC;QACH,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;YAC/C,IAAI;YACJ,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,OAAO,EAAE,kBAAkB,CAAC,IAAI,CAAC;SAClC,CAAC,CAAC;KACJ,CAAC,CAAC;AACL,CAAC;AAgBD;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAA0B,CAAC,EAAmC,EAAE,EAAE;QAAvC,EAAE,QAAQ,EAAE,WAAW,OAAY,EAAP,KAAK,cAAjC,2BAAmC,CAAF;IAClF,MAAM,KAAK,GAAG,SAAS,EAAE,CAAC;IAC1B,OAAO,oBAAC,WAAW,kBAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,IAAM,KAAK,EAAI,CAAC;AACtE,CAAC,CAAC;AACF,WAAW,CAAC,WAAW,GAAG,QAAQ,CAAC"}
|
package/esm/types/api.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ReactElement, ReactNode } from 'react';
|
|
2
2
|
import type { RouteComponentProps } from 'react-router';
|
|
3
3
|
import type { PiletApi, Pilet, PiletEntry, PiletEntries, PiletMetadata, EventEmitter, PiletLoader, PiletLoadingStrategy } from 'piral-base';
|
|
4
|
-
import type { PiletCustomApi
|
|
5
|
-
import type { AnyComponent } from './components';
|
|
4
|
+
import type { PiletCustomApi } from './custom';
|
|
5
|
+
import type { AnyComponent, PiralPageMeta } from './components';
|
|
6
6
|
import type { ExtensionParams, ExtensionSlotProps, PiralExtensionSlotMap } from './extension';
|
|
7
7
|
import type { SharedData, DataStoreOptions } from './data';
|
|
8
8
|
import type { Disposable } from './utils';
|
|
@@ -38,11 +38,6 @@ export interface ExtensionComponentProps<T> extends BaseComponentProps {
|
|
|
38
38
|
*/
|
|
39
39
|
children?: ReactNode;
|
|
40
40
|
}
|
|
41
|
-
/**
|
|
42
|
-
* The meta data registered for a page.
|
|
43
|
-
*/
|
|
44
|
-
export interface PiralPageMeta extends PiralCustomPageMeta {
|
|
45
|
-
}
|
|
46
41
|
/**
|
|
47
42
|
* The props that every registered page component obtains.
|
|
48
43
|
*/
|
|
@@ -65,11 +60,6 @@ export interface PageComponentProps<T extends {
|
|
|
65
60
|
*/
|
|
66
61
|
children: ReactNode;
|
|
67
62
|
}
|
|
68
|
-
/**
|
|
69
|
-
* The meta data registered for a page.
|
|
70
|
-
*/
|
|
71
|
-
export interface PiralPageMeta extends PiralCustomPageMeta {
|
|
72
|
-
}
|
|
73
63
|
/**
|
|
74
64
|
* Shorthand for the definition of an extension component.
|
|
75
65
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ComponentType, ReactNode } from 'react';
|
|
2
2
|
import type { RouteComponentProps, SwitchProps } from 'react-router';
|
|
3
3
|
import type { FirstParametersOf, UnionOf } from './common';
|
|
4
|
-
import type { PiralCustomErrors, PiralCustomComponentConverters } from './custom';
|
|
4
|
+
import type { PiralCustomErrors, PiralCustomComponentConverters, PiralCustomPageMeta } from './custom';
|
|
5
5
|
import type { NavigationApi } from './navigation';
|
|
6
6
|
import type { LayoutType } from './layout';
|
|
7
7
|
/**
|
|
@@ -209,6 +209,11 @@ export interface RouterProps {
|
|
|
209
209
|
*/
|
|
210
210
|
publicPath: string;
|
|
211
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* The meta data registered for a page.
|
|
214
|
+
*/
|
|
215
|
+
export interface PiralPageMeta extends PiralCustomPageMeta {
|
|
216
|
+
}
|
|
212
217
|
/**
|
|
213
218
|
* Represents a path in the app registration.
|
|
214
219
|
*/
|
|
@@ -217,6 +222,14 @@ export interface AppPath {
|
|
|
217
222
|
* The exact path to use.
|
|
218
223
|
*/
|
|
219
224
|
path: string;
|
|
225
|
+
/**
|
|
226
|
+
* The associated route matcher.
|
|
227
|
+
*/
|
|
228
|
+
matcher: RegExp;
|
|
229
|
+
/**
|
|
230
|
+
* The page metadata.
|
|
231
|
+
*/
|
|
232
|
+
meta: PiralPageMeta;
|
|
220
233
|
/**
|
|
221
234
|
* The component to register for this path.
|
|
222
235
|
*/
|
package/esm/types/state.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ import type { Dict, Without } from './common';
|
|
|
6
6
|
import type { NavigationApi } from './navigation';
|
|
7
7
|
import type { SharedDataItem, DataStoreTarget } from './data';
|
|
8
8
|
import type { PiralCustomActions, PiralCustomState, PiralCustomRegistryState, PiralCustomComponentsState } from './custom';
|
|
9
|
-
import type { EventEmitter, Pilet, BaseComponentProps, PageComponentProps, ExtensionComponentProps, PiletsBag,
|
|
10
|
-
import type { ComponentConverters, LoadingIndicatorProps, ErrorInfoProps, RouterProps, LayoutProps, Errors, RouteSwitchProps } from './components';
|
|
9
|
+
import type { EventEmitter, Pilet, BaseComponentProps, PageComponentProps, ExtensionComponentProps, PiletsBag, PiletEntry } from './api';
|
|
10
|
+
import type { PiralPageMeta, ComponentConverters, LoadingIndicatorProps, ErrorInfoProps, RouterProps, LayoutProps, Errors, RouteSwitchProps } from './components';
|
|
11
11
|
export interface StateDispatcher<TState> {
|
|
12
12
|
(state: TState): Partial<TState>;
|
|
13
13
|
}
|
package/esm/utils/index.d.ts
CHANGED
package/esm/utils/index.js
CHANGED
package/esm/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEnD,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEnD,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createRouteMatcher(path: string): RegExp;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../src/utils/routes.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,4EAA4E;AAC5E,MAAM,GAAG,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAEtC,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC;AACnB,CAAC"}
|
|
@@ -4,14 +4,25 @@ exports.PiralRoutes = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const React = require("react");
|
|
6
6
|
const hooks_1 = require("../hooks");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
7
8
|
const app_codegen_1 = require("../../app.codegen");
|
|
8
9
|
function useRoutes() {
|
|
9
10
|
const routes = (0, hooks_1.useGlobalState)((s) => s.routes);
|
|
10
11
|
const pages = (0, hooks_1.useGlobalState)((s) => s.registry.pages);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
return (0, app_codegen_1.useRouteFilter)([
|
|
13
|
+
...Object.entries(routes).map(([path, Component]) => ({
|
|
14
|
+
path,
|
|
15
|
+
Component,
|
|
16
|
+
meta: {},
|
|
17
|
+
matcher: (0, utils_1.createRouteMatcher)(path),
|
|
18
|
+
})),
|
|
19
|
+
...Object.entries(pages).map(([path, entry]) => ({
|
|
20
|
+
path,
|
|
21
|
+
Component: entry.component,
|
|
22
|
+
meta: entry.meta,
|
|
23
|
+
matcher: (0, utils_1.createRouteMatcher)(path),
|
|
24
|
+
})),
|
|
25
|
+
]);
|
|
15
26
|
}
|
|
16
27
|
/**
|
|
17
28
|
* The component for defining the exclusive routes to be used.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PiralRoutes.js","sourceRoot":"","sources":["../../src/components/PiralRoutes.tsx"],"names":[],"mappings":";;;;AAAA,+BAA+B;AAE/B,oCAA0C;
|
|
1
|
+
{"version":3,"file":"PiralRoutes.js","sourceRoot":"","sources":["../../src/components/PiralRoutes.tsx"],"names":[],"mappings":";;;;AAAA,+BAA+B;AAE/B,oCAA0C;AAC1C,oCAA8C;AAE9C,mDAAmD;AAEnD,SAAS,SAAS;IAChB,MAAM,MAAM,GAAG,IAAA,sBAAc,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC/C,MAAM,KAAK,GAAG,IAAA,sBAAc,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAEtD,OAAO,IAAA,4BAAc,EAAC;QACpB,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC;YACpD,IAAI;YACJ,SAAS;YACT,IAAI,EAAE,EAAE;YACR,OAAO,EAAE,IAAA,0BAAkB,EAAC,IAAI,CAAC;SAClC,CAAC,CAAC;QACH,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;YAC/C,IAAI;YACJ,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,OAAO,EAAE,IAAA,0BAAkB,EAAC,IAAI,CAAC;SAClC,CAAC,CAAC;KACJ,CAAC,CAAC;AACL,CAAC;AAgBD;;GAEG;AACI,MAAM,WAAW,GAA0B,CAAC,EAAmC,EAAE,EAAE;QAAvC,EAAE,QAAQ,EAAE,WAAW,OAAY,EAAP,KAAK,sBAAjC,2BAAmC,CAAF;IAClF,MAAM,KAAK,GAAG,SAAS,EAAE,CAAC;IAC1B,OAAO,oBAAC,WAAW,kBAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,IAAM,KAAK,EAAI,CAAC;AACtE,CAAC,CAAC;AAHW,QAAA,WAAW,eAGtB;AACF,mBAAW,CAAC,WAAW,GAAG,QAAQ,CAAC"}
|
package/lib/types/api.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ReactElement, ReactNode } from 'react';
|
|
2
2
|
import type { RouteComponentProps } from 'react-router';
|
|
3
3
|
import type { PiletApi, Pilet, PiletEntry, PiletEntries, PiletMetadata, EventEmitter, PiletLoader, PiletLoadingStrategy } from 'piral-base';
|
|
4
|
-
import type { PiletCustomApi
|
|
5
|
-
import type { AnyComponent } from './components';
|
|
4
|
+
import type { PiletCustomApi } from './custom';
|
|
5
|
+
import type { AnyComponent, PiralPageMeta } from './components';
|
|
6
6
|
import type { ExtensionParams, ExtensionSlotProps, PiralExtensionSlotMap } from './extension';
|
|
7
7
|
import type { SharedData, DataStoreOptions } from './data';
|
|
8
8
|
import type { Disposable } from './utils';
|
|
@@ -38,11 +38,6 @@ export interface ExtensionComponentProps<T> extends BaseComponentProps {
|
|
|
38
38
|
*/
|
|
39
39
|
children?: ReactNode;
|
|
40
40
|
}
|
|
41
|
-
/**
|
|
42
|
-
* The meta data registered for a page.
|
|
43
|
-
*/
|
|
44
|
-
export interface PiralPageMeta extends PiralCustomPageMeta {
|
|
45
|
-
}
|
|
46
41
|
/**
|
|
47
42
|
* The props that every registered page component obtains.
|
|
48
43
|
*/
|
|
@@ -65,11 +60,6 @@ export interface PageComponentProps<T extends {
|
|
|
65
60
|
*/
|
|
66
61
|
children: ReactNode;
|
|
67
62
|
}
|
|
68
|
-
/**
|
|
69
|
-
* The meta data registered for a page.
|
|
70
|
-
*/
|
|
71
|
-
export interface PiralPageMeta extends PiralCustomPageMeta {
|
|
72
|
-
}
|
|
73
63
|
/**
|
|
74
64
|
* Shorthand for the definition of an extension component.
|
|
75
65
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ComponentType, ReactNode } from 'react';
|
|
2
2
|
import type { RouteComponentProps, SwitchProps } from 'react-router';
|
|
3
3
|
import type { FirstParametersOf, UnionOf } from './common';
|
|
4
|
-
import type { PiralCustomErrors, PiralCustomComponentConverters } from './custom';
|
|
4
|
+
import type { PiralCustomErrors, PiralCustomComponentConverters, PiralCustomPageMeta } from './custom';
|
|
5
5
|
import type { NavigationApi } from './navigation';
|
|
6
6
|
import type { LayoutType } from './layout';
|
|
7
7
|
/**
|
|
@@ -209,6 +209,11 @@ export interface RouterProps {
|
|
|
209
209
|
*/
|
|
210
210
|
publicPath: string;
|
|
211
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* The meta data registered for a page.
|
|
214
|
+
*/
|
|
215
|
+
export interface PiralPageMeta extends PiralCustomPageMeta {
|
|
216
|
+
}
|
|
212
217
|
/**
|
|
213
218
|
* Represents a path in the app registration.
|
|
214
219
|
*/
|
|
@@ -217,6 +222,14 @@ export interface AppPath {
|
|
|
217
222
|
* The exact path to use.
|
|
218
223
|
*/
|
|
219
224
|
path: string;
|
|
225
|
+
/**
|
|
226
|
+
* The associated route matcher.
|
|
227
|
+
*/
|
|
228
|
+
matcher: RegExp;
|
|
229
|
+
/**
|
|
230
|
+
* The page metadata.
|
|
231
|
+
*/
|
|
232
|
+
meta: PiralPageMeta;
|
|
220
233
|
/**
|
|
221
234
|
* The component to register for this path.
|
|
222
235
|
*/
|
package/lib/types/state.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ import type { Dict, Without } from './common';
|
|
|
6
6
|
import type { NavigationApi } from './navigation';
|
|
7
7
|
import type { SharedDataItem, DataStoreTarget } from './data';
|
|
8
8
|
import type { PiralCustomActions, PiralCustomState, PiralCustomRegistryState, PiralCustomComponentsState } from './custom';
|
|
9
|
-
import type { EventEmitter, Pilet, BaseComponentProps, PageComponentProps, ExtensionComponentProps, PiletsBag,
|
|
10
|
-
import type { ComponentConverters, LoadingIndicatorProps, ErrorInfoProps, RouterProps, LayoutProps, Errors, RouteSwitchProps } from './components';
|
|
9
|
+
import type { EventEmitter, Pilet, BaseComponentProps, PageComponentProps, ExtensionComponentProps, PiletsBag, PiletEntry } from './api';
|
|
10
|
+
import type { PiralPageMeta, ComponentConverters, LoadingIndicatorProps, ErrorInfoProps, RouterProps, LayoutProps, Errors, RouteSwitchProps } from './components';
|
|
11
11
|
export interface StateDispatcher<TState> {
|
|
12
12
|
(state: TState): Partial<TState>;
|
|
13
13
|
}
|
package/lib/utils/index.d.ts
CHANGED
package/lib/utils/index.js
CHANGED
|
@@ -13,6 +13,7 @@ tslib_1.__exportStar(require("./guid"), exports);
|
|
|
13
13
|
tslib_1.__exportStar(require("./helpers"), exports);
|
|
14
14
|
tslib_1.__exportStar(require("./media"), exports);
|
|
15
15
|
tslib_1.__exportStar(require("./react"), exports);
|
|
16
|
+
tslib_1.__exportStar(require("./routes"), exports);
|
|
16
17
|
tslib_1.__exportStar(require("./state"), exports);
|
|
17
18
|
tslib_1.__exportStar(require("./storage"), exports);
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
package/lib/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;AAAA,yCAAmD;AAA1C,oGAAA,MAAM,OAAA;AAAE,2GAAA,aAAa,OAAA;AAE9B,oDAA0B;AAC1B,iDAAuB;AACvB,sDAA4B;AAC5B,oDAA0B;AAC1B,iDAAuB;AACvB,oDAA0B;AAC1B,kDAAwB;AACxB,kDAAwB;AACxB,kDAAwB;AACxB,oDAA0B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;AAAA,yCAAmD;AAA1C,oGAAA,MAAM,OAAA;AAAE,2GAAA,aAAa,OAAA;AAE9B,oDAA0B;AAC1B,iDAAuB;AACvB,sDAA4B;AAC5B,oDAA0B;AAC1B,iDAAuB;AACvB,oDAA0B;AAC1B,kDAAwB;AACxB,kDAAwB;AACxB,mDAAyB;AACzB,kDAAwB;AACxB,oDAA0B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createRouteMatcher(path: string): RegExp;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRouteMatcher = void 0;
|
|
4
|
+
// Unfortunately `require`d:
|
|
5
|
+
// * exports are otherwise potentially converted by, e.g., Parcel (see #385)
|
|
6
|
+
const ptr = require('path-to-regexp');
|
|
7
|
+
function createRouteMatcher(path) {
|
|
8
|
+
return ptr(path);
|
|
9
|
+
}
|
|
10
|
+
exports.createRouteMatcher = createRouteMatcher;
|
|
11
|
+
//# sourceMappingURL=routes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../src/utils/routes.ts"],"names":[],"mappings":";;;AAAA,4BAA4B;AAC5B,4EAA4E;AAC5E,MAAM,GAAG,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAEtC,SAAgB,kBAAkB,CAAC,IAAY;IAC7C,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC;AACnB,CAAC;AAFD,gDAEC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-core",
|
|
3
|
-
"version": "1.3.0-beta.
|
|
3
|
+
"version": "1.3.0-beta.6059",
|
|
4
4
|
"description": "The core library for creating a Piral instance.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"portal",
|
|
@@ -72,8 +72,9 @@
|
|
|
72
72
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"
|
|
76
|
-
"piral-
|
|
75
|
+
"path-to-regexp": "^1.8.0",
|
|
76
|
+
"piral-base": "1.3.0-beta.6059",
|
|
77
|
+
"piral-debug-utils": "1.3.0-beta.6059",
|
|
77
78
|
"zustand": "^3.0.0"
|
|
78
79
|
},
|
|
79
80
|
"devDependencies": {
|
|
@@ -93,5 +94,5 @@
|
|
|
93
94
|
"react-router-dom",
|
|
94
95
|
"tslib"
|
|
95
96
|
],
|
|
96
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "ad05f392cd349ca6f6ac5b8cea1a8934ee3d202e"
|
|
97
98
|
}
|
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { RouteComponentProps, SwitchProps } from 'react-router';
|
|
3
3
|
import { useGlobalState } from '../hooks';
|
|
4
|
-
import {
|
|
4
|
+
import { createRouteMatcher } from '../utils';
|
|
5
|
+
import { RouteSwitchProps } from '../types';
|
|
5
6
|
import { useRouteFilter } from '../../app.codegen';
|
|
6
7
|
|
|
7
8
|
function useRoutes() {
|
|
8
9
|
const routes = useGlobalState((s) => s.routes);
|
|
9
10
|
const pages = useGlobalState((s) => s.registry.pages);
|
|
10
|
-
const paths: Array<AppPath> = [];
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
return useRouteFilter([
|
|
13
|
+
...Object.entries(routes).map(([path, Component]) => ({
|
|
14
|
+
path,
|
|
15
|
+
Component,
|
|
16
|
+
meta: {},
|
|
17
|
+
matcher: createRouteMatcher(path),
|
|
18
|
+
})),
|
|
19
|
+
...Object.entries(pages).map(([path, entry]) => ({
|
|
20
|
+
path,
|
|
21
|
+
Component: entry.component,
|
|
22
|
+
meta: entry.meta,
|
|
23
|
+
matcher: createRouteMatcher(path),
|
|
24
|
+
})),
|
|
25
|
+
]);
|
|
16
26
|
}
|
|
17
27
|
|
|
18
28
|
/**
|
package/src/types/api.ts
CHANGED
|
@@ -12,7 +12,7 @@ import type {
|
|
|
12
12
|
} from 'piral-base';
|
|
13
13
|
import type {} from 'piral-debug-utils';
|
|
14
14
|
import type { PiletCustomApi, PiralCustomPageMeta } from './custom';
|
|
15
|
-
import type { AnyComponent } from './components';
|
|
15
|
+
import type { AnyComponent, PiralPageMeta } from './components';
|
|
16
16
|
import type { ExtensionParams, ExtensionSlotProps, PiralExtensionSlotMap } from './extension';
|
|
17
17
|
import type { SharedData, DataStoreOptions } from './data';
|
|
18
18
|
import type { Disposable } from './utils';
|
|
@@ -53,11 +53,6 @@ export interface ExtensionComponentProps<T> extends BaseComponentProps {
|
|
|
53
53
|
children?: ReactNode;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
/**
|
|
57
|
-
* The meta data registered for a page.
|
|
58
|
-
*/
|
|
59
|
-
export interface PiralPageMeta extends PiralCustomPageMeta {}
|
|
60
|
-
|
|
61
56
|
/**
|
|
62
57
|
* The props that every registered page component obtains.
|
|
63
58
|
*/
|
|
@@ -79,11 +74,6 @@ export interface PageComponentProps<T extends { [K in keyof T]?: string } = {},
|
|
|
79
74
|
children: ReactNode;
|
|
80
75
|
}
|
|
81
76
|
|
|
82
|
-
/**
|
|
83
|
-
* The meta data registered for a page.
|
|
84
|
-
*/
|
|
85
|
-
export interface PiralPageMeta extends PiralCustomPageMeta {}
|
|
86
|
-
|
|
87
77
|
/**
|
|
88
78
|
* Shorthand for the definition of an extension component.
|
|
89
79
|
*/
|
package/src/types/components.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ComponentType, ReactNode } from 'react';
|
|
2
2
|
import type { RouteComponentProps, SwitchProps } from 'react-router';
|
|
3
3
|
import type { FirstParametersOf, UnionOf } from './common';
|
|
4
|
-
import type { PiralCustomErrors, PiralCustomComponentConverters } from './custom';
|
|
4
|
+
import type { PiralCustomErrors, PiralCustomComponentConverters, PiralCustomPageMeta } from './custom';
|
|
5
5
|
import type { NavigationApi } from './navigation';
|
|
6
6
|
import type { LayoutType } from './layout';
|
|
7
7
|
|
|
@@ -224,6 +224,11 @@ export interface RouterProps {
|
|
|
224
224
|
publicPath: string;
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
+
/**
|
|
228
|
+
* The meta data registered for a page.
|
|
229
|
+
*/
|
|
230
|
+
export interface PiralPageMeta extends PiralCustomPageMeta {}
|
|
231
|
+
|
|
227
232
|
/**
|
|
228
233
|
* Represents a path in the app registration.
|
|
229
234
|
*/
|
|
@@ -232,6 +237,14 @@ export interface RouterProps {
|
|
|
232
237
|
* The exact path to use.
|
|
233
238
|
*/
|
|
234
239
|
path: string;
|
|
240
|
+
/**
|
|
241
|
+
* The associated route matcher.
|
|
242
|
+
*/
|
|
243
|
+
matcher: RegExp;
|
|
244
|
+
/**
|
|
245
|
+
* The page metadata.
|
|
246
|
+
*/
|
|
247
|
+
meta: PiralPageMeta;
|
|
235
248
|
/**
|
|
236
249
|
* The component to register for this path.
|
|
237
250
|
*/
|
package/src/types/state.ts
CHANGED
package/src/utils/index.ts
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createRouteMatcher } from './routes';
|
|
2
|
+
|
|
3
|
+
describe('Routes Utilities', () => {
|
|
4
|
+
it('creates an exact matcher that does not match', () => {
|
|
5
|
+
const matcher = createRouteMatcher('/foo');
|
|
6
|
+
expect(matcher.test('/bar')).toBeFalsy();
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('creates an exact matcher that does match exactly', () => {
|
|
10
|
+
const matcher = createRouteMatcher('/foo');
|
|
11
|
+
expect(matcher.test('/foo')).toBeTruthy();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('creates an exact matcher that does match with trailing slash', () => {
|
|
15
|
+
const matcher = createRouteMatcher('/foo');
|
|
16
|
+
expect(matcher.test('/foo/')).toBeTruthy();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('creates an exact parameter matcher that does not match', () => {
|
|
20
|
+
const matcher = createRouteMatcher('/foo/:id');
|
|
21
|
+
expect(matcher.test('/bar')).toBeFalsy();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('creates an exact matcher that does not match exactly', () => {
|
|
25
|
+
const matcher = createRouteMatcher('/foo/:id');
|
|
26
|
+
expect(matcher.test('/foo')).toBeFalsy();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('creates an exact matcher that does match exactly', () => {
|
|
30
|
+
const matcher = createRouteMatcher('/foo/:id');
|
|
31
|
+
expect(matcher.test('/foo/bar')).toBeTruthy();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('creates an inexact matcher that does not match', () => {
|
|
35
|
+
const matcher = createRouteMatcher('/foo/*');
|
|
36
|
+
expect(matcher.test('/bar')).toBeFalsy();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('creates an inexact matcher that does not match exactly', () => {
|
|
40
|
+
const matcher = createRouteMatcher('/foo/:id/*');
|
|
41
|
+
expect(matcher.test('/foo/')).toBeFalsy();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('creates an inexact matcher that does match exactly', () => {
|
|
45
|
+
const matcher = createRouteMatcher('/foo/*');
|
|
46
|
+
expect(matcher.test('/foo/bar')).toBeTruthy();
|
|
47
|
+
});
|
|
48
|
+
});
|