@common-stack/client-react 0.1.23 → 0.2.2

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.
Files changed (153) hide show
  1. package/lib/__tests__/fill-register-test.d.ts +1 -0
  2. package/lib/__tests__/fill-register-test.js +66 -0
  3. package/lib/__tests__/fill-register-test.js.map +1 -0
  4. package/lib/__tests__/helpers/sample-menu.d.ts +79 -0
  5. package/lib/__tests__/helpers/sample-menu.js +78 -0
  6. package/lib/__tests__/helpers/sample-menu.js.map +1 -0
  7. package/lib/__tests__/integrated-routes.test.d.ts +1 -0
  8. package/lib/__tests__/integrated-routes.test.js +83 -0
  9. package/lib/__tests__/integrated-routes.test.js.map +1 -0
  10. package/lib/__tests__/render-routes.test.d.ts +3 -0
  11. package/lib/__tests__/render-routes.test.js +89 -0
  12. package/lib/__tests__/render-routes.test.js.map +1 -0
  13. package/lib/connector/base-connector.d.ts +52 -0
  14. package/lib/connector/base-connector.js +148 -0
  15. package/lib/connector/base-connector.js.map +1 -0
  16. package/lib/connector/connector.d.ts +7 -43
  17. package/lib/connector/connector.js +15 -0
  18. package/lib/connector/connector.js.map +1 -0
  19. package/lib/connector/connector.native.d.ts +7 -0
  20. package/lib/connector/connector.native.js +14 -0
  21. package/lib/connector/connector.native.js.map +1 -0
  22. package/lib/connector/connector.test.d.ts +1 -0
  23. package/lib/connector/connector.test.js +32 -0
  24. package/lib/connector/connector.test.js.map +1 -0
  25. package/lib/connector/index.js +14 -0
  26. package/lib/connector/index.js.map +1 -0
  27. package/lib/index.d.ts +1 -1
  28. package/lib/index.js +9 -1722
  29. package/lib/index.js.map +1 -1
  30. package/lib/index.native.d.ts +9 -0
  31. package/lib/index.native.js +24 -0
  32. package/lib/index.native.js.map +1 -0
  33. package/lib/interfaces/extended-feature.js +3 -0
  34. package/lib/interfaces/extended-feature.js.map +1 -0
  35. package/lib/interfaces/index.js +17 -0
  36. package/lib/interfaces/index.js.map +1 -0
  37. package/lib/interfaces/menu.js +12 -0
  38. package/lib/interfaces/menu.js.map +1 -0
  39. package/lib/interfaces/new-router.d.ts +18 -1
  40. package/lib/interfaces/new-router.js +3 -0
  41. package/lib/interfaces/new-router.js.map +1 -0
  42. package/lib/interfaces/router.js +3 -0
  43. package/lib/interfaces/router.js.map +1 -0
  44. package/lib/inversify/InversifyContext.js +37 -0
  45. package/lib/inversify/InversifyContext.js.map +1 -0
  46. package/lib/inversify/index.js +14 -0
  47. package/lib/inversify/index.js.map +1 -0
  48. package/lib/plugin-area/__tests__/higher-order-component-util.test.d.ts +1 -0
  49. package/lib/plugin-area/__tests__/higher-order-component-util.test.js +60 -0
  50. package/lib/plugin-area/__tests__/higher-order-component-util.test.js.map +1 -0
  51. package/lib/plugin-area/__tests__/plugin-api.test.d.ts +1 -0
  52. package/lib/plugin-area/__tests__/plugin-api.test.js +54 -0
  53. package/lib/plugin-area/__tests__/plugin-api.test.js.map +1 -0
  54. package/lib/plugin-area/{plugin-area.d.ts → base-plugin-area.d.ts} +1 -1
  55. package/lib/plugin-area/base-plugin-area.js +68 -0
  56. package/lib/plugin-area/base-plugin-area.js.map +1 -0
  57. package/lib/plugin-area/higher-order-component-util.js +23 -0
  58. package/lib/plugin-area/higher-order-component-util.js.map +1 -0
  59. package/lib/plugin-area/index.d.ts +2 -2
  60. package/lib/plugin-area/index.js +34 -0
  61. package/lib/plugin-area/index.js.map +1 -0
  62. package/lib/plugin-area/index.native.d.ts +3 -0
  63. package/lib/plugin-area/index.native.js +35 -0
  64. package/lib/plugin-area/index.native.js.map +1 -0
  65. package/lib/plugin-area/plugin-api.js +79 -0
  66. package/lib/plugin-area/plugin-api.js.map +1 -0
  67. package/lib/plugin-area/plugin-context.js +44 -0
  68. package/lib/plugin-area/plugin-context.js.map +1 -0
  69. package/lib/route/__tests__/admin-new-routes.test.d.ts +1 -0
  70. package/lib/route/__tests__/admin-new-routes.test.js +175 -0
  71. package/lib/route/__tests__/admin-new-routes.test.js.map +1 -0
  72. package/lib/route/__tests__/config-routes.test.d.ts +0 -0
  73. package/lib/route/__tests__/config-routes.test.js +326 -0
  74. package/lib/route/__tests__/config-routes.test.js.map +1 -0
  75. package/lib/route/__tests__/getFlatMenus.test.d.ts +1 -0
  76. package/lib/route/__tests__/getFlatMenus.test.js +96 -0
  77. package/lib/route/__tests__/getFlatMenus.test.js.map +1 -0
  78. package/lib/route/__tests__/render-routes-config.test.d.ts +2 -0
  79. package/lib/route/__tests__/render-routes-config.test.js +69 -0
  80. package/lib/route/__tests__/render-routes-config.test.js.map +1 -0
  81. package/lib/route/__tests__/route-type.test.d.ts +1 -0
  82. package/lib/route/__tests__/route-type.test.js +9 -0
  83. package/lib/route/__tests__/route-type.test.js.map +1 -0
  84. package/lib/route/get-routes.d.ts +3 -0
  85. package/lib/route/get-routes.js +86 -0
  86. package/lib/route/get-routes.js.map +1 -0
  87. package/lib/route/get-routes.test.d.ts +1 -0
  88. package/lib/route/get-routes.test.js +170 -0
  89. package/lib/route/get-routes.test.js.map +1 -0
  90. package/lib/route/index.js +14 -0
  91. package/lib/route/index.js.map +1 -0
  92. package/lib/route/index.native.d.ts +1 -0
  93. package/lib/route/index.native.js +14 -0
  94. package/lib/route/index.native.js.map +1 -0
  95. package/lib/route/old/__tests__/config-sidebar-menu.test.d.ts +1 -0
  96. package/lib/route/old/__tests__/config-sidebar-menu.test.js +198 -0
  97. package/lib/route/old/__tests__/config-sidebar-menu.test.js.map +1 -0
  98. package/lib/route/old/get-menus.d.ts +2 -0
  99. package/lib/route/old/get-menus.js +63 -0
  100. package/lib/route/old/get-menus.js.map +1 -0
  101. package/lib/route/old/get-routes-notused.d.ts +11 -0
  102. package/lib/route/old/get-routes-notused.js +61 -0
  103. package/lib/route/old/get-routes-notused.js.map +1 -0
  104. package/lib/route/old/render.d.ts +2 -0
  105. package/lib/route/old/render.js +30 -0
  106. package/lib/route/old/render.js.map +1 -0
  107. package/lib/route/render-routes-test.d.ts +1 -0
  108. package/lib/route/render-routes-test.js +40 -0
  109. package/lib/route/render-routes-test.js.map +1 -0
  110. package/lib/route/render-routes.d.ts +2 -14
  111. package/lib/route/render-routes.js +164 -0
  112. package/lib/route/render-routes.js.map +1 -0
  113. package/lib/route/render-routes.native.d.ts +4 -0
  114. package/lib/route/render-routes.native.js +158 -0
  115. package/lib/route/render-routes.native.js.map +1 -0
  116. package/lib/route-based-plugin-area/__tests__/higher-order-component-util.test.d.ts +1 -0
  117. package/lib/route-based-plugin-area/__tests__/higher-order-component-util.test.js +60 -0
  118. package/lib/route-based-plugin-area/__tests__/higher-order-component-util.test.js.map +1 -0
  119. package/lib/route-based-plugin-area/__tests__/plugin-api.test.d.ts +1 -0
  120. package/lib/route-based-plugin-area/__tests__/plugin-api.test.js +54 -0
  121. package/lib/route-based-plugin-area/__tests__/plugin-api.test.js.map +1 -0
  122. package/lib/route-based-plugin-area/higher-order-component-util.js +23 -0
  123. package/lib/route-based-plugin-area/higher-order-component-util.js.map +1 -0
  124. package/lib/route-based-plugin-area/index.js +15 -0
  125. package/lib/route-based-plugin-area/index.js.map +1 -0
  126. package/lib/route-based-plugin-area/plugin-api.js +79 -0
  127. package/lib/route-based-plugin-area/plugin-api.js.map +1 -0
  128. package/lib/route-based-plugin-area/plugin-context.js +44 -0
  129. package/lib/route-based-plugin-area/plugin-context.js.map +1 -0
  130. package/lib/route-based-plugin-area/route-based-plugin-area.js +68 -0
  131. package/lib/route-based-plugin-area/route-based-plugin-area.js.map +1 -0
  132. package/lib/{router/router.d.ts → router-factory/index.d.ts} +0 -0
  133. package/lib/router-factory/index.js +30 -0
  134. package/lib/router-factory/index.js.map +1 -0
  135. package/lib/router-factory/index.native.d.ts +2 -0
  136. package/lib/router-factory/index.native.js +30 -0
  137. package/lib/router-factory/index.native.js.map +1 -0
  138. package/lib/utils/index.d.ts +2 -1
  139. package/lib/utils/index.js +15 -0
  140. package/lib/utils/index.js.map +1 -0
  141. package/lib/utils/sort-keys.d.ts +1 -0
  142. package/lib/utils/sort-keys.js +73 -0
  143. package/lib/utils/sort-keys.js.map +1 -0
  144. package/lib/utils/sort-keys.test.d.ts +1 -0
  145. package/lib/utils/sort-keys.test.js +30 -0
  146. package/lib/utils/sort-keys.test.js.map +1 -0
  147. package/lib/utils/utils.d.ts +4 -0
  148. package/lib/utils/utils.js +13 -0
  149. package/lib/utils/utils.js.map +1 -0
  150. package/package.json +7 -6
  151. package/lib/plugin-area/browser-plugin-area.d.ts +0 -2
  152. package/lib/router/index.d.ts +0 -1
  153. package/lib/utils/route-utils.d.ts +0 -17
@@ -0,0 +1,326 @@
1
+ // OUTDATED TEST NEED TO UPDATE
2
+ // import * as React from 'react';
3
+ // import * as renderer from 'react-test-renderer';
4
+ // import * as Loadable from 'react-loadable';
5
+ // import { Route } from 'react-router-dom';
6
+ // import { getRoutes } from '../get-routes';
7
+ // import { Feature } from '../../connector';
8
+ // import { FeatureWithRouterFactory } from '../../router-factory';
9
+ // import 'jest';
10
+ // function waitFor(delay) {
11
+ // return new Promise(resolve => {
12
+ // setTimeout(resolve, delay);
13
+ // });
14
+ // }
15
+ // function createLoader(delay, loader, error?: any) {
16
+ // return () => {
17
+ // return waitFor(delay).then(() => {
18
+ // if (loader) {
19
+ // return loader();
20
+ // } else {
21
+ // throw error;
22
+ // }
23
+ // });
24
+ // };
25
+ // }
26
+ // function MyLoadingComponent(props) {
27
+ // return <div>MyLoadingComponent {JSON.stringify(props)}</div>;
28
+ // }
29
+ // function MyComponent(props) {
30
+ // return <div>MyComponent {JSON.stringify(props)}</div>;
31
+ // }
32
+ // afterEach(async () => {
33
+ // try {
34
+ // await Loadable.preloadAll();
35
+ // } catch (err) {
36
+ // }
37
+ // });
38
+ // // Test case borrowed from
39
+ // // https://github.com/jamiebuilds/react-loadable/blob/master/__tests__/test.js
40
+ // test('loading success', async () => {
41
+ // let LoadableMyComponent = Loadable({
42
+ // loader: createLoader(400, () => MyComponent),
43
+ // loading: MyLoadingComponent,
44
+ // });
45
+ // let component1 = renderer.create(<LoadableMyComponent prop="foo" />);
46
+ // expect(component1.toJSON()).toMatchSnapshot(); // initial
47
+ // await waitFor(200);
48
+ // expect(component1.toJSON()).toMatchSnapshot(); // loading
49
+ // await waitFor(200);
50
+ // expect(component1.toJSON()).toMatchSnapshot(); // loaded
51
+ // let component2 = renderer.create(<LoadableMyComponent prop="bar" />);
52
+ // expect(component2.toJSON()).toMatchSnapshot(); // reload
53
+ // });
54
+ // const routerConfig = (namespace = '') => ({
55
+ // [namespace + '/a']: {
56
+ // component: MyComponent,
57
+ // },
58
+ // ['/a/1']: {
59
+ // component: MyComponent,
60
+ // },
61
+ // ['/a/:b/1']: {
62
+ // component: MyComponent,
63
+ // },
64
+ // [namespace + '/a/1']: {
65
+ // component: MyComponent,
66
+ // },
67
+ // [namespace + '/a/:c/1']: {
68
+ // component: MyComponent,
69
+ // },
70
+ // [namespace + '/a/2']: {
71
+ // component: MyComponent,
72
+ // },
73
+ // [namespace + '/a/2/1']: {
74
+ // component: MyComponent,
75
+ // },
76
+ // [namespace + '/ab/2/1']: {
77
+ // component: MyComponent,
78
+ // },
79
+ // [namespace + '/b/1']: {
80
+ // component: MyComponent,
81
+ // },
82
+ // [namespace + '/b/login/register']: {
83
+ // component: MyComponent,
84
+ // },
85
+ // });
86
+ // describe('getRoutes utility with basic routes', () => {
87
+ // test('with /a', async () => {
88
+ // const result = {
89
+ // // component: any,
90
+ // routes: [{
91
+ // path: '/a', exact: true, routes:
92
+ // [{ path: '/a/1', exact: true },
93
+ // { path: '/a/:b/1', exact: true },
94
+ // { path: '/a/2', exact: false, routes: [{ 'exact': true, 'path': '/a/2/1' }] },
95
+ // { path: '/ab/2/1', exact: true }],
96
+ // }],
97
+ // };
98
+ // const routes = getRoutes('/', routerConfig());
99
+ // expect(routes).toMatchSnapshot();
100
+ // });
101
+ // test('with /', async () => {
102
+ // const result =
103
+ // [{
104
+ // path: '/a', exact: false, routes:
105
+ // [
106
+ // { path: '/a/1', exact: true },
107
+ // { path: '/a/:b/1', exact: true },
108
+ // { path: '/a/:c/1', exact: true },
109
+ // {
110
+ // path: '/a/2', exact: false, routes:
111
+ // [
112
+ // { path: '/a/2/1', exact: true },
113
+ // ],
114
+ // },
115
+ // ],
116
+ // },
117
+ // { path: '/ab/2/1', exact: true },
118
+ // { path: '/b/1', exact: true },
119
+ // { path: '/b/login/register', exact: true }];
120
+ // const routes = getRoutes('/', routerConfig());
121
+ // expect(routes).toMatchSnapshot();
122
+ // expect(JSON.parse(JSON.stringify(routes))).toMatchObject(result);
123
+ // });
124
+ // test('with `@`in root throws error', async () => {
125
+ // try {
126
+ // getRoutes('@namespace.', routerConfig('@namespace'));
127
+ // } catch (e) {
128
+ // expect(e.message).toEqual('Invalid path!');
129
+ // }
130
+ // });
131
+ // xdescribe('getRoutes utility with realistic routes', () => {
132
+ // test('with realistic routes', () => {
133
+ // const genRoutes = {
134
+ // ['/path']: { component: MyComponent, exact: true },
135
+ // ['/path/a']: { component: MyComponent },
136
+ // ['/path/a/b']: { component: MyComponent },
137
+ // ['/path/child']: { component: MyComponent, exact: true },
138
+ // ['/path/child1']: { component: MyComponent, exact: true },
139
+ // };
140
+ // const routes = getRoutes('/', genRoutes);
141
+ // const result = [
142
+ // {
143
+ // // should render
144
+ // component: MyComponent,
145
+ // path: '/path',
146
+ // exact: true,
147
+ // routes: [
148
+ // {
149
+ // // should skip
150
+ // component: MyComponent,
151
+ // path: '/path/a',
152
+ // exact: false,
153
+ // routes: [
154
+ // {
155
+ // // should skip
156
+ // component: MyComponent,
157
+ // path: '/path/a/b',
158
+ // exact: true,
159
+ // },
160
+ // ],
161
+ // },
162
+ // {
163
+ // // should skip
164
+ // component: MyComponent,
165
+ // path: '/path/child',
166
+ // exact: true,
167
+ // },
168
+ // {
169
+ // // should render
170
+ // path: '/path/child1',
171
+ // component: MyComponent,
172
+ // },
173
+ // ],
174
+ // },
175
+ // ];
176
+ // expect(routes).toMatchObject(result);
177
+ // expect(routes).toMatchSnapshot();
178
+ // });
179
+ // it('another realistic test', () => {
180
+ // const genRoutes = [
181
+ // {
182
+ // ['/ghost']: { component: MyComponent },
183
+ // ['/pepper']: { component: MyComponent, exact: false },
184
+ // ['/pepper/:type']: { component: MyComponent, exact: false },
185
+ // ['/pepper/:type/scoville']: { component: MyComponent, exact: false },
186
+ // },
187
+ // ];
188
+ // const result = [
189
+ // {
190
+ // path: '/ghost',
191
+ // component: MyComponent,
192
+ // },
193
+ // {
194
+ // path: '/pepper',
195
+ // component: MyComponent,
196
+ // exact: false,
197
+ // routes: [
198
+ // {
199
+ // path: '/pepper/:type',
200
+ // component: MyComponent,
201
+ // exact: false,
202
+ // routes: [
203
+ // {
204
+ // path: '/pepper/:type/scoville',
205
+ // component: MyComponent,
206
+ // exact: false,
207
+ // },
208
+ // ],
209
+ // },
210
+ // ],
211
+ // },
212
+ // ];
213
+ // const connector = new Feature({ routeConfig: genRoutes });
214
+ // const connectorRoutes = connector.getConfiguredRoutes();
215
+ // expect(connectorRoutes).toMatchObject(result);
216
+ // });
217
+ // });
218
+ // it('with root', () => {
219
+ // const genRoutes = [
220
+ // {
221
+ // ['/']: { component: MyComponent, exact: false },
222
+ // ['/ghost']: { component: MyComponent },
223
+ // ['/pepper']: { component: MyComponent, exact: false },
224
+ // ['/pepper/:type']: { component: MyComponent, exact: false },
225
+ // ['/pepper/:type/scoville']: { component: MyComponent, exact: false },
226
+ // },
227
+ // ];
228
+ // const connector = new Feature({ routeConfig: genRoutes });
229
+ // const connectorRoutes = connector.getConfiguredRoutes();
230
+ // expect(connectorRoutes).toMatchSnapshot();
231
+ // });
232
+ // });
233
+ // xdescribe('connector configuredRoutes', () => {
234
+ // test('with no arguments passed', async () => {
235
+ // const connector = new Feature({ routeConfig: routerConfig() });
236
+ // const result = [{
237
+ // exact: false, path: '/a',
238
+ // routes: [
239
+ // { exact: true, path: '/a/1' },
240
+ // { path: '/a/:b/1', exact: true },
241
+ // { path: '/a/:c/1', exact: true },
242
+ // {
243
+ // exact: false, path: '/a/2',
244
+ // routes: [
245
+ // { exact: true, path: '/a/2/1' },
246
+ // ],
247
+ // }],
248
+ // },
249
+ // { exact: true, path: '/ab/2/1' },
250
+ // { exact: true, path: '/b/1' },
251
+ // { exact: true, path: '/b/login/register' }];
252
+ // const routes = connector.getConfiguredRoutes();
253
+ // expect(routes).toMatchSnapshot();
254
+ // expect(JSON.parse(JSON.stringify(routes))).toMatchObject(result);
255
+ // });
256
+ // test('with @namespace in routes', async () => {
257
+ // const connector = new Feature({ routeConfig: routerConfig('@namespace') });
258
+ // const result = [
259
+ // { exact: true, path: '/a/1' },
260
+ // { path: '/a/:b/1', exact: true },
261
+ // ];
262
+ // expect(JSON.parse(JSON.stringify(connector.getConfiguredRoutes()))).toMatchObject(result);
263
+ // });
264
+ // });
265
+ // xdescribe('connector getRoutes', () => {
266
+ // const staticRoutes = {
267
+ // route: [
268
+ // <Route key={'static1'} exact={true} path="/static1" component={MyComponent} />,
269
+ // <Route key={'static2'} exact={true} path="/static2" component={MyComponent} />,
270
+ // ],
271
+ // };
272
+ // const staticRoutes2 = {
273
+ // route: [
274
+ // <Route key={'static3'} exact={true} path="/static3" component={MyComponent} />,
275
+ // <Route key={'static4'} exact={true} path="/static4" component={MyComponent} />,
276
+ // ],
277
+ // };
278
+ // test('with only static routes', async () => {
279
+ // const connector = new Feature(staticRoutes, FeatureWithRouterFactory);
280
+ // expect(connector.routerFactory()).toMatchSnapshot();
281
+ // });
282
+ // test('with static routes and configurable routes', async () => {
283
+ // const connector = new Feature({ routeConfig: routerConfig() }, new Feature(staticRoutes));
284
+ // expect(connector.getRoutes()).toMatchSnapshot();
285
+ // });
286
+ // test('with only configurable routes', async () => {
287
+ // const connector = new Feature({ routeConfig: routerConfig() });
288
+ // expect(connector.getRoutes()).toMatchSnapshot();
289
+ // });
290
+ // test('with multiple Features', async () => {
291
+ // const connector = new Feature(
292
+ // { routeConfig: routerConfig() },
293
+ // new Feature(staticRoutes),
294
+ // new Feature(staticRoutes2),
295
+ // { routeConfig: routerConfig('/ac') },
296
+ // );
297
+ // const routes = connector.getRoutes();
298
+ // expect(routes).toMatchSnapshot();
299
+ // });
300
+ // });
301
+ // xdescribe('filter routes with realizting routes', () => {
302
+ // const genRoutes = {
303
+ // ['/']: { component: MyComponent, exact: true },
304
+ // ['/l']: { component: MyComponent },
305
+ // ['/rl']: { component: MyComponent },
306
+ // ['/:or/a/b']: { component: MyComponent },
307
+ // ['/:or/child']: { component: MyComponent, exact: true },
308
+ // ['/:or/child1']: { component: MyComponent, exact: true },
309
+ // };
310
+ // const result =
311
+ // [
312
+ // { path: '/', exact: true },
313
+ // { path: '/l' },
314
+ // { path: '/rl' },
315
+ // { path: '/:or/ab/2/1', exact: true },
316
+ // { path: '/:or/b/1', exact: true },
317
+ // { path: '/:or/b/login/register', exact: true }];
318
+ // const connector = new Feature({ routeConfig: genRoutes });
319
+ // const regexExpNotStartWithColon = /^\/(?!(:)).*/;
320
+ // const connectorRoutes = connector.getConfiguredRoutes('/');
321
+ // // TODO now need to filter routes which don't start with `/:or`. Something
322
+ // // similar to regex, we need to a netgaive `connector.getConfiguredRoutes('^/:or');`
323
+ // console.log('---ConnectorRoutes', connectorRoutes);
324
+ // // connectorRoutes.
325
+ // });
326
+ //# sourceMappingURL=config-routes.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-routes.test.js","sourceRoot":"","sources":["../../../src/route/__tests__/config-routes.test.tsx"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B,kCAAkC;AAClC,mDAAmD;AACnD,8CAA8C;AAC9C,4CAA4C;AAC5C,6CAA6C;AAC7C,6CAA6C;AAC7C,mEAAmE;AACnE,iBAAiB;AAGjB,4BAA4B;AAC5B,oCAAoC;AACpC,kCAAkC;AAClC,QAAQ;AACR,IAAI;AAEJ,sDAAsD;AACtD,mBAAmB;AACnB,yCAAyC;AACzC,sBAAsB;AACtB,2BAA2B;AAC3B,iBAAiB;AACjB,uBAAuB;AACvB,UAAU;AACV,UAAU;AACV,OAAO;AACP,IAAI;AAEJ,uCAAuC;AAC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AACjD,qCAAqC;AACrC,yCAAyC;AACzC,mCAAmC;AACnC,oCAAoC;AACpC,8CAA8C;AAC9C,SAAS;AAET,4CAA4C;AAC5C,wCAAwC;AACxC,QAAQ;AAKR,MAAM;AAEN,4DAA4D;AAE5D,wBAAwB;AACxB,sDAAsD;AACtD,0CAA0C;AAC1C,2CAA2C;AAC3C,gDAAgD;AAChD,+DAA+D;AAC/D,gEAAgE;AAChE,OAAO;AACP,mBAAmB;AACnB,QAAQ;AACR,oCAAoC;AACpC,wBAAwB;AACxB,yBAAyB;AACzB,8CAA8C;AAC9C,2CAA2C;AAC3C,yDAAyD;AAEzD,mEAAmE;AACnE,0DAA0D;AAC1D,oEAAoE;AAEpE,mFAAmF;AACnF,6FAA6F;AAC7F,4DAA4D;AAC5D,4BAA4B;AAC5B,MAAM"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const route_utils_1 = require("@umijs/route-utils");
4
+ const routes = [
5
+ {
6
+ path: '/welcome',
7
+ name: 'welcome',
8
+ exact: true,
9
+ unaccessible: false,
10
+ },
11
+ {
12
+ path: '/admin',
13
+ name: 'admin',
14
+ access: 'canAdmin',
15
+ routes: [
16
+ {
17
+ path: '/admin/sub-page',
18
+ name: 'sub-page',
19
+ exact: true,
20
+ unaccessible: false,
21
+ },
22
+ ],
23
+ },
24
+ {
25
+ name: 'list.table.result',
26
+ path: '/list/:id',
27
+ exact: true,
28
+ unaccessible: false,
29
+ },
30
+ {
31
+ name: 'list.table-list',
32
+ path: '/list',
33
+ exact: true,
34
+ unaccessible: false,
35
+ },
36
+ { path: '/', redirect: '/welcome', exact: true, unaccessible: false },
37
+ ];
38
+ const { menuData } = route_utils_1.transformRoute(routes, true, ({ id }) => {
39
+ if (id === 'menu.list.table-list')
40
+ return 'query table';
41
+ if (id === 'menu.list.table.result')
42
+ return 'Data details';
43
+ if (id === 'menu.admin')
44
+ return 'Admin page';
45
+ if (id === 'menu.admin.sub-page')
46
+ return 'Secondary management page';
47
+ if (id === 'menu.welcome')
48
+ return 'welcome';
49
+ return id;
50
+ });
51
+ console.log('---Menu Data', menuData);
52
+ describe('getFlatMenus', () => {
53
+ it('normal', () => {
54
+ const flatMenus = route_utils_1.getFlatMenus(menuData);
55
+ console.log('--flatMenus', flatMenus);
56
+ expect(Object.keys(flatMenus).length).toEqual(5);
57
+ expect(flatMenus['/list'].name).toEqual('Inquiry Form');
58
+ expect(flatMenus).toMatchSnapshot();
59
+ });
60
+ it('no has ket', () => {
61
+ const noHasKeyData = [
62
+ {
63
+ path: '/welcome',
64
+ name: '欢迎',
65
+ exact: true,
66
+ unaccessible: false,
67
+ locale: 'menu.welcome',
68
+ key: '/welcome',
69
+ routes: null,
70
+ pro_layout_parentKeys: [],
71
+ children: undefined,
72
+ },
73
+ {
74
+ path: '/welcome',
75
+ name: '欢迎',
76
+ key: '/admin/welcome',
77
+ exact: true,
78
+ unaccessible: false,
79
+ locale: 'menu.welcome',
80
+ routes: null,
81
+ children: undefined,
82
+ },
83
+ {
84
+ path: '/admin',
85
+ name: '管理页',
86
+ access: 'canAdmin',
87
+ routes: null,
88
+ locale: 'menu.admin',
89
+ pro_layout_parentKeys: [],
90
+ },
91
+ ];
92
+ const flatMenus = route_utils_1.getFlatMenus(noHasKeyData);
93
+ expect(Object.keys(flatMenus).length).toEqual(2);
94
+ });
95
+ });
96
+ //# sourceMappingURL=getFlatMenus.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getFlatMenus.test.js","sourceRoot":"","sources":["../../../src/route/__tests__/getFlatMenus.test.ts"],"names":[],"mappings":";;AAAA,oDAAiE;AAEjE,MAAM,MAAM,GAAG;IACX;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,IAAI;QACX,YAAY,EAAE,KAAK;KACpB;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,OAAO;QACb,MAA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 -0,0 +1,69 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.logger = void 0;
13
+ const server_1 = require("@cdm-logger/server");
14
+ const get_routes_1 = require("../get-routes");
15
+ exports.logger = server_1.ConsoleLogger.create('test', { level: 'trace' });
16
+ function MyComponent(props) {
17
+ return {};
18
+ }
19
+ test('loading success', () => __awaiter(void 0, void 0, void 0, function* () {
20
+ const routerConfig = (namespace = '') => ({
21
+ [namespace + '/a']: {
22
+ component: () => MyComponent,
23
+ },
24
+ ['/a']: {
25
+ component: () => MyComponent,
26
+ },
27
+ ['/a/1']: {
28
+ component: () => MyComponent,
29
+ },
30
+ ['/a/1/2']: {
31
+ component: () => MyComponent,
32
+ },
33
+ ['/b']: {
34
+ component: () => MyComponent,
35
+ },
36
+ ['/a/b']: {
37
+ component: () => MyComponent,
38
+ },
39
+ ['/a/b/1']: {
40
+ component: () => MyComponent,
41
+ },
42
+ ['/a/b/1/2']: {
43
+ component: () => MyComponent,
44
+ },
45
+ ['/a/b/1/2/3']: {
46
+ component: () => MyComponent,
47
+ },
48
+ [namespace + '/a/1']: {
49
+ component: () => MyComponent,
50
+ },
51
+ [namespace + '/a/2']: {
52
+ component: () => MyComponent,
53
+ },
54
+ [namespace + '/a/2/1']: {
55
+ component: () => MyComponent,
56
+ },
57
+ [namespace + '/ab/2/1']: {
58
+ component: () => MyComponent,
59
+ },
60
+ [namespace + '/b/1']: {
61
+ component: () => MyComponent,
62
+ },
63
+ [namespace + '/b/c/e']: {
64
+ component: () => MyComponent,
65
+ },
66
+ });
67
+ console.log(get_routes_1.getRoutes('/', routerConfig('@test'), null));
68
+ }));
69
+ //# sourceMappingURL=render-routes-config.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-routes-config.test.js","sourceRoot":"","sources":["../../../src/route/__tests__/render-routes-config.test.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAAmD;AAEnD,8CAA0C;AAE7B,QAAA,MAAM,GAAsB,sBAAa,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;AAE1F,SAAS,WAAW,CAAC,KAAK;IACtB,OAAO,EAAE,CAAA;AACb,CAAC;AAED,IAAI,CAAC,iBAAiB,EAAE,GAAS,EAAE;IAC/B,MAAM,YAAY,GAAG,CAAC,SAAS,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC;QACtC,CAAC,SAAS,GAAG,IAAI,CAAC,EAAE;YAChB,SAAS,EAAE,GAAG,EAAE,CAAC,WAAW;SAC/B;QACD,CAAC,IAAI,CAAC,EAAE;YACJ,SAAS,EAAE,GAAG,EAAE,CAAC,WAAW;SAC/B;QACD,CAAC,MAAM,CAAC,EAAE;YACN,SAAS,EAAE,GAAG,EAAE,CAAC,WAAW;SAC/B;QACD,CAAC,QAAQ,CAAC,EAAE;YACR,SAAS,EAAE,GAAG,EAAE,CAAC,WAAW;SAC/B;QACD,CAAC,IAAI,CAAC,EAAE;YACJ,SAAS,EAAE,GAAG,EAAE,CAAC,WAAW;SAC/B;QACD,CAAC,MAAM,CAAC,EAAE;YACN,SAAS,EAAE,GAAG,EAAE,CAAC,WAAW;SAC/B;QACD,CAAC,QAAQ,CAAC,EAAE;YACR,SAAS,EAAE,GAAG,EAAE,CAAC,WAAW;SAC/B;QACD,CAAC,UAAU,CAAC,EAAE;YACV,SAAS,EAAE,GAAG,EAAE,CAAC,WAAW;SAC/B;QACD,CAAC,YAAY,CAAC,EAAE;YACZ,SAAS,EAAE,GAAG,EAAE,CAAC,WAAW;SAC/B;QACD,CAAC,SAAS,GAAG,MAAM,CAAC,EAAE;YAClB,SAAS,EAAE,GAAG,EAAE,CAAC,WAAW;SAC/B;QACD,CAAC,SAAS,GAAG,MAAM,CAAC,EAAE;YAClB,SAAS,EAAE,GAAG,EAAE,CAAC,WAAW;SAC/B;QACD,CAAC,SAAS,GAAG,QAAQ,CAAC,EAAE;YACpB,SAAS,EAAE,GAAG,EAAE,CAAC,WAAW;SAC/B;QACD,CAAC,SAAS,GAAG,SAAS,CAAC,EAAE;YACrB,SAAS,EAAE,GAAG,EAAE,CAAC,WAAW;SAC/B;QACD,CAAC,SAAS,GAAG,MAAM,CAAC,EAAE;YAClB,SAAS,EAAE,GAAG,EAAE,CAAC,WAAW;SAC/B;QACD,CAAC,SAAS,GAAG,QAAQ,CAAC,EAAE;YACpB,SAAS,EAAE,GAAG,EAAE,CAAC,WAAW;SAC/B;KACJ,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,sBAAS,CAAC,GAAG,EAAE,YAAY,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;AAC7D,CAAC,CAAA,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const route = {
4
+ ['/test']: {
5
+ disabled: false,
6
+ authority: ['test']
7
+ }
8
+ };
9
+ //# sourceMappingURL=route-type.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route-type.test.js","sourceRoot":"","sources":["../../../src/route/__tests__/route-type.test.ts"],"names":[],"mappings":";;AAMA,MAAM,KAAK,GAA6B;IACvC,CAAC,OAAO,CAAC,EAAE;QACR,QAAQ,EAAE,KAAK;QACf,SAAS,EAAE,CAAC,MAAM,CAAC;KAErB;CACD,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { IRouteData } from '../interfaces';
2
+ export declare const getSortedRoutes: (path: string, routeData: IRouteData, authWrapper?: (ele: React.ReactElement, props: Record<string, any>) => void) => any;
3
+ export declare function getRoutes(path: string, routeData: IRouteData, authWrapper?: (ele: any, props: any) => void): any;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.getRoutes = exports.getSortedRoutes = void 0;
15
+ const interfaces_1 = require("../interfaces");
16
+ const utils_1 = require("../utils");
17
+ const getSortedRoutes = (path, routeData, authWrapper = null) => {
18
+ const sortedRoutes = utils_1.sortKeys(routeData);
19
+ return getRoutes(path, sortedRoutes, authWrapper);
20
+ };
21
+ exports.getSortedRoutes = getSortedRoutes;
22
+ function getRoutes(path, routeData, authWrapper = null) {
23
+ if (!path.startsWith('/')) {
24
+ throw new Error('Invalid path!');
25
+ }
26
+ let searchPath = path;
27
+ if (path[path.length - 1] !== '/') {
28
+ searchPath = path + '/';
29
+ }
30
+ const routes = Object.keys(routeData).filter(menuPath => {
31
+ return menuPath.indexOf(searchPath) === 0 || menuPath === path;
32
+ });
33
+ const mappedMenuPaths = routes.map(mPath => {
34
+ return Object.assign({ route: mPath, position: interfaces_1.IMenuPosition.MIDDLE }, routeData[mPath]);
35
+ });
36
+ const root = {
37
+ // just to satisfy types added following
38
+ // TOOD need to correct types so we don't have to enter them.
39
+ name: 'root',
40
+ position: interfaces_1.IMenuPosition.LOGO,
41
+ };
42
+ mappedMenuPaths.forEach(routeItem => {
43
+ const children = routeItem.route.split('/');
44
+ children.shift();
45
+ // if the route is `/` then add this correction.
46
+ if (routeItem.path === '/') {
47
+ children.shift();
48
+ children.push('/');
49
+ }
50
+ const depth = children.length;
51
+ let lastNode = root;
52
+ for (let i = 0; i < depth; i++) {
53
+ const lastIndex = (lastNode.routes || []).findIndex(item => {
54
+ const routePath = `${item._pathPrefix}${item.path}`;
55
+ if (routeItem.route.startsWith(routePath)) {
56
+ return routeItem.route[routePath.length] === '/';
57
+ }
58
+ });
59
+ if (lastIndex === -1) {
60
+ break;
61
+ }
62
+ lastNode = lastNode.routes[lastIndex];
63
+ const lastNodePath = `${lastNode._pathPrefix}${lastNode.path}`;
64
+ lastNode.exact = routeData[lastNodePath].hasOwnProperty('exact') ? routeData[lastNodePath].exact : false;
65
+ }
66
+ if (!lastNode.routes) {
67
+ lastNode.routes = [];
68
+ }
69
+ const { route: ignore, auth } = routeItem, rest = __rest(routeItem, ["route", "auth"]);
70
+ const pathParams = utils_1.formatSlash(routeItem.route);
71
+ lastNode.routes.push(Object.assign(Object.assign(Object.assign({}, rest), pathParams), { exact: routeData[routeItem.route].hasOwnProperty('exact') ? routeData[routeItem.route].exact : true,
72
+ /**
73
+ * Here we are checking whether auth property is being
74
+ * set by this route and if authWrapper is declared
75
+ * which is a high order component that can take a component
76
+ * and its props as argument then perform some
77
+ * computation and return a component
78
+ */
79
+ component: auth && authWrapper
80
+ ? (props) => authWrapper(routeItem.component, props)
81
+ : routeItem.component }));
82
+ });
83
+ return root.routes;
84
+ }
85
+ exports.getRoutes = getRoutes;
86
+ //# sourceMappingURL=get-routes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-routes.js","sourceRoot":"","sources":["../../src/route/get-routes.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,8CAAuE;AACvE,oCAAiD;AAE1C,MAAM,eAAe,GAAG,CAAC,IAAY,EAAE,SAAqB,EAAE,cAGzD,IAAI,E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