mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-14 10:34:06 +02:00
# Description of Changes ## What & why This PR introduces the **Stirling developer portal** — a new control-plane frontend that sits alongside the existing PDF editor — plus the shared design system and workspace structure needed to host both apps in one frontend. The portal is the parent product surface: where users connect sources, compose pipelines, wire agents, and manage usage / billing / infrastructure, with the PDF editor as one capability inside it. This PR lays the **foundation** — workspace reshape, design system, app shell, navigation, and a mock-driven home — rather than wiring real backends (those surfaces are placeholders for follow-up phases). ## What's in this PR **1. Frontend repo reshape (`frontend/src/` → `frontend/editor/`)** The existing editor app moved under `frontend/editor/`, so `editor`, `portal`, and `shared` are siblings in one workspace. All references were updated accordingly: `LICENSE`, `.dockerignore`, `.gitignore`, build/sign shell scripts, the GH language-check script, the Taskfile, and Docker config. **No editor source logic changed — path references only.** **2. New shared design system (`frontend/shared/`)** - **Design tokens** in `tokens.css` as the single runtime source of truth (light/dark, category accents, gradients). `tokens.ts` now holds only the `Tier` type — the old JS palette mirror was removed (nothing consumed it and it had drifted). - ~30 framework-light **components** (Card, Button, Input, Select, Tabs, Modal, Drawer, Toast, MetricCard, StatusBadge, Skeleton, EmptyState, …) with Storybook stories. - **Typed data catalogues**: `endpoints.ts` (10 verticals / 64 endpoints) and `ops.ts`. **3. New developer portal app (`frontend/portal/`)** - App shell: `Header`, `Sidebar`, `AssistantPanel`, search modal, notifications, tier switcher, theme toggle, MSW toggle. - **Tier-aware** home (free / pay-as-you-go / enterprise): KPI strip, 30-day usage chart, onboarding checklist, quick actions, recent activity, region health, product grid, and a curated **"Popular use cases"** teaser. - **Documents** view hosting the full, tab-filterable endpoint catalogue. - Placeholder views for Sources / Pipelines / Agents / Editor / Infrastructure / Usage & Billing / Developer Docs / Settings (follow-up phases). - **MSW-mocked** API layer: `api/*` issues real `fetch`, intercepted by mocks in dev/Storybook; pointing at a real backend is just a matter of not registering MSW. `react-router` URLs; Tier / View / UI contexts. **4. Tooling & guardrails** - ESLint extended to `portal` + `shared`, with **layering-boundary rules**: `shared/` may depend only on third-party packages and itself (no `@app` / `@portal` / `@core` / `@proprietary` / Tauri), so it stays cleanly extractable into a standalone package later. - `dpdm` circular-dependency check now walks editor + portal + shared (the old glob matched only 2 files). - New **devDependencies only** — Storybook (+ a11y/docs/themes addons), MSW. No runtime dependencies added. - New tasks: `frontend:dev:portal`, `frontend:build:portal`. ## Testing done locally - `tsc` for both `portal` and `shared` projects — clean - `eslint --max-warnings=0` across the whole frontend — clean - `dpdm` circular-dependency check — no cycles - Editor builds clean: `vite build editor --mode core` (✓ built, only the pre-existing >500 kB chunk-size advisory) - Editor runs in dev (core mode) with **zero console errors**; portal runs in dev across all three tiers ## Notes for reviewers - The change is overwhelmingly **additive**: `shared/` and `portal/` are brand-new; the existing editor is path-reference changes only. - The portal is intentionally **mock-driven** at this stage — real backends and the remaining views land in follow-up phases. --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [x] I have performed a self-review of my own code - [x] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### Translations (if applicable) - [ ] I ran [`scripts/counter_translation.py`](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/docs/counter_translation.md) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have run `task check` to verify linters, typechecks, and tests pass - [x] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#7-testing) for more details. --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
234 lines
5.5 KiB
TypeScript
234 lines
5.5 KiB
TypeScript
import {
|
|
cloneElement,
|
|
createContext,
|
|
isValidElement,
|
|
useCallback,
|
|
useContext,
|
|
useEffect,
|
|
useId,
|
|
useMemo,
|
|
useRef,
|
|
useState,
|
|
type ReactElement,
|
|
type ReactNode,
|
|
} from "react";
|
|
import "@shared/components/Dropdown.css";
|
|
|
|
type Alignment = "start" | "end";
|
|
|
|
interface DropdownContextValue {
|
|
open: boolean;
|
|
setOpen: (open: boolean) => void;
|
|
triggerRef: React.RefObject<HTMLElement | null>;
|
|
menuId: string;
|
|
align: Alignment;
|
|
}
|
|
|
|
const DropdownContext = createContext<DropdownContextValue | null>(null);
|
|
|
|
function useDropdownCtx(): DropdownContextValue {
|
|
const ctx = useContext(DropdownContext);
|
|
if (!ctx)
|
|
throw new Error(
|
|
"Dropdown subcomponents must be used inside <Dropdown.Root>",
|
|
);
|
|
return ctx;
|
|
}
|
|
|
|
export interface DropdownRootProps {
|
|
/** Controlled open state. Omit for uncontrolled. */
|
|
open?: boolean;
|
|
defaultOpen?: boolean;
|
|
onOpenChange?: (open: boolean) => void;
|
|
/** Alignment of the menu relative to the trigger. */
|
|
align?: Alignment;
|
|
children: ReactNode;
|
|
className?: string;
|
|
}
|
|
|
|
function Root({
|
|
open: openProp,
|
|
defaultOpen,
|
|
onOpenChange,
|
|
align = "end",
|
|
children,
|
|
className,
|
|
}: DropdownRootProps) {
|
|
const [uncontrolled, setUncontrolled] = useState(defaultOpen ?? false);
|
|
const isControlled = openProp !== undefined;
|
|
const open = isControlled ? openProp : uncontrolled;
|
|
|
|
const setOpen = useCallback(
|
|
(next: boolean) => {
|
|
if (!isControlled) setUncontrolled(next);
|
|
onOpenChange?.(next);
|
|
},
|
|
[isControlled, onOpenChange],
|
|
);
|
|
|
|
const triggerRef = useRef<HTMLElement | null>(null);
|
|
const containerRef = useRef<HTMLDivElement | null>(null);
|
|
const menuId = useId();
|
|
|
|
// Click-outside + Escape close.
|
|
useEffect(() => {
|
|
if (!open) return;
|
|
function onDocClick(e: MouseEvent) {
|
|
if (
|
|
containerRef.current &&
|
|
!containerRef.current.contains(e.target as Node)
|
|
) {
|
|
setOpen(false);
|
|
}
|
|
}
|
|
function onKey(e: KeyboardEvent) {
|
|
if (e.key === "Escape") {
|
|
setOpen(false);
|
|
triggerRef.current?.focus();
|
|
}
|
|
}
|
|
document.addEventListener("mousedown", onDocClick);
|
|
document.addEventListener("keydown", onKey);
|
|
return () => {
|
|
document.removeEventListener("mousedown", onDocClick);
|
|
document.removeEventListener("keydown", onKey);
|
|
};
|
|
}, [open, setOpen]);
|
|
|
|
const value = useMemo<DropdownContextValue>(
|
|
() => ({ open, setOpen, triggerRef, menuId, align }),
|
|
[open, setOpen, menuId, align],
|
|
);
|
|
|
|
return (
|
|
<DropdownContext.Provider value={value}>
|
|
<div
|
|
ref={containerRef}
|
|
className={["sui-dd", className ?? ""].filter(Boolean).join(" ")}
|
|
>
|
|
{children}
|
|
</div>
|
|
</DropdownContext.Provider>
|
|
);
|
|
}
|
|
|
|
export interface DropdownTriggerProps {
|
|
/** A single button-like element. Receives onClick + aria props. */
|
|
children: ReactElement<{
|
|
onClick?: (e: React.MouseEvent) => void;
|
|
"aria-haspopup"?: string;
|
|
"aria-expanded"?: boolean;
|
|
"aria-controls"?: string;
|
|
ref?: React.Ref<unknown>;
|
|
}>;
|
|
}
|
|
|
|
function Trigger({ children }: DropdownTriggerProps) {
|
|
const { open, setOpen, triggerRef, menuId } = useDropdownCtx();
|
|
if (!isValidElement(children)) {
|
|
throw new Error(
|
|
"Dropdown.Trigger requires exactly one React element child",
|
|
);
|
|
}
|
|
return cloneElement(children, {
|
|
ref: triggerRef as React.Ref<unknown>,
|
|
onClick: (e: React.MouseEvent) => {
|
|
children.props.onClick?.(e);
|
|
setOpen(!open);
|
|
},
|
|
"aria-haspopup": "menu",
|
|
"aria-expanded": open,
|
|
"aria-controls": menuId,
|
|
});
|
|
}
|
|
|
|
export interface DropdownMenuProps {
|
|
children: ReactNode;
|
|
className?: string;
|
|
/** Optional min-width override (px or CSS length). */
|
|
width?: string | number;
|
|
}
|
|
|
|
function Menu({ children, className, width }: DropdownMenuProps) {
|
|
const { open, menuId, align } = useDropdownCtx();
|
|
if (!open) return null;
|
|
const style =
|
|
width !== undefined
|
|
? { minWidth: typeof width === "number" ? `${width}px` : width }
|
|
: undefined;
|
|
return (
|
|
<div
|
|
id={menuId}
|
|
role="menu"
|
|
className={["sui-dd__menu", `sui-dd__menu--${align}`, className ?? ""]
|
|
.filter(Boolean)
|
|
.join(" ")}
|
|
style={style}
|
|
>
|
|
{children}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export interface DropdownItemProps {
|
|
onSelect?: () => void;
|
|
/** Active visual state (e.g. current value in a switcher). */
|
|
active?: boolean;
|
|
disabled?: boolean;
|
|
/** Optional leading visual. */
|
|
leading?: ReactNode;
|
|
/** Optional trailing visual (kbd hint, badge, etc). */
|
|
trailing?: ReactNode;
|
|
children?: ReactNode;
|
|
className?: string;
|
|
}
|
|
|
|
function Item({
|
|
onSelect,
|
|
active,
|
|
disabled,
|
|
leading,
|
|
trailing,
|
|
children,
|
|
className,
|
|
}: DropdownItemProps) {
|
|
const { setOpen } = useDropdownCtx();
|
|
return (
|
|
<button
|
|
type="button"
|
|
role="menuitem"
|
|
disabled={disabled}
|
|
aria-current={active ? "true" : undefined}
|
|
className={[
|
|
"sui-dd__item",
|
|
active ? "is-active" : "",
|
|
disabled ? "is-disabled" : "",
|
|
className ?? "",
|
|
]
|
|
.filter(Boolean)
|
|
.join(" ")}
|
|
onClick={() => {
|
|
if (disabled) return;
|
|
onSelect?.();
|
|
setOpen(false);
|
|
}}
|
|
>
|
|
{leading && <span className="sui-dd__item-leading">{leading}</span>}
|
|
<span className="sui-dd__item-label">{children}</span>
|
|
{trailing && <span className="sui-dd__item-trailing">{trailing}</span>}
|
|
</button>
|
|
);
|
|
}
|
|
|
|
function Divider() {
|
|
return <div className="sui-dd__divider" role="separator" aria-hidden />;
|
|
}
|
|
|
|
export const Dropdown = {
|
|
Root,
|
|
Trigger,
|
|
Menu,
|
|
Item,
|
|
Divider,
|
|
};
|