UNPKG

@stencil/react-output-target

Version:

React output target for @stencil/core components.

1 lines 1.51 kB
{"version":3,"file":"runtime.cjs","sources":["../src/runtime/create-component.ts"],"sourcesContent":["import type { EventName, Options } from '@lit/react';\nimport { createComponent as createComponentWrapper } from '@lit/react';\n\n// A key value map matching React prop names to event names.\ntype EventNames = Record<string, EventName | string>;\n\n// Type that's compatible with both React 18 and 19\ntype StencilProps<I extends HTMLElement, E extends EventNames> = Omit<React.HTMLAttributes<I>, keyof E> &\n Partial<{ [K in keyof E]: E[K] extends EventName<infer T> ? (event: T) => void : (event: any) => void }> &\n Partial<Omit<I, keyof HTMLElement>> &\n React.RefAttributes<I>;\n\nexport type StencilReactComponent<I extends HTMLElement, E extends EventNames = {}> = React.FunctionComponent<\n StencilProps<I, E>\n>;\n\n/**\n * Defines a custom element and creates a React component.\n * @public\n */\nexport const createComponent = <I extends HTMLElement, E extends EventNames = {}>({\n defineCustomElement,\n ...options\n}: Options<I, E> & { defineCustomElement: () => void }): StencilReactComponent<I, E> => {\n if (typeof defineCustomElement !== 'undefined') {\n defineCustomElement();\n }\n return createComponentWrapper<I, E>(options) as unknown as StencilReactComponent<I, E>;\n};\n"],"names":["createComponent","defineCustomElement","options","createComponentWrapper"],"mappings":"8GAoBaA,EAAkB,CAAmD,CAChF,oBAAAC,EACA,GAAGC,CACL,KACM,OAAOD,EAAwB,KACbA,EAAA,EAEfE,EAAAA,gBAA6BD,CAAO"}