mirror of
https://github.com/wavetermdev/waveterm
synced 2026-05-23 16:58:30 +00:00
Directory Formatting Changes (#92)
This make the following changes: - widen column resize handles - pin the `..` directory to the top row when it is visible - add some clarification to datetime format - fix arrow keys for directory parsing to only be local - switch to using keyutil for keypresses - only use the block's dummy focus if another focus element doesn't exist - add a gray background to directory nav buttons when they are focused - typing into search box works as long as the focus is in the directory view block - add a popup in the table to notify when searching/filtering - remove original search box
This commit is contained in:
parent
1f973b3fdc
commit
8a28a48c4e
4 changed files with 374 additions and 185 deletions
|
|
@ -95,7 +95,7 @@ function switchTab(offset: number) {
|
||||||
services.ObjectService.SetActiveTab(newActiveTabId);
|
services.ObjectService.SetActiveTab(newActiveTabId);
|
||||||
}
|
}
|
||||||
|
|
||||||
var transformRegexp = /translate\(\s*([0-9.]+)px\s*,\s*([0-9.]+)px\)/;
|
var transformRegexp = /translate3d\(\s*([0-9.]+)px\s*,\s*([0-9.]+)px,\s*0\)/;
|
||||||
|
|
||||||
function parseFloatFromCSS(s: string | number): number {
|
function parseFloatFromCSS(s: string | number): number {
|
||||||
if (typeof s == "number") {
|
if (typeof s == "number") {
|
||||||
|
|
|
||||||
|
|
@ -205,6 +205,7 @@ interface BlockFrameProps {
|
||||||
blockId: string;
|
blockId: string;
|
||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
onClick?: () => void;
|
onClick?: () => void;
|
||||||
|
onFocusCapture?: React.FocusEventHandler<HTMLDivElement>;
|
||||||
preview: boolean;
|
preview: boolean;
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
blockRef?: React.RefObject<HTMLDivElement>;
|
blockRef?: React.RefObject<HTMLDivElement>;
|
||||||
|
|
@ -215,6 +216,7 @@ const BlockFrame_Tech_Component = ({
|
||||||
blockId,
|
blockId,
|
||||||
onClose,
|
onClose,
|
||||||
onClick,
|
onClick,
|
||||||
|
onFocusCapture,
|
||||||
preview,
|
preview,
|
||||||
blockRef,
|
blockRef,
|
||||||
dragHandleRef,
|
dragHandleRef,
|
||||||
|
|
@ -249,6 +251,7 @@ const BlockFrame_Tech_Component = ({
|
||||||
preview ? "block-preview" : null
|
preview ? "block-preview" : null
|
||||||
)}
|
)}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
|
onFocusCapture={onFocusCapture}
|
||||||
ref={blockRef}
|
ref={blockRef}
|
||||||
style={style}
|
style={style}
|
||||||
>
|
>
|
||||||
|
|
@ -425,6 +428,18 @@ const Block = React.memo(({ blockId, onClose, dragHandleRef }: BlockProps) => {
|
||||||
const blockRef = React.useRef<HTMLDivElement>(null);
|
const blockRef = React.useRef<HTMLDivElement>(null);
|
||||||
const [blockClicked, setBlockClicked] = React.useState(false);
|
const [blockClicked, setBlockClicked] = React.useState(false);
|
||||||
const [blockData, blockDataLoading] = WOS.useWaveObjectValue<Block>(WOS.makeORef("block", blockId));
|
const [blockData, blockDataLoading] = WOS.useWaveObjectValue<Block>(WOS.makeORef("block", blockId));
|
||||||
|
const [focusedChild, setFocusedChild] = React.useState(null);
|
||||||
|
const isFocusedAtom = useBlockAtom<boolean>(blockId, "isFocused", () => {
|
||||||
|
return jotai.atom((get) => {
|
||||||
|
const winData = get(atoms.waveWindow);
|
||||||
|
return winData.activeblockid === blockId;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
let isFocused = jotai.useAtomValue(isFocusedAtom);
|
||||||
|
|
||||||
|
React.useLayoutEffect(() => {
|
||||||
|
setBlockClicked(isFocused);
|
||||||
|
}, [isFocused]);
|
||||||
|
|
||||||
React.useLayoutEffect(() => {
|
React.useLayoutEffect(() => {
|
||||||
if (!blockClicked) {
|
if (!blockClicked) {
|
||||||
|
|
@ -433,15 +448,50 @@ const Block = React.memo(({ blockId, onClose, dragHandleRef }: BlockProps) => {
|
||||||
setBlockClicked(false);
|
setBlockClicked(false);
|
||||||
const focusWithin = blockRef.current?.contains(document.activeElement);
|
const focusWithin = blockRef.current?.contains(document.activeElement);
|
||||||
if (!focusWithin) {
|
if (!focusWithin) {
|
||||||
focusElemRef.current?.focus();
|
setFocusTarget();
|
||||||
}
|
}
|
||||||
setBlockFocus(blockId);
|
setBlockFocus(blockId);
|
||||||
}, [blockClicked]);
|
}, [blockClicked]);
|
||||||
|
|
||||||
|
React.useLayoutEffect(() => {
|
||||||
|
if (focusedChild == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setBlockFocus(blockId);
|
||||||
|
}, [focusedChild, blockId]);
|
||||||
|
|
||||||
|
// treat the block as clicked on creation
|
||||||
const setBlockClickedTrue = React.useCallback(() => {
|
const setBlockClickedTrue = React.useCallback(() => {
|
||||||
setBlockClicked(true);
|
setBlockClicked(true);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const determineFocusedChild = React.useCallback(
|
||||||
|
(event: React.FocusEvent<HTMLDivElement, Element>) => {
|
||||||
|
setFocusedChild(event.target);
|
||||||
|
},
|
||||||
|
[setFocusedChild]
|
||||||
|
);
|
||||||
|
|
||||||
|
const getFocusableChildren = React.useCallback(() => {
|
||||||
|
if (blockRef.current == null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return Array.from(
|
||||||
|
blockRef.current.querySelectorAll(
|
||||||
|
'a[href], area[href], input:not([disabled]), select:not([disabled]), button:not([disabled]), [tabindex="0"]'
|
||||||
|
)
|
||||||
|
).filter((elem) => elem.id != `${blockId}-dummy-focus`);
|
||||||
|
}, [blockRef.current]);
|
||||||
|
|
||||||
|
const setFocusTarget = React.useCallback(() => {
|
||||||
|
const focusableChildren = getFocusableChildren();
|
||||||
|
if (focusableChildren.length == 0) {
|
||||||
|
focusElemRef.current.focus({ preventScroll: true });
|
||||||
|
} else {
|
||||||
|
(focusableChildren[0] as HTMLElement).focus({ preventScroll: true });
|
||||||
|
}
|
||||||
|
}, [focusElemRef.current, getFocusableChildren]);
|
||||||
|
|
||||||
if (!blockId || !blockData) return null;
|
if (!blockId || !blockData) return null;
|
||||||
if (blockDataLoading) {
|
if (blockDataLoading) {
|
||||||
blockElem = <CenteredDiv>Loading...</CenteredDiv>;
|
blockElem = <CenteredDiv>Loading...</CenteredDiv>;
|
||||||
|
|
@ -458,6 +508,7 @@ const Block = React.memo(({ blockId, onClose, dragHandleRef }: BlockProps) => {
|
||||||
} else if (blockData.view === "waveai") {
|
} else if (blockData.view === "waveai") {
|
||||||
blockElem = <WaveAi key={blockId} parentRef={blockRef} />;
|
blockElem = <WaveAi key={blockId} parentRef={blockRef} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BlockFrame
|
<BlockFrame
|
||||||
key={blockId}
|
key={blockId}
|
||||||
|
|
@ -467,9 +518,17 @@ const Block = React.memo(({ blockId, onClose, dragHandleRef }: BlockProps) => {
|
||||||
onClick={setBlockClickedTrue}
|
onClick={setBlockClickedTrue}
|
||||||
blockRef={blockRef}
|
blockRef={blockRef}
|
||||||
dragHandleRef={dragHandleRef}
|
dragHandleRef={dragHandleRef}
|
||||||
|
onFocusCapture={(e) => determineFocusedChild(e)}
|
||||||
>
|
>
|
||||||
<div key="focuselem" className="block-focuselem">
|
<div key="focuselem" className="block-focuselem">
|
||||||
<input type="text" value="" ref={focusElemRef} onChange={() => {}} />
|
<input
|
||||||
|
type="text"
|
||||||
|
value=""
|
||||||
|
ref={focusElemRef}
|
||||||
|
id={`${blockId}-dummy-focus`}
|
||||||
|
onChange={() => {}}
|
||||||
|
disabled={getFocusableChildren().length > 0}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div key="content" className="block-content">
|
<div key="content" className="block-content">
|
||||||
<ErrorBoundary>
|
<ErrorBoundary>
|
||||||
|
|
|
||||||
|
|
@ -1,122 +1,179 @@
|
||||||
.dir-table {
|
.dir-table-container {
|
||||||
--col-size-size: 0.2rem;
|
|
||||||
overflow: auto;
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-radius: 3px;
|
|
||||||
.dir-table-head {
|
|
||||||
.dir-table-head-row {
|
|
||||||
display: flex;
|
|
||||||
border-bottom: 2px solid var(--border-color);
|
|
||||||
padding: 4px 0;
|
|
||||||
background-color: var(--panel-bg-color);
|
|
||||||
|
|
||||||
.dir-table-head-cell:not(:first-child) {
|
|
||||||
position: relative;
|
|
||||||
padding: 2px 4px;
|
|
||||||
font-weight: bold;
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
overflow: hidden;
|
|
||||||
.dir-table-head-resize {
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
right: 0;
|
|
||||||
height: 100%;
|
|
||||||
cursor: col-resize;
|
|
||||||
user-select: none;
|
|
||||||
-webkit-user-select: none;
|
|
||||||
touch-action: none;
|
|
||||||
width: 2px;
|
|
||||||
background: linear-gradient(var(--border-color), var(--border-color)) no-repeat center/2px 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dir-table-head-direction {
|
|
||||||
color: var(--grey-text-color);
|
|
||||||
margin-right: 0.2rem;
|
|
||||||
margin-top: 0.2rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
&:last-child {
|
|
||||||
.dir-table-head-resize {
|
|
||||||
width: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.dir-table-body {
|
|
||||||
.dir-table-body-row {
|
|
||||||
display: flex;
|
|
||||||
border-radius: 3px;
|
|
||||||
|
|
||||||
&.focused {
|
|
||||||
background-color: rgb(from var(--accent-color) r g b / 0.7);
|
|
||||||
color: var(--main-text-color);
|
|
||||||
|
|
||||||
.dir-table-body-cell {
|
|
||||||
.dir-table-lastmod,
|
|
||||||
.dir-table-modestr,
|
|
||||||
.dir-table-size,
|
|
||||||
.dir-table-type {
|
|
||||||
color: var(--main-text-color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&:focus {
|
|
||||||
background-color: rgb(from var(--accent-color) r g b / 0.7);
|
|
||||||
color: var(--main-text-color);
|
|
||||||
|
|
||||||
.dir-table-body-cell {
|
|
||||||
.dir-table-lastmod,
|
|
||||||
.dir-table-modestr,
|
|
||||||
.dir-table-size,
|
|
||||||
.dir-table-type {
|
|
||||||
color: var(--main-text-color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&:hover:not(:focus):not(.focused) {
|
|
||||||
background-color: var(--highlight-bg-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.dir-table-body-cell {
|
|
||||||
overflow: hidden;
|
|
||||||
white-space: nowrap;
|
|
||||||
padding: 0.25rem;
|
|
||||||
cursor: default;
|
|
||||||
|
|
||||||
&.col-size {
|
|
||||||
text-align: right;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dir-table-lastmod,
|
|
||||||
.dir-table-modestr,
|
|
||||||
.dir-table-size,
|
|
||||||
.dir-table-type {
|
|
||||||
color: var(--secondary-text-color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.dir-table-search-line {
|
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 0.7rem;
|
flex-direction: column;
|
||||||
|
height: 100%;
|
||||||
|
.dir-table {
|
||||||
|
height: 100%;
|
||||||
|
--col-size-size: 0.2rem;
|
||||||
|
border-radius: 3px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
.dir-table-head {
|
||||||
|
.dir-table-head-row {
|
||||||
|
display: flex;
|
||||||
|
border-bottom: 2px solid var(--border-color);
|
||||||
|
padding: 4px 0;
|
||||||
|
background-color: var(--panel-bg-color);
|
||||||
|
|
||||||
.dir-table-search-box {
|
.dir-table-head-cell:not(:first-child) {
|
||||||
background-color: var(--panel-bg-color);
|
position: relative;
|
||||||
margin-bottom: 0.5rem;
|
padding: 2px 4px;
|
||||||
border: none;
|
font-weight: bold;
|
||||||
width: 15rem;
|
display: flex;
|
||||||
color: var(--main-text-color);
|
justify-content: space-between;
|
||||||
border-radius: 4px;
|
overflow: hidden;
|
||||||
|
.dir-table-head-resize {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
height: 100%;
|
||||||
|
cursor: col-resize;
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
touch-action: none;
|
||||||
|
width: 4px;
|
||||||
|
background: linear-gradient(var(--border-color), var(--border-color)) no-repeat center/2px 100%;
|
||||||
|
}
|
||||||
|
|
||||||
&:focus {
|
.dir-table-head-direction {
|
||||||
outline-color: var(--accent-color);
|
color: var(--grey-text-color);
|
||||||
|
margin-right: 0.2rem;
|
||||||
|
margin-top: 0.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:last-child {
|
||||||
|
.dir-table-head-resize {
|
||||||
|
width: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.dir-table-body {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
.dir-table-body-search-display {
|
||||||
|
display: flex;
|
||||||
|
border-radius: 3px;
|
||||||
|
padding: 0.25rem 0.5rem;
|
||||||
|
background-color: var(--warning-color);
|
||||||
|
|
||||||
|
.search-display-close-button {
|
||||||
|
margin-left: auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.dir-table-body-scroll-box {
|
||||||
|
position: relative;
|
||||||
|
overflow-y: auto;
|
||||||
|
.dummy {
|
||||||
|
position: absolute;
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
.dir-table-body-row {
|
||||||
|
display: flex;
|
||||||
|
border-radius: 3px;
|
||||||
|
|
||||||
|
&.focused {
|
||||||
|
background-color: rgb(from var(--accent-color) r g b / 0.7);
|
||||||
|
color: var(--main-text-color);
|
||||||
|
|
||||||
|
.dir-table-body-cell {
|
||||||
|
.dir-table-lastmod,
|
||||||
|
.dir-table-modestr,
|
||||||
|
.dir-table-size,
|
||||||
|
.dir-table-type {
|
||||||
|
color: var(--main-text-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&:focus {
|
||||||
|
background-color: rgb(from var(--accent-color) r g b / 0.7);
|
||||||
|
color: var(--main-text-color);
|
||||||
|
|
||||||
|
.dir-table-body-cell {
|
||||||
|
.dir-table-lastmod,
|
||||||
|
.dir-table-modestr,
|
||||||
|
.dir-table-size,
|
||||||
|
.dir-table-type {
|
||||||
|
color: var(--main-text-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover:not(:focus):not(.focused) {
|
||||||
|
background-color: var(--highlight-bg-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dir-table-body-cell {
|
||||||
|
overflow: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
|
padding: 0.25rem;
|
||||||
|
cursor: default;
|
||||||
|
|
||||||
|
&.col-size {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dir-table-lastmod,
|
||||||
|
.dir-table-modestr,
|
||||||
|
.dir-table-size,
|
||||||
|
.dir-table-type {
|
||||||
|
color: var(--secondary-text-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.dir-table-search-line {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 0.7rem;
|
||||||
|
|
||||||
|
.dir-table-search-box {
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
opacity: 0;
|
||||||
|
padding: 0;
|
||||||
|
border: none;
|
||||||
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.dir-table-button {
|
||||||
|
background-color: transparent;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
flex-direction: column;
|
||||||
|
padding: 0.2rem;
|
||||||
|
border-radius: 6px;
|
||||||
|
|
||||||
|
input {
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
opacity: 0;
|
||||||
|
padding: 0;
|
||||||
|
border: none;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: var(--highlight-bg-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:focus {
|
||||||
|
background-color: var(--highlight-bg-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:focus-within {
|
||||||
|
background-color: var(--highlight-bg-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
// Copyright 2024, Command Line Inc.
|
// Copyright 2024, Command Line Inc.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
import { Button } from "@/element/button";
|
|
||||||
import * as services from "@/store/services";
|
import * as services from "@/store/services";
|
||||||
|
import * as keyutil from "@/util/keyutil";
|
||||||
import * as util from "@/util/util";
|
import * as util from "@/util/util";
|
||||||
import {
|
import {
|
||||||
|
Row,
|
||||||
Table,
|
Table,
|
||||||
createColumnHelper,
|
createColumnHelper,
|
||||||
flexRender,
|
flexRender,
|
||||||
|
|
@ -23,6 +24,7 @@ import "./directorypreview.less";
|
||||||
|
|
||||||
interface DirectoryTableProps {
|
interface DirectoryTableProps {
|
||||||
data: FileInfo[];
|
data: FileInfo[];
|
||||||
|
search: string;
|
||||||
focusIndex: number;
|
focusIndex: number;
|
||||||
setFocusIndex: (_: number) => void;
|
setFocusIndex: (_: number) => void;
|
||||||
setFileName: (_: string) => void;
|
setFileName: (_: string) => void;
|
||||||
|
|
@ -94,7 +96,7 @@ function getLastModifiedTime(unixMillis: number): string {
|
||||||
} else if (nowDatetime.month() != fileDatetime.month()) {
|
} else if (nowDatetime.month() != fileDatetime.month()) {
|
||||||
return dayjs(fileDatetime).format("MMM D");
|
return dayjs(fileDatetime).format("MMM D");
|
||||||
} else {
|
} else {
|
||||||
return dayjs(fileDatetime).format("h:mm A");
|
return dayjs(fileDatetime).format("MMM D h:mm A");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,6 +137,7 @@ function cleanMimetype(input: string): string {
|
||||||
|
|
||||||
function DirectoryTable({
|
function DirectoryTable({
|
||||||
data,
|
data,
|
||||||
|
search,
|
||||||
focusIndex,
|
focusIndex,
|
||||||
setFocusIndex,
|
setFocusIndex,
|
||||||
setFileName,
|
setFileName,
|
||||||
|
|
@ -227,11 +230,28 @@ function DirectoryTable({
|
||||||
columnVisibility: {
|
columnVisibility: {
|
||||||
path: false,
|
path: false,
|
||||||
},
|
},
|
||||||
|
rowPinning: {
|
||||||
|
top: [],
|
||||||
|
bottom: [],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
enableMultiSort: false,
|
enableMultiSort: false,
|
||||||
enableSortingRemoval: false,
|
enableSortingRemoval: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
setSelectedPath((table.getSortedRowModel()?.flatRows[focusIndex]?.getValue("path") as string) ?? null);
|
||||||
|
}, [table, focusIndex, data]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
let rows = table.getRowModel()?.flatRows;
|
||||||
|
for (const row of rows) {
|
||||||
|
if (row.getValue("name") == "..") {
|
||||||
|
row.pin("top");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [data]);
|
||||||
const columnSizeVars = React.useMemo(() => {
|
const columnSizeVars = React.useMemo(() => {
|
||||||
const headers = table.getFlatHeaders();
|
const headers = table.getFlatHeaders();
|
||||||
const colSizes: { [key: string]: number } = {};
|
const colSizes: { [key: string]: number } = {};
|
||||||
|
|
@ -271,7 +291,9 @@ function DirectoryTable({
|
||||||
</div>
|
</div>
|
||||||
{table.getState().columnSizingInfo.isResizingColumn ? (
|
{table.getState().columnSizingInfo.isResizingColumn ? (
|
||||||
<MemoizedTableBody
|
<MemoizedTableBody
|
||||||
|
data={data}
|
||||||
table={table}
|
table={table}
|
||||||
|
search={search}
|
||||||
focusIndex={focusIndex}
|
focusIndex={focusIndex}
|
||||||
setFileName={setFileName}
|
setFileName={setFileName}
|
||||||
setFocusIndex={setFocusIndex}
|
setFocusIndex={setFocusIndex}
|
||||||
|
|
@ -281,7 +303,9 @@ function DirectoryTable({
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<TableBody
|
<TableBody
|
||||||
|
data={data}
|
||||||
table={table}
|
table={table}
|
||||||
|
search={search}
|
||||||
focusIndex={focusIndex}
|
focusIndex={focusIndex}
|
||||||
setFileName={setFileName}
|
setFileName={setFileName}
|
||||||
setFocusIndex={setFocusIndex}
|
setFocusIndex={setFocusIndex}
|
||||||
|
|
@ -295,7 +319,9 @@ function DirectoryTable({
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TableBodyProps {
|
interface TableBodyProps {
|
||||||
|
data: Array<FileInfo>;
|
||||||
table: Table<FileInfo>;
|
table: Table<FileInfo>;
|
||||||
|
search: string;
|
||||||
focusIndex: number;
|
focusIndex: number;
|
||||||
setFocusIndex: (_: number) => void;
|
setFocusIndex: (_: number) => void;
|
||||||
setFileName: (_: string) => void;
|
setFileName: (_: string) => void;
|
||||||
|
|
@ -305,7 +331,9 @@ interface TableBodyProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
function TableBody({
|
function TableBody({
|
||||||
|
data,
|
||||||
table,
|
table,
|
||||||
|
search,
|
||||||
focusIndex,
|
focusIndex,
|
||||||
setFocusIndex,
|
setFocusIndex,
|
||||||
setFileName,
|
setFileName,
|
||||||
|
|
@ -313,9 +341,36 @@ function TableBody({
|
||||||
setSelectedPath,
|
setSelectedPath,
|
||||||
setRefresh,
|
setRefresh,
|
||||||
}: TableBodyProps) {
|
}: TableBodyProps) {
|
||||||
|
const dummyLineRef = React.useRef<HTMLDivElement>(null);
|
||||||
|
const parentRef = React.useRef<HTMLDivElement>(null);
|
||||||
|
const warningBoxRef = React.useRef<HTMLDivElement>(null);
|
||||||
|
const [bodyHeight, setBodyHeight] = React.useState(0);
|
||||||
|
const [containerHeight, setContainerHeight] = React.useState(0);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
setSelectedPath((table.getSortedRowModel()?.flatRows[focusIndex]?.getValue("path") as string) ?? null);
|
if (parentRef.current == null) {
|
||||||
}, [table, focusIndex]);
|
return;
|
||||||
|
}
|
||||||
|
const resizeObserver = new ResizeObserver(() => {
|
||||||
|
setContainerHeight(parentRef.current.getBoundingClientRect().height); // 17 is height of breadcrumb
|
||||||
|
});
|
||||||
|
resizeObserver.observe(parentRef.current);
|
||||||
|
|
||||||
|
return () => resizeObserver.disconnect();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (dummyLineRef.current && data && parentRef.current) {
|
||||||
|
const rowHeight = dummyLineRef.current.offsetHeight;
|
||||||
|
const fullTBodyHeight = rowHeight * data.length;
|
||||||
|
const warningBoxHeight = warningBoxRef.current?.offsetHeight ?? 0;
|
||||||
|
const maxHeight = containerHeight - 1; // i don't know why, but the -1 makes the resize work
|
||||||
|
const maxHeightLessHeader = maxHeight - warningBoxHeight;
|
||||||
|
const tbodyHeight = Math.min(maxHeightLessHeader, fullTBodyHeight);
|
||||||
|
|
||||||
|
setBodyHeight(tbodyHeight);
|
||||||
|
}
|
||||||
|
}, [data, containerHeight]);
|
||||||
|
|
||||||
const handleFileContextMenu = React.useCallback(
|
const handleFileContextMenu = React.useCallback(
|
||||||
(e: React.MouseEvent<HTMLDivElement>, path: string) => {
|
(e: React.MouseEvent<HTMLDivElement>, path: string) => {
|
||||||
|
|
@ -350,33 +405,53 @@ function TableBody({
|
||||||
[setRefresh]
|
[setRefresh]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const displayRow = React.useCallback(
|
||||||
|
(row: Row<FileInfo>, idx: number) => (
|
||||||
|
<div
|
||||||
|
className={clsx("dir-table-body-row", { focused: focusIndex === idx })}
|
||||||
|
key={row.id}
|
||||||
|
onDoubleClick={() => {
|
||||||
|
const newFileName = row.getValue("path") as string;
|
||||||
|
setFileName(newFileName);
|
||||||
|
setSearch("");
|
||||||
|
}}
|
||||||
|
onClick={() => setFocusIndex(idx)}
|
||||||
|
onContextMenu={(e) => handleFileContextMenu(e, row.getValue("path") as string)}
|
||||||
|
>
|
||||||
|
{row.getVisibleCells().map((cell) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={clsx("dir-table-body-cell", "col-" + cell.column.id)}
|
||||||
|
key={cell.id}
|
||||||
|
style={{ width: `calc(var(--col-${cell.column.id}-size) * 1px)` }}
|
||||||
|
>
|
||||||
|
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
[setSearch, setFileName, handleFileContextMenu, setFocusIndex, focusIndex]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="dir-table-body">
|
<div className="dir-table-body" ref={parentRef}>
|
||||||
{table.getRowModel().rows.map((row, idx) => (
|
{search == "" || (
|
||||||
<div
|
<div className="dir-table-body-search-display" ref={warningBoxRef}>
|
||||||
className={clsx("dir-table-body-row", { focused: focusIndex === idx })}
|
<span>Searching for "{search}"</span>
|
||||||
key={row.id}
|
<div className="search-display-close-button dir-table-button" onClick={() => setSearch("")}>
|
||||||
onDoubleClick={() => {
|
<i className="fa-solid fa-xmark" />
|
||||||
const newFileName = row.getValue("path") as string;
|
<input type="text" value={search} onChange={() => {}}></input>
|
||||||
setFileName(newFileName);
|
</div>
|
||||||
setSearch("");
|
|
||||||
}}
|
|
||||||
onClick={() => setFocusIndex(idx)}
|
|
||||||
onContextMenu={(e) => handleFileContextMenu(e, row.getValue("path") as string)}
|
|
||||||
>
|
|
||||||
{row.getVisibleCells().map((cell) => {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className={clsx("dir-table-body-cell", "col-" + cell.column.id)}
|
|
||||||
key={cell.id}
|
|
||||||
style={{ width: `calc(var(--col-${cell.column.id}-size) * 1px)` }}
|
|
||||||
>
|
|
||||||
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
</div>
|
||||||
))}
|
)}
|
||||||
|
<div className="dir-table-body-scroll-box" style={{ height: bodyHeight }}>
|
||||||
|
<div className="dummy dir-table-body-row" ref={dummyLineRef}>
|
||||||
|
<div className="dir-table-body-cell">dummy-data</div>
|
||||||
|
</div>
|
||||||
|
{table.getTopRows().map(displayRow)}
|
||||||
|
{table.getCenterRows().map((row, idx) => displayRow(row, idx + table.getTopRows().length))}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -405,7 +480,7 @@ function DirectoryPreview({ fileNameAtom }: DirectoryPreviewProps) {
|
||||||
const serializedContent = util.base64ToString(file?.data64);
|
const serializedContent = util.base64ToString(file?.data64);
|
||||||
let content: FileInfo[] = JSON.parse(serializedContent);
|
let content: FileInfo[] = JSON.parse(serializedContent);
|
||||||
let filtered = content.filter((fileInfo) => {
|
let filtered = content.filter((fileInfo) => {
|
||||||
if (hideHiddenFiles && fileInfo.name.startsWith(".")) {
|
if (hideHiddenFiles && fileInfo.name.startsWith(".") && fileInfo.name != "..") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return fileInfo.name.toLowerCase().includes(searchText);
|
return fileInfo.name.toLowerCase().includes(searchText);
|
||||||
|
|
@ -416,62 +491,60 @@ function DirectoryPreview({ fileNameAtom }: DirectoryPreviewProps) {
|
||||||
}, [fileName, searchText, hideHiddenFiles, refresh]);
|
}, [fileName, searchText, hideHiddenFiles, refresh]);
|
||||||
|
|
||||||
const handleKeyDown = React.useCallback(
|
const handleKeyDown = React.useCallback(
|
||||||
(e) => {
|
(waveEvent: WaveKeyboardEvent): boolean => {
|
||||||
switch (e.key) {
|
if (keyutil.checkKeyPressed(waveEvent, "Escape")) {
|
||||||
case "Escape":
|
setSearchText("");
|
||||||
//todo: escape block focus
|
return;
|
||||||
break;
|
}
|
||||||
case "ArrowUp":
|
if (keyutil.checkKeyPressed(waveEvent, "ArrowUp")) {
|
||||||
e.preventDefault();
|
setFocusIndex((idx) => Math.max(idx - 1, 0));
|
||||||
setFocusIndex((idx) => Math.max(idx - 1, 0));
|
return true;
|
||||||
break;
|
}
|
||||||
case "ArrowDown":
|
if (keyutil.checkKeyPressed(waveEvent, "ArrowDown")) {
|
||||||
e.preventDefault();
|
setFocusIndex((idx) => Math.min(idx + 1, content.length - 1));
|
||||||
setFocusIndex((idx) => Math.min(idx + 1, content.length - 1));
|
return true;
|
||||||
break;
|
}
|
||||||
case "Enter":
|
if (keyutil.checkKeyPressed(waveEvent, "Enter")) {
|
||||||
e.preventDefault();
|
setFileName(selectedPath);
|
||||||
setFileName(selectedPath);
|
setSearchText("");
|
||||||
setSearchText("");
|
return true;
|
||||||
break;
|
|
||||||
default:
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[content, focusIndex, selectedPath]
|
[content, focusIndex, selectedPath]
|
||||||
);
|
);
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
document.addEventListener("keydown", handleKeyDown);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
document.removeEventListener("keydown", handleKeyDown);
|
|
||||||
};
|
|
||||||
}, [handleKeyDown]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<div
|
||||||
|
className="dir-table-container"
|
||||||
|
onChangeCapture={(e) => {
|
||||||
|
const event = e as React.ChangeEvent<HTMLInputElement>;
|
||||||
|
setSearchText(event.target.value.toLowerCase());
|
||||||
|
}}
|
||||||
|
onKeyDownCapture={(e) => keyutil.keydownWrapper(handleKeyDown)(e)}
|
||||||
|
onFocusCapture={() => document.getSelection().collapseToEnd()}
|
||||||
|
>
|
||||||
<div className="dir-table-search-line">
|
<div className="dir-table-search-line">
|
||||||
<label>Search:</label>
|
|
||||||
|
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
className="dir-table-search-box"
|
className="dir-table-search-box"
|
||||||
onChange={(e) => setSearchText(e.target.value.toLowerCase())}
|
onChange={() => {}} //for nuisance warnings
|
||||||
maxLength={400}
|
maxLength={400}
|
||||||
autoFocus={true}
|
autoFocus={true}
|
||||||
value={searchText}
|
value={searchText}
|
||||||
/>
|
/>
|
||||||
<Button onClick={() => setHideHiddenFiles((current) => !current)}>
|
<div onClick={() => setHideHiddenFiles((current) => !current)} className="dir-table-button">
|
||||||
Hidden Files:
|
|
||||||
{!hideHiddenFiles && <i className={"fa-sharp fa-solid fa-eye-slash"} />}
|
{!hideHiddenFiles && <i className={"fa-sharp fa-solid fa-eye-slash"} />}
|
||||||
{hideHiddenFiles && <i className={"fa-sharp fa-solid fa-eye"} />}
|
{hideHiddenFiles && <i className={"fa-sharp fa-solid fa-eye"} />}
|
||||||
</Button>
|
<input type="text" value={searchText} onChange={() => {}}></input>
|
||||||
<Button onClick={() => setRefresh((current) => !current)}>
|
</div>
|
||||||
|
<div onClick={() => setRefresh((current) => !current)} className="dir-table-button">
|
||||||
<i className="fa-solid fa-arrows-rotate" />
|
<i className="fa-solid fa-arrows-rotate" />
|
||||||
</Button>
|
<input type="text" value={searchText} onChange={() => {}}></input>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<DirectoryTable
|
<DirectoryTable
|
||||||
data={content}
|
data={content}
|
||||||
|
search={searchText}
|
||||||
focusIndex={focusIndex}
|
focusIndex={focusIndex}
|
||||||
setFileName={setFileName}
|
setFileName={setFileName}
|
||||||
setFocusIndex={setFocusIndex}
|
setFocusIndex={setFocusIndex}
|
||||||
|
|
@ -479,7 +552,7 @@ function DirectoryPreview({ fileNameAtom }: DirectoryPreviewProps) {
|
||||||
setSelectedPath={setSelectedPath}
|
setSelectedPath={setSelectedPath}
|
||||||
setRefresh={setRefresh}
|
setRefresh={setRefresh}
|
||||||
/>
|
/>
|
||||||
</>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue