) => {
+ if (e.key === "F2") {
+ e.stopPropagation();
+
+ dispatch({ type: IFileExplorerActionKind.RENAME });
+ }
+
+ if (e.code === "Delete") {
+ e.stopPropagation();
+
+ dispatch({ type: IFileExplorerActionKind.DELETE });
+ }
+
+ if (state.type === "folder") {
+ if (e.ctrlKey && e.key.toUpperCase() === "N") {
+ if (e.shiftKey) {
+ dispatch({
+ type: IFileExplorerActionKind.ADD,
+ payload: {
+ type: "folder",
+ },
+ });
+ } else {
+ dispatch({
+ type: IFileExplorerActionKind.ADD,
+ payload: {
+ type: "file",
+ },
+ });
+ }
+ }
+ }
+ }}
+ nodeRenderer={({
+ element,
+ isBranch,
+ isExpanded,
+ getNodeProps,
+ level,
+ }) => (
+
+
+ {state.showAdd && state.path === element.id ? (
+ {
+ setTimeout(() => {
+ ref?.focus();
+ }, 200);
+ }}
+ className="ml-8"
+ onBlur={() =>
+ dispatch({ type: IFileExplorerActionKind.CLOSE_MODAL })
+ }
+ onKeyDown={async (e) => {
+ if (e.key === "Escape")
+ dispatch({ type: IFileExplorerActionKind.CLOSE_MODAL });
+
+ if (e.key === "Enter") {
+ await db.files.add({
+ path: `${pathname}/${encodeURIComponent(
+ `${state.path}/${e.currentTarget.value}${
+ state.addType === "folder" ? "/.gitkeep" : ""
+ }`
+ )}`,
+ contents: "",
+ });
+ await refreshFileExplorer();
+ dispatch({ type: IFileExplorerActionKind.CLOSE_MODAL });
+ }
+ }}
+ />
+ ) : null}
+
+ )}
+ />
+