UNPKG

@stencil/react-output-target

Version:

React output target for @stencil/core components.

1 lines 1.83 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 tagName,\n transformTag,\n ...options\n}: Options<I, E> & {\n defineCustomElement: () => void;\n transformTag?: (tagName: string) => string;\n}): StencilReactComponent<I, E> => {\n if (typeof defineCustomElement !== 'undefined') {\n defineCustomElement();\n }\n const finalTagName = transformTag ? transformTag(tagName) : tagName;\n return createComponentWrapper<I, E>({ ...options, tagName: finalTagName }) as unknown as StencilReactComponent<I, E>;\n};\n"],"names":["createComponent","defineCustomElement","tagName","transformTag","options","finalTagName","createComponentWrapper"],"mappings":"8GAoBaA,EAAkB,CAAmD,CAChF,oBAAAC,EACA,QAAAC,EACA,aAAAC,EACA,GAAGC,CACL,IAGmC,CAC7B,OAAOH,EAAwB,KACbA,EAAA,EAEtB,MAAMI,EAAeF,EAAeA,EAAaD,CAAO,EAAIA,EAC5D,OAAOI,kBAA6B,CAAE,GAAGF,EAAS,QAASC,EAAc,CAC3E"}