mirror of
https://github.com/outline/outline.git
synced 2026-11-24 23:00:18 +03:00
* React 19 upgrade Bumps react and react-dom to 19.2.8, with the dependency changes React 19 requires: react-is 19, @types/react 19, @types/react-dom 19, react-helmet-async 3 and react-avatar-editor 15 (which now ships its own types). framer-motion moves to 13 — its v6 types reference React.ReactHTML, removed from @types/react 19. The type changes fall into a few classes: - The global JSX namespace is gone, so JSX.Element becomes React.JSX.Element and the custom element declarations move into a module augmentation. - useRef() now requires an initial value. - A ref created with a null initial value is typed nullable, so consumers that accept one are widened to RefObject<T | null>. - React.ReactChild was removed; tooltips take React.ReactNode. - Ref callbacks may only return a cleanup function. react-dnd connectors return the connected node, so useDragRef and useDropRef wrap useDrag and useDrop and hand back a ref callback. react-i18next stays on v12: i18next 23 drops compatibilityJSON "v3", which would rewrite all 64 _plural keys across every locale. outline-icons, oy-vey and react-waypoint have no release that lists React 19 as a peer. All three render correctly under it; the install reports them as unmet peers. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Remove react-helmet and forwardRef --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
152 lines
3.8 KiB
TypeScript
152 lines
3.8 KiB
TypeScript
import { observer } from "mobx-react";
|
|
import * as React from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import styled from "styled-components";
|
|
import breakpoint from "styled-components-breakpoint";
|
|
import { s, ellipsis } from "@shared/styles";
|
|
import Flex from "~/components/Flex";
|
|
import Disclosure from "~/components/Sidebar/components/Disclosure";
|
|
import Text from "~/components/Text";
|
|
|
|
type Props = {
|
|
/** Whether this node is the chosen destination (committed pick via click or Enter). */
|
|
selected: boolean;
|
|
/** Whether this node is currently highlighted by pointer hover or keyboard navigation. */
|
|
active: boolean;
|
|
/** Inline style passed in by the virtualized list for absolute positioning. */
|
|
style: React.CSSProperties;
|
|
/** Whether this node's children are currently revealed in the tree. */
|
|
expanded: boolean;
|
|
/** Icon rendered before the title (document icon, emoji, or star). */
|
|
icon?: React.ReactNode;
|
|
/** Display title for the node. */
|
|
title: string;
|
|
/** Zero-based nesting depth, used to indent the node. */
|
|
depth: number;
|
|
/** Whether this node has descendants and should render a disclosure chevron. */
|
|
hasChildren: boolean;
|
|
/** Fired when the disclosure chevron is clicked to expand or collapse the node. */
|
|
onDisclosureClick: (ev: React.MouseEvent) => void;
|
|
/** Fired on pointer movement over the node; used to update the active highlight. */
|
|
onPointerMove: (ev: React.MouseEvent) => void;
|
|
/** Fired when the node is clicked to select it. */
|
|
onClick: (ev: React.MouseEvent) => void;
|
|
/** Fired when the node is double-clicked to submit the current selection. */
|
|
onDoubleClick: (ev: React.MouseEvent) => void;
|
|
/** Ref to the node element. */
|
|
ref?: React.Ref<HTMLSpanElement>;
|
|
};
|
|
|
|
function DocumentExplorerNode({
|
|
selected,
|
|
active,
|
|
style,
|
|
expanded,
|
|
icon,
|
|
title,
|
|
depth,
|
|
hasChildren,
|
|
onDisclosureClick,
|
|
onPointerMove,
|
|
onClick,
|
|
onDoubleClick,
|
|
ref,
|
|
}: Props) {
|
|
const { t } = useTranslation();
|
|
const DISCLOSURE = 24;
|
|
const width = (depth + 2) * DISCLOSURE;
|
|
|
|
return (
|
|
<Node
|
|
ref={ref}
|
|
selected={selected}
|
|
active={active}
|
|
onClick={onClick}
|
|
onDoubleClick={onDoubleClick}
|
|
style={style}
|
|
onPointerMove={onPointerMove}
|
|
role="option"
|
|
aria-selected={selected}
|
|
>
|
|
<Spacer width={width}>
|
|
{hasChildren && (
|
|
<StyledDisclosure
|
|
expanded={expanded}
|
|
onClick={onDisclosureClick}
|
|
tabIndex={-1}
|
|
/>
|
|
)}
|
|
</Spacer>
|
|
{icon}
|
|
<Title>{title || t("Untitled")}</Title>
|
|
</Node>
|
|
);
|
|
}
|
|
|
|
const Title = styled(Text)`
|
|
${ellipsis()}
|
|
margin: 0 4px 0 4px;
|
|
color: inherit;
|
|
`;
|
|
|
|
const StyledDisclosure = styled(Disclosure)`
|
|
position: relative;
|
|
left: auto;
|
|
margin: 2px 0;
|
|
|
|
&&[aria-expanded="true"]:not(:hover) {
|
|
background: none;
|
|
}
|
|
`;
|
|
|
|
const Spacer = styled(Flex)<{ width: number }>`
|
|
flex-direction: row-reverse;
|
|
flex-shrink: 0;
|
|
width: ${(props) => props.width}px;
|
|
`;
|
|
|
|
export const Node = styled.span<{
|
|
active: boolean;
|
|
selected: boolean;
|
|
style: React.CSSProperties;
|
|
}>`
|
|
display: flex;
|
|
user-select: none;
|
|
overflow: hidden;
|
|
font-size: 16px;
|
|
width: ${(props) => props.style.width};
|
|
color: ${s("text")};
|
|
cursor: var(--pointer);
|
|
padding: 12px;
|
|
border-radius: 6px;
|
|
background: ${(props) =>
|
|
!props.selected && props.active && props.theme.listItemHoverBackground};
|
|
|
|
svg {
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
&:focus {
|
|
outline: none;
|
|
}
|
|
|
|
${(props) =>
|
|
props.selected &&
|
|
`
|
|
background: ${props.theme.accent};
|
|
color: ${props.theme.white};
|
|
|
|
svg {
|
|
color: ${props.theme.white};
|
|
fill: ${props.theme.white};
|
|
}
|
|
`}
|
|
|
|
${breakpoint("tablet")`
|
|
padding: 4px;
|
|
font-size: 15px;
|
|
`}
|
|
`;
|
|
|
|
export default observer(DocumentExplorerNode);
|