@pie-lib/mask-markup 3.0.2-next.1 → 3.0.2-next.3
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 +10 -0
- package/lib/mask.js +8 -6
- package/lib/mask.js.map +1 -1
- package/package.json +6 -6
- package/src/__tests__/mask.test.js +194 -0
- package/src/mask.jsx +8 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
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.2-next.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/mask-markup@3.0.2-next.2...@pie-lib/mask-markup@3.0.2-next.3) (2026-05-07)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @pie-lib/mask-markup
|
|
9
|
+
|
|
10
|
+
## [3.0.2-next.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/mask-markup@3.0.2-next.1...@pie-lib/mask-markup@3.0.2-next.2) (2026-05-06)
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
- made sure extra spacing is added only when needed [PIE-436] ([1eb4b4c](https://github.com/pie-framework/pie-lib/commit/1eb4b4cfa26612ff32f68bc849da59dc0c5c521b))
|
|
15
|
+
|
|
6
16
|
## [3.0.2-next.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/mask-markup@3.0.2-next.0...@pie-lib/mask-markup@3.0.2-next.1) (2026-05-06)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @pie-lib/mask-markup
|
package/lib/mask.js
CHANGED
|
@@ -72,8 +72,15 @@ var _renderChildren = exports.renderChildren = function renderChildren(layout, v
|
|
|
72
72
|
if (rootRenderChildren) {
|
|
73
73
|
var c = rootRenderChildren(n, value, onChange);
|
|
74
74
|
if (c) {
|
|
75
|
+
var _n$data;
|
|
76
|
+
var isDndComponent = ((_n$data = n.data) === null || _n$data === void 0 || (_n$data = _n$data.dataset) === null || _n$data === void 0 ? void 0 : _n$data.component) === 'blank';
|
|
77
|
+
if (isDndComponent) {
|
|
78
|
+
children.push(/*#__PURE__*/_react["default"].createElement(Spacer, {
|
|
79
|
+
key: "spacer-".concat(index)
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
75
82
|
children.push(c);
|
|
76
|
-
if (
|
|
83
|
+
if (isDndComponent) {
|
|
77
84
|
children.push(/*#__PURE__*/_react["default"].createElement(Spacer, {
|
|
78
85
|
key: "spacer-".concat(index)
|
|
79
86
|
}));
|
|
@@ -101,11 +108,6 @@ var _renderChildren = exports.renderChildren = function renderChildren(layout, v
|
|
|
101
108
|
}
|
|
102
109
|
} else if (content.length > 0) {
|
|
103
110
|
children.push(content);
|
|
104
|
-
if ((parentNode === null || parentNode === void 0 ? void 0 : parentNode.type) !== 'td' && elementType === 'drag-in-the-blank') {
|
|
105
|
-
children.push(/*#__PURE__*/_react["default"].createElement(Spacer, {
|
|
106
|
-
key: "spacer-".concat(index)
|
|
107
|
-
}));
|
|
108
|
-
}
|
|
109
111
|
}
|
|
110
112
|
} else {
|
|
111
113
|
var subNodes = _renderChildren(n, value, onChange, rootRenderChildren, n, elementType);
|
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","object","content","reduce","acc","l","extraText","markKey","MARK_TAGS","Tag","subNodes","_Tag","_extends2","data","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 children.push(c);\n if (parentNode?.type !== 'td' && elementType === 'drag-in-the-blank') {\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 if (parentNode?.type !== 'td' && elementType === 'drag-in-the-blank') {\n children.push(<Spacer key={`spacer-${index}`} />);\n }\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,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O,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","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,CAAA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BAAOlH,MAAA,YAAAiF,aAAA,CAACuB,aAAa;QAACsB,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":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/mask-markup",
|
|
3
|
-
"version": "3.0.2-next.
|
|
3
|
+
"version": "3.0.2-next.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"@emotion/style": "^0.8.0",
|
|
14
14
|
"@mui/icons-material": "^7.3.4",
|
|
15
15
|
"@mui/material": "^7.3.4",
|
|
16
|
-
"@pie-lib/drag": "^4.0.2-next.
|
|
17
|
-
"@pie-lib/editable-html-tip-tap": "^2.1.0-next.
|
|
18
|
-
"@pie-lib/math-rendering": "^5.0.2-next.
|
|
19
|
-
"@pie-lib/render-ui": "^6.1.0-next.
|
|
16
|
+
"@pie-lib/drag": "^4.0.2-next.2",
|
|
17
|
+
"@pie-lib/editable-html-tip-tap": "^2.1.0-next.3",
|
|
18
|
+
"@pie-lib/math-rendering": "^5.0.2-next.1",
|
|
19
|
+
"@pie-lib/render-ui": "^6.1.0-next.2",
|
|
20
20
|
"classnames": "^2.2.6",
|
|
21
21
|
"debug": "^4.1.1",
|
|
22
22
|
"lodash-es": "^4.17.23",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"keywords": [],
|
|
29
29
|
"author": "",
|
|
30
30
|
"license": "ISC",
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "abac0350cad300ce7a38fd54141b281b48a1461a"
|
|
32
32
|
}
|
|
@@ -184,4 +184,198 @@ describe('Mask', () => {
|
|
|
184
184
|
expect(container.querySelector('tr')).toBeInTheDocument();
|
|
185
185
|
});
|
|
186
186
|
});
|
|
187
|
+
|
|
188
|
+
describe('spacer rendering for DnD components', () => {
|
|
189
|
+
it('adds spacers before and after DnD blank components', () => {
|
|
190
|
+
const mockRenderChildren = jest.fn((n) => {
|
|
191
|
+
if (n.data?.dataset?.component === 'blank') {
|
|
192
|
+
return <span data-testid="blank-component">Blank</span>;
|
|
193
|
+
}
|
|
194
|
+
return null;
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
const { container } = render(
|
|
198
|
+
<Mask
|
|
199
|
+
{...defaultProps}
|
|
200
|
+
renderChildren={mockRenderChildren}
|
|
201
|
+
layout={{
|
|
202
|
+
nodes: [
|
|
203
|
+
{
|
|
204
|
+
type: 'div',
|
|
205
|
+
data: {
|
|
206
|
+
dataset: { component: 'blank' },
|
|
207
|
+
attributes: {},
|
|
208
|
+
},
|
|
209
|
+
nodes: [],
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
}}
|
|
213
|
+
/>,
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
// Check that renderChildren was called and spacers are present
|
|
217
|
+
// Count all children in the container - should be: spacer + blank + spacer = 3 elements
|
|
218
|
+
const maskContainer = container.firstChild;
|
|
219
|
+
expect(maskContainer.childNodes.length).toBe(3);
|
|
220
|
+
expect(screen.getByTestId('blank-component')).toBeInTheDocument();
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('does not add spacers for non-DnD components', () => {
|
|
224
|
+
const mockRenderChildren = jest.fn((n) => {
|
|
225
|
+
return <span data-testid="regular-component">Regular</span>;
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
const { container } = render(
|
|
229
|
+
<Mask
|
|
230
|
+
{...defaultProps}
|
|
231
|
+
renderChildren={mockRenderChildren}
|
|
232
|
+
layout={{
|
|
233
|
+
nodes: [
|
|
234
|
+
{
|
|
235
|
+
type: 'div',
|
|
236
|
+
data: {
|
|
237
|
+
attributes: {},
|
|
238
|
+
},
|
|
239
|
+
nodes: [],
|
|
240
|
+
},
|
|
241
|
+
],
|
|
242
|
+
}}
|
|
243
|
+
/>,
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
// Should not have spacers - only the regular component
|
|
247
|
+
const maskContainer = container.firstChild;
|
|
248
|
+
expect(maskContainer.childNodes.length).toBe(1);
|
|
249
|
+
expect(screen.getByTestId('regular-component')).toBeInTheDocument();
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it('adds spacers regardless of parent node type', () => {
|
|
253
|
+
const mockRenderChildren = jest.fn((n) => {
|
|
254
|
+
if (n.data?.dataset?.component === 'blank') {
|
|
255
|
+
return <span data-testid="blank-in-td">Blank in TD</span>;
|
|
256
|
+
}
|
|
257
|
+
return null;
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
const { container } = render(
|
|
261
|
+
<Mask
|
|
262
|
+
{...defaultProps}
|
|
263
|
+
renderChildren={mockRenderChildren}
|
|
264
|
+
elementType="drag-in-the-blank"
|
|
265
|
+
layout={{
|
|
266
|
+
nodes: [
|
|
267
|
+
{
|
|
268
|
+
type: 'table',
|
|
269
|
+
data: { attributes: {} },
|
|
270
|
+
nodes: [
|
|
271
|
+
{
|
|
272
|
+
type: 'tbody',
|
|
273
|
+
data: { attributes: {} },
|
|
274
|
+
nodes: [
|
|
275
|
+
{
|
|
276
|
+
type: 'tr',
|
|
277
|
+
data: { attributes: {} },
|
|
278
|
+
nodes: [
|
|
279
|
+
{
|
|
280
|
+
type: 'td',
|
|
281
|
+
data: { attributes: {} },
|
|
282
|
+
nodes: [
|
|
283
|
+
{
|
|
284
|
+
type: 'div',
|
|
285
|
+
data: {
|
|
286
|
+
dataset: { component: 'blank' },
|
|
287
|
+
attributes: {},
|
|
288
|
+
},
|
|
289
|
+
nodes: [],
|
|
290
|
+
},
|
|
291
|
+
],
|
|
292
|
+
},
|
|
293
|
+
],
|
|
294
|
+
},
|
|
295
|
+
],
|
|
296
|
+
},
|
|
297
|
+
],
|
|
298
|
+
},
|
|
299
|
+
],
|
|
300
|
+
}}
|
|
301
|
+
/>,
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
// Should have spacers even inside td element
|
|
305
|
+
const td = container.querySelector('td');
|
|
306
|
+
expect(td.childNodes.length).toBe(3); // spacer + blank + spacer
|
|
307
|
+
expect(screen.getByTestId('blank-in-td')).toBeInTheDocument();
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it('does not add spacers for text content', () => {
|
|
311
|
+
const { container } = render(
|
|
312
|
+
<Mask
|
|
313
|
+
{...defaultProps}
|
|
314
|
+
elementType="drag-in-the-blank"
|
|
315
|
+
layout={{
|
|
316
|
+
nodes: [
|
|
317
|
+
{
|
|
318
|
+
object: 'text',
|
|
319
|
+
leaves: [
|
|
320
|
+
{
|
|
321
|
+
text: 'Some text',
|
|
322
|
+
},
|
|
323
|
+
],
|
|
324
|
+
},
|
|
325
|
+
],
|
|
326
|
+
}}
|
|
327
|
+
/>,
|
|
328
|
+
);
|
|
329
|
+
|
|
330
|
+
// Should not have spacers for plain text - just text node
|
|
331
|
+
const maskContainer = container.firstChild;
|
|
332
|
+
expect(maskContainer.childNodes.length).toBe(1);
|
|
333
|
+
expect(maskContainer.childNodes[0].nodeType).toBe(Node.TEXT_NODE);
|
|
334
|
+
expect(screen.getByText('Some text')).toBeInTheDocument();
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it('handles multiple DnD components with correct spacer placement', () => {
|
|
338
|
+
const mockRenderChildren = jest.fn((n) => {
|
|
339
|
+
if (n.data?.dataset?.component === 'blank') {
|
|
340
|
+
return <span data-testid={`blank-${n.data.testId}`}>Blank</span>;
|
|
341
|
+
}
|
|
342
|
+
return null;
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
const { container } = render(
|
|
346
|
+
<Mask
|
|
347
|
+
{...defaultProps}
|
|
348
|
+
renderChildren={mockRenderChildren}
|
|
349
|
+
layout={{
|
|
350
|
+
nodes: [
|
|
351
|
+
{
|
|
352
|
+
type: 'div',
|
|
353
|
+
data: {
|
|
354
|
+
dataset: { component: 'blank' },
|
|
355
|
+
attributes: {},
|
|
356
|
+
testId: '1',
|
|
357
|
+
},
|
|
358
|
+
nodes: [],
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
type: 'div',
|
|
362
|
+
data: {
|
|
363
|
+
dataset: { component: 'blank' },
|
|
364
|
+
attributes: {},
|
|
365
|
+
testId: '2',
|
|
366
|
+
},
|
|
367
|
+
nodes: [],
|
|
368
|
+
},
|
|
369
|
+
],
|
|
370
|
+
}}
|
|
371
|
+
/>,
|
|
372
|
+
);
|
|
373
|
+
|
|
374
|
+
// Should have 2 spacers per component = 4 spacers + 2 blanks = 6 total children
|
|
375
|
+
const maskContainer = container.firstChild;
|
|
376
|
+
expect(maskContainer.childNodes.length).toBe(6);
|
|
377
|
+
expect(screen.getByTestId('blank-1')).toBeInTheDocument();
|
|
378
|
+
expect(screen.getByTestId('blank-2')).toBeInTheDocument();
|
|
379
|
+
});
|
|
380
|
+
});
|
|
187
381
|
});
|
package/src/mask.jsx
CHANGED
|
@@ -62,8 +62,15 @@ export const renderChildren = (layout, value, onChange, rootRenderChildren, pare
|
|
|
62
62
|
if (rootRenderChildren) {
|
|
63
63
|
const c = rootRenderChildren(n, value, onChange);
|
|
64
64
|
if (c) {
|
|
65
|
+
const isDndComponent = n.data?.dataset?.component === 'blank';
|
|
66
|
+
|
|
67
|
+
if (isDndComponent) {
|
|
68
|
+
children.push(<Spacer key={`spacer-${index}`} />);
|
|
69
|
+
}
|
|
70
|
+
|
|
65
71
|
children.push(c);
|
|
66
|
-
|
|
72
|
+
|
|
73
|
+
if (isDndComponent) {
|
|
67
74
|
children.push(<Spacer key={`spacer-${index}`} />);
|
|
68
75
|
}
|
|
69
76
|
return;
|
|
@@ -91,9 +98,6 @@ export const renderChildren = (layout, value, onChange, rootRenderChildren, pare
|
|
|
91
98
|
}
|
|
92
99
|
} else if (content.length > 0) {
|
|
93
100
|
children.push(content);
|
|
94
|
-
if (parentNode?.type !== 'td' && elementType === 'drag-in-the-blank') {
|
|
95
|
-
children.push(<Spacer key={`spacer-${index}`} />);
|
|
96
|
-
}
|
|
97
101
|
}
|
|
98
102
|
} else {
|
|
99
103
|
const subNodes = renderChildren(n, value, onChange, rootRenderChildren, n, elementType);
|