Skip to content

Commit

Permalink
Merge pull request #21 from RRosio/lint
Browse files Browse the repository at this point in the history
Fixed linting errors
  • Loading branch information
RRosio authored Nov 13, 2024
2 parents c34ddcc + 499496b commit 945ccc2
Show file tree
Hide file tree
Showing 11 changed files with 2,188 additions and 17,774 deletions.
9 changes: 4 additions & 5 deletions jupyter-config/server-config/jupyter_fsspec.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"ServerApp": {
"jpserver_extensions": {
"jupyter_fsspec": true
}
"ServerApp": {
"jpserver_extensions": {
"jupyter_fsspec": true
}
}
}
15,377 changes: 0 additions & 15,377 deletions package-lock.json

This file was deleted.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
"watch:labextension": "jupyter labextension watch ."
},
"dependencies": {
"@jupyter/react-components": "^0.15.0",
"@jupyter/web-components": "^0.15.0",
"@jupyterlab/application": "^4.0.0",
"@jupyterlab/apputils": "^4.0.0",
"@jupyterlab/settingregistry": "^4.0.0",
Expand Down Expand Up @@ -93,6 +91,10 @@
"typescript": "~5.0.2",
"yjs": "^13.5.0"
},
"resolutions": {
"@jupyter/react-components": "^0.15.0",
"@jupyter/web-components": "^0.15.0"
},
"sideEffects": [
"style/*.css",
"style/index.js"
Expand Down
231 changes: 115 additions & 116 deletions src/FssFilesysItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,139 +8,138 @@ const UNHOVER = 'var(--jp-layout-color2)';
const SELECTED = 'var(--jp-brand-color2)';

class FssFilesysItem {
root: HTMLElement;
model: any;
filesysName: string;
filesysType: string;
fsInfo: any;
clickSlots: any;
nameField: any;
pathField: any;
_selected = false;
_hovered = false;

constructor(model: any, fsInfo: any, userClickSlots: any) {
this.model = model;
this.filesysName = fsInfo.name;
this.filesysType = fsInfo.type;
this.fsInfo = fsInfo;

this.clickSlots = [];
for (const slot of userClickSlots) {
this.clickSlots.push(slot);
}
root: HTMLElement;
model: any;
filesysName: string;
filesysType: string;
fsInfo: any;
clickSlots: any;
nameField: any;
pathField: any;
_selected = false;
_hovered = false;

constructor(model: any, fsInfo: any, userClickSlots: any) {
this.model = model;
this.filesysName = fsInfo.name;
this.filesysType = fsInfo.type;
this.fsInfo = fsInfo;

this.clickSlots = [];
for (const slot of userClickSlots) {
this.clickSlots.push(slot);
}

let fsItem = document.createElement('div');
fsItem.classList.add('jfss-fsitem-root');
fsItem.addEventListener('mouseenter', this.handleFsysHover.bind(this));
fsItem.addEventListener('mouseleave', this.handleFsysHover.bind(this));
fsItem.dataset.fssname = fsInfo.name;
this.root = fsItem;
const fsItem = document.createElement('div');
fsItem.classList.add('jfss-fsitem-root');
fsItem.addEventListener('mouseenter', this.handleFsysHover.bind(this));
fsItem.addEventListener('mouseleave', this.handleFsysHover.bind(this));
fsItem.dataset.fssname = fsInfo.name;
this.root = fsItem;

// Set the tooltip
this.root.title = `Root Path: ${fsInfo.path}`;
// Set the tooltip
this.root.title = `Root Path: ${fsInfo.path}`;

this.nameField = document.createElement('div');
this.nameField.classList.add('jfss-fsitem-name');
this.nameField.innerText = this.filesysName;
fsItem.appendChild(this.nameField);
this.nameField = document.createElement('div');
this.nameField.classList.add('jfss-fsitem-name');
this.nameField.innerText = this.filesysName;
fsItem.appendChild(this.nameField);

this.pathField = document.createElement('div');
this.pathField.classList.add('jfss-fsitem-type');
this.pathField.innerText = 'Path: ' + fsInfo.path;
fsItem.appendChild(this.pathField);
this.pathField = document.createElement('div');
this.pathField.classList.add('jfss-fsitem-type');
this.pathField.innerText = 'Path: ' + fsInfo.path;
fsItem.appendChild(this.pathField);

fsItem.addEventListener('click', this.handleClick.bind(this));
fsItem.addEventListener('contextmenu', this.handleContext.bind(this));
}
fsItem.addEventListener('click', this.handleClick.bind(this));
fsItem.addEventListener('contextmenu', this.handleContext.bind(this));
}

handleContext(event: any) {
// Prevent ancestors from adding extra context boxes
event.stopPropagation();

handleContext(event: any) {
// Prevent ancestors from adding extra context boxes
event.stopPropagation();

// Prevent default browser context menu (unless shift pressed
// as per usual JupyterLab conventions)
if (!event.shiftKey) {
event.preventDefault();
} else {
return;
}

// Make/add the context menu
let context = new FssContextMenu(this.model);
context.root.dataset.fss = this.root.dataset.fss;
let body = document.getElementsByTagName('body')[0];
body.appendChild(context.root);

// Position it under the mouse (top left corner normally,
// or bottom right if that corner is out-of-viewport)
let parentRect = body.getBoundingClientRect();
let contextRect = context.root.getBoundingClientRect();
let xCoord = event.clientX - parentRect.x;
let yCoord = event.clientY - parentRect.y;
let spacing = 12;
if (xCoord + contextRect.width > window.innerWidth || yCoord + contextRect.height > window.innerHeight) {
// Context menu is cut off when positioned under mouse at top left corner,
// use the bottom right corner instead
xCoord -= contextRect.width;
yCoord -= contextRect.height;
// Shift the menu so the mouse is inside it, not at the corner/edge
xCoord += spacing;
yCoord += spacing;
} else {
// Shift the menu so the mouse is inside it, not at the corner/edge
xCoord -= spacing;
yCoord -= spacing;
}

context.root.style.left = `${xCoord}` + 'px';
context.root.style.top = `${yCoord}` + 'px';
// Prevent default browser context menu (unless shift pressed
// as per usual JupyterLab conventions)
if (!event.shiftKey) {
event.preventDefault();
} else {
return;
}

setMetadata(value: string) {
this.root.dataset.fss = value;
// Make/add the context menu
const context = new FssContextMenu(this.model);
context.root.dataset.fss = this.root.dataset.fss;
const body = document.getElementsByTagName('body')[0];
body.appendChild(context.root);

// Position it under the mouse (top left corner normally,
// or bottom right if that corner is out-of-viewport)
const parentRect = body.getBoundingClientRect();
const contextRect = context.root.getBoundingClientRect();
let xCoord = event.clientX - parentRect.x;
let yCoord = event.clientY - parentRect.y;
const spacing = 12;
if (
xCoord + contextRect.width > window.innerWidth ||
yCoord + contextRect.height > window.innerHeight
) {
// Context menu is cut off when positioned under mouse at top left corner,
// use the bottom right corner instead
xCoord -= contextRect.width;
yCoord -= contextRect.height;
// Shift the menu so the mouse is inside it, not at the corner/edge
xCoord += spacing;
yCoord += spacing;
} else {
// Shift the menu so the mouse is inside it, not at the corner/edge
xCoord -= spacing;
yCoord -= spacing;
}

set selected(value: boolean) {
this._selected = value;
if (value) {
this.root.style.backgroundColor = SELECTED;
}
else {
this.hovered = this._hovered;
}
context.root.style.left = `${xCoord}` + 'px';
context.root.style.top = `${yCoord}` + 'px';
}

setMetadata(value: string) {
this.root.dataset.fss = value;
}

set selected(value: boolean) {
this._selected = value;
if (value) {
this.root.style.backgroundColor = SELECTED;
} else {
this.hovered = this._hovered;
}
}

set hovered(state: boolean) {
this._hovered = state;
if (this._selected) {
this.root.style.backgroundColor = SELECTED;
}
else {
if (state) {
this.root.style.backgroundColor = HOVER;
}
else {
this.root.style.backgroundColor = UNHOVER;
}
set hovered(state: boolean) {
this._hovered = state;
if (this._selected) {
this.root.style.backgroundColor = SELECTED;
} else {
if (state) {
this.root.style.backgroundColor = HOVER;
} else {
this.root.style.backgroundColor = UNHOVER;
}
}
}

handleFsysHover(event: any) {
if (event.type == 'mouseenter') {
this.hovered = true;
}
else {
this.hovered = false;
}
handleFsysHover(event: any) {
if (event.type === 'mouseenter') {
this.hovered = true;
} else {
this.hovered = false;
}
}

handleClick(_event: any) {
this.selected = true;
for (const slot of this.clickSlots) {
slot(this.fsInfo);
}
handleClick(_event: any) {
this.selected = true;
for (const slot of this.clickSlots) {
slot(this.fsInfo);
}
}
}

export { FssFilesysItem };
export { FssFilesysItem };
Loading

0 comments on commit 945ccc2

Please sign in to comment.