diff --git a/.oxlintrc.json b/.oxlintrc.json index 349f3eea59..7b2243a1a5 100644 --- a/.oxlintrc.json +++ b/.oxlintrc.json @@ -125,32 +125,6 @@ "react-hooks/exhaustive-deps": "error" }, "plugins": ["eslint", "oxc", "react", "typescript", "import"] - }, - { - "files": ["shared/**/*.{js,jsx,ts,tsx}"], - "rules": { - "no-restricted-imports": [ - "error", - { - "paths": [ - { - "name": "prosemirror-tables", - "importNames": [ - "addRowBefore", - "addRowAfter", - "addColumnBefore", - "addColumnAfter" - ], - "message": "Use the wrappers from shared/editor/commands/table instead, which respect the target index and place the cursor in the inserted cell." - }, - { - "name": "sonner", - "message": "Do not import a toast library within shared; surface notifications through the onNotice callback so shared code stays decoupled from the app's toast implementation." - } - ] - } - ] - } } ] } diff --git a/app/.oxlintrc.json b/app/.oxlintrc.json index c5e7a685e1..9857c6171f 100644 --- a/app/.oxlintrc.json +++ b/app/.oxlintrc.json @@ -16,6 +16,18 @@ "no-restricted-imports": [ "error", { + "paths": [ + { + "name": "prosemirror-tables", + "importNames": [ + "addRowBefore", + "addRowAfter", + "addColumnBefore", + "addColumnAfter" + ], + "message": "Use the wrappers from shared/editor/commands/table instead, which respect the target index and place the cursor in the inserted cell." + } + ], "patterns": [ { "group": ["mime-types"], diff --git a/app/actions/definitions/developer.tsx b/app/actions/definitions/developer.tsx index 773ea07661..d7cf387dd3 100644 --- a/app/actions/definitions/developer.tsx +++ b/app/actions/definitions/developer.tsx @@ -133,9 +133,10 @@ export const clearIndexedDB = createAction({ icon: , keywords: "cache clear database", section: DeveloperSection, - perform: async ({ t }) => { + perform: async ({ t, stores }) => { history.push(homePath()); await deleteAllDatabases(); + stores.enablePersistence(); toast.success(t("IndexedDB cache cleared")); }, }); diff --git a/app/actions/definitions/documents.tsx b/app/actions/definitions/documents.tsx index 7972f7d6a9..ce8b8e7031 100644 --- a/app/actions/definitions/documents.tsx +++ b/app/actions/definitions/documents.tsx @@ -1,4 +1,5 @@ import copy from "copy-to-clipboard"; +import type { TFunction } from "i18next"; import invariant from "invariant"; import { capitalize, uniqBy } from "es-toolkit/compat"; import { @@ -30,6 +31,7 @@ import { GlobeIcon, LogoutIcon, CaseSensitiveIcon, + OrderedListIcon, RestoreIcon, EditIcon, EmbedIcon, @@ -42,7 +44,12 @@ import { import { toast } from "sonner"; import Icon from "@shared/components/Icon"; import type { NavigationNode } from "@shared/types"; -import { ExportContentType, UserPreference } from "@shared/types"; +import { + DocumentPreference, + ExportContentType, + HeadingPrefixStyle, + UserPreference, +} from "@shared/types"; import { isMobile } from "@shared/utils/browser"; import { Week } from "@shared/utils/time"; import type UserMembership from "~/models/UserMembership"; @@ -928,23 +935,25 @@ export const duplicateDocument = createAction({ }, }); +function pinToCollectionName({ getActiveModels, t, stores }: ActionContext) { + const documents = getActiveModels(Document); + if (documents.length === 1) { + const collectionName = stores.documents.getCollectionForDocument( + documents[0] + )?.name; + return t("Pin to {{collectionName}}", { + collectionName: collectionName ?? t("collection"), + }); + } + return t("Pin"); +} + /** * Pin a document to a collection. Pinned documents will be displayed at the top * of the collection for all collection members to see. */ export const pinDocumentToCollection = createAction({ - name: ({ getActiveModels, t, stores }) => { - const documents = getActiveModels(Document); - if (documents.length === 1) { - const collectionName = stores.documents.getCollectionForDocument( - documents[0] - )?.name; - return t("Pin to {{collectionName}}", { - collectionName: collectionName ?? t("collection"), - }); - } - return t("Pin"); - }, + name: pinToCollectionName, analyticsName: "Pin document to collection", section: ActiveDocumentSection, icon: , @@ -1006,14 +1015,6 @@ export const pinDocumentToHome = createAction({ }, }); -export const pinDocument = createActionWithChildren({ - name: ({ t }) => t("Pin"), - analyticsName: "Pin document", - section: ActiveDocumentSection, - icon: , - children: [pinDocumentToCollection, pinDocumentToHome], -}); - export const unpinDocument = createAction({ name: ({ t }) => t("Unpin"), analyticsName: "Unpin document", @@ -1039,6 +1040,82 @@ export const unpinDocument = createAction({ ), }); +const allPinnedToCollection = (context: ActionContext) => + everyActiveModel(context, Document, (document) => document.pinned); + +const nonePinnedToCollection = (context: ActionContext) => + everyActiveModel(context, Document, (document) => !document.pinned); + +/** + * Toggle whether a document is pinned to its collection, the current state is + * reflected in the item so the label does not change between the two. + */ +export const togglePinDocumentToCollection = createAction({ + name: pinToCollectionName, + analyticsName: "Toggle pin document to collection", + section: ActiveDocumentSection, + icon: , + iconInContextMenu: false, + selected: allPinnedToCollection, + visible: (context) => + // A mixed selection has no single state to toggle to, the one-way Pin and + // Unpin actions cover that case instead. + (allPinnedToCollection(context) || nonePinnedToCollection(context)) && + everyActiveModel(context, Document, (document) => { + const can = context.stores.policies.abilities(document.id); + return !!document.collectionId && (document.pinned ? can.unpin : can.pin); + }), + perform: (context) => + allPinnedToCollection(context) + ? unpinDocument.perform(context) + : pinDocumentToCollection.perform(context), +}); + +/** + * Toggle whether a document is pinned to team home, the current state is + * reflected in the item so the label does not change between the two. + */ +export const togglePinDocumentToHome = createAction({ + name: ({ t }) => t("Pin to home"), + analyticsName: "Toggle pin document to home", + section: ActiveDocumentSection, + icon: , + iconInContextMenu: false, + selected: ({ activeDocumentId, stores }) => + !!activeDocumentId && + !!stores.documents.get(activeDocumentId)?.pinnedToHome, + visible: ({ activeDocumentId, currentTeamId, stores }) => + !!currentTeamId && + !!activeDocumentId && + !!stores.policies.abilities(activeDocumentId).pinToHome, + perform: async (context) => { + const { activeDocumentId, location, t, stores } = context; + if (!activeDocumentId) { + return; + } + const document = stores.documents.get(activeDocumentId); + + if (!document?.pinnedToHome) { + await pinDocumentToHome.perform(context); + return; + } + + await document.unpin(); + + if (location.pathname !== homePath()) { + toast.success(t("Unpinned")); + } + }, +}); + +export const pinDocument = createActionWithChildren({ + name: ({ t }) => t("Pin"), + analyticsName: "Pin document", + section: ActiveDocumentSection, + icon: , + children: [togglePinDocumentToCollection, togglePinDocumentToHome], +}); + export const searchInDocument = createInternalLinkAction({ name: ({ t }) => t("Search in document"), analyticsName: "Search document", @@ -1720,6 +1797,75 @@ export const toggleDocumentStats = createAction({ }, }); +/** An example of the numbering each style produces, used to aid search. */ +const headingPrefixExamples: Record = { + [HeadingPrefixStyle.None]: "", + [HeadingPrefixStyle.Numeric]: "1.1.1", + [HeadingPrefixStyle.Alphanumeric]: "1.a.i", + [HeadingPrefixStyle.Outline]: "I.A.1", +}; + +const headingPrefixNames: Record string> = + { + [HeadingPrefixStyle.None]: (t) => t("None"), + [HeadingPrefixStyle.Numeric]: (t) => t("Multi-level decimal"), + [HeadingPrefixStyle.Alphanumeric]: (t) => t("Alphanumeric"), + [HeadingPrefixStyle.Outline]: (t) => t("Harvard"), + }; + +const changeHeadingPrefixFactory = (style: HeadingPrefixStyle) => + createAction({ + name: ({ t }) => headingPrefixNames[style](t), + // The example is displayed in the shortcut slot of menu items, but must + // not be set on the command bar action where shortcuts are registered as + // key sequences. + shortcut: ({ isMenu }) => + isMenu && headingPrefixExamples[style] + ? [headingPrefixExamples[style]] + : undefined, + keywords: headingPrefixExamples[style], + analyticsName: "Change heading numbering", + section: ActiveDocumentSection, + selected: ({ activeDocumentId, stores }) => { + const document = activeDocumentId + ? stores.documents.get(activeDocumentId) + : undefined; + return ( + (document?.getPreference(DocumentPreference.HeadingPrefix) ?? + HeadingPrefixStyle.None) === style + ); + }, + perform: async ({ activeDocumentId, stores }) => { + const document = activeDocumentId + ? stores.documents.get(activeDocumentId) + : undefined; + if (!document) { + return; + } + document.setPreference(DocumentPreference.HeadingPrefix, style); + await document.save(); + }, + }); + +export const changeHeadingPrefix = createActionWithChildren({ + name: ({ t }) => t("Heading numbering"), + analyticsName: "Change heading numbering", + section: ActiveDocumentSection, + icon: , + visible: ({ activeDocumentId, stores }) => { + const document = activeDocumentId + ? stores.documents.get(activeDocumentId) + : undefined; + + return ( + !!document && + !document.isDeleted && + stores.policies.abilities(document.id).update + ); + }, + children: Object.values(HeadingPrefixStyle).map(changeHeadingPrefixFactory), +}); + export const leaveDocument = createAction({ name: ({ t }) => t("Leave document"), analyticsName: "Leave document", @@ -1820,4 +1966,5 @@ export const rootDocumentActions = [ openDocumentInSplit, shareDocument, toggleDocumentStats, + changeHeadingPrefix, ]; diff --git a/app/actions/definitions/revisions.tsx b/app/actions/definitions/revisions.tsx index 96bff4050a..98b14fd1c8 100644 --- a/app/actions/definitions/revisions.tsx +++ b/app/actions/definitions/revisions.tsx @@ -94,7 +94,7 @@ export const deleteRevision = createAction({ dangerous: true, visible: ({ activeDocumentId }) => !!activeDocumentId && stores.policies.abilities(activeDocumentId).update, - perform: async ({ t, event, location, activeDocumentId }) => { + perform: async ({ t, event, location, activeDocumentId, sidebarContext }) => { event?.preventDefault(); if (!activeDocumentId) { return; @@ -113,7 +113,7 @@ export const deleteRevision = createAction({ const revision = stores.revisions.get(revisionId); await revision?.delete(); toast.success(t("This version of the document was deleted")); - history.push(documentHistoryPath(document)); + history.push(documentHistoryPath(document), { sidebarContext }); } }, }); diff --git a/app/actions/index.ts b/app/actions/index.ts index ac639fc003..13d83120cd 100644 --- a/app/actions/index.ts +++ b/app/actions/index.ts @@ -166,6 +166,7 @@ export function actionToMenuItem( const title = resolve(action.name, context); const visible = resolve(action.visible, context) ?? true; const disabled = resolve(action.disabled, context); + const shortcut = resolve(action.shortcut, context); const icon = !!action.icon && action.iconInContextMenu !== false ? resolve(action.icon, context) @@ -182,7 +183,7 @@ export function actionToMenuItem( tooltip: resolve(action.tooltip, context), selected: resolve(action.selected, context), dangerous: action.dangerous, - shortcut: action.shortcut, + shortcut, onClick: () => performAction(action, context), }; @@ -194,7 +195,7 @@ export function actionToMenuItem( icon, visible, disabled, - shortcut: action.shortcut, + shortcut, to, }; } @@ -206,7 +207,7 @@ export function actionToMenuItem( icon, visible, disabled, - shortcut: action.shortcut, + shortcut, href: action.target ? { url: action.url, target: action.target } : action.url, @@ -261,6 +262,7 @@ export function actionToKBar( } const name = resolve(action.name, context); + const shortcut = resolve(action.shortcut, context); const icon = resolve(action.icon, context); const badge = resolve(action.badge, context); const section = resolve(action.section, context); @@ -294,7 +296,7 @@ export function actionToKBar( name, section: sectionWithPriority, keywords: action.keywords, - shortcut: action.shortcut, + shortcut, subtitle, icon, badge, @@ -320,7 +322,7 @@ export function actionToKBar( name, section: sectionWithPriority, keywords: action.keywords, - shortcut: action.shortcut, + shortcut, icon, badge, subtitle, diff --git a/app/components/DocumentCard.tsx b/app/components/DocumentCard.tsx index 0ffbc4a869..c0b4143640 100644 --- a/app/components/DocumentCard.tsx +++ b/app/components/DocumentCard.tsx @@ -10,7 +10,7 @@ import { Link } from "react-router-dom"; import styled, { useTheme } from "styled-components"; import Icon from "@shared/components/Icon"; import Squircle from "@shared/components/Squircle"; -import { s, hover, ellipsis } from "@shared/styles"; +import { s, hover, ellipsis, borderRadius } from "@shared/styles"; import { IconType } from "@shared/types"; import { determineIconType } from "@shared/utils/icon"; import type Document from "~/models/Document"; @@ -20,6 +20,7 @@ import NudeButton from "~/components/NudeButton"; import Time from "~/components/Time"; import usePolicy from "~/hooks/usePolicy"; import useStores from "~/hooks/useStores"; +import { DocumentContextMenu } from "~/menus/DocumentContextMenu"; import CollectionIcon from "./Icons/CollectionIcon"; import Text from "./Text"; import Tooltip from "./Tooltip"; @@ -73,7 +74,7 @@ function DocumentCard(props: Props) { }; const handleUnpin = useCallback( - async (ev) => { + async (ev: React.MouseEvent) => { ev.preventDefault(); ev.stopPropagation(); await pin?.delete(); @@ -81,6 +82,12 @@ function DocumentCard(props: Props) { [pin] ); + // Keep the drag sensor from claiming the pointer, otherwise holding the + // button for longer than the activation delay starts a drag + const handleActionsPointerDown = useCallback((ev: React.PointerEvent) => { + ev.stopPropagation(); + }, []); + // If the document was updated within the last 7 days, show a timestamp instead of reading time const isRecentlyUpdated = new Date(document.updatedAt) > subDays(new Date(), 7); @@ -113,78 +120,84 @@ function DocumentCard(props: Props) { }} exit={{ opacity: 0, scale: 0.95 }} > - - - - - - - - {document.icon ? ( - - ) : ( - + + + - {collection?.icon && - collection?.icon !== "letter" && - collection?.icon !== "collection" && - pinnedToHome ? ( - - ) : ( - - )} - + + + + + {document.icon ? ( + + ) : ( + + {collection?.icon && + collection?.icon !== "letter" && + collection?.icon !== "collection" && + pinnedToHome ? ( + + ) : ( + + )} + + )} +
+ + {hasEmojiInTitle + ? document.titleWithDefault.replace(document.icon!, "") + : document.titleWithDefault} + + + {isRecentlyUpdated ? ( + updatedAt + ) : ( + + + + )} + +
+
+ {canUnpin && !isDragging && pin && ( + + + + + + + )} -
- - {hasEmojiInTitle - ? document.titleWithDefault.replace(document.icon!, "") - : document.titleWithDefault} - - - {isRecentlyUpdated ? ( - updatedAt - ) : ( - - - - )} - -
- - {canUnpin && !isDragging && pin && ( - - - - - - - - )} -
+ + ); @@ -292,7 +305,7 @@ const DocumentLink = styled(Link)<{ padding: 12px; width: 100%; height: 100%; - border-radius: 8px; + ${borderRadius(8)} cursor: var(--pointer); background: ${s("background")}; transition: transform 50ms ease-in-out; @@ -304,10 +317,13 @@ const DocumentLink = styled(Link)<{ opacity: 0; } + // data-state is set by the context menu trigger, so the treatment stays + // active while the menu is open &:${hover}, &:active, &:focus, - &:focus-within { + &:focus-within, + &[data-state="open"] { transform: ${(props) => (props.$isDragging ? "scale(1.1)" : "scale(1.08)")} rotate(-2deg); box-shadow: ${(props) => diff --git a/app/components/DocumentChip.tsx b/app/components/DocumentChip.tsx index 64409bac76..5c45fb46ae 100644 --- a/app/components/DocumentChip.tsx +++ b/app/components/DocumentChip.tsx @@ -1,5 +1,7 @@ import { observer } from "mobx-react"; -import { DocumentIcon } from "outline-icons"; +import { CloseIcon, DocumentIcon } from "outline-icons"; +import { useCallback } from "react"; +import { useTranslation } from "react-i18next"; import { Link } from "react-router-dom"; import styled from "styled-components"; import Icon from "@shared/components/Icon"; @@ -7,10 +9,17 @@ import { s, hover, ellipsis } from "@shared/styles"; import { IconType } from "@shared/types"; import { determineIconType } from "@shared/utils/icon"; import type Document from "~/models/Document"; +import type Pin from "~/models/Pin"; +import NudeButton from "~/components/NudeButton"; +import Tooltip from "~/components/Tooltip"; +import usePolicy from "~/hooks/usePolicy"; +import { DocumentContextMenu } from "~/menus/DocumentContextMenu"; type Props = { /** The document to display */ document: Document; + /** The pin related to the document, when given an unpin control is shown */ + pin?: Pin; }; /** @@ -19,32 +28,58 @@ type Props = { */ export const DocumentChip = observer(function DocumentChip_({ document, + pin, }: Props) { + const { t } = useTranslation(); const { icon, color } = document; + const canPin = usePolicy(pin); + const canDocument = usePolicy(document); const title = document.titleWithDefault; const isEmoji = determineIconType(icon) === IconType.Emoji; + // Pins in a collection are governed by the document policy, pins on home by + // the policy of the pin itself. + const canUnpin = pin?.collectionId ? canDocument.unpin : canPin.delete; + + const handleUnpin = useCallback( + async (ev: React.MouseEvent) => { + ev.preventDefault(); + ev.stopPropagation(); + await pin?.delete(); + }, + [pin] + ); + return ( - - {icon ? ( - - ) : ( - - )} - {isEmoji ? title.replace(icon!, "") : title} - + + + {icon ? ( + + ) : ( + + )} + {isEmoji ? title.replace(icon!, "") : title} + {pin && canUnpin && ( + + + + + + )} + + ); }); @@ -55,6 +90,20 @@ const Title = styled.span` color: ${s("text")}; `; +const PinButton = styled(NudeButton)` + width: 18px; + height: 18px; + flex-shrink: 0; + color: ${s("textTertiary")}; + opacity: 0; + transition: opacity 100ms ease-in-out; + + &:${hover}, + &:active { + color: ${s("text")}; + } +`; + const Chip = styled(Link)` display: flex; align-items: center; @@ -73,4 +122,9 @@ const Chip = styled(Link)` &:focus-visible { background: ${s("listItemHoverBackground")}; } + + &:${hover} ${PinButton}, + &:focus-within ${PinButton} { + opacity: 1; + } `; diff --git a/app/components/DocumentContext.tsx b/app/components/DocumentContext.tsx index a4ceea07ee..0722911c49 100644 --- a/app/components/DocumentContext.tsx +++ b/app/components/DocumentContext.tsx @@ -30,7 +30,8 @@ class DocumentContext { @computed get hasHeadings() { - return this.headings.length > 0; + // Headings inside tables are not listed in the table of contents. + return this.headings.some((heading) => !heading.inTable); } /** Statistics for the text content of the document, kept up to date as it is edited */ diff --git a/app/components/DocumentListItem.tsx b/app/components/DocumentListItem.tsx index c5243ff9b6..eb20ccc727 100644 --- a/app/components/DocumentListItem.tsx +++ b/app/components/DocumentListItem.tsx @@ -34,7 +34,7 @@ import { useDragDocument } from "./Sidebar/hooks/useDragAndDrop"; import { ActionContextProvider } from "~/hooks/useActionContext"; import { useDocumentMenuAction } from "~/hooks/useDocumentMenuAction"; import { ContextMenu } from "./Menu/ContextMenu"; -import useStores from "~/hooks/useStores"; +import { useDocumentActiveModels } from "~/hooks/useDocumentActiveModels"; type Props = { document: Document; @@ -60,7 +60,6 @@ function DocumentListItem( const { t } = useTranslation(); const user = useCurrentUser(); const theme = useTheme(); - const { userMemberships, groupMemberships } = useStores(); const locationSidebarContext = useLocationSidebarContext(); const [menuOpen, handleMenuOpen, handleMenuClose] = useBoolean(); const isMobile = useMobile(); @@ -122,10 +121,7 @@ function DocumentListItem( } }; - const isShared = !!( - userMemberships.getByDocumentId(document.id) || - groupMemberships.getByDocumentId(document.id) - ); + const activeModels = useDocumentActiveModels(document); const sidebarContext = determineSidebarContext({ document, @@ -153,14 +149,7 @@ function DocumentListItem( ); return ( - + = ({ } else if (deletedAt) { content = ( - {lastUpdatedByCurrentUser + {document.deletedBy?.id === user.id ? t("You deleted") - : t("{{ userName }} deleted", { userName })}{" "} + : t("{{ userName }} deleted", { + userName: document.deletedBy?.name ?? t("Unknown"), + })}{" "} ); @@ -227,42 +229,12 @@ const DocumentMeta: React.FC = ({ ); }; -/** A button that visually matches the surrounding meta text. */ -export const MetaButton = styled(NudeButton)` - display: inline-flex; - align-items: center; - gap: 2px; - width: auto; - height: auto; - border-radius: 0; - color: inherit; - font: inherit; - text-align: inherit; - - &:hover { - text-decoration: underline; - } -`; - -export const Separator = styled.span` - padding: 0 0.4em; - - &::after { - content: "•"; - } -`; - const Strong = styled.strong` font-weight: 550; `; const Container = styled(Flex)<{ $rtl?: boolean }>` - justify-content: ${(props) => (props.$rtl ? "flex-end" : "flex-start")}; - color: ${s("textTertiary")}; - font-size: 13px; - white-space: nowrap; - overflow: hidden; - min-width: 0; + ${metaStyles} `; const Viewed = styled.span` diff --git a/app/components/Editor.tsx b/app/components/Editor.tsx index b9b523cc4b..46353cb49a 100644 --- a/app/components/Editor.tsx +++ b/app/components/Editor.tsx @@ -1,22 +1,16 @@ import { difference } from "es-toolkit/compat"; import { observer } from "mobx-react"; -import { DOMParser as ProsemirrorDOMParser } from "prosemirror-model"; -import { TextSelection } from "prosemirror-state"; import * as React from "react"; import { useTranslation } from "react-i18next"; import { toast } from "sonner"; import { mergeRefs } from "react-merge-refs"; import type { Optional } from "utility-types"; -import insertFiles from "@shared/editor/commands/insertFiles"; import EditorContainer from "@shared/editor/components/Styles"; import { AttachmentPreset } from "@shared/types"; import { ProsemirrorHelper } from "@shared/utils/ProsemirrorHelper"; -import { getDataTransferFiles } from "@shared/utils/files"; -import { AttachmentValidation } from "@shared/validations"; import ClickablePadding from "~/components/ClickablePadding"; import ErrorBoundary from "~/components/ErrorBoundary"; import type { Props as EditorProps, Editor as SharedEditor } from "~/editor"; -import { toastNotice } from "~/editor/toastNotice"; import useCurrentUser from "~/hooks/useCurrentUser"; import useEditorClickHandlers from "~/hooks/useEditorClickHandlers"; import useEmbeds from "~/hooks/useEmbeds"; @@ -135,61 +129,9 @@ function Editor(props: Props, ref: React.RefObject | null) { }, [localRef]); const handleDrop = React.useCallback( - (event: React.DragEvent) => { - event.preventDefault(); - event.stopPropagation(); - const files = getDataTransferFiles(event); - - const view = localRef?.current?.view; - if (!view) { - return; - } - - // Find a valid position at the end of the document to insert our content - const pos = TextSelection.near( - view.state.doc.resolve(view.state.doc.nodeSize - 2) - ).from; - - // If there are no files in the drop event attempt to parse the html - // as a fragment and insert it at the end of the document - if (files.length === 0) { - const text = - event.dataTransfer.getData("text/html") || - event.dataTransfer.getData("text/plain"); - - const dom = new DOMParser().parseFromString(text, "text/html"); - - view.dispatch( - view.state.tr.insert( - pos, - ProsemirrorDOMParser.fromSchema(view.state.schema).parse(dom) - ) - ); - - return; - } - - // Insert all files as attachments if any of the files are not images. - const isAttachment = files.some( - (file) => !AttachmentValidation.imageContentTypes.includes(file.type) - ); - - return insertFiles(view, event, pos, files, { - uploadFile: handleUploadFile, - onFileUploadStart: handleFileUploadStart, - onFileUploadStop: handleFileUploadStop, - onFileUploadProgress: handleFileUploadProgress, - onNotice: toastNotice, - isAttachment, - }); - }, - [ - localRef, - handleFileUploadStart, - handleFileUploadStop, - handleFileUploadProgress, - handleUploadFile, - ] + (event: React.DragEvent) => + localRef.current?.insertDroppedContent(event), + [] ); // see: https://stackoverflow.com/a/50233827/192065 diff --git a/app/components/EditorAwareHTML5Backend.ts b/app/components/EditorAwareHTML5Backend.ts index 3322d22a19..b1924052d4 100644 --- a/app/components/EditorAwareHTML5Backend.ts +++ b/app/components/EditorAwareHTML5Backend.ts @@ -29,6 +29,14 @@ const topHandlerNames = [ const isWithinEditor = (target: EventTarget | null): boolean => target instanceof Element && Boolean(target.closest(".ProseMirror")); +// A file dragged over an element marked `data-drop-area`, which accepts native +// file drops itself. react-dnd never tracks these drags, so its handlers would +// otherwise reject them. +const isFileOverDropArea = (event: DragEvent): boolean => + Boolean(event.dataTransfer?.types.includes("Files")) && + event.target instanceof Element && + Boolean(event.target.closest("[data-drop-area]")); + /** * An HTML5 drag-and-drop backend that ignores drag events originating within the * rich text editor so that ProseMirror can handle them itself. @@ -57,7 +65,7 @@ export const EditorAwareHTML5Backend: BackendFactory = ( const original = handlers[name]; if (typeof original === "function") { handlers[name] = (event: DragEvent) => { - if (isWithinEditor(event.target)) { + if (isWithinEditor(event.target) || isFileOverDropArea(event)) { return; } // A drag that began or entered the page over the editor is never diff --git a/app/components/HeaderMeta.tsx b/app/components/HeaderMeta.tsx new file mode 100644 index 0000000000..68cd6c6484 --- /dev/null +++ b/app/components/HeaderMeta.tsx @@ -0,0 +1,86 @@ +import styled, { css } from "styled-components"; +import breakpoint from "styled-components-breakpoint"; +import { s } from "@shared/styles"; +import Flex from "~/components/Flex"; +import NudeButton from "~/components/NudeButton"; + +/** A dot separating two pieces of meta information. */ +export const Separator = styled.span` + padding: 0 0.4em; + + &::after { + content: "•"; + } +`; + +/** A button that visually matches the surrounding meta text. */ +export const MetaButton = styled(NudeButton)` + display: inline-flex; + align-items: center; + gap: 2px; + width: auto; + height: auto; + border-radius: 0; + color: inherit; + font: inherit; + text-align: inherit; + + &:hover { + text-decoration: underline; + } +`; + +/** Lays out a line of meta information about a document or collection. */ +export const metaStyles = css<{ $rtl?: boolean }>` + justify-content: ${(props) => (props.$rtl ? "flex-end" : "flex-start")}; + color: ${s("textTertiary")}; + font-size: 13px; + white-space: nowrap; + overflow: hidden; + min-width: 0; +`; + +/** + * Additional styles for a line of meta information rendered directly beneath a + * page title. Composed by `HeaderMeta`, and applied directly by consumers that + * style an existing meta component rather than rendering their own. + */ +export const headerMetaStyles = css` + margin: -12px 0 2em 0; + font-size: 14px; + position: relative; + user-select: none; + z-index: 1; + + ${breakpoint("mobile", "tablet")` + flex-direction: column; + align-items: flex-start; + line-height: 1.6; + + ${Separator} { + display: none; + } + `} + + a { + color: inherit; + cursor: var(--pointer); + + &:hover { + text-decoration: underline; + } + } + + @media print { + display: none; + } +`; + +/** + * A line of meta information rendered directly beneath a page title, stacking + * into a list on mobile and hidden when printing. + */ +export const HeaderMeta = styled(Flex)<{ $rtl?: boolean }>` + ${metaStyles} + ${headerMetaStyles} +`; diff --git a/app/components/Menu/ContextMenu.tsx b/app/components/Menu/ContextMenu.tsx index 070034a3c9..e9f734b4be 100644 --- a/app/components/Menu/ContextMenu.tsx +++ b/app/components/Menu/ContextMenu.tsx @@ -91,7 +91,7 @@ export const ContextMenu = observer( return ( - {children} + {children} ` const Background = styled(Flex)` background-color: ${s("menuBackground")}; box-shadow: ${s("menuShadow")}; - border-radius: 8px; + ${borderRadius(8)} height: 40px; padding: 0 8px; `; diff --git a/app/components/PinnedDocuments.tsx b/app/components/PinnedDocuments.tsx index 36b73e1bd8..79532148c7 100644 --- a/app/components/PinnedDocuments.tsx +++ b/app/components/PinnedDocuments.tsx @@ -149,8 +149,10 @@ function PinnedDocuments({ {items.map((documentId) => { const document = documents.get(documentId); + const pin = pins.find((p) => p.documentId === documentId); + return document ? ( - + ) : null; })} diff --git a/app/components/Sidebar/App.tsx b/app/components/Sidebar/App.tsx index 217d62e935..fb542f6fc8 100644 --- a/app/components/Sidebar/App.tsx +++ b/app/components/Sidebar/App.tsx @@ -8,6 +8,7 @@ import { import { useTranslation } from "react-i18next"; import { useHistory } from "react-router-dom"; import styled from "styled-components"; +import { SidebarSection, UserPreference } from "@shared/types"; import { metaDisplay } from "@shared/utils/keyboard"; import Scrollable from "~/components/Scrollable"; import { navigateToImport } from "~/actions/definitions/navigation"; @@ -24,6 +25,9 @@ import Tooltip from "../Tooltip"; import Sidebar from "./Sidebar"; import ArchiveLink from "./components/ArchiveLink"; import Collections from "./components/Collections"; +import DraggableSection, { + normalizeSidebarSectionOrder, +} from "./components/DraggableSection"; import { DraftsLink } from "./components/DraftsLink"; import DragPlaceholder from "./components/DragPlaceholder"; import { DismissableSidebarAction } from "./components/DismissableSidebarAction"; @@ -72,6 +76,16 @@ function AppSidebar() { setScrollArea(scrollRef.current); }, []); + const sectionOrder = normalizeSidebarSectionOrder( + user.getPreference(UserPreference.SidebarSectionOrder, []) + ); + + const sectionContent = { + [SidebarSection.Starred]: , + [SidebarSection.SharedWithMe]: , + [SidebarSection.Collections]: , + }; + return (