@pie-lib/mask-markup 3.0.16 → 3.0.17
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.
- package/CHANGELOG.md +6 -0
- package/lib/mask.js +20 -15
- package/lib/mask.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/mask.test.js +98 -0
- package/src/mask.jsx +13 -11
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.0.17](https://github.com/pie-framework/pie-lib/compare/@pie-lib/mask-markup@3.0.16...@pie-lib/mask-markup@3.0.17) (2026-08-22)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- made sure template field renders all marks [PIE-518] ([ad97d4f](https://github.com/pie-framework/pie-lib/commit/ad97d4ff98821544ca944741643601eeaefbffc5))
|
|
11
|
+
|
|
6
12
|
## [3.0.16](https://github.com/pie-framework/pie-lib/compare/@pie-lib/mask-markup@3.0.15...@pie-lib/mask-markup@3.0.16) (2026-08-21)
|
|
7
13
|
|
|
8
14
|
**Note:** Version bump only for package @pie-lib/mask-markup
|
package/lib/mask.js
CHANGED
|
@@ -50,7 +50,7 @@ var getMark = function getMark(n) {
|
|
|
50
50
|
return (0, _lodashEs.get)(leave, 'marks', []).length;
|
|
51
51
|
});
|
|
52
52
|
if (mark) {
|
|
53
|
-
return mark.marks
|
|
53
|
+
return mark.marks;
|
|
54
54
|
}
|
|
55
55
|
return null;
|
|
56
56
|
};
|
|
@@ -94,17 +94,22 @@ var _renderChildren = exports.renderChildren = function renderChildren(layout, v
|
|
|
94
94
|
var extraText = addText(parentNode, t);
|
|
95
95
|
return extraText ? acc + extraText : acc;
|
|
96
96
|
}, '');
|
|
97
|
-
var
|
|
98
|
-
if (
|
|
99
|
-
var
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
97
|
+
var marks = getMark(n);
|
|
98
|
+
if ((marks === null || marks === void 0 ? void 0 : marks.length) > 0) {
|
|
99
|
+
var tagsToWrap = marks.map(function (mark) {
|
|
100
|
+
return Object.keys(_serialization.MARK_TAGS).find(function (markKey) {
|
|
101
|
+
return _serialization.MARK_TAGS[markKey] === mark.type;
|
|
102
|
+
});
|
|
103
|
+
}).filter(Boolean);
|
|
104
|
+
if (tagsToWrap.length > 0) {
|
|
105
|
+
// nest from the inside out so the first mark ends up as the outermost tag: <b><em>content</em></b>
|
|
106
|
+
children.push(tagsToWrap.reduceRight(function (acc, Tag, tagIndex) {
|
|
107
|
+
return /*#__PURE__*/_react["default"].createElement(Tag, {
|
|
108
|
+
key: "".concat(key, "-").concat(Tag, "-").concat(tagIndex)
|
|
109
|
+
}, acc);
|
|
110
|
+
}, content));
|
|
111
|
+
} else {
|
|
112
|
+
children.push(content);
|
|
108
113
|
}
|
|
109
114
|
} else if (content.length > 0) {
|
|
110
115
|
children.push(content);
|
|
@@ -116,13 +121,13 @@ var _renderChildren = exports.renderChildren = function renderChildren(layout, v
|
|
|
116
121
|
key: key
|
|
117
122
|
}, subNodes));
|
|
118
123
|
} else {
|
|
119
|
-
var
|
|
124
|
+
var Tag = n.type;
|
|
120
125
|
if (n.nodes && n.nodes.length > 0) {
|
|
121
|
-
children.push(/*#__PURE__*/_react["default"].createElement(
|
|
126
|
+
children.push(/*#__PURE__*/_react["default"].createElement(Tag, (0, _extends2["default"])({
|
|
122
127
|
key: key
|
|
123
128
|
}, n.data.attributes), subNodes));
|
|
124
129
|
} else {
|
|
125
|
-
children.push(/*#__PURE__*/_react["default"].createElement(
|
|
130
|
+
children.push(/*#__PURE__*/_react["default"].createElement(Tag, (0, _extends2["default"])({
|
|
126
131
|
key: key
|
|
127
132
|
}, n.data.attributes)));
|
|
128
133
|
}
|
package/lib/mask.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mask.js","names":["_react","_interopRequireDefault","require","_propTypes","_lodashEs","_styles","_mathRendering","_serialization","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","_callSuper","_getPrototypeOf2","_possibleConstructorReturn2","_isNativeReflectConstruct","Reflect","construct","constructor","Boolean","prototype","valueOf","call","Paragraph","styled","_ref","theme","paddingTop","spacing","paddingBottom","Spacer","display","width","restrictWhitespaceTypes","addText","parentNode","text","isWhitespace","trim","parentType","type","includes","undefined","getMark","n","mark","leaves","find","leave","get","marks","renderChildren","exports","layout","value","onChange","rootRenderChildren","elementType","children","nodes","index","key","concat","isMath","createElement","dangerouslySetInnerHTML","__html","innerHTML","c","_n$data","isDndComponent","data","dataset","component","object","content","reduce","acc","l","extraText","markKey","MARK_TAGS","Tag","subNodes","_Tag","_extends2","attributes","MaskContainer","borderCollapse","padding","textAlign","Mask","_React$Component","props","_this","_classCallCheck2","id","internalContainerRef","React","createRef","_inherits2","_createClass2","componentDidMount","containerRef","current","renderMath","render","_this$props","handleChange","ref","Component","PropTypes","func","string","oneOfType","shape","instanceOf","Element"],"sources":["../src/mask.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { get } from 'lodash-es';\nimport { styled } from '@mui/material/styles';\nimport { renderMath } from '@pie-lib/math-rendering';\nimport { MARK_TAGS } from './serialization';\n\nconst Paragraph = styled('div')(({ theme }) => ({\n paddingTop: theme.spacing(0.5),\n paddingBottom: theme.spacing(0.5),\n}));\n\nconst Spacer = styled('span')(() => ({\n display: 'inline-block',\n width: '.75em',\n}));\n\nconst restrictWhitespaceTypes = ['tbody', 'tr'];\n\nconst addText = (parentNode, text) => {\n const isWhitespace = text.trim() === '';\n const parentType = parentNode && parentNode.type;\n\n if (isWhitespace && restrictWhitespaceTypes.includes(parentType)) {\n return undefined;\n } else {\n return text;\n }\n};\n\nconst getMark = (n) => {\n const mark = n.leaves.find((leave) => get(leave, 'marks', []).length);\n\n if (mark) {\n return mark.marks[0];\n }\n\n return null;\n};\n\nexport const renderChildren = (layout, value, onChange, rootRenderChildren, parentNode, elementType) => {\n if (!value) {\n return null;\n }\n\n const children = [];\n\n (layout.nodes || []).forEach((n, index) => {\n const key = n.type ? `${n.type}-${index}` : `${index}`;\n\n if (n.isMath) {\n children.push(\n <span\n dangerouslySetInnerHTML={{\n __html: `<math displaystyle=\"true\">${n.nodes[0].innerHTML}</math>`,\n }}\n />,\n );\n return children;\n }\n\n if (rootRenderChildren) {\n const c = rootRenderChildren(n, value, onChange);\n if (c) {\n const isDndComponent = n.data?.dataset?.component === 'blank';\n\n if (isDndComponent) {\n children.push(<Spacer key={`spacer-${index}`} />);\n }\n\n children.push(c);\n\n if (isDndComponent) {\n children.push(<Spacer key={`spacer-${index}`} />);\n }\n return;\n }\n }\n\n if (n.object === 'text') {\n const content = n.leaves.reduce((acc, l) => {\n const t = l.text;\n const extraText = addText(parentNode, t);\n return extraText ? acc + extraText : acc;\n }, '');\n const mark = getMark(n);\n\n if (mark) {\n let markKey;\n\n for (markKey in MARK_TAGS) {\n if (MARK_TAGS[markKey] === mark.type) {\n const Tag = markKey;\n\n children.push(<Tag key={key}>{content}</Tag>);\n break;\n }\n }\n } else if (content.length > 0) {\n children.push(content);\n }\n } else {\n const subNodes = renderChildren(n, value, onChange, rootRenderChildren, n, elementType);\n if (n.type === 'p' || n.type === 'paragraph') {\n children.push(<Paragraph key={key}>{subNodes}</Paragraph>);\n } else {\n const Tag = n.type;\n if (n.nodes && n.nodes.length > 0) {\n children.push(\n <Tag key={key} {...n.data.attributes}>\n {subNodes}\n </Tag>,\n );\n } else {\n children.push(<Tag key={key} {...n.data.attributes} />);\n }\n }\n }\n });\n return children;\n};\n\nconst MaskContainer = styled('div')(() => ({\n display: 'initial',\n '&:not(.MathJax) table': {\n borderCollapse: 'collapse',\n },\n // align table content to left as per STAR requirement PD-3687\n '&:not(.MathJax) table td, &:not(.MathJax) table th': {\n padding: '8px 12px',\n textAlign: 'left',\n },\n}));\n\n/**\n * Renders a layout that uses the slate.js Value model structure.\n */\nexport default class Mask extends React.Component {\n constructor(props) {\n super(props);\n this.internalContainerRef = React.createRef();\n }\n\n static propTypes = {\n renderChildren: PropTypes.func,\n layout: PropTypes.object,\n value: PropTypes.object,\n onChange: PropTypes.func,\n elementType: PropTypes.string,\n containerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({ current: PropTypes.instanceOf(Element) })]),\n };\n\n componentDidMount() {\n const containerRef = this.props.containerRef || this.internalContainerRef;\n if (containerRef.current && typeof renderMath === 'function') {\n renderMath(containerRef.current);\n }\n }\n\n handleChange = (id, value) => {\n const data = { ...this.props.value, [id]: value };\n this.props.onChange(data);\n };\n\n render() {\n const { value, layout, elementType, containerRef } = this.props;\n const children = renderChildren(layout, value, this.handleChange, this.props.renderChildren, null, elementType);\n const ref = containerRef || this.internalContainerRef;\n\n return <MaskContainer ref={ref}>{children}</MaskContainer>;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AACA,IAAAK,cAAA,GAAAL,OAAA;AAA4C,SAAAM,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,OAAAG,MAAA,CAAAE,qBAAA,QAAAC,CAAA,GAAAH,MAAA,CAAAE,qBAAA,CAAAL,CAAA,GAAAC,CAAA,KAAAK,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAN,CAAA,WAAAE,MAAA,CAAAK,wBA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sB,GAAG,EAAEA;MAAI,GAAEnD,QAAwB,CAAC;IAC5D;EAAC;AAAA,EAjC+BwC,iBAAK,CAACY,SAAS;AAAA,IAAAtG,gBAAA,aAA5BmF,IAAI,eAMJ;EACjBxC,cAAc,EAAE4D,qBAAS,CAACC,IAAI;EAC9B3D,MAAM,EAAE0D,qBAAS,CAACrC,MAAM;EACxBpB,KAAK,EAAEyD,qBAAS,CAACrC,MAAM;EACvBnB,QAAQ,EAAEwD,qBAAS,CAACC,IAAI;EACxBvD,WAAW,EAAEsD,qBAAS,CAACE,MAAM;EAC7BV,YAAY,EAAEQ,qBAAS,CAACG,SAAS,CAAC,CAACH,qBAAS,CAACC,IAAI,EAAED,qBAAS,CAACI,KAAK,CAAC;IAAEX,OAAO,EAAEO,qBAAS,CAACK,UAAU,CAACC,OAAO;EAAE,CAAC,CAAC,CAAC;AACjH,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"mask.js","names":["_react","_interopRequireDefault","require","_propTypes","_lodashEs","_styles","_mathRendering","_serialization","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","_callSuper","_getPrototypeOf2","_possibleConstructorReturn2","_isNativeReflectConstruct","Reflect","construct","constructor","Boolean","prototype","valueOf","call","Paragraph","styled","_ref","theme","paddingTop","spacing","paddingBottom","Spacer","display","width","restrictWhitespaceTypes","addText","parentNode","text","isWhitespace","trim","parentType","type","includes","undefined","getMark","n","mark","leaves","find","leave","get","marks","renderChildren","exports","layout","value","onChange","rootRenderChildren","elementType","children","nodes","index","key","concat","isMath","createElement","dangerouslySetInnerHTML","__html","innerHTML","c","_n$data","isDndComponent","data","dataset","component","object","content","reduce","acc","l","extraText","tagsToWrap","map","MARK_TAGS","markKey","reduceRight","Tag","tagIndex","subNodes","_extends2","attributes","MaskContainer","borderCollapse","padding","textAlign","Mask","_React$Component","props","_this","_classCallCheck2","id","internalContainerRef","React","createRef","_inherits2","_createClass2","componentDidMount","containerRef","current","renderMath","render","_this$props","handleChange","ref","Component","PropTypes","func","string","oneOfType","shape","instanceOf","Element"],"sources":["../src/mask.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { get } from 'lodash-es';\nimport { styled } from '@mui/material/styles';\nimport { renderMath } from '@pie-lib/math-rendering';\nimport { MARK_TAGS } from './serialization';\n\nconst Paragraph = styled('div')(({ theme }) => ({\n paddingTop: theme.spacing(0.5),\n paddingBottom: theme.spacing(0.5),\n}));\n\nconst Spacer = styled('span')(() => ({\n display: 'inline-block',\n width: '.75em',\n}));\n\nconst restrictWhitespaceTypes = ['tbody', 'tr'];\n\nconst addText = (parentNode, text) => {\n const isWhitespace = text.trim() === '';\n const parentType = parentNode && parentNode.type;\n\n if (isWhitespace && restrictWhitespaceTypes.includes(parentType)) {\n return undefined;\n } else {\n return text;\n }\n};\n\nconst getMark = (n) => {\n const mark = n.leaves.find((leave) => get(leave, 'marks', []).length);\n\n if (mark) {\n return mark.marks;\n }\n\n return null;\n};\n\nexport const renderChildren = (layout, value, onChange, rootRenderChildren, parentNode, elementType) => {\n if (!value) {\n return null;\n }\n\n const children = [];\n\n (layout.nodes || []).forEach((n, index) => {\n const key = n.type ? `${n.type}-${index}` : `${index}`;\n\n if (n.isMath) {\n children.push(\n <span\n dangerouslySetInnerHTML={{\n __html: `<math displaystyle=\"true\">${n.nodes[0].innerHTML}</math>`,\n }}\n />,\n );\n return children;\n }\n\n if (rootRenderChildren) {\n const c = rootRenderChildren(n, value, onChange);\n if (c) {\n const isDndComponent = n.data?.dataset?.component === 'blank';\n\n if (isDndComponent) {\n children.push(<Spacer key={`spacer-${index}`} />);\n }\n\n children.push(c);\n\n if (isDndComponent) {\n children.push(<Spacer key={`spacer-${index}`} />);\n }\n return;\n }\n }\n\n if (n.object === 'text') {\n const content = n.leaves.reduce((acc, l) => {\n const t = l.text;\n const extraText = addText(parentNode, t);\n return extraText ? acc + extraText : acc;\n }, '');\n const marks = getMark(n);\n\n if (marks?.length > 0) {\n const tagsToWrap = marks\n .map((mark) => Object.keys(MARK_TAGS).find((markKey) => MARK_TAGS[markKey] === mark.type))\n .filter(Boolean);\n\n if (tagsToWrap.length > 0) {\n // nest from the inside out so the first mark ends up as the outermost tag: <b><em>content</em></b>\n children.push(\n tagsToWrap.reduceRight((acc, Tag, tagIndex) => <Tag key={`${key}-${Tag}-${tagIndex}`}>{acc}</Tag>, content),\n );\n } else {\n children.push(content);\n }\n } else if (content.length > 0) {\n children.push(content);\n }\n } else {\n const subNodes = renderChildren(n, value, onChange, rootRenderChildren, n, elementType);\n if (n.type === 'p' || n.type === 'paragraph') {\n children.push(<Paragraph key={key}>{subNodes}</Paragraph>);\n } else {\n const Tag = n.type;\n if (n.nodes && n.nodes.length > 0) {\n children.push(\n <Tag key={key} {...n.data.attributes}>\n {subNodes}\n </Tag>,\n );\n } else {\n children.push(<Tag key={key} {...n.data.attributes} />);\n }\n }\n }\n });\n return children;\n};\n\nconst MaskContainer = styled('div')(() => ({\n display: 'initial',\n '&:not(.MathJax) table': {\n borderCollapse: 'collapse',\n },\n // align table content to left as per STAR requirement PD-3687\n '&:not(.MathJax) table td, &:not(.MathJax) table th': {\n padding: '8px 12px',\n textAlign: 'left',\n },\n}));\n\n/**\n * Renders a layout that uses the slate.js Value model structure.\n */\nexport default class Mask extends React.Component {\n constructor(props) {\n super(props);\n this.internalContainerRef = React.createRef();\n }\n\n static propTypes = {\n renderChildren: PropTypes.func,\n layout: PropTypes.object,\n value: PropTypes.object,\n onChange: PropTypes.func,\n elementType: PropTypes.string,\n containerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({ current: PropTypes.instanceOf(Element) })]),\n };\n\n componentDidMount() {\n const containerRef = this.props.containerRef || this.internalContainerRef;\n if (containerRef.current && typeof renderMath === 'function') {\n renderMath(containerRef.current);\n }\n }\n\n handleChange = (id, value) => {\n const data = { ...this.props.value, [id]: value };\n this.props.onChange(data);\n };\n\n render() {\n const { value, layout, elementType, containerRef } = this.props;\n const children = renderChildren(layout, value, this.handleChange, this.props.renderChildren, null, elementType);\n const ref = containerRef || this.internalContainerRef;\n\n return <MaskContainer ref={ref}>{children}</MaskContainer>;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AACA,IAAAK,cAAA,GAAAL,OAAA;AAA4C,SAAAM,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,OAAAG,MAAA,CAAAE,qBAAA,QAAAC,CAAA,GAAAH,MAAA,CAAAE,qBAAA,CAAAL,CAAA,GAAAC,CAAA,KAAAK,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAN,CAAA,WAAAE,MAAA,CAAAK,wBAAA,CAAAR,CAAA,EAAAC,CAAA,EAAAQ,UAAA,OAAAP,CAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,CAAA,EAAAI,CAAA,YAAAJ,CAAA;AAAA,SAAAU,cAAAZ,CAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAY,SAAA,CAAAC,MAAA,EAAAb,CAAA,UAAAC,CAAA,WAAAW,SAAA,CAAAZ,CAAA,IAAAY,SAAA,CAAAZ,CAAA,QAAAA,CAAA,OAAAF,OAAA,CAAAI,MAAA,CAAAD,CAAA,OAAAa,OAAA,WAAAd,CAAA,QAAAe,gBAAA,aAAAhB,CAAA,EAAAC,CAAA,EAAAC,CAAA,CAAAD,CAAA,SAAAE,MAAA,CAAAc,yBAAA,GAAAd,MAAA,CAAAe,gBAAA,CAAAlB,CAAA,EAAAG,MAAA,CAAAc,yBAA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K,CAACY,SAAS;AAAA,IAAAzG,gBAAA,aAA5BsF,IAAI,eAMJ;EACjB3C,cAAc,EAAE+D,qBAAS,CAACC,IAAI;EAC9B9D,MAAM,EAAE6D,qBAAS,CAACxC,MAAM;EACxBpB,KAAK,EAAE4D,qBAAS,CAACxC,MAAM;EACvBnB,QAAQ,EAAE2D,qBAAS,CAACC,IAAI;EACxB1D,WAAW,EAAEyD,qBAAS,CAACE,MAAM;EAC7BV,YAAY,EAAEQ,qBAAS,CAACG,SAAS,CAAC,CAACH,qBAAS,CAACC,IAAI,EAAED,qBAAS,CAACI,KAAK,CAAC;IAAEX,OAAO,EAAEO,qBAAS,CAACK,UAAU,CAACC,OAAO;EAAE,CAAC,CAAC,CAAC;AACjH,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/mask-markup",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.17",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"keywords": [],
|
|
29
29
|
"author": "",
|
|
30
30
|
"license": "ISC",
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "748a5c413f84555835fa0728fb4867499a839a9a"
|
|
32
32
|
}
|
|
@@ -185,6 +185,104 @@ describe('Mask', () => {
|
|
|
185
185
|
});
|
|
186
186
|
});
|
|
187
187
|
|
|
188
|
+
describe('mark rendering', () => {
|
|
189
|
+
const markedLayout = (marks, text = 'x') => ({
|
|
190
|
+
nodes: [
|
|
191
|
+
{
|
|
192
|
+
object: 'text',
|
|
193
|
+
leaves: [{ marks, text }],
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('renders a mark as an element, not as escaped html text', () => {
|
|
199
|
+
const { container } = render(<Mask {...defaultProps} layout={markedLayout([{ type: 'bold' }])} />);
|
|
200
|
+
|
|
201
|
+
const b = container.querySelector('b');
|
|
202
|
+
expect(b).toBeInTheDocument();
|
|
203
|
+
expect(b.textContent).toBe('x');
|
|
204
|
+
// the tag must not leak into the text content
|
|
205
|
+
expect(container.textContent).toBe('x');
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it.each([
|
|
209
|
+
['bold', 'b'],
|
|
210
|
+
['italic', 'em'],
|
|
211
|
+
['underline', 'u'],
|
|
212
|
+
['strikethrough', 's'],
|
|
213
|
+
['code', 'code'],
|
|
214
|
+
['strong', 'strong'],
|
|
215
|
+
])('maps the %s mark to a <%s> element', (markType, tag) => {
|
|
216
|
+
const { container } = render(<Mask {...defaultProps} layout={markedLayout([{ type: markType }])} />);
|
|
217
|
+
|
|
218
|
+
const el = container.querySelector(tag);
|
|
219
|
+
expect(el).toBeInTheDocument();
|
|
220
|
+
expect(el.textContent).toBe('x');
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('nests multiple marks, keeping the first mark as the outermost tag', () => {
|
|
224
|
+
const { container } = render(
|
|
225
|
+
<Mask {...defaultProps} layout={markedLayout([{ type: 'bold' }, { type: 'italic' }])} />,
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
const nested = container.querySelector('b > em');
|
|
229
|
+
expect(nested).toBeInTheDocument();
|
|
230
|
+
expect(nested.textContent).toBe('x');
|
|
231
|
+
expect(container.textContent).toBe('x');
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('nests three marks in mark order', () => {
|
|
235
|
+
const { container } = render(
|
|
236
|
+
<Mask
|
|
237
|
+
{...defaultProps}
|
|
238
|
+
layout={markedLayout([{ type: 'underline' }, { type: 'strikethrough' }, { type: 'italic' }])}
|
|
239
|
+
/>,
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
const nested = container.querySelector('u > s > em');
|
|
243
|
+
expect(nested).toBeInTheDocument();
|
|
244
|
+
expect(nested.textContent).toBe('x');
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it('renders plain text when no mark maps to a tag', () => {
|
|
248
|
+
const { container } = render(<Mask {...defaultProps} layout={markedLayout([{ type: 'unknown-mark' }])} />);
|
|
249
|
+
|
|
250
|
+
expect(container.textContent).toBe('x');
|
|
251
|
+
expect(container.firstChild.childNodes[0].nodeType).toBe(Node.TEXT_NODE);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it('wraps only the marks that map to a tag', () => {
|
|
255
|
+
const { container } = render(
|
|
256
|
+
<Mask {...defaultProps} layout={markedLayout([{ type: 'unknown-mark' }, { type: 'bold' }])} />,
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
const b = container.querySelector('b');
|
|
260
|
+
expect(b).toBeInTheDocument();
|
|
261
|
+
expect(b.textContent).toBe('x');
|
|
262
|
+
expect(container.textContent).toBe('x');
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it('renders marked text inline alongside unmarked text', () => {
|
|
266
|
+
const { container } = render(
|
|
267
|
+
<Mask
|
|
268
|
+
{...defaultProps}
|
|
269
|
+
layout={{
|
|
270
|
+
nodes: [
|
|
271
|
+
{ object: 'text', leaves: [{ text: 'Foo ' }] },
|
|
272
|
+
{ object: 'text', leaves: [{ marks: [{ type: 'bold' }, { type: 'italic' }], text: 'x' }] },
|
|
273
|
+
{ object: 'text', leaves: [{ text: ' bar' }] },
|
|
274
|
+
],
|
|
275
|
+
object: 'block',
|
|
276
|
+
type: 'div',
|
|
277
|
+
}}
|
|
278
|
+
/>,
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
expect(container.querySelector('b > em').textContent).toBe('x');
|
|
282
|
+
expect(container.textContent).toBe('Foo x bar');
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
|
|
188
286
|
describe('spacer rendering for DnD components', () => {
|
|
189
287
|
it('adds spacers before and after DnD blank components', () => {
|
|
190
288
|
const mockRenderChildren = jest.fn((n) => {
|
package/src/mask.jsx
CHANGED
|
@@ -32,7 +32,7 @@ const getMark = (n) => {
|
|
|
32
32
|
const mark = n.leaves.find((leave) => get(leave, 'marks', []).length);
|
|
33
33
|
|
|
34
34
|
if (mark) {
|
|
35
|
-
return mark.marks
|
|
35
|
+
return mark.marks;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
return null;
|
|
@@ -83,18 +83,20 @@ export const renderChildren = (layout, value, onChange, rootRenderChildren, pare
|
|
|
83
83
|
const extraText = addText(parentNode, t);
|
|
84
84
|
return extraText ? acc + extraText : acc;
|
|
85
85
|
}, '');
|
|
86
|
-
const
|
|
86
|
+
const marks = getMark(n);
|
|
87
87
|
|
|
88
|
-
if (
|
|
89
|
-
|
|
88
|
+
if (marks?.length > 0) {
|
|
89
|
+
const tagsToWrap = marks
|
|
90
|
+
.map((mark) => Object.keys(MARK_TAGS).find((markKey) => MARK_TAGS[markKey] === mark.type))
|
|
91
|
+
.filter(Boolean);
|
|
90
92
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
93
|
+
if (tagsToWrap.length > 0) {
|
|
94
|
+
// nest from the inside out so the first mark ends up as the outermost tag: <b><em>content</em></b>
|
|
95
|
+
children.push(
|
|
96
|
+
tagsToWrap.reduceRight((acc, Tag, tagIndex) => <Tag key={`${key}-${Tag}-${tagIndex}`}>{acc}</Tag>, content),
|
|
97
|
+
);
|
|
98
|
+
} else {
|
|
99
|
+
children.push(content);
|
|
98
100
|
}
|
|
99
101
|
} else if (content.length > 0) {
|
|
100
102
|
children.push(content);
|