diff --git a/ad4m-hooks/react/src/index.ts b/ad4m-hooks/react/src/index.ts index ad9beb087..e897d4bfc 100644 --- a/ad4m-hooks/react/src/index.ts +++ b/ad4m-hooks/react/src/index.ts @@ -5,8 +5,10 @@ import { toCustomElement } from "./register"; import { usePerspective } from "./usePerspective"; import { usePerspectives } from "./usePerspectives"; import { useModel } from "./useModel"; +import { reactToWebComponent } from "./reactToWebComponent"; export { + reactToWebComponent, toCustomElement, useAgent, useMe, diff --git a/ad4m-hooks/react/src/reactToWebComponent.ts b/ad4m-hooks/react/src/reactToWebComponent.ts new file mode 100644 index 000000000..ccc9908da --- /dev/null +++ b/ad4m-hooks/react/src/reactToWebComponent.ts @@ -0,0 +1,251 @@ +// Minimal runtime contract for React/ReactDOM (so this file is framework-agnostic) +type ReactLike = { + createElement: (...args: any[]) => any; +}; +type ReactDOMLike = { + createRoot: (container: Element | DocumentFragment) => { + render: (el: any) => void; + unmount: () => void; + }; +}; + +type Options = { + /** Tag name to register (you can also call `customElements.define` yourself). */ + tagName?: string; + /** Use Shadow DOM? If false, render into the element itself. */ + shadow?: boolean | ShadowRootInit; + /** Attribute prefix to treat as props (e.g. data-foo -> foo). Empty = all attributes. */ + attrPrefix?: string; // default: '' (accept all) + /** Element property names to expose as pass-through React props (object/class friendly). */ + observedProps?: string[]; + /** Initial props (merged shallowly before anything else). */ + initialProps?: Record; + /** Optional styles to inject (adoptedStyleSheets or