Skip to content

Commit

Permalink
feat: add support for custom components
Browse files Browse the repository at this point in the history
  • Loading branch information
trezy committed Jul 12, 2024
1 parent 31f80b5 commit fd96cf2
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/global.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { NamespacedPixiElements } from './typedefs/NamespacedPixiElements.ts';
import type { PixiElements } from './typedefs/PixiElements.ts';

export type { PixiReactNode } from './typedefs/PixiReactNode.ts';

declare global
{
// eslint-disable-next-line @typescript-eslint/no-namespace
Expand All @@ -9,5 +11,3 @@ declare global
interface IntrinsicElements extends PixiElements, NamespacedPixiElements {}
}
}

export {};
4 changes: 1 addition & 3 deletions src/helpers/extend.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import { catalogue } from './catalogue.js';
/**
* Expose Pixi.js components for use in JSX.
*
* @param {{
* [K in AutoFilteredKeys]?: typeof import('pixi.js')[K]
* }} objects The Pixi.js components to be exposed.
* @param {{ [key: string]: new (...args: any) => any }} objects Components to be exposed.
*/
export function extend(objects)
{
Expand Down
2 changes: 1 addition & 1 deletion src/typedefs/AutoFilteredKeys.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type * as PIXI from 'pixi.js';

type PixiType = typeof PIXI;
export type PixiType = typeof PIXI;

export type AutoFilteredKeys = {
[K in keyof PixiType]: PixiType[K] extends new (...args: any) => any ? K : never
Expand Down
6 changes: 2 additions & 4 deletions src/typedefs/Instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ import type { ContainerElement } from './ContainerElement.ts';
import type { EventHandlers } from './EventHandlers.ts';
import type { InstanceState } from './InstanceState.ts';

interface BaseInstance
export type Instance = ContainerElement & EventHandlers &
{
BaseInstance: object
__pixireact?: InstanceState
autoRemovedBeforeAppend?: boolean
children?: ContainerElement | ContainerElement[]
draw?: (graphics: Graphics) => void
}

export type Instance = ContainerElement & BaseInstance & EventHandlers;
};
8 changes: 3 additions & 5 deletions src/typedefs/InstanceProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import type { Graphics } from 'pixi.js';
import type { ContainerElement } from './ContainerElement.ts';
import type { InstanceState } from './InstanceState.ts';

interface BaseInstanceProps
{
export type InstanceProps = {
[key: string]: unknown
__pixireact?: InstanceState
autoRemovedBeforeAppend?: boolean
children?: ContainerElement | ContainerElement[]
draw?: (graphics: Graphics) => void
}

export type InstanceProps = { [key: string]: unknown } & BaseInstanceProps;
};
5 changes: 0 additions & 5 deletions src/typedefs/Node.ts

This file was deleted.

11 changes: 4 additions & 7 deletions src/typedefs/PixiElements.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { type NameOverrides } from '../constants/NameOverrides.js';

import type * as PIXI from 'pixi.js';
import type { AutoFilteredKeys } from './AutoFilteredKeys';
import type { Node } from './Node';

type PixiType = typeof PIXI;
import type { NameOverrides } from '../constants/NameOverrides.js';
import type { AutoFilteredKeys } from './AutoFilteredKeys.ts';
import type { PixiReactNode } from './PixiReactNode.ts';

export type PixiElements = {
[K in AutoFilteredKeys as K extends keyof typeof NameOverrides ? typeof NameOverrides[K] : Uncapitalize<K>]: Node<PixiType[K]>
[K in AutoFilteredKeys as K extends keyof typeof NameOverrides ? typeof NameOverrides[K] : Uncapitalize<K>]: PixiReactNode<typeof PIXI[K]>
};
5 changes: 5 additions & 0 deletions src/typedefs/PixiReactNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { ConstructorParams } from './ConstructorParams.ts';
import type { Overwrite } from './Overwrite.ts';
import type { PixiReactNodeProps } from './PixiReactNodeProps.ts';

export type PixiReactNode<T extends abstract new (...args: any) => any> = Overwrite<Partial<ConstructorParams<T>>, PixiReactNodeProps<InstanceType<T>>>;
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ export interface BaseNodeProps<T extends abstract new (...args: any) => any>
ref?: Ref<T>;
}

export type NodeProps<T extends abstract new (...args: any) => any> = T extends Graphics
export type PixiReactNodeProps<T extends abstract new (...args: any) => any> = T extends Graphics
? BaseNodeProps<T> & EventHandlers & { draw?: (graphics: Graphics) => void; }
: BaseNodeProps<T> & EventHandlers;

0 comments on commit fd96cf2

Please sign in to comment.