mirror of
https://github.com/outline/outline.git
synced 2026-11-22 22:02:35 +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>
165 lines
3.9 KiB
TypeScript
165 lines
3.9 KiB
TypeScript
import { OpenIcon } from "outline-icons";
|
|
import * as React from "react";
|
|
import { useState, useEffect, useRef } from "react";
|
|
import styled from "styled-components";
|
|
import type { Optional } from "utility-types";
|
|
import { s } from "../../styles";
|
|
import { sanitizeUrl } from "../../utils/urls";
|
|
|
|
type Props = Omit<
|
|
Optional<React.ComponentProps<typeof Iframe>>,
|
|
"children" | "style"
|
|
> & {
|
|
/** The URL to load in the iframe */
|
|
src?: string;
|
|
/** Whether to display a border, defaults to true */
|
|
border?: boolean;
|
|
/** The aria title of the frame */
|
|
title?: string;
|
|
/** An icon to display under the frame representing the service */
|
|
icon?: React.ReactNode;
|
|
/** The canonical URL of the content */
|
|
canonicalUrl?: string;
|
|
/** Whether the node is currently selected */
|
|
isSelected?: boolean;
|
|
/** Additional styling */
|
|
style?: React.CSSProperties;
|
|
/** The allow policy of the frame */
|
|
allow?: string;
|
|
/** Ref to the underlying iframe element */
|
|
ref?: React.Ref<HTMLIFrameElement>;
|
|
};
|
|
|
|
const Frame = ({
|
|
border,
|
|
style = {},
|
|
ref,
|
|
icon,
|
|
title,
|
|
canonicalUrl,
|
|
isSelected,
|
|
referrerPolicy,
|
|
className = "",
|
|
src,
|
|
...rest
|
|
}: Props) => {
|
|
const [isLoaded, setIsLoaded] = useState(false);
|
|
const mountedRef = useRef(true);
|
|
|
|
useEffect(() => {
|
|
// Set mounted flag
|
|
mountedRef.current = true;
|
|
|
|
// Load iframe after a small delay
|
|
const timer = setTimeout(() => {
|
|
if (mountedRef.current) {
|
|
setIsLoaded(true);
|
|
}
|
|
}, 0);
|
|
|
|
// Cleanup function
|
|
return () => {
|
|
mountedRef.current = false;
|
|
clearTimeout(timer);
|
|
};
|
|
}, []);
|
|
|
|
const showBottomBar = !!(icon || canonicalUrl);
|
|
|
|
return (
|
|
<Rounded
|
|
style={style}
|
|
$showBottomBar={showBottomBar}
|
|
$border={border}
|
|
className={
|
|
isSelected ? `ProseMirror-selectednode ${className}` : className
|
|
}
|
|
>
|
|
{isLoaded && (
|
|
<Iframe
|
|
ref={ref}
|
|
$showBottomBar={showBottomBar}
|
|
sandbox="allow-same-origin allow-scripts allow-popups allow-popups-to-escape-sandbox allow-forms allow-downloads allow-storage-access-by-user-activation"
|
|
allow="fullscreen; encrypted-media; picture-in-picture; clipboard-read; clipboard-write"
|
|
style={style}
|
|
frameBorder="0"
|
|
title="embed"
|
|
loading="lazy"
|
|
src={sanitizeUrl(src)}
|
|
referrerPolicy={referrerPolicy}
|
|
allowFullScreen
|
|
{...rest}
|
|
/>
|
|
)}
|
|
{showBottomBar && (
|
|
<Bar>
|
|
{icon} <Title>{title}</Title>
|
|
{canonicalUrl && (
|
|
<Open
|
|
href={sanitizeUrl(canonicalUrl)}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
>
|
|
<OpenIcon size={18} /> Open
|
|
</Open>
|
|
)}
|
|
</Bar>
|
|
)}
|
|
</Rounded>
|
|
);
|
|
};
|
|
|
|
const Iframe = styled.iframe<{ $showBottomBar: boolean }>`
|
|
border-radius: ${(props) => (props.$showBottomBar ? "3px 3px 0 0" : "3px")};
|
|
display: block;
|
|
`;
|
|
|
|
const Rounded = styled.div<{
|
|
$showBottomBar: boolean;
|
|
$border?: boolean;
|
|
}>`
|
|
border: 1px solid
|
|
${(props) => (props.$border ? props.theme.embedBorder : "transparent")};
|
|
border-radius: 6px;
|
|
overflow: hidden;
|
|
|
|
${(props) =>
|
|
props.$showBottomBar &&
|
|
`
|
|
padding-bottom: 28px;
|
|
`}
|
|
`;
|
|
|
|
const Open = styled.a`
|
|
color: ${s("textSecondary")} !important;
|
|
font-size: 13px;
|
|
font-weight: 500;
|
|
align-items: center;
|
|
display: flex;
|
|
position: absolute;
|
|
right: 0;
|
|
padding: 0 8px;
|
|
`;
|
|
|
|
const Title = styled.span`
|
|
font-size: 13px;
|
|
font-weight: 500;
|
|
padding-left: 4px;
|
|
`;
|
|
|
|
const Bar = styled.div`
|
|
display: flex;
|
|
align-items: center;
|
|
border-top: 1px solid ${(props) => props.theme.embedBorder};
|
|
background: ${s("backgroundSecondary")};
|
|
color: ${s("textSecondary")};
|
|
padding: 0 8px;
|
|
border-bottom-left-radius: 6px;
|
|
border-bottom-right-radius: 6px;
|
|
user-select: none;
|
|
height: 28px;
|
|
position: relative;
|
|
`;
|
|
|
|
export default Frame;
|