From ac91753ed24cfe14fa1369f4099590a3bd7d6a01 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Fri, 20 Dec 2024 16:24:12 +0100 Subject: [PATCH] Add support for React 19 This adds support for React 19 types, by removing the dependency on the types provided by hast-util-to-jsx-runtime, thus removing the dependency on the JSX global namespace. --- index.js | 2 +- lib/index.js | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index ff903ce..174bffe 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ /** - * @typedef {import('hast-util-to-jsx-runtime').ExtraProps} ExtraProps * @typedef {import('./lib/index.js').AllowElement} AllowElement * @typedef {import('./lib/index.js').Components} Components + * @typedef {import('./lib/index.js').ExtraProps} ExtraProps * @typedef {import('./lib/index.js').Options} Options * @typedef {import('./lib/index.js').UrlTransform} UrlTransform */ diff --git a/lib/index.js b/lib/index.js index b97d6ed..d3d201f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,7 +1,6 @@ /** * @import {Element, ElementContent, Nodes, Parents, Root} from 'hast' - * @import {Components as JsxRuntimeComponents} from 'hast-util-to-jsx-runtime' - * @import {ReactElement} from 'react' + * @import {ComponentProps, ElementType, ReactElement} from 'react' * @import {Options as RemarkRehypeOptions} from 'remark-rehype' * @import {BuildVisitor} from 'unist-util-visit' * @import {PluggableList} from 'unified' @@ -21,7 +20,16 @@ */ /** - * @typedef {Partial} Components + * @typedef ExtraProps + * Extra fields we pass. + * @property {Element | undefined} [node] + * passed when `passNode` is on. + */ + +/** + * @typedef {{ + * [Key in Extract]?: ElementType & ExtraProps> + * }} Components * Map tag names to components. */ @@ -225,6 +233,9 @@ export function Markdown(options) { return toJsxRuntime(hastTree, { Fragment, + // @ts-expect-error + // React components are allowed to return numbers, + // but not according to the types in hast-util-to-jsx-runtime components, ignoreInvalidStyle: true, jsx,