mirror of
https://github.com/outline/outline.git
synced 2026-11-22 22:02:35 +03:00
Merge public/main
This commit is contained in:
commit
4648a405bb
313 files changed
+7596
-3097
No files matched your search
@@ -3,7 +3,7 @@ Business Source License 1.1
|
||||
Parameters
|
||||
|
||||
Licensor: General Outline, Inc.
|
||||
Licensed Work: Outline 0.80.2
|
||||
Licensed Work: Outline 0.81.0
|
||||
The Licensed Work is (c) 2024 General Outline, Inc.
|
||||
Additional Use Grant: You may make use of the Licensed Work, provided that
|
||||
you may not use the Licensed Work for a Document
|
||||
@@ -15,7 +15,7 @@ Additional Use Grant: You may make use of the Licensed Work, provided that
|
||||
Licensed Work by creating teams and documents
|
||||
controlled by such third parties.
|
||||
|
||||
Change Date: 2028-09-26
|
||||
Change Date: 2028-11-11
|
||||
|
||||
Change License: Apache License, Version 2.0
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { DoneIcon, TrashIcon } from "outline-icons";
|
||||
import { DoneIcon, SmileyIcon, TrashIcon } from "outline-icons";
|
||||
import * as React from "react";
|
||||
import { toast } from "sonner";
|
||||
import stores from "~/stores";
|
||||
import Comment from "~/models/Comment";
|
||||
import CommentDeleteDialog from "~/components/CommentDeleteDialog";
|
||||
import ViewReactionsDialog from "~/components/Reactions/ViewReactionsDialog";
|
||||
import history from "~/utils/history";
|
||||
import { createAction } from "..";
|
||||
import { DocumentSection } from "../sections";
|
||||
@@ -88,3 +89,27 @@ export const unresolveCommentFactory = ({
|
||||
onUnresolve();
|
||||
},
|
||||
});
|
||||
|
||||
export const viewCommentReactionsFactory = ({
|
||||
comment,
|
||||
}: {
|
||||
comment: Comment;
|
||||
}) =>
|
||||
createAction({
|
||||
name: ({ t }) => `${t("View reactions")}`,
|
||||
analyticsName: "View comment reactions",
|
||||
section: DocumentSection,
|
||||
icon: <SmileyIcon />,
|
||||
visible: () =>
|
||||
stores.policies.abilities(comment.id).read &&
|
||||
comment.reactions.length > 0,
|
||||
perform: ({ t, event }) => {
|
||||
event?.preventDefault();
|
||||
event?.stopPropagation();
|
||||
|
||||
stores.dialogs.openModal({
|
||||
title: t("Reactions"),
|
||||
content: <ViewReactionsDialog model={comment} />,
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -28,6 +28,7 @@ import {
|
||||
EyeIcon,
|
||||
PadlockIcon,
|
||||
GlobeIcon,
|
||||
LogoutIcon,
|
||||
} from "outline-icons";
|
||||
import * as React from "react";
|
||||
import { toast } from "sonner";
|
||||
@@ -37,6 +38,7 @@ import {
|
||||
NavigationNode,
|
||||
} from "@shared/types";
|
||||
import { getEventFiles } from "@shared/utils/files";
|
||||
import UserMembership from "~/models/UserMembership";
|
||||
import DocumentDelete from "~/scenes/DocumentDelete";
|
||||
import DocumentMove from "~/scenes/DocumentMove";
|
||||
import DocumentPermanentDelete from "~/scenes/DocumentPermanentDelete";
|
||||
@@ -129,11 +131,30 @@ export const createDocumentFromTemplate = createAction({
|
||||
section: DocumentSection,
|
||||
icon: <NewDocumentIcon />,
|
||||
keywords: "create",
|
||||
visible: ({ currentTeamId, activeDocumentId, stores }) =>
|
||||
!!currentTeamId &&
|
||||
!!activeDocumentId &&
|
||||
!!stores.documents.get(activeDocumentId)?.template &&
|
||||
stores.policies.abilities(currentTeamId).createDocument,
|
||||
visible: ({
|
||||
currentTeamId,
|
||||
activeCollectionId,
|
||||
activeDocumentId,
|
||||
stores,
|
||||
}) => {
|
||||
const document = activeDocumentId
|
||||
? stores.documents.get(activeDocumentId)
|
||||
: undefined;
|
||||
|
||||
if (
|
||||
!currentTeamId ||
|
||||
!document?.isTemplate ||
|
||||
!!document?.isDraft ||
|
||||
!!document?.isDeleted
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (activeCollectionId) {
|
||||
return stores.policies.abilities(activeCollectionId).createDocument;
|
||||
}
|
||||
return stores.policies.abilities(currentTeamId).createDocument;
|
||||
},
|
||||
perform: ({ activeCollectionId, activeDocumentId, sidebarContext }) =>
|
||||
history.push(
|
||||
newDocumentPath(activeCollectionId, { templateId: activeDocumentId }),
|
||||
@@ -1119,6 +1140,42 @@ export const toggleViewerInsights = createAction({
|
||||
},
|
||||
});
|
||||
|
||||
export const leaveDocument = createAction({
|
||||
name: ({ t }) => t("Leave document"),
|
||||
analyticsName: "Leave document",
|
||||
section: ActiveDocumentSection,
|
||||
icon: <LogoutIcon />,
|
||||
visible: ({ currentUserId, activeDocumentId, stores }) => {
|
||||
const membership = stores.userMemberships.orderedData.find(
|
||||
(m) => m.documentId === activeDocumentId && m.userId === currentUserId
|
||||
);
|
||||
|
||||
return !!membership;
|
||||
},
|
||||
perform: async ({ t, location, currentUserId, activeDocumentId, stores }) => {
|
||||
if (!activeDocumentId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const document = stores.documents.get(activeDocumentId);
|
||||
|
||||
try {
|
||||
if (document && location.pathname.startsWith(document.path)) {
|
||||
history.push(homePath());
|
||||
}
|
||||
|
||||
await stores.userMemberships.delete({
|
||||
documentId: activeDocumentId,
|
||||
userId: currentUserId,
|
||||
} as UserMembership);
|
||||
|
||||
toast.success(t("You have left the shared document"));
|
||||
} catch (err) {
|
||||
toast.error(t("Could not leave document"));
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export const rootDocumentActions = [
|
||||
openDocument,
|
||||
archiveDocument,
|
||||
@@ -1137,6 +1194,7 @@ export const rootDocumentActions = [
|
||||
subscribeDocument,
|
||||
unsubscribeDocument,
|
||||
duplicateDocument,
|
||||
leaveDocument,
|
||||
moveTemplateToWorkspace,
|
||||
moveDocumentToCollection,
|
||||
openRandomDocument,
|
||||
|
||||
@@ -91,6 +91,15 @@ export const navigateToSettings = createAction({
|
||||
perform: () => history.push(settingsPath()),
|
||||
});
|
||||
|
||||
export const navigateToWorkspaceSettings = createAction({
|
||||
name: ({ t }) => t("Settings"),
|
||||
analyticsName: "Navigate to workspace settings",
|
||||
section: NavigationSection,
|
||||
icon: <SettingsIcon />,
|
||||
visible: () => stores.policies.abilities(stores.auth.team?.id || "").update,
|
||||
perform: () => history.push(settingsPath("details")),
|
||||
});
|
||||
|
||||
export const navigateToProfileSettings = createAction({
|
||||
name: ({ t }) => t("Profile"),
|
||||
analyticsName: "Navigate to profile settings",
|
||||
|
||||
@@ -226,7 +226,7 @@ const Input = styled.div`
|
||||
}
|
||||
|
||||
&[data-editing="true"] {
|
||||
background: ${s("secondaryBackground")};
|
||||
background: ${s("backgroundSecondary")};
|
||||
}
|
||||
|
||||
.block-menu-trigger,
|
||||
|
||||
@@ -2,7 +2,11 @@ import { NewDocumentIcon, ShapesIcon } from "outline-icons";
|
||||
import * as React from "react";
|
||||
import Icon from "~/components/Icon";
|
||||
import { createAction } from "~/actions";
|
||||
import { DocumentSection } from "~/actions/sections";
|
||||
import {
|
||||
ActiveCollectionSection,
|
||||
DocumentSection,
|
||||
TeamSection,
|
||||
} from "~/actions/sections";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import history from "~/utils/history";
|
||||
import { newDocumentPath } from "~/utils/routeHelpers";
|
||||
@@ -11,26 +15,42 @@ const useTemplatesAction = () => {
|
||||
const { documents } = useStores();
|
||||
|
||||
React.useEffect(() => {
|
||||
void documents.fetchTemplates();
|
||||
void documents.fetchAllTemplates();
|
||||
}, [documents]);
|
||||
|
||||
const actions = React.useMemo(
|
||||
() =>
|
||||
documents.templatesAlphabetical.map((item) =>
|
||||
documents.templatesAlphabetical.map((template) =>
|
||||
createAction({
|
||||
name: item.titleWithDefault,
|
||||
name: template.titleWithDefault,
|
||||
analyticsName: "New document",
|
||||
section: DocumentSection,
|
||||
icon: item.icon ? (
|
||||
<Icon value={item.icon} color={item.color ?? undefined} />
|
||||
section: template.isWorkspaceTemplate
|
||||
? TeamSection
|
||||
: ActiveCollectionSection,
|
||||
icon: template.icon ? (
|
||||
<Icon value={template.icon} color={template.color ?? undefined} />
|
||||
) : (
|
||||
<NewDocumentIcon />
|
||||
),
|
||||
keywords: "create",
|
||||
visible: ({ currentTeamId, activeCollectionId, stores }) => {
|
||||
if (activeCollectionId) {
|
||||
return (
|
||||
stores.policies.abilities(activeCollectionId).createDocument &&
|
||||
(template.collectionId === activeCollectionId ||
|
||||
template.isWorkspaceTemplate)
|
||||
);
|
||||
}
|
||||
return (
|
||||
!!currentTeamId &&
|
||||
stores.policies.abilities(currentTeamId).createDocument &&
|
||||
template.isWorkspaceTemplate
|
||||
);
|
||||
},
|
||||
perform: ({ activeCollectionId, sidebarContext }) =>
|
||||
history.push(
|
||||
newDocumentPath(item.collectionId ?? activeCollectionId, {
|
||||
templateId: item.id,
|
||||
newDocumentPath(template.collectionId ?? activeCollectionId, {
|
||||
templateId: template.id,
|
||||
}),
|
||||
{
|
||||
sidebarContext,
|
||||
@@ -49,9 +69,15 @@ const useTemplatesAction = () => {
|
||||
placeholder: ({ t }) => t("Choose a template"),
|
||||
section: DocumentSection,
|
||||
icon: <ShapesIcon />,
|
||||
visible: ({ currentTeamId, stores }) =>
|
||||
!!currentTeamId &&
|
||||
stores.policies.abilities(currentTeamId).createDocument,
|
||||
visible: ({ currentTeamId, activeCollectionId, stores }) => {
|
||||
if (activeCollectionId) {
|
||||
return stores.policies.abilities(activeCollectionId).createDocument;
|
||||
}
|
||||
return (
|
||||
!!currentTeamId &&
|
||||
stores.policies.abilities(currentTeamId).createDocument
|
||||
);
|
||||
},
|
||||
children: () => actions,
|
||||
}),
|
||||
[actions]
|
||||
|
||||
@@ -11,6 +11,9 @@ class DocumentContext {
|
||||
/** The editor instance for this document */
|
||||
editor?: Editor;
|
||||
|
||||
@observable
|
||||
isEditorInitialized: boolean = false;
|
||||
|
||||
@observable
|
||||
headings: Heading[] = [];
|
||||
|
||||
@@ -31,6 +34,11 @@ class DocumentContext {
|
||||
this.updateState();
|
||||
};
|
||||
|
||||
@action
|
||||
setEditorInitialized = (initialized: boolean) => {
|
||||
this.isEditorInitialized = initialized;
|
||||
};
|
||||
|
||||
@action
|
||||
updateState = () => {
|
||||
this.updateHeadings();
|
||||
|
||||
@@ -98,7 +98,7 @@ function Editor(props: Props, ref: React.RefObject<SharedEditor> | null) {
|
||||
}
|
||||
|
||||
// default search for anything that doesn't look like a URL
|
||||
const results = await documents.searchTitles(term);
|
||||
const results = await documents.searchTitles({ query: term });
|
||||
|
||||
return sortBy(
|
||||
results.map(({ document }) => ({
|
||||
@@ -255,6 +255,7 @@ function Editor(props: Props, ref: React.RefObject<SharedEditor> | null) {
|
||||
<ErrorBoundary component="div" reloadOnChunkMissing>
|
||||
<>
|
||||
<LazyLoadedEditor
|
||||
key={props.extensions?.length || 0}
|
||||
ref={mergeRefs([ref, localRef, handleRefChanged])}
|
||||
uploadFile={handleUploadFile}
|
||||
embeds={embeds}
|
||||
@@ -267,14 +268,15 @@ function Editor(props: Props, ref: React.RefObject<SharedEditor> | null) {
|
||||
placeholder={props.placeholder || ""}
|
||||
defaultValue={props.defaultValue || ""}
|
||||
/>
|
||||
{props.editorStyle?.paddingBottom && !props.readOnly && (
|
||||
<ClickablePadding
|
||||
onClick={focusAtEnd}
|
||||
onDrop={handleDrop}
|
||||
onDragOver={handleDragOver}
|
||||
minHeight={props.editorStyle.paddingBottom}
|
||||
/>
|
||||
)}
|
||||
{props.editorStyle?.paddingBottom &&
|
||||
(!props.readOnly || props.shareId) && (
|
||||
<ClickablePadding
|
||||
onClick={props.readOnly ? undefined : focusAtEnd}
|
||||
onDrop={props.readOnly ? undefined : handleDrop}
|
||||
onDragOver={props.readOnly ? undefined : handleDragOver}
|
||||
minHeight={props.editorStyle.paddingBottom}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
</ErrorBoundary>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import styled from "styled-components";
|
||||
import { s } from "@shared/styles";
|
||||
|
||||
type Props = {
|
||||
/** Width of the containing element. */
|
||||
width?: number | string;
|
||||
/** Height of the containing element. */
|
||||
height?: number | string;
|
||||
/** Controls the rendered emoji size. */
|
||||
size?: number;
|
||||
};
|
||||
|
||||
export const Emoji = styled.span<Props>`
|
||||
font-family: ${s("fontFamilyEmoji")};
|
||||
width: ${({ width }) =>
|
||||
typeof width === "string" ? width : width ? `${width}px` : "auto"};
|
||||
height: ${({ height }) =>
|
||||
typeof height === "string" ? height : height ? `${height}px` : "auto"};
|
||||
font-size: ${({ size }) => size && `${size}px`};
|
||||
`;
|
||||
@@ -138,7 +138,7 @@ class ErrorBoundary extends React.Component<Props> {
|
||||
}
|
||||
|
||||
const Pre = styled.pre`
|
||||
background: ${s("secondaryBackground")};
|
||||
background: ${s("backgroundSecondary")};
|
||||
padding: 16px;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
|
||||
@@ -27,7 +27,7 @@ import { documentHistoryPath } from "~/utils/routeHelpers";
|
||||
|
||||
type Props = {
|
||||
document: Document;
|
||||
event: Event;
|
||||
event: Event<Document>;
|
||||
latest?: boolean;
|
||||
};
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ const Image = styled(Flex)`
|
||||
justify-content: center;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
background: ${s("secondaryBackground")};
|
||||
background: ${s("backgroundSecondary")};
|
||||
border-radius: 32px;
|
||||
`;
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ import useStores from "~/hooks/useStores";
|
||||
import { draggableOnDesktop, fadeOnDesktopBackgrounded } from "~/styles";
|
||||
import Desktop from "~/utils/Desktop";
|
||||
|
||||
export const HEADER_HEIGHT = 64;
|
||||
|
||||
type Props = {
|
||||
left?: React.ReactNode;
|
||||
title: React.ReactNode;
|
||||
@@ -130,7 +132,7 @@ const Wrapper = styled(Flex)<WrapperProps>`
|
||||
padding: 12px;
|
||||
transition: all 100ms ease-out;
|
||||
transform: translate3d(0, 0, 0);
|
||||
min-height: 64px;
|
||||
min-height: ${HEADER_HEIGHT}px;
|
||||
justify-content: flex-start;
|
||||
${draggableOnDesktop()}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ export const Label = styled(Text).attrs({ size: "xsmall", weight: "bold" })<{
|
||||
color?: string;
|
||||
}>`
|
||||
background-color: ${(props) =>
|
||||
props.color ?? props.theme.secondaryBackground};
|
||||
props.color ?? props.theme.backgroundSecondary};
|
||||
color: ${(props) =>
|
||||
props.color ? getTextColor(props.color) : props.theme.text};
|
||||
width: fit-content;
|
||||
|
||||
@@ -125,6 +125,7 @@ function HoverPreviewDesktop({ element, data, dataLoading, onClose }: Props) {
|
||||
avatarUrl={data.avatarUrl}
|
||||
color={data.color}
|
||||
lastActive={data.lastActive}
|
||||
email={data.email}
|
||||
/>
|
||||
) : data.type === UnfurlResourceType.Document ? (
|
||||
<HoverPreviewDocument
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Preview, Title, Info, Card, CardContent } from "./Components";
|
||||
type Props = Omit<UnfurlResponse[UnfurlResourceType.Mention], "type">;
|
||||
|
||||
const HoverPreviewMention = React.forwardRef(function _HoverPreviewMention(
|
||||
{ avatarUrl, name, lastActive, color }: Props,
|
||||
{ avatarUrl, name, lastActive, color, email }: Props,
|
||||
ref: React.Ref<HTMLDivElement>
|
||||
) {
|
||||
return (
|
||||
@@ -25,6 +25,7 @@ const HoverPreviewMention = React.forwardRef(function _HoverPreviewMention(
|
||||
/>
|
||||
<Flex column gap={2} justify="center">
|
||||
<Title>{name}</Title>
|
||||
{email && <Info>{email}</Info>}
|
||||
<Info>{lastActive}</Info>
|
||||
</Flex>
|
||||
</Flex>
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
import styled from "styled-components";
|
||||
import { s } from "@shared/styles";
|
||||
|
||||
export const Emoji = styled.span`
|
||||
font-family: ${s("fontFamilyEmoji")};
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
`;
|
||||
@@ -18,11 +18,7 @@ import {
|
||||
import GridTemplate, { DataNode } from "./GridTemplate";
|
||||
import SkinTonePicker from "./SkinTonePicker";
|
||||
|
||||
/**
|
||||
* This is needed as a constant for react-window.
|
||||
* Calculated from the heights of TabPanel and InputSearch.
|
||||
*/
|
||||
const GRID_HEIGHT = 362;
|
||||
const GRID_HEIGHT = 410;
|
||||
|
||||
const useEmojiState = () => {
|
||||
const [emojiSkinTone, setEmojiSkinTone] = usePersistedState<EmojiSkinTone>(
|
||||
@@ -80,6 +76,7 @@ type Props = {
|
||||
panelWidth: number;
|
||||
query: string;
|
||||
panelActive: boolean;
|
||||
height?: number;
|
||||
onEmojiChange: (emoji: string) => void;
|
||||
onQueryChange: (query: string) => void;
|
||||
};
|
||||
@@ -90,6 +87,7 @@ const EmojiPanel = ({
|
||||
panelActive,
|
||||
onEmojiChange,
|
||||
onQueryChange,
|
||||
height = GRID_HEIGHT,
|
||||
}: Props) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
@@ -159,7 +157,7 @@ const EmojiPanel = ({
|
||||
<GridTemplate
|
||||
ref={scrollableRef}
|
||||
width={panelWidth}
|
||||
height={GRID_HEIGHT}
|
||||
height={height - 48}
|
||||
data={templateData}
|
||||
onIconSelect={handleEmojiSelection}
|
||||
/>
|
||||
|
||||
@@ -4,9 +4,9 @@ import React from "react";
|
||||
import styled from "styled-components";
|
||||
import { IconType } from "@shared/types";
|
||||
import { IconLibrary } from "@shared/utils/IconLibrary";
|
||||
import { Emoji } from "~/components/Emoji";
|
||||
import Text from "~/components/Text";
|
||||
import { TRANSLATED_CATEGORIES } from "../utils";
|
||||
import { Emoji } from "./Emoji";
|
||||
import Grid from "./Grid";
|
||||
import { IconButton } from "./IconButton";
|
||||
|
||||
@@ -85,7 +85,9 @@ const GridTemplate = (
|
||||
key={item.id}
|
||||
onClick={() => onIconSelect({ id: item.id, value: item.value })}
|
||||
>
|
||||
<Emoji>{item.value}</Emoji>
|
||||
<Emoji width={24} height={24}>
|
||||
{item.value}
|
||||
</Emoji>
|
||||
</IconButton>
|
||||
);
|
||||
});
|
||||
|
||||
@@ -5,10 +5,10 @@ import styled from "styled-components";
|
||||
import { depths, s } from "@shared/styles";
|
||||
import { EmojiSkinTone } from "@shared/types";
|
||||
import { getEmojiVariants } from "@shared/utils/emoji";
|
||||
import { Emoji } from "~/components/Emoji";
|
||||
import Flex from "~/components/Flex";
|
||||
import NudeButton from "~/components/NudeButton";
|
||||
import { hover } from "~/styles";
|
||||
import { Emoji } from "./Emoji";
|
||||
import { IconButton } from "./IconButton";
|
||||
|
||||
const SkinTonePicker = ({
|
||||
@@ -26,7 +26,7 @@ const SkinTonePicker = ({
|
||||
);
|
||||
|
||||
const menu = useMenuState({
|
||||
placement: "bottom",
|
||||
placement: "bottom-end",
|
||||
});
|
||||
|
||||
const handleSkinClick = React.useCallback(
|
||||
@@ -43,7 +43,9 @@ const SkinTonePicker = ({
|
||||
<MenuItem {...menu} key={emoji.value}>
|
||||
{(menuprops) => (
|
||||
<IconButton {...menuprops} onClick={() => handleSkinClick(eskin)}>
|
||||
<Emoji>{emoji.value}</Emoji>
|
||||
<Emoji width={24} height={24}>
|
||||
{emoji.value}
|
||||
</Emoji>
|
||||
</IconButton>
|
||||
)}
|
||||
</MenuItem>
|
||||
|
||||
@@ -82,6 +82,7 @@ const IconPicker = ({
|
||||
modal: true,
|
||||
unstable_offset: [0, 0],
|
||||
});
|
||||
const { hide, show, visible } = popover;
|
||||
const tab = useTabState({ selectedId: defaultTab });
|
||||
const previouslyVisible = usePrevious(popover.visible);
|
||||
|
||||
@@ -96,12 +97,12 @@ const IconPicker = ({
|
||||
|
||||
const handleIconChange = React.useCallback(
|
||||
(ic: string) => {
|
||||
popover.hide();
|
||||
hide();
|
||||
const icType = determineIconType(ic);
|
||||
const finalColor = icType === IconType.SVG ? chosenColor : null;
|
||||
onChange(ic, finalColor);
|
||||
},
|
||||
[popover, onChange, chosenColor]
|
||||
[hide, onChange, chosenColor]
|
||||
);
|
||||
|
||||
const handleIconColorChange = React.useCallback(
|
||||
@@ -118,32 +119,32 @@ const IconPicker = ({
|
||||
);
|
||||
|
||||
const handleIconRemove = React.useCallback(() => {
|
||||
popover.hide();
|
||||
hide();
|
||||
onChange(null, null);
|
||||
}, [popover, onChange]);
|
||||
}, [hide, onChange]);
|
||||
|
||||
const handlePopoverButtonClick = React.useCallback(
|
||||
(ev: React.MouseEvent) => {
|
||||
ev.stopPropagation();
|
||||
if (popover.visible) {
|
||||
popover.hide();
|
||||
if (visible) {
|
||||
hide();
|
||||
} else {
|
||||
popover.show();
|
||||
show();
|
||||
}
|
||||
},
|
||||
[popover]
|
||||
[hide, show, visible]
|
||||
);
|
||||
|
||||
// Popover open effect
|
||||
React.useEffect(() => {
|
||||
if (popover.visible && !previouslyVisible) {
|
||||
if (visible && !previouslyVisible) {
|
||||
onOpen?.();
|
||||
} else if (!popover.visible && previouslyVisible) {
|
||||
} else if (!visible && previouslyVisible) {
|
||||
onClose?.();
|
||||
setQuery("");
|
||||
resetDefaultTab();
|
||||
}
|
||||
}, [popover.visible, previouslyVisible, onOpen, onClose, resetDefaultTab]);
|
||||
}, [visible, previouslyVisible, onOpen, onClose, resetDefaultTab]);
|
||||
|
||||
// Custom click outside handling rather than using `hideOnClickOutside` from reakit so that we can
|
||||
// prevent event bubbling.
|
||||
|
||||
@@ -10,7 +10,7 @@ import * as React from "react";
|
||||
import { VisuallyHidden } from "reakit/VisuallyHidden";
|
||||
import styled, { css } from "styled-components";
|
||||
import { s } from "@shared/styles";
|
||||
import Button, { Inner } from "~/components/Button";
|
||||
import Button, { Props as ButtonProps, Inner } from "~/components/Button";
|
||||
import Text from "~/components/Text";
|
||||
import useMenuHeight from "~/hooks/useMenuHeight";
|
||||
import useMobile from "~/hooks/useMobile";
|
||||
@@ -33,7 +33,7 @@ export type Option = {
|
||||
divider?: boolean;
|
||||
};
|
||||
|
||||
export type Props = {
|
||||
export type Props = Omit<ButtonProps<any>, "onChange"> & {
|
||||
id?: string;
|
||||
name?: string;
|
||||
value?: string | null;
|
||||
@@ -313,7 +313,7 @@ const StyledButton = styled(Button)<{ $nude?: boolean }>`
|
||||
margin-bottom: 16px;
|
||||
display: block;
|
||||
width: 100%;
|
||||
cursor: default;
|
||||
cursor: var(--pointer);
|
||||
|
||||
&:hover:not(:disabled) {
|
||||
background: ${s("buttonNeutralBackground")};
|
||||
|
||||
@@ -192,7 +192,7 @@ const Wrapper = styled.a<{
|
||||
&:focus,
|
||||
&:focus-within {
|
||||
background: ${(props) =>
|
||||
props.$hover ? props.theme.secondaryBackground : "inherit"};
|
||||
props.$hover ? props.theme.backgroundSecondary : "inherit"};
|
||||
}
|
||||
|
||||
cursor: ${(props) =>
|
||||
|
||||
@@ -24,13 +24,15 @@ import NotificationListItem from "./NotificationListItem";
|
||||
type Props = {
|
||||
/** Callback when the notification panel wants to close. */
|
||||
onRequestClose: () => void;
|
||||
/** Whether the panel is open or not. */
|
||||
isOpen: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* A panel containing a list of notifications and controls to manage them.
|
||||
*/
|
||||
function Notifications(
|
||||
{ onRequestClose }: Props,
|
||||
{ onRequestClose, isOpen }: Props,
|
||||
ref: React.RefObject<HTMLDivElement>
|
||||
) {
|
||||
const context = useActionContext();
|
||||
@@ -72,7 +74,7 @@ function Notifications(
|
||||
<PaginatedList
|
||||
fetch={notifications.fetchPage}
|
||||
options={{ archived: false }}
|
||||
items={notifications.orderedData}
|
||||
items={isOpen ? notifications.orderedData : undefined}
|
||||
renderItem={(item: Notification) => (
|
||||
<NotificationListItem
|
||||
key={item.id}
|
||||
|
||||
@@ -40,7 +40,11 @@ const NotificationsPopover: React.FC = ({ children }: Props) => {
|
||||
shrink
|
||||
flex
|
||||
>
|
||||
<Notifications onRequestClose={popover.hide} ref={scrollableRef} />
|
||||
<Notifications
|
||||
onRequestClose={popover.hide}
|
||||
isOpen={popover.visible}
|
||||
ref={scrollableRef}
|
||||
/>
|
||||
</StyledPopover>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -6,9 +6,11 @@ import PaginatedList from "~/components/PaginatedList";
|
||||
import EventListItem from "./EventListItem";
|
||||
|
||||
type Props = {
|
||||
events: Event[];
|
||||
events: Event<Document>[];
|
||||
document: Document;
|
||||
fetch: (options: Record<string, any> | undefined) => Promise<Event[]>;
|
||||
fetch: (
|
||||
options: Record<string, any> | undefined
|
||||
) => Promise<Event<Document>[]>;
|
||||
options?: Record<string, any>;
|
||||
heading?: React.ReactNode;
|
||||
empty?: React.ReactNode;
|
||||
@@ -30,7 +32,7 @@ const PaginatedEventList = React.memo<Props>(function PaginatedEventList({
|
||||
heading={heading}
|
||||
fetch={fetch}
|
||||
options={options}
|
||||
renderItem={(item: Event, index) => (
|
||||
renderItem={(item: Event<Document>, index) => (
|
||||
<EventListItem
|
||||
key={item.id}
|
||||
event={item}
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
import { observer } from "mobx-react";
|
||||
import { transparentize } from "polished";
|
||||
import React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import styled, { css } from "styled-components";
|
||||
import { s } from "@shared/styles";
|
||||
import type { ReactionSummary } from "@shared/types";
|
||||
import { getEmojiId } from "@shared/utils/emoji";
|
||||
import User from "~/models/User";
|
||||
import { Emoji } from "~/components/Emoji";
|
||||
import Flex from "~/components/Flex";
|
||||
import NudeButton from "~/components/NudeButton";
|
||||
import Text from "~/components/Text";
|
||||
import Tooltip from "~/components/Tooltip";
|
||||
import useCurrentUser from "~/hooks/useCurrentUser";
|
||||
import { hover } from "~/styles";
|
||||
|
||||
type Props = {
|
||||
/** Thin reaction data - contains the emoji & active user ids for this reaction. */
|
||||
reaction: ReactionSummary;
|
||||
/** Users who reacted using this emoji. */
|
||||
reactedUsers: User[];
|
||||
/** Whether the emoji button should be disabled (prevents add/remove events). */
|
||||
disabled: boolean;
|
||||
/** Callback when the user intends to add the reaction. */
|
||||
onAddReaction: (emoji: string) => Promise<void>;
|
||||
/** Callback when the user intends to remove the reaction. */
|
||||
onRemoveReaction: (emoji: string) => Promise<void>;
|
||||
};
|
||||
|
||||
const useTooltipContent = ({
|
||||
reactedUsers,
|
||||
currUser,
|
||||
emoji,
|
||||
active,
|
||||
}: {
|
||||
reactedUsers: User[];
|
||||
currUser: User;
|
||||
emoji: string;
|
||||
active: boolean;
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
if (!reactedUsers.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const transformedEmoji = `:${getEmojiId(emoji)}:`;
|
||||
|
||||
switch (reactedUsers.length) {
|
||||
case 1: {
|
||||
return t("{{ username }} reacted with {{ emoji }}", {
|
||||
username: active ? t("You") : reactedUsers[0].name,
|
||||
emoji: transformedEmoji,
|
||||
});
|
||||
}
|
||||
|
||||
case 2: {
|
||||
const firstUsername = active ? t("You") : reactedUsers[0].name;
|
||||
const secondUsername = active
|
||||
? reactedUsers.find((user) => user.id !== currUser.id)?.name
|
||||
: reactedUsers[1].name;
|
||||
|
||||
return t(
|
||||
"{{ firstUsername }} and {{ secondUsername }} reacted with {{ emoji }}",
|
||||
{
|
||||
firstUsername,
|
||||
secondUsername,
|
||||
emoji: transformedEmoji,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
default: {
|
||||
const firstUsername = active ? t("You") : reactedUsers[0].name;
|
||||
const count = reactedUsers.length - 1;
|
||||
|
||||
return t(
|
||||
"{{ firstUsername }} and {{ count }} others reacted with {{ emoji }}",
|
||||
{
|
||||
firstUsername,
|
||||
count,
|
||||
emoji: transformedEmoji,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const Reaction: React.FC<Props> = ({
|
||||
reaction,
|
||||
reactedUsers,
|
||||
disabled,
|
||||
onAddReaction,
|
||||
onRemoveReaction,
|
||||
}) => {
|
||||
const user = useCurrentUser();
|
||||
|
||||
const active = reaction.userIds.includes(user.id);
|
||||
|
||||
const tooltipContent = useTooltipContent({
|
||||
reactedUsers,
|
||||
currUser: user,
|
||||
emoji: reaction.emoji,
|
||||
active,
|
||||
});
|
||||
|
||||
const handleClick = React.useCallback(
|
||||
(event: React.SyntheticEvent<HTMLButtonElement>) => {
|
||||
event.stopPropagation();
|
||||
active
|
||||
? void onRemoveReaction(reaction.emoji)
|
||||
: void onAddReaction(reaction.emoji);
|
||||
},
|
||||
[reaction, active, onAddReaction, onRemoveReaction]
|
||||
);
|
||||
|
||||
const DisplayedEmoji = React.useMemo(
|
||||
() => (
|
||||
<EmojiButton disabled={disabled} $active={active} onClick={handleClick}>
|
||||
<Flex gap={6} justify="center" align="center">
|
||||
<Emoji size={15}>{reaction.emoji}</Emoji>
|
||||
<Count weight="xbold">{reaction.userIds.length}</Count>
|
||||
</Flex>
|
||||
</EmojiButton>
|
||||
),
|
||||
[reaction.emoji, reaction.userIds, disabled, active, handleClick]
|
||||
);
|
||||
|
||||
return tooltipContent ? (
|
||||
<Tooltip content={tooltipContent} delay={250} placement="bottom">
|
||||
{DisplayedEmoji}
|
||||
</Tooltip>
|
||||
) : (
|
||||
<>{DisplayedEmoji}</>
|
||||
);
|
||||
};
|
||||
|
||||
const EmojiButton = styled(NudeButton)<{
|
||||
$active: boolean;
|
||||
disabled: boolean;
|
||||
}>`
|
||||
width: auto;
|
||||
height: 28px;
|
||||
padding: 6px;
|
||||
border-radius: 12px;
|
||||
transition: ${s("backgroundTransition")};
|
||||
background: ${s("backgroundTertiary")};
|
||||
pointer-events: ${({ disabled }) => disabled && "none"};
|
||||
|
||||
&: ${hover} {
|
||||
background: ${s("backgroundQuaternary")};
|
||||
}
|
||||
|
||||
${(props) =>
|
||||
props.$active &&
|
||||
css`
|
||||
background: ${transparentize(0.7, props.theme.accent)};
|
||||
|
||||
&: ${hover} {
|
||||
background: ${transparentize(0.5, props.theme.accent)};
|
||||
}
|
||||
`}
|
||||
`;
|
||||
|
||||
const Count = styled(Text)`
|
||||
font-size: 11px;
|
||||
color: ${s("buttonNeutralText")};
|
||||
padding-right: 1px;
|
||||
font-variant-numeric: tabular-nums;
|
||||
`;
|
||||
|
||||
export default observer(Reaction);
|
||||
@@ -0,0 +1,87 @@
|
||||
import compact from "lodash/compact";
|
||||
import { observer } from "mobx-react";
|
||||
import React from "react";
|
||||
import Comment from "~/models/Comment";
|
||||
import useHover from "~/hooks/useHover";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import Logger from "~/utils/Logger";
|
||||
import Flex from "../Flex";
|
||||
import { ResizingHeightContainer } from "../ResizingHeightContainer";
|
||||
import Reaction from "./Reaction";
|
||||
|
||||
type Props = {
|
||||
/** Model for which to show the reactions. */
|
||||
model: Comment;
|
||||
/** Callback when the user intends to add a reaction. */
|
||||
onAddReaction: (emoji: string) => Promise<void>;
|
||||
/** Callback when the user intends to remove a reaction. */
|
||||
onRemoveReaction: (emoji: string) => Promise<void>;
|
||||
/** classname generated by styled-components. */
|
||||
className?: string;
|
||||
/** Picker to render as the last element */
|
||||
picker?: React.ReactElement;
|
||||
};
|
||||
|
||||
const ReactionList: React.FC<Props> = ({
|
||||
model,
|
||||
onAddReaction,
|
||||
onRemoveReaction,
|
||||
className,
|
||||
picker,
|
||||
}) => {
|
||||
const { users } = useStores();
|
||||
const listRef = React.useRef<HTMLDivElement>(null);
|
||||
|
||||
const hovered = useHover({
|
||||
ref: listRef,
|
||||
duration: 250,
|
||||
});
|
||||
|
||||
React.useEffect(() => {
|
||||
const loadReactedUsersData = async () => {
|
||||
try {
|
||||
await model.loadReactedUsersData();
|
||||
} catch (err) {
|
||||
Logger.warn("Could not prefetch reaction data");
|
||||
}
|
||||
};
|
||||
|
||||
if (hovered) {
|
||||
void loadReactedUsersData();
|
||||
}
|
||||
}, [hovered, model]);
|
||||
|
||||
const hasReactions = !!model.reactions.length;
|
||||
const style = React.useMemo(() => {
|
||||
if (hasReactions) {
|
||||
return { minHeight: 28 };
|
||||
}
|
||||
return undefined;
|
||||
}, [hasReactions]);
|
||||
|
||||
return (
|
||||
<ResizingHeightContainer style={style}>
|
||||
<Flex ref={listRef} className={className} align="center" gap={6} wrap>
|
||||
{model.reactions.map((reaction) => {
|
||||
const reactedUsers = compact(
|
||||
reaction.userIds.map((id) => users.get(id))
|
||||
);
|
||||
|
||||
return (
|
||||
<Reaction
|
||||
key={reaction.emoji}
|
||||
reaction={reaction}
|
||||
reactedUsers={reactedUsers}
|
||||
disabled={model.isResolved}
|
||||
onAddReaction={onAddReaction}
|
||||
onRemoveReaction={onRemoveReaction}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
{picker}
|
||||
</Flex>
|
||||
</ResizingHeightContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default observer(ReactionList);
|
||||
@@ -0,0 +1,158 @@
|
||||
import { ReactionIcon } from "outline-icons";
|
||||
import React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { PopoverDisclosure, usePopoverState } from "reakit";
|
||||
import styled from "styled-components";
|
||||
import EventBoundary from "@shared/components/EventBoundary";
|
||||
import Flex from "~/components/Flex";
|
||||
import NudeButton from "~/components/NudeButton";
|
||||
import PlaceholderText from "~/components/PlaceholderText";
|
||||
import Popover from "~/components/Popover";
|
||||
import useMobile from "~/hooks/useMobile";
|
||||
import useOnClickOutside from "~/hooks/useOnClickOutside";
|
||||
import useWindowSize from "~/hooks/useWindowSize";
|
||||
|
||||
const EmojiPanel = React.lazy(
|
||||
() => import("~/components/IconPicker/components/EmojiPanel")
|
||||
);
|
||||
|
||||
type Props = {
|
||||
/** Callback when an emoji is selected by the user. */
|
||||
onSelect: (emoji: string) => Promise<void>;
|
||||
/** Callback when the picker is opened. */
|
||||
onOpen?: () => void;
|
||||
/** Callback when the picker is closed. */
|
||||
onClose?: () => void;
|
||||
/** Optional classname. */
|
||||
className?: string;
|
||||
size?: number;
|
||||
};
|
||||
|
||||
const ReactionPicker: React.FC<Props> = ({
|
||||
onSelect,
|
||||
onOpen,
|
||||
onClose,
|
||||
className,
|
||||
size,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const popover = usePopoverState({
|
||||
modal: true,
|
||||
unstable_offset: [0, 0],
|
||||
placement: "bottom-end",
|
||||
});
|
||||
|
||||
const { width: windowWidth } = useWindowSize();
|
||||
const isMobile = useMobile();
|
||||
|
||||
const [query, setQuery] = React.useState("");
|
||||
const contentRef = React.useRef<HTMLDivElement | null>(null);
|
||||
|
||||
const popoverWidth = isMobile ? windowWidth : 300;
|
||||
// In mobile, popover is absolutely positioned to leave 8px on both sides.
|
||||
const panelWidth = isMobile ? windowWidth - 16 : popoverWidth;
|
||||
const { toggle, hide } = popover;
|
||||
const handlePopoverButtonClick = React.useCallback(
|
||||
(ev: React.MouseEvent) => {
|
||||
ev.stopPropagation();
|
||||
toggle();
|
||||
},
|
||||
[toggle]
|
||||
);
|
||||
|
||||
const handleEmojiSelect = React.useCallback(
|
||||
(emoji: string) => {
|
||||
hide();
|
||||
void onSelect(emoji);
|
||||
},
|
||||
[hide, onSelect]
|
||||
);
|
||||
|
||||
// Popover open effect
|
||||
React.useEffect(() => {
|
||||
if (popover.visible) {
|
||||
onOpen?.();
|
||||
} else {
|
||||
onClose?.();
|
||||
}
|
||||
}, [popover.visible, onOpen, onClose]);
|
||||
|
||||
// Custom click outside handling rather than using `hideOnClickOutside` from reakit so that we can
|
||||
// prevent event bubbling.
|
||||
useOnClickOutside(
|
||||
contentRef,
|
||||
(event) => {
|
||||
if (
|
||||
popover.visible &&
|
||||
!popover.unstable_disclosureRef.current?.contains(event.target as Node)
|
||||
) {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
popover.hide();
|
||||
}
|
||||
},
|
||||
{ capture: true }
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<PopoverDisclosure {...popover}>
|
||||
{(props) => (
|
||||
<PopoverButton
|
||||
{...props}
|
||||
aria-label={t("Reaction picker")}
|
||||
className={className}
|
||||
onClick={handlePopoverButtonClick}
|
||||
size={size}
|
||||
>
|
||||
<ReactionIcon size={22} />
|
||||
</PopoverButton>
|
||||
)}
|
||||
</PopoverDisclosure>
|
||||
<Popover
|
||||
{...popover}
|
||||
ref={contentRef}
|
||||
width={popoverWidth}
|
||||
shrink
|
||||
aria-label={t("Reaction picker")}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
hideOnClickOutside={false}
|
||||
>
|
||||
{popover.visible && (
|
||||
<React.Suspense fallback={<Placeholder />}>
|
||||
<EventBoundary>
|
||||
<EmojiPanel
|
||||
height={300}
|
||||
panelWidth={panelWidth}
|
||||
query={query}
|
||||
onEmojiChange={handleEmojiSelect}
|
||||
onQueryChange={setQuery}
|
||||
panelActive
|
||||
/>
|
||||
</EventBoundary>
|
||||
</React.Suspense>
|
||||
)}
|
||||
</Popover>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const Placeholder = React.memo(
|
||||
() => (
|
||||
<Flex column gap={6} style={{ height: "300px", padding: "6px 12px" }}>
|
||||
<Flex gap={8}>
|
||||
<PlaceholderText height={32} minWidth={90} />
|
||||
<PlaceholderText height={32} width={32} />
|
||||
</Flex>
|
||||
<PlaceholderText height={24} width={120} />
|
||||
</Flex>
|
||||
),
|
||||
() => true
|
||||
);
|
||||
Placeholder.displayName = "ReactionPickerPlaceholder";
|
||||
|
||||
const PopoverButton = styled(NudeButton)`
|
||||
border-radius: 50%;
|
||||
`;
|
||||
|
||||
export default ReactionPicker;
|
||||
@@ -0,0 +1,146 @@
|
||||
import compact from "lodash/compact";
|
||||
import { observer } from "mobx-react";
|
||||
import React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Tab, TabPanel, useTabState } from "reakit";
|
||||
import { toast } from "sonner";
|
||||
import styled, { css } from "styled-components";
|
||||
import { s } from "@shared/styles";
|
||||
import Comment from "~/models/Comment";
|
||||
import { Avatar, AvatarSize } from "~/components/Avatar";
|
||||
import { Emoji } from "~/components/Emoji";
|
||||
import Flex from "~/components/Flex";
|
||||
import PlaceholderText from "~/components/PlaceholderText";
|
||||
import Text from "~/components/Text";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import { hover } from "~/styles";
|
||||
|
||||
type Props = {
|
||||
/** Model for which to show the reactions. */
|
||||
model: Comment;
|
||||
};
|
||||
|
||||
const ViewReactionsDialog: React.FC<Props> = ({ model }) => {
|
||||
const { t } = useTranslation();
|
||||
const { users } = useStores();
|
||||
const tab = useTabState();
|
||||
const { reactedUsersLoaded } = model;
|
||||
|
||||
React.useEffect(() => {
|
||||
const loadReactedUsersData = async () => {
|
||||
try {
|
||||
await model.loadReactedUsersData();
|
||||
} catch (err) {
|
||||
toast.error(t("Could not load reactions"));
|
||||
}
|
||||
};
|
||||
|
||||
void loadReactedUsersData();
|
||||
}, [t, model]);
|
||||
|
||||
if (!reactedUsersLoaded) {
|
||||
return <PlaceHolder />;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<TabActionsWrapper>
|
||||
{model.reactions.map((reaction) => (
|
||||
<StyledTab
|
||||
{...tab}
|
||||
key={reaction.emoji}
|
||||
id={reaction.emoji}
|
||||
aria-label={t("Reaction")}
|
||||
$active={tab.selectedId === reaction.emoji}
|
||||
>
|
||||
<Emoji size={16}>{reaction.emoji}</Emoji>
|
||||
</StyledTab>
|
||||
))}
|
||||
</TabActionsWrapper>
|
||||
{model.reactions.map((reaction) => {
|
||||
const reactedUsers = compact(
|
||||
reaction.userIds.map((id) => users.get(id))
|
||||
);
|
||||
|
||||
return (
|
||||
<StyledTabPanel {...tab} key={reaction.emoji}>
|
||||
{reactedUsers.map((user) => (
|
||||
<UserInfo key={user.name} align="center" gap={8}>
|
||||
<Avatar model={user} size={AvatarSize.Medium} />
|
||||
<Text size="medium">{user.name}</Text>
|
||||
</UserInfo>
|
||||
))}
|
||||
</StyledTabPanel>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const PlaceHolder = React.memo(
|
||||
() => (
|
||||
<>
|
||||
<TabActionsWrapper gap={8} style={{ paddingBottom: "10px" }}>
|
||||
<PlaceholderText width={40} height={32} />
|
||||
<PlaceholderText width={40} height={32} />
|
||||
</TabActionsWrapper>
|
||||
<UserInfo align="center" gap={12}>
|
||||
<PlaceholderText width={AvatarSize.Medium} height={AvatarSize.Medium} />
|
||||
<PlaceholderText height={34} />
|
||||
</UserInfo>
|
||||
<UserInfo align="center" gap={12}>
|
||||
<PlaceholderText width={AvatarSize.Medium} height={AvatarSize.Medium} />
|
||||
<PlaceholderText height={34} />
|
||||
</UserInfo>
|
||||
</>
|
||||
),
|
||||
() => true
|
||||
);
|
||||
PlaceHolder.displayName = "ViewReactionsPlaceholder";
|
||||
|
||||
const TabActionsWrapper = styled(Flex)`
|
||||
border-bottom: 1px solid ${s("inputBorder")};
|
||||
`;
|
||||
|
||||
const StyledTab = styled(Tab)<{ $active: boolean }>`
|
||||
position: relative;
|
||||
font-weight: 500;
|
||||
font-size: 14px;
|
||||
cursor: var(--pointer);
|
||||
background: none;
|
||||
border: 0;
|
||||
border-radius: 4px 4px 0 0;
|
||||
padding: 8px 12px 10px;
|
||||
user-select: none;
|
||||
transition: background-color 100ms ease;
|
||||
|
||||
&: ${hover} {
|
||||
background-color: ${s("listItemHoverBackground")};
|
||||
}
|
||||
|
||||
${({ $active }) =>
|
||||
$active &&
|
||||
css`
|
||||
&:after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 1px;
|
||||
background: ${s("textSecondary")};
|
||||
}
|
||||
`}
|
||||
`;
|
||||
|
||||
const StyledTabPanel = styled(TabPanel)`
|
||||
height: 300px;
|
||||
padding: 5px 0;
|
||||
overflow-y: auto;
|
||||
`;
|
||||
|
||||
const UserInfo = styled(Flex)`
|
||||
padding: 10px 8px;
|
||||
`;
|
||||
|
||||
export default observer(ViewReactionsDialog);
|
||||
@@ -19,9 +19,10 @@ import SearchListItem from "./SearchListItem";
|
||||
|
||||
interface Props extends React.HTMLAttributes<HTMLInputElement> {
|
||||
shareId: string;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
function SearchPopover({ shareId }: Props) {
|
||||
function SearchPopover({ shareId, className }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const { documents } = useStores();
|
||||
const focusRef = React.useRef<HTMLElement | null>(null);
|
||||
@@ -54,7 +55,8 @@ function SearchPopover({ shareId }: Props) {
|
||||
const performSearch = React.useCallback(
|
||||
async ({ query, ...options }) => {
|
||||
if (query?.length > 0) {
|
||||
const response = await documents.search(query, {
|
||||
const response = await documents.search({
|
||||
query,
|
||||
shareId,
|
||||
...options,
|
||||
});
|
||||
@@ -186,6 +188,7 @@ function SearchPopover({ shareId }: Props) {
|
||||
onChange={handleSearchInputChange}
|
||||
onFocus={handleSearchInputFocus}
|
||||
onKeyDown={handleKeyDown}
|
||||
className={className}
|
||||
/>
|
||||
)}
|
||||
</PopoverDisclosure>
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import debounce from "lodash/debounce";
|
||||
import isEmpty from "lodash/isEmpty";
|
||||
import { observer } from "mobx-react";
|
||||
import { CopyIcon, GlobeIcon, InfoIcon } from "outline-icons";
|
||||
import { CopyIcon, GlobeIcon, InfoIcon, QuestionMarkIcon } from "outline-icons";
|
||||
import * as React from "react";
|
||||
import { Trans, useTranslation } from "react-i18next";
|
||||
import { Link } from "react-router-dom";
|
||||
import { toast } from "sonner";
|
||||
import styled, { useTheme } from "styled-components";
|
||||
import Flex from "@shared/components/Flex";
|
||||
import Squircle from "@shared/components/Squircle";
|
||||
import { s } from "@shared/styles";
|
||||
import { UrlHelper } from "@shared/utils/UrlHelper";
|
||||
@@ -50,6 +51,19 @@ function PublicAccess({ document, share, sharedParent }: Props) {
|
||||
setUrlId(share?.urlId);
|
||||
}, [share?.urlId]);
|
||||
|
||||
const handleIndexingChanged = React.useCallback(
|
||||
async (event) => {
|
||||
try {
|
||||
await share?.save({
|
||||
allowIndexing: event.currentTarget.checked,
|
||||
});
|
||||
} catch (err) {
|
||||
toast.error(err.message);
|
||||
}
|
||||
},
|
||||
[share]
|
||||
);
|
||||
|
||||
const handlePublishedChange = React.useCallback(
|
||||
async (event) => {
|
||||
try {
|
||||
@@ -153,6 +167,32 @@ function PublicAccess({ document, share, sharedParent }: Props) {
|
||||
/>
|
||||
|
||||
<ResizingHeightContainer>
|
||||
{share?.published && (
|
||||
<ListItem
|
||||
title={
|
||||
<Text type="tertiary" as={Flex}>
|
||||
{t("Search engine indexing")}
|
||||
<Tooltip
|
||||
content={t(
|
||||
"Disable this setting to discourage search engines from indexing the page"
|
||||
)}
|
||||
>
|
||||
<QuestionMarkIcon size={18} />
|
||||
</Tooltip>
|
||||
</Text>
|
||||
}
|
||||
actions={
|
||||
<Switch
|
||||
aria-label={t("Search engine indexing")}
|
||||
checked={share?.allowIndexing ?? false}
|
||||
onChange={handleIndexingChanged}
|
||||
width={26}
|
||||
height={14}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
{sharedParent?.published ? (
|
||||
<ShareLinkInput type="text" disabled defaultValue={shareUrl}>
|
||||
{copyButton}
|
||||
|
||||
@@ -94,38 +94,40 @@ function AppSidebar() {
|
||||
</SidebarButton>
|
||||
)}
|
||||
</OrganizationMenu>
|
||||
<Section>
|
||||
<SidebarLink
|
||||
to={homePath()}
|
||||
icon={<HomeIcon />}
|
||||
exact={false}
|
||||
label={t("Home")}
|
||||
/>
|
||||
<SidebarLink
|
||||
to={searchPath()}
|
||||
icon={<SearchIcon />}
|
||||
label={t("Search")}
|
||||
exact={false}
|
||||
/>
|
||||
{can.createDocument && (
|
||||
<Overflow>
|
||||
<Section>
|
||||
<SidebarLink
|
||||
to={draftsPath()}
|
||||
icon={<DraftsIcon />}
|
||||
label={
|
||||
<Flex align="center" justify="space-between">
|
||||
{t("Drafts")}
|
||||
{documents.totalDrafts > 0 ? (
|
||||
<Drafts size="xsmall" type="tertiary">
|
||||
{documents.totalDrafts > 25
|
||||
? "25+"
|
||||
: documents.totalDrafts}
|
||||
</Drafts>
|
||||
) : null}
|
||||
</Flex>
|
||||
}
|
||||
to={homePath()}
|
||||
icon={<HomeIcon />}
|
||||
exact={false}
|
||||
label={t("Home")}
|
||||
/>
|
||||
)}
|
||||
</Section>
|
||||
<SidebarLink
|
||||
to={searchPath()}
|
||||
icon={<SearchIcon />}
|
||||
label={t("Search")}
|
||||
exact={false}
|
||||
/>
|
||||
{can.createDocument && (
|
||||
<SidebarLink
|
||||
to={draftsPath()}
|
||||
icon={<DraftsIcon />}
|
||||
label={
|
||||
<Flex align="center" justify="space-between">
|
||||
{t("Drafts")}
|
||||
{documents.totalDrafts > 0 ? (
|
||||
<Drafts size="xsmall" type="tertiary">
|
||||
{documents.totalDrafts > 25
|
||||
? "25+"
|
||||
: documents.totalDrafts}
|
||||
</Drafts>
|
||||
) : null}
|
||||
</Flex>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</Section>
|
||||
</Overflow>
|
||||
<Scrollable flex shadow>
|
||||
<Section>
|
||||
<Starred />
|
||||
@@ -152,6 +154,11 @@ function AppSidebar() {
|
||||
);
|
||||
}
|
||||
|
||||
const Overflow = styled.div`
|
||||
overflow: hidden;
|
||||
flex-shrink: 0;
|
||||
`;
|
||||
|
||||
const Drafts = styled(Text)`
|
||||
margin: 0 4px;
|
||||
`;
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
import { observer } from "mobx-react";
|
||||
import { SidebarIcon } from "outline-icons";
|
||||
import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import styled from "styled-components";
|
||||
import { NavigationNode } from "@shared/types";
|
||||
import Flex from "~/components/Flex";
|
||||
import Scrollable from "~/components/Scrollable";
|
||||
import SearchPopover from "~/components/SearchPopover";
|
||||
import Tooltip from "~/components/Tooltip";
|
||||
import useCurrentUser from "~/hooks/useCurrentUser";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import { hover } from "~/styles";
|
||||
import history from "~/utils/history";
|
||||
import { metaDisplay } from "~/utils/keyboard";
|
||||
import { homePath, sharedDocumentPath } from "~/utils/routeHelpers";
|
||||
import { useTeamContext } from "../TeamContext";
|
||||
import TeamLogo from "../TeamLogo";
|
||||
@@ -15,6 +20,7 @@ import Sidebar from "./Sidebar";
|
||||
import Section from "./components/Section";
|
||||
import DocumentLink from "./components/SharedDocumentLink";
|
||||
import SidebarButton from "./components/SidebarButton";
|
||||
import ToggleButton from "./components/ToggleButton";
|
||||
|
||||
type Props = {
|
||||
rootNode: NavigationNode;
|
||||
@@ -27,9 +33,11 @@ function SharedSidebar({ rootNode, shareId }: Props) {
|
||||
const { ui, documents } = useStores();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const teamAvailable = !!team?.name;
|
||||
|
||||
return (
|
||||
<Sidebar>
|
||||
{team?.name && (
|
||||
<StyledSidebar $hoverTransition={!teamAvailable}>
|
||||
{teamAvailable && (
|
||||
<SidebarButton
|
||||
title={team.name}
|
||||
image={<TeamLogo model={team} size={32} alt={t("Logo")} />}
|
||||
@@ -38,11 +46,20 @@ function SharedSidebar({ rootNode, shareId }: Props) {
|
||||
user ? homePath() : sharedDocumentPath(shareId, rootNode.url)
|
||||
)
|
||||
}
|
||||
/>
|
||||
>
|
||||
<ToggleSidebar />
|
||||
</SidebarButton>
|
||||
)}
|
||||
<ScrollContainer topShadow flex>
|
||||
<TopSection>
|
||||
<SearchPopover shareId={shareId} />
|
||||
<SearchWrapper>
|
||||
<StyledSearchPopover shareId={shareId} />
|
||||
</SearchWrapper>
|
||||
{!teamAvailable && (
|
||||
<ToggleWrapper>
|
||||
<ToggleSidebar />
|
||||
</ToggleWrapper>
|
||||
)}
|
||||
</TopSection>
|
||||
<Section>
|
||||
<DocumentLink
|
||||
@@ -55,23 +72,74 @@ function SharedSidebar({ rootNode, shareId }: Props) {
|
||||
/>
|
||||
</Section>
|
||||
</ScrollContainer>
|
||||
</Sidebar>
|
||||
</StyledSidebar>
|
||||
);
|
||||
}
|
||||
|
||||
const ToggleSidebar = () => {
|
||||
const { t } = useTranslation();
|
||||
const { ui } = useStores();
|
||||
|
||||
return (
|
||||
<Tooltip
|
||||
content={t("Toggle sidebar")}
|
||||
shortcut={`${metaDisplay}+.`}
|
||||
delay={500}
|
||||
>
|
||||
<ToggleButton
|
||||
position="bottom"
|
||||
image={<SidebarIcon />}
|
||||
onClick={() => {
|
||||
ui.toggleCollapsedSidebar();
|
||||
(document.activeElement as HTMLElement)?.blur();
|
||||
}}
|
||||
/>
|
||||
</Tooltip>
|
||||
);
|
||||
};
|
||||
|
||||
const ScrollContainer = styled(Scrollable)`
|
||||
padding-bottom: 16px;
|
||||
`;
|
||||
|
||||
const TopSection = styled(Section)`
|
||||
// this weird looking && increases the specificity of the style rule
|
||||
&&:first-child {
|
||||
margin-top: 16px;
|
||||
}
|
||||
const TopSection = styled(Flex)`
|
||||
padding: 8px;
|
||||
flex-shrink: 0;
|
||||
`;
|
||||
|
||||
&& {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
const SearchWrapper = styled.div`
|
||||
width: 100%;
|
||||
`;
|
||||
|
||||
const StyledSearchPopover = styled(SearchPopover)`
|
||||
width: 100%;
|
||||
transition: width 100ms ease-out;
|
||||
margin: 8px 0;
|
||||
`;
|
||||
|
||||
const ToggleWrapper = styled.div`
|
||||
position: absolute;
|
||||
right: 0;
|
||||
opacity: 0;
|
||||
transform: translateX(10px);
|
||||
transition: opacity 100ms ease-out, transform 100ms ease-out;
|
||||
`;
|
||||
|
||||
const StyledSidebar = styled(Sidebar)<{ $hoverTransition: boolean }>`
|
||||
${({ $hoverTransition }) =>
|
||||
$hoverTransition &&
|
||||
`
|
||||
&: ${hover} {
|
||||
${StyledSearchPopover} {
|
||||
width: 85%;
|
||||
}
|
||||
|
||||
${ToggleWrapper} {
|
||||
opacity: 1;
|
||||
transform: translateX(0);
|
||||
}
|
||||
}
|
||||
`}
|
||||
`;
|
||||
|
||||
export default observer(SharedSidebar);
|
||||
@@ -94,9 +94,17 @@ const Sidebar = React.forwardRef<HTMLDivElement, Props>(function _Sidebar(
|
||||
}
|
||||
}, [ui, isSmallerThanMinimum, minWidth, width, setWidth]);
|
||||
|
||||
const handleBlur = React.useCallback(() => {
|
||||
setHovering(false);
|
||||
}, []);
|
||||
|
||||
const handleMouseDown = React.useCallback(
|
||||
(event) => {
|
||||
event.preventDefault();
|
||||
if (!document.hasFocus()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setOffset(event.pageX - width);
|
||||
setResizing(true);
|
||||
setAnimating(false);
|
||||
@@ -104,9 +112,9 @@ const Sidebar = React.forwardRef<HTMLDivElement, Props>(function _Sidebar(
|
||||
[width]
|
||||
);
|
||||
|
||||
const handlePointerMove = React.useCallback(() => {
|
||||
const handlePointerActivity = React.useCallback(() => {
|
||||
if (ui.sidebarIsClosed) {
|
||||
setHovering(true);
|
||||
setHovering(document.hasFocus());
|
||||
setPointerMoved(true);
|
||||
}
|
||||
}, [ui.sidebarIsClosed]);
|
||||
@@ -115,7 +123,10 @@ const Sidebar = React.forwardRef<HTMLDivElement, Props>(function _Sidebar(
|
||||
(ev) => {
|
||||
if (hasPointerMoved) {
|
||||
setHovering(
|
||||
ev.pageX < width && ev.pageY < window.innerHeight && ev.pageY > 0
|
||||
document.hasFocus() &&
|
||||
ev.pageX < width &&
|
||||
ev.pageY < window.innerHeight &&
|
||||
ev.pageY > 0
|
||||
);
|
||||
}
|
||||
},
|
||||
@@ -153,11 +164,14 @@ const Sidebar = React.forwardRef<HTMLDivElement, Props>(function _Sidebar(
|
||||
document.body.style.cursor = "initial";
|
||||
}
|
||||
|
||||
window.addEventListener("blur", handleBlur);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("blur", handleBlur);
|
||||
document.removeEventListener("mousemove", handleDrag);
|
||||
document.removeEventListener("mouseup", handleStopDrag);
|
||||
};
|
||||
}, [isResizing, handleDrag, handleStopDrag]);
|
||||
}, [isResizing, handleDrag, handleBlur, handleStopDrag]);
|
||||
|
||||
const handleReset = React.useCallback(() => {
|
||||
ui.setSidebarWidth(theme.sidebarWidth);
|
||||
@@ -193,7 +207,8 @@ const Sidebar = React.forwardRef<HTMLDivElement, Props>(function _Sidebar(
|
||||
$collapsed={collapsed}
|
||||
$isMobile={isMobile}
|
||||
className={className}
|
||||
onPointerMove={handlePointerMove}
|
||||
onPointerDown={handlePointerActivity}
|
||||
onPointerMove={handlePointerActivity}
|
||||
onPointerLeave={handlePointerLeave}
|
||||
column
|
||||
>
|
||||
@@ -217,15 +232,7 @@ const Sidebar = React.forwardRef<HTMLDivElement, Props>(function _Sidebar(
|
||||
/>
|
||||
}
|
||||
>
|
||||
<NotificationsPopover>
|
||||
{(rest: SidebarButtonProps) => (
|
||||
<SidebarButton
|
||||
{...rest}
|
||||
position="bottom"
|
||||
image={<NotificationIcon />}
|
||||
/>
|
||||
)}
|
||||
</NotificationsPopover>
|
||||
<Notifications />
|
||||
</SidebarButton>
|
||||
)}
|
||||
</AccountMenu>
|
||||
@@ -240,6 +247,14 @@ const Sidebar = React.forwardRef<HTMLDivElement, Props>(function _Sidebar(
|
||||
);
|
||||
});
|
||||
|
||||
const Notifications = () => (
|
||||
<NotificationsPopover>
|
||||
{(rest: SidebarButtonProps) => (
|
||||
<SidebarButton {...rest} position="bottom" image={<NotificationIcon />} />
|
||||
)}
|
||||
</NotificationsPopover>
|
||||
);
|
||||
|
||||
const Backdrop = styled.a`
|
||||
animation: ${fadeIn} 250ms ease-in-out;
|
||||
position: fixed;
|
||||
|
||||
@@ -112,6 +112,10 @@ const CollectionLink: React.FC<Props> = ({
|
||||
sidebarContext,
|
||||
});
|
||||
|
||||
const handleRename = React.useCallback(() => {
|
||||
editableTitleRef.current?.setIsEditing(true);
|
||||
}, [editableTitleRef]);
|
||||
|
||||
return (
|
||||
<Relative ref={drop}>
|
||||
<DropToImport collectionId={collection.id}>
|
||||
@@ -157,7 +161,7 @@ const CollectionLink: React.FC<Props> = ({
|
||||
</NudeButton>
|
||||
<CollectionMenu
|
||||
collection={collection}
|
||||
onRename={() => editableTitleRef.current?.setIsEditing(true)}
|
||||
onRename={handleRename}
|
||||
onOpen={handleMenuOpen}
|
||||
onClose={handleMenuClose}
|
||||
/>
|
||||
|
||||
@@ -2,6 +2,7 @@ import { observer } from "mobx-react";
|
||||
import * as React from "react";
|
||||
import { useDrop } from "react-dnd";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Waypoint } from "react-waypoint";
|
||||
import { toast } from "sonner";
|
||||
import styled from "styled-components";
|
||||
import Collection from "~/models/Collection";
|
||||
@@ -34,11 +35,13 @@ function CollectionLinkChildren({
|
||||
expanded,
|
||||
prefetchDocument,
|
||||
}: Props) {
|
||||
const pageSize = 250;
|
||||
const can = usePolicy(collection);
|
||||
const manualSort = collection.sort.field === "index";
|
||||
const { documents, dialogs, collections } = useStores();
|
||||
const { t } = useTranslation();
|
||||
const childDocuments = useCollectionDocuments(collection, documents.active);
|
||||
const [showing, setShowing] = React.useState(pageSize);
|
||||
|
||||
// Drop to reorder document
|
||||
const [{ isOverReorder, isDraggingAnyDocument }, dropToReorder] = useDrop({
|
||||
@@ -83,6 +86,18 @@ function CollectionLinkChildren({
|
||||
}),
|
||||
});
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!expanded) {
|
||||
setShowing(pageSize);
|
||||
}
|
||||
}, [expanded]);
|
||||
|
||||
const showMore = React.useCallback(() => {
|
||||
if (childDocuments && childDocuments.length > showing) {
|
||||
setShowing((value) => value + pageSize);
|
||||
}
|
||||
}, [childDocuments, showing]);
|
||||
|
||||
return (
|
||||
<Folder expanded={expanded}>
|
||||
{isDraggingAnyDocument && can.createDocument && manualSort && (
|
||||
@@ -98,7 +113,7 @@ function CollectionLinkChildren({
|
||||
<Loading />
|
||||
</ResizingHeightContainer>
|
||||
)}
|
||||
{childDocuments?.map((node, index) => (
|
||||
{childDocuments?.slice(0, showing).map((node, index) => (
|
||||
<DocumentLink
|
||||
key={node.id}
|
||||
node={node}
|
||||
@@ -121,6 +136,7 @@ function CollectionLinkChildren({
|
||||
depth={2}
|
||||
/>
|
||||
)}
|
||||
<Waypoint key={showing} onEnter={showMore} fireOnRapidScroll />
|
||||
</DocumentsLoader>
|
||||
</Folder>
|
||||
);
|
||||
|
||||
@@ -59,6 +59,7 @@ const StyledMoreIcon = styled(MoreIcon)`
|
||||
`;
|
||||
|
||||
const Container = styled(Flex)<{ $position: "top" | "bottom" }>`
|
||||
overflow: hidden;
|
||||
padding-top: ${(props) =>
|
||||
props.$position === "top" && Desktop.hasInsetTitlebar() ? 36 : 0}px;
|
||||
${draggableOnDesktop()}
|
||||
|
||||
@@ -2,41 +2,29 @@ import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import styled from "styled-components";
|
||||
import Badge from "~/components/Badge";
|
||||
import { version } from "../../../../package.json";
|
||||
import { client } from "~/utils/ApiClient";
|
||||
import Logger from "~/utils/Logger";
|
||||
import { version as currentVersion } from "../../../../package.json";
|
||||
import SidebarLink from "./SidebarLink";
|
||||
|
||||
export default function Version() {
|
||||
const [releasesBehind, setReleasesBehind] = React.useState(-1);
|
||||
const [versionsBehind, setVersionsBehind] = React.useState(-1);
|
||||
const { t } = useTranslation();
|
||||
|
||||
React.useEffect(() => {
|
||||
async function loadReleases() {
|
||||
const res = await fetch(
|
||||
"https://api.github.com/repos/outline/outline/releases"
|
||||
);
|
||||
const releases = await res.json();
|
||||
|
||||
if (Array.isArray(releases)) {
|
||||
const everyNewRelease = releases
|
||||
.map((release) => release.tag_name)
|
||||
.findIndex((tagName) => tagName === `v${version}`);
|
||||
|
||||
const onlyFullNewRelease = releases
|
||||
.filter((release) => !release.prerelease)
|
||||
.map((release) => release.tag_name)
|
||||
.findIndex((tagName) => tagName === `v${version}`);
|
||||
|
||||
const computedReleasesBehind = version.includes("pre")
|
||||
? everyNewRelease
|
||||
: onlyFullNewRelease;
|
||||
|
||||
if (computedReleasesBehind >= 0) {
|
||||
setReleasesBehind(computedReleasesBehind);
|
||||
async function loadVersionInfo() {
|
||||
try {
|
||||
// Fetch version info from the server-side proxy
|
||||
const res = await client.post("/installation.info");
|
||||
if (res.data && res.data.versionsBehind >= 0) {
|
||||
setVersionsBehind(res.data.versionsBehind);
|
||||
}
|
||||
} catch (error) {
|
||||
Logger.error("Failed to load version info", error);
|
||||
}
|
||||
}
|
||||
|
||||
void loadReleases();
|
||||
void loadVersionInfo();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
@@ -45,16 +33,16 @@ export default function Version() {
|
||||
href="https://github.com/outline/outline/releases"
|
||||
label={
|
||||
<>
|
||||
v{version}
|
||||
{releasesBehind >= 0 && (
|
||||
v{currentVersion}
|
||||
{versionsBehind >= 0 && (
|
||||
<>
|
||||
<br />
|
||||
<LilBadge>
|
||||
{releasesBehind === 0
|
||||
{versionsBehind === 0
|
||||
? t("Up to date")
|
||||
: t(`{{ releasesBehind }} versions behind`, {
|
||||
releasesBehind,
|
||||
count: releasesBehind,
|
||||
releasesBehind: versionsBehind,
|
||||
count: versionsBehind,
|
||||
})}
|
||||
</LilBadge>
|
||||
</>
|
||||
|
||||
+27
-24
@@ -120,30 +120,33 @@ function Table({
|
||||
<Anchor ref={topRef} />
|
||||
<InnerTable {...getTableProps()}>
|
||||
<thead>
|
||||
{headerGroups.map((headerGroup) => (
|
||||
<tr {...headerGroup.getHeaderGroupProps()} key={headerGroup.id}>
|
||||
{headerGroup.headers.map((column) => (
|
||||
<Head
|
||||
{...column.getHeaderProps(column.getSortByToggleProps())}
|
||||
key={column.id}
|
||||
>
|
||||
<SortWrapper
|
||||
align="center"
|
||||
$sortable={!column.disableSortBy}
|
||||
gap={4}
|
||||
{headerGroups.map((headerGroup) => {
|
||||
const groupProps = headerGroup.getHeaderGroupProps();
|
||||
return (
|
||||
<tr {...groupProps} key={groupProps.key}>
|
||||
{headerGroup.headers.map((column) => (
|
||||
<Head
|
||||
{...column.getHeaderProps(column.getSortByToggleProps())}
|
||||
key={column.id}
|
||||
>
|
||||
{column.render("Header")}
|
||||
{column.isSorted &&
|
||||
(column.isSortedDesc ? (
|
||||
<DescSortIcon />
|
||||
) : (
|
||||
<AscSortIcon />
|
||||
))}
|
||||
</SortWrapper>
|
||||
</Head>
|
||||
))}
|
||||
</tr>
|
||||
))}
|
||||
<SortWrapper
|
||||
align="center"
|
||||
$sortable={!column.disableSortBy}
|
||||
gap={4}
|
||||
>
|
||||
{column.render("Header")}
|
||||
{column.isSorted &&
|
||||
(column.isSortedDesc ? (
|
||||
<DescSortIcon />
|
||||
) : (
|
||||
<AscSortIcon />
|
||||
))}
|
||||
</SortWrapper>
|
||||
</Head>
|
||||
))}
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</thead>
|
||||
<tbody {...getTableBodyProps()}>
|
||||
{rows.map((row) => {
|
||||
@@ -253,7 +256,7 @@ const SortWrapper = styled(Flex)<{ $sortable: boolean }>`
|
||||
|
||||
&:hover {
|
||||
background: ${(props) =>
|
||||
props.$sortable ? props.theme.secondaryBackground : "none"};
|
||||
props.$sortable ? props.theme.backgroundSecondary : "none"};
|
||||
}
|
||||
`;
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import withStores from "~/components/withStores";
|
||||
import {
|
||||
PartialExcept,
|
||||
WebsocketCollectionUpdateIndexEvent,
|
||||
WebsocketCommentReactionEvent,
|
||||
WebsocketEntitiesEvent,
|
||||
WebsocketEntityDeletedEvent,
|
||||
} from "~/types";
|
||||
@@ -351,6 +352,30 @@ class WebsocketProvider extends React.Component<Props> {
|
||||
comments.remove(event.modelId);
|
||||
});
|
||||
|
||||
this.socket.on(
|
||||
"comments.add_reaction",
|
||||
(event: WebsocketCommentReactionEvent) => {
|
||||
const comment = comments.get(event.commentId);
|
||||
comment?.updateReaction({
|
||||
type: "add",
|
||||
emoji: event.emoji,
|
||||
user: event.user,
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
this.socket.on(
|
||||
"comments.remove_reaction",
|
||||
(event: WebsocketCommentReactionEvent) => {
|
||||
const comment = comments.get(event.commentId);
|
||||
comment?.updateReaction({
|
||||
type: "remove",
|
||||
emoji: event.emoji,
|
||||
user: event.user,
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
this.socket.on("groups.create", (event: PartialExcept<Group, "id">) => {
|
||||
groups.add(event);
|
||||
});
|
||||
|
||||
@@ -7,6 +7,7 @@ import { isCode } from "@shared/editor/lib/isCode";
|
||||
import { findParentNode } from "@shared/editor/queries/findParentNode";
|
||||
import { EditorStyleHelper } from "@shared/editor/styles/EditorStyleHelper";
|
||||
import { depths, s } from "@shared/styles";
|
||||
import { HEADER_HEIGHT } from "~/components/Header";
|
||||
import { Portal } from "~/components/Portal";
|
||||
import useComponentSize from "~/hooks/useComponentSize";
|
||||
import useEventListener from "~/hooks/useEventListener";
|
||||
@@ -130,59 +131,64 @@ function usePosition({
|
||||
|
||||
// Images need their own positioning to get the toolbar in the center
|
||||
if (isImageSelection) {
|
||||
const element = view.nodeDOM(selection.from);
|
||||
const element = view.nodeDOM(selection.from) as HTMLElement;
|
||||
|
||||
// Images are wrapped which impacts positioning - need to get the element
|
||||
// specifically tagged as the handle
|
||||
const imageElement = (element as HTMLElement).getElementsByClassName(
|
||||
const imageElement = element.getElementsByClassName(
|
||||
EditorStyleHelper.imageHandle
|
||||
)[0];
|
||||
const { left, top, width } = imageElement.getBoundingClientRect();
|
||||
if (imageElement) {
|
||||
const { left, top, width } = imageElement.getBoundingClientRect();
|
||||
|
||||
return {
|
||||
left: Math.round(left + width / 2 - menuWidth / 2 - offsetParent.left),
|
||||
top: Math.round(top - menuHeight - offsetParent.top),
|
||||
offset: 0,
|
||||
visible: true,
|
||||
};
|
||||
} else {
|
||||
// calculate the horizontal center of the selection
|
||||
const halfSelection =
|
||||
Math.abs(selectionBounds.right - selectionBounds.left) / 2;
|
||||
const centerOfSelection = selectionBounds.left + halfSelection;
|
||||
return {
|
||||
left: Math.round(left + width / 2 - menuWidth / 2 - offsetParent.left),
|
||||
top: Math.round(top - menuHeight - offsetParent.top),
|
||||
offset: 0,
|
||||
visible: true,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// position the menu so that it is centered over the selection except in
|
||||
// the cases where it would extend off the edge of the screen. In these
|
||||
// instances leave a margin
|
||||
const margin = 12;
|
||||
const left = Math.min(
|
||||
Math.min(
|
||||
offsetParent.x + offsetParent.width - menuWidth - margin,
|
||||
window.innerWidth - margin
|
||||
),
|
||||
Math.max(
|
||||
Math.max(offsetParent.x, margin),
|
||||
centerOfSelection - menuWidth / 2
|
||||
)
|
||||
);
|
||||
const top = Math.min(
|
||||
// calculate the horizontal center of the selection
|
||||
const halfSelection =
|
||||
Math.abs(selectionBounds.right - selectionBounds.left) / 2;
|
||||
const centerOfSelection = selectionBounds.left + halfSelection;
|
||||
|
||||
// position the menu so that it is centered over the selection except in
|
||||
// the cases where it would extend off the edge of the screen. In these
|
||||
// instances leave a margin
|
||||
const margin = 12;
|
||||
const left = Math.min(
|
||||
Math.min(
|
||||
offsetParent.x + offsetParent.width - menuWidth - margin,
|
||||
window.innerWidth - margin
|
||||
),
|
||||
Math.max(
|
||||
Math.max(offsetParent.x, margin),
|
||||
centerOfSelection - menuWidth / 2
|
||||
)
|
||||
);
|
||||
const top = Math.max(
|
||||
HEADER_HEIGHT,
|
||||
Math.min(
|
||||
window.innerHeight - menuHeight - margin,
|
||||
Math.max(margin, selectionBounds.top - menuHeight)
|
||||
);
|
||||
)
|
||||
);
|
||||
|
||||
// if the menu has been offset to not extend offscreen then we should adjust
|
||||
// the position of the triangle underneath to correctly point to the center
|
||||
// of the selection still
|
||||
const offset = left - (centerOfSelection - menuWidth / 2);
|
||||
return {
|
||||
left: Math.round(left - offsetParent.left),
|
||||
top: Math.round(top - offsetParent.top),
|
||||
offset: Math.round(offset),
|
||||
maxWidth: Math.min(window.innerWidth - margin * 2, offsetParent.width),
|
||||
blockSelection: codeBlock || isColSelection || isRowSelection,
|
||||
visible: true,
|
||||
};
|
||||
}
|
||||
// if the menu has been offset to not extend offscreen then we should adjust
|
||||
// the position of the triangle underneath to correctly point to the center
|
||||
// of the selection still
|
||||
const offset = left - (centerOfSelection - menuWidth / 2);
|
||||
return {
|
||||
left: Math.round(left - offsetParent.left),
|
||||
top: Math.round(top - offsetParent.top),
|
||||
offset: Math.round(offset),
|
||||
maxWidth: Math.min(window.innerWidth - margin * 2, offsetParent.width),
|
||||
blockSelection: codeBlock || isColSelection || isRowSelection,
|
||||
visible: true,
|
||||
};
|
||||
}
|
||||
|
||||
const FloatingToolbar = React.forwardRef(function FloatingToolbar_(
|
||||
|
||||
@@ -216,8 +216,7 @@ export default function SelectionToolbar(props: Props) {
|
||||
const colIndex = getColumnIndex(state);
|
||||
const rowIndex = getRowIndex(state);
|
||||
const isTableSelection = colIndex !== undefined && rowIndex !== undefined;
|
||||
const link = isMarkActive(state.schema.marks.link)(state);
|
||||
const range = getMarkRange(selection.$from, state.schema.marks.link);
|
||||
const link = getMarkRange(selection.$from, state.schema.marks.link);
|
||||
const isImageSelection =
|
||||
selection instanceof NodeSelection && selection.node.type.name === "image";
|
||||
const isAttachmentSelection =
|
||||
@@ -266,7 +265,8 @@ export default function SelectionToolbar(props: Props) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const showLinkToolbar = link && range;
|
||||
const showLinkToolbar =
|
||||
link && link.from === selection.from && link.to === selection.to;
|
||||
|
||||
return (
|
||||
<FloatingToolbar
|
||||
@@ -276,12 +276,12 @@ export default function SelectionToolbar(props: Props) {
|
||||
>
|
||||
{showLinkToolbar ? (
|
||||
<LinkEditor
|
||||
key={`${range.from}-${range.to}`}
|
||||
key={`${link.from}-${link.to}`}
|
||||
dictionary={dictionary}
|
||||
view={view}
|
||||
mark={range.mark}
|
||||
from={range.from}
|
||||
to={range.to}
|
||||
mark={link.mark}
|
||||
from={link.from}
|
||||
to={link.to}
|
||||
onClickLink={props.onClickLink}
|
||||
onSearchLink={props.onSearchLink}
|
||||
onCreateLink={onCreateLink ? handleOnCreateLink : undefined}
|
||||
|
||||
@@ -8,7 +8,7 @@ export default class MentionMenuExtension extends Suggestion {
|
||||
get defaultOptions() {
|
||||
return {
|
||||
// ported from https://github.com/tc39/proposal-regexp-unicode-property-escapes#unicode-aware-version-of-w
|
||||
openRegex: /(?:^|\s|\()@([\p{L}\p{M}\d\s{1}]+)?$/u,
|
||||
openRegex: /(?:^|\s|\()@([\p{L}\p{M}\d\s{1}@\.]+)?$/u,
|
||||
closeRegex: /(?:^|\s|\()@(([\p{L}\p{M}\d]*\s{2})|(\s+[\p{L}\p{M}\d]+))$/u,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -90,14 +90,8 @@ export default class PasteHandler extends Extension {
|
||||
},
|
||||
},
|
||||
handlePaste: (view, event: ClipboardEvent) => {
|
||||
// Do nothing if the document isn't currently editable
|
||||
if (!view.editable) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Default behavior if there is nothing on the clipboard or were
|
||||
// special pasting with no formatting (Shift held)
|
||||
if (!event.clipboardData || this.shiftKey) {
|
||||
// Do nothing if the document isn't currently editable or there is no clipboard data
|
||||
if (!view.editable || !event.clipboardData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -137,76 +131,6 @@ export default class PasteHandler extends Extension {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if the clipboard contents can be parsed as a single url
|
||||
if (isUrl(text)) {
|
||||
// If there is selected text then we want to wrap it in a link to the url
|
||||
if (!state.selection.empty) {
|
||||
toggleMark(this.editor.schema.marks.link, { href: text })(
|
||||
state,
|
||||
dispatch
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Is this link embeddable? Create an embed!
|
||||
const { embeds } = this.editor.props;
|
||||
if (
|
||||
embeds &&
|
||||
this.editor.commands.embed &&
|
||||
!isInCode(state) &&
|
||||
!isInList(state)
|
||||
) {
|
||||
for (const embed of embeds) {
|
||||
if (!embed.matchOnInput) {
|
||||
continue;
|
||||
}
|
||||
const matches = embed.matcher(text);
|
||||
if (matches) {
|
||||
this.editor.commands.embed({
|
||||
href: text,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Is the link a link to a document? If so, we can grab the title and insert it.
|
||||
if (isDocumentUrl(text)) {
|
||||
const slug = parseDocumentSlug(text);
|
||||
|
||||
if (slug) {
|
||||
void stores.documents
|
||||
.fetch(slug)
|
||||
.then((document) => {
|
||||
if (view.isDestroyed) {
|
||||
return;
|
||||
}
|
||||
if (document) {
|
||||
const { hash } = new URL(text);
|
||||
|
||||
const hasEmoji =
|
||||
determineIconType(document.icon) === IconType.Emoji;
|
||||
|
||||
const title = `${hasEmoji ? document.icon + " " : ""}${
|
||||
document.titleWithDefault
|
||||
}`;
|
||||
insertLink(`${document.path}${hash}`, title);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
if (view.isDestroyed) {
|
||||
return;
|
||||
}
|
||||
insertLink(text);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
insertLink(text);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Because VSCode is an especially popular editor that places metadata
|
||||
// on the clipboard, we can parse it to find out what kind of content
|
||||
// was pasted.
|
||||
@@ -215,52 +139,129 @@ export default class PasteHandler extends Extension {
|
||||
const supportsCodeBlock = !!state.schema.nodes.code_block;
|
||||
const supportsCodeMark = !!state.schema.marks.code_inline;
|
||||
|
||||
if (pasteCodeLanguage && pasteCodeLanguage !== "markdown") {
|
||||
if (text.includes("\n") && supportsCodeBlock) {
|
||||
event.preventDefault();
|
||||
view.dispatch(
|
||||
state.tr
|
||||
.replaceSelectionWith(
|
||||
state.schema.nodes.code_block.create({
|
||||
language: Object.keys(LANGUAGES).includes(
|
||||
vscodeMeta.mode
|
||||
)
|
||||
? vscodeMeta.mode
|
||||
: null,
|
||||
if (!this.shiftKey) {
|
||||
// Check if the clipboard contents can be parsed as a single url
|
||||
if (isUrl(text)) {
|
||||
// If there is selected text then we want to wrap it in a link to the url
|
||||
if (!state.selection.empty) {
|
||||
toggleMark(this.editor.schema.marks.link, { href: text })(
|
||||
state,
|
||||
dispatch
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Is this link embeddable? Create an embed!
|
||||
const { embeds } = this.editor.props;
|
||||
if (
|
||||
embeds &&
|
||||
this.editor.commands.embed &&
|
||||
!isInCode(state) &&
|
||||
!isInList(state)
|
||||
) {
|
||||
for (const embed of embeds) {
|
||||
if (!embed.matchOnInput) {
|
||||
continue;
|
||||
}
|
||||
const matches = embed.matcher(text);
|
||||
if (matches) {
|
||||
this.editor.commands.embed({
|
||||
href: text,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Is the link a link to a document? If so, we can grab the title and insert it.
|
||||
if (isDocumentUrl(text)) {
|
||||
const slug = parseDocumentSlug(text);
|
||||
|
||||
if (slug) {
|
||||
void stores.documents
|
||||
.fetch(slug)
|
||||
.then((document) => {
|
||||
if (view.isDestroyed) {
|
||||
return;
|
||||
}
|
||||
if (document) {
|
||||
const { hash } = new URL(text);
|
||||
|
||||
const hasEmoji =
|
||||
determineIconType(document.icon) === IconType.Emoji;
|
||||
|
||||
const title = `${
|
||||
hasEmoji ? document.icon + " " : ""
|
||||
}${document.titleWithDefault}`;
|
||||
insertLink(`${document.path}${hash}`, title);
|
||||
}
|
||||
})
|
||||
)
|
||||
.insertText(text)
|
||||
);
|
||||
.catch(() => {
|
||||
if (view.isDestroyed) {
|
||||
return;
|
||||
}
|
||||
insertLink(text);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
insertLink(text);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (supportsCodeMark) {
|
||||
event.preventDefault();
|
||||
view.dispatch(
|
||||
state.tr
|
||||
.insertText(text, state.selection.from, state.selection.to)
|
||||
.addMark(
|
||||
state.selection.from,
|
||||
state.selection.to + text.length,
|
||||
state.schema.marks.code_inline.create()
|
||||
)
|
||||
);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (pasteCodeLanguage && pasteCodeLanguage !== "markdown") {
|
||||
if (text.includes("\n") && supportsCodeBlock) {
|
||||
event.preventDefault();
|
||||
view.dispatch(
|
||||
state.tr
|
||||
.replaceSelectionWith(
|
||||
state.schema.nodes.code_block.create({
|
||||
language: Object.keys(LANGUAGES).includes(
|
||||
vscodeMeta.mode
|
||||
)
|
||||
? vscodeMeta.mode
|
||||
: null,
|
||||
})
|
||||
)
|
||||
.insertText(text)
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
// If the HTML on the clipboard is from Prosemirror then the best
|
||||
// compatability is to just use the HTML parser, regardless of
|
||||
// whether it "looks" like Markdown, see: outline/outline#2416
|
||||
if (html?.includes("data-pm-slice")) {
|
||||
return false;
|
||||
if (supportsCodeMark) {
|
||||
event.preventDefault();
|
||||
view.dispatch(
|
||||
state.tr
|
||||
.insertText(
|
||||
text,
|
||||
state.selection.from,
|
||||
state.selection.to
|
||||
)
|
||||
.addMark(
|
||||
state.selection.from,
|
||||
state.selection.to + text.length,
|
||||
state.schema.marks.code_inline.create()
|
||||
)
|
||||
);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// If the HTML on the clipboard is from Prosemirror then the best
|
||||
// compatability is to just use the HTML parser, regardless of
|
||||
// whether it "looks" like Markdown, see: outline/outline#2416
|
||||
if (html?.includes("data-pm-slice")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// If the text on the clipboard looks like Markdown OR there is no
|
||||
// html on the clipboard then try to parse content as Markdown
|
||||
if (
|
||||
(isMarkdown(text) && !isDropboxPaper(html)) ||
|
||||
pasteCodeLanguage === "markdown"
|
||||
pasteCodeLanguage === "markdown" ||
|
||||
this.shiftKey
|
||||
) {
|
||||
event.preventDefault();
|
||||
|
||||
|
||||
@@ -30,19 +30,23 @@ export default class SmartText extends Extension {
|
||||
}
|
||||
|
||||
inputRules() {
|
||||
return [
|
||||
rightArrow,
|
||||
emdash,
|
||||
oneHalf,
|
||||
threeQuarters,
|
||||
copyright,
|
||||
registered,
|
||||
trademarked,
|
||||
ellipsis,
|
||||
openDoubleQuote,
|
||||
closeDoubleQuote,
|
||||
openSingleQuote,
|
||||
closeSingleQuote,
|
||||
];
|
||||
if (this.options.userPreferences?.enableSmartText ?? true) {
|
||||
return [
|
||||
rightArrow,
|
||||
emdash,
|
||||
oneHalf,
|
||||
threeQuarters,
|
||||
copyright,
|
||||
registered,
|
||||
trademarked,
|
||||
ellipsis,
|
||||
openDoubleQuote,
|
||||
closeDoubleQuote,
|
||||
openSingleQuote,
|
||||
closeSingleQuote,
|
||||
];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
+28
-1
@@ -91,6 +91,10 @@ export type Props = {
|
||||
scrollTo?: string;
|
||||
/** Callback for handling uploaded images, should return the url of uploaded file */
|
||||
uploadFile?: (file: File) => Promise<string>;
|
||||
/** Callback when prosemirror nodes are initialized on document mount. */
|
||||
onInit?: () => void;
|
||||
/** Callback when prosemirror nodes are destroyed on document unmount. */
|
||||
onDestroy?: () => void;
|
||||
/** Callback when editor is blurred, as native input */
|
||||
onBlur?: () => void;
|
||||
/** Callback when editor is focused, as native input */
|
||||
@@ -176,6 +180,7 @@ export class Editor extends React.PureComponent<
|
||||
linkToolbarOpen: false,
|
||||
};
|
||||
|
||||
isInitialized = false;
|
||||
isBlurred = true;
|
||||
extensions: ExtensionManager;
|
||||
elementRef = React.createRef<HTMLDivElement>();
|
||||
@@ -283,6 +288,7 @@ export class Editor extends React.PureComponent<
|
||||
window.removeEventListener("theme-changed", this.dispatchThemeChanged);
|
||||
this.view?.destroy();
|
||||
this.mutationObserver?.disconnect();
|
||||
this.handleEditorDestroy();
|
||||
}
|
||||
|
||||
private init() {
|
||||
@@ -482,6 +488,8 @@ export class Editor extends React.PureComponent<
|
||||
self.handleChange();
|
||||
}
|
||||
|
||||
self.handleEditorInit();
|
||||
|
||||
self.calculateDir();
|
||||
|
||||
// Because Prosemirror and React are not linked we must tell React that
|
||||
@@ -682,7 +690,10 @@ export class Editor extends React.PureComponent<
|
||||
* @param commentId The id of the comment to remove
|
||||
* @param attrs The attributes to update
|
||||
*/
|
||||
public updateComment = (commentId: string, attrs: { resolved: boolean }) => {
|
||||
public updateComment = (
|
||||
commentId: string,
|
||||
attrs: { resolved?: boolean; draft?: boolean }
|
||||
) => {
|
||||
const { state, dispatch } = this.view;
|
||||
const tr = state.tr;
|
||||
|
||||
@@ -740,6 +751,22 @@ export class Editor extends React.PureComponent<
|
||||
);
|
||||
};
|
||||
|
||||
private handleEditorInit = () => {
|
||||
if (!this.props.onInit || this.isInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.props.onInit();
|
||||
this.isInitialized = true;
|
||||
};
|
||||
|
||||
private handleEditorDestroy = () => {
|
||||
if (!this.props.onDestroy) {
|
||||
return;
|
||||
}
|
||||
this.props.onDestroy();
|
||||
};
|
||||
|
||||
private handleEditorBlur = () => {
|
||||
this.setState({ isEditorFocused: false });
|
||||
return false;
|
||||
|
||||
@@ -214,7 +214,6 @@ export default function formattingMenuItems(
|
||||
name: "link",
|
||||
tooltip: dictionary.createLink,
|
||||
icon: <LinkIcon />,
|
||||
active: isMarkActive(schema.marks.link),
|
||||
attrs: { href: "" },
|
||||
visible: !isCodeBlock && (!isMobile || !isEmpty),
|
||||
},
|
||||
|
||||
@@ -11,10 +11,11 @@ export default function readOnlyMenuItems(
|
||||
dictionary: Dictionary
|
||||
): MenuItem[] {
|
||||
const { schema } = state;
|
||||
const isEmpty = state.selection.empty;
|
||||
|
||||
return [
|
||||
{
|
||||
visible: canUpdate,
|
||||
visible: canUpdate && !isEmpty,
|
||||
name: "comment",
|
||||
tooltip: dictionary.comment,
|
||||
label: dictionary.comment,
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import React from "react";
|
||||
import useUnmount from "./useUnmount";
|
||||
|
||||
type Props = {
|
||||
/** Ref to the element that needs to be observed. */
|
||||
ref: React.RefObject<HTMLElement>;
|
||||
/** Duration to wait until it's considered as a hover event. */
|
||||
duration: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* Hook that will trigger the first time an element is hovered.
|
||||
*
|
||||
* @returns {boolean} hovered - Signals when an element is hovered by the user.
|
||||
*/
|
||||
const useHover = ({ ref, duration }: Props): boolean => {
|
||||
const [hovered, setHovered] = React.useState(false);
|
||||
const timer = React.useRef<number>();
|
||||
|
||||
const onMouseEnter = React.useCallback(() => {
|
||||
if (timer.current) {
|
||||
clearTimeout(timer.current);
|
||||
}
|
||||
|
||||
timer.current = window.setTimeout(() => setHovered(true), duration);
|
||||
}, [duration]);
|
||||
|
||||
const onMouseLeave = React.useCallback(() => {
|
||||
if (timer.current) {
|
||||
clearTimeout(timer.current);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useUnmount(() => {
|
||||
if (timer.current) {
|
||||
clearTimeout(timer.current);
|
||||
}
|
||||
});
|
||||
|
||||
React.useEffect(() => {
|
||||
if (ref.current) {
|
||||
ref.current.onmouseenter = onMouseEnter;
|
||||
ref.current.onmouseleave = onMouseLeave;
|
||||
}
|
||||
}, [ref, onMouseEnter, onMouseLeave]);
|
||||
|
||||
return hovered;
|
||||
};
|
||||
|
||||
export default useHover;
|
||||
@@ -23,6 +23,6 @@ export default function useOnClickOutside(
|
||||
[ref, callback]
|
||||
);
|
||||
|
||||
useEventListener("mousedown", listener, window, options);
|
||||
useEventListener("pointerdown", listener, window, options);
|
||||
useEventListener("touchstart", listener, window, options);
|
||||
}
|
||||
@@ -124,6 +124,8 @@ function CollectionMenu({
|
||||
} catch (err) {
|
||||
toast.error(err.message);
|
||||
throw err;
|
||||
} finally {
|
||||
ev.target.value = "";
|
||||
}
|
||||
},
|
||||
[history, collection.id, documents]
|
||||
|
||||
+50
-41
@@ -15,6 +15,7 @@ import {
|
||||
deleteCommentFactory,
|
||||
resolveCommentFactory,
|
||||
unresolveCommentFactory,
|
||||
viewCommentReactionsFactory,
|
||||
} from "~/actions/definitions/comments";
|
||||
import useActionContext from "~/hooks/useActionContext";
|
||||
import usePolicy from "~/hooks/usePolicy";
|
||||
@@ -66,47 +67,55 @@ function CommentMenu({
|
||||
{...menu}
|
||||
/>
|
||||
</EventBoundary>
|
||||
<ContextMenu {...menu} aria-label={t("Comment options")}>
|
||||
<Template
|
||||
{...menu}
|
||||
items={[
|
||||
{
|
||||
type: "button",
|
||||
title: `${t("Edit")}…`,
|
||||
icon: <EditIcon />,
|
||||
onClick: onEdit,
|
||||
visible: can.update && !comment.isResolved,
|
||||
},
|
||||
actionToMenuItem(
|
||||
resolveCommentFactory({
|
||||
comment,
|
||||
onResolve: () => onUpdate({ resolved: true }),
|
||||
}),
|
||||
context
|
||||
),
|
||||
actionToMenuItem(
|
||||
unresolveCommentFactory({
|
||||
comment,
|
||||
onUnresolve: () => onUpdate({ resolved: false }),
|
||||
}),
|
||||
context
|
||||
),
|
||||
{
|
||||
type: "button",
|
||||
icon: <CopyIcon />,
|
||||
title: t("Copy link"),
|
||||
onClick: handleCopyLink,
|
||||
},
|
||||
{
|
||||
type: "separator",
|
||||
},
|
||||
actionToMenuItem(
|
||||
deleteCommentFactory({ comment, onDelete }),
|
||||
context
|
||||
),
|
||||
]}
|
||||
/>
|
||||
</ContextMenu>
|
||||
{menu.visible && (
|
||||
<ContextMenu {...menu} aria-label={t("Comment options")}>
|
||||
<Template
|
||||
{...menu}
|
||||
items={[
|
||||
{
|
||||
type: "button",
|
||||
title: `${t("Edit")}…`,
|
||||
icon: <EditIcon />,
|
||||
onClick: onEdit,
|
||||
visible: can.update && !comment.isResolved,
|
||||
},
|
||||
actionToMenuItem(
|
||||
resolveCommentFactory({
|
||||
comment,
|
||||
onResolve: () => onUpdate({ resolved: true }),
|
||||
}),
|
||||
context
|
||||
),
|
||||
actionToMenuItem(
|
||||
unresolveCommentFactory({
|
||||
comment,
|
||||
onUnresolve: () => onUpdate({ resolved: false }),
|
||||
}),
|
||||
context
|
||||
),
|
||||
actionToMenuItem(
|
||||
viewCommentReactionsFactory({
|
||||
comment,
|
||||
}),
|
||||
context
|
||||
),
|
||||
{
|
||||
type: "button",
|
||||
icon: <CopyIcon />,
|
||||
title: t("Copy link"),
|
||||
onClick: handleCopyLink,
|
||||
},
|
||||
{
|
||||
type: "separator",
|
||||
},
|
||||
actionToMenuItem(
|
||||
deleteCommentFactory({ comment, onDelete }),
|
||||
context
|
||||
),
|
||||
]}
|
||||
/>
|
||||
</ContextMenu>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ import {
|
||||
shareDocument,
|
||||
copyDocument,
|
||||
searchInDocument,
|
||||
leaveDocument,
|
||||
moveTemplate,
|
||||
} from "~/actions/definitions/documents";
|
||||
import useActionContext from "~/hooks/useActionContext";
|
||||
@@ -298,6 +299,7 @@ const MenuContent: React.FC<MenuContentProps> = ({
|
||||
},
|
||||
actionToMenuItem(deleteDocument, context),
|
||||
actionToMenuItem(permanentlyDeleteDocument, context),
|
||||
actionToMenuItem(leaveDocument, context),
|
||||
]}
|
||||
/>
|
||||
{(showDisplayOptions || showToggleEmbeds) && can.update && (
|
||||
@@ -407,6 +409,8 @@ function DocumentMenu({
|
||||
} catch (err) {
|
||||
toast.error(err.message);
|
||||
throw err;
|
||||
} finally {
|
||||
ev.target.value = "";
|
||||
}
|
||||
},
|
||||
[history, collection, documents, document.id]
|
||||
|
||||
@@ -4,7 +4,10 @@ import { useTranslation } from "react-i18next";
|
||||
import { MenuButton, useMenuState } from "reakit/Menu";
|
||||
import ContextMenu from "~/components/ContextMenu";
|
||||
import Template from "~/components/ContextMenu/Template";
|
||||
import { navigateToSettings, logout } from "~/actions/definitions/navigation";
|
||||
import {
|
||||
navigateToWorkspaceSettings,
|
||||
logout,
|
||||
} from "~/actions/definitions/navigation";
|
||||
import {
|
||||
createTeam,
|
||||
createTeamsList,
|
||||
@@ -45,7 +48,7 @@ const OrganizationMenu: React.FC = ({ children }: Props) => {
|
||||
createTeam,
|
||||
desktopLoginTeam,
|
||||
separator(),
|
||||
navigateToSettings,
|
||||
navigateToWorkspaceSettings,
|
||||
logout,
|
||||
],
|
||||
[context]
|
||||
|
||||
+176
-3
@@ -1,8 +1,12 @@
|
||||
import { subSeconds } from "date-fns";
|
||||
import { computed, observable } from "mobx";
|
||||
import invariant from "invariant";
|
||||
import uniq from "lodash/uniq";
|
||||
import { action, computed, observable } from "mobx";
|
||||
import { now } from "mobx-utils";
|
||||
import type { ProsemirrorData } from "@shared/types";
|
||||
import { Pagination } from "@shared/constants";
|
||||
import type { ProsemirrorData, ReactionSummary } from "@shared/types";
|
||||
import User from "~/models/User";
|
||||
import { client } from "~/utils/ApiClient";
|
||||
import Document from "./Document";
|
||||
import Model from "./base/Model";
|
||||
import Field from "./decorators/Field";
|
||||
@@ -26,7 +30,7 @@ class Comment extends Model {
|
||||
* The Prosemirror data representing the comment content
|
||||
*/
|
||||
@Field
|
||||
@observable
|
||||
@observable.shallow
|
||||
data: ProsemirrorData;
|
||||
|
||||
/**
|
||||
@@ -84,6 +88,25 @@ class Comment extends Model {
|
||||
*/
|
||||
resolvedById: string | null;
|
||||
|
||||
/**
|
||||
* Active reactions for this comment.
|
||||
*
|
||||
* Note: This contains just the emoji with the associated user-ids.
|
||||
*/
|
||||
@observable
|
||||
reactions: ReactionSummary[];
|
||||
|
||||
/**
|
||||
* Denotes whether the user data for the active reactions are loaded.
|
||||
*/
|
||||
@observable
|
||||
reactedUsersLoaded: boolean = false;
|
||||
|
||||
/**
|
||||
* Denotes whether there is an in-flight request for loading reacted users.
|
||||
*/
|
||||
private reactedUsersLoading = false;
|
||||
|
||||
/**
|
||||
* An array of users that are currently typing a reply in this comments thread.
|
||||
*/
|
||||
@@ -124,6 +147,156 @@ class Comment extends Model {
|
||||
public unresolve() {
|
||||
return this.store.rootStore.comments.unresolve(this.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an emoji as a reaction to this comment.
|
||||
*
|
||||
* Optimistically updates the `reactions` cache and invokes the backend API.
|
||||
*
|
||||
* @param {Object} reaction - The reaction data.
|
||||
* @param {string} reaction.emoji - The emoji to add as a reaction.
|
||||
* @param {string} reaction.user - The user who added this reaction.
|
||||
*/
|
||||
@action
|
||||
public addReaction = async ({
|
||||
emoji,
|
||||
user,
|
||||
}: {
|
||||
emoji: string;
|
||||
user: User;
|
||||
}) => {
|
||||
this.updateReaction({ type: "add", emoji, user });
|
||||
try {
|
||||
await client.post("/comments.add_reaction", {
|
||||
id: this.id,
|
||||
emoji,
|
||||
});
|
||||
} catch {
|
||||
this.updateReaction({ type: "remove", emoji, user });
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove an emoji as a reaction from this comment.
|
||||
*
|
||||
* Optimistically updates the `reactions` cache and invokes the backend API.
|
||||
*
|
||||
* @param {Object} reaction - The reaction data.
|
||||
* @param {string} reaction.emoji - The emoji to remove as a reaction.
|
||||
* @param {string} reaction.user - The user who removed this reaction.
|
||||
*/
|
||||
@action
|
||||
public removeReaction = async ({
|
||||
emoji,
|
||||
user,
|
||||
}: {
|
||||
emoji: string;
|
||||
user: User;
|
||||
}) => {
|
||||
this.updateReaction({ type: "remove", emoji, user });
|
||||
try {
|
||||
await client.post("/comments.remove_reaction", {
|
||||
id: this.id,
|
||||
emoji,
|
||||
});
|
||||
} catch {
|
||||
this.updateReaction({ type: "add", emoji, user });
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Update the `reactions` cache.
|
||||
*
|
||||
* @param {Object} reaction - The reaction data.
|
||||
* @param {string} reaction.type - The type of the action.
|
||||
* @param {string} reaction.emoji - The emoji to update as a reaction.
|
||||
* @param {string} reaction.user - The user who performed this action.
|
||||
*/
|
||||
@action
|
||||
public updateReaction = ({
|
||||
type,
|
||||
emoji,
|
||||
user,
|
||||
}: {
|
||||
type: "add" | "remove";
|
||||
emoji: string;
|
||||
user: User;
|
||||
}) => {
|
||||
const reaction = this.reactions.find((r) => r.emoji === emoji);
|
||||
|
||||
// Step 1: Update the reactions cache.
|
||||
|
||||
if (type === "add") {
|
||||
if (!reaction) {
|
||||
this.reactions.push({ emoji, userIds: [user.id] });
|
||||
} else {
|
||||
reaction.userIds = uniq([...reaction.userIds, user.id]);
|
||||
}
|
||||
} else {
|
||||
if (reaction) {
|
||||
reaction.userIds = reaction.userIds.filter((id) => id !== user.id);
|
||||
}
|
||||
|
||||
if (reaction?.userIds.length === 0) {
|
||||
this.reactions = this.reactions.filter(
|
||||
(r) => r.emoji !== reaction.emoji
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2: Add the user to the store.
|
||||
this.store.rootStore.users.add(user);
|
||||
};
|
||||
|
||||
/**
|
||||
* Load the users for the active reactions.
|
||||
*
|
||||
*
|
||||
* @param {Object} options - Options for loading the data.
|
||||
* @param {string} options.limit - Per request limit for pagination.
|
||||
*/
|
||||
@action
|
||||
loadReactedUsersData = async (
|
||||
{ limit }: { limit: number } = { limit: Pagination.defaultLimit }
|
||||
) => {
|
||||
if (this.reactedUsersLoading || this.reactedUsersLoaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.reactedUsersLoading = true;
|
||||
|
||||
try {
|
||||
const fetchPage = async (offset: number = 0) => {
|
||||
const res = await client.post("/reactions.list", {
|
||||
commentId: this.id,
|
||||
offset,
|
||||
limit,
|
||||
});
|
||||
|
||||
invariant(res?.data, "Data not available");
|
||||
// @ts-expect-error reaction from server response
|
||||
res.data.map((reaction) =>
|
||||
this.store.rootStore.users.add(reaction.user)
|
||||
);
|
||||
|
||||
return res.pagination;
|
||||
};
|
||||
|
||||
const { total } = await fetchPage();
|
||||
|
||||
const pages = Math.ceil(total / limit);
|
||||
const fetchPages = [];
|
||||
for (let page = 1; page < pages; page++) {
|
||||
fetchPages.push(fetchPage(page * limit));
|
||||
}
|
||||
|
||||
await Promise.all(fetchPages);
|
||||
|
||||
this.reactedUsersLoaded = true;
|
||||
} finally {
|
||||
this.reactedUsersLoading = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default Comment;
|
||||
@@ -254,7 +254,8 @@ export default class Document extends ArchivableModel {
|
||||
|
||||
@computed
|
||||
get path(): string {
|
||||
const prefix = this.template ? settingsPath("templates") : "/doc";
|
||||
const prefix =
|
||||
this.template && !this.isDeleted ? settingsPath("templates") : "/doc";
|
||||
|
||||
if (!this.title) {
|
||||
return `${prefix}/untitled-${this.urlId}`;
|
||||
|
||||
+18
-11
@@ -1,21 +1,29 @@
|
||||
import Collection from "./Collection";
|
||||
import Document from "./Document";
|
||||
import User from "./User";
|
||||
import Model from "./base/Model";
|
||||
import Relation from "./decorators/Relation";
|
||||
|
||||
class Event extends Model {
|
||||
class Event<T extends Model> extends Model {
|
||||
static modelName = "Event";
|
||||
|
||||
id: string;
|
||||
|
||||
name: string;
|
||||
|
||||
modelId: string | null | undefined;
|
||||
modelId: string | undefined;
|
||||
|
||||
actorIpAddress: string | null | undefined;
|
||||
|
||||
documentId: string;
|
||||
@Relation(() => Document)
|
||||
document: Document;
|
||||
|
||||
collectionId: string | null | undefined;
|
||||
documentId: string | undefined;
|
||||
|
||||
@Relation(() => Collection)
|
||||
collection: Collection;
|
||||
|
||||
collectionId: string | undefined;
|
||||
|
||||
@Relation(() => User)
|
||||
user: User;
|
||||
@@ -27,13 +35,12 @@ class Event extends Model {
|
||||
|
||||
actorId: string;
|
||||
|
||||
data: {
|
||||
name: string;
|
||||
email: string;
|
||||
title: string;
|
||||
published: boolean;
|
||||
templateId: string;
|
||||
};
|
||||
data: Partial<T> | null;
|
||||
|
||||
changes: {
|
||||
attributes: Partial<T>;
|
||||
previous: Partial<T>;
|
||||
} | null;
|
||||
}
|
||||
|
||||
export default Event;
|
||||
@@ -55,6 +55,10 @@ class Share extends Model {
|
||||
@observable
|
||||
url: string;
|
||||
|
||||
@Field
|
||||
@observable
|
||||
allowIndexing: boolean;
|
||||
|
||||
/** The user that shared the document. */
|
||||
@Relation(() => User, { onDelete: "null" })
|
||||
createdBy: User;
|
||||
|
||||
@@ -50,6 +50,10 @@ class User extends ParanoidModel {
|
||||
@observable
|
||||
notificationSettings: NotificationSettings;
|
||||
|
||||
@Field
|
||||
@observable
|
||||
timezone?: string;
|
||||
|
||||
@observable
|
||||
email: string;
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ function ApiKeyNew({ onSubmit }: Props) {
|
||||
value={expiryType}
|
||||
options={expiryOptions}
|
||||
onChange={handleExpiryTypeChange}
|
||||
skipBodyScroll={true}
|
||||
skipBodyScroll
|
||||
/>
|
||||
{expiryType === ExpiryType.Custom ? (
|
||||
<ExpiryDatePicker
|
||||
|
||||
@@ -172,7 +172,8 @@ function SharedDocumentScene(props: Props) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!response) {
|
||||
// Note: `sharedTree` will be null when `includeChildDocuments` = false
|
||||
if (response?.sharedTree === undefined) {
|
||||
return <Loading location={props.location} />;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { observer } from "mobx-react";
|
||||
import * as React from "react";
|
||||
import { basicExtensions, withComments } from "@shared/editor/nodes";
|
||||
import HardBreak from "@shared/editor/nodes/HardBreak";
|
||||
@@ -36,4 +37,4 @@ const CommentEditor = (
|
||||
);
|
||||
};
|
||||
|
||||
export default React.forwardRef(CommentEditor);
|
||||
export default observer(React.forwardRef(CommentEditor));
|
||||
@@ -27,6 +27,8 @@ import { Bubble } from "./CommentThreadItem";
|
||||
import { HighlightedText } from "./HighlightText";
|
||||
|
||||
type Props = {
|
||||
/** Callback when the form is submitted. */
|
||||
onSubmit?: () => void;
|
||||
/** Callback when the draft should be saved. */
|
||||
onSaveDraft: (data: ProsemirrorData | undefined) => void;
|
||||
/** A draft comment for this thread. */
|
||||
@@ -59,6 +61,7 @@ function CommentForm({
|
||||
documentId,
|
||||
thread,
|
||||
draft,
|
||||
onSubmit,
|
||||
onSaveDraft,
|
||||
onTyping,
|
||||
onFocus,
|
||||
@@ -109,6 +112,7 @@ function CommentForm({
|
||||
createdAt: new Date().toISOString(),
|
||||
documentId,
|
||||
data: draft,
|
||||
reactions: [],
|
||||
},
|
||||
comments
|
||||
);
|
||||
@@ -118,6 +122,7 @@ function CommentForm({
|
||||
documentId,
|
||||
data: draft,
|
||||
})
|
||||
.then(() => onSubmit?.())
|
||||
.catch(() => {
|
||||
comment.isNew = true;
|
||||
toast.error(t("Error creating comment"));
|
||||
@@ -144,6 +149,7 @@ function CommentForm({
|
||||
parentCommentId: thread?.id,
|
||||
documentId,
|
||||
data: draft,
|
||||
reactions: [],
|
||||
},
|
||||
comments
|
||||
);
|
||||
@@ -151,11 +157,14 @@ function CommentForm({
|
||||
comment.id = uuidv4();
|
||||
comments.add(comment);
|
||||
|
||||
comment.save().catch(() => {
|
||||
comments.remove(comment.id);
|
||||
comment.isNew = true;
|
||||
toast.error(t("Error creating comment"));
|
||||
});
|
||||
comment
|
||||
.save()
|
||||
.then(() => onSubmit?.())
|
||||
.catch(() => {
|
||||
comments.remove(comment.id);
|
||||
comment.isNew = true;
|
||||
toast.error(t("Error creating comment"));
|
||||
});
|
||||
|
||||
// optimistically update the comment model
|
||||
comment.isNew = false;
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
import queryString from "query-string";
|
||||
import React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useHistory, useLocation } from "react-router-dom";
|
||||
import styled from "styled-components";
|
||||
import { s } from "@shared/styles";
|
||||
import { UserPreference } from "@shared/types";
|
||||
import InputSelect from "~/components/InputSelect";
|
||||
import useCurrentUser from "~/hooks/useCurrentUser";
|
||||
import useQuery from "~/hooks/useQuery";
|
||||
import { CommentSortType } from "~/types";
|
||||
|
||||
const CommentSortMenu = () => {
|
||||
const { t } = useTranslation();
|
||||
const location = useLocation();
|
||||
const history = useHistory();
|
||||
const user = useCurrentUser();
|
||||
const params = useQuery();
|
||||
|
||||
const viewingResolved = params.get("resolved") === "";
|
||||
const value = viewingResolved
|
||||
? "resolved"
|
||||
: user.getPreference(UserPreference.SortCommentsByOrderInDocument)
|
||||
? CommentSortType.OrderInDocument
|
||||
: CommentSortType.MostRecent;
|
||||
|
||||
const handleSortTypeChange = (type: CommentSortType) => {
|
||||
user.setPreference(
|
||||
UserPreference.SortCommentsByOrderInDocument,
|
||||
type === CommentSortType.OrderInDocument
|
||||
);
|
||||
void user.save();
|
||||
};
|
||||
|
||||
const showResolved = () => {
|
||||
history.push({
|
||||
search: queryString.stringify({
|
||||
...queryString.parse(location.search),
|
||||
resolved: "",
|
||||
}),
|
||||
pathname: location.pathname,
|
||||
});
|
||||
};
|
||||
|
||||
const showUnresolved = () => {
|
||||
history.push({
|
||||
search: queryString.stringify({
|
||||
...queryString.parse(location.search),
|
||||
resolved: undefined,
|
||||
}),
|
||||
pathname: location.pathname,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Select
|
||||
style={{ margin: 0 }}
|
||||
ariaLabel={t("Sort comments")}
|
||||
value={value}
|
||||
onChange={(ev) => {
|
||||
if (ev === "resolved") {
|
||||
showResolved();
|
||||
} else {
|
||||
handleSortTypeChange(ev as CommentSortType);
|
||||
showUnresolved();
|
||||
}
|
||||
}}
|
||||
borderOnHover
|
||||
options={[
|
||||
{ value: CommentSortType.MostRecent, label: t("Most recent") },
|
||||
{ value: CommentSortType.OrderInDocument, label: t("Order in doc") },
|
||||
{
|
||||
divider: true,
|
||||
value: "resolved",
|
||||
label: t("Resolved"),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const Select = styled(InputSelect)`
|
||||
color: ${s("textSecondary")};
|
||||
`;
|
||||
|
||||
export default CommentSortMenu;
|
||||
@@ -36,12 +36,16 @@ type Props = {
|
||||
focused: boolean;
|
||||
/** Whether the thread is displayed in a recessed/backgrounded state */
|
||||
recessed: boolean;
|
||||
/** Enable scroll for the comments container */
|
||||
enableScroll: () => void;
|
||||
/** Disable scroll for the comments container */
|
||||
disableScroll: () => void;
|
||||
};
|
||||
|
||||
function useTypingIndicator({
|
||||
document,
|
||||
comment,
|
||||
}: Omit<Props, "focused" | "recessed">): [undefined, () => void] {
|
||||
}: Pick<Props, "document" | "comment">): [undefined, () => void] {
|
||||
const socket = React.useContext(WebsocketContext);
|
||||
|
||||
const setIsTyping = React.useMemo(
|
||||
@@ -63,6 +67,8 @@ function CommentThread({
|
||||
document,
|
||||
recessed,
|
||||
focused,
|
||||
enableScroll,
|
||||
disableScroll,
|
||||
}: Props) {
|
||||
const [focusedOnMount] = React.useState(focused);
|
||||
const { editor } = useDocumentContext();
|
||||
@@ -80,6 +86,11 @@ function CommentThread({
|
||||
});
|
||||
const can = usePolicy(document);
|
||||
|
||||
const [draft, onSaveDraft] = usePersistedState<ProsemirrorData | undefined>(
|
||||
`draft-${document.id}-${thread.id}`,
|
||||
undefined
|
||||
);
|
||||
|
||||
const canReply = can.comment && !thread.isResolved;
|
||||
|
||||
const highlightedCommentMarks = editor
|
||||
@@ -94,7 +105,8 @@ function CommentThread({
|
||||
useOnClickOutside(topRef, (event) => {
|
||||
if (
|
||||
focused &&
|
||||
!(event.target as HTMLElement).classList.contains("comment")
|
||||
!(event.target as HTMLElement).classList.contains("comment") &&
|
||||
event.defaultPrevented === false
|
||||
) {
|
||||
history.replace({
|
||||
search: location.search,
|
||||
@@ -104,6 +116,10 @@ function CommentThread({
|
||||
}
|
||||
});
|
||||
|
||||
const handleSubmit = React.useCallback(() => {
|
||||
editor?.updateComment(thread.id, { draft: false });
|
||||
}, [editor, thread.id]);
|
||||
|
||||
const handleClickThread = () => {
|
||||
history.replace({
|
||||
// Clear any commentId from the URL when explicitly focusing a thread
|
||||
@@ -167,11 +183,6 @@ function CommentThread({
|
||||
}
|
||||
}, [focused, focusedOnMount, thread.id]);
|
||||
|
||||
const [draft, onSaveDraft] = usePersistedState<ProsemirrorData | undefined>(
|
||||
`draft-${document.id}-${thread.id}`,
|
||||
undefined
|
||||
);
|
||||
|
||||
return (
|
||||
<Thread
|
||||
ref={topRef}
|
||||
@@ -192,8 +203,8 @@ function CommentThread({
|
||||
<CommentThreadItem
|
||||
highlightedText={index === 0 ? highlightedText : undefined}
|
||||
comment={comment}
|
||||
onDelete={() => editor?.removeComment(comment.id)}
|
||||
onUpdate={(attrs) => editor?.updateComment(comment.id, attrs)}
|
||||
onDelete={editor?.removeComment}
|
||||
onUpdate={editor?.updateComment}
|
||||
key={comment.id}
|
||||
firstOfThread={index === 0}
|
||||
lastOfThread={index === commentsInThread.length - 1 && !draft}
|
||||
@@ -202,6 +213,8 @@ function CommentThread({
|
||||
lastOfAuthor={lastOfAuthor}
|
||||
previousCommentCreatedAt={commentsInThread[index - 1]?.createdAt}
|
||||
dir={document.dir}
|
||||
enableScroll={enableScroll}
|
||||
disableScroll={disableScroll}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
@@ -219,6 +232,7 @@ function CommentThread({
|
||||
{(focused || draft || commentsInThread.length === 0) && canReply && (
|
||||
<Fade timing={100}>
|
||||
<CommentForm
|
||||
onSubmit={handleSubmit}
|
||||
onSaveDraft={onSaveDraft}
|
||||
draft={draft}
|
||||
documentId={document.id}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { differenceInMilliseconds } from "date-fns";
|
||||
import { toJS } from "mobx";
|
||||
import { action } from "mobx";
|
||||
import { observer } from "mobx-react";
|
||||
import { darken } from "polished";
|
||||
import * as React from "react";
|
||||
@@ -16,9 +16,12 @@ import Comment from "~/models/Comment";
|
||||
import { Avatar } from "~/components/Avatar";
|
||||
import ButtonSmall from "~/components/ButtonSmall";
|
||||
import Flex from "~/components/Flex";
|
||||
import ReactionList from "~/components/Reactions/ReactionList";
|
||||
import ReactionPicker from "~/components/Reactions/ReactionPicker";
|
||||
import Text from "~/components/Text";
|
||||
import Time from "~/components/Time";
|
||||
import useBoolean from "~/hooks/useBoolean";
|
||||
import useCurrentUser from "~/hooks/useCurrentUser";
|
||||
import CommentMenu from "~/menus/CommentMenu";
|
||||
import { hover } from "~/styles";
|
||||
import CommentEditor from "./CommentEditor";
|
||||
@@ -76,11 +79,15 @@ type Props = {
|
||||
/** Whether the user can reply in the thread */
|
||||
canReply: boolean;
|
||||
/** Callback when the comment has been deleted */
|
||||
onDelete: () => void;
|
||||
onDelete?: (id: string) => void;
|
||||
/** Callback when the comment has been updated */
|
||||
onUpdate: (attrs: { resolved: boolean }) => void;
|
||||
onUpdate?: (id: string, attrs: { resolved: boolean }) => void;
|
||||
/** Text to highlight at the top of the comment */
|
||||
highlightedText?: string;
|
||||
/** Enable scroll for the comments container */
|
||||
enableScroll: () => void;
|
||||
/** Disable scroll for the comments container */
|
||||
disableScroll: () => void;
|
||||
};
|
||||
|
||||
function CommentThreadItem({
|
||||
@@ -94,10 +101,12 @@ function CommentThreadItem({
|
||||
onDelete,
|
||||
onUpdate,
|
||||
highlightedText,
|
||||
enableScroll,
|
||||
disableScroll,
|
||||
}: Props) {
|
||||
const { t } = useTranslation();
|
||||
const [forceRender, setForceRender] = React.useState(0);
|
||||
const [data, setData] = React.useState(toJS(comment.data));
|
||||
const user = useCurrentUser();
|
||||
const [data, setData] = React.useState(comment.data);
|
||||
const showAuthor = firstOfAuthor;
|
||||
const showTime = useShowTime(comment.createdAt, previousCommentCreatedAt);
|
||||
const showEdited =
|
||||
@@ -107,41 +116,62 @@ function CommentThreadItem({
|
||||
const [isEditing, setEditing, setReadOnly] = useBoolean();
|
||||
const formRef = React.useRef<HTMLFormElement>(null);
|
||||
|
||||
const handleChange = (value: (asString: boolean) => ProsemirrorData) => {
|
||||
setData(value(false));
|
||||
};
|
||||
const handleAddReaction = React.useCallback(
|
||||
async (emoji: string) => {
|
||||
await comment.addReaction({ emoji, user });
|
||||
},
|
||||
[comment, user]
|
||||
);
|
||||
|
||||
const handleSave = () => {
|
||||
const handleRemoveReaction = React.useCallback(
|
||||
async (emoji: string) => {
|
||||
await comment.removeReaction({ emoji, user });
|
||||
},
|
||||
[comment, user]
|
||||
);
|
||||
|
||||
const handleUpdate = React.useCallback(
|
||||
(attrs: { resolved: boolean }) => {
|
||||
onUpdate?.(comment.id, attrs);
|
||||
},
|
||||
[comment.id, onUpdate]
|
||||
);
|
||||
|
||||
const handleDelete = React.useCallback(() => {
|
||||
onDelete?.(comment.id);
|
||||
}, [comment.id, onDelete]);
|
||||
|
||||
const handleChange = React.useCallback(
|
||||
(value: (asString: boolean) => ProsemirrorData) => {
|
||||
setData(value(false));
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
const handleSave = React.useCallback(() => {
|
||||
formRef.current?.dispatchEvent(
|
||||
new Event("submit", { cancelable: true, bubbles: true })
|
||||
);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const handleSubmit = async (event: React.FormEvent) => {
|
||||
const handleSubmit = action(async (event: React.FormEvent) => {
|
||||
event.preventDefault();
|
||||
|
||||
try {
|
||||
setReadOnly();
|
||||
await comment.save({
|
||||
data,
|
||||
});
|
||||
comment.data = data;
|
||||
await comment.save();
|
||||
} catch (error) {
|
||||
setEditing();
|
||||
toast.error(t("Error updating comment"));
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
const handleCancel = () => {
|
||||
setData(toJS(comment.data));
|
||||
setData(comment.data);
|
||||
setReadOnly();
|
||||
setForceRender((i) => ++i);
|
||||
};
|
||||
|
||||
React.useEffect(() => {
|
||||
setData(toJS(comment.data));
|
||||
setForceRender((i) => ++i);
|
||||
}, [comment.data]);
|
||||
|
||||
return (
|
||||
<Flex gap={8} align="flex-start" reverse={dir === "rtl"}>
|
||||
{firstOfAuthor && (
|
||||
@@ -186,8 +216,9 @@ function CommentThreadItem({
|
||||
)}
|
||||
<Body ref={formRef} onSubmit={handleSubmit}>
|
||||
<StyledCommentEditor
|
||||
key={`${forceRender}`}
|
||||
key={String(isEditing)}
|
||||
readOnly={!isEditing}
|
||||
value={comment.data}
|
||||
defaultValue={data}
|
||||
onChange={handleChange}
|
||||
onSave={handleSave}
|
||||
@@ -203,16 +234,43 @@ function CommentThreadItem({
|
||||
</ButtonSmall>
|
||||
</Flex>
|
||||
)}
|
||||
{!!comment.reactions.length && (
|
||||
<ReactionListContainer gap={6} align="center">
|
||||
<ReactionList
|
||||
model={comment}
|
||||
onAddReaction={handleAddReaction}
|
||||
onRemoveReaction={handleRemoveReaction}
|
||||
picker={
|
||||
!comment.isResolved ? (
|
||||
<StyledReactionPicker
|
||||
onSelect={handleAddReaction}
|
||||
onOpen={disableScroll}
|
||||
onClose={enableScroll}
|
||||
size={28}
|
||||
/>
|
||||
) : undefined
|
||||
}
|
||||
/>
|
||||
</ReactionListContainer>
|
||||
)}
|
||||
</Body>
|
||||
<EventBoundary>
|
||||
{!isEditing && (
|
||||
<Menu
|
||||
comment={comment}
|
||||
onEdit={setEditing}
|
||||
onDelete={onDelete}
|
||||
onUpdate={onUpdate}
|
||||
dir={dir}
|
||||
/>
|
||||
<Actions gap={4} dir={dir}>
|
||||
{!comment.isResolved && (
|
||||
<StyledReactionPicker
|
||||
onSelect={handleAddReaction}
|
||||
onOpen={disableScroll}
|
||||
onClose={enableScroll}
|
||||
/>
|
||||
)}
|
||||
<StyledMenu
|
||||
comment={comment}
|
||||
onEdit={setEditing}
|
||||
onDelete={handleDelete}
|
||||
onUpdate={handleUpdate}
|
||||
/>
|
||||
</Actions>
|
||||
)}
|
||||
</EventBoundary>
|
||||
</Bubble>
|
||||
@@ -250,21 +308,59 @@ const Body = styled.form`
|
||||
border-radius: 2px;
|
||||
`;
|
||||
|
||||
const Menu = styled(CommentMenu)<{ dir?: "rtl" | "ltr" }>`
|
||||
const StyledMenu = styled(CommentMenu)`
|
||||
color: ${s("textSecondary")};
|
||||
|
||||
svg {
|
||||
fill: currentColor;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
&: ${hover}, &[aria-expanded= "true"] {
|
||||
background: ${s("backgroundQuaternary")};
|
||||
|
||||
svg {
|
||||
opacity: 0.75;
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const StyledReactionPicker = styled(ReactionPicker)`
|
||||
color: ${s("textSecondary")};
|
||||
|
||||
svg {
|
||||
fill: currentColor;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
&: ${hover}, &[aria-expanded= "true"] {
|
||||
background: ${s("backgroundQuaternary")};
|
||||
|
||||
svg {
|
||||
opacity: 0.75;
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const Actions = styled(Flex)<{ dir?: "rtl" | "ltr" }>`
|
||||
position: absolute;
|
||||
left: ${(props) => (props.dir !== "rtl" ? "auto" : "4px")};
|
||||
right: ${(props) => (props.dir === "rtl" ? "auto" : "4px")};
|
||||
top: 4px;
|
||||
opacity: 0;
|
||||
transition: opacity 100ms ease-in-out;
|
||||
color: ${s("textSecondary")};
|
||||
background: ${s("backgroundSecondary")};
|
||||
padding-left: 4px;
|
||||
|
||||
&: ${hover}, &[aria-expanded= "true"] {
|
||||
&:has(${StyledReactionPicker}[aria-expanded="true"], ${StyledMenu}[aria-expanded="true"]) {
|
||||
opacity: 1;
|
||||
background: ${s("sidebarActiveBackground")};
|
||||
}
|
||||
`;
|
||||
|
||||
const ReactionListContainer = styled(Flex)`
|
||||
margin-top: 6px;
|
||||
`;
|
||||
|
||||
const Meta = styled(Text)`
|
||||
margin-bottom: 2px;
|
||||
|
||||
@@ -286,7 +382,7 @@ export const Bubble = styled(Flex)<{
|
||||
flex-grow: 1;
|
||||
font-size: 16px;
|
||||
color: ${s("text")};
|
||||
background: ${s("commentBackground")};
|
||||
background: ${s("backgroundSecondary")};
|
||||
min-width: 2em;
|
||||
margin-bottom: 1px;
|
||||
padding: 8px 12px;
|
||||
@@ -310,7 +406,7 @@ export const Bubble = styled(Flex)<{
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
&: ${hover} ${Menu} {
|
||||
&: ${hover} ${Actions} {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,40 +1,49 @@
|
||||
import { AnimatePresence } from "framer-motion";
|
||||
import { observer } from "mobx-react";
|
||||
import { DoneIcon } from "outline-icons";
|
||||
import queryString from "query-string";
|
||||
import { ArrowIcon } from "outline-icons";
|
||||
import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useHistory, useLocation, useRouteMatch } from "react-router-dom";
|
||||
import styled, { css } from "styled-components";
|
||||
import { ProsemirrorData } from "@shared/types";
|
||||
import Button from "~/components/Button";
|
||||
import { useRouteMatch } from "react-router-dom";
|
||||
import styled from "styled-components";
|
||||
import { ProsemirrorData, UserPreference } from "@shared/types";
|
||||
import ButtonSmall from "~/components/ButtonSmall";
|
||||
import { useDocumentContext } from "~/components/DocumentContext";
|
||||
import Empty from "~/components/Empty";
|
||||
import Fade from "~/components/Fade";
|
||||
import Flex from "~/components/Flex";
|
||||
import Scrollable from "~/components/Scrollable";
|
||||
import Tooltip from "~/components/Tooltip";
|
||||
import useBoolean from "~/hooks/useBoolean";
|
||||
import useCurrentUser from "~/hooks/useCurrentUser";
|
||||
import useFocusedComment from "~/hooks/useFocusedComment";
|
||||
import useKeyDown from "~/hooks/useKeyDown";
|
||||
import usePersistedState from "~/hooks/usePersistedState";
|
||||
import usePolicy from "~/hooks/usePolicy";
|
||||
import useQuery from "~/hooks/useQuery";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import { bigPulse } from "~/styles/animations";
|
||||
import { CommentSortOption, CommentSortType } from "~/types";
|
||||
import CommentForm from "./CommentForm";
|
||||
import CommentSortMenu from "./CommentSortMenu";
|
||||
import CommentThread from "./CommentThread";
|
||||
import Sidebar from "./SidebarLayout";
|
||||
|
||||
function Comments() {
|
||||
const { ui, comments, documents } = useStores();
|
||||
const user = useCurrentUser();
|
||||
const { editor, isEditorInitialized } = useDocumentContext();
|
||||
const { t } = useTranslation();
|
||||
const location = useLocation();
|
||||
const history = useHistory();
|
||||
const match = useRouteMatch<{ documentSlug: string }>();
|
||||
const params = useQuery();
|
||||
const [pulse, setPulse] = React.useState(false);
|
||||
// We need to control scroll behaviour when reaction picker is opened / closed.
|
||||
const [scrollable, enableScroll, disableScroll] = useBoolean(true);
|
||||
const document = documents.getByUrl(match.params.documentSlug);
|
||||
const focusedComment = useFocusedComment();
|
||||
const can = usePolicy(document);
|
||||
|
||||
const scrollableRef = React.useRef<HTMLDivElement | null>(null);
|
||||
const prevThreadCount = React.useRef(0);
|
||||
const isAtBottom = React.useRef(true);
|
||||
const [showJumpToRecentBtn, setShowJumpToRecentBtn] = React.useState(false);
|
||||
|
||||
useKeyDown("Escape", () => document && ui.collapseComments(document?.id));
|
||||
|
||||
const [draft, onSaveDraft] = usePersistedState<ProsemirrorData | undefined>(
|
||||
@@ -42,71 +51,79 @@ function Comments() {
|
||||
undefined
|
||||
);
|
||||
|
||||
const sortOption: CommentSortOption = user.getPreference(
|
||||
UserPreference.SortCommentsByOrderInDocument
|
||||
)
|
||||
? {
|
||||
type: CommentSortType.OrderInDocument,
|
||||
referencedCommentIds: editor?.getComments().map((c) => c.id) ?? [],
|
||||
}
|
||||
: { type: CommentSortType.MostRecent };
|
||||
|
||||
const viewingResolved = params.get("resolved") === "";
|
||||
const resolvedThreads = document
|
||||
? comments.resolvedThreadsInDocument(document.id)
|
||||
: [];
|
||||
const resolvedThreadsCount = resolvedThreads.length;
|
||||
|
||||
React.useEffect(() => {
|
||||
setPulse(true);
|
||||
const timeout = setTimeout(() => setPulse(false), 250);
|
||||
|
||||
return () => {
|
||||
clearTimeout(timeout);
|
||||
setPulse(false);
|
||||
};
|
||||
}, [resolvedThreadsCount]);
|
||||
|
||||
if (!document) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const threads = viewingResolved
|
||||
? resolvedThreads
|
||||
: comments.unresolvedThreadsInDocument(document.id);
|
||||
const threads = !document
|
||||
? []
|
||||
: viewingResolved
|
||||
? comments.resolvedThreadsInDocument(document.id, sortOption)
|
||||
: comments.unresolvedThreadsInDocument(document.id, sortOption);
|
||||
const hasComments = threads.length > 0;
|
||||
|
||||
const toggleViewingResolved = () => {
|
||||
history.push({
|
||||
search: queryString.stringify({
|
||||
...queryString.parse(location.search),
|
||||
resolved: viewingResolved ? undefined : "",
|
||||
}),
|
||||
pathname: location.pathname,
|
||||
});
|
||||
const scrollToBottom = () => {
|
||||
if (scrollableRef.current) {
|
||||
scrollableRef.current.scrollTo({
|
||||
top: scrollableRef.current.scrollHeight,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const handleScroll = () => {
|
||||
const BUFFER_PX = 50;
|
||||
|
||||
if (scrollableRef.current) {
|
||||
const sh = scrollableRef.current.scrollHeight;
|
||||
const st = scrollableRef.current.scrollTop;
|
||||
const ch = scrollableRef.current.clientHeight;
|
||||
isAtBottom.current = Math.abs(sh - (st + ch)) <= BUFFER_PX;
|
||||
|
||||
if (isAtBottom.current) {
|
||||
setShowJumpToRecentBtn(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
React.useEffect(() => {
|
||||
// Handles: 1. on refresh 2. when switching sort setting
|
||||
const readyToDisplay = Boolean(document && isEditorInitialized);
|
||||
if (readyToDisplay && sortOption.type === CommentSortType.MostRecent) {
|
||||
scrollToBottom();
|
||||
}
|
||||
}, [sortOption.type, document, isEditorInitialized]);
|
||||
|
||||
React.useEffect(() => {
|
||||
setShowJumpToRecentBtn(false);
|
||||
if (sortOption.type === CommentSortType.MostRecent) {
|
||||
const commentsAdded = threads.length > prevThreadCount.current;
|
||||
if (commentsAdded) {
|
||||
if (isAtBottom.current) {
|
||||
scrollToBottom(); // Remain pinned to bottom on new comments
|
||||
} else {
|
||||
setShowJumpToRecentBtn(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
prevThreadCount.current = threads.length;
|
||||
}, [sortOption.type, threads.length]);
|
||||
|
||||
if (!document || !isEditorInitialized) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Sidebar
|
||||
title={
|
||||
<Flex align="center" justify="space-between" auto>
|
||||
{viewingResolved ? (
|
||||
<React.Fragment key="resolved">
|
||||
<span>{t("Resolved comments")}</span>
|
||||
<Tooltip delay={500} content={t("View comments")}>
|
||||
<ResolvedButton
|
||||
neutral
|
||||
borderOnHover
|
||||
icon={<DoneIcon />}
|
||||
onClick={toggleViewingResolved}
|
||||
/>
|
||||
</Tooltip>
|
||||
</React.Fragment>
|
||||
) : (
|
||||
<React.Fragment>
|
||||
<span>{t("Comments")}</span>
|
||||
<Tooltip delay={250} content={t("View resolved comments")}>
|
||||
<ResolvedButton
|
||||
neutral
|
||||
borderOnHover
|
||||
icon={<DoneIcon outline />}
|
||||
onClick={toggleViewingResolved}
|
||||
$pulse={pulse}
|
||||
/>
|
||||
</Tooltip>
|
||||
</React.Fragment>
|
||||
)}
|
||||
<span>{t("Comments")}</span>
|
||||
<CommentSortMenu />
|
||||
</Flex>
|
||||
}
|
||||
onClose={() => ui.collapseComments(document?.id)}
|
||||
@@ -117,6 +134,10 @@ function Comments() {
|
||||
bottomShadow={!focusedComment}
|
||||
hiddenScrollbars
|
||||
topShadow
|
||||
overflow={scrollable ? "auto" : "hidden"}
|
||||
style={{ overflowX: "hidden" }}
|
||||
ref={scrollableRef}
|
||||
onScroll={handleScroll}
|
||||
>
|
||||
<Wrapper $hasComments={hasComments}>
|
||||
{hasComments ? (
|
||||
@@ -127,6 +148,8 @@ function Comments() {
|
||||
document={document}
|
||||
recessed={!!focusedComment && focusedComment.id !== thread.id}
|
||||
focused={focusedComment?.id === thread.id}
|
||||
enableScroll={enableScroll}
|
||||
disableScroll={disableScroll}
|
||||
/>
|
||||
))
|
||||
) : (
|
||||
@@ -138,6 +161,16 @@ function Comments() {
|
||||
</PositionedEmpty>
|
||||
</NoComments>
|
||||
)}
|
||||
{showJumpToRecentBtn && (
|
||||
<Fade>
|
||||
<JumpToRecent onClick={scrollToBottom}>
|
||||
<Flex align="center">
|
||||
{t("New comments")}
|
||||
<ArrowDownIcon size={20} />
|
||||
</Flex>
|
||||
</JumpToRecent>
|
||||
</Fade>
|
||||
)}
|
||||
</Wrapper>
|
||||
</Scrollable>
|
||||
<AnimatePresence initial={false}>
|
||||
@@ -158,14 +191,6 @@ function Comments() {
|
||||
);
|
||||
}
|
||||
|
||||
const ResolvedButton = styled(Button)<{ $pulse: boolean }>`
|
||||
${(props) =>
|
||||
props.$pulse &&
|
||||
css`
|
||||
animation: ${bigPulse} 250ms 1;
|
||||
`}
|
||||
`;
|
||||
|
||||
const PositionedEmpty = styled(Empty)`
|
||||
position: absolute;
|
||||
top: calc(50vh - 30px);
|
||||
@@ -178,10 +203,27 @@ const NoComments = styled(Flex)`
|
||||
`;
|
||||
|
||||
const Wrapper = styled.div<{ $hasComments: boolean }>`
|
||||
padding-bottom: ${(props) => (props.$hasComments ? "50vh" : "0")};
|
||||
height: ${(props) => (props.$hasComments ? "auto" : "100%")};
|
||||
`;
|
||||
|
||||
const JumpToRecent = styled(ButtonSmall)`
|
||||
position: sticky;
|
||||
bottom: 12px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
opacity: 0.8;
|
||||
border-radius: 12px;
|
||||
padding: 0 4px;
|
||||
|
||||
&:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
`;
|
||||
|
||||
const ArrowDownIcon = styled(ArrowIcon)`
|
||||
transform: rotate(90deg);
|
||||
`;
|
||||
|
||||
const NewCommentForm = styled(CommentForm)<{ dir?: "ltr" | "rtl" }>`
|
||||
padding: 12px;
|
||||
padding-right: ${(props) => (props.dir !== "rtl" ? "18px" : "12px")};
|
||||
|
||||
@@ -218,11 +218,11 @@ function DataLoader({ match, children }: Props) {
|
||||
);
|
||||
}
|
||||
|
||||
const readOnly =
|
||||
!isEditing || !can.update || document.isArchived || !!revisionId;
|
||||
const canEdit = can.update && !document.isArchived && !revisionId;
|
||||
const readOnly = !isEditing || !canEdit;
|
||||
|
||||
return (
|
||||
<React.Fragment key={readOnly ? "readOnly" : ""}>
|
||||
<React.Fragment key={canEdit ? "edit" : "read"}>
|
||||
{children({
|
||||
document,
|
||||
revision,
|
||||
|
||||
@@ -27,6 +27,7 @@ import useCurrentTeam from "~/hooks/useCurrentTeam";
|
||||
import useCurrentUser from "~/hooks/useCurrentUser";
|
||||
import useFocusedComment from "~/hooks/useFocusedComment";
|
||||
import usePolicy from "~/hooks/usePolicy";
|
||||
import useQuery from "~/hooks/useQuery";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import {
|
||||
documentHistoryPath,
|
||||
@@ -81,6 +82,7 @@ function DocumentEditor(props: Props, ref: React.RefObject<any>) {
|
||||
const user = useCurrentUser({ rejectOnEmpty: false });
|
||||
const team = useCurrentTeam({ rejectOnEmpty: false });
|
||||
const history = useHistory();
|
||||
const params = useQuery();
|
||||
const {
|
||||
document,
|
||||
onChangeTitle,
|
||||
@@ -93,7 +95,6 @@ function DocumentEditor(props: Props, ref: React.RefObject<any>) {
|
||||
...rest
|
||||
} = props;
|
||||
const can = usePolicy(document);
|
||||
|
||||
const iconColor = document.color ?? (last(colorPalette) as string);
|
||||
const childRef = React.useRef<HTMLDivElement>(null);
|
||||
const focusAtStart = React.useCallback(() => {
|
||||
@@ -104,9 +105,20 @@ function DocumentEditor(props: Props, ref: React.RefObject<any>) {
|
||||
|
||||
React.useEffect(() => {
|
||||
if (focusedComment) {
|
||||
const viewingResolved = params.get("resolved") === "";
|
||||
if (
|
||||
(focusedComment.isResolved && !viewingResolved) ||
|
||||
(!focusedComment.isResolved && viewingResolved)
|
||||
) {
|
||||
history.replace({
|
||||
search: focusedComment.isResolved ? "resolved=" : "",
|
||||
pathname: location.pathname,
|
||||
state: { commentId: focusedComment.id },
|
||||
});
|
||||
}
|
||||
ui.expandComments(document.id);
|
||||
}
|
||||
}, [focusedComment, ui, document.id]);
|
||||
}, [focusedComment, ui, document.id, history, params]);
|
||||
|
||||
// Save document when blurring title, but delay so that if clicking on a
|
||||
// button this is allowed to execute first.
|
||||
@@ -150,6 +162,7 @@ function DocumentEditor(props: Props, ref: React.RefObject<any>) {
|
||||
documentId: props.id,
|
||||
createdAt: new Date(),
|
||||
createdById,
|
||||
reactions: [],
|
||||
},
|
||||
comments
|
||||
);
|
||||
@@ -175,7 +188,11 @@ function DocumentEditor(props: Props, ref: React.RefObject<any>) {
|
||||
[comments]
|
||||
);
|
||||
|
||||
const { setEditor, updateState: updateDocState } = useDocumentContext();
|
||||
const {
|
||||
setEditor,
|
||||
setEditorInitialized,
|
||||
updateState: updateDocState,
|
||||
} = useDocumentContext();
|
||||
const handleRefChanged = React.useCallback(setEditor, [setEditor]);
|
||||
const EditorComponent = multiplayer ? MultiplayerEditor : Editor;
|
||||
|
||||
@@ -189,6 +206,16 @@ function DocumentEditor(props: Props, ref: React.RefObject<any>) {
|
||||
[childOffsetHeight]
|
||||
);
|
||||
|
||||
const handleInit = React.useCallback(
|
||||
() => setEditorInitialized(true),
|
||||
[setEditorInitialized]
|
||||
);
|
||||
|
||||
const handleDestroy = React.useCallback(
|
||||
() => setEditorInitialized(false),
|
||||
[setEditorInitialized]
|
||||
);
|
||||
|
||||
return (
|
||||
<Flex auto column>
|
||||
<DocumentTitle
|
||||
@@ -241,6 +268,8 @@ function DocumentEditor(props: Props, ref: React.RefObject<any>) {
|
||||
? handleRemoveComment
|
||||
: undefined
|
||||
}
|
||||
onInit={handleInit}
|
||||
onDestroy={handleDestroy}
|
||||
onChange={updateDocState}
|
||||
extensions={extensions}
|
||||
editorStyle={editorStyle}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { useTranslation } from "react-i18next";
|
||||
import { useHistory, useRouteMatch } from "react-router-dom";
|
||||
import styled from "styled-components";
|
||||
import { RevisionHelper } from "@shared/utils/RevisionHelper";
|
||||
import Document from "~/models/Document";
|
||||
import Event from "~/models/Event";
|
||||
import Empty from "~/components/Empty";
|
||||
import PaginatedEventList from "~/components/PaginatedEventList";
|
||||
@@ -12,7 +13,7 @@ import useStores from "~/hooks/useStores";
|
||||
import { documentPath } from "~/utils/routeHelpers";
|
||||
import Sidebar from "./SidebarLayout";
|
||||
|
||||
const EMPTY_ARRAY: Event[] = [];
|
||||
const EMPTY_ARRAY: Event<Document>[] = [];
|
||||
|
||||
function History() {
|
||||
const { events, documents } = useStores();
|
||||
|
||||
@@ -61,6 +61,8 @@ function ReferenceListItem({
|
||||
}: Props) {
|
||||
const { icon, color } = document;
|
||||
const isEmoji = determineIconType(icon) === IconType.Emoji;
|
||||
const title =
|
||||
document instanceof Document ? document.titleWithDefault : document.title;
|
||||
|
||||
return (
|
||||
<DocumentLink
|
||||
@@ -81,9 +83,7 @@ function ReferenceListItem({
|
||||
) : (
|
||||
<DocumentIcon />
|
||||
)}
|
||||
<Title>
|
||||
{isEmoji ? document.title.replace(icon!, "") : document.title}
|
||||
</Title>
|
||||
<Title>{isEmoji ? title.replace(icon!, "") : title}</Title>
|
||||
</Content>
|
||||
</DocumentLink>
|
||||
);
|
||||
|
||||
@@ -8,15 +8,18 @@ import User from "~/models/User";
|
||||
import Invite from "~/scenes/Invite";
|
||||
import { Avatar, AvatarSize } from "~/components/Avatar";
|
||||
import ButtonLink from "~/components/ButtonLink";
|
||||
import DelayedMount from "~/components/DelayedMount";
|
||||
import Empty from "~/components/Empty";
|
||||
import Flex from "~/components/Flex";
|
||||
import Input from "~/components/Input";
|
||||
import PlaceholderList from "~/components/List/Placeholder";
|
||||
import Modal from "~/components/Modal";
|
||||
import PaginatedList from "~/components/PaginatedList";
|
||||
import Text from "~/components/Text";
|
||||
import useBoolean from "~/hooks/useBoolean";
|
||||
import useCurrentTeam from "~/hooks/useCurrentTeam";
|
||||
import usePolicy from "~/hooks/usePolicy";
|
||||
import useRequest from "~/hooks/useRequest";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import GroupMemberListItem from "./components/GroupMemberListItem";
|
||||
|
||||
@@ -72,6 +75,14 @@ function AddPeopleToGroup(props: Props) {
|
||||
}
|
||||
};
|
||||
|
||||
const { loading } = useRequest(
|
||||
React.useCallback(
|
||||
() => groupUsers.fetchAll({ id: group.id }),
|
||||
[groupUsers, group]
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
return (
|
||||
<Flex column>
|
||||
<Text as="p" type="secondary">
|
||||
@@ -99,24 +110,30 @@ function AddPeopleToGroup(props: Props) {
|
||||
autoFocus
|
||||
flex
|
||||
/>
|
||||
<PaginatedList
|
||||
empty={
|
||||
query ? (
|
||||
<Empty>{t("No people matching your search")}</Empty>
|
||||
) : (
|
||||
<Empty>{t("No people left to add")}</Empty>
|
||||
)
|
||||
}
|
||||
items={users.notInGroup(group.id, query)}
|
||||
fetch={query ? undefined : users.fetchPage}
|
||||
renderItem={(item: User) => (
|
||||
<GroupMemberListItem
|
||||
key={item.id}
|
||||
user={item}
|
||||
onAdd={() => handleAddUser(item)}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
{loading ? (
|
||||
<DelayedMount>
|
||||
<PlaceholderList count={5} />
|
||||
</DelayedMount>
|
||||
) : (
|
||||
<PaginatedList
|
||||
empty={
|
||||
query ? (
|
||||
<Empty>{t("No people matching your search")}</Empty>
|
||||
) : (
|
||||
<Empty>{t("No people left to add")}</Empty>
|
||||
)
|
||||
}
|
||||
items={users.notInGroup(group.id, query)}
|
||||
fetch={query ? undefined : users.fetchPage}
|
||||
renderItem={(item: User) => (
|
||||
<GroupMemberListItem
|
||||
key={item.id}
|
||||
user={item}
|
||||
onAdd={() => handleAddUser(item)}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
<Modal
|
||||
title={t("Invite people")}
|
||||
onRequestClose={handleInviteModalClose}
|
||||
|
||||
@@ -5,6 +5,124 @@ import { Trans } from "react-i18next";
|
||||
import Notice from "~/components/Notice";
|
||||
import useQuery from "~/hooks/useQuery";
|
||||
|
||||
function Message({ notice }: { notice: string }) {
|
||||
switch (notice) {
|
||||
case "domain-not-allowed":
|
||||
return (
|
||||
<Trans>
|
||||
The domain associated with your email address has not been allowed for
|
||||
this workspace.
|
||||
</Trans>
|
||||
);
|
||||
case "domain-required":
|
||||
return (
|
||||
<Trans>
|
||||
Unable to sign-in. Please navigate to your workspace's custom URL,
|
||||
then try to sign-in again.
|
||||
<hr />
|
||||
If you were invited to a workspace, you will find a link to it in the
|
||||
invite email.
|
||||
</Trans>
|
||||
);
|
||||
case "gmail-account-creation":
|
||||
return (
|
||||
<Trans>
|
||||
Sorry, a new account cannot be created with a personal Gmail address.
|
||||
<hr />
|
||||
Please use a Google Workspaces account instead.
|
||||
</Trans>
|
||||
);
|
||||
case "pending-deletion":
|
||||
return (
|
||||
<Trans>
|
||||
The workspace associated with your user is scheduled for deletion and
|
||||
cannot be accessed at this time.
|
||||
</Trans>
|
||||
);
|
||||
case "maximum-reached":
|
||||
return (
|
||||
<Trans>
|
||||
The workspace you authenticated with is not authorized on this
|
||||
installation. Try another?
|
||||
</Trans>
|
||||
);
|
||||
case "malformed-user-info":
|
||||
return (
|
||||
<Trans>
|
||||
We could not read the user info supplied by your identity provider.
|
||||
</Trans>
|
||||
);
|
||||
case "email-auth-required":
|
||||
return (
|
||||
<Trans>
|
||||
Your account uses email sign-in, please sign-in with email to
|
||||
continue.
|
||||
</Trans>
|
||||
);
|
||||
case "email-auth-ratelimit":
|
||||
return (
|
||||
<Trans>
|
||||
An email sign-in link was recently sent, please check your inbox or
|
||||
try again in a few minutes.
|
||||
</Trans>
|
||||
);
|
||||
case "auth-error":
|
||||
case "state-mismatch":
|
||||
return (
|
||||
<Trans>
|
||||
Authentication failed – we were unable to sign you in at this time.
|
||||
Please try again.
|
||||
</Trans>
|
||||
);
|
||||
case "invalid-authentication":
|
||||
return (
|
||||
<Trans>
|
||||
Authentication failed – you do not have permission to access this
|
||||
workspace.
|
||||
</Trans>
|
||||
);
|
||||
case "expired-token":
|
||||
return (
|
||||
<Trans>
|
||||
Sorry, it looks like that sign-in link is no longer valid, please try
|
||||
requesting another.
|
||||
</Trans>
|
||||
);
|
||||
case "user-suspended":
|
||||
return (
|
||||
<Trans>
|
||||
Your account has been suspended. To re-activate your account, please
|
||||
contact a workspace admin.
|
||||
</Trans>
|
||||
);
|
||||
case "team-suspended":
|
||||
return (
|
||||
<Trans>
|
||||
This workspace has been suspended. Please contact support to restore
|
||||
access.
|
||||
</Trans>
|
||||
);
|
||||
case "authentication-provider-disabled":
|
||||
return (
|
||||
<Trans>
|
||||
Authentication failed – this login method was disabled by a team
|
||||
admin.
|
||||
</Trans>
|
||||
);
|
||||
case "invite-required":
|
||||
return (
|
||||
<Trans>
|
||||
The workspace you are trying to join requires an invite before you can
|
||||
create an account.
|
||||
<hr />
|
||||
Please request an invite from your workspace admin and try again.
|
||||
</Trans>
|
||||
);
|
||||
default:
|
||||
return <Trans>Sorry, an unknown error occurred.</Trans>;
|
||||
}
|
||||
}
|
||||
|
||||
export default function Notices() {
|
||||
const query = useQuery();
|
||||
const notice = query.get("notice");
|
||||
@@ -15,107 +133,7 @@ export default function Notices() {
|
||||
|
||||
return (
|
||||
<Notice icon={<WarningIcon color="currentcolor" />}>
|
||||
{notice === "domain-not-allowed" && (
|
||||
<Trans>
|
||||
The domain associated with your email address has not been allowed for
|
||||
this workspace.
|
||||
</Trans>
|
||||
)}
|
||||
{notice === "domain-required" && (
|
||||
<Trans>
|
||||
Unable to sign-in. Please navigate to your workspace's custom URL,
|
||||
then try to sign-in again.
|
||||
<hr />
|
||||
If you were invited to a workspace, you will find a link to it in the
|
||||
invite email.
|
||||
</Trans>
|
||||
)}
|
||||
{notice === "gmail-account-creation" && (
|
||||
<Trans>
|
||||
Sorry, a new account cannot be created with a personal Gmail address.
|
||||
<hr />
|
||||
Please use a Google Workspaces account instead.
|
||||
</Trans>
|
||||
)}
|
||||
{notice === "pending-deletion" && (
|
||||
<Trans>
|
||||
The workspace associated with your user is scheduled for deletion and
|
||||
cannot be accessed at this time.
|
||||
</Trans>
|
||||
)}
|
||||
{notice === "maximum-reached" && (
|
||||
<Trans>
|
||||
The workspace you authenticated with is not authorized on this
|
||||
installation. Try another?
|
||||
</Trans>
|
||||
)}
|
||||
{notice === "malformed-user-info" && (
|
||||
<Trans>
|
||||
We could not read the user info supplied by your identity provider.
|
||||
</Trans>
|
||||
)}
|
||||
{notice === "email-auth-required" && (
|
||||
<Trans>
|
||||
Your account uses email sign-in, please sign-in with email to
|
||||
continue.
|
||||
</Trans>
|
||||
)}
|
||||
{notice === "email-auth-ratelimit" && (
|
||||
<Trans>
|
||||
An email sign-in link was recently sent, please check your inbox or
|
||||
try again in a few minutes.
|
||||
</Trans>
|
||||
)}
|
||||
{(notice === "auth-error" || notice === "state-mismatch") && (
|
||||
<Trans>
|
||||
Authentication failed – we were unable to sign you in at this time.
|
||||
Please try again.
|
||||
</Trans>
|
||||
)}
|
||||
{notice === "invalid-authentication" && (
|
||||
<Trans>
|
||||
Authentication failed – you do not have permission to access this
|
||||
workspace.
|
||||
</Trans>
|
||||
)}
|
||||
{notice === "expired-token" && (
|
||||
<Trans>
|
||||
Sorry, it looks like that sign-in link is no longer valid, please try
|
||||
requesting another.
|
||||
</Trans>
|
||||
)}
|
||||
{notice === "user-suspended" && (
|
||||
<Trans>
|
||||
Your account has been suspended. To re-activate your account, please
|
||||
contact a workspace admin.
|
||||
</Trans>
|
||||
)}
|
||||
{notice === "team-suspended" && (
|
||||
<Trans>
|
||||
This workspace has been suspended. Please contact support to restore
|
||||
access.
|
||||
</Trans>
|
||||
)}
|
||||
{notice === "authentication-provider-disabled" && (
|
||||
<Trans>
|
||||
Authentication failed – this login method was disabled by a team
|
||||
admin.
|
||||
</Trans>
|
||||
)}
|
||||
{notice === "invite-required" && (
|
||||
<Trans>
|
||||
The workspace you are trying to join requires an invite before you can
|
||||
create an account.
|
||||
<hr />
|
||||
Please request an invite from your workspace admin and try again.
|
||||
</Trans>
|
||||
)}
|
||||
{notice === "domain-not-allowed" && (
|
||||
<Trans>
|
||||
Sorry, your domain is not allowed. Please try again with an allowed
|
||||
workspace domain.
|
||||
</Trans>
|
||||
)}
|
||||
<Message notice={notice} />
|
||||
</Notice>
|
||||
);
|
||||
}
|
||||
@@ -57,9 +57,10 @@ function Search(props: Props) {
|
||||
const recentSearchesRef = React.useRef<HTMLDivElement | null>(null);
|
||||
|
||||
// filters
|
||||
const query = decodeURIComponentSafe(
|
||||
const decodedQuery = decodeURIComponentSafe(
|
||||
routeMatch.params.term ?? params.get("query") ?? ""
|
||||
);
|
||||
).trim();
|
||||
const query = decodedQuery !== "" ? decodedQuery : undefined;
|
||||
const collectionId = params.get("collectionId") ?? undefined;
|
||||
const userId = params.get("userId") ?? undefined;
|
||||
const documentId = params.get("documentId") ?? undefined;
|
||||
@@ -68,7 +69,19 @@ function Search(props: Props) {
|
||||
? (params.getAll("statusFilter") as TStatusFilter[])
|
||||
: [TStatusFilter.Published, TStatusFilter.Draft];
|
||||
const titleFilter = params.get("titleFilter") === "true";
|
||||
const hasFilters = !!(documentId || collectionId || userId || dateFilter);
|
||||
|
||||
const isSearchable = !!(query || collectionId || userId);
|
||||
|
||||
const document = documentId ? documents.get(documentId) : undefined;
|
||||
|
||||
const filterVisibility = {
|
||||
document: !!document,
|
||||
collection: !document,
|
||||
user: !document || !!(document && query),
|
||||
documentType: isSearchable,
|
||||
date: isSearchable,
|
||||
title: !!query && !document,
|
||||
};
|
||||
|
||||
const filters = React.useMemo(
|
||||
() => ({
|
||||
@@ -100,22 +113,22 @@ function Search(props: Props) {
|
||||
query,
|
||||
createdAt: new Date().toISOString(),
|
||||
});
|
||||
}
|
||||
|
||||
if (isSearchable) {
|
||||
return async () =>
|
||||
titleFilter
|
||||
? await documents.searchTitles(query, filters)
|
||||
: await documents.search(query, filters);
|
||||
? await documents.searchTitles(filters)
|
||||
: await documents.search(filters);
|
||||
}
|
||||
|
||||
return () => Promise.resolve([] as SearchResult[]);
|
||||
}, [query, titleFilter, filters, searches, documents]);
|
||||
}, [query, titleFilter, filters, searches, documents, isSearchable]);
|
||||
|
||||
const { data, next, end, error, loading } = usePaginatedRequest(requestFn, {
|
||||
limit: Pagination.defaultLimit,
|
||||
});
|
||||
|
||||
const document = documentId ? documents.get(documentId) : undefined;
|
||||
|
||||
const updateLocation = (query: string) => {
|
||||
history.replace({
|
||||
pathname: searchPath(query),
|
||||
@@ -225,39 +238,47 @@ function Search(props: Props) {
|
||||
: t("Search")
|
||||
}…`}
|
||||
onKeyDown={handleKeyDown}
|
||||
defaultValue={query}
|
||||
defaultValue={query ?? ""}
|
||||
/>
|
||||
|
||||
{(query || hasFilters) && (
|
||||
<Filters>
|
||||
{document && (
|
||||
<DocumentFilter
|
||||
document={document}
|
||||
onClick={() => {
|
||||
handleFilterChange({ documentId: undefined });
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<DocumentTypeFilter
|
||||
statusFilter={statusFilter}
|
||||
onSelect={({ statusFilter }) =>
|
||||
handleFilterChange({ statusFilter })
|
||||
}
|
||||
<Filters>
|
||||
{filterVisibility.document && (
|
||||
<DocumentFilter
|
||||
document={document!}
|
||||
onClick={() => {
|
||||
handleFilterChange({ documentId: undefined });
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{filterVisibility.collection && (
|
||||
<CollectionFilter
|
||||
collectionId={collectionId}
|
||||
onSelect={(collectionId) =>
|
||||
handleFilterChange({ collectionId })
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{filterVisibility.user && (
|
||||
<UserFilter
|
||||
userId={userId}
|
||||
onSelect={(userId) => handleFilterChange({ userId })}
|
||||
/>
|
||||
)}
|
||||
{filterVisibility.documentType && (
|
||||
<DocumentTypeFilter
|
||||
statusFilter={statusFilter}
|
||||
onSelect={({ statusFilter }) =>
|
||||
handleFilterChange({ statusFilter })
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{filterVisibility.date && (
|
||||
<DateFilter
|
||||
dateFilter={dateFilter}
|
||||
onSelect={(dateFilter) => handleFilterChange({ dateFilter })}
|
||||
/>
|
||||
)}
|
||||
{filterVisibility.title && (
|
||||
<SearchTitlesFilter
|
||||
width={26}
|
||||
height={14}
|
||||
@@ -267,10 +288,10 @@ function Search(props: Props) {
|
||||
}}
|
||||
checked={titleFilter}
|
||||
/>
|
||||
</Filters>
|
||||
)}
|
||||
)}
|
||||
</Filters>
|
||||
</form>
|
||||
{query ? (
|
||||
{isSearchable ? (
|
||||
<>
|
||||
{error ? (
|
||||
<Fade>
|
||||
@@ -322,7 +343,7 @@ function Search(props: Props) {
|
||||
/>
|
||||
</ResultList>
|
||||
</>
|
||||
) : documentId || collectionId ? null : (
|
||||
) : documentId ? null : (
|
||||
<RecentSearches ref={recentSearchesRef} onEscape={handleEscape} />
|
||||
)}
|
||||
</ResultsWrapper>
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { observer } from "mobx-react";
|
||||
import { CollectionIcon as SVGCollectionIcon } from "outline-icons";
|
||||
import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import FilterOptions from "~/components/FilterOptions";
|
||||
import CollectionIcon from "~/components/Icons/CollectionIcon";
|
||||
import useStores from "~/hooks/useStores";
|
||||
|
||||
type Props = {
|
||||
@@ -16,14 +18,16 @@ function CollectionFilter(props: Props) {
|
||||
const { collections } = useStores();
|
||||
const { onSelect, collectionId } = props;
|
||||
const options = React.useMemo(() => {
|
||||
const collectionOptions = collections.orderedData.map((user) => ({
|
||||
key: user.id,
|
||||
label: user.name,
|
||||
const collectionOptions = collections.orderedData.map((collection) => ({
|
||||
key: collection.id,
|
||||
label: collection.name,
|
||||
icon: <CollectionIcon collection={collection} size={18} />,
|
||||
}));
|
||||
return [
|
||||
{
|
||||
key: "",
|
||||
label: t("Any collection"),
|
||||
icon: <SVGCollectionIcon size={18} />,
|
||||
},
|
||||
...collectionOptions,
|
||||
];
|
||||
|
||||
@@ -81,7 +81,7 @@ const RecentSearch = styled(Link)`
|
||||
&:focus,
|
||||
&:${hover} {
|
||||
color: ${s("text")};
|
||||
background: ${s("secondaryBackground")};
|
||||
background: ${s("backgroundSecondary")};
|
||||
|
||||
${RemoveButton} {
|
||||
opacity: 1;
|
||||
|
||||
@@ -153,7 +153,6 @@ function Preferences() {
|
||||
/>
|
||||
</SettingRow>
|
||||
<SettingRow
|
||||
border={false}
|
||||
name={UserPreference.RememberLastPath}
|
||||
label={t("Remember previous location")}
|
||||
description={t(
|
||||
@@ -167,6 +166,21 @@ function Preferences() {
|
||||
onChange={handlePreferenceChange(false)}
|
||||
/>
|
||||
</SettingRow>
|
||||
<SettingRow
|
||||
border={false}
|
||||
name={UserPreference.EnableSmartText}
|
||||
label={t("Smart text replacements")}
|
||||
description={t(
|
||||
"Auto-format text by replacing shortcuts with symbols, dashes, smart quotes, and other typographical elements."
|
||||
)}
|
||||
>
|
||||
<Switch
|
||||
id={UserPreference.EnableSmartText}
|
||||
name={UserPreference.EnableSmartText}
|
||||
checked={!!user.getPreference(UserPreference.EnableSmartText)}
|
||||
onChange={handlePreferenceChange(false)}
|
||||
/>
|
||||
</SettingRow>
|
||||
|
||||
{can.delete && (
|
||||
<>
|
||||
|
||||
@@ -138,7 +138,7 @@ const DropzoneContainer = styled.div<{
|
||||
}>`
|
||||
background: ${(props) =>
|
||||
props.$isDragActive
|
||||
? props.theme.secondaryBackground
|
||||
? props.theme.backgroundSecondary
|
||||
: props.theme.background};
|
||||
border-radius: 8px;
|
||||
border: 1px dashed ${s("divider")};
|
||||
@@ -149,7 +149,7 @@ const DropzoneContainer = styled.div<{
|
||||
opacity: ${(props) => (props.$disabled ? 0.5 : 1)};
|
||||
|
||||
&:hover {
|
||||
background: ${s("secondaryBackground")};
|
||||
background: ${s("backgroundSecondary")};
|
||||
}
|
||||
`;
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ const ImageBox = styled(Flex)`
|
||||
position: relative;
|
||||
font-size: 14px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 0 0 1px ${s("secondaryBackground")};
|
||||
box-shadow: 0 0 0 1px ${s("backgroundSecondary")};
|
||||
background: ${s("background")};
|
||||
overflow: hidden;
|
||||
|
||||
|
||||
+12
-4
@@ -218,10 +218,10 @@ export default class AuthStore extends Store<Team> {
|
||||
this.collaborationToken = res.data.collaborationToken;
|
||||
|
||||
if (env.SENTRY_DSN) {
|
||||
Sentry.configureScope(function (scope) {
|
||||
scope.setUser({ id: this.currentUserId });
|
||||
scope.setExtra("team", this.team.name);
|
||||
scope.setExtra("teamId", this.team.id);
|
||||
Sentry.configureScope((scope) => {
|
||||
scope.setUser({ id: this.currentUserId! });
|
||||
scope.setExtra("team", this.team?.name);
|
||||
scope.setExtra("teamId", this.currentTeamId);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -241,6 +241,13 @@ export default class AuthStore extends Store<Team> {
|
||||
window.location.href = `${data.team.url}${pathname}`;
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the user's timezone if it has changed
|
||||
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
if (data.user.timezone !== timezone) {
|
||||
const user = this.rootStore.users.get(data.user.id)!;
|
||||
void user.save({ timezone });
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.error === "user_suspended") {
|
||||
@@ -248,6 +255,7 @@ export default class AuthStore extends Store<Team> {
|
||||
this.suspendedContactEmail = err.data.adminEmail;
|
||||
return;
|
||||
}
|
||||
throw err;
|
||||
} finally {
|
||||
this.isFetching = false;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import invariant from "invariant";
|
||||
import compact from "lodash/compact";
|
||||
import differenceBy from "lodash/differenceBy";
|
||||
import keyBy from "lodash/keyBy";
|
||||
import orderBy from "lodash/orderBy";
|
||||
import uniq from "lodash/uniq";
|
||||
import { action, computed } from "mobx";
|
||||
import Comment from "~/models/Comment";
|
||||
import { CommentSortOption, CommentSortType } from "~/types";
|
||||
import { client } from "~/utils/ApiClient";
|
||||
import RootStore from "./RootStore";
|
||||
import Store from "./base/Store";
|
||||
@@ -28,14 +33,29 @@ export default class CommentsStore extends Store<Comment> {
|
||||
* @param documentId ID of the document to get comments for
|
||||
* @returns Array of comments
|
||||
*/
|
||||
threadsInDocument(documentId: string): Comment[] {
|
||||
return this.filter(
|
||||
threadsInDocument(
|
||||
documentId: string,
|
||||
options: CommentSortOption = { type: CommentSortType.MostRecent }
|
||||
) {
|
||||
const comments = this.filter(
|
||||
(comment: Comment) =>
|
||||
comment.documentId === documentId &&
|
||||
!comment.parentCommentId &&
|
||||
(!comment.isNew ||
|
||||
comment.createdById === this.rootStore.auth.currentUserId)
|
||||
);
|
||||
|
||||
if (options.type === CommentSortType.MostRecent) {
|
||||
return comments;
|
||||
}
|
||||
|
||||
const commentsById = keyBy(comments, "id");
|
||||
const referencedComments = compact(
|
||||
uniq(options.referencedCommentIds.map((id) => commentsById[id]))
|
||||
);
|
||||
const directComments = differenceBy(comments, referencedComments, "id");
|
||||
|
||||
return [...referencedComments, ...directComments];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,8 +65,11 @@ export default class CommentsStore extends Store<Comment> {
|
||||
* @param documentId ID of the document to get comments for
|
||||
* @returns Array of comments
|
||||
*/
|
||||
resolvedThreadsInDocument(documentId: string): Comment[] {
|
||||
return this.threadsInDocument(documentId).filter(
|
||||
resolvedThreadsInDocument(
|
||||
documentId: string,
|
||||
options: CommentSortOption = { type: CommentSortType.MostRecent }
|
||||
): Comment[] {
|
||||
return this.threadsInDocument(documentId, options).filter(
|
||||
(comment: Comment) => comment.isResolved === true
|
||||
);
|
||||
}
|
||||
@@ -58,8 +81,11 @@ export default class CommentsStore extends Store<Comment> {
|
||||
* @param documentId ID of the document to get comments for
|
||||
* @returns Array of comments
|
||||
*/
|
||||
unresolvedThreadsInDocument(documentId: string): Comment[] {
|
||||
return this.threadsInDocument(documentId).filter(
|
||||
unresolvedThreadsInDocument(
|
||||
documentId: string,
|
||||
options: CommentSortOption = { type: CommentSortType.MostRecent }
|
||||
): Comment[] {
|
||||
return this.threadsInDocument(documentId, options).filter(
|
||||
(comment: Comment) => comment.isResolved !== true
|
||||
);
|
||||
}
|
||||
|
||||
@@ -68,12 +68,16 @@ export default class PresenceStore {
|
||||
|
||||
@action
|
||||
private update(documentId: string, userId: string, isEditing: boolean) {
|
||||
const existing = this.data.get(documentId) || new Map();
|
||||
existing.set(userId, {
|
||||
isEditing,
|
||||
userId,
|
||||
});
|
||||
this.data.set(documentId, existing);
|
||||
const presence = this.data.get(documentId) || new Map();
|
||||
const existing = presence.get(userId);
|
||||
|
||||
if (!existing || existing.isEditing !== isEditing) {
|
||||
presence.set(userId, {
|
||||
isEditing,
|
||||
userId,
|
||||
});
|
||||
this.data.set(documentId, presence);
|
||||
}
|
||||
}
|
||||
|
||||
public get(documentId: string): DocumentPresence | null | undefined {
|
||||
|
||||
@@ -33,6 +33,7 @@ type FetchPageParams = PaginationParams & {
|
||||
};
|
||||
|
||||
export type SearchParams = {
|
||||
query?: string;
|
||||
offset?: number;
|
||||
limit?: number;
|
||||
dateFilter?: DateFilter;
|
||||
@@ -62,6 +63,7 @@ export default class DocumentsStore extends Store<Document> {
|
||||
".md",
|
||||
".doc",
|
||||
".docx",
|
||||
"text/csv",
|
||||
"text/markdown",
|
||||
"text/plain",
|
||||
"text/html",
|
||||
@@ -366,6 +368,10 @@ export default class DocumentsStore extends Store<Document> {
|
||||
fetchTemplates = async (options?: PaginationParams): Promise<Document[]> =>
|
||||
this.fetchNamedPage("list", { ...options, template: true });
|
||||
|
||||
@action
|
||||
fetchAllTemplates = async (options?: PaginationParams): Promise<Document[]> =>
|
||||
this.fetchAll({ ...options, template: true });
|
||||
|
||||
@action
|
||||
fetchAlphabetical = async (options?: PaginationParams): Promise<Document[]> =>
|
||||
this.fetchNamedPage("list", {
|
||||
@@ -412,14 +418,10 @@ export default class DocumentsStore extends Store<Document> {
|
||||
this.fetchNamedPage("list", options);
|
||||
|
||||
@action
|
||||
searchTitles = async (
|
||||
query: string,
|
||||
options?: SearchParams
|
||||
): Promise<SearchResult[]> => {
|
||||
searchTitles = async (options?: SearchParams): Promise<SearchResult[]> => {
|
||||
const compactedOptions = omitBy(options, (o) => !o);
|
||||
const res = await client.post("/documents.search_titles", {
|
||||
...compactedOptions,
|
||||
query,
|
||||
});
|
||||
invariant(res?.data, "Search response should be available");
|
||||
|
||||
@@ -447,14 +449,10 @@ export default class DocumentsStore extends Store<Document> {
|
||||
};
|
||||
|
||||
@action
|
||||
search = async (
|
||||
query: string,
|
||||
options: SearchParams
|
||||
): Promise<SearchResult[]> => {
|
||||
search = async (options: SearchParams): Promise<SearchResult[]> => {
|
||||
const compactedOptions = omitBy(options, (o) => !o);
|
||||
const res = await client.post("/documents.search", {
|
||||
...compactedOptions,
|
||||
query,
|
||||
});
|
||||
invariant(res?.data, "Search response should be available");
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import Event from "~/models/Event";
|
||||
import RootStore from "./RootStore";
|
||||
import Store, { RPCAction } from "./base/Store";
|
||||
|
||||
export default class EventsStore extends Store<Event> {
|
||||
export default class EventsStore extends Store<Event<any>> {
|
||||
actions = [RPCAction.List];
|
||||
|
||||
constructor(rootStore: RootStore) {
|
||||
@@ -12,7 +12,7 @@ export default class EventsStore extends Store<Event> {
|
||||
}
|
||||
|
||||
@computed
|
||||
get orderedData(): Event[] {
|
||||
get orderedData(): Event<any>[] {
|
||||
return orderBy(Array.from(this.data.values()), "createdAt", "desc");
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,11 @@ import GroupUser from "~/models/GroupUser";
|
||||
import { PaginationParams } from "~/types";
|
||||
import { client } from "~/utils/ApiClient";
|
||||
import RootStore from "./RootStore";
|
||||
import Store, { RPCAction } from "./base/Store";
|
||||
import Store, {
|
||||
PaginatedResponse,
|
||||
PAGINATION_SYMBOL,
|
||||
RPCAction,
|
||||
} from "./base/Store";
|
||||
|
||||
export default class GroupUsersStore extends Store<GroupUser> {
|
||||
actions = [RPCAction.Create, RPCAction.Delete];
|
||||
@@ -17,20 +21,22 @@ export default class GroupUsersStore extends Store<GroupUser> {
|
||||
@action
|
||||
fetchPage = async (
|
||||
params: PaginationParams | undefined
|
||||
): Promise<GroupUser[]> => {
|
||||
): Promise<PaginatedResponse<GroupUser>> => {
|
||||
this.isFetching = true;
|
||||
|
||||
try {
|
||||
const res = await client.post(`/groups.memberships`, params);
|
||||
invariant(res?.data, "Data not available");
|
||||
|
||||
let models: GroupUser[] = [];
|
||||
let response: PaginatedResponse<GroupUser> = [];
|
||||
runInAction(`GroupUsersStore#fetchPage`, () => {
|
||||
res.data.users.forEach(this.rootStore.users.add);
|
||||
models = res.data.groupMemberships.map(this.add);
|
||||
response = res.data.groupMemberships.map(this.add);
|
||||
this.isLoaded = true;
|
||||
});
|
||||
return models;
|
||||
|
||||
response[PAGINATION_SYMBOL] = res.pagination;
|
||||
return response;
|
||||
} finally {
|
||||
this.isFetching = false;
|
||||
}
|
||||
|
||||
@@ -8,3 +8,5 @@ initI18n();
|
||||
global.localStorage = localStorage;
|
||||
|
||||
require("jest-fetch-mock").enableMocks();
|
||||
|
||||
jest.mock("~/utils/ApiClient");
|
||||
+19
-2
@@ -12,6 +12,7 @@ import Document from "./models/Document";
|
||||
import FileOperation from "./models/FileOperation";
|
||||
import Pin from "./models/Pin";
|
||||
import Star from "./models/Star";
|
||||
import User from "./models/User";
|
||||
import UserMembership from "./models/UserMembership";
|
||||
|
||||
export type PartialExcept<T, K extends keyof T> = Partial<Omit<T, K>> &
|
||||
@@ -166,7 +167,7 @@ export type PaginationParams = {
|
||||
export type SearchResult = {
|
||||
id: string;
|
||||
ranking: number;
|
||||
context: string;
|
||||
context?: string;
|
||||
document: Document;
|
||||
};
|
||||
|
||||
@@ -188,6 +189,12 @@ export type WebsocketCollectionUpdateIndexEvent = {
|
||||
index: string;
|
||||
};
|
||||
|
||||
export type WebsocketCommentReactionEvent = {
|
||||
emoji: string;
|
||||
commentId: string;
|
||||
user: User;
|
||||
};
|
||||
|
||||
export type WebsocketEvent =
|
||||
| PartialExcept<Pin, "id">
|
||||
| PartialExcept<Star, "id">
|
||||
@@ -195,7 +202,8 @@ export type WebsocketEvent =
|
||||
| PartialExcept<UserMembership, "id">
|
||||
| WebsocketCollectionUpdateIndexEvent
|
||||
| WebsocketEntityDeletedEvent
|
||||
| WebsocketEntitiesEvent;
|
||||
| WebsocketEntitiesEvent
|
||||
| WebsocketCommentReactionEvent;
|
||||
|
||||
export type AwarenessChangeEvent = {
|
||||
states: { user?: { id: string }; cursor: any; scrollY: number | undefined }[];
|
||||
@@ -215,3 +223,12 @@ export type Properties<C> = {
|
||||
? Property
|
||||
: never]?: C[Property];
|
||||
};
|
||||
|
||||
export enum CommentSortType {
|
||||
MostRecent = "mostRecent",
|
||||
OrderInDocument = "orderInDocument",
|
||||
}
|
||||
|
||||
export type CommentSortOption =
|
||||
| { type: CommentSortType.MostRecent }
|
||||
| { type: CommentSortType.OrderInDocument; referencedCommentIds: string[] };
|
||||
Vendored
+4
-2
@@ -91,6 +91,7 @@ declare module "styled-components" {
|
||||
purple: string;
|
||||
blue: string;
|
||||
marine: string;
|
||||
dusk: string;
|
||||
green: string;
|
||||
yellow: string;
|
||||
};
|
||||
@@ -120,10 +121,12 @@ declare module "styled-components" {
|
||||
Breakpoints,
|
||||
EditorTheme {
|
||||
background: string;
|
||||
backgroundSecondary: string;
|
||||
backgroundTertiary: string;
|
||||
backgroundQuaternary: string;
|
||||
backgroundTransition: string;
|
||||
accent: string;
|
||||
accentText: string;
|
||||
secondaryBackground: string;
|
||||
link: string;
|
||||
text: string;
|
||||
cursor: string;
|
||||
@@ -135,7 +138,6 @@ declare module "styled-components" {
|
||||
textDiffDeletedBackground: string;
|
||||
placeholder: string;
|
||||
commentMarkBackground: string;
|
||||
commentBackground: string;
|
||||
sidebarBackground: string;
|
||||
sidebarActiveBackground: string;
|
||||
sidebarControlHoverBackground: string;
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
/* eslint-disable */
|
||||
export default {
|
||||
client: {
|
||||
post: jest.fn(() => Promise.resolve)
|
||||
}
|
||||
};
|
||||
export const client = {
|
||||
post: jest.fn(() => Promise.resolve({
|
||||
data: {
|
||||
user: {},
|
||||
team: {},
|
||||
groups: [],
|
||||
groupUsers: [],
|
||||
}
|
||||
}))
|
||||
};
|
||||
+26
-25
@@ -57,9 +57,9 @@
|
||||
"@babel/plugin-proposal-decorators": "^7.24.7",
|
||||
"@babel/plugin-transform-class-properties": "^7.24.7",
|
||||
"@babel/plugin-transform-destructuring": "^7.24.8",
|
||||
"@babel/plugin-transform-regenerator": "^7.24.7",
|
||||
"@babel/plugin-transform-regenerator": "^7.25.9",
|
||||
"@babel/preset-env": "^7.25.8",
|
||||
"@babel/preset-react": "^7.24.7",
|
||||
"@babel/preset-react": "^7.25.9",
|
||||
"@benrbray/prosemirror-math": "^0.2.2",
|
||||
"@bull-board/api": "^4.2.2",
|
||||
"@bull-board/koa": "^4.12.2",
|
||||
@@ -68,6 +68,7 @@
|
||||
"@dnd-kit/modifiers": "^6.0.1",
|
||||
"@dnd-kit/sortable": "^7.0.2",
|
||||
"@emoji-mart/data": "^1.2.1",
|
||||
"@fast-csv/parse": "^5.0.2",
|
||||
"@fortawesome/fontawesome-svg-core": "^6.5.2",
|
||||
"@fortawesome/free-brands-svg-icons": "^6.5.2",
|
||||
"@fortawesome/free-solid-svg-icons": "^6.5.2",
|
||||
@@ -123,7 +124,7 @@
|
||||
"glob": "^8.1.0",
|
||||
"http-errors": "2.0.0",
|
||||
"i18next": "^22.5.1",
|
||||
"i18next-fs-backend": "^2.3.1",
|
||||
"i18next-fs-backend": "^2.3.2",
|
||||
"i18next-http-backend": "^2.5.0",
|
||||
"invariant": "^2.2.4",
|
||||
"ioredis": "^5.4.1",
|
||||
@@ -149,7 +150,7 @@
|
||||
"markdown-it": "^13.0.2",
|
||||
"markdown-it-container": "^3.0.0",
|
||||
"markdown-it-emoji": "^2.0.0",
|
||||
"mermaid": "9.3.0",
|
||||
"mermaid": "11.4.0",
|
||||
"mime-types": "^2.1.35",
|
||||
"mobx": "^4.15.4",
|
||||
"mobx-react": "^6.3.1",
|
||||
@@ -171,19 +172,19 @@
|
||||
"png-chunks-extract": "^1.0.0",
|
||||
"polished": "^4.3.1",
|
||||
"prosemirror-codemark": "^0.4.2",
|
||||
"prosemirror-commands": "^1.6.0",
|
||||
"prosemirror-commands": "^1.6.2",
|
||||
"prosemirror-dropcursor": "^1.8.1",
|
||||
"prosemirror-gapcursor": "^1.3.2",
|
||||
"prosemirror-history": "^1.4.1",
|
||||
"prosemirror-inputrules": "^1.4.0",
|
||||
"prosemirror-keymap": "^1.2.2",
|
||||
"prosemirror-markdown": "^1.13.0",
|
||||
"prosemirror-markdown": "^1.13.1",
|
||||
"prosemirror-model": "^1.23.0",
|
||||
"prosemirror-schema-list": "^1.4.1",
|
||||
"prosemirror-state": "^1.4.3",
|
||||
"prosemirror-tables": "^1.4.0",
|
||||
"prosemirror-transform": "^1.10.0",
|
||||
"prosemirror-view": "^1.34.3",
|
||||
"prosemirror-transform": "1.10.0",
|
||||
"prosemirror-view": "^1.36.0",
|
||||
"query-string": "^7.1.3",
|
||||
"randomstring": "1.3.0",
|
||||
"rate-limiter-flexible": "^2.4.2",
|
||||
@@ -196,9 +197,9 @@
|
||||
"react-dom": "^17.0.2",
|
||||
"react-dropzone": "^11.7.1",
|
||||
"react-helmet-async": "^2.0.5",
|
||||
"react-hook-form": "^7.53.0",
|
||||
"react-hook-form": "^7.53.1",
|
||||
"react-i18next": "^12.3.1",
|
||||
"react-medium-image-zoom": "^5.2.7",
|
||||
"react-medium-image-zoom": "5.2.10",
|
||||
"react-merge-refs": "^2.1.1",
|
||||
"react-portal": "^4.2.2",
|
||||
"react-router-dom": "^5.3.4",
|
||||
@@ -213,6 +214,7 @@
|
||||
"resolve-path": "^1.4.0",
|
||||
"rfc6902": "^5.1.1",
|
||||
"sanitize-filename": "^1.6.3",
|
||||
"scroll-into-view-if-needed": "^3.1.0",
|
||||
"semver": "^7.6.2",
|
||||
"sequelize": "^6.37.3",
|
||||
"sequelize-cli": "^6.6.2",
|
||||
@@ -220,7 +222,6 @@
|
||||
"sequelize-typescript": "^2.1.6",
|
||||
"slug": "^5.3.0",
|
||||
"slugify": "^1.6.6",
|
||||
"scroll-into-view-if-needed": "^3.1.0",
|
||||
"socket.io": "^4.7.5",
|
||||
"socket.io-client": "^4.8.0",
|
||||
"socket.io-redis": "^6.1.1",
|
||||
@@ -238,7 +239,7 @@
|
||||
"utility-types": "^3.10.0",
|
||||
"uuid": "^8.3.2",
|
||||
"validator": "13.12.0",
|
||||
"vite": "^5.4.8",
|
||||
"vite": "^5.4.10",
|
||||
"vite-plugin-pwa": "^0.20.3",
|
||||
"winston": "^3.13.0",
|
||||
"ws": "^7.5.10",
|
||||
@@ -247,19 +248,19 @@
|
||||
"y-protocols": "^1.0.6",
|
||||
"yauzl": "^2.10.0",
|
||||
"yjs": "^13.6.1",
|
||||
"zod": "^3.22.4"
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.23.4",
|
||||
"@babel/cli": "^7.25.9",
|
||||
"@babel/preset-typescript": "^7.24.1",
|
||||
"@faker-js/faker": "^8.4.1",
|
||||
"@relative-ci/agent": "^4.2.9",
|
||||
"@relative-ci/agent": "^4.2.12",
|
||||
"@testing-library/react": "^12.0.0",
|
||||
"@types/addressparser": "^1.0.3",
|
||||
"@types/body-scroll-lock": "^3.1.2",
|
||||
"@types/crypto-js": "^4.2.2",
|
||||
"@types/diff": "^5.0.9",
|
||||
"@types/dotenv": "^8.2.0",
|
||||
"@types/dotenv": "^8.2.3",
|
||||
"@types/emoji-regex": "^9.2.0",
|
||||
"@types/escape-html": "^1.0.4",
|
||||
"@types/express-useragent": "^1.0.2",
|
||||
@@ -269,7 +270,7 @@
|
||||
"@types/glob": "^8.0.1",
|
||||
"@types/google.analytics": "^0.0.46",
|
||||
"@types/invariant": "^2.2.37",
|
||||
"@types/jest": "^29.5.13",
|
||||
"@types/jest": "^29.5.14",
|
||||
"@types/jsonwebtoken": "^8.5.9",
|
||||
"@types/katex": "^0.16.7",
|
||||
"@types/koa": "^2.15.0",
|
||||
@@ -281,10 +282,9 @@
|
||||
"@types/koa-send": "^4.1.6",
|
||||
"@types/koa-sslify": "^4.0.6",
|
||||
"@types/koa-useragent": "^2.1.2",
|
||||
"@types/markdown-it": "^12.2.3",
|
||||
"@types/markdown-it": "^14.1.2",
|
||||
"@types/markdown-it-container": "^2.0.9",
|
||||
"@types/markdown-it-emoji": "^2.0.4",
|
||||
"@types/mermaid": "^9.2.0",
|
||||
"@types/mime-types": "^2.1.4",
|
||||
"@types/natural-sort": "^0.0.24",
|
||||
"@types/node": "20.14.2",
|
||||
@@ -307,7 +307,7 @@
|
||||
"@types/react-window": "^1.8.8",
|
||||
"@types/readable-stream": "^4.0.15",
|
||||
"@types/redis-info": "^3.0.3",
|
||||
"@types/refractor": "^3.4.0",
|
||||
"@types/refractor": "^3.4.1",
|
||||
"@types/resolve-path": "^1.4.2",
|
||||
"@types/semver": "^7.5.8",
|
||||
"@types/sequelize": "^4.28.20",
|
||||
@@ -316,7 +316,7 @@
|
||||
"@types/styled-components": "^5.1.32",
|
||||
"@types/throng": "^5.0.7",
|
||||
"@types/tmp": "^0.2.6",
|
||||
"@types/turndown": "^5.0.4",
|
||||
"@types/turndown": "^5.0.5",
|
||||
"@types/utf8": "^3.0.3",
|
||||
"@types/validator": "^13.12.1",
|
||||
"@types/yauzl": "^2.10.3",
|
||||
@@ -335,12 +335,12 @@
|
||||
"eslint-import-resolver-typescript": "^3.6.3",
|
||||
"eslint-plugin-es": "^4.1.0",
|
||||
"eslint-plugin-import": "^2.29.1",
|
||||
"eslint-plugin-jsx-a11y": "^6.7.1",
|
||||
"eslint-plugin-jsx-a11y": "^6.10.2",
|
||||
"eslint-plugin-lodash": "^7.4.0",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"eslint-plugin-react": "^7.35.0",
|
||||
"eslint-plugin-react-hooks": "^4.6.0",
|
||||
"eslint-plugin-react-hooks": "^4.6.2",
|
||||
"husky": "^8.0.3",
|
||||
"i18next-parser": "^7.9.0",
|
||||
"jest-cli": "^29.7.0",
|
||||
@@ -353,12 +353,13 @@
|
||||
"react-refresh": "^0.14.0",
|
||||
"rimraf": "^2.5.4",
|
||||
"rollup-plugin-webpack-stats": "^0.4.1",
|
||||
"terser": "^5.32.0",
|
||||
"terser": "^5.36.0",
|
||||
"typescript": "^5.6.3",
|
||||
"vite-plugin-static-copy": "^0.17.0",
|
||||
"yarn-deduplicate": "^6.0.2"
|
||||
},
|
||||
"resolutions": {
|
||||
"prosemirror-transform": "1.10.0",
|
||||
"body-scroll-lock": "^4.0.0-beta.0",
|
||||
"d3": "^7.0.0",
|
||||
"debug": "4.3.4",
|
||||
@@ -367,5 +368,5 @@
|
||||
"qs": "6.9.7",
|
||||
"rollup": "^4.5.1"
|
||||
},
|
||||
"version": "0.80.2"
|
||||
"version": "0.81.0"
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import passport from "@outlinewiki/koa-passport";
|
||||
import { isURL } from "class-validator";
|
||||
import type {
|
||||
RESTGetAPICurrentUserGuildsResult,
|
||||
RESTGetAPICurrentUserResult,
|
||||
@@ -129,10 +130,19 @@ if (env.DISCORD_CLIENT_ID && env.DISCORD_CLIENT_SECRET) {
|
||||
}
|
||||
}
|
||||
|
||||
/** Guild Name */
|
||||
teamName = guild.name;
|
||||
subdomain = slugify(guild.name);
|
||||
|
||||
/** If the guild name is a URL, use the subdomain instead – we do not allow URLs in names. */
|
||||
if (
|
||||
isURL(teamName, {
|
||||
require_host: false,
|
||||
require_protocol: false,
|
||||
})
|
||||
) {
|
||||
teamName = subdomain;
|
||||
}
|
||||
|
||||
/** Fetch the user's member object in the server for nickname and roles */
|
||||
const guildMember: RESTGetCurrentUserGuildMemberResult =
|
||||
await request(
|
||||
|
||||
@@ -225,6 +225,7 @@ router.post(
|
||||
}
|
||||
|
||||
const options = {
|
||||
query: text,
|
||||
limit: 5,
|
||||
};
|
||||
|
||||
@@ -238,11 +239,7 @@ router.post(
|
||||
return;
|
||||
}
|
||||
|
||||
const { results, total } = await SearchHelper.searchForUser(
|
||||
user,
|
||||
text,
|
||||
options
|
||||
);
|
||||
const { results, total } = await SearchHelper.searchForUser(user, options);
|
||||
|
||||
await SearchQuery.create({
|
||||
userId: user ? user.id : null,
|
||||
|
||||
@@ -3,11 +3,12 @@ import compact from "lodash/compact";
|
||||
import isEmpty from "lodash/isEmpty";
|
||||
import { UserRole } from "@shared/types";
|
||||
import auth from "@server/middlewares/authentication";
|
||||
import { transaction } from "@server/middlewares/transaction";
|
||||
import validate from "@server/middlewares/validate";
|
||||
import { WebhookSubscription, Event } from "@server/models";
|
||||
import { authorize } from "@server/policies";
|
||||
import pagination from "@server/routes/api/middlewares/pagination";
|
||||
import { WebhookSubscriptionEvent, APIContext } from "@server/types";
|
||||
import { APIContext } from "@server/types";
|
||||
import presentWebhookSubscription from "../presenters/webhookSubscription";
|
||||
import * as T from "./schema";
|
||||
|
||||
@@ -40,36 +41,37 @@ router.post(
|
||||
"webhookSubscriptions.create",
|
||||
auth({ role: UserRole.Admin }),
|
||||
validate(T.WebhookSubscriptionsCreateSchema),
|
||||
transaction(),
|
||||
async (ctx: APIContext<T.WebhookSubscriptionsCreateReq>) => {
|
||||
const { transaction } = ctx.state;
|
||||
const { user } = ctx.state.auth;
|
||||
authorize(user, "createWebhookSubscription", user.team);
|
||||
|
||||
const { name, url, secret } = ctx.input.body;
|
||||
const events: string[] = compact(ctx.input.body.events);
|
||||
|
||||
const webhookSubscription = await WebhookSubscription.create({
|
||||
name,
|
||||
events,
|
||||
createdById: user.id,
|
||||
teamId: user.teamId,
|
||||
url,
|
||||
enabled: true,
|
||||
secret: isEmpty(secret) ? undefined : secret,
|
||||
});
|
||||
const webhookSubscription = await WebhookSubscription.create(
|
||||
{
|
||||
name,
|
||||
events,
|
||||
createdById: user.id,
|
||||
teamId: user.teamId,
|
||||
url,
|
||||
enabled: true,
|
||||
secret: isEmpty(secret) ? undefined : secret,
|
||||
},
|
||||
{ transaction }
|
||||
);
|
||||
|
||||
const event: WebhookSubscriptionEvent = {
|
||||
await Event.createFromContext(ctx, {
|
||||
name: "webhookSubscriptions.create",
|
||||
modelId: webhookSubscription.id,
|
||||
teamId: user.teamId,
|
||||
actorId: user.id,
|
||||
data: {
|
||||
name,
|
||||
url,
|
||||
events,
|
||||
},
|
||||
ip: ctx.request.ip,
|
||||
};
|
||||
await Event.create(event);
|
||||
});
|
||||
|
||||
ctx.body = {
|
||||
data: presentWebhookSubscription(webhookSubscription),
|
||||
@@ -81,28 +83,30 @@ router.post(
|
||||
"webhookSubscriptions.delete",
|
||||
auth({ role: UserRole.Admin }),
|
||||
validate(T.WebhookSubscriptionsDeleteSchema),
|
||||
transaction(),
|
||||
async (ctx: APIContext<T.WebhookSubscriptionsDeleteReq>) => {
|
||||
const { id } = ctx.input.body;
|
||||
const { user } = ctx.state.auth;
|
||||
const webhookSubscription = await WebhookSubscription.findByPk(id);
|
||||
const { transaction } = ctx.state;
|
||||
const webhookSubscription = await WebhookSubscription.findByPk(id, {
|
||||
rejectOnEmpty: true,
|
||||
lock: transaction.LOCK.UPDATE,
|
||||
transaction,
|
||||
});
|
||||
|
||||
authorize(user, "delete", webhookSubscription);
|
||||
|
||||
await webhookSubscription.destroy();
|
||||
await webhookSubscription.destroy({ transaction });
|
||||
|
||||
const event: WebhookSubscriptionEvent = {
|
||||
await Event.createFromContext(ctx, {
|
||||
name: "webhookSubscriptions.delete",
|
||||
modelId: webhookSubscription.id,
|
||||
teamId: user.teamId,
|
||||
actorId: user.id,
|
||||
data: {
|
||||
name: webhookSubscription.name,
|
||||
url: webhookSubscription.url,
|
||||
events: webhookSubscription.events,
|
||||
},
|
||||
ip: ctx.request.ip,
|
||||
};
|
||||
await Event.create(event);
|
||||
});
|
||||
|
||||
ctx.body = {
|
||||
success: true,
|
||||
@@ -114,37 +118,40 @@ router.post(
|
||||
"webhookSubscriptions.update",
|
||||
auth({ role: UserRole.Admin }),
|
||||
validate(T.WebhookSubscriptionsUpdateSchema),
|
||||
transaction(),
|
||||
async (ctx: APIContext<T.WebhookSubscriptionsUpdateReq>) => {
|
||||
const { id, name, url, secret } = ctx.input.body;
|
||||
const { user } = ctx.state.auth;
|
||||
const { transaction } = ctx.state;
|
||||
const events: string[] = compact(ctx.input.body.events);
|
||||
const webhookSubscription = await WebhookSubscription.findByPk(id, {
|
||||
rejectOnEmpty: true,
|
||||
lock: transaction.LOCK.UPDATE,
|
||||
transaction,
|
||||
});
|
||||
|
||||
authorize(user, "update", webhookSubscription);
|
||||
|
||||
await webhookSubscription.update({
|
||||
name,
|
||||
url,
|
||||
events,
|
||||
enabled: true,
|
||||
secret: isEmpty(secret) ? undefined : secret,
|
||||
});
|
||||
await webhookSubscription.update(
|
||||
{
|
||||
name,
|
||||
url,
|
||||
events,
|
||||
enabled: true,
|
||||
secret: isEmpty(secret) ? undefined : secret,
|
||||
},
|
||||
{ transaction }
|
||||
);
|
||||
|
||||
const event: WebhookSubscriptionEvent = {
|
||||
await Event.createFromContext(ctx, {
|
||||
name: "webhookSubscriptions.update",
|
||||
modelId: webhookSubscription.id,
|
||||
teamId: user.teamId,
|
||||
actorId: user.id,
|
||||
data: {
|
||||
name: webhookSubscription.name,
|
||||
url: webhookSubscription.url,
|
||||
events: webhookSubscription.events,
|
||||
},
|
||||
ip: ctx.request.ip,
|
||||
};
|
||||
await Event.create(event);
|
||||
});
|
||||
|
||||
ctx.body = {
|
||||
data: presentWebhookSubscription(webhookSubscription),
|
||||
|
||||
@@ -178,6 +178,10 @@ export default class DeliverWebhookTask extends BaseTask<Props> {
|
||||
case "comments.delete":
|
||||
await this.handleCommentEvent(subscription, event);
|
||||
return;
|
||||
case "comments.add_reaction":
|
||||
case "comments.remove_reaction":
|
||||
// Ignored
|
||||
return;
|
||||
case "groups.create":
|
||||
case "groups.update":
|
||||
case "groups.delete":
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
@@ -1,9 +1,9 @@
|
||||
import { Transaction } from "sequelize";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { AttachmentPreset } from "@shared/types";
|
||||
import { Attachment, Event, User } from "@server/models";
|
||||
import { Attachment, User } from "@server/models";
|
||||
import AttachmentHelper from "@server/models/helpers/AttachmentHelper";
|
||||
import FileStorage from "@server/storage/files";
|
||||
import { APIContext } from "@server/types";
|
||||
import { RequestInit } from "@server/utils/fetch";
|
||||
|
||||
type BaseProps = {
|
||||
@@ -17,10 +17,8 @@ type BaseProps = {
|
||||
source?: "import";
|
||||
/** The preset to use for the attachment */
|
||||
preset: AttachmentPreset;
|
||||
/** The IP address of the user creating the attachment, if available. */
|
||||
ip?: string;
|
||||
/** The database transaction to use for the creation */
|
||||
transaction?: Transaction;
|
||||
/** The request context */
|
||||
ctx: APIContext;
|
||||
/** Options to pass to fetch when downloading the attachment */
|
||||
fetchOptions?: RequestInit;
|
||||
};
|
||||
@@ -42,8 +40,7 @@ export default async function attachmentCreator({
|
||||
user,
|
||||
source,
|
||||
preset,
|
||||
ip,
|
||||
transaction,
|
||||
ctx,
|
||||
fetchOptions,
|
||||
...rest
|
||||
}: Props): Promise<Attachment | undefined> {
|
||||
@@ -64,20 +61,15 @@ export default async function attachmentCreator({
|
||||
if (!res) {
|
||||
return;
|
||||
}
|
||||
attachment = await Attachment.create(
|
||||
{
|
||||
id,
|
||||
key,
|
||||
acl,
|
||||
size: res.contentLength,
|
||||
contentType: res.contentType,
|
||||
teamId: user.teamId,
|
||||
userId: user.id,
|
||||
},
|
||||
{
|
||||
transaction,
|
||||
}
|
||||
);
|
||||
attachment = await Attachment.createWithCtx(ctx, {
|
||||
id,
|
||||
key,
|
||||
acl,
|
||||
size: res.contentLength,
|
||||
contentType: res.contentType,
|
||||
teamId: user.teamId,
|
||||
userId: user.id,
|
||||
});
|
||||
} else {
|
||||
const { buffer, type } = rest;
|
||||
await FileStorage.store({
|
||||
@@ -88,38 +80,16 @@ export default async function attachmentCreator({
|
||||
acl,
|
||||
});
|
||||
|
||||
attachment = await Attachment.create(
|
||||
{
|
||||
id,
|
||||
key,
|
||||
acl,
|
||||
size: buffer.length,
|
||||
contentType: type,
|
||||
teamId: user.teamId,
|
||||
userId: user.id,
|
||||
},
|
||||
{
|
||||
transaction,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
await Event.create(
|
||||
{
|
||||
name: "attachments.create",
|
||||
data: {
|
||||
name,
|
||||
source,
|
||||
},
|
||||
modelId: attachment.id,
|
||||
attachment = await Attachment.createWithCtx(ctx, {
|
||||
id,
|
||||
key,
|
||||
acl,
|
||||
size: buffer.length,
|
||||
contentType: type,
|
||||
teamId: user.teamId,
|
||||
actorId: user.id,
|
||||
ip,
|
||||
},
|
||||
{
|
||||
transaction,
|
||||
}
|
||||
);
|
||||
userId: user.id,
|
||||
});
|
||||
}
|
||||
|
||||
return attachment;
|
||||
}
|
||||
@@ -9,7 +9,7 @@ type Props = {
|
||||
/** The database transaction to use */
|
||||
transaction: Transaction;
|
||||
/** The IP address of the current request */
|
||||
ip: string;
|
||||
ip: string | null;
|
||||
};
|
||||
|
||||
export default async function collectionDestroyer({
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Transaction } from "sequelize";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import {
|
||||
FileOperationFormat,
|
||||
@@ -6,8 +5,9 @@ import {
|
||||
FileOperationState,
|
||||
} from "@shared/types";
|
||||
import { traceFunction } from "@server/logging/tracing";
|
||||
import { Collection, Event, Team, User, FileOperation } from "@server/models";
|
||||
import { Collection, Team, User, FileOperation } from "@server/models";
|
||||
import { Buckets } from "@server/models/helpers/AttachmentHelper";
|
||||
import { type APIContext } from "@server/types";
|
||||
|
||||
type Props = {
|
||||
collection?: Collection;
|
||||
@@ -15,8 +15,7 @@ type Props = {
|
||||
user: User;
|
||||
format?: FileOperationFormat;
|
||||
includeAttachments?: boolean;
|
||||
ip: string;
|
||||
transaction: Transaction;
|
||||
ctx: APIContext;
|
||||
};
|
||||
|
||||
function getKeyForFileOp(
|
||||
@@ -35,8 +34,7 @@ async function collectionExporter({
|
||||
user,
|
||||
format = FileOperationFormat.MarkdownZip,
|
||||
includeAttachments = true,
|
||||
ip,
|
||||
transaction,
|
||||
ctx,
|
||||
}: Props) {
|
||||
const collectionId = collection?.id;
|
||||
const key = getKeyForFileOp(
|
||||
@@ -44,43 +42,20 @@ async function collectionExporter({
|
||||
format,
|
||||
collection?.name || team.name
|
||||
);
|
||||
const fileOperation = await FileOperation.create(
|
||||
{
|
||||
type: FileOperationType.Export,
|
||||
state: FileOperationState.Creating,
|
||||
format,
|
||||
key,
|
||||
url: null,
|
||||
size: 0,
|
||||
collectionId,
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
options: {
|
||||
includeAttachments,
|
||||
},
|
||||
const fileOperation = await FileOperation.createWithCtx(ctx, {
|
||||
type: FileOperationType.Export,
|
||||
state: FileOperationState.Creating,
|
||||
format,
|
||||
key,
|
||||
url: null,
|
||||
size: 0,
|
||||
collectionId,
|
||||
options: {
|
||||
includeAttachments,
|
||||
},
|
||||
{
|
||||
transaction,
|
||||
}
|
||||
);
|
||||
|
||||
await Event.create(
|
||||
{
|
||||
name: "fileOperations.create",
|
||||
teamId: user.teamId,
|
||||
actorId: user.id,
|
||||
modelId: fileOperation.id,
|
||||
collectionId,
|
||||
ip,
|
||||
data: {
|
||||
type: FileOperationType.Export,
|
||||
format,
|
||||
},
|
||||
},
|
||||
{
|
||||
transaction,
|
||||
}
|
||||
);
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
|
||||
fileOperation.user = user;
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import { schema, serializer } from "@server/editor";
|
||||
import Logger from "@server/logging/Logger";
|
||||
import { Document, Event } from "@server/models";
|
||||
import { sequelize } from "@server/storage/database";
|
||||
import { AuthenticationType } from "@server/types";
|
||||
|
||||
type Props = {
|
||||
/** The document ID to update. */
|
||||
@@ -89,6 +90,7 @@ export default async function documentCollaborativeUpdater({
|
||||
collectionId: document.collectionId,
|
||||
teamId: document.teamId,
|
||||
actorId: lastModifiedById,
|
||||
authType: AuthenticationType.APP,
|
||||
data: {
|
||||
multiplayer: true,
|
||||
title: document.title,
|
||||
|
||||
Loaded 100 of 313 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user