Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 29 additions & 6 deletions client/modules/IDE/components/VersionPicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,23 @@ const VersionPicker = React.forwardRef(({ onChangeVersion }, ref) => {
return (
<VersionDropdownMenu
className="versionPicker"
aria-label="Select p5.js version"
anchor={
<VersionPickerButton ref={ref}>
<VersionPickerText>{versionInfo.version}</VersionPickerText>
<VersionPickerText>
{versionInfo
? (() => {
const current = p5Versions.find((v) =>
typeof v === 'string'
? v === versionInfo.version
: v.version === versionInfo.version
);
if (!current) return versionInfo.version;
if (typeof current === 'string') return current;
return `${current.version} ${current.label}`;
})()
: t('Toolbar.CustomLibraryVersion')}
</VersionPickerText>
<VersionPickerArrow>
<DropdownArrowIcon />
</VersionPickerArrow>
Expand All @@ -86,11 +100,20 @@ const VersionPicker = React.forwardRef(({ onChangeVersion }, ref) => {
align="left"
maxHeight="50vh"
>
{p5Versions.map((version) => (
<MenuItem key={version} onClick={() => dispatchReplaceVersion(version)}>
{version}
</MenuItem>
))}
{p5Versions.map((item) => {
const version = typeof item === 'string' ? item : item.version;
const label =
typeof item === 'string' ? item : `${item.version} ${item.label}`;

return (
<MenuItem
key={version}
onClick={() => dispatchReplaceVersion(version)}
>
{label}
</MenuItem>
);
})}
</VersionDropdownMenu>
);
});
Expand Down
9 changes: 6 additions & 3 deletions client/modules/IDE/hooks/useP5Version.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import PropTypes from 'prop-types';
// JSON.stringify([...document.querySelectorAll('._132722c7')].map(n => n.innerText), null, 2)
// TODO: use their API for this to grab these at build time?
export const p5Versions = [
'2.0.3',
{ version: '2.0.3', label: '(Beta)' },
'2.0.2',
'2.0.1',
'2.0.0',
'1.11.8',
'1.11.7',
{ version: '1.11.7', label: '(Default)' },
'1.11.6',
'1.11.5',
'1.11.4',
Expand Down Expand Up @@ -197,7 +197,10 @@ export function P5VersionProvider(props) {
if (!match) return null;

// See if this is a version we recognize
if (p5Versions.includes(match[1])) {
const versionExists = p5Versions.some((v) =>
typeof v === 'string' ? v === match[1] : v.version === match[1]
);
if (versionExists) {
return { version: match[1], minified: !!match[2], scriptNode };
}
return null;
Expand Down