-
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.
- Loading branch information
Showing
85 changed files
with
1,752 additions
and
1,491 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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { KnotEditor } from 'editor' | ||
import { KnotEditor } from "editor"; | ||
|
||
export default function App() { | ||
return <KnotEditor /> | ||
return <KnotEditor />; | ||
} |
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 |
---|---|---|
|
@@ -11,18 +11,17 @@ | |
"desktop": "pnpm --filter desktop" | ||
}, | ||
"devDependencies": { | ||
"dprint": "^0.37.1", | ||
"husky": "^8.0.3", | ||
"husky": "latest", | ||
"turbo": "latest" | ||
}, | ||
"engines": { | ||
"node": ">=14.0.0", | ||
"node": ">=16.0.0", | ||
"pnpm": ">=8", | ||
"npm": "pnpm", | ||
"yarn": "pnpm" | ||
}, | ||
"packageManager": "[email protected]", | ||
"dependencies": { | ||
"flexsearch": "^0.7.3" | ||
"flexsearch": "^0.7.31" | ||
} | ||
} |
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 |
---|---|---|
@@ -1 +1 @@ | ||
module.exports = require('ui/postcss') | ||
module.exports = require("ui/postcss"); |
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 |
---|---|---|
@@ -1 +1 @@ | ||
import '@testing-library/jest-dom' | ||
import "@testing-library/jest-dom"; |
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,173 @@ | ||
import { createContext, For, useContext } from 'solid-js' | ||
import { createStore, produce } from 'solid-js/store' | ||
import { Button, Icon } from 'ui' | ||
|
||
export type File = { | ||
id: number | ||
name: string | ||
created: string | ||
edited: string | ||
contents: string | ||
} | ||
|
||
export type Folder = { | ||
id: number | ||
name: string | ||
created: string | ||
edited: string | ||
files: File[] | null | ||
} | ||
|
||
// !TODO | ||
/* onEnter={(e) => { | ||
e.preventDefault() | ||
const now = new Date() | ||
const str = (new Date()) | ||
.toISOString() | ||
.slice(0, 19) | ||
.replace(/-/g, '/') | ||
.replace('T', ' ') | ||
if (!edt.isEmpty) { | ||
cabinet.addFile({ | ||
id: Date.now(), | ||
name: edt.getText(), | ||
content: edt.getText() ?? '', | ||
created: str, | ||
edited: str, | ||
}) | ||
edt.commands.clearContent() | ||
edt.commands.blur() | ||
} | ||
}} */ | ||
|
||
const createCabinetContext = () => { | ||
const key = 'cabinet' | ||
const localCabinet = localStorage.getItem(key) | ||
|
||
const [cabinet, setCabinet] = createStore({ | ||
files: [] as File[], | ||
addFile: (file: File) => { | ||
setCabinet('files', (files) => [...files, file]) | ||
localStorage.setItem(key, JSON.stringify(cabinet.files)) | ||
}, | ||
editFile: (id: number, change: string) => { | ||
setCabinet( | ||
'files', | ||
(file) => file.id === id, | ||
produce((f) => { | ||
f.name = change | ||
f.edited = (new Date()) | ||
.toISOString() | ||
.slice(0, 19) | ||
.replace(/-/g, '/') | ||
.replace('T', ' ') | ||
console.log(f) | ||
}), | ||
) | ||
localStorage.setItem(key, JSON.stringify(cabinet.files)) | ||
}, | ||
removeFile: (id: number) => { | ||
setCabinet('files', (files) => files.filter((f) => f.id !== id)) | ||
localStorage.setItem(key, JSON.stringify(cabinet.files)) | ||
}, | ||
}) | ||
|
||
if (localCabinet) { | ||
setCabinet('files', JSON.parse(localCabinet)) | ||
} | ||
|
||
return cabinet | ||
} | ||
|
||
const CabinetContext = createContext<ReturnType<typeof createCabinetContext>>() | ||
|
||
export const useCabinetContext = () => { | ||
const context = useContext(CabinetContext) | ||
if (!context) { | ||
throw new Error('useCabinetContext must be used within CabinetProvider') | ||
} | ||
return context | ||
} | ||
|
||
export const CabinetProvider = (props: { children: any }) => { | ||
const cabinet = createCabinetContext() | ||
|
||
return ( | ||
<CabinetContext.Provider value={cabinet}> | ||
<div class='flex flex-col w-full h-full p-4 gap-4 bg-editorBg relative pb-32'> | ||
<For each={cabinet.files}> | ||
{(file) => ( | ||
<FolderCard | ||
file={file} | ||
/> | ||
)} | ||
</For> | ||
</div> | ||
{props.children} | ||
</CabinetContext.Provider> | ||
) | ||
} | ||
|
||
function FolderCard( | ||
props: { | ||
file: File | ||
}, | ||
) { | ||
const cabinet = useCabinetContext() | ||
|
||
return ( | ||
<div class='border rounded bg-gray-800 text-white p-2 flex flex-col gap-2'> | ||
<div class='flex justify-between'> | ||
<div class='flex items-center justify-center gap-1'> | ||
<Icon name='IconFolder' /> | ||
<div | ||
contenteditable={true} | ||
class='text-xl font-bold p-1' | ||
onkeydown={(e) => { | ||
if (e.key === 'Enter') { | ||
e.preventDefault() | ||
console.log(e.target.textContent) | ||
cabinet.editFile( | ||
props | ||
.file | ||
.id, | ||
e.target.textContent || props.file.name, | ||
) | ||
} | ||
}} | ||
> | ||
{props.file.name} | ||
</div> | ||
</div> | ||
<Button | ||
onclick={() => { | ||
cabinet.removeFile(props.file.id) | ||
}} | ||
> | ||
<Icon name='IconTrash' /> | ||
</Button> | ||
</div> | ||
<div class='flex justify-between'> | ||
<div class='text-xs text-gray-500'> | ||
{props.file.id} | ||
</div> | ||
<div class='flex flex-col justify-center'> | ||
<div class='text-xs flex justify-between gap-1'> | ||
<span> | ||
created: | ||
</span> | ||
{props.file.created} | ||
</div> | ||
<div class='text-xs flex justify-between gap-1'> | ||
<span> | ||
edited: | ||
</span> | ||
{props.file.edited} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} |
Oops, something went wrong.