@common-stack/client-react 3.0.3-alpha.7 → 4.0.1-alpha.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/lib/connector/base-connector.js +2 -2
- package/lib/connector/base-connector.js.map +1 -1
- package/lib/connector/connector.native.d.ts +11 -2
- package/lib/connector/connector.native.js +12 -3
- package/lib/connector/connector.native.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.native.d.ts +0 -1
- package/lib/index.native.js +1 -1
- package/lib/route/get-routes.js +47 -14
- package/lib/route/get-routes.js.map +1 -1
- package/lib/utils/filteredRoutes.d.ts +3 -0
- package/lib/utils/filteredRoutes.js +31 -0
- package/lib/utils/filteredRoutes.js.map +1 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/sort-keys.js +14 -13
- package/lib/utils/sort-keys.js.map +1 -1
- package/lib/utils/utils.js +6 -7
- package/lib/utils/utils.js.map +1 -1
- package/package.json +4 -4
- package/lib/route/index.native.d.ts +0 -1
- package/lib/route/render-routes-native.d.ts +0 -3
- package/lib/route/render-routes-native.js +0 -68
- package/lib/route/render-routes-native.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import*as React from'react';import {AbstractFeature}from'@common-stack/client-core';import {sortBy,find}from'lodash-es';import {getMenus}from'../route/old/get-menus.js';import'@wordpress/hooks';import'../plugin-area/plugin-context.js';import {getPlugin,registerPlugin,getPlugins}from'../plugin-area/plugin-api.js';import'sort-keys';import {combine}from'../utils/combine.js';import {hydrate}from'../utils/hydrate.js';import {beforeSSR}from'../utils/before-ssr.js';const getFirst = (features, extractor) => extractor(find(features, (res) => extractor(res)) || {});
|
|
1
|
+
import*as React from'react';import {AbstractFeature}from'@common-stack/client-core';import {sortBy,find}from'lodash-es';import {routesConfiguration}from'virtual:routes-configuration';import {getMenus}from'../route/old/get-menus.js';import'@wordpress/hooks';import'../plugin-area/plugin-context.js';import {getPlugin,registerPlugin,getPlugins}from'../plugin-area/plugin-api.js';import'sort-keys';import {combine}from'../utils/combine.js';import {hydrate}from'../utils/hydrate.js';import {beforeSSR}from'../utils/before-ssr.js';const getFirst = (features, extractor) => extractor(find(features, (res) => extractor(res)) || {});
|
|
2
2
|
class BaseFeature extends AbstractFeature {
|
|
3
3
|
constructor(feature,
|
|
4
4
|
// tslint:disable:trailing-comma
|
|
@@ -66,7 +66,7 @@ class BaseFeature extends AbstractFeature {
|
|
|
66
66
|
return this.getSortedRoutes(searchPath, Object.assign({}, ...this.routeConfig), this.authWrapper);
|
|
67
67
|
}
|
|
68
68
|
getConfiguredRoutes2(searchPath = '/') {
|
|
69
|
-
return
|
|
69
|
+
return routesConfiguration;
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* get configured menus.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-connector.js","sources":["../../src/connector/base-connector.tsx"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base-connector.js","sources":["../../src/connector/base-connector.tsx"],"sourcesContent":[null],"names":[],"mappings":"8gBAUA,MAAM,QAAQ,GAAG,CAAC,QAAQ,EAAE,SAAS,KAAK,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,GAAG,KAAK,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AAG7F,MAAgB,WAAY,SAAQ,eAAe,CAAA;AAcrD,IAAA,WAAA,CACI,OAAsB;;AAEtB,IAAA,GAAG,QAAwB,EAAA;AAE3B,QAAA,KAAK,CAAC,OAAO,EAAE,GAAG,QAAQ,CAAC,CAAC;AA2IxB,QAAA,IAAA,CAAA,mBAAmB,GAAG,CAAC,KAAK,KAAI;AACpC,YAAA,OAAO,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,KAAK,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC;AAC9D,SAAC,CAAA;AAEO,QAAA,IAAA,CAA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C,CAAC;AAC1E,SAAA;AACD,QAAA,OAAO,UAAU,CAAC;KACrB;AAEM,IAAA,WAAW,CAAC,IAAI,EAAA;QACnB,IAAI,UAAU,GAAG,IAAI,CAAC;AACtB,QAAA,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,iBAAiB,EAAE;YAC5C,UAAU,GAAG,KAAK,CAAC,aAAa,CAAC,SAAS,EAAE,EAAE,EAAE,UAAU,CAAC,CAAC;AAC/D,SAAA;AACD,QAAA,OAAO,UAAU,CAAC;KACrB;AAEM,IAAA,iBAAiB,CAAC,MAAM,EAAA;AAC3B,QAAA,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,cAAc,EAAE;YACpC,IAAI,CAAC,MAAM,CAAC,CAAC;AAChB,SAAA;KACJ;AAEO,IAAA,4BAA4B,CAAC,OAAO,EAAA;AACxC,QAAA,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,KAAI;AAClB,YAAA,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;YACnB,MAAM,OAAO,GAAG,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YAClC,IAAI,CAAC,OAAO,EAAE;AACV,gBAAA,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AAC3B,aAAA;AACL,SAAC,CAAC,CAAC;AACH,QAAA,OAAO,OAAO,CAAC;KAClB;IAEM,uBAAuB,GAAA;QAC1B,OAAO,UAAU,EAAE,CAAC;KACvB;AAqBJ"}
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { IReactFeature } from '../interfaces';
|
|
2
2
|
import { BaseFeature } from './base-connector';
|
|
3
3
|
export declare class Feature extends BaseFeature implements IReactFeature {
|
|
4
|
-
protected renderRoutes: (
|
|
4
|
+
protected renderRoutes: (arg1: any, arg2: any) => import("react").JSX.Element;
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated: use `renderRoutes`
|
|
7
|
+
* @param arg1
|
|
8
|
+
* @param arg2
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
5
11
|
protected renderRoutes2: (arg1: any, arg2: any) => import("react").JSX.Element;
|
|
6
|
-
protected getSortedRoutes: (path: string, routeData: import("../interfaces").IRouteData, authWrapper?: (
|
|
12
|
+
protected getSortedRoutes: (path: string, routeData: import("../interfaces").IRouteData, authWrapper?: (component: import("react").FC<{}>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>) => any;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated use getSortedRoutes
|
|
15
|
+
*/
|
|
7
16
|
protected getSortedRoutes2: (path: string, routeData: import("../interfaces").IRouteData, authWrapper?: (component: import("react").FC<{}>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>) => any;
|
|
8
17
|
}
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
import {BaseFeature}from'./base-connector.js';import
|
|
1
|
+
import {BaseFeature}from'./base-connector.js';import resolveRootRoute from'../route/react-navigation/react-navigation-render.js';import {getSortedNavigations}from'../route/react-navigation/get-navigation-utils.js';class Feature extends BaseFeature {
|
|
2
2
|
constructor() {
|
|
3
3
|
super(...arguments);
|
|
4
|
-
this.renderRoutes = (
|
|
4
|
+
this.renderRoutes = (arg1, arg2) => resolveRootRoute(arg1[0], arg2);
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated: use `renderRoutes`
|
|
7
|
+
* @param arg1
|
|
8
|
+
* @param arg2
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
5
11
|
this.renderRoutes2 = (arg1, arg2) => resolveRootRoute(arg1[0], arg2);
|
|
6
|
-
this.getSortedRoutes =
|
|
12
|
+
this.getSortedRoutes = getSortedNavigations;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated use getSortedRoutes
|
|
15
|
+
*/
|
|
7
16
|
this.getSortedRoutes2 = getSortedNavigations;
|
|
8
17
|
}
|
|
9
18
|
}export{Feature};//# sourceMappingURL=connector.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connector.native.js","sources":["../../src/connector/connector.native.tsx"],"sourcesContent":[null],"names":["renderNavigation"],"mappings":"
|
|
1
|
+
{"version":3,"file":"connector.native.js","sources":["../../src/connector/connector.native.tsx"],"sourcesContent":[null],"names":["renderNavigation"],"mappings":"sNAKM,MAAO,OAAQ,SAAQ,WAAW,CAAA;AAAxC,IAAA,WAAA,GAAA;;AACc,QAAA,IAAA,CAAA,YAAY,GAAG,CAAC,IAAI,EAAE,IAAI,KAAKA,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;AACzE;;;;;AAKG;AACO,QAAA,IAAA,CAAA,aAAa,GAAG,CAAC,IAAI,EAAE,IAAI,KAAKA,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;QAChE,IAAe,CAAA,eAAA,GAAG,oBAAoB,CAAC;AACjD;;AAEG;QACO,IAAgB,CAAA,gBAAA,GAAG,oBAAoB,CAAC;KACrD;AAAA"}
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{ClientTypes}from'@common-stack/client-core';export{Feature}from'./connector/connector.js';export{FeatureWithRouterFactory}from'./router-factory/index.js';export{renderRoutes2}from'./route/render-routes.js';import'react';export{getNavigation,getSortedNavigations}from'./route/react-navigation/get-navigation-utils.js';export{navigate,navigationRef}from'./route/root-navigation.js';export{sortByPaths,sortKeys}from'./utils/sort-keys.js';export{formatSlash}from'./utils/utils.js';export{combine}from'./utils/combine.js';export{hydrate}from'./utils/hydrate.js';export{beforeSSR}from'./utils/before-ssr.js';export{IMenuPosition}from'./interfaces/menu.js';export{PluginArea}from'./plugin-area/index.js';export{RouteBasedPluginArea}from'./route-based-plugin-area/route-based-plugin-area.js';export{getRouteBasePlugin,getRouteBasePlugins,registerRouteBasePlugin,unregisterRouteBasePlugin}from'./route-based-plugin-area/plugin-api.js';export{InversifyContext,InversifyProvider,useInjection}from'./inversify/InversifyContext.js';export{getPlugin,getPlugins,registerPlugin,unregisterPlugin}from'./plugin-area/plugin-api.js';//# sourceMappingURL=index.js.map
|
|
1
|
+
export{ClientTypes}from'@common-stack/client-core';export{Feature}from'./connector/connector.js';export{FeatureWithRouterFactory}from'./router-factory/index.js';export{renderRoutes2}from'./route/render-routes.js';import'react';export{getNavigation,getSortedNavigations}from'./route/react-navigation/get-navigation-utils.js';export{navigate,navigationRef}from'./route/root-navigation.js';export{sortByPaths,sortKeys}from'./utils/sort-keys.js';export{formatSlash}from'./utils/utils.js';export{combine}from'./utils/combine.js';export{hydrate}from'./utils/hydrate.js';export{beforeSSR}from'./utils/before-ssr.js';export{getFilteredMenus,getFilteredRoutes,getFilteredTabs}from'./utils/filteredRoutes.js';export{IMenuPosition}from'./interfaces/menu.js';export{PluginArea}from'./plugin-area/index.js';export{RouteBasedPluginArea}from'./route-based-plugin-area/route-based-plugin-area.js';export{getRouteBasePlugin,getRouteBasePlugins,registerRouteBasePlugin,unregisterRouteBasePlugin}from'./route-based-plugin-area/plugin-api.js';export{InversifyContext,InversifyProvider,useInjection}from'./inversify/InversifyContext.js';export{getPlugin,getPlugins,registerPlugin,unregisterPlugin}from'./plugin-area/plugin-api.js';//# sourceMappingURL=index.js.map
|
package/lib/index.native.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { ClientTypes } from '@common-stack/client-core';
|
|
2
2
|
export * from './connector/connector.native';
|
|
3
3
|
export * from './router-factory/index.native';
|
|
4
|
-
export * from './route/index.native';
|
|
5
4
|
export * from './route/react-navigation/root-navigation';
|
|
6
5
|
export * from './utils';
|
|
7
6
|
export * from './interfaces';
|
package/lib/index.native.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{ClientTypes}from'@common-stack/client-core';export{Feature}from'./connector/connector.native.js';export{FeatureWithRouterFactory}from'./router-factory/index.native.js';export{
|
|
1
|
+
export{ClientTypes}from'@common-stack/client-core';export{Feature}from'./connector/connector.native.js';export{FeatureWithRouterFactory}from'./router-factory/index.native.js';export{navigate,navigationRef}from'./route/react-navigation/root-navigation.js';export{sortByPaths,sortKeys}from'./utils/sort-keys.js';export{formatSlash}from'./utils/utils.js';export{combine}from'./utils/combine.js';export{hydrate}from'./utils/hydrate.js';export{beforeSSR}from'./utils/before-ssr.js';export{getFilteredMenus,getFilteredRoutes,getFilteredTabs}from'./utils/filteredRoutes.js';export{IMenuPosition}from'./interfaces/menu.js';export{PluginArea}from'./plugin-area/index.native.js';export{RouteBasedPluginArea}from'./route-based-plugin-area/route-based-plugin-area.js';export{getRouteBasePlugin,getRouteBasePlugins,registerRouteBasePlugin,unregisterRouteBasePlugin}from'./route-based-plugin-area/plugin-api.js';export{InversifyContext,InversifyProvider,useInjection}from'./inversify/InversifyContext.js';export{getPlugin,getPlugins,registerPlugin,unregisterPlugin}from'./plugin-area/plugin-api.js';//# sourceMappingURL=index.native.js.map
|
package/lib/route/get-routes.js
CHANGED
|
@@ -1,67 +1,102 @@
|
|
|
1
|
-
import {IMenuPosition}from'../interfaces/menu.js';import {sortKeys}from'../utils/sort-keys.js';import {formatSlash}from'../utils/utils.js'
|
|
1
|
+
import {IMenuPosition}from'../interfaces/menu.js';import {sortKeys}from'../utils/sort-keys.js';import {formatSlash}from'../utils/utils.js';// Function to get sorted routes based on a given path, route data, and an optional authentication wrapper.
|
|
2
|
+
const getSortedRoutes = (path, routeData, authWrapper = null) => {
|
|
3
|
+
// Sort the keys of the route data for consistency.
|
|
2
4
|
const sortedRoutes = sortKeys(routeData);
|
|
5
|
+
// Pass the sorted route data to getRoutes function.
|
|
3
6
|
return getRoutes(path, sortedRoutes, authWrapper);
|
|
4
7
|
};
|
|
8
|
+
// Function to process and return routes based on the given path, route data, and auth wrapper.
|
|
5
9
|
function getRoutes(path, routeData, authWrapper = null) {
|
|
10
|
+
// Ensure the provided path starts with a '/'.
|
|
6
11
|
if (!path.startsWith('/')) {
|
|
7
12
|
throw new Error('Invalid path!');
|
|
8
13
|
}
|
|
14
|
+
// Normalize the path to ensure it ends with '/' for consistent matching.
|
|
9
15
|
let searchPath = path;
|
|
10
16
|
if (path[path.length - 1] !== '/') {
|
|
11
17
|
searchPath = path + '/';
|
|
12
18
|
}
|
|
13
|
-
|
|
19
|
+
// Filter the routes from the routeData based on the search path or exact path match.
|
|
20
|
+
const routes = Object.keys(routeData).filter((menuPath) => {
|
|
14
21
|
return menuPath.indexOf(searchPath) === 0 || menuPath === path;
|
|
15
22
|
});
|
|
16
|
-
|
|
23
|
+
// Map the filtered routes to include additional properties and merge with routeData.
|
|
24
|
+
const mappedMenuPaths = routes.map((mPath) => {
|
|
17
25
|
return {
|
|
18
26
|
route: mPath,
|
|
19
27
|
position: IMenuPosition.Middle,
|
|
20
28
|
...routeData[mPath],
|
|
21
29
|
};
|
|
22
30
|
});
|
|
31
|
+
// Initialize the root route object with a placeholder name and position.
|
|
23
32
|
const root = {
|
|
24
33
|
// just to satisfy types added following
|
|
25
34
|
// TOOD need to correct types so we don't have to enter them.
|
|
26
35
|
name: 'root',
|
|
27
36
|
position: IMenuPosition.Logo,
|
|
28
37
|
};
|
|
29
|
-
|
|
38
|
+
// Iterate over the mapped routes to build the nested route structure.
|
|
39
|
+
mappedMenuPaths.forEach((routeItem) => {
|
|
40
|
+
// Split the route path to process each segment.
|
|
30
41
|
const children = routeItem.route.split('/');
|
|
31
|
-
children.shift();
|
|
32
|
-
//
|
|
42
|
+
children.shift(); // Remove the first empty element from splitting.
|
|
43
|
+
// Special case handling for the root ('/') route.
|
|
33
44
|
if (routeItem.path === '/') {
|
|
34
|
-
children.shift();
|
|
35
|
-
children.push('/');
|
|
45
|
+
children.shift(); // Adjust for root path.
|
|
46
|
+
children.push('/'); // Ensure the array reflects the root path.
|
|
36
47
|
}
|
|
48
|
+
// Determine the depth of the current route for nested routing.
|
|
37
49
|
const depth = children.length;
|
|
38
|
-
let lastNode = root;
|
|
50
|
+
let lastNode = root; // Start building from the root.
|
|
51
|
+
// Iterate through each segment to find or create nested route nodes.
|
|
39
52
|
for (let i = 0; i < depth; i++) {
|
|
40
|
-
const lastIndex = (lastNode.routes || []).findIndex(item => {
|
|
53
|
+
const lastIndex = (lastNode.routes || []).findIndex((item) => {
|
|
41
54
|
const routePath = `${item._pathPrefix}${item.path}`;
|
|
42
55
|
if (routeItem.route.startsWith(routePath)) {
|
|
43
|
-
//
|
|
56
|
+
// Check if the route starts with the path prefix and if nested routing is allowed.
|
|
44
57
|
return routeItem.route[routePath.length] === '/' && routeData[routePath]?.exact === false;
|
|
45
58
|
}
|
|
46
59
|
});
|
|
60
|
+
// Break the loop if no further nested route is found.
|
|
47
61
|
if (lastIndex === -1) {
|
|
48
62
|
break;
|
|
49
63
|
}
|
|
64
|
+
// Navigate to the last found nested route.
|
|
50
65
|
lastNode = lastNode.routes[lastIndex];
|
|
51
66
|
// const lastNodePath = `${(lastNode as any)._pathPrefix}${lastNode.path}`;
|
|
52
67
|
// lastNode.exact = routeData[lastNodePath].hasOwnProperty('exact') ? routeData[lastNodePath].exact : false;
|
|
53
68
|
}
|
|
69
|
+
// Ensure the last node has a routes array to push into.
|
|
54
70
|
if (!lastNode.routes) {
|
|
55
71
|
lastNode.routes = [];
|
|
56
72
|
}
|
|
73
|
+
// Extract relevant properties to construct the final route object.
|
|
57
74
|
const { route: ignore, auth, ...rest } = routeItem;
|
|
58
75
|
const pathParams = formatSlash(routeItem.route);
|
|
76
|
+
// Determine the parent path for the current route
|
|
77
|
+
// Attempt to construct parentPath more defensively
|
|
78
|
+
let parentPath;
|
|
79
|
+
if (lastNode && lastNode !== root) {
|
|
80
|
+
// Ensure lastNode is not the root and is defined
|
|
81
|
+
parentPath = '';
|
|
82
|
+
if (lastNode._pathPrefix) {
|
|
83
|
+
parentPath += lastNode._pathPrefix;
|
|
84
|
+
}
|
|
85
|
+
if (lastNode.path) {
|
|
86
|
+
parentPath += lastNode.path;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const relativePath = routeItem.route.replace(new RegExp(`^${parentPath}/?`), '');
|
|
59
90
|
lastNode.routes.push({
|
|
60
91
|
...rest,
|
|
61
92
|
// path: formatSlash(routeItem.route),
|
|
62
93
|
// path: routeItem.route,
|
|
63
94
|
...pathParams,
|
|
95
|
+
relativePath,
|
|
96
|
+
auth: auth,
|
|
64
97
|
exact: routeData[routeItem.route].hasOwnProperty('exact') ? routeData[routeItem.route].exact : true,
|
|
98
|
+
// ...(parentPath !== '/' && { parentPath }),
|
|
99
|
+
parentPath,
|
|
65
100
|
/**
|
|
66
101
|
* Here we are checking whether auth property is being
|
|
67
102
|
* set by this route and if authWrapper is declared
|
|
@@ -69,9 +104,7 @@ function getRoutes(path, routeData, authWrapper = null) {
|
|
|
69
104
|
* and its props as argument then perform some
|
|
70
105
|
* computation and return a component
|
|
71
106
|
*/
|
|
72
|
-
component: auth && authWrapper
|
|
73
|
-
? (props) => authWrapper(routeItem.component, props)
|
|
74
|
-
: routeItem.component
|
|
107
|
+
component: auth && authWrapper ? (props) => authWrapper(routeItem.component, props) : routeItem.component,
|
|
75
108
|
});
|
|
76
109
|
});
|
|
77
110
|
return root.routes;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-routes.js","sources":["../../src/route/get-routes.tsx"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-routes.js","sources":["../../src/route/get-routes.tsx"],"sourcesContent":[null],"names":[],"mappings":"2IAKA;AACO,MAAM,eAAe,GAAG,CAC3B,IAAY,EACZ,SAAqB,EACrB,WAAA,GAA6E,IAAI,KACjF;;AAEA,IAAA,MAAM,YAAY,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;;IAEzC,OAAO,SAAS,CAAC,IAAI,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;AACtD,EAAE;AAEF;AACM,SAAU,SAAS,CAAC,IAAY,EAAE,SAAqB,EAAE,cAAoC,IAAI,EAAA;;AAEnG,IAAA,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;AAC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AQ,CAAC,IAAI,EAAE;AACf,gBAAA,UAAU,IAAI,QAAQ,CAAC,IAAI,CAAC;AAC/B,aAAA;AACJ,SAAA;AACD,QAAA,MAAM,YAAY,GAAG,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,IAAI,UAAU,CAAA,EAAA,CAAI,CAAC,EAAE,EAAE,CAAC,CAAC;AAEjF,QAAA,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;AACjB,YAAA,GAAG,IAAI;;;AAGP,YAAA,GAAG,UAAU;YACb,YAAY;AACZ,YAAA,IAAI,EAAE,IAAI;YACV,KAAK,EAAE,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,IAAI;;YAEnG,UAAU;AACV;;;;;;AAMG;YACH,SAAS,EAAE,IAAI,IAAI,WAAW,GAAG,CAAC,KAAK,KAAK,WAAW,CAAC,SAAS,CAAC,SAAS,EAAE,KAAK,CAAC,GAAG,SAAS,CAAC,SAAS;AAC5G,SAAA,CAAC,CAAC;AACP,KAAC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC,MAAM,CAAC;AACvB"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const getFilteredMenus: (accountPageStore: any, selectedMenu?: string) => any;
|
|
2
|
+
export declare const getFilteredRoutes: (accountPageStore: any, selectedRoutes?: string) => any;
|
|
3
|
+
export declare const getFilteredTabs: (accountPageStore: any, selectedTabs?: string) => any;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const getFilteredMenus = (accountPageStore, selectedMenu = '*') => accountPageStore
|
|
2
|
+
.map((item) => {
|
|
3
|
+
if (selectedMenu === '*' || selectedMenu.includes(item.key)) {
|
|
4
|
+
const { path, component, ...rest } = item;
|
|
5
|
+
return {
|
|
6
|
+
[path]: { name: rest.tab, ...rest },
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
return null;
|
|
10
|
+
})
|
|
11
|
+
.filter((valid) => valid);
|
|
12
|
+
const getFilteredRoutes = (accountPageStore, selectedRoutes = '*') => accountPageStore
|
|
13
|
+
.map((item) => {
|
|
14
|
+
if (selectedRoutes === '*' || selectedRoutes.includes(item.key)) {
|
|
15
|
+
const { path } = item;
|
|
16
|
+
return {
|
|
17
|
+
[path]: item,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
})
|
|
22
|
+
.filter((valid) => valid);
|
|
23
|
+
const getFilteredTabs = (accountPageStore, selectedTabs = '*') => accountPageStore
|
|
24
|
+
.map((item) => {
|
|
25
|
+
if (selectedTabs === '*' || selectedTabs.includes(item.key)) {
|
|
26
|
+
const { component, ...rest } = item;
|
|
27
|
+
return rest;
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
})
|
|
31
|
+
.filter((valid) => valid);export{getFilteredMenus,getFilteredRoutes,getFilteredTabs};//# sourceMappingURL=filteredRoutes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filteredRoutes.js","sources":["../../src/utils/filteredRoutes.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAO,MAAM,gBAAgB,GAAG,CAAC,gBAAgB,EAAE,YAAY,GAAG,GAAG,KACnE,gBAAgB;AACb,KAAA,GAAG,CAAC,CAAC,IAAI,KAAI;AACZ,IAAA,IAAI,YAAY,KAAK,GAAG,IAAI,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QAC3D,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;QAC1C,OAAO;AACL,YAAA,CAAC,IAAI,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE;SACpC,CAAC;AACH,KAAA;AACD,IAAA,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;KACD,MAAM,CAAC,CAAC,KAAK,KAAK,KAAK,EAAE;AAEvB,MAAM,iBAAiB,GAAG,CAAC,gBAAgB,EAAE,cAAc,GAAG,GAAG,KACtE,gBAAgB;AACb,KAAA,GAAG,CAAC,CAAC,IAAI,KAAI;AACZ,IAAA,IAAI,cAAc,KAAK,GAAG,IAAI,cAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;AAC/D,QAAA,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;QACtB,OAAO;YACL,CAAC,IAAI,GAAG,IAAI;SACb,CAAC;AACH,KAAA;AACD,IAAA,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;KACD,MAAM,CAAC,CAAC,KAAK,KAAK,KAAK,EAAE;AAEvB,MAAM,eAAe,GAAG,CAAC,gBAAgB,EAAE,YAAY,GAAG,GAAG,KAClE,gBAAgB;AACb,KAAA,GAAG,CAAC,CAAC,IAAI,KAAI;AACZ,IAAA,IAAI,YAAY,KAAK,GAAG,IAAI,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QAC3D,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;AACpC,QAAA,OAAO,IAAI,CAAC;AACb,KAAA;AACD,IAAA,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;KACD,MAAM,CAAC,CAAC,KAAK,KAAK,KAAK"}
|
package/lib/utils/index.d.ts
CHANGED
package/lib/utils/sort-keys.js
CHANGED
|
@@ -5,14 +5,14 @@ function sortByPaths(routes) {
|
|
|
5
5
|
const routeData = {};
|
|
6
6
|
routes.forEach((route) => {
|
|
7
7
|
if (typeof route.path === 'undefined') {
|
|
8
|
-
route.path =
|
|
8
|
+
route.path = '*';
|
|
9
9
|
}
|
|
10
10
|
routeData[route.path] = route;
|
|
11
11
|
});
|
|
12
12
|
const sortedRoutes = defaultSortKeys(routeData, { compare });
|
|
13
|
-
return Object.keys(sortedRoutes).map(key => sortedRoutes[key]);
|
|
13
|
+
return Object.keys(sortedRoutes).map((key) => sortedRoutes[key]);
|
|
14
14
|
}
|
|
15
|
-
const compare = (
|
|
15
|
+
const compare = (a, b) => {
|
|
16
16
|
const aStr = String(a).toLowerCase();
|
|
17
17
|
const bStr = String(b).toLowerCase();
|
|
18
18
|
// Alphanumeric elements always come before non-alphanumeric elements
|
|
@@ -28,7 +28,7 @@ const compare = ((a, b) => {
|
|
|
28
28
|
if (aIsAlphanumeric > 0) {
|
|
29
29
|
return -1;
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
if (bIsAlphanumeric > 0) {
|
|
32
32
|
return 1;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -40,38 +40,39 @@ const compare = ((a, b) => {
|
|
|
40
40
|
return aNum - bNum;
|
|
41
41
|
// If a is numerical but b isn't, put a first.
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
if (aNum) {
|
|
44
44
|
return -1;
|
|
45
45
|
// If b is numerical but a isn't, put b first.
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
if (bNum) {
|
|
48
48
|
return 1;
|
|
49
49
|
}
|
|
50
50
|
// In all other cases, default to usual sort order.
|
|
51
51
|
return aStr.localeCompare(bStr);
|
|
52
|
-
}
|
|
52
|
+
};
|
|
53
53
|
function notStartWithColon(str) {
|
|
54
54
|
const match = (str.match(/^[\/, *, :]{1,}/) || [-1])[0];
|
|
55
55
|
if (match === -1) {
|
|
56
56
|
return -1;
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
let i = match.length;
|
|
59
59
|
let count = 0;
|
|
60
60
|
while (i--) {
|
|
61
61
|
const char = match[i];
|
|
62
62
|
if (char === '/') {
|
|
63
|
-
if (str === '/') {
|
|
64
|
-
|
|
63
|
+
if (str === '/') {
|
|
64
|
+
// if it is root only we put at the last
|
|
65
|
+
count += 6;
|
|
65
66
|
}
|
|
66
67
|
else {
|
|
67
|
-
count
|
|
68
|
+
count += 3;
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
else if (char === ':') {
|
|
71
|
-
count
|
|
72
|
+
count += 1;
|
|
72
73
|
}
|
|
73
74
|
else if (char === '*') {
|
|
74
|
-
count
|
|
75
|
+
count += 2;
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
return count;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sort-keys.js","sources":["../../src/utils/sort-keys.ts"],"sourcesContent":[null],"names":[],"mappings":"uCAEM,SAAU,QAAQ,CAAC,SAAS,EAAA;
|
|
1
|
+
{"version":3,"file":"sort-keys.js","sources":["../../src/utils/sort-keys.ts"],"sourcesContent":[null],"names":[],"mappings":"uCAEM,SAAU,QAAQ,CAAC,SAAS,EAAA;IAC9B,OAAO,eAAe,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;AACnD,CAAC;AAEK,SAAU,WAAW,CAAC,MAAM,EAAA;IAC9B,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,IAAA,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,KAAI;AACrB,QAAA,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,WAAW,EAAE;AACnC,YAAA,KAAK,CAAC,IAAI,GAAG,GAAG,CAAC;AACpB,SAAA;AACD,QAAA,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;AAClC,KAAC,CAAC,CAAC;IACH,MAAM,YAAY,GAAG,eAAe,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;AAC7D,IAAA,OAAO,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;AACrE,CAAC;AAED,MAAM,OAAO,GAAG,CAAC,CAAC,EAAE,CAAC,KAAI;IACrB,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CA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CAAC;AACxD,IAAA,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;QACd,OAAO,CAAC,CAAC,CAAC;AACb,KAAA;AACD,IAAA,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC;IACrB,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,OAAO,CAAC,EAAE,EAAE;AACR,QAAA,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,IAAI,KAAK,GAAG,EAAE;YACd,IAAI,GAAG,KAAK,GAAG,EAAE;;gBAEb,KAAK,IAAI,CAAC,CAAC;AACd,aAAA;AAAM,iBAAA;gBACH,KAAK,IAAI,CAAC,CAAC;AACd,aAAA;AACJ,SAAA;aAAM,IAAI,IAAI,KAAK,GAAG,EAAE;YACrB,KAAK,IAAI,CAAC,CAAC;AACd,SAAA;aAAM,IAAI,IAAI,KAAK,GAAG,EAAE;YACrB,KAAK,IAAI,CAAC,CAAC;AACd,SAAA;AACJ,KAAA;AACD,IAAA,OAAO,KAAK,CAAC;AACjB"}
|
package/lib/utils/utils.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
const startWithMoreThanOneSlash = /^(\/)\1+/; // for exame `//abc, ///abc, ...`
|
|
2
|
-
const formatSlash = (route) =>
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};export{formatSlash};//# sourceMappingURL=utils.js.map
|
|
2
|
+
const formatSlash = (route) =>
|
|
3
|
+
// replaced `//` with `/` in the routes.
|
|
4
|
+
({
|
|
5
|
+
path: route.replace(startWithMoreThanOneSlash, '/'),
|
|
6
|
+
_pathPrefix: (route.match(/^\/(\/{1,})/) || ['', ''])[1],
|
|
7
|
+
});export{formatSlash};//# sourceMappingURL=utils.js.map
|
package/lib/utils/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../src/utils/utils.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/utils/utils.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA,MAAM,yBAAyB,GAAG,UAAU,CAAC;AAChC,MAAA,WAAW,GAAG,CAAC,KAAK;AAC7B;AACA,CAAC;IACG,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,yBAAyB,EAAE,GAAG,CAAC;AACnD,IAAA,WAAW,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;AAC3D,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@common-stack/client-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1-alpha.0",
|
|
4
4
|
"description": "Client Module for react app",
|
|
5
5
|
"homepage": "https://github.com/cdmbase/fullstack-pro#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"watch": "npm run build:lib:watch"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@common-stack/client-core": "
|
|
34
|
-
"@common-stack/core": "
|
|
33
|
+
"@common-stack/client-core": "4.0.1-alpha.0",
|
|
34
|
+
"@common-stack/core": "4.0.1-alpha.0",
|
|
35
35
|
"@wordpress/hooks": "^3.53.0",
|
|
36
36
|
"browser-bunyan": "^1.6.3",
|
|
37
37
|
"history-with-query": "^4.10.4",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "d2631ce11c2e00c523f29182bc7817601edc5733",
|
|
55
55
|
"typescript": {
|
|
56
56
|
"definition": "lib/index.d.ts"
|
|
57
57
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './render-routes-native';
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import*as React from'react';import {Routes,Route,Navigate}from'react-router-native';function render({ route, opts, props }) {
|
|
2
|
-
const routes = renderRoutes({
|
|
3
|
-
...opts,
|
|
4
|
-
routes: route.routes || [],
|
|
5
|
-
rootRoutes: opts.rootRoutes,
|
|
6
|
-
});
|
|
7
|
-
const { component: Component, wrappers } = route;
|
|
8
|
-
if (Component) {
|
|
9
|
-
const defaultPageInitialProps = opts.isServer ? {} : window.g_initialProps;
|
|
10
|
-
const newProps = {
|
|
11
|
-
...props,
|
|
12
|
-
...opts.extraProps,
|
|
13
|
-
...(opts.pageInitialProps || defaultPageInitialProps),
|
|
14
|
-
route,
|
|
15
|
-
routes: opts.rootRoutes,
|
|
16
|
-
};
|
|
17
|
-
let element = React.createElement(Component, { ...newProps }, routes);
|
|
18
|
-
if (wrappers) {
|
|
19
|
-
element = wrappers.reduceRight((acc, Wrapper) => {
|
|
20
|
-
return React.createElement(Wrapper, { ...newProps }, acc);
|
|
21
|
-
}, element);
|
|
22
|
-
}
|
|
23
|
-
return element;
|
|
24
|
-
}
|
|
25
|
-
return routes;
|
|
26
|
-
}
|
|
27
|
-
function getRouteElement({ route, index, opts }) {
|
|
28
|
-
({
|
|
29
|
-
key: route.key || index,
|
|
30
|
-
exact: route.exact,
|
|
31
|
-
strict: route.strict,
|
|
32
|
-
sensitive: route.sensitive,
|
|
33
|
-
path: route.path,
|
|
34
|
-
});
|
|
35
|
-
if (route.redirect) {
|
|
36
|
-
return React.createElement(Route, { key: route.key || index, path: route.path, element: React.createElement(Navigate, { to: route.redirect, replace: true }) });
|
|
37
|
-
}
|
|
38
|
-
// avoid mount and unmount with url hash change
|
|
39
|
-
// @sri not supproted yet
|
|
40
|
-
// if (
|
|
41
|
-
// // only when SSR config enable
|
|
42
|
-
// opts.ssrProps &&
|
|
43
|
-
// !opts.isServer &&
|
|
44
|
-
// // make sure loaded once
|
|
45
|
-
// !(route.component as any)?.wrapInitialPropsLoaded &&
|
|
46
|
-
// (route.component?.getInitialProps || route.component?.preload)
|
|
47
|
-
// ) {
|
|
48
|
-
// // client Render for enable ssr, but not sure SSR success
|
|
49
|
-
// route.component = wrapInitialPropsFetch(route, opts);
|
|
50
|
-
// }
|
|
51
|
-
return (React.createElement(Route, { key: route.key || index, path: route.path, element: React.createElement(RouteElementWrapper, { route: route, render: render, opts: opts }) }));
|
|
52
|
-
}
|
|
53
|
-
function RouteElementWrapper({ route, render, opts }) {
|
|
54
|
-
const element = render({ route, opts, props: {} });
|
|
55
|
-
return React.createElement(React.Fragment, null, element);
|
|
56
|
-
}
|
|
57
|
-
function renderRoutes(opts) {
|
|
58
|
-
return opts.routes ? (React.createElement(Routes, null, opts.routes.map((route, index) => {
|
|
59
|
-
return getRouteElement({
|
|
60
|
-
route,
|
|
61
|
-
index,
|
|
62
|
-
opts: {
|
|
63
|
-
...opts,
|
|
64
|
-
rootRoutes: opts.rootRoutes || opts.routes,
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
}))) : null;
|
|
68
|
-
}export{renderRoutes};//# sourceMappingURL=render-routes-native.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"render-routes-native.js","sources":["../../src/route/render-routes-native.tsx"],"sourcesContent":[null],"names":[],"mappings":"oFA+DA,SAAS,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAA+D,EAAA;IACjG,MAAM,MAAM,GAAG,YAAY,CAAC;AAC1B,QAAA,GAAG,IAAI;AACP,QAAA,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,EAAE;QAC1B,UAAU,EAAE,IAAI,CAAC,UAAU;AAC5B,KAAA,CAAC,CAAC;IACH,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;AAEjD,IAAA,IAAI,SAAS,EAAE;AACb,QAAA,MAAM,uBAAuB,GAAG,IAAI,CAAC,QAAQ,GAAG,EAAE,GAAI,MAAc,CAA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