{
  "version": 3,
  "sources": ["../../../src/make-bindable-component/make-bindable-component.tsx"],
  "sourcesContent": ["import React from 'react';\n\nimport type { ReadonlyBinding } from '../binding/types/readonly-binding';\nimport { isBinding } from '../binding-utils/type-utils.mjs';\nimport { BindingsConsumer } from '../components/BindingsConsumer/index.mjs';\nimport { resolveTypeOrBindingType } from '../resolveable/utils.mjs';\nimport type { MakeBindableComponentOptions } from './types/make-bindable-component-options';\nimport type { UpgradeToBindingsProps } from './types/upgrade-to-binding-props';\n\n/**\n * Take a functional component and creates a new functional component that takes binding props.  The non-bound types are also still\n * accepted.\n *\n * The component will be re-rendered any time binding props change.\n *\n * The bindings are resolved before calling the original component.\n *\n * Bindings can also be passed through by specifying key names in the `passThru` option.\n */\nexport function makeBindableComponent<PropsT extends Record<string, any>, PassThruKeyT extends keyof PropsT & string = never>(\n  functionalComponent: (props: PropsT) => React.JSX.Element\n): (props: UpgradeToBindingsProps<PropsT, PassThruKeyT>) => React.JSX.Element;\nexport function makeBindableComponent<PropsT extends Record<string, any>, PassThruKeyT extends keyof PropsT & string = never>(\n  options: MakeBindableComponentOptions<PropsT, PassThruKeyT>,\n  functionalComponent: (props: PropsT) => React.JSX.Element\n): (props: UpgradeToBindingsProps<PropsT, PassThruKeyT>) => React.JSX.Element;\nexport function makeBindableComponent<PropsT extends Record<string, any>, PassThruKeyT extends keyof PropsT & string = never>(\n  optionsOrFunctionalComponent: MakeBindableComponentOptions<PropsT, PassThruKeyT> | ((props: PropsT) => React.JSX.Element),\n  theFunctionalComponent?: (props: PropsT) => React.JSX.Element\n): (props: UpgradeToBindingsProps<PropsT, PassThruKeyT>) => React.JSX.Element {\n  const { passThru, bindingsConsumerProps } =\n    typeof optionsOrFunctionalComponent === 'function'\n      ? ({} satisfies MakeBindableComponentOptions<PropsT, PassThruKeyT>)\n      : optionsOrFunctionalComponent;\n  const functionalComponent = (typeof optionsOrFunctionalComponent === 'function' ? optionsOrFunctionalComponent : theFunctionalComponent)!;\n\n  const passThruSet = new Set(passThru ?? []);\n\n  return (props: UpgradeToBindingsProps<PropsT, PassThruKeyT>) => {\n    const bindings = getAllBindings(props, passThruSet);\n    return bindings.length > 0 ? (\n      <BindingsConsumer {...bindingsConsumerProps} bindings={bindings}>\n        {() => functionalComponent(resolveBindings(props, passThruSet) as PropsT)}\n      </BindingsConsumer>\n    ) : (\n      functionalComponent(props as PropsT)\n    );\n  };\n}\n\n// Helpers\n\nconst getAllBindings = (obj: Record<string, any>, passThru: Set<string>) => {\n  const output: ReadonlyBinding[] = [];\n\n  for (const [key, value] of Object.entries(obj)) {\n    if (!passThru.has(key) && isBinding(value)) {\n      output.push(value);\n    }\n  }\n\n  return output;\n};\n\nconst resolveBindings = <PropsT extends Record<string, any>>(props: PropsT, passThru: Set<string>): PropsT =>\n  Object.entries(props).reduce((out, [key, value]) => {\n    if (passThru.has(key)) {\n      // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n      out[key as keyof PropsT] = value;\n\n      return out;\n    }\n\n    // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n    out[key as keyof PropsT] = resolveTypeOrBindingType(value);\n\n    return out;\n  }, {} as Partial<PropsT>) as PropsT;\n"],
  "mappings": "AAAA,OAAO,WAAW;AAGlB,SAAS,iBAAiB;AAC1B,SAAS,wBAAwB;AACjC,SAAS,gCAAgC;AAqBlC,SAAS,sBACd,8BACA,wBAC4E;AAC5E,QAAM,EAAE,UAAU,sBAAsB,IACtC,OAAO,iCAAiC,aACnC,CAAC,IACF;AACN,QAAM,sBAAuB,OAAO,iCAAiC,aAAa,+BAA+B;AAEjH,QAAM,cAAc,IAAI,IAAI,YAAY,CAAC,CAAC;AAE1C,SAAO,CAAC,UAAwD;AAC9D,UAAM,WAAW,eAAe,OAAO,WAAW;AAClD,WAAO,SAAS,SAAS,IACvB,oCAAC,oBAAkB,GAAG,uBAAuB,YAC1C,MAAM,oBAAoB,gBAAgB,OAAO,WAAW,CAAW,CAC1E,IAEA,oBAAoB,KAAe;AAAA,EAEvC;AACF;AAIA,MAAM,iBAAiB,CAAC,KAA0B,aAA0B;AAC1E,QAAM,SAA4B,CAAC;AAEnC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,CAAC,SAAS,IAAI,GAAG,KAAK,UAAU,KAAK,GAAG;AAC1C,aAAO,KAAK,KAAK;AAAA,IACnB;AAAA,EACF;AAEA,SAAO;AACT;AAEA,MAAM,kBAAkB,CAAqC,OAAe,aAC1E,OAAO,QAAQ,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM;AAClD,MAAI,SAAS,IAAI,GAAG,GAAG;AAErB,QAAI,GAAmB,IAAI;AAE3B,WAAO;AAAA,EACT;AAGA,MAAI,GAAmB,IAAI,yBAAyB,KAAK;AAEzD,SAAO;AACT,GAAG,CAAC,CAAoB;",
  "names": []
}
