{"version":3,"file":"Text.cjs","sources":["../src/Text.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { useComponentsContext } from './BlocksRenderer';\n\ninterface TextInlineNode {\n  type: 'text';\n  text: string;\n  bold?: boolean;\n  italic?: boolean;\n  underline?: boolean;\n  strikethrough?: boolean;\n  code?: boolean;\n}\n\ntype Modifier = Exclude<keyof TextInlineNode, 'type' | 'text'>;\n\ntype TextInlineProps = Omit<TextInlineNode, 'type'>;\n\nconst replaceLineBreaks = (text: string) => {\n  const split = text.split(/\\r?\\n|\\r/g);\n  return (\n    <>\n      {split.map((part, idx) => (\n        <React.Fragment key={idx}>\n          {idx > 0 && <br />}\n          {part}\n        </React.Fragment>\n      ))}\n    </>\n  );\n};\n\nconst Text = ({ text, ...modifiers }: TextInlineProps) => {\n  // Get matching React component from the context\n  const { modifiers: modifierComponents, missingModifierTypes } = useComponentsContext();\n\n  const modifierNames = Object.keys(modifiers) as Modifier[];\n\n  // Loop on each active modifier to wrap the text in its component\n  return modifierNames.reduce(\n    (children, modifierName) => {\n      // Don't wrap the text if the modifier is disabled\n      if (!modifiers[modifierName]) {\n        return children;\n      }\n\n      const ModifierComponent = modifierComponents[modifierName];\n\n      if (!ModifierComponent) {\n        // Only warn once per missing modifier\n        if (!missingModifierTypes.includes(modifierName)) {\n          console.warn(\n            `[@strapi/block-react-renderer] No component found for modifier \"${modifierName}\"`\n          );\n          missingModifierTypes.push(modifierName);\n        }\n\n        // Don't throw an error, just ignore the modifier\n        return children;\n      }\n\n      return <ModifierComponent>{children}</ModifierComponent>;\n    },\n    // By default, return the text without any wrapper to avoid useless nesting\n    replaceLineBreaks(text)\n  );\n};\n\nexport type { TextInlineNode, Modifier };\nexport { Text };\n"],"names":["jsx","Fragment","jsxs","React","useComponentsContext"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAkBA,MAAM,oBAAoB,CAAC,SAAiB;AACpC,QAAA,QAAQ,KAAK,MAAM,WAAW;AAElC,SAAAA,2BAAA,IAAAC,WAAA,UAAA,EACG,gBAAM,IAAI,CAAC,MAAM,QAChBC,2BAAA,KAACC,iBAAM,UAAN,EACE,UAAA;AAAA,IAAM,MAAA,oCAAM,MAAG,CAAA,CAAA;AAAA,IACf;AAAA,EAAA,KAFkB,GAGrB,CACD,EACH,CAAA;AAEJ;AAEA,MAAM,OAAO,CAAC,EAAE,MAAM,GAAG,gBAAiC;AAExD,QAAM,EAAE,WAAW,oBAAoB,yBAAyBC,eAAqB,qBAAA;AAE/E,QAAA,gBAAgB,OAAO,KAAK,SAAS;AAG3C,SAAO,cAAc;AAAA,IACnB,CAAC,UAAU,iBAAiB;AAEtB,UAAA,CAAC,UAAU,YAAY,GAAG;AACrB,eAAA;AAAA,MACT;AAEM,YAAA,oBAAoB,mBAAmB,YAAY;AAEzD,UAAI,CAAC,mBAAmB;AAEtB,YAAI,CAAC,qBAAqB,SAAS,YAAY,GAAG;AACxC,kBAAA;AAAA,YACN,mEAAmE,YAAY;AAAA,UAAA;AAEjF,+BAAqB,KAAK,YAAY;AAAA,QACxC;AAGO,eAAA;AAAA,MACT;AAEO,aAAAJ,+BAAC,qBAAmB,SAAS,CAAA;AAAA,IACtC;AAAA;AAAA,IAEA,kBAAkB,IAAI;AAAA,EAAA;AAE1B;;"}