Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sidebarnav #750

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,751 changes: 1,652 additions & 99 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@
"@codemirror/theme-one-dark": "^6.1.2",
"@codemirror/view": "^6.28.1",
"@lezer/highlight": "^1.2.0",
"@react-aria/listbox": "^3.12.1",
philippark marked this conversation as resolved.
Show resolved Hide resolved
"@react-stately/list": "^3.10.5",
"@replit/codemirror-indentation-markers": "^6.5.2",
"@replit/codemirror-interact": "^6.3.1",
"@replit/codemirror-lang-svelte": "^6.0.0",
Expand Down Expand Up @@ -139,9 +141,11 @@
"openai": "^4.51.0",
"prettier-plugin-svelte": "^3.2.4",
"react": "^18.3.1",
"react-aria": "^3.33.1",
"react-bootstrap": "^2.10.2",
"react-dom": "^18.3.1",
"react-router-dom": "^6.23.1",
"react-stately": "^3.31.1",
"sharedb": "^5.0.2",
"sharedb-client-browser": "^5.0.1",
"vizhub-ui": "^3.23.0",
Expand Down
4 changes: 2 additions & 2 deletions src/client/VZSidebar/DirectoryListing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const DirectoryListing = ({
);

return (
<>
<div tabIndex={0} onKeyDown={(e)=>e.key === 'Enter' && handleClick()}>
<Item
id={path}
name={name}
Expand Down Expand Up @@ -83,6 +83,6 @@ export const DirectoryListing = ({
})}
</div>
) : null}
</>
</div>
);
};
2 changes: 2 additions & 0 deletions src/client/VZSidebar/FileListing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const FileListing = ({
);

return (
<div tabIndex = {0} onKeyDown={(e)=>e.key==='Enter' && handleDoubleClick()}>
<Item
id={fileId}
name={name}
Expand All @@ -54,5 +55,6 @@ export const FileListing = ({
</i>
{name}
</Item>
</div>
);
};
2 changes: 0 additions & 2 deletions src/client/VZSidebar/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ export const Item = ({
? null
: handleDoubleClick
}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
<div className="name">
{isRenaming ? (
Expand Down
172 changes: 172 additions & 0 deletions src/client/VZSidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ import { VZCodeContext } from '../VZCodeContext';
import { Listing } from './Listing';
import { useDragAndDrop } from './useDragAndDrop';
import './styles.scss';
import type {AriaListBoxProps} from 'react-aria';
import {mergeProps, useFocusRing, useGridList, useGridListItem} from 'react-aria';
import {useListState} from 'react-stately';
import {useEffect, useRef} from 'react';

import {Item} from 'react-stately';

// TODO turn this UI back on when we are actually detecting
// the connection status.
Expand All @@ -38,6 +44,33 @@ export const VZSidebar = ({
reportBugTooltipText?: string;
openKeyboardShortcuts?: string;
}) => {

//TODO: Move these to useKeyboardShortcuts.ts
let gridListRef = useRef(null);

useEffect(() => {
const handleKeyDown = (event) => {
// Check if Alt key and '3' are pressed together
if (event.altKey && event.key === '3') {
// Prevent default action to avoid any unwanted behavior
event.preventDefault();
// Check if the gridListRef.current is not null and focus on it
if (gridListRef.current) {
gridListRef.current.focus();
}
}
};

// Attach the event listener to the window object
window.addEventListener('keydown', handleKeyDown);

// Cleanup the event listener on component unmount
return () => {
window.removeEventListener('keydown', handleKeyDown);
};
}, []);


const {
files,
openTab,
Expand Down Expand Up @@ -94,6 +127,58 @@ export const VZSidebar = ({
handleDrop,
} = useDragAndDrop();

function List(props) {
let state = useListState(props);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The style of this codebase prefers const over let. Please prefer const where possible. Thanks!

philippark marked this conversation as resolved.
Show resolved Hide resolved
let ref = gridListRef;
let { gridProps } = useGridList(props, state, ref);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let { gridProps } = useGridList(props, state, ref);
const { gridProps } = useGridList(props, state, ref);


return (
<div {...gridProps} ref={ref} className="list">
{[...state.collection].map((item) => (
<ListItem key={item.key} item={item} state={state} />
))}
</div>
);
}

function ListItem({ item, state }) {
const { fileId } = item as FileTreeFile;
const { path } = item as FileTree;
const key = fileId ? fileId : path;

let ref = useRef(null);
philippark marked this conversation as resolved.
Show resolved Hide resolved

let { rowProps, gridCellProps, isPressed } = useGridListItem(
philippark marked this conversation as resolved.
Show resolved Hide resolved
{ node: item },
state,
ref
);

if (isPressed){
gridListRef = ref;
}

let { isFocusVisible, focusProps } = useFocusRing();
philippark marked this conversation as resolved.
Show resolved Hide resolved
let showCheckbox = state.selectionManager.selectionMode !== 'none' &&
philippark marked this conversation as resolved.
Show resolved Hide resolved
state.selectionManager.selectionBehavior === 'toggle';

return (
<li
{...mergeProps(rowProps, focusProps)}
ref={ref}
className={`${isPressed ? 'pressed' : ''} ${
isFocusVisible ? 'focus-visible' : ''
}`}
>
<div {...gridCellProps}>
{item.rendered}
</div>
</li>
);
}



return (
<div
className="vz-sidebar"
Expand Down Expand Up @@ -199,11 +284,94 @@ export const VZSidebar = ({
</div>
</div>
) : filesExist ? (

<List
aria-label="Example dynamic collection List"
selectionMode="multiple"
selectionBehavior="replace"
items={fileTree.children}
>
{(item) => {
const { fileId } = item as FileTreeFile;
const { path } = item as FileTree;
const key = fileId ? fileId : path;
const itemKey = `item-${key}`;

return(
<Item key = {itemKey}>
<Listing
key={key}
entity={item}
handleFileClick={handleFileClick}
handleFileDoubleClick={
handleFileDoubleClick
}
/>
</Item>
)
}}
</List>


/*
<List
aria-label="Example List"
selectionMode="multiple"
selectionBehavior="replace"
onAction={(key) => handleFileDoubleClick(key)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this one can be simplified.

Suggested change
onAction={(key) => handleFileDoubleClick(key)}
onAction={handleFileDoubleClick}

>
{fileTree.children.map((entity) => {
const { fileId } = entity as FileTreeFile;
const { path } = entity as FileTree;
const key = fileId ? fileId : path;
return (
<Item key={key}>
Test
<Listing
key={key}
entity={entity}
handleFileClick={handleFileClick}
handleFileDoubleClick={
handleFileDoubleClick
}
/>

</Item>
);
})}
</List>
*/

/*
<ListBox label="Alignment" selectionMode="single">
{fileTree.children.map((entity) => {
const { fileId } = entity as FileTreeFile;
const { path } = entity as FileTree;
const key = fileId ? fileId : path;
return (
<Item key={key}>
<Listing
key={key}
entity={entity}
handleFileClick={handleFileClick}
handleFileDoubleClick={
handleFileDoubleClick
}
/>

</Item>
);
})}
</ListBox>
*/

/*
fileTree.children.map((entity) => {
const { fileId } = entity as FileTreeFile;
const { path } = entity as FileTree;
const key = fileId ? fileId : path;
return (

<Listing
key={key}
entity={entity}
Expand All @@ -212,8 +380,12 @@ export const VZSidebar = ({
handleFileDoubleClick
}
/>


);
})
*/

) : (
<div className="empty">
<div className="empty-text">
Expand Down
41 changes: 41 additions & 0 deletions src/client/VZSidebar/styles.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,45 @@
.vz-sidebar {
.list {
list-style: none;
}

.list li {
outline: none;
cursor: default;
}

.list li:nth-child(2n) {
background: var(--spectrum-alias-highlight-hover);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the --spectrum-alias-highlight-hover definition coming from? Did you verify that this resolves correctly? We may need a CSS import to make this work.

}

.list li.pressed {
background: var(--spectrum-global-color-gray-200);
}

.list li[aria-selected=true] {
background: slateblue;
color: white;
}

.list li.focus-visible {
outline: 2px solid slateblue;
outline-offset: -3px;
}

.list li.focus-visible[aria-selected=true] {
outline-color: white;
}

.list li[aria-disabled] {
opacity: 0.4;
}

.list [role=gridcell] {
display: flex;
align-items: center;
gap: 4px;
}

height: 100%;
color: var(--vh-color-neutral-04);
background: var(--vh-color-neutral-01);
Expand Down
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"compilerOptions": {
"jsx": "react-jsx",
"skipLibCheck": true,
"esModuleInterop": true
"esModuleInterop": true,
"target": "ES2015",
"moduleResolution":"node",
},
"include": ["src/**/*"],
"//": "TODO - remove this when we have this change: https://github.com/vitest-dev/vitest/issues/3622",
Expand Down
Loading