{"version":3,"file":"createFlowRemoteComponent.mjs","names":[],"sources":["../../../src/components/createFlowRemoteComponent.tsx"],"sourcesContent":["import type {\n  RemoteComponentOptions,\n  RemoteComponentTypeFromElementConstructor,\n} from \"@mittwald/remote-dom-react\";\nimport type { FlowComponentProvisionType } from \"@mittwald/flow-react-components/internal\";\nimport {\n  flowComponent,\n  isFlowComponentName,\n  useReportComponentUsage,\n  ViewCompositionReset,\n} from \"@mittwald/flow-react-components/internal\";\nimport type {\n  RemoteElement,\n  RemoteElementConstructor,\n} from \"@mittwald/flow-remote-core\";\nimport { createElement, type FC } from \"react\";\nimport { createRemoteComponent } from \"@/lib/createRemoteComponent\";\n\n// eslint-disable-next-line  @typescript-eslint/no-explicit-any\ntype AnyRecord = Record<string, any>;\n\nexport function createFlowRemoteComponent<\n  Tag extends keyof HTMLElementTagNameMap,\n  ElementConstructor extends RemoteElementConstructor<\n    AnyRecord,\n    AnyRecord,\n    AnyRecord,\n    AnyRecord\n  > = HTMLElementTagNameMap[Tag] extends RemoteElement<\n    infer Properties,\n    infer Methods,\n    infer Slots,\n    infer EventListeners\n  >\n    ? RemoteElementConstructor<Properties, Methods, Slots, EventListeners>\n    : never,\n  Props extends AnyRecord = AnyRecord,\n>(\n  tag: Tag,\n  flowComponentTag: string,\n  Element: ElementConstructor | undefined = customElements.get(tag) as never,\n  {\n    slotProps = true,\n    eventProps = {} as never,\n    type,\n  }: RemoteComponentOptions<ElementConstructor, Props> & {\n    /*\n     * The provision type of the component this stands in for. It has to travel\n     * with the generated component, because `flowComponent` defaults to `\"ui\"`\n     * — which wraps the element in a `ClearPropsContext` and cuts every props\n     * context that a surrounding provider set. A trigger whose local\n     * counterpart is not `@flr-generate` renders inside the remote tree\n     * (`ModalTrigger` → `OverlayTrigger` → this element), so clearing there\n     * drops the `onPress` its own trigger just supplied.\n     */\n    type?: FlowComponentProvisionType;\n  } = {},\n): RemoteComponentTypeFromElementConstructor<ElementConstructor> {\n  const element = createRemoteComponent(tag, Element, {\n    slotProps,\n    eventProps,\n  });\n\n  if (isFlowComponentName(flowComponentTag)) {\n    return flowComponent(\n      flowComponentTag,\n      (p) => {\n        return createElement(element, p as never, p.children);\n      },\n      {\n        isRemoteComponent: true,\n        type,\n      },\n    ) as never;\n  }\n\n  const RemoteComponent: FC<AnyRecord> = (props) => {\n    const isViewComposition = useReportComponentUsage(flowComponentTag);\n    const remoteElement = createElement(\n      element,\n      props as never,\n      props.children,\n    );\n\n    return isViewComposition ? (\n      <ViewCompositionReset>{remoteElement}</ViewCompositionReset>\n    ) : (\n      remoteElement\n    );\n  };\n\n  RemoteComponent.displayName = `FlowRemoteComponent(${flowComponentTag})`;\n\n  return RemoteComponent as never;\n}\n\nexport default createFlowRemoteComponent;\n"],"mappings":";;;;;;;AAqBA,SAAgB,0BAiBd,KACA,kBACA,UAA0C,eAAe,IAAI,GAAG,GAChE,EACE,YAAY,MACZ,aAAa,CAAC,GACd,SAYE,CAAC,GAC0D;CAC/D,MAAM,UAAU,sBAAsB,KAAK,SAAS;EAClD;EACA;CACF,CAAC;CAED,IAAI,oBAAoB,gBAAgB,GACtC,OAAO,cACL,mBACC,MAAM;EACL,OAAO,cAAc,SAAS,GAAY,EAAE,QAAQ;CACtD,GACA;EACE,mBAAmB;EACnB;CACF,CACF;CAGF,MAAM,mBAAkC,UAAU;EAChD,MAAM,oBAAoB,wBAAwB,gBAAgB;EAClE,MAAM,gBAAgB,cACpB,SACA,OACA,MAAM,QACR;EAEA,OAAO,oBACL,oBAAC,sBAAD,EAAA,UAAuB,cAAoC,CAAA,IAE3D;CAEJ;CAEA,gBAAgB,cAAc,uBAAuB,iBAAiB;CAEtE,OAAO;AACT"}