Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Export the events and titles modules so RoutingEventSink, DefaultRoutingEventSink, TitleBuilder and DefaultTitleBuilder can be used from the package entry point.",
"packageName": "@microsoft/fast-router",
"email": "144495202+AKnassa@users.noreply.github.com",
"dependentChangeType": "none"
}
49 changes: 45 additions & 4 deletions packages/fast-router/docs/api-report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,29 @@ export class DefaultRouteRecognizer<TSettings> implements RouteRecognizer<TSetti
recognize(path: string, converters?: Readonly<Record<string, RouteParameterConverter>>): Promise<RecognizedRoute<TSettings> | null>;
}

// @beta (undocumented)
export class DefaultRoutingEventSink implements RoutingEventSink {
// (undocumented)
onNavigationBegin(router: Router, route: RecognizedRoute, command: NavigationCommand): void;
// (undocumented)
onNavigationEnd(router: Router, route: RecognizedRoute, command: NavigationCommand): void;
// (undocumented)
onPhaseBegin(phase: NavigationPhase): void;
// (undocumented)
onPhaseEnd(phase: NavigationPhase): void;
// (undocumented)
onUnhandledNavigationMessage(router: Router, message: NavigationMessage): void;
}

// @beta (undocumented)
export class DefaultTitleBuilder implements TitleBuilder {
constructor(segmentSeparator?: string, fragmentSeparator?: string);
// (undocumented)
buildTitle(rootTitle: string, routeTitles: string[][]): string;
// (undocumented)
joinTitles(parentTitle: string, childTitle: string): string;
}

// @beta (undocumented)
export type DefinitionCallback = () => Promise<FallbackRouteDefinition> | FallbackRouteDefinition;

Expand Down Expand Up @@ -531,8 +554,6 @@ export abstract class RouterConfiguration<TSettings = any> {
construct<T>(Type: Constructable<T>): T;
// (undocumented)
readonly contributors: NavigationContributor<TSettings>[];
// Warning: (ae-forgotten-export) The symbol "RoutingEventSink" needs to be exported by the entry point index.d.ts
//
// (undocumented)
createEventSink(): RoutingEventSink;
// (undocumented)
Expand All @@ -543,8 +564,6 @@ export abstract class RouterConfiguration<TSettings = any> {
createNavigationQueue(): NavigationQueue;
// (undocumented)
createRouteRecognizer(): RouteRecognizer<TSettings>;
// Warning: (ae-forgotten-export) The symbol "TitleBuilder" needs to be exported by the entry point index.d.ts
//
// (undocumented)
createTitleBuilder(): TitleBuilder;
// (undocumented)
Expand Down Expand Up @@ -608,6 +627,20 @@ export interface RouteView {
dispose(): void;
}

// @beta (undocumented)
export interface RoutingEventSink {
// (undocumented)
onNavigationBegin(router: Router, route: RecognizedRoute, command: NavigationCommand): void;
// (undocumented)
onNavigationEnd(router: Router, route: RecognizedRoute, command: NavigationCommand): void;
// (undocumented)
onPhaseBegin(phase: NavigationPhase): void;
// (undocumented)
onPhaseEnd(phase: NavigationPhase): void;
// (undocumented)
onUnhandledNavigationMessage(router: Router, message: NavigationMessage): void;
}

// @beta (undocumented)
export type SupportsSettings<TSettings = any> = {
settings?: TSettings;
Expand All @@ -619,6 +652,14 @@ export type TemplateFallbackRouteDefinition<TSettings = any> = LayoutAndTransiti
// @beta (undocumented)
export type TemplateRouteDefinition<TSettings = any> = NavigableRouteDefinition<TSettings> & HasTemplate;

// @beta (undocumented)
export interface TitleBuilder {
// (undocumented)
buildTitle(rootTitle: string, routeTitles: string[][]): string;
// (undocumented)
joinTitles(parentTitle: string, childTitle: string): string;
}

// @beta (undocumented)
export interface Transition {
// (undocumented)
Expand Down
2 changes: 1 addition & 1 deletion packages/fast-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"prepublishOnly": "npm run clean:dist && npm run build",
"lint": "biome-changed",
"lint:fix": "biome-changed -- --fix",
"test:node": "tsgo -p ./tsconfig.json && node --test dist/esm/recognizer.spec.js",
"test:node": "tsgo -p ./tsconfig.json && node --test dist/esm/*.spec.js",
"test": "npm run lint && npm run doc:ci && npm run test:node",
"test:ci": "npm run doc:ci && npm run test:node"
},
Expand Down
28 changes: 28 additions & 0 deletions packages/fast-router/src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { strictEqual } from "node:assert/strict";
import { describe, test } from "node:test";
import { DefaultRoutingEventSink } from "./events.js";
import type { RoutingEventSink, TitleBuilder } from "./index.js";
import { DefaultTitleBuilder } from "./titles.js";

// The entry point has DOM-dependent side effects and cannot be imported at runtime under
// node:test, so it is asserted at the type level. Indexing the module type keeps the
// classes pinned as value exports rather than type-only ones.
type EntryPoint = typeof import("./index.js");

describe("index", () => {
test("re-exports the events module", () => {
const sink: RoutingEventSink = new DefaultRoutingEventSink();
const ctor: EntryPoint["DefaultRoutingEventSink"] = DefaultRoutingEventSink;

strictEqual(ctor, DefaultRoutingEventSink);
strictEqual(typeof sink.onNavigationBegin, "function");
});

test("re-exports the titles module", () => {
const builder: TitleBuilder = new DefaultTitleBuilder();
const ctor: EntryPoint["DefaultTitleBuilder"] = DefaultTitleBuilder;

strictEqual(ctor, DefaultTitleBuilder);
strictEqual(builder.joinTitles("a", "b"), "a - b");
});
});
4 changes: 3 additions & 1 deletion packages/fast-router/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
export * from "./commands.js";
export * from "./configuration.js";
export * from "./contributors.js";
export * from "./events.js";
export * from "./fast-router.js";
export * from "./links.js";
export * from "./navigation.js";
export * from "./contributors.js";
export * from "./phases.js";
export * from "./process.js";
export * from "./query-string.js";
export * from "./recognizer.js";
export * from "./router.js";
export * from "./routes.js";
export * from "./titles.js";
export * from "./view.js";