Skip to content

(Reference) Comparing scratch-gui changes for blockly plugins [DO NOT MERGE] #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
905f043
fix: temporarily disable functionality in scratch-gui for compatibili…
gonfunko Apr 19, 2024
dbbb251
fix: show the correct toolbox based on sprites or the stage being sel…
gonfunko Apr 23, 2024
59bf3c5
fix: modify inject options to reflect Scratch behaviors (#5)
gonfunko Apr 23, 2024
df207e4
fix: add support for Scratch-style procedures (#6)
gonfunko Apr 24, 2024
a7b1a10
fix: reenable the Scratch colour eyedropper
gonfunko Apr 24, 2024
dd98dd8
fix: patch the getCheckboxState method in the new flyout (#7)
gonfunko Apr 26, 2024
2d58403
fix: select extension categories when added (#8)
gonfunko Apr 30, 2024
077415b
fix: Use toolboxitemid instead of id as the identifier attribute for …
gonfunko Apr 30, 2024
c8bc880
fix: preserve toolbox scroll position when switching between sprites/…
gonfunko May 1, 2024
1898c52
fix: call reportValue on the ScratchBlocks module instead of the work…
gonfunko May 3, 2024
be4386d
fix: call the new glow methods on ScratchBlocks (#12)
gonfunko May 6, 2024
06b011f
fix: adjust key event filtering to fix the when key pressed block (#13)
gonfunko May 7, 2024
6e56e52
refactor: simplify toolbox refreshing behavior (#14)
gonfunko May 16, 2024
668fbb9
fix: allow typing into comments (#15)
gonfunko Jul 8, 2024
c92f244
feat: plumb Scratch variable support into the UI (#16)
gonfunko Aug 2, 2024
ee80f13
fix: specify the function to be used for prompting about variables (#17)
gonfunko Aug 5, 2024
505011d
fix: update the toolbox in response to procedure deletion/creation (#18)
gonfunko Aug 6, 2024
e422913
chore: don't specify the renderer/theme (#20)
gonfunko Aug 12, 2024
f6dfd53
fix: only refresh the toolbox when procedures are created via undo (#19)
gonfunko Aug 12, 2024
a690749
fix: add pinch to zoom support (#21)
BeksOmega Aug 21, 2024
45d4803
fix: make dropdown menu shadow block colors consistent (#22)
gonfunko Sep 3, 2024
b7d44cc
refactor: use block styles instead of directly specifying block color…
gonfunko Sep 11, 2024
fe03cce
refactor: improve efficiency of toolbox updates (#24)
gonfunko Sep 12, 2024
1745c59
fix: partially roll back flyout optimization (#25)
gonfunko Sep 16, 2024
d174ae9
fix: prevent exception when switching languages (#27)
gonfunko Sep 18, 2024
8b1bf24
fix: fix bug that prevented displaying the procedure editor modal on …
gonfunko Sep 18, 2024
9bd036b
fix: avoid clearing the state of the sensing_of block by refreshing t…
gonfunko Oct 2, 2024
67a5e05
refactor: fix compatibility with checkboxes and category status indic…
gonfunko Oct 14, 2024
b8f19dc
fix: fix preserving toolbox scroll position for new continuous toolbo…
gonfunko Feb 4, 2025
0570261
fix: fix issue that could prevent variables from appearing in the too…
gonfunko Feb 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 73 additions & 55 deletions src/components/monitor/monitor.jsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,56 @@
import React from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import Draggable from 'react-draggable';
import {FormattedMessage} from 'react-intl';
import {ContextMenuTrigger} from 'react-contextmenu';
import {BorderedMenuItem, ContextMenu, MenuItem} from '../context-menu/context-menu.jsx';
import Box from '../box/box.jsx';
import DefaultMonitor from './default-monitor.jsx';
import LargeMonitor from './large-monitor.jsx';
import SliderMonitor from '../../containers/slider-monitor.jsx';
import ListMonitor from '../../containers/list-monitor.jsx';
import {getColorsForTheme} from '../../lib/themes/index.js';
import React from "react";
import ReactDOM from "react-dom";
import PropTypes from "prop-types";
import Draggable from "react-draggable";
import { FormattedMessage } from "react-intl";
import { ContextMenuTrigger } from "react-contextmenu";
import {
BorderedMenuItem,
ContextMenu,
MenuItem,
} from "../context-menu/context-menu.jsx";
import Box from "../box/box.jsx";
import DefaultMonitor from "./default-monitor.jsx";
import LargeMonitor from "./large-monitor.jsx";
import SliderMonitor from "../../containers/slider-monitor.jsx";
import ListMonitor from "../../containers/list-monitor.jsx";
import { getColorsForTheme } from "../../lib/themes/index.js";

import styles from './monitor.css';
import styles from "./monitor.css";

// Map category name to color name used in scratch-blocks Blockly.Colours
// Map category name to color name used in scratch-blocks Blockly.Colours. Note
// that Blockly uses the UK spelling of "colour", so fields that interact
// directly with Blockly follow that convention, while Scratch code uses the US
// spelling of "color".
const categoryColorMap = {
data: 'data',
sensing: 'sensing',
sound: 'sounds',
looks: 'looks',
motion: 'motion',
list: 'data_lists',
extension: 'pen'
data: "data",
sensing: "sensing",
sound: "sounds",
looks: "looks",
motion: "motion",
list: "data_lists",
extension: "pen",
};

const modes = {
default: DefaultMonitor,
large: LargeMonitor,
slider: SliderMonitor,
list: ListMonitor
list: ListMonitor,
};

const getCategoryColor = (theme, category) => {
const colors = getColorsForTheme(theme);
return {
background: colors[categoryColorMap[category]].primary,
text: colors.text
background: colors[categoryColorMap[category]].colourPrimary,
text: colors.text,
};
};

const MonitorComponent = props => (
const MonitorComponent = (props) => (
<ContextMenuTrigger
disable={!props.draggable}
holdToDisplay={props.mode === 'slider' ? -1 : 1000}
holdToDisplay={props.mode === "slider" ? -1 : 1000}
id={`monitor-${props.label}`}
>
<Draggable
Expand All @@ -56,80 +63,94 @@ const MonitorComponent = props => (
<Box
className={styles.monitorContainer}
componentRef={props.componentRef}
onDoubleClick={props.mode === 'list' || !props.draggable ? null : props.onNextMode}
onDoubleClick={
props.mode === "list" || !props.draggable
? null
: props.onNextMode
}
>
{React.createElement(modes[props.mode], {
categoryColor: getCategoryColor(props.theme, props.category),
...props
categoryColor: getCategoryColor(
props.theme,
props.category
),
...props,
})}
</Box>
</Draggable>
{ReactDOM.createPortal((
{ReactDOM.createPortal(
// Use a portal to render the context menu outside the flow to avoid
// positioning conflicts between the monitors `transform: scale` and
// the context menus `position: fixed`. For more details, see
// http://meyerweb.com/eric/thoughts/2011/09/12/un-fixing-fixed-elements-with-css-transforms/
<ContextMenu id={`monitor-${props.label}`}>
{props.onSetModeToDefault &&
{props.onSetModeToDefault && (
<MenuItem onClick={props.onSetModeToDefault}>
<FormattedMessage
defaultMessage="normal readout"
description="Menu item to switch to the default monitor"
id="gui.monitor.contextMenu.default"
/>
</MenuItem>}
{props.onSetModeToLarge &&
</MenuItem>
)}
{props.onSetModeToLarge && (
<MenuItem onClick={props.onSetModeToLarge}>
<FormattedMessage
defaultMessage="large readout"
description="Menu item to switch to the large monitor"
id="gui.monitor.contextMenu.large"
/>
</MenuItem>}
{props.onSetModeToSlider &&
</MenuItem>
)}
{props.onSetModeToSlider && (
<MenuItem onClick={props.onSetModeToSlider}>
<FormattedMessage
defaultMessage="slider"
description="Menu item to switch to the slider monitor"
id="gui.monitor.contextMenu.slider"
/>
</MenuItem>}
{props.onSliderPromptOpen && props.mode === 'slider' &&
</MenuItem>
)}
{props.onSliderPromptOpen && props.mode === "slider" && (
<BorderedMenuItem onClick={props.onSliderPromptOpen}>
<FormattedMessage
defaultMessage="change slider range"
description="Menu item to change the slider range"
id="gui.monitor.contextMenu.sliderRange"
/>
</BorderedMenuItem>}
{props.onImport &&
</BorderedMenuItem>
)}
{props.onImport && (
<MenuItem onClick={props.onImport}>
<FormattedMessage
defaultMessage="import"
description="Menu item to import into list monitors"
id="gui.monitor.contextMenu.import"
/>
</MenuItem>}
{props.onExport &&
</MenuItem>
)}
{props.onExport && (
<MenuItem onClick={props.onExport}>
<FormattedMessage
defaultMessage="export"
description="Menu item to export from list monitors"
id="gui.monitor.contextMenu.export"
/>
</MenuItem>}
{props.onHide &&
</MenuItem>
)}
{props.onHide && (
<BorderedMenuItem onClick={props.onHide}>
<FormattedMessage
defaultMessage="hide"
description="Menu item to hide the monitor"
id="gui.monitor.contextMenu.hide"
/>
</BorderedMenuItem>}
</ContextMenu>
), document.body)}
</BorderedMenuItem>
)}
</ContextMenu>,
document.body
)}
</ContextMenuTrigger>

);

const monitorModes = Object.keys(modes);
Expand All @@ -149,15 +170,12 @@ MonitorComponent.propTypes = {
onSetModeToLarge: PropTypes.func,
onSetModeToSlider: PropTypes.func,
onSliderPromptOpen: PropTypes.func,
theme: PropTypes.string.isRequired
theme: PropTypes.string.isRequired,
};

MonitorComponent.defaultProps = {
category: 'extension',
mode: 'default'
category: "extension",
mode: "default",
};

export {
MonitorComponent as default,
monitorModes
};
export { MonitorComponent as default, monitorModes };
Loading