From 7a889a9a6c6075ba9588b4211a8cffee0242ea8d Mon Sep 17 00:00:00 2001 From: Anton Platonov Date: Mon, 4 Nov 2024 10:36:18 +0200 Subject: [PATCH] fix: add route v1 compatibility type definitions (#895) --- src/index.ts | 1 + src/v1-compat.d.ts | 84 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 src/v1-compat.d.ts diff --git a/src/index.ts b/src/index.ts index d57c8822..395c77ec 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,6 @@ export * from './router.js'; export type * from './types.js'; +export type * from './v1-compat.js'; export { processNewChildren, amend, diff --git a/src/v1-compat.d.ts b/src/v1-compat.d.ts new file mode 100644 index 00000000..496d95c3 --- /dev/null +++ b/src/v1-compat.d.ts @@ -0,0 +1,84 @@ +/* eslint-disable max-classes-per-file */ + +import type { MaybePromise } from './resolver/types'; +import type { RouteContext, Route, ActionResult, ChildrenCallback, WebComponentInterface } from './types'; + +/** + * Action result describing an HTML element to render. + * + * @deprecated Use `HTMLElement`. + */ +export type ComponentResult = HTMLElement; + +/** + * Route resolution context object, see {@link RouteContext}. + * + * @deprecated Use {@link RouteContext}. + */ +export type Context = RouteContext; + +/** + * Route action callback function, see {@link Route.action}. + * + * @deprecated Use `NonNullable`. + */ +export type ActionFn = ( + this: Route, + context: RouteContext, + commands: Commands, +) => MaybePromise; + +/** + * Route children callback function, see {@link ChildrenCallback}. + * + * @deprecated Use {@link ChildrenCallback}. + */ +export type ChildrenFn = ChildrenCallback; + +/** + * Web component route interface with {@link onBeforeEnter} callback. + * + * @deprecated Use {@link WebComponentInterface}. + */ +export interface BeforeEnterObserver { + /** + * See {@link WebComponentInterface.onBeforeEnter} + */ + onBeforeEnter: NonNullable; +} + +/** + * Web component route interface with {@link onBeforeLeave} callback. + * + * @deprecated Use {@link WebComponentInterface}. + */ +export interface BeforeLeaveObserver { + /** + * See {@link WebComponentInterface.onBeforeLeave} + */ + onBeforeLeave: NonNullable; +} + +/** + * Web component route interface with {@link onAfterEnter} callback. + * + * @deprecated Use {@link WebComponentInterface}. + */ +export interface AfterEnterObserver { + /** + * See {@link WebComponentInterface.onAfterEnter} + */ + onAfterEnter: NonNullable; +} + +/** + * Web component route interface with {@link onAfterLeave} callback. + * + * @deprecated Use {@link WebComponentInterface}. + */ +export interface AfterLeaveObserver { + /** + * See {@link WebComponentInterface.onAfterLeave} + */ + onAfterLeave: NonNullable; +}