@pie-lib/render-ui 4.12.1-next.546 → 4.12.1-next.590
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/lib/preview-prompt.js +43 -12
- package/lib/preview-prompt.js.map +1 -1
- package/package.json +2 -2
- package/src/preview-prompt.jsx +31 -11
package/lib/preview-prompt.js
CHANGED
|
@@ -35,6 +35,12 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
35
35
|
|
|
36
36
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
37
37
|
|
|
38
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
39
|
+
|
|
40
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
41
|
+
|
|
42
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
43
|
+
|
|
38
44
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
39
45
|
|
|
40
46
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
@@ -78,19 +84,44 @@ var PreviewPrompt = /*#__PURE__*/function (_Component) {
|
|
|
78
84
|
}
|
|
79
85
|
|
|
80
86
|
(0, _createClass2["default"])(PreviewPrompt, [{
|
|
87
|
+
key: "componentDidUpdate",
|
|
88
|
+
value: function componentDidUpdate() {
|
|
89
|
+
// set image parent style so it can be horizontally aligned
|
|
90
|
+
var previewPrompt = document.querySelector('#preview-prompt');
|
|
91
|
+
var images = previewPrompt && previewPrompt.getElementsByTagName('img');
|
|
92
|
+
|
|
93
|
+
if (images && images.length) {
|
|
94
|
+
var _iterator = _createForOfIteratorHelper(images),
|
|
95
|
+
_step;
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
99
|
+
var image = _step.value;
|
|
100
|
+
|
|
101
|
+
// check if alignment property was set
|
|
102
|
+
if (image.attributes && image.attributes.alignment && image.attributes.alignment.value) {
|
|
103
|
+
var parentNode = image.parentElement; // check if div is not already added to dom and replace current image with wrapped image
|
|
104
|
+
|
|
105
|
+
if (!(parentNode.tagName === 'DIV' && parentNode.style.display === 'flex' && parentNode.style.width === '100%')) {
|
|
106
|
+
var div = document.createElement('div');
|
|
107
|
+
div.style.display = 'flex';
|
|
108
|
+
div.style.width = '100%';
|
|
109
|
+
var copyImage = image.cloneNode(true);
|
|
110
|
+
div.appendChild(copyImage);
|
|
111
|
+
parentNode.replaceChild(div, image);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
} catch (err) {
|
|
116
|
+
_iterator.e(err);
|
|
117
|
+
} finally {
|
|
118
|
+
_iterator.f();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}, {
|
|
81
123
|
key: "render",
|
|
82
|
-
value:
|
|
83
|
-
// // set image parent style so it can be horizontally aligned
|
|
84
|
-
// const previewPrompt = document.querySelector('#preview-prompt');
|
|
85
|
-
// const images = previewPrompt && previewPrompt.getElementsByTagName('img');
|
|
86
|
-
//
|
|
87
|
-
// if (images && images.length) {
|
|
88
|
-
// for (let image of images) {
|
|
89
|
-
// image.parentElement.style.display = 'flex';
|
|
90
|
-
// }
|
|
91
|
-
// }
|
|
92
|
-
// }
|
|
93
|
-
function render() {
|
|
124
|
+
value: function render() {
|
|
94
125
|
var _this$props = this.props,
|
|
95
126
|
prompt = _this$props.prompt,
|
|
96
127
|
classes = _this$props.classes,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview-prompt.js","names":["NEWLINE_BLOCK_REGEX","NEWLINE_LATEX","PreviewPrompt","text","div","document","createElement","innerHTML","audio","querySelector","source","setAttribute","getAttribute","removeAttribute","appendChild","
|
|
1
|
+
{"version":3,"file":"preview-prompt.js","names":["NEWLINE_BLOCK_REGEX","NEWLINE_LATEX","PreviewPrompt","text","div","document","createElement","innerHTML","audio","querySelector","source","setAttribute","getAttribute","removeAttribute","appendChild","previewPrompt","images","getElementsByTagName","length","image","attributes","alignment","value","parentNode","parentElement","tagName","style","display","width","copyImage","cloneNode","replaceChild","props","prompt","classes","className","onClick","defaultClassName","CustomTag","customClasses","promptTable","__html","parsedText","replace","Component","PropTypes","object","string","func","styles","theme","verticalAlign","color","rationale","paddingLeft","spacing","unit","label","cursor","borderCollapse","backgroundColor","padding","textAlign","withStyles"],"sources":["../src/preview-prompt.jsx"],"sourcesContent":["import React, { Component } from 'react';\nimport { withStyles } from '@material-ui/core/styles';\nimport PropTypes from 'prop-types';\nimport * as color from './color';\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\nexport class PreviewPrompt extends Component {\n static propTypes = {\n classes: PropTypes.object,\n prompt: PropTypes.string,\n tagName: PropTypes.string,\n className: PropTypes.string,\n onClick: PropTypes.func,\n defaultClassName: PropTypes.string\n };\n\n static defaultProps = {\n onClick: () => {}\n };\n\n parsedText = text => {\n // fix imported audio content for Safari PD-1419\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.appendChild(source);\n }\n\n return div.innerHTML;\n };\n\n componentDidUpdate() {\n // set image parent style so it can be horizontally aligned\n const previewPrompt = document.querySelector('#preview-prompt');\n const images = previewPrompt && previewPrompt.getElementsByTagName('img');\n\n if (images && images.length) {\n for (let image of images) {\n // check if alignment property was set\n if (image.attributes && image.attributes.alignment && image.attributes.alignment.value) {\n const parentNode = image.parentElement;\n\n // check if div is not already added to dom and replace current image with wrapped image\n if (\n !(\n parentNode.tagName === 'DIV' &&\n parentNode.style.display === 'flex' &&\n parentNode.style.width === '100%'\n )\n ) {\n const div = document.createElement('div');\n div.style.display = 'flex';\n div.style.width = '100%';\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, classes, tagName, className, onClick, defaultClassName } = this.props;\n const CustomTag = tagName || 'div';\n const customClasses = `${classes.promptTable} ${classes[className] || ''} ${defaultClassName ||\n ''}`;\n\n return (\n <CustomTag\n id={'preview-prompt'}\n onClick={onClick}\n className={customClasses}\n dangerouslySetInnerHTML={{\n __html: this.parsedText(prompt || '').replace(NEWLINE_BLOCK_REGEX, NEWLINE_LATEX)\n }}\n />\n );\n }\n}\n\nconst styles = theme => ({\n prompt: {\n verticalAlign: 'middle',\n color: color.text()\n },\n rationale: {\n paddingLeft: theme.spacing.unit * 16\n },\n label: {\n color: `${color.text()} !important`, //'var(--choice-input-color, black)',\n display: 'inline-block',\n verticalAlign: 'middle',\n cursor: 'pointer'\n },\n promptTable: {\n '&:not(.MathJax) > table': {\n borderCollapse: 'collapse'\n },\n '&:not(.MathJax) > table tr': {\n '&:nth-child(2n)': {\n backgroundColor: '#f6f8fa'\n }\n },\n '&:not(.MathJax) > table td, &:not(.MathJax) > table th': {\n padding: '.6em 1em',\n textAlign: 'center'\n }\n }\n});\nexport default withStyles(styles)(PreviewPrompt);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;AAEA;AACA,IAAMA,mBAAmB,GAAG,yBAA5B;AACA,IAAMC,aAAa,GAAG,YAAtB;;IAEaC,a;;;;;;;;;;;;;;;mGAcE,UA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AAUE,MAHF;EAIjBZ,SAAS,EAAEU,qBAAA,CAAUE,MAJJ;EAKjBX,OAAO,EAAES,qBAAA,CAAUG,IALF;EAMjBX,gBAAgB,EAAEQ,qBAAA,CAAUE;AANX,C;iCADR7C,a,kBAUW;EACpBkC,OAAO,EAAE,mBAAM,CAAE;AADG,C;;AA0ExB,IAAMa,MAAM,GAAG,SAATA,MAAS,CAAAC,KAAK;EAAA,OAAK;IACvBjB,MAAM,EAAE;MACNkB,aAAa,EAAE,QADT;MAENC,KAAK,EAAEA,KAAK,CAACjD,IAAN;IAFD,CADe;IAKvBkD,SAAS,EAAE;MACTC,WAAW,EAAEJ,KAAK,CAACK,OAAN,CAAcC,IAAd,GAAqB;IADzB,CALY;IAQvBC,KAAK,EAAE;MACLL,KAAK,YAAKA,KAAK,CAACjD,IAAN,EAAL,gBADA;MACgC;MACrCwB,OAAO,EAAE,cAFJ;MAGLwB,aAAa,EAAE,QAHV;MAILO,MAAM,EAAE;IAJH,CARgB;IAcvBlB,WAAW,EAAE;MACX,2BAA2B;QACzBmB,cAAc,EAAE;MADS,CADhB;MAIX,8BAA8B;QAC5B,mBAAmB;UACjBC,eAAe,EAAE;QADA;MADS,CAJnB;MASX,0DAA0D;QACxDC,OAAO,EAAE,UAD+C;QAExDC,SAAS,EAAE;MAF6C;IAT/C;EAdU,CAAL;AAAA,CAApB;;eA6Be,IAAAC,kBAAA,EAAWd,MAAX,EAAmB/C,aAAnB,C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/render-ui",
|
|
3
|
-
"version": "4.12.1-next.
|
|
3
|
+
"version": "4.12.1-next.590+2ab22b4c",
|
|
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",
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"react": "^16.8.1",
|
|
27
27
|
"react-dom": "^16.8.1"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "2ab22b4c38e86bb4bb40b25d708678e5fb0f67d4"
|
|
30
30
|
}
|
package/src/preview-prompt.jsx
CHANGED
|
@@ -40,17 +40,37 @@ export class PreviewPrompt extends Component {
|
|
|
40
40
|
return div.innerHTML;
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
43
|
+
componentDidUpdate() {
|
|
44
|
+
// set image parent style so it can be horizontally aligned
|
|
45
|
+
const previewPrompt = document.querySelector('#preview-prompt');
|
|
46
|
+
const images = previewPrompt && previewPrompt.getElementsByTagName('img');
|
|
47
|
+
|
|
48
|
+
if (images && images.length) {
|
|
49
|
+
for (let image of images) {
|
|
50
|
+
// check if alignment property was set
|
|
51
|
+
if (image.attributes && image.attributes.alignment && image.attributes.alignment.value) {
|
|
52
|
+
const parentNode = image.parentElement;
|
|
53
|
+
|
|
54
|
+
// check if div is not already added to dom and replace current image with wrapped image
|
|
55
|
+
if (
|
|
56
|
+
!(
|
|
57
|
+
parentNode.tagName === 'DIV' &&
|
|
58
|
+
parentNode.style.display === 'flex' &&
|
|
59
|
+
parentNode.style.width === '100%'
|
|
60
|
+
)
|
|
61
|
+
) {
|
|
62
|
+
const div = document.createElement('div');
|
|
63
|
+
div.style.display = 'flex';
|
|
64
|
+
div.style.width = '100%';
|
|
65
|
+
|
|
66
|
+
const copyImage = image.cloneNode(true);
|
|
67
|
+
div.appendChild(copyImage);
|
|
68
|
+
parentNode.replaceChild(div, image);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
54
74
|
|
|
55
75
|
render() {
|
|
56
76
|
const { prompt, classes, tagName, className, onClick, defaultClassName } = this.props;
|