{"version":3,"sources":["../../src/IntlayerNode.tsx"],"sourcesContent":["import type { NodeProps } from '@intlayer/core';\nimport {\n  type PropsWithChildren,\n  type ReactNode,\n  type ReactElement,\n  isValidElement,\n} from 'react';\n\nexport type IntlayerNode<\n  T = NodeProps['children'],\n  AdditionalProps = {},\n> = ReactNode & {\n  value: T;\n} & AdditionalProps;\n\ntype RenderIntlayerNodeProps<T> = PropsWithChildren<{\n  value: T;\n  children: ReactNode;\n  additionalProps?: { [key: string]: any };\n}>;\n\nexport const renderIntlayerNode = <\n  T extends number | string | boolean | undefined | null,\n>({\n  children,\n  value,\n  additionalProps,\n}: RenderIntlayerNodeProps<T>): IntlayerNode<T> => {\n  // If children is not a valid ReactElement, wrap it in a fragment\n  const element: ReactElement<any> = isValidElement(children) ? (\n    children\n  ) : (\n    <>{children}</>\n  );\n\n  // Return a Proxy that pretends to be the original element\n  // but also has a .value getter.\n  return new Proxy(element as ReactElement, {\n    get(target, prop, receiver) {\n      if (prop === 'value') {\n        return value;\n      }\n\n      if (\n        additionalProps &&\n        Object.keys(additionalProps).includes(prop as string)\n      ) {\n        return additionalProps[prop as keyof typeof additionalProps];\n      }\n\n      return Reflect.get(target, prop, receiver);\n    },\n  }) as IntlayerNode<T>;\n};\n"],"mappings":"AAgCI;AA/BJ;AAAA,EAIE;AAAA,OACK;AAeA,MAAM,qBAAqB,CAEhC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAmD;AAEjD,QAAM,UAA6B,eAAe,QAAQ,IACxD,WAEA,gCAAG,UAAS;AAKd,SAAO,IAAI,MAAM,SAAyB;AAAA,IACxC,IAAI,QAAQ,MAAM,UAAU;AAC1B,UAAI,SAAS,SAAS;AACpB,eAAO;AAAA,MACT;AAEA,UACE,mBACA,OAAO,KAAK,eAAe,EAAE,SAAS,IAAc,GACpD;AACA,eAAO,gBAAgB,IAAoC;AAAA,MAC7D;AAEA,aAAO,QAAQ,IAAI,QAAQ,MAAM,QAAQ;AAAA,IAC3C;AAAA,EACF,CAAC;AACH;","names":[]}