@transferwise/components 0.0.0-experimental-fa3aa98 → 0.0.0-experimental-f4a328f

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 (201) hide show
  1. package/build/Calendar/Calendar.js +16 -94
  2. package/build/Calendar/Calendar.js.map +1 -1
  3. package/build/Calendar/Calendar.messages.js +0 -12
  4. package/build/Calendar/Calendar.messages.js.map +1 -1
  5. package/build/Calendar/Calendar.messages.mjs +0 -12
  6. package/build/Calendar/Calendar.messages.mjs.map +1 -1
  7. package/build/Calendar/Calendar.mjs +17 -95
  8. package/build/Calendar/Calendar.mjs.map +1 -1
  9. package/build/Calendar/DateHeader/DateHeader.js +1 -5
  10. package/build/Calendar/DateHeader/DateHeader.js.map +1 -1
  11. package/build/Calendar/DateHeader/DateHeader.mjs +1 -5
  12. package/build/Calendar/DateHeader/DateHeader.mjs.map +1 -1
  13. package/build/Calendar/DayCalendar/DayCalendar.js +0 -14
  14. package/build/Calendar/DayCalendar/DayCalendar.js.map +1 -1
  15. package/build/Calendar/DayCalendar/DayCalendar.mjs +0 -14
  16. package/build/Calendar/DayCalendar/DayCalendar.mjs.map +1 -1
  17. package/build/Calendar/DayCalendar/Table/DayCalendarTable.js +19 -53
  18. package/build/Calendar/DayCalendar/Table/DayCalendarTable.js.map +1 -1
  19. package/build/Calendar/DayCalendar/Table/DayCalendarTable.mjs +19 -53
  20. package/build/Calendar/DayCalendar/Table/DayCalendarTable.mjs.map +1 -1
  21. package/build/Calendar/MonthCalendar/MonthCalendar.js +0 -6
  22. package/build/Calendar/MonthCalendar/MonthCalendar.js.map +1 -1
  23. package/build/Calendar/MonthCalendar/MonthCalendar.mjs +0 -6
  24. package/build/Calendar/MonthCalendar/MonthCalendar.mjs.map +1 -1
  25. package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.js +3 -8
  26. package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.js.map +1 -1
  27. package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.mjs +3 -8
  28. package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.mjs.map +1 -1
  29. package/build/Calendar/YearCalendar/Table/YearCalendarTable.js +3 -8
  30. package/build/Calendar/YearCalendar/Table/YearCalendarTable.js.map +1 -1
  31. package/build/Calendar/YearCalendar/Table/YearCalendarTable.mjs +3 -8
  32. package/build/Calendar/YearCalendar/Table/YearCalendarTable.mjs.map +1 -1
  33. package/build/Calendar/YearCalendar/YearCalendar.js +0 -7
  34. package/build/Calendar/YearCalendar/YearCalendar.js.map +1 -1
  35. package/build/Calendar/YearCalendar/YearCalendar.mjs +0 -7
  36. package/build/Calendar/YearCalendar/YearCalendar.mjs.map +1 -1
  37. package/build/Calendar/{TableLink → tableLink}/TableLink.js +11 -26
  38. package/build/Calendar/tableLink/TableLink.js.map +1 -0
  39. package/build/Calendar/{TableLink → tableLink}/TableLink.mjs +11 -26
  40. package/build/Calendar/tableLink/TableLink.mjs.map +1 -0
  41. package/build/DateLookup/DateLookup.js +9 -20
  42. package/build/DateLookup/DateLookup.js.map +1 -1
  43. package/build/DateLookup/DateLookup.mjs +9 -20
  44. package/build/DateLookup/DateLookup.mjs.map +1 -1
  45. package/build/Markup/Markup.js +137 -0
  46. package/build/Markup/Markup.js.map +1 -0
  47. package/build/Markup/Markup.mjs +132 -0
  48. package/build/Markup/Markup.mjs.map +1 -0
  49. package/build/Markup/constants.js +36 -0
  50. package/build/Markup/constants.js.map +1 -0
  51. package/build/Markup/constants.mjs +29 -0
  52. package/build/Markup/constants.mjs.map +1 -0
  53. package/build/Markup/utils/parseMarkup.js +236 -0
  54. package/build/Markup/utils/parseMarkup.js.map +1 -0
  55. package/build/Markup/utils/parseMarkup.mjs +231 -0
  56. package/build/Markup/utils/parseMarkup.mjs.map +1 -0
  57. package/build/Markup/utils/sanitise.js +114 -0
  58. package/build/Markup/utils/sanitise.js.map +1 -0
  59. package/build/Markup/utils/sanitise.mjs +111 -0
  60. package/build/Markup/utils/sanitise.mjs.map +1 -0
  61. package/build/i18n/en.json +0 -4
  62. package/build/i18n/en.json.js +0 -4
  63. package/build/i18n/en.json.js.map +1 -1
  64. package/build/i18n/en.json.mjs +0 -4
  65. package/build/i18n/en.json.mjs.map +1 -1
  66. package/build/index.js +4 -2
  67. package/build/index.js.map +1 -1
  68. package/build/index.mjs +2 -1
  69. package/build/index.mjs.map +1 -1
  70. package/build/main.css +78 -123
  71. package/build/styles/Calendar/Calendar.css +37 -112
  72. package/build/styles/Markup/Markup.css +28 -0
  73. package/build/styles/Markup/_stories/Vulnerability/Vulnerability.css +69 -0
  74. package/build/styles/main.css +78 -123
  75. package/build/types/Body/Body.d.ts +2 -2
  76. package/build/types/Calendar/Calendar.d.ts +3 -16
  77. package/build/types/Calendar/Calendar.d.ts.map +1 -1
  78. package/build/types/Calendar/Calendar.messages.d.ts +0 -20
  79. package/build/types/Calendar/Calendar.messages.d.ts.map +1 -1
  80. package/build/types/Calendar/DateHeader/DateHeader.d.ts +0 -2
  81. package/build/types/Calendar/DateHeader/DateHeader.d.ts.map +1 -1
  82. package/build/types/Calendar/DayCalendar/DayCalendar.d.ts +1 -5
  83. package/build/types/Calendar/DayCalendar/DayCalendar.d.ts.map +1 -1
  84. package/build/types/Calendar/DayCalendar/Table/DayCalendarTable.d.ts +0 -4
  85. package/build/types/Calendar/DayCalendar/Table/DayCalendarTable.d.ts.map +1 -1
  86. package/build/types/Calendar/MonthCalendar/MonthCalendar.d.ts +0 -1
  87. package/build/types/Calendar/MonthCalendar/MonthCalendar.d.ts.map +1 -1
  88. package/build/types/Calendar/MonthCalendar/Table/MonthCalendarTable.d.ts +1 -2
  89. package/build/types/Calendar/MonthCalendar/Table/MonthCalendarTable.d.ts.map +1 -1
  90. package/build/types/Calendar/YearCalendar/Table/YearCalendarTable.d.ts +1 -2
  91. package/build/types/Calendar/YearCalendar/Table/YearCalendarTable.d.ts.map +1 -1
  92. package/build/types/Calendar/YearCalendar/YearCalendar.d.ts +0 -1
  93. package/build/types/Calendar/YearCalendar/YearCalendar.d.ts.map +1 -1
  94. package/build/types/Calendar/index.d.ts +0 -1
  95. package/build/types/Calendar/index.d.ts.map +1 -1
  96. package/build/types/Calendar/{TableLink → tableLink}/TableLink.d.ts +1 -3
  97. package/build/types/Calendar/tableLink/TableLink.d.ts.map +1 -0
  98. package/build/types/Calendar/tableLink/index.d.ts.map +1 -0
  99. package/build/types/DateLookup/DateLookup.d.ts +5 -24
  100. package/build/types/DateLookup/DateLookup.d.ts.map +1 -1
  101. package/build/types/DateLookup/index.d.ts +0 -1
  102. package/build/types/DateLookup/index.d.ts.map +1 -1
  103. package/build/types/IconButton/IconButton.d.ts +1 -1
  104. package/build/types/Markup/Markup.d.ts +18 -0
  105. package/build/types/Markup/Markup.d.ts.map +1 -0
  106. package/build/types/Markup/Markup.types.d.ts +77 -0
  107. package/build/types/Markup/Markup.types.d.ts.map +1 -0
  108. package/build/types/Markup/_stories/Vulnerability/Vulnerability.d.ts +12 -0
  109. package/build/types/Markup/_stories/Vulnerability/Vulnerability.d.ts.map +1 -0
  110. package/build/types/Markup/constants.d.ts +20 -0
  111. package/build/types/Markup/constants.d.ts.map +1 -0
  112. package/build/types/Markup/index.d.ts +3 -0
  113. package/build/types/Markup/index.d.ts.map +1 -0
  114. package/build/types/Markup/utils/parseMarkup.d.ts +8 -0
  115. package/build/types/Markup/utils/parseMarkup.d.ts.map +1 -0
  116. package/build/types/Markup/utils/sanitise.d.ts +4 -0
  117. package/build/types/Markup/utils/sanitise.d.ts.map +1 -0
  118. package/build/types/Title/Title.d.ts +2 -2
  119. package/build/types/Upload/Steps/UploadImageStep/UploadImageStep.d.ts +1 -1
  120. package/build/types/UploadInput/UploadItem/UploadItemLink.d.ts +1 -1
  121. package/build/types/common/DateUtils/index.d.ts +0 -2
  122. package/build/types/common/DateUtils/index.d.ts.map +1 -1
  123. package/build/types/index.d.ts +4 -3
  124. package/build/types/index.d.ts.map +1 -1
  125. package/build/types/test-utils/index.d.ts +0 -8
  126. package/build/types/test-utils/index.d.ts.map +1 -1
  127. package/package.json +1 -1
  128. package/src/Calendar/Calendar.css +37 -112
  129. package/src/Calendar/Calendar.less +35 -5
  130. package/src/Calendar/Calendar.messages.ts +0 -21
  131. package/src/Calendar/Calendar.test.tsx +27 -288
  132. package/src/Calendar/Calendar.tsx +19 -136
  133. package/src/Calendar/DateHeader/DateHeader.tsx +0 -6
  134. package/src/Calendar/DayCalendar/DayCalendar.tsx +1 -33
  135. package/src/Calendar/DayCalendar/Table/DayCalendarTable.tsx +28 -62
  136. package/src/Calendar/MonthCalendar/MonthCalendar.tsx +0 -8
  137. package/src/Calendar/MonthCalendar/Table/MonthCalendarTable.tsx +3 -15
  138. package/src/Calendar/YearCalendar/Table/YearCalendarTable.tsx +3 -15
  139. package/src/Calendar/YearCalendar/YearCalendar.tsx +0 -9
  140. package/src/Calendar/_stories/Calendar.story.tsx +4 -138
  141. package/src/Calendar/index.ts +0 -7
  142. package/src/Calendar/{TableLink → tableLink}/TableLink.tsx +14 -29
  143. package/src/DateLookup/DateLookup.test.tsx +37 -34
  144. package/src/DateLookup/DateLookup.tsx +13 -37
  145. package/src/DateLookup/_stories/DateLookup.story.tsx +2 -124
  146. package/src/DateLookup/index.ts +0 -6
  147. package/src/Markup/Markup.css +28 -0
  148. package/src/Markup/Markup.injection.test.tsx +163 -0
  149. package/src/Markup/Markup.less +29 -0
  150. package/src/Markup/Markup.test.tsx +463 -0
  151. package/src/Markup/Markup.tsx +169 -0
  152. package/src/Markup/Markup.types.ts +62 -0
  153. package/src/Markup/_stories/Markup.docs.mdx +75 -0
  154. package/src/Markup/_stories/Markup.security.docs.mdx +343 -0
  155. package/src/Markup/_stories/Markup.story.tsx +266 -0
  156. package/src/Markup/_stories/Vulnerability/Vulnerability.css +69 -0
  157. package/src/Markup/_stories/Vulnerability/Vulnerability.tsx +30 -0
  158. package/src/Markup/constants.ts +41 -0
  159. package/src/Markup/index.ts +2 -0
  160. package/src/Markup/utils/parseMarkup.test.ts +706 -0
  161. package/src/Markup/utils/parseMarkup.ts +234 -0
  162. package/src/Markup/utils/sanitise.test.ts +497 -0
  163. package/src/Markup/utils/sanitise.ts +133 -0
  164. package/src/common/DateUtils/index.ts +0 -2
  165. package/src/i18n/en.json +0 -4
  166. package/src/index.ts +4 -3
  167. package/src/main.css +78 -123
  168. package/src/main.less +1 -0
  169. package/build/Calendar/TableLink/TableLink.js.map +0 -1
  170. package/build/Calendar/TableLink/TableLink.mjs.map +0 -1
  171. package/build/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.js +0 -33
  172. package/build/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.js.map +0 -1
  173. package/build/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.mjs +0 -31
  174. package/build/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.mjs.map +0 -1
  175. package/build/common/DateUtils/isDateDisabled/isDateDisabled.js +0 -40
  176. package/build/common/DateUtils/isDateDisabled/isDateDisabled.js.map +0 -1
  177. package/build/common/DateUtils/isDateDisabled/isDateDisabled.mjs +0 -38
  178. package/build/common/DateUtils/isDateDisabled/isDateDisabled.mjs.map +0 -1
  179. package/build/styles/Calendar/TableLink/TableLink.css +0 -115
  180. package/build/types/Calendar/Calendar.types.d.ts +0 -32
  181. package/build/types/Calendar/Calendar.types.d.ts.map +0 -1
  182. package/build/types/Calendar/TableLink/TableLink.d.ts.map +0 -1
  183. package/build/types/Calendar/TableLink/index.d.ts.map +0 -1
  184. package/build/types/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.d.ts +0 -3
  185. package/build/types/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.d.ts.map +0 -1
  186. package/build/types/common/DateUtils/isDateDisabled/isDateDisabled.d.ts +0 -3
  187. package/build/types/common/DateUtils/isDateDisabled/isDateDisabled.d.ts.map +0 -1
  188. package/src/Calendar/Calendar.disabledDates.test.tsx +0 -518
  189. package/src/Calendar/Calendar.types.ts +0 -35
  190. package/src/Calendar/TableLink/TableLink.css +0 -115
  191. package/src/Calendar/TableLink/TableLink.less +0 -68
  192. package/src/Calendar/_stories/Calendar.accessibility.docs.mdx +0 -118
  193. package/src/Calendar/_stories/Calendar.test.story.tsx +0 -74
  194. package/src/DateLookup/DateLookup.disabledDates.test.tsx +0 -293
  195. package/src/DateLookup/_stories/DateLookup.accessibility.docs.mdx +0 -108
  196. package/src/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.test.ts +0 -98
  197. package/src/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.ts +0 -45
  198. package/src/common/DateUtils/isDateDisabled/isDateDisabled.test.ts +0 -169
  199. package/src/common/DateUtils/isDateDisabled/isDateDisabled.ts +0 -59
  200. /package/build/types/Calendar/{TableLink → tableLink}/index.d.ts +0 -0
  201. /package/src/Calendar/{TableLink → tableLink}/index.ts +0 -0
@@ -0,0 +1,137 @@
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
+ if (node.href && sanitise.isAllowedHref(node.href) && sanitise.isHrefAllowedByMode(node.href, allowLinks)) {
32
+ return /*#__PURE__*/jsxRuntime.jsx(Link.default, {
33
+ href: node.href,
34
+ target: node.target,
35
+ "aria-label": node.accessibilityLabel,
36
+ children: children
37
+ }, key);
38
+ }
39
+ return /*#__PURE__*/jsxRuntime.jsx(React.Fragment, {
40
+ children: children
41
+ }, key);
42
+ }
43
+ function renderNode(node, actions, data, allowLinks, key) {
44
+ switch (node.type) {
45
+ case 'text':
46
+ return /*#__PURE__*/jsxRuntime.jsx(React.Fragment, {
47
+ children: data ? substituteData(node.content, data) : node.content
48
+ }, key);
49
+ case 'newline':
50
+ return /*#__PURE__*/jsxRuntime.jsx("br", {}, key);
51
+ case 'important':
52
+ case 'positive':
53
+ case 'negative':
54
+ return /*#__PURE__*/jsxRuntime.jsx("em", {
55
+ className: `wds-markup-emphasis wds-markup-emphasis--${node.type}`,
56
+ "aria-label": node.accessibilityLabel,
57
+ children: renderNodes(node.children, actions, data, allowLinks)
58
+ }, key);
59
+ case 'strong':
60
+ return /*#__PURE__*/jsxRuntime.jsx("strong", {
61
+ className: "wds-markup-strong",
62
+ "aria-label": node.accessibilityLabel,
63
+ children: renderNodes(node.children, actions, data, allowLinks)
64
+ }, key);
65
+ case 'strikethrough':
66
+ return /*#__PURE__*/jsxRuntime.jsx("del", {
67
+ className: "wds-markup-strikethrough",
68
+ "aria-label": node.accessibilityLabel,
69
+ children: renderNodes(node.children, actions, data, allowLinks)
70
+ }, key);
71
+ case 'paragraph':
72
+ return /*#__PURE__*/jsxRuntime.jsx("p", {
73
+ className: "wds-markup-paragraph",
74
+ children: renderNodes(node.children, actions, data, allowLinks)
75
+ }, key);
76
+ case 'link':
77
+ return renderLinkNode(node, actions, data, allowLinks, key);
78
+ }
79
+ }
80
+ function hasParagraph(nodes) {
81
+ for (const node of nodes) {
82
+ if (node.type === 'paragraph') {
83
+ return true;
84
+ }
85
+ if ('children' in node && hasParagraph(node.children)) {
86
+ return true;
87
+ }
88
+ }
89
+ return false;
90
+ }
91
+ /**
92
+ * Parses a markup string and renders it as React elements. Supports `<important>`,
93
+ * `<positive>`, `<negative>`, `<strong>`, `<strikethrough>`, `<paragraph>` (alias `<p>`),
94
+ * and `<link>` (alias `<a>`) with secure href validation.
95
+ *
96
+ * It only processes `string` input, while `ReactNode` is passed-through without processing.
97
+ *
98
+ * > The component supersedes [Emphasis](?path=/docs/typography-emphasis--docs), which will be
99
+ * eventually deprecated.
100
+ *
101
+ * @see http://storybook.wise.design/?path=/docs/typography-markup--docs
102
+ * @link ../emphasis/Emphasis | Emphasis
103
+ */
104
+ const Markup = ({
105
+ children,
106
+ data,
107
+ allowLinks = 'internal',
108
+ actions,
109
+ as,
110
+ className,
111
+ 'data-testid': testId
112
+ }) => {
113
+ const tree = React.useMemo(() => typeof children === 'string' ? parseMarkup.parseMarkup(children) : [], [children]);
114
+ if (typeof children !== 'string') {
115
+ if (children == null) {
116
+ return null;
117
+ }
118
+ return /*#__PURE__*/jsxRuntime.jsx("span", {
119
+ className: className,
120
+ "data-testid": testId,
121
+ children: children
122
+ });
123
+ }
124
+ if (tree.length === 0) {
125
+ return null;
126
+ }
127
+ const Element = as ?? (hasParagraph(tree) ? 'div' : 'span');
128
+ return /*#__PURE__*/jsxRuntime.jsx(Element, {
129
+ className: className,
130
+ "data-testid": testId,
131
+ children: renderNodes(tree, actions, data, allowLinks)
132
+ });
133
+ };
134
+
135
+ exports.Markup = Markup;
136
+ exports.default = Markup;
137
+ //# 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, isAllowedHref, isHrefAllowedByMode } 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 if (node.href && isAllowedHref(node.href) && isHrefAllowedByMode(node.href, allowLinks)) {\n return (\n <Link key={key} href={node.href} target={node.target} aria-label={node.accessibilityLabel}>\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","href","isAllowedHref","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,OAAO,EAAEX,IAAI,EAAEY,UAAU,CAAC;EAEtE,IAAIE,IAAI,CAACK,MAAM,IAAIR,OAAO,GAAGG,IAAI,CAACK,MAAM,CAAC,EAAE;AACzC,IAAA;AAAA;AACE;AACAC,MAAAA,cAAA,CAACC,YAAI,EAAA;QAAW,YAAA,EAAYP,IAAI,CAACQ,kBAAmB;AAACC,QAAAA,OAAO,EAAEZ,OAAO,CAACG,IAAI,CAACK,MAAM,CAAE;AAAAD,QAAAA,QAAA,EAChFA;AAAQ,OAAA,EADAf,GA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AAA,OAAO,IAAI;AACb,IAAA;AACF,EAAA;AACA,EAAA,OAAO,KAAK;AACd;AAEA;;;;;;;;;;;;AAYG;AACI,MAAMe,MAAM,GAA0BA,CAAC;EAC5Cf,QAAQ;EACRlB,IAAI;AACJY,EAAAA,UAAU,GAAG,UAAU;EACvBD,OAAO;EACPuB,EAAE;EACFH,SAAS;AACT,EAAA,aAAa,EAAEI;AAAM,CACtB,KAAI;EACH,MAAMC,IAAI,GAAGC,aAAO,CAClB,MAAO,OAAOnB,QAAQ,KAAK,QAAQ,GAAGoB,uBAAW,CAACpB,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;AAAMW,MAAAA,SAAS,EAAEA,SAAU;AAAC,MAAA,aAAA,EAAaI,MAAO;AAAAjB,MAAAA,QAAA,EAC7CA;AAAQ,KACL,CAAC;AAEX,EAAA;AAEA,EAAA,IAAIkB,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,oBACEhB,cAAA,CAACoB,OAAO,EAAA;AAACT,IAAAA,SAAS,EAAEA,SAAU;AAAC,IAAA,aAAA,EAAaI,MAAO;IAAAjB,QAAA,EAChDT,WAAW,CAAC2B,IAAI,EAAEzB,OAAO,EAAEX,IAAI,EAAEY,UAAU;AAAC,GACtC,CAAC;AAEd;;;;;"}
@@ -0,0 +1,132 @@
1
+ import { useMemo, Fragment } from 'react';
2
+ import Link from '../Link/Link.mjs';
3
+ import { parseMarkup } from './utils/parseMarkup.mjs';
4
+ import { isAllowedHref, 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
+ if (node.href && isAllowedHref(node.href) && isHrefAllowedByMode(node.href, allowLinks)) {
28
+ return /*#__PURE__*/jsx(Link, {
29
+ href: node.href,
30
+ target: node.target,
31
+ "aria-label": node.accessibilityLabel,
32
+ children: children
33
+ }, key);
34
+ }
35
+ return /*#__PURE__*/jsx(Fragment, {
36
+ children: children
37
+ }, key);
38
+ }
39
+ function renderNode(node, actions, data, allowLinks, key) {
40
+ switch (node.type) {
41
+ case 'text':
42
+ return /*#__PURE__*/jsx(Fragment, {
43
+ children: data ? substituteData(node.content, data) : node.content
44
+ }, key);
45
+ case 'newline':
46
+ return /*#__PURE__*/jsx("br", {}, key);
47
+ case 'important':
48
+ case 'positive':
49
+ case 'negative':
50
+ return /*#__PURE__*/jsx("em", {
51
+ className: `wds-markup-emphasis wds-markup-emphasis--${node.type}`,
52
+ "aria-label": node.accessibilityLabel,
53
+ children: renderNodes(node.children, actions, data, allowLinks)
54
+ }, key);
55
+ case 'strong':
56
+ return /*#__PURE__*/jsx("strong", {
57
+ className: "wds-markup-strong",
58
+ "aria-label": node.accessibilityLabel,
59
+ children: renderNodes(node.children, actions, data, allowLinks)
60
+ }, key);
61
+ case 'strikethrough':
62
+ return /*#__PURE__*/jsx("del", {
63
+ className: "wds-markup-strikethrough",
64
+ "aria-label": node.accessibilityLabel,
65
+ children: renderNodes(node.children, actions, data, allowLinks)
66
+ }, key);
67
+ case 'paragraph':
68
+ return /*#__PURE__*/jsx("p", {
69
+ className: "wds-markup-paragraph",
70
+ children: renderNodes(node.children, actions, data, allowLinks)
71
+ }, key);
72
+ case 'link':
73
+ return renderLinkNode(node, actions, data, allowLinks, key);
74
+ }
75
+ }
76
+ function hasParagraph(nodes) {
77
+ for (const node of nodes) {
78
+ if (node.type === 'paragraph') {
79
+ return true;
80
+ }
81
+ if ('children' in node && hasParagraph(node.children)) {
82
+ return true;
83
+ }
84
+ }
85
+ return false;
86
+ }
87
+ /**
88
+ * Parses a markup string and renders it as React elements. Supports `<important>`,
89
+ * `<positive>`, `<negative>`, `<strong>`, `<strikethrough>`, `<paragraph>` (alias `<p>`),
90
+ * and `<link>` (alias `<a>`) with secure href validation.
91
+ *
92
+ * It only processes `string` input, while `ReactNode` is passed-through without processing.
93
+ *
94
+ * > The component supersedes [Emphasis](?path=/docs/typography-emphasis--docs), which will be
95
+ * eventually deprecated.
96
+ *
97
+ * @see http://storybook.wise.design/?path=/docs/typography-markup--docs
98
+ * @link ../emphasis/Emphasis | Emphasis
99
+ */
100
+ const Markup = ({
101
+ children,
102
+ data,
103
+ allowLinks = 'internal',
104
+ actions,
105
+ as,
106
+ className,
107
+ 'data-testid': testId
108
+ }) => {
109
+ const tree = useMemo(() => typeof children === 'string' ? parseMarkup(children) : [], [children]);
110
+ if (typeof children !== 'string') {
111
+ if (children == null) {
112
+ return null;
113
+ }
114
+ return /*#__PURE__*/jsx("span", {
115
+ className: className,
116
+ "data-testid": testId,
117
+ children: children
118
+ });
119
+ }
120
+ if (tree.length === 0) {
121
+ return null;
122
+ }
123
+ const Element = as ?? (hasParagraph(tree) ? 'div' : 'span');
124
+ return /*#__PURE__*/jsx(Element, {
125
+ className: className,
126
+ "data-testid": testId,
127
+ children: renderNodes(tree, actions, data, allowLinks)
128
+ });
129
+ };
130
+
131
+ export { Markup, Markup as default };
132
+ //# 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, isAllowedHref, isHrefAllowedByMode } 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 if (node.href && isAllowedHref(node.href) && isHrefAllowedByMode(node.href, allowLinks)) {\n return (\n <Link key={key} href={node.href} target={node.target} aria-label={node.accessibilityLabel}>\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","href","isAllowedHref","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,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G,KAAK,GAAG,MAAM,CAAC;EAE3D,oBACEhB,GAAA,CAACoB,OAAO,EAAA;AAACT,IAAAA,SAAS,EAAEA,SAAU;AAAC,IAAA,aAAA,EAAaI,MAAO;IAAAjB,QAAA,EAChDT,WAAW,CAAC2B,IAAI,EAAEzB,OAAO,EAAEX,IAAI,EAAEY,UAAU;AAAC,GACtC,CAAC;AAEd;;;;"}
@@ -0,0 +1,36 @@
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
+ /**
6
+ * Matches opening and closing tags from the ALLOWED_TAGS allow-list.
7
+ *
8
+ * Capture groups:
9
+ * 1. `/` if this is a closing tag, undefined otherwise
10
+ * 2. Tag name
11
+ * 3. Raw attribute string between the tag name and `>` (empty for closing tags)
12
+ *
13
+ * The lookahead `(?=[\s>/])` after the tag name ensures we don't match partial
14
+ * words — e.g. `<stronger>` won't be matched as `<strong>`.
15
+ *
16
+ * Global flag (`g`) allows iterative matching via `exec()`.
17
+ */
18
+ const TAG_REGEX = new RegExp(`<(\\/)?(${ALLOWED_TAGS.join('|')})(?=[\\s>/])((?:[^>"']*(?:"[^"]*"|'[^']*'))*[^>"']*)>`, 'g');
19
+ const TAG_ALIASES = {
20
+ p: 'paragraph',
21
+ a: 'link'
22
+ };
23
+ // Maximum recursive nesting before the parser emits tags as literal text (DoS protection)
24
+ const MAX_NESTING_DEPTH = 32;
25
+ // Only these link targets are allowed — others are stripped to prevent iframe breakout
26
+ const ALLOWED_TARGETS = ['_blank', '_self'];
27
+ // Only these protocols pass href validation — all others are blocked
28
+ const ALLOWED_PROTOCOLS = ['https:', 'mailto:'];
29
+
30
+ exports.ALLOWED_PROTOCOLS = ALLOWED_PROTOCOLS;
31
+ exports.ALLOWED_TAGS = ALLOWED_TAGS;
32
+ exports.ALLOWED_TARGETS = ALLOWED_TARGETS;
33
+ exports.MAX_NESTING_DEPTH = MAX_NESTING_DEPTH;
34
+ exports.TAG_ALIASES = TAG_ALIASES;
35
+ exports.TAG_REGEX = TAG_REGEX;
36
+ //# 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\n/**\n * Matches opening and closing tags from the ALLOWED_TAGS allow-list.\n *\n * Capture groups:\n * 1. `/` if this is a closing tag, undefined otherwise\n * 2. Tag name\n * 3. Raw attribute string between the tag name and `>` (empty for closing tags)\n *\n * The lookahead `(?=[\\s>/])` after the tag name ensures we don't match partial\n * words — e.g. `<stronger>` won't be matched as `<strong>`.\n *\n * Global flag (`g`) allows iterative matching via `exec()`.\n */\nexport const TAG_REGEX = new RegExp(\n `<(\\\\/)?(${ALLOWED_TAGS.join('|')})(?=[\\\\s>/])((?:[^>\"']*(?:\"[^\"]*\"|'[^']*'))*[^>\"']*)>`,\n 'g',\n);\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_REGEX","RegExp","join","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;AAGL;;;;;;;;;;;;AAYG;MACUC,SAAS,GAAG,IAAIC,MAAM,CACjC,CAAA,QAAA,EAAWF,YAAY,CAACG,IAAI,CAAC,GAAG,CAAC,CAAA,qDAAA,CAAuD,EACxF,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,29 @@
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
+ /**
4
+ * Matches opening and closing tags from the ALLOWED_TAGS allow-list.
5
+ *
6
+ * Capture groups:
7
+ * 1. `/` if this is a closing tag, undefined otherwise
8
+ * 2. Tag name
9
+ * 3. Raw attribute string between the tag name and `>` (empty for closing tags)
10
+ *
11
+ * The lookahead `(?=[\s>/])` after the tag name ensures we don't match partial
12
+ * words — e.g. `<stronger>` won't be matched as `<strong>`.
13
+ *
14
+ * Global flag (`g`) allows iterative matching via `exec()`.
15
+ */
16
+ const TAG_REGEX = new RegExp(`<(\\/)?(${ALLOWED_TAGS.join('|')})(?=[\\s>/])((?:[^>"']*(?:"[^"]*"|'[^']*'))*[^>"']*)>`, 'g');
17
+ const TAG_ALIASES = {
18
+ p: 'paragraph',
19
+ a: 'link'
20
+ };
21
+ // Maximum recursive nesting before the parser emits tags as literal text (DoS protection)
22
+ const MAX_NESTING_DEPTH = 32;
23
+ // Only these link targets are allowed — others are stripped to prevent iframe breakout
24
+ const ALLOWED_TARGETS = ['_blank', '_self'];
25
+ // Only these protocols pass href validation — all others are blocked
26
+ const ALLOWED_PROTOCOLS = ['https:', 'mailto:'];
27
+
28
+ export { ALLOWED_PROTOCOLS, ALLOWED_TAGS, ALLOWED_TARGETS, MAX_NESTING_DEPTH, TAG_ALIASES, TAG_REGEX };
29
+ //# 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\n/**\n * Matches opening and closing tags from the ALLOWED_TAGS allow-list.\n *\n * Capture groups:\n * 1. `/` if this is a closing tag, undefined otherwise\n * 2. Tag name\n * 3. Raw attribute string between the tag name and `>` (empty for closing tags)\n *\n * The lookahead `(?=[\\s>/])` after the tag name ensures we don't match partial\n * words — e.g. `<stronger>` won't be matched as `<strong>`.\n *\n * Global flag (`g`) allows iterative matching via `exec()`.\n */\nexport const TAG_REGEX = new RegExp(\n `<(\\\\/)?(${ALLOWED_TAGS.join('|')})(?=[\\\\s>/])((?:[^>\"']*(?:\"[^\"]*\"|'[^']*'))*[^>\"']*)>`,\n 'g',\n);\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_REGEX","RegExp","join","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;AAGL;;;;;;;;;;;;AAYG;MACUC,SAAS,GAAG,IAAIC,MAAM,CACjC,CAAA,QAAA,EAAWF,YAAY,CAACG,IAAI,CAAC,GAAG,CAAC,CAAA,qDAAA,CAAuD,EACxF,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,236 @@
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
+ * Splits the input string into a flat list of tokens by scanning for known tags.
13
+ * Text between tags is emitted as text/newline tokens. Unrecognised tags are never
14
+ * tokenised — they remain part of the surrounding text content.
15
+ */
16
+ function tokenise(input) {
17
+ const tokens = [];
18
+ let lastIndex = 0;
19
+ constants.TAG_REGEX.lastIndex = 0;
20
+ let match = constants.TAG_REGEX.exec(input);
21
+ while (match !== null) {
22
+ if (match.index > lastIndex) {
23
+ pushTextWithNewlines(tokens, input.slice(lastIndex, match.index));
24
+ }
25
+ const isClose = match[1] === '/';
26
+ const tag = match[2];
27
+ const attrs = match[3] || '';
28
+ if (isClose) {
29
+ tokens.push({
30
+ type: 'close',
31
+ tag
32
+ });
33
+ } else {
34
+ tokens.push({
35
+ type: 'open',
36
+ tag,
37
+ attrs
38
+ });
39
+ }
40
+ lastIndex = constants.TAG_REGEX.lastIndex;
41
+ match = constants.TAG_REGEX.exec(input);
42
+ }
43
+ if (lastIndex < input.length) {
44
+ pushTextWithNewlines(tokens, input.slice(lastIndex));
45
+ }
46
+ return tokens;
47
+ }
48
+ /** Splits a text fragment on newline characters, interleaving newline tokens between parts. */
49
+ function pushTextWithNewlines(tokens, text) {
50
+ const parts = text.split('\n');
51
+ for (let index = 0; index < parts.length; index += 1) {
52
+ if (index > 0) {
53
+ tokens.push({
54
+ type: 'newline'
55
+ });
56
+ }
57
+ if (parts[index]) {
58
+ tokens.push({
59
+ type: 'text',
60
+ content: parts[index]
61
+ });
62
+ }
63
+ }
64
+ }
65
+ /**
66
+ * Recursive descent parser that consumes tokens and builds a MarkupNode tree.
67
+ *
68
+ * When `untilTag` is provided, the function collects nodes until it finds a matching
69
+ * close token — returning `{ closed: true }`. If it exhausts all tokens without finding
70
+ * the close, it returns `{ closed: false }` so the caller can fall back to plain text
71
+ * (graceful degradation for malformed input).
72
+ *
73
+ * The shared `position` object acts as a cursor across recursive calls, avoiding the
74
+ * need to slice or copy the token array.
75
+ */
76
+ function parse(tokens, position, untilTag, depth = 0) {
77
+ const nodes = [];
78
+ while (position.index < tokens.length) {
79
+ const token = tokens[position.index];
80
+ if (token.type === 'text') {
81
+ nodes.push({
82
+ type: 'text',
83
+ content: token.content
84
+ });
85
+ position.index += 1;
86
+ } else if (token.type === 'newline') {
87
+ nodes.push({
88
+ type: 'newline'
89
+ });
90
+ position.index += 1;
91
+ } else if (token.type === 'close') {
92
+ if (token.tag === untilTag) {
93
+ position.index += 1;
94
+ return {
95
+ closed: true,
96
+ nodes
97
+ };
98
+ }
99
+ // Mismatched close tag — render as literal text
100
+ nodes.push({
101
+ type: 'text',
102
+ content: `</${token.tag}>`
103
+ });
104
+ position.index += 1;
105
+ } else if (token.type === 'open') {
106
+ if (depth >= constants.MAX_NESTING_DEPTH) {
107
+ nodes.push({
108
+ type: 'text',
109
+ content: `<${token.tag}${token.attrs}>`
110
+ });
111
+ position.index += 1;
112
+ } else {
113
+ position.index += 1;
114
+ const result = parse(tokens, position, token.tag, depth + 1);
115
+ if (result.closed) {
116
+ const node = buildNode(token.tag, token.attrs, result.nodes);
117
+ nodes.push(node);
118
+ } else {
119
+ nodes.push({
120
+ type: 'text',
121
+ content: `<${token.tag}${token.attrs}>`
122
+ });
123
+ nodes.push(...result.nodes);
124
+ }
125
+ }
126
+ }
127
+ }
128
+ if (untilTag) {
129
+ return {
130
+ closed: false,
131
+ nodes
132
+ };
133
+ }
134
+ return {
135
+ closed: true,
136
+ nodes
137
+ };
138
+ }
139
+ /**
140
+ * Maps a raw tag name to a typed MarkupNode. Resolves aliases first (p→paragraph, a→link),
141
+ * then builds the appropriate node shape. Link nodes carry full attributes; other element
142
+ * nodes extract only accessibilityLabel.
143
+ */
144
+ function buildNode(rawTag, attrs, children) {
145
+ const tag = constants.TAG_ALIASES[rawTag] || rawTag;
146
+ if (tag === 'link') {
147
+ return {
148
+ type: 'link',
149
+ children,
150
+ ...parseAttributes(attrs)
151
+ };
152
+ }
153
+ if (tag === 'paragraph') {
154
+ return {
155
+ type: 'paragraph',
156
+ children
157
+ };
158
+ }
159
+ const {
160
+ accessibilityLabel
161
+ } = parseAttributes(attrs);
162
+ return {
163
+ type: tag,
164
+ children,
165
+ ...(accessibilityLabel && {
166
+ accessibilityLabel
167
+ })
168
+ };
169
+ }
170
+ const ATTR_REGEX = /(?<=\s)(href|action|target|accessibilityLabel)=(?:"([^"]*)"|'([^']*)')/g;
171
+ /**
172
+ * Extracts allowed attributes from a raw attribute string.
173
+ * Supports both double- and single-quoted values. Any attribute not in the
174
+ * allow-list (href, action, target, accessibilityLabel) is silently discarded.
175
+ * First occurrence wins — duplicates are ignored.
176
+ */
177
+ function parseAttributes(attrs) {
178
+ const result = {};
179
+ ATTR_REGEX.lastIndex = 0;
180
+ let match = ATTR_REGEX.exec(attrs);
181
+ while (match !== null) {
182
+ const key = match[1];
183
+ const value = match[2] ?? match[3];
184
+ if (!(key in result)) {
185
+ const sanitized = sanitizeAttributeValue(key, value);
186
+ if (sanitized !== undefined) {
187
+ result[key] = sanitized;
188
+ }
189
+ }
190
+ match = ATTR_REGEX.exec(attrs);
191
+ }
192
+ return result;
193
+ }
194
+ function sanitizeAttributeValue(key, value) {
195
+ switch (key) {
196
+ case 'href':
197
+ return value.replace(CONTROL_CHARS, '');
198
+ case 'action':
199
+ if (OBJECT_PROTOTYPE_KEYS.has(value)) {
200
+ return undefined;
201
+ }
202
+ return value;
203
+ case 'target':
204
+ if (!constants.ALLOWED_TARGETS.includes(value)) {
205
+ return undefined;
206
+ }
207
+ return value;
208
+ case 'accessibilityLabel':
209
+ return value.replace(HTML_METACHAR, '').slice(0, MAX_ACCESSIBILITY_LABEL_LENGTH);
210
+ default:
211
+ return value;
212
+ }
213
+ }
214
+ /** Entry point: tokenises the input string, then parses the token stream into a MarkupNode tree. */
215
+ function parseMarkup(input) {
216
+ if (!input) {
217
+ return [];
218
+ }
219
+ if (input.length > MAX_INPUT_LENGTH) {
220
+ return [{
221
+ type: 'text',
222
+ content: input
223
+ }];
224
+ }
225
+ const tokens = tokenise(input);
226
+ const position = {
227
+ index: 0
228
+ };
229
+ return parse(tokens, position).nodes;
230
+ }
231
+
232
+ exports.MAX_NESTING_DEPTH = constants.MAX_NESTING_DEPTH;
233
+ exports.MAX_ACCESSIBILITY_LABEL_LENGTH = MAX_ACCESSIBILITY_LABEL_LENGTH;
234
+ exports.MAX_INPUT_LENGTH = MAX_INPUT_LENGTH;
235
+ exports.parseMarkup = parseMarkup;
236
+ //# sourceMappingURL=parseMarkup.js.map