mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-24 23:56:51 +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:
@@ -1,6 +1,8 @@
|
||||
import { useEffect, useState } from 'preact/hooks'
|
||||
|
||||
export function useFocus(): [boolean, () => unknown] {
|
||||
export const LOSE_FOCUS = 'misode-lose-focus'
|
||||
|
||||
export function useFocus(): [boolean, (active?: boolean) => unknown] {
|
||||
const [active, setActive] = useState(false)
|
||||
|
||||
const hider = () => {
|
||||
@@ -11,12 +13,14 @@ export function useFocus(): [boolean, () => unknown] {
|
||||
if (active) {
|
||||
document.body.addEventListener('click', hider)
|
||||
document.body.addEventListener('contextmenu', hider)
|
||||
document.body.addEventListener(LOSE_FOCUS, hider)
|
||||
}
|
||||
return () => {
|
||||
document.body.removeEventListener('click', hider)
|
||||
document.body.removeEventListener('contextmenu', hider)
|
||||
document.body.removeEventListener(LOSE_FOCUS, hider)
|
||||
}
|
||||
}, [active])
|
||||
|
||||
return [active, () => setActive(true)]
|
||||
return [active, (active = true) => setActive(active)]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user