Skip to content

Commit d66ab28

Browse files
committed
ok so i made a thing, and im pretty sure it works now
1 parent 2e43966 commit d66ab28

File tree

9 files changed

+64
-17
lines changed

9 files changed

+64
-17
lines changed

src/components/monitor/default-monitor.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import styles from './monitor.css';
4+
import DOMElementRenderer from '../../containers/dom-element-renderer.jsx';
45

5-
const DefaultMonitor = ({categoryColor, label, value}) => (
6+
const DefaultMonitor = ({categoryColor, label, value, isHTML}) => (
67
<div className={styles.defaultMonitor}>
78
<div className={styles.row}>
89
<div className={styles.label}>
@@ -12,7 +13,9 @@ const DefaultMonitor = ({categoryColor, label, value}) => (
1213
className={styles.value}
1314
style={{background: categoryColor}}
1415
>
15-
{value}
16+
{isHTML
17+
? (<DOMElementRenderer domElement={value} />)
18+
: String(value)}
1619
</div>
1720
</div>
1821
</div>
@@ -21,6 +24,7 @@ const DefaultMonitor = ({categoryColor, label, value}) => (
2124
DefaultMonitor.propTypes = {
2225
categoryColor: PropTypes.string.isRequired,
2326
label: PropTypes.string.isRequired,
27+
isHTML: PropTypes.bool.isRequired,
2428
value: PropTypes.oneOfType([
2529
PropTypes.string,
2630
PropTypes.number

src/components/monitor/large-monitor.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import styles from './monitor.css';
4+
import DOMElementRenderer from '../../containers/dom-element-renderer.jsx';
45

5-
const LargeMonitor = ({categoryColor, value}) => (
6+
const LargeMonitor = ({categoryColor, value, isHTML}) => (
67
<div className={styles.largeMonitor}>
78
<div
89
className={styles.largeValue}
910
style={{background: categoryColor}}
1011
>
11-
{value}
12+
{isHTML
13+
? (<DOMElementRenderer domElement={value} />)
14+
: String(value)}
1215
</div>
1316
</div>
1417
);
1518

1619
LargeMonitor.propTypes = {
1720
categoryColor: PropTypes.string,
21+
isHTML: PropTypes.bool.isRequired,
1822
value: PropTypes.oneOfType([
1923
PropTypes.string,
2024
PropTypes.number

src/components/monitor/list-monitor-scroller.jsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {FormattedMessage} from 'react-intl';
66

77
import styles from './monitor.css';
88
import {List} from 'react-virtualized';
9+
import DOMElementRenderer from '../../containers/dom-element-renderer.jsx';
910

1011
class ListMonitorScroller extends React.Component {
1112
constructor (props) {
@@ -31,6 +32,17 @@ class ListMonitorScroller extends React.Component {
3132
);
3233
}
3334
rowRenderer ({index, key, style}) {
35+
const item = this.props.values[index];
36+
const renderedValue = item.toListItem
37+
? item.toListItem()
38+
: item.toMonitorContent
39+
? item.toMonitorContent()
40+
: item.toReporterContent
41+
? item.toReporterContent()
42+
: item;
43+
const value = item.isHTML
44+
? (<DOMElementRenderer domElement={renderedValue} />)
45+
: String(item);
3446
return (
3547
<div
3648
className={styles.listRow}
@@ -67,7 +79,7 @@ class ListMonitorScroller extends React.Component {
6779
</div>
6880

6981
) : (
70-
<div className={styles.valueInner}>{this.props.values[index]}</div>
82+
<div className={styles.valueInner}>{value}</div>
7183
)}
7284
</div>
7385
</div>

src/components/monitor/slider-monitor.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const SliderMonitor = ({categoryColor, isDiscrete, label, min, max, value, onSli
1414
className={styles.value}
1515
style={{background: categoryColor}}
1616
>
17-
{value}
17+
{Number(value)}
1818
</div>
1919
</div>
2020
<div className={styles.row}>
@@ -24,7 +24,7 @@ const SliderMonitor = ({categoryColor, isDiscrete, label, min, max, value, onSli
2424
min={min}
2525
step={isDiscrete ? 1 : 0.01}
2626
type="range"
27-
value={value}
27+
value={Number(value)}
2828
onChange={onSliderUpdate}
2929
/>
3030
</div>

src/containers/dom-element-renderer.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class DOMElementRenderer extends React.Component {
2222
this.container.appendChild(this.props.domElement);
2323
}
2424
componentWillUnmount () {
25+
if (this.props.domElement.parentNode !== this.container.childNodes[0]) return console.error('i dont fucking know how to solve this, all i know is the site just fucking keeps dieing with this exact issue');
2526
this.container.removeChild(this.props.domElement);
2627
}
2728
setContainer (c) {

src/containers/list-monitor.jsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ class ListMonitor extends React.Component {
3636
return;
3737
}
3838

39+
let activeValue = this.props.value[index];
40+
if (activeValue.toListEditor) activeValue = activeValue.toListEditor();
41+
3942
this.setState({
4043
activeIndex: index,
41-
activeValue: this.props.value[index]
44+
activeValue,
45+
handlerClass: this.props.value[index]
4246
});
4347
}
4448

@@ -47,7 +51,12 @@ class ListMonitor extends React.Component {
4751
if (this.state.activeIndex !== null) {
4852
const {vm, targetId, id: variableId} = this.props;
4953
const newListValue = getVariableValue(vm, targetId, variableId);
50-
newListValue[this.state.activeIndex] = this.state.activeValue;
54+
const oldValue = this.props.value[this.state.activeIndex];
55+
let newValue = this.state.activeValue;
56+
if (oldValue.fromListEditor) {
57+
newValue = oldValue.fromListEditor(newValue);
58+
}
59+
newListValue[this.state.activeIndex] = newValue;
5160
setVariableValue(vm, targetId, variableId, newListValue);
5261
this.setState({activeIndex: null, activeValue: null});
5362
}

src/containers/monitor-list.jsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import bindAll from 'lodash.bindall';
22
import React from 'react';
33
import PropTypes from 'prop-types';
4-
import { injectIntl, intlShape } from 'react-intl';
4+
import {injectIntl, intlShape} from 'react-intl';
55

6-
import { connect } from 'react-redux';
7-
import { moveMonitorRect, resetMonitorLayout } from '../reducers/monitor-layout';
6+
import {connect} from 'react-redux';
7+
import {moveMonitorRect, resetMonitorLayout} from '../reducers/monitor-layout';
88

99
import errorBoundaryHOC from '../lib/error-boundary-hoc.jsx';
1010
import OpcodeLabels from '../lib/opcode-labels';
1111

1212
import MonitorListComponent from '../components/monitor-list/monitor-list.jsx';
1313

1414
class MonitorList extends React.Component {
15-
constructor(props) {
15+
constructor (props) {
1616
super(props);
1717
bindAll(this, [
1818
'handleMonitorChange'
@@ -22,7 +22,7 @@ class MonitorList extends React.Component {
2222
key: 0
2323
};
2424
}
25-
componentWillReceiveProps(nextProps) {
25+
componentWillReceiveProps (nextProps) {
2626
// TW: When stage size changes, we'll force all monitors to re-render completely
2727
// This is important because the VM moves monitors after resize to preserve locations but
2828
// Scratch's monitor layout logic is very complex and it won't notice that
@@ -33,10 +33,10 @@ class MonitorList extends React.Component {
3333
});
3434
}
3535
}
36-
handleMonitorChange(id, x, y) { // eslint-disable-line no-unused-vars
36+
handleMonitorChange (id, x, y) { // eslint-disable-line no-unused-vars
3737
this.props.moveMonitorRect(id, x, y);
3838
}
39-
render() {
39+
render () {
4040
return (
4141
<MonitorListComponent
4242
onMonitorChange={this.handleMonitorChange}

src/containers/monitor.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ class Monitor extends React.Component {
9090
return true;
9191
}
9292
for (const key of Object.getOwnPropertyNames(nextProps)) {
93+
// skip all the other things to check custom monitors and see if they need an update
94+
if (key === 'value' && typeof nextProps[key] === 'object') {
95+
return !nextProps[key]._monitorUpToDate;
96+
}
9397
// Don't need to rerender when other monitors are moved.
9498
// monitorLayout is only used during initial layout.
9599
if (key !== 'monitorLayout' && nextProps[key] !== this.props[key]) {

src/lib/monitor-adapter.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,21 @@ export default function ({id, spriteName, opcode, params, value, vm}) {
4545
if (typeof item === 'boolean') {
4646
value[i] = item.toString();
4747
}
48+
if (typeof item === 'object' &&
49+
typeof (item.toListItem || value.toMonitorContent || item.toReporterContent) === 'function') {
50+
value[i].isHTML = true;
51+
}
4852
}
4953
}
5054

51-
return {id, label, category, value};
55+
let isHTML = false;
56+
if (typeof value === 'object' &&
57+
typeof (value.toMonitorContent || value.toReporterContent) === 'function') {
58+
value = value.toMonitorContent
59+
? value.toMonitorContent()
60+
: value.toReporterContent();
61+
isHTML = true;
62+
}
63+
64+
return {id, label, category, value, isHTML};
5265
}

0 commit comments

Comments
 (0)