Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 626ae02df0 | |||
| 7f47ca84fa | |||
| eac4fb423e | |||
| 14ac0f46de | |||
| 5a565f8165 | |||
| 12cbc68db6 |
+114
-52
@@ -4,87 +4,149 @@
|
|||||||
|
|
||||||
### Version 0.1.0
|
### Version 0.1.0
|
||||||
|
|
||||||
**Goal:** Barebone frontend with a real backend core.
|
**Goal:** Finish the base application shell, auth, and platform foundations.
|
||||||
|
|
||||||
#### Architecture
|
#### Architecture and Delivery
|
||||||
|
|
||||||
- [ ] Project-Structure
|
- [x] Project-Structure
|
||||||
- [ ] Stack-Decisions
|
- [x] Stack-Decisions
|
||||||
- [ ] Proxy
|
- [x] Proxy
|
||||||
- [ ] Local-Prod-NGINX-Proxy
|
- [x] Local-Dev-Vite-Proxy
|
||||||
- [ ] Static-Frontend-Serving
|
- [x] Local-Prod-NGINX-Proxy
|
||||||
- [ ] First-Request-Web-Loader
|
- [x] First-Request-Web-Loader
|
||||||
- [ ] Bootstrap-Document
|
- [x] Bootstrap-Document
|
||||||
- [ ] Route-Intent-Handoff
|
- [x] Route-Intent-Handoff
|
||||||
- [ ] Tiny-First-Paint-Budget
|
- [x] Tiny-First-Paint-Budget
|
||||||
- [ ] Dev-and-Prod-Builds
|
- [x] Dev-and-Prod-Builds
|
||||||
- [x] Local-Dev-Just-Commands
|
- [x] Local-Dev-Just-Commands
|
||||||
- [x] Local-Dev-Docker-Compose
|
- [x] Local-Dev-Docker-Compose
|
||||||
- [ ] Local-Prod-Just-Commands
|
- [x] Local-Prod-Just-Commands
|
||||||
- [ ] Local-Prod-Docker-Compose
|
- [x] Local-Prod-Docker-Compose
|
||||||
- [ ] Frontend-Production-Dockerfile
|
- [x] Frontend-Production-Dockerfile
|
||||||
- [ ] Frontend-docker-bake
|
- [x] Frontend-docker-bake
|
||||||
|
|
||||||
#### Backend
|
#### Backend — Done Foundations
|
||||||
|
|
||||||
|
- [x] Bootstrap-Persistence
|
||||||
|
- [x] Installation-Step
|
||||||
|
- [x] Mode-Step
|
||||||
|
- [x] Admin-Step
|
||||||
|
- [x] Structure-Step
|
||||||
|
- [x] Bootstrap-State-Authority
|
||||||
|
- [x] Development-Bootstrap-Reset
|
||||||
|
- [x] Base-Schema
|
||||||
|
- [x] Installations
|
||||||
|
- [x] Users
|
||||||
|
- [x] User-Homes
|
||||||
|
- [x] Organizations
|
||||||
|
- [x] Departments
|
||||||
|
- [x] Teams
|
||||||
|
- [x] Projects
|
||||||
|
- [x] Workspaces
|
||||||
|
- [x] Membership-Tables
|
||||||
|
- [x] App-Shell-Read-API
|
||||||
|
- [x] App-Shell-State-Endpoint
|
||||||
|
- [x] Bootstrap-Read-Endpoints
|
||||||
|
- [x] Shell-Tree-Hydration
|
||||||
|
- [x] Web-Route-Scaffolds
|
||||||
|
- [x] Session-Endpoint-Scaffold
|
||||||
|
- [x] Bootstrap-Endpoint-Scaffold
|
||||||
|
- [x] Current-User-Endpoint-Scaffold
|
||||||
|
|
||||||
|
#### Backend — Remaining for 0.1.0
|
||||||
|
|
||||||
- [ ] Auth
|
- [ ] Auth
|
||||||
- [ ] Session-Flow
|
- [ ] Session-Flow
|
||||||
- [ ] Login-Logout-Foundation
|
- [ ] Login-Logout-Foundation
|
||||||
- [ ] Authentication
|
- [ ] Authentication
|
||||||
- [ ] User
|
- [ ] Current-User-Implementation
|
||||||
- [ ] Base-Model
|
- [ ] POSIX-Lite-File-Persistence-Foundation
|
||||||
|
- [ ] Mounted-Storage-Root-Config
|
||||||
|
- [ ] Project-Folder-Creation-On-Backend
|
||||||
|
- [ ] moku.project.json
|
||||||
|
- [ ] Item-Folder-Creation
|
||||||
|
- [ ] item.json
|
||||||
|
- [ ] schema.json
|
||||||
|
- [ ] data.json
|
||||||
|
- [ ] DB-To-Files-Write-Flow
|
||||||
|
- [ ] User-and-Workspace-Domain-Readiness
|
||||||
- [ ] Base-Workspace
|
- [ ] Base-Workspace
|
||||||
- [ ] Folders-and-Subfolders
|
- [ ] Boards
|
||||||
- [ ] Boards
|
- [ ] Dashboard
|
||||||
- [ ] Dashboard
|
|
||||||
- [ ] Organization
|
|
||||||
- [ ] Base-Model
|
|
||||||
- [ ] Access-Rules-and-Membership
|
|
||||||
- [ ] Workspace
|
|
||||||
- [ ] Folders-and-Subfolders
|
|
||||||
- [ ] API
|
- [ ] API
|
||||||
|
- [ ] Real-Organizations-Read-Endpoint
|
||||||
|
- [ ] Real-Workspaces-Read-Endpoint
|
||||||
|
- [ ] Tree-Mutation-Endpoints
|
||||||
|
- [ ] Project-Creation-Endpoint
|
||||||
|
|
||||||
#### Frontend
|
#### Frontend — Done Foundations
|
||||||
|
|
||||||
- [x] Foundation
|
- [x] Foundation
|
||||||
- [x] Typography
|
- [x] Typography
|
||||||
- [x] Icons
|
- [x] Icons
|
||||||
- [ ] App Shell
|
- [x] App-Shell
|
||||||
|
- [x] Left-Rail
|
||||||
|
- [x] Top-Bar
|
||||||
|
- [x] Server-Dock
|
||||||
|
- [x] Department-Selector
|
||||||
|
- [x] Theme-Toggle
|
||||||
|
- [x] Notifications-Menu
|
||||||
|
- [x] Profile-Menu
|
||||||
|
- [x] Responsive-Shell
|
||||||
|
- [x] Collapsible-Shell
|
||||||
|
- [x] Mobile-Bottom-Nav
|
||||||
|
- [x] Mobile-Workspace-Browser
|
||||||
|
- [x] Mobile-Workspace-Views
|
||||||
|
- [x] Context-Menus
|
||||||
|
- [x] Workspace-Context-Menu
|
||||||
|
- [x] Project-Context-Menu
|
||||||
|
- [x] Bootstrap-Workspace-Home
|
||||||
|
- [x] Bootstrap-Wizard
|
||||||
|
- [x] Bootstrap-Step-Submission
|
||||||
|
- [x] App-Shell-Reload-After-Bootstrap
|
||||||
|
- [x] Project-Menu
|
||||||
|
- [x] Folders-and-Subfolders
|
||||||
|
- [x] Rooted-From-Department
|
||||||
|
- [x] Long-Press-Drag-and-Drop
|
||||||
|
- [x] Workspace-Tree
|
||||||
|
- [x] Folders-and-Subfolders
|
||||||
|
- [x] Long-Press-Drag-and-Drop
|
||||||
|
- [x] App-Shell-Hydration
|
||||||
|
|
||||||
|
#### Frontend — Remaining for 0.1.0
|
||||||
|
|
||||||
- [ ] Primitives
|
- [ ] Primitives
|
||||||
- [ ] Button
|
- [ ] Button
|
||||||
- [ ] IconButton
|
- [ ] IconButton
|
||||||
- [ ] Input
|
- [ ] Input
|
||||||
- [ ] Surface
|
- [ ] Surface
|
||||||
- [ ] Nav-Bar
|
|
||||||
- [ ] Workspace-Switching
|
- [ ] Workspace-Switching
|
||||||
- [ ] Workspace-Home
|
- [ ] Real-Workspace-Home
|
||||||
|
- [ ] Real-Workspace-Tree-Hydration
|
||||||
|
- [ ] Create-Project-Flow
|
||||||
|
- [ ] Persist-Tree-Mutations
|
||||||
|
- [ ] Connect-Tree-Interactions-To-Backend-Data
|
||||||
|
|
||||||
### Version 0.2.0
|
### Version 0.2.0
|
||||||
|
|
||||||
**Goal:** First real work surface.
|
**Goal:** Build the plugin app system on top of the base platform. And core app plugins like calendar, board, docs and text channels
|
||||||
|
|
||||||
- [ ] Table
|
|
||||||
- [ ] CVA
|
|
||||||
- [ ] Storyboard
|
|
||||||
- [ ] Theme-System
|
|
||||||
- [ ] Theme-Registry
|
|
||||||
- [ ] Built-In-Theme-Presets
|
|
||||||
- [ ] Active-Theme-Persistence
|
|
||||||
- [ ] Theme-Switcher
|
|
||||||
- [ ] Theme-JSON-Upload
|
|
||||||
- [ ] Theme-JSON-Import-Validation
|
|
||||||
- [ ] Community-Theme-Readiness
|
|
||||||
|
|
||||||
### Version 0.3.0
|
### Version 0.3.0
|
||||||
|
|
||||||
**Goal:** Documents and system hardening.
|
**Goal:** Communications and Collaboration (Email System, Reminder System, and Live Collaboration on Documents)
|
||||||
|
|
||||||
- [ ] Document
|
|
||||||
- [ ] Accessibility-Rules
|
|
||||||
- [ ] Motion-Foundation
|
|
||||||
|
|
||||||
### Version 0.4.0
|
### Version 0.4.0
|
||||||
|
|
||||||
- [ ] Gantt-Board
|
**Goal:** Introduce the POSIX-based file system drive direction with OnlyOffice + S3 blob storage
|
||||||
- [ ] Calendar
|
|
||||||
- [ ] Timeline
|
### Version 0.5.0
|
||||||
|
|
||||||
|
**Goal:** File Sharing and Per File Permissions
|
||||||
|
|
||||||
|
### Version 0.6.0
|
||||||
|
|
||||||
|
**Goal:** Git as a core plugin
|
||||||
|
|
||||||
|
### Version 0.7.0
|
||||||
|
|
||||||
|
**Goal:** Full Automation System (Extensive)
|
||||||
|
|||||||
@@ -0,0 +1,204 @@
|
|||||||
|
import { For, Show, createEffect, createMemo, createSignal, onMount, type JSX } from "solid-js";
|
||||||
|
import { Portal } from "solid-js/web";
|
||||||
|
import { ChevronRight, Plus } from "../../../lib/icons";
|
||||||
|
import {
|
||||||
|
getProjectContextMenuEyebrow,
|
||||||
|
getProjectContextMenuSections,
|
||||||
|
type ProjectContextMenuAction,
|
||||||
|
type ProjectMenuTarget,
|
||||||
|
type WorkspaceContextMenuShortcut,
|
||||||
|
} from "../data/shell.data";
|
||||||
|
import styles from "../WorkspaceContextMenu/WorkspaceContextMenu.module.scss";
|
||||||
|
|
||||||
|
type ShortcutPlatform = "mac" | "windows";
|
||||||
|
|
||||||
|
type NavigatorWithUserAgentData = Navigator & {
|
||||||
|
userAgentData?: {
|
||||||
|
platform?: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
type ProjectContextMenuPosition = {
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
type ProjectContextMenuProps = {
|
||||||
|
target: ProjectMenuTarget | null;
|
||||||
|
position: ProjectContextMenuPosition | null;
|
||||||
|
onClose: VoidFunction;
|
||||||
|
onSelect: (action: ProjectContextMenuAction, target: ProjectMenuTarget) => void;
|
||||||
|
menuRef: (element: HTMLDivElement) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getShortcutPlatform = (): ShortcutPlatform => {
|
||||||
|
if (typeof navigator === "undefined") {
|
||||||
|
return "mac";
|
||||||
|
}
|
||||||
|
|
||||||
|
const navigatorWithUserAgentData = navigator as NavigatorWithUserAgentData;
|
||||||
|
const platform =
|
||||||
|
typeof navigatorWithUserAgentData.userAgentData?.platform === "string"
|
||||||
|
? navigatorWithUserAgentData.userAgentData.platform
|
||||||
|
: navigator.platform;
|
||||||
|
|
||||||
|
return /mac|iphone|ipad|ipod/i.test(platform) ? "mac" : "windows";
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatShortcut = (shortcut: WorkspaceContextMenuShortcut, platform: ShortcutPlatform): string => {
|
||||||
|
const keyLabel = (() => {
|
||||||
|
switch (shortcut.key) {
|
||||||
|
case "enter":
|
||||||
|
return platform === "mac" ? "↩" : "Enter";
|
||||||
|
case "delete":
|
||||||
|
return platform === "mac" ? "⌫" : "Del";
|
||||||
|
default:
|
||||||
|
return shortcut.key.toUpperCase();
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
const modifierLabels =
|
||||||
|
shortcut.modifiers?.map((modifier) => {
|
||||||
|
switch (modifier) {
|
||||||
|
case "meta":
|
||||||
|
return platform === "mac" ? "⌘" : "Ctrl";
|
||||||
|
case "alt":
|
||||||
|
return platform === "mac" ? "⌥" : "Alt";
|
||||||
|
case "shift":
|
||||||
|
return platform === "mac" ? "⇧" : "Shift";
|
||||||
|
}
|
||||||
|
}) ?? [];
|
||||||
|
|
||||||
|
return platform === "mac" ? `${modifierLabels.join("")}${keyLabel}` : [...modifierLabels, keyLabel].join("+");
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ProjectContextMenu = (props: ProjectContextMenuProps): JSX.Element => {
|
||||||
|
const [activeSubmenuActionId, setActiveSubmenuActionId] = createSignal<string | null>(null);
|
||||||
|
const [shortcutPlatform, setShortcutPlatform] = createSignal<ShortcutPlatform>("mac");
|
||||||
|
const sections = createMemo(() => (props.target ? getProjectContextMenuSections(props.target) : []));
|
||||||
|
const isCreateAction = (action: ProjectContextMenuAction): boolean => action.id.startsWith("new-");
|
||||||
|
const menuState = createMemo<{
|
||||||
|
target: ProjectMenuTarget;
|
||||||
|
position: ProjectContextMenuPosition;
|
||||||
|
} | null>(() => (props.target && props.position ? { target: props.target, position: props.position } : null));
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
setShortcutPlatform(getShortcutPlatform());
|
||||||
|
});
|
||||||
|
|
||||||
|
createEffect(() => {
|
||||||
|
void props.target;
|
||||||
|
setActiveSubmenuActionId(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Show when={menuState()}>
|
||||||
|
{(resolvedMenuState): JSX.Element => {
|
||||||
|
const target = resolvedMenuState().target;
|
||||||
|
const position = resolvedMenuState().position;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Portal>
|
||||||
|
<div
|
||||||
|
ref={props.menuRef}
|
||||||
|
class={styles.menu}
|
||||||
|
role="menu"
|
||||||
|
aria-label={`${target.label} project context menu`}
|
||||||
|
style={{ left: `${position.x}px`, top: `${position.y}px` }}
|
||||||
|
>
|
||||||
|
<Show when={target.kind !== "surface"}>
|
||||||
|
<header class={styles.header}>
|
||||||
|
<span class={styles.eyebrow}>{getProjectContextMenuEyebrow(target)}</span>
|
||||||
|
<strong class={styles.title}>{target.label}</strong>
|
||||||
|
</header>
|
||||||
|
</Show>
|
||||||
|
|
||||||
|
<div class={styles.sectionList}>
|
||||||
|
<For each={sections()}>
|
||||||
|
{(section): JSX.Element => (
|
||||||
|
<section class={styles.section}>
|
||||||
|
<Show when={section.label}>
|
||||||
|
<span class={styles.sectionLabel}>{section.label}</span>
|
||||||
|
</Show>
|
||||||
|
<div class={styles.actionList}>
|
||||||
|
<For each={section.items}>
|
||||||
|
{(action): JSX.Element => {
|
||||||
|
const isSubmenuOpen = () => activeSubmenuActionId() === action.id;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div class={styles.actionItem} onMouseEnter={() => setActiveSubmenuActionId(action.children ? action.id : null)}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
role="menuitem"
|
||||||
|
classList={{
|
||||||
|
[styles.action]: true,
|
||||||
|
[styles.actionCreate]: isCreateAction(action),
|
||||||
|
[styles.actionDanger]: action.tone === "danger",
|
||||||
|
[styles.actionSubmenuOpen]: isSubmenuOpen(),
|
||||||
|
}}
|
||||||
|
onClick={() => {
|
||||||
|
if (action.children) {
|
||||||
|
setActiveSubmenuActionId(isSubmenuOpen() ? null : action.id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
props.onSelect(action, target);
|
||||||
|
props.onClose();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Show when={isCreateAction(action)}>
|
||||||
|
<span class={styles.actionCreateIcon} aria-hidden="true">
|
||||||
|
<Plus size={14} strokeWidth={2.25} />
|
||||||
|
</span>
|
||||||
|
</Show>
|
||||||
|
<span class={styles.actionLabel}>{action.label}</span>
|
||||||
|
<div class={styles.actionMeta}>
|
||||||
|
<Show when={action.shortcut}>
|
||||||
|
<span class={styles.actionShortcut}>{formatShortcut(action.shortcut!, shortcutPlatform())}</span>
|
||||||
|
</Show>
|
||||||
|
<Show when={action.children}>
|
||||||
|
<ChevronRight class={styles.actionChevron} size={16} strokeWidth={2} />
|
||||||
|
</Show>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<Show when={action.children && isSubmenuOpen()}>
|
||||||
|
<div class={styles.submenu} role="menu" aria-label={`${action.label} submenu`}>
|
||||||
|
<div class={styles.submenuList}>
|
||||||
|
<For each={action.children ?? []}>
|
||||||
|
{(childAction): JSX.Element => (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
role="menuitem"
|
||||||
|
classList={{
|
||||||
|
[styles.action]: true,
|
||||||
|
[styles.actionDanger]: childAction.tone === "danger",
|
||||||
|
}}
|
||||||
|
onClick={() => {
|
||||||
|
props.onSelect(childAction, target);
|
||||||
|
props.onClose();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span class={styles.actionLabel}>{childAction.label}</span>
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</For>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Show>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
</For>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
)}
|
||||||
|
</For>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Portal>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
</Show>
|
||||||
|
);
|
||||||
|
};
|
||||||
+120
@@ -0,0 +1,120 @@
|
|||||||
|
import { createEffect, createSignal, onCleanup } from "solid-js";
|
||||||
|
import type { ProjectMenuTarget } from "../data/shell.data";
|
||||||
|
|
||||||
|
type ProjectContextMenuState = {
|
||||||
|
target: ProjectMenuTarget;
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
const readRootPixelToken = (name: string, fallback: number): number => {
|
||||||
|
if (typeof window === "undefined") {
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
const value = window.getComputedStyle(document.documentElement).getPropertyValue(name).trim();
|
||||||
|
const parsed = Number.parseFloat(value);
|
||||||
|
|
||||||
|
if (!Number.isFinite(parsed)) {
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value.endsWith("px")) {
|
||||||
|
return parsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
return parsed * 16;
|
||||||
|
};
|
||||||
|
|
||||||
|
const clampMenuPosition = (value: number, min: number, max: number): number => {
|
||||||
|
if (max <= min) {
|
||||||
|
return min;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.min(Math.max(value, min), max);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const createProjectContextMenuController = () => {
|
||||||
|
const [menuState, setMenuState] = createSignal<ProjectContextMenuState | null>(null);
|
||||||
|
let menuRef: HTMLDivElement | undefined;
|
||||||
|
|
||||||
|
const closeMenu = (): void => {
|
||||||
|
setMenuState(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const repositionMenu = (): void => {
|
||||||
|
if (typeof window === "undefined" || !menuRef) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const current = menuState();
|
||||||
|
|
||||||
|
if (!current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const viewportPadding = readRootPixelToken("--space-4", 16);
|
||||||
|
const rect = menuRef.getBoundingClientRect();
|
||||||
|
const nextX = clampMenuPosition(current.x, viewportPadding, window.innerWidth - rect.width - viewportPadding);
|
||||||
|
const nextY = clampMenuPosition(current.y, viewportPadding, window.innerHeight - rect.height - viewportPadding);
|
||||||
|
|
||||||
|
if (nextX === current.x && nextY === current.y) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setMenuState({ ...current, x: nextX, y: nextY });
|
||||||
|
};
|
||||||
|
|
||||||
|
const openMenu = (event: MouseEvent, target: ProjectMenuTarget): void => {
|
||||||
|
event.preventDefault();
|
||||||
|
setMenuState({ target, x: event.clientX, y: event.clientY });
|
||||||
|
};
|
||||||
|
|
||||||
|
createEffect(() => {
|
||||||
|
if (!menuState() || typeof window === "undefined") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const frame = window.requestAnimationFrame(() => {
|
||||||
|
repositionMenu();
|
||||||
|
});
|
||||||
|
|
||||||
|
const handlePointerDown = (event: PointerEvent): void => {
|
||||||
|
if (!menuRef?.contains(event.target as Node)) {
|
||||||
|
closeMenu();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleKeyDown = (event: KeyboardEvent): void => {
|
||||||
|
if (event.key === "Escape") {
|
||||||
|
closeMenu();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleViewportChange = (): void => {
|
||||||
|
closeMenu();
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener("pointerdown", handlePointerDown);
|
||||||
|
window.addEventListener("resize", handleViewportChange);
|
||||||
|
window.addEventListener("scroll", handleViewportChange, true);
|
||||||
|
window.addEventListener("keydown", handleKeyDown);
|
||||||
|
|
||||||
|
onCleanup(() => {
|
||||||
|
window.cancelAnimationFrame(frame);
|
||||||
|
document.removeEventListener("pointerdown", handlePointerDown);
|
||||||
|
window.removeEventListener("resize", handleViewportChange);
|
||||||
|
window.removeEventListener("scroll", handleViewportChange, true);
|
||||||
|
window.removeEventListener("keydown", handleKeyDown);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
menuState,
|
||||||
|
openMenu,
|
||||||
|
closeMenu,
|
||||||
|
setMenuRef: (element: HTMLDivElement): void => {
|
||||||
|
menuRef = element;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -9,6 +9,15 @@
|
|||||||
justify-items: center;
|
justify-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.rootDragMode {
|
||||||
|
user-select: none;
|
||||||
|
cursor: grabbing;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rootDragMode .treeItem {
|
||||||
|
cursor: grabbing;
|
||||||
|
}
|
||||||
|
|
||||||
.trigger {
|
.trigger {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
@@ -38,9 +47,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.triggerOpen {
|
.triggerOpen {
|
||||||
border-color: color-mix(in srgb, var(--color-border-strong) 22%, transparent);
|
border-color: color-mix(in srgb, var(--color-accent-strong) 22%, var(--color-border-strong));
|
||||||
background: color-mix(in srgb, var(--color-surface) 92%, transparent);
|
background: color-mix(in srgb, var(--color-accent-soft) 26%, var(--color-surface));
|
||||||
box-shadow: var(--shadow-soft);
|
box-shadow: 0 10px 28px color-mix(in srgb, black 8%, transparent);
|
||||||
}
|
}
|
||||||
|
|
||||||
.triggerCompact {
|
.triggerCompact {
|
||||||
@@ -83,19 +92,14 @@
|
|||||||
gap: 0.12rem;
|
gap: 0.12rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.eyebrow,
|
.eyebrow {
|
||||||
.projectItemDescription {
|
|
||||||
@include text-caption;
|
@include text-caption;
|
||||||
color: var(--color-text-muted);
|
color: var(--color-text-muted);
|
||||||
}
|
|
||||||
|
|
||||||
.eyebrow {
|
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
letter-spacing: 0.08em;
|
letter-spacing: 0.08em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.value,
|
.value {
|
||||||
.projectItemName {
|
|
||||||
@include text-label;
|
@include text-label;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,7 +179,7 @@
|
|||||||
min-height: 0;
|
min-height: 0;
|
||||||
display: grid;
|
display: grid;
|
||||||
align-content: start;
|
align-content: start;
|
||||||
gap: var(--space-3);
|
gap: var(--space-2);
|
||||||
padding: var(--space-4);
|
padding: var(--space-4);
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
overscroll-behavior: contain;
|
overscroll-behavior: contain;
|
||||||
@@ -186,49 +190,148 @@
|
|||||||
width: 0;
|
width: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.projectList {
|
.treeSectionLabel {
|
||||||
|
@include text-caption;
|
||||||
|
margin: 0 0 var(--space-2);
|
||||||
|
padding: 0 var(--space-3);
|
||||||
|
color: var(--color-text-subtle);
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.04em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.treeList {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 0.2rem;
|
gap: var(--space-1);
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.projectItem {
|
.treeEmptySlot {
|
||||||
|
min-height: calc(var(--control-size-lg) - var(--space-2));
|
||||||
|
padding-left: calc(var(--space-3) + (var(--tree-depth, 0) * var(--space-4)));
|
||||||
|
border-radius: var(--radius-lg);
|
||||||
|
border: 1px dashed color-mix(in srgb, var(--color-border) 38%, transparent);
|
||||||
|
opacity: 0.35;
|
||||||
|
}
|
||||||
|
|
||||||
|
.treeInputRow {
|
||||||
|
width: 100%;
|
||||||
|
min-width: 0;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: auto minmax(0, 1fr);
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--space-2);
|
||||||
|
min-height: calc(var(--control-size-lg) - var(--space-2));
|
||||||
|
padding: var(--space-2) var(--space-3);
|
||||||
|
padding-left: calc(var(--space-3) + (var(--tree-depth, 0) * var(--space-4)));
|
||||||
|
border: 1px solid color-mix(in srgb, var(--color-border) 42%, transparent);
|
||||||
|
border-radius: var(--radius-lg);
|
||||||
|
background: color-mix(in srgb, var(--color-surface) 94%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.treeInput {
|
||||||
|
width: 100%;
|
||||||
|
min-width: 0;
|
||||||
|
border: 0;
|
||||||
|
background: transparent;
|
||||||
|
color: var(--color-text);
|
||||||
|
font: inherit;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.treeInput::placeholder {
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.treeItem {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
min-height: calc(var(--control-size-md) + var(--space-2));
|
display: grid;
|
||||||
|
grid-template-columns: auto auto minmax(0, 1fr) auto;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--space-2);
|
||||||
|
min-height: calc(var(--control-size-lg) - var(--space-2));
|
||||||
padding: var(--space-2) var(--space-3);
|
padding: var(--space-2) var(--space-3);
|
||||||
|
padding-left: calc(var(--space-3) + (var(--tree-depth, 0) * var(--space-4)));
|
||||||
border: 1px solid transparent;
|
border: 1px solid transparent;
|
||||||
border-radius: var(--radius-sm);
|
border-radius: var(--radius-lg);
|
||||||
background: transparent;
|
background: transparent;
|
||||||
color: var(--color-text-muted);
|
color: var(--color-text-muted);
|
||||||
transition:
|
transition:
|
||||||
background 160ms var(--easing-standard),
|
background 160ms var(--easing-standard),
|
||||||
color 160ms var(--easing-standard),
|
color 160ms var(--easing-standard),
|
||||||
border-color 160ms var(--easing-standard),
|
border-color 160ms var(--easing-standard),
|
||||||
|
box-shadow 160ms var(--easing-standard),
|
||||||
transform 180ms var(--easing-standard);
|
transform 180ms var(--easing-standard);
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
.projectItem:hover {
|
.treeItem:hover,
|
||||||
background: color-mix(in srgb, var(--color-surface-hover) 82%, transparent);
|
.treeItem:focus-visible {
|
||||||
|
background: color-mix(in srgb, var(--color-surface-hover) 80%, var(--color-accent-soft) 20%);
|
||||||
color: var(--color-text);
|
color: var(--color-text);
|
||||||
border-color: color-mix(in srgb, var(--color-border) 22%, transparent);
|
box-shadow: inset 0 1px 0 color-mix(in srgb, white 4%, transparent);
|
||||||
}
|
}
|
||||||
|
|
||||||
.projectItemActive {
|
.treeItemFolder {
|
||||||
border-color: color-mix(in srgb, var(--color-border) 28%, transparent);
|
|
||||||
background: color-mix(in srgb, var(--color-surface) 82%, transparent);
|
|
||||||
color: var(--color-text);
|
color: var(--color-text);
|
||||||
box-shadow: none;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.projectItemCopy {
|
.treeItemDragging {
|
||||||
|
opacity: 0.45;
|
||||||
|
transform: scale(0.985);
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.treeItemDropBefore {
|
||||||
|
box-shadow: inset 0 2px 0 color-mix(in srgb, var(--color-accent-strong) 78%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.treeItemDropAfter {
|
||||||
|
box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--color-accent-strong) 78%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.treeItemDropInside {
|
||||||
|
border-color: color-mix(in srgb, var(--color-accent-strong) 55%, transparent);
|
||||||
|
background: color-mix(in srgb, var(--color-accent-soft) 36%, var(--color-surface));
|
||||||
|
color: var(--color-text);
|
||||||
|
box-shadow: inset 0 1px 0 color-mix(in srgb, white 4%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.folderChevron {
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
transition: transform 160ms var(--easing-standard);
|
||||||
|
}
|
||||||
|
|
||||||
|
.folderChevronOpen {
|
||||||
|
transform: rotate(90deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.treeItemActive {
|
||||||
|
border-color: var(--color-border);
|
||||||
|
background: var(--color-surface);
|
||||||
|
color: var(--color-text);
|
||||||
|
box-shadow: inset 0 1px 0 color-mix(in srgb, white 4%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
color: inherit;
|
||||||
|
opacity: 0.85;
|
||||||
|
}
|
||||||
|
|
||||||
|
.label {
|
||||||
|
@include text-label;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
display: grid;
|
|
||||||
gap: 0.05rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.projectItemDescription {
|
.itemMeta {
|
||||||
color: color-mix(in srgb, var(--color-text-muted) 84%, transparent);
|
@include text-caption;
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 720px) {
|
||||||
|
.rootCompact .scrim,
|
||||||
|
.rootCompact .drawer {
|
||||||
|
width: min(18rem, calc(100vw - 5rem));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,17 @@
|
|||||||
// Path: Frontend/src/components/shell/ProjectSelector/ProjectSelector.tsx
|
// Path: Frontend/src/components/shell/ProjectSelector/ProjectSelector.tsx
|
||||||
|
|
||||||
import { For, createEffect, createSignal, onCleanup, onMount, type JSX } from "solid-js";
|
import { For, Show, createEffect, createSignal, onCleanup, onMount, type JSX } from "solid-js";
|
||||||
import { ChevronDown, Folder } from "../../../lib/icons";
|
import { ChevronDown, ChevronRight, Folder, LayoutGrid } from "../../../lib/icons";
|
||||||
|
import { ProjectContextMenu } from "../ProjectContextMenu/ProjectContextMenu";
|
||||||
import { useAppShellData } from "../data/app-shell.context";
|
import { useAppShellData } from "../data/app-shell.context";
|
||||||
|
import {
|
||||||
|
createProjectFolderTarget,
|
||||||
|
createProjectSurfaceTarget,
|
||||||
|
createProjectTarget,
|
||||||
|
type ProjectItem,
|
||||||
|
type ProjectMenuTarget,
|
||||||
|
} from "../data/shell.data";
|
||||||
|
import { createProjectContextMenuController } from "../ProjectContextMenu/createProjectContextMenuController";
|
||||||
import styles from "./ProjectSelector.module.scss";
|
import styles from "./ProjectSelector.module.scss";
|
||||||
|
|
||||||
type ProjectSelectorProps = {
|
type ProjectSelectorProps = {
|
||||||
@@ -12,41 +21,621 @@ type ProjectSelectorProps = {
|
|||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type ProjectFolderNode = {
|
||||||
|
kind: "folder";
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
meta?: string;
|
||||||
|
children: ProjectTreeNode[];
|
||||||
|
};
|
||||||
|
|
||||||
|
type ProjectLeafNode = {
|
||||||
|
kind: "project";
|
||||||
|
item: ProjectItem;
|
||||||
|
};
|
||||||
|
|
||||||
|
type ProjectTreeNode = ProjectFolderNode | ProjectLeafNode;
|
||||||
|
|
||||||
|
type PendingProjectFolderDraft = {
|
||||||
|
parentId: string | null;
|
||||||
|
depth: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
type ProjectDragTarget = {
|
||||||
|
parentId: string | null;
|
||||||
|
index: number;
|
||||||
|
intent: "before" | "after" | "inside";
|
||||||
|
targetNodeId?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type ProjectDragState = {
|
||||||
|
draggedNodeId: string;
|
||||||
|
dropTarget: ProjectDragTarget | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
type ProjectNodeLocation = {
|
||||||
|
parentId: string | null;
|
||||||
|
index: number;
|
||||||
|
node: ProjectTreeNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
const LONG_PRESS_MS = 320;
|
||||||
|
|
||||||
|
const createProjectFolderId = (): string => `project-folder-${Math.random().toString(36).slice(2, 10)}`;
|
||||||
|
|
||||||
|
const getProjectTreeNodeId = (node: ProjectTreeNode): string =>
|
||||||
|
node.kind === "folder" ? node.id : node.item.id;
|
||||||
|
|
||||||
|
const buildProjectTree = (items: readonly ProjectItem[]): ProjectTreeNode[] =>
|
||||||
|
items.map((item) => ({
|
||||||
|
kind: "project",
|
||||||
|
item,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const cloneProjectTreeNode = (node: ProjectTreeNode): ProjectTreeNode => {
|
||||||
|
if (node.kind === "project") {
|
||||||
|
return {
|
||||||
|
kind: "project",
|
||||||
|
item: { ...node.item },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
kind: "folder",
|
||||||
|
id: node.id,
|
||||||
|
label: node.label,
|
||||||
|
meta: node.meta,
|
||||||
|
children: node.children.map(cloneProjectTreeNode),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const insertProjectFolderNode = (
|
||||||
|
nodes: readonly ProjectTreeNode[],
|
||||||
|
parentId: string | null,
|
||||||
|
folder: ProjectFolderNode,
|
||||||
|
): ProjectTreeNode[] => {
|
||||||
|
if (parentId === null) {
|
||||||
|
return [...nodes, folder];
|
||||||
|
}
|
||||||
|
|
||||||
|
return nodes.map((node) => {
|
||||||
|
if (node.kind !== "folder") {
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.id === parentId) {
|
||||||
|
return {
|
||||||
|
...node,
|
||||||
|
children: [...node.children, folder],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...node,
|
||||||
|
children: insertProjectFolderNode(node.children, parentId, folder),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const findProjectNodeLocation = (
|
||||||
|
nodes: readonly ProjectTreeNode[],
|
||||||
|
nodeId: string,
|
||||||
|
parentId: string | null = null,
|
||||||
|
): ProjectNodeLocation | null => {
|
||||||
|
for (let index = 0; index < nodes.length; index += 1) {
|
||||||
|
const node = nodes[index];
|
||||||
|
|
||||||
|
if (getProjectTreeNodeId(node) === nodeId) {
|
||||||
|
return { parentId, index, node };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.kind === "folder") {
|
||||||
|
const nestedLocation = findProjectNodeLocation(node.children, nodeId, node.id);
|
||||||
|
|
||||||
|
if (nestedLocation) {
|
||||||
|
return nestedLocation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const findProjectNodeDepth = (nodes: readonly ProjectTreeNode[], nodeId: string, depth = 0): number | null => {
|
||||||
|
for (const node of nodes) {
|
||||||
|
if (getProjectTreeNodeId(node) === nodeId) {
|
||||||
|
return depth;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.kind === "folder") {
|
||||||
|
const nestedDepth = findProjectNodeDepth(node.children, nodeId, depth + 1);
|
||||||
|
|
||||||
|
if (nestedDepth !== null) {
|
||||||
|
return nestedDepth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const projectTreeContainsNode = (nodes: readonly ProjectTreeNode[], nodeId: string): boolean => {
|
||||||
|
for (const node of nodes) {
|
||||||
|
if (getProjectTreeNodeId(node) === nodeId) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.kind === "folder" && projectTreeContainsNode(node.children, nodeId)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const removeProjectTreeNode = (
|
||||||
|
nodes: readonly ProjectTreeNode[],
|
||||||
|
nodeId: string,
|
||||||
|
): { nodes: ProjectTreeNode[]; removed: ProjectTreeNode | null } => {
|
||||||
|
const nextNodes: ProjectTreeNode[] = [];
|
||||||
|
let removed: ProjectTreeNode | null = null;
|
||||||
|
|
||||||
|
for (const node of nodes) {
|
||||||
|
if (getProjectTreeNodeId(node) === nodeId) {
|
||||||
|
removed = node;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.kind === "folder") {
|
||||||
|
const result = removeProjectTreeNode(node.children, nodeId);
|
||||||
|
|
||||||
|
if (result.removed) {
|
||||||
|
removed = result.removed;
|
||||||
|
nextNodes.push({
|
||||||
|
...node,
|
||||||
|
children: result.nodes,
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nextNodes.push(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
return { nodes: nextNodes, removed };
|
||||||
|
};
|
||||||
|
|
||||||
|
const insertProjectTreeNode = (
|
||||||
|
nodes: readonly ProjectTreeNode[],
|
||||||
|
parentId: string | null,
|
||||||
|
index: number,
|
||||||
|
nodeToInsert: ProjectTreeNode,
|
||||||
|
): ProjectTreeNode[] => {
|
||||||
|
if (parentId === null) {
|
||||||
|
const nextNodes = [...nodes];
|
||||||
|
nextNodes.splice(Math.max(0, Math.min(index, nextNodes.length)), 0, nodeToInsert);
|
||||||
|
return nextNodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nodes.map((node) => {
|
||||||
|
if (node.kind !== "folder") {
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.id === parentId) {
|
||||||
|
const nextChildren = [...node.children];
|
||||||
|
nextChildren.splice(Math.max(0, Math.min(index, nextChildren.length)), 0, nodeToInsert);
|
||||||
|
return {
|
||||||
|
...node,
|
||||||
|
children: nextChildren,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...node,
|
||||||
|
children: insertProjectTreeNode(node.children, parentId, index, nodeToInsert),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const moveProjectTreeNode = (
|
||||||
|
nodes: readonly ProjectTreeNode[],
|
||||||
|
draggedNodeId: string,
|
||||||
|
dropTarget: ProjectDragTarget,
|
||||||
|
): ProjectTreeNode[] => {
|
||||||
|
const location = findProjectNodeLocation(nodes, draggedNodeId);
|
||||||
|
|
||||||
|
if (!location) {
|
||||||
|
return [...nodes];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
location.node.kind === "folder" &&
|
||||||
|
dropTarget.parentId !== null &&
|
||||||
|
(projectTreeContainsNode(location.node.children, dropTarget.parentId) || dropTarget.parentId === location.node.id)
|
||||||
|
) {
|
||||||
|
return [...nodes];
|
||||||
|
}
|
||||||
|
|
||||||
|
let normalizedIndex = dropTarget.index;
|
||||||
|
|
||||||
|
if (dropTarget.parentId === location.parentId && dropTarget.index > location.index) {
|
||||||
|
normalizedIndex -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dropTarget.parentId === location.parentId && normalizedIndex === location.index) {
|
||||||
|
return [...nodes];
|
||||||
|
}
|
||||||
|
|
||||||
|
const removalResult = removeProjectTreeNode(nodes, draggedNodeId);
|
||||||
|
|
||||||
|
if (!removalResult.removed) {
|
||||||
|
return [...nodes];
|
||||||
|
}
|
||||||
|
|
||||||
|
return insertProjectTreeNode(removalResult.nodes, dropTarget.parentId, normalizedIndex, removalResult.removed);
|
||||||
|
};
|
||||||
|
|
||||||
|
const ProjectFolderDraftRow = (props: {
|
||||||
|
depth: number;
|
||||||
|
value: string;
|
||||||
|
onInput: (value: string) => void;
|
||||||
|
onSubmit: () => void;
|
||||||
|
onCancel: () => void;
|
||||||
|
}): JSX.Element => {
|
||||||
|
let inputRef: HTMLInputElement | undefined;
|
||||||
|
|
||||||
|
queueMicrotask(() => inputRef?.focus());
|
||||||
|
|
||||||
|
return (
|
||||||
|
<li>
|
||||||
|
<div class={styles.treeInputRow} style={{ "--tree-depth": String(props.depth) }}>
|
||||||
|
<Folder class={styles.icon} size={18} strokeWidth={2} />
|
||||||
|
<input
|
||||||
|
ref={inputRef}
|
||||||
|
type="text"
|
||||||
|
class={styles.treeInput}
|
||||||
|
value={props.value}
|
||||||
|
placeholder="Folder name"
|
||||||
|
onInput={(event): void => props.onInput(event.currentTarget.value)}
|
||||||
|
onBlur={props.onSubmit}
|
||||||
|
onKeyDown={(event): void => {
|
||||||
|
if (event.key === "Enter") {
|
||||||
|
event.preventDefault();
|
||||||
|
event.currentTarget.blur();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.key === "Escape") {
|
||||||
|
event.preventDefault();
|
||||||
|
props.onCancel();
|
||||||
|
event.currentTarget.blur();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const ProjectFolderBranch = (props: {
|
||||||
|
nodes: readonly ProjectTreeNode[];
|
||||||
|
depth: number;
|
||||||
|
parentId: string | null;
|
||||||
|
selectedProjectId: string;
|
||||||
|
isFolderCollapsed: (folderId: string) => boolean;
|
||||||
|
onToggleFolder: (folderId: string) => void;
|
||||||
|
onSelectProject: (projectId: string) => void;
|
||||||
|
onOpenFolderMenu: (event: MouseEvent, folder: ProjectFolderNode) => void;
|
||||||
|
onOpenProjectMenu: (event: MouseEvent, item: ProjectItem) => void;
|
||||||
|
onNodePointerDown: (event: PointerEvent, nodeId: string) => void;
|
||||||
|
onNodePointerMove: (event: PointerEvent, parentId: string | null, index: number, node: ProjectTreeNode) => void;
|
||||||
|
pendingFolderDraft: PendingProjectFolderDraft | null;
|
||||||
|
pendingFolderName: string;
|
||||||
|
onPendingFolderNameChange: (value: string) => void;
|
||||||
|
onSubmitPendingFolder: () => void;
|
||||||
|
onCancelPendingFolder: () => void;
|
||||||
|
dragState: ProjectDragState | null;
|
||||||
|
}): JSX.Element => (
|
||||||
|
<ul class={styles.treeList} role="list">
|
||||||
|
<Show when={props.nodes.length === 0 && props.pendingFolderDraft?.parentId !== props.parentId}>
|
||||||
|
<li>
|
||||||
|
<div class={styles.treeEmptySlot} style={{ "--tree-depth": String(props.depth) }} />
|
||||||
|
</li>
|
||||||
|
</Show>
|
||||||
|
|
||||||
|
<For each={props.nodes}>
|
||||||
|
{(node, indexAccessor): JSX.Element => {
|
||||||
|
const nodeId = (): string => getProjectTreeNodeId(node);
|
||||||
|
const isDraggedNode = (): boolean => props.dragState?.draggedNodeId === nodeId();
|
||||||
|
const dropIntent = (): ProjectDragTarget["intent"] | null => {
|
||||||
|
if (props.dragState?.dropTarget?.targetNodeId !== nodeId()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return props.dragState.dropTarget.intent;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (node.kind === "folder") {
|
||||||
|
const isCollapsed = (): boolean => props.isFolderCollapsed(node.id);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<li>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
classList={{
|
||||||
|
[styles.treeItem]: true,
|
||||||
|
[styles.treeItemFolder]: true,
|
||||||
|
[styles.treeItemDragging]: isDraggedNode(),
|
||||||
|
[styles.treeItemDropBefore]: dropIntent() === "before",
|
||||||
|
[styles.treeItemDropAfter]: dropIntent() === "after",
|
||||||
|
[styles.treeItemDropInside]: dropIntent() === "inside",
|
||||||
|
}}
|
||||||
|
style={{ "--tree-depth": String(props.depth) }}
|
||||||
|
aria-expanded={!isCollapsed()}
|
||||||
|
onClick={() => {
|
||||||
|
if (props.dragState || suppressNextTreeClick()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
props.onToggleFolder(node.id);
|
||||||
|
}}
|
||||||
|
onContextMenu={(event): void => props.onOpenFolderMenu(event, node)}
|
||||||
|
onPointerDown={(event): void => props.onNodePointerDown(event, node.id)}
|
||||||
|
onPointerMove={(event): void =>
|
||||||
|
props.onNodePointerMove(event, props.parentId, indexAccessor(), node)
|
||||||
|
}
|
||||||
|
onPointerEnter={(event): void =>
|
||||||
|
props.onNodePointerMove(event, props.parentId, indexAccessor(), node)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<ChevronRight
|
||||||
|
classList={{
|
||||||
|
[styles.folderChevron]: true,
|
||||||
|
[styles.folderChevronOpen]: !isCollapsed(),
|
||||||
|
}}
|
||||||
|
size={16}
|
||||||
|
strokeWidth={2}
|
||||||
|
/>
|
||||||
|
<Folder class={styles.icon} size={18} strokeWidth={2} />
|
||||||
|
<span class={styles.label}>{node.label}</span>
|
||||||
|
<Show when={node.meta}>
|
||||||
|
<span class={styles.itemMeta}>{node.meta}</span>
|
||||||
|
</Show>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<Show when={!isCollapsed() && (node.children.length > 0 || props.pendingFolderDraft?.parentId === node.id)}>
|
||||||
|
<ProjectFolderBranch
|
||||||
|
nodes={node.children}
|
||||||
|
depth={props.depth + 1}
|
||||||
|
parentId={node.id}
|
||||||
|
selectedProjectId={props.selectedProjectId}
|
||||||
|
isFolderCollapsed={props.isFolderCollapsed}
|
||||||
|
onToggleFolder={props.onToggleFolder}
|
||||||
|
onSelectProject={props.onSelectProject}
|
||||||
|
onOpenFolderMenu={props.onOpenFolderMenu}
|
||||||
|
onOpenProjectMenu={props.onOpenProjectMenu}
|
||||||
|
onNodePointerDown={props.onNodePointerDown}
|
||||||
|
onNodePointerMove={props.onNodePointerMove}
|
||||||
|
pendingFolderDraft={props.pendingFolderDraft}
|
||||||
|
pendingFolderName={props.pendingFolderName}
|
||||||
|
onPendingFolderNameChange={props.onPendingFolderNameChange}
|
||||||
|
onSubmitPendingFolder={props.onSubmitPendingFolder}
|
||||||
|
onCancelPendingFolder={props.onCancelPendingFolder}
|
||||||
|
dragState={props.dragState}
|
||||||
|
/>
|
||||||
|
</Show>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<li>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
classList={{
|
||||||
|
[styles.treeItem]: true,
|
||||||
|
[styles.treeItemActive]: props.selectedProjectId === node.item.id,
|
||||||
|
[styles.treeItemDragging]: isDraggedNode(),
|
||||||
|
[styles.treeItemDropBefore]: dropIntent() === "before",
|
||||||
|
[styles.treeItemDropAfter]: dropIntent() === "after",
|
||||||
|
}}
|
||||||
|
style={{ "--tree-depth": String(props.depth) }}
|
||||||
|
onClick={(): void => {
|
||||||
|
if (props.dragState || suppressNextTreeClick()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
props.onSelectProject(node.item.id);
|
||||||
|
}}
|
||||||
|
onContextMenu={(event): void => props.onOpenProjectMenu(event, node.item)}
|
||||||
|
onPointerDown={(event): void => props.onNodePointerDown(event, node.item.id)}
|
||||||
|
onPointerMove={(event): void =>
|
||||||
|
props.onNodePointerMove(event, props.parentId, indexAccessor(), node)
|
||||||
|
}
|
||||||
|
onPointerEnter={(event): void =>
|
||||||
|
props.onNodePointerMove(event, props.parentId, indexAccessor(), node)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<LayoutGrid class={styles.icon} size={18} strokeWidth={2} />
|
||||||
|
<span class={styles.label}>{node.item.name}</span>
|
||||||
|
<Show when={node.item.meta}>
|
||||||
|
<span class={styles.itemMeta}>{node.item.meta}</span>
|
||||||
|
</Show>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
</For>
|
||||||
|
|
||||||
|
<Show when={props.pendingFolderDraft?.parentId === props.parentId}>
|
||||||
|
<ProjectFolderDraftRow
|
||||||
|
depth={props.pendingFolderDraft?.depth ?? props.depth}
|
||||||
|
value={props.pendingFolderName}
|
||||||
|
onInput={props.onPendingFolderNameChange}
|
||||||
|
onSubmit={props.onSubmitPendingFolder}
|
||||||
|
onCancel={props.onCancelPendingFolder}
|
||||||
|
/>
|
||||||
|
</Show>
|
||||||
|
</ul>
|
||||||
|
);
|
||||||
|
|
||||||
export const ProjectSelector = (props: ProjectSelectorProps): JSX.Element => {
|
export const ProjectSelector = (props: ProjectSelectorProps): JSX.Element => {
|
||||||
const appShellData = useAppShellData();
|
const appShellData = useAppShellData();
|
||||||
const [selectedProject, setSelectedProject] = createSignal(appShellData.activeProject());
|
const [selectedProject, setSelectedProject] = createSignal(appShellData.activeProject());
|
||||||
const [drawerTop, setDrawerTop] = createSignal<number>(0);
|
const [drawerTop, setDrawerTop] = createSignal<number>(0);
|
||||||
|
const [collapsedFolderIds, setCollapsedFolderIds] = createSignal<readonly string[]>([]);
|
||||||
|
const [projectTreeNodes, setProjectTreeNodes] = createSignal<ProjectTreeNode[]>(
|
||||||
|
buildProjectTree(appShellData.projectItems()),
|
||||||
|
);
|
||||||
|
const [pendingFolderDraft, setPendingFolderDraft] = createSignal<PendingProjectFolderDraft | null>(null);
|
||||||
|
const [pendingFolderName, setPendingFolderName] = createSignal("");
|
||||||
|
const [dragState, setDragState] = createSignal<ProjectDragState | null>(null);
|
||||||
|
const [suppressNextTreeClick, setSuppressNextTreeClick] = createSignal(false);
|
||||||
|
let rootRef: HTMLDivElement | undefined;
|
||||||
let triggerRef: HTMLButtonElement | undefined;
|
let triggerRef: HTMLButtonElement | undefined;
|
||||||
|
let contextMenuRef: HTMLDivElement | undefined;
|
||||||
|
let longPressTimer: number | undefined;
|
||||||
|
let suppressClickTimer: number | undefined;
|
||||||
|
const contextMenu = createProjectContextMenuController();
|
||||||
|
|
||||||
|
const clearLongPressTimer = (): void => {
|
||||||
|
if (longPressTimer !== undefined) {
|
||||||
|
window.clearTimeout(longPressTimer);
|
||||||
|
longPressTimer = undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const suppressTreeClickTemporarily = (): void => {
|
||||||
|
setSuppressNextTreeClick(true);
|
||||||
|
|
||||||
|
if (suppressClickTimer !== undefined) {
|
||||||
|
window.clearTimeout(suppressClickTimer);
|
||||||
|
}
|
||||||
|
|
||||||
|
suppressClickTimer = window.setTimeout(() => {
|
||||||
|
setSuppressNextTreeClick(false);
|
||||||
|
suppressClickTimer = undefined;
|
||||||
|
}, 80);
|
||||||
|
};
|
||||||
|
|
||||||
|
const isFolderCollapsed = (folderId: string): boolean => collapsedFolderIds().includes(folderId);
|
||||||
|
|
||||||
|
const toggleFolder = (folderId: string): void => {
|
||||||
|
setCollapsedFolderIds((current) =>
|
||||||
|
current.includes(folderId) ? current.filter((id) => id !== folderId) : [...current, folderId],
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
setSelectedProject(appShellData.activeProject());
|
setSelectedProject(appShellData.activeProject());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
createEffect(() => {
|
||||||
|
setProjectTreeNodes(buildProjectTree(appShellData.projectItems()));
|
||||||
|
setCollapsedFolderIds([]);
|
||||||
|
setPendingFolderDraft(null);
|
||||||
|
setPendingFolderName("");
|
||||||
|
setDragState(null);
|
||||||
|
});
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
if (!triggerRef) {
|
if (triggerRef) {
|
||||||
return;
|
const updateDrawerTop = (): void => {
|
||||||
|
if (!triggerRef) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setDrawerTop(triggerRef.offsetTop + triggerRef.offsetHeight + 8);
|
||||||
|
};
|
||||||
|
|
||||||
|
updateDrawerTop();
|
||||||
|
|
||||||
|
const observer = new ResizeObserver(() => {
|
||||||
|
updateDrawerTop();
|
||||||
|
});
|
||||||
|
|
||||||
|
observer.observe(triggerRef);
|
||||||
|
window.addEventListener("resize", updateDrawerTop);
|
||||||
|
|
||||||
|
onCleanup(() => {
|
||||||
|
observer.disconnect();
|
||||||
|
window.removeEventListener("resize", updateDrawerTop);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateDrawerTop = (): void => {
|
const handlePointerDown = (event: PointerEvent): void => {
|
||||||
if (!triggerRef) {
|
if (!props.isOpen || !rootRef) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setDrawerTop(triggerRef.offsetTop + triggerRef.offsetHeight);
|
const target = event.target;
|
||||||
|
|
||||||
|
if (target instanceof Node && rootRef.contains(target)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (target instanceof Node && contextMenuRef?.contains(target)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
props.onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
updateDrawerTop();
|
const handlePointerUp = (): void => {
|
||||||
|
clearLongPressTimer();
|
||||||
|
|
||||||
const observer = new ResizeObserver(() => {
|
const nextDragState = dragState();
|
||||||
updateDrawerTop();
|
|
||||||
});
|
|
||||||
|
|
||||||
observer.observe(triggerRef);
|
if (!nextDragState?.dropTarget) {
|
||||||
window.addEventListener("resize", updateDrawerTop);
|
if (nextDragState) {
|
||||||
|
suppressTreeClickTemporarily();
|
||||||
|
}
|
||||||
|
setDragState(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
suppressTreeClickTemporarily();
|
||||||
|
setProjectTreeNodes((current) =>
|
||||||
|
moveProjectTreeNode(current, nextDragState.draggedNodeId, nextDragState.dropTarget as ProjectDragTarget),
|
||||||
|
);
|
||||||
|
setDragState(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEscape = (event: KeyboardEvent): void => {
|
||||||
|
if (event.key !== "Escape") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearLongPressTimer();
|
||||||
|
|
||||||
|
if (dragState()) {
|
||||||
|
setDragState(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!props.isOpen) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
props.onClose();
|
||||||
|
triggerRef?.focus();
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener("pointerdown", handlePointerDown);
|
||||||
|
window.addEventListener("pointerup", handlePointerUp);
|
||||||
|
window.addEventListener("pointercancel", handlePointerUp);
|
||||||
|
window.addEventListener("keydown", handleEscape);
|
||||||
|
|
||||||
onCleanup(() => {
|
onCleanup(() => {
|
||||||
observer.disconnect();
|
clearLongPressTimer();
|
||||||
window.removeEventListener("resize", updateDrawerTop);
|
if (suppressClickTimer !== undefined) {
|
||||||
|
window.clearTimeout(suppressClickTimer);
|
||||||
|
}
|
||||||
|
document.removeEventListener("pointerdown", handlePointerDown);
|
||||||
|
window.removeEventListener("pointerup", handlePointerUp);
|
||||||
|
window.removeEventListener("pointercancel", handlePointerUp);
|
||||||
|
window.removeEventListener("keydown", handleEscape);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -60,27 +649,163 @@ export const ProjectSelector = (props: ProjectSelectorProps): JSX.Element => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const selectProject = (projectId: string): void => {
|
const selectProject = (projectId: string): void => {
|
||||||
const nextProject = appShellData.projectItems().find((item): boolean => item.id === projectId);
|
const location = findProjectNodeLocation(projectTreeNodes(), projectId);
|
||||||
|
|
||||||
if (!nextProject) {
|
if (!location || location.node.kind !== "project") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setSelectedProject({ id: nextProject.id, name: nextProject.name });
|
setSelectedProject({ id: location.node.item.id, name: location.node.item.name });
|
||||||
props.onClose();
|
props.onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const beginFolderDraft = (parentId: string | null, depth: number): void => {
|
||||||
|
if (parentId) {
|
||||||
|
setCollapsedFolderIds((current) => current.filter((id) => id !== parentId));
|
||||||
|
}
|
||||||
|
|
||||||
|
setPendingFolderName("");
|
||||||
|
setPendingFolderDraft({ parentId, depth });
|
||||||
|
};
|
||||||
|
|
||||||
|
const submitPendingFolder = (): void => {
|
||||||
|
const name = pendingFolderName().trim();
|
||||||
|
const draft = pendingFolderDraft();
|
||||||
|
|
||||||
|
if (!draft) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!name) {
|
||||||
|
setPendingFolderDraft(null);
|
||||||
|
setPendingFolderName("");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setProjectTreeNodes((current) =>
|
||||||
|
insertProjectFolderNode(current, draft.parentId, {
|
||||||
|
kind: "folder",
|
||||||
|
id: createProjectFolderId(),
|
||||||
|
label: name,
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
setPendingFolderDraft(null);
|
||||||
|
setPendingFolderName("");
|
||||||
|
};
|
||||||
|
|
||||||
|
const cancelPendingFolder = (): void => {
|
||||||
|
setPendingFolderDraft(null);
|
||||||
|
setPendingFolderName("");
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleContextActionSelect = (action: { id: string; label: string }, target: ProjectMenuTarget): void => {
|
||||||
|
if (action.id !== "new-folder") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (target.kind) {
|
||||||
|
case "surface":
|
||||||
|
beginFolderDraft(null, 0);
|
||||||
|
return;
|
||||||
|
case "folder":
|
||||||
|
beginFolderDraft(target.id, (findProjectNodeDepth(projectTreeNodes(), target.id) ?? 0) + 1);
|
||||||
|
return;
|
||||||
|
case "project": {
|
||||||
|
const parentId = findProjectNodeLocation(projectTreeNodes(), target.id)?.parentId ?? null;
|
||||||
|
beginFolderDraft(parentId, parentId ? (findProjectNodeDepth(projectTreeNodes(), parentId) ?? 0) + 1 : 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSurfaceContextMenu = (event: MouseEvent): void => {
|
||||||
|
event.stopPropagation();
|
||||||
|
contextMenu.openMenu(event, createProjectSurfaceTarget("Projects"));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleNodePointerDown = (event: PointerEvent, nodeId: string): void => {
|
||||||
|
if (event.button !== 0 || pendingFolderDraft()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearLongPressTimer();
|
||||||
|
longPressTimer = window.setTimeout(() => {
|
||||||
|
suppressTreeClickTemporarily();
|
||||||
|
setDragState({ draggedNodeId: nodeId, dropTarget: null });
|
||||||
|
}, LONG_PRESS_MS);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleNodePointerMove = (
|
||||||
|
event: PointerEvent,
|
||||||
|
parentId: string | null,
|
||||||
|
index: number,
|
||||||
|
node: ProjectTreeNode,
|
||||||
|
): void => {
|
||||||
|
const nextDragState = dragState();
|
||||||
|
|
||||||
|
if (!nextDragState) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nextDragState.draggedNodeId === getProjectTreeNodeId(node)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const bounds = event.currentTarget.getBoundingClientRect();
|
||||||
|
const relativeY = bounds.height <= 0 ? 0.5 : (event.clientY - bounds.top) / bounds.height;
|
||||||
|
let nextTarget: ProjectDragTarget;
|
||||||
|
|
||||||
|
if (node.kind === "folder") {
|
||||||
|
if (relativeY < 0.28) {
|
||||||
|
nextTarget = {
|
||||||
|
parentId,
|
||||||
|
index,
|
||||||
|
intent: "before",
|
||||||
|
targetNodeId: node.id,
|
||||||
|
};
|
||||||
|
} else if (relativeY > 0.72) {
|
||||||
|
nextTarget = {
|
||||||
|
parentId,
|
||||||
|
index: index + 1,
|
||||||
|
intent: "after",
|
||||||
|
targetNodeId: node.id,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
nextTarget = {
|
||||||
|
parentId: node.id,
|
||||||
|
index: node.children.length,
|
||||||
|
intent: "inside",
|
||||||
|
targetNodeId: node.id,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
nextTarget = {
|
||||||
|
parentId,
|
||||||
|
index: relativeY < 0.5 ? index : index + 1,
|
||||||
|
intent: relativeY < 0.5 ? "before" : "after",
|
||||||
|
targetNodeId: node.item.id,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
setDragState({
|
||||||
|
...nextDragState,
|
||||||
|
dropTarget: nextTarget,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
ref={rootRef}
|
||||||
classList={{
|
classList={{
|
||||||
[styles.root]: true,
|
[styles.root]: true,
|
||||||
[styles.rootCompact]: !!props.compact,
|
[styles.rootCompact]: !!props.compact,
|
||||||
|
[styles.rootDragMode]: !!dragState(),
|
||||||
}}
|
}}
|
||||||
style={{
|
style={{
|
||||||
"--project-drawer-top": `${drawerTop()}px`,
|
"--project-drawer-top": `${drawerTop()}px`,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{/* Project trigger */}
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
ref={triggerRef}
|
ref={triggerRef}
|
||||||
@@ -89,8 +814,9 @@ export const ProjectSelector = (props: ProjectSelectorProps): JSX.Element => {
|
|||||||
[styles.triggerCompact]: !!props.compact,
|
[styles.triggerCompact]: !!props.compact,
|
||||||
[styles.triggerOpen]: props.isOpen,
|
[styles.triggerOpen]: props.isOpen,
|
||||||
}}
|
}}
|
||||||
aria-label={`Open left workspace sidebar menu for ${selectedProject().name}`}
|
aria-label={`Open project menu for ${selectedProject().name}`}
|
||||||
aria-expanded={props.isOpen}
|
aria-expanded={props.isOpen}
|
||||||
|
aria-haspopup="menu"
|
||||||
title={selectedProject().name}
|
title={selectedProject().name}
|
||||||
onClick={toggleOpen}
|
onClick={toggleOpen}
|
||||||
>
|
>
|
||||||
@@ -113,54 +839,75 @@ export const ProjectSelector = (props: ProjectSelectorProps): JSX.Element => {
|
|||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{/* Outside-click scrim */}
|
<Show when={props.isOpen}>
|
||||||
<button
|
<>
|
||||||
type="button"
|
<button
|
||||||
classList={{
|
type="button"
|
||||||
[styles.scrim]: true,
|
classList={{
|
||||||
[styles.scrimOpen]: props.isOpen,
|
[styles.scrim]: true,
|
||||||
|
[styles.scrimOpen]: props.isOpen,
|
||||||
|
}}
|
||||||
|
aria-hidden={!props.isOpen}
|
||||||
|
tabIndex={props.isOpen ? 0 : -1}
|
||||||
|
onClick={props.onClose}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div
|
||||||
|
classList={{
|
||||||
|
[styles.drawer]: true,
|
||||||
|
[styles.drawerOpen]: props.isOpen,
|
||||||
|
}}
|
||||||
|
aria-hidden={!props.isOpen}
|
||||||
|
onContextMenu={handleSurfaceContextMenu}
|
||||||
|
>
|
||||||
|
<div class={styles.drawerBody}>
|
||||||
|
<Show when={!props.compact}>
|
||||||
|
<div class={styles.treeSectionLabel}>Projects</div>
|
||||||
|
</Show>
|
||||||
|
|
||||||
|
<ProjectFolderBranch
|
||||||
|
nodes={projectTreeNodes()}
|
||||||
|
depth={0}
|
||||||
|
parentId={null}
|
||||||
|
selectedProjectId={selectedProject().id}
|
||||||
|
isFolderCollapsed={isFolderCollapsed}
|
||||||
|
onToggleFolder={toggleFolder}
|
||||||
|
onSelectProject={selectProject}
|
||||||
|
onOpenFolderMenu={(event, folder): void => {
|
||||||
|
event.stopPropagation();
|
||||||
|
contextMenu.openMenu(event, createProjectFolderTarget(folder.id, folder.label));
|
||||||
|
}}
|
||||||
|
onOpenProjectMenu={(event, item): void => {
|
||||||
|
event.stopPropagation();
|
||||||
|
contextMenu.openMenu(event, createProjectTarget(item));
|
||||||
|
}}
|
||||||
|
onNodePointerDown={handleNodePointerDown}
|
||||||
|
onNodePointerMove={handleNodePointerMove}
|
||||||
|
pendingFolderDraft={pendingFolderDraft()}
|
||||||
|
pendingFolderName={pendingFolderName()}
|
||||||
|
onPendingFolderNameChange={setPendingFolderName}
|
||||||
|
onSubmitPendingFolder={submitPendingFolder}
|
||||||
|
onCancelPendingFolder={cancelPendingFolder}
|
||||||
|
dragState={dragState()}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
</Show>
|
||||||
|
|
||||||
|
<ProjectContextMenu
|
||||||
|
target={contextMenu.menuState()?.target ?? null}
|
||||||
|
position={(() => {
|
||||||
|
const state = contextMenu.menuState();
|
||||||
|
return state ? { x: state.x, y: state.y } : null;
|
||||||
|
})()}
|
||||||
|
menuRef={(element) => {
|
||||||
|
contextMenuRef = element;
|
||||||
|
contextMenu.setMenuRef(element);
|
||||||
}}
|
}}
|
||||||
aria-hidden={!props.isOpen}
|
onClose={contextMenu.closeMenu}
|
||||||
tabIndex={props.isOpen ? 0 : -1}
|
onSelect={handleContextActionSelect}
|
||||||
onClick={props.onClose}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Slide-out project list */}
|
|
||||||
<div
|
|
||||||
classList={{
|
|
||||||
[styles.drawer]: true,
|
|
||||||
[styles.drawerOpen]: props.isOpen,
|
|
||||||
}}
|
|
||||||
aria-hidden={!props.isOpen}
|
|
||||||
>
|
|
||||||
<div class={styles.drawerBody}>
|
|
||||||
<ul class={styles.projectList} role="list">
|
|
||||||
<For each={appShellData.projectItems()}>
|
|
||||||
{(item): JSX.Element => {
|
|
||||||
const isSelected = (): boolean => selectedProject().id === item.id;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<li>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
classList={{
|
|
||||||
[styles.projectItem]: true,
|
|
||||||
[styles.projectItemActive]: isSelected(),
|
|
||||||
}}
|
|
||||||
onClick={(): void => selectProject(item.id)}
|
|
||||||
>
|
|
||||||
<span class={styles.projectItemCopy}>
|
|
||||||
<span class={styles.projectItemName}>{item.name}</span>
|
|
||||||
<span class={styles.projectItemDescription}>{item.description}</span>
|
|
||||||
</span>
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
</For>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,6 +12,15 @@
|
|||||||
isolation: isolate;
|
isolation: isolate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sidebarDragMode {
|
||||||
|
user-select: none;
|
||||||
|
cursor: grabbing;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebarDragMode .treeItem {
|
||||||
|
cursor: grabbing;
|
||||||
|
}
|
||||||
|
|
||||||
.header {
|
.header {
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: var(--space-3);
|
gap: var(--space-3);
|
||||||
@@ -123,6 +132,43 @@
|
|||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.treeEmptySlot {
|
||||||
|
min-height: calc(var(--control-size-lg) - var(--space-2));
|
||||||
|
padding-left: calc(var(--space-3) + (var(--tree-depth, 0) * var(--space-4)));
|
||||||
|
border-radius: var(--radius-lg);
|
||||||
|
border: 1px dashed color-mix(in srgb, var(--color-border) 38%, transparent);
|
||||||
|
opacity: 0.35;
|
||||||
|
}
|
||||||
|
|
||||||
|
.treeInputRow {
|
||||||
|
width: 100%;
|
||||||
|
min-width: 0;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: auto minmax(0, 1fr);
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--space-2);
|
||||||
|
min-height: calc(var(--control-size-lg) - var(--space-2));
|
||||||
|
padding: var(--space-2) var(--space-3);
|
||||||
|
padding-left: calc(var(--space-3) + (var(--tree-depth, 0) * var(--space-4)));
|
||||||
|
border: 1px solid color-mix(in srgb, var(--color-border) 42%, transparent);
|
||||||
|
border-radius: var(--radius-lg);
|
||||||
|
background: color-mix(in srgb, var(--color-surface) 94%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.treeInput {
|
||||||
|
width: 100%;
|
||||||
|
min-width: 0;
|
||||||
|
border: 0;
|
||||||
|
background: transparent;
|
||||||
|
color: var(--color-text);
|
||||||
|
font: inherit;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.treeInput::placeholder {
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
.navItem {
|
.navItem {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
@@ -141,7 +187,7 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: auto minmax(0, 1fr) auto;
|
grid-template-columns: auto auto minmax(0, 1fr) auto;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: var(--space-2);
|
gap: var(--space-2);
|
||||||
min-height: calc(var(--control-size-lg) - var(--space-2));
|
min-height: calc(var(--control-size-lg) - var(--space-2));
|
||||||
@@ -156,19 +202,51 @@
|
|||||||
background 160ms var(--easing-standard),
|
background 160ms var(--easing-standard),
|
||||||
color 160ms var(--easing-standard),
|
color 160ms var(--easing-standard),
|
||||||
border-color 160ms var(--easing-standard),
|
border-color 160ms var(--easing-standard),
|
||||||
|
box-shadow 160ms var(--easing-standard),
|
||||||
transform 180ms var(--easing-standard);
|
transform 180ms var(--easing-standard);
|
||||||
}
|
}
|
||||||
|
|
||||||
.treeItem:hover,
|
.treeItem:hover,
|
||||||
.treeItem:focus-visible {
|
.treeItem:focus-visible {
|
||||||
background: var(--color-surface-hover);
|
background: color-mix(in srgb, var(--color-surface-hover) 80%, var(--color-accent-soft) 20%);
|
||||||
color: var(--color-text);
|
color: var(--color-text);
|
||||||
|
box-shadow: inset 0 1px 0 color-mix(in srgb, white 4%, transparent);
|
||||||
}
|
}
|
||||||
|
|
||||||
.treeItemFolder {
|
.treeItemFolder {
|
||||||
color: var(--color-text);
|
color: var(--color-text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.treeItemDragging {
|
||||||
|
opacity: 0.45;
|
||||||
|
transform: scale(0.985);
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.treeItemDropBefore {
|
||||||
|
box-shadow: inset 0 2px 0 color-mix(in srgb, var(--color-accent-strong) 78%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.treeItemDropAfter {
|
||||||
|
box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--color-accent-strong) 78%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.treeItemDropInside {
|
||||||
|
border-color: color-mix(in srgb, var(--color-accent-strong) 55%, transparent);
|
||||||
|
background: color-mix(in srgb, var(--color-accent-soft) 36%, var(--color-surface));
|
||||||
|
color: var(--color-text);
|
||||||
|
box-shadow: inset 0 1px 0 color-mix(in srgb, white 4%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.folderChevron {
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
transition: transform 160ms var(--easing-standard);
|
||||||
|
}
|
||||||
|
|
||||||
|
.folderChevronOpen {
|
||||||
|
transform: rotate(90deg);
|
||||||
|
}
|
||||||
|
|
||||||
.treeItemActive {
|
.treeItemActive {
|
||||||
border-color: var(--color-border);
|
border-color: var(--color-border);
|
||||||
background: var(--color-surface);
|
background: var(--color-surface);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Path: Frontend/src/components/shell/WorkspaceSidebar/WorkspaceSidebar.tsx
|
// Path: Frontend/src/components/shell/WorkspaceSidebar/WorkspaceSidebar.tsx
|
||||||
|
|
||||||
import { For, Show, createMemo, createSignal, type JSX } from "solid-js";
|
import { For, Show, createEffect, createSignal, onCleanup, onMount, type JSX } from "solid-js";
|
||||||
import { ChevronLeft, ChevronRight } from "../../../lib/icons";
|
import { ChevronLeft, ChevronRight, Folder } from "../../../lib/icons";
|
||||||
import { useAppShellData } from "../data/app-shell.context";
|
import { useAppShellData } from "../data/app-shell.context";
|
||||||
import { ProjectSelector } from "../ProjectSelector/ProjectSelector";
|
import { ProjectSelector } from "../ProjectSelector/ProjectSelector";
|
||||||
import {
|
import {
|
||||||
@@ -26,12 +26,276 @@ type WorkspaceSidebarProps = {
|
|||||||
onToggleRailCollapse: () => void;
|
onToggleRailCollapse: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type PendingWorkspaceFolderDraft = {
|
||||||
|
parentId: string | null;
|
||||||
|
depth: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
type WorkspaceDragTarget = {
|
||||||
|
parentId: string | null;
|
||||||
|
index: number;
|
||||||
|
intent: "before" | "after" | "inside";
|
||||||
|
targetNodeId?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type WorkspaceDragState = {
|
||||||
|
draggedNodeId: string;
|
||||||
|
dropTarget: WorkspaceDragTarget | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
type WorkspaceNodeLocation = {
|
||||||
|
parentId: string | null;
|
||||||
|
index: number;
|
||||||
|
node: WorkspaceTreeNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
const LONG_PRESS_MS = 320;
|
||||||
|
|
||||||
|
const createWorkspaceFolderId = (): string => `folder-${Math.random().toString(36).slice(2, 10)}`;
|
||||||
|
|
||||||
|
const getWorkspaceTreeNodeId = (node: WorkspaceTreeNode): string => node.id;
|
||||||
|
|
||||||
|
const insertWorkspaceFolderNode = (
|
||||||
|
nodes: readonly WorkspaceTreeNode[],
|
||||||
|
parentId: string | null,
|
||||||
|
folder: WorkspaceTreeNode,
|
||||||
|
): readonly WorkspaceTreeNode[] => {
|
||||||
|
if (parentId === null) {
|
||||||
|
return [...nodes, folder];
|
||||||
|
}
|
||||||
|
|
||||||
|
return nodes.map((node) => {
|
||||||
|
if (node.kind !== "folder") {
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.id === parentId) {
|
||||||
|
return {
|
||||||
|
...node,
|
||||||
|
children: [...(node.children ?? []), folder],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...node,
|
||||||
|
children: node.children ? insertWorkspaceFolderNode(node.children, parentId, folder) : node.children,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const findWorkspaceFolderDepth = (nodes: readonly WorkspaceTreeNode[], folderId: string, depth = 0): number | null => {
|
||||||
|
for (const node of nodes) {
|
||||||
|
if (node.kind !== "folder") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.id === folderId) {
|
||||||
|
return depth;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nestedDepth = node.children ? findWorkspaceFolderDepth(node.children, folderId, depth + 1) : null;
|
||||||
|
if (nestedDepth !== null) {
|
||||||
|
return nestedDepth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const findWorkspaceNodeLocation = (
|
||||||
|
nodes: readonly WorkspaceTreeNode[],
|
||||||
|
nodeId: string,
|
||||||
|
parentId: string | null = null,
|
||||||
|
): WorkspaceNodeLocation | null => {
|
||||||
|
for (let index = 0; index < nodes.length; index += 1) {
|
||||||
|
const node = nodes[index];
|
||||||
|
|
||||||
|
if (node.id === nodeId) {
|
||||||
|
return { parentId, index, node };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.kind === "folder" && node.children) {
|
||||||
|
const nestedLocation = findWorkspaceNodeLocation(node.children, nodeId, node.id);
|
||||||
|
|
||||||
|
if (nestedLocation) {
|
||||||
|
return nestedLocation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const workspaceTreeContainsNode = (nodes: readonly WorkspaceTreeNode[], nodeId: string): boolean => {
|
||||||
|
for (const node of nodes) {
|
||||||
|
if (node.id === nodeId) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.kind === "folder" && node.children && workspaceTreeContainsNode(node.children, nodeId)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const removeWorkspaceTreeNode = (
|
||||||
|
nodes: readonly WorkspaceTreeNode[],
|
||||||
|
nodeId: string,
|
||||||
|
): { nodes: WorkspaceTreeNode[]; removed: WorkspaceTreeNode | null } => {
|
||||||
|
const nextNodes: WorkspaceTreeNode[] = [];
|
||||||
|
let removed: WorkspaceTreeNode | null = null;
|
||||||
|
|
||||||
|
for (const node of nodes) {
|
||||||
|
if (node.id === nodeId) {
|
||||||
|
removed = node;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.kind === "folder" && node.children) {
|
||||||
|
const result = removeWorkspaceTreeNode(node.children, nodeId);
|
||||||
|
|
||||||
|
if (result.removed) {
|
||||||
|
removed = result.removed;
|
||||||
|
nextNodes.push({
|
||||||
|
...node,
|
||||||
|
children: result.nodes,
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nextNodes.push(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
return { nodes: nextNodes, removed };
|
||||||
|
};
|
||||||
|
|
||||||
|
const insertWorkspaceTreeNode = (
|
||||||
|
nodes: readonly WorkspaceTreeNode[],
|
||||||
|
parentId: string | null,
|
||||||
|
index: number,
|
||||||
|
nodeToInsert: WorkspaceTreeNode,
|
||||||
|
): WorkspaceTreeNode[] => {
|
||||||
|
if (parentId === null) {
|
||||||
|
const nextNodes = [...nodes];
|
||||||
|
nextNodes.splice(Math.max(0, Math.min(index, nextNodes.length)), 0, nodeToInsert);
|
||||||
|
return nextNodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nodes.map((node) => {
|
||||||
|
if (node.kind !== "folder") {
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.id === parentId) {
|
||||||
|
const nextChildren = [...(node.children ?? [])];
|
||||||
|
nextChildren.splice(Math.max(0, Math.min(index, nextChildren.length)), 0, nodeToInsert);
|
||||||
|
return {
|
||||||
|
...node,
|
||||||
|
children: nextChildren,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...node,
|
||||||
|
children: node.children ? insertWorkspaceTreeNode(node.children, parentId, index, nodeToInsert) : node.children,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const moveWorkspaceTreeNode = (
|
||||||
|
nodes: readonly WorkspaceTreeNode[],
|
||||||
|
draggedNodeId: string,
|
||||||
|
dropTarget: WorkspaceDragTarget,
|
||||||
|
): WorkspaceTreeNode[] => {
|
||||||
|
const location = findWorkspaceNodeLocation(nodes, draggedNodeId);
|
||||||
|
|
||||||
|
if (!location) {
|
||||||
|
return [...nodes];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
location.node.kind === "folder" &&
|
||||||
|
dropTarget.parentId !== null &&
|
||||||
|
((location.node.children && workspaceTreeContainsNode(location.node.children, dropTarget.parentId)) ||
|
||||||
|
dropTarget.parentId === location.node.id)
|
||||||
|
) {
|
||||||
|
return [...nodes];
|
||||||
|
}
|
||||||
|
|
||||||
|
let normalizedIndex = dropTarget.index;
|
||||||
|
|
||||||
|
if (dropTarget.parentId === location.parentId && dropTarget.index > location.index) {
|
||||||
|
normalizedIndex -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dropTarget.parentId === location.parentId && normalizedIndex === location.index) {
|
||||||
|
return [...nodes];
|
||||||
|
}
|
||||||
|
|
||||||
|
const removalResult = removeWorkspaceTreeNode(nodes, draggedNodeId);
|
||||||
|
|
||||||
|
if (!removalResult.removed) {
|
||||||
|
return [...nodes];
|
||||||
|
}
|
||||||
|
|
||||||
|
return insertWorkspaceTreeNode(removalResult.nodes, dropTarget.parentId, normalizedIndex, removalResult.removed);
|
||||||
|
};
|
||||||
|
|
||||||
|
const FolderDraftRow = (props: {
|
||||||
|
depth: number;
|
||||||
|
value: string;
|
||||||
|
onInput: (value: string) => void;
|
||||||
|
onSubmit: () => void;
|
||||||
|
onCancel: () => void;
|
||||||
|
}): JSX.Element => {
|
||||||
|
let inputRef: HTMLInputElement | undefined;
|
||||||
|
|
||||||
|
queueMicrotask(() => inputRef?.focus());
|
||||||
|
|
||||||
|
return (
|
||||||
|
<li>
|
||||||
|
<div class={styles.treeInputRow} style={{ "--tree-depth": String(props.depth) }}>
|
||||||
|
<Folder class={styles.icon} size={18} strokeWidth={2} />
|
||||||
|
<input
|
||||||
|
ref={inputRef}
|
||||||
|
type="text"
|
||||||
|
class={styles.treeInput}
|
||||||
|
value={props.value}
|
||||||
|
placeholder="Folder name"
|
||||||
|
onInput={(event): void => props.onInput(event.currentTarget.value)}
|
||||||
|
onBlur={props.onSubmit}
|
||||||
|
onKeyDown={(event): void => {
|
||||||
|
if (event.key === "Enter") {
|
||||||
|
event.preventDefault();
|
||||||
|
event.currentTarget.blur();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.key === "Escape") {
|
||||||
|
event.preventDefault();
|
||||||
|
props.onCancel();
|
||||||
|
event.currentTarget.blur();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const isContextMenuKeyboardTrigger = (event: KeyboardEvent): boolean => event.key === "ContextMenu" || (event.shiftKey && event.key === "F10");
|
const isContextMenuKeyboardTrigger = (event: KeyboardEvent): boolean => event.key === "ContextMenu" || (event.shiftKey && event.key === "F10");
|
||||||
|
|
||||||
const WorkspaceHomeEntry = (props: {
|
const WorkspaceHomeEntry = (props: {
|
||||||
item: WorkspaceStaticItem;
|
item: WorkspaceStaticItem;
|
||||||
onOpenContextMenu: (event: MouseEvent, target: WorkspaceContextMenuTarget) => void;
|
onOpenContextMenu: (event: MouseEvent, target: WorkspaceContextMenuTarget) => void;
|
||||||
onOpenContextMenuFromKeyboard: (element: HTMLElement, target: WorkspaceContextMenuTarget) => void;
|
onOpenContextMenuFromKeyboard: (element: HTMLElement, target: WorkspaceContextMenuTarget) => void;
|
||||||
|
onNodePointerDown: (event: PointerEvent, nodeId: string) => void;
|
||||||
|
onNodePointerMove: (event: PointerEvent, parentId: string | null, index: number, node: WorkspaceTreeNode) => void;
|
||||||
|
dragState: WorkspaceDragState | null;
|
||||||
|
isTreeClickSuppressed: () => boolean;
|
||||||
}): JSX.Element => {
|
}): JSX.Element => {
|
||||||
const Icon = props.item.icon;
|
const Icon = props.item.icon;
|
||||||
const target = createWorkspaceStaticTarget(props.item);
|
const target = createWorkspaceStaticTarget(props.item);
|
||||||
@@ -75,18 +339,41 @@ const WorkspaceHomeEntry = (props: {
|
|||||||
|
|
||||||
const WorkspaceTreeBranch = (props: {
|
const WorkspaceTreeBranch = (props: {
|
||||||
nodes: readonly WorkspaceTreeNode[];
|
nodes: readonly WorkspaceTreeNode[];
|
||||||
|
parentId?: string | null;
|
||||||
depth?: number;
|
depth?: number;
|
||||||
|
isFolderCollapsed: (folderId: string) => boolean;
|
||||||
|
onToggleFolder: (folderId: string) => void;
|
||||||
|
pendingFolderDraft: PendingWorkspaceFolderDraft | null;
|
||||||
|
pendingFolderName: string;
|
||||||
|
onPendingFolderNameChange: (value: string) => void;
|
||||||
|
onSubmitPendingFolder: () => void;
|
||||||
|
onCancelPendingFolder: () => void;
|
||||||
onOpenContextMenu: (event: MouseEvent, target: WorkspaceContextMenuTarget) => void;
|
onOpenContextMenu: (event: MouseEvent, target: WorkspaceContextMenuTarget) => void;
|
||||||
onOpenContextMenuFromKeyboard: (element: HTMLElement, target: WorkspaceContextMenuTarget) => void;
|
onOpenContextMenuFromKeyboard: (element: HTMLElement, target: WorkspaceContextMenuTarget) => void;
|
||||||
}): JSX.Element => {
|
}): JSX.Element => {
|
||||||
const depth = () => props.depth ?? 0;
|
const depth = () => props.depth ?? 0;
|
||||||
|
const parentId = () => props.parentId ?? null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ul class={styles.treeList} role="list">
|
<ul class={styles.treeList} role="list">
|
||||||
|
<Show when={props.nodes.length === 0 && props.pendingFolderDraft?.parentId !== parentId()}>
|
||||||
|
<li>
|
||||||
|
<div class={styles.treeEmptySlot} style={{ "--tree-depth": String(depth()) }} />
|
||||||
|
</li>
|
||||||
|
</Show>
|
||||||
<For each={props.nodes}>
|
<For each={props.nodes}>
|
||||||
{(node): JSX.Element => {
|
{(node, indexAccessor): JSX.Element => {
|
||||||
const Icon = getWorkspaceNodeIcon(node);
|
const Icon = getWorkspaceNodeIcon(node);
|
||||||
const target = createWorkspaceTreeTarget(node);
|
const target = createWorkspaceTreeTarget(node);
|
||||||
|
const isCollapsed = (): boolean => (node.kind === "folder" ? props.isFolderCollapsed(node.id) : false);
|
||||||
|
const isDraggedNode = (): boolean => props.dragState?.draggedNodeId === node.id;
|
||||||
|
const dropIntent = (): WorkspaceDragTarget["intent"] | null => {
|
||||||
|
if (props.dragState?.dropTarget?.targetNodeId !== node.id) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return props.dragState.dropTarget.intent;
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li>
|
<li>
|
||||||
@@ -96,8 +383,13 @@ const WorkspaceTreeBranch = (props: {
|
|||||||
[styles.treeItem]: true,
|
[styles.treeItem]: true,
|
||||||
[styles.treeItemActive]: !!node.active,
|
[styles.treeItemActive]: !!node.active,
|
||||||
[styles.treeItemFolder]: node.kind === "folder",
|
[styles.treeItemFolder]: node.kind === "folder",
|
||||||
|
[styles.treeItemDragging]: isDraggedNode(),
|
||||||
|
[styles.treeItemDropBefore]: dropIntent() === "before",
|
||||||
|
[styles.treeItemDropAfter]: dropIntent() === "after",
|
||||||
|
[styles.treeItemDropInside]: dropIntent() === "inside",
|
||||||
}}
|
}}
|
||||||
style={{ "--tree-depth": String(depth()) }}
|
style={{ "--tree-depth": String(depth()) }}
|
||||||
|
aria-expanded={node.kind === "folder" ? !isCollapsed() : undefined}
|
||||||
aria-current={node.active ? "page" : undefined}
|
aria-current={node.active ? "page" : undefined}
|
||||||
aria-label={node.label}
|
aria-label={node.label}
|
||||||
title={node.label}
|
title={node.label}
|
||||||
@@ -105,10 +397,28 @@ const WorkspaceTreeBranch = (props: {
|
|||||||
data-kind={node.kind}
|
data-kind={node.kind}
|
||||||
data-item-type={node.kind === "item" ? node.itemType : undefined}
|
data-item-type={node.kind === "item" ? node.itemType : undefined}
|
||||||
data-active={node.active ? "true" : "false"}
|
data-active={node.active ? "true" : "false"}
|
||||||
|
onClick={(): void => {
|
||||||
|
if (props.dragState || props.isTreeClickSuppressed()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.kind !== "folder") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
props.onToggleFolder(node.id);
|
||||||
|
}}
|
||||||
onContextMenu={(event): void => {
|
onContextMenu={(event): void => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
props.onOpenContextMenu(event, target);
|
props.onOpenContextMenu(event, target);
|
||||||
}}
|
}}
|
||||||
|
onPointerDown={(event): void => props.onNodePointerDown(event, node.id)}
|
||||||
|
onPointerMove={(event): void =>
|
||||||
|
props.onNodePointerMove(event, parentId(), indexAccessor(), node)
|
||||||
|
}
|
||||||
|
onPointerEnter={(event): void =>
|
||||||
|
props.onNodePointerMove(event, parentId(), indexAccessor(), node)
|
||||||
|
}
|
||||||
onKeyDown={(event): void => {
|
onKeyDown={(event): void => {
|
||||||
if (!isContextMenuKeyboardTrigger(event)) {
|
if (!isContextMenuKeyboardTrigger(event)) {
|
||||||
return;
|
return;
|
||||||
@@ -118,6 +428,16 @@ const WorkspaceTreeBranch = (props: {
|
|||||||
props.onOpenContextMenuFromKeyboard(event.currentTarget, target);
|
props.onOpenContextMenuFromKeyboard(event.currentTarget, target);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
<Show when={node.kind === "folder"}>
|
||||||
|
<ChevronRight
|
||||||
|
classList={{
|
||||||
|
[styles.folderChevron]: true,
|
||||||
|
[styles.folderChevronOpen]: !isCollapsed(),
|
||||||
|
}}
|
||||||
|
size={16}
|
||||||
|
strokeWidth={2}
|
||||||
|
/>
|
||||||
|
</Show>
|
||||||
<Icon class={styles.icon} size={18} strokeWidth={2} />
|
<Icon class={styles.icon} size={18} strokeWidth={2} />
|
||||||
<span class={styles.label}>{node.label}</span>
|
<span class={styles.label}>{node.label}</span>
|
||||||
<Show when={node.meta}>
|
<Show when={node.meta}>
|
||||||
@@ -125,18 +445,40 @@ const WorkspaceTreeBranch = (props: {
|
|||||||
</Show>
|
</Show>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<Show when={node.children?.length}>
|
<Show when={node.kind === "folder" && !isCollapsed() && (((node.children?.length ?? 0) > 0) || props.pendingFolderDraft?.parentId === node.id)}>
|
||||||
<WorkspaceTreeBranch
|
<WorkspaceTreeBranch
|
||||||
nodes={node.children ?? []}
|
nodes={node.children ?? []}
|
||||||
|
parentId={node.id}
|
||||||
depth={depth() + 1}
|
depth={depth() + 1}
|
||||||
|
isFolderCollapsed={props.isFolderCollapsed}
|
||||||
|
onToggleFolder={props.onToggleFolder}
|
||||||
|
pendingFolderDraft={props.pendingFolderDraft}
|
||||||
|
pendingFolderName={props.pendingFolderName}
|
||||||
|
onPendingFolderNameChange={props.onPendingFolderNameChange}
|
||||||
|
onSubmitPendingFolder={props.onSubmitPendingFolder}
|
||||||
|
onCancelPendingFolder={props.onCancelPendingFolder}
|
||||||
onOpenContextMenu={props.onOpenContextMenu}
|
onOpenContextMenu={props.onOpenContextMenu}
|
||||||
onOpenContextMenuFromKeyboard={props.onOpenContextMenuFromKeyboard}
|
onOpenContextMenuFromKeyboard={props.onOpenContextMenuFromKeyboard}
|
||||||
|
onNodePointerDown={props.onNodePointerDown}
|
||||||
|
onNodePointerMove={props.onNodePointerMove}
|
||||||
|
dragState={props.dragState}
|
||||||
|
isTreeClickSuppressed={props.isTreeClickSuppressed}
|
||||||
/>
|
/>
|
||||||
</Show>
|
</Show>
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
</For>
|
</For>
|
||||||
|
|
||||||
|
<Show when={props.pendingFolderDraft && props.pendingFolderDraft.parentId === parentId()}>
|
||||||
|
<FolderDraftRow
|
||||||
|
depth={props.pendingFolderDraft?.depth ?? depth()}
|
||||||
|
value={props.pendingFolderName}
|
||||||
|
onInput={props.onPendingFolderNameChange}
|
||||||
|
onSubmit={props.onSubmitPendingFolder}
|
||||||
|
onCancel={props.onCancelPendingFolder}
|
||||||
|
/>
|
||||||
|
</Show>
|
||||||
</ul>
|
</ul>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -144,23 +486,209 @@ const WorkspaceTreeBranch = (props: {
|
|||||||
export const WorkspaceSidebar = (props: WorkspaceSidebarProps): JSX.Element => {
|
export const WorkspaceSidebar = (props: WorkspaceSidebarProps): JSX.Element => {
|
||||||
const appShellData = useAppShellData();
|
const appShellData = useAppShellData();
|
||||||
const [isProjectDrawerOpen, setIsProjectDrawerOpen] = createSignal(false);
|
const [isProjectDrawerOpen, setIsProjectDrawerOpen] = createSignal(false);
|
||||||
|
const [workspaceTreeNodes, setWorkspaceTreeNodes] = createSignal<readonly WorkspaceTreeNode[]>(appShellData.workspaceTree());
|
||||||
|
const [collapsedFolderIds, setCollapsedFolderIds] = createSignal<readonly string[]>([]);
|
||||||
|
const [pendingFolderDraft, setPendingFolderDraft] = createSignal<PendingWorkspaceFolderDraft | null>(null);
|
||||||
|
const [pendingFolderName, setPendingFolderName] = createSignal("");
|
||||||
|
const [dragState, setDragState] = createSignal<WorkspaceDragState | null>(null);
|
||||||
|
const [suppressNextTreeClick, setSuppressNextTreeClick] = createSignal(false);
|
||||||
const contextMenu = createWorkspaceContextMenuController();
|
const contextMenu = createWorkspaceContextMenuController();
|
||||||
|
let longPressTimer: number | undefined;
|
||||||
|
let suppressClickTimer: number | undefined;
|
||||||
const railToggleLabel = (): string => (props.railCollapsed ? "Expand server rail" : "Collapse server rail");
|
const railToggleLabel = (): string => (props.railCollapsed ? "Expand server rail" : "Collapse server rail");
|
||||||
const sidebarContextMenuTarget = createMemo(() => createWorkspaceSurfaceTarget(appShellData.activeProject()));
|
const sidebarContextMenuTarget = createWorkspaceSurfaceTarget(appShellData.activeProject());
|
||||||
const contextMenuTarget = createMemo(() => contextMenu.menuState()?.target ?? null);
|
const isFolderCollapsed = (folderId: string): boolean => collapsedFolderIds().includes(folderId);
|
||||||
const contextMenuPosition = createMemo(() => {
|
const toggleFolder = (folderId: string): void => {
|
||||||
const state = contextMenu.menuState();
|
setCollapsedFolderIds((current) =>
|
||||||
|
current.includes(folderId) ? current.filter((id) => id !== folderId) : [...current, folderId],
|
||||||
|
);
|
||||||
|
};
|
||||||
|
const clearLongPressTimer = (): void => {
|
||||||
|
if (longPressTimer !== undefined) {
|
||||||
|
window.clearTimeout(longPressTimer);
|
||||||
|
longPressTimer = undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const suppressTreeClickTemporarily = (): void => {
|
||||||
|
setSuppressNextTreeClick(true);
|
||||||
|
|
||||||
return state
|
if (suppressClickTimer !== undefined) {
|
||||||
? {
|
window.clearTimeout(suppressClickTimer);
|
||||||
x: state.x,
|
}
|
||||||
y: state.y,
|
|
||||||
}
|
suppressClickTimer = window.setTimeout(() => {
|
||||||
: null;
|
setSuppressNextTreeClick(false);
|
||||||
|
suppressClickTimer = undefined;
|
||||||
|
}, 80);
|
||||||
|
};
|
||||||
|
|
||||||
|
createEffect(() => {
|
||||||
|
setWorkspaceTreeNodes(appShellData.workspaceTree());
|
||||||
|
setCollapsedFolderIds([]);
|
||||||
|
setPendingFolderDraft(null);
|
||||||
|
setPendingFolderName("");
|
||||||
|
setDragState(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleContextActionSelect = (_action: WorkspaceContextMenuAction, _target: WorkspaceContextMenuTarget): void => {
|
onMount(() => {
|
||||||
// Initial implementation only establishes the menu IA and placement.
|
const handlePointerUp = (): void => {
|
||||||
|
clearLongPressTimer();
|
||||||
|
|
||||||
|
const nextDragState = dragState();
|
||||||
|
|
||||||
|
if (!nextDragState?.dropTarget) {
|
||||||
|
if (nextDragState) {
|
||||||
|
suppressTreeClickTemporarily();
|
||||||
|
}
|
||||||
|
setDragState(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
suppressTreeClickTemporarily();
|
||||||
|
setWorkspaceTreeNodes((current) =>
|
||||||
|
moveWorkspaceTreeNode(current, nextDragState.draggedNodeId, nextDragState.dropTarget as WorkspaceDragTarget),
|
||||||
|
);
|
||||||
|
setDragState(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEscape = (event: KeyboardEvent): void => {
|
||||||
|
if (event.key !== "Escape") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearLongPressTimer();
|
||||||
|
|
||||||
|
if (dragState()) {
|
||||||
|
setDragState(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener("pointerup", handlePointerUp);
|
||||||
|
window.addEventListener("pointercancel", handlePointerUp);
|
||||||
|
window.addEventListener("keydown", handleEscape);
|
||||||
|
|
||||||
|
onCleanup(() => {
|
||||||
|
clearLongPressTimer();
|
||||||
|
if (suppressClickTimer !== undefined) {
|
||||||
|
window.clearTimeout(suppressClickTimer);
|
||||||
|
}
|
||||||
|
window.removeEventListener("pointerup", handlePointerUp);
|
||||||
|
window.removeEventListener("pointercancel", handlePointerUp);
|
||||||
|
window.removeEventListener("keydown", handleEscape);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const beginFolderDraft = (parentId: string | null, depth: number): void => {
|
||||||
|
if (parentId) {
|
||||||
|
setCollapsedFolderIds((current) => current.filter((id) => id !== parentId));
|
||||||
|
}
|
||||||
|
|
||||||
|
setPendingFolderName("");
|
||||||
|
setPendingFolderDraft({ parentId, depth });
|
||||||
|
};
|
||||||
|
|
||||||
|
const submitPendingFolder = (): void => {
|
||||||
|
const name = pendingFolderName().trim();
|
||||||
|
const draft = pendingFolderDraft();
|
||||||
|
|
||||||
|
if (!draft) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!name) {
|
||||||
|
setPendingFolderDraft(null);
|
||||||
|
setPendingFolderName("");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setWorkspaceTreeNodes((current) =>
|
||||||
|
insertWorkspaceFolderNode(current, draft.parentId, {
|
||||||
|
id: createWorkspaceFolderId(),
|
||||||
|
label: name,
|
||||||
|
kind: "folder",
|
||||||
|
icon: Folder,
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
setPendingFolderDraft(null);
|
||||||
|
setPendingFolderName("");
|
||||||
|
};
|
||||||
|
|
||||||
|
const cancelPendingFolder = (): void => {
|
||||||
|
setPendingFolderDraft(null);
|
||||||
|
setPendingFolderName("");
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleNodePointerDown = (event: PointerEvent, nodeId: string): void => {
|
||||||
|
if (event.button !== 0 || pendingFolderDraft()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearLongPressTimer();
|
||||||
|
longPressTimer = window.setTimeout(() => {
|
||||||
|
suppressTreeClickTemporarily();
|
||||||
|
setDragState({ draggedNodeId: nodeId, dropTarget: null });
|
||||||
|
}, LONG_PRESS_MS);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleNodePointerMove = (
|
||||||
|
event: PointerEvent,
|
||||||
|
parentId: string | null,
|
||||||
|
index: number,
|
||||||
|
node: WorkspaceTreeNode,
|
||||||
|
): void => {
|
||||||
|
const nextDragState = dragState();
|
||||||
|
|
||||||
|
if (!nextDragState || nextDragState.draggedNodeId === getWorkspaceTreeNodeId(node)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const bounds = event.currentTarget.getBoundingClientRect();
|
||||||
|
const relativeY = bounds.height <= 0 ? 0.5 : (event.clientY - bounds.top) / bounds.height;
|
||||||
|
let nextTarget: WorkspaceDragTarget;
|
||||||
|
|
||||||
|
if (node.kind === "folder") {
|
||||||
|
if (relativeY < 0.28) {
|
||||||
|
nextTarget = { parentId, index, intent: "before", targetNodeId: node.id };
|
||||||
|
} else if (relativeY > 0.72) {
|
||||||
|
nextTarget = { parentId, index: index + 1, intent: "after", targetNodeId: node.id };
|
||||||
|
} else {
|
||||||
|
nextTarget = {
|
||||||
|
parentId: node.id,
|
||||||
|
index: (node.children ?? []).length,
|
||||||
|
intent: "inside",
|
||||||
|
targetNodeId: node.id,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
nextTarget = {
|
||||||
|
parentId,
|
||||||
|
index: relativeY < 0.5 ? index : index + 1,
|
||||||
|
intent: relativeY < 0.5 ? "before" : "after",
|
||||||
|
targetNodeId: node.id,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
setDragState({ ...nextDragState, dropTarget: nextTarget });
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleContextActionSelect = (action: WorkspaceContextMenuAction, target: WorkspaceContextMenuTarget): void => {
|
||||||
|
if (action.id !== "new-folder") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (target.kind) {
|
||||||
|
case "workspace":
|
||||||
|
case "home":
|
||||||
|
beginFolderDraft(null, 0);
|
||||||
|
return;
|
||||||
|
case "folder":
|
||||||
|
beginFolderDraft(target.id, (findWorkspaceFolderDepth(workspaceTreeNodes(), target.id) ?? 0) + 1);
|
||||||
|
return;
|
||||||
|
case "settings":
|
||||||
|
case "item":
|
||||||
|
return;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -169,12 +697,13 @@ export const WorkspaceSidebar = (props: WorkspaceSidebarProps): JSX.Element => {
|
|||||||
classList={{
|
classList={{
|
||||||
[styles.sidebar]: true,
|
[styles.sidebar]: true,
|
||||||
[styles.sidebarCollapsed]: props.collapsed,
|
[styles.sidebarCollapsed]: props.collapsed,
|
||||||
|
[styles.sidebarDragMode]: !!dragState(),
|
||||||
}}
|
}}
|
||||||
aria-label="Left workspace sidebar"
|
aria-label="Left workspace sidebar"
|
||||||
data-ui="workspace-sidebar"
|
data-ui="workspace-sidebar"
|
||||||
data-collapsed={props.collapsed ? "true" : "false"}
|
data-collapsed={props.collapsed ? "true" : "false"}
|
||||||
onContextMenu={(event): void => {
|
onContextMenu={(event): void => {
|
||||||
contextMenu.openMenu(event, sidebarContextMenuTarget());
|
contextMenu.openMenu(event, sidebarContextMenuTarget);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
@@ -255,19 +784,39 @@ export const WorkspaceSidebar = (props: WorkspaceSidebarProps): JSX.Element => {
|
|||||||
</Show>
|
</Show>
|
||||||
|
|
||||||
<div data-slot="workspace-tree-root">
|
<div data-slot="workspace-tree-root">
|
||||||
<WorkspaceTreeBranch
|
<WorkspaceTreeBranch
|
||||||
nodes={appShellData.workspaceTree()}
|
nodes={workspaceTreeNodes()}
|
||||||
onOpenContextMenu={contextMenu.openMenu}
|
parentId={null}
|
||||||
onOpenContextMenuFromKeyboard={contextMenu.openMenuFromElement}
|
isFolderCollapsed={isFolderCollapsed}
|
||||||
/>
|
onToggleFolder={toggleFolder}
|
||||||
|
pendingFolderDraft={pendingFolderDraft()}
|
||||||
|
pendingFolderName={pendingFolderName()}
|
||||||
|
onPendingFolderNameChange={setPendingFolderName}
|
||||||
|
onSubmitPendingFolder={submitPendingFolder}
|
||||||
|
onCancelPendingFolder={cancelPendingFolder}
|
||||||
|
onOpenContextMenu={contextMenu.openMenu}
|
||||||
|
onOpenContextMenuFromKeyboard={contextMenu.openMenuFromElement}
|
||||||
|
onNodePointerDown={handleNodePointerDown}
|
||||||
|
onNodePointerMove={handleNodePointerMove}
|
||||||
|
dragState={dragState()}
|
||||||
|
isTreeClickSuppressed={suppressNextTreeClick}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
<WorkspaceContextMenu
|
<WorkspaceContextMenu
|
||||||
target={contextMenuTarget()}
|
target={contextMenu.menuState()?.target ?? null}
|
||||||
position={contextMenuPosition()}
|
position={(() => {
|
||||||
|
const state = contextMenu.menuState();
|
||||||
|
return state
|
||||||
|
? {
|
||||||
|
x: state.x,
|
||||||
|
y: state.y,
|
||||||
|
}
|
||||||
|
: null;
|
||||||
|
})()}
|
||||||
menuRef={contextMenu.setMenuRef}
|
menuRef={contextMenu.setMenuRef}
|
||||||
onClose={contextMenu.closeMenu}
|
onClose={contextMenu.closeMenu}
|
||||||
onSelect={handleContextActionSelect}
|
onSelect={handleContextActionSelect}
|
||||||
|
|||||||
@@ -194,6 +194,16 @@ const buildProjectItems = (payload: AppShellPayload | null): readonly ProjectIte
|
|||||||
id: project.id,
|
id: project.id,
|
||||||
name: project.name,
|
name: project.name,
|
||||||
description: project.slug || "Persisted project workspace",
|
description: project.slug || "Persisted project workspace",
|
||||||
|
groupLabel: payload.departments.find((department) => department.id === project.departmentId)?.name || "Projects",
|
||||||
|
parentLabel:
|
||||||
|
payload.teams.find((team) => team.id === project.teamId)?.name ||
|
||||||
|
payload.departments.find((department) => department.id === project.departmentId)?.name ||
|
||||||
|
"Shared project",
|
||||||
|
meta: (() => {
|
||||||
|
const workspaceCount = payload.workspaces.filter((workspace) => workspace.projectId === project.id).length;
|
||||||
|
|
||||||
|
return workspaceCount > 0 ? `${workspaceCount} workspace${workspaceCount === 1 ? "" : "s"}` : undefined;
|
||||||
|
})(),
|
||||||
active: index === 0,
|
active: index === 0,
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -71,9 +71,43 @@ export type ProjectItem = {
|
|||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
|
groupLabel?: string;
|
||||||
|
parentLabel?: string;
|
||||||
|
meta?: string;
|
||||||
active?: boolean;
|
active?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ProjectMenuTarget =
|
||||||
|
| {
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
kind: "surface";
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
kind: "folder";
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
kind: "project";
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ProjectContextMenuAction = {
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
tone?: "default" | "danger";
|
||||||
|
shortcut?: WorkspaceContextMenuShortcut;
|
||||||
|
children?: readonly ProjectContextMenuAction[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ProjectContextMenuSection = {
|
||||||
|
id: string;
|
||||||
|
label?: string;
|
||||||
|
items: readonly ProjectContextMenuAction[];
|
||||||
|
};
|
||||||
|
|
||||||
export type SidebarItem = {
|
export type SidebarItem = {
|
||||||
id: string;
|
id: string;
|
||||||
label: string;
|
label: string;
|
||||||
@@ -364,9 +398,31 @@ export const activeDepartment: ActiveDepartment = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const projectItems: readonly ProjectItem[] = [
|
export const projectItems: readonly ProjectItem[] = [
|
||||||
{ id: "general", name: "General", description: "Default shared project", active: true },
|
{
|
||||||
{ id: "operations", name: "Operations", description: "Cross-team planning and delivery" },
|
id: "general",
|
||||||
{ id: "hiring", name: "Hiring", description: "Candidate pipeline and interview loops" },
|
name: "General",
|
||||||
|
description: "Default shared project",
|
||||||
|
groupLabel: "Shared space",
|
||||||
|
parentLabel: "Workspace home",
|
||||||
|
meta: "1 workspace",
|
||||||
|
active: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "operations",
|
||||||
|
name: "Operations",
|
||||||
|
description: "Cross-team planning and delivery",
|
||||||
|
groupLabel: "Team folders",
|
||||||
|
parentLabel: "Shared Services",
|
||||||
|
meta: "2 workspaces",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "hiring",
|
||||||
|
name: "Hiring",
|
||||||
|
description: "Candidate pipeline and interview loops",
|
||||||
|
groupLabel: "Team folders",
|
||||||
|
parentLabel: "People Ops",
|
||||||
|
meta: "1 workspace",
|
||||||
|
},
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export const departmentItems: readonly DepartmentItem[] = [
|
export const departmentItems: readonly DepartmentItem[] = [
|
||||||
@@ -533,6 +589,69 @@ export const getWorkspaceContextMenuSections = (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getProjectCreateActions = (): readonly ProjectContextMenuAction[] =>
|
||||||
|
[
|
||||||
|
{ id: "new-project", label: "New project" },
|
||||||
|
{ id: "new-folder", label: "New folder" },
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
export const createProjectSurfaceTarget = (label = "Projects"): ProjectMenuTarget => ({
|
||||||
|
id: "project-surface",
|
||||||
|
label,
|
||||||
|
kind: "surface",
|
||||||
|
});
|
||||||
|
|
||||||
|
export const createProjectFolderTarget = (id: string, label: string): ProjectMenuTarget => ({
|
||||||
|
id,
|
||||||
|
label,
|
||||||
|
kind: "folder",
|
||||||
|
});
|
||||||
|
|
||||||
|
export const createProjectTarget = (project: ProjectItem): ProjectMenuTarget => ({
|
||||||
|
id: project.id,
|
||||||
|
label: project.name,
|
||||||
|
kind: "project",
|
||||||
|
});
|
||||||
|
|
||||||
|
export const getProjectContextMenuEyebrow = (target: ProjectMenuTarget): string => {
|
||||||
|
switch (target.kind) {
|
||||||
|
case "surface":
|
||||||
|
return "Projects";
|
||||||
|
case "folder":
|
||||||
|
return "Folder";
|
||||||
|
case "project":
|
||||||
|
return "Project";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getProjectContextMenuSections = (target: ProjectMenuTarget): readonly ProjectContextMenuSection[] => {
|
||||||
|
const createActions = getProjectCreateActions();
|
||||||
|
|
||||||
|
switch (target.kind) {
|
||||||
|
case "surface":
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
id: "create",
|
||||||
|
items: createActions,
|
||||||
|
},
|
||||||
|
] as const;
|
||||||
|
case "folder":
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
id: "create",
|
||||||
|
items: createActions,
|
||||||
|
},
|
||||||
|
] as const;
|
||||||
|
case "project":
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
id: "create",
|
||||||
|
items: createActions,
|
||||||
|
},
|
||||||
|
] as const;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const topBarActions: readonly TopBarAction[] = [
|
export const topBarActions: readonly TopBarAction[] = [
|
||||||
{ id: "search", label: "Search", icon: Search },
|
{ id: "search", label: "Search", icon: Search },
|
||||||
] as const;
|
] as const;
|
||||||
|
|||||||
Reference in New Issue
Block a user