forked from processing/p5.js-web-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into project-og-title
- Loading branch information
Showing
123 changed files
with
3,611 additions
and
4,079 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,6 @@ MAILGUN_KEY=<your-mailgun-api-key> | |
ML5_LIBRARY_USERNAME=ml5 | ||
ML5_LIBRARY_EMAIL=[email protected] | ||
ML5_LIBRARY_PASS=helloml5 | ||
MOBILE_ENABLED=true | ||
MONGO_URL=mongodb://localhost:27017/p5js-web-editor | ||
PORT=8000 | ||
PREVIEW_PORT=8002 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import { NavLink } from 'react-router-dom'; | ||
|
||
/** | ||
* Wraps the react-router `NavLink` with dashboard-header__tab styling. | ||
*/ | ||
const Tab = ({ children, to }) => ( | ||
<li className="dashboard-header__tab"> | ||
<NavLink | ||
className="dashboard-header__tab__title" | ||
activeClassName="dashboard-header__tab--selected" | ||
to={{ pathname: to, state: { skipSavingPath: true } }} | ||
> | ||
{children} | ||
</NavLink> | ||
</li> | ||
); | ||
|
||
Tab.propTypes = { | ||
children: PropTypes.string.isRequired, | ||
to: PropTypes.string.isRequired | ||
}; | ||
|
||
export default Tab; |
2 changes: 1 addition & 1 deletion
2
...t/modules/IDE/hooks/useKeyDownHandlers.js → client/common/useKeyDownHandlers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { useEffect, useRef } from 'react'; | ||
import useKeyDownHandlers from './useKeyDownHandlers'; | ||
|
||
/** | ||
* Common logic for Modal, Overlay, etc. | ||
* | ||
* Pass in the `onClose` handler. | ||
* | ||
* Can optionally pass in a ref, in case the `onClose` function needs to use the ref. | ||
* | ||
* Calls the provided `onClose` function on: | ||
* - Press Escape key. | ||
* - Click outside the element. | ||
* | ||
* Returns a ref to attach to the outermost element of the modal. | ||
* | ||
* @param {() => void} onClose | ||
* @param {React.MutableRefObject<HTMLElement | null>} [passedRef] | ||
* @return {React.MutableRefObject<HTMLElement | null>} | ||
*/ | ||
export default function useModalClose(onClose, passedRef) { | ||
const createdRef = useRef(null); | ||
const modalRef = passedRef || createdRef; | ||
|
||
useEffect(() => { | ||
modalRef.current?.focus(); | ||
|
||
function handleClick(e) { | ||
// ignore clicks on the component itself | ||
if (modalRef.current && !modalRef.current.contains(e.target)) { | ||
onClose?.(); | ||
} | ||
} | ||
|
||
document.addEventListener('click', handleClick, false); | ||
|
||
return () => { | ||
document.removeEventListener('click', handleClick, false); | ||
}; | ||
}, [onClose, modalRef]); | ||
|
||
useKeyDownHandlers({ escape: onClose }); | ||
|
||
return modalRef; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import PropTypes from 'prop-types'; | ||
import React, { forwardRef, useCallback, useRef, useState } from 'react'; | ||
import useModalClose from '../../common/useModalClose'; | ||
import DownArrowIcon from '../../images/down-filled-triangle.svg'; | ||
import { DropdownWrapper } from '../Dropdown'; | ||
|
||
// TODO: enable arrow keys to navigate options from list | ||
|
||
const DropdownMenu = forwardRef( | ||
( | ||
{ children, anchor, 'aria-label': ariaLabel, align, className, classes }, | ||
ref | ||
) => { | ||
// Note: need to use a ref instead of a state to avoid stale closures. | ||
const focusedRef = useRef(false); | ||
|
||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const close = useCallback(() => setIsOpen(false), [setIsOpen]); | ||
|
||
const anchorRef = useModalClose(close, ref); | ||
|
||
const toggle = useCallback(() => { | ||
setIsOpen((prevState) => !prevState); | ||
}, [setIsOpen]); | ||
|
||
const handleFocus = () => { | ||
focusedRef.current = true; | ||
}; | ||
|
||
const handleBlur = () => { | ||
focusedRef.current = false; | ||
setTimeout(() => { | ||
if (!focusedRef.current) { | ||
close(); | ||
} | ||
}, 200); | ||
}; | ||
|
||
return ( | ||
<div ref={anchorRef} className={className}> | ||
<button | ||
className={classes.button} | ||
aria-label={ariaLabel} | ||
tabIndex="0" | ||
onClick={toggle} | ||
onBlur={handleBlur} | ||
onFocus={handleFocus} | ||
> | ||
{anchor ?? <DownArrowIcon focusable="false" aria-hidden="true" />} | ||
</button> | ||
{isOpen && ( | ||
<DropdownWrapper | ||
className={classes.list} | ||
align={align} | ||
onMouseUp={() => { | ||
setTimeout(close, 0); | ||
}} | ||
onBlur={handleBlur} | ||
onFocus={handleFocus} | ||
> | ||
{children} | ||
</DropdownWrapper> | ||
)} | ||
</div> | ||
); | ||
} | ||
); | ||
|
||
DropdownMenu.propTypes = { | ||
/** | ||
* Provide <MenuItem> elements as children to control the contents of the menu. | ||
*/ | ||
children: PropTypes.node.isRequired, | ||
/** | ||
* Can optionally override the contents of the button which opens the menu. | ||
* Defaults to <DownArrowIcon> | ||
*/ | ||
anchor: PropTypes.node, | ||
'aria-label': PropTypes.string.isRequired, | ||
align: PropTypes.oneOf(['left', 'right']), | ||
className: PropTypes.string, | ||
classes: PropTypes.shape({ | ||
button: PropTypes.string, | ||
list: PropTypes.string | ||
}) | ||
}; | ||
|
||
DropdownMenu.defaultProps = { | ||
anchor: null, | ||
align: 'right', | ||
className: '', | ||
classes: {} | ||
}; | ||
|
||
export default DropdownMenu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import ButtonOrLink from '../../common/ButtonOrLink'; | ||
|
||
// TODO: combine with NavMenuItem | ||
|
||
function MenuItem({ hideIf, ...rest }) { | ||
if (hideIf) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<li> | ||
<ButtonOrLink {...rest} /> | ||
</li> | ||
); | ||
} | ||
|
||
MenuItem.propTypes = { | ||
...ButtonOrLink.propTypes, | ||
onClick: PropTypes.func, | ||
value: PropTypes.string, | ||
/** | ||
* Provides a way to deal with optional items. | ||
*/ | ||
hideIf: PropTypes.bool | ||
}; | ||
|
||
MenuItem.defaultProps = { | ||
onClick: null, | ||
value: null, | ||
hideIf: false | ||
}; | ||
|
||
export default MenuItem; |
Oops, something went wrong.