mobx-route 0.1.1 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobx-route",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "keywords": [
5
5
  "mobx",
6
6
  "react",
@@ -159,6 +159,11 @@
159
159
  "default": "./react/components/route-view.js",
160
160
  "types": "./react/components/route-view.d.ts"
161
161
  },
162
+ "./react/components/switch.test": {
163
+ "import": "./react/components/switch.test.js",
164
+ "default": "./react/components/switch.test.js",
165
+ "types": "./react/components/switch.test.d.ts"
166
+ },
162
167
  "./react/components/switch": {
163
168
  "import": "./react/components/switch.js",
164
169
  "default": "./react/components/switch.js",
@@ -1 +1 @@
1
- {"version":3,"file":"route-view.d.ts","sourceRoot":"","sources":["../../../src/react/components/route-view.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAU,MAAM,OAAO,CAAC;AACzD,OAAO,EAAY,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEjE,OAAO,EACL,sBAAsB,EACtB,KAAK,QAAQ,EACb,KAAK,eAAe,EACrB,MAAM,qBAAqB,CAAC;AAE7B,MAAM,MAAM,kBAAkB,CAAC,MAAM,SAAS,sBAAsB,IAClE,aAAa,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;AAExC,MAAM,WAAW,oBAAoB,CAAC,MAAM,SAAS,sBAAsB;IACzE,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAClC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,aAAa,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC7E,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,YAAY,CAAC,EAAE,SAAS,CAAC;IACz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C;IACd,IAAI,CAAC,EAAE,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAClC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,aAAa,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC7E,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,EACL,SAAS,GACT,CAAC,CAAC,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC;CAC9E;AAED,MAAM,MAAM,eAAe,CAAC,MAAM,SAAS,sBAAsB,IAC7D,wBAAwB,CAAC,MAAM,CAAC,GAChC,2BAA2B,CAAC;AAEhC,MAAM,MAAM,cAAc,CAAC,MAAM,SAAS,sBAAsB,IAAI;IAClE,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,MAAM,SAAS,QAAQ,GAC3B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC,GAC3C,MAAM,SAAS,eAAe,GAC5B,MAAM,CAAC,QAAQ,CAAC,GAChB,KAAK,CAAC;CACb,CAAC;AAEF,iBAAS,aAAa,CAAC,MAAM,SAAS,sBAAsB,EAC1D,KAAK,EAAE,QAAQ,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,GACvC,SAAS,CAwCX;AAED,eAAO,MAAM,SAAS;;CAA0B,CAAC"}
@@ -14,12 +14,14 @@ function RouteViewBase(props) {
14
14
  return props.fallbackView ?? null;
15
15
  }
16
16
  if (props.lazyView) {
17
- lazyViewComponentRef.current = loadable({
18
- load: () => props.lazyView(props.route),
19
- loading: props.loading,
20
- preload: props.preload,
21
- throwOnError: props.throwOnError,
22
- });
17
+ if (!lazyViewComponentRef.current) {
18
+ lazyViewComponentRef.current = loadable({
19
+ load: () => props.lazyView(props.route),
20
+ loading: props.loading,
21
+ preload: props.preload,
22
+ throwOnError: props.throwOnError,
23
+ });
24
+ }
23
25
  Component = lazyViewComponentRef.current;
24
26
  }
25
27
  else {
@@ -15,7 +15,7 @@ type SwitchPropsWithDefaultUrl = {
15
15
  default?: string;
16
16
  } & SwitchBaseProps & RouteNavigateParams;
17
17
  export type SwitchProps<TRoute extends AnyRouteEntity> = SwitchPropsWithDefaultRoute<TRoute> | SwitchPropsWithDefaultUrl;
18
- export declare const Switch: (<TRoute extends AnyRouteEntity>({ children, default: defaultNavigation, params, ...navigateParams }: SwitchProps<TRoute>) => ReactNode) & {
18
+ export declare const Switch: (<TRoute extends AnyRouteEntity>({ children, default: defaultNavigation, params, ...navigateParams }: SwitchProps<TRoute>) => string | number | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null) & {
19
19
  displayName: string;
20
20
  };
21
21
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"switch.d.ts","sourceRoot":"","sources":["../../../src/react/components/switch.tsx"],"names":[],"mappings":"AAGA,OAAO,EAIL,SAAS,EAEV,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAEnE,OAAO,EACL,cAAc,EAEd,mBAAmB,EACnB,WAAW,EACZ,MAAM,qBAAqB,CAAC;AAG7B,KAAK,eAAe,GAAG;IACrB,QAAQ,EAAE,SAAS,CAAC;CACrB,CAAC;AAEF,KAAK,2BAA2B,CAAC,MAAM,SAAS,cAAc,IAAI;IAChE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GAAG,CAAC,qBAAqB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,SAAS,IAAI,GACxD;IACE,MAAM,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;CACrC,GACD;IACE,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC7B,CAAC,GACJ,eAAe,GACf,mBAAmB,CAAC;AAEtB,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,uEAMnE,WAAW,CAAC,MAAM,CAAC;;CAsGpB,CAAC"}
@@ -1,36 +1,80 @@
1
+ /* eslint-disable sonarjs/no-nested-conditional */
2
+ /* eslint-disable unicorn/no-nested-ternary */
1
3
  /* eslint-disable @typescript-eslint/ban-ts-comment */
2
4
  import { buildSearchString } from 'mobx-location-history';
3
5
  import { observer } from 'mobx-react-lite';
4
- import { Fragment, isValidElement, useEffect, } from 'react';
5
- import { flatMapDeep } from 'yummies/data';
6
+ import { Fragment, isValidElement, useEffect } from 'react';
6
7
  import { routeConfig, } from '../../core/index.js';
7
8
  import { isRouteEntity } from '../../core/utils/is-route-entity.js';
8
- const flattenChildren = (children) => flatMapDeep(children, (c) =>
9
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
10
- // @ts-ignore
11
- c && c.type === Fragment ? c.props.children : c);
12
- const isValidRouteElement = (element) => {
13
- return (isValidElement(element) &&
14
- // @ts-ignore
15
- isRouteEntity(element.props?.route));
16
- };
17
9
  export const Switch = observer(function ({ children, default: defaultNavigation,
18
10
  // @ts-ignore
19
11
  params, ...navigateParams }) {
20
- let resultElement = null;
21
- let defaultElement = null;
22
- for (const element of flattenChildren(children)) {
23
- if (isValidRouteElement(element) && element.props.route.isOpened) {
24
- resultElement = element;
25
- break;
12
+ let activeElement = null;
13
+ let lastInactiveElement = null;
14
+ let foundActive = false;
15
+ const stack = Array.isArray(children)
16
+ ? [...children].reverse()
17
+ : children
18
+ ? [children]
19
+ : [];
20
+ while (stack.length > 0) {
21
+ const node = stack.pop();
22
+ if (node == null || typeof node === 'boolean') {
23
+ continue;
24
+ }
25
+ if (Array.isArray(node)) {
26
+ for (let i = node.length - 1; i >= 0; i--) {
27
+ stack.push(node[i]);
28
+ }
29
+ continue;
30
+ }
31
+ if (isValidElement(node) && node.type === Fragment) {
32
+ const fragmentChildren = node.props.children;
33
+ if (fragmentChildren) {
34
+ if (Array.isArray(fragmentChildren)) {
35
+ for (let i = fragmentChildren.length - 1; i >= 0; i--) {
36
+ stack.push(fragmentChildren[i]);
37
+ }
38
+ }
39
+ else {
40
+ stack.push(fragmentChildren);
41
+ }
42
+ }
43
+ continue;
44
+ }
45
+ let isActive = false;
46
+ const checkStack = [node];
47
+ while (checkStack.length > 0) {
48
+ const checkNode = checkStack.pop();
49
+ if (checkNode == null || typeof checkNode === 'boolean') {
50
+ continue;
51
+ }
52
+ if (Array.isArray(checkNode)) {
53
+ for (const element of checkNode) {
54
+ checkStack.push(element);
55
+ }
56
+ }
57
+ else if (isValidElement(checkNode)) {
58
+ if (isRouteEntity(checkNode.props?.route) &&
59
+ checkNode.props.route.isOpened) {
60
+ isActive = true;
61
+ break;
62
+ }
63
+ if (checkNode.props.children) {
64
+ checkStack.push(checkNode.props.children);
65
+ }
66
+ }
67
+ }
68
+ if (isActive) {
69
+ activeElement = node;
70
+ foundActive = true;
26
71
  }
27
72
  else {
28
- defaultElement = element;
73
+ lastInactiveElement = node;
29
74
  }
30
75
  }
31
- const isResultElementFound = !!resultElement;
32
76
  useEffect(() => {
33
- if (!isResultElementFound && defaultNavigation) {
77
+ if (!foundActive && defaultNavigation) {
34
78
  if (typeof defaultNavigation === 'string') {
35
79
  const history = routeConfig.get().history;
36
80
  const url = `${defaultNavigation}${buildSearchString(navigateParams.query || {})}`;
@@ -45,6 +89,12 @@ params, ...navigateParams }) {
45
89
  defaultNavigation.open(params, navigateParams);
46
90
  }
47
91
  }
48
- }, [isResultElementFound, defaultNavigation]);
49
- return resultElement ?? defaultElement;
92
+ }, [foundActive, defaultNavigation]);
93
+ if (foundActive) {
94
+ return activeElement;
95
+ }
96
+ if (defaultNavigation) {
97
+ return null;
98
+ }
99
+ return lastInactiveElement ?? null;
50
100
  });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=switch.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"switch.test.d.ts","sourceRoot":"","sources":["../../../src/react/components/switch.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,147 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /* eslint-disable sonarjs/no-unstable-nested-components */
3
+ import { act, render } from '@testing-library/react';
4
+ import { createBrowserHistory } from 'mobx-location-history';
5
+ import { beforeEach, describe, expect, it } from 'vitest';
6
+ import { Route, routeConfig } from '../../core/index.js';
7
+ import { mockHistory } from '../../core/route/route.test.js';
8
+ import { RouteView } from './route-view.js';
9
+ import { Switch } from './switch.js';
10
+ describe('<Switch/>', () => {
11
+ it('Should render nothing when no one route is opened', async () => {
12
+ const history = mockHistory(createBrowserHistory());
13
+ routeConfig.update({
14
+ history,
15
+ });
16
+ beforeEach(() => {
17
+ history.clearMocks();
18
+ });
19
+ const route1 = new Route('/test1');
20
+ const route2 = new Route('/test2');
21
+ const route3 = new Route('/test3');
22
+ const App = () => {
23
+ return (_jsxs(Switch, { children: [_jsx(RouteView, { route: route1, view: () => _jsx("div", { children: "route1" }) }), _jsx(RouteView, { route: route2, view: () => _jsx("div", { children: "route2" }) }), _jsx(RouteView, { route: route3, view: () => _jsx("div", { children: "route3" }) })] }));
24
+ };
25
+ const { container } = await act(async () => render(_jsx(App, {})));
26
+ expect(container.firstChild).toBeNull();
27
+ });
28
+ it('Should render last non active element when no one route is opened', async () => {
29
+ const history = mockHistory(createBrowserHistory());
30
+ routeConfig.update({
31
+ history,
32
+ });
33
+ beforeEach(() => {
34
+ history.clearMocks();
35
+ });
36
+ const route1 = new Route('/test1');
37
+ const route2 = new Route('/test2');
38
+ const route3 = new Route('/test3');
39
+ const App1 = () => {
40
+ return (_jsxs(Switch, { children: [_jsx(RouteView, { route: route1, view: () => _jsx("div", { children: "route1" }) }), _jsx(RouteView, { route: route2, view: () => _jsx("div", { children: "route2" }) }), _jsx(RouteView, { route: route3, view: () => _jsx("div", { children: "route3" }) }), _jsx("div", { children: "not_found1" })] }));
41
+ };
42
+ const screen1 = await act(async () => render(_jsx(App1, {})));
43
+ expect(screen1.getByText('not_found1')).toBeDefined();
44
+ });
45
+ it('Should render active element when 1-order route is opened', async () => {
46
+ const history = mockHistory(createBrowserHistory());
47
+ routeConfig.update({
48
+ history,
49
+ });
50
+ beforeEach(() => {
51
+ history.clearMocks();
52
+ });
53
+ const route1 = new Route('/test1');
54
+ const route2 = new Route('/test2');
55
+ const route3 = new Route('/test3');
56
+ const App1 = () => {
57
+ return (_jsxs(Switch, { children: [_jsx(RouteView, { route: route1, view: () => _jsx("div", { children: "route1" }) }), _jsx(RouteView, { route: route2, view: () => _jsx("div", { children: "route2" }) }), _jsx(RouteView, { route: route3, view: () => _jsx("div", { children: "route3" }) }), _jsx("div", { children: "not_found1" })] }));
58
+ };
59
+ await route1.open();
60
+ const screen1 = await act(async () => render(_jsx(App1, {})));
61
+ expect(screen1.getByText('route1')).toBeDefined();
62
+ });
63
+ it('Should render active element when 2-order route is opened', async () => {
64
+ const history = mockHistory(createBrowserHistory());
65
+ routeConfig.update({
66
+ history,
67
+ });
68
+ beforeEach(() => {
69
+ history.clearMocks();
70
+ });
71
+ const route1 = new Route('/test1');
72
+ const route2 = new Route('/test2');
73
+ const route3 = new Route('/test3');
74
+ const App1 = () => {
75
+ return (_jsxs(Switch, { children: [_jsx(RouteView, { route: route1, view: () => _jsx("div", { children: "route1" }) }), _jsx(RouteView, { route: route2, view: () => _jsx("div", { children: "route2" }) }), _jsx(RouteView, { route: route3, view: () => _jsx("div", { children: "route3" }) }), _jsx("div", { children: "not_found1" })] }));
76
+ };
77
+ await route2.open();
78
+ const screen1 = await act(async () => render(_jsx(App1, {})));
79
+ expect(screen1.getByText('route2')).toBeDefined();
80
+ });
81
+ it('Should render active element when 3-order route is opened', async () => {
82
+ const history = mockHistory(createBrowserHistory());
83
+ routeConfig.update({
84
+ history,
85
+ });
86
+ beforeEach(() => {
87
+ history.clearMocks();
88
+ });
89
+ const route1 = new Route('/test1');
90
+ const route2 = new Route('/test2');
91
+ const route3 = new Route('/test3');
92
+ const App1 = () => {
93
+ return (_jsxs(Switch, { children: [_jsx(RouteView, { route: route1, view: () => _jsx("div", { children: "route1" }) }), _jsx(RouteView, { route: route2, view: () => _jsx("div", { children: "route2" }) }), _jsx(RouteView, { route: route3, view: () => _jsx("div", { children: "route3" }) }), _jsx("div", { children: "not_found1" })] }));
94
+ };
95
+ await route3.open();
96
+ const screen1 = await act(async () => render(_jsx(App1, {})));
97
+ expect(screen1.getByText('route3')).toBeDefined();
98
+ });
99
+ it('Should render element of LAST OPENED route', async () => {
100
+ const history = mockHistory(createBrowserHistory());
101
+ routeConfig.update({
102
+ history,
103
+ });
104
+ beforeEach(() => {
105
+ history.clearMocks();
106
+ });
107
+ const route1 = new Route('/test');
108
+ const route2 = new Route('/test');
109
+ const route3 = new Route('/test');
110
+ const App1 = () => {
111
+ return (_jsxs(Switch, { children: [_jsx(RouteView, { route: route1, view: () => _jsx("div", { children: "route1" }) }), _jsx(RouteView, { route: route2, view: () => _jsx("div", { children: "route2" }) }), _jsx(RouteView, { route: route3, view: () => _jsx("div", { children: "route3" }) }), _jsx("div", { children: "not_found1" })] }));
112
+ };
113
+ await route3.open();
114
+ const screen1 = await act(async () => render(_jsx(App1, {})));
115
+ expect(screen1.getByText('route3')).toBeDefined();
116
+ expect(() => screen1.getByText('route2')).toThrowError();
117
+ expect(() => screen1.getByText('route1')).toThrowError();
118
+ expect(() => screen1.getByText('not_found1')).toThrowError();
119
+ });
120
+ it('Should render element with wrapper component if it is opened', async () => {
121
+ const history = mockHistory(createBrowserHistory());
122
+ routeConfig.update({
123
+ history,
124
+ });
125
+ beforeEach(() => {
126
+ history.clearMocks();
127
+ });
128
+ const route1 = new Route('/route-1-test');
129
+ const route2 = new Route('/route-2-test');
130
+ const route3 = new Route('/route-3-test');
131
+ const Wrapper = ({ children, text, }) => {
132
+ return (_jsxs("div", { className: "wrapper", children: [_jsx("label", { children: text }), children] }));
133
+ };
134
+ const App1 = () => {
135
+ return (_jsxs(Switch, { children: [_jsx(Wrapper, { text: "wrapper1", children: _jsx(RouteView, { route: route1, view: () => _jsx("div", { children: "route1" }) }) }), _jsx(Wrapper, { text: "wrapper2", children: _jsx(RouteView, { route: route2, view: () => _jsx("div", { children: "route2" }) }) }), _jsx(Wrapper, { text: "wrapper3", children: _jsx(RouteView, { route: route3, view: () => _jsx("div", { children: "route3" }) }) }), _jsx("div", { children: "not_found1" })] }));
136
+ };
137
+ await route2.open();
138
+ const screen1 = await act(async () => render(_jsx(App1, {})));
139
+ expect(screen1.getByText('route2')).toBeDefined();
140
+ expect(screen1.getByText('wrapper2')).toBeDefined();
141
+ expect(() => screen1.getByText('route1')).toThrowError();
142
+ expect(() => screen1.getByText('wrapper1')).toThrowError();
143
+ expect(() => screen1.getByText('route3')).toThrowError();
144
+ expect(() => screen1.getByText('wrapper3')).toThrowError();
145
+ expect(() => screen1.getByText('not_found1')).toThrowError();
146
+ });
147
+ });