diff --git a/app/components/Actions.ts b/app/components/Actions.ts index aff0f693c8..7e1e637dc1 100644 --- a/app/components/Actions.ts +++ b/app/components/Actions.ts @@ -1,5 +1,6 @@ import styled from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import { breakpoint } from "@shared/styles/breakpoint"; +import { MOBILE_TOUCH_TARGET } from "@shared/constants"; import { s } from "@shared/styles"; import Flex from "~/components/Flex"; @@ -10,6 +11,10 @@ export const Action = styled(Flex)` font-size: 15px; flex-shrink: 0; + ${breakpoint("mobile", "tablet")` + height: ${MOBILE_TOUCH_TARGET}px; + `}; + &:empty { display: none; } diff --git a/app/components/Button.tsx b/app/components/Button.tsx index 6bb3d8c9ad..524aa00672 100644 --- a/app/components/Button.tsx +++ b/app/components/Button.tsx @@ -3,6 +3,8 @@ import { DisclosureIcon } from "outline-icons"; import { darken, lighten, transparentize } from "polished"; import * as React from "react"; import styled from "styled-components"; +import { breakpoint } from "@shared/styles/breakpoint"; +import { MOBILE_TOUCH_TARGET } from "@shared/constants"; import { s } from "@shared/styles"; import type { Props as ActionButtonProps } from "~/components/ActionButton"; import ActionButton from "~/components/ActionButton"; @@ -36,6 +38,12 @@ const RealButton = styled(ActionButton)` transition: background 200ms ease-out; ${undraggableOnDesktop()} + ${breakpoint("mobile", "tablet")` + height: ${MOBILE_TOUCH_TARGET}px; + border-radius: ${MOBILE_TOUCH_TARGET / 2}px; + font-size: 16px; + `}; + &::-moz-focus-inner { padding: 0; border: 0; @@ -126,11 +134,13 @@ const Label = styled.span<{ hasIcon?: boolean }>` ${(props) => props.hasIcon && "padding-inline-start: 4px;"}; `; -export const Inner = styled.span<{ +interface InnerProps { disclosure?: boolean; hasIcon?: boolean; hasText?: boolean; -}>` +} + +export const Inner = styled.span` display: flex; padding: 0 8px; padding-inline-end: ${(props) => (props.disclosure ? 2 : 8)}px; @@ -141,6 +151,18 @@ export const Inner = styled.span<{ ${(props) => props.hasIcon && props.hasText && "padding-inline-start: 4px;"}; ${(props) => props.hasIcon && !props.hasText && "padding: 0 4px;"}; + + ${breakpoint("mobile", "tablet")` + min-height: ${MOBILE_TOUCH_TARGET}px; + padding: 0 16px; + padding-inline-end: ${(props: InnerProps) => (props.disclosure ? 8 : 16)}px; + ${(props: InnerProps) => + props.hasIcon && props.hasText && "padding-inline-start: 12px;"}; + ${(props: InnerProps) => + props.hasIcon && + !props.hasText && + `padding: 0 ${(MOBILE_TOUCH_TARGET - 24) / 2}px;`}; + `}; `; export type Props = ActionButtonProps & { @@ -192,6 +214,7 @@ function Button( $danger={danger} $fullwidth={fullwidth} $borderOnHover={borderOnHover} + data-variant={danger ? "danger" : neutral ? "neutral" : "primary"} {...rest} > diff --git a/app/components/CenteredContent.tsx b/app/components/CenteredContent.tsx index 7281629634..22efd72fbe 100644 --- a/app/components/CenteredContent.tsx +++ b/app/components/CenteredContent.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import styled from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import { breakpoint } from "@shared/styles/breakpoint"; import { EditorStyleHelper } from "@shared/editor/styles/EditorStyleHelper"; type Props = { diff --git a/app/components/CircularProgressBar.tsx b/app/components/CircularProgressBar.tsx index 9fc5aeb32a..04a143772e 100644 --- a/app/components/CircularProgressBar.tsx +++ b/app/components/CircularProgressBar.tsx @@ -17,12 +17,12 @@ const Circle = ({ }) => { const radius = offset * 0.7; const circumference = 2 * Math.PI * radius; - let strokePercentage; + let strokeDashoffset = 0; - if (percentage) { + if (percentage !== undefined) { // because the circle is so small, anything greater than 85% appears like 100% - percentage = percentage > 85 && percentage < 100 ? 85 : percentage; - strokePercentage = ((100 - percentage) * circumference) / 100; + const visible = percentage > 85 && percentage < 100 ? 85 : percentage; + strokeDashoffset = ((100 - visible) * circumference) / 100; } return ( @@ -31,13 +31,14 @@ const Circle = ({ cx={offset} cy={offset} fill="none" - stroke={strokePercentage !== circumference ? color : ""} + stroke={color} strokeWidth={2.5} strokeDasharray={circumference} - strokeDashoffset={percentage ? strokePercentage : 0} strokeLinecap="round" style={{ - transition: "stroke-dashoffset 0.6s ease 0s", + strokeDashoffset: `${strokeDashoffset}px`, + opacity: percentage === 0 ? 0 : 1, + transition: "stroke-dashoffset 0.6s ease, opacity 0.6s ease", }} /> ); @@ -76,13 +77,7 @@ const CircularProgressBar = ({ > - {percentage > 0 && ( - - )} + ); diff --git a/app/components/Collaborators.tsx b/app/components/Collaborators.tsx index 2eaece4f7a..fc9dda40ca 100644 --- a/app/components/Collaborators.tsx +++ b/app/components/Collaborators.tsx @@ -1,7 +1,9 @@ import { filter, isEqual, orderBy, uniq } from "es-toolkit/compat"; import { observer } from "mobx-react"; +import styled from "styled-components"; import { useState, useMemo, useEffect, useCallback } from "react"; import { useTranslation } from "react-i18next"; +import { MOBILE_TOUCH_TARGET } from "@shared/constants"; import type Document from "~/models/Document"; import type User from "~/models/User"; import type { AvatarProps } from "~/components/Avatar"; @@ -15,8 +17,12 @@ import { PopoverContent, } from "~/components/primitives/Popover"; import useCurrentUser from "~/hooks/useCurrentUser"; +import useMobile from "~/hooks/useMobile"; import useStores from "~/hooks/useStores"; +/** Space after the avatars on mobile, matching the inset of a 24px icon in a touch target. */ +const MobileIconInset = (MOBILE_TOUCH_TARGET - 24) / 2; + type Props = { /** The document to display live collaborators for */ document: Document; @@ -31,6 +37,8 @@ type Props = { function Collaborators(props: Props) { const { limit = 6 } = props; const { t } = useTranslation(); + const isMobile = useMobile(); + const size = isMobile ? AvatarSize.XLarge : AvatarSize.Large; const user = useCurrentUser(); const currentUserId = user?.id; const [requestedUserIds, setRequestedUserIds] = useState([]); @@ -163,21 +171,23 @@ function Collaborators(props: Props) { return null; } + const facepileWidth = Math.min(collaborators.length, limit) * size; + return ( - - + @@ -186,4 +196,9 @@ function Collaborators(props: Props) { ); } +const FacepileButton = styled(NudeButton)` + display: inline-flex; + align-items: center; +`; + export default observer(Collaborators); diff --git a/app/components/CommandBar/CommandBar.tsx b/app/components/CommandBar/CommandBar.tsx index 9fdf606e9c..39f4b66608 100644 --- a/app/components/CommandBar/CommandBar.tsx +++ b/app/components/CommandBar/CommandBar.tsx @@ -3,7 +3,7 @@ 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 { breakpoint } from "@shared/styles/breakpoint"; import { depths, s } from "@shared/styles"; import { Portal } from "~/components/Portal"; import SearchActions from "~/components/SearchActions"; diff --git a/app/components/CommandBar/SharedCommandBar.tsx b/app/components/CommandBar/SharedCommandBar.tsx index fe09861a77..8f41e847e0 100644 --- a/app/components/CommandBar/SharedCommandBar.tsx +++ b/app/components/CommandBar/SharedCommandBar.tsx @@ -3,7 +3,7 @@ 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 { breakpoint } from "@shared/styles/breakpoint"; import { depths, s } from "@shared/styles"; import { Portal } from "~/components/Portal"; import CommandBarResults from "./CommandBarResults"; diff --git a/app/components/DocumentExplorer/DocumentExplorer.tsx b/app/components/DocumentExplorer/DocumentExplorer.tsx index 90b659c2f1..e99efb9ed8 100644 --- a/app/components/DocumentExplorer/DocumentExplorer.tsx +++ b/app/components/DocumentExplorer/DocumentExplorer.tsx @@ -15,7 +15,7 @@ import { useTranslation } from "react-i18next"; import AutoSizer from "react-virtualized-auto-sizer"; import { FixedSizeList as List } from "react-window"; import styled, { useTheme } from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import { breakpoint } from "@shared/styles/breakpoint"; import Icon from "@shared/components/Icon"; import type { NavigationNode } from "@shared/types"; import { isModKey } from "@shared/utils/keyboard"; diff --git a/app/components/DocumentExplorer/DocumentExplorerNode.tsx b/app/components/DocumentExplorer/DocumentExplorerNode.tsx index 9dfc313e8d..edfab5d471 100644 --- a/app/components/DocumentExplorer/DocumentExplorerNode.tsx +++ b/app/components/DocumentExplorer/DocumentExplorerNode.tsx @@ -2,7 +2,7 @@ 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 { breakpoint } from "@shared/styles/breakpoint"; import { s, ellipsis } from "@shared/styles"; import Flex from "~/components/Flex"; import Disclosure from "~/components/Sidebar/components/Disclosure"; diff --git a/app/components/DocumentListItem.tsx b/app/components/DocumentListItem.tsx index 6bd015f197..02d907b50d 100644 --- a/app/components/DocumentListItem.tsx +++ b/app/components/DocumentListItem.tsx @@ -5,7 +5,7 @@ import { mergeRefs } from "react-merge-refs"; import { Link } from "react-router-dom"; import { CheckmarkIcon, DocumentIcon } from "outline-icons"; import styled, { css, useTheme } from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import { breakpoint } from "@shared/styles/breakpoint"; import EventBoundary from "@shared/components/EventBoundary"; import Icon from "@shared/components/Icon"; import { s, hover } from "@shared/styles"; diff --git a/app/components/Facepile.tsx b/app/components/Facepile.tsx index 62a36e09cc..e257f06670 100644 --- a/app/components/Facepile.tsx +++ b/app/components/Facepile.tsx @@ -63,7 +63,7 @@ function Facepile({ model, size, style: { - marginRight: lastChild ? 0 : -4, + marginRight: lastChild ? 0 : -Math.round(size / 7), ...(lastChild || filtered.length === 1 ? {} : { clipPath: `url(#${clipPathId(size)})` }), diff --git a/app/components/FilterOptions.tsx b/app/components/FilterOptions.tsx index 99cf68c4a1..058807c49c 100644 --- a/app/components/FilterOptions.tsx +++ b/app/components/FilterOptions.tsx @@ -3,6 +3,8 @@ import { CheckmarkIcon } from "outline-icons"; import * as React from "react"; import { useTranslation } from "react-i18next"; import styled from "styled-components"; +import { breakpoint } from "@shared/styles/breakpoint"; +import { MOBILE_TOUCH_TARGET } from "@shared/constants"; import { s } from "@shared/styles"; import type { FetchPageParams } from "~/stores/base/Store"; import Button, { Inner } from "~/components/Button"; @@ -359,6 +361,16 @@ export const StyledButton = styled(Button)` line-height: 28px; min-height: auto; } + + ${breakpoint("mobile", "tablet")` + && { + height: ${MOBILE_TOUCH_TARGET}px; + } + + && ${Inner} { + min-height: ${MOBILE_TOUCH_TARGET}px; + } + `}; `; export default FilterOptions; diff --git a/app/components/Header.tsx b/app/components/Header.tsx index 575d2dcafc..d93f795521 100644 --- a/app/components/Header.tsx +++ b/app/components/Header.tsx @@ -6,11 +6,12 @@ import { transparentize } from "polished"; import * as React from "react"; import { useTranslation } from "react-i18next"; import { mergeRefs } from "react-merge-refs"; -import styled from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import styled, { css } from "styled-components"; +import type { DefaultTheme } from "styled-components"; +import { breakpoint } from "@shared/styles/breakpoint"; import useMeasure from "react-use-measure"; -import { HEADER_HEIGHT } from "@shared/constants"; -import { depths, s } from "@shared/styles"; +import { HEADER_HEIGHT, MOBILE_TOUCH_TARGET } from "@shared/constants"; +import { depths, hover, s } from "@shared/styles"; import { metaDisplay } from "@shared/utils/keyboard"; import Button from "~/components/Button"; import Fade from "~/components/Fade"; @@ -164,6 +165,26 @@ function Header({ left, title, actions, hasSidebar, className, ref }: Props) { ); } +/** Height of the fade at the bottom of the mobile header background. */ +const HeaderFadeHeight = 64; + +/** Eased mask stops for the header fade, so it has no visible start or end. */ +const headerFadeStops = [1, 0.85, 0.5, 0.15, 0] + .map( + (opacity, index, stops) => + `rgb(0 0 0 / ${opacity}) calc(100% - ${HeaderFadeHeight * (1 - index / (stops.length - 1))}px)` + ) + .join(", "); + +/** Raised capsule that holds header buttons on mobile, like an iOS toolbar. */ +const mobilePill = css` + background: ${s("menuBackground")}; + box-shadow: + 0 0 0 1px ${s("divider")}, + 0 4px 12px rgb(0 0 0 / 8%); + border-radius: ${MOBILE_TOUCH_TARGET / 2}px; +`; + const Breadcrumbs = styled("div")` flex-grow: 1; flex-basis: 0; @@ -172,6 +193,20 @@ const Breadcrumbs = styled("div")` padding-inline: 0 8px; display: flex; + ${breakpoint("mobile", "tablet")` + gap: 8px; + + && [data-variant] { + ${mobilePill} + } + + && [data-variant]:${hover}:not(:disabled), + && [data-variant][aria-expanded="true"] { + ${mobilePill} + background: ${s("buttonNeutralBackground")}; + } + `}; + ${breakpoint("tablet")` min-width: auto; `}; @@ -185,6 +220,45 @@ const Actions = styled(Flex)` gap: 8px; margin-inline-start: 8px; + ${breakpoint("mobile", "tablet")` + flex: 0 0 auto; + gap: 0; + margin-inline-start: auto; + + &:not(:empty) { + ${mobilePill} + padding-inline: 10px; + } + + /* Touch targets overlap so icons sit closer than their 44px hit areas. */ + & > * { + margin-inline: -4px; + } + + && [data-variant] { + background: transparent; + box-shadow: none; + } + + && [data-variant="primary"] { + color: ${s("accent")}; + } + + && [data-variant="primary"]:disabled { + color: ${s("textTertiary")}; + + svg { + fill: currentColor; + } + } + + && [data-variant]:${hover}:not(:disabled), + && [data-variant][aria-expanded="true"] { + background: ${s("buttonNeutralBackground")}; + box-shadow: none; + } + `}; + ${breakpoint("tablet")` position: unset; `}; @@ -224,7 +298,7 @@ const Wrapper = styled(Flex)` backdrop-filter: blur(20px); `}; - padding: 12px 16px; + padding: 6px 16px; padding-inline-end: ${endPadding(16)}; transform: translate3d(0, 0, 0); min-height: ${HEADER_HEIGHT}px; @@ -249,6 +323,35 @@ const Wrapper = styled(Flex)` display: none; } + ${breakpoint("mobile", "tablet")` + ${(props: WrapperProps & { theme: DefaultTheme }) => + !props.$passThrough && + ` + background: transparent; + backdrop-filter: none; + + /* The blurred background extends past the header and fades out, so content blends under it. */ + &::before { + content: ""; + position: absolute; + inset: 0 0 -${HeaderFadeHeight / 2}px; + z-index: -1; + pointer-events: none; + background: ${transparentize(0.2, props.theme.background)}; + backdrop-filter: blur(20px); + mask-image: linear-gradient(to bottom, ${headerFadeStops}); + } + + /* A stuck tab bar continues the header, so the header is solid above it. */ + body:has([data-sticky-tabs][data-stuck]) &::before { + inset: 0; + background: ${props.theme.background}; + backdrop-filter: none; + mask-image: none; + } + `} + `}; + ${breakpoint("tablet")` padding: 12px; padding-inline-end: ${endPadding(12)}; @@ -282,7 +385,6 @@ const Title = styled("div")` `; const MobileMenuButton = styled(Button)` - margin-right: 8px; pointer-events: auto; @media print { diff --git a/app/components/HeaderMeta.tsx b/app/components/HeaderMeta.tsx index 68cd6c6484..7adc09fcc3 100644 --- a/app/components/HeaderMeta.tsx +++ b/app/components/HeaderMeta.tsx @@ -1,5 +1,5 @@ import styled, { css } from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import { breakpoint } from "@shared/styles/breakpoint"; import { s } from "@shared/styles"; import Flex from "~/components/Flex"; import NudeButton from "~/components/NudeButton"; diff --git a/app/components/Heading.ts b/app/components/Heading.ts index 940df0a7da..11e388065d 100644 --- a/app/components/Heading.ts +++ b/app/components/Heading.ts @@ -1,13 +1,21 @@ import styled from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import { breakpoint } from "@shared/styles/breakpoint"; +import { IconTitleWrapper } from "@shared/components/Icon"; const Heading = styled.h1<{ as?: string; centered?: boolean }>` display: flex; align-items: center; user-select: none; - ${(props) => (props.as ? "" : "margin-top: 8vh; font-weight: 600;")} + ${(props) => (props.as ? "" : "margin-top: 16px; font-weight: 600;")} ${(props) => (props.centered ? "text-align: center;" : "")} + /* On mobile the title icon sits above the title, so leave room for it. */ + ${breakpoint("mobile", "tablet")` + &:has(> ${IconTitleWrapper}) { + margin-top: 60px; + } + `}; + ${breakpoint("tablet")` ${(props: { as?: string }) => (props.as ? "" : "margin-top: 6vh;")} `}; diff --git a/app/components/ImportDocumentDialog.tsx b/app/components/ImportDocumentDialog.tsx index 440f5378fb..584f62b6b2 100644 --- a/app/components/ImportDocumentDialog.tsx +++ b/app/components/ImportDocumentDialog.tsx @@ -5,7 +5,7 @@ import Dropzone from "react-dropzone"; import { useTranslation } from "react-i18next"; import { toast } from "sonner"; import styled from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import { breakpoint } from "@shared/styles/breakpoint"; import { DropzoneContainer, dropzoneIcon, diff --git a/app/components/Input.tsx b/app/components/Input.tsx index 579ab54dfe..7743daa040 100644 --- a/app/components/Input.tsx +++ b/app/components/Input.tsx @@ -2,7 +2,8 @@ import * as VisuallyHidden from "@radix-ui/react-visually-hidden"; import * as React from "react"; import { mergeRefs } from "react-merge-refs"; import styled from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import { breakpoint } from "@shared/styles/breakpoint"; +import { MOBILE_TOUCH_TARGET } from "@shared/constants"; import { s, ellipsis } from "@shared/styles"; import Flex from "~/components/Flex"; import Text from "~/components/Text"; @@ -75,6 +76,7 @@ export const NativeInput = styled.input<{ ${breakpoint("mobile", "tablet")` font-size: 16px; + height: ${MOBILE_TOUCH_TARGET - 2}px; `}; `; @@ -121,6 +123,11 @@ export const Outline = styled(Flex)<{ : props.theme.inputBorder}; border-radius: ${(props) => (props.$round ? "16px" : "4px")}; font-weight: normal; + + ${breakpoint("mobile", "tablet")` + ${(props: { $round?: boolean }) => + props.$round && `border-radius: ${MOBILE_TOUCH_TARGET / 2}px;`} + `}; align-items: center; overflow: hidden; background: ${s("background")}; diff --git a/app/components/InputSearchPage.tsx b/app/components/InputSearchPage.tsx index d4536df81a..8634ce331b 100644 --- a/app/components/InputSearchPage.tsx +++ b/app/components/InputSearchPage.tsx @@ -4,7 +4,7 @@ import * as React from "react"; import { useTranslation } from "react-i18next"; import { useHistory } from "react-router-dom"; import styled, { useTheme } from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import { breakpoint } from "@shared/styles/breakpoint"; import { s } from "@shared/styles"; import { metaDisplay, shortcutSeparator } from "@shared/utils/keyboard"; import useBoolean from "~/hooks/useBoolean"; @@ -122,6 +122,8 @@ const InputMaxWidth = styled(Input).attrs({ round: true })` /* On mobile the input grows to fill the header, so add a gap before the * adjacent action button (e.g. "New doc"). */ ${breakpoint("mobile", "tablet")` + flex: 1; + min-width: 0; margin-inline-end: 8px; `} `; diff --git a/app/components/Layout.tsx b/app/components/Layout.tsx index ab806c8b31..eb333b8225 100644 --- a/app/components/Layout.tsx +++ b/app/components/Layout.tsx @@ -3,7 +3,7 @@ import { observer } from "mobx-react"; import * as React from "react"; import type { DefaultTheme } from "styled-components"; import styled from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import { breakpoint } from "@shared/styles/breakpoint"; import { s } from "@shared/styles"; import Flex from "~/components/Flex"; import { LoadingIndicatorBar } from "~/components/LoadingIndicator"; diff --git a/app/components/Menu/DropdownMenu.tsx b/app/components/Menu/DropdownMenu.tsx index 130256fd7d..313e1629b0 100644 --- a/app/components/Menu/DropdownMenu.tsx +++ b/app/components/Menu/DropdownMenu.tsx @@ -226,7 +226,7 @@ function MobileDropdown({ onAnimationStart={disablePointerEvents} onAnimationEnd={enablePointerEvents} > - {ariaLabel} + {content} {!submenuName ? append : null} diff --git a/app/components/Modal.tsx b/app/components/Modal.tsx index 5d75f32f34..3d4fcf7ef4 100644 --- a/app/components/Modal.tsx +++ b/app/components/Modal.tsx @@ -4,7 +4,7 @@ import { CloseIcon, BackIcon } from "outline-icons"; import * as React from "react"; import { useTranslation } from "react-i18next"; import styled from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import { breakpoint } from "@shared/styles/breakpoint"; import { depths, s, borderRadius } from "@shared/styles"; import Flex from "~/components/Flex"; import NudeButton from "~/components/NudeButton"; diff --git a/app/components/PinnedDocuments.tsx b/app/components/PinnedDocuments.tsx index 3d77643938..fef27fd480 100644 --- a/app/components/PinnedDocuments.tsx +++ b/app/components/PinnedDocuments.tsx @@ -21,7 +21,7 @@ import { CollapseIcon } from "outline-icons"; import { useState, useRef, useEffect, useCallback } from "react"; import { useTranslation } from "react-i18next"; import styled from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import { breakpoint } from "@shared/styles/breakpoint"; import { s, hover, hideScrollbars } from "@shared/styles"; import type Pin from "~/models/Pin"; import DocumentCard from "~/components/DocumentCard"; diff --git a/app/components/PlaceholderDocument.tsx b/app/components/PlaceholderDocument.tsx index cdc16d90b3..e40d6eef58 100644 --- a/app/components/PlaceholderDocument.tsx +++ b/app/components/PlaceholderDocument.tsx @@ -1,4 +1,5 @@ import styled from "styled-components"; +import { breakpoint } from "@shared/styles/breakpoint"; import DelayedMount from "~/components/DelayedMount"; import Fade from "~/components/Fade"; import Flex from "~/components/Flex"; @@ -54,6 +55,10 @@ export default function PlaceholderDocument({ const Wrapper = styled(Fade)` display: block; - margin: 6vh 0; + margin: 0 0 6vh; padding: 12px 0; + + ${breakpoint("tablet")` + margin-top: 6vh; + `}; `; diff --git a/app/components/Sidebar/Aside.tsx b/app/components/Sidebar/Aside.tsx index 5f825127b2..15cc2e7953 100644 --- a/app/components/Sidebar/Aside.tsx +++ b/app/components/Sidebar/Aside.tsx @@ -3,7 +3,7 @@ import { m } from "framer-motion"; import { observer } from "mobx-react"; import * as React from "react"; import styled, { useTheme } from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import { breakpoint } from "@shared/styles/breakpoint"; import { depths, s } from "@shared/styles"; import ErrorBoundary from "~/components/ErrorBoundary"; import ResizeBorder from "~/components/Sidebar/components/ResizeBorder"; diff --git a/app/components/Sidebar/Sidebar.tsx b/app/components/Sidebar/Sidebar.tsx index 523ef45694..d76497b0f1 100644 --- a/app/components/Sidebar/Sidebar.tsx +++ b/app/components/Sidebar/Sidebar.tsx @@ -3,7 +3,7 @@ import * as React from "react"; import { mergeRefs } from "react-merge-refs"; import { useHistory } from "react-router-dom"; import styled, { useTheme } from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import { breakpoint } from "@shared/styles/breakpoint"; import { depths, s } from "@shared/styles"; import { Avatar } from "~/components/Avatar"; import Flex from "~/components/Flex"; @@ -12,9 +12,10 @@ import useEventListener from "~/hooks/useEventListener"; import useMobile from "~/hooks/useMobile"; import { useResizeHandle } from "~/hooks/useResizeHandle"; import useStores from "~/hooks/useStores"; +import { useSwipeToDismiss } from "~/hooks/useSwipeToDismiss"; import AccountMenu from "~/menus/AccountMenu"; import { fadeOnDesktopBackgrounded } from "~/styles"; -import { fadeIn } from "~/styles/animations"; +import { drawerTransition } from "~/styles/animations"; import Desktop from "~/utils/Desktop"; import NotificationIcon from "../Notifications/NotificationIcon"; import NotificationsPopover from "../Notifications/NotificationsPopover"; @@ -71,6 +72,7 @@ function Sidebar({ const isSmallerThanMinimum = width < minWidth; const hoverTimeoutRef = React.useRef(null); const internalRef = React.useRef(null); + const backdropRef = React.useRef(null); const mergedRef = React.useMemo(() => mergeRefs([internalRef, ref]), [ref]); const measure = React.useCallback( @@ -258,16 +260,17 @@ function Sidebar({ [ui, history] ); + // On mobile the width comes from the viewport, not the resizable desktop width. const style = React.useMemo( - () => ({ - width: `${width}px`, - }), - [width] + () => (isMobile ? undefined : { width: `${width}px` }), + [isMobile, width] ); - const handleCloseSidebar = () => { - ui.toggleMobileSidebar(); - }; + useSwipeToDismiss(internalRef, backdropRef, { + enabled: isMobile && ui.mobileSidebarVisible, + side: direction === "rtl" ? "right" : "left", + onDismiss: ui.hideMobileSidebar, + }); return ( @@ -316,18 +319,24 @@ function Sidebar({ )} - + {!isMobile && ( + + )} - {ui.mobileSidebarVisible && } + ); } -const Backdrop = styled.a` - animation: ${fadeIn} 250ms ease-in-out; +const Backdrop = styled.a<{ $visible: boolean }>` position: fixed; top: 0; left: 0; @@ -336,6 +345,13 @@ const Backdrop = styled.a` cursor: default; z-index: ${depths.mobileSidebar - 1}; background: ${s("backdrop")}; + opacity: ${(props) => (props.$visible ? 1 : 0)}; + pointer-events: ${(props) => (props.$visible ? "auto" : "none")}; + transition: opacity ${drawerTransition}; + + ${breakpoint("tablet")` + display: none; + `}; `; type ContainerProps = { @@ -372,7 +388,7 @@ const Container = styled(Flex)` background: ${s("sidebarBackground")}; transition: box-shadow 150ms ease-in-out, - transform 250ms cubic-bezier(0.34, 1.15, 0.64, 1) + transform ${drawerTransition} ${(props: ContainerProps) => props.$isAnimating ? `, width ${ANIMATION_MS}ms ease-out` : ""}; transform: translateX( @@ -382,8 +398,54 @@ const Container = styled(Flex)` max-width: 80%; min-width: 280px; padding-inline-start: var(--sal); + padding-bottom: var(--sab, 0px); ${fadeOnDesktopBackgrounded()} + ${breakpoint("mobile", "tablet")` + /* Leaves a strip of the page visible to tap and close, as in Material navigation drawers. */ + width: calc(100% - 56px); + max-width: 360px; + min-width: 0; + border-start-end-radius: 8px; + border-end-end-radius: 8px; + /* The negative spread keeps the shadow off the edge side, so a stretch cannot reveal it. */ + box-shadow: ${(props: ContainerProps) => + props.$mobileSidebarVisible + ? "12px 0 24px -12px rgb(0 0 0 / 16%)" + : "none"}; + + [dir="rtl"] & { + box-shadow: ${(props: ContainerProps) => + props.$mobileSidebarVisible + ? "-12px 0 24px -12px rgb(0 0 0 / 16%)" + : "none"}; + } + + @supports (corner-shape: superellipse(2)) { + border-start-end-radius: 14px; + border-end-end-radius: 14px; + corner-shape: superellipse(2); + } + + /* Fills the space behind the edge when the sidebar is stretched past open, + overlapping by a pixel so no seam shows at fractional offsets. */ + &::after { + content: ""; + position: absolute; + top: 0; + bottom: 0; + inset-inline-end: calc(100% - 1px); + width: 100%; + background: inherit; + } + + /* Horizontal gestures drag the sidebar closed, scroll containers inside reset the value. */ + &, + & * { + touch-action: pan-y pinch-zoom; + } + `}; + [dir="rtl"] & { transform: translateX( ${(props) => (props.$mobileSidebarVisible ? 0 : "100%")} diff --git a/app/components/Sidebar/components/HistoryNavigation.tsx b/app/components/Sidebar/components/HistoryNavigation.tsx index ee9af46a63..49a0430489 100644 --- a/app/components/Sidebar/components/HistoryNavigation.tsx +++ b/app/components/Sidebar/components/HistoryNavigation.tsx @@ -92,7 +92,7 @@ function HistoryNavigation(props: React.ComponentProps) { const Navigation = styled(Flex)` position: absolute; inset-inline-end: 12px; - top: 20px; + top: 17px; button { cursor: default; diff --git a/app/components/Sidebar/components/PersonalDocs.tsx b/app/components/Sidebar/components/PersonalDocs.tsx index f16dc84c8b..b6ca43a151 100644 --- a/app/components/Sidebar/components/PersonalDocs.tsx +++ b/app/components/Sidebar/components/PersonalDocs.tsx @@ -8,9 +8,11 @@ import { UserPreference } from "@shared/types"; import { ProsemirrorDataHelper } from "@shared/utils/ProsemirrorDataHelper"; import { DocumentValidation } from "@shared/validations"; import { createAction } from "~/actions"; +import { sortCollection } from "~/actions/definitions/collections"; import { DocumentSection } from "~/actions/sections"; import EditableTitle, { type RefHandle } from "~/components/EditableTitle"; import Flex from "~/components/Flex"; +import { ActionContextProvider } from "~/hooks/useActionContext"; import useBoolean from "~/hooks/useBoolean"; import useCurrentTeam from "~/hooks/useCurrentTeam"; import useCurrentUser from "~/hooks/useCurrentUser"; @@ -59,7 +61,15 @@ export const PersonalDocs = observer(function PersonalDocs() { }), [canCreate, setIsAddingNew] ); - const headerActions = useMemo(() => [newDocAction], [newDocAction]); + const hasCollection = !!collection; + const headerActions = useMemo( + () => (hasCollection ? [newDocAction, sortCollection] : [newDocAction]), + [hasCollection, newDocAction] + ); + const activeModels = useMemo( + () => (collection ? [collection] : undefined), + [collection] + ); const handleNewDoc = useCallback( async (title: string) => { @@ -143,30 +153,32 @@ export const PersonalDocs = observer(function PersonalDocs() { return ( - -
- - {collection ? ( - - {newDocRow} - - ) : ( - newDocRow - )} - - -
-
+ + +
+ + {collection ? ( + + {newDocRow} + + ) : ( + newDocRow + )} + + +
+
+
); }); diff --git a/app/components/Sidebar/components/SidebarButton.tsx b/app/components/Sidebar/components/SidebarButton.tsx index 0e9b4e45a3..11d9fae736 100644 --- a/app/components/Sidebar/components/SidebarButton.tsx +++ b/app/components/Sidebar/components/SidebarButton.tsx @@ -2,7 +2,7 @@ import { MoreIcon } from "outline-icons"; import { observer } from "mobx-react"; import * as React from "react"; import styled from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import { breakpoint } from "@shared/styles/breakpoint"; import { extraArea, hover, s } from "@shared/styles"; import Flex from "~/components/Flex"; import Text from "~/components/Text"; diff --git a/app/components/Sidebar/components/SidebarLink.tsx b/app/components/Sidebar/components/SidebarLink.tsx index 3894a530dc..5a6a19083e 100644 --- a/app/components/Sidebar/components/SidebarLink.tsx +++ b/app/components/Sidebar/components/SidebarLink.tsx @@ -1,7 +1,7 @@ import type { LocationDescriptor } from "history"; import * as React from "react"; import styled, { useTheme, css } from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import { breakpoint } from "@shared/styles/breakpoint"; import { ellipsis, hover, s } from "@shared/styles"; import { isMobile } from "@shared/utils/browser"; import { UnreadBadge } from "~/components/UnreadBadge"; diff --git a/app/components/Switch.tsx b/app/components/Switch.tsx index a1bac9ff45..431bc0cc96 100644 --- a/app/components/Switch.tsx +++ b/app/components/Switch.tsx @@ -2,6 +2,7 @@ import * as RadixSwitch from "@radix-ui/react-switch"; import { darken } from "polished"; import * as React from "react"; import styled from "styled-components"; +import { breakpoint } from "@shared/styles/breakpoint"; import { s } from "@shared/styles"; import { LabelText } from "~/components/Input"; import Text from "~/components/Text"; @@ -67,7 +68,7 @@ function Switch({ className={label ? undefined : className} {...props} > - + ); @@ -128,15 +129,16 @@ const Label = styled.label<{ const HOVER_EXTRA = 3; -const StyledSwitchThumb = styled(RadixSwitch.Thumb)<{ - width: number; - height: number; -}>` +/** Minimum switch size on mobile, so that small switches stay usable by touch. */ +const MOBILE_MIN_WIDTH = 32; +const MOBILE_MIN_HEIGHT = 18; + +const StyledSwitchThumb = styled(RadixSwitch.Thumb)` display: block; - width: ${(props) => props.height - 8}px; - height: ${(props) => props.height - 8}px; + width: calc(var(--switch-height) - 8px); + height: calc(var(--switch-height) - 8px); background-color: white; - border-radius: ${(props) => (props.height - 8) / 2}px; + border-radius: calc((var(--switch-height) - 8px) / 2); transition: transform 0.2s, width 0.2s; @@ -144,11 +146,11 @@ const StyledSwitchThumb = styled(RadixSwitch.Thumb)<{ will-change: transform, width; &[data-state="checked"] { - transform: translateX(${(props) => props.width - props.height}px); + transform: translateX(calc(var(--switch-width) - var(--switch-height))); } [dir="rtl"] &[data-state="checked"] { - transform: translateX(${(props) => -(props.width - props.height)}px); + transform: translateX(calc(var(--switch-height) - var(--switch-width))); } `; @@ -156,17 +158,25 @@ const StyledSwitchRoot = styled(RadixSwitch.Root)<{ width: number; height: number; }>` + --switch-width: ${(props) => Math.max(props.width, MOBILE_MIN_WIDTH)}px; + --switch-height: ${(props) => Math.max(props.height, MOBILE_MIN_HEIGHT)}px; + position: relative; - width: ${(props) => props.width}px; - height: ${(props) => props.height}px; + width: var(--switch-width); + height: var(--switch-height); background-color: ${(props) => props.theme.slate}; - border-radius: ${(props) => props.height}px; + border-radius: var(--switch-height); border: none; cursor: var(--pointer); transition: background-color 0.2s; padding: 0 4px; flex-shrink: 0; + ${(props) => breakpoint("tablet")` + --switch-width: ${props.width}px; + --switch-height: ${props.height}px; + `} + &:focus { box-shadow: 0 0 1px ${s("accent")}; outline: none; @@ -190,12 +200,12 @@ const StyledSwitchRoot = styled(RadixSwitch.Root)<{ } &:hover:not(:disabled) ${StyledSwitchThumb} { - width: ${(props) => props.height - 8 + HOVER_EXTRA}px; + width: calc(var(--switch-height) - 8px + ${HOVER_EXTRA}px); } &:hover:not(:disabled)[data-state="checked"] ${StyledSwitchThumb} { transform: translateX( - ${(props) => props.width - props.height - HOVER_EXTRA}px + calc(var(--switch-width) - var(--switch-height) - ${HOVER_EXTRA}px) ); } @@ -203,7 +213,7 @@ const StyledSwitchRoot = styled(RadixSwitch.Root)<{ &:hover:not(:disabled)[data-state="checked"] ${StyledSwitchThumb} { transform: translateX( - ${(props) => -(props.width - props.height - HOVER_EXTRA)}px + calc(var(--switch-height) - var(--switch-width) + ${HOVER_EXTRA}px) ); } `; diff --git a/app/components/Table.tsx b/app/components/Table.tsx index 0ede787e92..d02f89d636 100644 --- a/app/components/Table.tsx +++ b/app/components/Table.tsx @@ -19,6 +19,8 @@ import * as React from "react"; import { useTranslation } from "react-i18next"; import { Waypoint } from "react-waypoint"; import styled from "styled-components"; +import { breakpoint } from "@shared/styles/breakpoint"; +import { HEADER_HEIGHT as APP_HEADER_HEIGHT } from "@shared/constants"; import { s } from "@shared/styles"; import DelayedMount from "~/components/DelayedMount"; import Empty from "~/components/Empty"; @@ -717,6 +719,11 @@ const THead = styled.div<{ $topPos: number }>` border-bottom: 1px solid ${(props) => transparentize(0.3, props.theme.divider)}; background: ${s("background")}; + + ${breakpoint("mobile", "tablet")` + top: ${({ $topPos }: { $topPos: number }) => + `${Math.min($topPos, APP_HEADER_HEIGHT)}px`}; + `}; `; const TBody = styled.div<{ $height: number }>` diff --git a/app/components/Tabs/Tab.tsx b/app/components/Tabs/Tab.tsx index ac69ac36bf..d9ee50fd2c 100644 --- a/app/components/Tabs/Tab.tsx +++ b/app/components/Tabs/Tab.tsx @@ -5,7 +5,8 @@ import { isEqual } from "es-toolkit/compat"; import queryString from "query-string"; import * as React from "react"; import styled, { css, useTheme } from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import { breakpoint } from "@shared/styles/breakpoint"; +import { MOBILE_TOUCH_TARGET } from "@shared/constants"; import { s, hover } from "@shared/styles"; import NavLink from "~/components/NavLink"; @@ -60,9 +61,11 @@ const tabStyles = css` cursor: var(--pointer); user-select: none; padding: 12px 0; + min-height: ${MOBILE_TOUCH_TARGET}px; ${breakpoint("tablet")` padding: 6px 0; + min-height: 0; `}; `; diff --git a/app/components/Tabs/Tabs.tsx b/app/components/Tabs/Tabs.tsx index 8175761e38..5b16d26d3a 100644 --- a/app/components/Tabs/Tabs.tsx +++ b/app/components/Tabs/Tabs.tsx @@ -44,9 +44,12 @@ const Nav = styled.nav<{ $shadowVisible?: boolean }>` // When sticky we need extra background coverage around the sides otherwise // items that scroll past can "stick out" the sides of the heading +/** Offset from the top of the viewport at which the tab bar sticks. */ +const StickyTop = 54; + const Sticky = styled.div` position: sticky; - top: 54px; + top: ${StickyTop}px; margin: 0 -8px; padding: 0 8px; background: ${s("background")}; @@ -76,6 +79,7 @@ export const TabsGroup: React.FC = ({ children }: Props) => { export const Tabs: React.FC = ({ children }: Props) => { const ref = React.useRef(null); + const stickyRef = React.useRef(null); const [shadowVisible, setShadow] = React.useState(false); const { width } = useWindowSize(); @@ -97,9 +101,29 @@ export const Tabs: React.FC = ({ children }: Props) => { updateShadows(); }, [width, updateShadows]); + // Mark the tab bar while it is stuck so the header above can style itself to match. + React.useEffect(() => { + const sticky = stickyRef.current; + if (!sticky) { + return; + } + const observer = new IntersectionObserver( + ([entry]) => { + sticky.toggleAttribute( + "data-stuck", + entry.intersectionRatio < 1 && + entry.boundingClientRect.top <= StickyTop + 1 + ); + }, + { threshold: 1, rootMargin: `-${StickyTop + 1}px 0px 0px 0px` } + ); + observer.observe(sticky); + return () => observer.disconnect(); + }, []); + return ( - + diff --git a/app/components/primitives/Drawer.tsx b/app/components/primitives/Drawer.tsx index f1eda8be44..073e23a92c 100644 --- a/app/components/primitives/Drawer.tsx +++ b/app/components/primitives/Drawer.tsx @@ -108,7 +108,9 @@ const StyledContent = styled(m.div)` const StyledInnerContent = styled(Flex)` padding: 6px; - padding-bottom: calc(6px + var(--sab, 0px)); + + /* The safe area inset is zero unless the viewport uses viewport-fit=cover. */ + padding-bottom: max(24px, calc(6px + var(--sab, 0px))); height: 100%; `; diff --git a/app/components/primitives/components/InputSelect.tsx b/app/components/primitives/components/InputSelect.tsx index 5655e5c8cc..31a698dfc3 100644 --- a/app/components/primitives/components/InputSelect.tsx +++ b/app/components/primitives/components/InputSelect.tsx @@ -4,7 +4,7 @@ import { CheckmarkIcon } from "outline-icons"; import styled, { css } from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import { breakpoint } from "@shared/styles/breakpoint"; import { s } from "@shared/styles"; import Button, { Inner } from "~/components/Button"; import Flex from "~/components/Flex"; diff --git a/app/components/primitives/components/Menu.tsx b/app/components/primitives/components/Menu.tsx index 4f8167e9d8..045912f46f 100644 --- a/app/components/primitives/components/Menu.tsx +++ b/app/components/primitives/components/Menu.tsx @@ -2,7 +2,7 @@ import { ExpandedIcon } from "outline-icons"; import { ellipsis } from "polished"; import { Link } from "react-router-dom"; import styled, { css } from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import { breakpoint } from "@shared/styles/breakpoint"; import { depths, s, borderRadius } from "@shared/styles"; import Scrollable from "~/components/Scrollable"; import { fadeAndScaleIn } from "~/styles/animations"; diff --git a/app/editor/components/NoticeIcon.tsx b/app/editor/components/NoticeIcon.tsx new file mode 100644 index 0000000000..a7027df84d --- /dev/null +++ b/app/editor/components/NoticeIcon.tsx @@ -0,0 +1,44 @@ +import { DoneIcon, InfoIcon, StarredIcon, WarningIcon } from "outline-icons"; +import styled from "styled-components"; +import { NoticeTypes } from "@shared/editor/nodes/Notice"; +import { s } from "@shared/styles"; + +interface Props { + /** The style of the notice. */ + type: NoticeTypes; +} + +/** + * Renders the icon for a notice style, colored to match the notice in the editor. + * + * @param props the component props. + * @returns the icon element. + */ +export function NoticeIcon({ type }: Props) { + switch (type) { + case NoticeTypes.Success: + return ; + case NoticeTypes.Warning: + return ; + case NoticeTypes.Tip: + return ; + default: + return ; + } +} + +const NoticeInfoIcon = styled(InfoIcon)` + color: ${s("noticeInfoText")}; +`; + +const SuccessIcon = styled(DoneIcon)` + color: ${s("noticeSuccessText")}; +`; + +const NoticeWarningIcon = styled(WarningIcon)` + color: ${s("noticeWarningText")}; +`; + +const TipIcon = styled(StarredIcon)` + color: ${s("noticeTipText")}; +`; diff --git a/app/editor/components/ToolbarMenu.tsx b/app/editor/components/ToolbarMenu.tsx index 1c0bcda744..9c1c5e2a56 100644 --- a/app/editor/components/ToolbarMenu.tsx +++ b/app/editor/components/ToolbarMenu.tsx @@ -1,6 +1,6 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import styled from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import { breakpoint } from "@shared/styles/breakpoint"; import * as Toolbar from "@radix-ui/react-toolbar"; import { closeHistory } from "@shared/editor/lib/closeHistory"; import { MenuItemGroup, type MenuItem } from "@shared/editor/types"; diff --git a/app/editor/menus/block.tsx b/app/editor/menus/block.tsx index 7d4fa7e648..55d4404f40 100644 --- a/app/editor/menus/block.tsx +++ b/app/editor/menus/block.tsx @@ -13,13 +13,9 @@ import { TableIcon, TodoListIcon, ImageIcon, - StarredIcon, - WarningIcon, - InfoIcon, AttachmentIcon, CalendarIcon, MathIcon, - DoneIcon, EmbedIcon, CollapseIcon, } from "outline-icons"; @@ -28,10 +24,12 @@ import styled from "styled-components"; import { v4 as uuidv4 } from "uuid"; import type { TFunction } from "i18next"; import Image from "@shared/editor/components/Img"; +import { NoticeTypes } from "@shared/editor/nodes/Notice"; import type { MenuItem } from "@shared/editor/types"; import { MentionType } from "@shared/types"; import { toISODate } from "@shared/utils/date"; import { metaDisplay } from "@shared/utils/keyboard"; +import { NoticeIcon } from "~/editor/components/NoticeIcon"; import Desktop from "~/utils/Desktop"; const Img = styled(Image)` @@ -243,30 +241,30 @@ export default function blockMenuItems( { name: "container_notice", title: t("Info notice"), - icon: , + icon: , keywords: "card callout hint information note", - attrs: { style: "info" }, + attrs: { style: NoticeTypes.Info }, }, { name: "container_notice", title: t("Success notice"), - icon: , + icon: , keywords: "card callout hint", - attrs: { style: "success" }, + attrs: { style: NoticeTypes.Success }, }, { name: "container_notice", title: t("Warning notice"), - icon: , + icon: , keywords: "card callout hint error caution danger alert", - attrs: { style: "warning" }, + attrs: { style: NoticeTypes.Warning }, }, { name: "container_notice", title: t("Tip notice"), - icon: , + icon: , keywords: "card callout hint suggestion", - attrs: { style: "tip" }, + attrs: { style: NoticeTypes.Tip }, }, { name: "separator", diff --git a/app/editor/menus/notice.tsx b/app/editor/menus/notice.tsx index 549e0682cc..96b78ae3f4 100644 --- a/app/editor/menus/notice.tsx +++ b/app/editor/menus/notice.tsx @@ -1,14 +1,9 @@ import { t } from "i18next"; -import { - DoneIcon, - ExpandedIcon, - InfoIcon, - StarredIcon, - WarningIcon, -} from "outline-icons"; +import { ExpandedIcon } from "outline-icons"; import { NoticeTypes } from "@shared/editor/nodes/Notice"; import { findParentNode } from "@shared/editor/queries/findParentNode"; import type { MenuItem, SelectionContext } from "@shared/editor/types"; +import { NoticeIcon } from "~/editor/components/NoticeIcon"; /** * Returns menu items for the notice/callout selection toolbar. @@ -39,25 +34,25 @@ export default function noticeMenuItems(ctx: SelectionContext): MenuItem[] { children: [ { name: NoticeTypes.Info, - icon: , + icon: , label: t("Info notice"), active: () => currentStyle === NoticeTypes.Info, }, { name: NoticeTypes.Success, - icon: , + icon: , label: t("Success notice"), active: () => currentStyle === NoticeTypes.Success, }, { name: NoticeTypes.Warning, - icon: , + icon: , label: t("Warning notice"), active: () => currentStyle === NoticeTypes.Warning, }, { name: NoticeTypes.Tip, - icon: , + icon: , label: t("Tip notice"), active: () => currentStyle === NoticeTypes.Tip, }, diff --git a/app/editor/menus/table.tsx b/app/editor/menus/table.tsx index 8592d6c319..628b8730b7 100644 --- a/app/editor/menus/table.tsx +++ b/app/editor/menus/table.tsx @@ -31,6 +31,7 @@ export default function tableMenuItems(ctx: SelectionContext): MenuItem[] { label: isFullWidth ? t("Default width") : t("Full width"), icon: , attrs: isFullWidth ? { layout: null } : { layout: TableLayout.fullWidth }, + visible: !ctx.isInNotice, }, { name: "distributeColumns", diff --git a/app/editor/plugins/DragTarget.test.ts b/app/editor/plugins/DragTarget.test.ts index b0506b5309..64619d2b41 100644 --- a/app/editor/plugins/DragTarget.test.ts +++ b/app/editor/plugins/DragTarget.test.ts @@ -90,4 +90,18 @@ describe("DragTarget#hasOwnControls", () => { const paragraph = new DragTarget(0, document.createElement("div"), "block"); expect(paragraph.hasOwnControls(state)).toBe(false); }); + + it("returns true for an empty paragraph that holds the selection", () => { + const emptyDoc = doc([p("one"), p("")]); + const state = createEditorStateWithSelection(emptyDoc, 6); + const paragraph = new DragTarget(5, document.createElement("div"), "block"); + expect(paragraph.hasOwnControls(state)).toBe(true); + }); + + it("returns false for an empty paragraph without the selection", () => { + const emptyDoc = doc([p("one"), p("")]); + const state = createEditorStateWithSelection(emptyDoc, 2); + const paragraph = new DragTarget(5, document.createElement("div"), "block"); + expect(paragraph.hasOwnControls(state)).toBe(false); + }); }); diff --git a/app/editor/plugins/DragTarget.ts b/app/editor/plugins/DragTarget.ts index 68a9f61a6b..9ba2e6d499 100644 --- a/app/editor/plugins/DragTarget.ts +++ b/app/editor/plugins/DragTarget.ts @@ -200,18 +200,28 @@ export class DragTarget { /** * Whether the editor shows its own controls for this block, which would - * overlap the drag handle, e.g. a table that holds the selection. + * overlap the drag handle, e.g. a table that holds the selection or an + * empty paragraph that shows the block menu trigger. * * @param state - the editor state. * @returns true if the drag handle should be hidden for this block. */ public hasOwnControls(state: EditorState): boolean { const node = state.doc.nodeAt(this.pos); - if (node?.type.name !== "table") { - return false; + const { $from, from, to } = state.selection; + + switch (node?.type.name) { + case "table": + return from > this.pos && to < this.pos + node.nodeSize; + case "paragraph": + return ( + node.content.size === 0 && + $from.depth === 1 && + $from.before() === this.pos + ); + default: + return false; } - const { from, to } = state.selection; - return from > this.pos && to < this.pos + node.nodeSize; } /** diff --git a/app/hooks/useSwipeToDismiss.ts b/app/hooks/useSwipeToDismiss.ts new file mode 100644 index 0000000000..be49b7cc50 --- /dev/null +++ b/app/hooks/useSwipeToDismiss.ts @@ -0,0 +1,175 @@ +import { useEffect } from "react"; +import type { RefObject } from "react"; + +interface Options { + /** Whether the panel is open and can be swiped away. */ + enabled: boolean; + /** The screen edge that the panel is attached to. */ + side: "left" | "right"; + /** Called when a swipe passes the dismiss threshold. */ + onDismiss: () => void; +} + +/** Distance in pixels a pointer must move before the gesture is a drag or a scroll. */ +const DragSlop = 8; + +/** Release speed in px/ms above which the panel is dismissed, matches vaul. */ +const VelocityThreshold = 0.4; + +/** Fraction of the panel width past which the panel is dismissed, matches vaul. */ +const CloseThreshold = 0.25; + +/** Rubber band resistance for a drag away from the edge, matches vaul. */ +const dampen = (value: number) => Math.max(8 * (Math.log(value + 1) - 2), 0); + +/** + * Lets the user drag an edge-attached panel toward its edge to dismiss it, with + * the same thresholds as the vaul drawer. The panel follows the pointer, and on + * release it either dismisses or springs back using the CSS transition of the + * panel. A vertical gesture is left to the browser so that the panel can scroll. + * + * @param panelRef ref to the panel element that moves. + * @param overlayRef ref to an optional backdrop that fades as the panel moves. + * @param options the swipe options. + */ +export function useSwipeToDismiss( + panelRef: RefObject, + overlayRef: RefObject, + { enabled, side, onDismiss }: Options +) { + useEffect(() => { + const panel = panelRef.current; + if (!enabled || !panel) { + return; + } + const overlay = overlayRef.current; + const sign = side === "left" ? -1 : 1; + + let start: { x: number; y: number; time: number } | null = null; + let isDragging = false; + let width = 0; + let distance = 0; + + const setStyles = ( + transition: string, + transform: string, + opacity: string + ) => { + panel.style.transition = transition; + panel.style.transform = transform; + if (overlay) { + overlay.style.transition = transition; + overlay.style.opacity = opacity; + } + }; + + const suppressClick = (event: MouseEvent) => { + event.preventDefault(); + event.stopPropagation(); + }; + + const handlePointerDown = (event: PointerEvent) => { + if (!event.isPrimary || event.button !== 0) { + return; + } + start = { x: event.clientX, y: event.clientY, time: event.timeStamp }; + isDragging = false; + distance = 0; + }; + + const handlePointerMove = (event: PointerEvent) => { + if (!start || !event.isPrimary) { + return; + } + const dx = event.clientX - start.x; + const dy = event.clientY - start.y; + + if (!isDragging) { + if (Math.abs(dx) < DragSlop && Math.abs(dy) < DragSlop) { + return; + } + + // A mostly vertical gesture is a scroll, so leave it to the browser. + if (Math.abs(dy) >= Math.abs(dx)) { + start = null; + return; + } + isDragging = true; + width = panel.getBoundingClientRect().width; + panel.setPointerCapture(event.pointerId); + } + + // A drag away from the edge stretches with resistance. Whole pixels + // stop a visible line where the panel meets its fill. + const dragged = dx * sign; + distance = Math.round( + dragged >= 0 ? Math.min(dragged, width) : -dampen(-dragged) + ); + setStyles( + "none", + `translateX(${distance * sign}px)`, + String(1 - Math.max(distance, 0) / width) + ); + }; + + const handlePointerUp = (event: PointerEvent) => { + if (!event.isPrimary) { + return; + } + if (!start || !isDragging) { + start = null; + return; + } + const velocity = + Math.abs(event.clientX - start.x) / + Math.max(event.timeStamp - start.time, 1); + start = null; + isDragging = false; + + // The pointer moved, so the click that follows is not a tap. + panel.addEventListener("click", suppressClick, { + capture: true, + once: true, + }); + setTimeout(() => { + panel.removeEventListener("click", suppressClick, { capture: true }); + }, 0); + + if ( + distance > 0 && + (velocity > VelocityThreshold || distance >= width * CloseThreshold) + ) { + // Hold the closed position until the closed styles apply, then the + // cleanup below removes the inline styles. + setStyles("", `translateX(${sign * 100}%)`, "0"); + onDismiss(); + return; + } + setStyles("", "", ""); + }; + + const handlePointerCancel = (event: PointerEvent) => { + if (!event.isPrimary) { + return; + } + if (isDragging) { + setStyles("", "", ""); + } + start = null; + isDragging = false; + }; + + panel.addEventListener("pointerdown", handlePointerDown); + panel.addEventListener("pointermove", handlePointerMove); + panel.addEventListener("pointerup", handlePointerUp); + panel.addEventListener("pointercancel", handlePointerCancel); + + return () => { + panel.removeEventListener("pointerdown", handlePointerDown); + panel.removeEventListener("pointermove", handlePointerMove); + panel.removeEventListener("pointerup", handlePointerUp); + panel.removeEventListener("pointercancel", handlePointerCancel); + setStyles("", "", ""); + }; + }, [panelRef, overlayRef, enabled, side, onDismiss]); +} diff --git a/app/menus/DocumentMenu.tsx b/app/menus/DocumentMenu.tsx index 6e676955ce..22010c351e 100644 --- a/app/menus/DocumentMenu.tsx +++ b/app/menus/DocumentMenu.tsx @@ -3,7 +3,7 @@ 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 { breakpoint } from "@shared/styles/breakpoint"; import { s } from "@shared/styles"; import { SubscriptionType, UserPreference } from "@shared/types"; import type Document from "~/models/Document"; diff --git a/app/menus/TableOfContentsMenu.tsx b/app/menus/TableOfContentsMenu.tsx index 74cee2f55a..e400eba13c 100644 --- a/app/menus/TableOfContentsMenu.tsx +++ b/app/menus/TableOfContentsMenu.tsx @@ -98,7 +98,11 @@ function TableOfContentsMenu() { const rootAction = useMenuAction(actions); return ( - + )} + {isMobile && ( + + + + )} - ) : null - ) : hasSidebar ? ( + isMobile ? null : hasSidebar ? ( + {hasHeadings && isMobile && ( + + + + )} {hasHeadings && !isMobile && !tocInLeft && {toc}} {allowSubscriptions !== false && env.EMAIL_ENABLED && ( diff --git a/app/scenes/Document/components/SizeWarning.tsx b/app/scenes/Document/components/SizeWarning.tsx index f11c5bf777..019f4e15c4 100644 --- a/app/scenes/Document/components/SizeWarning.tsx +++ b/app/scenes/Document/components/SizeWarning.tsx @@ -1,7 +1,7 @@ import { WarningIcon } from "outline-icons"; import { useTranslation } from "react-i18next"; import styled from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import { breakpoint } from "@shared/styles/breakpoint"; import { DocumentValidation } from "@shared/validations"; import type Document from "~/models/Document"; import Fade from "~/components/Fade"; diff --git a/app/scenes/Document/hooks/useDocumentSave.ts b/app/scenes/Document/hooks/useDocumentSave.ts index ce5908bd28..a341a3ae2c 100644 --- a/app/scenes/Document/hooks/useDocumentSave.ts +++ b/app/scenes/Document/hooks/useDocumentSave.ts @@ -338,35 +338,49 @@ export function useDocumentSave({ }, [readOnly, updateIsDirty]); // Auto-delete/auto-save on unmount + debounce cleanup - useEffect( - () => () => { + const isMountedRef = useRef(false); + useEffect(() => { + isMountedRef.current = true; + + return () => { + isMountedRef.current = false; autosave.cancel(); + + // Read the editor now, as it may be destroyed by the time the check runs. + // oxlint-disable-next-line react-hooks/exhaustive-deps const currentDoc = editorRef.current?.view.state.doc; const isEditorEmpty = !currentDoc || ProsemirrorHelper.isEmpty(currentDoc); + const currentTitle = titleRef.current; - if ( - shouldAutoDeleteDraftOnUnmount({ - isEditorEmpty, - title: titleRef.current, - createdById: document.createdBy?.id, - currentUserId: auth.user?.id, - isDraft: document.isDraft, - isActive: document.isActive, - hasEmptyTitle: document.hasEmptyTitle, - isPersistedOnce: document.isPersistedOnce, - }) - ) { - void document.delete(); - } else if (document.isDirty()) { - void document.save(undefined, { - autosave: true, - }); - } - }, + // Defer the check so that a StrictMode remount does not count as an unmount. + queueMicrotask(() => { + if (isMountedRef.current) { + return; + } + + if ( + shouldAutoDeleteDraftOnUnmount({ + isEditorEmpty, + title: currentTitle, + createdById: document.createdBy?.id, + currentUserId: auth.user?.id, + isDraft: document.isDraft, + isActive: document.isActive, + hasEmptyTitle: document.hasEmptyTitle, + isPersistedOnce: document.isPersistedOnce, + }) + ) { + void document.delete(); + } else if (document.isDirty()) { + void document.save(undefined, { + autosave: true, + }); + } + }); + }; // oxlint-disable-next-line react-hooks/exhaustive-deps - [] - ); + }, []); return { isUploading, diff --git a/app/scenes/Login/components/PasskeyAuthenticationProvider.tsx b/app/scenes/Login/components/PasskeyAuthenticationProvider.tsx index 9ee340ea2e..7b4c035cf6 100644 --- a/app/scenes/Login/components/PasskeyAuthenticationProvider.tsx +++ b/app/scenes/Login/components/PasskeyAuthenticationProvider.tsx @@ -7,6 +7,7 @@ import { CSRF } from "@shared/constants"; import { Client } from "@shared/types"; import { errToString } from "@shared/utils/error"; import ButtonLarge from "~/components/ButtonLarge"; +import ButtonLink from "~/components/ButtonLink"; import PluginIcon from "~/components/PluginIcon"; import useQuery from "~/hooks/useQuery"; import { client } from "~/utils/ApiClient"; @@ -51,9 +52,11 @@ function flattenFormFields( * Renders the "Continue with Passkey" login option and runs the WebAuthn * authentication ceremony. * - * In the desktop app the ceremony cannot run inside Electron's Chromium, so the - * flow is opened in the system browser and the resulting session is returned to - * the app via the outline:// deep link, mirroring the SSO desktop flow. + * In the desktop app the ceremony runs inside the app when it supports a + * platform authenticator. Otherwise, or if the user chooses a passkey that is + * not stored in the app, the flow is opened in the system browser and the + * resulting session is returned to the app via the outline:// deep link, + * mirroring the SSO desktop flow. */ export function PasskeyAuthenticationProvider(props: Props) { const { t } = useTranslation(); @@ -65,6 +68,13 @@ export function PasskeyAuthenticationProvider(props: Props) { ); const [isAuthenticating, setIsAuthenticating] = React.useState(false); const [hasError, setHasError] = React.useState(false); + const [isSupportedInApp, setIsSupportedInApp] = React.useState(false); + + React.useEffect(() => { + if (Desktop.isElectron()) { + void Desktop.isPasskeySupported().then(setIsSupportedInApp); + } + }, []); // True when this page was opened in the system browser from the desktop app // to complete a passkey login (see the /auth/passkey route). In that case the @@ -128,14 +138,19 @@ export function PasskeyAuthenticationProvider(props: Props) { } }, [isDesktopRedirect, runAuthentication]); + // Opens the flow in the system browser, which returns to the app via the + // outline:// deep link like SSO login. + const openInBrowser = () => { + window.location.href = `/auth/passkey?client=${Client.Desktop}`; + }; + const handleSubmit = (event: React.SyntheticEvent) => { event.preventDefault(); - // The WebAuthn ceremony cannot run inside Electron's Chromium as it lacks - // platform authenticator support. Open the flow in the system browser, - // which returns to the app via the outline:// deep link like SSO login. - if (Desktop.isElectron()) { - window.location.href = `/auth/passkey?client=${Client.Desktop}`; + // Older desktop apps and devices without a platform authenticator cannot + // run the WebAuthn ceremony inside the app. + if (Desktop.isElectron() && !isSupportedInApp) { + openInBrowser(); return; } @@ -172,6 +187,11 @@ export function PasskeyAuthenticationProvider(props: Props) { )} + {isSupportedInApp && hasError && ( + + {t("Use a passkey from your browser")} + + )} ); } @@ -180,6 +200,12 @@ const Wrapper = styled.div` width: 100%; `; +const Fallback = styled(ButtonLink)` + display: block; + margin: 12px auto 0; + font-size: 14px; +`; + const Form = styled.form` width: 100%; display: flex; diff --git a/app/scenes/Search/Search.tsx b/app/scenes/Search/Search.tsx index 6f91173b14..1d48c90693 100644 --- a/app/scenes/Search/Search.tsx +++ b/app/scenes/Search/Search.tsx @@ -6,7 +6,7 @@ import { useTranslation } from "react-i18next"; import { useHistory, useLocation, useRouteMatch } from "react-router-dom"; import { Waypoint } from "react-waypoint"; import styled from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import { breakpoint } from "@shared/styles/breakpoint"; import { Pagination } from "@shared/constants"; import type { Filter } from "@shared/helpers/FilterHelper"; import { DURATION_BY_DATE_FILTER } from "@shared/helpers/FilterHelper"; diff --git a/app/scenes/Settings/Notifications.tsx b/app/scenes/Settings/Notifications.tsx index 0ffabbe29f..b55b658207 100644 --- a/app/scenes/Settings/Notifications.tsx +++ b/app/scenes/Settings/Notifications.tsx @@ -36,7 +36,7 @@ function Notifications() { const options = [ { - event: NotificationEventType.PublishDocument, + events: [NotificationEventType.PublishDocument], icon: , title: t("Document published"), description: t( @@ -44,7 +44,7 @@ function Notifications() { ), }, { - event: NotificationEventType.UpdateDocument, + events: [NotificationEventType.UpdateDocument], icon: , title: t("Document updated"), description: t( @@ -52,7 +52,7 @@ function Notifications() { ), }, { - event: NotificationEventType.CreateComment, + events: [NotificationEventType.CreateComment], icon: , title: t("Comment posted"), description: t( @@ -60,7 +60,10 @@ function Notifications() { ), }, { - event: NotificationEventType.MentionedInComment, + events: [ + NotificationEventType.MentionedInComment, + NotificationEventType.MentionedInDocument, + ], icon: , title: t("Mentioned"), description: t( @@ -68,7 +71,10 @@ function Notifications() { ), }, { - event: NotificationEventType.GroupMentionedInDocument, + events: [ + NotificationEventType.GroupMentionedInDocument, + NotificationEventType.GroupMentionedInComment, + ], icon: , title: t("Group mentions"), description: t( @@ -76,7 +82,7 @@ function Notifications() { ), }, { - event: NotificationEventType.ResolveComment, + events: [NotificationEventType.ResolveComment], icon: , title: t("Resolved"), description: t( @@ -84,7 +90,7 @@ function Notifications() { ), }, { - event: NotificationEventType.ReactionsCreate, + events: [NotificationEventType.ReactionsCreate], icon: , title: t("Reaction added"), description: t( @@ -92,7 +98,7 @@ function Notifications() { ), }, { - event: NotificationEventType.CreateCollection, + events: [NotificationEventType.CreateCollection], icon: , title: t("Collection created"), description: t( @@ -100,7 +106,7 @@ function Notifications() { ), }, { - event: NotificationEventType.InviteAccepted, + events: [NotificationEventType.InviteAccepted], icon: , title: t("Invite accepted"), description: t( @@ -108,7 +114,7 @@ function Notifications() { ), }, { - event: NotificationEventType.AddUserToDocument, + events: [NotificationEventType.AddUserToDocument], icon: , title: t("Invited to document"), description: t( @@ -116,7 +122,7 @@ function Notifications() { ), }, { - event: NotificationEventType.AddUserToCollection, + events: [NotificationEventType.AddUserToCollection], icon: , title: t("Invited to collection"), description: t( @@ -124,7 +130,7 @@ function Notifications() { ), }, { - event: NotificationEventType.AddUserToGroup, + events: [NotificationEventType.AddUserToGroup], icon: , title: t("Group membership"), description: t( @@ -132,7 +138,7 @@ function Notifications() { ), }, { - event: NotificationEventType.ExportCompleted, + events: [NotificationEventType.ExportCompleted], icon: , title: t("Export completed"), description: t( @@ -140,7 +146,7 @@ function Notifications() { ), }, { - event: NotificationEventType.RequestDocumentAccess, + events: [NotificationEventType.RequestDocumentAccess], icon: , title: t("Document access requested"), description: t( @@ -150,14 +156,14 @@ function Notifications() { { visible: isCloudHosted, icon: , - event: NotificationEventType.Onboarding, + events: [NotificationEventType.Onboarding], title: t("Getting started"), description: t("Tips on getting started with features and functionality"), }, { visible: isCloudHosted, icon: , - event: NotificationEventType.Features, + events: [NotificationEventType.Features], title: t("New features"), description: t("Receive an email when new features of note are added"), }, @@ -170,8 +176,11 @@ function Notifications() { }, 500); const handleChange = React.useCallback( - (eventType: NotificationEventType) => async (checked: boolean) => { - await user.setNotificationEventType(eventType, checked); + (eventTypes: NotificationEventType[]) => async (checked: boolean) => { + // Sequential, as each request saves the full settings object. + for (const eventType of eventTypes) { + await user.setNotificationEventType(eventType, checked); + } showSuccessMessage(); }, [user, showSuccessMessage] @@ -182,7 +191,9 @@ function Notifications() { runInAction(() => { const updated = { ...user.notificationSettings }; for (const option of visibleOptions) { - updated[option.event] = checked; + for (const eventType of option.events) { + updated[eventType] = checked; + } } user.notificationSettings = updated; }); @@ -197,7 +208,7 @@ function Notifications() { ); const allEnabled = visibleOptions.every((o) => - user.subscribedToEventType(o.event) + o.events.every((eventType) => user.subscribedToEventType(eventType)) ); const showSuccessNotice = window.location.search === "?success"; @@ -231,14 +242,17 @@ function Notifications() { {options.map((option) => { - const setting = user.subscribedToEventType(option.event); + const [name] = option.events; + const checked = option.events.every((eventType) => + user.subscribedToEventType(eventType) + ); return ( {option.description} @@ -247,11 +261,11 @@ function Notifications() { compact > ); diff --git a/app/scenes/Settings/Users.tsx b/app/scenes/Settings/Users.tsx index 2d9aa06d3b..a2dc952f70 100644 --- a/app/scenes/Settings/Users.tsx +++ b/app/scenes/Settings/Users.tsx @@ -7,6 +7,7 @@ import { Trans, useTranslation } from "react-i18next"; import { useHistory, useLocation } from "react-router-dom"; import { toast } from "sonner"; import styled from "styled-components"; +import { breakpoint } from "@shared/styles/breakpoint"; import type { Filter } from "@shared/helpers/FilterHelper"; import type UsersStore from "~/stores/UsersStore"; import { queriedUsers } from "~/stores/UsersStore"; @@ -155,7 +156,7 @@ function Users() { - + - + @@ -268,6 +269,12 @@ function getFilteredUsers({ return filteredUsers; } +const FilterGroup = styled(HStack)` + ${breakpoint("mobile", "tablet")` + display: contents; + `}; +`; + const LargeUserStatusFilter = styled(UserStatusFilter)` height: 32px; `; diff --git a/app/scenes/Settings/components/ActionRow.tsx b/app/scenes/Settings/components/ActionRow.tsx index 00a90dc3bf..ddc4cf1560 100644 --- a/app/scenes/Settings/components/ActionRow.tsx +++ b/app/scenes/Settings/components/ActionRow.tsx @@ -1,6 +1,6 @@ import { transparentize } from "polished"; import styled from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import { breakpoint } from "@shared/styles/breakpoint"; import { s } from "@shared/styles"; import { HStack } from "~/components/primitives/HStack"; diff --git a/app/scenes/Settings/components/SettingRow.tsx b/app/scenes/Settings/components/SettingRow.tsx index 9d4de82789..bdb3921027 100644 --- a/app/scenes/Settings/components/SettingRow.tsx +++ b/app/scenes/Settings/components/SettingRow.tsx @@ -1,7 +1,7 @@ import { transparentize } from "polished"; import * as React from "react"; import styled from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import { breakpoint } from "@shared/styles/breakpoint"; import Flex from "~/components/Flex"; import Text from "~/components/Text"; @@ -27,6 +27,29 @@ const Row = styled(Flex)<{ $border?: boolean; $compact?: boolean }>` &:last-child { border-bottom: 0; } + + ${breakpoint("mobile", "tablet")` + &:has([role="switch"]) { + gap: 16px; + + > :first-child { + min-width: 0; + } + + > :last-child { + flex: 0 0 auto; + } + } + + &:not(:has([role="switch"])) { + flex-direction: column; + gap: 12px; + + > :last-child > * { + align-self: stretch; + } + } + `}; `; const Column = styled.div` diff --git a/app/scenes/Settings/components/StickyFilters.tsx b/app/scenes/Settings/components/StickyFilters.tsx index 2dfe99b294..493694326a 100644 --- a/app/scenes/Settings/components/StickyFilters.tsx +++ b/app/scenes/Settings/components/StickyFilters.tsx @@ -1,6 +1,8 @@ import styled from "styled-components"; +import { breakpoint } from "@shared/styles/breakpoint"; import { depths, s } from "@shared/styles"; import { HEADER_HEIGHT } from "~/components/Header"; +import { Wrapper as InputWrapper } from "~/components/Input"; import { HStack } from "~/components/primitives/HStack"; export const FILTER_HEIGHT = 40; @@ -11,4 +13,17 @@ export const StickyFilters = styled(HStack)` top: ${HEADER_HEIGHT}px; z-index: ${depths.header}; background: ${s("background")}; + + ${breakpoint("mobile", "tablet")` + position: static; + height: auto; + flex-wrap: wrap; + justify-content: flex-start; + padding-block: 8px; + + ${InputWrapper} { + flex: 1 1 100%; + max-width: none; + } + `}; `; diff --git a/app/scenes/Shared/Collection.tsx b/app/scenes/Shared/Collection.tsx index 1e7604138f..11b591b2f1 100644 --- a/app/scenes/Shared/Collection.tsx +++ b/app/scenes/Shared/Collection.tsx @@ -3,7 +3,7 @@ import { EditIcon } from "outline-icons"; import { useTranslation } from "react-i18next"; import { Link } from "react-router-dom"; import styled from "styled-components"; -import breakpoint from "styled-components-breakpoint"; +import { breakpoint } from "@shared/styles/breakpoint"; import { IconTitleWrapper } from "@shared/components/Icon"; import useShare from "@shared/hooks/useShare"; import type CollectionModel from "~/models/Collection"; diff --git a/app/styles/animations.ts b/app/styles/animations.ts index 88e123bd73..e8170960c1 100644 --- a/app/styles/animations.ts +++ b/app/styles/animations.ts @@ -148,3 +148,8 @@ export const pulse = keyframes` * The duration of the sidebar appearing animation in ms */ export const sidebarAppearDuration = 600; + +/** + * The duration and easing of the vaul drawer, shared so that panels move the same way. + */ +export const drawerTransition = "500ms cubic-bezier(0.32, 0.72, 0, 1)"; diff --git a/app/typings/index.d.ts b/app/typings/index.d.ts index 5246a4f60b..d5aae0be94 100644 --- a/app/typings/index.d.ts +++ b/app/typings/index.d.ts @@ -6,8 +6,6 @@ declare module "emoji-mart"; declare module "string-replace-to-array"; -declare module "styled-components-breakpoint"; - declare module "command-score"; declare module "*.png" { diff --git a/app/typings/window.d.ts b/app/typings/window.d.ts index 3045f5c3fd..e0014385a6 100644 --- a/app/typings/window.d.ts +++ b/app/typings/window.d.ts @@ -72,6 +72,12 @@ declare global { */ loadAuthConfig: (host: string) => Promise<{ providers: unknown[] }>; + /** + * Returns true when passkeys can be created and used inside the app, rather + * than in the system browser. Not present in older desktop apps. + */ + isPasskeySupported?: () => Promise; + /** * Clears the desktop configuration, removing any custom hosts. Intended * for debugging use. diff --git a/app/utils/Desktop.ts b/app/utils/Desktop.ts index e5b05935b6..fd0bbe3b6e 100644 --- a/app/utils/Desktop.ts +++ b/app/utils/Desktop.ts @@ -39,6 +39,24 @@ export default class Desktop { return navigator?.userAgent?.includes("Electron"); } + /** + * Returns true when the desktop app can run the WebAuthn ceremony itself. This + * requires a desktop app that has configured a platform authenticator, and a + * device that supports it. + * + * @returns a promise that resolves to true if passkeys work inside the app. + */ + static async isPasskeySupported(): Promise { + try { + if (!(await this.bridge?.isPasskeySupported?.())) { + return false; + } + return await PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable(); + } catch (_err) { + return false; + } + } + /** * The bridge provides secure access to API's in desktop wrapper. */ diff --git a/build.js b/build.js index 177135f0c3..1b7361441d 100755 --- a/build.js +++ b/build.js @@ -1,8 +1,18 @@ /* oxlint-disable no-console */ /* oxlint-disable typescript/no-require-imports */ /* oxlint-disable no-undef */ -const { exec } = require("child_process"); -const { readdirSync, existsSync } = require("fs"); +const { exec, spawn } = require("child_process"); +const { + copyFileSync, + existsSync, + mkdirSync, + readdirSync, + rmSync, + statSync, + watch, +} = require("fs"); +const { writeFile } = require("fs/promises"); +const path = require("path"); const getDirectories = (source) => readdirSync(source, { withFileTypes: true }) @@ -38,34 +48,12 @@ async function build() { const d = getDirectories("./plugins"); - // Compile server and shared + // Compile server, shared and plugins in a single SWC process, as process + // startup costs far more than the compilation itself. console.log("Compiling…"); - const swc = (src, out) => - execAsync( - `yarn swc "${src}" -d "${out}" --strip-leading-paths --extensions .ts,.tsx --ignore "**/*.test.ts,**/*.test.tsx,**/__mocks__/**" --quiet` - ); - - await Promise.all([ - swc("./server", "./build/server"), - swc("./shared", "./build/shared"), - ]); - - // SWC's --strip-leading-paths removes only the topmost path segment, so a - // `plugins//server` input keeps `/server/…` and lands correctly - // under a `./build/plugins` output directory. - for (const plugin of d) { - const hasServer = existsSync(`./plugins/${plugin}/server`); - - if (hasServer) { - await swc(`./plugins/${plugin}/server`, "./build/plugins"); - } - - const hasShared = existsSync(`./plugins/${plugin}/shared`); - - if (hasShared) { - await swc(`./plugins/${plugin}/shared`, "./build/plugins"); - } - } + await execAsync( + `node_modules/.bin/swc ./server ./shared ./plugins -d ./build --extensions .ts,.tsx --ignore "**/*.test.ts,**/*.test.tsx,**/__mocks__/**,plugins/*/client/**" --quiet` + ); // Copy static files console.log("Copying static files…"); @@ -91,4 +79,216 @@ async function build() { console.log("Done!"); } -void build(); +/** + * Whether a source file is compiled into the server build. + * @param file {string} path relative to the project root. + * @return {boolean} + */ +function isCompiled(file) { + return ( + /\.tsx?$/.test(file) && + !/\.test\.tsx?$/.test(file) && + !file.split(path.sep).includes("__mocks__") && + !/^plugins[\\/][^\\/]+[\\/]client[\\/]/.test(file) + ); +} + +/** + * The build output path of a source file. + * @param file {string} path relative to the project root. + * @return {string | undefined} the output path, or undefined if the file is not + * part of the build. + */ +function getDest(file) { + if (isCompiled(file)) { + return path.join("build", file.replace(/\.tsx?$/, ".js")); + } + if ( + /^plugins[\\/][^\\/]+[\\/]plugin\.json$/.test(file) || + /^shared[\\/]i18n[\\/]locales[\\/]/.test(file) + ) { + return path.join("build", file); + } + return undefined; +} + +/** + * Builds, then watches the source directories and updates the output of each + * changed, added or removed file. A full build runs again after a failed one. + * When a command is passed it is run, and restarted after each change that + * affects the server. + * @param command {string[]} the command and arguments to run, may be empty. + */ +async function watchSources(command) { + const swc = require("@swc/core"); + const timers = new Map(); + let child; + let restartTimer; + let isBuilt = false; + let isBuilding = false; + let isBuildPending = false; + + const startServer = () => { + // Run in a new process group so the forked service processes are stopped + // together with the master. + child = spawn(command[0], command.slice(1), { + stdio: "inherit", + detached: true, + }); + child.once("exit", (code, signal) => { + child = undefined; + if (signal !== "SIGKILL") { + console.log( + `Server exited with ${signal ?? code}, waiting for changes…` + ); + } + }); + }; + + const stopServer = (callback) => { + if (!child) { + callback?.(); + return; + } + if (callback) { + child.once("exit", callback); + } + process.kill(-child.pid, "SIGKILL"); + }; + + const restartServer = () => { + if (!command.length || !isBuilt) { + return; + } + clearTimeout(restartTimer); + restartTimer = setTimeout(() => { + console.log("Restarting…"); + stopServer(startServer); + }, 100); + }; + + const fullBuild = async () => { + if (isBuilding) { + isBuildPending = true; + return; + } + + isBuilding = true; + try { + await build(); + isBuilt = true; + } catch (err) { + console.error(err.message ?? err); + console.log("Build failed, waiting for changes…"); + } finally { + isBuilding = false; + } + + if (isBuildPending) { + isBuildPending = false; + await fullBuild(); + } else if (isBuilt && command.length) { + startServer(); + } + }; + + const updateFile = async (file) => { + const dest = getDest(file); + if (!dest) { + return false; + } + + if (!isCompiled(file)) { + mkdirSync(path.dirname(dest), { recursive: true }); + copyFileSync(file, dest); + console.log(`Copied ${file}`); + return true; + } + + const start = performance.now(); + try { + const { code } = await swc.transformFile(file); + mkdirSync(path.dirname(dest), { recursive: true }); + await writeFile(dest, code); + console.log( + `Compiled ${file} (${(performance.now() - start).toFixed(1)}ms)` + ); + return true; + } catch (err) { + console.error(err.message ?? err); + return false; + } + }; + + const handleChange = async (file) => { + const stats = statSync(file, { throwIfNoEntry: false }); + let isChanged = false; + + if (!stats) { + // The path of a removed directory maps directly to its output. + const dest = getDest(file) ?? path.join("build", file); + if (existsSync(dest)) { + rmSync(dest, { recursive: true, force: true }); + isChanged = true; + } + } else if (stats.isDirectory()) { + // A directory that was moved in does not emit events for its files. + for (const entry of readdirSync(file, { recursive: true })) { + isChanged = (await updateFile(path.join(file, entry))) || isChanged; + } + } else { + isChanged = await updateFile(file); + } + + // The editor and components are mostly used by the client, so changes + // there are picked up on the next restart. + if (isChanged && !/^shared[\\/](editor|components)[\\/]/.test(file)) { + restartServer(); + } + }; + + for (const dir of ["server", "shared", "plugins"]) { + watch(dir, { recursive: true }, (_event, filename) => { + if (!filename) { + return; + } + if (!isBuilt) { + void fullBuild(); + return; + } + + // Editors can emit several events for one save, so debounce each file. + const file = path.join(dir, filename); + clearTimeout(timers.get(file)); + timers.set( + file, + setTimeout(() => { + timers.delete(file); + void handleChange(file); + }, 50) + ); + }); + } + + watch(".", (_event, filename) => { + if (/^\.env(\.local|\.development)?$/.test(filename ?? "")) { + restartServer(); + } + }); + + for (const signal of ["SIGINT", "SIGTERM"]) { + process.once(signal, () => stopServer(() => process.exit(0))); + } + + await fullBuild(); + console.log("Watching for changes…"); +} + +if (process.argv.includes("--watch")) { + // Arguments after "--" are the command to run, e.g. the server. + const separator = process.argv.indexOf("--"); + const command = separator === -1 ? [] : process.argv.slice(separator + 1); + void watchSources(command); +} else { + void build(); +} diff --git a/package.json b/package.json index 8d3ab33590..47154d7a13 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "build": "yarn clean && yarn vite:build && yarn build:i18n && yarn build:server", "start": "node ./build/server/index.js", "dev": "NODE_ENV=development yarn concurrently -n api,collaboration -c \"blue,magenta\" \"node --inspect=0.0.0.0 build/server/index.js --services=cron,collaboration,websockets,admin,web,worker\"", - "dev:backend": "NODE_ENV=development nodemon --quiet --exec \"yarn build:server && yarn dev\" -e js,ts,tsx --watch server --watch shared --watch plugins --watch .env --watch .env.local --watch .env.development --ignore \"shared/components/**/*.tsx?\" --ignore \"plugins/client/**/*.tsx?\" --ignore \"**/*.test.ts\" --ignore data/ --ignore build/ --ignore app/ --ignore \"shared/editor/**\" --ignore server/migrations", + "dev:backend": "NODE_ENV=development node ./build.js --watch -- node --inspect=0.0.0.0 build/server/index.js --services=cron,collaboration,websockets,admin,web,worker", "dev:watch": "NODE_ENV=development yarn concurrently -n backend,frontend \"yarn dev:backend\" \"yarn vite:dev\"", "lint": "oxlint --type-aware app server shared plugins", "lint:changed": "git diff --name-only --diff-filter=ACMRTUXB | grep -E '\\.(js|jsx|ts|tsx)$' | xargs -r oxlint", @@ -52,12 +52,12 @@ "> 0.25%, not dead" ], "dependencies": { - "@aws-sdk/client-s3": "^3.1149.0", + "@aws-sdk/client-s3": "^3.1152.0", "@aws-sdk/cloudfront-signer": "^3.1149.0", - "@aws-sdk/lib-storage": "^3.1149.0", - "@aws-sdk/s3-presigned-post": "^3.1149.0", - "@aws-sdk/s3-request-presigner": "^3.1149.0", - "@aws-sdk/signature-v4-crt": "^3.1149.0", + "@aws-sdk/lib-storage": "^3.1152.0", + "@aws-sdk/s3-presigned-post": "^3.1152.0", + "@aws-sdk/s3-request-presigner": "^3.1152.0", + "@aws-sdk/signature-v4-crt": "^3.1152.0", "@benrbray/prosemirror-math": "^0.2.2", "@bull-board/api": "^6.21.3", "@bull-board/koa": "^6.21.3", @@ -85,7 +85,7 @@ "@koa/router": "^15.7.0", "@koa/send": "^6.0.0", "@linear/sdk": "^97.0.0", - "@modelcontextprotocol/sdk": "^1.31.0", + "@modelcontextprotocol/sdk": "^1.32.1", "@noble/hashes": "^2.4.0", "@node-oauth/oauth2-server": "^5.3.0", "@notionhq/client": "^2.3.0", @@ -93,21 +93,21 @@ "@octokit/webhooks-types": "^7.6.1", "@outlinewiki/koa-passport": "^4.2.1", "@outlinewiki/passport-azure-ad-oauth2": "^0.1.0", - "@radix-ui/react-collapsible": "^1.1.21", - "@radix-ui/react-context-menu": "^2.3.8", - "@radix-ui/react-dialog": "^1.2.0", - "@radix-ui/react-direction": "^1.1.5", - "@radix-ui/react-dropdown-menu": "^2.1.25", - "@radix-ui/react-hover-card": "^1.1.24", - "@radix-ui/react-one-time-password-field": "^0.1.17", - "@radix-ui/react-popover": "^1.2.0", - "@radix-ui/react-select": "^2.3.8", - "@radix-ui/react-slot": "^1.4.0", - "@radix-ui/react-switch": "^1.3.8", - "@radix-ui/react-tabs": "^1.1.22", - "@radix-ui/react-toolbar": "^1.1.20", - "@radix-ui/react-tooltip": "^1.3.0", - "@radix-ui/react-visually-hidden": "^1.2.12", + "@radix-ui/react-collapsible": "^1.2.1", + "@radix-ui/react-context-menu": "^2.4.1", + "@radix-ui/react-dialog": "^1.3.1", + "@radix-ui/react-direction": "^1.2.0", + "@radix-ui/react-dropdown-menu": "^2.2.1", + "@radix-ui/react-hover-card": "^1.2.1", + "@radix-ui/react-one-time-password-field": "^0.2.1", + "@radix-ui/react-popover": "^1.3.1", + "@radix-ui/react-select": "^2.4.1", + "@radix-ui/react-slot": "^1.5.0", + "@radix-ui/react-switch": "^1.4.1", + "@radix-ui/react-tabs": "^1.2.1", + "@radix-ui/react-toolbar": "^1.2.1", + "@radix-ui/react-tooltip": "^1.4.1", + "@radix-ui/react-visually-hidden": "^1.2.13", "@sentry/node": "^10.76.2", "@sentry/react": "^10.76.2", "@simplewebauthn/browser": "^13.3.0", @@ -121,7 +121,7 @@ "addressparser": "^1.0.1", "async-sema": "^3.1.1", "bull": "^4.16.5", - "chrono-node": "^2.10.1", + "chrono-node": "^2.10.3", "class-validator": "^0.15.1", "command-score": "^0.1.2", "compressorjs": "^1.3.0", @@ -153,8 +153,8 @@ "http-errors": "2.0.1", "https-proxy-agent": "^7.0.6", "i18next": "^22.5.1", - "i18next-fs-backend": "^2.6.8", - "i18next-http-backend": "^3.0.6", + "i18next-fs-backend": "^2.6.9", + "i18next-http-backend": "^4.0.3", "invariant": "^2.2.4", "ioredis": "^5.11.1", "ipaddr.js": "^2.4.0", @@ -177,7 +177,7 @@ "lib0": "^0.2.99", "mailparser": "^3.9.28", "mammoth": "^1.11.0", - "markdown-it": "^14.3.2", + "markdown-it": "^14.3.3", "markdown-it-container": "^3.0.0", "markdown-it-emoji": "^3.0.0", "mime-types": "^3.0.2", @@ -258,7 +258,6 @@ "stoppable": "^1.1.0", "string-replace-to-array": "^2.1.1", "styled-components": "^6.5.3", - "styled-components-breakpoint": "^2.1.1", "styled-normalize": "^8.1.1", "throng": "^5.0.0", "tiny-cookie": "^2.5.1", @@ -270,7 +269,7 @@ "uuid": "^11.1.1", "validator": "13.15.35", "vaul": "^1.1.2", - "vite": "^8.3.2", + "vite": "^8.3.3", "vite-plugin-pwa": "1.3.0", "winston": "^3.17.0", "ws": "^7.5.13", @@ -345,7 +344,6 @@ "ioredis-mock": "^8.13.1", "lint-staged": "^16.4.0", "msw": "^2.15.0", - "nodemon": "^3.1.14", "oxfmt": "0.72.0", "oxlint": "1.81.0", "oxlint-tsgolint": "7.0.2001", diff --git a/plugins/passkeys/client/Settings.tsx b/plugins/passkeys/client/Settings.tsx index 8137c52870..241df2e99f 100644 --- a/plugins/passkeys/client/Settings.tsx +++ b/plugins/passkeys/client/Settings.tsx @@ -21,6 +21,7 @@ import usePolicy from "~/hooks/usePolicy"; import useCurrentTeam from "~/hooks/useCurrentTeam"; import Notice from "~/components/Notice"; import DelayedMount from "~/components/DelayedMount"; +import Desktop from "~/utils/Desktop"; type Passkey = { id: string; @@ -38,6 +39,9 @@ function PasskeysSettings() { const [passkeys, setPasskeys] = React.useState([]); const [isLoading, setIsLoading] = React.useState(true); const [isRegistering, setIsRegistering] = React.useState(false); + const [isSupported, setIsSupported] = React.useState( + () => (Desktop.isElectron() ? undefined : true) + ); const team = useCurrentTeam(); const can = usePolicy(team); @@ -57,6 +61,12 @@ function PasskeysSettings() { void loadPasskeys(); }, [loadPasskeys]); + React.useEffect(() => { + if (Desktop.isElectron()) { + void Desktop.isPasskeySupported().then(setIsSupported); + } + }, []); + const handleRegister = async () => { setIsRegistering(true); try { @@ -139,7 +149,7 @@ function PasskeysSettings() {

+ +