Skip to content

Commit 29da68a

Browse files
authored
Merge pull request #3525 from A-L-A/version-dropdown-enhancement
[#3504] Add version labels for default and beta versions
2 parents b16df37 + b83a607 commit 29da68a

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

client/modules/IDE/components/VersionPicker.jsx

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,23 @@ const VersionPicker = React.forwardRef(({ onChangeVersion }, ref) => {
7777
return (
7878
<VersionDropdownMenu
7979
className="versionPicker"
80+
aria-label="Select p5.js version"
8081
anchor={
8182
<VersionPickerButton ref={ref}>
82-
<VersionPickerText>{versionInfo.version}</VersionPickerText>
83+
<VersionPickerText>
84+
{versionInfo
85+
? (() => {
86+
const current = p5Versions.find((v) =>
87+
typeof v === 'string'
88+
? v === versionInfo.version
89+
: v.version === versionInfo.version
90+
);
91+
if (!current) return versionInfo.version;
92+
if (typeof current === 'string') return current;
93+
return `${current.version} ${current.label}`;
94+
})()
95+
: t('Toolbar.CustomLibraryVersion')}
96+
</VersionPickerText>
8397
<VersionPickerArrow>
8498
<DropdownArrowIcon />
8599
</VersionPickerArrow>
@@ -88,11 +102,20 @@ const VersionPicker = React.forwardRef(({ onChangeVersion }, ref) => {
88102
align="left"
89103
maxHeight="50vh"
90104
>
91-
{p5Versions.map((version) => (
92-
<MenuItem key={version} onClick={() => dispatchReplaceVersion(version)}>
93-
{version}
94-
</MenuItem>
95-
))}
105+
{p5Versions.map((item) => {
106+
const version = typeof item === 'string' ? item : item.version;
107+
const label =
108+
typeof item === 'string' ? item : `${item.version} ${item.label}`;
109+
110+
return (
111+
<MenuItem
112+
key={version}
113+
onClick={() => dispatchReplaceVersion(version)}
114+
>
115+
{label}
116+
</MenuItem>
117+
);
118+
})}
96119
</VersionDropdownMenu>
97120
);
98121
});

client/modules/IDE/hooks/useP5Version.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ export function P5VersionProvider(props) {
6060
if (!match) return null;
6161

6262
// See if this is a version we recognize
63-
if (p5Versions.includes(match[1])) {
63+
const versionExists = p5Versions.some((v) =>
64+
typeof v === 'string' ? v === match[1] : v.version === match[1]
65+
);
66+
if (versionExists) {
6467
return { version: match[1], minified: !!match[2], scriptNode };
6568
}
6669
return null;

common/p5Versions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ export const currentP5Version = '1.11.11'; // Don't update to 2.x until 2026
55
// JSON.stringify([...document.querySelectorAll('._132722c7')].map(n => n.innerText), null, 2)
66
// TODO: use their API for this to grab these at build time?
77
export const p5Versions = [
8-
'2.1.1',
8+
{ version: '2.1.1', label: '(Beta)' },
99
'2.0.5',
1010
'2.0.4',
1111
'2.0.3',
1212
'2.0.2',
1313
'2.0.1',
1414
'2.0.0',
15-
'1.11.11',
15+
{ version: '1.11.11', label: '(Default)' },
1616
'1.11.10',
1717
'1.11.9',
1818
'1.11.8',

0 commit comments

Comments
 (0)