Socket
Socket
Sign inDemoInstall

@aurelia/router-lite

Package Overview
Dependencies
7
Maintainers
1
Versions
248
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.1-dev.202303301732 to 2.0.1-dev.202304151358

3

dist/types/component-agent.d.ts

@@ -5,4 +5,3 @@ import type { ICustomElementController, ICustomElementViewModel } from '@aurelia/runtime-html';

import { Params, NavigationInstruction } from './instructions';
import { IRouteConfig } from './route';
import type { RouterOptions } from './options';
import type { RouterOptions, IRouteConfig } from './options';
export interface IRouteViewModel extends ICustomElementViewModel {

@@ -9,0 +8,0 @@ getRouteConfig?(parentConfig: IRouteConfig | null, routeNode: RouteNode | null): IRouteConfig | Promise<IRouteConfig>;

@@ -1,2 +0,2 @@

export { type IViewport, FallbackFunction, } from './resources/viewport';
export { type IViewport, } from './resources/viewport';
export { RouterConfiguration, RouterRegistration, DefaultComponents, DefaultResources, ViewportCustomElement, ViewportCustomElementRegistration, LoadCustomAttribute, LoadCustomAttributeRegistration, HrefCustomAttribute, HrefCustomAttributeRegistration, IRouterConfigurationOptions, } from './configuration';

@@ -6,3 +6,3 @@ export { type IRouteViewModel, ComponentAgent, } from './component-agent';

export { ILocationManager, } from './location-manager';
export { type Routeable, type IRouteConfig, type IChildRouteConfig, RouteConfig, Route, type RouteType, route, } from './route';
export { RouteConfig, Route, type RouteType, route, } from './route';
export { IRouteContext, RouteContext, type INavigationModel, type INavigationRoute, } from './route-context';

@@ -12,3 +12,3 @@ export { AST, RouteExpression, CompositeSegmentExpression, ScopedSegmentExpression, SegmentGroupExpression, SegmentExpression, ComponentExpression, ActionExpression, ViewportExpression, ParameterListExpression, ParameterExpression, ExpressionKind, } from './route-expression';

export { isManagedState, toManagedState, IRouter, Router, Transition, } from './router';
export { IRouterOptions, type INavigationOptions, RouterOptions, NavigationOptions, type HistoryStrategy, } from './options';
export { IRouterOptions, type INavigationOptions, RouterOptions, NavigationOptions, type HistoryStrategy, FallbackFunction, type Routeable, type IRouteConfig, type IChildRouteConfig, } from './options';
export { AuNavId, type ManagedState, IRouterEvents, type RouterEvent, LocationChangeEvent, NavigationStartEvent, NavigationEndEvent, NavigationCancelEvent, NavigationErrorEvent, } from './router-events';

@@ -15,0 +15,0 @@ export { IStateManager, } from './state-manager';

@@ -1,4 +0,5 @@

import type { Params, RouteContextLike, ViewportInstructionTree } from './instructions';
import type { Params, RouteContextLike, RouteableComponent, ViewportInstruction, ViewportInstructionTree } from './instructions';
import type { RouteNode } from './route-tree';
import type { Transition } from './router';
import type { IRouteContext } from './route-context';
export type HistoryStrategy = 'none' | 'replace' | 'push';

@@ -34,2 +35,8 @@ export type ValueOrFunc<T extends string> = T | ((instructions: ViewportInstructionTree) => T);

readonly useNavigationModel: boolean;
/**
* The class that is added to the element by the `load` custom attribute, if the associated instruction is active.
* If no value is provided while configuring router, no class will be added.
* The default value is `null`.
*/
readonly activeClass: string | null;
protected constructor(useUrlFragmentHash: boolean, useHref: boolean,

@@ -57,3 +64,9 @@ /**

*/
useNavigationModel: boolean);
useNavigationModel: boolean,
/**
* The class that is added to the element by the `load` custom attribute, if the associated instruction is active.
* If no value is provided while configuring router, no class will be added.
* The default value is `null`.
*/
activeClass: string | null);
static create(input: IRouterOptions): RouterOptions;

@@ -93,2 +106,3 @@ toString(): string;

readonly state: Params | null;
readonly transitionPlan: TransitionPlan | null;
private constructor();

@@ -98,2 +112,81 @@ static create(routerOptions: RouterOptions, input: INavigationOptions): NavigationOptions;

}
export type FallbackFunction = (viewportInstruction: ViewportInstruction, routeNode: RouteNode, context: IRouteContext) => Routeable | null;
/**
* Either a `RouteableComponent` or a name/config that can be resolved to a one:
* - `string`: a string representing the component name. Must be resolveable via DI from the context of the component relative to which the navigation occurs (specified in the `dependencies` array, `<import>`ed in the view, declared as an inline template, or registered globally)
* - `IChildRouteConfig`: a standalone child route config object.
* - `RouteableComponent`: see `RouteableComponent`.
*
* NOTE: differs from `NavigationInstruction` only in having `IChildRouteConfig` instead of `IViewportIntruction`
* (which in turn are quite similar, but do have a few minor but important differences that make them non-interchangeable)
* as well as `IRedirectRouteConfig`
*/
export type Routeable = string | IChildRouteConfig | IRedirectRouteConfig | RouteableComponent;
export interface IRouteConfig {
/**
* The id for this route, which can be used in the view for generating hrefs.
*/
readonly id?: string | null;
/**
* The path to match against the url.
*
* If left blank, the path will be derived from the component's static `path` property (if it exists).
*/
readonly path?: string | string[] | null;
/**
* The title to use for this route when matched.
*
* If left blank, this route will not contribute to the generated title.
*/
readonly title?: string | ((node: RouteNode) => string | null) | null;
/**
* The path to which to redirect when the url matches the path in this config.
*/
readonly redirectTo?: string | null;
/**
* Whether the `path` should be case sensitive.
*/
readonly caseSensitive?: boolean;
/**
* How to behave when this component scheduled to be loaded again in the same viewport:
*
* - `replace`: completely removes the current component and creates a new one, behaving as if the component changed (default if only the parameters have changed).
* - `invoke-lifecycles`: calls `canUnload`, `canLoad`, `unloading` and `loading`.
* - `none`: does nothing (default if nothing has changed for the viewport).
*/
readonly transitionPlan?: TransitionPlanOrFunc | null;
/**
* The name of the viewport this component should be loaded into.
*/
readonly viewport?: string | null;
/**
* Any custom data that should be accessible to matched components or hooks.
*/
readonly data?: Record<string, unknown>;
/**
* The child routes that can be navigated to from this route. See `Routeable` for more information.
*/
readonly routes?: readonly Routeable[];
/**
* When set, will be used to redirect unknown/unconfigured routes to this route.
* Can be a route-id, route-path (route), or a custom element name; this is also the resolution/fallback order.
*/
readonly fallback?: Routeable | FallbackFunction | null;
/**
* When set to `false`, the routes won't be included in the navigation model.
*
* @default true
*/
readonly nav?: boolean;
}
export interface IChildRouteConfig extends IRouteConfig {
/**
* The component to load when this route is matched.
*/
readonly component: Routeable;
}
export interface IRedirectRouteConfig extends Pick<IRouteConfig, 'caseSensitive' | 'redirectTo' | 'path'> {
}
export type TransitionPlan = 'none' | 'replace' | 'invoke-lifecycles';
export type TransitionPlanOrFunc = TransitionPlan | ((current: RouteNode, next: RouteNode) => TransitionPlan);
//# sourceMappingURL=options.d.ts.map

@@ -1,6 +0,5 @@

import { ICustomAttributeViewModel, ICustomAttributeController, IEventTarget, INode, IWindow } from '@aurelia/runtime-html';
import { ICustomAttributeViewModel, ICustomAttributeController, INode, IWindow } from '@aurelia/runtime-html';
import { IRouter } from '../router';
import { IRouteContext } from '../route-context';
export declare class HrefCustomAttribute implements ICustomAttributeViewModel {
private readonly target;
private readonly el;

@@ -14,3 +13,3 @@ private readonly router;

readonly $controller: ICustomAttributeController<this>;
constructor(target: IEventTarget, el: INode<HTMLElement>, router: IRouter, ctx: IRouteContext, w: IWindow);
constructor(el: INode<HTMLElement>, router: IRouter, ctx: IRouteContext, w: IWindow);
binding(): void;

@@ -17,0 +16,0 @@ unbinding(): void;

@@ -1,2 +0,2 @@

import { ICustomAttributeViewModel, IEventTarget, INode } from '@aurelia/runtime-html';
import { ICustomAttributeViewModel, INode } from '@aurelia/runtime-html';
import { IRouter } from '../router';

@@ -8,3 +8,2 @@ import { IRouteContext } from '../route-context';

export declare class LoadCustomAttribute implements ICustomAttributeViewModel {
private readonly target;
private readonly el;

@@ -27,3 +26,4 @@ private readonly router;

private readonly isEnabled;
constructor(target: IEventTarget, el: INode<HTMLElement>, router: IRouter, events: IRouterEvents, ctx: IRouteContext, locationMgr: ILocationManager);
private readonly activeClass;
constructor(el: INode<HTMLElement>, router: IRouter, events: IRouterEvents, ctx: IRouteContext, locationMgr: ILocationManager);
binding(): void;

@@ -30,0 +30,0 @@ attaching(): void | Promise<void>;

import { ILogger } from '@aurelia/kernel';
import { ICustomElementViewModel, IHydratedController, ICompiledCustomElementController } from '@aurelia/runtime-html';
import { IRouteContext } from '../route-context';
import { type ViewportInstruction } from '../instructions';
import { type RouteNode } from '../route-tree';
export type FallbackFunction = (viewportInstruction: ViewportInstruction, routeNode: RouteNode, context: IRouteContext) => string | null;
import { FallbackFunction, Routeable } from '../options';
export interface IViewport {

@@ -11,3 +9,3 @@ readonly name: string;

readonly default: string;
readonly fallback: string | FallbackFunction;
readonly fallback: Routeable | FallbackFunction;
}

@@ -20,3 +18,3 @@ export declare class ViewportCustomElement implements ICustomElementViewModel, IViewport {

default: string;
fallback: string | FallbackFunction;
fallback: Routeable | FallbackFunction;
private agent;

@@ -23,0 +21,0 @@ private controller;

@@ -6,4 +6,5 @@ import { type IContainer, IModule } from '@aurelia/kernel';

import { NavigationInstruction, Params, ViewportInstruction } from './instructions';
import { IChildRouteConfig } from './options';
import { IViewport } from './resources/viewport';
import { IChildRouteConfig, RouteConfig, RouteType } from './route';
import { RouteConfig, RouteType } from './route';
import type { RouteNode } from './route-tree';

@@ -115,3 +116,2 @@ import { IRouter } from './router';

}
export declare const INavigationModel: import("@aurelia/kernel").InterfaceSymbol<INavigationModel>;
export interface INavigationModel {

@@ -118,0 +118,0 @@ /**

import { Constructable, ResourceType, IContainer } from '@aurelia/kernel';
import { RouteableComponent } from './instructions';
import type { RouteNode } from './route-tree';
import { FallbackFunction } from './resources/viewport';
import type { FallbackFunction, IChildRouteConfig, IRouteConfig, Routeable, TransitionPlan, TransitionPlanOrFunc } from './options';
export declare const noRoutes: readonly Routeable[];
/**
* Either a `RouteableComponent` or a name/config that can be resolved to a one:
* - `string`: a string representing the component name. Must be resolveable via DI from the context of the component relative to which the navigation occurs (specified in the `dependencies` array, `<import>`ed in the view, declared as an inline template, or registered globally)
* - `IChildRouteConfig`: a standalone child route config object.
* - `RouteableComponent`: see `RouteableComponent`.
*
* NOTE: differs from `NavigationInstruction` only in having `IChildRouteConfig` instead of `IViewportIntruction`
* (which in turn are quite similar, but do have a few minor but important differences that make them non-interchangeable)
* as well as `IRedirectRouteConfig`
*/
export type Routeable = string | IChildRouteConfig | IRedirectRouteConfig | RouteableComponent;
export interface IRouteConfig {
/**
* The id for this route, which can be used in the view for generating hrefs.
*/
readonly id?: string | null;
/**
* The path to match against the url.
*
* If left blank, the path will be derived from the component's static `path` property (if it exists).
*/
readonly path?: string | string[] | null;
/**
* The title to use for this route when matched.
*
* If left blank, this route will not contribute to the generated title.
*/
readonly title?: string | ((node: RouteNode) => string | null) | null;
/**
* The path to which to redirect when the url matches the path in this config.
*/
readonly redirectTo?: string | null;
/**
* Whether the `path` should be case sensitive.
*/
readonly caseSensitive?: boolean;
/**
* How to behave when this component scheduled to be loaded again in the same viewport:
*
* - `replace`: completely removes the current component and creates a new one, behaving as if the component changed (default if only the parameters have changed).
* - `invoke-lifecycles`: calls `canUnload`, `canLoad`, `unloading` and `loading`.
* - `none`: does nothing (default if nothing has changed for the viewport).
*/
readonly transitionPlan?: TransitionPlanOrFunc | null;
/**
* The name of the viewport this component should be loaded into.
*/
readonly viewport?: string | null;
/**
* Any custom data that should be accessible to matched components or hooks.
*/
readonly data?: Record<string, unknown>;
/**
* The child routes that can be navigated to from this route. See `Routeable` for more information.
*/
readonly routes?: readonly Routeable[];
/**
* When set, will be used to redirect unknown/unconfigured routes to this route.
* Can be a route-id, route-path (route), or a custom element name; this is also the resolution/fallback order.
*/
readonly fallback?: string | FallbackFunction | null;
/**
* When set to `false`, the routes won't be included in the navigation model.
*
* @default true
*/
readonly nav?: boolean;
}
export interface IChildRouteConfig extends IRouteConfig {
/**
* The component to load when this route is matched.
*/
readonly component: Routeable;
}
export interface IRedirectRouteConfig extends Pick<IRouteConfig, 'caseSensitive' | 'redirectTo' | 'path'> {
}
export type TransitionPlan = 'none' | 'replace' | 'invoke-lifecycles';
export type TransitionPlanOrFunc = TransitionPlan | ((current: RouteNode, next: RouteNode) => TransitionPlan);
export declare class RouteConfig implements IRouteConfig, IChildRouteConfig {

@@ -93,9 +14,7 @@ readonly id: string;

readonly routes: readonly Routeable[];
readonly fallback: string | FallbackFunction | null;
readonly fallback: Routeable | FallbackFunction | null;
readonly component: Routeable;
readonly nav: boolean;
get path(): string[];
protected constructor(id: string,
/** @internal */
_path: string[], title: string | ((node: RouteNode) => string | null) | null, redirectTo: string | null, caseSensitive: boolean, transitionPlan: TransitionPlanOrFunc | null, viewport: string, data: Record<string, unknown>, routes: readonly Routeable[], fallback: string | FallbackFunction | null, component: Routeable, nav: boolean);
private constructor();
getTransitionPlan(cur: RouteNode, next: RouteNode): TransitionPlan;

@@ -113,3 +32,3 @@ register(container: IContainer): void;

*/
configure<T extends RouteType<Constructable<{}>>>(configOrPath: IRouteConfig | IChildRouteConfig | string | string[], Type: T): T;
configure<T extends RouteType<Constructable>>(configOrPath: IRouteConfig | IChildRouteConfig | string | string[], Type: T): T;
/**

@@ -116,0 +35,0 @@ * Get the `RouteConfig` associated with the specified type, creating a new one if it does not yet exist.

import { type PartialCustomElementDefinition } from '@aurelia/runtime-html';
import type { IChildRouteConfig, IRedirectRouteConfig } from './route';
import type { IChildRouteConfig, IRedirectRouteConfig } from './options';
import type { IViewportInstruction, Params, RouteableComponent } from './instructions';

@@ -4,0 +4,0 @@ export declare function isPartialCustomElementDefinition(value: RouteableComponent | IChildRouteConfig | null | undefined): value is PartialCustomElementDefinition;

{
"name": "@aurelia/router-lite",
"version": "2.0.1-dev.202303301732",
"version": "2.0.1-dev.202304151358",
"main": "dist/cjs/index.cjs",

@@ -52,12 +52,12 @@ "module": "dist/esm/index.mjs",

"dependencies": {
"@aurelia/kernel": "2.0.1-dev.202303301732",
"@aurelia/metadata": "2.0.1-dev.202303301732",
"@aurelia/platform": "2.0.1-dev.202303301732",
"@aurelia/platform-browser": "2.0.1-dev.202303301732",
"@aurelia/route-recognizer": "2.0.1-dev.202303301732",
"@aurelia/runtime": "2.0.1-dev.202303301732",
"@aurelia/runtime-html": "2.0.1-dev.202303301732"
"@aurelia/kernel": "2.0.1-dev.202304151358",
"@aurelia/metadata": "2.0.1-dev.202304151358",
"@aurelia/platform": "2.0.1-dev.202304151358",
"@aurelia/platform-browser": "2.0.1-dev.202304151358",
"@aurelia/route-recognizer": "2.0.1-dev.202304151358",
"@aurelia/runtime": "2.0.1-dev.202304151358",
"@aurelia/runtime-html": "2.0.1-dev.202304151358"
},
"devDependencies": {
"typescript": "4.9.5"
"typescript": "5.0.2"
},

@@ -64,0 +64,0 @@ "engines": {

@@ -13,4 +13,3 @@ import { ILogger } from '@aurelia/kernel';

import { Batch } from './util';
import { IRouteConfig } from './route';
import type { RouterOptions } from './options';
import type { RouterOptions, IRouteConfig } from './options';

@@ -17,0 +16,0 @@ export interface IRouteViewModel extends ICustomElementViewModel {

@@ -69,2 +69,3 @@ import { isObject } from '@aurelia/metadata';

Registration.instance(IRouterOptions, routerOptions),
Registration.instance(RouterOptions, routerOptions),
AppTask.hydrated(IContainer, RouteContext.setRoot),

@@ -71,0 +72,0 @@ AppTask.activated(IRouter, router => router.start(true)),

export {
type IViewport,
FallbackFunction,
} from './resources/viewport';

@@ -44,5 +43,2 @@

export {
type Routeable,
type IRouteConfig,
type IChildRouteConfig,
RouteConfig,

@@ -95,2 +91,6 @@ Route,

type HistoryStrategy,
FallbackFunction,
type Routeable,
type IRouteConfig,
type IChildRouteConfig,
} from './options';

@@ -97,0 +97,0 @@

@@ -181,3 +181,3 @@ import { isObject } from '@aurelia/metadata';

const component = this.component.toUrlComponent();
const params = this.params === null || Object.keys(this.params).length === 0 ? '' : `(${stringifyParams(this.params)})`;
const params = this.params === null || Object.keys(this.params).length === 0 ? '' : `(${stringifyParams(this.params)})`; /** TODO(sayan): review the path generation usage and correct this stringifyParams artefact. */
const vp = this.viewport;

@@ -184,0 +184,0 @@ const viewport = component.length === 0 || vp === null || vp.length === 0 || vp === defaultViewportName ? '' : `@${vp}`;

import { DI } from '@aurelia/kernel';
import type { Params, RouteContextLike, ViewportInstructionTree } from './instructions';
import type { Params, RouteContextLike, RouteableComponent, ViewportInstruction, ViewportInstructionTree } from './instructions';
import type { RouteNode } from './route-tree';
import type { Transition } from './router';
import type { IRouteContext } from './route-context';

@@ -43,2 +44,8 @@ export type HistoryStrategy = 'none' | 'replace' | 'push';

public readonly useNavigationModel: boolean,
/**
* The class that is added to the element by the `load` custom attribute, if the associated instruction is active.
* If no value is provided while configuring router, no class will be added.
* The default value is `null`.
*/
public readonly activeClass: string | null,
) { }

@@ -53,2 +60,3 @@

input.useNavigationModel ?? true,
input.activeClass ?? null,
);

@@ -103,2 +111,3 @@ }

public readonly state: Params | null,
public readonly transitionPlan: TransitionPlan | null,
) { }

@@ -115,2 +124,3 @@

input.state ?? null,
input.transitionPlan ?? null,
);

@@ -128,2 +138,3 @@ }

this.state === null ? null : { ...this.state },
this.transitionPlan,
);

@@ -137,1 +148,84 @@ }

}
export type FallbackFunction = (viewportInstruction: ViewportInstruction, routeNode: RouteNode, context: IRouteContext) => Routeable | null;
/**
* Either a `RouteableComponent` or a name/config that can be resolved to a one:
* - `string`: a string representing the component name. Must be resolveable via DI from the context of the component relative to which the navigation occurs (specified in the `dependencies` array, `<import>`ed in the view, declared as an inline template, or registered globally)
* - `IChildRouteConfig`: a standalone child route config object.
* - `RouteableComponent`: see `RouteableComponent`.
*
* NOTE: differs from `NavigationInstruction` only in having `IChildRouteConfig` instead of `IViewportIntruction`
* (which in turn are quite similar, but do have a few minor but important differences that make them non-interchangeable)
* as well as `IRedirectRouteConfig`
*/
export type Routeable = string | IChildRouteConfig | IRedirectRouteConfig | RouteableComponent;
export interface IRouteConfig {
/**
* The id for this route, which can be used in the view for generating hrefs.
*/
readonly id?: string | null;
/**
* The path to match against the url.
*
* If left blank, the path will be derived from the component's static `path` property (if it exists).
*/
readonly path?: string | string[] | null;
/**
* The title to use for this route when matched.
*
* If left blank, this route will not contribute to the generated title.
*/
readonly title?: string | ((node: RouteNode) => string | null) | null;
/**
* The path to which to redirect when the url matches the path in this config.
*/
readonly redirectTo?: string | null;
/**
* Whether the `path` should be case sensitive.
*/
readonly caseSensitive?: boolean;
/**
* How to behave when this component scheduled to be loaded again in the same viewport:
*
* - `replace`: completely removes the current component and creates a new one, behaving as if the component changed (default if only the parameters have changed).
* - `invoke-lifecycles`: calls `canUnload`, `canLoad`, `unloading` and `loading`.
* - `none`: does nothing (default if nothing has changed for the viewport).
*/
readonly transitionPlan?: TransitionPlanOrFunc | null;
/**
* The name of the viewport this component should be loaded into.
*/
readonly viewport?: string | null;
/**
* Any custom data that should be accessible to matched components or hooks.
*/
readonly data?: Record<string, unknown>;
/**
* The child routes that can be navigated to from this route. See `Routeable` for more information.
*/
readonly routes?: readonly Routeable[];
/**
* When set, will be used to redirect unknown/unconfigured routes to this route.
* Can be a route-id, route-path (route), or a custom element name; this is also the resolution/fallback order.
*/
readonly fallback?: Routeable | FallbackFunction | null;
/**
* When set to `false`, the routes won't be included in the navigation model.
*
* @default true
*/
readonly nav?: boolean;
}
export interface IChildRouteConfig extends IRouteConfig {
/**
* The component to load when this route is matched.
*/
readonly component: Routeable;
}
export interface IRedirectRouteConfig extends Pick<IRouteConfig, 'caseSensitive' | 'redirectTo' | 'path'> { }
export type TransitionPlan = 'none' | 'replace' | 'invoke-lifecycles';
export type TransitionPlanOrFunc = TransitionPlan | ((current: RouteNode, next: RouteNode) => TransitionPlan);

@@ -7,3 +7,2 @@ import {

ICustomAttributeController,
IEventTarget,
INode,

@@ -36,3 +35,2 @@ IWindow,

// private eventListener!: IDisposable;
private isInitialized: boolean = false;

@@ -48,3 +46,2 @@ private isEnabled: boolean;

public constructor(
@IEventTarget private readonly target: IEventTarget,
@INode private readonly el: INode<HTMLElement>,

@@ -51,0 +48,0 @@ @IRouter private readonly router: IRouter,

@@ -7,3 +7,2 @@ import { IDisposable, IIndexable } from '@aurelia/kernel';

ICustomAttributeViewModel,
IEventTarget,
INode,

@@ -41,8 +40,7 @@ CustomElement,

private instructions: ViewportInstructionTree | null = null;
// private eventListener: IDisposable | null = null;
private navigationEndListener: IDisposable | null = null;
private readonly isEnabled: boolean;
private readonly activeClass: string | null;
public constructor(
@IEventTarget private readonly target: IEventTarget,
@INode private readonly el: INode<HTMLElement>,

@@ -56,2 +54,3 @@ @IRouter private readonly router: IRouter,

this.isEnabled = !el.hasAttribute('external') && !el.hasAttribute('data-external');
this.activeClass = router.options.activeClass;
}

@@ -66,3 +65,6 @@

this.valueChanged();
this.active = this.instructions !== null && this.router.isActive(this.instructions, this.context!);
const active = this.active = this.instructions !== null && this.router.isActive(this.instructions, this.context!);
const activeClass = this.activeClass;
if (activeClass === null) return;
this.el.classList.toggle(activeClass, active);
});

@@ -69,0 +71,0 @@ }

@@ -1,2 +0,2 @@

import { ILogger } from '@aurelia/kernel';
import { Constructable, ILogger } from '@aurelia/kernel';
import {

@@ -8,3 +8,4 @@ bindable,

ICustomElementController,
ICompiledCustomElementController
ICompiledCustomElementController,
CustomElement
} from '@aurelia/runtime-html';

@@ -16,5 +17,4 @@

import { type RouteNode } from '../route-tree';
import { FallbackFunction, Routeable } from '../options';
export type FallbackFunction = (viewportInstruction: ViewportInstruction, routeNode: RouteNode, context: IRouteContext) => string | null;
export interface IViewport {

@@ -24,5 +24,5 @@ readonly name: string;

readonly default: string;
readonly fallback: string | FallbackFunction;
readonly fallback: Routeable | FallbackFunction;
/** @internal */
_getFallback(viewportInstruction: ViewportInstruction, routeNode: RouteNode, context: IRouteContext): string | null;
_getFallback(viewportInstruction: ViewportInstruction, routeNode: RouteNode, context: IRouteContext): Routeable | null;
}

@@ -35,3 +35,3 @@

@bindable public default: string = '';
@bindable public fallback: string | FallbackFunction = '';
@bindable public fallback: Routeable | FallbackFunction = '';

@@ -51,6 +51,7 @@ private agent: ViewportAgent = (void 0)!;

/** @internal */
public _getFallback(viewportInstruction: ViewportInstruction, routeNode: RouteNode, context: IRouteContext): string | null {
public _getFallback(viewportInstruction: ViewportInstruction, routeNode: RouteNode, context: IRouteContext): Routeable | null {
const fallback = this.fallback;
return typeof fallback === 'function'
? fallback(viewportInstruction, routeNode, context)
&& !CustomElement.isType(fallback as Constructable)
? (fallback as FallbackFunction)(viewportInstruction, routeNode, context)
: fallback;

@@ -57,0 +58,0 @@ }

@@ -44,5 +44,7 @@ import {

NavigationOptions,
IChildRouteConfig,
Routeable,
} from './options';
import { IViewport } from './resources/viewport';
import { IChildRouteConfig, noRoutes, resolveCustomElementDefinition, resolveRouteConfiguration, Routeable, RouteConfig, RouteType } from './route';
import { noRoutes, resolveCustomElementDefinition, resolveRouteConfiguration, RouteConfig, RouteType } from './route';
import type { RouteNode } from './route-tree';

@@ -205,6 +207,5 @@ import {

container.registerResolver(
IRouteContext,
new InstanceProvider<IRouteContext>('IRouteContext', this)
);
const ctxProvider = new InstanceProvider<IRouteContext>('IRouteContext', this);
container.registerResolver(IRouteContext, ctxProvider);
container.registerResolver(RouteContext, ctxProvider);

@@ -396,3 +397,3 @@ container.register(config);

public getFallbackViewportAgent(name: string): ViewportAgent | null {
return this.childViewportAgents.find(x => x._isAvailable() && x.viewport.name === name && x.viewport.fallback.length > 0) ?? null;
return this.childViewportAgents.find(x => x._isAvailable() && x.viewport.name === name && x.viewport.fallback !== '') ?? null;
}

@@ -704,3 +705,2 @@

export const INavigationModel = DI.createInterface<INavigationModel>('INavigationModel');
export interface INavigationModel {

@@ -707,0 +707,0 @@ /**

@@ -440,18 +440,20 @@ import {

// fallback: id -> route -> CEDefn (Route configuration)
// look for a route first
log.trace(`Fallback is set to '${fallback}'. Looking for a recognized route.`);
const rd = (ctx.childRoutes as RouteConfig[]).find(x => x.id === fallback);
if (rd !== void 0) return appendNode(log, node, createFallbackNode(log, rd, node, vi as ViewportInstruction<ITypedNavigationInstruction_string>));
if (typeof fallback === 'string') {
// fallback: id -> route -> CEDefn (Route configuration)
// look for a route first
log.trace(`Fallback is set to '${fallback}'. Looking for a recognized route.`);
const rd = (ctx.childRoutes as RouteConfig[]).find(x => x.id === fallback);
if (rd !== void 0) return appendNode(log, node, createFallbackNode(log, rd, node, vi as ViewportInstruction<ITypedNavigationInstruction_string>));
log.trace(`No route configuration for the fallback '${fallback}' is found; trying to recognize the route.`);
const rr = ctx.recognize(fallback, true);
if (rr !== null && rr.residue !== fallback) return appendNode(log, node, createConfiguredNode(log, node, vi as ViewportInstruction<ITypedNavigationInstruction_ResolvedComponent>, rr, null));
log.trace(`No route configuration for the fallback '${fallback}' is found; trying to recognize the route.`);
const rr = ctx.recognize(fallback, true);
if (rr !== null && rr.residue !== fallback) return appendNode(log, node, createConfiguredNode(log, node, vi as ViewportInstruction<ITypedNavigationInstruction_ResolvedComponent>, rr, null));
}
// fallback is not recognized as a configured route; treat as CE and look for a route configuration.
log.trace(`The fallback '${fallback}' is not recognized as a route; treating as custom element name.`);
return appendNode(log, node, createFallbackNode(log,
resolveRouteConfiguration(fallback, false, ctx.config, null, ctx) as RouteConfig, // TODO: fix the typing by adding overloads.
node,
vi as ViewportInstruction<ITypedNavigationInstruction_string>));
return onResolve(
resolveRouteConfiguration(fallback, false, ctx.config, null, ctx),
rc => appendNode(log, node, createFallbackNode(log, rc, node, vi as ViewportInstruction<ITypedNavigationInstruction_string>))
);
}

@@ -458,0 +460,0 @@

@@ -5,5 +5,4 @@ import { Metadata } from '@aurelia/metadata';

import { validateRouteConfig, expectType, shallowEquals, isPartialRedirectRouteConfig, isPartialChildRouteConfig } from './validation';
import { defaultViewportName, ITypedNavigationInstruction_Component, NavigationInstructionType, RouteableComponent, TypedNavigationInstruction, ViewportInstruction } from './instructions';
import { defaultViewportName, ITypedNavigationInstruction_Component, NavigationInstructionType, TypedNavigationInstruction, ViewportInstruction } from './instructions';
import type { RouteNode } from './route-tree';
import { FallbackFunction } from './resources/viewport';
import type { IRouteContext } from './route-context';

@@ -13,85 +12,6 @@ import { CustomElement, CustomElementDefinition } from '@aurelia/runtime-html';

import { ensureArrayOfStrings, ensureString } from './util';
import type { FallbackFunction, IChildRouteConfig, IRedirectRouteConfig, IRouteConfig, Routeable, TransitionPlan, TransitionPlanOrFunc } from './options';
export const noRoutes = emptyArray as RouteConfig['routes'];
/**
* Either a `RouteableComponent` or a name/config that can be resolved to a one:
* - `string`: a string representing the component name. Must be resolveable via DI from the context of the component relative to which the navigation occurs (specified in the `dependencies` array, `<import>`ed in the view, declared as an inline template, or registered globally)
* - `IChildRouteConfig`: a standalone child route config object.
* - `RouteableComponent`: see `RouteableComponent`.
*
* NOTE: differs from `NavigationInstruction` only in having `IChildRouteConfig` instead of `IViewportIntruction`
* (which in turn are quite similar, but do have a few minor but important differences that make them non-interchangeable)
* as well as `IRedirectRouteConfig`
*/
export type Routeable = string | IChildRouteConfig | IRedirectRouteConfig | RouteableComponent;
export interface IRouteConfig {
/**
* The id for this route, which can be used in the view for generating hrefs.
*/
readonly id?: string | null;
/**
* The path to match against the url.
*
* If left blank, the path will be derived from the component's static `path` property (if it exists).
*/
readonly path?: string | string[] | null;
/**
* The title to use for this route when matched.
*
* If left blank, this route will not contribute to the generated title.
*/
readonly title?: string | ((node: RouteNode) => string | null) | null;
/**
* The path to which to redirect when the url matches the path in this config.
*/
readonly redirectTo?: string | null;
/**
* Whether the `path` should be case sensitive.
*/
readonly caseSensitive?: boolean;
/**
* How to behave when this component scheduled to be loaded again in the same viewport:
*
* - `replace`: completely removes the current component and creates a new one, behaving as if the component changed (default if only the parameters have changed).
* - `invoke-lifecycles`: calls `canUnload`, `canLoad`, `unloading` and `loading`.
* - `none`: does nothing (default if nothing has changed for the viewport).
*/
readonly transitionPlan?: TransitionPlanOrFunc | null;
/**
* The name of the viewport this component should be loaded into.
*/
readonly viewport?: string | null;
/**
* Any custom data that should be accessible to matched components or hooks.
*/
readonly data?: Record<string, unknown>;
/**
* The child routes that can be navigated to from this route. See `Routeable` for more information.
*/
readonly routes?: readonly Routeable[];
/**
* When set, will be used to redirect unknown/unconfigured routes to this route.
* Can be a route-id, route-path (route), or a custom element name; this is also the resolution/fallback order.
*/
readonly fallback?: string | FallbackFunction | null;
/**
* When set to `false`, the routes won't be included in the navigation model.
*
* @default true
*/
readonly nav?: boolean;
}
export interface IChildRouteConfig extends IRouteConfig {
/**
* The component to load when this route is matched.
*/
readonly component: Routeable;
}
export interface IRedirectRouteConfig extends Pick<IRouteConfig, 'caseSensitive' | 'redirectTo' | 'path'> { }
export type TransitionPlan = 'none' | 'replace' | 'invoke-lifecycles';
export type TransitionPlanOrFunc = TransitionPlan | ((current: RouteNode, next: RouteNode) => TransitionPlan);
function defaultReentryBehavior(current: RouteNode, next: RouteNode): TransitionPlan {

@@ -112,5 +32,6 @@ if (!shallowEquals(current.params, next.params)) {

if (path.length > 0) return path;
return this._path = [CustomElement.getDefinition(this.component as RouteType).name];
const ceDfn = CustomElement.getDefinition(this.component as RouteType);
return this._path = [ceDfn.name, ...ceDfn.aliases];
}
protected constructor(
private constructor(
public readonly id: string,

@@ -126,3 +47,3 @@ /** @internal */

public readonly routes: readonly Routeable[],
public readonly fallback: string | FallbackFunction | null,
public readonly fallback: Routeable | FallbackFunction | null,
public readonly component: Routeable,

@@ -172,3 +93,3 @@ public readonly nav: boolean,

const id = config.id ?? Type?.id ?? (path instanceof Array ? path[0] : path);
const reentryBehavior = config.transitionPlan ?? Type?.transitionPlan ?? /* parentConfig?.transitionPlan ?? */ null;
const reentryBehavior = config.transitionPlan ?? Type?.transitionPlan ?? null;
const viewport = config.viewport ?? Type?.viewport ?? defaultViewportName;

@@ -283,6 +204,7 @@ const data = {

/** @internal */
public _getFallback(viewportInstruction: ViewportInstruction, routeNode: RouteNode, context: IRouteContext): string | null {
public _getFallback(viewportInstruction: ViewportInstruction, routeNode: RouteNode, context: IRouteContext): Routeable | null {
const fallback = this.fallback;
return typeof fallback === 'function'
? fallback(viewportInstruction, routeNode, context)
&& !CustomElement.isType(fallback as Constructable)
? (fallback as FallbackFunction)(viewportInstruction, routeNode, context)
: fallback;

@@ -292,4 +214,9 @@ }

public register(container: IContainer): void {
const component= this.component;
if(component == null) return;
/**
* When an instance of the RouteConfig is created, via the static `_create` and `resolveRouteConfiguration`, the component is always resolved to a custom element.
* This makes the process to registering to registering the custom element to the DI.
* The component can only be null for redirection configurations and that is ignored here.
*/
const component = this.component;
if (component == null) return;
container.register(component);

@@ -314,3 +241,3 @@ }

): T {
const config = RouteConfig._create(configOrPath, Type /* , isDefinedByType , null */);
const config = RouteConfig._create(configOrPath, Type);
Metadata.define(Route.name, config, Type);

@@ -317,0 +244,0 @@

import { isObject } from '@aurelia/metadata';
import { IContainer, ILogger, DI, IDisposable, onResolve, Writable, resolveAll } from '@aurelia/kernel';
import { IContainer, ILogger, DI, IDisposable, onResolve, Writable, resolveAll, Registration, IResolver } from '@aurelia/kernel';
import { CustomElement, CustomElementDefinition, IPlatform } from '@aurelia/runtime-html';

@@ -196,2 +196,3 @@

this.instructions = ViewportInstructionTree.create('', options);
container.registerResolver(Router, Registration.instance(Router, this) as unknown as IResolver<Router>);
}

@@ -409,10 +410,19 @@

instructionOrInstructions = this.locationMgr.removeBaseHref(instructionOrInstructions);
if ((instructionOrInstructions as string).startsWith('../') && context !== null) {
context = this.resolveContext(context);
while ((instructionOrInstructions as string).startsWith('../') && (context?.parent ?? null) !== null) {
instructionOrInstructions = (instructionOrInstructions as string).slice(3);
context = context!.parent;
}
}
const isVpInstr = typeof instructionOrInstructions !== 'string' && 'component' in instructionOrInstructions;
let $instruction = isVpInstr ? (instructionOrInstructions as IViewportInstruction).component : instructionOrInstructions;
if (typeof $instruction === 'string' && $instruction.startsWith('../') && context !== null) {
context = this.resolveContext(context);
while (($instruction as string).startsWith('../') && (context?.parent ?? null) !== null) {
$instruction = ($instruction as string).slice(3);
context = context!.parent;
}
}
if(isVpInstr) {
(instructionOrInstructions as Writable<IViewportInstruction>).component = $instruction;
} else {
instructionOrInstructions = $instruction;
}
const routerOptions = this.options;

@@ -419,0 +429,0 @@ return ViewportInstructionTree.create(

import type { IIndexable } from '@aurelia/kernel';
import { isCustomElementViewModel, type PartialCustomElementDefinition } from '@aurelia/runtime-html';
import type { IChildRouteConfig, IRedirectRouteConfig, Routeable } from './route';
import type { IChildRouteConfig, IRedirectRouteConfig, Routeable } from './options';
import type { IViewportInstruction, Params, RouteableComponent } from './instructions';

@@ -116,3 +116,3 @@ import { tryStringify } from './util';

case 'component':
validateComponent(value, path);
validateComponent(value, path, 'component');
break;

@@ -125,3 +125,3 @@ case 'routes': {

const childPath = `${path}[${value.indexOf(route)}]`;
validateComponent(route, childPath);
validateComponent(route, childPath, 'component');
}

@@ -149,9 +149,3 @@ break;

case 'fallback':
switch(typeof value) {
case 'string':
case 'function':
break;
default:
expectType('string or function', path, value);
}
validateComponent(value, path, 'fallback');
break;

@@ -198,3 +192,3 @@ default:

function validateComponent(component: Routeable | null | undefined, parentPath: string): void {
function validateComponent(component: Routeable | null | undefined, parentPath: string, property: string): void {
switch (typeof component) {

@@ -219,3 +213,3 @@ case 'function':

) {
expectType(`an object with at least a 'component' property (see Routeable)`, parentPath, component);
expectType(`an object with at least a '${property}' property (see Routeable)`, parentPath, component);
}

@@ -222,0 +216,0 @@ break;

@@ -10,5 +10,4 @@ // No-fallthrough disabled due to large numbers of false positives

import type { IRouteContext } from './route-context';
import type { NavigationOptions } from './options';
import type { NavigationOptions, TransitionPlan } from './options';
import type { Transition } from './router';
import type { TransitionPlan } from './route';
import { Batch, mergeDistinct } from './util';

@@ -696,3 +695,3 @@ import { ViewportInstruction, defaultViewportName } from './instructions';

// Component is the same, so determine plan based on config and/or convention
this.$plan = next.context.config.getTransitionPlan(cur, next);
this.$plan = options.transitionPlan ?? next.context.config.getTransitionPlan(cur, next);
}

@@ -699,0 +698,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc