{"version":3,"file":"useControlledRemoteValueProps.mjs","names":[],"sources":["../../../../../../../src/lib/remote/useControlledRemoteValueProps.ts"],"sourcesContent":["import { useRef } from \"react\";\nimport { getRemoteEvent } from \"./eventHandlerContext\";\nimport type { FieldProps } from \"@/lib/remote/types\";\n\nconst unknownRemoteEventValue = Symbol(\"unknownRemoteEventValue\");\n\nexport const controlledRemoteValueMarker = \"___flowControlledRemoteValue___\";\n\nexport const useControlledRemoteValueProps = <T, P>(\n  props: FieldProps<T, P>,\n) => {\n  const valueOfRemoteEvent = useRef<unknown>(unknownRemoteEventValue);\n\n  const onChange = (value: T) => {\n    const remoteEvent = getRemoteEvent();\n    valueOfRemoteEvent.current = remoteEvent ? value : unknownRemoteEventValue;\n    props.onChange?.(value);\n  };\n\n  const value =\n    valueOfRemoteEvent.current === props.value\n      ? controlledRemoteValueMarker\n      : props.value;\n\n  return { ...props, onChange, value };\n};\n"],"mappings":";;;;;AAIA,IAAM,0BAA0B,OAAO,yBAAyB;AAEhE,IAAa,8BAA8B;AAE3C,IAAa,iCACX,UACG;CACH,MAAM,qBAAqB,OAAgB,uBAAuB;CAElE,MAAM,YAAY,UAAa;EAC7B,MAAM,cAAc,eAAe;EACnC,mBAAmB,UAAU,cAAc,QAAQ;EACnD,MAAM,WAAW,KAAK;CACxB;CAEA,MAAM,QACJ,mBAAmB,YAAY,MAAM,QACjC,8BACA,MAAM;CAEZ,OAAO;EAAE,GAAG;EAAO;EAAU;CAAM;AACrC"}