@transferwise/components 46.155.1 → 46.157.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (264) hide show
  1. package/build/Calendar/Calendar.constants.js +10 -0
  2. package/build/Calendar/Calendar.constants.js.map +1 -0
  3. package/build/Calendar/Calendar.constants.mjs +8 -0
  4. package/build/Calendar/Calendar.constants.mjs.map +1 -0
  5. package/build/Calendar/Calendar.js +121 -17
  6. package/build/Calendar/Calendar.js.map +1 -1
  7. package/build/Calendar/Calendar.messages.js +12 -0
  8. package/build/Calendar/Calendar.messages.js.map +1 -1
  9. package/build/Calendar/Calendar.messages.mjs +12 -0
  10. package/build/Calendar/Calendar.messages.mjs.map +1 -1
  11. package/build/Calendar/Calendar.mjs +122 -18
  12. package/build/Calendar/Calendar.mjs.map +1 -1
  13. package/build/Calendar/DateHeader/DateHeader.js +5 -1
  14. package/build/Calendar/DateHeader/DateHeader.js.map +1 -1
  15. package/build/Calendar/DateHeader/DateHeader.mjs +5 -1
  16. package/build/Calendar/DateHeader/DateHeader.mjs.map +1 -1
  17. package/build/Calendar/DayCalendar/DayCalendar.js +20 -2
  18. package/build/Calendar/DayCalendar/DayCalendar.js.map +1 -1
  19. package/build/Calendar/DayCalendar/DayCalendar.mjs +20 -2
  20. package/build/Calendar/DayCalendar/DayCalendar.mjs.map +1 -1
  21. package/build/Calendar/DayCalendar/Table/DayCalendarTable.js +60 -19
  22. package/build/Calendar/DayCalendar/Table/DayCalendarTable.js.map +1 -1
  23. package/build/Calendar/DayCalendar/Table/DayCalendarTable.mjs +60 -19
  24. package/build/Calendar/DayCalendar/Table/DayCalendarTable.mjs.map +1 -1
  25. package/build/Calendar/MonthCalendar/MonthCalendar.js +6 -0
  26. package/build/Calendar/MonthCalendar/MonthCalendar.js.map +1 -1
  27. package/build/Calendar/MonthCalendar/MonthCalendar.mjs +6 -0
  28. package/build/Calendar/MonthCalendar/MonthCalendar.mjs.map +1 -1
  29. package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.js +8 -3
  30. package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.js.map +1 -1
  31. package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.mjs +8 -3
  32. package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.mjs.map +1 -1
  33. package/build/Calendar/TableLink/TableLink.js +95 -0
  34. package/build/Calendar/TableLink/TableLink.js.map +1 -0
  35. package/build/Calendar/TableLink/TableLink.mjs +91 -0
  36. package/build/Calendar/TableLink/TableLink.mjs.map +1 -0
  37. package/build/Calendar/YearCalendar/Table/YearCalendarTable.js +8 -3
  38. package/build/Calendar/YearCalendar/Table/YearCalendarTable.js.map +1 -1
  39. package/build/Calendar/YearCalendar/Table/YearCalendarTable.mjs +8 -3
  40. package/build/Calendar/YearCalendar/Table/YearCalendarTable.mjs.map +1 -1
  41. package/build/Calendar/YearCalendar/YearCalendar.js +7 -0
  42. package/build/Calendar/YearCalendar/YearCalendar.js.map +1 -1
  43. package/build/Calendar/YearCalendar/YearCalendar.mjs +7 -0
  44. package/build/Calendar/YearCalendar/YearCalendar.mjs.map +1 -1
  45. package/build/Calendar/_helpers/clampToDayViewBoundary/clampToDayViewBoundary.js +24 -0
  46. package/build/Calendar/_helpers/clampToDayViewBoundary/clampToDayViewBoundary.js.map +1 -0
  47. package/build/Calendar/_helpers/clampToDayViewBoundary/clampToDayViewBoundary.mjs +22 -0
  48. package/build/Calendar/_helpers/clampToDayViewBoundary/clampToDayViewBoundary.mjs.map +1 -0
  49. package/build/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.js +33 -0
  50. package/build/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.js.map +1 -0
  51. package/build/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.mjs +31 -0
  52. package/build/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.mjs.map +1 -0
  53. package/build/Calendar/_helpers/isDateDisabled/isDateDisabled.js +40 -0
  54. package/build/Calendar/_helpers/isDateDisabled/isDateDisabled.js.map +1 -0
  55. package/build/Calendar/_helpers/isDateDisabled/isDateDisabled.mjs +38 -0
  56. package/build/Calendar/_helpers/isDateDisabled/isDateDisabled.mjs.map +1 -0
  57. package/build/DateLookup/DateLookup.js +20 -9
  58. package/build/DateLookup/DateLookup.js.map +1 -1
  59. package/build/DateLookup/DateLookup.mjs +20 -9
  60. package/build/DateLookup/DateLookup.mjs.map +1 -1
  61. package/build/ExpressiveMoneyInput/CurrencySelector/CurrencySelector.js +3 -5
  62. package/build/ExpressiveMoneyInput/CurrencySelector/CurrencySelector.js.map +1 -1
  63. package/build/ExpressiveMoneyInput/CurrencySelector/CurrencySelector.mjs +3 -5
  64. package/build/ExpressiveMoneyInput/CurrencySelector/CurrencySelector.mjs.map +1 -1
  65. package/build/Inputs/SelectInput/TriggerButton/SelectInputTriggerButton.js.map +1 -1
  66. package/build/Inputs/SelectInput/TriggerButton/SelectInputTriggerButton.mjs.map +1 -1
  67. package/build/Markup/Markup.js +138 -0
  68. package/build/Markup/Markup.js.map +1 -0
  69. package/build/Markup/Markup.mjs +133 -0
  70. package/build/Markup/Markup.mjs.map +1 -0
  71. package/build/Markup/constants.js +21 -0
  72. package/build/Markup/constants.js.map +1 -0
  73. package/build/Markup/constants.mjs +15 -0
  74. package/build/Markup/constants.mjs.map +1 -0
  75. package/build/Markup/utils/parseMarkup.js +263 -0
  76. package/build/Markup/utils/parseMarkup.js.map +1 -0
  77. package/build/Markup/utils/parseMarkup.mjs +258 -0
  78. package/build/Markup/utils/parseMarkup.mjs.map +1 -0
  79. package/build/Markup/utils/sanitise.js +111 -0
  80. package/build/Markup/utils/sanitise.js.map +1 -0
  81. package/build/Markup/utils/sanitise.mjs +108 -0
  82. package/build/Markup/utils/sanitise.mjs.map +1 -0
  83. package/build/Typeahead/Typeahead.js +53 -27
  84. package/build/Typeahead/Typeahead.js.map +1 -1
  85. package/build/Typeahead/Typeahead.messages.js +3 -0
  86. package/build/Typeahead/Typeahead.messages.js.map +1 -1
  87. package/build/Typeahead/Typeahead.messages.mjs +3 -0
  88. package/build/Typeahead/Typeahead.messages.mjs.map +1 -1
  89. package/build/Typeahead/Typeahead.mjs +53 -27
  90. package/build/Typeahead/Typeahead.mjs.map +1 -1
  91. package/build/Typeahead/TypeaheadInput/TypeaheadInput.js +2 -2
  92. package/build/Typeahead/TypeaheadInput/TypeaheadInput.js.map +1 -1
  93. package/build/Typeahead/TypeaheadInput/TypeaheadInput.mjs +2 -2
  94. package/build/Typeahead/TypeaheadInput/TypeaheadInput.mjs.map +1 -1
  95. package/build/Typeahead/TypeaheadOption/TypeaheadOption.js +3 -1
  96. package/build/Typeahead/TypeaheadOption/TypeaheadOption.js.map +1 -1
  97. package/build/Typeahead/TypeaheadOption/TypeaheadOption.mjs +3 -1
  98. package/build/Typeahead/TypeaheadOption/TypeaheadOption.mjs.map +1 -1
  99. package/build/i18n/en.json +5 -0
  100. package/build/i18n/en.json.js +5 -0
  101. package/build/i18n/en.json.js.map +1 -1
  102. package/build/i18n/en.json.mjs +5 -0
  103. package/build/i18n/en.json.mjs.map +1 -1
  104. package/build/i18n/hu.json +1 -1
  105. package/build/i18n/hu.json.js +1 -1
  106. package/build/i18n/hu.json.mjs +1 -1
  107. package/build/index.js +4 -2
  108. package/build/index.js.map +1 -1
  109. package/build/index.mjs +2 -1
  110. package/build/index.mjs.map +1 -1
  111. package/build/main.css +168 -43
  112. package/build/styles/Calendar/Calendar.css +112 -37
  113. package/build/styles/Calendar/TableLink/TableLink.css +115 -0
  114. package/build/styles/Markup/Markup.css +28 -0
  115. package/build/styles/Markup/_stories/Vulnerability/Vulnerability.css +69 -0
  116. package/build/styles/Typeahead/Typeahead.css +4 -0
  117. package/build/styles/Typeahead/TypeaheadOption/TypeaheadOption.css +5 -0
  118. package/build/styles/main.css +168 -43
  119. package/build/types/Calendar/Calendar.constants.d.ts +2 -0
  120. package/build/types/Calendar/Calendar.constants.d.ts.map +1 -0
  121. package/build/types/Calendar/Calendar.d.ts +16 -3
  122. package/build/types/Calendar/Calendar.d.ts.map +1 -1
  123. package/build/types/Calendar/Calendar.messages.d.ts +20 -0
  124. package/build/types/Calendar/Calendar.messages.d.ts.map +1 -1
  125. package/build/types/Calendar/Calendar.types.d.ts +32 -0
  126. package/build/types/Calendar/Calendar.types.d.ts.map +1 -0
  127. package/build/types/Calendar/DateHeader/DateHeader.d.ts +2 -0
  128. package/build/types/Calendar/DateHeader/DateHeader.d.ts.map +1 -1
  129. package/build/types/Calendar/DayCalendar/DayCalendar.d.ts +7 -1
  130. package/build/types/Calendar/DayCalendar/DayCalendar.d.ts.map +1 -1
  131. package/build/types/Calendar/DayCalendar/Table/DayCalendarTable.d.ts +6 -0
  132. package/build/types/Calendar/DayCalendar/Table/DayCalendarTable.d.ts.map +1 -1
  133. package/build/types/Calendar/MonthCalendar/MonthCalendar.d.ts +1 -0
  134. package/build/types/Calendar/MonthCalendar/MonthCalendar.d.ts.map +1 -1
  135. package/build/types/Calendar/MonthCalendar/Table/MonthCalendarTable.d.ts +2 -1
  136. package/build/types/Calendar/MonthCalendar/Table/MonthCalendarTable.d.ts.map +1 -1
  137. package/build/types/Calendar/{tableLink → TableLink}/TableLink.d.ts +5 -1
  138. package/build/types/Calendar/TableLink/TableLink.d.ts.map +1 -0
  139. package/build/types/Calendar/TableLink/index.d.ts.map +1 -0
  140. package/build/types/Calendar/YearCalendar/Table/YearCalendarTable.d.ts +2 -1
  141. package/build/types/Calendar/YearCalendar/Table/YearCalendarTable.d.ts.map +1 -1
  142. package/build/types/Calendar/YearCalendar/YearCalendar.d.ts +1 -0
  143. package/build/types/Calendar/YearCalendar/YearCalendar.d.ts.map +1 -1
  144. package/build/types/Calendar/_helpers/clampToDayViewBoundary/clampToDayViewBoundary.d.ts +8 -0
  145. package/build/types/Calendar/_helpers/clampToDayViewBoundary/clampToDayViewBoundary.d.ts.map +1 -0
  146. package/build/types/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.d.ts +3 -0
  147. package/build/types/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.d.ts.map +1 -0
  148. package/build/types/Calendar/_helpers/index.d.ts +4 -0
  149. package/build/types/Calendar/_helpers/index.d.ts.map +1 -0
  150. package/build/types/Calendar/_helpers/isDateDisabled/isDateDisabled.d.ts +3 -0
  151. package/build/types/Calendar/_helpers/isDateDisabled/isDateDisabled.d.ts.map +1 -0
  152. package/build/types/Calendar/index.d.ts +1 -0
  153. package/build/types/Calendar/index.d.ts.map +1 -1
  154. package/build/types/DateLookup/DateLookup.d.ts +24 -5
  155. package/build/types/DateLookup/DateLookup.d.ts.map +1 -1
  156. package/build/types/DateLookup/index.d.ts +1 -0
  157. package/build/types/DateLookup/index.d.ts.map +1 -1
  158. package/build/types/ExpressiveMoneyInput/CurrencySelector/CurrencySelector.d.ts +6 -4
  159. package/build/types/ExpressiveMoneyInput/CurrencySelector/CurrencySelector.d.ts.map +1 -1
  160. package/build/types/Inputs/SelectInput/TriggerButton/SelectInputTriggerButton.d.ts +1 -1
  161. package/build/types/Inputs/SelectInput/TriggerButton/SelectInputTriggerButton.d.ts.map +1 -1
  162. package/build/types/Markup/Markup.d.ts +18 -0
  163. package/build/types/Markup/Markup.d.ts.map +1 -0
  164. package/build/types/Markup/Markup.types.d.ts +77 -0
  165. package/build/types/Markup/Markup.types.d.ts.map +1 -0
  166. package/build/types/Markup/_stories/Vulnerability/Vulnerability.d.ts +12 -0
  167. package/build/types/Markup/_stories/Vulnerability/Vulnerability.d.ts.map +1 -0
  168. package/build/types/Markup/constants.d.ts +6 -0
  169. package/build/types/Markup/constants.d.ts.map +1 -0
  170. package/build/types/Markup/index.d.ts +3 -0
  171. package/build/types/Markup/index.d.ts.map +1 -0
  172. package/build/types/Markup/utils/parseMarkup.d.ts +8 -0
  173. package/build/types/Markup/utils/parseMarkup.d.ts.map +1 -0
  174. package/build/types/Markup/utils/sanitise.d.ts +4 -0
  175. package/build/types/Markup/utils/sanitise.d.ts.map +1 -0
  176. package/build/types/Typeahead/Typeahead.d.ts.map +1 -1
  177. package/build/types/Typeahead/Typeahead.messages.d.ts +5 -0
  178. package/build/types/Typeahead/Typeahead.messages.d.ts.map +1 -1
  179. package/build/types/Typeahead/TypeaheadInput/TypeaheadInput.d.ts.map +1 -1
  180. package/build/types/Typeahead/TypeaheadOption/TypeaheadOption.d.ts +1 -0
  181. package/build/types/Typeahead/TypeaheadOption/TypeaheadOption.d.ts.map +1 -1
  182. package/build/types/index.d.ts +5 -2
  183. package/build/types/index.d.ts.map +1 -1
  184. package/build/types/test-utils/index.d.ts +10 -0
  185. package/build/types/test-utils/index.d.ts.map +1 -1
  186. package/package.json +1 -1
  187. package/src/Calendar/Calendar.constants.ts +5 -0
  188. package/src/Calendar/Calendar.css +112 -37
  189. package/src/Calendar/Calendar.disabledDates.test.tsx +610 -0
  190. package/src/Calendar/Calendar.less +5 -35
  191. package/src/Calendar/Calendar.messages.ts +21 -0
  192. package/src/Calendar/Calendar.test.tsx +342 -32
  193. package/src/Calendar/Calendar.tsx +169 -19
  194. package/src/Calendar/Calendar.types.ts +35 -0
  195. package/src/Calendar/DateHeader/DateHeader.tsx +6 -0
  196. package/src/Calendar/DayCalendar/DayCalendar.tsx +39 -1
  197. package/src/Calendar/DayCalendar/Table/DayCalendarTable.tsx +67 -27
  198. package/src/Calendar/MonthCalendar/MonthCalendar.tsx +8 -0
  199. package/src/Calendar/MonthCalendar/Table/MonthCalendarTable.tsx +15 -3
  200. package/src/Calendar/TableLink/TableLink.css +115 -0
  201. package/src/Calendar/TableLink/TableLink.less +68 -0
  202. package/src/Calendar/TableLink/TableLink.tsx +117 -0
  203. package/src/Calendar/YearCalendar/Table/YearCalendarTable.tsx +15 -3
  204. package/src/Calendar/YearCalendar/YearCalendar.tsx +9 -0
  205. package/src/Calendar/_helpers/clampToDayViewBoundary/clampToDayViewBoundary.test.ts +90 -0
  206. package/src/Calendar/_helpers/clampToDayViewBoundary/clampToDayViewBoundary.ts +25 -0
  207. package/src/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.test.ts +98 -0
  208. package/src/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.ts +45 -0
  209. package/src/Calendar/_helpers/index.ts +3 -0
  210. package/src/Calendar/_helpers/isDateDisabled/isDateDisabled.test.ts +169 -0
  211. package/src/Calendar/_helpers/isDateDisabled/isDateDisabled.ts +59 -0
  212. package/src/Calendar/_stories/Calendar.accessibility.docs.mdx +118 -0
  213. package/src/Calendar/_stories/Calendar.story.tsx +144 -4
  214. package/src/Calendar/_stories/Calendar.test.story.tsx +114 -0
  215. package/src/Calendar/index.ts +7 -0
  216. package/src/DateLookup/DateLookup.disabledDates.test.tsx +312 -0
  217. package/src/DateLookup/DateLookup.test.tsx +34 -37
  218. package/src/DateLookup/DateLookup.tsx +37 -13
  219. package/src/DateLookup/_stories/DateLookup.accessibility.docs.mdx +108 -0
  220. package/src/DateLookup/_stories/DateLookup.story.tsx +126 -2
  221. package/src/DateLookup/index.ts +6 -0
  222. package/src/ExpressiveMoneyInput/CurrencySelector/CurrencySelector.tsx +12 -13
  223. package/src/Inputs/SelectInput/SelectInput.test.tsx +37 -0
  224. package/src/Inputs/SelectInput/TriggerButton/SelectInputTriggerButton.tsx +1 -1
  225. package/src/Markup/Markup.css +28 -0
  226. package/src/Markup/Markup.injection.test.tsx +163 -0
  227. package/src/Markup/Markup.less +29 -0
  228. package/src/Markup/Markup.test.tsx +502 -0
  229. package/src/Markup/Markup.tsx +175 -0
  230. package/src/Markup/Markup.types.ts +62 -0
  231. package/src/Markup/_stories/Markup.docs.mdx +75 -0
  232. package/src/Markup/_stories/Markup.security.docs.mdx +343 -0
  233. package/src/Markup/_stories/Markup.story.tsx +266 -0
  234. package/src/Markup/_stories/Vulnerability/Vulnerability.css +69 -0
  235. package/src/Markup/_stories/Vulnerability/Vulnerability.tsx +30 -0
  236. package/src/Markup/constants.ts +23 -0
  237. package/src/Markup/index.ts +2 -0
  238. package/src/Markup/utils/parseMarkup.test.ts +706 -0
  239. package/src/Markup/utils/parseMarkup.ts +265 -0
  240. package/src/Markup/utils/sanitise.test.ts +499 -0
  241. package/src/Markup/utils/sanitise.ts +129 -0
  242. package/src/Typeahead/Typeahead.css +4 -0
  243. package/src/Typeahead/Typeahead.less +2 -0
  244. package/src/Typeahead/Typeahead.messages.ts +5 -0
  245. package/src/Typeahead/Typeahead.test.tsx +80 -3
  246. package/src/Typeahead/Typeahead.tsx +50 -27
  247. package/src/Typeahead/TypeaheadInput/TypeaheadInput.tsx +2 -6
  248. package/src/Typeahead/TypeaheadOption/TypeaheadOption.css +5 -0
  249. package/src/Typeahead/TypeaheadOption/TypeaheadOption.less +9 -0
  250. package/src/Typeahead/TypeaheadOption/TypeaheadOption.tsx +4 -2
  251. package/src/i18n/en.json +4 -0
  252. package/src/i18n/hu.json +1 -1
  253. package/src/index.ts +5 -2
  254. package/src/main.css +168 -43
  255. package/src/main.less +1 -0
  256. package/build/Calendar/tableLink/TableLink.js +0 -61
  257. package/build/Calendar/tableLink/TableLink.js.map +0 -1
  258. package/build/Calendar/tableLink/TableLink.mjs +0 -57
  259. package/build/Calendar/tableLink/TableLink.mjs.map +0 -1
  260. package/build/types/Calendar/tableLink/TableLink.d.ts.map +0 -1
  261. package/build/types/Calendar/tableLink/index.d.ts.map +0 -1
  262. package/src/Calendar/tableLink/TableLink.tsx +0 -77
  263. /package/build/types/Calendar/{tableLink → TableLink}/index.d.ts +0 -0
  264. /package/src/Calendar/{tableLink → TableLink}/index.ts +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"SelectInputTriggerButton.mjs","sources":["../../../../src/Inputs/SelectInput/TriggerButton/SelectInputTriggerButton.tsx"],"sourcesContent":["import { ListboxButton } from '@headlessui/react';\nimport mergeProps from 'merge-props';\nimport { useContext } from 'react';\nimport { PolymorphicWithOverrides } from '../../../common/PolymorphicWithOverrides/PolymorphicWithOverrides';\nimport { Merge } from '../../../utils';\nimport { SelectInputTriggerButtonPropsContext } from '../SelectInput.contexts';\n\nexport type SelectInputTriggerButtonElementType = 'button' | React.ComponentType;\n\nexport type SelectInputTriggerButtonProps<\n T extends SelectInputTriggerButtonElementType = 'button',\n> = Merge<React.ComponentPropsWithoutRef<T>, { as?: T }>;\n\n/**\n * The trigger button component for SelectInput.\n * Uses Headless UI's ListboxButton with polymorphic support to allow\n * rendering as different element types.\n */\nexport function SelectInputTriggerButton<T extends SelectInputTriggerButtonElementType = 'button'>({\n as = 'button' as T,\n ...restProps\n}: SelectInputTriggerButtonProps<T>) {\n const { ref, onClick, onKeyDown, size, ...interactionProps } = useContext(\n SelectInputTriggerButtonPropsContext,\n );\n\n return (\n <ListboxButton\n ref={ref}\n as={PolymorphicWithOverrides}\n role=\"combobox\"\n __overrides={{ as, size, ...interactionProps }}\n {...mergeProps({ onClick, onKeyDown }, restProps)}\n />\n );\n}\n"],"names":["SelectInputTriggerButton","as","restProps","ref","onClick","onKeyDown","size","interactionProps","useContext","SelectInputTriggerButtonPropsContext","_jsx","ListboxButton","PolymorphicWithOverrides","role","__overrides","mergeProps"],"mappings":";;;;;;;AAkBM,SAAUA,wBAAwBA,CAA2D;AACjGC,EAAAA,EAAE,GAAG,QAAa;EAClB,GAAGC;AAAS,CACqB,EAAA;EACjC,MAAM;IAAEC,GAAG;IAAEC,OAAO;IAAEC,SAAS;IAAEC,IAAI;IAAE,GAAGC;AAAgB,GAAE,GAAGC,UAAU,CACvEC,oCAAoC,CACrC;EAED,oBACEC,GAAA,CAACC,aAAa,EAAA;AACZR,IAAAA,GAAG,EAAEA,GAAI;AACTF,IAAAA,EAAE,EAAEW,wBAAyB;AAC7BC,IAAAA,IAAI,EAAC,UAAU;AACfC,IAAAA,WAAW,EAAE;MAAEb,EAAE;MAAEK,IAAI;MAAE,GAAGC;KAAmB;AAAA,IAAA,GAC3CQ,UAAU,CAAC;MAAEX,OAAO;AAAEC,MAAAA;AAAS,KAAE,EAAEH,SAAS;AAAC,GAAC,CAClD;AAEN;;;;"}
1
+ {"version":3,"file":"SelectInputTriggerButton.mjs","sources":["../../../../src/Inputs/SelectInput/TriggerButton/SelectInputTriggerButton.tsx"],"sourcesContent":["import { ListboxButton } from '@headlessui/react';\nimport mergeProps from 'merge-props';\nimport { useContext } from 'react';\nimport { PolymorphicWithOverrides } from '../../../common/PolymorphicWithOverrides/PolymorphicWithOverrides';\nimport { Merge } from '../../../utils';\nimport { SelectInputTriggerButtonPropsContext } from '../SelectInput.contexts';\n\nexport type SelectInputTriggerButtonElementType = React.ElementType;\n\nexport type SelectInputTriggerButtonProps<\n T extends SelectInputTriggerButtonElementType = 'button',\n> = Merge<React.ComponentPropsWithoutRef<T>, { as?: T }>;\n\n/**\n * The trigger button component for SelectInput.\n * Uses Headless UI's ListboxButton with polymorphic support to allow\n * rendering as different element types.\n */\nexport function SelectInputTriggerButton<T extends SelectInputTriggerButtonElementType = 'button'>({\n as = 'button' as T,\n ...restProps\n}: SelectInputTriggerButtonProps<T>) {\n const { ref, onClick, onKeyDown, size, ...interactionProps } = useContext(\n SelectInputTriggerButtonPropsContext,\n );\n\n return (\n <ListboxButton\n ref={ref}\n as={PolymorphicWithOverrides}\n role=\"combobox\"\n __overrides={{ as, size, ...interactionProps }}\n {...mergeProps({ onClick, onKeyDown }, restProps)}\n />\n );\n}\n"],"names":["SelectInputTriggerButton","as","restProps","ref","onClick","onKeyDown","size","interactionProps","useContext","SelectInputTriggerButtonPropsContext","_jsx","ListboxButton","PolymorphicWithOverrides","role","__overrides","mergeProps"],"mappings":";;;;;;;AAkBM,SAAUA,wBAAwBA,CAA2D;AACjGC,EAAAA,EAAE,GAAG,QAAa;EAClB,GAAGC;AAAS,CACqB,EAAA;EACjC,MAAM;IAAEC,GAAG;IAAEC,OAAO;IAAEC,SAAS;IAAEC,IAAI;IAAE,GAAGC;AAAgB,GAAE,GAAGC,UAAU,CACvEC,oCAAoC,CACrC;EAED,oBACEC,GAAA,CAACC,aAAa,EAAA;AACZR,IAAAA,GAAG,EAAEA,GAAI;AACTF,IAAAA,EAAE,EAAEW,wBAAyB;AAC7BC,IAAAA,IAAI,EAAC,UAAU;AACfC,IAAAA,WAAW,EAAE;MAAEb,EAAE;MAAEK,IAAI;MAAE,GAAGC;KAAmB;AAAA,IAAA,GAC3CQ,UAAU,CAAC;MAAEX,OAAO;AAAEC,MAAAA;AAAS,KAAE,EAAEH,SAAS;AAAC,GAAC,CAClD;AAEN;;;;"}
@@ -0,0 +1,138 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+ var Link = require('../Link/Link.js');
7
+ var parseMarkup = require('./utils/parseMarkup.js');
8
+ var sanitise = require('./utils/sanitise.js');
9
+ var jsxRuntime = require('react/jsx-runtime');
10
+
11
+ const PLACEHOLDER_REGEX = /\{\{(\w+)\}\}/g;
12
+ function substituteData(text, data) {
13
+ return text.replace(PLACEHOLDER_REGEX, (match, key) => Object.prototype.hasOwnProperty.call(data, key) ? String(data[key]) : match);
14
+ }
15
+ function renderNodes(nodes, actions, data, allowLinks) {
16
+ return nodes.map((node, index) => renderNode(node, actions, data, allowLinks, index));
17
+ }
18
+ function renderLinkNode(node, actions, data, allowLinks, key) {
19
+ const children = renderNodes(node.children, actions, data, allowLinks);
20
+ if (node.action && actions?.[node.action]) {
21
+ return (
22
+ /*#__PURE__*/
23
+ // eslint-disable-next-line jsx-a11y/click-events-have-key-events
24
+ jsxRuntime.jsx(Link.default, {
25
+ "aria-label": node.accessibilityLabel,
26
+ onClick: actions[node.action],
27
+ children: children
28
+ }, key)
29
+ );
30
+ }
31
+ const sanitisedHref = node.href ? sanitise.sanitiseHref(node.href) : undefined;
32
+ if (sanitisedHref && sanitise.isHrefAllowedByMode(sanitisedHref, allowLinks)) {
33
+ return /*#__PURE__*/jsxRuntime.jsx(Link.default, {
34
+ href: sanitisedHref,
35
+ target: node.target,
36
+ "aria-label": node.accessibilityLabel,
37
+ children: children
38
+ }, key);
39
+ }
40
+ return /*#__PURE__*/jsxRuntime.jsx(React.Fragment, {
41
+ children: children
42
+ }, key);
43
+ }
44
+ function renderNode(node, actions, data, allowLinks, key) {
45
+ switch (node.type) {
46
+ case 'text':
47
+ return /*#__PURE__*/jsxRuntime.jsx(React.Fragment, {
48
+ children: data ? substituteData(node.content, data) : node.content
49
+ }, key);
50
+ case 'newline':
51
+ return /*#__PURE__*/jsxRuntime.jsx("br", {}, key);
52
+ case 'important':
53
+ case 'positive':
54
+ case 'negative':
55
+ return /*#__PURE__*/jsxRuntime.jsx("em", {
56
+ className: `wds-markup-emphasis wds-markup-emphasis--${node.type}`,
57
+ "aria-label": node.accessibilityLabel,
58
+ children: renderNodes(node.children, actions, data, allowLinks)
59
+ }, key);
60
+ case 'strong':
61
+ return /*#__PURE__*/jsxRuntime.jsx("strong", {
62
+ className: "wds-markup-strong",
63
+ "aria-label": node.accessibilityLabel,
64
+ children: renderNodes(node.children, actions, data, allowLinks)
65
+ }, key);
66
+ case 'strikethrough':
67
+ return /*#__PURE__*/jsxRuntime.jsx("del", {
68
+ className: "wds-markup-strikethrough",
69
+ "aria-label": node.accessibilityLabel,
70
+ children: renderNodes(node.children, actions, data, allowLinks)
71
+ }, key);
72
+ case 'paragraph':
73
+ return /*#__PURE__*/jsxRuntime.jsx("p", {
74
+ className: "wds-markup-paragraph",
75
+ children: renderNodes(node.children, actions, data, allowLinks)
76
+ }, key);
77
+ case 'link':
78
+ return renderLinkNode(node, actions, data, allowLinks, key);
79
+ }
80
+ }
81
+ function hasParagraph(nodes) {
82
+ for (const node of nodes) {
83
+ if (node.type === 'paragraph') {
84
+ return true;
85
+ }
86
+ if ('children' in node && hasParagraph(node.children)) {
87
+ return true;
88
+ }
89
+ }
90
+ return false;
91
+ }
92
+ /**
93
+ * Parses a markup string and renders it as React elements. Supports `<important>`,
94
+ * `<positive>`, `<negative>`, `<strong>`, `<strikethrough>`, `<paragraph>` (alias `<p>`),
95
+ * and `<link>` (alias `<a>`) with secure href validation.
96
+ *
97
+ * It only processes `string` input, while `ReactNode` is passed-through without processing.
98
+ *
99
+ * > The component supersedes [Emphasis](?path=/docs/typography-emphasis--docs), which will be
100
+ * eventually deprecated.
101
+ *
102
+ * @see http://storybook.wise.design/?path=/docs/typography-markup--docs
103
+ * @link ../emphasis/Emphasis | Emphasis
104
+ */
105
+ const Markup = ({
106
+ children,
107
+ data,
108
+ allowLinks = 'internal',
109
+ actions,
110
+ as,
111
+ className,
112
+ 'data-testid': testId
113
+ }) => {
114
+ const tree = React.useMemo(() => typeof children === 'string' ? parseMarkup.parseMarkup(children) : [], [children]);
115
+ if (typeof children !== 'string') {
116
+ if (children == null) {
117
+ return null;
118
+ }
119
+ return /*#__PURE__*/jsxRuntime.jsx("span", {
120
+ className: className,
121
+ "data-testid": testId,
122
+ children: children
123
+ });
124
+ }
125
+ if (tree.length === 0) {
126
+ return null;
127
+ }
128
+ const Element = as ?? (hasParagraph(tree) ? 'div' : 'span');
129
+ return /*#__PURE__*/jsxRuntime.jsx(Element, {
130
+ className: className,
131
+ "data-testid": testId,
132
+ children: renderNodes(tree, actions, data, allowLinks)
133
+ });
134
+ };
135
+
136
+ exports.Markup = Markup;
137
+ exports.default = Markup;
138
+ //# sourceMappingURL=Markup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Markup.js","sources":["../../src/Markup/Markup.tsx"],"sourcesContent":["import React, { Fragment, useMemo } from 'react';\n\nimport Link from '../Link';\n\nimport { parseMarkup } from './utils/parseMarkup';\nimport { type AllowLinksMode, isHrefAllowedByMode, sanitiseHref } from './utils/sanitise';\nimport type { MarkupActions, MarkupNode, MarkupProps } from './Markup.types';\n\nconst PLACEHOLDER_REGEX = /\\{\\{(\\w+)\\}\\}/g;\n\ntype MarkupData = Record<string, string | number>;\n\nfunction substituteData(text: string, data: MarkupData): string {\n return text.replace(PLACEHOLDER_REGEX, (match, key: string) =>\n Object.prototype.hasOwnProperty.call(data, key) ? String(data[key]) : match,\n );\n}\n\nfunction renderNodes(\n nodes: MarkupNode[],\n actions: MarkupActions | undefined,\n data: MarkupData | undefined,\n allowLinks: AllowLinksMode,\n): React.ReactNode[] {\n return nodes.map((node, index) => renderNode(node, actions, data, allowLinks, index));\n}\n\nfunction renderLinkNode(\n node: Extract<MarkupNode, { type: 'link' }>,\n actions: MarkupActions | undefined,\n data: MarkupData | undefined,\n allowLinks: AllowLinksMode,\n key: number,\n): React.ReactNode {\n const children = renderNodes(node.children, actions, data, allowLinks);\n\n if (node.action && actions?.[node.action]) {\n return (\n // eslint-disable-next-line jsx-a11y/click-events-have-key-events\n <Link key={key} aria-label={node.accessibilityLabel} onClick={actions[node.action]}>\n {children}\n </Link>\n );\n }\n\n const sanitisedHref = node.href ? sanitiseHref(node.href) : undefined;\n if (sanitisedHref && isHrefAllowedByMode(sanitisedHref, allowLinks)) {\n return (\n <Link\n key={key}\n href={sanitisedHref}\n target={node.target}\n aria-label={node.accessibilityLabel}\n >\n {children}\n </Link>\n );\n }\n\n return <Fragment key={key}>{children}</Fragment>;\n}\n\nfunction renderNode(\n node: MarkupNode,\n actions: MarkupActions | undefined,\n data: MarkupData | undefined,\n allowLinks: AllowLinksMode,\n key: number,\n): React.ReactNode {\n switch (node.type) {\n case 'text':\n return (\n <Fragment key={key}>{data ? substituteData(node.content, data) : node.content}</Fragment>\n );\n case 'newline':\n return <br key={key} />;\n case 'important':\n case 'positive':\n case 'negative':\n return (\n <em\n key={key}\n className={`wds-markup-emphasis wds-markup-emphasis--${node.type}`}\n aria-label={node.accessibilityLabel}\n >\n {renderNodes(node.children, actions, data, allowLinks)}\n </em>\n );\n case 'strong':\n return (\n <strong key={key} className=\"wds-markup-strong\" aria-label={node.accessibilityLabel}>\n {renderNodes(node.children, actions, data, allowLinks)}\n </strong>\n );\n case 'strikethrough':\n return (\n <del key={key} className=\"wds-markup-strikethrough\" aria-label={node.accessibilityLabel}>\n {renderNodes(node.children, actions, data, allowLinks)}\n </del>\n );\n case 'paragraph':\n return (\n <p key={key} className=\"wds-markup-paragraph\">\n {renderNodes(node.children, actions, data, allowLinks)}\n </p>\n );\n case 'link':\n return renderLinkNode(node, actions, data, allowLinks, key);\n }\n}\n\nfunction hasParagraph(nodes: MarkupNode[]): boolean {\n for (const node of nodes) {\n if (node.type === 'paragraph') {\n return true;\n }\n if ('children' in node && hasParagraph(node.children)) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Parses a markup string and renders it as React elements. Supports `<important>`,\n * `<positive>`, `<negative>`, `<strong>`, `<strikethrough>`, `<paragraph>` (alias `<p>`),\n * and `<link>` (alias `<a>`) with secure href validation.\n *\n * It only processes `string` input, while `ReactNode` is passed-through without processing.\n *\n * > The component supersedes [Emphasis](?path=/docs/typography-emphasis--docs), which will be\n * eventually deprecated.\n *\n * @see http://storybook.wise.design/?path=/docs/typography-markup--docs\n * @link ../emphasis/Emphasis | Emphasis\n */\nexport const Markup: React.FC<MarkupProps> = ({\n children,\n data,\n allowLinks = 'internal',\n actions,\n as,\n className,\n 'data-testid': testId,\n}) => {\n const tree = useMemo(\n () => (typeof children === 'string' ? parseMarkup(children) : []),\n [children],\n );\n\n if (typeof children !== 'string') {\n if (children == null) {\n return null;\n }\n return (\n <span className={className} data-testid={testId}>\n {children}\n </span>\n );\n }\n\n if (tree.length === 0) {\n return null;\n }\n\n const Element = as ?? (hasParagraph(tree) ? 'div' : 'span');\n\n return (\n <Element className={className} data-testid={testId}>\n {renderNodes(tree, actions, data, allowLinks)}\n </Element>\n );\n};\n\nexport default Markup;\n"],"names":["PLACEHOLDER_REGEX","substituteData","text","data","replace","match","key","Object","prototype","hasOwnProperty","call","String","renderNodes","nodes","actions","allowLinks","map","node","index","renderNode","renderLinkNode","children","action","_jsx","Link","accessibilityLabel","onClick","sanitisedHref","href","sanitiseHref","undefined","isHrefAllowedByMode","target","Fragment","type","content","className","hasParagraph","Markup","as","testId","tree","useMemo","parseMarkup","length","Element"],"mappings":";;;;;;;;;;AAQA,MAAMA,iBAAiB,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AAQ;EACRlB,IAAI;AACJY,EAAAA,UAAU,GAAG,UAAU;EACvBD,OAAO;EACPyB,EAAE;EACFH,SAAS;AACT,EAAA,aAAa,EAAEI;AAAM,CACtB,KAAI;EACH,MAAMC,IAAI,GAAGC,aAAO,CAClB,MAAO,OAAOrB,QAAQ,KAAK,QAAQ,GAAGsB,uBAAW,CAACtB,QAAQ,CAAC,GAAG,EAAG,EACjE,CAACA,QAAQ,CAAC,CACX;AAED,EAAA,IAAI,OAAOA,QAAQ,KAAK,QAAQ,EAAE;IAChC,IAAIA,QAAQ,IAAI,IAAI,EAAE;AACpB,MAAA,OAAO,IAAI;AACb,IAAA;AACA,IAAA,oBACEE,cAAA,CAAA,MAAA,EAAA;AAAMa,MAAAA,SAAS,EAAEA,SAAU;AAAC,MAAA,aAAA,EAAaI,MAAO;AAAAnB,MAAAA,QAAA,EAC7CA;AAAQ,KACL,CAAC;AAEX,EAAA;AAEA,EAAA,IAAIoB,IAAI,CAACG,MAAM,KAAK,CAAC,EAAE;AACrB,IAAA,OAAO,IAAI;AACb,EAAA;AAEA,EAAA,MAAMC,OAAO,GAAGN,EAAE,KAAKF,YAAY,CAACI,IAAI,CAAC,GAAG,KAAK,GAAG,MAAM,CAAC;EAE3D,oBACElB,cAAA,CAACsB,OAAO,EAAA;AAACT,IAAAA,SAAS,EAAEA,SAAU;AAAC,IAAA,aAAA,EAAaI,MAAO;IAAAnB,QAAA,EAChDT,WAAW,CAAC6B,IAAI,EAAE3B,OAAO,EAAEX,IAAI,EAAEY,UAAU;AAAC,GACtC,CAAC;AAEd;;;;;"}
@@ -0,0 +1,133 @@
1
+ import { useMemo, Fragment } from 'react';
2
+ import Link from '../Link/Link.mjs';
3
+ import { parseMarkup } from './utils/parseMarkup.mjs';
4
+ import { sanitiseHref, isHrefAllowedByMode } from './utils/sanitise.mjs';
5
+ import { jsx } from 'react/jsx-runtime';
6
+
7
+ const PLACEHOLDER_REGEX = /\{\{(\w+)\}\}/g;
8
+ function substituteData(text, data) {
9
+ return text.replace(PLACEHOLDER_REGEX, (match, key) => Object.prototype.hasOwnProperty.call(data, key) ? String(data[key]) : match);
10
+ }
11
+ function renderNodes(nodes, actions, data, allowLinks) {
12
+ return nodes.map((node, index) => renderNode(node, actions, data, allowLinks, index));
13
+ }
14
+ function renderLinkNode(node, actions, data, allowLinks, key) {
15
+ const children = renderNodes(node.children, actions, data, allowLinks);
16
+ if (node.action && actions?.[node.action]) {
17
+ return (
18
+ /*#__PURE__*/
19
+ // eslint-disable-next-line jsx-a11y/click-events-have-key-events
20
+ jsx(Link, {
21
+ "aria-label": node.accessibilityLabel,
22
+ onClick: actions[node.action],
23
+ children: children
24
+ }, key)
25
+ );
26
+ }
27
+ const sanitisedHref = node.href ? sanitiseHref(node.href) : undefined;
28
+ if (sanitisedHref && isHrefAllowedByMode(sanitisedHref, allowLinks)) {
29
+ return /*#__PURE__*/jsx(Link, {
30
+ href: sanitisedHref,
31
+ target: node.target,
32
+ "aria-label": node.accessibilityLabel,
33
+ children: children
34
+ }, key);
35
+ }
36
+ return /*#__PURE__*/jsx(Fragment, {
37
+ children: children
38
+ }, key);
39
+ }
40
+ function renderNode(node, actions, data, allowLinks, key) {
41
+ switch (node.type) {
42
+ case 'text':
43
+ return /*#__PURE__*/jsx(Fragment, {
44
+ children: data ? substituteData(node.content, data) : node.content
45
+ }, key);
46
+ case 'newline':
47
+ return /*#__PURE__*/jsx("br", {}, key);
48
+ case 'important':
49
+ case 'positive':
50
+ case 'negative':
51
+ return /*#__PURE__*/jsx("em", {
52
+ className: `wds-markup-emphasis wds-markup-emphasis--${node.type}`,
53
+ "aria-label": node.accessibilityLabel,
54
+ children: renderNodes(node.children, actions, data, allowLinks)
55
+ }, key);
56
+ case 'strong':
57
+ return /*#__PURE__*/jsx("strong", {
58
+ className: "wds-markup-strong",
59
+ "aria-label": node.accessibilityLabel,
60
+ children: renderNodes(node.children, actions, data, allowLinks)
61
+ }, key);
62
+ case 'strikethrough':
63
+ return /*#__PURE__*/jsx("del", {
64
+ className: "wds-markup-strikethrough",
65
+ "aria-label": node.accessibilityLabel,
66
+ children: renderNodes(node.children, actions, data, allowLinks)
67
+ }, key);
68
+ case 'paragraph':
69
+ return /*#__PURE__*/jsx("p", {
70
+ className: "wds-markup-paragraph",
71
+ children: renderNodes(node.children, actions, data, allowLinks)
72
+ }, key);
73
+ case 'link':
74
+ return renderLinkNode(node, actions, data, allowLinks, key);
75
+ }
76
+ }
77
+ function hasParagraph(nodes) {
78
+ for (const node of nodes) {
79
+ if (node.type === 'paragraph') {
80
+ return true;
81
+ }
82
+ if ('children' in node && hasParagraph(node.children)) {
83
+ return true;
84
+ }
85
+ }
86
+ return false;
87
+ }
88
+ /**
89
+ * Parses a markup string and renders it as React elements. Supports `<important>`,
90
+ * `<positive>`, `<negative>`, `<strong>`, `<strikethrough>`, `<paragraph>` (alias `<p>`),
91
+ * and `<link>` (alias `<a>`) with secure href validation.
92
+ *
93
+ * It only processes `string` input, while `ReactNode` is passed-through without processing.
94
+ *
95
+ * > The component supersedes [Emphasis](?path=/docs/typography-emphasis--docs), which will be
96
+ * eventually deprecated.
97
+ *
98
+ * @see http://storybook.wise.design/?path=/docs/typography-markup--docs
99
+ * @link ../emphasis/Emphasis | Emphasis
100
+ */
101
+ const Markup = ({
102
+ children,
103
+ data,
104
+ allowLinks = 'internal',
105
+ actions,
106
+ as,
107
+ className,
108
+ 'data-testid': testId
109
+ }) => {
110
+ const tree = useMemo(() => typeof children === 'string' ? parseMarkup(children) : [], [children]);
111
+ if (typeof children !== 'string') {
112
+ if (children == null) {
113
+ return null;
114
+ }
115
+ return /*#__PURE__*/jsx("span", {
116
+ className: className,
117
+ "data-testid": testId,
118
+ children: children
119
+ });
120
+ }
121
+ if (tree.length === 0) {
122
+ return null;
123
+ }
124
+ const Element = as ?? (hasParagraph(tree) ? 'div' : 'span');
125
+ return /*#__PURE__*/jsx(Element, {
126
+ className: className,
127
+ "data-testid": testId,
128
+ children: renderNodes(tree, actions, data, allowLinks)
129
+ });
130
+ };
131
+
132
+ export { Markup, Markup as default };
133
+ //# sourceMappingURL=Markup.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Markup.mjs","sources":["../../src/Markup/Markup.tsx"],"sourcesContent":["import React, { Fragment, useMemo } from 'react';\n\nimport Link from '../Link';\n\nimport { parseMarkup } from './utils/parseMarkup';\nimport { type AllowLinksMode, isHrefAllowedByMode, sanitiseHref } from './utils/sanitise';\nimport type { MarkupActions, MarkupNode, MarkupProps } from './Markup.types';\n\nconst PLACEHOLDER_REGEX = /\\{\\{(\\w+)\\}\\}/g;\n\ntype MarkupData = Record<string, string | number>;\n\nfunction substituteData(text: string, data: MarkupData): string {\n return text.replace(PLACEHOLDER_REGEX, (match, key: string) =>\n Object.prototype.hasOwnProperty.call(data, key) ? String(data[key]) : match,\n );\n}\n\nfunction renderNodes(\n nodes: MarkupNode[],\n actions: MarkupActions | undefined,\n data: MarkupData | undefined,\n allowLinks: AllowLinksMode,\n): React.ReactNode[] {\n return nodes.map((node, index) => renderNode(node, actions, data, allowLinks, index));\n}\n\nfunction renderLinkNode(\n node: Extract<MarkupNode, { type: 'link' }>,\n actions: MarkupActions | undefined,\n data: MarkupData | undefined,\n allowLinks: AllowLinksMode,\n key: number,\n): React.ReactNode {\n const children = renderNodes(node.children, actions, data, allowLinks);\n\n if (node.action && actions?.[node.action]) {\n return (\n // eslint-disable-next-line jsx-a11y/click-events-have-key-events\n <Link key={key} aria-label={node.accessibilityLabel} onClick={actions[node.action]}>\n {children}\n </Link>\n );\n }\n\n const sanitisedHref = node.href ? sanitiseHref(node.href) : undefined;\n if (sanitisedHref && isHrefAllowedByMode(sanitisedHref, allowLinks)) {\n return (\n <Link\n key={key}\n href={sanitisedHref}\n target={node.target}\n aria-label={node.accessibilityLabel}\n >\n {children}\n </Link>\n );\n }\n\n return <Fragment key={key}>{children}</Fragment>;\n}\n\nfunction renderNode(\n node: MarkupNode,\n actions: MarkupActions | undefined,\n data: MarkupData | undefined,\n allowLinks: AllowLinksMode,\n key: number,\n): React.ReactNode {\n switch (node.type) {\n case 'text':\n return (\n <Fragment key={key}>{data ? substituteData(node.content, data) : node.content}</Fragment>\n );\n case 'newline':\n return <br key={key} />;\n case 'important':\n case 'positive':\n case 'negative':\n return (\n <em\n key={key}\n className={`wds-markup-emphasis wds-markup-emphasis--${node.type}`}\n aria-label={node.accessibilityLabel}\n >\n {renderNodes(node.children, actions, data, allowLinks)}\n </em>\n );\n case 'strong':\n return (\n <strong key={key} className=\"wds-markup-strong\" aria-label={node.accessibilityLabel}>\n {renderNodes(node.children, actions, data, allowLinks)}\n </strong>\n );\n case 'strikethrough':\n return (\n <del key={key} className=\"wds-markup-strikethrough\" aria-label={node.accessibilityLabel}>\n {renderNodes(node.children, actions, data, allowLinks)}\n </del>\n );\n case 'paragraph':\n return (\n <p key={key} className=\"wds-markup-paragraph\">\n {renderNodes(node.children, actions, data, allowLinks)}\n </p>\n );\n case 'link':\n return renderLinkNode(node, actions, data, allowLinks, key);\n }\n}\n\nfunction hasParagraph(nodes: MarkupNode[]): boolean {\n for (const node of nodes) {\n if (node.type === 'paragraph') {\n return true;\n }\n if ('children' in node && hasParagraph(node.children)) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Parses a markup string and renders it as React elements. Supports `<important>`,\n * `<positive>`, `<negative>`, `<strong>`, `<strikethrough>`, `<paragraph>` (alias `<p>`),\n * and `<link>` (alias `<a>`) with secure href validation.\n *\n * It only processes `string` input, while `ReactNode` is passed-through without processing.\n *\n * > The component supersedes [Emphasis](?path=/docs/typography-emphasis--docs), which will be\n * eventually deprecated.\n *\n * @see http://storybook.wise.design/?path=/docs/typography-markup--docs\n * @link ../emphasis/Emphasis | Emphasis\n */\nexport const Markup: React.FC<MarkupProps> = ({\n children,\n data,\n allowLinks = 'internal',\n actions,\n as,\n className,\n 'data-testid': testId,\n}) => {\n const tree = useMemo(\n () => (typeof children === 'string' ? parseMarkup(children) : []),\n [children],\n );\n\n if (typeof children !== 'string') {\n if (children == null) {\n return null;\n }\n return (\n <span className={className} data-testid={testId}>\n {children}\n </span>\n );\n }\n\n if (tree.length === 0) {\n return null;\n }\n\n const Element = as ?? (hasParagraph(tree) ? 'div' : 'span');\n\n return (\n <Element className={className} data-testid={testId}>\n {renderNodes(tree, actions, data, allowLinks)}\n </Element>\n );\n};\n\nexport default Markup;\n"],"names":["PLACEHOLDER_REGEX","substituteData","text","data","replace","match","key","Object","prototype","hasOwnProperty","call","String","renderNodes","nodes","actions","allowLinks","map","node","index","renderNode","renderLinkNode","children","action","_jsx","Link","accessibilityLabel","onClick","sanitisedHref","href","sanitiseHref","undefined","isHrefAllowedByMode","target","Fragment","type","content","className","hasParagraph","Markup","as","testId","tree","useMemo","parseMarkup","length","Element"],"mappings":";;;;;;AAQA,MAAMA,iBAAiB,GAAG,gBAAgB;AAI1C,SAASC,cAAcA,CAACC,IAAY,EAAEC,IAAgB,EAAA;AACpD,EAAA,OAAOD,IAAI,CAACE,OAAO,CAACJ,iBAAiB,EAAE,CAACK,KAAK,EAAEC,GAAW,KACxDC,MAAM,CAACC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACP,IAAI,EAAEG,GAAG,CAAC,GAAGK,MAAM,CAACR,IAAI,CAACG,GAAG,CAAC,CAAC,GAAGD,KAAK,CAC5E;AACH;AAEA,SAASO,WAAWA,CAClBC,KAAmB,EACnBC,OAAkC,EAClCX,IAA4B,EAC5BY,UAA0B,EAAA;EAE1B,OAAOF,KAAK,CAACG,GAAG,CAAC,CAACC,IAAI,EAAEC,KAAK,KAAKC,UAAU,CAACF,IAAI,EAAEH,OAAO,EAAEX,IAAI,EAAEY,UAAU,EAAEG,KAAK,CAAC,CAAC;AACvF;AAEA,SAASE,cAAcA,CACrBH,IAA2C,EAC3CH,OAAkC,EAClCX,IAA4B,EAC5BY,UAA0B,EAC1BT,GAAW,EAAA;AAEX,EAAA,MAAMe,QAAQ,GAAGT,WAAW,CAACK,IAAI,CAACI,QAAQ,EAAEP,OA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CAAC,GAAG,KAAK,GAAG,MAAM,CAAC;EAE3D,oBACElB,GAAA,CAACsB,OAAO,EAAA;AAACT,IAAAA,SAAS,EAAEA,SAAU;AAAC,IAAA,aAAA,EAAaI,MAAO;IAAAnB,QAAA,EAChDT,WAAW,CAAC6B,IAAI,EAAE3B,OAAO,EAAEX,IAAI,EAAEY,UAAU;AAAC,GACtC,CAAC;AAEd;;;;"}
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ // Only these tags are recognised — anything else is treated as plain text (security allow-list)
4
+ const ALLOWED_TAGS = ['important', 'positive', 'negative', 'strong', 'strikethrough', 'paragraph', 'p', 'link', 'a'];
5
+ const TAG_ALIASES = {
6
+ p: 'paragraph',
7
+ a: 'link'
8
+ };
9
+ // Maximum recursive nesting before the parser emits tags as literal text (DoS protection)
10
+ const MAX_NESTING_DEPTH = 32;
11
+ // Only these link targets are allowed — others are stripped to prevent iframe breakout
12
+ const ALLOWED_TARGETS = ['_blank', '_self'];
13
+ // Only these protocols pass href validation — all others are blocked
14
+ const ALLOWED_PROTOCOLS = ['https:', 'mailto:'];
15
+
16
+ exports.ALLOWED_PROTOCOLS = ALLOWED_PROTOCOLS;
17
+ exports.ALLOWED_TAGS = ALLOWED_TAGS;
18
+ exports.ALLOWED_TARGETS = ALLOWED_TARGETS;
19
+ exports.MAX_NESTING_DEPTH = MAX_NESTING_DEPTH;
20
+ exports.TAG_ALIASES = TAG_ALIASES;
21
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sources":["../../src/Markup/constants.ts"],"sourcesContent":["// Only these tags are recognised — anything else is treated as plain text (security allow-list)\nexport const ALLOWED_TAGS = [\n 'important',\n 'positive',\n 'negative',\n 'strong',\n 'strikethrough',\n 'paragraph',\n 'p',\n 'link',\n 'a',\n] as const;\n\nexport const TAG_ALIASES: Record<string, string> = { p: 'paragraph', a: 'link' };\n\n// Maximum recursive nesting before the parser emits tags as literal text (DoS protection)\nexport const MAX_NESTING_DEPTH = 32;\n\n// Only these link targets are allowed — others are stripped to prevent iframe breakout\nexport const ALLOWED_TARGETS = ['_blank', '_self'];\n\n// Only these protocols pass href validation — all others are blocked\nexport const ALLOWED_PROTOCOLS = ['https:', 'mailto:'];\n"],"names":["ALLOWED_TAGS","TAG_ALIASES","p","a","MAX_NESTING_DEPTH","ALLOWED_TARGETS","ALLOWED_PROTOCOLS"],"mappings":";;AAAA;AACO,MAAMA,YAAY,GAAG,CAC1B,WAAW,EACX,UAAU,EACV,UAAU,EACV,QAAQ,EACR,eAAe,EACf,WAAW,EACX,GAAG,EACH,MAAM,EACN,GAAG;AAGE,MAAMC,WAAW,GAA2B;AAAEC,EAAAA,CAAC,EAAE,WAAW;AAAEC,EAAAA,CAAC,EAAE;;AAExE;AACO,MAAMC,iBAAiB,GAAG;AAEjC;MACaC,eAAe,GAAG,CAAC,QAAQ,EAAE,OAAO;AAEjD;MACaC,iBAAiB,GAAG,CAAC,QAAQ,EAAE,SAAS;;;;;;;;"}
@@ -0,0 +1,15 @@
1
+ // Only these tags are recognised — anything else is treated as plain text (security allow-list)
2
+ const ALLOWED_TAGS = ['important', 'positive', 'negative', 'strong', 'strikethrough', 'paragraph', 'p', 'link', 'a'];
3
+ const TAG_ALIASES = {
4
+ p: 'paragraph',
5
+ a: 'link'
6
+ };
7
+ // Maximum recursive nesting before the parser emits tags as literal text (DoS protection)
8
+ const MAX_NESTING_DEPTH = 32;
9
+ // Only these link targets are allowed — others are stripped to prevent iframe breakout
10
+ const ALLOWED_TARGETS = ['_blank', '_self'];
11
+ // Only these protocols pass href validation — all others are blocked
12
+ const ALLOWED_PROTOCOLS = ['https:', 'mailto:'];
13
+
14
+ export { ALLOWED_PROTOCOLS, ALLOWED_TAGS, ALLOWED_TARGETS, MAX_NESTING_DEPTH, TAG_ALIASES };
15
+ //# sourceMappingURL=constants.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.mjs","sources":["../../src/Markup/constants.ts"],"sourcesContent":["// Only these tags are recognised — anything else is treated as plain text (security allow-list)\nexport const ALLOWED_TAGS = [\n 'important',\n 'positive',\n 'negative',\n 'strong',\n 'strikethrough',\n 'paragraph',\n 'p',\n 'link',\n 'a',\n] as const;\n\nexport const TAG_ALIASES: Record<string, string> = { p: 'paragraph', a: 'link' };\n\n// Maximum recursive nesting before the parser emits tags as literal text (DoS protection)\nexport const MAX_NESTING_DEPTH = 32;\n\n// Only these link targets are allowed — others are stripped to prevent iframe breakout\nexport const ALLOWED_TARGETS = ['_blank', '_self'];\n\n// Only these protocols pass href validation — all others are blocked\nexport const ALLOWED_PROTOCOLS = ['https:', 'mailto:'];\n"],"names":["ALLOWED_TAGS","TAG_ALIASES","p","a","MAX_NESTING_DEPTH","ALLOWED_TARGETS","ALLOWED_PROTOCOLS"],"mappings":"AAAA;AACO,MAAMA,YAAY,GAAG,CAC1B,WAAW,EACX,UAAU,EACV,UAAU,EACV,QAAQ,EACR,eAAe,EACf,WAAW,EACX,GAAG,EACH,MAAM,EACN,GAAG;AAGE,MAAMC,WAAW,GAA2B;AAAEC,EAAAA,CAAC,EAAE,WAAW;AAAEC,EAAAA,CAAC,EAAE;;AAExE;AACO,MAAMC,iBAAiB,GAAG;AAEjC;MACaC,eAAe,GAAG,CAAC,QAAQ,EAAE,OAAO;AAEjD;MACaC,iBAAiB,GAAG,CAAC,QAAQ,EAAE,SAAS;;;;"}
@@ -0,0 +1,263 @@
1
+ 'use strict';
2
+
3
+ var constants = require('../constants.js');
4
+
5
+ const MAX_INPUT_LENGTH = 10_000;
6
+ const MAX_ACCESSIBILITY_LABEL_LENGTH = 250;
7
+ const OBJECT_PROTOTYPE_KEYS = new Set(Object.getOwnPropertyNames(Object.prototype));
8
+ // eslint-disable-next-line regexp/no-control-character
9
+ const CONTROL_CHARS = /[\x00-\x1f\x7f-\x9f]/g;
10
+ const HTML_METACHAR = /[<>"']/g;
11
+ /**
12
+ * Matches opening and closing tags from the ALLOWED_TAGS allow-list.
13
+ *
14
+ * Capture groups:
15
+ * 1. `/` if this is a closing tag, undefined otherwise
16
+ * 2. Tag name
17
+ * 3. Raw attribute string between the tag name and `>` (empty for closing tags)
18
+ *
19
+ * The lookahead `(?=[\s>/])` after the tag name ensures we don't match partial
20
+ * words — e.g. `<stronger>` won't be matched as `<strong>`.
21
+ *
22
+ * Global flag (`g`) allows iterative matching via `exec()`.
23
+ */
24
+ const TAG_REGEX = new RegExp(`<(\\/)?(${constants.ALLOWED_TAGS.join('|')})(?=[\\s>/])((?:[^>"']*(?:"[^"]*"|'[^']*'))*[^>"']*)>`, 'g');
25
+ /**
26
+ * Splits the input string into a flat list of tokens by scanning for known tags.
27
+ * Text between tags is emitted as text/newline tokens. Unrecognised tags are never
28
+ * tokenised — they remain part of the surrounding text content.
29
+ */
30
+ function tokenise(input) {
31
+ const tokens = [];
32
+ let lastIndex = 0;
33
+ TAG_REGEX.lastIndex = 0;
34
+ let match = TAG_REGEX.exec(input);
35
+ while (match !== null) {
36
+ if (match.index > lastIndex) {
37
+ pushTextWithNewlines(tokens, input.slice(lastIndex, match.index));
38
+ }
39
+ const isClose = match[1] === '/';
40
+ const tag = match[2];
41
+ const attrs = match[3] || '';
42
+ if (isClose) {
43
+ tokens.push({
44
+ type: 'close',
45
+ tag
46
+ });
47
+ } else {
48
+ tokens.push({
49
+ type: 'open',
50
+ tag,
51
+ attrs
52
+ });
53
+ }
54
+ lastIndex = TAG_REGEX.lastIndex;
55
+ match = TAG_REGEX.exec(input);
56
+ }
57
+ if (lastIndex < input.length) {
58
+ pushTextWithNewlines(tokens, input.slice(lastIndex));
59
+ }
60
+ return tokens;
61
+ }
62
+ /** Splits a text fragment on newline characters, interleaving newline tokens between parts. */
63
+ function pushTextWithNewlines(tokens, text) {
64
+ const parts = text.split('\n');
65
+ for (let index = 0; index < parts.length; index += 1) {
66
+ if (index > 0) {
67
+ tokens.push({
68
+ type: 'newline'
69
+ });
70
+ }
71
+ if (parts[index]) {
72
+ tokens.push({
73
+ type: 'text',
74
+ content: parts[index]
75
+ });
76
+ }
77
+ }
78
+ }
79
+ /**
80
+ * Recursive descent parser that consumes tokens and builds a MarkupNode tree.
81
+ *
82
+ * When `untilTag` is provided, the function collects nodes until it finds a matching
83
+ * close token — returning `{ closed: true }`. If it exhausts all tokens without finding
84
+ * the close, it returns `{ closed: false }` so the caller can fall back to plain text
85
+ * (graceful degradation for malformed input).
86
+ *
87
+ * The shared `position` object acts as a cursor across recursive calls, avoiding the
88
+ * need to slice or copy the token array.
89
+ */
90
+ function parse(tokens, position, untilTag, depth = 0) {
91
+ const nodes = [];
92
+ while (position.index < tokens.length) {
93
+ const token = tokens[position.index];
94
+ if (token.type === 'text') {
95
+ nodes.push({
96
+ type: 'text',
97
+ content: token.content
98
+ });
99
+ position.index += 1;
100
+ } else if (token.type === 'newline') {
101
+ nodes.push({
102
+ type: 'newline'
103
+ });
104
+ position.index += 1;
105
+ } else if (token.type === 'close') {
106
+ if (token.tag === untilTag) {
107
+ position.index += 1;
108
+ return {
109
+ closed: true,
110
+ nodes
111
+ };
112
+ }
113
+ // Mismatched close tag — render as literal text
114
+ nodes.push({
115
+ type: 'text',
116
+ content: `</${token.tag}>`
117
+ });
118
+ position.index += 1;
119
+ } else if (token.type === 'open') {
120
+ if (depth >= constants.MAX_NESTING_DEPTH) {
121
+ nodes.push({
122
+ type: 'text',
123
+ content: `<${token.tag}${token.attrs}>`
124
+ });
125
+ position.index += 1;
126
+ } else {
127
+ position.index += 1;
128
+ const result = parse(tokens, position, token.tag, depth + 1);
129
+ if (result.closed) {
130
+ const node = buildNode(token.tag, token.attrs, result.nodes);
131
+ nodes.push(node);
132
+ } else {
133
+ nodes.push({
134
+ type: 'text',
135
+ content: `<${token.tag}${token.attrs}>`
136
+ });
137
+ nodes.push(...result.nodes);
138
+ }
139
+ }
140
+ }
141
+ }
142
+ if (untilTag) {
143
+ return {
144
+ closed: false,
145
+ nodes
146
+ };
147
+ }
148
+ return {
149
+ closed: true,
150
+ nodes
151
+ };
152
+ }
153
+ /**
154
+ * Maps a raw tag name to a typed MarkupNode. Resolves aliases first (p→paragraph, a→link),
155
+ * then builds the appropriate node shape. Link nodes carry full attributes; other element
156
+ * nodes extract only accessibilityLabel.
157
+ */
158
+ function buildNode(rawTag, attrs, children) {
159
+ const tag = constants.TAG_ALIASES[rawTag] || rawTag;
160
+ if (tag === 'link') {
161
+ return {
162
+ type: 'link',
163
+ children,
164
+ ...parseAttributes(attrs)
165
+ };
166
+ }
167
+ if (tag === 'paragraph') {
168
+ return {
169
+ type: 'paragraph',
170
+ children
171
+ };
172
+ }
173
+ const {
174
+ accessibilityLabel
175
+ } = parseAttributes(attrs);
176
+ return {
177
+ type: tag,
178
+ children,
179
+ ...(accessibilityLabel && {
180
+ accessibilityLabel
181
+ })
182
+ };
183
+ }
184
+ /**
185
+ * Matches allow-listed attributes from the raw attribute string captured by TAG_REGEX.
186
+ * Requires whitespace before each attribute name to prevent matching inside quoted values.
187
+ *
188
+ * Example: for input ` href="https://wise.com" target="_blank"`
189
+ * - Match 1: groups = ['href', 'https://wise.com', undefined]
190
+ * - Match 2: groups = ['target', '_blank', undefined]
191
+ *
192
+ * Capture groups:
193
+ * 1. Attribute name (href, action, target, or accessibilityLabel)
194
+ * 2. Double-quoted value (if present)
195
+ * 3. Single-quoted value (if present)
196
+ */
197
+ const ATTR_REGEX = /(?<=\s)(href|action|target|accessibilityLabel)=(?:"([^"]*)"|'([^']*)')/g;
198
+ /**
199
+ * Extracts allowed attributes from a raw attribute string.
200
+ * Supports both double- and single-quoted values. Any attribute not in the
201
+ * allow-list (href, action, target, accessibilityLabel) is silently discarded.
202
+ * First occurrence wins — duplicates are ignored.
203
+ */
204
+ function parseAttributes(attrs) {
205
+ const result = {};
206
+ ATTR_REGEX.lastIndex = 0;
207
+ let match = ATTR_REGEX.exec(attrs);
208
+ while (match !== null) {
209
+ const key = match[1];
210
+ const value = match[2] ?? match[3];
211
+ if (!(key in result)) {
212
+ const sanitized = sanitizeAttributeValue(key, value);
213
+ if (sanitized !== undefined) {
214
+ result[key] = sanitized;
215
+ }
216
+ }
217
+ match = ATTR_REGEX.exec(attrs);
218
+ }
219
+ return result;
220
+ }
221
+ function sanitizeAttributeValue(key, value) {
222
+ switch (key) {
223
+ case 'href':
224
+ return value.replace(CONTROL_CHARS, '');
225
+ case 'action':
226
+ if (OBJECT_PROTOTYPE_KEYS.has(value)) {
227
+ return undefined;
228
+ }
229
+ return value;
230
+ case 'target':
231
+ if (!constants.ALLOWED_TARGETS.includes(value)) {
232
+ return undefined;
233
+ }
234
+ return value;
235
+ case 'accessibilityLabel':
236
+ return value.replace(HTML_METACHAR, '').slice(0, MAX_ACCESSIBILITY_LABEL_LENGTH);
237
+ default:
238
+ return undefined;
239
+ }
240
+ }
241
+ /** Entry point: tokenises the input string, then parses the token stream into a MarkupNode tree. */
242
+ function parseMarkup(input) {
243
+ if (!input) {
244
+ return [];
245
+ }
246
+ if (input.length > MAX_INPUT_LENGTH) {
247
+ return [{
248
+ type: 'text',
249
+ content: input
250
+ }];
251
+ }
252
+ const tokens = tokenise(input);
253
+ const position = {
254
+ index: 0
255
+ };
256
+ return parse(tokens, position).nodes;
257
+ }
258
+
259
+ exports.MAX_NESTING_DEPTH = constants.MAX_NESTING_DEPTH;
260
+ exports.MAX_ACCESSIBILITY_LABEL_LENGTH = MAX_ACCESSIBILITY_LABEL_LENGTH;
261
+ exports.MAX_INPUT_LENGTH = MAX_INPUT_LENGTH;
262
+ exports.parseMarkup = parseMarkup;
263
+ //# sourceMappingURL=parseMarkup.js.map