mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-24 15:47:08 +00:00
Project tree view and creation (#203)
* Implement creating and importing new projects * Add downloading a zip of a project * Project validation (WIP) * Add project side panel, remove project pages * Project file saving * Add file tree actions to rename and delete * Fix file creation auto focus * Add button to save file from menu * Add project creation * Fix specificity on version switcher button * Update default version to 1.19 * List project files by type, remember project and delete project
This commit is contained in:
38
src/app/components/Modal.tsx
Normal file
38
src/app/components/Modal.tsx
Normal file
@@ -0,0 +1,38 @@
|
||||
import { useCallback, useEffect } from 'preact/hooks'
|
||||
import type { JSXInternal } from 'preact/src/jsx'
|
||||
import { LOSE_FOCUS } from '../hooks'
|
||||
|
||||
const MODALS_KEY = 'data-modals'
|
||||
|
||||
interface Props extends JSXInternal.HTMLAttributes<HTMLDivElement> {
|
||||
onDismiss: () => void,
|
||||
}
|
||||
export function Modal(props: Props) {
|
||||
useEffect(() => {
|
||||
addCurrentModals(1)
|
||||
window.addEventListener('click', props.onDismiss)
|
||||
return () => {
|
||||
addCurrentModals(-1)
|
||||
window.removeEventListener('click', props.onDismiss)
|
||||
}
|
||||
})
|
||||
|
||||
const onClick = useCallback((e: MouseEvent) => {
|
||||
e.stopPropagation()
|
||||
e.target?.dispatchEvent(new Event(LOSE_FOCUS, { bubbles: true }))
|
||||
}, [])
|
||||
|
||||
return <div {...props} class={`modal ${props.class ?? ''}`} onClick={onClick}>
|
||||
{props.children}
|
||||
</div>
|
||||
}
|
||||
|
||||
function addCurrentModals(diff: number) {
|
||||
const currentModals = parseInt(document.body.getAttribute(MODALS_KEY) ?? '0')
|
||||
const newModals = currentModals + diff
|
||||
if (newModals <= 0) {
|
||||
document.body.removeAttribute(MODALS_KEY)
|
||||
} else {
|
||||
document.body.setAttribute(MODALS_KEY, newModals.toFixed())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user