From b71d01633d8ae85e874cb7cf44777a675fd59f27 Mon Sep 17 00:00:00 2001 From: sairamg Date: Wed, 17 Dec 2025 17:27:08 +0530 Subject: [PATCH 1/2] feat(types): add ComponentCustomProperties augmentation point and type built-in plugins --- index.d.ts | 73 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 67 insertions(+), 6 deletions(-) diff --git a/index.d.ts b/index.d.ts index b4a95786..d0e59d1f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -18,10 +18,10 @@ // blits file type reference /// -import {type ShaderEffect as RendererShaderEffect, type WebGlCoreShader, type RendererMainSettings} from '@lightningjs/renderer' - declare module '@lightningjs/blits' { - + type RendererShaderEffect = import('@lightningjs/renderer').ShaderEffect + type WebGlCoreShader = import('@lightningjs/renderer').WebGlCoreShader + type RendererMainSettings = import('@lightningjs/renderer').RendererMainSettings export interface AnnouncerUtteranceOptions { /** @@ -209,7 +209,7 @@ declare module '@lightningjs/blits' { } export interface Input { - [key: string]: (event: KeyboardEvent) => void | undefined | unknown, + [key: string]: ((event: KeyboardEvent) => unknown) | undefined, /** * Catch all input function * @@ -365,12 +365,44 @@ declare module '@lightningjs/blits' { // Extension point for app- and plugin-specific fields on the component `this`. // Add your own properties (e.g., `$telemetry`, `componentName`) via TypeScript // module augmentation in your app, without changing core types. + // Public extension point for app/plugin augmentation via module augmentation. // Note: `ComponentBase` extends this interface, so augmented fields appear in all // hooks, methods, input, computed, and watch. - export interface CustomComponentProperties { + export interface ComponentCustomProperties { // Empty by design: extend in your app via TypeScript module augmentation. } + /** + * @deprecated Use `ComponentCustomProperties`. + * + * Kept for backwards compatibility so existing module augmentations of + * `CustomComponentProperties` continue to flow into component `this`. + */ + export interface CustomComponentProperties extends ComponentCustomProperties {} + + export interface LanguagePlugin { + translate(key: string, ...replacements: any[]): string + readonly language: string + set(language: string): void + translations(translationsObject: Record): void + load(file: string): Promise + } + + export interface ThemePlugin { + get(key: string): T | undefined + get(key: string, fallback: T): T + set(theme: string): void + } + + export interface StoragePlugin { + get(key: string): T | null + set(key: string, value: unknown): boolean + remove(key: string): void + clear(): void + } + + export type AppStatePlugin = Record> = TState + export interface ComponentBase extends CustomComponentProperties { /** * Indicates whether the component currently has focus @@ -633,7 +665,7 @@ declare module '@lightningjs/blits' { } export interface RouterHooks { - init?: () => Promise<> | void; + init?: () => Promise | void; beforeEach?: (to: Route, from: Route) => string | Route | Promise | void; error?: (err: string) => string | Route | Promise | void; } @@ -1301,3 +1333,32 @@ declare module '@lightningjs/blits' { export default Blits; } + +declare module '@lightningjs/blits/plugins' { + import type { + AppStatePlugin, + LanguagePlugin, + StoragePlugin, + ThemePlugin, + } from '@lightningjs/blits' + + export const language: { + name: 'language' + plugin: (options?: Record) => LanguagePlugin + } + + export const theme: { + name: 'theme' + plugin: (config?: Record) => ThemePlugin + } + + export const appState: { + name: 'appState' + plugin: >(state?: TState) => AppStatePlugin + } + + export const storage: { + name: 'storage' + plugin: () => StoragePlugin + } +} From 2203a1de4a48969fcc09cb34c04036dc03f586f5 Mon Sep 17 00:00:00 2001 From: sairamg Date: Tue, 23 Dec 2025 17:23:21 +0530 Subject: [PATCH 2/2] Updated to CustomComponentProperties --- index.d.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/index.d.ts b/index.d.ts index d0e59d1f..d17cf65a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -365,21 +365,12 @@ declare module '@lightningjs/blits' { // Extension point for app- and plugin-specific fields on the component `this`. // Add your own properties (e.g., `$telemetry`, `componentName`) via TypeScript // module augmentation in your app, without changing core types. - // Public extension point for app/plugin augmentation via module augmentation. // Note: `ComponentBase` extends this interface, so augmented fields appear in all // hooks, methods, input, computed, and watch. - export interface ComponentCustomProperties { + export interface CustomComponentProperties { // Empty by design: extend in your app via TypeScript module augmentation. } - /** - * @deprecated Use `ComponentCustomProperties`. - * - * Kept for backwards compatibility so existing module augmentations of - * `CustomComponentProperties` continue to flow into component `this`. - */ - export interface CustomComponentProperties extends ComponentCustomProperties {} - export interface LanguagePlugin { translate(key: string, ...replacements: any[]): string readonly language: string