mobx-route 0.0.81 → 0.0.83

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.
@@ -3,6 +3,9 @@ import { AnyVirtualRoute } from '../virtual-route/index.js';
3
3
  import type { RouteGroup } from './route-group.js';
4
4
  export type AnyRouteGroup = RouteGroup<RoutesCollection>;
5
5
  export type AnyRouteEntity = AnyRoute | AnyRouteGroup | AnyVirtualRoute;
6
+ export type AbstractRouteEntity = {
7
+ isOpened: boolean;
8
+ };
6
9
  export type RoutesArrayCollection = AnyRouteEntity[];
7
10
  export type RoutesObjectCollection = Record<string, AnyRouteEntity>;
8
11
  export type RoutesCollection = RoutesArrayCollection | RoutesObjectCollection;
@@ -1 +1 @@
1
- {"version":3,"file":"route-group.types.d.ts","sourceRoot":"","sources":["../../../src/core/route-group/route-group.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;AAEzD,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,aAAa,GAAG,eAAe,CAAC;AAExE,MAAM,MAAM,qBAAqB,GAAG,cAAc,EAAE,CAAC;AAErD,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AAEpE,MAAM,MAAM,gBAAgB,GAAG,qBAAqB,GAAG,sBAAsB,CAAC"}
1
+ {"version":3,"file":"route-group.types.d.ts","sourceRoot":"","sources":["../../../src/core/route-group/route-group.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;AAEzD,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,aAAa,GAAG,eAAe,CAAC;AAExE,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,cAAc,EAAE,CAAC;AAErD,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AAEpE,MAAM,MAAM,gBAAgB,GAAG,qBAAqB,GAAG,sBAAsB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobx-route",
3
- "version": "0.0.81",
3
+ "version": "0.0.83",
4
4
  "keywords": [
5
5
  "mobx",
6
6
  "react",
@@ -23,10 +23,10 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "linked-abort-controller": "^1.1.0",
26
- "mobx-location-history": "^6.1.0",
26
+ "mobx-location-history": "^7.0.3",
27
27
  "path-to-regexp": "^8.2.0",
28
28
  "react-simple-loadable": "^2.1.0",
29
- "yummies": "^3.2.13"
29
+ "yummies": "^3.4.1"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "@types/react": "^18.3.20",
@@ -157,6 +157,11 @@
157
157
  "default": "./react/components/route-view.js",
158
158
  "types": "./react/components/route-view.d.ts"
159
159
  },
160
+ "./react/components/switch": {
161
+ "import": "./react/components/switch.js",
162
+ "default": "./react/components/switch.js",
163
+ "types": "./react/components/switch.d.ts"
164
+ },
160
165
  "./react": {
161
166
  "import": "./react/index.js",
162
167
  "default": "./react/index.js",
@@ -1,5 +1,4 @@
1
1
  export * from './link.js';
2
2
  export * from './route-view.js';
3
- export * from './route-group-view.js';
4
- export * from './route-view-map.js';
3
+ export * from './switch.js';
5
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,aAAa,CAAC"}
@@ -1,4 +1,5 @@
1
1
  export * from './link.js';
2
2
  export * from './route-view.js';
3
- export * from './route-group-view.js';
4
- export * from './route-view-map.js';
3
+ // export * from './route-group-view.js';
4
+ // export * from './route-view-map.js';
5
+ export * from './switch.js';
@@ -1,8 +1,8 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { EmptyObject } from 'yummies/utils/types';
3
3
  import { AnyRouteEntity, AnyRouteGroup, RoutesArrayCollection, RoutesCollection, RoutesObjectCollection } from '../../core/index.js';
4
- import { RouteViewComponent, RouteViewConfigProps } from './route-view.js';
5
- export type RouteGroupView<TRouteEntity extends AnyRouteEntity> = Omit<RouteViewConfigProps<TRouteEntity>, 'route'> | RouteViewComponent<TRouteEntity>;
4
+ import { RouteViewComponent, RouteViewConfigWithRoute } from './route-view.js';
5
+ export type RouteGroupView<TRouteEntity extends AnyRouteEntity> = Omit<RouteViewConfigWithRoute<TRouteEntity>, 'route'> | RouteViewComponent<TRouteEntity>;
6
6
  export type RouteGroupViews<TRoutes extends RoutesCollection> = TRoutes extends RoutesArrayCollection ? {
7
7
  [K in keyof TRoutes]: TRoutes[K] extends AnyRouteEntity ? RouteGroupView<TRoutes[K]> : never;
8
8
  } : TRoutes extends RoutesObjectCollection ? {
@@ -1 +1 @@
1
- {"version":3,"file":"route-group-view.d.ts","sourceRoot":"","sources":["../../../src/react/components/route-group-view.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,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 'react';
2
2
  import { AnyRouteEntity } from '../../core/index.js';
3
- import { RouteViewComponent, RouteViewConfigProps } from './route-view.js';
4
- export type MappedRouteView<TRouteEntity extends AnyRouteEntity> = Omit<RouteViewConfigProps<TRouteEntity>, 'route'> | RouteViewComponent<TRouteEntity>;
3
+ import { RouteViewComponent, RouteViewConfigWithRoute } from './route-view.js';
4
+ export type MappedRouteView<TRouteEntity extends AnyRouteEntity> = Omit<RouteViewConfigWithRoute<TRouteEntity>, 'route'> | RouteViewComponent<TRouteEntity>;
5
5
  type RouteViewMapArrayType = [
6
6
  AnyRouteEntity,
7
7
  MappedRouteView<AnyRouteEntity>
@@ -1 +1 @@
1
- {"version":3,"file":"route-view-map.d.ts","sourceRoot":"","sources":["../../../src/react/components/route-view-map.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAA4B,MAAM,OAAO,CAAC;AAE5D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAEL,kBAAkB,EAClB,oBAAoB,EACrB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,eAAe,CAAC,YAAY,SAAS,cAAc,IAE3D,IAAI,CAAC,oBAAoB,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,GAEjD,kBAAkB,CAAC,YAAY,CAAC,CAAC;AAErC,KAAK,qBAAqB,GAAG;IAC3B,cAAc;IACd,eAAe,CAAC,cAAc,CAAC;CAChC,EAAE,CAAC;AAGJ,MAAM,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AAErD,MAAM,WAAW,iBAAiB,CAAC,IAAI,SAAS,gBAAgB;IAC9D,GAAG,EAAE,IAAI,CAAC;IACV,UAAU,CAAC,EAAE,YAAY,CAAC;IAC1B,YAAY,CAAC,EAAE,SAAS,CAAC;CAC1B;AA2CD,eAAO,MAAM,YAAY,IAzCC,IAAI,SAAS,gBAAgB,sCAIpD,iBAAiB,CAAC,IAAI,CAAC;;CAqC4B,CAAC"}
1
+ {"version":3,"file":"route-view-map.d.ts","sourceRoot":"","sources":["../../../src/react/components/route-view-map.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAA4B,MAAM,OAAO,CAAC;AAE5D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAEL,kBAAkB,EAClB,wBAAwB,EACzB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,eAAe,CAAC,YAAY,SAAS,cAAc,IAE3D,IAAI,CAAC,wBAAwB,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,GAErD,kBAAkB,CAAC,YAAY,CAAC,CAAC;AAErC,KAAK,qBAAqB,GAAG;IAC3B,cAAc;IACd,eAAe,CAAC,cAAc,CAAC;CAChC,EAAE,CAAC;AAGJ,MAAM,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AAErD,MAAM,WAAW,iBAAiB,CAAC,IAAI,SAAS,gBAAgB;IAC9D,GAAG,EAAE,IAAI,CAAC;IACV,UAAU,CAAC,EAAE,YAAY,CAAC;IAC1B,YAAY,CAAC,EAAE,SAAS,CAAC;CAC1B;AA2CD,eAAO,MAAM,YAAY,IAzCC,IAAI,SAAS,gBAAgB,sCAIpD,iBAAiB,CAAC,IAAI,CAAC;;CAqC4B,CAAC"}
@@ -1,19 +1,31 @@
1
1
  import { ComponentType, ReactNode } from 'react';
2
- import type { AnyRoute, AnyRouteEntity, AnyVirtualRoute } from '../../core/index.js';
3
- export type RouteViewComponent<TRouteEntity extends AnyRouteEntity> = ComponentType<RouteViewProps<TRouteEntity>>;
4
- export interface RouteViewConfigProps<TRouteEntity extends AnyRouteEntity> {
5
- route: TRouteEntity;
6
- view?: RouteViewComponent<TRouteEntity>;
7
- lazyView?: (route: TRouteEntity) => Promise<ComponentType<RouteViewProps<TRouteEntity>>>;
2
+ import { AbstractRouteEntity, type AnyRoute, type AnyVirtualRoute } from '../../core/index.js';
3
+ export type RouteViewComponent<TRoute extends AbstractRouteEntity> = ComponentType<RouteViewProps<TRoute>>;
4
+ export interface RouteViewConfigProps<TRoute extends AbstractRouteEntity> {
5
+ route: TRoute;
6
+ view?: RouteViewComponent<TRoute>;
7
+ lazyView?: (route: TRoute) => Promise<ComponentType<RouteViewProps<TRoute>>>;
8
8
  loader?: ComponentType;
9
9
  fallbackView?: ReactNode;
10
- children?: ReactNode;
10
+ children?: ReactNode | ((params: RouteViewProps<TRoute>['params'], route: TRoute) => ReactNode);
11
+ }
12
+ interface RouteViewConfigWithoutRoute {
13
+ children?: ReactNode | (() => ReactNode);
14
+ }
15
+ export interface RouteViewConfigWithRoute<TRoute extends AbstractRouteEntity> {
16
+ route: TRoute;
17
+ view?: RouteViewComponent<TRoute>;
18
+ lazyView?: (route: TRoute) => Promise<ComponentType<RouteViewProps<TRoute>>>;
19
+ loader?: ComponentType;
20
+ fallbackView?: ReactNode;
21
+ children?: ReactNode | ((params: RouteViewProps<TRoute>['params'], route: TRoute) => ReactNode);
11
22
  }
12
- export type RouteViewProps<TRouteEntity extends AnyRouteEntity> = {
23
+ export type RouteViewConfig<TRoute extends AbstractRouteEntity> = RouteViewConfigWithRoute<TRoute> | RouteViewConfigWithoutRoute;
24
+ export type RouteViewProps<TRoute extends AbstractRouteEntity> = {
13
25
  children?: ReactNode;
14
- params: TRouteEntity extends AnyRoute ? Exclude<TRouteEntity['params'], null | undefined> : TRouteEntity extends AnyVirtualRoute ? TRouteEntity['params'] : never;
26
+ params: TRoute extends AnyRoute ? Exclude<TRoute['params'], null | undefined> : TRoute extends AnyVirtualRoute ? TRoute['params'] : never;
15
27
  };
16
- declare function RouteViewBase<TRouteEntity extends AnyRouteEntity>(props: RouteViewConfigProps<TRouteEntity>): string | number | boolean | Iterable<ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
28
+ declare function RouteViewBase<TRoute extends AbstractRouteEntity>(props: Readonly<RouteViewConfig<TRoute>>): ReactNode;
17
29
  export declare const RouteView: typeof RouteViewBase & {
18
30
  displayName: string;
19
31
  };
@@ -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;AAGzD,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EACd,eAAe,EAChB,MAAM,qBAAqB,CAAC;AAE7B,MAAM,MAAM,kBAAkB,CAAC,YAAY,SAAS,cAAc,IAChE,aAAa,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAAC;AAE9C,MAAM,WAAW,oBAAoB,CAAC,YAAY,SAAS,cAAc;IACvE,KAAK,EAAE,YAAY,CAAC;IACpB,IAAI,CAAC,EAAE,kBAAkB,CAAC,YAAY,CAAC,CAAC;IACxC,QAAQ,CAAC,EAAE,CACT,KAAK,EAAE,YAAY,KAChB,OAAO,CAAC,aAAa,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAC1D,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,MAAM,MAAM,cAAc,CAAC,YAAY,SAAS,cAAc,IAAI;IAChE,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,YAAY,SAAS,QAAQ,GACjC,OAAO,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC,GACjD,YAAY,SAAS,eAAe,GAClC,YAAY,CAAC,QAAQ,CAAC,GACtB,KAAK,CAAC;CACb,CAAC;AAEF,iBAAS,aAAa,CAAC,YAAY,SAAS,cAAc,EACxD,KAAK,EAAE,oBAAoB,CAAC,YAAY,CAAC,gHA6B1C;AAED,eAAO,MAAM,SAAS;;CAA0B,CAAC"}
1
+ {"version":3,"file":"route-view.d.ts","sourceRoot":"","sources":["../../../src/react/components/route-view.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAA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CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC;CAC9E;AAED,MAAM,MAAM,eAAe,CAAC,MAAM,SAAS,mBAAmB,IAC1D,wBAAwB,CAAC,MAAM,CAAC,GAChC,2BAA2B,CAAC;AAEhC,MAAM,MAAM,cAAc,CAAC,MAAM,SAAS,mBAAmB,IAAI;IAC/D,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,mBAAmB,EACvD,KAAK,EAAE,QAAQ,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,GACvC,SAAS,CAsCX;AAED,eAAO,MAAM,SAAS;;CAA0B,CAAC"}
@@ -5,6 +5,11 @@ import { loadable } from 'react-simple-loadable';
5
5
  function RouteViewBase(props) {
6
6
  const lazyViewComponentRef = useRef();
7
7
  let Component;
8
+ if (!('route' in props)) {
9
+ return typeof props.children === 'function'
10
+ ? props.children()
11
+ : props.children;
12
+ }
8
13
  if (!props.route.isOpened) {
9
14
  return props.fallbackView ?? null;
10
15
  }
@@ -18,6 +23,12 @@ function RouteViewBase(props) {
18
23
  Component = props.view;
19
24
  }
20
25
  const params = 'params' in props.route ? props.route.params : {};
21
- return Component ? (_jsx(Component, { params: params, children: props.children })) : (props.children);
26
+ if (Component) {
27
+ return _jsx(Component, { params: params, children: props.children });
28
+ }
29
+ if (typeof props.children === 'function') {
30
+ return props.children(params, props.route);
31
+ }
32
+ return props.children;
22
33
  }
23
34
  export const RouteView = observer(RouteViewBase);
@@ -0,0 +1,8 @@
1
+ import { ReactNode } from 'react';
2
+ export interface SwitchProps {
3
+ children: ReactNode;
4
+ }
5
+ export declare const Switch: (({ children }: SwitchProps) => ReactNode) & {
6
+ displayName: string;
7
+ };
8
+ //# sourceMappingURL=switch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"switch.d.ts","sourceRoot":"","sources":["../../../src/react/components/switch.tsx"],"names":[],"mappings":"AAEA,OAAO,EAA0C,SAAS,EAAE,MAAM,OAAO,CAAC;AAK1E,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,SAAS,CAAC;CACrB;AAwBD,eAAO,MAAM,MAAM,kBAA2B,WAAW;;CAYvD,CAAC"}
@@ -0,0 +1,27 @@
1
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
2
+ import { observer } from 'mobx-react-lite';
3
+ import { Fragment, isValidElement } from 'react';
4
+ import { flatMapDeep } from 'yummies';
5
+ const flattenChildren = (children) => flatMapDeep(children, (c) =>
6
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
7
+ // @ts-ignore
8
+ c && c.type === Fragment ? c.props.children : c);
9
+ const isValidRouteElement = (element) => {
10
+ return (isValidElement(element) &&
11
+ // @ts-ignore
12
+ element.props?.route &&
13
+ // @ts-ignore
14
+ 'isOpened' in element.props.route);
15
+ };
16
+ export const Switch = observer(({ children }) => {
17
+ let defaultElement = null;
18
+ for (const element of flattenChildren(children)) {
19
+ if (isValidRouteElement(element) && element.props.route.isOpened) {
20
+ return element;
21
+ }
22
+ else {
23
+ defaultElement = element;
24
+ }
25
+ }
26
+ return defaultElement;
27
+ });