diff --git a/README.md b/README.md index 33481fab25..da2636cc28 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@

An open, extensible, wiki for your team built using React and Node.js.
Try out Outline using our hosted version at www.getoutline.com.

- Outline + Outline

diff --git a/app.json b/app.json index 5aa7e99097..4af94bb08b 100644 --- a/app.json +++ b/app.json @@ -30,6 +30,10 @@ "postdeploy": "yarn sequelize db:migrate" }, "env": { + "NODE_ENV": { + "value": "production", + "required": true + }, "SECRET_KEY": { "description": "A secret key", "generator": "secret", @@ -144,4 +148,4 @@ "required": false } } -} \ No newline at end of file +} diff --git a/app/components/Arrow.js b/app/components/Arrow.js new file mode 100644 index 0000000000..2b6ade160a --- /dev/null +++ b/app/components/Arrow.js @@ -0,0 +1,23 @@ +// @flow +import * as React from "react"; + +export default function Arrow() { + return ( + + + + + ); +} diff --git a/app/components/Sidebar/components/Bubble.js b/app/components/Bubble.js similarity index 92% rename from app/components/Sidebar/components/Bubble.js rename to app/components/Bubble.js index e70087e360..2bfd3dc2b0 100644 --- a/app/components/Sidebar/components/Bubble.js +++ b/app/components/Bubble.js @@ -3,11 +3,15 @@ import * as React from "react"; import styled from "styled-components"; import { bounceIn } from "shared/styles/animations"; -type Props = { +type Props = {| count: number, -}; +|}; const Bubble = ({ count }: Props) => { + if (!count) { + return null; + } + return {count}; }; diff --git a/app/components/CenteredContent.js b/app/components/CenteredContent.js index 0a868cc567..b25801640a 100644 --- a/app/components/CenteredContent.js +++ b/app/components/CenteredContent.js @@ -3,17 +3,18 @@ import * as React from "react"; import styled from "styled-components"; import breakpoint from "styled-components-breakpoint"; -type Props = { +type Props = {| children?: React.Node, -}; + withStickyHeader?: boolean, +|}; const Container = styled.div` width: 100%; max-width: 100vw; - padding: 60px 20px; + padding: ${(props) => (props.withStickyHeader ? "4px 12px" : "60px 12px")}; ${breakpoint("tablet")` - padding: 60px; + padding: ${(props) => (props.withStickyHeader ? "4px 60px" : "60px")}; `}; `; diff --git a/app/components/Collaborators.js b/app/components/Collaborators.js index 2292f45fd7..b5f65ba625 100644 --- a/app/components/Collaborators.js +++ b/app/components/Collaborators.js @@ -2,8 +2,9 @@ import { sortBy, keyBy } from "lodash"; import { observer, inject } from "mobx-react"; import * as React from "react"; +import styled from "styled-components"; +import breakpoint from "styled-components-breakpoint"; import { MAX_AVATAR_DISPLAY } from "shared/constants"; - import DocumentPresenceStore from "stores/DocumentPresenceStore"; import ViewsStore from "stores/ViewsStore"; import Document from "models/Document"; @@ -51,7 +52,7 @@ class Collaborators extends React.Component { const overflow = documentViews.length - mostRecentViewers.length; return ( - v.user)} overflow={overflow} renderAvatar={(user) => { @@ -75,4 +76,10 @@ class Collaborators extends React.Component { } } +const FacepileHiddenOnMobile = styled(Facepile)` + ${breakpoint("mobile", "tablet")` + display: none; + `}; +`; + export default inject("views", "presence")(Collaborators); diff --git a/app/components/CollectionDescription.js b/app/components/CollectionDescription.js new file mode 100644 index 0000000000..1e13b461a5 --- /dev/null +++ b/app/components/CollectionDescription.js @@ -0,0 +1,212 @@ +// @flow +import { observer } from "mobx-react"; +import { transparentize } from "polished"; +import * as React from "react"; +import { useTranslation } from "react-i18next"; +import styled from "styled-components"; +import Collection from "models/Collection"; +import Arrow from "components/Arrow"; +import ButtonLink from "components/ButtonLink"; +import Editor from "components/Editor"; +import LoadingIndicator from "components/LoadingIndicator"; +import NudeButton from "components/NudeButton"; +import useDebouncedCallback from "hooks/useDebouncedCallback"; +import useStores from "hooks/useStores"; + +type Props = {| + collection: Collection, +|}; + +function CollectionDescription({ collection }: Props) { + const { collections, ui, policies } = useStores(); + const { t } = useTranslation(); + const [isExpanded, setExpanded] = React.useState(false); + const [isEditing, setEditing] = React.useState(false); + const [isDirty, setDirty] = React.useState(false); + const can = policies.abilities(collection.id); + + const handleStartEditing = React.useCallback(() => { + setEditing(true); + }, []); + + const handleStopEditing = React.useCallback(() => { + setEditing(false); + }, []); + + const handleClickDisclosure = React.useCallback( + (event) => { + event.preventDefault(); + + if (isExpanded && document.activeElement) { + document.activeElement.blur(); + } + + setExpanded(!isExpanded); + }, + [isExpanded] + ); + + const handleSave = useDebouncedCallback(async (getValue) => { + try { + await collection.save({ + description: getValue(), + }); + setDirty(false); + } catch (err) { + ui.showToast( + t("Sorry, an error occurred saving the collection", { + type: "error", + }) + ); + throw err; + } + }, 1000); + + const handleChange = React.useCallback( + (getValue) => { + setDirty(true); + handleSave(getValue); + }, + [handleSave] + ); + + React.useEffect(() => { + setEditing(false); + }, [collection.id]); + + const placeholder = `${t("Add a description")}…`; + const key = isEditing || isDirty ? "draft" : collection.updatedAt; + + return ( + + + + {collections.isSaving && } + {collection.hasDescription || isEditing || isDirty ? ( + Loading…}> + + + ) : ( + can.update && {placeholder} + )} + + + {!isEditing && ( + + + + )} + + ); +} + +const Disclosure = styled(NudeButton)` + opacity: 0; + color: ${(props) => props.theme.divider}; + position: absolute; + top: calc(25vh - 50px); + left: 50%; + z-index: 1; + transform: rotate(-90deg) translateX(-50%); + transition: opacity 100ms ease-in-out; + + &:focus, + &:hover { + opacity: 1; + } + + &:active { + color: ${(props) => props.theme.sidebarText}; + } +`; + +const Placeholder = styled(ButtonLink)` + color: ${(props) => props.theme.placeholder}; + cursor: text; + min-height: 27px; +`; + +const MaxHeight = styled.div` + position: relative; + max-height: 25vh; + overflow: hidden; + margin: -8px; + padding: 8px; + + &[data-editing="true"], + &[data-expanded="true"] { + max-height: initial; + overflow: initial; + + ${Disclosure} { + top: initial; + bottom: 0; + transform: rotate(90deg) translateX(-50%); + } + } + + &:hover ${Disclosure} { + opacity: 1; + } +`; + +const Input = styled.div` + margin: -8px; + padding: 8px; + border-radius: 8px; + transition: ${(props) => props.theme.backgroundTransition}; + + &:after { + content: ""; + position: absolute; + top: calc(25vh - 50px); + left: 0; + right: 0; + height: 50px; + pointer-events: none; + background: linear-gradient( + 180deg, + ${(props) => transparentize(1, props.theme.background)} 0%, + ${(props) => props.theme.background} 100% + ); + } + + &[data-editing="true"], + &[data-expanded="true"] { + &:after { + background: transparent; + } + } + + &[data-editing="true"] { + background: ${(props) => props.theme.secondaryBackground}; + } + + .block-menu-trigger, + .heading-anchor { + display: none !important; + } +`; + +export default observer(CollectionDescription); diff --git a/app/components/DocumentListItem.js b/app/components/DocumentListItem.js index 78fe61d54a..1a52d4f6c1 100644 --- a/app/components/DocumentListItem.js +++ b/app/components/DocumentListItem.js @@ -163,8 +163,11 @@ const DocumentLink = styled(Link)` padding: 6px 8px; border-radius: 8px; max-height: 50vh; - min-width: 100%; - max-width: calc(100vw - 40px); + width: calc(100vw - 8px); + + ${breakpoint("tablet")` + width: auto; + `}; ${Actions} { opacity: 0; diff --git a/app/components/Editor.js b/app/components/Editor.js index 103d877776..37d01c5f8a 100644 --- a/app/components/Editor.js +++ b/app/components/Editor.js @@ -27,13 +27,16 @@ export type Props = {| autoFocus?: boolean, template?: boolean, placeholder?: string, + maxLength?: number, scrollTo?: string, + handleDOMEvents?: Object, readOnlyWriteCheckboxes?: boolean, onBlur?: (event: SyntheticEvent<>) => any, onFocus?: (event: SyntheticEvent<>) => any, onPublish?: (event: SyntheticEvent<>) => any, onSave?: ({ done?: boolean, autosave?: boolean, publish?: boolean }) => any, onCancel?: () => any, + onDoubleClick?: () => any, onChange?: (getValue: () => string) => any, onSearchLink?: (title: string) => any, onHoverLink?: (event: MouseEvent) => any, @@ -177,7 +180,7 @@ const StyledEditor = styled(RichMarkdownEditor)` justify-content: start; > div { - transition: ${(props) => props.theme.backgroundTransition}; + background: transparent; } & * { diff --git a/app/components/Header.js b/app/components/Header.js new file mode 100644 index 0000000000..9a0e67908a --- /dev/null +++ b/app/components/Header.js @@ -0,0 +1,104 @@ +// @flow +import { throttle } from "lodash"; +import { observer } from "mobx-react"; +import { transparentize } from "polished"; +import * as React from "react"; +import styled from "styled-components"; +import breakpoint from "styled-components-breakpoint"; +import Fade from "components/Fade"; +import Flex from "components/Flex"; + +type Props = {| + breadcrumb?: React.Node, + title: React.Node, + actions?: React.Node, +|}; + +function Header({ breadcrumb, title, actions }: Props) { + const [isScrolled, setScrolled] = React.useState(false); + + const handleScroll = React.useCallback( + throttle(() => setScrolled(window.scrollY > 75), 50), + [] + ); + + React.useEffect(() => { + window.addEventListener("scroll", handleScroll); + + return () => window.removeEventListener("scroll", handleScroll); + }, [handleScroll]); + + const handleClickTitle = React.useCallback(() => { + window.scrollTo({ + top: 0, + behavior: "smooth", + }); + }, []); + + return ( + + {breadcrumb} + {isScrolled ? ( + + <Fade> + <Flex align="center">{title}</Flex> + </Fade> + + ) : ( +

+ )} + {actions && {actions}} + + ); +} + +const Wrapper = styled(Flex)` + position: sticky; + top: 0; + right: 0; + left: 0; + z-index: 2; + background: ${(props) => transparentize(0.2, props.theme.background)}; + padding: 12px; + transition: all 100ms ease-out; + transform: translate3d(0, 0, 0); + backdrop-filter: blur(20px); + + @media print { + display: none; + } + + ${breakpoint("tablet")` + padding: ${(props) => (props.isCompact ? "12px" : `24px 24px 0`)}; + `}; +`; + +const Title = styled(Flex)` + font-size: 16px; + font-weight: 600; + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; + cursor: pointer; + width: 0; + + ${breakpoint("tablet")` + flex-grow: 1; + `}; +`; + +const Actions = styled(Flex)` + align-self: flex-end; + height: 32px; +`; + +export default observer(Header); diff --git a/app/components/Input.js b/app/components/Input.js index 855f59b496..8ca02b24cf 100644 --- a/app/components/Input.js +++ b/app/components/Input.js @@ -4,6 +4,7 @@ import { observer } from "mobx-react"; import * as React from "react"; import { VisuallyHidden } from "reakit/VisuallyHidden"; import styled from "styled-components"; +import breakpoint from "styled-components-breakpoint"; import Flex from "components/Flex"; const RealTextarea = styled.textarea` @@ -33,6 +34,10 @@ const RealInput = styled.input` &::placeholder { color: ${(props) => props.theme.placeholder}; } + + ${breakpoint("mobile", "tablet")` + font-size: 16px; + `}; `; const Wrapper = styled.div` diff --git a/app/components/Layout.js b/app/components/Layout.js index dce3cb12cc..46b343f7d7 100644 --- a/app/components/Layout.js +++ b/app/components/Layout.js @@ -13,7 +13,7 @@ import { withRouter, type RouterHistory, } from "react-router-dom"; -import styled, { withTheme } from "styled-components"; +import styled from "styled-components"; import breakpoint from "styled-components-breakpoint"; import AuthStore from "stores/AuthStore"; import DocumentsStore from "stores/DocumentsStore"; @@ -31,7 +31,6 @@ import Sidebar from "components/Sidebar"; import SettingsSidebar from "components/Sidebar/Settings"; import SkipNavContent from "components/SkipNavContent"; import SkipNavLink from "components/SkipNavLink"; -import { type Theme } from "types"; import { meta } from "utils/keyboard"; import { homeUrl, @@ -50,7 +49,6 @@ type Props = { history: RouterHistory, policies: PoliciesStore, notifications?: React.Node, - theme: Theme, i18n: Object, t: TFunction, }; @@ -61,24 +59,12 @@ class Layout extends React.Component { @observable redirectTo: ?string; @observable keyboardShortcutsOpen: boolean = false; - constructor(props: Props) { - super(); - this.updateBackground(props); - } - componentDidUpdate() { - this.updateBackground(this.props); - if (this.redirectTo) { this.redirectTo = undefined; } } - updateBackground(props: Props) { - // ensure the wider page color always matches the theme - window.document.body.style.background = props.theme.background; - } - @keydown(`${meta}+.`) handleToggleSidebar() { this.props.ui.toggleCollapsedSidebar(); @@ -235,5 +221,5 @@ const Content = styled(Flex)` `; export default withTranslation()( - inject("auth", "ui", "documents", "policies")(withRouter(withTheme(Layout))) + inject("auth", "ui", "documents", "policies")(withRouter(Layout)) ); diff --git a/app/components/PageTheme.js b/app/components/PageTheme.js new file mode 100644 index 0000000000..2914f78b24 --- /dev/null +++ b/app/components/PageTheme.js @@ -0,0 +1,35 @@ +// @flow +import * as React from "react"; +import { useTheme } from "styled-components"; +import useStores from "hooks/useStores"; + +export default function PageTheme() { + const { ui } = useStores(); + const theme = useTheme(); + + React.useEffect(() => { + // wider page background beyond the React root + if (document.body) { + document.body.style.background = theme.background; + } + + // theme-color adjusts the title bar color for desktop PWA + const themeElement = document.querySelector('meta[name="theme-color"]'); + if (themeElement) { + themeElement.setAttribute("content", theme.background); + } + + // status bar color for iOS PWA + const statusElement = document.querySelector( + 'meta[name="apple-mobile-web-app-status-bar-style"]' + ); + if (statusElement) { + statusElement.setAttribute( + "content", + ui.resolvedTheme === "dark" ? "black-translucent" : "default" + ); + } + }, [theme, ui.resolvedTheme]); + + return null; +} diff --git a/app/components/Scene.js b/app/components/Scene.js new file mode 100644 index 0000000000..eaf31732bb --- /dev/null +++ b/app/components/Scene.js @@ -0,0 +1,50 @@ +// @flow +import * as React from "react"; +import styled from "styled-components"; +import CenteredContent from "components/CenteredContent"; +import Header from "components/Header"; +import PageTitle from "components/PageTitle"; + +type Props = {| + icon?: React.Node, + title: React.Node, + textTitle?: string, + children: React.Node, + breadcrumb?: React.Node, + actions?: React.Node, +|}; + +function Scene({ + title, + icon, + textTitle, + actions, + breadcrumb, + children, +}: Props) { + return ( + + +
+ {icon} {title} + + ) : ( + title + ) + } + actions={actions} + breadcrumb={breadcrumb} + /> + {children} + + ); +} + +const FillWidth = styled.div` + width: 100%; +`; + +export default Scene; diff --git a/app/components/Sidebar/Main.js b/app/components/Sidebar/Main.js index fdbd2e3534..8c948ccac4 100644 --- a/app/components/Sidebar/Main.js +++ b/app/components/Sidebar/Main.js @@ -16,15 +16,15 @@ import { useTranslation } from "react-i18next"; import styled from "styled-components"; import CollectionNew from "scenes/CollectionNew"; import Invite from "scenes/Invite"; +import Bubble from "components/Bubble"; import Flex from "components/Flex"; import Modal from "components/Modal"; import Scrollable from "components/Scrollable"; import Sidebar from "./Sidebar"; -import Bubble from "./components/Bubble"; import Collections from "./components/Collections"; -import HeaderBlock from "./components/HeaderBlock"; import Section from "./components/Section"; import SidebarLink from "./components/SidebarLink"; +import TeamButton from "./components/TeamButton"; import useStores from "hooks/useStores"; import AccountMenu from "menus/AccountMenu"; @@ -72,7 +72,7 @@ function MainSidebar() { {(props) => ( - {t("Drafts")} - {documents.totalDrafts > 0 && ( - - )} + } active={ diff --git a/app/components/Sidebar/Settings.js b/app/components/Sidebar/Settings.js index 94f732e4c6..ddb2057cb5 100644 --- a/app/components/Sidebar/Settings.js +++ b/app/components/Sidebar/Settings.js @@ -21,9 +21,9 @@ import Scrollable from "components/Scrollable"; import Sidebar from "./Sidebar"; import Header from "./components/Header"; -import HeaderBlock from "./components/HeaderBlock"; import Section from "./components/Section"; import SidebarLink from "./components/SidebarLink"; +import TeamButton from "./components/TeamButton"; import Version from "./components/Version"; import SlackIcon from "./icons/Slack"; import ZapierIcon from "./icons/Zapier"; @@ -46,7 +46,7 @@ function SettingsSidebar() { return ( - {t("Return to App")} diff --git a/app/components/Sidebar/components/HeaderBlock.js b/app/components/Sidebar/components/TeamButton.js similarity index 88% rename from app/components/Sidebar/components/HeaderBlock.js rename to app/components/Sidebar/components/TeamButton.js index ee8e40e464..9a9206dd1e 100644 --- a/app/components/Sidebar/components/HeaderBlock.js +++ b/app/components/Sidebar/components/TeamButton.js @@ -13,7 +13,7 @@ type Props = {| logoUrl: string, |}; -const HeaderBlock = React.forwardRef( +const TeamButton = React.forwardRef( ({ showDisclosure, teamName, subheading, logoUrl, ...rest }: Props, ref) => (
@@ -25,8 +25,7 @@ const HeaderBlock = React.forwardRef( /> - {teamName}{" "} - {showDisclosure && } + {teamName} {showDisclosure && } {subheading} @@ -35,7 +34,7 @@ const HeaderBlock = React.forwardRef( ) ); -const StyledExpandedIcon = styled(ExpandedIcon)` +const Disclosure = styled(ExpandedIcon)` position: absolute; right: 0; top: 0; @@ -84,4 +83,4 @@ const Header = styled.button` } `; -export default HeaderBlock; +export default TeamButton; diff --git a/app/components/Sidebar/components/Toggle.js b/app/components/Sidebar/components/Toggle.js index 4533c52069..86062e31a0 100644 --- a/app/components/Sidebar/components/Toggle.js +++ b/app/components/Sidebar/components/Toggle.js @@ -2,6 +2,7 @@ import * as React from "react"; import styled from "styled-components"; import breakpoint from "styled-components-breakpoint"; +import Arrow from "components/Arrow"; type Props = { direction: "left" | "right", @@ -14,22 +15,7 @@ const Toggle = React.forwardRef( return ( - - - - + ); @@ -60,6 +46,7 @@ export const ToggleButton = styled.button` `; export const Positioner = styled.div` + display: none; z-index: 2; position: absolute; top: 0; @@ -70,6 +57,10 @@ export const Positioner = styled.div` &:hover ${ToggleButton}, &:focus-within ${ToggleButton} { opacity: 1; } + + ${breakpoint("tablet")` + display: block; + `} `; export default Toggle; diff --git a/app/components/Subheading.js b/app/components/Subheading.js index c0716deb54..eecb044ab7 100644 --- a/app/components/Subheading.js +++ b/app/components/Subheading.js @@ -2,19 +2,17 @@ import * as React from "react"; import styled from "styled-components"; -type Props = { +type Props = {| children: React.Node, -}; +|}; const H3 = styled.h3` border-bottom: 1px solid ${(props) => props.theme.divider}; - margin-top: 22px; - margin-bottom: 12px; + margin: 12px 0; line-height: 1; - position: relative; `; -const Underline = styled("span")` +const Underline = styled.div` margin-top: -1px; display: inline-block; font-weight: 500; @@ -22,14 +20,29 @@ const Underline = styled("span")` line-height: 1.5; color: ${(props) => props.theme.textSecondary}; border-bottom: 3px solid ${(props) => props.theme.textSecondary}; - padding-bottom: 5px; + padding-top: 6px; + padding-bottom: 4px; +`; + +// When sticky we need extra background coverage around the sides otherwise +// items that scroll past can "stick out" the sides of the heading +const Sticky = styled.div` + position: sticky; + top: 54px; + margin: 0 -8px; + padding: 0 8px; + background: ${(props) => props.theme.background}; + transition: ${(props) => props.theme.backgroundTransition}; + z-index: 1; `; const Subheading = ({ children, ...rest }: Props) => { return ( -

- {children} -

+ +

+ {children} +

+
); }; diff --git a/app/components/Switch.js b/app/components/Switch.js index aaa08f186c..172c54e905 100644 --- a/app/components/Switch.js +++ b/app/components/Switch.js @@ -13,17 +13,23 @@ type Props = {| id?: string, |}; -function Switch({ width = 38, height = 20, label, ...props }: Props) { +function Switch({ width = 38, height = 20, label, disabled, ...props }: Props) { const component = ( - + ); if (label) { return ( -