Skip to content

Commit

Permalink
Local
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Apr 4, 2024
1 parent 4015090 commit 29663c7
Show file tree
Hide file tree
Showing 4 changed files with 321 additions and 129 deletions.
61 changes: 56 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,69 @@
/**
* @typedef {import('./lib/components.js').Components} Components
* @typedef {import('./lib/components.js').Components<JsxElement, JsxElementClass, JsxIntrinsicElements>} Components
* @template JsxElement
* @template JsxElementClass
* @template JsxIntrinsicElements
*/

/**
* @typedef {import('./lib/components.js').ExtraProps} ExtraProps
*/

/**
* @typedef {import('./lib/index.js').CreateEvaluater} CreateEvaluater
*/

/**
* @typedef {import('./lib/index.js').ElementAttributeNameCase} ElementAttributeNameCase
*/

/**
* @typedef {import('./lib/index.js').EvaluateExpression} EvaluateExpression
*/

/**
* @typedef {import('./lib/index.js').EvaluateProgram} EvaluateProgram
*/

/**
* @typedef {import('./lib/index.js').Evaluater} Evaluater
*/

/**
* @typedef {import('./lib/index.js').Fragment} Fragment
* @typedef {import('./lib/index.js').Jsx} Jsx
* @typedef {import('./lib/index.js').JsxDev} JsxDev
* @typedef {import('./lib/index.js').Options} Options
* @typedef {import('./lib/index.js').Props} Props
*/

/**
* @typedef {import('./lib/index.js').Jsx<JsxElement>} Jsx
* @template JsxElement
*/

/**
* @typedef {import('./lib/index.js').JsxDev<JsxElement>} JsxDev
* @template JsxElement
*/

/**
* @typedef {import('./lib/index.js').Options<JsxElement, JsxElementClass, JsxIntrinsicElements>} Options
* @template JsxElement
* @template JsxElementClass
* @template JsxIntrinsicElements
*/

/**
* @typedef {import('./lib/index.js').Props<JsxElement>} Props
* @template JsxElement
*/

/**
* @typedef {import('./lib/index.js').Source} Source
*/

/**
* @typedef {import('./lib/index.js').Space} Space
*/

/**
* @typedef {import('./lib/index.js').StylePropertyNameCase} StylePropertyNameCase
*/

Expand Down
36 changes: 20 additions & 16 deletions lib/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import type {Element} from 'hast'
* @returns
* Result.
*/
export type FunctionComponent<ComponentProps> = (
export type FunctionComponent<JsxElement, ComponentProps> = (
props: ComponentProps
) => JSX.Element | string | null | undefined
) => JsxElement | string | null | undefined

/**
* Class component: given props, returns an instance.
Expand All @@ -24,22 +24,22 @@ export type FunctionComponent<ComponentProps> = (
* @returns
* Instance.
*/
export type ClassComponent<ComponentProps> = new (
export type ClassComponent<JsxElementClass, ComponentProps> = new (
props: ComponentProps
) => JSX.ElementClass
) => JsxElementClass

/**
* Function or class component.
*
* You can access props at `JSX.IntrinsicElements`.
* For example, to find props for `a`, use `JSX.IntrinsicElements['a']`.
* You can access props at `LocalJsx.IntrinsicElements`.
* For example, to find props for `a`, use `LocalJsx.IntrinsicElements['a']`.
*
* @typeParam ComponentProps
* Props type.
*/
export type Component<ComponentProps> =
| ClassComponent<ComponentProps>
| FunctionComponent<ComponentProps>
export type Component<JsxElement, JsxElementClass, ComponentProps> =
| ClassComponent<JsxElementClass, ComponentProps>
| FunctionComponent<JsxElement, ComponentProps>

/**
* Extra fields we pass.
Expand All @@ -49,17 +49,21 @@ export type ExtraProps = {node?: Element | undefined}
/**
* Possible components to use.
*
* Each key is a tag name typed in `JSX.IntrinsicElements`.
* Each key is a tag name typed in `LocalJsx.IntrinsicElements`.
* Each value is either a different tag name, or a component accepting the
* corresponding props (and an optional `node` prop if `passNode` is on).
*
* You can access props at `JSX.IntrinsicElements`.
* For example, to find props for `a`, use `JSX.IntrinsicElements['a']`.
* You can access props at `LocalJsx.IntrinsicElements`.
* For example, to find props for `a`, use `LocalJsx.IntrinsicElements['a']`.
*/
// Note: this type has to be in `.ts` or `.d.ts`, otherwise TSC hardcodes
// react into the `.d.ts` file.
export type Components = {
[TagName in keyof JSX.IntrinsicElements]:
| Component<JSX.IntrinsicElements[TagName] & ExtraProps>
| keyof JSX.IntrinsicElements
export type Components<JsxElement, JsxElementClass, JsxIntrinsicElements> = {
[TagName in keyof JsxIntrinsicElements]:
| Component<
JsxElement,
JsxElementClass,
JsxIntrinsicElements[TagName] & ExtraProps
>
| keyof JsxIntrinsicElements
}
Loading

0 comments on commit 29663c7

Please sign in to comment.