@pie-lib/render-ui 7.0.1 → 7.0.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/preview-prompt.js +22 -12
- package/lib/preview-prompt.js.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/preview-prompt.test.jsx +110 -1
- package/src/preview-prompt.jsx +11 -3
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
|
+
## [7.0.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/render-ui@7.0.2...@pie-lib/render-ui@7.0.3) (2026-09-22)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **render-ui:** let the custom audio button start playback when autoplay is off PIE-1068 ([94712ee](https://github.com/pie-framework/pie-lib/commit/94712ee98252dec2ffd45b44b1cc86ba430a51b2))
|
|
11
|
+
|
|
12
|
+
## [7.0.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/render-ui@7.0.1...@pie-lib/render-ui@7.0.2) (2026-09-02)
|
|
13
|
+
|
|
14
|
+
**Note:** Version bump only for package @pie-lib/render-ui
|
|
15
|
+
|
|
6
16
|
## [7.0.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/render-ui@7.0.0...@pie-lib/render-ui@7.0.1) (2026-08-26)
|
|
7
17
|
|
|
8
18
|
### Bug Fixes
|
package/lib/preview-prompt.js
CHANGED
|
@@ -105,7 +105,9 @@ var PreviewPrompt = exports.PreviewPrompt = /*#__PURE__*/function (_Component) {
|
|
|
105
105
|
_this = _callSuper(this, PreviewPrompt, [].concat(args));
|
|
106
106
|
(0, _defineProperty2["default"])(_this, "promptRef", /*#__PURE__*/_react["default"].createRef());
|
|
107
107
|
(0, _defineProperty2["default"])(_this, "parsedText", function (text) {
|
|
108
|
-
var
|
|
108
|
+
var _this$props = _this.props,
|
|
109
|
+
autoplayAudioEnabled = _this$props.autoplayAudioEnabled,
|
|
110
|
+
customAudioButton = _this$props.customAudioButton;
|
|
109
111
|
var div = document.createElement('div');
|
|
110
112
|
div.innerHTML = text;
|
|
111
113
|
var audio = div.querySelector('audio');
|
|
@@ -125,7 +127,10 @@ var PreviewPrompt = exports.PreviewPrompt = /*#__PURE__*/function (_Component) {
|
|
|
125
127
|
display: 'block',
|
|
126
128
|
width: '128px',
|
|
127
129
|
height: '128px',
|
|
128
|
-
|
|
130
|
+
// pauseImage is the playing state. Only autoplay starts in it - with
|
|
131
|
+
// autoplay off the audio is paused, so the button has to show
|
|
132
|
+
// playImage or it advertises a state the audio is not in.
|
|
133
|
+
backgroundImage: "url(".concat(autoplayAudioEnabled ? customAudioButton.pauseImage : customAudioButton.playImage, ")"),
|
|
129
134
|
backgroundSize: 'cover',
|
|
130
135
|
borderRadius: '50%',
|
|
131
136
|
border: '1px solid #326295'
|
|
@@ -141,9 +146,9 @@ var PreviewPrompt = exports.PreviewPrompt = /*#__PURE__*/function (_Component) {
|
|
|
141
146
|
return (0, _createClass2["default"])(PreviewPrompt, [{
|
|
142
147
|
key: "addCustomAudioButtonControls",
|
|
143
148
|
value: function addCustomAudioButtonControls() {
|
|
144
|
-
var _this$
|
|
145
|
-
autoplayAudioEnabled = _this$
|
|
146
|
-
customAudioButton = _this$
|
|
149
|
+
var _this$props2 = this.props,
|
|
150
|
+
autoplayAudioEnabled = _this$props2.autoplayAudioEnabled,
|
|
151
|
+
customAudioButton = _this$props2.customAudioButton;
|
|
147
152
|
var playButton = document.getElementById('play-audio-button');
|
|
148
153
|
var audio = document.getElementById('pie-prompt-audio-player');
|
|
149
154
|
if (autoplayAudioEnabled && audio) {
|
|
@@ -152,6 +157,12 @@ var PreviewPrompt = exports.PreviewPrompt = /*#__PURE__*/function (_Component) {
|
|
|
152
157
|
audio.addEventListener('ended', handleAudioEnded);
|
|
153
158
|
}
|
|
154
159
|
})["catch"](function (error) {
|
|
160
|
+
// Autoplay blocked (Safari/Firefox until the page has been
|
|
161
|
+
// interacted with). The audio is paused, so drop the button back to
|
|
162
|
+
// the idle image - clicking it is now the only way to start.
|
|
163
|
+
if (playButton && customAudioButton) {
|
|
164
|
+
playButton.style.backgroundImage = "url(".concat(customAudioButton.playImage, ")");
|
|
165
|
+
}
|
|
155
166
|
console.error('Error playing audio', error);
|
|
156
167
|
});
|
|
157
168
|
}
|
|
@@ -159,7 +170,6 @@ var PreviewPrompt = exports.PreviewPrompt = /*#__PURE__*/function (_Component) {
|
|
|
159
170
|
var handlePlayClick = function handlePlayClick() {
|
|
160
171
|
// if already playing, don't play again
|
|
161
172
|
if (!audio.paused) return;
|
|
162
|
-
if (playButton.style.backgroundImage.includes(customAudioButton.pauseImage)) return;
|
|
163
173
|
audio.play();
|
|
164
174
|
};
|
|
165
175
|
var handleAudioEnded = function handleAudioEnded() {
|
|
@@ -275,12 +285,12 @@ var PreviewPrompt = exports.PreviewPrompt = /*#__PURE__*/function (_Component) {
|
|
|
275
285
|
}, {
|
|
276
286
|
key: "render",
|
|
277
287
|
value: function render() {
|
|
278
|
-
var _this$
|
|
279
|
-
prompt = _this$
|
|
280
|
-
tagName = _this$
|
|
281
|
-
className = _this$
|
|
282
|
-
onClick = _this$
|
|
283
|
-
defaultClassName = _this$
|
|
288
|
+
var _this$props3 = this.props,
|
|
289
|
+
prompt = _this$props3.prompt,
|
|
290
|
+
tagName = _this$props3.tagName,
|
|
291
|
+
className = _this$props3.className,
|
|
292
|
+
onClick = _this$props3.onClick,
|
|
293
|
+
defaultClassName = _this$props3.defaultClassName;
|
|
284
294
|
// legend tag was added once with accessibility tasks, we need extra style to make it work with images alignment
|
|
285
295
|
var legendClass = tagName === 'legend' ? 'legend' : '';
|
|
286
296
|
var customClasses = "".concat(className || '', " ").concat(defaultClassName || '', " ").concat(legendClass, " ").concat(PROMPT_CLASS).trim();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview-prompt.js","names":["_react","_interopRequireWildcard","require","_styles","_propTypes","_interopRequireDefault","color","_mathRendering","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","_typeof","has","get","set","_t","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_createForOfIteratorHelper","Symbol","iterator","Array","isArray","_unsupportedIterableToArray","length","_n","F","s","done","value","TypeError","a","u","next","_arrayLikeToArray","toString","slice","constructor","name","from","test","_callSuper","_getPrototypeOf2","_possibleConstructorReturn2","_isNativeReflectConstruct","Reflect","construct","apply","Boolean","prototype","valueOf","StyledPromptContainer","styled","_ref","theme","tagName","borderCollapse","borderStyle","borderColor","tableGrid","backgroundColor","tableStripe","padding","textAlign","verticalAlign","text","width","fontSize","paddingLeft","spacing","paddingBottom","concat","display","flexDirection","cursor","margin","NEWLINE_BLOCK_REGEX","NEWLINE_LATEX","PROMPT_CLASS","PreviewPrompt","exports","_Component","_this","_classCallCheck2","_len","arguments","args","_key","_defineProperty2","React","createRef","customAudioButton","props","div","document","createElement","innerHTML","audio","querySelector","source","setAttribute","getAttribute","removeAttribute","appendChild","style","playButton","id","assign","height","backgroundImage","pauseImage","backgroundSize","borderRadius","border","parentNode","insertBefore","_inherits2","_createClass2","key","addCustomAudioButtonControls","_this$props","autoplayAudioEnabled","getElementById","play","then","addEventListener","handleAudioEnded","error","console","handlePlayClick","paused","includes","playImage","handleAudioPlay","handleAudioPause","_handlePlayClick","_handleAudioPlay","_handleAudioPause","_handleAudioEnded","removeCustomAudioButtonListeners","removeEventListener","componentDidMount","alignImages","setupMathRendering","componentDidUpdate","prevProps","prompt","renderMathContent","componentWillUnmount","container","promptRef","current","renderMath","previewPrompt","images","getElementsByTagName","_iterator","_step","image","attributes","alignment","justifyContent","parentElement","copyImage","cloneNode","replaceChild","err","render","_this$props2","className","onClick","defaultClassName","legendClass","customClasses","trim","as","ref","dangerouslySetInnerHTML","__html","parsedText","replace","Component","PropTypes","string","func","bool","_default"],"sources":["../src/preview-prompt.jsx"],"sourcesContent":["import React, { Component } from 'react';\nimport { styled } from '@mui/material/styles';\nimport PropTypes from 'prop-types';\nimport * as color from './color';\nimport { renderMath } from '@pie-lib/math-rendering';\n\nconst StyledPromptContainer = styled('div')(({ theme, tagName }) => ({\n // presentation tables should not have any custom style\n // Base promptTable styles\n '&:not(.MathJax) > table:not([role=\"presentation\"])': {\n borderCollapse: 'collapse',\n },\n /*\n * The editor writes border=\"1\", and the UA answers it with `border-style: outset`\n * on the table and `inset` on the cells -- which browsers paint as synthesized 3D\n * shades rather than the colour the border resolves to, so the grid comes out grey\n * on every scheme (1.19:1 on black-on-violet). `solid` is what removes the\n * shading; without it, setting the colour has no effect.\n */\n '&:not(.MathJax) table[border]:not([role=\"presentation\"]), &:not(.MathJax) table[border]:not([role=\"presentation\"]) td, &:not(.MathJax) table[border]:not([role=\"presentation\"]) th':\n {\n borderStyle: 'solid',\n borderColor: color.tableGrid(),\n },\n // Apply vertical striping when first column is a header (th) and NOT mixed with td.\n // Ink stays at 5.44:1 or better on tableStripe in every scheme, so the cell inherits\n // its text colour rather than pinning the `color: black` this used to carry.\n '&:not(.MathJax) > table:not([role=\"presentation\"]):has(tbody tr > th:first-child):not(:has(tbody tr > td:first-child)) tbody td:nth-child(even)':\n {\n backgroundColor: color.tableStripe(),\n },\n // Apply horizontal striping for tables where first element is a data cell (td)\n '&:not(.MathJax) > table:not([role=\"presentation\"]):has(tbody tr > td:first-child) tbody tr:nth-child(even) td': {\n backgroundColor: color.tableStripe(),\n },\n // align table content to left as per STAR requirement PD-3687\n '&:not(.MathJax) table:not([role=\"presentation\"]) td, &:not(.MathJax) table:not([role=\"presentation\"]) th': {\n padding: '.6em 1em',\n textAlign: 'left',\n },\n // added this to fix alignment of text in prompt imported from studio (PD-3423)\n '&:not(.MathJax) > table td > p.kds-indent': {\n textAlign: 'initial',\n },\n\n // Conditional styles based on class names\n '&.prompt': {\n verticalAlign: 'middle',\n color: color.text(),\n },\n '&.legend': {\n width: '100%',\n fontSize: 'inherit !important',\n },\n '&.rationale': {\n paddingLeft: theme.spacing(4),\n paddingBottom: theme.spacing(1),\n },\n '&.prompt-label': {\n color: `${color.text()} !important`,\n display: 'flex',\n flexDirection: 'column',\n verticalAlign: 'middle',\n cursor: 'pointer',\n '& > p': {\n margin: '0 0 0 0 !important',\n },\n },\n}));\n\n//Used these below to replace \\\\embed{newLine} with \\\\newline from prompt which will get parsed in MathJax\nconst NEWLINE_BLOCK_REGEX = /\\\\embed\\{newLine\\}\\[\\]/g;\nconst NEWLINE_LATEX = '\\\\newline ';\n\n// stable hook for 'is this node inside a prompt' checks - a class rather than an id,\n// so it stays valid when a page renders more than one prompt\nconst PROMPT_CLASS = 'preview-prompt';\n\nexport class PreviewPrompt extends Component {\n static propTypes = {\n prompt: PropTypes.string,\n tagName: PropTypes.string,\n className: PropTypes.string,\n onClick: PropTypes.func,\n defaultClassName: PropTypes.string,\n autoplayAudioEnabled: PropTypes.bool,\n customAudioButton: {\n playImage: PropTypes.string,\n pauseImage: PropTypes.string,\n },\n };\n\n static defaultProps = {\n onClick: () => {},\n };\n\n promptRef = React.createRef();\n\n parsedText = (text) => {\n const { customAudioButton } = this.props;\n const div = document.createElement('div');\n div.innerHTML = text;\n\n const audio = div.querySelector('audio');\n if (audio) {\n const source = document.createElement('source');\n\n source.setAttribute('type', 'audio/mp3');\n source.setAttribute('src', audio.getAttribute('src'));\n\n audio.removeAttribute('src');\n audio.setAttribute('id', 'pie-prompt-audio-player');\n\n audio.appendChild(source);\n\n if (customAudioButton) {\n audio.style.display = 'none';\n\n const playButton = document.createElement('div');\n playButton.id = 'play-audio-button';\n\n Object.assign(playButton.style, {\n cursor: 'pointer',\n display: 'block',\n width: '128px',\n height: '128px',\n backgroundImage: `url(${customAudioButton.pauseImage})`,\n backgroundSize: 'cover',\n borderRadius: '50%',\n border: '1px solid #326295',\n });\n\n audio.parentNode.insertBefore(playButton, audio);\n }\n }\n\n return div.innerHTML;\n };\n\n addCustomAudioButtonControls() {\n const { autoplayAudioEnabled, customAudioButton } = this.props;\n const playButton = document.getElementById('play-audio-button');\n const audio = document.getElementById('pie-prompt-audio-player');\n\n if (autoplayAudioEnabled && audio) {\n audio\n .play()\n .then(() => {\n if (playButton && customAudioButton) {\n audio.addEventListener('ended', handleAudioEnded);\n }\n })\n .catch((error) => {\n console.error('Error playing audio', error);\n });\n }\n\n if (!playButton || !audio || !customAudioButton) return;\n\n const handlePlayClick = () => {\n // if already playing, don't play again\n if (!audio.paused) return;\n if (playButton.style.backgroundImage.includes(customAudioButton.pauseImage)) return;\n\n audio.play();\n };\n\n const handleAudioEnded = () => {\n playButton.style.backgroundImage = `url(${customAudioButton.playImage})`;\n };\n\n const handleAudioPlay = () => {\n Object.assign(playButton.style, {\n backgroundImage: `url(${customAudioButton.pauseImage})`,\n border: '1px solid #ccc',\n });\n };\n\n const handleAudioPause = () => {\n Object.assign(playButton.style, {\n backgroundImage: `url(${customAudioButton.playImage})`,\n border: '1px solid #326295',\n });\n };\n\n playButton.addEventListener('click', handlePlayClick);\n audio.addEventListener('play', handleAudioPlay);\n audio.addEventListener('pause', handleAudioPause);\n audio.addEventListener('ended', handleAudioEnded);\n\n // store event handler references so they can be removed later\n this._handlePlayClick = handlePlayClick;\n this._handleAudioPlay = handleAudioPlay;\n this._handleAudioPause = handleAudioPause;\n this._handleAudioEnded = handleAudioEnded;\n }\n\n removeCustomAudioButtonListeners() {\n const playButton = document.getElementById('play-audio-button');\n const audio = document.querySelector('audio');\n\n if (!playButton || !audio) return;\n\n // remove event listeners using stored references\n playButton.removeEventListener('click', this._handlePlayClick);\n audio.removeEventListener('play', this._handleAudioPlay);\n audio.removeEventListener('pause', this._handleAudioPause);\n audio.removeEventListener('ended', this._handleAudioEnded);\n }\n\n componentDidMount() {\n this.alignImages();\n this.addCustomAudioButtonControls();\n this.setupMathRendering();\n }\n\n componentDidUpdate(prevProps) {\n this.alignImages();\n\n if (prevProps.prompt !== this.props.prompt) {\n this.renderMathContent();\n }\n }\n\n componentWillUnmount() {\n this.removeCustomAudioButtonListeners();\n }\n\n setupMathRendering() {\n this.renderMathContent();\n }\n\n renderMathContent() {\n const container = this.promptRef.current;\n if (container && typeof renderMath === 'function') {\n renderMath(container);\n }\n }\n\n alignImages() {\n const previewPrompt = this.promptRef.current;\n\n if (!previewPrompt) {\n return;\n }\n\n const images = previewPrompt.getElementsByTagName('img');\n\n if (images && images.length) {\n for (let image of images) {\n if (image.attributes && image.attributes.alignment && image.attributes.alignment.value) {\n const alignment = image.attributes.alignment.value;\n const justifyContent =\n alignment === 'center' ? 'center' : alignment === 'right' ? 'flex-end' : 'flex-start';\n\n const parentNode = image.parentElement;\n\n if (\n parentNode.tagName === 'DIV' &&\n parentNode.style.display === 'flex' &&\n parentNode.style.width === '100%'\n ) {\n parentNode.style.justifyContent = justifyContent;\n } else {\n const div = document.createElement('div');\n div.style.display = 'flex';\n div.style.width = '100%';\n div.style.justifyContent = justifyContent;\n\n const copyImage = image.cloneNode(true);\n div.appendChild(copyImage);\n parentNode.replaceChild(div, image);\n }\n }\n }\n }\n }\n\n render() {\n const { prompt, tagName, className, onClick, defaultClassName } = this.props;\n // legend tag was added once with accessibility tasks, we need extra style to make it work with images alignment\n const legendClass = tagName === 'legend' ? 'legend' : '';\n const customClasses = `${className || ''} ${defaultClassName || ''} ${legendClass} ${PROMPT_CLASS}`.trim();\n\n return (\n <StyledPromptContainer\n as={tagName || 'div'}\n ref={this.promptRef}\n onClick={onClick}\n className={customClasses}\n tagName={tagName}\n dangerouslySetInnerHTML={{\n __html: this.parsedText(prompt || '').replace(NEWLINE_BLOCK_REGEX, NEWLINE_LATEX),\n }}\n />\n );\n }\n}\n\nexport default PreviewPrompt;\n"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,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C,CAAC;MAE1G,oBACExL,MAAA,YAAAyG,aAAA,CAAC5C,qBAAqB;QACpB4H,EAAE,EAAExH,OAAO,IAAI,KAAM;QACrByH,GAAG,EAAE,IAAI,CAAC1B,SAAU;QACpBoB,OAAO,EAAEA,OAAQ;QACjBD,SAAS,EAAEI,aAAc;QACzBtH,OAAO,EAAEA,OAAQ;QACjB0H,uBAAuB,EAAE;UACvBC,MAAM,EAAE,IAAI,CAACC,UAAU,CAACjC,MAAM,IAAI,EAAE,CAAC,CAACkC,OAAO,CAACxG,mBAAmB,EAAEC,aAAa;QAClF;MAAE,CACH,CAAC;IAEN;EAAC;AAAA,EA1NgCwG,gBAAS;AAAA,IAAA7F,gBAAA,aAA/BT,aAAa,eACL;EACjBmE,MAAM,EAAEoC,qBAAS,CAACC,MAAM;EACxBhI,OAAO,EAAE+H,qBAAS,CAACC,MAAM;EACzBd,SAAS,EAAEa,qBAAS,CAACC,MAAM;EAC3Bb,OAAO,EAAEY,qBAAS,CAACE,IAAI;EACvBb,gBAAgB,EAAEW,qBAAS,CAACC,MAAM;EAClC9D,oBAAoB,EAAE6D,qBAAS,CAACG,IAAI;EACpC9F,iBAAiB,EAAE;IACjByC,SAAS,EAAEkD,qBAAS,CAACC,MAAM;IAC3BzE,UAAU,EAAEwE,qBAAS,CAACC;EACxB;AACF,CAAC;AAAA,IAAA/F,gBAAA,aAZUT,aAAa,kBAcF;EACpB2F,OAAO,EAAE,SAATA,OAAOA,CAAA,EAAQ,CAAC;AAClB,CAAC;AAAA,IAAAgB,QAAA,GAAA1G,OAAA,cA6MYD,aAAa","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"preview-prompt.js","names":["_react","_interopRequireWildcard","require","_styles","_propTypes","_interopRequireDefault","color","_mathRendering","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","_typeof","has","get","set","_t","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_createForOfIteratorHelper","Symbol","iterator","Array","isArray","_unsupportedIterableToArray","length","_n","F","s","done","value","TypeError","a","u","next","_arrayLikeToArray","toString","slice","constructor","name","from","test","_callSuper","_getPrototypeOf2","_possibleConstructorReturn2","_isNativeReflectConstruct","Reflect","construct","apply","Boolean","prototype","valueOf","StyledPromptContainer","styled","_ref","theme","tagName","borderCollapse","borderStyle","borderColor","tableGrid","backgroundColor","tableStripe","padding","textAlign","verticalAlign","text","width","fontSize","paddingLeft","spacing","paddingBottom","concat","display","flexDirection","cursor","margin","NEWLINE_BLOCK_REGEX","NEWLINE_LATEX","PROMPT_CLASS","PreviewPrompt","exports","_Component","_this","_classCallCheck2","_len","arguments","args","_key","_defineProperty2","React","createRef","_this$props","props","autoplayAudioEnabled","customAudioButton","div","document","createElement","innerHTML","audio","querySelector","source","setAttribute","getAttribute","removeAttribute","appendChild","style","playButton","id","assign","height","backgroundImage","pauseImage","playImage","backgroundSize","borderRadius","border","parentNode","insertBefore","_inherits2","_createClass2","key","addCustomAudioButtonControls","_this$props2","getElementById","play","then","addEventListener","handleAudioEnded","error","console","handlePlayClick","paused","handleAudioPlay","handleAudioPause","_handlePlayClick","_handleAudioPlay","_handleAudioPause","_handleAudioEnded","removeCustomAudioButtonListeners","removeEventListener","componentDidMount","alignImages","setupMathRendering","componentDidUpdate","prevProps","prompt","renderMathContent","componentWillUnmount","container","promptRef","current","renderMath","previewPrompt","images","getElementsByTagName","_iterator","_step","image","attributes","alignment","justifyContent","parentElement","copyImage","cloneNode","replaceChild","err","render","_this$props3","className","onClick","defaultClassName","legendClass","customClasses","trim","as","ref","dangerouslySetInnerHTML","__html","parsedText","replace","Component","PropTypes","string","func","bool","_default"],"sources":["../src/preview-prompt.jsx"],"sourcesContent":["import React, { Component } from 'react';\nimport { styled } from '@mui/material/styles';\nimport PropTypes from 'prop-types';\nimport * as color from './color';\nimport { renderMath } from '@pie-lib/math-rendering';\n\nconst StyledPromptContainer = styled('div')(({ theme, tagName }) => ({\n // presentation tables should not have any custom style\n // Base promptTable styles\n '&:not(.MathJax) > table:not([role=\"presentation\"])': {\n borderCollapse: 'collapse',\n },\n /*\n * The editor writes border=\"1\", and the UA answers it with `border-style: outset`\n * on the table and `inset` on the cells -- which browsers paint as synthesized 3D\n * shades rather than the colour the border resolves to, so the grid comes out grey\n * on every scheme (1.19:1 on black-on-violet). `solid` is what removes the\n * shading; without it, setting the colour has no effect.\n */\n '&:not(.MathJax) table[border]:not([role=\"presentation\"]), &:not(.MathJax) table[border]:not([role=\"presentation\"]) td, &:not(.MathJax) table[border]:not([role=\"presentation\"]) th':\n {\n borderStyle: 'solid',\n borderColor: color.tableGrid(),\n },\n // Apply vertical striping when first column is a header (th) and NOT mixed with td.\n // Ink stays at 5.44:1 or better on tableStripe in every scheme, so the cell inherits\n // its text colour rather than pinning the `color: black` this used to carry.\n '&:not(.MathJax) > table:not([role=\"presentation\"]):has(tbody tr > th:first-child):not(:has(tbody tr > td:first-child)) tbody td:nth-child(even)':\n {\n backgroundColor: color.tableStripe(),\n },\n // Apply horizontal striping for tables where first element is a data cell (td)\n '&:not(.MathJax) > table:not([role=\"presentation\"]):has(tbody tr > td:first-child) tbody tr:nth-child(even) td': {\n backgroundColor: color.tableStripe(),\n },\n // align table content to left as per STAR requirement PD-3687\n '&:not(.MathJax) table:not([role=\"presentation\"]) td, &:not(.MathJax) table:not([role=\"presentation\"]) th': {\n padding: '.6em 1em',\n textAlign: 'left',\n },\n // added this to fix alignment of text in prompt imported from studio (PD-3423)\n '&:not(.MathJax) > table td > p.kds-indent': {\n textAlign: 'initial',\n },\n\n // Conditional styles based on class names\n '&.prompt': {\n verticalAlign: 'middle',\n color: color.text(),\n },\n '&.legend': {\n width: '100%',\n fontSize: 'inherit !important',\n },\n '&.rationale': {\n paddingLeft: theme.spacing(4),\n paddingBottom: theme.spacing(1),\n },\n '&.prompt-label': {\n color: `${color.text()} !important`,\n display: 'flex',\n flexDirection: 'column',\n verticalAlign: 'middle',\n cursor: 'pointer',\n '& > p': {\n margin: '0 0 0 0 !important',\n },\n },\n}));\n\n//Used these below to replace \\\\embed{newLine} with \\\\newline from prompt which will get parsed in MathJax\nconst NEWLINE_BLOCK_REGEX = /\\\\embed\\{newLine\\}\\[\\]/g;\nconst NEWLINE_LATEX = '\\\\newline ';\n\n// stable hook for 'is this node inside a prompt' checks - a class rather than an id,\n// so it stays valid when a page renders more than one prompt\nconst PROMPT_CLASS = 'preview-prompt';\n\nexport class PreviewPrompt extends Component {\n static propTypes = {\n prompt: PropTypes.string,\n tagName: PropTypes.string,\n className: PropTypes.string,\n onClick: PropTypes.func,\n defaultClassName: PropTypes.string,\n autoplayAudioEnabled: PropTypes.bool,\n customAudioButton: {\n playImage: PropTypes.string,\n pauseImage: PropTypes.string,\n },\n };\n\n static defaultProps = {\n onClick: () => {},\n };\n\n promptRef = React.createRef();\n\n parsedText = (text) => {\n const { autoplayAudioEnabled, customAudioButton } = this.props;\n const div = document.createElement('div');\n div.innerHTML = text;\n\n const audio = div.querySelector('audio');\n if (audio) {\n const source = document.createElement('source');\n\n source.setAttribute('type', 'audio/mp3');\n source.setAttribute('src', audio.getAttribute('src'));\n\n audio.removeAttribute('src');\n audio.setAttribute('id', 'pie-prompt-audio-player');\n\n audio.appendChild(source);\n\n if (customAudioButton) {\n audio.style.display = 'none';\n\n const playButton = document.createElement('div');\n playButton.id = 'play-audio-button';\n\n Object.assign(playButton.style, {\n cursor: 'pointer',\n display: 'block',\n width: '128px',\n height: '128px',\n // pauseImage is the playing state. Only autoplay starts in it - with\n // autoplay off the audio is paused, so the button has to show\n // playImage or it advertises a state the audio is not in.\n backgroundImage: `url(${autoplayAudioEnabled ? customAudioButton.pauseImage : customAudioButton.playImage})`,\n backgroundSize: 'cover',\n borderRadius: '50%',\n border: '1px solid #326295',\n });\n\n audio.parentNode.insertBefore(playButton, audio);\n }\n }\n\n return div.innerHTML;\n };\n\n addCustomAudioButtonControls() {\n const { autoplayAudioEnabled, customAudioButton } = this.props;\n const playButton = document.getElementById('play-audio-button');\n const audio = document.getElementById('pie-prompt-audio-player');\n\n if (autoplayAudioEnabled && audio) {\n audio\n .play()\n .then(() => {\n if (playButton && customAudioButton) {\n audio.addEventListener('ended', handleAudioEnded);\n }\n })\n .catch((error) => {\n // Autoplay blocked (Safari/Firefox until the page has been\n // interacted with). The audio is paused, so drop the button back to\n // the idle image - clicking it is now the only way to start.\n if (playButton && customAudioButton) {\n playButton.style.backgroundImage = `url(${customAudioButton.playImage})`;\n }\n console.error('Error playing audio', error);\n });\n }\n\n if (!playButton || !audio || !customAudioButton) return;\n\n const handlePlayClick = () => {\n // if already playing, don't play again\n if (!audio.paused) return;\n\n audio.play();\n };\n\n const handleAudioEnded = () => {\n playButton.style.backgroundImage = `url(${customAudioButton.playImage})`;\n };\n\n const handleAudioPlay = () => {\n Object.assign(playButton.style, {\n backgroundImage: `url(${customAudioButton.pauseImage})`,\n border: '1px solid #ccc',\n });\n };\n\n const handleAudioPause = () => {\n Object.assign(playButton.style, {\n backgroundImage: `url(${customAudioButton.playImage})`,\n border: '1px solid #326295',\n });\n };\n\n playButton.addEventListener('click', handlePlayClick);\n audio.addEventListener('play', handleAudioPlay);\n audio.addEventListener('pause', handleAudioPause);\n audio.addEventListener('ended', handleAudioEnded);\n\n // store event handler references so they can be removed later\n this._handlePlayClick = handlePlayClick;\n this._handleAudioPlay = handleAudioPlay;\n this._handleAudioPause = handleAudioPause;\n this._handleAudioEnded = handleAudioEnded;\n }\n\n removeCustomAudioButtonListeners() {\n const playButton = document.getElementById('play-audio-button');\n const audio = document.querySelector('audio');\n\n if (!playButton || !audio) return;\n\n // remove event listeners using stored references\n playButton.removeEventListener('click', this._handlePlayClick);\n audio.removeEventListener('play', this._handleAudioPlay);\n audio.removeEventListener('pause', this._handleAudioPause);\n audio.removeEventListener('ended', this._handleAudioEnded);\n }\n\n componentDidMount() {\n this.alignImages();\n this.addCustomAudioButtonControls();\n this.setupMathRendering();\n }\n\n componentDidUpdate(prevProps) {\n this.alignImages();\n\n if (prevProps.prompt !== this.props.prompt) {\n this.renderMathContent();\n }\n }\n\n componentWillUnmount() {\n this.removeCustomAudioButtonListeners();\n }\n\n setupMathRendering() {\n this.renderMathContent();\n }\n\n renderMathContent() {\n const container = this.promptRef.current;\n if (container && typeof renderMath === 'function') {\n renderMath(container);\n }\n }\n\n alignImages() {\n const previewPrompt = this.promptRef.current;\n\n if (!previewPrompt) {\n return;\n }\n\n const images = previewPrompt.getElementsByTagName('img');\n\n if (images && images.length) {\n for (let image of images) {\n if (image.attributes && image.attributes.alignment && image.attributes.alignment.value) {\n const alignment = image.attributes.alignment.value;\n const justifyContent =\n alignment === 'center' ? 'center' : alignment === 'right' ? 'flex-end' : 'flex-start';\n\n const parentNode = image.parentElement;\n\n if (\n parentNode.tagName === 'DIV' &&\n parentNode.style.display === 'flex' &&\n parentNode.style.width === '100%'\n ) {\n parentNode.style.justifyContent = justifyContent;\n } else {\n const div = document.createElement('div');\n div.style.display = 'flex';\n div.style.width = '100%';\n div.style.justifyContent = justifyContent;\n\n const copyImage = image.cloneNode(true);\n div.appendChild(copyImage);\n parentNode.replaceChild(div, image);\n }\n }\n }\n }\n }\n\n render() {\n const { prompt, tagName, className, onClick, defaultClassName } = this.props;\n // legend tag was added once with accessibility tasks, we need extra style to make it work with images alignment\n const legendClass = tagName === 'legend' ? 'legend' : '';\n const customClasses = `${className || ''} ${defaultClassName || ''} ${legendClass} ${PROMPT_CLASS}`.trim();\n\n return (\n <StyledPromptContainer\n as={tagName || 'div'}\n ref={this.promptRef}\n onClick={onClick}\n className={customClasses}\n tagName={tagName}\n dangerouslySetInnerHTML={{\n __html: this.parsedText(prompt || '').replace(NEWLINE_BLOCK_REGEX, NEWLINE_LATEX),\n }}\n />\n );\n }\n}\n\nexport default PreviewPrompt;\n"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,KAAA,GAAA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2
|
"name": "@pie-lib/render-ui",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.3",
|
|
4
4
|
"description": "Some shared ui elements when rendering - but not worthy of their own package yet.",
|
|
5
5
|
"module": "src/index.js",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"@emotion/styled": "^11.14.1",
|
|
15
15
|
"@mui/icons-material": "^7.3.4",
|
|
16
16
|
"@mui/material": "^7.3.4",
|
|
17
|
-
"@pie-lib/icons": "^4.0.
|
|
17
|
+
"@pie-lib/icons": "^4.0.4",
|
|
18
18
|
"@pie-lib/math-rendering": "^5.1.0",
|
|
19
|
-
"@pie-lib/test-utils": "^2.0.
|
|
19
|
+
"@pie-lib/test-utils": "^2.0.3",
|
|
20
20
|
"debug": "^4.1.1",
|
|
21
21
|
"lodash-es": "^4.17.23",
|
|
22
22
|
"prop-types": "^15.7.2",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"react": "^18.2.0",
|
|
32
32
|
"react-dom": "^18.2.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "555178e597d60d604dcc8b77cbb86dfde7b86b4f"
|
|
35
35
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
3
3
|
import userEvent from '@testing-library/user-event';
|
|
4
4
|
import PreviewPrompt from '../preview-prompt';
|
|
5
5
|
import * as color from '../color';
|
|
@@ -224,6 +224,115 @@ describe('PreviewPrompt - Extended Tests', () => {
|
|
|
224
224
|
});
|
|
225
225
|
});
|
|
226
226
|
|
|
227
|
+
// playImage is the idle state, pauseImage the playing one. The button has to
|
|
228
|
+
// start in the state the audio is actually in: it used to always start on
|
|
229
|
+
// pauseImage, and the click handler read that image back as "already
|
|
230
|
+
// playing", so with autoplay off every click was silently swallowed.
|
|
231
|
+
describe('custom audio button playback', () => {
|
|
232
|
+
const customAudioButton = { playImage: 'play.png', pauseImage: 'pause.png' };
|
|
233
|
+
const promptWithAudio = '<audio src="test.mp3"></audio>';
|
|
234
|
+
|
|
235
|
+
let play;
|
|
236
|
+
let paused;
|
|
237
|
+
|
|
238
|
+
const stubPlayback = (impl) => {
|
|
239
|
+
play = jest.fn(impl);
|
|
240
|
+
// jsdom does not implement playback, and the component reads `paused`
|
|
241
|
+
// alongside calling `play()`, so both are driven by hand here.
|
|
242
|
+
Object.defineProperty(HTMLMediaElement.prototype, 'play', {
|
|
243
|
+
configurable: true,
|
|
244
|
+
writable: true,
|
|
245
|
+
value: play,
|
|
246
|
+
});
|
|
247
|
+
Object.defineProperty(HTMLMediaElement.prototype, 'paused', {
|
|
248
|
+
configurable: true,
|
|
249
|
+
get: () => paused,
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const renderPrompt = (autoplayAudioEnabled) => {
|
|
254
|
+
render(
|
|
255
|
+
<PreviewPrompt
|
|
256
|
+
prompt={promptWithAudio}
|
|
257
|
+
autoplayAudioEnabled={autoplayAudioEnabled}
|
|
258
|
+
customAudioButton={customAudioButton}
|
|
259
|
+
/>,
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
return document.getElementById('play-audio-button');
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
beforeEach(() => {
|
|
266
|
+
paused = true;
|
|
267
|
+
stubPlayback(() => Promise.resolve());
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('should start on the idle image when autoplay is off', () => {
|
|
271
|
+
const playButton = renderPrompt(false);
|
|
272
|
+
|
|
273
|
+
expect(playButton.style.backgroundImage).toContain(customAudioButton.playImage);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it('should play when clicked with autoplay off', () => {
|
|
277
|
+
const playButton = renderPrompt(false);
|
|
278
|
+
|
|
279
|
+
fireEvent.click(playButton);
|
|
280
|
+
|
|
281
|
+
expect(play).toHaveBeenCalledTimes(1);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
// No controller defaults `autoplayAudioEnabled`, so an item that does not
|
|
285
|
+
// set it reaches delivery as undefined. The initial image tracks whether
|
|
286
|
+
// play() is called - a truthy check - not whether the author opted out.
|
|
287
|
+
it('should start on the idle image and stay clickable when autoplay is unset', () => {
|
|
288
|
+
const playButton = renderPrompt(undefined);
|
|
289
|
+
|
|
290
|
+
expect(playButton.style.backgroundImage).toContain(customAudioButton.playImage);
|
|
291
|
+
expect(play).not.toHaveBeenCalled();
|
|
292
|
+
|
|
293
|
+
fireEvent.click(playButton);
|
|
294
|
+
|
|
295
|
+
expect(play).toHaveBeenCalledTimes(1);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it('should start on the playing image and autoplay when autoplay is on', () => {
|
|
299
|
+
const playButton = renderPrompt(true);
|
|
300
|
+
|
|
301
|
+
expect(playButton.style.backgroundImage).toContain(customAudioButton.pauseImage);
|
|
302
|
+
expect(play).toHaveBeenCalledTimes(1);
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it('should ignore a click while the audio is already playing', () => {
|
|
306
|
+
const playButton = renderPrompt(false);
|
|
307
|
+
paused = false;
|
|
308
|
+
|
|
309
|
+
fireEvent.click(playButton);
|
|
310
|
+
|
|
311
|
+
expect(play).not.toHaveBeenCalled();
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it('should fall back to the idle image and stay clickable when autoplay is blocked', async () => {
|
|
315
|
+
// Only the autoplay attempt is blocked; the click that follows is a user
|
|
316
|
+
// gesture, so the browser allows it.
|
|
317
|
+
let attempts = 0;
|
|
318
|
+
stubPlayback(() => {
|
|
319
|
+
attempts += 1;
|
|
320
|
+
return attempts === 1 ? Promise.reject(new Error('NotAllowedError')) : Promise.resolve();
|
|
321
|
+
});
|
|
322
|
+
jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
323
|
+
|
|
324
|
+
const playButton = renderPrompt(true);
|
|
325
|
+
|
|
326
|
+
await waitFor(() => {
|
|
327
|
+
expect(playButton.style.backgroundImage).toContain(customAudioButton.playImage);
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
fireEvent.click(playButton);
|
|
331
|
+
|
|
332
|
+
expect(play).toHaveBeenCalledTimes(2);
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
|
|
227
336
|
describe('image alignment', () => {
|
|
228
337
|
it('should align images with alignment attribute', () => {
|
|
229
338
|
const promptWithImage = '<img src="test.jpg" alignment="center" />';
|
package/src/preview-prompt.jsx
CHANGED
|
@@ -97,7 +97,7 @@ export class PreviewPrompt extends Component {
|
|
|
97
97
|
promptRef = React.createRef();
|
|
98
98
|
|
|
99
99
|
parsedText = (text) => {
|
|
100
|
-
const { customAudioButton } = this.props;
|
|
100
|
+
const { autoplayAudioEnabled, customAudioButton } = this.props;
|
|
101
101
|
const div = document.createElement('div');
|
|
102
102
|
div.innerHTML = text;
|
|
103
103
|
|
|
@@ -124,7 +124,10 @@ export class PreviewPrompt extends Component {
|
|
|
124
124
|
display: 'block',
|
|
125
125
|
width: '128px',
|
|
126
126
|
height: '128px',
|
|
127
|
-
|
|
127
|
+
// pauseImage is the playing state. Only autoplay starts in it - with
|
|
128
|
+
// autoplay off the audio is paused, so the button has to show
|
|
129
|
+
// playImage or it advertises a state the audio is not in.
|
|
130
|
+
backgroundImage: `url(${autoplayAudioEnabled ? customAudioButton.pauseImage : customAudioButton.playImage})`,
|
|
128
131
|
backgroundSize: 'cover',
|
|
129
132
|
borderRadius: '50%',
|
|
130
133
|
border: '1px solid #326295',
|
|
@@ -151,6 +154,12 @@ export class PreviewPrompt extends Component {
|
|
|
151
154
|
}
|
|
152
155
|
})
|
|
153
156
|
.catch((error) => {
|
|
157
|
+
// Autoplay blocked (Safari/Firefox until the page has been
|
|
158
|
+
// interacted with). The audio is paused, so drop the button back to
|
|
159
|
+
// the idle image - clicking it is now the only way to start.
|
|
160
|
+
if (playButton && customAudioButton) {
|
|
161
|
+
playButton.style.backgroundImage = `url(${customAudioButton.playImage})`;
|
|
162
|
+
}
|
|
154
163
|
console.error('Error playing audio', error);
|
|
155
164
|
});
|
|
156
165
|
}
|
|
@@ -160,7 +169,6 @@ export class PreviewPrompt extends Component {
|
|
|
160
169
|
const handlePlayClick = () => {
|
|
161
170
|
// if already playing, don't play again
|
|
162
171
|
if (!audio.paused) return;
|
|
163
|
-
if (playButton.style.backgroundImage.includes(customAudioButton.pauseImage)) return;
|
|
164
172
|
|
|
165
173
|
audio.play();
|
|
166
174
|
};
|